@sema-agent/core 7.48.0 → 7.49.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +457 -0
- package/README.md +2 -2
- package/dist/agents/cascade.d.ts +2 -5
- package/dist/agents/child-failure.d.ts +20 -0
- package/dist/agents/child-failure.js +28 -0
- package/dist/agents/cross-session-ref.d.ts +11 -3
- package/dist/agents/cross-session-ref.js +6 -0
- package/dist/agents/cumulative-stats.d.ts +12 -15
- package/dist/agents/cumulative-stats.js +1 -1
- package/dist/agents/extra-tool-names.js +1 -1
- package/dist/agents/inherited-tool-pool.d.ts +17 -13
- package/dist/agents/inherited-tool-pool.js +4 -3
- package/dist/agents/peer-session-drain.d.ts +3 -2
- package/dist/agents/peer-session-drain.js +5 -4
- package/dist/agents/send-message-tool.js +2 -9
- package/dist/agents/subagent.d.ts +10 -29
- package/dist/agents/subagent.js +65 -53
- package/dist/agents/suspend-guard.d.ts +1 -1
- package/dist/agents/tool-filter.d.ts +76 -65
- package/dist/agents/tool-filter.js +122 -92
- package/dist/agents/verify.d.ts +4 -7
- package/dist/agents/verify.js +6 -7
- package/dist/bench/metrics.d.ts +1 -2
- package/dist/brain/anthropic.js +133 -79
- package/dist/brain/errors.d.ts +53 -6
- package/dist/brain/errors.js +22 -2
- package/dist/brain/input-too-long.d.ts +40 -19
- package/dist/brain/input-too-long.js +3 -16
- package/dist/brain/open-responses.js +19 -10
- package/dist/brain/openai.js +123 -32
- package/dist/brain/provider-dialect.d.ts +214 -0
- package/dist/brain/provider-dialect.js +186 -0
- package/dist/brain/request-params.d.ts +27 -8
- package/dist/brain/request-params.js +7 -12
- package/dist/brain/request-route.d.ts +84 -0
- package/dist/brain/request-route.js +41 -0
- package/dist/brain/retry.d.ts +8 -0
- package/dist/brain/retry.js +10 -4
- package/dist/brain/route-adjudicator.d.ts +7 -0
- package/dist/brain/route-adjudicator.js +5 -1
- package/dist/brain/status-sink.d.ts +20 -0
- package/dist/brain/status-sink.js +11 -0
- package/dist/brain/stream-engine.d.ts +52 -1
- package/dist/brain/stream-engine.js +81 -24
- package/dist/brain/stream-shared.d.ts +57 -11
- package/dist/brain/stream-shared.js +28 -2
- package/dist/core/a2a.d.ts +1 -0
- package/dist/core/agent-config-dir.js +3 -2
- package/dist/core/allow-entry.d.ts +21 -12
- package/dist/core/allow-entry.js +38 -31
- package/dist/core/arg-summary.d.ts +21 -28
- package/dist/core/arg-summary.js +235 -88
- package/dist/core/ask-origin.d.ts +42 -24
- package/dist/core/ask-origin.js +18 -13
- package/dist/core/auto-mode-prompt-assets.d.ts +2 -2
- package/dist/core/auto-mode-prompt-assets.js +1 -1
- package/dist/core/auto-mode-prompt.d.ts +11 -1
- package/dist/core/auto-mode-prompt.js +13 -10
- package/dist/core/auto-mode-rebuild.d.ts +7 -0
- package/dist/core/auto-mode-rebuild.js +4 -1
- package/dist/core/canonical-json.d.ts +3 -0
- package/dist/core/canonical-json.js +2 -1
- package/dist/core/checkpoint-requirements.d.ts +892 -0
- package/dist/core/checkpoint-requirements.js +333 -0
- package/dist/core/checkpoint-store.d.ts +94 -65
- package/dist/core/checkpoint-store.js +14 -26
- package/dist/core/child-clamp-seats.d.ts +228 -69
- package/dist/core/child-clamp-seats.js +211 -17
- package/dist/core/classifier-unavailable-arm.d.ts +5 -1
- package/dist/core/classifier-unavailable-arm.js +3 -3
- package/dist/core/compliance.d.ts +3 -0
- package/dist/core/compliance.js +9 -4
- package/dist/core/credential-vocabulary.d.ts +140 -0
- package/dist/core/credential-vocabulary.js +131 -0
- package/dist/core/decision-receipt.js +1 -1
- package/dist/core/effective-path-target.d.ts +73 -16
- package/dist/core/effective-path-target.js +63 -33
- package/dist/core/engine-notice.d.ts +43 -11
- package/dist/core/file-history-store.js +2 -2
- package/dist/core/fs-write-gate-policy.d.ts +4 -0
- package/dist/core/fs-write-gate-policy.js +22 -5
- package/dist/core/gate-bounded-await.d.ts +28 -13
- package/dist/core/gate-bounded-await.js +41 -4
- package/dist/core/gate-fold.d.ts +1 -1
- package/dist/core/gate-fold.js +24 -25
- package/dist/core/gate-lanes.js +16 -15
- package/dist/core/gate-outcome.d.ts +20 -5
- package/dist/core/gate-outcome.js +5 -0
- package/dist/core/governance-codes.d.ts +11 -4
- package/dist/core/governance-codes.js +14 -3
- package/dist/core/hooks.d.ts +21 -0
- package/dist/core/locked-config.d.ts +8 -0
- package/dist/core/locked-config.js +14 -2
- package/dist/core/lsp.js +3 -5
- package/dist/core/mailbox-store.d.ts +3 -4
- package/dist/core/mcp-connection-pool.d.ts +75 -0
- package/dist/core/mcp-connection-pool.js +128 -0
- package/dist/core/mcp-failure.d.ts +2 -1
- package/dist/core/mcp-failure.js +13 -2
- package/dist/core/mcp.d.ts +4 -0
- package/dist/core/mcp.js +70 -43
- package/dist/core/memory-engine/content-origin.js +2 -14
- package/dist/core/memory-engine/engine.d.ts +32 -22
- package/dist/core/memory-engine/engine.js +103 -55
- package/dist/core/memory-engine/file-backend.d.ts +13 -30
- package/dist/core/memory-engine/file-backend.js +37 -252
- package/dist/core/memory-engine/index.d.ts +1 -1
- package/dist/core/memory-engine/index.js +1 -1
- package/dist/core/memory-engine/layout.d.ts +139 -9
- package/dist/core/memory-engine/layout.js +350 -7
- package/dist/core/memory-engine/scope-contract.d.ts +10 -0
- package/dist/core/memory-engine/scope-contract.js +8 -0
- package/dist/core/memory-engine/session-incarnation.d.ts +14 -4
- package/dist/core/memory-engine/session-incarnation.js +5 -2
- package/dist/core/memory-engine/types.d.ts +10 -1
- package/dist/core/memory.js +5 -17
- package/dist/core/model-seat.d.ts +4 -4
- package/dist/core/model-seat.js +1 -1
- package/dist/core/mounted-mcp.d.ts +57 -0
- package/dist/core/mounted-mcp.js +19 -0
- package/dist/core/namespaced-rule-name.d.ts +29 -0
- package/dist/core/namespaced-rule-name.js +52 -0
- package/dist/core/park-selfcheck.d.ts +1 -1
- package/dist/core/park-selfcheck.js +16 -6
- package/dist/core/path-guard-rows.d.ts +99 -0
- package/dist/core/path-guard-rows.js +45 -0
- package/dist/core/path-identity.d.ts +22 -16
- package/dist/core/path-identity.js +10 -10
- package/dist/core/path-rule-binding.d.ts +2 -1
- package/dist/core/path-rule-binding.js +3 -1
- package/dist/core/pause-registry.d.ts +16 -2
- package/dist/core/pause-registry.js +6 -0
- package/dist/core/permission-rule-consent.js +0 -7
- package/dist/core/permission-rule-model.d.ts +68 -24
- package/dist/core/permission-rule-model.js +105 -24
- package/dist/core/permission-rule-store.js +2 -2
- package/dist/core/permission-rules.d.ts +3 -30
- package/dist/core/permission-rules.js +4 -54
- package/dist/core/read-root-candidate.d.ts +1 -3
- package/dist/core/read-root-candidate.js +4 -15
- package/dist/core/real-approval.d.ts +4 -3
- package/dist/core/retired-keys.d.ts +13 -0
- package/dist/core/retired-keys.js +14 -0
- package/dist/core/roles.d.ts +2 -3
- package/dist/core/roles.js +15 -6
- package/dist/core/runner/assemble-result.d.ts +0 -7
- package/dist/core/runner/assemble-result.js +19 -31
- package/dist/core/runner/caller-roster.d.ts +78 -0
- package/dist/core/runner/caller-roster.js +219 -0
- package/dist/core/runner/checkpoint-scope.d.ts +16 -16
- package/dist/core/runner/checkpoint-scope.js +2 -2
- package/dist/core/runner/child-tree.js +2 -2
- package/dist/core/runner/contracts.d.ts +68 -35
- package/dist/core/runner/decide-continuation.d.ts +51 -3
- package/dist/core/runner/decide-continuation.js +76 -21
- package/dist/core/runner/denial-limit-arms.d.ts +17 -5
- package/dist/core/runner/denial-limit-arms.js +11 -9
- package/dist/core/runner/extra-body-dropped-seat.d.ts +8 -0
- package/dist/core/runner/extra-body-dropped-seat.js +22 -0
- package/dist/core/runner/finish-reason-seat.d.ts +9 -0
- package/dist/core/runner/finish-reason-seat.js +40 -0
- package/dist/core/runner/gate-exit.d.ts +44 -32
- package/dist/core/runner/gate-exit.js +112 -25
- package/dist/core/runner/inherited-ask-grants.js +6 -4
- package/dist/core/runner/mcp-redial.d.ts +3 -3
- package/dist/core/runner/mcp-redial.js +3 -4
- package/dist/core/runner/permission-rule-lanes.d.ts +1 -2
- package/dist/core/runner/permission-rule-lanes.js +5 -4
- package/dist/core/runner/prepare-artifact.d.ts +4 -0
- package/dist/core/runner/prepare-artifact.js +2 -1
- package/dist/core/runner/prepare-ask-lane.d.ts +2 -0
- package/dist/core/runner/prepare-ask-lane.js +12 -6
- package/dist/core/runner/prepare-boundary-parks.d.ts +5 -8
- package/dist/core/runner/prepare-boundary-parks.js +4 -7
- package/dist/core/runner/prepare-caps-and-workflow.d.ts +11 -15
- package/dist/core/runner/prepare-caps-and-workflow.js +19 -27
- package/dist/core/runner/prepare-config-doors.d.ts +9 -9
- package/dist/core/runner/prepare-config-doors.js +10 -5
- package/dist/core/runner/prepare-defer-classify.d.ts +2 -2
- package/dist/core/runner/prepare-defer-classify.js +5 -3
- package/dist/core/runner/prepare-delegation-surface.d.ts +1 -1
- package/dist/core/runner/prepare-delegation-surface.js +3 -3
- package/dist/core/runner/prepare-gate-stations.d.ts +4 -4
- package/dist/core/runner/prepare-gate-stations.js +9 -7
- package/dist/core/runner/prepare-hands-readface.d.ts +7 -7
- package/dist/core/runner/prepare-hands-readface.js +7 -7
- package/dist/core/runner/prepare-inherited-gate.d.ts +7 -6
- package/dist/core/runner/prepare-inherited-gate.js +14 -15
- package/dist/core/runner/prepare-listings.d.ts +7 -24
- package/dist/core/runner/prepare-listings.js +4 -5
- package/dist/core/runner/prepare-memory-engine-session.d.ts +2 -0
- package/dist/core/runner/prepare-memory-engine-session.js +4 -3
- package/dist/core/runner/prepare-memory.d.ts +6 -0
- package/dist/core/runner/prepare-memory.js +13 -13
- package/dist/core/runner/prepare-offload-wrappers.d.ts +5 -0
- package/dist/core/runner/prepare-offload-wrappers.js +3 -3
- package/dist/core/runner/prepare-park-ask.d.ts +7 -8
- package/dist/core/runner/prepare-park-ask.js +17 -10
- package/dist/core/runner/prepare-policy-chain.js +24 -44
- package/dist/core/runner/prepare-project-context.d.ts +1 -1
- package/dist/core/runner/prepare-project-context.js +3 -4
- package/dist/core/runner/prepare-protocol-tools.d.ts +9 -3
- package/dist/core/runner/prepare-protocol-tools.js +3 -4
- package/dist/core/runner/prepare-run-refs.d.ts +3 -0
- package/dist/core/runner/prepare-run-refs.js +2 -1
- package/dist/core/runner/prepare-safety-scan.d.ts +4 -8
- package/dist/core/runner/prepare-safety-scan.js +1 -2
- package/dist/core/runner/prepare-suspend-saga.d.ts +7 -1
- package/dist/core/runner/prepare-suspend-saga.js +28 -12
- package/dist/core/runner/prepare-task.d.ts +1 -1
- package/dist/core/runner/prepare-task.js +67 -56
- package/dist/core/runner/prepare-wiring-manifest.d.ts +11 -10
- package/dist/core/runner/prepare-wiring-manifest.js +5 -8
- package/dist/core/runner/resume-apply.js +7 -14
- package/dist/core/runner/resume-checkpoint-screen.js +11 -4
- package/dist/core/runner/resume-internals-and-config.js +2 -2
- package/dist/core/runner/resume-policy-outcome.js +5 -32
- package/dist/core/runner/resume-review-outcome.js +4 -1
- package/dist/core/runner/retired-runner-deps.d.ts +6 -0
- package/dist/core/runner/retired-runner-deps.js +10 -1
- package/dist/core/runner/run-brain-sinks.d.ts +4 -0
- package/dist/core/runner/run-brain-sinks.js +5 -2
- package/dist/core/runner/run-harness-handlers.js +29 -36
- package/dist/core/runner/run-leg.d.ts +0 -2
- package/dist/core/runner/run-leg.js +32 -33
- package/dist/core/runner/run-terminal-adoption.js +4 -3
- package/dist/core/runner/runtask.js +8 -8
- package/dist/core/runner/session-rule-policy.js +5 -5
- package/dist/core/runner/stream-settle-backstop.js +7 -4
- package/dist/core/runner/sub-agent-deny-lists.d.ts +51 -12
- package/dist/core/runner/sub-agent-deny-lists.js +111 -80
- package/dist/core/runner/terminal-account.d.ts +48 -0
- package/dist/core/runner/terminal-account.js +186 -0
- package/dist/core/runner/tool-end-body.d.ts +54 -17
- package/dist/core/runner/tool-end-body.js +27 -2
- package/dist/core/runner/tool-face-overlay.d.ts +3 -1
- package/dist/core/runner/tool-face-overlay.js +6 -4
- package/dist/core/runner/tool-occurrence.d.ts +106 -0
- package/dist/core/runner/tool-occurrence.js +123 -0
- package/dist/core/runner/tool-progress-lane.d.ts +16 -8
- package/dist/core/runner/tool-progress-lane.js +25 -34
- package/dist/core/runner/tool-turn-repair-seat.d.ts +28 -4
- package/dist/core/runner/tool-turn-repair-seat.js +36 -13
- package/dist/core/runner/turn-attachments.d.ts +1 -1
- package/dist/core/runner/write-protection-station.d.ts +21 -9
- package/dist/core/runner/write-protection-station.js +20 -17
- package/dist/core/runner-deps.d.ts +12 -22
- package/dist/core/secret-env.d.ts +16 -5
- package/dist/core/secret-env.js +23 -63
- package/dist/core/sensitive-path-policy.d.ts +19 -18
- package/dist/core/sensitive-path-policy.js +73 -49
- package/dist/core/session-reconcile.d.ts +3 -0
- package/dist/core/session-reconcile.js +5 -4
- package/dist/core/session-store.d.ts +5 -0
- package/dist/core/session-store.js +12 -0
- package/dist/core/session.d.ts +13 -0
- package/dist/core/shared-memory/normalize.d.ts +17 -4
- package/dist/core/shared-memory/normalize.js +7 -7
- package/dist/core/shell-lexer.js +5 -4
- package/dist/core/shell-wrapper-projection.js +1 -1
- package/dist/core/skill-grant.js +1 -1
- package/dist/core/store-contracts/checkpoint-store-contract.js +13 -0
- package/dist/core/store-contracts/mailbox-store-contract.d.ts +7 -14
- package/dist/core/store-contracts/session-store-incarnation-contract.d.ts +27 -0
- package/dist/core/store-contracts/session-store-incarnation-contract.js +92 -0
- package/dist/core/stub-env.d.ts +2 -0
- package/dist/core/stub-env.js +1 -0
- package/dist/core/synthetic-read-verdict.js +2 -2
- package/dist/core/task-event.d.ts +59 -5
- package/dist/core/task-result.d.ts +1 -1
- package/dist/core/task-spec.d.ts +42 -9
- package/dist/core/terminal-cause.d.ts +94 -11
- package/dist/core/tighten-task-spec.d.ts +5 -4
- package/dist/core/tighten-task-spec.js +20 -25
- package/dist/core/tool-catalog-entries.d.ts +5 -7
- package/dist/core/tool-catalog-entries.js +14 -15
- package/dist/core/tool-face.d.ts +47 -0
- package/dist/core/tool-face.js +5 -0
- package/dist/core/tool-model-gate.d.ts +5 -5
- package/dist/core/tool-name-aliases.d.ts +26 -2
- package/dist/core/tool-name-aliases.js +13 -0
- package/dist/core/tool-name-list.d.ts +30 -0
- package/dist/core/tool-name-list.js +55 -0
- package/dist/core/tool-name-readings.d.ts +1 -9
- package/dist/core/tool-name-readings.js +1 -3
- package/dist/core/tool-policy.d.ts +195 -85
- package/dist/core/tool-policy.js +165 -380
- package/dist/core/tool-registry.d.ts +44 -1
- package/dist/core/tool-registry.js +26 -0
- package/dist/core/tool-roster.d.ts +19 -1
- package/dist/core/tool-roster.js +21 -2
- package/dist/core/tool-spec-members.d.ts +45 -0
- package/dist/core/tool-spec-members.js +169 -0
- package/dist/core/tool-spec.d.ts +46 -8
- package/dist/core/tools.d.ts +6 -2
- package/dist/core/tools.js +8 -4
- package/dist/core/untrusted-egress.js +29 -26
- package/dist/core/untrusted-text.d.ts +13 -10
- package/dist/core/untrusted-text.js +6 -44
- package/dist/core/workflow-journal-store.d.ts +4 -1
- package/dist/core/write-protect.d.ts +65 -29
- package/dist/core/write-protect.js +235 -177
- package/dist/engine/compaction/compaction.d.ts +2 -2
- package/dist/engine/execution-env/node-execution-env.d.ts +5 -23
- package/dist/engine/execution-env/node-execution-env.js +16 -38
- package/dist/engine/execution-env/symlink-chain.d.ts +23 -0
- package/dist/engine/execution-env/symlink-chain.js +32 -0
- package/dist/engine/harness/types.d.ts +7 -0
- package/dist/engine/llm/tool-turns.d.ts +3 -0
- package/dist/engine/llm/tool-turns.js +1 -0
- package/dist/engine/llm/types.d.ts +59 -23
- package/dist/engine/loop/agent-loop.js +16 -2
- package/dist/engine/session/memory-repo.js +11 -3
- package/dist/engine/session/repo-utils.d.ts +8 -0
- package/dist/engine/session/repo-utils.js +13 -0
- package/dist/index.d.ts +20 -23
- package/dist/index.js +17 -20
- package/dist/internal/harness.d.ts +1 -1
- package/dist/internal/harness.js +1 -1
- package/dist/internal/llm.d.ts +2 -2
- package/dist/internal/llm.js +1 -1
- package/dist/orchestration/governance-baseline-validity.js +1 -1
- package/dist/orchestration/run-spec.js +3 -3
- package/dist/orchestration/run-workflow-tool.d.ts +16 -35
- package/dist/orchestration/run-workflow-tool.js +38 -78
- package/dist/orchestration/workflow-governance.d.ts +21 -25
- package/dist/orchestration/workflow-governance.js +38 -78
- package/dist/orchestration/workflow-primitives.d.ts +7 -22
- package/dist/orchestration/workflow-primitives.js +5 -12
- package/dist/orchestration/workflow-types.d.ts +1 -1
- package/dist/orchestration/workflow.d.ts +61 -11
- package/dist/orchestration/workflow.js +189 -117
- package/dist/scenarios/full-body.d.ts +1 -1
- package/dist/shell/lex.d.ts +0 -21
- package/dist/shell/lex.js +250 -68
- package/dist/shell/shell-words.d.ts +35 -0
- package/dist/shell/shell-words.js +65 -0
- package/dist/stores/file/checkpoint-store.d.ts +5 -5
- package/dist/stores/file/checkpoint-store.js +5 -2
- package/dist/stores/file/index.d.ts +0 -8
- package/dist/stores/file/index.js +0 -12
- package/dist/stores/file/session-store.d.ts +3 -0
- package/dist/stores/file/session-store.js +44 -19
- package/dist/tools/artifact/artifact-tool.js +2 -0
- package/dist/tools/fs/bash-program-position.d.ts +12 -4
- package/dist/tools/fs/bash-program-position.js +32 -9
- package/dist/tools/fs/bash-readonly-classifier.d.ts +1 -1
- package/dist/tools/fs/bash-readonly-classifier.js +8 -7
- package/dist/tools/fs/containment-face.d.ts +4 -0
- package/dist/tools/fs/containment-face.js +3 -0
- package/dist/tools/fs/fs-shared.d.ts +10 -0
- package/dist/tools/fs/fs-shared.js +18 -0
- package/dist/tools/fs/fs-write.js +4 -2
- package/dist/tools/fs/index.d.ts +1 -1
- package/dist/tools/fs/program-read-model.d.ts +46 -20
- package/dist/tools/fs/program-read-model.js +50 -20
- package/dist/tools/fs/program-read-model.rows.d.ts +0 -14
- package/dist/tools/fs/program-read-model.rows.js +16 -15
- package/dist/tools/fs/read-deny-home.d.ts +33 -47
- package/dist/tools/fs/read-deny-home.js +35 -49
- package/dist/tools/fs/read-deny.d.ts +23 -22
- package/dist/tools/fs/read-deny.js +114 -89
- package/dist/tools/fs/removal-targets.d.ts +56 -23
- package/dist/tools/fs/removal-targets.js +65 -87
- package/dist/tools/fs/safety.d.ts +29 -22
- package/dist/tools/fs/safety.js +17 -11
- package/dist/tools/fs/search.js +10 -8
- package/dist/tools/fs/shell-read-argv.js +1 -1
- package/dist/tools/fs/shell-read-bindings.d.ts +169 -37
- package/dist/tools/fs/shell-read-bindings.js +324 -86
- package/dist/tools/fs/shell-read-builtins.d.ts +35 -0
- package/dist/tools/fs/shell-read-builtins.js +43 -0
- package/dist/tools/fs/shell-read-check.d.ts +15 -1
- package/dist/tools/fs/shell-read-check.js +67 -43
- package/dist/tools/fs/shell-read-establish.js +6 -6
- package/dist/tools/fs/shell-read-functions.d.ts +22 -0
- package/dist/tools/fs/shell-read-functions.js +29 -0
- package/dist/tools/fs/shell-read-judge.d.ts +51 -18
- package/dist/tools/fs/shell-read-judge.js +40 -4
- package/dist/tools/fs/shell-read-plan.d.ts +12 -6
- package/dist/tools/fs/shell-read-plan.js +118 -113
- package/dist/tools/fs/shell-read-start.d.ts +29 -6
- package/dist/tools/fs/shell-read-start.js +16 -9
- package/dist/tools/fs/shell-read-word.js +4 -0
- package/dist/tools/fs/shell-read-workdir.d.ts +156 -0
- package/dist/tools/fs/shell-read-workdir.js +281 -0
- package/dist/tools/fs/shell-read-write-targets.d.ts +5 -2
- package/dist/tools/fs/shell-read-write-targets.js +14 -5
- package/dist/tools/fs/shell-reentry-text.d.ts +4 -6
- package/dist/tools/fs/shell-reentry-text.js +3 -11
- package/dist/tools/task-list.d.ts +1 -2
- package/dist/tools/web.js +1 -1
- package/package.json +4 -1
- package/test/export-surface.snapshot.json +107 -143
- package/wire-changes/core@7.49.0.json +4765 -0
- package/dist/agents/teacher.d.ts +0 -159
- package/dist/agents/teacher.js +0 -577
- package/dist/agents/team.d.ts +0 -226
- package/dist/agents/team.js +0 -257
- package/dist/core/strategy-store.d.ts +0 -238
- package/dist/core/strategy-store.js +0 -253
- package/dist/orchestration/builtin-workflows.d.ts +0 -133
- package/dist/orchestration/builtin-workflows.js +0 -159
- package/dist/scenarios/env.d.ts +0 -40
- package/dist/scenarios/env.js +0 -39
- package/dist/scenarios/scenario-registry.d.ts +0 -110
- package/dist/scenarios/scenario-registry.js +0 -140
- package/dist/scenarios/teacher-quickstart.d.ts +0 -40
- package/dist/scenarios/teacher-quickstart.js +0 -12
- package/dist/stores/cc/lockfile.d.ts +0 -10
- package/dist/stores/cc/lockfile.js +0 -98
- package/dist/stores/cc/mailbox-store.d.ts +0 -20
- package/dist/stores/cc/mailbox-store.js +0 -255
- package/dist/stores/cc/roster-adapter.d.ts +0 -12
- package/dist/stores/cc/roster-adapter.js +0 -117
- package/dist/stores/cc/sidecar-transcript.d.ts +0 -97
- package/dist/stores/cc/sidecar-transcript.js +0 -264
- package/dist/stores/cc/task-list-store.d.ts +0 -2
- package/dist/stores/cc/task-list-store.js +0 -125
- package/dist/stores/file/strategy-store.d.ts +0 -97
- package/dist/stores/file/strategy-store.js +0 -341
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { argvOf, lexShell, literalTildeSpelling, substitutionsInHeredocBody } from "../../shell/lex.js";
|
|
2
|
+
import { shellWordsOf } from "../../shell/shell-words.js";
|
|
2
3
|
import { isShellSyntaxWord, LOOP_LIST_HEADS, readProgramPosition } from "./bash-program-position.js";
|
|
3
4
|
import { declaredAttributes, programRow, readArgRoles } from "./program-read-model.js";
|
|
4
5
|
import { codeBodies } from "./shell-reentry-text.js";
|
|
6
|
+
import { BUILTIN_ENABLED, BUILTINS_ALL, ENABLE_BUILTIN, builtinKey, chainAvailability, enableBindings, isBuiltinKey, isDisabledValue, speaksFor } from "./shell-read-builtins.js";
|
|
5
7
|
export function judgedSpellingOf(v) {
|
|
6
8
|
if (v.glob !== true)
|
|
7
9
|
return undefined;
|
|
@@ -25,53 +27,62 @@ export const SHELL_INTEGER_VARIABLES = new Set([
|
|
|
25
27
|
"LISTMAX", "LOGCHECK", "PERIOD", "FUNCNEST", "UID", "EUID", "GID", "EGID", "REPORTTIME", "REPORTMEMORY", "DIRSTACKSIZE", "BAUD",
|
|
26
28
|
"ZLE_RPROMPT_INDENT", "MBEGIN", "MEND", "PPID", "ARGC", "ZSH_SUBSHELL", "TTYIDLE", "status",
|
|
27
29
|
]);
|
|
28
|
-
const SHELL_SET_VARIABLES = new Set(["
|
|
30
|
+
const SHELL_SET_VARIABLES = new Set(["REPLY", "OPTARG", "MAPFILE", "BASH_REMATCH", "PIPESTATUS", "FUNCNAME", "BASH_COMMAND", "BASH_SUBSHELL", "COPROC", "GROUPS", "SHELLOPTS", "BASHOPTS", "BASH_VERSINFO"]);
|
|
29
31
|
export function shellKeepsName(name) {
|
|
30
32
|
return SHELL_INTEGER_VARIABLES.has(name) || SHELL_SET_VARIABLES.has(name);
|
|
31
33
|
}
|
|
32
|
-
const
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
const
|
|
34
|
+
export const WORKING_DIRECTORY_NAMES = Object.freeze(["PWD", "OLDPWD"]);
|
|
35
|
+
const isWorkingDirectoryName = (name) => name === "PWD" || name === "OLDPWD";
|
|
36
|
+
const OPENING_WORDS = shellWordsOf("scope_open");
|
|
37
|
+
const CLOSING_WORDS = shellWordsOf("scope_close");
|
|
38
|
+
const SWITCHING_WORDS = shellWordsOf("scope_switch");
|
|
39
|
+
const GROUP_WORDS = shellWordsOf("group"), DEFINITION_WORDS = shellWordsOf("definition"), ITERATING_HEADS = shellWordsOf("loop_iterates"), BACKGROUND_WORDS = shellWordsOf("background");
|
|
40
|
+
export const SPECIAL_BUILTINS = new Set([":", ".", "break", "continue", "eval", "exec", "exit", "export", "readonly", "return", "set", "shift", "source", "times", "trap", "unset"]);
|
|
36
41
|
const IDENTIFIER = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
42
|
+
const LOCAL_DECLARATION = "local";
|
|
43
|
+
const FUNCTION_KEY_PREFIX = "()";
|
|
44
|
+
export const functionKey = (name) => FUNCTION_KEY_PREFIX + name;
|
|
45
|
+
const isFunctionKey = (name) => name.startsWith(FUNCTION_KEY_PREFIX);
|
|
46
|
+
const FUNCTION_DEFINED = [{ spelled: "defined" }];
|
|
47
|
+
const FUNCTION_ABSENT = [{ spelled: "absent" }];
|
|
48
|
+
const isDefinedValue = (v) => v.spelled === "defined";
|
|
37
49
|
const ATTRIBUTE_KINDS = { integer: "integer", transformed: "transformed", frozen: "frozen" };
|
|
38
50
|
const EVERY_ATTRIBUTE = Object.values(ATTRIBUTE_KINDS).map((kind) => ({ kind }));
|
|
39
51
|
export function projectSegment(segment) {
|
|
40
52
|
const tokens = [...segment.tokens];
|
|
41
53
|
let grouped = tokens.some((t) => t.kind === "group");
|
|
42
|
-
const
|
|
54
|
+
const defines = dropDefinitionHeads(tokens).flat();
|
|
43
55
|
dropCasePattern(tokens);
|
|
44
56
|
const words = tokens.filter((t) => {
|
|
45
57
|
if (t.kind !== "word")
|
|
46
58
|
return false;
|
|
47
|
-
if (t.raw === t.folded && (t.folded
|
|
59
|
+
if (t.raw === t.folded && GROUP_WORDS.has(t.folded)) {
|
|
48
60
|
grouped = true;
|
|
49
61
|
return false;
|
|
50
62
|
}
|
|
51
63
|
return true;
|
|
52
64
|
});
|
|
53
|
-
return { argv: words, redirects: tokens.filter((t) => t.kind === "redirect"), grouped,
|
|
65
|
+
return { argv: words, redirects: tokens.filter((t) => t.kind === "redirect"), grouped, defines };
|
|
54
66
|
}
|
|
55
67
|
function isDefinitionName(word) {
|
|
56
68
|
return IDENTIFIER.test(word.folded) || (word.atCommandPosition && word.expansions.length === 0 && !/[?*+@!]$/.test(word.raw));
|
|
57
69
|
}
|
|
58
70
|
export function dropDefinitionHeads(tokens) {
|
|
59
|
-
const heads =
|
|
60
|
-
const drop = (k, count) => {
|
|
71
|
+
const heads = Array.from({ length: tokens.length + 1 }, () => []);
|
|
72
|
+
const drop = (k, count, name) => {
|
|
61
73
|
tokens.splice(k, count);
|
|
62
74
|
heads.splice(k, count);
|
|
63
|
-
heads[k]
|
|
75
|
+
heads[k].push(name);
|
|
64
76
|
};
|
|
65
77
|
for (let k = 0; k + 1 < tokens.length; k++) {
|
|
66
78
|
const [a, b, c, d] = [tokens[k], tokens[k + 1], tokens[k + 2], tokens[k + 3]];
|
|
67
|
-
if (a.kind === "word" && a.raw
|
|
68
|
-
drop(k--, c?.kind === "group" && c.op === "(" && d?.kind === "group" && d.op === ")" ? 4 : 2);
|
|
69
|
-
}
|
|
79
|
+
if (a.kind === "word" && DEFINITION_WORDS.has(a.raw) && a.atCommandPosition && b.kind === "word")
|
|
80
|
+
drop(k--, c?.kind === "group" && c.op === "(" && d?.kind === "group" && d.op === ")" ? 4 : 2, b.folded);
|
|
70
81
|
}
|
|
71
82
|
for (let k = 0; k + 2 < tokens.length; k++) {
|
|
72
83
|
const [a, b, c] = [tokens[k], tokens[k + 1], tokens[k + 2]];
|
|
73
84
|
if (a.kind === "word" && b.kind === "group" && b.op === "(" && c.kind === "group" && c.op === ")" && isDefinitionName(a))
|
|
74
|
-
drop(k, 3);
|
|
85
|
+
drop(k, 3, a.folded);
|
|
75
86
|
}
|
|
76
87
|
return heads;
|
|
77
88
|
}
|
|
@@ -108,6 +119,8 @@ function extglobParen(tokens, at) {
|
|
|
108
119
|
function blockStructure(segments) {
|
|
109
120
|
let depth = 0;
|
|
110
121
|
let bodies = 0;
|
|
122
|
+
let subshellIds = 0;
|
|
123
|
+
const subshellStack = [];
|
|
111
124
|
const frames = [];
|
|
112
125
|
const deeper = () => {
|
|
113
126
|
depth++;
|
|
@@ -123,9 +136,13 @@ function blockStructure(segments) {
|
|
|
123
136
|
return segments.map((segment) => {
|
|
124
137
|
const tokens = [...segment.tokens];
|
|
125
138
|
const heads = dropDefinitionHeads(tokens);
|
|
139
|
+
const defs = [];
|
|
126
140
|
const startBodies = (k) => {
|
|
127
|
-
for (
|
|
141
|
+
for (const name of heads[k]) {
|
|
142
|
+
const enclosing = innermost();
|
|
143
|
+
defs.push({ name, standing: { ...(enclosing !== undefined ? { body: enclosing } : {}), subshells: [...subshellStack], depth } });
|
|
128
144
|
frames.push({ body: { id: bodies++, base: depth }, opened: false });
|
|
145
|
+
}
|
|
129
146
|
};
|
|
130
147
|
const arithmetic = isArithmeticCommand(segment);
|
|
131
148
|
const patternEnd = casePatternEnd(tokens);
|
|
@@ -133,6 +150,7 @@ function blockStructure(segments) {
|
|
|
133
150
|
const open = [];
|
|
134
151
|
let lowest = depth;
|
|
135
152
|
let words;
|
|
153
|
+
let subshells;
|
|
136
154
|
let body;
|
|
137
155
|
const switches = [];
|
|
138
156
|
const innermost = () => [...frames].reverse().find((f) => f.opened)?.body;
|
|
@@ -150,6 +168,7 @@ function blockStructure(segments) {
|
|
|
150
168
|
if (k <= patternEnd)
|
|
151
169
|
return;
|
|
152
170
|
deeper();
|
|
171
|
+
subshellStack.push(subshellIds++);
|
|
153
172
|
return;
|
|
154
173
|
}
|
|
155
174
|
const from = open.pop();
|
|
@@ -161,6 +180,7 @@ function blockStructure(segments) {
|
|
|
161
180
|
return;
|
|
162
181
|
}
|
|
163
182
|
shallower();
|
|
183
|
+
subshellStack.pop();
|
|
164
184
|
lowest = Math.min(lowest, depth);
|
|
165
185
|
return;
|
|
166
186
|
}
|
|
@@ -177,6 +197,7 @@ function blockStructure(segments) {
|
|
|
177
197
|
switches.push(depth);
|
|
178
198
|
else if (k > patternEnd) {
|
|
179
199
|
words ??= depth;
|
|
200
|
+
subshells ??= [...subshellStack];
|
|
180
201
|
body = innermost();
|
|
181
202
|
}
|
|
182
203
|
};
|
|
@@ -210,7 +231,7 @@ function blockStructure(segments) {
|
|
|
210
231
|
while (frames.length > 0 && frames[frames.length - 1].flat === true)
|
|
211
232
|
frames.pop();
|
|
212
233
|
startBodies(tokens.length);
|
|
213
|
-
return { words: words ?? depth, after: depth, lowest, switches, ...(body !== undefined ? { body } : {}) };
|
|
234
|
+
return { words: words ?? depth, after: depth, lowest, switches, subshells: subshells ?? [...subshellStack], defs, ...(body !== undefined ? { body } : {}) };
|
|
214
235
|
});
|
|
215
236
|
}
|
|
216
237
|
const READABLE_VALUE = /^[^\\~()]*$/;
|
|
@@ -403,9 +424,9 @@ export function loopListHeadAt(argv) {
|
|
|
403
424
|
const at = isShellSyntaxWord(argv[0], LOOP_LIST_HEADS) ? 0 : readProgramPosition(argv).written;
|
|
404
425
|
return at !== undefined && isShellSyntaxWord(argv[at], LOOP_LIST_HEADS) ? at : undefined;
|
|
405
426
|
}
|
|
406
|
-
export function bindingEffectOf(segment, argv, shape, readValue) {
|
|
427
|
+
export function bindingEffectOf(segment, argv, shape, readValue, shadow, availability) {
|
|
407
428
|
const bindings = [];
|
|
408
|
-
let all = shape.
|
|
429
|
+
let all = shape.defines.length > 0 ? "reset" : undefined;
|
|
409
430
|
const unknownAll = () => void (all = "unknown");
|
|
410
431
|
const overlay = new Map();
|
|
411
432
|
let scope;
|
|
@@ -415,6 +436,8 @@ export function bindingEffectOf(segment, argv, shape, readValue) {
|
|
|
415
436
|
overlay.set(b.name, b.state);
|
|
416
437
|
};
|
|
417
438
|
const kill = (name) => bind({ name, state: "unknown" });
|
|
439
|
+
for (const name of shape.defines)
|
|
440
|
+
bind({ name: functionKey(name), state: FUNCTION_DEFINED });
|
|
418
441
|
const nameOf = (w) => {
|
|
419
442
|
if (w.pieces.some((p) => p.expansion !== undefined || p.literal === undefined))
|
|
420
443
|
return "computed";
|
|
@@ -464,7 +487,7 @@ export function bindingEffectOf(segment, argv, shape, readValue) {
|
|
|
464
487
|
}
|
|
465
488
|
const inAt = argv.findIndex((w, i) => i >= loopAt + 2 && w.raw === "in");
|
|
466
489
|
let state = "unknown";
|
|
467
|
-
if (headWord
|
|
490
|
+
if (ITERATING_HEADS.has(headWord) && inAt === loopAt + 2 && argv.length > loopAt + 3) {
|
|
468
491
|
const values = [];
|
|
469
492
|
for (const w of argv.slice(loopAt + 3)) {
|
|
470
493
|
const v = readValue(w, false, overlay);
|
|
@@ -480,7 +503,7 @@ export function bindingEffectOf(segment, argv, shape, readValue) {
|
|
|
480
503
|
bind({ name, state, loopVar: true });
|
|
481
504
|
return { bindings, all };
|
|
482
505
|
}
|
|
483
|
-
if (argv[0]
|
|
506
|
+
if (argv[0] !== undefined && BACKGROUND_WORDS.has(argv[0].raw) && argv[1] !== undefined)
|
|
484
507
|
killNamed(nameOf(argv[1]));
|
|
485
508
|
const pos = readProgramPosition(argv);
|
|
486
509
|
const program = pos.program;
|
|
@@ -500,9 +523,20 @@ export function bindingEffectOf(segment, argv, shape, readValue) {
|
|
|
500
523
|
unknownAll();
|
|
501
524
|
return { bindings, all, attributes: EVERY_ATTRIBUTE, references: true };
|
|
502
525
|
}
|
|
503
|
-
if (program === undefined ||
|
|
526
|
+
if (program === undefined || shadow === "named")
|
|
527
|
+
return { bindings, all };
|
|
528
|
+
const settled = bindings.length;
|
|
529
|
+
const runsAsBuiltin = program.name === program.basename && pos.launchers.every((l, i) => (l.name === "builtin" || l.name === "command") && argv[l.index].folded === l.name && l.index + 1 === (pos.launchers[i + 1]?.index ?? program.index)) && !segment.tokens.some((t) => t.kind === "redirect" || t.kind === "heredoc");
|
|
530
|
+
const available = runsAsBuiltin ? chainAvailability([...pos.launchers.map((l) => l.name), program.basename], availability) : "enabled";
|
|
531
|
+
if (available === "disabled")
|
|
504
532
|
return { bindings, all };
|
|
533
|
+
const mayNotRun = shadow === "maybe" || available === "maybe" || (!runsAsBuiltin && (row?.builtin === "declaration" || program.basename === ENABLE_BUILTIN));
|
|
534
|
+
const finish = (e) => (mayNotRun ? { ...e, bindings: e.bindings.map((b, i) => (i < settled ? b : { ...b, prefix: true })) } : e);
|
|
505
535
|
const args = argv.slice(program.index + 1);
|
|
536
|
+
if (program.basename === ENABLE_BUILTIN)
|
|
537
|
+
return finish({ bindings: [...bindings, ...enableBindings(args)], all });
|
|
538
|
+
if (row === undefined)
|
|
539
|
+
return { bindings, all };
|
|
506
540
|
const folded = args.map((w) => w.folded);
|
|
507
541
|
if (row.reentry?.kind === "shell" && (row.reentry.text === "words" || row.reentry.text === "file-operand"))
|
|
508
542
|
unknownAll();
|
|
@@ -515,7 +549,7 @@ export function bindingEffectOf(segment, argv, shape, readValue) {
|
|
|
515
549
|
kill(name);
|
|
516
550
|
}
|
|
517
551
|
if (row.builtin === "declaration") {
|
|
518
|
-
scope = args.some((w) => w.folded.startsWith("-") || w.folded.startsWith("+")) ? "unread" : program.basename ===
|
|
552
|
+
scope = args.some((w) => w.folded.startsWith("-") || w.folded.startsWith("+")) ? "unread" : program.basename === LOCAL_DECLARATION ? "local" : undefined;
|
|
519
553
|
const assigns = declaredAttributes(row, folded);
|
|
520
554
|
const kinds = [...assigns].filter((k) => k !== "reference" && k !== "unsettled");
|
|
521
555
|
const storesText = [...assigns].every((k) => k === "frozen");
|
|
@@ -542,12 +576,19 @@ export function bindingEffectOf(segment, argv, shape, readValue) {
|
|
|
542
576
|
bind({ name, state: assignedState(a, readValue, expanded) });
|
|
543
577
|
attributes.push(...kinds.map((kind) => ({ name, kind })));
|
|
544
578
|
}
|
|
545
|
-
const inFunction = program.basename ===
|
|
579
|
+
const inFunction = program.basename === LOCAL_DECLARATION ? { inFunction: true } : {};
|
|
546
580
|
if (references) {
|
|
547
581
|
unknownAll();
|
|
548
|
-
return { bindings, all, attributes, references: true, ...inFunction };
|
|
582
|
+
return finish({ bindings, all, attributes, references: true, ...inFunction });
|
|
549
583
|
}
|
|
550
|
-
return { bindings, all, attributes, ...inFunction };
|
|
584
|
+
return finish({ bindings, all, attributes, ...inFunction });
|
|
585
|
+
}
|
|
586
|
+
if (program.basename === "unset") {
|
|
587
|
+
const { operands, variablesOnly } = unsetOperands(args);
|
|
588
|
+
if (!variablesOnly)
|
|
589
|
+
for (const w of operands)
|
|
590
|
+
if (w.pieces.every((p) => p.literal !== undefined && p.expansion === undefined))
|
|
591
|
+
bind({ name: functionKey(w.folded), state: FUNCTION_ABSENT, prefix: true });
|
|
551
592
|
}
|
|
552
593
|
for (const e of readArgRoles(row, folded)) {
|
|
553
594
|
const role = e.kind === "value" || e.kind === "operand" ? e.role : e.kind === "option" && typeof e.reading === "object" ? e.reading.role : undefined;
|
|
@@ -567,11 +608,32 @@ export function bindingEffectOf(segment, argv, shape, readValue) {
|
|
|
567
608
|
const nameLetters = new Set(row.grammars.flatMap((g) => Object.entries(g.short).flatMap(([letter, s]) => (s.value?.kind === "binds-name" ? [letter] : []))));
|
|
568
609
|
if (nameLetters.size > 0 && readArgRoles(row, folded).some((e) => e.kind === "option" && e.reading === "speculative" && [...folded[e.at].slice(1)].some((ch) => nameLetters.has(ch))))
|
|
569
610
|
unknownAll();
|
|
570
|
-
return { bindings, all };
|
|
611
|
+
return finish({ bindings, all });
|
|
571
612
|
}
|
|
572
613
|
function nameIn(text) {
|
|
573
614
|
return /^([A-Za-z_][A-Za-z0-9_]*)(?:\[.*\])?$/s.exec(text)?.[1];
|
|
574
615
|
}
|
|
616
|
+
function unsetOperands(args) {
|
|
617
|
+
let variables = false;
|
|
618
|
+
let otherwise = false;
|
|
619
|
+
let at = 0;
|
|
620
|
+
for (; at < args.length; at++) {
|
|
621
|
+
const w = args[at].folded;
|
|
622
|
+
if (w === "--") {
|
|
623
|
+
at++;
|
|
624
|
+
break;
|
|
625
|
+
}
|
|
626
|
+
if (!/^-./.test(w))
|
|
627
|
+
break;
|
|
628
|
+
for (const letter of w.slice(1)) {
|
|
629
|
+
if (letter === "v" || letter === "n")
|
|
630
|
+
variables = true;
|
|
631
|
+
else
|
|
632
|
+
otherwise = true;
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
return { operands: args.slice(at), variablesOnly: variables && !otherwise };
|
|
636
|
+
}
|
|
575
637
|
function compoundElementWords(raw) {
|
|
576
638
|
const inner = /^\(([\s\S]*)\)$/.exec(raw)?.[1];
|
|
577
639
|
const l = inner === undefined ? undefined : lexShell(inner);
|
|
@@ -637,6 +699,11 @@ export function textBindsHome(text) {
|
|
|
637
699
|
return names === "all" || names.has("HOME");
|
|
638
700
|
}
|
|
639
701
|
const NOTHING_INHERITED = { attributes: [], references: false };
|
|
702
|
+
export function joinRebound(a, b) {
|
|
703
|
+
if (a === "all" || b === "all")
|
|
704
|
+
return "all";
|
|
705
|
+
return new Set([...(a ?? []), ...(b ?? [])]);
|
|
706
|
+
}
|
|
640
707
|
export class BindingThread {
|
|
641
708
|
segments;
|
|
642
709
|
named;
|
|
@@ -644,47 +711,186 @@ export class BindingThread {
|
|
|
644
711
|
boundAnywhere;
|
|
645
712
|
loops;
|
|
646
713
|
homeStartsTouched;
|
|
714
|
+
inheritedFunctions;
|
|
647
715
|
entries = [];
|
|
716
|
+
localDeclarations = [];
|
|
648
717
|
attributesAt;
|
|
649
718
|
unreadable;
|
|
650
719
|
blocks;
|
|
651
|
-
|
|
720
|
+
ownSubshell;
|
|
652
721
|
startFloors;
|
|
653
|
-
|
|
722
|
+
startRebound;
|
|
723
|
+
bodyRuns = { limit: -1, environment: [] };
|
|
724
|
+
constructor(segments, named, initial, boundAnywhere, loops, homeStartsTouched = false, inherited = NOTHING_INHERITED, inheritedFunctions) {
|
|
654
725
|
this.segments = segments;
|
|
655
726
|
this.named = named;
|
|
656
727
|
this.initial = initial;
|
|
657
728
|
this.boundAnywhere = boundAnywhere;
|
|
658
729
|
this.loops = loops;
|
|
659
730
|
this.homeStartsTouched = homeStartsTouched;
|
|
731
|
+
this.inheritedFunctions = inheritedFunctions;
|
|
660
732
|
this.startFloors = inherited.floors ?? new Map();
|
|
733
|
+
this.startRebound = inherited.rebound ?? new Set();
|
|
661
734
|
this.blocks = blockStructure(segments);
|
|
662
|
-
this.
|
|
735
|
+
this.ownSubshell = segments.map((_, i) => segments[i + 1]?.connector === "|" || segments[i + 1]?.connector === "&");
|
|
663
736
|
this.unreadable = [...(inherited.references ? [{ at: -1 }] : []), ...named.flatMap((effect, at) => this.unreadableBy(effect, at))];
|
|
664
737
|
this.attributesAt = [...inherited.attributes.map((a) => ({ ...a, at: -1 })), ...named.flatMap((effect, at) => (effect.attributes ?? []).map((a) => ({ ...a, at })))];
|
|
665
738
|
}
|
|
666
739
|
inheritedAt(j) {
|
|
667
740
|
const holds = (at) => j === undefined || this.mayRunBefore(at, j);
|
|
741
|
+
const reaches = (e) => j === undefined || (this.mayRunBefore(e.at, j) && this.visible(e, j));
|
|
668
742
|
const floors = new Map(this.startFloors);
|
|
669
743
|
for (const e of this.entries)
|
|
670
744
|
if (e.name !== undefined && e.floor !== undefined && (j === undefined || e.at < j))
|
|
671
745
|
floors.set(e.name, [...(floors.get(e.name) ?? []), ...e.floor]);
|
|
746
|
+
let rebound = this.startRebound;
|
|
747
|
+
for (const e of this.entries)
|
|
748
|
+
if (e.state !== "reset" && reaches(e))
|
|
749
|
+
rebound = joinRebound(rebound, e.name === undefined ? "all" : [e.name]);
|
|
750
|
+
for (const u of this.unreadable)
|
|
751
|
+
if (j === undefined || this.lostAt(u, j))
|
|
752
|
+
rebound = joinRebound(rebound, u.name === undefined ? "all" : [u.name]);
|
|
753
|
+
rebound = joinRebound(rebound, this.boundLater(j));
|
|
672
754
|
return {
|
|
673
755
|
attributes: this.attributesAt.filter((x) => holds(x.at)).map(({ name, kind }) => (name !== undefined ? { name, kind } : { kind })),
|
|
674
756
|
references: this.unreadable.some((u) => u.name === undefined && u.body === undefined && holds(u.at)),
|
|
675
757
|
...(floors.size > 0 ? { floors } : {}),
|
|
758
|
+
rebound,
|
|
676
759
|
};
|
|
677
760
|
}
|
|
761
|
+
startOf(name) {
|
|
762
|
+
return isFunctionKey(name) ? this.inheritedFunctions?.start(name) ?? FUNCTION_ABSENT : isBuiltinKey(name) ? this.inheritedFunctions?.start(name) ?? BUILTIN_ENABLED : this.initial(name);
|
|
763
|
+
}
|
|
764
|
+
bindsInText(name) {
|
|
765
|
+
return this.named.some((effect) => effect.all === "unknown" || effect.bindings.some((b) => speaksFor(b.name, name)));
|
|
766
|
+
}
|
|
767
|
+
heldAnywhere() {
|
|
768
|
+
const start = (key) => {
|
|
769
|
+
const own = this.startOf(key);
|
|
770
|
+
if (own === "unknown")
|
|
771
|
+
return own;
|
|
772
|
+
const values = [...own];
|
|
773
|
+
for (const effect of this.named) {
|
|
774
|
+
if (effect.all === "unknown")
|
|
775
|
+
return "unknown";
|
|
776
|
+
for (const b of effect.bindings) {
|
|
777
|
+
if (!speaksFor(b.name, key))
|
|
778
|
+
continue;
|
|
779
|
+
if (b.state === "unknown")
|
|
780
|
+
return "unknown";
|
|
781
|
+
for (const v of b.state)
|
|
782
|
+
if (!values.some((x) => sameValue(x, v)))
|
|
783
|
+
values.push(v);
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
return values;
|
|
787
|
+
};
|
|
788
|
+
return { start, bound: new Set() };
|
|
789
|
+
}
|
|
790
|
+
runsBodies(runs, atEnd, environment) {
|
|
791
|
+
let limit = atEnd ? this.named.length - 1 : -1;
|
|
792
|
+
runs.forEach((r, si) => {
|
|
793
|
+
if (!r)
|
|
794
|
+
return;
|
|
795
|
+
limit = Math.max(limit, si);
|
|
796
|
+
for (const [head, end] of this.loops)
|
|
797
|
+
if (head <= si && si < end)
|
|
798
|
+
limit = Math.max(limit, end);
|
|
799
|
+
});
|
|
800
|
+
this.bodyRuns = { limit, environment };
|
|
801
|
+
const calling = new Set(runs.flatMap((r, si) => (r && this.blocks[si].body !== undefined ? [this.blocks[si].body.id] : [])));
|
|
802
|
+
this.named.forEach((effect, at) => {
|
|
803
|
+
for (const b of effect.bindings) {
|
|
804
|
+
const body = this.standingOf(at, b.name).body;
|
|
805
|
+
if (body !== undefined && calling.has(body.id))
|
|
806
|
+
this.unreadable.push({ at, name: b.name, body });
|
|
807
|
+
}
|
|
808
|
+
});
|
|
809
|
+
}
|
|
810
|
+
boundLater(j) {
|
|
811
|
+
const out = new Set();
|
|
812
|
+
if (j !== undefined && this.blocks[j].body === undefined)
|
|
813
|
+
return out;
|
|
814
|
+
const limit = j === undefined ? this.named.length - 1 : this.bodyRuns.limit;
|
|
815
|
+
for (let s = j === undefined ? 0 : j + 1; s <= limit; s++) {
|
|
816
|
+
const effect = this.named[s];
|
|
817
|
+
if (effect.all === "unknown" || effect.references === true)
|
|
818
|
+
return "all";
|
|
819
|
+
for (const b of effect.bindings)
|
|
820
|
+
out.add(b.name);
|
|
821
|
+
const environment = this.bodyRuns.environment[s];
|
|
822
|
+
if (environment === "all")
|
|
823
|
+
return "all";
|
|
824
|
+
for (const name of environment ?? [])
|
|
825
|
+
out.add(name);
|
|
826
|
+
}
|
|
827
|
+
return out;
|
|
828
|
+
}
|
|
829
|
+
ownSubshellAt(at, standing) {
|
|
830
|
+
return this.ownSubshell[at] === true && standing.depth >= this.blocks[at].after;
|
|
831
|
+
}
|
|
832
|
+
detachedAt(at, standing) {
|
|
833
|
+
return this.segments[at].connector === "|" || this.ownSubshellAt(at, standing);
|
|
834
|
+
}
|
|
835
|
+
visible(e, j) {
|
|
836
|
+
const reader = j === undefined ? undefined : this.blocks[j];
|
|
837
|
+
if (e.standing.body !== undefined && reader?.body?.id !== e.standing.body.id)
|
|
838
|
+
return false;
|
|
839
|
+
if (j !== e.at && this.ownSubshellAt(e.at, e.standing))
|
|
840
|
+
return false;
|
|
841
|
+
const around = reader?.subshells ?? [];
|
|
842
|
+
return e.standing.subshells.every((id) => around.includes(id));
|
|
843
|
+
}
|
|
844
|
+
standingOf(at, name) {
|
|
845
|
+
const own = this.blocks[at];
|
|
846
|
+
const head = name !== undefined && isFunctionKey(name) ? own.defs.find((d) => functionKey(d.name) === name) : undefined;
|
|
847
|
+
return head?.standing ?? { ...(own.body !== undefined ? { body: own.body } : {}), subshells: own.subshells, depth: own.words };
|
|
848
|
+
}
|
|
849
|
+
functionBound() {
|
|
850
|
+
const out = new Set();
|
|
851
|
+
if (this.inheritedFunctions?.bound === "all")
|
|
852
|
+
return "all";
|
|
853
|
+
for (const name of this.inheritedFunctions?.bound ?? [])
|
|
854
|
+
out.add(name);
|
|
855
|
+
for (let at = 0; at < this.named.length; at++) {
|
|
856
|
+
const effect = this.named[at];
|
|
857
|
+
if (this.blocks[at].body !== undefined && (effect.all === "unknown" || effect.references === true))
|
|
858
|
+
return "all";
|
|
859
|
+
for (const b of effect.bindings) {
|
|
860
|
+
const own = this.bodyBinding(b, at);
|
|
861
|
+
if (own !== undefined && (b.scope === "unread" || !this.declaredLocal(b.name, at, own)))
|
|
862
|
+
out.add(b.name);
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
return out;
|
|
866
|
+
}
|
|
867
|
+
bodyBinding(b, at) {
|
|
868
|
+
const own = this.standingOf(at, b.name).body;
|
|
869
|
+
return own !== undefined && b.scope !== "local" ? own : undefined;
|
|
870
|
+
}
|
|
871
|
+
inFunctionBody(at) {
|
|
872
|
+
return this.blocks[at].body !== undefined;
|
|
873
|
+
}
|
|
874
|
+
runsApart(at) {
|
|
875
|
+
return this.blocks[at].subshells.length > 0 || this.ownSubshell[at] === true || this.blocks[at].body !== undefined;
|
|
876
|
+
}
|
|
877
|
+
runsLater(at, names) {
|
|
878
|
+
if (names === "all")
|
|
879
|
+
this.unreadable.push({ at });
|
|
880
|
+
else
|
|
881
|
+
for (const name of names)
|
|
882
|
+
this.unreadable.push({ at, name });
|
|
883
|
+
}
|
|
678
884
|
unreadableBy(effect, at) {
|
|
679
885
|
const body = this.blocks[at].body;
|
|
680
886
|
const out = [];
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
if (effect.all === "unknown")
|
|
686
|
-
out.push({ at, body });
|
|
887
|
+
for (const b of effect.bindings) {
|
|
888
|
+
const own = this.bodyBinding(b, at);
|
|
889
|
+
if (own !== undefined)
|
|
890
|
+
out.push({ at, name: b.name, body: own });
|
|
687
891
|
}
|
|
892
|
+
if (body !== undefined && effect.all === "unknown")
|
|
893
|
+
out.push({ at, body });
|
|
688
894
|
if (effect.references === true)
|
|
689
895
|
out.push({ at });
|
|
690
896
|
return out;
|
|
@@ -695,107 +901,139 @@ export class BindingThread {
|
|
|
695
901
|
return this.blocks[e].body !== undefined || [...this.loops].some(([head, end]) => head <= e && x < end);
|
|
696
902
|
}
|
|
697
903
|
declaredLocal(name, at, body) {
|
|
698
|
-
|
|
699
|
-
const connector = this.segments[k].connector;
|
|
700
|
-
if (this.blocks[k].body?.id !== body.id || this.detached[k] === true || connector === "&&" || connector === "||")
|
|
701
|
-
continue;
|
|
702
|
-
if (this.named[k].bindings.some((b) => b.scope === "local" && b.name === name) && this.heldThrough(k, at))
|
|
703
|
-
return true;
|
|
704
|
-
}
|
|
705
|
-
return false;
|
|
904
|
+
return this.localDeclarations.some((d) => d.body === body.id && d.name === name && d.at < at && this.heldThrough(d, at));
|
|
706
905
|
}
|
|
707
|
-
heldThrough(
|
|
708
|
-
const depth =
|
|
709
|
-
if (this.blocks[at].after < depth)
|
|
906
|
+
heldThrough(e, j) {
|
|
907
|
+
const depth = e.standing.depth;
|
|
908
|
+
if (this.blocks[e.at].after < depth)
|
|
710
909
|
return false;
|
|
711
|
-
for (let k = at + 1; k <= j; k++)
|
|
910
|
+
for (let k = e.at + 1; k <= j; k++)
|
|
712
911
|
if (this.blocks[k].lowest < depth || this.blocks[k].switches.includes(depth))
|
|
713
912
|
return false;
|
|
714
913
|
return true;
|
|
715
914
|
}
|
|
716
915
|
apply(at, effect, andRun, loopEnd) {
|
|
717
|
-
const
|
|
718
|
-
const refused = effect.inFunction === true &&
|
|
916
|
+
const body = this.blocks[at].body;
|
|
917
|
+
const refused = effect.inFunction === true && body === undefined;
|
|
719
918
|
if (effect.all !== undefined)
|
|
720
|
-
this.entries.push({ at, state: effect.all === "reset" ? "reset" : "unknown", detached: false, andRun: false });
|
|
919
|
+
this.entries.push({ at, standing: this.standingOf(at), state: effect.all === "reset" ? "reset" : "unknown", detached: false, andRun: false });
|
|
721
920
|
for (const b of effect.bindings) {
|
|
921
|
+
const standing = this.standingOf(at, b.name);
|
|
922
|
+
const detached = this.detachedAt(at, standing) || b.prefix === true;
|
|
722
923
|
this.entries.push({
|
|
723
|
-
at, name: b.name, state: refused ? "unknown" : b.state, detached
|
|
924
|
+
at, standing, name: b.name, state: refused ? "unknown" : b.state, detached, andRun,
|
|
724
925
|
...(b.loopVar === true && loopEnd !== undefined ? { certainUntil: loopEnd } : {}),
|
|
725
926
|
...(b.floor !== undefined && b.floor.length > 0 ? { floor: b.floor } : {}),
|
|
726
927
|
});
|
|
928
|
+
if (b.scope === "local" && body !== undefined && !refused && !detached && !andRun)
|
|
929
|
+
this.localDeclarations.push({ at, name: b.name, body: body.id, standing });
|
|
727
930
|
}
|
|
728
931
|
}
|
|
729
|
-
|
|
730
|
-
if (
|
|
731
|
-
return
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
return true;
|
|
735
|
-
return false;
|
|
932
|
+
lostAt(u, j) {
|
|
933
|
+
if (u.body === undefined)
|
|
934
|
+
return this.mayRunBefore(u.at, j);
|
|
935
|
+
const readerBody = this.blocks[j].body;
|
|
936
|
+
return readerBody !== undefined && readerBody.id !== u.body.id;
|
|
736
937
|
}
|
|
737
938
|
kill(at, names) {
|
|
939
|
+
const standing = this.standingOf(at);
|
|
738
940
|
if (names === "all") {
|
|
739
|
-
this.entries.push({ at, state: "unknown", detached: false, andRun: false });
|
|
941
|
+
this.entries.push({ at, standing, state: "unknown", detached: false, andRun: false });
|
|
740
942
|
return;
|
|
741
943
|
}
|
|
742
944
|
for (const name of names)
|
|
743
|
-
this.entries.push({ at, name, state: "unknown", detached: false, andRun: false });
|
|
945
|
+
this.entries.push({ at, standing, name, state: "unknown", detached: false, andRun: false });
|
|
744
946
|
}
|
|
745
|
-
tableAt(j, andRunStart) {
|
|
947
|
+
tableAt(j, andRunStart, where) {
|
|
746
948
|
const certain = (e) => {
|
|
747
949
|
if (e.certainUntil !== undefined && j < e.certainUntil)
|
|
748
950
|
return true;
|
|
749
|
-
if (e.detached || !this.heldThrough(e
|
|
951
|
+
if (e.detached || !this.heldThrough(e, j))
|
|
750
952
|
return false;
|
|
751
953
|
return !e.andRun || e.at >= andRunStart;
|
|
752
954
|
};
|
|
753
955
|
const readerBody = this.blocks[j].body;
|
|
754
|
-
const lost = (u) =>
|
|
755
|
-
|
|
756
|
-
return this.mayRunBefore(u.at, j);
|
|
757
|
-
if (readerBody !== undefined && readerBody.id !== u.body.id)
|
|
758
|
-
return true;
|
|
759
|
-
return u.at < j && this.leftBody(u.at, u.body, j);
|
|
760
|
-
};
|
|
761
|
-
const before = (e) => e.at < j || (e.at === j && e.state === "reset");
|
|
956
|
+
const lost = (u) => this.lostAt(u, j);
|
|
957
|
+
const before = (e) => (e.at < j || (e.at === j && e.state === "reset")) && this.visible(e, j);
|
|
762
958
|
const given = (name, at, integer) => this.attributesAt.some((x) => (x.name === undefined || x.name === name) && (integer !== true || x.kind === "integer") && x.at !== at && this.mayRunBefore(x.at, at));
|
|
763
|
-
const
|
|
764
|
-
if (shellKeepsName(name))
|
|
765
|
-
return "unknown";
|
|
766
|
-
if (this.unreadable.some((u) => (u.name === undefined || u.name === name) && lost(u)))
|
|
767
|
-
return "unknown";
|
|
959
|
+
const walk = (name, start) => {
|
|
768
960
|
const values = [];
|
|
769
961
|
const add = (vs) => { for (const v of vs)
|
|
770
962
|
if (!values.some((x) => sameValue(x, v)))
|
|
771
963
|
values.push(v); };
|
|
772
964
|
for (let i = this.entries.length - 1; i >= 0; i--) {
|
|
773
965
|
const e = this.entries[i];
|
|
774
|
-
if (!before(e) || (e.name !== undefined && e.name
|
|
966
|
+
if (!before(e) || (e.name !== undefined && !speaksFor(e.name, name)))
|
|
775
967
|
continue;
|
|
776
|
-
|
|
968
|
+
if (e.state === "reset" && isBuiltinKey(name))
|
|
969
|
+
continue;
|
|
970
|
+
const state = e.state === "reset" ? ((name === "HOME" && this.boundAnywhere("HOME")) || this.bindsInText(name) ? "unknown" : this.initial(name)) : e.state;
|
|
777
971
|
if (state === "unknown")
|
|
778
|
-
return "unknown";
|
|
972
|
+
return { state: "unknown" };
|
|
779
973
|
if (e.name !== undefined && given(e.name, e.at))
|
|
780
|
-
return "unknown";
|
|
974
|
+
return { state: "unknown" };
|
|
781
975
|
add(state);
|
|
782
976
|
if (certain(e))
|
|
783
|
-
return values;
|
|
977
|
+
return { state: values, decided: e };
|
|
784
978
|
}
|
|
785
|
-
const start = this.initial(name);
|
|
786
979
|
if (start === "unknown")
|
|
787
|
-
return "unknown";
|
|
980
|
+
return { state: "unknown" };
|
|
788
981
|
add(start);
|
|
789
|
-
return values;
|
|
982
|
+
return { state: values };
|
|
983
|
+
};
|
|
984
|
+
const later = this.boundLater(j);
|
|
985
|
+
const boundLater = (name) => later === "all" || later.has(name) || (isBuiltinKey(name) && later.has(BUILTINS_ALL));
|
|
986
|
+
const stateOf = (name) => {
|
|
987
|
+
if (shellKeepsName(name))
|
|
988
|
+
return "unknown";
|
|
989
|
+
if (this.unreadable.some((u) => speaksFor(u.name, name) && lost(u)))
|
|
990
|
+
return "unknown";
|
|
991
|
+
if (!isWorkingDirectoryName(name)) {
|
|
992
|
+
const walked = walk(name, this.startOf(name));
|
|
993
|
+
const own = walked.decided !== undefined && walked.decided.state !== "reset" && readerBody !== undefined && walked.decided.standing.body?.id === readerBody.id;
|
|
994
|
+
return boundLater(name) && !own ? "unknown" : walked.state;
|
|
995
|
+
}
|
|
996
|
+
if (boundLater(name))
|
|
997
|
+
return "unknown";
|
|
998
|
+
const assigned = walk(name, []);
|
|
999
|
+
if (assigned.decided !== undefined && where !== undefined && readerBody === undefined && assigned.decided.at > where.movedAt)
|
|
1000
|
+
return assigned.state;
|
|
1001
|
+
const thread = readerBody === undefined ? where?.[name] ?? "unknown" : "unknown";
|
|
1002
|
+
if (thread === "unknown" || assigned.state === "unknown")
|
|
1003
|
+
return "unknown";
|
|
1004
|
+
const held = assigned.state;
|
|
1005
|
+
return [...held, ...thread.filter((v) => !held.some((x) => sameValue(x, v)))];
|
|
790
1006
|
};
|
|
791
1007
|
const touched = (name) => this.entries.some((e) => before(e) && (e.name === undefined || e.name === name));
|
|
1008
|
+
let rebound = this.startRebound;
|
|
1009
|
+
for (const e of this.entries)
|
|
1010
|
+
if (e.state !== "reset" && (readerBody !== undefined ? e.at !== j : before(e)))
|
|
1011
|
+
rebound = joinRebound(rebound, e.name === undefined ? "all" : [e.name]);
|
|
1012
|
+
for (const u of this.unreadable)
|
|
1013
|
+
if (lost(u))
|
|
1014
|
+
rebound = joinRebound(rebound, u.name === undefined ? "all" : [u.name]);
|
|
1015
|
+
const settled = joinRebound(rebound, later);
|
|
792
1016
|
return {
|
|
793
1017
|
stateOf,
|
|
794
1018
|
isInteger: (name) => SHELL_INTEGER_VARIABLES.has(name) || given(name, j, true),
|
|
795
|
-
ifsTouched: touched("IFS"),
|
|
796
|
-
homeTouched: this.homeStartsTouched || touched("HOME"),
|
|
1019
|
+
ifsTouched: touched("IFS") || boundLater("IFS"),
|
|
1020
|
+
homeTouched: this.homeStartsTouched || touched("HOME") || boundLater("HOME"),
|
|
797
1021
|
floorOf: (name) => [...(this.startFloors.get(name) ?? []), ...this.entries.filter((e) => e.at < j && e.name === name).flatMap((e) => e.floor ?? [])],
|
|
798
1022
|
inherited: this.inheritedAt(j),
|
|
1023
|
+
rebound: settled,
|
|
1024
|
+
providedByShell: (name) => settled !== "all" && !settled.has(name),
|
|
1025
|
+
functionState: (name) => {
|
|
1026
|
+
const held = stateOf(functionKey(name));
|
|
1027
|
+
if (held === "unknown")
|
|
1028
|
+
return "maybe";
|
|
1029
|
+
return !held.some(isDefinedValue) ? "absent" : held.length > 1 ? "maybe" : "defined";
|
|
1030
|
+
},
|
|
1031
|
+
builtinState: (name) => {
|
|
1032
|
+
const held = stateOf(builtinKey(name));
|
|
1033
|
+
if (held === "unknown")
|
|
1034
|
+
return "maybe";
|
|
1035
|
+
return held.every(isDisabledValue) ? "disabled" : held.some(isDisabledValue) ? "maybe" : "enabled";
|
|
1036
|
+
},
|
|
799
1037
|
};
|
|
800
1038
|
}
|
|
801
1039
|
}
|