rungate 0.6.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 +81 -16
- package/lib/behavioral-cache.ts +150 -2
- 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 +93 -14
- package/lib/check-remedy.ts +140 -0
- package/lib/ci-checkout.ts +17 -0
- 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 +191 -17
- package/lib/config-loader.ts +39 -1
- package/lib/config-trackable.ts +391 -0
- package/lib/conformity.ts +1087 -100
- package/lib/containment.ts +238 -0
- package/lib/content-hash.ts +24 -0
- package/lib/create-sc.ts +249 -16
- 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/evidence-prevalidator.ts +224 -2
- package/lib/evidence-satisfiability.ts +534 -12
- package/lib/failure-intake.ts +317 -0
- package/lib/fallow-availability.ts +157 -0
- package/lib/fs-write-capabilities.ts +232 -0
- package/lib/gate-run-split.ts +147 -0
- package/lib/generators/agents-md.ts +140 -32
- 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 +52 -0
- package/lib/launch-base.ts +253 -0
- package/lib/line-citation.ts +372 -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/published-artifact.ts +525 -0
- package/lib/readdir-sorted.ts +45 -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-id-cross-tree.ts +19 -7
- 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 +4661 -64
- package/lib/scaffold/managed-workflow.ts +587 -192
- package/lib/scaffold/owned-files.ts +152 -45
- package/lib/scaffold/pre-push-hook.ts +49 -5
- package/lib/scaffold/steps.ts +1413 -244
- package/lib/scaffold/workflow-census.ts +217 -0
- package/lib/scaffold/workflow-drift.ts +217 -0
- package/lib/scaffold/write-steps.ts +4 -0
- package/lib/scan-budget.ts +247 -0
- package/lib/scanner.ts +43 -51
- 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/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 +241 -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-suite-lock.ts +159 -16
- package/lib/tool-probe.ts +31 -9
- package/lib/top-level-cd.ts +393 -0
- package/lib/tree-entries.ts +89 -0
- package/lib/ts-ast.ts +200 -0
- 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/create-sc.ts +21 -1
- package/scripts/extract-constraints.ts +107 -7
- package/scripts/generate-code-map.ts +23 -30
- package/scripts/scaffold-project.ts +8 -1
- package/scripts/sync-sc-status.ts +77 -16
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Promotion and eviction for extracted constraint candidates (#544).
|
|
3
|
+
*
|
|
4
|
+
* ## The one criterion enforced here
|
|
5
|
+
*
|
|
6
|
+
* **A candidate that cannot be traced to a dated observation is not
|
|
7
|
+
* promoted.** Evidence is a GATE, not a tiebreak.
|
|
8
|
+
*
|
|
9
|
+
* `specs/RULE-LIFECYCLE-AND-CONTEXT-BUDGET-SPEC.md` SC-1939 states the weaker
|
|
10
|
+
* form — *a candidate with no evidence never outranks one that has it* — and
|
|
11
|
+
* this satisfies it a fortiori: an evidence-less candidate never appears in
|
|
12
|
+
* `promoted` at all, at any budget, so there is no ordering in which it can
|
|
13
|
+
* outrank anything.
|
|
14
|
+
*
|
|
15
|
+
* The stronger form is the one the evidence supports. Every rule in this
|
|
16
|
+
* repository's `.claude/rules/` that an agent demonstrably acts on narrates a
|
|
17
|
+
* dated incident — the #70 collision, run `wf_0b15a933-b2b`, the five bugs of
|
|
18
|
+
* 2026-10-06. `agent-principles.md` ships *"verify before asserting"* to every
|
|
19
|
+
* consumer, costs budget in every session, and the learning loop still carries
|
|
20
|
+
* four separate low-rating patterns for failing to do exactly that. A general
|
|
21
|
+
* principle with nothing behind it is not a weak rule; it is a rule that has
|
|
22
|
+
* been measured not to work.
|
|
23
|
+
*
|
|
24
|
+
* ## Eviction is here, not in a follow-up
|
|
25
|
+
*
|
|
26
|
+
* `docs/research/context-management.md` records the measured collapse: rule
|
|
27
|
+
* sets lose effectiveness past roughly sixteen rules, and the threshold is
|
|
28
|
+
* about the TOTAL in context. So a lifecycle that only adds degrades the thing
|
|
29
|
+
* it feeds, and a promoter that cannot evict is a cap with no teeth. The
|
|
30
|
+
* budget cut and the promotion decision are therefore one reading, returned
|
|
31
|
+
* together, with every withheld candidate carrying the reason it lost.
|
|
32
|
+
*
|
|
33
|
+
* ## WHAT THIS DOES NOT COVER
|
|
34
|
+
*
|
|
35
|
+
* Each escape is asserted as a case in `test/failure-intake-promotion.test.ts`.
|
|
36
|
+
*
|
|
37
|
+
* - **The budget is a COUNT of promoted rules, not max-concurrent-load.**
|
|
38
|
+
* The spec's budget criterion asks for max-concurrent-load — for every
|
|
39
|
+
* file in the repository, count the rules whose globs match it, and take
|
|
40
|
+
* the maximum — and nothing here computes it, because nothing here emits
|
|
41
|
+
* `paths:` globs yet. A count is strictly more pessimistic than concurrent
|
|
42
|
+
* load, so this cannot under-report; it can refuse a set that would have
|
|
43
|
+
* been fine.
|
|
44
|
+
* - **Nothing reads whether the cited evidence still resolves.** The spec's
|
|
45
|
+
* auto-retirement criterion is not implemented: a candidate citing a commit
|
|
46
|
+
* that has been rebased away still ranks on its date.
|
|
47
|
+
* - **Recency is the only ranking signal among evidence-backed candidates.**
|
|
48
|
+
* The spec names four more — whether the governed code changed recently,
|
|
49
|
+
* the violation count in graded runs, whether the text states a prohibition,
|
|
50
|
+
* and whether the cited `file:line` resolves. A commit-subject candidate has
|
|
51
|
+
* no `file:line`, and the other three need producers that do not exist yet.
|
|
52
|
+
* So "the mechanical evidence score" is currently one term, and saying so is
|
|
53
|
+
* the difference between a scorer and a sort.
|
|
54
|
+
* - **A rejected hash is permanent and global.** The veto table has no
|
|
55
|
+
* per-source scoping, so vetoing a sentence mined from a commit also vetoes
|
|
56
|
+
* the identical sentence if it later appears in a doc. That is the intended
|
|
57
|
+
* reading of the permanent-veto criterion and is recorded here because it
|
|
58
|
+
* is a decision, not an accident.
|
|
59
|
+
*/
|
|
60
|
+
import type { CandidateEvidence } from "./failure-intake";
|
|
61
|
+
|
|
62
|
+
export interface PromotableCandidate {
|
|
63
|
+
rule: string;
|
|
64
|
+
source: string;
|
|
65
|
+
hash: string;
|
|
66
|
+
/** Absent for a doc-prose candidate. Its absence is the gate below. */
|
|
67
|
+
evidence?: CandidateEvidence;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export type WithheldReason =
|
|
71
|
+
/** Vetoed previously, per the table at `reference/rejected-constraints.md`. */
|
|
72
|
+
| "REJECTED"
|
|
73
|
+
/** No dated observation behind it. The criterion this module exists for. */
|
|
74
|
+
| "NO_EVIDENCE"
|
|
75
|
+
/** Evidence-backed, and ranked below the cut. The eviction. */
|
|
76
|
+
| "OVER_BUDGET";
|
|
77
|
+
|
|
78
|
+
export interface WithheldCandidate {
|
|
79
|
+
candidate: PromotableCandidate;
|
|
80
|
+
reason: WithheldReason;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* The number of mined rules allowed to be active at once.
|
|
85
|
+
*
|
|
86
|
+
* Sixteen, from `docs/research/context-management.md`: effectiveness collapses
|
|
87
|
+
* past roughly that many rules, and the threshold is over the total in
|
|
88
|
+
* context. ONE declaring position — a second literal somewhere else would be a
|
|
89
|
+
* second decider for a question this module answers.
|
|
90
|
+
*
|
|
91
|
+
* Superseded by the spec's max-concurrent-load budget once mined rules carry
|
|
92
|
+
* `paths:`. Until then this is the pessimistic stand-in, and the comment is
|
|
93
|
+
* here so the number is not mistaken for the budget the spec specifies.
|
|
94
|
+
*/
|
|
95
|
+
export const PROMOTION_BUDGET_RULES = 16;
|
|
96
|
+
|
|
97
|
+
export const NON_POSITIVE_BUDGET = "NON_POSITIVE_BUDGET";
|
|
98
|
+
/** An upstream read UNMEASURED without naming a reason. */
|
|
99
|
+
export const UPSTREAM_UNMEASURED = "UPSTREAM_UNMEASURED";
|
|
100
|
+
|
|
101
|
+
export interface PromotionReading {
|
|
102
|
+
/**
|
|
103
|
+
* The single discriminator. `unmeasuredReasons` is the other projection of
|
|
104
|
+
* the same computation, so the two cannot disagree.
|
|
105
|
+
*/
|
|
106
|
+
reading: "MEASURED" | "UNMEASURED";
|
|
107
|
+
unmeasuredReasons: string[];
|
|
108
|
+
budget: number;
|
|
109
|
+
promoted: PromotableCandidate[];
|
|
110
|
+
withheld: WithheldCandidate[];
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* THE ordering over evidence-backed candidates. One binding.
|
|
115
|
+
*
|
|
116
|
+
* It deliberately does NOT re-decide whether a candidate has evidence. The
|
|
117
|
+
* gate in `promoteCandidates` answers that, nothing evidence-less reaches this
|
|
118
|
+
* comparator, and a second evidence clause here would be unreachable code
|
|
119
|
+
* agreeing with a decision already taken — which is the fourth shape in
|
|
120
|
+
* `.claude/rules/checks-must-be-able-to-fail.md` built in on purpose.
|
|
121
|
+
*
|
|
122
|
+
* Dates are parsed, never compared as strings. `git log --format=%cI` emits
|
|
123
|
+
* whatever offset the committer's machine had: `main` carries
|
|
124
|
+
* `2026-10-21T19:18:27Z` and `2026-10-21T15:01:51-04:00` on adjacent commits,
|
|
125
|
+
* and those two sort in the wrong order lexicographically while naming almost
|
|
126
|
+
* the same instant.
|
|
127
|
+
*/
|
|
128
|
+
export function rankForPromotion(a: PromotableCandidate, b: PromotableCandidate): number {
|
|
129
|
+
const ta = epoch(a);
|
|
130
|
+
const tb = epoch(b);
|
|
131
|
+
if (ta !== tb) return tb - ta;
|
|
132
|
+
// Stable and content-derived, so two runs over one history agree byte for
|
|
133
|
+
// byte. Falling back to input order would make the output depend on the
|
|
134
|
+
// walk, which is the idempotency SC-1946 asks for, lost for free.
|
|
135
|
+
return a.hash < b.hash ? -1 : a.hash > b.hash ? 1 : 0;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function epoch(c: PromotableCandidate): number {
|
|
139
|
+
const parsed = c.evidence ? Date.parse(c.evidence.date) : NaN;
|
|
140
|
+
return Number.isNaN(parsed) ? 0 : parsed;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Decide what gets promoted, and say why everything else did not.
|
|
145
|
+
*
|
|
146
|
+
* Three questions, in order, each with one binding: has this been vetoed, does
|
|
147
|
+
* it carry evidence, and does it fit. They are not three readings of one fact
|
|
148
|
+
* — a vetoed candidate and an evidence-less one lose for different reasons and
|
|
149
|
+
* a reader can act on only one of them.
|
|
150
|
+
*
|
|
151
|
+
* `upstream` folds in the readings taken before this one — the intake's, and
|
|
152
|
+
* since #544 the retirement pass's. A promotion computed over a shallow
|
|
153
|
+
* clone's candidates is not a smaller promotion, it is a promotion over an
|
|
154
|
+
* unknown population, and `0 promoted` from a truncated history reads exactly
|
|
155
|
+
* like `0 promoted` from a repository with nothing to promote.
|
|
156
|
+
*
|
|
157
|
+
* It takes a LIST because there are now two of them, and folding two readings
|
|
158
|
+
* into one at the call site would put a third decider between the producers
|
|
159
|
+
* and this function — one that could report MEASURED while either upstream
|
|
160
|
+
* said otherwise. A single reading is still accepted; it is the one-element
|
|
161
|
+
* case.
|
|
162
|
+
*/
|
|
163
|
+
export type UpstreamReading = { reading: "MEASURED" | "UNMEASURED"; unmeasuredReasons: string[] };
|
|
164
|
+
|
|
165
|
+
export function promoteCandidates(
|
|
166
|
+
candidates: PromotableCandidate[],
|
|
167
|
+
options: {
|
|
168
|
+
budget: number;
|
|
169
|
+
rejectedHashes?: ReadonlySet<string>;
|
|
170
|
+
upstream?: UpstreamReading | readonly UpstreamReading[];
|
|
171
|
+
},
|
|
172
|
+
): PromotionReading {
|
|
173
|
+
const { budget } = options;
|
|
174
|
+
const rejected = options.rejectedHashes ?? new Set<string>();
|
|
175
|
+
const upstreams: readonly UpstreamReading[] = options.upstream
|
|
176
|
+
? Array.isArray(options.upstream)
|
|
177
|
+
? options.upstream
|
|
178
|
+
: [options.upstream as UpstreamReading]
|
|
179
|
+
: [];
|
|
180
|
+
const unmeasuredReasons = upstreams.flatMap(u => u.unmeasuredReasons);
|
|
181
|
+
// The discriminator is authoritative, not the reason list. An upstream that
|
|
182
|
+
// read UNMEASURED and named no reason is still UNMEASURED, and folding only
|
|
183
|
+
// the reasons would have let it through as MEASURED — a producer and a
|
|
184
|
+
// consumer disagreeing about one fact, with the wrong one winning.
|
|
185
|
+
if (upstreams.some(u => u.reading === "UNMEASURED") && unmeasuredReasons.length === 0) {
|
|
186
|
+
unmeasuredReasons.push(UPSTREAM_UNMEASURED);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const withheld: WithheldCandidate[] = [];
|
|
190
|
+
const eligible: PromotableCandidate[] = [];
|
|
191
|
+
|
|
192
|
+
for (const candidate of candidates) {
|
|
193
|
+
if (rejected.has(candidate.hash)) {
|
|
194
|
+
withheld.push({ candidate, reason: "REJECTED" });
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
if (!candidate.evidence) {
|
|
198
|
+
withheld.push({ candidate, reason: "NO_EVIDENCE" });
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
201
|
+
eligible.push(candidate);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if (budget < 1) {
|
|
205
|
+
unmeasuredReasons.push(NON_POSITIVE_BUDGET);
|
|
206
|
+
for (const candidate of eligible) withheld.push({ candidate, reason: "OVER_BUDGET" });
|
|
207
|
+
return { reading: "UNMEASURED", unmeasuredReasons, budget, promoted: [], withheld };
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
const ranked = [...eligible].sort(rankForPromotion);
|
|
211
|
+
for (const candidate of ranked.slice(budget)) {
|
|
212
|
+
withheld.push({ candidate, reason: "OVER_BUDGET" });
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
return {
|
|
216
|
+
reading: unmeasuredReasons.length > 0 ? "UNMEASURED" : "MEASURED",
|
|
217
|
+
unmeasuredReasons,
|
|
218
|
+
budget,
|
|
219
|
+
promoted: ranked.slice(0, budget),
|
|
220
|
+
withheld,
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/** One line a caller can print without re-deriving any of the above. */
|
|
225
|
+
export function promotionSummary(reading: PromotionReading): string {
|
|
226
|
+
const counts = new Map<WithheldReason, number>();
|
|
227
|
+
for (const w of reading.withheld) counts.set(w.reason, (counts.get(w.reason) ?? 0) + 1);
|
|
228
|
+
const why = [...counts.entries()].map(([r, n]) => `${r}=${n}`).join(" ");
|
|
229
|
+
return (
|
|
230
|
+
`promotion ${reading.reading}: ${reading.promoted.length} promoted of budget ${reading.budget}` +
|
|
231
|
+
(why ? `, withheld ${why}` : "") +
|
|
232
|
+
(reading.unmeasuredReasons.length > 0 ? ` — ${reading.unmeasuredReasons.join("; ")}` : "")
|
|
233
|
+
);
|
|
234
|
+
}
|