diff --git a/marketing/podcast/SCORE.md b/marketing/podcast/SCORE.md index ea78fde663..f41d76cefd 100644 --- a/marketing/podcast/SCORE.md +++ b/marketing/podcast/SCORE.md @@ -16,7 +16,11 @@ loudnorm. Alongside the longform readings, **Aesthetic Computer Radio** — an automated ~2-minute episode: gather the last day of commit subjects (filtered, deduped, and REDACTED — client/confidential lanes never reach the model), write a -~300-word script via `claude -p` in the storytelling register, produce with +~300-word script in the storytelling register — via `claude -p`, or with +`DAILY_WRITER=ac` through the daily's own AC braincells on Sonnet +(`lib/braincell-writer.mjs`; `DAILY_BRAIN_HANDLE` + `DAILY_BRAIN_TOKEN_FILE` +name the account, `DAILY_BRAIN_MODEL` overrides the model; jasellite runs +this since the Claude Code subscription stopped serving it) — produce with `--bedstyle club --frame daily` (116 BPM four-on-the-floor bed), publish via Buzzsprout. `daily-YYYY-MM-DD` slugs are pattern-cleared in `lib/hosted.mjs`; the content guard is daily.mjs's redaction filter + prompt rules + word-count diff --git a/marketing/podcast/bin/daily.mjs b/marketing/podcast/bin/daily.mjs index 7737e2496c..1b6b7ded6b 100644 --- a/marketing/podcast/bin/daily.mjs +++ b/marketing/podcast/bin/daily.mjs @@ -2,8 +2,9 @@ // daily.mjs — the automated ~2-minute Aesthetic Computer Radio episode. // // gather — the last day of commit subjects (filtered, deduped, REDACTED) -// write — a ~300-word spoken script via `claude -p` in the monthly-essay -// storytelling register (scenes, first person, no salesmanship) +// write — a ~300-word spoken script in the monthly-essay storytelling +// register (scenes, first person, no salesmanship), by `claude -p` +// or, with DAILY_WRITER=ac, by the daily's own AC braincells // produce — bin/produce.mjs with the club bed + the daily frame // publish — bin/buzzsprout.mjs (public; --stage keeps it private for review) // mint — with DAILY_MINT=1, bin/daily-token.mjs mints it on hic et nunc @@ -136,18 +137,38 @@ author: @jeffrey The day's commit subjects: ${subjects.map((s) => `- ${s}`).join("\n")}`; -console.log("Writing script… (claude -p)"); -const w = spawnSync("claude", ["-p", "--model", "sonnet", "--output-format", "text", "--tools", ""], { - input: PROMPT, encoding: "utf8", timeout: 300000, maxBuffer: 1 << 22, -}); -if (w.status !== 0 || !w.stdout) { - // claude -p reports auth failures on STDOUT ("Failed to authenticate…"), so - // show both streams — a week of "no output" hid an expired token once. - const said = [w.stderr, w.stdout].filter(Boolean).join(" | ").trim() || "no output"; - console.error(`✗ script generation failed (exit ${w.status}): ${said.slice(0, 400)}`); - process.exit(1); +// Two writers, same prompt. DAILY_WRITER=ac spends the daily's own AC +// braincells (lib/braincell-writer.mjs) — the appliance's path since the +// Claude Code subscription stopped serving `claude -p` there on 2026-10-16. +// Anything else keeps `claude -p` for a Mac with a working login. +let written; +if (process.env.DAILY_WRITER === "ac") { + console.log(`Writing script… (AC braincells, @${String(process.env.DAILY_BRAIN_HANDLE || "").replace(/^@/, "")})`); + const { braincellText } = await import("../lib/braincell-writer.mjs"); + try { + written = await braincellText(PROMPT, { + file: process.env.DAILY_BRAIN_TOKEN_FILE, handle: process.env.DAILY_BRAIN_HANDLE, + ...(process.env.DAILY_BRAIN_MODEL ? { model: process.env.DAILY_BRAIN_MODEL } : {}), + }); + } catch (err) { + console.error(`✗ script generation failed: ${err.message}`); + process.exit(1); + } +} else { + console.log("Writing script… (claude -p)"); + const w = spawnSync("claude", ["-p", "--model", "sonnet", "--output-format", "text", "--tools", ""], { + input: PROMPT, encoding: "utf8", timeout: 300000, maxBuffer: 1 << 22, + }); + if (w.status !== 0 || !w.stdout) { + // claude -p reports auth failures on STDOUT ("Failed to authenticate…"), so + // show both streams — a week of "no output" hid an expired token once. + const said = [w.stderr, w.stdout].filter(Boolean).join(" | ").trim() || "no output"; + console.error(`✗ script generation failed (exit ${w.status}): ${said.slice(0, 400)}`); + process.exit(1); + } + written = w.stdout; } -let script = w.stdout.trim(); +let script = written.trim(); // Some wrappers fence the output; unwrap one fence if present. script = script.replace(/^```(?:markdown|md)?\n([\s\S]*?)\n```$/m, "$1").trim(); // And drop any preamble the model put ahead of the frontmatter ("here's the diff --git a/marketing/podcast/lib/braincell-writer.mjs b/marketing/podcast/lib/braincell-writer.mjs new file mode 100644 index 0000000000..8a0171ee65 --- /dev/null +++ b/marketing/podcast/lib/braincell-writer.mjs @@ -0,0 +1,69 @@ +import { freshSession } from "../../../shared/ac-token.mjs"; + +// The same metered endpoint Aesel uses, with no file or publishing tools. +// An explicit session and server-verified handle bill the selected AC account. +// The Tezos signing key is not used for inference. +// +// The daily was written by `claude -p --model sonnet` until the Claude Code +// subscription stopped serving the appliance (2026-10-16); the same register +// comes from Sonnet through AC's own OpenRouter account, paid in braincells. +export const DAILY_BRAIN_MODEL = "anthropic/claude-sonnet-5.5"; + +export async function braincellText(prompt, { + file, handle, model = DAILY_BRAIN_MODEL, fetch = globalThis.fetch, session = freshSession, + timeoutMs = 180_000, +} = {}) { + if (!file || !handle) throw new Error("Set DAILY_BRAIN_TOKEN_FILE and DAILY_BRAIN_HANDLE for the daily's AC account"); + const expected = handle.replace(/^@/, ""); + const { access_token: token } = await session({ file }); + if (!token) throw new Error("The daily's AC session has no access token"); + const headers = { Authorization: `Bearer ${token}`, "Content-Type": "application/json" }; + const base = "https://aesthetic.computer/api"; + const balance = await fetch(`${base}/easel-credits`, { headers, signal: AbortSignal.timeout(15_000) }); + if (!balance.ok) throw new Error(`Cannot verify the daily's braincells (HTTP ${balance.status})`); + const credits = await balance.json(); + if (credits.handle !== `@${expected}`) throw new Error(`Daily account mismatch: expected @${expected}`); + if (![credits.remaining, credits.purchased].every(n => Number.isFinite(n) && n >= 0)) throw new Error("Daily braincell balance is unavailable"); + if (credits.remaining + credits.purchased <= 0) throw new Error(`@${expected} has no braincells available`); + + const response = await fetch(`${base}/easel-inference`, { + method: "POST", headers, signal: AbortSignal.timeout(timeoutMs), + body: JSON.stringify({ model, messages: [{ role: "user", content: prompt }], + max_tokens: 2048, thinking: { type: "disabled" } }), + }); + if (!response.ok) throw new Error(`Daily braincell inference failed (HTTP ${response.status})`); + if (!response.body) throw new Error("Daily braincell inference returned no stream"); + const reader = response.body.getReader(), decoder = new TextDecoder(); + let pending = "", text = "", stopped = false, reason = "", bytes = 0; + const line = value => { + if (!value.startsWith("data:")) return; + const payload = value.slice(5).trim(); + if (payload === "[DONE]") return; + const event = JSON.parse(payload); + if (event.type === "error") throw new Error("Daily braincell inference reported a stream error"); + if (event.type === "content_block_start" && event.content_block?.type === "tool_use") throw new Error("Daily writer unexpectedly requested a tool"); + if (event.type === "content_block_start" && event.content_block?.type === "text") text += event.content_block.text || ""; + if (event.type === "content_block_delta" && event.delta?.type === "text_delta") text += event.delta.text; + if (event.type === "message_delta") reason = event.delta?.stop_reason || reason; + if (event.type === "message_stop") stopped = true; + }; + try { + for (;;) { + const { done, value } = await reader.read(); + if (done) break; + bytes += value.byteLength; + if (bytes > 1_048_576) throw new Error("Daily writer exceeded its response limit"); + pending += decoder.decode(value, { stream: true }); + const lines = pending.split("\n"); + pending = lines.pop(); + for (const value of lines) line(value.trimEnd()); + } + pending += decoder.decode(); + if (pending.trim()) line(pending.trimEnd()); + if (!stopped || reason !== "end_turn" || !text.trim()) throw new Error("Daily writer returned an incomplete script; nothing saved"); + return text.trim(); + } finally { + await reader.cancel().catch(() => {}); + reader.releaseLock(); + } +} diff --git a/marketing/podcast/test/braincell-writer.test.mjs b/marketing/podcast/test/braincell-writer.test.mjs new file mode 100644 index 0000000000..db6dd05353 --- /dev/null +++ b/marketing/podcast/test/braincell-writer.test.mjs @@ -0,0 +1,70 @@ +import { test } from "node:test"; +import assert from "node:assert/strict"; +import { braincellText, DAILY_BRAIN_MODEL } from "../lib/braincell-writer.mjs"; + +const session = async () => ({ access_token: "test-only" }); +const sse = (events) => new Response(events.map((e) => `data: ${JSON.stringify(e)}\n\n`).join(""), { status: 200 }); +const credits = (over = {}) => new Response(JSON.stringify({ handle: "@jeffrey", remaining: 40, purchased: 0, ...over }), { status: 200 }); +const script = [ + { type: "message_start", message: { usage: { input_tokens: 10 } } }, + { type: "content_block_start", index: 0, content_block: { type: "text", text: "---\n" } }, + { type: "content_block_delta", index: 0, delta: { type: "text_delta", text: "title: a quiet night\n---\n\n" } }, + { type: "content_block_delta", index: 0, delta: { type: "text_delta", text: "The oven hummed." } }, + { type: "message_delta", delta: { stop_reason: "end_turn" }, usage: { output_tokens: 20 } }, + { type: "message_stop" }, +]; + +function fetcher({ credit = credits(), stream = sse(script), calls = [] } = {}) { + return async (url, init) => { + calls.push({ url, init }); + if (url.endsWith("/easel-credits")) return credit; + if (url.endsWith("/easel-inference")) return stream; + throw new Error(`unexpected ${url}`); + }; +} + +test("writes the script through the daily's own braincells on Sonnet", async () => { + const calls = []; + const text = await braincellText("write it", { file: "/x", handle: "@jeffrey", session, fetch: fetcher({ calls }) }); + assert.equal(text, "---\ntitle: a quiet night\n---\n\nThe oven hummed."); + const inference = calls.find((c) => c.url.endsWith("/easel-inference")); + const body = JSON.parse(inference.init.body); + assert.equal(body.model, DAILY_BRAIN_MODEL); + assert.deepEqual(body.thinking, { type: "disabled" }); + assert.equal(inference.init.headers.Authorization, "Bearer test-only"); + assert.equal(body.messages[0].content, "write it"); +}); + +test("a chosen model rides along", async () => { + const calls = []; + await braincellText("write it", { file: "/x", handle: "jeffrey", model: "anthropic/claude-opus-5.5", session, fetch: fetcher({ calls }) }); + assert.equal(JSON.parse(calls[1].init.body).model, "anthropic/claude-opus-5.5"); +}); + +test("refuses to bill a different handle than the one configured", async () => { + await assert.rejects( + braincellText("write it", { file: "/x", handle: "jeffrey", session, fetch: fetcher({ credit: credits({ handle: "@someone" }) }) }), + /Daily account mismatch/, + ); +}); + +test("refuses when the account has no braincells", async () => { + await assert.rejects( + braincellText("write it", { file: "/x", handle: "jeffrey", session, fetch: fetcher({ credit: credits({ remaining: 0, purchased: 0 }) }) }), + /no braincells/, + ); +}); + +test("an incomplete stream saves nothing", async () => { + const cut = sse(script.slice(0, 3)); + await assert.rejects(braincellText("write it", { file: "/x", handle: "jeffrey", session, fetch: fetcher({ stream: cut }) }), /incomplete script/); +}); + +test("a tool request is refused — the writer has no tools", async () => { + const tool = sse([{ type: "content_block_start", index: 0, content_block: { type: "tool_use", name: "write_file" } }]); + await assert.rejects(braincellText("write it", { file: "/x", handle: "jeffrey", session, fetch: fetcher({ stream: tool }) }), /requested a tool/); +}); + +test("missing configuration is named", async () => { + await assert.rejects(braincellText("write it", { session, fetch: fetcher() }), /DAILY_BRAIN_TOKEN_FILE and DAILY_BRAIN_HANDLE/); +});