bostrat-node 1.17.5 → 1.17.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,17 +1,22 @@
1
1
  #!/usr/bin/env node
2
- var I=process.env.BOSTRAT_AGENT_URL||`http://127.0.0.1:${process.env.BOSTRAT_AGENT_PORT||3362}`,d=["usage: bostrat-replay census [--rows] [--json] [--budget <ms>] [--once]"," bostrat-replay spec frame <source> [--json]",' bostrat-replay spec draft <source> (--statement "<text>" | --statement-file <path>) [--suite "<cmd>"] [--note "<why>"]',' bostrat-replay spec revise <spec> (--statement "<text>" | --statement-file <path>) [--suite "<cmd>"] [--note "<what changed>"]'," bostrat-replay spec ls [--status drafted|approved|dismissed] [--json]"," bostrat-replay spec show <spec> [--json]"," bostrat-replay run <spec> [--provider claude|codex|cursor] [--model <id>] [--cap-usd 30] [--cap-active 75m] [--cap-wall 3h] [--keep] [--no-wait] [--json]"," bostrat-replay runs [--status running|finished] [--json]"," bostrat-replay runs show <run> [--json]"," bostrat-replay runs stop <run>"].join(`
3
- `);function r(e){console.error(`[bostrat-replay] ${e}`),process.exit(1)}async function h(e,o,s){let t=await fetch(`${I}${o}`,{method:e,headers:s?{"content-type":"application/json"}:void 0,body:s?JSON.stringify(s):void 0}),a=await t.json().catch(()=>({}));if(!t.ok){let n=new Error(a.error||`HTTP ${t.status}`);throw n.status=t.status,n.data=a,n}return a}var $=e=>h("GET",e),E=new Set(["rows","json","once","keep","no-wait"]),M=new Set(["budget","statement","statement-file","suite","note","status","provider","model","cap-usd","cap-active","cap-wall"]);function f(e){let o={_:[]};for(let s=0;s<e.length;s++){let t=e[s];if(t.startsWith("--")){let a=t.slice(2);E.has(a)?o[a]=!0:M.has(a)?(s+1>=e.length&&r(`${t} needs a value
4
- ${d}`),o[a]=e[++s]):r(`unknown flag ${t}
5
- ${d}`)}else o._.push(t)}return o}var p=e=>{let o=Math.round((Number(e)||0)/6e4);return o>=60?`${(o/60).toFixed(1)}h`:`${o}m`},A=(e,o)=>o?`${Math.round(100*e/o)}%`:"\u2013",v=e=>String(e||"").slice(0,8)||"\u2013",O=e=>e?new Date(e).toISOString().slice(0,10):"\u2013",C=(e,o=96)=>{let s=String(e||"").replace(/\s+/g," ").trim();return s.length>o?`${s.slice(0,o-1)}\u2026`:s};async function x(e){let o=Number.isFinite(Number(e.budget))&&Number(e.budget)>0?Number(e.budget):8e3,s=e.rows?"1":"0",t;for(let i=0;i<120&&(t=await $(`/api/usage/replay-census?budgetMs=${o}&rows=${s}`),!(!t.partial||e.once));i++)process.stderr.write(`[bostrat-replay] census in progress \u2014 ${t.pending} still pending (${t.judged} judged)\r`);if(t||r("no answer from the agent"),e.json){console.log(JSON.stringify(t,null,2));return}let a=t.tracks,n=t.criteria,c=t.excluded;console.log(`[bostrat-replay] ${t.label}${t.partial?` \u2014 PARTIAL, ${t.pending} pending (run again)`:""}`),console.log(` eligible: ${t.eligible} of ${t.merged} merged archived Tracks (${A(t.eligible,t.merged)}) \u2014 ${a.archived} archived on this node, ${a.open} open, ${a.loops} loop runs excluded, ${a.unreadable} unreadable`),console.log(` funnel (each criterion counted on its own, over the ${t.judged} judged):`),console.log(` merged PR ${n.mergedPr}`),console.log(` recoverable base ${n.recoverableBase} (not: ${c.baseNotRecoverable}${Object.keys(t.baseReasons).length?" \u2014 "+Object.entries(t.baseReasons).map(([i,l])=>`${i} ${l}`).join(", "):""})`),console.log(` tests touched ${n.testsTouched} (not: ${c.noTestsTouched} of those with a base)`),console.log(` no ops/deploy step ${n.noOpsStep} (not: ${c.opsStep}${Object.keys(t.opsRules).length?" \u2014 "+Object.entries(t.opsRules).map(([i,l])=>`${i} ${l}`).join(", "):""})`),console.log(` not merged (archived without a merged PR): ${c.notMerged}`);let u=Object.entries(t.byRepo);if(u.length){console.log(" by repo:");for(let[i,l]of u)console.log(` ${i.padEnd(32)} merged ${String(l.merged).padStart(4)} eligible ${String(l.eligible).padStart(4)} (base ${l.baseNotRecoverable} \xB7 tests ${l.noTestsTouched} \xB7 ops ${l.opsStep})`)}let S=Object.entries(t.byCategory);S.length&&console.log(` eligible by category: ${S.map(([i,l])=>`${i} ${l}`).join(" \xB7 ")}`);let j=Object.entries(t.byModel);if(j.length&&console.log(` eligible by model: ${j.map(([i,l])=>`${i} ${l}`).join(" \xB7 ")}`),e.rows&&Array.isArray(t.rows)){console.log(` eligible Tracks (${t.rows.length}):`);for(let i of t.rows)console.log(` ${i.repo}#${i.pr} ${String(i.name||i.trackId).slice(0,48).padEnd(48)} ${i.category||"\u2013"} ${i.model||i.provider||"\u2013"} active ${p(i.activeMs)} tests ${i.tests}/${i.files} base ${v(i.base)} ${i.trackId}`)}console.log(` basis: ${t.basis.label}; ${t.basis.scope}`),console.log(` no ops/deploy step: ${t.basis.noOpsStep}`)}async function P(e){let o;for(let s=0;s<40&&(o=await $(`/api/replay/frame?source=${encodeURIComponent(e)}&budgetMs=15000`),!!o.partial);s++)process.stderr.write(`[bostrat-replay] reading the archived logs \u2014 ${o.pending} still pending\r`);return(!o||o.partial)&&r("the archived logs are still being read \u2014 run again"),o}function y(e,o=" "){console.log(`${o}source: ${e.repo}#${e.pr} \u2014 Track \u201C${e.trackName||e.trackId}\u201D (${e.trackId})`),console.log(`${o} merged ${O(e.mergedAt)} at ${v(e.mergeCommit)} \xB7 base ${v(e.base)} (the commit a sealed clone is cut at)`),console.log(`${o} ${e.category||"uncategorized"} \xB7 ${e.model||e.provider||"\u2013"} \xB7 agent-active ${p(e.activeMs)} \xB7 wall ${p(e.wallMs)} \xB7 ${e.prompts} operator prompt${e.prompts===1?"":"s"} \xB7 $${(Number(e.usd)||0).toFixed(2)} notional`)}async function _(e){let o=e._[0];o||r(`spec frame needs a <source>
6
- ${d}`);let s=await P(o);if(e.json){console.log(JSON.stringify(s,null,2));return}if(console.log(`[bostrat-replay] ${s.label||"replay task spec"} \u2014 frame for ${o}`),!s.eligible){console.log(` NOT replay-eligible: ${s.reasons.join(", ")}`),s.source&&y(s.source),console.log(" a spec cannot be drafted from this Track (R11: no acceptance tests, or an ops step a sealed clone cannot replay)");return}y(s.source),console.log(` acceptance: ${s.acceptance.tests.length} test path${s.acceptance.tests.length===1?"":"s"} the PR touched (of ${s.acceptance.files} files):`);for(let a of s.acceptance.tests)console.log(` ${a}`);let t=s.promptNotes||{};console.log(` operator prompts, verbatim and in order (${s.prompts.length}${t.echoesDropped?`; ${t.echoesDropped} transcript echo${t.echoesDropped===1?"":"es"} dropped`:""}${t.truncated?`; ${t.truncated} cut at 16 KB`:""}${t.omitted?`; ${t.omitted} beyond the first 200 omitted`:""}):`),s.prompts.forEach((a,n)=>{console.log(` \u2500\u2500 ${n+1}${n===0?" (the opening ask)":" (follow-up \u2014 NOT replayed)"} \xB7 ${new Date(a.at).toISOString()} \xB7 ${a.box||"\u2013"}${a.truncated?" \xB7 truncated":""}`),console.log(a.text.split(`
7
- `).map(c=>` \u2502 ${c}`).join(`
8
- `))}),console.log(" next: write the STATEMENT \u2014 the standalone task a replay box gets instead of this conversation (fold what the follow-ups settled into it; name the outcome the merged PR delivered, never the conversation) \u2014 and hand it in:"),console.log(` bostrat-replay spec draft ${o} --statement-file <path> [--suite "<the repo's suite command>"]`)}async function N(e){if(e.statement&&e["statement-file"]&&r("give --statement OR --statement-file, not both"),e["statement-file"]){let{readFile:o}=await import("node:fs/promises");try{return await o(e["statement-file"],"utf8")}catch(s){r(`cannot read ${e["statement-file"]}: ${s?.message||s}`)}}return e.statement||r(`a statement is required: --statement "<text>" or --statement-file <path>
9
- ${d}`),e.statement}function k(e){let o=e.versions[e.versions.length-1],s=e.approvedVersion!=null?`approved v${e.approvedVersion}`:"not approved";return console.log(`[bostrat-replay] spec ${e.id} v${e.version} \u2014 ${e.status} (${s}) \u2014 ${e.source.repo}#${e.source.pr} \u201C${e.source.trackName||e.source.trackId}\u201D`),o}async function L(e){let o=e._[0];o||r(`spec draft needs a <source>
10
- ${d}`);let s=await N(e),t;try{t=await h("POST","/api/replay/specs",{cwd:process.cwd(),source:o,statement:s,suite:e.suite??null,note:e.note??null})}catch(n){n.status===503&&n.data?.partial&&r(`${n.message}`),r(n.message)}let a=t.spec;k(a),console.log(` v1 drafted \u2014 the approval card is in this Track's chat (${a.acceptance.tests.length} acceptance test path${a.acceptance.tests.length===1?"":"s"}, ${a.prompts.length} original prompt${a.prompts.length===1?"":"s"} stored verbatim).`),console.log(" This is a BLOCKING prompt: stop and end your turn. The spec enters the bench only when the operator approves this version; to change it, `bostrat-replay spec revise "+a.id+" \u2026` (a new version, a fresh card).")}async function U(e){let o=e._[0];o||r(`spec revise needs a <spec>
11
- ${d}`);let s=await $(`/api/replay/specs/${encodeURIComponent(o)}`).catch(u=>r(u.message)),t=await N(e),a={cwd:process.cwd(),statement:t,note:e.note??null};e.suite!==void 0&&(a.suite=e.suite);let n;try{n=await h("POST",`/api/replay/specs/${encodeURIComponent(s.spec.id)}/revise`,a)}catch(u){r(u.message)}let c=n.spec;k(c),console.log(` v${c.version} drafted \u2014 a fresh approval card is in this Track's chat${c.approvedVersion!=null?`; v${c.approvedVersion} stays the bench entry until this one is approved`:""}.`),console.log(" This is a BLOCKING prompt: stop and end your turn.")}async function B(e){let{specs:o}=await $(`/api/replay/specs${e.status?`?status=${encodeURIComponent(e.status)}`:""}`);if(e.json){console.log(JSON.stringify(o,null,2));return}if(!o.length){console.log("[bostrat-replay] no task specs on this node yet \u2014 `bostrat-replay census --rows` lists the eligible sources");return}let s={drafted:0,approved:0,dismissed:0};for(let t of o)s[t.status]=(s[t.status]||0)+1;console.log(`[bostrat-replay] ${o.length} task spec${o.length===1?"":"s"} on this node \u2014 ${s.approved} approved (the bench) \xB7 ${s.drafted} awaiting approval \xB7 ${s.dismissed} dismissed`);for(let t of o){let a=t.versions[t.versions.length-1],n=t.status==="approved"?"+":t.status==="drafted"?"?":"-";console.log(`${n} ${t.id} v${t.version}${t.approvedVersion!=null&&t.approvedVersion!==t.version?` (approved v${t.approvedVersion})`:""} ${`${t.source.repo}#${t.source.pr}`.padEnd(28)} ${(t.source.category||"\u2013").padEnd(14)} ${(t.source.model||t.source.provider||"\u2013").padEnd(20)} active ${p(t.source.activeMs).padStart(5)} tests ${String(t.acceptance.tests.length).padStart(2)} ${C(a.statement,60)}`)}}async function q(e){let o=e._[0];o||r(`spec show needs a <spec>
12
- ${d}`);let{spec:s}=await $(`/api/replay/specs/${encodeURIComponent(o)}`).catch(t=>r(t.message));if(e.json){console.log(JSON.stringify(s,null,2));return}k(s),y(s.source),console.log(` acceptance: ${s.acceptance.tests.length} test path${s.acceptance.tests.length===1?"":"s"} (of ${s.acceptance.files} files the PR changed)${s.versions[s.versions.length-1].suite?` \xB7 suite: ${s.versions[s.versions.length-1].suite}`:""}`);for(let t of s.acceptance.tests)console.log(` ${t}`);console.log(` versions (${s.versions.length}):`);for(let t of s.versions)console.log(` \u2500\u2500 v${t.v} \xB7 ${t.outcome}${t.v===s.approvedVersion?" \xB7 THE BENCH ENTRY":""} \xB7 ${new Date(t.createdAt).toISOString()} \xB7 by ${t.by?.agent||"the lead"} on Track \u201C${t.by?.trackName||t.by?.trackId||"\u2013"}\u201D${t.note?` \xB7 ${t.note}`:""}${t.suite?` \xB7 suite: ${t.suite}`:""}`),console.log(t.statement.split(`
2
+ var M=process.env.BOSTRAT_AGENT_URL||`http://127.0.0.1:${process.env.BOSTRAT_AGENT_PORT||3362}`,$=["usage: bostrat-replay census [--rows] [--json] [--budget <ms>] [--once]"," bostrat-replay spec frame <source> [--json]",' bostrat-replay spec draft <source> (--statement "<text>" | --statement-file <path>) [--suite "<cmd>"] [--note "<why>"]',' bostrat-replay spec revise <spec> (--statement "<text>" | --statement-file <path>) [--suite "<cmd>"] [--note "<what changed>"]'," bostrat-replay spec ls [--status drafted|approved|dismissed] [--json]"," bostrat-replay spec show <spec> [--json]"," bostrat-replay run <spec> [--provider claude|codex|cursor] [--model <id>] [--cap-usd 30] [--cap-active 75m] [--cap-wall 3h] [--keep] [--no-wait] [--no-gate] [--json]"," bostrat-replay runs [--status running|finished] [--json]"," bostrat-replay runs show <run> [--json]"," bostrat-replay runs stop <run>"," bostrat-replay gate [--provider claude|codex|cursor] [--model <id>] [--cached] [--json]"," bostrat-replay gate set <provider> --weekly-runs <n>"," bostrat-replay skips [--provider <p>] [--since <days>] [--json]"," bostrat-replay queue [--provider <p>] [--status queued|running|done] [--json]"," bostrat-replay queue add <spec> [--provider claude|codex|cursor] [--model <id>[,<id>\u2026]] [--cap-usd 30] [--cap-active 75m]"," bostrat-replay queue show <item> [--json]"," bostrat-replay queue rm <item>"," bostrat-replay queue retry <item>"," bostrat-replay queue resume <provider>"," bostrat-replay next [--provider claude|codex|cursor] [--cap-usd 30] [--cap-active 75m] [--cap-wall 3h] [--no-gate] [--no-wait] [--json]"].join(`
3
+ `);function c(e){console.error(`[bostrat-replay] ${e}`),process.exit(1)}async function y(e,o,s){let t=await fetch(`${M}${o}`,{method:e,headers:s?{"content-type":"application/json"}:void 0,body:s?JSON.stringify(s):void 0}),a=await t.json().catch(()=>({}));if(!t.ok){let n=new Error(a.error||`HTTP ${t.status}`);throw n.status=t.status,n.data=a,n}return a}var h=e=>y("GET",e),U=new Set(["rows","json","once","keep","no-wait","no-gate","cached"]),A=new Set(["budget","statement","statement-file","suite","note","status","provider","model","cap-usd","cap-active","cap-wall","weekly-runs","since"]);function b(e){let o={_:[]};for(let s=0;s<e.length;s++){let t=e[s];if(t.startsWith("--")){let a=t.slice(2);U.has(a)?o[a]=!0:A.has(a)?(s+1>=e.length&&c(`${t} needs a value
4
+ ${$}`),o[a]=e[++s]):c(`unknown flag ${t}
5
+ ${$}`)}else o._.push(t)}return o}var u=e=>{let o=Math.round((Number(e)||0)/6e4);return o>=60?`${(o/60).toFixed(1)}h`:`${o}m`},D=(e,o)=>o?`${Math.round(100*e/o)}%`:"\u2013",q=e=>String(e||"").slice(0,8)||"\u2013",P=e=>e?new Date(e).toISOString().slice(0,10):"\u2013",C=(e,o=96)=>{let s=String(e||"").replace(/\s+/g," ").trim();return s.length>o?`${s.slice(0,o-1)}\u2026`:s};async function _(e){let o=Number.isFinite(Number(e.budget))&&Number(e.budget)>0?Number(e.budget):8e3,s=e.rows?"1":"0",t;for(let l=0;l<120&&(t=await h(`/api/usage/replay-census?budgetMs=${o}&rows=${s}`),!(!t.partial||e.once));l++)process.stderr.write(`[bostrat-replay] census in progress \u2014 ${t.pending} still pending (${t.judged} judged)\r`);if(t||c("no answer from the agent"),e.json){console.log(JSON.stringify(t,null,2));return}let a=t.tracks,n=t.criteria,r=t.excluded;console.log(`[bostrat-replay] ${t.label}${t.partial?` \u2014 PARTIAL, ${t.pending} pending (run again)`:""}`),console.log(` eligible: ${t.eligible} of ${t.merged} merged archived Tracks (${D(t.eligible,t.merged)}) \u2014 ${a.archived} archived on this node, ${a.open} open, ${a.loops} loop runs excluded, ${a.unreadable} unreadable`),console.log(` funnel (each criterion counted on its own, over the ${t.judged} judged):`),console.log(` merged PR ${n.mergedPr}`),console.log(` recoverable base ${n.recoverableBase} (not: ${r.baseNotRecoverable}${Object.keys(t.baseReasons).length?" \u2014 "+Object.entries(t.baseReasons).map(([l,p])=>`${l} ${p}`).join(", "):""})`),console.log(` tests touched ${n.testsTouched} (not: ${r.noTestsTouched} of those with a base)`),console.log(` no ops/deploy step ${n.noOpsStep} (not: ${r.opsStep}${Object.keys(t.opsRules).length?" \u2014 "+Object.entries(t.opsRules).map(([l,p])=>`${l} ${p}`).join(", "):""})`),console.log(` not merged (archived without a merged PR): ${r.notMerged}`);let i=Object.entries(t.byRepo);if(i.length){console.log(" by repo:");for(let[l,p]of i)console.log(` ${l.padEnd(32)} merged ${String(p.merged).padStart(4)} eligible ${String(p.eligible).padStart(4)} (base ${p.baseNotRecoverable} \xB7 tests ${p.noTestsTouched} \xB7 ops ${p.opsStep})`)}let d=Object.entries(t.byCategory);d.length&&console.log(` eligible by category: ${d.map(([l,p])=>`${l} ${p}`).join(" \xB7 ")}`);let f=Object.entries(t.byModel);if(f.length&&console.log(` eligible by model: ${f.map(([l,p])=>`${l} ${p}`).join(" \xB7 ")}`),e.rows&&Array.isArray(t.rows)){console.log(` eligible Tracks (${t.rows.length}):`);for(let l of t.rows)console.log(` ${l.repo}#${l.pr} ${String(l.name||l.trackId).slice(0,48).padEnd(48)} ${l.category||"\u2013"} ${l.model||l.provider||"\u2013"} active ${u(l.activeMs)} tests ${l.tests}/${l.files} base ${q(l.base)} ${l.trackId}`)}console.log(` basis: ${t.basis.label}; ${t.basis.scope}`),console.log(` no ops/deploy step: ${t.basis.noOpsStep}`)}async function B(e){let o;for(let s=0;s<40&&(o=await h(`/api/replay/frame?source=${encodeURIComponent(e)}&budgetMs=15000`),!!o.partial);s++)process.stderr.write(`[bostrat-replay] reading the archived logs \u2014 ${o.pending} still pending\r`);return(!o||o.partial)&&c("the archived logs are still being read \u2014 run again"),o}function R(e,o=" "){console.log(`${o}source: ${e.repo}#${e.pr} \u2014 Track \u201C${e.trackName||e.trackId}\u201D (${e.trackId})`),console.log(`${o} merged ${P(e.mergedAt)} at ${q(e.mergeCommit)} \xB7 base ${q(e.base)} (the commit a sealed clone is cut at)`),console.log(`${o} ${e.category||"uncategorized"} \xB7 ${e.model||e.provider||"\u2013"} \xB7 agent-active ${u(e.activeMs)} \xB7 wall ${u(e.wallMs)} \xB7 ${e.prompts} operator prompt${e.prompts===1?"":"s"} \xB7 $${(Number(e.usd)||0).toFixed(2)} notional`)}async function L(e){let o=e._[0];o||c(`spec frame needs a <source>
6
+ ${$}`);let s=await B(o);if(e.json){console.log(JSON.stringify(s,null,2));return}if(console.log(`[bostrat-replay] ${s.label||"replay task spec"} \u2014 frame for ${o}`),!s.eligible){console.log(` NOT replay-eligible: ${s.reasons.join(", ")}`),s.source&&R(s.source),console.log(" a spec cannot be drafted from this Track (R11: no acceptance tests, or an ops step a sealed clone cannot replay)");return}R(s.source),console.log(` acceptance: ${s.acceptance.tests.length} test path${s.acceptance.tests.length===1?"":"s"} the PR touched (of ${s.acceptance.files} files):`);for(let a of s.acceptance.tests)console.log(` ${a}`);let t=s.promptNotes||{};console.log(` operator prompts, verbatim and in order (${s.prompts.length}${t.echoesDropped?`; ${t.echoesDropped} transcript echo${t.echoesDropped===1?"":"es"} dropped`:""}${t.truncated?`; ${t.truncated} cut at 16 KB`:""}${t.omitted?`; ${t.omitted} beyond the first 200 omitted`:""}):`),s.prompts.forEach((a,n)=>{console.log(` \u2500\u2500 ${n+1}${n===0?" (the opening ask)":" (follow-up \u2014 NOT replayed)"} \xB7 ${new Date(a.at).toISOString()} \xB7 ${a.box||"\u2013"}${a.truncated?" \xB7 truncated":""}`),console.log(a.text.split(`
7
+ `).map(r=>` \u2502 ${r}`).join(`
8
+ `))}),console.log(" next: write the STATEMENT \u2014 the standalone task a replay box gets instead of this conversation (fold what the follow-ups settled into it; name the outcome the merged PR delivered, never the conversation) \u2014 and hand it in:"),console.log(` bostrat-replay spec draft ${o} --statement-file <path> [--suite "<the repo's suite command>"]`)}async function E(e){if(e.statement&&e["statement-file"]&&c("give --statement OR --statement-file, not both"),e["statement-file"]){let{readFile:o}=await import("node:fs/promises");try{return await o(e["statement-file"],"utf8")}catch(s){c(`cannot read ${e["statement-file"]}: ${s?.message||s}`)}}return e.statement||c(`a statement is required: --statement "<text>" or --statement-file <path>
9
+ ${$}`),e.statement}function N(e){let o=e.versions[e.versions.length-1],s=e.approvedVersion!=null?`approved v${e.approvedVersion}`:"not approved";return console.log(`[bostrat-replay] spec ${e.id} v${e.version} \u2014 ${e.status} (${s}) \u2014 ${e.source.repo}#${e.source.pr} \u201C${e.source.trackName||e.source.trackId}\u201D`),o}async function J(e){let o=e._[0];o||c(`spec draft needs a <source>
10
+ ${$}`);let s=await E(e),t;try{t=await y("POST","/api/replay/specs",{cwd:process.cwd(),source:o,statement:s,suite:e.suite??null,note:e.note??null})}catch(n){n.status===503&&n.data?.partial&&c(`${n.message}`),c(n.message)}let a=t.spec;N(a),console.log(` v1 drafted \u2014 the approval card is in this Track's chat (${a.acceptance.tests.length} acceptance test path${a.acceptance.tests.length===1?"":"s"}, ${a.prompts.length} original prompt${a.prompts.length===1?"":"s"} stored verbatim).`),console.log(" This is a BLOCKING prompt: stop and end your turn. The spec enters the bench only when the operator approves this version; to change it, `bostrat-replay spec revise "+a.id+" \u2026` (a new version, a fresh card).")}async function F(e){let o=e._[0];o||c(`spec revise needs a <spec>
11
+ ${$}`);let s=await h(`/api/replay/specs/${encodeURIComponent(o)}`).catch(i=>c(i.message)),t=await E(e),a={cwd:process.cwd(),statement:t,note:e.note??null};e.suite!==void 0&&(a.suite=e.suite);let n;try{n=await y("POST",`/api/replay/specs/${encodeURIComponent(s.spec.id)}/revise`,a)}catch(i){c(i.message)}let r=n.spec;N(r),console.log(` v${r.version} drafted \u2014 a fresh approval card is in this Track's chat${r.approvedVersion!=null?`; v${r.approvedVersion} stays the bench entry until this one is approved`:""}.`),console.log(" This is a BLOCKING prompt: stop and end your turn.")}async function V(e){let{specs:o}=await h(`/api/replay/specs${e.status?`?status=${encodeURIComponent(e.status)}`:""}`);if(e.json){console.log(JSON.stringify(o,null,2));return}if(!o.length){console.log("[bostrat-replay] no task specs on this node yet \u2014 `bostrat-replay census --rows` lists the eligible sources");return}let s={drafted:0,approved:0,dismissed:0};for(let t of o)s[t.status]=(s[t.status]||0)+1;console.log(`[bostrat-replay] ${o.length} task spec${o.length===1?"":"s"} on this node \u2014 ${s.approved} approved (the bench) \xB7 ${s.drafted} awaiting approval \xB7 ${s.dismissed} dismissed`);for(let t of o){let a=t.versions[t.versions.length-1],n=t.status==="approved"?"+":t.status==="drafted"?"?":"-";console.log(`${n} ${t.id} v${t.version}${t.approvedVersion!=null&&t.approvedVersion!==t.version?` (approved v${t.approvedVersion})`:""} ${`${t.source.repo}#${t.source.pr}`.padEnd(28)} ${(t.source.category||"\u2013").padEnd(14)} ${(t.source.model||t.source.provider||"\u2013").padEnd(20)} active ${u(t.source.activeMs).padStart(5)} tests ${String(t.acceptance.tests.length).padStart(2)} ${C(a.statement,60)}`)}}async function G(e){let o=e._[0];o||c(`spec show needs a <spec>
12
+ ${$}`);let{spec:s}=await h(`/api/replay/specs/${encodeURIComponent(o)}`).catch(t=>c(t.message));if(e.json){console.log(JSON.stringify(s,null,2));return}N(s),R(s.source),console.log(` acceptance: ${s.acceptance.tests.length} test path${s.acceptance.tests.length===1?"":"s"} (of ${s.acceptance.files} files the PR changed)${s.versions[s.versions.length-1].suite?` \xB7 suite: ${s.versions[s.versions.length-1].suite}`:""}`);for(let t of s.acceptance.tests)console.log(` ${t}`);console.log(` versions (${s.versions.length}):`);for(let t of s.versions)console.log(` \u2500\u2500 v${t.v} \xB7 ${t.outcome}${t.v===s.approvedVersion?" \xB7 THE BENCH ENTRY":""} \xB7 ${new Date(t.createdAt).toISOString()} \xB7 by ${t.by?.agent||"the lead"} on Track \u201C${t.by?.trackName||t.by?.trackId||"\u2013"}\u201D${t.note?` \xB7 ${t.note}`:""}${t.suite?` \xB7 suite: ${t.suite}`:""}`),console.log(t.statement.split(`
13
13
  `).map(a=>` \u2502 ${a}`).join(`
14
- `));console.log(` original prompts stored verbatim: ${s.prompts.length} (the opening ask is what the statement replaces; follow-ups are not replayed) \u2014 \`spec show ${s.id} --json\` prints them`)}function T(e,o){let s=String(e??"").trim().match(/^(\d+(?:\.\d+)?)\s*(m|min|mins|minutes?|h|hr|hrs|hours?|d|days?)?$/i);s||r(`${o} wants a duration like 75m, 1.5h or 1d (got "${e}")`);let t=Number(s[1]),a=(s[2]||"m").toLowerCase(),n=a.startsWith("h")?t*36e5:a.startsWith("d")?t*8*36e5:t*6e4;return n>0||r(`${o} must be positive`),n}var b=e=>`$${(Number(e)||0).toFixed(2)}`,R={sealing:"sealing the clone",starting:"starting the box",running:"the agent is working",checking:"running the acceptance tests",closing:"archiving the box and pruning the clone",done:"done"};function w(e,{head:o=!0}={}){if(o&&console.log(`[bostrat-replay] run ${e.id} \u2014 ${e.status==="running"?`${e.status} \xB7 ${R[e.phase]||e.phase}`:e.outcome} \u2014 ${e.source.repo}#${e.source.pr} \xB7 spec ${e.specId} v${e.version} \xB7 ${e.model||e.provider}${e.trackId?` \xB7 Track ${e.trackId}`:""}`),console.log(` agent-active ${p(e.activeMs)} \xB7 wall ${p(e.wallMs)} \xB7 ${b(e.usd)} notional \xB7 ${e.turns} turn${e.turns===1?"":"s"} \xB7 ${e.toolCalls} tool call${e.toolCalls===1?"":"s"} \xB7 ${e.questions} question${e.questions===1?"":"s"} answered "use your judgment"`),e.source.activeMs!=null&&console.log(` the source Track took agent-active ${p(e.source.activeMs)} \xB7 ${b(e.source.usd)} on ${e.source.model||"\u2013"} (conversational actuals \u2014 a different quantity from this single-shot run, D7)`),e.cappedBy&&console.log(` CAPPED by ${e.cappedBy} (caps: ${b(e.caps.usd)} \xB7 active ${p(e.caps.activeMs)} \xB7 wall ${p(e.caps.wallMs)} \xB7 ${e.caps.questions} questions) \u2014 partial time and cost recorded (R24)`),e.error&&console.log(` error: ${e.error}`),e.acceptance){let s=e.check?.tests||[];console.log(` acceptance: ${e.acceptance.toUpperCase()} \u2014 ${s.filter(t=>t.status==="pass").length}/${s.length} test path${s.length===1?"":"s"} pass${e.acceptance==="unverified"?" (no test could run: excluded from pass-rate figures, R11)":""}`);for(let t of s)console.log(` ${t.status.padEnd(7)} ${t.path}${t.runner?` (${t.runner}, ${p(t.ms)})`:""}${t.reason?` \u2014 ${t.reason}`:""}`);e.check?.suite&&console.log(` suite: ${e.check.suite.status} \u2014 ${e.check.suite.cmd} (${p(e.check.suite.ms)})`);for(let t of e.check?.deps||[])console.log(` deps: ${t.status} \u2014 ${t.cmd} in ${t.dir} (${p(t.ms)})`)}e.status==="finished"&&console.log(` record: ${e.dir}/result.json${e.patchBytes!=null?` \xB7 result.patch (${e.patchBytes} bytes)`:""}${e.cloneRemoved?" \xB7 clone removed":" \xB7 clone kept"}`),console.log(` ${e.label}`)}async function D(e){let o=e._[0];o||r(`run needs a <spec>
15
- ${d}`);let s={};e["cap-usd"]!=null&&(s.usd=Number(e["cap-usd"]),s.usd>0||r("--cap-usd wants a positive dollar figure")),e["cap-active"]!=null&&(s.activeMs=T(e["cap-active"],"--cap-active")),e["cap-wall"]!=null&&(s.wallMs=T(e["cap-wall"],"--cap-wall"));let t;try{t=await h("POST","/api/replay/runs",{spec:o,provider:e.provider||"claude",model:e.model||null,caps:s,keep:!!e.keep})}catch(c){r(c.status===409?`${c.message} \u2014 \`bostrat-replay runs stop ${c.data?.runId||"<run>"}\` ends it`:c.message)}let a=t.run;if(e["no-wait"]){e.json?console.log(JSON.stringify(a,null,2)):(w(a),console.log(` running in the background \u2014 \`bostrat-replay runs show ${a.id}\` reads it`));return}let n=null;for(;a.status==="running";)!e.json&&a.phase!==n&&(n=a.phase,process.stderr.write(`[bostrat-replay] run ${a.id}: ${R[n]||n}${a.trackId?` (Track ${a.trackId})`:""}
16
- `)),await new Promise(c=>setTimeout(c,1e4)),a=(await $(`/api/replay/runs/${encodeURIComponent(a.id)}`)).run;e.json?console.log(JSON.stringify(a,null,2)):w(a)}async function F(e){let o=e._[0];if(o==="show"||o==="stop"){let n=e._[1];if(n||r(`runs ${o} needs a <run>
17
- ${d}`),o==="stop"){await h("POST",`/api/replay/runs/${encodeURIComponent(n)}/stop`).catch(u=>r(u.message)),console.log(`[bostrat-replay] run ${n}: stop requested \u2014 it is recorded as capped (stop) once the turn closes, then checked`);return}let{run:c}=await $(`/api/replay/runs/${encodeURIComponent(n)}`).catch(u=>r(u.message));e.json?console.log(JSON.stringify(c,null,2)):w(c);return}o&&r(d);let{runs:s,live:t}=await $(`/api/replay/runs${e.status?`?status=${encodeURIComponent(e.status)}`:""}`);if(e.json){console.log(JSON.stringify({runs:s,live:t},null,2));return}if(!s.length){console.log("[bostrat-replay] no replay runs on this node yet \u2014 `bostrat-replay run <spec>` starts one (spec ls lists the approved specs)");return}let a={};for(let n of s)a[n.status==="running"?"running":n.outcome]=(a[n.status==="running"?"running":n.outcome]||0)+1;console.log(`[bostrat-replay] ${s.length} replay run${s.length===1?"":"s"} on this node \u2014 ${Object.entries(a).map(([n,c])=>`${n} ${c}`).join(" \xB7 ")}${t?` \xB7 live: ${t.id}`:""}`);for(let n of s){let c=n.status==="running"?"~":n.outcome==="passed"?"+":n.outcome==="failed"?"-":n.outcome==="capped"?"c":n.outcome==="unverified"?"?":"!";console.log(`${c} ${n.id} ${O(n.startedAt)} ${(n.status==="running"?`running/${n.phase}`:n.outcome).padEnd(11)} ${`${n.source.repo}#${n.source.pr}`.padEnd(28)} spec ${n.specId} v${n.version} ${(n.model||n.provider).padEnd(16)} active ${p(n.activeMs).padStart(5)} ${b(n.usd).padStart(7)} q ${n.questions} ${n.acceptance||"\u2013"}`)}console.log(` ${s[0].label}`)}var g=process.argv.slice(2),m=g.shift();try{if(m==="census")await x(f(g));else if(m==="spec"){let e=g.shift(),o=f(g);e==="frame"?await _(o):e==="draft"?await L(o):e==="revise"?await U(o):e==="ls"?await B(o):e==="show"?await q(o):r(d)}else m==="run"?await D(f(g)):m==="runs"?await F(f(g)):r(d)}catch(e){r(e?.message||String(e))}
14
+ `));console.log(` original prompts stored verbatim: ${s.prompts.length} (the opening ask is what the statement replaces; follow-ups are not replayed) \u2014 \`spec show ${s.id} --json\` prints them`)}function k(e,o){let s=String(e??"").trim().match(/^(\d+(?:\.\d+)?)\s*(m|min|mins|minutes?|h|hr|hrs|hours?|d|days?)?$/i);s||c(`${o} wants a duration like 75m, 1.5h or 1d (got "${e}")`);let t=Number(s[1]),a=(s[2]||"m").toLowerCase(),n=a.startsWith("h")?t*36e5:a.startsWith("d")?t*8*36e5:t*6e4;return n>0||c(`${o} must be positive`),n}var m=e=>`$${(Number(e)||0).toFixed(2)}`,j={sealing:"sealing the clone",starting:"starting the box",running:"the agent is working",checking:"running the acceptance tests",closing:"archiving the box and pruning the clone",done:"done"};function S(e,{head:o=!0}={}){if(o&&console.log(`[bostrat-replay] run ${e.id} \u2014 ${e.status==="running"?`${e.status} \xB7 ${j[e.phase]||e.phase}`:e.outcome} \u2014 ${e.source.repo}#${e.source.pr} \xB7 spec ${e.specId} v${e.version} \xB7 ${e.model||e.provider}${e.trackId?` \xB7 Track ${e.trackId}`:""}`),console.log(` agent-active ${u(e.activeMs)} \xB7 wall ${u(e.wallMs)} \xB7 ${m(e.usd)} notional \xB7 ${e.turns} turn${e.turns===1?"":"s"} \xB7 ${e.toolCalls} tool call${e.toolCalls===1?"":"s"} \xB7 ${e.questions} question${e.questions===1?"":"s"} answered "use your judgment"`),e.source.activeMs!=null&&console.log(` the source Track took agent-active ${u(e.source.activeMs)} \xB7 ${m(e.source.usd)} on ${e.source.model||"\u2013"} (conversational actuals \u2014 a different quantity from this single-shot run, D7)`),e.gate?console.log(` headroom gate: passed at ${new Date(e.gate.at).toISOString()} \u2014 weekly meter ${e.gate.weekPct??"\u2013"}%${e.gate.sessionPct!=null?` \xB7 session ${e.gate.sessionPct}%`:""} \xB7 replay spend $${e.gate.replaySpendUsd??0} of $${e.gate.budgetUsd??"\u2013"} budget at $${e.gate.usdPerPoint??"\u2013"}/point (${e.gate.calibration||"\u2013"})${e.gate.spendDown?" \xB7 spend-down window (D16)":""}`):e.gate===null&&e.caps&&console.log(" headroom gate: not read \u2014 started with --no-gate"),e.cappedBy&&console.log(` CAPPED by ${e.cappedBy} (caps: ${m(e.caps.usd)} \xB7 active ${u(e.caps.activeMs)} \xB7 wall ${u(e.caps.wallMs)} \xB7 ${e.caps.questions} questions) \u2014 partial time and cost recorded (R24)`),e.error&&console.log(` error: ${e.error}`),e.acceptance){let s=e.check?.tests||[];console.log(` acceptance: ${e.acceptance.toUpperCase()} \u2014 ${s.filter(t=>t.status==="pass").length}/${s.length} test path${s.length===1?"":"s"} pass${e.acceptance==="unverified"?" (no test could run: excluded from pass-rate figures, R11)":""}`);for(let t of s)console.log(` ${t.status.padEnd(7)} ${t.path}${t.runner?` (${t.runner}, ${u(t.ms)})`:""}${t.reason?` \u2014 ${t.reason}`:""}`);e.check?.suite&&console.log(` suite: ${e.check.suite.status} \u2014 ${e.check.suite.cmd} (${u(e.check.suite.ms)})`);for(let t of e.check?.deps||[])console.log(` deps: ${t.status} \u2014 ${t.cmd} in ${t.dir} (${u(t.ms)})`)}e.status==="finished"&&console.log(` record: ${e.dir}/result.json${e.patchBytes!=null?` \xB7 result.patch (${e.patchBytes} bytes)`:""}${e.cloneRemoved?" \xB7 clone removed":" \xB7 clone kept"}`),console.log(` ${e.label}`)}async function W(e){let o=e._[0];o||c(`run needs a <spec>
15
+ ${$}`);let s={};e["cap-usd"]!=null&&(s.usd=Number(e["cap-usd"]),s.usd>0||c("--cap-usd wants a positive dollar figure")),e["cap-active"]!=null&&(s.activeMs=k(e["cap-active"],"--cap-active")),e["cap-wall"]!=null&&(s.wallMs=k(e["cap-wall"],"--cap-wall"));let t;try{t=await y("POST","/api/replay/runs",{spec:o,provider:e.provider||"claude",model:e.model||null,caps:s,keep:!!e.keep,gate:!e["no-gate"],by:"operator"})}catch(r){r.status===423&&r.data?.verdict&&(e.json?console.log(JSON.stringify({skipped:!0,skip:r.data.skip,verdict:r.data.verdict},null,2)):(console.log(`[bostrat-replay] SKIPPED \u2014 the headroom gate held, nothing started (recorded as skip ${r.data.skip?.id||"\u2013"}; R22)`),x(r.data.verdict,{head:!1}),console.log(" `bostrat-replay run \u2026 --no-gate` starts it anyway; `bostrat-replay skips` lists the ledger")),process.exit(2)),c(r.status===409?`${r.message} \u2014 \`bostrat-replay runs stop ${r.data?.runId||"<run>"}\` ends it`:r.message)}let a=t.run;if(e["no-wait"]){e.json?console.log(JSON.stringify(a,null,2)):(S(a),console.log(` running in the background \u2014 \`bostrat-replay runs show ${a.id}\` reads it`));return}let n=null;for(;a.status==="running";)!e.json&&a.phase!==n&&(n=a.phase,process.stderr.write(`[bostrat-replay] run ${a.id}: ${j[n]||n}${a.trackId?` (Track ${a.trackId})`:""}
16
+ `)),await new Promise(r=>setTimeout(r,1e4)),a=(await h(`/api/replay/runs/${encodeURIComponent(a.id)}`)).run;e.json?console.log(JSON.stringify(a,null,2)):S(a)}async function H(e){let o=e._[0];if(o==="show"||o==="stop"){let n=e._[1];if(n||c(`runs ${o} needs a <run>
17
+ ${$}`),o==="stop"){await y("POST",`/api/replay/runs/${encodeURIComponent(n)}/stop`).catch(i=>c(i.message)),console.log(`[bostrat-replay] run ${n}: stop requested \u2014 it is recorded as capped (stop) once the turn closes, then checked`);return}let{run:r}=await h(`/api/replay/runs/${encodeURIComponent(n)}`).catch(i=>c(i.message));e.json?console.log(JSON.stringify(r,null,2)):S(r);return}o&&c($);let{runs:s,live:t}=await h(`/api/replay/runs${e.status?`?status=${encodeURIComponent(e.status)}`:""}`);if(e.json){console.log(JSON.stringify({runs:s,live:t},null,2));return}if(!s.length){console.log("[bostrat-replay] no replay runs on this node yet \u2014 `bostrat-replay run <spec>` starts one (spec ls lists the approved specs)");return}let a={};for(let n of s)a[n.status==="running"?"running":n.outcome]=(a[n.status==="running"?"running":n.outcome]||0)+1;console.log(`[bostrat-replay] ${s.length} replay run${s.length===1?"":"s"} on this node \u2014 ${Object.entries(a).map(([n,r])=>`${n} ${r}`).join(" \xB7 ")}${t?` \xB7 live: ${t.id}`:""}`);for(let n of s){let r=n.status==="running"?"~":n.outcome==="passed"?"+":n.outcome==="failed"?"-":n.outcome==="capped"?"c":n.outcome==="unverified"?"?":"!";console.log(`${r} ${n.id} ${P(n.startedAt)} ${(n.status==="running"?`running/${n.phase}`:n.outcome).padEnd(11)} ${`${n.source.repo}#${n.source.pr}`.padEnd(28)} spec ${n.specId} v${n.version} ${(n.model||n.provider).padEnd(16)} active ${u(n.activeMs).padStart(5)} ${m(n.usd).padStart(7)} q ${n.questions} ${n.acceptance||"\u2013"}`)}console.log(` ${s[0].label}`)}var O=e=>e==null?"\u2013":`${e}%`,g=e=>e?new Date(e).toISOString().replace("T"," ").slice(0,16):"\u2013";function x(e,{head:o=!0}={}){o&&console.log(`[bostrat-replay] headroom gate for ${e.model||e.provider}: ${e.ok?"OPEN \u2014 a run may start":"CLOSED \u2014 a run would be skipped"} (${e.mode}, read ${g(e.at)})`);let s=e.meters||{};if(!s.readable)console.log(` meter: not readable \u2014 ${s.why||"no read"}`),e.fixed&&console.log(` fixed weekly count (R25): ${e.fixed.weeklyRuns?`${e.fixed.used} of ${e.fixed.weeklyRuns} run${e.fixed.weeklyRuns===1?"":"s"} used this calendar week`:"none set \u2014 stays out of replay"}`);else{console.log(` meters: session ${O(s.session?.pct)} \xB7 week ${O(s.week?.pct)}${s.week?.resetsAt?` (resets ${g(s.week.resetsAt)})`:s.week?.resetsText?` (${s.week.resetsText})`:""}${(s.models||[]).length?` \xB7 ${s.models.map(n=>`${n.model} ${n.pct}%`).join(", ")}`:""} \xB7 captured ${g(s.capturedAt)}`),e.window&&console.log(` week: ${e.window.basis==="vendor"?"the vendor's window":"calendar week (no reset time read)"} ${g(e.window.start)} \u2192 ${g(e.window.end)} \xB7 ${Math.round((e.window.elapsedShare||0)*100)}% elapsed${e.window.spendDown?" \xB7 SPEND-DOWN WINDOW (D16)":""}`);let t=e.gates||{},a=n=>n?"pass":"FAIL";t.session&&console.log(` session gate ${a(t.session.ok)} ${t.session.pct==null?"no session meter rendered":`${t.session.pct}% < ${t.session.limit}%`}`),t.evenBurn&&console.log(` even-burn gate ${a(t.evenBurn.ok)} weekly ${t.evenBurn.pct}% vs line ${t.evenBurn.line}% (elapsed share less ${t.evenBurn.margin} points)`),t.reserve&&console.log(` reserve gate ${a(t.reserve.ok)} weekly ${t.reserve.pct}% < ${t.reserve.limit}%`),t.budget&&console.log(` budget gate ${t.budget.waived?"waived":a(t.budget.ok)} replay spent ${m(t.budget.spentUsd)} of ${m(t.budget.budgetUsd)} this week (${Math.round(t.budget.share*100)}% of the meter at ${m(t.budget.usdPerPoint)}/point)`),e.calibration&&console.log(` dollars per point: ${m(e.calibration.usdPerPoint)} \u2014 ${e.calibration.basis}${e.calibration.basis==="measured"?` from ${m(e.calibration.spendUsd)} notional at ${e.calibration.pct}% this week`:e.calibration.basis==="carried"?` from ${g(e.calibration.carriedFrom)}`:" (D14's observation; no week measured yet)"}`),console.log(` node spend on ${e.provider} this window: ${m(e.nodeSpendUsd)} over ${e.nodeTurns??"\u2013"} turns \xB7 replay runs this window: ${e.replayRuns??"\u2013"}`)}for(let t of e.reasons||[])console.log(` closed: ${t}`);for(let t of e.notes||[])console.log(` note: ${t}`)}async function K(e){if(e._[0]==="set"){let a=e._[1];(!a||e["weekly-runs"]==null)&&c(`gate set needs <provider> --weekly-runs <n>
18
+ ${$}`);let{fixed:n}=await y("PUT","/api/replay/gate/config",{provider:a,weeklyRuns:Number(e["weekly-runs"])}).catch(r=>c(r.message));console.log(`[bostrat-replay] ${a}: fixed weekly count set to ${n.weeklyRuns} run${n.weeklyRuns===1?"":"s"} (R25 \u2014 used only while its meter cannot be read${n.weeklyRuns?"":"; 0 keeps it out of replay"})`);return}e._[0]&&c($);let o=e.provider||"claude",s=new URLSearchParams({provider:o,...e.model?{model:e.model}:{},...e.cached?{fresh:"0"}:{}}),{verdict:t}=await h(`/api/replay/gate?${s}`).catch(a=>c(a.message));e.json?console.log(JSON.stringify(t,null,2)):x(t)}async function Y(e){let o=new URLSearchParams;if(e.provider&&o.set("provider",e.provider),e.since!=null){let t=Number(e.since);t>0||c("--since wants a number of days"),o.set("since",String(Date.now()-t*864e5))}let{skips:s}=await h(`/api/replay/skips?${o}`).catch(t=>c(t.message));if(e.json){console.log(JSON.stringify(s,null,2));return}if(!s.length){console.log("[bostrat-replay] no skips recorded \u2014 every gated start so far passed its gate (or none was tried)");return}console.log(`[bostrat-replay] ${s.length} skip${s.length===1?"":"s"} \u2014 a run the headroom gate held back (R22)`);for(let t of s){let a=t.meters?.readable?`week ${O(t.meters.week?.pct)}${t.meters.session?` \xB7 session ${t.meters.session.pct}%`:""}`:"meter unreadable";console.log(` ${g(t.at)} ${(t.model||t.provider||"\u2013").padEnd(16)} spec ${t.specId||"\u2013"} by ${t.by} ${a}`);for(let n of t.reasons||[])console.log(` ${n}`)}}var z={queued:"queued",running:"running",done:"done"};function T(e,{head:o=!0,run:s=null}={}){let t=e.result,a=e.status==="done"?`${t?.outcome||"done"}${t?.acceptance?` \xB7 acceptance ${t.acceptance}`:""}${t?.cappedBy?` \xB7 capped by ${t.cappedBy}`:""}`:e.status==="running"?`running \xB7 run ${e.runId}${s?` \xB7 ${j[s.phase]||s.phase}`:""}`:"queued";o&&console.log(`[bostrat-replay] queue item ${e.id} \u2014 ${a} \u2014 ${e.source?.repo}#${e.source?.pr} \xB7 spec ${e.specId} v${e.version} \xB7 ${e.model||e.provider}`),e.caps&&console.log(` caps: ${m(e.caps.usd)} \xB7 active ${u(e.caps.activeMs)} \xB7 wall ${u(e.caps.wallMs)} (R24; item overrides)`),t&&t.runId?console.log(` result: run ${t.runId} \u2014 agent-active ${u(t.activeMs)} \xB7 wall ${u(t.wallMs)} \xB7 ${m(t.usd)} notional \xB7 ${t.turns} turn${t.turns===1?"":"s"} \xB7 ${t.questions} question${t.questions===1?"":"s"}${t.error?` \xB7 error: ${t.error}`:""}`):t?.error&&console.log(` result: ${t.error}`),e.attempts?.length>1&&console.log(` attempts: ${e.attempts.map(n=>`${n.runId||"\u2013"} ${n.outcome}`).join(" \xB7 ")}`),console.log(` added ${g(e.addedAt)} by ${e.addedBy}${e.startedAt?` \xB7 started ${g(e.startedAt)}`:""}${e.finishedAt?` \xB7 finished ${g(e.finishedAt)}`:""}`)}function I(e){for(let[o,s]of Object.entries(e||{}))console.log(` PAUSED ${o} until ${g(s.until)} \u2014 ${s.reason} (R26; \`bostrat-replay queue resume ${o}\` lifts it)`)}async function Q(e){let o=e._[0];if(o==="add"){let i=e._[1];i||c(`queue add needs a <spec>
19
+ ${$}`);let d=e.model?String(e.model).split(",").map(p=>p.trim()).filter(Boolean):[null],f={};e["cap-usd"]!=null&&(f.usd=Number(e["cap-usd"]),f.usd>0||c("--cap-usd wants a positive dollar figure")),e["cap-active"]!=null&&(f.activeMs=k(e["cap-active"],"--cap-active")),e["cap-wall"]!=null&&(f.wallMs=k(e["cap-wall"],"--cap-wall"));let l=await y("POST","/api/replay/queue",{spec:i,provider:e.provider||"claude",models:d,caps:f,by:"operator"}).catch(p=>c(p.message));if(e.json){console.log(JSON.stringify(l,null,2));return}console.log(`[bostrat-replay] queue: spec ${l.spec.id} v${l.spec.version} (${l.spec.repo}#${l.spec.pr}) \xD7 ${d.length} model${d.length===1?"":"s"} on ${e.provider||"claude"} \u2014 ${l.added.length} added, ${l.existing.length} already queued`);for(let p of l.added)console.log(` + ${p.id} ${p.model||p.provider} queued`);for(let p of l.existing)console.log(` = ${p.id} ${p.model||p.provider} ${p.status} (already in the queue \u2014 one item per crossing)`);return}if(o==="show"||o==="rm"||o==="retry"){let i=e._[1];if(i||c(`queue ${o} needs an <item>
20
+ ${$}`),o==="rm"){let{removed:l}=await y("DELETE",`/api/replay/queue/${encodeURIComponent(i)}`).catch(p=>c(p.message));console.log(`[bostrat-replay] queue item ${l.id} removed (${l.source?.repo}#${l.source?.pr} on ${l.model||l.provider})`);return}if(o==="retry"){let{item:l}=await y("POST",`/api/replay/queue/${encodeURIComponent(i)}/retry`).catch(p=>c(p.message));console.log(`[bostrat-replay] queue item ${l.id} re-queued for a fresh attempt (${l.attempts.length} earlier attempt${l.attempts.length===1?"":"s"} kept on the item)`);return}let{item:d,run:f}=await h(`/api/replay/queue/${encodeURIComponent(i)}`).catch(l=>c(l.message));e.json?console.log(JSON.stringify({item:d,run:f},null,2)):T(d,{run:f});return}if(o==="resume"){let i=e._[1];i||c(`queue resume needs a <provider>
21
+ ${$}`);let{lifted:d}=await y("POST","/api/replay/queue/resume",{provider:i}).catch(f=>c(f.message));console.log(d?`[bostrat-replay] ${i}: pause lifted (was until ${g(d.until)} \u2014 ${d.reason})`:`[bostrat-replay] ${i}: not paused \u2014 nothing to lift`);return}o&&c($);let s=new URLSearchParams;e.provider&&s.set("provider",e.provider),e.status&&(z[e.status]||c("--status wants queued | running | done"),s.set("status",e.status));let t=await h(`/api/replay/queue?${s}`).catch(i=>c(i.message));if(e.json){console.log(JSON.stringify(t,null,2));return}let{items:a,summary:n}=t;if(!a.length){console.log(`[bostrat-replay] the replay queue is empty${e.provider||e.status?" for that filter":""} \u2014 \`bostrat-replay queue add <spec> [--provider p] [--model a,b]\` enqueues approved specs (\`spec ls --status approved\` lists the bench)`),I(n.paused);return}let r=Object.entries(n.by).map(([i,d])=>`${i}: ${d.queued} queued \xB7 ${d.running} running \xB7 ${d.done} done`).join(" | ");console.log(`[bostrat-replay] replay queue \u2014 ${a.length} item${a.length===1?"":"s"} shown of ${n.total} (${r})${t.live?` \xB7 live run ${t.live.id}`:""}`);for(let i of a){let d=i.status==="running"?"~":i.status==="queued"?".":i.result?.outcome==="passed"?"+":i.result?.outcome==="failed"?"-":i.result?.outcome==="capped"?"c":i.result?.outcome==="unverified"?"?":"!",f=i.status==="done"?`${(i.result?.outcome||"done").padEnd(10)} active ${u(i.result?.activeMs).padStart(5)} ${m(i.result?.usd).padStart(7)} ${i.result?.acceptance||"\u2013"}`:i.status==="running"?`running run ${i.runId}`:`queued added ${g(i.addedAt)}`;console.log(`${d} ${i.id} ${`${i.source?.repo}#${i.source?.pr}`.padEnd(28)} spec ${i.specId} v${i.version} ${(i.model||i.provider).padEnd(20)} ${f}`)}I(n.paused),console.log(` ${a[0].label}`)}async function X(e){let o=e.provider||"claude",s={};e["cap-usd"]!=null&&(s.usd=Number(e["cap-usd"]),s.usd>0||c("--cap-usd wants a positive dollar figure")),e["cap-active"]!=null&&(s.activeMs=k(e["cap-active"],"--cap-active")),e["cap-wall"]!=null&&(s.wallMs=k(e["cap-wall"],"--cap-wall"));let t;try{t=await y("POST","/api/replay/queue/next",{provider:o,caps:Object.keys(s).length?s:null,gate:!e["no-gate"],by:"loop"})}catch(d){d.data?.action?t=d.data:c(d.message)}let a=d=>e.json&&console.log(JSON.stringify(d,null,2));if(t.action==="empty"){a(t),e.json||console.log(`[bostrat-replay] next: nothing queued for ${o} \u2014 the queue is empty for it (\`bostrat-replay queue add <spec> --provider ${o}\`)`);return}if(t.action==="paused"&&(a(t),e.json||(console.log(`[bostrat-replay] next: ${o} is PAUSED until ${g(t.paused.until)} \u2014 nothing started (recorded as skip ${t.skip?.id||"\u2013"}; R26)`),console.log(` ${t.paused.reason}`),console.log(` \`bostrat-replay queue resume ${o}\` lifts it early`)),process.exit(2)),t.action==="busy"&&(a(t),e.json||console.log(`[bostrat-replay] next: BUSY \u2014 run ${t.live?.id||"?"} is live on this node and runs are sequential (R21); item ${t.item?.id||"\u2013"} stays queued, nothing started`),process.exit(3)),t.action==="skipped"&&(a(t),e.json||(console.log(`[bostrat-replay] next: SKIPPED \u2014 the headroom gate held for ${t.item.model||o}, nothing started (recorded as skip ${t.skip?.id||"\u2013"}; R22); item ${t.item.id} stays queued`),x(t.verdict,{head:!1})),process.exit(2)),t.action==="settled"&&!t.run){a(t),e.json||T(t.item);return}let n=t.item,r=t.run;if(e.json||(console.log(`[bostrat-replay] next: ${t.action==="resumed"?`resuming item ${n.id} \u2014 run ${r.id} is still live`:t.action==="settled"?`item ${n.id}: run ${r.id} had finished \u2014 result written`:`item ${n.id}: run ${r.id} started on ${n.model||o} (caps ${m(r.caps.usd)} \xB7 ${u(r.caps.activeMs)} active \xB7 ${u(r.caps.wallMs)} wall)`}`),t.verdict&&console.log(` headroom gate: passed \u2014 weekly ${t.verdict.weekPct??"\u2013"}%${t.verdict.gates?.budget?` \xB7 replay spent ${m(t.verdict.gates.budget.spentUsd)} of ${m(t.verdict.gates.budget.budgetUsd)}`:""}${t.verdict.window?.spendDown?" \xB7 spend-down window (D16)":""}`)),e["no-wait"]&&n.status!=="done"){a({...t,waited:!1}),e.json||console.log(` running in the background \u2014 \`bostrat-replay queue show ${n.id}\` reads it; \`bostrat-replay next\` again resumes it`);return}let i=null;for(;n.status!=="done";){!e.json&&r&&r.phase!==i&&(i=r.phase,process.stderr.write(`[bostrat-replay] run ${r.id}: ${j[i]||i}${r.trackId?` (Track ${r.trackId})`:""}
22
+ `)),await new Promise(f=>setTimeout(f,1e4));let d=await h(`/api/replay/queue/${encodeURIComponent(n.id)}`);if(n=d.item,r=d.run||r,n.status==="queued"){a({action:"requeued",item:n,run:r}),e.json||console.log(`[bostrat-replay] next: run ${r?.id||"\u2013"} died with the node \u2014 item ${n.id} re-queued (attempt ${n.attempts.length} of 2); run \`bostrat-replay next\` again`);return}}if(a({action:"done",item:n,run:r}),!e.json){T(n,{run:r}),r&&S(r,{head:!1});let d=await h(`/api/replay/queue?provider=${encodeURIComponent(o)}`).catch(()=>null);d?.summary?.paused?.[o]&&I({[o]:d.summary.paused[o]})}}var w=process.argv.slice(2),v=w.shift();try{if(v==="census")await _(b(w));else if(v==="spec"){let e=w.shift(),o=b(w);e==="frame"?await L(o):e==="draft"?await J(o):e==="revise"?await F(o):e==="ls"?await V(o):e==="show"?await G(o):c($)}else v==="run"?await W(b(w)):v==="runs"?await H(b(w)):v==="gate"?await K(b(w)):v==="skips"?await Y(b(w)):v==="queue"?await Q(b(w)):v==="next"?await X(b(w)):c($)}catch(e){c(e?.message||String(e))}