@bastani/atomic 0.10.1 → 0.10.2
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 +95 -0
- package/dist/builtin/intercom/CHANGELOG.md +12 -0
- package/dist/builtin/intercom/broker/watchdog.ts +4 -0
- package/dist/builtin/intercom/package.json +1 -1
- package/dist/builtin/mcp/package.json +1 -1
- package/dist/builtin/subagents/CHANGELOG.md +32 -0
- package/dist/builtin/subagents/README.md +2 -0
- package/dist/builtin/subagents/package.json +1 -1
- package/dist/builtin/subagents/skills/subagent/SKILL.md +3 -3
- package/dist/builtin/subagents/src/extension/index.bundle.mjs +269 -144
- package/dist/builtin/web-access/CHANGELOG.md +14 -0
- package/dist/builtin/web-access/index.bundle.mjs +9 -5
- package/dist/builtin/web-access/package.json +1 -1
- package/dist/cli/list-models.d.ts.map +1 -1
- package/dist/cli/list-models.js +1 -14
- package/dist/cli/list-models.js.map +1 -1
- package/dist/core/agent-session-export.d.ts.map +1 -1
- package/dist/core/agent-session-export.js +13 -9
- package/dist/core/agent-session-export.js.map +1 -1
- package/dist/core/agent-session-message-queue.d.ts.map +1 -1
- package/dist/core/agent-session-message-queue.js +6 -3
- package/dist/core/agent-session-message-queue.js.map +1 -1
- package/dist/core/agent-session-methods.d.ts +3 -0
- package/dist/core/agent-session-methods.d.ts.map +1 -1
- package/dist/core/agent-session-methods.js.map +1 -1
- package/dist/core/agent-session-nested-tools.d.ts.map +1 -1
- package/dist/core/agent-session-nested-tools.js +2 -1
- package/dist/core/agent-session-nested-tools.js.map +1 -1
- package/dist/core/agent-session-prompt.d.ts.map +1 -1
- package/dist/core/agent-session-prompt.js +12 -0
- package/dist/core/agent-session-prompt.js.map +1 -1
- package/dist/core/agent-session-state.d.ts +6 -0
- package/dist/core/agent-session-state.d.ts.map +1 -1
- package/dist/core/agent-session-state.js +71 -4
- package/dist/core/agent-session-state.js.map +1 -1
- package/dist/core/agent-session-tool-hooks.d.ts.map +1 -1
- package/dist/core/agent-session-tool-hooks.js +9 -1
- package/dist/core/agent-session-tool-hooks.js.map +1 -1
- package/dist/core/agent-session-types.d.ts +2 -0
- package/dist/core/agent-session-types.d.ts.map +1 -1
- package/dist/core/agent-session-types.js.map +1 -1
- package/dist/core/agent-session.d.ts +3 -0
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +7 -0
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/cache-stats.d.ts +15 -0
- package/dist/core/cache-stats.d.ts.map +1 -1
- package/dist/core/cache-stats.js +40 -2
- package/dist/core/cache-stats.js.map +1 -1
- package/dist/core/diagnostic-writer.d.ts.map +1 -1
- package/dist/core/diagnostic-writer.js +2 -1
- package/dist/core/diagnostic-writer.js.map +1 -1
- package/dist/core/export-html/template.js +14 -4
- package/dist/core/extensions/context-types.d.ts +6 -0
- package/dist/core/extensions/context-types.d.ts.map +1 -1
- package/dist/core/extensions/context-types.js.map +1 -1
- package/dist/core/extensions/loader-api.d.ts.map +1 -1
- package/dist/core/extensions/loader-api.js +5 -2
- package/dist/core/extensions/loader-api.js.map +1 -1
- package/dist/core/queued-message-delivery.d.ts +100 -7
- package/dist/core/queued-message-delivery.d.ts.map +1 -1
- package/dist/core/queued-message-delivery.js +194 -4
- package/dist/core/queued-message-delivery.js.map +1 -1
- package/dist/core/resume-cache-checkpoint.d.ts +32 -0
- package/dist/core/resume-cache-checkpoint.d.ts.map +1 -0
- package/dist/core/resume-cache-checkpoint.js +67 -0
- package/dist/core/resume-cache-checkpoint.js.map +1 -0
- package/dist/core/sdk-types.d.ts +37 -0
- package/dist/core/sdk-types.d.ts.map +1 -1
- package/dist/core/sdk-types.js.map +1 -1
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +57 -28
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-manager-core.d.ts.map +1 -1
- package/dist/core/session-manager-core.js +12 -3
- package/dist/core/session-manager-core.js.map +1 -1
- package/dist/core/session-manager-entries.d.ts +13 -0
- package/dist/core/session-manager-entries.d.ts.map +1 -1
- package/dist/core/session-manager-entries.js +38 -6
- package/dist/core/session-manager-entries.js.map +1 -1
- package/dist/core/settings-lock-directory.d.ts.map +1 -1
- package/dist/core/settings-lock-directory.js +2 -1
- package/dist/core/settings-lock-directory.js.map +1 -1
- package/dist/core/storage/node-sqlite-file-gate.d.ts +173 -0
- package/dist/core/storage/node-sqlite-file-gate.d.ts.map +1 -0
- package/dist/core/storage/node-sqlite-file-gate.js +1033 -0
- package/dist/core/storage/node-sqlite-file-gate.js.map +1 -0
- package/dist/core/storage/node-sqlite-thread.d.ts +33 -6
- package/dist/core/storage/node-sqlite-thread.d.ts.map +1 -1
- package/dist/core/storage/node-sqlite-thread.js +72 -2
- package/dist/core/storage/node-sqlite-thread.js.map +1 -1
- package/dist/core/storage/node-sqlite.d.ts.map +1 -1
- package/dist/core/storage/node-sqlite.js +216 -15
- package/dist/core/storage/node-sqlite.js.map +1 -1
- package/dist/core/storage/session/entry-structure.d.ts.map +1 -1
- package/dist/core/storage/session/entry-structure.js +39 -2
- package/dist/core/storage/session/entry-structure.js.map +1 -1
- package/dist/core/storage/session/session-resume.d.ts.map +1 -1
- package/dist/core/storage/session/session-resume.js +1 -0
- package/dist/core/storage/session/session-resume.js.map +1 -1
- package/dist/core/storage/session/session-search-index.d.ts.map +1 -1
- package/dist/core/storage/session/session-search-index.js +56 -9
- package/dist/core/storage/session/session-search-index.js.map +1 -1
- package/dist/core/storage/statement-sequence.d.ts +36 -0
- package/dist/core/storage/statement-sequence.d.ts.map +1 -0
- package/dist/core/storage/statement-sequence.js +22 -0
- package/dist/core/storage/statement-sequence.js.map +1 -0
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +13 -4
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/tasks/heartbeat-notice.d.ts.map +1 -1
- package/dist/core/tasks/heartbeat-notice.js +2 -1
- package/dist/core/tasks/heartbeat-notice.js.map +1 -1
- package/dist/core/tool-loadout.d.ts +4 -2
- package/dist/core/tool-loadout.d.ts.map +1 -1
- package/dist/core/tool-loadout.js +27 -5
- package/dist/core/tool-loadout.js.map +1 -1
- package/dist/core/tools/history-regex-worker.d.ts.map +1 -1
- package/dist/core/tools/history-regex-worker.js +2 -1
- package/dist/core/tools/history-regex-worker.js.map +1 -1
- package/dist/core/tools/powershell.d.ts +22 -22
- package/dist/core/tools/sqlite-selector-connection.d.ts.map +1 -1
- package/dist/core/tools/sqlite-selector-connection.js +7 -0
- package/dist/core/tools/sqlite-selector-connection.js.map +1 -1
- package/dist/core/transformed-system-prompt.d.ts +92 -0
- package/dist/core/transformed-system-prompt.d.ts.map +1 -0
- package/dist/core/transformed-system-prompt.js +240 -0
- package/dist/core/transformed-system-prompt.js.map +1 -0
- package/dist/extensions/codemode/execute.js +1 -1
- package/dist/extensions/codemode/execute.js.map +1 -1
- package/dist/extensions/codemode/tool.d.ts.map +1 -1
- package/dist/extensions/codemode/tool.js +16 -3
- package/dist/extensions/codemode/tool.js.map +1 -1
- package/dist/extensions/llama/ui.d.ts.map +1 -1
- package/dist/extensions/llama/ui.js +13 -8
- package/dist/extensions/llama/ui.js.map +1 -1
- package/dist/extensions/mcp/config.d.ts +2 -0
- package/dist/extensions/mcp/config.d.ts.map +1 -1
- package/dist/extensions/mcp/config.js +5 -0
- package/dist/extensions/mcp/config.js.map +1 -1
- package/dist/extensions/mcp/index.d.ts +4 -0
- package/dist/extensions/mcp/index.d.ts.map +1 -1
- package/dist/extensions/mcp/index.js +289 -64
- package/dist/extensions/mcp/index.js.map +1 -1
- package/dist/extensions/mcp/runtime.d.ts +1 -1
- package/dist/extensions/mcp/runtime.d.ts.map +1 -1
- package/dist/extensions/mcp/runtime.js +2 -2
- package/dist/extensions/mcp/runtime.js.map +1 -1
- package/dist/extensions/mcp/tool-records.d.ts +58 -0
- package/dist/extensions/mcp/tool-records.d.ts.map +1 -0
- package/dist/extensions/mcp/tool-records.js +129 -0
- package/dist/extensions/mcp/tool-records.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/modes/interactive/components/agent-panel.d.ts +2 -4
- package/dist/modes/interactive/components/agent-panel.d.ts.map +1 -1
- package/dist/modes/interactive/components/agent-panel.js +65 -80
- package/dist/modes/interactive/components/agent-panel.js.map +1 -1
- package/dist/modes/interactive/components/compaction-boundary-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/compaction-boundary-message.js +3 -3
- package/dist/modes/interactive/components/compaction-boundary-message.js.map +1 -1
- package/dist/modes/interactive/components/footer.d.ts.map +1 -1
- package/dist/modes/interactive/components/footer.js +35 -28
- package/dist/modes/interactive/components/footer.js.map +1 -1
- package/dist/modes/interactive/components/notice-line.d.ts +16 -0
- package/dist/modes/interactive/components/notice-line.d.ts.map +1 -1
- package/dist/modes/interactive/components/notice-line.js +7 -0
- package/dist/modes/interactive/components/notice-line.js.map +1 -1
- package/dist/modes/interactive/components/prompt-slot.d.ts +1 -0
- package/dist/modes/interactive/components/prompt-slot.d.ts.map +1 -1
- package/dist/modes/interactive/components/prompt-slot.js +8 -4
- package/dist/modes/interactive/components/prompt-slot.js.map +1 -1
- package/dist/modes/interactive/components/task-board.d.ts +0 -1
- package/dist/modes/interactive/components/task-board.d.ts.map +1 -1
- package/dist/modes/interactive/components/task-board.js +6 -14
- package/dist/modes/interactive/components/task-board.js.map +1 -1
- package/dist/modes/interactive/components/task-row.d.ts.map +1 -1
- package/dist/modes/interactive/components/task-row.js +7 -6
- package/dist/modes/interactive/components/task-row.js.map +1 -1
- package/dist/modes/interactive/components/token-segment.d.ts +2 -1
- package/dist/modes/interactive/components/token-segment.d.ts.map +1 -1
- package/dist/modes/interactive/components/token-segment.js +2 -4
- package/dist/modes/interactive/components/token-segment.js.map +1 -1
- package/dist/modes/interactive/components/tree-selector-content.d.ts.map +1 -1
- package/dist/modes/interactive/components/tree-selector-content.js +2 -2
- package/dist/modes/interactive/components/tree-selector-content.js.map +1 -1
- package/dist/modes/interactive/components/working-run-meter.d.ts +0 -1
- package/dist/modes/interactive/components/working-run-meter.d.ts.map +1 -1
- package/dist/modes/interactive/components/working-run-meter.js +0 -9
- package/dist/modes/interactive/components/working-run-meter.js.map +1 -1
- package/dist/modes/interactive/extension-command-hold.d.ts +25 -0
- package/dist/modes/interactive/extension-command-hold.d.ts.map +1 -0
- package/dist/modes/interactive/extension-command-hold.js +45 -0
- package/dist/modes/interactive/extension-command-hold.js.map +1 -0
- package/dist/modes/interactive/interactive-agent-events.js +2 -1
- package/dist/modes/interactive/interactive-agent-events.js.map +1 -1
- package/dist/modes/interactive/interactive-extension-context.js +18 -10
- package/dist/modes/interactive/interactive-extension-context.js.map +1 -1
- package/dist/modes/interactive/interactive-extension-custom-ui.js +3 -0
- package/dist/modes/interactive/interactive-extension-custom-ui.js.map +1 -1
- package/dist/modes/interactive/interactive-input-handling.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-input-handling.js +54 -13
- package/dist/modes/interactive/interactive-input-handling.js.map +1 -1
- package/dist/modes/interactive/interactive-model-routing.d.ts +6 -0
- package/dist/modes/interactive/interactive-model-routing.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-model-routing.js +15 -9
- package/dist/modes/interactive/interactive-model-routing.js.map +1 -1
- package/dist/modes/interactive/interactive-prompt-turn.js +4 -0
- package/dist/modes/interactive/interactive-prompt-turn.js.map +1 -1
- package/dist/modes/interactive/interactive-queueing.d.ts +7 -0
- package/dist/modes/interactive/interactive-queueing.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-queueing.js +47 -1
- package/dist/modes/interactive/interactive-queueing.js.map +1 -1
- package/dist/modes/interactive/interactive-session-routing.js +6 -0
- package/dist/modes/interactive/interactive-session-routing.js.map +1 -1
- package/dist/modes/interactive/interactive-slash-commands.js +165 -65
- package/dist/modes/interactive/interactive-slash-commands.js.map +1 -1
- package/dist/modes/interactive/screen-hold.d.ts +3 -0
- package/dist/modes/interactive/screen-hold.d.ts.map +1 -1
- package/dist/modes/interactive/screen-hold.js +9 -1
- package/dist/modes/interactive/screen-hold.js.map +1 -1
- package/dist/modes/interactive-engine/engine-health.d.ts +11 -3
- package/dist/modes/interactive-engine/engine-health.d.ts.map +1 -1
- package/dist/modes/interactive-engine/engine-health.js +5 -4
- package/dist/modes/interactive-engine/engine-health.js.map +1 -1
- package/dist/modes/interactive-engine/engine-quit-intent.d.ts +7 -0
- package/dist/modes/interactive-engine/engine-quit-intent.d.ts.map +1 -1
- package/dist/modes/interactive-engine/engine-quit-intent.js +19 -0
- package/dist/modes/interactive-engine/engine-quit-intent.js.map +1 -1
- package/dist/modes/interactive-engine/isolated-runtime.d.ts +18 -0
- package/dist/modes/interactive-engine/isolated-runtime.d.ts.map +1 -1
- package/dist/modes/interactive-engine/isolated-runtime.js +56 -4
- package/dist/modes/interactive-engine/isolated-runtime.js.map +1 -1
- package/dist/modes/interactive-engine/protocol.d.ts +7 -0
- package/dist/modes/interactive-engine/protocol.d.ts.map +1 -1
- package/dist/modes/interactive-engine/protocol.js +1 -0
- package/dist/modes/interactive-engine/protocol.js.map +1 -1
- package/dist/modes/rpc/agent-panel-bridge.d.ts.map +1 -1
- package/dist/modes/rpc/agent-panel-bridge.js +0 -13
- package/dist/modes/rpc/agent-panel-bridge.js.map +1 -1
- package/dist/modes/rpc/rpc-client-process.d.ts +14 -1
- package/dist/modes/rpc/rpc-client-process.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client-process.js +74 -10
- package/dist/modes/rpc/rpc-client-process.js.map +1 -1
- package/dist/modes/rpc/rpc-client.d.ts +27 -1
- package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client.js +81 -5
- package/dist/modes/rpc/rpc-client.js.map +1 -1
- package/dist/modes/rpc/rpc-event-buffer.d.ts +2 -0
- package/dist/modes/rpc/rpc-event-buffer.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-event-buffer.js +9 -0
- package/dist/modes/rpc/rpc-event-buffer.js.map +1 -1
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-mode.js +16 -3
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-session-binding.d.ts +7 -1
- package/dist/modes/rpc/rpc-session-binding.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-session-binding.js +10 -2
- package/dist/modes/rpc/rpc-session-binding.js.map +1 -1
- package/dist/utils/image-resize.d.ts.map +1 -1
- package/dist/utils/image-resize.js +2 -1
- package/dist/utils/image-resize.js.map +1 -1
- package/dist/utils/interactive-engine-bootstrap.d.ts +2 -0
- package/dist/utils/interactive-engine-bootstrap.d.ts.map +1 -1
- package/dist/utils/interactive-engine-bootstrap.js +1 -0
- package/dist/utils/interactive-engine-bootstrap.js.map +1 -1
- package/dist/utils/interactive-engine-env.d.ts +2 -0
- package/dist/utils/interactive-engine-env.d.ts.map +1 -1
- package/dist/utils/interactive-engine-env.js +1 -0
- package/dist/utils/interactive-engine-env.js.map +1 -1
- package/dist/utils/shell.d.ts.map +1 -1
- package/dist/utils/shell.js +2 -0
- package/dist/utils/shell.js.map +1 -1
- package/dist/utils/token-count.d.ts +8 -0
- package/dist/utils/token-count.d.ts.map +1 -0
- package/dist/utils/token-count.js +25 -0
- package/dist/utils/token-count.js.map +1 -0
- package/dist/utils/worker-threads.d.ts +18 -0
- package/dist/utils/worker-threads.d.ts.map +1 -0
- package/dist/utils/worker-threads.js +28 -0
- package/dist/utils/worker-threads.js.map +1 -0
- package/docs/background-tasks.md +13 -12
- package/docs/compaction.md +2 -2
- package/docs/development.md +1 -1
- package/docs/extensions/api-reference.md +5 -3
- package/docs/extensions/events.md +2 -0
- package/docs/mcp-servers.md +1 -1
- package/docs/settings.md +2 -0
- package/docs/storage.md +3 -1
- package/docs/subagents.md +6 -2
- package/docs/usage.md +1 -1
- package/npm-shrinkwrap.json +49 -49
- package/package.json +6 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engine-health.d.ts","sourceRoot":"","sources":["../../../src/modes/interactive-engine/engine-health.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,0BAA0B,EAA0B,MAAM,wBAAwB,CAAC;AACjG,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,wBAAwB,CAAC;AAE/E,MAAM,MAAM,wBAAwB,GAAG,CAAC,UAAU,EAAE,0BAA0B,KAAK,IAAI,CAAC;AAExF,MAAM,WAAW,gBAAgB;IAChC
|
|
1
|
+
{"version":3,"file":"engine-health.d.ts","sourceRoot":"","sources":["../../../src/modes/interactive-engine/engine-health.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,0BAA0B,EAA0B,MAAM,wBAAwB,CAAC;AACjG,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,wBAAwB,CAAC;AAE/E,MAAM,MAAM,wBAAwB,GAAG,CAAC,UAAU,EAAE,0BAA0B,KAAK,IAAI,CAAC;AAExF,MAAM,WAAW,gBAAgB;IAChC;;;OAGG;IACH,IAAI,CAAC,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACtD,8DAA8D;IAC9D,OAAO,CAAC,gBAAgB,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACrD,gFAAgF;IAChF,aAAa,IAAI,IAAI,CAAC;CACtB;AAED,eAAO,MAAM,6BAA6B,yDAAyD,CAAC;AACpG,eAAO,MAAM,0BAA0B,sDAAsD,CAAC;AAE9F;;;;GAIG;AACH,wBAAgB,gCAAgC,CAAC,KAAK,EAAE,gCAAgC,GAAG,MAAM,CAQhG;AAED,MAAM,WAAW,mBAAmB;IACnC,gFAAgF;IAChF,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;CACnB;AAED;;;;;;;;;;;;;;GAcG;AACH,qBAAa,s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CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAYxD;IAED,qBAAqB,CAAC,KAAK,EAAE,gCAAgC,GAAG,IAAI,CAanE;IAED,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC,CAkCzB;IAED,mEAAmE;IACnE,OAAO,CAAC,oBAAoB;YASd,WAAW;IASzB,OAAO,CAAC,OAAO;IAoDf,OAAO,CAAC,aAAa;IAMrB,OAAO,CAAC,MAAM;IAId,OAAO,CAAC,OAAO;CAIf"}
|
|
@@ -132,8 +132,9 @@ export class EngineHealthController {
|
|
|
132
132
|
* its spawn: the client's restart permit is voided by `deps.stop()`, and the
|
|
133
133
|
* attempt is then awaited so no child, and no host initialization, outlives
|
|
134
134
|
* teardown. Idempotent, and bounded by the client's own stop deadlines.
|
|
135
|
+
* `graceful` is passed to that stop: a quit lets the engine run its own shutdown.
|
|
135
136
|
*/
|
|
136
|
-
shutdown() {
|
|
137
|
+
shutdown(options) {
|
|
137
138
|
if (this.shutdownPromise)
|
|
138
139
|
return this.shutdownPromise;
|
|
139
140
|
this.stopped = true;
|
|
@@ -141,7 +142,7 @@ export class EngineHealthController {
|
|
|
141
142
|
this.replacementNeeded = false;
|
|
142
143
|
this.resetControls();
|
|
143
144
|
this.shutdownPromise = (async () => {
|
|
144
|
-
await this.stopQuietly();
|
|
145
|
+
await this.stopQuietly(options);
|
|
145
146
|
await this.attempt?.catch(() => { });
|
|
146
147
|
await this.termination?.catch(() => { });
|
|
147
148
|
})();
|
|
@@ -211,9 +212,9 @@ export class EngineHealthController {
|
|
|
211
212
|
void this.stopQuietly();
|
|
212
213
|
return true;
|
|
213
214
|
}
|
|
214
|
-
async stopQuietly() {
|
|
215
|
+
async stopQuietly(options) {
|
|
215
216
|
try {
|
|
216
|
-
await this.deps.stop();
|
|
217
|
+
await this.deps.stop(options);
|
|
217
218
|
}
|
|
218
219
|
catch {
|
|
219
220
|
// A stop failure must not strand the escape hatch: the restart still
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engine-health.js","sourceRoot":"","sources":["../../../src/modes/interactive-engine/engine-health.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmC,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAcjG,MAAM,CAAC,MAAM,6BAA6B,GAAG,sDAAsD,CAAC;AACpG,MAAM,CAAC,MAAM,0BAA0B,GAAG,mDAAmD,CAAC;AAE9F;;;;GAIG;AACH,MAAM,UAAU,gCAAgC,CAAC,KAAuC;IACvF,MAAM,SAAS,GAAG,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IAC1E,MAAM,WAAW,GAAG,SAAS,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IACnD,MAAM,aAAa,GAAG,CAAC,WAAW,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IAChG,MAAM,OAAO,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;IACpE,OAAO,OAAO;QACb,CAAC,CAAC,GAAG,6BAA6B,WAAW,KAAK,CAAC,IAAI,MAAM,OAAO,GAAG;QACvE,CAAC,CAAC,GAAG,6BAA6B,WAAW,KAAK,CAAC,IAAI,GAAG,CAAC;AAC7D,CAAC;AAOD;;;;;;;;;;;;;;GAcG;AACH,MAAM,OAAO,sBAAsB;IACjB,IAAI,CAAmB;IACvB,GAAG,CAAe;IAClB,SAAS,GAAG,IAAI,GAAG,EAA4B,CAAC;IACzD,OAAO,GAAiC,EAAE,CAAC;IAC3C,YAAY,GAAG,KAAK,CAAC;IACrB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,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC,CAAC;IACrG,CAAC;IAEO,OAAO,CAAC,UAAsC;QACrD,IAAI,IAAI,CAAC,SAAS,CAAC,IAAI,KAAK,CAAC;YAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAC7D,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,SAAS;YAAE,QAAQ,CAAC,UAAU,CAAC,CAAC;IAC7D,CAAC;CACD","sourcesContent":["import { type ActivityWatchdogDiagnostic, ENGINE_UNRESPONSIVE_MS } from \"./activity-watchdog.ts\";\nimport type { InteractiveEngineGenerationEnded } from \"./engine-generation.ts\";\n\nexport type EngineDiagnosticListener = (diagnostic: ActivityWatchdogDiagnostic) => void;\n\nexport interface EngineHealthDeps {\n\t/** Terminate the current (or hung replacement) engine child. */\n\tstop(): Promise<void>;\n\t/** Replace the engine child and reload host state from it. */\n\trestart(replacementReady: () => void): Promise<void>;\n\t/** Drop streaming/compaction/callback activity owned by the dead generation. */\n\tclearActivity(): void;\n}\n\nexport const UNEXPECTED_ENGINE_LOSS_NOTICE = \"Interactive engine stopped unexpectedly; restarting.\";\nexport const UNRESPONSIVE_ENGINE_NOTICE = \"Interactive engine is not responding; restarting.\";\n\n/**\n * Keep the actionable transport cause in the recovery notice. Child stderr can\n * contain provider output or secrets, so only the bounded summary before the\n * RpcClient's `. Stderr:` suffix is safe to render.\n */\nexport function formatUnexpectedEngineLossNotice(event: InteractiveEngineGenerationEnded): string {\n\tconst firstLine = event.error.message.split(/\\r?\\n/u, 1)[0]?.trim() ?? \"\";\n\tconst stderrIndex = firstLine.indexOf(\". Stderr:\");\n\tconst withoutStderr = (stderrIndex === -1 ? firstLine : firstLine.slice(0, stderrIndex)).trim();\n\tconst summary = withoutStderr.slice(0, 240).replace(/[.!?]+$/u, \"\");\n\treturn summary\n\t\t? `${UNEXPECTED_ENGINE_LOSS_NOTICE} Cause (${event.kind}): ${summary}.`\n\t\t: `${UNEXPECTED_ENGINE_LOSS_NOTICE} Cause: ${event.kind}.`;\n}\n\nexport interface EngineHealthOptions {\n\t/** Injectable clock so tests can cross the unresponsive threshold instantly. */\n\tnow?: () => number;\n}\n\n/**\n * Engine health surface: diagnostic fan-out plus single-flight recovery.\n *\n * Recovery has exactly two entry points, deliberately separate:\n *\n * - {@link handleGenerationEnded} runs ONE automatic replacement attempt after\n * an unexpected loss of a generation. Expected losses (explicit stop,\n * deliberate generation replacement, host shutdown) never restart.\n * - {@link terminate} is the explicit user escape hatch (Ctrl+C). It force-stops\n * first, so it can rescue a replacement child that is hung waiting for\n * readiness instead of joining that pending promise.\n *\n * Neither path is reachable from an interrupt: pressing Escape only requests the\n * engine's own cooperative abort and waits for it.\n */\nexport class EngineHealthController {\n\tprivate readonly deps: EngineHealthDeps;\n\tprivate readonly now: () => number;\n\tprivate readonly listeners = new Set<EngineDiagnosticListener>();\n\tprivate pending: ActivityWatchdogDiagnostic[] = [];\n\tprivate unresponsive = false;\n\tprivate abortStartedAt: number | undefined;\n\tprivate readonly pendingControls = new Map<symbol, number>();\n\tprivate controlFailed = false;\n\tprivate attempt: Promise<void> | undefined;\n\t/** When the current replacement attempt began; undefined once it settles. */\n\tprivate attemptStartedAt: number | undefined;\n\tprivate attemptId = 0;\n\tprivate forceStoppedAttemptId: number | undefined;\n\tprivate rescueRequested = false;\n\t/**\n\t * Latched when a replacement failed on its own. Automatic recovery stays\n\t * single-shot, but the user's Ctrl+C must remain able to try again: without\n\t * this the host would be left with no engine, no pending attempt, no overdue\n\t * abort, and no watchdog flag, so nothing could arm the escape hatch.\n\t */\n\tprivate replacementNeeded = false;\n\tprivate termination: Promise<void> | undefined;\n\t/** Set once disposal begins; joins the in-flight attempt and termination. */\n\tprivate shutdownPromise: Promise<void> | undefined;\n\tprivate stopped = false;\n\n\tconstructor(deps: EngineHealthDeps, options?: EngineHealthOptions) {\n\t\tthis.deps = deps;\n\t\tthis.now = options?.now ?? (() => performance.now());\n\t}\n\n\tonDiagnostic(listener: EngineDiagnosticListener): () => void {\n\t\tfor (const diagnostic of this.pending.splice(0)) listener(diagnostic);\n\t\tthis.listeners.add(listener);\n\t\treturn () => this.listeners.delete(listener);\n\t}\n\n\t/** Publish a diagnostic produced elsewhere (watchdog, transport, bridge). */\n\tpublish(diagnostic: ActivityWatchdogDiagnostic): void {\n\t\tif (diagnostic.level === \"unresponsive\" && diagnostic.source === \"watchdog\") this.unresponsive = true;\n\t\tthis.deliver(diagnostic);\n\t}\n\n\t/** A heartbeat proves the child's loop turns again, so clear a reported stall. */\n\tclearUnresponsive(): void {\n\t\tthis.unresponsive = false;\n\t}\n\n\tmarkCooperativeAbortStarted(): void {\n\t\tthis.abortStartedAt ??= this.now();\n\t}\n\n\tmarkCooperativeAbortSettled(): void {\n\t\tthis.abortStartedAt = undefined;\n\t}\n\n\tasync trackControlRequest<T>(request: () => Promise<T>): Promise<T> {\n\t\tconst key = Symbol();\n\t\tthis.pendingControls.set(key, this.now());\n\t\ttry {\n\t\t\treturn await request();\n\t\t} catch (error) {\n\t\t\tif (this.pendingControls.has(key)) this.controlFailed = true;\n\t\t\tthrow error;\n\t\t} finally {\n\t\t\tthis.pendingControls.delete(key);\n\t\t}\n\t}\n\n\t/**\n\t * True when a control failed or the engine is not answering:\n\t *\n\t * - the heartbeat watchdog declared it unresponsive;\n\t * - a replacement failed on its own and the host has no engine;\n\t * - a queue clear or cooperative abort failed or exceeded the unresponsive\n\t * threshold, even if the child's loop still turns;\n\t * - a replacement has been waiting for `engine_ready` past that threshold.\n\t *\n\t * The readiness case has no watchdog coverage at all: a child stopped before\n\t * readiness emits no heartbeat and no diagnostic, and `start()` waits without\n\t * a deadline by design. Crossing a threshold arms nothing on its own — it\n\t * only decides whether a deliberate Ctrl+C escalates — and all of this stays\n\t * false for a healthy engine so a stray second Ctrl+C cannot replace one.\n\t */\n\tneedsExplicitTermination(): boolean {\n\t\tif (this.unresponsive || this.replacementNeeded || this.controlFailed) return true;\n\t\treturn (\n\t\t\tthis.isOverdue(this.abortStartedAt) ||\n\t\t\tthis.isOverdue(this.attemptStartedAt) ||\n\t\t\t[...this.pendingControls.values()].some((startedAt) => this.isOverdue(startedAt))\n\t\t);\n\t}\n\n\tprivate isOverdue(startedAt: number | undefined): boolean {\n\t\treturn startedAt !== undefined && this.now() - startedAt >= ENGINE_UNRESPONSIVE_MS;\n\t}\n\n\tisRecovering(): boolean {\n\t\treturn this.attempt !== undefined || this.termination !== undefined;\n\t}\n\n\t/**\n\t * Stop accepting recovery work and join whatever is still running.\n\t *\n\t * Disposal must not return while a replacement is between its own stop and\n\t * its spawn: the client's restart permit is voided by `deps.stop()`, and the\n\t * attempt is then awaited so no child, and no host initialization, outlives\n\t * teardown. Idempotent, and bounded by the client's own stop deadlines.\n\t */\n\tshutdown(): Promise<void> {\n\t\tif (this.shutdownPromise) return this.shutdownPromise;\n\t\tthis.stopped = true;\n\t\tthis.rescueRequested = false;\n\t\tthis.replacementNeeded = false;\n\t\tthis.resetControls();\n\t\tthis.shutdownPromise = (async () => {\n\t\t\tawait this.stopQuietly();\n\t\t\tawait this.attempt?.catch(() => {});\n\t\t\tawait this.termination?.catch(() => {});\n\t\t})();\n\t\treturn this.shutdownPromise;\n\t}\n\n\thandleGenerationEnded(event: InteractiveEngineGenerationEnded): void {\n\t\tthis.resetControls();\n\t\tthis.deps.clearActivity();\n\t\tif (event.expected || this.stopped) return;\n\t\tif (this.attempt) {\n\t\t\t// A newer child died while the replacement attempt was still running, so\n\t\t\t// that attempt cannot leave a viable generation behind. Latch instead of\n\t\t\t// restarting again: automatic recovery stays single-shot, and Ctrl+C is\n\t\t\t// armed once the in-flight attempt settles.\n\t\t\tthis.replacementNeeded = true;\n\t\t\treturn;\n\t\t}\n\t\tvoid this.recover(formatUnexpectedEngineLossNotice(event)).catch(() => {});\n\t}\n\n\tterminate(): Promise<void> {\n\t\t// A repeat Ctrl+C must be able to rescue a replacement that is itself\n\t\t// overdue, instead of joining the in-flight termination forever. The stop\n\t\t// is fenced by attempt id so repeated presses cannot stack restarts onto a\n\t\t// healthy replacement.\n\t\tif (this.termination) {\n\t\t\tthis.rescueOverdueAttempt();\n\t\t\treturn this.termination;\n\t\t}\n\t\tconst inFlight = this.attempt;\n\t\t// The attempt this press supersedes fails by our own hand, so its failure is\n\t\t// expected rather than something to report to the user.\n\t\tif (inFlight) this.forceStoppedAttemptId = this.attemptId;\n\t\tconst run = (async () => {\n\t\t\tthis.resetControls();\n\t\t\tthis.deps.clearActivity();\n\t\t\tthis.notice(UNRESPONSIVE_ENGINE_NOTICE);\n\t\t\tawait this.stopQuietly();\n\t\t\t// An automatic attempt swallows its own errors, so this only waits for it\n\t\t\t// to release the single-flight slot.\n\t\t\tif (inFlight) await inFlight;\n\t\t\tawait this.recover(undefined);\n\t\t\t// Each user-forced stop of an overdue replacement earns exactly one more\n\t\t\t// replacement attempt, so the escape hatch stays usable indefinitely.\n\t\t\twhile (this.rescueRequested && !this.stopped) {\n\t\t\t\tthis.rescueRequested = false;\n\t\t\t\tthis.notice(UNRESPONSIVE_ENGINE_NOTICE);\n\t\t\t\tawait this.recover(undefined);\n\t\t\t}\n\t\t})().finally(() => {\n\t\t\tif (this.termination === run) this.termination = undefined;\n\t\t});\n\t\tthis.termination = run;\n\t\treturn run;\n\t}\n\n\t/** Force-stop an overdue replacement, at most once per attempt. */\n\tprivate rescueOverdueAttempt(): boolean {\n\t\tif (!this.isOverdue(this.attemptStartedAt)) return false;\n\t\tif (this.forceStoppedAttemptId === this.attemptId) return false;\n\t\tthis.forceStoppedAttemptId = this.attemptId;\n\t\tthis.rescueRequested = true;\n\t\tvoid this.stopQuietly();\n\t\treturn true;\n\t}\n\n\tprivate async stopQuietly(): Promise<void> {\n\t\ttry {\n\t\t\tawait this.deps.stop();\n\t\t} catch {\n\t\t\t// A stop failure must not strand the escape hatch: the restart still\n\t\t\t// replaces the child and reports any real failure.\n\t\t}\n\t}\n\n\tprivate recover(notice: string | undefined): Promise<void> {\n\t\t// Order matters: after shutdown no caller may join, or revive, an attempt\n\t\t// that still happens to occupy the slot.\n\t\tif (this.stopped) return Promise.resolve();\n\t\tif (this.attempt) return this.attempt;\n\t\tif (notice) this.notice(notice);\n\t\tthis.attemptId += 1;\n\t\tconst id = this.attemptId;\n\t\tthis.attemptStartedAt = this.now();\n\t\tthis.rescueRequested = false;\n\t\t// A new attempt is under way, so the previous failure is no longer the\n\t\t// reason to arm Ctrl+C. It re-arms below only if this attempt fails too.\n\t\tthis.replacementNeeded = false;\n\t\t// The watchdog verdict belonged to the generation being replaced. A fresh\n\t\t// child emits no heartbeat until it is ready, so leaving the latch set\n\t\t// would keep `needsExplicitTermination()` true through the whole pre-ready\n\t\t// window and let the first Ctrl+C stop a replacement that never misbehaved.\n\t\t// Only this child's own heartbeat, or its own stall, may set it again.\n\t\tthis.unresponsive = false;\n\t\tlet controlsFenced = false;\n\t\tconst fenceRetiredControls = () => {\n\t\t\tif (controlsFenced || this.stopped || this.attemptId !== id) return;\n\t\t\tcontrolsFenced = true;\n\t\t\tthis.resetControls();\n\t\t};\n\t\tconst run = this.deps\n\t\t\t.restart(fenceRetiredControls)\n\t\t\t.then(fenceRetiredControls)\n\t\t\t.catch((error: Error) => {\n\t\t\t\t// An attempt the user deliberately stopped, or one cancelled by\n\t\t\t\t// disposal, did not fail on its own.\n\t\t\t\tif (this.forceStoppedAttemptId === id || this.stopped) return;\n\t\t\t\t// Keep Ctrl+C armed: automatic recovery is single-shot, but the user\n\t\t\t\t// must be able to ask for another attempt after a real failure.\n\t\t\t\tthis.replacementNeeded = true;\n\t\t\t\t// A concrete failure, so no operational source: this one surfaces.\n\t\t\t\tthis.deliver({\n\t\t\t\t\tactivity: undefined,\n\t\t\t\t\telapsedMs: 0,\n\t\t\t\t\tlevel: \"unresponsive\",\n\t\t\t\t\tmessage: `Interactive engine restart failed: ${error.message}`,\n\t\t\t\t});\n\t\t\t})\n\t\t\t.finally(() => {\n\t\t\t\tif (this.attempt !== run) return;\n\t\t\t\tthis.attempt = undefined;\n\t\t\t\tthis.attemptStartedAt = undefined;\n\t\t\t});\n\t\tthis.attempt = run;\n\t\treturn run;\n\t}\n\n\tprivate resetControls(): void {\n\t\tthis.pendingControls.clear();\n\t\tthis.controlFailed = false;\n\t\tthis.abortStartedAt = undefined;\n\t}\n\n\tprivate notice(message: string): void {\n\t\tthis.deliver({ activity: undefined, elapsedMs: 0, level: \"blocking\", message, source: \"recovery\" });\n\t}\n\n\tprivate deliver(diagnostic: ActivityWatchdogDiagnostic): void {\n\t\tif (this.listeners.size === 0) this.pending.push(diagnostic);\n\t\tfor (const listener of this.listeners) listener(diagnostic);\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"engine-health.js","sourceRoot":"","sources":["../../../src/modes/interactive-engine/engine-health.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmC,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAiBjG,MAAM,CAAC,MAAM,6BAA6B,GAAG,sDAAsD,CAAC;AACpG,MAAM,CAAC,MAAM,0BAA0B,GAAG,mDAAmD,CAAC;AAE9F;;;;GAIG;AACH,MAAM,UAAU,gCAAgC,CAAC,KAAuC;IACvF,MAAM,SAAS,GAAG,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IAC1E,MAAM,WAAW,GAAG,SAAS,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IACnD,MAAM,aAAa,GAAG,CAAC,WAAW,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IAChG,MAAM,OAAO,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;IACpE,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,gBAAgB,GAAG,SAAS,CAAC;QACnC,CAAC,CAAC,CAAC;QACJ,IAAI,CAAC,OAAO,GAAG,GAAG,CAAC;QACnB,OAAO,GAAG,CAAC;IACZ,CAAC;IAEO,aAAa;QACpB,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,CAAC;QAC7B,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC;QAC3B,IAAI,CAAC,cAAc,GAAG,SAAS,CAAC;IACjC,CAAC;IAEO,MAAM,CAAC,OAAe;QAC7B,IAAI,CAAC,OAAO,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC,CAAC;IACrG,CAAC;IAEO,OAAO,CAAC,UAAsC;QACrD,IAAI,IAAI,CAAC,SAAS,CAAC,IAAI,KAAK,CAAC;YAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAC7D,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,SAAS;YAAE,QAAQ,CAAC,UAAU,CAAC,CAAC;IAC7D,CAAC;CACD","sourcesContent":["import { type ActivityWatchdogDiagnostic, ENGINE_UNRESPONSIVE_MS } from \"./activity-watchdog.ts\";\nimport type { InteractiveEngineGenerationEnded } from \"./engine-generation.ts\";\n\nexport type EngineDiagnosticListener = (diagnostic: ActivityWatchdogDiagnostic) => void;\n\nexport interface EngineHealthDeps {\n\t/**\n\t * Terminate the current (or hung replacement) engine child. `graceful` lets a ready\n\t * engine run its own shutdown first, within the client's bound.\n\t */\n\tstop(options?: { graceful?: boolean }): Promise<void>;\n\t/** Replace the engine child and reload host state from it. */\n\trestart(replacementReady: () => void): Promise<void>;\n\t/** Drop streaming/compaction/callback activity owned by the dead generation. */\n\tclearActivity(): void;\n}\n\nexport const UNEXPECTED_ENGINE_LOSS_NOTICE = \"Interactive engine stopped unexpectedly; restarting.\";\nexport const UNRESPONSIVE_ENGINE_NOTICE = \"Interactive engine is not responding; restarting.\";\n\n/**\n * Keep the actionable transport cause in the recovery notice. Child stderr can\n * contain provider output or secrets, so only the bounded summary before the\n * RpcClient's `. Stderr:` suffix is safe to render.\n */\nexport function formatUnexpectedEngineLossNotice(event: InteractiveEngineGenerationEnded): string {\n\tconst firstLine = event.error.message.split(/\\r?\\n/u, 1)[0]?.trim() ?? \"\";\n\tconst stderrIndex = firstLine.indexOf(\". Stderr:\");\n\tconst withoutStderr = (stderrIndex === -1 ? firstLine : firstLine.slice(0, stderrIndex)).trim();\n\tconst summary = withoutStderr.slice(0, 240).replace(/[.!?]+$/u, \"\");\n\treturn summary\n\t\t? `${UNEXPECTED_ENGINE_LOSS_NOTICE} Cause (${event.kind}): ${summary}.`\n\t\t: `${UNEXPECTED_ENGINE_LOSS_NOTICE} Cause: ${event.kind}.`;\n}\n\nexport interface EngineHealthOptions {\n\t/** Injectable clock so tests can cross the unresponsive threshold instantly. */\n\tnow?: () => number;\n}\n\n/**\n * Engine health surface: diagnostic fan-out plus single-flight recovery.\n *\n * Recovery has exactly two entry points, deliberately separate:\n *\n * - {@link handleGenerationEnded} runs ONE automatic replacement attempt after\n * an unexpected loss of a generation. Expected losses (explicit stop,\n * deliberate generation replacement, host shutdown) never restart.\n * - {@link terminate} is the explicit user escape hatch (Ctrl+C). It force-stops\n * first, so it can rescue a replacement child that is hung waiting for\n * readiness instead of joining that pending promise.\n *\n * Neither path is reachable from an interrupt: pressing Escape only requests the\n * engine's own cooperative abort and waits for it.\n */\nexport class EngineHealthController {\n\tprivate readonly deps: EngineHealthDeps;\n\tprivate readonly now: () => number;\n\tprivate readonly listeners = new Set<EngineDiagnosticListener>();\n\tprivate pending: ActivityWatchdogDiagnostic[] = [];\n\tprivate unresponsive = false;\n\tprivate abortStartedAt: number | undefined;\n\tprivate readonly pendingControls = new Map<symbol, number>();\n\tprivate controlFailed = false;\n\tprivate attempt: Promise<void> | undefined;\n\t/** When the current replacement attempt began; undefined once it settles. */\n\tprivate attemptStartedAt: number | undefined;\n\tprivate attemptId = 0;\n\tprivate forceStoppedAttemptId: number | undefined;\n\tprivate rescueRequested = false;\n\t/**\n\t * Latched when a replacement failed on its own. Automatic recovery stays\n\t * single-shot, but the user's Ctrl+C must remain able to try again: without\n\t * this the host would be left with no engine, no pending attempt, no overdue\n\t * abort, and no watchdog flag, so nothing could arm the escape hatch.\n\t */\n\tprivate replacementNeeded = false;\n\tprivate termination: Promise<void> | undefined;\n\t/** Set once disposal begins; joins the in-flight attempt and termination. */\n\tprivate shutdownPromise: Promise<void> | undefined;\n\tprivate stopped = false;\n\n\tconstructor(deps: EngineHealthDeps, options?: EngineHealthOptions) {\n\t\tthis.deps = deps;\n\t\tthis.now = options?.now ?? (() => performance.now());\n\t}\n\n\tonDiagnostic(listener: EngineDiagnosticListener): () => void {\n\t\tfor (const diagnostic of this.pending.splice(0)) listener(diagnostic);\n\t\tthis.listeners.add(listener);\n\t\treturn () => this.listeners.delete(listener);\n\t}\n\n\t/** Publish a diagnostic produced elsewhere (watchdog, transport, bridge). */\n\tpublish(diagnostic: ActivityWatchdogDiagnostic): void {\n\t\tif (diagnostic.level === \"unresponsive\" && diagnostic.source === \"watchdog\") this.unresponsive = true;\n\t\tthis.deliver(diagnostic);\n\t}\n\n\t/** A heartbeat proves the child's loop turns again, so clear a reported stall. */\n\tclearUnresponsive(): void {\n\t\tthis.unresponsive = false;\n\t}\n\n\tmarkCooperativeAbortStarted(): void {\n\t\tthis.abortStartedAt ??= this.now();\n\t}\n\n\tmarkCooperativeAbortSettled(): void {\n\t\tthis.abortStartedAt = undefined;\n\t}\n\n\tasync trackControlRequest<T>(request: () => Promise<T>): Promise<T> {\n\t\tconst key = Symbol();\n\t\tthis.pendingControls.set(key, this.now());\n\t\ttry {\n\t\t\treturn await request();\n\t\t} catch (error) {\n\t\t\tif (this.pendingControls.has(key)) this.controlFailed = true;\n\t\t\tthrow error;\n\t\t} finally {\n\t\t\tthis.pendingControls.delete(key);\n\t\t}\n\t}\n\n\t/**\n\t * True when a control failed or the engine is not answering:\n\t *\n\t * - the heartbeat watchdog declared it unresponsive;\n\t * - a replacement failed on its own and the host has no engine;\n\t * - a queue clear or cooperative abort failed or exceeded the unresponsive\n\t * threshold, even if the child's loop still turns;\n\t * - a replacement has been waiting for `engine_ready` past that threshold.\n\t *\n\t * The readiness case has no watchdog coverage at all: a child stopped before\n\t * readiness emits no heartbeat and no diagnostic, and `start()` waits without\n\t * a deadline by design. Crossing a threshold arms nothing on its own — it\n\t * only decides whether a deliberate Ctrl+C escalates — and all of this stays\n\t * false for a healthy engine so a stray second Ctrl+C cannot replace one.\n\t */\n\tneedsExplicitTermination(): boolean {\n\t\tif (this.unresponsive || this.replacementNeeded || this.controlFailed) return true;\n\t\treturn (\n\t\t\tthis.isOverdue(this.abortStartedAt) ||\n\t\t\tthis.isOverdue(this.attemptStartedAt) ||\n\t\t\t[...this.pendingControls.values()].some((startedAt) => this.isOverdue(startedAt))\n\t\t);\n\t}\n\n\tprivate isOverdue(startedAt: number | undefined): boolean {\n\t\treturn startedAt !== undefined && this.now() - startedAt >= ENGINE_UNRESPONSIVE_MS;\n\t}\n\n\tisRecovering(): boolean {\n\t\treturn this.attempt !== undefined || this.termination !== undefined;\n\t}\n\n\t/**\n\t * Stop accepting recovery work and join whatever is still running.\n\t *\n\t * Disposal must not return while a replacement is between its own stop and\n\t * its spawn: the client's restart permit is voided by `deps.stop()`, and the\n\t * attempt is then awaited so no child, and no host initialization, outlives\n\t * teardown. Idempotent, and bounded by the client's own stop deadlines.\n\t * `graceful` is passed to that stop: a quit lets the engine run its own shutdown.\n\t */\n\tshutdown(options?: { graceful?: boolean }): Promise<void> {\n\t\tif (this.shutdownPromise) return this.shutdownPromise;\n\t\tthis.stopped = true;\n\t\tthis.rescueRequested = false;\n\t\tthis.replacementNeeded = false;\n\t\tthis.resetControls();\n\t\tthis.shutdownPromise = (async () => {\n\t\t\tawait this.stopQuietly(options);\n\t\t\tawait this.attempt?.catch(() => {});\n\t\t\tawait this.termination?.catch(() => {});\n\t\t})();\n\t\treturn this.shutdownPromise;\n\t}\n\n\thandleGenerationEnded(event: InteractiveEngineGenerationEnded): void {\n\t\tthis.resetControls();\n\t\tthis.deps.clearActivity();\n\t\tif (event.expected || this.stopped) return;\n\t\tif (this.attempt) {\n\t\t\t// A newer child died while the replacement attempt was still running, so\n\t\t\t// that attempt cannot leave a viable generation behind. Latch instead of\n\t\t\t// restarting again: automatic recovery stays single-shot, and Ctrl+C is\n\t\t\t// armed once the in-flight attempt settles.\n\t\t\tthis.replacementNeeded = true;\n\t\t\treturn;\n\t\t}\n\t\tvoid this.recover(formatUnexpectedEngineLossNotice(event)).catch(() => {});\n\t}\n\n\tterminate(): Promise<void> {\n\t\t// A repeat Ctrl+C must be able to rescue a replacement that is itself\n\t\t// overdue, instead of joining the in-flight termination forever. The stop\n\t\t// is fenced by attempt id so repeated presses cannot stack restarts onto a\n\t\t// healthy replacement.\n\t\tif (this.termination) {\n\t\t\tthis.rescueOverdueAttempt();\n\t\t\treturn this.termination;\n\t\t}\n\t\tconst inFlight = this.attempt;\n\t\t// The attempt this press supersedes fails by our own hand, so its failure is\n\t\t// expected rather than something to report to the user.\n\t\tif (inFlight) this.forceStoppedAttemptId = this.attemptId;\n\t\tconst run = (async () => {\n\t\t\tthis.resetControls();\n\t\t\tthis.deps.clearActivity();\n\t\t\tthis.notice(UNRESPONSIVE_ENGINE_NOTICE);\n\t\t\tawait this.stopQuietly();\n\t\t\t// An automatic attempt swallows its own errors, so this only waits for it\n\t\t\t// to release the single-flight slot.\n\t\t\tif (inFlight) await inFlight;\n\t\t\tawait this.recover(undefined);\n\t\t\t// Each user-forced stop of an overdue replacement earns exactly one more\n\t\t\t// replacement attempt, so the escape hatch stays usable indefinitely.\n\t\t\twhile (this.rescueRequested && !this.stopped) {\n\t\t\t\tthis.rescueRequested = false;\n\t\t\t\tthis.notice(UNRESPONSIVE_ENGINE_NOTICE);\n\t\t\t\tawait this.recover(undefined);\n\t\t\t}\n\t\t})().finally(() => {\n\t\t\tif (this.termination === run) this.termination = undefined;\n\t\t});\n\t\tthis.termination = run;\n\t\treturn run;\n\t}\n\n\t/** Force-stop an overdue replacement, at most once per attempt. */\n\tprivate rescueOverdueAttempt(): boolean {\n\t\tif (!this.isOverdue(this.attemptStartedAt)) return false;\n\t\tif (this.forceStoppedAttemptId === this.attemptId) return false;\n\t\tthis.forceStoppedAttemptId = this.attemptId;\n\t\tthis.rescueRequested = true;\n\t\tvoid this.stopQuietly();\n\t\treturn true;\n\t}\n\n\tprivate async stopQuietly(options?: { graceful?: boolean }): Promise<void> {\n\t\ttry {\n\t\t\tawait this.deps.stop(options);\n\t\t} catch {\n\t\t\t// A stop failure must not strand the escape hatch: the restart still\n\t\t\t// replaces the child and reports any real failure.\n\t\t}\n\t}\n\n\tprivate recover(notice: string | undefined): Promise<void> {\n\t\t// Order matters: after shutdown no caller may join, or revive, an attempt\n\t\t// that still happens to occupy the slot.\n\t\tif (this.stopped) return Promise.resolve();\n\t\tif (this.attempt) return this.attempt;\n\t\tif (notice) this.notice(notice);\n\t\tthis.attemptId += 1;\n\t\tconst id = this.attemptId;\n\t\tthis.attemptStartedAt = this.now();\n\t\tthis.rescueRequested = false;\n\t\t// A new attempt is under way, so the previous failure is no longer the\n\t\t// reason to arm Ctrl+C. It re-arms below only if this attempt fails too.\n\t\tthis.replacementNeeded = false;\n\t\t// The watchdog verdict belonged to the generation being replaced. A fresh\n\t\t// child emits no heartbeat until it is ready, so leaving the latch set\n\t\t// would keep `needsExplicitTermination()` true through the whole pre-ready\n\t\t// window and let the first Ctrl+C stop a replacement that never misbehaved.\n\t\t// Only this child's own heartbeat, or its own stall, may set it again.\n\t\tthis.unresponsive = false;\n\t\tlet controlsFenced = false;\n\t\tconst fenceRetiredControls = () => {\n\t\t\tif (controlsFenced || this.stopped || this.attemptId !== id) return;\n\t\t\tcontrolsFenced = true;\n\t\t\tthis.resetControls();\n\t\t};\n\t\tconst run = this.deps\n\t\t\t.restart(fenceRetiredControls)\n\t\t\t.then(fenceRetiredControls)\n\t\t\t.catch((error: Error) => {\n\t\t\t\t// An attempt the user deliberately stopped, or one cancelled by\n\t\t\t\t// disposal, did not fail on its own.\n\t\t\t\tif (this.forceStoppedAttemptId === id || this.stopped) return;\n\t\t\t\t// Keep Ctrl+C armed: automatic recovery is single-shot, but the user\n\t\t\t\t// must be able to ask for another attempt after a real failure.\n\t\t\t\tthis.replacementNeeded = true;\n\t\t\t\t// A concrete failure, so no operational source: this one surfaces.\n\t\t\t\tthis.deliver({\n\t\t\t\t\tactivity: undefined,\n\t\t\t\t\telapsedMs: 0,\n\t\t\t\t\tlevel: \"unresponsive\",\n\t\t\t\t\tmessage: `Interactive engine restart failed: ${error.message}`,\n\t\t\t\t});\n\t\t\t})\n\t\t\t.finally(() => {\n\t\t\t\tif (this.attempt !== run) return;\n\t\t\t\tthis.attempt = undefined;\n\t\t\t\tthis.attemptStartedAt = undefined;\n\t\t\t});\n\t\tthis.attempt = run;\n\t\treturn run;\n\t}\n\n\tprivate resetControls(): void {\n\t\tthis.pendingControls.clear();\n\t\tthis.controlFailed = false;\n\t\tthis.abortStartedAt = undefined;\n\t}\n\n\tprivate notice(message: string): void {\n\t\tthis.deliver({ activity: undefined, elapsedMs: 0, level: \"blocking\", message, source: \"recovery\" });\n\t}\n\n\tprivate deliver(diagnostic: ActivityWatchdogDiagnostic): void {\n\t\tif (this.listeners.size === 0) this.pending.push(diagnostic);\n\t\tfor (const listener of this.listeners) listener(diagnostic);\n\t}\n}\n"]}
|
|
@@ -13,4 +13,11 @@ export declare class EngineQuitIntent {
|
|
|
13
13
|
get explicitQuitRequested(): boolean;
|
|
14
14
|
handleLine(line: string): boolean;
|
|
15
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Tell the host, once every exit handler registered so far has run, that this engine child has shut down. Call it
|
|
18
|
+
* immediately before `process.exit`. The diagnostics' last records are among those handlers, so they are written
|
|
19
|
+
* by then. What remains is the runtime's own exit work, such as writing its compile cache, which the host need not
|
|
20
|
+
* wait for.
|
|
21
|
+
*/
|
|
22
|
+
export declare function reportShutdownCompleteAtExit(): void;
|
|
16
23
|
//# sourceMappingURL=engine-quit-intent.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engine-quit-intent.d.ts","sourceRoot":"","sources":["../../../src/modes/interactive-engine/engine-quit-intent.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"engine-quit-intent.d.ts","sourceRoot":"","sources":["../../../src/modes/interactive-engine/engine-quit-intent.ts"],"names":[],"mappings":"AAKA;;;;;;;GAOG;AACH,qBAAa,gBAAgB;IAC5B,OAAO,CAAC,QAAQ,CAAS;IAEzB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAyB;IAE9C,YAAY,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,EAEvC;IAED,IAAI,qBAAqB,IAAI,OAAO,CAEnC;IAED,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAQhC;CACD;AAWD;;;;;GAKG;AACH,wBAAgB,4BAA4B,IAAI,IAAI,CAEnD"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { writeSync } from "node:fs";
|
|
1
2
|
import { markEventLoopShutdown } from "../../core/event-loop-monitor.js";
|
|
2
3
|
import { flushLifecycleTraceAtQuit } from "../../core/lifecycle-timings.js";
|
|
3
4
|
import { parseEngineExplicitQuitCommand, serializeInteractiveEngineMessage } from "./protocol.js";
|
|
@@ -29,4 +30,22 @@ export class EngineQuitIntent {
|
|
|
29
30
|
return true;
|
|
30
31
|
}
|
|
31
32
|
}
|
|
33
|
+
/** The engine child's last exit handler: a synchronous write, since nothing asynchronous runs after exit begins. */
|
|
34
|
+
function writeShutdownComplete() {
|
|
35
|
+
try {
|
|
36
|
+
writeSync(1, serializeInteractiveEngineMessage({ type: "engine_shutdown_complete" }));
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
// The host stopped reading; it ends this process on its own deadline.
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Tell the host, once every exit handler registered so far has run, that this engine child has shut down. Call it
|
|
44
|
+
* immediately before `process.exit`. The diagnostics' last records are among those handlers, so they are written
|
|
45
|
+
* by then. What remains is the runtime's own exit work, such as writing its compile cache, which the host need not
|
|
46
|
+
* wait for.
|
|
47
|
+
*/
|
|
48
|
+
export function reportShutdownCompleteAtExit() {
|
|
49
|
+
process.once("exit", writeShutdownComplete);
|
|
50
|
+
}
|
|
32
51
|
//# sourceMappingURL=engine-quit-intent.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engine-quit-intent.js","sourceRoot":"","sources":["../../../src/modes/interactive-engine/engine-quit-intent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AACzE,OAAO,EAAE,yBAAyB,EAAE,MAAM,iCAAiC,CAAC;AAC5E,OAAO,EAAE,8BAA8B,EAAE,iCAAiC,EAAE,MAAM,eAAe,CAAC;AAElG;;;;;;;GAOG;AACH,MAAM,OAAO,gBAAgB;IACpB,QAAQ,GAAG,KAAK,CAAC;IAER,IAAI,CAAyB;IAE9C,YAAY,IAA4B;QACvC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IAClB,CAAC;IAED,IAAI,qBAAqB;QACxB,OAAO,IAAI,CAAC,QAAQ,CAAC;IACtB,CAAC;IAED,UAAU,CAAC,IAAY;QACtB,IAAI,CAAC,8BAA8B,CAAC,IAAI,CAAC;YAAE,OAAO,KAAK,CAAC;QACxD,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACrB,oGAAoG;QACpG,qBAAqB,EAAE,CAAC;QACxB,yBAAyB,EAAE,CAAC;QAC5B,IAAI,CAAC,IAAI,CAAC,iCAAiC,CAAC,EAAE,IAAI,EAAE,0BAA0B,EAAE,CAAC,CAAC,CAAC;QACnF,OAAO,IAAI,CAAC;IACb,CAAC;CACD","sourcesContent":["import { markEventLoopShutdown } from \"../../core/event-loop-monitor.ts\";\nimport { flushLifecycleTraceAtQuit } from \"../../core/lifecycle-timings.ts\";\nimport { parseEngineExplicitQuitCommand, serializeInteractiveEngineMessage } from \"./protocol.ts\";\n\n/**\n * Child-side record of whether the host is quitting on purpose.\n *\n * The host stops the engine by closing stdin and then sending SIGTERM, and a host\n * that was itself signalled stops it the same way, so the child cannot infer the cause\n * from how it was stopped. The host announces an explicit quit first and waits for the\n * acknowledgement, which makes the flag visible before any stop signal can arrive.\n */\nexport class EngineQuitIntent {\n\tprivate explicit = false;\n\n\tprivate readonly send: (line: string) => void;\n\n\tconstructor(send: (line: string) => void) {\n\t\tthis.send = send;\n\t}\n\n\tget explicitQuitRequested(): boolean {\n\t\treturn this.explicit;\n\t}\n\n\thandleLine(line: string): boolean {\n\t\tif (!parseEngineExplicitQuitCommand(line)) return false;\n\t\tthis.explicit = true;\n\t\t// The host may end this process as soon as it has the acknowledgement: write the diagnostics first.\n\t\tmarkEventLoopShutdown();\n\t\tflushLifecycleTraceAtQuit();\n\t\tthis.send(serializeInteractiveEngineMessage({ type: \"engine_explicit_quit_ack\" }));\n\t\treturn true;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"engine-quit-intent.js","sourceRoot":"","sources":["../../../src/modes/interactive-engine/engine-quit-intent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AACzE,OAAO,EAAE,yBAAyB,EAAE,MAAM,iCAAiC,CAAC;AAC5E,OAAO,EAAE,8BAA8B,EAAE,iCAAiC,EAAE,MAAM,eAAe,CAAC;AAElG;;;;;;;GAOG;AACH,MAAM,OAAO,gBAAgB;IACpB,QAAQ,GAAG,KAAK,CAAC;IAER,IAAI,CAAyB;IAE9C,YAAY,IAA4B;QACvC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IAClB,CAAC;IAED,IAAI,qBAAqB;QACxB,OAAO,IAAI,CAAC,QAAQ,CAAC;IACtB,CAAC;IAED,UAAU,CAAC,IAAY;QACtB,IAAI,CAAC,8BAA8B,CAAC,IAAI,CAAC;YAAE,OAAO,KAAK,CAAC;QACxD,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACrB,oGAAoG;QACpG,qBAAqB,EAAE,CAAC;QACxB,yBAAyB,EAAE,CAAC;QAC5B,IAAI,CAAC,IAAI,CAAC,iCAAiC,CAAC,EAAE,IAAI,EAAE,0BAA0B,EAAE,CAAC,CAAC,CAAC;QACnF,OAAO,IAAI,CAAC;IACb,CAAC;CACD;AAED,oHAAoH;AACpH,SAAS,qBAAqB;IAC7B,IAAI,CAAC;QACJ,SAAS,CAAC,CAAC,EAAE,iCAAiC,CAAC,EAAE,IAAI,EAAE,0BAA0B,EAAE,CAAC,CAAC,CAAC;IACvF,CAAC;IAAC,MAAM,CAAC;QACR,sEAAsE;IACvE,CAAC;AACF,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,4BAA4B;IAC3C,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAAC;AAC7C,CAAC","sourcesContent":["import { writeSync } from \"node:fs\";\nimport { markEventLoopShutdown } from \"../../core/event-loop-monitor.ts\";\nimport { flushLifecycleTraceAtQuit } from \"../../core/lifecycle-timings.ts\";\nimport { parseEngineExplicitQuitCommand, serializeInteractiveEngineMessage } from \"./protocol.ts\";\n\n/**\n * Child-side record of whether the host is quitting on purpose.\n *\n * The host stops the engine by closing stdin and then sending SIGTERM, and a host\n * that was itself signalled stops it the same way, so the child cannot infer the cause\n * from how it was stopped. The host announces an explicit quit first and waits for the\n * acknowledgement, which makes the flag visible before any stop signal can arrive.\n */\nexport class EngineQuitIntent {\n\tprivate explicit = false;\n\n\tprivate readonly send: (line: string) => void;\n\n\tconstructor(send: (line: string) => void) {\n\t\tthis.send = send;\n\t}\n\n\tget explicitQuitRequested(): boolean {\n\t\treturn this.explicit;\n\t}\n\n\thandleLine(line: string): boolean {\n\t\tif (!parseEngineExplicitQuitCommand(line)) return false;\n\t\tthis.explicit = true;\n\t\t// The host may end this process as soon as it has the acknowledgement: write the diagnostics first.\n\t\tmarkEventLoopShutdown();\n\t\tflushLifecycleTraceAtQuit();\n\t\tthis.send(serializeInteractiveEngineMessage({ type: \"engine_explicit_quit_ack\" }));\n\t\treturn true;\n\t}\n}\n\n/** The engine child's last exit handler: a synchronous write, since nothing asynchronous runs after exit begins. */\nfunction writeShutdownComplete(): void {\n\ttry {\n\t\twriteSync(1, serializeInteractiveEngineMessage({ type: \"engine_shutdown_complete\" }));\n\t} catch {\n\t\t// The host stopped reading; it ends this process on its own deadline.\n\t}\n}\n\n/**\n * Tell the host, once every exit handler registered so far has run, that this engine child has shut down. Call it\n * immediately before `process.exit`. The diagnostics' last records are among those handlers, so they are written\n * by then. What remains is the runtime's own exit work, such as writing its compile cache, which the host need not\n * wait for.\n */\nexport function reportShutdownCompleteAtExit(): void {\n\tprocess.once(\"exit\", writeShutdownComplete);\n}\n"]}
|
|
@@ -3,6 +3,7 @@ import type { AgentSession, ClearedQueue } from "../../core/agent-session.js";
|
|
|
3
3
|
import { AgentSessionRuntime, type CreateAgentSessionRuntimeFactory } from "../../core/agent-session-runtime.ts";
|
|
4
4
|
import type { ResourceOverlap } from "../../core/diagnostics.ts";
|
|
5
5
|
import { type SessionTrustDecisions } from "../../core/project-trust-state.ts";
|
|
6
|
+
import { type QueuedMessageLanes } from "../../core/queued-message-delivery.ts";
|
|
6
7
|
import type { StopAllBackgroundOutcome } from "../../core/tasks/stop-all.ts";
|
|
7
8
|
import type { ToolStatusReport } from "../../core/tool-status.js";
|
|
8
9
|
import type { AgentPanelCounts } from "../rpc/agent-panel-bridge.ts";
|
|
@@ -77,6 +78,15 @@ export declare class IsolatedInteractiveRuntime extends AgentSessionRuntime {
|
|
|
77
78
|
private readonly activeBashRequestIds;
|
|
78
79
|
private steeringMessages;
|
|
79
80
|
private followUpMessages;
|
|
81
|
+
/**
|
|
82
|
+
* The queued messages the engine's session took and has not shown yet, as the changes on its event lines tell them
|
|
83
|
+
* (an engine that sends none leaves it empty). Read with the cached queue, which no longer lists them: the main chat
|
|
84
|
+
* draws them as queued until their own row arrives.
|
|
85
|
+
*/
|
|
86
|
+
private readonly queuedDeliveries;
|
|
87
|
+
/** Ends waiting for their event to reach the host's listeners, which a compaction can hold back. */
|
|
88
|
+
private readonly queuedDeliveryEnds;
|
|
89
|
+
private readonly queuedDeliveryResetListeners;
|
|
80
90
|
private readonly recoveryListeners;
|
|
81
91
|
/** Bumped by every authoritative queue_update. */
|
|
82
92
|
private queueUpdateGeneration;
|
|
@@ -201,6 +211,14 @@ export declare class IsolatedInteractiveRuntime extends AgentSessionRuntime {
|
|
|
201
211
|
*/
|
|
202
212
|
onEngineRecovered(listener: (replaced: boolean) => void): () => void;
|
|
203
213
|
private publishRecovery;
|
|
214
|
+
/**
|
|
215
|
+
* The queued messages the engine's session took and has not shown yet, per lane, oldest first. The cached queue
|
|
216
|
+
* lists none of them. The same object until a change arrives; empty for an engine that sends none.
|
|
217
|
+
*/
|
|
218
|
+
queuedMessagesUnderWay(): QueuedMessageLanes;
|
|
219
|
+
/** Called when the messages being delivered are forgotten at once: the engine was lost or retired its session. */
|
|
220
|
+
onQueuedDeliveriesForgotten(listener: () => void): () => void;
|
|
221
|
+
private forgetQueuedDeliveries;
|
|
204
222
|
/**
|
|
205
223
|
* Forget the queue the lost engine listed: its messages went down with it, and its replacement lists its own. The
|
|
206
224
|
* main chat's steering controller has already taken them for the user (see `loseTarget`).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isolated-runtime.d.ts","sourceRoot":"","sources":["../../../src/modes/interactive-engine/isolated-runtime.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAE1D,OAAO,K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AAC;QAAE,SAAS,EAAE,OAAO,CAAC;QAAC,YAAY,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAoBxD;IAED;;;;;;OAMG;IACH,UAAyB,kCAAkC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAG;IAEtE,OAAO,CAAC,OAAO,CAAC,EAAE;QAAE,UAAU,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CA8BlE;IAED,OAAO,CAAC,YAAY;IA8TpB;;;;;OAKG;YACW,eAAe;IAc7B,OAAO,CAAC,gBAAgB;IAcxB,OAAO,CAAC,aAAa;IAerB;;;;OAIG;IACH,OAAO,CAAC,gBAAgB;IA6CxB,OAAO,CAAC,mBAAmB;IAS3B,OAAO,CAAC,qBAAqB;IAU7B,iGAAiG;IACjG,OAAO,CAAC,oBAAoB;IAO5B,OAAO,CAAC,kBAAkB;IAY1B;;;;;;OAMG;IACH,gBAAgB,IAAI,OAAO,CAAC,YAAY,CAAC,CAGxC;IAED,gHAAgH;IAChH,OAAO,CAAC,eAAe;IA8BvB,OAAO,CAAC,gBAAgB;YAcV,2BAA2B;IAWzC,OAAO,CAAC,mBAAmB;IAiB3B,OAAO,CAAC,oBAAoB;YAed,yBAAyB;YAkCzB,kBAAkB;YAwBlB,kBAAkB;IAkChC;;;;OAIG;YACW,0BAA0B;YAoJzB,aAAa;YAYd,gBAAgB;IAO9B,OAAO,CAAC,YAAY;CAqFpB"}
|
|
@@ -4,6 +4,7 @@ import { AgentSessionRuntime } from "../../core/agent-session-runtime.js";
|
|
|
4
4
|
import { reportDebugAsync } from "../../core/debug.js";
|
|
5
5
|
import { onDebugSettingChange } from "../../core/debug-setting.js";
|
|
6
6
|
import { mergeSessionTrustDecisions } from "../../core/project-trust-state.js";
|
|
7
|
+
import { QueuedDeliveryView, } from "../../core/queued-message-delivery.js";
|
|
7
8
|
import { SessionManager } from "../../core/session-manager.js";
|
|
8
9
|
import { serializeSessionMutation } from "../../core/session-mutation-queue.js";
|
|
9
10
|
import { retryStatusUpdate } from "../../core/session-retry-status.js";
|
|
@@ -115,6 +116,15 @@ export class IsolatedInteractiveRuntime extends AgentSessionRuntime {
|
|
|
115
116
|
activeBashRequestIds = new Map();
|
|
116
117
|
steeringMessages = [];
|
|
117
118
|
followUpMessages = [];
|
|
119
|
+
/**
|
|
120
|
+
* The queued messages the engine's session took and has not shown yet, as the changes on its event lines tell them
|
|
121
|
+
* (an engine that sends none leaves it empty). Read with the cached queue, which no longer lists them: the main chat
|
|
122
|
+
* draws them as queued until their own row arrives.
|
|
123
|
+
*/
|
|
124
|
+
queuedDeliveries = new QueuedDeliveryView();
|
|
125
|
+
/** Ends waiting for their event to reach the host's listeners, which a compaction can hold back. */
|
|
126
|
+
queuedDeliveryEnds = new WeakMap();
|
|
127
|
+
queuedDeliveryResetListeners = new Set();
|
|
118
128
|
recoveryListeners = new Set();
|
|
119
129
|
/** Bumped by every authoritative queue_update. */
|
|
120
130
|
queueUpdateGeneration = 0;
|
|
@@ -176,7 +186,7 @@ export class IsolatedInteractiveRuntime extends AgentSessionRuntime {
|
|
|
176
186
|
this.queuePause = new RemoteQueuePause(client);
|
|
177
187
|
this.sessionStats = new EngineSessionStats(client);
|
|
178
188
|
this.health = new EngineHealthController({
|
|
179
|
-
stop: () => this.client.stop(),
|
|
189
|
+
stop: (options) => this.client.stop(options),
|
|
180
190
|
restart: async (replacementReady) => {
|
|
181
191
|
this.engineRecoveryFailure = undefined;
|
|
182
192
|
try {
|
|
@@ -213,6 +223,17 @@ export class IsolatedInteractiveRuntime extends AgentSessionRuntime {
|
|
|
213
223
|
},
|
|
214
224
|
});
|
|
215
225
|
this.client.onEvent((event) => this.observeEvent(event));
|
|
226
|
+
// Read with the queue it changes: a queue_update that no longer lists a message names it as being delivered.
|
|
227
|
+
this.client.onQueuedDeliveryChange?.((change, event) => {
|
|
228
|
+
const end = this.queuedDeliveries.receive(change);
|
|
229
|
+
// The messages it ended leave when the event reaches the chat, with the row it draws.
|
|
230
|
+
if (end === undefined)
|
|
231
|
+
return;
|
|
232
|
+
if (this.hostEventsSubscribed)
|
|
233
|
+
this.queuedDeliveryEnds.set(event, end);
|
|
234
|
+
else
|
|
235
|
+
this.queuedDeliveries.end(end);
|
|
236
|
+
});
|
|
216
237
|
this.stopSharingDebugSetting = onDebugSettingChange((enabled) => this.dispatchBestEffort("set debug", this.client.setDebug(enabled)));
|
|
217
238
|
this.initialStartSettled = initialStart === undefined;
|
|
218
239
|
this.initialStart = initialStart?.then(() => {
|
|
@@ -234,6 +255,8 @@ export class IsolatedInteractiveRuntime extends AgentSessionRuntime {
|
|
|
234
255
|
if (event.generation === this.client.getGeneration()) {
|
|
235
256
|
this.panelCounts = { total: 0, agents: 0, needsInput: 0, shells: 0, subagents: 0 };
|
|
236
257
|
this.updateResources({});
|
|
258
|
+
// What the lost engine was delivering is gone with it; its replacement starts telling afresh.
|
|
259
|
+
this.forgetQueuedDeliveries();
|
|
237
260
|
}
|
|
238
261
|
// A first child that never became ready failed startup; initialStart reports it instead of a restart.
|
|
239
262
|
if (!this.initialStartSettled) {
|
|
@@ -269,6 +292,8 @@ export class IsolatedInteractiveRuntime extends AgentSessionRuntime {
|
|
|
269
292
|
}
|
|
270
293
|
if (message.type === "engine_extension_ui_reset") {
|
|
271
294
|
this.panelCounts = { total: 0, agents: 0, needsInput: 0, shells: 0, subagents: 0 };
|
|
295
|
+
// The engine retires its session, with what it was delivering; it tells this one nothing more about them.
|
|
296
|
+
this.forgetQueuedDeliveries();
|
|
272
297
|
this.hostExtensionUIReset?.();
|
|
273
298
|
return;
|
|
274
299
|
}
|
|
@@ -721,6 +746,24 @@ export class IsolatedInteractiveRuntime extends AgentSessionRuntime {
|
|
|
721
746
|
}
|
|
722
747
|
}
|
|
723
748
|
}
|
|
749
|
+
/**
|
|
750
|
+
* The queued messages the engine's session took and has not shown yet, per lane, oldest first. The cached queue
|
|
751
|
+
* lists none of them. The same object until a change arrives; empty for an engine that sends none.
|
|
752
|
+
*/
|
|
753
|
+
queuedMessagesUnderWay() {
|
|
754
|
+
return this.queuedDeliveries.texts;
|
|
755
|
+
}
|
|
756
|
+
/** Called when the messages being delivered are forgotten at once: the engine was lost or retired its session. */
|
|
757
|
+
onQueuedDeliveriesForgotten(listener) {
|
|
758
|
+
this.queuedDeliveryResetListeners.add(listener);
|
|
759
|
+
return () => this.queuedDeliveryResetListeners.delete(listener);
|
|
760
|
+
}
|
|
761
|
+
forgetQueuedDeliveries() {
|
|
762
|
+
if (!this.queuedDeliveries.reset())
|
|
763
|
+
return;
|
|
764
|
+
for (const listener of [...this.queuedDeliveryResetListeners])
|
|
765
|
+
listener();
|
|
766
|
+
}
|
|
724
767
|
/**
|
|
725
768
|
* Forget the queue the lost engine listed: its messages went down with it, and its replacement lists its own. The
|
|
726
769
|
* main chat's steering controller has already taken them for the user (see `loseTarget`).
|
|
@@ -934,14 +977,18 @@ export class IsolatedInteractiveRuntime extends AgentSessionRuntime {
|
|
|
934
977
|
this.stopSharingDebugSetting();
|
|
935
978
|
this.disposePromise = (async () => {
|
|
936
979
|
// A quit the user asked for must reach the engine before it is stopped: the stop
|
|
937
|
-
// is a SIGTERM,
|
|
980
|
+
// is a SIGTERM or, on Windows, the end of its input, which the engine cannot tell
|
|
981
|
+
// from this process being signalled or ending.
|
|
938
982
|
// Optional like the other transport surfaces focused test doubles omit.
|
|
939
983
|
const unrecordedQuit = !options?.fromSignal && (await this.client.announceExplicitQuit?.()) === false;
|
|
984
|
+
// A quit lets the engine run its extensions' shutdown on every platform. After a
|
|
985
|
+
// signal, Windows still ends the engine at once.
|
|
986
|
+
const stop = { graceful: !options?.fromSignal };
|
|
940
987
|
// EngineHealthController owns the first client stop and joins recovery.
|
|
941
|
-
await this.health.shutdown();
|
|
988
|
+
await this.health.shutdown(stop);
|
|
942
989
|
// A replacement may have spawned while shutdown joined recovery; the
|
|
943
990
|
// idempotent trailing stop closes that child before disposal returns.
|
|
944
|
-
await this.client.stop();
|
|
991
|
+
await this.client.stop(stop);
|
|
945
992
|
if (unrecordedQuit) {
|
|
946
993
|
// No engine child recorded the quit, so none released Herdr's registration, and a replacement started
|
|
947
994
|
// during recovery may have registered again. Every child is stopped now; this host loads no Herdr reporter.
|
|
@@ -1349,6 +1396,11 @@ export class IsolatedInteractiveRuntime extends AgentSessionRuntime {
|
|
|
1349
1396
|
});
|
|
1350
1397
|
}
|
|
1351
1398
|
notifyHostListeners(event, audience) {
|
|
1399
|
+
const end = this.queuedDeliveryEnds.get(event);
|
|
1400
|
+
if (end !== undefined) {
|
|
1401
|
+
this.queuedDeliveryEnds.delete(event);
|
|
1402
|
+
this.queuedDeliveries.end(end);
|
|
1403
|
+
}
|
|
1352
1404
|
for (const [id, listener] of [...this.hostListeners])
|
|
1353
1405
|
if (id <= audience)
|
|
1354
1406
|
listener(event);
|