package file→ .shtukbase/packages/runs/actions/start.ts
actions/start.ts
45 lines, 2.2 KB.
- // `shtuk run runs start --title "…" [--action /actions/x] [--automation /automations/y] [--agent /agents/z]
- // [--about /work/tasks/t.md] [--woke hand] [--retryOf /runs/old.md] [--status done --evidence "…" | --status failed --message "…"] [--body "…"]`
- // Writes a run page into the collection of runs and prints its project path. With no --status the run is running;
- // with a final status it is written whole in one go (started and ended now).
- import { Project } from '../../collections/checks/lib/speclib.ts';
- import '../../agents/lib/factlib.ts'; // registers the type key RUN
- import { args, create, now, slug } from '../../agents/lib/write.ts';
- const STATES = ['running', 'waiting', 'done', 'failed', 'cancelled'];
- function fail(msg: string): never {
- console.error(msg);
- process.exit(2);
- }
- const a = args(process.argv.slice(2));
- const title = typeof a.title === 'string' ? a.title : fail('--title "what was run" is required');
- if (![a.action, a.automation, a.agent].some((x) => typeof x === 'string'))
- fail('at least one of --action, --automation, --agent is required');
- const status = typeof a.status === 'string' ? a.status : 'running';
- if (!STATES.includes(status)) fail(`--status: one of ${STATES.join(', ')}`);
- if (status === 'done' && a.evidence === undefined && !a.body) fail('a done run needs --evidence "…" (there can be several)');
- if ((status === 'failed' || status === 'cancelled') && typeof a.message !== 'string') fail(`${status}: --message "why" is required`);
- const root = process.cwd();
- const coll = new Project(root).coll('RUN') ?? '/runs';
- const t = now();
- const over = ['done', 'failed', 'cancelled'].includes(status);
- const evidence = a.evidence === undefined ? undefined : (Array.isArray(a.evidence) ? a.evidence : [a.evidence]).map(String);
- const path = create(root, coll, `${t.slice(0, 10)}-${t.slice(11, 19).replaceAll(':', '')}-${slug(title)}`, {
- type: 'Run',
- title,
- action: a.action,
- automation: a.automation,
- agent: a.agent,
- about: a.about,
- woke: typeof a.woke === 'string' ? a.woke : 'hand',
- started: typeof a.started === 'string' ? a.started : t,
- status,
- ended: over ? t : undefined,
- evidence,
- message: a.message,
- retryOf: a.retryOf,
- }, typeof a.body === 'string' ? a.body : '');
- console.log(path);