@namzu/sdk 38.1.0 → 39.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 +758 -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/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 +137 -0
- package/dist/manager/resident/agenda.d.ts.map +1 -0
- package/dist/manager/resident/agenda.js +586 -0
- package/dist/manager/resident/agenda.js.map +1 -0
- 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/delivery-window.d.ts +22 -0
- package/dist/manager/resident/delivery-window.d.ts.map +1 -0
- package/dist/manager/resident/delivery-window.js +78 -0
- package/dist/manager/resident/delivery-window.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/host.d.ts +78 -0
- package/dist/manager/resident/host.d.ts.map +1 -0
- package/dist/manager/resident/host.js +252 -0
- package/dist/manager/resident/host.js.map +1 -0
- package/dist/manager/resident/initiative.d.ts +111 -0
- package/dist/manager/resident/initiative.d.ts.map +1 -0
- package/dist/manager/resident/initiative.js +129 -0
- package/dist/manager/resident/initiative.js.map +1 -0
- 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 +726 -0
- package/dist/manager/resident/learning.d.ts.map +1 -0
- package/dist/manager/resident/learning.js +353 -0
- package/dist/manager/resident/learning.js.map +1 -0
- package/dist/manager/resident/loop.d.ts +31 -0
- package/dist/manager/resident/loop.d.ts.map +1 -0
- package/dist/manager/resident/loop.js +69 -0
- package/dist/manager/resident/loop.js.map +1 -0
- package/dist/manager/resident/outbox.d.ts +180 -0
- package/dist/manager/resident/outbox.d.ts.map +1 -0
- package/dist/manager/resident/outbox.js +214 -0
- package/dist/manager/resident/outbox.js.map +1 -0
- package/dist/manager/resident/proposal.d.ts +91 -0
- package/dist/manager/resident/proposal.d.ts.map +1 -0
- package/dist/manager/resident/proposal.js +75 -0
- package/dist/manager/resident/proposal.js.map +1 -0
- package/dist/manager/resident/store.d.ts +182 -0
- package/dist/manager/resident/store.d.ts.map +1 -0
- package/dist/manager/resident/store.js +199 -0
- package/dist/manager/resident/store.js.map +1 -0
- 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.map +1 -1
- package/dist/manager/run/persistence.js +6 -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/contributions.d.ts +5 -2
- package/dist/prompt/contributions.d.ts.map +1 -1
- package/dist/prompt/contributions.js.map +1 -1
- package/dist/prompt/index.d.ts +4 -0
- package/dist/prompt/index.d.ts.map +1 -1
- package/dist/prompt/index.js +2 -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 +36 -0
- package/dist/prompt/resident-step.d.ts.map +1 -0
- package/dist/prompt/resident-step.js +135 -0
- package/dist/prompt/resident-step.js.map +1 -0
- 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 +22 -3
- package/dist/public-runtime.d.ts.map +1 -1
- package/dist/public-runtime.js +21 -3
- package/dist/public-runtime.js.map +1 -1
- package/dist/public-tools.d.ts +2 -0
- package/dist/public-tools.d.ts.map +1 -1
- package/dist/public-tools.js +2 -0
- package/dist/public-tools.js.map +1 -1
- package/dist/public-types.d.ts +29 -3
- package/dist/public-types.d.ts.map +1 -1
- package/dist/registry/index.d.ts +1 -1
- package/dist/registry/index.d.ts.map +1 -1
- package/dist/registry/tool/execute.d.ts +18 -0
- package/dist/registry/tool/execute.d.ts.map +1 -1
- package/dist/registry/tool/execute.js +43 -6
- package/dist/registry/tool/execute.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/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 +7 -1
- package/dist/runtime/query/events.d.ts.map +1 -1
- package/dist/runtime/query/events.js +39 -12
- package/dist/runtime/query/events.js.map +1 -1
- package/dist/runtime/query/executor.d.ts +7 -1
- package/dist/runtime/query/executor.d.ts.map +1 -1
- package/dist/runtime/query/executor.js +38 -7
- 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 +64 -0
- package/dist/runtime/query/file-evidence-context.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 +40 -25
- package/dist/runtime/query/index.js.map +1 -1
- package/dist/runtime/query/iteration/index.d.ts +9 -31
- package/dist/runtime/query/iteration/index.d.ts.map +1 -1
- package/dist/runtime/query/iteration/index.js +231 -93
- 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 +2 -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 +3 -0
- 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/prompt-cache.d.ts.map +1 -1
- package/dist/runtime/query/prompt-cache.js +21 -42
- package/dist/runtime/query/prompt-cache.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/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 +3 -1
- package/dist/runtime/query/tooling.d.ts.map +1 -1
- package/dist/runtime/query/tooling.js +4 -0
- package/dist/runtime/query/tooling.js.map +1 -1
- package/dist/scheduler/completion-inbox.d.ts +3 -0
- package/dist/scheduler/completion-inbox.d.ts.map +1 -1
- package/dist/scheduler/completion-inbox.js +28 -0
- 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/job.d.ts.map +1 -1
- package/dist/tools/builtins/job.js +4 -5
- package/dist/tools/builtins/job.js.map +1 -1
- package/dist/tools/builtins/write-file.js +2 -2
- package/dist/tools/builtins/write-file.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 +12 -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 +8 -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 +7 -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/tool/index.d.ts +15 -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/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/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 +907 -0
- package/src/manager/resident/consumption.ts +311 -0
- package/src/manager/resident/delivery-window.ts +93 -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/host.ts +356 -0
- package/src/manager/resident/initiative.ts +205 -0
- 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 +493 -0
- package/src/manager/resident/loop.ts +101 -0
- package/src/manager/resident/outbox.ts +307 -0
- package/src/manager/resident/proposal.ts +105 -0
- package/src/manager/resident/store.ts +257 -0
- package/src/manager/resident/tool-evidence.ts +412 -0
- package/src/manager/run/persistence.ts +6 -0
- package/src/plugin/loader.ts +8 -3
- package/src/prompt/coding-agent-doctrine.ts +2 -0
- package/src/prompt/contributions.ts +5 -2
- package/src/prompt/index.ts +4 -0
- package/src/prompt/resident-learning.ts +143 -0
- package/src/prompt/resident-step.ts +176 -0
- 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 +44 -0
- package/src/public-tools.ts +3 -0
- package/src/public-types.ts +165 -0
- package/src/registry/index.ts +1 -1
- package/src/registry/tool/execute.ts +56 -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/query/callback-inference.ts +94 -0
- package/src/runtime/query/checkpoint.ts +14 -0
- package/src/runtime/query/events.ts +46 -14
- package/src/runtime/query/executor.ts +51 -9
- package/src/runtime/query/file-evidence-context.ts +65 -0
- package/src/runtime/query/guard.ts +2 -0
- package/src/runtime/query/index.ts +50 -27
- package/src/runtime/query/iteration/index.ts +269 -86
- package/src/runtime/query/iteration/phases/advisory.ts +3 -0
- package/src/runtime/query/iteration/phases/context.ts +2 -0
- package/src/runtime/query/iteration/phases/tool-review.ts +3 -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/prompt-cache.ts +24 -47
- 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/tool-output-budget.ts +65 -13
- package/src/runtime/query/tooling.ts +7 -1
- package/src/scheduler/completion-inbox.ts +26 -0
- 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/job.ts +4 -5
- package/src/tools/builtins/write-file.ts +2 -2
- package/src/tools/defineTool.ts +4 -2
- package/src/tools/file-read-tracker.ts +8 -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 +20 -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 +7 -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/tool/index.ts +19 -1
- package/src/utils/await-with-abort.ts +26 -0
- package/src/utils/evidence-time.ts +9 -0
- package/src/utils/evidence-tokens.ts +32 -0
|
@@ -8,6 +8,7 @@ import { renderSkillsSection } from '../../../persona/assembler.js';
|
|
|
8
8
|
import { resolveProviderCapabilities } from '../../../provider/capabilities.js';
|
|
9
9
|
import { collectChatCompletion } from '../../../provider/collect-chat-completion.js';
|
|
10
10
|
import { renderToolSchema } from '../../../registry/tool/schema.js';
|
|
11
|
+
import { PreparationContextError } from '../../../run/preparation-context-error.js';
|
|
11
12
|
import { formatCompletionNotification } from '../../../scheduler/completion-inbox.js';
|
|
12
13
|
import { GENAI, NAMZU, agentIterationSpanName, parentContext, } from '../../../telemetry/attributes.js';
|
|
13
14
|
import { getTracer } from '../../../telemetry/runtime-accessors.js';
|
|
@@ -19,6 +20,7 @@ import { classifyProviderError } from '../../../types/provider/errors.js';
|
|
|
19
20
|
import { toErrorMessage } from '../../../utils/error.js';
|
|
20
21
|
import { stableDigest } from '../../../utils/hash.js';
|
|
21
22
|
import { generateMessageId } from '../../../utils/id.js';
|
|
23
|
+
import { createCallbackInference } from '../callback-inference.js';
|
|
22
24
|
import { projectObservationContext } from '../observation-context.js';
|
|
23
25
|
import { applyLifecycleHookResults } from '../plugin-hooks.js';
|
|
24
26
|
import { diffRequestContext, snapshotRequestContext, } from '../request-context.js';
|
|
@@ -33,6 +35,18 @@ import { runToolReview } from './phases/tool-review.js';
|
|
|
33
35
|
import { refreshWorkingMemory } from './phases/working-memory.js';
|
|
34
36
|
import { streamWithProviderRejectedImageRecovery } from './provider-rejected-image.js';
|
|
35
37
|
import { streamProviderTurn } from './stream-turn.js';
|
|
38
|
+
/** A host reviewer is not the model transport, even when its cause is an HTTP failure. */
|
|
39
|
+
class AnswerReviewFailure extends NamzuError {
|
|
40
|
+
constructor(cause) {
|
|
41
|
+
super({
|
|
42
|
+
code: 'unknown',
|
|
43
|
+
message: `Answer review failed: ${toErrorMessage(cause)}`,
|
|
44
|
+
retryable: false,
|
|
45
|
+
details: { phase: 'answer-review' },
|
|
46
|
+
cause,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
36
50
|
/**
|
|
37
51
|
* How many times an answer may be handed back before the run stops.
|
|
38
52
|
*
|
|
@@ -42,6 +56,9 @@ import { streamProviderTurn } from './stream-turn.js';
|
|
|
42
56
|
* on the thing that actually went wrong.
|
|
43
57
|
*/
|
|
44
58
|
const DEFAULT_ANSWER_REVIEW_LIMIT = 3;
|
|
59
|
+
// Ending a run changes the available actions, not the strength of its evidence.
|
|
60
|
+
// Use the same standard for warning closure and empty-completion recovery.
|
|
61
|
+
const CLOSING_RESPONSE_GUIDANCE = 'Give a concise response using only what the available evidence supports. Attribute unverified statements to their source instead of presenting them as observed facts. If evidence is missing or conflicting, state what cannot be established. Do not claim unfinished work is complete. Do not request any more tool calls.';
|
|
45
62
|
/**
|
|
46
63
|
* The share of a run's REMAINING time a settle-hold may take.
|
|
47
64
|
*
|
|
@@ -101,6 +118,21 @@ export function settleGraceMs(remainingBeforeFinalizeMs) {
|
|
|
101
118
|
}
|
|
102
119
|
export class IterationOrchestrator {
|
|
103
120
|
ctx;
|
|
121
|
+
advisoryTurn;
|
|
122
|
+
/** Live only within its iteration; never joined by a guessed array offset. */
|
|
123
|
+
getAdvisoryTurnContext() {
|
|
124
|
+
const turn = this.advisoryTurn;
|
|
125
|
+
if (!turn || turn.iteration !== this.ctx.runMgr.currentIteration)
|
|
126
|
+
return undefined;
|
|
127
|
+
const start = this.ctx.runMgr.messages.indexOf(turn.response);
|
|
128
|
+
if (start < 0)
|
|
129
|
+
return undefined;
|
|
130
|
+
return {
|
|
131
|
+
iteration: turn.iteration,
|
|
132
|
+
requestMessages: turn.requestMessages,
|
|
133
|
+
subsequentMessages: this.ctx.runMgr.messages.slice(start),
|
|
134
|
+
};
|
|
135
|
+
}
|
|
104
136
|
/** Rejections so far. See {@link DEFAULT_ANSWER_REVIEW_LIMIT}. */
|
|
105
137
|
answerReviewAttempts = 0;
|
|
106
138
|
/**
|
|
@@ -143,6 +175,7 @@ export class IterationOrchestrator {
|
|
|
143
175
|
},
|
|
144
176
|
};
|
|
145
177
|
ctx.checkpointMgr.setLatestUserMessageSource(() => this.latestUserMessage);
|
|
178
|
+
ctx.checkpointMgr.setAnswerReviewAttemptsSource?.(() => this.answerReviewAttempts);
|
|
146
179
|
ctx.checkpointMgr.setStructuredReviewAttemptsSource?.(() => this.structuredReviewAttempts);
|
|
147
180
|
ctx.checkpointMgr.setNativeStructuredAttemptsSource?.(() => this.nativeStructuredAttempts);
|
|
148
181
|
if (ctx.structuredOutput?.mode === 'native') {
|
|
@@ -156,6 +189,9 @@ export class IterationOrchestrator {
|
|
|
156
189
|
const maxReviews = ctx.structuredOutput?.maxReviews;
|
|
157
190
|
if (maxReviews !== undefined && (!Number.isSafeInteger(maxReviews) || maxReviews < 0))
|
|
158
191
|
throw new RangeError('structuredOutput.maxReviews must be a nonnegative safe integer');
|
|
192
|
+
if (ctx.maxAnswerReviews !== undefined &&
|
|
193
|
+
(!Number.isSafeInteger(ctx.maxAnswerReviews) || ctx.maxAnswerReviews < 0))
|
|
194
|
+
throw new RangeError('maxAnswerReviews must be a nonnegative safe integer');
|
|
159
195
|
}
|
|
160
196
|
/**
|
|
161
197
|
* Check the exact post-budget request for tool-result shapes the active driver
|
|
@@ -233,6 +269,7 @@ export class IterationOrchestrator {
|
|
|
233
269
|
const tracer = getTracer();
|
|
234
270
|
// Resume hydration happens after construction, before the loop starts.
|
|
235
271
|
this.latestUserMessage = this.ctx.checkpointMgr.restoredLatestUserMessage;
|
|
272
|
+
this.answerReviewAttempts = this.ctx.checkpointMgr.restoredAnswerReviewAttempts ?? 0;
|
|
236
273
|
this.structuredReviewAttempts = this.ctx.checkpointMgr.restoredStructuredReviewAttempts ?? 0;
|
|
237
274
|
this.nativeStructuredAttempts = this.ctx.checkpointMgr.restoredNativeStructuredAttempts ?? 0;
|
|
238
275
|
if (!this.latestUserMessage) {
|
|
@@ -278,6 +315,11 @@ export class IterationOrchestrator {
|
|
|
278
315
|
runMgr.setStopReason('structured_output_failed');
|
|
279
316
|
break;
|
|
280
317
|
}
|
|
318
|
+
if (this.ctx.reviewAnswer &&
|
|
319
|
+
this.answerReviewAttempts > (this.ctx.maxAnswerReviews ?? DEFAULT_ANSWER_REVIEW_LIMIT)) {
|
|
320
|
+
runMgr.setStopReason('answer_rejected');
|
|
321
|
+
break;
|
|
322
|
+
}
|
|
281
323
|
if (this.ctx.structuredOutput?.review &&
|
|
282
324
|
this.structuredReviewAttempts >
|
|
283
325
|
(this.ctx.structuredOutput.maxReviews ?? DEFAULT_ANSWER_REVIEW_LIMIT)) {
|
|
@@ -434,13 +476,14 @@ export class IterationOrchestrator {
|
|
|
434
476
|
// Snapshot the cumulative counters so the step can report ITS
|
|
435
477
|
// own usage rather than the run total.
|
|
436
478
|
stepStartedAt = Date.now();
|
|
437
|
-
usageBefore = { ...runMgr.tokenUsage };
|
|
438
|
-
costBefore = { ...runMgr.costInfo };
|
|
439
479
|
// Shape this step before calling the model. `stopWhen` decides
|
|
440
480
|
// whether to keep going; this decides HOW. No-op when the host
|
|
441
481
|
// supplied no hook.
|
|
442
482
|
const contextModelBeforePreparation = this.ctx.contextModel ?? model;
|
|
443
483
|
const step = await this.prepareStep(iterationNum);
|
|
484
|
+
// Preparation inference belongs to the run, not the main-model step.
|
|
485
|
+
usageBefore = { ...runMgr.tokenUsage };
|
|
486
|
+
costBefore = { ...runMgr.costInfo };
|
|
444
487
|
stepModel = step.model ?? model;
|
|
445
488
|
await this.selectContextModel(stepModel);
|
|
446
489
|
// Preserve post-compaction preparation/recall semantics. A changed
|
|
@@ -465,7 +508,7 @@ export class IterationOrchestrator {
|
|
|
465
508
|
const baseMessages = forceFinalize
|
|
466
509
|
? [
|
|
467
510
|
...runMgr.messages,
|
|
468
|
-
createRuntimeContextMessage(
|
|
511
|
+
createRuntimeContextMessage(`[SYSTEM] You are approaching your resource limits. ${CLOSING_RESPONSE_GUIDANCE}`, 'limit-finalization'),
|
|
469
512
|
]
|
|
470
513
|
: runMgr.messages;
|
|
471
514
|
// Step guidance is appended to the REQUEST, never pushed onto
|
|
@@ -481,9 +524,9 @@ export class IterationOrchestrator {
|
|
|
481
524
|
// mutation, and per-iteration this is trivial next to the model
|
|
482
525
|
// call it precedes.
|
|
483
526
|
// A step's skills and its guidance ride the same ephemeral
|
|
484
|
-
//
|
|
485
|
-
//
|
|
486
|
-
//
|
|
527
|
+
// system message. A driver may move it before history; changing
|
|
528
|
+
// system guidance can therefore affect prefix caching. Observations
|
|
529
|
+
// that need no system authority use step.context below.
|
|
487
530
|
// `renderSkillsSection` already answers null for an empty list, so
|
|
488
531
|
// there is no length check here — a second guard for the same
|
|
489
532
|
// case is one more thing to keep in agreement with the first.
|
|
@@ -504,10 +547,9 @@ export class IterationOrchestrator {
|
|
|
504
547
|
? `Approval policy changed from "${policyChange.from}" to "${policyChange.to}" (${policyChange.reason}). Tool calls from here on are reviewed under the new policy.`
|
|
505
548
|
: null;
|
|
506
549
|
// State that changed during the run, reported once per turn.
|
|
507
|
-
// `turn` contributions
|
|
508
|
-
//
|
|
509
|
-
//
|
|
510
|
-
// exist to report goes stale silently.
|
|
550
|
+
// `turn` contributions are recomputed here, not fixed when the
|
|
551
|
+
// run's prompt is assembled. They retain system authority and
|
|
552
|
+
// may affect caching just like the other system contributions.
|
|
511
553
|
const turnSections = this.ctx.promptContributions?.render('turn', {
|
|
512
554
|
iteration: iterationNum,
|
|
513
555
|
}) ?? [];
|
|
@@ -517,7 +559,10 @@ export class IterationOrchestrator {
|
|
|
517
559
|
const requestHistory = stepPreamble
|
|
518
560
|
? [...baseMessages, createSystemMessage(stepPreamble)]
|
|
519
561
|
: [...baseMessages];
|
|
562
|
+
if (step.context)
|
|
563
|
+
requestHistory.push(this.stepContextMessage(step.context));
|
|
520
564
|
const messages = projectRequestRichContent(this.projectObservations(requestHistory), this.ctx.runConfig.maxRequestRichContentBytes ?? DEFAULT_MAX_REQUEST_RICH_CONTENT_BYTES);
|
|
565
|
+
this.appendWorkContext(messages, iterationNum, step);
|
|
521
566
|
await this.reportUnsupportedToolResults(messages);
|
|
522
567
|
yield* this.ctx.drainPending();
|
|
523
568
|
// What the model is about to be ASKED, recorded when it
|
|
@@ -619,7 +664,11 @@ export class IterationOrchestrator {
|
|
|
619
664
|
model: requestedMember.model ?? stepModel,
|
|
620
665
|
chainIndex: requestedMember.index,
|
|
621
666
|
};
|
|
622
|
-
const
|
|
667
|
+
const operatorInputAtDispatch = this.latestUserMessage;
|
|
668
|
+
const latestReviewUserMessage = (this.ctx.reviewAnswer || this.ctx.structuredOutput?.review) && operatorInputAtDispatch
|
|
669
|
+
? structuredClone(operatorInputAtDispatch)
|
|
670
|
+
: undefined;
|
|
671
|
+
const { response, messageId, requestMessages } = yield* streamProviderTurn(this.ctx.provider, {
|
|
623
672
|
model: stepModel,
|
|
624
673
|
...(this.ctx.structuredOutput?.mode === 'native'
|
|
625
674
|
? {
|
|
@@ -659,8 +708,12 @@ export class IterationOrchestrator {
|
|
|
659
708
|
signal: this.ctx.abortController.signal,
|
|
660
709
|
}, this.ctx.emitEvent, this.ctx.drainPending, runMgr.id, iterationNum, forceFinalize, this.ctx.log, iterSpan, stepMessageId, {
|
|
661
710
|
onAccepted: (identity) => this.acceptProviderRejectedImage(identity),
|
|
662
|
-
});
|
|
711
|
+
}, Boolean(this.ctx.reviewAnswer || this.ctx.structuredOutput?.review || this.ctx.advisoryCtx));
|
|
663
712
|
stepResponse = response;
|
|
713
|
+
const reviewRequest = {
|
|
714
|
+
...(requestMessages ? { requestMessages } : {}),
|
|
715
|
+
...(latestReviewUserMessage ? { latestUserMessage: latestReviewUserMessage } : {}),
|
|
716
|
+
};
|
|
664
717
|
// Who answered THIS turn.
|
|
665
718
|
//
|
|
666
719
|
// The read is exact at this point and stays exact: a chain that
|
|
@@ -668,18 +721,9 @@ export class IterationOrchestrator {
|
|
|
668
721
|
// request, so the member at the cursor when the stream ends is
|
|
669
722
|
// the one whose bytes are in `response`.
|
|
670
723
|
//
|
|
671
|
-
//
|
|
672
|
-
//
|
|
673
|
-
//
|
|
674
|
-
// fails no test, because nothing between the two asks this
|
|
675
|
-
// provider for anything: compaction and working memory run
|
|
676
|
-
// BEFORE the turn, the advisory phase runs after the step is
|
|
677
|
-
// already recorded, and the only thing in between is tool
|
|
678
|
-
// execution. That is a fact about today's phase order, which a
|
|
679
|
-
// later phase inserted here would change silently — and the
|
|
680
|
-
// symptom would be a step attributed to a member that first
|
|
681
|
-
// served the turn after it, which is the class of wrongness
|
|
682
|
-
// this whole field exists to end.
|
|
724
|
+
// Capture before host review: its auxiliary inference can move
|
|
725
|
+
// the fallback cursor. Main-step usage and provenance must keep
|
|
726
|
+
// naming the provider that produced this candidate.
|
|
683
727
|
const servedBy = (() => {
|
|
684
728
|
const member = this.ctx.servingMember?.() ?? {
|
|
685
729
|
index: 0,
|
|
@@ -780,8 +824,11 @@ export class IterationOrchestrator {
|
|
|
780
824
|
...(response.message.replayState !== undefined
|
|
781
825
|
? { replayState: response.message.replayState }
|
|
782
826
|
: {}),
|
|
783
|
-
});
|
|
827
|
+
}, response.message.textParts);
|
|
784
828
|
runMgr.pushMessage(assistantMsg);
|
|
829
|
+
if (this.ctx.advisoryCtx && requestMessages) {
|
|
830
|
+
this.advisoryTurn = { iteration: iterationNum, requestMessages, response: assistantMsg };
|
|
831
|
+
}
|
|
785
832
|
if (this.ctx.workingStateManager && this.ctx.compactionConfig && assistantMsg.content) {
|
|
786
833
|
extractFromAssistantMessage(this.ctx.workingStateManager, assistantMsg.content, this.ctx.compactionConfig);
|
|
787
834
|
}
|
|
@@ -887,7 +934,7 @@ export class IterationOrchestrator {
|
|
|
887
934
|
const candidate = await parseNativeCandidate(this.ctx.structuredOutput.schema, response, this.ctx.abortController.signal);
|
|
888
935
|
let outcome;
|
|
889
936
|
if (candidate.success)
|
|
890
|
-
outcome = await this.reviewStructuredOutput(candidate.value);
|
|
937
|
+
outcome = await this.reviewStructuredOutput(candidate.value, reviewRequest, stepModel);
|
|
891
938
|
else {
|
|
892
939
|
this.nativeStructuredAttempts++;
|
|
893
940
|
runMgr.pushMessage(createRuntimeContextMessage('Return a complete JSON value matching the supplied response schema. Do not continue a partial JSON fragment.', 'structured-output'));
|
|
@@ -1018,7 +1065,7 @@ export class IterationOrchestrator {
|
|
|
1018
1065
|
// judge: bounded attempts, feedback as a user message, and
|
|
1019
1066
|
// a loud stop rather than a loop.
|
|
1020
1067
|
if (!forceFinalize && this.ctx.reviewAnswer) {
|
|
1021
|
-
const review = await this.reviewAnswer(response.message.content ?? '');
|
|
1068
|
+
const review = await this.reviewAnswer(response.message.content ?? '', reviewRequest, stepModel);
|
|
1022
1069
|
if (this.ctx.abortController.signal.aborted) {
|
|
1023
1070
|
runMgr.setStopReason('cancelled');
|
|
1024
1071
|
runMgr.markCancelled();
|
|
@@ -1026,6 +1073,21 @@ export class IterationOrchestrator {
|
|
|
1026
1073
|
}
|
|
1027
1074
|
if (review && !review.accept) {
|
|
1028
1075
|
const attempt = ++this.answerReviewAttempts;
|
|
1076
|
+
runMgr.pushMessage(createRuntimeContextMessage(review.feedback, 'answer-review'));
|
|
1077
|
+
// Commit the consumed allowance with its feedback before another
|
|
1078
|
+
// request, including exhaustion. Compaction cannot reset this quota.
|
|
1079
|
+
const checkpoint = await this.ctx.checkpointMgr.create(runMgr, iterationNum);
|
|
1080
|
+
await this.ctx.emitEvent({
|
|
1081
|
+
type: 'checkpoint_created',
|
|
1082
|
+
runId: runMgr.id,
|
|
1083
|
+
checkpointId: checkpoint.id,
|
|
1084
|
+
iteration: iterationNum,
|
|
1085
|
+
});
|
|
1086
|
+
if (this.ctx.abortController.signal.aborted) {
|
|
1087
|
+
runMgr.setStopReason('cancelled');
|
|
1088
|
+
runMgr.markCancelled();
|
|
1089
|
+
break;
|
|
1090
|
+
}
|
|
1029
1091
|
const limit = this.ctx.maxAnswerReviews ?? DEFAULT_ANSWER_REVIEW_LIMIT;
|
|
1030
1092
|
if (attempt > limit) {
|
|
1031
1093
|
this.ctx.log.warn('Answer rejected more times than the run allows', {
|
|
@@ -1041,7 +1103,6 @@ export class IterationOrchestrator {
|
|
|
1041
1103
|
'namzu.retry.attempt': attempt,
|
|
1042
1104
|
'namzu.runtime.limit': limit,
|
|
1043
1105
|
});
|
|
1044
|
-
runMgr.pushMessage(createRuntimeContextMessage(review.feedback, 'answer-review'));
|
|
1045
1106
|
await this.ctx.emitEvent({
|
|
1046
1107
|
type: 'iteration_completed',
|
|
1047
1108
|
runId: runMgr.id,
|
|
@@ -1080,7 +1141,12 @@ export class IterationOrchestrator {
|
|
|
1080
1141
|
yield* this.ctx.drainPending();
|
|
1081
1142
|
continue;
|
|
1082
1143
|
}
|
|
1083
|
-
|
|
1144
|
+
// A limit-requested summary bypasses prose review and further
|
|
1145
|
+
// work. Preserve that limit on settlement, even if the provider
|
|
1146
|
+
// reports a normal text completion and headroom still remains.
|
|
1147
|
+
let closingStopReason = forceFinalize
|
|
1148
|
+
? guardResult.stopReason
|
|
1149
|
+
: undefined;
|
|
1084
1150
|
if (!hasContent && !forceFinalize) {
|
|
1085
1151
|
this.ctx.log.warn('Empty completion detected — requesting final summary', {
|
|
1086
1152
|
[NAMZU.ITERATION]: iterationNum,
|
|
@@ -1150,7 +1216,7 @@ export class IterationOrchestrator {
|
|
|
1150
1216
|
// run ends here rather than paying for another turn whose only
|
|
1151
1217
|
// job would be to restate it — unless it shared its turn with
|
|
1152
1218
|
// other calls, which relays instead. See the method.
|
|
1153
|
-
const structuredOutcome = await this.captureStructuredOutput(reviewOutcome.results, response);
|
|
1219
|
+
const structuredOutcome = await this.captureStructuredOutput(reviewOutcome.results, response, reviewRequest, stepModel);
|
|
1154
1220
|
if (structuredOutcome === 'retry' ||
|
|
1155
1221
|
structuredOutcome === 'exhausted' ||
|
|
1156
1222
|
structuredOutcome === 'cancelled') {
|
|
@@ -1174,10 +1240,6 @@ export class IterationOrchestrator {
|
|
|
1174
1240
|
break;
|
|
1175
1241
|
}
|
|
1176
1242
|
if (structuredOutcome === 'accepted') {
|
|
1177
|
-
this.ctx.log.info('Structured output produced — ending run', {
|
|
1178
|
-
[NAMZU.RUN_ID]: runMgr.id,
|
|
1179
|
-
[NAMZU.ITERATION]: iterationNum,
|
|
1180
|
-
});
|
|
1181
1243
|
await this.ctx.emitEvent({
|
|
1182
1244
|
type: 'iteration_completed',
|
|
1183
1245
|
runId: runMgr.id,
|
|
@@ -1190,6 +1252,22 @@ export class IterationOrchestrator {
|
|
|
1190
1252
|
runMgr.markCancelled();
|
|
1191
1253
|
break;
|
|
1192
1254
|
}
|
|
1255
|
+
if (!forceFinalize) {
|
|
1256
|
+
const inbound = this.deliverInbound();
|
|
1257
|
+
// Tool-result steering may already have been delivered by
|
|
1258
|
+
// runToolReview. Its candidate still answers the older input.
|
|
1259
|
+
if (inbound > 0 || this.latestUserMessage !== operatorInputAtDispatch)
|
|
1260
|
+
continue;
|
|
1261
|
+
}
|
|
1262
|
+
if (this.ctx.abortController.signal.aborted) {
|
|
1263
|
+
runMgr.setStopReason('cancelled');
|
|
1264
|
+
runMgr.markCancelled();
|
|
1265
|
+
break;
|
|
1266
|
+
}
|
|
1267
|
+
this.ctx.log.info('Structured output produced — ending run', {
|
|
1268
|
+
[NAMZU.RUN_ID]: runMgr.id,
|
|
1269
|
+
[NAMZU.ITERATION]: iterationNum,
|
|
1270
|
+
});
|
|
1193
1271
|
this.publishStructuredOutput();
|
|
1194
1272
|
runMgr.setStopReason('end_turn');
|
|
1195
1273
|
break;
|
|
@@ -1298,7 +1376,7 @@ export class IterationOrchestrator {
|
|
|
1298
1376
|
// the next iteration so a message queued during THIS turn is
|
|
1299
1377
|
// in the history the next request is built from.
|
|
1300
1378
|
this.deliverInbound();
|
|
1301
|
-
await runAdvisoryPhase(this.ctx, iterationNum, response);
|
|
1379
|
+
await runAdvisoryPhase(this.ctx, iterationNum, response, this.getAdvisoryTurnContext());
|
|
1302
1380
|
if (this.ctx.pluginManager) {
|
|
1303
1381
|
const hookResults = await this.ctx.pluginManager.executeHooks('iteration_end', {
|
|
1304
1382
|
runId: runMgr.id,
|
|
@@ -1411,6 +1489,7 @@ export class IterationOrchestrator {
|
|
|
1411
1489
|
// compaction means the prompt is irreducible, and looping on it
|
|
1412
1490
|
// would burn the budget to arrive at the same error.
|
|
1413
1491
|
if (!overflowRelieved &&
|
|
1492
|
+
!(err instanceof AnswerReviewFailure) &&
|
|
1414
1493
|
classifyProviderError(err, this.ctx.provider.id).code === 'context_length_exceeded') {
|
|
1415
1494
|
overflowRelieved = true;
|
|
1416
1495
|
const shed = await relieveOverflow(this.ctx);
|
|
@@ -1436,6 +1515,7 @@ export class IterationOrchestrator {
|
|
|
1436
1515
|
throw err;
|
|
1437
1516
|
}
|
|
1438
1517
|
finally {
|
|
1518
|
+
this.advisoryTurn = undefined;
|
|
1439
1519
|
// The only place the iteration span ends. It used to be ended at each of
|
|
1440
1520
|
// seventeen exits, which is a rule every future edit has to
|
|
1441
1521
|
// remember; a generator abandoned by its consumer never reached
|
|
@@ -1578,25 +1658,32 @@ export class IterationOrchestrator {
|
|
|
1578
1658
|
});
|
|
1579
1659
|
this.ctx.runMgr.pushMessage(createRuntimeContextMessage(formatCompletionNotification(unheard), 'task-completion'));
|
|
1580
1660
|
}
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1661
|
+
stepContextMessage(content) {
|
|
1662
|
+
return createRuntimeContextMessage(`Current step context (runtime-generated; not a new user request):\n${content}`, 'step-context');
|
|
1663
|
+
}
|
|
1664
|
+
/** Derived after request projection; never accumulates in canonical history or replaces operator intent. */
|
|
1665
|
+
appendWorkContext(messages, stepNumber, prepared) {
|
|
1666
|
+
const contributions = [
|
|
1667
|
+
this.ctx.completionInbox?.describeOwnedWork(),
|
|
1668
|
+
this.ctx.toolExecutor.describeFileEvidence(messages),
|
|
1669
|
+
].filter((content) => Boolean(content));
|
|
1670
|
+
if (contributions.length === 0)
|
|
1671
|
+
return;
|
|
1672
|
+
let room = this.stepContext(stepNumber, prepared).contextBudget?.remainingTokens ?? 0;
|
|
1673
|
+
// Leave room for the actual task; admit whole contributions, never dangling partial references.
|
|
1674
|
+
if (room < 1_500)
|
|
1675
|
+
return;
|
|
1676
|
+
for (const content of contributions) {
|
|
1677
|
+
if (!content || content.length > 8_000)
|
|
1678
|
+
continue;
|
|
1679
|
+
const message = this.stepContextMessage(content);
|
|
1680
|
+
const tokens = estimateMessageTokens(message);
|
|
1681
|
+
if (tokens > Math.min(2_000, room - 1_000))
|
|
1682
|
+
continue;
|
|
1683
|
+
messages.push(message);
|
|
1684
|
+
room -= tokens;
|
|
1685
|
+
}
|
|
1686
|
+
}
|
|
1600
1687
|
stepContext(stepNumber, prepared) {
|
|
1601
1688
|
const model = prepared.model ?? this.ctx.runConfig.model;
|
|
1602
1689
|
const window = resolveContextWindow(this.ctx.compactionConfig?.contextWindowTokens, model, model === this.ctx.runConfig.model
|
|
@@ -1606,7 +1693,8 @@ export class IterationOrchestrator {
|
|
|
1606
1693
|
: undefined);
|
|
1607
1694
|
const skills = prepared.skills ? renderSkillsSection([...prepared.skills]) : null;
|
|
1608
1695
|
const preamble = [prepared.system, skills].filter(Boolean).join('\n\n');
|
|
1609
|
-
const preparedTokens = preamble ? estimateMessageTokens(createSystemMessage(preamble)) : 0
|
|
1696
|
+
const preparedTokens = (preamble ? estimateMessageTokens(createSystemMessage(preamble)) : 0) +
|
|
1697
|
+
(prepared.context ? estimateMessageTokens(this.stepContextMessage(prepared.context)) : 0);
|
|
1610
1698
|
const responseReserve = Math.min(prepared.maxResponseTokens ??
|
|
1611
1699
|
this.ctx.runConfig.maxResponseTokens ??
|
|
1612
1700
|
Math.floor(window.tokens / 4), Math.floor(window.tokens / 4));
|
|
@@ -1614,6 +1702,7 @@ export class IterationOrchestrator {
|
|
|
1614
1702
|
runId: this.ctx.runMgr.id,
|
|
1615
1703
|
stepNumber,
|
|
1616
1704
|
messages: this.ctx.runMgr.messages,
|
|
1705
|
+
...(this.ctx.captureRunEvidence ? { captureRunEvidence: this.ctx.captureRunEvidence } : {}),
|
|
1617
1706
|
...(this.latestUserMessage ? { latestUserMessage: this.latestUserMessage } : {}),
|
|
1618
1707
|
signal: this.ctx.abortController.signal,
|
|
1619
1708
|
contextBudget: {
|
|
@@ -1624,6 +1713,7 @@ export class IterationOrchestrator {
|
|
|
1624
1713
|
prepared,
|
|
1625
1714
|
};
|
|
1626
1715
|
}
|
|
1716
|
+
/** Refuse the next call on a veto or hook error; do not skip a failed admission check. */
|
|
1627
1717
|
async beforeStep(stepNumber) {
|
|
1628
1718
|
const configured = this.ctx.beforeStep;
|
|
1629
1719
|
if (!configured)
|
|
@@ -1635,6 +1725,7 @@ export class IterationOrchestrator {
|
|
|
1635
1725
|
return { reason: `beforeStep threw: ${toErrorMessage(err)}` };
|
|
1636
1726
|
}
|
|
1637
1727
|
}
|
|
1728
|
+
/** Shape the next request. A failed tuning stage is skipped; admission belongs to beforeStep. */
|
|
1638
1729
|
async prepareStep(stepNumber) {
|
|
1639
1730
|
const configured = this.ctx.prepareStep;
|
|
1640
1731
|
if (!configured)
|
|
@@ -1646,8 +1737,12 @@ export class IterationOrchestrator {
|
|
|
1646
1737
|
// rather than an accident of install history.
|
|
1647
1738
|
let result = {};
|
|
1648
1739
|
for (const stage of stages) {
|
|
1740
|
+
const inference = createCallbackInference(this.ctx, result.model ?? this.ctx.runConfig.model, 'preparation');
|
|
1649
1741
|
try {
|
|
1650
|
-
const decided = await stage(
|
|
1742
|
+
const decided = await stage({
|
|
1743
|
+
...this.stepContext(stepNumber, result),
|
|
1744
|
+
generateText: inference.generateText,
|
|
1745
|
+
});
|
|
1651
1746
|
if (decided)
|
|
1652
1747
|
result = { ...result, ...decided };
|
|
1653
1748
|
await this.selectContextModel(result.model ?? this.ctx.runConfig.model);
|
|
@@ -1660,6 +1755,22 @@ export class IterationOrchestrator {
|
|
|
1660
1755
|
'namzu.runtime.step_number': stepNumber,
|
|
1661
1756
|
'exception.message': toErrorMessage(err),
|
|
1662
1757
|
});
|
|
1758
|
+
// An SDK stage may report availability and validated fallback evidence
|
|
1759
|
+
// without exposing its error. Preserve prior decisions and the context budget;
|
|
1760
|
+
// ordinary exceptions still contribute nothing to the model request.
|
|
1761
|
+
if (err instanceof PreparationContextError && !this.ctx.abortController.signal.aborted) {
|
|
1762
|
+
const room = this.stepContext(stepNumber, result).contextBudget?.remainingTokens ?? 0;
|
|
1763
|
+
if (typeof err.context === 'string' &&
|
|
1764
|
+
err.context.length > 0 &&
|
|
1765
|
+
err.context.length + (result.context ? 2 : 0) <= Math.min(12_000, Math.floor(room)))
|
|
1766
|
+
result = {
|
|
1767
|
+
...result,
|
|
1768
|
+
context: [result.context, err.context].filter(Boolean).join('\n\n'),
|
|
1769
|
+
};
|
|
1770
|
+
}
|
|
1771
|
+
}
|
|
1772
|
+
finally {
|
|
1773
|
+
inference.close();
|
|
1663
1774
|
}
|
|
1664
1775
|
}
|
|
1665
1776
|
const prepared = {};
|
|
@@ -1696,6 +1807,8 @@ export class IterationOrchestrator {
|
|
|
1696
1807
|
prepared.model = result.model;
|
|
1697
1808
|
if (result.system !== undefined)
|
|
1698
1809
|
prepared.system = result.system;
|
|
1810
|
+
if (result.context !== undefined)
|
|
1811
|
+
prepared.context = result.context;
|
|
1699
1812
|
if (result.skills !== undefined)
|
|
1700
1813
|
prepared.skills = result.skills;
|
|
1701
1814
|
if (result.temperature !== undefined)
|
|
@@ -1937,7 +2050,7 @@ export class IterationOrchestrator {
|
|
|
1937
2050
|
* doing work, and it is the bound the neighbour relies on for the
|
|
1938
2051
|
* identical pathology.
|
|
1939
2052
|
*/
|
|
1940
|
-
async captureStructuredOutput(results, response) {
|
|
2053
|
+
async captureStructuredOutput(results, response, reviewRequest, model) {
|
|
1941
2054
|
if (!this.needsStructuredOutput() || this.ctx.structuredOutput?.mode === 'native')
|
|
1942
2055
|
return 'absent';
|
|
1943
2056
|
const hit = results.find((r) => r.toolName === STRUCTURED_OUTPUT_TOOL_NAME && !r.isError);
|
|
@@ -1962,13 +2075,13 @@ export class IterationOrchestrator {
|
|
|
1962
2075
|
throw new Error('Structured review requires an intact JSON tool result; check tool-output limits and result transformations');
|
|
1963
2076
|
parsed = hit.output;
|
|
1964
2077
|
}
|
|
1965
|
-
return this.reviewStructuredOutput(parsed);
|
|
2078
|
+
return this.reviewStructuredOutput(parsed, reviewRequest, model);
|
|
1966
2079
|
}
|
|
1967
2080
|
publishStructuredOutput() {
|
|
1968
2081
|
this.ctx.runMgr.setStructuredOutput(this.pendingStructuredOutput);
|
|
1969
2082
|
this.structuredOutputDone = true;
|
|
1970
2083
|
}
|
|
1971
|
-
async reviewStructuredOutput(parsed) {
|
|
2084
|
+
async reviewStructuredOutput(parsed, reviewRequest, model) {
|
|
1972
2085
|
if (this.ctx.abortController.signal.aborted)
|
|
1973
2086
|
return 'cancelled';
|
|
1974
2087
|
const reviewer = this.ctx.structuredOutput?.review;
|
|
@@ -1982,14 +2095,20 @@ export class IterationOrchestrator {
|
|
|
1982
2095
|
signal.addEventListener('abort', onAbort, { once: true });
|
|
1983
2096
|
});
|
|
1984
2097
|
let verdict;
|
|
2098
|
+
const inference = createCallbackInference(this.ctx, model, 'review');
|
|
1985
2099
|
try {
|
|
1986
2100
|
verdict = await Promise.race([
|
|
1987
|
-
Promise.resolve().then(() =>
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
2101
|
+
Promise.resolve().then(() => {
|
|
2102
|
+
signal.throwIfAborted();
|
|
2103
|
+
return reviewer(structuredClone(parsed), {
|
|
2104
|
+
runId: this.ctx.runMgr.id,
|
|
2105
|
+
iteration: this.ctx.runMgr.currentIteration,
|
|
2106
|
+
signal,
|
|
2107
|
+
messages: this.ctx.runMgr.messages,
|
|
2108
|
+
...reviewRequest,
|
|
2109
|
+
generateText: inference.generateText,
|
|
2110
|
+
});
|
|
2111
|
+
}),
|
|
1993
2112
|
aborted,
|
|
1994
2113
|
]);
|
|
1995
2114
|
}
|
|
@@ -1999,6 +2118,7 @@ export class IterationOrchestrator {
|
|
|
1999
2118
|
throw error;
|
|
2000
2119
|
}
|
|
2001
2120
|
finally {
|
|
2121
|
+
inference.close();
|
|
2002
2122
|
signal.removeEventListener('abort', onAbort);
|
|
2003
2123
|
}
|
|
2004
2124
|
if (signal.aborted)
|
|
@@ -2030,35 +2150,49 @@ export class IterationOrchestrator {
|
|
|
2030
2150
|
this.pendingStructuredOutput = parsed;
|
|
2031
2151
|
return 'accepted';
|
|
2032
2152
|
}
|
|
2033
|
-
/**
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
* dangerous", where the cost of failing closed is one refused
|
|
2039
|
-
* operation. This is asked "is this good enough", where failing closed
|
|
2040
|
-
* means handing the answer back forever — so a broken judge would turn
|
|
2041
|
-
* every run into a loop that ends on a budget error naming nothing. One
|
|
2042
|
-
* unreviewed answer is the cheaper failure, and the throw is logged at
|
|
2043
|
-
* `error` so it is not mistaken for approval.
|
|
2044
|
-
*/
|
|
2045
|
-
async reviewAnswer(answer) {
|
|
2046
|
-
if (!this.ctx.reviewAnswer)
|
|
2153
|
+
/** A reviewer failure aborts settlement; only an explicit rejection requests correction. */
|
|
2154
|
+
async reviewAnswer(answer, reviewRequest, model) {
|
|
2155
|
+
const reviewer = this.ctx.reviewAnswer;
|
|
2156
|
+
const signal = this.ctx.abortController.signal;
|
|
2157
|
+
if (!reviewer || signal.aborted)
|
|
2047
2158
|
return undefined;
|
|
2159
|
+
let onAbort = () => { };
|
|
2160
|
+
const aborted = new Promise((_resolve, reject) => {
|
|
2161
|
+
onAbort = () => reject(signal.reason ?? new Error('Answer review cancelled'));
|
|
2162
|
+
signal.addEventListener('abort', onAbort, { once: true });
|
|
2163
|
+
});
|
|
2164
|
+
const inference = createCallbackInference(this.ctx, model, 'review');
|
|
2048
2165
|
try {
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2166
|
+
const verdict = await Promise.race([
|
|
2167
|
+
Promise.resolve().then(() => {
|
|
2168
|
+
signal.throwIfAborted();
|
|
2169
|
+
return reviewer(answer, {
|
|
2170
|
+
runId: this.ctx.runMgr.id,
|
|
2171
|
+
iteration: this.ctx.runMgr.currentIteration,
|
|
2172
|
+
signal,
|
|
2173
|
+
messages: this.ctx.runMgr.messages,
|
|
2174
|
+
...reviewRequest,
|
|
2175
|
+
generateText: inference.generateText,
|
|
2176
|
+
});
|
|
2177
|
+
}),
|
|
2178
|
+
aborted,
|
|
2179
|
+
]);
|
|
2180
|
+
if (signal.aborted)
|
|
2181
|
+
return undefined;
|
|
2182
|
+
if (!verdict || typeof verdict.accept !== 'boolean')
|
|
2183
|
+
throw new Error('Answer reviewer returned an invalid verdict');
|
|
2184
|
+
if (!verdict.accept && (typeof verdict.feedback !== 'string' || !verdict.feedback.trim()))
|
|
2185
|
+
throw new Error('Answer reviewer rejection requires feedback');
|
|
2186
|
+
return verdict;
|
|
2055
2187
|
}
|
|
2056
|
-
catch (
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2188
|
+
catch (error) {
|
|
2189
|
+
if (signal.aborted)
|
|
2190
|
+
return undefined;
|
|
2191
|
+
throw new AnswerReviewFailure(error);
|
|
2192
|
+
}
|
|
2193
|
+
finally {
|
|
2194
|
+
inference.close();
|
|
2195
|
+
signal.removeEventListener('abort', onAbort);
|
|
2062
2196
|
}
|
|
2063
2197
|
}
|
|
2064
2198
|
/** Evaluate the caller's halt predicate, if there is one. */
|
|
@@ -2131,9 +2265,10 @@ export class IterationOrchestrator {
|
|
|
2131
2265
|
try {
|
|
2132
2266
|
const finalHistory = [
|
|
2133
2267
|
...this.ctx.runMgr.messages,
|
|
2134
|
-
createRuntimeContextMessage(`[SYSTEM] Run is ending due to ${reason}.
|
|
2268
|
+
createRuntimeContextMessage(`[SYSTEM] Run is ending due to ${reason}. ${CLOSING_RESPONSE_GUIDANCE}`, 'limit-finalization'),
|
|
2135
2269
|
];
|
|
2136
2270
|
const finalMessages = projectRequestRichContent(this.projectObservations(finalHistory), this.ctx.runConfig.maxRequestRichContentBytes ?? DEFAULT_MAX_REQUEST_RICH_CONTENT_BYTES);
|
|
2271
|
+
this.appendWorkContext(finalMessages, this.steps.length + 1, { model });
|
|
2137
2272
|
await this.reportUnsupportedToolResults(finalMessages);
|
|
2138
2273
|
// Same cache discipline as the forced-final iteration: keep the
|
|
2139
2274
|
// tools param identical to prior iterations (cache prefix intact,
|
|
@@ -2185,7 +2320,7 @@ export class IterationOrchestrator {
|
|
|
2185
2320
|
...(response.message.replayState !== undefined
|
|
2186
2321
|
? { replayState: response.message.replayState }
|
|
2187
2322
|
: {}),
|
|
2188
|
-
});
|
|
2323
|
+
}, response.message.textParts);
|
|
2189
2324
|
this.ctx.runMgr.pushMessage(assistantMsg);
|
|
2190
2325
|
const finalMessageId = generateMessageId();
|
|
2191
2326
|
await this.ctx.emitEvent({
|
|
@@ -2202,6 +2337,7 @@ export class IterationOrchestrator {
|
|
|
2202
2337
|
stopReason: 'forced_finalize',
|
|
2203
2338
|
usage: response.usage,
|
|
2204
2339
|
content: response.message.content ?? undefined,
|
|
2340
|
+
...(response.message.textParts ? { textParts: response.message.textParts } : {}),
|
|
2205
2341
|
});
|
|
2206
2342
|
}
|
|
2207
2343
|
catch (err) {
|
|
@@ -2223,6 +2359,8 @@ export class IterationOrchestrator {
|
|
|
2223
2359
|
* threw and is left saying so rather than dressed up as something specific.
|
|
2224
2360
|
*/
|
|
2225
2361
|
function describeStepFailure(err, providerId) {
|
|
2362
|
+
if (err instanceof AnswerReviewFailure)
|
|
2363
|
+
return { message: err.message, code: 'unknown', retryable: false };
|
|
2226
2364
|
const classified = classifyProviderError(err, providerId);
|
|
2227
2365
|
return {
|
|
2228
2366
|
message: toErrorMessage(err),
|