@geohar/pi-mcp-combiner 0.16.0-dev.4 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/dist/client/proxy-tool.d.ts +2 -0
  2. package/dist/client/proxy-tool.d.ts.map +1 -1
  3. package/dist/client/proxy-tool.js +24 -8
  4. package/dist/client/proxy-tool.js.map +1 -1
  5. package/dist/client/render.d.ts +45 -5
  6. package/dist/client/render.d.ts.map +1 -1
  7. package/dist/client/render.js +95 -13
  8. package/dist/client/render.js.map +1 -1
  9. package/dist/client/runner-stale.d.ts +26 -0
  10. package/dist/client/runner-stale.d.ts.map +1 -0
  11. package/dist/client/runner-stale.js +57 -0
  12. package/dist/client/runner-stale.js.map +1 -0
  13. package/dist/client/settings.d.ts +5 -0
  14. package/dist/client/settings.d.ts.map +1 -1
  15. package/dist/client/settings.js +12 -0
  16. package/dist/client/settings.js.map +1 -1
  17. package/dist/client/widget-support.d.ts +1 -5
  18. package/dist/client/widget-support.d.ts.map +1 -1
  19. package/dist/client/widget-support.js +7 -50
  20. package/dist/client/widget-support.js.map +1 -1
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.js +2 -0
  23. package/dist/index.js.map +1 -1
  24. package/dist/native/combiner-connection.js +1 -1
  25. package/dist/native/combiner-connection.js.map +1 -1
  26. package/dist/native/index.d.ts +3 -0
  27. package/dist/native/index.d.ts.map +1 -1
  28. package/dist/native/index.js +2 -0
  29. package/dist/native/index.js.map +1 -1
  30. package/dist/native/resources.d.ts +2 -0
  31. package/dist/native/resources.d.ts.map +1 -1
  32. package/dist/native/resources.js +11 -2
  33. package/dist/native/resources.js.map +1 -1
  34. package/dist/native/tool-surface.d.ts +4 -0
  35. package/dist/native/tool-surface.d.ts.map +1 -1
  36. package/dist/native/tool-surface.js +25 -4
  37. package/dist/native/tool-surface.js.map +1 -1
  38. package/dist/pi.d.ts +6 -0
  39. package/dist/pi.d.ts.map +1 -1
  40. package/package.json +1 -1
  41. package/src/client/proxy-tool.ts +36 -9
  42. package/src/client/render.ts +130 -13
  43. package/src/client/runner-stale.ts +66 -0
  44. package/src/client/settings.ts +17 -0
  45. package/src/client/widget-support.ts +7 -42
  46. package/src/index.ts +2 -0
  47. package/src/native/combiner-connection.ts +1 -1
  48. package/src/native/index.ts +5 -0
  49. package/src/native/resources.ts +13 -2
  50. package/src/native/tool-surface.ts +34 -4
  51. package/src/pi.ts +4 -0
package/dist/pi.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"pi.d.ts","sourceRoot":"","sources":["../src/pi.ts"],"names":[],"mappings":"AAUA,MAAM,MAAM,kBAAkB,GAAG,SAAS,GAAG,QAAQ,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAA;AACjF,MAAM,MAAM,qBAAqB,GAAG,MAAM,GAAG,QAAQ,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAA;AAEjF,MAAM,MAAM,iBAAiB,GAAG;IAAE,MAAM,EAAE,kBAAkB,CAAC;IAAC,mBAAmB,CAAC,EAAE,MAAM,CAAA;CAAE,CAAA;AAC5F,MAAM,MAAM,oBAAoB,GAAG;IAAE,MAAM,EAAE,qBAAqB,CAAC;IAAC,iBAAiB,CAAC,EAAE,MAAM,CAAA;CAAE,CAAA;AAChG,MAAM,MAAM,qBAAqB,GAAG;IAAE,YAAY,EAAE,MAAM,CAAA;CAAE,CAAA;AAC5D,MAAM,MAAM,sBAAsB,GAAG;IAAE,YAAY,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAAA;AAErE,MAAM,MAAM,gBAAgB,GAAG;IAC3B,GAAG,EAAE,MAAM,CAAA;IACX,IAAI,EAAE,KAAK,GAAG,KAAK,GAAG,MAAM,GAAG,OAAO,CAAA;IACtC,KAAK,EAAE,OAAO,CAAA;IACd,MAAM,CAAC,EAAE,WAAW,CAAA;IACpB,EAAE,CAAC,EAAE,kBAAkB,CAAA;IACvB,c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AAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,CAAA;IACjF,WAAW,CAAC,OAAO,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,IAAI,CAAA;CACxE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geohar/pi-mcp-combiner",
3
- "version": "0.16.0-dev.4",
3
+ "version": "0.17.0",
4
4
  "description": "Pi extension: run the mcp-combiner MCP aggregator via sharedserver and inject its tool-discovery directive. Pairs with pi-mcp-adapter, which makes the combiner's tools reachable from Pi.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -11,16 +11,25 @@
11
11
  // does). No custom renderers — pi's default tool rendering.
12
12
 
13
13
  import { spawn } from "node:child_process"
14
- import type { ToolCallContext, ToolDefinition } from "../pi.js"
14
+ import { safeHasUi, safeModel } from "./runner-stale.js"
15
+ import type { ToolDefinition } from "../pi.js"
15
16
  import type { CombinerConnection, ToolSummary } from "./types.js"
16
17
  import { compileSafeRegex, rankTools, regexMatches, type SearchableTool } from "./ranking.js"
17
- import { renderDescribe, renderSearchHit, renderToolResult, textResult, toolUiResourceUri } from "./render.js"
18
+ import {
19
+ renderDescribe,
20
+ renderSearchHit,
21
+ renderToolResultBlocks,
22
+ textResult,
23
+ toolUiResourceUri,
24
+ } from "./render.js"
18
25
  import { proxyRenderers } from "./renderers.js"
19
26
 
20
27
  export type ProxyToolDeps = {
21
28
  connection: CombinerConnection
22
29
  /** Human label for error messages, e.g. "mcp". */
23
30
  toolName: string
31
+ /** Cap on guarded tool-result text before spill-to-file (maxResultChars setting). */
32
+ maxResultChars?: number
24
33
  /** Client-side server filter (mirrors the combiner-side token filter) — a GETTER
25
34
  * so per-session re-resolution (worktrees, project switch) applies mid-flight. */
26
35
  getServerFilter?: () => { allow?: string[]; deny?: string[] } | undefined
@@ -41,20 +50,24 @@ export function openInBrowser(url: string): void {
41
50
  }
42
51
  }
43
52
 
44
- /** Append the interactive-UI line + auto-open for results carrying a ui:// resource. */
53
+ /** Append the interactive-UI line + auto-open for results carrying a ui:// resource.
54
+ * Takes the hasUi BOOLEAN resolved at execute entry (see client/runner-stale.ts):
55
+ * reading ctx here — after the upstream call already ran — would let the reload
56
+ * window's throwing getter (pi#10599) turn a completed call into a rejection the
57
+ * model might retry, re-executing it. */
45
58
  function withUiResource(
46
59
  connection: CombinerConnection,
47
60
  deps: { uiAutoOpen?: boolean },
48
61
  text: string,
49
62
  result: unknown,
50
- ctx: ToolCallContext | undefined,
63
+ hasUi: boolean,
51
64
  ): string {
52
65
  const uri = toolUiResourceUri(result)
53
66
  if (!uri) return text
54
67
  const url = connection.uiUrlFor(uri)
55
68
  if (!url) return text
56
- if (deps.uiAutoOpen !== false && ctx?.hasUI) openInBrowser(url)
57
- return `${text}\n\ninteractive: ${url}${deps.uiAutoOpen !== false && ctx?.hasUI ? " (opened in your browser)" : ""}`
69
+ if (deps.uiAutoOpen !== false && hasUi) openInBrowser(url)
70
+ return `${text}\n\ninteractive: ${url}${deps.uiAutoOpen !== false && hasUi ? " (opened in your browser)" : ""}`
58
71
  }
59
72
 
60
73
  const PARAMETERS: Record<string, unknown> = {
@@ -141,6 +154,10 @@ export function createMcpTool(deps: ProxyToolDeps): ToolDefinition {
141
154
  parameters: PARAMETERS,
142
155
  ...proxyRenderers(toolName),
143
156
  execute: async (_toolCallId, params, _signal, _onUpdate, ctx) => {
157
+ // SAFETY: read the guarded ctx ONCE, before any await (runner-stale
158
+ // rule) — never re-enter ctx after the upstream call ran.
159
+ const hasUi = safeHasUi(ctx)
160
+ const model = safeModel(ctx)
144
161
  const p = params as Record<string, unknown>
145
162
  // ── call ──
146
163
  if (typeof p.tool === "string" && p.tool) {
@@ -163,10 +180,20 @@ export function createMcpTool(deps: ProxyToolDeps): ToolDefinition {
163
180
  )
164
181
  }
165
182
  const result = await connection.callTool(match!.name, args)
166
- const raw = renderToolResult(result)
167
- const text = withUiResource(connection, deps, raw, result, ctx)
183
+ const rendered = await renderToolResultBlocks(
184
+ result,
185
+ { maxResultChars: deps.maxResultChars, model },
186
+ match!.name,
187
+ )
188
+ const text = withUiResource(connection, deps, rendered.text, result, hasUi)
168
189
  if ((result as { isError?: boolean })?.isError) throw new Error(text)
169
- return textResult(text, { mode: "call", tool: match!.name, server: serverOf(match!.name) })
190
+ const details: Record<string, unknown> = {
191
+ mode: "call",
192
+ tool: match!.name,
193
+ server: serverOf(match!.name),
194
+ }
195
+ if (rendered.spillPath) details.full_output_path = rendered.spillPath
196
+ return { content: rendered.content, details }
170
197
  }
171
198
 
172
199
  // ── describe ──
@@ -1,14 +1,25 @@
1
1
  // describe/call output shaping: TS-shape schema rendering, result guarding, compact
2
2
  // text rendering. Lean versions of pi-mcp-adapter's tool-metadata / mcp-output-guard /
3
3
  // tool-result-renderer trio (MIT, © 2026 Nico Bailon) — one server, text-first.
4
+ //
5
+ // Oversized results SPILL rather than silently cut (the pi bash/read/codemode
6
+ // pattern): the head stays LLM-visible, the full text goes to a 0600 temp file and
7
+ // the truncated notice names it, so the call stays recoverable via `read` instead of
8
+ // ending mid-JSON with no continuation story. Images survive as REAL image blocks on
9
+ // the blocks path (pi normalizes + resizes them into history; provider adapters drop
10
+ // them for non-vision models with an omission note).
11
+
12
+ import { mkdtemp, writeFile } from "node:fs/promises"
13
+ import { tmpdir } from "node:os"
14
+ import { join } from "node:path"
4
15
 
5
16
  import { renderSchemaSignature } from "./schema-signature.js"
6
17
 
7
- import type { TextBlock, ToolResult } from "../pi.js"
18
+ import type { ImageBlock, TextBlock, ToolResult } from "../pi.js"
8
19
 
9
20
  /** Wrap guarded text as a pi tool result (content-blocks contract). */
10
21
  export function textResult(text: string, details?: unknown): ToolResult {
11
- const content: TextBlock[] = [{ type: "text", text }]
22
+ const content: (TextBlock | ImageBlock)[] = [{ type: "text", text }]
12
23
  return details === undefined ? { content } : { content, details }
13
24
  }
14
25
 
@@ -29,8 +40,68 @@ export type ToolInfo = {
29
40
  inputSchema?: unknown
30
41
  }
31
42
 
43
+ /** Default cap on guarded text before spill (kept in one place; the live cap is
44
+ * the `maxResultChars` setting, threaded through from index.ts). */
32
45
  export const MAX_RESULT_CHARS = 16 * 1024
33
46
 
47
+ /** Options for the guarded renderers. */
48
+ export type RenderOptions = {
49
+ /** Char cap before spilling (default MAX_RESULT_CHARS; min 1024). */
50
+ maxResultChars?: number
51
+ /** Active model — when it cannot see images, image blocks become omission notes
52
+ * instead (read-tool parity). Omit to forward images unconditionally. */
53
+ model?: { input?: string[] }
54
+ }
55
+
56
+ /** Clamp a caller-provided char cap into a sane band. */
57
+ function limitFor(max: number | undefined): number {
58
+ if (typeof max !== "number" || !Number.isFinite(max)) return MAX_RESULT_CHARS
59
+ return Math.min(4 * 1024 * 1024, Math.max(1024, Math.floor(max)))
60
+ }
61
+
62
+ /** UTF-16 surrogate-safe cut: never end the head with a lone high surrogate, so
63
+ * the truncated notice never glues itself into a split code point. */
64
+ function safeCut(text: string, at: number): string {
65
+ if (at <= 0 || at >= text.length) return at >= text.length ? text : ""
66
+ const last = text.charCodeAt(at - 1)
67
+ return last >= 0xd800 && last < 0xdc00 ? text.slice(0, at - 1) : text.slice(0, at)
68
+ }
69
+
70
+ /** Spill full text to a 0600 temp file (pi's truncated-output convention —
71
+ * user-readable only, like the bash tool's spill and codemode's images). */
72
+ export async function spillResultText(text: string, toolName: string): Promise<string | undefined> {
73
+ try {
74
+ const dir = await mkdtemp(join(tmpdir(), "pi-mcp-"))
75
+ const safe = toolName.replace(/[^a-zA-Z0-9_-]/g, "_").slice(0, 60) || "tool"
76
+ const path = join(dir, `${safe}.txt`)
77
+ await writeFile(path, text, { mode: 0o600 })
78
+ return path
79
+ } catch {
80
+ return undefined // spill failure degrades to the head-only result
81
+ }
82
+ }
83
+
84
+ export type GuardedText = {
85
+ /** Head (LLM-visible) + truncated notice when over the cap. */
86
+ text: string
87
+ /** Set when the full text was spilled to a temp file. */
88
+ spillPath?: string
89
+ }
90
+
91
+ /** Guard a rendered text against the char cap: under the cap → verbatim; over →
92
+ * surrogate-safe head + notice naming the spill file. Never cuts mid-JSON without
93
+ * a recovery story: the notice line tells the caller where the rest lives. */
94
+ export async function guardedText(text: string, opts: RenderOptions, label: string): Promise<GuardedText> {
95
+ const max = limitFor(opts.maxResultChars)
96
+ if (text.length <= max) return { text }
97
+ const spillPath = await spillResultText(text, label)
98
+ const head = safeCut(text, max)
99
+ const notice = spillPath
100
+ ? `\n\n[Truncated: showing first ${head.length} of ${text.length} chars. Full content: ${spillPath} (read with offset/limit)]`
101
+ : `\n\n[Truncated: showing first ${head.length} of ${text.length} chars — full contents could not be saved; narrow the call or paginate]`
102
+ return { text: head + notice, spillPath }
103
+ }
104
+
34
105
  /** Fallback describe-rendering of a JSON schema when the signature renderer bails (union-heavy,
35
106
  * conditional schemas): one level of properties with type + required markers. */
36
107
  function renderJsonSchemaShape(schema: unknown, indent = 0): string {
@@ -89,24 +160,71 @@ function prettifyIfSmallJson(text: string, maxPrettyChars = 2048): string {
89
160
  }
90
161
  }
91
162
 
92
- export function renderToolResult(result: unknown): string {
163
+ export type RenderedToolResult = {
164
+ /** Joined, guarded text (what the string API and error paths surface). */
165
+ text: string
166
+ /** Full content for a pi tool result: the guarded text block plus REAL image
167
+ * blocks (dropped to omission notes when the active model is non-vision). */
168
+ content: (TextBlock | ImageBlock)[]
169
+ /** Spill file path when the text was truncated. */
170
+ spillPath?: string
171
+ }
172
+
173
+ /** Non-vision gate (read-tool parity): pi's provider adapters also omit image
174
+ * blocks for text-only models, but the explicit note keeps the model informed. */
175
+ function nonVision(model: RenderOptions["model"]): boolean {
176
+ return Boolean(model && Array.isArray(model.input) && !model.input.includes("image"))
177
+ }
178
+
179
+ /** MCP tool result → guarded text AND content blocks. Text joins, pretty-prints
180
+ * (small JSON), and spills when oversized; images stay REAL blocks so the model
181
+ * sees them and codemode scripts can `image(block)` them. */
182
+ export async function renderToolResultBlocks(
183
+ result: unknown,
184
+ opts: RenderOptions = {},
185
+ label = "tool",
186
+ ): Promise<RenderedToolResult> {
187
+ const { text: joined, images } = renderToolTextParts(result)
188
+ const guarded = await guardedText(joined, opts, label)
189
+ const content: (TextBlock | ImageBlock)[] = [{ type: "text", text: guarded.text }]
190
+ for (const block of images) {
191
+ content.push(nonVision(opts.model) ? { type: "text", text: NON_VISION_NOTE } : block)
192
+ }
193
+ const out: RenderedToolResult = { text: guarded.text, content }
194
+ if (guarded.spillPath) out.spillPath = guarded.spillPath
195
+ return out
196
+ }
197
+
198
+ /** String API (script tool's tools.call, resource reads): guarded text only; images
199
+ * stay one-line placeholders. */
200
+ export async function renderToolResult(result: unknown, opts: RenderOptions = {}, label = "tool"): Promise<string> {
201
+ return (await renderToolResultBlocks(result, opts, label)).text
202
+ }
203
+
204
+ /** Joined text + surviving image blocks from an MCP tool result's content. */
205
+ function renderToolTextParts(result: unknown): { text: string; images: ImageBlock[] } {
93
206
  const blocks = (result as { content?: unknown[] })?.content
94
207
  if (!Array.isArray(blocks) || blocks.length === 0) {
95
208
  // Structured-content fallback (adapter parity): tools returning only
96
209
  // structuredContent otherwise lose their payload to "(empty result)".
97
210
  const structured = (result as { structuredContent?: unknown })?.structuredContent
98
211
  if (structured !== undefined && structured !== null) {
99
- return renderToolResult({ content: [{ type: "text", text: JSON.stringify(structured) }] })
212
+ return renderToolTextParts({ content: [{ type: "text", text: JSON.stringify(structured) }] })
100
213
  }
101
- return "(empty result)"
214
+ return { text: "(empty result)", images: [] }
102
215
  }
103
216
  const parts: string[] = []
217
+ const images: ImageBlock[] = []
104
218
  for (const b of blocks) {
105
219
  if (typeof b !== "object" || b === null) continue
106
220
  const block = b as Record<string, unknown>
107
221
  if (typeof block.text === "string") {
108
222
  parts.push(prettifyIfSmallJson(block.text))
223
+ } else if (block.type === "image" && typeof block.data === "string") {
224
+ const mimeType = typeof block.mimeType === "string" ? block.mimeType : "unknown"
225
+ images.push({ type: "image", data: block.data, mimeType })
109
226
  } else if (block.type === "image") {
227
+ // No data (or an upstream placeholder) — keep a marker so the block isn't lost.
110
228
  parts.push(`[image: ${typeof block.mimeType === "string" ? block.mimeType : "unknown"}]`)
111
229
  } else if (block.type === "resource" || block.type === "embedded_resource") {
112
230
  const resource = block.resource as Record<string, unknown> | undefined
@@ -116,11 +234,11 @@ export function renderToolResult(result: unknown): string {
116
234
  parts.push("[audio output]")
117
235
  }
118
236
  }
119
- const text = parts.join("\n").trim() || "(empty result)"
120
- if (text.length <= MAX_RESULT_CHARS) return text
121
- return `${text.slice(0, MAX_RESULT_CHARS)}\n\n… (output truncated at ${MAX_RESULT_CHARS} chars; narrow the call or paginate)`
237
+ return { text: parts.join("\n").trim() || (images.length ? "(image result)" : "(empty result)"), images }
122
238
  }
123
239
 
240
+ const NON_VISION_NOTE = "[Current model does not support images. The image will be omitted from this request.]"
241
+
124
242
  /** Extract a short first line for compact call-result rendering in the transcript. */
125
243
  export function resultFirstLine(text: string): string {
126
244
  const line = text.split("\n", 1)[0] ?? ""
@@ -139,9 +257,9 @@ export function toolUiResourceUri(result: unknown): string | undefined {
139
257
  }
140
258
 
141
259
  /** MCP readResource result → guarded plain text: text contents pass through
142
- * (pretty-printed when small JSON; with the shared size guard), images become
143
- * markers, base64 blobs become byte notes. */
144
- export function renderResourceResult(result: unknown): string {
260
+ * (pretty-printed when small JSON; spill-to-file guard shared with tool results),
261
+ * images become markers, base64 blobs become byte notes. */
262
+ export async function renderResourceResult(result: unknown, opts: RenderOptions = {}, label = "resource"): Promise<string> {
145
263
  const contents = (result as { contents?: unknown[] })?.contents
146
264
  if (!Array.isArray(contents) || contents.length === 0) return "(empty resource)"
147
265
  const parts: string[] = []
@@ -161,6 +279,5 @@ export function renderResourceResult(result: unknown): string {
161
279
  }
162
280
  }
163
281
  const text = parts.join("\n").trim() || "(empty resource)"
164
- if (text.length <= MAX_RESULT_CHARS) return text
165
- return `${text.slice(0, MAX_RESULT_CHARS)}\n\n… (resource truncated at ${MAX_RESULT_CHARS} chars)`
282
+ return (await guardedText(text, opts, label)).text
166
283
  }
@@ -0,0 +1,66 @@
1
+ // RUNNER-STALE GUARD : pi 1.0 invalidates the extension runner at the TOP of
2
+ // AgentSession.reload() and replaces it at the END (after settings + resource
3
+ // reloads — often seconds). Any guarded ctx read from a callback inside that
4
+ // window throws "This extension ctx is stale after session replacement or
5
+ // reload…" (pi#10599). Two hazards reach us, both handled extension-side:
6
+ //
7
+ // 1. `ctx?.hasUI` guards against null, NOT against a THROWING getter — a tool
8
+ // execute that reads ctx AFTER awaiting upstream work can turn a COMPLETED
9
+ // call into a rejection, and a model retry would then re-execute it.
10
+ // That is why reads here happen ONCE at execute entry and never re-read
11
+ // past an await — the same rule the stale-ctx sweep applied to timers.
12
+ // 2. When such a throw reaches the tool result anyway (pi's emitToolCall has
13
+ // no per-handler catch — pi#10599 issue 2), the raw stale text gives the
14
+ // model nothing to act on. The hint-wrappers below name what happened and
15
+ // when retrying is safe.
16
+ //
17
+ // Retry policy for this class: a retry is safe ONLY when the first attempt
18
+ // provably executed nothing (throw-before-upstream). Our tool executes do not
19
+ // touch guarded ctx before the upstream call, so this module intentionally
20
+ // ships NO automatic retry helper — classification + de-fatalizing reads +
21
+ // hint-wrapping only. (The combiner-connection layer has its own retry for its
22
+ // own staleness class; these are different failures.)
23
+
24
+ export type HasUiCtx = { hasUI?: boolean } | undefined
25
+
26
+ /** Read ctx.hasUI without ever letting the guarded getter throw. For
27
+ * execute-time reads; call BEFORE any await and pass the boolean down. */
28
+ export function safeHasUi(ctx: HasUiCtx): boolean {
29
+ try {
30
+ return Boolean(ctx?.hasUI)
31
+ } catch {
32
+ return false
33
+ }
34
+ }
35
+
36
+ /** Intersected with HasUiCtx (shared `hasUI`) so pi's context types — which don't
37
+ * declare `model` — satisfy TS's weak-type rule (no overlapping properties). */
38
+ export type ModelCtx = HasUiCtx & { model?: { input?: string[] } } | undefined
39
+
40
+ /** Read ctx.model (image support + input limits source, read-tool parity) without
41
+ * ever letting the guarded getter throw. Same execute-time rule as safeHasUi: call
42
+ * BEFORE any await, pass the value down. */
43
+ export function safeModel(ctx: ModelCtx): { input?: string[] } | undefined {
44
+ try {
45
+ return ctx?.model
46
+ } catch {
47
+ return undefined
48
+ }
49
+ }
50
+
51
+ /** True when the error is pi's runner-staleness (pi#10599), whether raw or
52
+ * wrapped by our own catch-rethrows (the stable substring survives both). */
53
+ export function isRunnerStaleError(e: unknown): boolean {
54
+ const msg = e instanceof Error ? e.message : String(e)
55
+ return /ctx is stale after session replacement or reload/i.test(msg)
56
+ }
57
+
58
+ /** Wrap a runner-stale failure in a hint that names what happened and when
59
+ * retrying is safe — instead of surfacing pi's raw assertion text. */
60
+ export function runnerStaleHint(toolLabel: string): string {
61
+ return (
62
+ `${toolLabel}: pi reloaded mid-call and this attempt hit the reload window. ` +
63
+ `If the tool did not run, retry it — upstream state is unchanged; wait a few ` +
64
+ `seconds so the reload finishes first.`
65
+ )
66
+ }
@@ -49,6 +49,11 @@ export type CombinerSettings = {
49
49
  url?: string
50
50
  /** Notify (vs stderr-only) for connection lifecycle messages. */
51
51
  notify: boolean
52
+ /** Cap (chars) on MCP tool-result text before spill-to-file. Oversized results get
53
+ * the head + a notice naming the 0600 temp file with the full content (recoverable
54
+ * via `read`). Env PI_MCP_COMBINER_MAX_RESULT_CHARS wins. Default 16 KiB — was a
55
+ * mid-JSON hard cut with no recovery story. */
56
+ maxResultChars: number
52
57
  }
53
58
 
54
59
  export const DEFAULT_SETTINGS: CombinerSettings = {
@@ -62,6 +67,7 @@ export const DEFAULT_SETTINGS: CombinerSettings = {
62
67
  uiAutoOpen: true,
63
68
  warnLargeDirectExposure: true,
64
69
  notify: true,
70
+ maxResultChars: 16 * 1024,
65
71
  }
66
72
 
67
73
  /** Pi's agent dir: `$PI_CODING_AGENT_DIR` when set, else the first existing of the
@@ -106,5 +112,16 @@ export function loadSettings(path = settingsPath()): CombinerSettings {
106
112
  if (typeof d.warnLargeDirectExposure === "boolean") out.warnLargeDirectExposure = d.warnLargeDirectExposure
107
113
  if (typeof d.url === "string" && d.url.trim()) out.url = d.url.trim()
108
114
  if (typeof d.notify === "boolean") out.notify = d.notify
115
+ if (typeof d.maxResultChars === "number" && Number.isFinite(d.maxResultChars)) {
116
+ out.maxResultChars = clampResultChars(d.maxResultChars)
117
+ }
118
+ // Env wins over the file (same precedence as PI_MCP_COMBINER_TOOL_NAME in index.ts).
119
+ const envChars = Number(process.env.PI_MCP_COMBINER_MAX_RESULT_CHARS)
120
+ if (Number.isFinite(envChars) && envChars > 0) out.maxResultChars = clampResultChars(envChars)
109
121
  return out
110
122
  }
123
+
124
+ /** Sanity band for the result cap: low but readable ceiling/floor. */
125
+ function clampResultChars(n: number): number {
126
+ return Math.min(4 * 1024 * 1024, Math.max(1024, Math.floor(n)))
127
+ }
@@ -11,7 +11,10 @@
11
11
  import { spawn } from "node:child_process"
12
12
  import type { ResourceSummary } from "./types.js"
13
13
 
14
- export const MAX_RESULT_CHARS = 16 * 1024
14
+ // The shared guarded resource read (pretty-print small JSON, spill over the cap)
15
+ // lives in render.ts — re-exported so the native resource surface keeps importing
16
+ // from here until the legacy-client factoring completes.
17
+ export { renderResourceResult } from "./render.js"
15
18
 
16
19
  export const MCP_APP_MIME = "text/html;profile=mcp-app"
17
20
 
@@ -43,44 +46,6 @@ export function toolUiResourceUri(result: unknown): string | undefined {
43
46
  return typeof uri === "string" && uri.startsWith("ui://") ? uri : undefined
44
47
  }
45
48
 
46
- const maxPrettyCharsDefault = 2048
47
-
48
- function prettifyIfSmallJson(text: string, maxPrettyChars = maxPrettyCharsDefault): string {
49
- const trimmed = text.trim()
50
- if (trimmed.length === 0 || trimmed.length > maxPrettyChars) return text
51
- if (!(trimmed.startsWith("{") || trimmed.startsWith("["))) return text
52
- try {
53
- const parsed: unknown = JSON.parse(trimmed)
54
- if (typeof parsed !== "object" || parsed === null) return text
55
- return JSON.stringify(parsed, null, 2)
56
- } catch {
57
- return text
58
- }
59
- }
60
-
61
- /** MCP readResource result → guarded plain text: text contents pass through
62
- * (pretty-printed when small JSON; with the shared size guard), images become
63
- * markers, base64 blobs become byte notes. */
64
- export function renderResourceResult(result: unknown): string {
65
- const contents = (result as { contents?: unknown[] })?.contents
66
- if (!Array.isArray(contents) || contents.length === 0) return "(empty resource)"
67
- const parts: string[] = []
68
- for (const c of contents) {
69
- if (typeof c !== "object" || c === null) continue
70
- const item = c as Record<string, unknown>
71
- const mime = typeof item.mimeType === "string" ? item.mimeType : "unknown"
72
- if (typeof item.text === "string") {
73
- parts.push(prettifyIfSmallJson(item.text))
74
- } else if (typeof item.blob === "string") {
75
- const bytes = Math.floor((item.blob.length * 3) / 4) // base64 → approx decoded size
76
- parts.push(`[binary ${mime}, ~${bytes} bytes — uri ${item.uri ?? "?"}]`)
77
- } else if (mime.startsWith("image/")) {
78
- parts.push(`[image: ${mime} — uri ${item.uri ?? "?"}]`)
79
- } else {
80
- parts.push(`[unreadable content: ${mime} — uri ${item.uri ?? "?"}]`)
81
- }
82
- }
83
- const text = parts.join("\n").trim() || "(empty resource)"
84
- if (text.length <= MAX_RESULT_CHARS) return text
85
- return `${text.slice(0, MAX_RESULT_CHARS)}\n\n… (resource truncated at ${MAX_RESULT_CHARS} chars)`
86
- }
49
+ // NOTE: the guarded resource read (pretty-print small JSON, spill over the cap)
50
+ // lives in render.ts and is re-exported above — the old copies here and in the
51
+ // legacy render.ts are unified; nothing remains here.
package/src/index.ts CHANGED
@@ -401,6 +401,7 @@ export default function mcpCombiner(pi: ExtensionAPI): void {
401
401
  createMcpTool({
402
402
  connection,
403
403
  toolName,
404
+ maxResultChars: settings.maxResultChars,
404
405
  getServerFilter: () => sessionCfg?.serverFilter,
405
406
  }),
406
407
  )
@@ -417,6 +418,7 @@ export default function mcpCombiner(pi: ExtensionAPI): void {
417
418
  exposeResources: settings.exposeResources !== false,
418
419
  uiAutoOpen: settings.uiAutoOpen !== false,
419
420
  warnLargeDirectExposure: settings.warnLargeDirectExposure,
421
+ maxResultChars: settings.maxResultChars,
420
422
  log: clientLog,
421
423
  })
422
424
  }
@@ -105,7 +105,7 @@ function ncDbg(s: string): void {
105
105
 
106
106
  // Keep in sync with plugins/pi/package.json "version": scripts/bump-version.sh stamps
107
107
  // this line alongside the package files (the string is what this client declares).
108
- const CLIENT_INFO = { name: "pi-mcp-combiner", version: "0.16.0-dev.3" }
108
+ const CLIENT_INFO = { name: "pi-mcp-combiner", version: "0.17.0" }
109
109
  const CONNECT_TIMEOUT_MS = 8_000
110
110
  const LIST_CACHE_MS = 5_000
111
111
 
@@ -37,6 +37,9 @@ export type NativeActivationOptions = {
37
37
  /** Warn when the direct-exposure set grows large; settings kill-switch
38
38
  * warnLargeDirectExposure disables it (default true, i.e. warn). */
39
39
  warnLargeDirectExposure?: boolean
40
+ /** Cap on guarded tool-result text before spill-to-file (maxResultChars setting);
41
+ * forwarded to the tool surface and the interactive read_* tools. */
42
+ maxResultChars?: number
40
43
  log: (level: "info" | "warn" | "error", message: string) => void
41
44
  }
42
45
 
@@ -62,6 +65,7 @@ export function activateNativeMode(
62
65
  directSpec: opts.directSpec,
63
66
  state: toolState,
64
67
  warnLargeDirectExposure: opts.warnLargeDirectExposure,
68
+ maxResultChars: opts.maxResultChars,
65
69
  log: opts.log,
66
70
  }).catch((e) =>
67
71
  opts.log("warn", `native tool surface failed: ${e instanceof Error ? e.message : String(e)}`),
@@ -74,6 +78,7 @@ export function activateNativeMode(
74
78
  serverFilter: opts.serverFilter,
75
79
  directSpec: opts.directSpec,
76
80
  uiAutoOpen: opts.uiAutoOpen,
81
+ maxResultChars: opts.maxResultChars,
77
82
  log: opts.log,
78
83
  },
79
84
  resourceRegistered,
@@ -23,6 +23,7 @@ import type { ExtensionAPI, ToolDefinition } from "../pi.js"
23
23
  import type { NativeCombinerConnection, ResourceSummary } from "./combiner-connection.js"
24
24
  import { isInteractiveResource, openInBrowser, renderResourceResult } from "../client/widget-support.js"
25
25
  import { resourceNameToToolName, resourceServer } from "../client/resource-naming.js"
26
+ import { isRunnerStaleError, runnerStaleHint, safeHasUi } from "../client/runner-stale.js"
26
27
  import type { ServerFilter } from "../client/config-ladder.js"
27
28
 
28
29
  export type NativeResourceOptions = {
@@ -36,6 +37,8 @@ export type NativeResourceOptions = {
36
37
  directSpec?: string[] | "search" | (() => string[] | "search" | undefined)
37
38
  /** Auto-open the widget URL on read (index.ts's uiAutoOpen setting). */
38
39
  uiAutoOpen?: boolean
40
+ /** Cap on guarded result text before spill-to-file (maxResultChars setting). */
41
+ maxResultChars?: number
39
42
  log: (level: "info" | "warn" | "error", message: string) => void
40
43
  }
41
44
 
@@ -94,6 +97,11 @@ function toReadTool(toolName: string, resource: ResourceSummary, opts: NativeRes
94
97
  exposure: resolveResourceExposure(opts, toolName),
95
98
  namespace: { name: "mcp_combiner", description: "mcp-combiner aggregated tools" },
96
99
  execute: async (_toolCallId, _params, _signal, _onUpdate, ctx) => {
100
+ // SAFETY: guarded ctx read ONCE at entry, never re-read after the await
101
+ // (client/runner-stale.ts — a mid-window read would reject a COMPLETED
102
+ // resource read; the model retrying would re-read, which is at least
103
+ // read-only, but the failure text helps nobody).
104
+ const hasUi = safeHasUi(ctx)
97
105
  try {
98
106
  const result = await opts.connection.readResource(resource.uri)
99
107
  // Compute the URL PER CALL: the session token changes across /new and
@@ -101,13 +109,16 @@ function toReadTool(toolName: string, resource: ResourceSummary, opts: NativeRes
101
109
  // registration-time URL would carry a dead token after the first
102
110
  // session switch.
103
111
  const url = opts.connection.uiUrlFor(resource.uri)
104
- let text = renderResourceResult(result)
112
+ let text = await renderResourceResult(result, { maxResultChars: opts.maxResultChars }, toolName)
105
113
  if (url) {
106
114
  text = `${text}\n\ninteractive: ${url}`
107
- if (opts.uiAutoOpen !== false && ctx?.hasUI) openInBrowser(url)
115
+ if (opts.uiAutoOpen !== false && hasUi) openInBrowser(url)
108
116
  }
109
117
  return { content: [{ type: "text", text }], details: { mode: "resource", uri: resource.uri, url: url || undefined } }
110
118
  } catch (e) {
119
+ if (isRunnerStaleError(e)) {
120
+ throw new Error(runnerStaleHint(toolName))
121
+ }
111
122
  throw new Error(`${toolName}: resource read failed (${e instanceof Error ? e.message : String(e)})`)
112
123
  }
113
124
  },