rungate 0.5.0 → 0.6.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.
- package/lib/agents-md-sections.ts +144 -0
- package/lib/branch-diff.ts +139 -0
- package/lib/bun-version.ts +268 -0
- package/lib/ci-checkout.ts +1 -1
- package/lib/compliance.ts +13 -11
- package/lib/config-loader.ts +12 -0
- package/lib/conformity.ts +184 -88
- package/lib/context-docs.ts +143 -28
- package/lib/create-brief.ts +2 -1
- package/lib/create-sc.ts +90 -4
- package/lib/doc-scan-targets.ts +9 -0
- package/lib/evidence-command-transport.ts +160 -0
- package/lib/evidence-prevalidator.ts +22 -0
- package/lib/fallow-availability.ts +129 -0
- package/lib/gate-refusal-currency.ts +112 -0
- package/lib/gate-timeouts.ts +82 -0
- package/lib/generators/agent-briefs.ts +4 -1
- package/lib/generators/agents-md.ts +71 -23
- package/lib/generators/code-map.ts +2 -1
- package/lib/generators/types.ts +8 -0
- package/lib/git-dates.ts +55 -0
- package/lib/junit-checks.ts +484 -0
- package/lib/local-calendar-day.ts +78 -0
- package/lib/project-state-shape.ts +59 -0
- package/lib/promote-outputs.ts +6 -2
- package/lib/report-provenance.ts +156 -0
- package/lib/sc-claim-forms.ts +75 -0
- package/lib/sc-id-cross-tree.ts +311 -0
- package/lib/scaffold/ai-review-step.ts +180 -0
- package/lib/scaffold/owned-files.ts +42 -2
- package/lib/scaffold/rehearsal.ts +205 -71
- package/lib/scaffold/steps.ts +128 -73
- package/lib/scaffold/write-steps.ts +6 -4
- package/lib/scanner.ts +38 -12
- package/lib/spec-listing.ts +148 -0
- package/lib/spec-requirements.ts +209 -0
- package/lib/suite-run-reading.ts +170 -0
- package/lib/test-command.ts +133 -0
- package/lib/test-suite-lock.ts +166 -10
- package/lib/tool-probe.ts +120 -0
- package/lib/tracked-vs-ignored.ts +234 -0
- package/lib/validators/spec-validators.ts +3 -2
- package/package.json +1 -1
- package/scripts/audit-specs.ts +247 -12
- package/scripts/audit-transcript.ts +2 -1
- package/scripts/convert-spec.ts +2 -1
- package/scripts/create-sc.ts +17 -7
- package/scripts/create-spec.ts +2 -1
- package/scripts/create-success.ts +2 -1
- package/scripts/extract-constraints.ts +90 -19
- package/scripts/generate-code-map.ts +53 -12
- package/scripts/scaffold-project.ts +4 -1
- package/scripts/split-spec.ts +2 -1
- package/scripts/sync-sc-status.ts +57 -5
- package/scripts/sync-spec-tests.ts +2 -1
|
@@ -13,6 +13,7 @@ import type { ProjectScan } from "./types";
|
|
|
13
13
|
import { OWNED_FILES, ownedFilesTable } from "../scaffold/owned-files";
|
|
14
14
|
import { isHarnessItself } from "../harness-identity";
|
|
15
15
|
import { typecheckDecision } from "../typescript-project";
|
|
16
|
+
import { localCalendarDay } from "../local-calendar-day";
|
|
16
17
|
|
|
17
18
|
/**
|
|
18
19
|
* Build the AGENTS.md frontmatter block.
|
|
@@ -22,34 +23,37 @@ import { typecheckDecision } from "../typescript-project";
|
|
|
22
23
|
* drop a hand-set owner, and emitting nothing — the previous behavior —
|
|
23
24
|
* stripped the block entirely on every re-scaffold.
|
|
24
25
|
*/
|
|
26
|
+
export function existingFrontmatter(root: string): Record<string, string> {
|
|
27
|
+
const path = join(root, "AGENTS.md");
|
|
28
|
+
const existing: Record<string, string> = {};
|
|
29
|
+
if (!existsSync(path)) return existing;
|
|
30
|
+
const content = readFileSync(path, "utf-8");
|
|
31
|
+
const match = content.match(/^---\n([\s\S]*?)\n---\n/);
|
|
32
|
+
if (!match) return existing;
|
|
33
|
+
for (const line of match[1].split("\n")) {
|
|
34
|
+
const kv = line.match(/^([\w-]+):\s*(.*)$/);
|
|
35
|
+
if (!kv) continue;
|
|
36
|
+
const value = kv[2].trim();
|
|
37
|
+
// Carry forward only simple scalars. The block is re-emitted verbatim,
|
|
38
|
+
// so a value holding a delimiter or control character could terminate
|
|
39
|
+
// the frontmatter early and turn the rest of the file into a second
|
|
40
|
+
// document — or smuggle keys past this loop on the next round-trip.
|
|
41
|
+
if (value.includes("---") || /[\x00-\x1f]/.test(value)) continue;
|
|
42
|
+
if (value.length > 200) continue;
|
|
43
|
+
existing[kv[1]] = value;
|
|
44
|
+
}
|
|
45
|
+
return existing;
|
|
46
|
+
}
|
|
47
|
+
|
|
25
48
|
function buildFrontmatter(root: string): string {
|
|
26
|
-
const today =
|
|
49
|
+
const today = localCalendarDay();
|
|
27
50
|
const defaults: Record<string, string> = {
|
|
28
51
|
"doc-type": "reference",
|
|
29
52
|
status: "active",
|
|
30
53
|
updated: today,
|
|
31
54
|
};
|
|
32
55
|
|
|
33
|
-
const
|
|
34
|
-
const existing: Record<string, string> = {};
|
|
35
|
-
if (existsSync(path)) {
|
|
36
|
-
const content = readFileSync(path, "utf-8");
|
|
37
|
-
const match = content.match(/^---\n([\s\S]*?)\n---\n/);
|
|
38
|
-
if (match) {
|
|
39
|
-
for (const line of match[1].split("\n")) {
|
|
40
|
-
const kv = line.match(/^([\w-]+):\s*(.*)$/);
|
|
41
|
-
if (!kv) continue;
|
|
42
|
-
const value = kv[2].trim();
|
|
43
|
-
// Carry forward only simple scalars. The block is re-emitted verbatim,
|
|
44
|
-
// so a value holding a delimiter or control character could terminate
|
|
45
|
-
// the frontmatter early and turn the rest of the file into a second
|
|
46
|
-
// document — or smuggle keys past this loop on the next round-trip.
|
|
47
|
-
if (value.includes("---") || /[\x00-\x1f]/.test(value)) continue;
|
|
48
|
-
if (value.length > 200) continue;
|
|
49
|
-
existing[kv[1]] = value;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
56
|
+
const existing = existingFrontmatter(root);
|
|
53
57
|
|
|
54
58
|
const merged: Record<string, string> = { ...defaults, ...existing, updated: today };
|
|
55
59
|
const order = ["doc-type", "status", "owner", "updated"];
|
|
@@ -76,7 +80,23 @@ export function generateAgentsMd(scan: ProjectScan): string {
|
|
|
76
80
|
} = scan;
|
|
77
81
|
|
|
78
82
|
const techLine = techStack.length > 0 ? `\n**Tech:** ${techStack.join(", ")}` : "";
|
|
79
|
-
|
|
83
|
+
|
|
84
|
+
// #552. `scan.repoUrl` is `git remote get-url origin`, and a project with
|
|
85
|
+
// no remote called `origin` gets `""` — which this line turned into
|
|
86
|
+
// `<!-- TODO: Add repo URL -->`, twice, on every single run, with NOWHERE
|
|
87
|
+
// for the consumer to put the answer. `--profile=minimal` writes no
|
|
88
|
+
// `.claude/rungate/`, so there was no config key either, and editing
|
|
89
|
+
// AGENTS.md is futile because the next run regenerates it.
|
|
90
|
+
//
|
|
91
|
+
// The frontmatter is the place, because it is the one part of this file
|
|
92
|
+
// that already survives regeneration: `buildFrontmatter` carries forward
|
|
93
|
+
// every simple scalar the existing block declared. So `repo:` written once
|
|
94
|
+
// by hand persists, and the git remote stays the default when there is one.
|
|
95
|
+
const declaredRepo = existingFrontmatter(scan.root).repo;
|
|
96
|
+
const effectiveRepoUrl = repoUrl || (declaredRepo ?? "");
|
|
97
|
+
const repoLine = effectiveRepoUrl
|
|
98
|
+
? `- **Repo:** ${effectiveRepoUrl}`
|
|
99
|
+
: "<!-- TODO: Add repo URL — set `repo:` in this file's frontmatter, which survives regeneration -->";
|
|
80
100
|
|
|
81
101
|
const consumerSection = consumers.length > 0
|
|
82
102
|
? `\n## Consumers (${consumers.length})\n\n${consumers.map(c => `- ${c}`).join("\n")}\n\nCheck cascade impact when modifying shared modules.`
|
|
@@ -284,7 +304,16 @@ If Skill("harness") or Skill("goal") fails, fall back to Skill("ship") with the
|
|
|
284
304
|
});
|
|
285
305
|
|
|
286
306
|
if (specs.length > 0) {
|
|
287
|
-
|
|
307
|
+
// A row that sends a reader to a document stating no requirements says so
|
|
308
|
+
// in the row (#579). `specs/PROJECT-STATE.md` sat here for two months as
|
|
309
|
+
// the governing spec for project state management while being a rendered
|
|
310
|
+
// status snapshot, and the table was the reason anyone went there.
|
|
311
|
+
const specsTable = specs
|
|
312
|
+
.map(s => {
|
|
313
|
+
const governs = s.criteriaNone ? `STATES NO CRITERIA — ${s.governs}` : s.governs;
|
|
314
|
+
return `| ${s.file} | ${governs} | ${s.testable} |`;
|
|
315
|
+
})
|
|
316
|
+
.join("\n");
|
|
288
317
|
rules.push({
|
|
289
318
|
filename: "specs-routing.md",
|
|
290
319
|
content: `---
|
|
@@ -357,8 +386,27 @@ ${ownedFilesTable()}
|
|
|
357
386
|
| regenerate | Rewrites it every run; reports CHANGED only when the bytes differ |
|
|
358
387
|
| provenance | Rewrites it unless you edited it, in which case it is preserved and reported (#370) |
|
|
359
388
|
| job-preserving | Owns named jobs inside a file you also write to; your jobs are carried forward |
|
|
389
|
+
| section-preserving | Rewrites the file every run except for named sections, which are carried forward verbatim |
|
|
360
390
|
| create-only | Seeds it once and never touches it again — the content is yours, not the harness's |
|
|
361
391
|
|
|
392
|
+
### AGENTS.md is section-owned (#568)
|
|
393
|
+
|
|
394
|
+
Everything in \`AGENTS.md\` is generated from the scan and your
|
|
395
|
+
\`.claude/rungate/\` config, with one exception: a \`## Hard Constraints\`
|
|
396
|
+
section is yours, and a re-scaffold carries it forward verbatim —
|
|
397
|
+
including the \`<!-- BEGIN AUTO-EXTRACTED -->\` block, and including any
|
|
398
|
+
lines you wrote outside it.
|
|
399
|
+
|
|
400
|
+
That is the only user-owned content in the tree that survives
|
|
401
|
+
regeneration, which is a promise \`specs/bootstrap-data-flow/\` makes and
|
|
402
|
+
nothing kept until #568: one run on a consumer removed 37 constraint
|
|
403
|
+
lines and reported \`REGENERATED: AGENTS.md\`, exit 0. Put non-inferable
|
|
404
|
+
project rules there — the ones an agent cannot read off the code — and
|
|
405
|
+
nowhere else in the file.
|
|
406
|
+
|
|
407
|
+
If a run cannot carry every one of those lines forward it **refuses the
|
|
408
|
+
write**, names the lines, and leaves your file untouched.
|
|
409
|
+
|
|
362
410
|
### The workflow files are job-owned, not file-owned (#216)
|
|
363
411
|
|
|
364
412
|
rungate owns the \`test\` job in \`ci.yml\` and the \`gates\` job in
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* Takes scan data in, produces file content out. No file I/O.
|
|
6
6
|
*/
|
|
7
7
|
import type { ProjectScan } from "./types";
|
|
8
|
+
import { localCalendarDay } from "../local-calendar-day";
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* Generate CODE-MAP.md content from project scan data.
|
|
@@ -12,7 +13,7 @@ import type { ProjectScan } from "./types";
|
|
|
12
13
|
* Returns the full markdown string. Does NOT write files.
|
|
13
14
|
*/
|
|
14
15
|
export function generateCodeMap(scan: ProjectScan): string {
|
|
15
|
-
const today =
|
|
16
|
+
const today = localCalendarDay();
|
|
16
17
|
const { name, dirs, deps, devDeps, modules, routes } = scan;
|
|
17
18
|
|
|
18
19
|
let md = `---
|
package/lib/generators/types.ts
CHANGED
|
@@ -17,6 +17,14 @@ export interface SpecEntry {
|
|
|
17
17
|
file: string;
|
|
18
18
|
governs: string;
|
|
19
19
|
testable: string;
|
|
20
|
+
/**
|
|
21
|
+
* The spec declares `criteria: none` in its frontmatter (#579).
|
|
22
|
+
*
|
|
23
|
+
* Carried into the routing table rather than left in the file, because the
|
|
24
|
+
* reader harmed by a criteria-free spec is the one the table SENDS there.
|
|
25
|
+
* Optional so a consumer's scanner predating this still typechecks.
|
|
26
|
+
*/
|
|
27
|
+
criteriaNone?: boolean;
|
|
20
28
|
}
|
|
21
29
|
|
|
22
30
|
export interface TestFile {
|
package/lib/git-dates.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every path's most recent commit date, from ONE git subprocess (#323).
|
|
3
|
+
*
|
|
4
|
+
* A LEAF module (#508). The implementation and its history live below,
|
|
5
|
+
* unchanged, moved out of `lib/conformity.ts` so a CLI can use it:
|
|
6
|
+
* conformity imports `bun:test` at module scope, and
|
|
7
|
+
* `scripts/extract-constraints.ts` runs outside a test runner. It is
|
|
8
|
+
* re-exported from `lib/conformity.ts`, which is the name every existing
|
|
9
|
+
* caller and SC-842 knows — one binding, two names, the same arrangement
|
|
10
|
+
* `isHarnessItself` has with `lib/harness-identity.ts` (#380).
|
|
11
|
+
*
|
|
12
|
+
* The second caller is why this moved. `computeStaleness` in
|
|
13
|
+
* `scripts/extract-constraints.ts` was still spawning one `git log` per
|
|
14
|
+
* document — the exact code #323 replaced here, in a file #323 did not
|
|
15
|
+
* touch — and HYGIENE-6 was timing out at 5001ms because of it.
|
|
16
|
+
*/
|
|
17
|
+
import { spawnSync } from "child_process";
|
|
18
|
+
import { existsSync } from "fs";
|
|
19
|
+
import { join } from "path";
|
|
20
|
+
|
|
21
|
+
export function lastCommitDates(root: string, pathspecs: string[]): Map<string, string> {
|
|
22
|
+
const lastCommit = new Map<string, string>();
|
|
23
|
+
// Not a git repository: nothing is tracked, so no path has a commit date.
|
|
24
|
+
// That is a real answer, not a failure, and scaffolded projects hit it.
|
|
25
|
+
if (!existsSync(join(root, ".git"))) return lastCommit;
|
|
26
|
+
if (pathspecs.length === 0) return lastCommit;
|
|
27
|
+
{
|
|
28
|
+
const log = spawnSync(
|
|
29
|
+
"git",
|
|
30
|
+
["-C", root, "log", "--format=%H %ci", "--name-only", "--", ...pathspecs],
|
|
31
|
+
{ timeout: 60_000, maxBuffer: 64 * 1024 * 1024 },
|
|
32
|
+
);
|
|
33
|
+
if (log.error) {
|
|
34
|
+
throw new Error(`lastCommitDates: git log could not run in ${root}: ${log.error.message}`);
|
|
35
|
+
}
|
|
36
|
+
if (log.status !== 0) {
|
|
37
|
+
throw new Error(
|
|
38
|
+
`lastCommitDates: git log exited ${log.status} in ${root}: ` +
|
|
39
|
+
`${log.stderr?.toString().trim() || "(no stderr)"}`,
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
let currentDate = "";
|
|
43
|
+
for (const line of log.stdout.toString().split("\n")) {
|
|
44
|
+
const header = /^[0-9a-f]{7,40} (\d{4}-\d{2}-\d{2})/.exec(line);
|
|
45
|
+
if (header) {
|
|
46
|
+
currentDate = header[1];
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
const path = line.trim();
|
|
50
|
+
if (!path || !currentDate) continue;
|
|
51
|
+
if (!lastCommit.has(path)) lastCommit.set(path, currentDate);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return lastCommit;
|
|
55
|
+
}
|