mirror of
https://github.com/bitbaum/fleet.git
synced 2026-12-04 05:07:28 +01:00
Problem: the org rules were restated by hand in CLAUDE.md essays (aoz-begleitung 1,850 lines), AGENTS.md intros and three differently worded starter templates; the starter said accounts are the app's own above a rule saying accountkit owns them. Nothing checked any of it, and 18 agent files import a personal ~/.claude file. Change: templates/agent-rules.md is the only place the rules are written. sync-agent-rules.mjs opens one pull request per code repo putting it between fleet:rules markers (and a CLAUDE.md pointer where there is no CLAUDE.md; an existing CLAUDE.md is never rewritten). agent-files-audit.mjs fails on a finding not in agent-files.baseline; a baselined finding that has been fixed, or a block that is merely out of date, never fails it (the org-drift ratchet went red twice on 26 Oct because a file in another repo improved). All three templates carry the block and a test pins that. Own workflow, so a finding in another repo cannot hold this repo's merges. Validation: 27 + 4 + 3 self-tests pass; the audit read 46 repositories and found 77 findings, all baselined; docs-truth-audit reports the same result on solon, petvity, aoz-begleitung and skif with and without the block.
53 lines
3.4 KiB
JavaScript
53 lines
3.4 KiB
JavaScript
#!/usr/bin/env node
|
|
/** Self-test for agent-rules.mjs. No network. */
|
|
import { BEGIN, END, CLAUDE_POINTER, ruleBlock, blockIn, withBlock, isPointer, findings } from './agent-rules.mjs';
|
|
import { readFileSync } from 'node:fs';
|
|
import { dirname, join } from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
|
|
let pass = 0, fail = 0;
|
|
const ok = m => { console.log(` ✓ ${m}`); pass++; };
|
|
const no = (m, got) => { console.log(` ✗ ${m}${got !== undefined ? ` — got ${JSON.stringify(got)}` : ''}`); fail++; };
|
|
const eq = (a, b, m) => (JSON.stringify(a) === JSON.stringify(b) ? ok(m) : no(m, a));
|
|
|
|
const block = ruleBlock('Rule one.\n');
|
|
console.log('inserting the block');
|
|
eq(withBlock('', block), `# Agents\n\n${block}`, 'an empty file becomes a heading and the block');
|
|
const doc = '# Agents\n\nOnly this repo.\n';
|
|
const once = withBlock(doc, block);
|
|
eq(once, `# Agents\n\n${block}\nOnly this repo.\n`, 'the block goes under the first heading, repo notes keep their place');
|
|
eq(withBlock(once, block), once, 'applying it twice changes nothing');
|
|
eq(withBlock('no heading here\n', block), `${block}\nno heading here\n`, 'a file without a heading gets the block on top');
|
|
const newer = ruleBlock('Rule two.\n');
|
|
eq(blockIn(withBlock(once, newer)), newer, 'a changed block replaces the old one in place');
|
|
eq(withBlock(once, newer).includes('Rule one.'), false, '…and nothing of the old one is left');
|
|
eq(withBlock(once, newer).includes('Only this repo.'), true, '…and the repo notes survive');
|
|
ok(BEGIN.startsWith('<!-- fleet:rules:begin') && END.includes('fleet:rules:end') ? 'markers are a pair' : 'x');
|
|
|
|
console.log('the shipped block');
|
|
const real = ruleBlock();
|
|
for (const phrase of ['@bitbaum/chatkit', '@bitbaum/searchkit', '@bitbaum/chartkit', '@bitbaum/accountkit', 'auto-merge sweep', 'No model identifier']) {
|
|
real.includes(phrase) ? ok(`names ${phrase}`) : no(`names ${phrase}`);
|
|
}
|
|
const root = join(dirname(fileURLToPath(import.meta.url)), '..', '..');
|
|
for (const t of ['templates/app/AGENTS.md', 'templates/package/AGENTS.md', 'templates/AGENTS.md']) {
|
|
const text = readFileSync(join(root, t), 'utf8');
|
|
blockIn(text)?.trim() === real.trim() ? ok(`${t} carries the current block`) : no(`${t} carries the current block`);
|
|
}
|
|
for (const t of ['templates/app/CLAUDE.md', 'templates/package/CLAUDE.md']) {
|
|
isPointer(readFileSync(join(root, t), 'utf8')) ? ok(`${t} is a pointer`) : no(`${t} is a pointer`);
|
|
}
|
|
|
|
console.log('findings');
|
|
eq(findings({ agents: once, claude: CLAUDE_POINTER, dotClaude: null }, block), [], 'a clean repo has none');
|
|
eq(findings({ agents: null, claude: null, dotClaude: null }, block), ['no-agents-md'], 'no AGENTS.md is a finding');
|
|
eq(findings({ agents: doc, claude: null, dotClaude: null }, block), ['no-rules-block'], 'AGENTS.md without the block');
|
|
eq(findings({ agents: withBlock(doc, newer), claude: null, dotClaude: null }, block), ['stale-rules-block'], 'an out-of-date block');
|
|
eq(findings({ agents: once, claude: 'x\n'.repeat(40), dotClaude: null }, block), ['claude-md-not-a-pointer'], 'a long CLAUDE.md is not a pointer');
|
|
eq(findings({ agents: once, claude: '@~/.claude/CLAUDE.md\nRead AGENTS.md\n', dotClaude: null }, block), ['home-claude-import-in-claude'], 'a personal-home import is a finding');
|
|
eq(isPointer('Read [AGENTS.md](AGENTS.md).\n'), true, 'a one-line pointer is a pointer');
|
|
eq(isPointer('Be nice.\n'), false, 'a short file that does not name AGENTS.md is not');
|
|
|
|
console.log(`\n${pass} passed, ${fail} failed`);
|
|
process.exit(fail ? 1 : 0);
|