vouchington-tooling 0.53.0 → 0.55.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.
Files changed (197) hide show
  1. package/README.md +99 -12
  2. package/dist/agent-blackboard/index.d.mts +0 -1
  3. package/dist/agent-blackboard/index.mjs +0 -23
  4. package/dist/cli/commands/agent-blackboard-flags.d.mts +0 -1
  5. package/dist/cli/commands/agent-blackboard-flags.mjs +0 -9
  6. package/dist/cli/commands/agent-blackboard.d.mts +0 -2
  7. package/dist/cli/commands/agent-blackboard.mjs +7 -121
  8. package/dist/cli/commands/story-coverage.d.mts +2 -0
  9. package/dist/cli/commands/story-coverage.mjs +56 -0
  10. package/dist/cli/index.mjs +6 -0
  11. package/dist/cli/optional-peer.d.mts +5 -0
  12. package/dist/cli/optional-peer.mjs +17 -0
  13. package/dist/cli/parse-forwarded-commands.d.mts +3 -0
  14. package/dist/cli/parse-forwarded-commands.mjs +2 -0
  15. package/dist/cli/parse-story-coverage-fields.d.mts +19 -0
  16. package/dist/cli/parse-story-coverage-fields.mjs +69 -0
  17. package/dist/cli/parse-story-coverage.d.mts +8 -0
  18. package/dist/cli/parse-story-coverage.mjs +34 -0
  19. package/dist/cli/parse.d.mts +5 -1
  20. package/dist/cli/parse.mjs +3 -0
  21. package/dist/cli/story-coverage-lazy.d.mts +3 -0
  22. package/dist/cli/story-coverage-lazy.mjs +6 -0
  23. package/dist/cli/usage.d.mts +1 -1
  24. package/dist/cli/usage.mjs +8 -7
  25. package/dist/host-storage/check.d.mts +38 -0
  26. package/dist/host-storage/check.mjs +109 -0
  27. package/dist/host-storage/cli.d.mts +7 -0
  28. package/dist/host-storage/cli.mjs +102 -0
  29. package/dist/host-storage/host-storage.test-helpers.d.mts +26 -0
  30. package/dist/host-storage/host-storage.test-helpers.mjs +58 -0
  31. package/dist/host-storage/index.d.mts +3 -0
  32. package/dist/host-storage/index.mjs +3 -0
  33. package/dist/host-storage/preflight.d.mts +22 -0
  34. package/dist/host-storage/preflight.mjs +105 -0
  35. package/dist/index.d.mts +2 -0
  36. package/dist/index.mjs +1 -0
  37. package/dist/playwright/assertions.d.mts +1 -0
  38. package/dist/playwright/assertions.mjs +5 -0
  39. package/dist/playwright/blocked-external-network.d.mts +15 -0
  40. package/dist/playwright/blocked-external-network.mjs +73 -0
  41. package/dist/playwright/browser-dialog-issues.d.mts +12 -0
  42. package/dist/playwright/browser-dialog-issues.mjs +29 -0
  43. package/dist/playwright/browser-errors.d.mts +23 -0
  44. package/dist/playwright/browser-errors.mjs +130 -0
  45. package/dist/playwright/browser-issue-monitor.test-helpers.d.mts +31 -0
  46. package/dist/playwright/browser-issue-monitor.test-helpers.mjs +51 -0
  47. package/dist/playwright/browser-issue-records.d.mts +42 -0
  48. package/dist/playwright/browser-issue-records.mjs +148 -0
  49. package/dist/playwright/browser-test.d.mts +22 -0
  50. package/dist/playwright/browser-test.mjs +68 -0
  51. package/dist/playwright/expect-no-broken-images.d.mts +17 -0
  52. package/dist/playwright/expect-no-broken-images.mjs +39 -0
  53. package/dist/playwright/index.d.mts +32 -0
  54. package/dist/playwright/index.mjs +22 -0
  55. package/dist/playwright/mobile-assertions.d.mts +14 -0
  56. package/dist/playwright/mobile-assertions.mjs +43 -0
  57. package/dist/playwright/monitored-test-info.d.mts +14 -0
  58. package/dist/playwright/monitored-test-info.mjs +1 -0
  59. package/dist/playwright/navigate-to.d.mts +27 -0
  60. package/dist/playwright/navigate-to.mjs +39 -0
  61. package/dist/playwright/radix-select.d.mts +18 -0
  62. package/dist/playwright/radix-select.mjs +19 -0
  63. package/dist/playwright/random-id.d.mts +34 -0
  64. package/dist/playwright/random-id.mjs +37 -0
  65. package/dist/playwright/retry-on-connection-lost.d.mts +7 -0
  66. package/dist/playwright/retry-on-connection-lost.mjs +107 -0
  67. package/dist/playwright/scroll-to-load-more.d.mts +37 -0
  68. package/dist/playwright/scroll-to-load-more.mjs +158 -0
  69. package/dist/playwright/storybook.d.mts +2 -0
  70. package/dist/playwright/storybook.mjs +13 -0
  71. package/dist/playwright/test-fixtures.d.mts +1 -0
  72. package/dist/playwright/test-fixtures.mjs +2 -0
  73. package/dist/playwright/test-lifecycle-reporter.d.mts +27 -0
  74. package/dist/playwright/test-lifecycle-reporter.mjs +57 -0
  75. package/dist/playwright/totp.d.mts +6 -0
  76. package/dist/playwright/totp.mjs +37 -0
  77. package/dist/playwright/turnstile-stub.d.mts +8 -0
  78. package/dist/playwright/turnstile-stub.mjs +61 -0
  79. package/dist/playwright/viewport-constants.d.mts +30 -0
  80. package/dist/playwright/viewport-constants.mjs +9 -0
  81. package/dist/playwright/virtual-authenticator.d.mts +5 -0
  82. package/dist/playwright/virtual-authenticator.mjs +15 -0
  83. package/dist/playwright/wait-for-hydration.d.mts +29 -0
  84. package/dist/playwright/wait-for-hydration.mjs +81 -0
  85. package/dist/shell-parse/ansi-c-string.d.mts +12 -0
  86. package/dist/shell-parse/ansi-c-string.mjs +80 -0
  87. package/dist/shell-parse/index.d.mts +20 -0
  88. package/dist/shell-parse/index.mjs +15 -0
  89. package/dist/shell-parse/shell-command-substitution-reads.d.mts +8 -0
  90. package/dist/shell-parse/shell-command-substitution-reads.mjs +53 -0
  91. package/dist/shell-parse/shell-command-substitutions.d.mts +8 -0
  92. package/dist/shell-parse/shell-command-substitutions.mjs +52 -0
  93. package/dist/shell-parse/shell-command-wrappers.d.mts +26 -0
  94. package/dist/shell-parse/shell-command-wrappers.mjs +143 -0
  95. package/dist/shell-parse/shell-commands.d.mts +24 -0
  96. package/dist/shell-parse/shell-commands.mjs +155 -0
  97. package/dist/shell-parse/shell-heredoc-delimiter.d.mts +5 -0
  98. package/dist/shell-parse/shell-heredoc-delimiter.mjs +52 -0
  99. package/dist/shell-parse/shell-heredoc-parser.d.mts +7 -0
  100. package/dist/shell-parse/shell-heredoc-parser.mjs +49 -0
  101. package/dist/shell-parse/shell-heredoc-quote-state.d.mts +19 -0
  102. package/dist/shell-parse/shell-heredoc-quote-state.mjs +40 -0
  103. package/dist/shell-parse/shell-heredoc.d.mts +10 -0
  104. package/dist/shell-parse/shell-heredoc.mjs +90 -0
  105. package/dist/shell-parse/shell-redirections.d.mts +5 -0
  106. package/dist/shell-parse/shell-redirections.mjs +34 -0
  107. package/dist/shell-parse/shell-script-operand.d.mts +13 -0
  108. package/dist/shell-parse/shell-script-operand.mjs +103 -0
  109. package/dist/shell-parse/shell-stdin-script.d.mts +6 -0
  110. package/dist/shell-parse/shell-stdin-script.mjs +61 -0
  111. package/dist/shell-parse/shell-token-utils.d.mts +9 -0
  112. package/dist/shell-parse/shell-token-utils.mjs +33 -0
  113. package/dist/shell-parse/shell-tokenizer-comments.d.mts +1 -0
  114. package/dist/shell-parse/shell-tokenizer-comments.mjs +57 -0
  115. package/dist/shell-parse/shell-tokenizer-operators.d.mts +14 -0
  116. package/dist/shell-parse/shell-tokenizer-operators.mjs +47 -0
  117. package/dist/shell-parse/shell-tokenizer.d.mts +12 -0
  118. package/dist/shell-parse/shell-tokenizer.mjs +104 -0
  119. package/dist/story-coverage/analyze.d.mts +8 -0
  120. package/dist/story-coverage/analyze.mjs +24 -0
  121. package/dist/story-coverage/check.d.mts +11 -0
  122. package/dist/story-coverage/check.mjs +42 -0
  123. package/dist/story-coverage/components.d.mts +10 -0
  124. package/dist/story-coverage/components.mjs +40 -0
  125. package/dist/story-coverage/coverage.d.mts +10 -0
  126. package/dist/story-coverage/coverage.mjs +43 -0
  127. package/dist/story-coverage/index.d.mts +13 -0
  128. package/dist/story-coverage/index.mjs +7 -0
  129. package/dist/story-coverage/messages.d.mts +10 -0
  130. package/dist/story-coverage/messages.mjs +42 -0
  131. package/dist/story-coverage/options.d.mts +27 -0
  132. package/dist/story-coverage/options.mjs +51 -0
  133. package/dist/story-coverage/workspace.d.mts +2 -0
  134. package/dist/story-coverage/workspace.mjs +27 -0
  135. package/dist/test-helpers/cancel-runs.test-helpers.d.mts +39 -0
  136. package/dist/test-helpers/cancel-runs.test-helpers.mjs +124 -0
  137. package/dist/test-helpers/run-bounded-exit-observer.test-helpers.d.mts +12 -0
  138. package/dist/test-helpers/run-bounded-exit-observer.test-helpers.mjs +68 -0
  139. package/dist/test-helpers/run-bounded-output-fixture.test-helpers.d.mts +18 -0
  140. package/dist/test-helpers/run-bounded-output-fixture.test-helpers.mjs +162 -0
  141. package/dist/vitest-diagnostics/browser.d.mts +2 -0
  142. package/dist/vitest-diagnostics/browser.mjs +6 -0
  143. package/dist/vitest-diagnostics/index.d.mts +14 -23
  144. package/dist/vitest-diagnostics/index.mjs +8 -124
  145. package/dist/vitest-diagnostics/report-summary.d.mts +22 -0
  146. package/dist/vitest-diagnostics/report-summary.mjs +123 -0
  147. package/dist/vitest-diagnostics/vitest-fake-timer-guard.d.mts +6 -0
  148. package/dist/vitest-diagnostics/vitest-fake-timer-guard.mjs +34 -0
  149. package/dist/vitest-diagnostics/vitest-fork-leak-detection.d.mts +1 -0
  150. package/dist/vitest-diagnostics/vitest-fork-leak-detection.mjs +8 -0
  151. package/dist/vitest-diagnostics/vitest-fork-leak-diagnostics.d.mts +17 -1
  152. package/dist/vitest-diagnostics/vitest-fork-leak-diagnostics.mjs +44 -2
  153. package/dist/vitest-diagnostics/vitest-fork-leak-handshake-samples.d.mts +55 -0
  154. package/dist/vitest-diagnostics/vitest-fork-leak-handshake-samples.mjs +74 -0
  155. package/dist/vitest-diagnostics/vitest-fork-leak-handshake.d.mts +19 -0
  156. package/dist/vitest-diagnostics/vitest-fork-leak-handshake.mjs +136 -0
  157. package/dist/vitest-diagnostics/vitest-network-allowlist-dns.d.mts +7 -0
  158. package/dist/vitest-diagnostics/vitest-network-allowlist-dns.mjs +54 -0
  159. package/dist/vitest-diagnostics/vitest-network-allowlist-host.d.mts +8 -0
  160. package/dist/vitest-diagnostics/vitest-network-allowlist-host.mjs +48 -0
  161. package/dist/vitest-diagnostics/vitest-network-allowlist-socket.d.mts +14 -0
  162. package/dist/vitest-diagnostics/vitest-network-allowlist-socket.mjs +39 -0
  163. package/dist/vitest-diagnostics/vitest-network-allowlist.d.mts +7 -0
  164. package/dist/vitest-diagnostics/vitest-network-allowlist.mjs +72 -0
  165. package/dist/vitest-diagnostics/vitest-process-resources.d.mts +10 -0
  166. package/dist/vitest-diagnostics/vitest-process-resources.mjs +54 -0
  167. package/dist/vitest-effective-timeout/cap.d.mts +9 -0
  168. package/dist/vitest-effective-timeout/cap.mjs +28 -0
  169. package/dist/vitest-effective-timeout/check-profiles.d.mts +15 -0
  170. package/dist/vitest-effective-timeout/check-profiles.mjs +52 -0
  171. package/dist/vitest-effective-timeout/config-file.d.mts +6 -0
  172. package/dist/vitest-effective-timeout/config-file.mjs +23 -0
  173. package/dist/vitest-effective-timeout/fixtures.d.mts +2 -0
  174. package/dist/vitest-effective-timeout/fixtures.mjs +18 -0
  175. package/dist/vitest-effective-timeout/index.d.mts +7 -0
  176. package/dist/vitest-effective-timeout/index.mjs +4 -0
  177. package/dist/vitest-effective-timeout/profiles.d.mts +10 -0
  178. package/dist/vitest-effective-timeout/profiles.mjs +33 -0
  179. package/dist/vitest-effective-timeout/run-profile.d.mts +31 -0
  180. package/dist/vitest-effective-timeout/run-profile.mjs +95 -0
  181. package/docs/mcp-server.md +2 -13
  182. package/package.json +37 -2
  183. package/scripts/__pycache__/run_bounded_process.cpython-312.pyc +0 -0
  184. package/scripts/chromium-launch-probe.d.mts +7 -0
  185. package/scripts/chromium-launch-probe.mjs +101 -0
  186. package/scripts/run-bounded-fixtures/run-bounded-backpressure.py +186 -0
  187. package/scripts/run-bounded-fixtures/run-bounded-merged-output.py +75 -0
  188. package/scripts/run-bounded-fixtures/run-bounded-reset-socket.py +25 -0
  189. package/scripts/run-bounded.py +199 -0
  190. package/scripts/run_bounded_process.py +129 -0
  191. package/scripts/worktree/git-index-lock.sh +16 -0
  192. package/scripts/worktree/git-worktrees.sh +23 -20
  193. package/scripts/worktree/reset-worktree-run.sh +199 -0
  194. package/scripts/worktree/reset-worktree.sh +122 -0
  195. package/skills/blackboard/SKILL.md +4 -64
  196. package/skills/stacked-prs/SKILL.md +1 -1
  197. package/skills/stacked-prs/references/drain.md +2 -2
@@ -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,5 @@
1
+ export declare function readHeredocDelimiter(line: string, startIndex: number): {
2
+ value: string;
3
+ endIndex: number;
4
+ expandsSubstitutions: boolean;
5
+ } | null;
@@ -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[];
@@ -0,0 +1,103 @@
1
+ import { readAnsiCString } from "./ansi-c-string.mjs";
2
+ // Every shell that reads a script from stdin or `-c`. `busybox` and `toybox` run `sh` / `ash` as an
3
+ // applet, so `segmentMayRunStdin` fails closed on them rather than parsing the applet name.
4
+ const SHELLS = new Set(['ash', 'bash', 'csh', 'dash', 'fish', 'ksh', 'mksh', 'sh', 'tcsh', 'zsh']);
5
+ // Long options that take the next word: bash `--rcfile FILE` / `--init-file FILE`, zsh
6
+ // `--emulate NAME`. Listing an extra name only makes a malformed invocation look scriptless.
7
+ const LONG_OPTIONS_WITH_ARGUMENT = new Set(['emulate', 'init-file', 'rcfile']);
8
+ const SHELL_WORD = /(?:^|[\s;&|()])(?:\S*\/)?(?:ash|bash|csh|dash|fish|ksh|mksh|sh|tcsh|zsh)(?=\s)/g;
9
+ const NEXT_WORD = /\s*(\S+)/y;
10
+ // A backslash is literal inside single quotes. Inside double quotes it escapes one character, and
11
+ // the two branches start with different characters so a run of backslashes has one reading.
12
+ const SINGLE_QUOTED_SCRIPT = /'([^']*)'/y;
13
+ const DOUBLE_QUOTED_SCRIPT = /"((?:\\[\s\S]|[^"\\])*)"/y;
14
+ /**
15
+ * How bash, sh, and zsh read one word before their first operand. `--` and `-` end the options.
16
+ * Each `o` / `O` letter in a `-` or `+` cluster consumes the next word (`-euo pipefail`,
17
+ * `+O extglob`), and a `c` letter in a `-` cluster makes the first operand the script.
18
+ */
19
+ function readShellOption(word) {
20
+ if (word === '--' || word === '-')
21
+ return 'end';
22
+ if (/^[-+][A-Za-z]+$/.test(word)) {
23
+ return {
24
+ argumentWords: word.replace(/[^oO]/g, '').length,
25
+ runsScript: word.startsWith('-') && word.includes('c'),
26
+ };
27
+ }
28
+ if (/^--[A-Za-z]/.test(word)) {
29
+ return {
30
+ argumentWords: LONG_OPTIONS_WITH_ARGUMENT.has(word.slice(2)) ? 1 : 0,
31
+ runsScript: false,
32
+ };
33
+ }
34
+ return 'operand';
35
+ }
36
+ /** Whether a command word runs bash, sh, or zsh, by any path. */
37
+ export function isShellWord(word) {
38
+ return SHELLS.has(word.slice(word.lastIndexOf('/') + 1));
39
+ }
40
+ /** The index of the script a `bash` / `sh` / `zsh -c` word at `index` runs, if it runs one. */
41
+ export function shellScriptOperandIndex(words, index) {
42
+ if (!isShellWord(words[index]))
43
+ return undefined;
44
+ let runsScript = false;
45
+ let cursor = index + 1;
46
+ while (cursor < words.length) {
47
+ const option = readShellOption(words[cursor]);
48
+ if (option === 'operand')
49
+ break;
50
+ cursor += 1;
51
+ if (option === 'end')
52
+ break;
53
+ runsScript ||= option.runsScript;
54
+ cursor += option.argumentWords;
55
+ }
56
+ return runsScript && cursor < words.length ? cursor : undefined;
57
+ }
58
+ /**
59
+ * The quoted or ANSI-C quoted scripts that `bash` / `sh` / `zsh -c` run in raw command text, each
60
+ * with the index where its shell word's match starts.
61
+ */
62
+ export function findShellScriptArguments(command) {
63
+ const scripts = [];
64
+ for (const match of command.matchAll(SHELL_WORD)) {
65
+ const start = scriptStart(command, match.index + match[0].length);
66
+ const script = start === undefined ? undefined : readQuotedScript(command, start);
67
+ if (script !== undefined)
68
+ scripts.push({ script, shellIndex: match.index });
69
+ }
70
+ return scripts;
71
+ }
72
+ function scriptStart(command, position) {
73
+ let runsScript = false;
74
+ let optionsEnded = false;
75
+ let pendingArguments = 0;
76
+ NEXT_WORD.lastIndex = position;
77
+ for (let match = NEXT_WORD.exec(command); match !== null; match = NEXT_WORD.exec(command)) {
78
+ if (pendingArguments > 0) {
79
+ pendingArguments -= 1;
80
+ continue;
81
+ }
82
+ const option = optionsEnded ? 'operand' : readShellOption(match[1]);
83
+ if (option === 'operand')
84
+ return runsScript ? NEXT_WORD.lastIndex - match[1].length : undefined;
85
+ if (option === 'end') {
86
+ optionsEnded = true;
87
+ continue;
88
+ }
89
+ runsScript ||= option.runsScript;
90
+ pendingArguments = option.argumentWords;
91
+ }
92
+ return undefined;
93
+ }
94
+ function readQuotedScript(command, start) {
95
+ if (command.startsWith("$'", start))
96
+ return readAnsiCString(command, start + 2)?.value;
97
+ if (command[start] === "'") {
98
+ SINGLE_QUOTED_SCRIPT.lastIndex = start;
99
+ return SINGLE_QUOTED_SCRIPT.exec(command)?.[1];
100
+ }
101
+ DOUBLE_QUOTED_SCRIPT.lastIndex = start;
102
+ return DOUBLE_QUOTED_SCRIPT.exec(command)?.[1]?.replace(/\\([$`"\\\n])/g, '$1');
103
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Whether a shell may read the stdin redirection (heredoc or here-string) at `operatorIndex` of
3
+ * `tokens` (tokenized with `splitRedirections`) as its script: the redirected command, or any later
4
+ * stage of its pipeline, is one the hook cannot rule out as a scriptless shell.
5
+ */
6
+ export declare function shellReadsStdinAt(tokens: string[], operatorIndex: number): boolean;
@@ -0,0 +1,61 @@
1
+ import { readCommandPrefix, withoutRedirections } from "./shell-command-wrappers.mjs";
2
+ import { isShellWord, shellScriptOperandIndex } from "./shell-script-operand.mjs";
3
+ import { commandSegmentStart, nextShellCommandSeparatorIndex } from "./shell-token-utils.mjs";
4
+ // Words that close a compound command. Its redirections feed every command inside it.
5
+ const COMPOUND_CLOSERS = new Set(['done', 'esac', 'fi']);
6
+ const EXEC_WRAPPERS = new Set([
7
+ 'busybox',
8
+ 'chroot',
9
+ 'doas',
10
+ 'ionice',
11
+ 'nice',
12
+ 'setsid',
13
+ 'stdbuf',
14
+ 'su',
15
+ 'sudo',
16
+ 'timeout',
17
+ 'toybox',
18
+ 'xargs',
19
+ ]);
20
+ const EXPANSION = /[$`*?[]/;
21
+ /**
22
+ * Whether a shell may read the stdin redirection (heredoc or here-string) at `operatorIndex` of
23
+ * `tokens` (tokenized with `splitRedirections`) as its script: the redirected command, or any later
24
+ * stage of its pipeline, is one the hook cannot rule out as a scriptless shell.
25
+ */
26
+ export function shellReadsStdinAt(tokens, operatorIndex) {
27
+ let start = commandSegmentStart(tokens, operatorIndex);
28
+ let end = nextShellCommandSeparatorIndex(tokens, operatorIndex);
29
+ if (segmentMayRunStdin(tokens, start, end))
30
+ return true;
31
+ while (tokens[end] === '|') {
32
+ // `|&` pipes stderr too.
33
+ start = tokens[end + 1] === '&' ? end + 2 : end + 1;
34
+ // A pipeline that continues after the heredoc body names its next stage on a later line.
35
+ if (start >= tokens.length)
36
+ return true;
37
+ end = nextShellCommandSeparatorIndex(tokens, start);
38
+ if (segmentMayRunStdin(tokens, start, end))
39
+ return true;
40
+ }
41
+ return false;
42
+ }
43
+ // A shell reads stdin as its script unless a `-c` script comes before its first operand. The hook
44
+ // also fails closed on a compound command (`{ bash; }`, `(bash)`, `done`), a wrapper option it
45
+ // cannot read (`env -S`), and a command word an expansion chooses (`$SHELL`).
46
+ function segmentMayRunStdin(tokens, start, end) {
47
+ if (tokens[start - 1] === ')' || tokens[start - 1] === '}')
48
+ return true;
49
+ const words = withoutRedirections(tokens.slice(start, end));
50
+ if (words === null || words.length === 0 || COMPOUND_CLOSERS.has(words[0]))
51
+ return true;
52
+ const read = readCommandPrefix(words);
53
+ if (read === null)
54
+ return true;
55
+ const command = words[read.commandIndex];
56
+ if (command === undefined || EXPANSION.test(command))
57
+ return true;
58
+ if (EXEC_WRAPPERS.has(command.slice(command.lastIndexOf('/') + 1)))
59
+ return true;
60
+ return isShellWord(command) && shellScriptOperandIndex(words, read.commandIndex) === undefined;
61
+ }