rungate 0.6.0 → 0.8.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 (164) hide show
  1. package/hooks/ActionVerificationGate.hook.ts +96 -0
  2. package/hooks/AgentBriefGuard.hook.ts +38 -0
  3. package/hooks/AgentVerdictCapture.hook.ts +87 -0
  4. package/hooks/AutoVerifyGate.hook.ts +79 -0
  5. package/hooks/BashToolGuard.hook.ts +65 -0
  6. package/hooks/BashWriteGuard.hook.ts +60 -0
  7. package/hooks/CommitEnforcement.hook.ts +130 -0
  8. package/hooks/DocHygiene.hook.ts +148 -0
  9. package/hooks/GateEnforcement.hook.ts +58 -0
  10. package/hooks/GateResultProtection.hook.ts +69 -0
  11. package/hooks/HarnessAFKGate.hook.ts +85 -0
  12. package/hooks/HookCurrency.hook.ts +99 -0
  13. package/hooks/IssueCloseGuard.hook.ts +149 -0
  14. package/hooks/MergeGuard.hook.ts +58 -0
  15. package/hooks/PostCompact.hook.ts +60 -0
  16. package/hooks/ProjectStateSync.hook.ts +103 -0
  17. package/hooks/SkillGuard.hook.ts +69 -0
  18. package/hooks/SpecConformityTrigger.hook.ts +43 -0
  19. package/hooks/SpecSCGuard.hook.ts +123 -0
  20. package/hooks/StaleTTLCleanup.hook.ts +141 -0
  21. package/hooks/TaskCompleted.hook.ts +51 -0
  22. package/hooks/TeamInit.hook.ts +85 -0
  23. package/hooks/TestSuiteGuard.hook.ts +70 -0
  24. package/hooks/TestSuiteRelease.hook.ts +85 -0
  25. package/hooks/TopLevelCdGuard.hook.ts +108 -0
  26. package/hooks/VerifyPhaseLock.hook.ts +84 -0
  27. package/hooks/WorkflowStateGuard.hook.ts +40 -0
  28. package/hooks/lib/agent-config.json +9 -0
  29. package/hooks/lib/agentDetection.ts +201 -0
  30. package/hooks/lib/comment-template.ts +86 -0
  31. package/hooks/lib/findWorkflow.ts +101 -0
  32. package/hooks/lib/parseStdin.ts +37 -0
  33. package/hooks/lib/paths.ts +111 -0
  34. package/hooks/lib/utils.ts +338 -0
  35. package/lib/affected-tests.ts +427 -0
  36. package/lib/agent-audit.ts +2 -3
  37. package/lib/agent-worktree.ts +287 -0
  38. package/lib/agents-md-sections.ts +81 -16
  39. package/lib/bash-write-guard.ts +373 -0
  40. package/lib/behavioral-cache.ts +150 -2
  41. package/lib/branch-cleanup.ts +279 -7
  42. package/lib/branch-protection.ts +790 -0
  43. package/lib/brief-ac-alignment.ts +104 -0
  44. package/lib/brief-references.ts +205 -0
  45. package/lib/bun-version.ts +93 -14
  46. package/lib/check-remedy.ts +140 -0
  47. package/lib/ci-checkout.ts +17 -0
  48. package/lib/ci-history-depth.ts +159 -0
  49. package/lib/ci-setup-step.ts +96 -0
  50. package/lib/claude-code-action.ts +85 -0
  51. package/lib/claude-tool-vocabulary.ts +188 -0
  52. package/lib/cli-commands.ts +15 -0
  53. package/lib/commit-sha.ts +42 -0
  54. package/lib/commit-subject.ts +90 -0
  55. package/lib/compliance-report.ts +377 -45
  56. package/lib/compliance.ts +191 -17
  57. package/lib/config-loader.ts +39 -1
  58. package/lib/config-trackable.ts +400 -0
  59. package/lib/conformity.ts +1087 -100
  60. package/lib/containment.ts +238 -0
  61. package/lib/content-hash.ts +24 -0
  62. package/lib/create-sc.ts +249 -16
  63. package/lib/dev-liveness.ts +180 -0
  64. package/lib/discovery-branch-points.ts +432 -0
  65. package/lib/discovery-stability.ts +481 -0
  66. package/lib/distribution-currency.ts +236 -0
  67. package/lib/doc-routing.ts +157 -0
  68. package/lib/evidence-prevalidator.ts +224 -2
  69. package/lib/evidence-satisfiability.ts +534 -12
  70. package/lib/failure-intake.ts +323 -0
  71. package/lib/fallow-availability.ts +157 -0
  72. package/lib/fs-write-capabilities.ts +232 -0
  73. package/lib/gate-enforcement.ts +222 -28
  74. package/lib/gate-names.ts +72 -0
  75. package/lib/gate-result-protection.ts +427 -0
  76. package/lib/gate-run-split.ts +147 -0
  77. package/lib/generators/agents-md.ts +140 -32
  78. package/lib/git-isolation.ts +140 -0
  79. package/lib/github.ts +15 -0
  80. package/lib/google-auth-action.ts +93 -0
  81. package/lib/harness-project.ts +48 -0
  82. package/lib/harness-provenance.ts +255 -0
  83. package/lib/hook-evidence.ts +235 -0
  84. package/lib/hook-scopes.ts +386 -0
  85. package/lib/hook-target-tree.ts +398 -0
  86. package/lib/hook-trees.ts +447 -0
  87. package/lib/intake-sources.ts +380 -0
  88. package/lib/js-top-level-code.ts +78 -10
  89. package/lib/junit-checks.ts +52 -0
  90. package/lib/late-env-spawn.ts +331 -0
  91. package/lib/launch-base.ts +376 -0
  92. package/lib/line-citation.ts +372 -0
  93. package/lib/orphan-reaper.ts +468 -0
  94. package/lib/parity-binding.ts +205 -0
  95. package/lib/paths.ts +96 -3
  96. package/lib/per-test-timeouts.ts +219 -0
  97. package/lib/phase2-decomposition.ts +1 -1
  98. package/lib/plan-coverage.ts +151 -0
  99. package/lib/prior-branch.ts +201 -8
  100. package/lib/process-table.ts +146 -0
  101. package/lib/project-state-derivation.ts +219 -0
  102. package/lib/project-state-root.ts +258 -0
  103. package/lib/published-artifact.ts +669 -0
  104. package/lib/readdir-sorted.ts +45 -0
  105. package/lib/review-execution-reading.ts +206 -0
  106. package/lib/review-tool-agreement.ts +433 -0
  107. package/lib/rule-promotion.ts +234 -0
  108. package/lib/rule-retirement.ts +525 -0
  109. package/lib/run-branch.ts +612 -0
  110. package/lib/rungate-schema.ts +19 -0
  111. package/lib/runner-home.ts +274 -0
  112. package/lib/sc-id-cross-tree.ts +103 -15
  113. package/lib/sc-ids.ts +121 -13
  114. package/lib/sc-reservations.ts +289 -0
  115. package/lib/scaffold/ai-review-findings.ts +409 -0
  116. package/lib/scaffold/ai-review-step.ts +5406 -64
  117. package/lib/scaffold/defaults.ts +82 -1
  118. package/lib/scaffold/managed-workflow.ts +587 -192
  119. package/lib/scaffold/owned-files.ts +152 -45
  120. package/lib/scaffold/pre-push-hook.ts +49 -5
  121. package/lib/scaffold/steps.ts +1836 -275
  122. package/lib/scaffold/workflow-census.ts +217 -0
  123. package/lib/scaffold/workflow-drift.ts +217 -0
  124. package/lib/scaffold/write-steps.ts +4 -0
  125. package/lib/scan-budget.ts +247 -0
  126. package/lib/scanner.ts +43 -51
  127. package/lib/scratch-roots.ts +50 -5
  128. package/lib/screenshot-discovery.ts +121 -0
  129. package/lib/screenshot-upload.ts +41 -1
  130. package/lib/secret-patterns.ts +511 -8
  131. package/lib/security-verdict.ts +1 -1
  132. package/lib/shell-path-interpolation.ts +594 -0
  133. package/lib/ship-mode.ts +219 -0
  134. package/lib/source-slice.ts +294 -0
  135. package/lib/stale-cleanup.ts +37 -3
  136. package/lib/suite-flake.ts +278 -0
  137. package/lib/suite-measurement.ts +23 -4
  138. package/lib/suite-run-reading.ts +241 -1
  139. package/lib/suite-timeout-margin.ts +193 -0
  140. package/lib/test-case-bodies.ts +883 -0
  141. package/lib/test-case-deletion.ts +653 -0
  142. package/lib/test-census.ts +97 -29
  143. package/lib/test-command-positions.ts +274 -0
  144. package/lib/test-suite-lock.ts +159 -16
  145. package/lib/text-dependents.ts +875 -0
  146. package/lib/tool-probe.ts +31 -9
  147. package/lib/top-level-cd.ts +393 -0
  148. package/lib/tree-entries.ts +89 -0
  149. package/lib/ts-ast.ts +200 -0
  150. package/lib/walk-test-files.ts +97 -0
  151. package/lib/workflow-actions.ts +263 -0
  152. package/lib/workflow-security.ts +29 -0
  153. package/lib/workflow-taint.ts +732 -0
  154. package/lib/worktree-cleanup.ts +65 -38
  155. package/lib/worktree-collect.ts +177 -5
  156. package/lib/worktree-repo.ts +68 -3
  157. package/package.json +4 -1
  158. package/scripts/ai-review-findings.ts +45 -0
  159. package/scripts/check-installed-hook-currency.ts +825 -0
  160. package/scripts/create-sc.ts +21 -1
  161. package/scripts/extract-constraints.ts +107 -7
  162. package/scripts/generate-code-map.ts +23 -30
  163. package/scripts/scaffold-project.ts +8 -1
  164. package/scripts/sync-sc-status.ts +77 -16
@@ -0,0 +1,398 @@
1
+ /**
2
+ * Where a registration's path actually RESOLVES — the tree the settings
3
+ * register, against the tree the repo tests (#713).
4
+ *
5
+ * A near-leaf module: its only relative imports are `hook-trees` (one argv
6
+ * parse) and `hook-scopes` (one definition of a complete scope reading), so
7
+ * there is one binding to mutate per question and no second opinion about
8
+ * either.
9
+ *
10
+ * ## The reading that was missing, with the cost attached
11
+ *
12
+ * `lib/hook-trees.ts` decides the tree by SPELLING: a command containing
13
+ * `${RUNGATE_HOOKS_DIR}` reads as `"rungate"`, which every check in this repo
14
+ * then treats as *this checkout*. Measured 2026-10-21 on the author's
15
+ * machine, `~/.claude/settings.json` defines
16
+ *
17
+ * RUNGATE_HOOKS_DIR = <a checkout that is not this one>
18
+ *
19
+ * and registers fourteen hook commands through it. So the spelling says
20
+ * "rungate" and the bytes that execute are a different tree's. `#999` merged
21
+ * a shell-injection fix into `hooks/ProjectStateSync.hook.ts` — replacing an
22
+ * `execSync` template literal carrying tool input with an argv
23
+ * `execFileSync` — and the file the registration resolves to still carries
24
+ * the `execSync` form. **A merged security fix did not reach the code that
25
+ * runs**, and the whole suite was green through it, including a case titled
26
+ * *"every hook this repo owns is wired to this repo's copy"*.
27
+ *
28
+ * That case is not wrong about what it asserts. It asserts the spelling, and
29
+ * the spelling was right. Nothing resolved it.
30
+ *
31
+ * ## The property
32
+ *
33
+ * **The tree the settings register is the tree the repo tests.** It is a
34
+ * statement about a RESOLVED path, and it cannot be decided from any amount
35
+ * of reading the command string — which is why this module exists beside
36
+ * `registrationTree` rather than inside it. `registrationTree` answers
37
+ * *which root is this spelled with*; this answers *which directory does that
38
+ * root name on the machine doing the reading*. They are different questions
39
+ * and the first one has been standing in for the second.
40
+ *
41
+ * ## Why this is a REFUSAL, and the three ways it would otherwise fail open
42
+ *
43
+ * Each of these produces a clean-looking reading from no evidence, and all
44
+ * three are reachable here (`.claude/rules/config-access.md`):
45
+ *
46
+ * | the silent pass | what it must read as instead |
47
+ * |---|---|
48
+ * | a variable no readable scope defines, assumed to mean this repo | `unresolved` → UNMEASURED |
49
+ * | a scope nobody could open, counted as registering nothing | UNMEASURED, with the scope named |
50
+ * | **zero registrations examined** | UNMEASURED — *zero trees compared is not perfect agreement* |
51
+ *
52
+ * The third is the one with no analogue in the existing census and the one a
53
+ * reader is least likely to write a case for: `foreign.length === 0` is the
54
+ * same value for a tree with every hook correctly wired and for a run that
55
+ * looked at nothing. `examined` is carried so the two are distinguishable,
56
+ * and the reading refuses rather than leaving it to a caller to notice.
57
+ *
58
+ * ## `CLAUDE_PROJECT_DIR` resolves only in a scope the repo owns
59
+ *
60
+ * In `.claude/settings.json` it is this repository by definition — that file
61
+ * loads only for a session started here. In `~/.claude/settings.json` it is
62
+ * **whatever directory the session was started in**, which is session state
63
+ * and not knowable from any file. Resolving it to the repo root in both
64
+ * places would be the first row of the table above, wearing the costume of
65
+ * an obvious simplification: it would turn a user-scope registration that may
66
+ * execute any checkout into a confident `in-repo`.
67
+ *
68
+ * ## A variable with two values is UNRESOLVED, not a precedence puzzle
69
+ *
70
+ * Two scopes defining the same variable differently is a state this module
71
+ * refuses rather than ranks. Picking a winner means encoding a precedence
72
+ * order nobody has written down, and being wrong about it produces exactly
73
+ * the confident-and-wrong path this file exists to stop.
74
+ */
75
+
76
+ import { executedHookPath } from "./hook-trees";
77
+ import {
78
+ type RegistrationScope,
79
+ type ScopeReading,
80
+ assertEveryScopeRead,
81
+ settingsScopePaths,
82
+ } from "./hook-scopes";
83
+
84
+ /**
85
+ * The scopes in which `${CLAUDE_PROJECT_DIR}` is THIS repository.
86
+ *
87
+ * Derived from nothing: it is the list of scopes that only load for a session
88
+ * started in this tree. `repo-registry` is included because
89
+ * `.claude/rungate/hooks.json` is scaffolded into the project settings and
90
+ * has the same reach.
91
+ */
92
+ const PROJECT_DIR_SCOPES: RegistrationScope[] = [
93
+ "project-settings",
94
+ "project-local-settings",
95
+ "repo-registry",
96
+ ];
97
+
98
+ /** `env` assignments read from one settings scope. `null` means unreadable. */
99
+ export interface EnvReading {
100
+ scope: RegistrationScope;
101
+ env: Record<string, string> | null;
102
+ /** Why it could not be read. REQUIRED when `env` is null. */
103
+ unreadable?: string;
104
+ }
105
+
106
+ /**
107
+ * The `env` block of one settings document.
108
+ *
109
+ * A document that does not parse THROWS, for the same reason
110
+ * `settingsCommands` throws: a corrupt settings file is not a settings file
111
+ * with no variables in it, and swallowing it would turn every variable it
112
+ * defines into `unresolved` — a refusal, but for the wrong reason, and one
113
+ * nobody could act on.
114
+ *
115
+ * Non-string values are DROPPED rather than coerced. `"X": 3` is not a path
116
+ * fragment and `String(3)` would build one.
117
+ */
118
+ export function settingsEnv(doc: string): Record<string, string> {
119
+ const parsed = JSON.parse(doc) as { env?: unknown };
120
+ const env = parsed?.env;
121
+ if (env === null || typeof env !== "object" || Array.isArray(env)) return {};
122
+ const out: Record<string, string> = {};
123
+ for (const [k, v] of Object.entries(env as Record<string, unknown>)) {
124
+ if (typeof v === "string") out[k] = v;
125
+ }
126
+ return out;
127
+ }
128
+
129
+ /**
130
+ * Every distinct value each variable is given, across the scopes that could
131
+ * be read.
132
+ *
133
+ * A list rather than a value, so a variable defined twice differently is
134
+ * visible as such at the point of use instead of being resolved by whichever
135
+ * scope happened to be last.
136
+ */
137
+ export function mergeEnv(readings: EnvReading[]): Record<string, string[]> {
138
+ const out: Record<string, string[]> = {};
139
+ for (const r of readings) {
140
+ for (const [k, v] of Object.entries(r.env ?? {})) {
141
+ const seen = (out[k] ??= []);
142
+ if (!seen.includes(v)) seen.push(v);
143
+ }
144
+ }
145
+ return out;
146
+ }
147
+
148
+ /**
149
+ * Assemble a complete env reading from a filesystem.
150
+ *
151
+ * Deliberately shaped like `readRegistrationScopes` and reading the SAME
152
+ * `settingsScopePaths` declaration, including its `ownership` field — so what
153
+ * an absent file means is decided in one place for both readings. A reader
154
+ * with its own idea of that is how `unregistered` became unreachable once
155
+ * already (battery row M6 of #970).
156
+ *
157
+ * `repo-registry` is a hooks array, not a settings document, so it defines no
158
+ * variables. It is present with an empty reading rather than omitted: an
159
+ * omitted scope is what `assertEveryScopeRead` exists to refuse, and "this
160
+ * scope cannot define variables" is a reading.
161
+ */
162
+ export function readEnvScopes(
163
+ repoRoot: string,
164
+ home: string,
165
+ readFile: (path: string) => string | null,
166
+ ): EnvReading[] {
167
+ const readings: EnvReading[] = settingsScopePaths(repoRoot, home).map(
168
+ ({ scope, path, ownership }) => {
169
+ const doc = readFile(path);
170
+ if (doc !== null) return { scope, env: settingsEnv(doc) };
171
+ if (ownership === "repo") return { scope, env: {} };
172
+ return {
173
+ scope,
174
+ env: null,
175
+ unreadable:
176
+ `${path} is not on this machine, and it is machine state the repo does not own — so ` +
177
+ `any variable it defines is a value this run never saw`,
178
+ };
179
+ },
180
+ );
181
+ readings.push({ scope: "repo-registry", env: {} });
182
+ return readings;
183
+ }
184
+
185
+ export type Resolution =
186
+ | { kind: "resolved"; path: string }
187
+ | { kind: "unresolved"; reason: string };
188
+
189
+ const VAR = /\$\{([A-Za-z_][A-Za-z0-9_]*)\}|\$([A-Za-z_][A-Za-z0-9_]*)/g;
190
+
191
+ /**
192
+ * The first variable a raw path is reached through, or `"literal"`.
193
+ *
194
+ * This is what a ratchet keys on. Not the resolved directory — that is a
195
+ * machine path, and a machine path in a committed file is wrong on the next
196
+ * machine and churns on this one. Not the hook name either: a hundred hooks
197
+ * behind one misdirected variable is ONE fact, and banking it a hundred times
198
+ * means the entry churns on every hook added.
199
+ */
200
+ export function pathSpelling(raw: string): string {
201
+ VAR.lastIndex = 0;
202
+ const m = VAR.exec(raw);
203
+ return m ? (m[1] ?? m[2]) : "literal";
204
+ }
205
+
206
+ /**
207
+ * Expand `${VAR}` and `$VAR` against a reading, or say which variable stopped
208
+ * it.
209
+ *
210
+ * `projectDir` is `null` in a scope where `${CLAUDE_PROJECT_DIR}` is session
211
+ * state — see the header. Passing the repo root there regardless is the
212
+ * cheapest wrong fix available at this call site and it is the one that
213
+ * reintroduces the defect.
214
+ */
215
+ export function resolvePath(
216
+ raw: string,
217
+ env: Record<string, string[]>,
218
+ projectDir: string | null,
219
+ ): Resolution {
220
+ const unresolved: string[] = [];
221
+ const expanded = raw.replace(VAR, (whole, braced?: string, bare?: string) => {
222
+ const name = braced ?? bare ?? "";
223
+ if (name === "CLAUDE_PROJECT_DIR") {
224
+ if (projectDir !== null) return projectDir;
225
+ unresolved.push(
226
+ `${name} is the directory the session was started in, which is session state and is ` +
227
+ `not readable from this scope`,
228
+ );
229
+ return whole;
230
+ }
231
+ const values = env[name];
232
+ if (values === undefined || values.length === 0) {
233
+ unresolved.push(`${name} is not defined by any scope this run could read`);
234
+ return whole;
235
+ }
236
+ if (values.length > 1) {
237
+ unresolved.push(
238
+ `${name} is defined ${values.length} times with different values, and which one applies ` +
239
+ `is a precedence question nobody has written down`,
240
+ );
241
+ return whole;
242
+ }
243
+ return values[0];
244
+ });
245
+
246
+ if (unresolved.length > 0) return { kind: "unresolved", reason: unresolved.join("; ") };
247
+ if (!expanded.startsWith("/")) {
248
+ return {
249
+ kind: "unresolved",
250
+ reason:
251
+ `${expanded} is not absolute, so which directory it names depends on the working ` +
252
+ `directory of whatever spawns the hook`,
253
+ };
254
+ }
255
+ return { kind: "resolved", path: normalize(expanded) };
256
+ }
257
+
258
+ /** Collapse `//`, `/./` and a trailing slash. No `fs`, so no symlink resolution. */
259
+ function normalize(path: string): string {
260
+ const parts: string[] = [];
261
+ for (const seg of path.split("/")) {
262
+ if (seg === "" || seg === ".") continue;
263
+ if (seg === ".." ) { parts.pop(); continue; }
264
+ parts.push(seg);
265
+ }
266
+ return "/" + parts.join("/");
267
+ }
268
+
269
+ export type Target = "in-repo" | "foreign" | "unresolved";
270
+
271
+ export interface TargetReading {
272
+ hook: string;
273
+ scope: RegistrationScope;
274
+ command: string;
275
+ /** The variable the path is reached through, or `"literal"`. */
276
+ spelling: string;
277
+ target: Target;
278
+ /** The absolute path the registration resolves to, when it resolved. */
279
+ resolved: string | null;
280
+ detail: string;
281
+ }
282
+
283
+ export interface TargetTreeCensus {
284
+ reading: "MEASURED" | "UNMEASURED";
285
+ unmeasuredReasons: string[];
286
+ /** How many registrations this run actually looked at. */
287
+ examined: number;
288
+ inRepo: TargetReading[];
289
+ foreign: TargetReading[];
290
+ unresolved: TargetReading[];
291
+ }
292
+
293
+ /**
294
+ * Resolve every registration of every hook this repo owns, and say which tree
295
+ * it lands in.
296
+ *
297
+ * `readings` carries the commands and `envReadings` carries the variables,
298
+ * and BOTH go through `assertEveryScopeRead` — the one binding deciding what
299
+ * a complete reading is. A second definition of completeness here would be
300
+ * two deciders for one question
301
+ * (`.claude/rules/checks-must-be-able-to-fail.md`, the fourth shape), and the
302
+ * env half is the one that would quietly acquire a narrower scope list: a
303
+ * variable defined in a scope nobody read is indistinguishable from a
304
+ * variable nobody defined, and only the first of those is innocent.
305
+ */
306
+ export function registeredTreeCensus(
307
+ owned: string[],
308
+ readings: ScopeReading[],
309
+ envReadings: EnvReading[],
310
+ repoRoot: string,
311
+ ): TargetTreeCensus {
312
+ assertEveryScopeRead(readings);
313
+ assertEveryScopeRead(
314
+ envReadings.map(r => ({
315
+ scope: r.scope,
316
+ commands: r.env === null ? null : [],
317
+ unreadable: r.unreadable,
318
+ })),
319
+ );
320
+
321
+ const reasons: string[] = [];
322
+ for (const r of readings) {
323
+ if (r.commands === null) reasons.push(`${r.scope} commands: ${r.unreadable}`);
324
+ }
325
+ for (const r of envReadings) {
326
+ if (r.env === null) reasons.push(`${r.scope} env: ${r.unreadable}`);
327
+ }
328
+
329
+ const env = mergeEnv(envReadings);
330
+ const hooksDir = normalize(`${repoRoot}/hooks`);
331
+ const out: TargetReading[] = [];
332
+ let examined = 0;
333
+
334
+ for (const reading of readings) {
335
+ const projectDir = PROJECT_DIR_SCOPES.includes(reading.scope) ? repoRoot : null;
336
+ for (const command of reading.commands ?? []) {
337
+ const raw = executedHookPath(command);
338
+ if (raw === null) continue;
339
+ const base = raw.slice(raw.lastIndexOf("/") + 1).replace(/\.hook\.ts$/, "");
340
+ if (!owned.includes(base)) continue;
341
+
342
+ examined++;
343
+ const spelling = pathSpelling(raw);
344
+ const res = resolvePath(raw, env, projectDir);
345
+ if (res.kind === "unresolved") {
346
+ out.push({
347
+ hook: base,
348
+ scope: reading.scope,
349
+ command,
350
+ spelling,
351
+ target: "unresolved",
352
+ resolved: null,
353
+ detail:
354
+ `${base} is registered in ${reading.scope} as ${raw}, and which directory that names ` +
355
+ `could not be read: ${res.reason}. An unresolved path is not this repo's copy; it is ` +
356
+ `no reading at all`,
357
+ });
358
+ continue;
359
+ }
360
+
361
+ const dir = res.path.slice(0, res.path.lastIndexOf("/"));
362
+ const inRepo = dir === hooksDir;
363
+ out.push({
364
+ hook: base,
365
+ scope: reading.scope,
366
+ command,
367
+ spelling,
368
+ target: inRepo ? "in-repo" : "foreign",
369
+ resolved: res.path,
370
+ detail: inRepo
371
+ ? `${base} is registered in ${reading.scope} and resolves to ${res.path}, inside the ` +
372
+ `tree this suite runs against`
373
+ : `${base} is registered in ${reading.scope} as ${raw}, which resolves to ${res.path} — ` +
374
+ `OUTSIDE ${hooksDir}. Nothing merged into this repository reaches that file, and ` +
375
+ `every check here is measuring bytes that do not execute`,
376
+ });
377
+ }
378
+ }
379
+
380
+ const unresolved = out.filter(r => r.target === "unresolved");
381
+ for (const r of unresolved) reasons.push(r.detail);
382
+ if (examined === 0) {
383
+ reasons.push(
384
+ `no registration of a hook this repo owns was examined, so no tree was compared with any ` +
385
+ `other. Zero trees compared is not perfect agreement — an empty violation list here means ` +
386
+ `the run found nothing to read, which is the state CI is in and is not a pass`,
387
+ );
388
+ }
389
+
390
+ return {
391
+ reading: reasons.length === 0 ? "MEASURED" : "UNMEASURED",
392
+ unmeasuredReasons: reasons,
393
+ examined,
394
+ inRepo: out.filter(r => r.target === "in-repo"),
395
+ foreign: out.filter(r => r.target === "foreign"),
396
+ unresolved,
397
+ };
398
+ }