The best way to control Claude Code, Codex and more from any computer or phone
fix(pi): long tool calls no longer share a session approval with different calls (#34528)
Co-authored-by: maria-rcks <254055478+maria-rcks@users.noreply.github.com>
maria committed
Nov 12, 2026 at 00:23 UTC
b9d9aab2349eff1a974294c4a259c8312721af78
3 files changed
+38
-2
packages/provider-pi/src/server/mcpBridge.testkit.ts
+2
@@ -1,4 +1,5 @@
1
// @effect-diagnostics nodeBuiltinImport:off -- Executes the shipped Pi extension at its native JavaScript boundary.
2
+import * as NodeCrypto from "node:crypto";
3
import * as NodeModule from "node:module";
4
import * as NodePath from "node:path";
5
import * as NodeVM from "node:vm";
@@ -95,6 +96,7 @@ export async function loadMcpBridge(
96
},
97
},
98
AbortSignal,
99
+ NodeCrypto,
100
NodePath,
101
Type: { Unsafe: (schema: unknown) => schema },
102
fetch: async (
packages/provider-pi/src/server/mcpExtensionSource.test.ts
+26
@@ -400,6 +400,32 @@ describe("Pi tool discovery permissions", () => {
400
assert.equal(replaced?.block, true);
401
assert.equal(confirmations.at(-1), "Allow tool_search?");
402
});
403
+
404
+ it("gives long inputs that differ past the shown text different confirmation details", async () => {
405
+ const bridge = await loadMcpBridge({ runtimeMode: "approval-required" });
406
+ const hook = bridge.handlers.get("tool_call") as unknown as (
407
+ event: { toolName: string; input: unknown },
408
+ ctx: { ui: { confirm: (title: string, detail: string) => Promise<boolean> } },
409
+ ) => Promise<{ block: true; reason: string } | undefined>;
410
+ const details: string[] = [];
411
+ const ctx = {
412
+ ui: {
413
+ confirm: async (_title: string, detail: string) => {
414
+ details.push(detail);
415
+ return true;
416
+ },
417
+ },
418
+ };
419
+ const filler = "a".repeat(4_100);
420
+ await hook({ toolName: "bash", input: { command: filler + "\necho one" } }, ctx);
421
+ await hook({ toolName: "bash", input: { command: filler + "\necho two" } }, ctx);
422
+ await hook({ toolName: "bash", input: { command: "ls" } }, ctx);
423
+ const [first, second, short] = details;
424
+ assert.equal(first!.slice(0, 4_000), second!.slice(0, 4_000));
425
+ assert.notEqual(first, second);
426
+ assert.match(first!, /\n\.\.\. \d+ more characters not shown \(sha256 [0-9a-f]{64}\)$/);
427
+ assert.equal(short, JSON.stringify({ command: "ls" }, null, 2));
428
+ });
429
});
430
431
async function loadRequestHook() {
packages/provider-pi/src/server/mcpExtensionSource.ts
+10
-2
@@ -14,6 +14,7 @@ export const PI_FILE_CHANGE_TOOLS = ["edit", "write"] as const;
14
15
export const PI_T3_MCP_EXTENSION_SOURCE = `\
16
import { stripFrontmatter, type ExtensionAPI, type ExtensionContext } from "@earendil-works/pi-coding-agent";
17
+import * as NodeCrypto from "node:crypto";
18
import * as NodeFSP from "node:fs/promises";
19
import * as NodePath from "node:path";
20
import { Type } from "typebox";
@@ -61,12 +62,19 @@ function runtimeMode(): RuntimeMode {
62
: "full-access";
63
}
64
65
+// T3 keys "Always allow this session" on this text, so a cut summary ends with the
66
+// full input's hash: calls that differ only past the cut get separate grants.
67
function toolInputSummary(input: unknown): string {
68
+ let text: string;
69
try {
66
- return JSON.stringify(input, null, 2).slice(0, 4_000);
70
+ text = JSON.stringify(input, null, 2) ?? String(input);
71
} catch {
68
- return String(input).slice(0, 4_000);
72
+ text = String(input);
73
}
74
+ if (text.length <= 4_000) return text;
75
+ const hash = NodeCrypto.createHash("sha256").update(text, "utf16le").digest("hex");
76
+ return text.slice(0, 4_000) + "\\n... " + (text.length - 4_000) +
77
+ " more characters not shown (sha256 " + hash + ")";
78
}
79
80
function parseSseOrJson(body: string, contentType: string): JsonRpcResponse {