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
46 lines
1.5 KiB
JavaScript
46 lines
1.5 KiB
JavaScript
// Generic exclusive file lock, same idiom as calendar.mjs but reusable for any
|
|
// critical section. Used for the global BUILD lock so cron builds (promoteDraft)
|
|
// and Developer Console builds (preview + publish) never run npm/astro
|
|
// concurrently — important on this memory-constrained box.
|
|
import { writeFileSync, openSync, closeSync, unlinkSync, statSync } from "node:fs";
|
|
|
|
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
|
|
/**
|
|
* Acquire an exclusive lockfile, run fn, always release.
|
|
* @param {string} lockPath absolute path to the lockfile
|
|
* @param {() => Promise<T>|T} fn critical section
|
|
* @param {{timeoutMs?: number, staleMs?: number}} [opts]
|
|
* @returns {Promise<T>}
|
|
*/
|
|
export async function withLock(lockPath, fn, { timeoutMs = 300000, staleMs = 15 * 60 * 1000 } = {}) {
|
|
const start = Date.now();
|
|
for (;;) {
|
|
try {
|
|
const fd = openSync(lockPath, "wx"); // exclusive create — fails if it exists
|
|
writeFileSync(lockPath, `${process.pid} ${new Date().toISOString()}`);
|
|
closeSync(fd);
|
|
break;
|
|
} catch {
|
|
try {
|
|
if (Date.now() - statSync(lockPath).mtimeMs > staleMs) {
|
|
unlinkSync(lockPath); // presumed orphaned
|
|
continue;
|
|
}
|
|
} catch {
|
|
/* lock vanished between failed create and stat — retry immediately */
|
|
}
|
|
if (Date.now() - start > timeoutMs) throw new Error(`lock timeout: ${lockPath}`);
|
|
await sleep(200);
|
|
}
|
|
}
|
|
try {
|
|
return await fn();
|
|
} finally {
|
|
try {
|
|
unlinkSync(lockPath);
|
|
} catch {
|
|
/* already gone */
|
|
}
|
|
}
|
|
}
|