@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,312 @@
|
|
|
1
|
+
import { z } from 'zod'
|
|
2
|
+
import type { ResidentAgendaState } from './agenda.js'
|
|
3
|
+
import { ResidentHistoryPageLimit, type ResidentHistoryReadBudget } from './history-disk.js'
|
|
4
|
+
|
|
5
|
+
const SCAN_BYTES = 8 * 1024 * 1024
|
|
6
|
+
const SCAN_REVISIONS = 32
|
|
7
|
+
const TEXT_PAGE_CHARS = 6_000
|
|
8
|
+
|
|
9
|
+
/** @experimental Host-bound historical scope; the upper revision never advances implicitly. */
|
|
10
|
+
export interface ResidentHistoryScope {
|
|
11
|
+
readonly tenantId: string
|
|
12
|
+
readonly agentKey: string
|
|
13
|
+
readonly pursuitId: string
|
|
14
|
+
readonly throughRevision: number
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** @experimental Revision plus part identifies retained text within one pursuit. */
|
|
18
|
+
export interface ResidentHistoryAddress {
|
|
19
|
+
readonly revision: number
|
|
20
|
+
readonly part: number
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** @experimental Summary or accepted wake input from a settled historical step. */
|
|
24
|
+
export interface ResidentHistoryMatch extends ResidentHistoryAddress {
|
|
25
|
+
readonly step: number
|
|
26
|
+
readonly claimId: string
|
|
27
|
+
readonly kind: 'wait' | 'complete' | 'blocked'
|
|
28
|
+
readonly source: 'summary' | 'wake'
|
|
29
|
+
readonly excerpt: string
|
|
30
|
+
readonly matchingParts: readonly number[]
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** @experimental Empty query browses recent steps; cursor is the next inclusive revision. */
|
|
34
|
+
export interface ResidentHistorySearchOptions {
|
|
35
|
+
/** Optional per-call ceiling, 1 byte–8 MiB. Defaults to 8 MiB. */
|
|
36
|
+
readonly maxReadBytes?: number
|
|
37
|
+
readonly query?: string
|
|
38
|
+
readonly cursor?: number
|
|
39
|
+
readonly limit?: number
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** @experimental Counts describe this page, not the whole history. */
|
|
43
|
+
export interface ResidentHistorySearchResult {
|
|
44
|
+
readonly matches: readonly ResidentHistoryMatch[]
|
|
45
|
+
readonly nextCursor: number | null
|
|
46
|
+
readonly scannedRevisions: number
|
|
47
|
+
readonly scannedBytes: number
|
|
48
|
+
readonly unavailableRevisions: readonly number[]
|
|
49
|
+
readonly incomplete: boolean
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** @experimental Use the returned nextOffset to continue exact Unicode-safe text. */
|
|
53
|
+
export interface ResidentHistoryReadOptions extends ResidentHistoryAddress {
|
|
54
|
+
readonly offset?: number
|
|
55
|
+
/** Optional per-call ceiling, 1 byte–8 MiB. Defaults to 8 MiB. */
|
|
56
|
+
readonly maxReadBytes?: number
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** @experimental A recorded claim remains historical evidence, not proof of current validity. */
|
|
60
|
+
export interface ResidentHistoryText extends ResidentHistoryAddress {
|
|
61
|
+
readonly step: number
|
|
62
|
+
readonly claimId: string
|
|
63
|
+
readonly kind: 'wait' | 'complete' | 'blocked'
|
|
64
|
+
readonly source: 'summary' | 'wake'
|
|
65
|
+
readonly receivedAt?: number
|
|
66
|
+
readonly text: string
|
|
67
|
+
readonly offset: number
|
|
68
|
+
readonly totalChars: number
|
|
69
|
+
readonly nextOffset: number | null
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** @experimental Null with unavailable revisions means unreadable evidence, not proven absence. */
|
|
73
|
+
export interface ResidentHistoryReadResult {
|
|
74
|
+
readonly entry: ResidentHistoryText | null
|
|
75
|
+
readonly scannedRevisions: number
|
|
76
|
+
readonly scannedBytes: number
|
|
77
|
+
readonly unavailableRevisions: readonly number[]
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** @experimental A backend must enforce its bound scope and bounded reads. */
|
|
81
|
+
export interface ResidentHistorySource {
|
|
82
|
+
readonly scope: ResidentHistoryScope
|
|
83
|
+
search(
|
|
84
|
+
options?: ResidentHistorySearchOptions,
|
|
85
|
+
signal?: AbortSignal,
|
|
86
|
+
): Promise<ResidentHistorySearchResult>
|
|
87
|
+
read(
|
|
88
|
+
options: ResidentHistoryReadOptions,
|
|
89
|
+
signal?: AbortSignal,
|
|
90
|
+
): Promise<ResidentHistoryReadResult>
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
type LoadRevision = (
|
|
94
|
+
revision: number,
|
|
95
|
+
budget: ResidentHistoryReadBudget,
|
|
96
|
+
) => Promise<ResidentAgendaState>
|
|
97
|
+
interface Part {
|
|
98
|
+
source: 'summary' | 'wake'
|
|
99
|
+
text: string
|
|
100
|
+
receivedAt?: number
|
|
101
|
+
}
|
|
102
|
+
interface Episode {
|
|
103
|
+
step: number
|
|
104
|
+
claimId: string
|
|
105
|
+
kind: 'wait' | 'complete' | 'blocked'
|
|
106
|
+
parts: Part[]
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function episode(
|
|
110
|
+
before: ResidentAgendaState | null,
|
|
111
|
+
after: ResidentAgendaState | null,
|
|
112
|
+
id: string,
|
|
113
|
+
): Episode | null {
|
|
114
|
+
const previous = before?.pursuits.find((p) => p.id === id)?.state
|
|
115
|
+
const current = after?.pursuits.find((p) => p.id === id)?.state
|
|
116
|
+
if (
|
|
117
|
+
!before ||
|
|
118
|
+
!after ||
|
|
119
|
+
!previous ||
|
|
120
|
+
!current ||
|
|
121
|
+
previous.phase !== 'running' ||
|
|
122
|
+
!previous.claimId ||
|
|
123
|
+
current.phase === 'running' ||
|
|
124
|
+
current.claimId !== null ||
|
|
125
|
+
current.summary === null ||
|
|
126
|
+
current.stepsAdmitted !== previous.stepsAdmitted ||
|
|
127
|
+
current.revision !== previous.revision + 1
|
|
128
|
+
)
|
|
129
|
+
return null
|
|
130
|
+
return {
|
|
131
|
+
step: current.stepsAdmitted,
|
|
132
|
+
claimId: previous.claimId,
|
|
133
|
+
kind: current.phase === 'waiting' ? 'wait' : current.phase,
|
|
134
|
+
parts: [
|
|
135
|
+
{ source: 'summary', text: current.summary },
|
|
136
|
+
...(previous.wakeEvidence ?? []).map((entry) => ({
|
|
137
|
+
source: 'wake' as const,
|
|
138
|
+
text: entry.reason,
|
|
139
|
+
receivedAt: entry.receivedAt,
|
|
140
|
+
})),
|
|
141
|
+
],
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function boundary(text: string, offset: number): boolean {
|
|
146
|
+
const current = text.charCodeAt(offset)
|
|
147
|
+
const previous = text.charCodeAt(offset - 1)
|
|
148
|
+
return !(current >= 0xdc00 && current <= 0xdfff && previous >= 0xd800 && previous <= 0xdbff)
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function textSlice(text: string, offset: number, maxChars: number): string {
|
|
152
|
+
let end = Math.min(text.length, offset + maxChars)
|
|
153
|
+
if (!boundary(text, end)) end--
|
|
154
|
+
return text.slice(offset, end)
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** Internal disk adapter. Other backends may implement ResidentHistorySource directly. */
|
|
158
|
+
export function createResidentHistorySource(
|
|
159
|
+
scopeInput: ResidentHistoryScope,
|
|
160
|
+
identity: { identity: string; objective: string },
|
|
161
|
+
load: LoadRevision,
|
|
162
|
+
): ResidentHistorySource {
|
|
163
|
+
const scope = Object.freeze({ ...scopeInput })
|
|
164
|
+
const expected = { ...identity }
|
|
165
|
+
const revisionSchema = z.number().int().min(1).max(scope.throughRevision).safe()
|
|
166
|
+
function page(signal: AbortSignal | undefined, requestedBytes: number | undefined) {
|
|
167
|
+
const limit = z
|
|
168
|
+
.number()
|
|
169
|
+
.int()
|
|
170
|
+
.min(1)
|
|
171
|
+
.max(SCAN_BYTES)
|
|
172
|
+
.parse(requestedBytes ?? SCAN_BYTES)
|
|
173
|
+
const budget: ResidentHistoryReadBudget = { remaining: limit, bytesRead: 0, signal }
|
|
174
|
+
const unavailable = new Set<number>()
|
|
175
|
+
let scanned = 0
|
|
176
|
+
const cache = new Map<number, ResidentAgendaState | null>()
|
|
177
|
+
return {
|
|
178
|
+
budget,
|
|
179
|
+
async load(revision: number) {
|
|
180
|
+
signal?.throwIfAborted()
|
|
181
|
+
if (cache.has(revision)) return cache.get(revision) ?? null
|
|
182
|
+
if (scanned >= SCAN_REVISIONS) throw new ResidentHistoryPageLimit()
|
|
183
|
+
scanned++
|
|
184
|
+
let record: ResidentAgendaState | null = null
|
|
185
|
+
try {
|
|
186
|
+
record = await load(revision, budget)
|
|
187
|
+
const pursuit = record.pursuits.find((p) => p.id === scope.pursuitId)
|
|
188
|
+
if (
|
|
189
|
+
record.revision !== revision ||
|
|
190
|
+
record.tenantId !== scope.tenantId ||
|
|
191
|
+
record.agentKey !== scope.agentKey ||
|
|
192
|
+
(pursuit &&
|
|
193
|
+
(pursuit.state.identity !== expected.identity ||
|
|
194
|
+
pursuit.state.objective !== expected.objective))
|
|
195
|
+
)
|
|
196
|
+
throw new Error('History identity does not match its bound pursuit.')
|
|
197
|
+
} catch (error) {
|
|
198
|
+
signal?.throwIfAborted()
|
|
199
|
+
if (error instanceof ResidentHistoryPageLimit) throw error
|
|
200
|
+
unavailable.add(revision)
|
|
201
|
+
record = null
|
|
202
|
+
}
|
|
203
|
+
// Adjacent revisions are reused on the next scan iteration, without
|
|
204
|
+
// keeping the whole archive in memory.
|
|
205
|
+
if (cache.size >= 2) cache.delete(cache.keys().next().value as number)
|
|
206
|
+
cache.set(revision, record)
|
|
207
|
+
return record
|
|
208
|
+
},
|
|
209
|
+
counts: () => ({
|
|
210
|
+
scannedRevisions: scanned,
|
|
211
|
+
scannedBytes: budget.bytesRead,
|
|
212
|
+
unavailableRevisions: [...unavailable],
|
|
213
|
+
}),
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
return Object.freeze({
|
|
217
|
+
scope,
|
|
218
|
+
async search(options: ResidentHistorySearchOptions = {}, signal?: AbortSignal) {
|
|
219
|
+
signal?.throwIfAborted()
|
|
220
|
+
const query = z
|
|
221
|
+
.string()
|
|
222
|
+
.max(256)
|
|
223
|
+
.parse(options.query ?? '')
|
|
224
|
+
const limit = z
|
|
225
|
+
.number()
|
|
226
|
+
.int()
|
|
227
|
+
.min(1)
|
|
228
|
+
.max(8)
|
|
229
|
+
.parse(options.limit ?? 5)
|
|
230
|
+
let revision = revisionSchema.parse(options.cursor ?? scope.throughRevision)
|
|
231
|
+
const reader = page(signal, options.maxReadBytes)
|
|
232
|
+
const matches: ResidentHistoryMatch[] = []
|
|
233
|
+
while (revision >= 2 && matches.length < limit) {
|
|
234
|
+
let found: Episode | null
|
|
235
|
+
try {
|
|
236
|
+
const after = await reader.load(revision)
|
|
237
|
+
const before = await reader.load(revision - 1)
|
|
238
|
+
found = episode(before, after, scope.pursuitId)
|
|
239
|
+
} catch (error) {
|
|
240
|
+
if (!(error instanceof ResidentHistoryPageLimit)) throw error
|
|
241
|
+
break
|
|
242
|
+
}
|
|
243
|
+
if (found) {
|
|
244
|
+
const matchingParts = found.parts.flatMap((part, index) =>
|
|
245
|
+
part.text.includes(query) ? [index] : [],
|
|
246
|
+
)
|
|
247
|
+
const part = matchingParts[0]
|
|
248
|
+
const matched = part === undefined ? undefined : found.parts[part]
|
|
249
|
+
if (matched && part !== undefined) {
|
|
250
|
+
let start = Math.max(0, matched.text.indexOf(query) - 120)
|
|
251
|
+
if (!boundary(matched.text, start)) start--
|
|
252
|
+
matches.push({
|
|
253
|
+
revision,
|
|
254
|
+
part,
|
|
255
|
+
step: found.step,
|
|
256
|
+
claimId: found.claimId,
|
|
257
|
+
kind: found.kind,
|
|
258
|
+
source: matched.source,
|
|
259
|
+
excerpt: textSlice(matched.text, start, 512),
|
|
260
|
+
matchingParts,
|
|
261
|
+
})
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
revision--
|
|
265
|
+
}
|
|
266
|
+
const nextCursor = revision >= 2 ? revision : null
|
|
267
|
+
const counts = reader.counts()
|
|
268
|
+
return {
|
|
269
|
+
matches,
|
|
270
|
+
nextCursor,
|
|
271
|
+
...counts,
|
|
272
|
+
incomplete: nextCursor !== null || counts.unavailableRevisions.length > 0,
|
|
273
|
+
}
|
|
274
|
+
},
|
|
275
|
+
async read(options: ResidentHistoryReadOptions, signal?: AbortSignal) {
|
|
276
|
+
const revision = revisionSchema.parse(options.revision)
|
|
277
|
+
const part = z.number().int().min(0).max(16).parse(options.part)
|
|
278
|
+
const offset = z
|
|
279
|
+
.number()
|
|
280
|
+
.int()
|
|
281
|
+
.nonnegative()
|
|
282
|
+
.safe()
|
|
283
|
+
.parse(options.offset ?? 0)
|
|
284
|
+
const reader = page(signal, options.maxReadBytes)
|
|
285
|
+
const after = await reader.load(revision)
|
|
286
|
+
const before = revision >= 2 ? await reader.load(revision - 1) : null
|
|
287
|
+
const found = episode(before, after, scope.pursuitId)
|
|
288
|
+
const selected = found?.parts[part]
|
|
289
|
+
if (!selected || !found) return { entry: null, ...reader.counts() }
|
|
290
|
+
if (offset > selected.text.length || !boundary(selected.text, offset))
|
|
291
|
+
throw new Error('Invalid retained text offset; use nextOffset from the previous page.')
|
|
292
|
+
const text = textSlice(selected.text, offset, TEXT_PAGE_CHARS)
|
|
293
|
+
const end = offset + text.length
|
|
294
|
+
return {
|
|
295
|
+
entry: {
|
|
296
|
+
revision,
|
|
297
|
+
part,
|
|
298
|
+
step: found.step,
|
|
299
|
+
claimId: found.claimId,
|
|
300
|
+
kind: found.kind,
|
|
301
|
+
source: selected.source,
|
|
302
|
+
...(selected.receivedAt !== undefined ? { receivedAt: selected.receivedAt } : {}),
|
|
303
|
+
text,
|
|
304
|
+
offset,
|
|
305
|
+
totalChars: selected.text.length,
|
|
306
|
+
nextOffset: end < selected.text.length ? end : null,
|
|
307
|
+
},
|
|
308
|
+
...reader.counts(),
|
|
309
|
+
}
|
|
310
|
+
},
|
|
311
|
+
})
|
|
312
|
+
}
|
|
@@ -103,6 +103,18 @@ export interface ResidentSelection {
|
|
|
103
103
|
/** @experimental Pure local selection; perform inference inside budgeted steps, not here. */
|
|
104
104
|
export type ResidentSelector = (agenda: ResidentAgendaState, now: number) => ResidentSelection
|
|
105
105
|
|
|
106
|
+
function meanObservedCost(observations: readonly ResidentObservation[]): number {
|
|
107
|
+
// Null costs are rejected before this function. Scale by the largest finite
|
|
108
|
+
// observation: the intermediate sum is at most eight, even near MAX_VALUE.
|
|
109
|
+
const scale = Math.max(...observations.map((item) => item.costUnits ?? 0))
|
|
110
|
+
if (scale === 0) return 0
|
|
111
|
+
return (
|
|
112
|
+
(observations.reduce((total, item) => total + (item.costUnits ?? 0) / scale, 0) /
|
|
113
|
+
observations.length) *
|
|
114
|
+
scale
|
|
115
|
+
)
|
|
116
|
+
}
|
|
117
|
+
|
|
106
118
|
/**
|
|
107
119
|
* @experimental Cost-aware continuation with an explicit abstention choice.
|
|
108
120
|
* This is a measured-progress heuristic, not Bayesian value of computation.
|
|
@@ -162,9 +174,7 @@ export function createResidentSelector(config: ResidentSelectionConfig): Residen
|
|
|
162
174
|
? policy.initialExpectedProgress
|
|
163
175
|
: (totalGain + policy.initialExpectedProgress) / (recent.length + 1)
|
|
164
176
|
const expectedCost =
|
|
165
|
-
recent.length === 0
|
|
166
|
-
? policy.initialExpectedCost
|
|
167
|
-
: recent.reduce((total, item) => total + (item.costUnits ?? 0), 0) / recent.length
|
|
177
|
+
recent.length === 0 ? policy.initialExpectedCost : meanObservedCost(recent)
|
|
168
178
|
const score = policy.progressValue * expectedGain - expectedCost
|
|
169
179
|
return {
|
|
170
180
|
pursuitId: p.id,
|