@namzu/sdk 72.0.0 → 74.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 +61 -0
- package/README.md +34 -34
- package/dist/agents/examples/SupervisorAgent.d.ts.map +1 -1
- package/dist/agents/examples/SupervisorAgent.js +5 -0
- package/dist/agents/examples/SupervisorAgent.js.map +1 -1
- package/dist/authorization/protected-paths.d.ts +7 -0
- package/dist/authorization/protected-paths.d.ts.map +1 -1
- package/dist/authorization/protected-paths.js +11 -0
- package/dist/authorization/protected-paths.js.map +1 -1
- package/dist/authorization/readonly-commands.d.ts +23 -0
- package/dist/authorization/readonly-commands.d.ts.map +1 -1
- package/dist/authorization/readonly-commands.js +89 -3
- package/dist/authorization/readonly-commands.js.map +1 -1
- package/dist/authorization/shell-paths.d.ts +8 -0
- package/dist/authorization/shell-paths.d.ts.map +1 -1
- package/dist/authorization/shell-paths.js +125 -2
- package/dist/authorization/shell-paths.js.map +1 -1
- package/dist/bridge/acp/permission.d.ts +6 -0
- package/dist/bridge/acp/permission.d.ts.map +1 -1
- package/dist/bridge/acp/permission.js.map +1 -1
- package/dist/bridge/acp/server.d.ts.map +1 -1
- package/dist/bridge/acp/server.js +21 -3
- package/dist/bridge/acp/server.js.map +1 -1
- package/dist/compaction/context-window.d.ts.map +1 -1
- package/dist/compaction/context-window.js +11 -0
- package/dist/compaction/context-window.js.map +1 -1
- package/dist/compaction/manual.d.ts +16 -1
- package/dist/compaction/manual.d.ts.map +1 -1
- package/dist/compaction/manual.js +75 -13
- package/dist/compaction/manual.js.map +1 -1
- package/dist/compaction/plan.d.ts +2 -1
- package/dist/compaction/plan.d.ts.map +1 -1
- package/dist/compaction/plan.js +6 -5
- package/dist/compaction/plan.js.map +1 -1
- package/dist/compaction/precompute.d.ts +179 -0
- package/dist/compaction/precompute.d.ts.map +1 -0
- package/dist/compaction/precompute.js +274 -0
- package/dist/compaction/precompute.js.map +1 -0
- package/dist/compaction/retained-images.d.ts +16 -0
- package/dist/compaction/retained-images.d.ts.map +1 -0
- package/dist/compaction/retained-images.js +113 -0
- package/dist/compaction/retained-images.js.map +1 -0
- package/dist/compaction/token-estimate.d.ts +8 -3
- package/dist/compaction/token-estimate.d.ts.map +1 -1
- package/dist/compaction/token-estimate.js +76 -8
- package/dist/compaction/token-estimate.js.map +1 -1
- package/dist/compaction/tool-result-editing.d.ts.map +1 -1
- package/dist/compaction/tool-result-editing.js +15 -8
- package/dist/compaction/tool-result-editing.js.map +1 -1
- package/dist/config/runtime.d.ts +4 -0
- package/dist/config/runtime.d.ts.map +1 -1
- package/dist/config/runtime.js +17 -0
- package/dist/config/runtime.js.map +1 -1
- package/dist/constants/acp/index.d.ts +2 -0
- package/dist/constants/acp/index.d.ts.map +1 -1
- package/dist/constants/acp/index.js +2 -0
- package/dist/constants/acp/index.js.map +1 -1
- package/dist/manager/agent/lifecycle.d.ts.map +1 -1
- package/dist/manager/agent/lifecycle.js +8 -0
- package/dist/manager/agent/lifecycle.js.map +1 -1
- package/dist/manager/session/turn-recorder.d.ts +26 -0
- package/dist/manager/session/turn-recorder.d.ts.map +1 -1
- package/dist/manager/session/turn-recorder.js +72 -5
- package/dist/manager/session/turn-recorder.js.map +1 -1
- package/dist/peers/protocol.d.ts +9 -0
- package/dist/peers/protocol.d.ts.map +1 -1
- package/dist/peers/protocol.js +4 -0
- package/dist/peers/protocol.js.map +1 -1
- package/dist/peers/record.d.ts +6 -0
- package/dist/peers/record.d.ts.map +1 -1
- package/dist/peers/record.js +4 -0
- package/dist/peers/record.js.map +1 -1
- package/dist/plugin/index.d.ts +2 -2
- package/dist/plugin/index.d.ts.map +1 -1
- package/dist/plugin/index.js +1 -1
- package/dist/plugin/index.js.map +1 -1
- package/dist/plugin/shell-hook.d.ts +30 -0
- package/dist/plugin/shell-hook.d.ts.map +1 -1
- package/dist/plugin/shell-hook.js +35 -0
- package/dist/plugin/shell-hook.js.map +1 -1
- package/dist/pricing/catalogue.generated.d.ts.map +1 -1
- package/dist/pricing/catalogue.generated.js +178 -1
- package/dist/pricing/catalogue.generated.js.map +1 -1
- package/dist/provider/attribution.js +1 -1
- package/dist/provider/attribution.js.map +1 -1
- package/dist/public-runtime.d.ts +9 -5
- package/dist/public-runtime.d.ts.map +1 -1
- package/dist/public-runtime.js +12 -4
- package/dist/public-runtime.js.map +1 -1
- package/dist/public-tools.d.ts +1 -1
- package/dist/public-tools.d.ts.map +1 -1
- package/dist/public-tools.js +1 -1
- package/dist/public-tools.js.map +1 -1
- package/dist/public-types.d.ts +3 -2
- package/dist/public-types.d.ts.map +1 -1
- package/dist/rag/embedding.d.ts +5 -1
- package/dist/rag/embedding.d.ts.map +1 -1
- package/dist/rag/embedding.js +22 -7
- package/dist/rag/embedding.js.map +1 -1
- package/dist/registry/command/kernel-commands.d.ts +7 -1
- package/dist/registry/command/kernel-commands.d.ts.map +1 -1
- package/dist/registry/command/kernel-commands.js +40 -2
- package/dist/registry/command/kernel-commands.js.map +1 -1
- package/dist/registry/tool/execute.d.ts +8 -0
- package/dist/registry/tool/execute.d.ts.map +1 -1
- package/dist/registry/tool/execute.js +12 -0
- package/dist/registry/tool/execute.js.map +1 -1
- package/dist/runtime/query/abandon-turn.d.ts.map +1 -1
- package/dist/runtime/query/abandon-turn.js +9 -0
- package/dist/runtime/query/abandon-turn.js.map +1 -1
- package/dist/runtime/query/budget-nudge.d.ts +27 -0
- package/dist/runtime/query/budget-nudge.d.ts.map +1 -0
- package/dist/runtime/query/budget-nudge.js +66 -0
- package/dist/runtime/query/budget-nudge.js.map +1 -0
- package/dist/runtime/query/compact-session.d.ts +19 -3
- package/dist/runtime/query/compact-session.d.ts.map +1 -1
- package/dist/runtime/query/compact-session.js +180 -93
- package/dist/runtime/query/compact-session.js.map +1 -1
- package/dist/runtime/query/guard.d.ts +8 -0
- package/dist/runtime/query/guard.d.ts.map +1 -1
- package/dist/runtime/query/guard.js +20 -0
- package/dist/runtime/query/guard.js.map +1 -1
- package/dist/runtime/query/index.d.ts.map +1 -1
- package/dist/runtime/query/index.js +1 -0
- package/dist/runtime/query/index.js.map +1 -1
- package/dist/runtime/query/iteration/index.d.ts +2 -0
- package/dist/runtime/query/iteration/index.d.ts.map +1 -1
- package/dist/runtime/query/iteration/index.js +41 -1
- package/dist/runtime/query/iteration/index.js.map +1 -1
- package/dist/runtime/query/iteration/phases/compaction.d.ts +1 -0
- package/dist/runtime/query/iteration/phases/compaction.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/compaction.js +203 -45
- package/dist/runtime/query/iteration/phases/compaction.js.map +1 -1
- package/dist/runtime/query/iteration/phases/context.d.ts +2 -0
- package/dist/runtime/query/iteration/phases/context.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/context.js +1 -0
- package/dist/runtime/query/iteration/phases/context.js.map +1 -1
- package/dist/runtime/query/iteration/phases/precompute.d.ts +60 -0
- package/dist/runtime/query/iteration/phases/precompute.d.ts.map +1 -0
- package/dist/runtime/query/iteration/phases/precompute.js +240 -0
- package/dist/runtime/query/iteration/phases/precompute.js.map +1 -0
- package/dist/runtime/query/iteration/request-prefix.d.ts +21 -0
- package/dist/runtime/query/iteration/request-prefix.d.ts.map +1 -0
- package/dist/runtime/query/iteration/request-prefix.js +111 -0
- package/dist/runtime/query/iteration/request-prefix.js.map +1 -0
- package/dist/runtime/query/review-policy.d.ts +11 -3
- package/dist/runtime/query/review-policy.d.ts.map +1 -1
- package/dist/runtime/query/review-policy.js +54 -3
- package/dist/runtime/query/review-policy.js.map +1 -1
- package/dist/runtime/query/turn/outcome-ledger.d.ts +14 -0
- package/dist/runtime/query/turn/outcome-ledger.d.ts.map +1 -1
- package/dist/runtime/query/turn/outcome-ledger.js +28 -0
- package/dist/runtime/query/turn/outcome-ledger.js.map +1 -1
- package/dist/sandbox/exec-stdin.d.ts +21 -0
- package/dist/sandbox/exec-stdin.d.ts.map +1 -0
- package/dist/sandbox/exec-stdin.js +40 -0
- package/dist/sandbox/exec-stdin.js.map +1 -0
- package/dist/sandbox/file-walk.d.ts +12 -7
- package/dist/sandbox/file-walk.d.ts.map +1 -1
- package/dist/sandbox/file-walk.js +13 -4
- package/dist/sandbox/file-walk.js.map +1 -1
- package/dist/sandbox/ignore-matcher.d.ts +1 -0
- package/dist/sandbox/ignore-matcher.d.ts.map +1 -1
- package/dist/sandbox/ignore-matcher.js.map +1 -1
- package/dist/sandbox/ignore-source.js +1 -1
- package/dist/sandbox/index.d.ts +3 -2
- package/dist/sandbox/index.d.ts.map +1 -1
- package/dist/sandbox/index.js +2 -1
- package/dist/sandbox/index.js.map +1 -1
- package/dist/sandbox/provider/local.d.ts.map +1 -1
- package/dist/sandbox/provider/local.js +2 -0
- package/dist/sandbox/provider/local.js.map +1 -1
- package/dist/session/paths.d.ts +6 -0
- package/dist/session/paths.d.ts.map +1 -1
- package/dist/session/paths.js +7 -0
- package/dist/session/paths.js.map +1 -1
- package/dist/session-query/index.d.ts +1 -0
- package/dist/session-query/index.d.ts.map +1 -1
- package/dist/session-query/index.js +26 -15
- package/dist/session-query/index.js.map +1 -1
- package/dist/store/evidence/disk.js +3 -1
- package/dist/store/evidence/disk.js.map +1 -1
- package/dist/store/evidence/index-page.d.ts +1 -0
- package/dist/store/evidence/index-page.d.ts.map +1 -1
- package/dist/store/evidence/index-page.js +8 -0
- package/dist/store/evidence/index-page.js.map +1 -1
- package/dist/store/goal/gates.d.ts +53 -0
- package/dist/store/goal/gates.d.ts.map +1 -0
- package/dist/store/goal/gates.js +664 -0
- package/dist/store/goal/gates.js.map +1 -0
- package/dist/store/goal/index.d.ts +16 -1
- package/dist/store/goal/index.d.ts.map +1 -1
- package/dist/store/goal/index.js +74 -0
- package/dist/store/goal/index.js.map +1 -1
- package/dist/store/memory/operation-lock.d.ts.map +1 -1
- package/dist/store/memory/operation-lock.js +15 -1
- package/dist/store/memory/operation-lock.js.map +1 -1
- package/dist/store/session-log/core.d.ts.map +1 -1
- package/dist/store/session-log/core.js +23 -0
- package/dist/store/session-log/core.js.map +1 -1
- package/dist/tools/builtins/bash.js +1 -1
- package/dist/tools/builtins/bash.js.map +1 -1
- package/dist/tools/builtins/browser.d.ts.map +1 -1
- package/dist/tools/builtins/browser.js +2 -0
- package/dist/tools/builtins/browser.js.map +1 -1
- package/dist/tools/builtins/computer-use-image.d.ts +9 -0
- package/dist/tools/builtins/computer-use-image.d.ts.map +1 -1
- package/dist/tools/builtins/computer-use-image.js +21 -0
- package/dist/tools/builtins/computer-use-image.js.map +1 -1
- package/dist/tools/builtins/computer-use.d.ts +1 -9
- package/dist/tools/builtins/computer-use.d.ts.map +1 -1
- package/dist/tools/builtins/computer-use.js +2 -22
- package/dist/tools/builtins/computer-use.js.map +1 -1
- package/dist/tools/builtins/monitor.d.ts.map +1 -1
- package/dist/tools/builtins/monitor.js +1 -0
- package/dist/tools/builtins/monitor.js.map +1 -1
- package/dist/tools/builtins/search-tools.js +2 -2
- package/dist/tools/builtins/search-tools.js.map +1 -1
- package/dist/tools/builtins/sleep-guard.js +1 -1
- package/dist/tools/builtins/sleep-guard.js.map +1 -1
- package/dist/tools/builtins/wait-for-job.js +1 -1
- package/dist/tools/builtins/wait-for-job.js.map +1 -1
- package/dist/tools/coordinator/ask-user-question.d.ts.map +1 -1
- package/dist/tools/coordinator/ask-user-question.js +25 -0
- package/dist/tools/coordinator/ask-user-question.js.map +1 -1
- package/dist/tools/coordinator/index.d.ts.map +1 -1
- package/dist/tools/coordinator/index.js +3 -0
- package/dist/tools/coordinator/index.js.map +1 -1
- package/dist/tools/defineTool.d.ts +2 -0
- package/dist/tools/defineTool.d.ts.map +1 -1
- package/dist/tools/defineTool.js +3 -0
- package/dist/tools/defineTool.js.map +1 -1
- package/dist/tools/goal/confirmation.d.ts +40 -2
- package/dist/tools/goal/confirmation.d.ts.map +1 -1
- package/dist/tools/goal/confirmation.js +117 -0
- package/dist/tools/goal/confirmation.js.map +1 -1
- package/dist/tools/goal/index.d.ts.map +1 -1
- package/dist/tools/goal/index.js +14 -2
- package/dist/tools/goal/index.js.map +1 -1
- package/dist/tools/memory/save.d.ts.map +1 -1
- package/dist/tools/memory/save.js +1 -0
- package/dist/tools/memory/save.js.map +1 -1
- package/dist/tools/schedules/index.d.ts +1 -0
- package/dist/tools/schedules/index.d.ts.map +1 -1
- package/dist/tools/schedules/index.js +1 -0
- package/dist/tools/schedules/index.js.map +1 -1
- package/dist/tools/schedules/loop-tool.d.ts.map +1 -1
- package/dist/tools/schedules/loop-tool.js +1 -0
- package/dist/tools/schedules/loop-tool.js.map +1 -1
- package/dist/tools/schedules/present.d.ts.map +1 -1
- package/dist/tools/schedules/present.js +2 -0
- package/dist/tools/schedules/present.js.map +1 -1
- package/dist/tools/schedules/schedule-tool.d.ts.map +1 -1
- package/dist/tools/schedules/schedule-tool.js +79 -9
- package/dist/tools/schedules/schedule-tool.js.map +1 -1
- package/dist/tools/schedules/self-tool.d.ts +16 -0
- package/dist/tools/schedules/self-tool.d.ts.map +1 -0
- package/dist/tools/schedules/self-tool.js +140 -0
- package/dist/tools/schedules/self-tool.js.map +1 -0
- package/dist/tools/schedules/timer-tools.d.ts.map +1 -1
- package/dist/tools/schedules/timer-tools.js +1 -0
- package/dist/tools/schedules/timer-tools.js.map +1 -1
- package/dist/tools/schedules/types.d.ts +63 -0
- package/dist/tools/schedules/types.d.ts.map +1 -1
- package/dist/toolsets/manager.d.ts +14 -0
- package/dist/toolsets/manager.d.ts.map +1 -1
- package/dist/toolsets/manager.js +60 -7
- package/dist/toolsets/manager.js.map +1 -1
- package/dist/types/agent/supervisor.d.ts +10 -0
- package/dist/types/agent/supervisor.d.ts.map +1 -1
- package/dist/types/agent/task.d.ts +6 -0
- package/dist/types/agent/task.d.ts.map +1 -1
- package/dist/types/common/index.d.ts +20 -0
- package/dist/types/common/index.d.ts.map +1 -1
- package/dist/types/common/index.js +4 -1
- package/dist/types/common/index.js.map +1 -1
- package/dist/types/goal/index.d.ts +66 -0
- package/dist/types/goal/index.d.ts.map +1 -1
- package/dist/types/hitl/index.d.ts +11 -0
- package/dist/types/hitl/index.d.ts.map +1 -1
- package/dist/types/hitl/index.js.map +1 -1
- package/dist/types/rag/embedding.d.ts +4 -0
- package/dist/types/rag/embedding.d.ts.map +1 -1
- package/dist/types/sandbox/index.d.ts +19 -0
- package/dist/types/sandbox/index.d.ts.map +1 -1
- package/dist/types/sandbox/index.js.map +1 -1
- package/dist/types/session/events.d.ts +55 -0
- package/dist/types/session/events.d.ts.map +1 -1
- package/dist/types/session/events.js.map +1 -1
- package/dist/types/session/outcome.d.ts +12 -0
- package/dist/types/session/outcome.d.ts.map +1 -1
- package/dist/types/session/outcome.js.map +1 -1
- package/dist/types/session/records.d.ts +81 -1
- package/dist/types/session/records.d.ts.map +1 -1
- package/dist/types/session/records.js +33 -0
- package/dist/types/session/records.js.map +1 -1
- package/dist/types/tool/index.d.ts +7 -0
- package/dist/types/tool/index.d.ts.map +1 -1
- package/dist/types/tool/index.js.map +1 -1
- package/dist/utils/cost.d.ts +15 -0
- package/dist/utils/cost.d.ts.map +1 -1
- package/dist/utils/cost.js +24 -1
- package/dist/utils/cost.js.map +1 -1
- package/package.json +2 -2
- package/src/agents/examples/SupervisorAgent.ts +5 -0
- package/src/authorization/protected-paths.ts +11 -0
- package/src/authorization/readonly-commands.ts +85 -3
- package/src/authorization/shell-paths.ts +141 -3
- package/src/bridge/acp/permission.ts +6 -0
- package/src/bridge/acp/server.ts +20 -1
- package/src/compaction/context-window.ts +11 -0
- package/src/compaction/manual.ts +103 -17
- package/src/compaction/plan.ts +11 -5
- package/src/compaction/precompute.ts +390 -0
- package/src/compaction/retained-images.ts +130 -0
- package/src/compaction/token-estimate.ts +86 -8
- package/src/compaction/tool-result-editing.ts +20 -8
- package/src/config/runtime.ts +17 -0
- package/src/constants/acp/index.ts +2 -0
- package/src/manager/agent/lifecycle.ts +9 -0
- package/src/manager/session/turn-recorder.ts +92 -5
- package/src/peers/protocol.ts +4 -0
- package/src/peers/record.ts +4 -0
- package/src/plugin/index.ts +2 -0
- package/src/plugin/shell-hook.ts +60 -0
- package/src/pricing/catalogue.generated.ts +178 -1
- package/src/pricing/rates.source.json +155 -2
- package/src/provider/attribution.ts +1 -1
- package/src/public-runtime.ts +48 -0
- package/src/public-tools.ts +2 -0
- package/src/public-types.ts +8 -0
- package/src/rag/embedding.ts +23 -7
- package/src/registry/command/kernel-commands.ts +62 -3
- package/src/registry/tool/execute.ts +14 -0
- package/src/runtime/query/abandon-turn.ts +9 -0
- package/src/runtime/query/budget-nudge.ts +92 -0
- package/src/runtime/query/compact-session.ts +242 -87
- package/src/runtime/query/guard.ts +22 -0
- package/src/runtime/query/index.ts +1 -0
- package/src/runtime/query/iteration/index.ts +40 -1
- package/src/runtime/query/iteration/phases/compaction.ts +224 -46
- package/src/runtime/query/iteration/phases/context.ts +3 -0
- package/src/runtime/query/iteration/phases/precompute.ts +277 -0
- package/src/runtime/query/iteration/request-prefix.ts +161 -0
- package/src/runtime/query/review-policy.ts +79 -11
- package/src/runtime/query/turn/outcome-ledger.ts +34 -0
- package/src/sandbox/exec-stdin.ts +54 -0
- package/src/sandbox/file-walk.ts +25 -18
- package/src/sandbox/ignore-matcher.ts +1 -0
- package/src/sandbox/ignore-source.ts +1 -1
- package/src/sandbox/index.ts +8 -2
- package/src/sandbox/provider/local.ts +2 -0
- package/src/session/paths.ts +9 -0
- package/src/session-query/index.ts +23 -14
- package/src/store/evidence/disk.ts +3 -1
- package/src/store/evidence/index-page.ts +11 -0
- package/src/store/goal/gates.ts +738 -0
- package/src/store/goal/index.ts +109 -0
- package/src/store/memory/operation-lock.ts +19 -1
- package/src/store/session-log/core.ts +26 -0
- package/src/tools/builtins/bash.ts +1 -1
- package/src/tools/builtins/browser.ts +4 -0
- package/src/tools/builtins/computer-use-image.ts +20 -0
- package/src/tools/builtins/computer-use.ts +1 -20
- package/src/tools/builtins/monitor.ts +2 -0
- package/src/tools/builtins/search-tools.ts +2 -2
- package/src/tools/builtins/sleep-guard.ts +1 -1
- package/src/tools/builtins/wait-for-job.ts +1 -1
- package/src/tools/coordinator/ask-user-question.ts +37 -10
- package/src/tools/coordinator/index.ts +3 -0
- package/src/tools/defineTool.ts +5 -0
- package/src/tools/goal/confirmation.ts +171 -3
- package/src/tools/goal/index.ts +15 -3
- package/src/tools/memory/save.ts +2 -0
- package/src/tools/schedules/index.ts +1 -0
- package/src/tools/schedules/loop-tool.ts +2 -0
- package/src/tools/schedules/present.ts +2 -0
- package/src/tools/schedules/schedule-tool.ts +84 -9
- package/src/tools/schedules/self-tool.ts +152 -0
- package/src/tools/schedules/timer-tools.ts +2 -0
- package/src/tools/schedules/types.ts +62 -0
- package/src/toolsets/manager.ts +59 -8
- package/src/types/agent/supervisor.ts +11 -0
- package/src/types/agent/task.ts +7 -0
- package/src/types/common/index.ts +26 -1
- package/src/types/goal/index.ts +72 -0
- package/src/types/hitl/index.ts +11 -0
- package/src/types/rag/embedding.ts +7 -0
- package/src/types/sandbox/index.ts +19 -0
- package/src/types/session/events.ts +56 -0
- package/src/types/session/outcome.ts +16 -1
- package/src/types/session/records.ts +41 -0
- package/src/types/tool/index.ts +7 -0
- package/src/utils/cost.ts +44 -1
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
planCompaction,
|
|
25
25
|
planSalienceWorkingSet,
|
|
26
26
|
} from '../../../../compaction/plan.js'
|
|
27
|
+
import { precomputeStoreFor } from '../../../../compaction/precompute.js'
|
|
27
28
|
import type { ContextReducer, ContextReduction } from '../../../../compaction/reducer.js'
|
|
28
29
|
import { createSlidingWindowReducer } from '../../../../compaction/reducer.js'
|
|
29
30
|
import {
|
|
@@ -32,6 +33,7 @@ import {
|
|
|
32
33
|
keptInstructionFiles,
|
|
33
34
|
renderRestoredContext,
|
|
34
35
|
} from '../../../../compaction/restore.js'
|
|
36
|
+
import { fitRetainedImages } from '../../../../compaction/retained-images.js'
|
|
35
37
|
import { findRetainedIndices } from '../../../../compaction/retention.js'
|
|
36
38
|
import { serializeState } from '../../../../compaction/serializer.js'
|
|
37
39
|
import {
|
|
@@ -40,7 +42,10 @@ import {
|
|
|
40
42
|
collectRevealedTools,
|
|
41
43
|
isCompactionMessage,
|
|
42
44
|
} from '../../../../compaction/summary.js'
|
|
43
|
-
import {
|
|
45
|
+
import {
|
|
46
|
+
estimateMessagesTokens,
|
|
47
|
+
estimateMessagesTokensForModel,
|
|
48
|
+
} from '../../../../compaction/token-estimate.js'
|
|
44
49
|
import { clearStaleToolResults } from '../../../../compaction/tool-result-editing.js'
|
|
45
50
|
import { buildVerifiedSummaryWithBoundedProvider } from '../../../../compaction/verifier.js'
|
|
46
51
|
import type { CompactionConfig } from '../../../../config/runtime.js'
|
|
@@ -60,6 +65,7 @@ import {
|
|
|
60
65
|
estimateRefillTokens,
|
|
61
66
|
} from './compaction-breaker.js'
|
|
62
67
|
import type { IterationContext } from './context.js'
|
|
68
|
+
import { armPrecompute, bookPreparedSpend, takePrepared } from './precompute.js'
|
|
63
69
|
import { isWorkingMemoryMessage } from './working-memory.js'
|
|
64
70
|
|
|
65
71
|
// `isCompactionMessage` and the header moved to `compaction/summary.ts` —
|
|
@@ -129,7 +135,12 @@ function estimateToolCatalogTokens(ctx: IterationContext): number {
|
|
|
129
135
|
}
|
|
130
136
|
|
|
131
137
|
function estimateTokens(ctx: IterationContext): number {
|
|
132
|
-
return
|
|
138
|
+
return (
|
|
139
|
+
estimateMessagesTokensForModel(
|
|
140
|
+
ctx.recorder.messages,
|
|
141
|
+
ctx.contextModel ?? ctx.turnConfig.model,
|
|
142
|
+
) + estimateToolCatalogTokens(ctx)
|
|
143
|
+
)
|
|
133
144
|
}
|
|
134
145
|
|
|
135
146
|
type ToolResultClearPlan = Extract<CompactionPlan, { kind: 'cleared' }>
|
|
@@ -364,7 +375,12 @@ export function measureContext(ctx: IterationContext): {
|
|
|
364
375
|
if (reported !== undefined && reported > 0) {
|
|
365
376
|
const measuredThrough = ctx.recorder.lastPromptMessageCount ?? ctx.recorder.messages.length
|
|
366
377
|
const appended = ctx.recorder.messages.slice(measuredThrough)
|
|
367
|
-
return {
|
|
378
|
+
return {
|
|
379
|
+
tokens:
|
|
380
|
+
reported +
|
|
381
|
+
estimateMessagesTokensForModel(appended, ctx.contextModel ?? ctx.turnConfig.model),
|
|
382
|
+
source: 'provider',
|
|
383
|
+
}
|
|
368
384
|
}
|
|
369
385
|
return { tokens: estimateTokens(ctx), source: 'estimate' }
|
|
370
386
|
}
|
|
@@ -652,6 +668,7 @@ async function applyReducer(
|
|
|
652
668
|
windowSource: 'config' | 'provider' | 'model-table' | 'default'
|
|
653
669
|
},
|
|
654
670
|
): Promise<void> {
|
|
671
|
+
const startedAt = performance.now()
|
|
655
672
|
const messages = ctx.recorder.messages
|
|
656
673
|
const before = messages.length
|
|
657
674
|
const beforeChars = totalChars(messages)
|
|
@@ -724,6 +741,13 @@ async function applyReducer(
|
|
|
724
741
|
// Found by a test written for the decline paths asserting that success does
|
|
725
742
|
// NOT report a failure, which is the only reason anybody looked here.
|
|
726
743
|
const tokensAfter = estimateTokens(ctx)
|
|
744
|
+
const durationMs = Math.max(0, Math.round(performance.now() - startedAt))
|
|
745
|
+
ctx.recorder.noteCompaction?.({
|
|
746
|
+
trigger: 'auto',
|
|
747
|
+
tokensBefore: reduction.estimatedTokens,
|
|
748
|
+
tokensAfter,
|
|
749
|
+
durationMs,
|
|
750
|
+
})
|
|
727
751
|
await ctx.emitEvent?.({
|
|
728
752
|
type: 'compaction_completed',
|
|
729
753
|
turnId: ctx.recorder.turnId,
|
|
@@ -735,6 +759,8 @@ async function applyReducer(
|
|
|
735
759
|
measuredBy: measurement.measuredBy,
|
|
736
760
|
contextWindowTokens: reduction.contextWindowTokens,
|
|
737
761
|
windowSource: measurement.windowSource,
|
|
762
|
+
trigger: 'auto',
|
|
763
|
+
durationMs,
|
|
738
764
|
})
|
|
739
765
|
await emitContextUsageSnapshot(
|
|
740
766
|
ctx,
|
|
@@ -801,17 +827,22 @@ interface CompactionPass {
|
|
|
801
827
|
hookInstructions?: string
|
|
802
828
|
/** The summary the pass installed, for `post_compact`. */
|
|
803
829
|
summary?: string
|
|
830
|
+
/** The summary was written ahead of time and installed at once. */
|
|
831
|
+
precomputed?: boolean
|
|
832
|
+
/** A turn that started after the prompt cache lapsed asked for it. */
|
|
833
|
+
cause?: 'cache_expired'
|
|
804
834
|
tokensBefore: number
|
|
805
835
|
contextWindowTokens: number
|
|
806
836
|
}
|
|
807
837
|
|
|
808
838
|
export async function runCompactionCheck(
|
|
809
839
|
ctx: IterationContext,
|
|
810
|
-
options?: { force?: boolean; deeper?: boolean },
|
|
840
|
+
options?: { force?: boolean; deeper?: boolean; preparedOnly?: boolean },
|
|
811
841
|
): Promise<void> {
|
|
812
842
|
const pass: CompactionPass = {
|
|
813
843
|
attempted: false,
|
|
814
844
|
reason: options?.force ? 'overflow' : 'threshold',
|
|
845
|
+
...(options?.preparedOnly ? { cause: 'cache_expired' as const } : {}),
|
|
815
846
|
tokensBefore: 0,
|
|
816
847
|
contextWindowTokens: 0,
|
|
817
848
|
}
|
|
@@ -852,13 +883,23 @@ export async function runCompactionCheck(
|
|
|
852
883
|
async function runCompactionCheckInner(
|
|
853
884
|
ctx: IterationContext,
|
|
854
885
|
pass: CompactionPass,
|
|
855
|
-
options?: { force?: boolean; deeper?: boolean },
|
|
886
|
+
options?: { force?: boolean; deeper?: boolean; preparedOnly?: boolean },
|
|
856
887
|
): Promise<void> {
|
|
888
|
+
const startedAt = performance.now()
|
|
889
|
+
// What summaries prepared earlier cost, before any early return below.
|
|
890
|
+
bookPreparedSpend(ctx)
|
|
857
891
|
const configured = ctx.compactionConfig
|
|
858
892
|
if (!configured) return
|
|
859
893
|
if (configured.strategy === 'disabled') return
|
|
860
894
|
// Automatic compaction off: only a pass the provider forced (an overflow) runs.
|
|
861
895
|
if (configured.autoCompact === false && !options?.force) return
|
|
896
|
+
if (options?.preparedOnly) {
|
|
897
|
+
// Only a summary already written, and only where one could be used: a
|
|
898
|
+
// reducer owns reduction, and nothing prepared means nothing to install.
|
|
899
|
+
if (configured.precompute === false || !ctx.compactionSummaryRoute) return
|
|
900
|
+
if (ctx.contextReducer || configured.strategy === 'sliding-window') return
|
|
901
|
+
if (precomputeStoreFor(ctx.recorder.sessionId).entry?.status !== 'ready') return
|
|
902
|
+
}
|
|
862
903
|
const deepened = options?.deeper ? deepenConfig(configured, ctx.recorder.messages) : configured
|
|
863
904
|
|
|
864
905
|
const measured = measureContext(ctx)
|
|
@@ -907,7 +948,20 @@ async function runCompactionCheckInner(
|
|
|
907
948
|
config.autoCompactWindowTokens,
|
|
908
949
|
)
|
|
909
950
|
const startAt = salience ? Math.min(config.softTarget ?? DEFAULT_SOFT_TARGET, trigger) : trigger
|
|
910
|
-
if (!options?.force && usage < startAt)
|
|
951
|
+
if (!options?.force && !options?.preparedOnly && usage < startAt) {
|
|
952
|
+
// Short of the trigger. Near it, a summary starts in the background so it
|
|
953
|
+
// is ready by the time the trigger is reached; far from it, nothing runs.
|
|
954
|
+
armPrecompute(ctx, {
|
|
955
|
+
config,
|
|
956
|
+
usage,
|
|
957
|
+
trigger,
|
|
958
|
+
budget,
|
|
959
|
+
estimatedTokens,
|
|
960
|
+
...(maxOutputTokens !== undefined ? { maxOutputTokens } : {}),
|
|
961
|
+
source: 'estimate',
|
|
962
|
+
})
|
|
963
|
+
return
|
|
964
|
+
}
|
|
911
965
|
|
|
912
966
|
// A pass that can shed nothing and has not reached the summary trigger
|
|
913
967
|
// does nothing but announce itself: two hooks, a started event and a log
|
|
@@ -919,10 +973,21 @@ async function runCompactionCheckInner(
|
|
|
919
973
|
if (
|
|
920
974
|
salience &&
|
|
921
975
|
!options?.force &&
|
|
976
|
+
!options?.preparedOnly &&
|
|
922
977
|
!ctx.contextReducer &&
|
|
923
978
|
usage < trigger &&
|
|
924
979
|
!canShedSalienceWorkingSet(ctx.recorder.messages, config)
|
|
925
980
|
) {
|
|
981
|
+
// Nothing to shed yet, but the summary can still start near the trigger.
|
|
982
|
+
armPrecompute(ctx, {
|
|
983
|
+
config,
|
|
984
|
+
usage,
|
|
985
|
+
trigger,
|
|
986
|
+
budget,
|
|
987
|
+
estimatedTokens,
|
|
988
|
+
...(maxOutputTokens !== undefined ? { maxOutputTokens } : {}),
|
|
989
|
+
source: 'estimate',
|
|
990
|
+
})
|
|
926
991
|
return
|
|
927
992
|
}
|
|
928
993
|
|
|
@@ -1056,7 +1121,7 @@ async function runCompactionCheckInner(
|
|
|
1056
1121
|
// The decision is `planCompaction`'s; installing it is this file's. The
|
|
1057
1122
|
// planner touches no `ctx` at all, which is what lets the boundary
|
|
1058
1123
|
// arithmetic be tested without a turn.
|
|
1059
|
-
if (salience) {
|
|
1124
|
+
if (salience && !options?.preparedOnly) {
|
|
1060
1125
|
let openTasks: string[] | undefined
|
|
1061
1126
|
if (ctx.taskStore) {
|
|
1062
1127
|
try {
|
|
@@ -1084,16 +1149,69 @@ async function runCompactionCheckInner(
|
|
|
1084
1149
|
// Under the trigger, the working set was the whole pass: the summary
|
|
1085
1150
|
// path is for the trigger, not for the soft target.
|
|
1086
1151
|
if (!options?.force && (estimatedTokens - working.reclaimedTokens) / budget < trigger) {
|
|
1152
|
+
armPrecompute(ctx, {
|
|
1153
|
+
config,
|
|
1154
|
+
usage: (estimatedTokens - working.reclaimedTokens) / budget,
|
|
1155
|
+
trigger,
|
|
1156
|
+
budget,
|
|
1157
|
+
estimatedTokens: estimatedTokens - working.reclaimedTokens,
|
|
1158
|
+
...(maxOutputTokens !== undefined ? { maxOutputTokens } : {}),
|
|
1159
|
+
source: 'estimate',
|
|
1160
|
+
})
|
|
1087
1161
|
return
|
|
1088
1162
|
}
|
|
1089
1163
|
}
|
|
1164
|
+
const fitWithoutSummary = async (candidate: readonly Message[]): Promise<boolean> => {
|
|
1165
|
+
if (options?.preparedOnly) return false
|
|
1166
|
+
const copy = [...candidate]
|
|
1167
|
+
const fitted = fitRetainedImages(
|
|
1168
|
+
copy,
|
|
1169
|
+
Math.floor(budget * config.resetThreshold) - estimateToolCatalogTokens(ctx),
|
|
1170
|
+
model,
|
|
1171
|
+
)
|
|
1172
|
+
if (fitted === copy) return false
|
|
1173
|
+
|
|
1174
|
+
const live = ctx.recorder.messages
|
|
1175
|
+
await recordShed(ctx, live, fitted, pass.reason)
|
|
1176
|
+
installMessages(live, fitted)
|
|
1177
|
+
ctx.recorder.clearLastPromptTokens?.()
|
|
1178
|
+
const tokensAfter = estimateTokens(ctx)
|
|
1179
|
+
const durationMs = Math.max(0, Math.round(performance.now() - startedAt))
|
|
1180
|
+
ctx.recorder.noteCompaction?.({
|
|
1181
|
+
trigger: 'auto',
|
|
1182
|
+
tokensBefore: estimatedTokens,
|
|
1183
|
+
tokensAfter,
|
|
1184
|
+
durationMs,
|
|
1185
|
+
})
|
|
1186
|
+
await ctx.emitEvent?.({
|
|
1187
|
+
type: 'compaction_completed',
|
|
1188
|
+
turnId: ctx.recorder.turnId,
|
|
1189
|
+
iteration: ctx.recorder.currentIteration,
|
|
1190
|
+
messagesBefore: live.length,
|
|
1191
|
+
messagesAfter: live.length,
|
|
1192
|
+
tokensBefore: estimatedTokens,
|
|
1193
|
+
tokensAfter,
|
|
1194
|
+
measuredBy: measured.source,
|
|
1195
|
+
contextWindowTokens: budget,
|
|
1196
|
+
windowSource: window.source,
|
|
1197
|
+
reachedResetThreshold: tokensAfter / budget <= config.resetThreshold,
|
|
1198
|
+
trigger: 'auto',
|
|
1199
|
+
durationMs,
|
|
1200
|
+
})
|
|
1201
|
+
await emitContextUsageSnapshot(ctx, tokensAfter, budget, window.source)
|
|
1202
|
+
breaker?.recordRelief()
|
|
1203
|
+
return true
|
|
1204
|
+
}
|
|
1090
1205
|
const clearPlan = planCompaction({
|
|
1206
|
+
model,
|
|
1091
1207
|
messages: ctx.recorder.messages,
|
|
1092
1208
|
config,
|
|
1093
1209
|
contextWindowTokens: budget,
|
|
1094
1210
|
...(maxOutputTokens !== undefined ? { maxOutputTokens } : {}),
|
|
1095
1211
|
estimatedTokens,
|
|
1096
1212
|
...(options?.force ? { force: true } : {}),
|
|
1213
|
+
// Installing a prepared summary leaves the tool results to the stale clear.
|
|
1214
|
+
...(options?.preparedOnly ? { skipToolResultClear: true } : {}),
|
|
1097
1215
|
})
|
|
1098
1216
|
|
|
1099
1217
|
if (clearPlan.kind === 'cleared') {
|
|
@@ -1114,6 +1232,7 @@ async function runCompactionCheckInner(
|
|
|
1114
1232
|
const stagedClear = clearPlan.kind === 'cleared' ? clearPlan : undefined
|
|
1115
1233
|
const messages = stagedClear?.messages ?? ctx.recorder.messages
|
|
1116
1234
|
const plan = planCompaction({
|
|
1235
|
+
model,
|
|
1117
1236
|
messages,
|
|
1118
1237
|
config,
|
|
1119
1238
|
contextWindowTokens: budget,
|
|
@@ -1124,6 +1243,7 @@ async function runCompactionCheckInner(
|
|
|
1124
1243
|
})
|
|
1125
1244
|
|
|
1126
1245
|
if (plan.kind !== 'plan') {
|
|
1246
|
+
if (await fitWithoutSummary(messages)) return
|
|
1127
1247
|
// One log line per reason, with the fields each one was already
|
|
1128
1248
|
// reporting. The planner names the reason; what it means to an
|
|
1129
1249
|
// operator reading a turn is this file's to say.
|
|
@@ -1168,52 +1288,82 @@ async function runCompactionCheckInner(
|
|
|
1168
1288
|
return
|
|
1169
1289
|
}
|
|
1170
1290
|
|
|
1171
|
-
|
|
1291
|
+
let { olderMessages, recentMessages, keepStart } = plan
|
|
1292
|
+
const { systemMessages } = plan
|
|
1172
1293
|
|
|
1173
1294
|
let compactedContent: string
|
|
1174
1295
|
|
|
1296
|
+
// A summary written ahead of time stands in for the one this pass would
|
|
1297
|
+
// write, when it still describes the start of the conversation. What was
|
|
1298
|
+
// said after it was armed stays verbatim after the summary.
|
|
1299
|
+
const prepared =
|
|
1300
|
+
ctx.compactionSummaryRoute && config.precompute !== false && !ctx.contextReducer
|
|
1301
|
+
? await takePrepared(ctx, {
|
|
1302
|
+
messages,
|
|
1303
|
+
floorLength: systemMessages.length,
|
|
1304
|
+
hookInstructions: pass.hookInstructions,
|
|
1305
|
+
overheadTokens: estimateToolCatalogTokens(ctx),
|
|
1306
|
+
budget,
|
|
1307
|
+
triggerTokens: trigger * budget,
|
|
1308
|
+
...(options?.preparedOnly ? { readyOnly: true } : {}),
|
|
1309
|
+
})
|
|
1310
|
+
: undefined
|
|
1311
|
+
// A turn that starts after the cache lapsed installs a summary that is
|
|
1312
|
+
// ready, and writes none: a refusal is a skip.
|
|
1313
|
+
if (options?.preparedOnly && !prepared) return
|
|
1314
|
+
if (prepared) {
|
|
1315
|
+
keepStart = prepared.keepStart
|
|
1316
|
+
olderMessages = messages.slice(systemMessages.length, keepStart)
|
|
1317
|
+
recentMessages = messages.slice(keepStart)
|
|
1318
|
+
pass.precomputed = true
|
|
1319
|
+
}
|
|
1320
|
+
|
|
1175
1321
|
// A model the host set aside writes the summary when it can. Its own cost
|
|
1176
1322
|
// goes on the turn's ledger at the price of the model that answered. When
|
|
1177
1323
|
// there is no such model, or its call does not give a summary, the
|
|
1178
1324
|
// extracted state below is used, with its verifier step where that applies.
|
|
1179
1325
|
let modelRoute: { providerId: string; model: string } | undefined
|
|
1180
|
-
const modelWritten =
|
|
1181
|
-
?
|
|
1182
|
-
:
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1326
|
+
const modelWritten = prepared
|
|
1327
|
+
? prepared.summary
|
|
1328
|
+
: !ctx.compactionSummaryRoute
|
|
1329
|
+
? undefined
|
|
1330
|
+
: await summarizeWithModel({
|
|
1331
|
+
manager,
|
|
1332
|
+
olderMessages,
|
|
1333
|
+
previousSummaries: replaceableSummaries(systemMessages),
|
|
1334
|
+
config,
|
|
1335
|
+
...(pass.hookInstructions !== undefined
|
|
1336
|
+
? { hookInstructions: pass.hookInstructions }
|
|
1337
|
+
: {}),
|
|
1338
|
+
resolveRoute: async (signal) => {
|
|
1339
|
+
const route = await ctx.compactionSummaryRoute?.(signal)
|
|
1340
|
+
if (route) {
|
|
1341
|
+
modelRoute = {
|
|
1342
|
+
providerId: route.providerId ?? ctx.recorder.servingProviderId,
|
|
1343
|
+
model: route.model,
|
|
1344
|
+
}
|
|
1194
1345
|
}
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
}
|
|
1216
|
-
})
|
|
1346
|
+
return route
|
|
1347
|
+
},
|
|
1348
|
+
onUsage: (usage) => {
|
|
1349
|
+
if (modelRoute) ctx.recorder.accumulateUsage(usage, modelRoute)
|
|
1350
|
+
},
|
|
1351
|
+
signal: ctx.abortController.signal,
|
|
1352
|
+
onFallback: (reason, error) => {
|
|
1353
|
+
if (reason === 'no_route') return
|
|
1354
|
+
if (error !== undefined) noteCompactionError(ctx, error)
|
|
1355
|
+
ctx.log.warn(
|
|
1356
|
+
'The model-written compaction summary was not used — using the extracted state',
|
|
1357
|
+
{
|
|
1358
|
+
[NAMZU.TURN_ID]: ctx.recorder.turnId,
|
|
1359
|
+
'namzu.runtime.reason': reason,
|
|
1360
|
+
...(error !== undefined
|
|
1361
|
+
? { 'exception.message': error instanceof Error ? error.message : String(error) }
|
|
1362
|
+
: {}),
|
|
1363
|
+
},
|
|
1364
|
+
)
|
|
1365
|
+
},
|
|
1366
|
+
})
|
|
1217
1367
|
|
|
1218
1368
|
if (modelWritten !== undefined) {
|
|
1219
1369
|
compactedContent = modelWritten
|
|
@@ -1348,7 +1498,17 @@ async function runCompactionCheckInner(
|
|
|
1348
1498
|
},
|
|
1349
1499
|
)
|
|
1350
1500
|
|
|
1351
|
-
const newMessages =
|
|
1501
|
+
const newMessages = fitRetainedImages(
|
|
1502
|
+
[...preservedSystem, compactionMessage, ...retainedOlder, ...recentMessages],
|
|
1503
|
+
Math.floor(budget * config.resetThreshold) - estimateToolCatalogTokens(ctx),
|
|
1504
|
+
model,
|
|
1505
|
+
config.keepRecentTokens === undefined
|
|
1506
|
+
? undefined
|
|
1507
|
+
: {
|
|
1508
|
+
start: preservedSystem.length + 1 + retainedOlder.length,
|
|
1509
|
+
tokens: config.keepRecentTokens,
|
|
1510
|
+
},
|
|
1511
|
+
)
|
|
1352
1512
|
|
|
1353
1513
|
// OPAQUE survival guard: the pinned working-memory slot is a
|
|
1354
1514
|
// leading system message, so it is kept in `preservedSystem` (the compaction
|
|
@@ -1379,7 +1539,11 @@ async function runCompactionCheckInner(
|
|
|
1379
1539
|
// comparing provider usage against an estimate or trusting message count.
|
|
1380
1540
|
// When a clear was staged, require the summary itself to improve on it;
|
|
1381
1541
|
// otherwise publish the useful clear without consuming its savings.
|
|
1382
|
-
if (
|
|
1542
|
+
if (
|
|
1543
|
+
estimateMessagesTokensForModel(newMessages, model) >=
|
|
1544
|
+
estimateMessagesTokensForModel(messages, model)
|
|
1545
|
+
) {
|
|
1546
|
+
if (await fitWithoutSummary(messages)) return
|
|
1383
1547
|
if (stagedClear && stagedClear.reclaimedTokens > 0) {
|
|
1384
1548
|
await commitToolResultClear(ctx, stagedClear, budget, window.source, pass.reason)
|
|
1385
1549
|
} else {
|
|
@@ -1393,6 +1557,16 @@ async function runCompactionCheckInner(
|
|
|
1393
1557
|
pass.summary = compactedContent
|
|
1394
1558
|
|
|
1395
1559
|
const newEstimate = estimateTokens(ctx)
|
|
1560
|
+
// Said before anything below emits: an emit reconciles the log with the new
|
|
1561
|
+
// context, and the `compaction` record it writes carries what was said here.
|
|
1562
|
+
const durationMs = Math.max(0, Math.round(performance.now() - startedAt))
|
|
1563
|
+
ctx.recorder.noteCompaction?.({
|
|
1564
|
+
trigger: pass.precomputed ? 'prepared' : 'auto',
|
|
1565
|
+
tokensBefore: estimatedTokens,
|
|
1566
|
+
tokensAfter: newEstimate,
|
|
1567
|
+
durationMs,
|
|
1568
|
+
...(pass.precomputed ? { precomputed: true } : {}),
|
|
1569
|
+
})
|
|
1396
1570
|
|
|
1397
1571
|
// The provider's count described the PRE-compaction prompt; the window
|
|
1398
1572
|
// it just shrank to has not been sent yet, so the post number is
|
|
@@ -1446,6 +1620,10 @@ async function runCompactionCheckInner(
|
|
|
1446
1620
|
contextWindowTokens: budget,
|
|
1447
1621
|
windowSource: window.source,
|
|
1448
1622
|
reachedResetThreshold: reachedReset,
|
|
1623
|
+
trigger: pass.precomputed ? 'prepared' : 'auto',
|
|
1624
|
+
durationMs,
|
|
1625
|
+
...(pass.precomputed ? { precomputed: true } : {}),
|
|
1626
|
+
...(pass.cause ? { cause: pass.cause } : {}),
|
|
1449
1627
|
})
|
|
1450
1628
|
await emitContextUsageSnapshot(ctx, newEstimate, budget, window.source)
|
|
1451
1629
|
if (putBack.rendered && putBack.rendered.carried.length > 0) {
|
|
@@ -269,6 +269,8 @@ export interface IterationContext {
|
|
|
269
269
|
readonly resumedInput?: readonly import('../../../../types/message/index.js').Message[]
|
|
270
270
|
/** Observes pending input without draining it; abort releases the waiter. */
|
|
271
271
|
readonly waitForInbound?: (signal: AbortSignal) => Promise<void>
|
|
272
|
+
/** Resolves when the person wrote to this turn; handed to resume handlers, see `ResumeContext`. */
|
|
273
|
+
readonly waitForOperator?: (signal: AbortSignal) => Promise<void>
|
|
272
274
|
readonly durableInbound?: DurableInboundSource
|
|
273
275
|
|
|
274
276
|
/** Live project policy; separate from human inbound continuation. */
|
|
@@ -481,6 +483,7 @@ function resumeContextOf(ctx: IterationContext, scope?: AskScope): ResumeContext
|
|
|
481
483
|
return {
|
|
482
484
|
transcript: () => ctx.recorder.messages,
|
|
483
485
|
...(signal ? { signal } : {}),
|
|
486
|
+
...(ctx.waitForOperator ? { waitForOperator: ctx.waitForOperator } : {}),
|
|
484
487
|
...(typeof ctx.toolExecutor?.launchedScripts === 'function'
|
|
485
488
|
? {
|
|
486
489
|
launchedScripts: (callId, line, dialect) =>
|