fix: preserve agent memory files when installing RA-H rules
- Add RA-H graph memory as a marked section instead of replacing files - Make install-rules idempotent for AGENTS.md and CLAUDE.md - Document the demo-safe memory file setup command Generated with Claude Code
This commit is contained in:
@@ -344,7 +344,9 @@ function validateClient(client) {
|
||||
}
|
||||
|
||||
function rulesSnippet() {
|
||||
return `You are helping build a thoughtful graph of atomic units of context.
|
||||
return `## RA-H Graph Memory
|
||||
|
||||
You are helping build a thoughtful graph of atomic units of context.
|
||||
|
||||
- Before substantive work that touches the user's projects, ideas, people, decisions, or prior context, retrieve relevant graph context from RA-H.
|
||||
- Use queryNodes for direct lookup of a specific existing node.
|
||||
@@ -356,6 +358,19 @@ function rulesSnippet() {
|
||||
`;
|
||||
}
|
||||
|
||||
function mergeRulesFile(existing, content) {
|
||||
const start = '<!-- RA-H_GRAPH_MEMORY_START -->';
|
||||
const end = '<!-- RA-H_GRAPH_MEMORY_END -->';
|
||||
const block = `${start}\n${content.trimEnd()}\n${end}`;
|
||||
const pattern = new RegExp(`${start}[\\s\\S]*?${end}`);
|
||||
|
||||
if (pattern.test(existing)) {
|
||||
return `${existing.replace(pattern, block).trimEnd()}\n`;
|
||||
}
|
||||
|
||||
return `${existing.trimEnd()}${existing.trim() ? '\n\n' : ''}${block}\n`;
|
||||
}
|
||||
|
||||
function rulesTarget(client, target) {
|
||||
const base = expandPath(target || process.cwd());
|
||||
if (client === 'cursor') return path.join(base, '.cursor', 'rules', 'ra-h.mdc');
|
||||
@@ -415,8 +430,9 @@ function commandInstallRules(args) {
|
||||
}
|
||||
|
||||
fs.mkdirSync(path.dirname(targetPath), { recursive: true });
|
||||
fs.writeFileSync(targetPath, content);
|
||||
log(`Wrote rules to ${targetPath}`);
|
||||
const existing = fs.existsSync(targetPath) ? fs.readFileSync(targetPath, 'utf8') : '';
|
||||
fs.writeFileSync(targetPath, mergeRulesFile(existing, content));
|
||||
log(`Updated rules in ${targetPath}`);
|
||||
}
|
||||
|
||||
function commandSetup(args) {
|
||||
|
||||
Reference in New Issue
Block a user