rungate 0.8.22 → 0.8.24

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.
@@ -1,3 +1,3 @@
1
1
  ba56e1fcb00c7a9bc1f2b05beca701cb264785e017cd2bf54a2dd07cdde331df ac-adversary.md
2
2
  7d4ff0ef4b787e68b59643c11ba51e62a9411f5e24509b97855a337598c67508 evidence-validator.md
3
- fd6e01a8e6ec1845a39bd29b15355320238ca7dcf9131e25f5b8cb1468f635ee prove-reproducer.md
3
+ 6f15ff6891118f749894f55f18fa21234211f993cf6eadfb3c90561a64b91691 prove-reproducer.md
@@ -1,7 +1,8 @@
1
1
  import { test, expect, describe } from "bun:test";
2
2
  import { readFileSync, existsSync, writeFileSync } from "fs";
3
3
  import { execSync } from "child_process";
4
- import { beforeEvidenceFor, comparisonSummaryFor, readBeforeState } from "./gate-executor";
4
+ import { beforeEvidenceFor, comparisonSummaryFor, readBeforeState, validateArtifactSchema } from "./gate-executor";
5
+ import { ProveEvidenceSchema } from "./schema";
5
6
 
6
7
  const TEST_DIR = process.env.TEST_WORK_DIR || "";
7
8
  const PROJECT_ROOT = process.env.PROJECT_ROOT || process.cwd();
@@ -145,6 +146,10 @@ describe("prove: run evidence commands from workflow-state", () => {
145
146
  criteriaResults,
146
147
  };
147
148
 
149
+ // #2254 / SC-2770: checked against the one contract before it is written,
150
+ // as B3's and prove.js's are. A required field this writer stops emitting
151
+ // fails here, with the field named, instead of in whatever reads it next.
152
+ expect(validateArtifactSchema(evidence, ProveEvidenceSchema)).toEqual([]);
148
153
  writeFileSync(`${TEST_DIR}/prove-evidence.json`, JSON.stringify(evidence, null, 2));
149
154
  expect(verdict).toBe("PROVEN");
150
155
  });
package/gates/schema.ts CHANGED
@@ -1193,7 +1193,10 @@ export const ShipEvidenceSchema = z.object({
1193
1193
  status: z.enum(["PASS", "FAIL"]),
1194
1194
  evidence: z.array(z.object({
1195
1195
  criterion: z.string(),
1196
- result: z.enum(["PASS", "FAIL", "SKIP"]),
1196
+ // PENDING is a legitimate ship-time state (#2255): an OUTCOME criterion
1197
+ // waits for Quinn or /prove, and the verify gate passes it through
1198
+ // (checkVerifyPendingACs). The writer copies the criterion's verdict.
1199
+ result: z.enum(["PASS", "FAIL", "SKIP", "PENDING"]),
1197
1200
  detail: z.any().optional(),
1198
1201
  })),
1199
1202
  }),
@@ -1252,9 +1255,26 @@ const BeforeEvidenceSchema = z.union([
1252
1255
  }),
1253
1256
  ]);
1254
1257
 
1258
+ /**
1259
+ * One row of `prove-evidence.json`'s `criteriaResults` (#1559). The shape all
1260
+ * three writers already emit — B3's reproducer, `gates/prove.test.ts` and
1261
+ * `workflows/prove.js` — and the one the deleted
1262
+ * `config/prove-evidence.schema.json` declared. SKIP is the reproducer's
1263
+ * verdict for a UI criterion it has no browser to check.
1264
+ */
1265
+ const CriterionResultSchema = z.object({
1266
+ scId: z.string(),
1267
+ verdict: z.enum(["PASS", "FAIL", "SKIP"]),
1268
+ evidence: z.string(),
1269
+ });
1270
+
1255
1271
  export const ProveEvidenceSchema = z.object({
1256
1272
  issueNumber: z.number(),
1257
1273
  verdict: z.enum(["PROVEN", "UNPROVEN", "INCONCLUSIVE"]),
1274
+ // Required, but not `.min(1)`: an INCONCLUSIVE with no criteria is a record
1275
+ // `gates/prove.test.ts` legitimately writes. That a PROVEN needs a PASS row
1276
+ // is `buildProveEvidence`'s rule, because it is about two fields at once.
1277
+ criteriaResults: z.array(CriterionResultSchema),
1258
1278
  commitSHA: z.string(),
1259
1279
  capturedAt: z.string(),
1260
1280
  beforeEvidence: BeforeEvidenceSchema,
@@ -453,6 +453,18 @@ export function verifyFanoutViolations(label: string, val: unknown, tier: unknow
453
453
  `is an absence with extra steps (#126)`,
454
454
  ];
455
455
  }
456
+ // #2259: the agent ran and its reply could not be read. Before, that reply
457
+ // left no record, which the absence branch above refused, so the ship
458
+ // outcome is unchanged. What changes is that the refusal names the cause
459
+ // instead of failing on a missing `gameable` further down.
460
+ if ((val as { status?: unknown }).status === "UNMEASURED") {
461
+ const reason = (val as { reason?: unknown }).reason;
462
+ return [
463
+ `gates.verify.${label} is UNMEASURED — the agent ran and its reply could not be read` +
464
+ (typeof reason === "string" && reason.trim() !== "" ? `: ${reason}` : "") +
465
+ `. An unread reply is not an approval (#126, #2259).`,
466
+ ];
467
+ }
456
468
  return [];
457
469
  }
458
470
 
@@ -224,8 +224,19 @@ export function aiReviewSuppressionGate(inputs: SuppressionInputs): AiReviewSupp
224
224
  const a = anchorOnlyKey(k);
225
225
  if (a !== null) anchors.add(a);
226
226
  }
227
+ // #2257: how many findings cite a line, and how many of those lines could
228
+ // be read. Read from the SAME calls the keys are built from, not a second
229
+ // pass, so the count cannot disagree with what the keys saw.
230
+ let located = 0;
231
+ let readable = 0;
227
232
  const repeat = candidates.map(c => {
228
- const key = carryKey(c, inputs.lineTextFor(c as ReviewFinding));
233
+ const cited = c as ReviewFinding;
234
+ const lineText = inputs.lineTextFor(cited);
235
+ if (typeof cited?.file === "string" && Number.isInteger(cited?.line) && (cited.line as number) >= 1) {
236
+ located++;
237
+ if (lineText !== undefined) readable++;
238
+ }
239
+ const key = carryKey(c, lineText);
229
240
  // Unkeyable CARRIES. It cannot be shown to be a repeat, and the
230
241
  // direction this is allowed to be wrong in is toward reporting.
231
242
  if (key === null) return null;
@@ -282,7 +293,20 @@ export function aiReviewSuppressionGate(inputs: SuppressionInputs): AiReviewSupp
282
293
  // this whole increment is a correction for.
283
294
  return null;
284
295
  });
285
- return { repeat, unmeasured: null };
296
+ // #2257. A gate that could read no cited line built every key from a line
297
+ // NUMBER, which never equals a key an earlier round recorded from line
298
+ // TEXT. "Nothing to suppress" from that gate is a reading of nothing, and
299
+ // it printed the same words as a gate that read every line (#1872: 0 of
300
+ // 420 in CI). Byte-key matches above still stand; this says the anchor
301
+ // half was blind.
302
+ const unmeasured =
303
+ located > 0 && readable === 0 && prior.keys.length > 0
304
+ ? `no cited line could be read for any of this round's ${located} finding(s) that cite one, ` +
305
+ `so no key could match one an earlier round recorded from the line's text, and a ` +
306
+ `restated finding could not be recognised. The checkout the gate reads is probably not ` +
307
+ `the one under review (#2257).`
308
+ : null;
309
+ return { repeat, unmeasured };
286
310
  };
287
311
  }
288
312
 
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Check a gate artifact against its declared schema, before it is written
3
+ * (#1559, #2255, SC-2770).
4
+ *
5
+ * Lives in `lib/` rather than beside its first caller in
6
+ * `gates/gate-executor.ts` because `gates/orchestrator.ts` needs it too, and
7
+ * gate-executor already imports orchestrator. `gates/gate-executor.ts`
8
+ * re-exports both names, so there is one definition and every existing import
9
+ * keeps working.
10
+ */
11
+
12
+ /**
13
+ * Anything with zod's `safeParse` shape. Structural, so callers keep no
14
+ * direct zod import and a test can hand it a stricter copy of a schema.
15
+ */
16
+ export interface ArtifactSchema {
17
+ safeParse(value: unknown): {
18
+ success: boolean;
19
+ error?: { issues: ReadonlyArray<{ path: ReadonlyArray<PropertyKey>; message: string }> };
20
+ };
21
+ }
22
+
23
+ /**
24
+ * One `path: message` line per violation, `[]` when it validates.
25
+ *
26
+ * `config/prove-evidence.schema.json` declared a contract nothing read, so
27
+ * writer and contract drifted apart: B3's artifact failed both the JSON
28
+ * schema and the zod one, and no check said so. A refusal that names no
29
+ * issue is still a refusal — an empty list there would read as a pass.
30
+ */
31
+ export function validateArtifactSchema(artifact: unknown, schema: ArtifactSchema): string[] {
32
+ const result = schema.safeParse(artifact);
33
+ if (result.success) return [];
34
+ const issues = result.error?.issues ?? [];
35
+ if (issues.length === 0) return ["(root): the schema refused the artifact without naming a field"];
36
+ return issues.map((i) => `${i.path.length > 0 ? i.path.map(String).join(".") : "(root)"}: ${i.message}`);
37
+ }
@@ -299,6 +299,16 @@ export const CLI_COMMANDS: Record<string, CliCommand> = {
299
299
  "rungate unaccounted-work [--project-root <dir>] [--repo <owner/name>] [--issues-fixture <file.json>] [--json] " +
300
300
  "(exit 1 when work is unaccounted, 2 when a source could not be read)",
301
301
  },
302
+ // #2248: the command #2233 (fix-commits on push to main) and #2234
303
+ // (gate-refusals at the end of a ship run) call, per #1126's decision that
304
+ // each intake source runs on its own trigger.
305
+ intake: {
306
+ script: "scripts/intake.ts",
307
+ summary: "Run each intake source and print its reading — MEASURED with a count, or UNMEASURED naming why",
308
+ usage:
309
+ "rungate intake [--project-root <dir>] [--source <id>] [--json] " +
310
+ "(advisory: an unreadable source prints UNMEASURED and exits 0; exit 2 on a bad argument)",
311
+ },
302
312
  // Reads a `gh pr view`-shaped payload on stdin, which the dispatcher passes
303
313
  // through (`stdio: "inherit"`), or `--fixture` offline.
304
314
  "audit-closing-references": {
@@ -1822,6 +1822,20 @@ export const AI_REVIEW_LEDGER_SNAPSHOT_BASENAME = "ai-review-ledger-snapshot.txt
1822
1822
  */
1823
1823
  export const AI_REVIEW_THREADS_PATH_VAR = "AI_REVIEW_THREADS_PATH";
1824
1824
 
1825
+ /**
1826
+ * The checkout the adjudicator reads cited lines from (#2257).
1827
+ *
1828
+ * The adjudicator runs from the payload's own directory, outside the
1829
+ * checkout, because `bunx` resolves bunfig.toml, .npmrc and package.json by
1830
+ * walking up from its working directory, so the PR under review must not be
1831
+ * the tree it starts in. That made `process.cwd()` the payload directory,
1832
+ * the suppression gate could read no cited line, and the anchor rule matched
1833
+ * 0 of 420 round-2+ findings in CI (#1872). The root has to arrive by name.
1834
+ * `scripts/ai-review-findings.ts` falls back to its working directory when
1835
+ * this is unset, which is what a step generated before it was set does.
1836
+ */
1837
+ export const AI_REVIEW_CHECKOUT_ROOT_VAR = "AI_REVIEW_CHECKOUT_ROOT";
1838
+
1825
1839
  /** The basename inside the findings directory. One spelling. */
1826
1840
  export const AI_REVIEW_THREADS_BASENAME = "ai-review-threads.json";
1827
1841
 
@@ -0,0 +1,120 @@
1
+ /**
2
+ * `.github/workflows/intake.yml`, generated — #2233.
3
+ *
4
+ * Jason decided on #1126 (2026-11-15) that each intake source runs on its own
5
+ * trigger, not on scaffold: "scaffold" reads as a one-time setup step, so
6
+ * nobody re-runs it to re-mine, and intake should run when its data appears.
7
+ * For `fix-commits` the data is the history of the default branch, and the
8
+ * trigger is a push to it.
9
+ *
10
+ * ## Full history, or the reading is of the clone
11
+ *
12
+ * `mineFixCommits` reports `SHALLOW_HISTORY` on a shallow clone, and
13
+ * `actions/checkout` clones to depth 1 unless told otherwise. That depth is
14
+ * the only reason the source read UNMEASURED on a runner, so the checkout
15
+ * sets `fetch-depth: 0`.
16
+ *
17
+ * ## Advisory, and never silent
18
+ *
19
+ * `rungate intake` exits 0 on every reading (#2248), so a reading never turns
20
+ * the run red: an unreadable source says nothing about the push that fired
21
+ * it. UNMEASURED is printed as the command prints it and raised as a warning
22
+ * annotation, so it is visible on the run without being mistaken for zero.
23
+ * A non-zero exit is the command refusing its arguments or `bunx` failing,
24
+ * which is the tool broken, and the step goes red on it.
25
+ *
26
+ * ## It calls the published CLI
27
+ *
28
+ * A consumer has `node_modules/rungate`, not `scripts/`, so the step runs
29
+ * `bunx rungate@<version> intake`, at the generating version like every other
30
+ * pin. `intake` first shipped in 0.8.23 (#2250).
31
+ */
32
+
33
+ /** The file this module generates, under `.github/workflows/`. */
34
+ export const INTAKE_WORKFLOW_FILE = "intake.yml";
35
+
36
+ /** The one job in it. */
37
+ export const INTAKE_JOB = "fix-commit-intake";
38
+
39
+ /**
40
+ * The CLI command the step runs. `lib/cli-commands.ts` must register it, or
41
+ * the workflow calls a command `bin/rungate.ts` refuses (#675's defect).
42
+ */
43
+ export const INTAKE_COMMAND = "intake";
44
+
45
+ /**
46
+ * The step's `run:` body. Exported so `test/intake-workflow.test.ts` executes
47
+ * THIS text against a stub `bunx`, rather than a paraphrase.
48
+ *
49
+ * The output is captured so it can be both printed and inspected. Under
50
+ * `bash -e` a failing command substitution in an assignment stops the step,
51
+ * which is the red a broken tool should produce.
52
+ */
53
+ export function buildIntakeScript(version: string): string {
54
+ return `out=$(bunx rungate@${version} ${INTAKE_COMMAND} --source fix-commits)
55
+ printf '%s\\n' "$out"
56
+ case "$out" in
57
+ *UNMEASURED*)
58
+ echo "::warning::UNMEASURED — the fix-commits intake reading could not be taken on this run; the reason is printed above. This is not zero candidates."
59
+ ;;
60
+ esac
61
+ `;
62
+ }
63
+
64
+ export interface IntakeWorkflowOptions {
65
+ /** The `runs-on:` value, already JSON-quoted by the caller. */
66
+ runsOn: string;
67
+ /** The pinned `actions/checkout` reference. */
68
+ checkout: string;
69
+ /** The pinned `oven-sh/setup-bun` reference. */
70
+ setupBun: string;
71
+ /** The `with:` body of that step, at ten spaces — the project's single bun declaration (#622). */
72
+ setupBunWith: string;
73
+ /** The step's `env:` block, from `setupBunEnv` (#2039). */
74
+ setupBunEnv: string;
75
+ /** The published harness version the step runs through `bunx`. */
76
+ version: string;
77
+ }
78
+
79
+ /** The whole `intake.yml` body. */
80
+ export function buildIntakeWorkflow(opts: IntakeWorkflowOptions): string {
81
+ const indent = (text: string, pad: string) =>
82
+ text
83
+ .trimEnd()
84
+ .split("\n")
85
+ .map(line => (line === "" ? "" : `${pad}${line}`))
86
+ .join("\n");
87
+
88
+ return `# Managed by rungate — do not edit. Customize the ci section of .claude/rungate/config.json.
89
+ #
90
+ # Mines the default branch's fix commits into rule candidates on every push to
91
+ # it (#2233). Jason's #1126 decision: each intake source runs on its own
92
+ # trigger, never on scaffold. Advisory: a reading never fails the run, and an
93
+ # UNMEASURED one is raised as a warning rather than read as zero.
94
+ name: Intake — fix commits
95
+
96
+ on:
97
+ push:
98
+ branches: [main]
99
+
100
+ permissions:
101
+ contents: read
102
+
103
+ jobs:
104
+ ${INTAKE_JOB}:
105
+ runs-on: ${opts.runsOn}
106
+ steps:
107
+ # Full history: a depth-1 clone is the only reason this source reads
108
+ # UNMEASURED (SHALLOW_HISTORY) on a runner.
109
+ - uses: ${opts.checkout}
110
+ with:
111
+ fetch-depth: 0
112
+ - uses: ${opts.setupBun}
113
+ with:
114
+ ${opts.setupBunWith}
115
+ ${opts.setupBunEnv}
116
+ - name: Mine fix commits into rule candidates
117
+ run: |
118
+ ${indent(buildIntakeScript(opts.version), " ")}
119
+ `;
120
+ }
@@ -210,6 +210,16 @@ export const OWNED_FILES: OwnedFile[] = [
210
210
  customize: "Set `board.id` in config and secret `RUNGATE_PROJECT_TOKEN`; add your own jobs alongside the generated `add-to-board` job",
211
211
  avoid: "Don't edit the generated `add-to-board` job",
212
212
  },
213
+ {
214
+ // #2233: fix-commit intake on push to main, with full history. Jason's
215
+ // #1126 decision put each intake source on its own trigger; a consumer has
216
+ // no scripts/, so the generator writes it and calls the published CLI.
217
+ path: ".github/workflows/intake.yml",
218
+ strategy: "job-preserving",
219
+ servedBy: "writeManagedFile (lib/scaffold/steps.ts) via mergeManagedWorkflow — the harness owns named jobs, not the file",
220
+ customize: "Advisory — a reading never fails the run; add your own jobs alongside the generated `fix-commit-intake` job",
221
+ avoid: "Don't edit the generated `fix-commit-intake` job, and don't drop `fetch-depth: 0` — a shallow clone reads UNMEASURED",
222
+ },
213
223
  {
214
224
  // `regenerate` until #655, and the declaration was never consulted:
215
225
  // `generateAgentBriefsStep` called `writeFileSync` directly, so the row
@@ -50,6 +50,7 @@ import {
50
50
  } from "./ai-review-unmeasured-workflow";
51
51
  import { buildAdrAcceptedWorkflow } from "./adr-accepted-workflow";
52
52
  import { buildClosingReferencesWorkflow } from "./closing-references-workflow";
53
+ import { buildIntakeWorkflow } from "./intake-workflow";
53
54
  import { buildBoardReadyWorkflow } from "./board-ready-workflow";
54
55
  import { buildBoardIntakeWorkflow } from "./board-intake-workflow";
55
56
  import { CI_SUITE_FETCH_DEPTH, baseRefFetchDepth } from "../ci-history-depth";
@@ -4515,6 +4516,18 @@ ${buildAuthDetectStep(vertex)}${buildReviewRunStep(
4515
4516
  version: harnessVersion(),
4516
4517
  });
4517
4518
 
4519
+ // #2233: fix-commit intake on every push to main, with full history (Jason's
4520
+ // #1126 decision: each intake source on its own trigger, never on scaffold).
4521
+ // It calls the published CLI's `intake`, first shipped in 0.8.23.
4522
+ const intakeYml = buildIntakeWorkflow({
4523
+ runsOn,
4524
+ checkout: actionRef("actions/checkout"),
4525
+ setupBun: actionRef("oven-sh/setup-bun"),
4526
+ setupBunWith: bunStep,
4527
+ setupBunEnv: setupBunEnv(" "),
4528
+ version: harnessVersion(),
4529
+ });
4530
+
4518
4531
  // #2166, ADR-014 row 4: new issues and pull requests onto the board. It
4519
4532
  // names no board: the published CLI prints board.id from the default
4520
4533
  // branch's config (#2173), and the add uses that node id.
@@ -4542,7 +4555,7 @@ ${buildAuthDetectStep(vertex)}${buildReviewRunStep(
4542
4555
  // lib/conformity.ts reads back, and the two are held together by
4543
4556
  // test/ai-review-workflow.test.ts AC-1, which looks for the constant's
4544
4557
  // filename in what this loop actually wrote.
4545
- for (const [name, content] of [["ci.yml", ciYml], ["gates.yml", gatesYml], ["ai-review.yml", aiReviewYml], ["ai-review-unmeasured.yml", aiReviewUnmeasuredYml], ["adr-accepted.yml", adrAcceptedYml], ["closing-references.yml", closingReferencesYml], ["board-ready.yml", boardReadyYml], ["board-intake.yml", boardIntakeYml]] as const) {
4558
+ for (const [name, content] of [["ci.yml", ciYml], ["gates.yml", gatesYml], ["ai-review.yml", aiReviewYml], ["ai-review-unmeasured.yml", aiReviewUnmeasuredYml], ["adr-accepted.yml", adrAcceptedYml], ["closing-references.yml", closingReferencesYml], ["board-ready.yml", boardReadyYml], ["board-intake.yml", boardIntakeYml], ["intake.yml", intakeYml]] as const) {
4546
4559
  const label = `.github/workflows/${name}`;
4547
4560
  try {
4548
4561
  // Keyed by FILE, and the lookup is here because this loop is the only
@@ -509,6 +509,68 @@ export function stageLadderViolations(raw: unknown): string[] {
509
509
  });
510
510
  });
511
511
 
512
+ out.push(...duplicateVerifyViolations(raw));
513
+ return out;
514
+ }
515
+
516
+ /**
517
+ * Two items proved by one command — #2236.
518
+ *
519
+ * They can never disagree, so the second is never checked as its own claim:
520
+ * whatever makes the first true makes the second true, which is the
521
+ * done-condition restated that AGENTS.md rule 10 forbids. On #2221, E4's first
522
+ * proof was B4's `criteria-field` reading copied byte for byte, and only
523
+ * review caught it.
524
+ *
525
+ * Across the WHOLE ladder, not within a stage, because that is where it
526
+ * happened. Compared after trimming, so a copied command with a stray newline
527
+ * is still the same command. A null verify is an item nobody has written a
528
+ * proof for yet, and two of those duplicate nothing.
529
+ *
530
+ * Retro improvements are in the same population (review of #2243): an
531
+ * improvement's verify proves a mechanism is in place, which is a claim of
532
+ * the same kind, and the live plan carried #1849's improvement in two retros
533
+ * with one command until #2245. An improvement is named by its stage and its
534
+ * 1-based position, `"C retro improvement 2"`, because it has no id.
535
+ */
536
+ function duplicateVerifyViolations(raw: unknown[]): string[] {
537
+ const proofs: { id: string; verify: unknown }[] = [];
538
+ for (const s of raw) {
539
+ const stage = s as { id?: unknown; items?: unknown; retro?: unknown } | null;
540
+ if (stage === null || typeof stage !== "object") continue;
541
+ if (Array.isArray(stage.items)) {
542
+ for (const it of stage.items) {
543
+ const item = it as { id?: unknown; verify?: unknown } | null;
544
+ if (item !== null && typeof item === "object") proofs.push({ id: String(item.id), verify: item.verify });
545
+ }
546
+ }
547
+ const improvements = (stage.retro as { improvements?: unknown } | null)?.improvements;
548
+ if (Array.isArray(improvements)) {
549
+ improvements.forEach((imp, k) => {
550
+ const i = imp as { verify?: unknown } | null;
551
+ if (i !== null && typeof i === "object") {
552
+ proofs.push({ id: `${String(stage.id)} retro improvement ${k + 1}`, verify: i.verify });
553
+ }
554
+ });
555
+ }
556
+ }
557
+ const first = new Map<string, string>();
558
+ const out: string[] = [];
559
+ for (const { id, verify } of proofs) {
560
+ if (typeof verify !== "string") continue;
561
+ const cmd = verify.trim();
562
+ if (cmd === "") continue;
563
+ const earlier = first.get(cmd);
564
+ if (earlier === undefined) {
565
+ first.set(cmd, id);
566
+ continue;
567
+ }
568
+ out.push(
569
+ `"${earlier}" and "${id}" carry the same verify command, so they can never disagree and ` +
570
+ `"${id}" is never checked as its own claim — a done-condition restated (AGENTS.md rule 10). ` +
571
+ `Give "${id}" a command that reads what only it claims.`,
572
+ );
573
+ }
512
574
  return out;
513
575
  }
514
576
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rungate",
3
- "version": "0.8.22",
3
+ "version": "0.8.24",
4
4
  "type": "module",
5
5
  "description": "Ship harness — conformity tests, scaffold, and agent briefs for AI-first development",
6
6
  "repository": {
@@ -37,6 +37,7 @@
37
37
  "scripts/board-ready.ts",
38
38
  "scripts/board-id.ts",
39
39
  "scripts/unaccounted-work.ts",
40
+ "scripts/intake.ts",
40
41
  "scripts/board-intake-move.ts",
41
42
  "scripts/audit-closing-references.ts",
42
43
  "scripts/create-spec.ts",
@@ -94,7 +94,7 @@
94
94
  import { aiReviewJuryGate } from "../lib/ai-review-jury";
95
95
  import { productionSuppression } from "../lib/ai-review-suppression";
96
96
  import { main } from "../lib/scaffold/ai-review-findings";
97
- import { AI_REVIEW_BALLOT_DIR_ENV, AI_REVIEW_THREADS_PATH_VAR } from "../lib/scaffold/ai-review-step";
97
+ import { AI_REVIEW_BALLOT_DIR_ENV, AI_REVIEW_CHECKOUT_ROOT_VAR, AI_REVIEW_THREADS_PATH_VAR } from "../lib/scaffold/ai-review-step";
98
98
 
99
99
  const ballotDir = process.env[AI_REVIEW_BALLOT_DIR_ENV];
100
100
  const jury =
@@ -105,9 +105,13 @@ const jury =
105
105
  // Assembled in `lib/`, not here. This command and `ai-review-threads.ts` must
106
106
  // form the SAME gate from the same file, and two hand-written literals is how
107
107
  // `anchorOccurrences` reached one of them and not the other (#1861 round 4).
108
+ // #2257: the checkout by name. The generated step runs this from the payload's
109
+ // directory on purpose, so the working directory is not the checkout; it is
110
+ // the fallback only for a step generated before the variable was set.
111
+ const checkoutRoot = process.env[AI_REVIEW_CHECKOUT_ROOT_VAR];
108
112
  const { gate: suppress } = productionSuppression(
109
113
  process.env[AI_REVIEW_THREADS_PATH_VAR],
110
- process.cwd(),
114
+ checkoutRoot !== undefined && checkoutRoot !== "" ? checkoutRoot : process.cwd(),
111
115
  );
112
116
 
113
117
  // One line, and `process.exit(main(` is load-bearing text: AC-4 in
@@ -0,0 +1,101 @@
1
+ #!/usr/bin/env bun
2
+ /**
3
+ * `rungate intake` — run the registered intake sources and print each one's
4
+ * reading (#2248).
5
+ *
6
+ * Before this, nothing outside `lib/intake-sources.ts` called
7
+ * `mineObservedFailures`, so no command ran intake at all. Jason decided on
8
+ * #1126 (2026-11-15) that each source runs on its own trigger: `fix-commits`
9
+ * in CI on push to main with full history (#2233), `gate-refusals` at the end
10
+ * of a ship run (#2234). Both call this.
11
+ *
12
+ * ADVISORY. A source that cannot be read here prints UNMEASURED with the
13
+ * producer's own reason and the command still exits 0: a shallow clone or an
14
+ * absent run store says nothing about the change that triggered the run, so
15
+ * it must never turn that run red. UNMEASURED is printed, never a silent
16
+ * zero, and the partial count of an unmeasured reading is never printed as
17
+ * the reading (`AggregateIntakeReading` withholds `candidates` there for the
18
+ * same reason). A bad argument is the only refusal.
19
+ */
20
+ import { resolve } from "path";
21
+ import {
22
+ INTAKE_SOURCES,
23
+ defaultIntakeContext,
24
+ mineObservedFailures,
25
+ type IntakeContext,
26
+ } from "../lib/intake-sources";
27
+
28
+ /** A bad argument. The only non-zero exit: every reading exits 0. */
29
+ export const EXIT_REFUSED = 2;
30
+
31
+ const USAGE =
32
+ "rungate intake [--project-root <dir>] [--source <id>] [--json] " +
33
+ `(sources: ${INTAKE_SOURCES.map(s => s.id).join(", ")}; advisory — an unreadable source prints UNMEASURED and exits 0)`;
34
+
35
+ /**
36
+ * `deps.workStore` overrides the run store, so a test reads a fixture rather
37
+ * than this machine's `~/.rungate`. Absent, `defaultIntakeContext` decides,
38
+ * which reads `RUNGATE_WORK_DIR` through `lib/paths.ts`.
39
+ */
40
+ export function main(argv: readonly string[], deps: { workStore?: string } = {}): number {
41
+ let rootArg: string | undefined;
42
+ let source: string | undefined;
43
+ let json = false;
44
+ for (let i = 0; i < argv.length; i++) {
45
+ const a = argv[i];
46
+ if (a === "--json") {
47
+ json = true;
48
+ } else if (a === "--project-root" || a === "--source") {
49
+ const next = argv[i + 1];
50
+ if (next === undefined || next.startsWith("--")) {
51
+ console.error(`intake: ${a} needs a value after it. Nothing was read.\n${USAGE}`);
52
+ return EXIT_REFUSED;
53
+ }
54
+ if (a === "--project-root") rootArg = next;
55
+ else source = next;
56
+ i++;
57
+ } else {
58
+ console.error(`intake: unknown argument ${JSON.stringify(a)}. Nothing was read.\n${USAGE}`);
59
+ return EXIT_REFUSED;
60
+ }
61
+ }
62
+
63
+ const sources = source === undefined ? INTAKE_SOURCES : INTAKE_SOURCES.filter(s => s.id === source);
64
+ if (sources.length === 0) {
65
+ console.error(
66
+ `intake: no source is named ${JSON.stringify(source)}. The registered sources are ` +
67
+ `${INTAKE_SOURCES.map(s => s.id).join(", ")}. Nothing was read.`,
68
+ );
69
+ return EXIT_REFUSED;
70
+ }
71
+
72
+ const root = resolve(rootArg ?? process.cwd());
73
+ const base = defaultIntakeContext(root);
74
+ const ctx: IntakeContext = deps.workStore === undefined ? base : { ...base, workStore: deps.workStore };
75
+ const reading = mineObservedFailures(ctx, sources);
76
+
77
+ if (json) {
78
+ console.log(JSON.stringify(reading, null, 2));
79
+ return 0;
80
+ }
81
+
82
+ for (const s of sources) {
83
+ const r = reading.bySource[s.id];
84
+ if (r.reading === "MEASURED") {
85
+ console.log(
86
+ `${s.id}: MEASURED — ${r.candidates.length} candidate(s) from ${r.commitsScanned} unit(s) of history read`,
87
+ );
88
+ } else {
89
+ console.log(`${s.id}: UNMEASURED — ${r.unmeasuredReasons.join("; ")}`);
90
+ }
91
+ }
92
+ console.log(
93
+ reading.reading === "MEASURED"
94
+ ? `intake: MEASURED — ${reading.candidates.length} candidate(s) across ${sources.length} source(s)`
95
+ : `intake: UNMEASURED — ${reading.unmeasuredReasons.length} reason(s) above; ` +
96
+ `${reading.partialCandidates.length} candidate(s) came from the sources that could be read, and are not a reading`,
97
+ );
98
+ return 0;
99
+ }
100
+
101
+ if (import.meta.main) process.exitCode = main(process.argv.slice(2));