← back to The Ai Factory
src/stages/document.js
43 lines
// Stage 8 — document. For skills only, drop a README.md into the artifact dir
// alongside SKILL.md so Steve can read what it does without opening SKILL.md.
// No-op for subagents (they're a single .md and self-documenting).
const fs = require('node:fs/promises');
const path = require('node:path');
async function runDocument({ runId, spec, scaffoldOutPath }) {
if (spec.artifact_type !== 'skill') return { skipped: true, reason: 'subagent — README not needed' };
const dir = path.dirname(scaffoldOutPath);
const readmePath = path.join(dir, 'README.md');
const triggers = (spec.triggers || []).length
? spec.triggers.map(t => `- "${t}"`).join('\n')
: '- (none specified in spec)';
const oos = (spec.out_of_scope || []).length
? spec.out_of_scope.map(o => `- ${o}`).join('\n')
: '- (none specified)';
const content = `# ${spec.artifact_name}
${spec.scope || ''}
## Triggers
${triggers}
## Out of scope
${oos}
---
Generated by The AI Factory · run #${runId} · ${new Date().toISOString().slice(0, 10)}
`;
await fs.writeFile(readmePath, content, 'utf8');
return { skipped: false, readmePath };
}
module.exports = { runDocument };