rungate 0.5.0 → 0.7.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 (142) hide show
  1. package/lib/affected-tests.ts +398 -0
  2. package/lib/agent-audit.ts +2 -3
  3. package/lib/agent-worktree.ts +287 -0
  4. package/lib/agents-md-sections.ts +209 -0
  5. package/lib/behavioral-cache.ts +150 -2
  6. package/lib/branch-diff.ts +139 -0
  7. package/lib/branch-protection.ts +790 -0
  8. package/lib/brief-ac-alignment.ts +104 -0
  9. package/lib/brief-references.ts +205 -0
  10. package/lib/bun-version.ts +347 -0
  11. package/lib/check-remedy.ts +140 -0
  12. package/lib/ci-checkout.ts +18 -1
  13. package/lib/ci-history-depth.ts +159 -0
  14. package/lib/ci-setup-step.ts +96 -0
  15. package/lib/claude-code-action.ts +85 -0
  16. package/lib/claude-tool-vocabulary.ts +188 -0
  17. package/lib/cli-commands.ts +15 -0
  18. package/lib/commit-sha.ts +42 -0
  19. package/lib/commit-subject.ts +90 -0
  20. package/lib/compliance-report.ts +377 -45
  21. package/lib/compliance.ts +196 -20
  22. package/lib/config-loader.ts +51 -1
  23. package/lib/config-trackable.ts +391 -0
  24. package/lib/conformity.ts +1272 -189
  25. package/lib/containment.ts +238 -0
  26. package/lib/content-hash.ts +24 -0
  27. package/lib/context-docs.ts +143 -28
  28. package/lib/create-brief.ts +2 -1
  29. package/lib/create-sc.ts +323 -4
  30. package/lib/dev-liveness.ts +180 -0
  31. package/lib/discovery-branch-points.ts +432 -0
  32. package/lib/discovery-stability.ts +481 -0
  33. package/lib/distribution-currency.ts +186 -0
  34. package/lib/doc-routing.ts +157 -0
  35. package/lib/doc-scan-targets.ts +9 -0
  36. package/lib/evidence-command-transport.ts +160 -0
  37. package/lib/evidence-prevalidator.ts +246 -2
  38. package/lib/evidence-satisfiability.ts +534 -12
  39. package/lib/failure-intake.ts +317 -0
  40. package/lib/fallow-availability.ts +286 -0
  41. package/lib/fs-write-capabilities.ts +232 -0
  42. package/lib/gate-refusal-currency.ts +112 -0
  43. package/lib/gate-run-split.ts +147 -0
  44. package/lib/gate-timeouts.ts +82 -0
  45. package/lib/generators/agent-briefs.ts +4 -1
  46. package/lib/generators/agents-md.ts +204 -48
  47. package/lib/generators/code-map.ts +2 -1
  48. package/lib/generators/types.ts +8 -0
  49. package/lib/git-dates.ts +55 -0
  50. package/lib/git-isolation.ts +140 -0
  51. package/lib/github.ts +15 -0
  52. package/lib/google-auth-action.ts +93 -0
  53. package/lib/harness-project.ts +48 -0
  54. package/lib/harness-provenance.ts +255 -0
  55. package/lib/hook-evidence.ts +235 -0
  56. package/lib/hook-scopes.ts +386 -0
  57. package/lib/hook-target-tree.ts +398 -0
  58. package/lib/hook-trees.ts +447 -0
  59. package/lib/js-top-level-code.ts +78 -10
  60. package/lib/junit-checks.ts +536 -0
  61. package/lib/launch-base.ts +253 -0
  62. package/lib/line-citation.ts +372 -0
  63. package/lib/local-calendar-day.ts +78 -0
  64. package/lib/orphan-reaper.ts +468 -0
  65. package/lib/parity-binding.ts +205 -0
  66. package/lib/per-test-timeouts.ts +219 -0
  67. package/lib/plan-coverage.ts +151 -0
  68. package/lib/prior-branch.ts +201 -8
  69. package/lib/process-table.ts +146 -0
  70. package/lib/project-state-derivation.ts +219 -0
  71. package/lib/project-state-root.ts +258 -0
  72. package/lib/project-state-shape.ts +59 -0
  73. package/lib/promote-outputs.ts +6 -2
  74. package/lib/published-artifact.ts +525 -0
  75. package/lib/readdir-sorted.ts +45 -0
  76. package/lib/report-provenance.ts +156 -0
  77. package/lib/review-execution-reading.ts +206 -0
  78. package/lib/review-tool-agreement.ts +433 -0
  79. package/lib/rule-promotion.ts +234 -0
  80. package/lib/rule-retirement.ts +525 -0
  81. package/lib/run-branch.ts +612 -0
  82. package/lib/rungate-schema.ts +19 -0
  83. package/lib/runner-home.ts +274 -0
  84. package/lib/sc-claim-forms.ts +75 -0
  85. package/lib/sc-id-cross-tree.ts +323 -0
  86. package/lib/sc-ids.ts +121 -13
  87. package/lib/sc-reservations.ts +289 -0
  88. package/lib/scaffold/ai-review-findings.ts +403 -0
  89. package/lib/scaffold/ai-review-step.ts +4777 -0
  90. package/lib/scaffold/managed-workflow.ts +587 -192
  91. package/lib/scaffold/owned-files.ts +186 -39
  92. package/lib/scaffold/pre-push-hook.ts +49 -5
  93. package/lib/scaffold/rehearsal.ts +205 -71
  94. package/lib/scaffold/steps.ts +1517 -293
  95. package/lib/scaffold/workflow-census.ts +217 -0
  96. package/lib/scaffold/workflow-drift.ts +217 -0
  97. package/lib/scaffold/write-steps.ts +10 -4
  98. package/lib/scan-budget.ts +247 -0
  99. package/lib/scanner.ts +80 -62
  100. package/lib/scratch-roots.ts +50 -5
  101. package/lib/screenshot-discovery.ts +121 -0
  102. package/lib/screenshot-upload.ts +41 -1
  103. package/lib/secret-patterns.ts +511 -8
  104. package/lib/ship-mode.ts +219 -0
  105. package/lib/source-slice.ts +294 -0
  106. package/lib/spec-listing.ts +148 -0
  107. package/lib/spec-requirements.ts +209 -0
  108. package/lib/stale-cleanup.ts +37 -3
  109. package/lib/suite-flake.ts +278 -0
  110. package/lib/suite-measurement.ts +23 -4
  111. package/lib/suite-run-reading.ts +411 -1
  112. package/lib/suite-timeout-margin.ts +193 -0
  113. package/lib/test-case-bodies.ts +883 -0
  114. package/lib/test-case-deletion.ts +653 -0
  115. package/lib/test-census.ts +97 -29
  116. package/lib/test-command-positions.ts +274 -0
  117. package/lib/test-command.ts +133 -0
  118. package/lib/test-suite-lock.ts +325 -26
  119. package/lib/tool-probe.ts +142 -0
  120. package/lib/top-level-cd.ts +393 -0
  121. package/lib/tracked-vs-ignored.ts +234 -0
  122. package/lib/tree-entries.ts +89 -0
  123. package/lib/ts-ast.ts +200 -0
  124. package/lib/validators/spec-validators.ts +3 -2
  125. package/lib/walk-test-files.ts +97 -0
  126. package/lib/workflow-actions.ts +263 -0
  127. package/lib/worktree-collect.ts +177 -5
  128. package/lib/worktree-repo.ts +36 -1
  129. package/package.json +2 -1
  130. package/scripts/ai-review-findings.ts +45 -0
  131. package/scripts/audit-specs.ts +247 -12
  132. package/scripts/audit-transcript.ts +2 -1
  133. package/scripts/convert-spec.ts +2 -1
  134. package/scripts/create-sc.ts +37 -7
  135. package/scripts/create-spec.ts +2 -1
  136. package/scripts/create-success.ts +2 -1
  137. package/scripts/extract-constraints.ts +197 -26
  138. package/scripts/generate-code-map.ts +62 -28
  139. package/scripts/scaffold-project.ts +12 -2
  140. package/scripts/split-spec.ts +2 -1
  141. package/scripts/sync-sc-status.ts +127 -14
  142. package/scripts/sync-spec-tests.ts +2 -1
@@ -0,0 +1,121 @@
1
+ /**
2
+ * Where a prove run's UI evidence lives, and what is actually in it (#809).
3
+ *
4
+ * ## The defect
5
+ *
6
+ * `workflows/prove.js` globbed **all of `/tmp`** for
7
+ * `playwright-screenshot.*\.png$|browser-screenshot.*\.png$`, handed every
8
+ * match to `uploadScreenshotsToIssue`, and embedded the resulting PUBLIC gist
9
+ * links in a PR comment. Nothing scoped that read to this run, this issue, or
10
+ * this project, on a machine that routinely carries a dozen concurrent
11
+ * worktrees.
12
+ *
13
+ * It never fired, and the reason is worth keeping because it is the more
14
+ * serious half. Playwright's `browser_take_screenshot` writes
15
+ * `.playwright-mcp/page-{timestamp}.png` under the workspace root when given
16
+ * no `filename` — not `/tmp`, and matching neither pattern. Measured across
17
+ * the machine this was found on: 96 files produced by the tool between
18
+ * 2026-09-28 and 2026-10-19, and zero ever named for either pattern. So the
19
+ * glob could not match its producer, UI evidence had never been attached to
20
+ * any pull request, and the phase reported success every time because
21
+ * `markdownLinks.length > 0` was simply false.
22
+ *
23
+ * ## Why a directory rather than a better pattern
24
+ *
25
+ * A narrower glob is still a guess about a filename somebody else chooses.
26
+ * `prove.js` now creates this directory, tells Quinn to write into it, and
27
+ * reads nothing else — so a concurrent run cannot place a file where this
28
+ * one will find it. That is a property of the layout rather than a prediction
29
+ * about names, and it closes the exposure instead of narrowing it.
30
+ *
31
+ * The `--public` flag in `lib/screenshot-upload.ts` is deliberately NOT
32
+ * touched here. Whether evidence is world-readable is a disclosure decision
33
+ * for the repository owner, and changing it inside a scoping fix would make
34
+ * that decision look like a cleanup.
35
+ */
36
+
37
+ import { existsSync, readdirSync, statSync } from "fs";
38
+ import { join } from "path";
39
+
40
+ /**
41
+ * The directory a prove run writes and reads its screenshots in.
42
+ *
43
+ * Derived from `WORK_DIR`, which `prove.js` already scopes per issue, so two
44
+ * issues cannot share one. A plain subdirectory rather than `mkdtemp`: the
45
+ * name has to be computable twice — once to tell Quinn, once to read it back
46
+ * — and a random suffix would have to be threaded through an agent prompt and
47
+ * returned intact, which is a second decider about the same path.
48
+ */
49
+ export function screenshotDirFor(workDir: string): string {
50
+ return join(workDir, "screenshots");
51
+ }
52
+
53
+ /**
54
+ * What a scan of that directory found.
55
+ *
56
+ * Three cases, not two, because the old code had one. `missing` and `none`
57
+ * both produced an empty array, `markdownLinks.length > 0` was false for
58
+ * both, and the phase reported success either way — so a feature that had
59
+ * never worked was indistinguishable from a run with nothing to show. The
60
+ * distinction is the fix for that, and it only means anything because
61
+ * `prove.js` creates the directory BEFORE Quinn runs: after that, empty is a
62
+ * statement about Quinn and absent is a statement about us.
63
+ */
64
+ export type ScreenshotScan =
65
+ | { kind: "found"; dir: string; files: string[] }
66
+ | { kind: "none"; dir: string }
67
+ | { kind: "missing"; dir: string };
68
+
69
+ /** PNG only. The tool drops `.yml` snapshots and `.log` console dumps beside its images. */
70
+ function isScreenshot(name: string): boolean {
71
+ return name.toLowerCase().endsWith(".png");
72
+ }
73
+
74
+ /**
75
+ * Lists the names in a directory. A seam, for one reason: the sort below.
76
+ *
77
+ * `readdirSync` returns sorted order on the filesystem this was written on,
78
+ * so a battery row that deleted the `.sort()` measured **0 red** — the
79
+ * mechanism was present and unprovable, and a sort nothing can witness is a
80
+ * sort somebody later deletes as dead code. Handing the lister in lets a case
81
+ * return names in the wrong order on purpose. Same shape as `GistCreator` in
82
+ * `lib/screenshot-upload.ts`.
83
+ */
84
+ export type DirLister = (dir: string) => string[];
85
+
86
+ const realLister: DirLister = dir => readdirSync(dir);
87
+
88
+ /**
89
+ * Reads exactly one directory, non-recursively, and reports what is in it.
90
+ *
91
+ * Returns absolute paths because the only consumer hands them to
92
+ * `uploadScreenshotsToIssue`, which calls `existsSync` on each — a relative
93
+ * path there resolves against whatever the process cwd happens to be and
94
+ * lands in `failed` with no explanation.
95
+ *
96
+ * Sorted, so the order evidence appears in a PR comment is the order the
97
+ * filenames imply rather than the order the filesystem offers.
98
+ */
99
+ export function discoverScreenshots(dir: string, list: DirLister = realLister): ScreenshotScan {
100
+ if (!existsSync(dir)) return { kind: "missing", dir };
101
+
102
+ const files = list(dir)
103
+ .filter(isScreenshot)
104
+ .map(name => join(dir, name))
105
+ .filter(path => statSync(path).isFile())
106
+ .sort();
107
+
108
+ return files.length === 0 ? { kind: "none", dir } : { kind: "found", dir, files };
109
+ }
110
+
111
+ /** One sentence for the run log, so each of the three readings is legible. */
112
+ export function describeScan(scan: ScreenshotScan): string {
113
+ switch (scan.kind) {
114
+ case "found":
115
+ return `${scan.files.length} screenshot(s) from ${scan.dir}`;
116
+ case "none":
117
+ return `no screenshots: Quinn ran and wrote none into ${scan.dir}`;
118
+ case "missing":
119
+ return `UNMEASURED: ${scan.dir} does not exist, so no screenshot was ever looked for`;
120
+ }
121
+ }
@@ -8,6 +8,42 @@ export interface UploadResult {
8
8
  markdownLinks: string[];
9
9
  }
10
10
 
11
+ /**
12
+ * Creates one gist and returns whatever the command printed.
13
+ *
14
+ * The return is deliberately the RAW stdout rather than a parsed URL: the
15
+ * caller's job is to decide whether what came back is a gist URL at all, and
16
+ * a seam that pre-validates would hide the case where it is not.
17
+ */
18
+ export type GistCreator = (filePath: string) => Promise<string>;
19
+
20
+ /**
21
+ * The ONE place this module reaches the network (#806).
22
+ *
23
+ * It is a seam because there was none, and the cost of there being none is
24
+ * measured rather than argued: three cases in
25
+ * `test/screenshot-upload.test.ts` handed a real file to the function below,
26
+ * so every `bun test` run published four PUBLIC gists to whoever ran it.
27
+ * 3,667 of them existed on the account when this was found, every gist on it,
28
+ * from 2026-09-30 to 2026-10-20 — and the same three cases were the red shard
29
+ * on `main`, timing out at bun's default 5000ms whenever GitHub was slow.
30
+ *
31
+ * A test must never need the network to find out what this function does with
32
+ * what the network says. One exported binding, so a test overrides it by
33
+ * passing it in and nothing has to mutate `PATH`, the environment, or the
34
+ * module.
35
+ */
36
+ export const createPublicGist: GistCreator = async (filePath: string) =>
37
+ await $`gh gist create --public ${filePath}`.text();
38
+
39
+ export interface UploadOpts {
40
+ /**
41
+ * Used instead of `createPublicGist`. Omitted in production; supplied by
42
+ * every test, which is what keeps the suite off the network.
43
+ */
44
+ createGist?: GistCreator;
45
+ }
46
+
11
47
  /**
12
48
  * Uploads screenshot files to GitHub via gists and returns markdown image links.
13
49
  *
@@ -17,13 +53,17 @@ export interface UploadResult {
17
53
  * @param issue - GitHub issue number (for future use in direct issue attachments)
18
54
  * @param repo - Repository in owner/repo format
19
55
  * @param screenshotPaths - Array of absolute paths to screenshot files
56
+ * @param opts - `createGist` overrides the network seam; omit it in production
20
57
  * @returns UploadResult with uploaded files, failed files, and markdown links
21
58
  */
22
59
  export async function uploadScreenshotsToIssue(
23
60
  issue: number,
24
61
  repo: string,
25
62
  screenshotPaths: string[],
63
+ opts?: UploadOpts,
26
64
  ): Promise<UploadResult> {
65
+ const createGist = opts?.createGist ?? createPublicGist;
66
+
27
67
  const result: UploadResult = {
28
68
  uploaded: [],
29
69
  failed: [],
@@ -44,7 +84,7 @@ export async function uploadScreenshotsToIssue(
44
84
  try {
45
85
  // Upload to GitHub gist
46
86
  // gh gist create returns the gist URL on stdout
47
- const gistResult = await $`gh gist create --public ${filePath}`.text();
87
+ const gistResult = await createGist(filePath);
48
88
  const gistUrl = gistResult.trim();
49
89
 
50
90
  if (!gistUrl || !gistUrl.startsWith("https://gist.github.com/")) {