@sema-agent/core 7.70.0 → 7.71.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 +740 -0
- package/dist/agents/agent-transcript-tool.js +43 -19
- package/dist/agents/inherited-tool-pool.d.ts +5 -1
- package/dist/agents/inherited-tool-pool.js +6 -0
- package/dist/agents/retain-ledger.js +2 -0
- package/dist/agents/send-message-tool.d.ts +12 -1
- package/dist/agents/send-message-tool.js +47 -9
- package/dist/agents/subagent.js +31 -10
- package/dist/agents/tool-filter.js +1 -2
- package/dist/agents/verify.js +13 -2
- package/dist/agents/yield-adoption.js +11 -1
- package/dist/brain/claude-model-id.d.ts +11 -0
- package/dist/brain/claude-model-id.js +3 -1
- package/dist/config/catalog.js +10 -1
- package/dist/config/defaults.d.ts +3 -0
- package/dist/config/defaults.js +1 -0
- package/dist/core/allow-entry.js +1 -2
- package/dist/core/ask-origin.d.ts +55 -21
- package/dist/core/ask-origin.js +19 -11
- package/dist/core/ask-question.d.ts +4 -7
- package/dist/core/ask-question.js +2 -4
- package/dist/core/ask-unresolvable-notice.d.ts +17 -3
- package/dist/core/ask-unresolvable-notice.js +18 -4
- package/dist/core/attachment-source.d.ts +1 -1
- package/dist/core/attachment-source.js +2 -0
- package/dist/core/auto-compaction.d.ts +14 -4
- package/dist/core/auto-compaction.js +3 -2
- package/dist/core/auto-strip.js +2 -0
- package/dist/core/caller-text.d.ts +2 -33
- package/dist/core/caller-text.js +2 -23
- package/dist/core/caller-tool-name.js +1 -2
- package/dist/core/canonical-json.d.ts +9 -0
- package/dist/core/canonical-json.js +6 -0
- package/dist/core/checkpoint-features.d.ts +43 -80
- package/dist/core/checkpoint-features.js +10 -20
- package/dist/core/checkpoint-generation.d.ts +89 -19
- package/dist/core/checkpoint-generation.js +89 -14
- package/dist/core/checkpoint-queries.d.ts +95 -15
- package/dist/core/checkpoint-queries.js +108 -7
- package/dist/core/checkpoint-rekey.d.ts +2 -1
- package/dist/core/checkpoint-rekey.js +2 -2
- package/dist/core/checkpoint-requirements.d.ts +21 -7
- package/dist/core/checkpoint-requirements.js +2 -5
- package/dist/core/checkpoint-row-verdict.d.ts +3 -4
- package/dist/core/checkpoint-row-verdict.js +20 -41
- package/dist/core/checkpoint-store.d.ts +69 -41
- package/dist/core/checkpoint-store.js +28 -14
- package/dist/core/command-sandbox.d.ts +5 -3
- package/dist/core/command-sandbox.js +17 -9
- package/dist/core/config-refusal-codes.d.ts +1 -1
- package/dist/core/config-refusal-codes.js +1 -0
- package/dist/core/declaration-words.d.ts +2 -1
- package/dist/core/declaration-words.js +13 -2
- package/dist/core/effective-path-target.d.ts +23 -0
- package/dist/core/effective-path-target.js +15 -1
- package/dist/core/engine-attestation.d.ts +5 -1
- package/dist/core/engine-attestation.js +1 -0
- package/dist/core/engine-capabilities.d.ts +14 -9
- package/dist/core/engine-capabilities.js +1 -1
- package/dist/core/engine-notice.d.ts +62 -32
- package/dist/core/engine-version.js +1 -1
- package/dist/core/entries-not-applied.d.ts +1 -1
- package/dist/core/entries-not-applied.js +1 -0
- package/dist/core/file-history-store.d.ts +95 -11
- package/dist/core/file-history-store.js +117 -19
- package/dist/core/gate-fold.js +13 -7
- package/dist/core/gate-lanes.js +9 -9
- package/dist/core/governance-codes.d.ts +56 -7
- package/dist/core/governance-codes.js +105 -7
- package/dist/core/grant-holder.d.ts +53 -0
- package/dist/core/grant-holder.js +80 -0
- package/dist/core/hooks.d.ts +7 -3
- package/dist/core/hooks.js +2 -2
- package/dist/core/locked-config.d.ts +7 -1
- package/dist/core/locked-config.js +9 -2
- package/dist/core/mcp-call-meta.d.ts +52 -7
- package/dist/core/mcp-call-meta.js +21 -2
- package/dist/core/mcp-host-read.d.ts +1 -1
- package/dist/core/mcp-server-spec.d.ts +18 -0
- package/dist/core/mcp-server-spec.js +1 -0
- package/dist/core/mcp.js +2 -2
- package/dist/core/member-outcome.d.ts +22 -1
- package/dist/core/member-outcome.js +18 -6
- package/dist/core/memory-engine/delegation-settlement.js +5 -5
- package/dist/core/memory-engine/engine.js +19 -19
- package/dist/core/memory-engine/file-backend.d.ts +7 -2
- package/dist/core/memory-engine/file-backend.js +14 -12
- package/dist/core/memory-engine/frontmatter.js +1 -1
- package/dist/core/memory-engine/index.d.ts +1 -0
- package/dist/core/memory-engine/index.js +1 -0
- package/dist/core/memory-engine/layout.d.ts +34 -9
- package/dist/core/memory-engine/layout.js +36 -19
- package/dist/core/memory-engine/memory-deployment.js +8 -8
- package/dist/core/memory-engine/mount-failed-notice.d.ts +8 -5
- package/dist/core/memory-engine/mount-failed-notice.js +5 -2
- package/dist/core/mode-policy.d.ts +5 -0
- package/dist/core/mode-policy.js +6 -0
- package/dist/core/mods/host.d.ts +2 -1
- package/dist/core/mods/host.js +7 -6
- package/dist/core/mods/kernel/index.d.ts +1 -1
- package/dist/core/mods/kernel/index.js +1 -1
- package/dist/core/mods/kernel/registration.d.ts +5 -2
- package/dist/core/mods/kernel/registration.js +19 -3
- package/dist/core/mods/package.d.ts +12 -1
- package/dist/core/mods/package.js +36 -9
- package/dist/core/mods/stations.d.ts +7 -1
- package/dist/core/mods/stations.js +17 -3
- package/dist/core/mods/teammate-stations.d.ts +4 -1
- package/dist/core/mods/teammate-stations.js +1 -1
- package/dist/core/native-signal.d.ts +13 -0
- package/dist/core/native-signal.js +18 -0
- package/dist/core/park-resumability.d.ts +16 -14
- package/dist/core/park-resumability.js +9 -4
- package/dist/core/path-rule-binding.js +1 -1
- package/dist/core/permission-rule-model.d.ts +11 -5
- package/dist/core/permission-rule-model.js +5 -3
- package/dist/core/permission-rule-org.js +1 -1
- package/dist/core/permission-rule-provider.d.ts +5 -1
- package/dist/core/permission-rule-provider.js +6 -1
- package/dist/core/permission-rule-session.d.ts +35 -5
- package/dist/core/permission-rule-session.js +32 -1
- package/dist/core/permission-rule-store.d.ts +5 -1
- package/dist/core/permission-rule-store.js +28 -5
- package/dist/core/permission-rules.d.ts +2 -2
- package/dist/core/permission-rules.js +2 -3
- package/dist/core/principal-name.d.ts +12 -0
- package/dist/core/principal-name.js +6 -2
- package/dist/core/read-root-grant-screen.d.ts +7 -6
- package/dist/core/read-root-grant-screen.js +7 -8
- package/dist/core/remote-env.d.ts +42 -8
- package/dist/core/resume-config-judge.js +1 -1
- package/dist/core/resume-startup-cause.d.ts +19 -4
- package/dist/core/resume-startup-cause.js +25 -6
- package/dist/core/rewind-conversation.d.ts +4 -0
- package/dist/core/rewrite-rejudge.d.ts +9 -1
- package/dist/core/rewrite-rejudge.js +11 -1
- package/dist/core/rule-offer-read.js +3 -2
- package/dist/core/runner/assemble-result.d.ts +21 -11
- package/dist/core/runner/assemble-result.js +24 -4
- package/dist/core/runner/boundary-reminders.d.ts +104 -0
- package/dist/core/runner/boundary-reminders.js +108 -0
- package/dist/core/runner/branch-writeback.d.ts +21 -7
- package/dist/core/runner/branch-writeback.js +44 -6
- package/dist/core/runner/command-sandbox-frame.js +2 -1
- package/dist/core/runner/compact-session.js +11 -4
- package/dist/core/runner/constraint-layers.d.ts +24 -5
- package/dist/core/runner/constraint-layers.js +21 -2
- package/dist/core/runner/continuation-gate.js +3 -1
- package/dist/core/runner/contracts.d.ts +83 -13
- package/dist/core/runner/cross-boundary-lane.js +2 -1
- package/dist/core/runner/delegation-owner.d.ts +246 -45
- package/dist/core/runner/delegation-owner.js +237 -63
- package/dist/core/runner/expire-settle.d.ts +17 -0
- package/dist/core/runner/expire-settle.js +8 -2
- package/dist/core/runner/file-history-request.d.ts +4 -3
- package/dist/core/runner/file-history-request.js +4 -1
- package/dist/core/runner/file-history-restore.d.ts +11 -3
- package/dist/core/runner/file-history-restore.js +11 -3
- package/dist/core/runner/gate-exit.d.ts +22 -1
- package/dist/core/runner/gate-exit.js +12 -14
- package/dist/core/runner/nested-memory-content.js +1 -1
- package/dist/core/runner/nested-memory-lane.d.ts +10 -2
- package/dist/core/runner/nested-memory-lane.js +29 -8
- package/dist/core/runner/own-model-money-door.d.ts +13 -0
- package/dist/core/runner/own-model-money-door.js +17 -0
- package/dist/core/runner/park-commit.d.ts +4 -2
- package/dist/core/runner/park-commit.js +2 -1
- package/dist/core/runner/permission-rule-lanes.d.ts +4 -0
- package/dist/core/runner/permission-rule-lanes.js +7 -0
- package/dist/core/runner/person-path-rows.js +1 -1
- package/dist/core/runner/placement-fence.d.ts +8 -2
- package/dist/core/runner/placement-fence.js +8 -3
- package/dist/core/runner/policy-throw.d.ts +3 -2
- package/dist/core/runner/policy-throw.js +2 -2
- package/dist/core/runner/prepare-acquire-reconcile.d.ts +23 -14
- package/dist/core/runner/prepare-acquire-reconcile.js +33 -15
- package/dist/core/runner/prepare-artifact.d.ts +14 -1
- package/dist/core/runner/prepare-artifact.js +7 -2
- package/dist/core/runner/prepare-ask-lane.d.ts +8 -0
- package/dist/core/runner/prepare-ask-lane.js +14 -5
- package/dist/core/runner/prepare-boundary-parks.js +5 -4
- package/dist/core/runner/prepare-config-doors.d.ts +9 -4
- package/dist/core/runner/prepare-config-doors.js +25 -8
- package/dist/core/runner/prepare-defer-classify.d.ts +8 -4
- package/dist/core/runner/prepare-defer-classify.js +6 -6
- package/dist/core/runner/prepare-execution-env.d.ts +4 -1
- package/dist/core/runner/prepare-execution-env.js +8 -3
- package/dist/core/runner/prepare-file-history.d.ts +26 -0
- package/dist/core/runner/prepare-file-history.js +15 -1
- package/dist/core/runner/prepare-inherited-gate.d.ts +8 -3
- package/dist/core/runner/prepare-inherited-gate.js +9 -2
- package/dist/core/runner/prepare-leg-adoption.d.ts +2 -2
- package/dist/core/runner/prepare-park-ask.js +8 -5
- package/dist/core/runner/prepare-policy-chain.d.ts +5 -0
- package/dist/core/runner/prepare-policy-chain.js +18 -7
- package/dist/core/runner/prepare-prompt-assembly.d.ts +3 -0
- package/dist/core/runner/prepare-prompt-assembly.js +4 -3
- package/dist/core/runner/prepare-suspend-saga.d.ts +4 -1
- package/dist/core/runner/prepare-suspend-saga.js +19 -5
- package/dist/core/runner/prepare-task.d.ts +2 -5
- package/dist/core/runner/prepare-task.js +71 -26
- package/dist/core/runner/prepare-turn-wiring.js +7 -5
- package/dist/core/runner/prepare-workspace-restore.js +59 -28
- package/dist/core/runner/read-root-grant.d.ts +1 -0
- package/dist/core/runner/read-root-grant.js +1 -2
- package/dist/core/runner/resume-admission.d.ts +3 -0
- package/dist/core/runner/resume-admission.js +6 -4
- package/dist/core/runner/resume-apply.js +7 -5
- package/dist/core/runner/resume-claim.d.ts +2 -2
- package/dist/core/runner/resume-claim.js +4 -4
- package/dist/core/runner/resume-policy-outcome.d.ts +1 -1
- package/dist/core/runner/resume-policy-outcome.js +6 -4
- package/dist/core/runner/resume-preflight.d.ts +3 -0
- package/dist/core/runner/resume-preflight.js +10 -3
- package/dist/core/runner/rewind-conversation.js +11 -4
- package/dist/core/runner/rewind-files.js +29 -14
- package/dist/core/runner/rewind-outcome.d.ts +27 -0
- package/dist/core/runner/rewind-outcome.js +14 -0
- package/dist/core/runner/run-attachment-seats.js +2 -1
- package/dist/core/runner/run-clock-and-content.js +2 -0
- package/dist/core/runner/run-identity-wiring.js +2 -0
- package/dist/core/runner/run-leg.js +11 -1
- package/dist/core/runner/run-notification-lane.d.ts +3 -0
- package/dist/core/runner/run-notification-lane.js +2 -2
- package/dist/core/runner/run-settle-and-teardown.d.ts +4 -2
- package/dist/core/runner/run-settle-and-teardown.js +52 -40
- package/dist/core/runner/run-stop-and-final-verify.d.ts +4 -0
- package/dist/core/runner/run-stop-and-final-verify.js +5 -4
- package/dist/core/runner/run-terminal-adoption.d.ts +1 -1
- package/dist/core/runner/run-terminal-adoption.js +3 -3
- package/dist/core/runner/run-turn-boundary.js +7 -0
- package/dist/core/runner/runtask.d.ts +7 -4
- package/dist/core/runner/runtask.js +18 -9
- package/dist/core/runner/session-call-grant-station.d.ts +64 -0
- package/dist/core/runner/session-call-grant-station.js +119 -0
- package/dist/core/runner/session-file-state-replay.js +2 -2
- package/dist/core/runner/session-prompt-seats.d.ts +95 -0
- package/dist/core/runner/session-prompt-seats.js +62 -0
- package/dist/core/runner/session-rule-policy.js +1 -1
- package/dist/core/runner/session-write-ledger.d.ts +8 -0
- package/dist/core/runner/session-write-ledger.js +16 -0
- package/dist/core/runner/side-call-account.js +5 -1
- package/dist/core/runner/stop-tail-notice.d.ts +7 -0
- package/dist/core/runner/stop-tail-notice.js +23 -8
- package/dist/core/runner/stream-reap.js +4 -2
- package/dist/core/runner/stream-settle-backstop.d.ts +1 -1
- package/dist/core/runner/stream-settle-backstop.js +17 -18
- package/dist/core/runner/terminal-account.js +17 -8
- package/dist/core/runner/terminal-projection.d.ts +3 -2
- package/dist/core/runner/terminal-projection.js +1 -1
- package/dist/core/runner/tool-turn-repair-seat.d.ts +2 -2
- package/dist/core/runner/tool-turn-repair-seat.js +12 -7
- package/dist/core/runner/turn-attachments.d.ts +22 -1
- package/dist/core/runner/turn-attachments.js +20 -3
- package/dist/core/runner-deps.d.ts +6 -2
- package/dist/core/secret-env.d.ts +26 -6
- package/dist/core/secret-env.js +6 -6
- package/dist/core/session-call-grant-screen.d.ts +58 -0
- package/dist/core/session-call-grant-screen.js +18 -0
- package/dist/core/session-call-grant.d.ts +93 -0
- package/dist/core/session-call-grant.js +524 -0
- package/dist/core/session-checkout.d.ts +3 -0
- package/dist/core/session-checkout.js +8 -3
- package/dist/core/session-policy-store.d.ts +14 -0
- package/dist/core/session-policy-store.js +16 -2
- package/dist/core/session-store.d.ts +18 -1
- package/dist/core/session-store.js +20 -4
- package/dist/core/session.d.ts +36 -4
- package/dist/core/shared-artifact-reads.d.ts +93 -0
- package/dist/core/shared-artifact-reads.js +94 -0
- package/dist/core/skill-grant.js +1 -1
- package/dist/core/skills-directory.d.ts +9 -45
- package/dist/core/skills-directory.js +9 -722
- package/dist/core/spend-account.js +3 -0
- package/dist/core/store-contracts/checkpoint-store-contract.d.ts +22 -4
- package/dist/core/store-contracts/checkpoint-store-contract.js +363 -29
- package/dist/core/store-contracts/file-history-store-contract.d.ts +11 -3
- package/dist/core/store-contracts/file-history-store-contract.js +62 -2
- package/dist/core/store-contracts/grant-fixture.d.ts +52 -0
- package/dist/core/store-contracts/grant-fixture.js +84 -0
- package/dist/core/store-contracts/session-repo-contract.js +18 -0
- package/dist/core/store-contracts/session-store-contract.d.ts +15 -1
- package/dist/core/store-contracts/session-store-contract.js +211 -2
- package/dist/core/store-contracts/workflow-journal-store-contract.js +47 -8
- package/dist/core/suspend-lane-reasons.d.ts +13 -0
- package/dist/core/suspend-lane-reasons.js +5 -0
- package/dist/core/synthetic-read-verdict.d.ts +5 -3
- package/dist/core/synthetic-read-verdict.js +1 -1
- package/dist/core/task-limits.d.ts +15 -0
- package/dist/core/task-notification.d.ts +33 -7
- package/dist/core/task-notification.js +34 -9
- package/dist/core/task-registry-agent.d.ts +1 -1
- package/dist/core/task-registry-agent.js +18 -7
- package/dist/core/task-registry-shared.d.ts +29 -4
- package/dist/core/task-registry-shared.js +7 -0
- package/dist/core/task-registry.d.ts +21 -1
- package/dist/core/task-registry.js +36 -9
- package/dist/core/task-result.d.ts +55 -1
- package/dist/core/task-spec.d.ts +17 -3
- package/dist/core/terminal-cause.d.ts +68 -5
- package/dist/core/tool-catalog-entries.js +1 -1
- package/dist/core/tool-check-reading.js +2 -1
- package/dist/core/tool-errors.js +1 -0
- package/dist/core/tool-list-grammar.d.ts +0 -47
- package/dist/core/tool-list-grammar.js +1 -75
- package/dist/core/tool-model-gate.d.ts +7 -11
- package/dist/core/tool-model-gate.js +5 -8
- package/dist/core/tool-name-aliases.js +2 -3
- package/dist/core/tool-name-readings.d.ts +4 -0
- package/dist/core/tool-name-readings.js +1 -0
- package/dist/core/tool-policy.d.ts +46 -4
- package/dist/core/tool-policy.js +47 -18
- package/dist/core/tool-result-store.d.ts +0 -24
- package/dist/core/tool-result-store.js +1 -36
- package/dist/core/tool-spec.d.ts +8 -4
- package/dist/core/untrusted-egress.js +2 -2
- package/dist/core/untrusted-text.d.ts +8 -0
- package/dist/core/untrusted-text.js +14 -0
- package/dist/core/user-attachment.d.ts +16 -1
- package/dist/core/user-attachment.js +42 -18
- package/dist/core/wiring-manifest.d.ts +4 -9
- package/dist/core/wiring-manifest.js +1 -1
- package/dist/core/workflow-journal-store.d.ts +55 -8
- package/dist/core/workflow-journal-store.js +34 -10
- package/dist/core/workflow-run-store-contract.js +56 -1
- package/dist/core/workflow-run-store.d.ts +43 -19
- package/dist/core/workflow-run-store.js +17 -2
- package/dist/engine/execution-env/node-execution-env.d.ts +3 -0
- package/dist/engine/execution-env/node-execution-env.js +4 -0
- package/dist/engine/harness/agent-harness.d.ts +10 -5
- package/dist/engine/harness/agent-harness.js +12 -4
- package/dist/engine/harness/types.d.ts +18 -0
- package/dist/engine/llm/tool-turns.d.ts +1 -1
- package/dist/engine/llm/types.d.ts +5 -4
- package/dist/engine/session/memory-repo.d.ts +15 -3
- package/dist/engine/session/memory-repo.js +21 -3
- package/dist/engine/session/memory-storage.d.ts +5 -0
- package/dist/engine/session/memory-storage.js +8 -3
- package/dist/engine/session/repo-utils.d.ts +9 -0
- package/dist/engine/session/repo-utils.js +14 -0
- package/dist/engine/session/storage-base.d.ts +20 -7
- package/dist/engine/session/storage-base.js +13 -1
- package/dist/index.d.ts +39 -21
- package/dist/index.js +32 -17
- package/dist/internal/harness.d.ts +1 -1
- package/dist/internal/harness.js +1 -1
- package/dist/orchestration/run-workflow-tool.d.ts +13 -1
- package/dist/orchestration/run-workflow-tool.js +101 -32
- package/dist/orchestration/workflow-park-adoption.d.ts +309 -92
- package/dist/orchestration/workflow-park-adoption.js +588 -323
- package/dist/orchestration/workflow-tree-id.d.ts +66 -0
- package/dist/orchestration/workflow-tree-id.js +66 -0
- package/dist/orchestration/workflow-types.d.ts +90 -11
- package/dist/orchestration/workflow-types.js +10 -1
- package/dist/orchestration/workflow.d.ts +30 -4
- package/dist/orchestration/workflow.js +424 -114
- package/dist/prompt-assembly/catalog/constitution.js +5 -1
- package/dist/prompt-assembly/catalog/core-behavior.d.ts +3 -4
- package/dist/prompt-assembly/catalog/core-behavior.js +61 -22
- package/dist/prompt-assembly/catalog/environment.js +2 -2
- package/dist/prompt-assembly/catalog/events.d.ts +16 -0
- package/dist/prompt-assembly/catalog/events.js +2 -0
- package/dist/prompt-assembly/catalog/locales/zh-Hans/core-behavior.js +72 -44
- package/dist/prompt-assembly/catalog/locales/zh-Hans/environment.js +2 -2
- package/dist/prompt-assembly/catalog/locales/zh-Hans/events.js +2 -0
- package/dist/prompt-assembly/catalog/schema.d.ts +5 -1
- package/dist/prompt-assembly/catalog/schema.js +2 -0
- package/dist/prompt-assembly/catalog/sections.js +3 -14
- package/dist/prompt-assembly/event-registry.js +2 -0
- package/dist/prompt-assembly/select.js +1 -0
- package/dist/prompt-assembly/tool-catalog.d.ts +10 -7
- package/dist/prompt-assembly/tool-catalog.js +21 -7
- package/dist/prompt-assembly/types.d.ts +3 -0
- package/dist/prompts/default.d.ts +4 -1
- package/dist/prompts/default.js +6 -0
- package/dist/stores/file/checkpoint-store.d.ts +11 -10
- package/dist/stores/file/checkpoint-store.js +36 -10
- package/dist/stores/file/file-history-store.d.ts +6 -0
- package/dist/stores/file/file-history-store.js +21 -4
- package/dist/stores/file/fs-atomic.d.ts +1 -1
- package/dist/stores/file/index.d.ts +14 -4
- package/dist/stores/file/index.js +21 -5
- package/dist/stores/file/process-anchor.d.ts +9 -1
- package/dist/stores/file/session-policy-store.js +2 -17
- package/dist/stores/file/session-store.d.ts +27 -0
- package/dist/stores/file/session-store.js +81 -9
- package/dist/stores/file/workflow-journal-store.d.ts +14 -4
- package/dist/stores/file/workflow-journal-store.js +32 -24
- package/dist/stores/file/workflow-run-store.d.ts +15 -4
- package/dist/stores/file/workflow-run-store.js +76 -0
- package/dist/tools/artifact/artifact-tool.d.ts +10 -3
- package/dist/tools/artifact/artifact-tool.js +16 -1
- package/dist/tools/fs/bash-program-position.d.ts +10 -4
- package/dist/tools/fs/bash-program-position.js +11 -8
- package/dist/tools/fs/bash-readonly-classifier.d.ts +3 -1
- package/dist/tools/fs/bash-readonly-classifier.js +9 -2
- package/dist/tools/fs/find-actions.d.ts +30 -16
- package/dist/tools/fs/find-actions.js +272 -19
- package/dist/tools/fs/fs-bash.js +8 -5
- package/dist/tools/fs/fs-shared.d.ts +0 -29
- package/dist/tools/fs/fs-shared.js +0 -5
- package/dist/tools/fs/fs-write.js +2 -1
- package/dist/tools/fs/read-deny.d.ts +6 -1
- package/dist/tools/fs/read-deny.js +6 -1
- package/dist/tools/fs/read-floor.d.ts +6 -0
- package/dist/tools/fs/read-floor.js +5 -1
- package/dist/tools/fs/removal-actions.d.ts +43 -0
- package/dist/tools/fs/removal-actions.js +25 -0
- package/dist/tools/fs/removal-targets.d.ts +2 -21
- package/dist/tools/fs/removal-targets.js +2 -3
- package/dist/tools/fs/safety.d.ts +37 -1
- package/dist/tools/fs/safety.js +52 -0
- package/dist/tools/fs/shell-climb.d.ts +46 -0
- package/dist/tools/fs/shell-climb.js +79 -0
- package/dist/tools/fs/shell-read-check.js +47 -19
- package/dist/tools/fs/shell-read-establish.js +36 -22
- package/dist/tools/fs/shell-read-judge.d.ts +10 -2
- package/dist/tools/fs/shell-read-judge.js +4 -4
- package/dist/tools/fs/shell-read-plan.d.ts +3 -0
- package/dist/tools/fs/shell-read-plan.js +1 -1
- package/dist/tools/fs/shell-read-workdir.js +3 -2
- package/dist/tools/fs/shell-read-write-targets.d.ts +4 -3
- package/dist/tools/fs/shell-read-write-targets.js +3 -0
- package/package.json +2 -2
- package/test/export-surface.snapshot.json +173 -15
- package/wire-changes/core-stores-sql@7.71.0.json +40 -0
- package/wire-changes/core-stores-sql@7.71.1.json +40 -0
- package/wire-changes/core@7.71.0.json +5827 -0
- package/wire-changes/core@7.71.1.json +118 -0
- package/wire-changes/mods-kernel@7.71.0.json +52 -0
- package/wire-changes/mods-kernel@7.71.1.json +40 -0
- package/wire-changes/primitives@7.71.0.json +473 -0
- package/wire-changes/primitives@7.71.1.json +40 -0
- package/wire-changes/wiki-gate@7.71.0.json +40 -0
- package/wire-changes/wiki-gate@7.71.1.json +40 -0
- package/dist/core/frontmatter-fence.d.ts +0 -10
- package/dist/core/frontmatter-fence.js +0 -6
- package/dist/core/permission-rule-syntax.d.ts +0 -46
- package/dist/core/permission-rule-syntax.js +0 -52
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DENIED_BY_MAY_ECHO, modeReleaseOf, readDenyTableOf, screenGateOutcome, SETTLEMENT_IS_REFUSAL } from "../gate-outcome.js";
|
|
2
2
|
import { traceHookCrash } from "../gate-crash-trace.js";
|
|
3
3
|
import { thrownText } from "../thrown-value.js";
|
|
4
|
-
import { ASK_CLASSES, askFaceOf, classifyAsk, headlessApprovalRemedy, NOBODY_CAN_APPROVE, unresolvedAskDenialMessage
|
|
4
|
+
import { ASK_CLASSES, askFaceOf, classifyAsk, headlessApprovalRemedy, withParkRemedy, NOBODY_CAN_APPROVE, unresolvedAskDenialMessage } from "../ask-origin.js";
|
|
5
5
|
import { NOT_RESUMABLE_CARRY_ON, notResumableWayOut } from "../park-resumability.js";
|
|
6
6
|
import { wireOf } from "../tool-name-readings.js";
|
|
7
7
|
import { isProtectedWrite } from "../tool-registry.js";
|
|
@@ -12,7 +12,7 @@ import { argsAsTheToolReads } from "../effective-path-target.js";
|
|
|
12
12
|
import { rewriteRecordOf } from "../rewrite-rejudge.js";
|
|
13
13
|
import { askUnresolvableRemedySeat } from "../ask-unresolvable-notice.js";
|
|
14
14
|
import { foreignLine } from "../protocol-http-auth.js";
|
|
15
|
-
import {
|
|
15
|
+
import { isSuspendLaneReason } from "../suspend-lane-reasons.js";
|
|
16
16
|
import { unavailableLandingOf } from "../unavailable-landing.js";
|
|
17
17
|
import { notRecordedMark } from "../redaction-marks.js";
|
|
18
18
|
import { formatHookFeedback } from "../reminder-mint.js";
|
|
@@ -273,6 +273,7 @@ function memberAt(value, path) {
|
|
|
273
273
|
return at;
|
|
274
274
|
}
|
|
275
275
|
const PARK_FAILURE_CAUSE_MAX = 600;
|
|
276
|
+
const suspendLaneReasonOf = (v) => (isSuspendLaneReason(v) ? v : undefined);
|
|
276
277
|
function withParkFailureCause(reason, park, nobodyJudged) {
|
|
277
278
|
if (park === undefined)
|
|
278
279
|
return reason;
|
|
@@ -291,15 +292,10 @@ function wayOnOf(row) {
|
|
|
291
292
|
return undefined;
|
|
292
293
|
return row.nobodyRemedy !== undefined ? row.nobodyRemedy() : row.wayOut !== undefined ? NOBODY_CAN_APPROVE : undefined;
|
|
293
294
|
}
|
|
294
|
-
function parkFailedBase(text,
|
|
295
|
-
if (park === undefined)
|
|
296
|
-
return text;
|
|
297
|
-
if (park.kind === "no_target" && text.startsWith(CONTENT_ASK_NOT_SHOWN))
|
|
298
|
-
return `${contentAskNotShownMessage(true)}${text.slice(CONTENT_ASK_NOT_SHOWN.length)}`;
|
|
299
|
-
if (cause !== "no_approver_wired" && cause !== "approver_unavailable")
|
|
295
|
+
export function parkFailedBase(text, minted, park) {
|
|
296
|
+
if (park === undefined || minted === undefined || !text.startsWith(minted.text))
|
|
300
297
|
return text;
|
|
301
|
-
|
|
302
|
-
return question === undefined ? text : unresolvedAskDenialMessage(cause, toolName, question, true);
|
|
298
|
+
return `${unresolvedAskDenialMessage(minted.cause, minted.question, true)}${text.slice(minted.text.length)}`;
|
|
303
299
|
}
|
|
304
300
|
export function takeInheritedScreen(pass, read) {
|
|
305
301
|
if (read?.floated !== undefined)
|
|
@@ -400,17 +396,19 @@ export async function exitGate(pass) {
|
|
|
400
396
|
const nobodyMayAnswer = input.askSeatForm !== undefined && input.askSeatForm !== "callback" && !parkCanWait && pass.askClassification?.classes.has("content_question") !== true;
|
|
401
397
|
const remedyOf = (approverSeat) => headlessApprovalRemedy({ mode: input.permissionMode?.(), classification: foldCause !== undefined ? ancestorUnresolvedClassification(pass.req) : pass.askClassification, approverSeat, coveredWrite: isProtectedWrite(pass.req), ...(pass.shellUnplacedOptions !== undefined ? { unplacedOptions: pass.shellUnplacedOptions } : {}), ...(wayOut !== undefined ? { notResumableWayOut: wayOut } : {}) });
|
|
402
398
|
const headless = bindingRefusal !== undefined || remedySeat === undefined ? undefined : remedyOf(remedySeat);
|
|
403
|
-
const
|
|
404
|
-
const
|
|
399
|
+
const parkNote = pass.parkFailed !== undefined ? ((r) => ({ kind: "failed", cause: pass.parkFailed, ...(r !== undefined ? { reason: r } : {}) }))(suspendLaneReasonOf(pass.parkFailedReason)) : unresolvable !== undefined && pass.parkTargetGap !== undefined ? { kind: "no_target", gap: pass.parkTargetGap } : undefined;
|
|
400
|
+
const parkFailedSaid = parkNote?.kind === "failed" && headless !== undefined ? foreignLine(parkNote.cause, PARK_FAILURE_CAUSE_MAX) : "";
|
|
401
|
+
const hostWay = headless !== undefined && parkFailedSaid !== "" ? withParkRemedy(headless, parkFailedSaid) : headless;
|
|
402
|
+
const remedy = hostWay?.sentence;
|
|
405
403
|
const question = pass.askClassification?.classes.has("content_question") === true;
|
|
406
404
|
const modelWayOut = wayOnOf({ nobodyJudged: unresolvable !== undefined, question, unbindable: bindingRefusal !== undefined, legHoldsNoPark: !floated && parkNote?.kind === "no_target", seatReAsked: input.askSeatForm === undefined || input.askSeatForm === "callback" || input.askSeatForm === "policy_callback", nobodyMayAnswer, nobodyRemedy: remedy !== undefined ? () => remedyOf("nobody").sentence : undefined, wayOut });
|
|
407
|
-
const base = parkFailedBase(decisionText(pass.decision) ?? `tool "${toolName}" denied by policy`,
|
|
405
|
+
const base = parkFailedBase(decisionText(pass.decision) ?? `tool "${toolName}" denied by policy`, attestationOf(pass.decision, { toolCallId, toolName })?.unanswered, parkNote);
|
|
408
406
|
const tail = question ? "" : remedy !== undefined || (modelWayOut !== undefined && wayOut === undefined) ? ` — ${modelWayOut ?? remedy}` : unresolvable !== undefined && wayOut !== undefined && bindingRefusal === undefined ? (modelWayOut !== undefined ? `. To go on: ${modelWayOut}.` : `. To go on: ${wayOut}. ${NOT_RESUMABLE_CARRY_ON}`) : "";
|
|
409
407
|
const denyReason = withParkFailureCause(`${tail.startsWith(".") ? base.replace(/\.$/, "") : base}${tail}`, parkNote, unresolvable !== undefined && !question);
|
|
410
408
|
if (unresolvable !== undefined) {
|
|
411
409
|
const cause = unresolvable;
|
|
412
410
|
const noticeRemedy = bindingRefusal ?? remedy;
|
|
413
|
-
pass.notifier.notify(() => input.onAskUnresolvable?.({ toolName, toolCallId, cause, parkLaneExisted: pass.suspendAsk !== undefined, ...(parkNote?.kind === "no_target" ? { parkTargetGap: parkNote.gap } : {}), ...(noticeRemedy !== undefined ? { remedy: noticeRemedy } : {}), ...(modelWayOut !== undefined ? { modelRemedy: modelWayOut } : {}), ...(
|
|
411
|
+
pass.notifier.notify(() => input.onAskUnresolvable?.({ toolName, toolCallId, cause, parkLaneExisted: pass.suspendAsk !== undefined, ...(parkNote?.kind === "no_target" ? { parkTargetGap: parkNote.gap } : {}), ...(parkFailedSaid !== "" ? { parkFailed: parkFailedSaid, ...(parkNote?.kind === "failed" && parkNote.reason !== undefined ? { parkFailedReason: parkNote.reason } : {}) } : {}), ...(noticeRemedy !== undefined ? { remedy: noticeRemedy } : {}), ...(modelWayOut !== undefined ? { modelRemedy: modelWayOut } : {}), ...(hostWay !== undefined ? { remedies: hostWay.remedies } : {}), ...(wayOut !== undefined && input.notResumable !== undefined ? { notResumableWayOut: wayOut, notResumableSource: input.notResumable.source } : {}), ...(question ? { question: true } : {}), ...(bindingRefusal !== undefined ? { unbindable: true } : {}) }), "toolGate.onAskUnresolvable");
|
|
414
412
|
}
|
|
415
413
|
const finalInput = frozenInputSnapshot(pass.currentInput);
|
|
416
414
|
await notifyPermissionDenied(permissionDeniedOf({ toolName, finalInput, toolCallId, reason: denyReason, gate, identity: input.identity }));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isFrontmatterFence } from "
|
|
1
|
+
import { isFrontmatterFence } from "@sema-agent/primitives";
|
|
2
2
|
import { sliceHeadSafe } from "../surrogate-safe-slice.js";
|
|
3
3
|
import { compileGlobToken } from "../../tools/fs/search.js";
|
|
4
4
|
export const INSTRUCTION_FILE_MIN_CHARS = 40_000;
|
|
@@ -3,7 +3,7 @@ import type { ModelFileReader } from "../../tools/fs/fs-read.js";
|
|
|
3
3
|
import { type ReadFileState } from "../../tools/fs/safety.js";
|
|
4
4
|
import type { SyntheticServedReadJudge } from "../synthetic-read-verdict.js";
|
|
5
5
|
import type { ToolCallFace } from "../tool-policy.js";
|
|
6
|
-
import { type InstructionLayer, type MintedAttachmentFrame } from "../user-attachment.js";
|
|
6
|
+
import { type FrameFileTools, type InstructionLayer, type MintedAttachmentFrame } from "../user-attachment.js";
|
|
7
7
|
import type { ReminderDisclosureCounts } from "../reminder-disclosure.js";
|
|
8
8
|
import type { TaskSpec } from "../task-spec.js";
|
|
9
9
|
import type { EngineNotice, RunnerDeps, TaskEvent, TaskEventIdentity } from "../types.js";
|
|
@@ -43,6 +43,11 @@ export declare const INSTRUCTIONS_WITHHELD = "instructions.withheld";
|
|
|
43
43
|
* no file of the run's (a label for a name, or a run with no files), so it has nowhere to resolve. */
|
|
44
44
|
export declare const INSTRUCTIONS_WITHHELD_REASONS: readonly ["rule_denied", "outside_roots", "approval_required", "admission_unknown", "target_moved", "outside_its_root", "too_many_texts", "unanchored"];
|
|
45
45
|
export type InstructionsWithheldReason = (typeof INSTRUCTIONS_WITHHELD_REASONS)[number];
|
|
46
|
+
/** The notice a member the family names was loaded under though it really lies, links followed, outside its root and the task root
|
|
47
|
+
* (a link to a shared file): read as before — the reference reads it too — and said once per session per (path, target), with no
|
|
48
|
+
* contents. A found file outside them is not loaded ({@link INSTRUCTIONS_WITHHELD} `outside_its_root`); one the read roots or a rule
|
|
49
|
+
* refuses is withheld whatever the name. */
|
|
50
|
+
export declare const INSTRUCTIONS_OUTSIDE_ROOT = "instructions.outside_root";
|
|
46
51
|
/** The notice a run prepared with no instruction family declared is the first, for its notice receiver, to say. */
|
|
47
52
|
export declare const INSTRUCTIONS_FAMILY_UNDECLARED = "instructions.family_undeclared";
|
|
48
53
|
/** The operator's sentence for that absence: what no run reads, and the one thing that makes them read it. */
|
|
@@ -122,7 +127,7 @@ export declare function instructionFamilyOf(spec: Pick<TaskSpec, "instructionFam
|
|
|
122
127
|
export declare function screenNestedMemory(spec: Pick<TaskSpec, "instructionFamily"> | unknown, projectMemory: TaskSpec["projectMemory"] | unknown): ScreenedNestedMemory | undefined;
|
|
123
128
|
/** What the lane reads with: the hands' environment and reader, the run's served-read judge (every ask held: nobody asked
|
|
124
129
|
* for this file, so it is shown only where the model's own `Read` of it would be served with nobody asked) and the face
|
|
125
|
-
* the run's roster gives `Read` (read at each judgment; none ⇒ the
|
|
130
|
+
* the run's roster gives `Read` (read at each judgment; none ⇒ the probe carries no face — never a reason to withhold), the live read
|
|
126
131
|
* state, the canonical task root and the additional working directories the request declared (each its declared spelling
|
|
127
132
|
* and the one canonical form the hands resolved it to, in declaration order; read as roots only under the declaration's
|
|
128
133
|
* opt-in); the prepared leg (read at each load) for the model and the records. A leg with no hands seats the lane without
|
|
@@ -146,6 +151,9 @@ interface LaneSeatCommon {
|
|
|
146
151
|
readonly counts: ReminderDisclosureCounts | undefined;
|
|
147
152
|
readonly deps: Pick<RunnerDeps, "onNotice" | "onError">;
|
|
148
153
|
readonly leg: () => Pick<Prepared, "harness" | "session" | "sessionId" | "runId" | "announcedListingsRef" | "frameReceipts" | "hookIdentity"> | undefined;
|
|
154
|
+
/** The file tools the run's roster mounts, read at each mint — what a frame's sentence (a cut file's way to the rest) may send the
|
|
155
|
+
* model to; absent outside a Runner: every one taken as mounted. */
|
|
156
|
+
readonly fileTools?: () => FrameFileTools;
|
|
149
157
|
}
|
|
150
158
|
/** An additional working directory as the request declared it (`TaskSpec.additionalDirectories`, the spelling) and as the
|
|
151
159
|
* hands resolved it (the canonical form the file tools' fence holds). */
|
|
@@ -28,6 +28,7 @@ export const NESTED_MEMORY_STAT_BATCH = 8;
|
|
|
28
28
|
export const NESTED_MEMORY_PROBE_FACE = "nested-memory";
|
|
29
29
|
export const INSTRUCTIONS_WITHHELD = "instructions.withheld";
|
|
30
30
|
export const INSTRUCTIONS_WITHHELD_REASONS = Object.freeze(["rule_denied", "outside_roots", "approval_required", "admission_unknown", "target_moved", "outside_its_root", "too_many_texts", "unanchored"]);
|
|
31
|
+
export const INSTRUCTIONS_OUTSIDE_ROOT = "instructions.outside_root";
|
|
31
32
|
export const INSTRUCTIONS_FAMILY_UNDECLARED = "instructions.family_undeclared";
|
|
32
33
|
export function instructionsFamilyUndeclaredNotice(sessionId) {
|
|
33
34
|
return {
|
|
@@ -341,6 +342,26 @@ export function createNestedMemoryLane(seat) {
|
|
|
341
342
|
const rel = relOf(key);
|
|
342
343
|
return at === "any" && rel !== undefined && rel !== "" && levelsOf(rel).some((level) => memberAt(rel, level, declaredNamesOf(0), declaredRulesOf(0)) !== undefined);
|
|
343
344
|
};
|
|
345
|
+
const tellLoadedOutside = (path, target) => {
|
|
346
|
+
const leg = seat.leg();
|
|
347
|
+
if (leg === undefined)
|
|
348
|
+
return;
|
|
349
|
+
const d = announceDigest(INSTRUCTIONS_OUTSIDE_ROOT, JSON.stringify([path, target]));
|
|
350
|
+
if ((leg.announcedListingsRef.advisories ?? []).includes(d))
|
|
351
|
+
return;
|
|
352
|
+
leg.announcedListingsRef.advisories = withAnnounceDigests(leg.announcedListingsRef.advisories, [d]);
|
|
353
|
+
leg.frameReceipts.listingSnapshotOwed = true;
|
|
354
|
+
if (agentIdOf(leg.hookIdentity) !== undefined)
|
|
355
|
+
return;
|
|
356
|
+
const r = rootLevelOf(path);
|
|
357
|
+
const what = r === 0 ? "An instruction file of the task root" : r > 0 ? "An instruction file of an additional working directory" : "An instruction file of a directory the model accessed";
|
|
358
|
+
const from = r > 0 ? "that directory and the task root" : "the task root";
|
|
359
|
+
deliverEngineNotice(seat.deps.onNotice, {
|
|
360
|
+
code: INSTRUCTIONS_OUTSIDE_ROOT,
|
|
361
|
+
message: `${what} was loaded from outside ${from}: ${path} leads to ${target}. If that is not meant, replace it with a file inside ${from}, or turn the project's instruction files off for the request.`,
|
|
362
|
+
detail: { path, target, sessionId: leg.sessionId, runId: leg.runId },
|
|
363
|
+
});
|
|
364
|
+
};
|
|
344
365
|
const levelItems = (r, level) => {
|
|
345
366
|
const items = [];
|
|
346
367
|
const add = (i) => {
|
|
@@ -597,15 +618,11 @@ export function createNestedMemoryLane(seat) {
|
|
|
597
618
|
visited.add(key);
|
|
598
619
|
return includesAt(includesBy.get(key) ?? [], item, key);
|
|
599
620
|
}
|
|
600
|
-
const face = hands.readFace();
|
|
601
|
-
if (face === undefined) {
|
|
602
|
-
withheld(item, "admission_unknown");
|
|
603
|
-
return [];
|
|
604
|
-
}
|
|
605
621
|
p.count++;
|
|
622
|
+
const face = hands.readFace();
|
|
606
623
|
const held = await hands.reader.openBound(key, seat.signal);
|
|
607
624
|
try {
|
|
608
|
-
const verdict = await hands.judge({ file_path: item.path, face }, NESTED_MEMORY_PROBE_FACE, { deadlineAt });
|
|
625
|
+
const verdict = await hands.judge({ file_path: item.path, ...(face !== undefined ? { face } : {}) }, NESTED_MEMORY_PROBE_FACE, { deadlineAt });
|
|
609
626
|
if (verdict.verdict !== "no_objection") {
|
|
610
627
|
withheld(item, verdict.verdict === "deny" ? "rule_denied" : verdict.verdict === "ask" ? "approval_required" : "admission_unknown");
|
|
611
628
|
return [];
|
|
@@ -660,6 +677,7 @@ export function createNestedMemoryLane(seat) {
|
|
|
660
677
|
const recorded = { hash, totalLines, truncated: !whole, ...(whole ? { view: { start: 1, end: totalLines } } : { isPartialView: true }) };
|
|
661
678
|
inFlight.add(key);
|
|
662
679
|
const layer = layerOf(item.level);
|
|
680
|
+
const outsideItsRoots = !foundByLane(item) && !insideItsRoots(item.root, key);
|
|
663
681
|
const read = {
|
|
664
682
|
supply: "path",
|
|
665
683
|
owner: item.owner ?? "repository",
|
|
@@ -674,6 +692,8 @@ export function createNestedMemoryLane(seat) {
|
|
|
674
692
|
seen?.set(key, entryId(landed));
|
|
675
693
|
inFlight.delete(key);
|
|
676
694
|
echo.fn?.(key, layer, false);
|
|
695
|
+
if (outsideItsRoots)
|
|
696
|
+
tellLoadedOutside(item.path, key);
|
|
677
697
|
},
|
|
678
698
|
};
|
|
679
699
|
reads.push({ read, item, key });
|
|
@@ -817,7 +837,8 @@ export function createNestedMemoryLane(seat) {
|
|
|
817
837
|
const model = leg.harness.getModel();
|
|
818
838
|
const budget = NESTED_MEMORY_FRAME_BUDGET_FILES * instructionFileCap(model.contextWindow, model.charsPerToken ?? 4);
|
|
819
839
|
const taken = [...reads];
|
|
820
|
-
const
|
|
840
|
+
const fileTools = seat.fileTools?.();
|
|
841
|
+
const disclosure = { reader: hands?.reader, mark: seat.mark, counts: seat.counts, ...(fileTools !== undefined ? { fileTools } : {}) };
|
|
821
842
|
let minted = mintInstructionFrames(taken.map((r) => r.read), disclosure);
|
|
822
843
|
const sizeOf = (frames) => frames.reduce((n, f) => n + f.seed.content.reduce((m, b) => m + (b.type === "text" ? b.text.length : 0), 0), 0);
|
|
823
844
|
while (taken.length > 1 && sizeOf(minted.frames) > budget) {
|
|
@@ -952,7 +973,7 @@ const WITHHELD_WAY_OUT = {
|
|
|
952
973
|
rule_denied: "Remove the read rule that refuses it (a built-in credential row can be removed only by the deployment), or move the file to a path no rule refuses.",
|
|
953
974
|
outside_roots: "Point the link back inside those directories or make it a real file there, or add the directory it leads to among the session's additional directories.",
|
|
954
975
|
approval_required: "Remove the ask rule or policy (yours, the deployment's or the organization's) that makes reading it ask; an allow rule does not override an ask.",
|
|
955
|
-
admission_unknown: "
|
|
976
|
+
admission_unknown: "A check that could not answer is retried the next time instruction files are loaded; for a `~/` include, the deployment must declare a home directory.",
|
|
956
977
|
target_moved: "Nothing to change: it is checked again the next time instruction files are loaded.",
|
|
957
978
|
outside_its_root: "A file the lane found outside that root and the task root is loaded only when this project approves instruction files outside it (an approval applies from the next run); otherwise put the file inside one of them or point the link at one — adding directories or rules does not change this.",
|
|
958
979
|
too_many_texts: "Merge the texts, or leave out the ones not needed, so that what matters is among the first.",
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A resume's money-ceiling door: the run's OWN money ceiling over the model it runs on that the ceiling cannot count — the refusal the
|
|
3
|
+
* start's doors give ({@link unpricedModelRefusal}), asked of the config a resume is handed, so `Runner.judgeResumeConfig` and the
|
|
4
|
+
* resume's pre-claim ladder say what prepare would say after the claim (the row staying pending).
|
|
5
|
+
*
|
|
6
|
+
* The model is read the way prepare reads it (`resolveRunModel` over the role maps' receipts: `deps` with the deployment's, `taskRoles`
|
|
7
|
+
* the task's). `priorLedger` is the resumed row's ledger (what its chain has left of a total); none ⇒ the config's own ceiling.
|
|
8
|
+
* A model that does not resolve — or a price table that cannot be read — is prepare's refusal to give, after the claim and in its own
|
|
9
|
+
* words, not this door's: nothing is asked of it here.
|
|
10
|
+
*/
|
|
11
|
+
import type { ResourceLedger } from "../checkpoint-store.js";
|
|
12
|
+
import type { RunnerDeps, TaskSpec } from "../types.js";
|
|
13
|
+
export declare function refuseUncountedOwnModel(config: Pick<TaskSpec, "limits" | "resourceSuspend" | "model" | "modelRole" | "roles" | "thinking">, deps: RunnerDeps, taskRoles: TaskSpec["roles"], priorLedger: ResourceLedger | undefined): void;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { resolveRunModel } from "./seat-model-doors.js";
|
|
2
|
+
import { ownMoneyCeiling, unpricedModelRefusal } from "./side-call-account.js";
|
|
3
|
+
export function refuseUncountedOwnModel(config, deps, taskRoles, priorLedger) {
|
|
4
|
+
const held = ownMoneyCeiling(config, priorLedger);
|
|
5
|
+
if (held === undefined)
|
|
6
|
+
return;
|
|
7
|
+
let refusal;
|
|
8
|
+
try {
|
|
9
|
+
const resolved = resolveRunModel(taskRoles !== undefined ? { ...config, roles: taskRoles } : config, deps);
|
|
10
|
+
refusal = unpricedModelRefusal(held, resolved.model, deps.pricing, resolved.modelInput);
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
if (refusal !== undefined)
|
|
16
|
+
throw refusal;
|
|
17
|
+
}
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import type { Checkpoint, CheckpointGate, CheckpointToken } from "../checkpoint-store.js";
|
|
10
10
|
import type { WorkspaceHandle } from "../remote-env.js";
|
|
11
|
-
import type { Prepared } from "./contracts.js";
|
|
11
|
+
import type { ParkWrites, Prepared } from "./contracts.js";
|
|
12
12
|
/** Default resource-checkpoint retention (30 days, the spec's
|
|
13
13
|
* `RESOURCE_SUSPEND_TTL_SEC`). Stamped onto the checkpoint `deadline` so the durable reaper can GC an
|
|
14
14
|
* ORPHANED resource suspend; a legitimate auto-resume fires long before this. Override via
|
|
@@ -127,4 +127,6 @@ export declare function heldCallResultOf(refs: Pick<Prepared, "pausedRef">, tool
|
|
|
127
127
|
export declare function publishCommittedSuspend(refs: Pick<Prepared, "pausedRef">, token: CheckpointToken, gate: CheckpointGate, scope: string, remoteHandle: WorkspaceHandle | undefined,
|
|
128
128
|
/** The COMMITTED row — passed whole, not as pre-extracted members, so no call site can hand this seam an id or a fact
|
|
129
129
|
* the committed row does not actually carry. */
|
|
130
|
-
row: Pick<Checkpoint, "checkpointId" | "pendingAction" | "state"
|
|
130
|
+
row: Pick<Checkpoint, "checkpointId" | "pendingAction" | "state">,
|
|
131
|
+
/** What the saga's committed answer says the put carried — passed as the saga answered it (see {@link CommittedPause.writes}). */
|
|
132
|
+
writes: ParkWrites): void;
|
|
@@ -32,7 +32,7 @@ export function heldCallResultOf(refs, toolCallId) {
|
|
|
32
32
|
const text = card.kind === "card" && card.card === "question" ? HELD_CALL_TEXT.question : HELD_CALL_TEXT.approval;
|
|
33
33
|
return { content: [{ type: "text", text }], details: { code: "gate.parked", gatedCallId: toolCallId } };
|
|
34
34
|
}
|
|
35
|
-
export function publishCommittedSuspend(refs, token, gate, scope, remoteHandle, row) {
|
|
35
|
+
export function publishCommittedSuspend(refs, token, gate, scope, remoteHandle, row, writes) {
|
|
36
36
|
const { pendingAction } = row;
|
|
37
37
|
const pause = {
|
|
38
38
|
cause: {
|
|
@@ -45,6 +45,7 @@ export function publishCommittedSuspend(refs, token, gate, scope, remoteHandle,
|
|
|
45
45
|
},
|
|
46
46
|
scope,
|
|
47
47
|
...(pendingAction.kind === "tool_approval" ? { gatedCallId: pendingAction.toolCallId } : {}),
|
|
48
|
+
writes,
|
|
48
49
|
};
|
|
49
50
|
refs.pausedRef.current = pause;
|
|
50
51
|
}
|
|
@@ -34,6 +34,7 @@ import { type EffectivePermissionRules, type PermissionRuleStoreProvider, type P
|
|
|
34
34
|
import { type AutoStripReason } from "../auto-strip.js";
|
|
35
35
|
import { type MountedPeersSeat } from "../a2a-bound-grant.js";
|
|
36
36
|
import { type PersistedRuleBuckets } from "../persisted-rule-buckets.js";
|
|
37
|
+
import { type CallGrantBinding } from "../session-call-grant.js";
|
|
37
38
|
/**
|
|
38
39
|
* The evidence an INHERITED-lane ask carries.
|
|
39
40
|
*
|
|
@@ -196,6 +197,9 @@ export declare function createPermissionRuleLanes(cfg: {
|
|
|
196
197
|
* (its scope covers this leg) and whose text reads as an allow rule (one that does not grants nothing in any mode). Absent ⇒
|
|
197
198
|
* nobody is told (a judgment that is not the gate's: the consolidation judge, a synthetic read, a resumed call's belt). */
|
|
198
199
|
onAutoStripped?: (rule: PersistedRule, reason: AutoStripReason, req: ToolCallRequest) => void;
|
|
200
|
+
/** The session call grants' one judgment, over the run's execution environment: does a stored binding admit this shell
|
|
201
|
+
* command now ({@link callGrantAdmits})? Absent ⇒ no call grant row admits anything (the leg has no environment to read). */
|
|
202
|
+
callGrantAdmits?: (binding: CallGrantBinding, command: string, signal?: AbortSignal) => Promise<boolean>;
|
|
199
203
|
}): PermissionRuleLanes;
|
|
200
204
|
/** The surviving-ask facts the rule-offer factory reads (see {@link createRuleOffersOf}): the
|
|
201
205
|
* synchronous mint sites spread the surviving decision, which carries them; the park leg threads
|
|
@@ -18,6 +18,7 @@ import { strongestAnswer } from "../persisted-rule-arms.js";
|
|
|
18
18
|
import { ORG_ADJUDICATION_TIMEOUT_MS } from "../permission-rule-org.js";
|
|
19
19
|
import { insidePeerOfferOf } from "../a2a-bound-grant.js";
|
|
20
20
|
import { refuseUnreadAncestorBuckets } from "../persisted-rule-buckets.js";
|
|
21
|
+
import { callGrantRowAdmitting } from "../session-call-grant.js";
|
|
21
22
|
const NO_LEADS = new Map();
|
|
22
23
|
export function inheritedAskRuleEvidence(provider) {
|
|
23
24
|
const org = provider?.partitions.org === true ? "not_adjudicated" : "not_wired";
|
|
@@ -173,6 +174,11 @@ export function createPermissionRuleLanes(cfg) {
|
|
|
173
174
|
const stands = answer !== undefined && (("behavior" in answer && answer.behavior === "deny") || "unreadable" in answer);
|
|
174
175
|
if ((view.unreadable !== undefined || unread.length > 0) && !stands)
|
|
175
176
|
return storeUnreadable(unread, answer !== undefined && "behavior" in answer && answer.behavior === "ask" ? answer : undefined);
|
|
177
|
+
if (answer === undefined || "segmentCoverage" in answer) {
|
|
178
|
+
const granted = await callGrantOf(stripped, req, judged);
|
|
179
|
+
if (granted !== undefined)
|
|
180
|
+
return persistedRuleAnswerOf({ behavior: "allow", rules: [granted] });
|
|
181
|
+
}
|
|
176
182
|
if (answer === undefined || !("behavior" in answer) || answer.behavior !== "allow")
|
|
177
183
|
return answer;
|
|
178
184
|
const bound = table.flatMap((r) => {
|
|
@@ -192,6 +198,7 @@ export function createPermissionRuleLanes(cfg) {
|
|
|
192
198
|
return { unreadable: true, reason: why };
|
|
193
199
|
}
|
|
194
200
|
};
|
|
201
|
+
const callGrantOf = (rows, req, judged) => callGrantRowAdmitting(rows, { words: judged.flatMap(([n, g, grants]) => (grants && g === "command" ? [n] : [])), sessionId: cfg.sessionId, command: req.args?.command, judge: cfg.callGrantAdmits });
|
|
195
202
|
const unjudgedRowAnswer = (row, refusal, tool) => {
|
|
196
203
|
const why = `the stored ${row.behavior} rule ${escapeForDisclosure(row.rule)} is no rule this engine reads (${refusal})`;
|
|
197
204
|
cfg.onDisclosure(`the persisted rule lane could not judge a ${tool} call against the rows it read — ${why}`);
|
|
@@ -5,7 +5,7 @@ import { readPrincipal } from "../principal-name.js";
|
|
|
5
5
|
import { ORG_ADJUDICATION_TIMEOUT_MS, orgResolutionHeld, orgRowsStandOverFace } from "../permission-rule-org.js";
|
|
6
6
|
import { canonicalize } from "../canonical-json.js";
|
|
7
7
|
import { PATH_RULE_FACES, READ_RULE_TOOL, eligiblePersisted, noticeRuleText, ruleToolGrammarOf } from "../permission-rule-model.js";
|
|
8
|
-
import { indexOfUnescaped } from "
|
|
8
|
+
import { indexOfUnescaped } from "@sema-agent/primitives";
|
|
9
9
|
import { ROSTERLESS_RETIRED_VIEW, ruleListUnderView } from "../tool-name-aliases.js";
|
|
10
10
|
import { bindPathRules, persistedRowAnchors, projectScopeIdentity } from "../path-rule-binding.js";
|
|
11
11
|
import { DEFAULT_GATE_AWAIT_TIMEOUT_MS, gateWaitFailureOf, withGateTimeout } from "../gate-bounded-await.js";
|
|
@@ -21,9 +21,15 @@ export declare function mintPlacementFence(row: WorkspaceHandle | undefined, han
|
|
|
21
21
|
* device its fence names is refused before anything reports the workspace or runs on it. A leg that restored a
|
|
22
22
|
* checkpointed workspace (its restore took the receipt already, against the restored handle) is refused
|
|
23
23
|
* `resume.env_failed` here too — its env may have moved after the restore (re-initialization reconnecting elsewhere) —
|
|
24
|
-
* any other leg `config.placement_not_honored`.
|
|
24
|
+
* any other leg `config.placement_not_honored`. `restoredRow` is that leg's row's workspace (absent on every other leg): a
|
|
25
|
+
* refusal whose one reading of the env's device {@link devicesDisprove} the row's is marked `envDisowned` (the env is not the
|
|
26
|
+
* row's workspace, so the leg's exit destroys it at once).
|
|
25
27
|
*/
|
|
26
|
-
export declare function settleOwnTarget(env: ExecutionEnv | undefined, fence: PlacementTarget | undefined,
|
|
28
|
+
export declare function settleOwnTarget(env: ExecutionEnv | undefined, fence: PlacementTarget | undefined, restoredRow: Pick<WorkspaceHandle, "deviceId"> | undefined): PlacementTarget | undefined;
|
|
29
|
+
/** Whether a device receipt disproves that a resume leg's env stands at its row's workspace: the row and the env each name a
|
|
30
|
+
* device and they differ (an absent one, or the waking leg's, proves nothing). The one reading of both receipts a resume leg
|
|
31
|
+
* meets — the restore's identity check before anything is connected, and the settle point after. */
|
|
32
|
+
export declare function devicesDisprove(rowDevice: string | undefined, envDevice: string | undefined): boolean;
|
|
27
33
|
/** The codes a device move is refused with: a fresh fenced leg, and a leg that restores or resumes a checkpointed workspace. */
|
|
28
34
|
export type DeviceMoveRefusalCode = "config.placement_not_honored" | "resume.env_failed";
|
|
29
35
|
/**
|
|
@@ -20,12 +20,17 @@ function handedFence(value) {
|
|
|
20
20
|
}
|
|
21
21
|
return Object.freeze(deviceId !== undefined ? { provider, deviceId } : { provider });
|
|
22
22
|
}
|
|
23
|
-
export function settleOwnTarget(env, fence,
|
|
23
|
+
export function settleOwnTarget(env, fence, restoredRow) {
|
|
24
24
|
const own = reportedPlacementTarget(env);
|
|
25
|
-
if (!placementHonored(fence, own))
|
|
26
|
-
|
|
25
|
+
if (!placementHonored(fence, own)) {
|
|
26
|
+
const refusal = deviceMoveRefusal(restoredRow !== undefined ? "resume.env_failed" : "config.placement_not_honored", fence?.deviceId, own?.deviceId);
|
|
27
|
+
throw restoredRow !== undefined && devicesDisprove(restoredRow.deviceId, own?.deviceId) ? Object.assign(refusal, { envDisowned: true }) : refusal;
|
|
28
|
+
}
|
|
27
29
|
return own;
|
|
28
30
|
}
|
|
31
|
+
export function devicesDisprove(rowDevice, envDevice) {
|
|
32
|
+
return rowDevice !== undefined && envDevice !== undefined && rowDevice !== envDevice;
|
|
33
|
+
}
|
|
29
34
|
export function deviceMoveRefusal(code, fenceDevice, reportedDevice) {
|
|
30
35
|
const fenced = fenceDevice !== undefined ? `device "${renderDeviceId(fenceDevice)}"` : "no device";
|
|
31
36
|
const reports = reportedDevice !== undefined ? `device "${renderDeviceId(reportedDevice)}"` : "no device";
|
|
@@ -19,11 +19,12 @@ export declare function policyCheckAbortedDeny(): PermissionResult;
|
|
|
19
19
|
/** The deny of a judgment that FAILED (threw or rejected) while `signal` bounded its wait: the aborted deny when the signal had
|
|
20
20
|
* already ended the wait (a cancellation — not reported), else the policy's own throw — its sentence and one line of what it
|
|
21
21
|
* threw — reported once through {@link reportPolicyThrow}. A seat that raced the judgment against its signal has told the two
|
|
22
|
-
* apart already and passes no signal.
|
|
22
|
+
* apart already and passes no signal. `said`: the model's sentence of a seat whose failure was no throw (a target reading that moved
|
|
23
|
+
* the call it was handed), which says what failed in its own words; absent, the sentence is the policy's throw. */
|
|
23
24
|
export declare function failedJudgmentDeny(err: unknown, signal: AbortSignal | undefined, report: (err: Error) => void, seat: string, call: {
|
|
24
25
|
readonly toolName: string;
|
|
25
26
|
readonly toolCallId: string;
|
|
26
|
-
}): PermissionResult;
|
|
27
|
+
}, said?: string): PermissionResult;
|
|
27
28
|
/** Hand the deployment, through `report` (the seat's hook-failure lane), the failure of the policy that threw while `seat`
|
|
28
29
|
* judged `call`. A rejection that arrives with the judgment's `signal` already aborted is the task ending mid-judgment — a
|
|
29
30
|
* cancellation, not a policy defect — and is not reported (the deny it produced stands either way). A report lane that
|
|
@@ -10,11 +10,11 @@ export function policyThrowLine(err) {
|
|
|
10
10
|
export function policyCheckAbortedDeny() {
|
|
11
11
|
return { action: "deny", message: "policy check aborted (task timed out or cancelled)" };
|
|
12
12
|
}
|
|
13
|
-
export function failedJudgmentDeny(err, signal, report, seat, call) {
|
|
13
|
+
export function failedJudgmentDeny(err, signal, report, seat, call, said) {
|
|
14
14
|
if (signal?.aborted === true)
|
|
15
15
|
return policyCheckAbortedDeny();
|
|
16
16
|
reportPolicyThrow(report, seat, call, err);
|
|
17
|
-
return { action: "deny", message: `policy check threw — the tool policy chain failed while judging this call (not a timeout or cancellation), so it was denied fail-closed: ${policyThrowLine(err)}` };
|
|
17
|
+
return { action: "deny", message: said ?? `policy check threw — the tool policy chain failed while judging this call (not a timeout or cancellation), so it was denied fail-closed: ${policyThrowLine(err)}` };
|
|
18
18
|
}
|
|
19
19
|
export function reportPolicyThrow(report, seat, call, err, signal) {
|
|
20
20
|
if (signal?.aborted === true)
|
|
@@ -13,10 +13,11 @@
|
|
|
13
13
|
* audit B-17: release deletes the history on the default store), so a throw here never strands a
|
|
14
14
|
* cached view and never hands out a half-acquired resource.
|
|
15
15
|
*
|
|
16
|
-
* Throws pass through unchanged: `delegation.owner_mismatch` (
|
|
17
|
-
*
|
|
16
|
+
* Throws pass through unchanged: `delegation.owner_mismatch` (a leg holding a seat resolved a row that is not its tree's — its cached view
|
|
17
|
+
* dropped first), the session store's fault of that judgement (`config.invalid_session_store` / `storage`), `resume.session_not_found` (requireExisting fail-loud mapping),
|
|
18
18
|
* the `resume_at.*` target-validation refusals (`judgeRewindTarget`, then the landing's: the window, `refuseOpenToolCallAt`), `corrupt_session`
|
|
19
|
-
* for a log that does not hold together (the path reads after the branch),
|
|
19
|
+
* for a log that does not hold together (the path reads after the branch), `holder.superseded` (a write the store refused for the
|
|
20
|
+
* leg's grant: never re-woken — a superseded leg stops), and — after the
|
|
20
21
|
* bounded re-wake budget — the session conflict itself. A throw after a `resumeAt` branch landed first writes that branch
|
|
21
22
|
* back (`settleBranchWriteBack`); on success the branch is handed over with the session.
|
|
22
23
|
*/
|
|
@@ -25,9 +26,10 @@ import type { AcquiredSession, SessionStore } from "../session.js";
|
|
|
25
26
|
import { type RecoveredOrphan } from "../session-reconcile.js";
|
|
26
27
|
import type { TaskSpec, ToolEffect } from "../types.js";
|
|
27
28
|
import type { PrepareResume } from "./contracts.js";
|
|
28
|
-
import { type ResumeAtBranch } from "./branch-writeback.js";
|
|
29
|
+
import { type ResumeAtBranch, type WriteRefusal } from "./branch-writeback.js";
|
|
29
30
|
import { type LegWrites } from "./session-write-ledger.js";
|
|
30
31
|
import { replayLossLeg } from "./lineage-reroot-view.js";
|
|
32
|
+
import type { RewindOutcome } from "./rewind-outcome.js";
|
|
31
33
|
export interface PrepareAcquireReconcileInput {
|
|
32
34
|
/** borrowed-mutable (service port) — the deployment's session store. This phase's verbs on it are
|
|
33
35
|
* the acquire/forget half of the session resource protocol: `acquire` per attempt, `forget` to
|
|
@@ -50,10 +52,12 @@ export interface PrepareAcquireReconcileInput {
|
|
|
50
52
|
* partition. Never combined with `requireExistingSession` semantics: the require-existing form
|
|
51
53
|
* re-opens and placement is first-write immutable, so it rides only the create-capable arm. */
|
|
52
54
|
placement?: import("../session.js").SessionPlacement;
|
|
53
|
-
/** borrowed-readonly —
|
|
54
|
-
*
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
/** borrowed-readonly — what this leg's row is judged by (read before this phase from the spawner's seat; absent = the leg holds no seat:
|
|
56
|
+
* its row is not judged). Its owner, when a name, is named on the create-capable acquire; the row every attempt resolves — either form —
|
|
57
|
+
* is judged before anything is written to it ({@link judgeLegRow}: under the leg's stop). */
|
|
58
|
+
judged?: import("./delegation-owner.js").JudgedLeg;
|
|
59
|
+
/** borrowed-readonly — told once that the acquired row may be named: the row of the attempt the phase ends on, when that attempt's
|
|
60
|
+
* judgement held (or the leg holds no seat) — never an attempt a lost CAS re-woke from. */
|
|
57
61
|
verified?: (sessionId: string) => void;
|
|
58
62
|
/** borrowed-readonly — the durable-park TOPOLOGY gap sentence for this
|
|
59
63
|
* deployment (`durableParkGapFor`), or `undefined` when the topology is whole / does not apply.
|
|
@@ -65,8 +69,15 @@ export interface PrepareAcquireReconcileInput {
|
|
|
65
69
|
report?: (err: Error, sessionId: string) => void;
|
|
66
70
|
/** borrowed-mutable (the Runner's) — this leg's view of the session write ledger, every storage write issued through it ({@link writesThroughLeg}); absent for a standalone prepare. */
|
|
67
71
|
legWrites?: LegWrites;
|
|
72
|
+
/** borrowed-readonly — the grant holder this leg's session writes carry ({@link stampHolder}, installed nearest the storage, with or
|
|
73
|
+
* without a ledger): the run's `RunInternals.holder` on a leg the host started; absent on a leg an engine lane started, and when the
|
|
74
|
+
* run carries none. */
|
|
75
|
+
holder?: string;
|
|
68
76
|
/** borrowed-readonly — where the leg says what the log's replay dropped, and re-rooted a branch at it ({@link replayLossLeg}): absent ⇒ nothing said and no re-root (a break is refused). */
|
|
69
77
|
replayLossNotice?: Parameters<typeof replayLossLeg>[0];
|
|
78
|
+
/** borrowed-mutable — the leg's record of where its request left the conversation's leaf ({@link RewindOutcome.branch}): the
|
|
79
|
+
* `resumeAt` branch states it moved once its leaf write lands, and the branch it hands on carries the record to its write-back. */
|
|
80
|
+
rewindOutcome?: Pick<RewindOutcome, "branch">;
|
|
70
81
|
}
|
|
71
82
|
/** The phase's outputs (four-class form). All six are fresh bindings —
|
|
72
83
|
* the driver destructures them into consts, so a consumer moved ahead of this call is a lexical
|
|
@@ -79,12 +90,10 @@ export interface PrepareAcquireReconcileResult {
|
|
|
79
90
|
* always wraps storage in the concrete built-in — the epoch pin needs its
|
|
80
91
|
* append/getPromptEpoch). Aliases `acquired.session`'s storage through the proxy. */
|
|
81
92
|
session: StoredSession;
|
|
82
|
-
/** owned cell —
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
|
|
86
|
-
hit: boolean;
|
|
87
|
-
};
|
|
93
|
+
/** owned cell — the leg's write-boundary latch ({@link WriteRefusal}), set by the proxy installed inside `session` whenever a
|
|
94
|
+
* RUN-time write is refused with `conflict` or `holder.superseded` (identity is contract: the proxy closes over this exact
|
|
95
|
+
* object; the run loop reads its word into `errorCode`). */
|
|
96
|
+
writeRefusal: WriteRefusal;
|
|
88
97
|
/** owned — scan-1/A5: what the wake/crash reconcile closed, handed to the run loop so it can mint
|
|
89
98
|
* the matching stream frames (see `Prepared.wakeRecovered`). Written by the acquire attempt that
|
|
90
99
|
* SUCCEEDS (a conflict-losing attempt re-wakes and re-derives the whole set from the fresh
|
|
@@ -4,24 +4,26 @@ import { readMember } from "../thrown-value.js";
|
|
|
4
4
|
import { refuseOpenToolCallAt } from "./continues-from.js";
|
|
5
5
|
import { beforeTakes, judgeRewindTarget } from "./rewind-target.js";
|
|
6
6
|
import { reconcileInterruptedSession } from "../session-reconcile.js";
|
|
7
|
-
import { detectConflicts, settleBranchWriteBack } from "./branch-writeback.js";
|
|
7
|
+
import { detectConflicts, settleBranchWriteBack, writeRefusalLatch } from "./branch-writeback.js";
|
|
8
8
|
import { settleTeardownLeg } from "./teardown-bounded.js";
|
|
9
|
-
import { writesThroughLeg } from "./session-write-ledger.js";
|
|
9
|
+
import { stampHolder, writesThroughLeg } from "./session-write-ledger.js";
|
|
10
10
|
import { replayLossLeg } from "./lineage-reroot-view.js";
|
|
11
11
|
import { atLanding, refuseBranchOutsideWindow } from "./branch-window.js";
|
|
12
|
-
import { createForm,
|
|
12
|
+
import { createForm, judgeLegRow } from "./delegation-owner.js";
|
|
13
13
|
const RECONCILE_MAX_RETRIES = 3;
|
|
14
14
|
export async function prepareAcquireReconcile(input) {
|
|
15
15
|
const { sessions, spec, resume, wakeEffects } = input;
|
|
16
16
|
let acquired;
|
|
17
17
|
let session;
|
|
18
|
-
let
|
|
18
|
+
let writeRefusal;
|
|
19
19
|
let wakeRecovered = [];
|
|
20
20
|
let branch;
|
|
21
|
+
let rebranched = false;
|
|
21
22
|
const lossLeg = input.replayLossNotice !== undefined ? replayLossLeg(input.replayLossNotice) : undefined;
|
|
23
|
+
const namedOwner = input.judged?.owner ?? undefined;
|
|
22
24
|
for (let attempt = 0;; attempt++) {
|
|
23
25
|
try {
|
|
24
|
-
acquired = await sessions.acquire(spec.sessionId, spec.requireExistingSession ? { requireExisting: true } : createForm({ ...(input.placement !== undefined ? { placement: input.placement } : {}), ...(
|
|
26
|
+
acquired = await sessions.acquire(spec.sessionId, spec.requireExistingSession ? { requireExisting: true } : createForm({ ...(input.placement !== undefined ? { placement: input.placement } : {}), ...(namedOwner !== undefined ? { owner: namedOwner } : {}) }));
|
|
25
27
|
}
|
|
26
28
|
catch (err) {
|
|
27
29
|
if (spec.requireExistingSession && err?.code === "not_found") {
|
|
@@ -32,17 +34,19 @@ export async function prepareAcquireReconcile(input) {
|
|
|
32
34
|
}
|
|
33
35
|
throw err;
|
|
34
36
|
}
|
|
35
|
-
if (input.
|
|
36
|
-
await
|
|
37
|
-
|
|
38
|
-
conflictRef = { hit: false };
|
|
37
|
+
if (input.judged !== undefined)
|
|
38
|
+
await judgeLegRow(sessions, acquired, { ...input.judged, minted: input.judged.minted && !spec.requireExistingSession }, (e, id) => input.report?.(e, id));
|
|
39
|
+
writeRefusal = writeRefusalLatch();
|
|
39
40
|
const own = { ids: undefined };
|
|
40
|
-
const
|
|
41
|
-
|
|
41
|
+
const stamped = input.holder !== undefined ? stampHolder(acquired.session.getStorage(), input.holder) : acquired.session.getStorage();
|
|
42
|
+
const legStorage = input.legWrites !== undefined ? writesThroughLeg(stamped, input.legWrites, acquired.sessionId) : stamped;
|
|
43
|
+
session = new StoredSession(detectConflicts(lossLeg !== undefined ? lossLeg.view(legStorage, acquired.sessionId) : legStorage, writeRefusal, own));
|
|
42
44
|
try {
|
|
43
45
|
input.legWrites?.startAt(await session.getLeafId());
|
|
44
|
-
if (!spec.sessionId)
|
|
46
|
+
if (!spec.sessionId) {
|
|
47
|
+
input.verified?.(acquired.sessionId);
|
|
45
48
|
break;
|
|
49
|
+
}
|
|
46
50
|
if (resume) {
|
|
47
51
|
await session.getStorage().setLeafId(resume.leafId).catch((cut) => {
|
|
48
52
|
throw readMember(cut, "code") === "not_found" ? new SessionError("corrupt_session", `session "${spec.sessionId}" no longer holds the entry its checkpoint was cut at ("${resume.leafId}")`, cut, "cut_point_missing") : cut;
|
|
@@ -56,11 +60,22 @@ export async function prepareAcquireReconcile(input) {
|
|
|
56
60
|
const leafSet = await refuseBranchOutsideWindow(raw, landing, spec.resumeAt, acquired.sessionId, "resumeAt", start.id, beforeTakes(target.entry));
|
|
57
61
|
if (leafSet !== null)
|
|
58
62
|
await refuseOpenToolCallAt(session, leafSet, spec.resumeAt, "resumeAt");
|
|
59
|
-
|
|
63
|
+
const outcome = input.rewindOutcome;
|
|
64
|
+
try {
|
|
65
|
+
await storage.setLeafId(leafSet);
|
|
66
|
+
}
|
|
67
|
+
catch (err) {
|
|
68
|
+
if (outcome !== undefined && !isSessionConflict(err))
|
|
69
|
+
outcome.branch = undefined;
|
|
70
|
+
throw err;
|
|
71
|
+
}
|
|
72
|
+
if (outcome !== undefined && leafSet !== leafBefore)
|
|
73
|
+
outcome.branch = "left_moved";
|
|
60
74
|
own.ids = new Set();
|
|
61
|
-
branch = { storage, leafBefore, leafSet, own };
|
|
75
|
+
branch = { storage, leafBefore, leafSet, own, ...(outcome !== undefined && !rebranched ? { outcome } : {}) };
|
|
62
76
|
}
|
|
63
77
|
wakeRecovered = (await reconcileInterruptedSession(session, wakeEffects, resume?.suspendedBatch)).recovered;
|
|
78
|
+
input.verified?.(acquired.sessionId);
|
|
64
79
|
break;
|
|
65
80
|
}
|
|
66
81
|
catch (err) {
|
|
@@ -69,10 +84,13 @@ export async function prepareAcquireReconcile(input) {
|
|
|
69
84
|
const forget = sessions.forget.bind(sessions), id = acquired.sessionId;
|
|
70
85
|
await settleTeardownLeg(() => Promise.resolve(forget(id)).catch(() => undefined), "forget (acquire-reconcile re-wake leg)", (e) => input.report?.(e, id));
|
|
71
86
|
}
|
|
87
|
+
if (branch !== undefined)
|
|
88
|
+
rebranched = true;
|
|
72
89
|
branch = undefined;
|
|
73
90
|
lossLeg?.discard();
|
|
74
91
|
continue;
|
|
75
92
|
}
|
|
93
|
+
input.verified?.(acquired.sessionId);
|
|
76
94
|
if (branch !== undefined)
|
|
77
95
|
await settleBranchWriteBack(branch, acquired.sessionId, "resumeAt branch write-back (acquire-reconcile failure leg)", (e) => input.report?.(e, acquired.sessionId));
|
|
78
96
|
await settleTeardownLeg(() => Promise.resolve(sessions.forget ? sessions.forget(acquired.sessionId) : undefined).catch(() => undefined), "forget (acquire-reconcile failure leg)", (e) => input.report?.(e, acquired.sessionId));
|
|
@@ -80,5 +98,5 @@ export async function prepareAcquireReconcile(input) {
|
|
|
80
98
|
}
|
|
81
99
|
}
|
|
82
100
|
lossLeg?.settle();
|
|
83
|
-
return { acquired, session,
|
|
101
|
+
return { acquired, session, writeRefusal, wakeRecovered, branch };
|
|
84
102
|
}
|