@bastani/atomic 0.9.14-alpha.3 → 0.9.14-alpha.5

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 (150) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/dist/builtin/intercom/package.json +1 -1
  3. package/dist/builtin/mcp/package.json +1 -1
  4. package/dist/builtin/subagents/CHANGELOG.md +6 -0
  5. package/dist/builtin/subagents/package.json +1 -1
  6. package/dist/builtin/subagents/src/extension/schemas.ts +5 -0
  7. package/dist/builtin/subagents/src/runs/shared/long-running-guard.ts +3 -1
  8. package/dist/builtin/subagents/src/runs/shared/progress-trend.ts +69 -0
  9. package/dist/builtin/subagents/src/runs/shared/subagent-control.ts +12 -1
  10. package/dist/builtin/subagents/src/shared/types-results.ts +2 -0
  11. package/dist/builtin/web-access/CHANGELOG.md +10 -0
  12. package/dist/builtin/web-access/README.md +3 -6
  13. package/dist/builtin/web-access/index.ts +1 -2
  14. package/dist/builtin/web-access/package.json +1 -1
  15. package/dist/builtin/web-access/web-search-config.ts +2 -8
  16. package/dist/builtin/web-access/web-search-tool.ts +2 -7
  17. package/dist/builtin/web-access/web-search-workflow.ts +10 -0
  18. package/dist/builtin/workflows/CHANGELOG.md +46 -0
  19. package/dist/builtin/workflows/README.md +6 -5
  20. package/dist/builtin/workflows/builtin/adversarial-verification-prompts.ts +13 -5
  21. package/dist/builtin/workflows/builtin/adversarial-verification-runner.ts +376 -89
  22. package/dist/builtin/workflows/builtin/adversarial-verification.d.ts +30 -6
  23. package/dist/builtin/workflows/builtin/adversarial-verification.ts +14 -9
  24. package/dist/builtin/workflows/builtin/generate-and-filter-prompts.ts +26 -3
  25. package/dist/builtin/workflows/builtin/generate-and-filter-runner.ts +18 -14
  26. package/dist/builtin/workflows/builtin/goal-artifacts.ts +9 -8
  27. package/dist/builtin/workflows/builtin/goal-convergence.ts +87 -0
  28. package/dist/builtin/workflows/builtin/goal-ledger.ts +4 -0
  29. package/dist/builtin/workflows/builtin/goal-prompts.ts +2 -0
  30. package/dist/builtin/workflows/builtin/goal-reducer.ts +6 -1
  31. package/dist/builtin/workflows/builtin/goal-reverify.ts +305 -0
  32. package/dist/builtin/workflows/builtin/goal-runner.ts +75 -10
  33. package/dist/builtin/workflows/builtin/goal-schemas.ts +7 -0
  34. package/dist/builtin/workflows/builtin/goal-types.ts +6 -0
  35. package/dist/builtin/workflows/builtin/loop-until-done-runner.ts +94 -6
  36. package/dist/builtin/workflows/builtin/loop-until-done.d.ts +8 -0
  37. package/dist/builtin/workflows/builtin/loop-until-done.ts +15 -0
  38. package/dist/builtin/workflows/builtin/progress-scoring.ts +230 -0
  39. package/dist/builtin/workflows/builtin/ralph-core.ts +11 -0
  40. package/dist/builtin/workflows/builtin/ralph-review-gate.ts +1 -0
  41. package/dist/builtin/workflows/builtin/ralph-reviewer-prompt.ts +2 -0
  42. package/dist/builtin/workflows/builtin/ralph-runner.ts +60 -10
  43. package/dist/builtin/workflows/builtin/selection-math.ts +156 -0
  44. package/dist/builtin/workflows/builtin/shared-prompts.ts +5 -0
  45. package/dist/builtin/workflows/builtin/tournament-prompts.ts +57 -75
  46. package/dist/builtin/workflows/builtin/tournament-runner.ts +384 -178
  47. package/dist/builtin/workflows/builtin/tournament.d.ts +46 -17
  48. package/dist/builtin/workflows/builtin/tournament.ts +66 -32
  49. package/dist/builtin/workflows/builtin/verification-criteria.ts +330 -0
  50. package/dist/builtin/workflows/builtin/verification-prompts.ts +206 -0
  51. package/dist/builtin/workflows/builtin/verification-usage.ts +44 -0
  52. package/dist/builtin/workflows/package.json +1 -1
  53. package/dist/builtin/workflows/skills/create-spec/SKILL.md +90 -30
  54. package/dist/builtin/workflows/skills/show-me/LICENSE.txt +21 -0
  55. package/dist/builtin/workflows/skills/show-me/SKILL.md +143 -0
  56. package/dist/builtin/workflows/src/authoring/workflow.ts +8 -0
  57. package/dist/builtin/workflows/src/authoring.d.ts +1 -1
  58. package/dist/builtin/workflows/src/durable/completed-catalog.ts +5 -2
  59. package/dist/builtin/workflows/src/durable/dbos-envelope.ts +1 -1
  60. package/dist/builtin/workflows/src/durable/resume-eligibility.ts +5 -3
  61. package/dist/builtin/workflows/src/durable/run-timing.ts +41 -10
  62. package/dist/builtin/workflows/src/durable/tool-primitive.ts +24 -2
  63. package/dist/builtin/workflows/src/engine/options.ts +1 -0
  64. package/dist/builtin/workflows/src/engine/primitives/workflow.ts +12 -3
  65. package/dist/builtin/workflows/src/engine/run-budget.ts +308 -0
  66. package/dist/builtin/workflows/src/engine/run-returned-status.ts +8 -0
  67. package/dist/builtin/workflows/src/engine/run-tool-node-lifecycle.ts +6 -0
  68. package/dist/builtin/workflows/src/engine/run.ts +124 -2
  69. package/dist/builtin/workflows/src/engine/runtime.ts +9 -0
  70. package/dist/builtin/workflows/src/extension/config-file-loader.ts +6 -0
  71. package/dist/builtin/workflows/src/extension/config-loader.ts +24 -1
  72. package/dist/builtin/workflows/src/extension/dispatcher.ts +6 -5
  73. package/dist/builtin/workflows/src/extension/extension-runtime-state.ts +2 -0
  74. package/dist/builtin/workflows/src/extension/index.bundle.mjs +3033 -872
  75. package/dist/builtin/workflows/src/extension/lifecycle-notifications.ts +51 -4
  76. package/dist/builtin/workflows/src/extension/public-types.ts +3 -1
  77. package/dist/builtin/workflows/src/extension/runtime-durable-resume.ts +7 -1
  78. package/dist/builtin/workflows/src/extension/runtime.ts +22 -10
  79. package/dist/builtin/workflows/src/extension/workflow-module-loader.ts +5 -0
  80. package/dist/builtin/workflows/src/extension/workflow-prompts.ts +1 -0
  81. package/dist/builtin/workflows/src/extension/workflow-schema.ts +16 -0
  82. package/dist/builtin/workflows/src/extension/workflow-status-summary.ts +44 -1
  83. package/dist/builtin/workflows/src/extension/workflow-tool-content.ts +10 -1
  84. package/dist/builtin/workflows/src/extension/workflow-tool-control.ts +21 -9
  85. package/dist/builtin/workflows/src/runs/foreground/executor-continuation.ts +14 -0
  86. package/dist/builtin/workflows/src/runs/foreground/executor-lifecycle.ts +15 -4
  87. package/dist/builtin/workflows/src/runs/foreground/executor-stage-call.ts +62 -5
  88. package/dist/builtin/workflows/src/runs/foreground/executor-stage-factory.ts +4 -0
  89. package/dist/builtin/workflows/src/runs/foreground/executor-stage-types.ts +2 -0
  90. package/dist/builtin/workflows/src/runs/foreground/executor-types.ts +3 -1
  91. package/dist/builtin/workflows/src/runs/foreground/stage-runner-controller.ts +10 -1
  92. package/dist/builtin/workflows/src/shared/authoring-contract-stage.d.ts +1 -0
  93. package/dist/builtin/workflows/src/shared/authoring-contract-stage.ts +1 -0
  94. package/dist/builtin/workflows/src/shared/authoring-contract-ui.d.ts +7 -0
  95. package/dist/builtin/workflows/src/shared/authoring-contract-ui.ts +7 -0
  96. package/dist/builtin/workflows/src/shared/authoring-contract.d.ts +1 -0
  97. package/dist/builtin/workflows/src/shared/budget-meter.ts +34 -0
  98. package/dist/builtin/workflows/src/shared/budget.d.ts +67 -0
  99. package/dist/builtin/workflows/src/shared/budget.ts +127 -0
  100. package/dist/builtin/workflows/src/shared/persistence-restore-helpers.ts +92 -8
  101. package/dist/builtin/workflows/src/shared/persistence-restore.ts +11 -1
  102. package/dist/builtin/workflows/src/shared/persistence-session-entries.ts +15 -3
  103. package/dist/builtin/workflows/src/shared/returned-run-status.ts +35 -2
  104. package/dist/builtin/workflows/src/shared/store-public-types.ts +4 -1
  105. package/dist/builtin/workflows/src/shared/store-run-methods.ts +8 -1
  106. package/dist/builtin/workflows/src/shared/store-stage-methods.ts +1 -0
  107. package/dist/builtin/workflows/src/shared/store-types.ts +24 -0
  108. package/dist/builtin/workflows/src/shared/types.ts +3 -0
  109. package/dist/builtin/workflows/src/shared/workflow-artifacts.ts +1 -0
  110. package/dist/builtin/workflows/src/shared/workflow-authoring-types.d.ts +3 -0
  111. package/dist/builtin/workflows/src/shared/workflow-authoring-types.ts +3 -0
  112. package/dist/builtin/workflows/src/tui/graph-theme.ts +11 -0
  113. package/dist/builtin/workflows/src/tui/graph-view-render.ts +19 -10
  114. package/dist/builtin/workflows/src/tui/tool-detail.ts +45 -26
  115. package/dist/core/atomic-guide-command.d.ts.map +1 -1
  116. package/dist/core/atomic-guide-command.js +1 -0
  117. package/dist/core/atomic-guide-command.js.map +1 -1
  118. package/dist/core/extensions/ui-types.d.ts +13 -3
  119. package/dist/core/extensions/ui-types.d.ts.map +1 -1
  120. package/dist/core/extensions/ui-types.js +15 -3
  121. package/dist/core/extensions/ui-types.js.map +1 -1
  122. package/dist/core/slash-commands.d.ts.map +1 -1
  123. package/dist/core/slash-commands.js +33 -3
  124. package/dist/core/slash-commands.js.map +1 -1
  125. package/dist/main-deferred-startup.d.ts.map +1 -1
  126. package/dist/main-deferred-startup.js +6 -2
  127. package/dist/main-deferred-startup.js.map +1 -1
  128. package/dist/modes/interactive/interactive-startup.js +4 -0
  129. package/dist/modes/interactive/interactive-startup.js.map +1 -1
  130. package/dist/modes/interactive/interactive-tui.d.ts.map +1 -1
  131. package/dist/modes/interactive/interactive-tui.js +19 -1
  132. package/dist/modes/interactive/interactive-tui.js.map +1 -1
  133. package/dist/modes/interactive-engine/isolated-runtime.d.ts +7 -0
  134. package/dist/modes/interactive-engine/isolated-runtime.d.ts.map +1 -1
  135. package/dist/modes/interactive-engine/isolated-runtime.js +94 -37
  136. package/dist/modes/interactive-engine/isolated-runtime.js.map +1 -1
  137. package/dist/modes/rpc/rpc-client.d.ts +1 -0
  138. package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
  139. package/dist/modes/rpc/rpc-client.js +15 -2
  140. package/dist/modes/rpc/rpc-client.js.map +1 -1
  141. package/dist/modes/rpc/rpc-input-scheduler.d.ts +3 -2
  142. package/dist/modes/rpc/rpc-input-scheduler.d.ts.map +1 -1
  143. package/dist/modes/rpc/rpc-input-scheduler.js +5 -2
  144. package/dist/modes/rpc/rpc-input-scheduler.js.map +1 -1
  145. package/docs/extensions.md +1 -1
  146. package/docs/quickstart.md +1 -0
  147. package/docs/skills.md +4 -0
  148. package/docs/workflows.md +75 -11
  149. package/npm-shrinkwrap.json +29 -29
  150. package/package.json +2 -2
@@ -1 +1 @@
1
- {"version":3,"file":"isolated-runtime.js","sourceRoot":"","sources":["../../../src/modes/interactive-engine/isolated-runtime.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAyC,MAAM,qCAAqC,CAAC;AAGjH,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAa/D,OAAO,EAAiC,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAC3F,OAAO,EAAkC,0BAA0B,EAAE,MAAM,oBAAoB,CAAC;AAEhG,OAAO,EAAE,oBAAoB,EAA+B,MAAM,6BAA6B,CAAC;AAChG,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D;;;;;;GAMG;AACH,MAAM,OAAO,0BAA2B,SAAQ,mBAAmB;IAoBlE,YAAY,YAAiC,EAAE,aAA+C,EAAE,MAAiB;QAChH,KAAK,CACJ,YAAY,CAAC,OAAO,EACpB,YAAY,CAAC,QAAQ,EACrB,aAAa,EACb,CAAC,GAAG,YAAY,CAAC,WAAW,CAAC,EAC7B,YAAY,CAAC,oBAAoB,EACjC,YAAY,CAAC,mBAAmB,CAChC,CAAC;QA1Bc,oBAAe,GAAG,IAAI,OAAO,EAAgB,CAAC;QACvD,cAAS,GAAG,KAAK,CAAC;QAClB,eAAU,GAAG,KAAK,CAAC;QAEV,yBAAoB,GAAG,IAAI,GAAG,EAA2B,CAAC;QACnE,qBAAgB,GAAa,EAAE,CAAC;QAChC,qBAAgB,GAAa,EAAE,CAAC;QAChC,yBAAoB,GAAG,KAAK,CAAC;QAE7B,0BAAqB,GAAG,IAAI,CAAC;QAC7B,qBAAgB,GAAG,IAAI,CAAC;QAMxB,qBAAgB,GAAsB,EAAE,CAAC;QAWhD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,cAAc,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AK,CAAC,KAAK,CAAC;gBACxC,MAAM;YACP,KAAK,wBAAwB;gBAC5B,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,aAAa,GAAG,KAAK,CAAC,KAAK,CAAC;gBAChD,MAAM;YACP,KAAK,sBAAsB;gBAC1B,IAAI,CAAC,iBAAiB,GAAG,KAAK,CAAC,IAAI,CAAC;gBACpC,MAAM;QACR,CAAC;IACF,CAAC;CACD","sourcesContent":["import type { Api, Model } from \"@earendil-works/pi-ai/compat\";\nimport type { AgentSession, CompactionReason } from \"../../core/agent-session.ts\";\nimport { AgentSessionRuntime, type CreateAgentSessionRuntimeFactory } from \"../../core/agent-session-runtime.ts\";\nimport type { PromptOptions } from \"../../core/agent-session-types.ts\";\nimport type { ResourceOverlap } from \"../../core/diagnostics.ts\";\nimport { SessionManager } from \"../../core/session-manager.ts\";\nimport type { JsonAgentSessionEvent } from \"../json-event.ts\";\nimport type { RpcClient } from \"../rpc/rpc-client.ts\";\nimport type {\n\tRpcAutocompleteItem,\n\tRpcEvent,\n\tRpcExtensionUIRequest,\n\tRpcExtensionUIResponse,\n\tRpcModelCatalog,\n\tRpcSlashCommand,\n} from \"../rpc/rpc-types.ts\";\nimport type { ActivityWatchdogDiagnostic } from \"./activity-watchdog.ts\";\nimport type { InteractiveEngineGenerationEndedListener } from \"./engine-generation.ts\";\nimport { type EngineDiagnosticListener, EngineHealthController } from \"./engine-health.ts\";\nimport { type AtomicOAuthLoginCallbacks, loginIsolatedOAuthProvider } from \"./isolated-auth.ts\";\nimport type { EngineKeybindingState, InteractiveEngineCommand, InteractiveEngineMessage } from \"./protocol.ts\";\nimport { RemoteCommandCatalog, type RemoteCommandsListener } from \"./remote-command-catalog.ts\";\nimport { RemoteModelCatalog } from \"./remote-model-catalog.ts\";\nimport { RemoteQueuePause } from \"./remote-queue-pause.js\";\n/**\n * Owns Atomic's local interactive host facade and child-process engine.\n *\n * This runtime is deliberately not a RemoteSession adapter. Its JSONL RPC,\n * rendering, custom UI, and recovery lifecycle stay separate from pi-client's\n * protocol lease lifecycle.\n */\nexport class IsolatedInteractiveRuntime extends AgentSessionRuntime {\n\tprivate readonly client: RpcClient;\n\tprivate readonly patchedSessions = new WeakSet<AgentSession>();\n\tprivate streaming = false;\n\tprivate compacting = false;\n\tprivate compactionReason: CompactionReason | undefined;\n\tprivate readonly activeBashRequestIds = new Map<string | symbol, string>();\n\tprivate steeringMessages: string[] = [];\n\tprivate followUpMessages: string[] = [];\n\tprivate engineCallbackActive = false;\n\tprivate readonly queuePause: RemoteQueuePause;\n\tprivate autoCompactionEnabled = true;\n\tprivate autoRetryEnabled = true;\n\tprivate remoteSessionName: string | undefined;\n\tprivate remoteSessionFile: string | undefined;\n\tprivate readonly health: EngineHealthController;\n\tprivate readonly remoteCommands: RemoteCommandCatalog;\n\tprivate readonly remoteModelCatalog: RemoteModelCatalog;\n\tprivate resourceOverlaps: ResourceOverlap[] = [];\n\n\tconstructor(localRuntime: AgentSessionRuntime, createRuntime: CreateAgentSessionRuntimeFactory, client: RpcClient) {\n\t\tsuper(\n\t\t\tlocalRuntime.session,\n\t\t\tlocalRuntime.services,\n\t\t\tcreateRuntime,\n\t\t\t[...localRuntime.diagnostics],\n\t\t\tlocalRuntime.modelFallbackMessage,\n\t\t\tlocalRuntime.modelFallbackReason,\n\t\t);\n\t\tthis.client = client;\n\t\tthis.remoteCommands = new RemoteCommandCatalog(client);\n\t\tthis.remoteModelCatalog = new RemoteModelCatalog(client);\n\t\tthis.queuePause = new RemoteQueuePause(client);\n\t\tthis.health = new EngineHealthController({\n\t\t\tstop: () => this.client.stop(),\n\t\t\trestart: async () => {\n\t\t\t\tawait this.client.restart(this.remoteSessionFile);\n\t\t\t\tawait this.initializeFromEngine();\n\t\t\t},\n\t\t\tclearActivity: () => {\n\t\t\t\tthis.streaming = false;\n\t\t\t\tthis.compacting = false;\n\t\t\t\tthis.compactionReason = undefined;\n\t\t\t\tthis.engineCallbackActive = false;\n\t\t\t\tthis.health.markCooperativeAbortSettled();\n\t\t\t},\n\t\t});\n\t\tthis.client.onEvent((event) => this.observeEvent(event));\n\t\tthis.client.onGenerationEnded((event) => this.health.handleGenerationEnded(event));\n\t}\n\n\toverride get session(): AgentSession {\n\t\tconst session = super.session;\n\t\tthis.patchSession(session);\n\t\treturn session;\n\t}\n\tasync initializeFromEngine(): Promise<void> {\n\t\tconst state = await this.client.getState();\n\t\tconst catalog = await this.client.requestInternal<RpcModelCatalog>({ type: \"get_available_models\" });\n\t\tif (state.sessionFile && super.session.sessionManager.getSessionFile() !== state.sessionFile) {\n\t\t\tawait super.switchSession(state.sessionFile);\n\t\t}\n\t\tconst session = super.session;\n\t\tthis.remoteModelCatalog.apply(catalog);\n\t\tthis.remoteModelCatalog.patch(session);\n\t\t(session.agent.state as { model?: Model<Api> }).model = state.model;\n\t\tsession.agent.state.thinkingLevel = state.thinkingLevel;\n\t\tsession.agent.steeringMode = state.steeringMode;\n\t\tsession.agent.followUpMode = state.followUpMode;\n\t\tthis.autoCompactionEnabled = state.autoCompactionEnabled;\n\t\tthis.resourceOverlaps = state.resourceOverlaps ?? [];\n\t\tthis.remoteSessionName = state.sessionName;\n\t\tthis.remoteSessionFile = state.sessionFile;\n\t\tthis.streaming = state.isStreaming;\n\t\tthis.compacting = state.isCompacting;\n\t\tthis.compactionReason = state.isCompacting ? state.compactionReason : undefined;\n\t\tthis.queuePause.synchronize(state.queuedMessagesPaused === true);\n\t\tthis.replaceModelFallback(state.modelFallbackMessage, state.modelFallbackReason);\n\t\tthis.refreshSessionView();\n\t\tthis.engineCallbackActive = false;\n\t\tthis.health.clearUnresponsive();\n\t\tthis.health.markCooperativeAbortSettled();\n\t\t// Non-blocking refresh so isolated autocomplete lists engine-only extension\n\t\t// commands after bind/restart/reload/new/resume/fork. See RemoteCommandCatalog.\n\t\tthis.remoteCommands.refresh();\n\t}\n\n\toverride async loginOAuthProvider(provider: string, callbacks: AtomicOAuthLoginCallbacks) {\n\t\treturn loginIsolatedOAuthProvider(super.session, this.client, this.remoteModelCatalog, provider, callbacks);\n\t}\n\n\toverride async logoutProvider(provider: string) {\n\t\tconst result = await this.client.logoutProvider(provider);\n\t\tthis.remoteModelCatalog.applyModels({ models: result.models, scopedModels: result.scopedModels ?? [] });\n\t\tawait super.session.modelRuntime.reloadCredentials({ refreshAvailability: false });\n\t\tsuper.session.modelRuntime.applyExternalProviderAuthStatus(provider, result.authStatus);\n\t\tsuper.session.refreshCurrentModelFromRegistry();\n\t\treturn result;\n\t}\n\n\tonDiagnostic(listener: EngineDiagnosticListener): () => void {\n\t\treturn this.health.onDiagnostic(listener);\n\t}\n\n\tonEngineMessage(listener: (message: InteractiveEngineMessage) => void): () => void {\n\t\treturn this.client.onInteractiveEngineMessage(listener);\n\t}\n\tonKeybindingState(listener: (state: EngineKeybindingState) => void): () => void {\n\t\treturn this.client.onInteractiveEngineKeybindingState(listener);\n\t}\n\n\tsendEngineCommand(command: InteractiveEngineCommand): void {\n\t\tthis.client.sendInteractiveEngineCommand(command);\n\t}\n\n\tgetRemoteCommands(): readonly RpcSlashCommand[] {\n\t\treturn this.remoteCommands.getCommands();\n\t}\n\tonRemoteCommandsChanged(listener: RemoteCommandsListener): () => void {\n\t\treturn this.remoteCommands.onChange(listener);\n\t}\n\tgetRemoteCommandCompletions(commandName: string, argumentPrefix: string): Promise<RpcAutocompleteItem[] | null> {\n\t\treturn this.client.getCommandCompletions(commandName, argumentPrefix);\n\t}\n\n\tasync invokeRemoteShortcut(key: string): Promise<void> {\n\t\tawait this.client.requestInternal<void>({ type: \"invoke_shortcut\", key });\n\t}\n\n\twaitUntilBound(): Promise<void> {\n\t\treturn this.client.waitForInteractiveEngineBound();\n\t}\n\tgetEnginePid(): number | undefined {\n\t\treturn this.client.getEnginePid();\n\t}\n\tgetEngineGeneration(): number {\n\t\treturn this.client.getGeneration();\n\t}\n\tisRecovering(): boolean {\n\t\treturn this.health.isRecovering();\n\t}\n\t/** Subscribe to host-local engine generation death (see engine-generation.ts). */\n\tonGenerationEnded(listener: InteractiveEngineGenerationEndedListener): () => void {\n\t\treturn this.client.onGenerationEnded(listener);\n\t}\n\t/**\n\t * A heartbeat proves the child's event loop is turning again, so a stall the\n\t * watchdog already reported must stop arming the Ctrl+C escape hatch. Fed by a\n\t * dedicated client callback rather than a generic engine-message subscriber,\n\t * which would consume buffered startup custom-UI messages.\n\t */\n\tnoteEngineHeartbeat(): void {\n\t\tthis.health.clearUnresponsive();\n\t}\n\t/** True only when the engine is provably not answering (see EngineHealthController). */\n\tneedsExplicitTermination(): boolean {\n\t\treturn this.health.needsExplicitTermination();\n\t}\n\t/** Explicit user-driven engine termination and recovery (Ctrl+C escape hatch). */\n\tterminateAndRecover(): Promise<void> {\n\t\treturn this.health.terminate();\n\t}\n\tgetResourceOverlaps(): readonly ResourceOverlap[] {\n\t\treturn this.resourceOverlaps;\n\t}\n\tasync synchronize(): Promise<void> {\n\t\tconst state = await this.client.getState();\n\t\tthis.remoteSessionFile = state.sessionFile;\n\t\tthis.remoteSessionName = state.sessionName;\n\t\tthis.resourceOverlaps = state.resourceOverlaps ?? [];\n\t}\n\n\tsetEngineCallbackActive(active: boolean): void {\n\t\tthis.engineCallbackActive = active;\n\t}\n\n\tinterruptBlockedCallback(): boolean {\n\t\tif (!this.engineCallbackActive) return false;\n\t\tthis.dispatchBestEffort(\"interrupt\", this.session.abort());\n\t\treturn true;\n\t}\n\n\tsetExtensionUIHandler(\n\t\thandler: (request: RpcExtensionUIRequest) => Promise<RpcExtensionUIResponse | undefined>,\n\t): () => void {\n\t\treturn this.client.onExtensionUIRequest((request) => {\n\t\t\tvoid handler(request)\n\t\t\t\t.then(async (response) => {\n\t\t\t\t\tif (response) await this.client.respondExtensionUI(response);\n\t\t\t\t})\n\t\t\t\t.catch((error: Error) => {\n\t\t\t\t\tthis.emitDiagnostic({\n\t\t\t\t\t\tactivity: undefined,\n\t\t\t\t\t\telapsedMs: 0,\n\t\t\t\t\t\tlevel: \"unresponsive\",\n\t\t\t\t\t\tmessage: `Interactive engine UI bridge failed: ${error.message}`,\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t});\n\t}\n\n\temitDiagnostic(diagnostic: ActivityWatchdogDiagnostic): void {\n\t\tthis.engineCallbackActive = true;\n\t\tthis.health.publish(diagnostic);\n\t}\n\n\toverride async switchSession(sessionPath: string): Promise<{ cancelled: boolean }> {\n\t\tconst result = await this.client.switchSession(sessionPath);\n\t\tif (!result.cancelled) {\n\t\t\tawait super.switchSession(sessionPath);\n\t\t\tawait this.initializeFromEngine();\n\t\t}\n\t\treturn result;\n\t}\n\n\toverride async newSession(options?: { parentSession?: string }): Promise<{ cancelled: boolean }> {\n\t\tconst result = await this.client.newSession(options?.parentSession);\n\t\tif (result.cancelled) return result;\n\t\tconst state = await this.client.getState();\n\t\tif (state.sessionFile) await super.switchSession(state.sessionFile);\n\t\telse this.resetUnpersistedSessionView();\n\t\tawait this.initializeFromEngine();\n\t\treturn result;\n\t}\n\n\toverride async importFromJsonl(inputPath: string, cwdOverride?: string): Promise<{ cancelled: boolean }> {\n\t\tconst result = await this.client.requestInternal<{ cancelled: boolean }>({\n\t\t\ttype: \"import_session\",\n\t\t\tinputPath,\n\t\t\tcwdOverride,\n\t\t});\n\t\tif (result.cancelled) return result;\n\t\tconst state = await this.client.getState();\n\t\tif (state.sessionFile) await super.switchSession(state.sessionFile);\n\t\tawait this.initializeFromEngine();\n\t\treturn result;\n\t}\n\n\toverride async fork(\n\t\tentryId: string,\n\t\toptions?: { position?: \"before\" | \"at\" },\n\t): Promise<{ cancelled: boolean; selectedText?: string }> {\n\t\tlet selectedText: string | undefined;\n\t\tlet cancelled: boolean;\n\t\tif (options?.position === \"at\") {\n\t\t\tcancelled = (await this.client.clone()).cancelled;\n\t\t} else {\n\t\t\tconst result = await this.client.fork(entryId);\n\t\t\tcancelled = result.cancelled;\n\t\t\tselectedText = result.text;\n\t\t}\n\t\tif (cancelled) return { cancelled: true };\n\t\tconst state = await this.client.getState();\n\t\tif (state.sessionFile) await super.switchSession(state.sessionFile);\n\t\tawait this.initializeFromEngine();\n\t\treturn { cancelled: false, selectedText };\n\t}\n\n\t/**\n\t * The child engine already settled (and persisted) its own turn before it\n\t * reported the replacement, and the host facade's `abort()` is `abortAndRecover()`\n\t * — an unbounded cooperative round trip. Re-entering it during teardown would\n\t * hang session replacement on an unresponsive or dead engine, which is exactly\n\t * what engine recovery exists to survive.\n\t */\n\tprotected override async settleActiveResponseBeforeTeardown(): Promise<void> {}\n\n\toverride async dispose(): Promise<void> {\n\t\t// Joins any in-flight replacement: shutdown voids the client's restart\n\t\t// permit and waits for the attempt, so nothing spawns after this returns.\n\t\tawait this.health.shutdown();\n\t\tawait this.client.stop();\n\t\tawait super.dispose();\n\t}\n\n\tprivate patchSession(session: AgentSession): void {\n\t\tif (this.patchedSessions.has(session)) return;\n\t\tthis.patchedSessions.add(session);\n\t\tthis.patchSessionManager(session.sessionManager);\n\t\tObject.defineProperties(session, {\n\t\t\tisStreaming: { configurable: true, get: () => this.streaming },\n\t\t\tisCompacting: { configurable: true, get: () => this.compacting },\n\t\t\tcompactionReason: { configurable: true, get: () => this.compactionReason },\n\t\t\tisBashRunning: { configurable: true, get: () => this.activeBashRequestIds.size > 0 },\n\t\t\tsessionName: { configurable: true, get: () => this.remoteSessionName },\n\t\t\tsessionFile: { configurable: true, get: () => this.remoteSessionFile },\n\t\t\tautoCompactionEnabled: { configurable: true, get: () => this.autoCompactionEnabled },\n\t\t\tautoRetryEnabled: { configurable: true, get: () => this.autoRetryEnabled },\n\t\t\tqueuedMessagesPaused: { configurable: true, get: () => this.queuePause.isPaused },\n\t\t\tsubscribe: {\n\t\t\t\tconfigurable: true,\n\t\t\t\tvalue: (listener: (event: JsonAgentSessionEvent) => void) => this.client.onEvent(listener),\n\t\t\t},\n\t\t\tprompt: {\n\t\t\t\tconfigurable: true,\n\t\t\t\tvalue: async (text: string, options?: PromptOptions) => {\n\t\t\t\t\tawait this.client.prompt(text, options?.images, options?.streamingBehavior);\n\t\t\t\t\toptions?.preflightResult?.(true);\n\t\t\t\t},\n\t\t\t},\n\t\t\tsteer: { configurable: true, value: (text: string) => this.client.steer(text) },\n\t\t\tfollowUp: { configurable: true, value: (text: string) => this.client.followUp(text) },\n\t\t\tabort: { configurable: true, value: () => this.abortAndRecover() },\n\t\t\texecuteBash: {\n\t\t\t\tconfigurable: true,\n\t\t\t\tvalue: async (\n\t\t\t\t\tcommand: string,\n\t\t\t\t\tonChunk?: Parameters<AgentSession[\"executeBash\"]>[1],\n\t\t\t\t\toptions?: Parameters<AgentSession[\"executeBash\"]>[2],\n\t\t\t\t) => {\n\t\t\t\t\tconst key = options?.id ?? Symbol(\"isolated-bash-request\");\n\t\t\t\t\ttry {\n\t\t\t\t\t\treturn await this.client.userBashWithUpdates(command, (delta, channel) => onChunk?.(delta, channel), {\n\t\t\t\t\t\t\texcludeFromContext: options?.excludeFromContext,\n\t\t\t\t\t\t\tonRequestId: (requestId) => this.activeBashRequestIds.set(key, requestId),\n\t\t\t\t\t\t});\n\t\t\t\t\t} finally {\n\t\t\t\t\t\tthis.activeBashRequestIds.delete(key);\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t},\n\t\t\trecordBashResult: { configurable: true, value: () => {} },\n\t\t\tabortBash: {\n\t\t\t\tconfigurable: true,\n\t\t\t\tvalue: (id?: string) => {\n\t\t\t\t\tif (id === undefined) this.dispatchBestEffort(\"abort bash\", this.client.abortBash());\n\t\t\t\t\telse {\n\t\t\t\t\t\tconst requestId = this.activeBashRequestIds.get(id);\n\t\t\t\t\t\tif (requestId) this.dispatchBestEffort(\"abort bash\", this.client.abortBash(requestId));\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t},\n\t\t\tcompact: { configurable: true, value: () => this.client.compact() },\n\t\t\tabortCompaction: {\n\t\t\t\tconfigurable: true,\n\t\t\t\tvalue: () =>\n\t\t\t\t\tthis.dispatchBestEffort(\n\t\t\t\t\t\t\"abort compaction\",\n\t\t\t\t\t\tthis.client.requestInternal<void>({ type: \"abort_compaction\" }),\n\t\t\t\t\t),\n\t\t\t},\n\t\t\tabortRetry: {\n\t\t\t\tconfigurable: true,\n\t\t\t\tvalue: () => this.dispatchBestEffort(\"abort retry\", this.client.abortRetry()),\n\t\t\t},\n\t\t\tnavigateTree: {\n\t\t\t\tconfigurable: true,\n\t\t\t\tvalue: async (targetId: string, options?: Parameters<AgentSession[\"navigateTree\"]>[1]) =>\n\t\t\t\t\tthis.client.requestInternal<Awaited<ReturnType<AgentSession[\"navigateTree\"]>>>({\n\t\t\t\t\t\ttype: \"navigate_tree\",\n\t\t\t\t\t\ttargetId,\n\t\t\t\t\t\toptions,\n\t\t\t\t\t}),\n\t\t\t},\n\t\t\treload: {\n\t\t\t\tconfigurable: true,\n\t\t\t\tvalue: async () => {\n\t\t\t\t\tawait this.client.requestInternal<void>({ type: \"reload\" });\n\t\t\t\t\tawait this.initializeFromEngine();\n\t\t\t\t},\n\t\t\t},\n\t\t\tsetSessionName: {\n\t\t\t\tconfigurable: true,\n\t\t\t\tvalue: (name: string) => {\n\t\t\t\t\tthis.remoteSessionName = name;\n\t\t\t\t\tthis.dispatchBestEffort(\n\t\t\t\t\t\t\"set session name\",\n\t\t\t\t\t\tthis.client.setSessionName(name).then(() => this.refreshSessionView()),\n\t\t\t\t\t);\n\t\t\t\t},\n\t\t\t},\n\t\t\tgetSteeringMessages: { configurable: true, value: () => [...this.steeringMessages] },\n\t\t\tgetFollowUpMessages: { configurable: true, value: () => [...this.followUpMessages] },\n\t\t\tclearQueue: {\n\t\t\t\tconfigurable: true,\n\t\t\t\tvalue: () => {\n\t\t\t\t\tconst queued = { steering: [...this.steeringMessages], followUp: [...this.followUpMessages] };\n\t\t\t\t\tthis.steeringMessages = [];\n\t\t\t\t\tthis.followUpMessages = [];\n\t\t\t\t\tthis.dispatchBestEffort(\"clear queue\", this.client.requestInternal({ type: \"clear_queue\" }));\n\t\t\t\t\treturn queued;\n\t\t\t\t},\n\t\t\t},\n\t\t\tpauseQueuedMessages: { configurable: true, value: () => this.queuePause.pause() },\n\t\t\tresumeQueuedMessages: {\n\t\t\t\tconfigurable: true,\n\t\t\t\tvalue: (beforeRelease?: () => void) => this.queuePause.resume(beforeRelease),\n\t\t\t},\n\t\t\tsetModel: {\n\t\t\t\tconfigurable: true,\n\t\t\t\tvalue: async (model: Model<Api>) => {\n\t\t\t\t\tconst selected = await this.client.setModel(model.provider, model.id);\n\t\t\t\t\tsession.agent.state.model = session.modelRuntime.getModel(selected.provider, selected.id) ?? model;\n\t\t\t\t\tthis.resolveModelFallback();\n\t\t\t\t},\n\t\t\t},\n\t\t\tsetThinkingLevel: {\n\t\t\t\tconfigurable: true,\n\t\t\t\tvalue: (level: AgentSession[\"thinkingLevel\"]) => {\n\t\t\t\t\tsession.agent.state.thinkingLevel = level;\n\t\t\t\t\tthis.dispatchBestEffort(\"set thinking level\", this.client.setThinkingLevel(level));\n\t\t\t\t},\n\t\t\t},\n\t\t\tcycleModel: {\n\t\t\t\tconfigurable: true,\n\t\t\t\tvalue: async (direction?: \"forward\" | \"backward\") => {\n\t\t\t\t\tconst previousModel = session.model;\n\t\t\t\t\tconst result = await this.client.cycleModel(direction);\n\t\t\t\t\tif (!result) return undefined;\n\t\t\t\t\tconst model = session.modelRuntime.getModel(result.model.provider, result.model.id) ?? result.model;\n\t\t\t\t\tsession.agent.state.model = model;\n\t\t\t\t\tsession.agent.state.thinkingLevel = result.thinkingLevel;\n\t\t\t\t\tthis.resolveModelFallbackAfterExplicitModelSelection(previousModel, model);\n\t\t\t\t\treturn { ...result, model };\n\t\t\t\t},\n\t\t\t},\n\t\t\tcycleThinkingLevel: {\n\t\t\t\tconfigurable: true,\n\t\t\t\tvalue: () => {\n\t\t\t\t\tconst levels = session.getAvailableThinkingLevels();\n\t\t\t\t\tif (levels.length <= 1) return undefined;\n\t\t\t\t\tconst current = levels.indexOf(session.thinkingLevel);\n\t\t\t\t\tconst level = levels[(current + 1) % levels.length]!;\n\t\t\t\t\tsession.agent.state.thinkingLevel = level;\n\t\t\t\t\tthis.dispatchBestEffort(\"cycle thinking level\", this.client.setThinkingLevel(level));\n\t\t\t\t\treturn level;\n\t\t\t\t},\n\t\t\t},\n\t\t\tsetSteeringMode: {\n\t\t\t\tconfigurable: true,\n\t\t\t\tvalue: (mode: \"all\" | \"one-at-a-time\") => {\n\t\t\t\t\tsession.agent.steeringMode = mode;\n\t\t\t\t\tthis.dispatchBestEffort(\"set steering mode\", this.client.setSteeringMode(mode));\n\t\t\t\t},\n\t\t\t},\n\t\t\tsetFollowUpMode: {\n\t\t\t\tconfigurable: true,\n\t\t\t\tvalue: (mode: \"all\" | \"one-at-a-time\") => {\n\t\t\t\t\tsession.agent.followUpMode = mode;\n\t\t\t\t\tthis.dispatchBestEffort(\"set follow-up mode\", this.client.setFollowUpMode(mode));\n\t\t\t\t},\n\t\t\t},\n\t\t\tsetAutoCompactionEnabled: {\n\t\t\t\tconfigurable: true,\n\t\t\t\tvalue: (enabled: boolean) => {\n\t\t\t\t\tthis.autoCompactionEnabled = enabled;\n\t\t\t\t\tthis.dispatchBestEffort(\"set auto compaction\", this.client.setAutoCompaction(enabled));\n\t\t\t\t},\n\t\t\t},\n\t\t\tsetAutoRetryEnabled: {\n\t\t\t\tconfigurable: true,\n\t\t\t\tvalue: (enabled: boolean) => {\n\t\t\t\t\tthis.autoRetryEnabled = enabled;\n\t\t\t\t\tthis.dispatchBestEffort(\"set auto retry\", this.client.setAutoRetry(enabled));\n\t\t\t\t},\n\t\t\t},\n\t\t});\n\t}\n\n\t/**\n\t * Cooperative interrupt. Requests the engine's own abort and waits for it —\n\t * no timeout, no termination, no restart. A genuinely wedged engine is the\n\t * user's call to terminate with Ctrl+C (see terminateAndRecover), never an\n\t * automatic consequence of pressing Escape.\n\t */\n\tprivate async abortAndRecover(): Promise<void> {\n\t\tawait this.queuePause.settleBeforeAbort();\n\t\tthis.health.markCooperativeAbortStarted();\n\t\ttry {\n\t\t\tawait this.client.abort();\n\t\t} finally {\n\t\t\tthis.health.markCooperativeAbortSettled();\n\t\t\tthis.engineCallbackActive = false;\n\t\t}\n\t}\n\n\tprivate dispatchBestEffort(label: string, operation: Promise<unknown>): void {\n\t\tvoid operation.catch((error: Error) => {\n\t\t\tif (this.health.isRecovering()) return;\n\t\t\tthis.emitDiagnostic({\n\t\t\t\tactivity: undefined,\n\t\t\t\telapsedMs: 0,\n\t\t\t\tlevel: \"unresponsive\",\n\t\t\t\tmessage: `Interactive engine ${label} failed: ${error.message}`,\n\t\t\t});\n\t\t});\n\t}\n\n\tprivate resetUnpersistedSessionView(): void {\n\t\tconst session = super.session;\n\t\tconst manager = SessionManager.create(session.sessionManager.getCwd(), session.sessionManager.getSessionDir());\n\t\tObject.defineProperty(session, \"sessionManager\", { configurable: true, value: manager });\n\t\tthis.patchSessionManager(manager);\n\t\tsession.agent.state.messages = [];\n\t}\n\n\tprivate patchSessionManager(manager: SessionManager): void {\n\t\tObject.defineProperty(manager, \"appendLabelChange\", {\n\t\t\tconfigurable: true,\n\t\t\tvalue: (entryId: string, label?: string) => {\n\t\t\t\tthis.dispatchBestEffort(\n\t\t\t\t\t\"set label\",\n\t\t\t\t\tthis.client\n\t\t\t\t\t\t.requestInternal<void>({ type: \"set_label\", entryId, label })\n\t\t\t\t\t\t.then(() => this.refreshSessionView()),\n\t\t\t\t);\n\t\t\t},\n\t\t});\n\t}\n\n\tprivate refreshSessionView(): void {\n\t\tconst session = super.session;\n\t\tconst sessionFile = session.sessionFile;\n\t\tif (!sessionFile) return;\n\t\tconst currentManager = session.sessionManager;\n\t\tconst refreshed = SessionManager.open(sessionFile, currentManager.getSessionDir(), currentManager.getCwd());\n\t\tObject.defineProperty(session, \"sessionManager\", { configurable: true, value: refreshed });\n\t\tthis.patchSessionManager(refreshed);\n\t\tsession.agent.state.messages = refreshed.buildSessionContext().messages;\n\t}\n\n\tprivate observeEvent(event: RpcEvent): void {\n\t\tconst session = super.session;\n\t\tswitch (event.type) {\n\t\t\tcase \"agent_start\":\n\t\t\t\tthis.streaming = true;\n\t\t\t\tbreak;\n\t\t\tcase \"agent_end\":\n\t\t\t\tthis.streaming = false;\n\t\t\t\tthis.refreshSessionView();\n\t\t\t\tbreak;\n\t\t\tcase \"compaction_start\":\n\t\t\t\tthis.compacting = true;\n\t\t\t\tthis.compactionReason = event.reason;\n\t\t\t\tbreak;\n\t\t\tcase \"compaction_end\":\n\t\t\t\tthis.compacting = false;\n\t\t\t\tthis.compactionReason = undefined;\n\t\t\t\tbreak;\n\t\t\tcase \"queue_update\":\n\t\t\t\tthis.steeringMessages = [...event.steering];\n\t\t\t\tthis.followUpMessages = [...event.followUp];\n\t\t\t\tbreak;\n\t\t\tcase \"model_changed\":\n\t\t\t\tsession.agent.state.model = event.model;\n\t\t\t\tbreak;\n\t\t\tcase \"thinking_level_changed\":\n\t\t\t\tsession.agent.state.thinkingLevel = event.level;\n\t\t\t\tbreak;\n\t\t\tcase \"session_info_changed\":\n\t\t\t\tthis.remoteSessionName = event.name;\n\t\t\t\tbreak;\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"isolated-runtime.js","sourceRoot":"","sources":["../../../src/modes/interactive-engine/isolated-runtime.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAyC,MAAM,qCAAqC,CAAC;AAGjH,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAG/D,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAWtE,OAAO,EAAiC,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAC3F,OAAO,EAAkC,0BAA0B,EAAE,MAAM,oBAAoB,CAAC;AAEhG,OAAO,EAAE,oBAAoB,EAA+B,MAAM,6BAA6B,CAAC;AAChG,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAW3D;;;;;;GAMG;AACH,MAAM,OAAO,0BAA2B,SAAQ,mBAAmB;IA0BlE,YAA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;gBAC5C,MAAM;YACP,KAAK,eAAe;gBACnB,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;gBACxC,MAAM;YACP,KAAK,wBAAwB;gBAC5B,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,aAAa,GAAG,KAAK,CAAC,KAAK,CAAC;gBAChD,MAAM;YACP,KAAK,sBAAsB;gBAC1B,IAAI,CAAC,iBAAiB,GAAG,KAAK,CAAC,IAAI,CAAC;gBACpC,MAAM;QACR,CAAC;IACF,CAAC;CACD","sourcesContent":["import type { Api, Model } from \"@earendil-works/pi-ai/compat\";\nimport type { AgentSession, CompactionReason } from \"../../core/agent-session.ts\";\nimport { AgentSessionRuntime, type CreateAgentSessionRuntimeFactory } from \"../../core/agent-session-runtime.ts\";\nimport type { PromptOptions } from \"../../core/agent-session-types.ts\";\nimport type { ResourceOverlap } from \"../../core/diagnostics.ts\";\nimport { SessionManager } from \"../../core/session-manager.ts\";\nimport type { JsonAgentSessionEvent } from \"../json-event.ts\";\nimport type { RpcClient } from \"../rpc/rpc-client.ts\";\nimport { isRpcTransportFailure } from \"../rpc/rpc-transport-error.ts\";\nimport type {\n\tRpcAutocompleteItem,\n\tRpcEvent,\n\tRpcExtensionUIRequest,\n\tRpcExtensionUIResponse,\n\tRpcModelCatalog,\n\tRpcSlashCommand,\n} from \"../rpc/rpc-types.ts\";\nimport type { ActivityWatchdogDiagnostic } from \"./activity-watchdog.ts\";\nimport type { InteractiveEngineGenerationEndedListener } from \"./engine-generation.ts\";\nimport { type EngineDiagnosticListener, EngineHealthController } from \"./engine-health.ts\";\nimport { type AtomicOAuthLoginCallbacks, loginIsolatedOAuthProvider } from \"./isolated-auth.ts\";\nimport type { EngineKeybindingState, InteractiveEngineCommand, InteractiveEngineMessage } from \"./protocol.ts\";\nimport { RemoteCommandCatalog, type RemoteCommandsListener } from \"./remote-command-catalog.ts\";\nimport { RemoteModelCatalog } from \"./remote-model-catalog.ts\";\nimport { RemoteQueuePause } from \"./remote-queue-pause.js\";\n\ntype QueueSnapshot = { steering: string[]; followUp: string[] };\n\ntype PendingQueueClear = {\n\tsnapshot: QueueSnapshot;\n\tqueueUpdateGeneration: number;\n\tcount: number;\n\tsucceeded: boolean;\n};\n\n/**\n * Owns Atomic's local interactive host facade and child-process engine.\n *\n * This runtime is deliberately not a RemoteSession adapter. Its JSONL RPC,\n * rendering, custom UI, and recovery lifecycle stay separate from pi-client's\n * protocol lease lifecycle.\n */\nexport class IsolatedInteractiveRuntime extends AgentSessionRuntime {\n\tprivate readonly client: RpcClient;\n\tprivate readonly patchedSessions = new WeakSet<AgentSession>();\n\tprivate streaming = false;\n\tprivate compacting = false;\n\tprivate compactionReason: CompactionReason | undefined;\n\tprivate readonly activeBashRequestIds = new Map<string | symbol, string>();\n\tprivate steeringMessages: string[] = [];\n\tprivate followUpMessages: string[] = [];\n\t/** Bumped by every authoritative queue_update. */\n\tprivate queueUpdateGeneration = 0;\n\t/** Clears started before the next queue_update share one rollback snapshot. */\n\tprivate pendingQueueClear: PendingQueueClear | undefined;\n\tprivate engineCallbackActive = false;\n\tprivate readonly queuePause: RemoteQueuePause;\n\tprivate autoCompactionEnabled = true;\n\tprivate autoRetryEnabled = true;\n\tprivate remoteSessionName: string | undefined;\n\tprivate remoteSessionFile: string | undefined;\n\tprivate readonly health: EngineHealthController;\n\tprivate readonly remoteCommands: RemoteCommandCatalog;\n\tprivate disposed = false;\n\tprivate disposePromise: Promise<void> | undefined;\n\tprivate readonly remoteModelCatalog: RemoteModelCatalog;\n\tprivate resourceOverlaps: ResourceOverlap[] = [];\n\n\tconstructor(localRuntime: AgentSessionRuntime, createRuntime: CreateAgentSessionRuntimeFactory, client: RpcClient) {\n\t\tsuper(\n\t\t\tlocalRuntime.session,\n\t\t\tlocalRuntime.services,\n\t\t\tcreateRuntime,\n\t\t\t[...localRuntime.diagnostics],\n\t\t\tlocalRuntime.modelFallbackMessage,\n\t\t\tlocalRuntime.modelFallbackReason,\n\t\t);\n\t\tthis.client = client;\n\t\tthis.remoteCommands = new RemoteCommandCatalog(client);\n\t\tthis.remoteModelCatalog = new RemoteModelCatalog(client);\n\t\tthis.queuePause = new RemoteQueuePause(client);\n\t\tthis.health = new EngineHealthController({\n\t\t\tstop: () => this.client.stop(),\n\t\t\trestart: async () => {\n\t\t\t\tawait this.client.restart(this.remoteSessionFile);\n\t\t\t\tawait this.initializeFromEngine();\n\t\t\t},\n\t\t\tclearActivity: () => {\n\t\t\t\tthis.streaming = false;\n\t\t\t\tthis.compacting = false;\n\t\t\t\tthis.compactionReason = undefined;\n\t\t\t\tthis.pendingQueueClear = undefined;\n\t\t\t\tthis.engineCallbackActive = false;\n\t\t\t\tthis.health.markCooperativeAbortSettled();\n\t\t\t},\n\t\t});\n\t\tthis.client.onEvent((event) => this.observeEvent(event));\n\t\tthis.client.onGenerationEnded((event) => this.health.handleGenerationEnded(event));\n\t}\n\n\toverride get session(): AgentSession {\n\t\tconst session = super.session;\n\t\tthis.patchSession(session);\n\t\treturn session;\n\t}\n\tasync initializeFromEngine(): Promise<void> {\n\t\tif (this.disposed) return;\n\t\ttry {\n\t\t\tconst state = await this.client.getState();\n\t\t\tconst catalog = await this.client.requestInternal<RpcModelCatalog>({ type: \"get_available_models\" });\n\t\t\tif (state.sessionFile && super.session.sessionManager.getSessionFile() !== state.sessionFile) {\n\t\t\t\tawait super.switchSession(state.sessionFile);\n\t\t\t}\n\t\t\tconst session = super.session;\n\t\t\tthis.remoteModelCatalog.apply(catalog);\n\t\t\tthis.remoteModelCatalog.patch(session);\n\t\t\t(session.agent.state as { model?: Model<Api> }).model = state.model;\n\t\t\tsession.agent.state.thinkingLevel = state.thinkingLevel;\n\t\t\tsession.agent.steeringMode = state.steeringMode;\n\t\t\tsession.agent.followUpMode = state.followUpMode;\n\t\t\tthis.autoCompactionEnabled = state.autoCompactionEnabled;\n\t\t\tthis.resourceOverlaps = state.resourceOverlaps ?? [];\n\t\t\tthis.remoteSessionName = state.sessionName;\n\t\t\tthis.remoteSessionFile = state.sessionFile;\n\t\t\tthis.streaming = state.isStreaming;\n\t\t\tthis.compacting = state.isCompacting;\n\t\t\tthis.compactionReason = state.isCompacting ? state.compactionReason : undefined;\n\t\t\tthis.queuePause.synchronize(state.queuedMessagesPaused === true);\n\t\t\tthis.replaceModelFallback(state.modelFallbackMessage, state.modelFallbackReason);\n\t\t\tthis.refreshSessionView();\n\t\t\tthis.engineCallbackActive = false;\n\t\t\tthis.health.clearUnresponsive();\n\t\t\tthis.health.markCooperativeAbortSettled();\n\t\t\t// Non-blocking refresh so isolated autocomplete lists engine-only extension\n\t\t\t// commands after bind/restart/reload/new/resume/fork. See RemoteCommandCatalog.\n\t\t\tthis.remoteCommands.refresh();\n\t\t} catch (error) {\n\t\t\tif (this.disposed && isRpcTransportFailure(error)) return;\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\toverride async loginOAuthProvider(provider: string, callbacks: AtomicOAuthLoginCallbacks) {\n\t\treturn loginIsolatedOAuthProvider(super.session, this.client, this.remoteModelCatalog, provider, callbacks);\n\t}\n\n\toverride async logoutProvider(provider: string) {\n\t\tconst result = await this.client.logoutProvider(provider);\n\t\tthis.remoteModelCatalog.applyModels({ models: result.models, scopedModels: result.scopedModels ?? [] });\n\t\tawait super.session.modelRuntime.reloadCredentials({ refreshAvailability: false });\n\t\tsuper.session.modelRuntime.applyExternalProviderAuthStatus(provider, result.authStatus);\n\t\tsuper.session.refreshCurrentModelFromRegistry();\n\t\treturn result;\n\t}\n\n\tonDiagnostic(listener: EngineDiagnosticListener): () => void {\n\t\treturn this.health.onDiagnostic(listener);\n\t}\n\n\tonEngineMessage(listener: (message: InteractiveEngineMessage) => void): () => void {\n\t\treturn this.client.onInteractiveEngineMessage(listener);\n\t}\n\tonKeybindingState(listener: (state: EngineKeybindingState) => void): () => void {\n\t\treturn this.client.onInteractiveEngineKeybindingState(listener);\n\t}\n\n\tsendEngineCommand(command: InteractiveEngineCommand): void {\n\t\tthis.client.sendInteractiveEngineCommand(command);\n\t}\n\n\tgetRemoteCommands(): readonly RpcSlashCommand[] {\n\t\treturn this.remoteCommands.getCommands();\n\t}\n\tonRemoteCommandsChanged(listener: RemoteCommandsListener): () => void {\n\t\treturn this.remoteCommands.onChange(listener);\n\t}\n\tgetRemoteCommandCompletions(commandName: string, argumentPrefix: string): Promise<RpcAutocompleteItem[] | null> {\n\t\treturn this.client.getCommandCompletions(commandName, argumentPrefix);\n\t}\n\n\tasync invokeRemoteShortcut(key: string): Promise<void> {\n\t\tawait this.client.requestInternal<void>({ type: \"invoke_shortcut\", key });\n\t}\n\n\tasync waitUntilBound(): Promise<void> {\n\t\ttry {\n\t\t\tawait this.client.waitForInteractiveEngineBound();\n\t\t} catch (error) {\n\t\t\tif (this.disposed && isRpcTransportFailure(error)) return;\n\t\t\tthrow error;\n\t\t}\n\t}\n\tgetEnginePid(): number | undefined {\n\t\treturn this.client.getEnginePid();\n\t}\n\tgetEngineGeneration(): number {\n\t\treturn this.client.getGeneration();\n\t}\n\tisRecovering(): boolean {\n\t\treturn this.health.isRecovering();\n\t}\n\t/** Subscribe to host-local engine generation death (see engine-generation.ts). */\n\tonGenerationEnded(listener: InteractiveEngineGenerationEndedListener): () => void {\n\t\treturn this.client.onGenerationEnded(listener);\n\t}\n\t/**\n\t * A heartbeat proves the child's event loop is turning again, so a stall the\n\t * watchdog already reported must stop arming the Ctrl+C escape hatch. Fed by a\n\t * dedicated client callback rather than a generic engine-message subscriber,\n\t * which would consume buffered startup custom-UI messages.\n\t */\n\tnoteEngineHeartbeat(): void {\n\t\tthis.health.clearUnresponsive();\n\t}\n\t/** True only when the engine is provably not answering (see EngineHealthController). */\n\tneedsExplicitTermination(): boolean {\n\t\treturn this.health.needsExplicitTermination();\n\t}\n\t/** Explicit user-driven engine termination and recovery (Ctrl+C escape hatch). */\n\tterminateAndRecover(): Promise<void> {\n\t\treturn this.health.terminate();\n\t}\n\tgetResourceOverlaps(): readonly ResourceOverlap[] {\n\t\treturn this.resourceOverlaps;\n\t}\n\tasync synchronize(): Promise<void> {\n\t\tconst state = await this.client.getState();\n\t\tthis.remoteSessionFile = state.sessionFile;\n\t\tthis.remoteSessionName = state.sessionName;\n\t\tthis.resourceOverlaps = state.resourceOverlaps ?? [];\n\t}\n\n\tsetEngineCallbackActive(active: boolean): void {\n\t\tthis.engineCallbackActive = active;\n\t}\n\n\tinterruptBlockedCallback(): boolean {\n\t\tif (!this.engineCallbackActive) return false;\n\t\tthis.dispatchBestEffort(\"interrupt\", this.session.abort());\n\t\treturn true;\n\t}\n\n\tsetExtensionUIHandler(\n\t\thandler: (request: RpcExtensionUIRequest) => Promise<RpcExtensionUIResponse | undefined>,\n\t): () => void {\n\t\treturn this.client.onExtensionUIRequest((request) => {\n\t\t\tvoid handler(request)\n\t\t\t\t.then(async (response) => {\n\t\t\t\t\tif (response) await this.client.respondExtensionUI(response);\n\t\t\t\t})\n\t\t\t\t.catch((error: Error) => {\n\t\t\t\t\tthis.emitDiagnostic({\n\t\t\t\t\t\tactivity: undefined,\n\t\t\t\t\t\telapsedMs: 0,\n\t\t\t\t\t\tlevel: \"unresponsive\",\n\t\t\t\t\t\tmessage: `Interactive engine UI bridge failed: ${error.message}`,\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t});\n\t}\n\n\temitDiagnostic(diagnostic: ActivityWatchdogDiagnostic): void {\n\t\tthis.engineCallbackActive = true;\n\t\tthis.health.publish(diagnostic);\n\t}\n\n\toverride async switchSession(sessionPath: string): Promise<{ cancelled: boolean }> {\n\t\tconst result = await this.client.switchSession(sessionPath);\n\t\tif (!result.cancelled) {\n\t\t\tawait super.switchSession(sessionPath);\n\t\t\tawait this.initializeFromEngine();\n\t\t}\n\t\treturn result;\n\t}\n\n\toverride async newSession(options?: { parentSession?: string }): Promise<{ cancelled: boolean }> {\n\t\tconst result = await this.client.newSession(options?.parentSession);\n\t\tif (result.cancelled) return result;\n\t\tconst state = await this.client.getState();\n\t\tif (state.sessionFile) await super.switchSession(state.sessionFile);\n\t\telse this.resetUnpersistedSessionView();\n\t\tawait this.initializeFromEngine();\n\t\treturn result;\n\t}\n\n\toverride async importFromJsonl(inputPath: string, cwdOverride?: string): Promise<{ cancelled: boolean }> {\n\t\tconst result = await this.client.requestInternal<{ cancelled: boolean }>({\n\t\t\ttype: \"import_session\",\n\t\t\tinputPath,\n\t\t\tcwdOverride,\n\t\t});\n\t\tif (result.cancelled) return result;\n\t\tconst state = await this.client.getState();\n\t\tif (state.sessionFile) await super.switchSession(state.sessionFile);\n\t\tawait this.initializeFromEngine();\n\t\treturn result;\n\t}\n\n\toverride async fork(\n\t\tentryId: string,\n\t\toptions?: { position?: \"before\" | \"at\" },\n\t): Promise<{ cancelled: boolean; selectedText?: string }> {\n\t\tlet selectedText: string | undefined;\n\t\tlet cancelled: boolean;\n\t\tif (options?.position === \"at\") {\n\t\t\tcancelled = (await this.client.clone()).cancelled;\n\t\t} else {\n\t\t\tconst result = await this.client.fork(entryId);\n\t\t\tcancelled = result.cancelled;\n\t\t\tselectedText = result.text;\n\t\t}\n\t\tif (cancelled) return { cancelled: true };\n\t\tconst state = await this.client.getState();\n\t\tif (state.sessionFile) await super.switchSession(state.sessionFile);\n\t\tawait this.initializeFromEngine();\n\t\treturn { cancelled: false, selectedText };\n\t}\n\n\t/**\n\t * The child engine already settled (and persisted) its own turn before it\n\t * reported the replacement, and the host facade's `abort()` is `abortAndRecover()`\n\t * — an unbounded cooperative round trip. Re-entering it during teardown would\n\t * hang session replacement on an unresponsive or dead engine, which is exactly\n\t * what engine recovery exists to survive.\n\t */\n\tprotected override async settleActiveResponseBeforeTeardown(): Promise<void> {}\n\n\toverride dispose(): Promise<void> {\n\t\tif (this.disposePromise) return this.disposePromise;\n\t\tthis.disposed = true;\n\t\tthis.disposePromise = (async () => {\n\t\t\t// EngineHealthController owns the first client stop and joins recovery.\n\t\t\tawait this.health.shutdown();\n\t\t\t// A replacement may have spawned while shutdown joined recovery; the\n\t\t\t// idempotent trailing stop closes that child before disposal returns.\n\t\t\tawait this.client.stop();\n\t\t\tawait super.dispose();\n\t\t})();\n\t\treturn this.disposePromise;\n\t}\n\n\tprivate patchSession(session: AgentSession): void {\n\t\tif (this.patchedSessions.has(session)) return;\n\t\tthis.patchedSessions.add(session);\n\t\tthis.patchSessionManager(session.sessionManager);\n\t\tObject.defineProperties(session, {\n\t\t\tisStreaming: { configurable: true, get: () => this.streaming },\n\t\t\tisCompacting: { configurable: true, get: () => this.compacting },\n\t\t\tcompactionReason: { configurable: true, get: () => this.compactionReason },\n\t\t\tisBashRunning: { configurable: true, get: () => this.activeBashRequestIds.size > 0 },\n\t\t\tsessionName: { configurable: true, get: () => this.remoteSessionName },\n\t\t\tsessionFile: { configurable: true, get: () => this.remoteSessionFile },\n\t\t\tautoCompactionEnabled: { configurable: true, get: () => this.autoCompactionEnabled },\n\t\t\tautoRetryEnabled: { configurable: true, get: () => this.autoRetryEnabled },\n\t\t\tqueuedMessagesPaused: { configurable: true, get: () => this.queuePause.isPaused },\n\t\t\tsubscribe: {\n\t\t\t\tconfigurable: true,\n\t\t\t\tvalue: (listener: (event: JsonAgentSessionEvent) => void) => this.client.onEvent(listener),\n\t\t\t},\n\t\t\tprompt: {\n\t\t\t\tconfigurable: true,\n\t\t\t\tvalue: async (text: string, options?: PromptOptions) => {\n\t\t\t\t\tawait this.client.prompt(text, options?.images, options?.streamingBehavior);\n\t\t\t\t\toptions?.preflightResult?.(true);\n\t\t\t\t},\n\t\t\t},\n\t\t\tsteer: { configurable: true, value: (text: string) => this.client.steer(text) },\n\t\t\tfollowUp: { configurable: true, value: (text: string) => this.client.followUp(text) },\n\t\t\tabort: { configurable: true, value: () => this.abortAndRecover() },\n\t\t\texecuteBash: {\n\t\t\t\tconfigurable: true,\n\t\t\t\tvalue: async (\n\t\t\t\t\tcommand: string,\n\t\t\t\t\tonChunk?: Parameters<AgentSession[\"executeBash\"]>[1],\n\t\t\t\t\toptions?: Parameters<AgentSession[\"executeBash\"]>[2],\n\t\t\t\t) => {\n\t\t\t\t\tconst key = options?.id ?? Symbol(\"isolated-bash-request\");\n\t\t\t\t\ttry {\n\t\t\t\t\t\treturn await this.client.userBashWithUpdates(command, (delta, channel) => onChunk?.(delta, channel), {\n\t\t\t\t\t\t\texcludeFromContext: options?.excludeFromContext,\n\t\t\t\t\t\t\tonRequestId: (requestId) => this.activeBashRequestIds.set(key, requestId),\n\t\t\t\t\t\t});\n\t\t\t\t\t} finally {\n\t\t\t\t\t\tthis.activeBashRequestIds.delete(key);\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t},\n\t\t\trecordBashResult: { configurable: true, value: () => {} },\n\t\t\tabortBash: {\n\t\t\t\tconfigurable: true,\n\t\t\t\tvalue: (id?: string) => {\n\t\t\t\t\tif (id === undefined) this.dispatchBestEffort(\"abort bash\", this.client.abortBash());\n\t\t\t\t\telse {\n\t\t\t\t\t\tconst requestId = this.activeBashRequestIds.get(id);\n\t\t\t\t\t\tif (requestId) this.dispatchBestEffort(\"abort bash\", this.client.abortBash(requestId));\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t},\n\t\t\tcompact: { configurable: true, value: () => this.client.compact() },\n\t\t\tabortCompaction: {\n\t\t\t\tconfigurable: true,\n\t\t\t\tvalue: () =>\n\t\t\t\t\tthis.dispatchBestEffort(\n\t\t\t\t\t\t\"abort compaction\",\n\t\t\t\t\t\tthis.client.requestInternal<void>({ type: \"abort_compaction\" }),\n\t\t\t\t\t),\n\t\t\t},\n\t\t\tabortRetry: {\n\t\t\t\tconfigurable: true,\n\t\t\t\tvalue: () => this.dispatchBestEffort(\"abort retry\", this.client.abortRetry()),\n\t\t\t},\n\t\t\tnavigateTree: {\n\t\t\t\tconfigurable: true,\n\t\t\t\tvalue: async (targetId: string, options?: Parameters<AgentSession[\"navigateTree\"]>[1]) =>\n\t\t\t\t\tthis.client.requestInternal<Awaited<ReturnType<AgentSession[\"navigateTree\"]>>>({\n\t\t\t\t\t\ttype: \"navigate_tree\",\n\t\t\t\t\t\ttargetId,\n\t\t\t\t\t\toptions,\n\t\t\t\t\t}),\n\t\t\t},\n\t\t\treload: {\n\t\t\t\tconfigurable: true,\n\t\t\t\tvalue: async () => {\n\t\t\t\t\tawait this.client.requestInternal<void>({ type: \"reload\" });\n\t\t\t\t\tawait this.initializeFromEngine();\n\t\t\t\t},\n\t\t\t},\n\t\t\tsetSessionName: {\n\t\t\t\tconfigurable: true,\n\t\t\t\tvalue: (name: string) => {\n\t\t\t\t\tthis.remoteSessionName = name;\n\t\t\t\t\tthis.dispatchBestEffort(\n\t\t\t\t\t\t\"set session name\",\n\t\t\t\t\t\tthis.client.setSessionName(name).then(() => this.refreshSessionView()),\n\t\t\t\t\t);\n\t\t\t\t},\n\t\t\t},\n\t\t\tgetSteeringMessages: { configurable: true, value: () => [...this.steeringMessages] },\n\t\t\tgetFollowUpMessages: { configurable: true, value: () => [...this.followUpMessages] },\n\t\t\tclearQueue: {\n\t\t\t\tconfigurable: true,\n\t\t\t\tvalue: () => {\n\t\t\t\t\tconst queued: QueueSnapshot = {\n\t\t\t\t\t\tsteering: [...this.steeringMessages],\n\t\t\t\t\t\tfollowUp: [...this.followUpMessages],\n\t\t\t\t\t};\n\t\t\t\t\tconst pendingClear = this.pendingQueueClear ?? {\n\t\t\t\t\t\tsnapshot: queued,\n\t\t\t\t\t\tqueueUpdateGeneration: this.queueUpdateGeneration,\n\t\t\t\t\t\tcount: 0,\n\t\t\t\t\t\tsucceeded: false,\n\t\t\t\t\t};\n\t\t\t\t\tthis.pendingQueueClear = pendingClear;\n\t\t\t\t\tpendingClear.count += 1;\n\t\t\t\t\tthis.steeringMessages = [];\n\t\t\t\t\tthis.followUpMessages = [];\n\t\t\t\t\tthis.dispatchBestEffort(\n\t\t\t\t\t\t\"clear queue\",\n\t\t\t\t\t\tthis.client.requestInternal({ type: \"clear_queue\" }).then(\n\t\t\t\t\t\t\t() => this.settleQueueClear(pendingClear, true),\n\t\t\t\t\t\t\t(error: Error) => {\n\t\t\t\t\t\t\t\tthis.settleQueueClear(pendingClear, false);\n\t\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t\t\t\treturn queued;\n\t\t\t\t},\n\t\t\t},\n\t\t\tpauseQueuedMessages: { configurable: true, value: () => this.queuePause.pause() },\n\t\t\tresumeQueuedMessages: {\n\t\t\t\tconfigurable: true,\n\t\t\t\tvalue: (beforeRelease?: () => void) => this.queuePause.resume(beforeRelease),\n\t\t\t},\n\t\t\tsetModel: {\n\t\t\t\tconfigurable: true,\n\t\t\t\tvalue: async (model: Model<Api>) => {\n\t\t\t\t\tconst selected = await this.client.setModel(model.provider, model.id);\n\t\t\t\t\tsession.agent.state.model = session.modelRuntime.getModel(selected.provider, selected.id) ?? model;\n\t\t\t\t\tthis.resolveModelFallback();\n\t\t\t\t},\n\t\t\t},\n\t\t\tsetThinkingLevel: {\n\t\t\t\tconfigurable: true,\n\t\t\t\tvalue: (level: AgentSession[\"thinkingLevel\"]) => {\n\t\t\t\t\tsession.agent.state.thinkingLevel = level;\n\t\t\t\t\tthis.dispatchBestEffort(\"set thinking level\", this.client.setThinkingLevel(level));\n\t\t\t\t},\n\t\t\t},\n\t\t\tcycleModel: {\n\t\t\t\tconfigurable: true,\n\t\t\t\tvalue: async (direction?: \"forward\" | \"backward\") => {\n\t\t\t\t\tconst previousModel = session.model;\n\t\t\t\t\tconst result = await this.client.cycleModel(direction);\n\t\t\t\t\tif (!result) return undefined;\n\t\t\t\t\tconst model = session.modelRuntime.getModel(result.model.provider, result.model.id) ?? result.model;\n\t\t\t\t\tsession.agent.state.model = model;\n\t\t\t\t\tsession.agent.state.thinkingLevel = result.thinkingLevel;\n\t\t\t\t\tthis.resolveModelFallbackAfterExplicitModelSelection(previousModel, model);\n\t\t\t\t\treturn { ...result, model };\n\t\t\t\t},\n\t\t\t},\n\t\t\tcycleThinkingLevel: {\n\t\t\t\tconfigurable: true,\n\t\t\t\tvalue: () => {\n\t\t\t\t\tconst levels = session.getAvailableThinkingLevels();\n\t\t\t\t\tif (levels.length <= 1) return undefined;\n\t\t\t\t\tconst current = levels.indexOf(session.thinkingLevel);\n\t\t\t\t\tconst level = levels[(current + 1) % levels.length]!;\n\t\t\t\t\tsession.agent.state.thinkingLevel = level;\n\t\t\t\t\tthis.dispatchBestEffort(\"cycle thinking level\", this.client.setThinkingLevel(level));\n\t\t\t\t\treturn level;\n\t\t\t\t},\n\t\t\t},\n\t\t\tsetSteeringMode: {\n\t\t\t\tconfigurable: true,\n\t\t\t\tvalue: (mode: \"all\" | \"one-at-a-time\") => {\n\t\t\t\t\tsession.agent.steeringMode = mode;\n\t\t\t\t\tthis.dispatchBestEffort(\"set steering mode\", this.client.setSteeringMode(mode));\n\t\t\t\t},\n\t\t\t},\n\t\t\tsetFollowUpMode: {\n\t\t\t\tconfigurable: true,\n\t\t\t\tvalue: (mode: \"all\" | \"one-at-a-time\") => {\n\t\t\t\t\tsession.agent.followUpMode = mode;\n\t\t\t\t\tthis.dispatchBestEffort(\"set follow-up mode\", this.client.setFollowUpMode(mode));\n\t\t\t\t},\n\t\t\t},\n\t\t\tsetAutoCompactionEnabled: {\n\t\t\t\tconfigurable: true,\n\t\t\t\tvalue: (enabled: boolean) => {\n\t\t\t\t\tthis.autoCompactionEnabled = enabled;\n\t\t\t\t\tthis.dispatchBestEffort(\"set auto compaction\", this.client.setAutoCompaction(enabled));\n\t\t\t\t},\n\t\t\t},\n\t\t\tsetAutoRetryEnabled: {\n\t\t\t\tconfigurable: true,\n\t\t\t\tvalue: (enabled: boolean) => {\n\t\t\t\t\tthis.autoRetryEnabled = enabled;\n\t\t\t\t\tthis.dispatchBestEffort(\"set auto retry\", this.client.setAutoRetry(enabled));\n\t\t\t\t},\n\t\t\t},\n\t\t});\n\t}\n\n\t/**\n\t * Cooperative interrupt. Requests the engine's own abort and waits for it —\n\t * no timeout, no termination, no restart. A genuinely wedged engine is the\n\t * user's call to terminate with Ctrl+C (see terminateAndRecover), never an\n\t * automatic consequence of pressing Escape.\n\t */\n\tprivate async abortAndRecover(): Promise<void> {\n\t\tawait this.queuePause.settleBeforeAbort();\n\t\tthis.health.markCooperativeAbortStarted();\n\t\ttry {\n\t\t\tawait this.client.abort();\n\t\t} finally {\n\t\t\tthis.health.markCooperativeAbortSettled();\n\t\t\tthis.engineCallbackActive = false;\n\t\t}\n\t}\n\n\tprivate dispatchBestEffort(label: string, operation: Promise<unknown>): void {\n\t\tvoid operation.catch((error: Error) => {\n\t\t\tif (this.health.isRecovering()) return;\n\t\t\tthis.emitDiagnostic({\n\t\t\t\tactivity: undefined,\n\t\t\t\telapsedMs: 0,\n\t\t\t\tlevel: \"unresponsive\",\n\t\t\t\tmessage: `Interactive engine ${label} failed: ${error.message}`,\n\t\t\t});\n\t\t});\n\t}\n\n\tprivate settleQueueClear(pendingClear: PendingQueueClear, succeeded: boolean): void {\n\t\tif (this.pendingQueueClear !== pendingClear) return;\n\n\t\tpendingClear.count -= 1;\n\t\tpendingClear.succeeded ||= succeeded;\n\t\tif (pendingClear.count > 0) return;\n\n\t\tthis.pendingQueueClear = undefined;\n\t\tif (pendingClear.succeeded || this.queueUpdateGeneration !== pendingClear.queueUpdateGeneration) return;\n\n\t\tthis.steeringMessages = [...pendingClear.snapshot.steering];\n\t\tthis.followUpMessages = [...pendingClear.snapshot.followUp];\n\t}\n\n\tprivate resetUnpersistedSessionView(): void {\n\t\tconst session = super.session;\n\t\tconst manager = SessionManager.create(session.sessionManager.getCwd(), session.sessionManager.getSessionDir());\n\t\tObject.defineProperty(session, \"sessionManager\", { configurable: true, value: manager });\n\t\tthis.patchSessionManager(manager);\n\t\tsession.agent.state.messages = [];\n\t}\n\n\tprivate patchSessionManager(manager: SessionManager): void {\n\t\tObject.defineProperty(manager, \"appendLabelChange\", {\n\t\t\tconfigurable: true,\n\t\t\tvalue: (entryId: string, label?: string) => {\n\t\t\t\tthis.dispatchBestEffort(\n\t\t\t\t\t\"set label\",\n\t\t\t\t\tthis.client\n\t\t\t\t\t\t.requestInternal<void>({ type: \"set_label\", entryId, label })\n\t\t\t\t\t\t.then(() => this.refreshSessionView()),\n\t\t\t\t);\n\t\t\t},\n\t\t});\n\t}\n\n\tprivate refreshSessionView(): void {\n\t\tconst session = super.session;\n\t\tconst sessionFile = session.sessionFile;\n\t\tif (!sessionFile) return;\n\t\tconst currentManager = session.sessionManager;\n\t\tconst refreshed = SessionManager.open(sessionFile, currentManager.getSessionDir(), currentManager.getCwd());\n\t\tObject.defineProperty(session, \"sessionManager\", { configurable: true, value: refreshed });\n\t\tthis.patchSessionManager(refreshed);\n\t\tsession.agent.state.messages = refreshed.buildSessionContext().messages;\n\t}\n\n\tprivate observeEvent(event: RpcEvent): void {\n\t\tconst session = super.session;\n\t\tswitch (event.type) {\n\t\t\tcase \"agent_start\":\n\t\t\t\tthis.streaming = true;\n\t\t\t\tbreak;\n\t\t\tcase \"agent_end\":\n\t\t\t\tthis.streaming = false;\n\t\t\t\tthis.refreshSessionView();\n\t\t\t\tbreak;\n\t\t\tcase \"compaction_start\":\n\t\t\t\tthis.compacting = true;\n\t\t\t\tthis.compactionReason = event.reason;\n\t\t\t\tbreak;\n\t\t\tcase \"compaction_end\":\n\t\t\t\tthis.compacting = false;\n\t\t\t\tthis.compactionReason = undefined;\n\t\t\t\tbreak;\n\t\t\tcase \"queue_update\":\n\t\t\t\tthis.queueUpdateGeneration += 1;\n\t\t\t\tthis.pendingQueueClear = undefined;\n\t\t\t\tthis.steeringMessages = [...event.steering];\n\t\t\t\tthis.followUpMessages = [...event.followUp];\n\t\t\t\tbreak;\n\t\t\tcase \"model_changed\":\n\t\t\t\tsession.agent.state.model = event.model;\n\t\t\t\tbreak;\n\t\t\tcase \"thinking_level_changed\":\n\t\t\t\tsession.agent.state.thinkingLevel = event.level;\n\t\t\t\tbreak;\n\t\t\tcase \"session_info_changed\":\n\t\t\t\tthis.remoteSessionName = event.name;\n\t\t\t\tbreak;\n\t\t}\n\t}\n}\n"]}
@@ -51,6 +51,7 @@ export declare class RpcClient extends RpcClientApi {
51
51
  private readonly pendingRequests;
52
52
  /** Bumped by every explicit stop; a restart holds a permit across its own stop. */
53
53
  private restartRevision;
54
+ private stopPromise;
54
55
  private readonly terminalDrain;
55
56
  private stdoutDrained;
56
57
  private requestId;
@@ -1 +1 @@
1
- {"version":3,"file":"rpc-client.d.ts","sourceRoot":"","sources":["../../../src/modes/rpc/rpc-client.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAE9D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAElE,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,4CAA4C,CAAC;AAC7F,OAAO,KAAK,EAEX,wCAAwC,EAExC,MAAM,4CAA4C,CAAC;AAEpD,OAAO,EACN,KAAK,qBAAqB,EAC1B,KAAK,wBAAwB,EAC7B,KAAK,wBAAwB,EAE7B,MAAM,mCAAmC,CAAC;AAG3C,OAAO,EAAE,YAAY,EAAE,KAAK,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAexE,OAAO,KAAK,EAAc,QAAQ,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAEvH,YAAY,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrE,YAAY,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE/C,MAAM,WAAW,gBAAgB;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,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E,iBAAiB,KAAK,IAAI,EAC7D,OAAO,CAAC,EAAE;QAAE,kBAAkB,CAAC,EAAE,OAAO,CAAC;QAAC,WAAW,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAA;KAAE,GAC5E,OAAO,CAAC,UAAU,CAAC,CAErB;IACD,SAAS,IAAI,MAAM,CAElB;IAED,WAAW,CAAC,OAAO,SAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAE1C;IACD,aAAa,CAAC,OAAO,SAAQ,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC,CAElD;IACK,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,YAAY,EAAE,EAAE,OAAO,SAAQ,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC,CAIlG;IACD,OAAO,CAAC,UAAU;IAmBlB,OAAO,CAAC,SAAS;IAGjB,OAAO,CAAC,4BAA4B;IAMpC,OAAO,CAAC,sBAAsB;IAG9B,OAAO,CAAC,yBAAyB;IAMjC,OAAO,CAAC,+BAA+B;IAkBvC;;;OAGG;IACH,OAAO,CAAC,cAAc;IAatB,kFAAkF;IAClF,OAAO,CAAC,kBAAkB;IAK1B,OAAO,CAAC,sBAAsB;IAiB9B,OAAO,CAAC,aAAa;IASrB,OAAO,CAAC,aAAa;IAIrB,OAAO,CAAC,UAAU;IAWlB,UAAgB,OAAO,CAAC,OAAO,EAAE,cAAc,EAAE,WAAW,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,WAAW,CAAC,CA4CzG;IACD,OAAO,CAAC,aAAa;IAYrB,SAAS,CAAC,IAAI,CAAC,CAAC,EAAE,QAAQ,EAAE,WAAW,GAAG,CAAC,CAI1C;CACD"}
@@ -105,9 +105,18 @@ export class RpcClient extends RpcClientApi {
105
105
  * Explicit stop. Voids any in-flight restart permit, so a replacement caught
106
106
  * between its own stop and start can never spawn after this returns.
107
107
  */
108
- async stop() {
108
+ stop() {
109
109
  this.restartRevision += 1;
110
- await this.stopCurrentGeneration();
110
+ if (this.stopPromise)
111
+ return this.stopPromise;
112
+ if (!this.process)
113
+ return Promise.resolve();
114
+ const stopPromise = this.stopCurrentGeneration().finally(() => {
115
+ if (this.stopPromise === stopPromise)
116
+ this.stopPromise = undefined;
117
+ });
118
+ this.stopPromise = stopPromise;
119
+ return stopPromise;
111
120
  }
112
121
  /**
113
122
  * Tear down the current child without touching the restart permit. The reader
@@ -246,6 +255,10 @@ export class RpcClient extends RpcClientApi {
246
255
  async restart(sessionFile) {
247
256
  const permit = this.restartRevision;
248
257
  await this.stopCurrentGeneration();
258
+ // Join an in-flight stop before the permit check: waiting after it would
259
+ // reopen the window this fence exists to close.
260
+ if (this.stopPromise)
261
+ await this.stopPromise;
249
262
  if (permit !== this.restartRevision)
250
263
  throw rpcTransportError(RESTART_CANCELLED_MESSAGE);
251
264
  this.options = { ...this.options, args: restartCliArgs(this.options.args, sessionFile) };
@@ -1 +1 @@
1
- {"version":3,"file":"rpc-client.js","sourceRoot":"","sources":["../../../src/modes/rpc/rpc-client.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,8BAA8B,EAAE,MAAM,6BAA6B,CAAC;AAE7E,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAO7C,OAAO,EAAE,wBAAwB,EAAE,MAAM,yCAAyC,CAAC;AACnF,OAAO,EAIN,+BAA+B,GAC/B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAuB,MAAM,qBAAqB,CAAC;AACxE,OAAO,EACN,mBAAmB,EACnB,6BAA6B,EAC7B,cAAc,EACd,qBAAqB,EACrB,yBAAyB,GACzB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,gBAAgB,EAAE,sBAAsB,EA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AAS,CAAC;IAClC,CAAC;CACD","sourcesContent":["import type { ChildProcess } from \"node:child_process\";\nimport type { ImageContent } from \"@earendil-works/pi-ai/compat\";\nimport type { BashResult } from \"../../core/bash-executor.ts\";\nimport { CredentialSynchronizationError } from \"../../core/model-runtime.js\";\nimport type { BashOutputChannel } from \"../../core/tools/bash.ts\";\nimport { sleep } from \"../../utils/sleep.ts\";\nimport type { ActivityWatchdogDiagnostic } from \"../interactive-engine/activity-watchdog.ts\";\nimport type {\n\tInteractiveEngineGenerationEnded,\n\tInteractiveEngineGenerationEndedListener,\n\tInteractiveEngineGenerationEndKind,\n} from \"../interactive-engine/engine-generation.ts\";\nimport { InteractiveEngineMonitor } from \"../interactive-engine/engine-monitor.ts\";\nimport {\n\ttype EngineKeybindingState,\n\ttype InteractiveEngineCommand,\n\ttype InteractiveEngineMessage,\n\tserializeInteractiveEngineFrame,\n} from \"../interactive-engine/protocol.ts\";\nimport { attachJsonlLineReader, serializeJsonLine } from \"./jsonl.ts\";\nimport { QueuedWriter } from \"./queued-writer.ts\";\nimport { RpcClientApi, type RpcCommandBody } from \"./rpc-client-api.ts\";\nimport {\n\tappendBoundedStderr,\n\tcreateInteractiveJsonlOptions,\n\trestartCliArgs,\n\tspawnRpcClientProcess,\n\tterminateRpcClientProcess,\n} from \"./rpc-client-process.ts\";\nimport { collectRpcEvents, runUserBashWithUpdates, waitForRpcIdle } from \"./rpc-client-waits.ts\";\nimport { DEFAULT_REQUEST_TIMEOUT_MS, LONG_LIVED_COMMANDS, RESTART_CANCELLED_MESSAGE } from \"./rpc-command-timeouts.ts\";\nimport { RpcEventBuffer } from \"./rpc-event-buffer.ts\";\nimport { GenerationBuffer } from \"./rpc-generation-buffer.ts\";\nimport { RpcPendingRequests } from \"./rpc-pending-requests.ts\";\nimport { RpcTerminalDrain } from \"./rpc-terminal-drain.ts\";\nimport { markRpcTransportFailure, rpcTransportError } from \"./rpc-transport-error.ts\";\nimport type { RpcCommand, RpcEvent, RpcExtensionUIRequest, RpcExtensionUIResponse, RpcResponse } from \"./rpc-types.ts\";\n\nexport type { ModelInfo, RpcCommandBody } from \"./rpc-client-api.ts\";\nexport type { RpcEvent } from \"./rpc-types.ts\";\n\nexport interface RpcClientOptions {\n\tcliPath?: string;\n\tcwd?: string;\n\tenv?: Record<string, string>;\n\tprovider?: string;\n\tmodel?: string;\n\targs?: string[];\n\truntimeExecutable?: string;\n\truntimeArgs?: string[];\n\t/**\n\t * Bounded deadline (ms) applied to short metadata/control requests. Long-lived\n\t * commands (see LONG_LIVED_COMMANDS) never use this timer. Defaults to 30s.\n\t */\n\trequestTimeoutMs?: number;\n\tinteractiveEngine?: {\n\t\tonDiagnostic: (diagnostic: ActivityWatchdogDiagnostic) => void;\n\t\tonActivityChange?: (active: boolean) => void;\n\t\t/**\n\t\t * Heartbeat observer. Deliberately NOT a generic engine-message listener:\n\t\t * subscribing there drains the buffered startup custom-UI messages into the\n\t\t * first subscriber and stops buffering for the real controllers.\n\t\t */\n\t\tonHeartbeat?: () => void;\n\t\t/**\n\t\t * Credential for the engine child. Delivered through the protected\n\t\t * bootstrap file, never through the child's environment or argv.\n\t\t */\n\t\tapiKey?: string;\n\t};\n}\n\nexport type RpcEventListener = (event: RpcEvent) => void;\n\nexport class RpcClient extends RpcClientApi {\n\tprivate process: ChildProcess | null = null;\n\tprivate stopReadingStdout: (() => void) | null = null;\n\tprivate eventListeners: RpcEventListener[] = [];\n\tprivate extensionUIListeners: Array<(request: RpcExtensionUIRequest) => void> = [];\n\tprivate readonly pendingExtensionUIRequests = new GenerationBuffer<RpcExtensionUIRequest>();\n\tprivate engineMessageListeners: Array<(message: InteractiveEngineMessage) => void> = [];\n\tprivate latestEngineKeybindingState: EngineKeybindingState | undefined;\n\tprivate readonly pendingEngineMessages = new GenerationBuffer<InteractiveEngineMessage>();\n\tprivate readonly pendingRequests = new RpcPendingRequests();\n\t/** Bumped by every explicit stop; a restart holds a permit across its own stop. */\n\tprivate restartRevision = 0;\n\tprivate readonly terminalDrain = new RpcTerminalDrain();\n\tprivate stdoutDrained: Promise<void> = Promise.resolve();\n\tprivate requestId = 0;\n\tprivate stderr = \"\";\n\tprivate exitError: Error | null = null;\n\tprivate engineMonitor: InteractiveEngineMonitor | undefined;\n\tprivate eventBuffer: RpcEventBuffer | undefined;\n\tprivate stdinWriter: QueuedWriter | undefined;\n\tprivate generation = 0;\n\tprivate lastEndedGeneration = 0;\n\tprivate generationEndedListeners: InteractiveEngineGenerationEndedListener[] = [];\n\t/**\n\t * The latest generation-end event, retained so a subscriber that attaches\n\t * after the child died still observes it. A child can exit between\n\t * `start()` returning and the runtime constructing its listeners.\n\t */\n\tprivate retainedGenerationEnd: InteractiveEngineGenerationEnded | undefined;\n\tprivate readonly activeActivityIds = new Set<string>();\n\tprivate enginePid: number | undefined;\n\n\tprivate declare options: RpcClientOptions;\n\n\tconstructor(options: RpcClientOptions = {}) {\n\t\tsuper();\n\t\tthis.options = options;\n\t}\n\n\tasync start(): Promise<void> {\n\t\tif (this.process) {\n\t\t\tthrow new Error(\"Client already started\");\n\t\t}\n\n\t\tconst cliPath = this.options.cliPath ?? \"dist/cli.js\";\n\t\tconst args = [\"--mode\", \"rpc\"];\n\n\t\tif (this.options.provider) {\n\t\t\targs.push(\"--provider\", this.options.provider);\n\t\t}\n\t\tif (this.options.model) {\n\t\t\targs.push(\"--model\", this.options.model);\n\t\t}\n\t\tif (this.options.args) {\n\t\t\targs.push(...this.options.args);\n\t\t}\n\n\t\tconst generation = ++this.generation;\n\t\tthis.exitError = null;\n\t\tthis.stderr = \"\";\n\t\tthis.activeActivityIds.clear();\n\t\tthis.enginePid = undefined;\n\t\tthis.engineMonitor = this.options.interactiveEngine\n\t\t\t? new InteractiveEngineMonitor(this.options.interactiveEngine.onDiagnostic, (message) =>\n\t\t\t\t\tthis.observeInteractiveEngineMessage(message, generation),\n\t\t\t\t)\n\t\t\t: undefined;\n\t\tthis.eventBuffer = this.engineMonitor ? new RpcEventBuffer((event) => this.emitEvent(event)) : undefined;\n\t\tconst childProcess = spawnRpcClientProcess({\n\t\t\tcliPath,\n\t\t\tcliArgs: args,\n\t\t\tcwd: this.options.cwd,\n\t\t\tenv: this.options.env,\n\t\t\truntimeExecutable: this.options.runtimeExecutable,\n\t\t\truntimeArgs: this.options.runtimeArgs,\n\t\t\tinteractiveEngine: this.engineMonitor !== undefined,\n\t\t\t...(this.options.interactiveEngine?.apiKey\n\t\t\t\t? { interactiveEngineApiKey: this.options.interactiveEngine.apiKey }\n\t\t\t\t: {}),\n\t\t});\n\t\tthis.process = childProcess;\n\t\tthis.stdinWriter = new QueuedWriter(childProcess.stdin!);\n\n\t\tchildProcess.once(\"exit\", (code, signal) =>\n\t\t\tthis.failGeneration(this.createProcessExitError(code, signal), generation, \"exit\"),\n\t\t);\n\t\tchildProcess.once(\"error\", (rawError) => this.failGeneration(rawError, generation, \"process-error\"));\n\t\tchildProcess.stdin?.on(\"error\", (rawError) => this.failGeneration(rawError, generation, \"stdin-error\"));\n\t\tchildProcess.stderr?.on(\"data\", (data) => {\n\t\t\tif (generation !== this.generation) return;\n\t\t\tthis.stderr = appendBoundedStderr(this.stderr, data.toString());\n\t\t\tprocess.stderr.write(data);\n\t\t});\n\t\tconst readerOptions = createInteractiveJsonlOptions(this.engineMonitor !== undefined);\n\t\tlet markStdoutDrained!: () => void;\n\t\tthis.stdoutDrained = new Promise<void>((resolve) => {\n\t\t\tmarkStdoutDrained = resolve;\n\t\t});\n\t\tthis.stopReadingStdout = attachJsonlLineReader(\n\t\t\tchildProcess.stdout!,\n\t\t\t(line) => {\n\t\t\t\tif (generation === this.generation) this.handleLine(line, generation);\n\t\t\t},\n\t\t\t{ ...readerOptions, onDrained: () => markStdoutDrained() },\n\t\t);\n\t\tif (this.engineMonitor) await this.engineMonitor.waitUntilReady();\n\t\telse await sleep(100);\n\n\t\tif (generation !== this.generation || this.process?.exitCode !== null) {\n\t\t\tthrow rpcTransportError(`Agent process exited immediately. Stderr: ${this.stderr}`);\n\t\t}\n\t}\n\n\t/**\n\t * Explicit stop. Voids any in-flight restart permit, so a replacement caught\n\t * between its own stop and start can never spawn after this returns.\n\t */\n\tasync stop(): Promise<void> {\n\t\tthis.restartRevision += 1;\n\t\tawait this.stopCurrentGeneration();\n\t}\n\n\t/**\n\t * Tear down the current child without touching the restart permit. The reader\n\t * stays attached and the generation stays current until the dead child's\n\t * stdout settles, so an ownership frame it already sent still reaches its\n\t * request; only then is the generation retired (see RpcTerminalDrain).\n\t */\n\tprivate async stopCurrentGeneration(): Promise<void> {\n\t\tconst child = this.process;\n\t\tif (!child) return;\n\t\tconst endedGeneration = this.generation;\n\t\tconst stopError = rpcTransportError(\"Agent process stopped\");\n\t\tthis.invalidateEngineShortcuts();\n\t\tconst terminateTree = this.engineMonitor !== undefined;\n\t\tthis.engineMonitor?.stop();\n\t\tthis.stdinWriter?.close(stopError);\n\t\t// Unblock an in-flight start()/waitUntilBound() for the generation being\n\t\t// replaced. Readiness has no deadline by design, so without this an\n\t\t// explicit stop of a hung replacement child could never be observed.\n\t\tthis.engineMonitor?.fail(stopError);\n\t\tthis.engineMonitor = undefined;\n\t\tthis.stdinWriter = undefined;\n\t\tthis.process = null;\n\t\t// Publish before terminating so host controllers tear down this generation's\n\t\t// UI while the writer is detached: disposal cannot write into a replacement.\n\t\tthis.publishGenerationEnded(endedGeneration, stopError, \"explicit-stop\", true);\n\t\t// Claim before terminating so the exit this provokes does not relabel a\n\t\t// deliberate stop; an exit that already claimed keeps its own error.\n\t\tthis.terminalDrain.claim(endedGeneration, stopError);\n\t\tawait terminateRpcClientProcess(child, terminateTree);\n\t\tawait this.beginTerminalDrain(endedGeneration, stopError);\n\t\tthis.stopReadingStdout?.();\n\t\tthis.stopReadingStdout = null;\n\t\tthis.generation += 1;\n\t\tthis.pendingRequests.rejectAll(stopError);\n\t\tthis.eventBuffer?.dispose();\n\t\tthis.eventBuffer = undefined;\n\t\tthis.activeActivityIds.clear();\n\t\tthis.options.interactiveEngine?.onActivityChange?.(false);\n\t}\n\n\t/** Subscribe to agent events. */\n\tonEvent(listener: RpcEventListener): () => void {\n\t\tthis.eventListeners.push(listener);\n\t\treturn () => {\n\t\t\tconst index = this.eventListeners.indexOf(listener);\n\t\t\tif (index !== -1) {\n\t\t\t\tthis.eventListeners.splice(index, 1);\n\t\t\t}\n\t\t};\n\t}\n\n\tonExtensionUIRequest(listener: (request: RpcExtensionUIRequest) => void): () => void {\n\t\tthis.extensionUIListeners.push(listener);\n\t\tfor (const request of this.pendingExtensionUIRequests.drain(this.generation)) listener(request);\n\t\treturn () => {\n\t\t\tconst index = this.extensionUIListeners.indexOf(listener);\n\t\t\tif (index !== -1) this.extensionUIListeners.splice(index, 1);\n\t\t};\n\t}\n\n\tasync respondExtensionUI(response: RpcExtensionUIResponse): Promise<void> {\n\t\tawait this.requireWriter().write(serializeJsonLine(response));\n\t}\n\n\tonInteractiveEngineMessage(listener: (message: InteractiveEngineMessage) => void): () => void {\n\t\tthis.engineMessageListeners.push(listener);\n\t\tfor (const message of this.pendingEngineMessages.drain(this.generation)) listener(message);\n\t\treturn () => {\n\t\t\tconst index = this.engineMessageListeners.indexOf(listener);\n\t\t\tif (index !== -1) this.engineMessageListeners.splice(index, 1);\n\t\t};\n\t}\n\n\tonInteractiveEngineKeybindingState(listener: (state: EngineKeybindingState) => void): () => void {\n\t\tconst messageListener = (message: InteractiveEngineMessage): void => {\n\t\t\tif (message.type === \"engine_keybindings_reloaded\") listener(message.state);\n\t\t};\n\t\tthis.engineMessageListeners.push(messageListener);\n\t\tif (this.latestEngineKeybindingState) listener(this.latestEngineKeybindingState);\n\t\treturn () => {\n\t\t\tconst index = this.engineMessageListeners.indexOf(messageListener);\n\t\t\tif (index !== -1) this.engineMessageListeners.splice(index, 1);\n\t\t};\n\t}\n\n\t/**\n\t * Subscribe to host-local generation death. Fires at most once per\n\t * generation, synchronously, before any restart work. A death that has\n\t * already happened for the current generation replays immediately, so a\n\t * listener attached after an exit still sees it.\n\t */\n\tonGenerationEnded(listener: InteractiveEngineGenerationEndedListener): () => void {\n\t\tthis.generationEndedListeners.push(listener);\n\t\tconst retained = this.retainedGenerationEnd;\n\t\t// Only while it still describes the live generation: once stop()/start()\n\t\t// has moved on, that death belongs to a replaced child.\n\t\tif (retained && retained.generation === this.generation) listener(retained);\n\t\treturn () => {\n\t\t\tconst index = this.generationEndedListeners.indexOf(listener);\n\t\t\tif (index !== -1) this.generationEndedListeners.splice(index, 1);\n\t\t};\n\t}\n\n\tsendInteractiveEngineCommand(command: InteractiveEngineCommand): void {\n\t\tconst writer = this.stdinWriter;\n\t\tif (!writer) return;\n\t\tconst frame = serializeInteractiveEngineFrame(command);\n\t\tif (\n\t\t\tcommand.type === \"engine_custom_render\" ||\n\t\t\tcommand.type === \"engine_tool_render\" ||\n\t\t\tcommand.type === \"engine_message_render\"\n\t\t) {\n\t\t\twriter.offerLatest(`render:${command.componentId}`, frame);\n\t\t\treturn;\n\t\t}\n\t\tthis.bestEffort(writer.write(frame), `engine command ${command.type}`);\n\t}\n\twaitForInteractiveEngineBound(): Promise<void> {\n\t\treturn this.engineMonitor?.waitUntilBound() ?? Promise.resolve();\n\t}\n\tgetEnginePid(): number | undefined {\n\t\treturn this.enginePid;\n\t}\n\tgetGeneration(): number {\n\t\treturn this.generation;\n\t}\n\n\t/**\n\t * Replace the engine child, unless an explicit stop supersedes this attempt.\n\t * The permit is checked immediately before spawning, so a `stop()` in that\n\t * window is always observed; cancellation throws rather than returning\n\t * quietly, because callers go on to initialize against the new child.\n\t */\n\tasync restart(sessionFile: string | undefined): Promise<void> {\n\t\tconst permit = this.restartRevision;\n\t\tawait this.stopCurrentGeneration();\n\t\tif (permit !== this.restartRevision) throw rpcTransportError(RESTART_CANCELLED_MESSAGE);\n\t\tthis.options = { ...this.options, args: restartCliArgs(this.options.args, sessionFile) };\n\t\tawait this.start();\n\t\tawait this.waitForInteractiveEngineBound();\n\t}\n\n\tasync requestInternal<T>(command: RpcCommandBody): Promise<T> {\n\t\treturn this.data<T>(await this.request(command));\n\t}\n\tuserBashWithUpdates(\n\t\tcommand: string,\n\t\tonUpdate: (delta: string, channel: BashOutputChannel) => void,\n\t\toptions?: { excludeFromContext?: boolean; onRequestId?: (id: string) => void },\n\t): Promise<BashResult> {\n\t\treturn runUserBashWithUpdates(this, command, onUpdate, options, (body, onId) => this.request(body, onId));\n\t}\n\tgetStderr(): string {\n\t\treturn this.stderr;\n\t}\n\n\twaitForIdle(timeout = 60000): Promise<void> {\n\t\treturn waitForRpcIdle(this, timeout);\n\t}\n\tcollectEvents(timeout = 60000): Promise<RpcEvent[]> {\n\t\treturn collectRpcEvents(this, timeout);\n\t}\n\tasync promptAndWait(message: string, images?: ImageContent[], timeout = 60000): Promise<RpcEvent[]> {\n\t\tconst eventsPromise = this.collectEvents(timeout);\n\t\tawait this.prompt(message, images);\n\t\treturn eventsPromise;\n\t}\n\tprivate handleLine(line: string, generation: number): void {\n\t\tif (this.terminalDrain.observe(generation, line, (id) => this.pendingRequests.markAccepted(id))) return;\n\t\tif (this.engineMonitor?.handleLine(line)) return;\n\t\ttry {\n\t\t\tconst data = JSON.parse(line) as { type?: string; id?: string };\n\t\t\tif (data.type === \"extension_ui_request\") {\n\t\t\t\tconst request = data as RpcExtensionUIRequest;\n\t\t\t\tif (this.extensionUIListeners.length === 0) this.pendingExtensionUIRequests.push(generation, request);\n\t\t\t\tfor (const listener of this.extensionUIListeners) listener(request);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (data.type === \"response\" && data.id && this.pendingRequests.resolve(data.id, data as RpcResponse)) return;\n\t\t\tconst event = data as RpcEvent;\n\t\t\tif (this.eventBuffer) this.eventBuffer.enqueue(event);\n\t\t\telse this.emitEvent(event);\n\t\t} catch {\n\t\t\tif (this.engineMonitor) this.failTransport(rpcTransportError(\"Interactive engine emitted malformed JSONL\"));\n\t\t}\n\t}\n\tprivate emitEvent(event: RpcEvent): void {\n\t\tfor (const listener of this.eventListeners) listener(event);\n\t}\n\tprivate emitInteractiveEngineMessage(message: InteractiveEngineMessage, generation: number): void {\n\t\tif (this.engineMessageListeners.length === 0 && message.type.startsWith(\"engine_custom_\")) {\n\t\t\tthis.pendingEngineMessages.push(generation, message);\n\t\t}\n\t\tfor (const listener of this.engineMessageListeners) listener(message);\n\t}\n\tprivate createProcessExitError(code: number | null, signal: NodeJS.Signals | null): Error {\n\t\treturn rpcTransportError(`Agent process exited (code=${code} signal=${signal}). Stderr: ${this.stderr}`);\n\t}\n\tprivate invalidateEngineShortcuts(): void {\n\t\tif (!this.latestEngineKeybindingState || this.latestEngineKeybindingState.shortcuts.length === 0) return;\n\t\tconst state: EngineKeybindingState = { ...this.latestEngineKeybindingState, shortcuts: [] };\n\t\tthis.latestEngineKeybindingState = state;\n\t\tthis.emitInteractiveEngineMessage({ type: \"engine_keybindings_reloaded\", state }, this.generation);\n\t}\n\tprivate observeInteractiveEngineMessage(message: InteractiveEngineMessage, generation: number): void {\n\t\t// Ownership is the one thing a dead generation may still report: request\n\t\t// ids never repeat, and the alternative is classifying work it already\n\t\t// started as never sent. Nothing else from it may touch host state — a\n\t\t// stale frame would revive a PID, an activity, or a mount that is gone.\n\t\tif (message.type === \"engine_request_accepted\") {\n\t\t\tif (generation === this.generation) this.pendingRequests.markAccepted(message.requestId);\n\t\t\treturn;\n\t\t}\n\t\tif (generation !== this.generation || generation <= this.lastEndedGeneration) return;\n\t\tif (message.type === \"engine_heartbeat\") this.options.interactiveEngine?.onHeartbeat?.();\n\t\tif (message.type === \"engine_ready\") this.enginePid = message.pid;\n\t\tif (message.type === \"engine_keybindings_reloaded\") this.latestEngineKeybindingState = message.state;\n\t\tif (message.type === \"engine_activity_started\") this.activeActivityIds.add(message.activity.id);\n\t\telse if (message.type === \"engine_activity_finished\") this.activeActivityIds.delete(message.activityId);\n\t\tthis.options.interactiveEngine?.onActivityChange?.(this.activeActivityIds.size > 0);\n\t\tthis.emitInteractiveEngineMessage(message, generation);\n\t}\n\t/**\n\t * Shared teardown for every unexpected end of `generation`. Death publishes\n\t * at once for the host UI; its requests wait for stdout (RpcTerminalDrain).\n\t */\n\tprivate failGeneration(rawError: Error, generation: number, kind: InteractiveEngineGenerationEndKind): void {\n\t\tif (generation !== this.generation) return;\n\t\tconst error = markRpcTransportFailure(rawError);\n\t\tthis.exitError = error;\n\t\tthis.stdinWriter?.close(error);\n\t\tthis.engineMonitor?.fail(error);\n\t\tif (kind === \"exit\") {\n\t\t\tthis.activeActivityIds.clear();\n\t\t\tthis.options.interactiveEngine?.onActivityChange?.(false);\n\t\t}\n\t\tthis.beginTerminalDrain(generation, error);\n\t\tthis.publishGenerationEnded(generation, error, kind, false);\n\t}\n\t/** Hold this generation's requests until its stdout drains (RpcTerminalDrain). */\n\tprivate beginTerminalDrain(generation: number, error: Error): Promise<void> {\n\t\treturn this.terminalDrain.begin(generation, this.stdoutDrained, error, (settled) => {\n\t\t\tif (generation === this.generation) this.pendingRequests.rejectAll(settled);\n\t\t});\n\t}\n\tprivate publishGenerationEnded(\n\t\tgeneration: number,\n\t\terror: Error,\n\t\tkind: InteractiveEngineGenerationEndKind,\n\t\texpected: boolean,\n\t): void {\n\t\tif (generation <= this.lastEndedGeneration) return;\n\t\tthis.lastEndedGeneration = generation;\n\t\tconst event: InteractiveEngineGenerationEnded = { generation, error, kind, expected };\n\t\tthis.retainedGenerationEnd = event;\n\t\t// Death is a strict boundary: drop this generation's buffered frames\n\t\t// BEFORE teardown runs, so no listener can drain a stale mount frame\n\t\t// while it is closing that very generation's components.\n\t\tthis.pendingEngineMessages.dropGeneration(generation);\n\t\tthis.pendingExtensionUIRequests.dropGeneration(generation);\n\t\tfor (const listener of [...this.generationEndedListeners]) listener(event);\n\t}\n\tprivate failTransport(rawError: Error): void {\n\t\tthis.options.interactiveEngine?.onDiagnostic({\n\t\t\tactivity: undefined,\n\t\t\telapsedMs: 0,\n\t\t\tlevel: \"unresponsive\",\n\t\t\tmessage: rawError.message,\n\t\t});\n\t\tthis.failGeneration(rawError, this.generation, \"transport-error\");\n\t}\n\tprivate requireWriter(): QueuedWriter {\n\t\tif (!this.stdinWriter) throw rpcTransportError(\"Agent process stdin is not writable\");\n\t\treturn this.stdinWriter;\n\t}\n\tprivate bestEffort(operation: Promise<void>, label: string): void {\n\t\tvoid operation.catch((error: Error) => {\n\t\t\tif (!this.process || this.exitError) return;\n\t\t\tthis.options.interactiveEngine?.onDiagnostic({\n\t\t\t\tactivity: undefined,\n\t\t\t\telapsedMs: 0,\n\t\t\t\tlevel: \"unresponsive\",\n\t\t\t\tmessage: `Interactive engine ${label} failed: ${error.message}`,\n\t\t\t});\n\t\t});\n\t}\n\tprotected async request(command: RpcCommandBody, onRequestId?: (id: string) => void): Promise<RpcResponse> {\n\t\tconst childProcess = this.process;\n\t\tif (!childProcess) throw rpcTransportError(\"Client not started\");\n\t\tif (this.exitError) throw this.exitError;\n\t\tif (childProcess.exitCode !== null) {\n\t\t\tconst error = this.createProcessExitError(childProcess.exitCode, childProcess.signalCode);\n\t\t\tthis.exitError = error;\n\t\t\tthrow error;\n\t\t}\n\t\tconst id = `req_${++this.requestId}`;\n\t\tonRequestId?.(id);\n\t\tconst fullCommand = { ...command, id } as RpcCommand;\n\t\tlet timeout: ReturnType<typeof setTimeout> | undefined;\n\t\tlet rejectResponse!: (error: Error) => void;\n\t\tconst response = new Promise<RpcResponse>((resolve, reject) => {\n\t\t\trejectResponse = reject;\n\t\t\tthis.pendingRequests.add(id, {\n\t\t\t\tresolve: (value) => {\n\t\t\t\t\tif (timeout) clearTimeout(timeout);\n\t\t\t\t\tresolve(value);\n\t\t\t\t},\n\t\t\t\treject: (error) => {\n\t\t\t\t\tif (timeout) clearTimeout(timeout);\n\t\t\t\t\treject(error);\n\t\t\t\t},\n\t\t\t});\n\t\t});\n\t\ttry {\n\t\t\tawait this.requireWriter().write(serializeJsonLine(fullCommand));\n\t\t} catch (error) {\n\t\t\tthis.pendingRequests.delete(id);\n\t\t\t// Idempotent: the writer already classified this, but a caller-supplied\n\t\t\t// stream can reject with anything, and a send that never left the host\n\t\t\t// is a transport failure whatever it threw.\n\t\t\trejectResponse(markRpcTransportFailure(error));\n\t\t\treturn response;\n\t\t}\n\t\tif (this.pendingRequests.has(id) && !LONG_LIVED_COMMANDS.has(command.type)) {\n\t\t\ttimeout = setTimeout(() => {\n\t\t\t\tthis.pendingRequests.delete(id);\n\t\t\t\trejectResponse(new Error(`Timeout waiting for response to ${command.type}. Stderr: ${this.stderr}`));\n\t\t\t}, this.options.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS);\n\t\t}\n\t\treturn response;\n\t}\n\tprivate assertSuccess(response: RpcResponse): void {\n\t\tif (response.success) return;\n\t\tif (response.errorCode === \"credential_synchronization\" && response.errorDetails) {\n\t\t\tthrow new CredentialSynchronizationError(\n\t\t\t\tresponse.errorDetails.providerId,\n\t\t\t\tresponse.errorDetails.operation,\n\t\t\t\tundefined,\n\t\t\t\t{ cause: new Error(response.error) },\n\t\t\t);\n\t\t}\n\t\tthrow new Error(response.error);\n\t}\n\tprotected data<T>(response: RpcResponse): T {\n\t\tthis.assertSuccess(response);\n\t\tconst successResponse = response as Extract<RpcResponse, { success: true; data: unknown }>;\n\t\treturn successResponse.data as T;\n\t}\n}\n"]}
1
+ {"version":3,"file":"rpc-client.js","sourceRoot":"","sources":["../../../src/modes/rpc/rpc-client.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,8BAA8B,EAAE,MAAM,6BAA6B,CAAC;AAE7E,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAO7C,OAAO,EAAE,wBAAwB,EAAE,MAAM,yCAAyC,CAAC;AACnF,OAAO,EAIN,+BAA+B,GAC/B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAuB,MAAM,qBAAqB,CAAC;AACxE,OAAO,EACN,mBAAmB,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O,aAAa,CAAC,QAAqB;QAC1C,IAAI,QAAQ,CAAC,OAAO;YAAE,OAAO;QAC7B,IAAI,QAAQ,CAAC,SAAS,KAAK,4BAA4B,IAAI,QAAQ,CAAC,YAAY,EAAE,CAAC;YAClF,MAAM,IAAI,8BAA8B,CACvC,QAAQ,CAAC,YAAY,CAAC,UAAU,EAChC,QAAQ,CAAC,YAAY,CAAC,SAAS,EAC/B,SAAS,EACT,EAAE,KAAK,EAAE,IAAI,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CACpC,CAAC;QACH,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IACjC,CAAC;IACS,IAAI,CAAI,QAAqB;QACtC,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;QAC7B,MAAM,eAAe,GAAG,QAAkE,CAAC;QAC3F,OAAO,eAAe,CAAC,IAAS,CAAC;IAClC,CAAC;CACD","sourcesContent":["import type { ChildProcess } from \"node:child_process\";\nimport type { ImageContent } from \"@earendil-works/pi-ai/compat\";\nimport type { BashResult } from \"../../core/bash-executor.ts\";\nimport { CredentialSynchronizationError } from \"../../core/model-runtime.js\";\nimport type { BashOutputChannel } from \"../../core/tools/bash.ts\";\nimport { sleep } from \"../../utils/sleep.ts\";\nimport type { ActivityWatchdogDiagnostic } from \"../interactive-engine/activity-watchdog.ts\";\nimport type {\n\tInteractiveEngineGenerationEnded,\n\tInteractiveEngineGenerationEndedListener,\n\tInteractiveEngineGenerationEndKind,\n} from \"../interactive-engine/engine-generation.ts\";\nimport { InteractiveEngineMonitor } from \"../interactive-engine/engine-monitor.ts\";\nimport {\n\ttype EngineKeybindingState,\n\ttype InteractiveEngineCommand,\n\ttype InteractiveEngineMessage,\n\tserializeInteractiveEngineFrame,\n} from \"../interactive-engine/protocol.ts\";\nimport { attachJsonlLineReader, serializeJsonLine } from \"./jsonl.ts\";\nimport { QueuedWriter } from \"./queued-writer.ts\";\nimport { RpcClientApi, type RpcCommandBody } from \"./rpc-client-api.ts\";\nimport {\n\tappendBoundedStderr,\n\tcreateInteractiveJsonlOptions,\n\trestartCliArgs,\n\tspawnRpcClientProcess,\n\tterminateRpcClientProcess,\n} from \"./rpc-client-process.ts\";\nimport { collectRpcEvents, runUserBashWithUpdates, waitForRpcIdle } from \"./rpc-client-waits.ts\";\nimport { DEFAULT_REQUEST_TIMEOUT_MS, LONG_LIVED_COMMANDS, RESTART_CANCELLED_MESSAGE } from \"./rpc-command-timeouts.ts\";\nimport { RpcEventBuffer } from \"./rpc-event-buffer.ts\";\nimport { GenerationBuffer } from \"./rpc-generation-buffer.ts\";\nimport { RpcPendingRequests } from \"./rpc-pending-requests.ts\";\nimport { RpcTerminalDrain } from \"./rpc-terminal-drain.ts\";\nimport { markRpcTransportFailure, rpcTransportError } from \"./rpc-transport-error.ts\";\nimport type { RpcCommand, RpcEvent, RpcExtensionUIRequest, RpcExtensionUIResponse, RpcResponse } from \"./rpc-types.ts\";\n\nexport type { ModelInfo, RpcCommandBody } from \"./rpc-client-api.ts\";\nexport type { RpcEvent } from \"./rpc-types.ts\";\n\nexport interface RpcClientOptions {\n\tcliPath?: string;\n\tcwd?: string;\n\tenv?: Record<string, string>;\n\tprovider?: string;\n\tmodel?: string;\n\targs?: string[];\n\truntimeExecutable?: string;\n\truntimeArgs?: string[];\n\t/**\n\t * Bounded deadline (ms) applied to short metadata/control requests. Long-lived\n\t * commands (see LONG_LIVED_COMMANDS) never use this timer. Defaults to 30s.\n\t */\n\trequestTimeoutMs?: number;\n\tinteractiveEngine?: {\n\t\tonDiagnostic: (diagnostic: ActivityWatchdogDiagnostic) => void;\n\t\tonActivityChange?: (active: boolean) => void;\n\t\t/**\n\t\t * Heartbeat observer. Deliberately NOT a generic engine-message listener:\n\t\t * subscribing there drains the buffered startup custom-UI messages into the\n\t\t * first subscriber and stops buffering for the real controllers.\n\t\t */\n\t\tonHeartbeat?: () => void;\n\t\t/**\n\t\t * Credential for the engine child. Delivered through the protected\n\t\t * bootstrap file, never through the child's environment or argv.\n\t\t */\n\t\tapiKey?: string;\n\t};\n}\n\nexport type RpcEventListener = (event: RpcEvent) => void;\n\nexport class RpcClient extends RpcClientApi {\n\tprivate process: ChildProcess | null = null;\n\tprivate stopReadingStdout: (() => void) | null = null;\n\tprivate eventListeners: RpcEventListener[] = [];\n\tprivate extensionUIListeners: Array<(request: RpcExtensionUIRequest) => void> = [];\n\tprivate readonly pendingExtensionUIRequests = new GenerationBuffer<RpcExtensionUIRequest>();\n\tprivate engineMessageListeners: Array<(message: InteractiveEngineMessage) => void> = [];\n\tprivate latestEngineKeybindingState: EngineKeybindingState | undefined;\n\tprivate readonly pendingEngineMessages = new GenerationBuffer<InteractiveEngineMessage>();\n\tprivate readonly pendingRequests = new RpcPendingRequests();\n\t/** Bumped by every explicit stop; a restart holds a permit across its own stop. */\n\tprivate restartRevision = 0;\n\tprivate stopPromise: Promise<void> | undefined;\n\tprivate readonly terminalDrain = new RpcTerminalDrain();\n\tprivate stdoutDrained: Promise<void> = Promise.resolve();\n\tprivate requestId = 0;\n\tprivate stderr = \"\";\n\tprivate exitError: Error | null = null;\n\tprivate engineMonitor: InteractiveEngineMonitor | undefined;\n\tprivate eventBuffer: RpcEventBuffer | undefined;\n\tprivate stdinWriter: QueuedWriter | undefined;\n\tprivate generation = 0;\n\tprivate lastEndedGeneration = 0;\n\tprivate generationEndedListeners: InteractiveEngineGenerationEndedListener[] = [];\n\t/**\n\t * The latest generation-end event, retained so a subscriber that attaches\n\t * after the child died still observes it. A child can exit between\n\t * `start()` returning and the runtime constructing its listeners.\n\t */\n\tprivate retainedGenerationEnd: InteractiveEngineGenerationEnded | undefined;\n\tprivate readonly activeActivityIds = new Set<string>();\n\tprivate enginePid: number | undefined;\n\n\tprivate declare options: RpcClientOptions;\n\n\tconstructor(options: RpcClientOptions = {}) {\n\t\tsuper();\n\t\tthis.options = options;\n\t}\n\n\tasync start(): Promise<void> {\n\t\tif (this.process) {\n\t\t\tthrow new Error(\"Client already started\");\n\t\t}\n\n\t\tconst cliPath = this.options.cliPath ?? \"dist/cli.js\";\n\t\tconst args = [\"--mode\", \"rpc\"];\n\n\t\tif (this.options.provider) {\n\t\t\targs.push(\"--provider\", this.options.provider);\n\t\t}\n\t\tif (this.options.model) {\n\t\t\targs.push(\"--model\", this.options.model);\n\t\t}\n\t\tif (this.options.args) {\n\t\t\targs.push(...this.options.args);\n\t\t}\n\n\t\tconst generation = ++this.generation;\n\t\tthis.exitError = null;\n\t\tthis.stderr = \"\";\n\t\tthis.activeActivityIds.clear();\n\t\tthis.enginePid = undefined;\n\t\tthis.engineMonitor = this.options.interactiveEngine\n\t\t\t? new InteractiveEngineMonitor(this.options.interactiveEngine.onDiagnostic, (message) =>\n\t\t\t\t\tthis.observeInteractiveEngineMessage(message, generation),\n\t\t\t\t)\n\t\t\t: undefined;\n\t\tthis.eventBuffer = this.engineMonitor ? new RpcEventBuffer((event) => this.emitEvent(event)) : undefined;\n\t\tconst childProcess = spawnRpcClientProcess({\n\t\t\tcliPath,\n\t\t\tcliArgs: args,\n\t\t\tcwd: this.options.cwd,\n\t\t\tenv: this.options.env,\n\t\t\truntimeExecutable: this.options.runtimeExecutable,\n\t\t\truntimeArgs: this.options.runtimeArgs,\n\t\t\tinteractiveEngine: this.engineMonitor !== undefined,\n\t\t\t...(this.options.interactiveEngine?.apiKey\n\t\t\t\t? { interactiveEngineApiKey: this.options.interactiveEngine.apiKey }\n\t\t\t\t: {}),\n\t\t});\n\t\tthis.process = childProcess;\n\t\tthis.stdinWriter = new QueuedWriter(childProcess.stdin!);\n\n\t\tchildProcess.once(\"exit\", (code, signal) =>\n\t\t\tthis.failGeneration(this.createProcessExitError(code, signal), generation, \"exit\"),\n\t\t);\n\t\tchildProcess.once(\"error\", (rawError) => this.failGeneration(rawError, generation, \"process-error\"));\n\t\tchildProcess.stdin?.on(\"error\", (rawError) => this.failGeneration(rawError, generation, \"stdin-error\"));\n\t\tchildProcess.stderr?.on(\"data\", (data) => {\n\t\t\tif (generation !== this.generation) return;\n\t\t\tthis.stderr = appendBoundedStderr(this.stderr, data.toString());\n\t\t\tprocess.stderr.write(data);\n\t\t});\n\t\tconst readerOptions = createInteractiveJsonlOptions(this.engineMonitor !== undefined);\n\t\tlet markStdoutDrained!: () => void;\n\t\tthis.stdoutDrained = new Promise<void>((resolve) => {\n\t\t\tmarkStdoutDrained = resolve;\n\t\t});\n\t\tthis.stopReadingStdout = attachJsonlLineReader(\n\t\t\tchildProcess.stdout!,\n\t\t\t(line) => {\n\t\t\t\tif (generation === this.generation) this.handleLine(line, generation);\n\t\t\t},\n\t\t\t{ ...readerOptions, onDrained: () => markStdoutDrained() },\n\t\t);\n\t\tif (this.engineMonitor) await this.engineMonitor.waitUntilReady();\n\t\telse await sleep(100);\n\n\t\tif (generation !== this.generation || this.process?.exitCode !== null) {\n\t\t\tthrow rpcTransportError(`Agent process exited immediately. Stderr: ${this.stderr}`);\n\t\t}\n\t}\n\n\t/**\n\t * Explicit stop. Voids any in-flight restart permit, so a replacement caught\n\t * between its own stop and start can never spawn after this returns.\n\t */\n\tstop(): Promise<void> {\n\t\tthis.restartRevision += 1;\n\t\tif (this.stopPromise) return this.stopPromise;\n\t\tif (!this.process) return Promise.resolve();\n\t\tconst stopPromise = this.stopCurrentGeneration().finally(() => {\n\t\t\tif (this.stopPromise === stopPromise) this.stopPromise = undefined;\n\t\t});\n\t\tthis.stopPromise = stopPromise;\n\t\treturn stopPromise;\n\t}\n\n\t/**\n\t * Tear down the current child without touching the restart permit. The reader\n\t * stays attached and the generation stays current until the dead child's\n\t * stdout settles, so an ownership frame it already sent still reaches its\n\t * request; only then is the generation retired (see RpcTerminalDrain).\n\t */\n\tprivate async stopCurrentGeneration(): Promise<void> {\n\t\tconst child = this.process;\n\t\tif (!child) return;\n\t\tconst endedGeneration = this.generation;\n\t\tconst stopError = rpcTransportError(\"Agent process stopped\");\n\t\tthis.invalidateEngineShortcuts();\n\t\tconst terminateTree = this.engineMonitor !== undefined;\n\t\tthis.engineMonitor?.stop();\n\t\tthis.stdinWriter?.close(stopError);\n\t\t// Unblock an in-flight start()/waitUntilBound() for the generation being\n\t\t// replaced. Readiness has no deadline by design, so without this an\n\t\t// explicit stop of a hung replacement child could never be observed.\n\t\tthis.engineMonitor?.fail(stopError);\n\t\tthis.engineMonitor = undefined;\n\t\tthis.stdinWriter = undefined;\n\t\tthis.process = null;\n\t\t// Publish before terminating so host controllers tear down this generation's\n\t\t// UI while the writer is detached: disposal cannot write into a replacement.\n\t\tthis.publishGenerationEnded(endedGeneration, stopError, \"explicit-stop\", true);\n\t\t// Claim before terminating so the exit this provokes does not relabel a\n\t\t// deliberate stop; an exit that already claimed keeps its own error.\n\t\tthis.terminalDrain.claim(endedGeneration, stopError);\n\t\tawait terminateRpcClientProcess(child, terminateTree);\n\t\tawait this.beginTerminalDrain(endedGeneration, stopError);\n\t\tthis.stopReadingStdout?.();\n\t\tthis.stopReadingStdout = null;\n\t\tthis.generation += 1;\n\t\tthis.pendingRequests.rejectAll(stopError);\n\t\tthis.eventBuffer?.dispose();\n\t\tthis.eventBuffer = undefined;\n\t\tthis.activeActivityIds.clear();\n\t\tthis.options.interactiveEngine?.onActivityChange?.(false);\n\t}\n\n\t/** Subscribe to agent events. */\n\tonEvent(listener: RpcEventListener): () => void {\n\t\tthis.eventListeners.push(listener);\n\t\treturn () => {\n\t\t\tconst index = this.eventListeners.indexOf(listener);\n\t\t\tif (index !== -1) {\n\t\t\t\tthis.eventListeners.splice(index, 1);\n\t\t\t}\n\t\t};\n\t}\n\n\tonExtensionUIRequest(listener: (request: RpcExtensionUIRequest) => void): () => void {\n\t\tthis.extensionUIListeners.push(listener);\n\t\tfor (const request of this.pendingExtensionUIRequests.drain(this.generation)) listener(request);\n\t\treturn () => {\n\t\t\tconst index = this.extensionUIListeners.indexOf(listener);\n\t\t\tif (index !== -1) this.extensionUIListeners.splice(index, 1);\n\t\t};\n\t}\n\n\tasync respondExtensionUI(response: RpcExtensionUIResponse): Promise<void> {\n\t\tawait this.requireWriter().write(serializeJsonLine(response));\n\t}\n\n\tonInteractiveEngineMessage(listener: (message: InteractiveEngineMessage) => void): () => void {\n\t\tthis.engineMessageListeners.push(listener);\n\t\tfor (const message of this.pendingEngineMessages.drain(this.generation)) listener(message);\n\t\treturn () => {\n\t\t\tconst index = this.engineMessageListeners.indexOf(listener);\n\t\t\tif (index !== -1) this.engineMessageListeners.splice(index, 1);\n\t\t};\n\t}\n\n\tonInteractiveEngineKeybindingState(listener: (state: EngineKeybindingState) => void): () => void {\n\t\tconst messageListener = (message: InteractiveEngineMessage): void => {\n\t\t\tif (message.type === \"engine_keybindings_reloaded\") listener(message.state);\n\t\t};\n\t\tthis.engineMessageListeners.push(messageListener);\n\t\tif (this.latestEngineKeybindingState) listener(this.latestEngineKeybindingState);\n\t\treturn () => {\n\t\t\tconst index = this.engineMessageListeners.indexOf(messageListener);\n\t\t\tif (index !== -1) this.engineMessageListeners.splice(index, 1);\n\t\t};\n\t}\n\n\t/**\n\t * Subscribe to host-local generation death. Fires at most once per\n\t * generation, synchronously, before any restart work. A death that has\n\t * already happened for the current generation replays immediately, so a\n\t * listener attached after an exit still sees it.\n\t */\n\tonGenerationEnded(listener: InteractiveEngineGenerationEndedListener): () => void {\n\t\tthis.generationEndedListeners.push(listener);\n\t\tconst retained = this.retainedGenerationEnd;\n\t\t// Only while it still describes the live generation: once stop()/start()\n\t\t// has moved on, that death belongs to a replaced child.\n\t\tif (retained && retained.generation === this.generation) listener(retained);\n\t\treturn () => {\n\t\t\tconst index = this.generationEndedListeners.indexOf(listener);\n\t\t\tif (index !== -1) this.generationEndedListeners.splice(index, 1);\n\t\t};\n\t}\n\n\tsendInteractiveEngineCommand(command: InteractiveEngineCommand): void {\n\t\tconst writer = this.stdinWriter;\n\t\tif (!writer) return;\n\t\tconst frame = serializeInteractiveEngineFrame(command);\n\t\tif (\n\t\t\tcommand.type === \"engine_custom_render\" ||\n\t\t\tcommand.type === \"engine_tool_render\" ||\n\t\t\tcommand.type === \"engine_message_render\"\n\t\t) {\n\t\t\twriter.offerLatest(`render:${command.componentId}`, frame);\n\t\t\treturn;\n\t\t}\n\t\tthis.bestEffort(writer.write(frame), `engine command ${command.type}`);\n\t}\n\twaitForInteractiveEngineBound(): Promise<void> {\n\t\treturn this.engineMonitor?.waitUntilBound() ?? Promise.resolve();\n\t}\n\tgetEnginePid(): number | undefined {\n\t\treturn this.enginePid;\n\t}\n\tgetGeneration(): number {\n\t\treturn this.generation;\n\t}\n\n\t/**\n\t * Replace the engine child, unless an explicit stop supersedes this attempt.\n\t * The permit is checked immediately before spawning, so a `stop()` in that\n\t * window is always observed; cancellation throws rather than returning\n\t * quietly, because callers go on to initialize against the new child.\n\t */\n\tasync restart(sessionFile: string | undefined): Promise<void> {\n\t\tconst permit = this.restartRevision;\n\t\tawait this.stopCurrentGeneration();\n\t\t// Join an in-flight stop before the permit check: waiting after it would\n\t\t// reopen the window this fence exists to close.\n\t\tif (this.stopPromise) await this.stopPromise;\n\t\tif (permit !== this.restartRevision) throw rpcTransportError(RESTART_CANCELLED_MESSAGE);\n\t\tthis.options = { ...this.options, args: restartCliArgs(this.options.args, sessionFile) };\n\t\tawait this.start();\n\t\tawait this.waitForInteractiveEngineBound();\n\t}\n\n\tasync requestInternal<T>(command: RpcCommandBody): Promise<T> {\n\t\treturn this.data<T>(await this.request(command));\n\t}\n\tuserBashWithUpdates(\n\t\tcommand: string,\n\t\tonUpdate: (delta: string, channel: BashOutputChannel) => void,\n\t\toptions?: { excludeFromContext?: boolean; onRequestId?: (id: string) => void },\n\t): Promise<BashResult> {\n\t\treturn runUserBashWithUpdates(this, command, onUpdate, options, (body, onId) => this.request(body, onId));\n\t}\n\tgetStderr(): string {\n\t\treturn this.stderr;\n\t}\n\n\twaitForIdle(timeout = 60000): Promise<void> {\n\t\treturn waitForRpcIdle(this, timeout);\n\t}\n\tcollectEvents(timeout = 60000): Promise<RpcEvent[]> {\n\t\treturn collectRpcEvents(this, timeout);\n\t}\n\tasync promptAndWait(message: string, images?: ImageContent[], timeout = 60000): Promise<RpcEvent[]> {\n\t\tconst eventsPromise = this.collectEvents(timeout);\n\t\tawait this.prompt(message, images);\n\t\treturn eventsPromise;\n\t}\n\tprivate handleLine(line: string, generation: number): void {\n\t\tif (this.terminalDrain.observe(generation, line, (id) => this.pendingRequests.markAccepted(id))) return;\n\t\tif (this.engineMonitor?.handleLine(line)) return;\n\t\ttry {\n\t\t\tconst data = JSON.parse(line) as { type?: string; id?: string };\n\t\t\tif (data.type === \"extension_ui_request\") {\n\t\t\t\tconst request = data as RpcExtensionUIRequest;\n\t\t\t\tif (this.extensionUIListeners.length === 0) this.pendingExtensionUIRequests.push(generation, request);\n\t\t\t\tfor (const listener of this.extensionUIListeners) listener(request);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (data.type === \"response\" && data.id && this.pendingRequests.resolve(data.id, data as RpcResponse)) return;\n\t\t\tconst event = data as RpcEvent;\n\t\t\tif (this.eventBuffer) this.eventBuffer.enqueue(event);\n\t\t\telse this.emitEvent(event);\n\t\t} catch {\n\t\t\tif (this.engineMonitor) this.failTransport(rpcTransportError(\"Interactive engine emitted malformed JSONL\"));\n\t\t}\n\t}\n\tprivate emitEvent(event: RpcEvent): void {\n\t\tfor (const listener of this.eventListeners) listener(event);\n\t}\n\tprivate emitInteractiveEngineMessage(message: InteractiveEngineMessage, generation: number): void {\n\t\tif (this.engineMessageListeners.length === 0 && message.type.startsWith(\"engine_custom_\")) {\n\t\t\tthis.pendingEngineMessages.push(generation, message);\n\t\t}\n\t\tfor (const listener of this.engineMessageListeners) listener(message);\n\t}\n\tprivate createProcessExitError(code: number | null, signal: NodeJS.Signals | null): Error {\n\t\treturn rpcTransportError(`Agent process exited (code=${code} signal=${signal}). Stderr: ${this.stderr}`);\n\t}\n\tprivate invalidateEngineShortcuts(): void {\n\t\tif (!this.latestEngineKeybindingState || this.latestEngineKeybindingState.shortcuts.length === 0) return;\n\t\tconst state: EngineKeybindingState = { ...this.latestEngineKeybindingState, shortcuts: [] };\n\t\tthis.latestEngineKeybindingState = state;\n\t\tthis.emitInteractiveEngineMessage({ type: \"engine_keybindings_reloaded\", state }, this.generation);\n\t}\n\tprivate observeInteractiveEngineMessage(message: InteractiveEngineMessage, generation: number): void {\n\t\t// Ownership is the one thing a dead generation may still report: request\n\t\t// ids never repeat, and the alternative is classifying work it already\n\t\t// started as never sent. Nothing else from it may touch host state — a\n\t\t// stale frame would revive a PID, an activity, or a mount that is gone.\n\t\tif (message.type === \"engine_request_accepted\") {\n\t\t\tif (generation === this.generation) this.pendingRequests.markAccepted(message.requestId);\n\t\t\treturn;\n\t\t}\n\t\tif (generation !== this.generation || generation <= this.lastEndedGeneration) return;\n\t\tif (message.type === \"engine_heartbeat\") this.options.interactiveEngine?.onHeartbeat?.();\n\t\tif (message.type === \"engine_ready\") this.enginePid = message.pid;\n\t\tif (message.type === \"engine_keybindings_reloaded\") this.latestEngineKeybindingState = message.state;\n\t\tif (message.type === \"engine_activity_started\") this.activeActivityIds.add(message.activity.id);\n\t\telse if (message.type === \"engine_activity_finished\") this.activeActivityIds.delete(message.activityId);\n\t\tthis.options.interactiveEngine?.onActivityChange?.(this.activeActivityIds.size > 0);\n\t\tthis.emitInteractiveEngineMessage(message, generation);\n\t}\n\t/**\n\t * Shared teardown for every unexpected end of `generation`. Death publishes\n\t * at once for the host UI; its requests wait for stdout (RpcTerminalDrain).\n\t */\n\tprivate failGeneration(rawError: Error, generation: number, kind: InteractiveEngineGenerationEndKind): void {\n\t\tif (generation !== this.generation) return;\n\t\tconst error = markRpcTransportFailure(rawError);\n\t\tthis.exitError = error;\n\t\tthis.stdinWriter?.close(error);\n\t\tthis.engineMonitor?.fail(error);\n\t\tif (kind === \"exit\") {\n\t\t\tthis.activeActivityIds.clear();\n\t\t\tthis.options.interactiveEngine?.onActivityChange?.(false);\n\t\t}\n\t\tthis.beginTerminalDrain(generation, error);\n\t\tthis.publishGenerationEnded(generation, error, kind, false);\n\t}\n\t/** Hold this generation's requests until its stdout drains (RpcTerminalDrain). */\n\tprivate beginTerminalDrain(generation: number, error: Error): Promise<void> {\n\t\treturn this.terminalDrain.begin(generation, this.stdoutDrained, error, (settled) => {\n\t\t\tif (generation === this.generation) this.pendingRequests.rejectAll(settled);\n\t\t});\n\t}\n\tprivate publishGenerationEnded(\n\t\tgeneration: number,\n\t\terror: Error,\n\t\tkind: InteractiveEngineGenerationEndKind,\n\t\texpected: boolean,\n\t): void {\n\t\tif (generation <= this.lastEndedGeneration) return;\n\t\tthis.lastEndedGeneration = generation;\n\t\tconst event: InteractiveEngineGenerationEnded = { generation, error, kind, expected };\n\t\tthis.retainedGenerationEnd = event;\n\t\t// Death is a strict boundary: drop this generation's buffered frames\n\t\t// BEFORE teardown runs, so no listener can drain a stale mount frame\n\t\t// while it is closing that very generation's components.\n\t\tthis.pendingEngineMessages.dropGeneration(generation);\n\t\tthis.pendingExtensionUIRequests.dropGeneration(generation);\n\t\tfor (const listener of [...this.generationEndedListeners]) listener(event);\n\t}\n\tprivate failTransport(rawError: Error): void {\n\t\tthis.options.interactiveEngine?.onDiagnostic({\n\t\t\tactivity: undefined,\n\t\t\telapsedMs: 0,\n\t\t\tlevel: \"unresponsive\",\n\t\t\tmessage: rawError.message,\n\t\t});\n\t\tthis.failGeneration(rawError, this.generation, \"transport-error\");\n\t}\n\tprivate requireWriter(): QueuedWriter {\n\t\tif (!this.stdinWriter) throw rpcTransportError(\"Agent process stdin is not writable\");\n\t\treturn this.stdinWriter;\n\t}\n\tprivate bestEffort(operation: Promise<void>, label: string): void {\n\t\tvoid operation.catch((error: Error) => {\n\t\t\tif (!this.process || this.exitError) return;\n\t\t\tthis.options.interactiveEngine?.onDiagnostic({\n\t\t\t\tactivity: undefined,\n\t\t\t\telapsedMs: 0,\n\t\t\t\tlevel: \"unresponsive\",\n\t\t\t\tmessage: `Interactive engine ${label} failed: ${error.message}`,\n\t\t\t});\n\t\t});\n\t}\n\tprotected async request(command: RpcCommandBody, onRequestId?: (id: string) => void): Promise<RpcResponse> {\n\t\tconst childProcess = this.process;\n\t\tif (!childProcess) throw rpcTransportError(\"Client not started\");\n\t\tif (this.exitError) throw this.exitError;\n\t\tif (childProcess.exitCode !== null) {\n\t\t\tconst error = this.createProcessExitError(childProcess.exitCode, childProcess.signalCode);\n\t\t\tthis.exitError = error;\n\t\t\tthrow error;\n\t\t}\n\t\tconst id = `req_${++this.requestId}`;\n\t\tonRequestId?.(id);\n\t\tconst fullCommand = { ...command, id } as RpcCommand;\n\t\tlet timeout: ReturnType<typeof setTimeout> | undefined;\n\t\tlet rejectResponse!: (error: Error) => void;\n\t\tconst response = new Promise<RpcResponse>((resolve, reject) => {\n\t\t\trejectResponse = reject;\n\t\t\tthis.pendingRequests.add(id, {\n\t\t\t\tresolve: (value) => {\n\t\t\t\t\tif (timeout) clearTimeout(timeout);\n\t\t\t\t\tresolve(value);\n\t\t\t\t},\n\t\t\t\treject: (error) => {\n\t\t\t\t\tif (timeout) clearTimeout(timeout);\n\t\t\t\t\treject(error);\n\t\t\t\t},\n\t\t\t});\n\t\t});\n\t\ttry {\n\t\t\tawait this.requireWriter().write(serializeJsonLine(fullCommand));\n\t\t} catch (error) {\n\t\t\tthis.pendingRequests.delete(id);\n\t\t\t// Idempotent: the writer already classified this, but a caller-supplied\n\t\t\t// stream can reject with anything, and a send that never left the host\n\t\t\t// is a transport failure whatever it threw.\n\t\t\trejectResponse(markRpcTransportFailure(error));\n\t\t\treturn response;\n\t\t}\n\t\tif (this.pendingRequests.has(id) && !LONG_LIVED_COMMANDS.has(command.type)) {\n\t\t\ttimeout = setTimeout(() => {\n\t\t\t\tthis.pendingRequests.delete(id);\n\t\t\t\trejectResponse(new Error(`Timeout waiting for response to ${command.type}. Stderr: ${this.stderr}`));\n\t\t\t}, this.options.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS);\n\t\t}\n\t\treturn response;\n\t}\n\tprivate assertSuccess(response: RpcResponse): void {\n\t\tif (response.success) return;\n\t\tif (response.errorCode === \"credential_synchronization\" && response.errorDetails) {\n\t\t\tthrow new CredentialSynchronizationError(\n\t\t\t\tresponse.errorDetails.providerId,\n\t\t\t\tresponse.errorDetails.operation,\n\t\t\t\tundefined,\n\t\t\t\t{ cause: new Error(response.error) },\n\t\t\t);\n\t\t}\n\t\tthrow new Error(response.error);\n\t}\n\tprotected data<T>(response: RpcResponse): T {\n\t\tthis.assertSuccess(response);\n\t\tconst successResponse = response as Extract<RpcResponse, { success: true; data: unknown }>;\n\t\treturn successResponse.data as T;\n\t}\n}\n"]}
@@ -2,8 +2,9 @@ import type { RpcExtensionUIResponse } from "./rpc-types.ts";
2
2
  export declare function isRpcExtensionUIResponse(value: unknown): value is RpcExtensionUIResponse;
3
3
  /**
4
4
  * Control frames must remain reachable while an ordinary RPC command is
5
- * pending. Interrupts cancel that command, while host responses can unblock UI
6
- * work awaited by it. Everything else stays on the ordered command lane.
5
+ * pending. Interrupts cancel or adjust queued work for that command, while
6
+ * host responses can unblock UI work awaited by it. Everything else stays on
7
+ * the ordered command lane.
7
8
  */
8
9
  export declare function isConcurrentRpcControlLine(line: string): boolean;
9
10
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"rpc-input-scheduler.d.ts","sourceRoot":"","sources":["../../../src/modes/rpc/rpc-input-scheduler.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAY7D,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,sBAAsB,CASxF;AAED;;;;GAIG;AACH,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAgBhE;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAgC3G"}
1
+ {"version":3,"file":"rpc-input-scheduler.d.ts","sourceRoot":"","sources":["../../../src/modes/rpc/rpc-input-scheduler.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAc7D,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,sBAAsB,CASxF;AAED;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAgBhE;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAgC3G"}
@@ -6,6 +6,8 @@ const INTERRUPT_COMMANDS = new Set([
6
6
  "abort_retry",
7
7
  "abort_bash",
8
8
  "pause_queued_messages",
9
+ "resume_queued_messages",
10
+ "clear_queue",
9
11
  ]);
10
12
  const CONCURRENT_COMMANDS = new Set(["bash", "user_bash", "refresh_models"]);
11
13
  export function isRpcExtensionUIResponse(value) {
@@ -18,8 +20,9 @@ export function isRpcExtensionUIResponse(value) {
18
20
  }
19
21
  /**
20
22
  * Control frames must remain reachable while an ordinary RPC command is
21
- * pending. Interrupts cancel that command, while host responses can unblock UI
22
- * work awaited by it. Everything else stays on the ordered command lane.
23
+ * pending. Interrupts cancel or adjust queued work for that command, while
24
+ * host responses can unblock UI work awaited by it. Everything else stays on
25
+ * the ordered command lane.
23
26
  */
24
27
  export function isConcurrentRpcControlLine(line) {
25
28
  if (parseInteractiveEngineCommand(line))
@@ -1 +1 @@
1
- {"version":3,"file":"rpc-input-scheduler.js","sourceRoot":"","sources":["../../../src/modes/rpc/rpc-input-scheduler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,mCAAmC,CAAC;AAGlF,MAAM,kBAAkB,GAAwB,IAAI,GAAG,CAAC;IACvD,OAAO;IACP,uBAAu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AClF,MAAM,aAAa,GAAa,EAAE,CAAC;IACnC,IAAI,cAAc,GAAG,KAAK,CAAC;IAE3B,MAAM,MAAM,GAAG,CAAC,IAAY,EAAiB,EAAE;QAC9C,IAAI,CAAC;YACJ,OAAO,UAAU,CAAC,IAAI,CAAC,CAAC;QACzB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,OAAO,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC9B,CAAC;IACF,CAAC,CAAC;IAEF,MAAM,iBAAiB,GAAG,GAAS,EAAE;QACpC,MAAM,IAAI,GAAG,aAAa,CAAC,KAAK,EAAE,CAAC;QACnC,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACxB,cAAc,GAAG,KAAK,CAAC;YACvB,OAAO;QACR,CAAC;QACD,cAAc,GAAG,IAAI,CAAC;QACtB,KAAK,MAAM,CAAC,IAAI,CAAC;aACf,OAAO,CAAC,iBAAiB,CAAC;aAC1B,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;IACnB,CAAC,CAAC;IAEF,OAAO,CAAC,IAAY,EAAQ,EAAE;QAC7B,IAAI,0BAA0B,CAAC,IAAI,CAAC,EAAE,CAAC;YACtC,KAAK,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;YAClC,OAAO;QACR,CAAC;QACD,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACzB,IAAI,CAAC,cAAc;YAAE,iBAAiB,EAAE,CAAC;IAC1C,CAAC,CAAC;AACH,CAAC","sourcesContent":["import { parseInteractiveEngineCommand } from \"../interactive-engine/protocol.ts\";\nimport type { RpcExtensionUIResponse } from \"./rpc-types.ts\";\n\nconst INTERRUPT_COMMANDS: ReadonlySet<string> = new Set([\n\t\"abort\",\n\t\"cancel_login_provider\",\n\t\"abort_compaction\",\n\t\"abort_retry\",\n\t\"abort_bash\",\n\t\"pause_queued_messages\",\n]);\nconst CONCURRENT_COMMANDS: ReadonlySet<string> = new Set([\"bash\", \"user_bash\", \"refresh_models\"]);\n\nexport function isRpcExtensionUIResponse(value: unknown): value is RpcExtensionUIResponse {\n\treturn (\n\t\ttypeof value === \"object\" &&\n\t\tvalue !== null &&\n\t\t\"type\" in value &&\n\t\tvalue.type === \"extension_ui_response\" &&\n\t\t\"id\" in value &&\n\t\ttypeof value.id === \"string\"\n\t);\n}\n\n/**\n * Control frames must remain reachable while an ordinary RPC command is\n * pending. Interrupts cancel that command, while host responses can unblock UI\n * work awaited by it. Everything else stays on the ordered command lane.\n */\nexport function isConcurrentRpcControlLine(line: string): boolean {\n\tif (parseInteractiveEngineCommand(line)) return true;\n\tlet value: object | null;\n\ttry {\n\t\tconst parsed = JSON.parse(line) as object | boolean | null | number | string;\n\t\tvalue = typeof parsed === \"object\" && !Array.isArray(parsed) ? parsed : null;\n\t} catch {\n\t\treturn false;\n\t}\n\tif (isRpcExtensionUIResponse(value)) return true;\n\treturn (\n\t\tvalue !== null &&\n\t\t\"type\" in value &&\n\t\ttypeof value.type === \"string\" &&\n\t\t(INTERRUPT_COMMANDS.has(value.type) || CONCURRENT_COMMANDS.has(value.type))\n\t);\n}\n\n/**\n * Runs ordinary RPC input one frame at a time while giving validated control\n * frames and independently correlated bash executions a concurrent lane. The\n * first ordinary frame starts synchronously, so a following interrupt cannot\n * overtake initialization of the operation it is intended to cancel.\n */\nexport function createRpcInputScheduler(handleLine: (line: string) => Promise<void>): (line: string) => void {\n\tconst ordinaryQueue: string[] = [];\n\tlet ordinaryActive = false;\n\n\tconst invoke = (line: string): Promise<void> => {\n\t\ttry {\n\t\t\treturn handleLine(line);\n\t\t} catch (error) {\n\t\t\treturn Promise.reject(error);\n\t\t}\n\t};\n\n\tconst startNextOrdinary = (): void => {\n\t\tconst line = ordinaryQueue.shift();\n\t\tif (line === undefined) {\n\t\t\tordinaryActive = false;\n\t\t\treturn;\n\t\t}\n\t\tordinaryActive = true;\n\t\tvoid invoke(line)\n\t\t\t.finally(startNextOrdinary)\n\t\t\t.catch(() => {});\n\t};\n\n\treturn (line: string): void => {\n\t\tif (isConcurrentRpcControlLine(line)) {\n\t\t\tvoid invoke(line).catch(() => {});\n\t\t\treturn;\n\t\t}\n\t\tordinaryQueue.push(line);\n\t\tif (!ordinaryActive) startNextOrdinary();\n\t};\n}\n"]}
1
+ {"version":3,"file":"rpc-input-scheduler.js","sourceRoot":"","sources":["../../../src/modes/rpc/rpc-input-scheduler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,mCAAmC,CAAC;AAGlF,MAAM,kBAAkB,GAAwB,IAAI,GAAG,CAAC;IACvD,OAAO;IACP,uBAAuB;IACvB,kBAAkB;IAClB,aAAa;IACb,YAAY;IACZ,uBAAuB;IACvB,wBAAwB;IACxB,aAAa;CACb,CAAC,CAAC;AACH,MAAM,mBAAmB,GAAwB,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,WAAW,EAAE,gBAAgB,CAAC,CAAC,CAAC;AAElG,MAAM,UAAU,wBAAwB,CAAC,KAAc;IACtD,OAAO,CACN,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,MAAM,IAAI,KAAK;QACf,KAAK,CAAC,IAAI,KAAK,uBAAuB;QACtC,IAAI,IAAI,KAAK;QACb,OAAO,KAAK,CAAC,EAAE,KAAK,QAAQ,CAC5B,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,0BAA0B,CAAC,IAAY;IACtD,IAAI,6BAA6B,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IACrD,IAAI,KAAoB,CAAC;IACzB,IAAI,CAAC;QACJ,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAA8C,CAAC;QAC7E,KAAK,GAAG,OAAO,MAAM,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAA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KAAK,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;YAClC,OAAO;QACR,CAAC;QACD,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACzB,IAAI,CAAC,cAAc;YAAE,iBAAiB,EAAE,CAAC;IAC1C,CAAC,CAAC;AACH,CAAC","sourcesContent":["import { parseInteractiveEngineCommand } from \"../interactive-engine/protocol.ts\";\nimport type { RpcExtensionUIResponse } from \"./rpc-types.ts\";\n\nconst INTERRUPT_COMMANDS: ReadonlySet<string> = new Set([\n\t\"abort\",\n\t\"cancel_login_provider\",\n\t\"abort_compaction\",\n\t\"abort_retry\",\n\t\"abort_bash\",\n\t\"pause_queued_messages\",\n\t\"resume_queued_messages\",\n\t\"clear_queue\",\n]);\nconst CONCURRENT_COMMANDS: ReadonlySet<string> = new Set([\"bash\", \"user_bash\", \"refresh_models\"]);\n\nexport function isRpcExtensionUIResponse(value: unknown): value is RpcExtensionUIResponse {\n\treturn (\n\t\ttypeof value === \"object\" &&\n\t\tvalue !== null &&\n\t\t\"type\" in value &&\n\t\tvalue.type === \"extension_ui_response\" &&\n\t\t\"id\" in value &&\n\t\ttypeof value.id === \"string\"\n\t);\n}\n\n/**\n * Control frames must remain reachable while an ordinary RPC command is\n * pending. Interrupts cancel or adjust queued work for that command, while\n * host responses can unblock UI work awaited by it. Everything else stays on\n * the ordered command lane.\n */\nexport function isConcurrentRpcControlLine(line: string): boolean {\n\tif (parseInteractiveEngineCommand(line)) return true;\n\tlet value: object | null;\n\ttry {\n\t\tconst parsed = JSON.parse(line) as object | boolean | null | number | string;\n\t\tvalue = typeof parsed === \"object\" && !Array.isArray(parsed) ? parsed : null;\n\t} catch {\n\t\treturn false;\n\t}\n\tif (isRpcExtensionUIResponse(value)) return true;\n\treturn (\n\t\tvalue !== null &&\n\t\t\"type\" in value &&\n\t\ttypeof value.type === \"string\" &&\n\t\t(INTERRUPT_COMMANDS.has(value.type) || CONCURRENT_COMMANDS.has(value.type))\n\t);\n}\n\n/**\n * Runs ordinary RPC input one frame at a time while giving validated control\n * frames and independently correlated bash executions a concurrent lane. The\n * first ordinary frame starts synchronously, so a following interrupt cannot\n * overtake initialization of the operation it is intended to cancel.\n */\nexport function createRpcInputScheduler(handleLine: (line: string) => Promise<void>): (line: string) => void {\n\tconst ordinaryQueue: string[] = [];\n\tlet ordinaryActive = false;\n\n\tconst invoke = (line: string): Promise<void> => {\n\t\ttry {\n\t\t\treturn handleLine(line);\n\t\t} catch (error) {\n\t\t\treturn Promise.reject(error);\n\t\t}\n\t};\n\n\tconst startNextOrdinary = (): void => {\n\t\tconst line = ordinaryQueue.shift();\n\t\tif (line === undefined) {\n\t\t\tordinaryActive = false;\n\t\t\treturn;\n\t\t}\n\t\tordinaryActive = true;\n\t\tvoid invoke(line)\n\t\t\t.finally(startNextOrdinary)\n\t\t\t.catch(() => {});\n\t};\n\n\treturn (line: string): void => {\n\t\tif (isConcurrentRpcControlLine(line)) {\n\t\t\tvoid invoke(line).catch(() => {});\n\t\t\treturn;\n\t\t}\n\t\tordinaryQueue.push(line);\n\t\tif (!ordinaryActive) startNextOrdinary();\n\t};\n}\n"]}
@@ -2829,7 +2829,7 @@ const result = await ctx.ui.custom<string | null>(
2829
2829
 
2830
2830
  A component mounted with `reserveTranscriptRows` always releases configured fullscreen transcript actions and vertical wheel input to the host viewport, including while a nested input has focus. The component keeps all other keyboard and mouse input, including text editing, arrows, confirmation, cancellation, and clicks. This rule applies only to reserving overlays; other focused overlays still receive page and wheel input first and can keep it by returning `true`.
2831
2831
 
2832
- Bounding a tall dialog means dropping rows, and the host would otherwise have to guess which. Embed `OVERLAY_ACTIVE_ROW_MARKER` in the line your component most needs kept — the selected row of a list — and the host places what it keeps around that row instead of taking a fixed head, even when the effective `maxHeight` is only one row. The mark is a zero-width APC sequence that `visibleWidth` measures as zero, and the host strips it before the line is painted, so it never reaches the terminal. Embed it once per frame; the host uses the first line that carries it. The `ask_user_question` dialog marks every active selectable row, including single- and multi-select options, Next, Submit, Cancel, and inline sentinel rows. Focused pi-tui inputs also anchor the bound through their cursor marker, so arrow keys and text input stay visible on a 16-row terminal.
2832
+ Bounding a tall dialog means dropping rows, and the host would otherwise have to guess which. Embed `OVERLAY_ACTIVE_ROW_MARKER` in the line your component most needs kept — the selected row of a list — and the host places what it keeps around that row instead of taking a fixed head, even when the effective `maxHeight` is only one row. The mark is a zero-width APC sequence that `visibleWidth` measures as zero, terminated with ST as ECMA-48 requires. The renderer strips it centrally, in the last transform over the composited screen before it is written out, so it never reaches the terminal — from a reserving overlay, an ordinary overlay, an inline mount, a widget, or a workflow stage chat alike. Embed it once per frame; the host uses the first line that carries it. Put it anywhere on that line: a mark buried mid-line is removed just as a trailing one is. The `ask_user_question` dialog marks every active selectable row, including single- and multi-select options, Next, Submit, Cancel, and inline sentinel rows. Focused pi-tui inputs also anchor the bound through their cursor marker, so arrow keys and text input stay visible on a 16-row terminal.
2833
2833
 
2834
2834
  ```typescript
2835
2835
  import { OVERLAY_ACTIVE_ROW_MARKER } from "@bastani/atomic";
@@ -171,6 +171,7 @@ Skills are reusable expert instructions. Trigger one with `/skill:<name>` follow
171
171
  | `impeccable` | Critique or refine web/native frontend and product UI; includes detector hooks, framework-aware live review, and mount-failure recovery. | `/skill:impeccable` |
172
172
  | `playwright-cli` | Drive a real browser for end-to-end UI checks, screenshots, and reviewable proof videos. | `/skill:playwright-cli` |
173
173
  | `liteparse` | Pull text, tables, or values out of PDF, DOCX, PPTX, XLSX, and image files locally. | `/skill:liteparse` |
174
+ | `show-me` | Explain a topic visually with concise diagrams, code-shape sketches, or focused HTML artifacts. HumanLayer, MIT licensed. | `/skill:show-me` |
174
175
 
175
176
  Impeccable 4.1.1 resolves Live sessions to the selected app root, supports SvelteKit, Nuxt, TanStack Start, Astro, Next.js, Vite, and static HTML injection, and rejects absolute, traversing, or symlinked configured write targets. Its concept roll may contact `impeccable.style`; set `IMPECCABLE_NO_TELEMETRY=1` or `DO_NOT_TRACK=1` to disable the anonymous choice ping. The image fallback runs only with `OPENAI_API_KEY`, sends prompts and optional reference images to OpenAI, and spends that account's API credit. Generated image prompts are embedded in the image or a sidecar, so do not include secrets.
176
177
 
package/docs/skills.md CHANGED
@@ -76,6 +76,10 @@ The bundled `/skill:prompt-engineer` creates, optimizes, evaluates, and troubles
76
76
 
77
77
  The skill no longer recommends response prefilling, which returns an error on Claude 4.6 and later, or visible chain-of-thought as a primary technique. Use explicit output instructions, schemas, tools, or post-processing instead of prefilling. Request conclusions, citations, commands, and observed results rather than reconstructed private reasoning; such requests can trigger Claude Fable 5's `reasoning_extraction` safeguard and force a model fallback.
78
78
 
79
+ ### Built-in visual explanation guidance
80
+
81
+ The bundled `/skill:show-me` from [HumanLayer](https://github.com/humanlayer/skills) helps explain the current topic visually with concise diagrams, code-shape sketches, and focused HTML artifacts. It is distributed under the MIT License.
82
+
79
83
  ## Skill Commands
80
84
 
81
85
  Skills register as `/skill:name` commands: