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,258 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where `ProjectStateSync` is allowed to run a generator — and everywhere it
|
|
3
|
+
* is not (#1001).
|
|
4
|
+
*
|
|
5
|
+
* ## The defect this exists to close
|
|
6
|
+
*
|
|
7
|
+
* The hook took a `project-state.json` path out of a tool call, stripped the
|
|
8
|
+
* filename, and ran `scripts/update-project-state.ts` from whatever was left:
|
|
9
|
+
*
|
|
10
|
+
* const projectRoot = filePath.replace(/\/project-state\.json$/, "");
|
|
11
|
+
* const script = join(projectRoot, "scripts", "update-project-state.ts");
|
|
12
|
+
* if (!existsSync(script)) …decline…
|
|
13
|
+
* execFileSync("bun", [script, "--skip-tests"], { cwd: projectRoot });
|
|
14
|
+
*
|
|
15
|
+
* `projectRoot` is wherever the tool call pointed. Anything able to write two
|
|
16
|
+
* files — `<anywhere>/project-state.json` and
|
|
17
|
+
* `<anywhere>/scripts/update-project-state.ts` — got code execution as the
|
|
18
|
+
* user, on the next `Write` or `Edit`, in every session on this machine.
|
|
19
|
+
*
|
|
20
|
+
* **It is a permission-gate bypass, and that is the part that matters.**
|
|
21
|
+
* `Bash` is gated far more tightly than `Write`. The agent never runs a
|
|
22
|
+
* command; the hook runs it on the agent's behalf, with the agent's choice of
|
|
23
|
+
* directory. #971/#999 converted the spawn from a shell string to an argv,
|
|
24
|
+
* which closed metacharacter injection and left this untouched — the hook's
|
|
25
|
+
* own header says so: *"`existsSync(script)` above is a bar, not a wall — it
|
|
26
|
+
* only requires the payload to be a real directory, and /tmp is writable."*
|
|
27
|
+
*
|
|
28
|
+
* ## The cheapest wrong fix, named so it cannot be mistaken for this one
|
|
29
|
+
*
|
|
30
|
+
* *"Allow anything under `$HOME/Projects`."* It satisfies the symptom, it is
|
|
31
|
+
* a prefix test, and it is **a new list of trusted paths** — a fourth
|
|
32
|
+
* position declaring something this repo already decides elsewhere. It also
|
|
33
|
+
* does not work: a planted root inside the prefix passes it. `AC-4` is that
|
|
34
|
+
* input, and it is red against that fix.
|
|
35
|
+
*
|
|
36
|
+
* The cheapest wrong fix for the SECOND round is different and more
|
|
37
|
+
* tempting: *"also `realpath` the leaf."* It closes the symlinked-directory
|
|
38
|
+
* hole completely, reads like a security fix in a diff, and leaves the
|
|
39
|
+
* forged repository exactly as open as it was — a forgery's generator is a
|
|
40
|
+
* perfectly ordinary file. `AC-14` is the input it does not survive.
|
|
41
|
+
*
|
|
42
|
+
* ## What is checked instead, and why it delegates
|
|
43
|
+
*
|
|
44
|
+
* **The generator may only run at the root of a real git repository, and it
|
|
45
|
+
* must be a TRACKED file of that repository.** Neither is a list; both are
|
|
46
|
+
* questions something else already answers — `lib/paths.ts:repoRootFrom`
|
|
47
|
+
* resolves `--git-common-dir` and `realpathSync`es the result so callers can
|
|
48
|
+
* compare stable strings, and `git ls-files --error-unmatch` decides
|
|
49
|
+
* membership. No second definition of "trusted root" is declared here.
|
|
50
|
+
*
|
|
51
|
+
* ### Why the repo-root test alone was not enough
|
|
52
|
+
*
|
|
53
|
+
* The first version of this module shipped with only the root test, and its
|
|
54
|
+
* limits note claimed an attacker needed "to create a directory AND run
|
|
55
|
+
* `git init`". That is false, and measured false on this machine:
|
|
56
|
+
*
|
|
57
|
+
* mkdir -p $D/.git/objects $D/.git/refs/heads $D/scripts
|
|
58
|
+
* printf 'ref: refs/heads/main\n' > $D/.git/HEAD
|
|
59
|
+
* git -C $D rev-parse --show-toplevel → $D
|
|
60
|
+
* git -C $D rev-parse --git-common-dir → .git
|
|
61
|
+
*
|
|
62
|
+
* Three `mkdir`s and a 24-byte file, every one of them reachable with
|
|
63
|
+
* `Write` — the exact primitive this issue exists to contain. "Any writable
|
|
64
|
+
* directory" became "any writable directory plus three mkdirs", which is not
|
|
65
|
+
* a narrowing, and saying it was is worse than the gap: a reader checking
|
|
66
|
+
* the limits would have stopped there.
|
|
67
|
+
*
|
|
68
|
+
* The tracked test refuses it, because **the barrier is `.git/index`** — a
|
|
69
|
+
* binary file with a trailing checksum, not something a text write produces.
|
|
70
|
+
* It also asks the better question: *is this generator part of a project*
|
|
71
|
+
* rather than *is there a `.git` directory here*. `AC-14` is the forgery and
|
|
72
|
+
* `AC-15` is an untracked file dropped into a REAL repository, which is what
|
|
73
|
+
* an attacker gets from any checkout on the machine.
|
|
74
|
+
*
|
|
75
|
+
* ### Both sides must be resolved, and this machine is why
|
|
76
|
+
*
|
|
77
|
+
* The obvious spelling of the anchor is wrong:
|
|
78
|
+
*
|
|
79
|
+
* if (claimedRoot !== repoRootFrom(claimedRoot)) decline // WRONG
|
|
80
|
+
*
|
|
81
|
+
* `repoRootFrom` realpaths its answer and the claimed path has not been
|
|
82
|
+
* realpathed, so the two can never agree through a symlink. Measured:
|
|
83
|
+
* `/Users/jhorn/Projects/pai-harness` is a symlink to
|
|
84
|
+
* `/Users/jhorn/Projects/rungate`, and the live `project-state.json` is
|
|
85
|
+
* written through the former. That spelling **refuses the only real caller
|
|
86
|
+
* there is**, silently, as a security improvement. `AC-3` is that input.
|
|
87
|
+
*
|
|
88
|
+
* ### The whole path is resolved, not the leaf
|
|
89
|
+
*
|
|
90
|
+
* `lstat` on the last component sees a link AT the leaf and is blind to one
|
|
91
|
+
* above it: a `scripts` directory symlinked anywhere, with an ordinary file
|
|
92
|
+
* at the end of it, reports no link at all. `projectRoot` is already
|
|
93
|
+
* resolved, so comparing `realpathSync(script)` against the expected path
|
|
94
|
+
* catches a link at ANY depth. `AC-16` is that input, and it asserts the
|
|
95
|
+
* leaf-level `lstat` reads false on it so the arm cannot quietly become a
|
|
96
|
+
* duplicate of `AC-7`.
|
|
97
|
+
*
|
|
98
|
+
* ### A linked worktree is NOT the root of its repository
|
|
99
|
+
*
|
|
100
|
+
* `repoRootFrom` resolves `--git-common-dir`, so from a linked worktree it
|
|
101
|
+
* returns the MAIN checkout. A worktree therefore reads as `not-repo-root`
|
|
102
|
+
* and the generator does not run there. That is a behaviour change and it is
|
|
103
|
+
* deliberate: `PROJECT-STATE.md` is DA-owned and an agent in a worktree must
|
|
104
|
+
* never write it (#296), which #910's SC-3 raised as an open question while
|
|
105
|
+
* the hook was registered on `Write` **and** `Edit` and taking the other
|
|
106
|
+
* answer by default. The outcome is recorded distinctly so the decision is
|
|
107
|
+
* visible in the evidence rather than buried in a refusal count.
|
|
108
|
+
*
|
|
109
|
+
* ## WHAT THIS DOES NOT COVER
|
|
110
|
+
*
|
|
111
|
+
* - **A repository whose CONFIG is hostile.** `repoRootFrom` shells out to
|
|
112
|
+
* `git` in the candidate directory before the tracked-file test can run,
|
|
113
|
+
* and that call is not isolated. `rev-parse --git-common-dir` neither
|
|
114
|
+
* refreshes the index nor fires a hook, so `core.fsmonitor` and
|
|
115
|
+
* `core.hooksPath` do not execute on it — but that is a property of the
|
|
116
|
+
* subcommand, not a boundary. Isolating `repoRootFrom` itself is the right
|
|
117
|
+
* fix and is not done here: `test/harness-root.test.ts` stages
|
|
118
|
+
* `lib/paths.ts` into a scratch directory, so an import added to it fails
|
|
119
|
+
* to load there (`.claude/rules/self-referential-tests.md`, Tier 1).
|
|
120
|
+
* - **A real project someone else controls.** Tracked means part of a
|
|
121
|
+
* project, not part of YOUR project. An attacker who can commit to a
|
|
122
|
+
* repository on this machine can change what the generator does, which is
|
|
123
|
+
* the next item and not a smaller problem.
|
|
124
|
+
* - **A generator that is a regular file with hostile contents.** Confining
|
|
125
|
+
* WHERE is not reviewing WHAT.
|
|
126
|
+
* - **A race between the checks and the spawn.** Everything here resolves
|
|
127
|
+
* paths once; a component swapped for a symlink afterwards is not seen.
|
|
128
|
+
*
|
|
129
|
+
* Issue: #1001. Refs #971, #999, #910, #296.
|
|
130
|
+
*/
|
|
131
|
+
|
|
132
|
+
import { spawnSync } from "child_process";
|
|
133
|
+
import { realpathSync, statSync } from "fs";
|
|
134
|
+
import { isAbsolute, join } from "path";
|
|
135
|
+
import { repoRootFrom } from "./paths";
|
|
136
|
+
import { gitIsolatedArgs, gitIsolatedEnv } from "./git-isolation";
|
|
137
|
+
|
|
138
|
+
/** The generator this hook runs, relative to a project root. */
|
|
139
|
+
export const GENERATOR_RELPATH = join("scripts", "update-project-state.ts");
|
|
140
|
+
|
|
141
|
+
export type ProjectStateTarget =
|
|
142
|
+
| { ok: true; projectRoot: string; script: string }
|
|
143
|
+
/**
|
|
144
|
+
* `outcome` is the string the hook records. Every refusal has one: a
|
|
145
|
+
* decline and a hook that never ran are otherwise the same observation,
|
|
146
|
+
* which is #910.
|
|
147
|
+
*/
|
|
148
|
+
| { ok: false; outcome: string; detail: Record<string, unknown> };
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Resolve a `project-state.json` path to the generator that may run for it.
|
|
152
|
+
*
|
|
153
|
+
* Pure apart from the filesystem reads it is about, and separate from the
|
|
154
|
+
* hook so every refusal has an input that reaches it — a guard that only the
|
|
155
|
+
* hook can exercise is a guard whose ordering nothing can test.
|
|
156
|
+
*/
|
|
157
|
+
export function projectStateTarget(filePath: string): ProjectStateTarget {
|
|
158
|
+
const claimed = filePath.replace(/\/project-state\.json$/, "");
|
|
159
|
+
const detail: Record<string, unknown> = { filePath, claimedRoot: claimed };
|
|
160
|
+
|
|
161
|
+
// Resolve the CLAIMED side too. Without this the comparison below is a
|
|
162
|
+
// string match between a resolved and an unresolved path, which disagrees
|
|
163
|
+
// through any symlink — including the one the real caller arrives through.
|
|
164
|
+
let projectRoot: string;
|
|
165
|
+
try {
|
|
166
|
+
projectRoot = realpathSync(claimed);
|
|
167
|
+
} catch (e) {
|
|
168
|
+
return { ok: false, outcome: "declined-unresolvable-root", detail: { ...detail, error: (e as Error).message } };
|
|
169
|
+
}
|
|
170
|
+
detail.projectRoot = projectRoot;
|
|
171
|
+
|
|
172
|
+
const repoRoot = repoRootFrom(projectRoot);
|
|
173
|
+
if (repoRoot === null) {
|
|
174
|
+
// No repository at all: the planted-directory case this issue is about.
|
|
175
|
+
return { ok: false, outcome: "declined-outside-repo", detail };
|
|
176
|
+
}
|
|
177
|
+
if (repoRoot !== projectRoot) {
|
|
178
|
+
// A subdirectory, or a LINKED WORKTREE — `--git-common-dir` resolves to
|
|
179
|
+
// the main checkout from inside one. Recorded distinctly because of the
|
|
180
|
+
// #296 interaction; `repoRoot` in the detail tells the two apart.
|
|
181
|
+
return { ok: false, outcome: "declined-not-repo-root", detail: { ...detail, repoRoot } };
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const script = join(projectRoot, GENERATOR_RELPATH);
|
|
185
|
+
// INVARIANT, not a guard. `realpathSync` returns an absolute path and
|
|
186
|
+
// `join` keeps it absolute, so `script` can never be read as a flag by the
|
|
187
|
+
// spawned `bun`. Stated because the pre-fix code had no such guarantee —
|
|
188
|
+
// a `file_path` of `-rf/project-state.json` built the argv
|
|
189
|
+
// `-rf/scripts/update-project-state.ts`, which `bun` parses as options.
|
|
190
|
+
// Asserted rather than branched on: a condition no input can satisfy is
|
|
191
|
+
// not a check (`.claude/rules/checks-must-be-able-to-fail.md`), and
|
|
192
|
+
// pretending otherwise would hide which mechanism actually closes this.
|
|
193
|
+
if (!isAbsolute(script)) {
|
|
194
|
+
throw new Error(`projectStateTarget produced a relative generator path: ${script}`);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// Resolve the WHOLE path, not the leaf. `lstat` on the last component is
|
|
198
|
+
// blind to a symlinked INTERMEDIATE: `scripts` may be a link to anywhere
|
|
199
|
+
// with a perfectly ordinary file at the end of it, and `lstat` reports no
|
|
200
|
+
// link. `projectRoot` is already resolved, so any disagreement here is a
|
|
201
|
+
// link at some depth below it.
|
|
202
|
+
let realScript: string;
|
|
203
|
+
try {
|
|
204
|
+
realScript = realpathSync(script);
|
|
205
|
+
} catch {
|
|
206
|
+
return { ok: false, outcome: "declined-no-generator", detail: { ...detail, script } };
|
|
207
|
+
}
|
|
208
|
+
if (realScript !== script) {
|
|
209
|
+
return {
|
|
210
|
+
ok: false,
|
|
211
|
+
outcome: "declined-symlinked-generator",
|
|
212
|
+
detail: { ...detail, script, resolved: realScript },
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
if (!statSync(realScript).isFile()) {
|
|
216
|
+
return { ok: false, outcome: "declined-no-generator", detail: { ...detail, script } };
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
if (!trackedInRepo(projectRoot, GENERATOR_RELPATH)) {
|
|
220
|
+
// THE ANCHOR. A `.git` directory is three `mkdir`s and a 24-byte `HEAD`
|
|
221
|
+
// away from any `Write`; a TRACKED file is not.
|
|
222
|
+
//
|
|
223
|
+
// LAST, so that every check above it stays reachable. Tracking is the
|
|
224
|
+
// strongest test here, and putting it first would make the symlink
|
|
225
|
+
// branches unreachable — git does not descend a symlinked directory, so
|
|
226
|
+
// a link would be refused as untracked and the branch that exists to
|
|
227
|
+
// name it could never be taken (`.claude/rules/checks-must-be-able-to-fail.md`).
|
|
228
|
+
// Order changes which refusal is RECORDED, never whether one happens:
|
|
229
|
+
// nothing is spawned until all of them pass.
|
|
230
|
+
return { ok: false, outcome: "declined-untracked-generator", detail: { ...detail, script } };
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
return { ok: true, projectRoot, script };
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Is `relPath` a tracked file of the repository at `root`?
|
|
238
|
+
*
|
|
239
|
+
* `ls-files --error-unmatch` rather than a filesystem test, because the
|
|
240
|
+
* question is *is this part of a project* and only git can answer it. The
|
|
241
|
+
* barrier is the INDEX: `.git/index` is a binary file carrying a trailing
|
|
242
|
+
* checksum, so the three-`mkdir`s forgery that satisfies `rev-parse` has no
|
|
243
|
+
* index at all and this refuses it. Committed content raises the bar again,
|
|
244
|
+
* but the index alone is already past what writing text files can reach.
|
|
245
|
+
*
|
|
246
|
+
* ISOLATED, because this runs `git` in a directory the caller chose and git
|
|
247
|
+
* executes that repository's config — `lib/git-isolation.ts`. `--` so a
|
|
248
|
+
* relative path can never be read as a revision or a flag.
|
|
249
|
+
*/
|
|
250
|
+
function trackedInRepo(root: string, relPath: string): boolean {
|
|
251
|
+
const r = spawnSync("git", gitIsolatedArgs(["-C", root, "ls-files", "--error-unmatch", "--", relPath]), {
|
|
252
|
+
encoding: "utf-8",
|
|
253
|
+
timeout: 5000,
|
|
254
|
+
stdio: ["ignore", "ignore", "ignore"],
|
|
255
|
+
env: gitIsolatedEnv(),
|
|
256
|
+
});
|
|
257
|
+
return r.status === 0;
|
|
258
|
+
}
|
|
@@ -164,3 +164,62 @@ export function missingStateVerdict(opts: {
|
|
|
164
164
|
}
|
|
165
165
|
return { verdict: "SKIP", detail: "project-state.json not found and no PROJECT-STATE.md to maintain — nothing to do" };
|
|
166
166
|
}
|
|
167
|
+
|
|
168
|
+
/** One rendered session, and the entries the selection could not place. */
|
|
169
|
+
export interface SessionSelection<T> {
|
|
170
|
+
/** Newest first, at most `limit` of them. */
|
|
171
|
+
rendered: T[];
|
|
172
|
+
/**
|
|
173
|
+
* Entries whose `date` does not begin with an ISO date.
|
|
174
|
+
*
|
|
175
|
+
* They are NOT excluded — they rank below every dated entry, in array
|
|
176
|
+
* order, which is the only information left about them and is exactly
|
|
177
|
+
* what the old renderer used for everything. A project whose dates are
|
|
178
|
+
* all free-form therefore renders exactly as it did before.
|
|
179
|
+
*
|
|
180
|
+
* They are reported by name, because an entry nobody can order is a
|
|
181
|
+
* thing worth saying out loud: it will be outranked by any dated entry,
|
|
182
|
+
* however old, and that is surprising if you cannot see it.
|
|
183
|
+
*/
|
|
184
|
+
undated: T[];
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const ISO_DATE = /^(\d{4})-(\d{2})-(\d{2})\b/;
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* The `limit` NEWEST sessions, chosen by date (#572).
|
|
191
|
+
*
|
|
192
|
+
* The renderer used to take `[...sessions].reverse().slice(0, 3)` — "the
|
|
193
|
+
* last three entries of the array", which is correct exactly while the
|
|
194
|
+
* array is in append order and which nothing anywhere enforced. Session 48
|
|
195
|
+
* was written to `sessions[0]`, so eight merged issues never appeared in
|
|
196
|
+
* PROJECT-STATE.md, the file AGENTS.md tells the next session to read
|
|
197
|
+
* first. The script printed `✅ rewrote` every time, because it had in fact
|
|
198
|
+
* rewritten the file.
|
|
199
|
+
*
|
|
200
|
+
* This is the second instance of that bug in the same function. The first
|
|
201
|
+
* was `slice(0, 3)` rendering the three OLDEST entries, and the fix was
|
|
202
|
+
* `.reverse()` — which repaired the symptom and left the defect: the
|
|
203
|
+
* renderer still had no idea which sessions were newest, it just trusted a
|
|
204
|
+
* position. Choosing by date removes the position from the question
|
|
205
|
+
* entirely, so where an entry is written stops mattering.
|
|
206
|
+
*
|
|
207
|
+
* Ties keep array order with the later index first, which is the only
|
|
208
|
+
* information left when two entries share a day — and several do.
|
|
209
|
+
*/
|
|
210
|
+
export function selectRecentSessions<T extends { date: string }>(
|
|
211
|
+
sessions: readonly T[],
|
|
212
|
+
limit: number,
|
|
213
|
+
): SessionSelection<T> {
|
|
214
|
+
const undated: T[] = [];
|
|
215
|
+
const ranked = sessions.map((s, i) => {
|
|
216
|
+
const m = ISO_DATE.exec(s.date ?? "");
|
|
217
|
+
if (m === null) undated.push(s);
|
|
218
|
+
// An undated entry sorts below every dated one. `""` is less than any
|
|
219
|
+
// ISO date, so the comparison needs no second branch — and a branch
|
|
220
|
+
// that exists only for the empty case is a branch no fixture reaches.
|
|
221
|
+
return { s, key: m === null ? "" : m[0], i };
|
|
222
|
+
});
|
|
223
|
+
ranked.sort((a, b) => (a.key === b.key ? b.i - a.i : a.key < b.key ? 1 : -1));
|
|
224
|
+
return { rendered: ranked.slice(0, limit).map(d => d.s), undated };
|
|
225
|
+
}
|
package/lib/promote-outputs.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { existsSync, readdirSync, readFileSync, writeFileSync, mkdirSync, renameSync, statSync } from "fs";
|
|
2
2
|
import { join, basename } from "path";
|
|
3
|
+
import { localCalendarDay } from "./local-calendar-day";
|
|
3
4
|
|
|
4
5
|
interface PromoteResult {
|
|
5
6
|
promoted: string[];
|
|
@@ -32,7 +33,10 @@ export function promoteOutputs(projectRoot: string): PromoteResult {
|
|
|
32
33
|
const data = JSON.parse(readFileSync(councilJson, "utf-8"));
|
|
33
34
|
const topic = data.topic || slug;
|
|
34
35
|
const topicSlug = topic.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "").slice(0, 60);
|
|
35
|
-
|
|
36
|
+
// `capturedAt` is an ISO INSTANT written by the council run, so
|
|
37
|
+
// slicing it is reading a recorded field rather than stamping a day.
|
|
38
|
+
// The fallback — nothing recorded — is a day stamp and is local (#600).
|
|
39
|
+
const date = data.capturedAt?.slice(0, 10) || localCalendarDay();
|
|
36
40
|
const destDir = join(projectRoot, "docs", "council");
|
|
37
41
|
const destFile = join(destDir, `${date}-${topicSlug}.md`);
|
|
38
42
|
|
|
@@ -140,7 +144,7 @@ function buildResearchMarkdown(data: any, topic: string): string {
|
|
|
140
144
|
"---",
|
|
141
145
|
"doc-type: research",
|
|
142
146
|
"status: active",
|
|
143
|
-
`created: ${
|
|
147
|
+
`created: ${localCalendarDay()}`,
|
|
144
148
|
`governs: ${topic}`,
|
|
145
149
|
"---",
|
|
146
150
|
"",
|