Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pi-extension/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ export default function ponytailExtension(pi) {

pi.on("before_agent_start", async (event) => {
if (!currentMode || currentMode === "off") return;
return { systemPrompt: `${event.systemPrompt}\n\n${getPonytailInstructions(currentMode)}` };
return { systemPrompt: `${event?.systemPrompt ?? ""}\n\n${getPonytailInstructions(currentMode)}` };
});

}
36 changes: 36 additions & 0 deletions pi-extension/test/extension.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,39 @@ test("status bar stays silent when ui lacks a theme", async () => withTempConfig

assert.deepEqual(calls, []);
}));

// Regression: before_agent_start must not throw when event is null/undefined
// or when event is a truthy object without a systemPrompt key (issue #439).
test("before_agent_start: null event does not throw", async () => withTempConfig(async () => {
const { commands, events } = createPiHarness();
const ctx = createCommandContext();
await events.get("session_start")({ reason: "startup" }, ctx);
await commands.get("ponytail").handler("full", ctx);

const result = await events.get("before_agent_start")(null, ctx);
assert.ok(result.systemPrompt.includes("PONYTAIL MODE ACTIVE"), "instructions present even with null event");
assert.ok(!result.systemPrompt.includes("undefined"), "no literal 'undefined' in output");
}));

test("before_agent_start: undefined event does not throw", async () => withTempConfig(async () => {
const { commands, events } = createPiHarness();
const ctx = createCommandContext();
await events.get("session_start")({ reason: "startup" }, ctx);
await commands.get("ponytail").handler("full", ctx);

const result = await events.get("before_agent_start")(undefined, ctx);
assert.ok(result.systemPrompt.includes("PONYTAIL MODE ACTIVE"), "instructions present even with undefined event");
assert.ok(!result.systemPrompt.includes("undefined"), "no literal 'undefined' in output");
}));

test("before_agent_start: truthy event without systemPrompt does not produce 'undefined' prefix", async () => withTempConfig(async () => {
const { commands, events } = createPiHarness();
const ctx = createCommandContext();
await events.get("session_start")({ reason: "startup" }, ctx);
await commands.get("ponytail").handler("full", ctx);

const result = await events.get("before_agent_start")({}, ctx);
assert.ok(result.systemPrompt.includes("PONYTAIL MODE ACTIVE"), "instructions present");
assert.ok(!result.systemPrompt.startsWith("undefined"), "no literal 'undefined' prefix");
}));

Loading