@namzu/sdk 70.0.0 → 71.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +117 -0
- package/dist/authorization/bare-repository.d.ts +21 -0
- package/dist/authorization/bare-repository.d.ts.map +1 -0
- package/dist/authorization/bare-repository.js +62 -0
- package/dist/authorization/bare-repository.js.map +1 -0
- package/dist/authorization/command-line.d.ts.map +1 -1
- package/dist/authorization/command-line.js +10 -3
- package/dist/authorization/command-line.js.map +1 -1
- package/dist/authorization/gate.d.ts +7 -0
- package/dist/authorization/gate.d.ts.map +1 -1
- package/dist/authorization/gate.js +4 -0
- package/dist/authorization/gate.js.map +1 -1
- package/dist/authorization/protected-paths.d.ts.map +1 -1
- package/dist/authorization/protected-paths.js +46 -1
- package/dist/authorization/protected-paths.js.map +1 -1
- package/dist/authorization/readonly-commands.d.ts +17 -5
- package/dist/authorization/readonly-commands.d.ts.map +1 -1
- package/dist/authorization/readonly-commands.js +77 -6
- package/dist/authorization/readonly-commands.js.map +1 -1
- package/dist/authorization/readonly-flags.d.ts.map +1 -1
- package/dist/authorization/readonly-flags.js +98 -0
- package/dist/authorization/readonly-flags.js.map +1 -1
- package/dist/authorization/shell-lexer.d.ts +15 -0
- package/dist/authorization/shell-lexer.d.ts.map +1 -1
- package/dist/authorization/shell-lexer.js +108 -3
- package/dist/authorization/shell-lexer.js.map +1 -1
- package/dist/authorization/shell-paths.d.ts.map +1 -1
- package/dist/authorization/shell-paths.js +276 -0
- package/dist/authorization/shell-paths.js.map +1 -1
- package/dist/authorization/shell-session-state.d.ts +47 -0
- package/dist/authorization/shell-session-state.d.ts.map +1 -0
- package/dist/authorization/shell-session-state.js +70 -0
- package/dist/authorization/shell-session-state.js.map +1 -0
- package/dist/authorization/shell-session.d.ts +9 -0
- package/dist/authorization/shell-session.d.ts.map +1 -0
- package/dist/authorization/shell-session.js +19 -0
- package/dist/authorization/shell-session.js.map +1 -0
- package/dist/authorization/skill-grant.d.ts.map +1 -1
- package/dist/authorization/skill-grant.js +1 -0
- package/dist/authorization/skill-grant.js.map +1 -1
- package/dist/compaction/extractor.d.ts.map +1 -1
- package/dist/compaction/extractor.js +2 -0
- package/dist/compaction/extractor.js.map +1 -1
- package/dist/compaction/hooks.d.ts +16 -0
- package/dist/compaction/hooks.d.ts.map +1 -1
- package/dist/compaction/hooks.js +26 -1
- package/dist/compaction/hooks.js.map +1 -1
- package/dist/compaction/manual.d.ts.map +1 -1
- package/dist/compaction/manual.js +6 -1
- package/dist/compaction/manual.js.map +1 -1
- package/dist/compaction/restore.d.ts.map +1 -1
- package/dist/compaction/restore.js +3 -2
- package/dist/compaction/restore.js.map +1 -1
- package/dist/config/runtime.d.ts +2 -0
- package/dist/config/runtime.d.ts.map +1 -1
- package/dist/config/runtime.js +7 -0
- package/dist/config/runtime.js.map +1 -1
- package/dist/connector/mcp/client.d.ts +7 -0
- package/dist/connector/mcp/client.d.ts.map +1 -1
- package/dist/connector/mcp/client.js +54 -4
- package/dist/connector/mcp/client.js.map +1 -1
- package/dist/connector/web/types.d.ts +8 -0
- package/dist/connector/web/types.d.ts.map +1 -1
- package/dist/constants/compaction/index.d.ts.map +1 -1
- package/dist/constants/compaction/index.js +1 -1
- package/dist/constants/compaction/index.js.map +1 -1
- package/dist/execution/code-runtime/worker-program.d.ts +1 -1
- package/dist/execution/code-runtime/worker-program.d.ts.map +1 -1
- package/dist/execution/code-runtime/worker-program.js +9 -5
- package/dist/execution/code-runtime/worker-program.js.map +1 -1
- package/dist/execution/local.d.ts.map +1 -1
- package/dist/execution/local.js +6 -1
- package/dist/execution/local.js.map +1 -1
- package/dist/peers/index.d.ts +2 -2
- package/dist/peers/index.d.ts.map +1 -1
- package/dist/peers/index.js +1 -1
- package/dist/peers/index.js.map +1 -1
- package/dist/peers/record.d.ts +74 -0
- package/dist/peers/record.d.ts.map +1 -1
- package/dist/peers/record.js +41 -1
- package/dist/peers/record.js.map +1 -1
- package/dist/peers/registry.d.ts.map +1 -1
- package/dist/peers/registry.js +20 -3
- package/dist/peers/registry.js.map +1 -1
- package/dist/plugin/bin-path.d.ts +41 -0
- package/dist/plugin/bin-path.d.ts.map +1 -0
- package/dist/plugin/bin-path.js +146 -0
- package/dist/plugin/bin-path.js.map +1 -0
- package/dist/plugin/common-layout/read.js +1 -1
- package/dist/plugin/common-layout/read.js.map +1 -1
- package/dist/plugin/common-layout-names.d.ts.map +1 -1
- package/dist/plugin/common-layout-names.js +0 -1
- package/dist/plugin/common-layout-names.js.map +1 -1
- package/dist/plugin/hook-module/scan.d.ts +16 -0
- package/dist/plugin/hook-module/scan.d.ts.map +1 -1
- package/dist/plugin/hook-module/scan.js +67 -2
- package/dist/plugin/hook-module/scan.js.map +1 -1
- package/dist/plugin/hook-module/worker-source.d.ts.map +1 -1
- package/dist/plugin/hook-module/worker-source.js +56 -0
- package/dist/plugin/hook-module/worker-source.js.map +1 -1
- package/dist/plugin/lifecycle.d.ts +21 -0
- package/dist/plugin/lifecycle.d.ts.map +1 -1
- package/dist/plugin/lifecycle.js +64 -0
- package/dist/plugin/lifecycle.js.map +1 -1
- package/dist/plugin/shell-hook-tool-names.d.ts.map +1 -1
- package/dist/plugin/shell-hook-tool-names.js +1 -0
- package/dist/plugin/shell-hook-tool-names.js.map +1 -1
- package/dist/plugin/shell-hook.d.ts +1 -1
- package/dist/plugin/shell-hook.d.ts.map +1 -1
- package/dist/plugin/shell-hook.js +22 -4
- package/dist/plugin/shell-hook.js.map +1 -1
- package/dist/public-runtime.d.ts +8 -6
- package/dist/public-runtime.d.ts.map +1 -1
- package/dist/public-runtime.js +8 -5
- package/dist/public-runtime.js.map +1 -1
- package/dist/public-tools.d.ts +6 -2
- package/dist/public-tools.d.ts.map +1 -1
- package/dist/public-tools.js +6 -2
- package/dist/public-tools.js.map +1 -1
- package/dist/public-types.d.ts +2 -2
- package/dist/public-types.d.ts.map +1 -1
- package/dist/runtime/jobs/monitor-stream.d.ts +9 -1
- package/dist/runtime/jobs/monitor-stream.d.ts.map +1 -1
- package/dist/runtime/jobs/monitor-stream.js +13 -4
- package/dist/runtime/jobs/monitor-stream.js.map +1 -1
- package/dist/runtime/jobs/registry.d.ts +4 -0
- package/dist/runtime/jobs/registry.d.ts.map +1 -1
- package/dist/runtime/jobs/registry.js +12 -2
- package/dist/runtime/jobs/registry.js.map +1 -1
- package/dist/runtime/query/auto-review/git-status.d.ts.map +1 -1
- package/dist/runtime/query/auto-review/git-status.js +3 -2
- package/dist/runtime/query/auto-review/git-status.js.map +1 -1
- package/dist/runtime/query/executor.d.ts +16 -6
- package/dist/runtime/query/executor.d.ts.map +1 -1
- package/dist/runtime/query/executor.js +60 -5
- package/dist/runtime/query/executor.js.map +1 -1
- package/dist/runtime/query/index.d.ts.map +1 -1
- package/dist/runtime/query/index.js +2 -2
- package/dist/runtime/query/index.js.map +1 -1
- package/dist/runtime/query/iteration/outstanding-work.d.ts.map +1 -1
- package/dist/runtime/query/iteration/outstanding-work.js +14 -4
- package/dist/runtime/query/iteration/outstanding-work.js.map +1 -1
- package/dist/runtime/query/iteration/phases/compaction.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/compaction.js +11 -1
- package/dist/runtime/query/iteration/phases/compaction.js.map +1 -1
- package/dist/runtime/query/iteration/phases/tool-review.d.ts +2 -0
- package/dist/runtime/query/iteration/phases/tool-review.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/tool-review.js +19 -8
- package/dist/runtime/query/iteration/phases/tool-review.js.map +1 -1
- package/dist/runtime/query/path-escalation.d.ts +6 -0
- package/dist/runtime/query/path-escalation.d.ts.map +1 -1
- package/dist/runtime/query/path-escalation.js +58 -4
- package/dist/runtime/query/path-escalation.js.map +1 -1
- package/dist/runtime/query/review-policy.d.ts.map +1 -1
- package/dist/runtime/query/review-policy.js +4 -2
- package/dist/runtime/query/review-policy.js.map +1 -1
- package/dist/runtime/query/steering.d.ts +11 -2
- package/dist/runtime/query/steering.d.ts.map +1 -1
- package/dist/runtime/query/steering.js +18 -4
- package/dist/runtime/query/steering.js.map +1 -1
- package/dist/sandbox/provider/local.d.ts.map +1 -1
- package/dist/sandbox/provider/local.js +3 -1
- package/dist/sandbox/provider/local.js.map +1 -1
- package/dist/schedules/describe.d.ts.map +1 -1
- package/dist/schedules/describe.js +2 -0
- package/dist/schedules/describe.js.map +1 -1
- package/dist/schedules/evaluate.d.ts +4 -0
- package/dist/schedules/evaluate.d.ts.map +1 -1
- package/dist/schedules/evaluate.js +26 -1
- package/dist/schedules/evaluate.js.map +1 -1
- package/dist/schedules/index.d.ts +3 -1
- package/dist/schedules/index.d.ts.map +1 -1
- package/dist/schedules/index.js +2 -1
- package/dist/schedules/index.js.map +1 -1
- package/dist/schedules/next-fire.d.ts.map +1 -1
- package/dist/schedules/next-fire.js +10 -0
- package/dist/schedules/next-fire.js.map +1 -1
- package/dist/schedules/spec.d.ts +9 -0
- package/dist/schedules/spec.d.ts.map +1 -1
- package/dist/schedules/spec.js +33 -0
- package/dist/schedules/spec.js.map +1 -1
- package/dist/schedules/types.d.ts +32 -4
- package/dist/schedules/types.d.ts.map +1 -1
- package/dist/schedules/types.js +3 -2
- package/dist/schedules/types.js.map +1 -1
- package/dist/schedules/watch.d.ts +23 -0
- package/dist/schedules/watch.d.ts.map +1 -0
- package/dist/schedules/watch.js +46 -0
- package/dist/schedules/watch.js.map +1 -0
- package/dist/session/workspace/git-worktree.d.ts.map +1 -1
- package/dist/session/workspace/git-worktree.js +2 -1
- package/dist/session/workspace/git-worktree.js.map +1 -1
- package/dist/skills/arguments.d.ts +58 -0
- package/dist/skills/arguments.d.ts.map +1 -0
- package/dist/skills/arguments.js +208 -0
- package/dist/skills/arguments.js.map +1 -0
- package/dist/skills/index.d.ts +3 -1
- package/dist/skills/index.d.ts.map +1 -1
- package/dist/skills/index.js +1 -0
- package/dist/skills/index.js.map +1 -1
- package/dist/skills/inline-shell.d.ts +17 -0
- package/dist/skills/inline-shell.d.ts.map +1 -1
- package/dist/skills/inline-shell.js +1232 -14
- package/dist/skills/inline-shell.js.map +1 -1
- package/dist/tools/builtins/bash-cwd.d.ts.map +1 -1
- package/dist/tools/builtins/bash-cwd.js +2 -0
- package/dist/tools/builtins/bash-cwd.js.map +1 -1
- package/dist/tools/builtins/bash.d.ts.map +1 -1
- package/dist/tools/builtins/bash.js +79 -11
- package/dist/tools/builtins/bash.js.map +1 -1
- package/dist/tools/builtins/exit-semantics.d.ts +6 -0
- package/dist/tools/builtins/exit-semantics.d.ts.map +1 -1
- package/dist/tools/builtins/exit-semantics.js +10 -0
- package/dist/tools/builtins/exit-semantics.js.map +1 -1
- package/dist/tools/builtins/glob.d.ts.map +1 -1
- package/dist/tools/builtins/glob.js +68 -13
- package/dist/tools/builtins/glob.js.map +1 -1
- package/dist/tools/builtins/grep.d.ts.map +1 -1
- package/dist/tools/builtins/grep.js +37 -12
- package/dist/tools/builtins/grep.js.map +1 -1
- package/dist/tools/builtins/index.d.ts +11 -0
- package/dist/tools/builtins/index.d.ts.map +1 -1
- package/dist/tools/builtins/index.js +14 -0
- package/dist/tools/builtins/index.js.map +1 -1
- package/dist/tools/builtins/job.js +1 -1
- package/dist/tools/builtins/job.js.map +1 -1
- package/dist/tools/builtins/monitor.d.ts +1 -1
- package/dist/tools/builtins/monitor.d.ts.map +1 -1
- package/dist/tools/builtins/monitor.js +4 -2
- package/dist/tools/builtins/monitor.js.map +1 -1
- package/dist/tools/builtins/notebook-cells.d.ts +31 -0
- package/dist/tools/builtins/notebook-cells.d.ts.map +1 -0
- package/dist/tools/builtins/notebook-cells.js +160 -0
- package/dist/tools/builtins/notebook-cells.js.map +1 -0
- package/dist/tools/builtins/notebook-edit.d.ts +8 -0
- package/dist/tools/builtins/notebook-edit.d.ts.map +1 -0
- package/dist/tools/builtins/notebook-edit.js +249 -0
- package/dist/tools/builtins/notebook-edit.js.map +1 -0
- package/dist/tools/builtins/notebook-guard.d.ts.map +1 -1
- package/dist/tools/builtins/notebook-guard.js +2 -1
- package/dist/tools/builtins/notebook-guard.js.map +1 -1
- package/dist/tools/builtins/push-notification.d.ts +49 -0
- package/dist/tools/builtins/push-notification.d.ts.map +1 -0
- package/dist/tools/builtins/push-notification.js +107 -0
- package/dist/tools/builtins/push-notification.js.map +1 -0
- package/dist/tools/builtins/read-file.d.ts.map +1 -1
- package/dist/tools/builtins/read-file.js +8 -3
- package/dist/tools/builtins/read-file.js.map +1 -1
- package/dist/tools/builtins/read-media.d.ts.map +1 -1
- package/dist/tools/builtins/read-media.js +2 -1
- package/dist/tools/builtins/read-media.js.map +1 -1
- package/dist/tools/builtins/read-render.d.ts.map +1 -1
- package/dist/tools/builtins/read-render.js +5 -3
- package/dist/tools/builtins/read-render.js.map +1 -1
- package/dist/tools/builtins/search-support.d.ts +6 -4
- package/dist/tools/builtins/search-support.d.ts.map +1 -1
- package/dist/tools/builtins/search-support.js +15 -3
- package/dist/tools/builtins/search-support.js.map +1 -1
- package/dist/tools/builtins/skill.d.ts.map +1 -1
- package/dist/tools/builtins/skill.js +28 -8
- package/dist/tools/builtins/skill.js.map +1 -1
- package/dist/tools/builtins/sleep-guard.d.ts +20 -0
- package/dist/tools/builtins/sleep-guard.d.ts.map +1 -1
- package/dist/tools/builtins/sleep-guard.js +125 -1
- package/dist/tools/builtins/sleep-guard.js.map +1 -1
- package/dist/tools/builtins/wait-for-job.js +1 -1
- package/dist/tools/builtins/wait-for-job.js.map +1 -1
- package/dist/tools/builtins/web.d.ts +2 -0
- package/dist/tools/builtins/web.d.ts.map +1 -1
- package/dist/tools/builtins/web.js +97 -3
- package/dist/tools/builtins/web.js.map +1 -1
- package/dist/tools/command-shell.d.ts +50 -0
- package/dist/tools/command-shell.d.ts.map +1 -1
- package/dist/tools/command-shell.js +145 -0
- package/dist/tools/command-shell.js.map +1 -1
- package/dist/tools/env-scrub.d.ts +2 -0
- package/dist/tools/env-scrub.d.ts.map +1 -1
- package/dist/tools/env-scrub.js +15 -1
- package/dist/tools/env-scrub.js.map +1 -1
- package/dist/tools/git-config-env.d.ts +55 -0
- package/dist/tools/git-config-env.d.ts.map +1 -0
- package/dist/tools/git-config-env.js +130 -0
- package/dist/tools/git-config-env.js.map +1 -0
- package/dist/tools/schedules/schedule-tool.d.ts +7 -0
- package/dist/tools/schedules/schedule-tool.d.ts.map +1 -1
- package/dist/tools/schedules/schedule-tool.js +72 -3
- package/dist/tools/schedules/schedule-tool.js.map +1 -1
- package/dist/tools/schedules/types.d.ts +38 -2
- package/dist/tools/schedules/types.d.ts.map +1 -1
- package/dist/types/connector/mcp.d.ts +24 -0
- package/dist/types/connector/mcp.d.ts.map +1 -1
- package/dist/types/message/index.d.ts +21 -1
- package/dist/types/message/index.d.ts.map +1 -1
- package/dist/types/message/index.js +37 -2
- package/dist/types/message/index.js.map +1 -1
- package/dist/types/plugin/index.d.ts +10 -2
- package/dist/types/plugin/index.d.ts.map +1 -1
- package/dist/types/plugin/index.js.map +1 -1
- package/dist/types/tool/index.d.ts +6 -0
- package/dist/types/tool/index.d.ts.map +1 -1
- package/dist/types/tool/index.js.map +1 -1
- package/dist/utils/plain-terminal-text.d.ts +21 -0
- package/dist/utils/plain-terminal-text.d.ts.map +1 -0
- package/dist/utils/plain-terminal-text.js +156 -0
- package/dist/utils/plain-terminal-text.js.map +1 -0
- package/package.json +1 -1
- package/src/authorization/bare-repository.ts +70 -0
- package/src/authorization/command-line.ts +18 -4
- package/src/authorization/gate.ts +11 -0
- package/src/authorization/protected-paths.ts +45 -1
- package/src/authorization/readonly-commands.ts +75 -6
- package/src/authorization/readonly-flags.ts +103 -0
- package/src/authorization/shell-lexer.ts +126 -3
- package/src/authorization/shell-paths.ts +386 -0
- package/src/authorization/shell-session-state.ts +97 -0
- package/src/authorization/shell-session.ts +23 -0
- package/src/authorization/skill-grant.ts +1 -0
- package/src/compaction/extractor.ts +1 -0
- package/src/compaction/hooks.ts +43 -1
- package/src/compaction/manual.ts +6 -0
- package/src/compaction/restore.ts +3 -2
- package/src/config/runtime.ts +7 -0
- package/src/connector/mcp/client.ts +61 -4
- package/src/connector/web/types.ts +8 -0
- package/src/constants/compaction/index.ts +1 -1
- package/src/execution/code-runtime/worker-program.ts +9 -5
- package/src/execution/local.ts +6 -1
- package/src/peers/index.ts +8 -2
- package/src/peers/record.ts +45 -1
- package/src/peers/registry.ts +21 -5
- package/src/plugin/bin-path.ts +149 -0
- package/src/plugin/common-layout/read.ts +1 -1
- package/src/plugin/common-layout-names.ts +0 -1
- package/src/plugin/hook-module/scan.ts +74 -2
- package/src/plugin/hook-module/worker-source.ts +56 -0
- package/src/plugin/lifecycle.ts +67 -0
- package/src/plugin/shell-hook-tool-names.ts +1 -0
- package/src/plugin/shell-hook.ts +23 -4
- package/src/public-runtime.ts +21 -0
- package/src/public-tools.ts +32 -1
- package/src/public-types.ts +3 -1
- package/src/runtime/jobs/monitor-stream.ts +18 -4
- package/src/runtime/jobs/registry.ts +22 -2
- package/src/runtime/query/auto-review/git-status.ts +3 -2
- package/src/runtime/query/executor.ts +79 -5
- package/src/runtime/query/index.ts +5 -2
- package/src/runtime/query/iteration/outstanding-work.ts +22 -4
- package/src/runtime/query/iteration/phases/compaction.ts +14 -1
- package/src/runtime/query/iteration/phases/tool-review.ts +24 -7
- package/src/runtime/query/path-escalation.ts +52 -4
- package/src/runtime/query/review-policy.ts +5 -2
- package/src/runtime/query/steering.ts +32 -4
- package/src/sandbox/provider/local.ts +3 -1
- package/src/schedules/describe.ts +2 -0
- package/src/schedules/evaluate.ts +29 -1
- package/src/schedules/index.ts +9 -1
- package/src/schedules/next-fire.ts +9 -0
- package/src/schedules/spec.ts +42 -0
- package/src/schedules/types.ts +33 -3
- package/src/schedules/watch.ts +71 -0
- package/src/session/workspace/git-worktree.ts +3 -1
- package/src/skills/arguments.ts +250 -0
- package/src/skills/index.ts +10 -0
- package/src/skills/inline-shell.ts +1268 -14
- package/src/tools/builtins/bash-cwd.ts +2 -0
- package/src/tools/builtins/bash.ts +93 -13
- package/src/tools/builtins/exit-semantics.ts +10 -0
- package/src/tools/builtins/glob.ts +79 -15
- package/src/tools/builtins/grep.ts +37 -10
- package/src/tools/builtins/index.ts +15 -0
- package/src/tools/builtins/job.ts +1 -1
- package/src/tools/builtins/monitor.ts +4 -2
- package/src/tools/builtins/notebook-cells.ts +196 -0
- package/src/tools/builtins/notebook-edit.ts +280 -0
- package/src/tools/builtins/notebook-guard.ts +2 -1
- package/src/tools/builtins/push-notification.ts +138 -0
- package/src/tools/builtins/read-file.ts +9 -3
- package/src/tools/builtins/read-media.ts +2 -1
- package/src/tools/builtins/read-render.ts +5 -3
- package/src/tools/builtins/search-support.ts +17 -3
- package/src/tools/builtins/skill.ts +27 -7
- package/src/tools/builtins/sleep-guard.ts +128 -1
- package/src/tools/builtins/wait-for-job.ts +1 -1
- package/src/tools/builtins/web.ts +100 -3
- package/src/tools/command-shell.ts +166 -0
- package/src/tools/env-scrub.ts +13 -1
- package/src/tools/git-config-env.ts +143 -0
- package/src/tools/schedules/schedule-tool.ts +79 -3
- package/src/tools/schedules/types.ts +47 -9
- package/src/types/connector/mcp.ts +25 -0
- package/src/types/message/index.ts +53 -1
- package/src/types/plugin/index.ts +10 -2
- package/src/types/tool/index.ts +6 -0
- package/src/utils/plain-terminal-text.ts +142 -0
|
@@ -146,6 +146,15 @@ export interface ShellLexResult {
|
|
|
146
146
|
readonly complete: boolean
|
|
147
147
|
/** Why the line is opaque, for diagnostics. Empty when it is not. */
|
|
148
148
|
readonly reasons: readonly string[]
|
|
149
|
+
/**
|
|
150
|
+
* Names the line gives the integer (or name-reference) attribute to, with
|
|
151
|
+
* `declare`, `typeset` or `local`: a later value stored into one is
|
|
152
|
+
* evaluated as arithmetic. A host that keeps a shell session records them
|
|
153
|
+
* (see `shell-session.ts`).
|
|
154
|
+
*/
|
|
155
|
+
readonly integerNames: readonly string[]
|
|
156
|
+
/** The line gives the attribute to names it does not spell out, or may do so through `eval` or `source`. */
|
|
157
|
+
readonly integerNamesUnknown: boolean
|
|
149
158
|
}
|
|
150
159
|
|
|
151
160
|
/**
|
|
@@ -232,12 +241,18 @@ import {
|
|
|
232
241
|
shellInvocation,
|
|
233
242
|
unwrapReexecChain,
|
|
234
243
|
} from './reexec-wrapper.js'
|
|
244
|
+
import { type ShellAttributes, currentShellAttributes } from './shell-session-state.js'
|
|
235
245
|
|
|
236
246
|
export type { ShellDialect }
|
|
237
247
|
|
|
238
248
|
export interface ShellLexOptions {
|
|
239
249
|
/** Default `bash`. */
|
|
240
250
|
readonly dialect?: ShellDialect
|
|
251
|
+
/**
|
|
252
|
+
* What earlier lines of the same shell session gave the integer attribute
|
|
253
|
+
* to. Default: the session the caller runs in (`withShellSession`), if any.
|
|
254
|
+
*/
|
|
255
|
+
readonly attributes?: ShellAttributes
|
|
241
256
|
}
|
|
242
257
|
|
|
243
258
|
export function lexShellCommandLine(line: string, options: ShellLexOptions = {}): ShellLexResult {
|
|
@@ -251,9 +266,11 @@ export function lexShellCommandLine(line: string, options: ShellLexOptions = {})
|
|
|
251
266
|
opaque: true,
|
|
252
267
|
complete: false,
|
|
253
268
|
reasons: ['native CMD command parsing is unavailable'],
|
|
269
|
+
integerNames: [],
|
|
270
|
+
integerNamesUnknown: false,
|
|
254
271
|
}
|
|
255
272
|
}
|
|
256
|
-
const context = new Context(line.length)
|
|
273
|
+
const context = new Context(line.length, options.attributes ?? currentShellAttributes())
|
|
257
274
|
context.setDialect(line, options.dialect ?? 'bash')
|
|
258
275
|
try {
|
|
259
276
|
lexInto(line, context, 'line', 0)
|
|
@@ -270,6 +287,8 @@ export function lexShellCommandLine(line: string, options: ShellLexOptions = {})
|
|
|
270
287
|
opaque: context.reasons.size > 0,
|
|
271
288
|
complete: context.complete,
|
|
272
289
|
reasons: [...context.reasons],
|
|
290
|
+
integerNames: [...context.declaredNames],
|
|
291
|
+
integerNamesUnknown: context.declaredUnknown,
|
|
273
292
|
}
|
|
274
293
|
}
|
|
275
294
|
|
|
@@ -286,10 +305,29 @@ class Context {
|
|
|
286
305
|
*/
|
|
287
306
|
private rescans: number
|
|
288
307
|
|
|
289
|
-
constructor(
|
|
308
|
+
constructor(
|
|
309
|
+
length: number,
|
|
310
|
+
private readonly prior: ShellAttributes | undefined = undefined,
|
|
311
|
+
) {
|
|
290
312
|
this.rescans = 4 * length + 4096
|
|
291
313
|
}
|
|
292
314
|
|
|
315
|
+
/** Names this line gives the integer attribute to, and whether it may give it to more. */
|
|
316
|
+
readonly declaredNames = new Set<string>()
|
|
317
|
+
declaredUnknown = false
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* A value that may hold a subscript or an expansion is stored into `name`.
|
|
321
|
+
* If an earlier line of the session gave `name` the integer attribute, or
|
|
322
|
+
* may have given it to any name, bash evaluates the value as arithmetic.
|
|
323
|
+
* `undefined` is a name the lexer cannot read.
|
|
324
|
+
*/
|
|
325
|
+
storedInto(name: string | undefined): void {
|
|
326
|
+
if (this.prior === undefined) return
|
|
327
|
+
if (this.prior.unknown || name === undefined || this.prior.integers.has(name))
|
|
328
|
+
this.opaque('arithmetic')
|
|
329
|
+
}
|
|
330
|
+
|
|
293
331
|
opaque(reason: string): void {
|
|
294
332
|
this.reasons.add(reason)
|
|
295
333
|
}
|
|
@@ -484,6 +522,28 @@ function subscriptWithExpansion(word: ShellWord): boolean {
|
|
|
484
522
|
return word.value.includes('[') && (word.expands || /[$`]/.test(word.value))
|
|
485
523
|
}
|
|
486
524
|
|
|
525
|
+
/** The variable a `NAME`, `NAME[sub]` or `NAME+` operand stores into; undefined when it is not a plain name. */
|
|
526
|
+
function plainName(text: string): string | undefined {
|
|
527
|
+
const match = /^([A-Za-z_][A-Za-z0-9_]*)(?:\[.*\])?\+?$/s.exec(text)
|
|
528
|
+
return match === null ? undefined : (match[1] as string)
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
/**
|
|
532
|
+
* Text with a letter or underscore in it. Stored into an integer name, a bare
|
|
533
|
+
* word like that is read as a variable and its value evaluated again, so
|
|
534
|
+
* `x=y` runs what an earlier call stored in `y`.
|
|
535
|
+
*/
|
|
536
|
+
const NAMES_A_VARIABLE = /[A-Za-z_]/
|
|
537
|
+
|
|
538
|
+
/** `NAME=`, `NAME+=` or `NAME[sub]=` at the start of a word. */
|
|
539
|
+
const ASSIGNMENT_NAME = /^([A-Za-z_][A-Za-z0-9_]*)(?:\[[^\]]*\])?\+?=/
|
|
540
|
+
|
|
541
|
+
/** A parameter expansion that assigns: `${NAME:=word}`, `${NAME=word}`. */
|
|
542
|
+
const ASSIGNING_EXPANSION = /\$\{([A-Za-z_][A-Za-z0-9_]*)(?:\[[^\]]*\])?:?=/g
|
|
543
|
+
|
|
544
|
+
/** Text that hands a name the integer or name-reference attribute when read as a line. */
|
|
545
|
+
const DECLARES_INTEGER = /\b(?:declare|typeset|local)\b[^;&|\n]*\s-[A-Za-z]*[in]/
|
|
546
|
+
|
|
487
547
|
const PLAIN_INTEGER_ARGUMENT = /^[A-Za-z_][A-Za-z0-9_]*(?:=[0-9\s+\-*/%()<>=!&|^~?:,]*)?$/
|
|
488
548
|
|
|
489
549
|
const WORD_BREAK = new Set([' ', '\t', '\n', ';', '&', '|', '(', ')', '<', '>'])
|
|
@@ -947,6 +1007,7 @@ class Parser {
|
|
|
947
1007
|
this.context.compoundWords.push(name.word)
|
|
948
1008
|
// The loop variable takes whatever the list holds.
|
|
949
1009
|
this.context.bracketAssigned()
|
|
1010
|
+
let listHoldsBracket = false
|
|
950
1011
|
this.newlines()
|
|
951
1012
|
token = this.peek()
|
|
952
1013
|
if (token.kind === 'word' && !token.word.quoted && token.word.value === 'in') {
|
|
@@ -966,6 +1027,12 @@ class Parser {
|
|
|
966
1027
|
token = this.takePlainWord()
|
|
967
1028
|
if (token.kind === 'word') {
|
|
968
1029
|
this.context.compoundWords.push(token.word)
|
|
1030
|
+
if (
|
|
1031
|
+
token.word.value.includes('[') ||
|
|
1032
|
+
token.word.expands ||
|
|
1033
|
+
NAMES_A_VARIABLE.test(token.word.value)
|
|
1034
|
+
)
|
|
1035
|
+
listHoldsBracket = true
|
|
969
1036
|
continue
|
|
970
1037
|
}
|
|
971
1038
|
if (token.kind === 'newline' || (token.kind === 'op' && token.op === ';')) break
|
|
@@ -976,6 +1043,7 @@ class Parser {
|
|
|
976
1043
|
this.take()
|
|
977
1044
|
this.newlines()
|
|
978
1045
|
}
|
|
1046
|
+
if (listHoldsBracket) this.context.storedInto(plainName(name.word.value))
|
|
979
1047
|
this.loopBody()
|
|
980
1048
|
}
|
|
981
1049
|
|
|
@@ -1409,6 +1477,10 @@ class Parser {
|
|
|
1409
1477
|
*/
|
|
1410
1478
|
private inspectArithmeticBuiltin(command: ShellCommand): void {
|
|
1411
1479
|
for (let i = 0; i < command.assignments; i += 1) this.noteBracketAssignment(command.words[i])
|
|
1480
|
+
for (const word of command.words) {
|
|
1481
|
+
for (const match of word.value.matchAll(ASSIGNING_EXPANSION))
|
|
1482
|
+
this.context.storedInto(match[1])
|
|
1483
|
+
}
|
|
1412
1484
|
let at = command.assignments
|
|
1413
1485
|
for (;;) {
|
|
1414
1486
|
const word = command.words[at]
|
|
@@ -1418,6 +1490,17 @@ class Parser {
|
|
|
1418
1490
|
// later word, the line asks.
|
|
1419
1491
|
if (command.words.slice(at + 1).some(subscriptWithExpansion))
|
|
1420
1492
|
this.context.opaque('arithmetic')
|
|
1493
|
+
// A command name held in a variable may be `declare`: flags that
|
|
1494
|
+
// give the integer or name-reference attribute then name a name the
|
|
1495
|
+
// lexer cannot read.
|
|
1496
|
+
if (
|
|
1497
|
+
command.words
|
|
1498
|
+
.slice(at + 1)
|
|
1499
|
+
.some((arg) => !arg.expands && /^-[A-Za-z]*[in]/.test(arg.value))
|
|
1500
|
+
) {
|
|
1501
|
+
this.context.declaredUnknown = true
|
|
1502
|
+
this.context.declaredArithmetic()
|
|
1503
|
+
}
|
|
1421
1504
|
return
|
|
1422
1505
|
}
|
|
1423
1506
|
if ((word.value === 'builtin' || word.value === 'command') && command.words[at + 1]) {
|
|
@@ -1452,6 +1535,14 @@ class Parser {
|
|
|
1452
1535
|
// eval reads its words as a line again, where a name with a subscript
|
|
1453
1536
|
// and an expansion can reach `unset` or `declare -i`.
|
|
1454
1537
|
if (args.some(subscriptWithExpansion)) this.context.opaque('arithmetic')
|
|
1538
|
+
// What it runs may give the attribute to any name.
|
|
1539
|
+
if (args.some((word) => word.expands || DECLARES_INTEGER.test(word.value)))
|
|
1540
|
+
this.context.declaredUnknown = true
|
|
1541
|
+
return
|
|
1542
|
+
}
|
|
1543
|
+
if (name === 'source' || name === '.') {
|
|
1544
|
+
// A file read into the shell may declare anything.
|
|
1545
|
+
this.context.declaredUnknown = true
|
|
1455
1546
|
return
|
|
1456
1547
|
}
|
|
1457
1548
|
if (name === 'let') {
|
|
@@ -1468,12 +1559,15 @@ class Parser {
|
|
|
1468
1559
|
this.context.bracketAssigned()
|
|
1469
1560
|
const target = args[i + 1]
|
|
1470
1561
|
if (target !== undefined && subscriptOrExpands(target)) this.context.opaque('arithmetic')
|
|
1562
|
+
// The formatted text is stored: whatever its arguments hold.
|
|
1563
|
+
this.context.storedInto(target === undefined ? undefined : plainName(target.value))
|
|
1471
1564
|
i += 1
|
|
1472
1565
|
continue
|
|
1473
1566
|
}
|
|
1474
1567
|
if (value.startsWith('-v')) {
|
|
1475
1568
|
this.context.bracketAssigned()
|
|
1476
1569
|
if (subscriptOrExpands(args[i] as ShellWord)) this.context.opaque('arithmetic')
|
|
1570
|
+
this.context.storedInto(plainName(value.slice(2)))
|
|
1477
1571
|
}
|
|
1478
1572
|
}
|
|
1479
1573
|
return
|
|
@@ -1490,6 +1584,10 @@ class Parser {
|
|
|
1490
1584
|
if (name === 'mapfile' || name === 'readarray' || name === 'getopts') {
|
|
1491
1585
|
this.context.bracketAssigned()
|
|
1492
1586
|
if (args.some((word) => subscriptOrExpands(word))) this.context.opaque('arithmetic')
|
|
1587
|
+
// Input stores into the named array (default MAPFILE); getopts into its name.
|
|
1588
|
+
const operands = args.filter((word) => !word.value.startsWith('-'))
|
|
1589
|
+
if (name !== 'getopts' && operands.length === 0) this.context.storedInto('MAPFILE')
|
|
1590
|
+
for (const word of operands) this.context.storedInto(plainName(word.value))
|
|
1493
1591
|
return
|
|
1494
1592
|
}
|
|
1495
1593
|
if (name === 'test' || name === '[') {
|
|
@@ -1500,6 +1598,10 @@ class Parser {
|
|
|
1500
1598
|
}
|
|
1501
1599
|
return
|
|
1502
1600
|
}
|
|
1601
|
+
if (name === 'export' || name === 'readonly') {
|
|
1602
|
+
for (const word of args) this.noteBracketAssignment(word)
|
|
1603
|
+
return
|
|
1604
|
+
}
|
|
1503
1605
|
if (name !== 'declare' && name !== 'typeset' && name !== 'local') return
|
|
1504
1606
|
let integer = false
|
|
1505
1607
|
let nameref = false
|
|
@@ -1521,6 +1623,11 @@ class Parser {
|
|
|
1521
1623
|
if (flags && word.value.startsWith('-') && !word.expands) continue
|
|
1522
1624
|
const equals = word.value.indexOf('=')
|
|
1523
1625
|
const nameFor = equals < 0 ? word.value : word.value.slice(0, equals)
|
|
1626
|
+
if (integer || nameref) {
|
|
1627
|
+
const declared = plainName(nameFor)
|
|
1628
|
+
if (declared === undefined) this.context.declaredUnknown = true
|
|
1629
|
+
else this.context.declaredNames.add(declared)
|
|
1630
|
+
}
|
|
1524
1631
|
if (nameFor.includes('[') || (word.expands && /[$`]/.test(nameFor)))
|
|
1525
1632
|
this.context.opaque('arithmetic')
|
|
1526
1633
|
else if (nameref && word.value.slice(equals + 1).includes('[') && equals >= 0)
|
|
@@ -1534,6 +1641,7 @@ class Parser {
|
|
|
1534
1641
|
/** The names `read` stores into, minus the arguments of its options. */
|
|
1535
1642
|
private inspectRead(args: ShellWord[]): void {
|
|
1536
1643
|
let options = true
|
|
1644
|
+
let targets = 0
|
|
1537
1645
|
for (let i = 0; i < args.length; i += 1) {
|
|
1538
1646
|
const value = (args[i] as ShellWord).value
|
|
1539
1647
|
if (options && value === '--') {
|
|
@@ -1548,13 +1656,20 @@ class Parser {
|
|
|
1548
1656
|
const operand = rest.length > 0 ? rest : (args[i + 1]?.value ?? '')
|
|
1549
1657
|
if (rest.length === 0) i += 1
|
|
1550
1658
|
if (letter === 'a' && operand.includes('[')) this.context.opaque('arithmetic')
|
|
1659
|
+
if (letter === 'a') {
|
|
1660
|
+
this.context.storedInto(plainName(operand))
|
|
1661
|
+
targets += 1
|
|
1662
|
+
}
|
|
1551
1663
|
break
|
|
1552
1664
|
}
|
|
1553
1665
|
}
|
|
1554
1666
|
continue
|
|
1555
1667
|
}
|
|
1556
1668
|
if (subscriptOrExpands(args[i] as ShellWord)) this.context.opaque('arithmetic')
|
|
1669
|
+
this.context.storedInto(plainName(value))
|
|
1670
|
+
targets += 1
|
|
1557
1671
|
}
|
|
1672
|
+
if (targets === 0) this.context.storedInto('REPLY')
|
|
1558
1673
|
}
|
|
1559
1674
|
|
|
1560
1675
|
/** A plain `NAME=value` whose value holds a subscript: dangerous once NAME is `-i` or `-n`. */
|
|
@@ -1563,7 +1678,15 @@ class Parser {
|
|
|
1563
1678
|
const equals = word.value.indexOf('=')
|
|
1564
1679
|
if (equals <= 0) return
|
|
1565
1680
|
const value = word.value.slice(equals + 1)
|
|
1566
|
-
if (value.includes('[') || (word.expands && /[$`]/.test(value)))
|
|
1681
|
+
if (value.includes('[') || (word.expands && /[$`]/.test(value))) {
|
|
1682
|
+
this.context.bracketAssigned()
|
|
1683
|
+
const named = ASSIGNMENT_NAME.exec(word.value)
|
|
1684
|
+
this.context.storedInto(named === null ? undefined : named[1])
|
|
1685
|
+
} else if (NAMES_A_VARIABLE.test(value)) {
|
|
1686
|
+
// A name holds whatever an earlier call stored in it.
|
|
1687
|
+
const named = ASSIGNMENT_NAME.exec(word.value)
|
|
1688
|
+
this.context.storedInto(named === null ? undefined : named[1])
|
|
1689
|
+
}
|
|
1567
1690
|
}
|
|
1568
1691
|
|
|
1569
1692
|
/** Read the payload of `bash -c payload` as a command line of its own. */
|
|
@@ -997,6 +997,382 @@ function touchOperands(args: Args): ShellWord[] {
|
|
|
997
997
|
return out
|
|
998
998
|
}
|
|
999
999
|
|
|
1000
|
+
/** The value of a flag that may be attached (`-oX`, `--output=X`) or separate (`-o X`). */
|
|
1001
|
+
function flagValues(args: Args, short: string, long: readonly string[]): ShellWord[] {
|
|
1002
|
+
const out: ShellWord[] = []
|
|
1003
|
+
for (let i = 0; i < args.length; i += 1) {
|
|
1004
|
+
const arg = args[i] as ShellWord
|
|
1005
|
+
const text = arg.value
|
|
1006
|
+
if (text === '--') break
|
|
1007
|
+
if (text.startsWith('--')) {
|
|
1008
|
+
const eq = text.indexOf('=')
|
|
1009
|
+
const name = eq >= 0 ? text.slice(0, eq) : text
|
|
1010
|
+
if (!long.includes(name)) continue
|
|
1011
|
+
if (eq >= 0) out.push(derived(arg, text.slice(eq + 1)))
|
|
1012
|
+
else if (args[i + 1] !== undefined) out.push(args[i + 1] as ShellWord)
|
|
1013
|
+
continue
|
|
1014
|
+
}
|
|
1015
|
+
if (text.startsWith('-') && text.length > 1 && short !== '') {
|
|
1016
|
+
const at = text.indexOf(short, 1)
|
|
1017
|
+
if (at < 0) continue
|
|
1018
|
+
const rest = text.slice(at + 1)
|
|
1019
|
+
if (rest !== '') out.push(derived(arg, rest))
|
|
1020
|
+
else if (args[i + 1] !== undefined) out.push(args[i + 1] as ShellWord)
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
return out
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
/** Whether any short flag cluster holds one of `letters` (`-xf`, `-x`). */
|
|
1027
|
+
function hasShort(args: Args, letters: string): boolean {
|
|
1028
|
+
return args.some(
|
|
1029
|
+
(a) =>
|
|
1030
|
+
!a.value.startsWith('--') &&
|
|
1031
|
+
a.value.startsWith('-') &&
|
|
1032
|
+
[...letters].some((l) => a.value.slice(1).includes(l)),
|
|
1033
|
+
)
|
|
1034
|
+
}
|
|
1035
|
+
|
|
1036
|
+
/**
|
|
1037
|
+
* Positional arguments once the value of every option that takes one is
|
|
1038
|
+
* skipped. `valuedLong` are `--name VALUE` options (`--name=VALUE` is one
|
|
1039
|
+
* word and never needs skipping); `valuedShort` letters take the rest of the
|
|
1040
|
+
* cluster or, when last, the next word. An option not named here is a switch.
|
|
1041
|
+
*/
|
|
1042
|
+
function operandsSkippingValues(
|
|
1043
|
+
args: Args,
|
|
1044
|
+
valuedLong: ReadonlySet<string>,
|
|
1045
|
+
valuedShort: string,
|
|
1046
|
+
): ShellWord[] {
|
|
1047
|
+
const out: ShellWord[] = []
|
|
1048
|
+
for (let i = 0; i < args.length; i += 1) {
|
|
1049
|
+
const arg = args[i] as ShellWord
|
|
1050
|
+
const text = arg.value
|
|
1051
|
+
if (text === '--') {
|
|
1052
|
+
out.push(...args.slice(i + 1))
|
|
1053
|
+
break
|
|
1054
|
+
}
|
|
1055
|
+
if (text === '-' || !text.startsWith('-')) {
|
|
1056
|
+
out.push(arg)
|
|
1057
|
+
} else if (text.startsWith('--')) {
|
|
1058
|
+
if (!text.includes('=') && valuedLong.has(text)) i += 1
|
|
1059
|
+
} else {
|
|
1060
|
+
for (let j = 1; j < text.length; j += 1) {
|
|
1061
|
+
if (valuedShort.includes(text[j] as string)) {
|
|
1062
|
+
if (j === text.length - 1) i += 1
|
|
1063
|
+
break
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
1068
|
+
return out
|
|
1069
|
+
}
|
|
1070
|
+
|
|
1071
|
+
const GIT_CLONE_VALUED = set(
|
|
1072
|
+
'--depth',
|
|
1073
|
+
'--branch',
|
|
1074
|
+
'--origin',
|
|
1075
|
+
'--config',
|
|
1076
|
+
'--template',
|
|
1077
|
+
'--reference',
|
|
1078
|
+
'--reference-if-able',
|
|
1079
|
+
'--separate-git-dir',
|
|
1080
|
+
'--jobs',
|
|
1081
|
+
'--filter',
|
|
1082
|
+
'--upload-pack',
|
|
1083
|
+
'--server-option',
|
|
1084
|
+
'--shallow-since',
|
|
1085
|
+
'--shallow-exclude',
|
|
1086
|
+
'--bundle-uri',
|
|
1087
|
+
'--ref-format',
|
|
1088
|
+
'--object-format',
|
|
1089
|
+
'--revision',
|
|
1090
|
+
)
|
|
1091
|
+
const GIT_INIT_VALUED = set(
|
|
1092
|
+
'--template',
|
|
1093
|
+
'--initial-branch',
|
|
1094
|
+
'--object-format',
|
|
1095
|
+
'--separate-git-dir',
|
|
1096
|
+
'--ref-format',
|
|
1097
|
+
)
|
|
1098
|
+
const RSYNC_VALUED = set(
|
|
1099
|
+
'--exclude',
|
|
1100
|
+
'--include',
|
|
1101
|
+
'--filter',
|
|
1102
|
+
'--exclude-from',
|
|
1103
|
+
'--include-from',
|
|
1104
|
+
'--rsh',
|
|
1105
|
+
'--rsync-path',
|
|
1106
|
+
'--log-file',
|
|
1107
|
+
'--backup-dir',
|
|
1108
|
+
'--partial-dir',
|
|
1109
|
+
'--temp-dir',
|
|
1110
|
+
'--files-from',
|
|
1111
|
+
'--port',
|
|
1112
|
+
'--bwlimit',
|
|
1113
|
+
'--max-size',
|
|
1114
|
+
'--min-size',
|
|
1115
|
+
'--timeout',
|
|
1116
|
+
'--compare-dest',
|
|
1117
|
+
'--copy-dest',
|
|
1118
|
+
'--link-dest',
|
|
1119
|
+
'--suffix',
|
|
1120
|
+
'--chmod',
|
|
1121
|
+
'--chown',
|
|
1122
|
+
'--usermap',
|
|
1123
|
+
'--groupmap',
|
|
1124
|
+
'--block-size',
|
|
1125
|
+
'--compress-level',
|
|
1126
|
+
'--skip-compress',
|
|
1127
|
+
'--address',
|
|
1128
|
+
'--sockopts',
|
|
1129
|
+
'--out-format',
|
|
1130
|
+
'--info',
|
|
1131
|
+
'--debug',
|
|
1132
|
+
'--read-batch',
|
|
1133
|
+
'--write-batch',
|
|
1134
|
+
'--only-write-batch',
|
|
1135
|
+
'--password-file',
|
|
1136
|
+
'--protocol',
|
|
1137
|
+
'--iconv',
|
|
1138
|
+
'--max-delete',
|
|
1139
|
+
'--modify-window',
|
|
1140
|
+
'--checksum-seed',
|
|
1141
|
+
'--stop-after',
|
|
1142
|
+
'--stop-at',
|
|
1143
|
+
'--early-input',
|
|
1144
|
+
'--outbuf',
|
|
1145
|
+
)
|
|
1146
|
+
|
|
1147
|
+
/**
|
|
1148
|
+
* The places a program writes through an output flag or a destination operand,
|
|
1149
|
+
* for the programs that download, copy or unpack. None of them is in the
|
|
1150
|
+
* reading table, and each can plant a file at a path the line names. One that
|
|
1151
|
+
* downloads or unpacks into the current directory when it is given no
|
|
1152
|
+
* destination reports `.`.
|
|
1153
|
+
*/
|
|
1154
|
+
function outputTargets(program: string, args: Args): ShellWord[] {
|
|
1155
|
+
const dot = word('.')
|
|
1156
|
+
switch (program) {
|
|
1157
|
+
case 'curl': {
|
|
1158
|
+
const out = flagValues(args, 'o', ['--output'])
|
|
1159
|
+
out.push(...flagValues(args, 'D', ['--dump-header']))
|
|
1160
|
+
out.push(...flagValues(args, 'c', ['--cookie-jar']))
|
|
1161
|
+
out.push(...flagValues(args, '', ['--output-dir', '--trace', '--trace-ascii', '--stderr']))
|
|
1162
|
+
if (hasShort(args, 'O') || args.some((a) => a.value === '--remote-name')) out.push(dot)
|
|
1163
|
+
return out
|
|
1164
|
+
}
|
|
1165
|
+
case 'wget': {
|
|
1166
|
+
const document = flagValues(args, 'O', ['--output-document'])
|
|
1167
|
+
const out = [...document]
|
|
1168
|
+
out.push(...flagValues(args, 'P', ['--directory-prefix']))
|
|
1169
|
+
out.push(...flagValues(args, 'o', ['--output-file']))
|
|
1170
|
+
out.push(...flagValues(args, 'a', ['--append-output']))
|
|
1171
|
+
out.push(...flagValues(args, '', ['--save-cookies']))
|
|
1172
|
+
if (document.length === 0) out.push(dot)
|
|
1173
|
+
return out
|
|
1174
|
+
}
|
|
1175
|
+
case 'dd':
|
|
1176
|
+
return args.filter((a) => a.value.startsWith('of=')).map((a) => derived(a, a.value.slice(3)))
|
|
1177
|
+
case 'install':
|
|
1178
|
+
return [...copyOperands(args), ...(hasShort(args, 'd') ? operands(args) : [])]
|
|
1179
|
+
case 'rsync': {
|
|
1180
|
+
const rest = operandsSkippingValues(args, RSYNC_VALUED, 'eTBMfgp'.replace(/[gp]/g, ''))
|
|
1181
|
+
return rest.length > 1 ? [rest[rest.length - 1] as ShellWord] : []
|
|
1182
|
+
}
|
|
1183
|
+
case 'tar': {
|
|
1184
|
+
const out = [...flagValues(args, 'C', ['--directory'])]
|
|
1185
|
+
const first = args[0]?.value ?? ''
|
|
1186
|
+
const old = !first.startsWith('-') && /^[A-Za-z]+$/.test(first) ? first : ''
|
|
1187
|
+
const has = (letter: string): boolean => old.includes(letter) || hasShort(args, letter)
|
|
1188
|
+
const extracts = has('x') || args.some((a) => a.value === '--extract' || a.value === '--get')
|
|
1189
|
+
const creates = has('c') || args.some((a) => a.value === '--create')
|
|
1190
|
+
if (extracts && out.length === 0) out.push(dot)
|
|
1191
|
+
const rewrites =
|
|
1192
|
+
has('r') ||
|
|
1193
|
+
has('u') ||
|
|
1194
|
+
has('A') ||
|
|
1195
|
+
args.some((a) => /^--(?:append|update|catenate|concatenate|delete)$/.test(a.value))
|
|
1196
|
+
if (creates || rewrites) {
|
|
1197
|
+
out.push(...flagValues(args, 'f', ['--file']))
|
|
1198
|
+
const named = args[1]
|
|
1199
|
+
if (old.includes('f') && named !== undefined) out.push(named)
|
|
1200
|
+
}
|
|
1201
|
+
return out
|
|
1202
|
+
}
|
|
1203
|
+
case 'unzip': {
|
|
1204
|
+
const lists = args.some((a) => {
|
|
1205
|
+
if (a.value.startsWith('--') || !a.value.startsWith('-')) return false
|
|
1206
|
+
for (const letter of a.value.slice(1)) {
|
|
1207
|
+
if ('dxP'.includes(letter)) return false
|
|
1208
|
+
if ('lptvZ'.includes(letter)) return true
|
|
1209
|
+
}
|
|
1210
|
+
return false
|
|
1211
|
+
})
|
|
1212
|
+
if (lists) return []
|
|
1213
|
+
const out = flagValues(args, 'd', [])
|
|
1214
|
+
return out.length > 0 ? out : [dot]
|
|
1215
|
+
}
|
|
1216
|
+
case 'git': {
|
|
1217
|
+
const valued = new Set(['-C', '-c', '--git-dir', '--work-tree', '--namespace'])
|
|
1218
|
+
let index = 0
|
|
1219
|
+
let base = ''
|
|
1220
|
+
const hooked: ShellWord[] = []
|
|
1221
|
+
while (index < args.length && (args[index] as ShellWord).value.startsWith('-')) {
|
|
1222
|
+
const flag = (args[index] as ShellWord).value
|
|
1223
|
+
index += 1
|
|
1224
|
+
if (valued.has(flag) && index < args.length) {
|
|
1225
|
+
if (flag === '-C') base = (args[index] as ShellWord).value
|
|
1226
|
+
if (
|
|
1227
|
+
flag === '-c' &&
|
|
1228
|
+
/^core\.(?:hookspath|fsmonitor|sshcommand|pager|editor)=/i.test(
|
|
1229
|
+
(args[index] as ShellWord).value,
|
|
1230
|
+
)
|
|
1231
|
+
) {
|
|
1232
|
+
hooked.push(word('.git/hooks'))
|
|
1233
|
+
}
|
|
1234
|
+
index += 1
|
|
1235
|
+
}
|
|
1236
|
+
}
|
|
1237
|
+
const sub = args[index]?.value
|
|
1238
|
+
const place = (target: ShellWord | undefined): ShellWord => {
|
|
1239
|
+
const value = target?.value ?? '.'
|
|
1240
|
+
const placed =
|
|
1241
|
+
base === '' || value.startsWith('/') || value.startsWith('~')
|
|
1242
|
+
? value
|
|
1243
|
+
: `${base.replace(/\/+$/, '')}/${value}`
|
|
1244
|
+
return target === undefined ? word(placed) : derived(target, placed)
|
|
1245
|
+
}
|
|
1246
|
+
const tail = args.slice(index + 1)
|
|
1247
|
+
if (sub === 'clone' || sub === 'init') {
|
|
1248
|
+
const rest = operandsSkippingValues(
|
|
1249
|
+
tail,
|
|
1250
|
+
sub === 'clone' ? GIT_CLONE_VALUED : GIT_INIT_VALUED,
|
|
1251
|
+
sub === 'clone' ? 'bocju' : 'b',
|
|
1252
|
+
)
|
|
1253
|
+
// A clone names its destination last; one operand is only the source.
|
|
1254
|
+
const target =
|
|
1255
|
+
sub === 'clone' ? (rest.length > 1 ? rest[rest.length - 1] : undefined) : rest[0]
|
|
1256
|
+
return [...hooked, place(target)]
|
|
1257
|
+
}
|
|
1258
|
+
if (sub === 'config') {
|
|
1259
|
+
const file = flagValues(tail, 'f', ['--file'])
|
|
1260
|
+
if (file.length > 0) return [...hooked, ...file.map((f) => place(f))]
|
|
1261
|
+
const reads = tail.some((a) =>
|
|
1262
|
+
/^(?:--get|--get-all|--get-regexp|--get-urlmatch|--list|-l|--show-origin|--show-scope|--name-only)$/.test(
|
|
1263
|
+
a.value,
|
|
1264
|
+
),
|
|
1265
|
+
)
|
|
1266
|
+
const given = operandsSkippingValues(
|
|
1267
|
+
tail,
|
|
1268
|
+
set('--file', '--blob', '--type', '--default'),
|
|
1269
|
+
'f',
|
|
1270
|
+
)
|
|
1271
|
+
const writes = tail.some((a) =>
|
|
1272
|
+
/^(?:--add|--unset|--unset-all|--replace-all|--edit|-e|--rename-section|--remove-section)$/.test(
|
|
1273
|
+
a.value,
|
|
1274
|
+
),
|
|
1275
|
+
)
|
|
1276
|
+
const risky =
|
|
1277
|
+
/^(?:core|alias|credential|filter|include|includeif|url|protocol|gpg|diff|merge|pager|sequence|uploadpack|receive|http|ssh|safe|submodule)\./i.test(
|
|
1278
|
+
given[0]?.value ?? '',
|
|
1279
|
+
) ||
|
|
1280
|
+
/\.(?:command|cmd|driver|textconv|program|sshcommand|helper|path)$/i.test(
|
|
1281
|
+
given[0]?.value ?? '',
|
|
1282
|
+
)
|
|
1283
|
+
if (!reads && (writes || given.length >= 2) && risky) {
|
|
1284
|
+
return [...hooked, place(word('.git/config'))]
|
|
1285
|
+
}
|
|
1286
|
+
return hooked
|
|
1287
|
+
}
|
|
1288
|
+
if (sub === 'archive')
|
|
1289
|
+
return [...hooked, ...flagValues(tail, 'o', ['--output']).map((f) => place(f))]
|
|
1290
|
+
if (sub === 'bundle' && tail[0]?.value === 'create' && tail[1] !== undefined) {
|
|
1291
|
+
return [...hooked, place(tail[1])]
|
|
1292
|
+
}
|
|
1293
|
+
if (sub === 'worktree' && tail[0]?.value === 'add') {
|
|
1294
|
+
const dest = operandsSkippingValues(tail.slice(1), set('--reason'), 'bB')[0]
|
|
1295
|
+
return [...hooked, ...(dest !== undefined ? [place(dest)] : [])]
|
|
1296
|
+
}
|
|
1297
|
+
return hooked
|
|
1298
|
+
}
|
|
1299
|
+
case 'ln': {
|
|
1300
|
+
const into = flagValues(args, 't', ['--target-directory'])
|
|
1301
|
+
if (into.length > 0) return into
|
|
1302
|
+
const rest = operandsSkippingValues(args, set('--suffix'), 'S')
|
|
1303
|
+
return rest.length > 0 ? [rest.length > 1 ? (rest[rest.length - 1] as ShellWord) : dot] : []
|
|
1304
|
+
}
|
|
1305
|
+
case 'zip': {
|
|
1306
|
+
const out = flagValues(args, 'O', ['--output-file'])
|
|
1307
|
+
if (out.length > 0) return out
|
|
1308
|
+
const first = operandsSkippingValues(
|
|
1309
|
+
args,
|
|
1310
|
+
set('--temp-path', '--password'),
|
|
1311
|
+
'btnPpdf'.replace(/[pdf]/g, ''),
|
|
1312
|
+
)[0]
|
|
1313
|
+
return first === undefined ? [] : [first]
|
|
1314
|
+
}
|
|
1315
|
+
case 'patch': {
|
|
1316
|
+
const out = flagValues(args, 'o', ['--output'])
|
|
1317
|
+
if (out.length > 0) return out
|
|
1318
|
+
const first = operandsSkippingValues(
|
|
1319
|
+
args,
|
|
1320
|
+
set(
|
|
1321
|
+
'--strip',
|
|
1322
|
+
'--input',
|
|
1323
|
+
'--directory',
|
|
1324
|
+
'--reject-file',
|
|
1325
|
+
'--backup-prefix',
|
|
1326
|
+
'--suffix',
|
|
1327
|
+
'--basename-prefix',
|
|
1328
|
+
'--fuzz',
|
|
1329
|
+
'--version-control',
|
|
1330
|
+
),
|
|
1331
|
+
'pidDrBVYzF',
|
|
1332
|
+
)[0]
|
|
1333
|
+
return first === undefined ? [] : [first]
|
|
1334
|
+
}
|
|
1335
|
+
case 'truncate':
|
|
1336
|
+
return operandsSkippingValues(args, set('--size', '--reference', '--io-blocks'), 'sr')
|
|
1337
|
+
case 'perl': {
|
|
1338
|
+
const inPlace = args.some((a) => /^-[A-Za-z0-9]*i/.test(a.value) && !a.value.startsWith('--'))
|
|
1339
|
+
if (!inPlace) return []
|
|
1340
|
+
const script = args.some(
|
|
1341
|
+
(a) => /^-[A-Za-z0-9]*[eE]/.test(a.value) && !a.value.startsWith('--'),
|
|
1342
|
+
)
|
|
1343
|
+
const files = operandsSkippingValues(args, set(), 'eEIMmxCl'.replace(/[Cl]/g, ''))
|
|
1344
|
+
return script ? files : files.slice(1)
|
|
1345
|
+
}
|
|
1346
|
+
case 'sort':
|
|
1347
|
+
return flagValues(args, 'o', ['--output'])
|
|
1348
|
+
case 'openssl':
|
|
1349
|
+
return args.flatMap((a, i) =>
|
|
1350
|
+
['-out', '-keyout', '-outform'].includes(a.value) &&
|
|
1351
|
+
a.value !== '-outform' &&
|
|
1352
|
+
args[i + 1] !== undefined
|
|
1353
|
+
? [args[i + 1] as ShellWord]
|
|
1354
|
+
: [],
|
|
1355
|
+
)
|
|
1356
|
+
case 'ssh-keygen': {
|
|
1357
|
+
const key = flagValues(args, 'f', [])
|
|
1358
|
+
return key.flatMap((k) => [k, derived(k, `${k.value}.pub`)])
|
|
1359
|
+
}
|
|
1360
|
+
case 'find':
|
|
1361
|
+
return args.flatMap((a, i) =>
|
|
1362
|
+
/^-f(?:print|print0|printf|ls)$/.test(a.value) && args[i + 1] !== undefined
|
|
1363
|
+
? [args[i + 1] as ShellWord]
|
|
1364
|
+
: [],
|
|
1365
|
+
)
|
|
1366
|
+
case 'aria2c':
|
|
1367
|
+
return [
|
|
1368
|
+
...flagValues(args, 'd', ['--dir']),
|
|
1369
|
+
...flagValues(args, '', ['--out', '--log', '--save-cookies', '--save-session']),
|
|
1370
|
+
]
|
|
1371
|
+
default:
|
|
1372
|
+
return []
|
|
1373
|
+
}
|
|
1374
|
+
}
|
|
1375
|
+
|
|
1000
1376
|
/** Commands that create or change what their operands name. `sed` is added per call when it edits in place. */
|
|
1001
1377
|
const WRITERS = new Set(['mkdir', 'touch', 'rm', 'rmdir', 'mv', 'cp', 'tee'])
|
|
1002
1378
|
|
|
@@ -1063,6 +1439,16 @@ export function shellPathAccess(reading: ShellReading): ShellPathAccess {
|
|
|
1063
1439
|
})
|
|
1064
1440
|
}
|
|
1065
1441
|
}
|
|
1442
|
+
for (const arg of outputTargets(program, args)) {
|
|
1443
|
+
if (arg.value === '' || arg.value === '-' || isHarmlessTarget(arg.value)) continue
|
|
1444
|
+
uses.push({
|
|
1445
|
+
path: arg.value,
|
|
1446
|
+
access: 'write',
|
|
1447
|
+
via: program,
|
|
1448
|
+
unresolved: expandsAtRuntime(arg),
|
|
1449
|
+
...(directory !== undefined ? { directory } : {}),
|
|
1450
|
+
})
|
|
1451
|
+
}
|
|
1066
1452
|
if (program === 'touch') {
|
|
1067
1453
|
for (const arg of touchReferences(args)) {
|
|
1068
1454
|
if (arg.value === '' || isHarmlessTarget(arg.value)) continue
|