ShtukbaseStandard
package file→ .shtukbase/packages/automations/checks/t01_action.ts

checks/t01_action.ts

47 lines, 2.5 KB.

  1. // ACT-R01. An action has something to carry it out: a program its script (found on disk) or its command, an agent
  2. // action an agent page that exists. Actions on hold are not checked.
  3. import { main } from '../../collections/checks/lib/runner.ts';
  4. import { type Project, type Result, addr, findFile, has, pageExists, recordsOf, target, text } from '../../agents/lib/factlib.ts';
  5. export const RULE = {
  6. id: 'ACT-R01', title: 'An action has something to run it',
  7. scope: 'actions, except postponed ones (status: hold)',
  8. };
  9. export const KINDS = ['move', 'set', 'program', 'wake', 'agent', 'assistant', 'harness', 'specialist', 'notify', 'model', 'create', 'task', 'cloud'];
  10. const PROGRAM = ['program', 'cloud'];
  11. const AGENT = ['agent', 'assistant', 'specialist', 'harness'];
  12. export function check(p: Project, res: Result): void {
  13. const all = recordsOf(p, 'FACTION');
  14. const recs = all.filter((r) => text(r.fm.status) !== 'hold');
  15. res.scope = recs.map((r) => addr(r.id));
  16. res.scopeText = `actions ${p.coll('FACTION') || '—'} (${recs.length} of ${all.length}, postponed ones excluded)`;
  17. if (!res.part('actions', p.coll('FACTION') ? null : 'no actions collection')) return;
  18. for (const r of recs) {
  19. const at = addr(r.id);
  20. if (text(r.fm.type) !== 'Action') res.hole(at, `type "${text(r.fm.type) || '—'}", not Action`, 'set type: Action', 'bad-type');
  21. const kind = text(r.fm.kind);
  22. if (!kind) {
  23. res.hole(at, 'no kind named', `write kind: ${KINDS.join(' | ')}`, 'no-kind');
  24. continue;
  25. }
  26. if (!KINDS.includes(kind)) {
  27. res.hole(at, `kind "${kind}" is unknown`, `set one of: ${KINDS.join(', ')}`, 'bad-kind');
  28. continue;
  29. }
  30. if (PROGRAM.includes(kind)) {
  31. if (!has(r, 'path') && !has(r, 'command'))
  32. res.hole(at, 'a program with neither a script nor a command', 'write path (a script) or command', 'no-script');
  33. else if (has(r, 'path') && !findFile(p, text(r.fm.path)))
  34. res.hole(at, `script ${text(r.fm.path)} exists neither from the project root nor from the repository root`, 'fix path or bring the script back; if it is not needed, status: hold', 'missing-script');
  35. }
  36. if (AGENT.includes(kind)) {
  37. const t = has(r, 'agent') ? target(r, r.fm.agent) : null;
  38. if (!t) res.hole(at, 'an agent action without an agent', 'write agent: /agents/<name>', 'no-agent');
  39. else if (!pageExists(p, t)) res.hole(at, `agent ${t} does not exist`, 'fix the agent link or create the agent page', 'missing-agent');
  40. }
  41. }
  42. }
  43. if (import.meta.main) main({ RULE, check });