seedproject-web/agents/scripts/lib/claude.mjs
Carlos Arias 2c969c0753 feat: content-pipeline/ → agents/ — formalize the agent system in the seed
Adopt the agents/ architecture proven on medellin.co (reference impl):

- Move the content engine to a top-level agents/ dir: orchestrators, prompts,
  config, run.sh, admin console, shared libs. All content-pipeline literals
  repointed (config paths, scripts, admin, LLM-facing prompts/image.md string,
  configure.mjs, new-site.sh, astroagent tokenFile, .gitignore runtime block).
- Every script carries a parseable @agent-manifest header: name, title, class
  (content|operational|runtime|plumbing), trigger, model, prompts, skills (MCP),
  tools, reads/writes tables. 5 content agents + 3 plumbing scripts.
- New agents/catalog.mjs generates the catalog from the headers:
  agents/AGENTS.md (human, grouped by class) + agents/agents.json (machine
  manifest — a clone diffs it against a source to find missing tools/tables/MCP
  before running). configure.mjs regenerates the catalog on every identity
  stamp. No DB table, no watcher.
- config.json gains paths.stateDir/newsDir; publish-tick, write-daily, and
  news-radar read them instead of hardcoding.
- Full cut: content-pipeline/ deleted (the seed has no live crons, so no
  hybrid period needed). Docs updated (AGENTS.md structure + pipeline section,
  README paths).

Clones migrating from content-pipeline/: see medellin.co's
.memory/handoffs/agents-directory-migration.md for the cutover playbook
(one cron set active at a time; migrate drafts/state after repointing cron).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FMQeUnUrAeexcZ7P2Hxa6G
2026-07-11 17:09:15 -05:00

71 lines
2 KiB
JavaScript

import { spawn } from "node:child_process";
import { createWriteStream, readFileSync } from "node:fs";
const CLAUDE_BIN = process.env.CLAUDE_BIN || "claude";
/**
* Run headless Claude Code and return the parsed JSON result.
* The system prompt file is read and passed via --append-system-prompt so we don't
* depend on the --append-system-prompt-file flag variant.
*/
export function runClaude({
prompt,
systemPromptFile,
model,
mcpConfig,
allowedTools,
addDirs = [],
cwd,
logFile,
permissionMode = "acceptEdits", // bypassPermissions is blocked under root
}) {
return new Promise((resolve, reject) => {
const args = [
"-p",
prompt,
"--output-format",
"json",
"--permission-mode",
permissionMode,
];
if (model) args.push("--model", model);
if (systemPromptFile) {
const sys = readFileSync(systemPromptFile, "utf8");
args.push("--append-system-prompt", sys);
}
if (mcpConfig) args.push("--mcp-config", mcpConfig);
if (allowedTools) args.push("--allowed-tools", allowedTools);
for (const d of addDirs) args.push("--add-dir", d);
const log = logFile ? createWriteStream(logFile, { flags: "a" }) : null;
if (log) log.write(`\n\n===== ${new Date().toISOString()} claude run =====\n`);
const child = spawn(CLAUDE_BIN, args, {
cwd,
env: process.env,
stdio: ["ignore", "pipe", "pipe"],
});
let stdout = "";
let stderr = "";
child.stdout.on("data", (b) => {
stdout += b;
if (log) log.write(b);
});
child.stderr.on("data", (b) => {
stderr += b;
if (log) log.write(b);
});
child.on("error", reject);
child.on("close", (code) => {
if (log) log.end();
if (code !== 0) {
return reject(new Error(`claude exited ${code}: ${stderr.slice(-2000) || stdout.slice(-2000)}`));
}
try {
resolve(JSON.parse(stdout));
} catch {
resolve({ result: stdout.trim(), raw: true });
}
});
});
}