rungate 0.7.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 (63) 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 +29 -0
  36. package/lib/bash-write-guard.ts +373 -0
  37. package/lib/branch-cleanup.ts +279 -7
  38. package/lib/config-trackable.ts +9 -0
  39. package/lib/distribution-currency.ts +55 -5
  40. package/lib/failure-intake.ts +7 -1
  41. package/lib/gate-enforcement.ts +222 -28
  42. package/lib/gate-names.ts +72 -0
  43. package/lib/gate-result-protection.ts +427 -0
  44. package/lib/intake-sources.ts +380 -0
  45. package/lib/late-env-spawn.ts +331 -0
  46. package/lib/launch-base.ts +128 -5
  47. package/lib/paths.ts +96 -3
  48. package/lib/phase2-decomposition.ts +1 -1
  49. package/lib/published-artifact.ts +162 -18
  50. package/lib/sc-id-cross-tree.ts +84 -8
  51. package/lib/scaffold/ai-review-findings.ts +7 -1
  52. package/lib/scaffold/ai-review-step.ts +861 -116
  53. package/lib/scaffold/defaults.ts +82 -1
  54. package/lib/scaffold/steps.ts +436 -44
  55. package/lib/security-verdict.ts +1 -1
  56. package/lib/shell-path-interpolation.ts +594 -0
  57. package/lib/text-dependents.ts +875 -0
  58. package/lib/workflow-security.ts +29 -0
  59. package/lib/workflow-taint.ts +732 -0
  60. package/lib/worktree-cleanup.ts +65 -38
  61. package/lib/worktree-repo.ts +32 -2
  62. package/package.json +3 -1
  63. package/scripts/check-installed-hook-currency.ts +825 -0
@@ -12,6 +12,61 @@
12
12
  import { readdirSync, realpathSync, statSync, existsSync, readFileSync, rmSync } from "fs";
13
13
  import { join, isAbsolute } from "path";
14
14
  import { spawnSync } from "child_process";
15
+ import { gitIsolatedArgs, gitIsolatedEnv } from "./git-isolation";
16
+
17
+ /**
18
+ * The ONE place this module runs `git` (#1097).
19
+ *
20
+ * ## Why isolation matters more here than anywhere it has been applied yet
21
+ *
22
+ * Every other consumer of `lib/git-isolation.ts` reads. This one deletes.
23
+ * The chain is three steps and it was live on `origin/main`:
24
+ *
25
+ * 1. `core.excludesFile` makes an untracked file invisible to
26
+ * `git status --porcelain`. Measured on git 2.50.1 by #1048/#1090.
27
+ * 2. The dirty check below reads clean, so the worktree falls through
28
+ * every remaining check.
29
+ * 3. `git worktree remove --force` takes the tree, and the file that
30
+ * existed in exactly one place is gone.
31
+ *
32
+ * **The guard meant to spare the work is the reading that was tampered
33
+ * with**, which is why no amount of care in the checks downstream of it
34
+ * helps. #1090 isolated the census — the module that REPORTS the same
35
+ * reading — and did not touch this one.
36
+ *
37
+ * Latent rather than active when this shipped: none of
38
+ * `core.excludesFile`, `core.hooksPath` or `core.fsmonitor` was set in any
39
+ * scope on the machine (measured 2026-10-22). What makes it worth fixing
40
+ * is that a global gitignore is ordinary advice, setting one silently arms
41
+ * this, and the failure is silent — the summary prints `N removed` and
42
+ * nothing says what was in them.
43
+ *
44
+ * ## One seam, not the flags at each site
45
+ *
46
+ * There are eight `git` invocations in this module. `lib/git-isolation.ts`
47
+ * is the single declaring position for WHAT isolation is; this is the
48
+ * single declaring position for WHERE this module applies it. Pasting the
49
+ * `-c` flags at eight call sites is the cheaper change and is measured as
50
+ * the cheapest WRONG fix in #1090's battery: it works, and it reinstates
51
+ * the drifting spellings #1001 removed.
52
+ *
53
+ * ## WHAT THIS DOES NOT COVER
54
+ *
55
+ * `rmSync` on an orphaned checkout, in the `removeOrphans` arm below. Git
56
+ * has no registration for that directory — that is the definition of the
57
+ * bucket — so there is no git invocation there to isolate and no config
58
+ * that could steer it. It is a recursive delete of content nothing has
59
+ * classified, which is why it is off by default; that is #436's argument
60
+ * and this change does not touch it.
61
+ */
62
+ function cleanupGit(args: readonly string[], cwd: string, timeout: number) {
63
+ return spawnSync("git", gitIsolatedArgs(args), {
64
+ cwd,
65
+ encoding: "utf-8",
66
+ timeout,
67
+ env: gitIsolatedEnv(),
68
+ });
69
+ }
15
70
 
16
71
  export interface CleanupResult {
17
72
  removed: string[];
@@ -78,15 +133,11 @@ export interface CleanupOptions {
78
133
  * safety check reverted.
79
134
  */
80
135
  export function unpushedCommitCount(projectRoot: string, branch: string): number | null {
81
- const remotes = spawnSync("git", ["remote"], {
82
- cwd: projectRoot, encoding: "utf-8", timeout: 5000,
83
- });
136
+ const remotes = cleanupGit(["remote"], projectRoot, 5000);
84
137
  if (remotes.status !== 0) return null;
85
138
  if (!remotes.stdout.split("\n").map(r => r.trim()).includes("origin")) return 0;
86
139
 
87
- const count = spawnSync("git", ["rev-list", "--count", branch, "--not", "--remotes=origin"], {
88
- cwd: projectRoot, encoding: "utf-8", timeout: 10_000,
89
- });
140
+ const count = cleanupGit(["rev-list", "--count", branch, "--not", "--remotes=origin"], projectRoot, 10_000);
90
141
  if (count.status !== 0) return null;
91
142
  const n = parseInt(count.stdout.trim(), 10);
92
143
  return Number.isFinite(n) ? n : null;
@@ -124,13 +175,11 @@ export type OriginState =
124
175
  | { kind: "on-origin" };
125
176
 
126
177
  export function originState(projectRoot: string, branch: string): OriginState {
127
- const remotes = spawnSync("git", ["remote"], { cwd: projectRoot, encoding: "utf-8", timeout: 5000 });
178
+ const remotes = cleanupGit(["remote"], projectRoot, 5000);
128
179
  if (remotes.status !== 0) return { kind: "unknown" };
129
180
  if (!remotes.stdout.split("\n").map(r => r.trim()).includes("origin")) return { kind: "no-origin" };
130
181
 
131
- const count = spawnSync("git", ["rev-list", "--count", branch, "--not", "--remotes=origin"], {
132
- cwd: projectRoot, encoding: "utf-8", timeout: 10_000,
133
- });
182
+ const count = cleanupGit(["rev-list", "--count", branch, "--not", "--remotes=origin"], projectRoot, 10_000);
134
183
  if (count.status !== 0) return { kind: "unknown" };
135
184
  const n = parseInt(count.stdout.trim(), 10);
136
185
  if (!Number.isFinite(n)) return { kind: "unknown" };
@@ -193,9 +242,7 @@ export function removalKeepReason(
193
242
  * permission — the same rule `unpushedCommitCount` follows for `null`.
194
243
  */
195
244
  export function lockedWorktreePaths(projectRoot: string): Set<string> | null {
196
- const list = spawnSync("git", ["worktree", "list", "--porcelain"], {
197
- cwd: projectRoot, encoding: "utf-8", timeout: 15_000,
198
- });
245
+ const list = cleanupGit(["worktree", "list", "--porcelain"], projectRoot, 15_000);
199
246
  if (list.status !== 0) return null;
200
247
 
201
248
  const paths = new Set<string>();
@@ -420,11 +467,7 @@ export async function cleanupWorktrees(opts: CleanupOptions): Promise<CleanupRes
420
467
  }
421
468
 
422
469
  // Check for uncommitted changes
423
- const statusCheck = spawnSync("git", ["status", "--porcelain"], {
424
- cwd: worktreePath,
425
- encoding: "utf-8",
426
- timeout: 5000,
427
- });
470
+ const statusCheck = cleanupGit(["status", "--porcelain"], worktreePath, 5000);
428
471
 
429
472
  if (statusCheck.status !== 0) {
430
473
  result.errors.push(`Failed to check git status for ${entry}: ${statusCheck.stderr}`);
@@ -438,11 +481,7 @@ export async function cleanupWorktrees(opts: CleanupOptions): Promise<CleanupRes
438
481
  }
439
482
 
440
483
  // Get branch name
441
- const branchCheck = spawnSync("git", ["-C", worktreePath, "branch", "--show-current"], {
442
- cwd: projectRoot,
443
- encoding: "utf-8",
444
- timeout: 5000,
445
- });
484
+ const branchCheck = cleanupGit(["-C", worktreePath, "branch", "--show-current"], projectRoot, 5000);
446
485
 
447
486
  if (branchCheck.status !== 0) {
448
487
  result.errors.push(`Failed to get branch name for ${entry}: ${branchCheck.stderr}`);
@@ -475,11 +514,7 @@ export async function cleanupWorktrees(opts: CleanupOptions): Promise<CleanupRes
475
514
  // asks whether BRANCH is an ancestor of main. Reversed, every branch cut
476
515
  // from main would look merged and cleanup would delete unmerged work.
477
516
  // test/unit/worktree-cleanup-merge.test.ts pins both directions.
478
- const mergeCheck = spawnSync("git", ["merge-base", "--is-ancestor", branchName, "main"], {
479
- cwd: projectRoot,
480
- encoding: "utf-8",
481
- timeout: 5000,
482
- });
517
+ const mergeCheck = cleanupGit(["merge-base", "--is-ancestor", branchName, "main"], projectRoot, 5000);
483
518
 
484
519
  // Exit 0 = merged, 1 = not merged. Anything else (128: bad revision, no
485
520
  // `main`, not a repo) is an error, NOT a verdict — treating it as "not
@@ -507,11 +542,7 @@ export async function cleanupWorktrees(opts: CleanupOptions): Promise<CleanupRes
507
542
  }
508
543
 
509
544
  // All safety checks passed — remove the worktree
510
- const removeResult = spawnSync("git", ["worktree", "remove", "--force", worktreePath], {
511
- cwd: projectRoot,
512
- encoding: "utf-8",
513
- timeout: 15000,
514
- });
545
+ const removeResult = cleanupGit(["worktree", "remove", "--force", worktreePath], projectRoot, 15000);
515
546
 
516
547
  if (removeResult.status !== 0) {
517
548
  result.errors.push(`Failed to remove ${entry}: ${removeResult.stderr}`);
@@ -521,11 +552,7 @@ export async function cleanupWorktrees(opts: CleanupOptions): Promise<CleanupRes
521
552
  }
522
553
 
523
554
  // Prune worktree references
524
- const pruneResult = spawnSync("git", ["worktree", "prune"], {
525
- cwd: projectRoot,
526
- encoding: "utf-8",
527
- timeout: 5000,
528
- });
555
+ const pruneResult = cleanupGit(["worktree", "prune"], projectRoot, 5000);
529
556
 
530
557
  if (pruneResult.status !== 0) {
531
558
  result.errors.push(`Failed to prune worktree references: ${pruneResult.stderr}`);
@@ -482,11 +482,27 @@ export interface WorktreeReport {
482
482
  * check" — it is a row claiming files with no checkable origin, and omitting
483
483
  * one field would skip the guard entirely. Callers that are about to act on
484
484
  * the rows pass `true`; callers merely surveying them do not.
485
+ *
486
+ * `allowPath` is the DESTINATION question asked at the same boundary (#1098).
487
+ * Identity answers "which repository is this a worktree of", read off the
488
+ * remote; it says nothing about whether the directory is one this run may act
489
+ * in. In `workflows/ship.js` those were two checks ~350 lines apart, and the
490
+ * second ran after two agents had already been told to validate and to fix
491
+ * inside the path. Asked here, every reported path is vetted once, before
492
+ * anything is interpolated into a prompt.
493
+ *
494
+ * It is asked where identity had nothing to say, not instead of it: a row in
495
+ * the wrong repository keeps #218's own refusal, which names the repository.
496
+ *
497
+ * The predicate is INJECTED, not referenced: ship.js's allowlist is declared
498
+ * in a different marked block and the identity block is sliced out and
499
+ * executed on its own. Absent, nothing is allowlisted — a caller merely
500
+ * surveying rows has no destination to vet.
485
501
  */
486
502
  export function worktreeIdentityViolations(
487
503
  reports: readonly WorktreeReport[] | null | undefined,
488
504
  expectedRepo: string | null | undefined,
489
- opts: { requirePath?: boolean } = {},
505
+ opts: { requirePath?: boolean; allowPath?: (path: string) => unknown } = {},
490
506
  ): string[] {
491
507
  if (!Array.isArray(reports)) return [];
492
508
  const out: string[] = [];
@@ -494,7 +510,21 @@ export function worktreeIdentityViolations(
494
510
  const path = r && typeof r.worktreePath === "string" ? r.worktreePath.trim() : "";
495
511
  if (!path && !opts.requirePath) continue;
496
512
  const got = worktreeIdentity(path, expectedRepo, r?.worktreeRepo);
497
- if (got.refusal) out.push(got.refusal);
513
+ if (got.refusal) {
514
+ out.push(got.refusal);
515
+ continue;
516
+ }
517
+ // AFTER the identity reading, and only where identity had nothing to
518
+ // say. A row that is a worktree of the wrong repository keeps #218's own
519
+ // refusal, which names the repository. What this adds is the case
520
+ // identity CANNOT see: a checkout of the RIGHT repository sitting in a
521
+ // directory this run does not own, which reads as a match.
522
+ if (path && typeof opts.allowPath === "function" && !opts.allowPath(path)) {
523
+ out.push(
524
+ `${path} is not this run's project root nor one of its agent worktrees, ` +
525
+ `so it is not a directory this run may act in (#1098)`,
526
+ );
527
+ }
498
528
  }
499
529
  return out;
500
530
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rungate",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "type": "module",
5
5
  "description": "Ship harness — conformity tests, scaffold, and agent briefs for AI-first development",
6
6
  "repository": {
@@ -14,6 +14,7 @@
14
14
  "files": [
15
15
  "bin/",
16
16
  "lib/",
17
+ "hooks/",
17
18
  "prompts/",
18
19
  "config/",
19
20
  "templates/",
@@ -32,6 +33,7 @@
32
33
  "scripts/sync-sc-status.ts",
33
34
  "scripts/audit-transcript.ts",
34
35
  "scripts/detect-sc-drift.ts",
36
+ "scripts/check-installed-hook-currency.ts",
35
37
  "package.json"
36
38
  ],
37
39
  "exports": {