@code-yeongyu/senpi 2026.8.30-2 → 2026.8.30-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 (88) hide show
  1. package/CHANGELOG.md +51 -1
  2. package/dist/core/agent-session.d.ts +2 -0
  3. package/dist/core/agent-session.d.ts.map +1 -1
  4. package/dist/core/agent-session.js +77 -10
  5. package/dist/core/agent-session.js.map +1 -1
  6. package/dist/core/extensions/builtin/compaction/context-pipeline.d.ts +1 -0
  7. package/dist/core/extensions/builtin/compaction/context-pipeline.d.ts.map +1 -1
  8. package/dist/core/extensions/builtin/compaction/context-pipeline.js +6 -2
  9. package/dist/core/extensions/builtin/compaction/context-pipeline.js.map +1 -1
  10. package/dist/core/extensions/builtin/compaction/deterministic-fallback.d.ts.map +1 -1
  11. package/dist/core/extensions/builtin/compaction/deterministic-fallback.js +3 -2
  12. package/dist/core/extensions/builtin/compaction/deterministic-fallback.js.map +1 -1
  13. package/dist/core/extensions/builtin/compaction/idle-retry.d.ts +1 -1
  14. package/dist/core/extensions/builtin/compaction/idle-retry.d.ts.map +1 -1
  15. package/dist/core/extensions/builtin/compaction/idle-retry.js +1 -1
  16. package/dist/core/extensions/builtin/compaction/idle-retry.js.map +1 -1
  17. package/dist/core/extensions/builtin/compaction/index.d.ts.map +1 -1
  18. package/dist/core/extensions/builtin/compaction/index.js +34 -10
  19. package/dist/core/extensions/builtin/compaction/index.js.map +1 -1
  20. package/dist/core/extensions/builtin/compaction/model-usability-budget.d.ts +30 -0
  21. package/dist/core/extensions/builtin/compaction/model-usability-budget.d.ts.map +1 -0
  22. package/dist/core/extensions/builtin/compaction/model-usability-budget.js +74 -0
  23. package/dist/core/extensions/builtin/compaction/model-usability-budget.js.map +1 -0
  24. package/dist/core/extensions/builtin/compaction/orchestration.d.ts +3 -13
  25. package/dist/core/extensions/builtin/compaction/orchestration.d.ts.map +1 -1
  26. package/dist/core/extensions/builtin/compaction/orchestration.js +50 -83
  27. package/dist/core/extensions/builtin/compaction/orchestration.js.map +1 -1
  28. package/dist/core/extensions/builtin/compaction/policy.d.ts +8 -1
  29. package/dist/core/extensions/builtin/compaction/policy.d.ts.map +1 -1
  30. package/dist/core/extensions/builtin/compaction/policy.js +12 -3
  31. package/dist/core/extensions/builtin/compaction/policy.js.map +1 -1
  32. package/dist/core/extensions/builtin/compaction/token-budget-reminder.d.ts +8 -2
  33. package/dist/core/extensions/builtin/compaction/token-budget-reminder.d.ts.map +1 -1
  34. package/dist/core/extensions/builtin/compaction/token-budget-reminder.js +12 -5
  35. package/dist/core/extensions/builtin/compaction/token-budget-reminder.js.map +1 -1
  36. package/dist/core/extensions/builtin/compaction/tool-admission.d.ts +12 -21
  37. package/dist/core/extensions/builtin/compaction/tool-admission.d.ts.map +1 -1
  38. package/dist/core/extensions/builtin/compaction/tool-admission.js +27 -63
  39. package/dist/core/extensions/builtin/compaction/tool-admission.js.map +1 -1
  40. package/dist/core/extensions/builtin/terminal/runtime-session.d.ts +11 -0
  41. package/dist/core/extensions/builtin/terminal/runtime-session.d.ts.map +1 -1
  42. package/dist/core/extensions/builtin/terminal/runtime-session.js +18 -2
  43. package/dist/core/extensions/builtin/terminal/runtime-session.js.map +1 -1
  44. package/dist/core/sdk.d.ts.map +1 -1
  45. package/dist/core/sdk.js +5 -0
  46. package/dist/core/sdk.js.map +1 -1
  47. package/dist/index.d.ts +1 -1
  48. package/dist/index.d.ts.map +1 -1
  49. package/dist/index.js +1 -1
  50. package/dist/index.js.map +1 -1
  51. package/dist/modes/index.d.ts +1 -1
  52. package/dist/modes/index.d.ts.map +1 -1
  53. package/dist/modes/index.js +1 -1
  54. package/dist/modes/index.js.map +1 -1
  55. package/dist/modes/interactive/interactive-host-runtime.d.ts +13 -2
  56. package/dist/modes/interactive/interactive-host-runtime.d.ts.map +1 -1
  57. package/dist/modes/interactive/interactive-host-runtime.js +317 -72
  58. package/dist/modes/interactive/interactive-host-runtime.js.map +1 -1
  59. package/dist/modes/rpc/connection-handler.d.ts.map +1 -1
  60. package/dist/modes/rpc/connection-handler.js +17 -4
  61. package/dist/modes/rpc/connection-handler.js.map +1 -1
  62. package/dist/modes/rpc/rpc-client.d.ts +10 -0
  63. package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
  64. package/dist/modes/rpc/rpc-client.js +32 -10
  65. package/dist/modes/rpc/rpc-client.js.map +1 -1
  66. package/docs/rpc.md +4 -0
  67. package/node_modules/@code-yeongyu/senpi-codemode/CHANGELOG.md +12 -0
  68. package/node_modules/@code-yeongyu/senpi-codemode/package.json +4 -4
  69. package/node_modules/@earendil-works/pi-agent-core/package.json +3 -3
  70. package/node_modules/@earendil-works/pi-ai/dist/providers/data/.manifest.json +1 -1
  71. package/node_modules/@earendil-works/pi-ai/dist/providers/data/openrouter.json +1 -1
  72. package/node_modules/@earendil-works/pi-ai/package.json +2 -2
  73. package/node_modules/@earendil-works/pi-pty/dist/screen-operations.d.ts +42 -0
  74. package/node_modules/@earendil-works/pi-pty/dist/screen-operations.d.ts.map +1 -0
  75. package/node_modules/@earendil-works/pi-pty/dist/screen-operations.js +34 -0
  76. package/node_modules/@earendil-works/pi-pty/dist/screen-operations.js.map +1 -0
  77. package/node_modules/@earendil-works/pi-pty/dist/screen-text.d.ts +8 -0
  78. package/node_modules/@earendil-works/pi-pty/dist/screen-text.d.ts.map +1 -0
  79. package/node_modules/@earendil-works/pi-pty/dist/screen-text.js +51 -0
  80. package/node_modules/@earendil-works/pi-pty/dist/screen-text.js.map +1 -0
  81. package/node_modules/@earendil-works/pi-pty/dist/screen.d.ts +45 -0
  82. package/node_modules/@earendil-works/pi-pty/dist/screen.d.ts.map +1 -1
  83. package/node_modules/@earendil-works/pi-pty/dist/screen.js +178 -55
  84. package/node_modules/@earendil-works/pi-pty/dist/screen.js.map +1 -1
  85. package/node_modules/@earendil-works/pi-pty/package.json +1 -1
  86. package/node_modules/@earendil-works/pi-telemetry/package.json +1 -1
  87. package/node_modules/@earendil-works/pi-tui/package.json +1 -1
  88. package/package.json +7 -7
@@ -1 +1 @@
1
- {"version":3,"file":"interactive-host-runtime.js","sourceRoot":"","sources":["../../../src/modes/interactive/interactive-host-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAKtC,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAExE,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAEjE,OAAO,EAAoB,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACrE,OAAO,EAAE,SAAS,EAAuB,MAAM,sBAAsB,CAAC;AAEtE,MAAM,CAAC,MAAM,iCAAiC,GAAG,kEAAkE,CAAC;AA2CpH;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,4BAA4B,CACjD,YAAiC,EACjC,OAAsC;IAEtC,MAAM,WAAW,GAAG,YAAY,CAAC,OAAO,CAAC,WAAW,CAAC;IACrD,IAAI,CAAC,WAAW;QAAE,OAAO,YAAY,CAAC;IACtC,MAAM,SAAS,GAAG,OAAO,CAAC,UAAU,IAAI,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC;IACnF,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC,EAAE,UAAU,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAC7D,IAAI,CAAC;QACJ,MAAM,SAAS,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;QACxE,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;QACrB,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,WAAW,CAAC;YACvC,WAAW;YACX,GAAG,EAAE,YAAY,CAAC,GAAG;Y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,CAAC,IAAI,KAAK,gBAAgB,IAAI,OAAO,EAAE,IAAI,KAAK,UAAU,EAAE,CAAC;QACtE,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC;QAC7D,IAAI,CAAC;YACJ,MAAM,MAAM,GAAY,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YACxC,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;gBAC7E,OAAO,CAAC,SAAS,GAAG,MAAiC,CAAC;YACvD,CAAC;QACF,CAAC;QAAC,MAAM,CAAC;YACR,gEAAgE;QACjE,CAAC;IACF,CAAC;IACD,kBAAkB,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;IACvC,OAAO;QACN,IAAI,EAAE,gBAAgB;QACtB,OAAO,EAAE,eAAe,CAAC,kBAAkB,CAAC;QAC5C,qBAAqB,EAAE,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,eAAe,CAAC,kBAAkB,CAAC,EAAE;KAC7D,CAAC;AACxB,CAAC;AAED,SAAS,YAAY,CAAC,KA0BrB;IACA,OAAO,KAAK,CAAC;AACd,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,KAAqB;IAC3D,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,MAAM,IAAI,KAAK,CAAC;AACvE,CAAC","sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport { rm } from \"node:fs/promises\";\nimport type { ThinkingLevel } from \"@earendil-works/pi-agent-core\";\nimport type { AgentSession, AgentSessionEvent, AgentSessionEventListener } from \"../../core/agent-session.ts\";\nimport type { AgentSessionRuntime } from \"../../core/agent-session-runtime.ts\";\nimport type { AgentSessionRuntimeDiagnostic } from \"../../core/agent-session-services.ts\";\nimport { executeBashWithOperations } from \"../../core/bash-executor.ts\";\nimport type { ProjectTrustContext, ReplacedSessionContext } from \"../../core/extensions/index.ts\";\nimport { SessionManager } from \"../../core/session-manager.ts\";\nimport { SettingsManager } from \"../../core/settings-manager.ts\";\nimport type { BashOperations } from \"../../core/tools/bash.ts\";\nimport { type EnsuredHost, ensureHost } from \"../rpc/host-ensure.ts\";\nimport { RpcClient, type RpcClientEvent } from \"../rpc/rpc-client.ts\";\n\nexport const INTERACTIVE_HOST_FALLBACK_WARNING = \"Warning: shared interactive host unavailable; continuing locally\";\n\nexport interface InteractiveHostWarning {\n\treadonly type: \"interactive_host_fallback\" | \"interactive_host_action_failed\";\n\treadonly message: string;\n\treadonly cause: unknown;\n}\n\n/**\n * The session contract InteractiveMode actually runs against. The local\n * AgentSession answers these reads synchronously; the shared-host proxy answers\n * them over RPC. Declaring the union here keeps the proxy honest (no more\n * `as unknown as` lie at the boundary) and lets the compiler find every TUI\n * call site that must await.\n */\nexport type InteractiveSession = Omit<\n\tAgentSession,\n\t\"cycleThinkingLevel\" | \"getAvailableThinkingLevels\" | \"getSessionStats\" | \"getUserMessagesForForking\"\n> & {\n\tcycleThinkingLevel(): ThinkingLevel | undefined | Promise<ThinkingLevel | undefined>;\n\tgetAvailableThinkingLevels(): ThinkingLevel[] | Promise<ThinkingLevel[]>;\n\tgetSessionStats():\n\t\t| ReturnType<AgentSession[\"getSessionStats\"]>\n\t\t| Promise<ReturnType<AgentSession[\"getSessionStats\"]>>;\n\tgetUserMessagesForForking():\n\t\t| ReturnType<AgentSession[\"getUserMessagesForForking\"]>\n\t\t| Promise<ReturnType<AgentSession[\"getUserMessagesForForking\"]>>;\n};\n\nexport type InteractiveHostUiHandler = (\n\trequest: import(\"../rpc/rpc-types.ts\").RpcExtensionUIRequest,\n) =>\n\t| Promise<import(\"../rpc/rpc-types.ts\").RpcExtensionUIResponse | undefined>\n\t| import(\"../rpc/rpc-types.ts\").RpcExtensionUIResponse\n\t| undefined;\n\nexport interface InteractiveHostRuntimeOptions {\n\treadonly socket: string;\n\treadonly agentDir?: string;\n\treadonly ensureHost?: (options: { socket: string; agentDir?: string }) => Promise<EnsuredHost | undefined>;\n\tonWarning?: (warning: InteractiveHostWarning) => void;\n}\n\n/**\n * Replace only the transport-facing session operations. The object returned is\n * deliberately still an AgentSessionRuntime: InteractiveMode and extensions\n * retain their existing runtime seam, while the authoritative prompt/session\n * state is hosted by the shared RPC process.\n */\nexport async function createInteractiveHostRuntime(\n\tlocalRuntime: AgentSessionRuntime,\n\toptions: InteractiveHostRuntimeOptions,\n): Promise<AgentSessionRuntime> {\n\tconst sessionPath = localRuntime.session.sessionFile;\n\tif (!sessionPath) return localRuntime;\n\tconst startHost = options.ensureHost ?? ((hostOptions) => ensureHost(hostOptions));\n\tconst client = new RpcClient({ socketPath: options.socket });\n\ttry {\n\t\tawait startHost({ socket: options.socket, agentDir: options.agentDir });\n\t\tawait client.start();\n\t\tconst opened = await client.openSession({\n\t\t\tsessionPath,\n\t\t\tcwd: localRuntime.cwd,\n\t\t\tprovider: localRuntime.session.model?.provider,\n\t\t\tmodelId: localRuntime.session.model?.id,\n\t\t\tthinkingLevel: localRuntime.session.thinkingLevel,\n\t\t});\n\t\tconst remoteSession = createRemoteSessionProxy(\n\t\t\tlocalRuntime.session,\n\t\t\tlocalRuntime.services.agentDir,\n\t\t\tclient,\n\t\t\topened.state,\n\t\t\toptions.onWarning,\n\t\t);\n\t\tif (opened.state.isBashRunning && !opened.attached) {\n\t\t\t// Only a newly opened session can have an execution orphaned by a\n\t\t\t// previous connection. An attach is an observer of the same live runtime;\n\t\t\t// aborting it would cancel work owned by the surviving attachment.\n\t\t\tawait client.abortBash().catch(() => {});\n\t\t}\n\t\tif (opened.attached) await remoteSession.refresh();\n\t\treturn new RemoteInteractiveRuntime(localRuntime, remoteSession, client) as unknown as AgentSessionRuntime;\n\t} catch (cause) {\n\t\tawait client.stop().catch(() => {});\n\t\toptions.onWarning?.({\n\t\t\ttype: \"interactive_host_fallback\",\n\t\t\tmessage: `${INTERACTIVE_HOST_FALLBACK_WARNING}: ${cause instanceof Error ? cause.message : String(cause)}`,\n\t\t\tcause,\n\t\t});\n\t\treturn localRuntime;\n\t}\n}\n\nexport class RemoteInteractiveRuntime {\n\treadonly #local: AgentSessionRuntime;\n\treadonly #remoteSession: RemoteSessionProxy;\n\treadonly #client: RpcClient;\n\t#rebindSession: (() => Promise<void>) | undefined;\n\t#beforeSessionInvalidate: (() => void) | undefined;\n\n\tconstructor(local: AgentSessionRuntime, remoteSession: RemoteSessionProxy, client: RpcClient) {\n\t\tthis.#local = local;\n\t\tthis.#remoteSession = remoteSession;\n\t\tthis.#client = client;\n\t}\n\n\tget session(): AgentSession {\n\t\treturn this.#remoteSession.session;\n\t}\n\tget services(): AgentSessionRuntime[\"services\"] {\n\t\treturn this.#local.services;\n\t}\n\tget cwd(): string {\n\t\treturn this.#remoteSession.session.sessionManager.getCwd();\n\t}\n\tget diagnostics(): readonly AgentSessionRuntimeDiagnostic[] {\n\t\treturn this.#local.diagnostics;\n\t}\n\tget modelFallbackMessage(): string | undefined {\n\t\treturn this.#local.modelFallbackMessage;\n\t}\n\tget launchProfile(): AgentSessionRuntime[\"launchProfile\"] {\n\t\treturn this.#local.launchProfile;\n\t}\n\tsetBeforeSessionInvalidate(callback?: () => void): void {\n\t\tthis.#beforeSessionInvalidate = callback;\n\t}\n\tsetRebindSession(callback?: () => Promise<void>): void {\n\t\tthis.#rebindSession = callback;\n\t}\n\tsetHostUiHandler(callback?: InteractiveHostUiHandler): void {\n\t\tthis.#remoteSession.setHostUiHandler(callback);\n\t}\n\tasync dispose(): Promise<void> {\n\t\tconst errors: unknown[] = [];\n\t\tfor (const cleanup of [\n\t\t\t() => this.#remoteSession.abortLocalBash(),\n\t\t\t() => this.#client.closeSession(),\n\t\t\t() => this.#client.stop(),\n\t\t\t() => this.#local.dispose(),\n\t\t]) {\n\t\t\ttry {\n\t\t\t\tawait cleanup();\n\t\t\t} catch (error) {\n\t\t\t\terrors.push(error);\n\t\t\t}\n\t\t}\n\t\tif (errors.length > 0) throw errors[0];\n\t}\n\tasync newSession(options?: {\n\t\tparentSession?: string;\n\t\tsetup?: (sessionManager: SessionManager) => Promise<void>;\n\t\twithSession?: (ctx: ReplacedSessionContext) => Promise<void>;\n\t}): Promise<{ cancelled: boolean }> {\n\t\t// Suppresses for the ENTIRE command, not just the refresh tail: a\n\t\t// multi-session host emits session_replaced while completing it, so the echo\n\t\t// can arrive before the refresh/rebind sequence below starts and race it -\n\t\t// newSession transports setup entries between two refreshes.\n\t\treturn this.#remoteSession.aroundLocalReplacement(async () => {\n\t\t\tconst result = await this.#client.newSession(options?.parentSession);\n\t\t\tif (!result.cancelled) {\n\t\t\t\tthis.#beforeSessionInvalidate?.();\n\t\t\t\tthis.#remoteSession.abortLocalBash();\n\t\t\t\tawait this.#remoteSession.refresh();\n\t\t\t\tif (options?.setup) {\n\t\t\t\t\tconst capture = SessionManager.inMemory(this.#remoteSession.session.sessionManager.getCwd());\n\t\t\t\t\tawait options.setup(capture);\n\t\t\t\t\tfor (const entry of capture.getEntries()) await this.#client.appendSessionEntry(entry);\n\t\t\t\t\tawait this.#remoteSession.refresh();\n\t\t\t\t}\n\t\t\t\tawait this.#rebindSession?.();\n\t\t\t\tif (options?.withSession) await options.withSession(this.#remoteSession.createReplacedSessionContext());\n\t\t\t}\n\t\t\treturn result;\n\t\t});\n\t}\n\tasync switchSession(\n\t\tsessionPath: string,\n\t\toptions?: {\n\t\t\tcwdOverride?: string;\n\t\t\twithSession?: (ctx: ReplacedSessionContext) => Promise<void>;\n\t\t\tprojectTrustContextFactory?: (cwd: string) => ProjectTrustContext;\n\t\t},\n\t): Promise<{ cancelled: boolean }> {\n\t\t// See newSession: the suppression must cover the command itself, since the\n\t\t// host emits session_replaced while completing it.\n\t\treturn this.#remoteSession.aroundLocalReplacement(async () => {\n\t\t\tconst result = await this.#client.switchSession(\n\t\t\t\tsessionPath,\n\t\t\t\toptions?.cwdOverride === undefined ? undefined : { cwdOverride: options.cwdOverride },\n\t\t\t);\n\t\t\tif (!result.cancelled) {\n\t\t\t\tthis.#beforeSessionInvalidate?.();\n\t\t\t\tthis.#remoteSession.abortLocalBash();\n\t\t\t\tawait this.#remoteSession.refresh();\n\t\t\t\tawait this.#rebindSession?.();\n\t\t\t\t// The shared host already resolved trust; this callback is retained for\n\t\t\t\t// compatibility, but its result cannot override host-authoritative state.\n\t\t\t\toptions?.projectTrustContextFactory?.(this.#remoteSession.session.sessionManager.getCwd());\n\t\t\t\tif (options?.withSession) await options.withSession(this.#remoteSession.createReplacedSessionContext());\n\t\t\t}\n\t\t\treturn result;\n\t\t});\n\t}\n\tasync fork(\n\t\tentryId: string,\n\t\toptions?: { position?: \"before\" | \"at\"; withSession?: (ctx: ReplacedSessionContext) => Promise<void> },\n\t): Promise<{ cancelled: boolean; selectedText?: string }> {\n\t\t// See newSession: the suppression must cover the command itself.\n\t\treturn this.#remoteSession.aroundLocalReplacement(async () => {\n\t\t\tconst result = await this.#client.fork(entryId, options);\n\t\t\tif (!result.cancelled) {\n\t\t\t\tthis.#beforeSessionInvalidate?.();\n\t\t\t\tthis.#remoteSession.abortLocalBash();\n\t\t\t\tawait this.#refreshAndRebind();\n\t\t\t\tif (options?.withSession) await options.withSession(this.#remoteSession.createReplacedSessionContext());\n\t\t\t}\n\t\t\treturn { cancelled: result.cancelled, selectedText: result.text };\n\t\t});\n\t}\n\tasync importFromJsonl(inputPath: string, cwdOverride?: string): Promise<{ cancelled: boolean }> {\n\t\t// See newSession: the suppression must cover the command itself.\n\t\treturn this.#remoteSession.aroundLocalReplacement(async () => {\n\t\t\tconst result = await this.#client.importJsonl(inputPath, cwdOverride);\n\t\t\tif (!result.cancelled) {\n\t\t\t\tthis.#beforeSessionInvalidate?.();\n\t\t\t\tthis.#remoteSession.abortLocalBash();\n\t\t\t\tawait this.#refreshAndRebind();\n\t\t\t}\n\t\t\treturn result;\n\t\t});\n\t}\n\n\tasync #refreshAndRebind(): Promise<void> {\n\t\tawait this.#remoteSession.refresh();\n\t\tawait this.#rebindSession?.();\n\t}\n}\n\ninterface RemoteSessionProxy {\n\treadonly session: AgentSession;\n\tsetHostUiHandler(callback?: InteractiveHostUiHandler): void;\n\trefresh(): Promise<void>;\n\t/**\n\t * Run a replacement this runtime is driving itself, suppressing the refresh\n\t * that the host's broadcast `session_replaced` would otherwise trigger. The\n\t * caller owns the refresh/rebind ordering for its own replacements, so the\n\t * scope must cover the command itself, not just its refresh tail.\n\t */\n\taroundLocalReplacement<T>(body: () => Promise<T>): Promise<T>;\n\tabortLocalBash(): void;\n\tcreateReplacedSessionContext(): ReplacedSessionContext;\n}\n\n/** Exported for direct coverage of the wire-event handling below. */\nexport function createRemoteSessionProxy(\n\tlocal: AgentSession,\n\tagentDir: string,\n\tclient: RpcClient,\n\tinitialState: ReturnType<typeof stateFromRpc>,\n\tonWarning?: (warning: InteractiveHostWarning) => void,\n): RemoteSessionProxy {\n\t// Fire-and-forget setters keep the sync AgentSession signature, but their RPC\n\t// failures must not vanish: the matching *_changed wire event confirms success,\n\t// and a rejection here is the only signal of failure.\n\tconst reportActionFailure = (action: string) => (error: unknown) => {\n\t\tonWarning?.({\n\t\t\ttype: \"interactive_host_action_failed\",\n\t\t\tmessage: `Warning: shared interactive host ${action} failed: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\tcause: error,\n\t\t});\n\t};\n\tlet state = { ...initialState };\n\tconst waitForBashCallbacks = async (promises: Set<Promise<void>>, allowAbandonment: boolean): Promise<boolean> => {\n\t\tif (promises.size === 0) return true;\n\t\tconst settled = Promise.allSettled([...promises]).then(() => true);\n\t\tlet timeout: ReturnType<typeof setTimeout> | undefined;\n\t\tconst bounded = new Promise<false>((resolve) => {\n\t\t\ttimeout = setTimeout(resolve, allowAbandonment ? 100 : 5_000, false);\n\t\t\ttimeout.unref?.();\n\t\t});\n\t\ttry {\n\t\t\treturn await Promise.race([settled, bounded]);\n\t\t} finally {\n\t\t\tif (timeout) clearTimeout(timeout);\n\t\t}\n\t};\n\tconst executionNamespace = randomUUID();\n\tconst cleanupRemoteBashOutput = async (path: string): Promise<void> => {\n\t\tlet cleanupTimeout: ReturnType<typeof setTimeout> | undefined;\n\t\ttry {\n\t\t\tawait Promise.race([\n\t\t\t\tclient.cleanupBashOutput(path),\n\t\t\t\tnew Promise<never>((_, reject) => {\n\t\t\t\t\tcleanupTimeout = setTimeout(() => reject(new Error(\"RPC cleanup timed out\")), 1_000);\n\t\t\t\t}),\n\t\t\t]);\n\t\t\treturn;\n\t\t} catch (transportError) {\n\t\t\t// Spill paths are shared host filesystem paths. If the RPC transport is\n\t\t\t// already unavailable, remove locally as a bounded best-effort fallback;\n\t\t\t// a later reconnect is not required to prevent this callback failure from\n\t\t\t// permanently leaking the host-owned artifact.\n\t\t\ttry {\n\t\t\t\tawait rm(path, { force: true });\n\t\t\t\treturn;\n\t\t\t} catch (localError) {\n\t\t\t\tonWarning?.({\n\t\t\t\t\ttype: \"interactive_host_action_failed\",\n\t\t\t\t\tmessage: `Warning: failed to clean up shared bash output spill: ${localError instanceof Error ? localError.message : String(localError)}`,\n\t\t\t\t\tcause: new AggregateError([transportError, localError]),\n\t\t\t\t});\n\t\t\t}\n\t\t} finally {\n\t\t\tif (cleanupTimeout) clearTimeout(cleanupTimeout);\n\t\t}\n\t};\n\tlet nextBashExecutionId = 0;\n\tconst bashExecutions = new Map<\n\t\tstring,\n\t\t{\n\t\t\tchunk?: (chunk: string) => void | PromiseLike<void>;\n\t\t\tpromises: Set<Promise<void>>;\n\t\t\terror: unknown;\n\t\t\thasError: boolean;\n\t\t}\n\t>();\n\tlet hostUiHandler: InteractiveHostUiHandler | undefined;\n\tconst pendingUiRequests: import(\"../rpc/rpc-types.ts\").RpcExtensionUIRequest[] = [];\n\tlet localBashAbortController: AbortController | undefined;\n\tlet localBashRunning = false;\n\tlet hostBashRunning = initialState.isBashRunning;\n\tlet nextQueuedInputOrder = Math.max(0, ...initialState.ordered.map((item) => item.enqueueOrder));\n\tlet sessionManager = local.sessionManager;\n\tlet settingsManager = SettingsManager.create(initialState.cwd, agentDir, {\n\t\tprojectTrusted: initialState.projectTrusted,\n\t});\n\tconst updateBashState = () => {\n\t\tstate = { ...state, isBashRunning: localBashRunning || hostBashRunning };\n\t};\n\tconst remoteSessionManager = new Proxy({} as SessionManager, {\n\t\tget(_target, property, _receiver) {\n\t\t\tif (property === \"appendLabelChange\") {\n\t\t\t\treturn (entryId: string, label?: string) => void client.setLabel(entryId, label);\n\t\t\t}\n\t\t\tif (property === \"getCwd\") return () => state.cwd;\n\t\t\tif (property === \"getSessionName\") return () => state.sessionName;\n\t\t\tif (property === \"getUsageTotals\") return () => state.usageTotals;\n\t\t\tconst value = Reflect.get(sessionManager, property, sessionManager);\n\t\t\treturn typeof value === \"function\" ? value.bind(sessionManager) : value;\n\t\t},\n\t});\n\tlet streamingAssistant: Extract<AgentSession[\"messages\"][number], { role: \"assistant\" }> | undefined;\n\tlet mirroredCurrentAssistantUsage = false;\n\t/** Non-zero while this runtime is driving its own replacement sequence. */\n\tlet localReplacementDepth = 0;\n\tconst listeners = new Set<AgentSessionEventListener>();\n\tclient.onEvent((wireEvent) => {\n\t\tif ((wireEvent as { type?: string }).type === \"extension_ui_request\") {\n\t\t\tconst request = wireEvent as import(\"../rpc/rpc-types.ts\").RpcExtensionUIRequest;\n\t\t\tif (hostUiHandler)\n\t\t\t\tvoid Promise.resolve(hostUiHandler(request)).then(\n\t\t\t\t\t(response) => response && client.sendExtensionUIResponse(response),\n\t\t\t\t);\n\t\t\telse pendingUiRequests.push(request);\n\t\t\treturn;\n\t\t}\n\t\tif (wireEvent.type === \"session_replaced\") {\n\t\t\t// The host swapped the live session behind this connection - another\n\t\t\t// attached client issued the replacement, or an extension drove one that no\n\t\t\t// client issued. Nothing else re-reads the binding, so without this the\n\t\t\t// proxy keeps serving the previous session's manager, settings and message\n\t\t\t// mirror while the host has already moved on. The command response carries\n\t\t\t// only `{ cancelled }`, so this event is the only signal available here.\n\t\t\t//\n\t\t\t// A multi-session host broadcasts the event to every connection including\n\t\t\t// the one that issued the replacement, and this runtime's own replacement\n\t\t\t// methods already run an ordered refresh/rebind - newSession additionally\n\t\t\t// transports setup entries between two refreshes. Refreshing again from\n\t\t\t// here would race that sequence, so self-driven replacements are skipped.\n\t\t\tif (localReplacementDepth === 0) {\n\t\t\t\tvoid refresh().catch(reportActionFailure(\"session refresh after replacement\"));\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tif (wireEvent.type === \"agent_settled\") state = { ...state, isStreaming: false, retryAttempt: 0 };\n\t\tif (wireEvent.type === \"bash_start\") {\n\t\t\thostBashRunning = true;\n\t\t\tupdateBashState();\n\t\t}\n\t\tif (wireEvent.type === \"bash_end\") {\n\t\t\thostBashRunning = false;\n\t\t\tupdateBashState();\n\t\t}\n\t\tif (wireEvent.type === \"bash_execution_update\" && wireEvent.id) {\n\t\t\tconst execution = bashExecutions.get(wireEvent.id);\n\t\t\tif (execution?.chunk && !execution.hasError) {\n\t\t\t\ttry {\n\t\t\t\t\tconst callbackPromise = Promise.resolve(execution.chunk(wireEvent.delta)).catch((error) => {\n\t\t\t\t\t\tif (!execution.hasError) {\n\t\t\t\t\t\t\texecution.error = error;\n\t\t\t\t\t\t\texecution.hasError = true;\n\t\t\t\t\t\t\tvoid client.abortBash().catch(() => {});\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthrow error;\n\t\t\t\t\t});\n\t\t\t\t\texecution.promises.add(callbackPromise);\n\t\t\t\t\tvoid callbackPromise.catch(() => {}).finally(() => execution.promises.delete(callbackPromise));\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (!execution.hasError) {\n\t\t\t\t\t\texecution.error = error;\n\t\t\t\t\t\texecution.hasError = true;\n\t\t\t\t\t\tvoid client.abortBash().catch(() => {});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (wireEvent.type === \"agent_start\") state = { ...state, isStreaming: true };\n\t\tif (wireEvent.type === \"compaction_start\") state = { ...state, isCompacting: true };\n\t\tif (wireEvent.type === \"compaction_end\") state = { ...state, isCompacting: false };\n\t\tif (wireEvent.type === \"auto_retry_start\") state = { ...state, retryAttempt: wireEvent.attempt };\n\t\tif (wireEvent.type === \"auto_retry_end\") state = { ...state, retryAttempt: 0 };\n\t\tif (wireEvent.type === \"queue_update\") {\n\t\t\tnextQueuedInputOrder = Math.max(nextQueuedInputOrder, ...wireEvent.ordered.map((item) => item.enqueueOrder));\n\t\t\tstate = {\n\t\t\t\t...state,\n\t\t\t\tsteering: [...wireEvent.steering],\n\t\t\t\tfollowUp: [...wireEvent.followUp],\n\t\t\t\tordered: [...wireEvent.ordered],\n\t\t\t\tpendingMessageCount: wireEvent.steering.length + wireEvent.followUp.length,\n\t\t\t};\n\t\t}\n\t\tif (wireEvent.type === \"model_changed\") {\n\t\t\tstate = { ...state, model: wireEvent.model, thinkingLevel: wireEvent.thinkingLevel };\n\t\t}\n\t\tif (wireEvent.type === \"thinking_level_changed\") state = { ...state, thinkingLevel: wireEvent.level };\n\t\tif (wireEvent.type === \"service_tier_changed\") {\n\t\t\tstate = { ...state, serviceTier: wireEvent.tier, fastMode: wireEvent.fastMode };\n\t\t}\n\t\tif (wireEvent.type === \"session_settings_changed\") {\n\t\t\tstate = {\n\t\t\t\t...state,\n\t\t\t\tsteeringMode: wireEvent.steeringMode,\n\t\t\t\tfollowUpMode: wireEvent.followUpMode,\n\t\t\t\tautoCompactionEnabled: wireEvent.autoCompactionEnabled,\n\t\t\t};\n\t\t}\n\t\tif (wireEvent.type === \"entry_appended\") {\n\t\t\ttry {\n\t\t\t\tsessionManager.appendEntry(wireEvent.entry);\n\t\t\t\tlocal.agent.state.messages = sessionManager.buildSessionContext().messages;\n\t\t\t} catch {\n\t\t\t\t// Non-fatal if the local snapshot cannot accept a concurrent entry.\n\t\t\t}\n\t\t}\n\t\tif (wireEvent.type === \"session_info_changed\") state = { ...state, sessionName: wireEvent.name };\n\t\tif (wireEvent.type === \"message_start\") {\n\t\t\tif (wireEvent.message.role === \"assistant\") {\n\t\t\t\tstreamingAssistant = structuredClone(wireEvent.message);\n\t\t\t\tmirroredCurrentAssistantUsage = false;\n\t\t\t}\n\t\t\tlocal.agent.state.messages.push(structuredClone(wireEvent.message));\n\t\t}\n\t\tif (wireEvent.type === \"message_end\") {\n\t\t\tif (wireEvent.message.role === \"assistant\") {\n\t\t\t\tstreamingAssistant = structuredClone(wireEvent.message);\n\t\t\t\tconst usage = wireEvent.message.usage;\n\t\t\t\tif (usage && !mirroredCurrentAssistantUsage) {\n\t\t\t\t\tmirroredCurrentAssistantUsage = true;\n\t\t\t\t\tconst latestPromptTokens = usage.input + usage.cacheRead + usage.cacheWrite;\n\t\t\t\t\tconst contextWindow = state.model?.contextWindow ?? 0;\n\t\t\t\t\tconst contextTokens = usage.input + usage.cacheRead + usage.cacheWrite;\n\t\t\t\t\tstate = {\n\t\t\t\t\t\t...state,\n\t\t\t\t\t\tcontextUsage:\n\t\t\t\t\t\t\tcontextWindow > 0\n\t\t\t\t\t\t\t\t? { tokens: contextTokens, contextWindow, percent: (contextTokens / contextWindow) * 100 }\n\t\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\t\tusageTotals: {\n\t\t\t\t\t\t\t...state.usageTotals,\n\t\t\t\t\t\t\tinput: state.usageTotals.input + usage.input,\n\t\t\t\t\t\t\toutput: state.usageTotals.output + usage.output,\n\t\t\t\t\t\t\tcacheRead: state.usageTotals.cacheRead + usage.cacheRead,\n\t\t\t\t\t\t\tcacheWrite: state.usageTotals.cacheWrite + usage.cacheWrite,\n\t\t\t\t\t\t\tcost: state.usageTotals.cost + (usage.cost?.total ?? 0),\n\t\t\t\t\t\t\tlatestCacheHitRate:\n\t\t\t\t\t\t\t\tlatestPromptTokens > 0 ? (usage.cacheRead / latestPromptTokens) * 100 : undefined,\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst messages = local.agent.state.messages;\n\t\t\tconst previous = messages.at(-1);\n\t\t\tif (previous?.role === wireEvent.message.role)\n\t\t\t\tmessages[messages.length - 1] = structuredClone(wireEvent.message);\n\t\t}\n\t\tif (wireEvent.type === \"compaction_end\" && wireEvent.accepted && !wireEvent.aborted) {\n\t\t\ttry {\n\t\t\t\tlocal.sessionManager.reloadFromDisk?.();\n\t\t\t\tif (sessionManager !== local.sessionManager) sessionManager.reloadFromDisk?.();\n\t\t\t\tlocal.agent.state.messages = sessionManager.buildSessionContext().messages;\n\t\t\t} catch {\n\t\t\t\t// Non-fatal if session file is transiently locked or unavailable\n\t\t\t}\n\t\t}\n\t\tconst event = hydrateMessageUpdate(wireEvent, streamingAssistant);\n\t\tfor (const listener of listeners) listener(event);\n\t});\n\tconst performRefresh = async (): Promise<void> => {\n\t\tconst nextState = await client.getState();\n\t\tstate = { ...stateFromRpc(nextState) };\n\t\tnextQueuedInputOrder = Math.max(0, ...nextState.ordered.map((item) => item.enqueueOrder));\n\t\tlet messages: AgentSession[\"messages\"];\n\t\tsettingsManager = SettingsManager.create(nextState.cwd, agentDir, {\n\t\t\tprojectTrusted: nextState.projectTrusted,\n\t\t});\n\t\tif (nextState.sessionFile) {\n\t\t\t// Keep the caller-owned manager identity when refreshing the same session.\n\t\t\t// Navigation and host-side mutations must update every existing mirror, not\n\t\t\t// leave the interactive runtime holding the pre-refresh snapshot.\n\t\t\tif (sessionManager.getSessionFile() === nextState.sessionFile) {\n\t\t\t\tsessionManager.reloadFromDisk?.();\n\t\t\t} else {\n\t\t\t\t// SessionManager.open retains the explicit path even when the host has\n\t\t\t\t// deferred creating the file for a setup-only session.\n\t\t\t\tsessionManager = SessionManager.open(nextState.sessionFile, undefined, nextState.cwd);\n\t\t\t}\n\t\t\tif (nextState.entries?.length && !sessionManager.getEntries().length) {\n\t\t\t\tfor (const entry of nextState.entries) sessionManager.appendEntry(entry);\n\t\t\t}\n\t\t\tmessages = sessionManager.buildSessionContext().messages;\n\t\t} else {\n\t\t\tmessages = await client.getMessages();\n\t\t}\n\t\tlocal.agent.state.messages.splice(0, local.agent.state.messages.length, ...structuredClone(messages));\n\t\tstreamingAssistant = undefined;\n\t};\n\t// Refreshes must not interleave: each one reassigns sessionManager,\n\t// settingsManager and the mirrored message list, so two in flight can commit a\n\t// mixed snapshot of two different sessions. A replacement-driven refresh races\n\t// exactly that way against a caller-driven one, so run them in order.\n\tlet refreshChain: Promise<void> = Promise.resolve();\n\tconst refresh = (): Promise<void> => {\n\t\tconst next = refreshChain.then(performRefresh, performRefresh);\n\t\trefreshChain = next.then(\n\t\t\t() => {},\n\t\t\t() => {},\n\t\t);\n\t\treturn next;\n\t};\n\tconst session = new Proxy(local, {\n\t\tget(target, property, receiver) {\n\t\t\tif (property === \"prompt\")\n\t\t\t\treturn (message: string, options?: Parameters<AgentSession[\"prompt\"]>[1]) =>\n\t\t\t\t\tclient.prompt(message, {\n\t\t\t\t\t\t...(options?.images ? { images: options.images } : {}),\n\t\t\t\t\t\t...(options?.streamingBehavior ? { streamingBehavior: options.streamingBehavior } : {}),\n\t\t\t\t\t\t...(options?.thinkingLevel ? { thinkingLevel: options.thinkingLevel } : {}),\n\t\t\t\t\t\t...(options?.sessionTitlePrompt !== undefined\n\t\t\t\t\t\t\t? { sessionTitlePrompt: options.sessionTitlePrompt }\n\t\t\t\t\t\t\t: {}),\n\t\t\t\t\t\t...(options?.expandPromptTemplates !== undefined\n\t\t\t\t\t\t\t? { expandPromptTemplates: options.expandPromptTemplates }\n\t\t\t\t\t\t\t: {}),\n\t\t\t\t\t\t...(options?.promptDisposition ? { promptDisposition: options.promptDisposition } : {}),\n\t\t\t\t\t\t...(options?.preflightResult ? { preflightResult: options.preflightResult } : {}),\n\t\t\t\t\t});\n\t\t\tif (property === \"abort\") return () => client.abort();\n\t\t\tif (property === \"abortCompaction\") return () => void client.abortCompaction();\n\t\t\tif (property === \"steer\")\n\t\t\t\treturn (\n\t\t\t\t\tmessage: string,\n\t\t\t\t\timages?: Parameters<AgentSession[\"steer\"]>[1],\n\t\t\t\t\trecovery?: { enqueueOrder?: number },\n\t\t\t\t) => {\n\t\t\t\t\tconst enqueueOrder =\n\t\t\t\t\t\trecovery?.enqueueOrder ?? Math.max(0, ...state.ordered.map((item) => item.enqueueOrder)) + 1;\n\t\t\t\t\tstate = {\n\t\t\t\t\t\t...state,\n\t\t\t\t\t\tsteering: [...state.steering, message],\n\t\t\t\t\t\tordered: [...state.ordered, { text: message, mode: \"steer\", enqueueOrder }],\n\t\t\t\t\t\tpendingMessageCount: state.pendingMessageCount + 1,\n\t\t\t\t\t};\n\t\t\t\t\treturn client.steer(message, images, { ...recovery, enqueueOrder });\n\t\t\t\t};\n\t\t\tif (property === \"followUp\")\n\t\t\t\treturn (\n\t\t\t\t\tmessage: string,\n\t\t\t\t\timages?: Parameters<AgentSession[\"followUp\"]>[1],\n\t\t\t\t\trecovery?: { enqueueOrder?: number },\n\t\t\t\t) => {\n\t\t\t\t\tconst enqueueOrder =\n\t\t\t\t\t\trecovery?.enqueueOrder ?? Math.max(0, ...state.ordered.map((item) => item.enqueueOrder)) + 1;\n\t\t\t\t\tstate = {\n\t\t\t\t\t\t...state,\n\t\t\t\t\t\tfollowUp: [...state.followUp, message],\n\t\t\t\t\t\tordered: [...state.ordered, { text: message, mode: \"followUp\", enqueueOrder }],\n\t\t\t\t\t\tpendingMessageCount: state.pendingMessageCount + 1,\n\t\t\t\t\t};\n\t\t\t\t\treturn client.followUp(message, images, { ...recovery, enqueueOrder });\n\t\t\t\t};\n\t\t\tif (property === \"waitForIdle\") return () => client.waitForIdle();\n\t\t\tif (property === \"getLastAssistantText\") return () => target.getLastAssistantText();\n\t\t\tif (property === \"setModel\" || property === \"setSessionModel\")\n\t\t\t\treturn async (model: NonNullable<AgentSession[\"model\"]>) => {\n\t\t\t\t\tconst next = await client.setModel(model.provider, model.id);\n\t\t\t\t\treturn { systemPromptName: next.systemPromptName, model: next };\n\t\t\t\t};\n\t\t\tif (property === \"setSessionThinkingLevel\")\n\t\t\t\treturn (level: AgentSession[\"thinkingLevel\"]) =>\n\t\t\t\t\tvoid client\n\t\t\t\t\t\t.setThinkingLevel(level, { scope: \"turn\" })\n\t\t\t\t\t\t.catch(reportActionFailure(\"setSessionThinkingLevel\"));\n\t\t\tif (property === \"setSessionFastMode\")\n\t\t\t\treturn (enabled: boolean) =>\n\t\t\t\t\tvoid client.setFastMode(enabled).catch(reportActionFailure(\"setSessionFastMode\"));\n\t\t\tif (property === \"abortRetry\") return () => void client.abortRetry().catch(reportActionFailure(\"abortRetry\"));\n\t\t\tif (property === \"setAutoRetryEnabled\")\n\t\t\t\treturn (enabled: boolean) =>\n\t\t\t\t\tvoid client.setAutoRetry(enabled).catch(reportActionFailure(\"setAutoRetryEnabled\"));\n\t\t\tif (property === \"reserveQueuedInputOrder\") return () => ++nextQueuedInputOrder;\n\t\t\tif (property === \"setFavoriteModels\")\n\t\t\t\treturn (models: Parameters<AgentSession[\"setFavoriteModels\"]>[0]) => {\n\t\t\t\t\tstate = { ...state, favoriteModels: [...models] };\n\t\t\t\t\tvoid client.setFavoriteModels(models).catch(reportActionFailure(\"setFavoriteModels\"));\n\t\t\t\t};\n\t\t\tif (property === \"setScopedModels\")\n\t\t\t\treturn (models: Parameters<AgentSession[\"setScopedModels\"]>[0]) => {\n\t\t\t\t\tstate = { ...state, scopedModels: [...models] };\n\t\t\t\t\tvoid client.setScopedModels(models).catch(reportActionFailure(\"setScopedModels\"));\n\t\t\t\t};\n\t\t\tif (property === \"cycleModel\") return (direction?: \"forward\" | \"backward\") => client.cycleModel(direction);\n\t\t\tif (property === \"setThinkingLevel\")\n\t\t\t\treturn (level: AgentSession[\"thinkingLevel\"]) =>\n\t\t\t\t\tvoid client.setThinkingLevel(level).catch(reportActionFailure(\"setThinkingLevel\"));\n\t\t\tif (property === \"cycleThinkingLevel\")\n\t\t\t\treturn () => client.cycleThinkingLevel().then((result) => result?.level);\n\t\t\tif (property === \"getAvailableThinkingLevels\") return () => client.getAvailableThinkingLevels();\n\t\t\tif (property === \"setSteeringMode\")\n\t\t\t\treturn (mode: AgentSession[\"steeringMode\"]) =>\n\t\t\t\t\tvoid client.setSteeringMode(mode).catch(reportActionFailure(\"setSteeringMode\"));\n\t\t\tif (property === \"setFollowUpMode\")\n\t\t\t\treturn (mode: AgentSession[\"followUpMode\"]) =>\n\t\t\t\t\tvoid client.setFollowUpMode(mode).catch(reportActionFailure(\"setFollowUpMode\"));\n\t\t\tif (property === \"compact\") return (instructions?: string) => client.compact(instructions);\n\t\t\tif (property === \"setAutoCompactionEnabled\")\n\t\t\t\treturn (enabled: boolean) =>\n\t\t\t\t\tvoid client.setAutoCompaction(enabled).catch(reportActionFailure(\"setAutoCompaction\"));\n\t\t\tif (property === \"executeBash\")\n\t\t\t\treturn async (\n\t\t\t\t\tcommand: string,\n\t\t\t\t\tonChunk?: (chunk: string) => void | PromiseLike<void>,\n\t\t\t\t\toptions?: { excludeFromContext?: boolean; operations?: BashOperations | Record<string, unknown> },\n\t\t\t\t) => {\n\t\t\t\t\tif (options?.operations && typeof options.operations.exec === \"function\") {\n\t\t\t\t\t\tconst abortController = new AbortController();\n\t\t\t\t\t\tlocalBashAbortController = abortController;\n\t\t\t\t\t\tlocalBashRunning = true;\n\t\t\t\t\t\tupdateBashState();\n\t\t\t\t\t\tconst sessionAtStart = state.sessionId;\n\t\t\t\t\t\tconst prefix = settingsManager.getShellCommandPrefix();\n\t\t\t\t\t\tconst resolvedCommand = prefix ? `${prefix}\\n${command}` : command;\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tconst result = await executeBashWithOperations(\n\t\t\t\t\t\t\t\tresolvedCommand,\n\t\t\t\t\t\t\t\tstate.cwd,\n\t\t\t\t\t\t\t\toptions.operations as BashOperations,\n\t\t\t\t\t\t\t\t{ onChunk, signal: abortController.signal },\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tif (state.sessionId === sessionAtStart) {\n\t\t\t\t\t\t\t\tawait client.recordBashResult(command, result, options.excludeFromContext);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn result;\n\t\t\t\t\t\t} finally {\n\t\t\t\t\t\t\tlocalBashAbortController = undefined;\n\t\t\t\t\t\t\tlocalBashRunning = false;\n\t\t\t\t\t\t\tupdateBashState();\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tconst executionId = `bash-${executionNamespace}-${++nextBashExecutionId}`;\n\t\t\t\t\tconst execution = {\n\t\t\t\t\t\tchunk: onChunk,\n\t\t\t\t\t\tpromises: new Set<Promise<void>>(),\n\t\t\t\t\t\terror: undefined as unknown,\n\t\t\t\t\t\thasError: false,\n\t\t\t\t\t};\n\t\t\t\t\tbashExecutions.set(executionId, execution);\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst result = await client.bash(command, {\n\t\t\t\t\t\t\texcludeFromContext: options?.excludeFromContext,\n\t\t\t\t\t\t\texecutionId,\n\t\t\t\t\t\t\toperations: options?.operations as Record<string, unknown> | undefined,\n\t\t\t\t\t\t});\n\t\t\t\t\t\tconst callbacksSettled = await waitForBashCallbacks(execution.promises, false);\n\t\t\t\t\t\tif (!callbacksSettled) {\n\t\t\t\t\t\t\tif (result.fullOutputPath) await cleanupRemoteBashOutput(result.fullOutputPath);\n\t\t\t\t\t\t\tthrow new Error(\"Bash output callback did not settle within 5000ms\");\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (execution.hasError) {\n\t\t\t\t\t\t\tif (result.fullOutputPath) await cleanupRemoteBashOutput(result.fullOutputPath);\n\t\t\t\t\t\t\tthrow execution.error;\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn result;\n\t\t\t\t\t} finally {\n\t\t\t\t\t\tbashExecutions.delete(executionId);\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\tif (property === \"abortBash\")\n\t\t\t\treturn () => {\n\t\t\t\t\tif (localBashAbortController) localBashAbortController.abort();\n\t\t\t\t\telse void client.abortBash().catch(reportActionFailure(\"abortBash\"));\n\t\t\t\t};\n\t\t\tif (property === \"getContextUsage\") return () => state.contextUsage;\n\t\t\tif (property === \"getSessionStats\") return () => client.getSessionStats();\n\t\t\tif (property === \"exportToHtml\")\n\t\t\t\treturn (outputPath?: string, options?: { themeName?: string }) =>\n\t\t\t\t\tclient.exportHtml(outputPath, options?.themeName).then((result) => result.path);\n\t\t\tif (property === \"setSessionName\")\n\t\t\t\treturn (name: string) => client.setSessionName(name).catch(reportActionFailure(\"setSessionName\"));\n\t\t\tif (property === \"navigateTree\")\n\t\t\t\treturn async (targetId: string, options?: Parameters<AgentSession[\"navigateTree\"]>[1]) => {\n\t\t\t\t\tconst result = await client.navigateTree(targetId, options);\n\t\t\t\t\tif (!result.cancelled) await refresh();\n\t\t\t\t\treturn result;\n\t\t\t\t};\n\t\t\tif (property === \"getUserMessagesForForking\") return () => client.getForkMessages();\n\t\t\tif (property === \"subscribe\")\n\t\t\t\treturn (listener: AgentSessionEventListener) => {\n\t\t\t\t\tlisteners.add(listener);\n\t\t\t\t\tconst localUnsubscribe = target.subscribe(listener);\n\t\t\t\t\treturn () => {\n\t\t\t\t\t\tlisteners.delete(listener);\n\t\t\t\t\t\tlocalUnsubscribe();\n\t\t\t\t\t};\n\t\t\t\t};\n\t\t\tif (property === \"isStreaming\") return state.isStreaming;\n\t\t\tif (property === \"isIdle\") return !state.isStreaming;\n\t\t\tif (property === \"isCompacting\") return state.isCompacting;\n\t\t\tif (property === \"pendingMessageCount\") return state.pendingMessageCount;\n\t\t\tif (property === \"getSteeringMessages\") return () => state.steering;\n\t\t\tif (property === \"getFollowUpMessages\") return () => state.followUp;\n\t\t\tif (property === \"clearQueue\")\n\t\t\t\treturn (options?: { abortWillFollow: boolean }) => {\n\t\t\t\t\tconst result = {\n\t\t\t\t\t\tsteering: [...state.steering],\n\t\t\t\t\t\tfollowUp: [...state.followUp],\n\t\t\t\t\t\tordered: [...state.ordered],\n\t\t\t\t\t};\n\t\t\t\t\tObject.defineProperty(result, \"ordered\", { value: result.ordered, enumerable: false });\n\t\t\t\t\tvoid client.clearQueue(options).catch(reportActionFailure(\"clearQueue\"));\n\t\t\t\t\treturn result;\n\t\t\t\t};\n\t\t\tif (property === \"abortBranchSummary\")\n\t\t\t\treturn () => void client.abortBranchSummary().catch(reportActionFailure(\"abortBranchSummary\"));\n\t\t\tif (property === \"recordBashResult\")\n\t\t\t\treturn (\n\t\t\t\t\tcommand: string,\n\t\t\t\t\tresult: Parameters<AgentSession[\"recordBashResult\"]>[1],\n\t\t\t\t\toptions?: { excludeFromContext?: boolean },\n\t\t\t\t) =>\n\t\t\t\t\tvoid client\n\t\t\t\t\t\t.recordBashResult(command, result, options?.excludeFromContext)\n\t\t\t\t\t\t.catch(reportActionFailure(\"recordBashResult\"));\n\t\t\tif (property === \"set_label\") return undefined;\n\t\t\tif (property === \"retryAttempt\") return state.retryAttempt;\n\t\t\tif (property === \"isBashRunning\") return state.isBashRunning;\n\t\t\tif (property === \"reload\") return (_options?: Parameters<AgentSession[\"reload\"]>[0]) => client.reload();\n\t\t\tif (property === \"checkReloadVeto\") return () => client.checkReloadVeto();\n\t\t\tif (property === \"exportToJsonl\")\n\t\t\t\treturn (outputPath?: string) => client.exportJsonl(outputPath).then((result) => result.path);\n\t\t\t// The footer and other renderers read session.state.*; surface the\n\t\t\t// host-authoritative fields there too, not only via the direct getters.\n\t\t\tif (property === \"state\") {\n\t\t\t\tconst localState = target.state;\n\t\t\t\treturn {\n\t\t\t\t\t...localState,\n\t\t\t\t\tmodel: state.model ?? localState.model,\n\t\t\t\t\tthinkingLevel: state.thinkingLevel,\n\t\t\t\t\tisStreaming: state.isStreaming,\n\t\t\t\t\tisCompacting: state.isCompacting,\n\t\t\t\t};\n\t\t\t}\n\t\t\tif (property === \"sessionFile\") return state.sessionFile;\n\t\t\tif (property === \"sessionId\") return state.sessionId;\n\t\t\tif (property === \"sessionName\") return state.sessionName;\n\t\t\tif (property === \"serviceTier\") return state.serviceTier;\n\t\t\tif (property === \"steeringMode\") return state.steeringMode;\n\t\t\tif (property === \"followUpMode\") return state.followUpMode;\n\t\t\tif (property === \"autoCompactionEnabled\") return state.autoCompactionEnabled;\n\t\t\tif (property === \"isFastModeActive\") return () => state.fastMode;\n\t\t\tif (property === \"sessionManager\") return remoteSessionManager;\n\t\t\tif (property === \"settingsManager\") return settingsManager;\n\t\t\tif (property === \"messages\") return target.messages;\n\t\t\tif (property === \"favoriteModels\") return state.favoriteModels;\n\t\t\tif (property === \"scopedModels\") return state.scopedModels;\n\t\t\tif (property === \"model\") return state.model ?? target.model;\n\t\t\tif (property === \"thinkingLevel\") return state.thinkingLevel;\n\t\t\treturn Reflect.get(target, property, receiver);\n\t\t},\n\t});\n\treturn {\n\t\tsession,\n\t\tsetHostUiHandler: (callback) => {\n\t\t\thostUiHandler = callback;\n\t\t\tif (callback)\n\t\t\t\tfor (const request of pendingUiRequests.splice(0))\n\t\t\t\t\tvoid Promise.resolve(callback(request)).then(\n\t\t\t\t\t\t(response) => response && client.sendExtensionUIResponse(response),\n\t\t\t\t\t);\n\t\t},\n\t\trefresh,\n\t\taroundLocalReplacement: async (body) => {\n\t\t\tlocalReplacementDepth++;\n\t\t\ttry {\n\t\t\t\treturn await body();\n\t\t\t} finally {\n\t\t\t\tlocalReplacementDepth--;\n\t\t\t}\n\t\t},\n\t\tabortLocalBash: () => localBashAbortController?.abort(),\n\t\tcreateReplacedSessionContext: () => {\n\t\t\tconst context = local.createReplacedSessionContext();\n\t\t\tObject.defineProperty(context, \"cwd\", { value: state.cwd });\n\t\t\tObject.defineProperty(context, \"sessionManager\", { value: remoteSessionManager });\n\t\t\tcontext.sendMessage = (message, options) =>\n\t\t\t\tclient.sendCustomMessage(message, {\n\t\t\t\t\ttriggerTurn: options?.triggerTurn,\n\t\t\t\t\tdeliverAs: options?.deliverAs,\n\t\t\t\t});\n\t\t\tcontext.sendUserMessage = (content, options) => {\n\t\t\t\tif (typeof content === \"string\")\n\t\t\t\t\treturn client.prompt(content, {\n\t\t\t\t\t\tstreamingBehavior: options?.deliverAs,\n\t\t\t\t\t\texpandPromptTemplates: options?.expandPromptTemplates,\n\t\t\t\t\t});\n\t\t\t\tconst text = content\n\t\t\t\t\t.filter((part) => part.type === \"text\")\n\t\t\t\t\t.map((part) => part.text)\n\t\t\t\t\t.join(\"\\n\");\n\t\t\t\tconst images = content.filter((part) => part.type === \"image\");\n\t\t\t\treturn client.prompt(text, {\n\t\t\t\t\timages,\n\t\t\t\t\tstreamingBehavior: options?.deliverAs,\n\t\t\t\t\texpandPromptTemplates: options?.expandPromptTemplates,\n\t\t\t\t});\n\t\t\t};\n\t\t\treturn context;\n\t\t},\n\t};\n}\n\nfunction hydrateMessageUpdate(\n\tevent: RpcClientEvent,\n\tstreamingAssistant: Extract<AgentSession[\"messages\"][number], { role: \"assistant\" }> | undefined,\n): AgentSessionEvent {\n\tif (event.type !== \"message_update\" || !streamingAssistant) return event as unknown as AgentSessionEvent;\n\tconst update = event.assistantMessageEvent;\n\tif (update.type !== \"text_delta\" && update.type !== \"thinking_delta\" && update.type !== \"toolcall_delta\") {\n\t\treturn event as unknown as AgentSessionEvent;\n\t}\n\tconst content = streamingAssistant.content[update.contentIndex];\n\tif (update.type === \"text_delta\" && content?.type === \"text\") content.text += update.delta;\n\tif (update.type === \"thinking_delta\" && content?.type === \"thinking\") content.thinking += update.delta;\n\tif (update.type === \"toolcall_delta\" && content?.type === \"toolCall\") {\n\t\tconst raw = JSON.stringify(content.arguments) + update.delta;\n\t\ttry {\n\t\t\tconst parsed: unknown = JSON.parse(raw);\n\t\t\tif (typeof parsed === \"object\" && parsed !== null && !Array.isArray(parsed)) {\n\t\t\t\tcontent.arguments = parsed as Record<string, unknown>;\n\t\t\t}\n\t\t} catch {\n\t\t\t// Keep the last valid arguments until the next complete update.\n\t\t}\n\t}\n\tstreamingAssistant.usage = event.usage;\n\treturn {\n\t\ttype: \"message_update\",\n\t\tmessage: structuredClone(streamingAssistant),\n\t\tassistantMessageEvent: { ...update, partial: structuredClone(streamingAssistant) },\n\t} as AgentSessionEvent;\n}\n\nfunction stateFromRpc(state: {\n\tmodel?: AgentSession[\"model\"];\n\tthinkingLevel: AgentSession[\"thinkingLevel\"];\n\tisStreaming: boolean;\n\tisCompacting: boolean;\n\tpendingMessageCount: number;\n\tusageTotals: import(\"../../core/session-manager.ts\").UsageTotals;\n\tcontextUsage?: import(\"../../core/extensions/types.ts\").ContextUsage;\n\tretryAttempt: number;\n\tisBashRunning: boolean;\n\tsessionFile?: string;\n\tsessionId: string;\n\tsessionName?: string;\n\tcwd: string;\n\tprojectTrusted: boolean;\n\tserviceTier?: AgentSession[\"serviceTier\"];\n\tfastMode: boolean;\n\tsteeringMode: AgentSession[\"steeringMode\"];\n\tfollowUpMode: AgentSession[\"followUpMode\"];\n\tautoCompactionEnabled: boolean;\n\tentries?: import(\"../../core/session-manager.ts\").SessionEntry[];\n\tfavoriteModels: import(\"../rpc/rpc-types.ts\").RpcSessionModelEntry[];\n\tscopedModels: import(\"../rpc/rpc-types.ts\").RpcSessionModelEntry[];\n\tsteering: string[];\n\tfollowUp: string[];\n\tordered: Array<{ text: string; mode: \"steer\" | \"followUp\"; enqueueOrder: number }>;\n}) {\n\treturn state;\n}\n\nexport function isInteractiveHostEvent(event: RpcClientEvent): event is Extract<RpcClientEvent, { type: string }> {\n\treturn typeof event === \"object\" && event !== null && \"type\" in event;\n}\n"]}
1
+ {"version":3,"file":"interactive-host-runtime.js","sourceRoot":"","sources":["../../../src/modes/interactive/interactive-host-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAKtC,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAExE,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAEjE,OAAO,EAAoB,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACrE,OAAO,E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AAM,GAAY,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YACxC,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;gBAC7E,OAAO,CAAC,SAAS,GAAG,MAAiC,CAAC;YACvD,CAAC;QACF,CAAC;QAAC,MAAM,CAAC;YACR,gEAAgE;QACjE,CAAC;IACF,CAAC;IACD,kBAAkB,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;IACvC,OAAO;QACN,IAAI,EAAE,gBAAgB;QACtB,OAAO,EAAE,eAAe,CAAC,kBAAkB,CAAC;QAC5C,qBAAqB,EAAE,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,eAAe,CAAC,kBAAkB,CAAC,EAAE;KAC7D,CAAC;AACxB,CAAC;AAED,SAAS,YAAY,CAAC,KA0BrB;IACA,OAAO,KAAK,CAAC;AACd,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,KAAqB;IAC3D,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,MAAM,IAAI,KAAK,CAAC;AACvE,CAAC","sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport { rm } from \"node:fs/promises\";\nimport type { ThinkingLevel } from \"@earendil-works/pi-agent-core\";\nimport type { AgentSession, AgentSessionEvent, AgentSessionEventListener } from \"../../core/agent-session.ts\";\nimport type { AgentSessionRuntime } from \"../../core/agent-session-runtime.ts\";\nimport type { AgentSessionRuntimeDiagnostic } from \"../../core/agent-session-services.ts\";\nimport { executeBashWithOperations } from \"../../core/bash-executor.ts\";\nimport type { ProjectTrustContext, ReplacedSessionContext } from \"../../core/extensions/index.ts\";\nimport { SessionManager } from \"../../core/session-manager.ts\";\nimport { SettingsManager } from \"../../core/settings-manager.ts\";\nimport type { BashOperations } from \"../../core/tools/bash.ts\";\nimport { type EnsuredHost, ensureHost } from \"../rpc/host-ensure.ts\";\nimport { isTransportGoneError, RpcClient, type RpcClientEvent } from \"../rpc/rpc-client.ts\";\n\nexport const INTERACTIVE_HOST_FALLBACK_WARNING = \"Warning: shared interactive host unavailable; continuing locally\";\nexport const INTERACTIVE_HOST_RECONNECTING_WARNING = \"Warning: shared interactive host connection lost; reconnecting\";\n\nexport interface InteractiveHostWarning {\n\treadonly type: \"interactive_host_fallback\" | \"interactive_host_action_failed\";\n\treadonly message: string;\n\treadonly cause: unknown;\n}\n\n/**\n * The session contract InteractiveMode actually runs against. The local\n * AgentSession answers these reads synchronously; the shared-host proxy answers\n * them over RPC. Declaring the union here keeps the proxy honest (no more\n * `as unknown as` lie at the boundary) and lets the compiler find every TUI\n * call site that must await.\n */\nexport type InteractiveSession = Omit<\n\tAgentSession,\n\t\"cycleThinkingLevel\" | \"getAvailableThinkingLevels\" | \"getSessionStats\" | \"getUserMessagesForForking\"\n> & {\n\tcycleThinkingLevel(): ThinkingLevel | undefined | Promise<ThinkingLevel | undefined>;\n\tgetAvailableThinkingLevels(): ThinkingLevel[] | Promise<ThinkingLevel[]>;\n\tgetSessionStats():\n\t\t| ReturnType<AgentSession[\"getSessionStats\"]>\n\t\t| Promise<ReturnType<AgentSession[\"getSessionStats\"]>>;\n\tgetUserMessagesForForking():\n\t\t| ReturnType<AgentSession[\"getUserMessagesForForking\"]>\n\t\t| Promise<ReturnType<AgentSession[\"getUserMessagesForForking\"]>>;\n};\n\nexport type InteractiveHostUiHandler = (\n\trequest: import(\"../rpc/rpc-types.ts\").RpcExtensionUIRequest,\n) =>\n\t| Promise<import(\"../rpc/rpc-types.ts\").RpcExtensionUIResponse | undefined>\n\t| import(\"../rpc/rpc-types.ts\").RpcExtensionUIResponse\n\t| undefined;\n\nexport interface InteractiveHostRuntimeOptions {\n\treadonly socket: string;\n\treadonly agentDir?: string;\n\treadonly ensureHost?: (options: { socket: string; agentDir?: string }) => Promise<EnsuredHost | undefined>;\n\tonWarning?: (warning: InteractiveHostWarning) => void;\n}\n\n/**\n * Replace only the transport-facing session operations. The object returned is\n * deliberately still an AgentSessionRuntime: InteractiveMode and extensions\n * retain their existing runtime seam, while the authoritative prompt/session\n * state is hosted by the shared RPC process.\n */\nexport async function createInteractiveHostRuntime(\n\tlocalRuntime: AgentSessionRuntime,\n\toptions: InteractiveHostRuntimeOptions,\n): Promise<AgentSessionRuntime> {\n\tconst sessionPath = localRuntime.session.sessionFile;\n\tif (!sessionPath) return localRuntime;\n\tconst startHost = options.ensureHost ?? ((hostOptions) => ensureHost(hostOptions));\n\tlet remoteSession: RemoteSessionProxy | undefined;\n\tlet remoteRuntime: RemoteInteractiveRuntime | undefined;\n\tlet reconnecting: Promise<void> | undefined;\n\tlet disconnectQueued = false;\n\tlet disposed = false;\n\tlet fallbackWarned = false;\n\tlet reconnectWarningShown = false;\n\tconst warnReconnect = (cause: unknown) => {\n\t\tif (reconnectWarningShown) return;\n\t\treconnectWarningShown = true;\n\t\toptions.onWarning?.({\n\t\t\ttype: \"interactive_host_action_failed\",\n\t\t\tmessage: INTERACTIVE_HOST_RECONNECTING_WARNING,\n\t\t\tcause,\n\t\t});\n\t};\n\tconst warnFallback = (cause: unknown) => {\n\t\tif (fallbackWarned) return;\n\t\tfallbackWarned = true;\n\t\toptions.onWarning?.({ type: \"interactive_host_fallback\", message: INTERACTIVE_HOST_FALLBACK_WARNING, cause });\n\t};\n\tlet scheduleReconnect: () => void = () => {};\n\tconst client = new RpcClient({\n\t\tsocketPath: options.socket,\n\t\tonDisconnect: () => {\n\t\t\tdisconnectQueued = true;\n\t\t\tscheduleReconnect();\n\t\t},\n\t});\n\tscheduleReconnect = () => {\n\t\tif (!remoteSession || reconnecting || disposed || remoteRuntime?.isFallback) return;\n\t\tremoteRuntime?.enterReconnecting();\n\t\treconnecting = (async () => {\n\t\t\tlet cause: unknown;\n\t\t\tfor (let attempt = 0; attempt < 3; attempt++) {\n\t\t\t\tif (disposed) return;\n\t\t\t\tdisconnectQueued = false;\n\t\t\t\ttry {\n\t\t\t\t\tawait startHost({ socket: options.socket, agentDir: options.agentDir });\n\t\t\t\t\tif (disposed) return;\n\t\t\t\t\tawait client.start();\n\t\t\t\t\tif (disposed) return;\n\t\t\t\t\tawait client.openSession({ sessionPath, cwd: localRuntime.cwd });\n\t\t\t\t\tif (disposed) return;\n\t\t\t\t\tawait remoteSession.refresh();\n\t\t\t\t\tif (disposed) return;\n\t\t\t\t\tfallbackWarned = false;\n\t\t\t\t\treconnectWarningShown = false;\n\t\t\t\t\tremoteRuntime?.enterConnected();\n\t\t\t\t\treturn;\n\t\t\t\t} catch (error) {\n\t\t\t\t\tcause = error;\n\t\t\t\t\tawait client.stop().catch(() => {});\n\t\t\t\t\tif (disposed) return;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!disposed) {\n\t\t\t\tawait remoteRuntime?.enterFallback();\n\t\t\t\twarnFallback(cause);\n\t\t\t}\n\t\t})().finally(() => {\n\t\t\treconnecting = undefined;\n\t\t\tif (disconnectQueued && !disposed && !remoteRuntime?.isFallback) scheduleReconnect();\n\t\t});\n\t};\n\ttry {\n\t\tawait startHost({ socket: options.socket, agentDir: options.agentDir });\n\t\tawait client.start();\n\t\tconst opened = await client.openSession({\n\t\t\tsessionPath,\n\t\t\tcwd: localRuntime.cwd,\n\t\t\tprovider: localRuntime.session.model?.provider,\n\t\t\tmodelId: localRuntime.session.model?.id,\n\t\t\tthinkingLevel: localRuntime.session.thinkingLevel,\n\t\t});\n\t\tremoteSession = createRemoteSessionProxy(\n\t\t\tlocalRuntime.session,\n\t\t\tlocalRuntime.services.agentDir,\n\t\t\tclient,\n\t\t\topened.state,\n\t\t\toptions.onWarning,\n\t\t\t(cause) => {\n\t\t\t\tif (remoteRuntime?.isReconnecting) warnReconnect(cause);\n\t\t\t\telse warnFallback(cause);\n\t\t\t},\n\t\t);\n\t\tif (opened.state.isBashRunning && !opened.attached) {\n\t\t\t// Only a newly opened session can have an execution orphaned by a\n\t\t\t// previous connection. An attach is an observer of the same live runtime;\n\t\t\t// aborting it would cancel work owned by the surviving attachment.\n\t\t\tawait client.abortBash().catch(() => {});\n\t\t}\n\t\tif (opened.attached) await remoteSession.refresh();\n\t\tremoteRuntime = new RemoteInteractiveRuntime(localRuntime, remoteSession, client, {\n\t\t\tonTransportGone: (cause) => {\n\t\t\t\tif (remoteRuntime?.isReconnecting) warnReconnect(cause);\n\t\t\t\telse warnFallback(cause);\n\t\t\t},\n\t\t\tget reconnecting() {\n\t\t\t\treturn reconnecting;\n\t\t\t},\n\t\t\tdispose: () => {\n\t\t\t\tdisposed = true;\n\t\t\t},\n\t\t});\n\t\treturn remoteRuntime as unknown as AgentSessionRuntime;\n\t} catch (cause) {\n\t\tawait client.stop().catch(() => {});\n\t\twarnFallback(cause);\n\t\treturn localRuntime;\n\t}\n}\n\nexport class RemoteInteractiveRuntime {\n\treadonly #local: AgentSessionRuntime;\n\treadonly #remoteSession: RemoteSessionProxy;\n\treadonly #client: RpcClient;\n\treadonly #lifecycle?: { readonly reconnecting: Promise<void> | undefined; readonly dispose: () => void };\n\treadonly #onTransportGone: (cause: unknown) => void;\n\t#rebindSession: (() => Promise<void>) | undefined;\n\t#beforeSessionInvalidate: (() => void) | undefined;\n\t#state: \"connected\" | \"reconnecting\" | \"fallback\" | \"disposed\" = \"connected\";\n\t#fallbackHandoff: Promise<void> | undefined;\n\tget isReconnecting(): boolean {\n\t\treturn this.#state === \"reconnecting\";\n\t}\n\tget isFallback(): boolean {\n\t\treturn this.#state === \"fallback\";\n\t}\n\n\tconstructor(\n\t\tlocal: AgentSessionRuntime,\n\t\tremoteSession: RemoteSessionProxy,\n\t\tclient: RpcClient,\n\t\tlifecycle?: { readonly reconnecting: Promise<void> | undefined; readonly dispose: () => void } & {\n\t\t\tonTransportGone: (cause: unknown) => void;\n\t\t},\n\t) {\n\t\tthis.#local = local;\n\t\tthis.#remoteSession = remoteSession;\n\t\tthis.#client = client;\n\t\tthis.#lifecycle = lifecycle;\n\t\tthis.#onTransportGone = lifecycle?.onTransportGone ?? (() => {});\n\t}\n\n\tasync #call<T>(call: () => Promise<T>): Promise<T> {\n\t\ttry {\n\t\t\treturn await call();\n\t\t} catch (error) {\n\t\t\tif (isTransportGoneError(error)) {\n\t\t\t\tthis.#onTransportGone(error);\n\t\t\t\treturn { cancelled: true } as T;\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\tenterConnected(): void {\n\t\tif (this.#state !== \"disposed\" && this.#state !== \"fallback\") this.#state = \"connected\";\n\t}\n\n\tenterReconnecting(): void {\n\t\tif (this.#state !== \"disposed\" && this.#state !== \"fallback\") this.#state = \"reconnecting\";\n\t}\n\n\tasync enterFallback(): Promise<void> {\n\t\tif (this.#state === \"disposed\" || this.#state === \"fallback\") return;\n\t\tthis.#state = \"fallback\";\n\t\tthis.#beforeSessionInvalidate?.();\n\t\tconst rebind = this.#rebindSession?.();\n\t\tif (rebind) {\n\t\t\tthis.#fallbackHandoff = rebind.catch((error) => {\n\t\t\t\tthis.#onTransportGone(error);\n\t\t\t});\n\t\t\tawait this.#fallbackHandoff;\n\t\t}\n\t}\n\n\tget session(): AgentSession {\n\t\treturn this.#state === \"fallback\" || this.#state === \"disposed\"\n\t\t\t? this.#local.session\n\t\t\t: this.#remoteSession.session;\n\t}\n\tget services(): AgentSessionRuntime[\"services\"] {\n\t\treturn this.#local.services;\n\t}\n\tget cwd(): string {\n\t\treturn this.session.sessionManager.getCwd();\n\t}\n\tget diagnostics(): readonly AgentSessionRuntimeDiagnostic[] {\n\t\treturn this.#local.diagnostics;\n\t}\n\tget modelFallbackMessage(): string | undefined {\n\t\treturn this.#local.modelFallbackMessage;\n\t}\n\tget launchProfile(): AgentSessionRuntime[\"launchProfile\"] {\n\t\treturn this.#local.launchProfile;\n\t}\n\tsetBeforeSessionInvalidate(callback?: () => void): void {\n\t\tthis.#beforeSessionInvalidate = callback;\n\t\tthis.#local.setBeforeSessionInvalidate(callback);\n\t}\n\tsetRebindSession(callback?: () => Promise<void>): void {\n\t\tthis.#rebindSession = callback;\n\t\tthis.#local.setRebindSession(callback);\n\t\tif (callback && this.#state === \"fallback\" && !this.#fallbackHandoff) {\n\t\t\tthis.#fallbackHandoff = callback().catch((error) => {\n\t\t\t\tthis.#onTransportGone(error);\n\t\t\t});\n\t\t}\n\t}\n\tsetHostUiHandler(callback?: InteractiveHostUiHandler): void {\n\t\tthis.#remoteSession.setHostUiHandler(callback);\n\t}\n\tasync dispose(): Promise<void> {\n\t\tif (this.#state === \"disposed\") return;\n\t\tthis.#state = \"disposed\";\n\t\tthis.#lifecycle?.dispose();\n\t\tawait this.#lifecycle?.reconnecting?.catch(() => {});\n\t\tawait this.#fallbackHandoff?.catch(() => {});\n\t\tconst errors: unknown[] = [];\n\t\tfor (const cleanup of [\n\t\t\t() => this.#remoteSession.abortLocalBash(),\n\t\t\t() => this.#client.closeSession(),\n\t\t\t() => this.#client.stop(),\n\t\t\t() => this.#local.dispose(),\n\t\t]) {\n\t\t\ttry {\n\t\t\t\tawait cleanup();\n\t\t\t} catch (error) {\n\t\t\t\terrors.push(error);\n\t\t\t}\n\t\t}\n\t\tif (errors.length > 0) throw errors[0];\n\t}\n\tasync newSession(options?: {\n\t\tparentSession?: string;\n\t\tsetup?: (sessionManager: SessionManager) => Promise<void>;\n\t\twithSession?: (ctx: ReplacedSessionContext) => Promise<void>;\n\t}): Promise<{ cancelled: boolean }> {\n\t\tif (this.#state === \"fallback\") return this.#local.newSession(options);\n\t\t// Suppresses for the ENTIRE command, not just the refresh tail: a\n\t\t// multi-session host emits session_replaced while completing it, so the echo\n\t\t// can arrive before the refresh/rebind sequence below starts and race it -\n\t\t// newSession transports setup entries between two refreshes.\n\t\treturn this.#remoteSession\n\t\t\t.aroundLocalReplacement(async () => {\n\t\t\t\tconst result = await this.#call(() => this.#client.newSession(options?.parentSession));\n\t\t\t\tif (!result.cancelled) {\n\t\t\t\t\tthis.#beforeSessionInvalidate?.();\n\t\t\t\t\tthis.#remoteSession.abortLocalBash();\n\t\t\t\t\tawait this.#remoteSession.refresh();\n\t\t\t\t\tif (options?.setup) {\n\t\t\t\t\t\tconst capture = SessionManager.inMemory(this.#remoteSession.session.sessionManager.getCwd());\n\t\t\t\t\t\tawait options.setup(capture);\n\t\t\t\t\t\tfor (const entry of capture.getEntries()) await this.#client.appendSessionEntry(entry);\n\t\t\t\t\t\tawait this.#remoteSession.refresh();\n\t\t\t\t\t}\n\t\t\t\t\tawait this.#rebindSession?.();\n\t\t\t\t\tif (options?.withSession) await options.withSession(this.#remoteSession.createReplacedSessionContext());\n\t\t\t\t}\n\t\t\t\treturn result;\n\t\t\t})\n\t\t\t.catch((error) => {\n\t\t\t\tif (isTransportGoneError(error)) return { cancelled: true };\n\t\t\t\tthrow error;\n\t\t\t});\n\t}\n\tasync switchSession(\n\t\tsessionPath: string,\n\t\toptions?: {\n\t\t\tcwdOverride?: string;\n\t\t\twithSession?: (ctx: ReplacedSessionContext) => Promise<void>;\n\t\t\tprojectTrustContextFactory?: (cwd: string) => ProjectTrustContext;\n\t\t},\n\t): Promise<{ cancelled: boolean }> {\n\t\tif (this.#state === \"fallback\") return this.#local.switchSession(sessionPath, options);\n\t\t// See newSession: the suppression must cover the command itself, since the\n\t\t// host emits session_replaced while completing it.\n\t\treturn this.#remoteSession\n\t\t\t.aroundLocalReplacement(async () => {\n\t\t\t\tconst result = await this.#call(() =>\n\t\t\t\t\tthis.#client.switchSession(\n\t\t\t\t\t\tsessionPath,\n\t\t\t\t\t\toptions?.cwdOverride === undefined ? undefined : { cwdOverride: options.cwdOverride },\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t\tif (!result.cancelled) {\n\t\t\t\t\tthis.#beforeSessionInvalidate?.();\n\t\t\t\t\tthis.#remoteSession.abortLocalBash();\n\t\t\t\t\tawait this.#remoteSession.refresh();\n\t\t\t\t\tawait this.#rebindSession?.();\n\t\t\t\t\t// The shared host already resolved trust; this callback is retained for\n\t\t\t\t\t// compatibility, but its result cannot override host-authoritative state.\n\t\t\t\t\toptions?.projectTrustContextFactory?.(this.#remoteSession.session.sessionManager.getCwd());\n\t\t\t\t\tif (options?.withSession) await options.withSession(this.#remoteSession.createReplacedSessionContext());\n\t\t\t\t}\n\t\t\t\treturn result;\n\t\t\t})\n\t\t\t.catch((error) => {\n\t\t\t\tif (isTransportGoneError(error)) return { cancelled: true };\n\t\t\t\tthrow error;\n\t\t\t});\n\t}\n\tasync fork(\n\t\tentryId: string,\n\t\toptions?: { position?: \"before\" | \"at\"; withSession?: (ctx: ReplacedSessionContext) => Promise<void> },\n\t): Promise<{ cancelled: boolean; selectedText?: string }> {\n\t\tif (this.#state === \"fallback\") return this.#local.fork(entryId, options);\n\t\t// See newSession: the suppression must cover the command itself.\n\t\treturn this.#remoteSession\n\t\t\t.aroundLocalReplacement(async () => {\n\t\t\t\tconst result = await this.#call(() => this.#client.fork(entryId, options));\n\t\t\t\tif (!result.cancelled) {\n\t\t\t\t\tthis.#beforeSessionInvalidate?.();\n\t\t\t\t\tthis.#remoteSession.abortLocalBash();\n\t\t\t\t\tawait this.#refreshAndRebind();\n\t\t\t\t\tif (options?.withSession) await options.withSession(this.#remoteSession.createReplacedSessionContext());\n\t\t\t\t}\n\t\t\t\treturn { cancelled: result.cancelled, selectedText: result.text };\n\t\t\t})\n\t\t\t.catch((error) => {\n\t\t\t\tif (isTransportGoneError(error)) return { cancelled: true };\n\t\t\t\tthrow error;\n\t\t\t});\n\t}\n\tasync importFromJsonl(inputPath: string, cwdOverride?: string): Promise<{ cancelled: boolean }> {\n\t\tif (this.#state === \"fallback\") return this.#local.importFromJsonl(inputPath, cwdOverride);\n\t\t// See newSession: the suppression must cover the command itself.\n\t\treturn this.#remoteSession\n\t\t\t.aroundLocalReplacement(async () => {\n\t\t\t\tconst result = await this.#call(() => this.#client.importJsonl(inputPath, cwdOverride));\n\t\t\t\tif (!result.cancelled) {\n\t\t\t\t\tthis.#beforeSessionInvalidate?.();\n\t\t\t\t\tthis.#remoteSession.abortLocalBash();\n\t\t\t\t\tawait this.#refreshAndRebind();\n\t\t\t\t}\n\t\t\t\treturn result;\n\t\t\t})\n\t\t\t.catch((error) => {\n\t\t\t\tif (isTransportGoneError(error)) return { cancelled: true };\n\t\t\t\tthrow error;\n\t\t\t});\n\t}\n\n\tasync #refreshAndRebind(): Promise<void> {\n\t\tawait this.#remoteSession.refresh();\n\t\tawait this.#rebindSession?.();\n\t}\n}\n\ninterface RemoteSessionProxy {\n\treadonly session: AgentSession;\n\tsetHostUiHandler(callback?: InteractiveHostUiHandler): void;\n\trefresh(): Promise<void>;\n\t/**\n\t * Run a replacement this runtime is driving itself, suppressing the refresh\n\t * that the host's broadcast `session_replaced` would otherwise trigger. The\n\t * caller owns the refresh/rebind ordering for its own replacements, so the\n\t * scope must cover the command itself, not just its refresh tail.\n\t */\n\taroundLocalReplacement<T>(body: () => Promise<T>): Promise<T>;\n\tabortLocalBash(): void;\n\tcreateReplacedSessionContext(): ReplacedSessionContext;\n}\n\n/** Exported for direct coverage of the wire-event handling below. */\nexport function createRemoteSessionProxy(\n\tlocal: AgentSession,\n\tagentDir: string,\n\tclient: RpcClient,\n\tinitialState: ReturnType<typeof stateFromRpc>,\n\tonWarning?: (warning: InteractiveHostWarning) => void,\n\tonTransportGone?: (cause: unknown) => void,\n): RemoteSessionProxy {\n\t// Fire-and-forget setters keep the sync AgentSession signature, but their RPC\n\t// failures must not vanish: the matching *_changed wire event confirms success,\n\t// and a rejection here is the only signal of failure.\n\tconst reportActionFailure = (action: string) => (error: unknown) => {\n\t\tconst transportGone = isTransportGoneError(error);\n\t\tif (transportGone) onTransportGone?.(error);\n\t\telse\n\t\t\tonWarning?.({\n\t\t\t\ttype: \"interactive_host_action_failed\",\n\t\t\t\tmessage: `Warning: shared interactive host ${action} failed: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t\tcause: error,\n\t\t\t});\n\t};\n\tconst transportCall = async <T>(action: string, call: () => Promise<T>, cancelledValue?: T): Promise<T> => {\n\t\ttry {\n\t\t\treturn await call();\n\t\t} catch (error) {\n\t\t\tif (!isTransportGoneError(error)) throw error;\n\t\t\treportActionFailure(action)(error);\n\t\t\treturn cancelledValue as T;\n\t\t}\n\t};\n\tlet state = { ...initialState };\n\tconst waitForBashCallbacks = async (promises: Set<Promise<void>>, allowAbandonment: boolean): Promise<boolean> => {\n\t\tif (promises.size === 0) return true;\n\t\tconst settled = Promise.allSettled([...promises]).then(() => true);\n\t\tlet timeout: ReturnType<typeof setTimeout> | undefined;\n\t\tconst bounded = new Promise<false>((resolve) => {\n\t\t\ttimeout = setTimeout(resolve, allowAbandonment ? 100 : 5_000, false);\n\t\t\ttimeout.unref?.();\n\t\t});\n\t\ttry {\n\t\t\treturn await Promise.race([settled, bounded]);\n\t\t} finally {\n\t\t\tif (timeout) clearTimeout(timeout);\n\t\t}\n\t};\n\tconst executionNamespace = randomUUID();\n\tconst cleanupRemoteBashOutput = async (path: string): Promise<void> => {\n\t\tlet cleanupTimeout: ReturnType<typeof setTimeout> | undefined;\n\t\ttry {\n\t\t\tawait Promise.race([\n\t\t\t\tclient.cleanupBashOutput(path),\n\t\t\t\tnew Promise<never>((_, reject) => {\n\t\t\t\t\tcleanupTimeout = setTimeout(() => reject(new Error(\"RPC cleanup timed out\")), 1_000);\n\t\t\t\t}),\n\t\t\t]);\n\t\t\treturn;\n\t\t} catch (transportError) {\n\t\t\t// Spill paths are shared host filesystem paths. If the RPC transport is\n\t\t\t// already unavailable, remove locally as a bounded best-effort fallback;\n\t\t\t// a later reconnect is not required to prevent this callback failure from\n\t\t\t// permanently leaking the host-owned artifact.\n\t\t\ttry {\n\t\t\t\tawait rm(path, { force: true });\n\t\t\t\treturn;\n\t\t\t} catch (localError) {\n\t\t\t\tonWarning?.({\n\t\t\t\t\ttype: \"interactive_host_action_failed\",\n\t\t\t\t\tmessage: `Warning: failed to clean up shared bash output spill: ${localError instanceof Error ? localError.message : String(localError)}`,\n\t\t\t\t\tcause: new AggregateError([transportError, localError]),\n\t\t\t\t});\n\t\t\t}\n\t\t} finally {\n\t\t\tif (cleanupTimeout) clearTimeout(cleanupTimeout);\n\t\t}\n\t};\n\tlet nextBashExecutionId = 0;\n\tconst bashExecutions = new Map<\n\t\tstring,\n\t\t{\n\t\t\tchunk?: (chunk: string) => void | PromiseLike<void>;\n\t\t\tpromises: Set<Promise<void>>;\n\t\t\terror: unknown;\n\t\t\thasError: boolean;\n\t\t}\n\t>();\n\tlet hostUiHandler: InteractiveHostUiHandler | undefined;\n\tconst pendingUiRequests: import(\"../rpc/rpc-types.ts\").RpcExtensionUIRequest[] = [];\n\tlet localBashAbortController: AbortController | undefined;\n\tlet localBashRunning = false;\n\tlet hostBashRunning = initialState.isBashRunning;\n\tlet nextQueuedInputOrder = Math.max(0, ...initialState.ordered.map((item) => item.enqueueOrder));\n\tlet sessionManager = local.sessionManager;\n\tlet settingsManager = SettingsManager.create(initialState.cwd, agentDir, {\n\t\tprojectTrusted: initialState.projectTrusted,\n\t});\n\tconst updateBashState = () => {\n\t\tstate = { ...state, isBashRunning: localBashRunning || hostBashRunning };\n\t};\n\tconst remoteSessionManager = new Proxy({} as SessionManager, {\n\t\tget(_target, property, _receiver) {\n\t\t\tif (property === \"appendLabelChange\") {\n\t\t\t\treturn (entryId: string, label?: string) =>\n\t\t\t\t\tvoid client.setLabel(entryId, label).catch(reportActionFailure(\"appendLabelChange\"));\n\t\t\t}\n\t\t\tif (property === \"getCwd\") return () => state.cwd;\n\t\t\tif (property === \"getSessionName\") return () => state.sessionName;\n\t\t\tif (property === \"getUsageTotals\") return () => state.usageTotals;\n\t\t\tconst value = Reflect.get(sessionManager, property, sessionManager);\n\t\t\treturn typeof value === \"function\" ? value.bind(sessionManager) : value;\n\t\t},\n\t});\n\tlet streamingAssistant: Extract<AgentSession[\"messages\"][number], { role: \"assistant\" }> | undefined;\n\tlet mirroredCurrentAssistantUsage = false;\n\t/** Non-zero while this runtime is driving its own replacement sequence. */\n\tlet localReplacementDepth = 0;\n\tconst listeners = new Set<AgentSessionEventListener>();\n\tclient.onEvent((wireEvent) => {\n\t\tif ((wireEvent as { type?: string }).type === \"extension_ui_request\") {\n\t\t\tconst request = wireEvent as import(\"../rpc/rpc-types.ts\").RpcExtensionUIRequest;\n\t\t\tif (hostUiHandler)\n\t\t\t\tvoid Promise.resolve(hostUiHandler(request))\n\t\t\t\t\t.then((response) => response && client.sendExtensionUIResponse(response))\n\t\t\t\t\t.catch(reportActionFailure(\"host UI response\"));\n\t\t\telse pendingUiRequests.push(request);\n\t\t\treturn;\n\t\t}\n\t\tif (wireEvent.type === \"session_replaced\") {\n\t\t\t// The host swapped the live session behind this connection - another\n\t\t\t// attached client issued the replacement, or an extension drove one that no\n\t\t\t// client issued. Nothing else re-reads the binding, so without this the\n\t\t\t// proxy keeps serving the previous session's manager, settings and message\n\t\t\t// mirror while the host has already moved on. The command response carries\n\t\t\t// only `{ cancelled }`, so this event is the only signal available here.\n\t\t\t//\n\t\t\t// A multi-session host broadcasts the event to every connection including\n\t\t\t// the one that issued the replacement, and this runtime's own replacement\n\t\t\t// methods already run an ordered refresh/rebind - newSession additionally\n\t\t\t// transports setup entries between two refreshes. Refreshing again from\n\t\t\t// here would race that sequence, so self-driven replacements are skipped.\n\t\t\tif (localReplacementDepth === 0) {\n\t\t\t\tvoid refresh().catch(reportActionFailure(\"session refresh after replacement\"));\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tif (wireEvent.type === \"agent_settled\") state = { ...state, isStreaming: false, retryAttempt: 0 };\n\t\tif (wireEvent.type === \"bash_start\") {\n\t\t\thostBashRunning = true;\n\t\t\tupdateBashState();\n\t\t}\n\t\tif (wireEvent.type === \"bash_end\") {\n\t\t\thostBashRunning = false;\n\t\t\tupdateBashState();\n\t\t}\n\t\tif (wireEvent.type === \"bash_execution_update\" && wireEvent.id) {\n\t\t\tconst execution = bashExecutions.get(wireEvent.id);\n\t\t\tif (execution?.chunk && !execution.hasError) {\n\t\t\t\ttry {\n\t\t\t\t\tconst callbackPromise = Promise.resolve(execution.chunk(wireEvent.delta)).catch((error) => {\n\t\t\t\t\t\tif (!execution.hasError) {\n\t\t\t\t\t\t\texecution.error = error;\n\t\t\t\t\t\t\texecution.hasError = true;\n\t\t\t\t\t\t\tvoid client.abortBash().catch(() => {});\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthrow error;\n\t\t\t\t\t});\n\t\t\t\t\texecution.promises.add(callbackPromise);\n\t\t\t\t\tvoid callbackPromise.catch(() => {}).finally(() => execution.promises.delete(callbackPromise));\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (!execution.hasError) {\n\t\t\t\t\t\texecution.error = error;\n\t\t\t\t\t\texecution.hasError = true;\n\t\t\t\t\t\tvoid client.abortBash().catch(() => {});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (wireEvent.type === \"agent_start\") state = { ...state, isStreaming: true };\n\t\tif (wireEvent.type === \"compaction_start\") state = { ...state, isCompacting: true };\n\t\tif (wireEvent.type === \"compaction_end\") state = { ...state, isCompacting: false };\n\t\tif (wireEvent.type === \"auto_retry_start\") state = { ...state, retryAttempt: wireEvent.attempt };\n\t\tif (wireEvent.type === \"auto_retry_end\") state = { ...state, retryAttempt: 0 };\n\t\tif (wireEvent.type === \"queue_update\") {\n\t\t\tnextQueuedInputOrder = Math.max(nextQueuedInputOrder, ...wireEvent.ordered.map((item) => item.enqueueOrder));\n\t\t\tstate = {\n\t\t\t\t...state,\n\t\t\t\tsteering: [...wireEvent.steering],\n\t\t\t\tfollowUp: [...wireEvent.followUp],\n\t\t\t\tordered: [...wireEvent.ordered],\n\t\t\t\tpendingMessageCount: wireEvent.steering.length + wireEvent.followUp.length,\n\t\t\t};\n\t\t}\n\t\tif (wireEvent.type === \"model_changed\") {\n\t\t\tstate = { ...state, model: wireEvent.model, thinkingLevel: wireEvent.thinkingLevel };\n\t\t}\n\t\tif (wireEvent.type === \"thinking_level_changed\") state = { ...state, thinkingLevel: wireEvent.level };\n\t\tif (wireEvent.type === \"service_tier_changed\") {\n\t\t\tstate = { ...state, serviceTier: wireEvent.tier, fastMode: wireEvent.fastMode };\n\t\t}\n\t\tif (wireEvent.type === \"session_settings_changed\") {\n\t\t\tstate = {\n\t\t\t\t...state,\n\t\t\t\tsteeringMode: wireEvent.steeringMode,\n\t\t\t\tfollowUpMode: wireEvent.followUpMode,\n\t\t\t\tautoCompactionEnabled: wireEvent.autoCompactionEnabled,\n\t\t\t};\n\t\t}\n\t\tif (wireEvent.type === \"entry_appended\") {\n\t\t\ttry {\n\t\t\t\tsessionManager.appendEntry(wireEvent.entry);\n\t\t\t\tlocal.agent.state.messages = sessionManager.buildSessionContext().messages;\n\t\t\t} catch {\n\t\t\t\t// Non-fatal if the local snapshot cannot accept a concurrent entry.\n\t\t\t}\n\t\t}\n\t\tif (wireEvent.type === \"session_info_changed\") state = { ...state, sessionName: wireEvent.name };\n\t\tif (wireEvent.type === \"message_start\") {\n\t\t\tif (wireEvent.message.role === \"assistant\") {\n\t\t\t\tstreamingAssistant = structuredClone(wireEvent.message);\n\t\t\t\tmirroredCurrentAssistantUsage = false;\n\t\t\t}\n\t\t\tlocal.agent.state.messages.push(structuredClone(wireEvent.message));\n\t\t}\n\t\tif (wireEvent.type === \"message_end\") {\n\t\t\tif (wireEvent.message.role === \"assistant\") {\n\t\t\t\tstreamingAssistant = structuredClone(wireEvent.message);\n\t\t\t\tconst usage = wireEvent.message.usage;\n\t\t\t\tif (usage && !mirroredCurrentAssistantUsage) {\n\t\t\t\t\tmirroredCurrentAssistantUsage = true;\n\t\t\t\t\tconst latestPromptTokens = usage.input + usage.cacheRead + usage.cacheWrite;\n\t\t\t\t\tconst contextWindow = state.model?.contextWindow ?? 0;\n\t\t\t\t\tconst contextTokens = usage.input + usage.cacheRead + usage.cacheWrite;\n\t\t\t\t\tstate = {\n\t\t\t\t\t\t...state,\n\t\t\t\t\t\tcontextUsage:\n\t\t\t\t\t\t\tcontextWindow > 0\n\t\t\t\t\t\t\t\t? { tokens: contextTokens, contextWindow, percent: (contextTokens / contextWindow) * 100 }\n\t\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\t\tusageTotals: {\n\t\t\t\t\t\t\t...state.usageTotals,\n\t\t\t\t\t\t\tinput: state.usageTotals.input + usage.input,\n\t\t\t\t\t\t\toutput: state.usageTotals.output + usage.output,\n\t\t\t\t\t\t\tcacheRead: state.usageTotals.cacheRead + usage.cacheRead,\n\t\t\t\t\t\t\tcacheWrite: state.usageTotals.cacheWrite + usage.cacheWrite,\n\t\t\t\t\t\t\tcost: state.usageTotals.cost + (usage.cost?.total ?? 0),\n\t\t\t\t\t\t\tlatestCacheHitRate:\n\t\t\t\t\t\t\t\tlatestPromptTokens > 0 ? (usage.cacheRead / latestPromptTokens) * 100 : undefined,\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst messages = local.agent.state.messages;\n\t\t\tconst previous = messages.at(-1);\n\t\t\tif (previous?.role === wireEvent.message.role)\n\t\t\t\tmessages[messages.length - 1] = structuredClone(wireEvent.message);\n\t\t}\n\t\tif (wireEvent.type === \"compaction_end\" && wireEvent.accepted && !wireEvent.aborted) {\n\t\t\ttry {\n\t\t\t\tlocal.sessionManager.reloadFromDisk?.();\n\t\t\t\tif (sessionManager !== local.sessionManager) sessionManager.reloadFromDisk?.();\n\t\t\t\tlocal.agent.state.messages = sessionManager.buildSessionContext().messages;\n\t\t\t} catch {\n\t\t\t\t// Non-fatal if session file is transiently locked or unavailable\n\t\t\t}\n\t\t}\n\t\tconst event = hydrateMessageUpdate(wireEvent, streamingAssistant);\n\t\tfor (const listener of listeners) listener(event);\n\t});\n\tconst performRefresh = async (): Promise<void> => {\n\t\t// Captured before the first await: entries that arrive via `entry_appended`\n\t\t// while this refresh is in flight are newer than the snapshot it reconciles\n\t\t// against, and must survive the rebuild below.\n\t\tconst idsAtRefreshStart = new Set(sessionManager.getEntries().map((entry) => entry.id));\n\t\tconst nextState = await transportCall(\"refresh\", () => client.getState());\n\t\tif (!nextState) return;\n\t\tstate = { ...stateFromRpc(nextState) };\n\t\tnextQueuedInputOrder = Math.max(0, ...nextState.ordered.map((item) => item.enqueueOrder));\n\t\tlet messages: AgentSession[\"messages\"];\n\t\tsettingsManager = SettingsManager.create(nextState.cwd, agentDir, {\n\t\t\tprojectTrusted: nextState.projectTrusted,\n\t\t});\n\t\tif (nextState.sessionFile) {\n\t\t\t// Keep the caller-owned manager identity when refreshing the same session.\n\t\t\t// Navigation and host-side mutations must update every existing mirror, not\n\t\t\t// leave the interactive runtime holding the pre-refresh snapshot.\n\t\t\tif (sessionManager.getSessionFile() === nextState.sessionFile) {\n\t\t\t\tsessionManager.reloadFromDisk?.();\n\t\t\t} else {\n\t\t\t\t// SessionManager.open retains the explicit path even when the host has\n\t\t\t\t// deferred creating the file for a setup-only session.\n\t\t\t\tsessionManager = SessionManager.open(nextState.sessionFile, undefined, nextState.cwd);\n\t\t\t}\n\t\t\t// The host ships its complete entry list while the session file is still\n\t\t\t// deferred (no assistant message yet, so nothing has been written), which\n\t\t\t// makes that list the only authoritative view of the session. Reconcile the\n\t\t\t// mirror to it exactly: `entry_appended` notifications that cross a\n\t\t\t// concurrent refresh land on whichever manager is current, so the mirror\n\t\t\t// can hold an arbitrary partial set rather than a prefix, and a snapshot\n\t\t\t// taken mid-bind can simply be short. Backfilling only an empty mirror\n\t\t\t// wedged it at whatever partial set it happened to hold.\n\t\t\tconst authoritative = nextState.entries;\n\t\t\tif (authoritative?.length) {\n\t\t\t\tconst mirror = sessionManager.getEntries();\n\t\t\t\tconst matches =\n\t\t\t\t\tmirror.length === authoritative.length &&\n\t\t\t\t\tmirror.every((entry, index) => entry.id === authoritative[index]?.id);\n\t\t\t\tif (!matches) {\n\t\t\t\t\tconst rebuilt = SessionManager.open(nextState.sessionFile, undefined, nextState.cwd);\n\t\t\t\t\tfor (const entry of authoritative) rebuilt.appendEntry(entry);\n\t\t\t\t\t// A notification that crossed this refresh refers to an entry the\n\t\t\t\t\t// snapshot predates, so it is newer than the snapshot; dropping it\n\t\t\t\t\t// would strand the entry until an unrelated refresh happened to\n\t\t\t\t\t// run. Keep it, in arrival order, after the authoritative list.\n\t\t\t\t\tconst authoritativeIds = new Set(authoritative.map((entry) => entry.id));\n\t\t\t\t\tfor (const entry of mirror) {\n\t\t\t\t\t\tif (!idsAtRefreshStart.has(entry.id) && !authoritativeIds.has(entry.id)) {\n\t\t\t\t\t\t\trebuilt.appendEntry(entry);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tsessionManager = rebuilt;\n\t\t\t\t}\n\t\t\t}\n\t\t\tmessages = sessionManager.buildSessionContext().messages;\n\t\t} else {\n\t\t\tmessages = await transportCall(\"refresh\", () => client.getMessages(), []);\n\t\t}\n\t\tlocal.agent.state.messages.splice(0, local.agent.state.messages.length, ...structuredClone(messages));\n\t\tstreamingAssistant = undefined;\n\t};\n\t// Refreshes must not interleave: each one reassigns sessionManager,\n\t// settingsManager and the mirrored message list, so two in flight can commit a\n\t// mixed snapshot of two different sessions. A replacement-driven refresh races\n\t// exactly that way against a caller-driven one, so run them in order.\n\tlet refreshChain: Promise<void> = Promise.resolve();\n\tconst refresh = (): Promise<void> => {\n\t\tconst next = refreshChain.then(performRefresh, performRefresh);\n\t\trefreshChain = next.then(\n\t\t\t() => {},\n\t\t\t() => {},\n\t\t);\n\t\treturn next;\n\t};\n\tconst session = new Proxy(local, {\n\t\tget(target, property, receiver) {\n\t\t\tif (property === \"prompt\")\n\t\t\t\treturn async (message: string, options?: Parameters<AgentSession[\"prompt\"]>[1]) => {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait client.prompt(message, {\n\t\t\t\t\t\t\t...(options?.images ? { images: options.images } : {}),\n\t\t\t\t\t\t\t...(options?.streamingBehavior ? { streamingBehavior: options.streamingBehavior } : {}),\n\t\t\t\t\t\t\t...(options?.thinkingLevel ? { thinkingLevel: options.thinkingLevel } : {}),\n\t\t\t\t\t\t\t...(options?.sessionTitlePrompt !== undefined\n\t\t\t\t\t\t\t\t? { sessionTitlePrompt: options.sessionTitlePrompt }\n\t\t\t\t\t\t\t\t: {}),\n\t\t\t\t\t\t\t...(options?.expandPromptTemplates !== undefined\n\t\t\t\t\t\t\t\t? { expandPromptTemplates: options.expandPromptTemplates }\n\t\t\t\t\t\t\t\t: {}),\n\t\t\t\t\t\t\t...(options?.promptDisposition ? { promptDisposition: options.promptDisposition } : {}),\n\t\t\t\t\t\t\t...(options?.preflightResult ? { preflightResult: options.preflightResult } : {}),\n\t\t\t\t\t\t});\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tif (!isTransportGoneError(error)) throw error;\n\t\t\t\t\t\treportActionFailure(\"prompt\")(error);\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\tif (property === \"abort\") return () => client.abort();\n\t\t\tif (property === \"abortCompaction\")\n\t\t\t\treturn () => void client.abortCompaction().catch(reportActionFailure(\"abortCompaction\"));\n\t\t\tif (property === \"steer\")\n\t\t\t\treturn (\n\t\t\t\t\tmessage: string,\n\t\t\t\t\timages?: Parameters<AgentSession[\"steer\"]>[1],\n\t\t\t\t\trecovery?: { enqueueOrder?: number },\n\t\t\t\t) => {\n\t\t\t\t\tconst enqueueOrder =\n\t\t\t\t\t\trecovery?.enqueueOrder ?? Math.max(0, ...state.ordered.map((item) => item.enqueueOrder)) + 1;\n\t\t\t\t\tstate = {\n\t\t\t\t\t\t...state,\n\t\t\t\t\t\tsteering: [...state.steering, message],\n\t\t\t\t\t\tordered: [...state.ordered, { text: message, mode: \"steer\", enqueueOrder }],\n\t\t\t\t\t\tpendingMessageCount: state.pendingMessageCount + 1,\n\t\t\t\t\t};\n\t\t\t\t\treturn transportCall(\"steer\", () => client.steer(message, images, { ...recovery, enqueueOrder }));\n\t\t\t\t};\n\t\t\tif (property === \"followUp\")\n\t\t\t\treturn (\n\t\t\t\t\tmessage: string,\n\t\t\t\t\timages?: Parameters<AgentSession[\"followUp\"]>[1],\n\t\t\t\t\trecovery?: { enqueueOrder?: number },\n\t\t\t\t) => {\n\t\t\t\t\tconst enqueueOrder =\n\t\t\t\t\t\trecovery?.enqueueOrder ?? Math.max(0, ...state.ordered.map((item) => item.enqueueOrder)) + 1;\n\t\t\t\t\tstate = {\n\t\t\t\t\t\t...state,\n\t\t\t\t\t\tfollowUp: [...state.followUp, message],\n\t\t\t\t\t\tordered: [...state.ordered, { text: message, mode: \"followUp\", enqueueOrder }],\n\t\t\t\t\t\tpendingMessageCount: state.pendingMessageCount + 1,\n\t\t\t\t\t};\n\t\t\t\t\treturn transportCall(\"followUp\", () => client.followUp(message, images, { ...recovery, enqueueOrder }));\n\t\t\t\t};\n\t\t\tif (property === \"waitForIdle\") return () => client.waitForIdle();\n\t\t\tif (property === \"getLastAssistantText\") return () => target.getLastAssistantText();\n\t\t\tif (property === \"setModel\" || property === \"setSessionModel\")\n\t\t\t\treturn async (model: NonNullable<AgentSession[\"model\"]>) => {\n\t\t\t\t\tconst next = await transportCall(\"setModel\", () => client.setModel(model.provider, model.id), undefined);\n\t\t\t\t\treturn next ? { systemPromptName: next.systemPromptName, model: next } : undefined;\n\t\t\t\t};\n\t\t\tif (property === \"setSessionThinkingLevel\")\n\t\t\t\treturn (level: AgentSession[\"thinkingLevel\"]) =>\n\t\t\t\t\tvoid client\n\t\t\t\t\t\t.setThinkingLevel(level, { scope: \"turn\" })\n\t\t\t\t\t\t.catch(reportActionFailure(\"setSessionThinkingLevel\"));\n\t\t\tif (property === \"setSessionFastMode\")\n\t\t\t\treturn (enabled: boolean) =>\n\t\t\t\t\tvoid client.setFastMode(enabled).catch(reportActionFailure(\"setSessionFastMode\"));\n\t\t\tif (property === \"abortRetry\") return () => void client.abortRetry().catch(reportActionFailure(\"abortRetry\"));\n\t\t\tif (property === \"setAutoRetryEnabled\")\n\t\t\t\treturn (enabled: boolean) =>\n\t\t\t\t\tvoid client.setAutoRetry(enabled).catch(reportActionFailure(\"setAutoRetryEnabled\"));\n\t\t\tif (property === \"reserveQueuedInputOrder\") return () => ++nextQueuedInputOrder;\n\t\t\tif (property === \"setFavoriteModels\")\n\t\t\t\treturn (models: Parameters<AgentSession[\"setFavoriteModels\"]>[0]) => {\n\t\t\t\t\tstate = { ...state, favoriteModels: [...models] };\n\t\t\t\t\tvoid client.setFavoriteModels(models).catch(reportActionFailure(\"setFavoriteModels\"));\n\t\t\t\t};\n\t\t\tif (property === \"setScopedModels\")\n\t\t\t\treturn (models: Parameters<AgentSession[\"setScopedModels\"]>[0]) => {\n\t\t\t\t\tstate = { ...state, scopedModels: [...models] };\n\t\t\t\t\tvoid client.setScopedModels(models).catch(reportActionFailure(\"setScopedModels\"));\n\t\t\t\t};\n\t\t\tif (property === \"cycleModel\")\n\t\t\t\treturn (direction?: \"forward\" | \"backward\") =>\n\t\t\t\t\ttransportCall(\"cycleModel\", () => client.cycleModel(direction), undefined);\n\t\t\tif (property === \"setThinkingLevel\")\n\t\t\t\treturn (level: AgentSession[\"thinkingLevel\"]) =>\n\t\t\t\t\tvoid client.setThinkingLevel(level).catch(reportActionFailure(\"setThinkingLevel\"));\n\t\t\tif (property === \"cycleThinkingLevel\")\n\t\t\t\treturn () =>\n\t\t\t\t\ttransportCall(\"cycleThinkingLevel\", () => client.cycleThinkingLevel(), undefined).then(\n\t\t\t\t\t\t(result) => result?.level,\n\t\t\t\t\t);\n\t\t\tif (property === \"getAvailableThinkingLevels\")\n\t\t\t\treturn () => transportCall(\"getAvailableThinkingLevels\", () => client.getAvailableThinkingLevels(), []);\n\t\t\tif (property === \"setSteeringMode\")\n\t\t\t\treturn (mode: AgentSession[\"steeringMode\"]) =>\n\t\t\t\t\tvoid client.setSteeringMode(mode).catch(reportActionFailure(\"setSteeringMode\"));\n\t\t\tif (property === \"setFollowUpMode\")\n\t\t\t\treturn (mode: AgentSession[\"followUpMode\"]) =>\n\t\t\t\t\tvoid client.setFollowUpMode(mode).catch(reportActionFailure(\"setFollowUpMode\"));\n\t\t\tif (property === \"compact\")\n\t\t\t\treturn (instructions?: string) => transportCall(\"compact\", () => client.compact(instructions));\n\t\t\tif (property === \"setAutoCompactionEnabled\")\n\t\t\t\treturn (enabled: boolean) =>\n\t\t\t\t\tvoid client.setAutoCompaction(enabled).catch(reportActionFailure(\"setAutoCompaction\"));\n\t\t\tif (property === \"executeBash\")\n\t\t\t\treturn async (\n\t\t\t\t\tcommand: string,\n\t\t\t\t\tonChunk?: (chunk: string) => void | PromiseLike<void>,\n\t\t\t\t\toptions?: { excludeFromContext?: boolean; operations?: BashOperations | Record<string, unknown> },\n\t\t\t\t) => {\n\t\t\t\t\tif (options?.operations && typeof options.operations.exec === \"function\") {\n\t\t\t\t\t\tconst abortController = new AbortController();\n\t\t\t\t\t\tlocalBashAbortController = abortController;\n\t\t\t\t\t\tlocalBashRunning = true;\n\t\t\t\t\t\tupdateBashState();\n\t\t\t\t\t\tconst sessionAtStart = state.sessionId;\n\t\t\t\t\t\tconst prefix = settingsManager.getShellCommandPrefix();\n\t\t\t\t\t\tconst resolvedCommand = prefix ? `${prefix}\\n${command}` : command;\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tconst result = await executeBashWithOperations(\n\t\t\t\t\t\t\t\tresolvedCommand,\n\t\t\t\t\t\t\t\tstate.cwd,\n\t\t\t\t\t\t\t\toptions.operations as BashOperations,\n\t\t\t\t\t\t\t\t{ onChunk, signal: abortController.signal },\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tif (state.sessionId === sessionAtStart) {\n\t\t\t\t\t\t\t\tawait transportCall(\"recordBashResult\", () =>\n\t\t\t\t\t\t\t\t\tclient.recordBashResult(command, result, options.excludeFromContext),\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn result;\n\t\t\t\t\t\t} finally {\n\t\t\t\t\t\t\tlocalBashAbortController = undefined;\n\t\t\t\t\t\t\tlocalBashRunning = false;\n\t\t\t\t\t\t\tupdateBashState();\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tconst executionId = `bash-${executionNamespace}-${++nextBashExecutionId}`;\n\t\t\t\t\tconst execution = {\n\t\t\t\t\t\tchunk: onChunk,\n\t\t\t\t\t\tpromises: new Set<Promise<void>>(),\n\t\t\t\t\t\terror: undefined as unknown,\n\t\t\t\t\t\thasError: false,\n\t\t\t\t\t};\n\t\t\t\t\tbashExecutions.set(executionId, execution);\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst result = await transportCall(\n\t\t\t\t\t\t\t\"bash\",\n\t\t\t\t\t\t\t() =>\n\t\t\t\t\t\t\t\tclient.bash(command, {\n\t\t\t\t\t\t\t\t\texcludeFromContext: options?.excludeFromContext,\n\t\t\t\t\t\t\t\t\texecutionId,\n\t\t\t\t\t\t\t\t\toperations: options?.operations as Record<string, unknown> | undefined,\n\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t{ output: \"\", exitCode: undefined, cancelled: true, truncated: false },\n\t\t\t\t\t\t);\n\t\t\t\t\t\tconst callbacksSettled = await waitForBashCallbacks(execution.promises, false);\n\t\t\t\t\t\tif (!callbacksSettled) {\n\t\t\t\t\t\t\tif (result.fullOutputPath) await cleanupRemoteBashOutput(result.fullOutputPath);\n\t\t\t\t\t\t\tthrow new Error(\"Bash output callback did not settle within 5000ms\");\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (execution.hasError) {\n\t\t\t\t\t\t\tif (result.fullOutputPath) await cleanupRemoteBashOutput(result.fullOutputPath);\n\t\t\t\t\t\t\tthrow execution.error;\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn result;\n\t\t\t\t\t} finally {\n\t\t\t\t\t\tbashExecutions.delete(executionId);\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\tif (property === \"abortBash\")\n\t\t\t\treturn () => {\n\t\t\t\t\tif (localBashAbortController) localBashAbortController.abort();\n\t\t\t\t\telse void client.abortBash().catch(reportActionFailure(\"abortBash\"));\n\t\t\t\t};\n\t\t\tif (property === \"getContextUsage\") return () => state.contextUsage;\n\t\t\tif (property === \"getSessionStats\")\n\t\t\t\treturn () => transportCall(\"getSessionStats\", () => client.getSessionStats(), local.getSessionStats());\n\t\t\tif (property === \"exportToHtml\")\n\t\t\t\treturn (outputPath?: string, options?: { themeName?: string }) =>\n\t\t\t\t\ttransportCall(\"exportToHtml\", () => client.exportHtml(outputPath, options?.themeName)).then(\n\t\t\t\t\t\t(result) => result?.path,\n\t\t\t\t\t);\n\t\t\tif (property === \"setSessionName\")\n\t\t\t\treturn (name: string) => client.setSessionName(name).catch(reportActionFailure(\"setSessionName\"));\n\t\t\tif (property === \"navigateTree\")\n\t\t\t\treturn async (targetId: string, options?: Parameters<AgentSession[\"navigateTree\"]>[1]) => {\n\t\t\t\t\tconst result = await transportCall(\"navigateTree\", () => client.navigateTree(targetId, options), {\n\t\t\t\t\t\tcancelled: true,\n\t\t\t\t\t});\n\t\t\t\t\tif (!result.cancelled) await refresh();\n\t\t\t\t\treturn result;\n\t\t\t\t};\n\t\t\tif (property === \"getUserMessagesForForking\")\n\t\t\t\treturn () => transportCall(\"getUserMessagesForForking\", () => client.getForkMessages(), []);\n\t\t\tif (property === \"subscribe\")\n\t\t\t\treturn (listener: AgentSessionEventListener) => {\n\t\t\t\t\tlisteners.add(listener);\n\t\t\t\t\tconst localUnsubscribe = target.subscribe(listener);\n\t\t\t\t\treturn () => {\n\t\t\t\t\t\tlisteners.delete(listener);\n\t\t\t\t\t\tlocalUnsubscribe();\n\t\t\t\t\t};\n\t\t\t\t};\n\t\t\tif (property === \"isStreaming\") return state.isStreaming;\n\t\t\tif (property === \"isIdle\") return !state.isStreaming;\n\t\t\tif (property === \"isCompacting\") return state.isCompacting;\n\t\t\tif (property === \"pendingMessageCount\") return state.pendingMessageCount;\n\t\t\tif (property === \"getSteeringMessages\") return () => state.steering;\n\t\t\tif (property === \"getFollowUpMessages\") return () => state.followUp;\n\t\t\tif (property === \"clearQueue\")\n\t\t\t\treturn (options?: { abortWillFollow: boolean }) => {\n\t\t\t\t\tconst result = {\n\t\t\t\t\t\tsteering: [...state.steering],\n\t\t\t\t\t\tfollowUp: [...state.followUp],\n\t\t\t\t\t\tordered: [...state.ordered],\n\t\t\t\t\t};\n\t\t\t\t\tObject.defineProperty(result, \"ordered\", { value: result.ordered, enumerable: false });\n\t\t\t\t\tvoid client.clearQueue(options).catch(reportActionFailure(\"clearQueue\"));\n\t\t\t\t\treturn result;\n\t\t\t\t};\n\t\t\tif (property === \"abortBranchSummary\")\n\t\t\t\treturn () => void client.abortBranchSummary().catch(reportActionFailure(\"abortBranchSummary\"));\n\t\t\tif (property === \"recordBashResult\")\n\t\t\t\treturn (\n\t\t\t\t\tcommand: string,\n\t\t\t\t\tresult: Parameters<AgentSession[\"recordBashResult\"]>[1],\n\t\t\t\t\toptions?: { excludeFromContext?: boolean },\n\t\t\t\t) =>\n\t\t\t\t\tvoid client\n\t\t\t\t\t\t.recordBashResult(command, result, options?.excludeFromContext)\n\t\t\t\t\t\t.catch(reportActionFailure(\"recordBashResult\"));\n\t\t\tif (property === \"set_label\") return undefined;\n\t\t\tif (property === \"retryAttempt\") return state.retryAttempt;\n\t\t\tif (property === \"isBashRunning\") return state.isBashRunning;\n\t\t\tif (property === \"reload\")\n\t\t\t\treturn (_options?: Parameters<AgentSession[\"reload\"]>[0]) =>\n\t\t\t\t\ttransportCall(\"reload\", () => client.reload(), { cancelled: true });\n\t\t\tif (property === \"checkReloadVeto\")\n\t\t\t\treturn () => transportCall(\"checkReloadVeto\", () => client.checkReloadVeto(), { cancelled: true });\n\t\t\tif (property === \"exportToJsonl\")\n\t\t\t\treturn (outputPath?: string) =>\n\t\t\t\t\ttransportCall(\"exportToJsonl\", () => client.exportJsonl(outputPath)).then((result) => result?.path);\n\t\t\t// The footer and other renderers read session.state.*; surface the\n\t\t\t// host-authoritative fields there too, not only via the direct getters.\n\t\t\tif (property === \"state\") {\n\t\t\t\tconst localState = target.state;\n\t\t\t\treturn {\n\t\t\t\t\t...localState,\n\t\t\t\t\tmodel: state.model ?? localState.model,\n\t\t\t\t\tthinkingLevel: state.thinkingLevel,\n\t\t\t\t\tisStreaming: state.isStreaming,\n\t\t\t\t\tisCompacting: state.isCompacting,\n\t\t\t\t};\n\t\t\t}\n\t\t\tif (property === \"sessionFile\") return state.sessionFile;\n\t\t\tif (property === \"sessionId\") return state.sessionId;\n\t\t\tif (property === \"sessionName\") return state.sessionName;\n\t\t\tif (property === \"serviceTier\") return state.serviceTier;\n\t\t\tif (property === \"steeringMode\") return state.steeringMode;\n\t\t\tif (property === \"followUpMode\") return state.followUpMode;\n\t\t\tif (property === \"autoCompactionEnabled\") return state.autoCompactionEnabled;\n\t\t\tif (property === \"isFastModeActive\") return () => state.fastMode;\n\t\t\tif (property === \"sessionManager\") return remoteSessionManager;\n\t\t\tif (property === \"settingsManager\") return settingsManager;\n\t\t\tif (property === \"messages\") return target.messages;\n\t\t\tif (property === \"favoriteModels\") return state.favoriteModels;\n\t\t\tif (property === \"scopedModels\") return state.scopedModels;\n\t\t\tif (property === \"model\") return state.model ?? target.model;\n\t\t\tif (property === \"thinkingLevel\") return state.thinkingLevel;\n\t\t\treturn Reflect.get(target, property, receiver);\n\t\t},\n\t});\n\treturn {\n\t\tsession,\n\t\tsetHostUiHandler: (callback) => {\n\t\t\thostUiHandler = callback;\n\t\t\tif (callback)\n\t\t\t\tfor (const request of pendingUiRequests.splice(0))\n\t\t\t\t\tvoid Promise.resolve(callback(request))\n\t\t\t\t\t\t.then((response) => response && client.sendExtensionUIResponse(response))\n\t\t\t\t\t\t.catch(reportActionFailure(\"host UI response\"));\n\t\t},\n\t\trefresh,\n\t\taroundLocalReplacement: async (body) => {\n\t\t\tlocalReplacementDepth++;\n\t\t\ttry {\n\t\t\t\treturn await body();\n\t\t\t} finally {\n\t\t\t\tlocalReplacementDepth--;\n\t\t\t}\n\t\t},\n\t\tabortLocalBash: () => localBashAbortController?.abort(),\n\t\tcreateReplacedSessionContext: () => {\n\t\t\tconst context = local.createReplacedSessionContext();\n\t\t\tObject.defineProperty(context, \"cwd\", { value: state.cwd });\n\t\t\tObject.defineProperty(context, \"sessionManager\", { value: remoteSessionManager });\n\t\t\tcontext.sendMessage = (message, options) =>\n\t\t\t\ttransportCall(\"sendMessage\", () =>\n\t\t\t\t\tclient.sendCustomMessage(message, {\n\t\t\t\t\t\ttriggerTurn: options?.triggerTurn,\n\t\t\t\t\t\tdeliverAs: options?.deliverAs,\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\tcontext.sendUserMessage = (content, options) => {\n\t\t\t\tif (typeof content === \"string\")\n\t\t\t\t\treturn transportCall(\"sendUserMessage\", () =>\n\t\t\t\t\t\tclient.prompt(content, {\n\t\t\t\t\t\t\tstreamingBehavior: options?.deliverAs,\n\t\t\t\t\t\t\texpandPromptTemplates: options?.expandPromptTemplates,\n\t\t\t\t\t\t}),\n\t\t\t\t\t);\n\t\t\t\tconst text = content\n\t\t\t\t\t.filter((part) => part.type === \"text\")\n\t\t\t\t\t.map((part) => part.text)\n\t\t\t\t\t.join(\"\\n\");\n\t\t\t\tconst images = content.filter((part) => part.type === \"image\");\n\t\t\t\treturn transportCall(\"sendUserMessage\", () =>\n\t\t\t\t\tclient.prompt(text, {\n\t\t\t\t\t\timages,\n\t\t\t\t\t\tstreamingBehavior: options?.deliverAs,\n\t\t\t\t\t\texpandPromptTemplates: options?.expandPromptTemplates,\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t};\n\t\t\treturn context;\n\t\t},\n\t};\n}\n\nfunction hydrateMessageUpdate(\n\tevent: RpcClientEvent,\n\tstreamingAssistant: Extract<AgentSession[\"messages\"][number], { role: \"assistant\" }> | undefined,\n): AgentSessionEvent {\n\tif (event.type !== \"message_update\" || !streamingAssistant) return event as unknown as AgentSessionEvent;\n\tconst update = event.assistantMessageEvent;\n\tif (update.type !== \"text_delta\" && update.type !== \"thinking_delta\" && update.type !== \"toolcall_delta\") {\n\t\treturn event as unknown as AgentSessionEvent;\n\t}\n\tconst content = streamingAssistant.content[update.contentIndex];\n\tif (update.type === \"text_delta\" && content?.type === \"text\") content.text += update.delta;\n\tif (update.type === \"thinking_delta\" && content?.type === \"thinking\") content.thinking += update.delta;\n\tif (update.type === \"toolcall_delta\" && content?.type === \"toolCall\") {\n\t\tconst raw = JSON.stringify(content.arguments) + update.delta;\n\t\ttry {\n\t\t\tconst parsed: unknown = JSON.parse(raw);\n\t\t\tif (typeof parsed === \"object\" && parsed !== null && !Array.isArray(parsed)) {\n\t\t\t\tcontent.arguments = parsed as Record<string, unknown>;\n\t\t\t}\n\t\t} catch {\n\t\t\t// Keep the last valid arguments until the next complete update.\n\t\t}\n\t}\n\tstreamingAssistant.usage = event.usage;\n\treturn {\n\t\ttype: \"message_update\",\n\t\tmessage: structuredClone(streamingAssistant),\n\t\tassistantMessageEvent: { ...update, partial: structuredClone(streamingAssistant) },\n\t} as AgentSessionEvent;\n}\n\nfunction stateFromRpc(state: {\n\tmodel?: AgentSession[\"model\"];\n\tthinkingLevel: AgentSession[\"thinkingLevel\"];\n\tisStreaming: boolean;\n\tisCompacting: boolean;\n\tpendingMessageCount: number;\n\tusageTotals: import(\"../../core/session-manager.ts\").UsageTotals;\n\tcontextUsage?: import(\"../../core/extensions/types.ts\").ContextUsage;\n\tretryAttempt: number;\n\tisBashRunning: boolean;\n\tsessionFile?: string;\n\tsessionId: string;\n\tsessionName?: string;\n\tcwd: string;\n\tprojectTrusted: boolean;\n\tserviceTier?: AgentSession[\"serviceTier\"];\n\tfastMode: boolean;\n\tsteeringMode: AgentSession[\"steeringMode\"];\n\tfollowUpMode: AgentSession[\"followUpMode\"];\n\tautoCompactionEnabled: boolean;\n\tentries?: import(\"../../core/session-manager.ts\").SessionEntry[];\n\tfavoriteModels: import(\"../rpc/rpc-types.ts\").RpcSessionModelEntry[];\n\tscopedModels: import(\"../rpc/rpc-types.ts\").RpcSessionModelEntry[];\n\tsteering: string[];\n\tfollowUp: string[];\n\tordered: Array<{ text: string; mode: \"steer\" | \"followUp\"; enqueueOrder: number }>;\n}) {\n\treturn state;\n}\n\nexport function isInteractiveHostEvent(event: RpcClientEvent): event is Extract<RpcClientEvent, { type: string }> {\n\treturn typeof event === \"object\" && event !== null && \"type\" in event;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"connection-handler.d.ts","sourceRoot":"","sources":["../../../src/modes/rpc/connection-handler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAOH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AAC7E,OAAO,KAAK,EAAE,YAAY,EAAqB,MAAM,6BAA6B,CAAC;AACnF,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;AAyC/E,OAAO,KAAK,EAYX,eAAe,EAEf,MAAM,gBAAgB,CAAC;AAGxB,kFAAkF;AAClF,MAAM,WAAW,oBAAoB;IACpC,mFAAmF;IACnF,YAAY,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACjC,iFAAiF;IACjF,eAAe,CAAC,EAAE,MAAM,IAAI,CAAC;IAC7B,0DAA0D;IAC1D,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,kFAAkF;IAClF,SAAS,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IACjC,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACrC;AAED,MAAM,WAAW,oBAAoB;IACpC;;;OAGG;IACH,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9B,sEAAsE;IACtE,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7C;;;OAGG;IACH,mBAAmB,IAAI,OAAO,CAAC;IAC/B,4EAA4E;IAC5E,gCAAgC,IAAI,IAAI,CAAC;IACzC,iFAAiF;IACjF,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,C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AC,CAAC;IAC7C;;;OAGG;IACH,mBAAmB,IAAI,OAAO,CAAC;IAC/B,4EAA4E;IAC5E,gCAAgC,IAAI,IAAI,CAAC;IACzC,iFAAiF;IACjF,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACzB;AA4BD;;;;;;;;;;GAUG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,YAAY,EAAE,eAAe,CAAC,EAAE,gBAAgB,GAAG,eAAe,CAkD/G;AA4BD;;;;;;GAMG;AACH,wBAAgB,0BAA0B,CACzC,WAAW,EAAE,mBAAmB,EAChC,IAAI,EAAE,iBAAiB,EACvB,OAAO,GAAE,oBAAyB,GAChC,oBAAoB,CAyvCtB"}
@@ -512,6 +512,17 @@ export function createRpcConnectionHandler(runtimeHost, sink, options = {}) {
512
512
  })
513
513
  : undefined;
514
514
  subscribeLoadedSurfaceEvents();
515
+ // Subscribe to the replaced session before its bind runs, not after. The bind
516
+ // is deferred by design - awaiting it would deadlock a client whose
517
+ // session_start handler blocks on an extension_ui_request it cannot answer
518
+ // while still awaiting the replacement response - and it still mutates the
519
+ // session it owns: pi-rules appends a durable scan entry from session_start.
520
+ // Those entries must reach every attached connection, and nothing else can
521
+ // carry them, because the session file is not written until an assistant
522
+ // message exists, so a client that misses the notification can never
523
+ // reconstruct the session it is bound to. Installing here also drops the
524
+ // previous session's subscription immediately instead of after the bind.
525
+ installSessionSubscriptions();
515
526
  const refresh = refreshLoadedSurfacesAfter(() => session.bindExtensions({
516
527
  uiContext: createExtensionUIContext(),
517
528
  mode: "rpc",
@@ -557,7 +568,7 @@ export function createRpcConnectionHandler(runtimeHost, sink, options = {}) {
557
568
  });
558
569
  },
559
570
  }), true);
560
- const installSessionSubscriptions = () => {
571
+ function installSessionSubscriptions() {
561
572
  unsubscribe?.();
562
573
  unsubscribeBackpressure?.();
563
574
  unsubscribe = session.subscribe((event) => {
@@ -592,15 +603,17 @@ export function createRpcConnectionHandler(runtimeHost, sink, options = {}) {
592
603
  unsubscribeBackpressure = session.agent.subscribe(async () => {
593
604
  await waitForRpcBackpressure();
594
605
  });
595
- };
606
+ }
596
607
  if (deferRefresh) {
597
- void refresh.then(installSessionSubscriptions, (cause) => {
608
+ // The subscription is already installed on the replaced session above, so
609
+ // the deferred refresh only needs its failure reported. Re-installing here
610
+ // would replay the settings-source selection a second time.
611
+ void refresh.catch((cause) => {
598
612
  outputEvent({ type: "rpc_error", error: String(cause) });
599
613
  });
600
614
  return;
601
615
  }
602
616
  await refresh;
603
- installSessionSubscriptions();
604
617
  };
605
618
  /**
606
619
  * Drive an OAuth login for one provider as fire-command-then-subscribe.