fix(state): preserve frontmatter status when body Status field is missing
syncStateFrontmatter() rebuilds YAML frontmatter from the body on every writeStateMd() call. If an agent removes or omits the Status: field from the body, buildStateFrontmatter() defaults to 'unknown', overwriting a previously valid status (e.g., 'executing'). Fix: read existing frontmatter before stripping, and preserve its status value when the body-derived status would be 'unknown'. This makes frontmatter self-healing — once a status is set, it persists even if the body loses the field. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -475,6 +475,30 @@ describe('STATE.md frontmatter sync', () => {
|
||||
assert.ok(content.includes('status: paused'), 'frontmatter should reflect latest status');
|
||||
});
|
||||
|
||||
test('preserves frontmatter status when body Status field is missing', () => {
|
||||
// Simulate: frontmatter has status: executing, but body lost Status: field
|
||||
fs.writeFileSync(
|
||||
path.join(tmpDir, '.planning', 'STATE.md'),
|
||||
`---
|
||||
status: executing
|
||||
milestone: v1.0
|
||||
---
|
||||
|
||||
# Project State
|
||||
|
||||
**Current Phase:** 03
|
||||
**Current Plan:** 03-02
|
||||
`
|
||||
);
|
||||
|
||||
// Any writeStateMd triggers syncStateFrontmatter — use state update on a field that exists
|
||||
runGsdTools('state update "Current Plan" "03-03"', tmpDir);
|
||||
|
||||
const content = fs.readFileSync(path.join(tmpDir, '.planning', 'STATE.md'), 'utf-8');
|
||||
assert.ok(content.includes('status: executing'), 'should preserve existing status, not overwrite with unknown');
|
||||
assert.ok(!content.includes('status: unknown'), 'should not contain unknown status');
|
||||
});
|
||||
|
||||
test('round-trip: write then read via state json', () => {
|
||||
fs.writeFileSync(
|
||||
path.join(tmpDir, '.planning', 'STATE.md'),
|
||||
|
||||
Reference in New Issue
Block a user