fix: CRLF frontmatter parsing, duplicate cwd crash, STATE.md phase transitions (#1105)

- fix(frontmatter): handle CRLF line endings in extractFrontmatter,
  spliceFrontmatter, and parseMustHavesBlock — fixes wave parsing on
  Windows where all plans reported as wave 1 (#1085)

- fix(hooks): remove duplicate const cwd declaration in
  gsd-context-monitor.js that caused SyntaxError on every PostToolUse
  invocation (#1091, #1092, #1094)

- feat(state): add 'state begin-phase' command that updates STATUS,
  Last Activity, Current focus, Current Position, and plan counts
  when a new phase starts executing (#1102, #1103, #1104)

- docs(workflow): add state begin-phase call to execute-phase workflow
  validate_phase step so STATE.md is current from the start
This commit is contained in:
Tom Boucher
2026-03-16 15:40:21 -04:00
committed by GitHub
parent 80605d2051
commit 2842f076ea
5 changed files with 99 additions and 6 deletions

View File

@@ -10,11 +10,11 @@ const { safeReadFile, normalizeMd, output, error } = require('./core.cjs');
function extractFrontmatter(content) {
const frontmatter = {};
const match = content.match(/^---\n([\s\S]+?)\n---/);
const match = content.match(/^---\r?\n([\s\S]+?)\r?\n---/);
if (!match) return frontmatter;
const yaml = match[1];
const lines = yaml.split('\n');
const lines = yaml.split(/\r?\n/);
// Stack to track nested objects: [{obj, key, indent}]
// obj = object to write to, key = current key collecting array items, indent = indentation level
@@ -149,7 +149,7 @@ function reconstructFrontmatter(obj) {
function spliceFrontmatter(content, newObj) {
const yamlStr = reconstructFrontmatter(newObj);
const match = content.match(/^---\n[\s\S]+?\n---/);
const match = content.match(/^---\r?\n[\s\S]+?\r?\n---/);
if (match) {
return `---\n${yamlStr}\n---` + content.slice(match[0].length);
}
@@ -159,7 +159,7 @@ function spliceFrontmatter(content, newObj) {
function parseMustHavesBlock(content, blockName) {
// Extract a specific block from must_haves in raw frontmatter YAML
// Handles 3-level nesting: must_haves > artifacts/key_links > [{path, provides, ...}]
const fmMatch = content.match(/^---\n([\s\S]+?)\n---/);
const fmMatch = content.match(/^---\r?\n([\s\S]+?)\r?\n---/);
if (!fmMatch) return [];
const yaml = fmMatch[1];
@@ -169,7 +169,7 @@ function parseMustHavesBlock(content, blockName) {
if (blockStart === -1) return [];
const afterBlock = yaml.slice(blockStart);
const blockLines = afterBlock.split('\n').slice(1); // skip the header line
const blockLines = afterBlock.split(/\r?\n/).slice(1); // skip the header line
const items = [];
let current = null;