ShtukbaseStandard
archivo del paquete→ .shtukbase/packages/runs/actions/start.ts

actions/start.ts

45 líneas, 2.2 KB.

El archivo tal como está en el paquete: el código y sus comentarios no se traducen.

  1. // `shtuk run runs start --title "…" [--action /actions/x] [--automation /automations/y] [--agent /agents/z]
  2. // [--about /work/tasks/t.md] [--woke hand] [--retryOf /runs/old.md] [--status done --evidence "…" | --status failed --message "…"] [--body "…"]`
  3. // Writes a run page into the collection of runs and prints its project path. With no --status the run is running;
  4. // with a final status it is written whole in one go (started and ended now).
  5. import { Project } from '../../collections/checks/lib/speclib.ts';
  6. import '../../agents/lib/factlib.ts'; // registers the type key RUN
  7. import { args, create, now, slug } from '../../agents/lib/write.ts';
  8. const STATES = ['running', 'waiting', 'done', 'failed', 'cancelled'];
  9. function fail(msg: string): never {
  10. console.error(msg);
  11. process.exit(2);
  12. }
  13. const a = args(process.argv.slice(2));
  14. const title = typeof a.title === 'string' ? a.title : fail('--title "what was run" is required');
  15. if (![a.action, a.automation, a.agent].some((x) => typeof x === 'string'))
  16. fail('at least one of --action, --automation, --agent is required');
  17. const status = typeof a.status === 'string' ? a.status : 'running';
  18. if (!STATES.includes(status)) fail(`--status: one of ${STATES.join(', ')}`);
  19. if (status === 'done' && a.evidence === undefined && !a.body) fail('a done run needs --evidence "…" (there can be several)');
  20. if ((status === 'failed' || status === 'cancelled') && typeof a.message !== 'string') fail(`${status}: --message "why" is required`);
  21. const root = process.cwd();
  22. const coll = new Project(root).coll('RUN') ?? '/runs';
  23. const t = now();
  24. const over = ['done', 'failed', 'cancelled'].includes(status);
  25. const evidence = a.evidence === undefined ? undefined : (Array.isArray(a.evidence) ? a.evidence : [a.evidence]).map(String);
  26. const path = create(root, coll, `${t.slice(0, 10)}-${t.slice(11, 19).replaceAll(':', '')}-${slug(title)}`, {
  27. type: 'Run',
  28. title,
  29. action: a.action,
  30. automation: a.automation,
  31. agent: a.agent,
  32. about: a.about,
  33. woke: typeof a.woke === 'string' ? a.woke : 'hand',
  34. started: typeof a.started === 'string' ? a.started : t,
  35. status,
  36. ended: over ? t : undefined,
  37. evidence,
  38. message: a.message,
  39. retryOf: a.retryOf,
  40. }, typeof a.body === 'string' ? a.body : '');
  41. console.log(path);