vouchington-tooling 0.53.0 → 0.54.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/README.md +76 -12
- package/dist/agent-blackboard/index.d.mts +0 -1
- package/dist/agent-blackboard/index.mjs +0 -23
- package/dist/cli/commands/agent-blackboard-flags.d.mts +0 -1
- package/dist/cli/commands/agent-blackboard-flags.mjs +0 -9
- package/dist/cli/commands/agent-blackboard.d.mts +0 -2
- package/dist/cli/commands/agent-blackboard.mjs +7 -121
- package/dist/cli/commands/story-coverage.d.mts +2 -0
- package/dist/cli/commands/story-coverage.mjs +56 -0
- package/dist/cli/index.mjs +6 -0
- package/dist/cli/parse-forwarded-commands.d.mts +3 -0
- package/dist/cli/parse-forwarded-commands.mjs +2 -0
- package/dist/cli/parse-story-coverage-fields.d.mts +19 -0
- package/dist/cli/parse-story-coverage-fields.mjs +69 -0
- package/dist/cli/parse-story-coverage.d.mts +8 -0
- package/dist/cli/parse-story-coverage.mjs +34 -0
- package/dist/cli/parse.d.mts +5 -1
- package/dist/cli/parse.mjs +3 -0
- package/dist/cli/usage.d.mts +1 -1
- package/dist/cli/usage.mjs +8 -7
- package/dist/host-storage/check.d.mts +38 -0
- package/dist/host-storage/check.mjs +109 -0
- package/dist/host-storage/cli.d.mts +7 -0
- package/dist/host-storage/cli.mjs +102 -0
- package/dist/host-storage/host-storage.test-helpers.d.mts +26 -0
- package/dist/host-storage/host-storage.test-helpers.mjs +58 -0
- package/dist/host-storage/index.d.mts +3 -0
- package/dist/host-storage/index.mjs +3 -0
- package/dist/host-storage/preflight.d.mts +22 -0
- package/dist/host-storage/preflight.mjs +105 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.mjs +1 -0
- package/dist/playwright/assertions.d.mts +1 -0
- package/dist/playwright/assertions.mjs +5 -0
- package/dist/playwright/blocked-external-network.d.mts +15 -0
- package/dist/playwright/blocked-external-network.mjs +73 -0
- package/dist/playwright/browser-dialog-issues.d.mts +12 -0
- package/dist/playwright/browser-dialog-issues.mjs +29 -0
- package/dist/playwright/browser-errors.d.mts +22 -0
- package/dist/playwright/browser-errors.mjs +130 -0
- package/dist/playwright/browser-issue-monitor.test-helpers.d.mts +31 -0
- package/dist/playwright/browser-issue-monitor.test-helpers.mjs +51 -0
- package/dist/playwright/browser-issue-records.d.mts +42 -0
- package/dist/playwright/browser-issue-records.mjs +148 -0
- package/dist/playwright/browser-test.d.mts +21 -0
- package/dist/playwright/browser-test.mjs +68 -0
- package/dist/playwright/expect-no-broken-images.d.mts +17 -0
- package/dist/playwright/expect-no-broken-images.mjs +39 -0
- package/dist/playwright/index.d.mts +30 -0
- package/dist/playwright/index.mjs +22 -0
- package/dist/playwright/mobile-assertions.d.mts +14 -0
- package/dist/playwright/mobile-assertions.mjs +43 -0
- package/dist/playwright/navigate-to.d.mts +27 -0
- package/dist/playwright/navigate-to.mjs +39 -0
- package/dist/playwright/radix-select.d.mts +18 -0
- package/dist/playwright/radix-select.mjs +19 -0
- package/dist/playwright/random-id.d.mts +34 -0
- package/dist/playwright/random-id.mjs +37 -0
- package/dist/playwright/retry-on-connection-lost.d.mts +7 -0
- package/dist/playwright/retry-on-connection-lost.mjs +107 -0
- package/dist/playwright/scroll-to-load-more.d.mts +37 -0
- package/dist/playwright/scroll-to-load-more.mjs +158 -0
- package/dist/playwright/storybook.d.mts +2 -0
- package/dist/playwright/storybook.mjs +13 -0
- package/dist/playwright/test-fixtures.d.mts +1 -0
- package/dist/playwright/test-fixtures.mjs +2 -0
- package/dist/playwright/test-lifecycle-reporter.d.mts +11 -0
- package/dist/playwright/test-lifecycle-reporter.mjs +35 -0
- package/dist/playwright/totp.d.mts +6 -0
- package/dist/playwright/totp.mjs +37 -0
- package/dist/playwright/turnstile-stub.d.mts +8 -0
- package/dist/playwright/turnstile-stub.mjs +61 -0
- package/dist/playwright/viewport-constants.d.mts +30 -0
- package/dist/playwright/viewport-constants.mjs +9 -0
- package/dist/playwright/virtual-authenticator.d.mts +5 -0
- package/dist/playwright/virtual-authenticator.mjs +15 -0
- package/dist/playwright/wait-for-hydration.d.mts +29 -0
- package/dist/playwright/wait-for-hydration.mjs +81 -0
- package/dist/shell-parse/ansi-c-string.d.mts +12 -0
- package/dist/shell-parse/ansi-c-string.mjs +80 -0
- package/dist/shell-parse/index.d.mts +20 -0
- package/dist/shell-parse/index.mjs +15 -0
- package/dist/shell-parse/shell-command-substitution-reads.d.mts +8 -0
- package/dist/shell-parse/shell-command-substitution-reads.mjs +53 -0
- package/dist/shell-parse/shell-command-substitutions.d.mts +8 -0
- package/dist/shell-parse/shell-command-substitutions.mjs +52 -0
- package/dist/shell-parse/shell-command-wrappers.d.mts +26 -0
- package/dist/shell-parse/shell-command-wrappers.mjs +143 -0
- package/dist/shell-parse/shell-commands.d.mts +24 -0
- package/dist/shell-parse/shell-commands.mjs +155 -0
- package/dist/shell-parse/shell-heredoc-delimiter.d.mts +5 -0
- package/dist/shell-parse/shell-heredoc-delimiter.mjs +52 -0
- package/dist/shell-parse/shell-heredoc-parser.d.mts +7 -0
- package/dist/shell-parse/shell-heredoc-parser.mjs +49 -0
- package/dist/shell-parse/shell-heredoc-quote-state.d.mts +19 -0
- package/dist/shell-parse/shell-heredoc-quote-state.mjs +40 -0
- package/dist/shell-parse/shell-heredoc.d.mts +10 -0
- package/dist/shell-parse/shell-heredoc.mjs +90 -0
- package/dist/shell-parse/shell-redirections.d.mts +5 -0
- package/dist/shell-parse/shell-redirections.mjs +34 -0
- package/dist/shell-parse/shell-script-operand.d.mts +13 -0
- package/dist/shell-parse/shell-script-operand.mjs +103 -0
- package/dist/shell-parse/shell-stdin-script.d.mts +6 -0
- package/dist/shell-parse/shell-stdin-script.mjs +61 -0
- package/dist/shell-parse/shell-token-utils.d.mts +9 -0
- package/dist/shell-parse/shell-token-utils.mjs +33 -0
- package/dist/shell-parse/shell-tokenizer-comments.d.mts +1 -0
- package/dist/shell-parse/shell-tokenizer-comments.mjs +57 -0
- package/dist/shell-parse/shell-tokenizer-operators.d.mts +14 -0
- package/dist/shell-parse/shell-tokenizer-operators.mjs +47 -0
- package/dist/shell-parse/shell-tokenizer.d.mts +12 -0
- package/dist/shell-parse/shell-tokenizer.mjs +104 -0
- package/dist/story-coverage/analyze.d.mts +8 -0
- package/dist/story-coverage/analyze.mjs +24 -0
- package/dist/story-coverage/check.d.mts +11 -0
- package/dist/story-coverage/check.mjs +42 -0
- package/dist/story-coverage/components.d.mts +10 -0
- package/dist/story-coverage/components.mjs +40 -0
- package/dist/story-coverage/coverage.d.mts +10 -0
- package/dist/story-coverage/coverage.mjs +43 -0
- package/dist/story-coverage/index.d.mts +13 -0
- package/dist/story-coverage/index.mjs +7 -0
- package/dist/story-coverage/messages.d.mts +10 -0
- package/dist/story-coverage/messages.mjs +42 -0
- package/dist/story-coverage/options.d.mts +27 -0
- package/dist/story-coverage/options.mjs +51 -0
- package/dist/story-coverage/workspace.d.mts +2 -0
- package/dist/story-coverage/workspace.mjs +27 -0
- package/dist/test-helpers/cancel-runs.test-helpers.d.mts +39 -0
- package/dist/test-helpers/cancel-runs.test-helpers.mjs +124 -0
- package/dist/test-helpers/run-bounded-exit-observer.test-helpers.d.mts +12 -0
- package/dist/test-helpers/run-bounded-exit-observer.test-helpers.mjs +68 -0
- package/dist/test-helpers/run-bounded-output-fixture.test-helpers.d.mts +18 -0
- package/dist/test-helpers/run-bounded-output-fixture.test-helpers.mjs +162 -0
- package/dist/vitest-diagnostics/index.d.mts +9 -1
- package/dist/vitest-diagnostics/index.mjs +5 -1
- package/dist/vitest-diagnostics/vitest-fake-timer-guard.d.mts +6 -0
- package/dist/vitest-diagnostics/vitest-fake-timer-guard.mjs +34 -0
- package/dist/vitest-diagnostics/vitest-fork-leak-detection.d.mts +1 -0
- package/dist/vitest-diagnostics/vitest-fork-leak-detection.mjs +8 -0
- package/dist/vitest-diagnostics/vitest-fork-leak-diagnostics.d.mts +10 -1
- package/dist/vitest-diagnostics/vitest-fork-leak-diagnostics.mjs +43 -2
- package/dist/vitest-diagnostics/vitest-fork-leak-handshake-samples.d.mts +50 -0
- package/dist/vitest-diagnostics/vitest-fork-leak-handshake-samples.mjs +69 -0
- package/dist/vitest-diagnostics/vitest-fork-leak-handshake.d.mts +19 -0
- package/dist/vitest-diagnostics/vitest-fork-leak-handshake.mjs +136 -0
- package/dist/vitest-diagnostics/vitest-network-allowlist-dns.d.mts +7 -0
- package/dist/vitest-diagnostics/vitest-network-allowlist-dns.mjs +54 -0
- package/dist/vitest-diagnostics/vitest-network-allowlist-host.d.mts +8 -0
- package/dist/vitest-diagnostics/vitest-network-allowlist-host.mjs +48 -0
- package/dist/vitest-diagnostics/vitest-network-allowlist-socket.d.mts +14 -0
- package/dist/vitest-diagnostics/vitest-network-allowlist-socket.mjs +39 -0
- package/dist/vitest-diagnostics/vitest-network-allowlist.d.mts +7 -0
- package/dist/vitest-diagnostics/vitest-network-allowlist.mjs +72 -0
- package/dist/vitest-diagnostics/vitest-process-resources.d.mts +6 -0
- package/dist/vitest-diagnostics/vitest-process-resources.mjs +51 -0
- package/dist/vitest-effective-timeout/cap.d.mts +9 -0
- package/dist/vitest-effective-timeout/cap.mjs +28 -0
- package/dist/vitest-effective-timeout/check-profiles.d.mts +15 -0
- package/dist/vitest-effective-timeout/check-profiles.mjs +52 -0
- package/dist/vitest-effective-timeout/config-file.d.mts +6 -0
- package/dist/vitest-effective-timeout/config-file.mjs +23 -0
- package/dist/vitest-effective-timeout/fixtures.d.mts +2 -0
- package/dist/vitest-effective-timeout/fixtures.mjs +18 -0
- package/dist/vitest-effective-timeout/index.d.mts +7 -0
- package/dist/vitest-effective-timeout/index.mjs +4 -0
- package/dist/vitest-effective-timeout/profiles.d.mts +10 -0
- package/dist/vitest-effective-timeout/profiles.mjs +33 -0
- package/dist/vitest-effective-timeout/run-profile.d.mts +31 -0
- package/dist/vitest-effective-timeout/run-profile.mjs +95 -0
- package/docs/mcp-server.md +2 -13
- package/package.json +32 -2
- package/scripts/__pycache__/run_bounded_process.cpython-312.pyc +0 -0
- package/scripts/chromium-launch-probe.d.mts +7 -0
- package/scripts/chromium-launch-probe.mjs +101 -0
- package/scripts/run-bounded-fixtures/run-bounded-backpressure.py +186 -0
- package/scripts/run-bounded-fixtures/run-bounded-merged-output.py +75 -0
- package/scripts/run-bounded-fixtures/run-bounded-reset-socket.py +25 -0
- package/scripts/run-bounded.py +199 -0
- package/scripts/run_bounded_process.py +129 -0
- package/scripts/worktree/git-index-lock.sh +16 -0
- package/scripts/worktree/git-worktrees.sh +23 -20
- package/scripts/worktree/reset-worktree-run.sh +199 -0
- package/scripts/worktree/reset-worktree.sh +122 -0
- package/skills/blackboard/SKILL.md +4 -64
- package/skills/stacked-prs/SKILL.md +1 -1
- package/skills/stacked-prs/references/drain.md +2 -2
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { isShellRedirectionOperatorToken } from "./shell-redirections.mjs";
|
|
2
|
+
import { isShellAssignment, plainShellAssignment } from "./shell-token-utils.mjs";
|
|
3
|
+
// Reserved words that may open a simple command without choosing which program it runs.
|
|
4
|
+
const SHELL_CONTROL_PREFIXES = new Set([
|
|
5
|
+
'!',
|
|
6
|
+
'{',
|
|
7
|
+
'coproc',
|
|
8
|
+
'do',
|
|
9
|
+
'elif',
|
|
10
|
+
'else',
|
|
11
|
+
'if',
|
|
12
|
+
'then',
|
|
13
|
+
'until',
|
|
14
|
+
'while',
|
|
15
|
+
]);
|
|
16
|
+
// Control prefixes that open a compound command whose first command follows in the same segment.
|
|
17
|
+
const COMPOUND_OPENERS = new Set(['{', 'if', 'until', 'while']);
|
|
18
|
+
/**
|
|
19
|
+
* The only wrappers the hook reads through, by basename, with each option spelling they accept.
|
|
20
|
+
* An `arguments` option takes one argument, attached (`-C/tmp`, `--chdir=/tmp`) or the next word.
|
|
21
|
+
* Any other option (`env -S`, a flag cluster) and every other wrapper (`timeout`, `sudo`, `xargs`)
|
|
22
|
+
* leaves the command word unread.
|
|
23
|
+
*/
|
|
24
|
+
const WRAPPERS = new Map([
|
|
25
|
+
['builtin', { arguments: {}, flags: [] }],
|
|
26
|
+
['command', { arguments: {}, flags: ['-p'] }],
|
|
27
|
+
[
|
|
28
|
+
'env',
|
|
29
|
+
{
|
|
30
|
+
arguments: { '--chdir': 'chdir', '--unset': 'unset', '-C': 'chdir', '-u': 'unset' },
|
|
31
|
+
flags: ['-', '-i', '--ignore-environment'],
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
['exec', { arguments: { '-a': 'other' }, flags: ['-c', '-l'] }],
|
|
35
|
+
['nohup', { arguments: {}, flags: [] }],
|
|
36
|
+
['time', { arguments: {}, flags: ['-p'] }],
|
|
37
|
+
]);
|
|
38
|
+
/**
|
|
39
|
+
* Parses the words between a command segment's start and a command word. Returns null when they
|
|
40
|
+
* are not a recognized wrapper chain, i.e. the command word is an argument rather than the
|
|
41
|
+
* program the shell runs. Wrappers chain in any order (`nohup env -C /tmp gh`) and match by
|
|
42
|
+
* basename (`/usr/bin/env`).
|
|
43
|
+
*/
|
|
44
|
+
export function parseCommandPrefix(prefixWords) {
|
|
45
|
+
const words = withoutRedirections(prefixWords);
|
|
46
|
+
if (words === null)
|
|
47
|
+
return null;
|
|
48
|
+
const read = readCommandPrefix(words);
|
|
49
|
+
return read?.commandIndex === words.length ? read.prefix : null;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Reads the wrapper chain that opens a simple command's words (redirections already removed) and
|
|
53
|
+
* finds the command word it runs. Returns null when a wrapper's options are unrecognized or only
|
|
54
|
+
* describe the command (`command -v gh`).
|
|
55
|
+
*/
|
|
56
|
+
export function readCommandPrefix(words) {
|
|
57
|
+
const prefix = { chdir: [], env: {}, wrappers: [] };
|
|
58
|
+
let controlAllowed = true;
|
|
59
|
+
let cursor = 0;
|
|
60
|
+
while (cursor < words.length) {
|
|
61
|
+
const word = words[cursor];
|
|
62
|
+
if (isShellAssignment(word)) {
|
|
63
|
+
const assignment = plainShellAssignment(word);
|
|
64
|
+
if (assignment !== null)
|
|
65
|
+
prefix.env[assignment.name] = assignment.value;
|
|
66
|
+
cursor += 1;
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
// `function NAME` and bash's `coproc NAME` before a compound command (`coproc m { gh …; }`).
|
|
70
|
+
if (controlAllowed &&
|
|
71
|
+
(word === 'function' || (word === 'coproc' && COMPOUND_OPENERS.has(words[cursor + 2]))) &&
|
|
72
|
+
cursor + 1 < words.length) {
|
|
73
|
+
cursor += 2;
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
if (controlAllowed && SHELL_CONTROL_PREFIXES.has(word)) {
|
|
77
|
+
cursor += 1;
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
const name = word.slice(word.lastIndexOf('/') + 1);
|
|
81
|
+
const grammar = WRAPPERS.get(name);
|
|
82
|
+
if (grammar === undefined)
|
|
83
|
+
return { commandIndex: cursor, prefix };
|
|
84
|
+
cursor = readWrapperOptions(words, cursor + 1, grammar, prefix);
|
|
85
|
+
if (cursor < 0)
|
|
86
|
+
return null;
|
|
87
|
+
prefix.wrappers.push(name);
|
|
88
|
+
// The `time` keyword times a whole pipeline, so `time ! gh` is still a command.
|
|
89
|
+
controlAllowed = name === 'time';
|
|
90
|
+
}
|
|
91
|
+
return { commandIndex: words.length, prefix };
|
|
92
|
+
}
|
|
93
|
+
// The shell applies redirections itself and drops each operator and its target from the argv the
|
|
94
|
+
// command (or wrapper) receives, wherever they appear: `2>/dev/null env -C /tmp gh` runs env with
|
|
95
|
+
// `-C /tmp gh`. A trailing operator's target is the command word, so that word is not a command.
|
|
96
|
+
export function withoutRedirections(words) {
|
|
97
|
+
const argv = [];
|
|
98
|
+
for (let index = 0; index < words.length; index += 1) {
|
|
99
|
+
if (!isShellRedirectionOperatorToken(words[index])) {
|
|
100
|
+
argv.push(words[index]);
|
|
101
|
+
}
|
|
102
|
+
else if (index + 1 === words.length) {
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
index += 1;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return argv;
|
|
110
|
+
}
|
|
111
|
+
// Applies one wrapper's options to `prefix` and returns the index after them (right after `--` or
|
|
112
|
+
// at the first operand), or -1 for an option outside the grammar. GNU and BSD env keep only the
|
|
113
|
+
// last -C, relative to the directory env started in.
|
|
114
|
+
function readWrapperOptions(words, start, grammar, prefix) {
|
|
115
|
+
let chdir;
|
|
116
|
+
let cursor = start;
|
|
117
|
+
while (words[cursor]?.startsWith('-')) {
|
|
118
|
+
const word = words[cursor++];
|
|
119
|
+
if (word === '--')
|
|
120
|
+
break;
|
|
121
|
+
if (grammar.flags.includes(word))
|
|
122
|
+
continue;
|
|
123
|
+
const spelling = Object.keys(grammar.arguments).find((option) => takesOption(word, option));
|
|
124
|
+
const attached = spelling === undefined ? '' : word.slice(spelling.length).replace(/^=/, '');
|
|
125
|
+
const value = attached || words[cursor++];
|
|
126
|
+
if (spelling === undefined || value === undefined)
|
|
127
|
+
return -1;
|
|
128
|
+
if (grammar.arguments[spelling] === 'unset')
|
|
129
|
+
prefix.env[value] = undefined;
|
|
130
|
+
if (grammar.arguments[spelling] === 'chdir')
|
|
131
|
+
chdir = value;
|
|
132
|
+
}
|
|
133
|
+
if (chdir !== undefined)
|
|
134
|
+
prefix.chdir.push(chdir);
|
|
135
|
+
return cursor;
|
|
136
|
+
}
|
|
137
|
+
// A short option takes its argument attached (`-C/tmp`); a long one only after `=` (`--chdir=/tmp`),
|
|
138
|
+
// so `--chdirx` is an unknown option, not `--chdir x`.
|
|
139
|
+
function takesOption(word, option) {
|
|
140
|
+
if (!option.startsWith('--'))
|
|
141
|
+
return word.startsWith(option);
|
|
142
|
+
return word === option || word.startsWith(`${option}=`);
|
|
143
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** Collapse `git -C <path>` / other globals so banned-subcommand regexes still match. */
|
|
2
|
+
export declare function stripGitGlobalOptionsForPolicy(command: string): string;
|
|
3
|
+
/**
|
|
4
|
+
* The scripts the git, hook-bypass, and dev-server policies read: the command text, each heredoc
|
|
5
|
+
* body a shell may read as its script, and each substitution an unquoted-delimiter body runs, each
|
|
6
|
+
* with the `bash -c` scripts nested in it. Any other heredoc body is data (a `git commit -F -`
|
|
7
|
+
* message).
|
|
8
|
+
*
|
|
9
|
+
* Substitutions in the command text itself (`echo $(...)`) are not scanned: callers must also run
|
|
10
|
+
* `extractShellCommandSubstitutions` and inspect each result.
|
|
11
|
+
*/
|
|
12
|
+
export declare function commandsToInspectForGitPolicy(command: string): string[];
|
|
13
|
+
/** The same list with quoted refs readable; it too skips `$(...)` in the command text. */
|
|
14
|
+
export declare function commandsToInspectPreservingQuotes(command: string): string[];
|
|
15
|
+
export type ShellCommandArgument = {
|
|
16
|
+
command: string;
|
|
17
|
+
inheritsEditor: boolean;
|
|
18
|
+
};
|
|
19
|
+
export declare function extractShellCommandArguments(command: string): ShellCommandArgument[];
|
|
20
|
+
export declare function shellCommandInheritsEditor(command: string, shellCommandIndex: number): boolean;
|
|
21
|
+
export declare function isInteractiveRebaseContinue(command: string): boolean;
|
|
22
|
+
export declare function envPrefixSetsEditor(prefix: string): boolean;
|
|
23
|
+
/** Blanks quoted text. It does not look inside `$(...)`; see `extractShellCommandSubstitutions`. */
|
|
24
|
+
export declare function stripQuotedShellText(command: string): string;
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { stripNonShellHeredocBodies } from "./shell-heredoc.mjs";
|
|
2
|
+
import { findShellScriptArguments, shellScriptOperandIndex } from "./shell-script-operand.mjs";
|
|
3
|
+
import { stripUnquotedShellComments, tokenizeShellWords } from "./shell-tokenizer.mjs";
|
|
4
|
+
const GIT_GLOBAL_OPTIONS_RE = new RegExp(String.raw `\bgit(?:\s+(?:` +
|
|
5
|
+
String.raw `-C\s+(?:"[^"]*"|'[^']*'|\S+)|` +
|
|
6
|
+
String.raw `-c\s+(?!["']?[Cc][Oo][Rr][Ee]\.[Hh][Oo][Oo][Kk][Ss][Pp][Aa][Tt][Hh]\b)(?:"[^"]*"|'[^']*'|[^\s=]+(?:=(?:"[^"]*"|'[^']*'|\S+))?)|` +
|
|
7
|
+
String.raw `--(?:git-dir|work-tree|namespace|exec-path)=[^\s]+|` +
|
|
8
|
+
String.raw `--(?:no-pager|paginate|bare|no-replace-objects|version|help|html-path|man-path|info-path)|` +
|
|
9
|
+
String.raw `-[vhpP]` +
|
|
10
|
+
String.raw `))+`, 'g');
|
|
11
|
+
/** Collapse `git -C <path>` / other globals so banned-subcommand regexes still match. */
|
|
12
|
+
export function stripGitGlobalOptionsForPolicy(command) {
|
|
13
|
+
return command.replace(GIT_GLOBAL_OPTIONS_RE, 'git');
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The scripts the git, hook-bypass, and dev-server policies read: the command text, each heredoc
|
|
17
|
+
* body a shell may read as its script, and each substitution an unquoted-delimiter body runs, each
|
|
18
|
+
* with the `bash -c` scripts nested in it. Any other heredoc body is data (a `git commit -F -`
|
|
19
|
+
* message).
|
|
20
|
+
*
|
|
21
|
+
* Substitutions in the command text itself (`echo $(...)`) are not scanned: callers must also run
|
|
22
|
+
* `extractShellCommandSubstitutions` and inspect each result.
|
|
23
|
+
*/
|
|
24
|
+
export function commandsToInspectForGitPolicy(command) {
|
|
25
|
+
return commandsToInspectPreservingQuotes(command).map(stripQuotedShellText);
|
|
26
|
+
}
|
|
27
|
+
/** The same list with quoted refs readable; it too skips `$(...)` in the command text. */
|
|
28
|
+
export function commandsToInspectPreservingQuotes(command) {
|
|
29
|
+
const { bodySubstitutions, shellBodies, textWithoutBodies } = stripNonShellHeredocBodies(command);
|
|
30
|
+
return [textWithoutBodies, ...shellBodies, ...bodySubstitutions].flatMap((script) => {
|
|
31
|
+
const normalizedScript = stripGitGlobalOptionsForPolicy(script.replace(/\\\n/g, ' '));
|
|
32
|
+
return [
|
|
33
|
+
normalizedScript,
|
|
34
|
+
...extractShellCommandArguments(normalizedScript).map(({ command: shellCommand, inheritsEditor }) => `${inheritsEditor ? 'export GIT_EDITOR=true; ' : ''}${stripGitGlobalOptionsForPolicy(shellCommand)}`),
|
|
35
|
+
];
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
export function extractShellCommandArguments(command) {
|
|
39
|
+
const commandWithoutComments = stripUnquotedShellComments(command);
|
|
40
|
+
const quotedScripts = findShellScriptArguments(commandWithoutComments).map(({ script, shellIndex }) => ({
|
|
41
|
+
command: script,
|
|
42
|
+
inheritsEditor: shellCommandInheritsEditor(commandWithoutComments, shellIndex),
|
|
43
|
+
}));
|
|
44
|
+
// The quoted scan also reads a `bash -c '…'` nested inside another command's argument. A script
|
|
45
|
+
// built from several quoted pieces or escapes (`bash -c gh\ pr\ merge`, `"gh pr "merge`) is one
|
|
46
|
+
// shell word only the tokenizer reads, and it never inherits an exported editor.
|
|
47
|
+
const seen = new Set(quotedScripts.map((script) => script.command));
|
|
48
|
+
const words = tokenizeShellWords(commandWithoutComments, { splitRedirections: true });
|
|
49
|
+
const wordScripts = words.flatMap((_word, index) => {
|
|
50
|
+
const operand = shellScriptOperandIndex(words, index);
|
|
51
|
+
if (operand === undefined || seen.has(words[operand]))
|
|
52
|
+
return [];
|
|
53
|
+
seen.add(words[operand]);
|
|
54
|
+
return [{ command: words[operand], inheritsEditor: false }];
|
|
55
|
+
});
|
|
56
|
+
return [...quotedScripts, ...wordScripts];
|
|
57
|
+
}
|
|
58
|
+
export function shellCommandInheritsEditor(command, shellCommandIndex) {
|
|
59
|
+
const segments = command
|
|
60
|
+
.slice(0, shellCommandIndex)
|
|
61
|
+
.split(/[;&|]/)
|
|
62
|
+
.flatMap((segment) => (segment.trim() ? [segment.trim()] : []));
|
|
63
|
+
let exportedEditor = false;
|
|
64
|
+
for (const segment of segments) {
|
|
65
|
+
if (/^unset\s+GIT_EDITOR\b/.test(segment)) {
|
|
66
|
+
exportedEditor = false;
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
if (/^export\s+GIT_EDITOR\s*=\s*(?:"true"|'true'|true)$/.test(segment)) {
|
|
70
|
+
exportedEditor = true;
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
if (/^export\s+GIT_EDITOR\s*=/.test(segment)) {
|
|
74
|
+
exportedEditor = false;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const sameCommandPrefix = segments.at(-1) ?? '';
|
|
78
|
+
return exportedEditor || envPrefixSetsEditor(sameCommandPrefix);
|
|
79
|
+
}
|
|
80
|
+
export function isInteractiveRebaseContinue(command) {
|
|
81
|
+
let exportedEditor = false;
|
|
82
|
+
for (const rawSegment of command.split(/&&|\|\||[;|]/)) {
|
|
83
|
+
const segment = rawSegment.trim();
|
|
84
|
+
if (segment === '') {
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
if (/^unset\s+GIT_EDITOR\b/.test(segment)) {
|
|
88
|
+
exportedEditor = false;
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
if (/^export\s+GIT_EDITOR\s*=\s*true\b/.test(segment)) {
|
|
92
|
+
exportedEditor = true;
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
if (/^export\s+GIT_EDITOR\s*=/.test(segment)) {
|
|
96
|
+
exportedEditor = false;
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
const rebaseMatch = /\bgit\s+rebase\b[^\n;&|()]*--continue\b/.exec(segment);
|
|
100
|
+
if (rebaseMatch === null)
|
|
101
|
+
continue;
|
|
102
|
+
const envPrefix = segment.slice(0, rebaseMatch.index).trim();
|
|
103
|
+
if (rebaseMatch.index === 0 && exportedEditor) {
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
if (envPrefixSetsEditor(envPrefix)) {
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
export function envPrefixSetsEditor(prefix) {
|
|
114
|
+
const tokens = prefix
|
|
115
|
+
.replace(/^env\s+/, '')
|
|
116
|
+
.trim()
|
|
117
|
+
.split(/\s+/)
|
|
118
|
+
.filter(Boolean);
|
|
119
|
+
return (tokens.length > 0 &&
|
|
120
|
+
tokens.every((token) => /^[A-Za-z_][A-Za-z0-9_]*=/.test(token)) &&
|
|
121
|
+
tokens.some((token) => /^GIT_EDITOR=(?:"true"|'true'|true)$/.test(token)));
|
|
122
|
+
}
|
|
123
|
+
/** Blanks quoted text. It does not look inside `$(...)`; see `extractShellCommandSubstitutions`. */
|
|
124
|
+
export function stripQuotedShellText(command) {
|
|
125
|
+
const commandWithSafeEditor = command.replace(/\bGIT_EDITOR\s*=\s*(["'])true\1/g, 'GIT_EDITOR=true');
|
|
126
|
+
let result = '';
|
|
127
|
+
let quote = null;
|
|
128
|
+
let escaping = false;
|
|
129
|
+
for (const char of commandWithSafeEditor) {
|
|
130
|
+
if (escaping) {
|
|
131
|
+
result += quote === null ? char : ' ';
|
|
132
|
+
escaping = false;
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
if (char === '\\' && quote !== "'") {
|
|
136
|
+
result += quote === null ? char : ' ';
|
|
137
|
+
escaping = true;
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
if (quote !== null) {
|
|
141
|
+
if (char === quote) {
|
|
142
|
+
quote = null;
|
|
143
|
+
}
|
|
144
|
+
result += ' ';
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
if (char === "'" || char === '"') {
|
|
148
|
+
quote = char;
|
|
149
|
+
result += ' ';
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
result += char;
|
|
153
|
+
}
|
|
154
|
+
return result;
|
|
155
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export function readHeredocDelimiter(line, startIndex) {
|
|
2
|
+
let value = '';
|
|
3
|
+
let cursor = startIndex;
|
|
4
|
+
let quote = null;
|
|
5
|
+
let quoted = false;
|
|
6
|
+
while (cursor < line.length) {
|
|
7
|
+
const char = line[cursor];
|
|
8
|
+
if (quote === null && /[\s;&|()<>]/.test(char)) {
|
|
9
|
+
break;
|
|
10
|
+
}
|
|
11
|
+
if (quote !== null) {
|
|
12
|
+
if (char === quote) {
|
|
13
|
+
quote = null;
|
|
14
|
+
cursor += 1;
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
if (quote === '"' && char === '\\' && cursor + 1 < line.length) {
|
|
18
|
+
const nextChar = line[cursor + 1];
|
|
19
|
+
if (new Set(['$', '`', '"', '\\']).has(nextChar)) {
|
|
20
|
+
value += nextChar;
|
|
21
|
+
cursor += 2;
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
value += char;
|
|
26
|
+
cursor += 1;
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
if (char === "'" || char === '"') {
|
|
30
|
+
quoted = true;
|
|
31
|
+
quote = char;
|
|
32
|
+
cursor += 1;
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
if (char === '\\') {
|
|
36
|
+
const nextChar = line[cursor + 1];
|
|
37
|
+
if (nextChar === undefined) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
quoted = true;
|
|
41
|
+
value += nextChar;
|
|
42
|
+
cursor += 2;
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
value += char;
|
|
46
|
+
cursor += 1;
|
|
47
|
+
}
|
|
48
|
+
if (value === '' || quote !== null) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
return { value, endIndex: cursor - 1, expandsSubstitutions: !quoted };
|
|
52
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type HeredocLineState } from './shell-heredoc-quote-state.mts';
|
|
2
|
+
export type HeredocSpec = {
|
|
3
|
+
delimiter: string;
|
|
4
|
+
expandsSubstitutions: boolean;
|
|
5
|
+
stripLeadingTabs: boolean;
|
|
6
|
+
};
|
|
7
|
+
export declare function heredocSpecsFromLine(line: string, carried?: HeredocLineState): HeredocSpec[];
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { readHeredocDelimiter } from "./shell-heredoc-delimiter.mjs";
|
|
2
|
+
import { newHeredocLineState, stepHeredocQuoteState, } from "./shell-heredoc-quote-state.mjs";
|
|
3
|
+
export function heredocSpecsFromLine(line, carried) {
|
|
4
|
+
const specs = [];
|
|
5
|
+
const state = carried ?? newHeredocLineState();
|
|
6
|
+
let escaping = false;
|
|
7
|
+
for (let index = 0; index < line.length; index += 1) {
|
|
8
|
+
const char = line[index];
|
|
9
|
+
if (escaping) {
|
|
10
|
+
escaping = false;
|
|
11
|
+
continue;
|
|
12
|
+
}
|
|
13
|
+
if (char === '\\' && state.quote !== "'") {
|
|
14
|
+
escaping = true;
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
const consumed = stepHeredocQuoteState(state, char, line[index + 1]);
|
|
18
|
+
if (consumed !== undefined) {
|
|
19
|
+
index += consumed;
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
if (char === '#' && (index === 0 || /[\s;&|()]/.test(line[index - 1]))) {
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
if (char !== '<' || line[index + 1] !== '<') {
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
// `<<<` opens a here-string, whose word ends on this line: no body follows.
|
|
29
|
+
if (line[index + 2] === '<') {
|
|
30
|
+
index += 2;
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
const stripLeadingTabs = line[index + 2] === '-';
|
|
34
|
+
let cursor = index + (stripLeadingTabs ? 3 : 2);
|
|
35
|
+
while (cursor < line.length && /\s/.test(line[cursor])) {
|
|
36
|
+
cursor += 1;
|
|
37
|
+
}
|
|
38
|
+
const delimiter = readHeredocDelimiter(line, cursor);
|
|
39
|
+
if (delimiter !== null) {
|
|
40
|
+
specs.push({
|
|
41
|
+
delimiter: delimiter.value,
|
|
42
|
+
expandsSubstitutions: delimiter.expandsSubstitutions,
|
|
43
|
+
stripLeadingTabs,
|
|
44
|
+
});
|
|
45
|
+
index = delimiter.endIndex;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return specs;
|
|
49
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
type Quote = "'" | '"' | null;
|
|
2
|
+
/** A `$(` still open: the quote state to restore at its `)` and the plain `(` opened inside it. */
|
|
3
|
+
type Substitution = {
|
|
4
|
+
parens: number;
|
|
5
|
+
restore: Quote;
|
|
6
|
+
};
|
|
7
|
+
/** The quote and `$(` nesting a line ends in, carried into the next line of one command. */
|
|
8
|
+
export type HeredocLineState = {
|
|
9
|
+
quote: Quote;
|
|
10
|
+
substitutions: Substitution[];
|
|
11
|
+
};
|
|
12
|
+
export declare function newHeredocLineState(): HeredocLineState;
|
|
13
|
+
/**
|
|
14
|
+
* Advances `state` over `char` (`next` follows it) and returns how many extra characters it
|
|
15
|
+
* consumed, or undefined when `char` is plain text the caller still has to read. A `$(` saves the
|
|
16
|
+
* quote it opened in, so the matching `)` restores that quote rather than leaving it unquoted.
|
|
17
|
+
*/
|
|
18
|
+
export declare function stepHeredocQuoteState(state: HeredocLineState, char: string, next: string | undefined): number | undefined;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export function newHeredocLineState() {
|
|
2
|
+
return { quote: null, substitutions: [] };
|
|
3
|
+
}
|
|
4
|
+
/**
|
|
5
|
+
* Advances `state` over `char` (`next` follows it) and returns how many extra characters it
|
|
6
|
+
* consumed, or undefined when `char` is plain text the caller still has to read. A `$(` saves the
|
|
7
|
+
* quote it opened in, so the matching `)` restores that quote rather than leaving it unquoted.
|
|
8
|
+
*/
|
|
9
|
+
export function stepHeredocQuoteState(state, char, next) {
|
|
10
|
+
if (state.quote === "'" || (state.quote === '"' && char !== '$')) {
|
|
11
|
+
if (char === state.quote)
|
|
12
|
+
state.quote = null;
|
|
13
|
+
return 0;
|
|
14
|
+
}
|
|
15
|
+
if (char === '$' && next === '(') {
|
|
16
|
+
state.substitutions.push({ parens: 0, restore: state.quote });
|
|
17
|
+
state.quote = null;
|
|
18
|
+
return 1;
|
|
19
|
+
}
|
|
20
|
+
if (state.quote !== null) {
|
|
21
|
+
if (char === state.quote)
|
|
22
|
+
state.quote = null;
|
|
23
|
+
return 0;
|
|
24
|
+
}
|
|
25
|
+
const open = state.substitutions.at(-1);
|
|
26
|
+
if (open !== undefined && (char === '(' || char === ')')) {
|
|
27
|
+
if (char === '(')
|
|
28
|
+
open.parens += 1;
|
|
29
|
+
else if (open.parens > 0)
|
|
30
|
+
open.parens -= 1;
|
|
31
|
+
else
|
|
32
|
+
state.quote = state.substitutions.pop().restore;
|
|
33
|
+
return 0;
|
|
34
|
+
}
|
|
35
|
+
if (char === "'" || char === '"') {
|
|
36
|
+
state.quote = char;
|
|
37
|
+
return 0;
|
|
38
|
+
}
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
type HeredocScan = {
|
|
2
|
+
/** The command substitutions heredoc bodies with an unquoted delimiter run. */
|
|
3
|
+
bodySubstitutions: string[];
|
|
4
|
+
/** Heredoc bodies and here-strings a shell may read as its script. */
|
|
5
|
+
shellBodies: string[];
|
|
6
|
+
/** The command with every heredoc body line blanked, so no body line reads as a command. */
|
|
7
|
+
textWithoutBodies: string;
|
|
8
|
+
};
|
|
9
|
+
export declare function stripNonShellHeredocBodies(command: string): HeredocScan;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { readBacktickSubstitution, readParenthesizedSubstitution, } from "./shell-command-substitutions.mjs";
|
|
2
|
+
import { heredocSpecsFromLine } from "./shell-heredoc-parser.mjs";
|
|
3
|
+
import { newHeredocLineState } from "./shell-heredoc-quote-state.mjs";
|
|
4
|
+
import { redirectionOperatorOf } from "./shell-redirections.mjs";
|
|
5
|
+
import { shellReadsStdinAt } from "./shell-stdin-script.mjs";
|
|
6
|
+
import { tokenizeShellWords } from "./shell-tokenizer.mjs";
|
|
7
|
+
const HEREDOC_OPERATORS = new Set(['<<', '<<-']);
|
|
8
|
+
export function stripNonShellHeredocBodies(command) {
|
|
9
|
+
const lines = command.split('\n');
|
|
10
|
+
const textLines = [];
|
|
11
|
+
const bodySubstitutions = [];
|
|
12
|
+
const shellBodies = [];
|
|
13
|
+
const carried = newHeredocLineState();
|
|
14
|
+
for (let index = 0; index < lines.length; index += 1) {
|
|
15
|
+
const line = lines[index];
|
|
16
|
+
const specs = heredocSpecsFromLine(line, carried);
|
|
17
|
+
textLines.push(line);
|
|
18
|
+
if (specs.length === 0) {
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
// The hook does not pair each operator with its body, so a line with a shell-read heredoc
|
|
22
|
+
// inspects every body on it.
|
|
23
|
+
const isShellScriptHeredoc = lineFeedsShellHeredoc(line);
|
|
24
|
+
for (const spec of specs) {
|
|
25
|
+
const bodyLines = [];
|
|
26
|
+
index += 1;
|
|
27
|
+
while (index < lines.length && heredocLineDelimiter(lines[index], spec) !== spec.delimiter) {
|
|
28
|
+
bodyLines.push(lines[index]);
|
|
29
|
+
textLines.push('');
|
|
30
|
+
index += 1;
|
|
31
|
+
}
|
|
32
|
+
if (index < lines.length) {
|
|
33
|
+
textLines.push(lines[index]);
|
|
34
|
+
}
|
|
35
|
+
if (isShellScriptHeredoc) {
|
|
36
|
+
shellBodies.push(bodyLines.join('\n'));
|
|
37
|
+
}
|
|
38
|
+
if (spec.expandsSubstitutions) {
|
|
39
|
+
bodySubstitutions.push(...heredocBodySubstitutions(bodyLines.join('\n')));
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const textWithoutBodies = textLines.join('\n');
|
|
44
|
+
return {
|
|
45
|
+
bodySubstitutions,
|
|
46
|
+
shellBodies: [...shellBodies, ...shellHereStrings(textWithoutBodies)],
|
|
47
|
+
textWithoutBodies,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
// `bash <<< 'gh pr merge 1'` and `cat <<< '…' | sh` read the here-string as the script, as they
|
|
51
|
+
// would a heredoc body.
|
|
52
|
+
function shellHereStrings(command) {
|
|
53
|
+
const tokens = tokenizeShellWords(command, { splitRedirections: true });
|
|
54
|
+
return tokens.flatMap((token, index) => redirectionOperatorOf(token) === '<<<' &&
|
|
55
|
+
index + 1 < tokens.length &&
|
|
56
|
+
shellReadsStdinAt(tokens, index)
|
|
57
|
+
? [tokens[index + 1]]
|
|
58
|
+
: []);
|
|
59
|
+
}
|
|
60
|
+
// Quotes and `#` are literal text in a heredoc body; a backslash escapes only `$`, a backtick,
|
|
61
|
+
// or another backslash.
|
|
62
|
+
function heredocBodySubstitutions(body) {
|
|
63
|
+
const substitutions = [];
|
|
64
|
+
for (let index = 0; index < body.length; index += 1) {
|
|
65
|
+
const char = body[index];
|
|
66
|
+
if (char === '\\') {
|
|
67
|
+
index += 1;
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
const substitution = char === '$' && body[index + 1] === '('
|
|
71
|
+
? readParenthesizedSubstitution(body, index + 2)
|
|
72
|
+
: char === '`'
|
|
73
|
+
? readBacktickSubstitution(body, index + 1)
|
|
74
|
+
: null;
|
|
75
|
+
if (substitution !== null) {
|
|
76
|
+
substitutions.push(substitution.command);
|
|
77
|
+
index = substitution.endIndex;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return substitutions;
|
|
81
|
+
}
|
|
82
|
+
function heredocLineDelimiter(line, spec) {
|
|
83
|
+
return spec.stripLeadingTabs ? line.replace(/^\t+/, '') : line;
|
|
84
|
+
}
|
|
85
|
+
// The tokenizer keeps a heredoc operator inside a double-quoted `"$(… <<'EOF'` in the quoted word,
|
|
86
|
+
// so that body stays data (`git commit -m "$(cat <<'EOF'`) even when a shell reads it.
|
|
87
|
+
function lineFeedsShellHeredoc(line) {
|
|
88
|
+
const tokens = tokenizeShellWords(line, { splitRedirections: true });
|
|
89
|
+
return tokens.some((token, index) => HEREDOC_OPERATORS.has(redirectionOperatorOf(token)) && shellReadsStdinAt(tokens, index));
|
|
90
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const SHELL_REDIRECTION_OPERATORS: readonly ["&>>", "<<<", "<<-", "&>", ">>", ">&", ">|", "<<", "<&", "<>", ">", "<"];
|
|
2
|
+
export declare function shellRedirectionOperatorAt(command: string, index: number): string | null;
|
|
3
|
+
export declare function isRedirectionFd(word: string): boolean;
|
|
4
|
+
export declare function redirectionOperatorOf(token: string): string;
|
|
5
|
+
export declare function isShellRedirectionOperatorToken(token: string): boolean;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export const SHELL_REDIRECTION_OPERATORS = [
|
|
2
|
+
'&>>',
|
|
3
|
+
'<<<',
|
|
4
|
+
'<<-',
|
|
5
|
+
'&>',
|
|
6
|
+
'>>',
|
|
7
|
+
'>&',
|
|
8
|
+
'>|',
|
|
9
|
+
'<<',
|
|
10
|
+
'<&',
|
|
11
|
+
'<>',
|
|
12
|
+
'>',
|
|
13
|
+
'<',
|
|
14
|
+
];
|
|
15
|
+
export function shellRedirectionOperatorAt(command, index) {
|
|
16
|
+
const suffix = command.slice(index);
|
|
17
|
+
return SHELL_REDIRECTION_OPERATORS.find((operator) => suffix.startsWith(operator)) ?? null;
|
|
18
|
+
}
|
|
19
|
+
// A file descriptor written right before an operator: a number (`2>`) or a bash/zsh `{name}` that
|
|
20
|
+
// the shell assigns a free descriptor to (`{fd}>out`).
|
|
21
|
+
const REDIRECTION_FD = String.raw `(?:\d+|\{[A-Za-z_][A-Za-z0-9_]*\})`;
|
|
22
|
+
const REDIRECTION_FD_PREFIX = new RegExp(`^${REDIRECTION_FD}`);
|
|
23
|
+
const REDIRECTION_FD_WORD = new RegExp(`^${REDIRECTION_FD}$`);
|
|
24
|
+
export function isRedirectionFd(word) {
|
|
25
|
+
return REDIRECTION_FD_WORD.test(word);
|
|
26
|
+
}
|
|
27
|
+
// tokenizeShellWords({splitRedirections:true}) fuses a leading file descriptor into the operator
|
|
28
|
+
// token itself (e.g. `2>` for `gh pr merge 123 2> --auto`) — strip it before matching.
|
|
29
|
+
export function redirectionOperatorOf(token) {
|
|
30
|
+
return token.replace(REDIRECTION_FD_PREFIX, '');
|
|
31
|
+
}
|
|
32
|
+
export function isShellRedirectionOperatorToken(token) {
|
|
33
|
+
return SHELL_REDIRECTION_OPERATORS.includes(redirectionOperatorOf(token));
|
|
34
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Whether a command word runs bash, sh, or zsh, by any path. */
|
|
2
|
+
export declare function isShellWord(word: string): boolean;
|
|
3
|
+
/** The index of the script a `bash` / `sh` / `zsh -c` word at `index` runs, if it runs one. */
|
|
4
|
+
export declare function shellScriptOperandIndex(words: readonly string[], index: number): number | undefined;
|
|
5
|
+
export type ShellScriptArgument = {
|
|
6
|
+
script: string;
|
|
7
|
+
shellIndex: number;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* The quoted or ANSI-C quoted scripts that `bash` / `sh` / `zsh -c` run in raw command text, each
|
|
11
|
+
* with the index where its shell word's match starts.
|
|
12
|
+
*/
|
|
13
|
+
export declare function findShellScriptArguments(command: string): ShellScriptArgument[];
|