@sema-agent/core 7.69.0 → 7.69.1
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 +583 -0
- package/dist/agents/repair-loop.js +6 -14
- package/dist/agents/subagent.js +2 -1
- package/dist/agents/verify.d.ts +1 -1
- package/dist/agents/verify.js +7 -1
- package/dist/brain/reasoning-request.d.ts +7 -0
- package/dist/brain/reasoning-request.js +6 -0
- package/dist/core/agent-config-dir.d.ts +39 -3
- package/dist/core/agent-config-dir.js +67 -11
- package/dist/core/allow-entry.d.ts +5 -5
- package/dist/core/allow-entry.js +12 -6
- package/dist/core/ask-headline.d.ts +2 -2
- package/dist/core/ask-origin.d.ts +31 -31
- package/dist/core/ask-origin.js +20 -13
- package/dist/core/attachment-source.d.ts +1 -1
- package/dist/core/attachment-source.js +1 -0
- package/dist/core/auto-compaction.d.ts +44 -62
- package/dist/core/auto-compaction.js +44 -103
- package/dist/core/cache-break-detector.d.ts +23 -11
- package/dist/core/cache-break-detector.js +11 -5
- package/dist/core/checkpoint-features.d.ts +1 -1
- package/dist/core/checkpoint-features.js +1 -1
- package/dist/core/checkpoint-requirements.d.ts +19 -1
- package/dist/core/checkpoint-requirements.js +6 -0
- package/dist/core/checkpoint-row-verdict.js +3 -0
- package/dist/core/checkpoint-store.d.ts +13 -2
- package/dist/core/child-clamp-seats.d.ts +30 -3
- package/dist/core/child-clamp-seats.js +24 -0
- package/dist/core/compaction-retired-members.d.ts +12 -0
- package/dist/core/compaction-retired-members.js +22 -0
- package/dist/core/config-refusal-codes.d.ts +1 -1
- package/dist/core/config-refusal-codes.js +2 -0
- package/dist/core/context-edit.d.ts +32 -17
- package/dist/core/context-edit.js +28 -0
- package/dist/core/cron.d.ts +68 -0
- package/dist/core/cron.js +259 -0
- package/dist/core/engine-attestation.d.ts +16 -0
- package/dist/core/engine-attestation.js +2 -0
- package/dist/core/engine-capabilities.d.ts +14 -1
- package/dist/core/engine-capabilities.js +1 -1
- package/dist/core/engine-notice.d.ts +18 -7
- package/dist/core/engine-version.js +1 -1
- package/dist/core/gate-outcome.d.ts +29 -2
- package/dist/core/gate-outcome.js +6 -0
- package/dist/core/git-read-only.d.ts +10 -0
- package/dist/core/git-read-only.js +1 -0
- package/dist/core/git-worktree-env.js +9 -8
- package/dist/core/governance-codes.d.ts +9 -2
- package/dist/core/governance-codes.js +9 -0
- package/dist/core/locked-config.js +7 -3
- package/dist/core/lsp.d.ts +3 -0
- package/dist/core/lsp.js +3 -2
- package/dist/core/memory-engine/engine.d.ts +48 -12
- package/dist/core/memory-engine/engine.js +108 -46
- package/dist/core/memory-engine/file-backend.d.ts +2 -1
- package/dist/core/memory-engine/index-copies.d.ts +47 -0
- package/dist/core/memory-engine/index-copies.js +88 -0
- package/dist/core/memory-engine/layout.d.ts +20 -3
- package/dist/core/memory-engine/layout.js +39 -3
- package/dist/core/memory-engine/origin-clearance.d.ts +9 -7
- package/dist/core/memory-engine/origin-clearance.js +2 -4
- package/dist/core/memory-engine/types.d.ts +16 -3
- package/dist/core/mode-policy.d.ts +7 -1
- package/dist/core/mode-policy.js +9 -0
- package/dist/core/mods/session-compact.js +3 -3
- package/dist/core/mods/stations.d.ts +2 -0
- package/dist/core/mods/stations.js +2 -1
- package/dist/core/path-guard-rows.d.ts +8 -3
- package/dist/core/path-guard-rows.js +18 -5
- package/dist/core/peer-seat.d.ts +3 -0
- package/dist/core/peer-seat.js +3 -0
- package/dist/core/permission-rule-model.js +3 -2
- package/dist/core/process-identity.d.ts +11 -3
- package/dist/core/process-identity.js +26 -16
- package/dist/core/runner/assemble-result.d.ts +5 -0
- package/dist/core/runner/assemble-result.js +1 -1
- package/dist/core/runner/cleared-results-record.d.ts +33 -0
- package/dist/core/runner/cleared-results-record.js +56 -0
- package/dist/core/runner/compact-session.js +14 -9
- package/dist/core/runner/compaction-knobs.d.ts +1 -1
- package/dist/core/runner/continuation-gate.js +2 -1
- package/dist/core/runner/continues-from.d.ts +1 -1
- package/dist/core/runner/continues-from.js +1 -1
- package/dist/core/runner/contracts.d.ts +83 -31
- package/dist/core/runner/conversation-segment.d.ts +19 -12
- package/dist/core/runner/conversation-segment.js +27 -7
- package/dist/core/runner/derived-route-fallback.d.ts +2 -12
- package/dist/core/runner/derived-route-fallback.js +0 -6
- package/dist/core/runner/gate-exit.d.ts +2 -1
- package/dist/core/runner/gate-exit.js +4 -2
- package/dist/core/runner/git-status-frame.d.ts +2 -2
- package/dist/core/runner/git-status-frame.js +2 -1
- package/dist/core/runner/initial-run-state.js +1 -1
- package/dist/core/runner/leg-caller-places.d.ts +39 -0
- package/dist/core/runner/leg-caller-places.js +23 -0
- package/dist/core/runner/leg-frame.d.ts +8 -2
- package/dist/core/runner/leg-receipt.d.ts +29 -2
- package/dist/core/runner/leg-receipt.js +37 -6
- package/dist/core/runner/media-removed-seat.d.ts +10 -6
- package/dist/core/runner/media-removed-seat.js +6 -3
- package/dist/core/runner/messages-omitted-seat.d.ts +2 -1
- package/dist/core/runner/messages-omitted-seat.js +15 -5
- package/dist/core/runner/person-path-rows.d.ts +25 -7
- package/dist/core/runner/person-path-rows.js +16 -2
- package/dist/core/runner/prefix-ledger.d.ts +120 -0
- package/dist/core/runner/prefix-ledger.js +176 -0
- package/dist/core/runner/prepare-advisor.d.ts +2 -0
- package/dist/core/runner/prepare-advisor.js +2 -1
- package/dist/core/runner/prepare-artifact.d.ts +3 -0
- package/dist/core/runner/prepare-artifact.js +2 -2
- package/dist/core/runner/prepare-caps-and-workflow.d.ts +2 -0
- package/dist/core/runner/prepare-caps-and-workflow.js +4 -3
- package/dist/core/runner/prepare-config-doors.d.ts +9 -8
- package/dist/core/runner/prepare-config-doors.js +15 -12
- package/dist/core/runner/prepare-context-lane.d.ts +25 -6
- package/dist/core/runner/prepare-context-lane.js +82 -27
- package/dist/core/runner/prepare-gate-stations.d.ts +1 -2
- package/dist/core/runner/prepare-gate-stations.js +2 -4
- package/dist/core/runner/prepare-hands-readface.d.ts +18 -5
- package/dist/core/runner/prepare-hands-readface.js +41 -22
- package/dist/core/runner/prepare-inherited-gate.d.ts +5 -0
- package/dist/core/runner/prepare-inherited-gate.js +2 -0
- package/dist/core/runner/prepare-memory.d.ts +10 -2
- package/dist/core/runner/prepare-memory.js +51 -5
- package/dist/core/runner/prepare-policy-chain.d.ts +3 -0
- package/dist/core/runner/prepare-policy-chain.js +13 -2
- package/dist/core/runner/prepare-prompt-assembly.d.ts +12 -4
- package/dist/core/runner/prepare-prompt-assembly.js +10 -4
- package/dist/core/runner/prepare-prompt-inputs.d.ts +3 -7
- package/dist/core/runner/prepare-prompt-inputs.js +6 -7
- package/dist/core/runner/prepare-safety-scan.js +7 -0
- package/dist/core/runner/prepare-suspend-saga.d.ts +4 -0
- package/dist/core/runner/prepare-suspend-saga.js +3 -2
- package/dist/core/runner/prepare-task.js +59 -53
- package/dist/core/runner/prepare-tool-disclosure-mount.d.ts +5 -11
- package/dist/core/runner/prepare-tool-disclosure-mount.js +7 -8
- package/dist/core/runner/prepare-turn-wiring.d.ts +16 -25
- package/dist/core/runner/prepare-turn-wiring.js +8 -18
- package/dist/core/runner/prepare-wiring-manifest.d.ts +1 -0
- package/dist/core/runner/prepare-wiring-manifest.js +3 -2
- package/dist/core/runner/prompt-suggestions.d.ts +3 -1
- package/dist/core/runner/prompt-suggestions.js +1 -1
- package/dist/core/runner/read-block-judge.d.ts +47 -0
- package/dist/core/runner/read-block-judge.js +33 -0
- package/dist/core/runner/role-resolution-table.d.ts +15 -10
- package/dist/core/runner/role-resolution-table.js +4 -5
- package/dist/core/runner/rule-store-unreadable-notice.d.ts +7 -4
- package/dist/core/runner/rule-store-unreadable-notice.js +4 -3
- package/dist/core/runner/run-compaction-machinery.d.ts +0 -10
- package/dist/core/runner/run-compaction-machinery.js +3 -39
- package/dist/core/runner/run-harness-handlers.js +4 -17
- package/dist/core/runner/run-identity-wiring.js +4 -1
- package/dist/core/runner/run-leg.js +11 -1
- package/dist/core/runner/run-recovery-lanes.d.ts +0 -4
- package/dist/core/runner/run-recovery-lanes.js +34 -18
- package/dist/core/runner/run-settle-and-teardown.d.ts +1 -3
- package/dist/core/runner/run-settle-and-teardown.js +14 -22
- package/dist/core/runner/run-telemetry-and-budget-seats.js +0 -1
- package/dist/core/runner/run-terminal-adoption.d.ts +11 -30
- package/dist/core/runner/run-terminal-adoption.js +5 -88
- package/dist/core/runner/run-tool-mount-facts.js +1 -5
- package/dist/core/runner/run-turn-boundary.js +56 -26
- package/dist/core/runner/runtask.js +7 -7
- package/dist/core/runner/session-hash-salt.d.ts +18 -0
- package/dist/core/runner/session-hash-salt.js +36 -0
- package/dist/core/runner/shell-env-withheld.d.ts +8 -5
- package/dist/core/runner/shell-env-withheld.js +3 -3
- package/dist/core/runner/side-call-account.d.ts +9 -1
- package/dist/core/runner/side-call-account.js +15 -4
- package/dist/core/runner/skill-mention.d.ts +12 -0
- package/dist/core/runner/skill-mention.js +50 -0
- package/dist/core/runner/stream-settle-backstop.js +1 -0
- package/dist/core/runner/synthetic-tools.js +2 -2
- package/dist/core/runner/tool-table-view.d.ts +5 -9
- package/dist/core/runner/tool-table-view.js +23 -21
- package/dist/core/runner/write-protection-station.d.ts +5 -2
- package/dist/core/runner/write-protection-station.js +1 -1
- package/dist/core/runner-deps.d.ts +25 -27
- package/dist/core/scheduler.d.ts +13 -3
- package/dist/core/scheduler.js +0 -12
- package/dist/core/secret-env.d.ts +47 -11
- package/dist/core/secret-env.js +65 -4
- package/dist/core/sensitive-path-policy.js +4 -0
- package/dist/core/session-checkout.js +10 -9
- package/dist/core/shell-read-silence.d.ts +2 -1
- package/dist/core/shell-run-candidates.d.ts +1 -1
- package/dist/core/shell-run-candidates.js +11 -3
- package/dist/core/task-event.d.ts +32 -10
- package/dist/core/task-intake.d.ts +5 -3
- package/dist/core/task-intake.js +6 -2
- package/dist/core/task-result.d.ts +39 -0
- package/dist/core/task-spec-members.d.ts +3 -0
- package/dist/core/task-spec-members.js +2 -2
- package/dist/core/task-spec.d.ts +37 -20
- package/dist/core/tool-policy.d.ts +30 -18
- package/dist/core/tool-policy.js +44 -32
- package/dist/core/tool-roster.d.ts +21 -7
- package/dist/core/tool-roster.js +34 -6
- package/dist/core/tool-spec-members.js +1 -1
- package/dist/core/tool-spec.d.ts +27 -0
- package/dist/core/tools.js +1 -0
- package/dist/core/trace.d.ts +42 -19
- package/dist/core/unc-spelling.d.ts +31 -0
- package/dist/core/unc-spelling.js +51 -0
- package/dist/core/wiring-manifest.d.ts +30 -3
- package/dist/core/wiring-manifest.js +10 -0
- package/dist/core/workflow-run-store-contract.js +22 -0
- package/dist/core/workflow-run-store.d.ts +17 -13
- package/dist/core/workflow-run-store.js +1 -1
- package/dist/core/write-protect.d.ts +4 -0
- package/dist/core/write-protect.js +17 -15
- package/dist/engine/compaction/compaction.d.ts +48 -98
- package/dist/engine/compaction/compaction.js +136 -216
- package/dist/engine/compaction/utils.d.ts +2 -11
- package/dist/engine/compaction/utils.js +4 -13
- package/dist/engine/execution-env/node-execution-env.js +17 -6
- package/dist/engine/harness/agent-harness.d.ts +19 -5
- package/dist/engine/harness/agent-harness.js +18 -7
- package/dist/engine/harness/types.d.ts +5 -7
- package/dist/engine/loop/agent-loop.d.ts +14 -1
- package/dist/engine/loop/agent-loop.js +31 -11
- package/dist/engine/loop/types.d.ts +8 -2
- package/dist/index.d.ts +9 -6
- package/dist/index.js +8 -6
- package/dist/internal/harness-types.d.ts +1 -1
- package/dist/internal/harness.d.ts +1 -1
- package/dist/internal/harness.js +1 -1
- package/dist/orchestration/run-spec.js +7 -2
- package/dist/orchestration/run-workflow-tool.js +5 -3
- package/dist/orchestration/workflow-park-adoption.d.ts +66 -8
- package/dist/orchestration/workflow-park-adoption.js +195 -45
- package/dist/orchestration/workflow-types.d.ts +20 -0
- package/dist/orchestration/workflow-types.js +1 -0
- package/dist/orchestration/workflow.d.ts +3 -2
- package/dist/orchestration/workflow.js +10 -4
- package/dist/prompt-assembly/catalog/core-behavior.js +6 -0
- package/dist/prompt-assembly/catalog/events.d.ts +8 -0
- package/dist/prompt-assembly/catalog/locales/zh-Hans/core-behavior.js +6 -0
- package/dist/prompt-assembly/catalog/locales/zh-Hans/mechanism.js +1 -0
- package/dist/prompt-assembly/catalog/mechanism.d.ts +8 -0
- package/dist/prompt-assembly/catalog/mechanism.js +1 -0
- package/dist/prompt-assembly/catalog/schema.d.ts +1 -1
- package/dist/prompt-assembly/catalog/schema.js +1 -0
- package/dist/prompt-assembly/catalog/sections.js +8 -0
- package/dist/prompt-assembly/event-registry.js +1 -0
- package/dist/prompt-assembly/select.js +1 -0
- package/dist/prompt-assembly/turn-snapshot.d.ts +14 -27
- package/dist/prompt-assembly/turn-snapshot.js +6 -18
- package/dist/prompt-assembly/types.d.ts +3 -0
- package/dist/prompts/default.d.ts +9 -0
- package/dist/prompts/default.js +4 -0
- package/dist/shell/lex.d.ts +75 -11
- package/dist/shell/lex.js +340 -76
- package/dist/tools/fs/bash-program-position.js +2 -6
- package/dist/tools/fs/bash-readonly-classifier.d.ts +18 -3
- package/dist/tools/fs/bash-readonly-classifier.js +19 -9
- package/dist/tools/fs/containment-face.d.ts +12 -3
- package/dist/tools/fs/containment-face.js +16 -7
- package/dist/tools/fs/file-read-check.d.ts +26 -1
- package/dist/tools/fs/file-read-check.js +20 -2
- package/dist/tools/fs/fs-bash.js +4 -4
- package/dist/tools/fs/fs-read.d.ts +3 -0
- package/dist/tools/fs/fs-read.js +2 -2
- package/dist/tools/fs/fs-search-tools.d.ts +2 -2
- package/dist/tools/fs/fs-search-tools.js +4 -4
- package/dist/tools/fs/index.js +5 -3
- package/dist/tools/fs/pdf.js +12 -4
- package/dist/tools/fs/read-deny-home.d.ts +13 -2
- package/dist/tools/fs/read-deny-home.js +26 -22
- package/dist/tools/fs/read-deny.js +15 -6
- package/dist/tools/fs/removal-targets.d.ts +33 -17
- package/dist/tools/fs/removal-targets.js +160 -61
- package/dist/tools/fs/repo-map.d.ts +1 -1
- package/dist/tools/fs/repo-map.js +2 -2
- package/dist/tools/fs/safety.d.ts +28 -5
- package/dist/tools/fs/safety.js +72 -8
- package/dist/tools/fs/shell-read-bindings.d.ts +8 -2
- package/dist/tools/fs/shell-read-bindings.js +25 -6
- package/dist/tools/fs/shell-read-check.d.ts +3 -0
- package/dist/tools/fs/shell-read-check.js +22 -4
- package/dist/tools/fs/shell-read-establish.js +73 -43
- package/dist/tools/fs/shell-read-judge.d.ts +32 -14
- package/dist/tools/fs/shell-read-judge.js +13 -5
- package/dist/tools/fs/shell-read-object-path.d.ts +5 -1
- package/dist/tools/fs/shell-read-object-path.js +17 -4
- package/dist/tools/fs/shell-read-plan.d.ts +8 -2
- package/dist/tools/fs/shell-read-plan.js +36 -22
- package/dist/tools/fs/shell-read-sourced.js +12 -4
- package/dist/tools/fs/shell-read-start.d.ts +4 -2
- package/dist/tools/fs/shell-read-start.js +3 -3
- package/dist/tools/fs/shell-read-workdir.d.ts +14 -6
- package/dist/tools/fs/shell-read-workdir.js +35 -17
- package/dist/tools/scheduler-tools.d.ts +7 -17
- package/dist/tools/scheduler-tools.js +9 -85
- package/dist/tools/worktree.js +5 -4
- package/package.json +3 -2
- package/test/export-surface.snapshot.json +47 -1
- package/wire-changes/core-stores-sql@7.68.6.json +39 -0
- package/wire-changes/core-stores-sql@7.69.1.json +39 -0
- package/wire-changes/core@7.68.6.json +125 -0
- package/wire-changes/core@7.69.1.json +2561 -0
- package/wire-changes/mods-kernel@7.68.6.json +39 -0
- package/wire-changes/mods-kernel@7.69.1.json +39 -0
- package/wire-changes/primitives@7.68.6.json +39 -0
- package/wire-changes/primitives@7.69.1.json +39 -0
- package/wire-changes/wiki-gate@7.68.6.json +39 -0
- package/wire-changes/wiki-gate@7.69.1.json +39 -0
- package/dist/core/runner/prompt-hash-salt.d.ts +0 -1
- package/dist/core/runner/prompt-hash-salt.js +0 -2
package/dist/core/ask-origin.js
CHANGED
|
@@ -198,7 +198,7 @@ export const ORIGIN_IMPLIES_REAL_APPROVAL = {
|
|
|
198
198
|
hook: false,
|
|
199
199
|
ask_rule: false,
|
|
200
200
|
denial_limit_fallback: "at_mint",
|
|
201
|
-
integrity_guard:
|
|
201
|
+
integrity_guard: false,
|
|
202
202
|
shell_gate_tighten: false,
|
|
203
203
|
safety_tighten: false,
|
|
204
204
|
policy: false,
|
|
@@ -277,8 +277,6 @@ export const ASK_CLASSES = Object.freeze([
|
|
|
277
277
|
"hook",
|
|
278
278
|
"ancestor",
|
|
279
279
|
"dangerous_delete",
|
|
280
|
-
"unverifiable_delete",
|
|
281
|
-
"unverifiable_shell_text",
|
|
282
280
|
"transcript_write",
|
|
283
281
|
"org_rule",
|
|
284
282
|
"org_unreadable",
|
|
@@ -300,6 +298,8 @@ export const ASK_CLASSES = Object.freeze([
|
|
|
300
298
|
"policy_rra",
|
|
301
299
|
"artifact_shared_read",
|
|
302
300
|
"mode",
|
|
301
|
+
"unverifiable_delete",
|
|
302
|
+
"unverifiable_shell_text",
|
|
303
303
|
"sandbox_override",
|
|
304
304
|
"sandbox_network",
|
|
305
305
|
"unstated",
|
|
@@ -318,14 +318,12 @@ export function classWordsOf(classification, toolName) {
|
|
|
318
318
|
export function allowMayClearOn(row, kind) {
|
|
319
319
|
return row.ruleMayClear && (kind === "rule" || !row.hookAskFloor);
|
|
320
320
|
}
|
|
321
|
-
const
|
|
321
|
+
const ORDINARY_ROW = Object.freeze({ bypassImmune: false, classifierEligible: true, sandboxAdmission: true, ruleMayClear: true, hookAskFloor: false });
|
|
322
322
|
export const MODE_ARBITRATION = {
|
|
323
323
|
content_question: { bypassImmune: true, classifierEligible: false, sandboxAdmission: false, ruleMayClear: false, hookAskFloor: true },
|
|
324
324
|
hook: { bypassImmune: true, classifierEligible: false, sandboxAdmission: false, ruleMayClear: false, hookAskFloor: false },
|
|
325
325
|
ancestor: { bypassImmune: true, classifierEligible: false, sandboxAdmission: false, ruleMayClear: false, hookAskFloor: false },
|
|
326
|
-
dangerous_delete:
|
|
327
|
-
unverifiable_delete: REMOVAL_BREAKER_ROW,
|
|
328
|
-
unverifiable_shell_text: REMOVAL_BREAKER_ROW,
|
|
326
|
+
dangerous_delete: { bypassImmune: true, classifierEligible: false, sandboxAdmission: false, ruleMayClear: false, hookAskFloor: true },
|
|
329
327
|
transcript_write: { bypassImmune: false, classifierEligible: true, sandboxAdmission: false, ruleMayClear: false, hookAskFloor: true },
|
|
330
328
|
org_rule: { bypassImmune: true, classifierEligible: false, sandboxAdmission: false, ruleMayClear: false, hookAskFloor: false },
|
|
331
329
|
org_unreadable: { bypassImmune: true, classifierEligible: false, sandboxAdmission: false, ruleMayClear: false, hookAskFloor: false },
|
|
@@ -347,10 +345,12 @@ export const MODE_ARBITRATION = {
|
|
|
347
345
|
policy_rra: { bypassImmune: true, classifierEligible: true, sandboxAdmission: false, ruleMayClear: false, hookAskFloor: false },
|
|
348
346
|
artifact_shared_read: { bypassImmune: false, classifierEligible: true, sandboxAdmission: false, ruleMayClear: false, hookAskFloor: true },
|
|
349
347
|
mode: { bypassImmune: false, classifierEligible: false, sandboxAdmission: false, ruleMayClear: false, hookAskFloor: false },
|
|
348
|
+
unverifiable_delete: ORDINARY_ROW,
|
|
349
|
+
unverifiable_shell_text: ORDINARY_ROW,
|
|
350
350
|
sandbox_override: { bypassImmune: false, classifierEligible: true, sandboxAdmission: false, ruleMayClear: true, hookAskFloor: true },
|
|
351
351
|
sandbox_network: { bypassImmune: false, classifierEligible: true, sandboxAdmission: false, ruleMayClear: true, hookAskFloor: false },
|
|
352
352
|
unstated: { bypassImmune: false, classifierEligible: true, sandboxAdmission: false, ruleMayClear: true, hookAskFloor: false },
|
|
353
|
-
ordinary:
|
|
353
|
+
ordinary: ORDINARY_ROW,
|
|
354
354
|
};
|
|
355
355
|
export const ASK_FACES = Object.freeze(["shell", "other"]);
|
|
356
356
|
export function askFaceOf(toolName) {
|
|
@@ -364,7 +364,13 @@ function bypassImmuneOf(c) {
|
|
|
364
364
|
return [...c.classes].some((k) => bypassImmuneOn(k, c.askFace));
|
|
365
365
|
}
|
|
366
366
|
const CLASSIFIER_WITHHELD_ON_ROOTS = new Set(["probe"]);
|
|
367
|
-
|
|
367
|
+
function unfinishedCheck(classes) {
|
|
368
|
+
return classes.has("unverifiable_shell_text") && classes.has("policy_rra");
|
|
369
|
+
}
|
|
370
|
+
function bareBit(d, classes, record) {
|
|
371
|
+
return d.requiresRealApproval === true && (!explainsRealApprovalBit(classes) || record?.guards?.includes("unverifiable_shell_text") === true);
|
|
372
|
+
}
|
|
373
|
+
export const RRA_EXPLAINERS = new Set(["dangerous_delete", "transcript_write", "org_rule", "org_unreadable", "rule_unreadable", "call_unreadable", "denial_limit_fallback", "classifier_no_ruling", "ancestor", "artifact_shared_read", "requires_user_interaction", "cross_boundary"]);
|
|
368
374
|
export function explainsRealApprovalBit(classes) {
|
|
369
375
|
for (const c of classes)
|
|
370
376
|
if (RRA_EXPLAINERS.has(c))
|
|
@@ -419,7 +425,7 @@ export function ownAskClassesOf(d, record) {
|
|
|
419
425
|
out.add("hook");
|
|
420
426
|
if (d.decisionReason === "mode")
|
|
421
427
|
out.add("mode");
|
|
422
|
-
if (d
|
|
428
|
+
if (bareBit(d, out, record))
|
|
423
429
|
out.add("policy_rra");
|
|
424
430
|
if (out.size === 0 && d.mandated === true)
|
|
425
431
|
out.add("operator_forced");
|
|
@@ -435,8 +441,9 @@ export function decisionAskClassesOf(d, call) {
|
|
|
435
441
|
export function foldArbitrationRow(classes, readFace, askFace) {
|
|
436
442
|
if (classes.size === 0)
|
|
437
443
|
return MODE_ARBITRATION.ordinary;
|
|
438
|
-
const
|
|
439
|
-
|
|
444
|
+
const unfinished = unfinishedCheck(classes);
|
|
445
|
+
const withheld = unfinished || (readFace === "roots" && [...classes].some((c) => CLASSIFIER_WITHHELD_ON_ROOTS.has(c)));
|
|
446
|
+
let bypassImmune = false, classifierEligible = !withheld, sandboxAdmission = true, ruleMayClear = true, hookAskFloor = unfinished;
|
|
440
447
|
for (const c of classes) {
|
|
441
448
|
const row = MODE_ARBITRATION[c];
|
|
442
449
|
bypassImmune ||= bypassImmuneOn(c, askFace);
|
|
@@ -492,7 +499,7 @@ export function classifyAsk(d, facts) {
|
|
|
492
499
|
classes.add("unstated");
|
|
493
500
|
for (const c of facts.ancestorClasses ?? [])
|
|
494
501
|
classes.add(c);
|
|
495
|
-
if (d
|
|
502
|
+
if (bareBit(d, classes, record))
|
|
496
503
|
classes.add("policy_rra");
|
|
497
504
|
for (const c of record?.foldedClasses ?? [])
|
|
498
505
|
classes.add(c);
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* beside it, only the words no attachment-lane producer owns — so a word added here reaches the echo with no second edit, and a
|
|
8
8
|
* word is a member of this set or one of those, never both.
|
|
9
9
|
*/
|
|
10
|
-
export declare const ATTACHMENT_SOURCES: readonly ["todo_reminder", "task_reminder", "tool_search_usage_reminder", "changed_files", "output_style", "date_change", "workflow_size_guideline_change", "budget_usd", "total_tokens_reminder", "background_tasks", "tools_delta", "mcp_unavailable", "agent_listing", "skills_listing", "mcp_instructions", "mcp_dropped_tools", "workflow_continuation"];
|
|
10
|
+
export declare const ATTACHMENT_SOURCES: readonly ["todo_reminder", "task_reminder", "tool_search_usage_reminder", "changed_files", "output_style", "date_change", "workflow_size_guideline_change", "budget_usd", "total_tokens_reminder", "background_tasks", "tools_delta", "mcp_unavailable", "agent_listing", "skills_listing", "mcp_instructions", "mcp_dropped_tools", "workflow_continuation", "skill_mention"];
|
|
11
11
|
export type AttachmentSource = (typeof ATTACHMENT_SOURCES)[number];
|
|
12
12
|
/** Membership test for {@link AttachmentSource}. */
|
|
13
13
|
export declare function isAttachmentSource(v: unknown): v is AttachmentSource;
|
|
@@ -47,6 +47,15 @@ export type CompactionPhaseDurations = Omit<Extract<TraceEvent, {
|
|
|
47
47
|
* the failure was NOT the withdrawal: a real summarizer error racing a late cancel stays
|
|
48
48
|
* unmarked so the caller's breaker/onError accounting still sees it. */
|
|
49
49
|
export declare function isCompactionManualCancel(err: unknown): boolean;
|
|
50
|
+
/** The withdrawal a cut of `turn` is while `leg` still runs — the caller's cut (an interrupt of the turn a pass serves). The leg's own
|
|
51
|
+
* stop (the walltime limit, a budget) cuts the turn too and is not one. Joins a pass's `manualCancelSignal`, so the failure site marks
|
|
52
|
+
* a caller's cut only. */
|
|
53
|
+
export declare function turnCutWhileLegRuns(turn: AbortSignal, leg: AbortSignal): AbortSignal;
|
|
54
|
+
/** How a pass that threw reads, by the failure's own cause — never by what the signals say when the catch runs: a withdrawal the
|
|
55
|
+
* failure site marked is the caller's cut (`cancelled`); the pass's own abort outcome with no such mark is the leg's stop
|
|
56
|
+
* (`task_ending`); anything else is a real failure (`failed`, the whole account) — a store's error after a stop included. The one
|
|
57
|
+
* reading of every lane's catch. */
|
|
58
|
+
export declare function compactionCutOf(err: unknown): "cancelled" | "task_ending" | "failed";
|
|
50
59
|
/** The ONE reason a failed compaction pass reports, read by every lane that accounts for one (the turn boundary, the end-of-task pass,
|
|
51
60
|
* the prompt-too-long recovery) for its trace frame and its `compaction_outcome{failed}` event: the thrown value's words through the
|
|
52
61
|
* same-principal tier, THEN bounded — minted before the cut, so the cut can leave no part of a value. */
|
|
@@ -66,14 +75,8 @@ export type CompactionFailureCause = (typeof COMPACTION_FAILURE_CAUSES)[number];
|
|
|
66
75
|
* leaf compare-and-set refusing a write of the pass is `leaf_moved`; anything else names no cause. */
|
|
67
76
|
export declare function compactionFailureCause(err: unknown): CompactionFailureCause | undefined;
|
|
68
77
|
/**
|
|
69
|
-
*
|
|
70
|
-
* (
|
|
71
|
-
* failure). `kind:"fallback"` → the summary call was moved to the MAIN model (window safety);
|
|
72
|
-
* `kind:"clamp_disclosure"` → the small model keeps the call but the conversation WILL be
|
|
73
|
-
* clamp-truncated: `reason` says why the fallback did not happen ("budget" = the gate
|
|
74
|
-
* denied it; "tolerance" = the truncation is within `clampTolerance` — bounded, but no longer
|
|
75
|
-
* silent). All token figures are in the MAIN model's structural coordinate except
|
|
76
|
-
* `headroomTokens` (the小 model's — it describes THAT window's capacity).
|
|
78
|
+
* @deprecated Never produced: the summary always runs on the main model, so there is no window-safety decision to
|
|
79
|
+
* report (`MaybeCompactOptions.onWindowSafety` is never called). Removed in 7.70.0.
|
|
77
80
|
*/
|
|
78
81
|
export interface CompactionWindowSafetyInfo {
|
|
79
82
|
kind: "fallback" | "clamp_disclosure";
|
|
@@ -123,6 +126,13 @@ export interface CompactionForkContext {
|
|
|
123
126
|
/** The recorded request's locale of the engine's own texts (`Context.promptLocale`): a request built from the record
|
|
124
127
|
* (the fork, the advisor) carries it on. */
|
|
125
128
|
promptLocale?: Context["promptLocale"];
|
|
129
|
+
/** The recorded request's own controls as sent — thinking tier, try-undeclared posture, output cap: the reuse form sends
|
|
130
|
+
* them unchanged (the engine-side twin's doc says why). */
|
|
131
|
+
request?: {
|
|
132
|
+
reasoning?: ThinkingLevel;
|
|
133
|
+
tryUndeclared?: boolean;
|
|
134
|
+
maxTokens?: number;
|
|
135
|
+
};
|
|
126
136
|
}
|
|
127
137
|
/**
|
|
128
138
|
* What a compaction pass reports at the moment it commits ({@link MaybeCompactOptions.onStarted}) — and the
|
|
@@ -237,27 +247,18 @@ export interface MaybeCompactOptions {
|
|
|
237
247
|
* measured through it, so an operator who lowers a model's window reaches the legs already running.
|
|
238
248
|
* Absent ⇒ the model card's own declarations, unchanged. */
|
|
239
249
|
contextOverlay?: ContextWindowOverlay;
|
|
240
|
-
/**
|
|
241
|
-
*
|
|
242
|
-
* dry-run clamp shows the conversation would lose more than `settings.clampTolerance` of its
|
|
243
|
-
* chars to fit this model's window, the summary call falls back to the MAIN model (`model`),
|
|
244
|
-
* which is always window-safe (the content grew inside its window; the reference compresses
|
|
245
|
-
* with the main-loop model unconditionally — the fallback IS the CC posture, the independent
|
|
246
|
-
* compaction model is sema's superset). Subagent note (design/145 §5): delegated children never
|
|
247
|
-
* inherit this option (subagent.ts buildChildSpec carries no compactionModel), so a child always
|
|
248
|
-
* self-compacts on its own main model — the judgment is structurally never triggered there. */
|
|
250
|
+
/** @deprecated Received and ignored: the summary always runs on `model` (announced once per process). Refused by name
|
|
251
|
+
* from 7.70.0. */
|
|
249
252
|
compactionModel?: Model;
|
|
250
253
|
/**
|
|
251
|
-
* design/169-A — accessor for the main lane's
|
|
252
|
-
*
|
|
253
|
-
*
|
|
254
|
-
*
|
|
255
|
-
*
|
|
256
|
-
*
|
|
257
|
-
* back ONCE to the independent form inside `compact()` (the fork form must not clamp — a clamp
|
|
258
|
-
* rewrites the cached prefix, defeating the form's purpose).
|
|
254
|
+
* design/169-A — accessor for the main lane's request the summary reuses (see {@link CompactionForkContext}): the
|
|
255
|
+
* latest request a run recorded, or — on the turn-start lane — the request it is about to send. Consulted once per
|
|
256
|
+
* pass, after every gate that can end the pass; it may answer asynchronously. `undefined` (or an accessor answering
|
|
257
|
+
* `undefined`: no request yet, a lossy one, or a library caller driving maybeCompact directly) keeps the independent
|
|
258
|
+
* request form. A reuse-form prompt-too-long drops the oldest message groups and retries in the reuse form inside
|
|
259
|
+
* `compact()` (the reference's shape); an empty or unenveloped reuse-form answer falls back ONCE to the independent form.
|
|
259
260
|
*/
|
|
260
|
-
forkContext?: () => CompactionForkContext | undefined
|
|
261
|
+
forkContext?: () => CompactionForkContext | undefined | Promise<CompactionForkContext | undefined>;
|
|
261
262
|
brain: Brain;
|
|
262
263
|
getApiKeyAndHeaders?: TaskSpec["getApiKeyAndHeaders"];
|
|
263
264
|
thinking?: ThinkingLevel;
|
|
@@ -303,16 +304,8 @@ export interface MaybeCompactOptions {
|
|
|
303
304
|
* never aborts anything by itself (the same signals already ride inside `signal`).
|
|
304
305
|
*/
|
|
305
306
|
manualCancelSignal?: AbortSignal;
|
|
306
|
-
/**
|
|
307
|
-
*
|
|
308
|
-
* of a near-window conversation is one giant prefill whose cost lands in the SAME ledger the
|
|
309
|
-
* budget gate enforces (`recordCompactionUsage` → `stats.costMicroUsd` → `overBudget()`), so an
|
|
310
|
-
* un-gated fallback under a cost cap is the "钱花了任务照死" double loss. When present AND
|
|
311
|
-
* `mainInputPer1M` is known, the fallback is denied if `spentMicroUsd() + contentTokens ×
|
|
312
|
-
* mainInputPer1M > capMicroUsd` — the pass then keeps the small model and DISCLOSES the clamp
|
|
313
|
-
* (`clamp_disclosure`, reason "budget"). Absent field / absent pricing = the gate never blocks
|
|
314
|
-
* (design: "pricing/cap 不可得=门不拦").
|
|
315
|
-
*/
|
|
307
|
+
/** @deprecated Received and ignored: there is no summary-model fallback left to gate (announced once per process).
|
|
308
|
+
* Refused by name from 7.70.0. */
|
|
316
309
|
fallbackBudget?: {
|
|
317
310
|
/** Live cumulative spend reader (the caller's `stats.costMicroUsd` at decision time). */
|
|
318
311
|
spentMicroUsd: () => number;
|
|
@@ -322,12 +315,8 @@ export interface MaybeCompactOptions {
|
|
|
322
315
|
* equal to micro-USD per token, so `est = contentTokens × mainInputPer1M` needs no unit dance. */
|
|
323
316
|
mainInputPer1M?: number;
|
|
324
317
|
};
|
|
325
|
-
/**
|
|
326
|
-
*
|
|
327
|
-
* Fired BEFORE the summary call (survives a later failure, `onInputTruncated` posture); throws
|
|
328
|
-
* are swallowed (observe-only). The caller bridges it to the `compaction.model_fallback` /
|
|
329
|
-
* `compaction.clamp_disclosure` trace frames.
|
|
330
|
-
*/
|
|
318
|
+
/** @deprecated Received and never called: there is no window-safety decision left (announced once per process).
|
|
319
|
+
* Refused by name from 7.70.0. */
|
|
331
320
|
onWindowSafety?: (info: CompactionWindowSafetyInfo) => void;
|
|
332
321
|
/**
|
|
333
322
|
* Anti-thrash re-trigger floor (design/64 §25.2): ALSO require the estimated context to exceed this
|
|
@@ -615,7 +604,9 @@ export interface MaybeCompactOptions {
|
|
|
615
604
|
* truncated to fit the compaction model's context window (the ~300K-session shape that previously
|
|
616
605
|
* guaranteed a provider prompt-too-long throw at every boundary). The caller bridges it to the
|
|
617
606
|
* `compaction.input_truncated` trace frame (fidelity disclosure). Fired BEFORE the summary call, so
|
|
618
|
-
* it reports truncation even when the attempt later fails.
|
|
607
|
+
* it reports truncation even when the attempt later fails. `label` is always `"history"`: a pass sends
|
|
608
|
+
* one summary request over everything it folds (the kept tail starts at a group's opening, so no turn is
|
|
609
|
+
* split and no separate turn-prefix request exists). `"turn_prefix"` is deprecated: always absent, removed in 7.70.0.
|
|
619
610
|
*/
|
|
620
611
|
onInputTruncated?: (info: {
|
|
621
612
|
label: "history" | "turn_prefix";
|
|
@@ -668,7 +659,7 @@ export declare function windowBelowOverheadReason(w: WindowBelowOverhead): strin
|
|
|
668
659
|
* is thrown, not swallowed; callers are expected to catch, count it toward the §17.4 breaker, and
|
|
669
660
|
* surface it via onError. A legitimate nothing-to-compact (under threshold/floor, no cut point)
|
|
670
661
|
* returns `{compacted:false}` quietly.
|
|
671
|
-
*
|
|
662
|
+
* The summary runs on `model` (the main model) — never another one.
|
|
672
663
|
* Zero-config: uses DEFAULT_COMPACTION_SETTINGS unless overridden; settings pathological for the
|
|
673
664
|
* model's window are repaired via {@link sanitizeCompactionSettings}.
|
|
674
665
|
*/
|
|
@@ -740,7 +731,7 @@ export declare function maybeCompact(opts: MaybeCompactOptions): Promise<{
|
|
|
740
731
|
* `persistMs` = restore reads → session rewrite (`appendCompaction`) → restore frames → post measurement →
|
|
741
732
|
* observers. The phases tile the pass exactly: prepareMs + (summaryMs ?? 0) + persistMs ===
|
|
742
733
|
* durationMs. `ptlRetries` = reactive prompt-too-long retries burned inside this pass's summary
|
|
743
|
-
* call(s) (
|
|
734
|
+
* call(s) (0 on provider reuse). Set only when
|
|
744
735
|
* `compacted`. Exposure path note: runtask deliberately NOT touched this batch — the bridge to the
|
|
745
736
|
* `compaction.phase_timings` trace frame (trace.ts, defined-not-yet-emitted) is a follow-up wiring
|
|
746
737
|
* batch that adds an additive passthrough next to runtask's existing
|
|
@@ -793,21 +784,17 @@ export declare function maybeCompact(opts: MaybeCompactOptions): Promise<{
|
|
|
793
784
|
windowTokens: number;
|
|
794
785
|
compactAtTokens: number;
|
|
795
786
|
};
|
|
796
|
-
/**
|
|
797
|
-
*
|
|
787
|
+
/** @deprecated Never set: the summary always runs on the main model, so there is no window fallback to report.
|
|
788
|
+
* Removed in 7.70.0. */
|
|
798
789
|
modelFallback?: true;
|
|
799
|
-
/**
|
|
790
|
+
/** @deprecated Never set (see {@link modelFallback}). Removed in 7.70.0. */
|
|
800
791
|
fallbackReason?: "window";
|
|
801
|
-
/**
|
|
802
|
-
* clamp-truncated on the small model — set when a gate denied the fallback OR the ratio was
|
|
803
|
-
* within tolerance but non-zero. */
|
|
792
|
+
/** @deprecated Never set: the summary input is never clipped to a smaller summary model's window. Removed in 7.70.0. */
|
|
804
793
|
clampedRatio?: number;
|
|
805
|
-
/**
|
|
806
|
-
* ordinary truncation (disclosed, not silent). */
|
|
794
|
+
/** @deprecated Never set (see {@link clampedRatio}). Removed in 7.70.0. */
|
|
807
795
|
clampReason?: "budget" | "tolerance";
|
|
808
796
|
}>;
|
|
809
|
-
/** What a landed compaction hands the wire frame. Structural, so the full `maybeCompact` result satisfies it
|
|
810
|
-
* lane's `EndOfTaskCompaction` is this type itself (plus `compacted`). */
|
|
797
|
+
/** What a landed compaction hands the wire frame. Structural, so the full `maybeCompact` result satisfies it. */
|
|
811
798
|
export interface CompactedFrameSource {
|
|
812
799
|
/** The pass this landing concludes (see {@link MaybeCompactOptions.onStarted}). */
|
|
813
800
|
pass?: string;
|
|
@@ -824,10 +811,6 @@ export interface CompactedFrameSource {
|
|
|
824
811
|
truncated: boolean;
|
|
825
812
|
}>;
|
|
826
813
|
restoreOutcomes?: HumanInputAttachment[];
|
|
827
|
-
modelFallback?: true;
|
|
828
|
-
fallbackReason?: "window";
|
|
829
|
-
clampedRatio?: number;
|
|
830
|
-
clampReason?: "budget" | "tolerance";
|
|
831
814
|
/** Cross-session message frames that sat in the summarized prefix (present iff ≥ 1). */
|
|
832
815
|
summarizedCrossSessionMessages?: number;
|
|
833
816
|
}
|
|
@@ -859,9 +842,8 @@ export interface CompactSessionRequest {
|
|
|
859
842
|
/** The members of `TaskSpec.compaction` a pass reads, as a run would carry them — of the two seats only `manualCompact`
|
|
860
843
|
* (this pass is a requested one; `false` answers `"disabled"`, and absent reads the deployment's twin, else on). */
|
|
861
844
|
compaction?: Pick<NonNullable<TaskSpec["compaction"]>, "manualCompact" | "reserveTokens" | "keepRecentTokens" | "instructions" | "clampTolerance">;
|
|
862
|
-
/**
|
|
863
|
-
*
|
|
864
|
-
* announced, as on a run. */
|
|
845
|
+
/** @deprecated Received and ignored: the summary runs on the request's `model` (announced once per process). Refused by
|
|
846
|
+
* name from 7.70.0. `compaction.clampTolerance` likewise. */
|
|
865
847
|
compactionModel?: ModelRef;
|
|
866
848
|
/** Per-model credentials (`TaskSpec.getApiKeyAndHeaders`). */
|
|
867
849
|
getApiKeyAndHeaders?: TaskSpec["getApiKeyAndHeaders"];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CROSS_SESSION_MESSAGE_TAG } from "../agents/cross-session-envelope.js";
|
|
2
|
-
import { DEFAULT_CHARS_PER_TOKEN,
|
|
2
|
+
import { DEFAULT_CHARS_PER_TOKEN, DEFAULT_COMPACTION_SETTINGS, CompactionError, compact, computeFileLists, estimateContextTokens, estimateTokens, formatFileOperations, formatPersistedOutputRefs, prepareCompaction, shouldCompact, uuidv7, } from "../internal/harness.js";
|
|
3
3
|
import { fileArgPath } from "./tool-registry.js";
|
|
4
4
|
import { userAttachmentOf } from "../internal/llm.js";
|
|
5
5
|
import { askPerModelAuth } from "../brain/route-adjudicator.js";
|
|
@@ -15,6 +15,7 @@ import { appendAdmittedRow } from "./row-admission.js";
|
|
|
15
15
|
import { isSessionConflict } from "./session.js";
|
|
16
16
|
import { egressThrownText } from "./untrusted-egress.js";
|
|
17
17
|
import { restatedFramesTokens } from "./context-guard.js";
|
|
18
|
+
import { announceIgnoredCompactionMember } from "./compaction-retired-members.js";
|
|
18
19
|
export const DEFAULT_COMPACTION_INSTRUCTIONS = "Preserve verbatim every code, identifier, name, number, file path, error message, credential " +
|
|
19
20
|
"reference, and explicit user instruction or decision mentioned anywhere in the conversation. " +
|
|
20
21
|
"When in doubt, keep the specific detail rather than generalizing it.";
|
|
@@ -41,15 +42,35 @@ async function untilPassCut(start, signal) {
|
|
|
41
42
|
release = () => signal.removeEventListener("abort", onAbort);
|
|
42
43
|
});
|
|
43
44
|
try {
|
|
44
|
-
return await Promise.race([
|
|
45
|
+
return await Promise.race([cut, (async () => await start())()]);
|
|
45
46
|
}
|
|
46
47
|
finally {
|
|
47
48
|
release();
|
|
48
49
|
}
|
|
49
50
|
}
|
|
51
|
+
function passCutOutcome(opts, words) {
|
|
52
|
+
return Object.assign(new CompactionError("aborted", words), opts.manualCancelSignal?.aborted === true ? { [COMPACTION_MANUAL_CANCEL_FLAG]: true } : {});
|
|
53
|
+
}
|
|
50
54
|
export function isCompactionManualCancel(err) {
|
|
51
55
|
return (typeof err === "object" && err !== null && err[COMPACTION_MANUAL_CANCEL_FLAG] === true);
|
|
52
56
|
}
|
|
57
|
+
export function turnCutWhileLegRuns(turn, leg) {
|
|
58
|
+
const cut = new AbortController();
|
|
59
|
+
const fire = () => {
|
|
60
|
+
if (!leg.aborted)
|
|
61
|
+
cut.abort(turn.reason);
|
|
62
|
+
};
|
|
63
|
+
if (turn.aborted)
|
|
64
|
+
fire();
|
|
65
|
+
else
|
|
66
|
+
turn.addEventListener("abort", fire, { once: true });
|
|
67
|
+
return cut.signal;
|
|
68
|
+
}
|
|
69
|
+
export function compactionCutOf(err) {
|
|
70
|
+
if (isCompactionManualCancel(err))
|
|
71
|
+
return "cancelled";
|
|
72
|
+
return err instanceof CompactionError && err.code === "aborted" ? "task_ending" : "failed";
|
|
73
|
+
}
|
|
53
74
|
const COMPACTION_FAILURE_REASON_MAX = 512;
|
|
54
75
|
export function compactionFailureReason(err) {
|
|
55
76
|
const words = egressThrownText("same-principal", err);
|
|
@@ -59,24 +80,17 @@ export const COMPACTION_FAILURE_CAUSES = Object.freeze(["leaf_moved"]);
|
|
|
59
80
|
export function compactionFailureCause(err) {
|
|
60
81
|
return isSessionConflict(err) ? "leaf_moved" : undefined;
|
|
61
82
|
}
|
|
62
|
-
function summarizationCharsCapacity(model) {
|
|
63
|
-
return model.contextWindow > 0
|
|
64
|
-
? model.contextWindow * (model.charsPerToken ?? DEFAULT_CHARS_PER_TOKEN)
|
|
65
|
-
: Number.POSITIVE_INFINITY;
|
|
66
|
-
}
|
|
67
83
|
export const STALE_ANCHOR_STRUCTURAL_MARGIN = 2;
|
|
68
84
|
export function sanitizeCompactionSettings(settings, contextWindow) {
|
|
69
85
|
const wide = settings;
|
|
70
86
|
const reserveInvalid = !Number.isFinite(wide.reserveTokens);
|
|
71
87
|
const keepRecentInvalid = !Number.isFinite(wide.keepRecentTokens);
|
|
72
|
-
const clampToleranceInvalid = wide.clampTolerance !== undefined && !Number.isFinite(wide.clampTolerance);
|
|
73
88
|
const summaryBudgetInvalid = wide.summaryOutputBudgetTokens !== undefined && !Number.isFinite(wide.summaryOutputBudgetTokens);
|
|
74
|
-
const base = reserveInvalid || keepRecentInvalid ||
|
|
89
|
+
const base = reserveInvalid || keepRecentInvalid || summaryBudgetInvalid
|
|
75
90
|
? {
|
|
76
91
|
...settings,
|
|
77
92
|
...(reserveInvalid ? { reserveTokens: DEFAULT_COMPACTION_SETTINGS.reserveTokens } : {}),
|
|
78
93
|
...(keepRecentInvalid ? { keepRecentTokens: DEFAULT_COMPACTION_SETTINGS.keepRecentTokens } : {}),
|
|
79
|
-
...(clampToleranceInvalid ? { clampTolerance: DEFAULT_CLAMP_TOLERANCE } : {}),
|
|
80
94
|
...(summaryBudgetInvalid ? { summaryOutputBudgetTokens: undefined } : {}),
|
|
81
95
|
}
|
|
82
96
|
: settings;
|
|
@@ -148,6 +162,12 @@ export function windowBelowOverheadReason(w) {
|
|
|
148
162
|
}
|
|
149
163
|
export async function maybeCompact(opts) {
|
|
150
164
|
const compactStartAt = Date.now();
|
|
165
|
+
if (opts.compactionModel !== undefined)
|
|
166
|
+
announceIgnoredCompactionMember("maybeCompact.compactionModel", undefined);
|
|
167
|
+
if (opts.fallbackBudget !== undefined)
|
|
168
|
+
announceIgnoredCompactionMember("maybeCompact.fallbackBudget", undefined);
|
|
169
|
+
if (opts.onWindowSafety !== undefined)
|
|
170
|
+
announceIgnoredCompactionMember("maybeCompact.onWindowSafety", undefined);
|
|
151
171
|
const rawSettings = opts.settings ?? DEFAULT_COMPACTION_SETTINGS;
|
|
152
172
|
if (!rawSettings.enabled) {
|
|
153
173
|
return { compacted: false, disabled: true };
|
|
@@ -207,10 +227,8 @@ export async function maybeCompact(opts) {
|
|
|
207
227
|
const asWritten = new Map();
|
|
208
228
|
for (const [written, sent] of asSent)
|
|
209
229
|
asWritten.set(sent, written);
|
|
210
|
-
const ownRequest = (slice) => projectRequestCopies(slice.map((m) => asWritten.get(m) ?? m));
|
|
211
230
|
const messagesCompacted = prep.value.messagesToSummarize.length;
|
|
212
|
-
prep.value.messagesToSummarize =
|
|
213
|
-
prep.value.turnPrefixMessages = ownRequest(prep.value.turnPrefixMessages);
|
|
231
|
+
prep.value.messagesToSummarize = projectRequestCopies(prep.value.messagesToSummarize.map((m) => asWritten.get(m) ?? m));
|
|
214
232
|
const trigger = opts.trigger ?? "auto";
|
|
215
233
|
const notifier = createSafeNotifier(opts.onNotifyError !== undefined ? { onError: opts.onNotifyError } : undefined);
|
|
216
234
|
let hookInstructions;
|
|
@@ -242,15 +260,14 @@ export async function maybeCompact(opts) {
|
|
|
242
260
|
: hookSanitized
|
|
243
261
|
: specInstructions;
|
|
244
262
|
const signalAtCommit = opts.signal;
|
|
245
|
-
if (signalAtCommit?.aborted === true)
|
|
246
|
-
throw
|
|
247
|
-
}
|
|
263
|
+
if (signalAtCommit?.aborted === true)
|
|
264
|
+
throw passCutOutcome(opts, "compaction cancelled before the pass committed — nothing was summarized or persisted");
|
|
248
265
|
const pass = uuidv7();
|
|
249
266
|
notifier.notify(() => observeThenableRejection(opts.onStarted?.({ pass, trigger, startedAt: Date.now() }), notifier, "compaction.onStarted"), "compaction.onStarted");
|
|
250
267
|
const maxReuse = opts.maxConsecutiveProviderReuse ?? 3;
|
|
251
268
|
const forceRealSummary = maxReuse > 0 && (opts.consecutiveProviderReuse ?? 0) >= maxReuse;
|
|
252
269
|
let providerSummary;
|
|
253
|
-
if (opts.summaryProvider && !forceRealSummary
|
|
270
|
+
if (opts.summaryProvider && !forceRealSummary) {
|
|
254
271
|
const providerModifiedFiles = computeFileLists(prep.value.fileOps).modifiedFilesByRecency;
|
|
255
272
|
const summaryProvider = opts.summaryProvider;
|
|
256
273
|
const boundary = prep.value;
|
|
@@ -268,17 +285,13 @@ export async function maybeCompact(opts) {
|
|
|
268
285
|
}
|
|
269
286
|
catch {
|
|
270
287
|
}
|
|
271
|
-
if (consulted === PASS_CUT)
|
|
272
|
-
throw
|
|
273
|
-
}
|
|
288
|
+
if (consulted === PASS_CUT)
|
|
289
|
+
throw passCutOutcome(opts, "compaction cancelled while the summary provider was answering — nothing was persisted");
|
|
274
290
|
}
|
|
275
291
|
let summary;
|
|
276
292
|
let firstKeptEntryId;
|
|
277
293
|
let summaryTokensBefore;
|
|
278
294
|
let details;
|
|
279
|
-
let modelFallback = false;
|
|
280
|
-
let clampedRatio;
|
|
281
|
-
let clampReason;
|
|
282
295
|
let summaryStartAt;
|
|
283
296
|
let summaryEndAt;
|
|
284
297
|
let ptlRetries = 0;
|
|
@@ -306,81 +319,17 @@ export async function maybeCompact(opts) {
|
|
|
306
319
|
}
|
|
307
320
|
}
|
|
308
321
|
else {
|
|
309
|
-
|
|
310
|
-
const wantsWindowSafety = opts.compactionModel !== undefined &&
|
|
311
|
-
summarizationCharsCapacity(opts.compactionModel) < summarizationCharsCapacity(opts.model);
|
|
312
|
-
let dry;
|
|
313
|
-
if (wantsWindowSafety) {
|
|
314
|
-
dry = dryRunSummarizationClamp(prep.value, summaryModel, effectiveInstructions);
|
|
315
|
-
}
|
|
316
|
-
const mainSection = dry !== undefined && prep.value.contextInstructionFiles !== undefined
|
|
317
|
-
? dryRunSummarizationClamp(prep.value, opts.model, effectiveInstructions).instructionFilesChars
|
|
318
|
-
: 0;
|
|
319
|
-
const contentTokens = dry !== undefined
|
|
320
|
-
? Math.ceil((dry.conversationChars + mainSection + (prep.value.previousSummary?.length ?? 0)) / cpt)
|
|
321
|
-
: 0;
|
|
322
|
-
const observeWindowSafety = (info) => {
|
|
323
|
-
notifier.notify(() => opts.onWindowSafety?.(info), "compaction.onWindowSafety");
|
|
324
|
-
};
|
|
325
|
-
if (wantsWindowSafety && dry !== undefined) {
|
|
326
|
-
const tolerance = settings.clampTolerance ?? DEFAULT_CLAMP_TOLERANCE;
|
|
327
|
-
const smallCpt = summaryModel.charsPerToken ?? DEFAULT_CHARS_PER_TOKEN;
|
|
328
|
-
const headroomTokens = Math.ceil(dry.keptChars / smallCpt);
|
|
329
|
-
if (dry.truncationRatio > tolerance) {
|
|
330
|
-
let gate;
|
|
331
|
-
let estCostMicroUsd;
|
|
332
|
-
const bg = opts.fallbackBudget;
|
|
333
|
-
if (bg?.mainInputPer1M !== undefined) {
|
|
334
|
-
estCostMicroUsd = Math.round(contentTokens * bg.mainInputPer1M);
|
|
335
|
-
if (bg.spentMicroUsd() + estCostMicroUsd > bg.capMicroUsd) {
|
|
336
|
-
gate = "budget";
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
if (gate === undefined) {
|
|
340
|
-
summaryModel = opts.model;
|
|
341
|
-
modelFallback = true;
|
|
342
|
-
observeWindowSafety({
|
|
343
|
-
kind: "fallback",
|
|
344
|
-
truncationRatio: dry.truncationRatio,
|
|
345
|
-
contentTokens,
|
|
346
|
-
headroomTokens,
|
|
347
|
-
...(estCostMicroUsd !== undefined ? { estCostMicroUsd } : {}),
|
|
348
|
-
});
|
|
349
|
-
}
|
|
350
|
-
else {
|
|
351
|
-
clampedRatio = dry.truncationRatio;
|
|
352
|
-
clampReason = gate;
|
|
353
|
-
observeWindowSafety({
|
|
354
|
-
kind: "clamp_disclosure",
|
|
355
|
-
reason: gate,
|
|
356
|
-
truncationRatio: dry.truncationRatio,
|
|
357
|
-
contentTokens,
|
|
358
|
-
headroomTokens,
|
|
359
|
-
...(estCostMicroUsd !== undefined ? { estCostMicroUsd } : {}),
|
|
360
|
-
});
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
else if (dry.truncationRatio > 0) {
|
|
364
|
-
clampedRatio = dry.truncationRatio;
|
|
365
|
-
clampReason = "tolerance";
|
|
366
|
-
observeWindowSafety({
|
|
367
|
-
kind: "clamp_disclosure",
|
|
368
|
-
reason: "tolerance",
|
|
369
|
-
truncationRatio: dry.truncationRatio,
|
|
370
|
-
contentTokens,
|
|
371
|
-
headroomTokens,
|
|
372
|
-
});
|
|
373
|
-
}
|
|
374
|
-
}
|
|
322
|
+
const summaryModel = opts.model;
|
|
375
323
|
const getApiKeyAndHeaders = opts.getApiKeyAndHeaders;
|
|
376
324
|
const authed = getApiKeyAndHeaders === undefined ? undefined : await untilPassCut(() => askPerModelAuth(getApiKeyAndHeaders, summaryModel), opts.signal);
|
|
377
|
-
if (authed === PASS_CUT)
|
|
378
|
-
throw
|
|
379
|
-
}
|
|
325
|
+
if (authed === PASS_CUT)
|
|
326
|
+
throw passCutOutcome(opts, "compaction cancelled while the summary model's credentials were being fetched — nothing was summarized or persisted");
|
|
380
327
|
const auth = authed;
|
|
381
328
|
const summarySignal = opts.signal;
|
|
382
329
|
const runtime = brainToRuntime(opts.brain);
|
|
383
|
-
const forkCandidate = opts.
|
|
330
|
+
const forkCandidate = opts.forkContext === undefined ? undefined : await untilPassCut(() => opts.forkContext?.(), opts.signal);
|
|
331
|
+
if (forkCandidate === PASS_CUT)
|
|
332
|
+
throw passCutOutcome(opts, "compaction cancelled while the request it reuses was being rendered — nothing was summarized or persisted");
|
|
384
333
|
const forkContext = forkCandidate !== undefined && (forkCandidate.modelId === undefined || forkCandidate.modelId === summaryModel.id) ? forkCandidate : undefined;
|
|
385
334
|
let res;
|
|
386
335
|
summaryStartAt = Date.now();
|
|
@@ -534,9 +483,8 @@ export async function maybeCompact(opts) {
|
|
|
534
483
|
const identityNow = ca?.promptIdentity ?? opts.promptIdentity ?? (current !== undefined ? { layers: current.layers, ...(current.sourceRevision !== undefined ? { sourceRevision: current.sourceRevision } : {}) } : undefined);
|
|
535
484
|
const restatedEpoch = identityNow !== undefined ? selectCompactionEpoch(current, identityNow.layers, identityNow.sourceRevision) : undefined;
|
|
536
485
|
const restatedListings = await opts.session.getAnnouncedListing().catch(() => undefined);
|
|
537
|
-
if (opts.signal?.aborted === true)
|
|
538
|
-
throw
|
|
539
|
-
}
|
|
486
|
+
if (opts.signal?.aborted === true)
|
|
487
|
+
throw passCutOutcome(opts, "compaction cancelled before commit — the abort signal fired after the summary was produced; nothing was persisted");
|
|
540
488
|
await opts.session.appendCompaction(summary, firstKeptEntryId, summaryTokensBefore, {
|
|
541
489
|
...(details ?? {}),
|
|
542
490
|
...(restatedEpoch !== undefined ? { promptEpoch: restatedEpoch } : {}),
|
|
@@ -654,9 +602,6 @@ export async function maybeCompact(opts) {
|
|
|
654
602
|
: {}),
|
|
655
603
|
...(attachedFiles.length > 0 ? { attachedFiles } : {}),
|
|
656
604
|
...(restoreOutcomes.length > 0 ? { restoreOutcomes } : {}),
|
|
657
|
-
...(modelFallback ? { modelFallback: true, fallbackReason: "window" } : {}),
|
|
658
|
-
...(clampedRatio !== undefined ? { clampedRatio } : {}),
|
|
659
|
-
...(clampReason !== undefined ? { clampReason } : {}),
|
|
660
605
|
};
|
|
661
606
|
}
|
|
662
607
|
export function mintCompactedEvent(comp, trigger, identity) {
|
|
@@ -673,10 +618,6 @@ export function mintCompactedEvent(comp, trigger, identity) {
|
|
|
673
618
|
...(comp.firstKeptEntryId !== undefined ? { preserved_segment: { firstKeptEntryId: comp.firstKeptEntryId } } : {}),
|
|
674
619
|
...(comp.attachedFiles !== undefined ? { attachedFiles: comp.attachedFiles } : {}),
|
|
675
620
|
...(comp.restoreOutcomes !== undefined ? { restoreOutcomes: comp.restoreOutcomes } : {}),
|
|
676
|
-
...(comp.modelFallback ? { modelFallback: true } : {}),
|
|
677
|
-
...(comp.fallbackReason !== undefined ? { fallbackReason: comp.fallbackReason } : {}),
|
|
678
|
-
...(comp.clampedRatio !== undefined ? { clampedRatio: comp.clampedRatio } : {}),
|
|
679
|
-
...(comp.clampReason !== undefined ? { clampReason: comp.clampReason } : {}),
|
|
680
621
|
...(comp.summarizedCrossSessionMessages !== undefined ? { summarizedCrossSessionMessages: comp.summarizedCrossSessionMessages } : {}),
|
|
681
622
|
...identity,
|
|
682
623
|
};
|