@andorra-labs/code 0.1.7 → 0.1.9
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/README.md +3 -3
- package/THIRD_PARTY_NOTICES.md +2 -1
- package/dist/src/account-presentation.d.ts +11 -0
- package/dist/src/account-presentation.js +29 -2
- package/dist/src/agent-execution.js +83 -19
- package/dist/src/agent-mcp.d.ts +12 -0
- package/dist/src/agent-mcp.js +81 -2
- package/dist/src/app-server/protocol.d.ts +19 -1
- package/dist/src/app-server/protocol.js +4 -1
- package/dist/src/app-server/reasoning.d.ts +0 -8
- package/dist/src/app-server/reasoning.js +15 -28
- package/dist/src/app-server.d.ts +45 -0
- package/dist/src/app-server.js +341 -62
- package/dist/src/auth/AuthManager.d.ts +15 -0
- package/dist/src/auth/AuthManager.js +66 -7
- package/dist/src/auth/deployment.d.ts +6 -0
- package/dist/src/auth/deployment.js +8 -2
- package/dist/src/automation-service.d.ts +7 -2
- package/dist/src/automation-service.js +12 -19
- package/dist/src/background-tasks.d.ts +40 -0
- package/dist/src/background-tasks.js +54 -0
- package/dist/src/browser-runner.js +1 -2
- package/dist/src/browser-server.js +10 -2
- package/dist/src/browser-session.js +6 -2
- package/dist/src/browser-stealth.d.ts +29 -0
- package/dist/src/browser-stealth.js +166 -0
- package/dist/src/browser-ui/app.js +108 -13
- package/dist/src/browser-ui/icons/chevron-right.svg +8 -0
- package/dist/src/browser-ui/index.html +8 -8
- package/dist/src/browser-ui/style.css +199 -171
- package/dist/src/browser-ui/tokens.css +198 -0
- package/dist/src/browser-view.d.ts +67 -9
- package/dist/src/browser-view.js +209 -36
- package/dist/src/claude-provider.d.ts +8 -0
- package/dist/src/claude-provider.js +133 -24
- package/dist/src/cli.js +72 -4
- package/dist/src/code-intelligence/CodeIntelligenceManager.d.ts +21 -0
- package/dist/src/code-intelligence/CodeIntelligenceManager.js +51 -0
- package/dist/src/coding-tools.js +175 -8
- package/dist/src/command-screens.js +4 -4
- package/dist/src/commands.d.ts +1 -1
- package/dist/src/commands.js +4 -3
- package/dist/src/completion-gates.d.ts +35 -0
- package/dist/src/completion-gates.js +25 -0
- package/dist/src/completion.d.ts +6 -0
- package/dist/src/completion.js +85 -3
- package/dist/src/config.d.ts +13 -4
- package/dist/src/config.js +34 -39
- package/dist/src/context-budget.d.ts +11 -0
- package/dist/src/context-budget.js +13 -0
- package/dist/src/decision/DecisionEngine.d.ts +5 -1
- package/dist/src/decision/DecisionManager.d.ts +1 -0
- package/dist/src/decision/DecisionManager.js +14 -3
- package/dist/src/decision/FactContinuations.d.ts +6 -0
- package/dist/src/decision/FactContinuations.js +9 -1
- package/dist/src/decision/FactServiceGate.js +1 -1
- package/dist/src/decision/hostedSkills.d.ts +37 -0
- package/dist/src/decision/hostedSkills.js +64 -0
- package/dist/src/decision/providers/AndorraDecisionProvider.d.ts +10 -2
- package/dist/src/decision/providers/AndorraDecisionProvider.js +121 -10
- package/dist/src/default-graph.d.ts +11 -0
- package/dist/src/default-graph.js +20 -0
- package/dist/src/duration.d.ts +13 -2
- package/dist/src/duration.js +27 -3
- package/dist/src/extensions.d.ts +2 -0
- package/dist/src/extensions.js +42 -22
- package/dist/src/firefox-cookies.d.ts +78 -0
- package/dist/src/firefox-cookies.js +261 -0
- package/dist/src/graph-health.d.ts +10 -0
- package/dist/src/graph-health.js +5 -0
- package/dist/src/graph-manager-chat.d.ts +302 -0
- package/dist/src/graph-manager-chat.js +940 -0
- package/dist/src/graph-runner.js +14 -1
- package/dist/src/graph-server.d.ts +9 -0
- package/dist/src/graph-server.js +167 -16
- package/dist/src/graph-studio-features.js +2 -2
- package/dist/src/graph-sync.js +5 -2
- package/dist/src/graph-ui/app.js +252 -71
- package/dist/src/graph-ui/controls.css +55 -32
- package/dist/src/graph-ui/controls.js +85 -9
- package/dist/src/graph-ui/edge-router.js +114 -13
- package/dist/src/graph-ui/embed.js +23 -8
- package/dist/src/graph-ui/index.html +3 -3
- package/dist/src/graph-ui/library.css +4 -10
- package/dist/src/graph-ui/manager-markdown.js +155 -0
- package/dist/src/graph-ui/manager-state.js +191 -0
- package/dist/src/graph-ui/manager.css +161 -0
- package/dist/src/graph-ui/manager.js +700 -0
- package/dist/src/graph-ui/studio-canvas.js +2 -0
- package/dist/src/graph-ui/studio.css +24 -23
- package/dist/src/graph-ui/studio.js +29 -8
- package/dist/src/graph-ui/style.css +125 -92
- package/dist/src/graph-ui/tokens.css +217 -151
- package/dist/src/graphs.d.ts +69 -1
- package/dist/src/graphs.js +160 -7
- package/dist/src/hardened-runtime.d.ts +7 -2
- package/dist/src/hardened-runtime.js +32 -14
- package/dist/src/host-process-guard.d.ts +62 -0
- package/dist/src/host-process-guard.js +2859 -0
- package/dist/src/mcp.d.ts +55 -2
- package/dist/src/mcp.js +360 -88
- package/dist/src/membership-errors.d.ts +14 -0
- package/dist/src/membership-errors.js +24 -1
- package/dist/src/membership.d.ts +20 -0
- package/dist/src/membership.js +45 -16
- package/dist/src/memory/MemoryManager.js +7 -13
- package/dist/src/memory/MemoryProvider.d.ts +1 -1
- package/dist/src/memory/index.d.ts +0 -2
- package/dist/src/memory/index.js +0 -2
- package/dist/src/memory/repository.d.ts +1 -1
- package/dist/src/memory/repository.js +2 -2
- package/dist/src/memory/types.d.ts +1 -8
- package/dist/src/memory/types.js +1 -1
- package/dist/src/model-health-cache.d.ts +62 -0
- package/dist/src/model-health-cache.js +161 -0
- package/dist/src/palette.d.ts +25 -8
- package/dist/src/palette.js +26 -8
- package/dist/src/provider-engine.d.ts +25 -4
- package/dist/src/provider-engine.js +102 -27
- package/dist/src/provider-settings.js +1 -1
- package/dist/src/providers.d.ts +46 -0
- package/dist/src/providers.js +126 -32
- package/dist/src/qa/guidance.d.ts +26 -0
- package/dist/src/qa/guidance.js +59 -0
- package/dist/src/qa/index.d.ts +4 -8
- package/dist/src/qa/index.js +4 -16
- package/dist/src/qa/qa-authorize.js +6 -0
- package/dist/src/qa/runtime/ProcessManager.d.ts +30 -2
- package/dist/src/qa/runtime/ProcessManager.js +89 -14
- package/dist/src/qa/runtime/PtyManager.d.ts +9 -0
- package/dist/src/qa/runtime/PtyManager.js +18 -0
- package/dist/src/qa/runtime/changes.d.ts +15 -0
- package/dist/src/qa/runtime/changes.js +15 -0
- package/dist/src/qa/tools.js +4 -0
- package/dist/src/react-runtime.d.ts +11 -0
- package/dist/src/react-runtime.js +212 -56
- package/dist/src/remote/engine-pool.js +7 -2
- package/dist/src/remote/network.js +1 -1
- package/dist/src/run-control.d.ts +9 -0
- package/dist/src/run-control.js +15 -0
- package/dist/src/run-progress.d.ts +6 -0
- package/dist/src/run-progress.js +7 -0
- package/dist/src/runtime.d.ts +9 -1
- package/dist/src/runtime.js +2 -1
- package/dist/src/session-skills.d.ts +75 -0
- package/dist/src/session-skills.js +151 -0
- package/dist/src/side-panel.d.ts +1 -1
- package/dist/src/side-panel.js +6 -12
- package/dist/src/skill-commands.js +1 -1
- package/dist/src/skills/bundled/control-browser/SKILL.md +9 -1
- package/dist/src/skills/bundled/create-skill/SKILL.md +17 -3
- package/dist/src/skills/bundled/diagram/SKILL.md +144 -0
- package/dist/src/skills/bundled/graph-manager/SKILL.md +11 -1
- package/dist/src/skills/bundled/manage-skills/SKILL.md +6 -1
- package/dist/src/skills/bundled/provenance.json +10 -5
- package/dist/src/skills/bundled/web-gui-tester/SKILL.md +1 -1
- package/dist/src/skills/runtime-skills.d.ts +7 -0
- package/dist/src/skills/runtime-skills.js +12 -3
- package/dist/src/stall-recovery.d.ts +22 -0
- package/dist/src/stall-recovery.js +71 -0
- package/dist/src/subagent-run.js +2 -3
- package/dist/src/terminal-ui.d.ts +2 -2
- package/dist/src/terminal-ui.js +18 -13
- package/dist/src/tool-availability.d.ts +16 -0
- package/dist/src/tool-availability.js +28 -0
- package/dist/src/transcript.js +9 -1
- package/dist/src/types.d.ts +37 -9
- package/dist/src/update-check.d.ts +35 -0
- package/dist/src/update-check.js +104 -0
- package/dist/src/usage-analytics.d.ts +13 -0
- package/dist/src/usage-analytics.js +99 -16
- package/dist/src/web-search.d.ts +6 -0
- package/dist/src/web-search.js +12 -0
- package/dist/src/workspace-instructions.d.ts +10 -0
- package/dist/src/workspace-instructions.js +26 -21
- package/dist/vendor/engine/provenance.json +3088 -17923
- package/dist/vendor/engine/runtime/agent/types.d.ts +1 -1
- package/dist/vendor/engine/runtime/ai/types.d.ts +8 -14
- package/dist/vendor/engine/runtime/coding-agent/core/tools/bash.d.ts +2 -2
- package/dist/vendor/engine/runtime/coding-agent/core/tools/bash.js +2 -2
- package/dist/vendor/engine/runtime/coding-agent/core/tools/edit.d.ts +3 -4
- package/dist/vendor/engine/runtime/coding-agent/core/tools/edit.js +0 -3
- package/dist/vendor/engine/runtime/coding-agent/core/tools/find.d.ts +2 -2
- package/dist/vendor/engine/runtime/coding-agent/core/tools/find.js +0 -2
- package/dist/vendor/engine/runtime/coding-agent/core/tools/grep.d.ts +2 -2
- package/dist/vendor/engine/runtime/coding-agent/core/tools/grep.js +0 -2
- package/dist/vendor/engine/runtime/coding-agent/core/tools/index.d.ts +2 -2
- package/dist/vendor/engine/runtime/coding-agent/core/tools/ls.d.ts +2 -2
- package/dist/vendor/engine/runtime/coding-agent/core/tools/ls.js +0 -2
- package/dist/vendor/engine/runtime/coding-agent/core/tools/read.d.ts +3 -3
- package/dist/vendor/engine/runtime/coding-agent/core/tools/read.js +0 -2
- package/dist/vendor/engine/runtime/coding-agent/core/tools/tool-definition-wrapper.d.ts +2 -2
- package/dist/vendor/engine/runtime/coding-agent/core/tools/tool-definition.d.ts +40 -0
- package/dist/vendor/engine/runtime/coding-agent/core/tools/write.d.ts +2 -2
- package/dist/vendor/engine/runtime/coding-agent/core/tools/write.js +0 -2
- package/docs/README.md +1 -1
- package/docs/agents/README.md +5 -5
- package/docs/agents/install-for-agents.md +7 -6
- package/docs/agents/mcp-server.md +4 -4
- package/docs/agents/subagent-mode.md +6 -6
- package/docs/concepts/README.md +3 -3
- package/docs/concepts/jev-efficiency.md +2 -1
- package/docs/concepts/limits.md +12 -3
- package/docs/concepts/memory.md +5 -25
- package/docs/concepts/security.md +13 -5
- package/docs/concepts/workspace-instructions.md +3 -2
- package/docs/getting-started/README.md +3 -3
- package/docs/getting-started/accounts.md +4 -4
- package/docs/getting-started/configure-providers.md +4 -2
- package/docs/guides/browser.md +13 -1
- package/docs/guides/desktop-app.md +71 -18
- package/docs/guides/extensions.md +4 -2
- package/docs/guides/graph-builder.md +17 -2
- package/docs/guides/headless.md +5 -4
- package/docs/guides/update.md +3 -1
- package/docs/guides/web-search.md +6 -2
- package/docs/guides/windows-code-signing.md +13 -10
- package/docs/llms.txt +2 -2
- package/docs/reference/cli.md +9 -4
- package/docs/reference/config.md +14 -8
- package/docs/reference/slash-commands.md +6 -2
- package/docs/superpowers/plans/2026-11-13-graph-manager-chat.md +203 -0
- package/docs/superpowers/plans/2026-11-14-jev-fair-use-pricing.md +79 -0
- package/docs/superpowers/specs/2026-11-13-graph-manager-chat-design.md +182 -0
- package/docs/superpowers/specs/2026-11-14-jev-fair-use-pricing-design.md +156 -0
- package/package.json +3 -22
- package/tests/chat-side-panel-test-plan.md +1 -1
- package/tests/harness-extensions-test-plan.md +4 -1
- package/dist/src/memory/providers/graphiti/GraphitiClient.d.ts +0 -27
- package/dist/src/memory/providers/graphiti/GraphitiClient.js +0 -76
- package/dist/src/memory/providers/graphiti/GraphitiMapper.d.ts +0 -6
- package/dist/src/memory/providers/graphiti/GraphitiMapper.js +0 -116
- package/dist/src/memory/providers/graphiti/GraphitiMemoryProvider.d.ts +0 -27
- package/dist/src/memory/providers/graphiti/GraphitiMemoryProvider.js +0 -137
- package/dist/src/memory/providers/graphiti/GraphitiTypes.d.ts +0 -57
- package/dist/src/memory/providers/graphiti/GraphitiTypes.js +0 -2
- package/dist/vendor/engine/runtime/agent/agent-loop.d.ts +0 -23
- package/dist/vendor/engine/runtime/agent/agent-loop.js +0 -601
- package/dist/vendor/engine/runtime/agent/agent.d.ts +0 -130
- package/dist/vendor/engine/runtime/agent/agent.js +0 -430
- package/dist/vendor/engine/runtime/agent/harness/agent-harness.d.ts +0 -715
- package/dist/vendor/engine/runtime/agent/harness/agent-harness.js +0 -5
- package/dist/vendor/engine/runtime/agent/harness/compaction/branch-summarization.d.ts +0 -67
- package/dist/vendor/engine/runtime/agent/harness/compaction/branch-summarization.js +0 -175
- package/dist/vendor/engine/runtime/agent/harness/compaction/compaction.d.ts +0 -125
- package/dist/vendor/engine/runtime/agent/harness/compaction/compaction.js +0 -559
- package/dist/vendor/engine/runtime/agent/harness/compaction/utils.d.ts +0 -24
- package/dist/vendor/engine/runtime/agent/harness/compaction/utils.js +0 -119
- package/dist/vendor/engine/runtime/agent/harness/config.d.ts +0 -8
- package/dist/vendor/engine/runtime/agent/harness/config.js +0 -34
- package/dist/vendor/engine/runtime/agent/harness/context.d.ts +0 -8
- package/dist/vendor/engine/runtime/agent/harness/context.js +0 -12
- package/dist/vendor/engine/runtime/agent/harness/events.d.ts +0 -24
- package/dist/vendor/engine/runtime/agent/harness/events.js +0 -249
- package/dist/vendor/engine/runtime/agent/harness/execution/assistant.d.ts +0 -41
- package/dist/vendor/engine/runtime/agent/harness/execution/assistant.js +0 -81
- package/dist/vendor/engine/runtime/agent/harness/execution/effect-gate.d.ts +0 -21
- package/dist/vendor/engine/runtime/agent/harness/execution/effect-gate.js +0 -48
- package/dist/vendor/engine/runtime/agent/harness/execution/tools.d.ts +0 -66
- package/dist/vendor/engine/runtime/agent/harness/execution/tools.js +0 -118
- package/dist/vendor/engine/runtime/agent/harness/hooks.d.ts +0 -37
- package/dist/vendor/engine/runtime/agent/harness/hooks.js +0 -405
- package/dist/vendor/engine/runtime/agent/harness/messages.d.ts +0 -50
- package/dist/vendor/engine/runtime/agent/harness/messages.js +0 -102
- package/dist/vendor/engine/runtime/agent/harness/prompt-templates.d.ts +0 -48
- package/dist/vendor/engine/runtime/agent/harness/prompt-templates.js +0 -224
- package/dist/vendor/engine/runtime/agent/harness/result.d.ts +0 -132
- package/dist/vendor/engine/runtime/agent/harness/result.js +0 -80
- package/dist/vendor/engine/runtime/agent/harness/runtime/drive/boundary.d.ts +0 -27
- package/dist/vendor/engine/runtime/agent/harness/runtime/drive/boundary.js +0 -172
- package/dist/vendor/engine/runtime/agent/harness/runtime/drive/checkpoint.d.ts +0 -7
- package/dist/vendor/engine/runtime/agent/harness/runtime/drive/checkpoint.js +0 -132
- package/dist/vendor/engine/runtime/agent/harness/runtime/drive/deferred.d.ts +0 -14
- package/dist/vendor/engine/runtime/agent/harness/runtime/drive/deferred.js +0 -178
- package/dist/vendor/engine/runtime/agent/harness/runtime/drive/generation.d.ts +0 -7
- package/dist/vendor/engine/runtime/agent/harness/runtime/drive/generation.js +0 -204
- package/dist/vendor/engine/runtime/agent/harness/runtime/drive/reconcile.d.ts +0 -4
- package/dist/vendor/engine/runtime/agent/harness/runtime/drive/reconcile.js +0 -139
- package/dist/vendor/engine/runtime/agent/harness/runtime/drive/recovery.d.ts +0 -7
- package/dist/vendor/engine/runtime/agent/harness/runtime/drive/recovery.js +0 -84
- package/dist/vendor/engine/runtime/agent/harness/runtime/drive/response.d.ts +0 -22
- package/dist/vendor/engine/runtime/agent/harness/runtime/drive/response.js +0 -393
- package/dist/vendor/engine/runtime/agent/harness/runtime/drive/retry.d.ts +0 -3
- package/dist/vendor/engine/runtime/agent/harness/runtime/drive/retry.js +0 -33
- package/dist/vendor/engine/runtime/agent/harness/runtime/drive/structural.d.ts +0 -31
- package/dist/vendor/engine/runtime/agent/harness/runtime/drive/structural.js +0 -928
- package/dist/vendor/engine/runtime/agent/harness/runtime/drive/terminal.d.ts +0 -6
- package/dist/vendor/engine/runtime/agent/harness/runtime/drive/terminal.js +0 -48
- package/dist/vendor/engine/runtime/agent/harness/runtime/drive/tool-placement.d.ts +0 -13
- package/dist/vendor/engine/runtime/agent/harness/runtime/drive/tool-placement.js +0 -218
- package/dist/vendor/engine/runtime/agent/harness/runtime/drive/tools.d.ts +0 -5
- package/dist/vendor/engine/runtime/agent/harness/runtime/drive/tools.js +0 -448
- package/dist/vendor/engine/runtime/agent/harness/runtime/drive.d.ts +0 -5
- package/dist/vendor/engine/runtime/agent/harness/runtime/drive.js +0 -92
- package/dist/vendor/engine/runtime/agent/harness/runtime/harness.d.ts +0 -58
- package/dist/vendor/engine/runtime/agent/harness/runtime/harness.js +0 -310
- package/dist/vendor/engine/runtime/agent/harness/runtime/lane.d.ts +0 -117
- package/dist/vendor/engine/runtime/agent/harness/runtime/lane.js +0 -1574
- package/dist/vendor/engine/runtime/agent/harness/runtime/progress.d.ts +0 -14
- package/dist/vendor/engine/runtime/agent/harness/runtime/progress.js +0 -65
- package/dist/vendor/engine/runtime/agent/harness/runtime/reducer.d.ts +0 -4
- package/dist/vendor/engine/runtime/agent/harness/runtime/reducer.js +0 -239
- package/dist/vendor/engine/runtime/agent/harness/runtime/restore.d.ts +0 -23
- package/dist/vendor/engine/runtime/agent/harness/runtime/restore.js +0 -116
- package/dist/vendor/engine/runtime/agent/harness/runtime/transcript.d.ts +0 -20
- package/dist/vendor/engine/runtime/agent/harness/runtime/transcript.js +0 -71
- package/dist/vendor/engine/runtime/agent/harness/runtime/types.d.ts +0 -104
- package/dist/vendor/engine/runtime/agent/harness/runtime/types.js +0 -60
- package/dist/vendor/engine/runtime/agent/harness/session/commit.d.ts +0 -52
- package/dist/vendor/engine/runtime/agent/harness/session/commit.js +0 -56
- package/dist/vendor/engine/runtime/agent/harness/session/context.d.ts +0 -9
- package/dist/vendor/engine/runtime/agent/harness/session/context.js +0 -48
- package/dist/vendor/engine/runtime/agent/harness/session/fork-policy.d.ts +0 -20
- package/dist/vendor/engine/runtime/agent/harness/session/fork-policy.js +0 -54
- package/dist/vendor/engine/runtime/agent/harness/session/fork.d.ts +0 -15
- package/dist/vendor/engine/runtime/agent/harness/session/fork.js +0 -78
- package/dist/vendor/engine/runtime/agent/harness/session/in-memory-storage-state.d.ts +0 -38
- package/dist/vendor/engine/runtime/agent/harness/session/in-memory-storage-state.js +0 -275
- package/dist/vendor/engine/runtime/agent/harness/session/index.d.ts +0 -10
- package/dist/vendor/engine/runtime/agent/harness/session/index.js +0 -8
- package/dist/vendor/engine/runtime/agent/harness/session/jsonl/codec.d.ts +0 -20
- package/dist/vendor/engine/runtime/agent/harness/session/jsonl/codec.js +0 -44
- package/dist/vendor/engine/runtime/agent/harness/session/jsonl/fork.d.ts +0 -37
- package/dist/vendor/engine/runtime/agent/harness/session/jsonl/fork.js +0 -263
- package/dist/vendor/engine/runtime/agent/harness/session/jsonl/index.d.ts +0 -3
- package/dist/vendor/engine/runtime/agent/harness/session/jsonl/index.js +0 -3
- package/dist/vendor/engine/runtime/agent/harness/session/jsonl/io.d.ts +0 -13
- package/dist/vendor/engine/runtime/agent/harness/session/jsonl/io.js +0 -85
- package/dist/vendor/engine/runtime/agent/harness/session/jsonl/legacy-v3.d.ts +0 -43
- package/dist/vendor/engine/runtime/agent/harness/session/jsonl/legacy-v3.js +0 -461
- package/dist/vendor/engine/runtime/agent/harness/session/jsonl/repo.d.ts +0 -34
- package/dist/vendor/engine/runtime/agent/harness/session/jsonl/repo.js +0 -300
- package/dist/vendor/engine/runtime/agent/harness/session/jsonl/storage.d.ts +0 -40
- package/dist/vendor/engine/runtime/agent/harness/session/jsonl/storage.js +0 -199
- package/dist/vendor/engine/runtime/agent/harness/session/jsonl/types.d.ts +0 -38
- package/dist/vendor/engine/runtime/agent/harness/session/jsonl/types.js +0 -2
- package/dist/vendor/engine/runtime/agent/harness/session/memory.d.ts +0 -47
- package/dist/vendor/engine/runtime/agent/harness/session/memory.js +0 -368
- package/dist/vendor/engine/runtime/agent/harness/session/mutation-line.d.ts +0 -7
- package/dist/vendor/engine/runtime/agent/harness/session/mutation-line.js +0 -20
- package/dist/vendor/engine/runtime/agent/harness/session/session.d.ts +0 -81
- package/dist/vendor/engine/runtime/agent/harness/session/session.js +0 -360
- package/dist/vendor/engine/runtime/agent/harness/session/types.d.ts +0 -511
- package/dist/vendor/engine/runtime/agent/harness/session/types.js +0 -8
- package/dist/vendor/engine/runtime/agent/harness/session/values.d.ts +0 -94
- package/dist/vendor/engine/runtime/agent/harness/session/values.js +0 -80
- package/dist/vendor/engine/runtime/agent/harness/skills.d.ts +0 -45
- package/dist/vendor/engine/runtime/agent/harness/skills.js +0 -325
- package/dist/vendor/engine/runtime/agent/harness/system-prompt.d.ts +0 -2
- package/dist/vendor/engine/runtime/agent/harness/system-prompt.js +0 -29
- package/dist/vendor/engine/runtime/agent/harness/telemetry.d.ts +0 -1241
- package/dist/vendor/engine/runtime/agent/harness/telemetry.js +0 -526
- package/dist/vendor/engine/runtime/agent/harness/tools/bash.d.ts +0 -26
- package/dist/vendor/engine/runtime/agent/harness/tools/bash.js +0 -104
- package/dist/vendor/engine/runtime/agent/harness/tools/edit-diff.d.ts +0 -88
- package/dist/vendor/engine/runtime/agent/harness/tools/edit-diff.js +0 -385
- package/dist/vendor/engine/runtime/agent/harness/tools/edit.d.ts +0 -18
- package/dist/vendor/engine/runtime/agent/harness/tools/edit.js +0 -107
- package/dist/vendor/engine/runtime/agent/harness/tools/file-mutation-queue.d.ts +0 -4
- package/dist/vendor/engine/runtime/agent/harness/tools/file-mutation-queue.js +0 -45
- package/dist/vendor/engine/runtime/agent/harness/tools/image.d.ts +0 -2
- package/dist/vendor/engine/runtime/agent/harness/tools/image.js +0 -105
- package/dist/vendor/engine/runtime/agent/harness/tools/index.d.ts +0 -5
- package/dist/vendor/engine/runtime/agent/harness/tools/index.js +0 -4
- package/dist/vendor/engine/runtime/agent/harness/tools/path-utils.d.ts +0 -4
- package/dist/vendor/engine/runtime/agent/harness/tools/path-utils.js +0 -25
- package/dist/vendor/engine/runtime/agent/harness/tools/read.d.ts +0 -34
- package/dist/vendor/engine/runtime/agent/harness/tools/read.js +0 -107
- package/dist/vendor/engine/runtime/agent/harness/tools/tool-context.d.ts +0 -5
- package/dist/vendor/engine/runtime/agent/harness/tools/write.d.ts +0 -10
- package/dist/vendor/engine/runtime/agent/harness/tools/write.js +0 -30
- package/dist/vendor/engine/runtime/agent/harness/types.d.ts +0 -304
- package/dist/vendor/engine/runtime/agent/harness/types.js +0 -74
- package/dist/vendor/engine/runtime/agent/harness/utils/adaptive-publisher.d.ts +0 -23
- package/dist/vendor/engine/runtime/agent/harness/utils/adaptive-publisher.js +0 -78
- package/dist/vendor/engine/runtime/agent/harness/utils/output-capture.d.ts +0 -30
- package/dist/vendor/engine/runtime/agent/harness/utils/output-capture.js +0 -216
- package/dist/vendor/engine/runtime/agent/harness/utils/shell-output.d.ts +0 -28
- package/dist/vendor/engine/runtime/agent/harness/utils/shell-output.js +0 -70
- package/dist/vendor/engine/runtime/agent/harness/utils/truncate.d.ts +0 -70
- package/dist/vendor/engine/runtime/agent/harness/utils/truncate.js +0 -295
- package/dist/vendor/engine/runtime/agent/harness/utils/usage.d.ts +0 -3
- package/dist/vendor/engine/runtime/agent/harness/utils/usage.js +0 -32
- package/dist/vendor/engine/runtime/agent/index.d.ts +0 -27
- package/dist/vendor/engine/runtime/agent/index.js +0 -25
- package/dist/vendor/engine/runtime/agent/proxy.d.ts +0 -71
- package/dist/vendor/engine/runtime/agent/proxy.js +0 -309
- package/dist/vendor/engine/runtime/agent/search/index.d.ts +0 -28
- package/dist/vendor/engine/runtime/agent/search/index.js +0 -1
- package/dist/vendor/engine/runtime/agent/stream-fn.d.ts +0 -9
- package/dist/vendor/engine/runtime/agent/stream-fn.js +0 -16
- package/dist/vendor/engine/runtime/ai/api/anthropic-messages.lazy.d.ts +0 -2
- package/dist/vendor/engine/runtime/ai/api/anthropic-messages.lazy.js +0 -2
- package/dist/vendor/engine/runtime/ai/api/azure-openai-responses.d.ts +0 -16
- package/dist/vendor/engine/runtime/ai/api/azure-openai-responses.js +0 -260
- package/dist/vendor/engine/runtime/ai/api/azure-openai-responses.lazy.d.ts +0 -2
- package/dist/vendor/engine/runtime/ai/api/azure-openai-responses.lazy.js +0 -2
- package/dist/vendor/engine/runtime/ai/api/bedrock-converse-stream.d.ts +0 -37
- package/dist/vendor/engine/runtime/ai/api/bedrock-converse-stream.js +0 -1091
- package/dist/vendor/engine/runtime/ai/api/bedrock-converse-stream.lazy.d.ts +0 -9
- package/dist/vendor/engine/runtime/ai/api/bedrock-converse-stream.lazy.js +0 -21
- package/dist/vendor/engine/runtime/ai/api/google-generative-ai.d.ts +0 -12
- package/dist/vendor/engine/runtime/ai/api/google-generative-ai.js +0 -368
- package/dist/vendor/engine/runtime/ai/api/google-generative-ai.lazy.d.ts +0 -2
- package/dist/vendor/engine/runtime/ai/api/google-generative-ai.lazy.js +0 -2
- package/dist/vendor/engine/runtime/ai/api/google-vertex.d.ts +0 -14
- package/dist/vendor/engine/runtime/ai/api/google-vertex.js +0 -429
- package/dist/vendor/engine/runtime/ai/api/google-vertex.lazy.d.ts +0 -2
- package/dist/vendor/engine/runtime/ai/api/google-vertex.lazy.js +0 -2
- package/dist/vendor/engine/runtime/ai/api/mistral-conversations.d.ts +0 -24
- package/dist/vendor/engine/runtime/ai/api/mistral-conversations.js +0 -747
- package/dist/vendor/engine/runtime/ai/api/mistral-conversations.lazy.d.ts +0 -2
- package/dist/vendor/engine/runtime/ai/api/mistral-conversations.lazy.js +0 -2
- package/dist/vendor/engine/runtime/ai/api/openai-codex-responses.d.ts +0 -30
- package/dist/vendor/engine/runtime/ai/api/openai-codex-responses.js +0 -1302
- package/dist/vendor/engine/runtime/ai/api/openai-codex-responses.lazy.d.ts +0 -2
- package/dist/vendor/engine/runtime/ai/api/openai-codex-responses.lazy.js +0 -2
- package/dist/vendor/engine/runtime/ai/api/openai-completions.lazy.d.ts +0 -2
- package/dist/vendor/engine/runtime/ai/api/openai-completions.lazy.js +0 -2
- package/dist/vendor/engine/runtime/ai/api/openai-responses.lazy.d.ts +0 -2
- package/dist/vendor/engine/runtime/ai/api/openai-responses.lazy.js +0 -2
- package/dist/vendor/engine/runtime/ai/api/openrouter-images.d.ts +0 -2
- package/dist/vendor/engine/runtime/ai/api/openrouter-images.js +0 -131
- package/dist/vendor/engine/runtime/ai/api/openrouter-images.lazy.d.ts +0 -2
- package/dist/vendor/engine/runtime/ai/api/openrouter-images.lazy.js +0 -3
- package/dist/vendor/engine/runtime/ai/api/pi-messages.d.ts +0 -98
- package/dist/vendor/engine/runtime/ai/api/pi-messages.js +0 -312
- package/dist/vendor/engine/runtime/ai/api/pi-messages.lazy.d.ts +0 -2
- package/dist/vendor/engine/runtime/ai/api/pi-messages.lazy.js +0 -2
- package/dist/vendor/engine/runtime/ai/auth/helpers.d.ts +0 -21
- package/dist/vendor/engine/runtime/ai/auth/helpers.js +0 -52
- package/dist/vendor/engine/runtime/ai/auth/oauth/load.d.ts +0 -28
- package/dist/vendor/engine/runtime/ai/auth/oauth/load.js +0 -55
- package/dist/vendor/engine/runtime/ai/compat/extension-oauth-types.d.ts +0 -38
- package/dist/vendor/engine/runtime/ai/compat/extension-oauth-types.js +0 -1
- package/dist/vendor/engine/runtime/ai/compat.d.ts +0 -66
- package/dist/vendor/engine/runtime/ai/compat.js +0 -201
- package/dist/vendor/engine/runtime/ai/env-api-keys.d.ts +0 -20
- package/dist/vendor/engine/runtime/ai/env-api-keys.js +0 -148
- package/dist/vendor/engine/runtime/ai/image-models.d.ts +0 -9
- package/dist/vendor/engine/runtime/ai/image-models.generated.d.ts +0 -814
- package/dist/vendor/engine/runtime/ai/image-models.generated.js +0 -816
- package/dist/vendor/engine/runtime/ai/image-models.js +0 -22
- package/dist/vendor/engine/runtime/ai/images-api-registry.d.ts +0 -13
- package/dist/vendor/engine/runtime/ai/images-api-registry.js +0 -21
- package/dist/vendor/engine/runtime/ai/images-models.d.ts +0 -94
- package/dist/vendor/engine/runtime/ai/images-models.js +0 -142
- package/dist/vendor/engine/runtime/ai/images.d.ts +0 -3
- package/dist/vendor/engine/runtime/ai/images.js +0 -13
- package/dist/vendor/engine/runtime/ai/index.d.ts +0 -36
- package/dist/vendor/engine/runtime/ai/index.js +0 -23
- package/dist/vendor/engine/runtime/ai/legacy-api-aliases.d.ts +0 -41
- package/dist/vendor/engine/runtime/ai/legacy-api-aliases.js +0 -48
- package/dist/vendor/engine/runtime/ai/models.generated.d.ts +0 -84
- package/dist/vendor/engine/runtime/ai/models.generated.js +0 -86
- package/dist/vendor/engine/runtime/ai/oauth.d.ts +0 -2
- package/dist/vendor/engine/runtime/ai/oauth.js +0 -1
- package/dist/vendor/engine/runtime/ai/providers/all.d.ts +0 -27
- package/dist/vendor/engine/runtime/ai/providers/all.js +0 -132
- package/dist/vendor/engine/runtime/ai/providers/amazon-bedrock.d.ts +0 -2
- package/dist/vendor/engine/runtime/ai/providers/amazon-bedrock.js +0 -92
- package/dist/vendor/engine/runtime/ai/providers/amazon-bedrock.models.d.ts +0 -3
- package/dist/vendor/engine/runtime/ai/providers/amazon-bedrock.models.js +0 -5
- package/dist/vendor/engine/runtime/ai/providers/ant-ling.d.ts +0 -2
- package/dist/vendor/engine/runtime/ai/providers/ant-ling.js +0 -14
- package/dist/vendor/engine/runtime/ai/providers/ant-ling.models.d.ts +0 -3
- package/dist/vendor/engine/runtime/ai/providers/ant-ling.models.js +0 -5
- package/dist/vendor/engine/runtime/ai/providers/anthropic.d.ts +0 -2
- package/dist/vendor/engine/runtime/ai/providers/anthropic.js +0 -55
- package/dist/vendor/engine/runtime/ai/providers/azure-openai-responses.d.ts +0 -2
- package/dist/vendor/engine/runtime/ai/providers/azure-openai-responses.js +0 -13
- package/dist/vendor/engine/runtime/ai/providers/azure-openai-responses.models.d.ts +0 -3
- package/dist/vendor/engine/runtime/ai/providers/azure-openai-responses.models.js +0 -5
- package/dist/vendor/engine/runtime/ai/providers/baseten.d.ts +0 -2
- package/dist/vendor/engine/runtime/ai/providers/baseten.js +0 -14
- package/dist/vendor/engine/runtime/ai/providers/baseten.models.d.ts +0 -3
- package/dist/vendor/engine/runtime/ai/providers/baseten.models.js +0 -5
- package/dist/vendor/engine/runtime/ai/providers/cerebras.d.ts +0 -2
- package/dist/vendor/engine/runtime/ai/providers/cerebras.js +0 -14
- package/dist/vendor/engine/runtime/ai/providers/cerebras.models.d.ts +0 -3
- package/dist/vendor/engine/runtime/ai/providers/cerebras.models.js +0 -5
- package/dist/vendor/engine/runtime/ai/providers/cloudflare-ai-gateway.d.ts +0 -4
- package/dist/vendor/engine/runtime/ai/providers/cloudflare-ai-gateway.js +0 -24
- package/dist/vendor/engine/runtime/ai/providers/cloudflare-ai-gateway.models.d.ts +0 -3
- package/dist/vendor/engine/runtime/ai/providers/cloudflare-ai-gateway.models.js +0 -5
- package/dist/vendor/engine/runtime/ai/providers/cloudflare-auth.d.ts +0 -3
- package/dist/vendor/engine/runtime/ai/providers/cloudflare-auth.js +0 -85
- package/dist/vendor/engine/runtime/ai/providers/cloudflare-stream.d.ts +0 -7
- package/dist/vendor/engine/runtime/ai/providers/cloudflare-stream.js +0 -20
- package/dist/vendor/engine/runtime/ai/providers/cloudflare-workers-ai.d.ts +0 -2
- package/dist/vendor/engine/runtime/ai/providers/cloudflare-workers-ai.js +0 -14
- package/dist/vendor/engine/runtime/ai/providers/cloudflare-workers-ai.models.d.ts +0 -3
- package/dist/vendor/engine/runtime/ai/providers/cloudflare-workers-ai.models.js +0 -5
- package/dist/vendor/engine/runtime/ai/providers/data/.manifest.json +0 -1
- package/dist/vendor/engine/runtime/ai/providers/data/amazon-bedrock.json +0 -1
- package/dist/vendor/engine/runtime/ai/providers/data/ant-ling.json +0 -1
- package/dist/vendor/engine/runtime/ai/providers/data/azure-openai-responses.json +0 -1
- package/dist/vendor/engine/runtime/ai/providers/data/baseten.json +0 -1
- package/dist/vendor/engine/runtime/ai/providers/data/cerebras.json +0 -1
- package/dist/vendor/engine/runtime/ai/providers/data/cloudflare-ai-gateway.json +0 -1
- package/dist/vendor/engine/runtime/ai/providers/data/cloudflare-workers-ai.json +0 -1
- package/dist/vendor/engine/runtime/ai/providers/data/deepseek.json +0 -1
- package/dist/vendor/engine/runtime/ai/providers/data/fireworks.json +0 -1
- package/dist/vendor/engine/runtime/ai/providers/data/github-copilot.json +0 -1
- package/dist/vendor/engine/runtime/ai/providers/data/google-vertex.json +0 -1
- package/dist/vendor/engine/runtime/ai/providers/data/google.json +0 -1
- package/dist/vendor/engine/runtime/ai/providers/data/groq.json +0 -1
- package/dist/vendor/engine/runtime/ai/providers/data/huggingface.json +0 -1
- package/dist/vendor/engine/runtime/ai/providers/data/kimi-coding.json +0 -1
- package/dist/vendor/engine/runtime/ai/providers/data/meta.json +0 -1
- package/dist/vendor/engine/runtime/ai/providers/data/minimax-cn.json +0 -1
- package/dist/vendor/engine/runtime/ai/providers/data/minimax.json +0 -1
- package/dist/vendor/engine/runtime/ai/providers/data/mistral.json +0 -1
- package/dist/vendor/engine/runtime/ai/providers/data/moonshotai-cn.json +0 -1
- package/dist/vendor/engine/runtime/ai/providers/data/moonshotai.json +0 -1
- package/dist/vendor/engine/runtime/ai/providers/data/nvidia.json +0 -1
- package/dist/vendor/engine/runtime/ai/providers/data/openai-codex.json +0 -1
- package/dist/vendor/engine/runtime/ai/providers/data/openai.json +0 -1
- package/dist/vendor/engine/runtime/ai/providers/data/opencode-go.json +0 -1
- package/dist/vendor/engine/runtime/ai/providers/data/opencode.json +0 -1
- package/dist/vendor/engine/runtime/ai/providers/data/openrouter.json +0 -1
- package/dist/vendor/engine/runtime/ai/providers/data/qwen-token-plan-cn.json +0 -1
- package/dist/vendor/engine/runtime/ai/providers/data/qwen-token-plan-individual.json +0 -1
- package/dist/vendor/engine/runtime/ai/providers/data/qwen-token-plan.json +0 -1
- package/dist/vendor/engine/runtime/ai/providers/data/radius.json +0 -1
- package/dist/vendor/engine/runtime/ai/providers/data/together.json +0 -1
- package/dist/vendor/engine/runtime/ai/providers/data/vercel-ai-gateway.json +0 -1
- package/dist/vendor/engine/runtime/ai/providers/data/xai.json +0 -1
- package/dist/vendor/engine/runtime/ai/providers/data/xiaomi-token-plan-ams.json +0 -1
- package/dist/vendor/engine/runtime/ai/providers/data/xiaomi-token-plan-cn.json +0 -1
- package/dist/vendor/engine/runtime/ai/providers/data/xiaomi-token-plan-sgp.json +0 -1
- package/dist/vendor/engine/runtime/ai/providers/data/xiaomi.json +0 -1
- package/dist/vendor/engine/runtime/ai/providers/data/zai-coding-cn.json +0 -1
- package/dist/vendor/engine/runtime/ai/providers/data/zai.json +0 -1
- package/dist/vendor/engine/runtime/ai/providers/deepseek.d.ts +0 -2
- package/dist/vendor/engine/runtime/ai/providers/deepseek.js +0 -14
- package/dist/vendor/engine/runtime/ai/providers/deepseek.models.d.ts +0 -3
- package/dist/vendor/engine/runtime/ai/providers/deepseek.models.js +0 -5
- package/dist/vendor/engine/runtime/ai/providers/faux.d.ts +0 -102
- package/dist/vendor/engine/runtime/ai/providers/faux.js +0 -488
- package/dist/vendor/engine/runtime/ai/providers/fireworks.d.ts +0 -2
- package/dist/vendor/engine/runtime/ai/providers/fireworks.js +0 -18
- package/dist/vendor/engine/runtime/ai/providers/fireworks.models.d.ts +0 -3
- package/dist/vendor/engine/runtime/ai/providers/fireworks.models.js +0 -5
- package/dist/vendor/engine/runtime/ai/providers/github-copilot.d.ts +0 -2
- package/dist/vendor/engine/runtime/ai/providers/github-copilot.js +0 -34
- package/dist/vendor/engine/runtime/ai/providers/github-copilot.models.d.ts +0 -3
- package/dist/vendor/engine/runtime/ai/providers/github-copilot.models.js +0 -5
- package/dist/vendor/engine/runtime/ai/providers/google-vertex.d.ts +0 -2
- package/dist/vendor/engine/runtime/ai/providers/google-vertex.js +0 -93
- package/dist/vendor/engine/runtime/ai/providers/google-vertex.models.d.ts +0 -3
- package/dist/vendor/engine/runtime/ai/providers/google-vertex.models.js +0 -5
- package/dist/vendor/engine/runtime/ai/providers/google.d.ts +0 -2
- package/dist/vendor/engine/runtime/ai/providers/google.js +0 -14
- package/dist/vendor/engine/runtime/ai/providers/google.models.d.ts +0 -3
- package/dist/vendor/engine/runtime/ai/providers/google.models.js +0 -5
- package/dist/vendor/engine/runtime/ai/providers/groq.d.ts +0 -2
- package/dist/vendor/engine/runtime/ai/providers/groq.js +0 -14
- package/dist/vendor/engine/runtime/ai/providers/groq.models.d.ts +0 -3
- package/dist/vendor/engine/runtime/ai/providers/groq.models.js +0 -5
- package/dist/vendor/engine/runtime/ai/providers/huggingface.d.ts +0 -2
- package/dist/vendor/engine/runtime/ai/providers/huggingface.js +0 -14
- package/dist/vendor/engine/runtime/ai/providers/huggingface.models.d.ts +0 -3
- package/dist/vendor/engine/runtime/ai/providers/huggingface.models.js +0 -5
- package/dist/vendor/engine/runtime/ai/providers/images/register-builtins.d.ts +0 -3
- package/dist/vendor/engine/runtime/ai/providers/images/register-builtins.js +0 -33
- package/dist/vendor/engine/runtime/ai/providers/kimi-coding.d.ts +0 -2
- package/dist/vendor/engine/runtime/ai/providers/kimi-coding.js +0 -23
- package/dist/vendor/engine/runtime/ai/providers/kimi-coding.models.d.ts +0 -3
- package/dist/vendor/engine/runtime/ai/providers/kimi-coding.models.js +0 -5
- package/dist/vendor/engine/runtime/ai/providers/meta.d.ts +0 -2
- package/dist/vendor/engine/runtime/ai/providers/meta.js +0 -23
- package/dist/vendor/engine/runtime/ai/providers/meta.models.d.ts +0 -3
- package/dist/vendor/engine/runtime/ai/providers/meta.models.js +0 -5
- package/dist/vendor/engine/runtime/ai/providers/minimax-cn.d.ts +0 -2
- package/dist/vendor/engine/runtime/ai/providers/minimax-cn.js +0 -14
- package/dist/vendor/engine/runtime/ai/providers/minimax-cn.models.d.ts +0 -3
- package/dist/vendor/engine/runtime/ai/providers/minimax-cn.models.js +0 -5
- package/dist/vendor/engine/runtime/ai/providers/minimax.d.ts +0 -2
- package/dist/vendor/engine/runtime/ai/providers/minimax.js +0 -14
- package/dist/vendor/engine/runtime/ai/providers/minimax.models.d.ts +0 -3
- package/dist/vendor/engine/runtime/ai/providers/minimax.models.js +0 -5
- package/dist/vendor/engine/runtime/ai/providers/mistral.d.ts +0 -2
- package/dist/vendor/engine/runtime/ai/providers/mistral.js +0 -14
- package/dist/vendor/engine/runtime/ai/providers/mistral.models.d.ts +0 -3
- package/dist/vendor/engine/runtime/ai/providers/mistral.models.js +0 -5
- package/dist/vendor/engine/runtime/ai/providers/moonshotai-cn.d.ts +0 -2
- package/dist/vendor/engine/runtime/ai/providers/moonshotai-cn.js +0 -14
- package/dist/vendor/engine/runtime/ai/providers/moonshotai-cn.models.d.ts +0 -3
- package/dist/vendor/engine/runtime/ai/providers/moonshotai-cn.models.js +0 -5
- package/dist/vendor/engine/runtime/ai/providers/moonshotai.d.ts +0 -2
- package/dist/vendor/engine/runtime/ai/providers/moonshotai.js +0 -14
- package/dist/vendor/engine/runtime/ai/providers/moonshotai.models.d.ts +0 -3
- package/dist/vendor/engine/runtime/ai/providers/moonshotai.models.js +0 -5
- package/dist/vendor/engine/runtime/ai/providers/nvidia.d.ts +0 -2
- package/dist/vendor/engine/runtime/ai/providers/nvidia.js +0 -14
- package/dist/vendor/engine/runtime/ai/providers/nvidia.models.d.ts +0 -3
- package/dist/vendor/engine/runtime/ai/providers/nvidia.models.js +0 -5
- package/dist/vendor/engine/runtime/ai/providers/openai-codex.d.ts +0 -2
- package/dist/vendor/engine/runtime/ai/providers/openai-codex.js +0 -21
- package/dist/vendor/engine/runtime/ai/providers/openai-codex.models.d.ts +0 -3
- package/dist/vendor/engine/runtime/ai/providers/openai-codex.models.js +0 -5
- package/dist/vendor/engine/runtime/ai/providers/openai.d.ts +0 -2
- package/dist/vendor/engine/runtime/ai/providers/openai.js +0 -14
- package/dist/vendor/engine/runtime/ai/providers/openai.models.d.ts +0 -3
- package/dist/vendor/engine/runtime/ai/providers/openai.models.js +0 -5
- package/dist/vendor/engine/runtime/ai/providers/opencode-go.d.ts +0 -2
- package/dist/vendor/engine/runtime/ai/providers/opencode-go.js +0 -20
- package/dist/vendor/engine/runtime/ai/providers/opencode-go.models.d.ts +0 -3
- package/dist/vendor/engine/runtime/ai/providers/opencode-go.models.js +0 -5
- package/dist/vendor/engine/runtime/ai/providers/opencode-headers.d.ts +0 -3
- package/dist/vendor/engine/runtime/ai/providers/opencode-headers.js +0 -21
- package/dist/vendor/engine/runtime/ai/providers/opencode.d.ts +0 -2
- package/dist/vendor/engine/runtime/ai/providers/opencode.js +0 -22
- package/dist/vendor/engine/runtime/ai/providers/opencode.models.d.ts +0 -3
- package/dist/vendor/engine/runtime/ai/providers/opencode.models.js +0 -5
- package/dist/vendor/engine/runtime/ai/providers/openrouter-images.d.ts +0 -2
- package/dist/vendor/engine/runtime/ai/providers/openrouter-images.js +0 -21
- package/dist/vendor/engine/runtime/ai/providers/openrouter.d.ts +0 -2
- package/dist/vendor/engine/runtime/ai/providers/openrouter.js +0 -26
- package/dist/vendor/engine/runtime/ai/providers/openrouter.models.d.ts +0 -3
- package/dist/vendor/engine/runtime/ai/providers/openrouter.models.js +0 -5
- package/dist/vendor/engine/runtime/ai/providers/qwen-token-plan-cn.d.ts +0 -2
- package/dist/vendor/engine/runtime/ai/providers/qwen-token-plan-cn.js +0 -14
- package/dist/vendor/engine/runtime/ai/providers/qwen-token-plan-cn.models.d.ts +0 -3
- package/dist/vendor/engine/runtime/ai/providers/qwen-token-plan-cn.models.js +0 -5
- package/dist/vendor/engine/runtime/ai/providers/qwen-token-plan-individual.d.ts +0 -2
- package/dist/vendor/engine/runtime/ai/providers/qwen-token-plan-individual.js +0 -14
- package/dist/vendor/engine/runtime/ai/providers/qwen-token-plan-individual.models.d.ts +0 -3
- package/dist/vendor/engine/runtime/ai/providers/qwen-token-plan-individual.models.js +0 -5
- package/dist/vendor/engine/runtime/ai/providers/qwen-token-plan.d.ts +0 -2
- package/dist/vendor/engine/runtime/ai/providers/qwen-token-plan.js +0 -14
- package/dist/vendor/engine/runtime/ai/providers/qwen-token-plan.models.d.ts +0 -3
- package/dist/vendor/engine/runtime/ai/providers/qwen-token-plan.models.js +0 -5
- package/dist/vendor/engine/runtime/ai/providers/radius-config.d.ts +0 -25
- package/dist/vendor/engine/runtime/ai/providers/radius-config.js +0 -62
- package/dist/vendor/engine/runtime/ai/providers/radius.d.ts +0 -8
- package/dist/vendor/engine/runtime/ai/providers/radius.js +0 -77
- package/dist/vendor/engine/runtime/ai/providers/radius.models.d.ts +0 -3
- package/dist/vendor/engine/runtime/ai/providers/radius.models.js +0 -5
- package/dist/vendor/engine/runtime/ai/providers/together.d.ts +0 -2
- package/dist/vendor/engine/runtime/ai/providers/together.js +0 -14
- package/dist/vendor/engine/runtime/ai/providers/together.models.d.ts +0 -3
- package/dist/vendor/engine/runtime/ai/providers/together.models.js +0 -5
- package/dist/vendor/engine/runtime/ai/providers/vercel-ai-gateway.d.ts +0 -2
- package/dist/vendor/engine/runtime/ai/providers/vercel-ai-gateway.js +0 -14
- package/dist/vendor/engine/runtime/ai/providers/vercel-ai-gateway.models.d.ts +0 -3
- package/dist/vendor/engine/runtime/ai/providers/vercel-ai-gateway.models.js +0 -5
- package/dist/vendor/engine/runtime/ai/providers/xai.d.ts +0 -2
- package/dist/vendor/engine/runtime/ai/providers/xai.js +0 -23
- package/dist/vendor/engine/runtime/ai/providers/xai.models.d.ts +0 -3
- package/dist/vendor/engine/runtime/ai/providers/xai.models.js +0 -5
- package/dist/vendor/engine/runtime/ai/providers/xiaomi-token-plan-ams.d.ts +0 -2
- package/dist/vendor/engine/runtime/ai/providers/xiaomi-token-plan-ams.js +0 -14
- package/dist/vendor/engine/runtime/ai/providers/xiaomi-token-plan-ams.models.d.ts +0 -3
- package/dist/vendor/engine/runtime/ai/providers/xiaomi-token-plan-ams.models.js +0 -5
- package/dist/vendor/engine/runtime/ai/providers/xiaomi-token-plan-cn.d.ts +0 -2
- package/dist/vendor/engine/runtime/ai/providers/xiaomi-token-plan-cn.js +0 -14
- package/dist/vendor/engine/runtime/ai/providers/xiaomi-token-plan-cn.models.d.ts +0 -3
- package/dist/vendor/engine/runtime/ai/providers/xiaomi-token-plan-cn.models.js +0 -5
- package/dist/vendor/engine/runtime/ai/providers/xiaomi-token-plan-sgp.d.ts +0 -2
- package/dist/vendor/engine/runtime/ai/providers/xiaomi-token-plan-sgp.js +0 -14
- package/dist/vendor/engine/runtime/ai/providers/xiaomi-token-plan-sgp.models.d.ts +0 -3
- package/dist/vendor/engine/runtime/ai/providers/xiaomi-token-plan-sgp.models.js +0 -5
- package/dist/vendor/engine/runtime/ai/providers/xiaomi.d.ts +0 -2
- package/dist/vendor/engine/runtime/ai/providers/xiaomi.js +0 -14
- package/dist/vendor/engine/runtime/ai/providers/xiaomi.models.d.ts +0 -3
- package/dist/vendor/engine/runtime/ai/providers/xiaomi.models.js +0 -5
- package/dist/vendor/engine/runtime/ai/providers/zai-coding-cn.d.ts +0 -2
- package/dist/vendor/engine/runtime/ai/providers/zai-coding-cn.js +0 -14
- package/dist/vendor/engine/runtime/ai/providers/zai-coding-cn.models.d.ts +0 -3
- package/dist/vendor/engine/runtime/ai/providers/zai-coding-cn.models.js +0 -5
- package/dist/vendor/engine/runtime/ai/providers/zai.d.ts +0 -2
- package/dist/vendor/engine/runtime/ai/providers/zai.js +0 -14
- package/dist/vendor/engine/runtime/ai/providers/zai.models.d.ts +0 -3
- package/dist/vendor/engine/runtime/ai/providers/zai.models.js +0 -5
- package/dist/vendor/engine/runtime/ai/session-resources.d.ts +0 -3
- package/dist/vendor/engine/runtime/ai/session-resources.js +0 -21
- package/dist/vendor/engine/runtime/ai/utils/abort-signals.d.ts +0 -5
- package/dist/vendor/engine/runtime/ai/utils/abort-signals.js +0 -33
- package/dist/vendor/engine/runtime/ai/utils/assistant-message-frame.d.ts +0 -76
- package/dist/vendor/engine/runtime/ai/utils/assistant-message-frame.js +0 -424
- package/dist/vendor/engine/runtime/ai/utils/node-http-proxy.d.ts +0 -3
- package/dist/vendor/engine/runtime/ai/utils/node-http-proxy.js +0 -132
- package/dist/vendor/engine/runtime/ai/utils/retry.d.ts +0 -57
- package/dist/vendor/engine/runtime/ai/utils/retry.js +0 -182
- package/dist/vendor/engine/runtime/ai/utils/typebox-helpers.d.ts +0 -16
- package/dist/vendor/engine/runtime/ai/utils/typebox-helpers.js +0 -20
- package/dist/vendor/engine/runtime/ai/utils/uuid.d.ts +0 -2
- package/dist/vendor/engine/runtime/ai/utils/uuid.js +0 -41
- package/dist/vendor/engine/runtime/ai/utils/validation.d.ts +0 -17
- package/dist/vendor/engine/runtime/ai/utils/validation.js +0 -308
- package/dist/vendor/engine/runtime/chord/api.d.ts +0 -14
- package/dist/vendor/engine/runtime/chord/api.js +0 -71
- package/dist/vendor/engine/runtime/chord/context/index.d.ts +0 -23
- package/dist/vendor/engine/runtime/chord/context/index.js +0 -96
- package/dist/vendor/engine/runtime/chord/delta/index.d.ts +0 -118
- package/dist/vendor/engine/runtime/chord/delta/index.js +0 -1903
- package/dist/vendor/engine/runtime/chord/facets/host.d.ts +0 -11
- package/dist/vendor/engine/runtime/chord/facets/host.js +0 -762
- package/dist/vendor/engine/runtime/chord/facets/loader.d.ts +0 -2
- package/dist/vendor/engine/runtime/chord/facets/loader.js +0 -4
- package/dist/vendor/engine/runtime/chord/index.d.ts +0 -10
- package/dist/vendor/engine/runtime/chord/index.js +0 -9
- package/dist/vendor/engine/runtime/chord/json.d.ts +0 -3
- package/dist/vendor/engine/runtime/chord/json.js +0 -56
- package/dist/vendor/engine/runtime/chord/services/consumer.d.ts +0 -10
- package/dist/vendor/engine/runtime/chord/services/consumer.js +0 -536
- package/dist/vendor/engine/runtime/chord/services/errors.d.ts +0 -7
- package/dist/vendor/engine/runtime/chord/services/errors.js +0 -21
- package/dist/vendor/engine/runtime/chord/services/handle.d.ts +0 -14
- package/dist/vendor/engine/runtime/chord/services/handle.js +0 -100
- package/dist/vendor/engine/runtime/chord/services/instances.d.ts +0 -24
- package/dist/vendor/engine/runtime/chord/services/instances.js +0 -136
- package/dist/vendor/engine/runtime/chord/services/loopback.d.ts +0 -4
- package/dist/vendor/engine/runtime/chord/services/loopback.js +0 -14
- package/dist/vendor/engine/runtime/chord/services/provider.d.ts +0 -36
- package/dist/vendor/engine/runtime/chord/services/provider.js +0 -471
- package/dist/vendor/engine/runtime/chord/services/state-codec.d.ts +0 -14
- package/dist/vendor/engine/runtime/chord/services/state-codec.js +0 -114
- package/dist/vendor/engine/runtime/chord/services/state-internals.d.ts +0 -10
- package/dist/vendor/engine/runtime/chord/services/state-internals.js +0 -9
- package/dist/vendor/engine/runtime/chord/services/state.d.ts +0 -22
- package/dist/vendor/engine/runtime/chord/services/state.js +0 -123
- package/dist/vendor/engine/runtime/chord/services/wire.d.ts +0 -59
- package/dist/vendor/engine/runtime/chord/services/wire.js +0 -172
- package/dist/vendor/engine/runtime/chord/types.d.ts +0 -202
- package/dist/vendor/engine/runtime/chord/types.js +0 -1
- package/dist/vendor/engine/runtime/coding-agent/cli/args.d.ts +0 -60
- package/dist/vendor/engine/runtime/coding-agent/cli/args.js +0 -439
- package/dist/vendor/engine/runtime/coding-agent/cli/auth-check.d.ts +0 -18
- package/dist/vendor/engine/runtime/coding-agent/cli/auth-check.js +0 -49
- package/dist/vendor/engine/runtime/coding-agent/cli/auth-command.d.ts +0 -23
- package/dist/vendor/engine/runtime/coding-agent/cli/auth-command.js +0 -102
- package/dist/vendor/engine/runtime/coding-agent/cli/config-selector.d.ts +0 -15
- package/dist/vendor/engine/runtime/coding-agent/cli/config-selector.js +0 -31
- package/dist/vendor/engine/runtime/coding-agent/cli/credential-print.d.ts +0 -12
- package/dist/vendor/engine/runtime/coding-agent/cli/credential-print.js +0 -75
- package/dist/vendor/engine/runtime/coding-agent/cli/file-processor.d.ts +0 -14
- package/dist/vendor/engine/runtime/coding-agent/cli/file-processor.js +0 -70
- package/dist/vendor/engine/runtime/coding-agent/cli/initial-message.d.ts +0 -17
- package/dist/vendor/engine/runtime/coding-agent/cli/initial-message.js +0 -21
- package/dist/vendor/engine/runtime/coding-agent/cli/list-models.d.ts +0 -8
- package/dist/vendor/engine/runtime/coding-agent/cli/list-models.js +0 -97
- package/dist/vendor/engine/runtime/coding-agent/cli/project-trust.d.ts +0 -9
- package/dist/vendor/engine/runtime/coding-agent/cli/project-trust.js +0 -47
- package/dist/vendor/engine/runtime/coding-agent/cli/session-picker.d.ts +0 -9
- package/dist/vendor/engine/runtime/coding-agent/cli/session-picker.js +0 -35
- package/dist/vendor/engine/runtime/coding-agent/cli/startup-ui.d.ts +0 -19
- package/dist/vendor/engine/runtime/coding-agent/cli/startup-ui.js +0 -184
- package/dist/vendor/engine/runtime/coding-agent/core/agent-session-runtime.d.ts +0 -118
- package/dist/vendor/engine/runtime/coding-agent/core/agent-session-runtime.js +0 -316
- package/dist/vendor/engine/runtime/coding-agent/core/agent-session-services.d.ts +0 -85
- package/dist/vendor/engine/runtime/coding-agent/core/agent-session-services.js +0 -133
- package/dist/vendor/engine/runtime/coding-agent/core/agent-session.d.ts +0 -771
- package/dist/vendor/engine/runtime/coding-agent/core/agent-session.js +0 -2990
- package/dist/vendor/engine/runtime/coding-agent/core/auth-guidance.d.ts +0 -4
- package/dist/vendor/engine/runtime/coding-agent/core/auth-guidance.js +0 -20
- package/dist/vendor/engine/runtime/coding-agent/core/auth-storage.d.ts +0 -71
- package/dist/vendor/engine/runtime/coding-agent/core/auth-storage.js +0 -425
- package/dist/vendor/engine/runtime/coding-agent/core/bash-executor.d.ts +0 -31
- package/dist/vendor/engine/runtime/coding-agent/core/bash-executor.js +0 -110
- package/dist/vendor/engine/runtime/coding-agent/core/bug-report-upload.d.ts +0 -11
- package/dist/vendor/engine/runtime/coding-agent/core/bug-report-upload.js +0 -21
- package/dist/vendor/engine/runtime/coding-agent/core/bug-report.d.ts +0 -175
- package/dist/vendor/engine/runtime/coding-agent/core/bug-report.js +0 -291
- package/dist/vendor/engine/runtime/coding-agent/core/cache-stats.d.ts +0 -48
- package/dist/vendor/engine/runtime/coding-agent/core/cache-stats.js +0 -111
- package/dist/vendor/engine/runtime/coding-agent/core/cache-warmer.d.ts +0 -102
- package/dist/vendor/engine/runtime/coding-agent/core/cache-warmer.js +0 -355
- package/dist/vendor/engine/runtime/coding-agent/core/compaction/branch-summarization.d.ts +0 -97
- package/dist/vendor/engine/runtime/coding-agent/core/compaction/branch-summarization.js +0 -250
- package/dist/vendor/engine/runtime/coding-agent/core/compaction/compaction.d.ts +0 -142
- package/dist/vendor/engine/runtime/coding-agent/core/compaction/compaction.js +0 -666
- package/dist/vendor/engine/runtime/coding-agent/core/compaction/index.d.ts +0 -6
- package/dist/vendor/engine/runtime/coding-agent/core/compaction/index.js +0 -6
- package/dist/vendor/engine/runtime/coding-agent/core/compaction/utils.d.ts +0 -37
- package/dist/vendor/engine/runtime/coding-agent/core/compaction/utils.js +0 -141
- package/dist/vendor/engine/runtime/coding-agent/core/crash-log.d.ts +0 -26
- package/dist/vendor/engine/runtime/coding-agent/core/crash-log.js +0 -138
- package/dist/vendor/engine/runtime/coding-agent/core/defaults.d.ts +0 -3
- package/dist/vendor/engine/runtime/coding-agent/core/defaults.js +0 -10
- package/dist/vendor/engine/runtime/coding-agent/core/diagnostics.d.ts +0 -14
- package/dist/vendor/engine/runtime/coding-agent/core/diagnostics.js +0 -1
- package/dist/vendor/engine/runtime/coding-agent/core/event-bus.d.ts +0 -8
- package/dist/vendor/engine/runtime/coding-agent/core/event-bus.js +0 -24
- package/dist/vendor/engine/runtime/coding-agent/core/exec.d.ts +0 -28
- package/dist/vendor/engine/runtime/coding-agent/core/exec.js +0 -74
- package/dist/vendor/engine/runtime/coding-agent/core/experimental.d.ts +0 -1
- package/dist/vendor/engine/runtime/coding-agent/core/experimental.js +0 -3
- package/dist/vendor/engine/runtime/coding-agent/core/export-html/ansi-to-html.d.ts +0 -21
- package/dist/vendor/engine/runtime/coding-agent/core/export-html/ansi-to-html.js +0 -248
- package/dist/vendor/engine/runtime/coding-agent/core/export-html/index.d.ts +0 -36
- package/dist/vendor/engine/runtime/coding-agent/core/export-html/index.js +0 -225
- package/dist/vendor/engine/runtime/coding-agent/core/export-html/template.css +0 -1066
- package/dist/vendor/engine/runtime/coding-agent/core/export-html/template.html +0 -55
- package/dist/vendor/engine/runtime/coding-agent/core/export-html/template.js +0 -1864
- package/dist/vendor/engine/runtime/coding-agent/core/export-html/tool-renderer.d.ts +0 -33
- package/dist/vendor/engine/runtime/coding-agent/core/export-html/tool-renderer.js +0 -107
- package/dist/vendor/engine/runtime/coding-agent/core/export-html/vendor/highlight.min.js +0 -1213
- package/dist/vendor/engine/runtime/coding-agent/core/export-html/vendor/marked.min.js +0 -78
- package/dist/vendor/engine/runtime/coding-agent/core/extensions/index.d.ts +0 -11
- package/dist/vendor/engine/runtime/coding-agent/core/extensions/index.js +0 -8
- package/dist/vendor/engine/runtime/coding-agent/core/extensions/jiti-loader.d.ts +0 -1
- package/dist/vendor/engine/runtime/coding-agent/core/extensions/jiti-loader.js +0 -3
- package/dist/vendor/engine/runtime/coding-agent/core/extensions/jiti-static-loader.d.ts +0 -1
- package/dist/vendor/engine/runtime/coding-agent/core/extensions/jiti-static-loader.js +0 -3
- package/dist/vendor/engine/runtime/coding-agent/core/extensions/loader.d.ts +0 -22
- package/dist/vendor/engine/runtime/coding-agent/core/extensions/loader.js +0 -633
- package/dist/vendor/engine/runtime/coding-agent/core/extensions/runner.d.ts +0 -180
- package/dist/vendor/engine/runtime/coding-agent/core/extensions/runner.js +0 -1028
- package/dist/vendor/engine/runtime/coding-agent/core/extensions/types.d.ts +0 -1362
- package/dist/vendor/engine/runtime/coding-agent/core/extensions/types.js +0 -47
- package/dist/vendor/engine/runtime/coding-agent/core/extensions/virtual-modules.d.ts +0 -2
- package/dist/vendor/engine/runtime/coding-agent/core/extensions/virtual-modules.js +0 -37
- package/dist/vendor/engine/runtime/coding-agent/core/extensions/wrapper.d.ts +0 -19
- package/dist/vendor/engine/runtime/coding-agent/core/extensions/wrapper.js +0 -21
- package/dist/vendor/engine/runtime/coding-agent/core/footer-data-provider.d.ts +0 -63
- package/dist/vendor/engine/runtime/coding-agent/core/footer-data-provider.js +0 -337
- package/dist/vendor/engine/runtime/coding-agent/core/http-dispatcher.d.ts +0 -21
- package/dist/vendor/engine/runtime/coding-agent/core/http-dispatcher.js +0 -97
- package/dist/vendor/engine/runtime/coding-agent/core/keybindings.d.ts +0 -427
- package/dist/vendor/engine/runtime/coding-agent/core/keybindings.js +0 -320
- package/dist/vendor/engine/runtime/coding-agent/core/messages.d.ts +0 -76
- package/dist/vendor/engine/runtime/coding-agent/core/messages.js +0 -123
- package/dist/vendor/engine/runtime/coding-agent/core/model-config.d.ts +0 -723
- package/dist/vendor/engine/runtime/coding-agent/core/model-config.js +0 -281
- package/dist/vendor/engine/runtime/coding-agent/core/model-registry.d.ts +0 -48
- package/dist/vendor/engine/runtime/coding-agent/core/model-registry.js +0 -114
- package/dist/vendor/engine/runtime/coding-agent/core/model-resolver.d.ts +0 -123
- package/dist/vendor/engine/runtime/coding-agent/core/model-resolver.js +0 -589
- package/dist/vendor/engine/runtime/coding-agent/core/model-runtime.d.ts +0 -100
- package/dist/vendor/engine/runtime/coding-agent/core/model-runtime.js +0 -603
- package/dist/vendor/engine/runtime/coding-agent/core/models-store.d.ts +0 -21
- package/dist/vendor/engine/runtime/coding-agent/core/models-store.js +0 -114
- package/dist/vendor/engine/runtime/coding-agent/core/output-guard.d.ts +0 -6
- package/dist/vendor/engine/runtime/coding-agent/core/output-guard.js +0 -88
- package/dist/vendor/engine/runtime/coding-agent/core/package-manager.d.ts +0 -212
- package/dist/vendor/engine/runtime/coding-agent/core/package-manager.js +0 -2176
- package/dist/vendor/engine/runtime/coding-agent/core/pi-manifest.d.ts +0 -7
- package/dist/vendor/engine/runtime/coding-agent/core/pi-manifest.js +0 -25
- package/dist/vendor/engine/runtime/coding-agent/core/project-trust.d.ts +0 -14
- package/dist/vendor/engine/runtime/coding-agent/core/project-trust.js +0 -58
- package/dist/vendor/engine/runtime/coding-agent/core/prompt-templates.d.ts +0 -53
- package/dist/vendor/engine/runtime/coding-agent/core/prompt-templates.js +0 -235
- package/dist/vendor/engine/runtime/coding-agent/core/provider-attribution.d.ts +0 -3
- package/dist/vendor/engine/runtime/coding-agent/core/provider-attribution.js +0 -71
- package/dist/vendor/engine/runtime/coding-agent/core/provider-composer.d.ts +0 -59
- package/dist/vendor/engine/runtime/coding-agent/core/provider-composer.js +0 -422
- package/dist/vendor/engine/runtime/coding-agent/core/radius.d.ts +0 -4
- package/dist/vendor/engine/runtime/coding-agent/core/radius.js +0 -7
- package/dist/vendor/engine/runtime/coding-agent/core/remote-catalog-provider.d.ts +0 -4
- package/dist/vendor/engine/runtime/coding-agent/core/remote-catalog-provider.js +0 -121
- package/dist/vendor/engine/runtime/coding-agent/core/resolve-config-value.d.ts +0 -29
- package/dist/vendor/engine/runtime/coding-agent/core/resolve-config-value.js +0 -246
- package/dist/vendor/engine/runtime/coding-agent/core/resource-loader.d.ts +0 -220
- package/dist/vendor/engine/runtime/coding-agent/core/resource-loader.js +0 -874
- package/dist/vendor/engine/runtime/coding-agent/core/runtime-credentials.d.ts +0 -14
- package/dist/vendor/engine/runtime/coding-agent/core/runtime-credentials.js +0 -38
- package/dist/vendor/engine/runtime/coding-agent/core/sdk.d.ts +0 -107
- package/dist/vendor/engine/runtime/coding-agent/core/sdk.js +0 -296
- package/dist/vendor/engine/runtime/coding-agent/core/session-cwd.d.ts +0 -18
- package/dist/vendor/engine/runtime/coding-agent/core/session-cwd.js +0 -37
- package/dist/vendor/engine/runtime/coding-agent/core/session-export.d.ts +0 -7
- package/dist/vendor/engine/runtime/coding-agent/core/session-export.js +0 -32
- package/dist/vendor/engine/runtime/coding-agent/core/session-manager.d.ts +0 -379
- package/dist/vendor/engine/runtime/coding-agent/core/session-manager.js +0 -1432
- package/dist/vendor/engine/runtime/coding-agent/core/settings-diagnostics.d.ts +0 -8
- package/dist/vendor/engine/runtime/coding-agent/core/settings-diagnostics.js +0 -20
- package/dist/vendor/engine/runtime/coding-agent/core/settings-manager.d.ts +0 -346
- package/dist/vendor/engine/runtime/coding-agent/core/settings-manager.js +0 -1032
- package/dist/vendor/engine/runtime/coding-agent/core/skills.d.ts +0 -59
- package/dist/vendor/engine/runtime/coding-agent/core/skills.js +0 -406
- package/dist/vendor/engine/runtime/coding-agent/core/slash-commands.d.ts +0 -14
- package/dist/vendor/engine/runtime/coding-agent/core/slash-commands.js +0 -27
- package/dist/vendor/engine/runtime/coding-agent/core/source-info.d.ts +0 -17
- package/dist/vendor/engine/runtime/coding-agent/core/source-info.js +0 -18
- package/dist/vendor/engine/runtime/coding-agent/core/system-prompt.d.ts +0 -70
- package/dist/vendor/engine/runtime/coding-agent/core/system-prompt.js +0 -146
- package/dist/vendor/engine/runtime/coding-agent/core/telemetry.d.ts +0 -2
- package/dist/vendor/engine/runtime/coding-agent/core/telemetry.js +0 -8
- package/dist/vendor/engine/runtime/coding-agent/core/timings.d.ts +0 -9
- package/dist/vendor/engine/runtime/coding-agent/core/timings.js +0 -40
- package/dist/vendor/engine/runtime/coding-agent/core/tools/render-utils.d.ts +0 -23
- package/dist/vendor/engine/runtime/coding-agent/core/tools/render-utils.js +0 -64
- package/dist/vendor/engine/runtime/coding-agent/core/tools/renderers/bash.d.ts +0 -11
- package/dist/vendor/engine/runtime/coding-agent/core/tools/renderers/bash.js +0 -137
- package/dist/vendor/engine/runtime/coding-agent/core/tools/renderers/edit.d.ts +0 -22
- package/dist/vendor/engine/runtime/coding-agent/core/tools/renderers/edit.js +0 -166
- package/dist/vendor/engine/runtime/coding-agent/core/tools/renderers/find.d.ts +0 -9
- package/dist/vendor/engine/runtime/coding-agent/core/tools/renderers/find.js +0 -63
- package/dist/vendor/engine/runtime/coding-agent/core/tools/renderers/grep.d.ts +0 -9
- package/dist/vendor/engine/runtime/coding-agent/core/tools/renderers/grep.js +0 -68
- package/dist/vendor/engine/runtime/coding-agent/core/tools/renderers/index.d.ts +0 -27
- package/dist/vendor/engine/runtime/coding-agent/core/tools/renderers/index.js +0 -46
- package/dist/vendor/engine/runtime/coding-agent/core/tools/renderers/ls.d.ts +0 -9
- package/dist/vendor/engine/runtime/coding-agent/core/tools/renderers/ls.js +0 -57
- package/dist/vendor/engine/runtime/coding-agent/core/tools/renderers/read.d.ts +0 -10
- package/dist/vendor/engine/runtime/coding-agent/core/tools/renderers/read.js +0 -128
- package/dist/vendor/engine/runtime/coding-agent/core/tools/renderers/write.d.ts +0 -9
- package/dist/vendor/engine/runtime/coding-agent/core/tools/renderers/write.js +0 -152
- package/dist/vendor/engine/runtime/coding-agent/core/trust-manager.d.ts +0 -35
- package/dist/vendor/engine/runtime/coding-agent/core/trust-manager.js +0 -202
- package/dist/vendor/engine/runtime/coding-agent/core/usage-totals.d.ts +0 -18
- package/dist/vendor/engine/runtime/coding-agent/core/usage-totals.js +0 -55
- package/dist/vendor/engine/runtime/coding-agent/extensions/index.d.ts +0 -2
- package/dist/vendor/engine/runtime/coding-agent/extensions/index.js +0 -2
- package/dist/vendor/engine/runtime/coding-agent/extensions/llama/client.d.ts +0 -68
- package/dist/vendor/engine/runtime/coding-agent/extensions/llama/client.js +0 -312
- package/dist/vendor/engine/runtime/coding-agent/extensions/llama/huggingface.d.ts +0 -22
- package/dist/vendor/engine/runtime/coding-agent/extensions/llama/huggingface.js +0 -140
- package/dist/vendor/engine/runtime/coding-agent/extensions/llama/index.d.ts +0 -2
- package/dist/vendor/engine/runtime/coding-agent/extensions/llama/index.js +0 -218
- package/dist/vendor/engine/runtime/coding-agent/extensions/llama/provider.d.ts +0 -11
- package/dist/vendor/engine/runtime/coding-agent/extensions/llama/provider.js +0 -160
- package/dist/vendor/engine/runtime/coding-agent/extensions/llama/ui.d.ts +0 -41
- package/dist/vendor/engine/runtime/coding-agent/extensions/llama/ui.js +0 -415
- package/dist/vendor/engine/runtime/coding-agent/index.d.ts +0 -36
- package/dist/vendor/engine/runtime/coding-agent/index.js +0 -47
- package/dist/vendor/engine/runtime/coding-agent/main.d.ts +0 -15
- package/dist/vendor/engine/runtime/coding-agent/main.js +0 -808
- package/dist/vendor/engine/runtime/coding-agent/migrations.d.ts +0 -32
- package/dist/vendor/engine/runtime/coding-agent/migrations.js +0 -281
- package/dist/vendor/engine/runtime/coding-agent/modes/index.d.ts +0 -9
- package/dist/vendor/engine/runtime/coding-agent/modes/index.js +0 -7
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/bug-report.d.ts +0 -15
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/bug-report.js +0 -209
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/chat-viewport.d.ts +0 -19
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/chat-viewport.js +0 -27
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/armin.d.ts +0 -33
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/armin.js +0 -332
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/assistant-message.d.ts +0 -25
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/assistant-message.js +0 -157
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/bash-execution.d.ts +0 -33
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/bash-execution.js +0 -174
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/bordered-loader.d.ts +0 -15
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/bordered-loader.js +0 -53
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/branch-summary-message.d.ts +0 -15
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/branch-summary-message.js +0 -50
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/compaction-summary-message.d.ts +0 -15
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/compaction-summary-message.js +0 -51
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/config-selector.d.ts +0 -101
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/config-selector.js +0 -760
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/countdown-timer.d.ts +0 -13
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/countdown-timer.js +0 -32
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/custom-editor.d.ts +0 -29
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/custom-editor.js +0 -114
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/custom-entry.d.ts +0 -18
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/custom-entry.js +0 -51
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/custom-message.d.ts +0 -21
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/custom-message.js +0 -86
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/daxnuts.d.ts +0 -22
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/daxnuts.js +0 -139
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/diff.d.ts +0 -11
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/diff.js +0 -132
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/dynamic-border.d.ts +0 -14
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/dynamic-border.js +0 -20
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/earendil-announcement.d.ts +0 -4
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/earendil-announcement.js +0 -39
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/extension-editor.d.ts +0 -23
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/extension-editor.js +0 -102
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/extension-input.d.ts +0 -24
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/extension-input.js +0 -66
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/extension-selector.d.ts +0 -26
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/extension-selector.js +0 -86
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/first-time-setup.d.ts +0 -24
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/first-time-setup.js +0 -102
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/footer.d.ts +0 -31
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/footer.js +0 -224
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/index.d.ts +0 -33
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/index.js +0 -34
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/keybinding-hints.d.ts +0 -12
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/keybinding-hints.js +0 -35
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/login-dialog.d.ts +0 -51
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/login-dialog.js +0 -187
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/markdown-transform.d.ts +0 -2
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/markdown-transform.js +0 -18
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/mermaid.d.ts +0 -10
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/mermaid.js +0 -74
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/model-selector.d.ts +0 -59
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/model-selector.js +0 -360
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/oauth-selector.d.ts +0 -32
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/oauth-selector.js +0 -162
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/scoped-models-selector.d.ts +0 -45
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/scoped-models-selector.js +0 -325
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/session-selector-search.d.ts +0 -22
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/session-selector-search.js +0 -154
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/session-selector.d.ts +0 -94
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/session-selector.js +0 -892
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/settings-selector.d.ts +0 -93
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/settings-selector.js +0 -719
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/settings-submenu.d.ts +0 -71
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/settings-submenu.js +0 -164
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/show-images-selector.d.ts +0 -9
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/show-images-selector.js +0 -38
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/skill-invocation-message.d.ts +0 -16
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/skill-invocation-message.js +0 -53
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/status-indicator.d.ts +0 -29
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/status-indicator.js +0 -66
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/theme-selector.d.ts +0 -10
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/theme-selector.js +0 -49
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/thinking-selector.d.ts +0 -22
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/thinking-selector.js +0 -108
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/tool-execution.d.ts +0 -79
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/tool-execution.js +0 -336
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/tree-selector.d.ts +0 -93
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/tree-selector.js +0 -1246
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/trust-selector.d.ts +0 -22
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/trust-selector.js +0 -90
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/user-message-selector.d.ts +0 -29
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/user-message-selector.js +0 -113
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/user-message.d.ts +0 -15
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/user-message.js +0 -48
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/visual-truncate.d.ts +0 -23
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/visual-truncate.js +0 -32
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/external-editor.d.ts +0 -11
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/external-editor.js +0 -37
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/interactive-mode.d.ts +0 -467
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/interactive-mode.js +0 -5720
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/model-catalog-refresh.d.ts +0 -6
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/model-catalog-refresh.js +0 -33
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/model-search.d.ts +0 -11
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/model-search.js +0 -14
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/session-share.d.ts +0 -17
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/session-share.js +0 -187
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/theme/dark.json +0 -91
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/theme/light.json +0 -90
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/theme/theme-controller.d.ts +0 -40
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/theme/theme-controller.js +0 -129
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/theme/theme-json.d.ts +0 -83
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/theme/theme-json.js +0 -129
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/theme/theme-schema.json +0 -356
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/theme/theme.d.ts +0 -130
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/theme/theme.js +0 -990
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/tui-renderer.d.ts +0 -20
- package/dist/vendor/engine/runtime/coding-agent/modes/interactive/tui-renderer.js +0 -65
- package/dist/vendor/engine/runtime/coding-agent/modes/json-event.d.ts +0 -33
- package/dist/vendor/engine/runtime/coding-agent/modes/json-event.js +0 -28
- package/dist/vendor/engine/runtime/coding-agent/modes/print-mode.d.ts +0 -27
- package/dist/vendor/engine/runtime/coding-agent/modes/print-mode.js +0 -141
- package/dist/vendor/engine/runtime/coding-agent/modes/rpc/jsonl.d.ts +0 -16
- package/dist/vendor/engine/runtime/coding-agent/modes/rpc/jsonl.js +0 -48
- package/dist/vendor/engine/runtime/coding-agent/modes/rpc/rpc-client.d.ts +0 -253
- package/dist/vendor/engine/runtime/coding-agent/modes/rpc/rpc-client.js +0 -494
- package/dist/vendor/engine/runtime/coding-agent/modes/rpc/rpc-mode.d.ts +0 -19
- package/dist/vendor/engine/runtime/coding-agent/modes/rpc/rpc-mode.js +0 -656
- package/dist/vendor/engine/runtime/coding-agent/modes/rpc/rpc-types.d.ts +0 -468
- package/dist/vendor/engine/runtime/coding-agent/modes/rpc/rpc-types.js +0 -7
- package/dist/vendor/engine/runtime/coding-agent/package-manager-cli.d.ts +0 -8
- package/dist/vendor/engine/runtime/coding-agent/package-manager-cli.js +0 -960
- package/dist/vendor/engine/runtime/coding-agent/utils/abort.d.ts +0 -4
- package/dist/vendor/engine/runtime/coding-agent/utils/abort.js +0 -47
- package/dist/vendor/engine/runtime/coding-agent/utils/ansi.d.ts +0 -1
- package/dist/vendor/engine/runtime/coding-agent/utils/ansi.js +0 -51
- package/dist/vendor/engine/runtime/coding-agent/utils/changelog.d.ts +0 -21
- package/dist/vendor/engine/runtime/coding-agent/utils/changelog.js +0 -164
- package/dist/vendor/engine/runtime/coding-agent/utils/clipboard-command.d.ts +0 -6
- package/dist/vendor/engine/runtime/coding-agent/utils/clipboard-command.js +0 -44
- package/dist/vendor/engine/runtime/coding-agent/utils/clipboard-image.d.ts +0 -10
- package/dist/vendor/engine/runtime/coding-agent/utils/clipboard-image.js +0 -216
- package/dist/vendor/engine/runtime/coding-agent/utils/clipboard.d.ts +0 -3
- package/dist/vendor/engine/runtime/coding-agent/utils/clipboard.js +0 -150
- package/dist/vendor/engine/runtime/coding-agent/utils/frontmatter.d.ts +0 -7
- package/dist/vendor/engine/runtime/coding-agent/utils/frontmatter.js +0 -26
- package/dist/vendor/engine/runtime/coding-agent/utils/fs-watch.d.ts +0 -4
- package/dist/vendor/engine/runtime/coding-agent/utils/fs-watch.js +0 -24
- package/dist/vendor/engine/runtime/coding-agent/utils/git.d.ts +0 -25
- package/dist/vendor/engine/runtime/coding-agent/utils/git.js +0 -194
- package/dist/vendor/engine/runtime/coding-agent/utils/html.d.ts +0 -6
- package/dist/vendor/engine/runtime/coding-agent/utils/html.js +0 -39
- package/dist/vendor/engine/runtime/coding-agent/utils/json.d.ts +0 -2
- package/dist/vendor/engine/runtime/coding-agent/utils/json.js +0 -6
- package/dist/vendor/engine/runtime/coding-agent/utils/open-browser.d.ts +0 -8
- package/dist/vendor/engine/runtime/coding-agent/utils/open-browser.js +0 -21
- package/dist/vendor/engine/runtime/coding-agent/utils/pi-user-agent.d.ts +0 -1
- package/dist/vendor/engine/runtime/coding-agent/utils/pi-user-agent.js +0 -4
- package/dist/vendor/engine/runtime/coding-agent/utils/sleep.d.ts +0 -4
- package/dist/vendor/engine/runtime/coding-agent/utils/sleep.js +0 -16
- package/dist/vendor/engine/runtime/coding-agent/utils/syntax-highlight.d.ts +0 -12
- package/dist/vendor/engine/runtime/coding-agent/utils/syntax-highlight.js +0 -176
- package/dist/vendor/engine/runtime/coding-agent/utils/tool-result-images.d.ts +0 -20
- package/dist/vendor/engine/runtime/coding-agent/utils/tool-result-images.js +0 -47
- package/dist/vendor/engine/runtime/coding-agent/utils/version-check.d.ts +0 -18
- package/dist/vendor/engine/runtime/coding-agent/utils/version-check.js +0 -78
- package/dist/vendor/engine/runtime/coding-agent/utils/windows-self-update.d.ts +0 -2
- package/dist/vendor/engine/runtime/coding-agent/utils/windows-self-update.js +0 -76
- package/dist/vendor/engine/runtime/coding-agent/utils/wsl.d.ts +0 -2
- package/dist/vendor/engine/runtime/coding-agent/utils/wsl.js +0 -14
- package/dist/vendor/engine/runtime/coding-agent/utils/zip.d.ts +0 -6
- package/dist/vendor/engine/runtime/coding-agent/utils/zip.js +0 -59
- package/dist/vendor/engine/runtime/tui/alt-screen-search.d.ts +0 -45
- package/dist/vendor/engine/runtime/tui/alt-screen-search.js +0 -281
- package/dist/vendor/engine/runtime/tui/autocomplete.d.ts +0 -56
- package/dist/vendor/engine/runtime/tui/autocomplete.js +0 -671
- package/dist/vendor/engine/runtime/tui/components/alt-screen-flash.d.ts +0 -12
- package/dist/vendor/engine/runtime/tui/components/alt-screen-flash.js +0 -36
- package/dist/vendor/engine/runtime/tui/components/box.d.ts +0 -23
- package/dist/vendor/engine/runtime/tui/components/box.js +0 -132
- package/dist/vendor/engine/runtime/tui/components/cancellable-loader.d.ts +0 -21
- package/dist/vendor/engine/runtime/tui/components/cancellable-loader.js +0 -34
- package/dist/vendor/engine/runtime/tui/components/editor.d.ts +0 -259
- package/dist/vendor/engine/runtime/tui/components/editor.js +0 -2041
- package/dist/vendor/engine/runtime/tui/components/h-stack.d.ts +0 -6
- package/dist/vendor/engine/runtime/tui/components/h-stack.js +0 -42
- package/dist/vendor/engine/runtime/tui/components/image.d.ts +0 -27
- package/dist/vendor/engine/runtime/tui/components/image.js +0 -89
- package/dist/vendor/engine/runtime/tui/components/input.d.ts +0 -47
- package/dist/vendor/engine/runtime/tui/components/input.js +0 -416
- package/dist/vendor/engine/runtime/tui/components/loader.d.ts +0 -32
- package/dist/vendor/engine/runtime/tui/components/loader.js +0 -75
- package/dist/vendor/engine/runtime/tui/components/markdown.d.ts +0 -102
- package/dist/vendor/engine/runtime/tui/components/markdown.js +0 -810
- package/dist/vendor/engine/runtime/tui/components/mouse-region.d.ts +0 -11
- package/dist/vendor/engine/runtime/tui/components/mouse-region.js +0 -20
- package/dist/vendor/engine/runtime/tui/components/scroll-view.d.ts +0 -58
- package/dist/vendor/engine/runtime/tui/components/scroll-view.js +0 -194
- package/dist/vendor/engine/runtime/tui/components/select-list.d.ts +0 -52
- package/dist/vendor/engine/runtime/tui/components/select-list.js +0 -205
- package/dist/vendor/engine/runtime/tui/components/settings-list.d.ts +0 -59
- package/dist/vendor/engine/runtime/tui/components/settings-list.js +0 -251
- package/dist/vendor/engine/runtime/tui/components/spacer.d.ts +0 -11
- package/dist/vendor/engine/runtime/tui/components/spacer.js +0 -22
- package/dist/vendor/engine/runtime/tui/components/stack.d.ts +0 -31
- package/dist/vendor/engine/runtime/tui/components/stack.js +0 -110
- package/dist/vendor/engine/runtime/tui/components/text.d.ts +0 -18
- package/dist/vendor/engine/runtime/tui/components/text.js +0 -89
- package/dist/vendor/engine/runtime/tui/components/truncated-text.d.ts +0 -12
- package/dist/vendor/engine/runtime/tui/components/truncated-text.js +0 -50
- package/dist/vendor/engine/runtime/tui/components/v-stack.d.ts +0 -7
- package/dist/vendor/engine/runtime/tui/components/v-stack.js +0 -25
- package/dist/vendor/engine/runtime/tui/editor-component.d.ts +0 -38
- package/dist/vendor/engine/runtime/tui/editor-component.js +0 -1
- package/dist/vendor/engine/runtime/tui/fuzzy.d.ts +0 -15
- package/dist/vendor/engine/runtime/tui/fuzzy.js +0 -110
- package/dist/vendor/engine/runtime/tui/index.d.ts +0 -32
- package/dist/vendor/engine/runtime/tui/index.js +0 -44
- package/dist/vendor/engine/runtime/tui/keybindings.d.ts +0 -272
- package/dist/vendor/engine/runtime/tui/keybindings.js +0 -232
- package/dist/vendor/engine/runtime/tui/keys.d.ts +0 -183
- package/dist/vendor/engine/runtime/tui/keys.js +0 -1173
- package/dist/vendor/engine/runtime/tui/kill-ring.d.ts +0 -27
- package/dist/vendor/engine/runtime/tui/kill-ring.js +0 -43
- package/dist/vendor/engine/runtime/tui/latex.d.ts +0 -9
- package/dist/vendor/engine/runtime/tui/latex.js +0 -1377
- package/dist/vendor/engine/runtime/tui/layout-node.d.ts +0 -39
- package/dist/vendor/engine/runtime/tui/layout-node.js +0 -5
- package/dist/vendor/engine/runtime/tui/layout.d.ts +0 -41
- package/dist/vendor/engine/runtime/tui/layout.js +0 -343
- package/dist/vendor/engine/runtime/tui/native-modifiers.d.ts +0 -3
- package/dist/vendor/engine/runtime/tui/native-modifiers.js +0 -12
- package/dist/vendor/engine/runtime/tui/native-module-path.d.ts +0 -6
- package/dist/vendor/engine/runtime/tui/native-module-path.js +0 -18
- package/dist/vendor/engine/runtime/tui/native-platform.d.ts +0 -17
- package/dist/vendor/engine/runtime/tui/native-platform.js +0 -41
- package/dist/vendor/engine/runtime/tui/stdin-buffer.d.ts +0 -55
- package/dist/vendor/engine/runtime/tui/stdin-buffer.js +0 -365
- package/dist/vendor/engine/runtime/tui/terminal-colors.d.ts +0 -9
- package/dist/vendor/engine/runtime/tui/terminal-colors.js +0 -58
- package/dist/vendor/engine/runtime/tui/terminal-image.d.ts +0 -117
- package/dist/vendor/engine/runtime/tui/terminal-image.js +0 -549
- package/dist/vendor/engine/runtime/tui/terminal.d.ts +0 -122
- package/dist/vendor/engine/runtime/tui/terminal.js +0 -441
- package/dist/vendor/engine/runtime/tui/tui-alt-screen.d.ts +0 -159
- package/dist/vendor/engine/runtime/tui/tui-alt-screen.js +0 -1507
- package/dist/vendor/engine/runtime/tui/tui-main-screen.d.ts +0 -38
- package/dist/vendor/engine/runtime/tui/tui-main-screen.js +0 -593
- package/dist/vendor/engine/runtime/tui/tui.d.ts +0 -385
- package/dist/vendor/engine/runtime/tui/tui.js +0 -1054
- package/dist/vendor/engine/runtime/tui/undo-stack.d.ts +0 -16
- package/dist/vendor/engine/runtime/tui/undo-stack.js +0 -24
- package/dist/vendor/engine/runtime/tui/utils.d.ts +0 -100
- package/dist/vendor/engine/runtime/tui/utils.js +0 -1203
- package/dist/vendor/engine/runtime/tui/word-navigation.d.ts +0 -24
- package/dist/vendor/engine/runtime/tui/word-navigation.js +0 -95
- package/tests/graphiti-test-plan.md +0 -359
- package/tests/mock-graphiti.mjs +0 -106
- /package/dist/vendor/engine/runtime/{agent/harness/tools/tool-context.js → coding-agent/core/tools/tool-definition.js} +0 -0
|
@@ -0,0 +1,2859 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Refusing a command that would stop the app this engine runs inside.
|
|
3
|
+
*
|
|
4
|
+
* A desktop engine is a child of the desktop shell, and its tools run with the user's own rights,
|
|
5
|
+
* so one command can end the window, the run, and every other run that window hosts. That is not
|
|
6
|
+
* hypothetical: on 2026-11-12 an agent testing the desktop app launched a second copy, the copy
|
|
7
|
+
* handed itself to the window already open (they shared an application identifier), and the agent
|
|
8
|
+
* then stopped every process named `andorra-desktop.exe` to clean up "its own" instance. The only
|
|
9
|
+
* such process was its host.
|
|
10
|
+
*
|
|
11
|
+
* The shell tells the engine who its host is (`ANDORRA_DESKTOP_HOST_PID` and
|
|
12
|
+
* `ANDORRA_DESKTOP_HOST_NAME`, set in `desktop/src-tauri/src/engine.rs`). A command is refused when
|
|
13
|
+
* it both terminates processes and names the host: by its image name, which a by-name kill would
|
|
14
|
+
* match, or by its process id. The engine's own process id is protected the same way. "Terminates"
|
|
15
|
+
* means a kill the shell would actually run, not the words in a quoted search pattern or message.
|
|
16
|
+
*
|
|
17
|
+
* This is a guard against an honest mistake, not a security boundary: a command built at run time
|
|
18
|
+
* or hidden behind a script can still do it. What it buys is that the plain form of the mistake
|
|
19
|
+
* comes back as an instruction (stop the process you started, by its id) instead of a dead window.
|
|
20
|
+
*/
|
|
21
|
+
function positiveInteger(value) {
|
|
22
|
+
if (!value || !/^[0-9]{1,10}$/.test(value.trim()))
|
|
23
|
+
return undefined;
|
|
24
|
+
const number = Number(value.trim());
|
|
25
|
+
return Number.isSafeInteger(number) && number > 0 ? number : undefined;
|
|
26
|
+
}
|
|
27
|
+
/** The host as the shell declared it. Outside the desktop app only the engine's own id is known. */
|
|
28
|
+
export function hostProcess(env = process.env, self = process.pid) {
|
|
29
|
+
const pid = positiveInteger(env.ANDORRA_DESKTOP_HOST_PID);
|
|
30
|
+
const name = env.ANDORRA_DESKTOP_HOST_NAME?.trim();
|
|
31
|
+
return { self, ...(pid === undefined ? {} : { pid }), ...(name ? { name } : {}) };
|
|
32
|
+
}
|
|
33
|
+
/** Programs and cmdlets whose whole job is ending a process, by the name they are invoked under. */
|
|
34
|
+
const KILLERS = new Set(['stop-process', 'spps', 'kill', 'pkill', 'killall', 'taskkill', 'tskill', 'remove-ciminstance', 'remove-wmiobject', 'rcim', 'rwmi']);
|
|
35
|
+
/** The killers that are PowerShell cmdlets, which take `-WhatIf`; `kill` is Stop-Process's alias. */
|
|
36
|
+
const WHATIF_CMDLETS = new Set(['stop-process', 'spps', 'kill', 'remove-ciminstance', 'remove-wmiobject', 'rcim', 'rwmi']);
|
|
37
|
+
/** Whether a cmdlet's arguments switch `-WhatIf` on, and nothing later switches it off. */
|
|
38
|
+
function previewsOnly(args) {
|
|
39
|
+
let preview = false;
|
|
40
|
+
for (const argument of args) {
|
|
41
|
+
const match = /^-w(?:h(?:a(?:t(?:i(?:f)?)?)?)?)?(?::(\$true|\$false|true|false|1|0))?$/i.exec(argument);
|
|
42
|
+
if (match)
|
|
43
|
+
preview = match[1] === undefined || /^(?:\$true|true|1)$/i.test(match[1]);
|
|
44
|
+
}
|
|
45
|
+
return preview;
|
|
46
|
+
}
|
|
47
|
+
/** Tools that end a process only when asked to: `wmic … delete`, `Invoke-CimMethod … Terminate`. */
|
|
48
|
+
const CONDITIONAL_KILLERS = new Set(['wmic', 'invoke-cimmethod', 'invoke-wmimethod', 'icim', 'iwmi']);
|
|
49
|
+
/** Programs that run their argument as code or as another command line. */
|
|
50
|
+
const INTERPRETERS = new Set(['node', 'nodejs', 'python', 'python3', 'py', 'powershell', 'pwsh', 'bash', 'sh', 'zsh', 'cmd', 'iex', 'invoke-expression', 'eval', 'ruby', 'perl', 'deno', 'bun']);
|
|
51
|
+
/** Words that only introduce the command that follows them. */
|
|
52
|
+
const PREFIXES = new Set(['&', '.', 'sudo', 'doas', 'exec', 'command', 'builtin', 'noglob', 'nocorrect', 'nohup', 'env', 'time', 'timeout', 'xargs', 'call', 'start', 'nice', 'ionice', 'stdbuf', 'setsid',
|
|
53
|
+
'if', 'elseif', 'else', 'then', 'do', 'while', 'until', 'for', 'foreach', 'try', 'catch', 'finally', 'return', '!', 'foreach-object', '%', 'where-object', '?']);
|
|
54
|
+
/**
|
|
55
|
+
* A wrapper's options that take a value, lower-cased: `env -u NAME`, `sudo -u USER`,
|
|
56
|
+
* `timeout -s SIGNAL`. The value is not the wrapped command. Where an option only sometimes takes
|
|
57
|
+
* one, both readings are judged, so getting the table wrong can only refuse more.
|
|
58
|
+
*/
|
|
59
|
+
const WRAPPER_VALUES = {
|
|
60
|
+
env: new Set(['-u', '--unset', '-c', '--chdir']),
|
|
61
|
+
sudo: new Set(['-u', '--user', '-g', '--group', '-c', '--close-from', '-d', '--chdir', '-h', '--host', '-p', '--prompt', '-r', '--role', '-t', '--type', '--other-user', '--command-timeout', '--chroot']),
|
|
62
|
+
doas: new Set(['-u', '-c']),
|
|
63
|
+
timeout: new Set(['-s', '--signal', '-k', '--kill-after']),
|
|
64
|
+
xargs: new Set(['-i', '-n', '--max-args', '-l', '--max-lines', '-p', '--max-procs', '-s', '--max-chars', '-d', '--delimiter', '-e', '--eof', '-a', '--arg-file', '--replace']),
|
|
65
|
+
exec: new Set(['-a']),
|
|
66
|
+
nice: new Set(['-n', '--adjustment']),
|
|
67
|
+
ionice: new Set(['-c', '--class', '-n', '--classdata', '-p', '--pid']),
|
|
68
|
+
stdbuf: new Set(['-i', '-o', '-e']),
|
|
69
|
+
time: new Set(['-f', '--format', '-o', '--output']),
|
|
70
|
+
start: new Set(['/d']),
|
|
71
|
+
};
|
|
72
|
+
/** Start-Process parameters that take a value, other than the program and its arguments. */
|
|
73
|
+
const START_PROCESS_VALUES = /^-(?:workingdirectory|wd|verb|windowstyle|credential|redirectstandard(?:error|input|output)|environment)$/;
|
|
74
|
+
/** A process ended from code: .NET's `.Kill()`, WMI's `.Terminate()`, Node's and Python's kill calls. */
|
|
75
|
+
// JavaScript may call through optional chaining: `process?.kill?.(…)`, `p?.Kill?.()`.
|
|
76
|
+
// Ruby calls without parentheses: `Process.kill 15, 80632`.
|
|
77
|
+
// Python and the others allow blanks around the dot: `os . kill(…)`.
|
|
78
|
+
const KILL_CALL = /\.\s*(?:Kill|Terminate)\s*(?:\?\.\s*)?\(|\bprocess\s*\??\.\s*kill\s*(?:\?\.\s*)?\(|\bProcess\s*\.\s*kill[ \t]+[^\s=]|\bos\s*\.\s*kill\s*\(|\bkillpg\s*\(/i;
|
|
79
|
+
/** The same calls with signal 0, which only asks whether the process exists. */
|
|
80
|
+
const PROBE_CALL = /\b(?:process|os)\s*\??\.\s*kill\s*(?:\?\.\s*)?\([^(),]*,\s*0\s*\)/gi;
|
|
81
|
+
/**
|
|
82
|
+
* Ruby's probe names the signal first: `Process.kill(0, pid)`, `Process.kill 0, pid`. Case-sensitive,
|
|
83
|
+
* since Node's `process.kill(0, 9)` signals process group 0.
|
|
84
|
+
*/
|
|
85
|
+
// Without parentheses the probe's arguments are a comma list of simple values; whatever follows
|
|
86
|
+
// (`and Process.kill 15, pid`) is another expression and is still judged.
|
|
87
|
+
const RUBY_PROBE_CALL = /\bProcess\s*\.\s*kill(?:\s*\(\s*0\s*,[^()]*\)|[ \t]+0[ \t]*,[ \t]*[\w$@.:]+(?:[ \t]*,[ \t]*[\w$@.:]+)*)/g;
|
|
88
|
+
/**
|
|
89
|
+
* The texts derived while judging one command — rendered `printf` and `echo` output, pipeline
|
|
90
|
+
* input, interpreter code. The host's id may appear only there (`printf 'kill %d' 0x13af8`), so the
|
|
91
|
+
* final check searches them too. Set for the length of one top-level check.
|
|
92
|
+
*/
|
|
93
|
+
let evidence;
|
|
94
|
+
function note(text) {
|
|
95
|
+
if (evidence !== undefined && evidence.length < 500)
|
|
96
|
+
evidence.push(text);
|
|
97
|
+
}
|
|
98
|
+
/** Whether code ends a process through a kill call; a signal-0 probe is not one. */
|
|
99
|
+
function callsKill(code) {
|
|
100
|
+
return KILL_CALL.test(code.replace(PROBE_CALL, '').replace(RUBY_PROBE_CALL, ''));
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Whether a `kill`, `pkill` or `killall` invocation only probes, by that command's own syntax.
|
|
104
|
+
* Signal 0 delivers nothing; it reports whether the process exists. `kill` and `killall` name a
|
|
105
|
+
* signal with `-s` (and `kill` with `-n`); to `pkill`, `-s` is a session filter, so
|
|
106
|
+
* `pkill -s 0 -f name` signals every match in the caller's session and is no probe.
|
|
107
|
+
*/
|
|
108
|
+
function probesOnly(word, args) {
|
|
109
|
+
const selectors = word === 'kill' ? ['-s', '-n', '--signal'] : word === 'killall' ? ['-s', '--signal'] : ['--signal'];
|
|
110
|
+
// `kill` may be the shell's builtin, which takes the first signal option, or an external program
|
|
111
|
+
// (`/bin/kill`, or run through `env`, `sudo`, `xargs`), which takes the last: `kill -s 0 -s TERM`
|
|
112
|
+
// sends TERM there. It only probes when both readings say signal 0.
|
|
113
|
+
if (word === 'kill')
|
|
114
|
+
return builtinKillProbes(args, selectors) && lastSignal(args, selectors) === '0';
|
|
115
|
+
return lastSignal(args, selectors) === '0';
|
|
116
|
+
}
|
|
117
|
+
/** Whether the shell's builtin `kill` sends signal 0: its first option names the signal. */
|
|
118
|
+
function builtinKillProbes(args, selectors) {
|
|
119
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
120
|
+
const argument = args[index];
|
|
121
|
+
// Past `--` every argument is an operand: `kill -- 80632 -0` signals 80632 and group 0.
|
|
122
|
+
if (argument === '--')
|
|
123
|
+
return false;
|
|
124
|
+
// kill reads its signal from its first option, and its options end at the first operand:
|
|
125
|
+
// `kill -9 -0 80632` sends SIGKILL to group 0 and to 80632, `kill 80632 -0` SIGTERM to both.
|
|
126
|
+
if (selectors.includes(argument))
|
|
127
|
+
return args[index + 1] === '0';
|
|
128
|
+
if (/^--signal=/.test(argument))
|
|
129
|
+
return argument === '--signal=0';
|
|
130
|
+
if (/^-[sn]./.test(argument))
|
|
131
|
+
return argument.slice(2) === '0';
|
|
132
|
+
return argument === '-0';
|
|
133
|
+
}
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* The last signal an option-order-free killer is given — pkill, killall, the external kill — which
|
|
138
|
+
* is the one it sends: `pkill -0 --signal TERM -f name` sends TERM.
|
|
139
|
+
*/
|
|
140
|
+
function lastSignal(args, selectors) {
|
|
141
|
+
let signal;
|
|
142
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
143
|
+
const argument = args[index];
|
|
144
|
+
if (argument === '--')
|
|
145
|
+
break;
|
|
146
|
+
if (argument.startsWith('--signal='))
|
|
147
|
+
signal = argument.slice('--signal='.length);
|
|
148
|
+
else if (selectors.includes(argument)) {
|
|
149
|
+
signal = args[index + 1];
|
|
150
|
+
index += 1;
|
|
151
|
+
}
|
|
152
|
+
else if (selectors.some(selector => selector.length === 2 && argument.startsWith(selector) && argument.length > 2))
|
|
153
|
+
signal = argument.slice(2);
|
|
154
|
+
// `-9`, `-0`, `-TERM`, `-SIGKILL`; a single capital letter is another option (`-P`, `-U`).
|
|
155
|
+
else if (/^-(?:\d+|(?:SIG)?[A-Z]{2,}[0-9+-]*)$/.test(argument))
|
|
156
|
+
signal = argument.slice(1);
|
|
157
|
+
}
|
|
158
|
+
return signal;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* A string literal handed to something that runs it: `execSync('…')`, `spawn('…'`,
|
|
162
|
+
* `subprocess.run('…'` or `run(['…'`, `os.system('…')`. The literal is the first argument, or the
|
|
163
|
+
* first element of an array that is. The capture is the literal's slot in the scanned text.
|
|
164
|
+
*/
|
|
165
|
+
// Python may pass the command by keyword, after other keywords: `subprocess.run(args=["kill", …])`.
|
|
166
|
+
const RUNS_LITERAL = /(\.?)\b(exec|execSync|execFile|execFileSync|spawn|spawnSync|system|popen|Popen|run|call|check_call|check_output|getoutput|shell_exec|passthru)\s*(?:\?\.\s*)?\(\s*(?:[^()]*?\bargs\s*=\s*)?([[(]?)\s*\u0000(\d+)\u0000/g;
|
|
167
|
+
/** The names [RUNS_LITERAL] reads as launchers, whole. */
|
|
168
|
+
const LAUNCHER_NAMES = /^(?:exec|execSync|execFile|execFileSync|spawn|spawnSync|system|popen|Popen|run|call|check_call|check_output|getoutput|shell_exec|passthru)$/;
|
|
169
|
+
/** JavaScript's evaluators of a string: `eval`, `Function`, `vm.runIn…Context`, string timers. */
|
|
170
|
+
const JS_EVAL = /\b(?:eval|Function|runInThisContext|runInNewContext|runInContext|compileFunction|setTimeout|setInterval|setImmediate)\s*(?:\?\.\s*)?\(/g;
|
|
171
|
+
/** The slot of the call's first argument when that argument is a single literal, or -1. */
|
|
172
|
+
function firstArgumentSlot(text, start) {
|
|
173
|
+
const first = /^\s*\u0000(\d+)\u0000\s*(?:[,)])/.exec(text.slice(start));
|
|
174
|
+
return first ? Number(first[1]) : -1;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* The slots of the literal arguments of the call whose argument list starts at `start` (just past
|
|
178
|
+
* its `(`), at the call's own level: `Function('x', 'body')` gives both.
|
|
179
|
+
*/
|
|
180
|
+
function callLiterals(text, start) {
|
|
181
|
+
const slots = [];
|
|
182
|
+
let depth = 1;
|
|
183
|
+
for (let index = start; index < text.length && depth > 0; index += 1) {
|
|
184
|
+
const character = text[index];
|
|
185
|
+
if ('([{'.includes(character))
|
|
186
|
+
depth += 1;
|
|
187
|
+
else if (')]}'.includes(character))
|
|
188
|
+
depth -= 1;
|
|
189
|
+
else if (character === '\u0000' && depth === 1) {
|
|
190
|
+
const slot = /^\u0000(\d+)\u0000/.exec(text.slice(index));
|
|
191
|
+
if (slot) {
|
|
192
|
+
slots.push(Number(slot[1]));
|
|
193
|
+
index += slot[0].length - 1;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return slots;
|
|
198
|
+
}
|
|
199
|
+
/** Python's, Ruby's and Perl's: `exec`, `eval`, `compile`, `instance_eval`, Perl's `eval '…'`. */
|
|
200
|
+
const HASH_EVAL = /\b(?:exec|eval|instance_eval|class_eval|module_eval)\s*\(?\s*\u0000(\d+)\u0000/g;
|
|
201
|
+
/** Python's `compile('…')`, which only builds a code object: its source runs once `exec` or `eval` is called. */
|
|
202
|
+
const PY_COMPILE = /\bcompile\s*\(\s*\u0000(\d+)\u0000/g;
|
|
203
|
+
/** A method looked up by a string: `process['kill'](…)`. The capture is the literal's slot. */
|
|
204
|
+
const INDEXED_CALL = /\[\s*\u0000(\d+)\u0000\s*\]\s*(?:\?\.\s*)?\(([^()]*)\)?/g;
|
|
205
|
+
/**
|
|
206
|
+
* Whether a call matched by [RUNS_LITERAL] starts a process, as far as its name and receiver say.
|
|
207
|
+
*
|
|
208
|
+
* Most of the names only ever mean that. Three are shared with unrelated APIs and need more:
|
|
209
|
+
* `exec` is also `RegExp.prototype.exec`, so as a method it counts only in code that uses
|
|
210
|
+
* `child_process` and not on a regular-expression literal; `run` and `call` count only in code
|
|
211
|
+
* that uses `subprocess`.
|
|
212
|
+
*/
|
|
213
|
+
function startsProcess(name, isMethod, before, code, regexes) {
|
|
214
|
+
if (name === 'exec') {
|
|
215
|
+
if (!isMethod)
|
|
216
|
+
return true;
|
|
217
|
+
const receiver = /\u0000(\d+)\u0000\s*$/.exec(before);
|
|
218
|
+
return /\bchild_process\b/.test(code) && !(receiver && regexes.has(Number(receiver[1])));
|
|
219
|
+
}
|
|
220
|
+
if (name === 'run' || name === 'call')
|
|
221
|
+
return /\bsubprocess\b/.test(code);
|
|
222
|
+
return true;
|
|
223
|
+
}
|
|
224
|
+
/** The shell a tool's [ShellKind] runs: PowerShell, or a POSIX shell (Bash or `/bin/sh`). */
|
|
225
|
+
export function hostShellOf(kind) {
|
|
226
|
+
return kind === 'powershell' ? 'powershell' : 'posix';
|
|
227
|
+
}
|
|
228
|
+
/** The rules an interpreter reads its code by. */
|
|
229
|
+
function dialectOf(word) {
|
|
230
|
+
if (word === 'node' || word === 'nodejs' || word === 'deno' || word === 'bun')
|
|
231
|
+
return 'js';
|
|
232
|
+
if (word === 'python' || word === 'python3' || word === 'py')
|
|
233
|
+
return 'hash';
|
|
234
|
+
if (word === 'ruby')
|
|
235
|
+
return 'ruby';
|
|
236
|
+
if (word === 'perl')
|
|
237
|
+
return 'perl';
|
|
238
|
+
if (word === 'powershell' || word === 'pwsh' || word === 'iex' || word === 'invoke-expression')
|
|
239
|
+
return 'powershell';
|
|
240
|
+
if (word === 'cmd')
|
|
241
|
+
return 'cmd';
|
|
242
|
+
return 'posix';
|
|
243
|
+
}
|
|
244
|
+
/** The character that escapes the next one: Bash's backslash, PowerShell's backtick, cmd's caret. */
|
|
245
|
+
function escapeOf(dialect) {
|
|
246
|
+
return dialect === 'powershell' ? '`' : dialect === 'cmd' ? '^' : '\\';
|
|
247
|
+
}
|
|
248
|
+
/** Whether the escape character works outside quotes: in the shells, not in program code. */
|
|
249
|
+
function escapesOutside(dialect) {
|
|
250
|
+
return dialect === 'posix' || dialect === 'powershell' || dialect === 'cmd';
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* The index of the quote that closes the span opening at `index`, the text's length when it never
|
|
254
|
+
* closes, or `undefined` when the character there opens no span in this dialect.
|
|
255
|
+
*/
|
|
256
|
+
function quoteEnd(text, index, dialect) {
|
|
257
|
+
const quote = text[index];
|
|
258
|
+
const opens = quote === '"' || (quote === "'" && dialect !== 'cmd') || (quote === '`' && dialect === 'js');
|
|
259
|
+
if (!opens)
|
|
260
|
+
return undefined;
|
|
261
|
+
// Bash escapes only in "…" and $'…'; PowerShell only in "…"; cmd never; program code always.
|
|
262
|
+
const escapes = dialect === 'js' || dialect === 'hash' || dialect === 'ruby' || dialect === 'perl' ? true
|
|
263
|
+
: dialect === 'posix' ? quote === '"' || text[index - 1] === '$'
|
|
264
|
+
: dialect === 'powershell' ? quote === '"' : false;
|
|
265
|
+
const escape = escapeOf(dialect);
|
|
266
|
+
// Python's `"""…"""` and `'''…'''` hold single quotes of the same kind; the span ends at the
|
|
267
|
+
// closing triple, and the index returned is its last quote.
|
|
268
|
+
if (dialect === 'hash' && (quote === '"' || quote === "'") && text.startsWith(quote.repeat(3), index)) {
|
|
269
|
+
const closing = quote.repeat(3);
|
|
270
|
+
let at = index + 3;
|
|
271
|
+
while (at < text.length) {
|
|
272
|
+
if (text[at] === '\\') {
|
|
273
|
+
at += 2;
|
|
274
|
+
continue;
|
|
275
|
+
}
|
|
276
|
+
if (text.startsWith(closing, at))
|
|
277
|
+
return at + 2;
|
|
278
|
+
at += 1;
|
|
279
|
+
}
|
|
280
|
+
return text.length;
|
|
281
|
+
}
|
|
282
|
+
let end = index + 1;
|
|
283
|
+
while (end < text.length) {
|
|
284
|
+
const character = text[end];
|
|
285
|
+
if (escapes && character === escape) {
|
|
286
|
+
end += 2;
|
|
287
|
+
continue;
|
|
288
|
+
}
|
|
289
|
+
if (character === quote) {
|
|
290
|
+
// PowerShell doubles a quote to put one inside the same kind of string.
|
|
291
|
+
if (dialect === 'powershell' && text[end + 1] === quote) {
|
|
292
|
+
end += 2;
|
|
293
|
+
continue;
|
|
294
|
+
}
|
|
295
|
+
return end;
|
|
296
|
+
}
|
|
297
|
+
// A template literal's `${ … }` is code, and may hold quotes and templates of its own.
|
|
298
|
+
if (quote === '`' && character === '$' && text[end + 1] === '{') {
|
|
299
|
+
end = braceEnd(text, end + 1, dialect);
|
|
300
|
+
continue;
|
|
301
|
+
}
|
|
302
|
+
// So is Bash's `$( … )` inside "…": its quotes nest, so `"$(echo "a)b")"` is one string.
|
|
303
|
+
if (dialect === 'posix' && quote === '"' && character === '$' && text[end + 1] === '(') {
|
|
304
|
+
end = parenEnd(text, end + 1);
|
|
305
|
+
continue;
|
|
306
|
+
}
|
|
307
|
+
end += 1;
|
|
308
|
+
}
|
|
309
|
+
return text.length;
|
|
310
|
+
}
|
|
311
|
+
/** The index just past the `)` that closes the `(` at `open` in a POSIX line, skipping quoted spans inside. */
|
|
312
|
+
function parenEnd(text, open) {
|
|
313
|
+
let depth = 0;
|
|
314
|
+
let index = open;
|
|
315
|
+
while (index < text.length) {
|
|
316
|
+
const character = text[index];
|
|
317
|
+
if (character === '\\') {
|
|
318
|
+
index += 2;
|
|
319
|
+
continue;
|
|
320
|
+
}
|
|
321
|
+
if (character === '(')
|
|
322
|
+
depth += 1;
|
|
323
|
+
else if (character === ')') {
|
|
324
|
+
depth -= 1;
|
|
325
|
+
if (depth === 0)
|
|
326
|
+
return index + 1;
|
|
327
|
+
}
|
|
328
|
+
else {
|
|
329
|
+
const close = quoteEnd(text, index, 'posix');
|
|
330
|
+
if (close !== undefined) {
|
|
331
|
+
index = close + 1;
|
|
332
|
+
continue;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
index += 1;
|
|
336
|
+
}
|
|
337
|
+
return text.length;
|
|
338
|
+
}
|
|
339
|
+
/** The index just past the `}` that closes the `{` at `open`, skipping quoted spans inside. */
|
|
340
|
+
function braceEnd(text, open, dialect) {
|
|
341
|
+
let depth = 0;
|
|
342
|
+
let index = open;
|
|
343
|
+
while (index < text.length) {
|
|
344
|
+
const character = text[index];
|
|
345
|
+
if (character === '{')
|
|
346
|
+
depth += 1;
|
|
347
|
+
else if (character === '}') {
|
|
348
|
+
depth -= 1;
|
|
349
|
+
if (depth === 0)
|
|
350
|
+
return index + 1;
|
|
351
|
+
}
|
|
352
|
+
else {
|
|
353
|
+
const close = quoteEnd(text, index, dialect);
|
|
354
|
+
if (close !== undefined) {
|
|
355
|
+
index = close + 1;
|
|
356
|
+
continue;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
index += 1;
|
|
360
|
+
}
|
|
361
|
+
return text.length;
|
|
362
|
+
}
|
|
363
|
+
/** Whether a `/` can open a regular-expression literal here, judged by the code before it. */
|
|
364
|
+
function regexMayStart(before) {
|
|
365
|
+
const trimmed = before.trimEnd();
|
|
366
|
+
if (trimmed === '')
|
|
367
|
+
return true;
|
|
368
|
+
if (/[(,=:[!&|?{;+\-*%<>~^/]$/.test(trimmed))
|
|
369
|
+
return true;
|
|
370
|
+
// After a block's `}` a statement, so a regex, may start; after an object literal's `}` a `/`
|
|
371
|
+
// divides. Which one it is takes a parser to know, so [codeTerminates] reads such code both ways.
|
|
372
|
+
if (trimmed.endsWith('}'))
|
|
373
|
+
return braceStartsRegex;
|
|
374
|
+
// `if (x) /re/.test(…)`: after a control-flow header's `)` a statement starts, which may be a regex.
|
|
375
|
+
if (trimmed.endsWith(')')) {
|
|
376
|
+
let depth = 0;
|
|
377
|
+
for (let index = trimmed.length - 1; index >= 0; index -= 1) {
|
|
378
|
+
if (trimmed[index] === ')')
|
|
379
|
+
depth += 1;
|
|
380
|
+
else if (trimmed[index] === '(' && --depth === 0)
|
|
381
|
+
return /\b(?:if|while|for|with)\s*$/.test(trimmed.slice(0, index));
|
|
382
|
+
}
|
|
383
|
+
return false;
|
|
384
|
+
}
|
|
385
|
+
return /\b(?:return|typeof|case|do|else|in|of|new|delete|void|throw|yield|await)$/.test(trimmed);
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* The index just past a regular-expression literal opening at `start`, with its flags, or -1 when
|
|
389
|
+
* no literal closes on that line: then the slash was division, or the code does not parse at all.
|
|
390
|
+
*/
|
|
391
|
+
function regexEnd(text, start) {
|
|
392
|
+
let index = start + 1;
|
|
393
|
+
let inClass = false;
|
|
394
|
+
while (index < text.length && text[index] !== '\n') {
|
|
395
|
+
const character = text[index];
|
|
396
|
+
if (character === '\\') {
|
|
397
|
+
index += 2;
|
|
398
|
+
continue;
|
|
399
|
+
}
|
|
400
|
+
if (character === '[')
|
|
401
|
+
inClass = true;
|
|
402
|
+
else if (character === ']')
|
|
403
|
+
inClass = false;
|
|
404
|
+
else if (character === '/' && !inClass) {
|
|
405
|
+
index += 1;
|
|
406
|
+
while (/[a-z]/i.test(text[index] ?? ''))
|
|
407
|
+
index += 1;
|
|
408
|
+
return index;
|
|
409
|
+
}
|
|
410
|
+
index += 1;
|
|
411
|
+
}
|
|
412
|
+
return -1;
|
|
413
|
+
}
|
|
414
|
+
/** Whether a regular-expression literal opens at `index` in JavaScript, given the code before it. */
|
|
415
|
+
function regexAt(text, index, before) {
|
|
416
|
+
if (text[index] !== '/' || text[index + 1] === '/' || text[index + 1] === '*' || !regexMayStart(before))
|
|
417
|
+
return undefined;
|
|
418
|
+
const end = regexEnd(text, index);
|
|
419
|
+
return end === -1 ? undefined : end;
|
|
420
|
+
}
|
|
421
|
+
/**
|
|
422
|
+
* Remove comments by the dialect's own rules, leaving quoted text untouched.
|
|
423
|
+
*
|
|
424
|
+
* A comment never runs: `// process.kill(80632)` above `console.log('ok')` only prints. Each
|
|
425
|
+
* dialect has its own: `#` at the start of a word in the shells and in Python, Ruby and Perl;
|
|
426
|
+
* `<# … #>` in PowerShell; `//` and `/* … *\/` in JavaScript, and nowhere else — in Python `//`
|
|
427
|
+
* divides, and on a Git Bash line it is a switch such as `taskkill //PID`. cmd.exe has none here.
|
|
428
|
+
* An escaped character is never the start of a comment, and an escaped blank does not end a word.
|
|
429
|
+
*/
|
|
430
|
+
function stripComments(text, dialect) {
|
|
431
|
+
if (dialect === 'cmd')
|
|
432
|
+
return text;
|
|
433
|
+
let out = '';
|
|
434
|
+
let index = 0;
|
|
435
|
+
let afterEscape = false;
|
|
436
|
+
while (index < text.length) {
|
|
437
|
+
const character = text[index];
|
|
438
|
+
if (escapesOutside(dialect) && character === escapeOf(dialect)) {
|
|
439
|
+
out += text.slice(index, index + 2);
|
|
440
|
+
index += 2;
|
|
441
|
+
afterEscape = true;
|
|
442
|
+
continue;
|
|
443
|
+
}
|
|
444
|
+
const wordStart = !afterEscape && (index === 0 || /[\s;|&(]/.test(text[index - 1]));
|
|
445
|
+
afterEscape = false;
|
|
446
|
+
const close = quoteEnd(text, index, dialect);
|
|
447
|
+
if (close !== undefined) {
|
|
448
|
+
out += text.slice(index, close + 1);
|
|
449
|
+
index = close + 1;
|
|
450
|
+
continue;
|
|
451
|
+
}
|
|
452
|
+
if (dialect === 'js' && character === '/') {
|
|
453
|
+
if (text[index + 1] === '/') {
|
|
454
|
+
const end = text.indexOf('\n', index);
|
|
455
|
+
index = end === -1 ? text.length : end;
|
|
456
|
+
continue;
|
|
457
|
+
}
|
|
458
|
+
if (text[index + 1] === '*') {
|
|
459
|
+
const end = text.indexOf('*/', index + 2);
|
|
460
|
+
index = end === -1 ? text.length : end + 2;
|
|
461
|
+
out += ' ';
|
|
462
|
+
continue;
|
|
463
|
+
}
|
|
464
|
+
const end = regexAt(text, index, out);
|
|
465
|
+
if (end !== undefined) {
|
|
466
|
+
out += text.slice(index, end);
|
|
467
|
+
index = end;
|
|
468
|
+
continue;
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
if (dialect === 'powershell' && character === '<' && text[index + 1] === '#' && wordStart) {
|
|
472
|
+
const end = text.indexOf('#>', index + 2);
|
|
473
|
+
index = end === -1 ? text.length : end + 2;
|
|
474
|
+
out += ' ';
|
|
475
|
+
continue;
|
|
476
|
+
}
|
|
477
|
+
// Python and Ruby start a comment at any `#` outside a string (`x = 1# note`). Perl does not: `$#a`
|
|
478
|
+
// and `s#a#b#` use it as syntax, so there it must begin a word.
|
|
479
|
+
const anywhere = dialect === 'hash' || dialect === 'ruby';
|
|
480
|
+
if (dialect !== 'js' && character === '#' && (wordStart || anywhere)) {
|
|
481
|
+
const end = text.indexOf('\n', index);
|
|
482
|
+
index = end === -1 ? text.length : end;
|
|
483
|
+
continue;
|
|
484
|
+
}
|
|
485
|
+
out += character;
|
|
486
|
+
index += 1;
|
|
487
|
+
}
|
|
488
|
+
return out;
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* Whether code handed to an interpreter ends a process.
|
|
492
|
+
*
|
|
493
|
+
* Code for a shell (`bash -c`, `powershell -Command`, `cmd /c`) is a command line in that shell.
|
|
494
|
+
* In program code a string literal is data — `console.log('kill 80632')` prints — so kill calls are
|
|
495
|
+
* looked for outside the literals, with comments removed. A literal counts where the code runs it:
|
|
496
|
+
* handed to an exec function, used as a method name (`process['kill']`), or interpolated
|
|
497
|
+
* (`${ … }`, an f-string's `{ … }`). The code is also read as a command line, which catches a
|
|
498
|
+
* statement such as Perl's `kill 9, $pid`.
|
|
499
|
+
*/
|
|
500
|
+
/** How a `/` after `}` is read in the current pass of [codeTerminates]: as a regex, or as division. */
|
|
501
|
+
let braceStartsRegex = true;
|
|
502
|
+
function codeTerminates(source, depth, dialect) {
|
|
503
|
+
// `{} / 1; process.kill(…); /a/` and `if (x) {} /"/.test(s); process.kill(…)` need opposite
|
|
504
|
+
// readings of the slash after `}`, and either reading may hide a call inside a false literal, so
|
|
505
|
+
// JavaScript with such a slash is judged both ways.
|
|
506
|
+
if (dialect === 'js' && /\}\s*\/(?![/*])/.test(source)) {
|
|
507
|
+
const saved = braceStartsRegex;
|
|
508
|
+
try {
|
|
509
|
+
braceStartsRegex = true;
|
|
510
|
+
if (codeTerminatesAs(source, depth, dialect))
|
|
511
|
+
return true;
|
|
512
|
+
braceStartsRegex = false;
|
|
513
|
+
return codeTerminatesAs(source, depth, dialect);
|
|
514
|
+
}
|
|
515
|
+
finally {
|
|
516
|
+
braceStartsRegex = saved;
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
return codeTerminatesAs(source, depth, dialect);
|
|
520
|
+
}
|
|
521
|
+
/** [codeTerminates] for one reading of the source. */
|
|
522
|
+
function codeTerminatesAs(written, depth, dialect) {
|
|
523
|
+
if (depth > 4)
|
|
524
|
+
return false;
|
|
525
|
+
note(written);
|
|
526
|
+
if (dialect === 'posix' || dialect === 'powershell' || dialect === 'cmd')
|
|
527
|
+
return terminates(written, depth + 1, dialect);
|
|
528
|
+
// Perl's `q[…]`, `qq{…}`, `qw(…)` and `qx[…]` are its quotes and backticks with other delimiters:
|
|
529
|
+
// `system q[kill 80632]` is `system 'kill 80632'`, and `qx[kill 80632]` runs it.
|
|
530
|
+
const source = dialect === 'perl' ? perlQuotesAsQuotes(written) : written;
|
|
531
|
+
const code = stripComments(source, dialect);
|
|
532
|
+
const scanned = scan(code, dialect);
|
|
533
|
+
const { quoted, embedded, regexes, interpolated } = scanned;
|
|
534
|
+
// JavaScript names an identifier the same with `\u…` escapes: `process.\u006bill` is
|
|
535
|
+
// `process.kill`. They are decoded outside strings only, where they can only spell identifiers;
|
|
536
|
+
// a string's escapes were resolved by [scan] as the string's own text.
|
|
537
|
+
// Ruby and Perl call without parentheses: `system "kill 80632"` is `system("kill 80632"`, which is
|
|
538
|
+
// what [RUNS_LITERAL] reads.
|
|
539
|
+
const named = dialect === 'js' ? decodeEscapes(scanned.bare)
|
|
540
|
+
: dialect === 'ruby' || dialect === 'perl' ? scanned.bare.replace(/\b(system|exec|spawn|popen)[ \t]+(?=\u0000\d+\u0000)/g, '$1(')
|
|
541
|
+
: scanned.bare;
|
|
542
|
+
// A launcher looked up by a string, `cp['execSync']('kill 80632')`, is read as `cp.execSync(…)`.
|
|
543
|
+
const bare = named.replace(/\[\s*\u0000(\d+)\u0000\s*\](?=\s*(?:\?\.\s*)?\()/g, (whole, slot) => {
|
|
544
|
+
const name = quoted[Number(slot)] ?? '';
|
|
545
|
+
return LAUNCHER_NAMES.test(name) ? `.${name}` : whole;
|
|
546
|
+
});
|
|
547
|
+
if (callsKill(bare))
|
|
548
|
+
return true;
|
|
549
|
+
// Perl's kill is a function usable anywhere in an expression: `print kill 15, $pid`,
|
|
550
|
+
// `my $n = kill(15, $pid)`, `use constant X => kill(…)`. Signal 0 (or ZERO) only probes.
|
|
551
|
+
if (dialect === 'perl') {
|
|
552
|
+
// `CORE::kill` (and `CORE::GLOBAL::kill`) is the same builtin, named explicitly.
|
|
553
|
+
const unqualified = bare.replace(/\bCORE::(?:GLOBAL::)?(?=kill\b)/g, ' ');
|
|
554
|
+
for (const match of unqualified.matchAll(/(?<![\w$@%&:>.-])kill\b\s*\(?\s*([^,;()]*?)\s*,/g)) {
|
|
555
|
+
const signal = match[1].replace(/\u0000(\d+)\u0000/g, (_, slot) => quoted[Number(slot)] ?? '').trim();
|
|
556
|
+
if (/^(?:0|(?:SIG)?ZERO)$/i.test(signal))
|
|
557
|
+
continue;
|
|
558
|
+
return true;
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
// Read as a command line with every string and regular expression blanked, so a statement such as
|
|
562
|
+
// Perl's `kill 9, $pid` counts and a literal's contents do not.
|
|
563
|
+
if (terminates(bare.replace(/\u0000\d+\u0000/g, "''"), depth + 1, 'posix', false))
|
|
564
|
+
return true;
|
|
565
|
+
if (embedded.some(inner => codeTerminates(inner, depth + 1, dialect)))
|
|
566
|
+
return true;
|
|
567
|
+
// A string that interpolates runs the code in it: a Python f-string's `{ … }`, Ruby's "#{ … }".
|
|
568
|
+
// (A JavaScript template's `${ … }` is in `embedded`.) Braces in any other string are text.
|
|
569
|
+
for (const [slot, pattern] of interpolated) {
|
|
570
|
+
// A pattern may match text that is not a field (a Python `{{` is a literal brace): no capture.
|
|
571
|
+
for (const match of (quoted[slot] ?? '').matchAll(pattern))
|
|
572
|
+
if (match[1] !== undefined && (callsKill(match[1]) || codeTerminates(match[1], depth + 1, dialect)))
|
|
573
|
+
return true;
|
|
574
|
+
}
|
|
575
|
+
// A literal handed to the language's own evaluator is code in that language, at the positions
|
|
576
|
+
// that evaluator runs: every argument of `Function` (its parameters' defaults run too, and the last
|
|
577
|
+
// is the body), the first of `eval`, the timers and `vm`. A timer's later arguments are data for
|
|
578
|
+
// its callback, and `eval` ignores any after the first.
|
|
579
|
+
if (dialect === 'js') {
|
|
580
|
+
for (const match of bare.matchAll(JS_EVAL)) {
|
|
581
|
+
const slots = callLiterals(bare, match.index + match[0].length);
|
|
582
|
+
const runs = /^Function\b/.test(match[0]) ? slots : slots.filter(slot => slot === firstArgumentSlot(bare, match.index + match[0].length));
|
|
583
|
+
for (const slot of runs) {
|
|
584
|
+
if (codeTerminates(quoted[slot] ?? '', depth + 1, dialect))
|
|
585
|
+
return true;
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
else {
|
|
590
|
+
for (const match of bare.matchAll(HASH_EVAL)) {
|
|
591
|
+
if (codeTerminates(quoted[Number(match[1])] ?? '', depth + 1, dialect))
|
|
592
|
+
return true;
|
|
593
|
+
}
|
|
594
|
+
// Compiled source runs only when the code calls an executor too: `exec(compile('…', 'f', 'exec'))`.
|
|
595
|
+
if (/\b(?:exec|eval)\s*\(/.test(bare)) {
|
|
596
|
+
for (const match of bare.matchAll(PY_COMPILE)) {
|
|
597
|
+
if (codeTerminates(quoted[Number(match[1])] ?? '', depth + 1, dialect))
|
|
598
|
+
return true;
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
for (const match of bare.matchAll(INDEXED_CALL)) {
|
|
603
|
+
if (!/^(?:kill|terminate)$/i.test(quoted[Number(match[1])] ?? ''))
|
|
604
|
+
continue;
|
|
605
|
+
// `process['kill'](pid, 0)` only asks whether the process exists.
|
|
606
|
+
if (match[2] !== undefined && /^[^,]*,\s*0\s*$/.test(match[2]) && /^kill$/i.test(quoted[Number(match[1])] ?? ''))
|
|
607
|
+
continue;
|
|
608
|
+
return true;
|
|
609
|
+
}
|
|
610
|
+
for (const match of bare.matchAll(RUNS_LITERAL)) {
|
|
611
|
+
if (!startsProcess(match[2], match[1] === '.', bare.slice(0, match.index), code, regexes))
|
|
612
|
+
continue;
|
|
613
|
+
const named = quoted[Number(match[4])] ?? '';
|
|
614
|
+
// An array is an argument vector: `spawn('bash', ['-c', …])`, or Python's `run(['bash', '-c', …])`.
|
|
615
|
+
const after = bare.slice(match.index + match[0].length);
|
|
616
|
+
// Ruby and Perl pass the arguments as further literals: `system("bash", "-c", "…")`.
|
|
617
|
+
const positional = /^((?:\s*,\s*\u0000\d+\u0000)*)/;
|
|
618
|
+
const list = match[3] ? positional.exec(after)
|
|
619
|
+
: /^\s*,\s*\[((?:\s*,?\s*\u0000\d+\u0000)*)/.exec(after) ?? (dialect === 'ruby' || dialect === 'perl' ? positional.exec(after) : null);
|
|
620
|
+
const args = [...(list?.[1] ?? '').matchAll(/\u0000(\d+)\u0000/g)].map(slot => quoted[Number(slot[1])] ?? '');
|
|
621
|
+
// Launch options that ask for a shell (Node's `{ shell: true }`, Python's `shell=True`) join the
|
|
622
|
+
// program and arguments into a command line for that shell to read.
|
|
623
|
+
// The rest of the call, to its own closing parenthesis: options may hold calls of their own,
|
|
624
|
+
// such as `{ cwd: require('os').tmpdir(), shell: true }`. Strings are placeholders here.
|
|
625
|
+
let open = 1;
|
|
626
|
+
let close = 0;
|
|
627
|
+
for (; close < after.length && open > 0; close += 1) {
|
|
628
|
+
if (after[close] === '(')
|
|
629
|
+
open += 1;
|
|
630
|
+
else if (after[close] === ')')
|
|
631
|
+
open -= 1;
|
|
632
|
+
}
|
|
633
|
+
// A key may be quoted (`{ 'shell': true }`): literals are put back before the option is looked for.
|
|
634
|
+
// Only the launch options argument, after the argument list: a string inside the list that
|
|
635
|
+
// reads `shell: true` is the child's data, not an option.
|
|
636
|
+
// Python's `executable=` runs that program with the argument vector, whose first element is only
|
|
637
|
+
// the name it is given: `run(["echo", "80632"], executable="/bin/kill")` runs kill.
|
|
638
|
+
// With shell=True, executable= names the shell instead, and the command stays the first element.
|
|
639
|
+
const viaShell = shellOption(after.slice(list?.[0].length ?? 0, close), quoted);
|
|
640
|
+
const override = dialect === 'hash' && match[3] && !viaShell ? /\bexecutable\s*=\s*\u0000(\d+)\u0000/.exec(after.slice(0, close)) : null;
|
|
641
|
+
const program = override ? quoted[Number(override[1])] ?? named : named;
|
|
642
|
+
if (viaShell && args.length > 0 && shellLaunchTerminates(program, args, depth + 1, dialect))
|
|
643
|
+
return true;
|
|
644
|
+
if (args.length > 0) {
|
|
645
|
+
if (wordsTerminate([program, ...args], [program, ...args], depth + 1, 'posix'))
|
|
646
|
+
return true;
|
|
647
|
+
continue;
|
|
648
|
+
}
|
|
649
|
+
// A string alone is a command line, run by /bin/sh or by cmd.exe on Windows. Both readings
|
|
650
|
+
// are tried: a stricter reading only ever refuses more.
|
|
651
|
+
if (terminates(program, depth + 1, 'posix') || terminates(program, depth + 1, 'cmd'))
|
|
652
|
+
return true;
|
|
653
|
+
}
|
|
654
|
+
return false;
|
|
655
|
+
}
|
|
656
|
+
/**
|
|
657
|
+
* Whether a launch's options turn its shell on: a top-level `shell` property of the options object
|
|
658
|
+
* (Node: `{ shell: true }`, `{ 'shell': '/bin/bash' }`) or a `shell=` keyword argument (Python).
|
|
659
|
+
* A `shell` nested inside another property (`{ env: { … } }`) and text inside strings are not it.
|
|
660
|
+
* `options` is the rest of the call with strings as placeholders, resolved through `quoted`.
|
|
661
|
+
*/
|
|
662
|
+
function shellOption(rest, quoted) {
|
|
663
|
+
// The argument list's own closing bracket comes first; depth is counted from after it.
|
|
664
|
+
const options = rest.replace(/^\s*\]/, '');
|
|
665
|
+
// A literal options object is read by its shape. Options built some other way
|
|
666
|
+
// (`Object.assign({}, a, { shell: true })`) have no shape to read, so a `shell` key at any depth counts.
|
|
667
|
+
const shaped = /^\s*(?:,\s*)?(?:\{|\)|$|[A-Za-z_]\w*\s*=)/.test(options);
|
|
668
|
+
let depth = 0;
|
|
669
|
+
for (let index = 0; index < options.length; index += 1) {
|
|
670
|
+
const character = options[index];
|
|
671
|
+
if ('([{'.includes(character)) {
|
|
672
|
+
depth += 1;
|
|
673
|
+
continue;
|
|
674
|
+
}
|
|
675
|
+
if (')]}'.includes(character)) {
|
|
676
|
+
depth -= 1;
|
|
677
|
+
continue;
|
|
678
|
+
}
|
|
679
|
+
// Python's keyword arguments sit at the call's own level; Node's options object one deeper.
|
|
680
|
+
if (shaped && depth !== 0 && depth !== 1)
|
|
681
|
+
continue;
|
|
682
|
+
const key = /^(?:shell\b|\u0000(\d+)\u0000)\s*([:=])/.exec(options.slice(index));
|
|
683
|
+
if (!key || (index > 0 && /[\w$.]/.test(options[index - 1])))
|
|
684
|
+
continue;
|
|
685
|
+
if (key[1] !== undefined && quoted[Number(key[1])] !== 'shell')
|
|
686
|
+
continue;
|
|
687
|
+
if (shaped && (key[2] === '=') !== (depth === 0))
|
|
688
|
+
continue;
|
|
689
|
+
const value = options.slice(index + key[0].length).trimStart();
|
|
690
|
+
const literal = /^\u0000(\d+)\u0000/.exec(value);
|
|
691
|
+
if (literal)
|
|
692
|
+
return (quoted[Number(literal[1])] ?? '') !== '';
|
|
693
|
+
return !/^(?:false|False|0|None|null|undefined)\b/.test(value);
|
|
694
|
+
}
|
|
695
|
+
return false;
|
|
696
|
+
}
|
|
697
|
+
/**
|
|
698
|
+
* Whether an argument list launched through a shell ends a process, by the launching API's rules.
|
|
699
|
+
*
|
|
700
|
+
* Node joins the program and arguments with spaces, unquoted, into one command line for the shell.
|
|
701
|
+
* Python does not: on POSIX the first element is the command and the rest are the shell's own
|
|
702
|
+
* arguments (`$0`, `$1`, …), which it does not run; on Windows each element is quoted where it
|
|
703
|
+
* needs to be (`list2cmdline`) and the result goes to cmd.exe, so an element stays one argument.
|
|
704
|
+
*/
|
|
705
|
+
function shellLaunchTerminates(program, args, depth, dialect) {
|
|
706
|
+
if (dialect === 'hash') {
|
|
707
|
+
const quoted = [program, ...args].map(item => item === '' || /[\s"]/.test(item) ? `"${item.replace(/"/g, '\\"')}"` : item).join(' ');
|
|
708
|
+
return terminates(program, depth, 'posix') || terminates(quoted, depth, 'cmd');
|
|
709
|
+
}
|
|
710
|
+
const line = [program, ...args].join(' ');
|
|
711
|
+
return terminates(line, depth, 'posix') || terminates(line, depth, 'cmd');
|
|
712
|
+
}
|
|
713
|
+
/** Options of each interpreter that take the next argument as their value: not the script, not code. */
|
|
714
|
+
const INTERPRETER_VALUE_OPTIONS = {
|
|
715
|
+
python: new Set(['-W', '-X', '--check-hash-based-pycs']),
|
|
716
|
+
python3: new Set(['-W', '-X', '--check-hash-based-pycs']),
|
|
717
|
+
py: new Set(['-W', '-X', '--check-hash-based-pycs']),
|
|
718
|
+
ruby: new Set(['-I', '-r', '-C', '-E', '--encoding', '-F']),
|
|
719
|
+
// -M, -m, -x and -C take their value attached (`-Mstrict`, `-C7`) or none; only -I may take the next word.
|
|
720
|
+
perl: new Set(['-I']),
|
|
721
|
+
bash: new Set(['-o', '+o', '-O', '+O', '--rcfile', '--init-file']),
|
|
722
|
+
sh: new Set(['-o', '+o']),
|
|
723
|
+
zsh: new Set(['-o', '+o']),
|
|
724
|
+
};
|
|
725
|
+
/**
|
|
726
|
+
* Whether a shell was started not to execute what it reads: `bash -n`, `sh -nc …`, `bash -o noexec`.
|
|
727
|
+
* Its options are read up to the code or the script, and a later `+n` or `+o noexec` undoes them.
|
|
728
|
+
*/
|
|
729
|
+
function shellNoExec(word, args) {
|
|
730
|
+
if (!SHELLS.has(word))
|
|
731
|
+
return false;
|
|
732
|
+
let noexec = false;
|
|
733
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
734
|
+
const argument = args[index];
|
|
735
|
+
if (argument === '-o' || argument === '+o') {
|
|
736
|
+
if (args[index + 1] === 'noexec')
|
|
737
|
+
noexec = argument === '-o';
|
|
738
|
+
index += 1;
|
|
739
|
+
continue;
|
|
740
|
+
}
|
|
741
|
+
// An option's value (`-O extglob`, `--rcfile f`) is not where the options end.
|
|
742
|
+
if (INTERPRETER_VALUE_OPTIONS[word]?.has(argument)) {
|
|
743
|
+
index += 1;
|
|
744
|
+
continue;
|
|
745
|
+
}
|
|
746
|
+
if (argument.startsWith('--'))
|
|
747
|
+
continue;
|
|
748
|
+
if (!/^[-+][A-Za-z]+$/.test(argument))
|
|
749
|
+
break;
|
|
750
|
+
if (argument.includes('n'))
|
|
751
|
+
noexec = argument.startsWith('-');
|
|
752
|
+
// `-c` does not end the options: `bash -nc +n 'kill …'` turns execution back on before the string.
|
|
753
|
+
}
|
|
754
|
+
return noexec;
|
|
755
|
+
}
|
|
756
|
+
/**
|
|
757
|
+
* Whether Node is told to check syntax only: `-c` or `--check` among its own options, before the
|
|
758
|
+
* script, `-` or `--`. After those it is an argument of the script: `node - --check` runs stdin.
|
|
759
|
+
*/
|
|
760
|
+
function nodeChecksOnly(args) {
|
|
761
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
762
|
+
const argument = args[index];
|
|
763
|
+
if (argument === '-' || argument === '--' || !argument.startsWith('-'))
|
|
764
|
+
return false;
|
|
765
|
+
if (argument === '-c' || argument === '--check')
|
|
766
|
+
return true;
|
|
767
|
+
if (NODE_VALUE_OPTIONS.has(argument))
|
|
768
|
+
index += 1;
|
|
769
|
+
}
|
|
770
|
+
return false;
|
|
771
|
+
}
|
|
772
|
+
/**
|
|
773
|
+
* Whether Ruby is told to check syntax only: `-c`, alone or bundled with flags that take no value
|
|
774
|
+
* (`-wc`, `-ce`). A bundle that starts with a value option (`-rcsv` requires csv) is not one.
|
|
775
|
+
*/
|
|
776
|
+
function rubySyntaxOnly(word, args) {
|
|
777
|
+
if (word !== 'ruby')
|
|
778
|
+
return false;
|
|
779
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
780
|
+
const argument = args[index];
|
|
781
|
+
if (argument === '--' || !argument.startsWith('-') || argument === '-')
|
|
782
|
+
return false;
|
|
783
|
+
if (/^-[adlnpsvwy]*c[adlnpsvwye]*$/.test(argument))
|
|
784
|
+
return true;
|
|
785
|
+
if (argument === '-e' || /^-[adlnpsvwy]*e$/.test(argument) || INTERPRETER_VALUE_OPTIONS.ruby?.has(argument))
|
|
786
|
+
index += 1;
|
|
787
|
+
}
|
|
788
|
+
return false;
|
|
789
|
+
}
|
|
790
|
+
/** Whether an argument is a shell's `+` option, which turns a flag off (`bash +o posix`, `bash +x`). */
|
|
791
|
+
function shellPlusOption(word, argument) {
|
|
792
|
+
return SHELLS.has(word) && /^\+[A-Za-z]+$/.test(argument);
|
|
793
|
+
}
|
|
794
|
+
/**
|
|
795
|
+
* Whether `argument` is the flag after which this interpreter runs its next argument as code.
|
|
796
|
+
* Node's `-p` prints an expression; Perl's and Ruby's `-p` is a read-print loop that takes no
|
|
797
|
+
* value, and their `-c` only checks syntax, so each interpreter has its own (Perl's and Ruby's
|
|
798
|
+
* `-e` bundles are read where they are matched).
|
|
799
|
+
*/
|
|
800
|
+
function evalFlag(word, argument) {
|
|
801
|
+
if (word === 'perl' || word === 'ruby')
|
|
802
|
+
return false;
|
|
803
|
+
if (word === 'python' || word === 'python3' || word === 'py')
|
|
804
|
+
return argument === '-c';
|
|
805
|
+
if (word === 'node' || word === 'nodejs' || word === 'bun' || word === 'deno')
|
|
806
|
+
return NODE_EVAL.has(argument);
|
|
807
|
+
return EVAL_FLAGS.has(argument);
|
|
808
|
+
}
|
|
809
|
+
/** Node and the runtimes that take its options. */
|
|
810
|
+
const NODE_FAMILY = new Set(['node', 'nodejs', 'bun', 'deno']);
|
|
811
|
+
/** Shells, whose `-c` may be bundled with other single-letter flags (`bash -lc`). */
|
|
812
|
+
const SHELLS = new Set(['bash', 'sh', 'zsh']);
|
|
813
|
+
/** The flags after which a language interpreter runs its next argument as code. */
|
|
814
|
+
const EVAL_FLAGS = new Set(['-e', '--eval', '-p', '--print', '-pe', '-c']);
|
|
815
|
+
/** PowerShell options that take a value, which is therefore not the command. */
|
|
816
|
+
const POWERSHELL_VALUE_OPTIONS = /^-(?:executionpolicy|ex|ep|windowstyle|w|version|v|inputformat|if|outputformat|of|workingdirectory|wd|configurationname|config|settingsfile|settings)$/i;
|
|
817
|
+
/**
|
|
818
|
+
* The arguments an interpreter runs as code, out of everything on its command line.
|
|
819
|
+
*
|
|
820
|
+
* Only those are judged. The rest is data the program receives: in
|
|
821
|
+
* `node -e 'console.log(process.argv)' -- 'kill 80632'` the last argument is printed, not run.
|
|
822
|
+
* An interpreter stops reading its own options at `--` and at the first argument that is not an
|
|
823
|
+
* option (the script to run); nothing after that is its code.
|
|
824
|
+
*/
|
|
825
|
+
function interpreterCode(word, args) {
|
|
826
|
+
if (word === 'iex' || word === 'invoke-expression' || word === 'eval')
|
|
827
|
+
return [...args];
|
|
828
|
+
if (word === 'cmd') {
|
|
829
|
+
const at = args.findIndex(argument => /^\/[ck]$/i.test(argument));
|
|
830
|
+
return at === -1 ? [] : [args.slice(at + 1).join(' ')];
|
|
831
|
+
}
|
|
832
|
+
if (word === 'powershell' || word === 'pwsh') {
|
|
833
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
834
|
+
const argument = args[index];
|
|
835
|
+
// `-Command` and its unambiguous prefixes; everything after it is the command.
|
|
836
|
+
if (/^-c(?:o(?:m(?:m(?:a(?:nd?)?)?)?)?)?$/i.test(argument))
|
|
837
|
+
return [args.slice(index + 1).join(' ')];
|
|
838
|
+
if (/^-(?:f(?:i(?:le?)?)?|e(?:n(?:c(?:odedcommand)?)?)?|ec)$/i.test(argument))
|
|
839
|
+
return [];
|
|
840
|
+
if (POWERSHELL_VALUE_OPTIONS.test(argument)) {
|
|
841
|
+
index += 1;
|
|
842
|
+
continue;
|
|
843
|
+
}
|
|
844
|
+
// With no `-Command` or `-File`, the first argument that is not an option starts the command.
|
|
845
|
+
if (!argument.startsWith('-'))
|
|
846
|
+
return [args.slice(index).join(' ')];
|
|
847
|
+
}
|
|
848
|
+
return [];
|
|
849
|
+
}
|
|
850
|
+
if (shellNoExec(word, args) || rubySyntaxOnly(word, args))
|
|
851
|
+
return [];
|
|
852
|
+
const code = [];
|
|
853
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
854
|
+
const argument = args[index];
|
|
855
|
+
if (argument === '--')
|
|
856
|
+
break;
|
|
857
|
+
// `-` reads the script from stdin; what follows is the script's arguments: `node - -e …`.
|
|
858
|
+
if (argument === '-')
|
|
859
|
+
break;
|
|
860
|
+
// A quoted value is scanned as a token of its own, so `--eval='…'` arrives as `--eval=` and the code.
|
|
861
|
+
if (argument === '--eval=' || argument === '--print=') {
|
|
862
|
+
if (args[index + 1] !== undefined)
|
|
863
|
+
code.push(args[index + 1]);
|
|
864
|
+
index += 1;
|
|
865
|
+
continue;
|
|
866
|
+
}
|
|
867
|
+
if (/^--(?:eval|print)=/.test(argument)) {
|
|
868
|
+
code.push(argument.slice(argument.indexOf('=') + 1));
|
|
869
|
+
continue;
|
|
870
|
+
}
|
|
871
|
+
// Perl's `-E` is `-e` with its optional features on; to Python and Ruby `-E` is something else.
|
|
872
|
+
// Perl and Ruby bundle switches before `-e`: `perl -lne '…'`, `ruby -we '…'`, Perl's `-wE`.
|
|
873
|
+
const evaluates = evalFlag(word, argument) || (word === 'perl' && /^-[A-Za-z]*[eE]$/.test(argument)) || (word === 'ruby' && /^-[A-Za-z]*e$/.test(argument)) || (SHELLS.has(word) && /^-[A-Za-z]*c[A-Za-z]*$/.test(argument));
|
|
874
|
+
if (evaluates) {
|
|
875
|
+
// A shell reads all its options first: the command string is the first operand after them and
|
|
876
|
+
// an optional `--` (`bash -c -- 'kill …'`, `bash -c -x 'kill …'`). Other interpreters take the
|
|
877
|
+
// next argument as their code, whatever it looks like.
|
|
878
|
+
if (SHELLS.has(word)) {
|
|
879
|
+
let at = index + 1;
|
|
880
|
+
while (at < args.length) {
|
|
881
|
+
const next = args[at];
|
|
882
|
+
if (next === '--') {
|
|
883
|
+
at += 1;
|
|
884
|
+
break;
|
|
885
|
+
}
|
|
886
|
+
if (/^[-+]o$/.test(next) || INTERPRETER_VALUE_OPTIONS[word]?.has(next)) {
|
|
887
|
+
at += 2;
|
|
888
|
+
continue;
|
|
889
|
+
}
|
|
890
|
+
if (/^[-+][A-Za-z]+$/.test(next)) {
|
|
891
|
+
at += 1;
|
|
892
|
+
continue;
|
|
893
|
+
}
|
|
894
|
+
break;
|
|
895
|
+
}
|
|
896
|
+
if (args[at] !== undefined)
|
|
897
|
+
code.push(args[at]);
|
|
898
|
+
break;
|
|
899
|
+
}
|
|
900
|
+
if (args[index + 1] !== undefined)
|
|
901
|
+
code.push(args[index + 1]);
|
|
902
|
+
index += 1;
|
|
903
|
+
// Python's `-c cmd` and a shell's `-c cmd` end the option list: what follows is the program's
|
|
904
|
+
// `sys.argv` or `$0 $1 …`. Node, Ruby and Perl take several `-e`.
|
|
905
|
+
if (word === 'python' || word === 'python3' || word === 'py' || SHELLS.has(word))
|
|
906
|
+
break;
|
|
907
|
+
continue;
|
|
908
|
+
}
|
|
909
|
+
// Python takes its code attached or after bundled flags (`-c'…'`, `-Ic '…'`), Ruby and Perl their
|
|
910
|
+
// `-e` code attached (`-e'…'`).
|
|
911
|
+
const python = word === 'python' || word === 'python3' || word === 'py';
|
|
912
|
+
const bundled = python ? /^-[bBdEhiIOqsSuvRP]*c([\s\S]*)$/.exec(argument) : undefined;
|
|
913
|
+
if (bundled) {
|
|
914
|
+
const attached = bundled[1] ?? '';
|
|
915
|
+
if (attached !== '')
|
|
916
|
+
code.push(attached);
|
|
917
|
+
else if (args[index + 1] !== undefined)
|
|
918
|
+
code.push(args[index + 1]);
|
|
919
|
+
break;
|
|
920
|
+
}
|
|
921
|
+
// Code attached to `-e`, also after value-less switches in one bundle: `perl -we'kill …'`.
|
|
922
|
+
const attached = word === 'perl' ? /^-[acflnpsStTuUvwWX]*[eE]([\s\S]+)$/.exec(argument)
|
|
923
|
+
: word === 'ruby' ? /^-[adlnpsvwy]*e([\s\S]+)$/.exec(argument) : null;
|
|
924
|
+
if (attached) {
|
|
925
|
+
code.push(attached[1]);
|
|
926
|
+
continue;
|
|
927
|
+
}
|
|
928
|
+
// Node's preload given as a `data:` URL is code: `--import data:text/javascript,…`.
|
|
929
|
+
const node = NODE_FAMILY.has(word);
|
|
930
|
+
const preload = !node ? undefined : nodePreloadCode(argument, args[index + 1]);
|
|
931
|
+
if (preload !== undefined)
|
|
932
|
+
code.push(preload);
|
|
933
|
+
// Node's value options are Node's: Perl's `-C` takes no following value.
|
|
934
|
+
if ((node && NODE_VALUE_OPTIONS.has(argument)) || INTERPRETER_VALUE_OPTIONS[word]?.has(argument)) {
|
|
935
|
+
index += 1;
|
|
936
|
+
continue;
|
|
937
|
+
}
|
|
938
|
+
// `python -m module` runs a module: no inline code follows, and its arguments are its own.
|
|
939
|
+
if ((word === 'python' || word === 'python3' || word === 'py') && argument === '-m')
|
|
940
|
+
break;
|
|
941
|
+
if (argument.startsWith('-') || shellPlusOption(word, argument))
|
|
942
|
+
continue;
|
|
943
|
+
// A word after a Node option this guard does not know may be its value: read on.
|
|
944
|
+
if ((word === 'node' || word === 'nodejs' || word === 'bun') && unknownLongOption(args[index - 1]))
|
|
945
|
+
continue;
|
|
946
|
+
// `deno eval <code>` is the one interpreter whose code follows a subcommand.
|
|
947
|
+
if (word === 'deno' && argument === 'eval' && args[index + 1] !== undefined)
|
|
948
|
+
code.push(args[index + 1]);
|
|
949
|
+
break;
|
|
950
|
+
}
|
|
951
|
+
// `perl -c` compiles without running; only its BEGIN, UNITCHECK and CHECK blocks run.
|
|
952
|
+
// The `-e` fragments are one program, so a block may span them: `-e 'BEGIN {' -e 'kill …' -e '}'`.
|
|
953
|
+
if (word === 'perl' && perlSyntaxOnly(args))
|
|
954
|
+
return (code.length > 1 ? [...code, code.join('\n')] : code).flatMap(compileTimeBlocks);
|
|
955
|
+
return code;
|
|
956
|
+
}
|
|
957
|
+
/** Whether Perl is told to check syntax only: `-c`, alone or bundled with switches that take no value (`-wc`). */
|
|
958
|
+
function perlSyntaxOnly(args) {
|
|
959
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
960
|
+
const argument = args[index];
|
|
961
|
+
if (argument === '--' || !argument.startsWith('-') || argument === '-')
|
|
962
|
+
return false;
|
|
963
|
+
// `-c` alone or in a bundle, also one ending in `e` with the code attached: `-ce'BEGIN { … }'`.
|
|
964
|
+
const bundle = /^-([acflnpsStTuUvwWX]*)(?:[eE][\s\S]*)?$/.exec(argument);
|
|
965
|
+
if (bundle && bundle[1].includes('c'))
|
|
966
|
+
return true;
|
|
967
|
+
if (/^-[A-Za-z]*[eE]$/.test(argument) || INTERPRETER_VALUE_OPTIONS.perl?.has(argument))
|
|
968
|
+
index += 1;
|
|
969
|
+
}
|
|
970
|
+
return false;
|
|
971
|
+
}
|
|
972
|
+
/**
|
|
973
|
+
* Where the Perl statement that starts at `start` ends: its own `;`, or a closing brace or
|
|
974
|
+
* bracket that encloses it, past nested blocks (`do { 1; kill … }`), quoted text and comments.
|
|
975
|
+
*/
|
|
976
|
+
function statementEnd(source, start) {
|
|
977
|
+
let depth = 0;
|
|
978
|
+
for (let at = start; at < source.length; at += 1) {
|
|
979
|
+
const character = source[at];
|
|
980
|
+
if (character === '"' || character === "'" || character === '`') {
|
|
981
|
+
for (at += 1; at < source.length && source[at] !== character; at += 1)
|
|
982
|
+
if (source[at] === '\\')
|
|
983
|
+
at += 1;
|
|
984
|
+
continue;
|
|
985
|
+
}
|
|
986
|
+
if (character === '#') {
|
|
987
|
+
while (at < source.length && source[at] !== '\n')
|
|
988
|
+
at += 1;
|
|
989
|
+
continue;
|
|
990
|
+
}
|
|
991
|
+
if ('({['.includes(character))
|
|
992
|
+
depth += 1;
|
|
993
|
+
else if (')}]'.includes(character)) {
|
|
994
|
+
if (depth === 0)
|
|
995
|
+
return at;
|
|
996
|
+
depth -= 1;
|
|
997
|
+
}
|
|
998
|
+
else if (character === ';' && depth === 0)
|
|
999
|
+
return at;
|
|
1000
|
+
}
|
|
1001
|
+
return source.length;
|
|
1002
|
+
}
|
|
1003
|
+
/**
|
|
1004
|
+
* The part of a program an interpreter runs when it reads it from its input or a here-document:
|
|
1005
|
+
* all of it, except under `perl -c`, which runs only its compile-time code.
|
|
1006
|
+
*/
|
|
1007
|
+
function inputProgram(word, args, program) {
|
|
1008
|
+
return word === 'perl' && perlSyntaxOnly(args) ? compileTimeBlocks(program).join('\n') : program;
|
|
1009
|
+
}
|
|
1010
|
+
/**
|
|
1011
|
+
* Perl source with each `q`, `qq`, `qw` and `qx` literal written as the quote it stands for: `'…'`,
|
|
1012
|
+
* `"…"`, `'…'` and a backtick command. Ordinary quotes, comments and the regex operators are left
|
|
1013
|
+
* as they are.
|
|
1014
|
+
*/
|
|
1015
|
+
function perlQuotesAsQuotes(source) {
|
|
1016
|
+
const pairs = { '(': ')', '[': ']', '{': '}', '<': '>' };
|
|
1017
|
+
const close = (from, open) => {
|
|
1018
|
+
const shut = pairs[open] ?? open;
|
|
1019
|
+
let depth = 1;
|
|
1020
|
+
for (let index = from; index < source.length; index += 1) {
|
|
1021
|
+
const character = source[index];
|
|
1022
|
+
if (character === '\\') {
|
|
1023
|
+
index += 1;
|
|
1024
|
+
continue;
|
|
1025
|
+
}
|
|
1026
|
+
if (shut !== open && character === open)
|
|
1027
|
+
depth += 1;
|
|
1028
|
+
else if (character === shut && --depth === 0)
|
|
1029
|
+
return index;
|
|
1030
|
+
}
|
|
1031
|
+
return source.length;
|
|
1032
|
+
};
|
|
1033
|
+
let out = '';
|
|
1034
|
+
let at = 0;
|
|
1035
|
+
while (at < source.length) {
|
|
1036
|
+
const character = source[at];
|
|
1037
|
+
if (character === '#' || character === "'" || character === '"' || character === '`') {
|
|
1038
|
+
const end = character === '#' ? (source.indexOf('\n', at) === -1 ? source.length : source.indexOf('\n', at)) : Math.min(source.length, close(at + 1, character) + 1);
|
|
1039
|
+
out += source.slice(at, end);
|
|
1040
|
+
at = end;
|
|
1041
|
+
continue;
|
|
1042
|
+
}
|
|
1043
|
+
const before = at === 0 ? '' : source[at - 1];
|
|
1044
|
+
const operator = /[\w$@%&>-]/.test(before) ? null : /^(qq|qw|qx|q)\s*([^\w\s])/.exec(source.slice(at, at + 8));
|
|
1045
|
+
if (operator && !(operator[2] === '=' && source[at + operator[0].length] === '>')) {
|
|
1046
|
+
const start = at + operator[0].length;
|
|
1047
|
+
const end = close(start, operator[2]);
|
|
1048
|
+
const body = source.slice(start, end);
|
|
1049
|
+
const quote = operator[1] === 'qq' ? '"' : operator[1] === 'qx' ? '`' : "'";
|
|
1050
|
+
out += quote + body.replace(new RegExp(`[\\\\${quote}]`, 'g'), match => match === quote ? `\\${quote}` : match) + quote;
|
|
1051
|
+
at = Math.min(source.length, end + 1);
|
|
1052
|
+
continue;
|
|
1053
|
+
}
|
|
1054
|
+
out += character;
|
|
1055
|
+
at += 1;
|
|
1056
|
+
}
|
|
1057
|
+
return out;
|
|
1058
|
+
}
|
|
1059
|
+
/**
|
|
1060
|
+
* `source` with Perl's quoted text and comments blanked to spaces, the same length: '…', "…",
|
|
1061
|
+
* `…`, the quote-like operators (`q[…]`, `qq{…}`, `qw(…)`, `m/…/`, `s{…}{…}`, `tr/…/…/`) and
|
|
1062
|
+
* `#` comments. Code is found in what is left, so a `}` or a `BEGIN` inside a string is text.
|
|
1063
|
+
*/
|
|
1064
|
+
function blankPerlLiterals(source) {
|
|
1065
|
+
const pairs = { '(': ')', '[': ']', '{': '}', '<': '>' };
|
|
1066
|
+
let out = '';
|
|
1067
|
+
let at = 0;
|
|
1068
|
+
// From `from` (just past an opening delimiter), the index just past its closing one.
|
|
1069
|
+
const close = (from, open) => {
|
|
1070
|
+
const shut = pairs[open] ?? open;
|
|
1071
|
+
let depth = 1;
|
|
1072
|
+
let index = from;
|
|
1073
|
+
for (; index < source.length; index += 1) {
|
|
1074
|
+
const character = source[index];
|
|
1075
|
+
if (character === '\\') {
|
|
1076
|
+
index += 1;
|
|
1077
|
+
continue;
|
|
1078
|
+
}
|
|
1079
|
+
if (shut !== open && character === open)
|
|
1080
|
+
depth += 1;
|
|
1081
|
+
else if (character === shut && --depth === 0)
|
|
1082
|
+
return index + 1;
|
|
1083
|
+
}
|
|
1084
|
+
return source.length;
|
|
1085
|
+
};
|
|
1086
|
+
while (at < source.length) {
|
|
1087
|
+
const character = source[at];
|
|
1088
|
+
const before = at === 0 ? '' : source[at - 1];
|
|
1089
|
+
const operator = /[\w$@%&>-]/.test(before) ? null : /^(qq|qw|qx|qr|q|m|s|tr|y)\s*([^\w\s])/.exec(source.slice(at, at + 12));
|
|
1090
|
+
// `y => 1` and `s => …` are hash keys, not operators.
|
|
1091
|
+
if (operator && !(operator[2] === '=' && source[at + operator[0].length] === '>')) {
|
|
1092
|
+
let index = close(at + operator[0].length, operator[2]);
|
|
1093
|
+
// s, tr and y take a second part: with brackets it has its own delimiters, otherwise it shares the middle one.
|
|
1094
|
+
if (['s', 'tr', 'y'].includes(operator[1])) {
|
|
1095
|
+
if (pairs[operator[2]]) {
|
|
1096
|
+
while (/\s/.test(source[index] ?? ''))
|
|
1097
|
+
index += 1;
|
|
1098
|
+
if (source[index] !== undefined)
|
|
1099
|
+
index = close(index + 1, source[index]);
|
|
1100
|
+
}
|
|
1101
|
+
else {
|
|
1102
|
+
index = close(index, operator[2]);
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1105
|
+
out += source.slice(at, index).replace(/[^\n]/g, ' ');
|
|
1106
|
+
at = index;
|
|
1107
|
+
continue;
|
|
1108
|
+
}
|
|
1109
|
+
// A bare regex (`/}/`, `split /,/`) where an operand may start is literal text too.
|
|
1110
|
+
if (character === '/' && /(?:^|[(,;{}=!~&|?:]|\b(?:split|grep|if|unless|and|or|not|return|when))\s*$/.test(out)) {
|
|
1111
|
+
const index = close(at + 1, '/');
|
|
1112
|
+
out += source.slice(at, index).replace(/[^\n]/g, ' ');
|
|
1113
|
+
at = index;
|
|
1114
|
+
continue;
|
|
1115
|
+
}
|
|
1116
|
+
if (character === '#') {
|
|
1117
|
+
const lineEnd = source.indexOf('\n', at);
|
|
1118
|
+
const stop = lineEnd === -1 ? source.length : lineEnd;
|
|
1119
|
+
out += ' '.repeat(stop - at);
|
|
1120
|
+
at = stop;
|
|
1121
|
+
continue;
|
|
1122
|
+
}
|
|
1123
|
+
if (character === "'" || character === '"' || character === '`') {
|
|
1124
|
+
const index = close(at + 1, character);
|
|
1125
|
+
out += source.slice(at, index).replace(/[^\n]/g, ' ');
|
|
1126
|
+
at = index;
|
|
1127
|
+
continue;
|
|
1128
|
+
}
|
|
1129
|
+
out += character;
|
|
1130
|
+
at += 1;
|
|
1131
|
+
}
|
|
1132
|
+
return out;
|
|
1133
|
+
}
|
|
1134
|
+
/**
|
|
1135
|
+
* The bodies of Perl's compile-time blocks in `source`: `BEGIN { … }`, `UNITCHECK { … }`, `CHECK { … }`,
|
|
1136
|
+
* and the arguments of `use` and `no` declarations. They are found outside quoted text and comments,
|
|
1137
|
+
* and their extent is measured the same way; the text returned is the source's own.
|
|
1138
|
+
*/
|
|
1139
|
+
function compileTimeBlocks(source) {
|
|
1140
|
+
const code = blankPerlLiterals(source);
|
|
1141
|
+
const blocks = [];
|
|
1142
|
+
for (const match of code.matchAll(/\b(?:BEGIN|UNITCHECK|CHECK)\s*\{/g)) {
|
|
1143
|
+
const start = match.index + match[0].length;
|
|
1144
|
+
let depth = 1;
|
|
1145
|
+
let at = start;
|
|
1146
|
+
for (; at < code.length && depth > 0; at += 1) {
|
|
1147
|
+
if (code[at] === '{')
|
|
1148
|
+
depth += 1;
|
|
1149
|
+
else if (code[at] === '}')
|
|
1150
|
+
depth -= 1;
|
|
1151
|
+
}
|
|
1152
|
+
blocks.push(source.slice(start, depth === 0 ? at - 1 : at));
|
|
1153
|
+
}
|
|
1154
|
+
// `use Module LIST` and `no Module LIST` evaluate LIST at compile time: `use constant X => kill(…)`.
|
|
1155
|
+
for (const match of code.matchAll(/\b(?:use|no)\s+[\w:]+/g)) {
|
|
1156
|
+
const start = match.index + match[0].length;
|
|
1157
|
+
blocks.push(source.slice(start, statementEnd(code, start)));
|
|
1158
|
+
}
|
|
1159
|
+
return blocks;
|
|
1160
|
+
}
|
|
1161
|
+
/** PowerShell's backtick escapes inside "…". */
|
|
1162
|
+
const POWERSHELL_ESCAPES = { '0': '\0', a: '\u0007', b: '\b', e: '\u001b', f: '\f', n: '\n', r: '\r', t: '\t', v: '\v' };
|
|
1163
|
+
/** Bash's one-letter escapes inside $'…'. */
|
|
1164
|
+
const ANSI_ESCAPES = { a: '\u0007', b: '\b', e: '\u001b', E: '\u001b', f: '\f', n: '\n', r: '\r', t: '\t', v: '\v', '\\': '\\', "'": "'", '"': '"', '?': '?' };
|
|
1165
|
+
/**
|
|
1166
|
+
* What an escape inside a shell string stands for, and how many characters it spans.
|
|
1167
|
+
*
|
|
1168
|
+
* Bash's "…" removes a backslash only before `$`, a backtick, `"`, `\` and a line break; before
|
|
1169
|
+
* anything else the backslash stays, so `"…\n…"` reaches a program as backslash-n for the program
|
|
1170
|
+
* to decode. `$'…'` decodes C escapes. PowerShell's "…" turns `` `n `` into a line break.
|
|
1171
|
+
*/
|
|
1172
|
+
function shellEscape(dialect, quote, raw, at) {
|
|
1173
|
+
const next = raw[at + 1];
|
|
1174
|
+
if (dialect === 'posix' && quote === '"') {
|
|
1175
|
+
if (next === '\n')
|
|
1176
|
+
return { text: '', length: 2 };
|
|
1177
|
+
return { text: '$`"\\'.includes(next) ? next : `\\${next}`, length: 2 };
|
|
1178
|
+
}
|
|
1179
|
+
if (dialect === 'posix' && quote === "'") {
|
|
1180
|
+
const coded = /^\\(?:x([0-9a-fA-F]{1,2})|([0-7]{1,3})|u([0-9a-fA-F]{1,4})|U([0-9a-fA-F]{1,8})|c(.))/.exec(raw.slice(at));
|
|
1181
|
+
if (coded) {
|
|
1182
|
+
const [whole, hex, octal, short, long, control] = coded;
|
|
1183
|
+
if (control !== undefined)
|
|
1184
|
+
return { text: String.fromCharCode(control.toUpperCase().charCodeAt(0) & 0x1f), length: whole.length };
|
|
1185
|
+
const point = hex !== undefined ? parseInt(hex, 16) : octal !== undefined ? parseInt(octal, 8) : parseInt((short ?? long), 16);
|
|
1186
|
+
return { text: point <= 0x10ffff ? String.fromCodePoint(point) : whole, length: whole.length };
|
|
1187
|
+
}
|
|
1188
|
+
return { text: ANSI_ESCAPES[next] ?? `\\${next}`, length: 2 };
|
|
1189
|
+
}
|
|
1190
|
+
if (dialect === 'powershell')
|
|
1191
|
+
return { text: POWERSHELL_ESCAPES[next] ?? next, length: 2 };
|
|
1192
|
+
return { text: next, length: 2 };
|
|
1193
|
+
}
|
|
1194
|
+
/** What the one-letter escapes of JavaScript and Python strings stand for. */
|
|
1195
|
+
const PROGRAM_ESCAPES = { n: '\n', t: '\t', r: '\r', v: '\v', f: '\f', b: '\b', '0': '\0', '\n': '' };
|
|
1196
|
+
/**
|
|
1197
|
+
* The bodies of the `$( … )` substitutions in `text`, each to its own matching parenthesis: a
|
|
1198
|
+
* call such as `console.log(1)` inside one does not end it. Quoted spans inside are skipped as
|
|
1199
|
+
* the shell skips them. `text` has its escaped characters blanked already.
|
|
1200
|
+
*/
|
|
1201
|
+
function substitutionBodies(text) {
|
|
1202
|
+
const bodies = [];
|
|
1203
|
+
for (let start = text.indexOf('$('); start !== -1; start = text.indexOf('$(', start + 2)) {
|
|
1204
|
+
let open = 1;
|
|
1205
|
+
let index = start + 2;
|
|
1206
|
+
while (index < text.length && open > 0) {
|
|
1207
|
+
const character = text[index];
|
|
1208
|
+
if (character === "'") {
|
|
1209
|
+
const close = text.indexOf("'", index + 1);
|
|
1210
|
+
index = close === -1 ? text.length : close + 1;
|
|
1211
|
+
continue;
|
|
1212
|
+
}
|
|
1213
|
+
if (character === '"') {
|
|
1214
|
+
index = (quoteEnd(text, index, 'posix') ?? index) + 1;
|
|
1215
|
+
continue;
|
|
1216
|
+
}
|
|
1217
|
+
if (character === '(')
|
|
1218
|
+
open += 1;
|
|
1219
|
+
else if (character === ')')
|
|
1220
|
+
open -= 1;
|
|
1221
|
+
index += 1;
|
|
1222
|
+
}
|
|
1223
|
+
bodies.push(text.slice(start + 2, open === 0 ? index - 1 : text.length));
|
|
1224
|
+
}
|
|
1225
|
+
return bodies;
|
|
1226
|
+
}
|
|
1227
|
+
/** The character a `\u` or `\x` escape at `at` names, and how long the escape is; undefined if it is none. */
|
|
1228
|
+
function escapeAt(text, at) {
|
|
1229
|
+
const match = /^\\(?:u\{([0-9a-fA-F]{1,6})\}|u([0-9a-fA-F]{4})|x([0-9a-fA-F]{2})|([0-3][0-7]{0,2}|[4-7][0-7]?))/.exec(text.slice(at));
|
|
1230
|
+
if (!match)
|
|
1231
|
+
return undefined;
|
|
1232
|
+
// Python, Ruby, Perl and sloppy-mode JavaScript read `\153` as octal: k.
|
|
1233
|
+
if (match[4] !== undefined)
|
|
1234
|
+
return { text: String.fromCharCode(parseInt(match[4], 8)), length: match[0].length };
|
|
1235
|
+
const point = parseInt(match[1] ?? match[2] ?? match[3], 16);
|
|
1236
|
+
// An escape beyond Unicode names no character; it stays as written.
|
|
1237
|
+
if (point > 0x10ffff)
|
|
1238
|
+
return undefined;
|
|
1239
|
+
return { text: String.fromCodePoint(point), length: match[0].length };
|
|
1240
|
+
}
|
|
1241
|
+
/** Decode every valid `\u` escape in identifier text; an invalid one stays as written. */
|
|
1242
|
+
function decodeEscapes(text) {
|
|
1243
|
+
let out = '';
|
|
1244
|
+
for (let index = 0; index < text.length;) {
|
|
1245
|
+
const escape = text[index] === '\\' && text[index + 1] === 'u' ? escapeAt(text, index) : undefined;
|
|
1246
|
+
if (escape) {
|
|
1247
|
+
out += escape.text;
|
|
1248
|
+
index += escape.length;
|
|
1249
|
+
continue;
|
|
1250
|
+
}
|
|
1251
|
+
out += text[index];
|
|
1252
|
+
index += 1;
|
|
1253
|
+
}
|
|
1254
|
+
return out;
|
|
1255
|
+
}
|
|
1256
|
+
/**
|
|
1257
|
+
* Separate what is read as syntax from what is only passed along, by the dialect's rules.
|
|
1258
|
+
*
|
|
1259
|
+
* A quoted span becomes a placeholder with no blanks around it, so a word that a quote merely
|
|
1260
|
+
* splits — `k'i'll` — is still one word. An escaped character outside quotes loses its meaning:
|
|
1261
|
+
* kept when it is a letter or digit (`k\ill` is `kill`), replaced by `_` otherwise, so `\;` is no
|
|
1262
|
+
* separator and `\'` opens no string.
|
|
1263
|
+
*/
|
|
1264
|
+
function scan(command, dialect) {
|
|
1265
|
+
const result = { bare: '', quoted: [], embedded: [], regexes: new Set(), interpolated: new Map() };
|
|
1266
|
+
const escape = escapeOf(dialect);
|
|
1267
|
+
let index = 0;
|
|
1268
|
+
while (index < command.length) {
|
|
1269
|
+
const character = command[index];
|
|
1270
|
+
// A regular expression is a literal like a string: a quote inside it opens nothing, and a call
|
|
1271
|
+
// spelled inside it is not made.
|
|
1272
|
+
const regex = dialect === 'js' ? regexAt(command, index, result.bare) : undefined;
|
|
1273
|
+
if (regex !== undefined) {
|
|
1274
|
+
result.quoted.push(command.slice(index, regex));
|
|
1275
|
+
result.regexes.add(result.quoted.length - 1);
|
|
1276
|
+
result.bare += `\u0000${result.quoted.length - 1}\u0000`;
|
|
1277
|
+
index = regex;
|
|
1278
|
+
continue;
|
|
1279
|
+
}
|
|
1280
|
+
if (escapesOutside(dialect) && character === escape) {
|
|
1281
|
+
const next = command[index + 1] ?? '';
|
|
1282
|
+
// An escaped line break continues the line: `node \` then `-e …` is one command.
|
|
1283
|
+
if (next === '\n') {
|
|
1284
|
+
index += 2;
|
|
1285
|
+
continue;
|
|
1286
|
+
}
|
|
1287
|
+
if (next === '\r' && command[index + 2] === '\n') {
|
|
1288
|
+
index += 3;
|
|
1289
|
+
continue;
|
|
1290
|
+
}
|
|
1291
|
+
result.bare += /[A-Za-z0-9]/.test(next) ? next : '_';
|
|
1292
|
+
index += 2;
|
|
1293
|
+
continue;
|
|
1294
|
+
}
|
|
1295
|
+
const close = quoteEnd(command, index, dialect);
|
|
1296
|
+
if (close === undefined) {
|
|
1297
|
+
result.bare += character;
|
|
1298
|
+
index += 1;
|
|
1299
|
+
continue;
|
|
1300
|
+
}
|
|
1301
|
+
// A Python triple-quoted string's text is inside its three quotes on each side.
|
|
1302
|
+
const triple = dialect === 'hash' && (character === '"' || character === "'") && command.startsWith(character.repeat(3), index) && close - index >= 5;
|
|
1303
|
+
const raw = triple ? command.slice(index + 3, close - 2) : command.slice(index + 1, close);
|
|
1304
|
+
// The span's text as the program receives it, and the same with every escaped character
|
|
1305
|
+
// blanked, so `\$(…)` is not read as a substitution.
|
|
1306
|
+
let content = '';
|
|
1307
|
+
let live = '';
|
|
1308
|
+
// A Python string's prefix (`r"…"`, `b'…'`, `rb"…"`) touches its quote. `r` keeps backslashes.
|
|
1309
|
+
const prefix = dialect === 'hash' && (character === '"' || character === "'") ? /(?:^|[^\w])([rRbBuUfF]{1,2})$/.exec(result.bare)?.[1] : undefined;
|
|
1310
|
+
const rawString = prefix !== undefined && /r/i.test(prefix);
|
|
1311
|
+
// Ruby's and Perl's single quotes decode only \\ and \': `'ok\nkill'` keeps its backslash.
|
|
1312
|
+
const singleQuoted = (dialect === 'ruby' || dialect === 'perl') && character === "'";
|
|
1313
|
+
const escapes = character === '"' || dialect === 'js' || dialect === 'hash' || dialect === 'ruby' || dialect === 'perl' || (dialect === 'posix' && command[index - 1] === '$');
|
|
1314
|
+
for (let at = 0; at < raw.length; at += 1) {
|
|
1315
|
+
if ((rawString || singleQuoted) && raw[at] === '\\') {
|
|
1316
|
+
const next = raw[at + 1] ?? '';
|
|
1317
|
+
const kept = rawString ? '\\' + next : next === '\\' || next === character ? next : '\\' + next;
|
|
1318
|
+
content += kept;
|
|
1319
|
+
live += '\u0001'.repeat(kept.length);
|
|
1320
|
+
at += 1;
|
|
1321
|
+
continue;
|
|
1322
|
+
}
|
|
1323
|
+
// In program code, `\u006b` and `\x6b` in a string are the character they name.
|
|
1324
|
+
const named = (dialect === 'js' || dialect === 'hash' || dialect === 'ruby' || dialect === 'perl') && raw[at] === '\\' ? escapeAt(raw, at) : undefined;
|
|
1325
|
+
if (named) {
|
|
1326
|
+
content += named.text;
|
|
1327
|
+
live += '\u0001';
|
|
1328
|
+
at += named.length - 1;
|
|
1329
|
+
continue;
|
|
1330
|
+
}
|
|
1331
|
+
// `\n` in a JavaScript or Python string is a line break, so `execSync('echo ok\nkill …')` runs
|
|
1332
|
+
// two commands; a backslash before a line break continues the string.
|
|
1333
|
+
const simple = (dialect === 'js' || dialect === 'hash' || dialect === 'ruby' || dialect === 'perl') && raw[at] === '\\' ? PROGRAM_ESCAPES[raw[at + 1] ?? ''] : undefined;
|
|
1334
|
+
if (simple !== undefined) {
|
|
1335
|
+
content += simple;
|
|
1336
|
+
live += '\u0001';
|
|
1337
|
+
at += 1;
|
|
1338
|
+
continue;
|
|
1339
|
+
}
|
|
1340
|
+
if (escapes && raw[at] === escape && dialect !== 'cmd' && at + 1 < raw.length) {
|
|
1341
|
+
const escaped = shellEscape(dialect, character, raw, at);
|
|
1342
|
+
content += escaped.text;
|
|
1343
|
+
live += '\u0001';
|
|
1344
|
+
at += escaped.length - 1;
|
|
1345
|
+
continue;
|
|
1346
|
+
}
|
|
1347
|
+
if (dialect === 'powershell' && raw[at] === character && raw[at + 1] === character) {
|
|
1348
|
+
content += character;
|
|
1349
|
+
live += '\u0001';
|
|
1350
|
+
at += 1;
|
|
1351
|
+
continue;
|
|
1352
|
+
}
|
|
1353
|
+
content += raw[at];
|
|
1354
|
+
live += raw[at];
|
|
1355
|
+
}
|
|
1356
|
+
if (character === '"' && (dialect === 'posix' || dialect === 'powershell')) {
|
|
1357
|
+
result.embedded.push(...substitutionBodies(live));
|
|
1358
|
+
}
|
|
1359
|
+
if (character === '"' && dialect === 'posix') {
|
|
1360
|
+
for (const match of live.matchAll(/`([^`]+)`/g))
|
|
1361
|
+
result.embedded.push(match[1]);
|
|
1362
|
+
}
|
|
1363
|
+
if (character === '`' && dialect === 'js') {
|
|
1364
|
+
// Only an unescaped `${` interpolates; `\${…}` is the literal text.
|
|
1365
|
+
for (let at = 0; at < raw.length; at += 1) {
|
|
1366
|
+
if (raw[at] === '\\') {
|
|
1367
|
+
at += 1;
|
|
1368
|
+
continue;
|
|
1369
|
+
}
|
|
1370
|
+
if (raw[at] !== '$' || raw[at + 1] !== '{')
|
|
1371
|
+
continue;
|
|
1372
|
+
const end = braceEnd(raw, at + 1, dialect);
|
|
1373
|
+
result.embedded.push(raw.slice(at + 2, end - 1));
|
|
1374
|
+
at = end - 1;
|
|
1375
|
+
}
|
|
1376
|
+
}
|
|
1377
|
+
// The \`$\` of Bash's \`$'…'\` and \`$"…"\` is part of the quoting, not text: \`$'\x6bill'\` is \`kill\`.
|
|
1378
|
+
if (dialect === 'posix' && result.bare.endsWith('$') && command[index - 1] === '$')
|
|
1379
|
+
result.bare = result.bare.slice(0, -1);
|
|
1380
|
+
result.quoted.push(content);
|
|
1381
|
+
const slot = result.quoted.length - 1;
|
|
1382
|
+
// A Python f-string: the prefix touches the quote, or the previous span of a `'''` opening.
|
|
1383
|
+
if (dialect === 'hash' && /(?:^|[^\w])[rRbB]?[fF][rRbB]?(?:\u0000\d+\u0000)*$/.test(result.bare))
|
|
1384
|
+
result.interpolated.set(slot, /\{\{|\}\}|\{([^{}]*)\}/g);
|
|
1385
|
+
// The prefix is part of the literal, so `os.system(r"…")` reads as a call with a literal argument.
|
|
1386
|
+
if (prefix !== undefined)
|
|
1387
|
+
result.bare = result.bare.slice(0, -prefix.length);
|
|
1388
|
+
// Ruby runs "#{…}" in a double-quoted string; Python prints it.
|
|
1389
|
+
if (dialect === 'ruby' && character === '"')
|
|
1390
|
+
result.interpolated.set(slot, /#\{([^{}]*)\}/g);
|
|
1391
|
+
// Perl runs code inside a double-quoted string's `@{[ … ]}`.
|
|
1392
|
+
if (dialect === 'perl' && character === '"')
|
|
1393
|
+
result.interpolated.set(slot, /@\{\[([^\]]*)\]\}/g);
|
|
1394
|
+
// Python and Ruby join adjacent literals at compile time: `os.system("ki" "ll 80632")` runs
|
|
1395
|
+
// `kill 80632`. The span joins the literal before it, which keeps its slot.
|
|
1396
|
+
const previous = dialect === 'hash' || dialect === 'ruby' ? /\u0000(\d+)\u0000\s*$/.exec(result.bare) : null;
|
|
1397
|
+
if (previous && !result.regexes.has(Number(previous[1]))) {
|
|
1398
|
+
const earlier = Number(previous[1]);
|
|
1399
|
+
result.quoted[earlier] += content;
|
|
1400
|
+
result.quoted.pop();
|
|
1401
|
+
const pattern = result.interpolated.get(slot);
|
|
1402
|
+
result.interpolated.delete(slot);
|
|
1403
|
+
if (pattern && !result.interpolated.has(earlier))
|
|
1404
|
+
result.interpolated.set(earlier, pattern);
|
|
1405
|
+
result.bare = result.bare.trimEnd();
|
|
1406
|
+
index = close + 1;
|
|
1407
|
+
continue;
|
|
1408
|
+
}
|
|
1409
|
+
result.bare += `\u0000${slot}\u0000`;
|
|
1410
|
+
index = close + 1;
|
|
1411
|
+
}
|
|
1412
|
+
return result;
|
|
1413
|
+
}
|
|
1414
|
+
/** The command a line runs last, by name: what a here-document on that line is fed to. */
|
|
1415
|
+
function receiver(line) {
|
|
1416
|
+
const tokens = (line.split(/[;|&]/).pop() ?? '').trim().split(/\s+/).filter(Boolean);
|
|
1417
|
+
let at = 0;
|
|
1418
|
+
while (at < tokens.length && (/^[A-Za-z_]\w*=/.test(tokens[at]) || PREFIXES.has(commandName(tokens[at]))))
|
|
1419
|
+
at += 1;
|
|
1420
|
+
if (at >= tokens.length)
|
|
1421
|
+
return { word: '', args: [] };
|
|
1422
|
+
// Simple quoting is enough here: the arguments only decide whether the reader runs its input.
|
|
1423
|
+
const args = tokens.slice(at + 1).map(token => token.replace(/^(['"])([\s\S]*)\1$/, '$2'));
|
|
1424
|
+
return { word: commandName(tokens[at]), args };
|
|
1425
|
+
}
|
|
1426
|
+
/**
|
|
1427
|
+
* Take here-document and here-string bodies out of a command.
|
|
1428
|
+
*
|
|
1429
|
+
* A body is input to the command that reads it, not a list of statements: `cat <<'EOF'` followed
|
|
1430
|
+
* by `kill 80632` prints that line. Left in place, every line of it would be judged as a command
|
|
1431
|
+
* of its own. Two things in a body do run and are handed back: the whole body when the reader is
|
|
1432
|
+
* an interpreter, and `$( … )` or backtick substitutions when the delimiter is unquoted (and in a
|
|
1433
|
+
* PowerShell `@" … "@` string), which the shell expands before the reader sees them. POSIX shells
|
|
1434
|
+
* have here-documents and PowerShell has here-strings; cmd.exe has neither.
|
|
1435
|
+
*/
|
|
1436
|
+
function withoutDocuments(command, shell) {
|
|
1437
|
+
const result = { text: command, code: [], shell: [] };
|
|
1438
|
+
const substitutions = (body) => {
|
|
1439
|
+
// An escaped `$` or backtick is literal text, in a here-document as in a quoted string.
|
|
1440
|
+
const live = body.replace(/[\\`][$`]/g, ' ');
|
|
1441
|
+
result.shell.push(...substitutionBodies(live));
|
|
1442
|
+
for (const match of live.matchAll(/`([^`]+)`/g))
|
|
1443
|
+
result.shell.push(match[1]);
|
|
1444
|
+
};
|
|
1445
|
+
if (shell === 'powershell') {
|
|
1446
|
+
// The body stays as a single-quoted literal, so a command that evaluates its argument
|
|
1447
|
+
// (`Invoke-Expression @'…'@`) is judged on it, and any other command takes it as data.
|
|
1448
|
+
const literal = (body) => `'${body.replace(/'/g, "''")}'`;
|
|
1449
|
+
result.text = result.text.replace(/@'[ \t]*\r?\n([\s\S]*?)\r?\n'@/g, (_, body) => literal(body));
|
|
1450
|
+
result.text = result.text.replace(/@"[ \t]*\r?\n([\s\S]*?)\r?\n"@/g, (_, body) => { substitutions(body); return literal(body); });
|
|
1451
|
+
return result;
|
|
1452
|
+
}
|
|
1453
|
+
if (shell !== 'posix')
|
|
1454
|
+
return result;
|
|
1455
|
+
// `<<<` is a here-string, a single quoted or bare word, and stays.
|
|
1456
|
+
// The delimiter is a shell word: `END-OF-TEXT`, `'my.eof'`, `\\EOF`, not only word characters.
|
|
1457
|
+
const opener = /(?<!<)<<(-?)[ \t]*(?:(['"])([^'"\n]+)\2|(\\?)([^\s;|&<>()'"`$\\]+))/g;
|
|
1458
|
+
for (let match = opener.exec(result.text); match; match = opener.exec(result.text)) {
|
|
1459
|
+
// `echo "a <<EOF"` opens nothing: the operator only counts where the shell reads syntax.
|
|
1460
|
+
if (insideLiteral(result.text, match.index))
|
|
1461
|
+
continue;
|
|
1462
|
+
const delimiter = match[3] ?? match[5];
|
|
1463
|
+
const literal = match[2] !== undefined || match[4] === '\\';
|
|
1464
|
+
const lineStart = result.text.lastIndexOf('\n', match.index) + 1;
|
|
1465
|
+
const lineEnd = result.text.indexOf('\n', match.index);
|
|
1466
|
+
if (lineEnd === -1)
|
|
1467
|
+
break;
|
|
1468
|
+
const lines = result.text.slice(lineEnd + 1).split('\n');
|
|
1469
|
+
// The closing line is the delimiter exactly: `EOF ` with a trailing blank is body text. `<<-`
|
|
1470
|
+
// strips only leading tabs; a CRLF line's \r is the line ending, not text.
|
|
1471
|
+
const closing = lines.findIndex(line => (match[1] ? line.replace(/^\t+/, '') : line).replace(/\r$/, '') === delimiter);
|
|
1472
|
+
if (closing === -1)
|
|
1473
|
+
continue;
|
|
1474
|
+
const body = lines.slice(0, closing).join('\n');
|
|
1475
|
+
const { word, args } = receiver(result.text.slice(lineStart, match.index));
|
|
1476
|
+
// The body is code only for an interpreter that reads its input (`bash <<EOF`, not
|
|
1477
|
+
// `bash -c 'cat' <<EOF`); the outer shell expands an unquoted body's substitutions either way.
|
|
1478
|
+
const runsBody = INTERPRETERS.has(word) && readsInput(word, withoutRedirections(args));
|
|
1479
|
+
if (runsBody)
|
|
1480
|
+
result.code.push({ word, body: inputProgram(word, withoutRedirections(args), body) });
|
|
1481
|
+
if (!literal)
|
|
1482
|
+
substitutions(body);
|
|
1483
|
+
// For any other reader the body is its input, which a pipeline may carry on to an interpreter
|
|
1484
|
+
// (`cat <<'EOF' | bash`): it stays on the line as a here-string, single-quoted so nothing in it
|
|
1485
|
+
// is read as syntax.
|
|
1486
|
+
const operator = runsBody ? '' : `<<<'${body.replace(/'/g, "'\\''")}'`;
|
|
1487
|
+
const line = result.text.slice(0, match.index) + operator + result.text.slice(match.index + match[0].length, lineEnd + 1);
|
|
1488
|
+
result.text = line + lines.slice(closing + 1).join('\n');
|
|
1489
|
+
opener.lastIndex = match.index + operator.length;
|
|
1490
|
+
}
|
|
1491
|
+
return result;
|
|
1492
|
+
}
|
|
1493
|
+
/**
|
|
1494
|
+
* Whether `position` in a POSIX command line falls inside literal text — a quoted span, an escaped
|
|
1495
|
+
* character, or a comment — where an operator is not an operator.
|
|
1496
|
+
*/
|
|
1497
|
+
function insideLiteral(text, position) {
|
|
1498
|
+
let index = 0;
|
|
1499
|
+
let afterEscape = false;
|
|
1500
|
+
while (index <= position && index < text.length) {
|
|
1501
|
+
const character = text[index];
|
|
1502
|
+
if (character === '\\') {
|
|
1503
|
+
if (position <= index + 1)
|
|
1504
|
+
return true;
|
|
1505
|
+
index += 2;
|
|
1506
|
+
afterEscape = true;
|
|
1507
|
+
continue;
|
|
1508
|
+
}
|
|
1509
|
+
const wordStart = !afterEscape && (index === 0 || /[\s;|&(]/.test(text[index - 1]));
|
|
1510
|
+
afterEscape = false;
|
|
1511
|
+
const close = quoteEnd(text, index, 'posix');
|
|
1512
|
+
if (close !== undefined) {
|
|
1513
|
+
if (position <= close)
|
|
1514
|
+
return true;
|
|
1515
|
+
index = close + 1;
|
|
1516
|
+
continue;
|
|
1517
|
+
}
|
|
1518
|
+
if (character === '#' && wordStart) {
|
|
1519
|
+
const end = text.indexOf('\n', index);
|
|
1520
|
+
if (end === -1 || position < end)
|
|
1521
|
+
return true;
|
|
1522
|
+
index = end;
|
|
1523
|
+
continue;
|
|
1524
|
+
}
|
|
1525
|
+
index += 1;
|
|
1526
|
+
}
|
|
1527
|
+
return false;
|
|
1528
|
+
}
|
|
1529
|
+
/** A command word as it is looked up: no directory, no `.exe`, lower case. */
|
|
1530
|
+
function commandName(word) {
|
|
1531
|
+
const name = word.replace(/^.*[\\/]/, '').replace(/\.(?:exe|cmd|bat|ps1)$/i, '').toLowerCase();
|
|
1532
|
+
// An interpreter named with its version (`python3.12`, `ruby3.2`, `perl5.36`) is that interpreter.
|
|
1533
|
+
const versioned = /^(python|ruby|perl|node|nodejs|pwsh|bash|zsh)[\d.]+$/.exec(name);
|
|
1534
|
+
if (!versioned)
|
|
1535
|
+
return name;
|
|
1536
|
+
return versioned[1] === 'python' ? 'python3' : versioned[1];
|
|
1537
|
+
}
|
|
1538
|
+
/**
|
|
1539
|
+
* Whether `command` ends a process when run in `shell`, as opposed to merely containing the words.
|
|
1540
|
+
*
|
|
1541
|
+
* The command is cut into statements at the separators and grouping characters, and each
|
|
1542
|
+
* statement is judged by the word in command position — after any assignment, keyword, or wrapper
|
|
1543
|
+
* such as `sudo`, `xargs`, or `Start-Process`. An interpreter's code argument is judged by that
|
|
1544
|
+
* interpreter's rules. `comments` is off for text whose comments were already removed by another
|
|
1545
|
+
* language's rules. `depth` bounds the recursion.
|
|
1546
|
+
*/
|
|
1547
|
+
function terminates(command, depth, shell, comments = true) {
|
|
1548
|
+
if (depth > 4)
|
|
1549
|
+
return false;
|
|
1550
|
+
note(command);
|
|
1551
|
+
const documents = withoutDocuments(command, shell);
|
|
1552
|
+
if (documents.code.some(({ word, body }) => codeTerminates(body, depth + 1, dialectOf(word))))
|
|
1553
|
+
return true;
|
|
1554
|
+
if (documents.shell.some(inner => terminates(inner, depth + 1, shell)))
|
|
1555
|
+
return true;
|
|
1556
|
+
// A shell comment runs nothing: `echo built # then kill 80632`.
|
|
1557
|
+
const { bare, quoted, embedded } = scan(comments ? stripComments(documents.text, shell) : documents.text, shell);
|
|
1558
|
+
if (callsKill(bare))
|
|
1559
|
+
return true;
|
|
1560
|
+
if (embedded.some(inner => terminates(inner, depth + 1, shell)))
|
|
1561
|
+
return true;
|
|
1562
|
+
const unquote = (token) => token.replace(/\u0000(\d+)\u0000/g, (_, slot) => quoted[Number(slot)] ?? '');
|
|
1563
|
+
// The `&` of a redirection (`2>&1`, `&>file`) joins it to its operand rather than ending a statement.
|
|
1564
|
+
// A redirection needs no blank before it: `kill>/dev/null 80632` runs `kill`. A word that is
|
|
1565
|
+
// only a descriptor number (`2>`) stays attached to its operator.
|
|
1566
|
+
const joined = bare.replace(/([<>])&/g, '$1\u0002').replace(/&>/g, '\u0002>')
|
|
1567
|
+
.replace(/(?<=[^\s\d<>\u0002;|&(){}])(?=[<>])/g, ' ');
|
|
1568
|
+
if (pipedIntoInterpreter(joined, unquote, depth))
|
|
1569
|
+
return true;
|
|
1570
|
+
for (const statement of joined.split(/[;\n|&(){}]|`[^`]*`/)) {
|
|
1571
|
+
const raw = statement.trim().split(/\s+/).filter(Boolean);
|
|
1572
|
+
if (wordsTerminate(raw, raw.map(unquote), depth, shell))
|
|
1573
|
+
return true;
|
|
1574
|
+
}
|
|
1575
|
+
// Backtick substitution in a POSIX shell runs its contents.
|
|
1576
|
+
if (shell === 'posix')
|
|
1577
|
+
for (const match of bare.matchAll(/`([^`]*)`/g))
|
|
1578
|
+
if (terminates(match[1], depth + 1, shell))
|
|
1579
|
+
return true;
|
|
1580
|
+
return false;
|
|
1581
|
+
}
|
|
1582
|
+
/**
|
|
1583
|
+
* Whether an interpreter runs what arrives on its input: given no code and no script file
|
|
1584
|
+
* (`bash`, `node`, `python3`), or told to read it (`-`, `bash -s`, `powershell -Command -`), or
|
|
1585
|
+
* `iex` with no argument, which runs its pipeline input. `node script.js` reads a file instead.
|
|
1586
|
+
*/
|
|
1587
|
+
function readsInput(word, args) {
|
|
1588
|
+
if (shellNoExec(word, args) || rubySyntaxOnly(word, args))
|
|
1589
|
+
return false;
|
|
1590
|
+
if (word === 'iex' || word === 'invoke-expression')
|
|
1591
|
+
return args.length === 0;
|
|
1592
|
+
if (word === 'eval')
|
|
1593
|
+
return false;
|
|
1594
|
+
// `node --check` parses its input without running it.
|
|
1595
|
+
if ((word === 'node' || word === 'nodejs') && nodeChecksOnly(args))
|
|
1596
|
+
return false;
|
|
1597
|
+
if (word === 'cmd')
|
|
1598
|
+
return !args.some(argument => /^\/[ck]$/i.test(argument));
|
|
1599
|
+
const code = interpreterCode(word, args);
|
|
1600
|
+
if (code.length === 1 && code[0] === '-')
|
|
1601
|
+
return true;
|
|
1602
|
+
if (code.length > 0)
|
|
1603
|
+
return false;
|
|
1604
|
+
const powershell = word === 'powershell' || word === 'pwsh';
|
|
1605
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
1606
|
+
const argument = args[index];
|
|
1607
|
+
if (argument === '-')
|
|
1608
|
+
return true;
|
|
1609
|
+
if (argument === '--')
|
|
1610
|
+
return args[index + 1] === undefined || args[index + 1] === '-';
|
|
1611
|
+
if (SHELLS.has(word) && /^-[A-Za-z]*s[A-Za-z]*$/.test(argument))
|
|
1612
|
+
return true;
|
|
1613
|
+
if (!argument.startsWith('-') && !shellPlusOption(word, argument))
|
|
1614
|
+
return false;
|
|
1615
|
+
if (powershell && /^-(?:f(?:i(?:le?)?)?)$/i.test(argument))
|
|
1616
|
+
return args[index + 1] === '-';
|
|
1617
|
+
if ((word === 'python' || word === 'python3' || word === 'py') && argument === '-m')
|
|
1618
|
+
return false;
|
|
1619
|
+
if ((NODE_FAMILY.has(word) && NODE_VALUE_OPTIONS.has(argument)) || INTERPRETER_VALUE_OPTIONS[word]?.has(argument) || (powershell && POWERSHELL_VALUE_OPTIONS.test(argument)))
|
|
1620
|
+
index += 1;
|
|
1621
|
+
}
|
|
1622
|
+
return true;
|
|
1623
|
+
}
|
|
1624
|
+
/** The text a statement's here-strings feed to its command: `<<< 'text'` or `<<<text`. */
|
|
1625
|
+
function hereStrings(words) {
|
|
1626
|
+
const fed = [];
|
|
1627
|
+
for (let index = 0; index < words.length; index += 1) {
|
|
1628
|
+
const word = words[index];
|
|
1629
|
+
if (word === '<<<') {
|
|
1630
|
+
if (words[index + 1] !== undefined)
|
|
1631
|
+
fed.push(words[index + 1]);
|
|
1632
|
+
index += 1;
|
|
1633
|
+
continue;
|
|
1634
|
+
}
|
|
1635
|
+
if (word.startsWith('<<<'))
|
|
1636
|
+
fed.push(word.slice(3));
|
|
1637
|
+
}
|
|
1638
|
+
return fed;
|
|
1639
|
+
}
|
|
1640
|
+
/** A statement's arguments with its redirections and their operands removed: they are not arguments. */
|
|
1641
|
+
function withoutRedirections(words) {
|
|
1642
|
+
const kept = [];
|
|
1643
|
+
for (let index = 0; index < words.length; index += 1) {
|
|
1644
|
+
const redirect = /^(?:\d+|\*|\u0002)?(?:<<<|>>?|<<?|>\||<>)(.*)$/.exec(words[index]);
|
|
1645
|
+
if (redirect) {
|
|
1646
|
+
if (!redirect[1])
|
|
1647
|
+
index += 1;
|
|
1648
|
+
continue;
|
|
1649
|
+
}
|
|
1650
|
+
kept.push(words[index]);
|
|
1651
|
+
}
|
|
1652
|
+
return kept;
|
|
1653
|
+
}
|
|
1654
|
+
/** Commands whose output is their arguments: what they print is what a pipe passes on. */
|
|
1655
|
+
const PRINTERS = new Set(['echo', 'write-output', 'write', 'echo.']);
|
|
1656
|
+
/** An argument quoted as Bash's `printf %q` quotes it: every character that means something escaped. */
|
|
1657
|
+
function shellQuote(value) {
|
|
1658
|
+
if (value === '')
|
|
1659
|
+
return "''";
|
|
1660
|
+
return value.replace(/[^A-Za-z0-9_\/.,:=@%+-]/g, character => character === '\n' ? "$'\\n'" : `\\${character}`);
|
|
1661
|
+
}
|
|
1662
|
+
/**
|
|
1663
|
+
* What `echo` writes. Its leading `-n`, `-e` and `-E` options are not output. Backslash escapes
|
|
1664
|
+
* are expanded unless the last of `-e`/`-E` is `-E`: Bash expands them with `-e`, and `sh` (dash)
|
|
1665
|
+
* and `zsh` always do, so expanding when unsure can only show more lines. PowerShell's printers
|
|
1666
|
+
* expand nothing here; their escapes were resolved as the string's own text.
|
|
1667
|
+
*/
|
|
1668
|
+
function echoOutput(word, args) {
|
|
1669
|
+
let at = 0;
|
|
1670
|
+
let expand = word === 'echo' || word === 'echo.';
|
|
1671
|
+
let explicit = false;
|
|
1672
|
+
while (at < args.length && /^-[neE]+$/.test(args[at])) {
|
|
1673
|
+
const flag = args[at];
|
|
1674
|
+
const last = flag.replace(/n/g, '').slice(-1);
|
|
1675
|
+
if (last === 'E') {
|
|
1676
|
+
expand = false;
|
|
1677
|
+
explicit = true;
|
|
1678
|
+
}
|
|
1679
|
+
else if (last === 'e') {
|
|
1680
|
+
expand = true;
|
|
1681
|
+
explicit = true;
|
|
1682
|
+
}
|
|
1683
|
+
at += 1;
|
|
1684
|
+
}
|
|
1685
|
+
const text = args.slice(at).join(' ');
|
|
1686
|
+
if (!expand)
|
|
1687
|
+
return text;
|
|
1688
|
+
// Bash's echo prints escapes as written unless told `-e`; dash's and zsh's expand them. Either
|
|
1689
|
+
// reading may be the dangerous one (`\x27; kill …; \x27` is quoting only once expanded), so
|
|
1690
|
+
// an echo that says neither writes both, each on its own lines.
|
|
1691
|
+
if (word === 'echo' && !explicit) {
|
|
1692
|
+
const expanded = echoEscapes(text);
|
|
1693
|
+
return expanded === text ? text : `${text}\n${expanded}`;
|
|
1694
|
+
}
|
|
1695
|
+
return echoEscapes(text);
|
|
1696
|
+
}
|
|
1697
|
+
/** `echo -e`'s escapes, decoded: `\0NNN`, `\xHH`, `\uHHHH`, `\UHHHHHHHH` and the letters. */
|
|
1698
|
+
function echoEscapes(text) {
|
|
1699
|
+
// Bash's echo -e (and printf's %b) also decodes \uHHHH and \UHHHHHHHH: `\u006bill` is `kill`.
|
|
1700
|
+
return text.replace(/\\(?:0([0-7]{0,3})|x([0-9a-fA-F]{1,2})|u([0-9a-fA-F]{1,4})|U([0-9a-fA-F]{1,8})|([abefnrtv\\]))/g, (whole, octal, hex, short, long, letter) => {
|
|
1701
|
+
if (octal !== undefined)
|
|
1702
|
+
return String.fromCharCode(parseInt(octal || '0', 8));
|
|
1703
|
+
if (hex !== undefined)
|
|
1704
|
+
return String.fromCharCode(parseInt(hex, 16));
|
|
1705
|
+
const point = short ?? long;
|
|
1706
|
+
if (point !== undefined) {
|
|
1707
|
+
const value = parseInt(point, 16);
|
|
1708
|
+
return value <= 0x10ffff ? String.fromCodePoint(value) : whole;
|
|
1709
|
+
}
|
|
1710
|
+
return { a: '\u0007', b: '\b', e: '\u001b', f: '\f', n: '\n', r: '\r', t: '\t', v: '\v', '\\': '\\' }[letter];
|
|
1711
|
+
});
|
|
1712
|
+
}
|
|
1713
|
+
/**
|
|
1714
|
+
* A printf format's escapes, which differ from `echo -e`'s: `\NNN` is octal with one to three
|
|
1715
|
+
* digits and no leading zero (`\153` is k), and `\uHHHH` and `\UHHHHHHHH` name code points.
|
|
1716
|
+
*/
|
|
1717
|
+
function printfEscapes(format) {
|
|
1718
|
+
return format.replace(/\\(?:([0-7]{1,3})|x([0-9a-fA-F]{1,2})|u([0-9a-fA-F]{1,4})|U([0-9a-fA-F]{1,8})|([abefnrtv\\"'?]))/g, (whole, octal, hex, short, long, letter) => {
|
|
1719
|
+
if (octal !== undefined)
|
|
1720
|
+
return String.fromCharCode(parseInt(octal, 8) & 0xff);
|
|
1721
|
+
if (hex !== undefined)
|
|
1722
|
+
return String.fromCharCode(parseInt(hex, 16));
|
|
1723
|
+
const point = short ?? long;
|
|
1724
|
+
if (point !== undefined) {
|
|
1725
|
+
const value = parseInt(point, 16);
|
|
1726
|
+
return value <= 0x10ffff ? String.fromCodePoint(value) : whole;
|
|
1727
|
+
}
|
|
1728
|
+
return { a: '\u0007', b: '\b', e: '\u001b', f: '\f', n: '\n', r: '\r', t: '\t', v: '\v', '\\': '\\', '"': '"', "'": "'", '?': '?' }[letter];
|
|
1729
|
+
});
|
|
1730
|
+
}
|
|
1731
|
+
/**
|
|
1732
|
+
* What `printf FORMAT ARGS…` writes: each conversion in the format takes the next argument, the
|
|
1733
|
+
* format is reused while arguments remain, and `\n`, `\t` and `%%` become what they name.
|
|
1734
|
+
*/
|
|
1735
|
+
function printfOutput(args) {
|
|
1736
|
+
// The format's own escapes are expanded; an argument's are not, except through %b.
|
|
1737
|
+
const [written = '', ...values] = args;
|
|
1738
|
+
const format = printfEscapes(written);
|
|
1739
|
+
const conversion = /%(?:(%)|([-+ #0']*)(\*|\d*)(?:\.(\*|\d*))?([bcdiouxXeEfFgGsq]))/g;
|
|
1740
|
+
let out = '';
|
|
1741
|
+
let next = 0;
|
|
1742
|
+
// The format is reused only while a pass consumes arguments: `%%` consumes none, so
|
|
1743
|
+
// `printf 'echo %%s' x` is one pass. Each pass takes at least one, so this ends.
|
|
1744
|
+
for (;;) {
|
|
1745
|
+
const before = next;
|
|
1746
|
+
out += format.replace(conversion, (_, percent, flags, width, precision, kind) => {
|
|
1747
|
+
if (percent)
|
|
1748
|
+
return '%';
|
|
1749
|
+
// A `*` width or precision takes its value from the next argument.
|
|
1750
|
+
// Widths and numeric precisions are bounded: they only pad with blanks or zeros, and rendering
|
|
1751
|
+
// a ten-million-character field would stall the engine's thread before approval. A string's
|
|
1752
|
+
// precision (`%.5000s`) only cuts its argument, which is already in memory, so it is taken as
|
|
1753
|
+
// written: bounding it would drop text that the shell prints and runs.
|
|
1754
|
+
const bound = (value) => Math.max(-PRINTF_FIELD_MAX, Math.min(PRINTF_FIELD_MAX, Number.isFinite(value) ? Math.trunc(value) : 0));
|
|
1755
|
+
const size = bound(width === '*' ? Number(values[next++] ?? 0) : width === '' ? 0 : Number(width));
|
|
1756
|
+
const written = precision === undefined ? undefined : precision === '*' ? Number(values[next++] ?? 0) : precision === '' ? 0 : Number(precision);
|
|
1757
|
+
// A negative precision (`%.*s` given -1) counts as none: the whole argument is printed.
|
|
1758
|
+
const places = written === undefined || written < 0 ? undefined
|
|
1759
|
+
: /[sbq]/.test(kind) ? (Number.isFinite(written) ? Math.max(0, Math.trunc(written)) : undefined)
|
|
1760
|
+
: Math.max(0, bound(written));
|
|
1761
|
+
return pad(formatConversion(kind, values[next++] ?? '', places), size, flags, /[diouxXeEfFgG]/.test(kind));
|
|
1762
|
+
});
|
|
1763
|
+
if (next === before || next >= values.length)
|
|
1764
|
+
break;
|
|
1765
|
+
// Past the budget the rest is not rendered, but it is still printed: keep the remaining
|
|
1766
|
+
// arguments as lines of their own, so a command among them is still judged.
|
|
1767
|
+
if (out.length > PRINTF_OUTPUT_MAX)
|
|
1768
|
+
return `${out}\n${values.slice(next).join('\n')}`;
|
|
1769
|
+
}
|
|
1770
|
+
return out;
|
|
1771
|
+
}
|
|
1772
|
+
/** One printf conversion of one argument, as Bash renders it. */
|
|
1773
|
+
/** The widest printf field rendered, and the most output kept, before the rest is judged unread. */
|
|
1774
|
+
const PRINTF_FIELD_MAX = 4096;
|
|
1775
|
+
const PRINTF_OUTPUT_MAX = 200_000;
|
|
1776
|
+
/** The first `count` UTF-8 bytes of `text`. */
|
|
1777
|
+
function bytePrefix(text, count) {
|
|
1778
|
+
return Buffer.from(text, 'utf8').subarray(0, count).toString('utf8');
|
|
1779
|
+
}
|
|
1780
|
+
function formatConversion(kind, value, precision) {
|
|
1781
|
+
// A zero integer with precision 0 prints no digits at all: `printf '%.0dkill' 0` is `kill`.
|
|
1782
|
+
if (precision === 0 && /[diouxX]/.test(kind) && printfInteger(value) === 0)
|
|
1783
|
+
return '';
|
|
1784
|
+
switch (kind) {
|
|
1785
|
+
// A string's precision counts bytes, as printf does: `%.2s` of `é"` is the two bytes of é.
|
|
1786
|
+
case 's': return precision === undefined ? value : bytePrefix(value, precision);
|
|
1787
|
+
case 'b': {
|
|
1788
|
+
const text = percentBEscapes(value);
|
|
1789
|
+
return precision === undefined ? text : bytePrefix(text, precision);
|
|
1790
|
+
}
|
|
1791
|
+
case 'q': return shellQuote(value);
|
|
1792
|
+
case 'c': return value.slice(0, 1);
|
|
1793
|
+
case 'd':
|
|
1794
|
+
case 'i': {
|
|
1795
|
+
const digits = String(Math.abs(printfInteger(value)));
|
|
1796
|
+
return (printfInteger(value) < 0 ? '-' : '') + digits.padStart(precision ?? 0, '0');
|
|
1797
|
+
}
|
|
1798
|
+
case 'u': return String(printfInteger(value) >>> 0 === printfInteger(value) ? printfInteger(value) : printfInteger(value));
|
|
1799
|
+
case 'o': return Math.trunc(printfInteger(value)).toString(8);
|
|
1800
|
+
case 'x': return Math.trunc(printfInteger(value)).toString(16);
|
|
1801
|
+
case 'X': return Math.trunc(printfInteger(value)).toString(16).toUpperCase();
|
|
1802
|
+
case 'e':
|
|
1803
|
+
case 'E': {
|
|
1804
|
+
const text = (Number(value) || 0).toExponential(Math.min(precision ?? 6, 100));
|
|
1805
|
+
return kind === 'E' ? text.toUpperCase() : text;
|
|
1806
|
+
}
|
|
1807
|
+
case 'f':
|
|
1808
|
+
case 'F': return (Number(value) || 0).toFixed(Math.min(precision ?? 6, 100));
|
|
1809
|
+
default: return String(Number(value) || 0);
|
|
1810
|
+
}
|
|
1811
|
+
}
|
|
1812
|
+
/**
|
|
1813
|
+
* A `%b` argument's escapes: those of `echo -e`, and octal both as `\0NNN` and as `\NNN` with one to
|
|
1814
|
+
* three digits (`\153` is k), which echo does not take.
|
|
1815
|
+
*/
|
|
1816
|
+
function percentBEscapes(value) {
|
|
1817
|
+
// One pass, so a backslash an escape produces is not decoded again and `\\153` stays `\153`.
|
|
1818
|
+
return value.replace(/\\(?:0([0-7]{0,3})|([1-7][0-7]{0,2})|x([0-9a-fA-F]{1,2})|u([0-9a-fA-F]{1,4})|U([0-9a-fA-F]{1,8})|([abefnrtv\\]))/g, (whole, zero, octal, hex, short, long, letter) => {
|
|
1819
|
+
if (zero !== undefined || octal !== undefined)
|
|
1820
|
+
return String.fromCharCode(parseInt(zero || octal || '0', 8) & 0xff);
|
|
1821
|
+
if (hex !== undefined)
|
|
1822
|
+
return String.fromCharCode(parseInt(hex, 16));
|
|
1823
|
+
const point = short ?? long;
|
|
1824
|
+
if (point !== undefined) {
|
|
1825
|
+
const code = parseInt(point, 16);
|
|
1826
|
+
return code <= 0x10ffff ? String.fromCodePoint(code) : whole;
|
|
1827
|
+
}
|
|
1828
|
+
return { a: '\u0007', b: '\b', e: '\u001b', f: '\f', n: '\n', r: '\r', t: '\t', v: '\v', '\\': '\\' }[letter];
|
|
1829
|
+
});
|
|
1830
|
+
}
|
|
1831
|
+
/** An argument read as printf reads an integer: decimal, `0x` hex, leading-zero octal, or `'c` a character's code. */
|
|
1832
|
+
function printfInteger(value) {
|
|
1833
|
+
const text = value.trim();
|
|
1834
|
+
const character = /^['"]([\s\S])/.exec(text);
|
|
1835
|
+
if (character)
|
|
1836
|
+
return character[1].codePointAt(0);
|
|
1837
|
+
if (/^[+-]?0x[0-9a-f]+$/i.test(text))
|
|
1838
|
+
return parseInt(text, 16);
|
|
1839
|
+
if (/^[+-]?0[0-7]+$/.test(text))
|
|
1840
|
+
return parseInt(text, 8);
|
|
1841
|
+
const number = parseInt(text, 10);
|
|
1842
|
+
return Number.isNaN(number) ? 0 : number;
|
|
1843
|
+
}
|
|
1844
|
+
/** Pad to a printf width: left with spaces, right with `-`, or with zeros for a number with `0`. */
|
|
1845
|
+
function pad(text, width, flags, numeric) {
|
|
1846
|
+
if (text.length >= Math.abs(width))
|
|
1847
|
+
return text;
|
|
1848
|
+
if (flags.includes('-') || width < 0)
|
|
1849
|
+
return text.padEnd(Math.abs(width));
|
|
1850
|
+
if (flags.includes('0') && numeric)
|
|
1851
|
+
return text.startsWith('-') ? `-${text.slice(1).padStart(width - 1, '0')}` : text.padStart(width, '0');
|
|
1852
|
+
return text.padStart(width);
|
|
1853
|
+
}
|
|
1854
|
+
/**
|
|
1855
|
+
* The text a pipeline stage writes, when it can be read from the stage itself: the arguments of
|
|
1856
|
+
* `echo` or `printf`, the here-string `cat` copies, or — in PowerShell — a stage that is nothing
|
|
1857
|
+
* but literals, which outputs them. Undefined when the output is not written out in the command.
|
|
1858
|
+
*/
|
|
1859
|
+
function producedText(raw, words) {
|
|
1860
|
+
if (raw.length === 0)
|
|
1861
|
+
return undefined;
|
|
1862
|
+
if (raw.every(token => /^(?:\u0000\d+\u0000)+$/.test(token)))
|
|
1863
|
+
return words.join(' ');
|
|
1864
|
+
const word = commandName(words[0]);
|
|
1865
|
+
if (PRINTERS.has(word))
|
|
1866
|
+
return echoOutput(word, words.slice(1));
|
|
1867
|
+
if (word === 'printf')
|
|
1868
|
+
return printfOutput(words.slice(1).filter((argument, index) => !(index === 0 && argument === '--')));
|
|
1869
|
+
if (word === 'cat' || word === 'get-content') {
|
|
1870
|
+
const fed = hereStrings(words.slice(1));
|
|
1871
|
+
return fed.length > 0 ? fed.join('\n') : undefined;
|
|
1872
|
+
}
|
|
1873
|
+
return undefined;
|
|
1874
|
+
}
|
|
1875
|
+
/**
|
|
1876
|
+
* Whether a regular expression could take super-linear time: a group with a repeat after it
|
|
1877
|
+
* (`(a+)+`, `(a|a)*`), a back-reference, or more than one repeat of any kind (`a*a*b` is cubic on a
|
|
1878
|
+
* run of a's, `a?a?a?aaa` exponential). Matching runs on the engine's thread before approval, so a
|
|
1879
|
+
* pattern that might stall is not run: the input is kept whole instead. Bracket contents and
|
|
1880
|
+
* escaped characters are not operators and are skipped.
|
|
1881
|
+
*/
|
|
1882
|
+
function mayBacktrack(source) {
|
|
1883
|
+
let open = 0;
|
|
1884
|
+
for (let index = 0; index < source.length; index += 1) {
|
|
1885
|
+
const character = source[index];
|
|
1886
|
+
if (character === '\\') {
|
|
1887
|
+
if (/[1-9]/.test(source[index + 1] ?? ''))
|
|
1888
|
+
return true;
|
|
1889
|
+
index += 1;
|
|
1890
|
+
continue;
|
|
1891
|
+
}
|
|
1892
|
+
if (character === '[') {
|
|
1893
|
+
let close = index + 1;
|
|
1894
|
+
if (source[close] === '^')
|
|
1895
|
+
close += 1;
|
|
1896
|
+
if (source[close] === ']')
|
|
1897
|
+
close += 1;
|
|
1898
|
+
while (close < source.length && source[close] !== ']')
|
|
1899
|
+
close += source[close] === '\\' ? 2 : 1;
|
|
1900
|
+
index = close;
|
|
1901
|
+
continue;
|
|
1902
|
+
}
|
|
1903
|
+
if (character === ')' && /[*+?{]/.test(source[index + 1] ?? ''))
|
|
1904
|
+
return true;
|
|
1905
|
+
// A quantifier; `*?` and `+?` are one lazy quantifier, not two.
|
|
1906
|
+
if ((character === '*' || character === '+' || character === '?' || (character === '{' && /^\{\d*,?\d*\}/.test(source.slice(index))))
|
|
1907
|
+
&& !/[*+?}]/.test(source[index - 1] ?? ''))
|
|
1908
|
+
open += 1;
|
|
1909
|
+
}
|
|
1910
|
+
return open > 1;
|
|
1911
|
+
}
|
|
1912
|
+
/** The ranges POSIX bracket classes stand for, written for a JavaScript character class. */
|
|
1913
|
+
const POSIX_CLASSES = {
|
|
1914
|
+
alpha: 'A-Za-z', digit: '0-9', alnum: 'A-Za-z0-9', upper: 'A-Z', lower: 'a-z', space: ' \\t\\n\\r\\f\\v',
|
|
1915
|
+
blank: ' \\t', punct: '!-\\/:-@\\[-`{-~', xdigit: '0-9A-Fa-f', cntrl: '\\x00-\\x1f\\x7f', print: '\\x20-\\x7e', graph: '\\x21-\\x7e',
|
|
1916
|
+
};
|
|
1917
|
+
/**
|
|
1918
|
+
* A grep pattern as a JavaScript regular expression, or undefined when it uses something this
|
|
1919
|
+
* translation does not reproduce. Basic syntax (the default) treats `+ ? | ( ) { }` as literals
|
|
1920
|
+
* and their backslashed forms as operators; extended syntax (`-E`) the reverse. Bracket
|
|
1921
|
+
* expressions keep their POSIX meaning: `[[:digit:]]` is a digit, and a backslash inside one is a
|
|
1922
|
+
* backslash. `\<` and `\>` are word edges.
|
|
1923
|
+
*/
|
|
1924
|
+
function grepPattern(pattern, extended) {
|
|
1925
|
+
let out = '';
|
|
1926
|
+
for (let index = 0; index < pattern.length; index += 1) {
|
|
1927
|
+
const character = pattern[index];
|
|
1928
|
+
if (character === '\\') {
|
|
1929
|
+
const next = pattern[index + 1];
|
|
1930
|
+
if (next === undefined)
|
|
1931
|
+
return undefined;
|
|
1932
|
+
index += 1;
|
|
1933
|
+
if (next === '<' || next === '>') {
|
|
1934
|
+
out += '\\b';
|
|
1935
|
+
continue;
|
|
1936
|
+
}
|
|
1937
|
+
if (/[wWsSbB1-9]/.test(next)) {
|
|
1938
|
+
out += `\\${next}`;
|
|
1939
|
+
continue;
|
|
1940
|
+
}
|
|
1941
|
+
if (!extended && /[+?|(){}]/.test(next)) {
|
|
1942
|
+
out += next;
|
|
1943
|
+
continue;
|
|
1944
|
+
}
|
|
1945
|
+
// Other letters and digits, and \` and \', are GNU extensions or unspecified (\` anchors the
|
|
1946
|
+
// start): not translated, so the input passes whole. Escaped punctuation is the character.
|
|
1947
|
+
if (/[A-Za-z0-9`']/.test(next))
|
|
1948
|
+
return undefined;
|
|
1949
|
+
out += `\\${next}`;
|
|
1950
|
+
continue;
|
|
1951
|
+
}
|
|
1952
|
+
if (character === '[') {
|
|
1953
|
+
let close = index + 1;
|
|
1954
|
+
if (pattern[close] === '^')
|
|
1955
|
+
close += 1;
|
|
1956
|
+
if (pattern[close] === ']')
|
|
1957
|
+
close += 1;
|
|
1958
|
+
let body = '';
|
|
1959
|
+
for (; close < pattern.length && pattern[close] !== ']'; close += 1) {
|
|
1960
|
+
if (pattern[close] === '[' && /[:=.]/.test(pattern[close + 1] ?? '')) {
|
|
1961
|
+
const kind = pattern[close + 1];
|
|
1962
|
+
const end = pattern.indexOf(`${kind}]`, close + 2);
|
|
1963
|
+
if (end === -1)
|
|
1964
|
+
return undefined;
|
|
1965
|
+
const name = pattern.slice(close + 2, end);
|
|
1966
|
+
if (kind !== ':' || POSIX_CLASSES[name] === undefined)
|
|
1967
|
+
return undefined;
|
|
1968
|
+
body += POSIX_CLASSES[name];
|
|
1969
|
+
close = end + 1;
|
|
1970
|
+
continue;
|
|
1971
|
+
}
|
|
1972
|
+
body += pattern[close] === '\\' ? '\\\\' : pattern[close] === ']' ? '\\]' : pattern[close];
|
|
1973
|
+
}
|
|
1974
|
+
if (close >= pattern.length)
|
|
1975
|
+
return undefined;
|
|
1976
|
+
const opened = pattern.slice(index + 1, index + 1 + (pattern[index + 1] === '^' ? 1 : 0));
|
|
1977
|
+
const literalClose = pattern[index + 1 + opened.length] === ']' ? '\\]' : '';
|
|
1978
|
+
// The leading `]` was skipped before the members were collected, so `body` holds all the rest.
|
|
1979
|
+
out += `[${opened}${literalClose}${body}]`;
|
|
1980
|
+
index = close;
|
|
1981
|
+
continue;
|
|
1982
|
+
}
|
|
1983
|
+
if (!extended && /[+?|(){}]/.test(character)) {
|
|
1984
|
+
out += `\\${character}`;
|
|
1985
|
+
continue;
|
|
1986
|
+
}
|
|
1987
|
+
out += character;
|
|
1988
|
+
}
|
|
1989
|
+
// GNU's `{,M}` is `{0,M}`; JavaScript would read `{,M}` as literal text.
|
|
1990
|
+
return out.replace(/(^|[^\\])\{,(\d+)\}/g, '$1{0,$2}');
|
|
1991
|
+
}
|
|
1992
|
+
/** Stages that pass their input on unchanged, or only drop or reorder lines of it. */
|
|
1993
|
+
const FORWARDERS = new Set(['cat', 'tee', 'sort', 'uniq', 'head', 'tail', 'more', 'less', 'out-string', 'tee-object', 'sort-object', 'select-object']);
|
|
1994
|
+
/**
|
|
1995
|
+
* What `head -c N` or `tail -c N` keeps of its input: the first N bytes (all but the last N for
|
|
1996
|
+
* `head -c -N`), the last N (from byte N on for `tail -c +N`). Sizes take K, M, G suffixes. A file
|
|
1997
|
+
* operand is read instead of the input, so the output is then unknown.
|
|
1998
|
+
*/
|
|
1999
|
+
function bytesKept(word, args, upstream) {
|
|
2000
|
+
let size;
|
|
2001
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
2002
|
+
const argument = args[index];
|
|
2003
|
+
if (argument === '-c' || argument === '--bytes') {
|
|
2004
|
+
size = args[index + 1];
|
|
2005
|
+
index += 1;
|
|
2006
|
+
continue;
|
|
2007
|
+
}
|
|
2008
|
+
if (argument.startsWith('--bytes=')) {
|
|
2009
|
+
size = argument.slice('--bytes='.length);
|
|
2010
|
+
continue;
|
|
2011
|
+
}
|
|
2012
|
+
if (/^-c./.test(argument)) {
|
|
2013
|
+
size = argument.slice(2);
|
|
2014
|
+
continue;
|
|
2015
|
+
}
|
|
2016
|
+
if (argument === '-' || argument.startsWith('-'))
|
|
2017
|
+
continue;
|
|
2018
|
+
return undefined;
|
|
2019
|
+
}
|
|
2020
|
+
const input = upstream();
|
|
2021
|
+
if (input === undefined)
|
|
2022
|
+
return undefined;
|
|
2023
|
+
const parsed = /^([+-]?)(\d+)(b|kB|K|KiB|MB|M|MiB|GB|G|GiB)?$/.exec(size ?? '');
|
|
2024
|
+
// A size this does not read keeps the whole input, which can only refuse more.
|
|
2025
|
+
if (!parsed)
|
|
2026
|
+
return input;
|
|
2027
|
+
const unit = { b: 512, kB: 1000, K: 1024, KiB: 1024, MB: 1e6, M: 1048576, MiB: 1048576, GB: 1e9, G: 1073741824, GiB: 1073741824 }[parsed[3] ?? ''] ?? 1;
|
|
2028
|
+
const count = Number(parsed[2]) * unit;
|
|
2029
|
+
// Counted in UTF-8 bytes, as the tools count: `é` is two.
|
|
2030
|
+
const bytes = Buffer.from(input, 'utf8');
|
|
2031
|
+
const kept = word === 'head'
|
|
2032
|
+
? (parsed[1] === '-' ? bytes.subarray(0, Math.max(0, bytes.length - count)) : bytes.subarray(0, count))
|
|
2033
|
+
: (parsed[1] === '+' ? bytes.subarray(Math.max(0, count - 1)) : count === 0 ? bytes.subarray(0, 0) : bytes.subarray(-count));
|
|
2034
|
+
return kept.toString('utf8');
|
|
2035
|
+
}
|
|
2036
|
+
/** Stages that keep the lines of their input that match a pattern. */
|
|
2037
|
+
const FILTERS = new Set(['grep', 'egrep', 'fgrep', 'select-string', 'sls', 'findstr']);
|
|
2038
|
+
/**
|
|
2039
|
+
* The text stage `at` of a pipeline writes, when it can be known from the command line: what a
|
|
2040
|
+
* printer writes, carried through stages that forward their input (`cat`, `tee`, `sort`, `head`,
|
|
2041
|
+
* … — taken to forward all of it) and through `grep`, whose pattern is applied. Anything else
|
|
2042
|
+
* (`sed`, `awk`, a command that reads files) makes the text unknown.
|
|
2043
|
+
*/
|
|
2044
|
+
function stageOutput(stages, at, unquote) {
|
|
2045
|
+
if (at < 0)
|
|
2046
|
+
return undefined;
|
|
2047
|
+
const raw = stages[at];
|
|
2048
|
+
const words = withoutRedirections(raw.map(unquote));
|
|
2049
|
+
const produced = producedText(raw, raw.map(unquote));
|
|
2050
|
+
if (produced !== undefined)
|
|
2051
|
+
return produced;
|
|
2052
|
+
// A wrapped stage (`env cat`, `sudo -u me tee`) produces what the command it runs produces.
|
|
2053
|
+
if (words[0] !== undefined && (PREFIXES.has(commandName(words[0])) || /^[A-Za-z_]\w*=/.test(words[0]))) {
|
|
2054
|
+
for (const reader of stageReaders(words)) {
|
|
2055
|
+
if (PREFIXES.has(reader.word))
|
|
2056
|
+
continue;
|
|
2057
|
+
const unwrapped = stages.slice();
|
|
2058
|
+
unwrapped[at] = [reader.word, ...reader.args];
|
|
2059
|
+
const output = stageOutput(unwrapped, at, unquote);
|
|
2060
|
+
if (output !== undefined)
|
|
2061
|
+
return output;
|
|
2062
|
+
}
|
|
2063
|
+
return undefined;
|
|
2064
|
+
}
|
|
2065
|
+
const word = commandName(words[0] ?? '');
|
|
2066
|
+
const args = words.slice(1);
|
|
2067
|
+
// A stage's input is its own here-string or here-document when it has one, the stage before it
|
|
2068
|
+
// otherwise.
|
|
2069
|
+
const fed = hereStrings(raw.map(unquote).slice(1));
|
|
2070
|
+
const upstream = () => fed.length > 0 ? fed.join('\n') : stageOutput(stages, at - 1, unquote);
|
|
2071
|
+
if ((word === 'head' || word === 'tail') && args.some(argument => /^(?:-c|--bytes)(?:=|$)|^-c./.test(argument))) {
|
|
2072
|
+
// `tail -c 10` and `head -c 4` cut bytes, which can strip a prefix: `xkill 80632` becomes `kill 80632`.
|
|
2073
|
+
return bytesKept(word, args, upstream);
|
|
2074
|
+
}
|
|
2075
|
+
if (FORWARDERS.has(word)) {
|
|
2076
|
+
// A forwarder named with a file reads the file, not its input.
|
|
2077
|
+
if ((word === 'cat' || word === 'sort' || word === 'uniq' || word === 'head' || word === 'tail') && args.some(argument => !argument.startsWith('-') && !/^\d+$/.test(argument)))
|
|
2078
|
+
return undefined;
|
|
2079
|
+
return upstream();
|
|
2080
|
+
}
|
|
2081
|
+
if (!FILTERS.has(word))
|
|
2082
|
+
return undefined;
|
|
2083
|
+
const input = upstream();
|
|
2084
|
+
if (input === undefined)
|
|
2085
|
+
return undefined;
|
|
2086
|
+
const powershell = word === 'select-string' || word === 'sls';
|
|
2087
|
+
const flags = new Set(word === 'fgrep' ? ['F'] : []);
|
|
2088
|
+
const LONG = {
|
|
2089
|
+
'--only-matching': 'o', '--count': 'c', '--files-with-matches': 'l', '--files-without-match': 'L', '--quiet': 'q', '--silent': 'q',
|
|
2090
|
+
'--line-number': 'n', '--byte-offset': 'b', '--with-filename': 'H', '--no-filename': 'h', '--line-regexp': 'x', '--word-regexp': 'w',
|
|
2091
|
+
'--invert-match': 'v', '--ignore-case': 'i', '--fixed-strings': 'F', '--extended-regexp': 'E', '--perl-regexp': 'P', '--null-data': 'z',
|
|
2092
|
+
};
|
|
2093
|
+
// `-e` may be given several times, and a line is kept if it matches any of them.
|
|
2094
|
+
const patterns = [];
|
|
2095
|
+
let named = false;
|
|
2096
|
+
let maxCount = Number.POSITIVE_INFINITY;
|
|
2097
|
+
let pattern;
|
|
2098
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
2099
|
+
const argument = args[index];
|
|
2100
|
+
if (argument === '-e' || argument === '--regexp' || /^-pattern$/i.test(argument)) {
|
|
2101
|
+
if (args[index + 1] !== undefined)
|
|
2102
|
+
patterns.push(args[index + 1]);
|
|
2103
|
+
named = true;
|
|
2104
|
+
index += 1;
|
|
2105
|
+
continue;
|
|
2106
|
+
}
|
|
2107
|
+
if (argument.startsWith('--regexp=')) {
|
|
2108
|
+
patterns.push(argument.slice('--regexp='.length));
|
|
2109
|
+
named = true;
|
|
2110
|
+
continue;
|
|
2111
|
+
}
|
|
2112
|
+
if (/^-e.+/.test(argument) && !powershell) {
|
|
2113
|
+
patterns.push(argument.slice(2));
|
|
2114
|
+
named = true;
|
|
2115
|
+
continue;
|
|
2116
|
+
}
|
|
2117
|
+
// Patterns from a file are not on the command line.
|
|
2118
|
+
if (argument === '-f' || argument.startsWith('--file'))
|
|
2119
|
+
return input;
|
|
2120
|
+
if (powershell && /^-notmatch$/i.test(argument)) {
|
|
2121
|
+
flags.add('v');
|
|
2122
|
+
continue;
|
|
2123
|
+
}
|
|
2124
|
+
if (powershell && /^-simplematch$/i.test(argument)) {
|
|
2125
|
+
flags.add('F');
|
|
2126
|
+
continue;
|
|
2127
|
+
}
|
|
2128
|
+
if (powershell && /^-casesensitive$/i.test(argument))
|
|
2129
|
+
continue;
|
|
2130
|
+
// Options that take a value: the value is not the pattern. `-m` limits the lines kept; context
|
|
2131
|
+
// options add lines around each match, so the input is then taken to pass whole.
|
|
2132
|
+
const long = /^--(max-count|after-context|before-context|context|devices|directories|binary-files|colou?r|label|include|exclude|exclude-dir|exclude-from|group-separator)(?:=([\s\S]*))?$/.exec(argument);
|
|
2133
|
+
if (long) {
|
|
2134
|
+
const value = long[2] ?? args[++index] ?? '';
|
|
2135
|
+
if (long[1] === 'max-count')
|
|
2136
|
+
maxCount = Number(value);
|
|
2137
|
+
if (long[1].endsWith('context'))
|
|
2138
|
+
return input;
|
|
2139
|
+
continue;
|
|
2140
|
+
}
|
|
2141
|
+
// `--no-ignore-case` undoes an earlier `-i`: options apply in order.
|
|
2142
|
+
if (argument === '--no-ignore-case') {
|
|
2143
|
+
flags.delete('i');
|
|
2144
|
+
continue;
|
|
2145
|
+
}
|
|
2146
|
+
if (LONG[argument]) {
|
|
2147
|
+
flags.add(LONG[argument]);
|
|
2148
|
+
continue;
|
|
2149
|
+
}
|
|
2150
|
+
if (argument.startsWith('--'))
|
|
2151
|
+
continue;
|
|
2152
|
+
if (/^-[A-Za-z0-9]+$/.test(argument) && !powershell) {
|
|
2153
|
+
const letters = argument.slice(1);
|
|
2154
|
+
for (let at = 0; at < letters.length; at += 1) {
|
|
2155
|
+
const letter = letters[at];
|
|
2156
|
+
// `-2` is two lines of context.
|
|
2157
|
+
if (/\d/.test(letter))
|
|
2158
|
+
return input;
|
|
2159
|
+
if (!'mABCdDef'.includes(letter)) {
|
|
2160
|
+
flags.add(letter);
|
|
2161
|
+
continue;
|
|
2162
|
+
}
|
|
2163
|
+
const attached = letters.slice(at + 1);
|
|
2164
|
+
const value = attached !== '' ? attached : (args[index + 1] ?? '');
|
|
2165
|
+
if (attached === '')
|
|
2166
|
+
index += 1;
|
|
2167
|
+
if (letter === 'm')
|
|
2168
|
+
maxCount = Number(value);
|
|
2169
|
+
else if (letter === 'e') {
|
|
2170
|
+
patterns.push(value);
|
|
2171
|
+
named = true;
|
|
2172
|
+
}
|
|
2173
|
+
else if (letter !== 'd' && letter !== 'D')
|
|
2174
|
+
return input;
|
|
2175
|
+
break;
|
|
2176
|
+
}
|
|
2177
|
+
continue;
|
|
2178
|
+
}
|
|
2179
|
+
if (/^-[A-Za-z]+$/.test(argument)) {
|
|
2180
|
+
for (const letter of argument.slice(1))
|
|
2181
|
+
flags.add(letter);
|
|
2182
|
+
continue;
|
|
2183
|
+
}
|
|
2184
|
+
if (!named && pattern === undefined) {
|
|
2185
|
+
pattern = argument;
|
|
2186
|
+
continue;
|
|
2187
|
+
}
|
|
2188
|
+
// `-` names standard input, which is the pipeline's.
|
|
2189
|
+
if (argument === '-')
|
|
2190
|
+
continue;
|
|
2191
|
+
// A file after the pattern: grep reads it instead of its input.
|
|
2192
|
+
return undefined;
|
|
2193
|
+
}
|
|
2194
|
+
if (pattern !== undefined)
|
|
2195
|
+
patterns.push(pattern);
|
|
2196
|
+
// With -z a record ends at a NUL, not a line break, so a match keeps every line of its record.
|
|
2197
|
+
if (flags.has('z'))
|
|
2198
|
+
return input;
|
|
2199
|
+
// Perl syntax (`\Q…\E`, `(?i)`, `\K`) can compile in JavaScript yet match differently, so a
|
|
2200
|
+
// `-P` pattern is not run: the input passes whole.
|
|
2201
|
+
if (flags.has('P'))
|
|
2202
|
+
return input;
|
|
2203
|
+
if (patterns.length === 0)
|
|
2204
|
+
return input;
|
|
2205
|
+
// grep reads a pattern argument's lines as separate patterns too.
|
|
2206
|
+
const each = patterns.flatMap(item => item.split('\n'));
|
|
2207
|
+
const pieces = each.map(item => flags.has('F') ? item.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
|
|
2208
|
+
: flags.has('P') ? item
|
|
2209
|
+
: grepPattern(item, flags.has('E') || word === 'egrep' || powershell));
|
|
2210
|
+
// A pattern this reading cannot translate faithfully is taken to keep everything: concluding that
|
|
2211
|
+
// nothing gets through would be the unsafe guess.
|
|
2212
|
+
if (pieces.some(piece => piece === undefined))
|
|
2213
|
+
return input;
|
|
2214
|
+
const translated = pieces.length === 1 ? pieces[0] : pieces.map(piece => `(?:${piece})`).join('|');
|
|
2215
|
+
// Matching runs on the engine's thread, so a pattern that could backtrack without bound is not
|
|
2216
|
+
// run at all: a quantified group, more than two open-ended repeats, or a very long line. The
|
|
2217
|
+
// input is then taken to pass whole, which can only refuse more.
|
|
2218
|
+
if (pieces.some(piece => mayBacktrack(piece)) || input.length > 20_000 || input.split('\n').some(line => line.length > 2_000))
|
|
2219
|
+
return input;
|
|
2220
|
+
let source = translated;
|
|
2221
|
+
if (flags.has('x'))
|
|
2222
|
+
source = `^(?:${source})$`;
|
|
2223
|
+
if (flags.has('w'))
|
|
2224
|
+
source = `(?<![\\w])(?:${source})(?![\\w])`;
|
|
2225
|
+
let matcher;
|
|
2226
|
+
try {
|
|
2227
|
+
matcher = new RegExp(source, flags.has('i') || powershell || word === 'findstr' ? 'gi' : 'g');
|
|
2228
|
+
}
|
|
2229
|
+
catch {
|
|
2230
|
+
// A pattern this reading cannot compile is taken to keep everything.
|
|
2231
|
+
return input;
|
|
2232
|
+
}
|
|
2233
|
+
const lines = input.split('\n');
|
|
2234
|
+
const hits = lines.map((line, number) => ({ line, number: number + 1, matched: new RegExp(matcher.source, matcher.flags.replace('g', '')).test(line) !== flags.has('v') }));
|
|
2235
|
+
const kept = hits.filter(hit => hit.matched).slice(0, Number.isFinite(maxCount) && maxCount >= 0 ? maxCount : undefined);
|
|
2236
|
+
// What grep writes, for the flags that change it.
|
|
2237
|
+
if (flags.has('q'))
|
|
2238
|
+
return '';
|
|
2239
|
+
if (flags.has('l'))
|
|
2240
|
+
return kept.length > 0 ? '(standard input)' : '';
|
|
2241
|
+
if (flags.has('L'))
|
|
2242
|
+
return kept.length > 0 ? '' : '(standard input)';
|
|
2243
|
+
if (flags.has('c'))
|
|
2244
|
+
return String(kept.length);
|
|
2245
|
+
const prefix = (number) => `${flags.has('H') ? '(standard input):' : ''}${flags.has('n') ? `${number}:` : ''}${flags.has('b') ? '0:' : ''}`;
|
|
2246
|
+
if (flags.has('o')) {
|
|
2247
|
+
if (flags.has('v'))
|
|
2248
|
+
return '';
|
|
2249
|
+
return kept.flatMap(hit => [...hit.line.matchAll(matcher)].filter(found => found[0] !== '').map(found => prefix(hit.number) + found[0])).join('\n');
|
|
2250
|
+
}
|
|
2251
|
+
return kept.map(hit => prefix(hit.number) + hit.line).join('\n');
|
|
2252
|
+
}
|
|
2253
|
+
/**
|
|
2254
|
+
* The commands that may read a pipeline stage's input: its first word, or the command a wrapper
|
|
2255
|
+
* runs (`env bash`, `sudo -u me bash`, `timeout 5 bash`). Where a wrapper's option may or may not
|
|
2256
|
+
* take a value, both readings are returned. `xargs` turns its input into arguments, not input.
|
|
2257
|
+
*/
|
|
2258
|
+
function stageReaders(words, depth = 0) {
|
|
2259
|
+
let at = 0;
|
|
2260
|
+
while (at < words.length && /^[A-Za-z_]\w*=/.test(words[at]))
|
|
2261
|
+
at += 1;
|
|
2262
|
+
if (at >= words.length)
|
|
2263
|
+
return [];
|
|
2264
|
+
const word = commandName(words[at]);
|
|
2265
|
+
const rest = words.slice(at + 1);
|
|
2266
|
+
if (word === 'xargs' || !PREFIXES.has(word) || depth > 4)
|
|
2267
|
+
return word === 'xargs' ? [] : [{ word, args: rest }];
|
|
2268
|
+
const values = WRAPPER_VALUES[word];
|
|
2269
|
+
const readers = [];
|
|
2270
|
+
for (let index = 0; index < rest.length; index += 1) {
|
|
2271
|
+
const option = rest[index];
|
|
2272
|
+
const lower = option.toLowerCase();
|
|
2273
|
+
if (option === '--')
|
|
2274
|
+
return [...readers, ...stageReaders(rest.slice(index + 1), depth + 1)];
|
|
2275
|
+
if (values?.has(lower)) {
|
|
2276
|
+
readers.push(...stageReaders(rest.slice(index + 1), depth + 1));
|
|
2277
|
+
index += 1;
|
|
2278
|
+
continue;
|
|
2279
|
+
}
|
|
2280
|
+
if (option === '-' || /^[-/][\w?-]+(?:[:=][\s\S]*)?$/.test(option))
|
|
2281
|
+
continue;
|
|
2282
|
+
if (word === 'timeout' && /^\d+(?:\.\d+)?[smhd]?$/.test(option))
|
|
2283
|
+
continue;
|
|
2284
|
+
return [...readers, ...stageReaders(rest.slice(index), depth + 1)];
|
|
2285
|
+
}
|
|
2286
|
+
return readers;
|
|
2287
|
+
}
|
|
2288
|
+
/**
|
|
2289
|
+
* A pipeline stage's words without the grouping around them: `(echo …`, `bash)`, `{ echo …`. A
|
|
2290
|
+
* subshell or a `{ …; }` group passes its input and output through, so `(echo 'kill 80632' | bash)`
|
|
2291
|
+
* and `{ echo … | bash; }` are the same pipeline.
|
|
2292
|
+
*/
|
|
2293
|
+
function ungrouped(words) {
|
|
2294
|
+
const out = [...words];
|
|
2295
|
+
while (out.length > 0 && (out[0] === '{' || out[0].startsWith('('))) {
|
|
2296
|
+
if (out[0] === '{')
|
|
2297
|
+
out.shift();
|
|
2298
|
+
else {
|
|
2299
|
+
out[0] = out[0].replace(/^\(+/, '');
|
|
2300
|
+
if (out[0] === '')
|
|
2301
|
+
out.shift();
|
|
2302
|
+
}
|
|
2303
|
+
}
|
|
2304
|
+
while (out.length > 0 && (out[out.length - 1] === '}' || out[out.length - 1].endsWith(')'))) {
|
|
2305
|
+
const last = out.length - 1;
|
|
2306
|
+
// A word that opens its own parenthesis keeps the close: `$(date)`, `f()`.
|
|
2307
|
+
if (out[last] === '}') {
|
|
2308
|
+
out.pop();
|
|
2309
|
+
continue;
|
|
2310
|
+
}
|
|
2311
|
+
const opened = (out[last].match(/\(/g) ?? []).length;
|
|
2312
|
+
const closed = (out[last].match(/\)/g) ?? []).length;
|
|
2313
|
+
if (closed <= opened)
|
|
2314
|
+
break;
|
|
2315
|
+
// Strip only the closes that have no open in the word itself: `bash)` → `bash`, `$(date))` → `$(date)`.
|
|
2316
|
+
let word = out[last];
|
|
2317
|
+
for (let excess = closed - opened; excess > 0 && word.endsWith(')'); excess -= 1)
|
|
2318
|
+
word = word.slice(0, -1);
|
|
2319
|
+
out[last] = word;
|
|
2320
|
+
if (word === '')
|
|
2321
|
+
out.pop();
|
|
2322
|
+
}
|
|
2323
|
+
return out;
|
|
2324
|
+
}
|
|
2325
|
+
/**
|
|
2326
|
+
* Stages that may drop, reorder or repeat whole lines of their input. Filters (grep and the like)
|
|
2327
|
+
* count as well: where their output is not modelled exactly (`-P`, `-A`, `-z`) it is taken to be
|
|
2328
|
+
* the whole input, which may keep a quote-only line that the real filter drops.
|
|
2329
|
+
*/
|
|
2330
|
+
const LINE_SELECTORS = new Set(['head', 'tail', 'sort', 'uniq', 'tac', 'shuf', 'rev', 'more', 'less', 'select-object', 'sort-object', 'get-unique']);
|
|
2331
|
+
/**
|
|
2332
|
+
* Whether the stages before a reader may hand it lines regrouped: one that selects or reorders
|
|
2333
|
+
* lines, or an `echo` with neither `-e` nor `-E`, whose two readings are written one after the other.
|
|
2334
|
+
*/
|
|
2335
|
+
function linesMayRegroup(stages, unquote) {
|
|
2336
|
+
return stages.some(stage => stageReaders(stage.map(unquote)).some(({ word, args }) => LINE_SELECTORS.has(word) || FILTERS.has(word) || (word === 'echo' && !args.some(argument => /^-[neE]*[eE][neE]*$/.test(argument)))));
|
|
2337
|
+
}
|
|
2338
|
+
/**
|
|
2339
|
+
* Whether a pipeline feeds code to an interpreter that reads it from its input:
|
|
2340
|
+
* `echo 'kill 80632' | bash`, `printf '…' | python3`, `'Stop-Process -Id 80632' | iex`. An
|
|
2341
|
+
* interpreter reads its input as code when it was given no code of its own, or `-`.
|
|
2342
|
+
*/
|
|
2343
|
+
function pipedIntoInterpreter(line, unquote, depth) {
|
|
2344
|
+
// A line break after `|` continues the pipeline: `echo 'kill 80632' |` then `bash` is one pipeline.
|
|
2345
|
+
// Bash's `|&` pipes standard error too; it is a pipe, not a `|` and a background `&`.
|
|
2346
|
+
const continued = line.replace(/\|&/g, '| ').replace(/(?<!\|)\|[ \t]*(?:\r?\n[ \t]*)+/g, '| ');
|
|
2347
|
+
for (const pipeline of continued.split(/;|\n|&&|\|\||&/)) {
|
|
2348
|
+
const stages = pipeline.split('|').map(stage => ungrouped(stage.trim().split(/\s+/).filter(Boolean)));
|
|
2349
|
+
for (let at = 1; at < stages.length; at += 1) {
|
|
2350
|
+
for (const { word, args } of stageReaders(stages[at].map(unquote))) {
|
|
2351
|
+
if (!INTERPRETERS.has(word))
|
|
2352
|
+
continue;
|
|
2353
|
+
// Its own input redirection (`bash </dev/null`, `0<file`, a here-string or here-document)
|
|
2354
|
+
// replaces the pipe: what the stage before writes never reaches it. `<(…)` is a file argument.
|
|
2355
|
+
// `0<&0` and `<&3` duplicate a descriptor that may still be the pipe, so they keep it judged;
|
|
2356
|
+
// `<&-` closes standard input.
|
|
2357
|
+
if (args.some(argument => /^0?<(?![(&\u0002])/.test(argument) || /^0?<[&\u0002]-$/.test(argument)))
|
|
2358
|
+
continue;
|
|
2359
|
+
if (!readsInput(word, withoutRedirections(args)))
|
|
2360
|
+
continue;
|
|
2361
|
+
// Bash drops NUL bytes from what it reads: `echo -e 'ki\0ll 80632' | bash` runs `kill 80632`.
|
|
2362
|
+
// Other readers reject or stop at them, so dropping them can only refuse more.
|
|
2363
|
+
const piped = stageOutput(stages, at - 1, unquote)?.replace(/\0/g, '');
|
|
2364
|
+
if (piped === undefined)
|
|
2365
|
+
continue;
|
|
2366
|
+
const fed = inputProgram(word, withoutRedirections(args), piped);
|
|
2367
|
+
if (codeTerminates(fed, depth + 1, dialectOf(word)))
|
|
2368
|
+
return true;
|
|
2369
|
+
// A stage that drops or reorders lines (`tail -n 1`, `sort`, `uniq`) can remove a line whose
|
|
2370
|
+
// open quote swallowed the next ones in the text as modelled, and an echo that may or may not
|
|
2371
|
+
// expand writes two readings whose quotes must not pair; then each line is judged alone too.
|
|
2372
|
+
// Unchanged input keeps its quoting: a multi-line string stays one string.
|
|
2373
|
+
const lines = fed.split('\n');
|
|
2374
|
+
if (lines.length > 1 && linesMayRegroup(stages.slice(0, at), unquote)
|
|
2375
|
+
&& lines.slice(0, 500).some(each => each.trim() !== '' && codeTerminates(each, depth + 1, dialectOf(word))))
|
|
2376
|
+
return true;
|
|
2377
|
+
}
|
|
2378
|
+
}
|
|
2379
|
+
}
|
|
2380
|
+
return false;
|
|
2381
|
+
}
|
|
2382
|
+
/**
|
|
2383
|
+
* Whether one statement ends a process, given its words as the shell passes them (`words`) and as
|
|
2384
|
+
* they were written (`raw`, where a fully quoted word is one placeholder).
|
|
2385
|
+
*
|
|
2386
|
+
* The command is the first word after any assignment (`$x = …`, `NAME=value`). A wrapper
|
|
2387
|
+
* (`sudo`, `env`, `timeout`, `xargs`, a keyword such as `do`) hands on to the command after its own
|
|
2388
|
+
* options, which [wrappedTerminates] skips by each wrapper's syntax.
|
|
2389
|
+
*/
|
|
2390
|
+
function wordsTerminate(raw, words, depth, shell) {
|
|
2391
|
+
if (depth > 8)
|
|
2392
|
+
return false;
|
|
2393
|
+
let at = 0;
|
|
2394
|
+
while (at < words.length) {
|
|
2395
|
+
const token = words[at];
|
|
2396
|
+
if (/^\$[\w:.]+$/.test(token) && words[at + 1] === '=') {
|
|
2397
|
+
at += 2;
|
|
2398
|
+
continue;
|
|
2399
|
+
}
|
|
2400
|
+
if (/^[A-Za-z_]\w*=/.test(token)) {
|
|
2401
|
+
at += 1;
|
|
2402
|
+
continue;
|
|
2403
|
+
}
|
|
2404
|
+
// A redirection may come first: `2>/dev/null kill …`, `> out kill …`. An operator standing
|
|
2405
|
+
// alone takes the next word as its operand.
|
|
2406
|
+
const redirect = /^(?:\d+|\*|\u0002)?(?:>>?|<<?|>\||<>)(.*)$/.exec(token);
|
|
2407
|
+
if (redirect) {
|
|
2408
|
+
at += redirect[1] ? 1 : 2;
|
|
2409
|
+
continue;
|
|
2410
|
+
}
|
|
2411
|
+
break;
|
|
2412
|
+
}
|
|
2413
|
+
if (at >= words.length)
|
|
2414
|
+
return false;
|
|
2415
|
+
const word = commandName(words[at]);
|
|
2416
|
+
const rest = words.slice(at + 1);
|
|
2417
|
+
// PowerShell's `-WhatIf` (or any prefix of it, `-WhatIf:$true`) only describes what would happen.
|
|
2418
|
+
// To POSIX `kill`, `-WhatIf` is a bad operand after the pid has already been signalled.
|
|
2419
|
+
if (shell === 'powershell' && KILLERS.has(word) && WHATIF_CMDLETS.has(word) && previewsOnly(rest))
|
|
2420
|
+
return false;
|
|
2421
|
+
if (KILLERS.has(word))
|
|
2422
|
+
return !((word === 'kill' || word === 'pkill' || word === 'killall') && probesOnly(word, rest));
|
|
2423
|
+
if (CONDITIONAL_KILLERS.has(word))
|
|
2424
|
+
return rest.some(argument => /\b(?:terminate|delete)\b/i.test(argument));
|
|
2425
|
+
if (INTERPRETERS.has(word)) {
|
|
2426
|
+
const args = withoutRedirections(rest);
|
|
2427
|
+
// `bash <<< 'kill …'`: the here-string is the interpreter's input, which it runs only when it
|
|
2428
|
+
// was given no code or script of its own (`bash -c 'cat' <<< …` prints it).
|
|
2429
|
+
if (readsInput(word, args) && hereStrings(rest).some(code => codeTerminates(inputProgram(word, args, code), depth, dialectOf(word))))
|
|
2430
|
+
return true;
|
|
2431
|
+
const codes = interpreterCode(word, args);
|
|
2432
|
+
// Ruby and Perl join their `-e` fragments into one program, one per line: a call may span them.
|
|
2433
|
+
if ((word === 'ruby' || word === 'perl') && codes.length > 1)
|
|
2434
|
+
codes.push(codes.join('\n'));
|
|
2435
|
+
return codes.some(code => codeTerminates(code, depth, dialectOf(word)));
|
|
2436
|
+
}
|
|
2437
|
+
if (word === 'start-process' || word === 'saps')
|
|
2438
|
+
return startProcessTerminates(rest, depth);
|
|
2439
|
+
// `git -c 'alias.x=!kill 80632' x`: a shell alias is a command line Git hands to sh.
|
|
2440
|
+
if (word === 'git')
|
|
2441
|
+
return gitShellAliases(rest).some(alias => terminates(alias, depth + 1, 'posix'));
|
|
2442
|
+
// `trap 'kill …' EXIT` runs its handler later, in this shell: the handler is shell code.
|
|
2443
|
+
if (word === 'trap') {
|
|
2444
|
+
const handler = rest.find(argument => !/^-[lp]$/.test(argument) && argument !== '--');
|
|
2445
|
+
return handler !== undefined && handler !== '-' && terminates(handler, depth + 1, shell);
|
|
2446
|
+
}
|
|
2447
|
+
if (!PREFIXES.has(word))
|
|
2448
|
+
return false;
|
|
2449
|
+
return wrappedTerminates(word, raw.slice(at + 1), rest, depth, shell);
|
|
2450
|
+
}
|
|
2451
|
+
/** Whether the command a wrapper runs ends a process, past the wrapper's own options. */
|
|
2452
|
+
function wrappedTerminates(wrapper, raw, words, depth, shell) {
|
|
2453
|
+
const values = WRAPPER_VALUES[wrapper];
|
|
2454
|
+
let titled = false;
|
|
2455
|
+
for (let at = 0; at < words.length; at += 1) {
|
|
2456
|
+
const option = words[at];
|
|
2457
|
+
const lower = option.toLowerCase();
|
|
2458
|
+
if (option === '--')
|
|
2459
|
+
return wordsTerminate(raw.slice(at + 1), words.slice(at + 1), depth + 1, shell);
|
|
2460
|
+
if (option === '-')
|
|
2461
|
+
continue;
|
|
2462
|
+
// `env -S 'kill 80632'` splits its value into a command line and runs it.
|
|
2463
|
+
if (wrapper === 'env') {
|
|
2464
|
+
const split = option === '-S' || lower === '--split-string' ? words[at + 1]
|
|
2465
|
+
: /^-S./.test(option) ? option.slice(2) : lower.startsWith('--split-string=') ? option.slice(option.indexOf('=') + 1) : undefined;
|
|
2466
|
+
if (split !== undefined && (terminates(split, depth + 1, 'posix')))
|
|
2467
|
+
return true;
|
|
2468
|
+
if (option === '-S' || lower === '--split-string') {
|
|
2469
|
+
at += 1;
|
|
2470
|
+
continue;
|
|
2471
|
+
}
|
|
2472
|
+
}
|
|
2473
|
+
// cmd's `start` takes a quoted window title before the program: `start "" taskkill …`.
|
|
2474
|
+
if (wrapper === 'start' && !titled && /^\u0000\d+\u0000$/.test(raw[at] ?? '')) {
|
|
2475
|
+
titled = true;
|
|
2476
|
+
continue;
|
|
2477
|
+
}
|
|
2478
|
+
if (values?.has(lower)) {
|
|
2479
|
+
// Read both ways: the next word as this option's value, and as the command.
|
|
2480
|
+
if (wordsTerminate(raw.slice(at + 1), words.slice(at + 1), depth + 1, shell))
|
|
2481
|
+
return true;
|
|
2482
|
+
at += 1;
|
|
2483
|
+
continue;
|
|
2484
|
+
}
|
|
2485
|
+
if (/^[-/][\w?-]+(?:[:=][\s\S]*)?$/.test(option))
|
|
2486
|
+
continue;
|
|
2487
|
+
// `timeout 5 kill …`: the duration comes before the command.
|
|
2488
|
+
if (wrapper === 'timeout' && /^\d+(?:\.\d+)?[smhd]?$/.test(option))
|
|
2489
|
+
continue;
|
|
2490
|
+
return wordsTerminate(raw.slice(at), words.slice(at), depth + 1, shell);
|
|
2491
|
+
}
|
|
2492
|
+
return false;
|
|
2493
|
+
}
|
|
2494
|
+
/**
|
|
2495
|
+
* Whether PowerShell's `Start-Process` is asked to start a process that ends one: the program from
|
|
2496
|
+
* `-FilePath` or the first positional argument, with `-ArgumentList` or the rest. The program and
|
|
2497
|
+
* its arguments are read as one command line, both as POSIX and as PowerShell would.
|
|
2498
|
+
*/
|
|
2499
|
+
function startProcessTerminates(args, depth) {
|
|
2500
|
+
let program;
|
|
2501
|
+
let argumentList;
|
|
2502
|
+
const positional = [];
|
|
2503
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
2504
|
+
const argument = args[index];
|
|
2505
|
+
const lower = argument.toLowerCase();
|
|
2506
|
+
if (/^-(?:f(?:i(?:l(?:e(?:p(?:a(?:th?)?)?)?)?)?)?|pspath|path)$/.test(lower)) {
|
|
2507
|
+
program = args[index + 1];
|
|
2508
|
+
index += 1;
|
|
2509
|
+
continue;
|
|
2510
|
+
}
|
|
2511
|
+
if (/^-(?:a(?:r(?:g(?:u(?:m(?:e(?:n(?:t(?:l(?:i(?:st?)?)?)?)?)?)?)?)?)?)?|args)$/.test(lower)) {
|
|
2512
|
+
argumentList = args[index + 1];
|
|
2513
|
+
index += 1;
|
|
2514
|
+
continue;
|
|
2515
|
+
}
|
|
2516
|
+
if (START_PROCESS_VALUES.test(lower)) {
|
|
2517
|
+
index += 1;
|
|
2518
|
+
continue;
|
|
2519
|
+
}
|
|
2520
|
+
if (lower.startsWith('-'))
|
|
2521
|
+
continue;
|
|
2522
|
+
positional.push(argument);
|
|
2523
|
+
}
|
|
2524
|
+
program ??= positional.shift();
|
|
2525
|
+
argumentList ??= positional.join(' ');
|
|
2526
|
+
if (!program)
|
|
2527
|
+
return false;
|
|
2528
|
+
const line = `${program} ${argumentList}`;
|
|
2529
|
+
return terminates(line, depth + 1, 'posix') || terminates(line, depth + 1, 'powershell');
|
|
2530
|
+
}
|
|
2531
|
+
const escapeRegExp = (text) => text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
2532
|
+
/** The image name without its extension: `andorra-desktop.exe` and `andorra-desktop` are one name. */
|
|
2533
|
+
/**
|
|
2534
|
+
* Whether a name-selecting killer in `text` is given a pattern that matches the host's name, by its
|
|
2535
|
+
* own matching rules: pkill's and pgrep's regular expressions match anywhere in the name
|
|
2536
|
+
* (`pkill -f 'andorra.*desktop'`), `killall -r` likewise, and PowerShell's and taskkill's wildcards
|
|
2537
|
+
* match the whole name (`Stop-Process -Name andorra*`, `taskkill /IM andorra*`).
|
|
2538
|
+
*/
|
|
2539
|
+
function selectsByPattern(text, stem) {
|
|
2540
|
+
const names = [stem, `${stem}.exe`];
|
|
2541
|
+
// The killer may be named by its path: `/usr/bin/pkill`, `C:\Windows\System32\taskkill.exe`.
|
|
2542
|
+
for (const match of text.matchAll(/(?:^|[\s;|&(`{])(?:[^\s;|&()'"]*[\\/])?(pkill|pgrep|killall|stop-process|spps|taskkill|get-process|gps|kill)(?:\.exe)?(?=\s)((?:'[^']*'|"[^"]*"|[^;|&\n'"])*)/gi)) {
|
|
2543
|
+
const killer = match[1].toLowerCase();
|
|
2544
|
+
// A quoted `|` or `;` belongs to the argument: `pkill -f 'andorra-(desktop|other)'`.
|
|
2545
|
+
const tokens = [...match[2].matchAll(/(?:'[^']*'|"[^"]*"|[^\s'"])+/g)].map(token => token[0].replace(/'([^']*)'|"([^"]*)"/g, '$1$2'));
|
|
2546
|
+
const regex = killer === 'pkill' || killer === 'pgrep' || (killer === 'killall' && tokens.some(word => word === '-r' || word === '--regexp'));
|
|
2547
|
+
// `Get-Process -Name andorra* | Stop-Process` selects with Get-Process's wildcards.
|
|
2548
|
+
// PowerShell's `kill` is Stop-Process when it is given `-Name`; the POSIX kill takes no names.
|
|
2549
|
+
const powershellKill = killer === 'kill' && tokens.some(token => /^-n(?:a(?:m(?:e)?)?)?$/i.test(token));
|
|
2550
|
+
const glob = killer === 'stop-process' || killer === 'spps' || killer === 'taskkill' || killer === 'get-process' || killer === 'gps' || powershellKill;
|
|
2551
|
+
// PowerShell takes several names as an array: `-Name 'node*','andorra*'` and `@('node*', 'andorra*')`
|
|
2552
|
+
// are two selectors each.
|
|
2553
|
+
const words = killer === 'taskkill' || !glob ? tokens
|
|
2554
|
+
: tokens.flatMap(token => token.replace(/^@?\(/, '').replace(/\)$/, '').split(',')).filter(word => word !== '');
|
|
2555
|
+
if (!regex && !glob)
|
|
2556
|
+
continue;
|
|
2557
|
+
for (const word of words) {
|
|
2558
|
+
if (word === '' || /^[-/]/.test(word) && !/[*?]/.test(word))
|
|
2559
|
+
continue;
|
|
2560
|
+
// pkill's patterns are POSIX extended regular expressions (`[[:punct:]]` is punctuation); one the
|
|
2561
|
+
// translation does not reproduce is taken to match when its literal parts appear in the name.
|
|
2562
|
+
const translated = glob ? undefined : grepPattern(word, true);
|
|
2563
|
+
if (!glob && translated === undefined) {
|
|
2564
|
+
if (names.some(name => literalsInOrder(word, name)))
|
|
2565
|
+
return true;
|
|
2566
|
+
continue;
|
|
2567
|
+
}
|
|
2568
|
+
let pattern;
|
|
2569
|
+
try {
|
|
2570
|
+
pattern = glob
|
|
2571
|
+
? new RegExp(`^${wildcardSource(word)}$`, 'i')
|
|
2572
|
+
: new RegExp(translated, 'i');
|
|
2573
|
+
}
|
|
2574
|
+
catch {
|
|
2575
|
+
continue;
|
|
2576
|
+
}
|
|
2577
|
+
// A pattern that could backtrack without bound is not run on the engine's thread: it is taken to
|
|
2578
|
+
// match when its literal parts appear in the name in order, which a pattern built from them may.
|
|
2579
|
+
if (mayBacktrack(pattern.source) ? names.some(name => literalsInOrder(glob ? word.replace(/[*?]/g, '.') : word, name)) : names.some(name => pattern.test(name)))
|
|
2580
|
+
return true;
|
|
2581
|
+
}
|
|
2582
|
+
}
|
|
2583
|
+
return false;
|
|
2584
|
+
}
|
|
2585
|
+
/**
|
|
2586
|
+
* A PowerShell or taskkill wildcard as a regular expression's source: `*` any run, `?` one
|
|
2587
|
+
* character, `[a-c]` one of a set, everything else itself.
|
|
2588
|
+
*/
|
|
2589
|
+
function wildcardSource(word) {
|
|
2590
|
+
let out = '';
|
|
2591
|
+
for (let index = 0; index < word.length; index += 1) {
|
|
2592
|
+
const character = word[index];
|
|
2593
|
+
if (character === '*') {
|
|
2594
|
+
out += '.*';
|
|
2595
|
+
continue;
|
|
2596
|
+
}
|
|
2597
|
+
if (character === '?') {
|
|
2598
|
+
out += '.';
|
|
2599
|
+
continue;
|
|
2600
|
+
}
|
|
2601
|
+
const set = character === '[' ? /^\[([^\]]+)\]/.exec(word.slice(index)) : null;
|
|
2602
|
+
if (set) {
|
|
2603
|
+
out += `[${set[1].replace(/[\\\]^]/g, '\\$&')}]`;
|
|
2604
|
+
index += set[0].length - 1;
|
|
2605
|
+
continue;
|
|
2606
|
+
}
|
|
2607
|
+
out += escapeRegExp(character);
|
|
2608
|
+
}
|
|
2609
|
+
return out;
|
|
2610
|
+
}
|
|
2611
|
+
/** Whether the literal runs of a pattern (the text between its operators) appear in `name` in order. */
|
|
2612
|
+
function literalsInOrder(pattern, name) {
|
|
2613
|
+
// With alternatives (`(andorra|other)+`) only one branch need appear; which one is not worked out
|
|
2614
|
+
// here, so such a pattern is taken to match.
|
|
2615
|
+
if (pattern.replace(/\\./g, '').includes('|'))
|
|
2616
|
+
return true;
|
|
2617
|
+
// Parts that may occur zero times are not required: `(other)?andorra`, `x*andorra`, `(ab){0,2}`.
|
|
2618
|
+
let optional = pattern.replace(/\\./g, '.');
|
|
2619
|
+
for (let previous = ''; previous !== optional;) {
|
|
2620
|
+
previous = optional;
|
|
2621
|
+
optional = optional.replace(/\([^()]*\)(?:\?|\*|\{0(?:,\d*)?\})/g, '.').replace(/[^.\])](?:\?|\*|\{0(?:,\d*)?\})/g, '.');
|
|
2622
|
+
}
|
|
2623
|
+
pattern = optional;
|
|
2624
|
+
// A repetition count (`{30}`, `{2,5}`) is an operator, not text.
|
|
2625
|
+
// A bracket expression (`[[:punct:]]`, `[a-z]`) stands for one character, whatever its text.
|
|
2626
|
+
const runs = pattern.replace(/\\./g, '.').replace(/\[\^?\]?(?:\[:[a-z]+:\]|[^\]])*\]/g, '.').replace(/\{\d*,?\d*\}/g, '.').split(/[\^$.|?*+()[\]{}]+/).filter(Boolean).map(run => run.toLowerCase());
|
|
2627
|
+
let from = 0;
|
|
2628
|
+
const lower = name.toLowerCase();
|
|
2629
|
+
for (const run of runs) {
|
|
2630
|
+
const at = lower.indexOf(run, from);
|
|
2631
|
+
if (at === -1)
|
|
2632
|
+
return false;
|
|
2633
|
+
from = at + run.length;
|
|
2634
|
+
}
|
|
2635
|
+
return true;
|
|
2636
|
+
}
|
|
2637
|
+
function imageStem(name) {
|
|
2638
|
+
return name.replace(/\.exe$/i, '').trim();
|
|
2639
|
+
}
|
|
2640
|
+
/**
|
|
2641
|
+
* Why `command` must not run, or `undefined` when it may.
|
|
2642
|
+
*
|
|
2643
|
+
* Two things must both be true. The command must end a process when run — a kill in command
|
|
2644
|
+
* position, not the words inside a search pattern or a message (`rg 'Stop-Process.*andorra-desktop'`
|
|
2645
|
+
* is a search). And it must name the host anywhere, quoted text included, because the usual shape
|
|
2646
|
+
* is a name filter in one statement feeding a kill in another.
|
|
2647
|
+
*
|
|
2648
|
+
* A process id only counts where it stands alone as a number, so `8063` does not match host
|
|
2649
|
+
* `80632` and a port or a line number that happens to equal the id is the one false positive
|
|
2650
|
+
* accepted: it only arises in a command that also terminates something.
|
|
2651
|
+
*/
|
|
2652
|
+
export function hostKillRefusal(command, host = hostProcess(), shell = 'any') {
|
|
2653
|
+
// A tool whose shell is not known is read both ways: what either shell would run counts.
|
|
2654
|
+
const shells = shell === 'any' ? ['posix', 'powershell'] : [shell];
|
|
2655
|
+
evidence = [];
|
|
2656
|
+
try {
|
|
2657
|
+
if (!shells.some(each => terminates(command, 0, each)))
|
|
2658
|
+
return undefined;
|
|
2659
|
+
return refusalFor(command, host, evidence);
|
|
2660
|
+
}
|
|
2661
|
+
finally {
|
|
2662
|
+
evidence = undefined;
|
|
2663
|
+
}
|
|
2664
|
+
}
|
|
2665
|
+
/** The refusal for text already known to terminate something, when that text names the host. */
|
|
2666
|
+
/** Text with its common escapes expanded: `\n`, `\t`, `\xHH`, `\0nnn`, `\uXXXX`, `\u{…}`. */
|
|
2667
|
+
function expandEscapes(text) {
|
|
2668
|
+
return text.replace(/\\(?:x([0-9a-fA-F]{1,2})|0([0-7]{0,3})|u\{([0-9a-fA-F]{1,6})\}|u([0-9a-fA-F]{4})|([ntr]))/g, (whole, hex, octal, wide, short, letter) => {
|
|
2669
|
+
if (hex !== undefined)
|
|
2670
|
+
return String.fromCharCode(parseInt(hex, 16));
|
|
2671
|
+
if (octal !== undefined)
|
|
2672
|
+
return String.fromCharCode(parseInt(octal || '0', 8));
|
|
2673
|
+
const point = parseInt((wide ?? short) ?? '', 16);
|
|
2674
|
+
if (wide !== undefined || short !== undefined)
|
|
2675
|
+
return point <= 0x10ffff ? String.fromCodePoint(point) : whole;
|
|
2676
|
+
return letter === 'n' ? '\n' : letter === 't' ? '\t' : '\r';
|
|
2677
|
+
});
|
|
2678
|
+
}
|
|
2679
|
+
/** The text with each numeric literal written in plain decimal: `0x13af8` and `80_632` become 80632. */
|
|
2680
|
+
function numbersInDecimal(text) {
|
|
2681
|
+
return text.replace(/(?<![\w.])(0[xX][0-9a-fA-F](?:_?[0-9a-fA-F])*|0[oO][0-7](?:_?[0-7])*|0[bB][01](?:_?[01])*|0|[1-9](?:_?\d)*)n?(?![\w.])/g, (whole, literal) => {
|
|
2682
|
+
try {
|
|
2683
|
+
return BigInt(literal.replace(/_/g, '')).toString();
|
|
2684
|
+
}
|
|
2685
|
+
catch {
|
|
2686
|
+
return whole;
|
|
2687
|
+
}
|
|
2688
|
+
});
|
|
2689
|
+
}
|
|
2690
|
+
/**
|
|
2691
|
+
* The text with each decimal number written as the integer it is worth, where it is one: `080632`
|
|
2692
|
+
* (kill reads decimal), `8.0632e4` and `80632.0` (JavaScript and Python numbers) become 80632.
|
|
2693
|
+
*/
|
|
2694
|
+
function numbersAsValues(text) {
|
|
2695
|
+
return text.replace(/(?<![\w.])(\d+(?:\.\d*)?(?:[eE][+-]?\d+)?)(?![\w.])/g, (whole, literal) => {
|
|
2696
|
+
const value = Number(literal);
|
|
2697
|
+
return Number.isSafeInteger(value) ? String(value) : whole;
|
|
2698
|
+
});
|
|
2699
|
+
}
|
|
2700
|
+
function refusalFor(command, host, derived = []) {
|
|
2701
|
+
const stem = host.name ? imageStem(host.name) : '';
|
|
2702
|
+
// The command as written, and with its escapes expanded: `kill\x2080632` names 80632 once
|
|
2703
|
+
// `echo -e` or a string literal has turned `\x20` into a space.
|
|
2704
|
+
// Also with the shell's quote removal applied: `kill 80'632'` and `andorra'-desktop'` are the
|
|
2705
|
+
// id and the name once the quotes and escapes are gone.
|
|
2706
|
+
// A backslash before a line break joins the lines (`kill 80\\` then `632` is `kill 80632`), and
|
|
2707
|
+
// PowerShell's backtick before one does the same.
|
|
2708
|
+
const joined = command.replace(/[\\`]\r?\n/g, '');
|
|
2709
|
+
const unquoted = joined.replace(/\\([\s\S])/g, '$1').replace(/`([A-Za-z0-9-])/g, '$1').replace(/['"^]/g, '');
|
|
2710
|
+
const written = [command, joined, expandEscapes(command), unquoted, ...derived];
|
|
2711
|
+
// Code may spell the id as any numeric literal: `80_632`, `0x13af8`, `0o235370`, `0b…`, `80632n`.
|
|
2712
|
+
const texts = [...written, ...written.map(numbersInDecimal), ...written.map(numbersAsValues)];
|
|
2713
|
+
// Three characters is the shortest name specific enough to match on.
|
|
2714
|
+
const namesHost = stem.length >= 3 && texts.some(text => new RegExp(`(?<![A-Za-z0-9_-])${escapeRegExp(stem)}(?![A-Za-z0-9_-])`, 'i').test(text)
|
|
2715
|
+
|| selectsByPattern(text, stem));
|
|
2716
|
+
const numbered = (pid) => pid !== undefined && texts.some(text => new RegExp(`(?<![0-9A-Za-z_.])${pid}(?![0-9A-Za-z_.])`).test(text));
|
|
2717
|
+
const hostPid = numbered(host.pid);
|
|
2718
|
+
const ownPid = numbered(host.self);
|
|
2719
|
+
if (!namesHost && !hostPid && !ownPid)
|
|
2720
|
+
return undefined;
|
|
2721
|
+
const target = namesHost
|
|
2722
|
+
? `every process named ${stem}, which includes the Andorra Code app hosting this session${host.pid === undefined ? '' : ` (process id ${host.pid})`}`
|
|
2723
|
+
: hostPid
|
|
2724
|
+
? `process ${host.pid}, which is the Andorra Code app hosting this session`
|
|
2725
|
+
: `process ${host.self}, which is the engine running this session`;
|
|
2726
|
+
return [
|
|
2727
|
+
`Refused: this command would stop ${target}. That would end this run and every other task in the window.`,
|
|
2728
|
+
namesHost
|
|
2729
|
+
? `If you started a test instance, stop only that one by the process id you got when you started it${host.pid === undefined ? '' : `, and never ${host.pid}`}; do not select processes by name.`
|
|
2730
|
+
: 'Stop only processes you started yourself.',
|
|
2731
|
+
'If a second copy of the app did not appear when you launched it, it was handed to the window already open: launch test copies under their own application identifier (see AGENTS.md, "Launching a desktop test instance").',
|
|
2732
|
+
].join(' ');
|
|
2733
|
+
}
|
|
2734
|
+
/**
|
|
2735
|
+
* The text of a `data:` URL — percent-decoded, or base64-decoded when it says so — or undefined
|
|
2736
|
+
* when the value is not one. Node imports such a URL as a module, so its text is code.
|
|
2737
|
+
*/
|
|
2738
|
+
/** Node's options that load a module: their `data:` URL value is code. `--title data:…` is a title. */
|
|
2739
|
+
const NODE_PRELOAD_OPTIONS = new Set(['--import', '--loader', '--experimental-loader', '-r', '--require']);
|
|
2740
|
+
/** The code a Node preload option loads from a `data:` URL, separate (`--import data:…`) or attached (`--import=data:…`). */
|
|
2741
|
+
function nodePreloadCode(argument, next) {
|
|
2742
|
+
if (NODE_PRELOAD_OPTIONS.has(argument))
|
|
2743
|
+
return dataUrlCode(next);
|
|
2744
|
+
const attached = /^(--[\w-]+)=([\s\S]*)$/.exec(argument);
|
|
2745
|
+
return attached && NODE_PRELOAD_OPTIONS.has(attached[1]) ? dataUrlCode(attached[2]) : undefined;
|
|
2746
|
+
}
|
|
2747
|
+
function dataUrlCode(value) {
|
|
2748
|
+
const match = value === undefined ? null : /^data:([^,]*),([\s\S]*)$/i.exec(value);
|
|
2749
|
+
if (!match)
|
|
2750
|
+
return undefined;
|
|
2751
|
+
if (/;base64$/i.test(match[1]))
|
|
2752
|
+
return Buffer.from(match[2], 'base64').toString('utf8');
|
|
2753
|
+
try {
|
|
2754
|
+
return decodeURIComponent(match[2]);
|
|
2755
|
+
}
|
|
2756
|
+
catch {
|
|
2757
|
+
return match[2];
|
|
2758
|
+
}
|
|
2759
|
+
}
|
|
2760
|
+
/** Whether an argument is a `--long` option, with no `=value`, that the value table does not list. */
|
|
2761
|
+
function unknownLongOption(argument) {
|
|
2762
|
+
return argument !== undefined && /^--[\w-]+$/.test(argument) && !NODE_VALUE_OPTIONS.has(argument) && !NODE_EVAL.has(argument);
|
|
2763
|
+
}
|
|
2764
|
+
/** The flags after which Node runs its next argument as code. */
|
|
2765
|
+
const NODE_EVAL = new Set(['-e', '--eval', '-p', '--print', '-pe']);
|
|
2766
|
+
/** Node options that take the next argument as their value, which is therefore not the script. */
|
|
2767
|
+
const NODE_VALUE_OPTIONS = new Set(['-r', '--require', '--import', '--loader', '--experimental-loader', '-C', '--conditions', '--input-type',
|
|
2768
|
+
'--env-file', '--title', '--inspect-port', '--max-http-header-size', '--stack-trace-limit', '--watch-path', '--test-name-pattern', '--test-reporter',
|
|
2769
|
+
'--unhandled-rejections', '--env-file-if-exists', '--disable-warning', '--dns-result-order', '--diagnostic-dir', '--redirect-warnings',
|
|
2770
|
+
'--report-dir', '--report-directory', '--report-filename', '--report-signal', '--heapsnapshot-signal', '--icu-data-dir', '--openssl-config',
|
|
2771
|
+
'--tls-cipher-list', '--tls-keylog', '--cpu-prof-dir', '--cpu-prof-name', '--heap-prof-dir', '--heap-prof-name', '--secure-heap',
|
|
2772
|
+
'--secure-heap-min', '--trace-event-categories', '--trace-event-file-pattern', '--use-largepages', '--experimental-config-file',
|
|
2773
|
+
'--localstorage-file', '--watch-kill-signal', '--test-reporter-destination', '--test-shard', '--test-skip-pattern', '--test-concurrency',
|
|
2774
|
+
'--test-timeout', '--experimental-sea-config', '--snapshot-blob', '--build-snapshot-config', '--max-old-space-size', '--max-semi-space-size']);
|
|
2775
|
+
/**
|
|
2776
|
+
* The refusal for a program started directly with an argument array, with no shell in between.
|
|
2777
|
+
*
|
|
2778
|
+
* Nothing there is shell syntax: an argument such as `; kill 80632` is one literal string handed
|
|
2779
|
+
* to the program, so joining the array and reading it as a command line would invent statements
|
|
2780
|
+
* that never run. Only an argument the program itself executes is judged — the code after Node's
|
|
2781
|
+
* `-e` or `-p` — and only that argument is searched for the host. Node stops reading its own
|
|
2782
|
+
* options at `--` and at the script's path; everything after either belongs to the program being
|
|
2783
|
+
* run, so a later `-e` there is data too.
|
|
2784
|
+
*/
|
|
2785
|
+
export function hostKillRefusalForArgv(program, args, host = hostProcess()) {
|
|
2786
|
+
// Git runs a command-line shell alias through sh, so the alias's text is a shell command.
|
|
2787
|
+
if (commandName(program) === 'git') {
|
|
2788
|
+
for (const alias of gitShellAliases(args)) {
|
|
2789
|
+
const refusal = hostKillRefusal(alias, host, 'posix');
|
|
2790
|
+
if (refusal)
|
|
2791
|
+
return refusal;
|
|
2792
|
+
}
|
|
2793
|
+
return undefined;
|
|
2794
|
+
}
|
|
2795
|
+
if (commandName(program) !== 'node')
|
|
2796
|
+
return undefined;
|
|
2797
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
2798
|
+
const argument = args[index];
|
|
2799
|
+
// The end of Node's options: the marker, or the first argument that is not an option.
|
|
2800
|
+
if (argument === '--')
|
|
2801
|
+
break;
|
|
2802
|
+
// A word after an option this table does not know may be that option's value
|
|
2803
|
+
// (`--some-option value -e …`), so the options are read on rather than stopping there.
|
|
2804
|
+
if (!argument.startsWith('-')) {
|
|
2805
|
+
if (unknownLongOption(args[index - 1]))
|
|
2806
|
+
continue;
|
|
2807
|
+
break;
|
|
2808
|
+
}
|
|
2809
|
+
const inline = /^--(?:eval|print)=/.test(argument) ? argument.slice(argument.indexOf('=') + 1) : undefined;
|
|
2810
|
+
const follows = NODE_EVAL.has(argument);
|
|
2811
|
+
// A preload given as a `data:` URL is code too: `--import data:text/javascript,process.kill(…)`.
|
|
2812
|
+
const preload = nodePreloadCode(argument, args[index + 1]);
|
|
2813
|
+
const code = inline ?? (follows ? args[index + 1] : preload);
|
|
2814
|
+
// The value an option consumes is neither an option nor the script.
|
|
2815
|
+
if (follows || NODE_VALUE_OPTIONS.has(argument))
|
|
2816
|
+
index += 1;
|
|
2817
|
+
if (code === undefined)
|
|
2818
|
+
continue;
|
|
2819
|
+
evidence = [];
|
|
2820
|
+
let refusal;
|
|
2821
|
+
try {
|
|
2822
|
+
if (!codeTerminates(code, 0, 'js'))
|
|
2823
|
+
continue;
|
|
2824
|
+
refusal = refusalFor(code, host, evidence);
|
|
2825
|
+
}
|
|
2826
|
+
finally {
|
|
2827
|
+
evidence = undefined;
|
|
2828
|
+
}
|
|
2829
|
+
if (refusal)
|
|
2830
|
+
return refusal;
|
|
2831
|
+
}
|
|
2832
|
+
return undefined;
|
|
2833
|
+
}
|
|
2834
|
+
/**
|
|
2835
|
+
* The shell aliases a Git command line defines for itself: `-c alias.NAME=!command`, which Git runs
|
|
2836
|
+
* through sh when NAME is invoked. Every such value is returned, invoked or not.
|
|
2837
|
+
*/
|
|
2838
|
+
function gitShellAliases(args) {
|
|
2839
|
+
const aliases = [];
|
|
2840
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
2841
|
+
const value = args[index] === '-c' ? args[index + 1] : /^-c./.test(args[index]) ? args[index].slice(2) : undefined;
|
|
2842
|
+
const alias = value === undefined ? undefined : /^alias\.[^=]+=\s*!([\s\S]*)$/i.exec(value);
|
|
2843
|
+
if (alias)
|
|
2844
|
+
aliases.push(alias[1]);
|
|
2845
|
+
}
|
|
2846
|
+
return aliases;
|
|
2847
|
+
}
|
|
2848
|
+
/** Throw the refusal, for a tool that is about to start `program` with `args` directly. */
|
|
2849
|
+
export function assertNotHostKillArgv(program, args, host = hostProcess()) {
|
|
2850
|
+
const refusal = hostKillRefusalForArgv(program, args, host);
|
|
2851
|
+
if (refusal)
|
|
2852
|
+
throw new Error(refusal);
|
|
2853
|
+
}
|
|
2854
|
+
/** Throw the refusal, for a tool that is about to run `command` in `shell`. */
|
|
2855
|
+
export function assertNotHostKill(command, shell = 'any', host = hostProcess()) {
|
|
2856
|
+
const refusal = hostKillRefusal(command, host, shell);
|
|
2857
|
+
if (refusal)
|
|
2858
|
+
throw new Error(refusal);
|
|
2859
|
+
}
|