@sema-agent/core 7.70.0 → 7.71.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +728 -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 +7 -6
- 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 +65 -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 +37 -19
- package/dist/index.js +30 -15
- 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 +169 -15
- package/wire-changes/core-stores-sql@7.71.0.json +40 -0
- package/wire-changes/core@7.71.0.json +5827 -0
- package/wire-changes/mods-kernel@7.71.0.json +52 -0
- package/wire-changes/primitives@7.71.0.json +473 -0
- package/wire-changes/wiki-gate@7.71.0.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,5 +1,5 @@
|
|
|
1
1
|
import type { PreToolUseResult } from "./hooks.js";
|
|
2
|
-
import type { PermissionResult } from "./tool-policy.js";
|
|
2
|
+
import type { PermissionResult, ToolCallRequest } from "./tool-policy.js";
|
|
3
3
|
import type { InheritedScreenRead, PreToolUseScreen, PreToolUseScreening } from "./runner/gate-exit.js";
|
|
4
4
|
import type { RewriteAuthor, ToolInputRewrite } from "./task-event.js";
|
|
5
5
|
/** One gate pass's account of its rewrites: the bytes it took at its entry, and one author per adoption that changed the bytes
|
|
@@ -38,6 +38,14 @@ export declare function screeningAuthorship(req: {
|
|
|
38
38
|
}, below: readonly unknown[]) => undefined;
|
|
39
39
|
readonly of: (answer: unknown) => readonly string[];
|
|
40
40
|
};
|
|
41
|
+
/** The digest of the bytes a seat hands an approver, taken BEFORE it waits (a value read afterwards could have been moved to match). */
|
|
42
|
+
export declare const shownDigestOf: (call: ToolCallRequest) => string | undefined;
|
|
43
|
+
/** `resolved` read by the one reading of an answer's edit ({@link editOfAnswer}; its `updatedInput` read once) over the bytes `shown`
|
|
44
|
+
* digests ({@link shownDigestOf}, taken before the wait): those bytes handed back are a plain approval, its other members and record
|
|
45
|
+
* kept. Every seat that takes an approval from outside the engine's own resolver (which reads its approver so already) reads it here,
|
|
46
|
+
* synchronously on the answer it awaited (`answerAsShown(shownDigestOf(call), await seat(…), call)`), so the read adds no wait. Only
|
|
47
|
+
* a plain-data answer is read so (its copy runs no code and drops nothing); any other answer is left as it came, its edit re-judged. */
|
|
48
|
+
export declare function answerAsShown<R extends PermissionResult>(shown: string | undefined, resolved: R, call: Pick<ToolCallRequest, "toolName">): R;
|
|
41
49
|
/** What a judge did with the bytes it was handed: kept them (`as_is`), or handed back another form. */
|
|
42
50
|
export type RejudgeReading = {
|
|
43
51
|
readonly kind: "as_is";
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { types } from "node:util";
|
|
2
|
+
import { canonicalize, editOfAnswer, exactBoundInputHashOf } from "./canonical-json.js";
|
|
2
3
|
import { argsAsTheToolReads } from "./effective-path-target.js";
|
|
3
4
|
export function noteRewrite(account, req, from, to, authors) {
|
|
4
5
|
if (!sameBytes(req, from, to))
|
|
@@ -40,6 +41,15 @@ export function screeningAuthorship(req) {
|
|
|
40
41
|
of: (answer) => (typeof answer === "object" && answer !== null ? (authors.get(answer) ?? []) : []),
|
|
41
42
|
};
|
|
42
43
|
}
|
|
44
|
+
export const shownDigestOf = (call) => exactBoundInputHashOf(call.toolName, call.args);
|
|
45
|
+
export function answerAsShown(shown, resolved, call) {
|
|
46
|
+
if (!isPlainDataAnswer(resolved) || resolved.action !== "allow" || editOfAnswer(call.toolName, shown, resolved.updatedInput) !== undefined)
|
|
47
|
+
return resolved;
|
|
48
|
+
const plain = { ...resolved };
|
|
49
|
+
Reflect.deleteProperty(plain, "updatedInput");
|
|
50
|
+
return plain;
|
|
51
|
+
}
|
|
52
|
+
const isPlainDataAnswer = (v) => !types.isProxy(v) && [Object.prototype, null].includes(Object.getPrototypeOf(v)) && Reflect.ownKeys(v).every((k) => ((d) => d !== undefined && "value" in d && d.enumerable === true)(Object.getOwnPropertyDescriptor(v, k)));
|
|
43
53
|
export function sameBytes(req, a, b) {
|
|
44
54
|
return a === b || canonicalize(argsAsTheToolReads(req, a)) === canonicalize(argsAsTheToolReads(req, b));
|
|
45
55
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { PERSISTED_RULE_MATCHES, RULE_OFFER_BATCH_MEMBER_KINDS, RULE_OFFER_KINDS, UNCOVERED_SEGMENT_REASONS, isAddStamp, } from "./permission-rule-model.js";
|
|
2
2
|
import { isPlainRecord } from "./checkpoint-store.js";
|
|
3
|
+
const OFFER_MATCHES = PERSISTED_RULE_MATCHES.filter((m) => m !== "call");
|
|
3
4
|
export const RULE_OFFER_SHAPE_PROBLEMS = Object.freeze(["not_an_array", "unknown_word", "malformed"]);
|
|
4
5
|
const MALFORMED = Object.freeze({ problem: "malformed" });
|
|
5
6
|
const UNKNOWN_WORD = Object.freeze({ problem: "unknown_word" });
|
|
@@ -34,7 +35,7 @@ function readOfferElement(value) {
|
|
|
34
35
|
switch (kind) {
|
|
35
36
|
case "single": {
|
|
36
37
|
const rule = value.rule;
|
|
37
|
-
const match = wordOf(value.match,
|
|
38
|
+
const match = wordOf(value.match, OFFER_MATCHES);
|
|
38
39
|
const command = value.command;
|
|
39
40
|
if (typeof rule !== "string")
|
|
40
41
|
return MALFORMED;
|
|
@@ -105,7 +106,7 @@ function readBatchMember(value) {
|
|
|
105
106
|
function commandMember(rule, rawMatch, command, segment) {
|
|
106
107
|
if (typeof rule !== "string")
|
|
107
108
|
return MALFORMED;
|
|
108
|
-
const match = wordOf(rawMatch,
|
|
109
|
+
const match = wordOf(rawMatch, OFFER_MATCHES);
|
|
109
110
|
if (typeof match !== "string")
|
|
110
111
|
return match;
|
|
111
112
|
if (typeof command !== "string" || typeof segment !== "string")
|
|
@@ -3,6 +3,8 @@ import type { HumanReviewGateRow } from "../task-result.js";
|
|
|
3
3
|
import type { NestedUsage, PausedCause, TaskResult, TerminalCause } from "../types.js";
|
|
4
4
|
import type { TerminalBlockedDetail } from "../terminal-cause.js";
|
|
5
5
|
import type { HaltConsumption, LoopTerminalReason } from "../../internal/harness.js";
|
|
6
|
+
import type { PostureSeatsSource } from "./contracts.js";
|
|
7
|
+
import { type RewindOutcome } from "./rewind-outcome.js";
|
|
6
8
|
/** Per-task usage/cost accumulator (filled across the run loop, surfaced as `TaskResult.stats`). */
|
|
7
9
|
export interface Stats {
|
|
8
10
|
turns: number;
|
|
@@ -135,6 +137,9 @@ export interface ResultFlags {
|
|
|
135
137
|
* Pure pass-through — assembly neither adds nor filters (a rewind that FAILED never reaches here; it
|
|
136
138
|
* throws at prepare and lands in the `threw` slot as a terminal errorCode). */
|
|
137
139
|
rewindNotes?: TaskResult["rewindNotes"];
|
|
140
|
+
/** The leg's record of what its rewind did ({@link RewindOutcome}): read once at the return ({@link withRewindOutcome}). Absent on a
|
|
141
|
+
* leg that asked for no rewind. */
|
|
142
|
+
rewindOutcome?: RewindOutcome;
|
|
138
143
|
/** The run's OWN edited-file ledger, echoed on `TaskResult.editedFiles`. Pure pass-through on
|
|
139
144
|
* EVERY terminal — what this run's hands changed is a fact about the leg that ran, whatever
|
|
140
145
|
* terminal it reached (a failed/aborted run that edited files is exactly the case a "restore the
|
|
@@ -183,19 +188,12 @@ export interface ResultFlags {
|
|
|
183
188
|
readonly verdictRefused?: TaskResult["verdictRefused"];
|
|
184
189
|
};
|
|
185
190
|
verdictLastEndRefused?: boolean;
|
|
186
|
-
/** The
|
|
187
|
-
*
|
|
188
|
-
|
|
189
|
-
* the posture is a fact about the leg that ran, whatever terminal it reached — a post-completion
|
|
190
|
-
* spawner folds it stricter-wins into follow-on legs; every other consumer may ignore it. */
|
|
191
|
-
effectiveReadFace?: TaskResult["effectiveReadFace"];
|
|
192
|
-
effectiveWriteFace?: TaskResult["effectiveWriteFace"];
|
|
193
|
-
effectiveReadDenyPatterns?: TaskResult["effectiveReadDenyPatterns"];
|
|
191
|
+
/** The leg's postures ({@link resultPostureSeats}): the prepared leg, read by the one assembly of its posture seats. INDEPENDENT of
|
|
192
|
+
* the status/errorCode chain — the posture is a fact about the leg that ran, whatever terminal it reached. */
|
|
193
|
+
posture?: PostureSeatsSource;
|
|
194
194
|
/** The byte floor's latch as the leg ends ({@link TaskResult.readDenyFloor}): `true` ⇔ a read-deny table the leg compiled — at
|
|
195
195
|
* prepare or after — held rows its environment's floor does not keep. Pure pass-through, every terminal (the posture law). */
|
|
196
196
|
readDenyFloorUnkept?: boolean;
|
|
197
|
-
effectiveAgentConfigDirs?: TaskResult["effectiveAgentConfigDirs"];
|
|
198
|
-
effectiveAgentHomeDirs?: TaskResult["effectiveAgentHomeDirs"];
|
|
199
197
|
/** The memory-visibility observation, echoed on
|
|
200
198
|
* `TaskResult.effectiveMemoryScopes`. Pure pass-through on every terminal, same law as the
|
|
201
199
|
* read-posture seats above: present iff prepare completed (the memory-less states are their own
|
|
@@ -243,7 +241,9 @@ export interface ResultFlags {
|
|
|
243
241
|
budgetAxis?: BudgetAxis;
|
|
244
242
|
blockedReason?: string;
|
|
245
243
|
blockedDetail?: TerminalBlockedDetail;
|
|
246
|
-
conflict
|
|
244
|
+
/** The leg's write-boundary latch as the result reads it (`Prepared.writeRefusal`): `conflict` — a session write lost the
|
|
245
|
+
* optimistic lock (slots 6 / 11); `holder.superseded` — a session write was refused for the run's grant (slot 0). */
|
|
246
|
+
writeRefusal?: "conflict" | "holder.superseded";
|
|
247
247
|
/** The request-build guard threw the irreducible-core terminal this run (the trim's core or the git frame's) — the loop
|
|
248
248
|
* folded it into a text-only failure message, so the typed code rides this flag. */
|
|
249
249
|
coreOverBudget?: boolean;
|
|
@@ -324,6 +324,8 @@ export declare function terminalCauseOf(final: AssistantMessage | undefined, sta
|
|
|
324
324
|
* Build the final {@link TaskResult} from the run's terminal state. **The errorCode priority chain is a
|
|
325
325
|
* public contract** (callers `switch` on these strings) — first match wins, in this exact order
|
|
326
326
|
* (red-line #3, do not reorder):
|
|
327
|
+
* 0. `writeRefusal` `"holder.superseded"` → `"holder.superseded"` (a session write refused for the run's grant; the leg stopped),
|
|
328
|
+
* EXCEPT under a committed durable pause (8.5 wins: the row was laid down while the grant held)
|
|
327
329
|
* 1. `outputInvalid` → `"output.invalid"`
|
|
328
330
|
* 2. degenerate → `"output.degenerate"` + `salvagedOutput` (wins over budget/timeout)
|
|
329
331
|
* 3. `budgetHit` → `"limits.max_tokens_exceeded"` | `"limits.max_cost_exceeded"` (by `budgetAxis`;
|
|
@@ -364,3 +366,11 @@ export declare function assembleResult(leg: {
|
|
|
364
366
|
readonly taskId: string;
|
|
365
367
|
readonly sessionId: string;
|
|
366
368
|
}, final: AssistantMessage | undefined, stats: Stats, flags: ResultFlags): TaskResult;
|
|
369
|
+
/**
|
|
370
|
+
* THE assembly of a leg's posture seats on its result — read by the result's two mints, this module's `assembleResult` and the stream
|
|
371
|
+
* layer's failure backstop (a leg that throws past its result assembly, once its identity wiring published the leg), so the seats ride either: the read and write faces, the deny
|
|
372
|
+
* additions and the declared places (the follow-on legs fold them) and the three postures a parked row keeps for its resume (the read
|
|
373
|
+
* block, the sandbox requirement, the external-content fold). Pure pass-through of the leg's own resolution; the declared places and the
|
|
374
|
+
* sandbox requirement are copied here, the deny additions are the defensive copy prepare already made. No leg ⇒ no seats.
|
|
375
|
+
*/
|
|
376
|
+
export declare function resultPostureSeats(p: PostureSeatsSource | undefined): Partial<Pick<TaskResult, "effectiveReadFace" | "effectiveWriteFace" | "effectiveReadDenyPatterns" | "effectiveAgentConfigDirs" | "effectiveAgentHomeDirs" | "effectiveBlockReadsOutsideRoots" | "effectiveSandbox" | "effectiveExternalContentTarget">>;
|
|
@@ -6,6 +6,7 @@ import { terminalProjection } from "./terminal-projection.js";
|
|
|
6
6
|
import { endingCutConsumed, haltConsumed, turnAbortedByOf } from "./halt-attribution.js";
|
|
7
7
|
import { providerReportedModel } from "../message-utils.js";
|
|
8
8
|
import { readMember, thrownText } from "../thrown-value.js";
|
|
9
|
+
import { withRewindOutcome } from "./rewind-outcome.js";
|
|
9
10
|
const SALVAGE_ELIGIBLE_TERMINALS = new Set([
|
|
10
11
|
"output.degenerate",
|
|
11
12
|
"limits.max_tokens_exceeded",
|
|
@@ -45,7 +46,10 @@ export function terminalCauseOf(final, stats, flags) {
|
|
|
45
46
|
const errorKind = readMember(final, "errorKind");
|
|
46
47
|
const isDegenerate = final?.stopReason === "error" && isDegenerateCutMessage({ errorKind: errorKind });
|
|
47
48
|
const loopExit = loopExitFailureOf(flags.loopTerminal);
|
|
48
|
-
if (flags.
|
|
49
|
+
if (flags.writeRefusal === "holder.superseded" && flags.paused === undefined) {
|
|
50
|
+
terminal = { kind: "failed", code: "holder.superseded", message: "this leg's grant is no longer the run's current one (another leg holds the run, or the run has ended): the session refused its write and the leg stopped — nothing it wrote after that is in the session; do not retry it" };
|
|
51
|
+
}
|
|
52
|
+
else if (flags.outputInvalid) {
|
|
49
53
|
const refused = flags.verdictLastEndRefused === true ? flags.refusalRecords?.(true).verdictRefused : undefined;
|
|
50
54
|
terminal = { kind: "failed", code: "output.invalid", message: refused !== undefined ? `the structured output submissions were refused at the gate (${refused.deniedBy}) until the retry limit; no result was delivered (see verdictRefused)` : "model did not produce a valid structured output within the retry limit" };
|
|
51
55
|
}
|
|
@@ -78,7 +82,7 @@ export function terminalCauseOf(final, stats, flags) {
|
|
|
78
82
|
}
|
|
79
83
|
else if (flags.threw) {
|
|
80
84
|
const thrown = thrownFailureOf(flags.threw, thrownText(flags.threw));
|
|
81
|
-
const axisCode = flags.abortedForTimeout ? "limits.max_walltime_exceeded" : flags.abortedForTurns ? "limits.max_turns_exceeded" : flags.conflict ? "conflict" : undefined;
|
|
85
|
+
const axisCode = flags.abortedForTimeout ? "limits.max_walltime_exceeded" : flags.abortedForTurns ? "limits.max_turns_exceeded" : flags.writeRefusal === "conflict" ? "conflict" : undefined;
|
|
82
86
|
const code = axisCode ?? thrown.code;
|
|
83
87
|
const detail = axisCode === undefined ? thrown.detail : undefined;
|
|
84
88
|
terminal = { kind: "failed", ...(code !== undefined ? { code } : {}), message: thrown.message, ...(detail !== undefined ? { detail } : {}) };
|
|
@@ -125,7 +129,7 @@ export function terminalCauseOf(final, stats, flags) {
|
|
|
125
129
|
code = "irreducible_core_over_budget";
|
|
126
130
|
messageNamed = false;
|
|
127
131
|
}
|
|
128
|
-
else if (flags.conflict) {
|
|
132
|
+
else if (flags.writeRefusal === "conflict") {
|
|
129
133
|
code = "conflict";
|
|
130
134
|
messageNamed = false;
|
|
131
135
|
}
|
|
@@ -181,5 +185,21 @@ export function assembleResult(leg, final, stats, flags) {
|
|
|
181
185
|
const turnAbortedBy = turnAbortedByOf(flags.haltConsumption);
|
|
182
186
|
const records = flags.refusalRecords?.(terminal.kind !== "paused") ?? {};
|
|
183
187
|
const { refusedToolCalls, verdictRefused } = records;
|
|
184
|
-
return { taskId, ...(flags.runId !== undefined ? { runId: flags.runId } : {}), sessionId, terminal, ...(flags.model !== undefined ? { model: flags.model } : {}), ...(responseModel !== undefined ? { responseModel } : {}), result: result.trim(), ...(flags.answerEntryIds !== undefined ? { resultEntryIds: [...flags.answerEntryIds] } : {}), ...(flags.intake !== undefined ? { intake: flags.intake } : {}), ...(flags.displayed !== undefined && flags.displayed.by.length > 0 ? { resultDisplayedBy: [...flags.displayed.by] } : {}), ...(flags.displayed?.inPart === true ? { resultDisplayedInPart: true } : {}), salvagedOutput, ...(apiFailure !== undefined ? { apiFailure } : {}), ...(retryAfterMs !== undefined ? { retryAfterMs } : {}), ...(flags.rewindNotes !== undefined && flags.rewindNotes.length > 0 ? { rewindNotes: flags.rewindNotes } : {}), ...(flags.editedFiles !== undefined && flags.editedFiles.length > 0 ? { editedFiles: flags.editedFiles } : {}), ...(flags.haltedOnUserRejection === true ? { haltedOnUserRejection: true } : {}), ...(stampHaltedByUser ? { haltedByUser: true } : {}), ...(turnAbortedBy !== undefined ? { turnAbortedBy } : {}), ...(terminal.kind === "completed" && flags.limitCrossed !== undefined ? { limitCrossed: flags.limitCrossed } : {}), ...(terminal.kind === "failed" && flags.budgetHit === "precall" && flags.spendStop !== undefined && (terminal.code === "limits.max_tokens_exceeded" || terminal.code === "limits.max_cost_exceeded") ? { limitCrossed: { axis: flags.spendStop.axis === "tokens" ? "budget_tokens" : "budget_cost", limit: flags.spendStop.limit, observed: flags.spendStop.observed, heldBy: flags.spendStop.heldBy } } : {}), ...(flags.remoteEnvFailures !== undefined && flags.remoteEnvFailures.length > 0 ? { remoteEnvFailures: [...flags.remoteEnvFailures] } : {}), ...(flags.refusedAsks !== undefined && flags.refusedAsks.length > 0 ? { refusedAsks: [...flags.refusedAsks] } : {}), ...(refusedToolCalls !== undefined ? { refusedToolCalls } : {}), ...(verdictRefused !== undefined ? { verdictRefused } : {}), ...(flags.strandedHumanAnswers !== undefined && flags.strandedHumanAnswers.length > 0 ? { strandedHumanAnswers: flags.strandedHumanAnswers } : {}), ...(flags.
|
|
188
|
+
return withRewindOutcome({ taskId, ...(flags.runId !== undefined ? { runId: flags.runId } : {}), sessionId, terminal, ...(flags.model !== undefined ? { model: flags.model } : {}), ...(responseModel !== undefined ? { responseModel } : {}), result: result.trim(), ...(flags.answerEntryIds !== undefined ? { resultEntryIds: [...flags.answerEntryIds] } : {}), ...(flags.intake !== undefined ? { intake: flags.intake } : {}), ...(flags.displayed !== undefined && flags.displayed.by.length > 0 ? { resultDisplayedBy: [...flags.displayed.by] } : {}), ...(flags.displayed?.inPart === true ? { resultDisplayedInPart: true } : {}), salvagedOutput, ...(apiFailure !== undefined ? { apiFailure } : {}), ...(retryAfterMs !== undefined ? { retryAfterMs } : {}), ...(flags.rewindNotes !== undefined && flags.rewindNotes.length > 0 ? { rewindNotes: flags.rewindNotes } : {}), ...(flags.editedFiles !== undefined && flags.editedFiles.length > 0 ? { editedFiles: flags.editedFiles } : {}), ...(flags.haltedOnUserRejection === true ? { haltedOnUserRejection: true } : {}), ...(stampHaltedByUser ? { haltedByUser: true } : {}), ...(turnAbortedBy !== undefined ? { turnAbortedBy } : {}), ...(terminal.kind === "completed" && flags.limitCrossed !== undefined ? { limitCrossed: flags.limitCrossed } : {}), ...(terminal.kind === "failed" && flags.budgetHit === "precall" && flags.spendStop !== undefined && (terminal.code === "limits.max_tokens_exceeded" || terminal.code === "limits.max_cost_exceeded") ? { limitCrossed: { axis: flags.spendStop.axis === "tokens" ? "budget_tokens" : "budget_cost", limit: flags.spendStop.limit, observed: flags.spendStop.observed, heldBy: flags.spendStop.heldBy } } : {}), ...(flags.remoteEnvFailures !== undefined && flags.remoteEnvFailures.length > 0 ? { remoteEnvFailures: [...flags.remoteEnvFailures] } : {}), ...(flags.refusedAsks !== undefined && flags.refusedAsks.length > 0 ? { refusedAsks: [...flags.refusedAsks] } : {}), ...(refusedToolCalls !== undefined ? { refusedToolCalls } : {}), ...(verdictRefused !== undefined ? { verdictRefused } : {}), ...(flags.strandedHumanAnswers !== undefined && flags.strandedHumanAnswers.length > 0 ? { strandedHumanAnswers: flags.strandedHumanAnswers } : {}), ...resultPostureSeats(flags.posture), ...(flags.readDenyFloorUnkept === true ? { readDenyFloor: { kept: false } } : {}), ...(flags.effectiveMemoryScopes !== undefined ? { effectiveMemoryScopes: flags.effectiveMemoryScopes } : {}), ...(flags.placementRoot !== undefined ? { placementRoot: flags.placementRoot } : {}), ...(flags.effectiveReasoning !== undefined ? { effectiveReasoning: flags.effectiveReasoning } : {}), ...(flags.fastMode !== undefined ? { fastMode: flags.fastMode } : {}), ...(flags.compaction !== undefined ? { compaction: flags.compaction } : {}), stats: publicStats }, flags.rewindOutcome);
|
|
189
|
+
}
|
|
190
|
+
export function resultPostureSeats(p) {
|
|
191
|
+
if (p === undefined)
|
|
192
|
+
return {};
|
|
193
|
+
const configRoots = p.callerPlaces?.configRoots.carried;
|
|
194
|
+
const homes = p.callerPlaces?.homes.carried;
|
|
195
|
+
return {
|
|
196
|
+
...(p.effectiveReadFace !== undefined ? { effectiveReadFace: p.effectiveReadFace } : {}),
|
|
197
|
+
...(p.effectiveWriteFace !== undefined ? { effectiveWriteFace: p.effectiveWriteFace } : {}),
|
|
198
|
+
...(p.effectiveReadDenyPatterns !== undefined && p.effectiveReadDenyPatterns.length > 0 ? { effectiveReadDenyPatterns: p.effectiveReadDenyPatterns } : {}),
|
|
199
|
+
...(configRoots !== undefined && configRoots.length > 0 ? { effectiveAgentConfigDirs: [...configRoots] } : {}),
|
|
200
|
+
...(homes !== undefined && homes.length > 0 ? { effectiveAgentHomeDirs: [...homes] } : {}),
|
|
201
|
+
...(p.effectiveBlockReadsOutsideRoots === true ? { effectiveBlockReadsOutsideRoots: true } : {}),
|
|
202
|
+
...(p.effectiveSandbox !== undefined ? { effectiveSandbox: structuredClone(p.effectiveSandbox) } : {}),
|
|
203
|
+
...(p.effectiveExternalContentTarget === true ? { effectiveExternalContentTarget: true } : {}),
|
|
204
|
+
};
|
|
185
205
|
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The two run-time reminders of the turn-boundary attachment lane — `silent_turn_reminder` (the model has gone several requests
|
|
3
|
+
* without a word to the person) and `elapsed_time_reminder` (how long the person's request has been running) — their switch and
|
|
4
|
+
* their judgment. Pure: no I/O, no clock of its own; the boundary hands the rows and the time.
|
|
5
|
+
*
|
|
6
|
+
* THE SWITCH is read once, at prepare ({@link runTimeReminderLane}): the run's prompt traits say whether the model is one the
|
|
7
|
+
* reference reminds (its capabilities `silent_turn_reminder` / `timed_silent_turn_reminder` / `elapsed_time_reminder`), the
|
|
8
|
+
* task's attachments config may turn either off (`TaskSpec.attachments.silentTurnReminder` / `.elapsedTimeReminder`, default on —
|
|
9
|
+
* the registry rows), and a child leg never gets the silent reminder (the reference serves it on the main thread only). The
|
|
10
|
+
* producers read the resolved lane, never a trait.
|
|
11
|
+
*
|
|
12
|
+
* THE JUDGMENT follows the reference's transcript walk ({@link readSilentStretch}): from the end backwards, an assistant row
|
|
13
|
+
* that says something to the person ends the stretch of silence; a person's input that opened its leg (an objective, a resume's
|
|
14
|
+
* continuation) ends it and is its start, a steer that landed mid-run does not touch it; a delivered silent
|
|
15
|
+
* reminder counts and moves the start; a turn-boundary bundle without one (the reference's other attachments: the elapsed time,
|
|
16
|
+
* the token count, …) is skipped; any other engine note moves the start (the reference's meta rows). The count arm fires when fewer than
|
|
17
|
+
* {@link SILENT_TURN_REMINDER.MAX_PER_STRETCH} reminders rode this stretch and {@link SILENT_TURN_REMINDER.TURNS} silent requests
|
|
18
|
+
* passed since the last one; the timed arm fires when at least one silent request passed since the last one and the silence has
|
|
19
|
+
* lasted {@link SILENT_TURN_REMINDER.SECONDS} seconds — with no cap: the reminder itself restarts the silence.
|
|
20
|
+
*/
|
|
21
|
+
import type { AgentMessage } from "../../internal/harness.js";
|
|
22
|
+
import type { PromptTraitName } from "../../prompt-assembly/catalog/schema.js";
|
|
23
|
+
/** The reference's thresholds: `wWn` (cli321.js:288269), `TWn` (cli321.js:288269), `F5r` (cli321.js:288269). */
|
|
24
|
+
export declare const SILENT_TURN_REMINDER: Readonly<{
|
|
25
|
+
/** Silent requests since the last reminder before the count arm fires again. */
|
|
26
|
+
TURNS: 5;
|
|
27
|
+
/** Reminders one stretch of silence may carry under the count arm. */
|
|
28
|
+
MAX_PER_STRETCH: 3;
|
|
29
|
+
/** Seconds of silence before the timed arm fires. */
|
|
30
|
+
SECONDS: 60;
|
|
31
|
+
}>;
|
|
32
|
+
/** Which arm of the silent reminder a run is on. */
|
|
33
|
+
export type SilentTurnReminderArm = "off" | "turns" | "timed";
|
|
34
|
+
/** The run's two reminder lanes, resolved once at prepare. */
|
|
35
|
+
export interface RunTimeReminderLane {
|
|
36
|
+
readonly silentTurn: SilentTurnReminderArm;
|
|
37
|
+
readonly elapsedTime: boolean;
|
|
38
|
+
}
|
|
39
|
+
/** The run's reminder lanes: the traits' answer, less what the task's attachments config turned off, less the silent reminder on
|
|
40
|
+
* a child leg. `switches` are the config's two answers (absent key = on, {@link import("./turn-attachments.js").attachmentSwitchOn}). */
|
|
41
|
+
export declare function runTimeReminderLane(input: {
|
|
42
|
+
readonly traits: ReadonlySet<PromptTraitName>;
|
|
43
|
+
readonly childLeg: boolean;
|
|
44
|
+
readonly switches: {
|
|
45
|
+
readonly silentTurn: boolean;
|
|
46
|
+
readonly elapsedTime: boolean;
|
|
47
|
+
};
|
|
48
|
+
}): RunTimeReminderLane;
|
|
49
|
+
/** What the transcript says about the current stretch of silence. */
|
|
50
|
+
export interface SilentStretch {
|
|
51
|
+
/** Assistant requests that said nothing to the person since the stretch's latest reminder (since its start when none rode). */
|
|
52
|
+
readonly turnsSinceLastReminder: number;
|
|
53
|
+
/** Silent reminders delivered in this stretch. */
|
|
54
|
+
readonly remindersInStretch: number;
|
|
55
|
+
/** When the silence started (ms, the rows' clock): the latest of the person's input, a delivered reminder, an engine note that
|
|
56
|
+
* is not a boundary bundle, and the last row of a request that spoke; absent only for an empty transcript. */
|
|
57
|
+
readonly silentSince: number | undefined;
|
|
58
|
+
}
|
|
59
|
+
/** How the running leg opened (set where its opening prompt is sent — run-leg.ts): whether that prompt's row is a person's-input
|
|
60
|
+
* row (a fresh leg's objective; a resume's continuation that carries an input frame) and when, on the rows' clock. A leg whose
|
|
61
|
+
* opening row is not one — a resume carrying no input frame, a wake — still stamps its first person's-input row as the one that
|
|
62
|
+
* opened it (`legFirstInput`, the harness's stamp, which the file-history boundary keys on); for the stretch that row is a steer
|
|
63
|
+
* that landed mid-run, the reference's queued-command attachment (`d3r` breaks on a person's prompt only). The stored row of an
|
|
64
|
+
* EARLIER such leg cannot be told from its opener: only the running leg's is read this way. */
|
|
65
|
+
export interface LegOpening {
|
|
66
|
+
readonly byPerson: boolean;
|
|
67
|
+
readonly at: number;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The current stretch of silence, read backwards off the rows the next request is built from (the reference's `d3r`). One
|
|
71
|
+
* assistant row is one request (the reference groups streamed rows by message id; a row here is already one response).
|
|
72
|
+
*/
|
|
73
|
+
export declare function readSilentStretch(rows: readonly AgentMessage[], opening?: LegOpening): SilentStretch;
|
|
74
|
+
/** Whether the silent reminder is due at a boundary on `arm`, `now` on the rows' clock (the reference's `u3r`). */
|
|
75
|
+
export declare function silentTurnReminderDue(stretch: SilentStretch, arm: Exclude<SilentTurnReminderArm, "off">, now: number): boolean;
|
|
76
|
+
/**
|
|
77
|
+
* A boundary's inputs for the two producers: the silent reminder's stretch, read off the rows the next request is built from (a
|
|
78
|
+
* read that fails says nothing this boundary), with `now` on the rows' own clock (the harness stamps a row with `Date.now()`); the
|
|
79
|
+
* elapsed reminder's reading of the session's clock. A source whose frame is already on its way is not read again.
|
|
80
|
+
*/
|
|
81
|
+
export declare function boundaryReminderInputs(input: {
|
|
82
|
+
readonly lane: RunTimeReminderLane;
|
|
83
|
+
readonly elapsedClock: {
|
|
84
|
+
elapsedMs(): number;
|
|
85
|
+
};
|
|
86
|
+
/** The running leg's opening, once its opening prompt has set it. */
|
|
87
|
+
readonly opening: {
|
|
88
|
+
readonly current?: LegOpening;
|
|
89
|
+
};
|
|
90
|
+
readonly carried: (source: "silent_turn_reminder" | "elapsed_time_reminder") => boolean;
|
|
91
|
+
readonly rows: () => Promise<readonly AgentMessage[]>;
|
|
92
|
+
}): Promise<{
|
|
93
|
+
readonly silentTurn?: {
|
|
94
|
+
readonly stretch: SilentStretch;
|
|
95
|
+
readonly now: number;
|
|
96
|
+
};
|
|
97
|
+
readonly elapsedMs?: number;
|
|
98
|
+
}>;
|
|
99
|
+
/** The elapsed-time reminder's two slots for a duration (the reference's `H5r`): whole minutes, and the seconds past them in two
|
|
100
|
+
* digits. */
|
|
101
|
+
export declare function elapsedTimeSlots(ms: number): {
|
|
102
|
+
readonly minutes: string;
|
|
103
|
+
readonly seconds: string;
|
|
104
|
+
};
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { traitsHold } from "../../prompt-assembly/select.js";
|
|
2
|
+
import { ASK_USER_QUESTION_TOOL_NAME } from "../ask-question.js";
|
|
3
|
+
import { PRESENT_PLAN_TOOL_NAME } from "../present-plan-tool.js";
|
|
4
|
+
import { readBundledAttachments } from "../attachment-source.js";
|
|
5
|
+
import { legFirstInputOf, userRowSourceOf } from "../user-row-origin.js";
|
|
6
|
+
export const SILENT_TURN_REMINDER = Object.freeze({
|
|
7
|
+
TURNS: 5,
|
|
8
|
+
MAX_PER_STRETCH: 3,
|
|
9
|
+
SECONDS: 60,
|
|
10
|
+
});
|
|
11
|
+
const LANE_TRAITS = Object.freeze({
|
|
12
|
+
silentTurn: { allOf: ["silent_turn_reminder"] },
|
|
13
|
+
silentTurnTimed: { allOf: ["timed_silent_turn_reminder"] },
|
|
14
|
+
elapsedTime: { allOf: ["elapsed_time_reminder"] },
|
|
15
|
+
});
|
|
16
|
+
export function runTimeReminderLane(input) {
|
|
17
|
+
const { traits, childLeg, switches } = input;
|
|
18
|
+
const silentOn = switches.silentTurn && !childLeg && traitsHold(LANE_TRAITS.silentTurn, traits);
|
|
19
|
+
return Object.freeze({
|
|
20
|
+
silentTurn: !silentOn ? "off" : traitsHold(LANE_TRAITS.silentTurnTimed, traits) ? "timed" : "turns",
|
|
21
|
+
elapsedTime: switches.elapsedTime && traitsHold(LANE_TRAITS.elapsedTime, traits),
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
const SPEAKING_TOOLS = new Set([ASK_USER_QUESTION_TOOL_NAME, PRESENT_PLAN_TOOL_NAME]);
|
|
25
|
+
const EMPTY_TEXT_PLACEHOLDER = "(no content)";
|
|
26
|
+
const said = (v) => (typeof v === "string" ? v.trim() : "");
|
|
27
|
+
function speaks(row) {
|
|
28
|
+
return Array.isArray(row.content) && row.content.some((b) => (b?.type === "text" && said(b.text) !== "" && said(b.text) !== EMPTY_TEXT_PLACEHOLDER) ||
|
|
29
|
+
(b?.type === "thinking" && b.redacted !== true && said(b.thinking) !== "") ||
|
|
30
|
+
(b?.type === "toolCall" && SPEAKING_TOOLS.has(b.name)));
|
|
31
|
+
}
|
|
32
|
+
function personInput(row) {
|
|
33
|
+
const source = userRowSourceOf(row);
|
|
34
|
+
return source === undefined || source.origin === "human_input";
|
|
35
|
+
}
|
|
36
|
+
function bundledSources(row) {
|
|
37
|
+
const m = row;
|
|
38
|
+
if (m.attachments === undefined)
|
|
39
|
+
return undefined;
|
|
40
|
+
const text = typeof m.content === "string" ? m.content : Array.isArray(m.content) ? m.content.map((b) => (typeof b?.text === "string" ? b.text : "")).join("") : "";
|
|
41
|
+
return readBundledAttachments(m.attachments, text.length)?.map((a) => a.source);
|
|
42
|
+
}
|
|
43
|
+
export function readSilentStretch(rows, opening) {
|
|
44
|
+
let turns = 0;
|
|
45
|
+
let reminders = 0;
|
|
46
|
+
let since;
|
|
47
|
+
let earliest;
|
|
48
|
+
for (let i = rows.length - 1; i >= 0; i--) {
|
|
49
|
+
const row = rows[i];
|
|
50
|
+
const at = row.timestamp;
|
|
51
|
+
if (typeof at === "number" && Number.isFinite(at))
|
|
52
|
+
earliest = at;
|
|
53
|
+
const role = row.role;
|
|
54
|
+
if (role === "assistant") {
|
|
55
|
+
const assistant = row;
|
|
56
|
+
if (speaks(assistant)) {
|
|
57
|
+
since ??= assistant.timestamp;
|
|
58
|
+
return { turnsSinceLastReminder: turns, remindersInStretch: reminders, silentSince: since };
|
|
59
|
+
}
|
|
60
|
+
if (reminders === 0)
|
|
61
|
+
turns++;
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
if (role !== "user")
|
|
65
|
+
continue;
|
|
66
|
+
const bundled = bundledSources(row);
|
|
67
|
+
if (bundled?.includes("silent_turn_reminder") === true) {
|
|
68
|
+
reminders++;
|
|
69
|
+
since ??= row.timestamp;
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
if (bundled !== undefined)
|
|
73
|
+
continue;
|
|
74
|
+
const first = legFirstInputOf(row);
|
|
75
|
+
if (first === false || (first === true && opening?.byPerson === false && typeof at === "number" && at >= opening.at))
|
|
76
|
+
continue;
|
|
77
|
+
since ??= row.timestamp;
|
|
78
|
+
if (personInput(row))
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
since ??= earliest;
|
|
82
|
+
return { turnsSinceLastReminder: turns, remindersInStretch: reminders, silentSince: since };
|
|
83
|
+
}
|
|
84
|
+
export function silentTurnReminderDue(stretch, arm, now) {
|
|
85
|
+
if (arm === "turns")
|
|
86
|
+
return stretch.remindersInStretch < SILENT_TURN_REMINDER.MAX_PER_STRETCH && stretch.turnsSinceLastReminder >= SILENT_TURN_REMINDER.TURNS;
|
|
87
|
+
if (stretch.silentSince === undefined || stretch.turnsSinceLastReminder < 1)
|
|
88
|
+
return false;
|
|
89
|
+
return Math.floor((now - stretch.silentSince) / 1000) >= SILENT_TURN_REMINDER.SECONDS;
|
|
90
|
+
}
|
|
91
|
+
export async function boundaryReminderInputs(input) {
|
|
92
|
+
const { lane, elapsedClock, opening, carried, rows } = input;
|
|
93
|
+
let silentTurn;
|
|
94
|
+
if (lane.silentTurn !== "off" && !carried("silent_turn_reminder")) {
|
|
95
|
+
try {
|
|
96
|
+
silentTurn = { stretch: readSilentStretch(await rows(), opening.current), now: Date.now() };
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
silentTurn = undefined;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
const elapsedMs = lane.elapsedTime && !carried("elapsed_time_reminder") ? elapsedClock.elapsedMs() : undefined;
|
|
103
|
+
return { ...(silentTurn !== undefined ? { silentTurn } : {}), ...(elapsedMs !== undefined ? { elapsedMs } : {}) };
|
|
104
|
+
}
|
|
105
|
+
export function elapsedTimeSlots(ms) {
|
|
106
|
+
const total = Number.isFinite(ms) ? Math.max(0, Math.floor(ms / 1000)) : 0;
|
|
107
|
+
return { minutes: String(Math.floor(total / 60)), seconds: String(total % 60).padStart(2, "0") };
|
|
108
|
+
}
|
|
@@ -1,26 +1,34 @@
|
|
|
1
1
|
import type { SessionStorage } from "../session.js";
|
|
2
|
+
import type { WriteRefusal } from "./contracts.js";
|
|
3
|
+
import type { RewindOutcome } from "./rewind-outcome.js";
|
|
2
4
|
/** The entries this prepare appended through the watched storage — recorded once a branch is armed (`ids` set). */
|
|
3
5
|
export interface OwnAppends {
|
|
4
6
|
ids: Set<string> | undefined;
|
|
5
7
|
}
|
|
6
|
-
/** The branch a `resumeAt` acquire wrote: the watched storage, the leaf the request found, the leaf it set,
|
|
8
|
+
/** The branch a `resumeAt` acquire wrote: the watched storage, the leaf the request found, the leaf it set, the own appends since, and
|
|
9
|
+
* the leg's record of where the leaf stands ({@link RewindOutcome.branch}; absent on a branch no leg record follows), which the
|
|
10
|
+
* write-back states at each step it takes. */
|
|
7
11
|
export interface ResumeAtBranch {
|
|
8
12
|
storage: SessionStorage;
|
|
9
13
|
leafBefore: string | null;
|
|
10
14
|
leafSet: string | null;
|
|
11
15
|
own: OwnAppends;
|
|
16
|
+
outcome?: Pick<RewindOutcome, "branch">;
|
|
12
17
|
}
|
|
18
|
+
export type { WriteRefusal };
|
|
19
|
+
/** A fresh latch: nothing refused yet, no stop bound. */
|
|
20
|
+
export declare function writeRefusalLatch(): WriteRefusal;
|
|
21
|
+
/** Latch the word a refused write said, if it is one of the latch's two (anything else leaves it as it is). */
|
|
22
|
+
export declare function latchWriteRefusal(ref: WriteRefusal, err: unknown): void;
|
|
13
23
|
/**
|
|
14
|
-
* Wrap a storage so a
|
|
24
|
+
* Wrap a storage so a refused append/leaf write latches its word on `ref` ({@link WriteRefusal}), and every append
|
|
15
25
|
* that lands is recorded on `own` while a branch is armed. The harness flattens a mid-run storage failure into
|
|
16
26
|
* a generic error (and, since a lost CAS makes every subsequent append fail, even its failure-reporting append
|
|
17
|
-
* fails) — so the
|
|
18
|
-
* storage boundary, keeps it
|
|
27
|
+
* fails) — so the store's code is gone by the time the task result is assembled. Catching it here, at the
|
|
28
|
+
* storage boundary, keeps it as `TaskResult.errorCode` (`conflict` / `holder.superseded`). Per-task and non-mutating (a
|
|
19
29
|
* Proxy over the shared storage), so it never stacks across tasks on a cached session.
|
|
20
30
|
*/
|
|
21
|
-
export declare function detectConflicts(storage: SessionStorage, ref:
|
|
22
|
-
hit: boolean;
|
|
23
|
-
}, own: OwnAppends): SessionStorage;
|
|
31
|
+
export declare function detectConflicts(storage: SessionStorage, ref: WriteRefusal, own: OwnAppends): SessionStorage;
|
|
24
32
|
/**
|
|
25
33
|
* Put a refused prepare's `resumeAt` branch back: the leaf returns to `leafBefore` when it still sits on the
|
|
26
34
|
* branch leaf or on this prepare's own appends above it, and the write is conditional on the leaf just
|
|
@@ -28,6 +36,12 @@ export declare function detectConflicts(storage: SessionStorage, ref: {
|
|
|
28
36
|
* not this request's to take back or the write cannot land. `signal` aborted before the write starts ⇒ no
|
|
29
37
|
* write (the caller's bound expired and the view is being dropped); a storage write already in flight cannot
|
|
30
38
|
* be called back — the storage contract carries no cancellation.
|
|
39
|
+
*
|
|
40
|
+
* Where the leaf stands is stated on `branch.outcome` at each step, so a bound that expires mid-way leaves the last thing known: the
|
|
41
|
+
* leaf found where the request found it ⇒ `put_back` (`untouched` when the request had branched at that very leaf); another writer's
|
|
42
|
+
* entries past the request's ⇒ `left_moved`, as is a bound that expired before the write started; a conditional write the store
|
|
43
|
+
* refused as a conflict ⇒ the leaf read again (`put_back` where it is where the request found it, else `left_moved`); a read that
|
|
44
|
+
* threw, or a write started and not answered, ⇒ not known (`undefined`); the write landed ⇒ `put_back`.
|
|
31
45
|
*/
|
|
32
46
|
export declare function writeBranchBack(branch: ResumeAtBranch, sessionId: string, signal?: AbortSignal): Promise<void>;
|
|
33
47
|
/**
|
|
@@ -1,6 +1,25 @@
|
|
|
1
1
|
import { isSessionConflict } from "../session.js";
|
|
2
2
|
import { thrownText } from "../thrown-value.js";
|
|
3
|
+
import { isHolderSuperseded } from "../grant-holder.js";
|
|
3
4
|
import { settleTeardownLeg } from "./teardown-bounded.js";
|
|
5
|
+
export function writeRefusalLatch() {
|
|
6
|
+
return { word: undefined };
|
|
7
|
+
}
|
|
8
|
+
export function latchWriteRefusal(ref, err) {
|
|
9
|
+
if (isHolderSuperseded(err)) {
|
|
10
|
+
if (ref.word === "holder.superseded")
|
|
11
|
+
return;
|
|
12
|
+
ref.word = "holder.superseded";
|
|
13
|
+
try {
|
|
14
|
+
ref.stop?.();
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
else if (isSessionConflict(err) && ref.word === undefined) {
|
|
20
|
+
ref.word = "conflict";
|
|
21
|
+
}
|
|
22
|
+
}
|
|
4
23
|
export function detectConflicts(storage, ref, own) {
|
|
5
24
|
const guard = (fn, landed) => async (...args) => {
|
|
6
25
|
try {
|
|
@@ -9,9 +28,7 @@ export function detectConflicts(storage, ref, own) {
|
|
|
9
28
|
return out;
|
|
10
29
|
}
|
|
11
30
|
catch (err) {
|
|
12
|
-
|
|
13
|
-
ref.hit = true;
|
|
14
|
-
}
|
|
31
|
+
latchWriteRefusal(ref, err);
|
|
15
32
|
throw err;
|
|
16
33
|
}
|
|
17
34
|
};
|
|
@@ -31,22 +48,43 @@ export function detectConflicts(storage, ref, own) {
|
|
|
31
48
|
});
|
|
32
49
|
}
|
|
33
50
|
export async function writeBranchBack(branch, sessionId, signal) {
|
|
51
|
+
const state = (word) => {
|
|
52
|
+
if (branch.outcome !== undefined)
|
|
53
|
+
branch.outcome.branch = word;
|
|
54
|
+
};
|
|
34
55
|
let now;
|
|
56
|
+
let moved = false;
|
|
35
57
|
try {
|
|
36
58
|
now = await branch.storage.getLeafId();
|
|
37
59
|
if (now === branch.leafBefore)
|
|
38
|
-
return;
|
|
60
|
+
return state(branch.leafSet === branch.leafBefore ? "untouched" : "put_back");
|
|
39
61
|
const ids = branch.own.ids ?? new Set();
|
|
40
62
|
for (let at = now, steps = 0; at !== branch.leafSet; steps++) {
|
|
41
|
-
if (at === null || steps > ids.size || !ids.has(at))
|
|
63
|
+
if (at === null || steps > ids.size || !ids.has(at)) {
|
|
64
|
+
moved = true;
|
|
42
65
|
throw new Error("another writer moved the leaf past the entries this request wrote");
|
|
66
|
+
}
|
|
43
67
|
at = (await branch.storage.getEntry(at))?.parentId ?? null;
|
|
44
68
|
}
|
|
45
69
|
if (signal?.aborted === true)
|
|
46
|
-
return;
|
|
70
|
+
return state("left_moved");
|
|
71
|
+
state(undefined);
|
|
47
72
|
await branch.storage.setLeafId(branch.leafBefore, { expectedLeafId: now });
|
|
73
|
+
state("put_back");
|
|
48
74
|
}
|
|
49
75
|
catch (err) {
|
|
76
|
+
if (moved)
|
|
77
|
+
state("left_moved");
|
|
78
|
+
else if (isSessionConflict(err)) {
|
|
79
|
+
try {
|
|
80
|
+
state((await branch.storage.getLeafId()) === branch.leafBefore ? "put_back" : "left_moved");
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
state(undefined);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
else
|
|
87
|
+
state(undefined);
|
|
50
88
|
const shown = (id) => (id === undefined ? "(unreadable)" : id === null ? "(empty)" : `"${id}"`);
|
|
51
89
|
throw new Error(`resumeAt: prepare refused this request but could not put session "${sessionId}" back — its leaf stays at ${shown(now)} (the request found it at ${shown(branch.leafBefore)}), so the next turn continues from there: ${thrownText(err)}`);
|
|
52
90
|
}
|
|
@@ -5,6 +5,7 @@ import { conversationSegmentOf, restateToldSeat } from "./conversation-segment.j
|
|
|
5
5
|
const LIST_SHOWN = 50;
|
|
6
6
|
const listed = (entries) => (entries.length > LIST_SHOWN ? [...entries.slice(0, LIST_SHOWN), `(${entries.length - LIST_SHOWN} more)`] : [...entries]);
|
|
7
7
|
const home = (p, at) => (p.startsWith("~/") && at !== undefined && at.startsWith("/") ? `${at.replace(/\/+$/, "")}/${p.slice(2)}` : p);
|
|
8
|
+
const NETWORK_LINE = "Attempt requests and read the error rather than predicting whether a host is reachable; denied connections are reported in a `<sandbox_violations>` block explaining the reason; a file the sandbox denies is reported the same way.";
|
|
8
9
|
const ESCAPE_RULES = `You should always default to running commands within the sandbox. Do NOT attempt to set \`dangerouslyDisableSandbox: true\` unless:
|
|
9
10
|
- The user *explicitly* asks you to bypass sandbox
|
|
10
11
|
- A specific command just failed and you see evidence of sandbox restrictions causing the failure. Note that commands can fail for many reasons unrelated to the sandbox (missing files, wrong arguments, network issues, etc.).
|
|
@@ -38,7 +39,7 @@ By default, Bash tool commands run in a sandbox. This sandbox controls which dir
|
|
|
38
39
|
The sandbox has the following restrictions:
|
|
39
40
|
Filesystem: ${JSON.stringify(filesystem)}
|
|
40
41
|
Network: ${JSON.stringify(network)}${ignored}
|
|
41
|
-
|
|
42
|
+
${NETWORK_LINE}
|
|
42
43
|
|
|
43
44
|
${r.allowUnsandboxedCommands === false ? ESCAPE_DISABLED : ESCAPE_RULES}`;
|
|
44
45
|
}
|