@lovek4d/kickflip 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. package/CONTEXT.md +105 -68
  2. package/README.md +1 -1
  3. package/SKILL.md +27 -21
  4. package/bin/kickflip.mjs +27 -18
  5. package/bin/wait-events.mjs +2 -2
  6. package/board/agents.mjs +2 -0
  7. package/board/arch-review.mjs +4 -4
  8. package/board/bin/board.mjs +199 -79
  9. package/board/build-script.mjs +2 -1
  10. package/board/domain.mjs +9 -7
  11. package/board/finish.mjs +4 -4
  12. package/board/headless.mjs +9 -4
  13. package/board/on-host.mjs +1 -1
  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-asks.js +6 -6
  19. package/board/public/app-banner.js +7 -13
  20. package/board/public/app-cards.js +75 -37
  21. package/board/public/app-core.js +26 -8
  22. package/board/public/app-header.js +8 -8
  23. package/board/public/app-lanes.js +67 -58
  24. package/board/public/app-needs.js +140 -10
  25. package/board/public/app-reader.js +1 -1
  26. package/board/public/app-snapshot.js +46 -72
  27. package/board/public/app-threads.js +78 -75
  28. package/board/public/app.html +9 -4
  29. package/board/public/app.js +114 -38
  30. package/board/public/attach.js +2 -2
  31. package/board/public/dialogs.js +9 -39
  32. package/board/public/hub-kit.js +66 -4
  33. package/board/public/hub.css +2 -0
  34. package/board/public/linear-key.js +46 -35
  35. package/board/public/new-task.js +20 -39
  36. package/board/public/progress-review.html +46 -0
  37. package/board/public/progress-review.js +158 -0
  38. package/board/public/prototype-kit.js +137 -7
  39. package/board/public/prototype-switcher.js +152 -123
  40. package/board/public/prototype.html +57 -3
  41. package/board/public/router.js +7 -6
  42. package/board/public/shell.js +68 -26
  43. package/board/public/sidebar.css +1 -0
  44. package/board/public/sidebar.js +16 -30
  45. package/board/public/style.css +205 -83
  46. package/board/public/ui-cards.js +91 -65
  47. package/board/public/ui-enums.js +1 -1
  48. package/board/public/ui-header.js +27 -18
  49. package/board/public/ui-hub.js +12 -1
  50. package/board/public/ui-links.js +7 -7
  51. package/board/public/ui-order.js +12 -10
  52. package/board/public/ui-page-header.js +19 -7
  53. package/board/public/ui-patch.js +7 -33
  54. package/board/public/ui-progress-bar.js +28 -0
  55. package/board/public/ui-questions.js +47 -52
  56. package/board/public/ui-sidebar.js +34 -26
  57. package/board/public/ui-snapshot.js +43 -52
  58. package/board/public/ui-threads.js +59 -30
  59. package/board/public/ui.js +125 -18
  60. package/board/public/view-hub-settings.js +22 -67
  61. package/board/public/view-hub.js +19 -4
  62. package/board/public/view-notes.js +27 -7
  63. package/board/public/view-questions.js +205 -240
  64. package/board/public/view-settings.js +313 -76
  65. package/board/render-check.mjs +10 -0
  66. package/board/review.mjs +1 -1
  67. package/board/server.mjs +19 -20
  68. package/board/stop.mjs +1 -0
  69. package/board/store.mjs +29 -15
  70. package/board/sync.mjs +2 -0
  71. package/board/tickets.mjs +3 -3
  72. package/board/transcript.mjs +2 -0
  73. package/board/worktree.mjs +25 -20
  74. package/hooks-plugin/hooks/board-data-gate.mjs +50 -0
  75. package/hooks-plugin/hooks/hooks.json +9 -0
  76. package/hooks-plugin/hooks/usage-gate.mjs +20 -3
  77. package/hub/board-repo.mjs +1 -1
  78. package/hub/boards.mjs +4 -4
  79. package/hub/front-door.mjs +5 -5
  80. package/hub/github.mjs +3 -3
  81. package/hub/hub.mjs +11 -11
  82. package/hub/incoming.mjs +2 -2
  83. package/hub/linear.mjs +1 -2
  84. package/hub/live.mjs +2 -2
  85. package/hub/locks.mjs +1 -1
  86. package/hub/owner-checks.mjs +1 -1
  87. package/hub/pr-report.mjs +2 -2
  88. package/hub/presence.mjs +1 -1
  89. package/hub/push.mjs +2 -2
  90. package/hub/readiness.mjs +1 -2
  91. package/hub/review-send.mjs +1 -0
  92. package/hub/secrets.mjs +2 -0
  93. package/hub/self-restart.mjs +2 -0
  94. package/hub/sessions.mjs +2 -2
  95. package/hub/share.mjs +1 -0
  96. package/hub/slack.mjs +2 -2
  97. package/hub/stream.mjs +10 -13
  98. package/hub/try.mjs +7 -7
  99. package/hub/upgrade.mjs +1 -1
  100. package/hub/usage.mjs +3 -3
  101. package/hub/views.mjs +1 -1
  102. package/package.json +2 -1
  103. package/shared/audit.mjs +4 -0
  104. package/shared/card-prs.mjs +1 -1
  105. package/shared/fake-gh.mjs +17 -4
  106. package/shared/machine-gate.mjs +2 -0
  107. package/shared/prototype-frame.js +1 -0
  108. package/shared/service.mjs +4 -4
  109. package/shared/usage-gate.mjs +1 -1
  110. 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 ht=Object.defineProperty;var d=(e,t)=>ht(e,"name",{value:t,configurable:!0});import{routeRecord as q}from"../hub/routes.mjs";import yt from"node:fs";import{ticketBadge as Ye,ticketIn as St}from"./tickets.mjs";import{reviewLinks as vt,reviewTime as bt,reviewersOf as Ot}from"./review.mjs";import{remoteFromInput as xt}from"../hub/repos.mjs";import{reviewsOf as $t,reviewNeeds as At,reviewActions as Bt}from"./auto-review.mjs";import{cardPRs as Et,hasPR as Te,leastReady as qt,prKeyOf as _t,prURL as Rt}from"../shared/card-prs.mjs";import ze from"node:vm";import{checkWords as It,parseCheck as Dt}from"../shared/owner-check.mjs";const Le=ze.createContext({});for(const e of["ui-enums.js","ui-order.js"])ze.runInContext(yt.readFileSync(new URL(`./public/${e}`,import.meta.url),"utf8"),Le);const{BUTTON:Y,ACTION_KIND:R,BUILDER_KIND:Re,PR_STATE:oe}=Le.BoardUI,{laneOrder:Ct}=Le.BoardUI,Mt=["item-message","mark-ready","grill-more","prototype-request","reask-request"],rs=["planned","waiting","building","fixing","checking","held","merged","done","dropped"],Nt=30*6e4,Je="build-refused",Se=Object.freeze({ask:"builder-ask",answer:"builder-answer"}),Tt=864e5,de=d(e=>e.lane==="done"||e.lane==="asks","closedLane"),Lt=d(e=>`wave:${e}`,"waveFold"),Pt=7*Tt,Ze=d((e,t)=>({id:e,url:t?.workspace?`https://linear.app/${t.workspace}/issue/${e}`:null}),"linearRef"),jt=d((e,t)=>String(e).replace(/^S(\d+)$/,`${t||"INT"}-$1`),"internalRef"),Pe=d((e,t,s)=>St(s,t.ticket)?t.ticket:e.internal===!0?jt(t.id,s?.prefix):t.id,"refOf"),Ut=d((e,t,s,o)=>Ye(e||(t?{source:"internal",prefix:"INT"}:null),s,o)||(t?{id:String(t),url:null,source:null}:null),"ticketOf");function Wt(e,t,s,o,r,a){const p=(e.status||"").toLowerCase();return p==="merged"||p==="done"||p==="dropped"||!r&&(t?.state==="MERGED"||t?.state==="CLOSED")?"done":s||p==="checking"?"progress":o?"review":t?.state==="OPEN"?t.checks?.state==="fail"&&(!t.isDraft||a)?"progress":"review":t?"progress":"todo"}d(Wt,"laneOf");function Ft(e,t){return e?.state==="MERGED"||t.status==="merged"||t.merged_at?oe.merged:e?.state==="CLOSED"?oe.closed:e?.state==="OPEN"?e.isDraft?oe.draft:oe.open:null}d(Ft,"prStateOf");const je=d(e=>{const t=(e.status||"").toLowerCase();return t==="dropped"||e.pr?.state==="CLOSED"&&t!=="merged"&&t!=="done"},"droppedCard");function Kt(e){if(!e.some(o=>o.kind==="work")||e.some(o=>o.lane!=="done"))return null;const t=e.filter(o=>o.lane==="done"),s=t.filter(je).length;return{merged:t.length-s,dropped:s}}d(Kt,"finishedOf");function Qt(e,t,s){return Object.fromEntries(e.map(o=>{const r=q(t?.reviews,o.github),a=r==="APPROVED"?"approved":r==="CHANGES_REQUESTED"?"changes":Object.hasOwn(s,o.name)?"sent":"unsent";return[o.name,{state:a,since:a==="sent"?q(s,o.name):null,github:o.github||null}]}))}d(Qt,"reviewOf");function Gt(e,t,s,o,r,a,{held:p,needsApproval:c}){return s?.kind===Re.install?"builder":o==="checking"?"checking":s?"builder":p&&e==="review"?"merge":r&&e==="review"?"owner":e==="review"&&t?.state==="OPEN"&&t.isDraft?a?"ci":"ready":e==="review"||e==="stale"?et(t,c)?"merge":"reviewers":null}d(Gt,"waitsOnOf");const et=d((e,t)=>e?.reviewDecision==="APPROVED"||!t&&!["REVIEW_REQUIRED","CHANGES_REQUESTED"].includes(e?.reviewDecision),"reviewed"),Ie=/(^|\/)prototype-[\w-]+\.html/,Vt={reviewers:"Waiting for PR reviewers",merge:"Approved, merges once CI and the merge state allow",ci:"Marked ready for review once CI passes"},De={waiting:"Approved, Merge shows once CI and the merge state allow",ready:"Approved and green: tap Merge",merging:"Merging"},Ue={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"},Ht=d(e=>`Verified: tap Merge to land it on ${e}`,"heldNext"),Xt="Fix the failing CI",tt="Tap Done once it is settled",Yt=["status","agent","ask-link",Se.answer],nt=d(e=>(e.who==="claude"||e.via==="github")&&!Yt.includes(e.kind),"countsUnread"),zt=/^(?:Not merged yet: |Lander launched headless )/;function Jt({slug:e,wave:t,it:s,order:o,prs:r,repo:a,remote:p,base:c,builder:u,reachedPhase:f,agents:k,worktree:l,eta:h,thread:O,events:m,working:I,said:G,askedAt:_,topicItems:V,boardReviewers:H,now:U,bumpedAt:i,holdAsk:$,closedAt:S,mergeAt:B,autoMerge:re,skipDraft:Z,tickets:T}){const ee=r.map(w=>({repo:w.repo,number:w.number,url:Rt(w),...w.gh||{},status:Ft(w.gh,s)})),W=qt(r.map(w=>w.gh)),N=r[W]?.gh||null,F=ee[W]?.status??null,j=!!S&&String(S)>String(s.status_at||"");j&&s.status!=="merged"&&(s={...s,status:"done"});const Oe=[j&&S,s.status_at,s.merged_at,...r.map(w=>w.gh?.mergedAt)].filter(Boolean).map(String).sort().pop()||null,L=String(Oe||""),D=["done","merged"].includes(s.status)||F===oe.merged&&s.status!=="dropped"?[...G.filter(w=>w.kind==="item-message").map(w=>w.ts),..._].map(String).filter(w=>w>L).sort().pop():void 0,pe=s.owner_step&&!j&&s.status!=="dropped"?String(s.owner_step):null,fe=["done","merged"].includes(s.status)||F===oe.merged;D&&(s={...s,status:void 0,next:void 0});const xe=!!D&&G.some(w=>String(w.ts)>L&&(w.state==="waiting"||w.state==="working")),ae=`${e}/${s.id}`,ge=Ot(t,H),$e=Object.fromEntries(Object.entries(vt(t,s,ae,V)).map(([w,Q])=>[w,bt(Q.ts)])),P=Object.values($e).filter(Boolean).sort()[0]||null,te=[...O.map(w=>w.ts),...m.map(w=>w.ts)].sort().pop()||null,Ae=[...O.filter(w=>nt({...w,who:w.who||"claude"})).map(w=>w.ts),...m.map(w=>w.reply?.at)].filter(Boolean).sort(),X=!Te(s)&&s.pushed?.branch?{branch:s.pushed.branch,at:s.pushed.at||null,host:p?.host||null}:null,K=!Te(s)&&s.merge_ready?.branch?{branch:s.merge_ready.branch,at:s.merge_ready.at||null,base:c}:null;let A=Wt(s,N,k.some(w=>w.started&&!w.done&&z(w)),X||K,!!D,Z);D&&A==="todo"&&(A="progress"),A==="review"&&P&&U-Date.parse(P)>Pt&&(A="stale");const le=!!pe&&fe&&A==="done";le&&(A="review");let M=Gt(A,N,u,(s.status||"").toLowerCase(),X,Z,{held:K,needsApproval:ge.length>0});const ke=M==="builder"&&N?.state==="OPEN"&&!N.isDraft,me=A==="progress"&&!M&&N?.state==="OPEN"&&(!N.isDraft||Z),ne=le||!!D&&A==="progress"&&!M&&!me&&!xe;ne&&(M="owner");const we=$&&String($.ts)>String(s.held_at||""),Be=A==="todo"&&(we?!!$.data.hold:s.status==="held"||!!s.held),Ce=Be&&(we?$.data.until:s.pick_up_at)||null,se=A==="todo"||A==="progress",Ee=k.filter(z).map(w=>String(w.started||"")).filter(Boolean).sort()[0]||"",Me=i&&!(Ee&&String(i)<Ee),qe=O.filter(w=>(w.who||"claude")==="claude"&&w.kind!=="status"&&!zt.test(w.text||"")).map(w=>String(w.ts)).sort().pop()||"",ie=[B,K&&s.merge_ready.tapped].filter(Boolean).map(String).sort().pop(),he=M==="merge"&&!!ie&&ie>qe,ye=O.filter(w=>w.kind==="status"&&String(w.ts)>String(ie)).sort((w,Q)=>String(w.ts).localeCompare(String(Q.ts))).at(-1),n=ye?.text.startsWith("Waiting for ")?`${De.merging} \xB7 ${ye.text[0].toLowerCase()}${ye.text.slice(1)}`:De.merging,g=O.filter(w=>w.kind!=="status").sort((w,Q)=>String(w.ts).localeCompare(String(Q.ts))).at(-1),y=A==="todo"&&g?.kind===Je?g.text:null,x=D||k.filter(z).map(w=>w.started).filter(Boolean).map(String).sort().pop()||s.queued_at||["building","fixing","checking"].includes(String(s.status||"").toLowerCase())&&s.status_at||null,b=N?.reviewDecision==="APPROVED",E=X&&M==="owner"?`merge ${X.branch} into ${c}`:K&&M==="merge"?he?n:Ht(c):M==="merge"&&!re?he?n:(b?De:Ue).waiting:M==="merge"&&!b?Ue.auto:Vt[M],C=F===oe.draft?`Review draft PR #${ee[W].number}`:null;return{key:ae,kind:"work",order:o,wave:e,waveTitle:t.title||e,id:s.id,ref:Pe(t,s,T),title:s.title,status:s.status||null,created:s.created||null,reviewSince:s.review_since||P||s.merge_ready?.at||s.pushed?.at||s.created||null,progressSince:x,closedAt:A==="done"?Oe:null,internal:t.internal===!0,repo:t.internal===!0&&!t.repo?null:a,lane:A,waitsOn:M,builder:M==="checking"?null:u,reachedPhase:f,agents:k,worktree:l??null,eta:h,working:I,reopened:!!D,awaitsDone:ne,ownerStep:ne?pe:null,ownerCheck:ne&&pe&&s.owner_check?{words:It(Dt(s.owner_check.check)),broken:s.owner_check.broken||null}:null,queuedAt:A!=="done"&&s.queued_at||null,queued:!1,deps:s.deps||[],held:Be,heldUntil:Ce,risky:!!s.risky,bumpable:se,bumpedAt:se&&Me?i:null,holdable:A!=="done",hasNotes:!!(s.plan||String(s.notes||"").trim()),finishable:A!=="done",merging:he,refusal:y,manualSteps:s.manual_steps||[],fromAsk:s.from_ask||null,next:ke||A==="done"||M==="checking"?null:me?Xt:E||s.next||C||null,branch:s.branch||N?.headRefName||X?.branch||null,pushed:A==="done"||le?null:X,mergeReady:A==="review"?K:null,ticket:T?.source==="linear"&&!s.ticket&&s.linear?.length?null:Ut(T,s.ticket,s.ticket||(t.internal?Pe(t,s,T):s.linear?.[0]),{repo:a,key:ae}),ticketSource:T?.source||null,linear:(s.linear||[]).map(w=>T?.source==="linear"&&Ye(T,w,{key:ae,repo:a})||Ze(w,T)),pr:ee[W]||null,prs:ee,reviewers:ge.map(w=>w.name),review:Qt(ge,N,$e),inReviewSince:P,threadCount:O.length+m.length,lastTs:te,othersAt:Ae,grilling:lt("grill",m,k,_),prototyping:lt("prototype",m,k,_),state:s.state||null,updatedAt:N?.mergedAt||N?.updatedAt||s.merged_at||u?.at||te||null,ask:null,fold:null,action:null,install:A==="done"?null:en(s.install,N),waitFacts:Zt(s,{agents:k,thread:O,events:m,refusedAt:y?g.ts:null})}}d(Jt,"workItem");function Zt(e,{agents:t,thread:s,events:o,refusedAt:r}){const a=new Set(s.filter(f=>f.kind===Se.answer).map(f=>f.ask)),p=s.filter(f=>f.kind===Se.ask&&!a.has(f.ask)).sort((f,k)=>String(f.ts).localeCompare(String(k.ts)))[0],c=d(f=>o.filter(k=>Fe(k,f)).pop()?.ts||null,"requestAt"),u=s.filter(f=>(f.who||"claude")==="claude"&&!["status","agent",Je].includes(f.kind)).map(f=>f.ts);return{statusAt:e.status_at||null,next:e.next||null,ask:p?{at:p.ts,text:p.text}:null,grillAt:c("grill"),prototypeAt:c("prototype"),refusedAt:r,unverified:t.some(f=>f.calls.some(k=>!f.verified||String(k.at)>String(f.verified.at))),writes:[...u,...t.flatMap(f=>[f.verified?.at,f.started])].filter(Boolean).map(String).sort()}}d(Zt,"waitFactsOf");function en(e,t){if(!e?.url)return null;const s=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:s,older:!!(s&&o&&!o.startsWith(s))}}d(en,"installOf");function tn(e,{needsApproval:t=!0}={}){if(e?.state!=="OPEN")return[`PR is ${String(e?.state||"unknown").toLowerCase()}`];const{state:s,pending:o,failing:r}=e.checks||{};return[e.isDraft&&"it is a draft",!et(e,t)&&`review: ${String(e.reviewDecision||"none").toLowerCase().replace(/_/g," ")}`,s==="fail"&&`failing: ${r?.length?r.join(", "):"a check"}`,s==="pending"&&`pending: ${o?J(o,"check"):"checks"}`,e.mergeStateStatus!=="CLEAN"&&`merge state: ${String(e.mergeStateStatus||"unknown").toLowerCase()}`].filter(Boolean)}d(tn,"mergeBlockers");const nn=d((e,t)=>!tn(e,{needsApproval:t}).length,"mergeable");function sn(e,t,s){if(e.held||de(e))return null;const o=`#item=${encodeURIComponent(e.key)}`;if(st(e)){const r=t.get(e.questions.first);return Ie.test(r?.url||"")?{kind:R.pick,url:`questions.html#${r.id}`,label:"Prototypes ready: pick a take"}:{kind:R.questions,url:`questions.html#${e.questions.first}`,label:`Answer ${J(e.questions.open,"question")}`}}return e.waitsOn==="ready"?{kind:R.ready,url:e.pr.url,label:`Review draft PR #${e.pr.number}`}:e.kind==="ask"&&e.waitsOn==="owner"?{kind:R.done,url:o,label:e.next||tt}:e.waitsOn==="merge"&&e.manualSteps.length&&!e.mergeReady?{kind:R.steps,url:o,label:"Run the manual steps, then merge"}:e.waitsOn==="merge"&&(!s||e.mergeReady)&&!e.merging&&e.prs.every(r=>["MERGED","CLOSED"].includes(r.state)||nn(r,e.reviewers.length>0))?{kind:R.merge,url:o,label:"Merge"}:null}d(sn,"actionOf");const st=d(e=>!!(e.questions&&e.questions.state!=="resolved"&&e.questions.open>0),"asking"),We=new Set([R.pick,R.questions]);function ot(e){return de(e)?null:st(e)?Y.openQuestions:e.action?.kind===R.done?Y.markDone:null}d(ot,"actionButtonOf");const on=d(e=>e.kind==="work"&&e.lane==="todo"&&!e.action&&!e.unpicked,"buildableOf"),rn=d((e,t)=>/^item:/.test(e.topic||"")&&Ie.test(e.url||"")&&!(e.options||[]).some(s=>s.id===t),"picksNoTake");function an(e,t){const s=e.filter(a=>a.topic===`item:${t}`),r=[...s.filter(a=>Ie.test(a.url||"")).flatMap(a=>a.answers.map(p=>({q:a,a:p,again:rn(a,p.choice)}))),...s.filter(a=>a.request).map(a=>({q:a,a:a.request,again:!0}))].sort((a,p)=>String(a.a.ts).localeCompare(String(p.a.ts))).at(-1);return r?.again?{id:r.q.id,note:r.a.note.replace(/\s+/g," ").trim()}:null}d(an,"noTakePicked");const ln="Prototype again",dn=Object.freeze({[R.pick]:Y.openQuestions,[R.questions]:Y.openQuestions,[R.ready]:Y.github,[R.steps]:Y.github,[R.merge]:Y.merge,[R.done]:Y.markDone});function un(e,t,s){if(e.action=sn(e,t,s),e.action?.kind===R.questions&&e.questions.fromAsks){Object.assign(e,{action:null,waitsOn:"owner",next:e.action.label,actionButton:ot(e),resolvedBy:null});return}e.awaitsDone&&=!e.action,e.awaitsDone||Object.assign(e,{ownerStep:null,ownerCheck:null}),e.actionButton=ot(e),e.resolvedBy=dn[e.action?.kind]||null,e.action?.kind===R.merge&&!e.mergeReady&&(e.next=(e.pr?.reviewDecision==="APPROVED"?De:Ue).ready),e.awaitsDone&&Object.assign(e,{lane:"review",next:e.ownerStep||tt,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"&&We.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})}d(un,"placeOwnerWait");const rt=d(e=>e.queuedAt||e.agents.some(z)||["building","fixing"].includes(String(e.status||"").toLowerCase()),"started"),at="none set yet";function as(e,t){const s=String(e.status||"").toLowerCase();if(e.next||Te(e)||e.pushed||e.held||e.queued_at||["held","checking","done","merged","dropped"].includes(s))return!1;const o=t.filter(r=>r?.started);return!o.some(r=>!r.done)&&rt({status:s,agents:o})}d(as,"owesNext");function cn(e,t=new Date){const s=new Date(e),o=s.toLocaleTimeString("en-GB",{hour:"2-digit",minute:"2-digit"});return s.toDateString()===t.toDateString()?o:`${s.getMonth()+1}/${s.getDate()} ${o}`}d(cn,"askedLabel");function pn(e,t,s,o,r,a,p){const c=t.find(S=>S.kind==="ask"&&S.eventId===e.id),u=c.files,f=(c.text||"").trim().split(`
2
- `)[0]||u.map(S=>S.name).join(", ")||"Ask",k=c.state==="replied"||c.state==="answered",l=r?.state==="progress"&&!(String(a||"")>String(r.at||"")),h=!l&&(!!r||!!a),O=k&&!h&&!l&&p.open>0,m=k&&!h&&!l&&!O&&p.answered>0,I=h||k&&!l&&!O&&!m,G=k&&!o&&!r?.moved&&[...t.filter(S=>S.who==="claude"&&S.kind!=="ask-link"&&S.kind!=="status").map(S=>S.ts),...t.map(S=>S.reply?.at)].filter(Boolean).sort().pop()||null,_=I||l||O||m,V=t.some(S=>S.who==="love"&&S.kind!=="ask"&&(S.state==="waiting"||S.state==="working")),H=_?"answered":c.state,U=_?null:s||null,i=[...t.filter(nt).map(S=>S.ts),...t.map(S=>S.reply?.at)].filter(Boolean).sort(),$=[...t.map(S=>S.ts),...i,...l?[r.at]:[]].filter(Boolean).sort().pop();return{key:`ask:${e.id}`,kind:"ask",order:0,wave:null,waveTitle:null,id:e.id,ref:_?cn(e.ts):"New",isNew:!_,title:f,status:null,internal:!1,repo:null,lane:l?"progress":I?"asks":"todo",waitsOn:l&&!V?"owner":null,builder:null,agents:[],eta:null,working:t.some(S=>S.state==="working"),deps:[],held:!1,risky:!1,bumpable:!_,bumpedAt:U,manualSteps:[],fromAsk:null,from:null,next:l&&r.next||null,hasNotes:!1,branch:null,finishable:_&&!I,linear:[],pr:null,prs:[],reviewers:[],review:{},inReviewSince:null,reviewSince:null,progressSince:l&&r.at||null,closedAt:null,threadCount:t.length,lastTs:$,othersAt:_?i:[],grilling:!1,prototyping:!1,created:e.ts,updatedAt:_?$:e.ts,ask:{eventId:e.id,state:H,askedAt:e.ts,bumpedAt:U,edited:!!c.edited,canEdit:!_,text:c.text,files:u,answerAt:G,from:c.from||null},fold:null,action:null}}d(pn,"askItem");const fn=new Set(["grill","prototype"]),ue=d(e=>fn.has(e.kind),"plans"),z=d(e=>!ue(e),"builds"),gn={grill:"preheating",prototype:"prototyping"},kn={grill:"grill-more",prototype:"prototype-request"},Fe=d((e,t)=>e.kind===kn[t]&&!e.data?.question,"isRequest");function lt(e,t,s,o){if(s.some(a=>a.kind===e&&a.started&&!a.done))return!0;const r=t.filter(a=>Fe(a,e)).pop();return!!(r&&!r.reply&&!o.some(a=>String(a)>String(r.ts))&&!s.some(a=>a.kind===e&&a.done&&String(a.started)>=String(r.ts)))}d(lt,"planningOf");const ls=30*6e4;function is(e,t){const s=[];for(const o of e.items){if(de(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&&Fe(a,"prototype")).pop();r&&s.push({key:o.key,request:r.id,since:r.ts});for(const a of e.owner.filter(p=>p.topic===`item:${o.key}`&&p.state==="requested"))s.push({key:o.key,request:a.request.id,question:a.id,since:a.request.ts})}return s}d(is,"prototypeWaits");function Ke(e={}){return Object.entries(e).filter(([,t])=>t&&typeof t=="object").map(([t,s])=>({name:t,kind:it(s.kind)||null,model:s.model||(s.kind==="opus"||s.kind==="sonnet"?s.kind:null),label:s.label||null,started:s.started||null,eta:s.done?null:s.eta||null,done:s.done||null,calls:Array.isArray(s.calls)?s.calls:[],verified:s.verified||null})).sort((t,s)=>String(t.started||"").localeCompare(String(s.started||""))||t.name.localeCompare(s.name))}d(Ke,"agentsOf");function mn(e={}){return Object.values(e).filter(t=>t?.worktree?.path).sort((t,s)=>String(t.started||"").localeCompare(String(s.started||""))).at(-1)?.worktree.path??null}d(mn,"worktreeOf");function wn(e,t=[]){const s=e.filter(z).map(o=>String(o.started||"")).filter(Boolean).sort().pop();return s===void 0?null:t.filter(o=>o.kind==="status"&&o.phase&&!o.planner&&String(o.ts)>=s).sort((o,r)=>String(o.ts).localeCompare(String(r.ts))).pop()?.phase||null}d(wn,"reachedPhaseOf");function hn(e,t=[],s){const o=e.filter(l=>l.started&&!l.done),r=o.every(ue),a=r?o:o.filter(z),p=a.map(l=>String(l.started||"")).sort()[0];if(p===void 0)return null;const c=t.filter(l=>l.kind==="status"&&String(l.ts)>=p&&(r||!l.planner)).sort((l,h)=>String(l.ts).localeCompare(String(h.ts))).pop(),u=a.some(l=>l.kind===Re.install)?Re.install:it(a.at(-1).kind),f=c?.ts||p;return{progress:c?c.phase||c.planner?c.text.replace(": "," \xB7 "):c.text||null:r?gn[u]:null,phase:c?.phase||null,at:f,kind:u,planner:r,silentSince:f,stalled:s-Date.parse(f)>=Nt}}d(hn,"builderOf");const Qe={opus:"Claude Opus",sonnet:"Claude Sonnet",codex:"Codex"},yn=d(({model:e,kind:t})=>Qe[e]||Qe[t]||(t==="claude"?Qe.opus:null),"modelName"),it=d(e=>e==="opus"||e==="sonnet"?"claude":e,"providerOf");function Ge(e){const t=yn(e),{kind:s}=e,o=e.label?.replace(/\bbuilder\b/,"implementer").replace(/\bBuilder\b/,"Implementer"),r=d(p=>p[0].toLowerCase()+p.slice(1),"lower");if(t&&ue(e))return`${t} ${s}`;if(t)return`${t} ${r(o?.replace(/^(?:claude\s+)?(?:opus|sonnet|codex)\b\s*/i,"")||"implementer")}`;const a=s?s[0].toUpperCase()+s.slice(1):"";return a?o?o.toLowerCase().includes(s.toLowerCase())?o:`${a} ${r(o)}`:a:o||"Implementer"}d(Ge,"agentName");const dt=d((e,t)=>!!e.resolved&&(!e.resolved_at||String(e.resolved_at)>=String(t)),"resolvedSince");function Sn(e,t,s=[],o=[]){const r=t.filter(l=>l.data?.id===e.id),a=r[r.length-1]||null,p=!!(e.resolved&&e.resolved_at&&a&&String(a.ts)>e.resolved_at),c=e.resolved&&!p,u=s.filter(l=>l.data?.question===e.id&&String(l.ts)>String(a?.ts||"")).at(-1),f=c?o.filter(l=>l.data?.question===e.id&&String(l.ts)>String(e.resolved_at||"")).at(-1):null,k=c?"resolved":u?"requested":a?a.reply?"replied":"answered":"open";return{...e,state:k,request:u?{id:u.id,ts:u.ts,note:u.data.note||"",choice:u.data.choice||null}:null,reask:f?{id:f.id,ts:f.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:dt(e,l.ts)}))}}d(Sn,"ownerQuestion");const ce=d(e=>e.round??(Ie.test(e.url||"")?1:0),"roundOf");function vn(e,t){const s=d((o,r)=>o.confirm_of||(o.options||[]).some(a=>a.id===r.choice),"settles");return e.filter(o=>ce(o)===t&&o.answers.length).map(o=>[o,o.answers.at(-1)]).filter(([o,r])=>s(o,r)).map(([,o])=>o).sort((o,r)=>String(o.ts).localeCompare(String(r.ts))).at(-1)}d(vn,"roundSettledBy");function bn(e){const t=e.find(r=>r.request&&!e.some(a=>ce(a)>ce(r)));if(t)return{n:ce(t)+1,state:"making"};const s=Math.max(0,...e.map(ce));if(!s)return null;const o=vn(e,s);return o?{n:s,state:"closed",take:o.choice}:e.some(r=>ce(r)===s&&r.state!=="resolved")?{n:s,state:"back"}:null}d(bn,"roundState");const ve=d((e,t,s)=>{const o=e.get(t);o?o.push(s):e.set(t,[s])},"add"),be=d((e,t)=>{const s=new Map;for(const o of e)ve(s,t(o),o);return s},"groupBy");function On(e,t,s=new Set){const o=new Set(e.map(p=>p.id)),r=[...e];t.some(p=>!o.has(p.topic))&&r.push({id:"",title:"Other"});const a=be(t,p=>o.has(p.topic)?p.topic:"");return r.map(p=>{const c=a.get(p.id)||[],u=d(l=>c.filter(h=>h.state===l).length,"count"),f=c.every(l=>l.state==="resolved")||s.has(p.id)&&!u("open"),k=c.length&&f?"resolved":"open";return{...p,state:k,questions:c.map(l=>l.id),open:u("open"),answered:u("answered"),replied:u("replied"),resolved:u("resolved"),round:bn(c)}}).filter(p=>p.questions.length)}d(On,"ownerTopics");const ut={"mark-ready":"Mark ready","grill-more":"grill requested","prototype-request":"prototype requested","reask-request":"re-ask requested"},xn="answers submitted",$n="quick build: no grill, as you asked",An=d((e,t)=>{if(e.kind!=="prototype-request"||!t.has(e.data.question))return e.data.text||(e.data.files?.length?"":q(ut,e.kind))||"";const s=t.get(e.data.question),o=(s.options||[]).find(r=>r.id===e.data.choice);return[s.question,o&&`${o.id}. ${o.label}`,e.data.note].filter(Boolean).join(`
3
- \u2192 `)},"actionText"),Bn=d((e,t)=>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:ut[e.kind]}:{request:!0},"requestOf"),Ve=d(e=>[...e.filter(t=>t.who==="claude"&&!["status","agent",Se.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 s=new Map,o=new Map;for(const k of t.items||[])ve(s,k.topic,k),o.set(k.id,k.topic);const r=new Map,a=new Map,p=new Map,c=new Map,u=new Map,f=new Map;e.forEach((k,l)=>{f.set(k,l),k.data?.key&&Mt.includes(k.kind)&&ve(r,k.data.key,k),k.kind==="owner-answer"&&o.has(k.data?.id)&&ve(a,o.get(k.data.id),k),k.kind==="ask"&&p.set(k.id,k)});for(const k of e.filter(l=>l.kind==="ask-edited").sort((l,h)=>String(l.ts).localeCompare(String(h.ts)))){c.set(k.data?.id,k.data?.text);for(const l of k.data?.files||[])ve(u,k.data?.id,l)}return{byKey:r,answers:a,asks:p,edits:c,editFiles:u,questions:s,order:f}}d(ct,"threadIndex");const He=d((e,t)=>{const s=t.filter(o=>o?.length);return s.length>1?s.flat().sort((o,r)=>e.order.get(o)-e.order.get(r)):[...s[0]||[]]},"inLogOrder"),En=/; its log is \S*\/\.claude\/kickflip\/logs\/([^/\s]+\.log)\.$/,qn=d(e=>{const t=!e.log&&typeof e.text=="string"?En.exec(e.text):null;return t?{...e,text:`${e.text.slice(0,t.index)}.`,log:t[1]}:e},"withLog");function pt(e,{lines:t=[],events:s=[],owner:o={},working:r={},fromAsk:a=null,links:p=[],agents:c={},moved:u=[],index:f=ct(s,o)}){const k=e.startsWith("ask:")?[e.slice(4)]:[a,...u].filter(Boolean),l=[...new Set([e,...k.map(i=>`ask:${i}`)])],h=new Map((f.questions.get(`item:${e}`)||[]).map(i=>[i.id,i])),O=f.answers.get(`item:${e}`)||[],m=new Set([...h.values()].map(i=>i.round_of).filter(Boolean)),I=Ke(c).filter(z).map(i=>String(i.started||"")).filter(Boolean),G=new Set(O.filter(i=>dt(h.get(i.data.id),i.ts)||m.has(i.data.id)||I.some($=>$>String(i.ts))).map(i=>i.id)),_=[...Ke(c).flatMap(i=>[...i.started?[{ts:i.started,who:"claude",kind:"agent",text:`${Ge(i)} started`,finished:!1,eta:i.done?null:i.eta,...ue(i)?{planner:!0}:{}}]:[],...i.done?[{ts:i.done,who:"claude",kind:"agent",text:`${Ge(i)} finished`,finished:!0,eta:null,...ue(i)?{planner:!0}:{}}]:[],...i.calls.length?[{ts:i.done||i.calls.at(-1).at,who:"claude",kind:"calls",text:Ge(i),calls:i.calls.map($=>$.text),verified:i.verified}]:[]]),...t.map(qn).map(i=>({ts:i.ts,who:i.who||"claude",...i.log?{log:i.log}:{},...i.kind==="status"?{kind:"status",...i.planner?{planner:!0}:{}}:{},...Object.values(Se).includes(i.kind)?{kind:i.kind,ask:i.ask}:{},text:i.text||"",html:i.html||null,link:i.link||null,via:i.via||null})),...He(f,l.map(i=>f.byKey.get(i))).map(i=>({ts:i.ts,who:"love",via:"site",kind:i.kind,text:An(i,h),files:i.data.files||[],eventId:i.id,reply:i.reply,...Bn(i,h)})),...O.map(i=>{const $=[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:`${h.get(i.data.id).question}
4
- \u2192 ${$}`,files:i.data.files||[],eventId:i.id,reply:i.reply,status:xn}}),...He(f,[...new Set(k)].map(i=>f.asks.has(i)?[f.asks.get(i)]:[])).flatMap(i=>[{ts:i.ts,who:"love",via:"ask",kind:i.kind,text:i.data?.text||"",files:i.data?.files||[],eventId:i.id,reply:i.reply,...u.includes(i.id)?{moved:!0}:{},...typeof i.data?.from?.title=="string"?{from:i.data.from.title}:{}},...i.data?.quick===!0?[{ts:i.ts,who:"love",kind:"quick-build",request:!0,text:$n}]:[],...p.map($=>({ts:i.ts,who:"claude",kind:"ask-link",text:`${$.became?"Became":"Added to"} ${$.ref}`,link:`#item=${encodeURIComponent($.key)}`,html:null,via:null}))])].sort((i,$)=>String(i.ts).localeCompare(String($.ts))),V=Ve(_),{edits:H,editFiles:U}=f;for(const i of _){if(!i.eventId)continue;(i.kind==="ask"||i.kind==="item-message")&&typeof H.get(i.eventId)=="string"&&Object.assign(i,{text:H.get(i.eventId),edited:!0,files:[...i.files,...U.get(i.eventId)||[]]});const $=i.kind==="ask"&&(p.length>0||!!i.moved);i.state=i.reply?"replied":$||G.has(i.eventId)||V>String(i.ts)?"answered":q(r,i.eventId)?"working":"waiting",i.canDelete=i.kind==="item-message"&&(i.state==="working"||i.state==="waiting"),i.canEdit=i.canDelete}return _}d(pt,"threadOf");function _n(e,t,s,o,r,a){const p=d((l,h)=>{const O=a.filter(I=>I.kind==="wave-triage"&&I.data?.[l]===h).pop(),m=r.filter(I=>I.topic===`${l}:${h}`&&(I.state==="open"||I.state==="answered")).length;return{running:!!(O&&!O.reply),questions:m}},"triageOf"),c=new Map(o.map(l=>[l.key,l])),u=d(l=>l.filter(h=>h.lane==="done"&&!je(h)).length,"merged"),f=s.map(l=>({l,cards:l.keys.map(h=>c.get(h)).filter(Boolean)})).map(l=>({...l,open:!l.l.finished_at&&l.cards.some(h=>h.lane!=="done")})).sort((l,h)=>Number(l.open)-Number(h.open));for(const{l,cards:h}of f)for(const O of h)O.lineup={slug:l.slug,title:l.title};const k=f.filter(l=>l.open).map(({l,cards:h})=>({kind:"lineup",slug:l.slug,title:l.title,goal:l.goal,keys:h.map(O=>O.key),phases:l.phases.map(O=>O.filter(m=>c.has(m))).filter(O=>O.length),next:Rn(h),merged:u(h),total:h.length,triage:p("lineup",l.slug)}));return e.fromWaves?[...k,...t.filter(l=>!l.finished).map(l=>({w:l,cards:o.filter(h=>h.wave===l.slug&&h.kind!=="ask")})).filter(({cards:l})=>l.length).map(({w:l,cards:h})=>({kind:"wave",slug:l.slug,title:l.title,goal:null,keys:h.map(O=>O.key),phases:null,next:null,merged:u(h),total:h.length,triage:p("wave",l.slug)}))]:k}d(_n,"waveBandsOf");function Rn(e){const t=e.filter(a=>a.lane==="todo"),s=t.find(a=>a.ready&&a.buildable)||t[0];if(!s)return null;const o=s.ready&&s.buildable,r=o?"ready":s.held?"held":s.blockedBy.length?`waits on ${s.blockedBy.map(a=>a.ref).join(", ")}`:s.action?"needs you":s.unsorted?"new":s.state||"not ready";return{key:s.key,ref:s.ref,ready:o,word:r}}d(Rn,"nextOf");function ds(e,t,s,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])),p=r.keys.filter(l=>a.get(l)==="todo"),c=p.indexOf(s),u=c+o;if(c<0||u<0||u>=p.length)return null;[p[c],p[u]]=[p[u],p[c]];let f=0;const k=r.keys.map(l=>a.get(l)==="todo"?p[f++]:l);return f=0,r.phases.map(l=>k.slice(f,f+=l.length))}d(ds,"lineupMoved");const In=d(e=>e.phases||e.items.map(t=>[t]),"lineupPhases");function us(e){const{owner:t={},topicItems:s={},events:o=[],threads:r={},prs:a={},working:p={}}=e,c=e.now??Date.now(),u=ct(o,t),f=new Set(o.filter(n=>n.kind==="ask-withdrawn"&&!n.data?.key).map(n=>n.data?.id)),k=new Map(o.filter(n=>n.kind==="ask"&&!f.has(n.id)).map(n=>[n.id,n])),l=d((n,g)=>new Map(o.filter(y=>y.kind===n).sort((y,x)=>String(y.ts).localeCompare(String(x.ts))).map(y=>[y.data?.[g],y.ts])),"latest"),h=l("ask-bump","id"),O=l("card-unbump","key"),m=new Map([...l("card-bump","key")].filter(([n,g])=>!(String(O.get(n)||"")>String(g)))),I=l("card-done","key"),G=l("card-merge","key"),_=e.autoMerge===!0,V=e.tickets,H=new Map(o.filter(n=>n.kind==="card-hold").sort((n,g)=>String(n.ts).localeCompare(String(g.ts))).map(n=>[n.data?.key,n])),U=new Map,i=e.askLinks||{},$=new Map;for(const[n,g]of Object.entries(i))k.has(n)&&$.set(g,[...$.get(g)||[],n]);const S=[],B=[],re=new Map,Z=new Map,T=new Map,ee=new Map,W=e.github?null:xt(e.remote);for(const{slug:n,wave:g,agents:y={}}of e.waves){const x=e.github||g.repo||null;S.push({slug:n,title:g.title||n,status:g.status||null,internal:!!g.internal,finished:null,reviewers:(g.reviewers||[]).map(b=>b.name)}),g.items.forEach((b,E)=>{const C=`${n}/${b.id}`,w=($.get(C)||[]).filter(v=>v!==b.from_ask),Q=[b.from_ask,...w].filter(v=>k.has(v)),mt=new Set(Q.map(v=>`ask:${v}`)),Xe=[...q(r,C)||[],...Q.flatMap(v=>q(r,`ask:${v}`)||[])];b.from_ask&&U.set(b.from_ask,[...U.get(b.from_ask)||[],{key:C,ref:Pe(g,b,V),became:!0}]);const _e=pt(C,{lines:Xe,events:o,owner:t,working:p,fromAsk:b.from_ask||null,moved:w,index:u});for(const v of _e)v.eventId&&re.set(v.eventId,v.state);Z.set(C,Ve(_e)),B.push(Jt({slug:n,wave:g,it:b,order:E,repo:x,remote:W,base:e.branch||"main",prs:Et(b,x).map(v=>({...v,gh:q(a,_t(v))||null})),...(v=>({agents:v,builder:hn(v,q(r,C),c),reachedPhase:wn(v,q(r,C)),eta:v.map(wt=>wt.eta).filter(Boolean).sort().pop()||null}))(Ke(q(y,b.id))),worktree:mn(q(y,b.id)),thread:Xe,events:[...He(u,[C,...mt].map(v=>u.byKey.get(v))),...Q.map(v=>k.get(v))],working:_e.some(v=>v.state==="working"),said:_e.filter(v=>v.who==="love"&&(v.kind==="item-message"||v.kind==="owner-answer")),askedAt:(u.questions.get(`item:${C}`)||[]).filter(v=>v.asked_at).map(v=>v.asked_at),topicItems:s,boardReviewers:e.reviewers||[],now:c,bumpedAt:m.get(C),holdAsk:H.get(C),closedAt:I.get(C),mergeAt:G.get(C),autoMerge:_,skipDraft:e.skipDraft===!0,tickets:V}));const Ne=B[B.length-1];ee.set(C,{parent:b.parent?gt(n,b.parent):null,related:(b.related||[]).map(v=>gt(n,v))}),Ne.lane==="done"&&T.set(C,Ne.closedAt||String(Ne.updatedAt||""))})}const N=new Map(B.map(n=>[n.key,n])),F=new Map,j=e.try||{},Oe=e.autoBuild===!0,L=["web","app"].includes(j.kind)?j.kind:e.waves.some(({wave:n})=>n.items.some(g=>g.install?.url))?"app":"web";for(const n of B){if(n.kind!=="work"||n.lane==="done")continue;const g=q(j.cards,n.key)||{},y=g.head||n.pr?.headRefOid,x=L==="web"?g.sha:n.install?.sha,b=n.builder?.kind===Re.install?"running":g.state||(L==="app"&&n.install?"ready":null);n.try={kind:L,state:b,stale:!!(x&&y&&!String(y).toLowerCase().startsWith(String(x).toLowerCase())),url:L==="web"?null:n.install?.url||null,port:L==="web"&&b==="ready"&&g.https||null,sha:x||null,changes:g.ahead>0,script:g.script===!0,autoBuild:Oe}}const D=j.main,pe=D?.script&&D.sha?{slug:D.slug,branch:D.branch||"main",sha:D.sha.slice(0,7),at:D.at,kind:L,state:D.state||null,url:L==="web"?null:e.main?.install?.url||null,port:L==="web"&&D.state==="ready"&&D.https||null,pull:j.pull?{running:j.pull.running===!0,error:j.pull.error||null}:null}:null,fe=e.askProgress||{},xe=l("ask-done","id"),ae=be(o.filter(n=>n.kind==="owner-answer"),n=>n.data?.id),ge=be(o.filter(n=>n.kind==="prototype-request"),n=>n.data?.question),$e=be(o.filter(n=>n.kind==="reask-request"),n=>n.data?.question),P=(t.items||[]).map(n=>Sn(n,ae.get(n.id)||[],ge.get(n.id)||[],$e.get(n.id)||[])),te=new Map(P.map(n=>[n.id,n])),Ae=be(P,n=>n.topic),X=d(n=>{const g=Ae.get(n)||[];return{open:g.filter(y=>y.state==="open").length,answered:g.filter(y=>y.state==="answered").length}},"pendingOn");for(const n of k.values()){const g=`ask:${n.id}`,y=N.get(q(i,n.id)),x=[...U.get(n.id)||[]];if(y&&!x.some(E=>E.key===y.key)&&x.push({key:y.key,ref:y.ref,became:!1}),x.length){F.set(g,x[0].key);continue}if(q(i,n.id)){F.set(g,q(i,n.id));continue}const b=pt(g,{lines:q(r,g)||[],events:o,working:p,links:x,index:u});for(const E of b)E.eventId&&re.set(E.eventId,E.state);Z.set(g,Ve(b)),B.push(pn(n,b,h.get(n.id),x.length>0||!!q(i,n.id),q(fe,n.id),xe.get(n.id),X(`item:${g}`)))}for(const n of S){const g=B.filter(y=>y.wave===n.slug);if(n.finished=Kt(g),n.finished)for(const y of g)y.lane==="done"&&(y.fold=Lt(n.slug))}for(const n of B)n.lineup=null;const K=new Set((t.topics||[]).map(n=>n.id)),A=e.waves.flatMap(({slug:n,wave:g})=>(g.lineups||[]).map(y=>{const x=In(y).map(b=>b.map(E=>`${n}/${E}`));return{...y,phases:x,keys:x.flat()}})),le=d(()=>On([...t.topics||[],...B.filter(n=>!K.has(`item:${n.key}`)).map(n=>({id:`item:${n.key}`,card:n.key,title:`${n.ref}: ${n.title}`,...n.kind==="ask"?{askedAt:n.ask.askedAt}:{},summary:"Questions about this work item."})),...A.filter(n=>!K.has(`lineup:${n.slug}`)).map(n=>({id:`lineup:${n.slug}`,title:n.title,summary:"Wave triage."})),...(e.fromWaves?S:[]).filter(n=>!K.has(`wave:${n.slug}`)).map(n=>({id:`wave:${n.slug}`,title:n.title,summary:"Wave triage."}))],P,new Set(B.filter(de).map(n=>`item:${n.key}`))),"topicsOf"),M=new Map(le().map(n=>[n.id,n]));for(const n of B){const g=M.get(`item:${n.key}`);if(!g){n.questions=null;continue}const y=g.questions.filter(E=>te.get(E)?.state!=="resolved"),x=g.questions.find(E=>te.get(E)?.state==="open")||y[0]||g.questions[0],b=g.questions.map(E=>te.get(E)).filter(E=>E?.state==="open");n.questions={topic:g.id,state:g.state,open:g.open,answered:g.answered,replied:g.replied,resolved:g.resolved,first:x,askedAt:b.map(E=>E.asked_at).filter(Boolean).sort(),fromAsks:b.length>0&&b.every(E=>E.ask)}}const ke=new Map(B.map(n=>[n.key,n]));for(const n of B){n.blockedBy=n.kind!=="work"||n.lane==="done"?[]:n.deps.map(y=>ke.get(String(y).includes("/")?y:`${n.wave}/${y}`)).filter(y=>y&&y.lane!=="done"&&!y.reopened).map(ft),un(n,te,_),n.lane==="todo"&&n.kind==="work"&&!n.held&&rt(n)&&(n.lane="progress"),n.unpicked=n.kind==="work"&&n.lane==="todo"&&!!an(P,n.key),n.unpicked&&(n.state="prototyping"),n.unpicked&&!n.action&&(n.next=ln),n.buildable=on(n);const g=n.kind==="work"&&n.lane==="todo";n.unsorted=g&&!!n.fromAsk&&!n.state,n.ready=g&&n.state==="ready"&&!n.blockedBy.length&&!n.action}Mn(B,ke,ee);const me=new Map((t.items||[]).map(n=>[n.id,n.topic])),ne=d(n=>n.kind==="owner-answer"?me.has(n.data?.id)?/^item:(.+)$/.exec(me.get(n.data.id))?.[1]||null:"":n.kind==="ask"?`ask:${n.id}`:n.data?.key||(n.kind.startsWith("ask-")&&n.data?.id?`ask:${n.data.id}`:null),"ownCardOf"),we=d(n=>{const g=ne(n);return F.get(g)||g},"cardOf"),Be=d(n=>{const g=n.startsWith("ask:")?n.slice(4):null,y=g&&q(fe,g)?.state==="done"?q(fe,g).at:null;return[I.get(n),g&&xe.get(g),y,T.get(n)].filter(Boolean).sort().pop()||""},"closedAt"),Ce=d(n=>{const g=we(n);return g===null?!n.reply:!ke.has(g)||!(Be(g)<String(q(p,n.id)))?!1:re.has(n.id)?re.get(n.id)==="working":!n.reply&&!F.has(ne(n))&&!(String(Z.get(g)||"")>String(n.ts))},"unanswered"),se=o.filter(n=>q(p,n.id)&&Ce(n)).map(n=>({id:n.id,kind:n.kind,key:we(n),data:n.data,since:q(p,n.id)})),Ee=e.autoPull===!0;for(const n of B)n.working=se.some(g=>g.key===n.key),n.kind==="work"&&(n.lane==="progress"&&n.queuedAt||Ee&&n.lane==="todo"&&kt(n))&&Object.assign(n,{lane:"todo",queued:!0}),n.kind==="work"&&n.lane==="progress"&&!n.builder&&!n.next&&n.waitsOn!=="checking"&&!n.working&&!n.queued&&(n.next=at),n.sortAt=(n.queued?n.queuedAt||n.created:Nn[n.lane](n))||(["review","stale"].includes(n.lane)?null:n.updatedAt)||null;for(const n of B){if(n.kind!=="work")continue;const g=(Ae.get(`item:${n.key}`)||[]).filter(x=>x.state==="answered").map(x=>x.answers.at(-1).ts).sort().pop(),y=se.filter(x=>x.key===n.key).map(x=>String(x.since)).sort()[0];n.orchestrator=["progress","todo"].includes(n.lane)?Vn(n,n.waitFacts,{answeredAt:g,workingSince:y}):null,delete n.waitFacts}B.sort(Ct);const Me=_n(e,S,A,B,P,o),qe=le(),ie=$t({on:e.autoReview,incoming:e.incoming,records:e.reviewRecords,events:o,now:c,refs:new Map(B.filter(n=>n.kind==="work").map(n=>[n.key,n.ref]))}),he=[...Ln(B,qe,P),...At(ie)],ye=B.filter(n=>n.ask?.answerAt).sort((n,g)=>g.ask.answerAt.localeCompare(n.ask.answerAt)).map(n=>({key:n.key,id:n.id,text:n.title,at:n.ask.answerAt}));return Dn({kind:L,main:pe,remote:W&&{host:W.host,name:`${W.host}/${W.path}`},waves:S,waveBands:Me,items:B,moved:Object.fromEntries(F),answers:ye,owner:P,ownerTopics:qe,reviews:ie,needs:he,working:se.length,workingOn:se,checks:Tn(e,c)},e)}d(us,"buildBoard");function Dn(e,{listen:t,prompts:s}={}){const o=[...Pn(s),...e.needs];return{...e,needs:o,needsSummary:jn(o),checks:{...e.checks,watcher:{listening:"running",asleep:"asleep",waking:"waking"}[t]||"stopped"}}}d(Dn,"withHub");const ft=d(e=>({key:e.key,ref:e.ref}),"linkOf"),gt=d((e,t)=>String(t).includes("/")?String(t):`${e}/${t}`,"linkKey"),Cn=d((e,t)=>e.ref.localeCompare(t.ref,void 0,{numeric:!0}),"byRef");function Mn(e,t,s){const o=new Map,r=new Map,a=new Map,p=d((u,f,k)=>u.set(f,[...u.get(f)||[],k]),"add");for(const[u,f]of s){f.parent&&p(o,f.parent,u);for(const k of f.related)k!==u&&(p(r,u,k),p(r,k,u))}for(const u of e)for(const f of u.blockedBy||[])p(a,f.key,u.key);const c=d((u=[])=>[...new Set(u)].map(f=>t.get(f)).filter(Boolean).map(ft).sort(Cn),"cards");for(const u of e){const f=s.get(u.key)?.parent;u.parent=f?{key:f,ref:t.get(f)?.ref||f.slice(f.indexOf("/")+1)}:null,u.children=c(o.get(u.key)),u.related=c(r.get(u.key)),u.waitsOnIt=c(a.get(u.key))}}d(Mn,"linkCards");const Nn={todo:d(e=>e.created,"todo"),progress:d(e=>e.progressSince,"progress"),review:d(e=>e.reviewSince,"review"),stale:d(e=>e.reviewSince,"stale"),done:d(e=>e.closedAt,"done"),asks:d(e=>e.ask.answerAt,"asks")},J=d((e,t)=>`${e} ${t}${e===1?"":"s"}`,"plural");function Tn({checked:e,watcher:t,replyAt:s,threads:o={},working:r={},waves:a=[]},p){const c=Number(e?.every)||30,f=[s,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(h=>Object.values(h||{})).map(h=>h?.done||h?.started))].filter(l=>typeof l=="string"&&!Number.isNaN(Date.parse(l))).reduce((l,h)=>l&&Date.parse(l)>Date.parse(h)?l:h,null),k=!!e?.idle;return{at:e?.at||null,every:k?null:c,idle:k,late:!k&&!!e?.at&&p-Date.parse(e.at)>2*c*6e4,claudeAt:f}}d(Tn,"checksOf");function Ln(e,t,s){const o=new Set(e.map(c=>c.questions?.topic).filter(Boolean)),r=d(c=>c.find(u=>s.find(f=>f.id===u)?.state==="open")||c[0],"firstOpen"),a=t.filter(c=>c.state!=="resolved"&&c.open>0&&!o.has(c.id)).map(c=>{const u=`questions.html#${r(c.questions)}`,f=/^(?:lineup|wave):(.+)$/.exec(c.id)?.[1]||null;return{kind:"Question",title:c.title,text:`${c.title} \xB7 ${J(c.open,"question")}`,url:u,topic:c.id,band:f,questions:{open:c.open,url:u},ready:null}}),p=e.filter(c=>!c.held).map(c=>{const u=c.questions&&c.questions.state!=="resolved"&&c.questions.open>0?{open:c.questions.open,url:`questions.html#${c.questions.first}`}:null,f=c.waitsOn==="ready"?c.pr.url:null,k=!u&&!f&&c.action?{label:c.action.label,url:c.action.url}:null;if(!u&&!f&&!k)return null;const l=`${c.ref}: ${c.title}`,h=[l,u&&J(u.open,"question"),f&&"Ready on GitHub",k?.label].filter(Boolean).join(" \xB7 ");return{kind:u?"Question":f?"Tap Ready":"Action needed",title:l,text:h,url:`#item=${encodeURIComponent(c.key)}`,key:c.key,questions:u,ready:f,action:k}}).filter(Boolean);return[...a,...p]}d(Ln,"needsOf");function Pn(e=[]){return e.map(t=>{const s=t.questions?.length?`Question: ${t.questions.map(o=>o.question).join(" \xB7 ")}`:`${t.tool}: ${t.detail||t.action}`;return{kind:"Prompt",title:s,text:s,url:"",prompt:t}})}d(Pn,"promptLines");function jn(e){const t=e.filter(a=>a.prompt).length,s=e.reduce((a,p)=>a+(p.questions?.open||0),0),o=e.filter(a=>a.ready).length,r=e.filter(a=>a.review).length;return[t&&J(t,"prompt"),s&&J(s,"question"),o&&`${J(o,"draft")} waiting on Ready`,r&&`${J(r,"review")} held`].filter(Boolean).join(" \xB7 ")}d(jn,"needsSummary");function cs(e){const t=d((...s)=>e.items.filter(o=>s.includes(o.lane)).length,"count");return{items:e.needs.map(({kind:s,text:o,url:r})=>({kind:s,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(s=>(s.agents||[]).some(o=>!o.done))}}d(cs,"needsAnswer");const kt=d(e=>e.buildable&&e.state==="ready"&&!e.held&&!e.unsorted&&!e.blockedBy.length&&!e.questions?.open&&!e.questions?.answered&&!e.grilling&&!e.prototyping,"queueable"),Un=10;function Wn(e,{cap:t=Un,pulled:s=[]}={}){const o=e.filter(m=>!de(m)),r=d(m=>(m.agents||[]).filter(I=>!I.done),"running"),a=o.filter(m=>m.waitsOn==="checking"||r(m).some(z)).length,p=o.filter(m=>kt(m)&&!m.working).map(m=>m.key),c=o.filter(m=>s.includes(m.key)&&(p.includes(m.key)||m.buildable&&m.working)).map(m=>m.key),u=d(m=>m.queued&&m.queuedAt&&!m.blockedBy.length,"tapped"),f=o.filter(m=>u(m)||p.includes(m.key)&&!c.includes(m.key)).slice(0,Math.max(0,t-a-c.length)),k=f.filter(u).map(m=>m.key),l=f.filter(m=>!u(m)).map(m=>m.key),O=o.some(m=>m.grilling||m.prototyping||r(m).some(ue))?[]:o.filter(m=>(m.buildable||m.unpicked&&!m.action)&&m.state!=="ready"&&!m.held&&!m.questions?.open&&!m.questions?.answered&&!m.working).map(m=>m.key);return{idle:!a,pullable:p,waiting:c,starts:k,pulls:l,plannable:O}}d(Wn,"pullOf");function Fn(e){return e.filter(t=>t.lane==="todo"&&(!t.queued||t.buildable)||t.lane==="stale").map(t=>JSON.stringify([t.key,t.title,t.deps||[]])).sort().join(`
5
- `)}d(Fn,"todoOf");function ps(e){const t=e.filter(o=>o.kind==="work"&&o.lane!=="done"&&o.questions?.open>0),s=t.map(o=>JSON.stringify([o.key,o.questions.open,o.questions.askedAt||[]])).sort().join(`
6
- `);return{waiting:t.map(o=>o.key),seen:`${s}
1
+ var Ut=Object.defineProperty;var l=(e,t)=>Ut(e,"name",{value:t,configurable:!0});import{routeRecord as A}from"../hub/routes.mjs";import Wt from"node:fs";import{ticketBadge as dt,ticketIn as Ft}from"./tickets.mjs";import{prLinks as Kt,reviewLinks as Gt,reviewTime as Qt,reviewersOf as Vt}from"./review.mjs";import{remoteFromInput as Ht}from"../hub/repos.mjs";import{reviewsOf as Xt,reviewNeeds as Yt,reviewActions as zt}from"./auto-review.mjs";import{cardPRs as Jt,hasPR as Ze,leastReady as Zt,prKeyOf as en,prURL as tn}from"../shared/card-prs.mjs";import ct from"node:vm";import{checkWords as nn,parseCheck as on}from"../shared/owner-check.mjs";import{buildScriptOf as sn}from"./build-script.mjs";const et=ct.createContext({});for(const e of["ui-enums.js","ui-order.js"])ct.runInContext(Wt.readFileSync(new URL(`./public/${e}`,import.meta.url),"utf8"),et);const{BUTTON:ce,ACTION_KIND:q,BUILDER_KIND:Re,PR_STATE:ee}=et.BoardUI,{laneOrder:rn}=et.BoardUI,an=["item-message","mark-ready","grill-more","prototype-request","visual-request","reask-request"],ut="question-reopen",Yo=Object.freeze({todo:"Todo",progress:"In Progress",review:"In Review",done:"Done"}),be="move",ln=10*6e4,dn=5*6e4,pt="build-refused",_e=Object.freeze({ask:"builder-ask",answer:"builder-answer"}),cn=864e5,ue=l(e=>e.lane==="done"||e.lane==="asks","closedLane"),un=l(e=>`wave:${e}`,"waveFold"),ft=7*cn,gt=l((e,t)=>({id:e,url:t?.workspace?`https://linear.app/${t.workspace}/issue/${e}`:null}),"linearRef"),pn=l((e,t)=>String(e).replace(/^S(\d+)$/,`${t||"INT"}-$1`),"internalRef"),We=l((e,t,n)=>Ft(n,t.ticket)?t.ticket:e.internal===!0?pn(t.id,n?.prefix):t.id,"refOf"),fn=l((e,t,n,s)=>dt(e||(t?{source:"internal",prefix:"INT"}:null),n,s)||(t?{id:String(t),url:null,source:null}:null),"ticketOf");function gn(e,t,n,s,r,a,u,d){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?"progress":"todo"}l(gn,"laneOf");function kn(e,t){return e?.state==="MERGED"||t?ee.merged:e?.state==="CLOSED"?ee.closed:e?.state==="OPEN"?e.isDraft?ee.draft:ee.open:null}l(kn,"prStateOf");const kt=l(e=>e.pr?.status===ee.closed,"unlanded"),mn=l(e=>e.some(t=>t.kind==="work")&&e.every(t=>t.lane==="done"),"finishedOf");function tt(e){const t=e.filter(n=>n?.started&&ne(n)&&n.kind!==Re.install).sort((n,s)=>String(n.started).localeCompare(String(s.started))).at(-1);return t?.done&&t.handed_back?t.handed_back:null}l(tt,"handedBackAt");function wn(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(wn,"reviewOf");function hn(e,t,n,s,r,a,{held:u,needsApproval:d}){return n?.kind===Re.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"||e==="stale"?mt(t,d)?"merge":"reviewers":null}l(hn,"waitsOnOf");const mt=l((e,t)=>e?.reviewDecision==="APPROVED"||!t&&!["REVIEW_REQUIRED","CHANGES_REQUESTED"].includes(e?.reviewDecision),"reviewed"),Me=/(^|\/)prototype-[\w-]+\.html/,yn={reviewers:"Waiting for PR reviewers",merge:"Approved, merges once CI and the merge state allow",ci:"Marked ready for review once CI passes"},Fe={waiting:"Approved, Merge shows once CI and the merge state allow",ready:"Approved and green: tap Merge",merging:"Merging"},nt={auto:"Ready, merges once CI and the merge state allow",waiting:"Ready, Merge shows once CI and the merge state allow",ready:"Ready and green: tap Merge"},bn=l(e=>`Verified: tap Merge to land it on ${e}`,"heldNext"),Sn="Fix the failing CI",wt="Tap Done once it is settled",vn=["status","agent","ask-link","command",be,_e.answer],ht=l(e=>(e.who==="claude"||e.via==="github")&&!vn.includes(e.kind),"countsUnread"),xn=/^(?:Not merged yet: |Lander launched headless )/;function On({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:F,now:E,bumpedAt:C,holdAsk:i,closedAt:y,mergeAt:B,autoMerge:ge,skipDraft:re,tickets:U}){const H=r.map(w=>({repo:w.repo,number:w.number,url:tn(w),...w.gh||{},status:kn(w.gh,w.merged_at)})),K=Zt(r.map(w=>w.gh)),D=r[K]?.gh||null,X=H[K]?.status??null,Y=n.lane||null,qe=!!y&&String(y)>String(n.lane_at||"");qe&&(n={...n,lane:"done",closed_at:y,reopened_at:void 0});const W=[n.closed_at,...r.flatMap(w=>[w.merged_at,w.gh?.mergedAt])].filter(Boolean).map(String).sort().pop()||null,j=String(W||""),De=H.length>0&&H.every(w=>w.status===ee.closed),G=(n.lane==="done"||n.reopened_at||X===ee.merged)&&!De&&([...L.filter(w=>w.kind==="item-message").map(w=>w.ts),..._].map(String).filter(w=>w>j).sort().pop()||n.reopened_at)||void 0,ke=n.owner_step&&!qe?String(n.owner_step):null,He=(n.lane==="done"||X===ee.merged)&&!De;G&&(n={...n,next:void 0});const Ne=tt(g),Xe=!!G&&L.some(w=>String(w.ts)>j&&(w.state==="waiting"||w.state==="working")),me=`${e}/${n.id}`,Q=Vt(t,F),oe=Object.fromEntries(Object.entries(Gt(t,n,me,P,Kt(T,r))).map(([w,V])=>[w,Qt(V.ts)])),ae=Object.values(oe).filter(Boolean).sort()[0]||null,Ce=[...m.map(w=>w.ts),...x.map(w=>w.ts)].sort().pop()||null,Oe=[...m.filter(w=>ht({...w,who:w.who||"claude"})).map(w=>w.ts),...x.map(w=>w.reply?.at)].filter(Boolean).sort(),z=!Ze(n)&&n.pushed?.branch?{branch:n.pushed.branch,at:n.pushed.at||null,host:u?.host||null}:null,J=!Ze(n)&&n.merge_ready?.branch?{branch:n.merge_ready.branch,at:n.merge_ready.at||null,base:d}:null,$e=!!n.rebase_run&&D?.state==="OPEN",le=(n.rebased||[]).at(-1);let R=gn(n,D,g.some(w=>w.started&&!w.done&&ne(w)),!!Ne,z||J,!!G,re,$e);G&&R==="todo"&&(R="progress"),R==="review"&&ae&&E-Date.parse(ae)>ft&&(R="stale");const we=!!ke&&He&&R==="done";we&&(R="review");let N=hn(R,D,p,!!Ne&&R!=="done",z,re,{held:J,needsApproval:Q.length>0});const Ye=N==="builder"&&D?.state==="OPEN"&&!D.isDraft,Te=R==="progress"&&!N&&D?.state==="OPEN"&&(!D.isDraft||re),Z=we||!!G&&R==="progress"&&!N&&!Te&&!Xe;Z&&(N="owner");const Le=i&&String(i.ts)>String(n.held_at||""),ie=R==="todo"&&(Le?!!i.data.hold:!!n.held),Pe=ie&&(Le?i.data.until:n.pick_up_at)||null,he=R==="todo"||R==="progress",Ee=g.filter(ne).map(w=>String(w.started||"")).filter(Boolean).sort()[0]||"",je=C&&!(Ee&&String(C)<Ee),ze=m.filter(w=>(w.who||"claude")==="claude"&&!["status","command",be].includes(w.kind)&&!xn.test(w.text||"")).map(w=>String(w.ts)).sort().pop()||"",Ae=[B,J&&n.merge_ready.tapped].filter(Boolean).map(String).sort().pop(),o=N==="merge"&&!!Ae&&Ae>ze,k=m.filter(w=>w.kind==="status"&&String(w.ts)>String(Ae)).sort((w,V)=>String(w.ts).localeCompare(String(V.ts))).at(-1),b=k?.text.startsWith("Waiting for ")?`${Fe.merging} \xB7 ${k.text[0].toLowerCase()}${k.text.slice(1)}`:Fe.merging,v=m.filter(w=>!["status",be].includes(w.kind)).sort((w,V)=>String(w.ts).localeCompare(String(V.ts))).at(-1),O=R==="todo"&&v?.kind===pt?v.text:null,M=G||g.filter(ne).map(w=>w.started).filter(Boolean).map(String).sort().pop()||null,I=D?.reviewDecision==="APPROVED",ye=z&&N==="owner"?`merge ${z.branch} into ${d}`:J&&N==="merge"?o?b:bn(d):N==="merge"&&!ge?o?b:(I?Fe:nt).waiting:N==="merge"&&!I?nt.auto:yn[N],de=X===ee.draft?`Review draft PR #${H[K].number}`:null,Je=!$e&&le?.to&&le.to===D?.headRefOid?`Rebased onto ${le.base||d}, pushed${D.mergeable==="MERGEABLE"?" \xB7 PR is clean again":""}`:null,Ue=$e&&N==="checking"?g.flatMap(w=>w.calls).sort((w,V)=>String(w.at).localeCompare(String(V.at))).at(-1)?.text??null:null;return{key:me,kind:"work",order:s,wave:e,waveTitle:t.title||e,id:n.id,ref:We(t,n,U),title:n.title,storedLane:Y,created:n.created||null,reviewSince:n.review_since||ae||n.merge_ready?.at||n.pushed?.at||n.created||null,progressSince:M,closedAt:R==="done"?W:null,internal:t.internal===!0,repo:t.internal===!0&&!t.repo?null:a,lane:R,waitsOn:N,builder:N==="checking"?null:p,reachedPhase:f,agents:g,worktree:c??null,eta:h,working:S,reopened:!!G,awaitsDone:Z,ownerStep:Z?ke:null,ownerCheck:Z&&ke&&n.owner_check?{words:nn(on(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:ie,heldUntil:Pe,risky:!!n.risky,bumpable:he,bumpedAt:he&&je?C:null,holdable:R!=="done",hasNotes:!!(n.plan||String(n.notes||"").trim()),finishable:R!=="done",merging:o,refusal:O,manualSteps:n.manual_steps||[],fromAsk:n.from_ask||null,unfiled:!!n.unfiled,next:Ye||R==="done"||N==="checking"?null:Te?Sn:Je||ye||n.next||de||null,rebaseFailed:Ue,branch:n.branch||D?.headRefName||z?.branch||null,pushed:R==="done"||we?null:z,mergeReady:R==="review"?J:null,landStopped:R==="review"&&J&&n.merge_ready.stopped&&String(n.merge_ready.stopped)>String(n.merge_ready.tapped||"")?{words:vt("land"),at:n.merge_ready.stopped}:null,ticket:U?.source==="linear"&&!n.ticket&&n.linear?.length?null:fn(U,n.ticket,n.ticket||(t.internal?We(t,n,U):n.linear?.[0]),{repo:a,key:me}),ticketSource:U?.source||null,linear:(n.linear||[]).map(w=>U?.source==="linear"&&dt(U,w,{key:me,repo:a})||gt(w,U)),pr:H[K]||null,prs:H,reviewers:Q.map(w=>w.name),review:wn(Q,D,oe),inReviewSince:ae,threadCount:m.length+x.length,lastTs:Ce,othersAt:Oe,grilling:xt("grill",x,g,_),prototyping:xt("prototype",x,g,_),state:n.state||null,updatedAt:D?.mergedAt||D?.updatedAt||r[K]?.merged_at||p?.at||Ce||null,ask:null,fold:null,action:null,install:R==="done"?null:En(n.install,D),waitFacts:$n(n,{agents:g,thread:m,events:x,refusedAt:O?v.ts:null})}}l(On,"workItem");function $n(e,{agents:t,thread:n,events:s,refusedAt:r}){const a=new Set(n.filter(f=>f.kind===_e.answer).map(f=>f.ask)),u=n.filter(f=>f.kind===_e.ask&&!a.has(f.ask)).sort((f,g)=>String(f.ts).localeCompare(String(g.ts)))[0],d=l(f=>s.filter(g=>st(g,f)).pop()?.ts||null,"requestAt"),p=n.filter(f=>(f.who||"claude")==="claude"&&!["status","agent","command",be,pt].includes(f.kind)).map(f=>f.ts);return{handedBackAt:tt(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($n,"waitFactsOf");function En(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(En,"installOf");function An(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",!mt(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(An,"mergeBlockers");const Bn=l((e,t)=>!An(e,{needsApproval:t}).length,"mergeable");function Rn(e,t,n){if(ue(e))return null;const s=`#item=${encodeURIComponent(e.key)}`;if(_n(e)){const r=t.get(e.questions.first);return Me.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||wt}: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)||Bn(r,e.reviewers.length>0))?{kind:q.merge,url:s,label:"Merge"}:null}l(Rn,"actionOf");const _n=l(e=>!!(e.questions&&e.questions.state!=="resolved"&&e.questions.open>0),"asking"),ot=new Set([q.pick,q.questions]);function yt(e){return e.questions?ce.openQuestions:null}l(yt,"actionButtonOf");const Mn=l(e=>e.kind==="work"&&e.lane==="todo"&&!e.action&&!e.unpicked,"buildableOf"),In=l((e,t)=>/^item:/.test(e.topic||"")&&Me.test(e.url||"")&&!(e.options||[]).some(n=>n.id===t),"picksNoTake");function qn(e,t){const n=e.filter(a=>a.topic===`item:${t}`),r=[...n.filter(a=>Me.test(a.url||"")).flatMap(a=>a.answers.map(u=>({q:a,a:u,again:In(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(qn,"noTakePicked");const Dn="Prototype again",Nn=Object.freeze({[q.pick]:ce.openQuestions,[q.questions]:ce.openQuestions,[q.ready]:ce.github,[q.steps]:ce.github,[q.merge]:ce.merge,[q.done]:ce.done}),Cn="Merges once unblocked",Tn=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 Ln(e,t,n){if(e.action=Rn(e,t,n),e.mergeBlocked=e.action?.kind===q.merge&&e.blocked?Tn(e):null,e.mergeBlocked&&Object.assign(e,{action:null,next:Cn}),e.action?.kind===q.questions&&e.questions.fromAsks){Object.assign(e,{action:null,waitsOn:"owner",next:e.action.label,actionButton:yt(e),resolvedBy:null});return}e.awaitsDone&&=!e.action,e.awaitsDone||Object.assign(e,{ownerStep:null,ownerCheck:null}),e.actionButton=yt(e),e.resolvedBy=Nn[e.action?.kind]||null,e.action?.kind===q.merge&&!e.mergeReady&&(e.next=(e.pr?.reviewDecision==="APPROVED"?Fe:nt).ready),e.awaitsDone&&Object.assign(e,{lane:"review",next:e.ownerStep||wt,bumpable:!1,bumpedAt:null});const s=e.lane==="todo"||e.waitsOn==="ready"||e.lane==="progress"&&e.waitsOn==="owner";if(!e.action||!s)return;const r=e.lane==="todo"&&ot.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(Ln,"placeOwnerWait");const bt=l((e,t)=>e?e!=="todo":t.some(ne),"started"),St="none set yet";function zo(e,t){const n=t.filter(s=>s?.started);return e.next||Ze(e)||e.pushed||e.held||e.lane==="done"||tt(n)?!1:!n.some(s=>!s.done)&&bt(e.lane,n)}l(zo,"owesNext");function Pn(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(Pn,"askedLabel");function jn(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(Ie).filter(([,y])=>y==="waiting"||y==="working").map(([y])=>y),F=_?"answered":d.state,E=_?null:n||null,C=[...t.filter(ht).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:_?Pn(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=>Ie(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:F,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(jn,"askItem");const pe="visual",Ke="helper",Un=new Set(["grill","prototype",pe]),te=l(e=>Un.has(e.kind),"plans"),ne=l(e=>!te(e),"builds"),Wn={grill:"grilling",prototype:"prototyping"},Fn=l((e,t)=>`${e} ${t} by orchestrator`,"orchestratorDid"),vt=l(e=>Fn(e,"stopped"),"stoppedWords"),Kn={grill:"grill-more",prototype:"prototype-request"},st=l((e,t)=>e.kind===Kn[t]&&!e.data?.question,"isRequest");function xt(e,t,n,s){if(n.some(a=>a.kind===e&&a.started&&!a.done))return!0;const r=t.filter(a=>st(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(xt,"planningOf");const Jo=30*6e4;function Zo(e,t){const n=[];for(const s of e.items){if(ue(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&&st(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(Zo,"prototypeWaits");function Ge(e={}){return Object.entries(e).filter(([,t])=>t&&typeof t=="object").map(([t,n])=>({name:t,kind:Ot(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===Ke?{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(Ge,"agentsOf");function rt(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(rt,"worktreeOf");function Gn(e,t=[]){const n=e.filter(ne).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(Gn,"reachedPhaseOf");function Qn(e,t=[],n,s=null,r=null,a=!1){const u=e.filter(E=>E.started&&!E.done&&E.kind!==pe),d=u.every(te),p=d?u:u.filter(ne),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!==Ke).at(-1),h=p.some(E=>E.kind===Re.install)?Re.install:c?Ot(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?Wn[h]:null,_=n-Date.parse(S),P=!d&&!m&&r==="held",T=d||P?null:m?!1:r,F=P?!1:T===null?_>=ln:!T;return{progress:L,phase:g?.phase||null,at:x,kind:h,planner:d,silentSince:S,stalled:F,alive:T,held:P,quiet:T===!0&&!a&&_>=dn,stopped:m?vt(m.run):null}}l(Qn,"builderOf");const at={opus:"Claude Opus",sonnet:"Claude Sonnet",codex:"Codex"},Vn=l(({model:e,kind:t})=>at[e]||at[t]||(t==="claude"?at.opus:null),"modelName"),Ot=l(e=>e==="opus"||e==="sonnet"?"claude":e,"providerOf");function Se(e){const t=Vn(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&&te(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(Se,"agentName");const $t=l((e,t)=>!!e.resolved&&(!e.resolved_at||String(e.resolved_at)>=String(t)),"resolvedSince");function Hn(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:$t(e,S.ts)}))}}l(Hn,"ownerQuestion");const fe=l(e=>e.round??(Me.test(e.url||"")?1:0),"roundOf");function Xn(e,t){const n=l((s,r)=>s.confirm_of||(s.options||[]).some(a=>a.id===r.choice),"settles");return e.filter(s=>fe(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(Xn,"roundSettledBy");function Yn(e){const t=e.find(r=>r.request&&!e.some(a=>fe(a)>fe(r)));if(t)return{n:fe(t)+1,state:"making"};const n=Math.max(0,...e.map(fe));if(!n)return null;const s=Xn(e,n);return s?{n,state:"closed",take:s.choice}:e.some(r=>fe(r)===n&&r.state!=="resolved")?{n,state:"back"}:null}l(Yn,"roundState");function zn(e){const t=e.filter(n=>Me.test(n.url||"")).map(n=>({n:fe(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(zn,"prototypesOf");const ve=l((e,t,n)=>{const s=e.get(t);s?s.push(n):e.set(t,[n])},"add"),xe=l((e,t)=>{const n=new Map;for(const s of e)ve(n,t(s),s);return n},"groupBy");function Jn(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=xe(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:Yn(d)}}).filter(u=>u.questions.length)}l(Jn,"ownerTopics");const Qe={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"},Et={"grill-more":"grill","prototype-request":"prototype","visual-request":"visual","reask-request":"reask"},At={"mark-ready":"Mark ready",...Object.fromEntries(Object.entries(Et).map(([e,t])=>[e,Qe[t]]))},Zn=["grill-more","prototype-request","visual-request"],eo="answers submitted",Bt={reply:"Reply",build:"Implement"},to=l(e=>Bt[e.data.intent],"intentLabel"),no=l((e,t)=>{if(e.kind!=="prototype-request"||!t.has(e.data.question))return e.data.text||(e.data.files?.length?"":A(At,e.kind))||"";const n=t.get(e.data.question),s=(n.options||[]).find(r=>r.id===e.data.choice);return[_t(t,n),s&&`${s.id}. ${s.label}`,e.data.note].filter(Boolean).join(`
3
+ \u2192 `)},"actionText"),Rt=l((e,t)=>[...e.keys()].indexOf(t)+1,"numberOf"),_t=l((e,t)=>`Question ${Rt(e,t.id)} \xB7 ${t.question}`,"numbered"),oo="question reopened",Ve=l(e=>e.data?.shared_by?.login?{by:e.data.shared_by.name||e.data.shared_by.login}:{},"byOf"),so=l((e,t)=>{const n=t.get(e.card);return{...e,text:`${Qe[e.command]} ${n?`${n.ref}: ${n.title}`:e.card}`,link:`#item=${encodeURIComponent(e.card)}`}},"linkLine"),Mt=l(e=>({kind:"command",command:e,request:!0,mark:Qe[e]}),"commandLine"),ro=l((e,t)=>{if(e.kind==="item-message")return Bt[e.data.intent]?{status:to(e)}:{};const n={request:!0,command:Et[e.kind]};return Zn.includes(e.kind)?(e.data.question?t.has(e.data.question):String(e.data.text||"").trim()||e.data.files?.length)?{status:At[e.kind]}:n:e.kind==="reask-request"?n:{}},"requestOf"),lt=l(e=>[...e.filter(t=>t.who==="claude"&&!["status","agent","command",be,_e.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 It(e,t={}){const n=new Map,s=new Map;for(const c of t.items||[])ve(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&&an.includes(c.kind)&&ve(r,c.data.key,c),c.kind==="owner-answer"&&s.has(c.data?.id)&&ve(a,s.get(c.data.id),c),c.kind===ut&&s.has(c.data?.question)&&ve(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||[])ve(f,c.data?.id,h)}return{byKey:r,answers:a,reopens:u,asks:d,edits:p,editFiles:f,questions:n,order:g}}l(It,"threadIndex");const it=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"),ao=/; its log is \S*\/\.claude\/kickflip\/logs\/([^/\s]+\.log)\.$/,lo=l(e=>{const t=!e.log&&typeof e.text=="string"?ao.exec(e.text):null;return t?{...e,text:`${e.text.slice(0,t.index)}.`,log:t[1]}:e},"withLog");function io(e,t){const n=t.run?e.find(s=>s.started===t.run):e.filter(s=>te(s)===!!t.planner&&s.started&&String(s.started)<=String(t.ts)&&(!s.done||String(t.ts)<=String(s.done))).pop();return n?{agent:Se(n),run:n.started,running:!n.done}:{}}l(io,"agentOfLine");function qt(e,{lines:t=[],events:n=[],owner:s={},working:r={},fromAsk:a=null,links:u=[],agents:d={},moved:p=[],cards:f=new Map,index:g=It(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=Ge(d).filter(ne).map(i=>String(i.started||"")).filter(Boolean),_=new Set(x.filter(i=>$t(m.get(i.data.id),i.ts)||S.has(i.data.id)||L.some(y=>y>String(i.ts))).map(i=>i.id)),P=Ge(d),T=[...Ge(d).flatMap(i=>[...i.started?[{ts:i.started,who:"claude",kind:"agent",text:`${Se(i)} started`,agent:Se(i),run:i.started,finished:!1,eta:i.done?null:i.eta,...i.log?{log:i.log}:{},...te(i)?{planner:!0}:{}}]:[],...i.done?[{ts:i.done,who:"claude",kind:"agent",text:`${Se(i)} finished`,agent:Se(i),run:i.started,finished:!0,eta:null,...te(i)?{planner:!0}:{}}]:[],...i.calls.length?[{ts:i.done||i.calls.at(-1).at,who:"claude",kind:"calls",text:Se(i),calls:i.calls.map(y=>y.text),verified:i.verified}]:[]]),...t.map(lo).map(i=>i.card?so(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}:{},...io(P,i)}:{},...i.kind===pe||i.kind===be?{kind:i.kind}:{},...i.command?Mt(i.command):{},...i.card?{card:i.card}:{},...Object.values(_e).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}:{}})),...it(g,h.map(i=>g.byKey.get(i))).map(i=>({ts:i.ts,who:"love",via:"site",kind:i.kind,text:no(i,m),files:i.data.files||[],eventId:i.id,reply:i.reply,...ro(i,m),...Ve(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:`${_t(m,m.get(i.data.id))}
4
+ \u2192 ${y}`,files:i.data.files||[],eventId:i.id,reply:i.reply,status:eo,...Ve(i)}}),...(g.reopens.get(`item:${e}`)||[]).map(i=>({ts:i.ts,who:"love",kind:i.kind,request:!0,mark:oo,text:`Question ${Rt(m,i.data.question)} was reopened`,...Ve(i)})),...it(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}:{},...Ve(i),...typeof i.data?.from?.title=="string"?{from:i.data.from.title}:{}},...i.data?.quick===!0?[{ts:i.ts,who:"love",...Mt("implement"),text:Qe.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))),F=lt(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)||F>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 co(T)}l(qt,"threadOf");const Dt=["waiting","working","answered","replied"];function co(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)=>Dt.indexOf(r)-Dt.indexOf(a))[0],reply:void 0,answers:s.map(r=>({eventId:r.eventId,state:r.state,reply:r.reply,text:r.text}))}]})}l(co,"foldSubmits");const Ie=l(e=>(e.answers||[e]).filter(t=>t.eventId).map(t=>[t.eventId,t.state]),"stateEntries");function uo(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"&&!kt(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:po(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(uo,"waveBandsOf");function po(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(po,"nextOf");function es(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(es,"lineupMoved");const fo=l(e=>e.phases||e.items.map(t=>[t]),"lineupPhases");function ts(e){const{owner:t={},topicItems:n={},events:s=[],threads:r={},prs:a={},working:u={}}=e,d=e.now??Date.now(),p=It(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])),F=new Map,E=new Map(e.waves.flatMap(({slug:o,wave:k})=>k.items.map(b=>[`${o}/${b.id}`,{ref:We(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=[],ge=new Map,re=new Map,U=new Map,H=new Map,K=e.github?null:Ht(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}`,ye=(i.get(I)||[]).filter($=>$!==O.from_ask),de=[O.from_ask,...ye].filter($=>g.has($)),Je=new Set(de.map($=>`ask:${$}`)),Ue=[...A(r,I)||[],...de.flatMap($=>A(r,`ask:${$}`)||[])];O.from_ask&&F.set(O.from_ask,[...F.get(O.from_ask)||[],{key:I,ref:We(k,O,P),became:!0}]);const w=qt(I,{lines:Ue,events:s,owner:t,working:u,fromAsk:O.from_ask||null,moved:ye,cards:E,index:p});for(const $ of w)for(const[Be,jt]of Ie($))ge.set(Be,jt);re.set(I,lt(w)),B.push(On({slug:o,wave:k,it:O,order:M,repo:v,remote:K,base:e.branch||"main",prs:Jt(O,v).map($=>({...$,gh:A(a,en($))||null})),...($=>({agents:$,builder:Qn($,A(r,I),d,e.moved?.[rt(A(b,O.id))]??null,A(e.alive,I)??null,!!e.commandRunning?.[rt(A(b,O.id))]),reachedPhase:Gn($,A(r,I)),eta:$.map(Be=>Be.eta).filter(Boolean).sort().pop()||null}))(Ge(A(b,O.id))),worktree:rt(A(b,O.id))??O.worktree?.path??null,thread:Ue,events:[...it(p,[I,...Je].map($=>p.byKey.get($))),...de.map($=>g.get($))],working:w.some($=>Ie($).some(([,Be])=>Be==="working")),said:w.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 V=B[B.length-1];H.set(I,{parent:O.parent?Ct(o,O.parent):null,related:(O.related||[]).map($=>Ct(o,$))}),V.lane==="done"&&U.set(I,V.closedAt||String(V.updatedAt||""))})}const D=new Map(B.map(o=>[o.key,o])),X=new Map,Y=e.try||{},qe=e.autoBuild===!0,W=["web","app"].includes(Y.kind)?Y.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(Y.cards,o.key)||{},b=k.head||o.pr?.headRefOid,v=W==="web"?k.sha:o.install?.sha,O=o.builder?.kind===Re.install?"running":k.state||(W==="app"&&o.install?"ready":null);o.try={kind:W,state:O,stale:!!(v&&b&&!String(b).toLowerCase().startsWith(String(v).toLowerCase())),url:W==="web"?null:o.install?.url||null,port:W==="web"&&O==="ready"&&k.https||null,sha:v||null,changes:k.ahead>0,script:k.script===!0,autoBuild:qe}}const j=Y.main,De=j?.script&&j.sha?{slug:j.slug,branch:j.branch||"main",sha:j.sha.slice(0,7),at:j.at,kind:W,state:j.state||null,url:W==="web"?null:e.main?.install?.url||null,port:W==="web"&&j.state==="ready"&&j.https||null,pull:Y.pull?{running:Y.pull.running===!0,error:Y.pull.error||null}:null,script:sn(j.target)}:null,G=e.askProgress||{},ke=c("ask-done","id"),He=xe(s.filter(o=>o.kind==="owner-answer"),o=>o.data?.id),Ne=xe(s.filter(o=>o.kind==="prototype-request"),o=>o.data?.question),Xe=xe(s.filter(o=>o.kind==="reask-request"),o=>o.data?.question),me=xe(s.filter(o=>o.kind===ut),o=>o.data?.question),Q=(t.items||[]).map(o=>Hn(o,He.get(o.id)||[],Ne.get(o.id)||[],Xe.get(o.id)||[],me.get(o.id)||[])),oe=new Map(Q.map(o=>[o.id,o])),ae=xe(Q,o=>o.topic),Ce=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=D.get(A(C,o.id)),v=[...F.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){X.set(k,v[0].key);continue}if(!O&&A(C,o.id)){X.set(k,A(C,o.id));continue}const M=qt(k,{lines:A(r,k)||[],events:s,working:u,links:v,index:p});for(const I of M)for(const[ye,de]of Ie(I))ge.set(ye,de);re.set(k,lt(M)),B.push(jn(o,M,h.get(o.id),v.length>0||!!A(C,o.id),A(G,o.id),ke.get(o.id),Ce(`item:${k}`)))}for(const o of y){const k=B.filter(b=>b.wave===o.slug);if(o.finished=mn(k),o.finished)for(const b of k)b.lane==="done"&&(b.fold=un(o.slug))}for(const o of B)o.lineup=null;const Oe=new Set((t.topics||[]).map(o=>o.id)),z=e.waves.flatMap(({slug:o,wave:k})=>(k.lineups||[]).map(b=>{const v=fo(b).map(O=>O.map(M=>`${o}/${M}`));return{...b,phases:v,keys:v.flat()}})),J=l(()=>Jn([...t.topics||[],...B.filter(o=>!Oe.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}:{}})),...z.filter(o=>!Oe.has(`lineup:${o.slug}`)).map(o=>({id:`lineup:${o.slug}`,title:o.title,summary:"Wave triage."})),...(e.fromWaves?y:[]).filter(o=>!Oe.has(`wave:${o.slug}`)).map(o=>({id:`wave:${o.slug}`,title:o.title,summary:"Wave triage."}))],Q,new Set(B.filter(ue).map(o=>`item:${o.key}`))),"topicsOf"),$e=new Map(J().map(o=>[o.id,o]));for(const o of B){const k=$e.get(`item:${o.key}`);if(!k){o.questions=null,o.prototypes=null;continue}const b=k.questions.filter(M=>oe.get(M)?.state!=="resolved"),v=k.questions.find(M=>oe.get(M)?.state==="open")||b[0]||k.questions[0],O=k.questions.map(M=>oe.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=zn(k.questions.map(M=>oe.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(Nt):[],o.blockedUntil=k?o.blockedUntil??null:null,o.blockReason=k?o.blockReason??null:null,o.blocked=o.blockedBy.length>0||!!o.blockedUntil,Ln(o,oe,_),o.lane==="todo"&&o.kind==="work"&&!o.held&&bt(o.storedLane,o.agents)&&(o.lane="progress"),o.unpicked=o.kind==="work"&&o.lane==="todo"&&!!qn(Q,o.key),o.unpicked&&(o.state="prototyping"),o.unpicked&&!o.action&&(o.next=Dn),o.buildable=Mn(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"}mo(B,le,H);const R=new Map((t.items||[]).map(o=>[o.id,o.topic])),we=l(o=>o.kind==="owner-answer"?R.has(o.data?.id)?/^item:(.+)$/.exec(R.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"),N=l(o=>{const k=we(o);return X.get(k)||k},"cardOf"),Ye=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&&ke.get(k),b,U.get(o)].filter(Boolean).sort().pop()||""},"closedAt"),Te=l(o=>{const k=N(o);return k===null?!o.reply:!le.has(k)||!(Ye(k)<String(A(u,o.id)))?!1:ge.has(o.id)?ge.get(o.id)==="working":!o.reply&&!X.has(we(o))&&!(String(re.get(k)||"")>String(o.ts))},"unanswered"),Z=s.filter(o=>A(u,o.id)&&Te(o)).map(o=>({id:o.id,kind:o.kind,key:N(o),data:o.data,since:A(u,o.id)}));for(const o of B)o.working=Z.some(k=>k.key===o.key),o.kind==="work"&&o.lane==="progress"&&!o.builder&&!o.next&&o.waitsOn!=="checking"&&!o.working&&(o.next=St),o.sortAt=wo[o.lane](o)||(["review","stale"].includes(o.lane)?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=Z.filter(v=>v.key===o.key).map(v=>String(v.since)).sort()[0];o.orchestrator=["progress","todo","stale"].includes(o.lane)||o.waitsOn==="checking"||o.lane==="review"&&o.builder?.stalled?No(o,o.waitFacts,{answeredAt:k,workingSince:b}):null,delete o.waitFacts}Bo(B,s),B.sort(rn);const Le=uo(e,y,z,B,Q,s),ie=J(),Pe=Xt({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=[...yo(B,ie,Q),...Yt(Pe)],Ee=new Map(he.filter(o=>o.questions).map((o,k)=>[o.topic||`item:${o.key}`,k])),je=l(o=>Ee.get(o.id)??Ee.size,"rankOf");ie.sort((o,k)=>je(o)-je(k));const ze=new Set(he.filter(o=>o.questions&&o.progress).map(o=>`item:${o.key}`));for(const o of ie)ze.has(o.id)&&(o.progress=!0);const Ae=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 go({kind:W,main:De,remote:K&&{host:K.host,name:`${K.host}/${K.path}`},waves:y,waveBands:Le,items:B,moved:Object.fromEntries(X),answers:Ae,owner:Q,ownerTopics:ie,reviews:Pe,needs:he,working:Z.length,workingOn:Z,checks:ho(e,d)},e)}l(ts,"buildBoard");function go(e,{listen:t,prompts:n}={}){const s=[...So(n),...e.needs];return{...e,needs:s,needsSummary:vo(s),checks:{...e.checks,watcher:{listening:"running",asleep:"asleep",waking:"waking"}[t]||"stopped"}}}l(go,"withHub");const Nt=l(e=>({key:e.key,ref:e.ref}),"linkOf"),Ct=l((e,t)=>String(t).includes("/")?String(t):`${e}/${t}`,"linkKey"),ko=l((e,t)=>e.ref.localeCompare(t.ref,void 0,{numeric:!0}),"byRef");function mo(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(Nt).sort(ko),"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(mo,"linkCards");const wo={todo:l(e=>e.created,"todo"),progress:l(e=>e.progressSince,"progress"),review:l(e=>e.reviewSince,"review"),stale:l(e=>e.reviewSince,"stale"),done:l(e=>e.closedAt,"done"),asks:l(e=>e.ask.answerAt,"asks")},se=l((e,t)=>`${e} ${t}${e===1?"":"s"}`,"plural");function ho({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(ho,"checksOf");function yo(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(bo)}l(yo,"needsOf");const bo=l((e,t)=>!!t.progress-!!e.progress||(e.since&&t.since?e.since.localeCompare(t.since):!!t.since-!!e.since),"oldestFirst");function So(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(So,"promptLines");function vo(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(vo,"needsSummary");function ns(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","stale"),progress:t("progress"),todo:t("todo")},building:e.items.some(n=>(n.agents||[]).some(s=>!s.done))}}l(ns,"needsAnswer");const xo=l(e=>e.buildable&&e.state==="ready"&&!e.held&&!e.blocked,"pullableCard"),Oo=10;function $o(e,{cap:t=Oo,pulled:n=[]}={}){const s=e.filter(m=>!ue(m)),r=l((m,x)=>m.started&&!m.done&&ne(m)&&!(m.kind===Ke&&!m.writes)&&!(m.waits&&x.some(S=>S.name===m.waits&&!S.done)),"counts"),a=s.reduce((m,x)=>m+(x.agents||[]).filter((S,L,_)=>r(S,_)).length,0),u=s.filter(m=>xo(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===Ke&&!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($o,"pullOf");function os(e,t,n){return e.filter(s=>s.kind==="work"&&!ue(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(os,"rebasesDue");const Eo=3;function ss(e,{cap:t=Eo}={}){const n=e.filter(a=>!ue(a)),s=n.filter(a=>(a.agents||[]).some(u=>te(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=>te(u)&&u.kind!==pe)).slice(0,Math.max(0,t-s)).map(a=>a.key)}l(ss,"arrivalsOf");function rs(e){return e.filter(t=>t.kind==="work"&&t.lane==="todo"&&t.roundAt&&["grilling","prototyping"].includes(t.state)&&!(t.agents||[]).some(n=>te(n)&&n.kind!==pe&&n.started&&(String(n.started)>=String(t.roundAt)||!n.done))).map(t=>({key:t.key,kind:t.state==="grilling"?"grill":"prototype"}))}l(rs,"roundsDue");const Ao=l(e=>`${pe}-${e.id}`,"visualAgent");function as(e,t){const n=[];for(const s of e){const r=s.agents||[];if(r.some(d=>d.kind===pe&&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(Ao(d)));u&&n.push({key:s.key,request:u})}return n}l(as,"visualsDue");const Tt=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 Lt(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(Lt,"unsorted");function Pt(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=Tt(r);return a&&!s.has(r.id)&&Lt(n,r,a)?[{event:r.id,key:a,kind:r.kind}]:[]})}l(Pt,"intakeOpen");function ls(e,t,n){return Object.values(n).some(s=>!s.ended)?null:Pt(e,t).find(s=>!A(n,s.event))??null}l(ls,"intakeDue");function is(e,t,n){return Pt(e,t).filter(s=>A(n,s.event)?.ended)}l(is,"intakeStranded");function Bo(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&&Tt(a);!u||!Lt(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(Bo,"intakeWaits");function Ro(e){return e.filter(t=>t.lane==="todo"||t.lane==="stale").map(t=>JSON.stringify([t.key,t.title,t.deps||[]])).sort().join(`
7
+ `)}l(Ro,"todoOf");function ds(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
- ${Fn(e)}`}}d(ps,"triageOf");const Kn=100,Qn=["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"],fs=d(e=>Object.fromEntries(Qn.filter(t=>t in e).map(t=>[t,e[t]])),"slimDone");function gs(e,t=Kn){const s=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)&&!s.has(r.key)&&!o.has(r.key)&&(!r.questions||r.questions.state==="resolved"))}d(gs,"archivedOf");const Gn=d(e=>e.startsWith("ask:")?`ask-${e.slice(4)}`:`item-${e}`,"pushTag");function ks(e){const t=d(a=>e.owner.filter(p=>p.topic===a&&p.state==="open").map(({id:p,question:c})=>({id:p,question:c})),"open"),s=[R.ready,R.merge],o=e.items.filter(a=>a.action).map(a=>{const p=We.has(a.action.kind)?t(a.questions.topic):[];return{tag:Gn(a.key),kind:a.action.kind,title:`${a.ref}: ${a.action.label}`,body:p[0]?.question||a.title,url:p.length?a.action.url:`#item=${encodeURIComponent(a.key)}`,now:!s.includes(a.action.kind),questions:p}}),r=e.needs.filter(a=>a.topic).map(a=>{const p=t(a.topic);return{tag:`topic-${a.topic}`,kind:R.questions,title:a.text,body:p[0]?.question||a.title,url:a.url,now:!0,questions:p}});return[...o,...r,...Bt(e.reviews)]}d(ks,"ownerActions");function ms(e,t){const s=e.owner.find(a=>a.id===t),o=/^item:([^/:]+\/[^/]+)$/.exec(s?.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,"planned","waiting"].includes(r.status)||r.agents.some(a=>!a.done)||e.owner.some(a=>a.topic===s.topic&&a.state==="open")?null:o}d(ms,"startedByAnswer");function ws(e,{pulled:t=[]}={}){return!e.items.filter(r=>!de(r)).some(r=>r.waitsOn==="checking"||r.grilling||r.prototyping||(r.agents||[]).some(a=>!a.done))&&!e.working&&!Wn(e.items,{pulled:t}).waiting.length}d(ws,"strictlyIdle");function Vn(e,t,{answeredAt:s,workingSince:o}){const r=d(f=>e.agents.some(k=>k.kind===f&&k.started&&!k.done),"running"),a=[e.progressSince,...e.agents.map(f=>f.done)].filter(Boolean).map(String).sort().pop()||null,p=t.ask?{kind:"ask",since:t.ask.at,next:`Answer the builder's ask: ${t.ask.text}`}:s?{kind:"answer",since:s,next:"Act on the owner's answer"}:We.has(e.action?.kind)?null: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===at&&a?{kind:"unowned",since:a,next:"Start a builder on it, or set its Next"}:null;if(!p?.since)return null;const c=String(p.since),u=[t.writes.find(f=>f>c),o].filter(Boolean).sort()[0]||null;return{kind:p.kind,since:c,picked:u,next:p.next}}d(Vn,"orchestratorWaitOf");function hs(e){return e.items.filter(t=>t.orchestrator).map(t=>({key:t.key,ref:t.ref,title:t.title,...t.orchestrator}))}d(hs,"orchestratorWaits");const ys=30*6e4,Hn=15;function Ss(e,{idle:t,now:s}){const o=s.toISOString(),r=e.last||o;return t?e.since?e.pushed||s-Date.parse(e.since)<Hn*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}}d(Ss,"idleStep");function vs(e,t){const s=d(u=>String(u.closedAt||"")>t,"after"),o=e.filter(u=>u.kind==="work"&&u.lane==="done"&&!je(u)&&s(u)),r=new Map;for(const u of e)u.lineup&&r.set(u.lineup.slug,[...r.get(u.lineup.slug)||[],u]);const a=[...r.values()].filter(u=>u.every(f=>f.lane==="done")&&u.some(s)).map(u=>u[0].lineup.title),p=o.slice(0,3).map(u=>u.ref).join(", ")+(o.length>3?` and ${o.length-3} more`:"");return[o.length&&`${o.length} ${o.length===1?"card":"cards"} landed: ${p}`,...a.map(u=>`${u} finished`)].filter(Boolean).join(" \xB7 ")||"Nothing closed since the last idle notification."}d(vs,"idleSummary");export{R as ACTION_KIND,Se as BUILDER_ASK,Re as BUILDER_KIND,Nt as BUILDER_STALLED_AFTER,Je as BUILD_REFUSED,Y as BUTTON,Qn as DONE_FIELDS,Kn as DONE_KEPT,Hn as IDLE_MINUTES,Mt as ITEM_EVENTS,rs as ITEM_STATUSES,Un as MAX_IMPLEMENTERS,at as NO_NEXT,ys as ORCHESTRATOR_PUSH_AFTER,gn as PLANNER_WORD,ln as PROTOTYPE_AGAIN,ls as PROTOTYPE_WAIT,oe as PR_STATE,gs as archivedOf,us as buildBoard,z as builds,Ss as idleStep,vs as idleSummary,ds as lineupMoved,In as lineupPhases,tn as mergeBlockers,yn as modelName,cs as needsAnswer,an as noTakePicked,hs as orchestratorWaits,as as owesNext,ks as ownerActions,Sn as ownerQuestion,rn as picksNoTake,ue as plans,is as prototypeWaits,it as providerOf,Wn as pullOf,Gn as pushTag,Pe as refOf,ce as roundOf,vn as roundSettledBy,fs as slimDone,ms as startedByAnswer,ws as strictlyIdle,ct as threadIndex,pt as threadOf,Fn as todoOf,ps as triageOf,Lt as waveFold,Dn as withHub};
10
+ ${Ro(e)}`}}l(ds,"triageOf");const _o=100,Mo=["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"],cs=l(e=>Object.fromEntries(Mo.filter(t=>t in e).map(t=>[t,e[t]])),"slimDone");function us(e,t=_o){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(us,"archivedOf");function ps(e){return e.items.filter(t=>t.kind==="work").flatMap(t=>{const n=t.lane==="stale"?"review":t.lane;return n===t.storedLane||n==="done"||t.storedLane==="done"&&!t.reopened?[]:[{key:t.key,to:n,why:Io(t,n)}]})}l(ps,"movesOf");function Io(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(Io,"moveWhy");const qo=l(e=>e.startsWith("ask:")?`ask-${e.slice(4)}`:`item-${e}`,"pushTag");function fs(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=ot.has(a.action.kind)?t(a.questions.topic):[];return{tag:qo(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,...zt(e.reviews)]}l(fs,"ownerActions");function gs(e,{pulled:t=[]}={}){return!e.items.filter(r=>!ue(r)).some(r=>r.waitsOn==="checking"||r.grilling||r.prototyping||(r.agents||[]).some(a=>!a.done))&&!e.working&&!$o(e.items,{pulled:t}).waiting.length}l(gs,"strictlyIdle");const Do="Judge the staged card: item set --state ready, or --state grilling or prototyping for another round";function No(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:Do}:n?{kind:"answer",since:n,next:"Act on the owner's answer"}:ot.has(e.action?.kind)?null:e.builder?.stopped?{kind:"stalled",since:e.builder.silentSince,next:`${e.builder.stopped}: start it again when it should run, or drop the card`}: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)+ft).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.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===St&&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(No,"orchestratorWaitOf");function ks(e){return e.items.filter(t=>t.orchestrator).map(t=>({key:t.key,ref:t.ref,title:t.title,...t.orchestrator}))}l(ks,"orchestratorWaits");const ms=30*6e4,Co=15*6e4,To=60*6e4;function ws(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?To:Co);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(ws,"waitsStep");function hs(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(hs,"waitsAgainLine");const Lo=15;function ys(e,{idle:t,now:n}){const s=n.toISOString(),r=e.last||s;return t?e.since?e.pushed||n-Date.parse(e.since)<Lo*6e4?{state:{...e,last:r},push:!1}:{state:{last:s,since:e.since,pushed:!0},push:!0}:{state:{last:r,since:s},push:!1}:{state:{last:r},push:!1}}l(ys,"idleStep");function bs(e,t){const n=l(p=>String(p.closedAt||"")>t,"after"),s=e.filter(p=>p.kind==="work"&&p.lane==="done"&&!kt(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(bs,"idleSummary");export{q as ACTION_KIND,At as ACTION_LABELS,eo as ANSWERS_SUBMITTED,_e as BUILDER_ASK,Re as BUILDER_KIND,dn as BUILDER_QUIET_AFTER,ln as BUILDER_STALLED_AFTER,pt as BUILD_REFUSED,ce as BUTTON,Qe as COMMANDS,Mo as DONE_FIELDS,_o as DONE_KEPT,Ke as HELPER,Lo as IDLE_MINUTES,Bt as INTENT_LABELS,an as ITEM_EVENTS,Yo as LANES,Oo as MAX_IMPLEMENTERS,Eo as MAX_PLANNERS,be as MOVE,St as NO_NEXT,ms as ORCHESTRATOR_PUSH_AFTER,To as PICKED_REWAKE_AFTER,Wn as PLANNER_WORD,Dn as PROTOTYPE_AGAIN,Jo as PROTOTYPE_WAIT,ee as PR_STATE,ut as QUESTION_REOPEN,Co as REWAKE_AFTER,pe as VISUAL,us as archivedOf,ss as arrivalsOf,ts as buildBoard,ne as builds,tt as handedBackAt,ys as idleStep,bs as idleSummary,ls as intakeDue,Tt as intakeKeyOf,is as intakeStranded,es as lineupMoved,fo as lineupPhases,An as mergeBlockers,Vn as modelName,ps as movesOf,ns as needsAnswer,qn as noTakePicked,Fn as orchestratorDid,ks as orchestratorWaits,zo as owesNext,fs as ownerActions,Hn as ownerQuestion,In as picksNoTake,te as plans,Zo as prototypeWaits,Ot as providerOf,$o as pullOf,qo as pushTag,os as rebasesDue,We as refOf,fe as roundOf,Xn as roundSettledBy,rs as roundsDue,cs as slimDone,Ie as stateEntries,vt as stoppedWords,gs as strictlyIdle,It as threadIndex,qt as threadOf,Ro as todoOf,ds as triageOf,kt as unlanded,Ao as visualAgent,as as visualsDue,hs as waitsAgainLine,ws as waitsStep,un as waveFold,go as withHub};
package/board/finish.mjs CHANGED
@@ -1,4 +1,4 @@
1
- var N=Object.defineProperty;var u=(t,a)=>N(t,"name",{value:a,configurable:!0});import W from"node:fs";import x from"node:path";import{spawnSync as j}from"node:child_process";import*as n from"./store.mjs";import{builderRepo as M,git as b,joiningLand as v,landInTurn as A,passTests as E,syncBase as B,worktreesDir as D}from"./worktree.mjs";import{readPermissions as F}from"./permissions.mjs";import{launchBuilder as H}from"./headless.mjs";import{boardAt as C}from"../hub/boards.mjs";import{boardRepo as R}from"../hub/board-repo.mjs";const w=u(t=>{throw new n.BoardError(t)},"fail"),L=u(t=>typeof t=="string"&&t.trim()?t.trim():w("--text must be non-empty text"),"said");async function I(t,a,{text:r,ownerStep:o,check:e,repo:i,onWait:d}){const m=a.split("/")[1],p=await n.recordedWorktree(t,a),{repo:c,base:s,remote:l}=M(t,{repo:i??p?.repo}),h={path:p?.path??x.join(D(),m),branch:p?.branch??m,repo:x.resolve(c),base:s},f=await n.cardName(t,a),g=await n.readBoardSettings(t),$=l?R(C(t).route).github:null;if(l&&(!$||g.prs))return V(t,a,{...h,ref:f,text:L(r)});const T=await v(f,()=>P(t,a,{tree:h,ref:f,base:s,remote:l,repo:c,settings:g,text:r,ownerStep:o,check:e,onWait:d}));return T.joined?await n.isFinished(t,a)?{said:"landed and done",lines:[]}:I(t,a,{text:r,ownerStep:o,check:e,repo:i,onWait:d}):T}u(I,"finishCard");async function P(t,a,{tree:r,ref:o,base:e,remote:i,repo:d,settings:m,text:p,ownerStep:c,check:s,onWait:l}){await n.checkClose(t,a,p,c,s),await n.checkCallsVerified(t,a),i&&(B(r.repo,e),b(r.repo,"branch","--unset-upstream",r.branch));const h=u($=>n.appendThread(t,a,{text:`Waiting for the test slot: ${$} is running the suite`,kind:"status"}),"onWaitTests"),f=m.auto_merge||!!(await n.heldMerge(t,a))?.tapped;if(await A({...r,ref:o},{hold:!f,onWait:l,onWaitTests:h,sync:u(()=>i&&B(r.repo,e),"sync")}),!f){const $=await n.setItem(t,a,{mergeReady:r.branch,ownerStep:c,check:s});return await n.appendThread(t,a,{text:p}),{said:"verified; waits for your Merge",lines:$.lines}}const g=await n.setItem(t,a,{status:"done",text:p,ownerStep:c,check:s});return{said:c===void 0?"landed and done":`landed; waits on the owner step "${c.trim()}"`,lines:[...g.lines,...await q(t,a,d,e)]}}u(P,"landCard");async function Y(t,a,{launch:r=H}={}){(await n.heldMerge(t,a))?.tapped||w(`${a} isn't waiting on a Merge tap`);try{const{base:e}=M(t,{repo:(await n.recordedWorktree(t,a))?.repo}),i=u(d=>n.appendThread(t,a,{text:`Waiting for ${d} to land`,kind:"status"}),"onWait");return await I(t,a,{text:`Landed on ${e} on your Merge.`,onWait:i})}catch(e){if(!(e instanceof n.BoardError))throw e;const i=e.message.split(`
2
- `)[0];if(/^rebasing .+ conflicts in |^tests failed in /.test(i)){await n.appendThread(t,a,{text:`Not merged yet: ${i}. A lander fixes it and lands it.`});try{await r(t,{key:a,model:await n.builderModel(t,a)},{lander:!0})}catch(d){await n.appendThread(t,a,{text:`Couldn't launch the lander headless (${d.message}); land it with board.mjs land ${a}.`})}}else await n.appendThread(t,a,{text:`Not merged: ${i}. Tap Merge again.`});throw e}}u(Y,"landHeld");async function q(t,a,r,o){if(!(await F(r)).pushMain)return[];const e=b(r,"push","--quiet","origin",o);if(e.ok)return[`pushed ${o} to origin`];const i=`${o} didn't reach origin: ${e.err}; push it with git -C ${r} push origin ${o}`;return await n.appendThread(t,a,{text:`Landed, but ${i}`}),[`landed, but ${i}`]}u(q,"pushBase");async function V(t,a,{path:r,branch:o,base:e,ref:i,text:d}){await n.checkCallsVerified(t,a),W.existsSync(r)||w(`no worktree at ${r}`),b(r,"status","--porcelain").out&&w(`${r} has uncommitted changes; commit them there first`),Number(b(r,"rev-list","--count",`refs/remotes/origin/${e}..HEAD`).out)===0&&w(`${o} has no commits beyond ${e}; nothing to send for review`),await E(r,{outcome:"nothing was pushed"});const m=b(r,"push","--quiet","origin",`HEAD:refs/heads/${o}`);m.ok||w(`could not push ${o} to origin: ${m.err}`);const{github:p}=R(C(t).route);if(!p){const g=await n.setItem(t,a,{pushed:o});return await n.appendThread(t,a,{text:d}),{said:`pushed ${o} for its merge`,lines:g.lines}}const{title:c}=await n.briefFacts(t,a),s=j("gh",["pr","create","--draft","--repo",p,"--base",e,"--head",o,"--title",`${i}: ${c}`,"--body",d],{cwd:r,encoding:"utf8"}),l=`${s.stdout||""}
3
- ${s.stderr||""}`,h=(s.status===0||/already exists/.test(l))&&/\/pull\/(\d+)/.exec(l)?.[1];h||w(`could not open a draft PR for ${o}: ${(s.stderr||s.error?.message||`gh exited ${s.status}`).trim().split(`
4
- `)[0]}`);const f=await n.setItem(t,a,{pr:Number(h)});return await n.appendThread(t,a,{text:d}),{said:`draft PR #${h} opened`,lines:f.lines}}u(V,"sendForReview");export{I as finishCard,Y 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,4 +1,9 @@
1
- var q=Object.defineProperty;var d=(t,e)=>q(t,"name",{value:e,configurable:!0});import g from"node:fs";import A from"node:os";import $ from"node:path";import{spawn as O}from"node:child_process";import{fileURLToPath as L}from"node:url";import{claudeBin as N,inherited as P}from"../hub/sessions.mjs";import{boardAt as S}from"../hub/boards.mjs";import{readHubRules as F}from"../hub/rules.mjs";import{builderRepo as W}from"./worktree.mjs";import{appendThread as Y,briefFacts as D,readBoardRules as H}from"./store.mjs";import{modelName as M,plans as E}from"./domain.mjs";const _=L(new URL("./bin/board.mjs",import.meta.url)),b=d(t=>`node ${_} --site ${t}`,"cli"),K=d(t=>`git -c core.commentChar=';' rebase ${t}`,"rebase"),T=d(t=>t.length?["Rules from the hub and this board:",...t.map(e=>`- ${e}`),""]:[],"ruleLines"),j=d(({route:t,key:e,worktree:n,base:a})=>[`- With no unverified calls, done finishes the card itself: it rebases onto ${a}, reruns the full test suite, fast-forwards ${a} 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 \`${K(a)}\` 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"),B=d(({route:t,key:e})=>`\`${b(t)} builder done ${e} --text "<what you checked>"\``,"finishCommand");function U({route:t,key:e,ref:n,title:a,notes:c,worktree:i,base:s,rules:r=[]}){const o=b(t);return[`You are the headless builder for card ${n} (${e}, "${a}") on the kickflip board /${t}. The board launched you; 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\`. If it refuses, stop.`,`2. Report progress with \`${o} builder progress ${e} --phase reading|building|testing|checking|landing "<plain, 80 characters or fewer>"\`, at least every 10 minutes.`,`3. To ask the orchestrator something, run \`${o} builder ask ${e} "<question>"\` and carry on; read its replies with \`${o} builder asks ${e}\`. Never block on a reply.`,`4. Record each judgment call the notes leave open with \`${o} builder call ${e} "<call>"\` instead of guessing silently.`,"",c?`Spec: the card's notes, ${c}, 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.","",...T(r),"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 ${B({route:t,key:e})}.`,"- If you recorded a judgment call, it hands the card back for the orchestrator to verify your calls; stop there: the orchestrator's verification finishes the card.",...j({route:t,key:e,worktree:i,base:s}),"","Never push."].join(`
2
- `)}d(U,"builderBrief");function X({route:t,key:e,ref:n,title:a,worktree:c,base:i,answers:s=[]}){const r=b(t);return[`You are the headless lander for card ${n} (${e}, "${a}") 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 ${c}, never restart the hub or a board server, and never push.`,"",`1. Run \`${r} builder start ${e} --kind build --label Lander\`. If it refuses, stop.`,`2. Report progress with \`${r} builder progress ${e} --phase landing "<plain, 80 characters or fewer>"\`.`,...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(o=>`- ${o.ask} "${o.question}": ${o.answer}`)]:[],"",`To finish, run ${B({route:t,key:e})}.`,...j({route:t,key:e,worktree:c,base:i}),"","Never push."].join(`
3
- `)}d(X,"landerBrief");function G({route:t,key:e,ref:n,title:a,notes:c,kind:i,repo:s,rules:r=[],text:o,files:u=[],question:l,note:p,choice:w}){const h=b(t),f=i==="grill";return[`You are the headless ${f?"grill":"prototype"} planner for card ${n} (${e}, "${a}") 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 there, never restart the hub or a board server, and never push.`,"",`1. Run \`${h} builder start ${e} --kind ${i}\`. If it refuses, stop.`,`2. Gather the context yourself: ${c?`the card's notes, ${c}, 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 \`${h} builder progress ${e} "<plain, 80 characters or fewer>"\` at least every 10 minutes.`,f?`4. Follow the grilling skill: find every decision the card leaves open, and post each as a question for the owner with \`${h} question add --file <json>\` on topic item:${e}, one per decision, your recommendation first.`:`4. Follow the prototype skill: record the prototype with \`${h} prototype add <topic> --card ${e} --take <K>:<label> \u2026\`, write one take per option, built from the board's real components fed fake data, and post one question whose url opens it with \`${h} question add --file <json>\` on topic item:${e}.`,...o?[` The owner asked for this ${f?"grill":"prototype"}, writing: "${o}"`]:[],...u.length?[` The owner attached: ${u.map(m=>m.path).join(", ")}.`]:[],...l?[` The owner asked for prototypes of question ${l}${p?`, noting "${p}"`:""}${w?`, leaning to option ${w}`:""}: draw that question's next round, its question naming round_of ${l}.`]:[],`5. Record what you learned in the card's notes with \`${h} item set ${e} --notes-file <file.md>\`, naming each answered question's id.`,"",...T(r),`To finish, run \`${h} builder done ${e} --text "<what you asked>"\`.`,"","Never push."].join(`
4
- `)}d(G,"plannerBrief");const z=d(()=>process.env.KICKFLIP_CODEX||"codex","codexBin"),J=d(({kind:t,prompt:e,model:n,cwd:a})=>t==="codex"?["exec","--sandbox","danger-full-access","--cd",a,e]:["-p",e,"--permission-mode","auto","--model",n,"--output-format","stream-json","--verbose"],"agentArgs");function Q({kind:t="claude",bin:e=t==="codex"?z():N(),cwd:n,prompt:a,model:c,log:i}){g.mkdirSync($.dirname(i),{recursive:!0});const s=g.openSync(i,"a"),r=Object.fromEntries(Object.entries(process.env).filter(([o])=>!P(o)));return $.isAbsolute(e)&&(r.PATH=`${$.dirname(e)}:${r.PATH||""}`),new Promise((o,u)=>{const l=O(e,J({kind:t,prompt:a,model:c,cwd:n}),{cwd:n,env:r,detached:!0,stdio:["ignore",s,s]});l.once("spawn",()=>{g.closeSync(s),l.unref(),o({pid:l.pid,log:i})}),l.once("error",p=>{g.closeSync(s),u(p)})})}d(Q,"launchHeadless");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:a,alive:c=V}){const i={};for(const[s,r]of Object.entries(t)){if(!e.has(s))continue;if(r.pid!==null&&c(r.pid)){i[s]=r;continue}const o={key:s,...r.kind?{kind:r.kind}:{},...r.model?{model:r.model}:{}};if(r.pid!==null&&r.relaunched){await a(o);continue}const{key:u,...l}=o;i[s]={...l,...await n(o),relaunched:r.pid!==null}}return i}d(ue,"reviveBuilders");const Z=d((t,e)=>$.join(A.homedir(),".claude","kickflip","logs",`${e}-${t}-${new Date().toISOString().replace(/[:.]/g,"-")}.log`),"logFile");async function pe(t,{key:e,kind:n="claude",model:a,text:c,files:i,question:s,note:r,choice:o},{lander:u=!1}={}){const l=await D(t,e),p=S(t)?.route??$.basename(t),w=[...F(),...await H(t)].map(I=>I.text),{base:h,repo:f}=W(t),m=E({kind:n}),v={...l,route:p,base:h,repo:f,rules:w,kind:n,text:c,files:i,question:s,note:r,choice:o},x=n==="codex"?"codex":a||"opus",y=m?"Planner":u?"Lander":"Builder",R=m?f:l.worktree,C=m?G(v):u?X(v):U(v),k=await Q({kind:m?"claude":n,cwd:R,prompt:C,model:x,log:Z(e.split("/")[1],y.toLowerCase())});return await Y(t,e,{text:`${y} launched on ${M({kind:n,model:x})} in ${R}.`,log:$.basename(k.log)}),k}d(pe,"launchBuilder");export{_ as BOARD_CLI,U as builderBrief,X as landerBrief,pe as launchBuilder,Q as launchHeadless,V as pidAlive,G as plannerBrief,ue as reviveBuilders};
1
+ var G=Object.defineProperty;var u=(t,e)=>G(t,"name",{value:e,configurable:!0});import K from"node:os";import v from"node:path";import{fileURLToPath as _}from"node:url";import{launchAgent as L}from"./agents.mjs";import{processStarts as B,ps as V}from"../hub/live.mjs";import{boardAt as P}from"../hub/boards.mjs";import{readHubRules as C}from"../hub/rules.mjs";import{builderRepo as D}from"./worktree.mjs";import{BoardError as z,appendThread as X,briefFacts as J,readBoardRules as M,recordSession as Q}from"./store.mjs";import{HELPER as Z,modelName as ee,plans as te,VISUAL as oe}from"./domain.mjs";const re=_(new URL("./bin/board.mjs",import.meta.url)),b=u(t=>`node ${re} --site ${t}`,"cli"),Y=u(t=>`git -c core.commentChar=';' rebase ${t}`,"rebase"),R=u((t,e="Rules from the hub and this board:")=>t.length?[e,...t.map(a=>`- ${a}`),""]:[],"ruleLines"),T=u(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"),O=u(({route:t,key:e,worktree:a,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 \`${Y(h)}\` 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"),N=u(({route:t,key:e})=>`\`${b(t)} builder done ${e} --text "<what you checked>"\``,"finishCommand"),ne=u((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 ae({route:t,key:e,ref:a,title:h,notes:n,worktree:r,base:s,rules:l=[],links:d=[]}){const i=b(t);return[`You are the headless builder for card ${a} (${e}, "${h}") 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 \`${i} builder start ${e} --kind build\`. If it refuses, stop.`,`2. Report progress with \`${i} 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 \`${i} builder ask ${e} "<question>"\` and carry on; read its replies with \`${i} builder asks ${e}\`. Never block on a reply.`,`4. Record each judgment call the notes leave open with \`${i} builder call ${e} "<call>"\` instead of guessing silently.`,...ne(i,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.","",...T(d),...R(l),"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 ${N({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.",...O({route:t,key:e,worktree:r,base:s}),"","Never push."].join(`
2
+ `)}u(ae,"builderBrief");function se({route:t,key:e,ref:a,title:h,worktree:n,base:r,answers:s=[]}){const l=b(t);return[`You are the headless lander for card ${a} (${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 ${n}, never restart the hub or a board server, and never push.`,"",`1. Run \`${l} builder start ${e} --kind build --label Lander --phase landing --progress "taking up the verified build"\`. If it refuses, stop.`,`2. Report progress with \`${l} 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(d=>`- ${d.ask} "${d.question}": ${d.answer}`)]:[],"",`To finish, run ${N({route:t,key:e})}.`,...O({route:t,key:e,worktree:n,base:r}),"","Never push."].join(`
3
+ `)}u(se,"landerBrief");function ie({route:t,key:e,ref:a,title:h,worktree:n,base:r,pr:s}){const l=b(t);return[`You are the headless rebase run for card ${a} (${e}, "${h}") 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 \`${l} 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 \`${Y(`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 \`${l} 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 \`${l} 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 ${N({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
+ `)}u(ie,"rebaseBrief");function he({route:t,key:e,ref:a,title:h,notes:n,kind:r,repo:s,rules:l=[],links:d=[],text:i,files:o=[],question:c,note:w,choice:m}){const p=b(t),g=r==="grill";return[`You are the headless ${g?"grill":"prototype"} planner for card ${a} (${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 ${s}; write no output code ${g?"there":`in ${s} itself`}, never restart the hub or a board server, and never push.`,"",`1. Run \`${p} 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 \`${p} 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 \`${p} 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 \`${p} 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 \`${p} 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 \`${p} 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: \`${p} 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.)`,...i?[` The owner asked for this ${g?"grill":"prototype"}, writing: "${i}"`]:[],...o.length?[` The owner attached: ${o.map(f=>f.path).join(", ")}.`]:[],...c?[` The owner asked for prototypes of question ${c}${w?`, noting "${w}"`:""}${m?`, leaning to option ${m}`:""}: draw that question's next round, its question naming round_of ${c}.`]:[],`5. Record what you learned in the card's notes with \`${p} item set ${e} --notes-file <file.md>\`, naming each answered question's id.`,...g?[`6. Where the owner asked for prototypes, or a rule here wants a UI prototype first, end the card \`${p} 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.`]:[],"",...T(d),...R(l,"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 \`${p} builder done ${e} --text "<what you asked>"\`.`,"","Never push."].join(`
5
+ `)}u(he,"plannerBrief");function de({route:t,key:e,ref:a,title:h,notes:n,repo:r,agent:s,rules:l=[],links:d=[],text:i,files:o=[]}){const c=b(t);return[`You are the headless visual agent for card ${a} (${e}, "${h}") 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 \`${c} 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.`,i?` The owner wrote: "${i}"`:" The owner typed nothing: draw what the thread was last discussing.",...o.length?[` The owner attached: ${o.map(w=>w.path).join(", ")}.`]:[],"3. Write one HTML file outside the repo, such as in a temporary folder. Keep its own CSS and script inline; it may load a library such as Mermaid or D3 from a CDN. Make it read well at phone width (390px) and on a desktop, in the dark and the light theme (prefers-color-scheme).",`4. Place it with \`${c} 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.","",...T(d),...R(l,"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} --agent ${s}\`.`,"","Never push."].join(`
6
+ `)}u(de,"visualBrief");function le({route:t,key:e,ref:a,title:h,notes:n,agent:r,task:s,writes:l,cwd:d,rules:i=[],links:o=[]}){const c=b(t);return[`You are the headless helper ${r} on card ${a} (${e}, "${h}") 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.`,l?`Work only in ${d}, 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 ${d}; change no files there and commit nothing.`,"","The task:",s,"",`1. Run \`${c} builder start ${e} --kind helper --agent ${r}\`. If it refuses, stop.`,`2. Report progress with \`${c} 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}.`:"","",...T(o),...R(i,"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} --agent ${r} --text "<your hand-back: what you did or found, ${l?"what you committed, ":""}and any decision you made>"\`.`,"","Never push."].filter((w,m,p)=>w!==""||p[m-1]!=="").join(`
7
+ `)}u(le,"helperBrief");function ce({route:t,repo:e,rules:a=[],waves:h=[],cards:n=[],event:r,key:s,kind:l,quick:d=!1,thread:i=[]}){const o=b(t),c=i.map(f=>`- ${f.who}: ${f.text}${f.files?.length?` (attached: ${f.files.map(I=>I.path).join(", ")})`:""}`),w=d?"--state staging --size <small|large>":"--state <grilling|prototyping>",m=d?" 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.",p=u(f=>[` 1. Write its notes file in the wave's folder, a .md named for the change: 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. Append that "## Related" line to each linked card's notes file too.`,` 2. ${f}`,m],"fileIt"),g={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 append the owner's words verbatim to that card's notes file under "## Asked (owner, <date>)".`,`- File it as a new card: \`${o} item add <wave> --title "<the change, in plain words>"\` prints "<label> added as <key>"; use that key.`,...p(`\`${o} item set <key> --from-ask ${r} --notes-file <file> --relate <keys> --text "<one line on what you filed>" ${w}\` (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: \`${o} item add <wave> --title "<the change>"\`, then`,...p(`\`${o} item set <key> --from-ask ${s.slice(4)} --notes-file <file> --relate <keys> --text "<one line>" ${w}\`,`)," 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, tidy its notes (what it is, why, where it came from), and add a "## Related" line to it and each linked card's notes. 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 through the board's CLI, \`${o} <command>\`, and notes files, nothing else. Never set a card ready, never build, never push, and never restart the hub or a board server.`,"",...g[l],"",`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}:`,...c.length?c:["- (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(f=>`- ${f.ref} ${f.key} "${f.title}", ${f.lane}, ${f.state||"no state"}: ${f.notes||"no notes"}`):["- (none)"],"","Waves a new card can go in, as slug: folder:",...h.map(f=>`- ${f.slug}: ${f.dir}`),"",...R(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
+ `)}u(ce,"intakeBrief");async function Te(t,e){const a=P(t)?.route??v.basename(t),h=[...C(),...await M(t)].map(s=>s.text),{repo:n}=D(t),r=await L({kind:"claude",model:"sonnet",cwd:n,site:t,prompt:ce({...e,route:a,repo:n,rules:h}),log:E(e.event,"intake")});return await X(t,e.key,{text:`${ee({kind:"claude",model:"sonnet"})} intake triage`,kind:"status",log:v.basename(r.log)}),r}u(Te,"launchIntake");const ue=6e4;function pe(t,{starts:e=B}={}){const a=t.filter(n=>n.pid&&n.at).map(n=>n.pid),h=a.length&&e(a)||new Map;return t.filter(n=>{const r=h.get(n.pid);return r!==void 0&&r<=Date.parse(n.at)&&r>=Date.parse(n.at)-ue})}u(pe,"launchedAgents");function Ie(t,{starts:e=B,kill:a=u((n,r)=>process.kill(-n,r),"kill"),killAfter:h=5e3}={}){const n=pe(t,{starts:e});for(const{pid:r}of n){try{a(r,"SIGTERM")}catch{continue}setTimeout(()=>{try{a(r,"SIGKILL")}catch{}},h).unref()}return n.length}u(Ie,"stopAgents");async function je(t,{grace:e=5e3}={}){const a=V(["-A","-o","pid=,ppid=,pgid=,args="]);if(a===null)throw new z("ps gave no answer, so nothing was stopped; run it again");const h=a.split(`
9
+ `).map(o=>/^\s*(\d+)\s+(\d+)\s+(\d+)\s+(.*)$/.exec(o)).filter(Boolean).map(([,o,c,w,m])=>({pid:Number(o),ppid:Number(c),pgid:Number(w),args:m})),n=new Set(h.filter(o=>t.includes(o.pgid)).map(o=>o.pid));for(let o=!0;o;){o=!1;for(const c of h)!n.has(c.pid)&&n.has(c.ppid)&&(n.add(c.pid),o=!0)}const r=h.find(o=>o.pid===process.pid)?.pgid,s=h.filter(o=>n.has(o.pid)&&o.pgid>1&&o.pgid!==r),l=[...new Set(s.map(o=>o.pgid))],d=u(o=>{for(const c of l)try{process.kill(-c,o)}catch{}},"signal");d("SIGTERM");const i=Date.now()+e;for(;s.some(o=>S(o.pid))&&Date.now()<i;)await new Promise(o=>setTimeout(o,50));return s.some(o=>S(o.pid))&&d("SIGKILL"),s.map(({pid:o,args:c})=>({pid:o,args:c}))}u(je,"stopRuns");const S=u(t=>{try{return process.kill(t,0),!0}catch(e){return e.code==="EPERM"}},"pidAlive");async function Ne(t,e,{launch:a,handBack:h,alive:n=S,held:r=u(()=>!1,"held"),stopped:s=new Set}){const l={};for(const[d,i]of Object.entries(t)){if(!e.has(d))continue;if(s.has(d)){l[d]={...i,handedBack:!0};continue}if(i.pid!==null&&n(i.pid)||r(i.kind??"claude")||i.handedBack){l[d]=i;continue}const o={key:d,...i.kind?{kind:i.kind}:{},...i.model?{model:i.model}:{}};if(i.pid!==null&&i.relaunched){await h(o),l[d]={...i,handedBack:!0};continue}const{key:c,...w}=o;l[d]={...w,...await a(o),relaunched:i.pid!==null}}return l}u(Ne,"reviveBuilders");const E=u((t,e)=>v.join(K.homedir(),".claude","kickflip","logs",`${e}-${t}-${new Date().toISOString().replace(/[:.]/g,"-")}.log`),"logFile");async function Se(t,{key:e,kind:a="claude",model:h,agent:n="main",text:r,files:s,question:l,note:d,choice:i,task:o,writes:c,worktree:w},{lander:m=!1}={}){const p=await J(t,e),g=P(t)?.route??v.basename(t),f=[...C(),...await M(t)].map(U=>U.text),{base:I,repo:j}=D(t),y=te({kind:a}),k=a===Z,A=!y&&!k&&!m&&p.rebasePR!==null,W=a===oe,q=y?j:k?w??p.worktree??j:p.worktree,$={...p,route:g,base:I,repo:j,rules:f,kind:a,agent:n,text:r,files:s,question:l,note:d,choice:i,task:o,writes:c,cwd:q,pr:p.rebasePR},F=W?"Visual agent":k?`Helper ${n}`:y?"Planner":m?"Lander":A?"Rebase run":"Builder",H=W?de($):k?le($):y?he($):m?se($):A?ie($):ae($),x=await L({kind:y||k?"claude":a,model:h,cwd:q,site:t,prompt:H,log:E(e.split("/")[1],F.split(" ")[0].toLowerCase())});return await Q(t,e,x.sessionId,x.pid,n,v.basename(x.log)),x}u(Se,"launchBuilder");export{re as BOARD_CLI,ae as builderBrief,le as helperBrief,ce as intakeBrief,se as landerBrief,Se as launchBuilder,Te as launchIntake,pe as launchedAgents,S as pidAlive,he as plannerBrief,ie as rebaseBrief,Ne as reviveBuilders,Ie as stopAgents,je as stopRuns,de as visualBrief};
package/board/on-host.mjs CHANGED
@@ -1 +1 @@
1
- var g=Object.defineProperty;var t=(e,r)=>g(e,"name",{value:r,configurable:!0});import w from"node:os";import{execFile as p}from"node:child_process";import{promisify as h}from"node:util";import{tailscaleBin as x}from"../shared/tailscale.mjs";const y=h(p),I=t(e=>String(e||"").trim().replace(/^::ffff:/,""),"bare"),c=t(()=>Object.values(w.networkInterfaces()).flat().map(e=>e.address),"interfaceAddresses");async function u(){const e=x();if(!e)return null;try{const{stdout:r}=await y(e,["status","--json"],{timeout:5e3}),{Self:s,User:n}=JSON.parse(r);return{login:n?.[s.UserID]?.LoginName,addresses:s.TailscaleIPs||[]}}catch{return null}}t(u,"tailnetNode");const f=t(e=>{const r=e.headers["x-forwarded-for"];return I(r?String(r).split(",").at(-1):e.socket.remoteAddress)},"clientOf");async function j(e,r={addresses:c,node:u}){const s=e.headers["x-forwarded-for"],n=f(e);if(r.addresses().includes(n))return!0;const o=e.headers["tailscale-user-login"];if(!s||!o)return!1;const a=await r.node();return!!a&&a.login===o&&a.addresses.includes(n)}t(j,"fromHost");function S(e={addresses:c,node:u},{now:r=Date.now,retryMs:s=5e3}={}){let n=null,o=null,a=-1/0;const m=t(()=>n||r()-a<s?n:(o||=e.node().then(i=>(o=null,i?.login?n=i.login:a=r(),n)),o),"ownerLogin");return async i=>{if(e.addresses().includes(f(i)))return"owner";const l=i.headers["tailscale-user-login"];if(!l)return"other";const d=await m();return d?d===l?"owner":"other":"unread"}}t(S,"ownerGate");const B=S();export{j as fromHost,B as hubGate,S as ownerGate};
1
+ var p=Object.defineProperty;var s=(e,n)=>p(e,"name",{value:n,configurable:!0});import w from"node:os";import{execFile as y}from"node:child_process";import{promisify as N}from"node:util";import{tailscaleBin as h}from"../shared/tailscale.mjs";const x=N(y),S=s(e=>String(e||"").trim().replace(/^::ffff:/,""),"bare"),f=s(()=>Object.values(w.networkInterfaces()).flat().map(e=>e.address),"interfaceAddresses");async function m(){const e=h();if(!e)return null;try{const{stdout:n}=await x(e,["status","--json"],{timeout:5e3}),{Self:o,User:r}=JSON.parse(n),t=r?.[o.UserID];return{login:t?.LoginName,name:t?.DisplayName||null,dnsName:String(o.DNSName||"").replace(/\.$/,"")||null,addresses:o.TailscaleIPs||[]}}catch{return null}}s(m,"tailnetNode");const g=s(e=>{const n=e.headers["x-forwarded-for"];return S(n?String(n).split(",").at(-1):e.socket.remoteAddress)},"clientOf");async function j(e,n={addresses:f,node:m}){const o=e.headers["x-forwarded-for"],r=g(e);if(n.addresses().includes(r))return!0;const t=e.headers["tailscale-user-login"];if(!o||!t)return!1;const a=await n.node();return!!a&&a.login===t&&a.addresses.includes(r)}s(j,"fromHost");function D(e={addresses:f,node:m},{now:n=Date.now,retryMs:o=5e3}={}){let r=null,t=null,a=-1/0;const l=s(()=>r||n()-a<o?r:(t||=e.node().then(i=>(t=null,i?.login?r=i:a=n(),r)),t),"ownerNode"),d=s(async i=>{if(e.addresses().includes(g(i)))return"owner";const c=i.headers["tailscale-user-login"];if(!c)return"other";const u=await l();return u?u.login===c?"owner":"other":"unread"},"gate");return d.node=async()=>l(),d}s(D,"ownerGate");const B=D();export{j as fromHost,B as hubGate,D as ownerGate};
@@ -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};