包文件→ .shtukbase/packages/automations/checks/t01_action.ts
checks/t01_action.ts
47 行, 2.5 KB.
文件按包中的原样显示:代码及其注释不做翻译。
- // ACT-R01. An action has something to carry it out: a program its script (found on disk) or its command, an agent
- // action an agent page that exists. Actions on hold are not checked.
- import { main } from '../../collections/checks/lib/runner.ts';
- import { type Project, type Result, addr, findFile, has, pageExists, recordsOf, target, text } from '../../agents/lib/factlib.ts';
- export const RULE = {
- id: 'ACT-R01', title: 'An action has something to run it',
- scope: 'actions, except postponed ones (status: hold)',
- };
- export const KINDS = ['move', 'set', 'program', 'wake', 'agent', 'assistant', 'harness', 'specialist', 'notify', 'model', 'create', 'task', 'cloud'];
- const PROGRAM = ['program', 'cloud'];
- const AGENT = ['agent', 'assistant', 'specialist', 'harness'];
- export function check(p: Project, res: Result): void {
- const all = recordsOf(p, 'FACTION');
- const recs = all.filter((r) => text(r.fm.status) !== 'hold');
- res.scope = recs.map((r) => addr(r.id));
- res.scopeText = `actions ${p.coll('FACTION') || '—'} (${recs.length} of ${all.length}, postponed ones excluded)`;
- if (!res.part('actions', p.coll('FACTION') ? null : 'no actions collection')) return;
- for (const r of recs) {
- const at = addr(r.id);
- if (text(r.fm.type) !== 'Action') res.hole(at, `type "${text(r.fm.type) || '—'}", not Action`, 'set type: Action', 'bad-type');
- const kind = text(r.fm.kind);
- if (!kind) {
- res.hole(at, 'no kind named', `write kind: ${KINDS.join(' | ')}`, 'no-kind');
- continue;
- }
- if (!KINDS.includes(kind)) {
- res.hole(at, `kind "${kind}" is unknown`, `set one of: ${KINDS.join(', ')}`, 'bad-kind');
- continue;
- }
- if (PROGRAM.includes(kind)) {
- if (!has(r, 'path') && !has(r, 'command'))
- res.hole(at, 'a program with neither a script nor a command', 'write path (a script) or command', 'no-script');
- else if (has(r, 'path') && !findFile(p, text(r.fm.path)))
- 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');
- }
- if (AGENT.includes(kind)) {
- const t = has(r, 'agent') ? target(r, r.fm.agent) : null;
- if (!t) res.hole(at, 'an agent action without an agent', 'write agent: /agents/<name>', 'no-agent');
- else if (!pageExists(p, t)) res.hole(at, `agent ${t} does not exist`, 'fix the agent link or create the agent page', 'missing-agent');
- }
- }
- }
- if (import.meta.main) main({ RULE, check });