fix(#4660): widen the 6 shell/markdown phase-id mirrors to the canonical grammar's letter axis (#4744)

* test(#4660): pin the letter-axis parity defect across all 6 shell/markdown phase-id sites

Extends tests/nsegment-phase-grammar.test.cjs (#4568) one axis over: for each
of the six sites, reads the live regex off disk and asserts it agrees with
src/phase-id.cts's PHASE_NUMBER_TOKEN_SOURCE on the letter axis in BOTH
directions — accepts `12A` / `3A` / `03A` / `23A.1.2`, still rejects `3a`,
`3AB`, `A3` and the other canonical-invalid shapes — and that the two
extracting sites return the full letter-suffixed token rather than its digit
prefix (or nothing).

Negative control against the unfixed tree: 22 failures, exactly the
"(fails before the fix)" cases; every reject-parity case already green.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NLtEbRc1Qfbe95HRMNqwp3

* fix(#4660): widen the 6 shell/markdown phase-id mirrors to the canonical grammar's letter axis

Adds `[A-Z]?` after the leading digit run at all six sites #4568 widened —
the ERE translation of src/phase-id.cts's `\d+[A-Z]?(?:\.\d+)*` — so a
documented, canonical-valid id like `12A` or `23A.1.2` is no longer refused
by the four validating sites (code-review.md, code-review-fix.md,
gsd-code-fixer.md, gsd-code-fixer.compact.md) or truncated to its digit
prefix by the two extracting sites (execute-plan.md's plan-filename grep,
plan-phase.md's --research-phase capture). Behaviour is byte-identical for
every id that matched before; the adjacent comment and error-message text
now names the grammar it mirrors.

Driven: `init code-review 3A` on a fixture with a `03A-slug/` directory and
a `### Phase 3A:` heading emits `padded_phase: "03A"`, which the old regex
rejects and the widened one accepts — nothing upstream of the validator
mangles the id.

At execute-plan.md the trailing `-[0-9]+` is the PLAN number and stays
digit-only; plan and milestone dimensions are out of scope per the brief.
`CASE_FLEXIBLE_PHASE_NUMBER_TOKEN_SOURCE` derives from the canonical source
by a literal `.replaceAll('A-Z', 'A-Za-z')`, so src/phase-id.cts is
deliberately untouched.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NLtEbRc1Qfbe95HRMNqwp3

* chore(#4634): extend lint-phase-id-drift to ban a letter-less phase-id mirror in workflows/ and agents/

Adds findLetterlessPhaseMirrorDrift — the letter-axis twin of the #4568
single-segment rule — flagging the unbounded-segment shape
`[0-9]+(\.[0-9]+)*` (and its \d / doubled-backslash near-variants) whose
digit run is NOT followed by the `[A-Z]?` class, on any phase-carrying line
across gsd-core/workflows/**/*.md, gsd-core/references/**/*.md and
agents/**/*.md. Sanctioned the same way (`<!-- phase-id-owner: ... -->`),
tolerates the case-flexible `[A-Za-z]?` directory-scanning variant so it
cannot force that separate axis to narrow, and is wired into scanAll.
Confirmed zero violations against the real tree post-#4660 fix, and one
violation when a single site is reverted.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NLtEbRc1Qfbe95HRMNqwp3

* docs(#4660): add Fixed changeset

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NLtEbRc1Qfbe95HRMNqwp3

* chore: regenerate conformance-tier manifests for the extended grammar test

tests/nsegment-phase-grammar.test.cjs now requires the compiled
gsd-core/bin/lib/phase-id.cjs (to assert the canonical grammar agrees with
each site's live regex), which moves it to a different platform-conformance
tier; `gen-platform-conformance-tier.cjs --check` in lint:ci flagged the
macOS manifest as stale.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NLtEbRc1Qfbe95HRMNqwp3

* test(#4660): reword a comment that tripped lint-docs-guard-registration

The comment mentioned `docs/CONFIGURATION.md` between two backticked
tokens, which the lint's template-literal detector read as a docs/ path
expression. The test reads no docs/ file.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NLtEbRc1Qfbe95HRMNqwp3

* chore(#4660): refresh the compact-content benchmark baseline and acknowledge emitted growth

plan-phase.md grew by 4 bytes (`[A-Z]?`), which moves the committed
compact-content benchmark; refreshed with `benchmark-compact-content.cjs
--write`. The six shipped files below grew by the widened regex literal plus
the comment and error-message text that now names the canonical grammar.

Emitted-Drift-Ack-Growth: code-review.md — #4660: `[A-Z]?` at the PADDED_PHASE validator plus a comment/error message naming the canonical grammar and the `12A` example
Emitted-Drift-Ack-Growth: code-review-fix.md — #4660: `[A-Z]?` at the PADDED_PHASE validator plus a comment/error message naming the canonical grammar and the `12A` example
Emitted-Drift-Ack-Growth: gsd-code-fixer.md — #4660: `[A-Z]?` at the padded_phase sink validator plus the defense-in-depth comment and error message updated to the canonical grammar
Emitted-Drift-Ack-Growth: gsd-code-fixer.compact.md — #4660: `[A-Z]?` at the padded_phase sink validator plus the comment and error message updated to the canonical grammar
Emitted-Drift-Ack-Growth: execute-plan.md — #4660: `[A-Z]?` in the plan-filename phase extraction (6 bytes)
Emitted-Drift-Ack-Growth: plan-phase.md — #4660: `[A-Z]?` in the --research-phase capture (6 bytes)
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NLtEbRc1Qfbe95HRMNqwp3

* chore(#4660): set changeset fragment pr to 4744

* chore: re-trigger Validate Branch Name

The required check-branch context was cancelled on this head by the
workflow's cancel-in-progress group when the changeset pr-field backfill
push landed three seconds after the PR opened; no completed run exists for
the current head, and a fork contributor cannot re-run it. Empty commit to
re-run it.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NLtEbRc1Qfbe95HRMNqwp3

---------

Co-authored-by: CI Rebase Check <ci@gsd-redux>
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
Co-authored-by: Tom Boucher <trekkie@nomorestars.com>
This commit is contained in:
0xdhx
2026-09-14 18:32:12 -05:00
committed by GitHub
parent 06845717fe
commit 48271de43f
12 changed files with 292 additions and 21 deletions

View File

@@ -127,6 +127,7 @@ module.exports = {
"tests/no-posix-mode-bit-assert.rule.test.cjs",
"tests/no-private-binary-resolution.rule.test.cjs",
"tests/no-unguarded-nonportable-exec.rule.test.cjs",
"tests/nsegment-phase-grammar.test.cjs",
"tests/observability/event.test.cjs",
"tests/onboard-command.test.cjs",
"tests/opencode-plugin-adapter.test.cjs",

View File

@@ -389,6 +389,66 @@ function scanMarkdownSingleSegmentPhaseRegex(root) {
return violations;
}
// #4660 (epic #4634): the six shell/markdown mirrors #4568 widened on the
// segment-count axis stayed digit-only on the LETTER axis — the canonical
// grammar (`src/phase-id.cts`) is `\d+[A-Z]?(?:\.\d+)*`, with an optional
// single uppercase letter after the leading digits (`12A`, `3A`, `23A.1.2`,
// documented in docs/CONFIGURATION.md and relied on by `renameIntegerPhases`).
// A digit-only mirror `[0-9]+(\.[0-9]+)*` hard-rejects (validating sites) or
// silently truncates (extracting sites) a letter-suffixed id. This rule is the
// ratchet for that axis, the twin of the single-segment rule above: it flags
// the unbounded-segment shape whose digit run is NOT followed by the letter
// class. `[A-Z]` is the canonical spelling; the case-flexible `[A-Za-z]`
// directory-scanning variant is a deliberately separate axis and is tolerated
// here so this rule cannot force it to narrow.
const LETTERLESS_PHASE_MIRROR_DRIFT_RE =
/(?:\\{1,2}d|\[0-9\])\+(?!\[A-Z(?:a-z)?\]\?)\(\\{1,2}\.(?:\\{1,2}d|\[0-9\])\+\)\*/;
/**
* Pure: find every unsanctioned digit-only (letter-less) unbounded-segment
* phase regex in `text`, restricted to lines that plausibly carry a
* phase-number variable — the same `PHASE_CARRYING_LINE_RE` filter and the
* same `<!-- phase-id-owner: ... -->` sanction as the single-segment rule.
* Returns [{ line, found }].
*/
function findLetterlessPhaseMirrorDrift(text) {
const out = [];
const lines = text.split('\n');
for (let i = 0; i < lines.length; i++) {
const line = lines[i];
const m = LETTERLESS_PHASE_MIRROR_DRIFT_RE.exec(line);
if (!m) continue;
if (!PHASE_CARRYING_LINE_RE.test(line)) continue;
if (isSanctionedByPrecedingComment(lines, i, MD_OWNER_RE)) continue;
out.push({ line: i + 1, found: m[0] });
}
return out;
}
/**
* Scan the same three markdown roots as the single-segment rule for
* unsanctioned letter-less phase-regex mirrors. Returns [{ file, line, found }]
* with repo-relative paths.
*/
function scanMarkdownLetterlessPhaseMirror(root) {
const violations = [];
for (const dir of SINGLE_SEGMENT_SCAN_DIRS) {
for (const file of walkMd(path.join(root, dir), [])) {
const rel = path.relative(root, file);
let text;
try {
text = fs.readFileSync(file, 'utf8');
} catch {
continue;
}
for (const d of findLetterlessPhaseMirrorDrift(text)) {
violations.push({ file: rel, kind: 'letterless-phase-mirror', ...d });
}
}
}
return violations;
}
// Authored TypeScript source only (the generated bin/lib/*.cjs mirror it).
const SCAN_DIRS = ['src'];
const SCAN_EXT = new Set(['.cts', '.ts', '.mts']);
@@ -541,6 +601,7 @@ function scanAll(root) {
...scanRepo(root),
...scanMarkdownShellArith(root),
...scanMarkdownSingleSegmentPhaseRegex(root),
...scanMarkdownLetterlessPhaseMirror(root),
];
}
@@ -567,6 +628,9 @@ function main() {
process.stderr.write('near-variant) is banned outright in gsd-core/workflows/**/*.md,\n');
process.stderr.write('gsd-core/references/**/*.md, and agents/**/*.md — widen it to `*` (unbounded\n');
process.stderr.write('segments) or sanction with `<!-- phase-id-owner: <reason> -->`.\n');
process.stderr.write('A digit-only unbounded-segment phase regex `[0-9]+(\\.[0-9]+)*` on the same roots\n');
process.stderr.write('is missing the canonical letter axis (#4660) — widen to `[0-9]+[A-Z]?(\\.[0-9]+)*`\n');
process.stderr.write('or sanction with `<!-- phase-id-owner: <reason> -->`.\n');
process.stderr.write('A `.replace(\'{slug}\', ... || \'phase\')` fallback is banned outright (#4126) —\n');
process.stderr.write('use `renderPhaseBranchName(` or sanction with\n');
process.stderr.write('`// phase-id-owner: <reason>` on the line directly above:\n');
@@ -585,8 +649,10 @@ module.exports = {
findBranchSlugFallbackDrift,
findShellPhaseArithDrift,
findSingleSegmentPhaseRegexDrift,
findLetterlessPhaseMirrorDrift,
scanMarkdownShellArith,
scanMarkdownSingleSegmentPhaseRegex,
scanMarkdownLetterlessPhaseMirror,
scanRepo,
scanAll,
countSelectorBaselines,
@@ -597,4 +663,5 @@ module.exports = {
BRANCH_SLUG_FALLBACK_DRIFT_RE,
SHELL_PHASE_ARITH_DRIFT_RE,
SINGLE_SEGMENT_PHASE_DRIFT_RE,
LETTERLESS_PHASE_MIRROR_DRIFT_RE,
};