Skip to content

Commit 83e5b85

Browse files
fix(pi): retain guidance after earlier prompt overrides
1 parent 38bd358 commit 83e5b85

3 files changed

Lines changed: 23 additions & 9 deletions

File tree

‎packages/provider-pi/src/server/mcpBridge.testkit.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ interface RegisteredTool {
3131
type AgentStartHook = (
3232
event: {
3333
systemPrompt: string;
34-
systemPromptOptions?: { sections?: Record<string, string> | null };
34+
systemPromptOptions?: { sections?: Record<string, string> | null; forceSystemPrompt?: string };
3535
},
3636
ctx: {
3737
model?: { api: string };

‎packages/provider-pi/src/server/mcpExtensionSource.test.ts‎

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,31 @@ describe("Pi orchestration prompt section", () => {
6767
});
6868
});
6969

70-
it("appends guidance on Pi builds without prompt sections", async () => {
70+
it.each([
71+
{
72+
name: "on Pi builds without prompt sections",
73+
events: [
74+
{ systemPrompt: "base" },
75+
{ systemPrompt: "base", systemPromptOptions: {} },
76+
{ systemPrompt: "base", systemPromptOptions: { sections: null } },
77+
],
78+
},
79+
{
80+
name: "when an earlier extension forces the system prompt",
81+
events: [
82+
{
83+
systemPrompt: "forced",
84+
systemPromptOptions: { sections: {}, forceSystemPrompt: "forced" },
85+
},
86+
],
87+
},
88+
])("appends guidance $name", async ({ events }) => {
7189
const bridge = await loadMcpBridge();
7290
const hook = bridge.handlers.get("before_agent_start")!;
73-
for (const event of [
74-
{ systemPrompt: "base" },
75-
{ systemPrompt: "base", systemPromptOptions: {} },
76-
{ systemPrompt: "base", systemPromptOptions: { sections: null } },
77-
]) {
91+
for (const event of events) {
7892
const result = await hook(event, { ui: { notify: assert.fail } });
7993
assert.isDefined(result);
80-
assert.isTrue(result!.systemPrompt.startsWith("base\n\n"));
94+
assert.isTrue(result!.systemPrompt.startsWith(`${event.systemPrompt}\n\n`));
8195
assert.include(result!.systemPrompt, "orchestrator_capabilities");
8296
}
8397
});

‎packages/provider-pi/src/server/mcpExtensionSource.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ export default async function t3McpExtension(pi: ExtensionAPI) {
452452
pi.on("before_agent_start", (event, ctx) => {
453453
reconcileDiscovery(ctx);
454454
const sections = event.systemPromptOptions?.sections;
455-
if (sections && typeof sections === "object") {
455+
if (sections && typeof sections === "object" && event.systemPromptOptions?.forceSystemPrompt === undefined) {
456456
// A full prompt override bypasses Pi's later section rendering.
457457
sections.t3_code_orchestration = ORCHESTRATION_INSTRUCTIONS;
458458
return undefined;

0 commit comments

Comments
 (0)