@lovek4d/kickflip 0.5.3 → 0.6.1

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.
Files changed (91) hide show
  1. package/CONTEXT.md +82 -46
  2. package/SKILL.md +21 -15
  3. package/bin/doctor.mjs +5 -4
  4. package/bin/install.mjs +3 -3
  5. package/bin/kickflip.mjs +12 -12
  6. package/bin/wait-events.mjs +2 -2
  7. package/board/agents.mjs +2 -2
  8. package/board/arch-review.mjs +4 -4
  9. package/board/bin/board.mjs +179 -92
  10. package/board/build-script.mjs +2 -1
  11. package/board/domain.mjs +9 -7
  12. package/board/finish.mjs +4 -4
  13. package/board/headless.mjs +9 -5
  14. package/board/onboarding.mjs +11 -0
  15. package/board/prototype-base.mjs +1 -0
  16. package/board/prototype-page.mjs +1 -0
  17. package/board/public/app-arch.js +1 -1
  18. package/board/public/app-cards.js +40 -47
  19. package/board/public/app-header.js +6 -7
  20. package/board/public/app-lanes.js +19 -45
  21. package/board/public/app-needs.js +36 -31
  22. package/board/public/app-snapshot.js +43 -70
  23. package/board/public/app-threads.js +42 -46
  24. package/board/public/app.html +9 -4
  25. package/board/public/app.js +78 -32
  26. package/board/public/hub-kit.js +62 -2
  27. package/board/public/hub.css +2 -0
  28. package/board/public/new-task.js +8 -6
  29. package/board/public/progress-review.html +46 -0
  30. package/board/public/progress-review.js +158 -0
  31. package/board/public/prototype-kit.js +109 -4
  32. package/board/public/prototype-switcher.js +130 -31
  33. package/board/public/prototype.html +57 -3
  34. package/board/public/router.js +7 -6
  35. package/board/public/shell.js +65 -24
  36. package/board/public/sidebar.css +6 -0
  37. package/board/public/sidebar.js +19 -69
  38. package/board/public/style.css +116 -73
  39. package/board/public/ui-cards.js +78 -57
  40. package/board/public/ui-enums.js +2 -2
  41. package/board/public/ui-header.js +23 -16
  42. package/board/public/ui-hub.js +19 -5
  43. package/board/public/ui-links.js +7 -7
  44. package/board/public/ui-order.js +1 -1
  45. package/board/public/ui-page-header.js +19 -7
  46. package/board/public/ui-patch.js +7 -33
  47. package/board/public/ui-progress-bar.js +28 -0
  48. package/board/public/ui-questions.js +25 -17
  49. package/board/public/ui-sidebar.js +31 -23
  50. package/board/public/ui-snapshot.js +44 -53
  51. package/board/public/ui-threads.js +57 -28
  52. package/board/public/ui.js +94 -18
  53. package/board/public/view-hub-settings.js +12 -58
  54. package/board/public/view-hub.js +5 -2
  55. package/board/public/view-notes.js +27 -7
  56. package/board/public/view-questions.js +90 -68
  57. package/board/public/view-settings.js +133 -15
  58. package/board/render-check.mjs +10 -0
  59. package/board/review.mjs +1 -1
  60. package/board/server.mjs +20 -19
  61. package/board/stop.mjs +1 -0
  62. package/board/store.mjs +29 -18
  63. package/board/sync.mjs +2 -0
  64. package/board/tickets.mjs +3 -3
  65. package/board/transcript.mjs +2 -2
  66. package/board/worktree.mjs +22 -21
  67. package/hooks-plugin/hooks/board-data-gate.mjs +9 -6
  68. package/hooks-plugin/hooks/usage-gate.mjs +20 -3
  69. package/hub/board-repo.mjs +1 -1
  70. package/hub/boards.mjs +4 -4
  71. package/hub/front-door.mjs +2 -2
  72. package/hub/github.mjs +3 -3
  73. package/hub/hub.mjs +11 -11
  74. package/hub/incoming.mjs +2 -2
  75. package/hub/owner-checks.mjs +1 -1
  76. package/hub/pr-report.mjs +2 -2
  77. package/hub/review-send.mjs +1 -1
  78. package/hub/sessions.mjs +2 -2
  79. package/hub/share.mjs +1 -1
  80. package/hub/slack.mjs +2 -2
  81. package/hub/try.mjs +6 -6
  82. package/hub/upgrade.mjs +1 -1
  83. package/hub/usage.mjs +3 -3
  84. package/hub/views.mjs +1 -1
  85. package/package.json +1 -1
  86. package/shared/card-prs.mjs +1 -1
  87. package/shared/machine-gate.mjs +2 -0
  88. package/shared/prototype-frame.js +1 -0
  89. package/shared/tailscale.mjs +1 -1
  90. package/shared/usage-gate.mjs +1 -1
  91. package/board/public/ui-phase-bars.js +0 -17
@@ -1 +1,2 @@
1
- var i=Object.defineProperty;var e=(r,t)=>i(r,"name",{value:t,configurable:!0});import u from"node:fs";import s from"node:path";function p(r){if(typeof r!="string"||!s.isAbsolute(r))return"Build script must be an absolute path.";let t;try{t=u.lstatSync(r)}catch{return"Build script must be an existing regular file."}return t.isFile()?t.uid!==process.getuid()?"Build script must be owned by the current user.":t.mode&18?"Build script must not be writable by group or others.":t.mode&64?null:"Build script must be executable.":"Build script must be an existing regular file."}e(p,"buildScriptError");export{p as buildScriptError};
1
+ var o=Object.defineProperty;var i=(t,r)=>o(t,"name",{value:r,configurable:!0});import n from"node:fs";import e from"node:path";import{execFile as l}from"node:child_process";import{promisify as c}from"node:util";const p=c(l);function x(t){if(typeof t!="string"||!e.isAbsolute(t))return"Build script must be an absolute path.";let r;try{r=n.lstatSync(t)}catch{return`Build script ${e.basename(t)} must be an existing regular file.`}return r.isFile()?r.uid!==process.getuid()?"Build script must be owned by the current user.":r.mode&18?"Build script must not be writable by group or others.":r.mode&64?null:"Build script must be executable.":`Build script ${e.basename(t)} must be an existing regular file.`}i(x,"buildScriptError");const a=i(t=>typeof t=="string"&&/^[A-Za-z0-9][\w.-]{0,63}$/.test(t),"validBuildTarget"),y=i(t=>t?`.kickflip/build-${t}`:".kickflip/build","buildScriptOf");async function B(t,r){if(!t)return[];let u;try{u=(await p("git",["-C",t,"ls-tree",`${r}:.kickflip`],{encoding:"utf8",timeout:3e3})).stdout}catch{return[]}return u.split(`
2
+ `).map(s=>/^100755 blob \S+\tbuild-(.+)$/.exec(s)?.[1]).filter(a).sort()}i(B,"listBuildTargets");export{x as buildScriptError,y as buildScriptOf,B as listBuildTargets,a as validBuildTarget};
package/board/domain.mjs CHANGED
@@ -1,8 +1,10 @@
1
- var Ot=Object.defineProperty;var i=(e,t)=>Ot(e,"name",{value:t,configurable:!0});import{routeRecord as $}from"../hub/routes.mjs";import xt from"node:fs";import{ticketBadge as Ze,ticketIn as $t}from"./tickets.mjs";import{reviewLinks as At,reviewTime as Et,reviewersOf as Bt}from"./review.mjs";import{remoteFromInput as Rt}from"../hub/repos.mjs";import{reviewsOf as _t,reviewNeeds as It,reviewActions as qt}from"./auto-review.mjs";import{cardPRs as Mt,hasPR as je,leastReady as Dt,prKeyOf as Ct,prURL as Nt}from"../shared/card-prs.mjs";import et from"node:vm";import{checkWords as Tt,parseCheck as Lt}from"../shared/owner-check.mjs";const Ue=et.createContext({});for(const e of["ui-enums.js","ui-order.js"])et.runInContext(xt.readFileSync(new URL(`./public/${e}`,import.meta.url),"utf8"),Ue);const{BUTTON:Y,ACTION_KIND:M,BUILDER_KIND:De,PR_STATE:re}=Ue.BoardUI,{laneOrder:Pt}=Ue.BoardUI,jt=["item-message","mark-ready","grill-more","prototype-request","reask-request"],fs=["waiting","building","fixing","checking","held","merged","done","dropped"],Ut=10*6e4,Ft=5*6e4,tt="build-refused",be=Object.freeze({ask:"builder-ask",answer:"builder-answer"}),Wt=864e5,z=i(e=>e.lane==="done"||e.lane==="asks","closedLane"),Gt=i(e=>`wave:${e}`,"waveFold"),nt=7*Wt,st=i((e,t)=>({id:e,url:t?.workspace?`https://linear.app/${t.workspace}/issue/${e}`:null}),"linearRef"),Kt=i((e,t)=>String(e).replace(/^S(\d+)$/,`${t||"INT"}-$1`),"internalRef"),Fe=i((e,t,n)=>$t(n,t.ticket)?t.ticket:e.internal===!0?Kt(t.id,n?.prefix):t.id,"refOf"),Qt=i((e,t,n,o)=>Ze(e||(t?{source:"internal",prefix:"INT"}:null),n,o)||(t?{id:String(t),url:null,source:null}:null),"ticketOf");function Vt(e,t,n,o,r,a,u){const p=(e.status||"").toLowerCase();return p==="merged"||p==="done"||p==="dropped"||!r&&(t?.state==="MERGED"||t?.state==="CLOSED")?"done":(n||p==="checking")&&!u?"progress":o?"review":t?.state==="OPEN"?t.checks?.state==="fail"&&(!t.isDraft||a)?"progress":"review":t?"progress":"todo"}i(Vt,"laneOf");function Ht(e,t){return e?.state==="MERGED"||t.status==="merged"||t.merged_at?re.merged:e?.state==="CLOSED"?re.closed:e?.state==="OPEN"?e.isDraft?re.draft:re.open:null}i(Ht,"prStateOf");const We=i(e=>{const t=(e.status||"").toLowerCase();return t==="dropped"||e.pr?.state==="CLOSED"&&t!=="merged"&&t!=="done"},"droppedCard");function Xt(e){if(!e.some(o=>o.kind==="work")||e.some(o=>o.lane!=="done"))return null;const t=e.filter(o=>o.lane==="done"),n=t.filter(We).length;return{merged:t.length-n,dropped:n}}i(Xt,"finishedOf");function Yt(e,t,n){return Object.fromEntries(e.map(o=>{const r=$(t?.reviews,o.github),a=r==="APPROVED"?"approved":r==="CHANGES_REQUESTED"?"changes":Object.hasOwn(n,o.name)?"sent":"unsent";return[o.name,{state:a,since:a==="sent"?$(n,o.name):null,github:o.github||null}]}))}i(Yt,"reviewOf");function zt(e,t,n,o,r,a,{held:u,needsApproval:p}){return n?.kind===De.install?"builder":o==="checking"?"checking":n?"builder":u&&e==="review"?"merge":r&&e==="review"?"owner":e==="review"&&t?.state==="OPEN"&&t.isDraft?a?"ci":"ready":e==="review"||e==="stale"?ot(t,p)?"merge":"reviewers":null}i(zt,"waitsOnOf");const ot=i((e,t)=>e?.reviewDecision==="APPROVED"||!t&&!["REVIEW_REQUIRED","CHANGES_REQUESTED"].includes(e?.reviewDecision),"reviewed"),Ce=/(^|\/)prototype-[\w-]+\.html/,Jt={reviewers:"Waiting for PR reviewers",merge:"Approved, merges once CI and the merge state allow",ci:"Marked ready for review once CI passes"},Ne={waiting:"Approved, Merge shows once CI and the merge state allow",ready:"Approved and green: tap Merge",merging:"Merging"},Ge={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"},Zt=i(e=>`Verified: tap Merge to land it on ${e}`,"heldNext"),en="Fix the failing CI",rt="Tap Done once it is settled",tn=["status","agent","ask-link",be.answer],at=i(e=>(e.who==="claude"||e.via==="github")&&!tn.includes(e.kind),"countsUnread"),nn=/^(?:Not merged yet: |Lander launched headless )/;function sn({slug:e,wave:t,it:n,order:o,prs:r,repo:a,remote:u,base:p,builder:f,reachedPhase:g,agents:c,worktree:l,eta:w,thread:b,events:D,working:q,said:L,askedAt:R,topicItems:I,boardReviewers:G,now:K,bumpedAt:d,holdAsk:x,closedAt:y,mergeAt:A,autoMerge:le,skipDraft:ee,tickets:P}){const te=r.map(k=>({repo:k.repo,number:k.number,url:Nt(k),...k.gh||{},status:Ht(k.gh,n)})),Q=Dt(r.map(k=>k.gh)),C=r[Q]?.gh||null,V=te[Q]?.status??null,W=!!y&&String(y)>String(n.status_at||"");W&&n.status!=="merged"&&(n={...n,status:"done"});const $e=[W&&y,n.status_at,n.merged_at,...r.map(k=>k.gh?.mergedAt)].filter(Boolean).map(String).sort().pop()||null,j=String($e||""),N=["done","merged"].includes(n.status)||V===re.merged&&n.status!=="dropped"?[...L.filter(k=>k.kind==="item-message").map(k=>k.ts),...R].map(String).filter(k=>k>j).sort().pop():void 0,me=n.owner_step&&!W&&n.status!=="dropped"?String(n.owner_step):null,ke=["done","merged"].includes(n.status)||V===re.merged;N&&(n={...n,status:void 0,next:void 0});const Ae=!!N&&L.some(k=>String(k.ts)>j&&(k.state==="waiting"||k.state==="working")),ie=`${e}/${n.id}`,we=Bt(t,G),Ee=Object.fromEntries(Object.entries(At(t,n,ie,I)).map(([k,F])=>[k,Et(F.ts)])),U=Object.values(Ee).filter(Boolean).sort()[0]||null,ne=[...b.map(k=>k.ts),...D.map(k=>k.ts)].sort().pop()||null,Be=[...b.filter(k=>at({...k,who:k.who||"claude"})).map(k=>k.ts),...D.map(k=>k.reply?.at)].filter(Boolean).sort(),X=!je(n)&&n.pushed?.branch?{branch:n.pushed.branch,at:n.pushed.at||null,host:u?.host||null}:null,H=!je(n)&&n.merge_ready?.branch?{branch:n.merge_ready.branch,at:n.merge_ready.at||null,base:p}:null,de=!!n.rebase_run&&C?.state==="OPEN",ce=(n.rebased||[]).at(-1);let E=Vt(n,C,c.some(k=>k.started&&!k.done&&J(k)),X||H,!!N,ee,de);N&&E==="todo"&&(E="progress"),E==="review"&&U&&K-Date.parse(U)>nt&&(E="stale");const se=!!me&&ke&&E==="done";se&&(E="review");let T=zt(E,C,f,(n.status||"").toLowerCase(),X,ee,{held:H,needsApproval:we.length>0});const Re=T==="builder"&&C?.state==="OPEN"&&!C.isDraft,he=E==="progress"&&!T&&C?.state==="OPEN"&&(!C.isDraft||ee),ue=se||!!N&&E==="progress"&&!T&&!he&&!Ae;ue&&(T="owner");const _e=x&&String(x.ts)>String(n.held_at||""),oe=E==="todo"&&(_e?!!x.data.hold:n.status==="held"||!!n.held),Te=oe&&(_e?x.data.until:n.pick_up_at)||null,pe=E==="todo"||E==="progress",ye=c.filter(J).map(k=>String(k.started||"")).filter(Boolean).sort()[0]||"",Ie=d&&!(ye&&String(d)<ye),qe=b.filter(k=>(k.who||"claude")==="claude"&&k.kind!=="status"&&!nn.test(k.text||"")).map(k=>String(k.ts)).sort().pop()||"",fe=[A,H&&n.merge_ready.tapped].filter(Boolean).map(String).sort().pop(),Se=T==="merge"&&!!fe&&fe>qe,s=b.filter(k=>k.kind==="status"&&String(k.ts)>String(fe)).sort((k,F)=>String(k.ts).localeCompare(String(F.ts))).at(-1),m=s?.text.startsWith("Waiting for ")?`${Ne.merging} \xB7 ${s.text[0].toLowerCase()}${s.text.slice(1)}`:Ne.merging,h=b.filter(k=>k.kind!=="status").sort((k,F)=>String(k.ts).localeCompare(String(F.ts))).at(-1),O=E==="todo"&&h?.kind===tt?h.text:null,S=N||c.filter(J).map(k=>k.started).filter(Boolean).map(String).sort().pop()||n.implement_at||["building","fixing","checking"].includes(String(n.status||"").toLowerCase())&&n.status_at||null,_=C?.reviewDecision==="APPROVED",B=X&&T==="owner"?`merge ${X.branch} into ${p}`:H&&T==="merge"?Se?m:Zt(p):T==="merge"&&!le?Se?m:(_?Ne:Ge).waiting:T==="merge"&&!_?Ge.auto:Jt[T],Me=V===re.draft?`Review draft PR #${te[Q].number}`:null,ve=!de&&ce?.to&&ce.to===C?.headRefOid?`Rebased onto ${ce.base||p}, pushed${C.mergeable==="MERGEABLE"?" \xB7 PR is clean again":""}`:null,Le=de&&T==="checking"?c.flatMap(k=>k.calls).sort((k,F)=>String(k.at).localeCompare(String(F.at))).at(-1)?.text??null:null;return{key:ie,kind:"work",order:o,wave:e,waveTitle:t.title||e,id:n.id,ref:Fe(t,n,P),title:n.title,status:n.status||null,created:n.created||null,reviewSince:n.review_since||U||n.merge_ready?.at||n.pushed?.at||n.created||null,progressSince:S,closedAt:E==="done"?$e:null,internal:t.internal===!0,repo:t.internal===!0&&!t.repo?null:a,lane:E,waitsOn:T,builder:T==="checking"?null:f,reachedPhase:g,agents:c,worktree:l??null,eta:w,working:q,reopened:!!N,awaitsDone:ue,ownerStep:ue?me:null,ownerCheck:ue&&me&&n.owner_check?{words:Tt(Lt(n.owner_check.check)),broken:n.owner_check.broken||null}:null,implementAt:E!=="done"&&n.implement_at||null,deps:n.deps||[],held:oe,heldUntil:Te,risky:!!n.risky,bumpable:pe,bumpedAt:pe&&Ie?d:null,holdable:E!=="done",hasNotes:!!(n.plan||String(n.notes||"").trim()),finishable:E!=="done",merging:Se,refusal:O,manualSteps:n.manual_steps||[],fromAsk:n.from_ask||null,unfiled:!!n.unfiled,next:Re||E==="done"||T==="checking"?null:he?en:ve||B||n.next||Me||null,rebaseFailed:Le,branch:n.branch||C?.headRefName||X?.branch||null,pushed:E==="done"||se?null:X,mergeReady:E==="review"?H:null,ticket:P?.source==="linear"&&!n.ticket&&n.linear?.length?null:Qt(P,n.ticket,n.ticket||(t.internal?Fe(t,n,P):n.linear?.[0]),{repo:a,key:ie}),ticketSource:P?.source||null,linear:(n.linear||[]).map(k=>P?.source==="linear"&&Ze(P,k,{key:ie,repo:a})||st(k,P)),pr:te[Q]||null,prs:te,reviewers:we.map(k=>k.name),review:Yt(we,C,Ee),inReviewSince:U,threadCount:b.length+D.length,lastTs:ne,othersAt:Be,grilling:ut("grill",D,c,R),prototyping:ut("prototype",D,c,R),state:n.state||null,updatedAt:C?.mergedAt||C?.updatedAt||n.merged_at||f?.at||ne||null,ask:null,fold:null,action:null,install:E==="done"?null:rn(n.install,C),waitFacts:on(n,{agents:c,thread:b,events:D,refusedAt:O?h.ts:null})}}i(sn,"workItem");function on(e,{agents:t,thread:n,events:o,refusedAt:r}){const a=new Set(n.filter(g=>g.kind===be.answer).map(g=>g.ask)),u=n.filter(g=>g.kind===be.ask&&!a.has(g.ask)).sort((g,c)=>String(g.ts).localeCompare(String(c.ts)))[0],p=i(g=>o.filter(c=>Qe(c,g)).pop()?.ts||null,"requestAt"),f=n.filter(g=>(g.who||"claude")==="claude"&&!["status","agent",tt].includes(g.kind)).map(g=>g.ts);return{statusAt:e.status_at||null,next:e.next||null,ask:u?{at:u.ts,text:u.text}:null,grillAt:p("grill"),prototypeAt:p("prototype"),refusedAt:r,unverified:t.some(g=>g.calls.some(c=>!g.verified||String(c.at)>String(g.verified.at))),writes:[...f,...t.flatMap(g=>[g.verified?.at,g.started])].filter(Boolean).map(String).sort()}}i(on,"waitFactsOf");function rn(e,t){if(!e?.url)return null;const n=e.sha?String(e.sha).toLowerCase():null,o=t?.headRefOid?String(t.headRefOid).toLowerCase():null;return{url:e.url,label:e.label||null,builtAt:e.built_at||null,sha:n,older:!!(n&&o&&!o.startsWith(n))}}i(rn,"installOf");function an(e,{needsApproval:t=!0}={}){if(e?.state!=="OPEN")return[`PR is ${String(e?.state||"unknown").toLowerCase()}`];const{state:n,pending:o,failing:r}=e.checks||{};return[e.isDraft&&"it is a draft",!ot(e,t)&&`review: ${String(e.reviewDecision||"none").toLowerCase().replace(/_/g," ")}`,n==="fail"&&`failing: ${r?.length?r.join(", "):"a check"}`,n==="pending"&&`pending: ${o?Z(o,"check"):"checks"}`,e.mergeStateStatus!=="CLEAN"&&`merge state: ${String(e.mergeStateStatus||"unknown").toLowerCase()}`].filter(Boolean)}i(an,"mergeBlockers");const ln=i((e,t)=>!an(e,{needsApproval:t}).length,"mergeable");function dn(e,t,n){if(z(e))return null;const o=`#item=${encodeURIComponent(e.key)}`;if(lt(e)){const r=t.get(e.questions.first);return Ce.test(r?.url||"")?{kind:M.pick,url:`questions.html#${r.id}`,label:"Prototypes ready: pick a take"}:{kind:M.questions,url:`questions.html#${e.questions.first}`,label:`Answer ${Z(e.questions.open,"question")}`}}return e.waitsOn==="ready"?{kind:M.ready,url:e.pr.url,label:`Review draft PR #${e.pr.number}`}:e.kind==="ask"&&e.waitsOn==="owner"?{kind:M.done,url:o,label:e.next||rt}:e.waitsOn==="merge"&&e.manualSteps.length&&!e.mergeReady?{kind:M.steps,url:o,label:"Run the manual steps, then merge"}:e.waitsOn==="merge"&&(!n||e.mergeReady)&&!e.merging&&e.prs.every(r=>["MERGED","CLOSED"].includes(r.state)||ln(r,e.reviewers.length>0))?{kind:M.merge,url:o,label:"Merge"}:null}i(dn,"actionOf");const lt=i(e=>!!(e.questions&&e.questions.state!=="resolved"&&e.questions.open>0),"asking"),Ke=new Set([M.pick,M.questions]);function it(e){return z(e)?null:lt(e)?Y.openQuestions:e.action?.kind===M.done?Y.markDone:null}i(it,"actionButtonOf");const cn=i(e=>e.kind==="work"&&e.lane==="todo"&&!e.action&&!e.unpicked,"buildableOf"),un=i((e,t)=>/^item:/.test(e.topic||"")&&Ce.test(e.url||"")&&!(e.options||[]).some(n=>n.id===t),"picksNoTake");function pn(e,t){const n=e.filter(a=>a.topic===`item:${t}`),r=[...n.filter(a=>Ce.test(a.url||"")).flatMap(a=>a.answers.map(u=>({q:a,a:u,again:un(a,u.choice)}))),...n.filter(a=>a.request).map(a=>({q:a,a:a.request,again:!0}))].sort((a,u)=>String(a.a.ts).localeCompare(String(u.a.ts))).at(-1);return r?.again?{id:r.q.id,note:r.a.note.replace(/\s+/g," ").trim()}:null}i(pn,"noTakePicked");const fn="Prototype again",gn=Object.freeze({[M.pick]:Y.openQuestions,[M.questions]:Y.openQuestions,[M.ready]:Y.github,[M.steps]:Y.github,[M.merge]:Y.merge,[M.done]:Y.markDone});function mn(e,t,n){if(e.action=dn(e,t,n),e.action?.kind===M.questions&&e.questions.fromAsks){Object.assign(e,{action:null,waitsOn:"owner",next:e.action.label,actionButton:it(e),resolvedBy:null});return}e.awaitsDone&&=!e.action,e.awaitsDone||Object.assign(e,{ownerStep:null,ownerCheck:null}),e.actionButton=it(e),e.resolvedBy=gn[e.action?.kind]||null,e.action?.kind===M.merge&&!e.mergeReady&&(e.next=(e.pr?.reviewDecision==="APPROVED"?Ne:Ge).ready),e.awaitsDone&&Object.assign(e,{lane:"review",next:e.ownerStep||rt,bumpable:!1,bumpedAt:null});const o=e.lane==="todo"||e.waitsOn==="ready"||e.lane==="progress"&&e.waitsOn==="owner";if(!e.action||!o)return;const r=e.lane==="todo"&&Ke.has(e.action.kind)?"todo":"review";Object.assign(e,{lane:r,waitsOn:e.waitsOn==="ready"?"ready":"owner",next:e.action.label}),r==="review"&&Object.assign(e,{bumpable:!1,bumpedAt:null})}i(mn,"placeOwnerWait");const dt=i(e=>e.implementAt||e.agents.some(J)||["building","fixing"].includes(String(e.status||"").toLowerCase()),"started"),ct="none set yet";function gs(e,t){const n=String(e.status||"").toLowerCase();if(e.next||je(e)||e.pushed||e.held||e.implement_at||["held","checking","done","merged","dropped"].includes(n))return!1;const o=t.filter(r=>r?.started);return!o.some(r=>!r.done)&&dt({status:n,agents:o})}i(gs,"owesNext");function kn(e,t=new Date){const n=new Date(e),o=n.toLocaleTimeString("en-GB",{hour:"2-digit",minute:"2-digit"});return n.toDateString()===t.toDateString()?o:`${n.getMonth()+1}/${n.getDate()} ${o}`}i(kn,"askedLabel");function wn(e,t,n,o,r,a,u){const p=t.find(y=>y.kind==="ask"&&y.eventId===e.id),f=p.files,g=(p.text||"").trim().split(`
2
- `)[0]||f.map(y=>y.name).join(", ")||"Ask",c=p.state==="replied"||p.state==="answered",l=r?.state==="progress"&&!(String(a||"")>String(r.at||"")),w=!l&&(!!r||!!a),b=c&&!w&&!l&&u.open>0,D=c&&!w&&!l&&!b&&u.answered>0,q=w||c&&!l&&!b&&!D,L=c&&!o&&!r?.moved&&[...t.filter(y=>y.who==="claude"&&y.kind!=="ask-link"&&y.kind!=="status").map(y=>y.ts),...t.map(y=>y.reply?.at)].filter(Boolean).sort().pop()||null,R=q||l||b||D,I=t.some(y=>y.who==="love"&&y.kind!=="ask"&&(y.state==="waiting"||y.state==="working")),G=R?"answered":p.state,K=R?null:n||null,d=[...t.filter(at).map(y=>y.ts),...t.map(y=>y.reply?.at)].filter(Boolean).sort(),x=[...t.map(y=>y.ts),...d,...l?[r.at]:[]].filter(Boolean).sort().pop();return{key:`ask:${e.id}`,kind:"ask",order:0,wave:null,waveTitle:null,id:e.id,ref:R?kn(e.ts):"New",isNew:!R,title:g,status:null,internal:!1,repo:null,lane:l?"progress":q?"asks":"todo",waitsOn:l&&!I?"owner":null,builder:null,agents:[],eta:null,working:t.some(y=>y.state==="working"),deps:[],held:!1,risky:!1,bumpable:!R,bumpedAt:K,manualSteps:[],fromAsk:null,from:null,next:l&&r.next||null,hasNotes:!1,branch:null,finishable:R&&!q,linear:[],pr:null,prs:[],reviewers:[],review:{},inReviewSince:null,reviewSince:null,progressSince:l&&r.at||null,closedAt:null,threadCount:t.length,lastTs:x,othersAt:R?d:[],grilling:!1,prototyping:!1,created:e.ts,updatedAt:R?x:e.ts,ask:{eventId:e.id,state:G,askedAt:e.ts,bumpedAt:K,edited:!!p.edited,canEdit:!R,text:p.text,files:f,answerAt:L,from:p.from||null},fold:null,action:null}}i(wn,"askItem");const hn=new Set(["grill","prototype"]),ae=i(e=>hn.has(e.kind),"plans"),J=i(e=>!ae(e),"builds"),yn={grill:"grilling",prototype:"prototyping"},Sn={grill:"grill-more",prototype:"prototype-request"},Qe=i((e,t)=>e.kind===Sn[t]&&!e.data?.question,"isRequest");function ut(e,t,n,o){if(n.some(a=>a.kind===e&&a.started&&!a.done))return!0;const r=t.filter(a=>Qe(a,e)).pop();return!!(r&&!r.reply&&!o.some(a=>String(a)>String(r.ts))&&!n.some(a=>a.kind===e&&a.done&&String(a.started)>=String(r.ts)))}i(ut,"planningOf");const ms=30*6e4;function ks(e,t){const n=[];for(const o of e.items){if(z(o)||(o.agents||[]).some(a=>a.kind==="prototype"&&a.started&&!a.done))continue;const r=o.prototyping&&t.filter(a=>a.data?.key===o.key&&Qe(a,"prototype")).pop();r&&n.push({key:o.key,request:r.id,since:r.ts});for(const a of e.owner.filter(u=>u.topic===`item:${o.key}`&&u.state==="requested"))n.push({key:o.key,request:a.request.id,question:a.id,since:a.request.ts})}return n}i(ks,"prototypeWaits");function Ve(e={}){return Object.entries(e).filter(([,t])=>t&&typeof t=="object").map(([t,n])=>({name:t,kind:pt(n.kind)||null,model:n.model||(n.kind==="opus"||n.kind==="sonnet"?n.kind:null),label:n.label||null,started:n.started||null,eta:n.done?null:n.eta||null,done:n.done||null,calls:Array.isArray(n.calls)?n.calls:[],verified:n.verified||null})).sort((t,n)=>String(t.started||"").localeCompare(String(n.started||""))||t.name.localeCompare(n.name))}i(Ve,"agentsOf");function He(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}i(He,"worktreeOf");function vn(e,t=[]){const n=e.filter(J).map(o=>String(o.started||"")).filter(Boolean).sort().pop();return n===void 0?null:t.filter(o=>o.kind==="status"&&o.phase&&!o.planner&&String(o.ts)>=n).sort((o,r)=>String(o.ts).localeCompare(String(r.ts))).pop()?.phase||null}i(vn,"reachedPhaseOf");function bn(e,t=[],n,o=null,r=null,a=!1){const u=e.filter(I=>I.started&&!I.done),p=u.every(ae),f=p?u:u.filter(J),g=f.map(I=>String(I.started||"")).sort()[0];if(g===void 0)return null;const c=t.filter(I=>I.kind==="status"&&String(I.ts)>=g&&(p||!I.planner)).sort((I,G)=>String(I.ts).localeCompare(String(G.ts))).pop(),l=f.some(I=>I.kind===De.install)?De.install:pt(f.at(-1).kind),w=c?.ts||g,b=o!==null&&o>Date.parse(w)?new Date(o).toISOString():w,D=c?c.phase||c.planner?c.text.replace(": "," \xB7 "):c.text||null:p?yn[l]:null,q=n-Date.parse(b),L=p?null:r,R=L===null?q>=Ut:!L;return{progress:D,phase:c?.phase||null,at:w,kind:l,planner:p,silentSince:b,stalled:R,alive:L,quiet:L===!0&&!a&&q>=Ft}}i(bn,"builderOf");const Xe={opus:"Claude Opus",sonnet:"Claude Sonnet",codex:"Codex"},On=i(({model:e,kind:t})=>Xe[e]||Xe[t]||(t==="claude"?Xe.opus:null),"modelName"),pt=i(e=>e==="opus"||e==="sonnet"?"claude":e,"providerOf");function Ye(e){const t=On(e),{kind:n}=e,o=e.label?.replace(/\bbuilder\b/,"implementer").replace(/\bBuilder\b/,"Implementer"),r=i(u=>u[0].toLowerCase()+u.slice(1),"lower");if(t&&ae(e))return`${t} ${n}`;if(t)return`${t} ${r(o?.replace(/^(?:claude\s+)?(?:opus|sonnet|codex)\b\s*/i,"")||"implementer")}`;const a=n?n[0].toUpperCase()+n.slice(1):"";return a?o?o.toLowerCase().includes(n.toLowerCase())?o:`${a} ${r(o)}`:a:o||"Implementer"}i(Ye,"agentName");const ft=i((e,t)=>!!e.resolved&&(!e.resolved_at||String(e.resolved_at)>=String(t)),"resolvedSince");function xn(e,t,n=[],o=[]){const r=t.filter(l=>l.data?.id===e.id),a=r[r.length-1]||null,u=!!(e.resolved&&e.resolved_at&&a&&String(a.ts)>e.resolved_at),p=e.resolved&&!u,f=n.filter(l=>l.data?.question===e.id&&String(l.ts)>String(a?.ts||"")).at(-1),g=p?o.filter(l=>l.data?.question===e.id&&String(l.ts)>String(e.resolved_at||"")).at(-1):null,c=p?"resolved":f?"requested":a?a.reply?"replied":"answered":"open";return{...e,state:c,request:f?{id:f.id,ts:f.ts,note:f.data.note||"",choice:f.data.choice||null}:null,reask:g?{id:g.id,ts:g.ts}:null,answers:r.map(l=>({ts:l.ts,choice:l.data.choice||null,note:l.data.note||"",files:l.data.files||[],reply:l.reply,acted:ft(e,l.ts)}))}}i(xn,"ownerQuestion");const ge=i(e=>e.round??(Ce.test(e.url||"")?1:0),"roundOf");function $n(e,t){const n=i((o,r)=>o.confirm_of||(o.options||[]).some(a=>a.id===r.choice),"settles");return e.filter(o=>ge(o)===t&&o.answers.length).map(o=>[o,o.answers.at(-1)]).filter(([o,r])=>n(o,r)).map(([,o])=>o).sort((o,r)=>String(o.ts).localeCompare(String(r.ts))).at(-1)}i($n,"roundSettledBy");function An(e){const t=e.find(r=>r.request&&!e.some(a=>ge(a)>ge(r)));if(t)return{n:ge(t)+1,state:"making"};const n=Math.max(0,...e.map(ge));if(!n)return null;const o=$n(e,n);return o?{n,state:"closed",take:o.choice}:e.some(r=>ge(r)===n&&r.state!=="resolved")?{n,state:"back"}:null}i(An,"roundState");const Oe=i((e,t,n)=>{const o=e.get(t);o?o.push(n):e.set(t,[n])},"add"),xe=i((e,t)=>{const n=new Map;for(const o of e)Oe(n,t(o),o);return n},"groupBy");function En(e,t,n=new Set){const o=new Set(e.map(u=>u.id)),r=[...e];t.some(u=>!o.has(u.topic))&&r.push({id:"",title:"Other"});const a=xe(t,u=>o.has(u.topic)?u.topic:"");return r.map(u=>{const p=a.get(u.id)||[],f=i(l=>p.filter(w=>w.state===l).length,"count"),g=p.every(l=>l.state==="resolved")||n.has(u.id)&&!f("open"),c=p.length&&g?"resolved":"open";return{...u,state:c,questions:p.map(l=>l.id),open:f("open"),answered:f("answered"),replied:f("replied"),resolved:f("resolved"),round:An(p)}}).filter(u=>u.questions.length)}i(En,"ownerTopics");const gt={"mark-ready":"Mark ready","grill-more":"grill requested","prototype-request":"prototype requested","reask-request":"re-ask requested"},Bn="answers submitted",Rn="quick build: no grill",mt={reply:"Reply",build:"Implement"},kt=i(e=>mt[e.data.intent],"intentLabel"),wt=i(e=>e.kind==="item-message"&&!String(e.data.text||"").trim()&&!e.data.files?.length,"bareMessage"),_n=i((e,t)=>{if(wt(e)&&e.data.intent==="build")return kt(e);if(e.kind!=="prototype-request"||!t.has(e.data.question))return e.data.text||(e.data.files?.length?"":$(gt,e.kind))||"";const n=t.get(e.data.question),o=(n.options||[]).find(r=>r.id===e.data.choice);return[n.question,o&&`${o.id}. ${o.label}`,e.data.note].filter(Boolean).join(`
3
- \u2192 `)},"actionText"),In=i((e,t)=>e.kind==="item-message"?wt(e)&&e.data.intent==="build"?{request:!0}:mt[e.data.intent]?{status:kt(e)}:{}:e.kind!=="grill-more"&&e.kind!=="prototype-request"?e.kind==="reask-request"?{request:!0}:{}:(e.data.question?t.has(e.data.question):String(e.data.text||"").trim()||e.data.files?.length)?{status:gt[e.kind]}:{request:!0},"requestOf"),ze=i(e=>[...e.filter(t=>t.who==="claude"&&!["status","agent",be.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 ht(e,t={}){const n=new Map,o=new Map;for(const c of t.items||[])Oe(n,c.topic,c),o.set(c.id,c.topic);const r=new Map,a=new Map,u=new Map,p=new Map,f=new Map,g=new Map;e.forEach((c,l)=>{g.set(c,l),c.data?.key&&jt.includes(c.kind)&&Oe(r,c.data.key,c),c.kind==="owner-answer"&&o.has(c.data?.id)&&Oe(a,o.get(c.data.id),c),c.kind==="ask"&&u.set(c.id,c)});for(const c of e.filter(l=>l.kind==="ask-edited").sort((l,w)=>String(l.ts).localeCompare(String(w.ts)))){p.set(c.data?.id,c.data?.text);for(const l of c.data?.files||[])Oe(f,c.data?.id,l)}return{byKey:r,answers:a,asks:u,edits:p,editFiles:f,questions:n,order:g}}i(ht,"threadIndex");const Je=i((e,t)=>{const n=t.filter(o=>o?.length);return n.length>1?n.flat().sort((o,r)=>e.order.get(o)-e.order.get(r)):[...n[0]||[]]},"inLogOrder"),qn=/; its log is \S*\/\.claude\/kickflip\/logs\/([^/\s]+\.log)\.$/,Mn=i(e=>{const t=!e.log&&typeof e.text=="string"?qn.exec(e.text):null;return t?{...e,text:`${e.text.slice(0,t.index)}.`,log:t[1]}:e},"withLog");function yt(e,{lines:t=[],events:n=[],owner:o={},working:r={},fromAsk:a=null,links:u=[],agents:p={},moved:f=[],index:g=ht(n,o)}){const c=e.startsWith("ask:")?[e.slice(4)]:[a,...f].filter(Boolean),l=[...new Set([e,...c.map(d=>`ask:${d}`)])],w=new Map((g.questions.get(`item:${e}`)||[]).map(d=>[d.id,d])),b=g.answers.get(`item:${e}`)||[],D=new Set([...w.values()].map(d=>d.round_of).filter(Boolean)),q=Ve(p).filter(J).map(d=>String(d.started||"")).filter(Boolean),L=new Set(b.filter(d=>ft(w.get(d.data.id),d.ts)||D.has(d.data.id)||q.some(x=>x>String(d.ts))).map(d=>d.id)),R=[...Ve(p).flatMap(d=>[...d.started?[{ts:d.started,who:"claude",kind:"agent",text:`${Ye(d)} started`,finished:!1,eta:d.done?null:d.eta,...ae(d)?{planner:!0}:{}}]:[],...d.done?[{ts:d.done,who:"claude",kind:"agent",text:`${Ye(d)} finished`,finished:!0,eta:null,...ae(d)?{planner:!0}:{}}]:[],...d.calls.length?[{ts:d.done||d.calls.at(-1).at,who:"claude",kind:"calls",text:Ye(d),calls:d.calls.map(x=>x.text),verified:d.verified}]:[]]),...t.map(Mn).map(d=>({ts:d.ts,who:d.who||"claude",...d.log?{log:d.log}:{},...d.kind==="status"?{kind:"status",...d.planner?{planner:!0}:{}}:{},...Object.values(be).includes(d.kind)?{kind:d.kind,ask:d.ask}:{},text:d.text||"",html:d.html||null,link:d.link||null,via:d.via||null})),...Je(g,l.map(d=>g.byKey.get(d))).map(d=>({ts:d.ts,who:"love",via:"site",kind:d.kind,text:_n(d,w),files:d.data.files||[],eventId:d.id,reply:d.reply,...In(d,w)})),...b.map(d=>{const x=[d.data.label||d.data.choice,d.data.note].filter(Boolean).join(" \xB7 ");return{ts:d.ts,who:"love",via:"questions",kind:d.kind,text:`${w.get(d.data.id).question}
4
- \u2192 ${x}`,files:d.data.files||[],eventId:d.id,reply:d.reply,status:Bn}}),...Je(g,[...new Set(c)].map(d=>g.asks.has(d)?[g.asks.get(d)]:[])).flatMap(d=>[{ts:d.ts,who:"love",via:"ask",kind:d.kind,text:d.data?.text||"",files:d.data?.files||[],eventId:d.id,reply:d.reply,...f.includes(d.id)?{moved:!0}:{},...typeof d.data?.from?.title=="string"?{from:d.data.from.title}:{}},...d.data?.quick===!0?[{ts:d.ts,who:"love",kind:"quick-build",request:!0,text:Rn}]:[],...u.map(x=>({ts:d.ts,who:"claude",kind:"ask-link",text:x.folded?`Moved to ${x.ref}: ${x.title}`:`${x.became?"Became":"Added to"} ${x.ref}`,link:`#item=${encodeURIComponent(x.key)}`,html:null,via:null}))])].sort((d,x)=>String(d.ts).localeCompare(String(x.ts))),I=ze(R),{edits:G,editFiles:K}=g;for(const d of R){if(!d.eventId)continue;(d.kind==="ask"||d.kind==="item-message")&&typeof G.get(d.eventId)=="string"&&Object.assign(d,{text:G.get(d.eventId),edited:!0,files:[...d.files,...K.get(d.eventId)||[]]});const x=d.kind==="ask"&&(u.length>0||!!d.moved);d.state=d.reply?"replied":x||L.has(d.eventId)||I>String(d.ts)?"answered":$(r,d.eventId)?"working":"waiting",d.canDelete=d.kind==="item-message"&&(d.state==="working"||d.state==="waiting"),d.canEdit=d.canDelete}return R}i(yt,"threadOf");function Dn(e,t,n,o,r,a){const u=i((l,w)=>{const b=a.filter(q=>q.kind==="wave-triage"&&q.data?.[l]===w).pop(),D=r.filter(q=>q.topic===`${l}:${w}`&&(q.state==="open"||q.state==="answered")).length;return{running:!!(b&&!b.reply),questions:D}},"triageOf"),p=new Map(o.map(l=>[l.key,l])),f=i(l=>l.filter(w=>w.lane==="done"&&!We(w)).length,"merged"),g=n.map(l=>({l,cards:l.keys.map(w=>p.get(w)).filter(Boolean)})).map(l=>({...l,open:!l.l.finished_at&&l.cards.some(w=>w.lane!=="done")})).sort((l,w)=>Number(l.open)-Number(w.open));for(const{l,cards:w}of g)for(const b of w)b.lineup={slug:l.slug,title:l.title};const c=g.filter(l=>l.open).map(({l,cards:w})=>({kind:"lineup",slug:l.slug,title:l.title,goal:l.goal,keys:w.map(b=>b.key),phases:l.phases.map(b=>b.filter(D=>p.has(D))).filter(b=>b.length),next:Cn(w),merged:f(w),total:w.length,triage:u("lineup",l.slug)}));return e.fromWaves?[...c,...t.filter(l=>!l.finished).map(l=>({w:l,cards:o.filter(w=>w.wave===l.slug&&w.kind!=="ask")})).filter(({cards:l})=>l.length).map(({w:l,cards:w})=>({kind:"wave",slug:l.slug,title:l.title,goal:null,keys:w.map(b=>b.key),phases:null,next:null,merged:f(w),total:w.length,triage:u("wave",l.slug)}))]:c}i(Dn,"waveBandsOf");function Cn(e){const t=e.filter(a=>a.lane==="todo"),n=t.find(a=>a.ready&&a.buildable)||t[0];if(!n)return null;const o=n.ready&&n.buildable,r=o?"ready":n.held?"held":n.blockedBy.length?`waits on ${n.blockedBy.map(a=>a.ref).join(", ")}`:n.action?"needs you":n.unsorted?"new":n.state||"not ready";return{key:n.key,ref:n.ref,ready:o,word:r}}i(Cn,"nextOf");function ws(e,t,n,o){const r=e.waveBands.find(l=>l.kind==="lineup"&&l.slug===t);if(!r)return null;const a=new Map(e.items.map(l=>[l.key,l.lane])),u=r.keys.filter(l=>a.get(l)==="todo"),p=u.indexOf(n),f=p+o;if(p<0||f<0||f>=u.length)return null;[u[p],u[f]]=[u[f],u[p]];let g=0;const c=r.keys.map(l=>a.get(l)==="todo"?u[g++]:l);return g=0,r.phases.map(l=>c.slice(g,g+=l.length))}i(ws,"lineupMoved");const Nn=i(e=>e.phases||e.items.map(t=>[t]),"lineupPhases");function hs(e){const{owner:t={},topicItems:n={},events:o=[],threads:r={},prs:a={},working:u={}}=e,p=e.now??Date.now(),f=ht(o,t),g=new Set(o.filter(s=>s.kind==="ask-withdrawn"&&!s.data?.key).map(s=>s.data?.id)),c=new Map(o.filter(s=>s.kind==="ask"&&!g.has(s.id)).map(s=>[s.id,s])),l=i((s,m)=>new Map(o.filter(h=>h.kind===s).sort((h,O)=>String(h.ts).localeCompare(String(O.ts))).map(h=>[h.data?.[m],h.ts])),"latest"),w=l("ask-bump","id"),b=l("card-unbump","key"),D=new Map([...l("card-bump","key")].filter(([s,m])=>!(String(b.get(s)||"")>String(m)))),q=l("card-done","key"),L=l("card-merge","key"),R=e.autoMerge===!0,I=e.tickets,G=new Map(o.filter(s=>s.kind==="card-hold").sort((s,m)=>String(s.ts).localeCompare(String(m.ts))).map(s=>[s.data?.key,s])),K=new Map,d=e.askLinks||{},x=new Map;for(const[s,m]of Object.entries(d))c.has(s)&&x.set(m,[...x.get(m)||[],s]);const y=[],A=[],le=new Map,ee=new Map,P=new Map,te=new Map,Q=e.github?null:Rt(e.remote);for(const{slug:s,wave:m,agents:h={}}of e.waves){const O=e.github||m.repo||null;y.push({slug:s,title:m.title||s,status:m.status||null,internal:!!m.internal,finished:null,reviewers:(m.reviewers||[]).map(S=>S.name)}),m.items.forEach((S,_)=>{const B=`${s}/${S.id}`,Me=(x.get(B)||[]).filter(v=>v!==S.from_ask),ve=[S.from_ask,...Me].filter(v=>c.has(v)),Le=new Set(ve.map(v=>`ask:${v}`)),k=[...$(r,B)||[],...ve.flatMap(v=>$(r,`ask:${v}`)||[])];S.from_ask&&K.set(S.from_ask,[...K.get(S.from_ask)||[],{key:B,ref:Fe(m,S,I),became:!0}]);const F=yt(B,{lines:k,events:o,owner:t,working:u,fromAsk:S.from_ask||null,moved:Me,index:f});for(const v of F)v.eventId&&le.set(v.eventId,v.state);ee.set(B,ze(F)),A.push(sn({slug:s,wave:m,it:S,order:_,repo:O,remote:Q,base:e.branch||"main",prs:Mt(S,O).map(v=>({...v,gh:$(a,Ct(v))||null})),...(v=>({agents:v,builder:bn(v,$(r,B),p,e.moved?.[He($(h,S.id))]??null,$(e.alive,B)??null,!!e.commandRunning?.[He($(h,S.id))]),reachedPhase:vn(v,$(r,B)),eta:v.map(bt=>bt.eta).filter(Boolean).sort().pop()||null}))(Ve($(h,S.id))),worktree:He($(h,S.id))??S.worktree?.path??null,thread:k,events:[...Je(f,[B,...Le].map(v=>f.byKey.get(v))),...ve.map(v=>c.get(v))],working:F.some(v=>v.state==="working"),said:F.filter(v=>v.who==="love"&&(v.kind==="item-message"||v.kind==="owner-answer")),askedAt:(f.questions.get(`item:${B}`)||[]).filter(v=>v.asked_at).map(v=>v.asked_at),topicItems:n,boardReviewers:e.reviewers||[],now:p,bumpedAt:D.get(B),holdAsk:G.get(B),closedAt:q.get(B),mergeAt:L.get(B),autoMerge:R,skipDraft:e.skipDraft===!0,tickets:I}));const Pe=A[A.length-1];te.set(B,{parent:S.parent?vt(s,S.parent):null,related:(S.related||[]).map(v=>vt(s,v))}),Pe.lane==="done"&&P.set(B,Pe.closedAt||String(Pe.updatedAt||""))})}const C=new Map(A.map(s=>[s.key,s])),V=new Map,W=e.try||{},$e=e.autoBuild===!0,j=["web","app"].includes(W.kind)?W.kind:e.waves.some(({wave:s})=>s.items.some(m=>m.install?.url))?"app":"web";for(const s of A){if(s.kind!=="work"||s.lane==="done")continue;const m=$(W.cards,s.key)||{},h=m.head||s.pr?.headRefOid,O=j==="web"?m.sha:s.install?.sha,S=s.builder?.kind===De.install?"running":m.state||(j==="app"&&s.install?"ready":null);s.try={kind:j,state:S,stale:!!(O&&h&&!String(h).toLowerCase().startsWith(String(O).toLowerCase())),url:j==="web"?null:s.install?.url||null,port:j==="web"&&S==="ready"&&m.https||null,sha:O||null,changes:m.ahead>0,script:m.script===!0,autoBuild:$e}}const N=W.main,me=N?.script&&N.sha?{slug:N.slug,branch:N.branch||"main",sha:N.sha.slice(0,7),at:N.at,kind:j,state:N.state||null,url:j==="web"?null:e.main?.install?.url||null,port:j==="web"&&N.state==="ready"&&N.https||null,pull:W.pull?{running:W.pull.running===!0,error:W.pull.error||null}:null}:null,ke=e.askProgress||{},Ae=l("ask-done","id"),ie=xe(o.filter(s=>s.kind==="owner-answer"),s=>s.data?.id),we=xe(o.filter(s=>s.kind==="prototype-request"),s=>s.data?.question),Ee=xe(o.filter(s=>s.kind==="reask-request"),s=>s.data?.question),U=(t.items||[]).map(s=>xn(s,ie.get(s.id)||[],we.get(s.id)||[],Ee.get(s.id)||[])),ne=new Map(U.map(s=>[s.id,s])),Be=xe(U,s=>s.topic),X=i(s=>{const m=Be.get(s)||[];return{open:m.filter(h=>h.state==="open").length,answered:m.filter(h=>h.state==="answered").length}},"pendingOn");for(const s of c.values()){const m=`ask:${s.id}`,h=C.get($(d,s.id)),O=[...K.get(s.id)||[]],S=h&&!O.some(B=>B.key===h.key);if(S&&O.push({key:h.key,ref:h.ref,title:h.title,became:!1,folded:!0}),O.length&&!S){V.set(m,O[0].key);continue}if(!S&&$(d,s.id)){V.set(m,$(d,s.id));continue}const _=yt(m,{lines:$(r,m)||[],events:o,working:u,links:O,index:f});for(const B of _)B.eventId&&le.set(B.eventId,B.state);ee.set(m,ze(_)),A.push(wn(s,_,w.get(s.id),O.length>0||!!$(d,s.id),$(ke,s.id),Ae.get(s.id),X(`item:${m}`)))}for(const s of y){const m=A.filter(h=>h.wave===s.slug);if(s.finished=Xt(m),s.finished)for(const h of m)h.lane==="done"&&(h.fold=Gt(s.slug))}for(const s of A)s.lineup=null;const H=new Set((t.topics||[]).map(s=>s.id)),de=e.waves.flatMap(({slug:s,wave:m})=>(m.lineups||[]).map(h=>{const O=Nn(h).map(S=>S.map(_=>`${s}/${_}`));return{...h,phases:O,keys:O.flat()}})),ce=i(()=>En([...t.topics||[],...A.filter(s=>!H.has(`item:${s.key}`)).map(s=>({id:`item:${s.key}`,card:s.key,title:`${s.ref}: ${s.title}`,...s.kind==="ask"?{askedAt:s.ask.askedAt}:{}})),...de.filter(s=>!H.has(`lineup:${s.slug}`)).map(s=>({id:`lineup:${s.slug}`,title:s.title,summary:"Wave triage."})),...(e.fromWaves?y:[]).filter(s=>!H.has(`wave:${s.slug}`)).map(s=>({id:`wave:${s.slug}`,title:s.title,summary:"Wave triage."}))],U,new Set(A.filter(z).map(s=>`item:${s.key}`))),"topicsOf"),E=new Map(ce().map(s=>[s.id,s]));for(const s of A){const m=E.get(`item:${s.key}`);if(!m){s.questions=null;continue}const h=m.questions.filter(_=>ne.get(_)?.state!=="resolved"),O=m.questions.find(_=>ne.get(_)?.state==="open")||h[0]||m.questions[0],S=m.questions.map(_=>ne.get(_)).filter(_=>_?.state==="open");s.questions={topic:m.id,state:m.state,open:m.open,answered:m.answered,replied:m.replied,resolved:m.resolved,first:O,askedAt:S.map(_=>_.asked_at).filter(Boolean).sort(),fromAsks:S.length>0&&S.every(_=>_.ask)}}const se=new Map(A.map(s=>[s.key,s]));for(const s of A){s.blockedBy=s.kind!=="work"||s.lane==="done"?[]:s.deps.map(h=>se.get(String(h).includes("/")?h:`${s.wave}/${h}`)).filter(h=>h&&h.lane!=="done"&&!h.reopened).map(St),mn(s,ne,R),s.lane==="todo"&&s.kind==="work"&&!s.held&&dt(s)&&(s.lane="progress"),s.unpicked=s.kind==="work"&&s.lane==="todo"&&!!pn(U,s.key),s.unpicked&&(s.state="prototyping"),s.unpicked&&!s.action&&(s.next=fn),s.buildable=cn(s);const m=s.kind==="work"&&s.lane==="todo";s.unsorted=m&&(!!s.fromAsk||s.unfiled)&&!s.state,s.ready=m&&s.state==="ready"&&!s.blockedBy.length&&!s.action}Pn(A,se,te);const T=new Map((t.items||[]).map(s=>[s.id,s.topic])),Re=i(s=>s.kind==="owner-answer"?T.has(s.data?.id)?/^item:(.+)$/.exec(T.get(s.data.id))?.[1]||null:"":s.kind==="ask"?`ask:${s.id}`:s.data?.key||(s.kind.startsWith("ask-")&&s.data?.id?`ask:${s.data.id}`:null),"ownCardOf"),he=i(s=>{const m=Re(s);return V.get(m)||m},"cardOf"),ue=i(s=>{const m=s.startsWith("ask:")?s.slice(4):null,h=m&&$(ke,m)?.state==="done"?$(ke,m).at:null;return[q.get(s),m&&Ae.get(m),h,P.get(s)].filter(Boolean).sort().pop()||""},"closedAt"),_e=i(s=>{const m=he(s);return m===null?!s.reply:!se.has(m)||!(ue(m)<String($(u,s.id)))?!1:le.has(s.id)?le.get(s.id)==="working":!s.reply&&!V.has(Re(s))&&!(String(ee.get(m)||"")>String(s.ts))},"unanswered"),oe=o.filter(s=>$(u,s.id)&&_e(s)).map(s=>({id:s.id,kind:s.kind,key:he(s),data:s.data,since:$(u,s.id)}));for(const s of A)s.working=oe.some(m=>m.key===s.key),s.kind==="work"&&s.lane==="progress"&&!s.builder&&!s.next&&s.waitsOn!=="checking"&&!s.working&&!s.implementAt&&(s.next=ct),s.sortAt=jn[s.lane](s)||(["review","stale"].includes(s.lane)?null:s.updatedAt)||null;for(const s of A){if(s.kind!=="work")continue;const m=(Be.get(`item:${s.key}`)||[]).filter(O=>O.state==="answered").map(O=>O.answers.at(-1).ts).sort().pop(),h=oe.filter(O=>O.key===s.key).map(O=>String(O.since)).sort()[0];s.orchestrator=["progress","todo","stale"].includes(s.lane)||s.waitsOn==="checking"||s.lane==="review"&&s.builder?.stalled?ts(s,s.waitFacts,{answeredAt:m,workingSince:h}):null,delete s.waitFacts}A.sort(Pt);const Te=Dn(e,y,de,A,U,o),pe=ce(),ye=_t({on:e.autoReview,incoming:e.incoming,records:e.reviewRecords,events:o,now:p,refs:new Map(A.filter(s=>s.kind==="work").map(s=>[s.key,s.ref]))}),Ie=[...Fn(A,pe,U),...It(ye)],qe=new Map(Ie.filter(s=>s.questions).map((s,m)=>[s.topic||`item:${s.key}`,m])),fe=i(s=>qe.get(s.id)??qe.size,"rankOf");pe.sort((s,m)=>fe(s)-fe(m));const Se=A.filter(s=>s.ask?.answerAt).sort((s,m)=>m.ask.answerAt.localeCompare(s.ask.answerAt)).map(s=>({key:s.key,id:s.id,text:s.title,at:s.ask.answerAt}));return Tn({kind:j,main:me,remote:Q&&{host:Q.host,name:`${Q.host}/${Q.path}`},waves:y,waveBands:Te,items:A,moved:Object.fromEntries(V),answers:Se,owner:U,ownerTopics:pe,reviews:ye,needs:Ie,working:oe.length,workingOn:oe,checks:Un(e,p)},e)}i(hs,"buildBoard");function Tn(e,{listen:t,prompts:n}={}){const o=[...Gn(n),...e.needs];return{...e,needs:o,needsSummary:Kn(o),checks:{...e.checks,watcher:{listening:"running",asleep:"asleep",waking:"waking"}[t]||"stopped"}}}i(Tn,"withHub");const St=i(e=>({key:e.key,ref:e.ref}),"linkOf"),vt=i((e,t)=>String(t).includes("/")?String(t):`${e}/${t}`,"linkKey"),Ln=i((e,t)=>e.ref.localeCompare(t.ref,void 0,{numeric:!0}),"byRef");function Pn(e,t,n){const o=new Map,r=new Map,a=new Map,u=i((f,g,c)=>f.set(g,[...f.get(g)||[],c]),"add");for(const[f,g]of n){g.parent&&u(o,g.parent,f);for(const c of g.related)c!==f&&(u(r,f,c),u(r,c,f))}for(const f of e)for(const g of f.blockedBy||[])u(a,g.key,f.key);const p=i((f=[])=>[...new Set(f)].map(g=>t.get(g)).filter(Boolean).map(St).sort(Ln),"cards");for(const f of e){const g=n.get(f.key)?.parent;f.parent=g?{key:g,ref:t.get(g)?.ref||g.slice(g.indexOf("/")+1)}:null,f.children=p(o.get(f.key)),f.related=p(r.get(f.key)),f.waitsOnIt=p(a.get(f.key))}}i(Pn,"linkCards");const jn={todo:i(e=>e.created,"todo"),progress:i(e=>e.progressSince,"progress"),review:i(e=>e.reviewSince,"review"),stale:i(e=>e.reviewSince,"stale"),done:i(e=>e.closedAt,"done"),asks:i(e=>e.ask.answerAt,"asks")},Z=i((e,t)=>`${e} ${t}${e===1?"":"s"}`,"plural");function Un({checked:e,watcher:t,replyAt:n,threads:o={},working:r={},waves:a=[]},u){const p=Number(e?.every)||30,g=[n,t?.since,...Object.values(r),...Object.values(o).flat().filter(l=>(l.who||"claude")==="claude").map(l=>l.ts),...a.flatMap(l=>Object.values(l.agents||{}).flatMap(w=>Object.values(w||{})).map(w=>w?.done||w?.started))].filter(l=>typeof l=="string"&&!Number.isNaN(Date.parse(l))).reduce((l,w)=>l&&Date.parse(l)>Date.parse(w)?l:w,null),c=!!e?.idle;return{at:e?.at||null,every:c?null:p,idle:c,late:!c&&!!e?.at&&u-Date.parse(e.at)>2*p*6e4,claudeAt:g}}i(Un,"checksOf");function Fn(e,t,n){const o=new Set(e.map(p=>p.questions?.topic).filter(Boolean)),r=i(p=>p.find(f=>n.find(g=>g.id===f)?.state==="open")||p[0],"firstOpen"),a=t.filter(p=>p.state!=="resolved"&&p.open>0&&!o.has(p.id)).map(p=>{const f=`questions.html#${r(p.questions)}`,g=/^(?:lineup|wave):(.+)$/.exec(p.id)?.[1]||null;return{kind:"Question",title:p.title,text:`${p.title} \xB7 ${Z(p.open,"question")}`,url:f,topic:p.id,band:g,questions:{open:p.open,url:f},ready:null,since:n.filter(c=>c.topic===p.id&&c.state==="open").map(c=>c.asked_at).filter(Boolean).sort()[0]||null}}),u=e.map(p=>{const f=p.questions&&p.questions.state!=="resolved"&&p.questions.open>0?{open:p.questions.open,url:`questions.html#${p.questions.first}`}:null,g=p.waitsOn==="ready"?p.pr.url:null,c=!f&&!g&&p.action?{label:p.action.label,url:p.action.url}:null;if(!f&&!g&&!c)return null;const l=`${p.ref}: ${p.title}`,w=[l,f&&Z(f.open,"question"),g&&"Ready on GitHub",c?.label].filter(Boolean).join(" \xB7 ");return{kind:f?"Question":g?"Tap Ready":"Action needed",title:l,text:w,url:`#item=${encodeURIComponent(p.key)}`,key:p.key,questions:f,ready:g,action:c,since:p.created||null}}).filter(Boolean);return[...a,...u].sort(Wn)}i(Fn,"needsOf");const Wn=i((e,t)=>e.since&&t.since?e.since.localeCompare(t.since):!!t.since-!!e.since,"oldestFirst");function Gn(e=[]){return e.map(t=>{const n=t.questions?.length?`Question: ${t.questions.map(o=>o.question).join(" \xB7 ")}`:`${t.tool}: ${t.detail||t.action}`;return{kind:"Prompt",title:n,text:n,url:"",prompt:t}})}i(Gn,"promptLines");function Kn(e){const t=e.filter(a=>a.prompt).length,n=e.reduce((a,u)=>a+(u.questions?.open||0),0),o=e.filter(a=>a.ready).length,r=e.filter(a=>a.review).length;return[t&&Z(t,"prompt"),n&&Z(n,"question"),o&&`${Z(o,"draft")} waiting on Ready`,r&&`${Z(r,"review")} held`].filter(Boolean).join(" \xB7 ")}i(Kn,"needsSummary");function ys(e){const t=i((...n)=>e.items.filter(o=>n.includes(o.lane)).length,"count");return{items:e.needs.map(({kind:n,text:o,url:r})=>({kind:n,text:o,url:r})),working:e.working,summary:e.needsSummary,lanes:{review:t("review","stale"),progress:t("progress"),todo:t("todo")},building:e.items.some(n=>(n.agents||[]).some(o=>!o.done))}}i(ys,"needsAnswer");const Qn=i(e=>e.buildable&&e.state==="ready"&&!e.held&&!e.unsorted&&!e.blockedBy.length&&!e.questions?.open&&!e.questions?.answered&&!e.grilling&&!e.prototyping,"pullableCard"),Vn=10;function Hn(e,{cap:t=Vn,pulled:n=[]}={}){const o=e.filter(c=>!z(c)),r=i(c=>(c.agents||[]).filter(l=>!l.done),"running"),a=o.filter(c=>c.waitsOn==="checking"||r(c).some(J)).length,u=o.filter(c=>Qn(c)&&!c.working).map(c=>c.key),p=o.filter(c=>n.includes(c.key)&&(u.includes(c.key)||c.buildable&&c.working)).map(c=>c.key),f=o.filter(c=>c.implementAt&&c.state==="ready"&&!c.blockedBy.length).map(c=>c.key),g=u.filter(c=>!p.includes(c)).slice(0,Math.max(0,t-a-p.length-f.length));return{idle:!a,pullable:u,waiting:p,starts:f,pulls:g}}i(Hn,"pullOf");function Ss(e,t,n){return e.filter(o=>o.kind==="work"&&!z(o)&&o.waitsOn!=="checking"&&!(o.agents||[]).some(r=>r.started&&!r.done)).flatMap(o=>{const r=(o.prs||[]).find(u=>u.state==="OPEN"&&u.mergeable==="CONFLICTING"&&u.repo===o.repo&&u.headRefOid),a=r&&`${r.headRefOid}@${n}`;return r&&$(t,o.key)!==a?[{key:o.key,pr:r.number,branch:r.headRefName,conflict:a}]:[]})}i(Ss,"rebasesDue");const Xn=3;function vs(e,{cap:t=Xn}={}){const n=e.filter(a=>!z(a)),o=n.filter(a=>(a.agents||[]).some(u=>ae(u)&&u.started&&!u.done)).length;return n.filter(a=>a.buildable&&a.state!=="ready"&&!a.unsorted&&!a.blockedBy.length&&!a.held&&!a.working&&!a.grilling&&!a.prototyping&&!a.questions&&!(a.agents||[]).some(ae)).slice(0,Math.max(0,t-o)).map(a=>a.key)}i(vs,"arrivalsOf");function Yn(e){return e.filter(t=>t.lane==="todo"||t.lane==="stale").map(t=>JSON.stringify([t.key,t.title,t.deps||[]])).sort().join(`
5
- `)}i(Yn,"todoOf");function bs(e){const t=e.filter(o=>o.kind==="work"&&o.lane!=="done"&&o.questions?.open>0),n=t.map(o=>JSON.stringify([o.key,o.questions.open,o.questions.askedAt||[]])).sort().join(`
6
- `);return{waiting:t.map(o=>o.key),seen:`${n}
1
+ var Gt=Object.defineProperty;var l=(e,t)=>Gt(e,"name",{value:t,configurable:!0});import{routeRecord as A}from"../hub/routes.mjs";import Qt from"node:fs";import{ticketBadge as ct,ticketIn as Vt}from"./tickets.mjs";import{prLinks as Ht,reviewLinks as Xt,reviewTime as Yt,reviewersOf as zt}from"./review.mjs";import{remoteFromInput as Jt}from"../hub/repos.mjs";import{reviewsOf as Zt,reviewNeeds as en,reviewActions as tn}from"./auto-review.mjs";import{cardPRs as nn,hasPR as et,leastReady as on,prKeyOf as sn,prURL as rn}from"../shared/card-prs.mjs";import ut from"node:vm";import{checkWords as an,parseCheck as ln}from"../shared/owner-check.mjs";import{buildScriptOf as dn}from"./build-script.mjs";const tt=ut.createContext({});for(const e of["ui-enums.js","ui-order.js"])ut.runInContext(Qt.readFileSync(new URL(`./public/${e}`,import.meta.url),"utf8"),tt);const{BUTTON:oe,ACTION_KIND:q,BUILDER_KIND:be,PR_STATE:Z}=tt.BoardUI,{laneOrder:cn}=tt.BoardUI,un=["item-message","mark-ready","grill-more","prototype-request","visual-request","reask-request"],pt="question-reopen",ts=Object.freeze({todo:"Todo",progress:"In Progress",review:"In Review",done:"Done"}),Se="move",ft=10*6e4,pn=5*6e4,gt="build-refused",Ie=Object.freeze({ask:"builder-ask",answer:"builder-answer"}),fn=864e5,pe=l(e=>e.lane==="done"||e.lane==="asks","closedLane"),gn=l(e=>`wave:${e}`,"waveFold"),kt=7*fn,mt=l((e,t)=>({id:e,url:t?.workspace?`https://linear.app/${t.workspace}/issue/${e}`:null}),"linearRef"),kn=l((e,t)=>String(e).replace(/^S(\d+)$/,`${t||"INT"}-$1`),"internalRef"),Ke=l((e,t,n)=>Vt(n,t.ticket)?t.ticket:e.internal===!0?kn(t.id,n?.prefix):t.id,"refOf"),mn=l((e,t,n,s)=>ct(e||(t?{source:"internal",prefix:"INT"}:null),n,s)||(t?{id:String(t),url:null,source:null}:null),"ticketOf");function wn(e,t,n,s,r,a,u,d,p){return!a&&(e.lane==="done"||t?.state==="MERGED"||t?.state==="CLOSED")?"done":(n||s)&&!d?"progress":r?"review":t?.state==="OPEN"?t.checks?.state==="fail"&&(!t.isDraft||u)?"progress":"review":t||p?"progress":"todo"}l(wn,"laneOf");const hn="Lander",wt=l(e=>e.kind!==be.install&&e.label!==hn,"changesCode");function yn(e,t){return e?.state==="MERGED"||t?Z.merged:e?.state==="CLOSED"?Z.closed:e?.state==="OPEN"?e.isDraft?Z.draft:Z.open:null}l(yn,"prStateOf");const ht=l(e=>e.pr?.status===Z.closed,"unlanded"),bn=l(e=>e.some(t=>t.kind==="work")&&e.every(t=>t.lane==="done"),"finishedOf");function nt(e){const t=yt(e);return t?.done&&t.handed_back?t.handed_back:null}l(nt,"handedBackAt");const yt=l(e=>e.filter(t=>t?.started&&te(t)&&t.kind!==be.install).sort((t,n)=>String(t.started).localeCompare(String(n.started))).at(-1),"newestBuild");function Sn(e,t,n){return Object.fromEntries(e.map(s=>{const r=A(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"?A(n,s.name):null,github:s.github||null}]}))}l(Sn,"reviewOf");function vn(e,t,n,s,r,a,{held:u,needsApproval:d}){return n?.kind===be.install?"builder":s?"checking":n?"builder":u&&e==="review"?"merge":r&&e==="review"?"owner":e==="review"&&t?.state==="OPEN"&&t.isDraft?a?"ci":"ready":e==="review"?bt(t,d)?"merge":"reviewers":null}l(vn,"waitsOnOf");const bt=l((e,t)=>e?.reviewDecision==="APPROVED"||!t&&!["REVIEW_REQUIRED","CHANGES_REQUESTED"].includes(e?.reviewDecision),"reviewed"),qe=/(^|\/)prototype-[\w-]+\.html/,xn={reviewers:"Waiting for PR reviewers",merge:"Approved, merges once CI and the merge state allow",ci:"Marked ready for review once CI passes"},Ge={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"},On=l(e=>`Verified: tap Merge to land it on ${e}`,"heldNext"),$n="Fix the failing CI",St="Tap Done once it is settled",En=["status","agent","ask-link","command",Se,Ie.answer],vt=l(e=>(e.who==="claude"||e.via==="github")&&!En.includes(e.kind),"countsUnread"),An=/^(?:Not merged yet: |Lander launched headless )/;function Bn({slug:e,wave:t,it:n,order:s,prs:r,repo:a,remote:u,base:d,builder:p,reachedPhase:f,agents:g,worktree:c,eta:h,thread:m,events:x,working:S,said:L,askedAt:_,topicItems:P,prSlack:T,boardReviewers:K,now:E,bumpedAt:C,holdAsk:i,closedAt:y,mergeAt:B,autoMerge:ke,skipDraft:re,tickets:U}){const V=r.map(w=>({repo:w.repo,number:w.number,url:rn(w),...w.gh||w.kept||{},status:yn(w.gh,w.merged_at)})),W=on(r.map(w=>w.gh)),N=r[W]?.gh||null,H=V[W]?.status??null,X=n.lane||null,Ne=!!y&&String(y)>String(n.lane_at||"");Ne&&(n={...n,lane:"done",closed_at:y,reopened_at:void 0});const F=[n.closed_at,...r.flatMap(w=>[w.merged_at,w.gh?.mergedAt])].filter(Boolean).map(String).sort().pop()||null,j=String(F||""),Ce=V.length>0&&V.every(w=>w.status===Z.closed),G=(n.lane==="done"||n.reopened_at||H===Z.merged)&&!Ce&&([...L.filter(w=>w.kind==="item-message").map(w=>w.ts),..._].map(String).filter(w=>w>j).sort().pop()||n.reopened_at)||void 0,me=n.owner_step&&!Ne?String(n.owner_step):null,Ye=(n.lane==="done"||H===Z.merged)&&!Ce;G&&(n={...n,next:void 0});const $e=nt(g),ze=!!G&&L.some(w=>String(w.ts)>j&&(w.state==="waiting"||w.state==="working")),we=`${e}/${n.id}`,Q=zt(t,K),ne=Object.fromEntries(Object.entries(Xt(t,n,we,P,Ht(T,r))).map(([w,J])=>[w,Yt(J.ts)])),ae=Object.values(ne).filter(Boolean).sort()[0]||null,Te=[...m.map(w=>w.ts),...x.map(w=>w.ts)].sort().pop()||null,Ee=[...m.filter(w=>vt({...w,who:w.who||"claude"})).map(w=>w.ts),...x.map(w=>w.reply?.at)].filter(Boolean).sort(),Y=!et(n)&&n.pushed?.branch?{branch:n.pushed.branch,at:n.pushed.at||null,host:u?.host||null}:null,z=!et(n)&&n.merge_ready?.branch?{branch:n.merge_ready.branch,at:n.merge_ready.at||null,base:d}:null,Ae=!!n.rebase_run&&N?.state==="OPEN",le=(n.rebased||[]).at(-1),Be=g.filter(w=>w.started&&!w.done&&te(w)),Le=!!$e&&wt(yt(g));let R=wn(n,N,Be.some(wt),Le,Y||z,!!G,re,Ae,Be.length>0||!!$e);G&&R==="todo"&&(R="progress");const Je=R==="review"&&!!ae&&E-Date.parse(ae)>kt,Re=!!me&&Ye&&R==="done";Re&&(R="review");let D=vn(R,N,p,!!$e&&R!=="done",Y,re,{held:z,needsApproval:Q.length>0});const Ze=D==="builder"&&N?.state==="OPEN"&&!N.isDraft,ie=R==="progress"&&!D&&N?.state==="OPEN"&&(!N.isDraft||re),de=Re||!!G&&R==="progress"&&!D&&!ie&&!ze;de&&(D="owner");const he=i&&String(i.ts)>String(n.held_at||""),_e=R==="todo"&&(he?!!i.data.hold:!!n.held),Pe=_e&&(he?i.data.until:n.pick_up_at)||null,je=R==="todo"||R==="progress",Ue=g.filter(te).map(w=>String(w.started||"")).filter(Boolean).sort()[0]||"",o=C&&!(Ue&&String(C)<Ue),k=m.filter(w=>(w.who||"claude")==="claude"&&!["status","command",Se].includes(w.kind)&&!An.test(w.text||"")).map(w=>String(w.ts)).sort().pop()||"",b=[B,z&&n.merge_ready.tapped].filter(Boolean).map(String).sort().pop(),v=D==="merge"&&!!b&&b>k,O=m.filter(w=>w.kind==="status"&&String(w.ts)>String(b)).sort((w,J)=>String(w.ts).localeCompare(String(J.ts))).at(-1),M=O?.text.startsWith("Waiting for ")?`${Ge.merging} \xB7 ${O.text[0].toLowerCase()}${O.text.slice(1)}`:Ge.merging,I=m.filter(w=>!["status",Se].includes(w.kind)).sort((w,J)=>String(w.ts).localeCompare(String(J.ts))).at(-1),ce=R==="todo"&&I?.kind===gt?I.text:null,ue=G||g.filter(te).map(w=>w.started).filter(Boolean).map(String).sort().pop()||null,We=N?.reviewDecision==="APPROVED",Fe=Y&&D==="owner"?`merge ${Y.branch} into ${d}`:z&&D==="merge"?v?M:On(d):D==="merge"&&!ke?v?M:(We?Ge:ot).waiting:D==="merge"&&!We?ot.auto:xn[D],ye=H===Z.draft?`Review draft PR #${V[W].number}`:null,Me=!Ae&&le?.to&&le.to===N?.headRefOid?`Rebased onto ${le.base||d}, pushed${N.mergeable==="MERGEABLE"?" \xB7 PR is clean again":""}`:null,$=Ae&&D==="checking"?g.flatMap(w=>w.calls).sort((w,J)=>String(w.at).localeCompare(String(J.at))).at(-1)?.text??null:null;return{key:we,kind:"work",order:s,wave:e,waveTitle:t.title||e,id:n.id,ref:Ke(t,n,U),title:n.title,storedLane:X,created:n.created||null,reviewSince:n.review_since||ae||n.merge_ready?.at||n.pushed?.at||n.created||null,progressSince:ue,closedAt:R==="done"?F:null,internal:t.internal===!0,repo:t.internal===!0&&!t.repo?null:a,lane:R,waitsOn:D,builder:D==="checking"?null:p,reachedPhase:f,agents:g,worktree:c??null,eta:h,working:S,reopened:!!G,awaitsDone:de,ownerStep:de?me:null,ownerCheck:de&&me&&n.owner_check?{words:an(ln(n.owner_check.check)),broken:n.owner_check.broken||null}:null,stagedAt:R==="todo"&&n.state==="staging"&&n.staged_at||null,roundAt:n.round_at||null,deps:n.deps||[],blockedUntil:n.blocked_until||null,blockReason:n.block_reason||null,held:_e,heldUntil:Pe,risky:!!n.risky,bumpable:je,bumpedAt:je&&o?C:null,holdable:R!=="done",hasNotes:!!(n.plan||String(n.notes||"").trim()),finishable:R!=="done",merging:v,refusal:ce,manualSteps:n.manual_steps||[],fromAsk:n.from_ask||null,unfiled:!!n.unfiled,next:Ze||R==="done"||D==="checking"?null:ie?$n:Me||Fe||n.next||ye||null,rebaseFailed:$,branch:n.branch||N?.headRefName||Y?.branch||null,pushed:R==="done"||Re?null:Y,mergeReady:R==="review"?z:null,stale:R!=="done"&&(Je||!!p?.stale),stalled:n.stalled?.reason||null,landStopped:R==="review"&&z&&n.merge_ready.stopped&&String(n.merge_ready.stopped)>String(n.merge_ready.tapped||"")?{words:Et("land"),at:n.merge_ready.stopped}:null,ticket:U?.source==="linear"&&!n.ticket&&n.linear?.length?null:mn(U,n.ticket,n.ticket||(t.internal?Ke(t,n,U):n.linear?.[0]),{repo:a,key:we}),ticketSource:U?.source||null,linear:(n.linear||[]).map(w=>U?.source==="linear"&&ct(U,w,{key:we,repo:a})||mt(w,U)),pr:V[W]||null,prs:V,reviewers:Q.map(w=>w.name),review:Sn(Q,N||r[W]?.kept,ne),inReviewSince:ae,threadCount:m.length+x.length,lastTs:Te,othersAt:Ee,grilling:At("grill",x,g,_),prototyping:At("prototype",x,g,_),state:n.state||null,updatedAt:N?.mergedAt||N?.updatedAt||r[W]?.merged_at||p?.at||Te||null,ask:null,fold:null,action:null,install:R==="done"?null:_n(n.install,N),waitFacts:Rn(n,{agents:g,thread:m,events:x,refusedAt:ce?I.ts:null})}}l(Bn,"workItem");function Rn(e,{agents:t,thread:n,events:s,refusedAt:r}){const a=new Set(n.filter(f=>f.kind===Ie.answer).map(f=>f.ask)),u=n.filter(f=>f.kind===Ie.ask&&!a.has(f.ask)).sort((f,g)=>String(f.ts).localeCompare(String(g.ts)))[0],d=l(f=>s.filter(g=>rt(g,f)).pop()?.ts||null,"requestAt"),p=n.filter(f=>(f.who||"claude")==="claude"&&!["status","agent","command",Se,gt].includes(f.kind)).map(f=>f.ts);return{handedBackAt:nt(t),next:e.next||null,ask:u?{at:u.ts,text:u.text}:null,grillAt:d("grill"),prototypeAt:d("prototype"),refusedAt:r,unverified:t.some(f=>f.calls.some(g=>!f.verified||String(g.at)>String(f.verified.at))),writes:[...p,...t.flatMap(f=>[f.verified?.at,f.started])].filter(Boolean).map(String).sort()}}l(Rn,"waitFactsOf");function _n(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))}}l(_n,"installOf");function Mn(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",!bt(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)}l(Mn,"mergeBlockers");const In=l((e,t)=>!Mn(e,{needsApproval:t}).length,"mergeable");function qn(e,t,n){if(pe(e))return null;const s=`#item=${encodeURIComponent(e.key)}`;if(e.stalled)return{kind:q.stalled,url:s,label:`stalled: ${e.stalled}`};if(Dn(e)){const r=t.get(e.questions.first);return qe.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.kind==="ask"&&e.waitsOn==="owner"?{kind:q.done,url:s,label:e.next||St}: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)||In(r,e.reviewers.length>0))?{kind:q.merge,url:s,label:"Merge"}:null}l(qn,"actionOf");const Dn=l(e=>!!(e.questions&&e.questions.state!=="resolved"&&e.questions.open>0),"asking"),st=new Set([q.pick,q.questions]);function xt(e){return e.questions?oe.openQuestions:null}l(xt,"actionButtonOf");const Nn=l(e=>e.kind==="work"&&e.lane==="todo"&&!e.action&&!e.unpicked,"buildableOf"),Cn=l((e,t)=>/^item:/.test(e.topic||"")&&qe.test(e.url||"")&&!(e.options||[]).some(n=>n.id===t),"picksNoTake");function Tn(e,t){const n=e.filter(a=>a.topic===`item:${t}`),r=[...n.filter(a=>qe.test(a.url||"")).flatMap(a=>a.answers.map(u=>({q:a,a:u,again:Cn(a,u.choice)}))),...n.filter(a=>a.request).map(a=>({q:a,a:a.request,again:!0}))].sort((a,u)=>String(a.a.ts).localeCompare(String(u.a.ts))).at(-1);return r?.again?{id:r.q.id,note:r.a.note.replace(/\s+/g," ").trim()}:null}l(Tn,"noTakePicked");const Ln="Prototype again",Pn=Object.freeze({[q.pick]:oe.openQuestions,[q.questions]:oe.openQuestions,[q.ready]:oe.github,[q.steps]:oe.github,[q.merge]:oe.merge,[q.done]:oe.done,[q.stalled]:oe.reply}),jn="Merges once unblocked",Un=l(e=>`Blocked ${[e.blockedBy.length&&`by ${e.blockedBy.map(t=>t.ref).join(", ")}`,e.blockedUntil&&`until ${e.blockedUntil}`].filter(Boolean).join(" and ")}`,"mergeBlockedWords");function Wn(e,t,n){if(e.action=qn(e,t,n),e.mergeBlocked=e.action?.kind===q.merge&&e.blocked?Un(e):null,e.mergeBlocked&&Object.assign(e,{action:null,next:jn}),e.action?.kind===q.questions&&e.questions.fromAsks){Object.assign(e,{action:null,waitsOn:"owner",next:e.action.label,actionButton:xt(e),resolvedBy:null});return}e.awaitsDone&&=!e.action,e.awaitsDone||Object.assign(e,{ownerStep:null,ownerCheck:null}),e.actionButton=xt(e),e.resolvedBy=Pn[e.action?.kind]||null,e.action?.kind===q.merge&&!e.mergeReady&&(e.next=(e.pr?.reviewDecision==="APPROVED"?Ge:ot).ready),e.awaitsDone&&Object.assign(e,{lane:"review",next:e.ownerStep||St,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"&&st.has(e.action.kind)?"todo":"review";Object.assign(e,{lane:r,waitsOn:e.waitsOn==="ready"?"ready":"owner",next:e.action.label}),r==="review"&&Object.assign(e,{bumpable:!1,bumpedAt:null})}l(Wn,"placeOwnerWait");const Ot=l((e,t)=>e?e!=="todo":t.some(te),"started"),$t="none set yet";function ns(e,t){const n=t.filter(s=>s?.started);return e.next||et(e)||e.pushed||e.held||e.lane==="done"||nt(n)?!1:!n.some(s=>!s.done)&&Ot(e.lane,n)}l(ns,"owesNext");function Fn(e,t=new Date){const n=new Date(e),s=n.toLocaleTimeString("en-GB",{hour:"2-digit",minute:"2-digit"});return n.toDateString()===t.toDateString()?s:`${n.getMonth()+1}/${n.getDate()} ${s}`}l(Fn,"askedLabel");function Kn(e,t,n,s,r,a,u){const d=t.find(y=>y.kind==="ask"&&y.eventId===e.id),p=d.files,f=(d.text||"").trim().split(`
2
+ `)[0]||p.map(y=>y.name).join(", ")||"Ask",g=d.state==="replied"||d.state==="answered",c=r?.state==="progress"&&!(String(a||"")>String(r.at||"")),h=!c&&(!!r||!!a),m=g&&!h&&!c&&u.open>0,x=g&&!h&&!c&&!m&&u.answered>0,S=h||g&&!c&&!m&&!x,L=g&&!s&&!r?.moved&&[...t.filter(y=>y.who==="claude"&&y.kind!=="ask-link"&&y.kind!=="status"&&y.kind!=="command").map(y=>y.ts),...t.map(y=>y.reply?.at)].filter(Boolean).sort().pop()||null,_=S||c||m||x,P=t.some(y=>y.who==="love"&&y.kind!=="ask"&&(y.state==="waiting"||y.state==="working")),T=t.filter(y=>y.who==="love"&&y.kind==="item-message").flatMap(De).filter(([,y])=>y==="waiting"||y==="working").map(([y])=>y),K=_?"answered":d.state,E=_?null:n||null,C=[...t.filter(vt).map(y=>y.ts),...t.map(y=>y.reply?.at)].filter(Boolean).sort(),i=[...t.map(y=>y.ts),...C,...c?[r.at]:[]].filter(Boolean).sort().pop();return{key:`ask:${e.id}`,kind:"ask",order:0,wave:null,waveTitle:null,id:e.id,ref:_?Fn(e.ts):"New",isNew:!_,title:f,storedLane:null,internal:!1,repo:null,lane:c?"progress":S?"asks":"todo",waitsOn:c&&!P?"owner":null,builder:null,agents:[],eta:null,working:t.some(y=>De(y).some(([,B])=>B==="working")),deps:[],held:!1,risky:!1,bumpable:!_,bumpedAt:E,manualSteps:[],fromAsk:null,from:null,next:c&&r.next||null,hasNotes:!1,branch:null,finishable:_&&!S,linear:[],pr:null,prs:[],reviewers:[],review:{},inReviewSince:null,reviewSince:null,progressSince:c&&r.at||null,closedAt:null,threadCount:t.length,lastTs:i,othersAt:_?C:[],grilling:!1,prototyping:!1,created:e.ts,updatedAt:_?i:e.ts,ask:{eventId:e.id,state:K,askedAt:e.ts,bumpedAt:E,edited:!!d.edited,canEdit:!_,text:d.text,files:p,answerAt:L,from:d.from||null,owed:T},fold:null,action:null}}l(Kn,"askItem");const fe="visual",Qe="helper",Gn=new Set(["grill","prototype",fe]),ee=l(e=>Gn.has(e.kind),"plans"),te=l(e=>!ee(e),"builds"),Qn={grill:"grilling",prototype:"prototyping"},Vn=l((e,t)=>`${e} ${t} by orchestrator`,"orchestratorDid"),Et=l(e=>Vn(e,"stopped"),"stoppedWords"),Hn={grill:"grill-more",prototype:"prototype-request"},rt=l((e,t)=>e.kind===Hn[t]&&!e.data?.question,"isRequest");function At(e,t,n,s){if(n.some(a=>a.kind===e&&a.started&&!a.done))return!0;const r=t.filter(a=>rt(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)))}l(At,"planningOf");const os=30*6e4;function ss(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&&rt(a,"prototype")).pop();r&&n.push({key:s.key,request:r.id,since:r.ts});for(const a of e.owner.filter(u=>u.topic===`item:${s.key}`&&u.state==="requested"))n.push({key:s.key,request:a.request.id,question:a.id,since:a.request.ts})}return n}l(ss,"prototypeWaits");function Ve(e={}){return Object.entries(e).filter(([,t])=>t&&typeof t=="object").map(([t,n])=>({name:t,kind:Bt(n.kind)||null,model:n.model||(n.kind==="opus"||n.kind==="sonnet"?n.kind:null),label:n.label||null,started:n.started||null,eta:n.done?null:n.eta||null,done:n.done||null,log:n.session?.log||null,calls:Array.isArray(n.calls)?n.calls:[],verified:n.verified||null,stopped:n.stopped||null,handed_back:n.handed_back||null,...n.kind===Qe?{writes:!!n.writes,requested:n.requested||null}:{},...n.waits?{waits:n.waits}:{}})).sort((t,n)=>String(t.started||"").localeCompare(String(n.started||""))||t.name.localeCompare(n.name))}l(Ve,"agentsOf");function at(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}l(at,"worktreeOf");function Xn(e,t=[]){const n=e.filter(te).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}l(Xn,"reachedPhaseOf");function Yn(e,t=[],n,s=null,r=null,a=!1){const u=e.filter(E=>E.started&&!E.done&&E.kind!==fe),d=u.every(ee),p=d?u:u.filter(te),f=p.map(E=>String(E.started||"")).sort()[0];if(f===void 0)return null;const g=t.filter(E=>E.kind==="status"&&String(E.ts)>=f&&(d||!E.planner)).sort((E,C)=>String(E.ts).localeCompare(String(C.ts))).pop(),c=p.filter(E=>E.kind!==Qe).at(-1),h=p.some(E=>E.kind===be.install)?be.install:c?Bt(c.kind):"claude",m=d?null:p.find(E=>E.stopped&&String(E.stopped.at)>=String(E.started))?.stopped,x=g?.ts||f,S=m?m.at:s!==null&&s>Date.parse(x)?new Date(s).toISOString():x,L=g?g.phase||g.planner?g.text.replace(": "," \xB7 "):g.text||null:d?Qn[h]:null,_=n-Date.parse(S),P=!d&&!m&&r==="held",T=d||P?null:m?!1:r,K=P?!1:T===null?_>=ft:!T;return{progress:L,phase:g?.phase||null,at:x,kind:h,planner:d,silentSince:S,stale:K,alive:T,held:P,quiet:T===!0&&!a&&_>=pn,stopped:m?Et(m.run):null}}l(Yn,"builderOf");const lt={opus:"Claude Opus",sonnet:"Claude Sonnet",codex:"Codex"},zn=l(({model:e,kind:t})=>lt[e]||lt[t]||(t==="claude"?lt.opus:null),"modelName"),Bt=l(e=>e==="opus"||e==="sonnet"?"claude":e,"providerOf");function ve(e){const t=zn(e),{kind:n}=e,s=e.label?.replace(/\bbuilder\b/,"implementer").replace(/\bBuilder\b/,"Implementer"),r=l(u=>u[0].toLowerCase()+u.slice(1),"lower");if(t&&ee(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"}l(ve,"agentName");const Rt=l((e,t)=>!!e.resolved&&(!e.resolved_at||String(e.resolved_at)>=String(t)),"resolvedSince");function Jn(e,t,n=[],s=[],r=[]){const a=t.filter(S=>S.data?.id===e.id),u=a[a.length-1]||null,d=r.filter(S=>S.data?.question===e.id).at(-1),p=l((S,...L)=>!!S&&L.every(_=>String(S.ts)>String(_||"")),"after"),f=!!(e.resolved&&e.resolved_at&&u&&String(u.ts)>e.resolved_at),g=n.filter(S=>S.data?.question===e.id&&p(S,u?.ts,d?.ts)).at(-1),c=p(d,u?.ts,g?.ts,e.resolved_at),h=e.resolved&&!f&&!c,m=h?s.filter(S=>S.data?.question===e.id&&String(S.ts)>String(e.resolved_at||"")).at(-1):null,x=c?"open":h?"resolved":g?"requested":u?u.reply?"replied":"answered":"open";return{...e,state:x,reopened:c,request:g?{id:g.id,ts:g.ts,note:g.data.note||"",choice:g.data.choice||null}:null,reask:m?{id:m.id,ts:m.ts}:null,answers:a.map(S=>({ts:S.ts,choice:S.data.choice||null,note:S.data.note||"",files:S.data.files||[],reply:S.reply,acted:Rt(e,S.ts)}))}}l(Jn,"ownerQuestion");const ge=l(e=>e.round??(qe.test(e.url||"")?1:0),"roundOf");function Zn(e,t){const n=l((s,r)=>s.confirm_of||(s.options||[]).some(a=>a.id===r.choice),"settles");return e.filter(s=>ge(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)}l(Zn,"roundSettledBy");function eo(e){const t=e.find(r=>r.request&&!e.some(a=>ge(a)>ge(r)));if(t)return{n:ge(t)+1,state:"making"};const n=Math.max(0,...e.map(ge));if(!n)return null;const s=Zn(e,n);return s?{n,state:"closed",take:s.choice}:e.some(r=>ge(r)===n&&r.state!=="resolved")?{n,state:"back"}:null}l(eo,"roundState");function to(e){const t=e.filter(n=>qe.test(n.url||"")).map(n=>({n:ge(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}l(to,"prototypesOf");const xe=l((e,t,n)=>{const s=e.get(t);s?s.push(n):e.set(t,[n])},"add"),Oe=l((e,t)=>{const n=new Map;for(const s of e)xe(n,t(s),s);return n},"groupBy");function no(e,t,n=new Set){const s=new Set(e.map(u=>u.id)),r=[...e];t.some(u=>!s.has(u.topic))&&r.push({id:"",title:"Other"});const a=Oe(t,u=>s.has(u.topic)?u.topic:"");return r.map(u=>{const d=a.get(u.id)||[],p=l(c=>d.filter(h=>h.state===c).length,"count"),f=d.every(c=>c.state==="resolved")||n.has(u.id)&&!p("open"),g=d.length&&f?"resolved":"open";return{...u,state:g,questions:d.map(c=>c.id),open:p("open"),answered:p("answered"),replied:p("replied"),resolved:p("resolved"),round:eo(d)}}).filter(u=>u.questions.length)}l(no,"ownerTopics");const He={implement:"Implementation requested",prototype:"Prototype requested",grill:"Grill requested",visual:"Visual requested",reask:"Re-ask requested",hold:"Held",resume:"Resumed",done:"Marked done",related:"Related to",unrelated:"Unrelated from",followup:"Follow-up","followup-of":"Follow-up of"},_t={"grill-more":"grill","prototype-request":"prototype","visual-request":"visual","reask-request":"reask"},Mt={"mark-ready":"Mark ready",...Object.fromEntries(Object.entries(_t).map(([e,t])=>[e,He[t]]))},oo=["grill-more","prototype-request","visual-request"],so="answers submitted",It={reply:"Reply",build:"Implement"},ro=l(e=>It[e.data.intent],"intentLabel"),ao=l((e,t)=>{if(e.kind!=="prototype-request"||!t.has(e.data.question))return e.data.text||(e.data.files?.length?"":A(Mt,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(`
3
+ \u2192 `)},"actionText"),qt=l((e,t)=>[...e.keys()].indexOf(t)+1,"numberOf"),Dt=l((e,t)=>`Question ${qt(e,t.id)} \xB7 ${t.question}`,"numbered"),lo="question reopened",Xe=l(e=>e.data?.shared_by?.login?{by:e.data.shared_by.name||e.data.shared_by.login}:{},"byOf"),io=l((e,t)=>{const n=t.get(e.card);return{...e,text:`${He[e.command]} ${n?`${n.ref}: ${n.title}`:e.card}`,link:`#item=${encodeURIComponent(e.card)}`}},"linkLine"),Nt=l(e=>({kind:"command",command:e,request:!0,mark:He[e]}),"commandLine"),co=l((e,t)=>{if(e.kind==="item-message")return It[e.data.intent]?{status:ro(e)}:{};const n={request:!0,command:_t[e.kind]};return oo.includes(e.kind)?(e.data.question?t.has(e.data.question):String(e.data.text||"").trim()||e.data.files?.length)?{status:Mt[e.kind]}:n:e.kind==="reask-request"?n:{}},"requestOf"),it=l(e=>[...e.filter(t=>t.who==="claude"&&!["status","agent","command",Se,Ie.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 Ct(e,t={}){const n=new Map,s=new Map;for(const c of t.items||[])xe(n,c.topic,c),s.set(c.id,c.topic);const r=new Map,a=new Map,u=new Map,d=new Map,p=new Map,f=new Map,g=new Map;e.forEach((c,h)=>{g.set(c,h),c.data?.key&&un.includes(c.kind)&&xe(r,c.data.key,c),c.kind==="owner-answer"&&s.has(c.data?.id)&&xe(a,s.get(c.data.id),c),c.kind===pt&&s.has(c.data?.question)&&xe(u,s.get(c.data.question),c),c.kind==="ask"&&d.set(c.id,c)});for(const c of e.filter(h=>h.kind==="ask-edited").sort((h,m)=>String(h.ts).localeCompare(String(m.ts)))){p.set(c.data?.id,c.data?.text);for(const h of c.data?.files||[])xe(f,c.data?.id,h)}return{byKey:r,answers:a,reopens:u,asks:d,edits:p,editFiles:f,questions:n,order:g}}l(Ct,"threadIndex");const dt=l((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"),uo=/; its log is \S*\/\.claude\/kickflip\/logs\/([^/\s]+\.log)\.$/,po=l(e=>{const t=!e.log&&typeof e.text=="string"?uo.exec(e.text):null;return t?{...e,text:`${e.text.slice(0,t.index)}.`,log:t[1]}:e},"withLog");function fo(e,t){const n=t.run?e.find(s=>s.started===t.run):e.filter(s=>ee(s)===!!t.planner&&s.started&&String(s.started)<=String(t.ts)&&(!s.done||String(t.ts)<=String(s.done))).pop();return n?{agent:ve(n),run:n.started,running:!n.done}:{}}l(fo,"agentOfLine");function Tt(e,{lines:t=[],events:n=[],owner:s={},working:r={},fromAsk:a=null,links:u=[],agents:d={},moved:p=[],cards:f=new Map,index:g=Ct(n,s)}){const c=e.startsWith("ask:")?[e.slice(4)]:[a,...p].filter(Boolean),h=[...new Set([e,...c.map(i=>`ask:${i}`)])],m=new Map((g.questions.get(`item:${e}`)||[]).map(i=>[i.id,i])),x=g.answers.get(`item:${e}`)||[],S=new Set([...m.values()].map(i=>i.round_of).filter(Boolean)),L=Ve(d).filter(te).map(i=>String(i.started||"")).filter(Boolean),_=new Set(x.filter(i=>Rt(m.get(i.data.id),i.ts)||S.has(i.data.id)||L.some(y=>y>String(i.ts))).map(i=>i.id)),P=Ve(d),T=[...Ve(d).flatMap(i=>[...i.started?[{ts:i.started,who:"claude",kind:"agent",text:`${ve(i)} started`,agent:ve(i),run:i.started,finished:!1,eta:i.done?null:i.eta,...i.log?{log:i.log}:{},...ee(i)?{planner:!0}:{}}]:[],...i.done?[{ts:i.done,who:"claude",kind:"agent",text:`${ve(i)} finished`,agent:ve(i),run:i.started,finished:!0,eta:null,...ee(i)?{planner:!0}:{}}]:[],...i.calls.length?[{ts:i.done||i.calls.at(-1).at,who:"claude",kind:"calls",text:ve(i),calls:i.calls.map(y=>y.text),verified:i.verified}]:[]]),...t.map(po).map(i=>i.card?io(i,f):i).map(i=>({ts:i.ts,who:i.who||"claude",...i.log?{log:i.log}:{},...i.kind==="status"?{kind:"status",...i.planner?{planner:!0}:{},...fo(P,i)}:{},...i.kind===fe||i.kind===Se?{kind:i.kind}:{},...i.command?Nt(i.command):{},...i.card?{card:i.card}:{},...Object.values(Ie).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}:{}})),...dt(g,h.map(i=>g.byKey.get(i))).map(i=>({ts:i.ts,who:"love",via:"site",kind:i.kind,text:ao(i,m),files:i.data.files||[],eventId:i.id,reply:i.reply,...co(i,m),...Xe(i)})),...x.map(i=>{const y=[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(m,m.get(i.data.id))}
4
+ \u2192 ${y}`,files:i.data.files||[],eventId:i.id,reply:i.reply,status:so,...Xe(i)}}),...(g.reopens.get(`item:${e}`)||[]).map(i=>({ts:i.ts,who:"love",kind:i.kind,request:!0,mark:lo,text:`Question ${qt(m,i.data.question)} was reopened`,...Xe(i)})),...dt(g,[...new Set(c)].map(i=>g.asks.has(i)?[g.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,...p.includes(i.id)?{moved:!0}:{},...Xe(i),...typeof i.data?.from?.title=="string"?{from:i.data.from.title}:{}},...i.data?.quick===!0?[{ts:i.ts,who:"love",...Nt("implement"),text:He.implement}]:[],...u.map(y=>({ts:i.ts,who:"claude",kind:"ask-link",text:y.folded?`Moved to ${y.ref}: ${y.title}`:`${y.became?"Became":"Added to"} ${y.ref}`,link:`#item=${encodeURIComponent(y.key)}`,html:null,via:null}))])].sort((i,y)=>String(i.ts).localeCompare(String(y.ts))),K=it(T),{edits:E,editFiles:C}=g;for(const i of T){if(!i.eventId)continue;(i.kind==="ask"||i.kind==="item-message")&&typeof E.get(i.eventId)=="string"&&Object.assign(i,{text:E.get(i.eventId),edited:!0,files:[...i.files,...C.get(i.eventId)||[]]});const y=i.kind==="ask"&&(u.length>0||!!i.moved);i.state=i.reply?"replied":y||_.has(i.eventId)||K>String(i.ts)?"answered":A(r,i.eventId)?"working":"waiting",i.canDelete=i.kind==="item-message"&&(i.state==="working"||i.state==="waiting"),i.canEdit=i.canDelete}return go(T)}l(Tt,"threadOf");const Lt=["waiting","working","answered","replied"];function go(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(`
5
+
6
+ `),files:s.flatMap(r=>r.files),state:s.map(r=>r.state).sort((r,a)=>Lt.indexOf(r)-Lt.indexOf(a))[0],reply:void 0,answers:s.map(r=>({eventId:r.eventId,state:r.state,reply:r.reply,text:r.text}))}]})}l(go,"foldSubmits");const De=l(e=>(e.answers||[e]).filter(t=>t.eventId).map(t=>[t.eventId,t.state]),"stateEntries");function ko(e,t,n,s,r,a){const u=l((c,h)=>{const m=a.filter(S=>S.kind==="wave-triage"&&S.data?.[c]===h).pop(),x=r.filter(S=>S.topic===`${c}:${h}`&&(S.state==="open"||S.state==="answered")).length;return{running:!!(m&&!m.reply),questions:x}},"triageOf"),d=new Map(s.map(c=>[c.key,c])),p=l(c=>c.filter(h=>h.lane==="done"&&!ht(h)).length,"merged"),f=n.map(c=>({l:c,cards:c.keys.map(h=>d.get(h)).filter(Boolean)})).map(c=>({...c,open:!c.l.finished_at&&c.cards.some(h=>h.lane!=="done")})).sort((c,h)=>Number(c.open)-Number(h.open));for(const{l:c,cards:h}of f)for(const m of h)m.lineup={slug:c.slug,title:c.title};const g=f.filter(c=>c.open).map(({l:c,cards:h})=>({kind:"lineup",slug:c.slug,title:c.title,goal:c.goal,keys:h.map(m=>m.key),phases:c.phases.map(m=>m.filter(x=>d.has(x))).filter(m=>m.length),next:mo(h),merged:p(h),total:h.length,triage:u("lineup",c.slug)}));return e.fromWaves?[...g,...t.filter(c=>!c.finished).map(c=>({w:c,cards:s.filter(h=>h.wave===c.slug&&h.kind!=="ask")})).filter(({cards:c})=>c.length).map(({w:c,cards:h})=>({kind:"wave",slug:c.slug,title:c.title,goal:null,keys:h.map(m=>m.key),phases:null,next:null,merged:p(h),total:h.length,triage:u("wave",c.slug)}))]:g}l(ko,"waveBandsOf");function mo(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.state||"not ready";return{key:n.key,ref:n.ref,ready:s,word:r}}l(mo,"nextOf");function rs(e,t,n,s){const r=e.waveBands.find(c=>c.kind==="lineup"&&c.slug===t);if(!r)return null;const a=new Map(e.items.map(c=>[c.key,c.lane])),u=r.keys.filter(c=>a.get(c)==="todo"),d=u.indexOf(n),p=d+s;if(d<0||p<0||p>=u.length)return null;[u[d],u[p]]=[u[p],u[d]];let f=0;const g=r.keys.map(c=>a.get(c)==="todo"?u[f++]:c);return f=0,r.phases.map(c=>g.slice(f,f+=c.length))}l(rs,"lineupMoved");const wo=l(e=>e.phases||e.items.map(t=>[t]),"lineupPhases");function as(e){const{owner:t={},topicItems:n={},events:s=[],threads:r={},prs:a={},working:u={}}=e,d=e.now??Date.now(),p=Ct(s,t),f=new Set(s.filter(o=>o.kind==="ask-withdrawn"&&!o.data?.key).map(o=>o.data?.id)),g=new Map(s.filter(o=>o.kind==="ask"&&!f.has(o.id)).map(o=>[o.id,o])),c=l((o,k)=>new Map(s.filter(b=>b.kind===o).sort((b,v)=>String(b.ts).localeCompare(String(v.ts))).map(b=>[b.data?.[k],b.ts])),"latest"),h=c("ask-bump","id"),m=c("card-unbump","key"),x=new Map([...c("card-bump","key")].filter(([o,k])=>!(String(m.get(o)||"")>String(k)))),S=c("card-done","key"),L=c("card-merge","key"),_=e.autoMerge===!0,P=e.tickets,T=new Map(s.filter(o=>o.kind==="card-hold").sort((o,k)=>String(o.ts).localeCompare(String(k.ts))).map(o=>[o.data?.key,o])),K=new Map,E=new Map(e.waves.flatMap(({slug:o,wave:k})=>k.items.map(b=>[`${o}/${b.id}`,{ref:Ke(k,b,P),title:b.title}]))),C=e.askLinks||{},i=new Map;for(const[o,k]of Object.entries(C))g.has(o)&&i.set(k,[...i.get(k)||[],o]);const y=[],B=[],ke=new Map,re=new Map,U=new Map,V=new Map,W=e.github?null:Jt(e.remote);for(const{slug:o,wave:k,agents:b={}}of e.waves){const v=e.github||k.repo||null;y.push({slug:o,title:k.title||o,status:k.status||null,internal:!!k.internal,finished:!1,reviewers:(k.reviewers||[]).map(O=>O.name)}),k.items.forEach((O,M)=>{const I=`${o}/${O.id}`,ce=(i.get(I)||[]).filter($=>$!==O.from_ask),ue=[O.from_ask,...ce].filter($=>g.has($)),We=new Set(ue.map($=>`ask:${$}`)),Fe=[...A(r,I)||[],...ue.flatMap($=>A(r,`ask:${$}`)||[])];O.from_ask&&K.set(O.from_ask,[...K.get(O.from_ask)||[],{key:I,ref:Ke(k,O,P),became:!0}]);const ye=Tt(I,{lines:Fe,events:s,owner:t,working:u,fromAsk:O.from_ask||null,moved:ce,cards:E,index:p});for(const $ of ye)for(const[w,J]of De($))ke.set(w,J);re.set(I,it(ye)),B.push(Bn({slug:o,wave:k,it:O,order:M,repo:v,remote:W,base:e.branch||"main",prs:nn(O,v).map($=>({...$,gh:A(a,sn($))||null})),...($=>({agents:$,builder:Yn($,A(r,I),d,e.moved?.[at(A(b,O.id))]??null,A(e.alive,I)??null,!!e.commandRunning?.[at(A(b,O.id))]),reachedPhase:Xn($,A(r,I)),eta:$.map(w=>w.eta).filter(Boolean).sort().pop()||null}))(Ve(A(b,O.id))),worktree:at(A(b,O.id))??O.worktree?.path??null,thread:Fe,events:[...dt(p,[I,...We].map($=>p.byKey.get($))),...ue.map($=>g.get($))],working:ye.some($=>De($).some(([,w])=>w==="working")),said:ye.filter($=>$.who==="love"&&($.kind==="item-message"||$.kind==="owner-answer")),askedAt:(p.questions.get(`item:${I}`)||[]).filter($=>$.asked_at).map($=>$.asked_at),topicItems:n,prSlack:e.prSlack||{},boardReviewers:e.reviewers||[],now:d,bumpedAt:x.get(I),holdAsk:T.get(I),closedAt:S.get(I),mergeAt:L.get(I),autoMerge:_,skipDraft:e.skipDraft===!0,tickets:P}));const Me=B[B.length-1];V.set(I,{parent:O.parent?jt(o,O.parent):null,related:(O.related||[]).map($=>jt(o,$))}),Me.lane==="done"&&U.set(I,Me.closedAt||String(Me.updatedAt||""))})}const N=new Map(B.map(o=>[o.key,o])),H=new Map,X=e.try||{},Ne=e.autoBuild===!0,F=["web","app"].includes(X.kind)?X.kind:e.waves.some(({wave:o})=>o.items.some(k=>k.install?.url))?"app":"web";for(const o of B){if(o.kind!=="work"||o.lane==="done")continue;const k=A(X.cards,o.key)||{},b=k.head||o.pr?.headRefOid,v=F==="web"?k.sha:o.install?.sha,O=o.builder?.kind===be.install?"running":k.state||(F==="app"&&o.install?"ready":null);o.try={kind:F,state:O,stale:!!(v&&b&&!String(b).toLowerCase().startsWith(String(v).toLowerCase())),url:F==="web"?null:o.install?.url||null,port:F==="web"&&O==="ready"&&k.https||null,sha:v||null,changes:k.ahead>0,script:k.script===!0,autoBuild:Ne}}const j=X.main,Ce=j?.script&&j.sha?{slug:j.slug,branch:j.branch||"main",sha:j.sha.slice(0,7),at:j.at,kind:F,state:j.state||null,url:F==="web"?null:e.main?.install?.url||null,port:F==="web"&&j.state==="ready"&&j.https||null,pull:X.pull?{running:X.pull.running===!0,error:X.pull.error||null}:null,script:dn(j.target)}:null,G=e.askProgress||{},me=c("ask-done","id"),Ye=Oe(s.filter(o=>o.kind==="owner-answer"),o=>o.data?.id),$e=Oe(s.filter(o=>o.kind==="prototype-request"),o=>o.data?.question),ze=Oe(s.filter(o=>o.kind==="reask-request"),o=>o.data?.question),we=Oe(s.filter(o=>o.kind===pt),o=>o.data?.question),Q=(t.items||[]).map(o=>Jn(o,Ye.get(o.id)||[],$e.get(o.id)||[],ze.get(o.id)||[],we.get(o.id)||[])),ne=new Map(Q.map(o=>[o.id,o])),ae=Oe(Q,o=>o.topic),Te=l(o=>{const k=ae.get(o)||[];return{open:k.filter(b=>b.state==="open").length,answered:k.filter(b=>b.state==="answered").length}},"pendingOn");for(const o of g.values()){const k=`ask:${o.id}`,b=N.get(A(C,o.id)),v=[...K.get(o.id)||[]],O=b&&!v.some(I=>I.key===b.key);if(O&&v.push({key:b.key,ref:b.ref,title:b.title,became:!1,folded:!0}),v.length&&!O){H.set(k,v[0].key);continue}if(!O&&A(C,o.id)){H.set(k,A(C,o.id));continue}const M=Tt(k,{lines:A(r,k)||[],events:s,working:u,links:v,index:p});for(const I of M)for(const[ce,ue]of De(I))ke.set(ce,ue);re.set(k,it(M)),B.push(Kn(o,M,h.get(o.id),v.length>0||!!A(C,o.id),A(G,o.id),me.get(o.id),Te(`item:${k}`)))}for(const o of y){const k=B.filter(b=>b.wave===o.slug);if(o.finished=bn(k),o.finished)for(const b of k)b.lane==="done"&&(b.fold=gn(o.slug))}for(const o of B)o.lineup=null;const Ee=new Set((t.topics||[]).map(o=>o.id)),Y=e.waves.flatMap(({slug:o,wave:k})=>(k.lineups||[]).map(b=>{const v=wo(b).map(O=>O.map(M=>`${o}/${M}`));return{...b,phases:v,keys:v.flat()}})),z=l(()=>no([...t.topics||[],...B.filter(o=>!Ee.has(`item:${o.key}`)).map(o=>({id:`item:${o.key}`,card:o.key,title:`${o.ref}: ${o.title}`,...o.kind==="ask"?{askedAt:o.ask.askedAt}:{}})),...Y.filter(o=>!Ee.has(`lineup:${o.slug}`)).map(o=>({id:`lineup:${o.slug}`,title:o.title,summary:"Wave triage."})),...(e.fromWaves?y:[]).filter(o=>!Ee.has(`wave:${o.slug}`)).map(o=>({id:`wave:${o.slug}`,title:o.title,summary:"Wave triage."}))],Q,new Set(B.filter(pe).map(o=>`item:${o.key}`))),"topicsOf"),Ae=new Map(z().map(o=>[o.id,o]));for(const o of B){const k=Ae.get(`item:${o.key}`);if(!k){o.questions=null,o.prototypes=null;continue}const b=k.questions.filter(M=>ne.get(M)?.state!=="resolved"),v=k.questions.find(M=>ne.get(M)?.state==="open")||b[0]||k.questions[0],O=k.questions.map(M=>ne.get(M)).filter(M=>M?.state==="open");o.questions={topic:k.id,state:k.state,open:k.open,answered:k.answered,replied:k.replied,resolved:k.resolved,first:v,askedAt:O.map(M=>M.asked_at).filter(Boolean).sort(),fromAsks:O.length>0&&O.every(M=>M.ask)},o.prototypes=to(k.questions.map(M=>ne.get(M)))}const le=new Map(B.map(o=>[o.key,o]));for(const o of B){const k=o.kind==="work"&&o.lane!=="done";o.blockedBy=k?o.deps.map(v=>le.get(String(v).includes("/")?v:`${o.wave}/${v}`)).filter(v=>v&&v.lane!=="done"&&!v.reopened).map(Pt):[],o.blockedUntil=k?o.blockedUntil??null:null,o.blockReason=k?o.blockReason??null:null,o.blocked=o.blockedBy.length>0||!!o.blockedUntil,Wn(o,ne,_),o.lane==="todo"&&o.kind==="work"&&!o.held&&Ot(o.storedLane,o.agents)&&(o.lane="progress"),o.unpicked=o.kind==="work"&&o.lane==="todo"&&!!Tn(Q,o.key),o.unpicked&&(o.state="prototyping"),o.unpicked&&!o.action&&(o.next=Ln),o.buildable=Nn(o);const b=o.kind==="work"&&o.lane==="todo";o.unsorted=b&&(!!o.fromAsk||o.unfiled)&&!o.state,o.ready=b&&o.state==="ready"&&!o.blocked&&!o.action,o.staging=b&&o.state==="staging"}bo(B,le,V);const Be=new Map((t.items||[]).map(o=>[o.id,o.topic])),Le=l(o=>o.kind==="owner-answer"?Be.has(o.data?.id)?/^item:(.+)$/.exec(Be.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"),R=l(o=>{const k=Le(o);return H.get(k)||k},"cardOf"),Je=l(o=>{const k=o.startsWith("ask:")?o.slice(4):null,b=k&&A(G,k)?.state==="done"?A(G,k).at:null;return[S.get(o),k&&me.get(k),b,U.get(o)].filter(Boolean).sort().pop()||""},"closedAt"),Re=l(o=>{const k=R(o);return k===null?!o.reply:!le.has(k)||!(Je(k)<String(A(u,o.id)))?!1:ke.has(o.id)?ke.get(o.id)==="working":!o.reply&&!H.has(Le(o))&&!(String(re.get(k)||"")>String(o.ts))},"unanswered"),D=s.filter(o=>A(u,o.id)&&Re(o)).map(o=>({id:o.id,kind:o.kind,key:R(o),data:o.data,since:A(u,o.id)}));for(const o of B)o.working=D.some(k=>k.key===o.key),o.kind==="work"&&o.lane==="progress"&&!o.builder&&!o.next&&o.waitsOn!=="checking"&&!o.working&&(o.next=$t),o.sortAt=So[o.lane](o)||(o.lane==="review"?null:o.updatedAt)||null;for(const o of B){if(o.kind!=="work")continue;const k=(ae.get(`item:${o.key}`)||[]).filter(v=>v.state==="answered").map(v=>v.answers.at(-1).ts).sort().pop(),b=D.filter(v=>v.key===o.key).map(v=>String(v.since)).sort()[0];o.orchestrator=!o.stalled&&(["progress","todo"].includes(o.lane)||o.waitsOn==="checking"||o.lane==="review"&&o.stale)?jo(o,o.waitFacts,{answeredAt:k,workingSince:b}):null,delete o.waitFacts}qo(B,s),B.sort(cn);const Ze=ko(e,y,Y,B,Q,s),ie=z(),de=Zt({on:e.autoReview,incoming:e.incoming,records:e.reviewRecords,events:s,now:d,refs:new Map(B.filter(o=>o.kind==="work").map(o=>[o.key,o.ref]))}),he=[...xo(B,ie,Q),...en(de)],_e=new Map(he.filter(o=>o.questions).map((o,k)=>[o.topic||`item:${o.key}`,k])),Pe=l(o=>_e.get(o.id)??_e.size,"rankOf");ie.sort((o,k)=>Pe(o)-Pe(k));const je=new Set(he.filter(o=>o.questions&&o.progress).map(o=>`item:${o.key}`));for(const o of ie)je.has(o.id)&&(o.progress=!0);const Ue=B.filter(o=>o.ask?.answerAt).sort((o,k)=>k.ask.answerAt.localeCompare(o.ask.answerAt)).map(o=>({key:o.key,id:o.id,text:o.title,at:o.ask.answerAt}));return ho({kind:F,main:Ce,remote:W&&{host:W.host,name:`${W.host}/${W.path}`},waves:y,waveBands:Ze,items:B,moved:Object.fromEntries(H),answers:Ue,owner:Q,ownerTopics:ie,reviews:de,needs:he,working:D.length,workingOn:D,checks:vo(e,d)},e)}l(as,"buildBoard");function ho(e,{listen:t,prompts:n}={}){const s=[...$o(n),...e.needs];return{...e,needs:s,needsSummary:Eo(s),checks:{...e.checks,watcher:{listening:"running",asleep:"asleep",waking:"waking"}[t]||"stopped"}}}l(ho,"withHub");const Pt=l(e=>({key:e.key,ref:e.ref}),"linkOf"),jt=l((e,t)=>String(t).includes("/")?String(t):`${e}/${t}`,"linkKey"),yo=l((e,t)=>e.ref.localeCompare(t.ref,void 0,{numeric:!0}),"byRef");function bo(e,t,n){const s=new Map,r=new Map,a=new Map,u=l((p,f,g)=>p.set(f,[...p.get(f)||[],g]),"add");for(const[p,f]of n){f.parent&&u(s,f.parent,p);for(const g of f.related)g!==p&&(u(r,p,g),u(r,g,p))}for(const p of e)for(const f of p.blockedBy||[])u(a,f.key,p.key);const d=l((p=[])=>[...new Set(p)].map(f=>t.get(f)).filter(Boolean).map(Pt).sort(yo),"cards");for(const p of e){const f=n.get(p.key)?.parent;p.parent=f?{key:f,ref:t.get(f)?.ref||f.slice(f.indexOf("/")+1)}:null,p.children=d(s.get(p.key)),p.related=d(r.get(p.key)),p.waitsOnIt=d(a.get(p.key))}}l(bo,"linkCards");const So={todo:l(e=>e.created,"todo"),progress:l(e=>e.progressSince,"progress"),review:l(e=>e.reviewSince,"review"),done:l(e=>e.closedAt,"done"),asks:l(e=>e.ask.answerAt,"asks")},se=l((e,t)=>`${e} ${t}${e===1?"":"s"}`,"plural");function vo({checked:e,watcher:t,replyAt:n,threads:s={},working:r={},waves:a=[]},u){const d=Number(e?.every)||30,f=[n,t?.since,...Object.values(r),...Object.values(s).flat().filter(c=>(c.who||"claude")==="claude").map(c=>c.ts),...a.flatMap(c=>Object.values(c.agents||{}).flatMap(h=>Object.values(h||{})).map(h=>h?.done||h?.started))].filter(c=>typeof c=="string"&&!Number.isNaN(Date.parse(c))).reduce((c,h)=>c&&Date.parse(c)>Date.parse(h)?c:h,null),g=!!e?.idle;return{at:e?.at||null,every:g?null:d,idle:g,late:!g&&!!e?.at&&u-Date.parse(e.at)>2*d*6e4,claudeAt:f}}l(vo,"checksOf");function xo(e,t,n){const s=new Set(e.map(d=>d.questions?.topic).filter(Boolean)),r=l(d=>d.find(p=>n.find(f=>f.id===p)?.state==="open")||d[0],"firstOpen"),a=t.filter(d=>d.state!=="resolved"&&d.open>0&&!s.has(d.id)).map(d=>{const p=`questions.html#${r(d.questions)}`,f=/^(?:lineup|wave):(.+)$/.exec(d.id)?.[1]||null;return{kind:"Question",title:d.title,text:`${d.title} \xB7 ${se(d.open,"question")}`,url:p,topic:d.id,band:f,questions:{open:d.open,url:p},ready:null,since:n.filter(g=>g.topic===d.id&&g.state==="open").map(g=>g.asked_at).filter(Boolean).sort()[0]||null}}),u=e.map(d=>{const p=d.questions&&d.questions.state!=="resolved"&&d.questions.open>0?{open:d.questions.open,url:`questions.html#${d.questions.first}`}:null,f=d.waitsOn==="ready"?d.pr.url:null,g=!p&&!f&&d.action?{label:d.action.label,url:d.action.url}:null;if(!p&&!f&&!g)return null;const c=`${d.ref}: ${d.title}`,h=[c,p&&se(p.open,"question"),f&&"Ready on GitHub",g?.label].filter(Boolean).join(" \xB7 ");return{kind:p?"Question":f?"Tap Ready":"Action needed",title:c,text:h,url:`#item=${encodeURIComponent(d.key)}`,key:d.key,questions:p,ready:f,action:g,since:d.created||null,progress:d.lane==="progress"}}).filter(Boolean);return[...a,...u].sort(Oo)}l(xo,"needsOf");const Oo=l((e,t)=>!!t.progress-!!e.progress||(e.since&&t.since?e.since.localeCompare(t.since):!!t.since-!!e.since),"oldestFirst");function $o(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}})}l($o,"promptLines");function Eo(e){const t=e.filter(a=>a.prompt).length,n=e.reduce((a,u)=>a+(u.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 ")}l(Eo,"needsSummary");function ls(e){const t=l((...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))}}l(ls,"needsAnswer");const Ao=l(e=>e.buildable&&e.state==="ready"&&!e.held&&!e.blocked,"pullableCard"),Bo=10;function Ro(e,{cap:t=Bo,pulled:n=[]}={}){const s=e.filter(m=>!pe(m)),r=l((m,x)=>m.started&&!m.done&&te(m)&&!(m.kind===Qe&&!m.writes)&&!(m.waits&&x.some(S=>S.name===m.waits&&!S.done)),"counts"),a=s.filter(m=>!m.stalled).reduce((m,x)=>m+(x.agents||[]).filter((S,L,_)=>r(S,_)).length,0),u=s.filter(m=>Ao(m)&&!m.working).map(m=>m.key),d=s.filter(m=>n.includes(m.key)&&(u.includes(m.key)||m.buildable&&m.working)).map(m=>m.key),p=s.flatMap(m=>(m.agents||[]).filter(x=>x.kind===Qe&&!x.started&&!x.done).map(x=>({key:m.key,name:x.name,writes:x.writes}))),f=Math.max(0,t-a-d.length),g=p.filter(m=>m.writes),c=[...p.filter(m=>!m.writes),...g.slice(0,f)].map(({key:m,name:x})=>({key:m,name:x})),h=u.filter(m=>!d.includes(m)).slice(0,Math.max(0,f-g.length));return{idle:!a&&!s.some(m=>m.waitsOn==="checking"),pullable:u,waiting:d,pulls:h,helpers:c}}l(Ro,"pullOf");function is(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(u=>u.state==="OPEN"&&u.mergeable==="CONFLICTING"&&u.repo===s.repo&&u.headRefOid),a=r&&`${r.headRefOid}@${n}`;return r&&A(t,s.key)!==a?[{key:s.key,pr:r.number,branch:r.headRefName,conflict:a}]:[]})}l(is,"rebasesDue");const _o=3;function ds(e,{cap:t=_o}={}){const n=e.filter(a=>!pe(a)),s=n.filter(a=>(a.agents||[]).some(u=>ee(u)&&u.started&&!u.done)).length;return n.filter(a=>a.buildable&&!["ready","staging"].includes(a.state)&&!a.unsorted&&!a.blocked&&!a.held&&!a.working&&!a.grilling&&!a.prototyping&&!a.questions&&!(a.agents||[]).some(u=>ee(u)&&u.kind!==fe)).slice(0,Math.max(0,t-s)).map(a=>a.key)}l(ds,"arrivalsOf");function cs(e){return e.filter(t=>t.kind==="work"&&t.lane==="todo"&&t.roundAt&&["grilling","prototyping"].includes(t.state)&&!(t.agents||[]).some(n=>ee(n)&&n.kind!==fe&&n.started&&(String(n.started)>=String(t.roundAt)||!n.done))).map(t=>({key:t.key,kind:t.state==="grilling"?"grill":"prototype"}))}l(cs,"roundsDue");const Mo=l(e=>`${fe}-${e.id}`,"visualAgent");function us(e,t){const n=[];for(const s of e){const r=s.agents||[];if(r.some(d=>d.kind===fe&&d.started&&!d.done))continue;const a=new Set(r.map(d=>d.name)),u=t.find(d=>d.kind==="visual-request"&&d.data?.key===s.key&&!a.has(Mo(d)));u&&n.push({key:s.key,request:u})}return n}l(us,"visualsDue");const Ut=l(e=>e.kind==="ask"?`ask:${e.id}`:e.kind==="card-added"?e.data?.key??null:e.kind==="item-message"&&String(e.data?.key||"").startsWith("ask:")?e.data.key:null,"intakeKeyOf");function Wt(e,t,n){const s=e.get(n);return s?t.kind==="ask"?s.isNew:t.kind==="card-added"?s.kind==="work"&&s.unfiled:(s.ask?.owed||[]).includes(t.id):!1}l(Wt,"unsorted");function Ft(e,t){const n=new Map(e.map(r=>[r.key,r])),s=new Set(t.filter(r=>r.kind==="intake-handoff").map(r=>r.data?.event));return t.flatMap(r=>{const a=Ut(r);return a&&!s.has(r.id)&&Wt(n,r,a)?[{event:r.id,key:a,kind:r.kind}]:[]})}l(Ft,"intakeOpen");function ps(e,t,n){return Object.values(n).some(s=>!s.ended)?null:Ft(e,t).find(s=>!A(n,s.event))??null}l(ps,"intakeDue");const Io=ft;function fs(e,t){return Object.entries(e).filter(([,n])=>!n.ended&&t-Date.parse(n.at)>=Io).map(([n])=>n)}l(fs,"intakeHung");function gs(e,t,n){return Ft(e,t).filter(s=>A(n,s.event)?.ended)}l(gs,"intakeStranded");function qo(e,t){const n=new Map(e.map(r=>[r.key,r])),s=new Map(t.map(r=>[r.id,r]));for(const r of t.filter(a=>a.kind==="intake-handoff")){const a=s.get(r.data?.event),u=a&&Ut(a);!u||!Wt(n,a,u)||(n.get(u).orchestrator={kind:"intake",since:String(r.ts),picked:null,next:`Sort what intake triage handed you: ${r.data.text}`})}}l(qo,"intakeWaits");function Do(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
+ `)}l(Do,"todoOf");function ks(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
+ `);return{waiting:t.map(s=>s.key),seen:`${n}
7
9
  --
8
- ${Yn(e)}`}}i(bs,"triageOf");const zn=100,Jn=["key","kind","id","ref","title","lane","status","wave","waveTitle","fold","internal","ticket","ticketSource","linear","pr","prs","review","reviewers","risky","sortAt","threadCount","othersAt","hasNotes","questions","next","ask","action","actionButton","builder","working","waitsOn","reachedPhase","grilling","refusal","install","parent","children","related","waitsOnIt","blockedBy","ready","finishable","reopened","manualSteps","branch","worktree"],Os=i(e=>Object.fromEntries(Jn.filter(t=>t in e).map(t=>[t,e[t]])),"slimDone");function xs(e,t=zn){const n=new Set((e.waveBands||[]).flatMap(r=>r.keys)),o=new Set(e.items.filter(r=>r.lane!=="done").flatMap(r=>[...(r.deps||[]).map(a=>String(a).includes("/")?String(a):`${r.wave}/${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=>["done","merged","dropped"].includes(r.status)&&!n.has(r.key)&&!o.has(r.key)&&(!r.questions||r.questions.state==="resolved"))}i(xs,"archivedOf");const Zn=i(e=>e.startsWith("ask:")?`ask-${e.slice(4)}`:`item-${e}`,"pushTag");function $s(e){const t=i(a=>e.owner.filter(u=>u.topic===a&&u.state==="open").map(({id:u,question:p})=>({id:u,question:p})),"open"),n=[M.ready,M.merge],o=e.items.filter(a=>a.action).map(a=>{const u=Ke.has(a.action.kind)?t(a.questions.topic):[];return{tag:Zn(a.key),kind:a.action.kind,title:`${a.ref}: ${a.action.label}`,body:u[0]?.question||a.title,url:u.length?a.action.url:`#item=${encodeURIComponent(a.key)}`,now:!n.includes(a.action.kind),questions:u}}),r=e.needs.filter(a=>a.topic).map(a=>{const u=t(a.topic);return{tag:`topic-${a.topic}`,kind:M.questions,title:a.text,body:u[0]?.question||a.title,url:a.url,now:!0,questions:u}});return[...o,...r,...qt(e.reviews)]}i($s,"ownerActions");function As(e,t){const n=e.owner.find(a=>a.id===t),o=/^item:([^/:]+\/[^/]+)$/.exec(n?.topic||"")?.[1],r=o&&e.items.find(a=>a.key===o);return!r||r.kind!=="work"||r.lane==="done"||r.held||r.blockedBy.length||r.action||r.unpicked||r.pr||r.pushed||![null,"waiting"].includes(r.status)||r.agents.some(a=>!a.done)||e.owner.some(a=>a.topic===n.topic&&a.state==="open")?null:o}i(As,"startedByAnswer");function Es(e,{pulled:t=[]}={}){return!e.items.filter(r=>!z(r)).some(r=>r.waitsOn==="checking"||r.grilling||r.prototyping||(r.agents||[]).some(a=>!a.done))&&!e.working&&!Hn(e.items,{pulled:t}).waiting.length}i(Es,"strictlyIdle");const es="Fold the Implement message into the notes, then item set --state ready to start the build";function ts(e,t,{answeredAt:n,workingSince:o}){const r=i(g=>e.agents.some(c=>c.kind===g&&c.started&&!c.done),"running"),a=[e.progressSince,...e.agents.map(g=>g.done)].filter(Boolean).map(String).sort().pop()||null,u=t.ask?{kind:"ask",since:t.ask.at,next:`Answer the builder's ask: ${t.ask.text}`}:n?{kind:"answer",since:n,next:"Act on the owner's answer"}:e.implementAt?e.state==="ready"?null:{kind:"implement",since:e.implementAt,next:es}:Ke.has(e.action?.kind)?null:e.builder?.stalled?{kind:"stalled",since:e.builder.silentSince,next:"Find out why the builder went silent or stopped, then restart or finish its run"}:e.lane==="stale"&&e.inReviewSince?{kind:"stale",since:new Date(Date.parse(e.inReviewSince)+nt).toISOString(),next:"Find out why the review went stale and fix what you can: rebase, CI, comments, a silent reviewer"}:e.waitsOn==="checking"?t.unverified?{kind:"calls",since:t.statusAt,next:t.next||"Verify the builder's judgment calls"}:{kind:"checking",since:t.statusAt,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.refusal&&t.refusedAt?{kind:"refused",since:t.refusedAt,next:e.refusal}:e.next===ct&&a?{kind:"unowned",since:a,next:"Start a builder on it, or set its Next"}:null;if(!u?.since)return null;const p=String(u.since),f=[t.writes.find(g=>g>p),o].filter(Boolean).sort()[0]||null;return{kind:u.kind,since:p,picked:f,next:u.next}}i(ts,"orchestratorWaitOf");function Bs(e){return e.items.filter(t=>t.orchestrator).map(t=>({key:t.key,ref:t.ref,title:t.title,...t.orchestrator}))}i(Bs,"orchestratorWaits");const Rs=30*6e4,ns=15;function _s(e,{idle:t,now:n}){const o=n.toISOString(),r=e.last||o;return t?e.since?e.pushed||n-Date.parse(e.since)<ns*6e4?{state:{...e,last:r},push:!1}:{state:{last:o,since:e.since,pushed:!0},push:!0}:{state:{last:r,since:o},push:!1}:{state:{last:r},push:!1}}i(_s,"idleStep");function Is(e,t){const n=i(f=>String(f.closedAt||"")>t,"after"),o=e.filter(f=>f.kind==="work"&&f.lane==="done"&&!We(f)&&n(f)),r=new Map;for(const f of e)f.lineup&&r.set(f.lineup.slug,[...r.get(f.lineup.slug)||[],f]);const a=[...r.values()].filter(f=>f.every(g=>g.lane==="done")&&f.some(n)).map(f=>f[0].lineup.title),u=o.slice(0,3).map(f=>f.ref).join(", ")+(o.length>3?` and ${o.length-3} more`:"");return[o.length&&`${o.length} ${o.length===1?"card":"cards"} landed: ${u}`,...a.map(f=>`${f} finished`)].filter(Boolean).join(" \xB7 ")||"Nothing closed since the last idle notification."}i(Is,"idleSummary");export{M as ACTION_KIND,be as BUILDER_ASK,De as BUILDER_KIND,Ft as BUILDER_QUIET_AFTER,Ut as BUILDER_STALLED_AFTER,tt as BUILD_REFUSED,Y as BUTTON,Jn as DONE_FIELDS,zn as DONE_KEPT,ns as IDLE_MINUTES,jt as ITEM_EVENTS,fs as ITEM_STATUSES,Vn as MAX_IMPLEMENTERS,Xn as MAX_PLANNERS,ct as NO_NEXT,Rs as ORCHESTRATOR_PUSH_AFTER,yn as PLANNER_WORD,fn as PROTOTYPE_AGAIN,ms as PROTOTYPE_WAIT,re as PR_STATE,xs as archivedOf,vs as arrivalsOf,hs as buildBoard,J as builds,_s as idleStep,Is as idleSummary,ws as lineupMoved,Nn as lineupPhases,an as mergeBlockers,On as modelName,ys as needsAnswer,pn as noTakePicked,Bs as orchestratorWaits,gs as owesNext,$s as ownerActions,xn as ownerQuestion,un as picksNoTake,ae as plans,ks as prototypeWaits,pt as providerOf,Hn as pullOf,Zn as pushTag,Ss as rebasesDue,Fe as refOf,ge as roundOf,$n as roundSettledBy,Os as slimDone,As as startedByAnswer,Es as strictlyIdle,ht as threadIndex,yt as threadOf,Yn as todoOf,bs as triageOf,Gt as waveFold,Tn as withHub};
10
+ ${Do(e)}`}}l(ks,"triageOf");const No=100,Co=["key","kind","id","ref","title","lane","wave","waveTitle","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"],ms=l(e=>Object.fromEntries(Co.filter(t=>t in e).map(t=>[t,e[t]])),"slimDone");function ws(e,t=No){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.wave}/${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"))}l(ws,"archivedOf");function hs(e){return e.items.filter(t=>t.kind==="work").flatMap(t=>{const n=t.lane;return n===t.storedLane||n==="done"||t.storedLane==="done"&&!t.reopened?[]:[{key:t.key,to:n,why:To(t,n)}]})}l(hs,"movesOf");function To(e,t){return t==="todo"?e.held?"it is held":e.blocked?"it is blocked":"nothing builds it":e.reopened&&t==="progress"?"a message or question reopened it":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"}l(To,"moveWhy");const Lo=l(e=>e.startsWith("ask:")?`ask-${e.slice(4)}`:`item-${e}`,"pushTag");function ys(e){const t=l(a=>e.owner.filter(u=>u.topic===a&&u.state==="open").map(({id:u,question:d})=>({id:u,question:d})),"open"),n=[q.ready,q.merge],s=e.items.filter(a=>a.action).map(a=>{const u=st.has(a.action.kind)?t(a.questions.topic):[];return{tag:Lo(a.key),kind:a.action.kind,title:`${a.ref}: ${a.action.label}`,body:u[0]?.question||a.title,url:u.length?a.action.url:`#item=${encodeURIComponent(a.key)}`,now:!n.includes(a.action.kind),questions:u}}),r=e.needs.filter(a=>a.topic).map(a=>{const u=t(a.topic);return{tag:`topic-${a.topic}`,kind:q.questions,title:a.text,body:u[0]?.question||a.title,url:a.url,now:!0,questions:u}});return[...s,...r,...tn(e.reviews)]}l(ys,"ownerActions");function bs(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&&!Ro(e.items,{pulled:t}).waiting.length}l(bs,"strictlyIdle");const Kt="item stall it with the reason when it can't go on",Po="Judge the staged card: item set --state ready, or --state grilling or prototyping for another round";function jo(e,t,{answeredAt:n,workingSince:s}){const r=l(f=>e.agents.some(g=>g.kind===f&&g.started&&!g.done),"running"),a=[e.progressSince,...e.agents.map(f=>f.done)].filter(Boolean).map(String).sort().pop()||null,u=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:Po}:n?{kind:"answer",since:n,next:"Act on the owner's answer"}:st.has(e.action?.kind)?null:e.builder?.stopped?{kind:"stale",since:e.builder.silentSince,next:`${e.builder.stopped}: start it again when it should run, or drop the card`}:e.builder?.stale?{kind:"stale",since:e.builder.silentSince,next:`Find out why the builder went silent or stopped, then restart or finish its run, or ${Kt}`}:e.lane==="review"&&e.stale?{kind:"stale",since:new Date(Date.parse(e.inReviewSince)+kt).toISOString(),next:`Find out why the review went stale and fix what you can: rebase, CI, comments, a silent reviewer, or ${Kt}`}: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.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"}:null;if(!u?.since)return null;const d=String(u.since),p=[t.writes.find(f=>f>d),s].filter(Boolean).sort()[0]||null;return{kind:u.kind,since:d,picked:p,next:u.next}}l(jo,"orchestratorWaitOf");function Ss(e){return e.items.filter(t=>t.orchestrator).map(t=>({key:t.key,ref:t.ref,title:t.title,...t.orchestrator}))}l(Ss,"orchestratorWaits");const vs=30*6e4,Uo=15*6e4,Wo=60*6e4;function xs(e,t,n){const s=n.toISOString(),r=[],a=[];return{waits:t.map(d=>{const p=e.find(c=>c.key===d.key&&c.kind===d.kind&&c.since===d.since);if(!p)return d.picked||r.push(d.key),{...d,bumped:s};const f=d.picked?[d.picked,p.bumped].filter(Boolean).sort().pop():p.bumped||d.since,g=n-Date.parse(f)>=(d.picked?Wo:Uo);return g&&a.push({key:d.key,ref:d.ref,kind:d.kind,since:d.since,next:d.next}),{...d,bumped:g?s:p.bumped||d.since,...p.pushed?{pushed:!0}:{}}}),added:r,again:a}}l(xs,"waitsStep");function Os(e,t){const n=l(s=>{const r=Math.floor((t-Date.parse(s))/6e4),a=Math.floor(r/60),u=r%60;return a?`${a}h${u?` ${u}m`:""}`:`${u}m`},"age");return`still waiting on you: ${e.map(s=>`${s.ref} ${s.kind} for ${n(s.since)}: ${s.next}`).join("; ")}`}l(Os,"waitsAgainLine");const Fo=15;function $s(e,{idle:t,now:n}){const s=n.toISOString(),r=e.last||s;return t?e.since?e.pushed||n-Date.parse(e.since)<Fo*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}}l($s,"idleStep");function Es(e,t){const n=l(p=>String(p.closedAt||"")>t,"after"),s=e.filter(p=>p.kind==="work"&&p.lane==="done"&&!ht(p)&&n(p)),r=new Map;for(const p of e)p.lineup&&r.set(p.lineup.slug,[...r.get(p.lineup.slug)||[],p]);const a=[...r.values()].filter(p=>p.every(f=>f.lane==="done")&&p.some(n)).map(p=>p[0].lineup.title),u=s.slice(0,3).map(p=>p.ref).join(", ")+(s.length>3?` and ${s.length-3} more`:"");return[s.length&&`${s.length} ${s.length===1?"card":"cards"} landed: ${u}`,...a.map(p=>`${p} finished`)].filter(Boolean).join(" \xB7 ")||"Nothing closed since the last idle notification."}l(Es,"idleSummary");export{q as ACTION_KIND,Mt as ACTION_LABELS,so as ANSWERS_SUBMITTED,Ie as BUILDER_ASK,be as BUILDER_KIND,pn as BUILDER_QUIET_AFTER,ft as BUILDER_STALE_AFTER,gt as BUILD_REFUSED,oe as BUTTON,He as COMMANDS,Co as DONE_FIELDS,No as DONE_KEPT,Qe as HELPER,Fo as IDLE_MINUTES,Io as INTAKE_TIMEOUT_AFTER,It as INTENT_LABELS,un as ITEM_EVENTS,hn as LANDER,ts as LANES,Bo as MAX_IMPLEMENTERS,_o as MAX_PLANNERS,Se as MOVE,$t as NO_NEXT,vs as ORCHESTRATOR_PUSH_AFTER,Wo as PICKED_REWAKE_AFTER,Qn as PLANNER_WORD,Ln as PROTOTYPE_AGAIN,os as PROTOTYPE_WAIT,Z as PR_STATE,pt as QUESTION_REOPEN,Uo as REWAKE_AFTER,fe as VISUAL,ws as archivedOf,ds as arrivalsOf,as as buildBoard,te as builds,nt as handedBackAt,$s as idleStep,Es as idleSummary,ps as intakeDue,fs as intakeHung,Ut as intakeKeyOf,gs as intakeStranded,rs as lineupMoved,wo as lineupPhases,Mn as mergeBlockers,zn as modelName,hs as movesOf,ls as needsAnswer,Tn as noTakePicked,Vn as orchestratorDid,Ss as orchestratorWaits,ns as owesNext,ys as ownerActions,Jn as ownerQuestion,Cn as picksNoTake,ee as plans,ss as prototypeWaits,Bt as providerOf,Ro as pullOf,Lo as pushTag,is as rebasesDue,Ke as refOf,ge as roundOf,Zn as roundSettledBy,cs as roundsDue,ms as slimDone,De as stateEntries,Et as stoppedWords,bs as strictlyIdle,Ct as threadIndex,Tt as threadOf,Do as todoOf,ks as triageOf,ht as unlanded,Mo as visualAgent,us as visualsDue,Os as waitsAgainLine,xs as waitsStep,gn as waveFold,ho as withHub};
package/board/finish.mjs CHANGED
@@ -1,4 +1,4 @@
1
- var D=Object.defineProperty;var c=(t,a)=>D(t,"name",{value:a,configurable:!0});import H from"node:fs";import R from"node:path";import{spawnSync as I}from"node:child_process";import*as r from"./store.mjs";import{builderRepo as M,git as f,joiningLand as N,landInTurn as P,passTests as j,syncBase as v,worktreesDir as L}from"./worktree.mjs";import{readPermissions as q}from"./permissions.mjs";import{launchBuilder as F}from"./headless.mjs";import{boardAt as x}from"../hub/boards.mjs";import{boardRepo as A}from"../hub/board-repo.mjs";const T=c(t=>{throw new r.BoardError(t)},"fail"),W=c(t=>typeof t=="string"&&t.trim()?t.trim():T("--text must be non-empty text"),"said");async function B(t,a,{text:e,ownerStep:n,check:o,repo:i,onWait:s}){const h=a.split("/")[1],d=await r.recordedWorktree(t,a),{repo:p,base:l,remote:g}=M(t,{repo:i??d?.repo}),u={path:d?.path??R.join(L(),h),branch:d?.branch??h,repo:R.resolve(p),base:l},m=await r.cardName(t,a),w=await r.readBoardSettings(t),b=g?A(x(t).route).github:null;if(g&&(!b||w.prs))return z(t,a,{...u,ref:m,text:W(e)});const $=await N(m,()=>V(t,a,{tree:u,ref:m,base:l,remote:g,repo:p,settings:w,text:e,ownerStep:n,check:o,onWait:s}));return $.joined?await r.isFinished(t,a)?{said:"landed and done",lines:[]}:B(t,a,{text:e,ownerStep:n,check:o,repo:i,onWait:s}):$}c(B,"finishCard");async function V(t,a,{tree:e,ref:n,base:o,remote:i,repo:s,settings:h,text:d,ownerStep:p,check:l,onWait:g}){await r.checkClose(t,a,d,p,l),await r.checkCallsVerified(t,a),i&&(v(e.repo,o),f(e.repo,"branch","--unset-upstream",e.branch));const u=h.auto_merge||!!(await r.heldMerge(t,a))?.tapped;if(u&&await r.landingLine(t,a),await P({...e,ref:n},{hold:!u,onWait:g,sync:c(()=>i&&v(e.repo,o),"sync")}),!u){const w=await r.setItem(t,a,{mergeReady:e.branch,ownerStep:p,check:l});return await r.appendThread(t,a,{text:d}),{said:"verified; waits for your Merge",lines:w.lines}}const m=await r.setItem(t,a,{status:"done",text:d,ownerStep:p,check:l});return{said:p===void 0?"landed and done":`landed; waits on the owner step "${p.trim()}"`,lines:[...m.lines,...await _(t,a,s,o)]}}c(V,"landCard");async function S(t,a,{launch:e=F}={}){(await r.heldMerge(t,a))?.tapped||T(`${a} isn't waiting on a Merge tap`);try{const{base:o}=M(t,{repo:(await r.recordedWorktree(t,a))?.repo}),i=c(s=>r.appendThread(t,a,{text:`Waiting for ${s} to land`,kind:"status"}),"onWait");return await B(t,a,{text:`Landed on ${o} on your Merge.`,onWait:i})}catch(o){if(!(o instanceof r.BoardError))throw o;const i=o.message.split(`
2
- `)[0];if(/^rebasing .+ conflicts in |^tests failed in /.test(i)){await r.appendThread(t,a,{text:`Not merged yet: ${i}. A lander fixes it and lands it.`});try{await e(t,{key:a,model:await r.builderModel(t,a)},{lander:!0})}catch(s){await r.appendThread(t,a,{text:`Couldn't launch the lander headless (${s.message}); land it with board.mjs land ${a}.`})}}else await r.appendThread(t,a,{text:`Not merged: ${i}. Tap Merge again.`});throw o}}c(S,"landHeld");async function _(t,a,e,n){if(!(await q(e)).pushMain)return[];const o=f(e,"push","--quiet","origin",n);if(o.ok)return[`pushed ${n} to origin`];const i=`${n} didn't reach origin: ${o.err}; push it with git -C ${e} push origin ${n}`;return await r.appendThread(t,a,{text:`Landed, but ${i}`}),[`landed, but ${i}`]}c(_,"pushBase");async function z(t,a,{path:e,branch:n,base:o,ref:i,text:s}){await r.checkCallsVerified(t,a),H.existsSync(e)||T(`no worktree at ${e}`),f(e,"status","--porcelain").out&&T(`${e} has uncommitted changes; commit them there first`),Number(f(e,"rev-list","--count",`refs/remotes/origin/${o}..HEAD`).out)===0&&T(`${n} has no commits beyond ${o}; nothing to send for review`),await j(e,{outcome:"nothing was pushed"});const{github:h}=A(x(t).route),d=h?await r.cardPR(t,a):null,p=d?f(e,"rev-parse",`refs/remotes/origin/${n}`).out:null,l=d?f(e,"push","--quiet",`--force-with-lease=refs/heads/${n}:${p}`,"origin",`HEAD:refs/heads/${n}`):f(e,"push","--quiet","origin",`HEAD:refs/heads/${n}`);if(l.ok||T(`could not push ${n} to origin: ${l.err}`),d){const $=c(E=>Number(f(e,"rev-list","--count",`refs/remotes/origin/${o}..${E}`).out),"ahead");await r.recordRebase(t,a,{from:p,to:f(e,"rev-parse","HEAD").out,replayed:$("HEAD")<=$(p)});const C=await r.setItem(t,a,{pr:d});return await r.appendThread(t,a,{text:s}),{said:`pushed ${n} to PR #${d}`,lines:C.lines}}if(!h){const $=await r.setItem(t,a,{pushed:n});return await r.appendThread(t,a,{text:s}),{said:`pushed ${n} for its merge`,lines:$.lines}}const{title:g}=await r.briefFacts(t,a),u=I("gh",["pr","create","--draft","--repo",h,"--base",o,"--head",n,"--title",`${i}: ${g}`,"--body",s],{cwd:e,encoding:"utf8"}),m=`${u.stdout||""}
3
- ${u.stderr||""}`,w=(u.status===0||/already exists/.test(m))&&/\/pull\/(\d+)/.exec(m)?.[1];w||T(`could not open a draft PR for ${n}: ${(u.stderr||u.error?.message||`gh exited ${u.status}`).trim().split(`
4
- `)[0]}`);const b=await r.setItem(t,a,{pr:Number(w)});return await r.appendThread(t,a,{text:s}),{said:`draft PR #${w} opened`,lines:b.lines}}c(z,"sendForReview");export{B as finishCard,S as landHeld};
1
+ var D=Object.defineProperty;var l=(t,a)=>D(t,"name",{value:a,configurable:!0});import H from"node:fs";import M from"node:path";import{spawnSync as I}from"node:child_process";import*as r from"./store.mjs";import{builderRepo as v,git as h,joiningLand as N,landInTurn as P,passTests as j,syncBase as x,worktreesDir as q}from"./worktree.mjs";import{readPermissions as F}from"./permissions.mjs";import{launchBuilder as L}from"./headless.mjs";import{boardAt as A}from"../hub/boards.mjs";import{boardRepo as B}from"../hub/board-repo.mjs";const $=l(t=>{throw new r.BoardError(t)},"fail"),W=l(t=>typeof t=="string"&&t.trim()?t.trim():$("--text must be non-empty text"),"said");async function C(t,a,{text:n,ownerStep:e,check:o,repo:i,onWait:d,merge:m=!1}){const c=a.split("/")[1],u=await r.recordedWorktree(t,a),{repo:p,base:b,remote:s}=v(t,{repo:i??u?.repo}),w={path:u?.path??M.join(q(),c),branch:u?.branch??c,repo:M.resolve(p),base:b},f=await r.cardName(t,a),T=await r.readBoardSettings(t),g=s?B(A(t).route).github:null;if(s&&(!g||T.prs))return z(t,a,{...w,ref:f,text:W(n)});const R=await N(f,()=>V(t,a,{tree:w,ref:f,base:b,remote:s,repo:p,settings:T,text:n,ownerStep:e,check:o,onWait:d}),{merge:m});return R.joined?await r.isFinished(t,a)?{said:"landed and done",lines:[]}:C(t,a,{text:n,ownerStep:e,check:o,repo:i,onWait:d,merge:m}):R}l(C,"finishCard");async function V(t,a,{tree:n,ref:e,base:o,remote:i,repo:d,settings:m,text:c,ownerStep:u,check:p,onWait:b}){const s=m.auto_merge||!!(await r.heldMerge(t,a))?.tapped,w=s&&await r.blockWords(t,a);w&&$(`${e} is blocked ${w}, so it can't land; it lands once nothing blocks it`),await r.checkClose(t,a,c,u,p),await r.checkCallsVerified(t,a),i&&(x(n.repo,o),h(n.repo,"branch","--unset-upstream",n.branch)),s&&await r.landingLine(t,a);const f={site:t,key:a,first:await r.landFirst(t,a)};if(await P({...n,ref:e},{hold:!s,onWait:b,queue:f,sync:l(()=>i&&x(n.repo,o),"sync")}),!s){const g=await r.setItem(t,a,{mergeReady:n.branch,ownerStep:u,check:p});return await r.appendThread(t,a,{text:c}),{said:"verified; waits for your Merge",lines:g.lines}}const T=await r.setItem(t,a,{done:!0,text:c,ownerStep:u,check:p});return{said:u===void 0?"landed and done":`landed; waits on the owner step "${u.trim()}"`,lines:[...T.lines,...await _(t,a,d,o)]}}l(V,"landCard");async function S(t,a,{launch:n=L}={}){(await r.heldMerge(t,a))?.tapped||$(`${a} isn't waiting on a Merge tap`);try{const{base:o}=v(t,{repo:(await r.recordedWorktree(t,a))?.repo}),i=l(d=>r.appendThread(t,a,{text:`Waiting for ${d} to land`,kind:"status"}),"onWait");return await C(t,a,{text:`Landed on ${o} on your Merge.`,onWait:i,merge:!0})}catch(o){if(!(o instanceof r.BoardError))throw o;const i=o.message.split(`
2
+ `)[0];if(/^rebasing .+ conflicts in |^tests failed in /.test(i)){await r.appendThread(t,a,{text:`Not merged yet: ${i}. A lander fixes it and lands it.`});try{await n(t,{key:a,model:await r.builderModel(t,a)},{lander:!0})}catch(d){await r.appendThread(t,a,{text:`Couldn't launch the lander headless (${d.message}); land it with board.mjs land ${a}.`})}}else await r.appendThread(t,a,{text:`Not merged: ${i}. Tap Merge again.`});throw o}}l(S,"landHeld");async function _(t,a,n,e){if(!(await F(n)).pushMain)return[];const o=h(n,"push","--quiet","origin",e);if(o.ok)return[`pushed ${e} to origin`];const i=`${e} didn't reach origin: ${o.err}; push it with git -C ${n} push origin ${e}`;return await r.appendThread(t,a,{text:`Landed, but ${i}`}),[`landed, but ${i}`]}l(_,"pushBase");async function z(t,a,{path:n,branch:e,base:o,ref:i,text:d}){await r.checkCallsVerified(t,a),H.existsSync(n)||$(`no worktree at ${n}`),h(n,"status","--porcelain").out&&$(`${n} has uncommitted changes; commit them there first`),Number(h(n,"rev-list","--count",`refs/remotes/origin/${o}..HEAD`).out)===0&&$(`${e} has no commits beyond ${o}; nothing to send for review`),await j(n,{outcome:"nothing was pushed"});const{github:m}=B(A(t).route),c=m?await r.cardPR(t,a):null,u=c?h(n,"rev-parse",`refs/remotes/origin/${e}`).out:null,p=c?h(n,"push","--quiet",`--force-with-lease=refs/heads/${e}:${u}`,"origin",`HEAD:refs/heads/${e}`):h(n,"push","--quiet","origin",`HEAD:refs/heads/${e}`);if(p.ok||$(`could not push ${e} to origin: ${p.err}`),c){const g=l(E=>Number(h(n,"rev-list","--count",`refs/remotes/origin/${o}..${E}`).out),"ahead");await r.recordRebase(t,a,{from:u,to:h(n,"rev-parse","HEAD").out,replayed:g("HEAD")<=g(u)});const R=await r.setItem(t,a,{pr:c});return await r.appendThread(t,a,{text:d}),{said:`pushed ${e} to PR #${c}`,lines:R.lines}}if(!m){const g=await r.setItem(t,a,{pushed:e});return await r.appendThread(t,a,{text:d}),{said:`pushed ${e} for its merge`,lines:g.lines}}const{title:b}=await r.briefFacts(t,a),s=I("gh",["pr","create","--draft","--repo",m,"--base",o,"--head",e,"--title",`${i}: ${b}`,"--body",d],{cwd:n,encoding:"utf8"}),w=`${s.stdout||""}
3
+ ${s.stderr||""}`,f=(s.status===0||/already exists/.test(w))&&/\/pull\/(\d+)/.exec(w)?.[1];f||$(`could not open a draft PR for ${e}: ${(s.stderr||s.error?.message||`gh exited ${s.status}`).trim().split(`
4
+ `)[0]}`);const T=await r.setItem(t,a,{pr:Number(f)});return await r.appendThread(t,a,{text:d}),{said:`draft PR #${f} opened`,lines:T.lines}}l(z,"sendForReview");export{C as finishCard,S as landHeld};
@@ -1,5 +1,9 @@
1
- var P=Object.defineProperty;var d=(t,e)=>P(t,"name",{value:e,configurable:!0});import S from"node:os";import y from"node:path";import{fileURLToPath as A}from"node:url";import{launchAgent as B}from"./agents.mjs";import{processStarts as L}from"../hub/live.mjs";import{boardAt as O}from"../hub/boards.mjs";import{readHubRules as D}from"../hub/rules.mjs";import{builderRepo as M}from"./worktree.mjs";import{appendThread as Y,briefFacts as F,readBoardRules as _,recordSession as E}from"./store.mjs";import{modelName as U,plans as H}from"./domain.mjs";const G=A(new URL("./bin/board.mjs",import.meta.url)),b=d(t=>`node ${G} --site ${t}`,"cli"),I=d(t=>`git -c core.commentChar=';' rebase ${t}`,"rebase"),T=d((t,e="Rules from the hub and this board:")=>t.length?[e,...t.map(n=>`- ${n}`),""]:[],"ruleLines"),q=d(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.status}): ${e.notes||"no notes"}`),""]:[],"linkLines"),j=d(({route:t,key:e,worktree:n,base:h})=>[`- With no unverified calls, done finishes the card itself: it rebases onto ${h}, reruns the full test suite, fast-forwards ${h} 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 \`${I(h)}\` in ${n}, 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.",`- Finishing never goes to the orchestrator. If done refuses for a reason you can't fix, record it with \`${b(t)} builder call ${e} "<why>"\` and run done again: with the call it hands the card back.`],"finishSteps"),R=d(({route:t,key:e})=>`\`${b(t)} builder done ${e} --text "<what you checked>"\``,"finishCommand");function K({route:t,key:e,ref:n,title:h,notes:i,worktree:s,base:a,rules:o=[],links:r=[]}){const l=b(t);return[`You are the headless builder for card ${n} (${e}, "${h}") on the kickflip board /${t}. The board launched you; nobody watches this session, so never wait on a person. Work only in ${s}. Never restart the hub or a board server, and never push.`,"",`1. Run \`${l} builder start ${e} --kind build\`. If it refuses, stop.`,`2. Report progress with \`${l} 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. To ask the orchestrator something, run \`${l} builder ask ${e} "<question>"\` and carry on; read its replies with \`${l} builder asks ${e}\`. Never block on a reply.`,`4. Record each judgment call the notes leave open with \`${l} builder call ${e} "<call>"\` instead of guessing silently.`,"",i?`Spec: the card's notes, ${i}, 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.","",...q(r),...T(o),"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 "${n}: <what the card now does>".`,"",`To finish, run ${R({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.",...j({route:t,key:e,worktree:s,base:a}),"","Never push."].join(`
2
- `)}d(K,"builderBrief");function X({route:t,key:e,ref:n,title:h,worktree:i,base:s,answers:a=[]}){const o=b(t);return[`You are the headless lander for card ${n} (${e}, "${h}") 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 ${i}, never restart the hub or a board server, and never push.`,"",`1. Run \`${o} builder start ${e} --kind build --label Lander --phase landing --progress "taking up the verified build"\`. If it refuses, stop.`,`2. Report progress with \`${o} builder progress ${e} --phase landing "<plain, 80 characters or fewer>"\`. The board adds the phase word; don't start the text with it.`,...a.length?["3. The owner answered the builder's deferred asks. Where an answer changes the build, change it, with its tests, and commit:",...a.map(r=>`- ${r.ask} "${r.question}": ${r.answer}`)]:[],"",`To finish, run ${R({route:t,key:e})}.`,...j({route:t,key:e,worktree:i,base:s}),"","Never push."].join(`
3
- `)}d(X,"landerBrief");function z({route:t,key:e,ref:n,title:h,worktree:i,base:s,pr:a}){const o=b(t);return[`You are the headless rebase run for card ${n} (${e}, "${h}") on the kickflip board /${t}. Its PR #${a} conflicts with ${s}; rebase its branch onto ${s} so the PR is clean again. Nobody watches this session, so never wait on a person. Work only in ${i}, never restart the hub or a board server, and never push.`,"",`1. Run \`${o} builder start ${e} --kind build --label Rebase --phase building --progress "Rebase run started \xB7 fetching ${s}"\`. If it refuses, stop.`,`2. Run \`git fetch origin\`, then \`${I(`origin/${s}`)}\`. Resolve each conflict keeping both sides' intent, \`git add\` it and continue with \`git -c core.commentChar=';' rebase --continue\`. Report each step with \`${o} builder progress ${e} --phase building "<line>"\`, the board adds the phase word, in these words: "Rebasing onto ${s} \xB7 resolving <n> files", then "Rebasing onto ${s} \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 \`${o} 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.`,"",`To finish, run ${R({route:t,key:e})}, the text saying what you resolved. It reruns the suite and pushes the branch to PR #${a} 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
- `)}d(z,"rebaseBrief");function J({route:t,key:e,ref:n,title:h,notes:i,kind:s,repo:a,rules:o=[],links:r=[],text:l,files:p=[],question:f,note:m,choice:$}){const c=b(t),u=s==="grill";return[`You are the headless ${u?"grill":"prototype"} planner for card ${n} (${e}, "${h}") 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 ${a}; write no output code there, never restart the hub or a board server, and never push.`,"",`1. Run \`${c} builder start ${e} --kind ${s}\`. If it refuses, stop.`,`2. Gather the context yourself: ${i?`the card's notes, ${i}, all sections, where later sections override earlier ones; `:"the card has no notes file yet; "}its thread, in the board site's data/threads folder, the repo's docs/adr and CONTEXT.md, and the cards its notes and thread link.`,`3. Report progress with \`${c} builder progress ${e} "<plain, 80 characters or fewer>"\` at least every 10 minutes.`,u?`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 \`${c} question add --file <json>\` on topic item:${e}, one per decision, your recommendation first. 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.) 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: the board moves the card to prototyping on yes, or to ready on no once the owner has answered the rest, 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. Record the prototype with \`${c} prototype add <topic> --card ${e} --take <K>:<label> \u2026\`, write one take per option as a page built from the board's real components fed fake data, and post one question whose url opens it with \`${c} question add --file <json>\` on topic item:${e}, never asking in the chat. Invoke the prototype skill with the Skill tool for this step. (With no Skill tool, follow this step as written.)`,...l?[` The owner asked for this ${u?"grill":"prototype"}, writing: "${l}"`]:[],...p.length?[` The owner attached: ${p.map(g=>g.path).join(", ")}.`]:[],...f?[` The owner asked for prototypes of question ${f}${m?`, noting "${m}"`:""}${$?`, leaning to option ${$}`:""}: draw that question's next round, its question naming round_of ${f}.`]:[],`5. Record what you learned in the card's notes with \`${c} item set ${e} --notes-file <file.md>\`, naming each answered question's id.`,...u?[`6. Where the owner asked for prototypes, or a rule here wants a UI prototype first, end the card \`${c} item set ${e} --state 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.`]:[],"",...q(r),...T(o,"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 \`${c} builder done ${e} --text "<what you asked>"\`.`,"","Never push."].join(`
5
- `)}d(J,"plannerBrief");const Q=6e4;function ce(t,{starts:e=L,kill:n=d((i,s)=>process.kill(-i,s),"kill"),killAfter:h=5e3}={}){const i=t.filter(o=>o.pid&&o.at).map(o=>o.pid),s=i.length&&e(i)||new Map,a=t.filter(o=>{const r=s.get(o.pid);return r!==void 0&&r<=Date.parse(o.at)&&r>=Date.parse(o.at)-Q});for(const{pid:o}of a){try{n(o,"SIGTERM")}catch{continue}setTimeout(()=>{try{n(o,"SIGKILL")}catch{}},h).unref()}return a.length}d(ce,"stopAgents");const V=d(t=>{try{return process.kill(t,0),!0}catch(e){return e.code==="EPERM"}},"pidAlive");async function ue(t,e,{launch:n,handBack:h,alive:i=V,held:s=d(()=>!1,"held")}){const a={};for(const[o,r]of Object.entries(t)){if(!e.has(o))continue;if(r.pid!==null&&i(r.pid)||s(r.kind??"claude")||r.handedBack){a[o]=r;continue}const l={key:o,...r.kind?{kind:r.kind}:{},...r.model?{model:r.model}:{}};if(r.pid!==null&&r.relaunched){await h(l),a[o]={...r,handedBack:!0};continue}const{key:p,...f}=l;a[o]={...f,...await n(l),relaunched:r.pid!==null}}return a}d(ue,"reviveBuilders");const Z=d((t,e)=>y.join(S.homedir(),".claude","kickflip","logs",`${e}-${t}-${new Date().toISOString().replace(/[:.]/g,"-")}.log`),"logFile");async function pe(t,{key:e,kind:n="claude",model:h,text:i,files:s,question:a,note:o,choice:r},{lander:l=!1}={}){const p=await F(t,e),f=O(t)?.route??y.basename(t),m=[...D(),...await _(t)].map(C=>C.text),{base:$,repo:c}=M(t),u=H({kind:n}),g=!u&&!l&&p.rebasePR!==null,v={...p,route:f,base:$,repo:c,rules:m,kind:n,text:i,files:s,question:a,note:o,choice:r,pr:p.rebasePR},k=u?"Planner":l?"Lander":g?"Rebase run":"Builder",x=u?c:p.worktree,N=u?J(v):l?X(v):g?z(v):K(v),w=await B({kind:u?"claude":n,model:h,cwd:x,site:t,prompt:N,log:Z(e.split("/")[1],k.split(" ")[0].toLowerCase())});w.sessionId&&await E(t,e,w.sessionId,w.pid);const W=w.sessionId?`, session ${w.sessionId}`:"";return await Y(t,e,{text:`${k} launched on ${U({kind:n,model:h})} in ${x}${W}.`,log:y.basename(w.log)}),w}d(pe,"launchBuilder");export{G as BOARD_CLI,K as builderBrief,X as landerBrief,pe as launchBuilder,V as pidAlive,J as plannerBrief,z as rebaseBrief,ue as reviveBuilders,ce as stopAgents};
1
+ var _=Object.defineProperty;var l=(t,e)=>_(t,"name",{value:e,configurable:!0});import V from"node:os";import x from"node:path";import{fileURLToPath as z}from"node:url";import{launchAgent as B}from"./agents.mjs";import{processStarts as L,ps as X}from"../hub/live.mjs";import{boardAt as P}from"../hub/boards.mjs";import{readHubRules as C}from"../hub/rules.mjs";import{builderRepo as M}from"./worktree.mjs";import{BoardError as J,appendThread as Q,briefFacts as Z,readBoardRules as Y,recordSession as ee}from"./store.mjs";import{HELPER as te,modelName as oe,plans as re,VISUAL as ne}from"./domain.mjs";const ae=z(new URL("./bin/board.mjs",import.meta.url)),b=l(t=>`node ${ae} --site ${t}`,"cli"),O=l(t=>`git -c core.commentChar=';' rebase ${t}`,"rebase"),E="a draft .md of your own outside the board's data folder (such as in /tmp)",j=l((t,e,a)=>`\`${t} item notes ${e} --heading "${a}" --file <draft.md>\``,"notesCommand"),T=l((t,e="Rules from the hub and this board:")=>t.length?[e,...t.map(a=>`- ${a}`),""]:[],"ruleLines"),N=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||"no notes"}`),""]:[],"linkLines"),F=l(({route:t,key:e,worktree:a,base:d})=>[`- With no unverified calls, done finishes the card itself: it rebases onto ${d}, reruns the full test suite, fast-forwards ${d} 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 \`${O(d)}\` in ${a}, 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 \`${b(t)} builder call ${e} "<why>"\` and run done again: with the call it hands the card back.`],"finishSteps"),S=l(({route:t,key:e})=>`\`${b(t)} builder done ${e} --text "<what you checked>"\``,"finishCommand"),se=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 ie({route:t,key:e,ref:a,title:d,notes:n,worktree:r,base:s,rules:u=[],links:p=[]}){const f=b(t);return[`You are the headless builder for card ${a} (${e}, "${d}") on the kickflip board /${t}. The board launched you; nobody watches this session, so never wait on a person. Work only in ${r}. Never restart the hub or a board server, and never push.`,"",`1. Run \`${f} builder start ${e} --kind build\`. If it refuses, stop.`,`2. Report progress with \`${f} 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. To ask the orchestrator something, run \`${f} builder ask ${e} "<question>"\` and carry on; read its replies with \`${f} builder asks ${e}\`. Never block on a reply.`,`4. Record each judgment call the notes leave open with \`${f} builder call ${e} "<call>"\` instead of guessing silently.`,...se(f,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.","",...N(p),...T(u),"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 "${a}: <what the card now does>".`,"",`To finish, run ${S({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.",...F({route:t,key:e,worktree:r,base:s}),"","Never push."].join(`
2
+ `)}l(ie,"builderBrief");function he({route:t,key:e,ref:a,title:d,worktree:n,base:r,answers:s=[]}){const u=b(t);return[`You are the headless lander for card ${a} (${e}, "${d}") 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 ${n}, never restart the hub or a board server, and never push.`,"",`1. Run \`${u} builder start ${e} --kind build --label Lander --phase landing --progress "taking up the verified build"\`. If it refuses, stop.`,`2. Report progress with \`${u} builder progress ${e} --phase landing "<plain, 80 characters or fewer>"\`. The board adds the phase word; don't start the text with it.`,...s.length?["3. The owner answered the builder's deferred asks. Where an answer changes the build, change it, with its tests, and commit:",...s.map(p=>`- ${p.ask} "${p.question}": ${p.answer}`)]:[],"",`To finish, run ${S({route:t,key:e})}.`,...F({route:t,key:e,worktree:n,base:r}),"","Never push."].join(`
3
+ `)}l(he,"landerBrief");function de({route:t,key:e,ref:a,title:d,worktree:n,base:r,pr:s}){const u=b(t);return[`You are the headless rebase run for card ${a} (${e}, "${d}") on the kickflip board /${t}. Its PR #${s} conflicts with ${r}; rebase its branch onto ${r} so the PR is clean again. Nobody watches this session, so never wait on a person. Work only in ${n}, never restart the hub or a board server, and never push.`,"",`1. Run \`${u} builder start ${e} --kind build --label Rebase --phase building --progress "Rebase run started \xB7 fetching ${r}"\`. If it refuses, stop.`,`2. Run \`git fetch origin\`, then \`${O(`origin/${r}`)}\`. Resolve each conflict keeping both sides' intent, \`git add\` it and continue with \`git -c core.commentChar=';' rebase --continue\`. Report each step with \`${u} builder progress ${e} --phase building "<line>"\`, the board adds the phase word, in these words: "Rebasing onto ${r} \xB7 resolving <n> files", then "Rebasing onto ${r} \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 \`${u} 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.`,"",`To finish, run ${S({route:t,key:e})}, the text saying what you resolved. It reruns the suite and pushes the branch to PR #${s} 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(de,"rebaseBrief");function le({route:t,key:e,ref:a,title:d,notes:n,kind:r,repo:s,rules:u=[],links:p=[],text:f,files:o=[],question:i,note:h,choice:m}){const c=b(t),g=r==="grill";return[`You are the headless ${g?"grill":"prototype"} planner for card ${a} (${e}, "${d}") 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 ${s}; write no output code ${g?"there":`in ${s} itself`}, never restart the hub or a board server, and never push.`,"",`1. Run \`${c} builder start ${e} --kind ${r}\`. 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, in the board site's data/threads folder, the repo's docs/adr and CONTEXT.md, and the cards its notes and thread link.`,`3. Report progress with \`${c} 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 \`${c} question add --file <json>\` on topic item:${e}, one per decision, your recommendation first. 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.) 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: the board moves the card to prototyping on yes, or to staging on no once the owner has answered the rest, 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. Build the round in situ, in the board's base prototype worktree: run \`${c} 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 \`${c} 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 \`${c} question add --file <json>\` on topic item:${e}, never asking in the chat. Only a repo whose app can't be served as a web page keeps take files: \`${c} prototype add <topic> --card ${e} --take <K>:<label> \u2026\`, one take file per option built from the board's real components fed fake data. Invoke the prototype skill with the Skill tool for this step. (With no Skill tool, follow this step as written.)`,...f?[` The owner asked for this ${g?"grill":"prototype"}, writing: "${f}"`]:[],...o.length?[` The owner attached: ${o.map($=>$.path).join(", ")}.`]:[],...i?[` The owner asked for prototypes of question ${i}${h?`, noting "${h}"`:""}${m?`, leaning to option ${m}`:""}: draw that question's next round, its question naming round_of ${i}.`]:[],`5. Record what you learned in the card's notes, naming each answered question's id: write it in ${E}, then run ${j(c,e,`${g?"Grill":"Prototype"} (<MM/DD>)`)}, which appends it as a section. The notes file is read-only; never write into it.`,...g?[`6. Where the owner asked for prototypes, or a rule here wants a UI prototype first, end the card \`${c} item set ${e} --state 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.`]:[],"",...N(p),...T(u,"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 \`${c} builder done ${e} --text "<what you asked>"\`.`,"","Never push."].join(`
5
+ `)}l(le,"plannerBrief");function ce({route:t,key:e,ref:a,title:d,notes:n,repo:r,agent:s,rules:u=[],links:p=[],text:f,files:o=[]}){const i=b(t);return[`You are the headless visual agent for card ${a} (${e}, "${d}") 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 ${r}; write no code there, never restart the hub or a board server, and never push.`,"",`1. Run \`${i} builder start ${e} --kind visual --agent ${s}\`. If it refuses, stop.`,`2. Gather what the page needs: ${n?`the card's notes, ${n}; `:""}its thread, in the board site's data/threads folder, and the code or docs it is about.`,f?` The owner wrote: "${f}"`:" The owner typed nothing: draw what the thread was last discussing.",...o.length?[` The owner attached: ${o.map(h=>h.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 \`${i} 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.","",...N(p),...T(u,"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 \`${i} builder done ${e} --agent ${s}\`.`,"","Never push."].join(`
6
+ `)}l(ce,"visualBrief");function ue({route:t,key:e,ref:a,title:d,notes:n,agent:r,task:s,writes:u,cwd:p,rules:f=[],links:o=[]}){const i=b(t);return[`You are the headless helper ${r} on card ${a} (${e}, "${d}") 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.`,u?`Work only in ${p}, your own worktree, branched from the card's: commit your work there with \`git -c core.commentChar=';' commit -F <file>\`, the subject "${a}: <what it does>". The card's builder merges your branch, so leave nothing uncommitted.`:`Read and run in ${p}; change no files there and commit nothing.`,"","The task:",s,"",`1. Run \`${i} builder start ${e} --kind helper --agent ${r}\`. If it refuses, stop.`,`2. Report progress with \`${i} builder progress ${e} --agent ${r} --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}.`:"","",...N(o),...T(f,"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 \`${i} builder done ${e} --agent ${r} --text "<your hand-back: what you did or found, ${u?"what you committed, ":""}and any decision you made>"\`.`,"","Never push."].filter((h,m,c)=>h!==""||c[m-1]!=="").join(`
7
+ `)}l(ue,"helperBrief");function pe({route:t,repo:e,rules:a=[],waves:d=[],cards:n=[],event:r,key:s,kind:u,quick:p=!1,thread:f=[]}){const o=b(t),i=f.map(w=>`- ${w.who}: ${w.text}${w.files?.length?` (attached: ${w.files.map(k=>k.path).join(", ")})`:""}`),h=p?"--state staging --size <small|large>":"--state <grilling|prototyping>",m=p?" The owner chose Implement: put the plan in the notes; the orchestrator judges it from staging before it goes ready.":" --state prototyping when it changes the hub's or a board's UI, --state grilling for anything else; the board starts the grill or prototype itself.",c=l(w=>[` 1. Write its notes in ${E}: open with the owner's words verbatim, under "## Asked (owner, <date>)", then a short "## What it is" in plain words and a "## Related" line naming each linked card and how they overlap. Add that line to each linked card's notes with ${j(o,"<linked key>","Related")} on a draft of its own.`,` 2. ${w}`,m],"fileIt"),g=l(w=>`\`${o} item add <wave> --title "${w}" --notes-from <draft.md>\``,"add"),$={ask:[`Your job: sort new task ${r}, on card ${s}, one of these ways:`,`- Answer it, when it is a question or asks for nothing to build: \`${o} reply ${r} --file <reply.html>\`.`,`- Fold it into the open card it is about: \`${o} item relate-ask ${r} <key> --summary "<one line>"\`, then add the owner's words verbatim to that card's notes with ${j(o,"<key>","Asked (owner, <date>)")}.`,`- File it as a new card, its notes drafted first (step 1): ${g("<the change, in plain words>")} prints "<label> added as <key>"; use that key.`,...c(`\`${o} item set <key> --from-ask ${r} --relate <keys> --text "<one line on what you filed>" ${h}\` (link every card it overlaps, depends on or would duplicate; --deps for one it truly waits on).`)],"item-message":[`Your job: the owner's message ${r} in the thread of new task ${s}, whose last line is theirs. Answer it with \`${o} reply ${r} --file <reply.html>\`, or, if it changes what the task asks, sort the task as the message now has it:`,`- fold it: \`${o} item relate-ask ${s.slice(4)} <key> --summary "<one line>"\`; or file it: ${g("<the change>")}, with its notes drafted as in step 1, then`,...c(`\`${o} item set <key> --from-ask ${s.slice(4)} --relate <keys> --text "<one line>" ${h}\`,`)," then reply to the message saying what you did."],"card-added":[`Your job: card ${s}, which an agent added unfiled (card-added ${r}). Read its notes and the cards its title looks related to, add what it is, why and where it came from to its notes with ${j(o,s,"What it is")}, and a "Related" section naming each linked card to it and to each linked card's notes the same way, each from a draft of its own. Then file it in one call:`,`\`${o} item set ${s} --relate <keys> --text "<one line>" --state <grilling|prototyping>\`: prototyping when it changes the hub's or a board's UI, grilling for anything else.`]};return[`You are an intake triage run on the kickflip board /${t}. The board launched you to sort one thing that reached it unsorted; nobody watches this session, so never wait on a person. Work in ${e}, reading only: you write only through the board's CLI, \`${o} <command>\`, notes included. Never set a card ready, never build, never push, and never restart the hub or a board server.`,"",...$[u],"",`If you can't tell how to sort it (which card it belongs to, or what it asks), don't guess: \`${o} intake handoff ${r} --text "<what you are unsure of>"\` hands it to the orchestrator, and stop.`,"Each command writes its own line in the thread, which is your report; add one with `"+o+" thread "+s+' --text "<line>"` only for what those lines leave unsaid. Every line stands alone: name cards by their label.',"",`The thread of ${s}:`,...i.length?i:["- (no messages)"],"",`The board's open cards, as label key "title", lane, state: notes file. Read the notes of any card whose title looks related before you choose.`,...n.length?n.map(w=>`- ${w.ref} ${w.key} "${w.title}", ${w.lane}, ${w.state||"no state"}: ${w.notes||"no notes"}`):["- (none)"],"","Waves a new card can go in, as slug: folder:",...d.map(w=>`- ${w.slug}: ${w.dir}`),"",...T(a,"Rules from the hub and this board, written for the orchestrator: where one tells you to push, land, build or restart, it isn't yours:"),"Sort that one thing, then exit. Never push."].join(`
8
+ `)}l(pe,"intakeBrief");async function je(t,e){const a=P(t)?.route??x.basename(t),d=[...C(),...await Y(t)].map(s=>s.text),{repo:n}=M(t),r=await B({kind:"claude",model:"sonnet",cwd:n,site:t,prompt:pe({...e,route:a,repo:n,rules:d}),log:H(e.event,"intake")});return await Q(t,e.key,{text:`${oe({kind:"claude",model:"sonnet"})} intake triage`,kind:"status",log:x.basename(r.log)}),r}l(je,"launchIntake");const fe=6e4;function we(t,{starts:e=L}={}){const a=t.filter(n=>n.pid&&n.at).map(n=>n.pid),d=a.length&&e(a)||new Map;return t.filter(n=>{const r=d.get(n.pid);return r!==void 0&&r<=Date.parse(n.at)&&r>=Date.parse(n.at)-fe})}l(we,"launchedAgents");function Ne(t,{starts:e=L,kill:a=l((n,r)=>process.kill(-n,r),"kill"),killAfter:d=5e3}={}){const n=we(t,{starts:e});for(const{pid:r}of n){try{a(r,"SIGTERM")}catch{continue}setTimeout(()=>{try{a(r,"SIGKILL")}catch{}},d).unref()}return n.length}l(Ne,"stopAgents");async function Se(t,{grace:e=5e3}={}){const a=X(["-A","-o","pid=,ppid=,pgid=,args="]);if(a===null)throw new J("ps gave no answer, so nothing was stopped; run it again");const d=a.split(`
9
+ `).map(o=>/^\s*(\d+)\s+(\d+)\s+(\d+)\s+(.*)$/.exec(o)).filter(Boolean).map(([,o,i,h,m])=>({pid:Number(o),ppid:Number(i),pgid:Number(h),args:m})),n=new Set(d.filter(o=>t.includes(o.pgid)).map(o=>o.pid));for(let o=!0;o;){o=!1;for(const i of d)!n.has(i.pid)&&n.has(i.ppid)&&(n.add(i.pid),o=!0)}const r=d.find(o=>o.pid===process.pid)?.pgid,s=d.filter(o=>n.has(o.pid)&&o.pgid>1&&o.pgid!==r),u=[...new Set(s.map(o=>o.pgid))],p=l(o=>{for(const i of u)try{process.kill(-i,o)}catch{}},"signal");p("SIGTERM");const f=Date.now()+e;for(;s.some(o=>A(o.pid))&&Date.now()<f;)await new Promise(o=>setTimeout(o,50));return s.some(o=>A(o.pid))&&p("SIGKILL"),s.map(({pid:o,args:i})=>({pid:o,args:i}))}l(Se,"stopRuns");const A=l(t=>{try{return process.kill(t,0),!0}catch(e){return e.code==="EPERM"}},"pidAlive");async function Ae(t,e,{launch:a,handBack:d,alive:n=A,held:r=l(()=>!1,"held"),stopped:s=new Set,limitedUntil:u=l(()=>null,"limitedUntil"),atLimit:p=l(async()=>{},"atLimit"),now:f=Date.now()}){const o={};for(const[i,h]of Object.entries(t)){if(!e.has(i))continue;if(s.has(i)){o[i]={...h,handedBack:!0};continue}if(h.pid!==null&&n(h.pid)||h.handedBack){o[i]=h;continue}const m={key:i,...h.kind?{kind:h.kind}:{},...h.model?{model:h.model}:{}},c=h.pid!==null?u(h):null;if(c){await p(m,c),o[i]={...h,pid:null,until:c};continue}if(r(h.kind??"claude")||h.until&&f<Date.parse(h.until)){o[i]=h;continue}if(h.pid!==null&&h.relaunched){await d(m),o[i]={...h,handedBack:!0};continue}const{key:g,...$}=m;o[i]={...$,...await a(m),relaunched:h.pid!==null||!!h.relaunched}}return o}l(Ae,"reviveBuilders");const H=l((t,e)=>x.join(V.homedir(),".claude","kickflip","logs",`${e}-${t}-${new Date().toISOString().replace(/[:.]/g,"-")}.log`),"logFile");async function We(t,{key:e,kind:a="claude",model:d,agent:n="main",text:r,files:s,question:u,note:p,choice:f,task:o,writes:i,worktree:h},{lander:m=!1}={}){const c=await Z(t,e),g=P(t)?.route??x.basename(t),$=[...C(),...await Y(t)].map(K=>K.text),{base:w,repo:k}=M(t),v=re({kind:a}),R=a===te,W=!v&&!R&&!m&&c.rebasePR!==null,q=a===ne,D=v?k:R?h??c.worktree??k:c.worktree,y={...c,route:g,base:w,repo:k,rules:$,kind:a,agent:n,text:r,files:s,question:u,note:p,choice:f,task:o,writes:i,cwd:D,pr:c.rebasePR},U=q?"Visual agent":R?`Helper ${n}`:v?"Planner":m?"Lander":W?"Rebase run":"Builder",G=q?ce(y):R?ue(y):v?le(y):m?he(y):W?de(y):ie(y),I=await B({kind:v||R?"claude":a,model:d,cwd:D,site:t,prompt:G,log:H(e.split("/")[1],U.split(" ")[0].toLowerCase())});return await ee(t,e,I.sessionId,I.pid,n,x.basename(I.log)),I}l(We,"launchBuilder");export{ae as BOARD_CLI,ie as builderBrief,ue as helperBrief,pe as intakeBrief,he as landerBrief,We as launchBuilder,je as launchIntake,we as launchedAgents,A as pidAlive,le as plannerBrief,de as rebaseBrief,Ae as reviveBuilders,Ne as stopAgents,Se as stopRuns,ce as visualBrief};
@@ -0,0 +1,11 @@
1
+ var h=Object.defineProperty;var o=(e,i)=>h(e,"name",{value:i,configurable:!0});import l from"node:fs";import d from"node:path";import{execFileSync as c}from"node:child_process";const p="# Prepare .kickflip/build\n\nThe hub builds and serves a card's version of this repo by running one script, `.kickflip/build <wave>/<id> <worktree>`, in the card's worktree. This board has none on main yet.\n\nContract (docs/adr/2026-11-01-1846-a-boards-build-script-serves-or-builds-each-card-and-main.md):\n- Print exactly `port <n>` on stdout to serve a website on that port.\n- Or exit 0 with no port for an app build, publishing the install with `board.mjs item set --install --install-sha`.\n- The file is a regular file in the repo, executable, writable by no one but its owner.\n\nWhat this card does:\n- Look at the repo for what it builds: a website or server, an iOS or Android app, a CLI, a library with nothing to serve.\n- If it finds one type, write `.kickflip/build` for it.\n- If it finds several, ask the owner which the board should serve, write one `.kickflip/build-<target>` for each type the owner wants (for example `build-web`, `build-ios`), and set this board's Build target in Board Settings to the one picked.\n- If nothing here builds, say so and write nothing.\n",u=`# Write CONTEXT.md and the first ADR
2
+
3
+ Cards in this repo are grilled and built against its own words and decisions. This card writes them down.
4
+
5
+ What this card does:
6
+ - Write CONTEXT.md at the repo root: a glossary of the terms this project uses, one entry each with what it means and what to avoid calling it.
7
+ - Write the first ADR in docs/adr/, named docs/adr/YYYY-MM-DD-HHMM-<slug>.md, for the biggest decision the repo's shape shows: what was chosen and what was considered.
8
+ - Ask the owner what the project is for and which words they use for its parts; their wording goes in verbatim.
9
+ - If the repo already has a CONTEXT.md or ADRs, extend them rather than start again.
10
+ `,b=[{id:"onboard-build",title:"Prepare .kickflip/build",notes:p,needsNoBuild:!0},{id:"onboard-context",title:"Write the repo's CONTEXT.md glossary and first ADR",notes:u}];function T(e,i){try{return c("git",["-C",e,"ls-tree",`${i}:.kickflip`],{encoding:"utf8",stdio:["ignore","pipe","ignore"],timeout:3e3}).split(`
11
+ `).some(r=>/^100755 blob \S+\tbuild(-.+)?$/.test(r))}catch{return!1}}o(T,"hasBuildScript");function y(e,{prefix:i="INT",hasBuild:s,now:r=new Date}){return b.filter(t=>!(t.needsNoBuild&&s)).map((t,a)=>{const n=`${t.id}-notes.md`;return l.writeFileSync(d.join(d.dirname(e),n),t.notes),{id:t.id,title:t.title,created:new Date(r.getTime()+a).toISOString(),state:"grilling",ticket:`${i}-${a+1}`,plan:n}})}o(y,"onboardingItems");export{T as hasBuildScript,y as onboardingItems};
@@ -0,0 +1 @@
1
+ var f=Object.defineProperty;var s=(t,o)=>f(t,"name",{value:o,configurable:!0});import p from"node:fs";import l from"node:os";import n from"node:path";import{execFile as u}from"node:child_process";import{promisify as h}from"node:util";import{fileURLToPath as b}from"node:url";import{boardAt as w}from"../hub/boards.mjs";import{boardRepo as k,mainRefOf as y}from"../hub/board-repo.mjs";import{buildScriptOf as $}from"./build-script.mjs";import{BoardError as g}from"./store.mjs";const x=h(u),c=s(async(t,...o)=>(await x("git",["-C",t,...o],{encoding:"utf8",timeout:6e4})).stdout.trim(),"git"),D="prototypes",v=s(t=>n.join(l.homedir(),".claude","kickflip","worktrees",`${t}-prototypes`),"baseWorktreeOf"),A=n.join(n.dirname(n.dirname(b(import.meta.url))),"shared","prototype-frame.js");async function S({repo:t,ref:o,dir:e}){const i=await c(t,"rev-parse","--verify",`${o}^{commit}`);if(!p.existsSync(e))return await c(t,"worktree","prune"),await c(t,"worktree","add","--quiet","--detach",e,i),{dir:e,sha:i,made:!0,blocked:null};try{return await c(e,"checkout","--quiet","--detach",i),{dir:e,sha:i,made:!1,blocked:null}}catch(r){const m=[...String(r.stderr||"").matchAll(/^\t(.+)$/gm)].map(a=>a[1].trim());if(!m.length)throw r;return{dir:e,sha:await c(e,"rev-parse","HEAD"),made:!1,blocked:m}}}s(S,"ensureBase");async function H(t){const o=w(t);if(!o)throw new g(`${t} is not a board in the hub's manifest, so it has no repo to prototype in`);const e=k(o.route),i=e.branch||"main",r=await S({repo:e.repo,ref:y(e),dir:v(o.route)}),m=r.made?`made from ${i}`:r.blocked?`kept: its pages' edits to ${r.blocked.join(", ")} block the move to ${i}`:`moved to ${i}`,a=$(o.build_target),d=p.existsSync(n.join(r.dir,a));return{lines:[`base ${r.dir} at ${r.sha.slice(0,7)}, ${m}`,d?`build script ${a} is there`:`build script ${a} is missing: write one that serves the app and prints "port <n>"`,`listener ${A}`]}}s(H,"prototypeBase");export{D as BASE_KEY,A as FRAME_SCRIPT,v as baseWorktreeOf,S as ensureBase,H as prototypeBase};
@@ -0,0 +1 @@
1
+ var u=Object.defineProperty;var r=(t,e)=>u(t,"name",{value:e,configurable:!0});import o from"node:fs/promises";import c from"node:path";import{fileURLToPath as f}from"node:url";import{takeFile as d}from"./store.mjs";const g=c.join(c.dirname(f(import.meta.url)),"public","prototype.html"),k=r(t=>String(t).replace(/[&<>"']/g,e=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"})[e]),"esc"),$=r(t=>`${Math.floor(t.mtimeMs).toString(36)}-${t.size.toString(36)}`,"versionOf"),p=r(t=>JSON.stringify(t).replace(/</g,"\\u003c").replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029"),"scriptJSON");async function O(t,e){const n=e.served?e.takes:await Promise.all(e.takes.map(async a=>{const i=`prototypes/${e.topic}/${a.key}.js`,s=await o.stat(d(t,e.topic,a.key)).catch(()=>null);return{key:a.key,label:a.label,src:s?.isFile()?`${i}?v=${$(s)}`:null,file:i}})),l=`${e.title} \xB7 prototype`,m={lead:"back",backHref:e.card?`./#item=${encodeURIComponent(e.card)}`:"./",title:l,controls:!1},y={prototypeTitle:k(l),prototypeHeader:`<!--header ${p(m).replace(/>/g,"\\u003e")}-->`,prototypeData:p({topic:e.topic,title:e.title,takes:n,...e.served?{served:e.served,states:e.states||null}:{}})};return(await o.readFile(g,"utf8")).replace(/\{\{(prototypeTitle|prototypeHeader|prototypeData)\}\}/g,(a,i)=>y[i])}r(O,"prototypePage");export{g as PROTOTYPE_TEMPLATE,k as esc,O as prototypePage,$ as versionOf};
@@ -1,4 +1,4 @@
1
- // The header's bulb and its review sheet: the board's last architecture review and Run, which confirms and asks the
1
+ // The bulb at the foot of the board and its review sheet: the board's last architecture review and Run, which confirms and asks the
2
2
  // board server to start one (docs/adr/2026-11-02-1813-the-bulb-runs-an-architecture-review-of-the-boards-repo.md). The bulb glows
3
3
  // while a review runs. Needs app-core.js.
4
4
  BoardView.part((B) => {