@parcha/agentrun-serve 0.1.0-beta.58 → 0.1.0-beta.60
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +402 -1
- package/README.md +516 -190
- package/dist/acp-package.d.ts +5 -1
- package/dist/acp-package.js +19 -2
- package/dist/adapters.d.ts +23 -2
- package/dist/adapters.js +106 -33
- package/dist/agent-delete.d.ts +6 -9
- package/dist/agent-delete.js +5 -3
- package/dist/agent-package.js +11 -1
- package/dist/agents-store.js +1 -1
- package/dist/answer-text.d.ts +3 -0
- package/dist/answer-text.js +22 -0
- package/dist/api-only.d.ts +2 -2
- package/dist/api-only.js +3 -3
- package/dist/archil-routes.d.ts +4 -1
- package/dist/archil-routes.js +15 -12
- package/dist/archil-settings.d.ts +18 -8
- package/dist/archil-settings.js +35 -17
- package/dist/attach-conformance.js +5 -4
- package/dist/box-paths.d.ts +3 -2
- package/dist/box-paths.js +5 -4
- package/dist/browser-computer.d.ts +3 -8
- package/dist/browser-computer.js +12 -35
- package/dist/browser-cost.js +94 -20
- package/dist/capacity.d.ts +1 -1
- package/dist/capacity.js +3 -3
- package/dist/chatgpt-plan.d.ts +7 -0
- package/dist/chatgpt-plan.js +35 -11
- package/dist/claude-login-token.d.ts +20 -11
- package/dist/claude-login-token.js +175 -107
- package/dist/claude-login.d.ts +124 -33
- package/dist/claude-login.js +562 -85
- package/dist/claude-sign-in.d.ts +3 -0
- package/dist/claude-sign-in.js +10 -1
- package/dist/cli-learning/connections.js +1 -1
- package/dist/cli.js +323 -292
- package/dist/composio-made.d.ts +1 -6
- package/dist/composio-made.js +1 -6
- package/dist/composio-owners.d.ts +26 -0
- package/dist/composio-owners.js +36 -0
- package/dist/composio-preset.d.ts +56 -23
- package/dist/composio-preset.js +173 -77
- package/dist/composio-triggers.d.ts +4 -4
- package/dist/composio-triggers.js +6 -7
- package/dist/compute-cost.js +11 -2
- package/dist/computer-attach.d.ts +6 -3
- package/dist/computer-attach.js +41 -29
- package/dist/computer-held-routes.d.ts +1 -1
- package/dist/computer-held-routes.js +9 -4
- package/dist/computer-keys.d.ts +11 -1
- package/dist/computer-keys.js +26 -1
- package/dist/computer-record.js +3 -1
- package/dist/computer-view.d.ts +5 -3
- package/dist/computer-view.js +10 -6
- package/dist/computer-viewer.js +36 -7
- package/dist/computers.d.ts +2 -1
- package/dist/computers.js +6 -3
- package/dist/console/THIRD-PARTY-NOTICES.txt +50 -0
- package/dist/console/assets/backend-QnwGVBeU.js +166 -0
- package/dist/console/assets/index-DZi-muIj.js +629 -0
- package/dist/console/assets/share-pz61zIn9.js +6 -0
- package/dist/console/assets/styles-CcceGcu2.js +291 -0
- package/dist/console/assets/styles-fjQBFfMv.css +1 -0
- package/dist/console/index.html +4 -3
- package/dist/console/share.html +17 -0
- package/dist/decisions.d.ts +17 -7
- package/dist/decisions.js +41 -15
- package/dist/dial-relay.js +10 -4
- package/dist/docker-daemon.js +4 -5
- package/dist/docker-host-addresses.js +29 -11
- package/dist/email/account.d.ts +6 -0
- package/dist/email/account.js +6 -0
- package/dist/email/authentication.d.ts +21 -0
- package/dist/email/authentication.js +106 -0
- package/dist/email/email-faux.d.ts +11 -2
- package/dist/email/email-faux.js +21 -5
- package/dist/email/mail.d.ts +25 -0
- package/dist/email/mail.js +58 -2
- package/dist/email/names.js +2 -2
- package/dist/email/tools.d.ts +9 -4
- package/dist/email/tools.js +95 -13
- package/dist/env-switch.d.ts +12 -2
- package/dist/env-switch.js +23 -3
- package/dist/errors.d.ts +1 -0
- package/dist/errors.js +2 -0
- package/dist/factory-activity.d.ts +68 -0
- package/dist/factory-activity.js +153 -0
- package/dist/factory-runs.d.ts +11 -0
- package/dist/factory-runs.js +52 -0
- package/dist/fal-price.d.ts +11 -1
- package/dist/fal-price.js +33 -0
- package/dist/faux-computers.js +1 -1
- package/dist/filed-answer.d.ts +2 -2
- package/dist/filed-answer.js +2 -2
- package/dist/filed-tool.d.ts +32 -0
- package/dist/filed-tool.js +122 -0
- package/dist/graph-served.d.ts +10 -5
- package/dist/graph-served.js +40 -10
- package/dist/handed-values.js +1 -2
- package/dist/harness-check.d.ts +2 -1
- package/dist/harness-check.js +45 -12
- package/dist/harness-keys.d.ts +1 -2
- package/dist/harness-keys.js +10 -8
- package/dist/harness-opencode/facts.js +2 -0
- package/dist/harness-recipe-entry.d.ts +9 -3
- package/dist/harness-recipe-entry.js +18 -9
- package/dist/harness-recipe.d.ts +21 -0
- package/dist/harness-recipe.js +25 -3
- package/dist/harness-table.d.ts +12 -0
- package/dist/harness-table.js +21 -6
- package/dist/harness.js +6 -2
- package/dist/helper-env.d.ts +4 -1
- package/dist/helper-env.js +4 -1
- package/dist/host-check.d.ts +2 -3
- package/dist/host-check.js +13 -7
- package/dist/hosted-search.js +1 -1
- package/dist/import-worker.js +2 -2
- package/dist/import.d.ts +20 -8
- package/dist/import.js +448 -187
- package/dist/key-refusal.d.ts +14 -2
- package/dist/key-refusal.js +97 -33
- package/dist/learn/audit.d.ts +28 -27
- package/dist/learn/audit.js +87 -62
- package/dist/learn/check.js +1 -1
- package/dist/learn/commit.d.ts +35 -43
- package/dist/learn/commit.js +62 -270
- package/dist/learn/compile.d.ts +9 -6
- package/dist/learn/compile.js +51 -28
- package/dist/learn/corrections.js +1 -1
- package/dist/learn/delete.d.ts +5 -12
- package/dist/learn/delete.js +17 -30
- package/dist/learn/field-check.d.ts +111 -0
- package/dist/learn/field-check.js +174 -0
- package/dist/learn/forget-run.d.ts +16 -0
- package/dist/learn/forget-run.js +53 -0
- package/dist/learn/index.js +1 -1
- package/dist/learn/learning-of.d.ts +0 -4
- package/dist/learn/learning-of.js +0 -5
- package/dist/learn/ledger.d.ts +32 -29
- package/dist/learn/ledger.js +26 -19
- package/dist/learn/{folder.d.ts → legacy/folder.d.ts} +2 -1
- package/dist/learn/{folder.js → legacy/folder.js} +4 -7
- package/dist/learn/legacy/place.d.ts +16 -0
- package/dist/{workspace/learning-workspace.js → learn/legacy/place.js} +12 -42
- package/dist/learn/legacy/scrub.d.ts +28 -0
- package/dist/learn/legacy/scrub.js +258 -0
- package/dist/learn/promote.d.ts +119 -102
- package/dist/learn/promote.js +119 -262
- package/dist/learn/reset-ledger.d.ts +18 -0
- package/dist/learn/reset-ledger.js +14 -0
- package/dist/learn/rows.d.ts +186 -0
- package/dist/learn/rows.js +376 -0
- package/dist/learn/secrets.d.ts +4 -0
- package/dist/learn/secrets.js +12 -0
- package/dist/learn/workflow-draft.d.ts +4 -1
- package/dist/learn/workflow-draft.js +12 -2
- package/dist/learned-nodes.d.ts +8 -5
- package/dist/learned-nodes.js +8 -5
- package/dist/learned-workflow.d.ts +2 -1
- package/dist/learned-workflow.js +13 -10
- package/dist/learning-cost.d.ts +25 -8
- package/dist/learning-cost.js +23 -8
- package/dist/learning-reset.d.ts +1 -1
- package/dist/learning-reset.js +9 -11
- package/dist/learning-routes.d.ts +60 -81
- package/dist/learning-routes.js +187 -360
- package/dist/learning-setting.d.ts +6 -0
- package/dist/learning-setting.js +11 -1
- package/dist/learning-words.d.ts +2 -0
- package/dist/learning-words.js +2 -0
- package/dist/learning.d.ts +18 -24
- package/dist/learning.js +35 -66
- package/dist/listen-first.d.ts +5 -4
- package/dist/listen-first.js +4 -5
- package/dist/live-reach.d.ts +7 -0
- package/dist/live-reach.js +7 -0
- package/dist/mcp-api-only-origins.d.ts +15 -0
- package/dist/mcp-api-only-origins.js +40 -0
- package/dist/mcp-gateway.d.ts +22 -2
- package/dist/mcp-gateway.js +85 -11
- package/dist/mcp-oauth.d.ts +1 -1
- package/dist/mcp-oauth.js +3 -2
- package/dist/mcp-probe.d.ts +3 -0
- package/dist/mcp-probe.js +3 -0
- package/dist/mcp-resources.d.ts +1 -1
- package/dist/mcp-secret-writes.d.ts +24 -2
- package/dist/mcp-secret-writes.js +30 -2
- package/dist/mcp-servers-store.d.ts +52 -14
- package/dist/mcp-servers-store.js +165 -61
- package/dist/mcp-sources.d.ts +1 -2
- package/dist/mcp-sources.js +1 -2
- package/dist/mcp-store.d.ts +5 -5
- package/dist/mcp-store.js +3 -3
- package/dist/mcp.js +1 -1
- package/dist/model-gateway.d.ts +1 -1
- package/dist/model-gateway.js +20 -36
- package/dist/native/discovery.d.ts +6 -0
- package/dist/native/discovery.js +14 -1
- package/dist/native/remote.d.ts +5 -0
- package/dist/native/remote.js +16 -0
- package/dist/native/runtime.js +3 -2
- package/dist/observation/observer.d.ts +6 -6
- package/dist/ollama-provider.d.ts +23 -9
- package/dist/ollama-provider.js +49 -20
- package/dist/openapi.js +290 -79
- package/dist/otel/genai.d.ts +83 -7
- package/dist/otel/genai.js +69 -9
- package/dist/otel/tracer.d.ts +42 -13
- package/dist/otel/tracer.js +241 -56
- package/dist/page.d.ts +7 -1
- package/dist/page.js +76 -22
- package/dist/paid-calls.d.ts +6 -4
- package/dist/paid-calls.js +15 -7
- package/dist/place-offers.d.ts +58 -34
- package/dist/place-offers.js +96 -54
- package/dist/place.d.ts +41 -20
- package/dist/place.js +97 -47
- package/dist/print.js +1 -1
- package/dist/provider.d.ts +3 -2
- package/dist/provider.js +17 -8
- package/dist/purged-workflow.d.ts +0 -33
- package/dist/purged-workflow.js +3 -71
- package/dist/redact/match.d.ts +42 -9
- package/dist/redact/match.js +356 -54
- package/dist/run-census.d.ts +1 -1
- package/dist/run-census.js +4 -5
- package/dist/run-cut.js +4 -5
- package/dist/run-export-store.d.ts +15 -0
- package/dist/run-export-store.js +30 -0
- package/dist/run-export.d.ts +139 -0
- package/dist/run-export.js +379 -0
- package/dist/run-file-cut.d.ts +5 -0
- package/dist/run-file-cut.js +13 -0
- package/dist/run-launch.d.ts +3 -3
- package/dist/run-launch.js +16 -3
- package/dist/run-learning-served.d.ts +3 -3
- package/dist/run-learning-served.js +1 -1
- package/dist/run-listing.d.ts +1 -1
- package/dist/run-model-key.d.ts +15 -6
- package/dist/run-model-key.js +30 -31
- package/dist/run-reads-over-store.js +4 -4
- package/dist/run-secrets.js +3 -5
- package/dist/run-timeline-served.d.ts +1 -1
- package/dist/run-timeline-served.js +8 -5
- package/dist/runnable.js +26 -9
- package/dist/runner/adapter-loop.d.ts +35 -18
- package/dist/runner/adapter-loop.js +94 -47
- package/dist/runner/adapter-run-spec.d.ts +14 -1
- package/dist/runner/adapter-run-spec.js +73 -46
- package/dist/runner/adapters/pi.js +4 -2
- package/dist/runner/audit.d.ts +10 -9
- package/dist/runner/audit.js +64 -67
- package/dist/runner/beside.js +5 -6
- package/dist/runner/claim-secrets.d.ts +10 -3
- package/dist/runner/claim-secrets.js +29 -13
- package/dist/runner/cli-run-spec.d.ts +18 -0
- package/dist/runner/cli-run-spec.js +87 -58
- package/dist/runner/compare-end.d.ts +2 -3
- package/dist/runner/compare-end.js +30 -11
- package/dist/runner/conformance/harness.js +2 -3
- package/dist/runner/conformance/subject.d.ts +4 -1
- package/dist/runner/disk-free.d.ts +15 -4
- package/dist/runner/disk-free.js +25 -7
- package/dist/runner/feedback-round.d.ts +1 -1
- package/dist/runner/feedback-round.js +2 -2
- package/dist/runner/harness-loops.js +3 -4
- package/dist/runner/held.d.ts +5 -12
- package/dist/runner/held.js +0 -25
- package/dist/runner/journal-kinds.d.ts +8 -2
- package/dist/runner/journal-kinds.js +23 -5
- package/dist/runner/learned-first.d.ts +0 -2
- package/dist/runner/learned-first.js +23 -7
- package/dist/runner/learning-end.d.ts +14 -24
- package/dist/runner/learning-end.js +52 -94
- package/dist/runner/learning-seed.d.ts +13 -16
- package/dist/runner/learning-seed.js +13 -23
- package/dist/runner/live-ticker.js +7 -5
- package/dist/runner/loop-contract.d.ts +0 -2
- package/dist/runner/loop.d.ts +7 -0
- package/dist/runner/loop.js +1 -0
- package/dist/runner/main.js +13 -12
- package/dist/runner/mcp-claim.js +21 -5
- package/dist/runner/mcp-run.d.ts +4 -0
- package/dist/runner/mcp-run.js +2 -0
- package/dist/runner/meta-tools.js +3 -2
- package/dist/runner/metrics.d.ts +7 -0
- package/dist/runner/metrics.js +19 -0
- package/dist/runner/model-route.d.ts +10 -7
- package/dist/runner/model-route.js +79 -15
- package/dist/runner/native-loop.js +12 -11
- package/dist/runner/presence.d.ts +1 -4
- package/dist/runner/presence.js +6 -8
- package/dist/runner/promotion.d.ts +39 -36
- package/dist/runner/promotion.js +168 -112
- package/dist/runner/redact.d.ts +3 -1
- package/dist/runner/redact.js +5 -3
- package/dist/runner/reflect-hook.d.ts +2 -2
- package/dist/runner/reflect-hook.js +4 -1
- package/dist/runner/responses-fetch.d.ts +36 -0
- package/dist/runner/responses-fetch.js +511 -0
- package/dist/runner/run-child-host.d.ts +21 -14
- package/dist/runner/run-child-host.js +187 -141
- package/dist/runner/run-child.js +11 -4
- package/dist/runner/runner-check.js +5 -1
- package/dist/runner/runner.d.ts +3 -4
- package/dist/runner/runner.js +13 -9
- package/dist/runner/sdk-loop.js +10 -12
- package/dist/runner/spec-holds.d.ts +8 -1
- package/dist/runner/spec-holds.js +9 -4
- package/dist/runner/workflow-calls.d.ts +9 -0
- package/dist/runner/workflow-calls.js +150 -0
- package/dist/runner/workflow-first.d.ts +120 -32
- package/dist/runner/workflow-first.js +218 -94
- package/dist/runner/workflow-spec.js +1 -1
- package/dist/runs-over-store.js +8 -7
- package/dist/save-once.d.ts +14 -0
- package/dist/save-once.js +31 -0
- package/dist/scrub-command.d.ts +34 -31
- package/dist/scrub-command.js +116 -147
- package/dist/sdk/check.d.ts +1 -4
- package/dist/sdk/check.js +2 -3
- package/dist/sdk/runs.d.ts +26 -7
- package/dist/sdk/runs.js +194 -78
- package/dist/seal-key.js +4 -4
- package/dist/secret-cut.d.ts +3 -0
- package/dist/secret-cut.js +7 -1
- package/dist/secret-rules.d.ts +8 -1
- package/dist/secret-rules.js +482 -53
- package/dist/secrets.d.ts +55 -9
- package/dist/secrets.js +345 -21
- package/dist/server-fs.d.ts +1 -1
- package/dist/server-fs.js +1 -1
- package/dist/server-keys.d.ts +10 -3
- package/dist/server-keys.js +16 -3
- package/dist/server-secrets-store.js +2 -4
- package/dist/server.d.ts +30 -18
- package/dist/server.js +520 -238
- package/dist/share-context.d.ts +22 -0
- package/dist/share-context.js +76 -0
- package/dist/shell-lex.d.ts +105 -0
- package/dist/shell-lex.js +646 -0
- package/dist/sign-ins-store.d.ts +5 -7
- package/dist/sign-ins-store.js +12 -16
- package/dist/sign-ins.d.ts +7 -11
- package/dist/sign-ins.js +40 -41
- package/dist/skills/agentrun-serve/SKILL.md +5 -2
- package/dist/source-sync/auxiliary.js +2 -2
- package/dist/start-switches.d.ts +6 -5
- package/dist/start-switches.js +8 -4
- package/dist/stats.d.ts +5 -1
- package/dist/stats.js +1 -1
- package/dist/store/agent-body.js +2 -2
- package/dist/store/dialect.d.ts +4 -0
- package/dist/store/dialect.js +1 -0
- package/dist/store/index.d.ts +2 -2
- package/dist/store/index.js +1 -1
- package/dist/store/mcp-record-keys.d.ts +10 -0
- package/dist/store/mcp-record-keys.js +13 -0
- package/dist/store/postgres/dialect.js +2 -0
- package/dist/store/postgres/migrations/0029_run_launch_census_settle.sql +28 -0
- package/dist/store/postgres/migrations/0030_learning_ledger_epoch.sql +40 -0
- package/dist/store/postgres/migrations/0031_learning_ledger_calls.sql +12 -0
- package/dist/store/postgres/migrations/0032_learning_rows.sql +65 -0
- package/dist/store/postgres/store.js +4 -0
- package/dist/store/schema.d.ts +60 -11
- package/dist/store/schema.js +147 -17
- package/dist/store/seal.d.ts +4 -1
- package/dist/store/sqlite/learning-rows.d.ts +23 -0
- package/dist/store/sqlite/learning-rows.js +559 -0
- package/dist/store/sqlite/run-launch.d.ts +3 -10
- package/dist/store/sqlite/run-launch.js +12 -23
- package/dist/store/sqlite/run-patch.d.ts +17 -10
- package/dist/store/sqlite/run-patch.js +50 -13
- package/dist/store/sqlite/store.d.ts +9 -0
- package/dist/store/sqlite/store.js +194 -46
- package/dist/store/store-schema.js +3 -4
- package/dist/store/store.d.ts +286 -38
- package/dist/store/store.js +27 -11
- package/dist/store-reads/analytics.d.ts +2 -1
- package/dist/store-reads/analytics.js +7 -5
- package/dist/store-reads/journal.d.ts +33 -3
- package/dist/store-reads/journal.js +99 -4
- package/dist/store-reads/learning.d.ts +50 -45
- package/dist/store-reads/learning.js +153 -116
- package/dist/store-reads/loop.js +1 -1
- package/dist/store-reads/stats.d.ts +2 -2
- package/dist/store-reads/stats.js +13 -7
- package/dist/store-view.d.ts +24 -2
- package/dist/store-view.js +49 -17
- package/dist/suggestions.d.ts +1 -1
- package/dist/suggestions.js +29 -13
- package/dist/template-eval.d.ts +72 -9
- package/dist/template-eval.js +358 -64
- package/dist/templates.d.ts +10 -2
- package/dist/templates.js +31 -4
- package/dist/timeline/labels.d.ts +1 -1
- package/dist/timeline/labels.js +4 -3
- package/dist/timeline/timeline.d.ts +23 -11
- package/dist/timeline/timeline.js +115 -31
- package/dist/timeline/web-calls.d.ts +8 -6
- package/dist/timeline/web-calls.js +10 -6
- package/dist/tool-gate.d.ts +13 -1
- package/dist/tool-gate.js +43 -3
- package/dist/tool-keys-store.js +2 -4
- package/dist/tool-keys.d.ts +11 -0
- package/dist/tool-keys.js +16 -0
- package/dist/tool-plane.d.ts +54 -13
- package/dist/tool-plane.js +103 -32
- package/dist/tools.d.ts +5 -1
- package/dist/tools.js +7 -7
- package/dist/trigger-email.js +12 -6
- package/dist/triggers.d.ts +15 -34
- package/dist/triggers.js +119 -126
- package/dist/validate.d.ts +8 -1
- package/dist/validate.js +163 -23
- package/dist/web-fake.d.ts +2 -1
- package/dist/web-fake.js +8 -6
- package/dist/web-fetch.d.ts +8 -6
- package/dist/web-fetch.js +13 -11
- package/dist/web-holds.d.ts +34 -0
- package/dist/web-holds.js +89 -0
- package/dist/web-run.d.ts +32 -5
- package/dist/web-run.js +76 -28
- package/dist/web-save.js +23 -12
- package/dist/web-search.js +14 -25
- package/dist/wires.d.ts +4 -3
- package/dist/wires.js +5 -4
- package/dist/workspace/archil-claim.d.ts +12 -5
- package/dist/workspace/archil-claim.js +45 -5
- package/dist/workspace/archil-exec.js +1 -1
- package/dist/workspace/archil.d.ts +1 -1
- package/dist/workspace/archil.js +1 -1
- package/dist/workspace/attach.js +52 -19
- package/dist/workspace/attached-computers.d.ts +6 -2
- package/dist/workspace/attached-computers.js +5 -4
- package/dist/workspace/computer-deps.d.ts +23 -6
- package/dist/workspace/computer-deps.js +38 -18
- package/dist/workspace/computer-for-claim.d.ts +21 -4
- package/dist/workspace/computer-for-claim.js +160 -54
- package/dist/workspace/computer-intervals.d.ts +2 -0
- package/dist/workspace/computer-intervals.js +1 -1
- package/dist/workspace/computer-janitor.d.ts +48 -14
- package/dist/workspace/computer-janitor.js +153 -44
- package/dist/workspace/computer-kept.d.ts +158 -32
- package/dist/workspace/computer-kept.js +288 -63
- package/dist/workspace/computer-providers.d.ts +19 -4
- package/dist/workspace/computer-providers.js +40 -6
- package/dist/workspace/index.d.ts +2 -3
- package/dist/workspace/index.js +2 -3
- package/dist/workspace/local.js +41 -1
- package/dist/workspace/mount-revoke-left.d.ts +31 -0
- package/dist/workspace/mount-revoke-left.js +72 -0
- package/dist/workspace/paired-route.js +4 -5
- package/dist/workspace/paths.d.ts +0 -4
- package/dist/workspace/paths.js +0 -6
- package/dist/workspace/resolve-computer.d.ts +5 -2
- package/dist/workspace/resolve-computer.js +9 -3
- package/dist/workspace/run-end-computers.d.ts +11 -5
- package/dist/workspace/run-end-computers.js +153 -28
- package/dist/workspace/run-tools.d.ts +22 -3
- package/dist/workspace/run-tools.js +17 -5
- package/dist/workspace/run-workspace.d.ts +14 -1
- package/dist/workspace/run-workspace.js +34 -1
- package/dist/workspace/workspace.d.ts +7 -1
- package/dist/workspace/workspace.js +1 -1
- package/package.json +13 -14
- package/skills/agentrun-serve/SKILL.md +5 -2
- package/templates/README.md +22 -6
- package/templates/TOOLS.md +46 -0
- package/dist/console/assets/backend-CSAWUqtZ.js +0 -166
- package/dist/console/assets/index-Bwn1oTem.css +0 -1
- package/dist/console/assets/index-DPh29cyz.js +0 -747
- package/dist/workspace/learning-workspace.d.ts +0 -24
- /package/dist/learn/{learning.sh → legacy/learning.sh} +0 -0
|
@@ -0,0 +1,646 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A shell command line read as the shell reads it: words (their quoted, escaped and expanded parts), control
|
|
3
|
+
* operators, redirections, and the bodies of command substitutions. It knows no secret rule; secret-rules.ts reads
|
|
4
|
+
* argv from it (redis-cli, a registry login, mysql, npm set, curl).
|
|
5
|
+
*
|
|
6
|
+
* A transcript is not a script, so three readings differ from the shell's:
|
|
7
|
+
* - Reading starts where the caller says (a command's name), never at the text's start: a prose apostrophe before it
|
|
8
|
+
* opens nothing.
|
|
9
|
+
* - A construct that does not close on its line, before `limit`, or within NEST_MAX levels (a quote, `$(`, a backtick,
|
|
10
|
+
* `${`, `$((`, `<(`) is a character, and reading goes on after it: unknown never ends a command early.
|
|
11
|
+
* - `#` is a character: a comment is still text that can hold a secret.
|
|
12
|
+
* - A non-ASCII blank (NBSP, the ideographic space and the rest of `\s`) separates words as a space does: a password
|
|
13
|
+
* after `-a` and an NBSP is still the flag's.
|
|
14
|
+
*
|
|
15
|
+
* Linear by count: `lexCount.read` counts each character a search reads. A search for a construct's closer that fails
|
|
16
|
+
* is remembered (Misses), so a later opener of that kind inside the span it read fails at once, without reading it
|
|
17
|
+
* again (it would read the same characters, paired the same; failing reads on, so it never ends a command earlier).
|
|
18
|
+
* A flat search (a single quote, `$'`, a backtick, `$((`) reads its whole span alike, so that always holds. A nested
|
|
19
|
+
* one (a double quote, `${`, a group) pairs quotes inside its span, so it holds only for an opener the read saw as one
|
|
20
|
+
* and that did not close. One that closed (`$(b)` in `$(a $(b) c`), or that the failed read took as quoted text
|
|
21
|
+
* (`$(c)` in `$(a 'b $(c) d'`, read again from a command named inside the quotes), is searched again.
|
|
22
|
+
* Callers read a command to commandLimit, which the commands named in one stretch share, so a search that failed at
|
|
23
|
+
* the limit is not read again by the next command (`curl $(a; curl $(a; …`).
|
|
24
|
+
*/
|
|
25
|
+
export const isWord = (token) => "parts" in token;
|
|
26
|
+
/** A command's arguments: its words, without a redirection's target (the word after `>`, `>>`, `<`, `<<`, `&>` and the
|
|
27
|
+
* rest; `>&2` and `<&-` name theirs in the operator) or a descriptor written against one (the `2` of `2>`). Bash
|
|
28
|
+
* gives the command neither. A substitution in a target is still in lex's `subs`. */
|
|
29
|
+
export function argWords(text, tokens) {
|
|
30
|
+
const out = [];
|
|
31
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
32
|
+
const token = tokens[i];
|
|
33
|
+
if (isWord(token)) {
|
|
34
|
+
const next = tokens[i + 1];
|
|
35
|
+
if (next && !isWord(next) && next.op === "redir" && next.start === token.end && DESCRIPTOR.test(text.slice(token.start, token.end)))
|
|
36
|
+
continue;
|
|
37
|
+
out.push(token);
|
|
38
|
+
}
|
|
39
|
+
else if (token.op === "redir" && !OWN_TARGET.test(text.slice(token.start, token.end)) && tokens[i + 1] && isWord(tokens[i + 1]))
|
|
40
|
+
i++;
|
|
41
|
+
}
|
|
42
|
+
return out;
|
|
43
|
+
}
|
|
44
|
+
const DESCRIPTOR = /^[0-9]{1,4}$/;
|
|
45
|
+
/** A redirection that duplicates or closes a descriptor (`>&2`, `2<&-`) and so takes no word after it. */
|
|
46
|
+
const OWN_TARGET = /&(?:-|[0-9]{1,4})$/;
|
|
47
|
+
/** The limit of a command named at `named`: `max` characters past the end of its stretch of `2 * max`, never past `to`.
|
|
48
|
+
* Every command named in one stretch shares it, and each reads at least `max` characters on and at most three times
|
|
49
|
+
* that. */
|
|
50
|
+
export function commandLimit(named, max, to) {
|
|
51
|
+
const stretch = 2 * max;
|
|
52
|
+
return Math.min(to, (Math.floor(named / stretch) + 1) * stretch + max);
|
|
53
|
+
}
|
|
54
|
+
/** Characters read by lex and its closer searches, over every call: the counted guard's measure (shell-lex.test.mjs);
|
|
55
|
+
* the most words secret-rules' commandWords held at once, handed out and not yet let go; and the words its
|
|
56
|
+
* subcommandAt looked at to find a path's words (secret-scrub.test.mjs). Tests' measures: nothing reads them to decide
|
|
57
|
+
* (each Lexed carries its own `reads`). */
|
|
58
|
+
export const lexCount = { read: 0, held: 0, passed: 0 };
|
|
59
|
+
/** How deep constructs nest before the next one is read as a character. */
|
|
60
|
+
export const NEST_MAX = 4;
|
|
61
|
+
/** The kinds whose closer search reads its span flat, pairing nothing inside it. */
|
|
62
|
+
const FLAT = new Set(["sq", "ansi", "tick", "arith"]);
|
|
63
|
+
/** The openers each Misses' reads saw as openers, true once one closed: only one seen and not closed fails from a span
|
|
64
|
+
* (a quote that hid it from the failed read, or a group around it that failed where it closed, says nothing of it). */
|
|
65
|
+
const seenOf = new WeakMap();
|
|
66
|
+
/** Character codes the reader looks at; END is past the limit. */
|
|
67
|
+
const END = -1;
|
|
68
|
+
const TAB = 9, NL = 10, CR = 13, SP = 32, DQ = 34, DOLLAR = 36, AMP = 38, SQ = 39, LP = 40, RP = 41, SEMI = 59;
|
|
69
|
+
const LT = 60, GT = 62, BS = 92, BT = 96, LB = 123, PIPE = 124, RB = 125, MINUS = 45;
|
|
70
|
+
/** ASCII classes, one bit each (a table, not a regex per character: the reader is the scrubber's hot loop). */
|
|
71
|
+
const BLANK = 1, OPERATOR = 2, NAME_START = 4, NAME_CHAR = 8, SPECIAL_VAR = 16, RUN_STOP = 32, DIGIT = 64;
|
|
72
|
+
const CLASS = new Uint8Array(128);
|
|
73
|
+
const mark = (chars, bit) => {
|
|
74
|
+
for (let k = 0; k < chars.length; k++)
|
|
75
|
+
CLASS[chars.charCodeAt(k)] |= bit;
|
|
76
|
+
};
|
|
77
|
+
const LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
78
|
+
mark(" \t", BLANK);
|
|
79
|
+
mark(";&|()<>\n", OPERATOR);
|
|
80
|
+
mark(`${LETTERS}_`, NAME_START);
|
|
81
|
+
mark(`${LETTERS}_0123456789`, NAME_CHAR);
|
|
82
|
+
mark("0123456789?$!#@*-", SPECIAL_VAR);
|
|
83
|
+
/** Where a bare run a limit cut reads on to: a blank, an operator or a quote. */
|
|
84
|
+
mark(" \t\n\r\v\f;&|()<>'\"\x60", RUN_STOP);
|
|
85
|
+
mark("0123456789", DIGIT);
|
|
86
|
+
const is = (c, bit) => c >= 0 && c < 128 && (CLASS[c] & bit) !== 0;
|
|
87
|
+
/** The non-ASCII blanks (`\s` past ASCII: NBSP, the Unicode spaces, the ideographic space, a BOM). The lexer reads
|
|
88
|
+
* each as a blank between words, as a transcript's reader does; bash would not (a transcript is not a script). */
|
|
89
|
+
const WIDE_BLANKS = new Set([0xa0, 0x1680, 0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, 0x2006, 0x2007, 0x2008, 0x2009, 0x200a, 0x2028, 0x2029, 0x202f, 0x205f, 0x3000, 0xfeff]);
|
|
90
|
+
const HEX_ESCAPE = /^[0-9A-Fa-f]{1,2}/;
|
|
91
|
+
const OCTAL_ESCAPE = /^[0-7]{1,3}/;
|
|
92
|
+
const OCTAL_DIGIT = /[0-7]/;
|
|
93
|
+
class Reader {
|
|
94
|
+
text;
|
|
95
|
+
limit;
|
|
96
|
+
misses;
|
|
97
|
+
constructor(text, limit, misses) {
|
|
98
|
+
this.text = text;
|
|
99
|
+
this.limit = limit;
|
|
100
|
+
this.misses = misses;
|
|
101
|
+
let seen = seenOf.get(misses);
|
|
102
|
+
if (!seen)
|
|
103
|
+
seenOf.set(misses, (seen = new Map()));
|
|
104
|
+
this.seen = seen;
|
|
105
|
+
}
|
|
106
|
+
seen;
|
|
107
|
+
/** Characters this reader's searches read (lex adds them to lexCount and returns them). */
|
|
108
|
+
reads = 0;
|
|
109
|
+
/** Where the last group (`$(`, `<(`, `>(`) that failed stopped, until a token stream outside any group reads past
|
|
110
|
+
* it: a group whose own tokens hold a group that failed fails there too (it reads the same characters from the
|
|
111
|
+
* same place, the failed one's `(` one level deeper), so its search ends at once instead of reading them again. */
|
|
112
|
+
groupFail = -1;
|
|
113
|
+
at(i) {
|
|
114
|
+
return i < this.limit ? this.text.charCodeAt(i) : END;
|
|
115
|
+
}
|
|
116
|
+
/** Whether the opener at `open` fails without a search. A flat search (a single quote, `$'`, a backtick, `$((`)
|
|
117
|
+
* reads every character of its span alike, so the span decides. A nested one (`"`, `${`, a group) can hold an
|
|
118
|
+
* opener in its quotes that it never read as one: that opener is searched until a read has seen it. */
|
|
119
|
+
missed(kind, open) {
|
|
120
|
+
const miss = this.misses.get(kind);
|
|
121
|
+
const inSpan = miss !== undefined && miss.from <= open && open < miss.to && miss.limit >= Math.min(this.limit, miss.to + 1);
|
|
122
|
+
const seen = this.seen.get(open);
|
|
123
|
+
if (FLAT.has(kind))
|
|
124
|
+
return inSpan && seen !== true;
|
|
125
|
+
if (seen === undefined) {
|
|
126
|
+
this.seen.set(open, false);
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
return !seen && inSpan;
|
|
130
|
+
}
|
|
131
|
+
/** `end`, the index past the closer of the construct at `open`, remembered as closed. */
|
|
132
|
+
closes(open, end) {
|
|
133
|
+
this.seen.set(open, true);
|
|
134
|
+
return end;
|
|
135
|
+
}
|
|
136
|
+
fail(kind, open, to) {
|
|
137
|
+
// It closed at another depth, if ever: from here on the span decides.
|
|
138
|
+
this.seen.set(open, false);
|
|
139
|
+
const miss = this.misses.get(kind);
|
|
140
|
+
// Keep the wider span: a nested search fails first, inside the one around it.
|
|
141
|
+
if (!(miss && miss.from <= open && miss.to >= to && miss.limit >= this.limit))
|
|
142
|
+
this.misses.set(kind, { from: open, to, limit: this.limit });
|
|
143
|
+
return -1;
|
|
144
|
+
}
|
|
145
|
+
/** Where the single quote at `open` closes (the index past it), or -1. */
|
|
146
|
+
single(open) {
|
|
147
|
+
if (this.missed("sq", open))
|
|
148
|
+
return -1;
|
|
149
|
+
for (let i = open + 1;; i++) {
|
|
150
|
+
this.reads++;
|
|
151
|
+
const c = this.at(i);
|
|
152
|
+
if (c === SQ)
|
|
153
|
+
return i + 1;
|
|
154
|
+
if (c === END || c === NL)
|
|
155
|
+
return this.fail("sq", open, i);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
/** `$'…'` from its `$`: a backslash escapes the next character. */
|
|
159
|
+
ansi(open) {
|
|
160
|
+
if (this.missed("ansi", open))
|
|
161
|
+
return -1;
|
|
162
|
+
for (let i = open + 2;; i++) {
|
|
163
|
+
this.reads++;
|
|
164
|
+
const c = this.at(i);
|
|
165
|
+
if (c === SQ)
|
|
166
|
+
return i + 1;
|
|
167
|
+
if (c === END || c === NL)
|
|
168
|
+
return this.fail("ansi", open, i);
|
|
169
|
+
if (c === BS)
|
|
170
|
+
i++;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
/** A double-quoted part from its first quote (`"` at `quote`, `open` its start: `$"` starts one before): the index
|
|
174
|
+
* past its closer, or -1; `inner` gets its expansions, and `subs` the substitution bodies inside them once it closes
|
|
175
|
+
* (one that does not close is characters, read again as such). */
|
|
176
|
+
double(open, quote, nest, inner, subs) {
|
|
177
|
+
if (this.missed("dq", open))
|
|
178
|
+
return -1;
|
|
179
|
+
const found = subs && [];
|
|
180
|
+
for (let i = quote + 1;;) {
|
|
181
|
+
this.reads++;
|
|
182
|
+
const c = this.at(i);
|
|
183
|
+
if (c === DQ) {
|
|
184
|
+
if (found)
|
|
185
|
+
subs.push(...found);
|
|
186
|
+
return this.closes(open, i + 1);
|
|
187
|
+
}
|
|
188
|
+
if (c === END || c === NL)
|
|
189
|
+
return this.fail("dq", open, i);
|
|
190
|
+
if (c === BS) {
|
|
191
|
+
i += this.at(i + 1) === END ? 1 : 2;
|
|
192
|
+
continue;
|
|
193
|
+
}
|
|
194
|
+
if (c === DOLLAR || c === BT) {
|
|
195
|
+
const part = this.expansion(i, nest, false, found);
|
|
196
|
+
this.groupFail = -1;
|
|
197
|
+
if (part) {
|
|
198
|
+
inner.push(part);
|
|
199
|
+
i = part.end;
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
i++;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
/** The expansion opening at `i` (`$…` or a backtick), or undefined when there is none or it does not close.
|
|
207
|
+
* `quotes`: `$'` and `$"` open quotes here (not inside double quotes). */
|
|
208
|
+
expansion(i, nest, quotes, subs) {
|
|
209
|
+
const c = this.at(i);
|
|
210
|
+
if (c === BT) {
|
|
211
|
+
const end = this.tick(i);
|
|
212
|
+
if (end < 0)
|
|
213
|
+
return undefined;
|
|
214
|
+
subs?.push([i + 1, end - 1]);
|
|
215
|
+
return { kind: "tick", start: i, end };
|
|
216
|
+
}
|
|
217
|
+
if (c !== DOLLAR)
|
|
218
|
+
return undefined;
|
|
219
|
+
const d = this.at(i + 1);
|
|
220
|
+
if (d === LP) {
|
|
221
|
+
if (this.at(i + 2) === LP) {
|
|
222
|
+
const end = this.arith(i);
|
|
223
|
+
if (end >= 0)
|
|
224
|
+
return { kind: "arith", start: i, end };
|
|
225
|
+
}
|
|
226
|
+
const end = this.group(i, i + 1, nest, "sub");
|
|
227
|
+
if (end < 0)
|
|
228
|
+
return undefined;
|
|
229
|
+
subs?.push([i + 2, end - 1]);
|
|
230
|
+
return { kind: "sub", start: i, end };
|
|
231
|
+
}
|
|
232
|
+
if (d === LB) {
|
|
233
|
+
const end = this.brace(i, nest, subs);
|
|
234
|
+
return end < 0 ? undefined : { kind: "brace", start: i, end };
|
|
235
|
+
}
|
|
236
|
+
if (quotes && d === SQ) {
|
|
237
|
+
const end = this.ansi(i);
|
|
238
|
+
return end < 0 ? undefined : { kind: "ansi", start: i, end };
|
|
239
|
+
}
|
|
240
|
+
if (quotes && d === DQ) {
|
|
241
|
+
const inner = [];
|
|
242
|
+
const end = this.double(i, i + 1, nest, inner, subs);
|
|
243
|
+
return end < 0 ? undefined : { kind: "dq", start: i, end, inner };
|
|
244
|
+
}
|
|
245
|
+
if (is(d, NAME_START)) {
|
|
246
|
+
let end = i + 2;
|
|
247
|
+
while (is(this.at(end), NAME_CHAR)) {
|
|
248
|
+
this.reads++;
|
|
249
|
+
end++;
|
|
250
|
+
}
|
|
251
|
+
return { kind: "var", start: i, end };
|
|
252
|
+
}
|
|
253
|
+
if (is(d, SPECIAL_VAR))
|
|
254
|
+
return { kind: "var", start: i, end: i + 2 };
|
|
255
|
+
return undefined;
|
|
256
|
+
}
|
|
257
|
+
/** A backtick substitution from its opener: the index past its closer, or -1. */
|
|
258
|
+
tick(open) {
|
|
259
|
+
if (this.missed("tick", open))
|
|
260
|
+
return -1;
|
|
261
|
+
for (let i = open + 1;; i++) {
|
|
262
|
+
this.reads++;
|
|
263
|
+
const c = this.at(i);
|
|
264
|
+
if (c === BT)
|
|
265
|
+
return i + 1;
|
|
266
|
+
if (c === END || c === NL)
|
|
267
|
+
return this.fail("tick", open, i);
|
|
268
|
+
if (c === BS)
|
|
269
|
+
i++;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
/** `${…}` from its `$`: to the `}` that closes it, quotes and nested expansions read whole; `subs` gets the
|
|
273
|
+
* substitution bodies inside it once it closes. */
|
|
274
|
+
brace(open, nest, subs) {
|
|
275
|
+
if (this.missed("brace", open) || nest >= NEST_MAX)
|
|
276
|
+
return -1;
|
|
277
|
+
const found = subs && [];
|
|
278
|
+
for (let i = open + 2;;) {
|
|
279
|
+
this.reads++;
|
|
280
|
+
const c = this.at(i);
|
|
281
|
+
if (c === RB) {
|
|
282
|
+
if (found)
|
|
283
|
+
subs.push(...found);
|
|
284
|
+
return this.closes(open, i + 1);
|
|
285
|
+
}
|
|
286
|
+
if (c === END || c === NL)
|
|
287
|
+
return this.fail("brace", open, i);
|
|
288
|
+
const end = this.quoted(i, nest + 1, found);
|
|
289
|
+
if (end > 0) {
|
|
290
|
+
i = end;
|
|
291
|
+
continue;
|
|
292
|
+
}
|
|
293
|
+
i += c === BS ? 2 : 1;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
/** `$((…))` from its `$`: to the `))` that brings its parentheses back to none. Only parentheses are counted:
|
|
297
|
+
* arithmetic holds no quote or substitution worth pairing, and a search that reads nothing nested fails once. */
|
|
298
|
+
arith(open) {
|
|
299
|
+
if (this.missed("arith", open))
|
|
300
|
+
return -1;
|
|
301
|
+
let depth = 0;
|
|
302
|
+
for (let i = open + 1;; i++) {
|
|
303
|
+
this.reads++;
|
|
304
|
+
const c = this.at(i);
|
|
305
|
+
if (c === END || c === NL)
|
|
306
|
+
return this.fail("arith", open, i);
|
|
307
|
+
if (c === LP)
|
|
308
|
+
depth++;
|
|
309
|
+
else if (c === RP && --depth === 0)
|
|
310
|
+
return this.at(i - 1) === RP ? i + 1 : this.fail("arith", open, i);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
groupFailed(result, at) {
|
|
314
|
+
this.groupFail = at;
|
|
315
|
+
return result;
|
|
316
|
+
}
|
|
317
|
+
/** A quote or expansion at `i` read whole: the index past it, or 0 when there is none there. `subs` gets the
|
|
318
|
+
* substitution bodies in it. */
|
|
319
|
+
quoted(i, nest, subs) {
|
|
320
|
+
const c = this.at(i);
|
|
321
|
+
if (c === SQ)
|
|
322
|
+
return Math.max(this.single(i), 0);
|
|
323
|
+
if (c === DQ)
|
|
324
|
+
return Math.max(this.double(i, i, nest, [], subs), 0);
|
|
325
|
+
if (c === DOLLAR || c === BT) {
|
|
326
|
+
const end = this.expansion(i, nest, true, subs)?.end ?? 0;
|
|
327
|
+
this.groupFail = -1;
|
|
328
|
+
return end;
|
|
329
|
+
}
|
|
330
|
+
return 0;
|
|
331
|
+
}
|
|
332
|
+
/** A command list in parentheses (`$(`, `<(`, `>(`: `paren` is the `(`), read as tokens to the `)` that closes it:
|
|
333
|
+
* the index past it, or -1. */
|
|
334
|
+
group(open, paren, nest, kind) {
|
|
335
|
+
if (this.missed(kind, open) || nest >= NEST_MAX)
|
|
336
|
+
return -1;
|
|
337
|
+
let depth = 0;
|
|
338
|
+
let i = paren + 1;
|
|
339
|
+
while (true) {
|
|
340
|
+
const token = this.token(i, nest + 1);
|
|
341
|
+
if (this.groupFail >= 0)
|
|
342
|
+
return this.fail(kind, open, this.groupFail);
|
|
343
|
+
if (!token)
|
|
344
|
+
return this.groupFailed(this.fail(kind, open, Math.min(i, this.limit)), Math.min(i, this.limit));
|
|
345
|
+
if ("op" in token) {
|
|
346
|
+
if (token.op === "\n")
|
|
347
|
+
return this.groupFailed(this.fail(kind, open, token.start), token.start);
|
|
348
|
+
if (token.op === "(")
|
|
349
|
+
depth++;
|
|
350
|
+
else if (token.op === ")") {
|
|
351
|
+
if (depth === 0)
|
|
352
|
+
return this.closes(open, token.end);
|
|
353
|
+
depth--;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
i = token.end;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
/** The token at or after `i` (blanks skipped), or undefined at the limit. `subs` gets the substitutions of a word. */
|
|
360
|
+
token(i, nest, subs) {
|
|
361
|
+
let c = this.at(i);
|
|
362
|
+
// Blanks, and a backslash-newline between words (a continuation joins the lines and leaves no word).
|
|
363
|
+
while (true) {
|
|
364
|
+
if (c === SP || c === TAB || WIDE_BLANKS.has(c))
|
|
365
|
+
i++;
|
|
366
|
+
else if (c === BS && this.at(i + 1) === NL)
|
|
367
|
+
i += 2;
|
|
368
|
+
else if (c === BS && this.at(i + 1) === CR && this.at(i + 2) === NL)
|
|
369
|
+
i += 3;
|
|
370
|
+
else
|
|
371
|
+
break;
|
|
372
|
+
this.reads++;
|
|
373
|
+
c = this.at(i);
|
|
374
|
+
}
|
|
375
|
+
if (c === END)
|
|
376
|
+
return undefined;
|
|
377
|
+
this.reads++;
|
|
378
|
+
const d = this.at(i + 1);
|
|
379
|
+
if (c === NL)
|
|
380
|
+
return { op: "\n", start: i, end: i + 1 };
|
|
381
|
+
if (c === SEMI)
|
|
382
|
+
return { op: ";", start: i, end: i + 1 };
|
|
383
|
+
if (c === LP)
|
|
384
|
+
return { op: "(", start: i, end: i + 1 };
|
|
385
|
+
if (c === RP)
|
|
386
|
+
return { op: ")", start: i, end: i + 1 };
|
|
387
|
+
if (c === AMP) {
|
|
388
|
+
if (d === AMP)
|
|
389
|
+
return { op: "&&", start: i, end: i + 2 };
|
|
390
|
+
if (d === GT)
|
|
391
|
+
return this.redirection(i, i + 1);
|
|
392
|
+
return { op: "&", start: i, end: i + 1 };
|
|
393
|
+
}
|
|
394
|
+
if (c === PIPE) {
|
|
395
|
+
if (d === PIPE)
|
|
396
|
+
return { op: "||", start: i, end: i + 2 };
|
|
397
|
+
if (d === AMP)
|
|
398
|
+
return { op: "|&", start: i, end: i + 2 };
|
|
399
|
+
return { op: "|", start: i, end: i + 1 };
|
|
400
|
+
}
|
|
401
|
+
if ((c === LT || c === GT) && d !== LP)
|
|
402
|
+
return this.redirection(i, i);
|
|
403
|
+
return this.word(i, nest, subs);
|
|
404
|
+
}
|
|
405
|
+
/** A redirection from `start` (its `<`/`>` run at `from`): `>`, `>>`, `<<`, `<<<`, `<>`, `>|`, `&>`, `&>>`, with a
|
|
406
|
+
* `&` and a descriptor or `-` after (`2>&1`, `<&-`). Its target is the next word. */
|
|
407
|
+
redirection(start, from) {
|
|
408
|
+
let i = from;
|
|
409
|
+
while ((this.at(i) === LT || this.at(i) === GT) && i - from < 3)
|
|
410
|
+
i++;
|
|
411
|
+
if (this.at(i) === PIPE)
|
|
412
|
+
i++;
|
|
413
|
+
else if (this.at(i) === AMP && (this.at(i + 1) === MINUS || is(this.at(i + 1), DIGIT))) {
|
|
414
|
+
i += 2;
|
|
415
|
+
while (is(this.at(i), DIGIT))
|
|
416
|
+
i++;
|
|
417
|
+
}
|
|
418
|
+
this.reads += i - start;
|
|
419
|
+
return { op: "redir", start, end: i };
|
|
420
|
+
}
|
|
421
|
+
/** The word at `start`: to a blank, an operator, a line break or the limit. */
|
|
422
|
+
word(start, nest, subs) {
|
|
423
|
+
const parts = [];
|
|
424
|
+
let lit = -1;
|
|
425
|
+
let i = start;
|
|
426
|
+
while (i < this.limit) {
|
|
427
|
+
const c = this.text.charCodeAt(i);
|
|
428
|
+
if (c < 128 ? (CLASS[c] & (BLANK | OPERATOR)) !== 0 && !((c === LT || c === GT) && this.at(i + 1) === LP) : WIDE_BLANKS.has(c))
|
|
429
|
+
break;
|
|
430
|
+
this.reads++;
|
|
431
|
+
let part;
|
|
432
|
+
if (c === BS) {
|
|
433
|
+
// A backslash escapes the next character; before a line break it joins the lines.
|
|
434
|
+
if (lit < 0)
|
|
435
|
+
lit = i;
|
|
436
|
+
const e = this.at(i + 1);
|
|
437
|
+
i += e === END ? 1 : e === CR && this.at(i + 2) === NL ? 3 : 2;
|
|
438
|
+
continue;
|
|
439
|
+
}
|
|
440
|
+
if (c === SQ) {
|
|
441
|
+
const end = this.single(i);
|
|
442
|
+
if (end > 0)
|
|
443
|
+
part = { kind: "sq", start: i, end };
|
|
444
|
+
}
|
|
445
|
+
else if (c === DQ) {
|
|
446
|
+
const inner = [];
|
|
447
|
+
const end = this.double(i, i, nest, inner, subs);
|
|
448
|
+
if (end > 0)
|
|
449
|
+
part = { kind: "dq", start: i, end, inner };
|
|
450
|
+
}
|
|
451
|
+
else if (c === DOLLAR || c === BT) {
|
|
452
|
+
part = this.expansion(i, nest, true, subs);
|
|
453
|
+
}
|
|
454
|
+
else if (c === LT || c === GT) {
|
|
455
|
+
const end = this.group(i, i + 1, nest, "proc");
|
|
456
|
+
if (end > 0) {
|
|
457
|
+
part = { kind: "proc", start: i, end };
|
|
458
|
+
subs?.push([i + 2, end - 1]);
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
if (part) {
|
|
462
|
+
if (lit >= 0)
|
|
463
|
+
parts.push({ kind: "lit", start: lit, end: i });
|
|
464
|
+
lit = -1;
|
|
465
|
+
parts.push(part);
|
|
466
|
+
i = part.end;
|
|
467
|
+
}
|
|
468
|
+
else {
|
|
469
|
+
// A construct that did not close is a character, its whole opener (`$(`, `$((`, `<(`) one run with it.
|
|
470
|
+
if (lit < 0)
|
|
471
|
+
lit = i;
|
|
472
|
+
i += this.at(i + 1) !== LP || (c !== DOLLAR && c !== LT && c !== GT) ? 1 : this.at(i + 2) === LP && c === DOLLAR ? 3 : 2;
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
if (lit >= 0 && i > lit)
|
|
476
|
+
parts.push({ kind: "lit", start: lit, end: i });
|
|
477
|
+
return { start, end: i, parts };
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
/** The tokens of the command reading from `from`, to the first operator `ends` accepts, a line break, or `limit`.
|
|
481
|
+
* A bare run the limit cuts is read on to its end, so a long value is whole. */
|
|
482
|
+
export function lex(text, from, limit, ends, misses = new Map()) {
|
|
483
|
+
const reader = new Reader(text, Math.min(limit, text.length), misses);
|
|
484
|
+
const read = tokensOf(reader, text, from, ends);
|
|
485
|
+
lexCount.read += reader.reads;
|
|
486
|
+
return { ...read, reads: reader.reads };
|
|
487
|
+
}
|
|
488
|
+
function tokensOf(reader, text, from, ends) {
|
|
489
|
+
const tokens = [];
|
|
490
|
+
const subs = [];
|
|
491
|
+
let at = from;
|
|
492
|
+
while (true) {
|
|
493
|
+
const token = reader.token(at, 0, subs);
|
|
494
|
+
reader.groupFail = -1;
|
|
495
|
+
if (!token)
|
|
496
|
+
break;
|
|
497
|
+
if ("op" in token && (token.op === "\n" || ends(token.op)))
|
|
498
|
+
return { tokens, end: token.start, subs };
|
|
499
|
+
tokens.push(token);
|
|
500
|
+
at = token.end;
|
|
501
|
+
}
|
|
502
|
+
const last = tokens[tokens.length - 1];
|
|
503
|
+
if (last && "parts" in last && last.end === reader.limit && reader.limit < text.length) {
|
|
504
|
+
let end = last.end;
|
|
505
|
+
for (; end < text.length; end++) {
|
|
506
|
+
const c = text.charCodeAt(end);
|
|
507
|
+
if (c < 128 ? (CLASS[c] & RUN_STOP) !== 0 : WIDE_BLANKS.has(c))
|
|
508
|
+
break;
|
|
509
|
+
reader.reads++;
|
|
510
|
+
}
|
|
511
|
+
if (end > last.end) {
|
|
512
|
+
tokens[tokens.length - 1] = { start: last.start, end, parts: [...last.parts, { kind: "lit", start: last.end, end }] };
|
|
513
|
+
return { tokens, end, subs };
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
return { tokens, end: Math.max(at, Math.min(reader.limit, text.length)), subs };
|
|
517
|
+
}
|
|
518
|
+
/** A word written as one plain run with no backslash: its text is its value. */
|
|
519
|
+
function plain(text, word) {
|
|
520
|
+
const only = word.parts.length === 1 ? word.parts[0] : undefined;
|
|
521
|
+
if (only?.kind !== "lit")
|
|
522
|
+
return undefined;
|
|
523
|
+
const raw = text.slice(only.start, only.end);
|
|
524
|
+
return raw.includes("\\") ? undefined : raw;
|
|
525
|
+
}
|
|
526
|
+
/** A word's value (wordChars' `value`) without the places: a single-quoted part or an expansion is its text, a part
|
|
527
|
+
* with escapes is read by wordChars. */
|
|
528
|
+
export function wordText(text, word) {
|
|
529
|
+
let value = "";
|
|
530
|
+
for (const part of word.parts) {
|
|
531
|
+
if (part.kind === "sq")
|
|
532
|
+
value += text.slice(part.start + 1, part.end - 1);
|
|
533
|
+
else if (part.kind === "dq" || part.kind === "ansi")
|
|
534
|
+
return wordChars(text, word).value;
|
|
535
|
+
else {
|
|
536
|
+
const raw = text.slice(part.start, part.end);
|
|
537
|
+
if (part.kind === "lit" && raw.includes("\\"))
|
|
538
|
+
return wordChars(text, word).value;
|
|
539
|
+
value += raw;
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
return value;
|
|
543
|
+
}
|
|
544
|
+
/** Where a word's value from its `skip`th character on is written (the first one's start and kind, the last one's
|
|
545
|
+
* end) and how long the whole value is, or undefined when it has no character there. */
|
|
546
|
+
export function wordFrom(text, word, skip) {
|
|
547
|
+
const raw = plain(text, word);
|
|
548
|
+
if (raw !== undefined)
|
|
549
|
+
return skip < raw.length ? { start: word.start + skip, end: word.end, kind: "lit", length: raw.length } : undefined;
|
|
550
|
+
const chars = wordChars(text, word);
|
|
551
|
+
return skip < chars.value.length ? { start: chars.start[skip], end: chars.end[chars.end.length - 1], kind: chars.kind[skip], length: chars.value.length } : undefined;
|
|
552
|
+
}
|
|
553
|
+
const ANSI = { a: "\x07", b: "\b", e: "\x1b", E: "\x1b", f: "\f", n: "\n", r: "\r", t: "\t", v: "\v", "\\": "\\", "'": "'", '"': '"', "?": "?" };
|
|
554
|
+
export function wordChars(text, word) {
|
|
555
|
+
let value = "";
|
|
556
|
+
const start = [];
|
|
557
|
+
const end = [];
|
|
558
|
+
const kind = [];
|
|
559
|
+
const put = (ch, from, to, k) => {
|
|
560
|
+
value += ch;
|
|
561
|
+
start.push(from);
|
|
562
|
+
end.push(to);
|
|
563
|
+
kind.push(k);
|
|
564
|
+
};
|
|
565
|
+
const raw = (from, to, k) => {
|
|
566
|
+
for (let i = from; i < to; i++)
|
|
567
|
+
put(text.charAt(i), i, i + 1, k);
|
|
568
|
+
};
|
|
569
|
+
for (const part of word.parts) {
|
|
570
|
+
const { start: s, end: e } = part;
|
|
571
|
+
if (part.kind === "lit") {
|
|
572
|
+
for (let i = s; i < e; i++) {
|
|
573
|
+
const c = text.charAt(i);
|
|
574
|
+
if (c !== "\\" || i + 1 >= e) {
|
|
575
|
+
put(c, i, i + 1, "lit");
|
|
576
|
+
continue;
|
|
577
|
+
}
|
|
578
|
+
const d = text.charAt(i + 1);
|
|
579
|
+
if (d === "\n")
|
|
580
|
+
i++;
|
|
581
|
+
else if (d === "\r" && text.charAt(i + 2) === "\n")
|
|
582
|
+
i += 2;
|
|
583
|
+
else {
|
|
584
|
+
put(d, i, i + 2, "lit");
|
|
585
|
+
i++;
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
else if (part.kind === "sq")
|
|
590
|
+
raw(s + 1, e - 1, "sq");
|
|
591
|
+
else if (part.kind === "dq") {
|
|
592
|
+
const open = text.charAt(s) === "$" ? s + 2 : s + 1;
|
|
593
|
+
const inner = part.inner ?? [];
|
|
594
|
+
let next = 0;
|
|
595
|
+
for (let i = open; i < e - 1; i++) {
|
|
596
|
+
const sub = inner[next];
|
|
597
|
+
if (sub && sub.start === i) {
|
|
598
|
+
raw(sub.start, sub.end, sub.kind);
|
|
599
|
+
i = sub.end - 1;
|
|
600
|
+
next++;
|
|
601
|
+
continue;
|
|
602
|
+
}
|
|
603
|
+
const c = text.charAt(i);
|
|
604
|
+
const d = text.charAt(i + 1);
|
|
605
|
+
if (c === "\\" && (d === "$" || d === "\x60" || d === '"' || d === "\\")) {
|
|
606
|
+
put(d, i, i + 2, "dq");
|
|
607
|
+
i++;
|
|
608
|
+
}
|
|
609
|
+
else if (c === "\\" && d === "\n")
|
|
610
|
+
i++;
|
|
611
|
+
else
|
|
612
|
+
put(c, i, i + 1, "dq");
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
else if (part.kind === "ansi") {
|
|
616
|
+
for (let i = s + 2; i < e - 1; i++) {
|
|
617
|
+
const c = text.charAt(i);
|
|
618
|
+
if (c !== "\\") {
|
|
619
|
+
put(c, i, i + 1, "ansi");
|
|
620
|
+
continue;
|
|
621
|
+
}
|
|
622
|
+
const d = text.charAt(i + 1);
|
|
623
|
+
const hex = d === "x" ? HEX_ESCAPE.exec(text.slice(i + 2, Math.min(i + 4, e - 1))) : null;
|
|
624
|
+
const octal = OCTAL_DIGIT.test(d) ? OCTAL_ESCAPE.exec(text.slice(i + 1, Math.min(i + 4, e - 1))) : null;
|
|
625
|
+
if (hex) {
|
|
626
|
+
put(String.fromCharCode(parseInt(hex[0], 16)), i, i + 2 + hex[0].length, "ansi");
|
|
627
|
+
i += 1 + hex[0].length;
|
|
628
|
+
}
|
|
629
|
+
else if (octal) {
|
|
630
|
+
put(String.fromCharCode(parseInt(octal[0], 8) & 0xff), i, i + 1 + octal[0].length, "ansi");
|
|
631
|
+
i += octal[0].length;
|
|
632
|
+
}
|
|
633
|
+
else if (d in ANSI) {
|
|
634
|
+
put(ANSI[d], i, i + 2, "ansi");
|
|
635
|
+
i++;
|
|
636
|
+
}
|
|
637
|
+
else {
|
|
638
|
+
put(c, i, i + 1, "ansi");
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
else
|
|
643
|
+
raw(s, e, part.kind);
|
|
644
|
+
}
|
|
645
|
+
return { value, start, end, kind };
|
|
646
|
+
}
|
package/dist/sign-ins-store.d.ts
CHANGED
|
@@ -118,12 +118,10 @@ export declare function forgetSignIn(store: SignInsStore, sealKey: Buffer, vendo
|
|
|
118
118
|
* before it serves a run's output. Exposes store.signIns.handedHolder. */
|
|
119
119
|
export declare function handedTo(store: SignInsStore, hash: string): Promise<string | undefined>;
|
|
120
120
|
export { SignInHandedTo, SignInMissing };
|
|
121
|
-
/**
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
export declare const
|
|
125
|
-
/** A browser the server keeps a sign-in for; a local Chrome keeps none. */
|
|
126
|
-
export type Vendor = "browserbase" | "kernel";
|
|
121
|
+
/** A browser the server keeps a sign-in for: a provider whose descriptor declares profiles. A local Chrome keeps none. */
|
|
122
|
+
export type Vendor = string;
|
|
123
|
+
/** Every vendor a sign-in is kept at, for a walk over an agent's tombstones: each provider that declares profiles. */
|
|
124
|
+
export declare const SIGN_IN_VENDORS: readonly Vendor[];
|
|
127
125
|
/** A saved sign-in as GET /agents/{id} shows it (the v2 SignIn), never its pointer: its key, provider, state, holder and
|
|
128
126
|
* verified_at, and its one secret's metadata under `secret` (sign-ins-secrets.ts signInSecretMeta). */
|
|
129
127
|
export type SignInView = {
|
|
@@ -134,7 +132,7 @@ export type SignInView = {
|
|
|
134
132
|
verified_at: string | null;
|
|
135
133
|
secret: SecretMeta;
|
|
136
134
|
};
|
|
137
|
-
/** The vendor a run's browser resolves to keeps a sign-in
|
|
135
|
+
/** The vendor a run's browser resolves to, where it keeps a sign-in (SIGN_IN_VENDORS); a local Chrome is refused by
|
|
138
136
|
* name; an unavailable browser has none. */
|
|
139
137
|
export declare function vendorOf(resolution: string): Vendor | undefined;
|
|
140
138
|
/** The agent's sign-ins as the v2 API shows them, never a pointer. Per sign-in: `held`/`held_by`
|