Skip to content

Commit 59c523c

Browse files
committed
fix: reject source-only plugin package installs
1 parent 0a2b87c commit 59c523c

6 files changed

Lines changed: 187 additions & 20 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Docs: https://docs.openclaw.ai
2626

2727
- Control UI/Sessions: avoid full `sessions.list` reloads for chat-turn `sessions.changed` payloads, so large session stores no longer add multi-second delays while chat responses are being delivered. (#76676) Thanks @VACInc.
2828
- Doctor/Telegram: warn when selected Telegram quote replies can suppress `streaming.preview.toolProgress`, and document the `replyToMode` trade-off without changing runtime delivery. Fixes #73487. Thanks @GodsBoy.
29+
- Plugins/install: reject source-only TypeScript package installs and installed plugin packages that are missing compiled runtime output, so broken npm artifacts fail at install/discovery time instead of falling through jiti and surfacing later as unavailable providers. Fixes #76720.
2930
- Discord/status: honor explicit `messages.statusReactions.enabled: true` in tool-only guild channels so queued ack reactions can progress through thinking/done lifecycle reactions instead of stopping at the initial emoji. Thanks @Marvinthebored.
3031
- Discord/native commands: compare Discord-normalized slash-command descriptions and localized descriptions during reconcile so CJK or multiline command text no longer triggers redundant startup PATCH bursts and rate-limit 429s. Fixes #76587. Thanks @zhengsx.
3132
- Agents/OpenAI: omit Chat Completions `reasoning_effort` for `gpt-5.4-mini` only when function tools are present while preserving tool-free Chat and Responses reasoning support, preventing Telegram-routed fallback runs from hanging after OpenAI rejects tool payloads. Fixes #76176. Thanks @ThisIsAdilah and @chinar-amrutkar.

‎docs/tools/plugin.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@ Native plugin npm packages must declare `openclaw.extensions` in `package.json`.
161161
Each entry must stay inside the package directory and resolve to a readable
162162
runtime file, or to a TypeScript source file with an inferred built JavaScript
163163
peer such as `src/index.ts` to `dist/index.js`.
164+
Packaged installs must ship that JavaScript runtime output. The TypeScript
165+
source fallback is for source checkouts and local development paths, not for
166+
npm packages installed into OpenClaw's managed plugin root.
164167

165168
Use `openclaw.runtimeExtensions` when published runtime files do not live at the
166169
same paths as the source entries. When present, `runtimeExtensions` must contain

‎src/plugins/discovery.test.ts‎

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import path from "node:path";
44
import { bundledDistPluginFile } from "openclaw/plugin-sdk/test-fixtures";
55
import { afterEach, describe, expect, it, vi } from "vitest";
66
import { discoverOpenClawPlugins } from "./discovery.js";
7+
import { listBuiltRuntimeEntryCandidates } from "./package-entrypoints.js";
78
import {
89
cleanupTrackedTempDirs,
910
makeTrackedTempDir,
@@ -198,6 +199,7 @@ function createPackagePluginWithEntry(params: {
198199
packageName: string;
199200
pluginId?: string;
200201
entryPath?: string;
202+
writeBuiltRuntime?: boolean;
201203
}) {
202204
const entryPath = params.entryPath ?? "src/index.ts";
203205
mkdirSafe(path.dirname(path.join(params.packageDir, entryPath)));
@@ -208,6 +210,14 @@ function createPackagePluginWithEntry(params: {
208210
...(params.pluginId ? { pluginId: params.pluginId } : {}),
209211
});
210212
writePluginEntry(path.join(params.packageDir, entryPath));
213+
if (params.writeBuiltRuntime ?? listBuiltRuntimeEntryCandidates(entryPath).length > 0) {
214+
const runtimeEntry = listBuiltRuntimeEntryCandidates(entryPath)[0];
215+
if (runtimeEntry) {
216+
const runtimePath = path.join(params.packageDir, runtimeEntry.replace(/^\.\//u, ""));
217+
mkdirSafe(path.dirname(runtimePath));
218+
writePluginEntry(runtimePath);
219+
}
220+
}
211221
}
212222

213223
function createBundleRoot(bundleDir: string, markerPath: string, manifest?: unknown) {
@@ -303,7 +313,7 @@ function expectBundleCandidateMatch(params: {
303313
async function expectRejectedPackageExtensionEntry(params: {
304314
stateDir: string;
305315
setup: (stateDir: string) => boolean | void;
306-
expectedDiagnostic?: "escapes" | "none";
316+
expectedDiagnostic?: "escapes" | "none" | "runtime";
307317
expectedId?: string;
308318
}) {
309319
if (params.setup(params.stateDir) === false) {
@@ -320,6 +330,14 @@ async function expectRejectedPackageExtensionEntry(params: {
320330
expectEscapesPackageDiagnostic(result.diagnostics);
321331
return;
322332
}
333+
if (params.expectedDiagnostic === "runtime") {
334+
expect(
335+
result.diagnostics.some(
336+
(entry) => entry.level === "error" && entry.message.includes("compiled runtime output"),
337+
),
338+
).toBe(true);
339+
return;
340+
}
323341
expect(result.diagnostics).toEqual([]);
324342
}
325343

@@ -714,6 +732,7 @@ describe("discoverOpenClawPlugins", () => {
714732
const stateDir = makeTempDir();
715733
const globalExt = path.join(stateDir, "extensions", "pack");
716734
mkdirSafe(path.join(globalExt, "src"));
735+
mkdirSafe(path.join(globalExt, "dist"));
717736

718737
writePluginPackageManifest({
719738
packageDir: globalExt,
@@ -722,15 +741,43 @@ describe("discoverOpenClawPlugins", () => {
722741
});
723742
writePluginEntry(path.join(globalExt, "src", "one.ts"));
724743
writePluginEntry(path.join(globalExt, "src", "two.ts"));
744+
writePluginEntry(path.join(globalExt, "dist", "one.js"));
745+
writePluginEntry(path.join(globalExt, "dist", "two.js"));
725746

726747
const { candidates } = await discoverWithStateDir(stateDir, {});
727748
expectCandidateIds(candidates, { includes: ["pack/one", "pack/two"] });
728749
});
729750

751+
it("rejects source-only TypeScript entries for installed package plugins", async () => {
752+
const stateDir = makeTempDir();
753+
const pluginDir = path.join(stateDir, "extensions", "source-only-pack");
754+
mkdirSafe(path.join(pluginDir, "src"));
755+
756+
writePluginPackageManifest({
757+
packageDir: pluginDir,
758+
packageName: "@openclaw/source-only-pack",
759+
extensions: ["./src/index.ts"],
760+
});
761+
writePluginEntry(path.join(pluginDir, "src", "index.ts"));
762+
763+
const result = await discoverWithStateDir(stateDir, {});
764+
765+
expectCandidatePresence(result, { absent: ["source-only-pack"] });
766+
expect(
767+
result.diagnostics.some(
768+
(entry) =>
769+
entry.level === "error" &&
770+
entry.message.includes("requires compiled runtime output") &&
771+
entry.message.includes("./dist/index.js"),
772+
),
773+
).toBe(true);
774+
});
775+
730776
it("reuses one filesystem realpath lookup per package root within a discovery run", () => {
731777
const stateDir = makeTempDir();
732778
const packageDir = path.join(stateDir, "extensions", "pack");
733779
mkdirSafe(path.join(packageDir, "src"));
780+
mkdirSafe(path.join(packageDir, "dist"));
734781

735782
writePluginPackageManifest({
736783
packageDir,
@@ -739,6 +786,8 @@ describe("discoverOpenClawPlugins", () => {
739786
});
740787
writePluginEntry(path.join(packageDir, "src", "one.ts"));
741788
writePluginEntry(path.join(packageDir, "src", "two.ts"));
789+
writePluginEntry(path.join(packageDir, "dist", "one.js"));
790+
writePluginEntry(path.join(packageDir, "dist", "two.js"));
742791

743792
const realpathSync = vi.spyOn(fs, "realpathSync");
744793
const { candidates } = discoverOpenClawPlugins({
@@ -1049,6 +1098,7 @@ describe("discoverOpenClawPlugins", () => {
10491098
"diffs",
10501099
);
10511100
mkdirSafe(path.join(pluginDir, "src"));
1101+
mkdirSafe(path.join(pluginDir, "dist"));
10521102
mkdirSafe(nestedDiffsDir);
10531103

10541104
writePluginPackageManifest({
@@ -1062,6 +1112,11 @@ describe("discoverOpenClawPlugins", () => {
10621112
"export default function () {}",
10631113
"utf-8",
10641114
);
1115+
fs.writeFileSync(
1116+
path.join(pluginDir, "dist", "index.js"),
1117+
"export default function () {}",
1118+
"utf-8",
1119+
);
10651120

10661121
writePluginPackageManifest({
10671122
packageDir: path.join(pluginDir, "node_modules", "openclaw"),
@@ -1322,8 +1377,8 @@ describe("discoverOpenClawPlugins", () => {
13221377
},
13231378
},
13241379
{
1325-
name: "skips missing package extension entries without escape diagnostics",
1326-
expectedDiagnostic: "none" as const,
1380+
name: "rejects missing TypeScript package runtime entries without escape diagnostics",
1381+
expectedDiagnostic: "runtime" as const,
13271382
setup: (stateDir: string) => {
13281383
const globalExt = path.join(stateDir, "extensions", "missing-entry-pack");
13291384
mkdirSafe(globalExt);

‎src/plugins/install.test.ts‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -930,6 +930,32 @@ describe("installPluginFromArchive", () => {
930930
}
931931
});
932932

933+
it("rejects package installs when a TypeScript extension entry has no compiled runtime output", async () => {
934+
const { pluginDir, extensionsDir } = setupPluginInstallDirs();
935+
fs.mkdirSync(path.join(pluginDir, "src"), { recursive: true });
936+
fs.writeFileSync(
937+
path.join(pluginDir, "package.json"),
938+
JSON.stringify({
939+
name: "source-only-runtime-plugin",
940+
version: "1.0.0",
941+
openclaw: { extensions: ["./src/index.ts"] },
942+
}),
943+
);
944+
fs.writeFileSync(path.join(pluginDir, "src", "index.ts"), "export {};\n");
945+
946+
const result = await installPluginFromDir({
947+
dirPath: pluginDir,
948+
extensionsDir,
949+
});
950+
951+
expect(result.ok).toBe(false);
952+
if (!result.ok) {
953+
expect(result.code).toBe(PLUGIN_INSTALL_ERROR_CODE.INVALID_OPENCLAW_EXTENSIONS);
954+
expect(result.error).toContain("requires compiled runtime output");
955+
expect(result.error).toContain("./dist/index.js");
956+
}
957+
});
958+
933959
it("rejects package installs when runtimeExtensions length does not match extensions", async () => {
934960
const { pluginDir, extensionsDir } = setupPluginInstallDirs();
935961
fs.mkdirSync(path.join(pluginDir, "dist"), { recursive: true });

‎src/plugins/package-entry-resolution.ts‎

Lines changed: 98 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ import { resolveBoundaryPath, resolveBoundaryPathSync } from "../infra/boundary-
99
import { normalizeOptionalString } from "../shared/string-coerce.js";
1010
import type { PluginDiagnostic } from "./manifest-types.js";
1111
import { getPackageManifestMetadata, type PackageManifest } from "./manifest.js";
12-
import { listBuiltRuntimeEntryCandidates } from "./package-entrypoints.js";
12+
import {
13+
isTypeScriptPackageEntry,
14+
listBuiltRuntimeEntryCandidates,
15+
} from "./package-entrypoints.js";
1316
import type { PluginOrigin } from "./plugin-origin.types.js";
1417

1518
type ExtensionEntryValidation = { ok: true; exists: boolean } | { ok: false; error: string };
@@ -56,6 +59,14 @@ function resolvePackageRuntimeExtensionEntries(params: {
5659
return { ok: true, runtimeExtensions };
5760
}
5861

62+
function missingCompiledRuntimeEntryMessage(params: {
63+
label: string;
64+
entry: string;
65+
candidates: readonly string[];
66+
}): string {
67+
return `${params.label} requires compiled runtime output for TypeScript entry ${params.entry}: expected ${params.candidates.join(", ")}`;
68+
}
69+
5970
async function validatePackageExtensionEntry(params: {
6071
packageDir: string;
6172
entry: string;
@@ -142,12 +153,9 @@ export async function validatePackageExtensionEntriesForInstall(params: {
142153
continue;
143154
}
144155

145-
if (sourceEntry.exists) {
146-
continue;
147-
}
148-
149156
let foundBuiltEntry = false;
150-
for (const builtEntry of listBuiltRuntimeEntryCandidates(entry)) {
157+
const builtEntryCandidates = listBuiltRuntimeEntryCandidates(entry);
158+
for (const builtEntry of builtEntryCandidates) {
151159
const builtResult = await validatePackageExtensionEntry({
152160
packageDir: params.packageDir,
153161
entry: builtEntry,
@@ -163,9 +171,37 @@ export async function validatePackageExtensionEntriesForInstall(params: {
163171
}
164172
}
165173

166-
if (!foundBuiltEntry) {
167-
return { ok: false, error: `extension entry not found: ${entry}` };
174+
if (foundBuiltEntry) {
175+
continue;
176+
}
177+
178+
if (sourceEntry.exists && isTypeScriptPackageEntry(entry)) {
179+
return {
180+
ok: false,
181+
error: missingCompiledRuntimeEntryMessage({
182+
label: "package install",
183+
entry,
184+
candidates: builtEntryCandidates,
185+
}),
186+
};
168187
}
188+
189+
if (sourceEntry.exists) {
190+
continue;
191+
}
192+
193+
if (builtEntryCandidates.length > 0) {
194+
return {
195+
ok: false,
196+
error: missingCompiledRuntimeEntryMessage({
197+
label: "package install",
198+
entry,
199+
candidates: builtEntryCandidates,
200+
}),
201+
};
202+
}
203+
204+
return { ok: false, error: `extension entry not found: ${entry}` };
169205
}
170206

171207
const packageManifest = getPackageManifestMetadata(params.manifest);
@@ -201,12 +237,9 @@ export async function validatePackageExtensionEntriesForInstall(params: {
201237
return { ok: true };
202238
}
203239

204-
if (sourceEntry.exists) {
205-
return { ok: true };
206-
}
207-
208240
let foundBuiltSetupEntry = false;
209-
for (const builtEntry of listBuiltRuntimeEntryCandidates(setupEntry)) {
241+
const builtSetupCandidates = listBuiltRuntimeEntryCandidates(setupEntry);
242+
for (const builtEntry of builtSetupCandidates) {
210243
const builtResult = await validatePackageExtensionEntry({
211244
packageDir: params.packageDir,
212245
entry: builtEntry,
@@ -221,9 +254,38 @@ export async function validatePackageExtensionEntriesForInstall(params: {
221254
break;
222255
}
223256
}
224-
if (!foundBuiltSetupEntry) {
225-
return { ok: false, error: `setup entry not found: ${setupEntry}` };
257+
258+
if (foundBuiltSetupEntry) {
259+
return { ok: true };
260+
}
261+
262+
if (sourceEntry.exists && isTypeScriptPackageEntry(setupEntry)) {
263+
return {
264+
ok: false,
265+
error: missingCompiledRuntimeEntryMessage({
266+
label: "package install",
267+
entry: setupEntry,
268+
candidates: builtSetupCandidates,
269+
}),
270+
};
271+
}
272+
273+
if (sourceEntry.exists) {
274+
return { ok: true };
275+
}
276+
277+
if (builtSetupCandidates.length > 0) {
278+
return {
279+
ok: false,
280+
error: missingCompiledRuntimeEntryMessage({
281+
label: "package install",
282+
entry: setupEntry,
283+
candidates: builtSetupCandidates,
284+
}),
285+
};
226286
}
287+
288+
return { ok: false, error: `setup entry not found: ${setupEntry}` };
227289
}
228290

229291
return { ok: true };
@@ -296,6 +358,10 @@ function shouldInferBuiltRuntimeEntry(origin: PluginOrigin): boolean {
296358
return origin === "config" || origin === "global";
297359
}
298360

361+
function shouldRequireBuiltRuntimeEntry(origin: PluginOrigin): boolean {
362+
return origin === "global";
363+
}
364+
299365
function resolveSafePackageEntry(params: {
300366
packageDir: string;
301367
packageRootRealPath?: string;
@@ -408,7 +474,8 @@ function resolvePackageRuntimeEntrySource(params: {
408474
}
409475

410476
if (shouldInferBuiltRuntimeEntry(params.origin)) {
411-
for (const candidate of listBuiltRuntimeEntryCandidates(safeEntry.relativePath)) {
477+
const builtEntryCandidates = listBuiltRuntimeEntryCandidates(safeEntry.relativePath);
478+
for (const candidate of builtEntryCandidates) {
412479
const runtimeSource = resolveExistingPackageEntrySource({
413480
packageDir: params.packageDir,
414481
...(params.packageRootRealPath !== undefined
@@ -423,6 +490,21 @@ function resolvePackageRuntimeEntrySource(params: {
423490
return runtimeSource;
424491
}
425492
}
493+
if (
494+
shouldRequireBuiltRuntimeEntry(params.origin) &&
495+
isTypeScriptPackageEntry(safeEntry.relativePath)
496+
) {
497+
params.diagnostics.push({
498+
level: "error",
499+
message: missingCompiledRuntimeEntryMessage({
500+
label: "installed plugin package",
501+
entry: safeEntry.relativePath,
502+
candidates: builtEntryCandidates,
503+
}),
504+
source: params.sourceLabel,
505+
});
506+
return null;
507+
}
426508
}
427509

428510
if (safeEntry.existingSource) {

‎src/plugins/package-entrypoints.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import path from "node:path";
22

3-
function isTypeScriptPackageEntry(entryPath: string): boolean {
3+
export function isTypeScriptPackageEntry(entryPath: string): boolean {
44
return [".ts", ".mts", ".cts"].includes(path.extname(entryPath).toLowerCase());
55
}
66

0 commit comments

Comments
 (0)