@lovek4d/kickflip 0.8.0 → 0.9.0

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.
package/board/domain.mjs CHANGED
@@ -1,10 +1,10 @@
1
- var Vt=Object.defineProperty;var d=(e,t)=>Vt(e,"name",{value:t,configurable:!0});import{routeRecord as R}from"../hub/routes.mjs";import Xt from"node:fs";import{ticketBadge as pt,ticketIn as Yt}from"./tickets.mjs";import{prLinks as zt,reviewLinks as Jt,reviewTime as Zt,reviewersOf as en}from"./review.mjs";import{remoteFromInput as tn}from"../hub/repos.mjs";import{reviewsOf as nn,reviewNeeds as sn,reviewActions as on}from"./auto-review.mjs";import{cardPRs as rn,hasPR as et,leastReady as an,prKeyOf as ln,prURL as dn}from"../shared/card-prs.mjs";import ft from"node:vm";import{checkWords as cn,parseCheck as un}from"../shared/owner-check.mjs";import{buildScriptOf as pn}from"./build-script.mjs";import{HUB as Qe,hubLineOf as gt}from"./hub-lines.mjs";const fn="card-merged",tt=ft.createContext({});for(const e of["ui-enums.js","ui-order.js"])ft.runInContext(Xt.readFileSync(new URL(`./public/${e}`,import.meta.url),"utf8"),tt);const{BUTTON:ce,ACTION_KIND:q,BUILDER_KIND:ue,PR_STATE:V,PHASES:kt}=tt.BoardUI,{laneOrder:gn}=tt.BoardUI,kn=["item-message","mark-ready","grill-more","prototype-request","visual-request","reask-request"],mt="question-reopen",So=Object.freeze({todo:"Todo",progress:"In Progress",review:"In Review",done:"Done"}),$e="move",mn=10*6e4,wn=5*6e4,wt="build-refused",De=Object.freeze({ask:"builder-ask",answer:"builder-answer"}),hn=864e5,pe=d(e=>e.lane==="done","closedLane"),yn=d(e=>`file:${e}`,"fileFold"),ht=7*hn,yt=d((e,t)=>({id:e,url:t?.workspace?`https://linear.app/${t.workspace}/issue/${e}`:null}),"linearRef"),bn=d(e=>String(e).replace(/^S(\d+)$/,"INT-$1"),"internalRef"),nt=d((e,t,n)=>Yt(n,t.ticket)?t.ticket:e.internal===!0?bn(t.id):t.id,"refOf"),Sn=d((e,t,n)=>pt(e,t,n)||(t?{id:String(t),url:null,source:null}:null),"ticketOf");function vn(e,t,n,s,r,a,c,l,u){return!a&&(e.lane==="done"||t?.state==="MERGED"||t?.state==="CLOSED")?"done":(n||s)&&!l?"progress":r?"review":t?.state==="OPEN"?t.checks?.state==="fail"&&(!t.isDraft||c)?"progress":"review":t||u?"progress":"todo"}d(vn,"laneOf");const He="Lander",bt=d(e=>e.kind!==ue.install&&e.label!==He,"changesCode");function xn(e,t){return e?.state==="MERGED"||t?V.merged:e?.state==="CLOSED"?V.closed:e?.state==="OPEN"?e.isDraft?V.draft:V.open:null}d(xn,"prStateOf");const St=d(e=>e.pr?.status===V.closed,"unlanded"),On=d(e=>e.some(t=>t.kind==="work")&&e.every(t=>t.lane==="done"),"finishedOf");function st(e){const t=vt(e);return t?.done&&t.handed_back?t.handed_back:null}d(st,"handedBackAt");const vt=d(e=>e.filter(t=>t?.started&&Q(t)&&t.kind!==ue.install&&t.kind!==ge).sort((t,n)=>String(t.started).localeCompare(String(n.started))).at(-1),"newestBuild");function En(e,t,n){return Object.fromEntries(e.map(s=>{const r=R(t?.reviews,s.github),a=r==="APPROVED"?"approved":r==="CHANGES_REQUESTED"?"changes":Object.hasOwn(n,s.name)?"sent":"unsent";return[s.name,{state:a,since:a==="sent"?R(n,s.name):null,github:s.github||null}]}))}d(En,"reviewOf");function $n(e,t,n,s,r,a,{held:c,needsApproval:l}){return n?.kind===ue.install?"builder":s?"checking":n?"builder":c&&e==="review"?"merge":r&&e==="review"?"owner":e==="review"&&t?.state==="OPEN"&&t.isDraft?a?"ci":"ready":e==="review"?xt(t,l)?"merge":"reviewers":null}d($n,"waitsOnOf");const xt=d((e,t)=>e?.reviewDecision==="APPROVED"||!t&&!["REVIEW_REQUIRED","CHANGES_REQUESTED"].includes(e?.reviewDecision),"reviewed"),Ne=/(^|\/)prototype-[\w-]+\.html/,An={reviewers:"Waiting for PR reviewers",merge:"Approved, merges once CI and the merge state allow",ci:"Marked ready for review once CI passes"},Ve={waiting:"Approved, Merge shows once CI and the merge state allow",ready:"Approved and green: tap Merge",merging:"Merging"},ot={auto:"Ready, merges once CI and the merge state allow",waiting:"Ready, Merge shows once CI and the merge state allow",ready:"Ready and green: tap Merge"},Bn=d(e=>`Verified: tap Merge to land it on ${e}`,"heldNext"),_n="Fix the failing CI",Rn="Your reply waits on the orchestrator",Mn="Tap Done",In=["status","agent","ask-link","command",$e,De.answer],qn=d(e=>(e.who==="claude"||e.via==="github")&&!In.includes(e.kind)&&(e.kind!==Qe||gt(e).fault),"countsUnread"),Cn=["lander-handoff","land-waiting"];function Dn({slug:e,itemFile:t,it:n,order:s,prs:r,repo:a,remote:c,base:l,builder:u,reachedPhase:m,agents:f,worktree:p,eta:w,thread:v,events:_,working:x,said:P,askedAt:C,topicItems:L,prSlack:T,boardReviewers:W,now:h,bumpedAt:b,holdAsk:i,closedAt:S,mergeAt:oe,autoMerge:me,skipDraft:we,tickets:K}){const F=r.map(k=>({repo:k.repo,number:k.number,...k.gh||k.kept||{},url:(k.gh||k.kept)?.url||dn(k),status:xn(k.gh,k.merged_at)})),ee=an(r.map(k=>k.gh)),I=r[ee]?.gh||null,G=F[ee]?.status??null,ze=n.lane||null,U=!!S&&String(S)>String(n.lane_at||"");U&&(n={...n,lane:"done",closed_at:S,reopened_at:void 0});const D=[n.closed_at,...r.flatMap(k=>[k.merged_at,k.gh?.mergedAt])].filter(Boolean).map(String).sort().pop()||null,he=String(D||""),ye=F.length>0&&F.every(k=>k.status===V.closed),be=(n.lane==="done"||n.reopened_at||G===V.merged)&&!ye&&([...P.filter(k=>k.kind==="item-message").map(k=>k.ts),...C].map(String).filter(k=>k>he).sort().pop()||n.reopened_at)||void 0,Le=n.answered_at&&!n.phase&&!n.closed_at&&!be?String(n.answered_at):void 0,j=be||Le,Re=n.owner_step&&!U?String(n.owner_step):null,Je=(n.lane==="done"||G===V.merged)&&!ye,H=!!j&&!!n.next&&String(n.next_at||"")>String(n.reopened_at||D||"");j&&!H&&(n={...n,next:void 0});const X=st(f),Te=j&&P.filter(k=>String(k.ts)>he&&(k.state==="waiting"||k.state==="working")).map(k=>String(k.ts)).sort()[0]||null,Se=!!Te,ve=`${e}/${n.id}`,xe=en(t,W),Pe=Object.fromEntries(Object.entries(Jt(t,n,ve,L,zt(T,r))).map(([k,de])=>[k,Zt(de.ts)])),te=Object.values(Pe).filter(Boolean).sort()[0]||null,Ue=[...v.map(k=>k.ts),..._.map(k=>k.ts)].sort().pop()||null,je=[...v.filter(k=>qn({...k,who:k.who||"claude"})).map(k=>k.ts),..._.map(k=>k.reply?.at)].filter(Boolean).sort(),Y=!et(n)&&n.pushed?.branch?{branch:n.pushed.branch,at:n.pushed.at||null,host:c?.host||null}:null,z=!et(n)&&n.merge_ready?.branch?{branch:n.merge_ready.branch,at:n.merge_ready.at||null,base:l}:null,Me=!!n.rebase_run&&I?.state==="OPEN",Ie=(n.rebased||[]).at(-1),re=f.filter(k=>k.started&&!k.done&&Q(k)),Ze=!!X&&bt(vt(f));let A=vn(n,I,re.some(bt),Ze,Y||z,!!j,we,Me,re.length>0||!!X);j&&A==="todo"&&(A="progress");const We=A==="review"&&!!te&&h-Date.parse(te)>ht,ae=!!Re&&Je&&A==="done";ae&&(A="review");let N=$n(A,I,u,!!X&&A!=="done",Y,we,{held:z,needsApproval:xe.length>0});const Fe=N==="builder"&&I?.state==="OPEN"&&!I.isDraft,qe=A==="progress"&&!N&&I?.state==="OPEN"&&(!I.isDraft||we),Oe=ae||!!j&&A==="progress"&&!N&&!qe&&!Se&&!H;Oe&&(N="owner");const o=!!j&&f.some(k=>Q(k)&&String(k.started||"")>String(j)),g=A==="progress"&&!N&&(qe||!!j&&!o);g&&(A="review");const E=i&&String(i.ts)>String(n.held_at||""),$=A==="todo"&&(E?!!i.data.hold:!!n.held),y=$&&(E?i.data.until:n.pick_up_at)||null,M=A!=="done",B=!!b&&!(he&&String(b)<=he),Ke=v.filter(k=>(k.who||"claude")==="claude"&&!["status","command",$e].includes(k.kind)&&!Cn.includes(k.line)).map(k=>String(k.ts)).sort().pop()||"",le=[oe,z&&n.merge_ready.tapped].filter(Boolean).map(String).sort().pop(),Ce=N==="merge"&&!!le&&le>Ke,Ee=v.filter(k=>(k.kind==="status"||k.kind===Qe)&&String(k.ts)>String(le)).sort((k,de)=>String(k.ts).localeCompare(String(de.ts))).at(-1),ne=Ee?.line==="land-waiting"?`${Ve.merging} \xB7 ${Ee.text[0].toLowerCase()}${Ee.text.slice(1)}`:Ve.merging,J=v.filter(k=>!["status",$e].includes(k.kind)).sort((k,de)=>String(k.ts).localeCompare(String(de.ts))).at(-1),O=A==="todo"&&J?.line===wt?J.text:null,ie=j||f.filter(Q).map(k=>k.started).filter(Boolean).map(String).sort().pop()||null,Ge=I?.reviewDecision==="APPROVED",Kt=Y&&N==="owner"?`merge ${Y.branch} into ${l}`:z&&N==="merge"?Ce?ne:Bn(l):N==="merge"&&!me?Ce?ne:(Ge?Ve:ot).waiting:N==="merge"&&!Ge?ot.auto:An[N],Gt=G===V.draft?`Review draft PR #${F[ee].number}`:null,Qt=!Me&&Ie?.to&&Ie.to===I?.headRefOid?`Rebased onto ${Ie.base||l}, pushed${I.mergeable==="MERGEABLE"?" \xB7 PR is clean again":""}`:null,Ht=Me&&N==="checking"?f.flatMap(k=>k.calls).sort((k,de)=>String(k.at).localeCompare(String(de.at))).at(-1)?.text??null:null;return{key:ve,kind:"work",order:s,file:e,fileTitle:t.title||e,id:n.id,ref:nt(t,n,K),title:n.title,storedLane:ze,created:n.created||null,reviewSince:g&&j||n.review_since||te||n.merge_ready?.at||n.pushed?.at||n.created||null,progressSince:ie,closedAt:A==="done"?D:null,internal:t.internal===!0,repo:t.internal===!0&&!t.repo?null:a,lane:A,waitsOn:N,builder:N==="checking"?null:u,reachedPhase:m,agents:f,worktree:p??null,eta:w,working:x,reopened:!!be,answered:!!Le,awaitsDone:Oe,ownerStep:Oe?Re:null,ownerCheck:Oe&&Re&&n.owner_check?{words:cn(un(n.owner_check.check)),broken:n.owner_check.broken||null}:null,stagedAt:A==="todo"&&n.phase==="staging"&&n.staged_at||null,roundAt:n.round_at||null,deps:n.deps||[],blockedUntil:n.blocked_until||null,blockReason:n.block_reason||null,held:$,heldUntil:y,risky:!!n.risky,bumpable:M,bumpedAt:M&&B?b:null,holdable:A!=="done",hasNotes:!!(n.plan||String(n.notes||"").trim()),finishable:A!=="done",merging:Ce,refusal:O,manualSteps:n.manual_steps||[],fromAsk:n.from_ask||null,unfiled:!!n.unfiled,filedHeld:!!n.filed_held,next:Fe||A==="done"||N==="checking"?null:g&&Se?Rn:qe?_n:Qt||Kt||n.next||Gt||null,rebaseFailed:Ht,branch:n.branch||I?.headRefName||Y?.branch||null,pushed:A==="done"||ae?null:Y,mergeReady:A==="review"?z:null,stale:A!=="done"&&(We||!!u?.stale),stalled:n.stalled?.reason||null,landStopped:A==="review"&&z&&n.merge_ready.stopped&&String(n.merge_ready.stopped)>String(n.merge_ready.tapped||"")?{words:At("land"),at:n.merge_ready.stopped}:null,ticket:K?.source==="linear"&&!n.ticket&&n.linear?.length?null:Sn(K,n.ticket,{repo:a}),ticketSource:K?.source||null,linear:(n.linear||[]).map(k=>K?.source==="linear"&&pt(K,k,{repo:a})||yt(k,K)),pr:F[ee]||null,prs:F,reviewers:xe.map(k=>k.name),review:En(xe,I||r[ee]?.kept,Pe),inReviewSince:te,threadCount:v.length+_.length,lastTs:Ue,othersAt:je,grilling:Bt("grill",_,f,C),prototyping:Bt("prototype",_,f,C),storedPhase:n.phase||null,phase:null,recheckAt:n.recheck_at||null,updatedAt:I?.mergedAt||I?.updatedAt||r[ee]?.merged_at||u?.at||Ue||null,ask:null,fold:null,action:null,install:A==="done"?null:Ln(n.install,I),waitFacts:Nn(n,{agents:f,thread:v,events:_,refusedAt:O?J.ts:null,replyAt:g?Te:null})}}d(Dn,"workItem");function Nn(e,{agents:t,thread:n,events:s,refusedAt:r,replyAt:a}){const c=new Set(n.filter(f=>f.kind===De.answer).map(f=>f.ask)),l=n.filter(f=>f.kind===De.ask&&!c.has(f.ask)).sort((f,p)=>String(f.ts).localeCompare(String(p.ts)))[0],u=d(f=>s.filter(p=>at(p,f)).pop()?.ts||null,"requestAt"),m=n.filter(f=>(f.who||"claude")==="claude"&&!["status","agent","command",$e].includes(f.kind)&&f.line!==wt).map(f=>f.ts);return{handedBackAt:st(t),next:e.next||null,ask:l?{at:l.ts,text:l.text}:null,grillAt:u("grill"),prototypeAt:u("prototype"),refusedAt:r,replyAt:a,unblockedAt:e.unblocked_at||null,unverified:t.some(f=>f.calls.some(p=>!f.verified||String(p.at)>String(f.verified.at))),writes:[...m,...t.flatMap(f=>[f.verified?.at,f.started])].filter(Boolean).map(String).sort()}}d(Nn,"waitFactsOf");function Ln(e,t){if(!e?.url)return null;const n=e.sha?String(e.sha).toLowerCase():null,s=t?.headRefOid?String(t.headRefOid).toLowerCase():null;return{url:e.url,label:e.label||null,builtAt:e.built_at||null,sha:n,older:!!(n&&s&&!s.startsWith(n))}}d(Ln,"installOf");function Tn(e,{needsApproval:t=!0}={}){if(e?.state!=="OPEN")return[`PR is ${String(e?.state||"unknown").toLowerCase()}`];const{state:n,pending:s,failing:r}=e.checks||{};return[e.isDraft&&"it is a draft",!xt(e,t)&&`review: ${String(e.reviewDecision||"none").toLowerCase().replace(/_/g," ")}`,n==="fail"&&`failing: ${r?.length?r.join(", "):"a check"}`,n==="pending"&&`pending: ${s?se(s,"check"):"checks"}`,e.mergeStateStatus!=="CLEAN"&&`merge state: ${String(e.mergeStateStatus||"unknown").toLowerCase()}`].filter(Boolean)}d(Tn,"mergeBlockers");const Pn=d((e,t)=>!Tn(e,{needsApproval:t}).length,"mergeable");function Un(e,t,n){if(pe(e))return null;const s=`#selectedCard=${encodeURIComponent(e.key)}`;if(e.stalled)return{kind:q.stalled,url:s,label:`stalled: ${e.stalled}`};if(jn(e)){const r=t.get(e.questions.first);return Ne.test(r?.url||"")?{kind:q.pick,url:`questions.html#${r.id}`,label:"Prototypes ready: pick a take"}:{kind:q.questions,url:`questions.html#${e.questions.first}`,label:`Answer ${se(e.questions.open,"question")}`}}return e.waitsOn==="ready"?{kind:q.ready,url:e.pr.url,label:`Review draft PR #${e.pr.number}`}:e.waitsOn==="merge"&&e.manualSteps.length&&!e.mergeReady?{kind:q.steps,url:s,label:"Run the manual steps, then merge"}:e.waitsOn==="merge"&&(!n||e.mergeReady)&&!e.merging&&e.prs.every(r=>["MERGED","CLOSED"].includes(r.state)||Pn(r,e.reviewers.length>0))?{kind:q.merge,url:s,label:"Merge"}:null}d(Un,"actionOf");const jn=d(e=>!!(e.questions&&e.questions.state!=="resolved"&&e.questions.open>0),"asking"),rt=new Set([q.pick,q.questions]);function Ot(e){return e.questions?ce.openQuestions:null}d(Ot,"actionButtonOf");const Wn=d(e=>e.kind==="work"&&e.lane==="todo"&&!e.action&&!e.unpicked,"buildableOf"),Fn=d((e,t)=>/^item:/.test(e.topic||"")&&Ne.test(e.url||"")&&!(e.options||[]).some(n=>n.id===t),"picksNoTake");function Kn(e,t){const n=e.filter(a=>a.topic===`item:${t}`),r=[...n.filter(a=>Ne.test(a.url||"")).flatMap(a=>a.answers.map(c=>({q:a,a:c,again:Fn(a,c.choice)}))),...n.filter(a=>a.request).map(a=>({q:a,a:a.request,again:!0}))].sort((a,c)=>String(a.a.ts).localeCompare(String(c.a.ts))).at(-1);return r?.again?{id:r.q.id,note:r.a.note.replace(/\s+/g," ").trim()}:null}d(Kn,"noTakePicked");const Gn="Prototype again",Qn=Object.freeze({[q.pick]:ce.openQuestions,[q.questions]:ce.openQuestions,[q.ready]:ce.github,[q.steps]:ce.github,[q.merge]:ce.merge,[q.stalled]:ce.reply}),Hn="Merges once unblocked",Vn=d(e=>`Blocked ${[e.blockedBy.length&&`by ${e.blockedBy.map(t=>t.ref).join(", ")}`,e.blockedUntil&&`until ${e.blockedUntil}`].filter(Boolean).join(" and ")}`,"mergeBlockedWords");function Xn(e,t,n){if(e.action=Un(e,t,n),e.mergeBlocked=e.action?.kind===q.merge&&e.blocked?Vn(e):null,e.mergeBlocked&&Object.assign(e,{action:null,next:Hn}),e.action?.kind===q.questions&&e.questions.fromAsks){Object.assign(e,{action:null,waitsOn:"owner",next:e.action.label,actionButton:Ot(e),resolvedBy:null});return}e.awaitsDone&&=!e.action,e.awaitsDone||Object.assign(e,{ownerStep:null,ownerCheck:null}),e.actionButton=Ot(e),e.resolvedBy=Qn[e.action?.kind]||null,e.action?.kind===q.merge&&!e.mergeReady&&(e.next=(e.pr?.reviewDecision==="APPROVED"?Ve:ot).ready),e.awaitsDone&&Object.assign(e,{lane:"review",next:e.ownerStep||Mn,bumpable:!1,bumpedAt:null});const s=e.lane==="todo"||e.waitsOn==="ready"||e.lane==="progress"&&e.waitsOn==="owner";if(!e.action||!s||e.stalled)return;const r=e.lane==="todo"&&rt.has(e.action.kind)?"todo":"review";Object.assign(e,{lane:r,waitsOn:e.waitsOn==="ready"?"ready":"owner",next:e.action.label})}d(Xn,"placeOwnerWait");const Et=d((e,t)=>e?e!=="todo":t.some(Q),"started"),$t="none set yet";function vo(e,t){const n=t.filter(s=>s?.started);return e.next||et(e)||e.pushed||e.held||e.lane==="done"||st(n)?!1:!n.some(s=>!s.done)&&Et(e.lane,n)}d(vo,"owesNext");const fe="visual",ge="helper",Yn=new Set(["grill","prototype",fe]),Z=d(e=>Yn.has(e.kind),"plans"),Q=d(e=>!Z(e),"builds"),zn={grill:"grilling",prototype:"prototyping"},Jn=d((e,t)=>`${e} ${t} by orchestrator`,"orchestratorDid"),At=d(e=>Jn(e,"stopped"),"stoppedWords"),Zn={grill:"grill-more",prototype:"prototype-request"},at=d((e,t)=>e.kind===Zn[t]&&!e.data?.question,"isRequest");function Bt(e,t,n,s){if(n.some(a=>a.kind===e&&a.started&&!a.done))return!0;const r=t.filter(a=>at(a,e)).pop();return!!(r&&!r.reply&&!s.some(a=>String(a)>String(r.ts))&&!n.some(a=>a.kind===e&&a.done&&String(a.started)>=String(r.ts)))}d(Bt,"planningOf");const xo=30*6e4;function Oo(e,t){const n=[];for(const s of e.items){if(pe(s)||(s.agents||[]).some(a=>a.kind==="prototype"&&a.started&&!a.done))continue;const r=s.prototyping&&t.filter(a=>a.data?.key===s.key&&at(a,"prototype")).pop();r&&n.push({key:s.key,request:r.id,since:r.ts});for(const a of e.owner.filter(c=>c.topic===`item:${s.key}`&&c.state==="requested"))n.push({key:s.key,request:a.request.id,question:a.id,since:a.request.ts})}return n}d(Oo,"prototypeWaits");function lt(e={},t=!1){return Object.entries(e).filter(([n,s])=>s&&typeof s=="object"&&(t||!n.startsWith("past-"))).map(([n,s])=>({name:n,kind:_t(s.kind)||null,model:s.model||(s.kind==="opus"||s.kind==="sonnet"?s.kind:null),label:s.label||null,started:s.started||null,eta:s.done?null:s.eta||null,done:s.done||null,log:s.session?.log||null,pid:s.session?.pid??null,calls:Array.isArray(s.calls)?s.calls:[],verified:s.verified||null,stopped:s.stopped||null,handed_back:s.handed_back||null,...s.pause?{pause:s.pause}:{},...s.kind===ge?{writes:!!s.writes,requested:s.requested||null}:{},...s.waits?{waits:s.waits}:{}})).sort((n,s)=>String(n.started||"").localeCompare(String(s.started||""))||n.name.localeCompare(s.name))}d(lt,"agentsOf");function it(e={}){return Object.values(e).filter(t=>t?.worktree?.path).sort((t,n)=>String(t.started||"").localeCompare(String(n.started||""))).at(-1)?.worktree.path??null}d(it,"worktreeOf");function es(e,t=[]){const n=e.filter(Q).map(s=>String(s.started||"")).filter(Boolean).sort().pop();return n===void 0?null:t.filter(s=>s.kind==="status"&&s.phase&&!s.planner&&String(s.ts)>=n).sort((s,r)=>String(s.ts).localeCompare(String(r.ts))).pop()?.phase||null}d(es,"reachedPhaseOf");function ts(e,t=[],n,s=null,r=null,a=!1){const c=e.filter(b=>b.started&&!b.done&&b.kind!==fe),l=c.every(Z),u=l?c:c.filter(Q),m=u.map(b=>String(b.started||"")).sort()[0];if(m===void 0)return null;const f=t.filter(b=>b.kind==="status"&&String(b.ts)>=m&&(l||!b.planner)).sort((b,i)=>String(b.ts).localeCompare(String(i.ts))).pop(),p=u.filter(b=>b.kind!==ge).at(-1),w=u.some(b=>b.kind===ue.install)?ue.install:p?_t(p.kind):"claude",v=l?null:u.find(b=>b.stopped&&String(b.stopped.at)>=String(b.started))?.stopped,_=f?.ts||m,x=v?v.at:s!==null&&s>Date.parse(_)?new Date(s).toISOString():_,P=f?f.phase||f.planner?f.text.replace(": "," \xB7 "):f.text||null:l?zn[w]:null,C=n-Date.parse(x),L=l?null:u.find(b=>b.pause)?.pause??null,T=!l&&!v&&(r==="held"||!!L?.paused),W=l||T?null:v?!1:r,h=T?!1:W===null?C>=mn:!W;return{progress:P,phase:f?.phase||null,at:_,kind:w,planner:l,silentSince:x,stale:h,alive:W,held:T,quiet:!!L||W===!0&&!a&&C>=wn,stopped:v?At(v.run):null,...L?{pause:{cause:L.cause,words:L.words,paused:!!L.paused}}:{}}}d(ts,"builderOf");const Eo={blocked:["nothing blocks it","nothing blocks it"],held:["you unhold it","unheld"],usage:["the usage pause lifts","the usage pause lifted"],bumped:["a slot frees","a slot freed"]},ns=15*6e4,ss=d(e=>(e.agents||[]).find(t=>t.name==="main"&&t.started&&!t.done&&Q(t))??null,"mainBuild"),os=d((e,t,n,{now:s,usageHeld:r})=>e.blocked||e.held||r(n??"claude")||!!(t.until&&s<Date.parse(t.until)),"stillPaused");function rs(e,{now:t=Date.now(),usageHeld:n}){const s={ask:[],drop:[],stop:[],resume:[]},r=[];for(const a of e){if(a.kind!=="work"||a.lane!=="progress")continue;const c=ss(a);if(!c)continue;const{pause:l}=c;if(!l){a.builder?.phase!=="landing"&&n(c.kind??"claude")&&s.ask.push(a.key);continue}const u=os(a,l,c.kind,{now:t,usageHeld:n});if(l.paused){u||r.push({key:a.key,at:l.paused});continue}!u&&l.cause!=="bumped"?s.drop.push(a.key):t-Date.parse(l.at)>=ns&&s.stop.push(a.key)}return s.resume=r.sort((a,c)=>String(a.at).localeCompare(String(c.at))).map(a=>a.key),s}d(rs,"pauseWork");function $o(e,t,n){const s=rs(t,n).drop;return e.filter(r=>s.includes(r))}d($o,"confirmedDrops");const dt={opus:"Claude Opus",sonnet:"Claude Sonnet",codex:"Codex"},as=d(({model:e,kind:t})=>dt[e]||dt[t]||(t==="claude"?dt.opus:null),"modelName"),_t=d(e=>e==="opus"||e==="sonnet"?"claude":e,"providerOf");function Ae(e){const t=as(e),{kind:n}=e,s=e.label?.replace(/\bbuilder\b/,"implementer").replace(/\bBuilder\b/,"Implementer"),r=d(c=>c[0].toLowerCase()+c.slice(1),"lower");if(t&&Z(e))return`${t} ${n}`;if(t)return`${t} ${r(s?.replace(/^(?:claude\s+)?(?:opus|sonnet|codex)\b\s*/i,"")||"implementer")}`;const a=n?n[0].toUpperCase()+n.slice(1):"";return a?s?s.toLowerCase().includes(n.toLowerCase())?s:`${a} ${r(s)}`:a:s||"Implementer"}d(Ae,"agentName");const Rt=d((e,t)=>!!e.resolved&&(!e.resolved_at||String(e.resolved_at)>=String(t)),"resolvedSince");function ls(e,t,n=[],s=[],r=[]){const a=t.filter(x=>x.data?.id===e.id),c=a[a.length-1]||null,l=r.filter(x=>x.data?.question===e.id).at(-1),u=d((x,...P)=>!!x&&P.every(C=>String(x.ts)>String(C||"")),"after"),m=!!(e.resolved&&e.resolved_at&&c&&String(c.ts)>e.resolved_at),f=n.filter(x=>x.data?.question===e.id&&u(x,c?.ts,l?.ts)).at(-1),p=u(l,c?.ts,f?.ts,e.resolved_at),w=e.resolved&&!m&&!p,v=w?s.filter(x=>x.data?.question===e.id&&String(x.ts)>String(e.resolved_at||"")).at(-1):null,_=p?"open":w?"resolved":f?"requested":c?c.reply?"replied":"answered":"open";return{...e,state:_,reopened:p,request:f?{id:f.id,ts:f.ts,note:f.data.note||"",choice:f.data.choice||null}:null,reask:v?{id:v.id,ts:v.ts}:null,answers:a.map(x=>({ts:x.ts,choice:x.data.choice||null,note:x.data.note||"",files:x.data.files||[],reply:x.reply,replies:x.replies,acted:Rt(e,x.ts)}))}}d(ls,"ownerQuestion");const ke=d(e=>e.round??(Ne.test(e.url||"")?1:0),"roundOf");function is(e,t){const n=d((s,r)=>s.confirm_of||(s.options||[]).some(a=>a.id===r.choice),"settles");return e.filter(s=>ke(s)===t&&s.answers.length).map(s=>[s,s.answers.at(-1)]).filter(([s,r])=>n(s,r)).map(([,s])=>s).sort((s,r)=>String(s.ts).localeCompare(String(r.ts))).at(-1)}d(is,"roundSettledBy");function ds(e){const t=e.find(r=>r.request&&!e.some(a=>ke(a)>ke(r)));if(t)return{n:ke(t)+1,state:"making"};const n=Math.max(0,...e.map(ke));if(!n)return null;const s=is(e,n);return s?{n,state:"closed",take:s.choice}:e.some(r=>ke(r)===n&&r.state!=="resolved")?{n,state:"back"}:null}d(ds,"roundState");function cs(e){const t=e.filter(n=>Ne.test(n.url||"")).map(n=>({n:ke(n),q:n.id,url:n.url,confirm:!!n.confirm_of,state:n.state})).sort((n,s)=>n.n-s.n);return t.length?{open:t.some(n=>n.state==="open"),rounds:t}:null}d(cs,"prototypesOf");const Be=d((e,t,n)=>{const s=e.get(t);s?s.push(n):e.set(t,[n])},"add"),_e=d((e,t)=>{const n=new Map;for(const s of e)Be(n,t(s),s);return n},"groupBy");function us(e,t,n=new Set){const s=new Set(e.map(c=>c.id)),r=[...e];t.some(c=>!s.has(c.topic))&&r.push({id:"",title:"Other"});const a=_e(t,c=>s.has(c.topic)?c.topic:"");return r.map(c=>{const l=a.get(c.id)||[],u=d(p=>l.filter(w=>w.state===p).length,"count"),m=l.every(p=>p.state==="resolved")||n.has(c.id)&&!u("open"),f=l.length&&m?"resolved":"open";return{...c,state:f,questions:l.map(p=>p.id),open:u("open"),answered:u("answered"),replied:u("replied"),resolved:u("resolved"),round:ds(l)}}).filter(c=>c.questions.length)}d(us,"ownerTopics");const Xe={implement:"Implementation requested",prototype:"Prototype requested",grill:"Grill requested",visual:"Visual requested",reask:"Re-ask requested",hold:"Held",resume:"Resumed",done:"Marked done",staged:"Marked as staging",readied:"Marked as ready",related:"Related to",unrelated:"Unrelated from",followup:"Follow-up","followup-of":"Follow-up of"},Mt={"grill-more":"grill","prototype-request":"prototype","visual-request":"visual","reask-request":"reask"},It={"mark-ready":"Mark ready",...Object.fromEntries(Object.entries(Mt).map(([e,t])=>[e,Xe[t]]))},ps=["grill-more","prototype-request","visual-request"],fs="answers submitted",qt={reply:"Reply",build:"Implement"},gs=d(e=>qt[e.data.intent],"intentLabel"),ks=d((e,t)=>{if(e.kind!=="prototype-request"||!t.has(e.data.question))return e.data.text||(e.data.files?.length?"":R(It,e.kind))||"";const n=t.get(e.data.question),s=(n.options||[]).find(r=>r.id===e.data.choice);return[Dt(t,n),s&&`${s.id}. ${s.label}`,e.data.note].filter(Boolean).join(`
2
- \u2192 `)},"actionText"),Ct=d((e,t)=>[...e.keys()].indexOf(t)+1,"numberOf"),Dt=d((e,t)=>`Question ${Ct(e,t.id)} \xB7 ${t.question}`,"numbered"),ms="question reopened",Ye=d(e=>e.data?.shared_by?.login?{by:e.data.shared_by.name||e.data.shared_by.login}:{},"byOf"),ws=d((e,t)=>{const n=t.get(e.card);return{...e,text:`${Xe[e.command]} ${n?`${n.ref}: ${n.title}`:e.card}`,link:`#selectedCard=${encodeURIComponent(e.card)}`}},"linkLine"),Nt=d(e=>({kind:"command",command:e,request:!0,mark:Xe[e]}),"commandLine"),hs=d((e,t)=>{if(e.kind==="item-message")return qt[e.data.intent]?{status:gs(e)}:{};const n={request:!0,command:Mt[e.kind]};return ps.includes(e.kind)?(e.data.question?t.has(e.data.question):String(e.data.text||"").trim()||e.data.files?.length)?{status:It[e.kind]}:n:e.kind==="reask-request"?n:{}},"requestOf"),Lt=d(e=>[...e.filter(t=>t.who==="claude"&&!["status","agent","command",$e,De.answer].includes(t.kind)).map(t=>t.ts),...e.filter(t=>t.kind==="ask").map(t=>t.reply?.at)].filter(Boolean).map(String).sort().pop()||"","claudeAtOf");function Tt(e,t={}){const n=new Map,s=new Map;for(const p of t.items||[])Be(n,p.topic,p),s.set(p.id,p.topic);const r=new Map,a=new Map,c=new Map,l=new Map,u=new Map,m=new Map,f=new Map;e.forEach((p,w)=>{f.set(p,w),p.data?.key&&kn.includes(p.kind)&&Be(r,p.data.key,p),p.kind==="owner-answer"&&s.has(p.data?.id)&&Be(a,s.get(p.data.id),p),p.kind===mt&&s.has(p.data?.question)&&Be(c,s.get(p.data.question),p),p.kind==="ask"&&l.set(p.id,p)});for(const p of e.filter(w=>w.kind==="ask-edited").sort((w,v)=>String(w.ts).localeCompare(String(v.ts)))){u.set(p.data?.id,p.data?.text);for(const w of p.data?.files||[])Be(m,p.data?.id,w)}return{byKey:r,answers:a,reopens:c,asks:l,edits:u,editFiles:m,questions:n,order:f}}d(Tt,"threadIndex");const ct=d((e,t)=>{const n=t.filter(s=>s?.length);return n.length>1?n.flat().sort((s,r)=>e.order.get(s)-e.order.get(r)):[...n[0]||[]]},"inLogOrder"),ys=/; its log is \S*\/\.claude\/kickflip\/logs\/([^/\s]+\.log)\.$/,bs=d(e=>{const t=!e.log&&typeof e.text=="string"?ys.exec(e.text):null;return t?{...e,text:`${e.text.slice(0,t.index)}.`,log:t[1]}:e},"withLog");function Ss(e,t){const n=t.run?e.find(s=>s.started===t.run):e.filter(s=>Z(s)===!!t.planner&&s.started&&String(s.started)<=String(t.ts)&&(!s.done||String(t.ts)<=String(s.done))).pop();return n?{agent:Ae(n),run:ut(e,n),running:!n.done}:{}}d(Ss,"agentOfLine");function ut(e,t){return t.label!==He?t.started:e.filter(n=>Q(n)&&n.label!==He&&n.started&&String(n.started)<String(t.started)).pop()?.started??t.started}d(ut,"sectionOf");function vs(e,{lines:t=[],events:n=[],owner:s={},working:r={},fromAsk:a=null,links:c=[],agents:l={},moved:u=[],cards:m=new Map,index:f=Tt(n,s)}){const p=e.startsWith("ask:")?[e.slice(4)]:[a,...u].filter(Boolean),w=[...new Set([e,...p.map(i=>`ask:${i}`)])],v=new Map((f.questions.get(`item:${e}`)||[]).map(i=>[i.id,i])),_=f.answers.get(`item:${e}`)||[],x=new Set([...v.values()].map(i=>i.round_of).filter(Boolean)),P=lt(l,!0).filter(Q).map(i=>String(i.started||"")).filter(Boolean),C=new Set(_.filter(i=>Rt(v.get(i.data.id),i.ts)||x.has(i.data.id)||P.some(S=>S>String(i.ts))).map(i=>i.id)),L=lt(l,!0),T=[...L.flatMap(i=>[...i.started?[{ts:i.started,who:"claude",kind:"agent",text:`${Ae(i)} started`,agent:Ae(i),run:ut(L,i),finished:!1,eta:i.done?null:i.eta,...i.log?{log:i.log}:{},...Z(i)?{planner:!0}:{}}]:[],...i.done?[{ts:i.done,who:"claude",kind:"agent",text:`${Ae(i)} finished`,agent:Ae(i),run:ut(L,i),finished:!0,eta:null,...Z(i)?{planner:!0}:{}}]:[],...i.calls.length?[{ts:i.done||i.calls.at(-1).at,who:"claude",kind:"calls",text:Ae(i),calls:i.calls.map(S=>S.text),verified:i.verified}]:[]]),...t.map(bs).map(i=>i.card?ws(i,m):i).map(i=>({ts:i.ts,who:i.who||"claude",...i.log?{log:i.log}:{},...i.kind==="status"?{kind:"status",...i.planner?{planner:!0}:{},...Ss(L,i)}:{},...i.kind===fe||i.kind===$e?{kind:i.kind}:{},...i.kind===Qe?{kind:Qe,line:i.line,...gt(i),...i.detail?{detail:i.detail}:{}}:{},...i.command?Nt(i.command):{},...i.card?{card:i.card}:{},...Object.values(De).includes(i.kind)?{kind:i.kind,ask:i.ask}:{},text:i.text||"",html:i.html||null,link:i.link||null,via:i.via||null,...i.by?{by:i.by}:{}})),...ct(f,w.map(i=>f.byKey.get(i))).map(i=>({ts:i.ts,who:"love",via:"site",kind:i.kind,text:ks(i,v),files:i.data.files||[],eventId:i.id,reply:i.reply,replies:i.replies,...hs(i,v),...Ye(i)})),..._.map(i=>{const S=[i.data.label||i.data.choice,i.data.note].filter(Boolean).join(" \xB7 ");return{ts:i.ts,who:"love",via:"questions",kind:i.kind,text:`${Dt(v,v.get(i.data.id))}
3
- \u2192 ${S}`,files:i.data.files||[],eventId:i.id,reply:i.reply,replies:i.replies,status:fs,...Ye(i)}}),...(f.reopens.get(`item:${e}`)||[]).map(i=>({ts:i.ts,who:"love",kind:i.kind,request:!0,mark:ms,text:`Question ${Ct(v,i.data.question)} was reopened`,...Ye(i)})),...ct(f,[...new Set(p)].map(i=>f.asks.has(i)?[f.asks.get(i)]:[])).flatMap(i=>[{ts:i.ts,who:"love",via:"ask",kind:i.kind,text:i.data?.text||"",files:i.data?.files||[],eventId:i.id,reply:i.reply,replies:i.replies,...u.includes(i.id)?{moved:!0}:{},...Ye(i),...typeof i.data?.from?.title=="string"?{from:i.data.from.title}:{}},...i.data?.quick===!0?[{ts:i.ts,who:"love",...Nt("implement"),text:Xe.implement}]:[],...c.map(S=>({ts:i.ts,who:"claude",kind:"ask-link",text:S.folded?`Moved to ${S.ref}: ${S.title}`:`${S.became?"Became":"Added to"} ${S.ref}`,link:`#selectedCard=${encodeURIComponent(S.key)}`,html:null,via:null}))])].sort((i,S)=>String(i.ts).localeCompare(String(S.ts))),W=Lt(T),{edits:h,editFiles:b}=f;for(const i of T){if(!i.eventId)continue;(i.kind==="ask"||i.kind==="item-message")&&typeof h.get(i.eventId)=="string"&&Object.assign(i,{text:h.get(i.eventId),edited:!0,files:[...i.files,...b.get(i.eventId)||[]]});const S=i.kind==="ask"&&(c.length>0||!!i.moved);i.state=i.reply?"replied":S||C.has(i.eventId)||W>String(i.ts)?"answered":R(r,i.eventId)?"working":"waiting",i.canDelete=i.kind==="item-message"&&(i.state==="working"||i.state==="waiting"),i.canEdit=i.canDelete}return xs(T)}d(vs,"threadOf");const Pt=["waiting","working","answered","replied"];function xs(e){const t=new Map;for(const n of e)n.kind==="owner-answer"&&t.set(n.ts,[...t.get(n.ts)||[],n]);return e.flatMap(n=>{if(n.kind!=="owner-answer")return[n];const s=t.get(n.ts);return s.length===1?[n]:s[0]!==n?[]:[{...n,text:s.map(r=>r.text).join(`
1
+ var Vt=Object.defineProperty;var d=(e,t)=>Vt(e,"name",{value:t,configurable:!0});import{routeRecord as R}from"../hub/routes.mjs";import Xt from"node:fs";import{ticketBadge as pt,ticketIn as Yt}from"./tickets.mjs";import{prLinks as zt,reviewLinks as Jt,reviewTime as Zt,reviewersOf as en}from"./review.mjs";import{remoteFromInput as tn}from"../hub/repos.mjs";import{reviewsOf as nn,reviewNeeds as sn,reviewActions as on}from"./auto-review.mjs";import{cardPRs as rn,hasPR as et,leastReady as an,prKeyOf as ln,prURL as dn}from"../shared/card-prs.mjs";import ft from"node:vm";import{checkWords as cn,parseCheck as un}from"../shared/owner-check.mjs";import{buildScriptOf as pn}from"./build-script.mjs";import{HUB as Qe,hubLineOf as gt}from"./hub-lines.mjs";const fn="card-merged",tt=ft.createContext({});for(const e of["ui-enums.js","ui-order.js"])ft.runInContext(Xt.readFileSync(new URL(`./public/${e}`,import.meta.url),"utf8"),tt);const{BUTTON:ce,ACTION_KIND:q,BUILDER_KIND:ue,PR_STATE:V,PHASES:kt}=tt.BoardUI,{laneOrder:gn}=tt.BoardUI,kn=["item-message","mark-ready","grill-more","prototype-request","visual-request","reask-request"],mt="question-reopen",So=Object.freeze({todo:"Todo",progress:"In Progress",review:"In Review",done:"Done"}),$e="move",mn=10*6e4,hn=5*6e4,ht="build-refused",De=Object.freeze({ask:"builder-ask",answer:"builder-answer"}),wn=864e5,pe=d(e=>e.lane==="done","closedLane"),yn=d(e=>`file:${e}`,"fileFold"),wt=7*wn,yt=d((e,t)=>({id:e,url:t?.workspace?`https://linear.app/${t.workspace}/issue/${e}`:null}),"linearRef"),bn=d(e=>String(e).replace(/^S(\d+)$/,"INT-$1"),"internalRef"),nt=d((e,t,n)=>Yt(n,t.ticket)?t.ticket:e.internal===!0?bn(t.id):t.id,"refOf"),Sn=d((e,t,n)=>pt(e,t,n)||(t?{id:String(t),url:null,source:null}:null),"ticketOf");function vn(e,t,n,s,r,a,c,l,u){return!a&&(e.lane==="done"||t?.state==="MERGED"||t?.state==="CLOSED")?"done":(n||s)&&!l?"progress":r?"review":t?.state==="OPEN"?t.checks?.state==="fail"&&(!t.isDraft||c)?"progress":"review":t||u?"progress":"todo"}d(vn,"laneOf");const He="Lander",bt=d(e=>e.kind!==ue.install&&e.label!==He,"changesCode");function xn(e,t){return e?.state==="MERGED"||t?V.merged:e?.state==="CLOSED"?V.closed:e?.state==="OPEN"?e.isDraft?V.draft:V.open:null}d(xn,"prStateOf");const St=d(e=>e.pr?.status===V.closed,"unlanded"),On=d(e=>e.some(t=>t.kind==="work")&&e.every(t=>t.lane==="done"),"finishedOf");function st(e){const t=vt(e);return t?.done&&t.handed_back?t.handed_back:null}d(st,"handedBackAt");const vt=d(e=>e.filter(t=>t?.started&&Q(t)&&t.kind!==ue.install&&t.kind!==ge).sort((t,n)=>String(t.started).localeCompare(String(n.started))).at(-1),"newestBuild");function En(e,t,n){return Object.fromEntries(e.map(s=>{const r=R(t?.reviews,s.github),a=r==="APPROVED"?"approved":r==="CHANGES_REQUESTED"?"changes":Object.hasOwn(n,s.name)?"sent":"unsent";return[s.name,{state:a,since:a==="sent"?R(n,s.name):null,github:s.github||null}]}))}d(En,"reviewOf");function $n(e,t,n,s,r,a,{held:c,needsApproval:l}){return n?.kind===ue.install?"builder":s?"checking":n?"builder":c&&e==="review"?"merge":r&&e==="review"?"owner":e==="review"&&t?.state==="OPEN"&&t.isDraft?a?"ci":"ready":e==="review"?xt(t,l)?"merge":"reviewers":null}d($n,"waitsOnOf");const xt=d((e,t)=>e?.reviewDecision==="APPROVED"||!t&&!["REVIEW_REQUIRED","CHANGES_REQUESTED"].includes(e?.reviewDecision),"reviewed"),Ne=/(^|\/)prototype-[\w-]+\.html/,An={reviewers:"Waiting for PR reviewers",merge:"Approved, merges once CI and the merge state allow",ci:"Marked ready for review once CI passes"},Ve={waiting:"Approved, Merge shows once CI and the merge state allow",ready:"Approved and green: tap Merge",merging:"Merging"},ot={auto:"Ready, merges once CI and the merge state allow",waiting:"Ready, Merge shows once CI and the merge state allow",ready:"Ready and green: tap Merge"},Bn=d(e=>`Verified: tap Merge to land it on ${e}`,"heldNext"),_n="Fix the failing CI",Rn="Your reply waits on the orchestrator",Mn="Tap Done",In=["status","agent","ask-link","command",$e,De.answer],qn=d(e=>(e.who==="claude"||e.via==="github")&&!In.includes(e.kind)&&(e.kind!==Qe||gt(e).fault),"countsUnread"),Cn=["lander-handoff","land-waiting"];function Dn({slug:e,itemFile:t,it:n,order:s,prs:r,repo:a,remote:c,base:l,builder:u,reachedPhase:m,agents:f,worktree:p,eta:h,thread:v,events:_,working:x,said:P,askedAt:C,topicItems:L,prSlack:T,boardReviewers:W,now:w,bumpedAt:b,holdAsk:i,closedAt:S,mergeAt:oe,autoMerge:me,skipDraft:he,tickets:K}){const F=r.map(k=>({repo:k.repo,number:k.number,...k.gh||k.kept||{},url:(k.gh||k.kept)?.url||dn(k),status:xn(k.gh,k.merged_at)})),ee=an(r.map(k=>k.gh)),I=r[ee]?.gh||null,G=F[ee]?.status??null,ze=n.lane||null,U=!!S&&String(S)>String(n.lane_at||"");U&&(n={...n,lane:"done",closed_at:S,reopened_at:void 0});const D=[n.closed_at,...r.flatMap(k=>[k.merged_at,k.gh?.mergedAt])].filter(Boolean).map(String).sort().pop()||null,we=String(D||""),ye=F.length>0&&F.every(k=>k.status===V.closed),be=(n.lane==="done"||n.reopened_at||G===V.merged)&&!ye&&([...P.filter(k=>k.kind==="item-message").map(k=>k.ts),...C].map(String).filter(k=>k>we).sort().pop()||n.reopened_at)||void 0,Le=n.answered_at&&!n.phase&&!n.closed_at&&!be?String(n.answered_at):void 0,j=be||Le,Re=n.owner_step&&!U?String(n.owner_step):null,Je=(n.lane==="done"||G===V.merged)&&!ye,H=!!j&&!!n.next&&String(n.next_at||"")>String(n.reopened_at||D||"");j&&!H&&(n={...n,next:void 0});const X=st(f),Te=j&&P.filter(k=>String(k.ts)>we&&(k.state==="waiting"||k.state==="working")).map(k=>String(k.ts)).sort()[0]||null,Se=!!Te,ve=`${e}/${n.id}`,xe=en(t,W),Pe=Object.fromEntries(Object.entries(Jt(t,n,ve,L,zt(T,r))).map(([k,de])=>[k,Zt(de.ts)])),te=Object.values(Pe).filter(Boolean).sort()[0]||null,Ue=[...v.map(k=>k.ts),..._.map(k=>k.ts)].sort().pop()||null,je=[...v.filter(k=>qn({...k,who:k.who||"claude"})).map(k=>k.ts),..._.map(k=>k.reply?.at)].filter(Boolean).sort(),Y=!et(n)&&n.pushed?.branch?{branch:n.pushed.branch,at:n.pushed.at||null,host:c?.host||null}:null,z=!et(n)&&n.merge_ready?.branch?{branch:n.merge_ready.branch,at:n.merge_ready.at||null,base:l}:null,Me=!!n.rebase_run&&I?.state==="OPEN",Ie=(n.rebased||[]).at(-1),re=f.filter(k=>k.started&&!k.done&&Q(k)),Ze=!!X&&bt(vt(f));let A=vn(n,I,re.some(bt),Ze,Y||z,!!j,he,Me,re.length>0||!!X);j&&A==="todo"&&(A="progress");const We=A==="review"&&!!te&&w-Date.parse(te)>wt,ae=!!Re&&Je&&A==="done";ae&&(A="review");let N=$n(A,I,u,!!X&&A!=="done",Y,he,{held:z,needsApproval:xe.length>0});const Fe=N==="builder"&&I?.state==="OPEN"&&!I.isDraft,qe=A==="progress"&&!N&&I?.state==="OPEN"&&(!I.isDraft||he),Oe=ae||!!j&&A==="progress"&&!N&&!qe&&!Se&&!H;Oe&&(N="owner");const o=!!j&&f.some(k=>Q(k)&&String(k.started||"")>String(j)),g=A==="progress"&&!N&&(qe||!!j&&!o);g&&(A="review");const E=i&&String(i.ts)>String(n.held_at||""),$=A==="todo"&&(E?!!i.data.hold:!!n.held),y=$&&(E?i.data.until:n.pick_up_at)||null,M=A!=="done",B=!!b&&!(we&&String(b)<=we),Ke=v.filter(k=>(k.who||"claude")==="claude"&&!["status","command",$e].includes(k.kind)&&!Cn.includes(k.line)).map(k=>String(k.ts)).sort().pop()||"",le=[oe,z&&n.merge_ready.tapped].filter(Boolean).map(String).sort().pop(),Ce=N==="merge"&&!!le&&le>Ke,Ee=v.filter(k=>(k.kind==="status"||k.kind===Qe)&&String(k.ts)>String(le)).sort((k,de)=>String(k.ts).localeCompare(String(de.ts))).at(-1),ne=Ee?.line==="land-waiting"?`${Ve.merging} \xB7 ${Ee.text[0].toLowerCase()}${Ee.text.slice(1)}`:Ve.merging,J=v.filter(k=>!["status",$e].includes(k.kind)).sort((k,de)=>String(k.ts).localeCompare(String(de.ts))).at(-1),O=A==="todo"&&J?.line===ht?J.text:null,ie=j||f.filter(Q).map(k=>k.started).filter(Boolean).map(String).sort().pop()||null,Ge=I?.reviewDecision==="APPROVED",Kt=Y&&N==="owner"?`merge ${Y.branch} into ${l}`:z&&N==="merge"?Ce?ne:Bn(l):N==="merge"&&!me?Ce?ne:(Ge?Ve:ot).waiting:N==="merge"&&!Ge?ot.auto:An[N],Gt=G===V.draft?`Review draft PR #${F[ee].number}`:null,Qt=!Me&&Ie?.to&&Ie.to===I?.headRefOid?`Rebased onto ${Ie.base||l}, pushed${I.mergeable==="MERGEABLE"?" \xB7 PR is clean again":""}`:null,Ht=Me&&N==="checking"?f.flatMap(k=>k.calls).sort((k,de)=>String(k.at).localeCompare(String(de.at))).at(-1)?.text??null:null;return{key:ve,kind:"work",order:s,file:e,fileTitle:t.title||e,id:n.id,ref:nt(t,n,K),title:n.title,storedLane:ze,created:n.created||null,reviewSince:g&&j||n.review_since||te||n.merge_ready?.at||n.pushed?.at||n.created||null,progressSince:ie,closedAt:A==="done"?D:null,internal:t.internal===!0,repo:t.internal===!0&&!t.repo?null:a,lane:A,waitsOn:N,builder:N==="checking"?null:u,reachedPhase:m,agents:f,worktree:p??null,eta:h,working:x,reopened:!!be,answered:!!Le,awaitsDone:Oe,ownerStep:Oe?Re:null,ownerCheck:Oe&&Re&&n.owner_check?{words:cn(un(n.owner_check.check)),broken:n.owner_check.broken||null}:null,stagedAt:A==="todo"&&n.phase==="staging"&&n.staged_at||null,roundAt:n.round_at||null,deps:n.deps||[],blockedUntil:n.blocked_until||null,blockReason:n.block_reason||null,held:$,heldUntil:y,risky:!!n.risky,bumpable:M,bumpedAt:M&&B?b:null,holdable:A!=="done",hasNotes:!!(n.plan||String(n.notes||"").trim()),finishable:A!=="done",merging:Ce,refusal:O,manualSteps:n.manual_steps||[],fromAsk:n.from_ask||null,unfiled:!!n.unfiled,filedHeld:!!n.filed_held,next:Fe||A==="done"||N==="checking"?null:g&&Se?Rn:qe?_n:Qt||Kt||n.next||Gt||null,rebaseFailed:Ht,branch:n.branch||I?.headRefName||Y?.branch||null,pushed:A==="done"||ae?null:Y,mergeReady:A==="review"?z:null,stale:A!=="done"&&(We||!!u?.stale),stalled:n.stalled?.reason||null,landStopped:A==="review"&&z&&n.merge_ready.stopped&&String(n.merge_ready.stopped)>String(n.merge_ready.tapped||"")?{words:At("land"),at:n.merge_ready.stopped}:null,ticket:K?.source==="linear"&&!n.ticket&&n.linear?.length?null:Sn(K,n.ticket,{repo:a}),ticketSource:K?.source||null,linear:(n.linear||[]).map(k=>K?.source==="linear"&&pt(K,k,{repo:a})||yt(k,K)),pr:F[ee]||null,prs:F,reviewers:xe.map(k=>k.name),review:En(xe,I||r[ee]?.kept,Pe),inReviewSince:te,threadCount:v.length+_.length,lastTs:Ue,othersAt:je,grilling:Bt("grill",_,f,C),prototyping:Bt("prototype",_,f,C),storedPhase:n.phase||null,phase:null,recheckAt:n.recheck_at||null,updatedAt:I?.mergedAt||I?.updatedAt||r[ee]?.merged_at||u?.at||Ue||null,ask:null,fold:null,action:null,install:A==="done"?null:Ln(n.install,I),waitFacts:Nn(n,{agents:f,thread:v,events:_,refusedAt:O?J.ts:null,replyAt:g?Te:null})}}d(Dn,"workItem");function Nn(e,{agents:t,thread:n,events:s,refusedAt:r,replyAt:a}){const c=new Set(n.filter(f=>f.kind===De.answer).map(f=>f.ask)),l=n.filter(f=>f.kind===De.ask&&!c.has(f.ask)).sort((f,p)=>String(f.ts).localeCompare(String(p.ts)))[0],u=d(f=>s.filter(p=>at(p,f)).pop()?.ts||null,"requestAt"),m=n.filter(f=>(f.who||"claude")==="claude"&&!["status","agent","command",$e].includes(f.kind)&&f.line!==ht).map(f=>f.ts);return{handedBackAt:st(t),next:e.next||null,ask:l?{at:l.ts,text:l.text}:null,unasked:n.filter(f=>f.line==="planner-unasked").sort((f,p)=>String(f.ts).localeCompare(String(p.ts))).map(f=>({at:f.ts,kind:f.detail})).pop()||null,grillAt:u("grill"),prototypeAt:u("prototype"),refusedAt:r,replyAt:a,unblockedAt:e.unblocked_at||null,unverified:t.some(f=>f.calls.some(p=>!f.verified||String(p.at)>String(f.verified.at))),writes:[...m,...t.flatMap(f=>[f.verified?.at,f.started])].filter(Boolean).map(String).sort()}}d(Nn,"waitFactsOf");function Ln(e,t){if(!e?.url)return null;const n=e.sha?String(e.sha).toLowerCase():null,s=t?.headRefOid?String(t.headRefOid).toLowerCase():null;return{url:e.url,label:e.label||null,builtAt:e.built_at||null,sha:n,older:!!(n&&s&&!s.startsWith(n))}}d(Ln,"installOf");function Tn(e,{needsApproval:t=!0}={}){if(e?.state!=="OPEN")return[`PR is ${String(e?.state||"unknown").toLowerCase()}`];const{state:n,pending:s,failing:r}=e.checks||{};return[e.isDraft&&"it is a draft",!xt(e,t)&&`review: ${String(e.reviewDecision||"none").toLowerCase().replace(/_/g," ")}`,n==="fail"&&`failing: ${r?.length?r.join(", "):"a check"}`,n==="pending"&&`pending: ${s?se(s,"check"):"checks"}`,e.mergeStateStatus!=="CLEAN"&&`merge state: ${String(e.mergeStateStatus||"unknown").toLowerCase()}`].filter(Boolean)}d(Tn,"mergeBlockers");const Pn=d((e,t)=>!Tn(e,{needsApproval:t}).length,"mergeable");function Un(e,t,n){if(pe(e))return null;const s=`#selectedCard=${encodeURIComponent(e.key)}`;if(e.stalled)return{kind:q.stalled,url:s,label:`stalled: ${e.stalled}`};if(jn(e)){const r=t.get(e.questions.first);return Ne.test(r?.url||"")?{kind:q.pick,url:`questions.html#${r.id}`,label:"Prototypes ready: pick a take"}:{kind:q.questions,url:`questions.html#${e.questions.first}`,label:`Answer ${se(e.questions.open,"question")}`}}return e.waitsOn==="ready"?{kind:q.ready,url:e.pr.url,label:`Review draft PR #${e.pr.number}`}:e.waitsOn==="merge"&&e.manualSteps.length&&!e.mergeReady?{kind:q.steps,url:s,label:"Run the manual steps, then merge"}:e.waitsOn==="merge"&&(!n||e.mergeReady)&&!e.merging&&e.prs.every(r=>["MERGED","CLOSED"].includes(r.state)||Pn(r,e.reviewers.length>0))?{kind:q.merge,url:s,label:"Merge"}:null}d(Un,"actionOf");const jn=d(e=>!!(e.questions&&e.questions.state!=="resolved"&&e.questions.open>0),"asking"),rt=new Set([q.pick,q.questions]);function Ot(e){return e.questions?ce.openQuestions:null}d(Ot,"actionButtonOf");const Wn=d(e=>e.kind==="work"&&e.lane==="todo"&&!e.action&&!e.unpicked,"buildableOf"),Fn=d((e,t)=>/^item:/.test(e.topic||"")&&Ne.test(e.url||"")&&!(e.options||[]).some(n=>n.id===t),"picksNoTake");function Kn(e,t){const n=e.filter(a=>a.topic===`item:${t}`),r=[...n.filter(a=>Ne.test(a.url||"")).flatMap(a=>a.answers.map(c=>({q:a,a:c,again:Fn(a,c.choice)}))),...n.filter(a=>a.request).map(a=>({q:a,a:a.request,again:!0}))].sort((a,c)=>String(a.a.ts).localeCompare(String(c.a.ts))).at(-1);return r?.again?{id:r.q.id,note:r.a.note.replace(/\s+/g," ").trim()}:null}d(Kn,"noTakePicked");const Gn="Prototype again",Qn=Object.freeze({[q.pick]:ce.openQuestions,[q.questions]:ce.openQuestions,[q.ready]:ce.github,[q.steps]:ce.github,[q.merge]:ce.merge,[q.stalled]:ce.reply}),Hn="Merges once unblocked",Vn=d(e=>`Blocked ${[e.blockedBy.length&&`by ${e.blockedBy.map(t=>t.ref).join(", ")}`,e.blockedUntil&&`until ${e.blockedUntil}`].filter(Boolean).join(" and ")}`,"mergeBlockedWords");function Xn(e,t,n){if(e.action=Un(e,t,n),e.mergeBlocked=e.action?.kind===q.merge&&e.blocked?Vn(e):null,e.mergeBlocked&&Object.assign(e,{action:null,next:Hn}),e.action?.kind===q.questions&&e.questions.fromAsks){Object.assign(e,{action:null,waitsOn:"owner",next:e.action.label,actionButton:Ot(e),resolvedBy:null});return}e.awaitsDone&&=!e.action,e.awaitsDone||Object.assign(e,{ownerStep:null,ownerCheck:null}),e.actionButton=Ot(e),e.resolvedBy=Qn[e.action?.kind]||null,e.action?.kind===q.merge&&!e.mergeReady&&(e.next=(e.pr?.reviewDecision==="APPROVED"?Ve:ot).ready),e.awaitsDone&&Object.assign(e,{lane:"review",next:e.ownerStep||Mn,bumpable:!1,bumpedAt:null});const s=e.lane==="todo"||e.waitsOn==="ready"||e.lane==="progress"&&e.waitsOn==="owner";if(!e.action||!s||e.stalled)return;const r=e.lane==="todo"&&rt.has(e.action.kind)?"todo":"review";Object.assign(e,{lane:r,waitsOn:e.waitsOn==="ready"?"ready":"owner",next:e.action.label})}d(Xn,"placeOwnerWait");const Et=d((e,t)=>e?e!=="todo":t.some(Q),"started"),$t="none set yet";function vo(e,t){const n=t.filter(s=>s?.started);return e.next||et(e)||e.pushed||e.held||e.lane==="done"||st(n)?!1:!n.some(s=>!s.done)&&Et(e.lane,n)}d(vo,"owesNext");const fe="visual",ge="helper",Yn=new Set(["grill","prototype",fe]),Z=d(e=>Yn.has(e.kind),"plans"),Q=d(e=>!Z(e),"builds"),zn={grill:"grilling",prototype:"prototyping"},Jn=d((e,t)=>`${e} ${t} by orchestrator`,"orchestratorDid"),At=d(e=>Jn(e,"stopped"),"stoppedWords"),Zn={grill:"grill-more",prototype:"prototype-request"},at=d((e,t)=>e.kind===Zn[t]&&!e.data?.question,"isRequest");function Bt(e,t,n,s){if(n.some(a=>a.kind===e&&a.started&&!a.done))return!0;const r=t.filter(a=>at(a,e)).pop();return!!(r&&!r.reply&&!s.some(a=>String(a)>String(r.ts))&&!n.some(a=>a.kind===e&&a.done&&String(a.started)>=String(r.ts)))}d(Bt,"planningOf");const xo=30*6e4;function Oo(e,t){const n=[];for(const s of e.items){if(pe(s)||(s.agents||[]).some(a=>a.kind==="prototype"&&a.started&&!a.done))continue;const r=s.prototyping&&t.filter(a=>a.data?.key===s.key&&at(a,"prototype")).pop();r&&n.push({key:s.key,request:r.id,since:r.ts});for(const a of e.owner.filter(c=>c.topic===`item:${s.key}`&&c.state==="requested"))n.push({key:s.key,request:a.request.id,question:a.id,since:a.request.ts})}return n}d(Oo,"prototypeWaits");function lt(e={},t=!1){return Object.entries(e).filter(([n,s])=>s&&typeof s=="object"&&(t||!n.startsWith("past-"))).map(([n,s])=>({name:n,kind:_t(s.kind)||null,model:s.model||(s.kind==="opus"||s.kind==="sonnet"?s.kind:null),label:s.label||null,started:s.started||null,eta:s.done?null:s.eta||null,done:s.done||null,log:s.session?.log||null,pid:s.session?.pid??null,calls:Array.isArray(s.calls)?s.calls:[],verified:s.verified||null,stopped:s.stopped||null,handed_back:s.handed_back||null,...s.pause?{pause:s.pause}:{},...s.kind===ge?{writes:!!s.writes,requested:s.requested||null}:{},...s.waits?{waits:s.waits}:{}})).sort((n,s)=>String(n.started||"").localeCompare(String(s.started||""))||n.name.localeCompare(s.name))}d(lt,"agentsOf");function it(e={}){return Object.values(e).filter(t=>t?.worktree?.path).sort((t,n)=>String(t.started||"").localeCompare(String(n.started||""))).at(-1)?.worktree.path??null}d(it,"worktreeOf");function es(e,t=[]){const n=e.filter(Q).map(s=>String(s.started||"")).filter(Boolean).sort().pop();return n===void 0?null:t.filter(s=>s.kind==="status"&&s.phase&&!s.planner&&String(s.ts)>=n).sort((s,r)=>String(s.ts).localeCompare(String(r.ts))).pop()?.phase||null}d(es,"reachedPhaseOf");function ts(e,t=[],n,s=null,r=null,a=!1){const c=e.filter(b=>b.started&&!b.done&&b.kind!==fe),l=c.every(Z),u=l?c:c.filter(Q),m=u.map(b=>String(b.started||"")).sort()[0];if(m===void 0)return null;const f=t.filter(b=>b.kind==="status"&&String(b.ts)>=m&&(l||!b.planner)).sort((b,i)=>String(b.ts).localeCompare(String(i.ts))).pop(),p=u.filter(b=>b.kind!==ge).at(-1),h=u.some(b=>b.kind===ue.install)?ue.install:p?_t(p.kind):"claude",v=l?null:u.find(b=>b.stopped&&String(b.stopped.at)>=String(b.started))?.stopped,_=f?.ts||m,x=v?v.at:s!==null&&s>Date.parse(_)?new Date(s).toISOString():_,P=f?f.phase||f.planner?f.text.replace(": "," \xB7 "):f.text||null:l?zn[h]:null,C=n-Date.parse(x),L=l?null:u.find(b=>b.pause)?.pause??null,T=!l&&!v&&(r==="held"||!!L?.paused),W=l||T?null:v?!1:r,w=T?!1:W===null?C>=mn:!W;return{progress:P,phase:f?.phase||null,at:_,kind:h,planner:l,silentSince:x,stale:w,alive:W,held:T,quiet:!!L||W===!0&&!a&&C>=hn,stopped:v?At(v.run):null,...L?{pause:{cause:L.cause,words:L.words,paused:!!L.paused}}:{}}}d(ts,"builderOf");const Eo={blocked:["nothing blocks it","nothing blocks it"],held:["you unhold it","unheld"],usage:["the usage pause lifts","the usage pause lifted"],bumped:["a slot frees","a slot freed"]},ns=15*6e4,ss=d(e=>(e.agents||[]).find(t=>t.name==="main"&&t.started&&!t.done&&Q(t))??null,"mainBuild"),os=d((e,t,n,{now:s,usageHeld:r})=>e.blocked||e.held||r(n??"claude")||!!(t.until&&s<Date.parse(t.until)),"stillPaused");function rs(e,{now:t=Date.now(),usageHeld:n}){const s={ask:[],drop:[],stop:[],resume:[]},r=[];for(const a of e){if(a.kind!=="work"||a.lane!=="progress")continue;const c=ss(a);if(!c)continue;const{pause:l}=c;if(!l){a.builder?.phase!=="landing"&&n(c.kind??"claude")&&s.ask.push(a.key);continue}const u=os(a,l,c.kind,{now:t,usageHeld:n});if(l.paused){u||r.push({key:a.key,at:l.paused});continue}!u&&l.cause!=="bumped"?s.drop.push(a.key):t-Date.parse(l.at)>=ns&&s.stop.push(a.key)}return s.resume=r.sort((a,c)=>String(a.at).localeCompare(String(c.at))).map(a=>a.key),s}d(rs,"pauseWork");function $o(e,t,n){const s=rs(t,n).drop;return e.filter(r=>s.includes(r))}d($o,"confirmedDrops");const dt={opus:"Claude Opus",sonnet:"Claude Sonnet",codex:"Codex"},as=d(({model:e,kind:t})=>dt[e]||dt[t]||(t==="claude"?dt.opus:null),"modelName"),_t=d(e=>e==="opus"||e==="sonnet"?"claude":e,"providerOf");function Ae(e){const t=as(e),{kind:n}=e,s=e.label?.replace(/\bbuilder\b/,"implementer").replace(/\bBuilder\b/,"Implementer"),r=d(c=>c[0].toLowerCase()+c.slice(1),"lower");if(t&&Z(e))return`${t} ${n}`;if(t)return`${t} ${r(s?.replace(/^(?:claude\s+)?(?:opus|sonnet|codex)\b\s*/i,"")||"implementer")}`;const a=n?n[0].toUpperCase()+n.slice(1):"";return a?s?s.toLowerCase().includes(n.toLowerCase())?s:`${a} ${r(s)}`:a:s||"Implementer"}d(Ae,"agentName");const Rt=d((e,t)=>!!e.resolved&&(!e.resolved_at||String(e.resolved_at)>=String(t)),"resolvedSince");function ls(e,t,n=[],s=[],r=[]){const a=t.filter(x=>x.data?.id===e.id),c=a[a.length-1]||null,l=r.filter(x=>x.data?.question===e.id).at(-1),u=d((x,...P)=>!!x&&P.every(C=>String(x.ts)>String(C||"")),"after"),m=!!(e.resolved&&e.resolved_at&&c&&String(c.ts)>e.resolved_at),f=n.filter(x=>x.data?.question===e.id&&u(x,c?.ts,l?.ts)).at(-1),p=u(l,c?.ts,f?.ts,e.resolved_at),h=e.resolved&&!m&&!p,v=h?s.filter(x=>x.data?.question===e.id&&String(x.ts)>String(e.resolved_at||"")).at(-1):null,_=p?"open":h?"resolved":f?"requested":c?c.reply?"replied":"answered":"open";return{...e,state:_,reopened:p,request:f?{id:f.id,ts:f.ts,note:f.data.note||"",choice:f.data.choice||null}:null,reask:v?{id:v.id,ts:v.ts}:null,answers:a.map(x=>({ts:x.ts,choice:x.data.choice||null,note:x.data.note||"",files:x.data.files||[],reply:x.reply,replies:x.replies,acted:Rt(e,x.ts)}))}}d(ls,"ownerQuestion");const ke=d(e=>e.round??(Ne.test(e.url||"")?1:0),"roundOf");function is(e,t){const n=d((s,r)=>s.confirm_of||(s.options||[]).some(a=>a.id===r.choice),"settles");return e.filter(s=>ke(s)===t&&s.answers.length).map(s=>[s,s.answers.at(-1)]).filter(([s,r])=>n(s,r)).map(([,s])=>s).sort((s,r)=>String(s.ts).localeCompare(String(r.ts))).at(-1)}d(is,"roundSettledBy");function ds(e){const t=e.find(r=>r.request&&!e.some(a=>ke(a)>ke(r)));if(t)return{n:ke(t)+1,state:"making"};const n=Math.max(0,...e.map(ke));if(!n)return null;const s=is(e,n);return s?{n,state:"closed",take:s.choice}:e.some(r=>ke(r)===n&&r.state!=="resolved")?{n,state:"back"}:null}d(ds,"roundState");function cs(e){const t=e.filter(n=>Ne.test(n.url||"")).map(n=>({n:ke(n),q:n.id,url:n.url,confirm:!!n.confirm_of,state:n.state})).sort((n,s)=>n.n-s.n);return t.length?{open:t.some(n=>n.state==="open"),rounds:t}:null}d(cs,"prototypesOf");const Be=d((e,t,n)=>{const s=e.get(t);s?s.push(n):e.set(t,[n])},"add"),_e=d((e,t)=>{const n=new Map;for(const s of e)Be(n,t(s),s);return n},"groupBy");function us(e,t,n=new Set){const s=new Set(e.map(c=>c.id)),r=[...e];t.some(c=>!s.has(c.topic))&&r.push({id:"",title:"Other"});const a=_e(t,c=>s.has(c.topic)?c.topic:"");return r.map(c=>{const l=a.get(c.id)||[],u=d(p=>l.filter(h=>h.state===p).length,"count"),m=l.every(p=>p.state==="resolved")||n.has(c.id)&&!u("open"),f=l.length&&m?"resolved":"open";return{...c,state:f,questions:l.map(p=>p.id),open:u("open"),answered:u("answered"),replied:u("replied"),resolved:u("resolved"),round:ds(l)}}).filter(c=>c.questions.length)}d(us,"ownerTopics");const Xe={implement:"Implementation requested",prototype:"Prototype requested",grill:"Grill requested",visual:"Visual requested",reask:"Re-ask requested",hold:"Held",resume:"Resumed",done:"Marked done",staged:"Marked as staging",readied:"Marked as ready",related:"Related to",unrelated:"Unrelated from",followup:"Follow-up","followup-of":"Follow-up of"},Mt={"grill-more":"grill","prototype-request":"prototype","visual-request":"visual","reask-request":"reask"},It={"mark-ready":"Mark ready",...Object.fromEntries(Object.entries(Mt).map(([e,t])=>[e,Xe[t]]))},ps=["grill-more","prototype-request","visual-request"],fs="answers submitted",qt={reply:"Reply",build:"Implement"},gs=d(e=>qt[e.data.intent],"intentLabel"),ks=d((e,t)=>{if(e.kind!=="prototype-request"||!t.has(e.data.question))return e.data.text||(e.data.files?.length?"":R(It,e.kind))||"";const n=t.get(e.data.question),s=(n.options||[]).find(r=>r.id===e.data.choice);return[Dt(t,n),s&&`${s.id}. ${s.label}`,e.data.note].filter(Boolean).join(`
2
+ \u2192 `)},"actionText"),Ct=d((e,t)=>[...e.keys()].indexOf(t)+1,"numberOf"),Dt=d((e,t)=>`Question ${Ct(e,t.id)} \xB7 ${t.question}`,"numbered"),ms="question reopened",Ye=d(e=>e.data?.shared_by?.login?{by:e.data.shared_by.name||e.data.shared_by.login}:{},"byOf"),hs=d((e,t)=>{const n=t.get(e.card);return{...e,text:`${Xe[e.command]} ${n?`${n.ref}: ${n.title}`:e.card}`,link:`#selectedCard=${encodeURIComponent(e.card)}`}},"linkLine"),Nt=d(e=>({kind:"command",command:e,request:!0,mark:Xe[e]}),"commandLine"),ws=d((e,t)=>{if(e.kind==="item-message")return qt[e.data.intent]?{status:gs(e)}:{};const n={request:!0,command:Mt[e.kind]};return ps.includes(e.kind)?(e.data.question?t.has(e.data.question):String(e.data.text||"").trim()||e.data.files?.length)?{status:It[e.kind]}:n:e.kind==="reask-request"?n:{}},"requestOf"),Lt=d(e=>[...e.filter(t=>t.who==="claude"&&!["status","agent","command",$e,De.answer].includes(t.kind)).map(t=>t.ts),...e.filter(t=>t.kind==="ask").map(t=>t.reply?.at)].filter(Boolean).map(String).sort().pop()||"","claudeAtOf");function Tt(e,t={}){const n=new Map,s=new Map;for(const p of t.items||[])Be(n,p.topic,p),s.set(p.id,p.topic);const r=new Map,a=new Map,c=new Map,l=new Map,u=new Map,m=new Map,f=new Map;e.forEach((p,h)=>{f.set(p,h),p.data?.key&&kn.includes(p.kind)&&Be(r,p.data.key,p),p.kind==="owner-answer"&&s.has(p.data?.id)&&Be(a,s.get(p.data.id),p),p.kind===mt&&s.has(p.data?.question)&&Be(c,s.get(p.data.question),p),p.kind==="ask"&&l.set(p.id,p)});for(const p of e.filter(h=>h.kind==="ask-edited").sort((h,v)=>String(h.ts).localeCompare(String(v.ts)))){u.set(p.data?.id,p.data?.text);for(const h of p.data?.files||[])Be(m,p.data?.id,h)}return{byKey:r,answers:a,reopens:c,asks:l,edits:u,editFiles:m,questions:n,order:f}}d(Tt,"threadIndex");const ct=d((e,t)=>{const n=t.filter(s=>s?.length);return n.length>1?n.flat().sort((s,r)=>e.order.get(s)-e.order.get(r)):[...n[0]||[]]},"inLogOrder"),ys=/; its log is \S*\/\.claude\/kickflip\/logs\/([^/\s]+\.log)\.$/,bs=d(e=>{const t=!e.log&&typeof e.text=="string"?ys.exec(e.text):null;return t?{...e,text:`${e.text.slice(0,t.index)}.`,log:t[1]}:e},"withLog");function Ss(e,t){const n=t.run?e.find(s=>s.started===t.run):e.filter(s=>Z(s)===!!t.planner&&s.started&&String(s.started)<=String(t.ts)&&(!s.done||String(t.ts)<=String(s.done))).pop();return n?{agent:Ae(n),run:ut(e,n),running:!n.done}:{}}d(Ss,"agentOfLine");function ut(e,t){return t.label!==He?t.started:e.filter(n=>Q(n)&&n.label!==He&&n.started&&String(n.started)<String(t.started)).pop()?.started??t.started}d(ut,"sectionOf");function vs(e,{lines:t=[],events:n=[],owner:s={},working:r={},fromAsk:a=null,links:c=[],agents:l={},moved:u=[],cards:m=new Map,index:f=Tt(n,s)}){const p=e.startsWith("ask:")?[e.slice(4)]:[a,...u].filter(Boolean),h=[...new Set([e,...p.map(i=>`ask:${i}`)])],v=new Map((f.questions.get(`item:${e}`)||[]).map(i=>[i.id,i])),_=f.answers.get(`item:${e}`)||[],x=new Set([...v.values()].map(i=>i.round_of).filter(Boolean)),P=lt(l,!0).filter(Q).map(i=>String(i.started||"")).filter(Boolean),C=new Set(_.filter(i=>Rt(v.get(i.data.id),i.ts)||x.has(i.data.id)||P.some(S=>S>String(i.ts))).map(i=>i.id)),L=lt(l,!0),T=[...L.flatMap(i=>[...i.started?[{ts:i.started,who:"claude",kind:"agent",text:`${Ae(i)} started`,agent:Ae(i),run:ut(L,i),finished:!1,eta:i.done?null:i.eta,...i.log?{log:i.log}:{},...Z(i)?{planner:!0}:{}}]:[],...i.done?[{ts:i.done,who:"claude",kind:"agent",text:`${Ae(i)} finished`,agent:Ae(i),run:ut(L,i),finished:!0,eta:null,...Z(i)?{planner:!0}:{}}]:[],...i.calls.length?[{ts:i.done||i.calls.at(-1).at,who:"claude",kind:"calls",text:Ae(i),calls:i.calls.map(S=>S.text),verified:i.verified}]:[]]),...t.map(bs).map(i=>i.card?hs(i,m):i).map(i=>({ts:i.ts,who:i.who||"claude",...i.log?{log:i.log}:{},...i.kind==="status"?{kind:"status",...i.planner?{planner:!0}:{},...Ss(L,i)}:{},...i.kind===fe||i.kind===$e?{kind:i.kind}:{},...i.kind===Qe?{kind:Qe,line:i.line,...gt(i),...i.detail?{detail:i.detail}:{}}:{},...i.command?Nt(i.command):{},...i.card?{card:i.card}:{},...Object.values(De).includes(i.kind)?{kind:i.kind,ask:i.ask}:{},text:i.text||"",html:i.html||null,link:i.link||null,via:i.via||null,...i.by?{by:i.by}:{}})),...ct(f,h.map(i=>f.byKey.get(i))).map(i=>({ts:i.ts,who:"love",via:"site",kind:i.kind,text:ks(i,v),files:i.data.files||[],eventId:i.id,reply:i.reply,replies:i.replies,...ws(i,v),...Ye(i)})),..._.map(i=>{const S=[i.data.label||i.data.choice,i.data.note].filter(Boolean).join(" \xB7 ");return{ts:i.ts,who:"love",via:"questions",kind:i.kind,text:`${Dt(v,v.get(i.data.id))}
3
+ \u2192 ${S}`,files:i.data.files||[],eventId:i.id,reply:i.reply,replies:i.replies,status:fs,...Ye(i)}}),...(f.reopens.get(`item:${e}`)||[]).map(i=>({ts:i.ts,who:"love",kind:i.kind,request:!0,mark:ms,text:`Question ${Ct(v,i.data.question)} was reopened`,...Ye(i)})),...ct(f,[...new Set(p)].map(i=>f.asks.has(i)?[f.asks.get(i)]:[])).flatMap(i=>[{ts:i.ts,who:"love",via:"ask",kind:i.kind,text:i.data?.text||"",files:i.data?.files||[],eventId:i.id,reply:i.reply,replies:i.replies,...u.includes(i.id)?{moved:!0}:{},...Ye(i),...typeof i.data?.from?.title=="string"?{from:i.data.from.title}:{}},...i.data?.quick===!0?[{ts:i.ts,who:"love",...Nt("implement"),text:Xe.implement}]:[],...c.map(S=>({ts:i.ts,who:"claude",kind:"ask-link",text:S.folded?`Moved to ${S.ref}: ${S.title}`:`${S.became?"Became":"Added to"} ${S.ref}`,link:`#selectedCard=${encodeURIComponent(S.key)}`,html:null,via:null}))])].sort((i,S)=>String(i.ts).localeCompare(String(S.ts))),W=Lt(T),{edits:w,editFiles:b}=f;for(const i of T){if(!i.eventId)continue;(i.kind==="ask"||i.kind==="item-message")&&typeof w.get(i.eventId)=="string"&&Object.assign(i,{text:w.get(i.eventId),edited:!0,files:[...i.files,...b.get(i.eventId)||[]]});const S=i.kind==="ask"&&(c.length>0||!!i.moved);i.state=i.reply?"replied":S||C.has(i.eventId)||W>String(i.ts)?"answered":R(r,i.eventId)?"working":"waiting",i.canDelete=i.kind==="item-message"&&(i.state==="working"||i.state==="waiting"),i.canEdit=i.canDelete}return xs(T)}d(vs,"threadOf");const Pt=["waiting","working","answered","replied"];function xs(e){const t=new Map;for(const n of e)n.kind==="owner-answer"&&t.set(n.ts,[...t.get(n.ts)||[],n]);return e.flatMap(n=>{if(n.kind!=="owner-answer")return[n];const s=t.get(n.ts);return s.length===1?[n]:s[0]!==n?[]:[{...n,text:s.map(r=>r.text).join(`
4
4
 
5
- `),files:s.flatMap(r=>r.files),state:s.map(r=>r.state).sort((r,a)=>Pt.indexOf(r)-Pt.indexOf(a))[0],reply:void 0,answers:s.map(r=>({eventId:r.eventId,state:r.state,reply:r.reply,replies:r.replies,text:r.text}))}]})}d(xs,"foldSubmits");const Ut=d(e=>(e.answers||[e]).filter(t=>t.eventId).map(t=>[t.eventId,t.state]),"stateEntries");function Os(e,t,n,s,r,a){const c=d((p,w)=>{const v=a.filter(x=>x.kind==="wave-triage"&&x.data?.[p]===w).pop(),_=r.filter(x=>x.topic===`${p}:${w}`&&(x.state==="open"||x.state==="answered")).length;return{running:!!(v&&!v.reply),questions:_}},"triageOf"),l=new Map(s.map(p=>[p.key,p])),u=d(p=>p.filter(w=>w.lane==="done"&&!St(w)).length,"merged"),m=n.map(p=>({l:p,cards:p.keys.map(w=>l.get(w)).filter(Boolean)})).map(p=>({...p,open:!p.l.finished_at&&p.cards.some(w=>w.lane!=="done")})).sort((p,w)=>Number(p.open)-Number(w.open));for(const{l:p,cards:w}of m)for(const v of w)v.wave={slug:p.slug,title:p.title};const f=m.filter(p=>p.open).map(({l:p,cards:w})=>({kind:"wave",slug:p.slug,title:p.title,goal:p.goal,keys:w.map(v=>v.key),next:Es(w),merged:u(w),total:w.length,triage:c("wave",p.slug)}));return e.fromWaves?[...f,...t.filter(p=>!p.finished).map(p=>({w:p,cards:s.filter(w=>w.file===p.slug&&w.kind!=="ask")})).filter(({cards:p})=>p.length).map(({w:p,cards:w})=>({kind:"file",slug:p.slug,title:p.title,goal:null,keys:w.map(v=>v.key),next:null,merged:u(w),total:w.length,triage:c("file",p.slug)}))]:f}d(Os,"waveBandsOf");function Es(e){const t=e.filter(a=>a.lane==="todo"),n=t.find(a=>a.ready&&a.buildable)||t[0];if(!n)return null;const s=n.ready&&n.buildable,r=s?"ready":n.held?"held":n.blockedBy.length?`waits on ${n.blockedBy.map(a=>a.ref).join(", ")}`:n.blockedUntil?`blocked until ${n.blockedUntil}`:n.action?"needs you":n.phase==="new"?"not ready":n.phase;return{key:n.key,ref:n.ref,ready:s,word:r}}d(Es,"nextOf");const $s=d(e=>e.items||e.phases.flat(),"waveItems");function Ao(e){const{owner:t={},topicItems:n={},events:s=[],threads:r={},prs:a={},working:c={}}=e,l=e.now??Date.now(),u=Tt(s,t),m=new Set(s.filter(o=>o.kind==="ask-withdrawn").map(o=>o.data?.id)),f=new Map(s.filter(o=>o.kind==="ask"&&!m.has(o.id)).map(o=>[o.id,o])),p=d((o,g)=>new Map(s.filter(E=>E.kind===o).sort((E,$)=>String(E.ts).localeCompare(String($.ts))).map(E=>[E.data?.[g],E.ts])),"latest"),w=p("card-unbump","key"),v=new Map([...p("card-bump","key")].filter(([o,g])=>!(String(w.get(o)||"")>String(g)))),_=p("card-done","key"),x=p("card-merge","key"),P=e.autoMerge===!0,C=e.tickets,L=new Map(s.filter(o=>o.kind==="card-hold").sort((o,g)=>String(o.ts).localeCompare(String(g.ts))).map(o=>[o.data?.key,o])),T=new Map,W=new Map(e.files.flatMap(({slug:o,itemFile:g})=>g.items.map(E=>[`${o}/${E.id}`,{ref:nt(g,E,C),title:E.title}]))),h=e.askLinks||{},b=new Map;for(const[o,g]of Object.entries(h))f.has(o)&&b.set(g,[...b.get(g)||[],o]);const i=[],S=[],oe=new Map,me=new Map,we=new Map,K=new Map,F=e.github?null:tn(e.remote);for(const{slug:o,itemFile:g,agents:E={}}of e.files){const $=e.github||g.repo||null;i.push({slug:o,title:g.title||o,status:g.status||null,internal:!!g.internal,finished:!1,reviewers:(g.reviewers||[]).map(y=>y.name)}),g.items.forEach((y,M)=>{const B=`${o}/${y.id}`,Ke=(b.get(B)||[]).filter(O=>O!==y.from_ask),le=[y.from_ask,...Ke].filter(O=>f.has(O)),Ce=new Set(le.map(O=>`ask:${O}`)),Ee=[...R(r,B)||[],...le.flatMap(O=>R(r,`ask:${O}`)||[])];y.from_ask&&T.set(y.from_ask,[...T.get(y.from_ask)||[],{key:B,ref:nt(g,y,C),became:!0}]);const ne=vs(B,{lines:Ee,events:s,owner:t,working:c,fromAsk:y.from_ask||null,moved:Ke,cards:W,index:u});for(const O of ne)for(const[ie,Ge]of Ut(O))oe.set(ie,Ge);me.set(B,Lt(ne)),S.push(Dn({slug:o,itemFile:g,it:y,order:M,repo:$,remote:F,base:e.branch||"main",prs:rn(y,$).map(O=>({...O,gh:R(a,ln(O))||null})),...(O=>({agents:O,builder:ts(O,R(r,B),l,e.moved?.[it(R(E,y.id))]??null,R(e.alive,B)??null,!!e.commandRunning?.[it(R(E,y.id))]),reachedPhase:es(O,R(r,B)),eta:O.map(ie=>ie.eta).filter(Boolean).sort().pop()||null}))(lt(R(E,y.id))),worktree:it(R(E,y.id))??y.worktree?.path??null,thread:Ee,events:[...ct(u,[B,...Ce].map(O=>u.byKey.get(O))),...le.map(O=>f.get(O))],working:ne.some(O=>Ut(O).some(([,ie])=>ie==="working")),said:ne.filter(O=>O.who==="love"&&(O.kind==="item-message"||O.kind==="owner-answer")),askedAt:(u.questions.get(`item:${B}`)||[]).filter(O=>O.asked_at).map(O=>O.asked_at),topicItems:n,prSlack:e.prSlack||{},boardReviewers:e.reviewers||[],now:l,bumpedAt:v.get(B),holdAsk:L.get(B),closedAt:_.get(B),mergeAt:x.get(B),autoMerge:P,skipDraft:e.skipDraft===!0,tickets:C}));const J=S[S.length-1];f.has(y.from_ask)&&(J.created=f.get(y.from_ask).ts),J.askMsg=ne.find(O=>O.kind==="ask"&&O.eventId===y.from_ask)||null,K.set(B,{parent:y.parent?Wt(o,y.parent):null,related:(y.related||[]).map(O=>Wt(o,O))}),J.lane==="done"&&we.set(B,J.closedAt||String(J.updatedAt||""))})}const ee=new Map(S.map(o=>[o.key,o])),I=new Map,G=e.try||{},ze=e.autoBuild===!0,U=["web","app"].includes(G.kind)?G.kind:e.files.some(({itemFile:o})=>o.items.some(g=>g.install?.url))?"app":"web";for(const o of S){if(o.kind!=="work"||o.lane==="done")continue;const g=R(G.cards,o.key)||{},E=g.head||o.pr?.headRefOid,$=U==="web"?g.sha:o.install?.sha,y=o.builder?.kind===ue.install?"running":g.state||(U==="app"&&o.install?"ready":null);o.try={kind:U,state:y,stale:!!($&&E&&!String(E).toLowerCase().startsWith(String($).toLowerCase())),url:U==="web"?null:o.install?.url||null,port:U==="web"&&y==="ready"&&g.https||null,sha:$||null,changes:g.ahead>0,script:g.script===!0,autoBuild:ze}}const D=G.main,he=D?.script&&D.sha?{slug:D.slug,branch:D.branch||"main",sha:D.sha.slice(0,7),at:D.at,kind:U,state:D.state||null,url:U==="web"?null:e.main?.install?.url||null,port:U==="web"&&(D.state==="ready"?D.https:D.serving?.https)||null,serving:U==="web"&&D.serving?{sha:D.serving.sha.slice(0,7),at:D.serving.at}:null,pull:G.pull?{running:G.pull.running===!0,error:G.pull.error||null}:null,script:pn(D.target)}:null,ye=[],be=[],Le=_e(s.filter(o=>o.kind==="owner-answer"),o=>o.data?.id),j=_e(s.filter(o=>o.kind==="prototype-request"),o=>o.data?.question),Re=_e(s.filter(o=>o.kind==="reask-request"),o=>o.data?.question),Je=_e(s.filter(o=>o.kind===mt),o=>o.data?.question),H=(t.items||[]).map(o=>ls(o,Le.get(o.id)||[],j.get(o.id)||[],Re.get(o.id)||[],Je.get(o.id)||[])),X=new Map(H.map(o=>[o.id,o])),Te=_e(H,o=>o.topic);for(const o of f.values()){const g=`ask:${o.id}`,E=R(r,g)||[],$=T.get(o.id)?.[0].key||R(h,o.id);if(!$){E.some(B=>B.line==="ask-moved")||be.push(o.id);continue}I.set(g,$);const y=E.filter(B=>B.line===fn).at(-1),M=ee.get($);if(y&&M){const B=y.title||String(u.edits.get(o.id)??o.data?.text??"").trim().split(`
6
- `)[0]||"Ask";ye.push({key:M.key,ref:M.ref,text:B,at:String(y.ts)})}}for(const o of i){const g=S.filter(E=>E.file===o.slug);if(o.finished=On(g),o.finished)for(const E of g)E.lane==="done"&&(E.fold=yn(o.slug))}for(const o of S)o.wave=null;const Se=new Set((t.topics||[]).map(o=>o.id)),ve=e.files.flatMap(({slug:o,itemFile:g})=>(g.waves||[]).map(E=>({...E,keys:$s(E).map($=>`${o}/${$}`)}))),xe=d(()=>us([...t.topics||[],...S.filter(o=>!Se.has(`item:${o.key}`)).map(o=>({id:`item:${o.key}`,card:o.key,title:`${o.ref}: ${o.title}`})),...ve.filter(o=>!Se.has(`wave:${o.slug}`)).map(o=>({id:`wave:${o.slug}`,title:o.title,summary:"Wave triage."})),...(e.fromWaves?i:[]).filter(o=>!Se.has(`file:${o.slug}`)).map(o=>({id:`file:${o.slug}`,title:o.title,summary:"Wave triage."}))],H,new Set(S.filter(pe).map(o=>`item:${o.key}`))),"topicsOf"),Pe=new Map(xe().map(o=>[o.id,o]));for(const o of S){const g=Pe.get(`item:${o.key}`);if(!g){o.questions=null,o.prototypes=null;continue}const E=g.questions.filter(M=>X.get(M)?.state!=="resolved"),$=g.questions.find(M=>X.get(M)?.state==="open")||E[0]||g.questions[0],y=g.questions.map(M=>X.get(M)).filter(M=>M?.state==="open");o.questions={topic:g.id,state:g.state,open:g.open,answered:g.answered,replied:g.replied,resolved:g.resolved,first:$,askedAt:y.map(M=>M.asked_at).filter(Boolean).sort(),fromAsks:y.length>0&&y.every(M=>M.ask)},o.prototypes=cs(g.questions.map(M=>X.get(M)))}const te=new Map(S.map(o=>[o.key,o])),Ue=new Map(ve.map(o=>[`wave:${o.slug}`,o.keys]));for(const o of S){const g=o.kind==="work"&&o.lane!=="done",E=new Set(o.deps.flatMap(y=>Ue.get(y)||[String(y).includes("/")?y:`${o.file}/${y}`]));o.blockedBy=g?[...E].map(y=>te.get(y)).filter(y=>y&&y.lane!=="done"&&!y.reopened).map(jt):[],o.blockedUntil=g?o.blockedUntil??null:null,o.blockReason=g?o.blockReason??null:null,o.blocked=o.blockedBy.length>0||!!o.blockedUntil,Xn(o,X,P),o.lane==="todo"&&o.kind==="work"&&!o.held&&Et(o.storedLane,o.agents)&&(o.lane="progress"),o.unpicked=o.kind==="work"&&o.lane==="todo"&&!!Kn(H,o.key),o.kind==="work"&&(o.phase=zs(o)),o.unpicked&&!o.action&&(o.next=Gn),o.buildable=Wn(o);const $=o.kind==="work"&&o.lane==="todo";if(o.unsorted=$&&(!!o.fromAsk||o.unfiled)&&!o.filedHeld&&o.phase==="new",o.kind==="work"){const y=o.askMsg;delete o.askMsg,o.unsorted&&y&&(o.isNew=!0,o.ask={eventId:y.eventId,state:y.state,askedAt:y.ts,edited:!!y.edited,canEdit:!0,text:y.text,files:y.files,from:y.from||null})}o.ready=$&&o.phase==="ready"&&!o.blocked&&!o.recheckAt&&!o.action,o.staging=$&&o.phase==="staging",o.kind==="work"&&(o.hostHeld=!!e.hostBusy&&o.ready&&!!o.bumpedAt&&!o.held)}_s(S,te,K);const je=new Map((t.items||[]).map(o=>[o.id,o.topic])),Y=d(o=>o.kind==="owner-answer"?je.has(o.data?.id)?/^item:(.+)$/.exec(je.get(o.data.id))?.[1]||null:"":o.kind==="ask"?`ask:${o.id}`:o.data?.key||(o.kind.startsWith("ask-")&&o.data?.id?`ask:${o.data.id}`:null),"ownCardOf"),z=d(o=>{const g=Y(o);return I.get(g)||g},"cardOf"),Me=d(o=>[_.get(o),we.get(o)].filter(Boolean).sort().pop()||"","closedAt"),Ie=d(o=>{const g=z(o);return g===null?!o.reply:!te.has(g)||!(Me(g)<String(R(c,o.id)))?!1:oe.has(o.id)?oe.get(o.id)==="working":!o.reply&&!I.has(Y(o))&&!(String(me.get(g)||"")>String(o.ts))},"unanswered"),re=s.filter(o=>R(c,o.id)&&Ie(o)).map(o=>({id:o.id,kind:o.kind,key:z(o),data:o.data,since:R(c,o.id)}));for(const o of S)o.working=re.some(g=>g.key===o.key),o.kind==="work"&&o.lane==="progress"&&!o.builder&&!o.next&&o.waitsOn!=="checking"&&!o.working&&(o.next=$t),o.sortAt=Rs[o.lane](o)||(o.lane==="review"?null:o.updatedAt)||null;for(const o of S){if(o.kind!=="work")continue;const g=(Te.get(`item:${o.key}`)||[]).filter($=>$.state==="answered").map($=>$.answers.at(-1).ts).sort().pop(),E=re.filter($=>$.key===o.key).map($=>String($.since)).sort()[0];o.orchestrator=!o.stalled&&(["progress","todo"].includes(o.lane)||o.waitsOn==="checking"||o.lane==="review"&&(o.stale||o.waitFacts.unblockedAt||o.waitFacts.replyAt))?so(o,o.waitFacts,{answeredAt:g,workingSince:E}):null,delete o.waitFacts}Gs(S,s,c,I),Qs(S,e.screening||{}),S.sort(gn);const Ze=Os(e,i,ve,S,H,s),A=xe(),We=nn({on:e.autoReview,incoming:e.incoming,records:e.reviewRecords,events:s,now:l,refs:new Map(S.filter(o=>o.kind==="work").map(o=>[o.key,o.ref]))}),ae=[...Is(S,A,H),...sn(We)],N=new Map(ae.filter(o=>o.questions).map((o,g)=>[o.topic||`item:${o.key}`,g])),Fe=d(o=>N.get(o.id)??N.size,"rankOf");A.sort((o,g)=>Fe(o)-Fe(g));const qe=new Set(ae.filter(o=>o.questions&&o.progress).map(o=>`item:${o.key}`));for(const o of A)qe.has(o.id)&&(o.progress=!0);const Oe=S.flatMap(o=>o.answered&&me.get(o.key)?[{key:o.key,id:o.id,text:o.title,at:me.get(o.key)}]:[]).sort((o,g)=>g.at.localeCompare(o.at));return ye.sort((o,g)=>g.at.localeCompare(o.at)),As({kind:U,main:he,remote:F&&{host:F.host,name:`${F.host}/${F.path}`},itemFiles:i,waveBands:Ze,items:S,moved:Object.fromEntries(I),answers:Oe,merges:ye,unfiled:be,owner:H,ownerTopics:A,reviews:We,needs:ae,working:re.length,workingOn:re,checks:Ms(e,l)},e)}d(Ao,"buildBoard");function As(e,{listen:t,prompts:n}={}){const s=[...Cs(n),...e.needs];return{...e,needs:s,needsSummary:Ds(s),checks:{...e.checks,watcher:{listening:"running",asleep:"asleep",waking:"waking"}[t]||"stopped"}}}d(As,"withHub");const jt=d(e=>({key:e.key,ref:e.ref}),"linkOf"),Wt=d((e,t)=>String(t).includes("/")?String(t):`${e}/${t}`,"linkKey"),Bs=d((e,t)=>e.ref.localeCompare(t.ref,void 0,{numeric:!0}),"byRef");function _s(e,t,n){const s=new Map,r=new Map,a=new Map,c=d((u,m,f)=>u.set(m,[...u.get(m)||[],f]),"add");for(const[u,m]of n){m.parent&&c(s,m.parent,u);for(const f of m.related)f!==u&&(c(r,u,f),c(r,f,u))}for(const u of e)for(const m of u.blockedBy||[])c(a,m.key,u.key);const l=d((u=[])=>[...new Set(u)].map(m=>t.get(m)).filter(Boolean).map(jt).sort(Bs),"cards");for(const u of e){const m=n.get(u.key)?.parent;u.parent=m?{key:m,ref:t.get(m)?.ref||m.slice(m.indexOf("/")+1)}:null,u.children=l(s.get(u.key)),u.related=l(r.get(u.key)),u.waitsOnIt=l(a.get(u.key))}}d(_s,"linkCards");const Rs={todo:d(e=>e.created,"todo"),progress:d(e=>e.progressSince,"progress"),review:d(e=>e.reviewSince,"review"),done:d(e=>e.closedAt,"done")},se=d((e,t)=>`${e} ${t}${e===1?"":"s"}`,"plural");function Ms({checked:e,watcher:t,replyAt:n,threads:s={},working:r={},files:a=[]},c){const l=Number(e?.every)||30,m=[n,t?.since,...Object.values(r),...Object.values(s).flat().filter(p=>(p.who||"claude")==="claude").map(p=>p.ts),...a.flatMap(p=>Object.values(p.agents||{}).flatMap(w=>Object.values(w||{})).map(w=>w?.done||w?.started))].filter(p=>typeof p=="string"&&!Number.isNaN(Date.parse(p))).reduce((p,w)=>p&&Date.parse(p)>Date.parse(w)?p:w,null),f=!!e?.idle;return{at:e?.at||null,every:f?null:l,idle:f,late:!f&&!!e?.at&&c-Date.parse(e.at)>2*l*6e4,claudeAt:m}}d(Ms,"checksOf");function Is(e,t,n){const s=new Set(e.map(l=>l.questions?.topic).filter(Boolean)),r=d(l=>l.find(u=>n.find(m=>m.id===u)?.state==="open")||l[0],"firstOpen"),a=t.filter(l=>l.state!=="resolved"&&l.open>0&&!s.has(l.id)).map(l=>{const u=`questions.html#${r(l.questions)}`,m=/^(?:wave|file):(.+)$/.exec(l.id)?.[1]||null;return{kind:"Question",title:l.title,text:`${l.title} \xB7 ${se(l.open,"question")}`,url:u,topic:l.id,band:m,questions:{open:l.open,url:u},ready:null,since:n.filter(f=>f.topic===l.id&&f.state==="open").map(f=>f.asked_at).filter(Boolean).sort()[0]||null}}),c=e.map(l=>{const u=l.questions&&l.questions.state!=="resolved"&&l.questions.open>0?{open:l.questions.open,url:`questions.html#${l.questions.first}`}:null,m=l.waitsOn==="ready"?l.pr.url:null,f=!u&&!m&&l.action?{label:l.action.label,url:l.action.url}:null;if(!u&&!m&&!f)return null;const p=`${l.ref}: ${l.title}`,w=[p,u&&se(u.open,"question"),m&&"Ready on GitHub",f?.label].filter(Boolean).join(" \xB7 ");return{kind:u?"Question":m?"Tap Ready":"Action needed",title:p,text:w,url:`#selectedCard=${encodeURIComponent(l.key)}`,key:l.key,questions:u,ready:m,action:f,since:l.created||null,progress:l.lane==="progress"}}).filter(Boolean);return[...a,...c].sort(qs)}d(Is,"needsOf");const qs=d((e,t)=>!!t.progress-!!e.progress||(e.since&&t.since?e.since.localeCompare(t.since):!!t.since-!!e.since),"oldestFirst");function Cs(e=[]){return e.map(t=>{const n=t.questions?.length?`Question: ${t.questions.map(s=>s.question).join(" \xB7 ")}`:`${t.tool}: ${t.detail||t.action}`;return{kind:"Prompt",title:n,text:n,url:"",prompt:t}})}d(Cs,"promptLines");function Ds(e){const t=e.filter(a=>a.prompt).length,n=e.reduce((a,c)=>a+(c.questions?.open||0),0),s=e.filter(a=>a.ready).length,r=e.filter(a=>a.review).length;return[t&&se(t,"prompt"),n&&se(n,"question"),s&&`${se(s,"draft")} waiting on Ready`,r&&`${se(r,"review")} held`].filter(Boolean).join(" \xB7 ")}d(Ds,"needsSummary");function Bo(e){const t=d((...n)=>e.items.filter(s=>n.includes(s.lane)).length,"count");return{items:e.needs.map(({kind:n,text:s,url:r})=>({kind:n,text:s,url:r})),working:e.working,summary:e.needsSummary,lanes:{review:t("review"),progress:t("progress"),todo:t("todo")},building:e.items.some(n=>(n.agents||[]).some(s=>!s.done))}}d(Bo,"needsAnswer");const Ns=d(e=>e.buildable&&e.phase==="ready"&&!e.held&&!e.blocked&&!e.recheckAt,"pullableCard"),Ls=10;function Ts(e,{cap:t=Ls,pulled:n=[],hold:s=[],taken:r=0}={}){const a=e.filter(h=>!pe(h)),c=d((h,b)=>h.started&&!h.done&&Q(h)&&!(h.kind===ge&&!h.writes)&&!h.pause?.paused&&!(h.waits&&b.some(i=>i.name===h.waits&&!i.done)),"counts"),l=a.filter(h=>!h.stalled).reduce((h,b)=>h+(b.agents||[]).filter((i,S,oe)=>c(i,oe)).length,0),u=a.filter(h=>Ns(h)&&!h.working).map(h=>h.key),m=a.filter(h=>n.includes(h.key)&&(u.includes(h.key)||h.buildable&&h.working)).map(h=>h.key),f=a.flatMap(h=>(h.agents||[]).filter(b=>b.kind===ge&&!b.started&&!b.done).map(b=>({key:h.key,name:b.name,writes:b.writes}))),p=Math.max(0,t-l-m.length-r),w=f.filter(h=>h.writes),v=[...f.filter(h=>!h.writes),...w.slice(0,p)].map(({key:h,name:b})=>({key:h,name:b})),_=Math.max(0,p-w.length),x=new Set(a.filter(h=>h.bumpedAt).map(h=>h.key)),P=u.filter(h=>!m.includes(h)&&!s.includes(h)),C=P.filter(h=>x.has(h)),L=[...C,...P.filter(h=>!x.has(h)).slice(0,Math.max(0,_-C.length))],T=C.slice(_),W=Ps(a,c).slice(0,T.length).map((h,b)=>({key:h,by:T[b]}));return{idle:!l&&!a.some(h=>h.waitsOn==="checking"),pullable:u,waiting:m,pulls:L,helpers:v,bumpOuts:W,pastCap:T,free:p}}d(Ts,"pullOf");function Ps(e,t){const n=d(s=>{const r=s.agents||[],a=r.filter(u=>t(u,r)),[c]=a;return s.lane==="progress"&&!s.bumpedAt&&!s.stalled&&s.waitsOn!=="checking"&&s.builder?.phase!=="landing"&&!(s.prs||[]).length&&!s.pushed&&!s.mergeReady&&a.length===1&&c.kind!==ge&&c.pid&&c.label!==He&&!c.pause&&!r.some(u=>u.kind===ge&&u.started&&!u.done)?String(c.started):null},"newest");return e.map(s=>({key:s.key,at:n(s)})).filter(s=>s.at).sort((s,r)=>r.at.localeCompare(s.at)).map(s=>s.key)}d(Ps,"bumpOutsOf");function _o(e,t,n){return e.filter(s=>s.kind==="work"&&!pe(s)&&s.waitsOn!=="checking"&&!(s.agents||[]).some(r=>r.started&&!r.done)).flatMap(s=>{const r=(s.prs||[]).find(c=>c.state==="OPEN"&&c.mergeable==="CONFLICTING"&&c.repo===s.repo&&c.headRefOid),a=r&&`${r.headRefOid}@${n}`;return r&&R(t,s.key)!==a?[{key:s.key,pr:r.number,branch:r.headRefName,conflict:a}]:[]})}d(_o,"rebasesDue");const Us=3;function Ro(e,{cap:t=Us}={}){const n=e.filter(l=>!pe(l)),s=n.filter(l=>(l.agents||[]).some(u=>Z(u)&&u.started&&!u.done)).length,r=n.filter(l=>l.buildable&&!["ready","staging"].includes(l.phase)&&!l.unsorted&&!l.held&&!l.working&&!l.grilling&&!l.prototyping&&!l.questions&&!(l.agents||[]).some(u=>Z(u)&&u.kind!==fe)),a=[...r.filter(l=>!l.blocked),...r.filter(l=>l.blocked)],c=a.filter(l=>l.bumpedAt);return[...c,...a.filter(l=>!l.bumpedAt).slice(0,Math.max(0,t-s-c.length))].map(l=>l.key)}d(Ro,"arrivalsOf");function Mo(e){return e.filter(t=>t.kind==="work"&&t.lane==="todo"&&t.roundAt&&["grilling","prototyping"].includes(t.phase)&&!(t.agents||[]).some(n=>Z(n)&&n.kind!==fe&&n.started&&(String(n.started)>=String(t.roundAt)||!n.done))).map(t=>({key:t.key,kind:t.phase==="grilling"?"grill":"prototype"}))}d(Mo,"roundsDue");const js=d(e=>`${fe}-${e.id}`,"visualAgent");function Io(e,t){const n=[];for(const s of e){const r=s.agents||[];if(r.some(l=>l.kind===fe&&l.started&&!l.done))continue;const a=new Set(r.map(l=>l.name)),c=t.find(l=>l.kind==="visual-request"&&l.data?.key===s.key&&!a.has(js(l)));c&&n.push({key:s.key,request:c})}return n}d(Io,"visualsDue");const Ws=d((e,t)=>e.kind==="ask"?t.get(`ask:${e.id}`)??null:e.kind==="card-added"?e.data?.key??null:null,"intakeKeyOf");function Fs(e,t,n){const s=e.get(n);return s?t.kind==="ask"?!!s.isNew:s.unfiled:!1}d(Fs,"unsorted");const Ks={ask:d((e,t)=>`Sort the new task: item notes, then item set ${e} --phase grilling or prototyping (ready, with --size, for a Quick build); merge it into a card with item relate-ask ${t.id} <card> --summary; or answer it with reply ${e}`,"ask"),"card-added":d(()=>"Link and file the card an agent added: item notes, then item set --relate and --phase","card-added")};function Gs(e,t,n,s){const r=new Map(e.map(c=>[c.key,c])),a=new Set;for(const c of t){const l=Ws(c,s);!l||a.has(l)||!Fs(r,c,l)||(a.add(l),r.get(l).orchestrator={kind:"intake",since:String(c.ts),picked:R(n,c.id)||null,next:Ks[c.kind](l,c)})}}d(Gs,"intakeWaits");function Qs(e,t){for(const n of e){const s=R(t,n.key);s&&(n.orchestrator={kind:"screen",since:s.since,picked:null,next:`Screen the grill's questions ${s.ids.join(", ")}: question settle <id> --note for each the board already answers, then question publish ${n.key}; left 15 minutes unscreened, they reach the owner as they are`})}}d(Qs,"screenWaits");function Hs(e){return e.filter(t=>t.lane==="todo"||t.lane==="review"&&t.stale).map(t=>JSON.stringify([t.key,t.title,t.deps||[]])).sort().join(`
5
+ `),files:s.flatMap(r=>r.files),state:s.map(r=>r.state).sort((r,a)=>Pt.indexOf(r)-Pt.indexOf(a))[0],reply:void 0,answers:s.map(r=>({eventId:r.eventId,state:r.state,reply:r.reply,replies:r.replies,text:r.text}))}]})}d(xs,"foldSubmits");const Ut=d(e=>(e.answers||[e]).filter(t=>t.eventId).map(t=>[t.eventId,t.state]),"stateEntries");function Os(e,t,n,s,r,a){const c=d((p,h)=>{const v=a.filter(x=>x.kind==="wave-triage"&&x.data?.[p]===h).pop(),_=r.filter(x=>x.topic===`${p}:${h}`&&(x.state==="open"||x.state==="answered")).length;return{running:!!(v&&!v.reply),questions:_}},"triageOf"),l=new Map(s.map(p=>[p.key,p])),u=d(p=>p.filter(h=>h.lane==="done"&&!St(h)).length,"merged"),m=n.map(p=>({l:p,cards:p.keys.map(h=>l.get(h)).filter(Boolean)})).map(p=>({...p,open:!p.l.finished_at&&p.cards.some(h=>h.lane!=="done")})).sort((p,h)=>Number(p.open)-Number(h.open));for(const{l:p,cards:h}of m)for(const v of h)v.wave={slug:p.slug,title:p.title};const f=m.filter(p=>p.open).map(({l:p,cards:h})=>({kind:"wave",slug:p.slug,title:p.title,goal:p.goal,keys:h.map(v=>v.key),next:Es(h),merged:u(h),total:h.length,triage:c("wave",p.slug)}));return e.fromWaves?[...f,...t.filter(p=>!p.finished).map(p=>({w:p,cards:s.filter(h=>h.file===p.slug&&h.kind!=="ask")})).filter(({cards:p})=>p.length).map(({w:p,cards:h})=>({kind:"file",slug:p.slug,title:p.title,goal:null,keys:h.map(v=>v.key),next:null,merged:u(h),total:h.length,triage:c("file",p.slug)}))]:f}d(Os,"waveBandsOf");function Es(e){const t=e.filter(a=>a.lane==="todo"),n=t.find(a=>a.ready&&a.buildable)||t[0];if(!n)return null;const s=n.ready&&n.buildable,r=s?"ready":n.held?"held":n.blockedBy.length?`waits on ${n.blockedBy.map(a=>a.ref).join(", ")}`:n.blockedUntil?`blocked until ${n.blockedUntil}`:n.action?"needs you":n.phase==="new"?"not ready":n.phase;return{key:n.key,ref:n.ref,ready:s,word:r}}d(Es,"nextOf");const $s=d(e=>e.items||e.phases.flat(),"waveItems");function Ao(e){const{owner:t={},topicItems:n={},events:s=[],threads:r={},prs:a={},working:c={}}=e,l=e.now??Date.now(),u=Tt(s,t),m=new Set(s.filter(o=>o.kind==="ask-withdrawn").map(o=>o.data?.id)),f=new Map(s.filter(o=>o.kind==="ask"&&!m.has(o.id)).map(o=>[o.id,o])),p=d((o,g)=>new Map(s.filter(E=>E.kind===o).sort((E,$)=>String(E.ts).localeCompare(String($.ts))).map(E=>[E.data?.[g],E.ts])),"latest"),h=p("card-unbump","key"),v=new Map([...p("card-bump","key")].filter(([o,g])=>!(String(h.get(o)||"")>String(g)))),_=p("card-done","key"),x=p("card-merge","key"),P=e.autoMerge===!0,C=e.tickets,L=new Map(s.filter(o=>o.kind==="card-hold").sort((o,g)=>String(o.ts).localeCompare(String(g.ts))).map(o=>[o.data?.key,o])),T=new Map,W=new Map(e.files.flatMap(({slug:o,itemFile:g})=>g.items.map(E=>[`${o}/${E.id}`,{ref:nt(g,E,C),title:E.title}]))),w=e.askLinks||{},b=new Map;for(const[o,g]of Object.entries(w))f.has(o)&&b.set(g,[...b.get(g)||[],o]);const i=[],S=[],oe=new Map,me=new Map,he=new Map,K=new Map,F=e.github?null:tn(e.remote);for(const{slug:o,itemFile:g,agents:E={}}of e.files){const $=e.github||g.repo||null;i.push({slug:o,title:g.title||o,status:g.status||null,internal:!!g.internal,finished:!1,reviewers:(g.reviewers||[]).map(y=>y.name)}),g.items.forEach((y,M)=>{const B=`${o}/${y.id}`,Ke=(b.get(B)||[]).filter(O=>O!==y.from_ask),le=[y.from_ask,...Ke].filter(O=>f.has(O)),Ce=new Set(le.map(O=>`ask:${O}`)),Ee=[...R(r,B)||[],...le.flatMap(O=>R(r,`ask:${O}`)||[])];y.from_ask&&T.set(y.from_ask,[...T.get(y.from_ask)||[],{key:B,ref:nt(g,y,C),became:!0}]);const ne=vs(B,{lines:Ee,events:s,owner:t,working:c,fromAsk:y.from_ask||null,moved:Ke,cards:W,index:u});for(const O of ne)for(const[ie,Ge]of Ut(O))oe.set(ie,Ge);me.set(B,Lt(ne)),S.push(Dn({slug:o,itemFile:g,it:y,order:M,repo:$,remote:F,base:e.branch||"main",prs:rn(y,$).map(O=>({...O,gh:R(a,ln(O))||null})),...(O=>({agents:O,builder:ts(O,R(r,B),l,e.moved?.[it(R(E,y.id))]??null,R(e.alive,B)??null,!!e.commandRunning?.[it(R(E,y.id))]),reachedPhase:es(O,R(r,B)),eta:O.map(ie=>ie.eta).filter(Boolean).sort().pop()||null}))(lt(R(E,y.id))),worktree:it(R(E,y.id))??y.worktree?.path??null,thread:Ee,events:[...ct(u,[B,...Ce].map(O=>u.byKey.get(O))),...le.map(O=>f.get(O))],working:ne.some(O=>Ut(O).some(([,ie])=>ie==="working")),said:ne.filter(O=>O.who==="love"&&(O.kind==="item-message"||O.kind==="owner-answer")),askedAt:(u.questions.get(`item:${B}`)||[]).filter(O=>O.asked_at).map(O=>O.asked_at),topicItems:n,prSlack:e.prSlack||{},boardReviewers:e.reviewers||[],now:l,bumpedAt:v.get(B),holdAsk:L.get(B),closedAt:_.get(B),mergeAt:x.get(B),autoMerge:P,skipDraft:e.skipDraft===!0,tickets:C}));const J=S[S.length-1];f.has(y.from_ask)&&(J.created=f.get(y.from_ask).ts),J.askMsg=ne.find(O=>O.kind==="ask"&&O.eventId===y.from_ask)||null,K.set(B,{parent:y.parent?Wt(o,y.parent):null,related:(y.related||[]).map(O=>Wt(o,O))}),J.lane==="done"&&he.set(B,J.closedAt||String(J.updatedAt||""))})}const ee=new Map(S.map(o=>[o.key,o])),I=new Map,G=e.try||{},ze=e.autoBuild===!0,U=["web","app"].includes(G.kind)?G.kind:e.files.some(({itemFile:o})=>o.items.some(g=>g.install?.url))?"app":"web";for(const o of S){if(o.kind!=="work"||o.lane==="done")continue;const g=R(G.cards,o.key)||{},E=g.head||o.pr?.headRefOid,$=U==="web"?g.sha:o.install?.sha,y=o.builder?.kind===ue.install?"running":g.state||(U==="app"&&o.install?"ready":null);o.try={kind:U,state:y,stale:!!($&&E&&!String(E).toLowerCase().startsWith(String($).toLowerCase())),url:U==="web"?null:o.install?.url||null,port:U==="web"&&y==="ready"&&g.https||null,sha:$||null,changes:g.ahead>0,script:g.script===!0,autoBuild:ze}}const D=G.main,we=D?.script&&D.sha?{slug:D.slug,branch:D.branch||"main",sha:D.sha.slice(0,7),at:D.at,kind:U,state:D.state||null,url:U==="web"?null:e.main?.install?.url||null,port:U==="web"&&(D.state==="ready"?D.https:D.serving?.https)||null,serving:U==="web"&&D.serving?{sha:D.serving.sha.slice(0,7),at:D.serving.at}:null,pull:G.pull?{running:G.pull.running===!0,error:G.pull.error||null}:null,script:pn(D.target)}:null,ye=[],be=[],Le=_e(s.filter(o=>o.kind==="owner-answer"),o=>o.data?.id),j=_e(s.filter(o=>o.kind==="prototype-request"),o=>o.data?.question),Re=_e(s.filter(o=>o.kind==="reask-request"),o=>o.data?.question),Je=_e(s.filter(o=>o.kind===mt),o=>o.data?.question),H=(t.items||[]).map(o=>ls(o,Le.get(o.id)||[],j.get(o.id)||[],Re.get(o.id)||[],Je.get(o.id)||[])),X=new Map(H.map(o=>[o.id,o])),Te=_e(H,o=>o.topic);for(const o of f.values()){const g=`ask:${o.id}`,E=R(r,g)||[],$=T.get(o.id)?.[0].key||R(w,o.id);if(!$){E.some(B=>B.line==="ask-moved")||be.push(o.id);continue}I.set(g,$);const y=E.filter(B=>B.line===fn).at(-1),M=ee.get($);if(y&&M){const B=y.title||String(u.edits.get(o.id)??o.data?.text??"").trim().split(`
6
+ `)[0]||"Ask";ye.push({key:M.key,ref:M.ref,text:B,at:String(y.ts)})}}for(const o of i){const g=S.filter(E=>E.file===o.slug);if(o.finished=On(g),o.finished)for(const E of g)E.lane==="done"&&(E.fold=yn(o.slug))}for(const o of S)o.wave=null;const Se=new Set((t.topics||[]).map(o=>o.id)),ve=e.files.flatMap(({slug:o,itemFile:g})=>(g.waves||[]).map(E=>({...E,keys:$s(E).map($=>`${o}/${$}`)}))),xe=d(()=>us([...t.topics||[],...S.filter(o=>!Se.has(`item:${o.key}`)).map(o=>({id:`item:${o.key}`,card:o.key,title:`${o.ref}: ${o.title}`})),...ve.filter(o=>!Se.has(`wave:${o.slug}`)).map(o=>({id:`wave:${o.slug}`,title:o.title,summary:"Wave triage."})),...(e.fromWaves?i:[]).filter(o=>!Se.has(`file:${o.slug}`)).map(o=>({id:`file:${o.slug}`,title:o.title,summary:"Wave triage."}))],H,new Set(S.filter(pe).map(o=>`item:${o.key}`))),"topicsOf"),Pe=new Map(xe().map(o=>[o.id,o]));for(const o of S){const g=Pe.get(`item:${o.key}`);if(!g){o.questions=null,o.prototypes=null;continue}const E=g.questions.filter(M=>X.get(M)?.state!=="resolved"),$=g.questions.find(M=>X.get(M)?.state==="open")||E[0]||g.questions[0],y=g.questions.map(M=>X.get(M)).filter(M=>M?.state==="open");o.questions={topic:g.id,state:g.state,open:g.open,answered:g.answered,replied:g.replied,resolved:g.resolved,first:$,askedAt:y.map(M=>M.asked_at).filter(Boolean).sort(),fromAsks:y.length>0&&y.every(M=>M.ask)},o.prototypes=cs(g.questions.map(M=>X.get(M)))}const te=new Map(S.map(o=>[o.key,o])),Ue=new Map(ve.map(o=>[`wave:${o.slug}`,o.keys]));for(const o of S){const g=o.kind==="work"&&o.lane!=="done",E=new Set(o.deps.flatMap(y=>Ue.get(y)||[String(y).includes("/")?y:`${o.file}/${y}`]));o.blockedBy=g?[...E].map(y=>te.get(y)).filter(y=>y&&y.lane!=="done"&&!y.reopened).map(jt):[],o.blockedUntil=g?o.blockedUntil??null:null,o.blockReason=g?o.blockReason??null:null,o.blocked=o.blockedBy.length>0||!!o.blockedUntil,Xn(o,X,P),o.lane==="todo"&&o.kind==="work"&&!o.held&&Et(o.storedLane,o.agents)&&(o.lane="progress"),o.unpicked=o.kind==="work"&&o.lane==="todo"&&!!Kn(H,o.key),o.kind==="work"&&(o.phase=zs(o)),o.unpicked&&!o.action&&(o.next=Gn),o.buildable=Wn(o);const $=o.kind==="work"&&o.lane==="todo";if(o.unsorted=$&&(!!o.fromAsk||o.unfiled)&&!o.filedHeld&&o.phase==="new",o.kind==="work"){const y=o.askMsg;delete o.askMsg,o.unsorted&&y&&(o.isNew=!0,o.ask={eventId:y.eventId,state:y.state,askedAt:y.ts,edited:!!y.edited,canEdit:!0,text:y.text,files:y.files,from:y.from||null})}o.ready=$&&o.phase==="ready"&&!o.blocked&&!o.recheckAt&&!o.action,o.staging=$&&o.phase==="staging",o.kind==="work"&&(o.hostHeld=!!e.hostBusy&&o.ready&&!!o.bumpedAt&&!o.held)}_s(S,te,K);const je=new Map((t.items||[]).map(o=>[o.id,o.topic])),Y=d(o=>o.kind==="owner-answer"?je.has(o.data?.id)?/^item:(.+)$/.exec(je.get(o.data.id))?.[1]||null:"":o.kind==="ask"?`ask:${o.id}`:o.data?.key||(o.kind.startsWith("ask-")&&o.data?.id?`ask:${o.data.id}`:null),"ownCardOf"),z=d(o=>{const g=Y(o);return I.get(g)||g},"cardOf"),Me=d(o=>[_.get(o),he.get(o)].filter(Boolean).sort().pop()||"","closedAt"),Ie=d(o=>{const g=z(o);return g===null?!o.reply:!te.has(g)||!(Me(g)<String(R(c,o.id)))?!1:oe.has(o.id)?oe.get(o.id)==="working":!o.reply&&!I.has(Y(o))&&!(String(me.get(g)||"")>String(o.ts))},"unanswered"),re=s.filter(o=>R(c,o.id)&&Ie(o)).map(o=>({id:o.id,kind:o.kind,key:z(o),data:o.data,since:R(c,o.id)}));for(const o of S)o.working=re.some(g=>g.key===o.key),o.kind==="work"&&o.lane==="progress"&&!o.builder&&!o.next&&o.waitsOn!=="checking"&&!o.working&&(o.next=$t),o.sortAt=Rs[o.lane](o)||(o.lane==="review"?null:o.updatedAt)||null;for(const o of S){if(o.kind!=="work")continue;const g=(Te.get(`item:${o.key}`)||[]).filter($=>$.state==="answered").map($=>$.answers.at(-1).ts).sort().pop(),E=re.filter($=>$.key===o.key).map($=>String($.since)).sort()[0];o.orchestrator=!o.stalled&&(["progress","todo"].includes(o.lane)||o.waitsOn==="checking"||o.lane==="review"&&(o.stale||o.waitFacts.unblockedAt||o.waitFacts.replyAt))?so(o,o.waitFacts,{answeredAt:g,workingSince:E}):null,delete o.waitFacts}Gs(S,s,c,I),Qs(S,e.screening||{}),S.sort(gn);const Ze=Os(e,i,ve,S,H,s),A=xe(),We=nn({on:e.autoReview,incoming:e.incoming,records:e.reviewRecords,events:s,now:l,refs:new Map(S.filter(o=>o.kind==="work").map(o=>[o.key,o.ref]))}),ae=[...Is(S,A,H),...sn(We)],N=new Map(ae.filter(o=>o.questions).map((o,g)=>[o.topic||`item:${o.key}`,g])),Fe=d(o=>N.get(o.id)??N.size,"rankOf");A.sort((o,g)=>Fe(o)-Fe(g));const qe=new Set(ae.filter(o=>o.questions&&o.progress).map(o=>`item:${o.key}`));for(const o of A)qe.has(o.id)&&(o.progress=!0);const Oe=S.flatMap(o=>o.answered&&me.get(o.key)?[{key:o.key,id:o.id,text:o.title,at:me.get(o.key)}]:[]).sort((o,g)=>g.at.localeCompare(o.at));return ye.sort((o,g)=>g.at.localeCompare(o.at)),As({kind:U,main:we,remote:F&&{host:F.host,name:`${F.host}/${F.path}`},itemFiles:i,waveBands:Ze,items:S,moved:Object.fromEntries(I),answers:Oe,merges:ye,unfiled:be,owner:H,ownerTopics:A,reviews:We,needs:ae,working:re.length,workingOn:re,checks:Ms(e,l)},e)}d(Ao,"buildBoard");function As(e,{listen:t,prompts:n}={}){const s=[...Cs(n),...e.needs];return{...e,needs:s,needsSummary:Ds(s),checks:{...e.checks,watcher:{listening:"running",asleep:"asleep",waking:"waking"}[t]||"stopped"}}}d(As,"withHub");const jt=d(e=>({key:e.key,ref:e.ref}),"linkOf"),Wt=d((e,t)=>String(t).includes("/")?String(t):`${e}/${t}`,"linkKey"),Bs=d((e,t)=>e.ref.localeCompare(t.ref,void 0,{numeric:!0}),"byRef");function _s(e,t,n){const s=new Map,r=new Map,a=new Map,c=d((u,m,f)=>u.set(m,[...u.get(m)||[],f]),"add");for(const[u,m]of n){m.parent&&c(s,m.parent,u);for(const f of m.related)f!==u&&(c(r,u,f),c(r,f,u))}for(const u of e)for(const m of u.blockedBy||[])c(a,m.key,u.key);const l=d((u=[])=>[...new Set(u)].map(m=>t.get(m)).filter(Boolean).map(jt).sort(Bs),"cards");for(const u of e){const m=n.get(u.key)?.parent;u.parent=m?{key:m,ref:t.get(m)?.ref||m.slice(m.indexOf("/")+1)}:null,u.children=l(s.get(u.key)),u.related=l(r.get(u.key)),u.waitsOnIt=l(a.get(u.key))}}d(_s,"linkCards");const Rs={todo:d(e=>e.created,"todo"),progress:d(e=>e.progressSince,"progress"),review:d(e=>e.reviewSince,"review"),done:d(e=>e.closedAt,"done")},se=d((e,t)=>`${e} ${t}${e===1?"":"s"}`,"plural");function Ms({checked:e,watcher:t,replyAt:n,threads:s={},working:r={},files:a=[]},c){const l=Number(e?.every)||30,m=[n,t?.since,...Object.values(r),...Object.values(s).flat().filter(p=>(p.who||"claude")==="claude").map(p=>p.ts),...a.flatMap(p=>Object.values(p.agents||{}).flatMap(h=>Object.values(h||{})).map(h=>h?.done||h?.started))].filter(p=>typeof p=="string"&&!Number.isNaN(Date.parse(p))).reduce((p,h)=>p&&Date.parse(p)>Date.parse(h)?p:h,null),f=!!e?.idle;return{at:e?.at||null,every:f?null:l,idle:f,late:!f&&!!e?.at&&c-Date.parse(e.at)>2*l*6e4,claudeAt:m}}d(Ms,"checksOf");function Is(e,t,n){const s=new Set(e.map(l=>l.questions?.topic).filter(Boolean)),r=d(l=>l.find(u=>n.find(m=>m.id===u)?.state==="open")||l[0],"firstOpen"),a=t.filter(l=>l.state!=="resolved"&&l.open>0&&!s.has(l.id)).map(l=>{const u=`questions.html#${r(l.questions)}`,m=/^(?:wave|file):(.+)$/.exec(l.id)?.[1]||null;return{kind:"Question",title:l.title,text:`${l.title} \xB7 ${se(l.open,"question")}`,url:u,topic:l.id,band:m,questions:{open:l.open,url:u},ready:null,since:n.filter(f=>f.topic===l.id&&f.state==="open").map(f=>f.asked_at).filter(Boolean).sort()[0]||null}}),c=e.map(l=>{const u=l.questions&&l.questions.state!=="resolved"&&l.questions.open>0?{open:l.questions.open,url:`questions.html#${l.questions.first}`}:null,m=l.waitsOn==="ready"?l.pr.url:null,f=!u&&!m&&l.action?{label:l.action.label,url:l.action.url}:null;if(!u&&!m&&!f)return null;const p=`${l.ref}: ${l.title}`,h=[p,u&&se(u.open,"question"),m&&"Ready on GitHub",f?.label].filter(Boolean).join(" \xB7 ");return{kind:u?"Question":m?"Tap Ready":"Action needed",title:p,text:h,url:`#selectedCard=${encodeURIComponent(l.key)}`,key:l.key,questions:u,ready:m,action:f,since:l.created||null,progress:l.lane==="progress"}}).filter(Boolean);return[...a,...c].sort(qs)}d(Is,"needsOf");const qs=d((e,t)=>!!t.progress-!!e.progress||(e.since&&t.since?e.since.localeCompare(t.since):!!t.since-!!e.since),"oldestFirst");function Cs(e=[]){return e.map(t=>{const n=t.questions?.length?`Question: ${t.questions.map(s=>s.question).join(" \xB7 ")}`:`${t.tool}: ${t.detail||t.action}`;return{kind:"Prompt",title:n,text:n,url:"",prompt:t}})}d(Cs,"promptLines");function Ds(e){const t=e.filter(a=>a.prompt).length,n=e.reduce((a,c)=>a+(c.questions?.open||0),0),s=e.filter(a=>a.ready).length,r=e.filter(a=>a.review).length;return[t&&se(t,"prompt"),n&&se(n,"question"),s&&`${se(s,"draft")} waiting on Ready`,r&&`${se(r,"review")} held`].filter(Boolean).join(" \xB7 ")}d(Ds,"needsSummary");function Bo(e){const t=d((...n)=>e.items.filter(s=>n.includes(s.lane)).length,"count");return{items:e.needs.map(({kind:n,text:s,url:r})=>({kind:n,text:s,url:r})),working:e.working,summary:e.needsSummary,lanes:{review:t("review"),progress:t("progress"),todo:t("todo")},building:e.items.some(n=>(n.agents||[]).some(s=>!s.done))}}d(Bo,"needsAnswer");const Ns=d(e=>e.buildable&&e.phase==="ready"&&!e.held&&!e.blocked&&!e.recheckAt,"pullableCard"),Ls=10;function Ts(e,{cap:t=Ls,pulled:n=[],hold:s=[],taken:r=0}={}){const a=e.filter(w=>!pe(w)),c=d((w,b)=>w.started&&!w.done&&Q(w)&&!(w.kind===ge&&!w.writes)&&!w.pause?.paused&&!(w.waits&&b.some(i=>i.name===w.waits&&!i.done)),"counts"),l=a.filter(w=>!w.stalled).reduce((w,b)=>w+(b.agents||[]).filter((i,S,oe)=>c(i,oe)).length,0),u=a.filter(w=>Ns(w)&&!w.working).map(w=>w.key),m=a.filter(w=>n.includes(w.key)&&(u.includes(w.key)||w.buildable&&w.working)).map(w=>w.key),f=a.flatMap(w=>(w.agents||[]).filter(b=>b.kind===ge&&!b.started&&!b.done).map(b=>({key:w.key,name:b.name,writes:b.writes}))),p=Math.max(0,t-l-m.length-r),h=f.filter(w=>w.writes),v=[...f.filter(w=>!w.writes),...h.slice(0,p)].map(({key:w,name:b})=>({key:w,name:b})),_=Math.max(0,p-h.length),x=new Set(a.filter(w=>w.bumpedAt).map(w=>w.key)),P=u.filter(w=>!m.includes(w)&&!s.includes(w)),C=P.filter(w=>x.has(w)),L=[...C,...P.filter(w=>!x.has(w)).slice(0,Math.max(0,_-C.length))],T=C.slice(_),W=Ps(a,c).slice(0,T.length).map((w,b)=>({key:w,by:T[b]}));return{idle:!l&&!a.some(w=>w.waitsOn==="checking"),pullable:u,waiting:m,pulls:L,helpers:v,bumpOuts:W,pastCap:T,free:p}}d(Ts,"pullOf");function Ps(e,t){const n=d(s=>{const r=s.agents||[],a=r.filter(u=>t(u,r)),[c]=a;return s.lane==="progress"&&!s.bumpedAt&&!s.stalled&&s.waitsOn!=="checking"&&s.builder?.phase!=="landing"&&!(s.prs||[]).length&&!s.pushed&&!s.mergeReady&&a.length===1&&c.kind!==ge&&c.pid&&c.label!==He&&!c.pause&&!r.some(u=>u.kind===ge&&u.started&&!u.done)?String(c.started):null},"newest");return e.map(s=>({key:s.key,at:n(s)})).filter(s=>s.at).sort((s,r)=>r.at.localeCompare(s.at)).map(s=>s.key)}d(Ps,"bumpOutsOf");function _o(e,t,n){return e.filter(s=>s.kind==="work"&&!pe(s)&&s.waitsOn!=="checking"&&!(s.agents||[]).some(r=>r.started&&!r.done)).flatMap(s=>{const r=(s.prs||[]).find(c=>c.state==="OPEN"&&c.mergeable==="CONFLICTING"&&c.repo===s.repo&&c.headRefOid),a=r&&`${r.headRefOid}@${n}`;return r&&R(t,s.key)!==a?[{key:s.key,pr:r.number,branch:r.headRefName,conflict:a}]:[]})}d(_o,"rebasesDue");const Us=3;function Ro(e,{cap:t=Us}={}){const n=e.filter(l=>!pe(l)),s=n.filter(l=>(l.agents||[]).some(u=>Z(u)&&u.started&&!u.done)).length,r=n.filter(l=>l.buildable&&!["ready","staging"].includes(l.phase)&&!l.unsorted&&!l.held&&!l.working&&!l.grilling&&!l.prototyping&&!l.questions&&!(l.agents||[]).some(u=>Z(u)&&u.kind!==fe)),a=[...r.filter(l=>!l.blocked),...r.filter(l=>l.blocked)],c=a.filter(l=>l.bumpedAt);return[...c,...a.filter(l=>!l.bumpedAt).slice(0,Math.max(0,t-s-c.length))].map(l=>l.key)}d(Ro,"arrivalsOf");function Mo(e){return e.filter(t=>t.kind==="work"&&t.lane==="todo"&&t.roundAt&&["grilling","prototyping"].includes(t.phase)&&!(t.agents||[]).some(n=>Z(n)&&n.kind!==fe&&n.started&&(String(n.started)>=String(t.roundAt)||!n.done))).map(t=>({key:t.key,kind:t.phase==="grilling"?"grill":"prototype"}))}d(Mo,"roundsDue");const js=d(e=>`${fe}-${e.id}`,"visualAgent");function Io(e,t){const n=[];for(const s of e){const r=s.agents||[];if(r.some(l=>l.kind===fe&&l.started&&!l.done))continue;const a=new Set(r.map(l=>l.name)),c=t.find(l=>l.kind==="visual-request"&&l.data?.key===s.key&&!a.has(js(l)));c&&n.push({key:s.key,request:c})}return n}d(Io,"visualsDue");const Ws=d((e,t)=>e.kind==="ask"?t.get(`ask:${e.id}`)??null:e.kind==="card-added"?e.data?.key??null:null,"intakeKeyOf");function Fs(e,t,n){const s=e.get(n);return s?t.kind==="ask"?!!s.isNew:s.unfiled:!1}d(Fs,"unsorted");const Ks={ask:d((e,t)=>`Sort the new task: item notes, then item set ${e} --phase grilling or prototyping (ready, with --size, for a Quick build); merge it into a card with item relate-ask ${t.id} <card> --summary; or answer it with reply ${e}`,"ask"),"card-added":d(()=>"Link and file the card an agent added: item notes, then item set --relate and --phase","card-added")};function Gs(e,t,n,s){const r=new Map(e.map(c=>[c.key,c])),a=new Set;for(const c of t){const l=Ws(c,s);!l||a.has(l)||!Fs(r,c,l)||(a.add(l),r.get(l).orchestrator={kind:"intake",since:String(c.ts),picked:R(n,c.id)||null,next:Ks[c.kind](l,c)})}}d(Gs,"intakeWaits");function Qs(e,t){for(const n of e){const s=R(t,n.key);s&&(n.orchestrator={kind:"screen",since:s.since,picked:null,next:`Screen the grill's questions ${s.ids.join(", ")}: question settle <id> --note for each the board already answers, then question publish ${n.key}; left 15 minutes unscreened, they reach the owner as they are`})}}d(Qs,"screenWaits");function Hs(e){return e.filter(t=>t.lane==="todo"||t.lane==="review"&&t.stale).map(t=>JSON.stringify([t.key,t.title,t.deps||[]])).sort().join(`
7
7
  `)}d(Hs,"todoOf");function qo(e){const t=e.filter(s=>s.kind==="work"&&s.lane!=="done"&&s.questions?.open>0),n=t.map(s=>JSON.stringify([s.key,s.questions.open,s.questions.askedAt||[]])).sort().join(`
8
8
  `);return{waiting:t.map(s=>s.key),seen:`${n}
9
9
  --
10
- ${Hs(e)}`}}d(qo,"triageOf");const Vs=100,Xs=["key","kind","id","ref","title","lane","phase","file","fileTitle","fold","internal","ticket","ticketSource","linear","pr","prs","review","reviewers","risky","sortAt","threadCount","othersAt","hasNotes","questions","prototypes","next","ask","action","actionButton","builder","working","waitsOn","reachedPhase","grilling","refusal","install","parent","children","related","waitsOnIt","blockedBy","ready","finishable","reopened","manualSteps","branch","worktree"],Co=d(e=>Object.fromEntries(Xs.filter(t=>t in e).map(t=>[t,e[t]])),"slimDone");function Do(e,t=Vs){const n=new Set((e.waveBands||[]).flatMap(r=>r.keys)),s=new Set(e.items.filter(r=>r.lane!=="done").flatMap(r=>[...(r.deps||[]).map(a=>String(a).includes("/")?String(a):`${r.file}/${a}`),r.parent?.key,...(r.children||[]).map(a=>a.key),...(r.related||[]).map(a=>a.key)]));return e.items.filter(r=>r.lane==="done"&&r.kind==="work").sort((r,a)=>String(a.closedAt||"").localeCompare(String(r.closedAt||""))).slice(t).filter(r=>r.storedLane==="done"&&!r.reopened&&!n.has(r.key)&&!s.has(r.key)&&(!r.questions||r.questions.state==="resolved"))}d(Do,"archivedOf");const Ys={ready:"draft",ci:"draft",reviewers:"reviewers",merge:"merge"};function zs(e){return e.lane==="todo"?e.unpicked?"prototyping":kt.todo.includes(e.storedPhase)?e.storedPhase:e.storedLane&&e.storedLane!=="todo"?"ready":"new":e.lane==="progress"?e.waitsOn==="checking"?"checking":e.builder&&!e.builder.planner&&e.builder.kind!==ue.install&&e.builder.phase||e.reachedPhase||"reading":e.lane==="review"?e.stale?"stale":e.waitsOn==="owner"&&e.pushed?"merge":Ys[e.waitsOn]??null:e.storedLane==="done"&&kt.done.includes(e.storedPhase)?e.storedPhase:e.prs.some(t=>t.status===V.merged)?"merged":"closed"}d(zs,"phaseOf");function No(e){return e.items.filter(t=>t.kind==="work").flatMap(t=>{const n=t.lane;return n==="done"||t.storedLane==="done"&&!t.reopened?[]:n===t.storedLane&&(n==="todo"||t.phase===t.storedPhase)?[]:[{key:t.key,to:n,phase:t.phase,why:Js(t,n),from:{lane:t.storedLane,phase:t.storedPhase}}]})}d(No,"movesOf");function Js(e,t){return t==="todo"?e.held?"it is held":e.blocked?"it is blocked":"nothing builds it":e.reopened&&e.storedLane==="done"?"a message or question reopened it":e.answered&&t==="review"?"answered, it waits for your Done":t==="progress"?e.waitsOn==="checking"?"its build handed back for a check":e.builder?"a build started":"Claude acts next":e.next||"it waits on review"}d(Js,"moveWhy");const Zs=d(e=>e.startsWith("ask:")?`ask-${e.slice(4)}`:`item-${e}`,"pushTag");function Lo(e){const t=d(a=>e.owner.filter(c=>c.topic===a&&c.state==="open").map(({id:c,question:l})=>({id:c,question:l})),"open"),n=[q.ready,q.merge],s=e.items.filter(a=>a.action).map(a=>{const c=rt.has(a.action.kind)?t(a.questions.topic):[];return{tag:Zs(a.key),kind:a.action.kind,title:`${a.ref}: ${a.action.label}`,body:c[0]?.question||a.title,url:c.length?a.action.url:`#selectedCard=${encodeURIComponent(a.key)}`,now:!n.includes(a.action.kind),questions:c}}),r=e.needs.filter(a=>a.topic).map(a=>{const c=t(a.topic);return{tag:`topic-${a.topic}`,kind:q.questions,title:a.text,body:c[0]?.question||a.title,url:a.url,now:!0,questions:c}});return[...s,...r,...on(e.reviews)]}d(Lo,"ownerActions");function To(e,{pulled:t=[]}={}){return!e.items.filter(r=>!pe(r)).some(r=>r.waitsOn==="checking"||r.grilling||r.prototyping||(r.agents||[]).some(a=>!a.done))&&!e.working&&!Ts(e.items,{pulled:t}).waiting.length}d(To,"strictlyIdle");const eo="item stall it with the reason when it can't go on",Ft="restart it once from its worktree with a thread line; if the restarted run goes stale too, item stall it with the reason",to='Judge the staged card against the whole board: item set --phase ready --text "<what you checked>", or --phase grilling or prototyping for another round; where its notes answer a split question Split as proposed, file the split instead',no='Its block ended: re-read its notes and answered questions against what landed; answer a stale one again with question settle <id> --note, or send the card back with item set --phase grilling when the change is too big; then item set --phase ready --text "<what you re-checked>"';function so(e,t,{answeredAt:n,workingSince:s}){const r=d(m=>e.agents.some(f=>f.kind===m&&f.started&&!f.done),"running"),a=[e.progressSince,...e.agents.map(m=>m.done)].filter(Boolean).map(String).sort().pop()||null,c=t.ask?{kind:"ask",since:t.ask.at,next:`Answer the builder's ask: ${t.ask.text}`}:e.staging?{kind:"staging",since:e.stagedAt,next:to}:n?{kind:"answer",since:n,next:"Act on the owner's answer"}:t.replyAt?{kind:"reply",since:t.replyAt,next:"Act on the owner's reply"}:rt.has(e.action?.kind)?null:e.builder?.stopped?{kind:"stale",since:e.builder.silentSince,next:`${e.builder.stopped}: ${Ft}, or drop the card`}:e.builder?.stale?{kind:"stale",since:e.builder.silentSince,next:`Find out why the builder went silent, then finish its run or ${Ft}`}:e.lane==="review"&&e.stale?{kind:"stale",since:new Date(Date.parse(e.inReviewSince)+ht).toISOString(),daily:!0,next:`Find out why the review went stale and fix what you can: rebase, CI, comments; if only a reviewer owes it, a thread line naming who; or ${eo}`}:e.waitsOn==="checking"?t.unverified?{kind:"calls",since:t.handedBackAt,next:t.next||"Verify the builder's judgment calls"}:{kind:"checking",since:t.handedBackAt,next:t.next||"Land the checked build"}:e.grilling&&t.grillAt&&!r("grill")?{kind:"grill",since:t.grillAt,next:"Start the grill asked for"}:e.prototyping&&t.prototypeAt&&!r("prototype")?{kind:"prototype",since:t.prototypeAt,next:"Draw the prototype asked for"}:e.recheckAt&&e.lane==="todo"&&e.phase==="ready"&&!e.blocked?{kind:"recheck",since:e.recheckAt,next:no}:e.refusal&&t.refusedAt?{kind:"refused",since:t.refusedAt,next:e.refusal}:e.next===$t&&a?{kind:"unowned",since:a,next:"Start a builder on it, or set its Next"}:t.unblockedAt&&e.lane!=="todo"&&!e.builder&&!e.blocked&&!t.writes.some(m=>m>t.unblockedAt)?{kind:"unblocked",since:t.unblockedAt,next:"Its block ended: act on what it waited for, or set its Next"}:null;if(!c?.since)return null;const l=String(c.since),u=[t.writes.find(m=>m>l),s].filter(Boolean).sort()[0]||null;return{kind:c.kind,since:l,picked:u,next:c.next,...c.daily?{daily:!0}:{}}}d(so,"orchestratorWaitOf");const Po=d((e,t=null)=>({key:e.id,ref:e.data.date,title:`Overnight triage ${e.data.date}`,kind:"triage",since:e.ts,picked:t,next:`Run the overnight triage and reply: board.mjs reply ${e.id}`}),"triageWaitOf");function Uo(e){const t=e.items.filter(n=>n.orchestrator).map(n=>({key:n.key,ref:n.ref,title:n.title,...n.orchestrator,bumpedAt:n.bumpedAt||null}));return[...t.filter(n=>n.bumpedAt).sort((n,s)=>n.bumpedAt.localeCompare(s.bumpedAt)),...t.filter(n=>!n.bumpedAt)]}d(Uo,"orchestratorWaits");const jo=30*6e4,oo=15*6e4,ro=60*6e4,ao=1440*6e4;function Wo(e,t,n){const s=n.toISOString(),r=[],a=[];return{waits:t.map(l=>{const u=e.find(p=>p.key===l.key&&p.kind===l.kind&&p.since===l.since);if(!u)return l.picked||r.push(l.key),{...l,bumped:s};const m=l.picked?[l.picked,u.bumped].filter(Boolean).sort().pop():u.bumped||l.since,f=n-Date.parse(m)>=(l.picked?l.daily?ao:ro:oo);return f&&a.push({key:l.key,ref:l.ref,kind:l.kind,since:l.since,next:l.next}),{...l,bumped:f?s:u.bumped||l.since,...u.pushed?{pushed:!0}:{}}}),added:r,again:a}}d(Wo,"waitsStep");function Fo(e,t){const n=d(s=>{const r=Math.floor((t-Date.parse(s))/6e4),a=Math.floor(r/60),c=r%60;return a?`${a}h${c?` ${c}m`:""}`:`${c}m`},"age");return`still waiting on you: ${e.map(s=>`${s.ref} ${s.kind} for ${n(s.since)}: ${s.next}`).join("; ")}`}d(Fo,"waitsAgainLine");const lo=15;function Ko(e,{idle:t,now:n}){const s=n.toISOString(),r=e.last||s;return t?e.since?e.pushed||n-Date.parse(e.since)<lo*6e4?{state:{...e,last:r},push:!1}:{state:{last:s,since:e.since,pushed:!0},push:!0}:{state:{last:r,since:s},push:!1}:{state:{last:r},push:!1}}d(Ko,"idleStep");function Go(e,t){const n=d(u=>String(u.closedAt||"")>t,"after"),s=e.filter(u=>u.kind==="work"&&u.lane==="done"&&!St(u)&&n(u)),r=new Map;for(const u of e)u.wave&&r.set(u.wave.slug,[...r.get(u.wave.slug)||[],u]);const a=[...r.values()].filter(u=>u.every(m=>m.lane==="done")&&u.some(n)).map(u=>u[0].wave.title),c=s.slice(0,3).map(u=>u.ref).join(", ")+(s.length>3?` and ${s.length-3} more`:"");return[s.length&&`${s.length} ${s.length===1?"card":"cards"} landed: ${c}`,...a.map(u=>`${u} finished`)].filter(Boolean).join(" \xB7 ")||"Nothing closed since the last idle notification."}d(Go,"idleSummary");export{q as ACTION_KIND,It as ACTION_LABELS,fs as ANSWERS_SUBMITTED,De as BUILDER_ASK,ue as BUILDER_KIND,wn as BUILDER_QUIET_AFTER,mn as BUILDER_STALE_AFTER,wt as BUILD_REFUSED,ce as BUTTON,Xe as COMMANDS,ao as DAILY_REWAKE_AFTER,Xs as DONE_FIELDS,Vs as DONE_KEPT,ge as HELPER,lo as IDLE_MINUTES,qt as INTENT_LABELS,kn as ITEM_EVENTS,He as LANDER,So as LANES,Ls as MAX_IMPLEMENTERS,Us as MAX_PLANNERS,$e as MOVE,$t as NO_NEXT,jo as ORCHESTRATOR_PUSH_AFTER,Eo as PAUSE_CLEARS,ns as PAUSE_HARD_STOP,kt as PHASES,ro as PICKED_REWAKE_AFTER,zn as PLANNER_WORD,Gn as PROTOTYPE_AGAIN,xo as PROTOTYPE_WAIT,V as PR_STATE,mt as QUESTION_REOPEN,oo as REWAKE_AFTER,fe as VISUAL,Do as archivedOf,Ro as arrivalsOf,Ao as buildBoard,Q as builds,$o as confirmedDrops,yn as fileFold,st as handedBackAt,Ko as idleStep,Go as idleSummary,Tn as mergeBlockers,as as modelName,No as movesOf,Bo as needsAnswer,Kn as noTakePicked,Jn as orchestratorDid,Uo as orchestratorWaits,vo as owesNext,Lo as ownerActions,ls as ownerQuestion,rs as pauseWork,Fn as picksNoTake,Z as plans,Oo as prototypeWaits,_t as providerOf,Ts as pullOf,Zs as pushTag,_o as rebasesDue,nt as refOf,ke as roundOf,is as roundSettledBy,Mo as roundsDue,Co as slimDone,Ut as stateEntries,At as stoppedWords,To as strictlyIdle,Tt as threadIndex,vs as threadOf,Hs as todoOf,qo as triageOf,Po as triageWaitOf,St as unlanded,js as visualAgent,Io as visualsDue,Fo as waitsAgainLine,Wo as waitsStep,$s as waveItems,As as withHub};
10
+ ${Hs(e)}`}}d(qo,"triageOf");const Vs=100,Xs=["key","kind","id","ref","title","lane","phase","file","fileTitle","fold","internal","ticket","ticketSource","linear","pr","prs","review","reviewers","risky","sortAt","threadCount","othersAt","hasNotes","questions","prototypes","next","ask","action","actionButton","builder","working","waitsOn","reachedPhase","grilling","refusal","install","parent","children","related","waitsOnIt","blockedBy","ready","finishable","reopened","manualSteps","branch","worktree"],Co=d(e=>Object.fromEntries(Xs.filter(t=>t in e).map(t=>[t,e[t]])),"slimDone");function Do(e,t=Vs){const n=new Set((e.waveBands||[]).flatMap(r=>r.keys)),s=new Set(e.items.filter(r=>r.lane!=="done").flatMap(r=>[...(r.deps||[]).map(a=>String(a).includes("/")?String(a):`${r.file}/${a}`),r.parent?.key,...(r.children||[]).map(a=>a.key),...(r.related||[]).map(a=>a.key)]));return e.items.filter(r=>r.lane==="done"&&r.kind==="work").sort((r,a)=>String(a.closedAt||"").localeCompare(String(r.closedAt||""))).slice(t).filter(r=>r.storedLane==="done"&&!r.reopened&&!n.has(r.key)&&!s.has(r.key)&&(!r.questions||r.questions.state==="resolved"))}d(Do,"archivedOf");const Ys={ready:"draft",ci:"draft",reviewers:"reviewers",merge:"merge"};function zs(e){return e.lane==="todo"?e.unpicked?"prototyping":kt.todo.includes(e.storedPhase)?e.storedPhase:e.storedLane&&e.storedLane!=="todo"?"ready":"new":e.lane==="progress"?e.waitsOn==="checking"?"checking":e.builder&&!e.builder.planner&&e.builder.kind!==ue.install&&e.builder.phase||e.reachedPhase||"reading":e.lane==="review"?e.stale?"stale":e.waitsOn==="owner"&&e.pushed?"merge":Ys[e.waitsOn]??null:e.storedLane==="done"&&kt.done.includes(e.storedPhase)?e.storedPhase:e.prs.some(t=>t.status===V.merged)?"merged":"closed"}d(zs,"phaseOf");function No(e){return e.items.filter(t=>t.kind==="work").flatMap(t=>{const n=t.lane;return n==="done"||t.storedLane==="done"&&!t.reopened?[]:n===t.storedLane&&(n==="todo"||t.phase===t.storedPhase)?[]:[{key:t.key,to:n,phase:t.phase,why:Js(t,n),from:{lane:t.storedLane,phase:t.storedPhase}}]})}d(No,"movesOf");function Js(e,t){return t==="todo"?e.held?"it is held":e.blocked?"it is blocked":"nothing builds it":e.reopened&&e.storedLane==="done"?"a message or question reopened it":e.answered&&t==="review"?"answered, it waits for your Done":t==="progress"?e.waitsOn==="checking"?"its build handed back for a check":e.builder?"a build started":"Claude acts next":e.next||"it waits on review"}d(Js,"moveWhy");const Zs=d(e=>e.startsWith("ask:")?`ask-${e.slice(4)}`:`item-${e}`,"pushTag");function Lo(e){const t=d(a=>e.owner.filter(c=>c.topic===a&&c.state==="open").map(({id:c,question:l})=>({id:c,question:l})),"open"),n=[q.ready,q.merge],s=e.items.filter(a=>a.action).map(a=>{const c=rt.has(a.action.kind)?t(a.questions.topic):[];return{tag:Zs(a.key),kind:a.action.kind,title:`${a.ref}: ${a.action.label}`,body:c[0]?.question||a.title,url:c.length?a.action.url:`#selectedCard=${encodeURIComponent(a.key)}`,now:!n.includes(a.action.kind),questions:c}}),r=e.needs.filter(a=>a.topic).map(a=>{const c=t(a.topic);return{tag:`topic-${a.topic}`,kind:q.questions,title:a.text,body:c[0]?.question||a.title,url:a.url,now:!0,questions:c}});return[...s,...r,...on(e.reviews)]}d(Lo,"ownerActions");function To(e,{pulled:t=[]}={}){return!e.items.filter(r=>!pe(r)).some(r=>r.waitsOn==="checking"||r.grilling||r.prototyping||(r.agents||[]).some(a=>!a.done))&&!e.working&&!Ts(e.items,{pulled:t}).waiting.length}d(To,"strictlyIdle");const eo="item stall it with the reason when it can't go on",Ft="restart it once from its worktree with a thread line; if the restarted run goes stale too, item stall it with the reason",to='Judge the staged card against the whole board: item set --phase ready --text "<what you checked>", or --phase grilling or prototyping for another round; where its notes answer a split question Split as proposed, file the split instead',no='Its block ended: re-read its notes and answered questions against what landed; answer a stale one again with question settle <id> --note, or send the card back with item set --phase grilling when the change is too big; then item set --phase ready --text "<what you re-checked>"';function so(e,t,{answeredAt:n,workingSince:s}){const r=d(f=>e.agents.some(p=>p.kind===f&&p.started&&!p.done),"running"),a=[e.progressSince,...e.agents.map(f=>f.done)].filter(Boolean).map(String).sort().pop()||null,c=t.unasked&&e.storedPhase==={grill:"grilling",prototype:"prototyping"}[t.unasked.kind]&&!e.agents.some(f=>f.kind===t.unasked.kind&&f.started&&(!f.done||String(f.started)>t.unasked.at))?t.unasked:null,l=t.ask?{kind:"ask",since:t.ask.at,next:`Answer the builder's ask: ${t.ask.text}`}:e.staging?{kind:"staging",since:e.stagedAt,next:to}:n?{kind:"answer",since:n,next:"Act on the owner's answer"}:t.replyAt?{kind:"reply",since:t.replyAt,next:"Act on the owner's reply"}:rt.has(e.action?.kind)?null:e.builder?.stopped?{kind:"stale",since:e.builder.silentSince,next:`${e.builder.stopped}: ${Ft}, or drop the card`}:e.builder?.stale?{kind:"stale",since:e.builder.silentSince,next:`Find out why the builder went silent, then finish its run or ${Ft}`}:e.lane==="review"&&e.stale?{kind:"stale",since:new Date(Date.parse(e.inReviewSince)+wt).toISOString(),daily:!0,next:`Find out why the review went stale and fix what you can: rebase, CI, comments; if only a reviewer owes it, a thread line naming who; or ${eo}`}:e.waitsOn==="checking"?t.unverified?{kind:"calls",since:t.handedBackAt,next:t.next||"Verify the builder's judgment calls"}:{kind:"checking",since:t.handedBackAt,next:t.next||"Land the checked build"}:e.grilling&&t.grillAt&&!r("grill")?{kind:"grill",since:t.grillAt,next:"Start the grill asked for"}:e.prototyping&&t.prototypeAt&&!r("prototype")?{kind:"prototype",since:t.prototypeAt,next:"Draw the prototype asked for"}:c?{kind:"unasked",since:c.at,next:`Its ${c.kind} planner ended without its question: read its log, then post the question, start the planner again, or move the card's phase`}:e.recheckAt&&e.lane==="todo"&&e.phase==="ready"&&!e.blocked?{kind:"recheck",since:e.recheckAt,next:no}:e.refusal&&t.refusedAt?{kind:"refused",since:t.refusedAt,next:e.refusal}:e.next===$t&&a?{kind:"unowned",since:a,next:"Start a builder on it, or set its Next"}:t.unblockedAt&&e.lane!=="todo"&&!e.builder&&!e.blocked&&!t.writes.some(f=>f>t.unblockedAt)?{kind:"unblocked",since:t.unblockedAt,next:"Its block ended: act on what it waited for, or set its Next"}:null;if(!l?.since)return null;const u=String(l.since),m=[t.writes.find(f=>f>u),s].filter(Boolean).sort()[0]||null;return{kind:l.kind,since:u,picked:m,next:l.next,...l.daily?{daily:!0}:{}}}d(so,"orchestratorWaitOf");const Po=d((e,t=null)=>({key:e.id,ref:e.data.date,title:`Overnight triage ${e.data.date}`,kind:"triage",since:e.ts,picked:t,next:`Run the overnight triage and reply: board.mjs reply ${e.id}`}),"triageWaitOf");function Uo(e){const t=e.items.filter(n=>n.orchestrator).map(n=>({key:n.key,ref:n.ref,title:n.title,...n.orchestrator,bumpedAt:n.bumpedAt||null}));return[...t.filter(n=>n.bumpedAt).sort((n,s)=>n.bumpedAt.localeCompare(s.bumpedAt)),...t.filter(n=>!n.bumpedAt)]}d(Uo,"orchestratorWaits");const jo=30*6e4,oo=15*6e4,ro=60*6e4,ao=1440*6e4;function Wo(e,t,n){const s=n.toISOString(),r=[],a=[];return{waits:t.map(l=>{const u=e.find(p=>p.key===l.key&&p.kind===l.kind&&p.since===l.since);if(!u)return l.picked||r.push(l.key),{...l,bumped:s};const m=l.picked?[l.picked,u.bumped].filter(Boolean).sort().pop():u.bumped||l.since,f=n-Date.parse(m)>=(l.picked?l.daily?ao:ro:oo);return f&&a.push({key:l.key,ref:l.ref,kind:l.kind,since:l.since,next:l.next}),{...l,bumped:f?s:u.bumped||l.since,...u.pushed?{pushed:!0}:{}}}),added:r,again:a}}d(Wo,"waitsStep");function Fo(e,t){const n=d(s=>{const r=Math.floor((t-Date.parse(s))/6e4),a=Math.floor(r/60),c=r%60;return a?`${a}h${c?` ${c}m`:""}`:`${c}m`},"age");return`still waiting on you: ${e.map(s=>`${s.ref} ${s.kind} for ${n(s.since)}: ${s.next}`).join("; ")}`}d(Fo,"waitsAgainLine");const lo=15;function Ko(e,{idle:t,now:n}){const s=n.toISOString(),r=e.last||s;return t?e.since?e.pushed||n-Date.parse(e.since)<lo*6e4?{state:{...e,last:r},push:!1}:{state:{last:s,since:e.since,pushed:!0},push:!0}:{state:{last:r,since:s},push:!1}:{state:{last:r},push:!1}}d(Ko,"idleStep");function Go(e,t){const n=d(u=>String(u.closedAt||"")>t,"after"),s=e.filter(u=>u.kind==="work"&&u.lane==="done"&&!St(u)&&n(u)),r=new Map;for(const u of e)u.wave&&r.set(u.wave.slug,[...r.get(u.wave.slug)||[],u]);const a=[...r.values()].filter(u=>u.every(m=>m.lane==="done")&&u.some(n)).map(u=>u[0].wave.title),c=s.slice(0,3).map(u=>u.ref).join(", ")+(s.length>3?` and ${s.length-3} more`:"");return[s.length&&`${s.length} ${s.length===1?"card":"cards"} landed: ${c}`,...a.map(u=>`${u} finished`)].filter(Boolean).join(" \xB7 ")||"Nothing closed since the last idle notification."}d(Go,"idleSummary");export{q as ACTION_KIND,It as ACTION_LABELS,fs as ANSWERS_SUBMITTED,De as BUILDER_ASK,ue as BUILDER_KIND,hn as BUILDER_QUIET_AFTER,mn as BUILDER_STALE_AFTER,ht as BUILD_REFUSED,ce as BUTTON,Xe as COMMANDS,ao as DAILY_REWAKE_AFTER,Xs as DONE_FIELDS,Vs as DONE_KEPT,ge as HELPER,lo as IDLE_MINUTES,qt as INTENT_LABELS,kn as ITEM_EVENTS,He as LANDER,So as LANES,Ls as MAX_IMPLEMENTERS,Us as MAX_PLANNERS,$e as MOVE,$t as NO_NEXT,jo as ORCHESTRATOR_PUSH_AFTER,Eo as PAUSE_CLEARS,ns as PAUSE_HARD_STOP,kt as PHASES,ro as PICKED_REWAKE_AFTER,zn as PLANNER_WORD,Gn as PROTOTYPE_AGAIN,xo as PROTOTYPE_WAIT,V as PR_STATE,mt as QUESTION_REOPEN,oo as REWAKE_AFTER,fe as VISUAL,Do as archivedOf,Ro as arrivalsOf,Ao as buildBoard,Q as builds,$o as confirmedDrops,yn as fileFold,st as handedBackAt,Ko as idleStep,Go as idleSummary,Tn as mergeBlockers,as as modelName,No as movesOf,Bo as needsAnswer,Kn as noTakePicked,Jn as orchestratorDid,Uo as orchestratorWaits,vo as owesNext,Lo as ownerActions,ls as ownerQuestion,rs as pauseWork,Fn as picksNoTake,Z as plans,Oo as prototypeWaits,_t as providerOf,Ts as pullOf,Zs as pushTag,_o as rebasesDue,nt as refOf,ke as roundOf,is as roundSettledBy,Mo as roundsDue,Co as slimDone,Ut as stateEntries,At as stoppedWords,To as strictlyIdle,Tt as threadIndex,vs as threadOf,Hs as todoOf,qo as triageOf,Po as triageWaitOf,St as unlanded,js as visualAgent,Io as visualsDue,Fo as waitsAgainLine,Wo as waitsStep,$s as waveItems,As as withHub};
package/board/finish.mjs CHANGED
@@ -1,4 +1,5 @@
1
- var I=Object.defineProperty;var c=(t,a)=>I(t,"name",{value:a,configurable:!0});import P from"node:fs";import v from"node:path";import{ghSync as N,limitWords as q}from"../shared/gh.mjs";import*as o from"./store.mjs";import{builderRepo as E,git as w,joiningLand as F,landInTurn as S,passTests as W,syncBase as A,worktreesDir as j}from"./worktree.mjs";import{readPermissions as L}from"./permissions.mjs";import{landByBuilder as T}from"./headless.mjs";import{boardAt as C}from"../hub/boards.mjs";import{boardRepo as D}from"../hub/board-repo.mjs";const b=c(t=>{throw new o.BoardError(t)},"fail"),V=c(t=>typeof t=="string"&&t.trim()?t.trim():b("--text must be non-empty text"),"said");async function H(t,a,{text:r,closing:n,ownerStep:e,check:i,repo:s,onWait:g,merge:d=!1}){o.messageText(r);const f=a.split("/")[1],u=await o.recordedWorktree(t,a),{repo:$,base:l,remote:p}=E(t,{repo:s??u?.repo}),m={path:u?.path??v.join(j(),f),branch:u?.branch??f,repo:v.resolve($),base:l},M=await o.cardName(t,a),h=await o.readBoardSettings(t),R=p?D(C(t).route).github:null;if(p&&(!R||h.prs))return z(t,a,{...m,ref:M,text:V(r)});const B=await F(M,()=>x(t,a,{tree:m,ref:M,base:l,remote:p,repo:$,settings:h,text:r,closing:n,ownerStep:e,check:i,onWait:g}),{merge:d});return B.joined?await o.isFinished(t,a)?{said:"landed and done",lines:[]}:H(t,a,{text:r,closing:n,ownerStep:e,check:i,repo:s,onWait:g,merge:d}):B}c(H,"finishCard");async function x(t,a,{tree:r,ref:n,base:e,remote:i,repo:s,settings:g,text:d,closing:f,ownerStep:u,check:$,onWait:l}){const p=g.auto_merge||!!(await o.heldMerge(t,a))?.tapped,m=p&&await o.blockWords(t,a);m&&b(`${n} is blocked ${m}, so it can't land; it lands once nothing blocks it`),await o.checkClose(t,a,d,u,$),await o.checkCallsVerified(t,a),i&&(A(r.repo,e),w(r.repo,"branch","--unset-upstream",r.branch)),p&&await o.landingLine(t,a);const M={site:t,key:a,first:await o.landFirst(t,a)};if(await S({...r,ref:n},{hold:!p,onWait:l,queue:M,sync:c(()=>i&&A(r.repo,e),"sync")}),!p){const R=await o.setItem(t,a,{mergeReady:r.branch,ownerStep:u,check:$});return await o.appendMessage(t,a,{text:d}),{said:"verified; waits for your Merge",lines:R.lines}}const h=await o.setItem(t,a,{done:!0,landed:!0,...f?{closing:f}:{text:d},ownerStep:u,check:$});return{said:u===void 0?"landed and done":`landed; waits on the owner step "${u.trim()}"`,lines:[...h.lines,...await _(t,a,s,e)]}}c(x,"landCard");async function y(t,a,{launch:r=T}={}){(await o.heldMerge(t,a))?.tapped||b(`${a} isn't waiting on a Merge tap`);try{const{base:e}=E(t,{repo:(await o.recordedWorktree(t,a))?.repo}),i=c(s=>o.appendStatus(t,a,"land-waiting",{card:s}),"onWait");return await H(t,a,{text:`Landed on ${e} on your Merge.`,closing:["landed-on-merge",{base:e}],onWait:i,merge:!0})}catch(e){if(!(e instanceof o.BoardError))throw e;const i=e.message.split(`
2
- `)[0];if(/^rebasing .+ conflicts in |^tests failed in /.test(i)){await o.appendStatus(t,a,"lander-handoff",{why:i});try{await r(t,{key:a,model:await o.builderModel(t,a)},{why:i})}catch(s){await o.appendStatus(t,a,"lander-failed",{error:s.message})}}else await o.appendStatus(t,a,"land-failed",{why:i});throw e}}c(y,"landHeld");async function _(t,a,r,n){if(!(await L(r)).pushMain)return[];const e=w(r,"push","--quiet","origin",n);if(e.ok)return[`pushed ${n} to origin`];const i=`${n} didn't reach origin: ${e.err}; push it with git -C ${r} push origin ${n}`;return await o.appendStatus(t,a,"push-failed",{base:n,error:e.err}),[`landed, but ${i}`]}c(_,"pushBase");async function z(t,a,{path:r,branch:n,base:e,ref:i,text:s}){await o.checkCallsVerified(t,a),P.existsSync(r)||b(`no worktree at ${r}`),w(r,"status","--porcelain").out&&b(`${r} has uncommitted changes; commit them there first`),Number(w(r,"rev-list","--count",`refs/remotes/origin/${e}..HEAD`).out)===0&&b(`${n} has no commits beyond ${e}; nothing to send for review`),await W(r,{outcome:"nothing was pushed"});const{github:g}=D(C(t).route),d=g?await o.cardPR(t,a):null,f=d?w(r,"rev-parse",`refs/remotes/origin/${n}`).out:null,u=d?w(r,"push","--quiet",`--force-with-lease=refs/heads/${n}:${f}`,"origin",`HEAD:refs/heads/${n}`):w(r,"push","--quiet","origin",`HEAD:refs/heads/${n}`);if(u.ok||b(`could not push ${n} to origin: ${u.err}`),d){const h=c(B=>Number(w(r,"rev-list","--count",`refs/remotes/origin/${e}..${B}`).out),"ahead");await o.recordRebase(t,a,{from:f,to:w(r,"rev-parse","HEAD").out,replayed:h("HEAD")<=h(f)});const R=await o.setItem(t,a,{pr:d});return await o.appendMessage(t,a,{text:s}),{said:`pushed ${n} to PR #${d}`,lines:R.lines}}if(!g){const h=await o.setItem(t,a,{pushed:n});return await o.appendMessage(t,a,{text:s}),{said:`pushed ${n} for its merge`,lines:h.lines}}const{title:$}=await o.briefFacts(t,a),l=N(["pr","create","--draft","--repo",g,"--base",e,"--head",n,"--title",`${i}: ${$}`,"--body",s],{cwd:r}),p=`${l.stdout||""}
3
- ${l.stderr||""}`,m=(l.status===0||/already exists/.test(p))&&/\/pull\/(\d+)/.exec(p)?.[1];l.limited&&await o.appendStatus(t,a,"gh-limited",{what:"No PR opened",words:q(l.limited)}),m||b(`could not open a draft PR for ${n}: ${(l.stderr||`gh exited ${l.status}`).trim().split(`
4
- `)[0]}`);const M=await o.setItem(t,a,{pr:Number(m)});return await o.appendMessage(t,a,{text:s}),{said:`draft PR #${m} opened`,lines:M.lines}}c(z,"sendForReview");export{H as finishCard,y as landHeld};
1
+ var P=Object.defineProperty;var c=(t,a)=>P(t,"name",{value:a,configurable:!0});import N from"node:fs";import E from"node:path";import{ghSync as j,limitWords as q}from"../shared/gh.mjs";import*as o from"./store.mjs";import{builderRepo as A,git as f,joiningLand as F,landInTurn as S,passTests as W,syncBase as D,worktreesDir as L}from"./worktree.mjs";import{readPermissions as T}from"./permissions.mjs";import{landByBuilder as V}from"./headless.mjs";import{boardAt as H}from"../hub/boards.mjs";import{boardRepo as C}from"../hub/board-repo.mjs";import{subjectFault as x}from"./commit-message.mjs";const $=c(t=>{throw new o.BoardError(t)},"fail"),_=c(t=>typeof t=="string"&&t.trim()?t.trim():$("--text must be non-empty text"),"said");async function I(t,a,{text:r,closing:e,ownerStep:n,check:s,repo:d,onWait:m,merge:u=!1,title:h}){o.messageText(r);const l=a.split("/")[1],p=await o.recordedWorktree(t,a),{repo:b,base:i,remote:w}=A(t,{repo:d??p?.repo}),M={path:p?.path??E.join(L(),l),branch:p?.branch??l,repo:E.resolve(b),base:i},R=await o.cardName(t,a),g=await o.readBoardSettings(t),B=w?C(H(t).route).github:null;if(w&&(!B||g.prs))return J(t,a,{...M,title:h,text:_(r)});const v=await F(R,()=>z(t,a,{tree:M,ref:R,base:i,remote:w,repo:b,settings:g,text:r,closing:e,ownerStep:n,check:s,onWait:m}),{merge:u});return v.joined?await o.isFinished(t,a)?{said:"landed and done",lines:[]}:I(t,a,{text:r,closing:e,ownerStep:n,check:s,repo:d,onWait:m,merge:u,title:h}):v}c(I,"finishCard");async function z(t,a,{tree:r,ref:e,base:n,remote:s,repo:d,settings:m,text:u,closing:h,ownerStep:l,check:p,onWait:b}){const i=m.auto_merge||!!(await o.heldMerge(t,a))?.tapped,w=i&&await o.blockWords(t,a);w&&$(`${e} is blocked ${w}, so it can't land; it lands once nothing blocks it`),await o.checkClose(t,a,u,l,p),await o.checkCallsVerified(t,a),s&&(D(r.repo,n),f(r.repo,"branch","--unset-upstream",r.branch)),i&&await o.landingLine(t,a);const M={site:t,key:a,first:await o.landFirst(t,a)};if(await S({...r,ref:e},{hold:!i,onWait:b,queue:M,sync:c(()=>s&&D(r.repo,n),"sync")}),!i){const g=await o.setItem(t,a,{mergeReady:r.branch,ownerStep:l,check:p});return await o.appendMessage(t,a,{text:u}),{said:"verified; waits for your Merge",lines:g.lines}}const R=await o.setItem(t,a,{done:!0,landed:!0,...h?{closing:h}:{text:u},ownerStep:l,check:p});return{said:l===void 0?"landed and done":`landed; waits on the owner step "${l.trim()}"`,lines:[...R.lines,...await G(t,a,d,n)]}}c(z,"landCard");async function at(t,a,{launch:r=V}={}){(await o.heldMerge(t,a))?.tapped||$(`${a} isn't waiting on a Merge tap`);try{const{base:n}=A(t,{repo:(await o.recordedWorktree(t,a))?.repo}),s=c(d=>o.appendStatus(t,a,"land-waiting",{card:d}),"onWait");return await I(t,a,{text:`Landed on ${n} on your Merge.`,closing:["landed-on-merge",{base:n}],onWait:s,merge:!0})}catch(n){if(!(n instanceof o.BoardError))throw n;const s=n.message.split(`
2
+ `)[0];if(/^rebasing .+ conflicts in |^tests failed in /.test(s)){await o.appendStatus(t,a,"lander-handoff",{why:s});try{await r(t,{key:a,model:await o.builderModel(t,a)},{why:s})}catch(d){await o.appendStatus(t,a,"lander-failed",{error:d.message})}}else await o.appendStatus(t,a,"land-failed",{why:s});throw n}}c(at,"landHeld");async function G(t,a,r,e){if(!(await T(r)).pushMain)return[];const n=f(r,"push","--quiet","origin",e);if(n.ok)return[`pushed ${e} to origin`];const s=`${e} didn't reach origin: ${n.err}; push it with git -C ${r} push origin ${e}`;return await o.appendStatus(t,a,"push-failed",{base:e,error:n.err}),[`landed, but ${s}`]}c(G,"pushBase");async function J(t,a,{path:r,branch:e,base:n,title:s,text:d}){await o.checkCallsVerified(t,a),N.existsSync(r)||$(`no worktree at ${r}`),f(r,"status","--porcelain").out&&$(`${r} has uncommitted changes; commit them there first`),Number(f(r,"rev-list","--count",`refs/remotes/origin/${n}..HEAD`).out)===0&&$(`${e} has no commits beyond ${n}; nothing to send for review`);const{github:m}=C(H(t).route),u=m?await o.cardPR(t,a):null,h=s??f(r,"log","--reverse","--format=%s",`refs/remotes/origin/${n}..HEAD`).out.split(`
3
+ `)[0],l=m&&!u&&x(h);l&&$(`--title "${h}" ${l}; pass --title "<type>(<scope>): <summary>", at most 72 characters`),await W(r,{outcome:"nothing was pushed"});const p=u?f(r,"rev-parse",`refs/remotes/origin/${e}`).out:null,b=u?f(r,"push","--quiet",`--force-with-lease=refs/heads/${e}:${p}`,"origin",`HEAD:refs/heads/${e}`):f(r,"push","--quiet","origin",`HEAD:refs/heads/${e}`);if(b.ok||$(`could not push ${e} to origin: ${b.err}`),u){const g=c(v=>Number(f(r,"rev-list","--count",`refs/remotes/origin/${n}..${v}`).out),"ahead");await o.recordRebase(t,a,{from:p,to:f(r,"rev-parse","HEAD").out,replayed:g("HEAD")<=g(p)});const B=await o.setItem(t,a,{pr:u});return await o.appendMessage(t,a,{text:d}),{said:`pushed ${e} to PR #${u}`,lines:B.lines}}if(!m){const g=await o.setItem(t,a,{pushed:e});return await o.appendMessage(t,a,{text:d}),{said:`pushed ${e} for its merge`,lines:g.lines}}const i=j(["pr","create","--draft","--repo",m,"--base",n,"--head",e,"--title",h,"--body",d],{cwd:r}),w=`${i.stdout||""}
4
+ ${i.stderr||""}`,M=(i.status===0||/already exists/.test(w))&&/\/pull\/(\d+)/.exec(w)?.[1];i.limited&&await o.appendStatus(t,a,"gh-limited",{what:"No PR opened",words:q(i.limited)}),M||$(`could not open a draft PR for ${e}: ${(i.stderr||`gh exited ${i.status}`).trim().split(`
5
+ `)[0]}`);const R=await o.setItem(t,a,{pr:Number(M)});return await o.appendMessage(t,a,{text:d}),{said:`draft PR #${M} opened`,lines:R.lines}}c(J,"sendForReview");export{I as finishCard,at as landHeld};
@@ -1,8 +1,8 @@
1
- var Q=Object.defineProperty;var l=(t,e)=>Q(t,"name",{value:e,configurable:!0});import X from"node:os";import{BRIEF_LINE_LIMIT as J}from"./hub-lines.mjs";import k from"node:path";import{fileURLToPath as Z}from"node:url";import{launchAgent as P}from"./agents.mjs";import{processStarts as W,ps as C}from"../hub/live.mjs";import{boardAt as M}from"../hub/boards.mjs";import{readHubRules as ee}from"../hub/rules.mjs";import{builderRepo as O}from"./worktree.mjs";import{appendStatus as te,BoardError as oe,briefFacts as L,readBoardRules as re,recordedSession as ne,recordSession as E}from"./store.mjs";import{HELPER as se,plans as ae,VISUAL as ie}from"./domain.mjs";const he=Z(new URL("./bin/board.mjs",import.meta.url)),g=l(t=>`node ${he} --site ${t}`,"cli"),F=l(t=>`git -c core.commentChar=';' rebase ${t}`,"rebase"),de="a draft .md of your own outside the board's data folder (such as in /tmp)",le=l((t,e,r)=>`\`${t} item notes ${e} --heading "${r}" --file <draft.md>\``,"notesCommand"),T=l((t,e="Rules from the hub and this board:")=>t.length?[e,...t.map(r=>`- ${r}`),""]:[],"ruleLines"),x=l(t=>t.length?["Related cards: read their notes for context; don't build their scope.",...t.map(e=>`- ${e.ref} "${e.title}" (${e.relation}, ${e.lane}): ${e.notes?`notes ${e.notes}`:"no notes"}, thread ${e.thread}`),""]:[],"linkLines"),I=l(t=>`The card's thread, which holds the owner's messages (who: love): ${t}. Read it live.`,"threadLine"),Y=l(({route:t,key:e,worktree:r,base:i})=>[`- With no unverified calls, done finishes the card itself: it rebases onto ${i}, reruns the full test suite, fast-forwards ${i} and closes the card (on a board with pull requests it pushes the branch and opens a draft PR instead; with Auto-merge off it stops before the fast-forward, and the card waits for the owner's Merge).`,`- On a conflict it undoes its rebase and names the files: run \`${F(i)}\` in ${r}, resolve each conflict keeping both sides' intent, continue with \`git -c core.commentChar=';' rebase --continue\`, rerun the tests, and run done again.`,"- On failing tests, fix them, commit, and run done again.","- While another card is landing, done waits its turn and then lands; leave it running.","- Once a reviewer has the card's PR link, done refuses without `--updated \"<what changed>\"`, which goes in that link's Slack thread, or `--updated none` for a change only to comments, names, docs or tests.",`- Finishing never goes to the orchestrator. If done refuses for a reason you can't fix, record it with \`${g(t)} builder call ${e} "<why>"\` and run done again: with the call it hands the card back.`],"finishSteps"),B=l(({route:t,key:e})=>`\`${g(t)} builder done ${e} --text "<what you checked>"\``,"finishCommand"),ce=l((t,e)=>[`5. To run a separate part of the work in parallel, ask the board for a helper: \`${t} agent launch ${e} --name <short-name> --task "<the whole task, with the files and what to hand back>"\`, adding --writes when it changes code or runs tests (it gets its own worktree off your branch, and waits for a free implementer slot). Then \`${t} agent wait ${e} --name <short-name>\`, which prints its hand-back; it returns within 10 minutes, so run it again while it says still running, and do the task yourself if it says the helper exited. Merge a writing helper's work with \`${t} agent merge ${e} --name <short-name>\` before you test and finish.`],"helperSteps");function ue({route:t,key:e,ref:r,title:i,notes:n,thread:a,worktree:h,base:u,rules:p=[],links:c=[]}){const d=g(t);return[`You are the headless builder for card ${r} (${e}, "${i}") on the kickflip board /${t}. The board launched you; nobody watches this session, so never wait on a person. Work only in ${h}. Never restart the hub or a board server, and never push.`,"",`1. Run \`${d} builder start ${e} --kind build\`. If it refuses, stop.`,`2. Report progress with \`${d} builder progress ${e} --phase reading|building|testing|checking|landing "<plain, 80 characters or fewer>"\`, at least every 10 minutes. The board adds the phase word; don't start the text with it. The phases:`," - reading: the notes and the code, until the first test is written."," - building: the tests and the code, the ADR and docs, and the commit."," - testing: the full suite run before you finish."," - checking: your own review of the diff before you hand back; the Orchestrator's review of your calls continues on the same 4th bar."," - landing: set by the finish step itself; you never report it.",`3. Decide, record the call (step 4) and carry on: the orchestrator reviews your calls after the build. Ask it only when you are blocked, meaning every way forward would likely be thrown away: the spec contradicts itself or the code, a rule needs the owner's go before code is written, or the answer is a fact only the orchestrator has. Then run \`${d} builder ask ${e} "<question>"\`, do any work the answer can't change, and wait with \`${d} builder asks ${e} --wait\`, which returns within 10 minutes, so run it again while it says still waiting. If no answer comes in 30 minutes, record the question as a call, "Question: <question>", and hand back.`,`4. Record each judgment call the notes leave open with \`${d} builder call ${e} "<call>"\` instead of guessing silently or asking. A problem you find outside your card is a call "Found: <what>" for the orchestrator to file at review; ask about it at once only when it stalls other cards' builds or lands.`,...ce(d,e),"",n?`Spec: the card's notes, ${n}, all sections, where later sections override earlier ones.`:"The card has no notes file: build from its title, and record what you had to decide as calls.",`${I(a)} Read it with the notes: a message of the owner's is an instruction, but where it contradicts the notes, the notes win; that contradiction counts as blocked (step 3), so ask with \`${d} builder ask ${e} "<question>"\` and wait as step 3 says. Read the thread again in checking, before you finish, for anything the owner wrote during the build.`,"",...x(c),...T(p),"Write tests first, and run the full suite once, in the foreground, at the end. Where the repo keeps ADRs, write one named with a timestamp: docs/adr/YYYY-MM-DD-HHMM-<slug>.md.",`Commit with \`git -c core.commentChar=';' commit -F <file>\`, the subject "${r}: <what the card now does>".`,"",`To finish, run ${B({route:t,key:e})}.`,"- If you recorded a judgment call, it hands the card back for the orchestrator to verify your calls; stop there: the orchestrator's verification finishes the card.",...Y({route:t,key:e,worktree:h,base:u}),"","Never push."].join(`
2
- `)}l(ue,"builderBrief");function H({route:t,key:e,ref:r,title:i,thread:n,worktree:a,base:h,answers:u=[],resumed:p=!1,why:c}){const d=g(t);return[p?`The board resumes you, the builder of card ${r} (${e}, "${i}") on the kickflip board /${t}, to land your build: ${c??"the orchestrator verified your judgment calls"}, and it waits only to land. Nobody watches this session, so never wait on a person. Work only in ${a}, never restart the hub or a board server, and never push.`:`You are the headless lander for card ${r} (${e}, "${i}") on the kickflip board /${t}. Its build is done and the orchestrator verified its judgment calls; it waits only to land. Nobody watches this session, so never wait on a person. Work only in ${a}, never restart the hub or a board server, and never push.`,"",`1. Run \`${d} builder start ${e} --kind build --label Lander --phase landing --progress "taking up the verified build"\`. If it refuses, stop.`,`2. Report progress with \`${d} builder progress ${e} --phase landing "<plain, 80 characters or fewer>"\`. The board adds the phase word; don't start the text with it.`,...u.length?["3. The owner answered the builder's deferred asks. Where an answer changes the build, change it, with its tests, and commit:",...u.map(o=>`- ${o.ask} "${o.question}": ${o.answer}`)]:[],"",I(n),"",`To finish, run ${B({route:t,key:e})}.`,...Y({route:t,key:e,worktree:a,base:h}),"","Never push."].join(`
3
- `)}l(H,"landerBrief");function K({route:t,key:e,ref:r,title:i,thread:n,worktree:a,base:h,pr:u,resumed:p=!1}){const c=g(t);return[...p?[`The board resumes you, the builder of card ${r}, for this run: the lines below are your brief for it.`]:[],`You are the headless rebase run for card ${r} (${e}, "${i}") on the kickflip board /${t}. Its PR #${u} conflicts with ${h}; rebase its branch onto ${h} so the PR is clean again. Nobody watches this session, so never wait on a person. Work only in ${a}, never restart the hub or a board server, and never push.`,"",`1. Run \`${c} builder start ${e} --kind build --label Rebase --phase building --progress "Rebase run started \xB7 fetching ${h}"\`. If it refuses, stop.`,`2. Run \`git fetch origin\`, then \`${F(`origin/${h}`)}\`. Resolve each conflict keeping both sides' intent, \`git add\` it and continue with \`git -c core.commentChar=';' rebase --continue\`. Report each step with \`${c} builder progress ${e} --phase building "<line>"\`, the board adds the phase word, in these words: "Rebasing onto ${h} \xB7 resolving <n> files", then "Rebasing onto ${h} \xB7 suite running".`,"3. Run the full test suite once, in the foreground. Fix what the rebase broke, and commit each fix with `git -c core.commentChar=';' commit -F <file>`. A push with commits of its own is no longer rebase-only, so a merge after an approval won't count it as trivial.",`4. If a conflict or a failing test is past what you can resolve with confidence, run \`git -c core.commentChar=';' rebase --abort\` if a rebase is under way, record it with \`${c} builder call ${e} "Rebase failed in <the files or tests> \xB7 <why>"\`, and run the finish step: with the call it hands the card to the orchestrator.`,"",I(n),"",`To finish, run ${B({route:t,key:e})}, the text saying what you resolved. It reruns the suite and pushes the branch to PR #${u} with --force-with-lease; the PR stays as it is.`,"- If it refuses because someone pushed to the branch since your fetch, fetch and rebase again (step 2), then run done again.","- On failing tests, fix them, commit, and run done again.","","Never push."].join(`
4
- `)}l(K,"rebaseBrief");function pe({route:t,key:e,ref:r,title:i,notes:n,thread:a,kind:h,repo:u,rules:p=[],links:c=[],text:d,files:o=[],question:s,note:m,choice:f}){const w=g(t),b=h==="grill";return[`You are the headless ${b?"grill":"prototype"} planner for card ${r} (${e}, "${i}") on the kickflip board /${t}. The board launched you; nobody watches this session, so never wait on a person: the owner answers on the board, and a later planner or builder picks up from their answers. Read and run in ${u}; write no output code ${b?"there":`in ${u} itself`}, never restart the hub or a board server, and never push.`,"",`1. Run \`${w} builder start ${e} --kind ${h}\`. If it refuses, stop.`,`2. Gather the context yourself: ${n?`the card's notes, ${n}, all sections, where later sections override earlier ones; `:"the card has no notes file yet; "}its thread, ${a}, the repo's docs/adr and CONTEXT.md, and the cards its notes and thread link.`,`3. Report progress with \`${w} builder progress ${e} "<plain, 80 characters or fewer>"\` at least every 10 minutes.`,b?`4. Find every decision the card leaves open: read the code it touches and answer what the code answers yourself. Post each decision left as a question for the owner with \`${w} question add --file <json>\` on topic item:${e}, one per decision, your recommendation first. Once you finish, the orchestrator screens them before the owner sees them, settling the ones the board already answers and passing the owner the rest. Invoke the grilling skill with the Skill tool and run it as one round: its questions go to the board with question add, never into the chat, and you never wait for an answer; after the round, finish. (With no Skill tool, follow this step as written.) When the code shows the card has separable parts, each a build of its own, propose splitting it into a wave of smaller cards as one question ahead of the prototype question: its options "Split as proposed" and "Keep as one card", your recommendation first. Slice it as ~/.claude/skills/to-tickets/SKILL.md step 3, "Draft vertical slices", says (read that step; you can't invoke the skill, and skip its quiz and publish steps). The first card is the thinnest end-to-end path. The question's context lists each proposed card with its title, its scope, the files it touches and the earlier proposed cards it waits on, or none: a card waits on an earlier one only when it builds on that card or shares its seam (the same function, component, CLI command or doc paragraph); sharing only a file waits on nothing. Write the same breakdown in your notes section. On Split the orchestrator files the cards when the card stages; never file them yourself. End every grill with one more question, "Prototype round first?", whose options are yes and no, with "prototype_gate": true in its \`question add --file\` entry: once the owner has answered every question the board moves the card to prototyping on yes, or to staging on no, so nothing else moves it. Recommend yes when the card changes the hub's or a board's UI, no otherwise. Ask it even when it is your only question.`:`4. Invoke the prototype skill with the Skill tool and build the round as take files, one per option: record them with \`${w} prototype add <topic> --card ${e} --take <K>:<label> \u2026\`, write the take files it prints, built from the repo's existing components, helpers and scripts fed mock data (the prototype template loads the board's scripts, so a take reuses the board's components; a hub-page take reuses them by path or copy), each take showing the states it needs inside itself, then post one question whose url opens prototype-<topic>.html with \`${w} question add --file <json>\` on topic item:${e}, never asking in the chat. Build in situ only where one of the board's rules asks for it: then, run \`${w} prototype base\`, which makes it or moves it to main and prints its path, whether its build script is there and the listener a page loads. When the build script is missing, write one there that serves the app and prints "port <n>" (board/build-script.mjs). Add one page to the worktree, at a path no other round uses, built from the repo's real components, helpers and scripts fed mock data, fully interactive; it reads the take from ?variant= and the state from ?state=, and loads the listener so \`KickflipPrototype.on((take, state) => \u2026)\` re-renders it in place when the viewer switches. Record it with \`${w} prototype add <topic> --card ${e} --served <path> --take <K>:<label> \u2026 --state <key>:<label> \u2026\`, one take per option and one state for each state that matters to the question, then post one question whose url opens prototype-<topic>.html with \`${w} question add --file <json>\` on topic item:${e}, never asking in the chat. (With no Skill tool, follow this step as written.)`,...d?[` The owner asked for this ${b?"grill":"prototype"}, writing: "${d}"`]:[],...o.length?[` The owner attached: ${o.map(q=>q.path).join(", ")}.`]:[],...s?[` The owner asked for prototypes of question ${s}${m?`, noting "${m}"`:""}${f?`, leaning to option ${f}`:""}: draw that question's next round, its question naming round_of ${s}.`]:[],`5. Record what you learned in the card's notes, naming each answered question's id: write it in ${de}, then run ${le(w,e,`${b?"Grill":"Prototype"} (<MM/DD>)`)}, which appends it as a section. The notes file is read-only; never write into it. Anything you leave open becomes a question with question add, never only a line in the notes, so the card can't go ready past it. A question's text is one line of at most ${J} characters (question add refuses a longer one); put the detail in its context and the options' details, which take markdown.`,...b?[`6. Where the owner asked for prototypes, or a rule here wants a UI prototype first, end the card \`${w} item set ${e} --phase prototyping\` instead and skip the prototype question. Otherwise the prototype question is what moves the card on: never set it ready yourself, and never leave a Next that asks the owner to mark it ready.`]:[],"",...x(c),...T(p,"Rules from the hub and this board, written for the orchestrator: where one tells you to push, land, restart the hub or a board server, or do the orchestrator's work, it isn't yours; you never push or restart:"),`To finish, run \`${w} builder done ${e} --text "<what you asked>"\`.`,"","Never push."].join(`
5
- `)}l(pe,"plannerBrief");function fe({route:t,key:e,ref:r,title:i,notes:n,thread:a,repo:h,agent:u,rules:p=[],links:c=[],text:d,files:o=[]}){const s=g(t);return[`You are the headless visual agent for card ${r} (${e}, "${i}") on the kickflip board /${t}. The owner asked, in the card's thread, for a visual: one HTML page that answers in a visual way, such as a diagram, a flow or a comparison. It is not a prototype or a grill: no question, no takes. The board launched you; nobody watches this session, so never wait on a person. Read and run in ${h}; write no code there, never restart the hub or a board server, and never push.`,"",`1. Run \`${s} builder start ${e} --kind visual --agent ${u}\`. If it refuses, stop.`,`2. Gather what the page needs: ${n?`the card's notes, ${n}; `:""}its thread, ${a}, and the code or docs it is about.`,d?` The owner wrote: "${d}"`:" The owner typed nothing: draw what the thread was last discussing.",...o.length?[` The owner attached: ${o.map(m=>m.path).join(", ")}.`]:[],"3. Write one HTML file outside the repo, such as in a temporary folder. Keep its own CSS and script inline; it may load a library such as Mermaid or D3 from a CDN. Make it read well at phone width (390px) and on a desktop, in the dark and the light theme (prefers-color-scheme).",`4. Place it with \`${s} visual add ${e} --file <page.html> --title "<what it shows>"\`, which copies it to the board and links it in the thread.`,"","Write nothing else: no notes, questions, card state, Next or progress lines.","",...x(c),...T(p,"Rules from the hub and this board, written for the orchestrator: where one tells you to push, land, restart the hub or a board server, or do the orchestrator's work, it isn't yours; you never push or restart:"),`To finish, run \`${s} builder done ${e} --agent ${u}\`.`,"","Never push."].join(`
6
- `)}l(fe,"visualBrief");function we({route:t,key:e,ref:r,title:i,notes:n,thread:a,agent:h,task:u,writes:p,cwd:c,rules:d=[],links:o=[]}){const s=g(t);return[`You are the headless helper ${h} on card ${r} (${e}, "${i}") on the kickflip board /${t}. Another agent working on the card asked the board for you to do one task beside it, and waits on your hand-back. Nobody watches this session, so never wait on a person. Never restart the hub or a board server, and never push.`,p?`Work only in ${c}, your own worktree, branched from the card's: commit your work there with \`git -c core.commentChar=';' commit -F <file>\`, the subject "${r}: <what it does>". The card's builder merges your branch, so leave nothing uncommitted.`:`Read and run in ${c}; change no files there and commit nothing.`,"","The task:",u,"",`1. Run \`${s} builder start ${e} --kind helper --agent ${h}\`. If it refuses, stop.`,`2. Report progress with \`${s} builder progress ${e} --agent ${h} --phase reading|building|testing|checking "<plain, 80 characters or fewer>"\` at least every 10 minutes; the board adds your name and the phase word.`,"3. Do only the task. Don't ask the orchestrator or the owner, record no judgment calls and post no questions: put any decision you had to make in your hand-back.",n?` The card's notes, for context: ${n}.`:"",` ${I(a)}`,"",...x(o),...T(d,"Rules from the hub and this board, written for the orchestrator: where one tells you to push, land, restart the hub or a board server, or do the orchestrator's work, it isn't yours; you never push or restart:"),`To finish, run \`${s} builder done ${e} --agent ${h} --text "<your hand-back: what you did or found, ${p?"what you committed, ":""}and any decision you made>"\`.`,"","Never push."].filter((m,f,w)=>m!==""||w[f-1]!=="").join(`
7
- `)}l(we,"helperBrief");const me=6e4;function be(t,{starts:e=W}={}){const r=t.filter(n=>n.pid&&n.at).map(n=>n.pid),i=r.length&&e(r)||new Map;return t.filter(n=>{const a=i.get(n.pid);return a!==void 0&&a<=Date.parse(n.at)&&a>=Date.parse(n.at)-me})}l(be,"launchedAgents");function je(t,{starts:e=W,kill:r=l((n,a)=>process.kill(-n,a),"kill"),killAfter:i=5e3}={}){const n=be(t,{starts:e});for(const{pid:a}of n){try{r(a,"SIGTERM")}catch{continue}setTimeout(()=>{try{r(a,"SIGKILL")}catch{}},i).unref()}return n.length}l(je,"stopAgents");async function Ae(t,{grace:e=5e3}={}){const r=["-A","-o","pid=,ppid=,pgid=,args="],i=C(r)??C(r);if(i===null)throw new oe("ps gave no answer, so nothing was stopped; run it again");const n=i.split(`
8
- `).map(o=>/^\s*(\d+)\s+(\d+)\s+(\d+)\s+(.*)$/.exec(o)).filter(Boolean).map(([,o,s,m,f])=>({pid:Number(o),ppid:Number(s),pgid:Number(m),args:f})),a=new Set(n.filter(o=>t.includes(o.pgid)).map(o=>o.pid));for(let o=!0;o;){o=!1;for(const s of n)!a.has(s.pid)&&a.has(s.ppid)&&(a.add(s.pid),o=!0)}const h=n.find(o=>o.pid===process.pid)?.pgid,u=n.filter(o=>a.has(o.pid)&&o.pgid>1&&o.pgid!==h),p=[...new Set(u.map(o=>o.pgid))],c=l(o=>{for(const s of p)try{process.kill(-s,o)}catch{}},"signal");c("SIGTERM");const d=Date.now()+e;for(;u.some(o=>j(o.pid))&&Date.now()<d;)await new Promise(o=>setTimeout(o,50));return u.some(o=>j(o.pid))&&c("SIGKILL"),u.map(({pid:o,args:s})=>({pid:o,args:s}))}l(Ae,"stopRuns");const j=l(t=>{try{return process.kill(t,0),!0}catch(e){return e.code==="EPERM"}},"pidAlive");async function Ne(t,e,{launch:r,handBack:i,alive:n=j,held:a=l(()=>!1,"held"),stopped:h=new Set,paused:u=new Set,limitedUntil:p=l(()=>null,"limitedUntil"),atLimit:c=l(async()=>{},"atLimit")}){const d={};for(const[o,s]of Object.entries(t)){if(!e.has(o))continue;if(h.has(o)){d[o]={...s,handedBack:!0};continue}if(u.has(o)||s.pid!==null&&n(s.pid)||s.handedBack){d[o]=s;continue}const m={key:o,...s.kind?{kind:s.kind}:{},...s.model?{model:s.model}:{}},f=s.pid!==null?p(s):null;if(f){await c(m,f),d[o]={...s,pid:null};continue}if(a(s.kind??"claude")){d[o]=s;continue}if(s.pid!==null&&s.relaunched){await i(m),d[o]={...s,handedBack:!0};continue}const{key:w,...b}=m;d[o]={...b,...await r(m),relaunched:s.pid!==null||!!s.relaunched}}return d}l(Ne,"reviveBuilders");const _=l((t,e)=>k.join(X.homedir(),".claude","kickflip","logs",`${e}-${t}-${new Date().toISOString().replace(/[:.]/g,"-")}.log`),"logFile");async function ge(t,{key:e,kind:r="claude",model:i,agent:n="main",text:a,files:h,question:u,note:p,choice:c,task:d,writes:o,worktree:s},{lander:m=!1}={}){const f=await L(t,e),w=M(t)?.route??k.basename(t),b=[...ee(),...await re(t)].map(z=>z.text),{base:q,repo:S}=O(t),y=ae({kind:r}),v=r===se,A=!y&&!v&&!m&&f.rebasePR!==null,N=r===ie,D=y?S:v?s??f.worktree??S:f.worktree,$={...f,route:w,base:q,repo:S,rules:b,kind:r,agent:n,text:a,files:h,question:u,note:p,choice:c,task:d,writes:o,cwd:D,pr:f.rebasePR},U=N?"Visual agent":v?`Helper ${n}`:y?"Planner":m?"Lander":A?"Rebase run":"Builder",V=N?fe($):v?we($):y?pe($):m?H($):A?K($):ue($),R=await P({kind:y||v?"claude":r,model:i,cwd:D,site:t,prompt:V,log:_(e.split("/")[1],U.split(" ")[0].toLowerCase())});return await E(t,e,R.sessionId,R.pid,n,k.basename(R.log)),R}l(ge,"launchBuilder");const De=l(({ref:t,worktree:e,cleared:r})=>`The board paused your build of card ${t}, and the pause has cleared: ${r}. Carry on where you stopped, in ${e}, following your brief as before. Your builder record is still open, so don't run builder start again.`,"resumeBrief");async function G(t,{key:e,kind:r="claude",model:i,session:n,brief:a,fresh:h=!1,freshLaunch:u={}}){if(r!=="claude"||!n||h)return{...await ge(t,{key:e,kind:r,model:i},u),resumed:!1};const p=await L(t,e),c=await P({kind:r,model:i,cwd:n.worktree??p.worktree,site:t,prompt:a(p),resume:n.id,log:_(e.split("/")[1],"builder")});return await E(t,e,c.sessionId??n.id,c.pid,"main",k.basename(c.log)),{...c,resumed:!0}}l(G,"resumeBuilder");async function Pe(t,{key:e,kind:r="claude",model:i},{why:n,fresh:a=!1}={}){const h=await ne(t,e),u=await L(t,e),p=u.rebasePR!==null,c=h&&(!p||h.worktree===u.worktree)?h:null,d=M(t)?.route??k.basename(t),{base:o}=O(t),s=l(w=>(p?K:H)({...w,route:d,base:o,pr:w.rebasePR,why:n,resumed:!0}),"brief"),m={lander:!p};let f;try{f=await G(t,{key:e,kind:r,model:i,session:c,brief:s,fresh:a,freshLaunch:m})}catch(w){if(!c)throw w;f=await G(t,{key:e,kind:r,model:i,session:null,brief:s,freshLaunch:m})}return f.resumed&&await te(t,e,"builder-resumed-to-land",{session:f.sessionId??c.id}),f}l(Pe,"landByBuilder");export{he as BOARD_CLI,ue as builderBrief,we as helperBrief,Pe as landByBuilder,H as landerBrief,ge as launchBuilder,be as launchedAgents,j as pidAlive,pe as plannerBrief,K as rebaseBrief,De as resumeBrief,G as resumeBuilder,Ne as reviveBuilders,je as stopAgents,Ae as stopRuns,fe as visualBrief};
1
+ var X=Object.defineProperty;var l=(t,e)=>X(t,"name",{value:e,configurable:!0});import J from"node:os";import{BRIEF_LINE_LIMIT as Z}from"./hub-lines.mjs";import T from"node:path";import{fileURLToPath as ee}from"node:url";import{launchAgent as W}from"./agents.mjs";import{processStarts as D,ps as M}from"../hub/live.mjs";import{boardAt as O}from"../hub/boards.mjs";import{readHubRules as te}from"../hub/rules.mjs";import{builderRepo as F}from"./worktree.mjs";import{standardWords as L}from"./commit-message.mjs";import{appendStatus as oe,BoardError as re,briefFacts as B,readBoardRules as ne,recordedSession as se,recordSession as E}from"./store.mjs";import{HELPER as ae,plans as ie,VISUAL as he}from"./domain.mjs";const de=ee(new URL("./bin/board.mjs",import.meta.url)),$=l(t=>`node ${de} --site ${t}`,"cli"),Y=l(t=>`git -c core.commentChar=';' rebase ${t}`,"rebase"),le="a draft .md of your own outside the board's data folder (such as in /tmp)",ce=l((t,e,r)=>`\`${t} item notes ${e} --heading "${r}" --file <draft.md>\``,"notesCommand"),I=l((t,e="Rules from the hub and this board:")=>t.length?[e,...t.map(r=>`- ${r}`),""]:[],"ruleLines"),q=l(t=>t.length?["Related cards: read their notes for context; don't build their scope.",...t.map(e=>`- ${e.ref} "${e.title}" (${e.relation}, ${e.lane}): ${e.notes?`notes ${e.notes}`:"no notes"}, thread ${e.thread}`),""]:[],"linkLines"),S=l(t=>`The card's thread, which holds the owner's messages (who: love): ${t}. Read it live.`,"threadLine"),H=l(({route:t,key:e,worktree:r,base:i})=>[`- With no unverified calls, done finishes the card itself: it rebases onto ${i}, reruns the full test suite, fast-forwards ${i} and closes the card (on a board with pull requests it pushes the branch and opens a draft PR instead, titled by \`--title "<type>(<scope>): <what the PR does>"\`, a Conventional subject of at most 72 characters written from the whole diff, else the branch's first commit subject; with Auto-merge off it stops before the fast-forward, and the card waits for the owner's Merge).`,`- On a conflict it undoes its rebase and names the files: run \`${Y(i)}\` in ${r}, resolve each conflict keeping both sides' intent, continue with \`git -c core.commentChar=';' rebase --continue\`, rerun the tests, and run done again.`,"- On failing tests, fix them, commit, and run done again.","- While another card is landing, done waits its turn and then lands; leave it running.","- Once a reviewer has the card's PR link, done refuses without `--updated \"<what changed>\"`, which goes in that link's Slack thread, or `--updated none` for a change only to comments, names, docs or tests.",`- Finishing never goes to the orchestrator. If done refuses for a reason you can't fix, record it with \`${$(t)} builder call ${e} "<why>"\` and run done again: with the call it hands the card back.`],"finishSteps"),j=l(({route:t,key:e})=>`\`${$(t)} builder done ${e} --text "<what you checked>"\``,"finishCommand"),ue=l((t,e)=>[`5. To run a separate part of the work in parallel, ask the board for a helper: \`${t} agent launch ${e} --name <short-name> --task "<the whole task, with the files and what to hand back>"\`, adding --writes when it changes code or runs tests (it gets its own worktree off your branch, and waits for a free implementer slot). Then \`${t} agent wait ${e} --name <short-name>\`, which prints its hand-back; it returns within 10 minutes, so run it again while it says still running, and do the task yourself if it says the helper exited. Merge a writing helper's work with \`${t} agent merge ${e} --name <short-name>\` before you test and finish.`],"helperSteps");function pe({route:t,key:e,ref:r,title:i,notes:n,thread:a,worktree:h,base:u,rules:p=[],links:c=[]}){const d=$(t);return[`You are the headless builder for card ${r} (${e}, "${i}") on the kickflip board /${t}. The board launched you; nobody watches this session, so never wait on a person. Work only in ${h}. Never restart the hub or a board server, and never push.`,"",`1. Run \`${d} builder start ${e} --kind build\`. If it refuses, stop.`,`2. Report progress with \`${d} builder progress ${e} --phase reading|building|testing|checking|landing "<plain, 80 characters or fewer>"\`, at least every 10 minutes. The board adds the phase word; don't start the text with it. The phases:`," - reading: the notes and the code, until the first test is written."," - building: the tests and the code, the ADR and docs, and the commit."," - testing: the full suite run before you finish."," - checking: your own review of the diff before you hand back; the Orchestrator's review of your calls continues on the same 4th bar."," - landing: set by the finish step itself; you never report it.",`3. Decide, record the call (step 4) and carry on: the orchestrator reviews your calls after the build. Ask it only when you are blocked, meaning every way forward would likely be thrown away: the spec contradicts itself or the code, a rule needs the owner's go before code is written, or the answer is a fact only the orchestrator has. Then run \`${d} builder ask ${e} "<question>"\`, do any work the answer can't change, and wait with \`${d} builder asks ${e} --wait\`, which returns within 10 minutes, so run it again while it says still waiting. If no answer comes in 30 minutes, record the question as a call, "Question: <question>", and hand back.`,`4. Record each judgment call the notes leave open with \`${d} builder call ${e} "<call>"\` instead of guessing silently or asking. A problem you find outside your card is a call "Found: <what>" for the orchestrator to file at review; ask about it at once only when it stalls other cards' builds or lands.`,...ue(d,e),"",n?`Spec: the card's notes, ${n}, all sections, where later sections override earlier ones.`:"The card has no notes file: build from its title, and record what you had to decide as calls.",`${S(a)} Read it with the notes: a message of the owner's is an instruction, but where it contradicts the notes, the notes win; that contradiction counts as blocked (step 3), so ask with \`${d} builder ask ${e} "<question>"\` and wait as step 3 says. Read the thread again in checking, before you finish, for anything the owner wrote during the build.`,"",...q(c),...I(p),"Write tests first, and run the full suite once, in the foreground, at the end. Where the repo keeps ADRs, write one named with a timestamp: docs/adr/YYYY-MM-DD-HHMM-<slug>.md.",`Commit with \`git -c core.commentChar=';' commit -F <file>\`: ${L(r)}. Land refuses any other shape.`,"",`To finish, run ${j({route:t,key:e})}.`,"- If you recorded a judgment call, it hands the card back for the orchestrator to verify your calls; stop there: the orchestrator's verification finishes the card.",...H({route:t,key:e,worktree:h,base:u}),"","Never push."].join(`
2
+ `)}l(pe,"builderBrief");function K({route:t,key:e,ref:r,title:i,thread:n,worktree:a,base:h,answers:u=[],resumed:p=!1,why:c}){const d=$(t);return[p?`The board resumes you, the builder of card ${r} (${e}, "${i}") on the kickflip board /${t}, to land your build: ${c??"the orchestrator verified your judgment calls"}, and it waits only to land. Nobody watches this session, so never wait on a person. Work only in ${a}, never restart the hub or a board server, and never push.`:`You are the headless lander for card ${r} (${e}, "${i}") on the kickflip board /${t}. Its build is done and the orchestrator verified its judgment calls; it waits only to land. Nobody watches this session, so never wait on a person. Work only in ${a}, never restart the hub or a board server, and never push.`,"",`1. Run \`${d} builder start ${e} --kind build --label Lander --phase landing --progress "taking up the verified build"\`. If it refuses, stop.`,`2. Report progress with \`${d} builder progress ${e} --phase landing "<plain, 80 characters or fewer>"\`. The board adds the phase word; don't start the text with it.`,...u.length?["3. The owner answered the builder's deferred asks. Where an answer changes the build, change it, with its tests, and commit:",...u.map(o=>`- ${o.ask} "${o.question}": ${o.answer}`)]:[],"",S(n),`Commit with \`git -c core.commentChar=';' commit -F <file>\`: ${L(r)}. Land refuses any other shape, so reword a commit the build left in another.`,"",`To finish, run ${j({route:t,key:e})}.`,...H({route:t,key:e,worktree:a,base:h}),"","Never push."].join(`
3
+ `)}l(K,"landerBrief");function _({route:t,key:e,ref:r,title:i,thread:n,worktree:a,base:h,pr:u,resumed:p=!1}){const c=$(t);return[...p?[`The board resumes you, the builder of card ${r}, for this run: the lines below are your brief for it.`]:[],`You are the headless rebase run for card ${r} (${e}, "${i}") on the kickflip board /${t}. Its PR #${u} conflicts with ${h}; rebase its branch onto ${h} so the PR is clean again. Nobody watches this session, so never wait on a person. Work only in ${a}, never restart the hub or a board server, and never push.`,"",`1. Run \`${c} builder start ${e} --kind build --label Rebase --phase building --progress "Rebase run started \xB7 fetching ${h}"\`. If it refuses, stop.`,`2. Run \`git fetch origin\`, then \`${Y(`origin/${h}`)}\`. Resolve each conflict keeping both sides' intent, \`git add\` it and continue with \`git -c core.commentChar=';' rebase --continue\`. Report each step with \`${c} builder progress ${e} --phase building "<line>"\`, the board adds the phase word, in these words: "Rebasing onto ${h} \xB7 resolving <n> files", then "Rebasing onto ${h} \xB7 suite running".`,"3. Run the full test suite once, in the foreground. Fix what the rebase broke, and commit each fix with `git -c core.commentChar=';' commit -F <file>`. A push with commits of its own is no longer rebase-only, so a merge after an approval won't count it as trivial.",`4. If a conflict or a failing test is past what you can resolve with confidence, run \`git -c core.commentChar=';' rebase --abort\` if a rebase is under way, record it with \`${c} builder call ${e} "Rebase failed in <the files or tests> \xB7 <why>"\`, and run the finish step: with the call it hands the card to the orchestrator.`,"",S(n),"",`To finish, run ${j({route:t,key:e})}, the text saying what you resolved. It reruns the suite and pushes the branch to PR #${u} with --force-with-lease; the PR stays as it is.`,"- If it refuses because someone pushed to the branch since your fetch, fetch and rebase again (step 2), then run done again.","- On failing tests, fix them, commit, and run done again.","","Never push."].join(`
4
+ `)}l(_,"rebaseBrief");function fe({route:t,key:e,ref:r,title:i,notes:n,thread:a,kind:h,repo:u,rules:p=[],links:c=[],text:d,files:o=[],question:s,note:w,choice:f,prototype:b=null}){const m=$(t),g=h==="grill";return[`You are the headless ${g?"grill":"prototype"} planner for card ${r} (${e}, "${i}") on the kickflip board /${t}. The board launched you; nobody watches this session, so never wait on a person: the owner answers on the board, and a later planner or builder picks up from their answers. Read and run in ${u}; write no output code ${g?"there":`in ${u} itself`}, never restart the hub or a board server, and never push.`,"",`1. Run \`${m} builder start ${e} --kind ${h}\`. If it refuses, stop.`,`2. Gather the context yourself: ${n?`the card's notes, ${n}, all sections, where later sections override earlier ones; `:"the card has no notes file yet; "}its thread, ${a}, the repo's docs/adr and CONTEXT.md, and the cards its notes and thread link.`,`3. Report progress with \`${m} builder progress ${e} "<plain, 80 characters or fewer>"\` at least every 10 minutes.`,g?`4. Find every decision the card leaves open: read the code it touches and answer what the code answers yourself. Post each decision left as a question for the owner with \`${m} question add --file <json>\` on topic item:${e}, one per decision, your recommendation first. Once you finish, the orchestrator screens them before the owner sees them, settling the ones the board already answers and passing the owner the rest. Invoke the grilling skill with the Skill tool and run it as one round: its questions go to the board with question add, never into the chat, and you never wait for an answer; after the round, finish. (With no Skill tool, follow this step as written.) When the code shows the card has separable parts, each a build of its own, propose splitting it into a wave of smaller cards as one question ahead of the prototype question: its options "Split as proposed" and "Keep as one card", your recommendation first. Slice it as ~/.claude/skills/to-tickets/SKILL.md step 3, "Draft vertical slices", says (read that step; you can't invoke the skill, and skip its quiz and publish steps). The first card is the thinnest end-to-end path. The question's context lists each proposed card with its title, its scope, the files it touches and the earlier proposed cards it waits on, or none: a card waits on an earlier one only when it builds on that card or shares its seam (the same function, component, CLI command or doc paragraph); sharing only a file waits on nothing. Write the same breakdown in your notes section. On Split the orchestrator files the cards when the card stages; never file them yourself.`+(b?` The card keeps the owner's answer to its prototype question, ${b}, so ask no "Prototype round first?" question: once every question you ask is answered, or as you finish when you ask none, the board moves the card ${b==="yes"?"to prototyping":"to staging"}.`:' End every grill with one more question, "Prototype round first?", whose options are yes and no, with "prototype_gate": true in its `question add --file` entry: once the owner has answered every question the board moves the card to prototyping on yes, or to staging on no, so nothing else moves it. Recommend yes when the card changes the hub\'s or a board\'s UI, no otherwise. Ask it even when it is your only question.'):`4. Invoke the prototype skill with the Skill tool and build the round as take files, one per option: record them with \`${m} prototype add <topic> --card ${e} --take <K>:<label> \u2026\`, write the take files it prints, built from the repo's existing components, helpers and scripts fed mock data (the prototype template loads the board's scripts, so a take reuses the board's components; a hub-page take reuses them by path or copy), each take showing the states it needs inside itself, then post one question whose url opens prototype-<topic>.html with \`${m} question add --file <json>\` on topic item:${e}, never asking in the chat. Build in situ only where one of the board's rules asks for it: then, run \`${m} prototype base\`, which makes it or moves it to main and prints its path, whether its build script is there and the listener a page loads. When the build script is missing, write one there that serves the app and prints "port <n>" (board/build-script.mjs). Add one page to the worktree, at a path no other round uses, built from the repo's real components, helpers and scripts fed mock data, fully interactive; it reads the take from ?variant= and the state from ?state=, and loads the listener so \`KickflipPrototype.on((take, state) => \u2026)\` re-renders it in place when the viewer switches. Record it with \`${m} prototype add <topic> --card ${e} --served <path> --take <K>:<label> \u2026 --state <key>:<label> \u2026\`, one take per option and one state for each state that matters to the question, then post one question whose url opens prototype-<topic>.html with \`${m} question add --file <json>\` on topic item:${e}, never asking in the chat. (With no Skill tool, follow this step as written.)`,...d?[` The owner asked for this ${g?"grill":"prototype"}, writing: "${d}"`]:[],...o.length?[` The owner attached: ${o.map(v=>v.path).join(", ")}.`]:[],...s?[` The owner asked for prototypes of question ${s}${w?`, noting "${w}"`:""}${f?`, leaning to option ${f}`:""}: draw that question's next round, its question naming round_of ${s}.`]:[],`5. Record what you learned in the card's notes, naming each answered question's id: write it in ${le}, then run ${ce(m,e,`${g?"Grill":"Prototype"} (<MM/DD>)`)}, which appends it as a section. The notes file is read-only; never write into it. Anything you leave open becomes a question with question add, never only a line in the notes, so the card can't go ready past it. A question's text is one line of at most ${Z} characters (question add refuses a longer one); put the detail in its context and the options' details, which take markdown.`,...g?[`6. Where the owner asked for prototypes, or a rule here wants a UI prototype first, end the card \`${m} item set ${e} --phase prototyping\` instead and skip the prototype question. Otherwise ${b?"the board":"the prototype question"} is what moves the card on: never set it ready yourself, and never leave a Next that asks the owner to mark it ready.`]:[],"",...q(c),...I(p,"Rules from the hub and this board, written for the orchestrator: where one tells you to push, land, restart the hub or a board server, or do the orchestrator's work, it isn't yours; you never push or restart:"),`To finish, run \`${m} builder done ${e} --text "<what you asked>"\`.`,"","Never push."].join(`
5
+ `)}l(fe,"plannerBrief");function we({route:t,key:e,ref:r,title:i,notes:n,thread:a,repo:h,agent:u,rules:p=[],links:c=[],text:d,files:o=[]}){const s=$(t);return[`You are the headless visual agent for card ${r} (${e}, "${i}") on the kickflip board /${t}. The owner asked, in the card's thread, for a visual: one HTML page that answers in a visual way, such as a diagram, a flow or a comparison. It is not a prototype or a grill: no question, no takes. The board launched you; nobody watches this session, so never wait on a person. Read and run in ${h}; write no code there, never restart the hub or a board server, and never push.`,"",`1. Run \`${s} builder start ${e} --kind visual --agent ${u}\`. If it refuses, stop.`,`2. Gather what the page needs: ${n?`the card's notes, ${n}; `:""}its thread, ${a}, and the code or docs it is about.`,d?` The owner wrote: "${d}"`:" The owner typed nothing: draw what the thread was last discussing.",...o.length?[` The owner attached: ${o.map(w=>w.path).join(", ")}.`]:[],"3. Write one HTML file outside the repo, such as in a temporary folder. Keep its own CSS and script inline; it may load a library such as Mermaid or D3 from a CDN. Make it read well at phone width (390px) and on a desktop, in the dark and the light theme (prefers-color-scheme).",`4. Place it with \`${s} visual add ${e} --file <page.html> --title "<what it shows>"\`, which copies it to the board and links it in the thread.`,"","Write nothing else: no notes, questions, card state, Next or progress lines.","",...q(c),...I(p,"Rules from the hub and this board, written for the orchestrator: where one tells you to push, land, restart the hub or a board server, or do the orchestrator's work, it isn't yours; you never push or restart:"),`To finish, run \`${s} builder done ${e} --agent ${u}\`.`,"","Never push."].join(`
6
+ `)}l(we,"visualBrief");function me({route:t,key:e,ref:r,title:i,notes:n,thread:a,agent:h,task:u,writes:p,cwd:c,rules:d=[],links:o=[]}){const s=$(t);return[`You are the headless helper ${h} on card ${r} (${e}, "${i}") on the kickflip board /${t}. Another agent working on the card asked the board for you to do one task beside it, and waits on your hand-back. Nobody watches this session, so never wait on a person. Never restart the hub or a board server, and never push.`,p?`Work only in ${c}, your own worktree, branched from the card's: commit your work there with \`git -c core.commentChar=';' commit -F <file>\`: ${L(r)}. The card's builder merges your branch, so leave nothing uncommitted.`:`Read and run in ${c}; change no files there and commit nothing.`,"","The task:",u,"",`1. Run \`${s} builder start ${e} --kind helper --agent ${h}\`. If it refuses, stop.`,`2. Report progress with \`${s} builder progress ${e} --agent ${h} --phase reading|building|testing|checking "<plain, 80 characters or fewer>"\` at least every 10 minutes; the board adds your name and the phase word.`,"3. Do only the task. Don't ask the orchestrator or the owner, record no judgment calls and post no questions: put any decision you had to make in your hand-back.",n?` The card's notes, for context: ${n}.`:"",` ${S(a)}`,"",...q(o),...I(d,"Rules from the hub and this board, written for the orchestrator: where one tells you to push, land, restart the hub or a board server, or do the orchestrator's work, it isn't yours; you never push or restart:"),`To finish, run \`${s} builder done ${e} --agent ${h} --text "<your hand-back: what you did or found, ${p?"what you committed, ":""}and any decision you made>"\`.`,"","Never push."].filter((w,f,b)=>w!==""||b[f-1]!=="").join(`
7
+ `)}l(me,"helperBrief");const be=6e4;function ge(t,{starts:e=D}={}){const r=t.filter(n=>n.pid&&n.at).map(n=>n.pid),i=r.length&&e(r)||new Map;return t.filter(n=>{const a=i.get(n.pid);return a!==void 0&&a<=Date.parse(n.at)&&a>=Date.parse(n.at)-be})}l(ge,"launchedAgents");function Ne(t,{starts:e=D,kill:r=l((n,a)=>process.kill(-n,a),"kill"),killAfter:i=5e3}={}){const n=ge(t,{starts:e});for(const{pid:a}of n){try{r(a,"SIGTERM")}catch{continue}setTimeout(()=>{try{r(a,"SIGKILL")}catch{}},i).unref()}return n.length}l(Ne,"stopAgents");async function Pe(t,{grace:e=5e3}={}){const r=["-A","-o","pid=,ppid=,pgid=,args="],i=M(r)??M(r);if(i===null)throw new re("ps gave no answer, so nothing was stopped; run it again");const n=i.split(`
8
+ `).map(o=>/^\s*(\d+)\s+(\d+)\s+(\d+)\s+(.*)$/.exec(o)).filter(Boolean).map(([,o,s,w,f])=>({pid:Number(o),ppid:Number(s),pgid:Number(w),args:f})),a=new Set(n.filter(o=>t.includes(o.pgid)).map(o=>o.pid));for(let o=!0;o;){o=!1;for(const s of n)!a.has(s.pid)&&a.has(s.ppid)&&(a.add(s.pid),o=!0)}const h=n.find(o=>o.pid===process.pid)?.pgid,u=n.filter(o=>a.has(o.pid)&&o.pgid>1&&o.pgid!==h),p=[...new Set(u.map(o=>o.pgid))],c=l(o=>{for(const s of p)try{process.kill(-s,o)}catch{}},"signal");c("SIGTERM");const d=Date.now()+e;for(;u.some(o=>A(o.pid))&&Date.now()<d;)await new Promise(o=>setTimeout(o,50));return u.some(o=>A(o.pid))&&c("SIGKILL"),u.map(({pid:o,args:s})=>({pid:o,args:s}))}l(Pe,"stopRuns");const A=l(t=>{try{return process.kill(t,0),!0}catch(e){return e.code==="EPERM"}},"pidAlive");async function Ce(t,e,{launch:r,handBack:i,alive:n=A,held:a=l(()=>!1,"held"),stopped:h=new Set,paused:u=new Set,limitedUntil:p=l(()=>null,"limitedUntil"),atLimit:c=l(async()=>{},"atLimit")}){const d={};for(const[o,s]of Object.entries(t)){if(!e.has(o))continue;if(h.has(o)){d[o]={...s,handedBack:!0};continue}if(u.has(o)||s.pid!==null&&n(s.pid)||s.handedBack){d[o]=s;continue}const w={key:o,...s.kind?{kind:s.kind}:{},...s.model?{model:s.model}:{}},f=s.pid!==null?p(s):null;if(f){await c(w,f),d[o]={...s,pid:null};continue}if(a(s.kind??"claude")){d[o]=s;continue}if(s.pid!==null&&s.relaunched){await i(w),d[o]={...s,handedBack:!0};continue}const{key:b,...m}=w;d[o]={...m,...await r(w),relaunched:s.pid!==null||!!s.relaunched}}return d}l(Ce,"reviveBuilders");const G=l((t,e)=>T.join(J.homedir(),".claude","kickflip","logs",`${e}-${t}-${new Date().toISOString().replace(/[:.]/g,"-")}.log`),"logFile");async function $e(t,{key:e,kind:r="claude",model:i,agent:n="main",text:a,files:h,question:u,note:p,choice:c,task:d,writes:o,worktree:s},{lander:w=!1}={}){const f=await B(t,e),b=O(t)?.route??T.basename(t),m=[...te(),...await ne(t)].map(Q=>Q.text),{base:g,repo:v}=F(t),k=ie({kind:r}),R=r===ae,N=!k&&!R&&!w&&f.rebasePR!==null,P=r===he,C=k?v:R?s??f.worktree??v:f.worktree,y={...f,route:b,base:g,repo:v,rules:m,kind:r,agent:n,text:a,files:h,question:u,note:p,choice:c,task:d,writes:o,cwd:C,pr:f.rebasePR},V=P?"Visual agent":R?`Helper ${n}`:k?"Planner":w?"Lander":N?"Rebase run":"Builder",z=P?we(y):R?me(y):k?fe(y):w?K(y):N?_(y):pe(y),x=await W({kind:k||R?"claude":r,model:i,cwd:C,site:t,prompt:z,log:G(e.split("/")[1],V.split(" ")[0].toLowerCase())});return await E(t,e,x.sessionId,x.pid,n,T.basename(x.log)),x}l($e,"launchBuilder");const We=l(({ref:t,worktree:e,cleared:r})=>`The board paused your build of card ${t}, and the pause has cleared: ${r}. Carry on where you stopped, in ${e}, following your brief as before. Your builder record is still open, so don't run builder start again.`,"resumeBrief");async function U(t,{key:e,kind:r="claude",model:i,session:n,brief:a,fresh:h=!1,freshLaunch:u={}}){if(r!=="claude"||!n||h)return{...await $e(t,{key:e,kind:r,model:i},u),resumed:!1};const p=await B(t,e),c=await W({kind:r,model:i,cwd:n.worktree??p.worktree,site:t,prompt:a(p),resume:n.id,log:G(e.split("/")[1],"builder")});return await E(t,e,c.sessionId??n.id,c.pid,"main",T.basename(c.log)),{...c,resumed:!0}}l(U,"resumeBuilder");async function De(t,{key:e,kind:r="claude",model:i},{why:n,fresh:a=!1}={}){const h=await se(t,e),u=await B(t,e),p=u.rebasePR!==null,c=h&&(!p||h.worktree===u.worktree)?h:null,d=O(t)?.route??T.basename(t),{base:o}=F(t),s=l(b=>(p?_:K)({...b,route:d,base:o,pr:b.rebasePR,why:n,resumed:!0}),"brief"),w={lander:!p};let f;try{f=await U(t,{key:e,kind:r,model:i,session:c,brief:s,fresh:a,freshLaunch:w})}catch(b){if(!c)throw b;f=await U(t,{key:e,kind:r,model:i,session:null,brief:s,freshLaunch:w})}return f.resumed&&await oe(t,e,"builder-resumed-to-land",{session:f.sessionId??c.id}),f}l(De,"landByBuilder");export{de as BOARD_CLI,pe as builderBrief,me as helperBrief,De as landByBuilder,K as landerBrief,$e as launchBuilder,ge as launchedAgents,A as pidAlive,fe as plannerBrief,_ as rebaseBrief,We as resumeBrief,U as resumeBuilder,Ce as reviveBuilders,Ne as stopAgents,Pe as stopRuns,we as visualBrief};