fix(#1098): guard generate-claude-md against clobbering hand-crafted files; redirect default to .claude/CLAUDE.md (#1118)
/gsd-new-project wrote a repo-root CLAUDE.md full of broad project docs, overwriting/diluting a hand-crafted instruction file. --force was parsed but silently dropped, and nothing guarded an existing non-GSD file. - Guard: an existing instruction file with no `<!-- GSD:<section>-start` markers (hand-crafted) is left untouched; report action:"skipped". --force (now wired through CmdGenerateClaudeMdOptions) overwrites intentionally. The marker check uses /<!-- GSD:[a-z]+-start/ so a file merely documenting GSD syntax is safe. - Redirect: the Claude-family default output is now ./.claude/CLAUDE.md (a valid auto-loaded project-memory location) instead of repo-root ./CLAUDE.md. Aligned across the handler default, config-defaults.manifest.json, buildNewProjectConfig, the config template, new-project.md, and cmdGenerateClaudeProfile; advisory read-CLAUDE.md hints in plan-phase/quick/profile-user updated. Codex still writes AGENTS.md. Closes #1098 Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -219,21 +219,39 @@ describe('generate-claude-md command', () => {
|
||||
}
|
||||
});
|
||||
|
||||
test('does not overwrite existing CLAUDE.md without --force', () => {
|
||||
test('does not overwrite existing marker-less CLAUDE.md without --force (#1098)', () => {
|
||||
const outputPath = path.join(tmpDir, 'CLAUDE.md');
|
||||
const original = '# Custom CLAUDE.md\n\nUser content.\n';
|
||||
fs.writeFileSync(outputPath, original);
|
||||
|
||||
// No GSD markers in the file → the #1098 guard must leave it untouched.
|
||||
const result = runGsdTools(['generate-claude-md', '--output', outputPath, '--auto'], tmpDir);
|
||||
assert.ok(result.success, `command should exit 0 even when skipping: ${result.error}`);
|
||||
assert.strictEqual(JSON.parse(result.output).action, 'skipped');
|
||||
|
||||
const content = fs.readFileSync(outputPath, 'utf-8');
|
||||
assert.strictEqual(content, original, 'hand-crafted file must be byte-identical (not overwritten)');
|
||||
});
|
||||
|
||||
test('overwrites existing marker-less CLAUDE.md with --force (#1098)', () => {
|
||||
const outputPath = path.join(tmpDir, 'CLAUDE.md');
|
||||
fs.writeFileSync(outputPath, '# Custom CLAUDE.md\n\nUser content.\n');
|
||||
|
||||
runGsdTools(['generate-claude-md', '--output', outputPath, '--auto', '--raw'], tmpDir);
|
||||
// Should merge, not overwrite
|
||||
const result = runGsdTools(['generate-claude-md', '--output', outputPath, '--force'], tmpDir);
|
||||
assert.ok(result.success, `Failed: ${result.error}`);
|
||||
assert.strictEqual(JSON.parse(result.output).action, 'updated');
|
||||
|
||||
const content = fs.readFileSync(outputPath, 'utf-8');
|
||||
assert.ok(content.length > 0, 'should still have content');
|
||||
assert.ok(content.includes('User content.'), '--force preserves existing content while adding sections');
|
||||
assert.ok(content.includes('## GSD Workflow Enforcement'), '--force injects GSD sections');
|
||||
});
|
||||
|
||||
test('skills fallback mentions the normalized project roots', () => {
|
||||
const result = runGsdTools('generate-claude-md', tmpDir);
|
||||
assert.ok(result.success, `Failed: ${result.error}`);
|
||||
|
||||
const content = fs.readFileSync(path.join(tmpDir, 'CLAUDE.md'), 'utf-8');
|
||||
// #1098: default Claude output is now .claude/CLAUDE.md
|
||||
const content = fs.readFileSync(path.join(tmpDir, '.claude', 'CLAUDE.md'), 'utf-8');
|
||||
assert.ok(content.includes('.claude/skills/'));
|
||||
assert.ok(content.includes('.agents/skills/'));
|
||||
assert.ok(content.includes('.cursor/skills/'));
|
||||
|
||||
Reference in New Issue
Block a user