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.
- package/lib/affected-tests.ts +398 -0
- package/lib/agent-audit.ts +2 -3
- package/lib/agent-worktree.ts +287 -0
- package/lib/agents-md-sections.ts +209 -0
- package/lib/behavioral-cache.ts +150 -2
- package/lib/branch-diff.ts +139 -0
- package/lib/branch-protection.ts +790 -0
- package/lib/brief-ac-alignment.ts +104 -0
- package/lib/brief-references.ts +205 -0
- package/lib/bun-version.ts +347 -0
- package/lib/check-remedy.ts +140 -0
- package/lib/ci-checkout.ts +18 -1
- package/lib/ci-history-depth.ts +159 -0
- package/lib/ci-setup-step.ts +96 -0
- package/lib/claude-code-action.ts +85 -0
- package/lib/claude-tool-vocabulary.ts +188 -0
- package/lib/cli-commands.ts +15 -0
- package/lib/commit-sha.ts +42 -0
- package/lib/commit-subject.ts +90 -0
- package/lib/compliance-report.ts +377 -45
- package/lib/compliance.ts +196 -20
- package/lib/config-loader.ts +51 -1
- package/lib/config-trackable.ts +391 -0
- package/lib/conformity.ts +1272 -189
- package/lib/containment.ts +238 -0
- package/lib/content-hash.ts +24 -0
- package/lib/context-docs.ts +143 -28
- package/lib/create-brief.ts +2 -1
- package/lib/create-sc.ts +323 -4
- package/lib/dev-liveness.ts +180 -0
- package/lib/discovery-branch-points.ts +432 -0
- package/lib/discovery-stability.ts +481 -0
- package/lib/distribution-currency.ts +186 -0
- package/lib/doc-routing.ts +157 -0
- package/lib/doc-scan-targets.ts +9 -0
- package/lib/evidence-command-transport.ts +160 -0
- package/lib/evidence-prevalidator.ts +246 -2
- package/lib/evidence-satisfiability.ts +534 -12
- package/lib/failure-intake.ts +317 -0
- package/lib/fallow-availability.ts +286 -0
- package/lib/fs-write-capabilities.ts +232 -0
- package/lib/gate-refusal-currency.ts +112 -0
- package/lib/gate-run-split.ts +147 -0
- package/lib/gate-timeouts.ts +82 -0
- package/lib/generators/agent-briefs.ts +4 -1
- package/lib/generators/agents-md.ts +204 -48
- package/lib/generators/code-map.ts +2 -1
- package/lib/generators/types.ts +8 -0
- package/lib/git-dates.ts +55 -0
- package/lib/git-isolation.ts +140 -0
- package/lib/github.ts +15 -0
- package/lib/google-auth-action.ts +93 -0
- package/lib/harness-project.ts +48 -0
- package/lib/harness-provenance.ts +255 -0
- package/lib/hook-evidence.ts +235 -0
- package/lib/hook-scopes.ts +386 -0
- package/lib/hook-target-tree.ts +398 -0
- package/lib/hook-trees.ts +447 -0
- package/lib/js-top-level-code.ts +78 -10
- package/lib/junit-checks.ts +536 -0
- package/lib/launch-base.ts +253 -0
- package/lib/line-citation.ts +372 -0
- package/lib/local-calendar-day.ts +78 -0
- package/lib/orphan-reaper.ts +468 -0
- package/lib/parity-binding.ts +205 -0
- package/lib/per-test-timeouts.ts +219 -0
- package/lib/plan-coverage.ts +151 -0
- package/lib/prior-branch.ts +201 -8
- package/lib/process-table.ts +146 -0
- package/lib/project-state-derivation.ts +219 -0
- package/lib/project-state-root.ts +258 -0
- package/lib/project-state-shape.ts +59 -0
- package/lib/promote-outputs.ts +6 -2
- package/lib/published-artifact.ts +525 -0
- package/lib/readdir-sorted.ts +45 -0
- package/lib/report-provenance.ts +156 -0
- package/lib/review-execution-reading.ts +206 -0
- package/lib/review-tool-agreement.ts +433 -0
- package/lib/rule-promotion.ts +234 -0
- package/lib/rule-retirement.ts +525 -0
- package/lib/run-branch.ts +612 -0
- package/lib/rungate-schema.ts +19 -0
- package/lib/runner-home.ts +274 -0
- package/lib/sc-claim-forms.ts +75 -0
- package/lib/sc-id-cross-tree.ts +323 -0
- package/lib/sc-ids.ts +121 -13
- package/lib/sc-reservations.ts +289 -0
- package/lib/scaffold/ai-review-findings.ts +403 -0
- package/lib/scaffold/ai-review-step.ts +4777 -0
- package/lib/scaffold/managed-workflow.ts +587 -192
- package/lib/scaffold/owned-files.ts +186 -39
- package/lib/scaffold/pre-push-hook.ts +49 -5
- package/lib/scaffold/rehearsal.ts +205 -71
- package/lib/scaffold/steps.ts +1517 -293
- package/lib/scaffold/workflow-census.ts +217 -0
- package/lib/scaffold/workflow-drift.ts +217 -0
- package/lib/scaffold/write-steps.ts +10 -4
- package/lib/scan-budget.ts +247 -0
- package/lib/scanner.ts +80 -62
- package/lib/scratch-roots.ts +50 -5
- package/lib/screenshot-discovery.ts +121 -0
- package/lib/screenshot-upload.ts +41 -1
- package/lib/secret-patterns.ts +511 -8
- package/lib/ship-mode.ts +219 -0
- package/lib/source-slice.ts +294 -0
- package/lib/spec-listing.ts +148 -0
- package/lib/spec-requirements.ts +209 -0
- package/lib/stale-cleanup.ts +37 -3
- package/lib/suite-flake.ts +278 -0
- package/lib/suite-measurement.ts +23 -4
- package/lib/suite-run-reading.ts +411 -1
- package/lib/suite-timeout-margin.ts +193 -0
- package/lib/test-case-bodies.ts +883 -0
- package/lib/test-case-deletion.ts +653 -0
- package/lib/test-census.ts +97 -29
- package/lib/test-command-positions.ts +274 -0
- package/lib/test-command.ts +133 -0
- package/lib/test-suite-lock.ts +325 -26
- package/lib/tool-probe.ts +142 -0
- package/lib/top-level-cd.ts +393 -0
- package/lib/tracked-vs-ignored.ts +234 -0
- package/lib/tree-entries.ts +89 -0
- package/lib/ts-ast.ts +200 -0
- package/lib/validators/spec-validators.ts +3 -2
- package/lib/walk-test-files.ts +97 -0
- package/lib/workflow-actions.ts +263 -0
- package/lib/worktree-collect.ts +177 -5
- package/lib/worktree-repo.ts +36 -1
- package/package.json +2 -1
- package/scripts/ai-review-findings.ts +45 -0
- 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 +37 -7
- package/scripts/create-spec.ts +2 -1
- package/scripts/create-success.ts +2 -1
- package/scripts/extract-constraints.ts +197 -26
- package/scripts/generate-code-map.ts +62 -28
- package/scripts/scaffold-project.ts +12 -2
- package/scripts/split-spec.ts +2 -1
- package/scripts/sync-sc-status.ts +127 -14
- package/scripts/sync-spec-tests.ts +2 -1
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* config-trackable.ts — the harness's own config must not be a file git
|
|
3
|
+
* considers disposable (#505)
|
|
4
|
+
*
|
|
5
|
+
* ## The report
|
|
6
|
+
*
|
|
7
|
+
* A consumer's `.gitignore` ignored `.claude/` wholesale. Its
|
|
8
|
+
* `.claude/rungate.json` had been force-added on one feature branch and was
|
|
9
|
+
* untracked on `main`, so creating a branch off `main` **deleted the file
|
|
10
|
+
* from the working tree** — correctly, from git's point of view: tracked on
|
|
11
|
+
* the branch you leave, ignored on the branch you arrive at. No warning, no
|
|
12
|
+
* prompt, and nothing in `git status` afterwards to say anything had
|
|
13
|
+
* happened. `git clean -x` does the same thing from the other direction.
|
|
14
|
+
*
|
|
15
|
+
* What is lost is not recoverable from defaults: the `pages` map, the
|
|
16
|
+
* consumer list, `remoteHosts`, the `compliance.organize` block. The harness
|
|
17
|
+
* then resolves `absent` and reports "this project has no rungate config",
|
|
18
|
+
* which reads as an unscaffolded project rather than as a checkout artifact.
|
|
19
|
+
*
|
|
20
|
+
* ## Why this is the scaffold's problem and not the consumer's
|
|
21
|
+
*
|
|
22
|
+
* The objection on the issue — that a harness version-controlling its
|
|
23
|
+
* consumers' files on their behalf is worse than the bug — has the boundary
|
|
24
|
+
* in the wrong place. `createGitignore` in `lib/scaffold/steps.ts` already
|
|
25
|
+
* appends `requiredGitignorePatterns()` to an adopting project's
|
|
26
|
+
* `.gitignore` and reports `UPDATED: .gitignore (added N missing entries)`.
|
|
27
|
+
* The scaffold is already an author of that file. The question is only
|
|
28
|
+
* whether, having told a project what to ignore, it may also stop its own
|
|
29
|
+
* config from being one of those things.
|
|
30
|
+
*
|
|
31
|
+
* This makes the config **trackable**. It does not track it: no `git add`,
|
|
32
|
+
* no commit, nothing staged. That remains the consumer's.
|
|
33
|
+
*
|
|
34
|
+
* ## The negation the issue recommends does not work, measured
|
|
35
|
+
*
|
|
36
|
+
* The issue recommends `!.claude/rungate.json` in preference to un-ignoring
|
|
37
|
+
* `.claude/` wholesale, so that `settings.local.json` and `worktrees/` stay
|
|
38
|
+
* ignored. The intent is right and the pattern is inert:
|
|
39
|
+
*
|
|
40
|
+
* ```
|
|
41
|
+
* # .gitignore
|
|
42
|
+
* .claude/
|
|
43
|
+
* !.claude/rungate.json
|
|
44
|
+
* ```
|
|
45
|
+
* ```
|
|
46
|
+
* $ git check-ignore --no-index -q .claude/rungate.json ; echo $?
|
|
47
|
+
* 0
|
|
48
|
+
* $ git add .claude/rungate.json
|
|
49
|
+
* The following paths are ignored by one of your .gitignore files:
|
|
50
|
+
* .claude
|
|
51
|
+
* hint: Use -f if you really want to add them.
|
|
52
|
+
* ```
|
|
53
|
+
*
|
|
54
|
+
* `gitignore(5)`: *"It is not possible to re-include a file if a parent
|
|
55
|
+
* directory of that file is excluded."* git does not descend into an
|
|
56
|
+
* excluded directory, so nothing inside one can be negated. A consumer
|
|
57
|
+
* following that recommendation gets a refusal from `git add` and concludes
|
|
58
|
+
* the harness is wrong.
|
|
59
|
+
*
|
|
60
|
+
* The form that works re-includes the directory and then re-excludes its
|
|
61
|
+
* contents, which keeps everything the issue wanted kept:
|
|
62
|
+
*
|
|
63
|
+
* ```
|
|
64
|
+
* !.claude/
|
|
65
|
+
* .claude/*
|
|
66
|
+
* !.claude/rungate/
|
|
67
|
+
* !.claude/rungate.json
|
|
68
|
+
* ```
|
|
69
|
+
* ```
|
|
70
|
+
* trackable .claude/rungate.json
|
|
71
|
+
* trackable .claude/rungate/config.json
|
|
72
|
+
* IGNORED .claude/settings.local.json
|
|
73
|
+
* IGNORED .claude/worktrees/x
|
|
74
|
+
* ```
|
|
75
|
+
*
|
|
76
|
+
* ## It asks git rather than reading the file
|
|
77
|
+
*
|
|
78
|
+
* Ignore rules compose from `.gitignore` at every level, `.git/info/exclude`,
|
|
79
|
+
* `core.excludesFile` and the skip-worktree bits. A regex over one
|
|
80
|
+
* `.gitignore` is a detector narrower than what it detects
|
|
81
|
+
* (`.claude/rules/checks-must-be-able-to-fail.md`, second shape), and it
|
|
82
|
+
* would be wrong in the direction that matters: reporting "not ignored" for
|
|
83
|
+
* a config a global excludes file is deleting.
|
|
84
|
+
*
|
|
85
|
+
* `--no-index` is load-bearing for the opposite reason it is in
|
|
86
|
+
* `lib/tracked-vs-ignored.ts`. Without it, `check-ignore` SKIPS paths that
|
|
87
|
+
* are in the index — so on the reported consumer, where the file was
|
|
88
|
+
* force-added on one branch, it would have answered "not ignored" about the
|
|
89
|
+
* exact file that was about to be deleted. The question here is what the
|
|
90
|
+
* RULES say, not what the index currently holds.
|
|
91
|
+
*
|
|
92
|
+
* ## It verifies its own edit, and reverts if it did not work
|
|
93
|
+
*
|
|
94
|
+
* Appending patterns and reporting success is a check that cannot fail: the
|
|
95
|
+
* ignore rule might not be `.claude/`-shaped at all — a `*.json` at the root
|
|
96
|
+
* or a `core.excludesFile` entry needs a different negation, and this block
|
|
97
|
+
* would not help. So the paths are re-measured afterwards, and if they are
|
|
98
|
+
* still ignored the file is restored byte-for-byte and the action says so
|
|
99
|
+
* rather than claiming an `UPDATED:`.
|
|
100
|
+
*
|
|
101
|
+
* The second re-measure is the one that is easy to forget. `.claude/*` is a
|
|
102
|
+
* no-op when `.claude/` was already excluded, and NOT a no-op if the config
|
|
103
|
+
* was ignored by some broader rule — it would newly ignore every other
|
|
104
|
+
* direct child, and any of those that are tracked become the
|
|
105
|
+
* tracked-and-ignored contradiction `lib/tracked-vs-ignored.ts` exists to
|
|
106
|
+
* report. So the set of tracked paths this project's rules match is
|
|
107
|
+
* measured before and after, and a single new entry reverts the write.
|
|
108
|
+
*/
|
|
109
|
+
import { spawnSync } from "child_process";
|
|
110
|
+
import { existsSync, readFileSync, unlinkSync, writeFileSync } from "fs";
|
|
111
|
+
import { join } from "path";
|
|
112
|
+
import {
|
|
113
|
+
DIRECTORY_CONFIG_FILES,
|
|
114
|
+
RUNGATE_CONFIG_DIR,
|
|
115
|
+
RUNGATE_CONFIG_IGNORE_PATHS,
|
|
116
|
+
RUNGATE_CONFIG_PARENT_DIR,
|
|
117
|
+
} from "./config-loader";
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* A file the directory layout is MADE of, which the block names on purpose.
|
|
121
|
+
*
|
|
122
|
+
* Derived from `DIRECTORY_CONFIG_FILES` so it cannot disagree with the block
|
|
123
|
+
* that emits the negations — a second list here would let the guard refuse
|
|
124
|
+
* the very write it is checking, or wave through one it should not.
|
|
125
|
+
*/
|
|
126
|
+
function isConfigFragment(rel: string): boolean {
|
|
127
|
+
return DIRECTORY_CONFIG_FILES.some(f => rel === `${RUNGATE_CONFIG_DIR}/${f}`);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** What this project's ignore rules say about the config's home. */
|
|
131
|
+
export interface TrackableReading {
|
|
132
|
+
/** Config paths the rules match. EMPTY is the state this module wants. */
|
|
133
|
+
ignored: string[];
|
|
134
|
+
/**
|
|
135
|
+
* Non-null when the question could not be answered — not in a repository,
|
|
136
|
+
* git missing, a git error. Never conflated with "none matched": that
|
|
137
|
+
* conflation would turn a broken `git` into the cheapest way to report
|
|
138
|
+
* that a consumer's config is safe.
|
|
139
|
+
*/
|
|
140
|
+
failure: string | null;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function git(root: string, args: string[], input?: string) {
|
|
144
|
+
const r = spawnSync("git", args, {
|
|
145
|
+
cwd: root,
|
|
146
|
+
input,
|
|
147
|
+
encoding: "utf-8",
|
|
148
|
+
timeout: 120_000,
|
|
149
|
+
maxBuffer: 16 * 1024 * 1024,
|
|
150
|
+
});
|
|
151
|
+
if (r.error) return { status: -1, stdout: "", stderr: r.error.message };
|
|
152
|
+
return { status: r.status ?? -1, stdout: r.stdout ?? "", stderr: r.stderr ?? "" };
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Which of `paths` this project's ignore rules match.
|
|
157
|
+
*
|
|
158
|
+
* Exit 0 means at least one matched, 1 means none did — which is a RESULT
|
|
159
|
+
* and not an error — and anything else is a `failure` the caller must
|
|
160
|
+
* surface. A `catch { return [] }` here reads a git error as a clean bill of
|
|
161
|
+
* health, which is the first shape in
|
|
162
|
+
* `.claude/rules/checks-must-be-able-to-fail.md`.
|
|
163
|
+
*/
|
|
164
|
+
function matchedByIgnoreRules(root: string, paths: readonly string[]): TrackableReading {
|
|
165
|
+
if (paths.length === 0) return { ignored: [], failure: null };
|
|
166
|
+
const r = git(root, ["check-ignore", "--no-index", "--stdin", "-z"], paths.join("\0") + "\0");
|
|
167
|
+
if (r.status !== 0 && r.status !== 1) {
|
|
168
|
+
return {
|
|
169
|
+
ignored: [],
|
|
170
|
+
failure: `git check-ignore failed (${r.status}): ${r.stderr.trim() || "no output"}`,
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
const matched = new Set(r.stdout.split("\0").filter(p => p !== ""));
|
|
174
|
+
return { ignored: paths.filter(p => matched.has(p)), failure: null };
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Whether this project's ignore rules mark the rungate config disposable.
|
|
179
|
+
*
|
|
180
|
+
* A project that is not a git repository has no ignore rules and nothing can
|
|
181
|
+
* delete the file on a checkout, so that is `{ ignored: [], failure: null }`
|
|
182
|
+
* and not an error — the harness scaffolds into trees that are not repos.
|
|
183
|
+
*/
|
|
184
|
+
export function configPathsIgnored(root: string): TrackableReading {
|
|
185
|
+
const inside = git(root, ["rev-parse", "--is-inside-work-tree"]);
|
|
186
|
+
if (inside.status !== 0 || inside.stdout.trim() !== "true") {
|
|
187
|
+
return { ignored: [], failure: null };
|
|
188
|
+
}
|
|
189
|
+
return matchedByIgnoreRules(root, RUNGATE_CONFIG_IGNORE_PATHS);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Every ignored, untracked path that EXISTS in the tree, sorted.
|
|
194
|
+
*
|
|
195
|
+
* The other half of the symmetry below. `trackedAndIgnoredPaths` answers
|
|
196
|
+
* "did the edit newly ignore something"; this answers "did it newly
|
|
197
|
+
* UN-ignore something", and that is the direction a glob gets wrong. The
|
|
198
|
+
* first cut of the block emitted `!.claude/rungate/` with nothing after it,
|
|
199
|
+
* which un-ignores that directory RECURSIVELY — every file in it, including
|
|
200
|
+
* ones added next month, defaulting to tracked in every consumer the
|
|
201
|
+
* scaffold reaches. Nothing in the tree could see that, because the two
|
|
202
|
+
* config files it was asked about came back trackable either way.
|
|
203
|
+
*
|
|
204
|
+
* A test asserting only the config files are trackable passes on the broken
|
|
205
|
+
* block. A measurement over the whole ignored set does not, and keeps
|
|
206
|
+
* holding for globs nobody has written yet.
|
|
207
|
+
*
|
|
208
|
+
* `--exclude-standard` is required for `-i`, and its absence is a git error
|
|
209
|
+
* rather than a narrower answer, so it is caught by the status check.
|
|
210
|
+
*/
|
|
211
|
+
function ignoredPaths(root: string): TrackableReading {
|
|
212
|
+
const r = git(root, ["ls-files", "-z", "-o", "-i", "--exclude-standard"]);
|
|
213
|
+
if (r.status !== 0) {
|
|
214
|
+
return { ignored: [], failure: `git ls-files -i failed (${r.status}): ${r.stderr.trim()}` };
|
|
215
|
+
}
|
|
216
|
+
return { ignored: r.stdout.split("\0").filter(p => p !== "").sort(), failure: null };
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/** Tracked paths this project's ignore rules also match, as a sorted list. */
|
|
220
|
+
function trackedAndIgnoredPaths(root: string): TrackableReading {
|
|
221
|
+
const listed = git(root, ["ls-files", "-z"]);
|
|
222
|
+
if (listed.status !== 0) {
|
|
223
|
+
return { ignored: [], failure: `git ls-files failed (${listed.status}): ${listed.stderr.trim()}` };
|
|
224
|
+
}
|
|
225
|
+
const tracked = listed.stdout.split("\0").filter(p => p !== "");
|
|
226
|
+
const reading = matchedByIgnoreRules(root, tracked);
|
|
227
|
+
return { ignored: [...reading.ignored].sort(), failure: reading.failure };
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* The block appended to a `.gitignore` that marks the config disposable.
|
|
232
|
+
*
|
|
233
|
+
* Every line is written here exactly as it must appear on disk and nothing
|
|
234
|
+
* downstream transforms it — the same rule `GITIGNORE_SECTIONS` carries, for
|
|
235
|
+
* the same reason (#474): a trailing slash appended by a helper is the
|
|
236
|
+
* difference between a pattern that matches and one that does nothing.
|
|
237
|
+
*
|
|
238
|
+
* The order is the whole mechanism and each line is load-bearing:
|
|
239
|
+
*
|
|
240
|
+
* 1. `!.claude/` — un-exclude the DIRECTORY, so git descends into it. A
|
|
241
|
+
* negation for anything inside is inert until this line exists.
|
|
242
|
+
* 2. `.claude/*` — re-exclude its contents, so `settings.local.json`,
|
|
243
|
+
* `worktrees/` and everything else stay ignored exactly as before.
|
|
244
|
+
* 3./4. the two config locations, re-included by name.
|
|
245
|
+
*/
|
|
246
|
+
export function configTrackabilityBlock(): string {
|
|
247
|
+
const parent = RUNGATE_CONFIG_PARENT_DIR;
|
|
248
|
+
return [
|
|
249
|
+
"",
|
|
250
|
+
`# Added by rungate scaffold: the harness config must survive a branch`,
|
|
251
|
+
`# switch (#505). A bare \`!${RUNGATE_CONFIG_IGNORE_PATHS[1]}\` is INERT while`,
|
|
252
|
+
`# \`${parent}/\` is excluded — git does not descend into an excluded`,
|
|
253
|
+
`# directory — so each level is re-included and then re-excluded, and only`,
|
|
254
|
+
`# the config files are named. Everything else in \`${parent}/\` and in`,
|
|
255
|
+
`# \`${RUNGATE_CONFIG_DIR}/\` stays ignored, now and when it is added later.`,
|
|
256
|
+
`#`,
|
|
257
|
+
`# NOT re-included, deliberately: a config file at an unexpected depth`,
|
|
258
|
+
`# (\`${RUNGATE_CONFIG_DIR}/nested/config.json\`) and any file this list does`,
|
|
259
|
+
`# not name. Ignored is the safe side of the default for a path nobody has`,
|
|
260
|
+
`# thought of yet; a new config file is a change to this list.`,
|
|
261
|
+
`!${parent}/`,
|
|
262
|
+
`${parent}/*`,
|
|
263
|
+
`!${RUNGATE_CONFIG_DIR}/`,
|
|
264
|
+
`${RUNGATE_CONFIG_DIR}/*`,
|
|
265
|
+
...DIRECTORY_CONFIG_FILES.map(f => `!${RUNGATE_CONFIG_DIR}/${f}`),
|
|
266
|
+
`!${RUNGATE_CONFIG_IGNORE_PATHS[1]}`,
|
|
267
|
+
"",
|
|
268
|
+
].join("\n");
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Make the rungate config committable, or say plainly that it could not be.
|
|
273
|
+
*
|
|
274
|
+
* Returns the `actions` strings it pushed, so a caller can assert on the
|
|
275
|
+
* outcome without re-deriving it.
|
|
276
|
+
*/
|
|
277
|
+
/**
|
|
278
|
+
* `block` is a REACHABILITY WITNESS seam and nothing else.
|
|
279
|
+
*
|
|
280
|
+
* The un-ignore guard below cannot fire against the block this module
|
|
281
|
+
* emits — that is the point of the block — so with one argument the guard
|
|
282
|
+
* is unfalsifiable: deleting it was **0 red of 17**, measured, which makes
|
|
283
|
+
* it a line in a report rather than a check
|
|
284
|
+
* (`.claude/rules/checks-must-be-able-to-fail.md`). The guard's value is
|
|
285
|
+
* prospective, for the next edit to the block, and a guard whose removal
|
|
286
|
+
* nothing notices does not survive to be there for it.
|
|
287
|
+
*
|
|
288
|
+
* So one caller may hand in a block that IS too wide, and the only caller
|
|
289
|
+
* that does is the test that proves the refusal happens. Production passes
|
|
290
|
+
* one argument.
|
|
291
|
+
*/
|
|
292
|
+
export function ensureConfigTrackable(
|
|
293
|
+
root: string,
|
|
294
|
+
actions: string[],
|
|
295
|
+
block: string = configTrackabilityBlock(),
|
|
296
|
+
): void {
|
|
297
|
+
const before = configPathsIgnored(root);
|
|
298
|
+
if (before.failure !== null) {
|
|
299
|
+
actions.push(`UNMEASURED: .gitignore (could not ask git about the config path — ${before.failure})`);
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
if (before.ignored.length === 0) {
|
|
303
|
+
actions.push("SKIP: .gitignore (the rungate config is already committable)");
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
const gitignorePath = join(root, ".gitignore");
|
|
308
|
+
const had = existsSync(gitignorePath);
|
|
309
|
+
const original = had ? readFileSync(gitignorePath, "utf-8") : "";
|
|
310
|
+
const trackedBefore = trackedAndIgnoredPaths(root);
|
|
311
|
+
if (trackedBefore.failure !== null) {
|
|
312
|
+
actions.push(`UNMEASURED: .gitignore (could not list tracked files — ${trackedBefore.failure})`);
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
const ignoredBefore = ignoredPaths(root);
|
|
316
|
+
if (ignoredBefore.failure !== null) {
|
|
317
|
+
actions.push(`UNMEASURED: .gitignore (could not list ignored files — ${ignoredBefore.failure})`);
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
writeFileSync(gitignorePath, original.trimEnd() + "\n" + block);
|
|
322
|
+
|
|
323
|
+
// Byte-for-byte, and the file is REMOVED rather than blanked when there
|
|
324
|
+
// was none: a project that acquires an empty `.gitignore` from a step that
|
|
325
|
+
// reported a refusal has been changed by a step that said it changed
|
|
326
|
+
// nothing.
|
|
327
|
+
const revert = (why: string) => {
|
|
328
|
+
if (had) writeFileSync(gitignorePath, original);
|
|
329
|
+
else unlinkSync(gitignorePath);
|
|
330
|
+
actions.push(`REFUSED: .gitignore (${why})`);
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
const after = configPathsIgnored(root);
|
|
334
|
+
if (after.failure !== null) {
|
|
335
|
+
revert(`could not verify the edit worked — ${after.failure}`);
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
if (after.ignored.length > 0) {
|
|
339
|
+
// The rule is not `.claude/`-shaped, so this block cannot reach it.
|
|
340
|
+
// Name the rule rather than the guess: `check-ignore -v` reports the
|
|
341
|
+
// source file, line and pattern, which is what a consumer needs.
|
|
342
|
+
const why = git(root, ["check-ignore", "--no-index", "-v", ...after.ignored]);
|
|
343
|
+
revert(
|
|
344
|
+
`the rungate config is still ignored after the negation — ${after.ignored.join(", ")}` +
|
|
345
|
+
(why.stdout.trim() ? ` (matched by ${why.stdout.trim().split("\n").join("; ")})` : "") +
|
|
346
|
+
`. Un-ignore it by hand; a config git treats as disposable is deleted by an ordinary branch switch`,
|
|
347
|
+
);
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
const trackedAfter = trackedAndIgnoredPaths(root);
|
|
352
|
+
if (trackedAfter.failure !== null) {
|
|
353
|
+
revert(`could not verify the edit ignored nothing new — ${trackedAfter.failure}`);
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
const newlyIgnored = trackedAfter.ignored.filter(p => !trackedBefore.ignored.includes(p));
|
|
357
|
+
if (newlyIgnored.length > 0) {
|
|
358
|
+
revert(
|
|
359
|
+
`the negation would newly ignore ${newlyIgnored.length} tracked file(s) — ` +
|
|
360
|
+
`${newlyIgnored.slice(0, 3).join(", ")}${newlyIgnored.length > 3 ? ", …" : ""}`,
|
|
361
|
+
);
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
// The symmetric half, and the one that generalises. Exactly the config
|
|
366
|
+
// paths may leave the ignored set; a glob that reaches one path further
|
|
367
|
+
// than intended shows up here as a file that stopped being ignored, and
|
|
368
|
+
// that is a REFUSAL rather than a surprise in three consumers' trees.
|
|
369
|
+
const ignoredAfter = ignoredPaths(root);
|
|
370
|
+
if (ignoredAfter.failure !== null) {
|
|
371
|
+
revert(`could not verify the edit un-ignored nothing else — ${ignoredAfter.failure}`);
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
374
|
+
const stillIgnored = new Set(ignoredAfter.ignored);
|
|
375
|
+
const unIgnored = ignoredBefore.ignored.filter(
|
|
376
|
+
p => !stillIgnored.has(p) && !(RUNGATE_CONFIG_IGNORE_PATHS as readonly string[]).includes(p)
|
|
377
|
+
&& !isConfigFragment(p),
|
|
378
|
+
);
|
|
379
|
+
if (unIgnored.length > 0) {
|
|
380
|
+
revert(
|
|
381
|
+
`the negation reaches further than the config — ${unIgnored.length} other file(s) stopped ` +
|
|
382
|
+
`being ignored: ${unIgnored.slice(0, 3).join(", ")}${unIgnored.length > 3 ? ", …" : ""}`,
|
|
383
|
+
);
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
actions.push(
|
|
388
|
+
`UPDATED: .gitignore (the rungate config was ignored — ${before.ignored.join(", ")} — ` +
|
|
389
|
+
`and is now committable; commit it, or the next branch switch deletes it)`,
|
|
390
|
+
);
|
|
391
|
+
}
|