@sema-agent/core 7.57.0 → 7.59.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 +1161 -0
- package/README.md +6 -4
- package/dist/agents/cc-peer-directory.js +8 -8
- package/dist/agents/child-model-seat.d.ts +4 -2
- package/dist/agents/child-model-seat.js +5 -3
- package/dist/agents/peer-directory.d.ts +9 -0
- package/dist/agents/peer-directory.js +6 -2
- package/dist/agents/send-message-tool.js +21 -12
- package/dist/agents/subagent-steps.js +2 -4
- package/dist/agents/subagent.js +33 -34
- package/dist/brain/anthropic.js +161 -45
- package/dist/brain/errors.d.ts +9 -3
- package/dist/brain/errors.js +7 -1
- package/dist/brain/failover.js +2 -1
- package/dist/brain/open-responses.js +3 -3
- package/dist/brain/openai.js +103 -53
- package/dist/brain/provider-dialect.d.ts +11 -0
- package/dist/brain/provider-dialect.js +5 -2
- package/dist/brain/reasoning-request.js +5 -4
- package/dist/brain/reasoning.d.ts +19 -0
- package/dist/brain/reasoning.js +17 -2
- package/dist/brain/request-route.d.ts +4 -1
- package/dist/brain/request-route.js +4 -1
- package/dist/brain/route-adjudicator.d.ts +84 -18
- package/dist/brain/route-adjudicator.js +89 -22
- package/dist/brain/route-conformance.js +1 -1
- package/dist/brain/stream-engine.js +84 -49
- package/dist/brain/stream-shared.d.ts +30 -0
- package/dist/brain/stream-shared.js +34 -1
- package/dist/brain/timeout.d.ts +62 -5
- package/dist/brain/timeout.js +93 -6
- package/dist/core/a2a.d.ts +2 -1
- package/dist/core/a2a.js +23 -10
- package/dist/core/account-row.d.ts +61 -0
- package/dist/core/account-row.js +51 -0
- package/dist/core/advisor-verdict.d.ts +2 -1
- package/dist/core/advisor-verdict.js +1 -1
- package/dist/core/allow-entry.d.ts +20 -7
- package/dist/core/allow-entry.js +18 -9
- package/dist/core/approval-object.d.ts +29 -15
- package/dist/core/approval-object.js +47 -19
- package/dist/core/ask-origin.d.ts +21 -2
- package/dist/core/ask-origin.js +5 -1
- package/dist/core/auto-compaction.d.ts +4 -0
- package/dist/core/auto-compaction.js +2 -2
- package/dist/core/auto-mode-directive.d.ts +29 -5
- package/dist/core/auto-mode-directive.js +38 -8
- package/dist/core/background-agent-store.d.ts +16 -3
- package/dist/core/checkpoint-requirements.d.ts +19 -1
- package/dist/core/checkpoint-requirements.js +5 -1
- package/dist/core/checkpoint-store.d.ts +85 -23
- package/dist/core/checkpoint-store.js +31 -9
- package/dist/core/child-clamp-seats.d.ts +29 -0
- package/dist/core/child-clamp-seats.js +56 -1
- package/dist/core/compliance.d.ts +2 -2
- package/dist/core/compliance.js +1 -1
- package/dist/core/effective-path-target.d.ts +8 -2
- package/dist/core/effective-path-target.js +8 -3
- package/dist/core/engine-notice.d.ts +99 -9
- package/dist/core/engine-notice.js +19 -5
- package/dist/core/fs-write-gate-policy.d.ts +4 -2
- package/dist/core/fs-write-gate-policy.js +7 -3
- package/dist/core/gate-fold.js +7 -4
- package/dist/core/gate-lanes.js +19 -6
- package/dist/core/gate-outcome.d.ts +32 -3
- package/dist/core/gate-outcome.js +19 -1
- package/dist/core/git-worktree-env.d.ts +53 -11
- package/dist/core/git-worktree-env.js +96 -12
- package/dist/core/governance-codes.d.ts +9 -1
- package/dist/core/governance-codes.js +13 -0
- package/dist/core/hooks.d.ts +35 -4
- package/dist/core/hooks.js +17 -11
- package/dist/core/human-input-projection.d.ts +1 -0
- package/dist/core/human-input-projection.js +3 -0
- package/dist/core/image-admission.d.ts +6 -5
- package/dist/core/image-admission.js +18 -14
- package/dist/core/locked-config.d.ts +20 -3
- package/dist/core/locked-config.js +40 -3
- package/dist/core/mailbox-store.d.ts +45 -1
- package/dist/core/mailbox-store.js +53 -9
- package/dist/core/mcp-call-meta.d.ts +66 -0
- package/dist/core/mcp-call-meta.js +103 -0
- package/dist/core/mcp-connection-pool.d.ts +3 -1
- package/dist/core/mcp-connection-pool.js +3 -1
- package/dist/core/mcp-failure.d.ts +117 -15
- package/dist/core/mcp-failure.js +71 -3
- package/dist/core/mcp-probe.d.ts +4 -0
- package/dist/core/mcp-probe.js +1 -1
- package/dist/core/mcp-server-link.d.ts +27 -3
- package/dist/core/mcp-server-link.js +25 -1
- package/dist/core/mcp-server-spec.d.ts +46 -18
- package/dist/core/mcp-server-spec.js +1 -18
- package/dist/core/mcp.d.ts +16 -20
- package/dist/core/mcp.js +112 -55
- package/dist/core/memory-engine/consolidation-driver.d.ts +2 -4
- package/dist/core/memory-engine/consolidation-driver.js +3 -3
- package/dist/core/memory-engine/consolidation.d.ts +4 -0
- package/dist/core/memory-engine/consolidation.js +1 -0
- package/dist/core/memory-engine/delegation-settlement.js +5 -12
- package/dist/core/memory-engine/distiller.js +2 -2
- package/dist/core/memory-engine/dual-root.d.ts +50 -1
- package/dist/core/memory-engine/dual-root.js +44 -1
- package/dist/core/memory-engine/engine.d.ts +67 -14
- package/dist/core/memory-engine/engine.js +384 -212
- package/dist/core/memory-engine/export-bundle.d.ts +23 -0
- package/dist/core/memory-engine/export-bundle.js +23 -4
- package/dist/core/memory-engine/file-backend.d.ts +128 -55
- package/dist/core/memory-engine/file-backend.js +290 -117
- package/dist/core/memory-engine/index.d.ts +1 -1
- package/dist/core/memory-engine/layout.d.ts +59 -11
- package/dist/core/memory-engine/layout.js +190 -40
- package/dist/core/memory-engine/memory-backend-contract.d.ts +1 -1
- package/dist/core/memory-engine/memory-backend-contract.js +39 -2
- package/dist/core/memory-engine/scope-contract.d.ts +45 -4
- package/dist/core/memory-engine/scope-contract.js +80 -11
- package/dist/core/memory-engine/sync-client.d.ts +9 -1
- package/dist/core/memory-engine/sync-client.js +31 -8
- package/dist/core/memory-engine/sync.d.ts +5 -0
- package/dist/core/memory-engine/types.d.ts +6 -0
- package/dist/core/mode-policy.d.ts +8 -5
- package/dist/core/mode-policy.js +5 -4
- package/dist/core/mods/classic-events.d.ts +5 -1
- package/dist/core/mods/host.js +1 -1
- package/dist/core/mods/kernel/dispatch.d.ts +3 -0
- package/dist/core/mods/kernel/dispatch.js +12 -9
- package/dist/core/mods/kernel/events.d.ts +6 -1
- package/dist/core/mods/kernel/events.js +2 -2
- package/dist/core/mods/kernel/registration.d.ts +9 -1
- package/dist/core/mods/kernel/registration.js +3 -0
- package/dist/core/mods/kernel/site-rules.d.ts +3 -0
- package/dist/core/mods/kernel/site-rules.js +10 -0
- package/dist/core/mods/package.d.ts +23 -0
- package/dist/core/mods/package.js +118 -0
- package/dist/core/mods/stations.d.ts +33 -12
- package/dist/core/mods/stations.js +45 -11
- package/dist/core/mods/tool-call.d.ts +5 -1
- package/dist/core/mods/tool-call.js +13 -4
- package/dist/core/parent-spec-seat.d.ts +8 -3
- package/dist/core/parent-spec-seat.js +2 -0
- package/dist/core/park-selfcheck.js +6 -0
- package/dist/core/path-guard-rows.d.ts +20 -0
- package/dist/core/path-guard-rows.js +11 -0
- package/dist/core/peer-seat.d.ts +248 -0
- package/dist/core/peer-seat.js +439 -0
- package/dist/core/permission-rule-consent.js +10 -4
- package/dist/core/permission-rule-model.d.ts +16 -0
- package/dist/core/permission-rule-model.js +1 -1
- package/dist/core/present-plan-tool.d.ts +20 -3
- package/dist/core/present-plan-tool.js +48 -4
- package/dist/core/protocol-http-auth.d.ts +40 -29
- package/dist/core/protocol-http-auth.js +30 -32
- package/dist/core/redaction-marks.d.ts +16 -0
- package/dist/core/redaction-marks.js +16 -0
- package/dist/core/redaction-passes.js +8 -9
- package/dist/core/resume-startup-cause.js +1 -0
- package/dist/core/retention.d.ts +41 -15
- package/dist/core/retention.js +59 -12
- package/dist/core/rewrite-rejudge.d.ts +38 -0
- package/dist/core/rewrite-rejudge.js +42 -2
- package/dist/core/roles.d.ts +34 -2
- package/dist/core/roles.js +43 -4
- package/dist/core/run-origin.d.ts +40 -0
- package/dist/core/run-origin.js +37 -0
- package/dist/core/runner/advertised-writable-dirs.d.ts +57 -38
- package/dist/core/runner/advertised-writable-dirs.js +126 -0
- package/dist/core/runner/announce-once-ledger.d.ts +5 -4
- package/dist/core/runner/announce-once-ledger.js +4 -2
- package/dist/core/runner/call-hook-stations.js +2 -2
- package/dist/core/runner/compaction-restate.d.ts +15 -6
- package/dist/core/runner/compaction-restate.js +28 -2
- package/dist/core/runner/contracts.d.ts +33 -21
- package/dist/core/runner/credential-origin-seat.js +4 -3
- package/dist/core/runner/cwd-alignment-probe.d.ts +20 -0
- package/dist/core/runner/cwd-alignment-probe.js +21 -0
- package/dist/core/runner/decide-continuation.d.ts +2 -2
- package/dist/core/runner/gate-exit.d.ts +30 -8
- package/dist/core/runner/gate-exit.js +15 -8
- package/dist/core/runner/image-removed-seat.d.ts +12 -0
- package/dist/core/runner/image-removed-seat.js +19 -0
- package/dist/core/runner/inline-image.js +1 -1
- package/dist/core/runner/memory-consolidation-driver.js +3 -3
- package/dist/core/runner/park-commit.d.ts +1 -1
- package/dist/core/runner/park-commit.js +3 -0
- package/dist/core/runner/prepare-ask-lane.d.ts +1 -1
- package/dist/core/runner/prepare-ask-lane.js +2 -1
- package/dist/core/runner/prepare-boundary-parks.js +2 -2
- package/dist/core/runner/prepare-caps-and-workflow.d.ts +5 -5
- package/dist/core/runner/prepare-caps-and-workflow.js +3 -1
- package/dist/core/runner/prepare-config-doors.d.ts +8 -5
- package/dist/core/runner/prepare-config-doors.js +14 -10
- package/dist/core/runner/prepare-context-lane.js +2 -0
- package/dist/core/runner/prepare-delegation-surface.d.ts +8 -0
- package/dist/core/runner/prepare-delegation-surface.js +16 -18
- package/dist/core/runner/prepare-gate-stations.js +1 -1
- package/dist/core/runner/prepare-hands-readface.d.ts +11 -3
- package/dist/core/runner/prepare-hands-readface.js +9 -1
- package/dist/core/runner/prepare-inherited-gate.d.ts +1 -3
- package/dist/core/runner/prepare-inherited-gate.js +14 -27
- package/dist/core/runner/prepare-memory.d.ts +3 -0
- package/dist/core/runner/prepare-memory.js +26 -37
- package/dist/core/runner/prepare-park-ask.d.ts +1 -1
- package/dist/core/runner/prepare-park-ask.js +2 -1
- package/dist/core/runner/prepare-policy-chain.d.ts +7 -7
- package/dist/core/runner/prepare-policy-chain.js +18 -15
- package/dist/core/runner/prepare-project-context.d.ts +2 -2
- package/dist/core/runner/prepare-project-context.js +2 -2
- package/dist/core/runner/prepare-prompt-inputs.d.ts +1 -1
- package/dist/core/runner/prepare-prompt-inputs.js +8 -19
- package/dist/core/runner/prepare-protocol-tools.d.ts +4 -2
- package/dist/core/runner/prepare-protocol-tools.js +11 -3
- package/dist/core/runner/prepare-run-refs.d.ts +2 -3
- package/dist/core/runner/prepare-run-refs.js +4 -1
- package/dist/core/runner/prepare-suspend-saga.d.ts +2 -0
- package/dist/core/runner/prepare-suspend-saga.js +2 -1
- package/dist/core/runner/prepare-task.js +28 -13
- package/dist/core/runner/prepare-wiring-manifest.d.ts +2 -1
- package/dist/core/runner/prepare-wiring-manifest.js +4 -3
- package/dist/core/runner/prepare-workspace-restore.d.ts +3 -0
- package/dist/core/runner/prepare-workspace-restore.js +4 -4
- package/dist/core/runner/reply-pricing.d.ts +30 -0
- package/dist/core/runner/reply-pricing.js +19 -0
- package/dist/core/runner/resume-admission.js +5 -3
- package/dist/core/runner/resume-apply.js +6 -1
- package/dist/core/runner/resume-checkpoint-screen.js +2 -0
- package/dist/core/runner/resume-policy-outcome.js +5 -5
- package/dist/core/runner/role-seat-defaulted.d.ts +44 -0
- package/dist/core/runner/role-seat-defaulted.js +40 -0
- package/dist/core/runner/run-brain-sinks.js +2 -0
- package/dist/core/runner/run-harness-handlers.d.ts +3 -4
- package/dist/core/runner/run-harness-handlers.js +1 -8
- package/dist/core/runner/run-identity-wiring.d.ts +2 -5
- package/dist/core/runner/run-identity-wiring.js +6 -4
- package/dist/core/runner/run-leg.d.ts +2 -0
- package/dist/core/runner/run-leg.js +42 -29
- package/dist/core/runner/run-notification-lane.js +3 -0
- package/dist/core/runner/run-stop-and-final-verify.js +2 -2
- package/dist/core/runner/run-terminal-adoption.d.ts +2 -5
- package/dist/core/runner/run-terminal-adoption.js +9 -3
- package/dist/core/runner/run-turn-boundary.js +77 -70
- package/dist/core/runner/runtask.d.ts +1 -1
- package/dist/core/runner/runtask.js +2 -2
- package/dist/core/runner/side-call-account.d.ts +1 -1
- package/dist/core/runner/side-call-account.js +3 -18
- package/dist/core/runner/sub-agent-deny-lists.d.ts +24 -0
- package/dist/core/runner/sub-agent-deny-lists.js +10 -0
- package/dist/core/runner/terminal-account.js +3 -3
- package/dist/core/runner/tool-end-body.js +2 -1
- package/dist/core/runner/tool-occurrence.d.ts +5 -2
- package/dist/core/runner/tool-occurrence.js +4 -3
- package/dist/core/runner/turn-attachments.d.ts +26 -22
- package/dist/core/runner/turn-attachments.js +24 -26
- package/dist/core/runner/write-protection-station.d.ts +8 -2
- package/dist/core/runner/write-protection-station.js +2 -0
- package/dist/core/runner-deps.d.ts +3 -3
- package/dist/core/secret-env.d.ts +32 -2
- package/dist/core/secret-env.js +65 -3
- package/dist/core/sensitive-path-policy.js +9 -10
- package/dist/core/session-log-transfer.d.ts +24 -0
- package/dist/core/session-log-transfer.js +166 -0
- package/dist/core/session-policy-store.d.ts +3 -1
- package/dist/core/session-policy-store.js +13 -9
- package/dist/core/session-store.d.ts +86 -24
- package/dist/core/session-store.js +162 -24
- package/dist/core/session.d.ts +92 -1
- package/dist/core/shell-read-silence.js +1 -0
- package/dist/core/side-query.d.ts +11 -1
- package/dist/core/side-query.js +9 -0
- package/dist/core/skill-grant-binding.d.ts +31 -2
- package/dist/core/skill-grant-binding.js +31 -1
- package/dist/core/skill-grant.d.ts +8 -5
- package/dist/core/skill-grant.js +6 -6
- package/dist/core/steer-replay.d.ts +4 -2
- package/dist/core/steer-replay.js +2 -1
- package/dist/core/store-contracts/background-agent-store-contract.js +27 -0
- package/dist/core/store-contracts/checkpoint-store-contract.js +20 -2
- package/dist/core/store-contracts/mailbox-store-contract.js +31 -1
- package/dist/core/store-contracts/session-repo-contract.js +112 -5
- package/dist/core/store-contracts/session-store-contract.d.ts +4 -1
- package/dist/core/store-contracts/session-store-contract.js +236 -2
- package/dist/core/synthetic-read-verdict.js +2 -1
- package/dist/core/task-event.d.ts +92 -8
- package/dist/core/task-notification.js +16 -10
- package/dist/core/task-registry-agent.js +1 -0
- package/dist/core/task-registry-shared.d.ts +7 -1
- package/dist/core/task-spec.d.ts +49 -1
- package/dist/core/task-stream.d.ts +2 -1
- package/dist/core/terminal-cause.d.ts +11 -1
- package/dist/core/tool-catalog-entries.js +1 -0
- package/dist/core/tool-check-reading.d.ts +1 -0
- package/dist/core/tool-check-reading.js +3 -3
- package/dist/core/tool-policy.d.ts +16 -0
- package/dist/core/tool-result-store.d.ts +17 -10
- package/dist/core/tool-result-store.js +3 -1
- package/dist/core/tool-roster.d.ts +112 -5
- package/dist/core/tool-roster.js +42 -1
- package/dist/core/tool-spec.d.ts +3 -1
- package/dist/core/types.d.ts +3 -3
- package/dist/core/types.js +1 -1
- package/dist/core/untrusted-egress.d.ts +0 -2
- package/dist/core/untrusted-egress.js +10 -14
- package/dist/core/user-attachment.js +1 -1
- package/dist/core/wiring-manifest.d.ts +18 -6
- package/dist/core/wiring-manifest.js +4 -3
- package/dist/core/workspace-snapshot.d.ts +44 -0
- package/dist/core/workspace-snapshot.js +34 -0
- package/dist/core/write-protect.d.ts +43 -3
- package/dist/core/write-protect.js +43 -16
- package/dist/engine/compaction/compaction.js +29 -3
- package/dist/engine/execution-env/node-execution-env.d.ts +4 -3
- package/dist/engine/execution-env/node-execution-env.js +24 -23
- package/dist/engine/execution-env/symlink-chain.d.ts +7 -5
- package/dist/engine/harness/agent-harness.d.ts +30 -2
- package/dist/engine/harness/agent-harness.js +43 -12
- package/dist/engine/harness/messages.d.ts +3 -1
- package/dist/engine/harness/messages.js +3 -2
- package/dist/engine/harness/types.d.ts +56 -7
- package/dist/engine/harness/types.js +5 -1
- package/dist/engine/llm/rejected-images.d.ts +46 -0
- package/dist/engine/llm/rejected-images.js +54 -0
- package/dist/engine/llm/tool-turns.d.ts +2 -1
- package/dist/engine/llm/types.d.ts +30 -10
- package/dist/engine/llm/types.js +1 -1
- package/dist/engine/loop/agent-loop.d.ts +8 -0
- package/dist/engine/loop/agent-loop.js +52 -15
- package/dist/engine/loop/types.d.ts +3 -1
- package/dist/engine/session/import-validate.js +3 -0
- package/dist/engine/session/memory-repo.d.ts +17 -9
- package/dist/engine/session/memory-repo.js +44 -34
- package/dist/engine/session/path-to-root.d.ts +38 -0
- package/dist/engine/session/path-to-root.js +39 -0
- package/dist/engine/session/repo-utils.d.ts +22 -4
- package/dist/engine/session/repo-utils.js +49 -1
- package/dist/engine/session/storage-base.d.ts +10 -1
- package/dist/engine/session/storage-base.js +11 -22
- package/dist/index.d.ts +29 -16
- package/dist/index.js +21 -11
- package/dist/internal/harness-types.d.ts +2 -2
- package/dist/internal/harness.d.ts +3 -2
- package/dist/internal/harness.js +2 -2
- package/dist/internal/llm.d.ts +1 -0
- package/dist/orchestration/workflow-observe.d.ts +17 -1
- package/dist/orchestration/workflow-observe.js +20 -0
- package/dist/orchestration/workflow-types.d.ts +32 -7
- package/dist/orchestration/workflow.js +739 -489
- package/dist/shell/counting-pass.d.ts +50 -0
- package/dist/shell/counting-pass.js +502 -0
- package/dist/shell/lex.d.ts +4 -2
- package/dist/shell/lex.js +93 -34
- package/dist/shell/shell-words.d.ts +1 -1
- package/dist/shell/shell-words.js +7 -6
- package/dist/stores/file/index.d.ts +4 -1
- package/dist/stores/file/index.js +4 -1
- package/dist/stores/file/mailbox-store.js +6 -10
- package/dist/stores/file/session-store.d.ts +15 -8
- package/dist/stores/file/session-store.js +28 -13
- package/dist/tools/fs/fs-bash.d.ts +6 -0
- package/dist/tools/fs/fs-bash.js +6 -3
- package/dist/tools/fs/fs-write.d.ts +6 -3
- package/dist/tools/fs/fs-write.js +8 -7
- package/dist/tools/fs/index.d.ts +3 -0
- package/dist/tools/fs/index.js +7 -3
- package/dist/tools/fs/program-read-model.d.ts +13 -0
- package/dist/tools/fs/program-read-model.js +15 -0
- package/dist/tools/fs/program-read-model.rows.js +1 -1
- package/dist/tools/fs/read-deny.d.ts +13 -10
- package/dist/tools/fs/read-deny.js +25 -5
- package/dist/tools/fs/read-floor.d.ts +19 -0
- package/dist/tools/fs/read-floor.js +23 -0
- package/dist/tools/fs/safety.js +40 -8
- package/dist/tools/fs/search.js +6 -24
- package/dist/tools/fs/shell-read-check.d.ts +9 -2
- package/dist/tools/fs/shell-read-check.js +61 -16
- package/dist/tools/fs/shell-read-establish.js +2 -1
- package/dist/tools/fs/shell-read-identity.js +1 -1
- package/dist/tools/fs/shell-read-judge.d.ts +26 -9
- package/dist/tools/fs/shell-read-judge.js +10 -6
- package/dist/tools/fs/shell-read-plan.d.ts +6 -1
- package/dist/tools/fs/shell-read-plan.js +22 -15
- package/dist/tools/fs/shell-read-start.js +1 -0
- package/dist/tools/fs/shell-reentry-text.d.ts +15 -1
- package/dist/tools/fs/shell-reentry-text.js +25 -3
- package/dist/tools/monitor.d.ts +4 -0
- package/dist/tools/monitor.js +2 -0
- package/dist/tools/worktree.d.ts +42 -15
- package/dist/tools/worktree.js +60 -32
- package/package.json +5 -2
- package/test/export-surface.snapshot.json +149 -1
- package/wire-changes/core-stores-sql@7.58.0.json +29 -0
- package/wire-changes/core-stores-sql@7.59.0.json +29 -0
- package/wire-changes/core@7.58.0.json +2188 -0
- package/wire-changes/core@7.59.0.json +2459 -0
- package/wire-changes/mods-kernel@7.58.0.json +81 -0
- package/wire-changes/mods-kernel@7.59.0.json +29 -0
- package/wire-changes/primitives@7.58.0.json +29 -0
- package/wire-changes/primitives@7.59.0.json +29 -0
- package/dist/primitives/credential-ref.d.ts +0 -89
- package/dist/primitives/credential-ref.js +0 -125
- package/dist/primitives/index.d.ts +0 -2
- package/dist/primitives/index.js +0 -1
package/dist/shell/lex.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { shellWordsOf } from "./shell-words.js";
|
|
2
|
+
import { arithmeticCommandEnd, bracePassEnd, countingPassEnd, holdsHashFrom, passesFor, whileReading } from "./counting-pass.js";
|
|
2
3
|
export const SHELL_LEX_DIALECT = "bash";
|
|
3
4
|
export const QUOTE_KINDS = Object.freeze(["'", '"', "$'", '$"', "\\"]);
|
|
4
5
|
export const EXPANSION_KINDS = Object.freeze(["parameter", "command", "process", "arithmetic", "tilde", "brace", "glob"]);
|
|
@@ -23,6 +24,7 @@ export const PARSE_FAILURE_REASONS = Object.freeze([
|
|
|
23
24
|
"unterminated_arithmetic_expansion",
|
|
24
25
|
"unterminated_heredoc",
|
|
25
26
|
"undelimited_substitution",
|
|
27
|
+
"undelimited_substitution_heredoc",
|
|
26
28
|
"redirect_without_target",
|
|
27
29
|
"heredoc_without_delimiter",
|
|
28
30
|
"heredoc_delimiter_expands",
|
|
@@ -39,6 +41,7 @@ export const PARSE_FAILURE_SENTENCE = {
|
|
|
39
41
|
unterminated_arithmetic_expansion: "an arithmetic expansion never terminates",
|
|
40
42
|
unterminated_heredoc: "a here-document body never terminates",
|
|
41
43
|
undelimited_substitution: "a command substitution carries a construct this lexer cannot delimit",
|
|
44
|
+
undelimited_substitution_heredoc: "a here-document in a command substitution that shell versions end at different places — feed the text as stdin (`git commit -F -`) or reword it",
|
|
42
45
|
redirect_without_target: "a redirection names no target",
|
|
43
46
|
heredoc_without_delimiter: "a here-document operator names no delimiter",
|
|
44
47
|
heredoc_delimiter_expands: "a here-document delimiter is not a plain word",
|
|
@@ -149,7 +152,19 @@ function heredocHeaderOf(word, dash) {
|
|
|
149
152
|
return undefined;
|
|
150
153
|
return { delimiter: word.folded, quoted: /["'\\]/.test(word.raw), dash };
|
|
151
154
|
}
|
|
152
|
-
function
|
|
155
|
+
function documentLine(text, p, joined) {
|
|
156
|
+
let nl = text.indexOf("\n", p);
|
|
157
|
+
let line = nl < 0 ? text.slice(p) : text.slice(p, nl);
|
|
158
|
+
if (joined) {
|
|
159
|
+
while (nl >= 0 && /(?<!\\)(?:\\\\)*\\$/.test(line)) {
|
|
160
|
+
const after = text.indexOf("\n", nl + 1);
|
|
161
|
+
line = line.slice(0, -1) + (after < 0 ? text.slice(nl + 1) : text.slice(nl + 1, after));
|
|
162
|
+
nl = after;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return { line, nl };
|
|
166
|
+
}
|
|
167
|
+
function heredocBodies(text, from, headers, closer) {
|
|
153
168
|
const bodies = [];
|
|
154
169
|
let p = from;
|
|
155
170
|
for (const h of headers) {
|
|
@@ -157,21 +172,15 @@ function heredocBodies(text, from, headers, inSubstitution) {
|
|
|
157
172
|
for (;;) {
|
|
158
173
|
if (p > text.length)
|
|
159
174
|
return "unterminated";
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
while (nl >= 0 && /(?<!\\)(?:\\\\)*\\$/.test(line)) {
|
|
164
|
-
const after = text.indexOf("\n", nl + 1);
|
|
165
|
-
line = line.slice(0, -1) + (after < 0 ? text.slice(nl + 1) : text.slice(nl + 1, after));
|
|
166
|
-
nl = after;
|
|
167
|
-
}
|
|
168
|
-
}
|
|
175
|
+
const { line, nl } = documentLine(text, p, !h.quoted);
|
|
176
|
+
if (closer !== undefined && text.slice(p, nl < 0 ? text.length : nl + 1).includes("\\\n"))
|
|
177
|
+
return "ambiguous";
|
|
169
178
|
const compared = h.dash ? line.replace(/^\t+/, "") : line;
|
|
170
179
|
if (compared === h.delimiter) {
|
|
171
180
|
p = nl < 0 ? text.length + 1 : nl + 1;
|
|
172
181
|
break;
|
|
173
182
|
}
|
|
174
|
-
if (
|
|
183
|
+
if (closer !== undefined && compared.startsWith(h.delimiter) && (closer === ")" ? compared.indexOf(")", h.delimiter.length) >= 0 : /^[ \t]*\}/.test(compared.slice(h.delimiter.length))))
|
|
175
184
|
return "ambiguous";
|
|
176
185
|
if (nl < 0)
|
|
177
186
|
return "unterminated";
|
|
@@ -231,7 +240,10 @@ function heredocHeaderAt(text, from, dash, op) {
|
|
|
231
240
|
return header === undefined ? fail("heredoc_delimiter_expands", start) : { ...header, end: j };
|
|
232
241
|
}
|
|
233
242
|
const BASH_READING = { heredoc: true, startComment: true };
|
|
234
|
-
const
|
|
243
|
+
const BASH32_PARSE = { heredoc: false, startComment: true };
|
|
244
|
+
const BASH32_EXPAND = { heredoc: false, startComment: false };
|
|
245
|
+
const NO_COMMENT_COUNT = { heredoc: false, startComment: false, noComments: true };
|
|
246
|
+
const BASH32_DOUBLE_QUOTED = { ...NO_COMMENT_COUNT };
|
|
235
247
|
const ARITHMETIC_READING = { heredoc: false, startComment: true, arithmetic: true };
|
|
236
248
|
const BODY_NESTING_MAX = 64;
|
|
237
249
|
function walkBody(text, open, reading, inDouble, level) {
|
|
@@ -308,10 +320,12 @@ function walkBody(text, open, reading, inDouble, level) {
|
|
|
308
320
|
word = "";
|
|
309
321
|
continue;
|
|
310
322
|
}
|
|
311
|
-
if (c === "#" && wordStart) {
|
|
323
|
+
if (c === "#" && wordStart && reading.noComments !== true) {
|
|
312
324
|
const nl = text.indexOf("\n", j);
|
|
313
325
|
if (nl < 0)
|
|
314
326
|
return "unterminated";
|
|
327
|
+
if (text[nl - 1] === "\\")
|
|
328
|
+
return "undelimited";
|
|
315
329
|
j = nl - 1;
|
|
316
330
|
word = "";
|
|
317
331
|
continue;
|
|
@@ -351,6 +365,8 @@ function walkBody(text, open, reading, inDouble, level) {
|
|
|
351
365
|
}
|
|
352
366
|
const dash = text[third] === "-";
|
|
353
367
|
const header = heredocHeaderAt(text, dash ? third + 1 : third, dash, j);
|
|
368
|
+
if (header === "undelimited")
|
|
369
|
+
return fail("undelimited_substitution_heredoc", j);
|
|
354
370
|
if (typeof header !== "object" || !("delimiter" in header))
|
|
355
371
|
return header;
|
|
356
372
|
owed.push(header);
|
|
@@ -390,17 +406,26 @@ function walkBody(text, open, reading, inDouble, level) {
|
|
|
390
406
|
continue;
|
|
391
407
|
}
|
|
392
408
|
if (c === "\n" && owed.length > 0) {
|
|
393
|
-
const read = heredocBodies(text, j + 1, owed,
|
|
409
|
+
const read = heredocBodies(text, j + 1, owed, ")");
|
|
394
410
|
if (read === "unterminated")
|
|
395
411
|
return fail("unterminated_heredoc", j + 1);
|
|
396
412
|
if (read === "ambiguous")
|
|
397
|
-
return "
|
|
413
|
+
return fail("undelimited_substitution_heredoc", j + 1);
|
|
398
414
|
owed.length = 0;
|
|
399
415
|
j = read.resume - 1;
|
|
400
416
|
wordStart = true;
|
|
401
417
|
word = "";
|
|
402
418
|
continue;
|
|
403
419
|
}
|
|
420
|
+
if (reading.heredoc && j > open && c === "(" && text[k] === "(") {
|
|
421
|
+
const end = arithmeticCommandEnd(text, k);
|
|
422
|
+
if (end !== undefined) {
|
|
423
|
+
j = end - 1;
|
|
424
|
+
wordStart = false;
|
|
425
|
+
word = "";
|
|
426
|
+
continue;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
404
429
|
if (c === "(")
|
|
405
430
|
depth++;
|
|
406
431
|
else if (c === ")") {
|
|
@@ -408,7 +433,7 @@ function walkBody(text, open, reading, inDouble, level) {
|
|
|
408
433
|
if (depth === 1)
|
|
409
434
|
innerClose ??= j;
|
|
410
435
|
if (depth === 0)
|
|
411
|
-
return owed.length > 0 ? "
|
|
436
|
+
return owed.length > 0 ? fail("undelimited_substitution_heredoc", j) : { end: j + 1, heredoc, ...(innerClose !== undefined ? { innerClose } : {}) };
|
|
412
437
|
}
|
|
413
438
|
if (!reading.heredoc) {
|
|
414
439
|
wordStart = j === open ? reading.startComment && !inDouble && level === 0 : c === " " || c === "\t" || c === "\n";
|
|
@@ -422,21 +447,40 @@ function walkBody(text, open, reading, inDouble, level) {
|
|
|
422
447
|
}
|
|
423
448
|
return "unterminated";
|
|
424
449
|
}
|
|
425
|
-
function
|
|
450
|
+
function doubleQuotedWordHolds(text, from, to) {
|
|
451
|
+
let inDq = true;
|
|
452
|
+
for (let j = from; j < to; j++) {
|
|
453
|
+
const c = text[j];
|
|
454
|
+
if (c === "\"")
|
|
455
|
+
inDq = !inDq;
|
|
456
|
+
else if (inDq ? c === "`" || (c === "$" && "({[".includes(text[j + 1] ?? "")) : " \t\n;&|<>()'`$\\".includes(c))
|
|
457
|
+
return false;
|
|
458
|
+
else if (inDq && c === "\\")
|
|
459
|
+
j++;
|
|
460
|
+
}
|
|
461
|
+
return inDq;
|
|
462
|
+
}
|
|
463
|
+
function substitutionBodyEnd(text, open, inDouble, level, form = "command") {
|
|
426
464
|
const arithmetic = arithmeticWalk(text, open, inDouble, level);
|
|
427
|
-
|
|
428
|
-
return { end: arithmetic.end, arithmetic: true };
|
|
429
|
-
const read = walkBody(text, open, BASH_READING, inDouble, level);
|
|
465
|
+
const read = arithmetic ?? walkBody(text, open, BASH_READING, inDouble, level);
|
|
430
466
|
if (typeof read !== "object" || !("end" in read))
|
|
431
467
|
return read;
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
468
|
+
const refused = fail(read.heredoc ? "undelimited_substitution_heredoc" : "undelimited_substitution", open);
|
|
469
|
+
const doubled = text[past(text, open + 1)] === "(";
|
|
470
|
+
if (form !== "document")
|
|
471
|
+
for (const pass of passesFor(text, open)) {
|
|
472
|
+
const end = countingPassEnd(text, open, pass);
|
|
473
|
+
if (end !== read.end && end !== "unterminated")
|
|
474
|
+
return refused;
|
|
475
|
+
}
|
|
476
|
+
const counts = [...(form === "document" ? [] : [inDouble ? BASH32_DOUBLE_QUOTED : BASH32_PARSE]), BASH32_EXPAND, ...(doubled || form === "process" ? [NO_COMMENT_COUNT] : [])];
|
|
477
|
+
for (const reading of holdsHashFrom(text, open) ? counts : counts.slice(-1)) {
|
|
435
478
|
const counted = walkBody(text, open, reading, inDouble, level);
|
|
436
|
-
if (counted
|
|
437
|
-
|
|
479
|
+
if (counted === "unterminated" || (typeof counted === "object" && "end" in counted && (counted.end === read.end || (reading === BASH32_DOUBLE_QUOTED && counted.end < read.end && doubleQuotedWordHolds(text, counted.end, read.end)))))
|
|
480
|
+
continue;
|
|
481
|
+
return refused;
|
|
438
482
|
}
|
|
439
|
-
return { end: read.end, arithmetic:
|
|
483
|
+
return { end: read.end, arithmetic: arithmetic !== undefined };
|
|
440
484
|
}
|
|
441
485
|
function arithmeticWalk(text, open, inDouble, level) {
|
|
442
486
|
if (text[past(text, open + 1)] !== "(")
|
|
@@ -478,10 +522,17 @@ function currentShellSubstitutionEnd(text, open, level) {
|
|
|
478
522
|
if (level > BODY_NESTING_MAX)
|
|
479
523
|
return "undelimited";
|
|
480
524
|
const list = { from: open + (text[open + 1] === "|" ? 2 : 1), groups: 0 };
|
|
481
|
-
const
|
|
525
|
+
const segments = [firstSegment(text)];
|
|
526
|
+
const read = scan(text, false, segments, level, list);
|
|
482
527
|
if ("parseFailure" in read)
|
|
483
528
|
return read;
|
|
484
|
-
|
|
529
|
+
if (list.closed === undefined)
|
|
530
|
+
return "undelimited";
|
|
531
|
+
const closed = list.closed;
|
|
532
|
+
if (passesFor(text, open).some((pass) => { const end = bracePassEnd(text, open, pass); return end !== closed && end !== "unterminated"; })) {
|
|
533
|
+
return fail(segments.some((s) => s.tokens.some((t) => t.kind === "heredoc")) ? "undelimited_substitution_heredoc" : "undelimited_substitution", open);
|
|
534
|
+
}
|
|
535
|
+
return { end: closed, from: list.from };
|
|
485
536
|
}
|
|
486
537
|
function bracketExpansionEnd(text, open) {
|
|
487
538
|
let depth = 0;
|
|
@@ -587,6 +638,9 @@ function backtickBody(source, open) {
|
|
|
587
638
|
return undefined;
|
|
588
639
|
}
|
|
589
640
|
export function expansionsInHeredocBody(body) {
|
|
641
|
+
return whileReading(body, () => expansionsInBody(body));
|
|
642
|
+
}
|
|
643
|
+
function expansionsInBody(body) {
|
|
590
644
|
const out = [];
|
|
591
645
|
for (let i = 0; i < body.length; i++) {
|
|
592
646
|
const ch = body[i];
|
|
@@ -606,7 +660,7 @@ export function expansionsInHeredocBody(body) {
|
|
|
606
660
|
continue;
|
|
607
661
|
const open = body[i + 1];
|
|
608
662
|
if (open === "(") {
|
|
609
|
-
const close = substitutionBodyEnd(body, i + 1, true, 0);
|
|
663
|
+
const close = substitutionBodyEnd(body, i + 1, true, 0, "document");
|
|
610
664
|
if (typeof close !== "object" || !("end" in close))
|
|
611
665
|
return undefined;
|
|
612
666
|
out.push({ expansion: { kind: close.arithmetic ? "arithmetic" : "command", yields: "one", body: body.slice(i + 2, close.end - 1) } });
|
|
@@ -1151,6 +1205,9 @@ class WordBuilder {
|
|
|
1151
1205
|
}
|
|
1152
1206
|
}
|
|
1153
1207
|
function scan(source, connectorsAreText, segments, level, list) {
|
|
1208
|
+
return whileReading(source, () => scanText(source, connectorsAreText, segments, level, list));
|
|
1209
|
+
}
|
|
1210
|
+
function scanText(source, connectorsAreText, segments, level, list) {
|
|
1154
1211
|
const split = !connectorsAreText;
|
|
1155
1212
|
const current = () => segments[segments.length - 1];
|
|
1156
1213
|
const pendingHeredocs = [];
|
|
@@ -1278,7 +1335,9 @@ function scan(source, connectorsAreText, segments, level, list) {
|
|
|
1278
1335
|
return undefined;
|
|
1279
1336
|
};
|
|
1280
1337
|
const readHeredocBodies = (from) => {
|
|
1281
|
-
const read = heredocBodies(source, from, pendingHeredocs,
|
|
1338
|
+
const read = heredocBodies(source, from, pendingHeredocs, list === undefined ? undefined : "}");
|
|
1339
|
+
if (read === "ambiguous")
|
|
1340
|
+
return fail("undelimited_substitution_heredoc", from);
|
|
1282
1341
|
if (typeof read !== "object")
|
|
1283
1342
|
return fail("unterminated_heredoc", from);
|
|
1284
1343
|
pendingHeredocs.forEach((h, k) => { h.token.body = read.bodies[k]; });
|
|
@@ -1295,7 +1354,7 @@ function scan(source, connectorsAreText, segments, level, list) {
|
|
|
1295
1354
|
const ch = source[i];
|
|
1296
1355
|
if (list !== undefined && ch === "}" && list.groups === 0 && !inSingle && !inDouble && !w.started && acceptable && pendingRedirect === undefined && pendingHeredoc === undefined) {
|
|
1297
1356
|
if (pendingHeredocs.length > 0)
|
|
1298
|
-
return fail("
|
|
1357
|
+
return fail("undelimited_substitution_heredoc", i);
|
|
1299
1358
|
list.closed = i + 1;
|
|
1300
1359
|
return { command: { segments: [], substitutions: [] } };
|
|
1301
1360
|
}
|
|
@@ -1472,7 +1531,7 @@ function scan(source, connectorsAreText, segments, level, list) {
|
|
|
1472
1531
|
continue;
|
|
1473
1532
|
}
|
|
1474
1533
|
if ((ch === "<" || ch === ">") && source[n1] === "(") {
|
|
1475
|
-
const close = substitutionBodyEnd(source, n1, false, level);
|
|
1534
|
+
const close = substitutionBodyEnd(source, n1, false, level, "process");
|
|
1476
1535
|
if (typeof close !== "object" || !("end" in close))
|
|
1477
1536
|
return close === "unterminated" ? fail("unterminated_process_substitution", i) : close === "undelimited" ? fail("undelimited_substitution", i) : close;
|
|
1478
1537
|
substitution(i, close.end, source.slice(n1 + 1, close.end - 1), "process");
|
|
@@ -1535,7 +1594,7 @@ function scan(source, connectorsAreText, segments, level, list) {
|
|
|
1535
1594
|
if (ch === "(") {
|
|
1536
1595
|
if (arithParens > 0)
|
|
1537
1596
|
arithParens++;
|
|
1538
|
-
else if (split && source[next(i)] === "(")
|
|
1597
|
+
else if (split && source[next(i)] === "(" && arithmeticCommandEnd(source, next(i)) !== undefined)
|
|
1539
1598
|
arithParens = 1;
|
|
1540
1599
|
}
|
|
1541
1600
|
else if (arithParens > 0)
|
|
@@ -1544,7 +1603,7 @@ function scan(source, connectorsAreText, segments, level, list) {
|
|
|
1544
1603
|
resetPosition();
|
|
1545
1604
|
continue;
|
|
1546
1605
|
}
|
|
1547
|
-
if (ch === "<" || ch === ">" || (ch === "&" && source[n1] === ">")) {
|
|
1606
|
+
if (arithParens === 0 && (ch === "<" || ch === ">" || (ch === "&" && source[n1] === ">"))) {
|
|
1548
1607
|
let fd;
|
|
1549
1608
|
if (ch !== "&" && w.started && w.raw === w.folded && /^\d+$/.test(w.raw)) {
|
|
1550
1609
|
fd = Number(w.raw);
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
*
|
|
26
26
|
* Pure data and a pure projection: this module imports nothing.
|
|
27
27
|
*/
|
|
28
|
-
export declare const SHELL_WORD_ROLES: readonly ["control_prefix", "group", "block", "compound_open", "loop_list_head", "loop_iterates", "loop_condition", "loop_end", "definition", "background", "case_arms", "timer", "scope_open", "scope_close", "scope_switch", "stripped_prefix", "stripped_standalone", "opaque", "rule_reserved", "base_mover", "stack_mover", "stack_editor"];
|
|
28
|
+
export declare const SHELL_WORD_ROLES: readonly ["control_prefix", "group", "block", "compound_open", "loop_list_head", "loop_iterates", "loop_condition", "loop_end", "definition", "background", "case_arms", "pass_keeps_reserved", "timer", "scope_open", "scope_close", "scope_switch", "stripped_prefix", "stripped_standalone", "opaque", "rule_reserved", "base_mover", "stack_mover", "stack_editor"];
|
|
29
29
|
export type ShellWordRole = (typeof SHELL_WORD_ROLES)[number];
|
|
30
30
|
/** Every word that plays `role`. The same set object on every call: a projection is a view, not a copy to edit. */
|
|
31
31
|
export declare function shellWordsOf(role: ShellWordRole): ReadonlySet<string>;
|
|
@@ -10,6 +10,7 @@ export const SHELL_WORD_ROLES = Object.freeze([
|
|
|
10
10
|
"definition",
|
|
11
11
|
"background",
|
|
12
12
|
"case_arms",
|
|
13
|
+
"pass_keeps_reserved",
|
|
13
14
|
"timer",
|
|
14
15
|
"scope_open",
|
|
15
16
|
"scope_close",
|
|
@@ -25,21 +26,21 @@ export const SHELL_WORD_ROLES = Object.freeze([
|
|
|
25
26
|
const ROWS = [
|
|
26
27
|
["!", "control_prefix", "stripped_prefix", "rule_reserved"],
|
|
27
28
|
["if", "control_prefix", "compound_open", "scope_open", "stripped_prefix", "rule_reserved"],
|
|
28
|
-
["then", "control_prefix", "stripped_prefix", "rule_reserved"],
|
|
29
|
-
["elif", "control_prefix", "scope_switch", "stripped_prefix", "rule_reserved"],
|
|
30
|
-
["else", "control_prefix", "scope_switch", "stripped_prefix", "rule_reserved"],
|
|
29
|
+
["then", "control_prefix", "stripped_prefix", "rule_reserved", "pass_keeps_reserved"],
|
|
30
|
+
["elif", "control_prefix", "scope_switch", "stripped_prefix", "rule_reserved", "pass_keeps_reserved"],
|
|
31
|
+
["else", "control_prefix", "scope_switch", "stripped_prefix", "rule_reserved", "pass_keeps_reserved"],
|
|
31
32
|
["while", "control_prefix", "compound_open", "loop_condition", "scope_open", "stripped_prefix", "rule_reserved"],
|
|
32
33
|
["until", "control_prefix", "compound_open", "loop_condition", "scope_open", "stripped_prefix", "rule_reserved"],
|
|
33
34
|
["do", "control_prefix", "stripped_prefix", "rule_reserved"],
|
|
34
|
-
["time", "control_prefix", "timer", "rule_reserved"],
|
|
35
|
+
["time", "control_prefix", "timer", "rule_reserved", "pass_keeps_reserved"],
|
|
35
36
|
["{", "group", "compound_open", "scope_open", "stripped_standalone", "rule_reserved"],
|
|
36
37
|
["}", "group", "scope_close", "stripped_standalone", "rule_reserved"],
|
|
37
38
|
["for", "block", "compound_open", "loop_list_head", "loop_iterates", "scope_open", "opaque", "rule_reserved"],
|
|
38
39
|
["select", "block", "compound_open", "loop_list_head", "scope_open", "opaque", "rule_reserved"],
|
|
39
40
|
["case", "block", "compound_open", "case_arms", "scope_open", "opaque", "rule_reserved"],
|
|
40
|
-
["esac", "block", "scope_close", "stripped_standalone", "rule_reserved"],
|
|
41
|
+
["esac", "block", "scope_close", "stripped_standalone", "rule_reserved", "pass_keeps_reserved"],
|
|
41
42
|
["fi", "block", "scope_close", "stripped_standalone", "rule_reserved"],
|
|
42
|
-
["done", "block", "loop_end", "scope_close", "stripped_standalone", "rule_reserved"],
|
|
43
|
+
["done", "block", "loop_end", "scope_close", "stripped_standalone", "rule_reserved", "pass_keeps_reserved"],
|
|
43
44
|
["function", "block", "definition", "opaque", "rule_reserved"],
|
|
44
45
|
["coproc", "block", "background", "opaque", "rule_reserved"],
|
|
45
46
|
["]]", "block", "stripped_standalone", "rule_reserved"],
|
|
@@ -2,7 +2,7 @@ import { type MemoryStore, type UtilityGate } from "../../core/memory.js";
|
|
|
2
2
|
import type { CheckpointStore } from "../../core/checkpoint-store.js";
|
|
3
3
|
import type { ToolResultStore } from "../../core/tool-result-store.js";
|
|
4
4
|
import { type EvictPolicy } from "../../core/session-store.js";
|
|
5
|
-
import type { SessionStore } from "../../core/session.js";
|
|
5
|
+
import type { SessionStore, SessionStoreHooks } from "../../core/session.js";
|
|
6
6
|
import { type FileCheckpointStoreOptions } from "./checkpoint-store.js";
|
|
7
7
|
import { type FileSessionPolicyStoreOptions } from "./session-policy-store.js";
|
|
8
8
|
import { type FileFileHistoryStoreOptions } from "./file-history-store.js";
|
|
@@ -107,6 +107,9 @@ export interface FileStorageBackendOptions {
|
|
|
107
107
|
* `principal` when the read was keyed by one. One sink for one failure grammar — a host does not register three.
|
|
108
108
|
*/
|
|
109
109
|
onCorruptRead?: (info: FileStorageCorruptReadInfo) => void;
|
|
110
|
+
/** The deployment's hooks on the session store's row deletions ({@link SessionStoreHooks}) — the File lane has no foreign keys, so a
|
|
111
|
+
* deployment's own records keyed by session id are cleaned here, before each row the session store deletes. */
|
|
112
|
+
sessions?: SessionStoreHooks;
|
|
110
113
|
}
|
|
111
114
|
/**
|
|
112
115
|
* The payload of {@link FileStorageBackendOptions.onCorruptRead} — the widest shape any store this
|
|
@@ -51,6 +51,9 @@ export class FileStorageBackend {
|
|
|
51
51
|
fileSessions;
|
|
52
52
|
fileWorkflowJournal;
|
|
53
53
|
constructor(opts = {}) {
|
|
54
|
+
if ("retention" in opts) {
|
|
55
|
+
throw Object.assign(new Error(`FileStorageBackend runs no retention executor, so its options take no \`retention\` word: its stores declare "none".`), { code: "config.retention_capability" });
|
|
56
|
+
}
|
|
54
57
|
this.root = resolveDataRoot(opts.root);
|
|
55
58
|
assertAdoptionBootGate(this.root, "FileStorageBackend");
|
|
56
59
|
this.lock = new BootLock(join(this.root, "LOCK"));
|
|
@@ -60,7 +63,7 @@ export class FileStorageBackend {
|
|
|
60
63
|
const corruptRead = opts.onCorruptRead !== undefined ? { onCorruptRead: opts.onCorruptRead } : undefined;
|
|
61
64
|
const repo = new FileSessionRepo(this.root, corruptRead);
|
|
62
65
|
this.fileSessions = repo;
|
|
63
|
-
this.ttl = new TtlSessionStore({ repo, evict: opts.evict ?? "forget", durability: "durable", placements: { subagent: { durability: "durable" } } });
|
|
66
|
+
this.ttl = new TtlSessionStore({ repo, evict: opts.evict ?? "forget", durability: "durable", placements: { subagent: { durability: "durable" } }, ...(opts.sessions !== undefined ? { hooks: opts.sessions } : {}) });
|
|
64
67
|
this.sessionStore = this.ttl;
|
|
65
68
|
const sessionHeadOf = this.ttl.headOf;
|
|
66
69
|
this.fileCheckpoints = new FileCheckpointStore(this.root, { ...opts.checkpoint, ...corruptRead, ...(sessionHeadOf !== undefined ? { sessionHeadOf } : {}) });
|
|
@@ -2,7 +2,7 @@ import { join, resolve, sep } from "node:path";
|
|
|
2
2
|
import { createHash, randomBytes } from "node:crypto";
|
|
3
3
|
import { assertRetentionPolicy } from "../../core/retention-policy.js";
|
|
4
4
|
import { existsSync, linkSync, readdirSync, readFileSync, renameSync, statSync, unlinkSync, writeFileSync } from "node:fs";
|
|
5
|
-
import { assertMailboxDecisionMove, detachMailboxMessage, newestSentAt, readStoredMailboxDecision,
|
|
5
|
+
import { assertMailboxDecisionMove, detachMailboxMessage, newestSentAt, readStoredMailboxDecision, readMailboxAppend, judgeMailboxAppendById, } from "../../core/mailbox-store.js";
|
|
6
6
|
import { AppendLog, atomicWriteFile, canonicalStoreKey, ensureDir, readJsonlRecords, sanitizeScope, sanitizePathComponent } from "./fs-atomic.js";
|
|
7
7
|
import { guardCorruptSink } from "./corrupt-read-sink.js";
|
|
8
8
|
import { physicalPathOf } from "../../core/physical-path.js";
|
|
@@ -441,18 +441,14 @@ export class FileMailboxStore {
|
|
|
441
441
|
async append(scope, handle, msg) {
|
|
442
442
|
if (scope === undefined || scope === "")
|
|
443
443
|
throw new Error("MailboxStore.append: refusing a message without a scope");
|
|
444
|
-
const
|
|
444
|
+
const record = readMailboxAppend(msg);
|
|
445
445
|
return this.withBox(this.lockKey(scope, handle), this.boxPath(scope, handle), () => {
|
|
446
446
|
const b = this.load(scope, handle);
|
|
447
|
+
const held = judgeMailboxAppendById(b.messages, record);
|
|
448
|
+
if (held !== undefined)
|
|
449
|
+
return held;
|
|
447
450
|
const seq = b.nextSeq;
|
|
448
|
-
const m = {
|
|
449
|
-
seq,
|
|
450
|
-
...(msg.from !== undefined ? { from: msg.from } : {}),
|
|
451
|
-
content: msg.content,
|
|
452
|
-
sentAt: msg.sentAt,
|
|
453
|
-
...(msg.hopChain !== undefined ? { hopChain: [...msg.hopChain] } : {}),
|
|
454
|
-
...(peerMeta !== undefined ? { peerMeta } : {}),
|
|
455
|
-
};
|
|
451
|
+
const m = { seq, ...record };
|
|
456
452
|
this.commit(b, this.boxPath(scope, handle), { t: "append", m });
|
|
457
453
|
return seq;
|
|
458
454
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Session, SessionCreateOptions, SessionForkOptions, SessionHead, SessionMetadata, SessionPlacementRecord, SessionRepo, SessionRow, SessionTreeEntry } from "../../internal/harness.js";
|
|
1
|
+
import type { Session, SessionCreateOptions, SessionForkOptions, SessionHead, SessionMetadata, SessionPlacementRecord, SessionRepo, SessionRow, SessionRowExpectation, SessionRowRead, SessionTreeEntry } from "../../internal/harness.js";
|
|
2
2
|
import type { PlacedSessionRow } from "../../core/session.js";
|
|
3
3
|
import { type CorruptReadInfo } from "./corrupt-read-sink.js";
|
|
4
4
|
export interface FileSessionRepoOptions {
|
|
@@ -60,6 +60,13 @@ export declare class FileSessionRepo implements SessionRepo {
|
|
|
60
60
|
* head does not see. A leaf entry naming an id the log does not hold is not checked here (a replay refuses that log on open).
|
|
61
61
|
*/
|
|
62
62
|
headOf(sessionId: string): Promise<SessionHead | undefined>;
|
|
63
|
+
/** {@link headOf}'s one read, synchronously — what a conditional delete judges its expectation against in the step that removes the row. */
|
|
64
|
+
private headNow;
|
|
65
|
+
/** The row in one read of its file (one inode): the header's cells, the head they and the replayed log give, and the log. */
|
|
66
|
+
readRow(sessionId: string): Promise<SessionRowRead | undefined>;
|
|
67
|
+
/** {@link readRow}'s one read, synchronously — what a conditional import judges its expectation against in the step that writes. A
|
|
68
|
+
* file whose header cannot be read rejects (`corrupt_session`): it is a row whose cells nobody can name. */
|
|
69
|
+
private rowNow;
|
|
63
70
|
/**
|
|
64
71
|
* The row's {@link SessionRow} — its header cells and the newest write it holds, the log's modification time (every write to a row
|
|
65
72
|
* is an append to its log; the placed listing's age reads the same time) — in one read of the header, never a replay of the log.
|
|
@@ -111,24 +118,24 @@ export declare class FileSessionRepo implements SessionRepo {
|
|
|
111
118
|
olderThanMs?: number;
|
|
112
119
|
scope?: string;
|
|
113
120
|
}): Promise<PlacedSessionRow[]>;
|
|
114
|
-
/** The row as it stands before a file-replacing write: `undefined` ⇔ there is no row (no file); a row
|
|
115
|
-
* whose header cannot be read rejects (it exists, and nobody can name its cells). */
|
|
116
|
-
private priorHeader;
|
|
117
121
|
/** Cheap placement probe for one id (the TtlSessionStore's cold-cache release consults it so the
|
|
118
122
|
* placed real-deletion obligation holds after a restart). `undefined` = missing file OR unplaced; a row that cannot be read rejects. */
|
|
119
123
|
placementOf(sessionId: string): Promise<SessionPlacementRecord | undefined>;
|
|
120
|
-
delete(metadata: SessionMetadata): Promise<void>;
|
|
124
|
+
delete(metadata: SessionMetadata, expect?: SessionRowExpectation): Promise<void>;
|
|
121
125
|
fork(sourceMetadata: SessionMetadata, options?: SessionForkOptions & SessionCreateOptions): Promise<Session>;
|
|
122
126
|
/** 2c session-sync (the FILE half): the FULL oldest-first log for export. The file backend
|
|
123
127
|
* has NO F3 floor — `read` returns EVERY persisted entry (`id`/`parentId` verbatim) — so this is the complete
|
|
124
128
|
* log, BYPASSing any bounded tail (matches `InMemorySessionRepo.exportEntries`). Missing file → not_found. */
|
|
125
129
|
exportEntries(sessionId: string): Promise<SessionTreeEntry[]>;
|
|
126
130
|
/** 2c session-sync: import a verbatim log into `sessionId`. The single fail-closed invariant gate runs
|
|
127
|
-
* FIRST ({@link validateEntriesForImport}); a new row's header records `owner`, an existing row's is laid down again whole
|
|
131
|
+
* FIRST ({@link validateEntriesForImport}); a new row's header records `owner`, an existing row's is laid down again whole and must already
|
|
132
|
+
* be `owner`'s (`importRowCells`), and the row must be the one `options.expect` names (`sessionRowMatches`) — the row read, both
|
|
133
|
+
* judgements and the write with no await between; the head answered is the one the write lays down. Writes the WHOLE file
|
|
128
134
|
* (meta + entries) atomically via tmp→fsync→rename — the rename is the commit point, so a crash leaves either nothing or an
|
|
129
|
-
* orphan temp, never a partially-imported session (mirrors `fork`).
|
|
135
|
+
* orphan temp, never a partially-imported session (mirrors `fork`). The importer's existing session is REPLACED (the
|
|
130
136
|
* orchestrator's importSession owns the already-exists policy, same as InMemory's overwrite). */
|
|
131
137
|
importEntries(sessionId: string, owner: string | undefined, entries: SessionTreeEntry[], options?: {
|
|
132
138
|
preserveActorAssertions?: boolean;
|
|
133
|
-
|
|
139
|
+
expect?: SessionRowExpectation;
|
|
140
|
+
}): Promise<SessionHead>;
|
|
134
141
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { closeSync, existsSync, fstatSync, openSync, readdirSync, rmSync, utimesSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
-
import { BaseSessionStorage, StoredSession, SessionError, assertForkTarget, compareOccupants, forkRowCells, frozenRow, getEntriesToFork, importRowCells, incarnationCell, leafIdAfterEntry, ownerCell, readIncarnationCell, readOwnerCell, uuidv7, validateEntriesForImport, } from "../../internal/harness.js";
|
|
3
|
+
import { BaseSessionStorage, StoredSession, SessionError, assertForkTarget, compareOccupants, forkRowCells, frozenRow, getEntriesToFork, importRowCells, incarnationCell, leafIdAfterEntry, ownerCell, readIncarnationCell, readOwnerCell, resolveLeafId, rowExpectationMissed, sessionLogMarkOf, sessionRowMatches, uuidv7, validateEntriesForImport, } from "../../internal/harness.js";
|
|
4
4
|
import { canonicalStoreKey, AppendLog, atomicWriteFile, ensureDir, firstJsonlRecord, lastJsonlRecord, readJsonlRecords, sanitizePathComponent, writeThenLink } from "./fs-atomic.js";
|
|
5
5
|
import { guardCorruptSink } from "./corrupt-read-sink.js";
|
|
6
6
|
import { assertAdoptionBootGate } from "./adoption/marker.js";
|
|
@@ -125,11 +125,30 @@ export class FileSessionRepo {
|
|
|
125
125
|
};
|
|
126
126
|
}
|
|
127
127
|
async headOf(sessionId) {
|
|
128
|
+
return this.headNow(sessionId);
|
|
129
|
+
}
|
|
130
|
+
headNow(sessionId) {
|
|
128
131
|
return this.atRow(sessionId, (fd, size, meta) => {
|
|
129
132
|
const last = lastJsonlRecord(fd, size, (r) => r.kind === "entry", SESSION_LINE_JUDGE);
|
|
130
133
|
return { owner: meta.owner ?? null, incarnation: meta.incarnation, leafId: last === undefined ? null : leafIdAfterEntry(last.entry) };
|
|
131
134
|
});
|
|
132
135
|
}
|
|
136
|
+
async readRow(sessionId) {
|
|
137
|
+
return this.rowNow(sessionId);
|
|
138
|
+
}
|
|
139
|
+
rowNow(sessionId) {
|
|
140
|
+
let read;
|
|
141
|
+
try {
|
|
142
|
+
read = this.read(sessionId);
|
|
143
|
+
}
|
|
144
|
+
catch (err) {
|
|
145
|
+
if (err instanceof SessionError && err.code === "not_found")
|
|
146
|
+
return undefined;
|
|
147
|
+
throw err;
|
|
148
|
+
}
|
|
149
|
+
const { meta, entries } = read;
|
|
150
|
+
return { metadata: meta, head: { owner: meta.owner ?? null, incarnation: meta.incarnation, leafId: resolveLeafId(entries) }, entries };
|
|
151
|
+
}
|
|
133
152
|
rowOf(sessionId) {
|
|
134
153
|
return this.atRow(sessionId, (_fd, _size, meta, mtimeMs) => ({ ...meta, lastActiveAt: Math.trunc(mtimeMs) }));
|
|
135
154
|
}
|
|
@@ -270,16 +289,6 @@ export class FileSessionRepo {
|
|
|
270
289
|
}
|
|
271
290
|
return out;
|
|
272
291
|
}
|
|
273
|
-
priorHeader(id) {
|
|
274
|
-
try {
|
|
275
|
-
return this.read(id).meta;
|
|
276
|
-
}
|
|
277
|
-
catch (err) {
|
|
278
|
-
if (err instanceof SessionError && err.code === "not_found")
|
|
279
|
-
return undefined;
|
|
280
|
-
throw err;
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
292
|
async placementOf(sessionId) {
|
|
284
293
|
try {
|
|
285
294
|
return this.read(sessionId).meta.placement;
|
|
@@ -290,7 +299,9 @@ export class FileSessionRepo {
|
|
|
290
299
|
throw err;
|
|
291
300
|
}
|
|
292
301
|
}
|
|
293
|
-
async delete(metadata) {
|
|
302
|
+
async delete(metadata, expect) {
|
|
303
|
+
if (expect !== undefined && !sessionRowMatches(expect, this.headNow(metadata.id), () => sessionLogMarkOf(this.read(metadata.id).entries)))
|
|
304
|
+
throw rowExpectationMissed(metadata.id, "delete");
|
|
294
305
|
evictSharedSessionStorage(canonicalStoreKey(this.pathFor(metadata.id)));
|
|
295
306
|
try {
|
|
296
307
|
rmSync(this.pathFor(metadata.id), { force: true });
|
|
@@ -320,12 +331,16 @@ export class FileSessionRepo {
|
|
|
320
331
|
}
|
|
321
332
|
async importEntries(sessionId, owner, entries, options) {
|
|
322
333
|
const validated = validateEntriesForImport(entries, options);
|
|
323
|
-
const
|
|
334
|
+
const prior = this.rowNow(sessionId);
|
|
335
|
+
if (!sessionRowMatches(options?.expect, prior?.metadata, () => sessionLogMarkOf(prior.entries)))
|
|
336
|
+
throw rowExpectationMissed(sessionId, "import");
|
|
337
|
+
const meta = importRowCells(sessionId, owner, prior?.metadata, new Date().toISOString());
|
|
324
338
|
evictSharedSessionStorage(canonicalStoreKey(this.pathFor(sessionId)));
|
|
325
339
|
const lines = [JSON.stringify({ kind: "meta", ...meta })];
|
|
326
340
|
for (const entry of validated) {
|
|
327
341
|
lines.push(JSON.stringify({ kind: "entry", entry }));
|
|
328
342
|
}
|
|
329
343
|
atomicWriteFile(this.tmpDir, this.pathFor(sessionId), `${lines.join("\n")}\n`);
|
|
344
|
+
return { owner: meta.owner ?? null, incarnation: meta.incarnation, leafId: resolveLeafId(validated) };
|
|
330
345
|
}
|
|
331
346
|
}
|
|
@@ -3,6 +3,7 @@ import { type TaskRegistry } from "../../core/task-registry.js";
|
|
|
3
3
|
import { type CwdRef } from "./fs-shared.js";
|
|
4
4
|
import type { ReversibilityVerdict } from "../../core/types.js";
|
|
5
5
|
import type { ShellReadAdmission } from "./shell-read-check.js";
|
|
6
|
+
import type { ReadFloorSeat } from "./read-floor.js";
|
|
6
7
|
/**
|
|
7
8
|
* The full shell face's SHAPE classifier for the `bash` tool, exposed as a `ToolSpec.reversibilityProbe`
|
|
8
9
|
* (the "maybe" tier's probe, installed on every full shell). A command is reversible ONLY if every connected
|
|
@@ -144,6 +145,9 @@ export declare function createBashTool(env: ExecutionEnv, rootCanonical: string,
|
|
|
144
145
|
* nothing is re-established, and the full shell runs unconfined as it always did.
|
|
145
146
|
*/
|
|
146
147
|
shellReadAdmission?: ShellReadAdmission;
|
|
148
|
+
/** The byte floor's seat (read-floor.ts): every command this leg starts, foreground or background, carries the
|
|
149
|
+
* read-deny table its call judges with to the environment. Absent ⇒ no table, the starts carry nothing. */
|
|
150
|
+
readFloor?: ReadFloorSeat;
|
|
147
151
|
/** Override of the `timeout` parameter's DEFAULT budget, in ms — see
|
|
148
152
|
* {@link import("./index.js").HandsToolkitOptions.bashDefaultTimeoutMs} for the resolution
|
|
149
153
|
* contract (options over env over constant; invalid values discarded). */
|
|
@@ -201,6 +205,8 @@ export declare function createBashReadonlyTool(env: ExecutionEnv, rootCanonical:
|
|
|
201
205
|
* containment IS the station, and a consumer mounting it without one must run `runToolGate` with the
|
|
202
206
|
* station's `shellReadCheck` (the Runner does). */
|
|
203
207
|
shellReadAdmission?: ShellReadAdmission;
|
|
208
|
+
/** The byte floor's seat — the SAME one the full shell leg takes (read-floor.ts). */
|
|
209
|
+
readFloor?: ReadFloorSeat;
|
|
204
210
|
/** The run's tool-progress sink — the SAME seat the full shell leg takes, for the same reason its
|
|
205
211
|
* two neighbours above are shared: both foreground legs run through `runShell`, so a long command
|
|
206
212
|
* must breathe on both or a person watching one of them is told nothing. This face has no detach
|
package/dist/tools/fs/fs-bash.js
CHANGED
|
@@ -292,7 +292,7 @@ function startLivenessTicks(onTick, filterStderr) {
|
|
|
292
292
|
stop: () => clearInterval(timer),
|
|
293
293
|
};
|
|
294
294
|
}
|
|
295
|
-
async function runShell(env, cwd, toolName, command, timeoutSec, caps, signal, cwdRef, detach, readOnly, containmentRoots, onTick) {
|
|
295
|
+
async function runShell(env, cwd, toolName, command, timeoutSec, caps, signal, cwdRef, detach, readOnly, containmentRoots, onTick, readFloor) {
|
|
296
296
|
const requestedSec = Math.max(1, Math.floor(timeoutSec ?? caps.defaultSec));
|
|
297
297
|
let timeout = Math.min(caps.maxSec, requestedSec);
|
|
298
298
|
const cappedByMaxTimeout = requestedSec > caps.maxSec;
|
|
@@ -311,6 +311,7 @@ async function runShell(env, cwd, toolName, command, timeoutSec, caps, signal, c
|
|
|
311
311
|
abortSignal: signal,
|
|
312
312
|
...execEnv,
|
|
313
313
|
...(live !== undefined ? { onStdout: live.onStdout, onStderr: live.onStderr } : {}),
|
|
314
|
+
...(readFloor !== undefined ? { readFloor } : {}),
|
|
314
315
|
...(detach
|
|
315
316
|
? {
|
|
316
317
|
detachSignal: detach.signal,
|
|
@@ -607,9 +608,11 @@ export function createBashTool(env, rootCanonical, coAuthor = false, cwdRef = {
|
|
|
607
608
|
if (ctx.signal?.aborted === true)
|
|
608
609
|
return errorResult("Error (Bash): the call was cancelled before the background command started.");
|
|
609
610
|
const requestedTimeoutSec = timeout !== undefined ? Math.max(1, Math.round(timeout / 1000)) : undefined;
|
|
611
|
+
const readFloor = taskOpts.readFloor?.(ctx.toolCallId);
|
|
610
612
|
const r = await env.spawnBackground(command, {
|
|
611
613
|
cwd: cwdRef.current,
|
|
612
614
|
...(requestedTimeoutSec !== undefined ? { timeout: requestedTimeoutSec } : {}),
|
|
615
|
+
...(readFloor !== undefined ? { readFloor } : {}),
|
|
613
616
|
});
|
|
614
617
|
if (!r.ok)
|
|
615
618
|
return errorResult(`Error (Bash): the background process could not be started (${r.error.code}): ${envErrorDetail(r.error.message)}`);
|
|
@@ -765,7 +768,7 @@ export function createBashTool(env, rootCanonical, coAuthor = false, cwdRef = {
|
|
|
765
768
|
: undefined;
|
|
766
769
|
let res;
|
|
767
770
|
try {
|
|
768
|
-
res = await runShell(env, rootCanonical, "Bash", command, msTimeoutToRequestedSec(timeout), timeoutCapsSecView, ctx.signal, cwdRef, detachChain, false, [rootCanonical, ...(taskOpts.additionalRoots ?? [])], onTick);
|
|
771
|
+
res = await runShell(env, rootCanonical, "Bash", command, msTimeoutToRequestedSec(timeout), timeoutCapsSecView, ctx.signal, cwdRef, detachChain, false, [rootCanonical, ...(taskOpts.additionalRoots ?? [])], onTick, taskOpts.readFloor?.(ctx.toolCallId));
|
|
769
772
|
}
|
|
770
773
|
finally {
|
|
771
774
|
taskOpts.detachHub?.gc(ctx.toolCallId);
|
|
@@ -811,7 +814,7 @@ export function createBashReadonlyTool(env, rootCanonical, allow, opts) {
|
|
|
811
814
|
if (refused !== undefined)
|
|
812
815
|
return refused;
|
|
813
816
|
const readOnlyTick = opts?.onToolProgress === undefined ? undefined : (t) => describeSafely(opts.onToolProgress, { toolCallId: ctx.toolCallId, toolName: "Bash", ...t });
|
|
814
|
-
return await runShell(env, rootCanonical, "Bash", command, msTimeoutToRequestedSec(timeout), timeoutCapsSecView, ctx.signal, undefined, undefined, true, undefined, readOnlyTick);
|
|
817
|
+
return await runShell(env, rootCanonical, "Bash", command, msTimeoutToRequestedSec(timeout), timeoutCapsSecView, ctx.signal, undefined, undefined, true, undefined, readOnlyTick, opts?.readFloor?.(ctx.toolCallId));
|
|
815
818
|
},
|
|
816
819
|
});
|
|
817
820
|
}
|