ShtukbaseStandard
package file→ .shtukbase/packages/agents/checks/a01_definition.ts

checks/a01_definition.ts

42 lines, 2.4 KB.

  1. // AGT-R01. An agent description can be repeated: its page type says how long the agent lives, it names the runtime
  2. // and the model (or the runtime's profile), limits are whole numbers, and the head carries no conversation.
  3. import { main } from '../../collections/checks/lib/runner.ts';
  4. import { AGENT_TYPES, type Project, type Result, addr, count, has, map, recordsOf, text } from '../lib/factlib.ts';
  5. export const RULE = {
  6. id: 'AGT-R01', title: 'An agent definition can be repeated',
  7. scope: 'all pages of the agents collection',
  8. };
  9. /** Head keys that would make a description a conversation (the node refuses the same). */
  10. export const TRANSCRIPT_FIELDS = ['chat', 'chats', 'session', 'sessions', 'transcript', 'transcripts', 'history'];
  11. const LIMITS = ['minutes', 'tokens', 'perHour', 'perDay'];
  12. export function check(p: Project, res: Result): void {
  13. const recs = recordsOf(p, 'AGENT');
  14. res.scope = recs.map((r) => addr(r.id));
  15. res.scopeText = `agents ${p.coll('AGENT') || '—'} (${recs.length})`;
  16. if (!res.part('agents', p.coll('AGENT') ? null : 'no agents collection')) return;
  17. for (const r of recs) {
  18. const at = addr(r.id);
  19. const type = text(r.fm.type);
  20. if (!AGENT_TYPES.includes(type))
  21. res.hole(at, `type "${type || '—'}" is not an agent kind`, `set type: ${AGENT_TYPES.join(' | ')}`, 'bad-type');
  22. if (!has(r, 'runtime')) res.hole(at, 'no runtime named', 'write runtime: claude, codex, hermes ...', 'no-runtime');
  23. if (!has(r, 'model') && !has(r, 'profile'))
  24. res.hole(at, 'neither a model nor a profile is named', 'write model (or the runtime profile)', 'no-model');
  25. for (const f of TRANSCRIPT_FIELDS)
  26. if (f in r.fm) res.hole(at, `the head has the field ${f}: an agent definition is a setup, not a conversation`, `remove ${f}; conversations and sessions go to the run log`, 'transcript-field');
  27. if (r.fm.limits !== undefined && r.fm.limits !== null) {
  28. const l = map(r.fm.limits);
  29. if (!l) res.hole(at, 'limits is not a map', `write limits: {${LIMITS.join(', ')}}`, 'bad-limit');
  30. else
  31. for (const [k, v] of Object.entries(l)) {
  32. if (!LIMITS.includes(k)) res.hole(at, `limits.${k} is an unknown limit`, `keep only ${LIMITS.join(', ')}`, 'bad-limit');
  33. else if (count(v) === null) res.hole(at, `limits.${k}: "${text(v)}" is not a whole number above zero`, 'set a whole number', 'bad-limit');
  34. }
  35. }
  36. }
  37. }
  38. if (import.meta.main) main({ RULE, check });