pi-odd-worktree 2.1.0 → 3.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.
Files changed (160) hide show
  1. package/README.md +54 -319
  2. package/extensions/odd-worktree-tools.ts +4145 -2529
  3. package/lib/bash-activity.js +1164 -0
  4. package/lib/bash-design.js +684 -0
  5. package/lib/bash-destructive.js +559 -0
  6. package/lib/bash-frame.js +205 -0
  7. package/lib/card-content.js +23 -0
  8. package/lib/card-style.js +175 -0
  9. package/lib/checkout-facts.js +30 -70
  10. package/lib/codegraph-card-preview.js +628 -0
  11. package/lib/codegraph-card.js +515 -0
  12. package/lib/codegraph-compaction.js +76 -0
  13. package/lib/codegraph-daemon.js +246 -0
  14. package/lib/codegraph-edit-sync.js +182 -0
  15. package/lib/codegraph-guard-target.js +337 -0
  16. package/lib/codegraph-guard.js +211 -0
  17. package/lib/codegraph-index.js +1020 -0
  18. package/lib/codegraph-lock.js +607 -0
  19. package/lib/codegraph-mcp-config.js +134 -0
  20. package/lib/codegraph-mcp.js +123 -0
  21. package/lib/codegraph-paths.js +69 -0
  22. package/lib/codegraph-prompt/explore.md +11 -0
  23. package/lib/codegraph-prompt/fix.md +6 -0
  24. package/lib/codegraph-prompt/generic.md +8 -0
  25. package/lib/codegraph-prompt/judge.md +9 -0
  26. package/lib/codegraph-prompt/orchestrator.md +17 -0
  27. package/lib/codegraph-prompt/verify.md +10 -0
  28. package/lib/codegraph-prompt/worker.md +7 -0
  29. package/lib/codegraph-role.js +55 -0
  30. package/lib/codegraph-rules.js +146 -0
  31. package/lib/codegraph-session.js +303 -383
  32. package/lib/codegraph-warmup.js +139 -0
  33. package/lib/file-card-markdown.js +141 -0
  34. package/lib/file-card-resolver.js +245 -0
  35. package/lib/file-card.js +659 -0
  36. package/lib/files-index.js +387 -0
  37. package/lib/files-insert.js +81 -0
  38. package/lib/files-orders.js +326 -0
  39. package/lib/files-picker-view.js +1416 -0
  40. package/lib/files-preview.js +338 -0
  41. package/lib/files-scope-detail.js +171 -0
  42. package/lib/files-scope-view.js +507 -0
  43. package/lib/gh-issues.js +308 -14
  44. package/lib/issue-preview.js +26 -7
  45. package/lib/issues-bash-mutation.js +206 -0
  46. package/lib/issues-cache-store.js +261 -0
  47. package/lib/issues-section.js +710 -0
  48. package/lib/issues-view.js +649 -52
  49. package/lib/odd-prompt/odd-worktrees.md +21 -0
  50. package/lib/odd-worktrees-prompt.js +10 -28
  51. package/lib/related-issues-cache.js +210 -0
  52. package/lib/shell-card.js +825 -0
  53. package/lib/skill-odd-card.js +183 -0
  54. package/lib/tui-paint.js +4 -5
  55. package/lib/warp-create-panel.js +538 -250
  56. package/lib/warp-create-picker.js +56 -9
  57. package/lib/warp-delete-confirm.js +19 -28
  58. package/lib/warp-selector-view.js +160 -82
  59. package/lib/which-command.js +90 -0
  60. package/lib/worktree-card.js +267 -897
  61. package/lib/worktree-cards.js +383 -0
  62. package/lib/worktree-create.js +287 -0
  63. package/lib/worktree-git.js +3 -3
  64. package/lib/worktree-guard.js +548 -0
  65. package/lib/worktree-hooks.js +421 -712
  66. package/lib/worktree-list.js +120 -0
  67. package/lib/worktree-registry.js +162 -879
  68. package/lib/{worktree-close-herdr.js → worktree-remove.js} +9 -11
  69. package/lib/worktree-setup-runner.js +376 -0
  70. package/lib/worktree-setup.js +140 -0
  71. package/lib/worktree-warp-busy.js +462 -85
  72. package/lib/worktree-warp-sessions.js +1 -2
  73. package/package.json +2 -2
  74. package/tools/bash-activity.test.js +1419 -0
  75. package/tools/bash-design.test.js +1091 -0
  76. package/tools/bash-destructive.test.js +139 -0
  77. package/tools/card-content.test.js +44 -0
  78. package/tools/card-style.test.js +298 -0
  79. package/tools/codegraph-card-preview.test.js +254 -0
  80. package/tools/codegraph-card.test.js +1080 -0
  81. package/tools/codegraph-compaction.test.js +378 -0
  82. package/tools/codegraph-daemon.test.js +248 -0
  83. package/tools/codegraph-edit-sync.test.js +295 -0
  84. package/tools/codegraph-guard-target.test.js +174 -0
  85. package/tools/codegraph-guard.test.js +238 -0
  86. package/tools/codegraph-index.test.js +1948 -0
  87. package/tools/codegraph-lock.test.js +932 -0
  88. package/tools/codegraph-mcp-config.test.js +181 -0
  89. package/tools/codegraph-mcp.test.js +194 -0
  90. package/tools/codegraph-paths.test.js +44 -0
  91. package/tools/codegraph-role.test.js +30 -0
  92. package/tools/codegraph-rules.test.js +250 -0
  93. package/tools/codegraph-session.test.js +660 -391
  94. package/tools/codegraph-warmup.test.js +316 -0
  95. package/tools/commands.test.js +510 -31
  96. package/tools/file-card-markdown.test.js +188 -0
  97. package/tools/file-card.test.js +1289 -0
  98. package/tools/files-bridge.test.js +575 -0
  99. package/tools/files-command.test.js +610 -0
  100. package/tools/files-index.test.js +473 -0
  101. package/tools/files-insert.test.js +139 -0
  102. package/tools/files-orders.test.js +597 -0
  103. package/tools/files-picker-view.test.js +1871 -0
  104. package/tools/files-preview.test.js +452 -0
  105. package/tools/files-scope-detail.test.js +264 -0
  106. package/tools/files-scope-view.test.js +614 -0
  107. package/tools/fixtures/card-codegraph-outputs.js +110 -0
  108. package/tools/fixtures/codegraph-cli-stub.js +16 -0
  109. package/tools/fixtures/codegraph-init-process.js +28 -0
  110. package/tools/fixtures/codegraph-lock-worker.js +117 -0
  111. package/tools/fixtures/daemon-fake.js +98 -0
  112. package/tools/fixtures/daemon-mcp-server.js +39 -0
  113. package/tools/fixtures/daemon-warmup-worker.js +12 -0
  114. package/tools/fixtures/load-extension.js +136 -3
  115. package/tools/gh-issues-feedback.test.js +31 -7
  116. package/tools/gh-issues.test.js +391 -1
  117. package/tools/issue-preview.test.js +44 -7
  118. package/tools/issues-bash-mutation.test.js +101 -0
  119. package/tools/issues-cache-store.test.js +222 -0
  120. package/tools/issues-command.test.js +1512 -66
  121. package/tools/issues-open-guard.test.js +1096 -0
  122. package/tools/issues-section.test.js +4195 -0
  123. package/tools/issues-seed-query-regression.test.js +67 -0
  124. package/tools/issues-view.test.js +1489 -60
  125. package/tools/odd-worktrees-prompt.test.js +98 -65
  126. package/tools/package-surface.test.js +431 -36
  127. package/tools/related-issues-cache.test.js +324 -0
  128. package/tools/shell-card.test.js +834 -0
  129. package/tools/skill-odd-card.test.js +200 -0
  130. package/tools/t5-session-identity.test.js +44 -22
  131. package/tools/warp-busy-guard.test.js +2565 -309
  132. package/tools/warp-create-panel.test.js +499 -74
  133. package/tools/warp-create-picker.test.js +101 -5
  134. package/tools/warp-delete-confirm.test.js +49 -15
  135. package/tools/warp-empty-session.test.js +0 -1
  136. package/tools/warp-fallback-regression.test.js +533 -0
  137. package/tools/warp-selector-view.test.js +460 -196
  138. package/tools/which-command.test.js +126 -0
  139. package/tools/worktree-card.test.js +551 -0
  140. package/tools/worktree-cards.test.js +845 -0
  141. package/tools/worktree-changes.test.js +4 -5
  142. package/tools/worktree-create.test.js +489 -0
  143. package/tools/worktree-guard.test.js +823 -0
  144. package/tools/worktree-hooks.test.js +905 -0
  145. package/tools/worktree-list.test.js +170 -0
  146. package/tools/worktree-registry.test.js +89 -230
  147. package/tools/worktree-remove-async.test.js +318 -0
  148. package/tools/worktree-setup-runner.test.js +276 -0
  149. package/tools/worktree-setup.test.js +140 -0
  150. package/tools/worktree-tools.test.js +419 -199
  151. package/lib/codegraph-commands.js +0 -165
  152. package/lib/odd-prompt/odd-worktrees.with-codegraph.md +0 -19
  153. package/lib/odd-prompt/odd-worktrees.without-codegraph.md +0 -15
  154. package/lib/worktree-model-result.js +0 -291
  155. package/tools/codegraph-commands.test.js +0 -371
  156. package/tools/herdr-free-create.test.js +0 -161
  157. package/tools/worktree-close-herdr-async.test.js +0 -204
  158. package/tools/worktree-odd-migration.test.js +0 -224
  159. package/tools/worktree-registry-cache.test.js +0 -163
  160. package/tools/worktree-registry-odd.test.js +0 -231
@@ -0,0 +1,1419 @@
1
+ 'use strict';
2
+ // S2 / S3 / S4 (T2): the bash ACTIVITY classifier — which named family one `bash`
3
+ // call belongs to, and the quote-aware segmenter every family is decided with.
4
+ //
5
+ // The rules are the user's own gentle-shell branch (`cards-bash-v2`,
6
+ // `lib/odd-phase-inference.ts` and `tests/odd-phase-inference.test.ts`, read
7
+ // read-only): the eight families this classifier names, their marks and theme roles,
8
+ // the segmenter, and the reference's conservatism. What this suite pins is the shell
9
+ // classification ONLY — the reference's ODD *phase* inference (what phase a tool
10
+ // implies) is out of scope here, so no case reads a phase label.
11
+ //
12
+ // The classifier's whole value is that it never guesses: an unknown program, an
13
+ // ambiguous composition, a command hidden in a substitution the segmenter cannot
14
+ // follow, or a redirect the call would write, all answer `undefined` and the card
15
+ // stays generic. That conservatism is what most of this suite states.
16
+ //
17
+ // Public surface only: `SHELL_ACTIVITIES`, `SHELL_ACTIVITY_IDENTITY`,
18
+ // `shellCommandSegments`, `inferBashActivity`, `isCodegraphCommand`. Nothing here
19
+ // reads module internals, spawns a process, reaches the network or touches a file.
20
+ const { test } = require('node:test');
21
+ const assert = require('node:assert/strict');
22
+ const {
23
+ SHELL_ACTIVITIES,
24
+ SHELL_ACTIVITY_IDENTITY,
25
+ inferBashActivity,
26
+ isCodegraphCommand,
27
+ shellCommandSegments,
28
+ } = require('../lib/bash-activity.js');
29
+ const { codegraphCallFromCommand } = require('../lib/codegraph-card-preview.js');
30
+
31
+ // The host TUI is a peer dependency this package does not install, so the width
32
+ // assertion below is the only one that needs it: it runs where the host is present
33
+ // and states the mark's own counted column, exactly as the reference does.
34
+ let visibleWidth;
35
+ try {
36
+ ({ visibleWidth } = require('@earendil-works/pi-tui'));
37
+ } catch {
38
+ visibleWidth = undefined;
39
+ }
40
+
41
+ // ---- the vocabulary ----
42
+
43
+ // A card names one identity per activity, so the vocabulary is a closed list: an
44
+ // activity without a mark and a theme role could not be drawn, and one the table
45
+ // forgot would silently fall back to the generic card. The order is the reference's
46
+ // precedence order, and `destructive` heads it: a deletion is the one consequence a
47
+ // reader cannot undo, so it outranks every identity beside it.
48
+ test('the activity vocabulary is the named families, in the reference order', () => {
49
+ assert.deepEqual([...SHELL_ACTIVITIES], [
50
+ 'destructive',
51
+ 'checking',
52
+ 'formatting',
53
+ 'preparing',
54
+ 'publishing',
55
+ 'versioning',
56
+ 'codegraph',
57
+ 'exploring',
58
+ ]);
59
+ assert.deepEqual(Object.keys(SHELL_ACTIVITY_IDENTITY).sort(), [...SHELL_ACTIVITIES].sort());
60
+ });
61
+
62
+ // The roles are the theme's own slots, never a palette: a light theme, a neon theme
63
+ // or a design pack repaints the heading with everything else. The mark is what
64
+ // tells two identities apart in one slot — `preparing` and `formatting` share the
65
+ // code palette, so their word and their mark are all the reader has.
66
+ test('every activity wears its own mark and a theme role', () => {
67
+ assert.deepEqual(SHELL_ACTIVITY_IDENTITY, {
68
+ // The one family whose warning a reader must see before expanding the row.
69
+ destructive: { glyph: '⚠', titleRole: 'error' },
70
+ checking: { glyph: '✓', titleRole: 'mdHeading' },
71
+ formatting: { glyph: '≋', titleRole: 'syntaxFunction' },
72
+ // U+2692 is painted two cells wide by an emoji-fallback font while the host
73
+ // counts it as one, so its mark ends in the one space that keeps a column of
74
+ // its own: the heading's counted width must match what the terminal paints.
75
+ preparing: { glyph: '⚒ ', titleRole: 'syntaxFunction' },
76
+ publishing: { glyph: '↑', titleRole: 'success' },
77
+ versioning: { glyph: '⎇', titleRole: 'warning' },
78
+ // The native tool's own mark, so the shell call and the tool read as one card.
79
+ codegraph: { glyph: '\u{F01BC}', titleRole: 'mdCode' },
80
+ exploring: { glyph: '⌕', titleRole: 'mdLink' },
81
+ });
82
+ const marks = SHELL_ACTIVITIES.map((activity) => SHELL_ACTIVITY_IDENTITY[activity].glyph);
83
+ assert.equal(new Set(marks.map((mark) => mark.trim())).size, marks.length, 'no two activities share a mark');
84
+ // No role is a colour this package invented: every one names a slot of the host's
85
+ // theme, so nothing here writes a hex value, a palette entry or an escape.
86
+ const roles = new Set(['mdHeading', 'mdLink', 'mdCode', 'success', 'warning', 'syntaxFunction', 'error']);
87
+ for (const activity of SHELL_ACTIVITIES) {
88
+ const { glyph, titleRole } = SHELL_ACTIVITY_IDENTITY[activity];
89
+ assert.ok(roles.has(titleRole), `${activity}: ${titleRole} is a theme slot`);
90
+ assert.equal(/\u001b|#[0-9a-fA-F]{3,8}\b/.test(glyph), false, `${activity}: the mark is plain text`);
91
+ }
92
+ });
93
+
94
+ // A heading's width is the host's own count, so a mark must cost exactly one column
95
+ // — plus the declared gap `preparing` keeps for the font that paints it wide. The
96
+ // statement is made twice: once in code points, so it holds with no host installed,
97
+ // and once through the host's own measurement, which is the number that wraps.
98
+ test('a mark costs one counted column, plus preparing\'s declared gap', () => {
99
+ for (const activity of SHELL_ACTIVITIES) {
100
+ const { glyph } = SHELL_ACTIVITY_IDENTITY[activity];
101
+ assert.equal([...glyph].length, activity === 'preparing' ? 2 : 1, `${activity}: one mark, plus its own gap`);
102
+ assert.equal(glyph.trimStart(), glyph, `${activity}: a mark never starts with its gap`);
103
+ }
104
+ });
105
+
106
+ test('the host measures every mark at the width the heading assumes', { skip: visibleWidth ? false : 'requires @earendil-works/pi-tui' }, () => {
107
+ for (const activity of SHELL_ACTIVITIES) {
108
+ const { glyph } = SHELL_ACTIVITY_IDENTITY[activity];
109
+ assert.equal(visibleWidth(glyph), activity === 'preparing' ? 2 : 1, `${activity}: one counted column plus its own gap`);
110
+ }
111
+ });
112
+
113
+ // ---- one rule per family ----
114
+
115
+ // Read-only inspection is the one family the ODD protocol also names as a phase, and
116
+ // the card reads the same segments the reference reads.
117
+ test('a read-only composition names the exploring activity', () => {
118
+ for (const command of [
119
+ 'git status',
120
+ 'git log --oneline -5',
121
+ 'git diff --stat',
122
+ 'git show HEAD',
123
+ 'git branch -a',
124
+ 'ls -la',
125
+ 'cat package.json',
126
+ 'head -20 README.md',
127
+ 'tail -n 5 log.txt',
128
+ 'grep -rn foo lib',
129
+ 'rg oddActivity',
130
+ "find . -name '*.ts'",
131
+ 'wc -l lib/bash-activity.js',
132
+ 'pwd',
133
+ 'gh pr view 12',
134
+ 'cat package.json && git diff',
135
+ ]) {
136
+ assert.equal(inferBashActivity(command), 'exploring', command);
137
+ }
138
+ });
139
+
140
+ // A verification runner is the check it is; the family reads the runner, not a
141
+ // script name a repository happened to choose, and a namespaced `test:unit` keeps
142
+ // the base family it is namespaced under.
143
+ test('a verification runner names the checking activity', () => {
144
+ for (const command of [
145
+ 'pnpm test',
146
+ 'npm test',
147
+ 'npm run test -- --watch=false',
148
+ 'node --experimental-strip-types --test tests/activity.test.js',
149
+ 'node scripts/check-types.mjs',
150
+ 'npx vitest run a.test.js',
151
+ 'jest --ci',
152
+ 'go test ./...',
153
+ 'go build ./...',
154
+ 'cargo test',
155
+ 'cargo nextest run --workspace',
156
+ 'python -m pytest -q',
157
+ 'pytest tests/',
158
+ 'tsc --noEmit',
159
+ 'pnpm typecheck',
160
+ 'pnpm lint',
161
+ 'eslint .',
162
+ 'npm run build',
163
+ 'make',
164
+ 'make test',
165
+ 'cd sub && make check',
166
+ 'deno test -A tests/',
167
+ 'deno check mod.ts',
168
+ 'ruff check .',
169
+ ]) {
170
+ assert.equal(inferBashActivity(command), 'checking', command);
171
+ }
172
+ });
173
+
174
+ // A monorepo flags the workspace before the script, and every value option's value
175
+ // must be read as the value it is, or `npm --prefix pkg test` would look like the
176
+ // script `pkg`.
177
+ test('workspace flags and namespaced scripts still name the checking activity', () => {
178
+ for (const command of [
179
+ 'pnpm -C pkg test',
180
+ 'pnpm -C packages/app run test',
181
+ 'pnpm --filter app test',
182
+ 'pnpm --filter=app build',
183
+ 'pnpm -w typecheck',
184
+ 'pnpm run test:unit',
185
+ 'npm run test:e2e',
186
+ 'pnpm run check:runtime-modules',
187
+ 'pnpm check:provider-contract',
188
+ 'yarn test:ci',
189
+ 'npm --prefix pkg run test:e2e',
190
+ 'npm --prefix pkg test',
191
+ 'yarn --cwd pkg test',
192
+ 'python -m unittest',
193
+ 'python3.12 -m pytest -q',
194
+ ]) {
195
+ assert.equal(inferBashActivity(command), 'checking', command);
196
+ }
197
+ });
198
+
199
+ // `ruff check --fix` and `deno lint --fix` repair code, so a fix flag turns the
200
+ // check into the rewrite it performs. eslint still verifies whatever write flag it
201
+ // carries, and `--fix-dry-run` writes nothing, so those stay checks.
202
+ test('a fix flag turns a check into the rewrite it performs', () => {
203
+ for (const command of ['ruff check --fix .', 'ruff check --fix-only .', 'deno lint --fix', `ruff check '--fix-only' .`]) {
204
+ assert.equal(inferBashActivity(command), 'formatting', command);
205
+ }
206
+ for (const command of ['ruff check .', 'deno lint', 'eslint --fix .', 'eslint src --fix --max-warnings 0', 'eslint --fix-dry-run src/app.ts']) {
207
+ assert.equal(inferBashActivity(command), 'checking', command);
208
+ }
209
+ });
210
+
211
+ // A formatter verifies only when it is told to report, and the report flag belongs
212
+ // to the tool that defines it: `-l` lists files for gofmt, gofumpt and shfmt but is
213
+ // the line length for black, and a write flag beside a report flag rewrites anyway.
214
+ test('a formatter reports a check only in its own report mode', () => {
215
+ for (const command of [
216
+ 'gofmt -l .',
217
+ 'gofmt -d cmd/app',
218
+ 'gofumpt -l .',
219
+ 'shfmt -l scripts',
220
+ 'shfmt -d scripts/build.sh',
221
+ 'black --check .',
222
+ 'black --diff src/app.py',
223
+ 'black --line-length=100 --check .',
224
+ 'prettier --check .',
225
+ 'prettier -l src/app.ts',
226
+ 'clang-format --dry-run src/app.c',
227
+ 'swiftformat --lint .',
228
+ 'npx prettier -l src/app.ts',
229
+ 'pnpm exec prettier --check .',
230
+ 'cargo fmt --check',
231
+ 'cargo fmt -- --check',
232
+ 'deno fmt --check',
233
+ 'ruff format --check .',
234
+ 'timeout 60 gofmt -l .',
235
+ ]) {
236
+ assert.equal(inferBashActivity(command), 'checking', command);
237
+ }
238
+ // A write flag outranks a report flag, and a formatter that rewrites in place by
239
+ // default names the rewrite even when its flags say nothing about it.
240
+ for (const command of [
241
+ 'gofmt -l -w .',
242
+ 'gofmt -w -l .',
243
+ 'gofumpt -w -l .',
244
+ 'shfmt -w -l scripts',
245
+ 'gofmt -w .',
246
+ 'prettier --write .',
247
+ 'prettier -w src/app.ts',
248
+ 'npx prettier --write src/app.ts',
249
+ 'black -l 100 .',
250
+ 'black --line-length 100 src/app.py',
251
+ 'clang-format -i src/app.c',
252
+ 'cargo fmt',
253
+ 'go fmt ./...',
254
+ 'ruff format .',
255
+ 'deno fmt',
256
+ 'biome format --write .',
257
+ "stylelint --fix '**/*.css'",
258
+ 'rustfmt src/main.rs',
259
+ ]) {
260
+ assert.equal(inferBashActivity(command), 'formatting', command);
261
+ }
262
+ // A formatter whose flags this classifier cannot read names nothing at all rather
263
+ // than claiming a rewrite that never happened.
264
+ assert.equal(inferBashActivity("prettier 'a --write b.ts'"), undefined);
265
+ });
266
+
267
+ // A flag keeps its meaning when it is quoted, while quoted text that merely contains
268
+ // one is a file name: `black "--check" .` asks black to report, and
269
+ // `prettier --check "a --write b.ts"` names a file whose text says `--write`.
270
+ test('a quoted flag keeps its mode while quoted text never becomes one', () => {
271
+ for (const command of [
272
+ 'black "--check" .',
273
+ "black '--check' .",
274
+ 'black "--diff" src/app.py',
275
+ 'prettier "--check" .',
276
+ 'gofmt "-l" .',
277
+ 'black "--line-length=100" --check .',
278
+ 'prettier --check "a --write b.ts"',
279
+ `eslint "--fix" .`,
280
+ "pnpm exec eslint '--fix' src",
281
+ 'ruff check "src/--fix.py"',
282
+ 'deno lint "src/--fix.ts"',
283
+ ]) {
284
+ assert.equal(inferBashActivity(command), 'checking', command);
285
+ }
286
+ for (const command of ['black "--line-length=100" .', 'gofmt "-w" main.go', 'ruff check "--fix" .', `deno lint '--fix' .`]) {
287
+ assert.equal(inferBashActivity(command), 'formatting', command);
288
+ }
289
+ assert.equal(inferBashActivity('prettier "a --check b.ts"'), undefined);
290
+ });
291
+
292
+ // make reads its options before the recipe, so an option that never changes which
293
+ // recipe runs must not hide the check — and every recipe named on the command line
294
+ // must be one this classifier can name: `make test install` is not a check.
295
+ test('make options keep a check while an unknown recipe names nothing', () => {
296
+ for (const command of [
297
+ 'make -B test',
298
+ 'make -e -i -O test',
299
+ 'make --no-print-directory check',
300
+ 'make --always-make -j4 test',
301
+ 'make -B -j 4 test',
302
+ 'make -rR build',
303
+ 'make -s -k check',
304
+ 'make -C pkg -B test',
305
+ 'make -f Makefile.ci --no-print-directory test',
306
+ 'make VAR=1 check',
307
+ ]) {
308
+ assert.equal(inferBashActivity(command), 'checking', command);
309
+ }
310
+ for (const command of [
311
+ 'make install',
312
+ 'make deploy',
313
+ 'make clean',
314
+ 'make release',
315
+ 'make test install',
316
+ 'make ci',
317
+ // `-j` takes an optional job count, so it must never swallow the recipe.
318
+ 'make -j install',
319
+ 'make -j2 deploy',
320
+ 'make -B install',
321
+ 'make -e test install',
322
+ 'make -O install',
323
+ ]) {
324
+ assert.equal(inferBashActivity(command), undefined, command);
325
+ }
326
+ });
327
+
328
+ // A watchdog bounds how long a check may run without changing what it does, so a
329
+ // runner behind `timeout` still names the call. Anything else behind one is not a
330
+ // check and is not inspection either.
331
+ test('a verification runner behind timeout still names the checking activity', () => {
332
+ for (const command of [
333
+ 'timeout 900 pnpm typecheck 2>&1 | tail -20',
334
+ 'timeout 900 pnpm typecheck',
335
+ 'timeout 30 pnpm test',
336
+ 'timeout 5 npx vitest run',
337
+ 'timeout 60 pnpm -C packages/app run test',
338
+ 'timeout 30 make test',
339
+ 'timeout -k 5 60 pnpm test',
340
+ 'timeout --foreground 900 make check',
341
+ 'timeout --signal=KILL 30 cargo test',
342
+ ]) {
343
+ assert.equal(inferBashActivity(command), 'checking', command);
344
+ }
345
+ for (const command of ['timeout 5 node scripts/release.mjs', 'timeout 5 git status', 'timeout 300 unknown-script --watch', 'timeout 5']) {
346
+ assert.equal(inferBashActivity(command), undefined, command);
347
+ }
348
+ });
349
+
350
+ // Installing dependencies in any ecosystem, creating a directory, a file or a
351
+ // repository, and storing configuration are all the one build-up identity; only the
352
+ // forms that name themselves count, so an unknown script stays unnamed.
353
+ test('installations, scaffolding and stored configuration name the preparing activity', () => {
354
+ for (const command of [
355
+ 'pnpm install',
356
+ 'pnpm install --frozen-lockfile',
357
+ 'npm ci',
358
+ 'npm install left-pad',
359
+ 'pnpm -C packages/app install',
360
+ 'yarn add left-pad',
361
+ 'bun install',
362
+ 'pip install -r requirements.txt',
363
+ 'python3 -m pip install -e .',
364
+ 'uv sync',
365
+ 'uv pip install pytest',
366
+ 'poetry install',
367
+ 'bundle install',
368
+ 'composer install',
369
+ 'brew install jq',
370
+ 'apt-get install -y jq',
371
+ 'apk add jq',
372
+ 'pacman -S jq',
373
+ 'go mod download',
374
+ 'go install ./cmd/tool',
375
+ 'cargo install cargo-nextest',
376
+ 'dotnet restore',
377
+ 'git init',
378
+ 'git clone https://example.com/repo.git',
379
+ 'cargo new crate',
380
+ 'mkdir -p tmp/scratch',
381
+ 'touch tmp/scratch/file',
382
+ 'cp package.json package.json.bak',
383
+ 'ln -s ../lib/bash-activity.js bash-activity.js',
384
+ "git config user.name 'A B'",
385
+ 'npm config set fund false',
386
+ 'go env -w GOFLAGS=-mod=mod',
387
+ ]) {
388
+ assert.equal(inferBashActivity(command), 'preparing', command);
389
+ }
390
+ });
391
+
392
+ // An installer told to report prepares nothing: `cargo install --list` lists what is
393
+ // already installed and `--dry-run` resolves a tree without writing it, so neither
394
+ // names an identity — and a report-shaped argument never hides the writing form.
395
+ test('an installer told to list or dry-run prepares nothing', () => {
396
+ for (const command of [
397
+ 'cargo install --list',
398
+ 'cargo install --list --quiet',
399
+ 'npm install --dry-run',
400
+ 'npm install --dry-run left-pad',
401
+ 'npm ci --dry-run',
402
+ 'npm install --dry-run=true',
403
+ 'pip install --dry-run .',
404
+ 'pip install -e . --dry-run',
405
+ 'uv pip install --dry-run pytest',
406
+ 'brew install --dry-run jq',
407
+ ]) {
408
+ assert.equal(inferBashActivity(command), undefined, command);
409
+ }
410
+ for (const command of ['npm install', 'npm install --save-dev left-pad', 'cargo install cargo-nextest', 'pip install --no-deps .', 'brew install jq']) {
411
+ assert.equal(inferBashActivity(command), 'preparing', command);
412
+ }
413
+ });
414
+
415
+ // Local history changes this machine only: the index, a commit (an `--amend`
416
+ // included), a rebase and a cherry-pick. `git -C <dir>` names the directory it runs
417
+ // in, never a different command.
418
+ test('local history changes name the versioning activity', () => {
419
+ for (const command of [
420
+ 'git add -A',
421
+ 'git add lib/bash-activity.js',
422
+ 'git -C /repo add .',
423
+ "git commit -m 'feat: x'",
424
+ 'git commit --amend --no-edit',
425
+ 'git commit -m "$(cat msg.txt)"',
426
+ 'git commit -m x && git log --oneline -3',
427
+ 'git rebase main',
428
+ 'git rebase -i origin/main',
429
+ 'git rebase --continue',
430
+ 'git rebase --abort',
431
+ 'git cherry-pick abc1234',
432
+ 'git cherry-pick --continue',
433
+ 'git cherry-pick --abort',
434
+ 'git add -A && git commit -m x',
435
+ 'gh stack init',
436
+ 'gh stack init --base feat/tracker feat/one feat/two',
437
+ 'gh stack add feat/three',
438
+ 'gh stack rebase --upstack',
439
+ ]) {
440
+ assert.equal(inferBashActivity(command), 'versioning', command);
441
+ }
442
+ });
443
+
444
+ // A remote write creates or moves something on GitHub — a push, a PR or issue
445
+ // mutation, a label, a release, a repository, a stack's remote half.
446
+ test('remote writes name the publishing activity', () => {
447
+ for (const command of [
448
+ 'git push',
449
+ 'git push -u origin HEAD',
450
+ 'git push origin feat/x',
451
+ 'gh pr create --title x --body y',
452
+ 'gh pr edit 12 --add-label bug --add-assignee octocat',
453
+ 'gh pr close 12',
454
+ 'gh pr reopen 12',
455
+ 'gh pr merge 12 --squash',
456
+ 'gh pr ready 12',
457
+ 'gh pr review 12 --approve',
458
+ 'gh pr update-branch 12',
459
+ 'gh pr comment 12 --body hi',
460
+ 'gh issue create --title x --label bug --assignee octocat',
461
+ 'gh issue edit 7 --add-label bug --remove-label wip --add-assignee octocat',
462
+ 'gh issue close 7',
463
+ 'gh issue reopen 7',
464
+ 'gh issue comment 7 --body hi',
465
+ 'gh issue pin 7',
466
+ 'gh issue transfer 7 owner/other',
467
+ 'gh label create bug --color ff0000',
468
+ 'gh label edit bug --new-name defect',
469
+ 'gh label delete bug --yes',
470
+ 'gh label clone owner/other',
471
+ 'gh release create v1.0.0 --generate-notes',
472
+ 'gh release edit v1.0.0 --draft=false',
473
+ 'gh release upload v1.0.0 dist/app.tgz',
474
+ 'gh stack submit',
475
+ 'gh stack submit --auto --open',
476
+ 'gh stack push',
477
+ 'gh stack sync',
478
+ 'gh stack merge',
479
+ 'gh stack link',
480
+ 'gh stack unstack',
481
+ ]) {
482
+ assert.equal(inferBashActivity(command), 'publishing', command);
483
+ }
484
+ });
485
+
486
+ // Moving between branches, aliasing a command and the rest of the stack subcommands
487
+ // publish nothing and read nothing, so they name no activity at all; viewing a stack
488
+ // is inspection.
489
+ test('a stack view is inspection and the rest of the stack subcommands name nothing', () => {
490
+ for (const command of ['gh stack view', 'gh stack view --json', 'gh stack view | jq -r .name']) {
491
+ assert.equal(inferBashActivity(command), 'exploring', command);
492
+ }
493
+ for (const command of [
494
+ 'gh stack checkout',
495
+ 'gh stack bottom',
496
+ 'gh stack top',
497
+ 'gh stack up',
498
+ 'gh stack down',
499
+ 'gh stack trunk',
500
+ 'gh stack switch',
501
+ 'gh stack modify',
502
+ 'gh stack alias co',
503
+ 'gh stack feedback',
504
+ ]) {
505
+ assert.equal(inferBashActivity(command), undefined, command);
506
+ }
507
+ });
508
+
509
+ // ---- gh: a CI read verifies work, a plain GET inspects, a write publishes ----
510
+
511
+ // Waiting on or reading CI results verifies work; it is not exploration, and a
512
+ // `sleep` or a `tail` beside it only bounds how long the wait takes.
513
+ test('reading or waiting on CI results names the checking activity', () => {
514
+ for (const command of [
515
+ 'gh pr checks 1511',
516
+ 'gh pr checks 1511 --repo owner/name --watch --interval 20',
517
+ 'sleep 30; gh pr checks 1511 --watch 2>&1 | tail -10',
518
+ 'gh run watch 123',
519
+ 'gh run view 123 --log-failed',
520
+ 'gh run list --branch main',
521
+ ]) {
522
+ assert.equal(inferBashActivity(command), 'checking', command);
523
+ }
524
+ for (const command of ['gh pr view 1511', 'gh pr diff 1511', 'gh issue list']) {
525
+ assert.equal(inferBashActivity(command), 'exploring', command);
526
+ }
527
+ });
528
+
529
+ // `gh api` writes whenever it is given a method, a field, or an input body, so only
530
+ // the plain GET form is a query — and every writing form is a name this classifier
531
+ // will not guess at, which leaves the card generic rather than claiming an identity.
532
+ test('a gh api call that writes names nothing while the plain GET inspects', () => {
533
+ for (const command of [
534
+ 'gh api repos/owner/name/pulls',
535
+ 'gh api --paginate repos/owner/name/commits',
536
+ ]) {
537
+ assert.equal(inferBashActivity(command), 'exploring', command);
538
+ }
539
+ for (const command of [
540
+ 'gh api repos/o/n -X POST',
541
+ 'gh api repos/o/n --method POST',
542
+ 'gh api repos/o/n/issues -f title=x',
543
+ 'gh api repos/o/n/issues --raw-field title=x',
544
+ 'gh api graphql -F query=@q.graphql',
545
+ 'gh api repos/o/n/issues --input body.json',
546
+ ]) {
547
+ assert.equal(inferBashActivity(command), undefined, command);
548
+ }
549
+ });
550
+
551
+ // Metadata probes answer "what is here?" without resolving, building or mutating
552
+ // anything; `go env` writes its configuration with `-w` and `-u`, so those are no
553
+ // probe, and the writing form is the build-up the next family names.
554
+ test('read-only metadata probes inspect while go env writes prepare', () => {
555
+ for (const command of [
556
+ 'locale',
557
+ 'locale -a',
558
+ 'locale | head -4',
559
+ 'cargo tree',
560
+ 'cargo tree -e normal --depth 1',
561
+ 'go env',
562
+ 'go env GOPATH',
563
+ 'go version',
564
+ 'gh auth status',
565
+ 'gh search prs --repo owner/name login',
566
+ 'gh label list',
567
+ 'gh workflow list',
568
+ 'gh workflow view ci.yml',
569
+ ]) {
570
+ assert.equal(inferBashActivity(command), 'exploring', command);
571
+ }
572
+ // `-w` stores a value in the Go env config file, which is the build-up the next
573
+ // family names; `-u` unsets one, a form no family here claims, so it stays unnamed
574
+ // rather than being filed as the inspection its sibling `go env` is.
575
+ for (const command of ['go env -w GOPATH=/tmp/go', 'go env -w GOFLAGS=-mod=mod GOPATH=/tmp/go']) {
576
+ assert.equal(inferBashActivity(command), 'preparing', command);
577
+ }
578
+ assert.equal(inferBashActivity('go env -u GOPATH'), undefined);
579
+ });
580
+
581
+ // ---- codegraph ----
582
+
583
+ // A shell call that runs the CodeGraph program wears the same identity the native
584
+ // tool wears, so one program reads as one card. Only a command-position program
585
+ // counts: prose that mentions the tool, a flag-only invocation and an unknown
586
+ // program that happens to take `codegraph` as an argument claim nothing.
587
+ test('a codegraph call names its own card identity', () => {
588
+ for (const command of [
589
+ 'codegraph init',
590
+ 'codegraph init /tmp/ws',
591
+ 'codegraph query --path . -- alpha',
592
+ 'codegraph explore --path . -- alpha',
593
+ 'cd /tmp/ws && codegraph init',
594
+ '/usr/local/bin/codegraph init',
595
+ ]) {
596
+ assert.equal(inferBashActivity(command), 'codegraph', command);
597
+ assert.equal(isCodegraphCommand(command), true, command);
598
+ }
599
+ // Every invocation of the program is its card, whatever subcommand it names: the
600
+ // card's detail is the command itself, so no operation has to be readable.
601
+ for (const command of [
602
+ 'codegraph',
603
+ 'codegraph --version',
604
+ 'codegraph --help',
605
+ 'codegraph status',
606
+ 'codegraph status .',
607
+ 'codegraph callers X',
608
+ 'codegraph init > build.log',
609
+ 'codegraph init && ./script',
610
+ // A launcher that runs what it names runs the program: only an explicit
611
+ // execution counts, never `npm run codegraph`, which is a script of that name.
612
+ 'npx codegraph init',
613
+ 'pnpx codegraph explore -- alpha',
614
+ 'bunx codegraph status',
615
+ 'pnpm exec codegraph status',
616
+ 'yarn codegraph status .',
617
+ 'yarn exec codegraph status .',
618
+ 'pnpm dlx codegraph init',
619
+ 'npm exec codegraph init',
620
+ ]) {
621
+ assert.equal(inferBashActivity(command), 'codegraph', command);
622
+ assert.equal(isCodegraphCommand(command), true, command);
623
+ }
624
+ // Prose that merely mentions the program, or a script named after it, claims nothing.
625
+ for (const command of ['echo codegraph init', 'mytool codegraph init', 'npm run codegraph']) {
626
+ assert.equal(inferBashActivity(command), undefined, command);
627
+ assert.equal(isCodegraphCommand(command), false, command);
628
+ }
629
+ // A read of a file named after it is still the read it is, so the CodeGraph card
630
+ // never claims it.
631
+ for (const command of ['cat codegraph.json', 'grep -r codegraph src']) {
632
+ assert.equal(inferBashActivity(command), 'exploring', command);
633
+ assert.equal(isCodegraphCommand(command), false, command);
634
+ }
635
+ // A read that merely searches for the word is still the read it is.
636
+ assert.equal(inferBashActivity('git log --grep codegraph'), 'exploring');
637
+ // When a call also runs the program, the card is CodeGraph's: it names what the call
638
+ // did to this project's graph, and a check beside it never takes the row.
639
+ assert.equal(inferBashActivity('codegraph init && pnpm test'), 'codegraph');
640
+ assert.equal(inferBashActivity('git status && codegraph init'), 'codegraph');
641
+ // A deletion still outranks it: it is the one consequence a reader cannot undo.
642
+ assert.equal(inferBashActivity('codegraph init && rm -rf dist'), 'destructive');
643
+ });
644
+
645
+ // Two readers answer the same question about one command: this classifier, and the
646
+ // CodeGraph card's own `codegraphCallFromCommand` (lib/codegraph-card-preview.js).
647
+ // They must not disagree, or a call would be drawn by one identity and read as
648
+ // another; whatever the card claims, this module calls a CodeGraph command.
649
+ test('the classifier agrees with the CodeGraph card\'s own reader', () => {
650
+ for (const command of [
651
+ 'codegraph init',
652
+ 'codegraph query --path . -- alpha',
653
+ 'codegraph explore -- alpha',
654
+ '/usr/local/bin/codegraph init',
655
+ 'codegraph',
656
+ 'codegraph --version',
657
+ 'echo codegraph init',
658
+ 'git status',
659
+ 'pnpm test',
660
+ ]) {
661
+ const claimed = codegraphCallFromCommand(command) !== undefined;
662
+ assert.equal(isCodegraphCommand(command), claimed, command);
663
+ }
664
+ });
665
+
666
+ // ---- destructive ----
667
+
668
+ // A command-position program that deletes files, directories, history or a branch is
669
+ // the one consequence a reader cannot undo, so it names the destructive card. The
670
+ // evidence is the program's own arguments, read positionally: prose a program merely
671
+ // receives never names a deletion.
672
+ test('a deletion names the destructive card identity', () => {
673
+ for (const command of [
674
+ 'rm dist/a.ts',
675
+ 'rm -f dist/a.ts',
676
+ 'rm -rf dist',
677
+ 'rm -f build/*.log',
678
+ 'rm -rf "tmp/my dir"',
679
+ "rm -rf 'tmp/my dir'",
680
+ 'rm -rf -- -weird-name',
681
+ 'sudo rm -rf /usr/local/lib/tool',
682
+ 'timeout 30 rm -rf node_modules',
683
+ 'git clean -fd',
684
+ 'git clean -fdx',
685
+ 'git reset --hard',
686
+ 'git reset --hard HEAD~1',
687
+ 'git branch -D feat/x',
688
+ 'git stash drop',
689
+ 'git push --force',
690
+ "find . -name '*.log' -delete",
691
+ 'find . -maxdepth 1 -exec rm -rf {} +',
692
+ 'dd if=/dev/zero of=disk.img bs=1M',
693
+ 'truncate -s 0 app.log',
694
+ 'shred -u secret.key',
695
+ ]) {
696
+ assert.equal(inferBashActivity(command), 'destructive', command);
697
+ }
698
+ });
699
+
700
+ // The evidence for a database client is the WHOLE command: a client is fed its
701
+ // statements through a pipe or a heredoc, so its own segment states none of them.
702
+ // Only the payload proves what it deletes, and only a statement that drops, truncates
703
+ // or deletes without a clause picking rows is a deletion at all.
704
+ test('a database client fed a deletion names the destructive card', () => {
705
+ for (const command of [
706
+ `psql -c 'DROP TABLE users'`,
707
+ `psql -c 'DELETE FROM users'`,
708
+ `mysql -e 'TRUNCATE TABLE logs'`,
709
+ `sqlite3 app.db 'DROP TABLE t'`,
710
+ `echo 'DROP TABLE t' | psql`,
711
+ `printf '%s' 'TRUNCATE TABLE logs' | psql`,
712
+ "psql <<'SQL'\nDROP TABLE t;\nSQL",
713
+ "psql <<-SQL\nDELETE FROM t;\nSQL",
714
+ ]) {
715
+ assert.equal(inferBashActivity(command), 'destructive', command);
716
+ }
717
+ // A read, and a delete whose clause picks the rows it removes, prove nothing: the
718
+ // client names no family at all, and the card stays the generic one.
719
+ for (const command of [
720
+ `psql -c 'SELECT 1'`,
721
+ `psql -c 'SELECT * FROM users ORDER BY id'`,
722
+ `psql -c 'DELETE FROM users WHERE id = 1'`,
723
+ `echo 'SELECT 1' | psql`,
724
+ "psql <<'SQL'\nSELECT 1;\nSQL",
725
+ ]) {
726
+ assert.equal(inferBashActivity(command), undefined, command);
727
+ }
728
+ // A segment outside the payload is still unnamed, so the whole call stays generic:
729
+ // the deletion is proven, but the card never hides the work it cannot name.
730
+ for (const command of [
731
+ `psql -c 'DROP TABLE t' && ./scripts/unknown.sh`,
732
+ `echo 'DROP TABLE t' | psql && ./scripts/unknown.sh`,
733
+ "psql <<'SQL'\nDROP TABLE t;\nSQL\n./scripts/unknown.sh",
734
+ ]) {
735
+ assert.equal(inferBashActivity(command), undefined, command);
736
+ }
737
+ });
738
+
739
+ // A deleting program asked for its usage page prints and stops, so it is the query
740
+ // every other family's help flag is — the reading this classifier already makes before
741
+ // a family reads the segment, and the reading the reference makes too. A program this
742
+ // classifier does not name leaves its `--help` unread (a guess), which keeps the
743
+ // segment unnamed rather than calling it a request.
744
+ test('a deleting program asked for its usage page is the query it is', () => {
745
+ for (const command of [
746
+ 'rm --help',
747
+ 'rm -rf dist --help',
748
+ 'find --help',
749
+ 'dd --help',
750
+ 'truncate --help',
751
+ 'shred --help',
752
+ ]) {
753
+ assert.equal(inferBashActivity(command), 'exploring', command);
754
+ }
755
+ assert.equal(inferBashActivity('psql --help'), undefined);
756
+ // A help flag directly after a flag-shaped word stays that word's value, the
757
+ // reading this classifier already makes everywhere (T2): the flag is then not a
758
+ // query, and the deletion it would have printed usage for removed nothing either,
759
+ // so the segment names nothing at all rather than claiming either identity. The
760
+ // reference's own order produces exactly this, because its help reading answers
761
+ // "consumed" before the destructive reading declines the same flag.
762
+ for (const command of ['git clean -fd --help', 'git reset --hard --help', "find . -name '*.log' -delete --help"]) {
763
+ assert.equal(inferBashActivity(command), undefined, command);
764
+ }
765
+ });
766
+
767
+ // The classifier runs synchronously on every bash row the host repaints, so a program
768
+ // whose name is an inherited member of a lookup table answers "no evidence" instead
769
+ // of throwing on the row it was asked to draw.
770
+ test('prototype-hazardous programs never throw and never name a deletion', () => {
771
+ for (const command of ['constructor -rf dist', '__proto__ -rf dist', '__proto__ rm -rf dist', 'constructor --help']) {
772
+ assert.equal(inferBashActivity(command), undefined, command);
773
+ }
774
+ });
775
+
776
+ // ---- the precedence ladder ----
777
+
778
+ // A check outranks a remote write, a history change, a rewrite and a build-up; a
779
+ // remote write outranks a history change, a rewrite outranks a build-up, and
780
+ // CodeGraph sits just above plain inspection. Every rung is stated with the two
781
+ // families it separates, so a moved rung fails here.
782
+ test('the strongest named segment decides the card', () => {
783
+ assert.equal(inferBashActivity('pnpm test | tail -20'), 'checking');
784
+ assert.equal(inferBashActivity('git status && pnpm test'), 'checking');
785
+ assert.equal(inferBashActivity('git push && git commit -m x'), 'publishing');
786
+ assert.equal(inferBashActivity('git commit -m x && prettier --write .'), 'versioning');
787
+ assert.equal(inferBashActivity('pnpm install && git config user.name x'), 'preparing');
788
+ assert.equal(inferBashActivity('prettier --write . && pnpm install'), 'formatting');
789
+ assert.equal(inferBashActivity('git status && pnpm install'), 'preparing');
790
+ for (const command of ['pnpm install && pnpm test', 'git push && pnpm test', 'git commit -m x && make test']) {
791
+ assert.equal(inferBashActivity(command), 'checking', command);
792
+ }
793
+ // The top rung: a deletion outranks every identity beside it, because it is the
794
+ // one consequence of the call a reader cannot undo. A check, an inspection or a
795
+ // remote write in the same command never takes the card from it.
796
+ for (const command of [
797
+ 'rm -rf dist && pnpm test',
798
+ 'pnpm test && git clean -fd',
799
+ 'git status && git reset --hard',
800
+ 'git push --force && git commit -m x',
801
+ `echo 'DROP TABLE t' | psql && pnpm test`,
802
+ ]) {
803
+ assert.equal(inferBashActivity(command), 'destructive', command);
804
+ }
805
+ });
806
+
807
+ // ---- undefined: the card stays generic ----
808
+
809
+ // The strongest rule in the reference: beside a segment nothing can name, the whole
810
+ // call stays generic. The heading never claims a check — or any other identity — for
811
+ // work the call also did silently.
812
+ test('an unnamed segment anywhere keeps the whole call generic', () => {
813
+ for (const command of [
814
+ 'pnpm test && node scripts/release.mjs',
815
+ 'pnpm test && echo ok > out.txt',
816
+ 'pnpm test && echo done | tee log.txt',
817
+ 'pnpm test && ./scripts/deploy.sh',
818
+ "pnpm test && bash -c 'unknown-tool --flag'",
819
+ 'curl https://example.com',
820
+ 'ls && unknown-tool --flag',
821
+ // A program whose name is an inherited member of a lookup table is still just an
822
+ // unknown program: the row it is drawn on must never throw.
823
+ 'constructor .',
824
+ '__proto__ prettier --write .',
825
+ ]) {
826
+ assert.equal(inferBashActivity(command), undefined, command);
827
+ }
828
+ });
829
+
830
+ // A call that changes nothing names no activity, and neither does one with no
831
+ // command at all: the card falls back to the tool's own identity.
832
+ test('a neutral or empty command names no activity', () => {
833
+ for (const command of ['cd repo', 'echo ok', 'sleep 4', 'echo ===', 'cd /repo && echo done', 'true']) {
834
+ assert.equal(inferBashActivity(command), undefined, command);
835
+ }
836
+ for (const command of [undefined, '', ' ', null, 42]) {
837
+ assert.equal(inferBashActivity(command), undefined, String(command));
838
+ }
839
+ });
840
+
841
+ // A redirect puts the call's output in a file the classifier cannot name, and a
842
+ // substitution it cannot follow may hide any command at all — including a delete.
843
+ // Both keep the card generic rather than claiming a clean identity for the
844
+ // labelled half of the work.
845
+ test('a redirect or an unreadable substitution keeps the call generic', () => {
846
+ for (const command of [
847
+ 'git push > out.txt',
848
+ 'npm install > install.log',
849
+ 'git commit -m `cat msg`',
850
+ 'git add <(cat list)',
851
+ 'git log --oneline `git rev-parse HEAD`',
852
+ 'rg foo `cat files.txt`',
853
+ 'cat <(touch marker)',
854
+ 'diff <(sort a) <(sort b)',
855
+ 'ls <(rm -rf dist)',
856
+ ]) {
857
+ assert.equal(inferBashActivity(command), undefined, command);
858
+ }
859
+ });
860
+
861
+ // A quoted `>` is text the shell hands the program, never a redirect, so it must not
862
+ // turn a labelled call into a write; an unquoted one still does.
863
+ test('quoted text never turns a command into a write', () => {
864
+ assert.equal(inferBashActivity('git commit -m "fix: a > b"'), 'versioning');
865
+ assert.equal(inferBashActivity("git commit -m 'x > y' --amend"), 'versioning');
866
+ assert.equal(inferBashActivity('gh issue comment 7 --body "before > after"'), 'publishing');
867
+ assert.equal(inferBashActivity('git log --format="%h > %s" -3'), 'exploring');
868
+ assert.equal(inferBashActivity("printf '%s\\n' \"a > b\" | cat"), 'exploring');
869
+ for (const command of ['git commit -m x > out.txt', 'cat src/a > out', "echo 'a > b' > out.txt"]) {
870
+ assert.equal(inferBashActivity(command), undefined, command);
871
+ }
872
+ });
873
+
874
+ // ---- --help: a query on any family, and never a guess ----
875
+
876
+ test('a genuine help flag on a known command is inspection', () => {
877
+ for (const command of [
878
+ 'git --help',
879
+ 'git push --help',
880
+ 'git commit --help',
881
+ 'git add --help',
882
+ 'gh --help',
883
+ 'gh pr create --help',
884
+ 'gh issue edit --help',
885
+ 'gh stack submit --help',
886
+ 'pnpm test --help',
887
+ 'cargo clippy --help',
888
+ 'make install --help',
889
+ 'git push --help | head -40',
890
+ ]) {
891
+ assert.equal(inferBashActivity(command), 'exploring', command);
892
+ }
893
+ });
894
+
895
+ test('help detection never masks a mutation or a payload it cannot read', () => {
896
+ // The flag belongs to one segment; a neighbouring mutation still names the card.
897
+ assert.equal(inferBashActivity('git add -A && git commit --help'), 'versioning');
898
+ assert.equal(inferBashActivity('git commit -m x && gh pr create --help'), 'versioning');
899
+ // A quoted flag is text, not a request, so the command keeps its own activity.
900
+ assert.equal(inferBashActivity('git commit -m "--help"'), 'versioning');
901
+ assert.equal(inferBashActivity("git commit -m 'docs: mention --help'"), 'versioning');
902
+ assert.equal(inferBashActivity("printf 'git push --help'"), undefined);
903
+ assert.equal(inferBashActivity('echo "--help"'), undefined);
904
+ // An unknown program's help flag is a guess, and a payload flag can swallow the
905
+ // help flag, so neither is a query.
906
+ for (const command of [
907
+ 'unknown-tool --help',
908
+ './scripts/deploy.sh --help',
909
+ "bash -c 'git status' --help",
910
+ "node -e 'process.exit(0)' --help",
911
+ "python -c 'print(1)' --help",
912
+ 'git commit --help > help.txt',
913
+ 'git push --help `date`',
914
+ ]) {
915
+ assert.equal(inferBashActivity(command), undefined, command);
916
+ }
917
+ });
918
+
919
+ // `--help` right after an option may be that option's value: git commits a message
920
+ // spelled `--help` and gh posts it as a comment body, printing nothing. Which
921
+ // options take a value cannot be known here, so that reading only ever removes a
922
+ // query and never adds one — a mutation is never turned into exploration.
923
+ test('a help flag an option consumed as its value is not a query', () => {
924
+ for (const [command, activity] of [
925
+ ['git commit -m --help', 'versioning'],
926
+ ['git commit --message --help', 'versioning'],
927
+ ['git commit -a -m --help', 'versioning'],
928
+ ['gh issue comment 7 --body --help', 'publishing'],
929
+ ['gh pr create --title --help', 'publishing'],
930
+ ['git push --force --help', 'publishing'],
931
+ ['git commit -m --help\\ foo', 'versioning'],
932
+ ['git commit -m $OPTS --help', 'versioning'],
933
+ ["git commit -m '--help' --help", 'versioning'],
934
+ ]) {
935
+ assert.equal(inferBashActivity(command), activity, command);
936
+ }
937
+ // A value that holds escaped whitespace still leaves a real help flag after it.
938
+ for (const command of [
939
+ 'git commit -m foo\\ bar --help',
940
+ "git commit -m 'foo bar' --help",
941
+ 'git commit -m "x" --help',
942
+ 'git commit -m foo --help',
943
+ ]) {
944
+ assert.equal(inferBashActivity(command), 'exploring', command);
945
+ }
946
+ });
947
+
948
+ test('an escaped space keeps a help flag inside the value it belongs to', () => {
949
+ // The shell joins `foo\ --help` into one word, so git commits `foo --help` and no
950
+ // usage page is printed.
951
+ assert.equal(inferBashActivity('git commit -m foo\\ --help'), 'versioning');
952
+ assert.equal(inferBashActivity('gh issue comment 7 --body foo\\ --help'), 'publishing');
953
+ // An escaped backslash is a literal backslash, not a word boundary.
954
+ assert.equal(inferBashActivity('git commit -m a\\\\b --help'), 'exploring');
955
+ assert.equal(inferBashActivity('git commit -m a\\\\ --help'), 'exploring');
956
+ assert.equal(inferBashActivity('git commit -m a\\\\b\\ --help'), 'versioning');
957
+ // A line continuation joins the lines, so a help flag after it is its own argument.
958
+ assert.equal(inferBashActivity('git commit -m foo \\\n--help'), 'exploring');
959
+ assert.equal(inferBashActivity('git commit -m foo\\ \\\n--help'), 'versioning');
960
+ });
961
+
962
+ // ---- the segmenter ----
963
+
964
+ // The quote-aware splitter is the one segmenter, so a reader that needs the same
965
+ // split reads this one and never a second, quoting-blind copy: a separator inside
966
+ // quoted text is the program's argument, not a boundary between two commands.
967
+ test('the segmenter splits only where the shell would', () => {
968
+ assert.deepEqual(shellCommandSegments('git commit -m "a && b"'), ['git commit -m "a && b"']);
969
+ assert.deepEqual(shellCommandSegments('git log --format="%h; %s" -3'), ['git log --format="%h; %s" -3']);
970
+ assert.deepEqual(shellCommandSegments('git status && git diff'), ['git status ', ' git diff']);
971
+ assert.deepEqual(shellCommandSegments('pnpm test | tail -20'), ['pnpm test ', ' tail -20']);
972
+ assert.deepEqual(shellCommandSegments('a; b'), ['a', ' b']);
973
+ assert.deepEqual(shellCommandSegments('a\nb'), ['a', 'b']);
974
+ // A substitution contributes its own commands and leaves a placeholder behind.
975
+ assert.deepEqual(shellCommandSegments('echo $(git status && git diff)'), ['git status ', ' git diff', 'echo $_']);
976
+ // `&` inside a redirection is part of the redirection, never a separator.
977
+ assert.deepEqual(shellCommandSegments('make test 2>&1'), ['make test 2>&1']);
978
+ assert.deepEqual(shellCommandSegments('make test &>/dev/null'), ['make test &>/dev/null']);
979
+ assert.deepEqual(shellCommandSegments('a & b'), ['a ', ' b']);
980
+ });
981
+
982
+ // A table for the refusals the segmenter feeds the classifier with: what it cannot
983
+ // follow stays in one segment that names nothing, so the call is unclassified rather
984
+ // than split on a guess. Every row is a shape a real command takes.
985
+ test('the segmenter refuses to split what it cannot prove', () => {
986
+ const refusals = [
987
+ // Backticks are not followed, so the command inside is invisible.
988
+ ['git log --oneline `git rev-parse HEAD`', undefined],
989
+ // Process substitution is not followed either, and `>(...)` is a write.
990
+ ['diff <(sort a) <(sort b)', undefined],
991
+ ['cat > >(tee log.txt)', undefined],
992
+ // An unterminated `$(` abandons the split and keeps the whole remainder as ONE
993
+ // segment, so the hidden half is never a command of its own: only the visible
994
+ // prefix is read, and the call wears what that prefix names.
995
+ ['git status $(git diff', 'exploring'],
996
+ // An unterminated quote keeps its separator inside the text, so the second half is
997
+ // never a command of its own either — the call keeps the identity its one visible
998
+ // command names rather than claiming the check that was only written down.
999
+ ['git commit -m "unterminated && pnpm test', 'versioning'],
1000
+ // A quoted separator is one argument, and the call keeps the identity its own
1001
+ // command names.
1002
+ ['git commit -m "a; b" && pnpm test', 'checking'],
1003
+ // A quoted `$(...)` still contributes its own commands, so a check hidden in a
1004
+ // commit message is a check this card names.
1005
+ ['git commit -m "$(printf x)"', 'versioning'],
1006
+ ];
1007
+ for (const [command, activity] of refusals) {
1008
+ assert.equal(inferBashActivity(command), activity, command);
1009
+ }
1010
+ });
1011
+
1012
+ // Classification runs synchronously on every bash row the transcript repaints, so a
1013
+ // pathological command must never backtrack exponentially and freeze the host.
1014
+ test('adversarial assignment runs classify in bounded time', () => {
1015
+ for (const command of ['a='.repeat(26) + '"', 'a='.repeat(26) + '\\"', 'a='.repeat(26) + "'"]) {
1016
+ const start = performance.now();
1017
+ assert.equal(inferBashActivity(command), undefined, command);
1018
+ const elapsed = performance.now() - start;
1019
+ assert.ok(elapsed < 250, `${command} took ${elapsed}ms`);
1020
+ }
1021
+ });
1022
+
1023
+ // The user's own transcripts: a read-only call must not fall to the generic card just because
1024
+ // the program is a modern replacement for one the table already names.
1025
+ test('read-only inspection programs beyond the classic ones are exploring', () => {
1026
+ const exploring = [
1027
+ 'fd -e js lib', 'fdfind --type f src', 'fd . lib | head',
1028
+ 'bat README.md', 'batcat -n lib/a.js', 'eza -la', 'exa --tree', 'lsd -l',
1029
+ 'ag needle src', 'ack needle', 'zgrep x a.gz', 'fgrep -n x a',
1030
+ 'less README.md', 'man ls', 'id', 'hostname', 'uptime', 'free -h', 'printenv PATH', 'nproc',
1031
+ 'comm -12 a b', 'paste a b', 'rev a', 'tac a', 'seq 1 5',
1032
+ 'git stash show -p', 'git diff-tree --stat HEAD', 'git show-ref', 'git symbolic-ref HEAD', 'git cherry -v',
1033
+ 'gh cache list', 'gh secret list', 'gh variable list',
1034
+ 'docker ps -a', 'docker images', 'docker logs web', 'docker inspect web', 'kubectl get pods', 'kubectl describe pod x', 'kubectl logs x',
1035
+ 'npm ls', 'npm view react version', 'npm outdated', 'npm explain x', 'pnpm ls', 'pnpm why x', 'yarn why x', 'pip list', 'pip show x', 'pip freeze',
1036
+ ];
1037
+ for (const command of exploring) {
1038
+ assert.equal(inferBashActivity(command), 'exploring', command);
1039
+ }
1040
+ });
1041
+
1042
+ test('a CI run listing stays a check, as it was', () => {
1043
+ for (const command of ['gh run list', 'gh run view 123']) assert.equal(inferBashActivity(command), 'checking', command);
1044
+ });
1045
+
1046
+ test('fd names exploring only while it executes nothing', () => {
1047
+ for (const command of ['fd -x rm {}', 'fd --exec rm {}', 'fd -X rm', 'fd --exec-batch rm', 'fd . -x sh -c "echo x"']) {
1048
+ assert.notEqual(inferBashActivity(command), 'exploring', command);
1049
+ }
1050
+ });
1051
+
1052
+ test('a composition of reads with neutral separators is exploring, and one unnamed segment still keeps it generic', () => {
1053
+ assert.equal(inferBashActivity('fd -e js lib; echo ---; bat lib/a.js && pwd'), 'exploring');
1054
+ assert.equal(inferBashActivity('cd /tmp && fd x && echo done'), 'exploring');
1055
+ assert.equal(inferBashActivity('fd -e js lib; frobnicate --now'), undefined);
1056
+ });
1057
+
1058
+ // ---- T7: the census rules ----
1059
+ //
1060
+ // A census of the user's own 6000 most recent distinct calls left 32.3% of them on the
1061
+ // generic `$ bash`, and most of that residue was not ambiguity: it was a command this
1062
+ // classifier could read if it stripped the same prefix the shell does. Every rule below
1063
+ // was judged against one standard — a heading must never claim work the call did not
1064
+ // do — so the payloads nobody can read still stay generic on purpose.
1065
+
1066
+ // A git or gh global option names how the tool runs, never what it does, and it stands
1067
+ // between the program and the subcommand that names the card. `-C <dir>`, `-c <k=v>`,
1068
+ // `--git-dir`, `--work-tree`, `--no-pager`, `-P`, `--no-optional-locks` and
1069
+ // `--paginate` are stripped in one place, so no family has to know about them.
1070
+ test('git and gh global options never hide the subcommand', () => {
1071
+ for (const command of [
1072
+ 'git -C /repo status',
1073
+ 'git -C /repo --no-pager log -1',
1074
+ 'git -c core.pager=cat log -1',
1075
+ 'git --no-pager log -1',
1076
+ 'git -P status',
1077
+ 'git --no-optional-locks status',
1078
+ 'git --git-dir=/repo/.git status',
1079
+ 'git --git-dir /repo/.git status',
1080
+ 'git --work-tree=/repo status',
1081
+ 'gh --paginate pr list',
1082
+ 'gh -R owner/name pr view 12',
1083
+ ]) {
1084
+ assert.equal(inferBashActivity(command), 'exploring', command);
1085
+ }
1086
+ assert.equal(inferBashActivity('git -C /repo add .'), 'versioning');
1087
+ assert.equal(inferBashActivity('git --no-pager fetch origin'), 'versioning');
1088
+ assert.equal(inferBashActivity('git -C /repo push'), 'publishing');
1089
+ assert.equal(inferBashActivity('git -C /repo --no-pager log -1 | head -3'), 'exploring');
1090
+ // An option this list does not know is not guessed at: the card stays generic.
1091
+ assert.equal(inferBashActivity('git --unknown-option status'), undefined);
1092
+ });
1093
+
1094
+ // A program named by a path is the program the path resolves to, so a virtualenv's
1095
+ // pytest and a project's own vitest are the checks they are — while a path to a program
1096
+ // this classifier does not name still matches nothing.
1097
+ test('a program named by a path classifies as its basename', () => {
1098
+ for (const [command, activity] of [
1099
+ ['/usr/bin/git status', 'exploring'],
1100
+ ['/opt/homebrew/bin/git -C /repo log -1', 'exploring'],
1101
+ ['./node_modules/.bin/vitest run a.test.js', 'checking'],
1102
+ ['.venv/bin/pytest -q', 'checking'],
1103
+ ['~/.local/bin/ruff check .', 'checking'],
1104
+ ['./scripts/deploy.sh', undefined],
1105
+ ['/opt/tools/unknown-tool --flag', undefined],
1106
+ ]) {
1107
+ assert.equal(inferBashActivity(command), activity, command);
1108
+ }
1109
+ });
1110
+
1111
+ // A wrapper changes how the command runs, not what it does, so the command behind it
1112
+ // names the card. `sudo` is deliberately absent: it runs the command as another user,
1113
+ // and no heading may file a privileged action as the read it resembles. `timeout` keeps
1114
+ // the reading this suite already pinned — only a check is unwrapped.
1115
+ test('a wrapper names the command it runs, and sudo never names anything', () => {
1116
+ for (const [command, activity] of [
1117
+ ['env FOO=1 git status', 'exploring'],
1118
+ ['env -i FOO=1 git status', 'exploring'],
1119
+ ['env --unset=FOO git status', 'exploring'],
1120
+ ['nice -n 10 git status', 'exploring'],
1121
+ ['nice -10 git status', 'exploring'],
1122
+ ['nohup git status', 'exploring'],
1123
+ ['stdbuf -oL git status', 'exploring'],
1124
+ ['stdbuf -i0 -o0 git status', 'exploring'],
1125
+ ['command git status', 'exploring'],
1126
+ ['exec git status', 'exploring'],
1127
+ ['ionice -c2 -n7 git status', 'exploring'],
1128
+ ['time -p pnpm test', 'checking'],
1129
+ ['nohup npm test', 'checking'],
1130
+ ['env CI=1 pnpm test', 'checking'],
1131
+ ['nice -n 5 git -C /repo fetch', 'versioning'],
1132
+ ['command -v git', 'exploring'],
1133
+ ['sudo git status', undefined],
1134
+ ['sudo -u root pnpm test', undefined],
1135
+ ['env -S "git status"', undefined],
1136
+ ['env', undefined],
1137
+ ['timeout 5 git status', undefined],
1138
+ ]) {
1139
+ assert.equal(inferBashActivity(command), activity, command);
1140
+ }
1141
+ });
1142
+
1143
+ // Moving between branches, fetching, merging, staging a patch and rewriting local
1144
+ // history all move work inside this machine and publish nothing: they are the one
1145
+ // versioning identity. A deletion the destructive table already names keeps its warning.
1146
+ test('the git verbs that move work name the versioning activity', () => {
1147
+ for (const command of [
1148
+ 'git fetch origin',
1149
+ 'git fetch --all --prune',
1150
+ 'git pull',
1151
+ 'git pull --rebase',
1152
+ 'git merge main',
1153
+ 'git merge --no-ff feat/x',
1154
+ 'git checkout main',
1155
+ 'git checkout -b feat/x',
1156
+ 'git switch main',
1157
+ 'git switch -c feat/y',
1158
+ 'git restore --staged .',
1159
+ 'git reset',
1160
+ 'git reset HEAD~1',
1161
+ 'git revert abc1234',
1162
+ 'git apply fix.patch',
1163
+ 'git am 0001-a.patch',
1164
+ 'git mv old.ts new.ts',
1165
+ 'git rm --cached a.txt',
1166
+ 'git branch feat/x',
1167
+ 'git branch -m old new',
1168
+ 'git branch -d old',
1169
+ 'git tag v1.0.0',
1170
+ 'git tag -a v1 -m x',
1171
+ 'git tag -d v1.0.0',
1172
+ 'git remote add origin /tmp/repo.git',
1173
+ 'git remote set-url origin /tmp/other.git',
1174
+ 'git remote rename a b',
1175
+ 'git stash',
1176
+ 'git stash push -m wip',
1177
+ 'git stash pop',
1178
+ 'git stash apply',
1179
+ 'git stash save wip',
1180
+ 'gh pr checkout 12',
1181
+ ]) {
1182
+ assert.equal(inferBashActivity(command), 'versioning', command);
1183
+ }
1184
+ // A deletion the destructive table already names keeps its warning, and a listing
1185
+ // stays the inspection it is.
1186
+ for (const command of ['git branch -D feat/x', 'git stash drop', 'git rm a.txt', 'git reset --hard']) {
1187
+ assert.equal(inferBashActivity(command), 'destructive', command);
1188
+ }
1189
+ for (const command of ['git branch', 'git branch -a', 'git tag', 'git tag -l "v*"', 'git stash list', 'git worktree list', 'git remote -v']) {
1190
+ assert.equal(inferBashActivity(command), 'exploring', command);
1191
+ }
1192
+ });
1193
+
1194
+ // A subshell's opening `(` stands before the program without a space, and a CI rerun is
1195
+ // work this machine sent to the remote: neither may hide the command it names.
1196
+ test('a subshell prefix and a CI rerun name the command they carry', () => {
1197
+ assert.equal(inferBashActivity('(git status)'), 'exploring');
1198
+ assert.equal(inferBashActivity('(cd /repo && git fetch)'), 'versioning');
1199
+ assert.equal(inferBashActivity('(gh pr create --title x --body y)'), 'publishing');
1200
+ assert.equal(inferBashActivity('gh run rerun 123'), 'publishing');
1201
+ assert.equal(inferBashActivity('gh run cancel 123 --force'), 'publishing');
1202
+ });
1203
+
1204
+ // A worktree the call creates is a checkout this machine did not have, so it is the
1205
+ // build-up identity; the lock files beside it are local git metadata like the index.
1206
+ test('a worktree the call creates prepares the machine', () => {
1207
+ for (const command of [
1208
+ 'git worktree add ../x main',
1209
+ 'git worktree add -b feat/x ../x main',
1210
+ ]) {
1211
+ assert.equal(inferBashActivity(command), 'preparing', command);
1212
+ }
1213
+ for (const command of ['git worktree lock ../x', 'git worktree unlock ../x']) {
1214
+ assert.equal(inferBashActivity(command), 'versioning', command);
1215
+ }
1216
+ assert.equal(inferBashActivity('git worktree list'), 'exploring');
1217
+ });
1218
+
1219
+ // Programs the transcripts read with name inspection: the journal, the kernel log, the
1220
+ // unit state, a package's own query verbs, and a tool's read-only words. The noun before
1221
+ // the read word is transparent, so `herdr plugin list` is the list it is while
1222
+ // `herdr plugin install` still names nothing.
1223
+ test('the read-only programs of the census name the exploring activity', () => {
1224
+ for (const command of [
1225
+ 'journalctl -u pi -n 50',
1226
+ 'journalctl --since today',
1227
+ 'dmesg -T',
1228
+ 'systemctl status pi',
1229
+ 'systemctl is-active herdr',
1230
+ 'systemctl --user list-units',
1231
+ 'systemctl show -p MainPID pi',
1232
+ 'systemctl cat pi.service',
1233
+ 'pacman -Qo /usr/bin/git',
1234
+ 'pacman -Qi git',
1235
+ 'pacman -Qe',
1236
+ 'pacman -Ss ripgrep',
1237
+ 'pacman -Si git',
1238
+ 'brew list',
1239
+ 'brew info jq',
1240
+ 'brew search jq',
1241
+ 'brew outdated',
1242
+ 'apt list --installed',
1243
+ 'apt show jq',
1244
+ 'apt search jq',
1245
+ 'apt policy jq',
1246
+ 'mise ls',
1247
+ 'mise current',
1248
+ 'mise which node',
1249
+ 'mise where node',
1250
+ 'mise doctor',
1251
+ 'mise ls-remote node',
1252
+ 'nvim --version',
1253
+ 'tmux list-sessions',
1254
+ 'tmux show-options -g',
1255
+ 'tmux display-message -p x',
1256
+ 'herdr --version',
1257
+ 'herdr plugin list',
1258
+ 'herdr config show',
1259
+ 'pi --version',
1260
+ 'pi mcp list',
1261
+ 'gentle-ai version',
1262
+ 'gentle-shell --version',
1263
+ 'odd-worktree list',
1264
+ // These tools print their usage page like every other known program.
1265
+ 'pi --help',
1266
+ 'herdr plugin --help',
1267
+ ]) {
1268
+ assert.equal(inferBashActivity(command), 'exploring', command);
1269
+ }
1270
+ // Only a read word is a read: the same tools' other verbs name nothing.
1271
+ for (const command of ['herdr plugin install x', 'pi install x', 'herdr server', 'systemctl restart pi', 'pacman -Syu', 'pacman -Sc', 'apt install jq']) {
1272
+ assert.notEqual(inferBashActivity(command), 'exploring', command);
1273
+ }
1274
+ });
1275
+
1276
+ // A script names a check only while its name is one. `verify` and a namespaced
1277
+ // `test:unit` are the same family, while a name that carries a fix, a write, a format, a
1278
+ // watch, a dev server or a start is not a check at all — and a bare `npm ci` still
1279
+ // installs, because `ci` is a script only when the package manager runs it as one.
1280
+ test('a package script names a check only while its name is a check', () => {
1281
+ for (const command of [
1282
+ 'npm run verify',
1283
+ 'pnpm verify',
1284
+ 'npm run ci',
1285
+ 'pnpm run ci',
1286
+ 'pnpm run test:unit',
1287
+ 'npm run lint:ci',
1288
+ 'npm run check:runtime-modules',
1289
+ 'npm run build',
1290
+ ]) {
1291
+ assert.equal(inferBashActivity(command), 'checking', command);
1292
+ }
1293
+ for (const command of [
1294
+ 'npm run test:watch',
1295
+ 'npm run lint:fix',
1296
+ 'npm run build:watch',
1297
+ 'npm run format',
1298
+ 'npm run dev',
1299
+ 'npm run start',
1300
+ 'npm run serve',
1301
+ 'npm run fix:lint',
1302
+ 'npm run write:docs',
1303
+ ]) {
1304
+ assert.equal(inferBashActivity(command), undefined, command);
1305
+ }
1306
+ assert.equal(inferBashActivity('npm ci'), 'preparing');
1307
+ });
1308
+
1309
+ // Creating a temporary path, changing a mode or an owner and renaming a file are the
1310
+ // build-up identity, exactly as `cp` and `mkdir` already are: none of them deletes
1311
+ // anything a reader could not rename back.
1312
+ test('temporary paths, modes, owners and renames prepare the machine', () => {
1313
+ for (const command of ['mktemp -d', 'mktemp', 'chmod +x scripts/run.sh', 'chmod -R 755 build', 'chown me tmp/file', 'mv old.txt new.txt', 'mise install node@20', 'mise use -g node@20']) {
1314
+ assert.equal(inferBashActivity(command), 'preparing', command);
1315
+ }
1316
+ });
1317
+
1318
+ // `exit`, `umask`, `unset`, `local`, `read`, `wait`, `return` and `:` change the shell
1319
+ // the call runs in and nothing else, so the named work beside them still decides the
1320
+ // card — and each on its own names nothing.
1321
+ test('shell bookkeeping builtins are neutral', () => {
1322
+ for (const [command, activity] of [
1323
+ ['git status && exit 0', 'exploring'],
1324
+ ['git commit -m x && umask 022', 'versioning'],
1325
+ ['git status; unset FOO', 'exploring'],
1326
+ ['pnpm test && :', 'checking'],
1327
+ ['pnpm test && wait', 'checking'],
1328
+ ['exit 1', undefined],
1329
+ ['umask 022', undefined],
1330
+ ['local x=1', undefined],
1331
+ ['read -r answer', undefined],
1332
+ ['wait', undefined],
1333
+ ['return 0', undefined],
1334
+ [':', undefined],
1335
+ // A bare assignment keeps its value whole: the path inside it is a value, never the
1336
+ // program the segment runs, so the neutral reading survives a path with spaces.
1337
+ ['LOG="/var/log/my app.log"', undefined],
1338
+ ['LOG="/var/log/my app.log" && wc -l app.log', 'exploring'],
1339
+ // A comment line is prose the shell never runs, so it keeps no card generic.
1340
+ ['# a note', undefined],
1341
+ ['git status;\n# a note\ngit diff', 'exploring'],
1342
+ ['git add -A\n# stage it all\ngit commit -m x', 'versioning'],
1343
+ ]) {
1344
+ assert.equal(inferBashActivity(command), activity, command);
1345
+ }
1346
+ });
1347
+
1348
+ // Ending a process removes no file and rewrites no history, and no family here names
1349
+ // it: `kill` and `pkill` stay generic rather than wearing the deletion warning.
1350
+ test('ending a process names no family, so kill and pkill stay generic', () => {
1351
+ for (const command of ['kill 1234', 'kill -9 1234', 'pkill -f node', 'killall node']) {
1352
+ assert.equal(inferBashActivity(command), undefined, command);
1353
+ }
1354
+ });
1355
+
1356
+ // A heredoc body is the text the command reads, never a command of its own: folding it
1357
+ // into the segment that opens it is what keeps a multi-line commit message from leaking
1358
+ // its words into the list of commands the classifier reads.
1359
+ test('a heredoc body belongs to the command that reads it', () => {
1360
+ assert.deepEqual(shellCommandSegments("cat <<'EOF'\nhello world\nEOF"), ["cat <<'EOF'\nhello world\nEOF"]);
1361
+ assert.deepEqual(shellCommandSegments('a <<-X\n\tbody\n\tX\nb'), ['a <<-X\n\tbody\n\tX', 'b']);
1362
+ // The words of a commit message are that message, so the call is the commit it is.
1363
+ assert.equal(inferBashActivity("git commit -F - <<'EOF'\nMerge branch 'main' of example\nEOF"), 'versioning');
1364
+ assert.equal(inferBashActivity("gh pr create --title x --body \"$(cat <<'EOF'\nsome body\nEOF\n)\""), 'publishing');
1365
+ assert.equal(inferBashActivity("git commit -m \"$(cat <<'EOF'\nMerge branch 'main'\n\nbody\nEOF\n)\""), 'versioning');
1366
+ // A heredoc that writes a file is still a write, and a payload this classifier cannot
1367
+ // read is still unnamed.
1368
+ assert.equal(inferBashActivity("cat > notes.txt <<'EOF'\nhello\nEOF"), undefined);
1369
+ assert.equal(inferBashActivity("python3 - <<'PY'\nprint(1)\nPY"), undefined);
1370
+ });
1371
+
1372
+ // The payloads nobody can read stay generic on purpose: an inline script, an interpreter
1373
+ // handed a file to run, an in-place editor, a command that writes its output into a
1374
+ // file, a privileged invocation, a shell fed by a pipe, and `eval`.
1375
+ test('the payloads this classifier cannot read stay generic on purpose', () => {
1376
+ for (const command of [
1377
+ "python3 -c 'print(1)'",
1378
+ "node -e 'console.log(1)'",
1379
+ "bash -c 'echo hi'",
1380
+ 'node scripts/build.mjs',
1381
+ 'python3 tools/run.py --fast',
1382
+ 'bash scripts/deploy.sh',
1383
+ "sed -i 's/a/b/' file.txt",
1384
+ "perl -pi -e 's/a/b/' file.txt",
1385
+ 'cat > notes.txt',
1386
+ 'echo hi | sh',
1387
+ 'eval "$(cat setup.sh)"',
1388
+ 'xargs rm -rf',
1389
+ 'unknown-tool --flag',
1390
+ ]) {
1391
+ assert.equal(inferBashActivity(command), undefined, command);
1392
+ }
1393
+ });
1394
+
1395
+ // Every rule above runs on each repainted bash row, so a long adversarial command must
1396
+ // still classify in bounded time.
1397
+ test('a long adversarial command classifies in bounded time', () => {
1398
+ for (const command of [
1399
+ 'git -C /x '.repeat(40) + 'status',
1400
+ 'env A=1 '.repeat(250) + 'git status',
1401
+ "cat <<'EOF'\n".repeat(160) + 'x',
1402
+ 'herdr '.repeat(50) + 'list',
1403
+ 'git -C ' + 'a'.repeat(500) + ' status',
1404
+ ]) {
1405
+ const start = performance.now();
1406
+ inferBashActivity(command);
1407
+ const elapsed = performance.now() - start;
1408
+ assert.ok(elapsed < 250, `${command.slice(0, 20)}… took ${elapsed}ms`);
1409
+ }
1410
+ });
1411
+
1412
+ // The family the card wears for a checkout the call removes, beside the ones it only
1413
+ // creates: the censused removal rows were the last silent gap in the table.
1414
+ test('a removed checkout wears the destructive family, a created one prepares', () => {
1415
+ assert.equal(inferBashActivity('git worktree remove ../old'), 'destructive');
1416
+ assert.equal(inferBashActivity('git worktree prune'), 'destructive');
1417
+ assert.equal(inferBashActivity('git worktree add ../new -b feat/x'), 'preparing');
1418
+ assert.equal(inferBashActivity('git worktree list'), 'exploring');
1419
+ });