@vibe-agent-toolkit/utils 0.2.0-rc.2 → 0.2.0-rc.4

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 (150) hide show
  1. package/README.md +26 -15
  2. package/dist/compare-code-units.d.ts +28 -0
  3. package/dist/compare-code-units.d.ts.map +1 -0
  4. package/dist/compare-code-units.js +33 -0
  5. package/dist/compare-code-units.js.map +1 -0
  6. package/dist/crawl-timing.d.ts +657 -0
  7. package/dist/crawl-timing.d.ts.map +1 -0
  8. package/dist/crawl-timing.js +765 -0
  9. package/dist/crawl-timing.js.map +1 -0
  10. package/dist/crawl.d.ts +2 -4
  11. package/dist/crawl.d.ts.map +1 -1
  12. package/dist/crawl.js +2 -4
  13. package/dist/crawl.js.map +1 -1
  14. package/dist/file-crawler.d.ts +22 -0
  15. package/dist/file-crawler.d.ts.map +1 -1
  16. package/dist/file-crawler.js +31 -7
  17. package/dist/file-crawler.js.map +1 -1
  18. package/dist/fs-utils.d.ts +17 -0
  19. package/dist/fs-utils.d.ts.map +1 -1
  20. package/dist/fs-utils.js +69 -0
  21. package/dist/fs-utils.js.map +1 -1
  22. package/dist/fs.d.ts +3 -1
  23. package/dist/fs.d.ts.map +1 -1
  24. package/dist/fs.js +5 -1
  25. package/dist/fs.js.map +1 -1
  26. package/dist/git-run.d.ts +167 -0
  27. package/dist/git-run.d.ts.map +1 -0
  28. package/dist/git-run.js +154 -0
  29. package/dist/git-run.js.map +1 -0
  30. package/dist/git-snapshot.d.ts +181 -0
  31. package/dist/git-snapshot.d.ts.map +1 -0
  32. package/dist/git-snapshot.js +232 -0
  33. package/dist/git-snapshot.js.map +1 -0
  34. package/dist/git-tracker.d.ts +94 -1
  35. package/dist/git-tracker.d.ts.map +1 -1
  36. package/dist/git-tracker.js +135 -3
  37. package/dist/git-tracker.js.map +1 -1
  38. package/dist/git-utils.d.ts +38 -0
  39. package/dist/git-utils.d.ts.map +1 -1
  40. package/dist/git-utils.js +103 -80
  41. package/dist/git-utils.js.map +1 -1
  42. package/dist/git.d.ts +12 -4
  43. package/dist/git.d.ts.map +1 -1
  44. package/dist/git.js +12 -4
  45. package/dist/git.js.map +1 -1
  46. package/dist/gitignore-checker.d.ts.map +1 -1
  47. package/dist/gitignore-checker.js +6 -3
  48. package/dist/gitignore-checker.js.map +1 -1
  49. package/dist/index.d.ts +24 -18
  50. package/dist/index.d.ts.map +1 -1
  51. package/dist/index.js +49 -30
  52. package/dist/index.js.map +1 -1
  53. package/dist/path-core.d.ts +1 -1
  54. package/dist/path-core.js +1 -1
  55. package/dist/project-utils.d.ts.map +1 -1
  56. package/dist/project-utils.js +6 -3
  57. package/dist/project-utils.js.map +1 -1
  58. package/dist/project.d.ts +7 -5
  59. package/dist/project.d.ts.map +1 -1
  60. package/dist/project.js +7 -5
  61. package/dist/project.js.map +1 -1
  62. package/dist/safe-exec.d.ts +38 -10
  63. package/dist/safe-exec.d.ts.map +1 -1
  64. package/dist/safe-exec.js +88 -19
  65. package/dist/safe-exec.js.map +1 -1
  66. package/dist/skill-test/index.d.ts +1 -1
  67. package/dist/skill-test/index.d.ts.map +1 -1
  68. package/dist/skill-test/index.js +1 -1
  69. package/dist/skill-test/index.js.map +1 -1
  70. package/dist/skill-test/spawn-claude.d.ts +28 -0
  71. package/dist/skill-test/spawn-claude.d.ts.map +1 -1
  72. package/dist/skill-test/spawn-claude.js +51 -2
  73. package/dist/skill-test/spawn-claude.js.map +1 -1
  74. package/dist/skill-test/transcript.d.ts +41 -2
  75. package/dist/skill-test/transcript.d.ts.map +1 -1
  76. package/dist/skill-test/transcript.js +47 -3
  77. package/dist/skill-test/transcript.js.map +1 -1
  78. package/dist/test-helpers.d.ts +185 -13
  79. package/dist/test-helpers.d.ts.map +1 -1
  80. package/dist/test-helpers.js +274 -27
  81. package/dist/test-helpers.js.map +1 -1
  82. package/dist/testing.d.ts +73 -3
  83. package/dist/testing.d.ts.map +1 -1
  84. package/dist/testing.js +93 -3
  85. package/dist/testing.js.map +1 -1
  86. package/dist/text-content.d.ts +197 -0
  87. package/dist/text-content.d.ts.map +1 -0
  88. package/dist/text-content.js +348 -0
  89. package/dist/text-content.js.map +1 -0
  90. package/dist/text-file.d.ts +45 -0
  91. package/dist/text-file.d.ts.map +1 -0
  92. package/dist/text-file.js +53 -0
  93. package/dist/text-file.js.map +1 -0
  94. package/dist/text.d.ts +16 -0
  95. package/dist/text.d.ts.map +1 -0
  96. package/dist/text.js +16 -0
  97. package/dist/text.js.map +1 -0
  98. package/dist/timing-dump.d.ts +136 -0
  99. package/dist/timing-dump.d.ts.map +1 -0
  100. package/dist/timing-dump.js +230 -0
  101. package/dist/timing-dump.js.map +1 -0
  102. package/eslint/README.md +105 -3
  103. package/eslint/index.cjs +50 -0
  104. package/eslint/index.d.cts +14 -4
  105. package/eslint/rules/no-bare-symlink-in-tests.cjs +200 -0
  106. package/eslint/rules/no-process-exit-in-phase.cjs +117 -0
  107. package/eslint/rules/no-raw-text-decode.cjs +296 -0
  108. package/eslint/rules/no-self-package-import.cjs +157 -0
  109. package/package.json +13 -8
  110. package/dist/link-auth/build-headers.d.ts +0 -34
  111. package/dist/link-auth/build-headers.d.ts.map +0 -1
  112. package/dist/link-auth/build-headers.js +0 -58
  113. package/dist/link-auth/build-headers.js.map +0 -1
  114. package/dist/link-auth/expand-macro.d.ts +0 -38
  115. package/dist/link-auth/expand-macro.d.ts.map +0 -1
  116. package/dist/link-auth/expand-macro.js +0 -133
  117. package/dist/link-auth/expand-macro.js.map +0 -1
  118. package/dist/link-auth/macros.yaml +0 -50
  119. package/dist/link-auth/resolve-token.d.ts +0 -83
  120. package/dist/link-auth/resolve-token.d.ts.map +0 -1
  121. package/dist/link-auth/resolve-token.js +0 -101
  122. package/dist/link-auth/resolve-token.js.map +0 -1
  123. package/dist/link-auth/resolve.d.ts +0 -102
  124. package/dist/link-auth/resolve.d.ts.map +0 -1
  125. package/dist/link-auth/resolve.js +0 -66
  126. package/dist/link-auth/resolve.js.map +0 -1
  127. package/dist/link-auth/rewrite.d.ts +0 -52
  128. package/dist/link-auth/rewrite.d.ts.map +0 -1
  129. package/dist/link-auth/rewrite.js +0 -102
  130. package/dist/link-auth/rewrite.js.map +0 -1
  131. package/dist/link-auth/select-provider.d.ts +0 -30
  132. package/dist/link-auth/select-provider.d.ts.map +0 -1
  133. package/dist/link-auth/select-provider.js +0 -55
  134. package/dist/link-auth/select-provider.js.map +0 -1
  135. package/dist/link-auth/template.d.ts +0 -40
  136. package/dist/link-auth/template.d.ts.map +0 -1
  137. package/dist/link-auth/template.js +0 -89
  138. package/dist/link-auth/template.js.map +0 -1
  139. package/dist/link-auth/transforms.d.ts +0 -46
  140. package/dist/link-auth/transforms.d.ts.map +0 -1
  141. package/dist/link-auth/transforms.js +0 -52
  142. package/dist/link-auth/transforms.js.map +0 -1
  143. package/dist/template-entry.d.ts +0 -10
  144. package/dist/template-entry.d.ts.map +0 -1
  145. package/dist/template-entry.js +0 -10
  146. package/dist/template-entry.js.map +0 -1
  147. package/dist/template.d.ts +0 -7
  148. package/dist/template.d.ts.map +0 -1
  149. package/dist/template.js +0 -18
  150. package/dist/template.js.map +0 -1
@@ -0,0 +1,230 @@
1
+ /**
2
+ * The on-disk plumbing every VAT timing seam shares.
3
+ *
4
+ * Two seams write per-process JSON dumps to an operator-named directory:
5
+ * `@vibe-agent-toolkit/resources`' `parse-timing.ts` (which pass inside a parser
6
+ * owns the time) and this package's `crawl-timing.ts` (which contributor or
7
+ * crawler owns the time). They sit in different packages because `crawl-timing`
8
+ * has to bracket `GitTracker`, which is here — so this module lives at the lower
9
+ * of the two and is exported for the higher one. What they
10
+ * MEASURE could not be less alike — one axis is a closed enum of parser passes,
11
+ * the other is an open set of contributor ids — but every property that makes
12
+ * the *file* trustworthy is identical between them, and the lab's
13
+ * `harness/dumps.ts` already says so from the reading end:
14
+ *
15
+ * 1. A directory that cannot be created is reported the moment the seam turns
16
+ * on, while there is still a run to abandon — never at exit, where a failure
17
+ * costs the whole measurement.
18
+ * 2. A dump failure is written to **stderr and never thrown**. These run from
19
+ * an `exit` listener, where a throw changes the process's exit behaviour, and
20
+ * they must never touch stdout, which carries vat's report.
21
+ * 3. A pid can file more than one dump, and the name is CLAIMED rather than
22
+ * checked. `vat validate` spawns the vat binary once per phase and pids are
23
+ * reused, so `<stem>-<pid>.json` genuinely collides; worse, worker threads
24
+ * SHARE their parent's pid, so a thread pool's whole cohort competes for one
25
+ * `<stem>-<pid>` sequence at the same instant. The name gains a counter
26
+ * rather than overwriting, and the counter is settled by
27
+ * {@link EXCLUSIVE_CREATE} so the OS — not a check-then-write gap — decides
28
+ * who won it.
29
+ * 4. The process's own wall and CPU time is read ONCE, at dump time. It is a
30
+ * lifetime figure for the process and never a duration of the measured work;
31
+ * its value is the RATIO, which tells a reader whether the wall-timed
32
+ * brackets above it were competing with a loaded machine.
33
+ *
34
+ * ⚠️ **A reader must never SUM these across dumps.** Point 3 means one
35
+ * command routinely files several, and a vat command's phase processes
36
+ * overlap in time — so summing their lifetimes counts the same wall clock
37
+ * more than once and produces a "total" longer than the command took. The
38
+ * figure is per process, and the only honest aggregate over several is the
39
+ * per-process ratio read one dump at a time. The `crawl` facet keeps one
40
+ * record per dump and publishes no total for exactly this reason; `parse`
41
+ * still sums, which is review finding F2 (2026-08-14) and is annotated at
42
+ * `facets/parse/dump.ts`. This list is where both seams learn what makes a
43
+ * dump trustworthy, so the hazard belongs here rather than only beside the
44
+ * consumer that already fixed it.
45
+ *
46
+ * Writing that twice would give two seams two chances to diverge on the one
47
+ * thing a reader has to be able to trust identically. What each seam keeps for
48
+ * itself is its accumulator shape, its dump body and the noun it is called by.
49
+ */
50
+ import { writeFileSync } from 'node:fs';
51
+ import { safePath } from './path-core.js';
52
+ import { mkdirSyncReal } from './path-utils.js';
53
+ /** `process.cpuUsage()` reports microseconds; a dump reports milliseconds. */
54
+ const MICROSECONDS_PER_MS = 1000;
55
+ /** `process.uptime()` reports seconds; a dump reports milliseconds. */
56
+ const MS_PER_SECOND = 1000;
57
+ /**
58
+ * Ceiling on the pid-collision search. A directory holding this many dumps for
59
+ * one pid is a runaway, not a collision, and giving up on a reported line is a
60
+ * better outcome than spinning.
61
+ *
62
+ * Exhausting it does NOT fall back to overwriting the last slot. That was the
63
+ * old behaviour, and it destroyed a dump for the same reason the check-then-
64
+ * write gap did — silently, and precisely when the directory was busiest.
65
+ */
66
+ export const MAX_DUMP_COLLISIONS = 1000;
67
+ /**
68
+ * The `writeFileSync` flag that makes claiming a name atomic.
69
+ *
70
+ * `wx` is create-exclusive: the OS fails the call with `EEXIST` when the path
71
+ * already exists, so exactly one caller wins each name no matter how many are
72
+ * racing for it. Asking `existsSync` first and writing second is two operations
73
+ * with a gap in between, and threads sharing a pid land in that gap routinely —
74
+ * a measured 8-worker parse pool lost 6 of 9 dumps to it, reporting 44 of 172
75
+ * documents as if that were the whole run.
76
+ */
77
+ const EXCLUSIVE_CREATE = 'wx';
78
+ /** How the failure line names the ceiling case, so it reads unlike an OS error. */
79
+ const CEILING_DETAIL = `every name up to the ${String(MAX_DUMP_COLLISIONS)}-collision ceiling was already claimed`;
80
+ /**
81
+ * Reduce a raw env value to a directory or `null`.
82
+ *
83
+ * An empty-string value counts as absent: `VAT_PARSE_TIMING=` in a shell profile
84
+ * is a variable somebody meant to unset, not a request to dump into the process's
85
+ * working directory.
86
+ *
87
+ * @param raw - The env var's value, if set
88
+ * @returns The dump directory, or `null` when the seam is off
89
+ */
90
+ export function normalizeTimingDirectory(raw) {
91
+ return raw === undefined || raw === '' ? null : raw;
92
+ }
93
+ /**
94
+ * Report a dump problem on stderr.
95
+ *
96
+ * Never throws and never touches stdout: vat's stdout carries a YAML report, and
97
+ * an exit handler that threw would change the process's exit behaviour.
98
+ *
99
+ * @param noun - What the seam is called, so a reader knows which instrument failed
100
+ * @param target - Path the failure concerns
101
+ * @param error - Whatever was caught
102
+ */
103
+ export function reportTimingDumpFailure(noun, target, error) {
104
+ const detail = error instanceof Error ? error.message : String(error);
105
+ process.stderr.write(`vat: ${noun} dump failed for ${target}: ${detail}\n`);
106
+ }
107
+ /**
108
+ * Create the dump directory, swallowing failure.
109
+ *
110
+ * Done once when the seam turns on rather than at exit, so a bad path is
111
+ * reported while there is still a run to abandon — and so the exit handler does
112
+ * the minimum possible work.
113
+ *
114
+ * @param noun - What the seam is called, for the failure line
115
+ * @param directory - Directory dumps will be written to
116
+ */
117
+ export function ensureTimingDirectory(noun, directory) {
118
+ try {
119
+ mkdirSyncReal(directory, { recursive: true });
120
+ }
121
+ catch (error) {
122
+ reportTimingDumpFailure(noun, directory, error);
123
+ }
124
+ }
125
+ /**
126
+ * Read this process's lifetime wall and CPU time.
127
+ *
128
+ * Called ONCE per dump — two syscalls for a whole run, which is why the process
129
+ * level can afford a CPU reading that a per-bracket level cannot. Deliberately
130
+ * not an accumulator and deliberately not reset: it describes the process, not
131
+ * the measurement window.
132
+ *
133
+ * @returns Wall clock and CPU since process start, in milliseconds
134
+ */
135
+ export function readTimingProcess() {
136
+ const cpu = process.cpuUsage();
137
+ return {
138
+ wallMs: process.uptime() * MS_PER_SECOND,
139
+ cpuUserMs: cpu.user / MICROSECONDS_PER_MS,
140
+ cpuSystemMs: cpu.system / MICROSECONDS_PER_MS,
141
+ };
142
+ }
143
+ /**
144
+ * The nth candidate name in one pid's dump sequence.
145
+ *
146
+ * @param directory - Directory dumps are written to
147
+ * @param stem - Basename and pid, already joined
148
+ * @param collision - 0 for the unsuffixed name, then the collision counter
149
+ * @returns The candidate path
150
+ */
151
+ function timingDumpCandidate(directory, stem, collision) {
152
+ const suffix = collision === 0 ? '' : `-${String(collision)}`;
153
+ return safePath.join(directory, `${stem}${suffix}.json`);
154
+ }
155
+ /**
156
+ * Whether a caught write failure means somebody else already holds the name.
157
+ *
158
+ * @param error - Whatever `writeFileSync` threw
159
+ * @returns `true` only for `EEXIST`, which is a lost race and not a fault
160
+ */
161
+ function isNameAlreadyTaken(error) {
162
+ return error instanceof Error && 'code' in error && error.code === 'EEXIST';
163
+ }
164
+ /**
165
+ * Claim a name by creating it, and fill it in the same operation.
166
+ *
167
+ * Choosing the name and writing it CANNOT be two steps: whatever separates them
168
+ * is a window in which another writer takes the name that was just declared
169
+ * free, and the loser's dump disappears with no error raised anywhere. So each
170
+ * candidate is written create-exclusively ({@link EXCLUSIVE_CREATE}) and an
171
+ * `EEXIST` — the OS saying somebody else got there — advances to the next
172
+ * counter rather than overwriting.
173
+ *
174
+ * @param directory - Directory dumps are written to
175
+ * @param basename - Basename stem; the pid and any collision counter follow
176
+ * @param contents - The already-serialized dump body
177
+ * @returns Which name was claimed, or why none could be
178
+ */
179
+ function claimTimingDump(directory, basename, contents) {
180
+ const stem = `${basename}-${String(process.pid)}`;
181
+ for (let collision = 0; collision <= MAX_DUMP_COLLISIONS; collision += 1) {
182
+ const candidate = timingDumpCandidate(directory, stem, collision);
183
+ try {
184
+ // eslint-disable-next-line security/detect-non-literal-fs-filename -- operator-supplied diagnostic directory from a VAT_*_TIMING variable
185
+ writeFileSync(candidate, contents, { encoding: 'utf-8', flag: EXCLUSIVE_CREATE });
186
+ return { outcome: 'written', path: candidate };
187
+ }
188
+ catch (error) {
189
+ if (!isNameAlreadyTaken(error))
190
+ return { outcome: 'failed', path: candidate, error };
191
+ }
192
+ }
193
+ return {
194
+ outcome: 'exhausted',
195
+ path: timingDumpCandidate(directory, stem, MAX_DUMP_COLLISIONS),
196
+ };
197
+ }
198
+ /**
199
+ * Write one seam's dump, if the seam is on.
200
+ *
201
+ * The body is built lazily, inside this call, so a disabled seam never pays to
202
+ * snapshot accumulators nobody will read — and a `build` that throws is reported
203
+ * like any other failure, because this runs from an `exit` listener where a
204
+ * throw would change the process's exit behaviour.
205
+ *
206
+ * @param noun - What the seam is called, for any failure line
207
+ * @param directory - Where to write, or `null` when the seam is off
208
+ * @param basename - Basename stem for the file
209
+ * @param build - Produces the dump body
210
+ * @returns The path written, or `null` when the seam is off or nothing was written
211
+ */
212
+ export function writeTimingDump(noun, directory, basename, build) {
213
+ if (directory === null)
214
+ return null;
215
+ let claim;
216
+ try {
217
+ claim = claimTimingDump(directory, basename, `${JSON.stringify(build(), null, 2)}\n`);
218
+ }
219
+ catch (error) {
220
+ // Only `build()` and its serialization can reach here; every filesystem
221
+ // failure is already an outcome rather than a throw.
222
+ reportTimingDumpFailure(noun, directory, error);
223
+ return null;
224
+ }
225
+ if (claim.outcome === 'written')
226
+ return claim.path;
227
+ reportTimingDumpFailure(noun, claim.path, claim.outcome === 'exhausted' ? CEILING_DETAIL : claim.error);
228
+ return null;
229
+ }
230
+ //# sourceMappingURL=timing-dump.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"timing-dump.js","sourceRoot":"","sources":["../src/timing-dump.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAoBhD,8EAA8E;AAC9E,MAAM,mBAAmB,GAAG,IAAI,CAAC;AAEjC,uEAAuE;AACvE,MAAM,aAAa,GAAG,IAAI,CAAC;AAE3B;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,CAAC;AAExC;;;;;;;;;GASG;AACH,MAAM,gBAAgB,GAAG,IAAI,CAAC;AAE9B,mFAAmF;AACnF,MAAM,cAAc,GAAG,wBAAwB,MAAM,CAAC,mBAAmB,CAAC,wCAAwC,CAAC;AAcnH;;;;;;;;;GASG;AACH,MAAM,UAAU,wBAAwB,CAAC,GAAuB;IAC9D,OAAO,GAAG,KAAK,SAAS,IAAI,GAAG,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC;AACtD,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,uBAAuB,CAA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EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC;IACxF,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,wEAAwE;QACxE,qDAAqD;QACrD,uBAAuB,CAAC,IAAI,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;QAChD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,KAAK,CAAC,OAAO,KAAK,SAAS;QAAE,OAAO,KAAK,CAAC,IAAI,CAAC;IACnD,uBAAuB,CACrB,IAAI,EACJ,KAAK,CAAC,IAAI,EACV,KAAK,CAAC,OAAO,KAAK,WAAW,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAC7D,CAAC;IACF,OAAO,IAAI,CAAC;AACd,CAAC"}
package/eslint/README.md CHANGED
@@ -25,7 +25,7 @@ export default [
25
25
  ];
26
26
  ```
27
27
 
28
- `configs.recommended` registers the plugin under the `@vibe-agent-toolkit` namespace and enables the **cross-platform safety core** — 18 of the 21 rules, most at `error` and three at `warn` (see [Severities](#severities)). The other three are opt-in; the [rule tables](#rules) mark each rule's `recommended` severity, and `—` means not in `recommended`.
28
+ `configs.recommended` registers the plugin under the `@vibe-agent-toolkit` namespace and enables the **cross-platform safety core** — 18 of the 22 rules, most at `error` and three at `warn` (see [Severities](#severities)). The other four are opt-in; the [rule tables](#rules) mark each rule's `recommended` severity, and `—` means not in `recommended`.
29
29
 
30
30
  To pick rules yourself, register the plugin and name them:
31
31
 
@@ -111,6 +111,21 @@ Two ways your target can be wrong, which surface differently: `ERR_MODULE_NOT_FO
111
111
  | `no-fs-promises-cp` | `cp()` from `node:fs/promises` (drops nested files on Node 22) | `cpSync()` from `node:fs` | — | ✓ | `error` |
112
112
  | `no-child-process-execSync` | `child_process.execSync()` | `safeExecSync()` | `/process` | ✓ | `error` |
113
113
  | `no-unix-shell-commands` | `tar`, `grep`, `rm`, `echo`, … spawned directly | Node APIs, or a portable script fixture | — | | `error` |
114
+ | `no-bare-symlink-in-tests` | unguarded `fs.symlinkSync()` / `fs.promises.symlink()` | in tests: `createSymlink(cap, …)` / `createSymlinkAsync(cap, …)`; in shipped code: a win32 junction, or a `catch` naming the privilege | `/testing` | | — |
115
+
116
+ **`no-bare-symlink-in-tests` reports two different remedies, and the name is narrower than the rule.**
117
+ Creating a symlink on Windows requires `SeCreateSymbolicLinkPrivilege` — Developer Mode or an
118
+ elevated shell — which most user machines and CI agents lack. In a **test file** the fix is to probe
119
+ with `symlinkCapability()` and pass the resulting token to `createSymlink()`, so a host without the
120
+ privilege produces a visible `skip()` rather than a failure or a silently-swallowed one. In **shipped
121
+ code** there is deliberately no wrapper to route through: `createSymlink()` lives on the `/testing`
122
+ subpath, and pointing production code at a test helper would be worse advice than the bare call.
123
+ There the guidance is a junction for a directory link on win32 (no elevation required), or catching
124
+ the failure and naming the missing privilege. Declaring a platform out of scope is legitimate —
125
+ say so in an `eslint-disable` justification, which is what `vat agent install --dev` does.
126
+
127
+ `exemptFiles` matters here: the implementation file holding the sanctioned `symlinkSync` is not a
128
+ test file, so it needs an explicit exemption once the rule covers shipped code.
114
129
 
115
130
  The member-call rules here check the **receiver**, not just the method name, so `env.tmpdir()` on some unrelated object is not a finding — and the namespace they check for can be bound by a static `import * as os`, by `const os = require('node:os')`, or by `const os = await import('node:os')`. The fix replaces the whole callee (`os.tmpdir()` → `normalizedTmpdir()`), which is correct however the binding was made. Matching the method name alone was the earlier behaviour and it produced `os.normalizedTmpdir()` — a method that does not exist, compiles, and throws.
116
131
 
@@ -122,6 +137,63 @@ The member-call rules here check the **receiver**, not just the method name, so
122
137
  | `no-bare-dynamic-import-path` | `await import(absolutePath)` | `dynamicImportPath()` / `pathToFileURL(p).href` | `/fs` | | `error` |
123
138
  | `no-file-url-string-concat` | `` `file://${p}` `` | `pathToFileURL(p).href` | — | | `error` |
124
139
 
140
+ ### Content decoding
141
+
142
+ | Rule | Bans | Use instead | Subpath | Fix | `recommended` |
143
+ |---|---|---|---|---|---|
144
+ | `no-raw-text-decode` | `buf.toString('utf-8')`, `new TextDecoder(…)`, `readFile(p, 'utf-8')` | one project-owned decoding seam | — | | — |
145
+
146
+ `buf.toString('utf-8')` ignores every byte-order mark and cannot express UTF-16BE at all — Node's `Buffer` has no such encoding. A UTF-16 document therefore decodes to NUL-interleaved mojibake, and whatever sniffs for binary content downstream believes it. PowerShell 5.1's `Out-File` and `>` write UTF-16LE by default, so this is a Windows-authored file, not an exotic one.
147
+
148
+ This rule has no wrapper to point at, because the seam is yours: write one decoder, name it with `safeModule`, and exempt its own file with `exemptFiles`. Put the decoder at the **bottom** of your dependency arrow — a seam in a leaf package cannot be imported by the primitive packages the rule also lints, and those files would then have no legal way to comply.
149
+
150
+ **Not every `'utf-8'` read is a content read**, and this is the distinction that decides whether the rule survives. Three categories:
151
+
152
+ 1. **A document you did not write** — an adopter's markdown, config, schema, `.gitignore`, `package.json`. The encoding must be **discovered**. This is the rule's target.
153
+ 2. **An artifact your project wrote** — its own cache entry, its own published asset. The encoding was **chosen at the write**; reading it back the same way is a closed loop.
154
+ 3. **Bytes that were never a file** — subprocess stdout, an HTTP body, a Buffer you built. The **producer's contract** decides.
155
+
156
+ Static analysis cannot tell them apart, so the rule reports all three and you settle 2 and 3 at the call site with a one-line `eslint-disable-next-line` that **names the writer or the producer**:
157
+
158
+ ```js
159
+ // eslint-disable-next-line @vibe-agent-toolkit/no-raw-text-decode -- subprocess stdout; producer is the credential helper spawned above
160
+ const out = result.stdout.toString('utf8');
161
+ ```
162
+
163
+ That gives a reviewer a falsifiable test: a justification that cannot name who wrote the bytes is a category-1 call wearing a disable comment. Do not settle these by adding paths to `exemptFiles` — that list is for the seam's own implementation file.
164
+
165
+ ```js
166
+ {
167
+ files: ['src/corpus/**/*.ts'],
168
+ rules: {
169
+ '@vibe-agent-toolkit/no-raw-text-decode': ['error', {
170
+ safeModule: '@my-org/resources',
171
+ exemptFiles: ['src/corpus/text-content.ts'],
172
+ }],
173
+ },
174
+ }
175
+ ```
176
+
177
+ Only a string **literal** encoding triggers it. `buf.toString(enc)` is deliberately not reported: without type information it is indistinguishable from `n.toString(radix)`, and `readFile(p, cb)` from `readFile(p, encoding)`.
178
+
179
+ ### Build correctness
180
+
181
+ | Rule | Bans | Use instead | Subpath | Fix | `recommended` |
182
+ |---|---|---|---|---|---|
183
+ | `no-self-package-import` | importing the enclosing package by its own name | a relative path to the defining module | — | | — (needs `packageName`) |
184
+
185
+ A file inside `packages/foo` that writes `import … from '@scope/foo'` resolves out through `node_modules` to its own `package.json`, whose `types` point at `./dist/index.d.ts` — a file the compiler is in the middle of producing. It works only by a TypeScript courtesy: while `dist` **is** the running project's output path, that declaration is recognised as the project's own output and the import is redirected back to `src`, so it resolves with no `dist/` on disk.
186
+
187
+ Change `outDir` — to a staging directory that makes emit atomic, say — and the redirect is gone, tsc looks for a literal `dist/index.d.ts`, and a tree that has never been built has none:
188
+
189
+ ```
190
+ error TS2307: Cannot find module '@scope/foo' or its corresponding type declarations.
191
+ ```
192
+
193
+ The knock-on `TS2339`s land wherever a local type extended one of the now-unresolved imports, which is what makes it read as a type bug in code nobody touched.
194
+
195
+ It is latent by construction, and worse, **it is invisible to any tree that has built before**: a stale `dist/` satisfies the literal lookup, so the build passes by typechecking against the *previous* build's declarations. In a monorepo whose worktrees live inside the main checkout, resolution walks up past the worktree and satisfies it from the *parent checkout's* `dist/`. Both are green locally and red in CI, which is the only genuinely pristine tree. Lint is the only stage that sees it on the author's machine.
196
+
125
197
  ### Code and test hygiene
126
198
 
127
199
  | Rule | Bans | Use instead | Subpath | Fix | `recommended` |
@@ -132,7 +204,7 @@ The member-call rules here check the **receiver**, not just the method name, so
132
204
 
133
205
  ### What `recommended` deliberately leaves out
134
206
 
135
- Three rules ship without riding in `recommended`, for two different reasons.
207
+ Six rules ship without riding in `recommended`, for five different reasons.
136
208
 
137
209
  **Test-style opinions** — `no-test-scoped-functions` (where a helper may be declared) and `require-justified-skip` (the annotation grammar for a disabled test). Neither is a portability or correctness fact, and installing this package for `safePath.join()` should not also import someone else's test conventions. Both are worth turning on deliberately.
138
210
 
@@ -147,7 +219,27 @@ safePath.join(base, userInput) // SILENT — the shape it exists to
147
219
 
148
220
  A rule that misses its own target does not belong in a config named `recommended` at any severity: a safety core that cries wolf teaches people to ignore it, and that costs you the true positives too. It still ships, and it still earns `error` when scoped to directories where a path escape is a security boundary — which is how this repo uses it, on its skill-test staging code. It will return to `recommended` when it keys on taint rather than on naming.
149
221
 
150
- Enable any of the three by naming it:
222
+ **No wrapper to point at** `no-raw-text-decode`. Every other rule in this pack names a replacement this package publishes; this one names a decoding seam that only exists once *you* write it. Shipped in `recommended`, its every message would read "use `decodeTextContent()` from your content-decoding module", which is advice nobody can follow. Turn it on with `safeModule` and `exemptFiles` set, as shown above.
223
+
224
+ **Needs an option, and only in the directories you compile** — `no-self-package-import`. The import it bans is a genuine build-breaker with no style opinion in it, but the rule cannot discover on its own which package a file is in: reading `package.json` would mean `require('node:fs')`, and every module on this subpath is plain data that requires *nothing* — not `eslint`, not a third-party package, not even a Node builtin. That is what keeps `eslint` an optional peer dependency and lets these rules ship as a subpath of a runtime package rather than as one of their own. So the caller names the package. The caller is a config file, which already runs in full Node and can read every manifest it likes:
225
+
226
+ ```js
227
+ import { readFileSync, readdirSync } from 'node:fs';
228
+
229
+ export default readdirSync('packages').flatMap((dir) => {
230
+ const { name } = JSON.parse(readFileSync(`packages/${dir}/package.json`, 'utf8'));
231
+ return [{
232
+ files: [`packages/${dir}/src/**/*.ts`],
233
+ rules: { '@vibe-agent-toolkit/no-self-package-import': ['error', { packageName: name }] },
234
+ }];
235
+ });
236
+ ```
237
+
238
+ Scope it to the sources you **compile**. Test and example trees — normally excluded from the build — import their own package by name **on purpose**, to exercise the public entry point exactly as a consumer does. This repo has ~10 such imports, every one of them correct.
239
+
240
+ **Half its advice is unreachable without a helper you may not have** — `no-bare-symlink-in-tests`. In a test file it points at `createSymlink()` / `createSymlinkAsync()`, which live on *this* package's `./testing` subpath and route through a probed capability token; an adopter on a different test runner, or with no symlink-heavy tests, should not silently inherit that opinion — nor the vitest-specific `skip()` idiom the message names. Its **shipped-code** half (`unguardedSymlink`) carries neither dependency and is portable advice on its own, so this is the one exclusion that is half arbitrary; it stays out because the two halves cannot be enabled separately. This repo turns it on explicitly, scoped to its own test-file convention.
241
+
242
+ Enable any of the six by naming it:
151
243
 
152
244
  ```js
153
245
  import vat from '@vibe-agent-toolkit/utils/eslint';
@@ -160,6 +252,16 @@ export default [
160
252
  '@vibe-agent-toolkit/require-justified-skip': 'error',
161
253
  },
162
254
  },
255
+ {
256
+ // Scope it to the code that reads files whose encoding you do not choose.
257
+ files: ['src/corpus/**/*.ts'],
258
+ rules: {
259
+ '@vibe-agent-toolkit/no-raw-text-decode': ['error', {
260
+ safeModule: '@my-org/resources',
261
+ exemptFiles: ['src/corpus/text-content.ts'],
262
+ }],
263
+ },
264
+ },
163
265
  {
164
266
  // Scope it to where an escape is a security boundary, not repo-wide.
165
267
  files: ['src/staging/**/*.ts'],
package/eslint/index.cjs CHANGED
@@ -50,7 +50,11 @@ const rules = {
50
50
  'no-file-url-string-concat': require('./rules/no-file-url-string-concat.cjs'),
51
51
  'prefer-startswith-over-regex': require('./rules/prefer-startswith-over-regex.cjs'),
52
52
  'no-unsafe-root-join': require('./rules/no-unsafe-root-join.cjs'),
53
+ 'no-raw-text-decode': require('./rules/no-raw-text-decode.cjs'),
54
+ 'no-self-package-import': require('./rules/no-self-package-import.cjs'),
53
55
  'require-justified-skip': require('./rules/require-justified-skip.cjs'),
56
+ 'no-bare-symlink-in-tests': require('./rules/no-bare-symlink-in-tests.cjs'),
57
+ 'no-process-exit-in-phase': require('./rules/no-process-exit-in-phase.cjs'),
54
58
  };
55
59
 
56
60
  /**
@@ -95,6 +99,52 @@ const RECOMMENDED_EXCLUDE = new Set([
95
99
  // a security boundary (this repo scopes it to the skill-test staging code).
96
100
  // Re-include it when it keys on taint rather than on naming.
97
101
  'no-unsafe-root-join',
102
+ // Excluded because it names a seam that does not exist until a consumer builds
103
+ // one. `decodeTextContent()` is VAT's module, in VAT's repo; an adopter who
104
+ // installed this package for `safePath.join()` has no content-decoding seam to
105
+ // be pointed at, so `recommended` would hand them a rule whose every message
106
+ // advises importing from `your content-decoding module`. It ships in `rules`
107
+ // and is enabled — with `safeModule` naming the real seam and `exemptFiles`
108
+ // naming the file that implements it — by whoever has one. VAT itself does
109
+ // exactly that, scoped to the directories that read corpus documents.
110
+ 'no-raw-text-decode',
111
+ // Excluded for two reasons, either of which would be enough. It REQUIRES a
112
+ // `packageName` option — it will not read a `package.json` to find out, because
113
+ // that would mean `require('node:fs')` and break the empty-external-set property
114
+ // this whole subpath rests on — and a rule with a required option cannot ride in
115
+ // a config that supplies none. And the directories it must not fire in are a
116
+ // property of the adopter's `tsconfig`, not of this package: a self-import only
117
+ // breaks the build in files the package actually COMPILES, while test and
118
+ // example trees import their own package by name on purpose, to exercise the
119
+ // public entry point the way a consumer does. This repo has ~10 such imports
120
+ // across `utils`, `agent-skills`, `claude-marketplace` and
121
+ // `vat-example-cat-agents`, every one of them correct. It ships in `rules`, and
122
+ // `eslint.config.js` generates one scoped block per workspace package.
123
+ 'no-self-package-import',
124
+ // Excluded for its TEST half only, which is the honest way to say it. That
125
+ // half names a vitest-specific idiom (`skip()` from the per-test context) and
126
+ // a replacement — `createSymlink()` / `createSymlinkAsync()` /
127
+ // `symlinkCapability()` — living on THIS package's own `./testing` subpath
128
+ // rather than on a seam every consumer already has. An adopter using a
129
+ // different test runner, or no symlink-heavy tests at all, should not
130
+ // silently inherit an opinion about vitest control flow.
131
+ //
132
+ // ⚠️ The rule now covers SHIPPED code too, and that half (`unguardedSymlink`)
133
+ // has neither dependency: it names the Windows privilege and a junction, both
134
+ // portable facts. So this exclusion is weaker than it reads — the two halves
135
+ // share one rule id and cannot be enabled separately, and the test half is
136
+ // what keeps the pair out. Splitting the rule would let the production half
137
+ // ride in `recommended`; that is a public-API change and has not been made.
138
+ // VAT enables the whole rule explicitly, scoped to its own conventions.
139
+ 'no-bare-symlink-in-tests',
140
+ // Excluded because it keys on a NAMING CONVENTION that is VAT's, not a
141
+ // portable fact — the same reason `no-unsafe-root-join` is excluded above. The
142
+ // hazard it guards is real and general (an in-process orchestrator whose step
143
+ // calls `process.exit()` silently skips every later step), but the marker is
144
+ // the `…Phase` suffix, and an adopter with an unrelated `computeRenderPhase()`
145
+ // that legitimately exits would get a finding they cannot act on. It ships in
146
+ // `rules` and VAT enables it explicitly, scoped to its own orchestrators.
147
+ 'no-process-exit-in-phase',
98
148
  ]);
99
149
 
100
150
  /**
@@ -47,10 +47,20 @@ declare namespace plugin {
47
47
  rules: Record<string, RuleModule>;
48
48
  configs: {
49
49
  /**
50
- * The cross-platform safety core: 18 of the 21 rules, 15 `error` / 3 `warn`.
51
- * `no-test-scoped-functions` and `require-justified-skip` are excluded — they
52
- * are positions on test style, not portability facts. Both still ship in
53
- * `rules` and are enabled by naming them.
50
+ * The cross-platform safety core: 18 of the 25 rules, 15 `error` / 3 `warn`.
51
+ *
52
+ * Seven are excluded, for four reasons. `no-test-scoped-functions`,
53
+ * `require-justified-skip` and `no-bare-symlink-in-tests` are positions on
54
+ * TEST STYLE rather than portability facts. `no-unsafe-root-join` and
55
+ * `no-process-exit-in-phase` key on NAMING rather than on the property they
56
+ * care about (taint, and an orchestrated call site). `no-raw-text-decode`
57
+ * names a decoding SEAM that only exists in the consuming repo. And
58
+ * `no-self-package-import` REQUIRES an option this config cannot supply.
59
+ *
60
+ * All seven still ship in `rules` and are enabled by naming them — which is
61
+ * what this repo's own `eslint.config.js` does. The count above is asserted
62
+ * by `packages/utils/test/eslint/rules.test.ts`, so it cannot drift
63
+ * unnoticed the way it did when this comment said "four".
54
64
  */
55
65
  recommended: FlatConfig;
56
66
  };