Skip to content

Commit 9ff51db

Browse files
Warn when an agent plugin prompt file is missing (#928)
* Warn when an agent plugin prompt file is missing * Pin unreadable marker in missing-prompt warning test
1 parent bec1b17 commit 9ff51db

2 files changed

Lines changed: 28 additions & 6 deletions

File tree

src/plugins/agent-plugins.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,4 +176,22 @@ describe("resolveAgentPluginProfiles", () => {
176176
),
177177
).toBe(true);
178178
});
179+
180+
test("warns once when a prompt file is missing and still loads the profile", async () => {
181+
const { mod, config } = agentModule("p1", [
182+
{ id: "scout", systemPromptPath: "prompts/does-not-exist.md" },
183+
]);
184+
mod.dir = "/tmp/wt-cl-6724-missing-prompt-dir";
185+
const warnings: string[] = [];
186+
const profiles = await resolveAgentPluginProfiles([mod], config, (msg) =>
187+
warnings.push(msg),
188+
);
189+
expect(profiles.length).toBe(1);
190+
expect(defined(profiles[0]).systemPromptRole).toBeUndefined();
191+
expect(warnings.length).toBe(1);
192+
expect(warnings[0]).toContain('"p1"');
193+
expect(warnings[0]).toContain('"scout"');
194+
expect(warnings[0]).toContain("prompts/does-not-exist.md");
195+
expect(defined(warnings[0])).toMatch(/unreadable|missing/i);
196+
});
179197
});

src/plugins/agent-plugins.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,18 @@ export async function resolveAgentPluginProfiles(
9090
profile.systemPromptRole === undefined &&
9191
mod.dir !== undefined
9292
) {
93+
const promptPath = join(mod.dir, profile.systemPromptPath);
9394
try {
94-
const promptRaw = await readFile(
95-
join(mod.dir, profile.systemPromptPath),
96-
"utf8",
97-
);
95+
const promptRaw = await readFile(promptPath, "utf8");
9896
profile.systemPromptRole = promptRaw.trim();
99-
} catch {
100-
// Missing prompt file is non-fatal — the profile loads without a role.
97+
} catch (err) {
98+
const reason =
99+
(err instanceof Error ? err.message : String(err))
100+
.split("\n")[0]
101+
?.trim() || "unknown error";
102+
onWarning(
103+
`plugin "${mod.manifest.id}" agent "${profile.id}" systemPromptPath "${profile.systemPromptPath}" unreadable (${promptPath}): ${reason}`,
104+
);
101105
}
102106
}
103107
// Provenance for search_agents: Claude marketplace installs stamp

0 commit comments

Comments
 (0)