* fix(#1776): scope prune phase resolution to ## Current Position cmdStatePrune resolved the current phase by extracting the `Phase` field over the WHOLE STATE.md body. stateExtractField's fallback chain ends in a pipe-table match (`| Phase | N |`), so a STATE.md lacking a `Current Phase` field and a prose `Phase:` line — but carrying an unrelated `Phase`-labelled table row (e.g. a historical verification table) — resolved that stale table cell as the current phase and computed a wrong cutoff (bailing "Only N phases" or pruning at a stale boundary). Resolve the phase via the same canonical chain buildStateFrontmatter uses — frontmatter `current_phase` → `Current Phase` field → prose `Phase: X of Y` — but scope ONLY the prose term to the `## Current Position` section via the fence-aware locateCurrentPosition seam (new exported sliceCurrentPositionSection). Frontmatter and the explicit `Current Phase` field stay document-wide (they are unambiguous); the shared stateExtractField is not narrowed for any other caller. Tests (folded into tests/state-prune.test.cjs): a stray `| Phase | 2 |` table with the real phase in frontmatter no longer drives the cutoff (fail-first on base); template-conformant STATE.md is unchanged; and a fast-check boundary-containment property that a `| Phase | N |` row outside Current Position never leaks into the scoped resolution. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * chore(#1776): add changeset for prune Current Position scoping Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Co-authored-by: Tom Boucher <trekkie@nomorestars.com>
This commit is contained in:
committed by
GitHub
parent
dae7f81482
commit
50ff7a8707
@@ -19,6 +19,7 @@ exports.STATE_MD_SECTIONS = exports.FIELD_CLASSIFICATION = void 0;
|
||||
exports.getFieldClassification = getFieldClassification;
|
||||
exports.applyStatePreservation = applyStatePreservation;
|
||||
exports.transitionCore = transitionCore;
|
||||
exports.sliceCurrentPositionSection = sliceCurrentPositionSection;
|
||||
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
||||
const frontmatter = require("./frontmatter.cjs");
|
||||
const state_document_cjs_1 = require("./state-document.cjs");
|
||||
@@ -319,6 +320,20 @@ function locateCurrentPosition(body) {
|
||||
}
|
||||
return { start, end };
|
||||
}
|
||||
/**
|
||||
* Return the body text of the `## Current Position` section, or `null` when it
|
||||
* is absent. Reuses the fence-aware `locateCurrentPosition` locator (ADR-1372).
|
||||
*
|
||||
* Exposed so callers that must read a position field (e.g. `cmdStatePrune`,
|
||||
* #1776) can scope extraction to the canonical section instead of the whole
|
||||
* document — where `stateExtractField`'s pipe-table fallback could otherwise
|
||||
* latch onto an unrelated `| Phase | N |` row elsewhere in STATE.md. This
|
||||
* scopes the *caller*; the shared extractor is left broad for every other use.
|
||||
*/
|
||||
function sliceCurrentPositionSection(body) {
|
||||
const span = locateCurrentPosition(body);
|
||||
return span === null ? null : body.slice(span.start, span.end);
|
||||
}
|
||||
/**
|
||||
* First-time ## Current Position mutation: update Phase / Plan / Status /
|
||||
* Last activity lines. Mirrors state.cts:2261-2324 byte-for-behaviour
|
||||
|
||||
Reference in New Issue
Block a user