Skip to content

Commit a90c8d8

Browse files
committed
fix(packaging): recognize owner-restricted plugin aliases
1 parent aacbcaa commit a90c8d8

3 files changed

Lines changed: 67 additions & 13 deletions

File tree

‎scripts/lib/plugin-npm-runtime-build.d.mts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export type PluginNpmRuntimeBuildPlan = {
3333
};
3434
/** Resolve the package-local runtime build plan for one publishable plugin package. */
3535
export function resolvePluginNpmRuntimeBuildPlan(params: unknown): PluginNpmRuntimeBuildPlan | null;
36-
/** List built host SDK imports that are absent from the OpenClaw package exports. */
36+
/** List built host SDK imports unavailable through package exports or owner-restricted aliases. */
3737
export function listMissingPluginNpmRuntimeHostExports(plan: PluginNpmRuntimeBuildPlan): string[];
3838
/** Build package-local runtime files and static assets for one plugin package. */
3939
export function buildPluginNpmRuntime(params: unknown): Promise<

‎scripts/lib/plugin-npm-runtime-build.mjs‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ function createNeverBundleDependencyMatcher(packageJson) {
9393

9494
const HOST_PLUGIN_SDK_IMPORT_RE =
9595
/(?:\bfrom\s+|\bimport\s*(?:\(\s*)?|\b(?:require|_+require\d*)\(\s*)["'](openclaw\/plugin-sdk\/[^"']+)["']/gu;
96+
const OWNER_RESTRICTED_HOST_IMPORTS_BY_PACKAGE_NAME = new Map([
97+
["@openclaw/codex", new Set(["openclaw/plugin-sdk/agent-harness-tool-authority-runtime"])],
98+
["@openclaw/copilot", new Set(["openclaw/plugin-sdk/agent-harness-tool-authority-runtime"])],
99+
]);
96100

97101
function listRuntimeJavaScriptFiles(rootDir) {
98102
if (!fs.existsSync(rootDir)) {
@@ -111,8 +115,8 @@ function listRuntimeJavaScriptFiles(rootDir) {
111115
}
112116

113117
/**
114-
* List host SDK imports emitted by a built plugin runtime but absent from package exports.
115-
* @param {{ repoRoot: string; outDir: string }} plan
118+
* List host SDK imports emitted by a built plugin runtime but unavailable to its package owner.
119+
* @param {{ repoRoot: string; outDir: string; packageJson?: { name?: unknown } }} plan
116120
*/
117121
export function listMissingPluginNpmRuntimeHostExports(plan) {
118122
const hostImports = new Set();
@@ -131,8 +135,16 @@ export function listMissingPluginNpmRuntimeHostExports(plan) {
131135

132136
const hostPackageJson = readJsonFile(path.join(plan.repoRoot, "package.json"));
133137
const hostExports = new Set(Object.keys(hostPackageJson.exports ?? {}));
138+
const packageName =
139+
typeof plan.packageJson?.name === "string" ? plan.packageJson.name.trim() : "";
140+
const ownerRestrictedHostImports =
141+
OWNER_RESTRICTED_HOST_IMPORTS_BY_PACKAGE_NAME.get(packageName) ?? new Set();
134142
return [...hostImports]
135-
.filter((specifier) => !hostExports.has(specifier.replace(/^openclaw/u, ".")))
143+
.filter(
144+
(specifier) =>
145+
!hostExports.has(specifier.replace(/^openclaw/u, ".")) &&
146+
!ownerRestrictedHostImports.has(specifier),
147+
)
136148
.toSorted((left, right) => left.localeCompare(right));
137149
}
138150

‎test/plugin-npm-runtime-build.test.ts‎

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -240,16 +240,19 @@ describe("plugin npm runtime build planning", () => {
240240
expect(plan.runtimeBuildOutputs).toContain("./dist/setup-api.js");
241241
});
242242

243-
it("keeps published Codex runtime imports resolvable from the host package", async () => {
244-
const result = await buildPluginNpmRuntime({
245-
repoRoot,
246-
packageDir: "extensions/codex",
247-
logLevel: "silent",
248-
});
249-
const plan = expectPluginNpmRuntimeBuildPlan(result);
243+
it.each(["codex", "copilot"])(
244+
"keeps published %s runtime imports resolvable from the host package",
245+
async (pluginId) => {
246+
const result = await buildPluginNpmRuntime({
247+
repoRoot,
248+
packageDir: `extensions/${pluginId}`,
249+
logLevel: "silent",
250+
});
251+
const plan = expectPluginNpmRuntimeBuildPlan(result);
250252

251-
expect(listMissingPluginNpmRuntimeHostExports(plan)).toEqual([]);
252-
});
253+
expect(listMissingPluginNpmRuntimeHostExports(plan)).toEqual([]);
254+
},
255+
);
253256

254257
it("detects unresolved side-effect host imports in built plugin runtimes", () => {
255258
const outDir = tempDirs.make("openclaw-plugin-runtime-host-import-");
@@ -275,6 +278,45 @@ describe("plugin npm runtime build planning", () => {
275278
]);
276279
});
277280

281+
it("allows private harness authority imports only for their official package owners", () => {
282+
const outDir = tempDirs.make("openclaw-plugin-runtime-private-owner-import-");
283+
writeFileSync(
284+
path.join(outDir, "index.js"),
285+
[
286+
'import "openclaw/plugin-sdk/agent-harness-tool-authority-runtime";',
287+
'import "openclaw/plugin-sdk/not-owner-restricted";',
288+
"",
289+
].join("\n"),
290+
);
291+
const plan = expectPluginNpmRuntimeBuildPlan(
292+
resolvePluginNpmRuntimeBuildPlan({
293+
repoRoot,
294+
packageDir: path.join(repoRoot, "extensions", "codex"),
295+
}),
296+
);
297+
298+
expect(listMissingPluginNpmRuntimeHostExports({ ...plan, outDir })).toEqual([
299+
"openclaw/plugin-sdk/not-owner-restricted",
300+
]);
301+
expect(
302+
listMissingPluginNpmRuntimeHostExports({
303+
...plan,
304+
outDir,
305+
packageJson: { ...plan.packageJson, name: "@openclaw/copilot" },
306+
}),
307+
).toEqual(["openclaw/plugin-sdk/not-owner-restricted"]);
308+
expect(
309+
listMissingPluginNpmRuntimeHostExports({
310+
...plan,
311+
outDir,
312+
packageJson: { ...plan.packageJson, name: "@openclaw/demo" },
313+
}),
314+
).toEqual([
315+
"openclaw/plugin-sdk/agent-harness-tool-authority-runtime",
316+
"openclaw/plugin-sdk/not-owner-restricted",
317+
]);
318+
});
319+
278320
it("does not require host metadata when the runtime has no host imports", () => {
279321
const syntheticRepoRoot = tempDirs.make("openclaw-plugin-runtime-synthetic-repo-");
280322
const outDir = tempDirs.make("openclaw-plugin-runtime-no-host-import-");

0 commit comments

Comments
 (0)