@bastani/atomic 0.9.19-alpha.5 → 0.9.19-alpha.7
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.
- package/CHANGELOG.md +32 -0
- package/README.md +2 -2
- package/dist/builtin/intercom/CHANGELOG.md +6 -0
- package/dist/builtin/intercom/broker/client.ts +19 -1
- package/dist/builtin/intercom/index.bundle.mjs +8 -1
- package/dist/builtin/intercom/package.json +1 -1
- package/dist/builtin/mcp/package.json +1 -1
- package/dist/builtin/subagents/CHANGELOG.md +6 -0
- package/dist/builtin/subagents/README.md +3 -1
- package/dist/builtin/subagents/agents/codebase-online-researcher.md +7 -7
- package/dist/builtin/subagents/package.json +1 -1
- package/dist/builtin/subagents/skills/subagent/SKILL.md +3 -1
- package/dist/builtin/subagents/src/extension/index.bundle.mjs +2 -1
- package/dist/builtin/web-access/CHANGELOG.md +13 -0
- package/dist/builtin/web-access/README.md +31 -24
- package/dist/builtin/web-access/index.bundle.mjs +16121 -80
- package/dist/builtin/web-access/package.json +2 -1
- package/dist/builtin/workflows/CHANGELOG.md +15 -0
- package/dist/builtin/workflows/README.md +1 -1
- package/dist/builtin/workflows/builtin/adversarial-verification.js +2 -2
- package/dist/builtin/workflows/builtin/{chunk-vhmnzdj9.js → chunk-1jth021m.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-p8jjwfg6.js → chunk-2377r57g.js} +4 -2
- package/dist/builtin/workflows/builtin/{chunk-hbnwv56f.js → chunk-31j2gs7h.js} +2 -2
- package/dist/builtin/workflows/builtin/{chunk-n8zysf1t.js → chunk-ngkqkzej.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-1nbq96fh.js → chunk-nkrafh9s.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-1kx4aggw.js → chunk-wf741bv3.js} +2 -2
- package/dist/builtin/workflows/builtin/{chunk-t6x2d78s.js → chunk-z29qbehr.js} +1 -1
- package/dist/builtin/workflows/builtin/generate-and-filter.js +2 -2
- package/dist/builtin/workflows/builtin/goal.js +3 -3
- package/dist/builtin/workflows/builtin/index.js +7 -7
- package/dist/builtin/workflows/builtin/ralph.js +3 -3
- package/dist/builtin/workflows/builtin/tournament.js +2 -2
- package/dist/builtin/workflows/package.json +1 -1
- package/dist/builtin/workflows/src/extension/index.bundle.mjs +339 -31
- package/dist/builtin/workflows/src/index.js +67 -19
- package/dist/builtin/workflows/src/shared/authoring-contract-stage.d.ts +2 -0
- package/dist/core/agent-session-tool-registry.d.ts.map +1 -1
- package/dist/core/agent-session-tool-registry.js +10 -0
- package/dist/core/agent-session-tool-registry.js.map +1 -1
- package/dist/core/bash-executor.js.map +1 -1
- package/dist/core/tools/bash.d.ts +1 -1
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +3 -2
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/edit.d.ts +3 -0
- package/dist/core/tools/edit.d.ts.map +1 -1
- package/dist/core/tools/edit.js +91 -12
- package/dist/core/tools/edit.js.map +1 -1
- package/dist/core/tools/file-mutation-coordinator.d.ts +255 -0
- package/dist/core/tools/file-mutation-coordinator.d.ts.map +1 -0
- package/dist/core/tools/file-mutation-coordinator.js +300 -0
- package/dist/core/tools/file-mutation-coordinator.js.map +1 -0
- package/dist/core/tools/file-mutation-queue.d.ts +14 -1
- package/dist/core/tools/file-mutation-queue.d.ts.map +1 -1
- package/dist/core/tools/file-mutation-queue.js +15 -3
- package/dist/core/tools/file-mutation-queue.js.map +1 -1
- package/dist/core/tools/hashline.d.ts +9 -0
- package/dist/core/tools/hashline.d.ts.map +1 -1
- package/dist/core/tools/hashline.js +12 -1
- package/dist/core/tools/hashline.js.map +1 -1
- package/dist/core/tools/index.d.ts +9 -1
- package/dist/core/tools/index.d.ts.map +1 -1
- package/dist/core/tools/index.js +67 -12
- package/dist/core/tools/index.js.map +1 -1
- package/dist/core/tools/non-minting-snapshot-store.d.ts +49 -0
- package/dist/core/tools/non-minting-snapshot-store.d.ts.map +1 -0
- package/dist/core/tools/non-minting-snapshot-store.js +64 -0
- package/dist/core/tools/non-minting-snapshot-store.js.map +1 -0
- package/dist/core/tools/powershell.d.ts +2 -2
- package/dist/core/tools/powershell.d.ts.map +1 -1
- package/dist/core/tools/powershell.js +2 -5
- package/dist/core/tools/powershell.js.map +1 -1
- package/dist/core/tools/read-document-extract.js.map +1 -1
- package/dist/core/tools/render-utils.js.map +1 -1
- package/dist/core/tools/write.d.ts +30 -1
- package/dist/core/tools/write.d.ts.map +1 -1
- package/dist/core/tools/write.js +97 -8
- package/dist/core/tools/write.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/modes/interactive/components/bash-execution.js.map +1 -1
- package/dist/modes/interactive/components/task-live-transcript.d.ts +1 -1
- package/dist/modes/interactive/components/task-live-transcript.d.ts.map +1 -1
- package/dist/modes/interactive/components/task-live-transcript.js +19 -11
- package/dist/modes/interactive/components/task-live-transcript.js.map +1 -1
- package/dist/modes/interactive/interactive-mode-base.d.ts +1 -0
- package/dist/modes/interactive/interactive-mode-base.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode-base.js +3 -1
- package/dist/modes/interactive/interactive-mode-base.js.map +1 -1
- package/dist/modes/interactive/interactive-mode-surface.d.ts +1 -1
- package/dist/modes/interactive/interactive-mode-surface.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode-surface.js.map +1 -1
- package/dist/modes/interactive/interactive-render-chat.js +28 -4
- package/dist/modes/interactive/interactive-render-chat.js.map +1 -1
- package/dist/modes/interactive/interactive-startup.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-startup.js +3 -0
- package/dist/modes/interactive/interactive-startup.js.map +1 -1
- package/dist/modes/interactive-engine/activity-watchdog.d.ts +2 -2
- package/dist/modes/interactive-engine/activity-watchdog.d.ts.map +1 -1
- package/dist/modes/interactive-engine/activity-watchdog.js.map +1 -1
- package/dist/modes/interactive-engine/engine-diagnostic-view.d.ts +3 -1
- package/dist/modes/interactive-engine/engine-diagnostic-view.d.ts.map +1 -1
- package/dist/modes/interactive-engine/engine-diagnostic-view.js +11 -0
- package/dist/modes/interactive-engine/engine-diagnostic-view.js.map +1 -1
- package/dist/modes/interactive-engine/isolated-runtime.js +2 -1
- package/dist/modes/interactive-engine/isolated-runtime.js.map +1 -1
- package/dist/modes/rpc/rpc-client-process.d.ts +2 -0
- package/dist/modes/rpc/rpc-client-process.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client-process.js +23 -1
- package/dist/modes/rpc/rpc-client-process.js.map +1 -1
- package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client.js +20 -3
- package/dist/modes/rpc/rpc-client.js.map +1 -1
- package/dist/utils/markit.d.ts +2 -0
- package/dist/utils/markit.d.ts.map +1 -1
- package/dist/utils/markit.js +65 -5
- package/dist/utils/markit.js.map +1 -1
- package/docs/background-tasks.md +15 -11
- package/docs/build.md +51 -0
- package/docs/changelog.mdx +8 -8
- package/docs/compaction/reference.md +267 -0
- package/docs/compaction.md +36 -219
- package/docs/computer-use.md +35 -0
- package/docs/containerization.md +9 -5
- package/docs/custom-provider/api-reference.md +145 -0
- package/docs/custom-provider/oauth.md +131 -0
- package/docs/custom-provider/override.md +34 -0
- package/docs/custom-provider/registration.md +163 -0
- package/docs/custom-provider/streaming.md +214 -0
- package/docs/custom-provider.md +43 -607
- package/docs/development.md +87 -0
- package/docs/docs.json +199 -76
- package/docs/environment-variables.md +1 -1
- package/docs/extensions/api-reference.md +1001 -0
- package/docs/extensions/authoring.md +676 -0
- package/docs/extensions/events.md +793 -0
- package/docs/extensions/examples.md +94 -0
- package/docs/extensions/ui.md +470 -0
- package/docs/extensions.md +270 -2768
- package/docs/getting-started/authentication.md +55 -0
- package/docs/getting-started/first-session.md +172 -0
- package/docs/getting-started/installation.md +154 -0
- package/docs/getting-started/project-instructions.md +43 -0
- package/docs/guides/configuration.md +65 -0
- package/docs/guides/intercom.md +24 -0
- package/docs/guides/non-interactive.md +33 -0
- package/docs/guides/subagents.md +24 -0
- package/docs/guides/workflows.md +27 -0
- package/docs/guides.md +41 -0
- package/docs/index.md +13 -45
- package/docs/intercom/operations.md +178 -0
- package/docs/intercom/reference.md +146 -0
- package/docs/intercom.md +54 -259
- package/docs/json.md +17 -0
- package/docs/llama-cpp.md +5 -0
- package/docs/models/artificial-analysis-index.md +89 -0
- package/docs/models/evals.md +2 -2
- package/docs/models/model-selection.md +3 -3
- package/docs/models/pareto-efficiency.md +2 -2
- package/docs/models/reference.md +601 -0
- package/docs/models.md +45 -550
- package/docs/packages/authoring.md +88 -0
- package/docs/packages/reference.md +43 -0
- package/docs/packages.md +28 -107
- package/docs/programmatic.md +29 -0
- package/docs/prompt-templates.md +11 -0
- package/docs/providers/reference.md +23 -0
- package/docs/providers.md +10 -15
- package/docs/quickstart.md +44 -238
- package/docs/reference/cli.md +252 -0
- package/docs/reference.md +52 -0
- package/docs/rpc/examples.md +64 -0
- package/docs/rpc/extension-ui.md +198 -0
- package/docs/rpc/protocol.md +1341 -0
- package/docs/rpc.md +109 -1346
- package/docs/sdk/reference.md +1090 -0
- package/docs/sdk.md +56 -1002
- package/docs/session-format.md +2 -0
- package/docs/sessions.md +6 -10
- package/docs/settings.md +6 -45
- package/docs/skills/authoring.md +95 -0
- package/docs/skills/reference.md +60 -0
- package/docs/skills.md +20 -122
- package/docs/subagents/authoring.md +37 -0
- package/docs/subagents/reference.md +60 -0
- package/docs/subagents.md +42 -96
- package/docs/terminal-setup.md +1 -1
- package/docs/themes/reference.md +176 -0
- package/docs/themes.md +21 -135
- package/docs/tmux.md +5 -0
- package/docs/tools/edit.md +5 -0
- package/docs/tools.md +31 -0
- package/docs/tui/reference.md +343 -0
- package/docs/tui.md +23 -286
- package/docs/usage.md +26 -209
- package/docs/web-access.md +40 -0
- package/docs/windows.md +2 -1
- package/docs/workflows/api-reference.md +11 -4
- package/docs/workflows/authoring.md +4 -2
- package/docs/workflows/builtins.md +2 -2
- package/docs/workflows/operations.md +11 -7
- package/docs/workflows/reliable-design.md +21 -3
- package/docs/workflows/verification.md +8 -0
- package/examples/extensions/gondolin/index.ts +116 -148
- package/examples/extensions/gondolin/package.json +1 -1
- package/examples/extensions/ssh.ts +56 -34
- package/npm-shrinkwrap.json +33 -33
- package/package.json +4 -4
|
@@ -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,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACjG,OAAO,EAAE,0BAA0B,EAAE,mBAAmB,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AACvH,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,uBAAuB,EAAE,iB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process\";\nimport type { ImageContent } from \"@bastani/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.js\";\nimport { sleep } from \"../../utils/sleep.ts\";\nimport type { ActivityWatchdogDiagnostic } from \"../interactive-engine/activity-watchdog.ts\";\nimport type {\n\tInteractiveEngineGenerationEnded,\n\tInteractiveEngineGenerationEndedListener,\n\tInteractiveEngineGenerationEndKind,\n} from \"../interactive-engine/engine-generation.ts\";\nimport { InteractiveEngineMonitor } from \"../interactive-engine/engine-monitor.ts\";\nimport {\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 pendingProjectTrustFrames = new GenerationBuffer<string>();\n\tprivate boundGeneration = 0;\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 (command.type === \"engine_project_trust_start\" || command.type === \"engine_project_trust_end\") {\n\t\t\tif (this.generation <= this.lastEndedGeneration) return;\n\t\t\t// The terminal can open and close /trust while the engine is still binding.\n\t\t\t// Retain both frames, without delaying the host-owned decision.\n\t\t\tif (this.engineMonitor && this.boundGeneration !== this.generation) {\n\t\t\t\tthis.pendingProjectTrustFrames.push(this.generation, serializeInteractiveEngineFrame(command));\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tif (!writer) return;\n\t\tconst frame = serializeInteractiveEngineFrame(command);\n\t\tif (\n\t\t\tcommand.type === \"engine_custom_render\" ||\n\t\t\tcommand.type === \"engine_tool_render\" ||\n\t\t\tcommand.type === \"engine_message_render\"\n\t\t) {\n\t\t\twriter.offerLatest(`render:${command.componentId}`, frame);\n\t\t\treturn;\n\t\t}\n\t\tthis.bestEffort(writer.write(frame), `engine command ${command.type}`);\n\t}\n\twaitForInteractiveEngineBound(): Promise<void> {\n\t\treturn this.engineMonitor?.waitUntilBound() ?? Promise.resolve();\n\t}\n\twaitForInteractiveEngineResources(): Promise<void> {\n\t\treturn this.engineMonitor?.waitUntilResourcesReady() ?? Promise.resolve();\n\t}\n\tgetEnginePid(): number | undefined {\n\t\treturn this.enginePid;\n\t}\n\tgetGeneration(): number {\n\t\treturn this.generation;\n\t}\n\n\t/**\n\t * Replace the engine child, unless an explicit stop supersedes this attempt.\n\t * The permit is checked immediately before spawning, so a `stop()` in that\n\t * window is always observed; cancellation throws rather than returning\n\t * quietly, because callers go on to initialize against the new child.\n\t */\n\tasync restart(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 (\n\t\t\tthis.engineMessageListeners.length === 0 &&\n\t\t\t(message.type.startsWith(\"engine_custom_\") || message.type.startsWith(\"engine_resources_\"))\n\t\t) {\n\t\t\tthis.pendingEngineMessages.push(generation, message);\n\t\t}\n\t\tfor (const listener of this.engineMessageListeners) listener(message);\n\t}\n\tprivate createProcessExitError(code: number | null, signal: NodeJS.Signals | null): Error {\n\t\treturn rpcTransportError(`Agent process exited (code=${code} signal=${signal}). Stderr: ${this.stderr}`);\n\t}\n\tprivate invalidateEngineShortcuts(): void {\n\t\tif (!this.latestEngineKeybindingState || this.latestEngineKeybindingState.shortcuts.length === 0) return;\n\t\tconst state: EngineKeybindingState = { ...this.latestEngineKeybindingState, shortcuts: [] };\n\t\tthis.latestEngineKeybindingState = state;\n\t\tthis.emitInteractiveEngineMessage({ type: \"engine_keybindings_reloaded\", state }, this.generation);\n\t}\n\tprivate observeInteractiveEngineMessage(message: InteractiveEngineMessage, generation: number): void {\n\t\t// Ownership is the one thing a dead generation may still report: request\n\t\t// ids never repeat, and the alternative is classifying work it already\n\t\t// started as never sent. Nothing else from it may touch host state — a\n\t\t// stale frame would revive a PID, an activity, or a mount that is gone.\n\t\tif (message.type === \"engine_request_accepted\") {\n\t\t\tif (generation === this.generation) this.pendingRequests.markAccepted(message.requestId);\n\t\t\treturn;\n\t\t}\n\t\tif (generation !== this.generation || generation <= this.lastEndedGeneration) return;\n\t\tif (message.type === \"engine_heartbeat\") this.options.interactiveEngine?.onHeartbeat?.();\n\t\tif (message.type === \"engine_ready\") this.enginePid = message.pid;\n\t\tif (message.type === \"engine_bound\") {\n\t\t\tthis.boundGeneration = generation;\n\t\t\tfor (const frame of this.pendingProjectTrustFrames.drain(generation)) {\n\t\t\t\tif (this.stdinWriter) this.bestEffort(this.stdinWriter.write(frame), \"project trust notification\");\n\t\t\t}\n\t\t}\n\t\tif (message.type === \"engine_keybindings_reloaded\") this.latestEngineKeybindingState = message.state;\n\t\tif (message.type === \"engine_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\tthis.pendingProjectTrustFrames.dropGeneration(generation);\n\t\tfor (const listener of [...this.generationEndedListeners]) listener(event);\n\t}\n\tprivate failTransport(rawError: Error): void {\n\t\tthis.options.interactiveEngine?.onDiagnostic({\n\t\t\tactivity: undefined,\n\t\t\telapsedMs: 0,\n\t\t\tlevel: \"unresponsive\",\n\t\t\tmessage: rawError.message,\n\t\t});\n\t\tthis.failGeneration(rawError, this.generation, \"transport-error\");\n\t}\n\tprivate requireWriter(): QueuedWriter {\n\t\tif (!this.stdinWriter) throw rpcTransportError(\"Agent process stdin is not writable\");\n\t\treturn this.stdinWriter;\n\t}\n\tprivate bestEffort(operation: Promise<void>, label: string): void {\n\t\tvoid operation.catch((error: Error) => {\n\t\t\tif (!this.process || this.exitError) return;\n\t\t\tthis.options.interactiveEngine?.onDiagnostic({\n\t\t\t\tactivity: undefined,\n\t\t\t\telapsedMs: 0,\n\t\t\t\tlevel: \"unresponsive\",\n\t\t\t\tmessage: `Interactive engine ${label} failed: ${error.message}`,\n\t\t\t});\n\t\t});\n\t}\n\tprotected async request(command: RpcCommandBody, onRequestId?: (id: string) => void): Promise<RpcResponse> {\n\t\tconst childProcess = this.process;\n\t\tif (!childProcess) throw rpcTransportError(\"Client not started\");\n\t\tif (this.exitError) throw this.exitError;\n\t\tif (childProcess.exitCode !== null) {\n\t\t\tconst error = this.createProcessExitError(childProcess.exitCode, childProcess.signalCode);\n\t\t\tthis.exitError = error;\n\t\t\tthrow error;\n\t\t}\n\t\tconst id = `req_${++this.requestId}`;\n\t\tonRequestId?.(id);\n\t\tconst fullCommand = { ...command, id } as RpcCommand;\n\t\tlet timeout: ReturnType<typeof setTimeout> | undefined;\n\t\tlet rejectResponse!: (error: Error) => void;\n\t\tconst response = new Promise<RpcResponse>((resolve, reject) => {\n\t\t\trejectResponse = reject;\n\t\t\tthis.pendingRequests.add(id, {\n\t\t\t\tresolve: (value) => {\n\t\t\t\t\tif (timeout) clearTimeout(timeout);\n\t\t\t\t\tresolve(value);\n\t\t\t\t},\n\t\t\t\treject: (error) => {\n\t\t\t\t\tif (timeout) clearTimeout(timeout);\n\t\t\t\t\treject(error);\n\t\t\t\t},\n\t\t\t});\n\t\t});\n\t\ttry {\n\t\t\tawait this.requireWriter().write(serializeJsonLine(fullCommand));\n\t\t} catch (error) {\n\t\t\tthis.pendingRequests.delete(id);\n\t\t\t// Idempotent: the writer already classified this, but a caller-supplied\n\t\t\t// stream can reject with anything, and a send that never left the host\n\t\t\t// is a transport failure whatever it threw.\n\t\t\trejectResponse(markRpcTransportFailure(error));\n\t\t\treturn response;\n\t\t}\n\t\tif (this.pendingRequests.has(id) && !LONG_LIVED_COMMANDS.has(command.type)) {\n\t\t\ttimeout = setTimeout(() => {\n\t\t\t\tthis.pendingRequests.delete(id);\n\t\t\t\trejectResponse(new Error(`Timeout waiting for response to ${command.type}. Stderr: ${this.stderr}`));\n\t\t\t}, this.options.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS);\n\t\t}\n\t\treturn response;\n\t}\n\tprivate assertSuccess(response: RpcResponse): void {\n\t\tif (response.success) return;\n\t\tif (response.errorCode === \"credential_synchronization\" && response.errorDetails) {\n\t\t\tthrow new CredentialSynchronizationError(\n\t\t\t\tresponse.errorDetails.providerId,\n\t\t\t\tresponse.errorDetails.operation,\n\t\t\t\tundefined,\n\t\t\t\t{ cause: new Error(response.error) },\n\t\t\t);\n\t\t}\n\t\tthrow new Error(response.error);\n\t}\n\tprotected data<T>(response: RpcResponse): T {\n\t\tthis.assertSuccess(response);\n\t\tconst successResponse = response as Extract<RpcResponse, { success: true; data: unknown }>;\n\t\treturn successResponse.data as T;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"rpc-client.js","sourceRoot":"","sources":["../../../src/modes/rpc/rpc-client.ts"],"names":[],"mappings":"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,oBAAoB,EACpB,cAAc,EACd,qBAAqB,EACrB,yBAAyB,GACzB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACjG,OAAO,EAAE,0BAA0B,EAAE,mBAAmB,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AACvH,OAAO,EAAE,cAAc,EAAE,M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AI,0BAA0B,CAAC,CAAC;QACjE,CAAC;QACD,OAAO,QAAQ,CAAC;IACjB,CAAC;IACO,aAAa,CAAC,QAAqB;QAC1C,IAAI,QAAQ,CAAC,OAAO;YAAE,OAAO;QAC7B,IAAI,QAAQ,CAAC,SAAS,KAAK,4BAA4B,IAAI,QAAQ,CAAC,YAAY,EAAE,CAAC;YAClF,MAAM,IAAI,8BAA8B,CACvC,QAAQ,CAAC,YAAY,CAAC,UAAU,EAChC,QAAQ,CAAC,YAAY,CAAC,SAAS,EAC/B,SAAS,EACT,EAAE,KAAK,EAAE,IAAI,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CACpC,CAAC;QACH,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IACjC,CAAC;IACS,IAAI,CAAI,QAAqB;QACtC,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;QAC7B,MAAM,eAAe,GAAG,QAAkE,CAAC;QAC3F,OAAO,eAAe,CAAC,IAAS,CAAC;IAClC,CAAC;CACD","sourcesContent":["import type { ChildProcess } from \"node:child_process\";\nimport type { ImageContent } from \"@bastani/pi-ai/compat\";\nimport type { BashResult } from \"../../core/bash-executor.ts\";\nimport { CredentialSynchronizationError } from \"../../core/model-runtime.js\";\nimport type { BashOutputChannel } from \"../../core/tools/bash.js\";\nimport { sleep } from \"../../utils/sleep.ts\";\nimport type { ActivityWatchdogDiagnostic } from \"../interactive-engine/activity-watchdog.ts\";\nimport type {\n\tInteractiveEngineGenerationEnded,\n\tInteractiveEngineGenerationEndedListener,\n\tInteractiveEngineGenerationEndKind,\n} from \"../interactive-engine/engine-generation.ts\";\nimport { InteractiveEngineMonitor } from \"../interactive-engine/engine-monitor.ts\";\nimport {\n\ttype EngineKeybindingState,\n\ttype InteractiveEngineCommand,\n\ttype InteractiveEngineMessage,\n\tserializeInteractiveEngineFrame,\n} from \"../interactive-engine/protocol.ts\";\nimport { attachJsonlLineReader, serializeJsonLine } from \"./jsonl.ts\";\nimport { QueuedWriter } from \"./queued-writer.ts\";\nimport { RpcClientApi, type RpcCommandBody } from \"./rpc-client-api.ts\";\nimport {\n\tappendBoundedStderr,\n\tcreateInteractiveJsonlOptions,\n\tcreateStderrReporter,\n\trestartCliArgs,\n\tspawnRpcClientProcess,\n\tterminateRpcClientProcess,\n} from \"./rpc-client-process.js\";\nimport { collectRpcEvents, runUserBashWithUpdates, waitForRpcIdle } from \"./rpc-client-waits.ts\";\nimport { DEFAULT_REQUEST_TIMEOUT_MS, LONG_LIVED_COMMANDS, RESTART_CANCELLED_MESSAGE } from \"./rpc-command-timeouts.ts\";\nimport { RpcEventBuffer } from \"./rpc-event-buffer.ts\";\nimport { GenerationBuffer } from \"./rpc-generation-buffer.ts\";\nimport { RpcPendingRequests } from \"./rpc-pending-requests.ts\";\nimport { RpcTerminalDrain } from \"./rpc-terminal-drain.ts\";\nimport { markRpcTransportFailure, rpcTransportError } from \"./rpc-transport-error.ts\";\nimport type { RpcCommand, RpcEvent, RpcExtensionUIRequest, RpcExtensionUIResponse, RpcResponse } from \"./rpc-types.ts\";\n\nexport type { ModelInfo, RpcCommandBody } from \"./rpc-client-api.ts\";\nexport type { RpcEvent } from \"./rpc-types.ts\";\n\nexport interface RpcClientOptions {\n\tcliPath?: string;\n\tcwd?: string;\n\tenv?: Record<string, string>;\n\tprovider?: string;\n\tmodel?: string;\n\targs?: string[];\n\truntimeExecutable?: string;\n\truntimeArgs?: string[];\n\t/**\n\t * Bounded deadline (ms) applied to short metadata/control requests. Long-lived\n\t * commands (see LONG_LIVED_COMMANDS) never use this timer. Defaults to 30s.\n\t */\n\trequestTimeoutMs?: number;\n\tinteractiveEngine?: {\n\t\tonDiagnostic: (diagnostic: ActivityWatchdogDiagnostic) => void;\n\t\tonActivityChange?: (active: boolean) => void;\n\t\t/**\n\t\t * Heartbeat observer. Deliberately NOT a generic engine-message listener:\n\t\t * subscribing there drains the buffered startup custom-UI messages into the\n\t\t * first subscriber and stops buffering for the real controllers.\n\t\t */\n\t\tonHeartbeat?: () => void;\n\t\t/**\n\t\t * Credential for the engine child. Delivered through the protected\n\t\t * bootstrap file, never through the child's environment or argv.\n\t\t */\n\t\tapiKey?: string;\n\t};\n}\n\nexport type RpcEventListener = (event: RpcEvent) => void;\n\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 pendingProjectTrustFrames = new GenerationBuffer<string>();\n\tprivate boundGeneration = 0;\n\tprivate readonly pendingRequests = new RpcPendingRequests();\n\t/** Bumped by every explicit stop; a restart holds a permit across its own stop. */\n\tprivate restartRevision = 0;\n\tprivate stopPromise: Promise<void> | undefined;\n\tprivate readonly terminalDrain = new RpcTerminalDrain();\n\tprivate stdoutDrained: Promise<void> = Promise.resolve();\n\tprivate requestId = 0;\n\tprivate stderr = \"\";\n\tprivate exitError: Error | null = null;\n\tprivate engineMonitor: InteractiveEngineMonitor | undefined;\n\tprivate eventBuffer: RpcEventBuffer | undefined;\n\tprivate stdinWriter: QueuedWriter | undefined;\n\tprivate generation = 0;\n\tprivate lastEndedGeneration = 0;\n\tprivate generationEndedListeners: InteractiveEngineGenerationEndedListener[] = [];\n\t/**\n\t * The latest generation-end event, retained so a subscriber that attaches\n\t * after the child died still observes it. A child can exit between\n\t * `start()` returning and the runtime constructing its listeners.\n\t */\n\tprivate retainedGenerationEnd: InteractiveEngineGenerationEnded | undefined;\n\tprivate readonly activeActivityIds = new Set<string>();\n\tprivate enginePid: number | undefined;\n\n\tprivate declare options: RpcClientOptions;\n\n\tconstructor(options: RpcClientOptions = {}) {\n\t\tsuper();\n\t\tthis.options = options;\n\t}\n\n\tasync start(): Promise<void> {\n\t\tif (this.process) {\n\t\t\tthrow new Error(\"Client already started\");\n\t\t}\n\n\t\tconst cliPath = this.options.cliPath ?? \"dist/cli.js\";\n\t\tconst args = [\"--mode\", \"rpc\"];\n\n\t\tif (this.options.provider) {\n\t\t\targs.push(\"--provider\", this.options.provider);\n\t\t}\n\t\tif (this.options.model) {\n\t\t\targs.push(\"--model\", this.options.model);\n\t\t}\n\t\tif (this.options.args) {\n\t\t\targs.push(...this.options.args);\n\t\t}\n\n\t\tconst generation = ++this.generation;\n\t\tthis.exitError = null;\n\t\tthis.stderr = \"\";\n\t\tthis.activeActivityIds.clear();\n\t\tthis.enginePid = undefined;\n\t\tthis.engineMonitor = this.options.interactiveEngine\n\t\t\t? new InteractiveEngineMonitor(this.options.interactiveEngine.onDiagnostic, (message) =>\n\t\t\t\t\tthis.observeInteractiveEngineMessage(message, generation),\n\t\t\t\t)\n\t\t\t: undefined;\n\t\tthis.eventBuffer = this.engineMonitor ? new RpcEventBuffer((event) => this.emitEvent(event)) : undefined;\n\t\tconst childProcess = spawnRpcClientProcess({\n\t\t\tcliPath,\n\t\t\tcliArgs: args,\n\t\t\tcwd: this.options.cwd,\n\t\t\tenv: this.options.env,\n\t\t\truntimeExecutable: this.options.runtimeExecutable,\n\t\t\truntimeArgs: this.options.runtimeArgs,\n\t\t\tinteractiveEngine: this.engineMonitor !== undefined,\n\t\t\t...(this.options.interactiveEngine?.apiKey\n\t\t\t\t? { interactiveEngineApiKey: this.options.interactiveEngine.apiKey }\n\t\t\t\t: {}),\n\t\t});\n\t\tthis.process = childProcess;\n\t\tthis.stdinWriter = new QueuedWriter(childProcess.stdin!);\n\n\t\tchildProcess.once(\"exit\", (code, signal) =>\n\t\t\tthis.failGeneration(this.createProcessExitError(code, signal), generation, \"exit\"),\n\t\t);\n\t\tchildProcess.once(\"error\", (rawError) => this.failGeneration(rawError, generation, \"process-error\"));\n\t\tchildProcess.stdin?.on(\"error\", (rawError) => this.failGeneration(rawError, generation, \"stdin-error\"));\n\t\tconst reportStderr = createStderrReporter((message) => {\n\t\t\tif (generation !== this.generation) return;\n\t\t\tif (this.options.interactiveEngine) {\n\t\t\t\tthis.options.interactiveEngine.onDiagnostic({\n\t\t\t\t\tactivity: undefined,\n\t\t\t\t\telapsedMs: 0,\n\t\t\t\t\tlevel: \"blocking\",\n\t\t\t\t\tsource: \"stderr\",\n\t\t\t\t\tmessage,\n\t\t\t\t});\n\t\t\t} else console.log(message);\n\t\t});\n\t\t// Decode continuously per child, including split code points and the final incomplete sequence at EOF.\n\t\tchildProcess.stderr?.setEncoding(\"utf8\");\n\t\tchildProcess.stderr?.on(\"data\", (data: string) => {\n\t\t\tif (generation !== this.generation) return;\n\t\t\tthis.stderr = appendBoundedStderr(this.stderr, data);\n\t\t\treportStderr(data);\n\t\t});\n\t\tconst readerOptions = createInteractiveJsonlOptions(this.engineMonitor !== undefined);\n\t\tlet markStdoutDrained!: () => void;\n\t\tthis.stdoutDrained = new Promise<void>((resolve) => {\n\t\t\tmarkStdoutDrained = resolve;\n\t\t});\n\t\tthis.stopReadingStdout = attachJsonlLineReader(\n\t\t\tchildProcess.stdout!,\n\t\t\t(line) => {\n\t\t\t\tif (generation === this.generation) this.handleLine(line, generation);\n\t\t\t},\n\t\t\t{ ...readerOptions, onDrained: () => markStdoutDrained() },\n\t\t);\n\t\tif (this.engineMonitor) await this.engineMonitor.waitUntilReady();\n\t\telse await sleep(100);\n\n\t\tif (generation !== this.generation || this.process?.exitCode !== null) {\n\t\t\tthrow rpcTransportError(`Agent process exited immediately. Stderr: ${this.stderr}`);\n\t\t}\n\t}\n\n\t/**\n\t * 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 (command.type === \"engine_project_trust_start\" || command.type === \"engine_project_trust_end\") {\n\t\t\tif (this.generation <= this.lastEndedGeneration) return;\n\t\t\t// The terminal can open and close /trust while the engine is still binding.\n\t\t\t// Retain both frames, without delaying the host-owned decision.\n\t\t\tif (this.engineMonitor && this.boundGeneration !== this.generation) {\n\t\t\t\tthis.pendingProjectTrustFrames.push(this.generation, serializeInteractiveEngineFrame(command));\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tif (!writer) return;\n\t\tconst frame = serializeInteractiveEngineFrame(command);\n\t\tif (\n\t\t\tcommand.type === \"engine_custom_render\" ||\n\t\t\tcommand.type === \"engine_tool_render\" ||\n\t\t\tcommand.type === \"engine_message_render\"\n\t\t) {\n\t\t\twriter.offerLatest(`render:${command.componentId}`, frame);\n\t\t\treturn;\n\t\t}\n\t\tthis.bestEffort(writer.write(frame), `engine command ${command.type}`);\n\t}\n\twaitForInteractiveEngineBound(): Promise<void> {\n\t\treturn this.engineMonitor?.waitUntilBound() ?? Promise.resolve();\n\t}\n\twaitForInteractiveEngineResources(): Promise<void> {\n\t\treturn this.engineMonitor?.waitUntilResourcesReady() ?? Promise.resolve();\n\t}\n\tgetEnginePid(): number | undefined {\n\t\treturn this.enginePid;\n\t}\n\tgetGeneration(): number {\n\t\treturn this.generation;\n\t}\n\n\t/**\n\t * Replace the engine child, unless an explicit stop supersedes this attempt.\n\t * The permit is checked immediately before spawning, so a `stop()` in that\n\t * window is always observed; cancellation throws rather than returning\n\t * quietly, because callers go on to initialize against the new child.\n\t */\n\tasync restart(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 (\n\t\t\tthis.engineMessageListeners.length === 0 &&\n\t\t\t(message.type.startsWith(\"engine_custom_\") || message.type.startsWith(\"engine_resources_\"))\n\t\t) {\n\t\t\tthis.pendingEngineMessages.push(generation, message);\n\t\t}\n\t\tfor (const listener of this.engineMessageListeners) listener(message);\n\t}\n\tprivate createProcessExitError(code: number | null, signal: NodeJS.Signals | null): Error {\n\t\treturn rpcTransportError(`Agent process exited (code=${code} signal=${signal}). Stderr: ${this.stderr}`);\n\t}\n\tprivate invalidateEngineShortcuts(): void {\n\t\tif (!this.latestEngineKeybindingState || this.latestEngineKeybindingState.shortcuts.length === 0) return;\n\t\tconst state: EngineKeybindingState = { ...this.latestEngineKeybindingState, shortcuts: [] };\n\t\tthis.latestEngineKeybindingState = state;\n\t\tthis.emitInteractiveEngineMessage({ type: \"engine_keybindings_reloaded\", state }, this.generation);\n\t}\n\tprivate observeInteractiveEngineMessage(message: InteractiveEngineMessage, generation: number): void {\n\t\t// Ownership is the one thing a dead generation may still report: request\n\t\t// ids never repeat, and the alternative is classifying work it already\n\t\t// started as never sent. Nothing else from it may touch host state — a\n\t\t// stale frame would revive a PID, an activity, or a mount that is gone.\n\t\tif (message.type === \"engine_request_accepted\") {\n\t\t\tif (generation === this.generation) this.pendingRequests.markAccepted(message.requestId);\n\t\t\treturn;\n\t\t}\n\t\tif (generation !== this.generation || generation <= this.lastEndedGeneration) return;\n\t\tif (message.type === \"engine_heartbeat\") this.options.interactiveEngine?.onHeartbeat?.();\n\t\tif (message.type === \"engine_ready\") this.enginePid = message.pid;\n\t\tif (message.type === \"engine_bound\") {\n\t\t\tthis.boundGeneration = generation;\n\t\t\tfor (const frame of this.pendingProjectTrustFrames.drain(generation)) {\n\t\t\t\tif (this.stdinWriter) this.bestEffort(this.stdinWriter.write(frame), \"project trust notification\");\n\t\t\t}\n\t\t}\n\t\tif (message.type === \"engine_keybindings_reloaded\") this.latestEngineKeybindingState = message.state;\n\t\tif (message.type === \"engine_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\tthis.pendingProjectTrustFrames.dropGeneration(generation);\n\t\tfor (const listener of [...this.generationEndedListeners]) listener(event);\n\t}\n\tprivate failTransport(rawError: Error): void {\n\t\tthis.options.interactiveEngine?.onDiagnostic({\n\t\t\tactivity: undefined,\n\t\t\telapsedMs: 0,\n\t\t\tlevel: \"unresponsive\",\n\t\t\tmessage: rawError.message,\n\t\t});\n\t\tthis.failGeneration(rawError, this.generation, \"transport-error\");\n\t}\n\tprivate requireWriter(): QueuedWriter {\n\t\tif (!this.stdinWriter) throw rpcTransportError(\"Agent process stdin is not writable\");\n\t\treturn this.stdinWriter;\n\t}\n\tprivate bestEffort(operation: Promise<void>, label: string): void {\n\t\tvoid operation.catch((error: Error) => {\n\t\t\tif (!this.process || this.exitError) return;\n\t\t\tthis.options.interactiveEngine?.onDiagnostic({\n\t\t\t\tactivity: undefined,\n\t\t\t\telapsedMs: 0,\n\t\t\t\tlevel: \"unresponsive\",\n\t\t\t\tmessage: `Interactive engine ${label} failed: ${error.message}`,\n\t\t\t});\n\t\t});\n\t}\n\tprotected async request(command: RpcCommandBody, onRequestId?: (id: string) => void): Promise<RpcResponse> {\n\t\tconst childProcess = this.process;\n\t\tif (!childProcess) throw rpcTransportError(\"Client not started\");\n\t\tif (this.exitError) throw this.exitError;\n\t\tif (childProcess.exitCode !== null) {\n\t\t\tconst error = this.createProcessExitError(childProcess.exitCode, childProcess.signalCode);\n\t\t\tthis.exitError = error;\n\t\t\tthrow error;\n\t\t}\n\t\tconst id = `req_${++this.requestId}`;\n\t\tonRequestId?.(id);\n\t\tconst fullCommand = { ...command, id } as RpcCommand;\n\t\tlet timeout: ReturnType<typeof setTimeout> | undefined;\n\t\tlet rejectResponse!: (error: Error) => void;\n\t\tconst response = new Promise<RpcResponse>((resolve, reject) => {\n\t\t\trejectResponse = reject;\n\t\t\tthis.pendingRequests.add(id, {\n\t\t\t\tresolve: (value) => {\n\t\t\t\t\tif (timeout) clearTimeout(timeout);\n\t\t\t\t\tresolve(value);\n\t\t\t\t},\n\t\t\t\treject: (error) => {\n\t\t\t\t\tif (timeout) clearTimeout(timeout);\n\t\t\t\t\treject(error);\n\t\t\t\t},\n\t\t\t});\n\t\t});\n\t\ttry {\n\t\t\tawait this.requireWriter().write(serializeJsonLine(fullCommand));\n\t\t} catch (error) {\n\t\t\tthis.pendingRequests.delete(id);\n\t\t\t// Idempotent: the writer already classified this, but a caller-supplied\n\t\t\t// stream can reject with anything, and a send that never left the host\n\t\t\t// is a transport failure whatever it threw.\n\t\t\trejectResponse(markRpcTransportFailure(error));\n\t\t\treturn response;\n\t\t}\n\t\tif (this.pendingRequests.has(id) && !LONG_LIVED_COMMANDS.has(command.type)) {\n\t\t\ttimeout = setTimeout(() => {\n\t\t\t\tthis.pendingRequests.delete(id);\n\t\t\t\trejectResponse(new Error(`Timeout waiting for response to ${command.type}. Stderr: ${this.stderr}`));\n\t\t\t}, this.options.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS);\n\t\t}\n\t\treturn response;\n\t}\n\tprivate assertSuccess(response: RpcResponse): void {\n\t\tif (response.success) return;\n\t\tif (response.errorCode === \"credential_synchronization\" && response.errorDetails) {\n\t\t\tthrow new CredentialSynchronizationError(\n\t\t\t\tresponse.errorDetails.providerId,\n\t\t\t\tresponse.errorDetails.operation,\n\t\t\t\tundefined,\n\t\t\t\t{ cause: new Error(response.error) },\n\t\t\t);\n\t\t}\n\t\tthrow new Error(response.error);\n\t}\n\tprotected data<T>(response: RpcResponse): T {\n\t\tthis.assertSuccess(response);\n\t\tconst successResponse = response as Extract<RpcResponse, { success: true; data: unknown }>;\n\t\treturn successResponse.data as T;\n\t}\n}\n"]}
|
package/dist/utils/markit.d.ts
CHANGED
|
@@ -3,6 +3,8 @@ export interface MarkitConversionResult {
|
|
|
3
3
|
ok: boolean;
|
|
4
4
|
error?: string;
|
|
5
5
|
}
|
|
6
|
+
/** Bind the in-process interactive renderer for its lifetime. */
|
|
7
|
+
export declare function setMarkitDiagnosticSink(sink: (message: string) => void): () => void;
|
|
6
8
|
export declare function convertFileWithMarkit(filePath: string, signal?: AbortSignal): Promise<MarkitConversionResult>;
|
|
7
9
|
export declare function convertBufferWithMarkit(buffer: Uint8Array, extension: string, signal?: AbortSignal): Promise<MarkitConversionResult>;
|
|
8
10
|
//# sourceMappingURL=markit.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markit.d.ts","sourceRoot":"","sources":["../../src/utils/markit.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,sBAAsB;IACtC,OAAO,EAAE,MAAM,CAAC;IAChB,EAAE,EAAE,OAAO,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;CACf;
|
|
1
|
+
{"version":3,"file":"markit.d.ts","sourceRoot":"","sources":["../../src/utils/markit.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,sBAAsB;IACtC,OAAO,EAAE,MAAM,CAAC;IAChB,EAAE,EAAE,OAAO,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;CACf;AAiBD,iEAAiE;AACjE,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,GAAG,MAAM,IAAI,CAMnF;AAmFD,wBAAsB,qBAAqB,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,sBAAsB,CAAC,CASnH;AAED,wBAAsB,uBAAuB,CAC5C,MAAM,EAAE,UAAU,EAClB,SAAS,EAAE,MAAM,EACjB,MAAM,CAAC,EAAE,WAAW,GAClB,OAAO,CAAC,sBAAsB,CAAC,CAWjC"}
|
package/dist/utils/markit.js
CHANGED
|
@@ -1,4 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MuPDF ships as an Emscripten module whose fd 1 and fd 2 sinks default to
|
|
3
|
+
* `console.log` / `console.error` (`mupdf/dist/mupdf-wasm.js`:
|
|
4
|
+
* `t.print&&(T=t.print),t.printErr&&(j=t.printErr)`), and
|
|
5
|
+
* `mupdf/dist/mupdf.js` builds that module at import time from
|
|
6
|
+
* `globalThis["$libmupdf_wasm_Module"]`. A PDF with a damaged `/FlateDecode`
|
|
7
|
+
* stream therefore writes diagnostics straight to the terminal. Capture a
|
|
8
|
+
* bounded batch and deliver it through the active TUI sink or console.log.
|
|
9
|
+
* RPC mode's stdout guard forwards console.log to the host through stderr.
|
|
10
|
+
*/
|
|
11
|
+
const MUPDF_MODULE_GLOBAL = "$libmupdf_wasm_Module";
|
|
12
|
+
const MAX_MUPDF_DIAGNOSTIC_LINES = 32;
|
|
13
|
+
const MAX_MUPDF_DIAGNOSTIC_LENGTH = 4096;
|
|
14
|
+
let diagnosticSink;
|
|
15
|
+
/** Bind the in-process interactive renderer for its lifetime. */
|
|
16
|
+
export function setMarkitDiagnosticSink(sink) {
|
|
17
|
+
const previous = diagnosticSink;
|
|
18
|
+
diagnosticSink = sink;
|
|
19
|
+
return () => {
|
|
20
|
+
if (diagnosticSink === sink)
|
|
21
|
+
diagnosticSink = previous;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function logMupdfDiagnostics() {
|
|
25
|
+
if (mupdfDiagnostics.length === 0)
|
|
26
|
+
return;
|
|
27
|
+
const message = mupdfDiagnostics.join("\n");
|
|
28
|
+
if (diagnosticSink)
|
|
29
|
+
diagnosticSink(message);
|
|
30
|
+
else
|
|
31
|
+
console.log(message);
|
|
32
|
+
}
|
|
33
|
+
// Process-global because the MuPDF module is: concurrent conversions may
|
|
34
|
+
// cross-attribute a line. The text is advisory suffix on an error message,
|
|
35
|
+
// never a decision input, so that imprecision is acceptable.
|
|
36
|
+
let mupdfDiagnostics = [];
|
|
37
|
+
function recordMupdfDiagnostic(line) {
|
|
38
|
+
if (mupdfDiagnostics.length >= MAX_MUPDF_DIAGNOSTIC_LINES)
|
|
39
|
+
mupdfDiagnostics.shift();
|
|
40
|
+
mupdfDiagnostics.push(line.slice(0, MAX_MUPDF_DIAGNOSTIC_LENGTH));
|
|
41
|
+
}
|
|
42
|
+
/** Must run before the first `import("markit-ai")`; mupdf reads the global at module evaluation. */
|
|
43
|
+
function captureMupdfDiagnostics() {
|
|
44
|
+
const globals = globalThis;
|
|
45
|
+
const existing = (globals[MUPDF_MODULE_GLOBAL] ?? {});
|
|
46
|
+
globals[MUPDF_MODULE_GLOBAL] = { ...existing, print: recordMupdfDiagnostic, printErr: recordMupdfDiagnostic };
|
|
47
|
+
}
|
|
48
|
+
function withMupdfDiagnostics(message) {
|
|
49
|
+
if (mupdfDiagnostics.length === 0)
|
|
50
|
+
return message;
|
|
51
|
+
logMupdfDiagnostics();
|
|
52
|
+
const detail = mupdfDiagnostics.join("; ");
|
|
53
|
+
mupdfDiagnostics = [];
|
|
54
|
+
return `${message} (mupdf: ${detail})`;
|
|
55
|
+
}
|
|
1
56
|
let markit = async () => {
|
|
57
|
+
captureMupdfDiagnostics();
|
|
2
58
|
const promise = import("markit-ai").then(({ Markit }) => {
|
|
3
59
|
const instance = new Markit();
|
|
4
60
|
markit = () => instance;
|
|
@@ -23,6 +79,7 @@ async function runMarkitConversion(task, signal) {
|
|
|
23
79
|
if (signal?.aborted)
|
|
24
80
|
throw abortError();
|
|
25
81
|
const instance = await markit();
|
|
82
|
+
mupdfDiagnostics = [];
|
|
26
83
|
if (!signal)
|
|
27
84
|
return task(instance);
|
|
28
85
|
return await new Promise((resolve, reject) => {
|
|
@@ -34,9 +91,12 @@ async function runMarkitConversion(task, signal) {
|
|
|
34
91
|
});
|
|
35
92
|
}
|
|
36
93
|
function finalizeConversion(markdown) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
94
|
+
if (typeof markdown === "string" && markdown.length > 0) {
|
|
95
|
+
logMupdfDiagnostics();
|
|
96
|
+
mupdfDiagnostics = [];
|
|
97
|
+
return { content: markdown, ok: true };
|
|
98
|
+
}
|
|
99
|
+
return { content: "", ok: false, error: withMupdfDiagnostics("Conversion produced no output") };
|
|
40
100
|
}
|
|
41
101
|
export async function convertFileWithMarkit(filePath, signal) {
|
|
42
102
|
try {
|
|
@@ -45,7 +105,7 @@ export async function convertFileWithMarkit(filePath, signal) {
|
|
|
45
105
|
catch (error) {
|
|
46
106
|
if (error instanceof Error && error.name === "AbortError")
|
|
47
107
|
throw error;
|
|
48
|
-
return { content: "", ok: false, error: normalizeError(error) };
|
|
108
|
+
return { content: "", ok: false, error: withMupdfDiagnostics(normalizeError(error)) };
|
|
49
109
|
}
|
|
50
110
|
}
|
|
51
111
|
export async function convertBufferWithMarkit(buffer, extension, signal) {
|
|
@@ -57,7 +117,7 @@ export async function convertBufferWithMarkit(buffer, extension, signal) {
|
|
|
57
117
|
catch (error) {
|
|
58
118
|
if (error instanceof Error && error.name === "AbortError")
|
|
59
119
|
throw error;
|
|
60
|
-
return { content: "", ok: false, error: normalizeError(error) };
|
|
120
|
+
return { content: "", ok: false, error: withMupdfDiagnostics(normalizeError(error)) };
|
|
61
121
|
}
|
|
62
122
|
}
|
|
63
123
|
//# sourceMappingURL=markit.js.map
|
package/dist/utils/markit.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markit.js","sourceRoot":"","sources":["../../src/ut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AAC,CAAC,EAAE,CAAC;IACvF,CAAC;AACF,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC5C,MAAkB,EAClB,SAAiB,EACjB,MAAoB;IAEpB,MAAM,mBAAmB,GAAG,kBAAkB,CAAC,SAAS,CAAC,CAAC;IAC1D,MAAM,UAAU,GAAe,EAAE,SAAS,EAAE,mBAAmB,EAAE,QAAQ,EAAE,QAAQ,mBAAmB,EAAE,EAAE,CAAC;IAC3G,IAAI,CAAC;QACJ,OAAO,kBAAkB,CACxB,CAAC,MAAM,mBAAmB,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,UAAU,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,QAAQ,CAC7G,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,IAAI,KAAK,YAAY,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,YAAY;YAAE,MAAM,KAAK,CAAC;QACvE,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,oBAAoB,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;IACvF,CAAC;AACF,CAAC","sourcesContent":["import type { Markit, StreamInfo } from \"markit-ai\";\n\nexport interface MarkitConversionResult {\n\tcontent: string;\n\tok: boolean;\n\terror?: string;\n}\n\n/**\n * MuPDF ships as an Emscripten module whose fd 1 and fd 2 sinks default to\n * `console.log` / `console.error` (`mupdf/dist/mupdf-wasm.js`:\n * `t.print&&(T=t.print),t.printErr&&(j=t.printErr)`), and\n * `mupdf/dist/mupdf.js` builds that module at import time from\n * `globalThis[\"$libmupdf_wasm_Module\"]`. A PDF with a damaged `/FlateDecode`\n * stream therefore writes diagnostics straight to the terminal. Capture a\n * bounded batch and deliver it through the active TUI sink or console.log.\n * RPC mode's stdout guard forwards console.log to the host through stderr.\n */\nconst MUPDF_MODULE_GLOBAL = \"$libmupdf_wasm_Module\";\nconst MAX_MUPDF_DIAGNOSTIC_LINES = 32;\nconst MAX_MUPDF_DIAGNOSTIC_LENGTH = 4096;\nlet diagnosticSink: ((message: string) => void) | undefined;\n\n/** Bind the in-process interactive renderer for its lifetime. */\nexport function setMarkitDiagnosticSink(sink: (message: string) => void): () => void {\n\tconst previous = diagnosticSink;\n\tdiagnosticSink = sink;\n\treturn () => {\n\t\tif (diagnosticSink === sink) diagnosticSink = previous;\n\t};\n}\n\nfunction logMupdfDiagnostics(): void {\n\tif (mupdfDiagnostics.length === 0) return;\n\tconst message = mupdfDiagnostics.join(\"\\n\");\n\tif (diagnosticSink) diagnosticSink(message);\n\telse console.log(message);\n}\n\n// Process-global because the MuPDF module is: concurrent conversions may\n// cross-attribute a line. The text is advisory suffix on an error message,\n// never a decision input, so that imprecision is acceptable.\nlet mupdfDiagnostics: string[] = [];\n\nfunction recordMupdfDiagnostic(line: string): void {\n\tif (mupdfDiagnostics.length >= MAX_MUPDF_DIAGNOSTIC_LINES) mupdfDiagnostics.shift();\n\tmupdfDiagnostics.push(line.slice(0, MAX_MUPDF_DIAGNOSTIC_LENGTH));\n}\n\n/** Must run before the first `import(\"markit-ai\")`; mupdf reads the global at module evaluation. */\nfunction captureMupdfDiagnostics(): void {\n\tconst globals = globalThis as Record<string, unknown>;\n\tconst existing = (globals[MUPDF_MODULE_GLOBAL] ?? {}) as Record<string, unknown>;\n\tglobals[MUPDF_MODULE_GLOBAL] = { ...existing, print: recordMupdfDiagnostic, printErr: recordMupdfDiagnostic };\n}\n\nfunction withMupdfDiagnostics(message: string): string {\n\tif (mupdfDiagnostics.length === 0) return message;\n\tlogMupdfDiagnostics();\n\tconst detail = mupdfDiagnostics.join(\"; \");\n\tmupdfDiagnostics = [];\n\treturn `${message} (mupdf: ${detail})`;\n}\n\nlet markit: () => Markit | Promise<Markit> = async () => {\n\tcaptureMupdfDiagnostics();\n\tconst promise = import(\"markit-ai\").then(({ Markit }) => {\n\t\tconst instance = new Markit();\n\t\tmarkit = () => instance;\n\t\treturn instance;\n\t});\n\tmarkit = () => promise;\n\treturn promise;\n};\n\nfunction normalizeExtension(extension: string): string {\n\tconst trimmed = extension.trim().toLowerCase();\n\treturn trimmed ? (trimmed.startsWith(\".\") ? trimmed : `.${trimmed}`) : \".bin\";\n}\n\nfunction normalizeError(error: unknown): string {\n\treturn error instanceof Error && error.message.trim().length > 0 ? error.message.trim() : \"Conversion failed\";\n}\n\nfunction abortError(): Error {\n\tconst error = new Error(\"Aborted\");\n\terror.name = \"AbortError\";\n\treturn error;\n}\n\nasync function runMarkitConversion<T>(task: (markit: Markit) => Promise<T>, signal?: AbortSignal): Promise<T> {\n\tif (signal?.aborted) throw abortError();\n\tconst instance = await markit();\n\tmupdfDiagnostics = [];\n\tif (!signal) return task(instance);\n\treturn await new Promise<T>((resolve, reject) => {\n\t\tconst abort = () => reject(abortError());\n\t\tsignal.addEventListener(\"abort\", abort, { once: true });\n\t\tvoid task(instance)\n\t\t\t.then(resolve, reject)\n\t\t\t.finally(() => signal.removeEventListener(\"abort\", abort));\n\t});\n}\n\nfunction finalizeConversion(markdown?: string): MarkitConversionResult {\n\tif (typeof markdown === \"string\" && markdown.length > 0) {\n\t\tlogMupdfDiagnostics();\n\t\tmupdfDiagnostics = [];\n\t\treturn { content: markdown, ok: true };\n\t}\n\treturn { content: \"\", ok: false, error: withMupdfDiagnostics(\"Conversion produced no output\") };\n}\n\nexport async function convertFileWithMarkit(filePath: string, signal?: AbortSignal): Promise<MarkitConversionResult> {\n\ttry {\n\t\treturn finalizeConversion(\n\t\t\t(await runMarkitConversion((instance) => instance.convertFile(filePath), signal)).markdown,\n\t\t);\n\t} catch (error) {\n\t\tif (error instanceof Error && error.name === \"AbortError\") throw error;\n\t\treturn { content: \"\", ok: false, error: withMupdfDiagnostics(normalizeError(error)) };\n\t}\n}\n\nexport async function convertBufferWithMarkit(\n\tbuffer: Uint8Array,\n\textension: string,\n\tsignal?: AbortSignal,\n): Promise<MarkitConversionResult> {\n\tconst normalizedExtension = normalizeExtension(extension);\n\tconst streamInfo: StreamInfo = { extension: normalizedExtension, filename: `input${normalizedExtension}` };\n\ttry {\n\t\treturn finalizeConversion(\n\t\t\t(await runMarkitConversion((instance) => instance.convert(Buffer.from(buffer), streamInfo), signal)).markdown,\n\t\t);\n\t} catch (error) {\n\t\tif (error instanceof Error && error.name === \"AbortError\") throw error;\n\t\treturn { content: \"\", ok: false, error: withMupdfDiagnostics(normalizeError(error)) };\n\t}\n}\n"]}
|
package/docs/background-tasks.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
---
|
|
2
|
-
title: "Background
|
|
2
|
+
title: "Background and parallel work"
|
|
3
3
|
description: "Run subagents and shell tasks while continuing your conversation"
|
|
4
4
|
---
|
|
5
5
|
|
|
@@ -25,6 +25,10 @@ Opening `/tasks` is navigation, not an approval request. It does not mark the ag
|
|
|
25
25
|
|
|
26
26
|
The agent can choose foreground-first or background observation for each authorized shell or subagent call. Choosing a mode does not require a separate user confirmation and does not relax tool permissions or task ownership.
|
|
27
27
|
|
|
28
|
+
For ordinary shell commands, leave `wait` out rather than routinely requesting one-second waits. Short waits can background otherwise brief commands and add follow-up calls without speeding up execution. Use explicit background observation when you have independent work to do, and a short budget only when you need control back sooner. Explicit budgets remain supported on every platform.
|
|
29
|
+
|
|
30
|
+
Keep immediately blocking work local unless a specialist, isolated context, or your explicit delegation request makes a subagent worthwhile. After spawning, continue independent work without duplicating the child's task. Wait when its result becomes a dependency; otherwise rely on completion notices rather than repeated short waits or status polls.
|
|
31
|
+
|
|
28
32
|
| Call | Observation behavior |
|
|
29
33
|
| --- | --- |
|
|
30
34
|
| `bash` or `powershell` without `wait` | Waits for the owner's command observation budget, normally 10 seconds, then automatically returns if still running. |
|
|
@@ -75,7 +79,7 @@ A launch result says **Launched in background**. This records what happened at l
|
|
|
75
79
|
|
|
76
80
|
### Waiting is not restarting
|
|
77
81
|
|
|
78
|
-
|
|
82
|
+
When specialist delegation is useful and its result is needed next, use foreground observation:
|
|
79
83
|
|
|
80
84
|
```ts
|
|
81
85
|
subagent({
|
|
@@ -88,7 +92,7 @@ subagent({
|
|
|
88
92
|
If that observation budget expires, the same child continues in the background. It is not an execution timeout. Observe the task ID returned by the original call:
|
|
89
93
|
|
|
90
94
|
```ts
|
|
91
|
-
subagent({ action: "wait", id: taskId
|
|
95
|
+
subagent({ action: "wait", id: taskId })
|
|
92
96
|
subagent({ action: "status", id: taskId })
|
|
93
97
|
```
|
|
94
98
|
|
|
@@ -156,14 +160,14 @@ Completed, failed, and stopped tasks retain inspection but do not offer executio
|
|
|
156
160
|
Top-level model `bash` calls on POSIX and native Windows, and `powershell` calls on native Windows, use the session's task owner. A long command can outlive its foreground observation budget and return a task ID while continuing to run. Its status then appears below the prompt and under **Shells** in `/tasks`. An explicit execution timeout still ends the command; it is separate from observation yielding.
|
|
157
161
|
|
|
158
162
|
```ts
|
|
159
|
-
//
|
|
160
|
-
bash({ command: "npm run
|
|
163
|
+
// Ordinary commands use the owner's observation budget, normally 10 seconds.
|
|
164
|
+
bash({ command: "npm run check" })
|
|
161
165
|
|
|
162
|
-
//
|
|
163
|
-
bash({ command: "npm
|
|
166
|
+
// Background a build when you can do independent work while it runs.
|
|
167
|
+
bash({ command: "npm run build", wait: { kind: "background" }, timeout: 600 })
|
|
164
168
|
|
|
165
|
-
//
|
|
166
|
-
bash({ command: "npm
|
|
169
|
+
// Wait longer when the test result is needed next; execution timeout is separate.
|
|
170
|
+
bash({ command: "npm test", wait: { kind: "foreground", budgetMs: 30000 }, timeout: 600 })
|
|
167
171
|
```
|
|
168
172
|
|
|
169
173
|
The shell execution timeout is separate: `timeout` is seconds and defaults to 300, with a maximum of 3600. It continues counting after backgrounding. Choose a timeout appropriate for the command; reducing `budgetMs` does not shorten or extend it. Use the returned task ID to inspect or stop the existing task through `/tasks`. Background completion notifies the parent automatically, so there is no need to launch the command again to collect its result.
|
|
@@ -171,8 +175,8 @@ The shell execution timeout is separate: `timeout` is seconds and defaults to 30
|
|
|
171
175
|
Observe an existing task without running its command again:
|
|
172
176
|
|
|
173
177
|
```ts
|
|
174
|
-
bash({ action: "wait", id: taskId
|
|
175
|
-
powershell({ action: "wait", id: taskId
|
|
178
|
+
bash({ action: "wait", id: taskId })
|
|
179
|
+
powershell({ action: "wait", id: taskId })
|
|
176
180
|
```
|
|
177
181
|
|
|
178
182
|
Use the original task ID from the same owning session or workflow stage. Omit `budgetMs` to use the owner's command observation policy, or pass `0` to poll. A wait returns retained output and a yielded or settled observation; settled results include available exit and failure details. While running, successive yielded waits advance through retained output in bounded pages, including after a session reload. A caught-up wait returns no output until more arrives. Settled waits return all retained output again, subject to labelled gaps and truncation, so they may repeat output you have already seen.
|
package/docs/build.md
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Build with Atomic
|
|
3
|
+
description: Extend Atomic with skills, subagents, intercom, workflows, extensions, prompt templates, themes, packages, custom models and providers, and programmatic integrations.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Build with Atomic
|
|
7
|
+
|
|
8
|
+
Build covers everything you add to Atomic: customization mechanisms that change how a session behaves, and programmatic interfaces that embed Atomic in your own software.
|
|
9
|
+
|
|
10
|
+
If you have not run Atomic yet, start at the [Quickstart](/quickstart). If you are looking for an exact contract rather than a way to build something, go to the [Reference index](/reference).
|
|
11
|
+
|
|
12
|
+
## Choose the lightest mechanism
|
|
13
|
+
|
|
14
|
+
Work down this list and stop at the first mechanism that solves your problem.
|
|
15
|
+
|
|
16
|
+
1. [Prompt templates](/prompt-templates) — reusable prompts that expand from a slash command. No code.
|
|
17
|
+
2. [Skills](/skills) — on-demand instructions the agent loads when a task matches. Markdown plus optional scripts.
|
|
18
|
+
3. [Subagents](/subagents) — delegate a focused, bounded task to a child agent.
|
|
19
|
+
4. [Intercom](/intercom) — coordinate several sessions on one machine.
|
|
20
|
+
5. [Workflows](/workflows) — multi-stage, resumable engineering loops with gates and artifacts.
|
|
21
|
+
6. [Extensions](/extensions) — TypeScript that adds tools, commands, events, and custom UI when nothing lighter fits.
|
|
22
|
+
7. [Atomic packages](/packages) — bundle and distribute the result.
|
|
23
|
+
|
|
24
|
+
## Change the model layer
|
|
25
|
+
|
|
26
|
+
- [Custom models](/models) — add model entries for a supported provider API.
|
|
27
|
+
- [Custom providers](/custom-provider) — implement a provider API or OAuth flow Atomic does not ship.
|
|
28
|
+
- [Themes](/themes) — restyle the terminal interface.
|
|
29
|
+
|
|
30
|
+
## Embed Atomic in your own software
|
|
31
|
+
|
|
32
|
+
[Programmatic use](/programmatic) compares JSON mode, RPC, and the SDK, and links each one to its protocol or API reference.
|
|
33
|
+
|
|
34
|
+
## Customization
|
|
35
|
+
|
|
36
|
+
- [Extensions](/extensions) - TypeScript modules for tools, commands, events, and custom UI.
|
|
37
|
+
- [Skills](/skills) - Agent Skills for reusable on-demand capabilities.
|
|
38
|
+
- [Subagents](/subagents) - focused child agents for research, analysis, debugging, cleanup, and review compositions.
|
|
39
|
+
- [Workflows](/workflows) - executable engineering loops with tracked stages, artifacts, gates, and resumable runs.
|
|
40
|
+
- [Prompt templates](/prompt-templates) - reusable prompts that expand from slash commands.
|
|
41
|
+
- [Themes](/themes) - built-in and custom terminal themes.
|
|
42
|
+
- [Atomic packages](/packages) - bundle and share extensions, skills, prompts, and themes.
|
|
43
|
+
- [Custom models](/models) - add model entries for supported provider APIs.
|
|
44
|
+
- [Custom providers](/custom-provider) - implement custom APIs and OAuth flows.
|
|
45
|
+
|
|
46
|
+
## Programmatic usage
|
|
47
|
+
|
|
48
|
+
- [SDK](/sdk) - embed Atomic in Node.js applications.
|
|
49
|
+
- [RPC mode](/rpc) - integrate over stdin/stdout JSONL.
|
|
50
|
+
- [JSON event stream mode](/json) - print mode with structured events.
|
|
51
|
+
- [TUI components](/tui) - build custom terminal UI for extensions.
|
package/docs/changelog.mdx
CHANGED
|
@@ -7,9 +7,9 @@ description: "What's new in Atomic"
|
|
|
7
7
|
|
|
8
8
|
## Pi 0.83.0 parity
|
|
9
9
|
|
|
10
|
-
- **One door prints a stored credential.** `atomic auth print-api-key --model <model>` and `atomic auth print-bearer-token --model <model>` hand a configured credential to an external client. The credential is all that reaches stdout — warnings, provider selection, refresh notices, and help go to stderr — `--model` is required, and each failure has its own exit code, with stdout empty on every non-zero exit. `--min-expiry` accepts `ms`, `s`, `m`, or `h`, defaults to `30m`, and is a usage error on `print-api-key`, which has no expiry to wait for. See [Usage](/
|
|
11
|
-
- **Extensions can read the session's model scope.** `ctx.scopedModels` reports the models scoped to the current session — the set `/scoped-models` shows — resolved at access time and correct under the isolated engine. It reports the scope and cannot widen it: the accessor is read-only, and every read hands back a frozen copy of the array, its entries, and their models, so neither pushing an entry nor swapping one in place reaches the session. `ScopedModel` and `ExtensionScopedModels` are exported so an extension can name what it read. See [Extensions](/extensions#
|
|
12
|
-
- **An unrecognised stop reason is now an error.** A provider that ends a turn with a terminal reason the mapping does not know surfaces a provider error naming the raw value instead of an ordinary successful stop, so a new truncation or safety signal is visible rather than silent. Streaming partials carry the new `pending` reason until the terminal event replaces it; a stream that ends still `pending` is an error. See [Providers](/providers#stop-reasons) and [Custom Providers](/custom-provider#stop-reasons).
|
|
10
|
+
- **One door prints a stored credential.** `atomic auth print-api-key --model <model>` and `atomic auth print-bearer-token --model <model>` hand a configured credential to an external client. The credential is all that reaches stdout — warnings, provider selection, refresh notices, and help go to stderr — `--model` is required, and each failure has its own exit code, with stdout empty on every non-zero exit. `--min-expiry` accepts `ms`, `s`, `m`, or `h`, defaults to `30m`, and is a usage error on `print-api-key`, which has no expiry to wait for. See [Usage](/reference/cli#credential-commands) and [Security](/security#credential-export).
|
|
11
|
+
- **Extensions can read the session's model scope.** `ctx.scopedModels` reports the models scoped to the current session — the set `/scoped-models` shows — resolved at access time and correct under the isolated engine. It reports the scope and cannot widen it: the accessor is read-only, and every read hands back a frozen copy of the array, its entries, and their models, so neither pushing an entry nor swapping one in place reaches the session. `ScopedModel` and `ExtensionScopedModels` are exported so an extension can name what it read. See [Extensions](/extensions/api-reference#ctx-modelregistry-/-ctx-model-/-ctx-scopedmodels).
|
|
12
|
+
- **An unrecognised stop reason is now an error.** A provider that ends a turn with a terminal reason the mapping does not know surfaces a provider error naming the raw value instead of an ordinary successful stop, so a new truncation or safety signal is visible rather than silent. Streaming partials carry the new `pending` reason until the terminal event replaces it; a stream that ends still `pending` is an error. See [Providers](/providers/reference#stop-reasons) and [Custom Providers](/custom-provider/streaming#stop-reasons).
|
|
13
13
|
- **OAuth tokens refresh before they expire.** A stored token with under five minutes of validity left is refreshed rather than used, so a long turn does not start on a credential that dies mid-request. The refresh runs under the `auth.json` lock and re-checks expiry inside it, so concurrent sessions sharing one credential file refresh it once between them. See [Providers](/providers#token-refresh).
|
|
14
14
|
- **Remote OpenRouter logins have a way through.** When the browser cannot reach the loopback callback — over SSH, or on a headless host — the OpenRouter login accepts the final redirect URL, or the authorization code alone, pasted into the prompt. See [Providers](/providers#subscriptions).
|
|
15
15
|
|
|
@@ -18,10 +18,10 @@ description: "What's new in Atomic"
|
|
|
18
18
|
|
|
19
19
|
## Pi 0.82.1 parity
|
|
20
20
|
|
|
21
|
-
- **Constrained tool sampling is public end to end.** Extensions and SDK tools can request strict JSON Schema (`prefer` or `require`) or OpenAI Lark/regex grammars. Atomic preserves exact optional-property identity during public inspection, and typed RPC model listings expose all four enforcement flags through optional `ModelInfo.compat`. Unsupported models never claim required enforcement. See [Extensions](/extensions#constrained-sampling), [Models](/models#constrained-tool-sampling), and [RPC](/rpc#get_available_models).
|
|
22
|
-
- **Authentication and flagship catalogs expanded.** `/login openrouter` uses provider-owned browser PKCE with optional key minting, `/login kimi-coding` uses device authorization with automatic refresh, and isolated engine-only extension OAuth now supports safe descriptor discovery, correlated UI callbacks/cancellation, transactional engine persistence/refresh/rollback/logout, and no credential or executable-function transport. Intentional Escape/Ctrl+C/native-abort cancellation is quiet; genuine provider, network, token, storage, and refresh failures remain visible. Claude Opus 5 is available through Anthropic and Bedrock, while bearer-only `ANTHROPIC_AUTH_TOKEN` remains selectable across normal and isolated/RPC catalogs without emitting an API key or `x-api-key`. See [Providers](/providers) and [Custom Providers](/custom-provider#oauth-support).
|
|
23
|
-
- **Catalogs and model configuration stay resilient.** Remote catalogs use ETag revalidation and accept empty `304` responses, newer bundled data beats stale overlays, and a validated persisted llama.cpp catalog remains selectable when the first online refresh after restart fails while Atomic still reports the original error; a later success replaces it. Opening `/model` reloads layered legacy `.pi` then primary `.atomic` configuration. See [Models](/models#catalog-freshness-and-precedence) and [llama.cpp](/llama-cpp).
|
|
24
|
-
- **Bash integrations are session-aware and stream precisely.** Bash commands receive Atomic and exact Pi session/model environment aliases; unsaved sessions omit the file path. Direct RPC bash streams request-correlated stdout/stderr deltas, targeted/legacy cancellation, one terminal response, and exactly-once starting-session persistence across new/switch/import/fork/clone replacement; RPC shutdown drains active owners. See [Environment Variables](/environment-variables#bash-and-powershell-session-environment) and [RPC](/rpc#bash).
|
|
21
|
+
- **Constrained tool sampling is public end to end.** Extensions and SDK tools can request strict JSON Schema (`prefer` or `require`) or OpenAI Lark/regex grammars. Atomic preserves exact optional-property identity during public inspection, and typed RPC model listings expose all four enforcement flags through optional `ModelInfo.compat`. Unsupported models never claim required enforcement. See [Extensions](/extensions/authoring#constrained-sampling), [Models](/models/reference#constrained-tool-sampling), and [RPC](/rpc/protocol#get_available_models).
|
|
22
|
+
- **Authentication and flagship catalogs expanded.** `/login openrouter` uses provider-owned browser PKCE with optional key minting, `/login kimi-coding` uses device authorization with automatic refresh, and isolated engine-only extension OAuth now supports safe descriptor discovery, correlated UI callbacks/cancellation, transactional engine persistence/refresh/rollback/logout, and no credential or executable-function transport. Intentional Escape/Ctrl+C/native-abort cancellation is quiet; genuine provider, network, token, storage, and refresh failures remain visible. Claude Opus 5 is available through Anthropic and Bedrock, while bearer-only `ANTHROPIC_AUTH_TOKEN` remains selectable across normal and isolated/RPC catalogs without emitting an API key or `x-api-key`. See [Providers](/providers) and [Custom Providers](/custom-provider/oauth#oauth-support).
|
|
23
|
+
- **Catalogs and model configuration stay resilient.** Remote catalogs use ETag revalidation and accept empty `304` responses, newer bundled data beats stale overlays, and a validated persisted llama.cpp catalog remains selectable when the first online refresh after restart fails while Atomic still reports the original error; a later success replaces it. Opening `/model` reloads layered legacy `.pi` then primary `.atomic` configuration. See [Models](/models/reference#catalog-freshness-and-precedence) and [llama.cpp](/llama-cpp).
|
|
24
|
+
- **Bash integrations are session-aware and stream precisely.** Bash commands receive Atomic and exact Pi session/model environment aliases; unsaved sessions omit the file path. Direct RPC bash streams request-correlated stdout/stderr deltas, targeted/legacy cancellation, one terminal response, and exactly-once starting-session persistence across new/switch/import/fork/clone replacement; RPC shutdown drains active owners. See [Environment Variables](/environment-variables#bash-and-powershell-session-environment) and [RPC](/rpc/protocol#bash).
|
|
25
25
|
- **Coding-agent parity fixes landed.** Custom message renderers receive `outputPad` in normal and isolated rendering; summaries use fresh routing IDs without prompt-cache writes; complete literal IDs win before thinking-suffix/glob parsing; unavailable scoped entries remain removable; shared async Ctrl+G editing uses a private exact `prompt.md`, configured/environment/platform precedence, and recursive cleanup across main and extension editors; `/copy` falls back after `wl-copy` failure; explicit update checks bypass startup-skip settings; configured agent directories own TUI logs; and context discovery ignores directories named like context files.
|
|
26
26
|
|
|
27
27
|
</Update>
|
|
@@ -42,7 +42,7 @@ See [SDK](/sdk) and [Custom providers](/custom-provider).
|
|
|
42
42
|
|
|
43
43
|
- **Synced through upstream Pi 0.80.6.** Atomic and its bundled extensions now use the 0.80.6 Pi runtime packages, including signed empty Anthropic thinking preservation, request-wide GPT-5.4/5.5 long-context pricing, and corrected GPT-5.6 catalog/backend metadata.
|
|
44
44
|
- **Model controls are current.** Atomic accepts `max` wherever the active model advertises it, applies the active agent directory's single `models.json` overrides to matching extension-registered models and built-ins, and falls back instead of synthesizing removed catalog IDs on resume. See [Models](/models).
|
|
45
|
-
- **Custom pricing tiers are preserved.** Custom `models.json` entries and extension providers can declare complete request-wide `cost.tiers`; matching `modelOverrides` can update scalar rates without losing inherited tiers or replace/clear the tier array explicitly. See [Models](/models#request-wide-cost-tiers) and [Custom Providers](/custom-provider#usage-and-cost).
|
|
45
|
+
- **Custom pricing tiers are preserved.** Custom `models.json` entries and extension providers can declare complete request-wide `cost.tiers`; matching `modelOverrides` can update scalar rates without losing inherited tiers or replace/clear the tier array explicitly. See [Models](/models/reference#request-wide-cost-tiers) and [Custom Providers](/custom-provider/streaming#usage-and-cost).
|
|
46
46
|
- **Safer session and tool behavior.** Invalid explicit bash timeouts fail instead of being clamped; missing exact session IDs warn before creation; lax null or omitted message content is normalized; auth writes surface persistence failures; Windows context traversal terminates at drive roots; and duplicate fork selections are ignored. See [Tools](/tools) and [Usage](/usage).
|
|
47
47
|
- **More reliable streaming and binaries.** Visible custom messages stay before the live assistant row, standalone Linux clipboard reads can fall back to xclip with correctly packaged native bindings, caller-relative `TMPDIR` paths work from external directories, and `--skip-deps` tolerates a missing optional clipboard wrapper.
|
|
48
48
|
|