@bastani/atomic 0.9.61-alpha.1 → 0.9.61-alpha.3

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 (72) hide show
  1. package/CHANGELOG.md +68 -4
  2. package/dist/builtin/intercom/index.bundle.mjs +3 -3
  3. package/dist/builtin/intercom/package.json +1 -1
  4. package/dist/builtin/mcp/package.json +1 -1
  5. package/dist/builtin/subagents/CHANGELOG.md +12 -0
  6. package/dist/builtin/subagents/package.json +1 -1
  7. package/dist/builtin/web-access/package.json +1 -1
  8. package/dist/builtin/workflows/CHANGELOG.md +14 -0
  9. package/dist/builtin/workflows/README.md +9 -7
  10. package/dist/builtin/workflows/builtin/{chunk-h6bt0r0g.js → chunk-a2j0x1a6.js} +1 -1
  11. package/dist/builtin/workflows/builtin/{chunk-g3b2zf8r.js → chunk-vzbec50q.js} +1 -1
  12. package/dist/builtin/workflows/builtin/goal.js +1 -1
  13. package/dist/builtin/workflows/builtin/index.js +2 -2
  14. package/dist/builtin/workflows/builtin/ralph.js +1 -1
  15. package/dist/builtin/workflows/package.json +1 -1
  16. package/dist/builtin/workflows/src/extension/index.bundle.mjs +828 -418
  17. package/dist/builtin/workflows/src/extension/local-worker-entry.mjs +905 -429
  18. package/dist/builtin/workflows/src/index.js +798 -393
  19. package/dist/builtin/workflows/src/local-worker-entry.mjs +905 -429
  20. package/dist/core/agent-session-retry.d.ts.map +1 -1
  21. package/dist/core/agent-session-retry.js +12 -3
  22. package/dist/core/agent-session-retry.js.map +1 -1
  23. package/dist/core/model-fallback-failures.d.ts +14 -4
  24. package/dist/core/model-fallback-failures.d.ts.map +1 -1
  25. package/dist/core/model-fallback-failures.js +43 -15
  26. package/dist/core/model-fallback-failures.js.map +1 -1
  27. package/dist/core/settings-defaults.d.ts +1 -0
  28. package/dist/core/settings-defaults.d.ts.map +1 -1
  29. package/dist/core/settings-defaults.js +1 -0
  30. package/dist/core/settings-defaults.js.map +1 -1
  31. package/dist/core/settings-manager-basic-accessors.d.ts +1 -0
  32. package/dist/core/settings-manager-basic-accessors.d.ts.map +1 -1
  33. package/dist/core/settings-manager-basic-accessors.js +2 -0
  34. package/dist/core/settings-manager-basic-accessors.js.map +1 -1
  35. package/dist/core/settings-schema.d.ts +2 -0
  36. package/dist/core/settings-schema.d.ts.map +1 -1
  37. package/dist/core/settings-schema.js +4 -0
  38. package/dist/core/settings-schema.js.map +1 -1
  39. package/dist/core/slash-commands.js +2 -2
  40. package/dist/core/slash-commands.js.map +1 -1
  41. package/dist/index.d.ts +1 -1
  42. package/dist/index.d.ts.map +1 -1
  43. package/dist/index.js.map +1 -1
  44. package/dist/modes/interactive/interactive-startup-chat-container.d.ts +2 -0
  45. package/dist/modes/interactive/interactive-startup-chat-container.d.ts.map +1 -1
  46. package/dist/modes/interactive/interactive-startup-chat-container.js +6 -0
  47. package/dist/modes/interactive/interactive-startup-chat-container.js.map +1 -1
  48. package/dist/modes/interactive-engine/engine-render-service.d.ts +8 -0
  49. package/dist/modes/interactive-engine/engine-render-service.d.ts.map +1 -1
  50. package/dist/modes/interactive-engine/engine-render-service.js +28 -6
  51. package/dist/modes/interactive-engine/engine-render-service.js.map +1 -1
  52. package/dist/modes/interactive-engine/remote-renderer.d.ts +33 -5
  53. package/dist/modes/interactive-engine/remote-renderer.d.ts.map +1 -1
  54. package/dist/modes/interactive-engine/remote-renderer.js +91 -17
  55. package/dist/modes/interactive-engine/remote-renderer.js.map +1 -1
  56. package/dist/modes/rpc/queued-writer.d.ts +2 -0
  57. package/dist/modes/rpc/queued-writer.d.ts.map +1 -1
  58. package/dist/modes/rpc/queued-writer.js +8 -0
  59. package/dist/modes/rpc/queued-writer.js.map +1 -1
  60. package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
  61. package/dist/modes/rpc/rpc-client.js +4 -0
  62. package/dist/modes/rpc/rpc-client.js.map +1 -1
  63. package/docs/intercom/reference.md +1 -1
  64. package/docs/models/evals.md +30 -2
  65. package/docs/settings.md +3 -0
  66. package/docs/subagents/reference.md +3 -1
  67. package/docs/workflows/api-reference.md +9 -6
  68. package/docs/workflows/builtins.md +1 -1
  69. package/docs/workflows/operations.md +4 -4
  70. package/npm-shrinkwrap.json +32 -32
  71. package/package.json +3 -3
  72. package/schemas/settings.schema.json +5 -0
@@ -1 +1 @@
1
- {"version":3,"file":"remote-renderer.js","sourceRoot":"","sources":["../../../src/modes/interactive-engine/remote-renderer.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAIhE,IAAI,oBAAoB,GAAG,CAAC,CAAC;AAE7B,SAAS,SAAS,CAAC,KAAc;IAChC,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,IAAI,CAAC;IACrC,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IACtC,OAAO,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAE,IAAI,CAAC,KAAK,CAAC,OAAO,CAAe,CAAC;AAC1E,CAAC;AAED,MAAe,cAAc;IACT,WAAW,GAAG,mBAAmB,EAAE,oBAAoB,EAAE,CAAC;IACrE,KAAK,GAAG,CAAC,4BAA4B,CAAC,CAAC;IACvC,KAAK,GAAG,CAAC,CAAC;IACV,SAAS,GAAG,CAAC,CAAC;IACd,gBAAgB,GAAG,CAAC,CAAC;IACrB,KAAK,GAAG,IAAI,CAAC;IACb,QAAQ,GAAG,KAAK,CAAC;IACR,UAAU,GAAG,IAAI,qBAAqB,EAAE,CAAC;IACzC,WAAW,CAAa;IAEtB,OAAO,CAA6B;IACtC,aAAa,CAAa;IAE3C,YAAY,OAAmC,EAAE,aAAyB;QACzE,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC,OAAO,EAAE,EAAE;YACtD,IAAI,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ustomMessage } from \"../../core/messages.ts\";\nimport type { ToolExecutionComponent } from \"../interactive/components/tool-execution.ts\";\nimport type { IsolatedInteractiveRuntime } from \"./isolated-runtime.js\";\nimport type { InteractiveEngineCommand, JsonObject, JsonValue } from \"./protocol.ts\";\nimport { RemoteFrameWidthClamp } from \"./remote-frame-clamp.ts\";\n\ntype RenderableToolResult = Parameters<ToolExecutionComponent[\"updateResult\"]>[0];\n\nlet nextRemoteRendererId = 0;\n\nfunction jsonValue(value: unknown): JsonValue {\n\tif (value === undefined) return null;\n\tconst encoded = JSON.stringify(value);\n\treturn encoded === undefined ? null : (JSON.parse(encoded) as JsonValue);\n}\n\nabstract class RemoteRenderer implements Component {\n\tprotected readonly componentId = `remote_renderer_${++nextRemoteRendererId}`;\n\tprivate lines = [\"Loading isolated renderer…\"];\n\tprivate width = 0;\n\tprivate requestId = 0;\n\tprivate appliedRequestId = 0;\n\tprivate dirty = true;\n\tprivate disposed = false;\n\tprivate readonly frameClamp = new RemoteFrameWidthClamp();\n\tprivate readonly unsubscribe: () => void;\n\n\tprotected readonly runtime: IsolatedInteractiveRuntime;\n\tprivate readonly requestRender: () => void;\n\n\tconstructor(runtime: IsolatedInteractiveRuntime, requestRender: () => void) {\n\t\tthis.runtime = runtime;\n\t\tthis.requestRender = requestRender;\n\t\tthis.unsubscribe = runtime.onEngineMessage((message) => {\n\t\t\tif (!(\"componentId\" in message) || message.componentId !== this.componentId) return;\n\t\t\tif (message.type === \"engine_custom_frame\") {\n\t\t\t\tif (message.requestId < this.appliedRequestId) return;\n\t\t\t\tthis.appliedRequestId = message.requestId;\n\t\t\t\tthis.lines = message.lines;\n\t\t\t\tthis.requestRender();\n\t\t\t} else if (message.type === \"engine_custom_invalidate\") {\n\t\t\t\tthis.changed();\n\t\t\t}\n\t\t});\n\t}\n\n\trender(width: number): string[] {\n\t\tif (!this.disposed && (this.dirty || width !== this.width)) {\n\t\t\tthis.width = width;\n\t\t\tthis.dirty = false;\n\t\t\tthis.runtime.sendEngineCommand(this.command(++this.requestId, width));\n\t\t}\n\t\t// The engine child re-renders asynchronously; until the fresh frame\n\t\t// arrives, the previous frame may be wrapped for an older terminal\n\t\t// width. Clamp so a resize never replays overflowing lines (pi-tui\n\t\t// crashes on any rendered line wider than the terminal).\n\t\treturn this.frameClamp.clamp(this.lines, width);\n\t}\n\n\tinvalidate(): void {\n\t\tthis.markDirty();\n\t}\n\n\tdispose(): void {\n\t\tif (this.disposed) return;\n\t\tthis.disposed = true;\n\t\tthis.unsubscribe();\n\t\tthis.runtime.sendEngineCommand({ type: \"engine_render_dispose\", componentId: this.componentId });\n\t}\n\n\tprotected changed(): void {\n\t\tthis.markDirty();\n\t\tthis.requestRender();\n\t}\n\n\tprotected abstract command(requestId: number, width: number): InteractiveEngineCommand;\n\n\tprivate markDirty(): void {\n\t\tthis.dirty = true;\n\t}\n}\n\nexport class RemoteToolExecutionComponent extends RemoteRenderer {\n\tprivate readonly toolName: string;\n\tprivate readonly toolCallId: string;\n\tprivate args: unknown;\n\tprivate result: RenderableToolResult | undefined;\n\tprivate executionStarted = false;\n\tprivate argsComplete = false;\n\tprivate isPartial = true;\n\tprivate expanded = false;\n\tprivate showImages: boolean;\n\tprivate imageWidthCells: number;\n\tprivate outputPad: number;\n\n\tconstructor(\n\t\ttoolName: string,\n\t\ttoolCallId: string,\n\t\targs: unknown,\n\t\toptions: { showImages?: boolean; imageWidthCells?: number; outputPad?: number },\n\t\truntime: IsolatedInteractiveRuntime,\n\t\trequestRender: () => void,\n\t) {\n\t\tsuper(runtime, requestRender);\n\t\tthis.toolName = toolName;\n\t\tthis.toolCallId = toolCallId;\n\t\tthis.args = args;\n\t\tthis.showImages = options.showImages ?? true;\n\t\tthis.imageWidthCells = options.imageWidthCells ?? 60;\n\t\tthis.outputPad = options.outputPad ?? 1;\n\t}\n\n\tsetOutputPad(outputPad: number): void {\n\t\tthis.outputPad = outputPad;\n\t\tthis.changed();\n\t}\n\tupdateArgs(args: unknown): void {\n\t\tthis.args = args;\n\t\tthis.changed();\n\t}\n\tmarkExecutionStarted(): void {\n\t\tthis.executionStarted = true;\n\t\tthis.changed();\n\t}\n\tsetArgsComplete(): void {\n\t\tthis.argsComplete = true;\n\t\tthis.changed();\n\t}\n\tupdateResult(result: RenderableToolResult, isPartial = false): void {\n\t\tthis.result = result;\n\t\tthis.isPartial = isPartial;\n\t\tthis.changed();\n\t}\n\tsetExpanded(expanded: boolean): void {\n\t\tthis.expanded = expanded;\n\t\tthis.changed();\n\t}\n\tsetShowImages(show: boolean): void {\n\t\tthis.showImages = show;\n\t\tthis.changed();\n\t}\n\tsetImageWidthCells(width: number): void {\n\t\tthis.imageWidthCells = Math.max(1, Math.floor(width));\n\t\tthis.changed();\n\t}\n\n\tprotected command(requestId: number, width: number): InteractiveEngineCommand {\n\t\treturn {\n\t\t\ttype: \"engine_tool_render\",\n\t\t\tcomponentId: this.componentId,\n\t\t\trequestId,\n\t\t\twidth,\n\t\t\ttoolName: this.toolName,\n\t\t\ttoolCallId: this.toolCallId,\n\t\t\targs: jsonValue(this.args),\n\t\t\tresult: this.result ? (jsonValue(this.result) as JsonObject) : undefined,\n\t\t\texecutionStarted: this.executionStarted,\n\t\t\targsComplete: this.argsComplete,\n\t\t\tisPartial: this.isPartial,\n\t\t\texpanded: this.expanded,\n\t\t\tshowImages: this.showImages,\n\t\t\timageWidthCells: this.imageWidthCells,\n\t\t\toutputPad: this.outputPad,\n\t\t};\n\t}\n}\n\nexport class RemoteCustomMessageComponent extends RemoteRenderer {\n\tprivate readonly message: CustomMessage<unknown>;\n\tprivate expanded = false;\n\tprivate outputPad: number;\n\tconstructor(\n\t\tmessage: CustomMessage<unknown>,\n\t\truntime: IsolatedInteractiveRuntime,\n\t\trequestRender: () => void,\n\t\toutputPad = 1,\n\t) {\n\t\tsuper(runtime, requestRender);\n\t\tthis.message = message;\n\t\tthis.outputPad = outputPad;\n\t}\n\n\tsetExpanded(expanded: boolean): void {\n\t\tthis.expanded = expanded;\n\t\tthis.changed();\n\t}\n\tsetOutputPad(outputPad: number): void {\n\t\tthis.outputPad = outputPad;\n\t\tthis.changed();\n\t}\n\n\tprotected command(requestId: number, width: number): InteractiveEngineCommand {\n\t\treturn {\n\t\t\ttype: \"engine_message_render\",\n\t\t\tcomponentId: this.componentId,\n\t\t\trequestId,\n\t\t\twidth,\n\t\t\tmessage: jsonValue(this.message) as JsonObject,\n\t\t\texpanded: this.expanded,\n\t\t\toutputPad: this.outputPad,\n\t\t};\n\t}\n}\n"]}
1
+ {"version":3,"file":"remote-renderer.js","sourceRoot":"","sources":["../../../src/modes/interactive-engine/remote-renderer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAMzC,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAKhE,IAAI,oBAAoB,GAAG,CAAC,CAAC;AAE7B,MAAM,aAAa,GAAG,CAAC,4BAA4B,CAAC,CAAC;AAErD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,KAAK,CAAC;AAC9C,MAAM,YAAY,GAAG,IAAI,GAAG,EAAoB,CAAC;AAEjD,SAAS,aAAa,CAAC,GAAW,EAAE,KAAe;IAClD,YAAY,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACzB,YAAY,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IAC7B,IAAI,YAAY,CAAC,IAAI,GAAG,wBAAwB,EAAE,CAAC;QAClD,MAAM,MAAM,GAAG,YAAY,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC;QAChD,IAAI,MAAM,KAAK,SAAS;YAAE,YAAY,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACvD,CAAC;AACF,CAAC;AAED,6GAA6G;AAC7G,MAAM,eAAe,GAAG,IAAI,OAAO,EAA2D,CAAC;AAE/F,SAAS,cAAc,CAAC,OAAmC;IAC1D,IAAI,MAAM,GAAG,eAAe,CAAC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a;QACtB,2GAA2G;QAC3G,IAAI,CAAC,aAAa,KAAK,UAAU,CAAC,MAAM,CAAC;aACvC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC;aAC1E,MAAM,CAAC,QAAQ,CAAC,CAAC;QACnB,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;IAChG,CAAC;CACD","sourcesContent":["import { createHash } from \"node:crypto\";\nimport type { Component } from \"@earendil-works/pi-tui\";\nimport type { CustomMessage } from \"../../core/messages.ts\";\nimport type { ToolExecutionComponent } from \"../interactive/components/tool-execution.ts\";\nimport type { IsolatedInteractiveRuntime } from \"./isolated-runtime.js\";\nimport type { InteractiveEngineCommand, InteractiveEngineMessage, JsonObject, JsonValue } from \"./protocol.ts\";\nimport { RemoteFrameWidthClamp } from \"./remote-frame-clamp.ts\";\n\ntype RenderableToolResult = Parameters<ToolExecutionComponent[\"updateResult\"]>[0];\ntype RemoteRenderCommand = Extract<InteractiveEngineCommand, { type: \"engine_tool_render\" | \"engine_message_render\" }>;\n\nlet nextRemoteRendererId = 0;\n\nconst LOADING_LINES = [\"Loading isolated renderer…\"];\n\n/**\n * How many rows' last frames are kept, by row identity (a tool call, a custom message), to repaint rebuilt rows. A chat\n * rebuild (compaction, `/reload`, a switched session) recreates every row, and each new row waits for the engine to\n * render it. Showing the row's last frame meanwhile keeps the rebuilt chat painted, instead of a screen of placeholders\n * that lasts as long as the engine is busy.\n */\nexport const REMOTE_FRAME_CACHE_LIMIT = 2_000;\nconst recentFrames = new Map<string, string[]>();\n\nfunction rememberFrame(key: string, lines: string[]): void {\n\trecentFrames.delete(key);\n\trecentFrames.set(key, lines);\n\tif (recentFrames.size > REMOTE_FRAME_CACHE_LIMIT) {\n\t\tconst oldest = recentFrames.keys().next().value;\n\t\tif (oldest !== undefined) recentFrames.delete(oldest);\n\t}\n}\n\n/** One engine-message subscription per runtime, routed by component id, however many rows the chat holds. */\nconst routesByRuntime = new WeakMap<IsolatedInteractiveRuntime, Map<string, RemoteRenderer>>();\n\nfunction rendererRoutes(runtime: IsolatedInteractiveRuntime): Map<string, RemoteRenderer> {\n\tlet routes = routesByRuntime.get(runtime);\n\tif (routes === undefined) {\n\t\tconst created = new Map<string, RemoteRenderer>();\n\t\truntime.onEngineMessage((message) => {\n\t\t\tif (\"componentId\" in message) created.get(message.componentId)?.receive(message);\n\t\t});\n\t\troutesByRuntime.set(runtime, created);\n\t\troutes = created;\n\t}\n\treturn routes;\n}\n\nfunction jsonValue(value: unknown): JsonValue {\n\tif (value === undefined) return null;\n\tconst encoded = JSON.stringify(value);\n\treturn encoded === undefined ? null : (JSON.parse(encoded) as JsonValue);\n}\n\nabstract class RemoteRenderer implements Component {\n\tprotected readonly componentId = `remote_renderer_${++nextRemoteRendererId}`;\n\tprivate lines = LOADING_LINES;\n\tprivate width = 0;\n\tprivate requestId = 0;\n\tprivate appliedRequestId = 0;\n\tprivate dirty = true;\n\tprivate disposed = false;\n\tprivate readonly frameClamp = new RemoteFrameWidthClamp();\n\tprivate readonly routes: Map<string, RemoteRenderer>;\n\t/**\n\t * What each unanswered request showed (its frame identity, expansion included), by request id. A frame is\n\t * remembered under the identity of the request it answers, not under the row's state when it arrives: a row\n\t * collapsed while its expanded frame was in flight must not have that frame remembered as its collapsed one.\n\t */\n\tprivate readonly requestIdentities = new Map<number, string>();\n\n\tprotected readonly runtime: IsolatedInteractiveRuntime;\n\tprivate readonly requestRender: () => void;\n\n\tconstructor(runtime: IsolatedInteractiveRuntime, requestRender: () => void) {\n\t\tthis.runtime = runtime;\n\t\tthis.requestRender = requestRender;\n\t\tthis.routes = rendererRoutes(runtime);\n\t\tthis.routes.set(this.componentId, this);\n\t}\n\n\t/** An engine message addressed to this row. */\n\treceive(message: InteractiveEngineMessage): void {\n\t\tif (message.type === \"engine_custom_frame\") {\n\t\t\tif (message.requestId < this.appliedRequestId) return;\n\t\t\tthis.appliedRequestId = message.requestId;\n\t\t\tthis.lines = message.lines;\n\t\t\tconst identity = this.requestIdentities.get(message.requestId);\n\t\t\tfor (const requestId of this.requestIdentities.keys())\n\t\t\t\tif (requestId <= message.requestId) this.requestIdentities.delete(requestId);\n\t\t\tif (identity !== undefined) rememberFrame(identity, message.lines);\n\t\t\tthis.requestRender();\n\t\t} else if (message.type === \"engine_custom_invalidate\") {\n\t\t\tthis.changed();\n\t\t}\n\t}\n\n\trender(width: number): string[] {\n\t\tif (!this.disposed && (this.dirty || width !== this.width)) {\n\t\t\tthis.width = width;\n\t\t\tthis.dirty = false;\n\t\t\t// A row rebuilt for a row the engine already rendered paints its last frame until the fresh one arrives.\n\t\t\tconst identity = this.frameIdentity();\n\t\t\tif (this.lines === LOADING_LINES) this.lines = recentFrames.get(identity) ?? LOADING_LINES;\n\t\t\tthis.requestIdentities.set(++this.requestId, identity);\n\t\t\tthis.runtime.sendEngineCommand(this.command(this.requestId, width));\n\t\t}\n\t\t// The engine child re-renders asynchronously; until the fresh frame\n\t\t// arrives, the previous frame may be wrapped for an older terminal\n\t\t// width. Clamp so a resize never replays overflowing lines (pi-tui\n\t\t// crashes on any rendered line wider than the terminal).\n\t\treturn this.frameClamp.clamp(this.lines, width);\n\t}\n\n\tinvalidate(): void {\n\t\tthis.markDirty();\n\t}\n\n\tdispose(): void {\n\t\tif (this.disposed) return;\n\t\tthis.disposed = true;\n\t\tif (this.routes.get(this.componentId) === this) this.routes.delete(this.componentId);\n\t\tthis.requestIdentities.clear();\n\t\tthis.runtime.sendEngineCommand({ type: \"engine_render_dispose\", componentId: this.componentId });\n\t}\n\n\tprotected changed(): void {\n\t\tthis.markDirty();\n\t\tthis.requestRender();\n\t}\n\n\tprotected abstract command(requestId: number, width: number): RemoteRenderCommand;\n\n\t/** Names what this row shows, the same for every row recreated for it. */\n\tprotected abstract frameIdentity(): string;\n\n\tprivate markDirty(): void {\n\t\tthis.dirty = true;\n\t}\n}\n\n/**\n * Disposes the rows rendered by the engine among `components`, which a cleared chat no longer shows: each one\n * otherwise keeps its renderer alive in the engine for the rest of the session.\n */\nexport function disposeRemoteRenderers(components: readonly Component[]): void {\n\tfor (const component of components) if (component instanceof RemoteRenderer) component.dispose();\n}\n\nexport class RemoteToolExecutionComponent extends RemoteRenderer {\n\tprivate readonly toolName: string;\n\tprivate readonly toolCallId: string;\n\tprivate args: unknown;\n\tprivate result: RenderableToolResult | undefined;\n\tprivate executionStarted = false;\n\tprivate argsComplete = false;\n\tprivate isPartial = true;\n\tprivate expanded = false;\n\tprivate showImages: boolean;\n\tprivate imageWidthCells: number;\n\tprivate outputPad: number;\n\n\tconstructor(\n\t\ttoolName: string,\n\t\ttoolCallId: string,\n\t\targs: unknown,\n\t\toptions: { showImages?: boolean; imageWidthCells?: number; outputPad?: number },\n\t\truntime: IsolatedInteractiveRuntime,\n\t\trequestRender: () => void,\n\t) {\n\t\tsuper(runtime, requestRender);\n\t\tthis.toolName = toolName;\n\t\tthis.toolCallId = toolCallId;\n\t\tthis.args = args;\n\t\tthis.showImages = options.showImages ?? true;\n\t\tthis.imageWidthCells = options.imageWidthCells ?? 60;\n\t\tthis.outputPad = options.outputPad ?? 1;\n\t}\n\n\tsetOutputPad(outputPad: number): void {\n\t\tthis.outputPad = outputPad;\n\t\tthis.changed();\n\t}\n\tupdateArgs(args: unknown): void {\n\t\tthis.args = args;\n\t\tthis.changed();\n\t}\n\tmarkExecutionStarted(): void {\n\t\tthis.executionStarted = true;\n\t\tthis.changed();\n\t}\n\tsetArgsComplete(): void {\n\t\tthis.argsComplete = true;\n\t\tthis.changed();\n\t}\n\tupdateResult(result: RenderableToolResult, isPartial = false): void {\n\t\tthis.result = result;\n\t\tthis.isPartial = isPartial;\n\t\tthis.changed();\n\t}\n\tsetExpanded(expanded: boolean): void {\n\t\tthis.expanded = expanded;\n\t\tthis.changed();\n\t}\n\tsetShowImages(show: boolean): void {\n\t\tthis.showImages = show;\n\t\tthis.changed();\n\t}\n\tsetImageWidthCells(width: number): void {\n\t\tthis.imageWidthCells = Math.max(1, Math.floor(width));\n\t\tthis.changed();\n\t}\n\n\tprotected command(requestId: number, width: number): RemoteRenderCommand {\n\t\treturn {\n\t\t\ttype: \"engine_tool_render\",\n\t\t\tcomponentId: this.componentId,\n\t\t\trequestId,\n\t\t\twidth,\n\t\t\ttoolName: this.toolName,\n\t\t\ttoolCallId: this.toolCallId,\n\t\t\targs: jsonValue(this.args),\n\t\t\tresult: this.result ? (jsonValue(this.result) as JsonObject) : undefined,\n\t\t\texecutionStarted: this.executionStarted,\n\t\t\targsComplete: this.argsComplete,\n\t\t\tisPartial: this.isPartial,\n\t\t\texpanded: this.expanded,\n\t\t\tshowImages: this.showImages,\n\t\t\timageWidthCells: this.imageWidthCells,\n\t\t\toutputPad: this.outputPad,\n\t\t};\n\t}\n\n\tprotected frameIdentity(): string {\n\t\treturn JSON.stringify([\"tool\", this.toolName, this.toolCallId, this.expanded]);\n\t}\n}\n\nexport class RemoteCustomMessageComponent extends RemoteRenderer {\n\tprivate readonly message: CustomMessage<unknown>;\n\tprivate contentDigest: string | undefined;\n\tprivate expanded = false;\n\tprivate outputPad: number;\n\tconstructor(\n\t\tmessage: CustomMessage<unknown>,\n\t\truntime: IsolatedInteractiveRuntime,\n\t\trequestRender: () => void,\n\t\toutputPad = 1,\n\t) {\n\t\tsuper(runtime, requestRender);\n\t\tthis.message = message;\n\t\tthis.outputPad = outputPad;\n\t}\n\n\tsetExpanded(expanded: boolean): void {\n\t\tthis.expanded = expanded;\n\t\tthis.changed();\n\t}\n\tsetOutputPad(outputPad: number): void {\n\t\tthis.outputPad = outputPad;\n\t\tthis.changed();\n\t}\n\n\tprotected command(requestId: number, width: number): RemoteRenderCommand {\n\t\treturn {\n\t\t\ttype: \"engine_message_render\",\n\t\t\tcomponentId: this.componentId,\n\t\t\trequestId,\n\t\t\twidth,\n\t\t\tmessage: jsonValue(this.message) as JsonObject,\n\t\t\texpanded: this.expanded,\n\t\t\toutputPad: this.outputPad,\n\t\t};\n\t}\n\n\tprotected frameIdentity(): string {\n\t\t// Not the timestamp: a message shown live and the same message restored from the session can differ in it.\n\t\tthis.contentDigest ??= createHash(\"sha1\")\n\t\t\t.update(JSON.stringify([this.message.content, this.message.details]) ?? \"\")\n\t\t\t.digest(\"base64\");\n\t\treturn JSON.stringify([\"message\", this.message.customType, this.contentDigest, this.expanded]);\n\t}\n}\n"]}
@@ -18,6 +18,8 @@ export declare class QueuedWriter {
18
18
  get pendingBytes(): number;
19
19
  write(text: string): Promise<void>;
20
20
  offerLatest(key: string, text: string): boolean;
21
+ /** Drops the frame `offerLatest` holds under `key`, if it has not started writing. */
22
+ discardLatest(key: string): void;
21
23
  /**
22
24
  * Reject the in-flight frame and everything queued behind it.
23
25
  *
@@ -1 +1 @@
1
- {"version":3,"file":"queued-writer.d.ts","sourceRoot":"","sources":["../../../src/modes/rpc/queued-writer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAS5C,oEAAoE;AACpE,qBAAa,YAAY;IACxB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAsB;IAC/C,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAmC;IAC7D;;;;;OAKG;IACH,OAAO,CAAC,MAAM,CAA2B;IACzC,OAAO,CAAC,WAAW,CAAK;IACxB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,WAAW,CAAoB;IAEvC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAW;IAElC,YAAY,MAAM,EAAE,QAAQ,EAE3B;IAED,IAAI,YAAY,IAAI,MAAM,CAEzB;IAEK,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAQvC;IAED,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAS9C;IAED;;;;;;OAMG;IACH,KAAK,CAAC,KAAK,GAAE,KAA8C,GAAG,IAAI,CAWjE;IAED,OAAO,CAAC,IAAI;IASZ,OAAO,CAAC,IAAI;YAME,OAAO;CAyBrB"}
1
+ {"version":3,"file":"queued-writer.d.ts","sourceRoot":"","sources":["../../../src/modes/rpc/queued-writer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAS5C,oEAAoE;AACpE,qBAAa,YAAY;IACxB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAsB;IAC/C,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAmC;IAC7D;;;;;OAKG;IACH,OAAO,CAAC,MAAM,CAA2B;IACzC,OAAO,CAAC,WAAW,CAAK;IACxB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,WAAW,CAAoB;IAEvC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAW;IAElC,YAAY,MAAM,EAAE,QAAQ,EAE3B;IAED,IAAI,YAAY,IAAI,MAAM,CAEzB;IAEK,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAQvC;IAED,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAS9C;IAED,sFAAsF;IACtF,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAK/B;IAED;;;;;;OAMG;IACH,KAAK,CAAC,KAAK,GAAE,KAA8C,GAAG,IAAI,CAWjE;IAED,OAAO,CAAC,IAAI;IASZ,OAAO,CAAC,IAAI;YAME,OAAO;CAyBrB"}
@@ -42,6 +42,14 @@ export class QueuedWriter {
42
42
  this.pump();
43
43
  return true;
44
44
  }
45
+ /** Drops the frame `offerLatest` holds under `key`, if it has not started writing. */
46
+ discardLatest(key) {
47
+ const pending = this.coalesced.get(key);
48
+ if (!pending)
49
+ return;
50
+ this.coalesced.delete(key);
51
+ this.queuedBytes -= pending.bytes.length;
52
+ }
45
53
  /**
46
54
  * Reject the in-flight frame and everything queued behind it.
47
55
  *
@@ -1 +1 @@
1
- {"version":3,"file":"queued-writer.js","sourceRoot":"","sources":["../../../src/modes/rpc/queued-writer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAQtF,oEAAoE;AACpE,MAAM,OAAO,YAAY;IACP,QAAQ,GAAmB,EAAE,CAAC;IAC9B,SAAS,GAAG,IAAI,GAAG,EAAwB,CAAC;IAC7D;;;;;OAKG;IACK,MAAM,CAA2B;IACjC,WAAW,GAAG,CAAC,CAAC;IAChB,OAAO,GAAG,KAAK,CAAC;IAChB,WAAW,CAAoB;IAEtB,MAAM,CAAW;IAElC,YAAY,MAAgB;QAC3B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACtB,CAAC;IAED,IAAI,YAAY;QACf,OAAO,IAAI,CAAC,WAAW,CAAC;IACzB,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,IAAY;QACvB,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACxC,IAAI,IAAI,CAAC,WAAW;YAAE,MAAM,IAAI,CAAC,WAAW,CAAC;QAC7C,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAC3C,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;YAC/C,IAAI,CAAC,WAAW,IAAI,KAAK,CAAC,MAAM,CAAC;YACjC,IAAI,CAAC,IAAI,EAAE,CAAC;QACb,CAAC,CAAC,CAAC;IACJ,CAAC;IAED,WAAW,CAAC,GAAW,EAAE,IAAY;QACpC,IAAI,IAAI,CAAC,WAAW;YAAE,OAAO,KAA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CAAC,KAAK,CAAC,uBAAuB,CAAC,KAAK,CAAC,CAAC,CAAC;QAC5C,CAAC;gBAAS,CAAC;YACV,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;YACrB,IAAI,CAAC,IAAI,CAAC,WAAW,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,IAAI,IAAI,CAAC,SAAS,CAAC,IAAI,GAAG,CAAC,CAAC;gBAAE,IAAI,CAAC,IAAI,EAAE,CAAC;QAC7F,CAAC;IACF,CAAC;CACD","sourcesContent":["import type { Writable } from \"node:stream\";\nimport { markRpcTransportFailure, rpcTransportError } from \"./rpc-transport-error.ts\";\n\ninterface PendingFrame {\n\tbytes: Buffer;\n\tresolve?: () => void;\n\treject?: (error: Error) => void;\n}\n\n/** A one-write-at-a-time stream writer with replaceable updates. */\nexport class QueuedWriter {\n\tprivate readonly critical: PendingFrame[] = [];\n\tprivate readonly coalesced = new Map<string, PendingFrame>();\n\t/**\n\t * The frame currently being written. It has already left the queue, so\n\t * `close()` would not see it; without this a stream callback failure (EPIPE\n\t * on a dying engine) leaves its `write()` promise pending forever and the\n\t * caller — a prompt, an abort — never learns the send failed.\n\t */\n\tprivate active: PendingFrame | undefined;\n\tprivate queuedBytes = 0;\n\tprivate pumping = false;\n\tprivate closedError: Error | undefined;\n\n\tprivate readonly stream: Writable;\n\n\tconstructor(stream: Writable) {\n\t\tthis.stream = stream;\n\t}\n\n\tget pendingBytes(): number {\n\t\treturn this.queuedBytes;\n\t}\n\n\tasync write(text: string): Promise<void> {\n\t\tconst bytes = Buffer.from(text, \"utf8\");\n\t\tif (this.closedError) throw this.closedError;\n\t\tawait new Promise<void>((resolve, reject) => {\n\t\t\tthis.critical.push({ bytes, resolve, reject });\n\t\t\tthis.queuedBytes += bytes.length;\n\t\t\tthis.pump();\n\t\t});\n\t}\n\n\tofferLatest(key: string, text: string): boolean {\n\t\tif (this.closedError) return false;\n\t\tconst bytes = Buffer.from(text, \"utf8\");\n\t\tconst previous = this.coalesced.get(key);\n\t\tif (previous) this.queuedBytes -= previous.bytes.length;\n\t\tthis.coalesced.set(key, { bytes });\n\t\tthis.queuedBytes += bytes.length;\n\t\tthis.pump();\n\t\treturn true;\n\t}\n\n\t/**\n\t * Reject the in-flight frame and everything queued behind it.\n\t *\n\t * The error is classified as a transport failure before it is stored, so the\n\t * active frame, the queued frames, and every later `write()` all reject with\n\t * the same classified value — a raw stream `EPIPE` included.\n\t */\n\tclose(error: Error = rpcTransportError(\"RPC writer closed\")): void {\n\t\tif (this.closedError) return;\n\t\tthis.closedError = markRpcTransportFailure(error);\n\t\tconst closedError = this.closedError;\n\t\t// The in-flight frame first: it is no longer in either queue.\n\t\tconst active = this.active;\n\t\tthis.active = undefined;\n\t\tactive?.reject?.(closedError);\n\t\tfor (const frame of this.critical.splice(0)) frame.reject?.(closedError);\n\t\tthis.coalesced.clear();\n\t\tthis.queuedBytes = 0;\n\t}\n\n\tprivate next(): PendingFrame | undefined {\n\t\tconst critical = this.critical.shift();\n\t\tif (critical) return critical;\n\t\tconst entry = this.coalesced.entries().next().value as [string, PendingFrame] | undefined;\n\t\tif (!entry) return undefined;\n\t\tthis.coalesced.delete(entry[0]);\n\t\treturn entry[1];\n\t}\n\n\tprivate pump(): void {\n\t\tif (this.pumping) return;\n\t\tthis.pumping = true;\n\t\tvoid this.runPump();\n\t}\n\n\tprivate async runPump(): Promise<void> {\n\t\ttry {\n\t\t\tfor (;;) {\n\t\t\t\tif (this.closedError) break;\n\t\t\t\tconst frame = this.next();\n\t\t\t\tif (frame === undefined) break;\n\t\t\t\tthis.active = frame;\n\t\t\t\tthis.queuedBytes -= frame.bytes.length;\n\t\t\t\tawait new Promise<void>((resolve, reject) => {\n\t\t\t\t\tthis.stream.write(frame.bytes, (error) => (error ? reject(error) : resolve()));\n\t\t\t\t});\n\t\t\t\tthis.active = undefined;\n\t\t\t\tframe.resolve?.();\n\t\t\t}\n\t\t} catch (error) {\n\t\t\t// Any callback failure means the frame never reached the child, so it is\n\t\t\t// a transport failure whatever the stream chose to call it. The frame\n\t\t\t// that failed is still `active`, so close() rejects it along with\n\t\t\t// everything still queued. Nothing is left pending.\n\t\t\tthis.close(markRpcTransportFailure(error));\n\t\t} finally {\n\t\t\tthis.pumping = false;\n\t\t\tif (!this.closedError && (this.critical.length > 0 || this.coalesced.size > 0)) this.pump();\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"queued-writer.js","sourceRoot":"","sources":["../../../src/modes/rpc/queued-writer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAQtF,oEAAoE;AACpE,MAAM,OAAO,YAAY;IACP,QAAQ,GAAmB,EAAE,CAAC;IAC9B,SAAS,GAAG,IAAI,GAAG,EAAwB,CAAC;IAC7D;;;;;OAKG;IACK,MAAM,CAA2B;IACjC,WAAW,GAAG,CAAC,CAAC;IAChB,OAAO,GAAG,KAAK,CAAC;IAChB,WAAW,CAAoB;IAEtB,MAAM,CAAW;IAElC,YAAY,MAAgB;QAC3B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACtB,CAAC;IAED,IAAI,YAAY;QACf,OAAO,IAAI,CAAC,WAAW,CAAC;IACzB,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,IAAY;QACvB,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACxC,IAAI,IAAI,CAAC,WAAW;YAAE,MAAM,IAAI,CAAC,WAAW,CAAC;QAC7C,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAC3C,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;YAC/C,IAAI,CAAC,WAAW,IAAI,KAAK,CAAC,MAAM,CAAC;YACjC,IAAI,CAAC,IAAI,EAAE,CAAC;QACb,CA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AAK,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;gBAChF,CAAC,CAAC,CAAC;gBACH,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC;gBACxB,KAAK,CAAC,OAAO,EAAE,EAAE,CAAC;YACnB,CAAC;QACF,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,yEAAyE;YACzE,sEAAsE;YACtE,kEAAkE;YAClE,oDAAoD;YACpD,IAAI,CAAC,KAAK,CAAC,uBAAuB,CAAC,KAAK,CAAC,CAAC,CAAC;QAC5C,CAAC;gBAAS,CAAC;YACV,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;YACrB,IAAI,CAAC,IAAI,CAAC,WAAW,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,IAAI,IAAI,CAAC,SAAS,CAAC,IAAI,GAAG,CAAC,CAAC;gBAAE,IAAI,CAAC,IAAI,EAAE,CAAC;QAC7F,CAAC;IACF,CAAC;CACD","sourcesContent":["import type { Writable } from \"node:stream\";\nimport { markRpcTransportFailure, rpcTransportError } from \"./rpc-transport-error.ts\";\n\ninterface PendingFrame {\n\tbytes: Buffer;\n\tresolve?: () => void;\n\treject?: (error: Error) => void;\n}\n\n/** A one-write-at-a-time stream writer with replaceable updates. */\nexport class QueuedWriter {\n\tprivate readonly critical: PendingFrame[] = [];\n\tprivate readonly coalesced = new Map<string, PendingFrame>();\n\t/**\n\t * The frame currently being written. It has already left the queue, so\n\t * `close()` would not see it; without this a stream callback failure (EPIPE\n\t * on a dying engine) leaves its `write()` promise pending forever and the\n\t * caller — a prompt, an abort — never learns the send failed.\n\t */\n\tprivate active: PendingFrame | undefined;\n\tprivate queuedBytes = 0;\n\tprivate pumping = false;\n\tprivate closedError: Error | undefined;\n\n\tprivate readonly stream: Writable;\n\n\tconstructor(stream: Writable) {\n\t\tthis.stream = stream;\n\t}\n\n\tget pendingBytes(): number {\n\t\treturn this.queuedBytes;\n\t}\n\n\tasync write(text: string): Promise<void> {\n\t\tconst bytes = Buffer.from(text, \"utf8\");\n\t\tif (this.closedError) throw this.closedError;\n\t\tawait new Promise<void>((resolve, reject) => {\n\t\t\tthis.critical.push({ bytes, resolve, reject });\n\t\t\tthis.queuedBytes += bytes.length;\n\t\t\tthis.pump();\n\t\t});\n\t}\n\n\tofferLatest(key: string, text: string): boolean {\n\t\tif (this.closedError) return false;\n\t\tconst bytes = Buffer.from(text, \"utf8\");\n\t\tconst previous = this.coalesced.get(key);\n\t\tif (previous) this.queuedBytes -= previous.bytes.length;\n\t\tthis.coalesced.set(key, { bytes });\n\t\tthis.queuedBytes += bytes.length;\n\t\tthis.pump();\n\t\treturn true;\n\t}\n\n\t/** Drops the frame `offerLatest` holds under `key`, if it has not started writing. */\n\tdiscardLatest(key: string): void {\n\t\tconst pending = this.coalesced.get(key);\n\t\tif (!pending) return;\n\t\tthis.coalesced.delete(key);\n\t\tthis.queuedBytes -= pending.bytes.length;\n\t}\n\n\t/**\n\t * Reject the in-flight frame and everything queued behind it.\n\t *\n\t * The error is classified as a transport failure before it is stored, so the\n\t * active frame, the queued frames, and every later `write()` all reject with\n\t * the same classified value — a raw stream `EPIPE` included.\n\t */\n\tclose(error: Error = rpcTransportError(\"RPC writer closed\")): void {\n\t\tif (this.closedError) return;\n\t\tthis.closedError = markRpcTransportFailure(error);\n\t\tconst closedError = this.closedError;\n\t\t// The in-flight frame first: it is no longer in either queue.\n\t\tconst active = this.active;\n\t\tthis.active = undefined;\n\t\tactive?.reject?.(closedError);\n\t\tfor (const frame of this.critical.splice(0)) frame.reject?.(closedError);\n\t\tthis.coalesced.clear();\n\t\tthis.queuedBytes = 0;\n\t}\n\n\tprivate next(): PendingFrame | undefined {\n\t\tconst critical = this.critical.shift();\n\t\tif (critical) return critical;\n\t\tconst entry = this.coalesced.entries().next().value as [string, PendingFrame] | undefined;\n\t\tif (!entry) return undefined;\n\t\tthis.coalesced.delete(entry[0]);\n\t\treturn entry[1];\n\t}\n\n\tprivate pump(): void {\n\t\tif (this.pumping) return;\n\t\tthis.pumping = true;\n\t\tvoid this.runPump();\n\t}\n\n\tprivate async runPump(): Promise<void> {\n\t\ttry {\n\t\t\tfor (;;) {\n\t\t\t\tif (this.closedError) break;\n\t\t\t\tconst frame = this.next();\n\t\t\t\tif (frame === undefined) break;\n\t\t\t\tthis.active = frame;\n\t\t\t\tthis.queuedBytes -= frame.bytes.length;\n\t\t\t\tawait new Promise<void>((resolve, reject) => {\n\t\t\t\t\tthis.stream.write(frame.bytes, (error) => (error ? reject(error) : resolve()));\n\t\t\t\t});\n\t\t\t\tthis.active = undefined;\n\t\t\t\tframe.resolve?.();\n\t\t\t}\n\t\t} catch (error) {\n\t\t\t// Any callback failure means the frame never reached the child, so it is\n\t\t\t// a transport failure whatever the stream chose to call it. The frame\n\t\t\t// that failed is still `active`, so close() rejects it along with\n\t\t\t// everything still queued. Nothing is left pending.\n\t\t\tthis.close(markRpcTransportFailure(error));\n\t\t} finally {\n\t\t\tthis.pumping = false;\n\t\t\tif (!this.closedError && (this.critical.length > 0 || this.coalesced.size > 0)) this.pump();\n\t\t}\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"rpc-client.d.ts","sourceRoot":"","sources":["../../../src/modes/rpc/rpc-client.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,0CAA0C,CAAC;AAEtF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAElE,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,4CAA4C,CAAC;AAC7F,OAAO,KAAK,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,SAAS;IAIjB,OAAO,CAAC,4BAA4B;IASpC,OAAO,CAAC,sBAAsB;IAG9B,OAAO,CAAC,yBAAyB;IAMjC,OAAO,CAAC,+BAA+B;IA6BvC;;;OAGG;IACH,OAAO,CAAC,cAAc;IAatB,kFAAkF;IAClF,OAAO,CAAC,kBAAkB;IAK1B,OAAO,CAAC,sBAAsB;IAmB9B,OAAO,CAAC,aAAa;IASrB,OAAO,CAAC,aAAa;IAIrB,OAAO,CAAC,UAAU;IAWlB,UAAgB,OAAO,CAAC,OAAO,EAAE,cAAc,EAAE,WAAW,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,WAAW,CAAC,CA4CzG;IACD,OAAO,CAAC,aAAa;IAYrB,SAAS,CAAC,IAAI,CAAC,CAAC,EAAE,QAAQ,EAAE,WAAW,GAAG,CAAC,CAI1C;CACD"}
@@ -331,6 +331,10 @@ export class RpcClient extends RpcClientApi {
331
331
  writer.offerLatest(`render:${command.componentId}`, frame);
332
332
  return;
333
333
  }
334
+ // Disposal goes through the ordered queue, ahead of coalesced renders: a render still waiting for a row
335
+ // being disposed would reach the engine after its disposal and bring its renderer back.
336
+ if (command.type === "engine_render_dispose" || command.type === "engine_custom_dispose")
337
+ writer.discardLatest(`render:${command.componentId}`);
334
338
  this.bestEffort(writer.write(frame), `engine command ${command.type}`);
335
339
  }
336
340
  waitForInteractiveEngineBound() {
@@ -1 +1 @@
1
- {"version":3,"file":"rpc-client.js","sourceRoot":"","sources":["../../../src/modes/rpc/rpc-client.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,8BAA8B,EAAE,MAAM,6BAA6B,CAAC;AAE7E,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAO7C,OAAO,EAAE,wBAAwB,EAAE,MAAM,yCAAyC,CAAC;AACnF,OAAO,EAAE,sBAAsB,EAAE,MAAM,mDAAmD,CAAC;AAC3F,OAAO,EAIN,+BAA+B,GAC/B,MAAM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AM,IAAI,8BAA8B,CACvC,QAAQ,CAAC,YAAY,CAAC,UAAU,EAChC,QAAQ,CAAC,YAAY,CAAC,SAAS,EAC/B,SAAS,EACT,EAAE,KAAK,EAAE,IAAI,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CACpC,CAAC;QACH,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IACjC,CAAC;IACS,IAAI,CAAI,QAAqB;QACtC,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;QAC7B,MAAM,eAAe,GAAG,QAAkE,CAAC;QAC3F,OAAO,eAAe,CAAC,IAAS,CAAC;IAClC,CAAC;CACD","sourcesContent":["import type { ChildProcess } from \"node:child_process\";\nimport type { ImageContent } from \"@bastani/pi-ai/compat\";\nimport type { BashResult } from \"../../core/bash-executor.ts\";\nimport type { WorkflowActivityFrame } from \"../../core/extensions/workflow-events.js\";\nimport { CredentialSynchronizationError } from \"../../core/model-runtime.js\";\nimport type { BashOutputChannel } from \"../../core/tools/bash.js\";\nimport { sleep } from \"../../utils/sleep.ts\";\nimport type { ActivityWatchdogDiagnostic } from \"../interactive-engine/activity-watchdog.ts\";\nimport type {\n\tInteractiveEngineGenerationEnded,\n\tInteractiveEngineGenerationEndedListener,\n\tInteractiveEngineGenerationEndKind,\n} from \"../interactive-engine/engine-generation.ts\";\nimport { InteractiveEngineMonitor } from \"../interactive-engine/engine-monitor.ts\";\nimport { WorkflowActivityMirror } from \"../interactive-engine/engine-workflow-activity.ts\";\nimport {\n\ttype EngineKeybindingState,\n\ttype InteractiveEngineCommand,\n\ttype InteractiveEngineMessage,\n\tserializeInteractiveEngineFrame,\n} from \"../interactive-engine/protocol.ts\";\nimport { attachJsonlLineReader, serializeJsonLine } from \"./jsonl.ts\";\nimport { QueuedWriter } from \"./queued-writer.ts\";\nimport { RpcClientApi, type RpcCommandBody } from \"./rpc-client-api.ts\";\nimport {\n\tappendBoundedStderr,\n\tcreateInteractiveJsonlOptions,\n\tcreateStderrReporter,\n\trestartCliArgs,\n\tspawnRpcClientProcess,\n\tterminateRpcClientProcess,\n} from \"./rpc-client-process.js\";\nimport { collectRpcEvents, runUserBashWithUpdates, waitForRpcIdle } from \"./rpc-client-waits.ts\";\nimport { DEFAULT_REQUEST_TIMEOUT_MS, LONG_LIVED_COMMANDS, RESTART_CANCELLED_MESSAGE } from \"./rpc-command-timeouts.ts\";\nimport { RpcEventBuffer } from \"./rpc-event-buffer.ts\";\nimport { GenerationBuffer } from \"./rpc-generation-buffer.ts\";\nimport { RpcPendingRequests } from \"./rpc-pending-requests.ts\";\nimport { RpcTerminalDrain } from \"./rpc-terminal-drain.ts\";\nimport { markRpcTransportFailure, rpcTransportError } from \"./rpc-transport-error.ts\";\nimport type { RpcCommand, RpcEvent, RpcExtensionUIRequest, RpcExtensionUIResponse, RpcResponse } from \"./rpc-types.ts\";\n\nexport type { ModelInfo, RpcCommandBody } from \"./rpc-client-api.ts\";\nexport type { RpcEvent } from \"./rpc-types.ts\";\n\nexport interface RpcClientOptions {\n\tcliPath?: string;\n\tcwd?: string;\n\tenv?: Record<string, string>;\n\tprovider?: string;\n\tmodel?: string;\n\targs?: string[];\n\truntimeExecutable?: string;\n\truntimeArgs?: string[];\n\t/**\n\t * Bounded deadline (ms) applied to short metadata/control requests. Long-lived\n\t * commands (see LONG_LIVED_COMMANDS) never use this timer. Defaults to 30s.\n\t */\n\trequestTimeoutMs?: number;\n\tinteractiveEngine?: {\n\t\tonDiagnostic: (diagnostic: ActivityWatchdogDiagnostic) => void;\n\t\tonActivityChange?: (active: boolean) => void;\n\t\t/**\n\t\t * Heartbeat observer. Deliberately NOT a generic engine-message listener:\n\t\t * subscribing there drains the buffered startup custom-UI messages into the\n\t\t * first subscriber and stops buffering for the real controllers.\n\t\t */\n\t\tonHeartbeat?: () => void;\n\t\t/**\n\t\t * Credential for the engine child. Delivered through the protected\n\t\t * bootstrap file, never through the child's environment or argv.\n\t\t */\n\t\tapiKey?: string;\n\t};\n}\n\nexport type RpcEventListener = (event: RpcEvent) => void;\n\n/** Longest an explicit quit waits for the child to acknowledge it before stopping an unresponsive engine anyway. */\nconst EXPLICIT_QUIT_ACK_TIMEOUT_MS = 1000;\n\nexport class RpcClient extends RpcClientApi {\n\tprivate process: ChildProcess | null = null;\n\tprivate stopReadingStdout: (() => void) | null = null;\n\tprivate eventListeners: RpcEventListener[] = [];\n\tprivate extensionUIListeners: Array<(request: RpcExtensionUIRequest) => void> = [];\n\tprivate readonly pendingExtensionUIRequests = new GenerationBuffer<RpcExtensionUIRequest>();\n\tprivate engineMessageListeners: Array<(message: InteractiveEngineMessage) => void> = [];\n\tprivate latestEngineKeybindingState: EngineKeybindingState | undefined;\n\tprivate readonly workflowActivity = new WorkflowActivityMirror();\n\tprivate readonly pendingEngineMessages = new GenerationBuffer<InteractiveEngineMessage>();\n\tprivate readonly pendingProjectTrustFrames = new GenerationBuffer<string>();\n\tprivate boundGeneration = 0;\n\tprivate explicitQuitAck: { generation: number; acknowledge: () => void } | undefined;\n\tprivate readonly pendingRequests = new RpcPendingRequests();\n\t/** Bumped by every explicit stop; a restart holds a permit across its own stop. */\n\tprivate restartRevision = 0;\n\tprivate stopPromise: Promise<void> | undefined;\n\tprivate readonly terminalDrain = new RpcTerminalDrain();\n\tprivate stdoutDrained: Promise<void> = Promise.resolve();\n\tprivate requestId = 0;\n\tprivate stderr = \"\";\n\tprivate exitError: Error | null = null;\n\tprivate engineMonitor: InteractiveEngineMonitor | undefined;\n\tprivate eventBuffer: RpcEventBuffer | undefined;\n\tprivate stdinWriter: QueuedWriter | undefined;\n\tprivate generation = 0;\n\tprivate lastEndedGeneration = 0;\n\tprivate generationEndedListeners: InteractiveEngineGenerationEndedListener[] = [];\n\t/**\n\t * The latest generation-end event, retained so a subscriber that attaches\n\t * after the child died still observes it. A child can exit between\n\t * `start()` returning and the runtime constructing its listeners.\n\t */\n\tprivate retainedGenerationEnd: InteractiveEngineGenerationEnded | undefined;\n\tprivate readonly activeActivityIds = new Set<string>();\n\tprivate enginePid: number | undefined;\n\n\tprivate declare options: RpcClientOptions;\n\n\tconstructor(options: RpcClientOptions = {}) {\n\t\tsuper();\n\t\tthis.options = options;\n\t}\n\n\tasync start(): Promise<void> {\n\t\tif (this.process) {\n\t\t\tthrow new Error(\"Client already started\");\n\t\t}\n\n\t\tconst cliPath = this.options.cliPath ?? \"dist/cli.js\";\n\t\tconst args = [\"--mode\", \"rpc\"];\n\n\t\tif (this.options.provider) {\n\t\t\targs.push(\"--provider\", this.options.provider);\n\t\t}\n\t\tif (this.options.model) {\n\t\t\targs.push(\"--model\", this.options.model);\n\t\t}\n\t\tif (this.options.args) {\n\t\t\targs.push(...this.options.args);\n\t\t}\n\n\t\tconst generation = ++this.generation;\n\t\tthis.exitError = null;\n\t\tthis.stderr = \"\";\n\t\tthis.activeActivityIds.clear();\n\t\tthis.enginePid = undefined;\n\t\tthis.engineMonitor = this.options.interactiveEngine\n\t\t\t? new InteractiveEngineMonitor(this.options.interactiveEngine.onDiagnostic, (message) =>\n\t\t\t\t\tthis.observeInteractiveEngineMessage(message, generation),\n\t\t\t\t)\n\t\t\t: undefined;\n\t\tthis.eventBuffer = this.engineMonitor ? new RpcEventBuffer((event) => this.emitEvent(event)) : undefined;\n\t\tconst childProcess = spawnRpcClientProcess({\n\t\t\tcliPath,\n\t\t\tcliArgs: args,\n\t\t\tcwd: this.options.cwd,\n\t\t\tenv: this.options.env,\n\t\t\truntimeExecutable: this.options.runtimeExecutable,\n\t\t\truntimeArgs: this.options.runtimeArgs,\n\t\t\tinteractiveEngine: this.engineMonitor !== undefined,\n\t\t\t...(this.options.interactiveEngine?.apiKey\n\t\t\t\t? { interactiveEngineApiKey: this.options.interactiveEngine.apiKey }\n\t\t\t\t: {}),\n\t\t});\n\t\tthis.process = childProcess;\n\t\tthis.stdinWriter = new QueuedWriter(childProcess.stdin!);\n\n\t\tchildProcess.once(\"exit\", (code, signal) =>\n\t\t\tthis.failGeneration(this.createProcessExitError(code, signal), generation, \"exit\"),\n\t\t);\n\t\tchildProcess.once(\"error\", (rawError) => this.failGeneration(rawError, generation, \"process-error\"));\n\t\tchildProcess.stdin?.on(\"error\", (rawError) => this.failGeneration(rawError, generation, \"stdin-error\"));\n\t\tconst reportStderr = createStderrReporter((message) => {\n\t\t\tif (generation !== this.generation) return;\n\t\t\tif (this.options.interactiveEngine) {\n\t\t\t\tthis.options.interactiveEngine.onDiagnostic({\n\t\t\t\t\tactivity: undefined,\n\t\t\t\t\telapsedMs: 0,\n\t\t\t\t\tlevel: \"blocking\",\n\t\t\t\t\tsource: \"stderr\",\n\t\t\t\t\tmessage,\n\t\t\t\t});\n\t\t\t} else console.log(message);\n\t\t});\n\t\t// Decode continuously per child, including split code points and the final incomplete sequence at EOF.\n\t\tchildProcess.stderr?.setEncoding(\"utf8\");\n\t\tchildProcess.stderr?.on(\"data\", (data: string) => {\n\t\t\tif (generation !== this.generation) return;\n\t\t\tthis.stderr = appendBoundedStderr(this.stderr, data);\n\t\t\treportStderr(data);\n\t\t});\n\t\tconst readerOptions = createInteractiveJsonlOptions(this.engineMonitor !== undefined);\n\t\tlet markStdoutDrained!: () => void;\n\t\tthis.stdoutDrained = new Promise<void>((resolve) => {\n\t\t\tmarkStdoutDrained = resolve;\n\t\t});\n\t\tthis.stopReadingStdout = attachJsonlLineReader(\n\t\t\tchildProcess.stdout!,\n\t\t\t(line) => {\n\t\t\t\tif (generation === this.generation) this.handleLine(line, generation);\n\t\t\t},\n\t\t\t{ ...readerOptions, onDrained: () => markStdoutDrained() },\n\t\t);\n\t\tif (this.engineMonitor) await this.engineMonitor.waitUntilReady();\n\t\telse await sleep(100);\n\n\t\tif (generation !== this.generation || this.process?.exitCode !== null) {\n\t\t\tthrow rpcTransportError(`Agent process exited immediately. Stderr: ${this.stderr}`);\n\t\t}\n\t}\n\n\t/**\n\t * Tell the engine child the host is quitting on purpose, and wait (bounded) for it to\n\t * record that. Call it before `stop()` for a quit the user asked for: stopping closes\n\t * stdin and sends SIGTERM, which is also how the child is stopped when the host itself\n\t * was signalled, so only this announcement lets the child tell the two apart.\n\t * Resolves true only when the child acknowledged the quit, and false without waiting when\n\t * there is no live engine child, or when the child exits or misses the deadline first.\n\t */\n\tasync announceExplicitQuit(timeoutMs = EXPLICIT_QUIT_ACK_TIMEOUT_MS): Promise<boolean> {\n\t\tconst writer = this.stdinWriter;\n\t\tif (!writer || !this.engineMonitor || this.generation <= this.lastEndedGeneration) return false;\n\t\tconst generation = this.generation;\n\t\tconst done = Promise.withResolvers<boolean>();\n\t\tthis.explicitQuitAck = { generation, acknowledge: () => done.resolve(true) };\n\t\tconst stopListening = this.onGenerationEnded((event) => {\n\t\t\tif (event.generation === generation) done.resolve(false);\n\t\t});\n\t\tconst timer = setTimeout(() => done.resolve(false), timeoutMs);\n\t\ttry {\n\t\t\tthis.bestEffort(\n\t\t\t\twriter.write(serializeInteractiveEngineFrame({ type: \"engine_explicit_quit\" })),\n\t\t\t\t\"explicit quit\",\n\t\t\t);\n\t\t\treturn await done.promise;\n\t\t} finally {\n\t\t\tclearTimeout(timer);\n\t\t\tstopListening();\n\t\t\tif (this.explicitQuitAck?.generation === generation) this.explicitQuitAck = undefined;\n\t\t}\n\t}\n\n\t/**\n\t * Explicit stop. Voids any in-flight restart permit, so a replacement caught\n\t * between its own stop and start can never spawn after this returns.\n\t */\n\tstop(): Promise<void> {\n\t\tthis.restartRevision += 1;\n\t\tif (this.stopPromise) return this.stopPromise;\n\t\tif (!this.process) return Promise.resolve();\n\t\tconst stopPromise = this.stopCurrentGeneration().finally(() => {\n\t\t\tif (this.stopPromise === stopPromise) this.stopPromise = undefined;\n\t\t});\n\t\tthis.stopPromise = stopPromise;\n\t\treturn stopPromise;\n\t}\n\n\t/**\n\t * Tear down the current child without touching the restart permit. The reader\n\t * stays attached and the generation stays current until the dead child's\n\t * stdout settles, so an ownership frame it already sent still reaches its\n\t * request; only then is the generation retired (see RpcTerminalDrain).\n\t */\n\tprivate async stopCurrentGeneration(): Promise<void> {\n\t\tconst child = this.process;\n\t\tif (!child) return;\n\t\tconst endedGeneration = this.generation;\n\t\tconst stopError = rpcTransportError(\"Agent process stopped\");\n\t\tthis.invalidateEngineShortcuts();\n\t\tconst terminateTree = this.engineMonitor !== undefined;\n\t\tthis.engineMonitor?.stop();\n\t\tthis.stdinWriter?.close(stopError);\n\t\t// Unblock an in-flight start()/waitUntilBound() for the generation being\n\t\t// replaced. Readiness has no deadline by design, so without this an\n\t\t// explicit stop of a hung replacement child could never be observed.\n\t\tthis.engineMonitor?.fail(stopError);\n\t\tthis.engineMonitor = undefined;\n\t\tthis.stdinWriter = undefined;\n\t\tthis.process = null;\n\t\t// Publish before terminating so host controllers tear down this generation's\n\t\t// UI while the writer is detached: disposal cannot write into a replacement.\n\t\tthis.publishGenerationEnded(endedGeneration, stopError, \"explicit-stop\", true);\n\t\t// Claim before terminating so the exit this provokes does not relabel a\n\t\t// deliberate stop; an exit that already claimed keeps its own error.\n\t\tthis.terminalDrain.claim(endedGeneration, stopError);\n\t\tawait terminateRpcClientProcess(child, terminateTree);\n\t\tawait this.beginTerminalDrain(endedGeneration, stopError);\n\t\tthis.stopReadingStdout?.();\n\t\tthis.stopReadingStdout = null;\n\t\tthis.generation += 1;\n\t\tthis.pendingRequests.rejectAll(stopError);\n\t\tthis.eventBuffer?.dispose();\n\t\tthis.eventBuffer = undefined;\n\t\tthis.activeActivityIds.clear();\n\t\tthis.options.interactiveEngine?.onActivityChange?.(false);\n\t}\n\n\t/** Subscribe to agent events. */\n\tonEvent(listener: RpcEventListener): () => void {\n\t\tthis.eventListeners.push(listener);\n\t\treturn () => {\n\t\t\tconst index = this.eventListeners.indexOf(listener);\n\t\t\tif (index !== -1) {\n\t\t\t\tthis.eventListeners.splice(index, 1);\n\t\t\t}\n\t\t};\n\t}\n\n\tonExtensionUIRequest(listener: (request: RpcExtensionUIRequest) => void): () => void {\n\t\tthis.extensionUIListeners.push(listener);\n\t\tfor (const request of this.pendingExtensionUIRequests.drain(this.generation)) listener(request);\n\t\treturn () => {\n\t\t\tconst index = this.extensionUIListeners.indexOf(listener);\n\t\t\tif (index !== -1) this.extensionUIListeners.splice(index, 1);\n\t\t};\n\t}\n\n\tasync respondExtensionUI(response: RpcExtensionUIResponse): Promise<void> {\n\t\tawait this.requireWriter().write(serializeJsonLine(response));\n\t}\n\n\tonInteractiveEngineMessage(listener: (message: InteractiveEngineMessage) => void): () => void {\n\t\tthis.engineMessageListeners.push(listener);\n\t\tfor (const message of this.pendingEngineMessages.drain(this.generation)) listener(message);\n\t\treturn () => {\n\t\t\tconst index = this.engineMessageListeners.indexOf(listener);\n\t\t\tif (index !== -1) this.engineMessageListeners.splice(index, 1);\n\t\t};\n\t}\n\n\tonInteractiveEngineKeybindingState(listener: (state: EngineKeybindingState) => void): () => void {\n\t\tconst messageListener = (message: InteractiveEngineMessage): void => {\n\t\t\tif (message.type === \"engine_keybindings_reloaded\") listener(message.state);\n\t\t};\n\t\tthis.engineMessageListeners.push(messageListener);\n\t\tif (this.latestEngineKeybindingState) listener(this.latestEngineKeybindingState);\n\t\treturn () => {\n\t\t\tconst index = this.engineMessageListeners.indexOf(messageListener);\n\t\t\tif (index !== -1) this.engineMessageListeners.splice(index, 1);\n\t\t};\n\t}\n\n\t/**\n\t * Subscribe to the engine's workflow activity. The engine publishes its snapshot as soon as it binds,\n\t * so an observer that attaches later starts from the current snapshot instead of missing it.\n\t */\n\tonInteractiveEngineWorkflowActivity(listener: (frame: WorkflowActivityFrame) => void): () => void {\n\t\tconst messageListener = (message: InteractiveEngineMessage): void => {\n\t\t\tif (message.type === \"engine_workflow_activity\") listener(message.frame);\n\t\t};\n\t\tthis.engineMessageListeners.push(messageListener);\n\t\tconst current = this.workflowActivity.current();\n\t\tif (current) listener(current);\n\t\treturn () => {\n\t\t\tconst index = this.engineMessageListeners.indexOf(messageListener);\n\t\t\tif (index !== -1) this.engineMessageListeners.splice(index, 1);\n\t\t};\n\t}\n\n\t/**\n\t * Subscribe to host-local generation death. Fires at most once per\n\t * generation, synchronously, before any restart work. A death that has\n\t * already happened for the current generation replays immediately, so a\n\t * listener attached after an exit still sees it.\n\t */\n\tonGenerationEnded(listener: InteractiveEngineGenerationEndedListener): () => void {\n\t\tthis.generationEndedListeners.push(listener);\n\t\tconst retained = this.retainedGenerationEnd;\n\t\t// Only while it still describes the live generation: once stop()/start()\n\t\t// has moved on, that death belongs to a replaced child.\n\t\tif (retained && retained.generation === this.generation) listener(retained);\n\t\treturn () => {\n\t\t\tconst index = this.generationEndedListeners.indexOf(listener);\n\t\t\tif (index !== -1) this.generationEndedListeners.splice(index, 1);\n\t\t};\n\t}\n\n\tsendInteractiveEngineCommand(command: InteractiveEngineCommand): void {\n\t\tconst writer = this.stdinWriter;\n\t\tif (command.type === \"engine_project_trust_start\" || command.type === \"engine_project_trust_end\") {\n\t\t\tif (this.generation <= this.lastEndedGeneration) return;\n\t\t\t// The terminal can open and close /trust while the engine is still binding.\n\t\t\t// Retain both frames, without delaying the host-owned decision.\n\t\t\tif (this.engineMonitor && this.boundGeneration !== this.generation) {\n\t\t\t\tthis.pendingProjectTrustFrames.push(this.generation, serializeInteractiveEngineFrame(command));\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tif (!writer) return;\n\t\tconst frame = serializeInteractiveEngineFrame(command);\n\t\tif (\n\t\t\tcommand.type === \"engine_custom_render\" ||\n\t\t\tcommand.type === \"engine_tool_render\" ||\n\t\t\tcommand.type === \"engine_message_render\"\n\t\t) {\n\t\t\twriter.offerLatest(`render:${command.componentId}`, frame);\n\t\t\treturn;\n\t\t}\n\t\tthis.bestEffort(writer.write(frame), `engine command ${command.type}`);\n\t}\n\twaitForInteractiveEngineBound(): Promise<void> {\n\t\treturn this.engineMonitor?.waitUntilBound() ?? Promise.resolve();\n\t}\n\twaitForInteractiveEngineProjectTrust(): Promise<void> {\n\t\treturn this.engineMonitor?.waitUntilProjectTrustSettled() ?? Promise.resolve();\n\t}\n\twaitForInteractiveEngineResources(): Promise<void> {\n\t\treturn this.engineMonitor?.waitUntilResourcesReady() ?? Promise.resolve();\n\t}\n\tgetEnginePid(): number | undefined {\n\t\treturn this.enginePid;\n\t}\n\tgetGeneration(): number {\n\t\treturn this.generation;\n\t}\n\n\t/**\n\t * Replace the engine child, unless an explicit stop supersedes this attempt.\n\t * The permit is checked immediately before spawning, so a `stop()` in that\n\t * window is always observed; cancellation throws rather than returning\n\t * quietly, because callers go on to initialize against the new child.\n\t */\n\tasync restart(sessionId: string | undefined, options?: { sessionDirectory?: string; cwd?: string }): Promise<void> {\n\t\tconst permit = this.restartRevision;\n\t\tawait this.stopCurrentGeneration();\n\t\t// Join an in-flight stop before the permit check: waiting after it would\n\t\t// reopen the window this fence exists to close.\n\t\tif (this.stopPromise) await this.stopPromise;\n\t\tif (permit !== this.restartRevision) throw rpcTransportError(RESTART_CANCELLED_MESSAGE);\n\t\tthis.options = {\n\t\t\t...this.options,\n\t\t\tcwd: options?.cwd ?? this.options.cwd,\n\t\t\targs: restartCliArgs(this.options.args, sessionId, options?.sessionDirectory),\n\t\t};\n\t\tawait this.start();\n\t\tawait this.waitForInteractiveEngineBound();\n\t}\n\n\tasync requestInternal<T>(command: RpcCommandBody): Promise<T> {\n\t\treturn this.data<T>(await this.request(command));\n\t}\n\tuserBashWithUpdates(\n\t\tcommand: string,\n\t\tonUpdate: (delta: string, channel: BashOutputChannel) => void,\n\t\toptions?: { excludeFromContext?: boolean; onRequestId?: (id: string) => void },\n\t): Promise<BashResult> {\n\t\treturn runUserBashWithUpdates(this, command, onUpdate, options, (body, onId) => this.request(body, onId));\n\t}\n\tgetStderr(): string {\n\t\treturn this.stderr;\n\t}\n\n\twaitForIdle(timeout = 60000): Promise<void> {\n\t\treturn waitForRpcIdle(this, timeout);\n\t}\n\tcollectEvents(timeout = 60000): Promise<RpcEvent[]> {\n\t\treturn collectRpcEvents(this, timeout);\n\t}\n\tasync promptAndWait(message: string, images?: ImageContent[], timeout = 60000): Promise<RpcEvent[]> {\n\t\tconst eventsPromise = this.collectEvents(timeout);\n\t\tconst accepted = this.prompt(message, images);\n\t\t// A prompt has no request deadline, so `timeout` must also end the wait while\n\t\t// the prompt is still unacknowledged. Whichever settles first decides; both are\n\t\t// observed so the loser's later rejection is never an unhandled rejection.\n\t\teventsPromise.catch(() => {});\n\t\taccepted.catch(() => {});\n\t\tawait Promise.race([accepted, eventsPromise]);\n\t\treturn eventsPromise;\n\t}\n\tprivate handleLine(line: string, generation: number): void {\n\t\tif (this.terminalDrain.observe(generation, line, (id) => this.pendingRequests.markAccepted(id))) return;\n\t\tif (this.engineMonitor?.handleLine(line)) return;\n\t\ttry {\n\t\t\tconst data = JSON.parse(line) as { type?: string; id?: string };\n\t\t\tif (data.type === \"extension_ui_request\") {\n\t\t\t\tconst request = data as RpcExtensionUIRequest;\n\t\t\t\tif (this.extensionUIListeners.length === 0) this.pendingExtensionUIRequests.push(generation, request);\n\t\t\t\tfor (const listener of this.extensionUIListeners) listener(request);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (data.type === \"response\" && data.id && this.pendingRequests.resolve(data.id, data as RpcResponse)) return;\n\t\t\tconst event = data as RpcEvent;\n\t\t\tif (this.eventBuffer) this.eventBuffer.enqueue(event);\n\t\t\telse this.emitEvent(event);\n\t\t} catch {\n\t\t\tif (this.engineMonitor) this.failTransport(rpcTransportError(\"Interactive engine emitted malformed JSONL\"));\n\t\t}\n\t}\n\tprivate emitEvent(event: RpcEvent): void {\n\t\t// Iterate a snapshot so listeners that unsubscribe during dispatch do not make later listeners miss this event.\n\t\tfor (const listener of [...this.eventListeners]) listener(event);\n\t}\n\tprivate emitInteractiveEngineMessage(message: InteractiveEngineMessage, generation: number): void {\n\t\tif (\n\t\t\tthis.engineMessageListeners.length === 0 &&\n\t\t\t(message.type.startsWith(\"engine_custom_\") || message.type.startsWith(\"engine_resources_\"))\n\t\t) {\n\t\t\tthis.pendingEngineMessages.push(generation, message);\n\t\t}\n\t\tfor (const listener of this.engineMessageListeners) listener(message);\n\t}\n\tprivate createProcessExitError(code: number | null, signal: NodeJS.Signals | null): Error {\n\t\treturn rpcTransportError(`Agent process exited (code=${code} signal=${signal}). Stderr: ${this.stderr}`);\n\t}\n\tprivate invalidateEngineShortcuts(): void {\n\t\tif (!this.latestEngineKeybindingState || this.latestEngineKeybindingState.shortcuts.length === 0) return;\n\t\tconst state: EngineKeybindingState = { ...this.latestEngineKeybindingState, shortcuts: [] };\n\t\tthis.latestEngineKeybindingState = state;\n\t\tthis.emitInteractiveEngineMessage({ type: \"engine_keybindings_reloaded\", state }, this.generation);\n\t}\n\tprivate observeInteractiveEngineMessage(message: InteractiveEngineMessage, generation: number): void {\n\t\t// Ownership is the one thing a dead generation may still report: request\n\t\t// ids never repeat, and the alternative is classifying work it already\n\t\t// started as never sent. Nothing else from it may touch host state — a\n\t\t// stale frame would revive a PID, an activity, or a mount that is gone.\n\t\tif (message.type === \"engine_request_accepted\") {\n\t\t\tif (generation === this.generation) this.pendingRequests.markAccepted(message.requestId);\n\t\t\treturn;\n\t\t}\n\t\tif (message.type === \"engine_explicit_quit_ack\") {\n\t\t\tif (this.explicitQuitAck?.generation === generation) this.explicitQuitAck.acknowledge();\n\t\t\treturn;\n\t\t}\n\t\tif (generation !== this.generation || generation <= this.lastEndedGeneration) return;\n\t\tif (message.type === \"engine_heartbeat\") this.options.interactiveEngine?.onHeartbeat?.();\n\t\tif (message.type === \"engine_ready\") this.enginePid = message.pid;\n\t\tif (message.type === \"engine_bound\") {\n\t\t\tthis.boundGeneration = generation;\n\t\t\tfor (const frame of this.pendingProjectTrustFrames.drain(generation)) {\n\t\t\t\tif (this.stdinWriter) this.bestEffort(this.stdinWriter.write(frame), \"project trust notification\");\n\t\t\t}\n\t\t}\n\t\tif (message.type === \"engine_keybindings_reloaded\") this.latestEngineKeybindingState = message.state;\n\t\tif (message.type === \"engine_workflow_activity\") this.workflowActivity.apply(message.frame);\n\t\tif (message.type === \"engine_activity_started\") this.activeActivityIds.add(message.activity.id);\n\t\telse if (message.type === \"engine_activity_finished\") this.activeActivityIds.delete(message.activityId);\n\t\tthis.options.interactiveEngine?.onActivityChange?.(this.activeActivityIds.size > 0);\n\t\tthis.emitInteractiveEngineMessage(message, generation);\n\t}\n\t/**\n\t * Shared teardown for every unexpected end of `generation`. Death publishes\n\t * at once for the host UI; its requests wait for stdout (RpcTerminalDrain).\n\t */\n\tprivate failGeneration(rawError: Error, generation: number, kind: InteractiveEngineGenerationEndKind): void {\n\t\tif (generation !== this.generation) return;\n\t\tconst error = markRpcTransportFailure(rawError);\n\t\tthis.exitError = error;\n\t\tthis.stdinWriter?.close(error);\n\t\tthis.engineMonitor?.fail(error);\n\t\tif (kind === \"exit\") {\n\t\t\tthis.activeActivityIds.clear();\n\t\t\tthis.options.interactiveEngine?.onActivityChange?.(false);\n\t\t}\n\t\tthis.beginTerminalDrain(generation, error);\n\t\tthis.publishGenerationEnded(generation, error, kind, false);\n\t}\n\t/** Hold this generation's requests until its stdout drains (RpcTerminalDrain). */\n\tprivate beginTerminalDrain(generation: number, error: Error): Promise<void> {\n\t\treturn this.terminalDrain.begin(generation, this.stdoutDrained, error, (settled) => {\n\t\t\tif (generation === this.generation) this.pendingRequests.rejectAll(settled);\n\t\t});\n\t}\n\tprivate publishGenerationEnded(\n\t\tgeneration: number,\n\t\terror: Error,\n\t\tkind: InteractiveEngineGenerationEndKind,\n\t\texpected: boolean,\n\t): void {\n\t\tif (generation <= this.lastEndedGeneration) return;\n\t\tthis.lastEndedGeneration = generation;\n\t\tconst event: InteractiveEngineGenerationEnded = { generation, error, kind, expected };\n\t\tthis.retainedGenerationEnd = event;\n\t\t// Death is a strict boundary: drop this generation's buffered frames\n\t\t// BEFORE teardown runs, so no listener can drain a stale mount frame\n\t\t// while it is closing that very generation's components.\n\t\tthis.pendingEngineMessages.dropGeneration(generation);\n\t\tthis.workflowActivity.reset();\n\t\tthis.pendingExtensionUIRequests.dropGeneration(generation);\n\t\tthis.pendingProjectTrustFrames.dropGeneration(generation);\n\t\tfor (const listener of [...this.generationEndedListeners]) listener(event);\n\t}\n\tprivate failTransport(rawError: Error): void {\n\t\tthis.options.interactiveEngine?.onDiagnostic({\n\t\t\tactivity: undefined,\n\t\t\telapsedMs: 0,\n\t\t\tlevel: \"unresponsive\",\n\t\t\tmessage: rawError.message,\n\t\t});\n\t\tthis.failGeneration(rawError, this.generation, \"transport-error\");\n\t}\n\tprivate requireWriter(): QueuedWriter {\n\t\tif (!this.stdinWriter) throw rpcTransportError(\"Agent process stdin is not writable\");\n\t\treturn this.stdinWriter;\n\t}\n\tprivate bestEffort(operation: Promise<void>, label: string): void {\n\t\tvoid operation.catch((error: Error) => {\n\t\t\tif (!this.process || this.exitError) return;\n\t\t\tthis.options.interactiveEngine?.onDiagnostic({\n\t\t\t\tactivity: undefined,\n\t\t\t\telapsedMs: 0,\n\t\t\t\tlevel: \"unresponsive\",\n\t\t\t\tmessage: `Interactive engine ${label} failed: ${error.message}`,\n\t\t\t});\n\t\t});\n\t}\n\tprotected async request(command: RpcCommandBody, onRequestId?: (id: string) => void): Promise<RpcResponse> {\n\t\tconst childProcess = this.process;\n\t\tif (!childProcess) throw rpcTransportError(\"Client not started\");\n\t\tif (this.exitError) throw this.exitError;\n\t\tif (childProcess.exitCode !== null) {\n\t\t\tconst error = this.createProcessExitError(childProcess.exitCode, childProcess.signalCode);\n\t\t\tthis.exitError = error;\n\t\t\tthrow error;\n\t\t}\n\t\tconst id = `req_${++this.requestId}`;\n\t\tonRequestId?.(id);\n\t\tconst fullCommand = { ...command, id } as RpcCommand;\n\t\tlet timeout: ReturnType<typeof setTimeout> | undefined;\n\t\tlet rejectResponse!: (error: Error) => void;\n\t\tconst response = new Promise<RpcResponse>((resolve, reject) => {\n\t\t\trejectResponse = reject;\n\t\t\tthis.pendingRequests.add(id, {\n\t\t\t\tresolve: (value) => {\n\t\t\t\t\tif (timeout) clearTimeout(timeout);\n\t\t\t\t\tresolve(value);\n\t\t\t\t},\n\t\t\t\treject: (error) => {\n\t\t\t\t\tif (timeout) clearTimeout(timeout);\n\t\t\t\t\treject(error);\n\t\t\t\t},\n\t\t\t});\n\t\t});\n\t\ttry {\n\t\t\tawait this.requireWriter().write(serializeJsonLine(fullCommand));\n\t\t} catch (error) {\n\t\t\tthis.pendingRequests.delete(id);\n\t\t\t// Idempotent: the writer already classified this, but a caller-supplied\n\t\t\t// stream can reject with anything, and a send that never left the host\n\t\t\t// is a transport failure whatever it threw.\n\t\t\trejectResponse(markRpcTransportFailure(error));\n\t\t\treturn response;\n\t\t}\n\t\tif (this.pendingRequests.has(id) && !LONG_LIVED_COMMANDS.has(command.type)) {\n\t\t\ttimeout = setTimeout(() => {\n\t\t\t\tthis.pendingRequests.delete(id);\n\t\t\t\trejectResponse(new Error(`Timeout waiting for response to ${command.type}. Stderr: ${this.stderr}`));\n\t\t\t}, this.options.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS);\n\t\t}\n\t\treturn response;\n\t}\n\tprivate assertSuccess(response: RpcResponse): void {\n\t\tif (response.success) return;\n\t\tif (response.errorCode === \"credential_synchronization\" && response.errorDetails) {\n\t\t\tthrow new CredentialSynchronizationError(\n\t\t\t\tresponse.errorDetails.providerId,\n\t\t\t\tresponse.errorDetails.operation,\n\t\t\t\tundefined,\n\t\t\t\t{ cause: new Error(response.error) },\n\t\t\t);\n\t\t}\n\t\tthrow new Error(response.error);\n\t}\n\tprotected data<T>(response: RpcResponse): T {\n\t\tthis.assertSuccess(response);\n\t\tconst successResponse = response as Extract<RpcResponse, { success: true; data: unknown }>;\n\t\treturn successResponse.data as T;\n\t}\n}\n"]}
1
+ {"version":3,"file":"rpc-client.js","sourceRoot":"","sources":["../../../src/modes/rpc/rpc-client.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,8BAA8B,EAAE,MAAM,6BAA6B,CAAC;AAE7E,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAO7C,OAAO,EAAE,wBAAwB,EAAE,MAAM,yC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C;YACtG,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,gBAAgB,IAAI,0BAA0B,CAAC,CAAC;QACjE,CAAC;QACD,OAAO,QAAQ,CAAC;IACjB,CAAC;IACO,aAAa,CAAC,QAAqB;QAC1C,IAAI,QAAQ,CAAC,OAAO;YAAE,OAAO;QAC7B,IAAI,QAAQ,CAAC,SAAS,KAAK,4BAA4B,IAAI,QAAQ,CAAC,YAAY,EAAE,CAAC;YAClF,MAAM,IAAI,8BAA8B,CACvC,QAAQ,CAAC,YAAY,CAAC,UAAU,EAChC,QAAQ,CAAC,YAAY,CAAC,SAAS,EAC/B,SAAS,EACT,EAAE,KAAK,EAAE,IAAI,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CACpC,CAAC;QACH,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IACjC,CAAC;IACS,IAAI,CAAI,QAAqB;QACtC,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;QAC7B,MAAM,eAAe,GAAG,QAAkE,CAAC;QAC3F,OAAO,eAAe,CAAC,IAAS,CAAC;IAClC,CAAC;CACD","sourcesContent":["import type { ChildProcess } from \"node:child_process\";\nimport type { ImageContent } from \"@bastani/pi-ai/compat\";\nimport type { BashResult } from \"../../core/bash-executor.ts\";\nimport type { WorkflowActivityFrame } from \"../../core/extensions/workflow-events.js\";\nimport { CredentialSynchronizationError } from \"../../core/model-runtime.js\";\nimport type { BashOutputChannel } from \"../../core/tools/bash.js\";\nimport { sleep } from \"../../utils/sleep.ts\";\nimport type { ActivityWatchdogDiagnostic } from \"../interactive-engine/activity-watchdog.ts\";\nimport type {\n\tInteractiveEngineGenerationEnded,\n\tInteractiveEngineGenerationEndedListener,\n\tInteractiveEngineGenerationEndKind,\n} from \"../interactive-engine/engine-generation.ts\";\nimport { InteractiveEngineMonitor } from \"../interactive-engine/engine-monitor.ts\";\nimport { WorkflowActivityMirror } from \"../interactive-engine/engine-workflow-activity.ts\";\nimport {\n\ttype EngineKeybindingState,\n\ttype InteractiveEngineCommand,\n\ttype InteractiveEngineMessage,\n\tserializeInteractiveEngineFrame,\n} from \"../interactive-engine/protocol.ts\";\nimport { attachJsonlLineReader, serializeJsonLine } from \"./jsonl.ts\";\nimport { QueuedWriter } from \"./queued-writer.ts\";\nimport { RpcClientApi, type RpcCommandBody } from \"./rpc-client-api.ts\";\nimport {\n\tappendBoundedStderr,\n\tcreateInteractiveJsonlOptions,\n\tcreateStderrReporter,\n\trestartCliArgs,\n\tspawnRpcClientProcess,\n\tterminateRpcClientProcess,\n} from \"./rpc-client-process.js\";\nimport { collectRpcEvents, runUserBashWithUpdates, waitForRpcIdle } from \"./rpc-client-waits.ts\";\nimport { DEFAULT_REQUEST_TIMEOUT_MS, LONG_LIVED_COMMANDS, RESTART_CANCELLED_MESSAGE } from \"./rpc-command-timeouts.ts\";\nimport { RpcEventBuffer } from \"./rpc-event-buffer.ts\";\nimport { GenerationBuffer } from \"./rpc-generation-buffer.ts\";\nimport { RpcPendingRequests } from \"./rpc-pending-requests.ts\";\nimport { RpcTerminalDrain } from \"./rpc-terminal-drain.ts\";\nimport { markRpcTransportFailure, rpcTransportError } from \"./rpc-transport-error.ts\";\nimport type { RpcCommand, RpcEvent, RpcExtensionUIRequest, RpcExtensionUIResponse, RpcResponse } from \"./rpc-types.ts\";\n\nexport type { ModelInfo, RpcCommandBody } from \"./rpc-client-api.ts\";\nexport type { RpcEvent } from \"./rpc-types.ts\";\n\nexport interface RpcClientOptions {\n\tcliPath?: string;\n\tcwd?: string;\n\tenv?: Record<string, string>;\n\tprovider?: string;\n\tmodel?: string;\n\targs?: string[];\n\truntimeExecutable?: string;\n\truntimeArgs?: string[];\n\t/**\n\t * Bounded deadline (ms) applied to short metadata/control requests. Long-lived\n\t * commands (see LONG_LIVED_COMMANDS) never use this timer. Defaults to 30s.\n\t */\n\trequestTimeoutMs?: number;\n\tinteractiveEngine?: {\n\t\tonDiagnostic: (diagnostic: ActivityWatchdogDiagnostic) => void;\n\t\tonActivityChange?: (active: boolean) => void;\n\t\t/**\n\t\t * Heartbeat observer. Deliberately NOT a generic engine-message listener:\n\t\t * subscribing there drains the buffered startup custom-UI messages into the\n\t\t * first subscriber and stops buffering for the real controllers.\n\t\t */\n\t\tonHeartbeat?: () => void;\n\t\t/**\n\t\t * Credential for the engine child. Delivered through the protected\n\t\t * bootstrap file, never through the child's environment or argv.\n\t\t */\n\t\tapiKey?: string;\n\t};\n}\n\nexport type RpcEventListener = (event: RpcEvent) => void;\n\n/** Longest an explicit quit waits for the child to acknowledge it before stopping an unresponsive engine anyway. */\nconst EXPLICIT_QUIT_ACK_TIMEOUT_MS = 1000;\n\nexport class RpcClient extends RpcClientApi {\n\tprivate process: ChildProcess | null = null;\n\tprivate stopReadingStdout: (() => void) | null = null;\n\tprivate eventListeners: RpcEventListener[] = [];\n\tprivate extensionUIListeners: Array<(request: RpcExtensionUIRequest) => void> = [];\n\tprivate readonly pendingExtensionUIRequests = new GenerationBuffer<RpcExtensionUIRequest>();\n\tprivate engineMessageListeners: Array<(message: InteractiveEngineMessage) => void> = [];\n\tprivate latestEngineKeybindingState: EngineKeybindingState | undefined;\n\tprivate readonly workflowActivity = new WorkflowActivityMirror();\n\tprivate readonly pendingEngineMessages = new GenerationBuffer<InteractiveEngineMessage>();\n\tprivate readonly pendingProjectTrustFrames = new GenerationBuffer<string>();\n\tprivate boundGeneration = 0;\n\tprivate explicitQuitAck: { generation: number; acknowledge: () => void } | undefined;\n\tprivate readonly pendingRequests = new RpcPendingRequests();\n\t/** Bumped by every explicit stop; a restart holds a permit across its own stop. */\n\tprivate restartRevision = 0;\n\tprivate stopPromise: Promise<void> | undefined;\n\tprivate readonly terminalDrain = new RpcTerminalDrain();\n\tprivate stdoutDrained: Promise<void> = Promise.resolve();\n\tprivate requestId = 0;\n\tprivate stderr = \"\";\n\tprivate exitError: Error | null = null;\n\tprivate engineMonitor: InteractiveEngineMonitor | undefined;\n\tprivate eventBuffer: RpcEventBuffer | undefined;\n\tprivate stdinWriter: QueuedWriter | undefined;\n\tprivate generation = 0;\n\tprivate lastEndedGeneration = 0;\n\tprivate generationEndedListeners: InteractiveEngineGenerationEndedListener[] = [];\n\t/**\n\t * The latest generation-end event, retained so a subscriber that attaches\n\t * after the child died still observes it. A child can exit between\n\t * `start()` returning and the runtime constructing its listeners.\n\t */\n\tprivate retainedGenerationEnd: InteractiveEngineGenerationEnded | undefined;\n\tprivate readonly activeActivityIds = new Set<string>();\n\tprivate enginePid: number | undefined;\n\n\tprivate declare options: RpcClientOptions;\n\n\tconstructor(options: RpcClientOptions = {}) {\n\t\tsuper();\n\t\tthis.options = options;\n\t}\n\n\tasync start(): Promise<void> {\n\t\tif (this.process) {\n\t\t\tthrow new Error(\"Client already started\");\n\t\t}\n\n\t\tconst cliPath = this.options.cliPath ?? \"dist/cli.js\";\n\t\tconst args = [\"--mode\", \"rpc\"];\n\n\t\tif (this.options.provider) {\n\t\t\targs.push(\"--provider\", this.options.provider);\n\t\t}\n\t\tif (this.options.model) {\n\t\t\targs.push(\"--model\", this.options.model);\n\t\t}\n\t\tif (this.options.args) {\n\t\t\targs.push(...this.options.args);\n\t\t}\n\n\t\tconst generation = ++this.generation;\n\t\tthis.exitError = null;\n\t\tthis.stderr = \"\";\n\t\tthis.activeActivityIds.clear();\n\t\tthis.enginePid = undefined;\n\t\tthis.engineMonitor = this.options.interactiveEngine\n\t\t\t? new InteractiveEngineMonitor(this.options.interactiveEngine.onDiagnostic, (message) =>\n\t\t\t\t\tthis.observeInteractiveEngineMessage(message, generation),\n\t\t\t\t)\n\t\t\t: undefined;\n\t\tthis.eventBuffer = this.engineMonitor ? new RpcEventBuffer((event) => this.emitEvent(event)) : undefined;\n\t\tconst childProcess = spawnRpcClientProcess({\n\t\t\tcliPath,\n\t\t\tcliArgs: args,\n\t\t\tcwd: this.options.cwd,\n\t\t\tenv: this.options.env,\n\t\t\truntimeExecutable: this.options.runtimeExecutable,\n\t\t\truntimeArgs: this.options.runtimeArgs,\n\t\t\tinteractiveEngine: this.engineMonitor !== undefined,\n\t\t\t...(this.options.interactiveEngine?.apiKey\n\t\t\t\t? { interactiveEngineApiKey: this.options.interactiveEngine.apiKey }\n\t\t\t\t: {}),\n\t\t});\n\t\tthis.process = childProcess;\n\t\tthis.stdinWriter = new QueuedWriter(childProcess.stdin!);\n\n\t\tchildProcess.once(\"exit\", (code, signal) =>\n\t\t\tthis.failGeneration(this.createProcessExitError(code, signal), generation, \"exit\"),\n\t\t);\n\t\tchildProcess.once(\"error\", (rawError) => this.failGeneration(rawError, generation, \"process-error\"));\n\t\tchildProcess.stdin?.on(\"error\", (rawError) => this.failGeneration(rawError, generation, \"stdin-error\"));\n\t\tconst reportStderr = createStderrReporter((message) => {\n\t\t\tif (generation !== this.generation) return;\n\t\t\tif (this.options.interactiveEngine) {\n\t\t\t\tthis.options.interactiveEngine.onDiagnostic({\n\t\t\t\t\tactivity: undefined,\n\t\t\t\t\telapsedMs: 0,\n\t\t\t\t\tlevel: \"blocking\",\n\t\t\t\t\tsource: \"stderr\",\n\t\t\t\t\tmessage,\n\t\t\t\t});\n\t\t\t} else console.log(message);\n\t\t});\n\t\t// Decode continuously per child, including split code points and the final incomplete sequence at EOF.\n\t\tchildProcess.stderr?.setEncoding(\"utf8\");\n\t\tchildProcess.stderr?.on(\"data\", (data: string) => {\n\t\t\tif (generation !== this.generation) return;\n\t\t\tthis.stderr = appendBoundedStderr(this.stderr, data);\n\t\t\treportStderr(data);\n\t\t});\n\t\tconst readerOptions = createInteractiveJsonlOptions(this.engineMonitor !== undefined);\n\t\tlet markStdoutDrained!: () => void;\n\t\tthis.stdoutDrained = new Promise<void>((resolve) => {\n\t\t\tmarkStdoutDrained = resolve;\n\t\t});\n\t\tthis.stopReadingStdout = attachJsonlLineReader(\n\t\t\tchildProcess.stdout!,\n\t\t\t(line) => {\n\t\t\t\tif (generation === this.generation) this.handleLine(line, generation);\n\t\t\t},\n\t\t\t{ ...readerOptions, onDrained: () => markStdoutDrained() },\n\t\t);\n\t\tif (this.engineMonitor) await this.engineMonitor.waitUntilReady();\n\t\telse await sleep(100);\n\n\t\tif (generation !== this.generation || this.process?.exitCode !== null) {\n\t\t\tthrow rpcTransportError(`Agent process exited immediately. Stderr: ${this.stderr}`);\n\t\t}\n\t}\n\n\t/**\n\t * Tell the engine child the host is quitting on purpose, and wait (bounded) for it to\n\t * record that. Call it before `stop()` for a quit the user asked for: stopping closes\n\t * stdin and sends SIGTERM, which is also how the child is stopped when the host itself\n\t * was signalled, so only this announcement lets the child tell the two apart.\n\t * Resolves true only when the child acknowledged the quit, and false without waiting when\n\t * there is no live engine child, or when the child exits or misses the deadline first.\n\t */\n\tasync announceExplicitQuit(timeoutMs = EXPLICIT_QUIT_ACK_TIMEOUT_MS): Promise<boolean> {\n\t\tconst writer = this.stdinWriter;\n\t\tif (!writer || !this.engineMonitor || this.generation <= this.lastEndedGeneration) return false;\n\t\tconst generation = this.generation;\n\t\tconst done = Promise.withResolvers<boolean>();\n\t\tthis.explicitQuitAck = { generation, acknowledge: () => done.resolve(true) };\n\t\tconst stopListening = this.onGenerationEnded((event) => {\n\t\t\tif (event.generation === generation) done.resolve(false);\n\t\t});\n\t\tconst timer = setTimeout(() => done.resolve(false), timeoutMs);\n\t\ttry {\n\t\t\tthis.bestEffort(\n\t\t\t\twriter.write(serializeInteractiveEngineFrame({ type: \"engine_explicit_quit\" })),\n\t\t\t\t\"explicit quit\",\n\t\t\t);\n\t\t\treturn await done.promise;\n\t\t} finally {\n\t\t\tclearTimeout(timer);\n\t\t\tstopListening();\n\t\t\tif (this.explicitQuitAck?.generation === generation) this.explicitQuitAck = undefined;\n\t\t}\n\t}\n\n\t/**\n\t * Explicit stop. Voids any in-flight restart permit, so a replacement caught\n\t * between its own stop and start can never spawn after this returns.\n\t */\n\tstop(): Promise<void> {\n\t\tthis.restartRevision += 1;\n\t\tif (this.stopPromise) return this.stopPromise;\n\t\tif (!this.process) return Promise.resolve();\n\t\tconst stopPromise = this.stopCurrentGeneration().finally(() => {\n\t\t\tif (this.stopPromise === stopPromise) this.stopPromise = undefined;\n\t\t});\n\t\tthis.stopPromise = stopPromise;\n\t\treturn stopPromise;\n\t}\n\n\t/**\n\t * Tear down the current child without touching the restart permit. The reader\n\t * stays attached and the generation stays current until the dead child's\n\t * stdout settles, so an ownership frame it already sent still reaches its\n\t * request; only then is the generation retired (see RpcTerminalDrain).\n\t */\n\tprivate async stopCurrentGeneration(): Promise<void> {\n\t\tconst child = this.process;\n\t\tif (!child) return;\n\t\tconst endedGeneration = this.generation;\n\t\tconst stopError = rpcTransportError(\"Agent process stopped\");\n\t\tthis.invalidateEngineShortcuts();\n\t\tconst terminateTree = this.engineMonitor !== undefined;\n\t\tthis.engineMonitor?.stop();\n\t\tthis.stdinWriter?.close(stopError);\n\t\t// Unblock an in-flight start()/waitUntilBound() for the generation being\n\t\t// replaced. Readiness has no deadline by design, so without this an\n\t\t// explicit stop of a hung replacement child could never be observed.\n\t\tthis.engineMonitor?.fail(stopError);\n\t\tthis.engineMonitor = undefined;\n\t\tthis.stdinWriter = undefined;\n\t\tthis.process = null;\n\t\t// Publish before terminating so host controllers tear down this generation's\n\t\t// UI while the writer is detached: disposal cannot write into a replacement.\n\t\tthis.publishGenerationEnded(endedGeneration, stopError, \"explicit-stop\", true);\n\t\t// Claim before terminating so the exit this provokes does not relabel a\n\t\t// deliberate stop; an exit that already claimed keeps its own error.\n\t\tthis.terminalDrain.claim(endedGeneration, stopError);\n\t\tawait terminateRpcClientProcess(child, terminateTree);\n\t\tawait this.beginTerminalDrain(endedGeneration, stopError);\n\t\tthis.stopReadingStdout?.();\n\t\tthis.stopReadingStdout = null;\n\t\tthis.generation += 1;\n\t\tthis.pendingRequests.rejectAll(stopError);\n\t\tthis.eventBuffer?.dispose();\n\t\tthis.eventBuffer = undefined;\n\t\tthis.activeActivityIds.clear();\n\t\tthis.options.interactiveEngine?.onActivityChange?.(false);\n\t}\n\n\t/** Subscribe to agent events. */\n\tonEvent(listener: RpcEventListener): () => void {\n\t\tthis.eventListeners.push(listener);\n\t\treturn () => {\n\t\t\tconst index = this.eventListeners.indexOf(listener);\n\t\t\tif (index !== -1) {\n\t\t\t\tthis.eventListeners.splice(index, 1);\n\t\t\t}\n\t\t};\n\t}\n\n\tonExtensionUIRequest(listener: (request: RpcExtensionUIRequest) => void): () => void {\n\t\tthis.extensionUIListeners.push(listener);\n\t\tfor (const request of this.pendingExtensionUIRequests.drain(this.generation)) listener(request);\n\t\treturn () => {\n\t\t\tconst index = this.extensionUIListeners.indexOf(listener);\n\t\t\tif (index !== -1) this.extensionUIListeners.splice(index, 1);\n\t\t};\n\t}\n\n\tasync respondExtensionUI(response: RpcExtensionUIResponse): Promise<void> {\n\t\tawait this.requireWriter().write(serializeJsonLine(response));\n\t}\n\n\tonInteractiveEngineMessage(listener: (message: InteractiveEngineMessage) => void): () => void {\n\t\tthis.engineMessageListeners.push(listener);\n\t\tfor (const message of this.pendingEngineMessages.drain(this.generation)) listener(message);\n\t\treturn () => {\n\t\t\tconst index = this.engineMessageListeners.indexOf(listener);\n\t\t\tif (index !== -1) this.engineMessageListeners.splice(index, 1);\n\t\t};\n\t}\n\n\tonInteractiveEngineKeybindingState(listener: (state: EngineKeybindingState) => void): () => void {\n\t\tconst messageListener = (message: InteractiveEngineMessage): void => {\n\t\t\tif (message.type === \"engine_keybindings_reloaded\") listener(message.state);\n\t\t};\n\t\tthis.engineMessageListeners.push(messageListener);\n\t\tif (this.latestEngineKeybindingState) listener(this.latestEngineKeybindingState);\n\t\treturn () => {\n\t\t\tconst index = this.engineMessageListeners.indexOf(messageListener);\n\t\t\tif (index !== -1) this.engineMessageListeners.splice(index, 1);\n\t\t};\n\t}\n\n\t/**\n\t * Subscribe to the engine's workflow activity. The engine publishes its snapshot as soon as it binds,\n\t * so an observer that attaches later starts from the current snapshot instead of missing it.\n\t */\n\tonInteractiveEngineWorkflowActivity(listener: (frame: WorkflowActivityFrame) => void): () => void {\n\t\tconst messageListener = (message: InteractiveEngineMessage): void => {\n\t\t\tif (message.type === \"engine_workflow_activity\") listener(message.frame);\n\t\t};\n\t\tthis.engineMessageListeners.push(messageListener);\n\t\tconst current = this.workflowActivity.current();\n\t\tif (current) listener(current);\n\t\treturn () => {\n\t\t\tconst index = this.engineMessageListeners.indexOf(messageListener);\n\t\t\tif (index !== -1) this.engineMessageListeners.splice(index, 1);\n\t\t};\n\t}\n\n\t/**\n\t * Subscribe to host-local generation death. Fires at most once per\n\t * generation, synchronously, before any restart work. A death that has\n\t * already happened for the current generation replays immediately, so a\n\t * listener attached after an exit still sees it.\n\t */\n\tonGenerationEnded(listener: InteractiveEngineGenerationEndedListener): () => void {\n\t\tthis.generationEndedListeners.push(listener);\n\t\tconst retained = this.retainedGenerationEnd;\n\t\t// Only while it still describes the live generation: once stop()/start()\n\t\t// has moved on, that death belongs to a replaced child.\n\t\tif (retained && retained.generation === this.generation) listener(retained);\n\t\treturn () => {\n\t\t\tconst index = this.generationEndedListeners.indexOf(listener);\n\t\t\tif (index !== -1) this.generationEndedListeners.splice(index, 1);\n\t\t};\n\t}\n\n\tsendInteractiveEngineCommand(command: InteractiveEngineCommand): void {\n\t\tconst writer = this.stdinWriter;\n\t\tif (command.type === \"engine_project_trust_start\" || command.type === \"engine_project_trust_end\") {\n\t\t\tif (this.generation <= this.lastEndedGeneration) return;\n\t\t\t// The terminal can open and close /trust while the engine is still binding.\n\t\t\t// Retain both frames, without delaying the host-owned decision.\n\t\t\tif (this.engineMonitor && this.boundGeneration !== this.generation) {\n\t\t\t\tthis.pendingProjectTrustFrames.push(this.generation, serializeInteractiveEngineFrame(command));\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tif (!writer) return;\n\t\tconst frame = serializeInteractiveEngineFrame(command);\n\t\tif (\n\t\t\tcommand.type === \"engine_custom_render\" ||\n\t\t\tcommand.type === \"engine_tool_render\" ||\n\t\t\tcommand.type === \"engine_message_render\"\n\t\t) {\n\t\t\twriter.offerLatest(`render:${command.componentId}`, frame);\n\t\t\treturn;\n\t\t}\n\t\t// Disposal goes through the ordered queue, ahead of coalesced renders: a render still waiting for a row\n\t\t// being disposed would reach the engine after its disposal and bring its renderer back.\n\t\tif (command.type === \"engine_render_dispose\" || command.type === \"engine_custom_dispose\")\n\t\t\twriter.discardLatest(`render:${command.componentId}`);\n\t\tthis.bestEffort(writer.write(frame), `engine command ${command.type}`);\n\t}\n\twaitForInteractiveEngineBound(): Promise<void> {\n\t\treturn this.engineMonitor?.waitUntilBound() ?? Promise.resolve();\n\t}\n\twaitForInteractiveEngineProjectTrust(): Promise<void> {\n\t\treturn this.engineMonitor?.waitUntilProjectTrustSettled() ?? Promise.resolve();\n\t}\n\twaitForInteractiveEngineResources(): Promise<void> {\n\t\treturn this.engineMonitor?.waitUntilResourcesReady() ?? Promise.resolve();\n\t}\n\tgetEnginePid(): number | undefined {\n\t\treturn this.enginePid;\n\t}\n\tgetGeneration(): number {\n\t\treturn this.generation;\n\t}\n\n\t/**\n\t * Replace the engine child, unless an explicit stop supersedes this attempt.\n\t * The permit is checked immediately before spawning, so a `stop()` in that\n\t * window is always observed; cancellation throws rather than returning\n\t * quietly, because callers go on to initialize against the new child.\n\t */\n\tasync restart(sessionId: string | undefined, options?: { sessionDirectory?: string; cwd?: string }): Promise<void> {\n\t\tconst permit = this.restartRevision;\n\t\tawait this.stopCurrentGeneration();\n\t\t// Join an in-flight stop before the permit check: waiting after it would\n\t\t// reopen the window this fence exists to close.\n\t\tif (this.stopPromise) await this.stopPromise;\n\t\tif (permit !== this.restartRevision) throw rpcTransportError(RESTART_CANCELLED_MESSAGE);\n\t\tthis.options = {\n\t\t\t...this.options,\n\t\t\tcwd: options?.cwd ?? this.options.cwd,\n\t\t\targs: restartCliArgs(this.options.args, sessionId, options?.sessionDirectory),\n\t\t};\n\t\tawait this.start();\n\t\tawait this.waitForInteractiveEngineBound();\n\t}\n\n\tasync requestInternal<T>(command: RpcCommandBody): Promise<T> {\n\t\treturn this.data<T>(await this.request(command));\n\t}\n\tuserBashWithUpdates(\n\t\tcommand: string,\n\t\tonUpdate: (delta: string, channel: BashOutputChannel) => void,\n\t\toptions?: { excludeFromContext?: boolean; onRequestId?: (id: string) => void },\n\t): Promise<BashResult> {\n\t\treturn runUserBashWithUpdates(this, command, onUpdate, options, (body, onId) => this.request(body, onId));\n\t}\n\tgetStderr(): string {\n\t\treturn this.stderr;\n\t}\n\n\twaitForIdle(timeout = 60000): Promise<void> {\n\t\treturn waitForRpcIdle(this, timeout);\n\t}\n\tcollectEvents(timeout = 60000): Promise<RpcEvent[]> {\n\t\treturn collectRpcEvents(this, timeout);\n\t}\n\tasync promptAndWait(message: string, images?: ImageContent[], timeout = 60000): Promise<RpcEvent[]> {\n\t\tconst eventsPromise = this.collectEvents(timeout);\n\t\tconst accepted = this.prompt(message, images);\n\t\t// A prompt has no request deadline, so `timeout` must also end the wait while\n\t\t// the prompt is still unacknowledged. Whichever settles first decides; both are\n\t\t// observed so the loser's later rejection is never an unhandled rejection.\n\t\teventsPromise.catch(() => {});\n\t\taccepted.catch(() => {});\n\t\tawait Promise.race([accepted, eventsPromise]);\n\t\treturn eventsPromise;\n\t}\n\tprivate handleLine(line: string, generation: number): void {\n\t\tif (this.terminalDrain.observe(generation, line, (id) => this.pendingRequests.markAccepted(id))) return;\n\t\tif (this.engineMonitor?.handleLine(line)) return;\n\t\ttry {\n\t\t\tconst data = JSON.parse(line) as { type?: string; id?: string };\n\t\t\tif (data.type === \"extension_ui_request\") {\n\t\t\t\tconst request = data as RpcExtensionUIRequest;\n\t\t\t\tif (this.extensionUIListeners.length === 0) this.pendingExtensionUIRequests.push(generation, request);\n\t\t\t\tfor (const listener of this.extensionUIListeners) listener(request);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (data.type === \"response\" && data.id && this.pendingRequests.resolve(data.id, data as RpcResponse)) return;\n\t\t\tconst event = data as RpcEvent;\n\t\t\tif (this.eventBuffer) this.eventBuffer.enqueue(event);\n\t\t\telse this.emitEvent(event);\n\t\t} catch {\n\t\t\tif (this.engineMonitor) this.failTransport(rpcTransportError(\"Interactive engine emitted malformed JSONL\"));\n\t\t}\n\t}\n\tprivate emitEvent(event: RpcEvent): void {\n\t\t// Iterate a snapshot so listeners that unsubscribe during dispatch do not make later listeners miss this event.\n\t\tfor (const listener of [...this.eventListeners]) listener(event);\n\t}\n\tprivate emitInteractiveEngineMessage(message: InteractiveEngineMessage, generation: number): void {\n\t\tif (\n\t\t\tthis.engineMessageListeners.length === 0 &&\n\t\t\t(message.type.startsWith(\"engine_custom_\") || message.type.startsWith(\"engine_resources_\"))\n\t\t) {\n\t\t\tthis.pendingEngineMessages.push(generation, message);\n\t\t}\n\t\tfor (const listener of this.engineMessageListeners) listener(message);\n\t}\n\tprivate createProcessExitError(code: number | null, signal: NodeJS.Signals | null): Error {\n\t\treturn rpcTransportError(`Agent process exited (code=${code} signal=${signal}). Stderr: ${this.stderr}`);\n\t}\n\tprivate invalidateEngineShortcuts(): void {\n\t\tif (!this.latestEngineKeybindingState || this.latestEngineKeybindingState.shortcuts.length === 0) return;\n\t\tconst state: EngineKeybindingState = { ...this.latestEngineKeybindingState, shortcuts: [] };\n\t\tthis.latestEngineKeybindingState = state;\n\t\tthis.emitInteractiveEngineMessage({ type: \"engine_keybindings_reloaded\", state }, this.generation);\n\t}\n\tprivate observeInteractiveEngineMessage(message: InteractiveEngineMessage, generation: number): void {\n\t\t// Ownership is the one thing a dead generation may still report: request\n\t\t// ids never repeat, and the alternative is classifying work it already\n\t\t// started as never sent. Nothing else from it may touch host state — a\n\t\t// stale frame would revive a PID, an activity, or a mount that is gone.\n\t\tif (message.type === \"engine_request_accepted\") {\n\t\t\tif (generation === this.generation) this.pendingRequests.markAccepted(message.requestId);\n\t\t\treturn;\n\t\t}\n\t\tif (message.type === \"engine_explicit_quit_ack\") {\n\t\t\tif (this.explicitQuitAck?.generation === generation) this.explicitQuitAck.acknowledge();\n\t\t\treturn;\n\t\t}\n\t\tif (generation !== this.generation || generation <= this.lastEndedGeneration) return;\n\t\tif (message.type === \"engine_heartbeat\") this.options.interactiveEngine?.onHeartbeat?.();\n\t\tif (message.type === \"engine_ready\") this.enginePid = message.pid;\n\t\tif (message.type === \"engine_bound\") {\n\t\t\tthis.boundGeneration = generation;\n\t\t\tfor (const frame of this.pendingProjectTrustFrames.drain(generation)) {\n\t\t\t\tif (this.stdinWriter) this.bestEffort(this.stdinWriter.write(frame), \"project trust notification\");\n\t\t\t}\n\t\t}\n\t\tif (message.type === \"engine_keybindings_reloaded\") this.latestEngineKeybindingState = message.state;\n\t\tif (message.type === \"engine_workflow_activity\") this.workflowActivity.apply(message.frame);\n\t\tif (message.type === \"engine_activity_started\") this.activeActivityIds.add(message.activity.id);\n\t\telse if (message.type === \"engine_activity_finished\") this.activeActivityIds.delete(message.activityId);\n\t\tthis.options.interactiveEngine?.onActivityChange?.(this.activeActivityIds.size > 0);\n\t\tthis.emitInteractiveEngineMessage(message, generation);\n\t}\n\t/**\n\t * Shared teardown for every unexpected end of `generation`. Death publishes\n\t * at once for the host UI; its requests wait for stdout (RpcTerminalDrain).\n\t */\n\tprivate failGeneration(rawError: Error, generation: number, kind: InteractiveEngineGenerationEndKind): void {\n\t\tif (generation !== this.generation) return;\n\t\tconst error = markRpcTransportFailure(rawError);\n\t\tthis.exitError = error;\n\t\tthis.stdinWriter?.close(error);\n\t\tthis.engineMonitor?.fail(error);\n\t\tif (kind === \"exit\") {\n\t\t\tthis.activeActivityIds.clear();\n\t\t\tthis.options.interactiveEngine?.onActivityChange?.(false);\n\t\t}\n\t\tthis.beginTerminalDrain(generation, error);\n\t\tthis.publishGenerationEnded(generation, error, kind, false);\n\t}\n\t/** Hold this generation's requests until its stdout drains (RpcTerminalDrain). */\n\tprivate beginTerminalDrain(generation: number, error: Error): Promise<void> {\n\t\treturn this.terminalDrain.begin(generation, this.stdoutDrained, error, (settled) => {\n\t\t\tif (generation === this.generation) this.pendingRequests.rejectAll(settled);\n\t\t});\n\t}\n\tprivate publishGenerationEnded(\n\t\tgeneration: number,\n\t\terror: Error,\n\t\tkind: InteractiveEngineGenerationEndKind,\n\t\texpected: boolean,\n\t): void {\n\t\tif (generation <= this.lastEndedGeneration) return;\n\t\tthis.lastEndedGeneration = generation;\n\t\tconst event: InteractiveEngineGenerationEnded = { generation, error, kind, expected };\n\t\tthis.retainedGenerationEnd = event;\n\t\t// Death is a strict boundary: drop this generation's buffered frames\n\t\t// BEFORE teardown runs, so no listener can drain a stale mount frame\n\t\t// while it is closing that very generation's components.\n\t\tthis.pendingEngineMessages.dropGeneration(generation);\n\t\tthis.workflowActivity.reset();\n\t\tthis.pendingExtensionUIRequests.dropGeneration(generation);\n\t\tthis.pendingProjectTrustFrames.dropGeneration(generation);\n\t\tfor (const listener of [...this.generationEndedListeners]) listener(event);\n\t}\n\tprivate failTransport(rawError: Error): void {\n\t\tthis.options.interactiveEngine?.onDiagnostic({\n\t\t\tactivity: undefined,\n\t\t\telapsedMs: 0,\n\t\t\tlevel: \"unresponsive\",\n\t\t\tmessage: rawError.message,\n\t\t});\n\t\tthis.failGeneration(rawError, this.generation, \"transport-error\");\n\t}\n\tprivate requireWriter(): QueuedWriter {\n\t\tif (!this.stdinWriter) throw rpcTransportError(\"Agent process stdin is not writable\");\n\t\treturn this.stdinWriter;\n\t}\n\tprivate bestEffort(operation: Promise<void>, label: string): void {\n\t\tvoid operation.catch((error: Error) => {\n\t\t\tif (!this.process || this.exitError) return;\n\t\t\tthis.options.interactiveEngine?.onDiagnostic({\n\t\t\t\tactivity: undefined,\n\t\t\t\telapsedMs: 0,\n\t\t\t\tlevel: \"unresponsive\",\n\t\t\t\tmessage: `Interactive engine ${label} failed: ${error.message}`,\n\t\t\t});\n\t\t});\n\t}\n\tprotected async request(command: RpcCommandBody, onRequestId?: (id: string) => void): Promise<RpcResponse> {\n\t\tconst childProcess = this.process;\n\t\tif (!childProcess) throw rpcTransportError(\"Client not started\");\n\t\tif (this.exitError) throw this.exitError;\n\t\tif (childProcess.exitCode !== null) {\n\t\t\tconst error = this.createProcessExitError(childProcess.exitCode, childProcess.signalCode);\n\t\t\tthis.exitError = error;\n\t\t\tthrow error;\n\t\t}\n\t\tconst id = `req_${++this.requestId}`;\n\t\tonRequestId?.(id);\n\t\tconst fullCommand = { ...command, id } as RpcCommand;\n\t\tlet timeout: ReturnType<typeof setTimeout> | undefined;\n\t\tlet rejectResponse!: (error: Error) => void;\n\t\tconst response = new Promise<RpcResponse>((resolve, reject) => {\n\t\t\trejectResponse = reject;\n\t\t\tthis.pendingRequests.add(id, {\n\t\t\t\tresolve: (value) => {\n\t\t\t\t\tif (timeout) clearTimeout(timeout);\n\t\t\t\t\tresolve(value);\n\t\t\t\t},\n\t\t\t\treject: (error) => {\n\t\t\t\t\tif (timeout) clearTimeout(timeout);\n\t\t\t\t\treject(error);\n\t\t\t\t},\n\t\t\t});\n\t\t});\n\t\ttry {\n\t\t\tawait this.requireWriter().write(serializeJsonLine(fullCommand));\n\t\t} catch (error) {\n\t\t\tthis.pendingRequests.delete(id);\n\t\t\t// Idempotent: the writer already classified this, but a caller-supplied\n\t\t\t// stream can reject with anything, and a send that never left the host\n\t\t\t// is a transport failure whatever it threw.\n\t\t\trejectResponse(markRpcTransportFailure(error));\n\t\t\treturn response;\n\t\t}\n\t\tif (this.pendingRequests.has(id) && !LONG_LIVED_COMMANDS.has(command.type)) {\n\t\t\ttimeout = setTimeout(() => {\n\t\t\t\tthis.pendingRequests.delete(id);\n\t\t\t\trejectResponse(new Error(`Timeout waiting for response to ${command.type}. Stderr: ${this.stderr}`));\n\t\t\t}, this.options.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS);\n\t\t}\n\t\treturn response;\n\t}\n\tprivate assertSuccess(response: RpcResponse): void {\n\t\tif (response.success) return;\n\t\tif (response.errorCode === \"credential_synchronization\" && response.errorDetails) {\n\t\t\tthrow new CredentialSynchronizationError(\n\t\t\t\tresponse.errorDetails.providerId,\n\t\t\t\tresponse.errorDetails.operation,\n\t\t\t\tundefined,\n\t\t\t\t{ cause: new Error(response.error) },\n\t\t\t);\n\t\t}\n\t\tthrow new Error(response.error);\n\t}\n\tprotected data<T>(response: RpcResponse): T {\n\t\tthis.assertSuccess(response);\n\t\tconst successResponse = response as Extract<RpcResponse, { success: true; data: unknown }>;\n\t\treturn successResponse.data as T;\n\t}\n}\n"]}
@@ -176,6 +176,6 @@ Config validation is strict: every field is checked, and if the file is not vali
176
176
 
177
177
  Intercom publishes live session status automatically: sessions register as `idle`, switch to `thinking` while the agent is running, show `tool:<name>` during tool execution, and return to `idle` on completion. A configured `status` is appended as context instead of replacing the lifecycle status.
178
178
 
179
- Activity is not reply capability. Session rows include `replyCapability: live` or `terminal` when the host supplies it; terminal noninteractive children cannot answer asks even if activity says `idle`. Closed workflow generations show `closed · reply: post-mortem only` when a late-message router is present, or `closed · reply: unavailable` without one. Post-mortem routing still validates the retained conversation and can return a bounded error if it is unavailable; it never resumes workflow execution. Missing capability metadata is not a guarantee that an ask can succeed. A workflow stage released from memory when its run ended keeps a listing with the same status for as long as the session that ran the workflow is open; an ask to it reopens the saved conversation for one turn and returns that turn's final answer, and a plain send reaches the session that ran the workflow. Invocation/subgroup visibility and stale-ID rejection are unchanged.
179
+ Activity is not reply capability. Session rows include `replyCapability: live` or `terminal` when the host supplies it; terminal noninteractive children cannot answer asks even if activity says `idle`. Closed workflow generations show `closed · reply: post-mortem only` when a late-message router is present, or `closed · reply: unavailable` without one. Post-mortem routing still validates the retained conversation and can return a bounded error if it is unavailable; it never resumes workflow execution. Missing capability metadata is not a guarantee that an ask can succeed. A completed workflow stage released from memory keeps a listing with the same status for as long as the session that ran the workflow is open; an ask to it reopens the saved conversation for one turn and returns that turn's final answer, and a plain send reaches the session that ran the workflow. Invocation/subgroup visibility and stale-ID rejection are unchanged.
180
180
 
181
181
  For a retained post-mortem conversation, use its exact Intercom session ID or the previously listed canonical stage path, including its final-stage-name variant. Alternate materialized run-ID paths resolve active stages through the workflow owner; they are not retained aliases after the stage completes. A stage marked `reply: unavailable` rejects an ask with guidance to contact a live stage or start new work with explicit context.
@@ -5,7 +5,7 @@ description: "Primary-source benchmark facts used by Atomic automatic model rout
5
5
 
6
6
  # Evals
7
7
 
8
- Last Accessed: 2026-10-26 (GPT-6.1 Terra additions; earlier rows retain their snapshot dates below).
8
+ Last Accessed: 2026-11-02 (Gemini 4 Argon additions; earlier rows retain their snapshot dates below).
9
9
 
10
10
  Key:
11
11
 
@@ -46,16 +46,18 @@ Key:
46
46
 
47
47
  ## Artificial Analysis Intelligence Index v4.3.2
48
48
 
49
- Table: the 673 models on the Artificial Analysis leaderboard as of 2026-09-25, including models with no published scores, plus 5 Claude Sonnet 5.5 rows accessed 2026-09-28, 5 GPT-6.1 Sol rows accessed 2026-09-29, 5 Claude Haiku 5.5 rows accessed 2026-10-07, and 6 GPT-6.1 Terra rows accessed 2026-10-26.
49
+ Table: the 673 models on the Artificial Analysis leaderboard as of 2026-09-25, including models with no published scores, plus 5 Claude Sonnet 5.5 rows accessed 2026-09-28, 5 GPT-6.1 Sol rows accessed 2026-09-29, 5 Claude Haiku 5.5 rows accessed 2026-10-07, 6 GPT-6.1 Terra rows accessed 2026-10-26, and 1 Gemini 4 Argon row accessed 2026-11-02.
50
50
 
51
51
  Sources and access dates for later additions. Release dates are not evaluation run dates; AA does not publish run dates. These are AA measurements, not vendor launch-table results. AA's [methodology](https://artificialanalysis.ai/methodology/intelligence-benchmarking) uses mini-swe-agent for TB4, all 66 tasks, pass@1 averaged over three repeats, a 500-step cap and no context compaction.
52
52
 
53
53
  - GPT-6.1 Sol: five effort rows accessed 2026-09-29 from the [leaderboard](https://artificialanalysis.ai/leaderboards/models) and [model page](https://artificialanalysis.ai/models/gpt-6-1-sol).
54
54
  - Claude Haiku 5.5: rows accessed 2026-10-07 from the [leaderboard](https://artificialanalysis.ai/leaderboards/models) and the [max](https://artificialanalysis.ai/models/claude-haiku-5-5), [xhigh](https://artificialanalysis.ai/models/claude-haiku-5-5-xhigh), [high](https://artificialanalysis.ai/models/claude-haiku-5-5-high), [medium](https://artificialanalysis.ai/models/claude-haiku-5-5-medium), and [low](https://artificialanalysis.ai/models/claude-haiku-5-5-low) model pages. AA labels these configurations "with fallback". All five pages publish non-estimated indices and twelve component measurements in their public structured data, although their text rendering says "Not publicly available". Missing `ONH` remains unknown; the published hallucination rate is a different metric.
55
55
  - GPT-6.1 Terra: six rows accessed 2026-10-26 from the [leaderboard](https://artificialanalysis.ai/leaderboards/models) and the [max](https://artificialanalysis.ai/models/gpt-6-1-terra), [xhigh](https://artificialanalysis.ai/models/gpt-6-1-terra-xhigh), [high](https://artificialanalysis.ai/models/gpt-6-1-terra-high), [medium](https://artificialanalysis.ai/models/gpt-6-1-terra-medium), [low](https://artificialanalysis.ai/models/gpt-6-1-terra-low), and [non-reasoning](https://artificialanalysis.ai/models/gpt-6-1-terra-non-reasoning) model pages. All six publish non-estimated indices in their public structured data. Columns AA does not publish for Terra remain `∅`.
56
+ - Gemini 4 Argon: `high`, the only configuration AA publishes, accessed 2026-11-02 from the [model page](https://artificialanalysis.ai/models/gemini-4-argon). AA now publishes `idx`, `OA`, `Omni`, `Harvey` and `MLCR` only on revised versions (Intelligence Index v5.0, Omniscience v1.1), so they stay `∅`. SciCode is under AA review.
56
57
 
57
58
  | slug | Model | Release date | idx | Brief | Gn | Auto | TB4 | Sci | HLE | PDF | Crit | OA | ONH | LCR | Omni | GPQA | TB21 | TBh | IF | MMMU | tau2 | tauB | Analyst | ITB | Apex | AIME | LCB | Harvey | MLCR | Open | Ent |
58
59
  | --- | --- | --- | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: |
60
+ | gemini-4-argon | Gemini 4 Argon (high) | 2026-09-30 | ∅ | 49.2 | 56.5 | 77.5 | 57.1 | 61.8 | 57.1 | 21.8 | 27.1 | ∅ | ∅ | 79.7 | ∅ | ∅ | ∅ | ∅ | ∅ | ∅ | ∅ | ∅ | 48.8 | ∅ | ∅ | ∅ | ∅ | ∅ | ∅ | ∅ | ∅ |
59
61
  | gpt-6-1-terra | GPT-6.1 Terra (max) | 2026-10-26 | 48.1 | 45.1 | 48.8 | 60.2 | 55.6 | 55.1 | 46.2 | 28.6 | 28.0 | 49.1 | 62.0 | 82.7 | 29.8 | ∅ | ∅ | ∅ | ∅ | 84.7 | ∅ | ∅ | ∅ | ∅ | ∅ | ∅ | ∅ | ∅ | ∅ | ∅ | ∅ |
60
62
  | gpt-6-1-terra-xhigh | GPT-6.1 Terra (xhigh) | 2026-10-26 | 45.4 | 41.6 | 45.8 | 59.9 | 46.5 | 53.4 | 43.7 | 26.6 | 26.6 | 49.6 | 58.5 | 81.7 | 28.7 | ∅ | ∅ | ∅ | ∅ | 83.8 | ∅ | ∅ | ∅ | ∅ | ∅ | ∅ | ∅ | ∅ | ∅ | ∅ | ∅ |
61
63
  | gpt-6-1-terra-high | GPT-6.1 Terra (high) | 2026-10-26 | 43.9 | 38.2 | 42.7 | 58.5 | 41.9 | 51.6 | 43.3 | 28.0 | 25.7 | 50.0 | 56.9 | 82.3 | 28.4 | ∅ | ∅ | ∅ | ∅ | 83.8 | ∅ | ∅ | ∅ | ∅ | ∅ | ∅ | ∅ | ∅ | ∅ | ∅ | ∅ |
@@ -797,6 +799,8 @@ GPT-6.1 Sol was added 2026-09-29 and accessed that day in the [primary JSON](htt
797
799
 
798
800
  Claude Haiku 5.5 was added and accessed 2026-10-07 in the [primary JSON](https://cognition.com/data/frontiercode-leaderboard/data.json). Its best score on both sets is max effort under the Claude Code harness; the run date is unpublished. No unfair-internet-use flag rate is recorded here. Mean cost per Main rollout is $1.33.
799
801
 
802
+ Gemini 4 Argon was added and accessed 2026-11-02 in the same JSON (low, medium and high under `devin-cli`). Medium is best on Main; low edges it on Extended (60.6). Run date unpublished.
803
+
800
804
  Key:
801
805
 
802
806
  - FrontierCode: mergeability of agent-written pull requests on tasks built by open-source maintainers, graded by rubrics, unit tests and other verifiers for correctness, test quality, scope discipline, style and codebase conventions. Runs that consult solution-bearing sources such as the original pull request score zero.
@@ -817,6 +821,7 @@ Key:
817
821
  | gpt-6-sol | GPT-6 Sol | max | 49.3 | 54.3 | 60.7 | 66.3 | 0.0 | $2.07 |
818
822
  | grok-4-6 | Grok 4.6 | high | 48.0 | 53.1 | 61.3 | 67.0 | 0.7 | $2.88 |
819
823
  | grok-4-7 | Grok 4.7 | high | 47.6 | 53.1 | 59.4 | 65.2 | 1.3 | $6.65 |
824
+ | gemini-4-argon | Gemini 4 Argon | medium | 47.6 | 52.8 | 60.5 | 66.1 | 1.2 | $6.74 |
820
825
  | gpt-5-6-sol | GPT-5.6 Sol | max | 47.5 | 52.9 | 60.6 | 66.6 | 0.0 | $5.19 |
821
826
  | claude-opus-4-8 | Opus 4.8 | max | 46.5 | 51.6 | 59.6 | 65.5 | 0.6 | $9.62 |
822
827
  | claude-haiku-5-5 | Haiku 5.5 | max | 46.4 | 51.7 | 58.4 | 64.7 | ∅ | $1.33 |
@@ -861,6 +866,7 @@ Sources and access dates:
861
866
  - GPT-6.1 Sol, accessed 2026-09-29: OpenAI = [Sol 6.1 announcement](https://openai.com/index/introducing-gpt-6-1-sol/) and [system card](https://deploymentsafety.openai.com/gpt-6-1-sol); Artificial Analysis = [Sol 6.1 model page](https://artificialanalysis.ai/models/gpt-6-1-sol) and [methodology](https://artificialanalysis.ai/methodology/intelligence-benchmarking). OpenAI's external benchmark results are vendor-reported, not benchmark-owner leaderboard rows. They ran in its research environment or API; individual harness revisions and run dates are not stated. AA's TBSci result is independent evidence from its own harness. No matching Sol 6.1 row was retrieved from the DeepSWE, TB-Science, Zapier, Surge GDP.pdf, OSWorld or ARC Prize owner leaderboards on that date.
862
867
  - Claude Haiku 5.5, accessed 2026-10-07: Anthropic = [launch announcement](https://www.anthropic.com/claude-haiku-5-5), published that day. These launch-table results are vendor-reported; effort, harness revisions, and evaluation run dates are not stated unless shown in the setting. GDPval-AA and AA-Briefcase are raw Elo, not the normalized AA columns above. Artificial Analysis independently measures Haiku 5.5 Terminal-Bench-Science in its **with-fallback** configuration, from the effort-specific model pages for [max](https://artificialanalysis.ai/models/claude-haiku-5-5), [xhigh](https://artificialanalysis.ai/models/claude-haiku-5-5-xhigh), [high](https://artificialanalysis.ai/models/claude-haiku-5-5-high), [medium](https://artificialanalysis.ai/models/claude-haiku-5-5-medium), and [low](https://artificialanalysis.ai/models/claude-haiku-5-5-low); these are not Anthropic launch-table results. No Haiku 5.5 result was published on the checked [DeepSWE leaderboard](https://deepswe.datacurve.ai/) on 2026-10-07; no row is added to that table.
863
868
  - GPT-6.1 Terra, accessed 2026-10-26: OpenAI = [launch announcement](https://openai.com/index/introducing-gpt-6-1-terra/) and [system card addendum](https://deploymentsafety.openai.com/gpt-6-1-terra). These results are vendor-reported; harness revisions and run dates are not stated. The announcement text states one numeric Terra score on an external benchmark, TB4 at max effort; its Agents' Last Exam, MMMU-Pro, OSWorld 2.1 and Terminal-Bench-Science comparisons state no Terra score and are not transcribed. The system card reports cybersecurity results at the maximum tested solution length without naming an effort; its internal evaluations are excluded. Artificial Analysis independently measures Terminal-Bench-Science for the six configurations whose model pages are listed in the Intelligence Index section above. No GPT-6.1 Terra result was published on the [DeepSWE leaderboard](https://deepswe.datacurve.ai/), the [TB-Science leaderboard](https://www.terminal-bench-science.ai/), the [FrontierCode data](https://cognition.com/data/frontiercode-leaderboard/data.json), or the visible [AutomationBench leaderboard](https://zapier.com/benchmarks) on that date; no row is added to those tables.
869
+ - Gemini 4 Argon, accessed 2026-11-02: Google = [model card](https://deepmind.google/models/model-cards/gemini-4-argon/) and [methodology](https://deepmind.google/models/evals-methodology/gemini-4-argon), vendor-reported at the highest thinking setting, pass@1; "from X" rows are Google's attribution, not separately retrieved. Zapier = [AutomationBench](https://zapier.com/benchmarks). The [DeepSWE leaderboard](https://deepswe.datacurve.ai/) had no Argon row.
864
870
 
865
871
  Artificial Analysis Terminal-Bench-Science rows use the [evaluation page](https://artificialanalysis.ai/evaluations/terminal-bench-science) and [AA's general methodology](https://artificialanalysis.ai/methodology/intelligence-benchmarking): version 0.1.0, 70 tasks, mini-swe-agent, pass@1 averaged over three repeats, and a 1,000-step cap. These are AA's general settings, not a separately documented model-specific harness revision. Evaluation run dates are unpublished.
866
872
 
@@ -874,6 +880,7 @@ Key:
874
880
  - `OSW21`: OSWorld 2.1, computer-use workflows; the Haiku result covers the offline subset.
875
881
  - `FC11`: FrontierCode 1.1 Main, weighted rubric score; distinct from all-blocking-criteria pass rate.
876
882
  - `Chart`: Chartography, chart understanding without tools.
883
+ - `VALS`: Vals Index. `VFA`: Vals Finance Agent v2. `HLAB`: Harvey's Legal Agent Benchmark. `FSWE`: FrontierSWE v2. `VCB`: Vibe Code Bench. `PTB`: PostTrainBench v1.1. `CWE`: CWE-bench v1. `LAB2`: LABBench 2. `RBench`: RiemannBench. `GW128`, `GW1M`: GraphWalks BFS F1, up to 128k and 256k to 1M tokens. `LVB`: LVBench.
877
884
 
878
885
  - `ALE`: [Agents' Last Exam](https://agents-last-exam.org/), long-horizon professional tasks in real software, from financial modeling to engineering and media production.
879
886
  - `OSW2`, `OSW2s`: [OSWorld 2.0](https://osworld-v2.xlang.ai/), long-horizon computer-use workflows operating desktop applications through the screen; partial credit and strict all-pass scoring.
@@ -892,6 +899,27 @@ Key:
892
899
 
893
900
  | slug | Model | Benchmark | Score | Setting | Source |
894
901
  | --- | --- | --- | ---: | --- | --- |
902
+ | gemini-4-argon | Gemini 4 Argon | DSWE | 77.9 | v1.1, mini-swe-agent; Google-reported, self-computed | Google |
903
+ | gemini-4-argon | Gemini 4 Argon | FSWE | 55.0 | v2; Google-reported, from Proximal's leaderboard | Google |
904
+ | gemini-4-argon | Gemini 4 Argon | TB4 | 57.4 | v4.0; Google-reported, self-computed | Google |
905
+ | gemini-4-argon | Gemini 4 Argon | TBSci | 57.6 | v0.1, 6x verifier timeout; Google-reported, self-computed | Google |
906
+ | gemini-4-argon | Gemini 4 Argon | TBSci | 52.9 | high effort; AA general settings above | Artificial Analysis |
907
+ | gemini-4-argon | Gemini 4 Argon | VCB | 91.9 | Google-reported, from Vals AI's leaderboard | Google |
908
+ | gemini-4-argon | Gemini 4 Argon | ABench | 51.3 | v1.0.6, private set, high effort | Zapier |
909
+ | gemini-4-argon-medium | Gemini 4 Argon | ABench | 50.1 | v1.0.6, private set, medium effort | Zapier |
910
+ | gemini-4-argon | Gemini 4 Argon | PTB | 45.3 | v1.1, OpenCode harness, 10 hours on one H100; Google-reported, self-computed | Google |
911
+ | gemini-4-argon | Gemini 4 Argon | VALS | 68.9 | Google-reported, from Vals AI | Google |
912
+ | gemini-4-argon | Gemini 4 Argon | VFA | 65.4 | Google-reported, from Vals AI | Google |
913
+ | gemini-4-argon | Gemini 4 Argon | HLAB | 19.6 | Google-reported, from Vals AI | Google |
914
+ | gemini-4-argon | Gemini 4 Argon | ALE | 39.5 | ALE-Claw harness, 5-hour window, binary pass rate; Google-reported, self-computed | Google |
915
+ | gemini-4-argon | Gemini 4 Argon | OSW2 | 69.2 | offline subset, partial, best of 3 runs, Gemini CUA harness with batch tool calls and compaction, 08.08 patch; Google-reported, self-computed | Google |
916
+ | gemini-4-argon | Gemini 4 Argon | LAB2 | 88.8 | terminal with bioinformatics tools, Python, R and internet; Google-reported, self-computed | Google |
917
+ | gemini-4-argon | Gemini 4 Argon | RBench | 76.0 | Google-reported, from Surge's leaderboard | Google |
918
+ | gemini-4-argon | Gemini 4 Argon | GW128 | 99.7 | BFS F1, 650 items up to 128k; Google-reported, self-computed | Google |
919
+ | gemini-4-argon | Gemini 4 Argon | GW1M | 84.2 | BFS F1, 200 problems at 256k to 1M; Google-reported, self-computed | Google |
920
+ | gemini-4-argon | Gemini 4 Argon | Chart | 71.6 | no tools; Google-reported, from Surge's leaderboard | Google |
921
+ | gemini-4-argon | Gemini 4 Argon | LVB | 91.7 | no tools, 1 FPS; Google-reported, self-computed | Google |
922
+ | gemini-4-argon | Gemini 4 Argon | CWE | 68.0 | v1, pass@1; Google-reported, from the public leaderboard | Google |
895
923
  | gpt-6-1-terra | GPT-6.1 Terra | TB4 | 50.3 | max effort; v4.0; OpenAI-reported, harness not stated | OpenAI |
896
924
  | gpt-6-1-terra | GPT-6.1 Terra | XBench | 97.1 | ACE-normalized mean capability score; max tested solution length; effort not stated | OpenAI |
897
925
  | gpt-6-1-terra | GPT-6.1 Terra | SECPro | 83.3 | pass@1; max tested solution length; effort not stated | OpenAI |
package/docs/settings.md CHANGED
@@ -147,6 +147,8 @@ To audit a routing decision, the stage's `routerSelection` in `workflow({ action
147
147
 
148
148
  If `retry.enabled` is `false`, Atomic skips same-model retries and moves directly to the next fallback for retryable failures. Non-retryable task failures and cancellations do not trigger fallback.
149
149
 
150
+ A content-filter refusal, such as OpenAI's HTTP 422 `cyber_policy` ("This content was flagged for possible cybersecurity risk"), Anthropic's refusal stop, or a `content_filter` finish reason, also moves to the next fallback, without retrying the model that refused: the same request would be refused again. The refused model is recorded in the fallback history. Set `retry.fallbackOnContentFilter` to `false` to keep such a refusal on the model that gave it. Subagents and workflow stages follow the same setting for their own `fallbackModels`.
151
+
150
152
  The fallback model and its thinking level remain active for later turns in the same main-chat session. Choose another model explicitly with `/model` or model cycle to change them.
151
153
 
152
154
  Workflow stages that set their own `model` or `fallbackModels` never use this list; they advance only the chain they declare. See [`fallbackModels`](/workflows/api-reference#fallbackmodels).
@@ -340,6 +342,7 @@ Both fields must be non-negative safe integers, including ordinary settings. Inv
340
342
  | `retry.maxRetries` | number | `3` | Maximum agent-level retry attempts |
341
343
  | `retry.baseDelayMs` | number | `2000` | Base delay for agent-level exponential backoff (2s, 4s, 8s) |
342
344
  | `retry.maxAgentDelayMs` | number | `60000` | Maximum agent-level backoff delay (60s); `0` retries immediately |
345
+ | `retry.fallbackOnContentFilter` | boolean | `true` | Move to the next `fallbackModels` entry when a provider's content filter refuses a request (for example OpenAI's HTTP 422 `cyber_policy`), instead of retrying the same model. `false` retries the refusal on the same model and never falls back for it |
343
346
  | `retry.provider.timeoutMs` | number | SDK default | Provider/SDK request timeout in milliseconds |
344
347
  | `retry.provider.maxRetries` | number | `0` | Provider/SDK retry attempts. Leave unset/`0` to let Atomic's agent-level retry handle transient failures |
345
348
  | `retry.provider.maxRetryDelayMs` | number | `60000` | Max server-requested delay before failing (60s); also caps how long an agent-level retry waits for a server retry hint |
@@ -110,7 +110,9 @@ Retryable causes include rate limits, quota/usage-limit exhaustion, auth problem
110
110
 
111
111
  A request-incompatible candidate also advances the sequence. Examples include HTTP 400/413/422 bad, unprocessable, or payload-too-large requests; unsupported tools or parameters; context-length/context-window overflow; and `too large` / `invalid_request` errors. The chain can therefore reach the current user-selected model when no configured candidate can serve the request.
112
112
 
113
- Fallback does not retry safety refusals, ordinary task or tool failures, validation failures, cancellations, or workflow-code errors.
113
+ A content-filter refusal also advances the sequence, without retrying the refusing model. Examples include OpenAI's HTTP 422 `cyber_policy` ("This content was flagged for possible cybersecurity risk"), Anthropic's refusal stop, and a `content_filter` finish reason. The result's fallback list shows which model refused. Set `retry.fallbackOnContentFilter: false` in settings to keep such a refusal on the model that gave it.
114
+
115
+ Fallback does not retry refused tool calls, ordinary task or tool failures, validation failures, cancellations, or workflow-code errors.
114
116
 
115
117
  There is no per-attempt idle watchdog or child wall-clock kill cap. Quiet provider responses may finish; only explicit termination or a provider failure supplies a retryable cause.
116
118