Skip to content

Commit 94ec609

Browse files
fix(pi): T3's orchestration guidance no longer overrides other extensions' prompt changes (pingdotgg#18933)
Co-authored-by: Julius Marminge <[email protected]>
1 parent 232e930 commit 94ec609

3 files changed

Lines changed: 64 additions & 6 deletions

File tree

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,15 @@ interface RegisteredTool {
2929
}
3030

3131
type AgentStartHook = (
32-
event: { systemPrompt: string },
32+
event: {
33+
systemPrompt: string;
34+
systemPromptOptions?: { sections?: Record<string, string> | null; forceSystemPrompt?: string };
35+
},
3336
ctx: {
3437
model?: { api: string };
3538
ui: { notify: (message: string, severity: string) => void };
3639
},
37-
) => Promise<{ systemPrompt: string }>;
40+
) => Promise<{ systemPrompt: string } | undefined>;
3841

3942
export async function loadMcpBridge(
4043
options: {

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

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,57 @@ async function loadHooks(commands: ReadonlyArray<SkillCommand> = []) {
4646
return handlers;
4747
}
4848

49+
describe("Pi orchestration prompt section", () => {
50+
it("adds a stable section without overriding the prompt or skipping discovery", async () => {
51+
const bridge = await loadMcpBridge({ modern: true, toolSearchAvailable: true });
52+
const hook = bridge.handlers.get("before_agent_start")!;
53+
const sections: Record<string, string> = { existing: "keep me" };
54+
const event = { systemPrompt: "base", systemPromptOptions: { sections } };
55+
const ctx = { model: { api: "openai-completions" }, ui: { notify: assert.fail } };
56+
57+
assert.isUndefined(await hook(event, ctx));
58+
assert.include(sections.t3_code_orchestration, "orchestrator_capabilities");
59+
assert.equal(event.systemPrompt, "base");
60+
assert.include(bridge.getActiveTools(), "mcp__t3-code__preview_snapshot");
61+
62+
const guidance = sections.t3_code_orchestration!;
63+
assert.isUndefined(await hook(event, ctx));
64+
assert.deepEqual(event.systemPromptOptions.sections, {
65+
existing: "keep me",
66+
t3_code_orchestration: guidance,
67+
});
68+
});
69+
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 }) => {
89+
const bridge = await loadMcpBridge();
90+
const hook = bridge.handlers.get("before_agent_start")!;
91+
for (const event of events) {
92+
const result = await hook(event, { ui: { notify: assert.fail } });
93+
assert.isDefined(result);
94+
assert.isTrue(result!.systemPrompt.startsWith(`${event.systemPrompt}\n\n`));
95+
assert.include(result!.systemPrompt, "orchestrator_capabilities");
96+
}
97+
});
98+
});
99+
49100
describe("Pi MCP tool results", () => {
50101
it("returns mixed screenshot blocks and typed script output without repeating structured text", async () => {
51102
const content = [
@@ -143,7 +194,7 @@ describe("Pi MCP tool exposure", () => {
143194
const start = bridge.handlers.get("before_agent_start");
144195
assert.isDefined(start);
145196
const prompt = await start!({ systemPrompt: "Pi system prompt" }, discoveryContext);
146-
assert.include(prompt.systemPrompt, "orchestrator_capabilities");
197+
assert.include(prompt?.systemPrompt ?? "", "orchestrator_capabilities");
147198
assert.equal(bridge.servers.length, 0);
148199
assert.equal(bridge.tools.length, 8);
149200
assert.deepEqual(bridge.getActiveTools(), ["read", "tool_search"]);

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -448,11 +448,15 @@ export default async function t3McpExtension(pi: ExtensionAPI) {
448448
}
449449
});
450450
451-
// Deliver orchestration guidance through pi's real system-prompt channel.
452-
// Wrapping the first user message instead would stop it from starting
453-
// with "/" and silently break slash-command expansion.
451+
// Keep guidance in the system prompt so leading slash commands still expand.
454452
pi.on("before_agent_start", (event, ctx) => {
455453
reconcileDiscovery(ctx);
454+
const sections = event.systemPromptOptions?.sections;
455+
if (sections && typeof sections === "object" && event.systemPromptOptions?.forceSystemPrompt === undefined) {
456+
// A full prompt override bypasses Pi's later section rendering.
457+
sections.t3_code_orchestration = ORCHESTRATION_INSTRUCTIONS;
458+
return undefined;
459+
}
456460
return { systemPrompt: event.systemPrompt + "\\n\\n" + ORCHESTRATION_INSTRUCTIONS };
457461
});
458462
}

0 commit comments

Comments
 (0)