MCPcopy Create free account
hub / github.com/SethGammon/Citadel / agentToToml

Function agentToToml

scripts/codex-compat.js:485–537  ·  view source on GitHub ↗
(fm, fullContent)

Source from the content-addressed store, hash-verified

483 // Per-agent override via frontmatter takes precedence — useful for an agent
484 // whose definition really needs more room.
485 if (fm.codex_max_chars !== undefined) {
486 const n = Number(fm.codex_max_chars);
487 if (Number.isFinite(n) && n >= 0) return n;
488 }
489 // Project-wide override via env var.
490 const envVal = process.env.CITADEL_CODEX_AGENT_MAX_CHARS;
491 if (envVal !== undefined && envVal !== '') {
492 const n = Number(envVal);
493 if (Number.isFinite(n) && n >= 0) return n;
494 }
495 return DEFAULT_AGENT_MAX_CHARS;
496}
497
498function translateAgents() {
499 console.log('Translating agent definitions...');
500
501 const agentsDir = path.join(CITADEL_ROOT, 'agents');
502 if (!fs.existsSync(agentsDir)) {
503 console.log(' No agents/ directory found, skipping.');
504 return;
505 }
506
507 const agentFiles = fs.readdirSync(agentsDir).filter(f => f.endsWith('.md'));
508 const agentConfig = loadCodexAgentConfig(PROJECT_ROOT);
509
510 for (const file of agentFiles) {
511 const content = fs.readFileSync(path.join(agentsDir, file), 'utf8');
512 const fm = parseFrontmatter(content);
513 if (!fm.name) continue;
514
515 const toml = agentToToml(fm, content, agentConfig);
516 writeFile(
517 path.join(PROJECT_ROOT, '.codex', 'agents', `${fm.name}.toml`),
518 toml
519 );
520 console.log(` ${file} -> .codex/agents/${fm.name}.toml`);
521 }
522}
523
524function agentToToml(fm, fullContent, agentConfig) {
525 // Extract the body after frontmatter as developer_instructions
526 const normalized = fullContent.replace(/\r\n/g, '\n');
527 const bodyMatch = normalized.match(/^---\n[\s\S]*?\n---\n([\s\S]*)/);
528 const body = bodyMatch ? bodyMatch[1].trim() : '';
529
530 // Truncate instructions, but loudly. Set CITADEL_CODEX_AGENT_MAX_CHARS=0
531 // (or higher than the body length) to disable.
532 const maxChars = getAgentMaxChars(fm);
533 if (maxChars > 0 && body.length > maxChars) {
534 const droppedChars = body.length - maxChars;
535 console.warn(
536 ` warning: agent "${fm.name}" instructions truncated — dropped ${droppedChars} chars ` +
537 `(body=${body.length}, cap=${maxChars}). Set codex_max_chars in frontmatter or ` +
538 `CITADEL_CODEX_AGENT_MAX_CHARS env to raise the cap.`
539 );
540 }

Callers 1

translateAgentsFunction · 0.85

Calls 1

getAgentMaxCharsFunction · 0.85

Tested by

no test coverage detected