seedproject-web/agents/scripts/lib/blogData.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

68 lines
2.3 KiB
JavaScript

import { readFileSync, writeFileSync } from "node:fs";
/** Find the [ ... ] range of `export const <arrayName> = [ ... ]`. */
function blockRange(src, arrayName) {
const marker = `export const ${arrayName} = [`;
const start = src.indexOf(marker);
if (start === -1) return null;
const open = src.indexOf("[", start);
let depth = 0;
let i = open;
for (; i < src.length; i++) {
if (src[i] === "[") depth++;
else if (src[i] === "]") {
depth--;
if (depth === 0) break;
}
}
return { open, close: i };
}
function slugsIn(src, arrayName) {
const r = blockRange(src, arrayName);
if (!r) return new Set();
const block = src.slice(r.open, r.close);
const out = new Set();
for (const m of block.matchAll(/slug:\s*["']([^"']+)["']/g)) out.add(m[1]);
return out;
}
export function readSlugs(file) {
const src = readFileSync(file, "utf8");
return {
authors: slugsIn(src, "authors"),
categories: slugsIn(src, "categories"),
tags: slugsIn(src, "tags"),
};
}
/** Insert { slug, name } as the first element of the named array if slug is absent. */
export function ensureEntry(file, arrayName, slug, name) {
let src = readFileSync(file, "utf8");
if (slugsIn(src, arrayName).has(slug)) return false;
const r = blockRange(src, arrayName);
if (!r) throw new Error(`Array ${arrayName} not found in ${file}`);
const entry = `\n { slug: ${JSON.stringify(slug)}, name: ${JSON.stringify(name)} },`;
src = src.slice(0, r.open + 1) + entry + src.slice(r.open + 1);
writeFileSync(file, src);
return true;
}
/** Insert a full author object if the slug is absent. author = {slug,name,bio,longBio,avatar} */
export function ensureAuthor(file, author) {
let src = readFileSync(file, "utf8");
if (slugsIn(src, "authors").has(author.slug)) return false;
const r = blockRange(src, "authors");
if (!r) throw new Error(`authors array not found in ${file}`);
const obj =
`\n {\n` +
` slug: ${JSON.stringify(author.slug)},\n` +
` name: ${JSON.stringify(author.name)},\n` +
` bio: ${JSON.stringify(author.bio || "")},\n` +
` longBio: ${JSON.stringify(author.longBio || author.bio || "")},\n` +
` avatar: ${JSON.stringify(author.avatar || "")},\n` +
` },`;
src = src.slice(0, r.open + 1) + obj + src.slice(r.open + 1);
writeFileSync(file, src);
return true;
}