fix: semver 3+ segment parsing and CRLF frontmatter corruption recovery

- fix(core): getMilestoneInfo() version regex `\d+\.\d+` only matched
  2-segment versions (v1.2). Changed to `\d+(?:\.\d+)+` to support
  3+ segments (v1.2.1, v2.0.1). Same fix in roadmap.cjs milestone
  extraction pattern.

- fix(state): stripFrontmatter() used `^---\n` (LF-only) which failed
  to strip CRLF frontmatter blocks. When STATE.md had dual frontmatter
  blocks from prior CRLF corruption, each writeStateMd() call preserved
  the stale block and prepended a new wrong one. Now handles CRLF and
  strips all stacked frontmatter blocks.

- fix(frontmatter): extractFrontmatter() always used the first ---
  block. When dual blocks exist from corruption, the first is stale.
  Now uses the last block (most recent sync).
This commit is contained in:
0Shard
2026-03-17 17:18:48 +02:00
parent 4915d28f98
commit 7156f02ed5
4 changed files with 23 additions and 7 deletions

View File

@@ -10,7 +10,11 @@ const { safeReadFile, normalizeMd, output, error } = require('./core.cjs');
function extractFrontmatter(content) {
const frontmatter = {};
const match = content.match(/^---\r?\n([\s\S]+?)\r?\n---/);
// Find ALL frontmatter blocks at the start of the file.
// If multiple blocks exist (corruption from CRLF mismatch), use the LAST one
// since it represents the most recent state sync.
const allBlocks = [...content.matchAll(/(?:^|\n)\s*---\r?\n([\s\S]+?)\r?\n---/g)];
const match = allBlocks.length > 0 ? allBlocks[allBlocks.length - 1] : null;
if (!match) return frontmatter;
const yaml = match[1];