Skip to content

Commit b24746d

Browse files
committed
Simplify policy tool evidence parsing
1 parent 4d5d291 commit b24746d

13 files changed

Lines changed: 64 additions & 147 deletions

extensions/oc-path/api.ts

Lines changed: 0 additions & 2 deletions
This file was deleted.

extensions/oc-path/package.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44
"private": true,
55
"description": "OpenClaw oc:// workspace path plugin",
66
"type": "module",
7-
"exports": {
8-
".": "./index.ts",
9-
"./api.js": "./api.ts"
10-
},
117
"dependencies": {
128
"commander": "14.0.3",
139
"jsonc-parser": "3.3.1",

extensions/policy/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"description": "OpenClaw policy doctor checks for workspace conformance",
66
"type": "module",
77
"dependencies": {
8-
"@openclaw/oc-path": "workspace:*",
98
"json5": "2.2.3"
109
},
1110
"devDependencies": {

extensions/policy/src/policy-state.ts

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -137,20 +137,18 @@ export function scanPolicyChannels(cfg: Record<string, unknown>): readonly Polic
137137
});
138138
}
139139

140-
export async function scanPolicyTools(raw: string): Promise<readonly PolicyToolEvidence[]> {
141-
return scanPolicyToolHeaders(raw);
140+
export function scanPolicyTools(raw: string): Promise<readonly PolicyToolEvidence[]> {
141+
return Promise.resolve(scanPolicyToolHeaders(raw));
142142
}
143143

144-
async function scanPolicyToolHeaders(raw: string): Promise<readonly PolicyToolEvidence[]> {
145-
const { parseMd } = await import("@openclaw/oc-path/api.js");
146-
const toolsBlock = parseMd(raw).ast.blocks.find((block) => block.slug === "tools");
147-
if (toolsBlock === undefined) {
144+
function scanPolicyToolHeaders(raw: string): readonly PolicyToolEvidence[] {
145+
const section = markdownSectionLines(raw, "tools");
146+
if (section.length === 0) {
148147
return [];
149148
}
150-
const body = toolsBlock.bodyText.split(/\r?\n/);
151149
const tools: PolicyToolEvidence[] = [];
152-
for (let index = 0; index < body.length; index += 1) {
153-
const line = body[index];
150+
for (let index = 0; index < section.length; index += 1) {
151+
const line = section[index]?.text ?? "";
154152
const heading = /^###\s+([^\s#]+)(.*)$/.exec(line);
155153
const bullet = /^[-*+]\s+([^:\s][^:]*?)\s*:(.*)$/.exec(line);
156154
const match = heading ?? bullet;
@@ -169,11 +167,11 @@ async function scanPolicyToolHeaders(raw: string): Promise<readonly PolicyToolEv
169167
} = {
170168
id,
171169
source: `oc://TOOLS.md/tools/${id}`,
172-
line: toolsBlock.line + index + 1,
170+
line: section[index]?.line ?? index + 1,
173171
};
174172
const metaLines = [match[2] ?? ""];
175-
for (let metaIndex = index + 1; metaIndex < body.length; metaIndex += 1) {
176-
const metaLine = body[metaIndex];
173+
for (let metaIndex = index + 1; metaIndex < section.length; metaIndex += 1) {
174+
const metaLine = section[metaIndex]?.text ?? "";
177175
if (/^###\s+\S+/.test(metaLine.trim()) || /^[-*+]\s+[^:\s][^:]*?\s*:/.test(metaLine)) {
178176
break;
179177
}
@@ -201,6 +199,38 @@ async function scanPolicyToolHeaders(raw: string): Promise<readonly PolicyToolEv
201199
return tools;
202200
}
203201

202+
function markdownSectionLines(
203+
raw: string,
204+
sectionSlug: string,
205+
): readonly { readonly line: number; readonly text: string }[] {
206+
const lines = raw.split(/\r?\n/);
207+
let sectionDepth: number | undefined;
208+
const section: { line: number; text: string }[] = [];
209+
for (let index = 0; index < lines.length; index += 1) {
210+
const line = lines[index] ?? "";
211+
const heading = /^(#{1,6})\s+(.+?)\s*#*\s*$/.exec(line);
212+
if (heading !== null) {
213+
const depth = heading[1]?.length ?? 0;
214+
const slug = slugify(heading[2] ?? "");
215+
if (sectionDepth !== undefined && depth <= sectionDepth) {
216+
break;
217+
}
218+
if (sectionDepth !== undefined) {
219+
section.push({ line: index + 1, text: line });
220+
continue;
221+
}
222+
if (sectionDepth === undefined && slug === sectionSlug) {
223+
sectionDepth = depth;
224+
}
225+
continue;
226+
}
227+
if (sectionDepth !== undefined) {
228+
section.push({ line: index + 1, text: line });
229+
}
230+
}
231+
return section;
232+
}
233+
204234
function slugify(text: string): string {
205235
return text
206236
.toLowerCase()

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
"!dist/extensions/amazon-bedrock-mantle/**",
3737
"!dist/extensions/anthropic-vertex/**",
3838
"!dist/extensions/node_modules/**",
39-
"dist/extensions/node_modules/@openclaw/oc-path/**",
4039
"!dist/extensions/*/node_modules/**",
4140
"!dist/extensions/brave/**",
4241
"!dist/extensions/codex/**",

pnpm-lock.yaml

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/release-check.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ const forbiddenPrefixes = [
101101
"docs/channels/qa-channel.md",
102102
"qa/",
103103
];
104-
const allowedNodeModulesPackPrefixes = ["dist/extensions/node_modules/@openclaw/oc-path/"];
105104
const forbiddenPrivateQaContentMarkers = [
106105
"//#region extensions/qa-lab/",
107106
"qa-channel/runtime-api.js",
@@ -639,8 +638,7 @@ export function collectForbiddenPackPaths(paths: Iterable<string>): string[] {
639638
forbiddenPrefixes.some((prefix) => path.startsWith(prefix)) ||
640639
/(^|\/)\.openclaw-runtime-deps-[^/]+(\/|$)/u.test(path) ||
641640
path.endsWith("/.openclaw-runtime-deps-stamp.json") ||
642-
(path.includes("node_modules/") &&
643-
!allowedNodeModulesPackPrefixes.some((prefix) => path.startsWith(prefix))),
641+
path.includes("node_modules/"),
644642
)
645643
.toSorted((left, right) => left.localeCompare(right));
646644
}

scripts/stage-bundled-plugin-runtime.mjs

Lines changed: 21 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -75,54 +75,31 @@ function writeJsonFile(targetPath, value) {
7575

7676
function ensureOpenClawExtensionAlias(params) {
7777
const pluginSdkDir = path.join(params.repoRoot, "dist", "plugin-sdk");
78-
const aliasDir = path.join(params.distExtensionsRoot, "node_modules", "openclaw");
79-
80-
if (fs.existsSync(pluginSdkDir)) {
81-
const pluginSdkAliasPath = path.join(aliasDir, "plugin-sdk");
82-
fs.mkdirSync(aliasDir, { recursive: true });
83-
writeJsonFile(path.join(aliasDir, "package.json"), {
84-
name: "openclaw",
85-
type: "module",
86-
exports: {
87-
"./plugin-sdk": "./plugin-sdk/index.js",
88-
"./plugin-sdk/*": "./plugin-sdk/*.js",
89-
},
90-
});
91-
removePathIfExists(pluginSdkAliasPath);
92-
fs.mkdirSync(pluginSdkAliasPath, { recursive: true });
93-
for (const dirent of fs.readdirSync(pluginSdkDir, { withFileTypes: true })) {
94-
if (!dirent.isFile() || path.extname(dirent.name) !== ".js") {
95-
continue;
96-
}
97-
writeRuntimeModuleWrapper(
98-
path.join(pluginSdkDir, dirent.name),
99-
path.join(pluginSdkAliasPath, dirent.name),
100-
);
101-
}
78+
if (!fs.existsSync(pluginSdkDir)) {
79+
return;
10280
}
10381

104-
const ocPathDir = path.join(params.distExtensionsRoot, "oc-path");
105-
const ocPathApiPath = path.join(ocPathDir, "api.js");
106-
if (fs.existsSync(ocPathApiPath)) {
107-
const ocPathAliasDir = path.join(
108-
params.distExtensionsRoot,
109-
"node_modules",
110-
"@openclaw",
111-
"oc-path",
112-
);
113-
writeJsonFile(path.join(ocPathAliasDir, "package.json"), {
114-
name: "@openclaw/oc-path",
115-
type: "module",
116-
exports: {
117-
".": "./index.js",
118-
"./api.js": "./api.js",
119-
},
120-
});
82+
const aliasDir = path.join(params.distExtensionsRoot, "node_modules", "openclaw");
83+
const pluginSdkAliasPath = path.join(aliasDir, "plugin-sdk");
84+
fs.mkdirSync(aliasDir, { recursive: true });
85+
writeJsonFile(path.join(aliasDir, "package.json"), {
86+
name: "openclaw",
87+
type: "module",
88+
exports: {
89+
"./plugin-sdk": "./plugin-sdk/index.js",
90+
"./plugin-sdk/*": "./plugin-sdk/*.js",
91+
},
92+
});
93+
removePathIfExists(pluginSdkAliasPath);
94+
fs.mkdirSync(pluginSdkAliasPath, { recursive: true });
95+
for (const dirent of fs.readdirSync(pluginSdkDir, { withFileTypes: true })) {
96+
if (!dirent.isFile() || path.extname(dirent.name) !== ".js") {
97+
continue;
98+
}
12199
writeRuntimeModuleWrapper(
122-
path.join(ocPathDir, "index.js"),
123-
path.join(ocPathAliasDir, "index.js"),
100+
path.join(pluginSdkDir, dirent.name),
101+
path.join(pluginSdkAliasPath, dirent.name),
124102
);
125-
writeRuntimeModuleWrapper(ocPathApiPath, path.join(ocPathAliasDir, "api.js"));
126103
}
127104
}
128105

src/plugins/loader.test.ts

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,28 +1113,6 @@ describe("loadOpenClawPlugins", () => {
11131113
expect(fs.readFileSync(path.join(aliasDir, "core.js"), "utf8")).toContain("core.js");
11141114
});
11151115

1116-
it("writes bundled oc-path package aliases for dist plugin consumers", () => {
1117-
const distRoot = makeTempDir();
1118-
const ocPathDir = path.join(distRoot, "extensions", "oc-path");
1119-
fs.mkdirSync(ocPathDir, { recursive: true });
1120-
fs.writeFileSync(path.join(ocPathDir, "index.js"), "export const full = true;\n", "utf8");
1121-
fs.writeFileSync(path.join(ocPathDir, "api.js"), "export const md = true;\n", "utf8");
1122-
1123-
ensureOpenClawPluginSdkAlias(distRoot);
1124-
1125-
const aliasDir = path.join(distRoot, "extensions", "node_modules", "@openclaw", "oc-path");
1126-
expect(JSON.parse(fs.readFileSync(path.join(aliasDir, "package.json"), "utf8"))).toMatchObject({
1127-
name: "@openclaw/oc-path",
1128-
exports: {
1129-
".": "./index.js",
1130-
"./api.js": "./api.js",
1131-
},
1132-
});
1133-
expect(fs.readFileSync(path.join(aliasDir, "api.js"), "utf8")).toContain(
1134-
"../../../oc-path/api.js",
1135-
);
1136-
});
1137-
11381116
it("disables bundled plugins by default", () => {
11391117
const bundledDir = makeTempDir();
11401118
writePlugin({

src/plugins/plugin-sdk-dist-alias.ts

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,30 +20,9 @@ function writeRuntimeModuleWrapper(sourcePath: string, targetPath: string): void
2020
fs.writeFileSync(targetPath, content, "utf8");
2121
}
2222

23-
function ensureOpenClawOcPathAlias(distRoot: string): void {
24-
const ocPathDir = path.join(distRoot, "extensions", "oc-path");
25-
const ocPathApiPath = path.join(ocPathDir, "api.js");
26-
if (!fs.existsSync(ocPathApiPath)) {
27-
return;
28-
}
29-
30-
const aliasDir = path.join(distRoot, "extensions", "node_modules", "@openclaw", "oc-path");
31-
writeRuntimeJsonFile(path.join(aliasDir, "package.json"), {
32-
name: "@openclaw/oc-path",
33-
type: "module",
34-
exports: {
35-
".": "./index.js",
36-
"./api.js": "./api.js",
37-
},
38-
});
39-
writeRuntimeModuleWrapper(path.join(ocPathDir, "index.js"), path.join(aliasDir, "index.js"));
40-
writeRuntimeModuleWrapper(ocPathApiPath, path.join(aliasDir, "api.js"));
41-
}
42-
4323
export function ensureOpenClawPluginSdkAlias(distRoot: string): void {
4424
const pluginSdkDir = path.join(distRoot, "plugin-sdk");
4525
if (!fs.existsSync(pluginSdkDir)) {
46-
ensureOpenClawOcPathAlias(distRoot);
4726
return;
4827
}
4928

@@ -74,5 +53,4 @@ export function ensureOpenClawPluginSdkAlias(distRoot: string): void {
7453
path.join(pluginSdkAliasDir, entry.name),
7554
);
7655
}
77-
ensureOpenClawOcPathAlias(distRoot);
7856
}

0 commit comments

Comments
 (0)