@devries-cameron20 / t3code Mirror · read-only / commits / 94ec6097c6
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 23, 00:30 UTC

fix(pi): T3's orchestration guidance no longer overrides other extensions' prompt changes (#18933)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

chrisb4096-alt committed Oct 19, 2026 at 19:16 UTC 94ec6097c60adfba9c1493756cbcdb8bcc9c4d87
3 files changed +64 -6
packages/provider-pi/src/server/mcpBridge.testkit.ts
+5 -2
@@ -29,12 +29,15 @@ interface RegisteredTool {
29 }
30
31 type AgentStartHook = (
32 - event: { systemPrompt: string },
32 + event: {
33 + systemPrompt: string;
34 + systemPromptOptions?: { sections?: Record<string, string> | null; forceSystemPrompt?: string };
35 + },
36 ctx: {
37 model?: { api: string };
38 ui: { notify: (message: string, severity: string) => void };
39 },
37 -) => Promise<{ systemPrompt: string }>;
40 +) => Promise<{ systemPrompt: string } | undefined>;
41
42 export async function loadMcpBridge(
43 options: {
packages/provider-pi/src/server/mcpExtensionSource.test.ts
+52 -1
@@ -46,6 +46,57 @@ async function loadHooks(commands: ReadonlyArray<SkillCommand> = []) {
46 return handlers;
47 }
48
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 +
100 describe("Pi MCP tool results", () => {
101 it("returns mixed screenshot blocks and typed script output without repeating structured text", async () => {
102 const content = [
@@ -143,7 +194,7 @@ describe("Pi MCP tool exposure", () => {
194 const start = bridge.handlers.get("before_agent_start");
195 assert.isDefined(start);
196 const prompt = await start!({ systemPrompt: "Pi system prompt" }, discoveryContext);
146 - assert.include(prompt.systemPrompt, "orchestrator_capabilities");
197 + assert.include(prompt?.systemPrompt ?? "", "orchestrator_capabilities");
198 assert.equal(bridge.servers.length, 0);
199 assert.equal(bridge.tools.length, 8);
200 assert.deepEqual(bridge.getActiveTools(), ["read", "tool_search"]);
packages/provider-pi/src/server/mcpExtensionSource.ts
+7 -3
@@ -448,11 +448,15 @@ export default async function t3McpExtension(pi: ExtensionAPI) {
448 }
449 });
450
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.
452 pi.on("before_agent_start", (event, ctx) => {
453 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 + }
460 return { systemPrompt: event.systemPrompt + "\\n\\n" + ORCHESTRATION_INSTRUCTIONS };
461 });
462 }