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

84 lines
3.3 KiB
JavaScript

import { existsSync, readFileSync, writeFileSync, renameSync, cpSync, rmSync } from "node:fs";
import { join } from "node:path";
import { readFrontmatter, fmString, fmArray, titleCase } from "./util.mjs";
import { readSlugs, ensureEntry } from "./blogData.mjs";
import { updateEntry } from "./calendar.mjs";
import { buildSite } from "./build.mjs";
import { gitCommitPaths } from "./git.mjs";
/**
* Promote a draft into the Astro blog and build the site.
* Shared by approve.mjs (manual) and publish-tick.mjs (auto). Does NOT do the SEO gate —
* callers decide whether the draft is allowed to publish.
* @param {object} cfg parsed config.json
* @param {string} slug
* @param {{dateOverride?: string}} opts dateOverride = ISO timestamp to stamp as the post date
* @returns {Promise<{dest:string,url:string,taxonomyAdded:string[]}>}
*/
export async function promoteDraft(cfg, slug, { dateOverride } = {}) {
const root = cfg.paths.projectRoot;
const draftDir = join(root, cfg.paths.draftsDir, slug);
const mdxPath = join(draftDir, "index.mdx");
if (!existsSync(mdxPath)) throw new Error(`no draft at ${mdxPath}`);
if (!existsSync(join(draftDir, "cover.jpg"))) throw new Error("draft is missing cover.jpg");
// Stamp a specific published date/time into the frontmatter (randomized publish time).
if (dateOverride) {
const raw = readFileSync(mdxPath, "utf8");
writeFileSync(mdxPath, raw.replace(/^date:.*$/m, `date: ${dateOverride}`));
}
const fm = readFrontmatter(readFileSync(mdxPath, "utf8"));
const author = fmString(fm, "author");
const category = fmString(fm, "category");
const tags = fmArray(fm, "tags");
const blogDataFile = join(root, cfg.paths.blogDataFile);
const known = readSlugs(blogDataFile);
if (author && !known.authors.has(author)) {
throw new Error(`author "${author}" is not in blog-data.js — add it first`);
}
const added = [];
if (category && !known.categories.has(category)) {
ensureEntry(blogDataFile, "categories", category, titleCase(category));
added.push(`category:${category}`);
}
for (const t of tags) {
if (!known.tags.has(t)) {
ensureEntry(blogDataFile, "tags", t, titleCase(t));
added.push(`tag:${t}`);
}
}
const dest = join(root, cfg.paths.blogContentDir, slug);
if (existsSync(dest)) throw new Error(`destination already exists: ${dest}`);
try {
renameSync(draftDir, dest);
} catch {
cpSync(draftDir, dest, { recursive: true });
rmSync(draftDir, { recursive: true, force: true });
}
const calendarPath = join(root, cfg.paths.calendar);
await updateEntry(
calendarPath,
slug,
dateOverride ? { status: "published", publishedAt: dateOverride } : { status: "published" }
);
await buildSite({ projectRoot: root, appDir: cfg.paths.appDir });
const out = join(root, "public", "blog", slug, "index.html");
if (!existsSync(out)) throw new Error(`expected output not found: ${out}`);
// Version the published content so the working tree stays clean for the
// Developer Console's git worktree/merge operations. Best-effort — a git
// hiccup must never keep already-built content off the live site.
const commit = await gitCommitPaths(
root,
[join(cfg.paths.blogContentDir, slug), cfg.paths.blogDataFile],
`content: publish ${slug}`
);
return { dest, url: `${cfg.site.url}/blog/${slug}/`, taxonomyAdded: added, commit };
}