feat(cli): add decision create/list commands
This commit is contained in:
parent
0cc88603e1
commit
fed43e70ed
55
src/cli/commands/decision.ts
Normal file
55
src/cli/commands/decision.ts
Normal file
@ -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<Decision> = {}): Promise<void> {
|
||||||
|
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}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user