@namzu/sdk 38.2.1 → 40.0.0
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 +851 -0
- package/dist/advisory/executor.d.ts +10 -1
- package/dist/advisory/executor.d.ts.map +1 -1
- package/dist/advisory/executor.js +5 -26
- package/dist/advisory/executor.js.map +1 -1
- package/dist/advisory/history.d.ts +9 -0
- package/dist/advisory/history.d.ts.map +1 -0
- package/dist/advisory/history.js +120 -0
- package/dist/advisory/history.js.map +1 -0
- package/dist/advisory/index.d.ts +1 -1
- package/dist/advisory/index.d.ts.map +1 -1
- package/dist/advisory/index.js.map +1 -1
- package/dist/agents/ReactiveAgent.d.ts.map +1 -1
- package/dist/agents/ReactiveAgent.js +3 -0
- package/dist/agents/ReactiveAgent.js.map +1 -1
- package/dist/agents/runAgent.d.ts +10 -0
- package/dist/agents/runAgent.d.ts.map +1 -1
- package/dist/agents/runAgent.js +3 -0
- package/dist/agents/runAgent.js.map +1 -1
- package/dist/compaction/manual.d.ts +6 -0
- package/dist/compaction/manual.d.ts.map +1 -1
- package/dist/compaction/manual.js +21 -2
- package/dist/compaction/manual.js.map +1 -1
- package/dist/compaction/summary.d.ts.map +1 -1
- package/dist/compaction/summary.js +4 -1
- package/dist/compaction/summary.js.map +1 -1
- package/dist/config/runtime.js +2 -2
- package/dist/config/runtime.js.map +1 -1
- package/dist/connector/mcp/adapter.d.ts.map +1 -1
- package/dist/connector/mcp/adapter.js +20 -6
- package/dist/connector/mcp/adapter.js.map +1 -1
- package/dist/contracts/schemas.js +1 -1
- package/dist/contracts/schemas.js.map +1 -1
- package/dist/eval/harness-protection.d.ts +18 -0
- package/dist/eval/harness-protection.d.ts.map +1 -0
- package/dist/eval/harness-protection.js +58 -0
- package/dist/eval/harness-protection.js.map +1 -0
- package/dist/eval/harness-verification.d.ts +6 -1
- package/dist/eval/harness-verification.d.ts.map +1 -1
- package/dist/eval/harness-verification.js +19 -2
- package/dist/eval/harness-verification.js.map +1 -1
- package/dist/eval/index.d.ts +1 -0
- package/dist/eval/index.d.ts.map +1 -1
- package/dist/eval/index.js.map +1 -1
- package/dist/manager/resident/activity.d.ts +50 -0
- package/dist/manager/resident/activity.d.ts.map +1 -0
- package/dist/manager/resident/activity.js +125 -0
- package/dist/manager/resident/activity.js.map +1 -0
- package/dist/manager/resident/agenda.d.ts +13 -1
- package/dist/manager/resident/agenda.d.ts.map +1 -1
- package/dist/manager/resident/agenda.js +40 -5
- package/dist/manager/resident/agenda.js.map +1 -1
- package/dist/manager/resident/consumption.d.ts +104 -0
- package/dist/manager/resident/consumption.d.ts.map +1 -0
- package/dist/manager/resident/consumption.js +233 -0
- package/dist/manager/resident/consumption.js.map +1 -0
- package/dist/manager/resident/evidence-recall.d.ts +24 -0
- package/dist/manager/resident/evidence-recall.d.ts.map +1 -0
- package/dist/manager/resident/evidence-recall.js +295 -0
- package/dist/manager/resident/evidence-recall.js.map +1 -0
- package/dist/manager/resident/history-disk.d.ts +10 -0
- package/dist/manager/resident/history-disk.d.ts.map +1 -0
- package/dist/manager/resident/history-disk.js +50 -0
- package/dist/manager/resident/history-disk.js.map +1 -0
- package/dist/manager/resident/history.d.ts +79 -0
- package/dist/manager/resident/history.d.ts.map +1 -0
- package/dist/manager/resident/history.js +203 -0
- package/dist/manager/resident/history.js.map +1 -0
- package/dist/manager/resident/initiative.d.ts.map +1 -1
- package/dist/manager/resident/initiative.js +11 -3
- package/dist/manager/resident/initiative.js.map +1 -1
- package/dist/manager/resident/learning-cycle.d.ts +131 -0
- package/dist/manager/resident/learning-cycle.d.ts.map +1 -0
- package/dist/manager/resident/learning-cycle.js +306 -0
- package/dist/manager/resident/learning-cycle.js.map +1 -0
- package/dist/manager/resident/learning-observation.d.ts +80 -0
- package/dist/manager/resident/learning-observation.d.ts.map +1 -0
- package/dist/manager/resident/learning-observation.js +22 -0
- package/dist/manager/resident/learning-observation.js.map +1 -0
- package/dist/manager/resident/learning-store.d.ts +106 -0
- package/dist/manager/resident/learning-store.d.ts.map +1 -0
- package/dist/manager/resident/learning-store.js +598 -0
- package/dist/manager/resident/learning-store.js.map +1 -0
- package/dist/manager/resident/learning.d.ts +246 -3
- package/dist/manager/resident/learning.d.ts.map +1 -1
- package/dist/manager/resident/learning.js +96 -6
- package/dist/manager/resident/learning.js.map +1 -1
- package/dist/manager/resident/outbox.d.ts +4 -4
- package/dist/manager/resident/store.d.ts +37 -4
- package/dist/manager/resident/store.d.ts.map +1 -1
- package/dist/manager/resident/store.js +27 -3
- package/dist/manager/resident/store.js.map +1 -1
- package/dist/manager/resident/tool-evidence.d.ts +71 -0
- package/dist/manager/resident/tool-evidence.d.ts.map +1 -0
- package/dist/manager/resident/tool-evidence.js +285 -0
- package/dist/manager/resident/tool-evidence.js.map +1 -0
- package/dist/manager/run/persistence.d.ts +8 -0
- package/dist/manager/run/persistence.d.ts.map +1 -1
- package/dist/manager/run/persistence.js +18 -0
- package/dist/manager/run/persistence.js.map +1 -1
- package/dist/plugin/loader.d.ts.map +1 -1
- package/dist/plugin/loader.js +5 -3
- package/dist/plugin/loader.js.map +1 -1
- package/dist/prompt/coding-agent-doctrine.d.ts +1 -1
- package/dist/prompt/coding-agent-doctrine.d.ts.map +1 -1
- package/dist/prompt/coding-agent-doctrine.js +2 -0
- package/dist/prompt/coding-agent-doctrine.js.map +1 -1
- package/dist/prompt/index.d.ts +2 -0
- package/dist/prompt/index.d.ts.map +1 -1
- package/dist/prompt/index.js +1 -0
- package/dist/prompt/index.js.map +1 -1
- package/dist/prompt/resident-learning.d.ts +19 -0
- package/dist/prompt/resident-learning.d.ts.map +1 -0
- package/dist/prompt/resident-learning.js +125 -0
- package/dist/prompt/resident-learning.js.map +1 -0
- package/dist/prompt/resident-step.d.ts +8 -1
- package/dist/prompt/resident-step.d.ts.map +1 -1
- package/dist/prompt/resident-step.js +65 -4
- package/dist/prompt/resident-step.js.map +1 -1
- package/dist/provider/collect-chat-completion.d.ts +2 -1
- package/dist/provider/collect-chat-completion.d.ts.map +1 -1
- package/dist/provider/collect-chat-completion.js +7 -6
- package/dist/provider/collect-chat-completion.js.map +1 -1
- package/dist/provider/fallback.d.ts.map +1 -1
- package/dist/provider/fallback.js +2 -1
- package/dist/provider/fallback.js.map +1 -1
- package/dist/provider/stream-text.d.ts +16 -0
- package/dist/provider/stream-text.d.ts.map +1 -0
- package/dist/provider/stream-text.js +51 -0
- package/dist/provider/stream-text.js.map +1 -0
- package/dist/public-runtime.d.ts +16 -4
- package/dist/public-runtime.d.ts.map +1 -1
- package/dist/public-runtime.js +17 -4
- package/dist/public-runtime.js.map +1 -1
- package/dist/public-tools.d.ts +13 -0
- package/dist/public-tools.d.ts.map +1 -1
- package/dist/public-tools.js +16 -0
- package/dist/public-tools.js.map +1 -1
- package/dist/public-types.d.ts +15 -3
- package/dist/public-types.d.ts.map +1 -1
- package/dist/registry/tool/execute.d.ts.map +1 -1
- package/dist/registry/tool/execute.js +2 -3
- package/dist/registry/tool/execute.js.map +1 -1
- package/dist/registry/tool/portable.d.ts +65 -0
- package/dist/registry/tool/portable.d.ts.map +1 -0
- package/dist/registry/tool/portable.js +244 -0
- package/dist/registry/tool/portable.js.map +1 -0
- package/dist/registry/tool/schema.d.ts +32 -5
- package/dist/registry/tool/schema.d.ts.map +1 -1
- package/dist/registry/tool/schema.js +35 -9
- package/dist/registry/tool/schema.js.map +1 -1
- package/dist/registry/toolset/catalog.js +8 -8
- package/dist/registry/toolset/catalog.js.map +1 -1
- package/dist/run/LimitChecker.js +3 -3
- package/dist/run/LimitChecker.js.map +1 -1
- package/dist/run/evidence-query.d.ts +41 -0
- package/dist/run/evidence-query.d.ts.map +1 -0
- package/dist/run/evidence-query.js +270 -0
- package/dist/run/evidence-query.js.map +1 -0
- package/dist/run/evidence-recall.d.ts +99 -0
- package/dist/run/evidence-recall.d.ts.map +1 -0
- package/dist/run/evidence-recall.js +633 -0
- package/dist/run/evidence-recall.js.map +1 -0
- package/dist/run/index.d.ts +2 -0
- package/dist/run/index.d.ts.map +1 -1
- package/dist/run/index.js +1 -0
- package/dist/run/index.js.map +1 -1
- package/dist/run/json-claim-verifier.d.ts +83 -0
- package/dist/run/json-claim-verifier.d.ts.map +1 -0
- package/dist/run/json-claim-verifier.js +200 -0
- package/dist/run/json-claim-verifier.js.map +1 -0
- package/dist/run/preparation-context-error.d.ts +10 -0
- package/dist/run/preparation-context-error.d.ts.map +1 -0
- package/dist/run/preparation-context-error.js +15 -0
- package/dist/run/preparation-context-error.js.map +1 -0
- package/dist/run-query/index.d.ts +3 -1
- package/dist/run-query/index.d.ts.map +1 -1
- package/dist/runtime/jobs/awaited-jobs.d.ts +215 -0
- package/dist/runtime/jobs/awaited-jobs.d.ts.map +1 -0
- package/dist/runtime/jobs/awaited-jobs.js +259 -0
- package/dist/runtime/jobs/awaited-jobs.js.map +1 -0
- package/dist/runtime/jobs/registry.d.ts +33 -2
- package/dist/runtime/jobs/registry.d.ts.map +1 -1
- package/dist/runtime/jobs/registry.js +37 -0
- package/dist/runtime/jobs/registry.js.map +1 -1
- package/dist/runtime/query/callback-inference.d.ts +8 -0
- package/dist/runtime/query/callback-inference.d.ts.map +1 -0
- package/dist/runtime/query/callback-inference.js +89 -0
- package/dist/runtime/query/callback-inference.js.map +1 -0
- package/dist/runtime/query/checkpoint.d.ts +4 -0
- package/dist/runtime/query/checkpoint.d.ts.map +1 -1
- package/dist/runtime/query/checkpoint.js +13 -0
- package/dist/runtime/query/checkpoint.js.map +1 -1
- package/dist/runtime/query/events.d.ts +1 -0
- package/dist/runtime/query/events.d.ts.map +1 -1
- package/dist/runtime/query/events.js +18 -0
- package/dist/runtime/query/events.js.map +1 -1
- package/dist/runtime/query/executor.d.ts +35 -1
- package/dist/runtime/query/executor.d.ts.map +1 -1
- package/dist/runtime/query/executor.js +77 -8
- package/dist/runtime/query/executor.js.map +1 -1
- package/dist/runtime/query/file-evidence-context.d.ts +5 -0
- package/dist/runtime/query/file-evidence-context.d.ts.map +1 -0
- package/dist/runtime/query/file-evidence-context.js +180 -0
- package/dist/runtime/query/file-evidence-context.js.map +1 -0
- package/dist/runtime/query/file-evidence-replay.d.ts +260 -0
- package/dist/runtime/query/file-evidence-replay.d.ts.map +1 -0
- package/dist/runtime/query/file-evidence-replay.js +647 -0
- package/dist/runtime/query/file-evidence-replay.js.map +1 -0
- package/dist/runtime/query/file-evidence-seed.d.ts +50 -0
- package/dist/runtime/query/file-evidence-seed.d.ts.map +1 -0
- package/dist/runtime/query/file-evidence-seed.js +100 -0
- package/dist/runtime/query/file-evidence-seed.js.map +1 -0
- package/dist/runtime/query/guard.d.ts.map +1 -1
- package/dist/runtime/query/guard.js +4 -0
- package/dist/runtime/query/guard.js.map +1 -1
- package/dist/runtime/query/index.d.ts +10 -1
- package/dist/runtime/query/index.d.ts.map +1 -1
- package/dist/runtime/query/index.js +133 -26
- package/dist/runtime/query/index.js.map +1 -1
- package/dist/runtime/query/iteration/index.d.ts +92 -36
- package/dist/runtime/query/iteration/index.d.ts.map +1 -1
- package/dist/runtime/query/iteration/index.js +420 -117
- package/dist/runtime/query/iteration/index.js.map +1 -1
- package/dist/runtime/query/iteration/phases/advisory.d.ts +2 -1
- package/dist/runtime/query/iteration/phases/advisory.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/advisory.js +2 -1
- package/dist/runtime/query/iteration/phases/advisory.js.map +1 -1
- package/dist/runtime/query/iteration/phases/context.d.ts +12 -1
- package/dist/runtime/query/iteration/phases/context.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/context.js.map +1 -1
- package/dist/runtime/query/iteration/phases/tool-review.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/tool-review.js +8 -1
- package/dist/runtime/query/iteration/phases/tool-review.js.map +1 -1
- package/dist/runtime/query/iteration/provider-rejected-image.d.ts +2 -1
- package/dist/runtime/query/iteration/provider-rejected-image.d.ts.map +1 -1
- package/dist/runtime/query/iteration/provider-rejected-image.js +5 -2
- package/dist/runtime/query/iteration/provider-rejected-image.js.map +1 -1
- package/dist/runtime/query/iteration/stream-turn.d.ts +4 -1
- package/dist/runtime/query/iteration/stream-turn.d.ts.map +1 -1
- package/dist/runtime/query/iteration/stream-turn.js +22 -8
- package/dist/runtime/query/iteration/stream-turn.js.map +1 -1
- package/dist/runtime/query/plugin-hooks.d.ts +14 -0
- package/dist/runtime/query/plugin-hooks.d.ts.map +1 -1
- package/dist/runtime/query/plugin-hooks.js +18 -0
- package/dist/runtime/query/plugin-hooks.js.map +1 -1
- package/dist/runtime/query/repeat-call.d.ts +17 -4
- package/dist/runtime/query/repeat-call.d.ts.map +1 -1
- package/dist/runtime/query/repeat-call.js +26 -19
- package/dist/runtime/query/repeat-call.js.map +1 -1
- package/dist/runtime/query/resume-pending.d.ts +18 -33
- package/dist/runtime/query/resume-pending.d.ts.map +1 -1
- package/dist/runtime/query/resume-pending.js +59 -42
- package/dist/runtime/query/resume-pending.js.map +1 -1
- package/dist/runtime/query/review-policy.d.ts +4 -4
- package/dist/runtime/query/review-policy.d.ts.map +1 -1
- package/dist/runtime/query/review-policy.js +10 -9
- package/dist/runtime/query/review-policy.js.map +1 -1
- package/dist/runtime/query/sandbox-lifecycle.d.ts.map +1 -1
- package/dist/runtime/query/sandbox-lifecycle.js +4 -0
- package/dist/runtime/query/sandbox-lifecycle.js.map +1 -1
- package/dist/runtime/query/steering.d.ts +11 -1
- package/dist/runtime/query/steering.d.ts.map +1 -1
- package/dist/runtime/query/steering.js +12 -1
- package/dist/runtime/query/steering.js.map +1 -1
- package/dist/runtime/query/tool-output-budget.d.ts +10 -6
- package/dist/runtime/query/tool-output-budget.d.ts.map +1 -1
- package/dist/runtime/query/tool-output-budget.js +54 -12
- package/dist/runtime/query/tool-output-budget.js.map +1 -1
- package/dist/runtime/query/tooling.d.ts +5 -1
- package/dist/runtime/query/tooling.d.ts.map +1 -1
- package/dist/runtime/query/tooling.js +5 -0
- package/dist/runtime/query/tooling.js.map +1 -1
- package/dist/scheduler/completion-inbox.d.ts +49 -0
- package/dist/scheduler/completion-inbox.d.ts.map +1 -1
- package/dist/scheduler/completion-inbox.js +122 -2
- package/dist/scheduler/completion-inbox.js.map +1 -1
- package/dist/store/evidence/compaction-archive.d.ts +109 -0
- package/dist/store/evidence/compaction-archive.d.ts.map +1 -0
- package/dist/store/evidence/compaction-archive.js +125 -0
- package/dist/store/evidence/compaction-archive.js.map +1 -0
- package/dist/store/evidence/compaction-provenance.d.ts +7 -0
- package/dist/store/evidence/compaction-provenance.d.ts.map +1 -0
- package/dist/store/evidence/compaction-provenance.js +49 -0
- package/dist/store/evidence/compaction-provenance.js.map +1 -0
- package/dist/store/evidence/compaction-text.d.ts +16 -0
- package/dist/store/evidence/compaction-text.d.ts.map +1 -0
- package/dist/store/evidence/compaction-text.js +51 -0
- package/dist/store/evidence/compaction-text.js.map +1 -0
- package/dist/store/evidence/disk.d.ts +11 -0
- package/dist/store/evidence/disk.d.ts.map +1 -0
- package/dist/store/evidence/disk.js +367 -0
- package/dist/store/evidence/disk.js.map +1 -0
- package/dist/store/evidence/format.d.ts +25 -0
- package/dist/store/evidence/format.d.ts.map +1 -0
- package/dist/store/evidence/format.js +115 -0
- package/dist/store/evidence/format.js.map +1 -0
- package/dist/store/evidence/index-page.d.ts +208 -0
- package/dist/store/evidence/index-page.d.ts.map +1 -0
- package/dist/store/evidence/index-page.js +262 -0
- package/dist/store/evidence/index-page.js.map +1 -0
- package/dist/store/evidence/io.d.ts +24 -0
- package/dist/store/evidence/io.d.ts.map +1 -0
- package/dist/store/evidence/io.js +69 -0
- package/dist/store/evidence/io.js.map +1 -0
- package/dist/store/evidence/linked.d.ts +9 -0
- package/dist/store/evidence/linked.d.ts.map +1 -0
- package/dist/store/evidence/linked.js +314 -0
- package/dist/store/evidence/linked.js.map +1 -0
- package/dist/store/evidence/passages.d.ts +15 -0
- package/dist/store/evidence/passages.d.ts.map +1 -0
- package/dist/store/evidence/passages.js +72 -0
- package/dist/store/evidence/passages.js.map +1 -0
- package/dist/store/evidence/record-chain.d.ts +42 -0
- package/dist/store/evidence/record-chain.d.ts.map +1 -0
- package/dist/store/evidence/record-chain.js +111 -0
- package/dist/store/evidence/record-chain.js.map +1 -0
- package/dist/store/evidence/search-input.d.ts +21 -0
- package/dist/store/evidence/search-input.d.ts.map +1 -0
- package/dist/store/evidence/search-input.js +44 -0
- package/dist/store/evidence/search-input.js.map +1 -0
- package/dist/store/evidence/selection.d.ts +9 -0
- package/dist/store/evidence/selection.d.ts.map +1 -0
- package/dist/store/evidence/selection.js +17 -0
- package/dist/store/evidence/selection.js.map +1 -0
- package/dist/store/evidence/source-kind.d.ts +11 -0
- package/dist/store/evidence/source-kind.d.ts.map +1 -0
- package/dist/store/evidence/source-kind.js +26 -0
- package/dist/store/evidence/source-kind.js.map +1 -0
- package/dist/store/evidence/source-text.d.ts +51 -0
- package/dist/store/evidence/source-text.d.ts.map +1 -0
- package/dist/store/evidence/source-text.js +213 -0
- package/dist/store/evidence/source-text.js.map +1 -0
- package/dist/store/evidence/types.d.ts +162 -0
- package/dist/store/evidence/types.d.ts.map +1 -0
- package/dist/store/evidence/types.js +2 -0
- package/dist/store/evidence/types.js.map +1 -0
- package/dist/store/memory/disk.d.ts +2 -0
- package/dist/store/memory/disk.d.ts.map +1 -1
- package/dist/store/memory/disk.js +2 -1
- package/dist/store/memory/disk.js.map +1 -1
- package/dist/store/run/disk.d.ts +10 -0
- package/dist/store/run/disk.d.ts.map +1 -1
- package/dist/store/run/disk.js +87 -7
- package/dist/store/run/disk.js.map +1 -1
- package/dist/store/run/memory.d.ts +1 -0
- package/dist/store/run/memory.d.ts.map +1 -1
- package/dist/store/run/memory.js +10 -0
- package/dist/store/run/memory.js.map +1 -1
- package/dist/store/run/tool-executions.d.ts +13 -0
- package/dist/store/run/tool-executions.d.ts.map +1 -0
- package/dist/store/run/tool-executions.js +99 -0
- package/dist/store/run/tool-executions.js.map +1 -0
- package/dist/store/session/index.d.ts +2 -0
- package/dist/store/session/index.d.ts.map +1 -1
- package/dist/store/session/index.js +1 -0
- package/dist/store/session/index.js.map +1 -1
- package/dist/store/session/sqlite.d.ts +57 -0
- package/dist/store/session/sqlite.d.ts.map +1 -0
- package/dist/store/session/sqlite.js +430 -0
- package/dist/store/session/sqlite.js.map +1 -0
- package/dist/tools/builtins/bash.d.ts.map +1 -1
- package/dist/tools/builtins/bash.js +4 -10
- package/dist/tools/builtins/bash.js.map +1 -1
- package/dist/tools/builtins/edit-apply.d.ts +126 -0
- package/dist/tools/builtins/edit-apply.d.ts.map +1 -0
- package/dist/tools/builtins/edit-apply.js +360 -0
- package/dist/tools/builtins/edit-apply.js.map +1 -0
- package/dist/tools/builtins/edit.d.ts +143 -1
- package/dist/tools/builtins/edit.d.ts.map +1 -1
- package/dist/tools/builtins/edit.js +37 -219
- package/dist/tools/builtins/edit.js.map +1 -1
- package/dist/tools/builtins/index.d.ts +1 -0
- package/dist/tools/builtins/index.d.ts.map +1 -1
- package/dist/tools/builtins/index.js +9 -3
- package/dist/tools/builtins/index.js.map +1 -1
- package/dist/tools/builtins/job.d.ts.map +1 -1
- package/dist/tools/builtins/job.js +5 -6
- package/dist/tools/builtins/job.js.map +1 -1
- package/dist/tools/builtins/read-file.d.ts +2 -2
- package/dist/tools/builtins/read-file.d.ts.map +1 -1
- package/dist/tools/builtins/read-file.js +50 -65
- package/dist/tools/builtins/read-file.js.map +1 -1
- package/dist/tools/builtins/read-render.d.ts +56 -0
- package/dist/tools/builtins/read-render.d.ts.map +1 -0
- package/dist/tools/builtins/read-render.js +73 -0
- package/dist/tools/builtins/read-render.js.map +1 -0
- package/dist/tools/builtins/wait-for-job-bounds.d.ts +67 -0
- package/dist/tools/builtins/wait-for-job-bounds.d.ts.map +1 -0
- package/dist/tools/builtins/wait-for-job-bounds.js +108 -0
- package/dist/tools/builtins/wait-for-job-bounds.js.map +1 -0
- package/dist/tools/builtins/wait-for-job.d.ts +6 -0
- package/dist/tools/builtins/wait-for-job.d.ts.map +1 -0
- package/dist/tools/builtins/wait-for-job.js +162 -0
- package/dist/tools/builtins/wait-for-job.js.map +1 -0
- package/dist/tools/builtins/write-file.js +7 -2
- package/dist/tools/builtins/write-file.js.map +1 -1
- package/dist/tools/coordinator/index.d.ts.map +1 -1
- package/dist/tools/coordinator/index.js +1 -7
- package/dist/tools/coordinator/index.js.map +1 -1
- package/dist/tools/defineTool.d.ts +2 -1
- package/dist/tools/defineTool.d.ts.map +1 -1
- package/dist/tools/defineTool.js +1 -1
- package/dist/tools/defineTool.js.map +1 -1
- package/dist/tools/file-read-tracker.d.ts.map +1 -1
- package/dist/tools/file-read-tracker.js +90 -3
- package/dist/tools/file-read-tracker.js.map +1 -1
- package/dist/tools/resident-history.d.ts +10 -0
- package/dist/tools/resident-history.d.ts.map +1 -0
- package/dist/tools/resident-history.js +80 -0
- package/dist/tools/resident-history.js.map +1 -0
- package/dist/tools/resident-tool-evidence.d.ts +5 -0
- package/dist/tools/resident-tool-evidence.d.ts.map +1 -0
- package/dist/tools/resident-tool-evidence.js +57 -0
- package/dist/tools/resident-tool-evidence.js.map +1 -0
- package/dist/types/advisory/config.d.ts +7 -0
- package/dist/types/advisory/config.d.ts.map +1 -1
- package/dist/types/agent/reactive.d.ts +1 -0
- package/dist/types/agent/reactive.d.ts.map +1 -1
- package/dist/types/authorization/index.d.ts +9 -9
- package/dist/types/authorization/index.d.ts.map +1 -1
- package/dist/types/authorization/index.js +1 -1
- package/dist/types/authorization/index.js.map +1 -1
- package/dist/types/hitl/index.d.ts +4 -0
- package/dist/types/hitl/index.d.ts.map +1 -1
- package/dist/types/hitl/index.js.map +1 -1
- package/dist/types/message/index.d.ts +16 -2
- package/dist/types/message/index.d.ts.map +1 -1
- package/dist/types/message/index.js +10 -1
- package/dist/types/message/index.js.map +1 -1
- package/dist/types/provider/chat.d.ts +2 -0
- package/dist/types/provider/chat.d.ts.map +1 -1
- package/dist/types/provider/stream.d.ts +4 -0
- package/dist/types/provider/stream.d.ts.map +1 -1
- package/dist/types/run/answer-review.d.ts +34 -3
- package/dist/types/run/answer-review.d.ts.map +1 -1
- package/dist/types/run/config.d.ts +3 -0
- package/dist/types/run/config.d.ts.map +1 -1
- package/dist/types/run/entity.d.ts +20 -0
- package/dist/types/run/entity.d.ts.map +1 -1
- package/dist/types/run/events.d.ts +31 -8
- package/dist/types/run/events.d.ts.map +1 -1
- package/dist/types/run/events.js.map +1 -1
- package/dist/types/run/prepare-step.d.ts +53 -8
- package/dist/types/run/prepare-step.d.ts.map +1 -1
- package/dist/types/run/store.d.ts +29 -4
- package/dist/types/run/store.d.ts.map +1 -1
- package/dist/types/run/store.js +0 -28
- package/dist/types/run/store.js.map +1 -1
- package/dist/types/sandbox/index.d.ts +15 -14
- package/dist/types/sandbox/index.d.ts.map +1 -1
- package/dist/types/sandbox/index.js.map +1 -1
- package/dist/types/tool/index.d.ts +124 -1
- package/dist/types/tool/index.d.ts.map +1 -1
- package/dist/types/tool/index.js.map +1 -1
- package/dist/utils/await-with-abort.d.ts +8 -0
- package/dist/utils/await-with-abort.d.ts.map +1 -0
- package/dist/utils/await-with-abort.js +28 -0
- package/dist/utils/await-with-abort.js.map +1 -0
- package/dist/utils/env.d.ts +19 -0
- package/dist/utils/env.d.ts.map +1 -0
- package/dist/utils/env.js +25 -0
- package/dist/utils/env.js.map +1 -0
- package/dist/utils/evidence-time.d.ts +3 -0
- package/dist/utils/evidence-time.d.ts.map +1 -0
- package/dist/utils/evidence-time.js +10 -0
- package/dist/utils/evidence-time.js.map +1 -0
- package/dist/utils/evidence-tokens.d.ts +13 -0
- package/dist/utils/evidence-tokens.d.ts.map +1 -0
- package/dist/utils/evidence-tokens.js +29 -0
- package/dist/utils/evidence-tokens.js.map +1 -0
- package/package.json +1 -1
- package/src/advisory/executor.ts +15 -30
- package/src/advisory/history.ts +126 -0
- package/src/advisory/index.ts +5 -1
- package/src/agents/ReactiveAgent.ts +3 -0
- package/src/agents/runAgent.ts +14 -1
- package/src/compaction/manual.ts +30 -2
- package/src/compaction/summary.ts +4 -1
- package/src/config/runtime.ts +2 -2
- package/src/connector/mcp/adapter.ts +20 -6
- package/src/contracts/schemas.ts +1 -1
- package/src/eval/harness-protection.ts +79 -0
- package/src/eval/harness-verification.ts +31 -1
- package/src/eval/index.ts +1 -0
- package/src/manager/resident/activity.ts +187 -0
- package/src/manager/resident/agenda.ts +59 -5
- package/src/manager/resident/consumption.ts +311 -0
- package/src/manager/resident/evidence-recall.ts +363 -0
- package/src/manager/resident/history-disk.ts +63 -0
- package/src/manager/resident/history.ts +312 -0
- package/src/manager/resident/initiative.ts +13 -3
- package/src/manager/resident/learning-cycle.ts +499 -0
- package/src/manager/resident/learning-observation.ts +39 -0
- package/src/manager/resident/learning-store.ts +813 -0
- package/src/manager/resident/learning.ts +132 -8
- package/src/manager/resident/store.ts +31 -3
- package/src/manager/resident/tool-evidence.ts +412 -0
- package/src/manager/run/persistence.ts +18 -0
- package/src/plugin/loader.ts +8 -3
- package/src/prompt/coding-agent-doctrine.ts +2 -0
- package/src/prompt/index.ts +2 -0
- package/src/prompt/resident-learning.ts +143 -0
- package/src/prompt/resident-step.ts +83 -3
- package/src/provider/collect-chat-completion.ts +7 -6
- package/src/provider/fallback.ts +2 -1
- package/src/provider/stream-text.ts +56 -0
- package/src/public-runtime.ts +39 -1
- package/src/public-tools.ts +21 -0
- package/src/public-types.ts +98 -0
- package/src/registry/tool/execute.ts +2 -4
- package/src/registry/tool/portable.ts +264 -0
- package/src/registry/tool/schema.ts +38 -8
- package/src/registry/toolset/catalog.ts +8 -9
- package/src/run/LimitChecker.ts +3 -3
- package/src/run/evidence-query.ts +333 -0
- package/src/run/evidence-recall.ts +854 -0
- package/src/run/index.ts +11 -0
- package/src/run/json-claim-verifier.ts +298 -0
- package/src/run/preparation-context-error.ts +16 -0
- package/src/run-query/index.ts +1 -1
- package/src/runtime/jobs/awaited-jobs.ts +271 -0
- package/src/runtime/jobs/registry.ts +50 -0
- package/src/runtime/query/callback-inference.ts +94 -0
- package/src/runtime/query/checkpoint.ts +14 -0
- package/src/runtime/query/events.ts +22 -0
- package/src/runtime/query/executor.ts +100 -10
- package/src/runtime/query/file-evidence-context.ts +209 -0
- package/src/runtime/query/file-evidence-replay.ts +776 -0
- package/src/runtime/query/file-evidence-seed.ts +126 -0
- package/src/runtime/query/guard.ts +2 -0
- package/src/runtime/query/index.ts +153 -27
- package/src/runtime/query/iteration/index.ts +467 -110
- package/src/runtime/query/iteration/phases/advisory.ts +3 -0
- package/src/runtime/query/iteration/phases/context.ts +12 -0
- package/src/runtime/query/iteration/phases/tool-review.ts +7 -0
- package/src/runtime/query/iteration/provider-rejected-image.ts +6 -1
- package/src/runtime/query/iteration/stream-turn.ts +35 -8
- package/src/runtime/query/plugin-hooks.ts +20 -0
- package/src/runtime/query/repeat-call.ts +28 -18
- package/src/runtime/query/resume-pending.ts +65 -40
- package/src/runtime/query/review-policy.ts +13 -9
- package/src/runtime/query/sandbox-lifecycle.ts +3 -0
- package/src/runtime/query/steering.ts +11 -0
- package/src/runtime/query/tool-output-budget.ts +65 -13
- package/src/runtime/query/tooling.ts +10 -1
- package/src/scheduler/completion-inbox.ts +124 -2
- package/src/store/evidence/compaction-archive.ts +139 -0
- package/src/store/evidence/compaction-provenance.ts +52 -0
- package/src/store/evidence/compaction-text.ts +61 -0
- package/src/store/evidence/disk.ts +461 -0
- package/src/store/evidence/format.ts +126 -0
- package/src/store/evidence/index-page.ts +292 -0
- package/src/store/evidence/io.ts +95 -0
- package/src/store/evidence/linked.ts +365 -0
- package/src/store/evidence/passages.ts +88 -0
- package/src/store/evidence/record-chain.ts +108 -0
- package/src/store/evidence/search-input.ts +62 -0
- package/src/store/evidence/selection.ts +25 -0
- package/src/store/evidence/source-kind.ts +36 -0
- package/src/store/evidence/source-text.ts +285 -0
- package/src/store/evidence/types.ts +177 -0
- package/src/store/memory/disk.ts +4 -1
- package/src/store/run/disk.ts +110 -8
- package/src/store/run/memory.ts +10 -0
- package/src/store/run/tool-executions.ts +112 -0
- package/src/store/session/index.ts +2 -0
- package/src/store/session/sqlite.ts +584 -0
- package/src/tools/builtins/bash.ts +4 -10
- package/src/tools/builtins/edit-apply.ts +456 -0
- package/src/tools/builtins/edit.ts +39 -270
- package/src/tools/builtins/index.ts +9 -3
- package/src/tools/builtins/job.ts +5 -6
- package/src/tools/builtins/read-file.ts +56 -77
- package/src/tools/builtins/read-render.ts +104 -0
- package/src/tools/builtins/wait-for-job-bounds.ts +179 -0
- package/src/tools/builtins/wait-for-job.ts +184 -0
- package/src/tools/builtins/write-file.ts +7 -2
- package/src/tools/coordinator/index.ts +1 -7
- package/src/tools/defineTool.ts +4 -2
- package/src/tools/file-read-tracker.ts +86 -2
- package/src/tools/resident-history.ts +86 -0
- package/src/tools/resident-tool-evidence.ts +68 -0
- package/src/types/advisory/config.ts +7 -0
- package/src/types/agent/reactive.ts +1 -0
- package/src/types/authorization/index.ts +2 -2
- package/src/types/hitl/index.ts +4 -0
- package/src/types/message/index.ts +22 -0
- package/src/types/provider/chat.ts +2 -0
- package/src/types/provider/stream.ts +4 -0
- package/src/types/run/answer-review.ts +34 -3
- package/src/types/run/config.ts +3 -0
- package/src/types/run/entity.ts +21 -0
- package/src/types/run/events.ts +31 -8
- package/src/types/run/prepare-step.ts +59 -8
- package/src/types/run/store.ts +35 -4
- package/src/types/sandbox/index.ts +15 -14
- package/src/types/tool/index.ts +123 -1
- package/src/utils/await-with-abort.ts +26 -0
- package/src/utils/env.ts +23 -0
- package/src/utils/evidence-time.ts +9 -0
- package/src/utils/evidence-tokens.ts +32 -0
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import type { BackgroundJob, BackgroundJobRegistry } from './registry.js';
|
|
2
|
+
/**
|
|
3
|
+
* What this adapter needs from a registry: the jobs' exits, and one job's
|
|
4
|
+
* current status. Structural rather than the class, for the reason
|
|
5
|
+
* `BackgroundJobRegistryRef` is: the kernel passes the real registry, and a
|
|
6
|
+
* test that needs two exits and nothing else should not have to spawn
|
|
7
|
+
* processes to produce them.
|
|
8
|
+
*/
|
|
9
|
+
export type AwaitedJobSource = Pick<BackgroundJobRegistry, 'get' | 'onExit'>;
|
|
10
|
+
/** Exits and the text that puts them in front of the model. See {@link AwaitedJobs.takeDelivery}. */
|
|
11
|
+
export interface DeliverableJobExits {
|
|
12
|
+
/** The notice text, already queued by the exit that produced it. */
|
|
13
|
+
readonly text: string;
|
|
14
|
+
/** The exits that text accounts for, taken from the record. */
|
|
15
|
+
readonly exits: readonly BackgroundJob[];
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Background jobs the model SAID it is waiting on.
|
|
19
|
+
*
|
|
20
|
+
* `CompletionInbox` gives a run a bounded, zero-token wait for a delegated
|
|
21
|
+
* task nobody is blocked on, and `holdForOutstandingWork` spends it: the
|
|
22
|
+
* model stops calling tools, the loop races the inbox against operator input,
|
|
23
|
+
* and the run only settles once the result is in the transcript or the grace
|
|
24
|
+
* is gone. Background shell jobs had none of it — so a model that started a
|
|
25
|
+
* job and then had nothing left to do improvised, and the recorded run
|
|
26
|
+
* (research/resident/results/2026-09-14-exploration-policy-terra-tui.json)
|
|
27
|
+
* shows what that costs: six `job read` polls, three `job list` polls and a
|
|
28
|
+
* `sleep 30`, each one a full context resend.
|
|
29
|
+
*
|
|
30
|
+
* This is the same three-method shape the hold already races —
|
|
31
|
+
* {@link hasPendingWork}, {@link waitForArrival}, {@link drain} — over the
|
|
32
|
+
* job registry instead of the task gateway.
|
|
33
|
+
*
|
|
34
|
+
* **Intent is stated, never inferred.** A job is only outstanding here once
|
|
35
|
+
* `wait_for_job` named it (see {@link expect}); job existence means nothing.
|
|
36
|
+
* That is the same distinction `CompletionInbox.expect` draws for a
|
|
37
|
+
* background task, and it is what keeps a dev server or a file watcher —
|
|
38
|
+
* started precisely so it would keep running — from holding every run of the
|
|
39
|
+
* session open for its grace period. The model that wants to wait says so.
|
|
40
|
+
*/
|
|
41
|
+
export declare class AwaitedJobs {
|
|
42
|
+
private readonly source;
|
|
43
|
+
/** Whose jobs these are — the run or the session the jobs are bound to. */
|
|
44
|
+
private readonly owner;
|
|
45
|
+
/**
|
|
46
|
+
* Whether the exit notice this run queues for the model is still
|
|
47
|
+
* unread. A second opinion on {@link noticesDelivered}, and it can
|
|
48
|
+
* only ever narrow what counts as pending.
|
|
49
|
+
*
|
|
50
|
+
* An exit is work only until the model has seen it, and this adapter is
|
|
51
|
+
* not what shows it: the text rides out on the next tool result
|
|
52
|
+
* (`attachNotice`), which is what normally happens, long before any
|
|
53
|
+
* hold opens. {@link noticesDelivered} is how that delivery says so,
|
|
54
|
+
* and it is the per-job record — the entry goes, so nothing can count
|
|
55
|
+
* it again.
|
|
56
|
+
*
|
|
57
|
+
* This stays because the two answer different questions. That one is
|
|
58
|
+
* reported BY a delivery site, so it is only as good as the sites that
|
|
59
|
+
* remember to call it; this reads the channel itself, and a channel
|
|
60
|
+
* with nothing queued cannot have news in it whatever the record says.
|
|
61
|
+
* It is also safe in one direction only: it can suppress a hold, never
|
|
62
|
+
* open one, so a stale `true` here is not a turn the model gets to
|
|
63
|
+
* spend — which is the failure this pair exists to prevent.
|
|
64
|
+
*
|
|
65
|
+
* `CompletionInbox.claim` draws the same line on the task side. It can
|
|
66
|
+
* name the task, because the call that delivers a completion knows
|
|
67
|
+
* which one it delivered; a notice is text by the time it reaches the
|
|
68
|
+
* tool result, so this asks the channel instead.
|
|
69
|
+
*
|
|
70
|
+
* Absent means nothing else consumes the notices, so a recorded exit is
|
|
71
|
+
* unread by definition.
|
|
72
|
+
*/
|
|
73
|
+
private readonly unreadNotice?;
|
|
74
|
+
/** Awaited and still running. Nothing else can hold a run open. */
|
|
75
|
+
private readonly outstanding;
|
|
76
|
+
/** Exits since the last {@link drain}. */
|
|
77
|
+
private exits;
|
|
78
|
+
private readonly arrivals;
|
|
79
|
+
private detach?;
|
|
80
|
+
constructor(source: AwaitedJobSource,
|
|
81
|
+
/** Whose jobs these are — the run or the session the jobs are bound to. */
|
|
82
|
+
owner: string,
|
|
83
|
+
/**
|
|
84
|
+
* Whether the exit notice this run queues for the model is still
|
|
85
|
+
* unread. A second opinion on {@link noticesDelivered}, and it can
|
|
86
|
+
* only ever narrow what counts as pending.
|
|
87
|
+
*
|
|
88
|
+
* An exit is work only until the model has seen it, and this adapter is
|
|
89
|
+
* not what shows it: the text rides out on the next tool result
|
|
90
|
+
* (`attachNotice`), which is what normally happens, long before any
|
|
91
|
+
* hold opens. {@link noticesDelivered} is how that delivery says so,
|
|
92
|
+
* and it is the per-job record — the entry goes, so nothing can count
|
|
93
|
+
* it again.
|
|
94
|
+
*
|
|
95
|
+
* This stays because the two answer different questions. That one is
|
|
96
|
+
* reported BY a delivery site, so it is only as good as the sites that
|
|
97
|
+
* remember to call it; this reads the channel itself, and a channel
|
|
98
|
+
* with nothing queued cannot have news in it whatever the record says.
|
|
99
|
+
* It is also safe in one direction only: it can suppress a hold, never
|
|
100
|
+
* open one, so a stale `true` here is not a turn the model gets to
|
|
101
|
+
* spend — which is the failure this pair exists to prevent.
|
|
102
|
+
*
|
|
103
|
+
* `CompletionInbox.claim` draws the same line on the task side. It can
|
|
104
|
+
* name the task, because the call that delivers a completion knows
|
|
105
|
+
* which one it delivered; a notice is text by the time it reaches the
|
|
106
|
+
* tool result, so this asks the channel instead.
|
|
107
|
+
*
|
|
108
|
+
* Absent means nothing else consumes the notices, so a recorded exit is
|
|
109
|
+
* unread by definition.
|
|
110
|
+
*/
|
|
111
|
+
unreadNotice?: (() => boolean) | undefined);
|
|
112
|
+
/**
|
|
113
|
+
* Start listening.
|
|
114
|
+
*
|
|
115
|
+
* Returns the detach, and attaching twice is a no-op rather than a second
|
|
116
|
+
* subscription — the same rule `CompletionInbox.attach` follows, for the
|
|
117
|
+
* same reason: two subscriptions would record each exit twice.
|
|
118
|
+
*/
|
|
119
|
+
attach(): () => void;
|
|
120
|
+
/**
|
|
121
|
+
* Say that the model is waiting on this job's exit.
|
|
122
|
+
*
|
|
123
|
+
* Called by `wait_for_job`, and by nothing else: the wait is the whole
|
|
124
|
+
* signal. A job that has ALREADY stopped is not recorded, because the
|
|
125
|
+
* call that marks it is the same call that returns its output — holding
|
|
126
|
+
* the run open afterwards would buy a turn to read a result the model has
|
|
127
|
+
* just read. `CompletionInbox.expect` skips an already-claimed task for
|
|
128
|
+
* the same reason.
|
|
129
|
+
*
|
|
130
|
+
* An id the registry does not know is ignored rather than raised: the
|
|
131
|
+
* caller is about to fail on it anyway, and a marking call is not the
|
|
132
|
+
* place that decides what an unknown job means.
|
|
133
|
+
*/
|
|
134
|
+
expect(id: string): void;
|
|
135
|
+
/**
|
|
136
|
+
* Recorded exits the model has not been shown yet.
|
|
137
|
+
*
|
|
138
|
+
* Both halves of the same question: {@link noticesDelivered} drops the
|
|
139
|
+
* entry when its notice goes out, and the `unreadNotice` constructor
|
|
140
|
+
* argument asks the channel whether anything is still queued. A queued
|
|
141
|
+
* exit whose notice has already been delivered is history, not pending
|
|
142
|
+
* work, and an exit nobody awaited is not this adapter's news to carry.
|
|
143
|
+
*/
|
|
144
|
+
private get unreadExits();
|
|
145
|
+
/** Whether an awaited job is still running, or one has exited unread. */
|
|
146
|
+
get hasPendingWork(): boolean;
|
|
147
|
+
/**
|
|
148
|
+
* Wait for the next awaited job's exit, deadline or abort, whichever comes
|
|
149
|
+
* first. Aborting releases only this waiter; the jobs are untouched.
|
|
150
|
+
*
|
|
151
|
+
* Bounded by the caller, exactly as `CompletionInbox.waitForArrival` is: a
|
|
152
|
+
* job that never exits — a dev server someone did await — must not keep a
|
|
153
|
+
* run open, and only the run's own budget knows how long is long enough.
|
|
154
|
+
*/
|
|
155
|
+
waitForArrival(timeoutMs: number, signal?: AbortSignal): Promise<void>;
|
|
156
|
+
/**
|
|
157
|
+
* Say that the queued exit notices have been put in front of the model.
|
|
158
|
+
*
|
|
159
|
+
* Called by the tool-result delivery (`attachNotice`), which is where an
|
|
160
|
+
* exit normally reaches the model; {@link takeDelivery} does the same for
|
|
161
|
+
* the hold's own path by taking the entries as it delivers them.
|
|
162
|
+
*
|
|
163
|
+
* Every recorded exit goes, and that is per-job rather than a blunt
|
|
164
|
+
* clear: the channel hands over ALL its queued text at once, and an exit
|
|
165
|
+
* is recorded here in the same synchronous announcement that queues its
|
|
166
|
+
* notice, so the text just delivered is exactly the notices of the exits
|
|
167
|
+
* in hand. An exit recorded after this call keeps its entry, because its
|
|
168
|
+
* notice was queued after that text was taken.
|
|
169
|
+
*
|
|
170
|
+
* Without it the entry outlived the delivery, and the channel-level gate
|
|
171
|
+
* above was the only thing standing between a read exit and a model turn
|
|
172
|
+
* — a gate that reopens the moment ANY later job, awaited or not, queues
|
|
173
|
+
* a notice of its own.
|
|
174
|
+
*/
|
|
175
|
+
noticesDelivered(): void;
|
|
176
|
+
/**
|
|
177
|
+
* Take the recorded exits together with the text that delivers them, or
|
|
178
|
+
* take neither.
|
|
179
|
+
*
|
|
180
|
+
* The pairing is the whole method. Draining the exits first and then
|
|
181
|
+
* asking for the notice loses them on the branch that finds none: the
|
|
182
|
+
* records are gone, no text was written, and the exit the run held itself
|
|
183
|
+
* open for is delivered by nobody. So {@link drain} is not called until
|
|
184
|
+
* the delivery is certain, and an exit this could not deliver stays in
|
|
185
|
+
* hand for the next one.
|
|
186
|
+
*/
|
|
187
|
+
takeDelivery(notice: () => string | undefined): DeliverableJobExits | undefined;
|
|
188
|
+
/**
|
|
189
|
+
* Take every exit recorded since the last call, leaving none behind.
|
|
190
|
+
*
|
|
191
|
+
* Draining rather than peeking, for the reason `CompletionInbox.drain`
|
|
192
|
+
* gives: an exit that stays queued after being delivered is a duplicate
|
|
193
|
+
* waiting to happen. Callers that are delivering want
|
|
194
|
+
* {@link takeDelivery}, which will not take them without the notice that
|
|
195
|
+
* accounts for them.
|
|
196
|
+
*/
|
|
197
|
+
drain(): readonly BackgroundJob[];
|
|
198
|
+
/**
|
|
199
|
+
* Awaited jobs still running.
|
|
200
|
+
*
|
|
201
|
+
* Read when a run ends, so it can say which wait it walked away from.
|
|
202
|
+
* Nothing here is stopped by being read — the ids are a statement, and a
|
|
203
|
+
* job's lifetime belongs to whoever owns it.
|
|
204
|
+
*/
|
|
205
|
+
get outstandingJobIds(): readonly string[];
|
|
206
|
+
/**
|
|
207
|
+
* Stop listening. Safe to call more than once.
|
|
208
|
+
*
|
|
209
|
+
* A run that ends without this leaves its listener on a registry the host
|
|
210
|
+
* reuses across runs — the leak `CompletionInbox.close` exists to prevent,
|
|
211
|
+
* on the other subsystem.
|
|
212
|
+
*/
|
|
213
|
+
close(): void;
|
|
214
|
+
}
|
|
215
|
+
//# sourceMappingURL=awaited-jobs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"awaited-jobs.d.ts","sourceRoot":"","sources":["../../../src/runtime/jobs/awaited-jobs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAA;AAEzE;;;;;;GAMG;AACH,MAAM,MAAM,gBAAgB,GAAG,IAAI,CAAC,qBAAqB,EAAE,KAAK,GAAG,QAAQ,CAAC,CAAA;AAE5E,qGAAqG;AACrG,MAAM,WAAW,mBAAmB;IACnC,oEAAoE;IACpE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,+DAA+D;IAC/D,QAAQ,CAAC,KAAK,EAAE,SAAS,aAAa,EAAE,CAAA;CACxC;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,qBAAa,WAAW;IAStB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,2EAA2E;IAC3E,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACH,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC;IAvC/B,mEAAmE;IACnE,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAoB;IAChD,0CAA0C;IAC1C,OAAO,CAAC,KAAK,CAAsB;IACnC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAwB;IACjD,OAAO,CAAC,MAAM,CAAC,CAAY;gBAGT,MAAM,EAAE,gBAAgB;IACzC,2EAA2E;IAC1D,KAAK,EAAE,MAAM;IAC9B;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACc,YAAY,CAAC,GAAE,MAAM,OAAO,aAAA;IAG9C;;;;;;OAMG;IACH,MAAM,IAAI,MAAM,IAAI;IAgBpB;;;;;;;;;;;;;OAaG;IACH,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;IAYxB;;;;;;;;OAQG;IACH,OAAO,KAAK,WAAW,GAGtB;IAED,yEAAyE;IACzE,IAAI,cAAc,IAAI,OAAO,CAE5B;IAED;;;;;;;OAOG;IACH,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAuBtE;;;;;;;;;;;;;;;;;;OAkBG;IACH,gBAAgB,IAAI,IAAI;IAIxB;;;;;;;;;;OAUG;IACH,YAAY,CAAC,MAAM,EAAE,MAAM,MAAM,GAAG,SAAS,GAAG,mBAAmB,GAAG,SAAS;IAO/E;;;;;;;;OAQG;IACH,KAAK,IAAI,SAAS,aAAa,EAAE;IAOjC;;;;;;OAMG;IACH,IAAI,iBAAiB,IAAI,SAAS,MAAM,EAAE,CAEzC;IAED;;;;;;OAMG;IACH,KAAK,IAAI,IAAI;CAUb"}
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Background jobs the model SAID it is waiting on.
|
|
3
|
+
*
|
|
4
|
+
* `CompletionInbox` gives a run a bounded, zero-token wait for a delegated
|
|
5
|
+
* task nobody is blocked on, and `holdForOutstandingWork` spends it: the
|
|
6
|
+
* model stops calling tools, the loop races the inbox against operator input,
|
|
7
|
+
* and the run only settles once the result is in the transcript or the grace
|
|
8
|
+
* is gone. Background shell jobs had none of it — so a model that started a
|
|
9
|
+
* job and then had nothing left to do improvised, and the recorded run
|
|
10
|
+
* (research/resident/results/2026-09-14-exploration-policy-terra-tui.json)
|
|
11
|
+
* shows what that costs: six `job read` polls, three `job list` polls and a
|
|
12
|
+
* `sleep 30`, each one a full context resend.
|
|
13
|
+
*
|
|
14
|
+
* This is the same three-method shape the hold already races —
|
|
15
|
+
* {@link hasPendingWork}, {@link waitForArrival}, {@link drain} — over the
|
|
16
|
+
* job registry instead of the task gateway.
|
|
17
|
+
*
|
|
18
|
+
* **Intent is stated, never inferred.** A job is only outstanding here once
|
|
19
|
+
* `wait_for_job` named it (see {@link expect}); job existence means nothing.
|
|
20
|
+
* That is the same distinction `CompletionInbox.expect` draws for a
|
|
21
|
+
* background task, and it is what keeps a dev server or a file watcher —
|
|
22
|
+
* started precisely so it would keep running — from holding every run of the
|
|
23
|
+
* session open for its grace period. The model that wants to wait says so.
|
|
24
|
+
*/
|
|
25
|
+
export class AwaitedJobs {
|
|
26
|
+
source;
|
|
27
|
+
owner;
|
|
28
|
+
unreadNotice;
|
|
29
|
+
/** Awaited and still running. Nothing else can hold a run open. */
|
|
30
|
+
outstanding = new Set();
|
|
31
|
+
/** Exits since the last {@link drain}. */
|
|
32
|
+
exits = [];
|
|
33
|
+
arrivals = new Set();
|
|
34
|
+
detach;
|
|
35
|
+
constructor(source,
|
|
36
|
+
/** Whose jobs these are — the run or the session the jobs are bound to. */
|
|
37
|
+
owner,
|
|
38
|
+
/**
|
|
39
|
+
* Whether the exit notice this run queues for the model is still
|
|
40
|
+
* unread. A second opinion on {@link noticesDelivered}, and it can
|
|
41
|
+
* only ever narrow what counts as pending.
|
|
42
|
+
*
|
|
43
|
+
* An exit is work only until the model has seen it, and this adapter is
|
|
44
|
+
* not what shows it: the text rides out on the next tool result
|
|
45
|
+
* (`attachNotice`), which is what normally happens, long before any
|
|
46
|
+
* hold opens. {@link noticesDelivered} is how that delivery says so,
|
|
47
|
+
* and it is the per-job record — the entry goes, so nothing can count
|
|
48
|
+
* it again.
|
|
49
|
+
*
|
|
50
|
+
* This stays because the two answer different questions. That one is
|
|
51
|
+
* reported BY a delivery site, so it is only as good as the sites that
|
|
52
|
+
* remember to call it; this reads the channel itself, and a channel
|
|
53
|
+
* with nothing queued cannot have news in it whatever the record says.
|
|
54
|
+
* It is also safe in one direction only: it can suppress a hold, never
|
|
55
|
+
* open one, so a stale `true` here is not a turn the model gets to
|
|
56
|
+
* spend — which is the failure this pair exists to prevent.
|
|
57
|
+
*
|
|
58
|
+
* `CompletionInbox.claim` draws the same line on the task side. It can
|
|
59
|
+
* name the task, because the call that delivers a completion knows
|
|
60
|
+
* which one it delivered; a notice is text by the time it reaches the
|
|
61
|
+
* tool result, so this asks the channel instead.
|
|
62
|
+
*
|
|
63
|
+
* Absent means nothing else consumes the notices, so a recorded exit is
|
|
64
|
+
* unread by definition.
|
|
65
|
+
*/
|
|
66
|
+
unreadNotice) {
|
|
67
|
+
this.source = source;
|
|
68
|
+
this.owner = owner;
|
|
69
|
+
this.unreadNotice = unreadNotice;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Start listening.
|
|
73
|
+
*
|
|
74
|
+
* Returns the detach, and attaching twice is a no-op rather than a second
|
|
75
|
+
* subscription — the same rule `CompletionInbox.attach` follows, for the
|
|
76
|
+
* same reason: two subscriptions would record each exit twice.
|
|
77
|
+
*/
|
|
78
|
+
attach() {
|
|
79
|
+
if (this.detach)
|
|
80
|
+
return this.detach;
|
|
81
|
+
this.detach = this.source.onExit((job) => {
|
|
82
|
+
// `onExit` is a broadcast over a registry a host may share between
|
|
83
|
+
// runs, and the filter is the same one the exit-notice channel
|
|
84
|
+
// applies in `runtime/query/index.ts`.
|
|
85
|
+
if (job.owner !== this.owner)
|
|
86
|
+
return;
|
|
87
|
+
// `outstanding` is the gate, so an id nobody awaited is ignored and
|
|
88
|
+
// a second announcement for the same job cannot queue twice.
|
|
89
|
+
if (!this.outstanding.delete(job.id))
|
|
90
|
+
return;
|
|
91
|
+
this.exits.push(job);
|
|
92
|
+
for (const wake of [...this.arrivals])
|
|
93
|
+
wake();
|
|
94
|
+
});
|
|
95
|
+
return this.detach;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Say that the model is waiting on this job's exit.
|
|
99
|
+
*
|
|
100
|
+
* Called by `wait_for_job`, and by nothing else: the wait is the whole
|
|
101
|
+
* signal. A job that has ALREADY stopped is not recorded, because the
|
|
102
|
+
* call that marks it is the same call that returns its output — holding
|
|
103
|
+
* the run open afterwards would buy a turn to read a result the model has
|
|
104
|
+
* just read. `CompletionInbox.expect` skips an already-claimed task for
|
|
105
|
+
* the same reason.
|
|
106
|
+
*
|
|
107
|
+
* An id the registry does not know is ignored rather than raised: the
|
|
108
|
+
* caller is about to fail on it anyway, and a marking call is not the
|
|
109
|
+
* place that decides what an unknown job means.
|
|
110
|
+
*/
|
|
111
|
+
expect(id) {
|
|
112
|
+
let job;
|
|
113
|
+
try {
|
|
114
|
+
job = this.source.get(id);
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
if (job.owner !== this.owner)
|
|
120
|
+
return;
|
|
121
|
+
if (job.status !== 'running')
|
|
122
|
+
return;
|
|
123
|
+
this.outstanding.add(id);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Recorded exits the model has not been shown yet.
|
|
127
|
+
*
|
|
128
|
+
* Both halves of the same question: {@link noticesDelivered} drops the
|
|
129
|
+
* entry when its notice goes out, and the `unreadNotice` constructor
|
|
130
|
+
* argument asks the channel whether anything is still queued. A queued
|
|
131
|
+
* exit whose notice has already been delivered is history, not pending
|
|
132
|
+
* work, and an exit nobody awaited is not this adapter's news to carry.
|
|
133
|
+
*/
|
|
134
|
+
get unreadExits() {
|
|
135
|
+
if (this.exits.length === 0)
|
|
136
|
+
return false;
|
|
137
|
+
return this.unreadNotice?.() ?? true;
|
|
138
|
+
}
|
|
139
|
+
/** Whether an awaited job is still running, or one has exited unread. */
|
|
140
|
+
get hasPendingWork() {
|
|
141
|
+
return this.unreadExits || this.outstanding.size > 0;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Wait for the next awaited job's exit, deadline or abort, whichever comes
|
|
145
|
+
* first. Aborting releases only this waiter; the jobs are untouched.
|
|
146
|
+
*
|
|
147
|
+
* Bounded by the caller, exactly as `CompletionInbox.waitForArrival` is: a
|
|
148
|
+
* job that never exits — a dev server someone did await — must not keep a
|
|
149
|
+
* run open, and only the run's own budget knows how long is long enough.
|
|
150
|
+
*/
|
|
151
|
+
waitForArrival(timeoutMs, signal) {
|
|
152
|
+
if (signal?.aborted)
|
|
153
|
+
return Promise.resolve();
|
|
154
|
+
if (this.unreadExits)
|
|
155
|
+
return Promise.resolve();
|
|
156
|
+
if (this.outstanding.size === 0)
|
|
157
|
+
return Promise.resolve();
|
|
158
|
+
return new Promise((resolve) => {
|
|
159
|
+
const finish = () => {
|
|
160
|
+
clearTimeout(timer);
|
|
161
|
+
this.arrivals.delete(finish);
|
|
162
|
+
signal?.removeEventListener('abort', finish);
|
|
163
|
+
resolve();
|
|
164
|
+
};
|
|
165
|
+
const timer = setTimeout(finish, timeoutMs);
|
|
166
|
+
timer.unref?.();
|
|
167
|
+
this.arrivals.add(finish);
|
|
168
|
+
signal?.addEventListener('abort', finish, { once: true });
|
|
169
|
+
if (signal?.aborted)
|
|
170
|
+
finish();
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Say that the queued exit notices have been put in front of the model.
|
|
175
|
+
*
|
|
176
|
+
* Called by the tool-result delivery (`attachNotice`), which is where an
|
|
177
|
+
* exit normally reaches the model; {@link takeDelivery} does the same for
|
|
178
|
+
* the hold's own path by taking the entries as it delivers them.
|
|
179
|
+
*
|
|
180
|
+
* Every recorded exit goes, and that is per-job rather than a blunt
|
|
181
|
+
* clear: the channel hands over ALL its queued text at once, and an exit
|
|
182
|
+
* is recorded here in the same synchronous announcement that queues its
|
|
183
|
+
* notice, so the text just delivered is exactly the notices of the exits
|
|
184
|
+
* in hand. An exit recorded after this call keeps its entry, because its
|
|
185
|
+
* notice was queued after that text was taken.
|
|
186
|
+
*
|
|
187
|
+
* Without it the entry outlived the delivery, and the channel-level gate
|
|
188
|
+
* above was the only thing standing between a read exit and a model turn
|
|
189
|
+
* — a gate that reopens the moment ANY later job, awaited or not, queues
|
|
190
|
+
* a notice of its own.
|
|
191
|
+
*/
|
|
192
|
+
noticesDelivered() {
|
|
193
|
+
this.exits = [];
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Take the recorded exits together with the text that delivers them, or
|
|
197
|
+
* take neither.
|
|
198
|
+
*
|
|
199
|
+
* The pairing is the whole method. Draining the exits first and then
|
|
200
|
+
* asking for the notice loses them on the branch that finds none: the
|
|
201
|
+
* records are gone, no text was written, and the exit the run held itself
|
|
202
|
+
* open for is delivered by nobody. So {@link drain} is not called until
|
|
203
|
+
* the delivery is certain, and an exit this could not deliver stays in
|
|
204
|
+
* hand for the next one.
|
|
205
|
+
*/
|
|
206
|
+
takeDelivery(notice) {
|
|
207
|
+
if (this.exits.length === 0)
|
|
208
|
+
return undefined;
|
|
209
|
+
const text = notice();
|
|
210
|
+
if (text === undefined)
|
|
211
|
+
return undefined;
|
|
212
|
+
return { text, exits: this.drain() };
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Take every exit recorded since the last call, leaving none behind.
|
|
216
|
+
*
|
|
217
|
+
* Draining rather than peeking, for the reason `CompletionInbox.drain`
|
|
218
|
+
* gives: an exit that stays queued after being delivered is a duplicate
|
|
219
|
+
* waiting to happen. Callers that are delivering want
|
|
220
|
+
* {@link takeDelivery}, which will not take them without the notice that
|
|
221
|
+
* accounts for them.
|
|
222
|
+
*/
|
|
223
|
+
drain() {
|
|
224
|
+
if (this.exits.length === 0)
|
|
225
|
+
return [];
|
|
226
|
+
const exits = this.exits;
|
|
227
|
+
this.exits = [];
|
|
228
|
+
return exits;
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Awaited jobs still running.
|
|
232
|
+
*
|
|
233
|
+
* Read when a run ends, so it can say which wait it walked away from.
|
|
234
|
+
* Nothing here is stopped by being read — the ids are a statement, and a
|
|
235
|
+
* job's lifetime belongs to whoever owns it.
|
|
236
|
+
*/
|
|
237
|
+
get outstandingJobIds() {
|
|
238
|
+
return [...this.outstanding];
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Stop listening. Safe to call more than once.
|
|
242
|
+
*
|
|
243
|
+
* A run that ends without this leaves its listener on a registry the host
|
|
244
|
+
* reuses across runs — the leak `CompletionInbox.close` exists to prevent,
|
|
245
|
+
* on the other subsystem.
|
|
246
|
+
*/
|
|
247
|
+
close() {
|
|
248
|
+
this.detach?.();
|
|
249
|
+
this.detach = undefined;
|
|
250
|
+
this.outstanding.clear();
|
|
251
|
+
this.exits = [];
|
|
252
|
+
// Release anyone still waiting. A closed adapter would otherwise hold
|
|
253
|
+
// them to their own deadline for an exit that can no longer reach them.
|
|
254
|
+
for (const wake of [...this.arrivals])
|
|
255
|
+
wake();
|
|
256
|
+
this.arrivals.clear();
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
//# sourceMappingURL=awaited-jobs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"awaited-jobs.js","sourceRoot":"","sources":["../../../src/runtime/jobs/awaited-jobs.ts"],"names":[],"mappings":"AAmBA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,OAAO,WAAW;IASL;IAEA;IA6BA;IAvClB,mEAAmE;IAClD,WAAW,GAAG,IAAI,GAAG,EAAU,CAAA;IAChD,0CAA0C;IAClC,KAAK,GAAoB,EAAE,CAAA;IAClB,QAAQ,GAAG,IAAI,GAAG,EAAc,CAAA;IACzC,MAAM,CAAa;IAE3B,YACkB,MAAwB;IACzC,2EAA2E;IAC1D,KAAa;IAC9B;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACc,YAA4B;QA/B5B,WAAM,GAAN,MAAM,CAAkB;QAExB,UAAK,GAAL,KAAK,CAAQ;QA6Bb,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AC;IAED;;;;;;;;;;OAUG;IACH,YAAY,CAAC,MAAgC;QAC5C,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,SAAS,CAAA;QAC7C,MAAM,IAAI,GAAG,MAAM,EAAE,CAAA;QACrB,IAAI,IAAI,KAAK,SAAS;YAAE,OAAO,SAAS,CAAA;QACxC,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,EAAE,CAAA;IACrC,CAAC;IAED;;;;;;;;OAQG;IACH,KAAK;QACJ,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,EAAE,CAAA;QACtC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAA;QACxB,IAAI,CAAC,KAAK,GAAG,EAAE,CAAA;QACf,OAAO,KAAK,CAAA;IACb,CAAC;IAED;;;;;;OAMG;IACH,IAAI,iBAAiB;QACpB,OAAO,CAAC,GAAG,IAAI,CAAC,WAAW,CAAC,CAAA;IAC7B,CAAC;IAED;;;;;;OAMG;IACH,KAAK;QACJ,IAAI,CAAC,MAAM,EAAE,EAAE,CAAA;QACf,IAAI,CAAC,MAAM,GAAG,SAAS,CAAA;QACvB,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAA;QACxB,IAAI,CAAC,KAAK,GAAG,EAAE,CAAA;QACf,sEAAsE;QACtE,wEAAwE;QACxE,KAAK,MAAM,IAAI,IAAI,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC;YAAE,IAAI,EAAE,CAAA;QAC7C,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAA;IACtB,CAAC;CACD"}
|
|
@@ -119,6 +119,22 @@ export declare class BackgroundJobRegistry {
|
|
|
119
119
|
start(params: StartJobParams): BackgroundJob;
|
|
120
120
|
/** The record, or throw for an id this registry does not know. */
|
|
121
121
|
get(id: string): BackgroundJob;
|
|
122
|
+
/**
|
|
123
|
+
* Await one job's exit — the public counterpart to `onExit`, for a
|
|
124
|
+
* caller that wants a single result rather than a standing
|
|
125
|
+
* subscription. Resolves at once for a job that has already stopped, so
|
|
126
|
+
* a caller that lost the race against a fast-finishing job never blocks
|
|
127
|
+
* on a promise that would otherwise never settle.
|
|
128
|
+
*
|
|
129
|
+
* `signal` is honoured: an aborted wait rejects and detaches rather than
|
|
130
|
+
* holding the internal exit promise's continuation open for a job that
|
|
131
|
+
* may run for another hour. That only ends the WAIT — the job itself is
|
|
132
|
+
* untouched either way, exactly as a timed-out `kill`-less wait leaves
|
|
133
|
+
* it. See `wait-for-job-bounds.ts`, the first caller.
|
|
134
|
+
*/
|
|
135
|
+
waitForExit(id: string, opts?: {
|
|
136
|
+
signal?: AbortSignal;
|
|
137
|
+
}): Promise<BackgroundJob>;
|
|
122
138
|
/**
|
|
123
139
|
* Output since `fromOffset`, with what the cap dropped stated.
|
|
124
140
|
*
|
|
@@ -161,7 +177,21 @@ export declare function bindOwner(registry: BackgroundJobRegistry, owner: string
|
|
|
161
177
|
readonly workingDirectory: string;
|
|
162
178
|
readonly env?: Record<string, string>;
|
|
163
179
|
}) => JobProcess;
|
|
180
|
+
/**
|
|
181
|
+
* Be told that the model said it is waiting on a job's exit.
|
|
182
|
+
*
|
|
183
|
+
* The registry does not keep this: wait-intent belongs to the RUN that
|
|
184
|
+
* expressed it, not to a registry a host may share across runs and
|
|
185
|
+
* sessions. The run passes its own recorder here — `AwaitedJobs`, which
|
|
186
|
+
* is what the iteration loop holds open for. Absent means nobody is
|
|
187
|
+
* listening, and `markAwaited` is then absent from the bound ref rather
|
|
188
|
+
* than present and silently doing nothing.
|
|
189
|
+
*/
|
|
190
|
+
readonly onAwaited?: (id: string) => void;
|
|
164
191
|
}): {
|
|
192
|
+
kill: (id: string) => Promise<BackgroundJob>;
|
|
193
|
+
list: () => readonly BackgroundJob[];
|
|
194
|
+
markAwaited?: ((id: string) => void) | undefined;
|
|
165
195
|
start: (params: {
|
|
166
196
|
command: string;
|
|
167
197
|
workingDirectory?: string;
|
|
@@ -170,7 +200,8 @@ export declare function bindOwner(registry: BackgroundJobRegistry, owner: string
|
|
|
170
200
|
read: (id: string, opts?: {
|
|
171
201
|
fromOffset?: number;
|
|
172
202
|
}) => BackgroundJobOutput;
|
|
173
|
-
|
|
174
|
-
|
|
203
|
+
waitForExit: (id: string, opts?: {
|
|
204
|
+
signal?: AbortSignal;
|
|
205
|
+
}) => Promise<BackgroundJob>;
|
|
175
206
|
};
|
|
176
207
|
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../../src/runtime/jobs/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../../src/runtime/jobs/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAO1C;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,MAAM,MAAM,mBAAmB,GAAG,SAAS,GAAG,QAAQ,GAAG,QAAQ,CAAA;AAEjE,MAAM,WAAW,aAAa;IAC7B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IACnB,yDAAyD;IACzD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,MAAM,EAAE,mBAAmB,CAAA;IACpC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CACxB;AAED,MAAM,WAAW,mBAAmB;IACnC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB;;;;O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;;;;;;;;GASG;AACH,wBAAgB,SAAS,CACxB,QAAQ,EAAE,qBAAqB,EAC/B,KAAK,EAAE,MAAM,EACb,QAAQ,GAAE;IACT,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAA;IAClC,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACrC,iFAAiF;IACjF,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE;QACzB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;QACxB,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAA;QACjC,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;KACrC,KAAK,UAAU,CAAA;IAChB;;;;;;;;;OASG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAA;CACpC;eA6CY,MAAM;;wBANF,MAAM;oBA/BX;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,gBAAgB,CAAC,EAAE,MAAM,CAAA;KAAE;cAoBpD,MAAM;eACL,MAAM,SAAS;QAAE,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE;sBAI/B,MAAM,SAAS;QAAE,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE;EAkB1D"}
|
|
@@ -2,6 +2,7 @@ import { spawn } from 'node:child_process';
|
|
|
2
2
|
import { SANDBOX_KILL_GRACE_MS } from '../../constants/sandbox/index.js';
|
|
3
3
|
import { killTree } from '../../process/kill-tree.js';
|
|
4
4
|
import { scrubInheritedEnv } from '../../tools/env-scrub.js';
|
|
5
|
+
import { awaitWithAbort } from '../../utils/await-with-abort.js';
|
|
5
6
|
const DEFAULT_MAX_JOBS_PER_OWNER = 8;
|
|
6
7
|
const DEFAULT_MAX_OUTPUT_BYTES = 1024 * 1024;
|
|
7
8
|
/** A start that would exceed a declared bound. */
|
|
@@ -195,6 +196,30 @@ export class BackgroundJobRegistry {
|
|
|
195
196
|
throw new UnknownBackgroundJobError({ id });
|
|
196
197
|
return entry.record;
|
|
197
198
|
}
|
|
199
|
+
/**
|
|
200
|
+
* Await one job's exit — the public counterpart to `onExit`, for a
|
|
201
|
+
* caller that wants a single result rather than a standing
|
|
202
|
+
* subscription. Resolves at once for a job that has already stopped, so
|
|
203
|
+
* a caller that lost the race against a fast-finishing job never blocks
|
|
204
|
+
* on a promise that would otherwise never settle.
|
|
205
|
+
*
|
|
206
|
+
* `signal` is honoured: an aborted wait rejects and detaches rather than
|
|
207
|
+
* holding the internal exit promise's continuation open for a job that
|
|
208
|
+
* may run for another hour. That only ends the WAIT — the job itself is
|
|
209
|
+
* untouched either way, exactly as a timed-out `kill`-less wait leaves
|
|
210
|
+
* it. See `wait-for-job-bounds.ts`, the first caller.
|
|
211
|
+
*/
|
|
212
|
+
waitForExit(id, opts = {}) {
|
|
213
|
+
const entry = this.jobs.get(id);
|
|
214
|
+
if (!entry)
|
|
215
|
+
throw new UnknownBackgroundJobError({ id });
|
|
216
|
+
if (entry.record.status !== 'running')
|
|
217
|
+
return Promise.resolve(entry.record);
|
|
218
|
+
// `entry` is the same object the `finalize` closure in `start()`
|
|
219
|
+
// mutates in place, so reading `entry.record` after `exit` settles
|
|
220
|
+
// sees the final status — the same trick `kill()` already relies on.
|
|
221
|
+
return awaitWithAbort(entry.exit.then(() => entry.record), opts.signal);
|
|
222
|
+
}
|
|
198
223
|
/**
|
|
199
224
|
* Output since `fromOffset`, with what the cap dropped stated.
|
|
200
225
|
*
|
|
@@ -312,6 +337,18 @@ export function bindOwner(registry, owner, defaults = {}) {
|
|
|
312
337
|
mine(id);
|
|
313
338
|
return registry.read(id, opts ?? {});
|
|
314
339
|
},
|
|
340
|
+
waitForExit: (id, opts) => {
|
|
341
|
+
mine(id);
|
|
342
|
+
return registry.waitForExit(id, opts ?? {});
|
|
343
|
+
},
|
|
344
|
+
...(defaults.onAwaited
|
|
345
|
+
? {
|
|
346
|
+
markAwaited: (id) => {
|
|
347
|
+
mine(id);
|
|
348
|
+
defaults.onAwaited?.(id);
|
|
349
|
+
},
|
|
350
|
+
}
|
|
351
|
+
: {}),
|
|
315
352
|
kill: async (id) => {
|
|
316
353
|
mine(id);
|
|
317
354
|
return await registry.kill(id);
|