包文件→ .shtukbase/packages/agents/checks/a01_definition.ts
checks/a01_definition.ts
42 行, 2.4 KB.
文件按包中的原样显示:代码及其注释不做翻译。
- // AGT-R01. An agent description can be repeated: its page type says how long the agent lives, it names the runtime
- // and the model (or the runtime's profile), limits are whole numbers, and the head carries no conversation.
- import { main } from '../../collections/checks/lib/runner.ts';
- import { AGENT_TYPES, type Project, type Result, addr, count, has, map, recordsOf, text } from '../lib/factlib.ts';
- export const RULE = {
- id: 'AGT-R01', title: 'An agent definition can be repeated',
- scope: 'all pages of the agents collection',
- };
- /** Head keys that would make a description a conversation (the node refuses the same). */
- export const TRANSCRIPT_FIELDS = ['chat', 'chats', 'session', 'sessions', 'transcript', 'transcripts', 'history'];
- const LIMITS = ['minutes', 'tokens', 'perHour', 'perDay'];
- export function check(p: Project, res: Result): void {
- const recs = recordsOf(p, 'AGENT');
- res.scope = recs.map((r) => addr(r.id));
- res.scopeText = `agents ${p.coll('AGENT') || '—'} (${recs.length})`;
- if (!res.part('agents', p.coll('AGENT') ? null : 'no agents collection')) return;
- for (const r of recs) {
- const at = addr(r.id);
- const type = text(r.fm.type);
- if (!AGENT_TYPES.includes(type))
- res.hole(at, `type "${type || '—'}" is not an agent kind`, `set type: ${AGENT_TYPES.join(' | ')}`, 'bad-type');
- if (!has(r, 'runtime')) res.hole(at, 'no runtime named', 'write runtime: claude, codex, hermes ...', 'no-runtime');
- if (!has(r, 'model') && !has(r, 'profile'))
- res.hole(at, 'neither a model nor a profile is named', 'write model (or the runtime profile)', 'no-model');
- for (const f of TRANSCRIPT_FIELDS)
- 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');
- if (r.fm.limits !== undefined && r.fm.limits !== null) {
- const l = map(r.fm.limits);
- if (!l) res.hole(at, 'limits is not a map', `write limits: {${LIMITS.join(', ')}}`, 'bad-limit');
- else
- for (const [k, v] of Object.entries(l)) {
- if (!LIMITS.includes(k)) res.hole(at, `limits.${k} is an unknown limit`, `keep only ${LIMITS.join(', ')}`, 'bad-limit');
- 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');
- }
- }
- }
- }
- if (import.meta.main) main({ RULE, check });