diff --git a/src/cli/commands/decision.ts b/src/cli/commands/decision.ts new file mode 100644 index 0000000..6ebe04f --- /dev/null +++ b/src/cli/commands/decision.ts @@ -0,0 +1,55 @@ +import { input } from '@inquirer/prompts'; +import { join } from 'path'; +import { getEntityDir } from '../../core/paths.js'; +import { getNextId } from '../../core/counter.js'; +import { readEntity, writeEntity, listEntities } from '../../core/files.js'; +import { DecisionSchema, type Decision } from '../../core/schema.js'; +import { Index } from '../../core/index.js'; + +export async function decisionCreate(cwd: string, options: Partial = {}): Promise { + const title = options.title ?? await input({ message: 'Decision title:' }); + const context = options.context ?? await input({ message: 'Context:' }); + const decision = options.decision ?? await input({ message: 'Decision:' }); + + const now = new Date().toISOString(); + const record: Decision = DecisionSchema.parse({ + id: getNextId(cwd, 'decision'), + title, + context, + decision, + createdAt: now, + updatedAt: now, + }); + + const filePath = join(getEntityDir(cwd, 'decisions'), `${record.id}.md`); + writeEntity(filePath, record, `# ${record.title}\n\n## Decision\n\n${record.decision}\n\n## Context\n\n${record.context}`); + + const index = new Index(cwd); + index.upsert({ + id: record.id, + type: 'decision', + title: record.title, + content: `${record.context} ${record.decision}`, + filePath, + createdAt: record.createdAt, + updatedAt: record.updatedAt, + }); + index.close(); + + console.log(`Decision recorded: ${record.id}`); +} + +export function decisionList(cwd: string): void { + const index = new Index(cwd); + const decisions = index.list('decision'); + index.close(); + + if (decisions.length === 0) { + console.log('No decisions found.'); + return; + } + + for (const d of decisions) { + console.log(`${d.id}: ${d.title}`); + } +}