claude-code-session-manager 0.115.0 → 0.116.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/dist/assets/{AgentLibrary-CjsZLl5e.js → AgentLibrary-CkS69HnN.js} +1 -1
  2. package/dist/assets/{Button-mj0vvcdc.js → Button-BQxkfIbW.js} +1 -1
  3. package/dist/assets/{DataModel-CG6ycpfG.js → DataModel-YVgdJTZF.js} +1 -1
  4. package/dist/assets/{History-DDqLQiAN.js → History-DneHh4jI.js} +2 -2
  5. package/dist/assets/{Hooks-dRje24Nk.js → Hooks-Bt4xIjfo.js} +3 -3
  6. package/dist/assets/{Library-Dl71nylN.js → Library-DoP5FdXq.js} +7 -7
  7. package/dist/assets/{ListDetail-DcAD_cuA.js → ListDetail-BYxyl13e.js} +1 -1
  8. package/dist/assets/{McpServers-BbvbhemH.js → McpServers-CKm_iZsf.js} +1 -1
  9. package/dist/assets/Memory-BWMQuAoC.js +18 -0
  10. package/dist/assets/{Panel-BkfK-W74.js → Panel-Cv8aYElQ.js} +1 -1
  11. package/dist/assets/{Permissions-BnjsXblr.js → Permissions-CFmWwqyV.js} +3 -3
  12. package/dist/assets/Plugins-CuYNgf_d.js +2 -0
  13. package/dist/assets/{ProvenanceBadge-CQXSiPHq.js → ProvenanceBadge-BMLVPyHr.js} +1 -1
  14. package/dist/assets/{RemoteMachines-li6EBPAt.js → RemoteMachines-D04Mby_W.js} +1 -1
  15. package/dist/assets/{SaveBar-0aiuy1L2.js → SaveBar-Cb4Q8TBK.js} +1 -1
  16. package/dist/assets/{Scheduler-Ul4jiK7q.js → Scheduler-ysJHQvW4.js} +1 -1
  17. package/dist/assets/{ScopeSwitcher-DR262W_R.js → ScopeSwitcher-BTOWfifI.js} +1 -1
  18. package/dist/assets/{Settings-BwUcGuar.js → Settings-C6fH8diZ.js} +4 -4
  19. package/dist/assets/{SkillReferenceGraph-fv2FJUNK.js → SkillReferenceGraph-esAcniTQ.js} +1 -1
  20. package/dist/assets/Skills-4_vqzrSF.js +2 -0
  21. package/dist/assets/SystemPrompt-CdUq4KXx.js +1 -0
  22. package/dist/assets/TagLibrary-CVFIphBv.js +1 -0
  23. package/dist/assets/{TiptapBody-CBxxEulT.js → TiptapBody-EkZlmD9k.js} +1 -1
  24. package/dist/assets/{Toggle-W944m375.js → Toggle-CpR97XGM.js} +1 -1
  25. package/dist/assets/{ViewTabs-BLQrBE2n.js → ViewTabs-ekJfFek8.js} +1 -1
  26. package/dist/assets/{historyTotals-BUeyjlNY.js → historyTotals-Bg0GVcsF.js} +1 -1
  27. package/dist/assets/{index-HpEbvDiE.css → index-CZsDDyLy.css} +1 -1
  28. package/dist/assets/{index-t37UuEZu.js → index-DQSEUdx0.js} +54 -54
  29. package/dist/assets/{settingsSchema-HwiOXtC7.js → settingsSchema-BG5jZbhn.js} +1 -1
  30. package/dist/assets/skillFrontmatter-DF6xI6Wb.js +10 -0
  31. package/dist/assets/{useAgentsDirWatch-D0rI9G_h.js → useAgentsDirWatch-Dox-xCx9.js} +1 -1
  32. package/dist/assets/{useRemotePeers-BipAySOB.js → useRemotePeers-DHo62LbA.js} +1 -1
  33. package/dist/index.html +2 -2
  34. package/package.json +2 -1
  35. package/scripts/README.md +2 -0
  36. package/src/main/build-info.json +4 -4
  37. package/src/main/ipcSchemas.cjs +26 -0
  38. package/src/main/lib/memoryOps.cjs +116 -0
  39. package/src/main/lib/memoryStale.cjs +24 -1
  40. package/src/main/memoryAssist.cjs +156 -0
  41. package/src/main/memoryTool.cjs +34 -0
  42. package/src/main/webRemote.cjs +52 -23
  43. package/src/preload/api.d.ts +21 -1
  44. package/src/preload/index.cjs +7 -0
  45. package/dist/assets/MarkdownEditor-D7JTNOOp.js +0 -1
  46. package/dist/assets/Memory-dyz8ZU1e.js +0 -8
  47. package/dist/assets/Plugins-DSyTJtTp.js +0 -2
  48. package/dist/assets/Skills-BA2I-iRE.js +0 -2
  49. package/dist/assets/SystemPrompt-BgvyrAKx.js +0 -1
  50. package/dist/assets/TagLibrary-B5rKEDVT.js +0 -1
  51. package/dist/assets/skillFrontmatter-Dif5JIg7.js +0 -10
@@ -1,4 +1,4 @@
1
- import{aL as Pe,ax as ie,af as Te,aR as gs,ak as Ce,ae as le,ai as ee,aW as q,ba as Fe,b8 as pe,aF as f,ac as xe,bh as xs,ap as t,b as Ue,I as me,L as bt,q as ms,K as ge,u as bs,Q as ws,d as vs,U as js,aQ as ys,b7 as st,b0 as Ns,a7 as wt,av as Tt,bg as $e,G as qe,aC as _e,A as nt,aP as at,N as _t,w as Ot,p as Lt,r as ks,o as rt,y as it,O as Ss,f as re,g as H,ag as Ft,bb as Cs,aE as $s,aH as qt,bk as Bt,V as Ps,ay as vt,b1 as jt,n as ke,x as yt,aM as Nt,m as Ds,aU as As,Y as Ms,v as Ht,b3 as Rs,aZ as ye,H as Is,C as Es,bc as Ts,aG as _s,T as Os,bj as Ls,bd as kt,aO as Fs}from"./index-t37UuEZu.js";import{f as qs,a as Bs,s as Hs}from"./historyTotals-BUeyjlNY.js";import{l as Gs}from"./listSkills-C1aWKf0T.js";import{T as Vs}from"./Toggle-W944m375.js";import"./monaco-editor-BsIlgG7c.js";function Ws(e){const s=new Map(e.map(i=>[i.slug,i])),n=new Map,a=new Set,c=[];function l(i){n.set(i,1),c.push(i);const r=s.get(i);for(const d of(r==null?void 0:r.dependsOn)??[]){if(!s.has(d))continue;const o=n.get(d);if(o===1){const p=c.indexOf(d);for(let u=p;u<c.length;u++)a.add(c[u])}else o===void 0&&l(d)}c.pop(),n.set(i,2)}for(const i of e)n.has(i.slug)||l(i.slug);return a}function Us(e,s){return(e.dependsOn??[]).map(n=>{const a=s.get(n);return a?{slug:n,status:a.status,missing:!1,needsReview:a.status==="needs_review"}:{slug:n,status:null,missing:!0,needsReview:!1}})}function Qs(e,s,n){const a=new Set(e.map(o=>o.slug)),c=new Set;for(const o of e)for(const p of o.dependsOn??[])a.has(p)&&c.add(p);const l=new Map,i=[];for(const o of e){const p=n.has(o.slug)?void 0:(o.dependsOn??[]).find(u=>a.has(u)&&!n.has(u));p?(l.has(p)||l.set(p,[]),l.get(p).push(o)):i.push(o)}const r=(o,p)=>o.slug.localeCompare(p.slug);i.sort(r);for(const o of l.values())o.sort(r);function d(o,p,u){const h=Us(o,s),g=n.has(o.slug);u.add(o.slug);const x=g?[]:(l.get(o.slug)??[]).filter(w=>!u.has(w.slug)).map(w=>d(w,p+1,u));return u.delete(o.slug),{row:o,depth:p,children:x,blockers:h,blocked:h.some(w=>!w.missing&&w.status!=="completed"),hasNeedsReviewBlocker:h.some(w=>w.needsReview),hasMissingDep:h.some(w=>w.missing),cycle:g,parallelEligible:(o.dependsOn??[]).length===0&&!c.has(o.slug)}}return i.map(o=>d(o,0,new Set))}function Gt(e,s,n){const a=new Map((n??e).map(o=>[o.slug,o])),c=Ws(e),l=[],i=new Map,r=new Map;for(const o of e){const p=Pe(o,s),u=p.epicId??"__none__";i.has(u)||(l.push(u),i.set(u,[]),r.set(u,{epicId:p.epicId,label:p.known&&p.label?p.label:p.epicId?`Epic ${p.epicId.slice(0,12)}…`:"No Epic",known:p.known})),i.get(u).push(o)}const d=l.map(o=>{const p=r.get(o),u=i.get(o),h=Qs(u,a,c),g={};for(const x of u){const w=x.status??"unknown";g[w]=(g[w]??0)+1}return{epicId:p.epicId,label:p.label,known:p.known,nodes:h,counts:g,total:u.length}});return d.sort((o,p)=>o.epicId===null?1:p.epicId===null?-1:o.known!==p.known?o.known?-1:1:o.label.localeCompare(p.label)),d}function Be(e){const s=[],n=a=>{s.push(a);for(const c of a.children)n(c)};for(const a of e)n(a);return s}function Ke(e){return String(e??"").replace(/^\d+-/,"")}function Oe(e){const s=new Set,n=new Map;for(const a of e){s.add(a.slug);const c=Ke(a.slug),l=n.get(c);l?l.push(a.slug):n.set(c,[a.slug])}return e.map(a=>{const c=a.dependsOn;if(!c||c.length===0)return a;let l=!1;const i=c.map(r=>{if(s.has(r))return r;const d=n.get(Ke(r));return d&&d.length===1?(l=!0,d[0]):r});return l?{...a,dependsOn:i}:a})}const Ys=15e4,Xe=e=>e==="completed"||e==="skipped",Se=e=>e==="running"||e==="investigating",Vt=e=>e==="failed"||e==="needs_review"||e==="quarantined",zs=e=>e==="failed"||e==="needs_review"||e==="quarantined";function Wt(e){if(e<=5e3)return"~now";if(e<6e4)return`~${Math.round(e/1e3)}s`;const s=Math.round(e/6e4);return s<60?`~${s}m`:`~${Math.floor(s/60)}h${String(s%60).padStart(2,"0")}m`}function Ut(e,s){const n=e.estimateMinutes?e.estimateMinutes*6e4:null;return n?`${Math.min(99,Math.floor(s/n*100))}%`:Te(s)}function Js(e){let s=0,n=0;for(const a of e)if(a.status==="completed"&&a.startedAt&&a.finishedAt){const c=Date.parse(a.finishedAt)-Date.parse(a.startedAt);c>0&&(s+=c,n++)}return n===0?Ys:s/n}function Le(e){const s=ie(e);return s===null?1/0:Number(s)}function Ze(e,s){const n=Le(e.slug)-Le(s.slug);return n!==0&&!Number.isNaN(n)?n:e.slug.localeCompare(s.slug)}function Ks(e){let s=0;for(const n of e.statusHistory??[])n.to==="pending"&&n.from!==null&&s++;return s}function Xs(e){return e.some(n=>Se(n.status))?"active":e.every(n=>Xe(n.status))?"done":e.filter(n=>n.status!=="quarantined").length===0?"draft":"queued"}function Zs(e,s,n,a){switch(e){case"done":return`${s.doneCount}/${s.rows.length} done`;case"running":return`${s.runningCount} running · ${n}`;case"held":return`${s.heldCount} held`;case"blocked":return`${s.blockedCount+a} blocked`;default:return`${n} ready`}}function en(e,s){return e._firstNum!==s._firstNum?e._firstNum<s._firstNum?-1:1:e._firstSlug.localeCompare(s._firstSlug)}function tn(e,s){const n=new Map(e.map(l=>[l.row.slug,l.row.slug])),a=l=>{for(;n.get(l)!==l;)n.set(l,n.get(n.get(l))),l=n.get(l);return l};for(const l of e)for(const i of l.row.dependsOn??[])s.has(i)&&n.set(a(l.row.slug),a(i));const c=new Map;for(const l of e){const i=a(l.row.slug),r=c.get(i);r?r.push(l):c.set(i,[l])}return[...c.values()]}function sn(e,s){if(e.length>0&&e.every(n=>!!n.row.planId)){const n=new Map;for(const a of e){const c=n.get(a.row.planId);c?c.push(a):n.set(a.row.planId,[a])}return[...n.values()]}return tn(e,s)}function nn(e,s,n,a){const c=[],l=[e];for(a.add(e.row.slug);l.length>0;){const i=l.pop();c.push(i);for(const r of i.row.dependsOn??[])if(n.has(r)&&!a.has(r)){a.add(r);const d=s.get(r);d&&l.push(d)}}return c}function an(e,s){const n=new Map(e.map(r=>[r.row.slug,r])),a=new Set,c=[],l=e.filter(r=>Ke(r.row.slug).startsWith("validate-")).sort((r,d)=>Ze({slug:r.row.slug},{slug:d.row.slug}));for(const r of l)a.has(r.row.slug)||c.push({nodes:nn(r,n,s,a),validateSlug:r.row.slug});const i=e.filter(r=>!a.has(r.row.slug));if(i.length>0){const r=new Set(i.map(d=>d.row.slug));for(const d of sn(i,r))c.push({nodes:d,validateSlug:null})}return c}function rn(e){return e.replace(/^validate[\s:-]*/i,"").trim()}function lt(e,s){if(e.length===0)return[];const n=Oe(e),a=s.now??Date.now(),c=s.avgDurationMs??Js(n),l=Math.max(1,s.concurrency??1),i=new Map(n.map(u=>[u.slug,u])),r=u=>u.status==="pending"&&(u.dependsOn??[]).every(h=>i.get(h)===void 0||i.get(h).status==="completed"),d=new Map;n.filter(r).sort(Ze).forEach((u,h)=>d.set(u.slug,h));const o=Gt(n,s.sessions,n),p=[];for(const u of o){const h=Be(u.nodes),g=new Set(h.map(D=>D.row.slug)),x=new Map(h.map(D=>[D.row.slug,D])),w=[];for(const D of an(h,g)){const k=D.nodes,E=new Set(k.map(N=>N.row.slug)),m=new Map,T=new Set,$=N=>{const S=x.get(N);return(S.row.dependsOn??[]).filter(G=>E.has(G)&&!(S.cycle&&x.get(G).cycle))},P=N=>{const S=m.get(N);if(S!==void 0)return S;if(T.has(N))return 0;T.add(N);let G=0;for(const F of $(N))G=Math.max(G,P(F));return T.delete(N),m.set(N,G+1),G+1};for(const N of k)P(N.row.slug);const O=k.map(N=>{const S=N.row,G=(S.dependsOn??[]).filter(F=>g.has(F));return{slug:S.slug,title:S.title,status:S.status,stage:m.get(S.slug),prdNumber:ie(S.slug),rowKind:"dep",rowTrailing:"",cycle:N.cycle,estimateMinutes:S.estimateMinutes??null,deps:G,crossEpicDeps:(S.dependsOn??[]).filter(F=>!g.has(F)),blockers:N.blockers,job:S}});O.sort(Ze);const J=O.reduce((N,S)=>Math.max(N,S.stage),0),W=new Map;for(const N of O){const S=N.job,G=x.get(N.slug),F=S.status;let U;if(Xe(F)){const b=S.startedAt&&S.finishedAt?Date.parse(S.finishedAt)-Date.parse(S.startedAt):NaN;U={kind:"done",trailing:b>0?Te(b):"",held:!1,blocked:!1}}else if(Se(F)){const b=S.startedAt?Math.max(0,a-Date.parse(S.startedAt)):null;U={kind:"running",trailing:b===null?"":Ut(S,b),held:!1,blocked:!1}}else if(F==="failed")U={kind:"failed",trailing:"failed",held:!1,blocked:!1};else if(F==="needs_review")U={kind:"review",trailing:"review",held:!1,blocked:!1};else if(F==="quarantined")U={kind:"quarantined",trailing:"quarantined",held:!1,blocked:!1};else{const b=G.blockers.filter(y=>!y.missing&&y.status!=="completed");if(b.length>0){const y=b.some(C=>zs(C.status)),A=b[0].slug;U={kind:"dep",trailing:`←${ie(A)??A}`,held:!y,blocked:y}}else if(S.heldReason)U={kind:"gate",trailing:"gate",held:!0,blocked:!1};else{const y=Ks(S),A=d.get(S.slug)??0;U=y>0?{kind:"retry",trailing:`${y} ${y===1?"retry":"retries"}`,held:!1,blocked:!1}:{kind:"eta",trailing:Wt(A*c/l),held:!1,blocked:!1}}}W.set(N.slug,U)}const Q=[];for(let N=1;N<=J;N++){const S=O.filter(_=>_.stage===N),G=S.find(_=>{const X=W.get(_.slug).kind;return _.status==="pending"&&(X==="eta"||X==="retry")});if(G){const _=W.get(G.slug);_.kind="next",_.trailing="next"}let F=0,U=0,b=0,y=0,A=0,C=0;for(const _ of S){const X=W.get(_.slug);_.rowKind=X.kind,_.rowTrailing=X.trailing,Xe(_.status)?F++:Se(_.status)?U++:_.status==="pending"?(A++,X.held&&b++,X.blocked&&y++):Vt(_.status)&&C++}const R=F===S.length?"done":U>0?"running":y+C>0?"blocked":b>0?"held":"pending",L={n:N,rows:S,doneCount:F,runningCount:U,heldCount:b,blockedCount:y};Q.push({...L,state:R,summary:Zs(R,L,A,C)})}let K=0;for(const N of O){const S=N.estimateMinutes?N.estimateMinutes*6e4:c;if(N.status==="pending")K+=S;else if(Se(N.status)){const G=N.job.startedAt?Math.max(0,a-Date.parse(N.job.startedAt)):0;K+=Math.max(0,S-G)}}const te=O.reduce((N,S)=>Math.min(N,Le(S.slug)),1/0),se=O.reduce((N,S)=>Math.max(N,Le(S.slug)),-1/0),Y=u.known?gs(u.label).title:u.label,M=D.validateSlug?O.find(N=>N.slug===D.validateSlug):void 0,B=M&&rn(M.title)||Y;w.push({epicId:u.epicId,waveIndex:0,index:0,label:B,epicLabel:Y,validateSlug:D.validateSlug,width:Q.reduce((N,S)=>Math.max(N,S.rows.length),0),status:Xs(O),prdCount:O.length,stageCount:J,doneCount:Q.reduce((N,S)=>N+S.doneCount,0),runningCount:Q.reduce((N,S)=>N+S.runningCount,0),heldCount:Q.reduce((N,S)=>N+S.heldCount,0),blockedCount:Q.reduce((N,S)=>N+S.blockedCount,0),etaMs:K/l,stages:Q,_firstNum:te,_lastNum:se,_firstSlug:O[0].slug})}w.sort(en),w.forEach((D,k)=>{D.waveIndex=k+1});const j=w.filter(D=>D.validateSlug===null);j.forEach((D,k)=>{j.length>1&&(D.label=`${D.label} · plan ${k+1}/${j.length}`)});for(const D of w)p.push(D)}return p.sort((u,h)=>{if(u._lastNum!==h._lastNum)return u._lastNum>h._lastNum?-1:1;const g=(u.epicId??"").localeCompare(h.epicId??"");return g!==0?g:u.waveIndex-h.waveIndex}),p.map(({_firstNum:u,_lastNum:h,_firstSlug:g,...x},w)=>({...x,index:w+1}))}function ln(e,s=Date.now()){const n=Oe(e),a=new Map(n.map(g=>[g.slug,g])),c=new Date(s).toDateString();let l=0,i=0,r=0,d=0,o=0,p=0,u=0;for(const g of n)g.status==="pending"?(i++,(g.dependsOn??[]).every(w=>a.get(w)===void 0||a.get(w).status==="completed")&&l++):Se(g.status)?u++:g.status==="failed"?r++:g.status==="needs_review"?d++:g.status==="quarantined"?o++:g.status==="completed"&&g.finishedAt&&new Date(Date.parse(g.finishedAt)).toDateString()===c&&p++;let h=null;if(r+d+o>0){for(const g of lt(n,{sessions:{},now:s}))for(const x of g.stages)if(x.rows.some(w=>Vt(w.status))){(h===null||x.n<h)&&(h=x.n);break}}return{readyNow:l,totalQueued:i,heldByDeps:i-l,needsYou:r+d+o,needsYouStage:h,failedCount:r,needsReviewCount:d,doneToday:p,inFlight:u}}function on(e){const s=new Map;for(const d of e.stages)for(const o of d.rows)s.set(o.slug,o);const n=d=>{var o;return((o=s.get(d))==null?void 0:o.cycle)===!0},a=new Map,c=new Set,l=(d,o)=>d.chain.length!==o.chain.length?d.chain.length>o.chain.length:d.est!==o.est?d.est>o.est:d.chain.join("\0")<o.chain.join("\0"),i=d=>{const o=a.get(d);if(o)return o;const p=s.get(d),u=p.estimateMinutes??0;if(c.has(d))return{chain:[d],est:u};c.add(d);let h=null;for(const x of p.deps){if(!s.has(x)||p.cycle&&n(x))continue;const w=i(x);(!h||l(w,h))&&(h=w)}c.delete(d);const g=h?{chain:[...h.chain,d],est:h.est+u}:{chain:[d],est:u};return a.set(d,g),g};let r=null;for(const d of s.keys()){const o=i(d);(!r||l(o,r))&&(r=o)}return r?r.chain:[]}const dn=300*6e4,cn={five_hour:"5-hour",session:"5-hour",weekly_all:"weekly",weekly:"weekly"};function un(e){return cn[e]??e.replace(/_/g," ")}function Qt({snap:e,now:s,avgDurationMs:n,runningJobs:a}){const{config:c,jobs:l,paused:i,nextReset:r,utilization:d,utilizationWindow:o,effectiveConcurrency:p}=e;let u=0,h=0;for(const k of l)k.status==="pending"?u++:k.status==="completed"&&h++;const g=a.length,x=u+g,w=(p==null?void 0:p.cap)??5;if(g>0){const k=a.reduce((P,O)=>(P.startedAt??"")<(O.startedAt??"")?P:O),E=k.startedAt?s-Date.parse(k.startedAt):0,m=h+g,T=h+x,$=g>1?` · ${g}/${w} parallel`:"";return{kind:"running",line1:`Running ${m}/${T}${$} · ${Ce(E)}`,line2:g===1?k.title:a.map(P=>P.title).join(", "),tooltip:a.map(P=>`${P.slug} (g${P.parallelGroup})`).join("; ")}}if(i){const k=i.resumeAt?Date.parse(i.resumeAt)-s:null;return{kind:"paused",line1:{rate_limit:"Paused — tokens exhausted",auth:"Paused — authentication failed",network:"Paused — network unreachable",reset_failure:"Paused — billing data unavailable",manual:"Paused — manual (you paused the queue)"}[i.reason]??`Paused — ${i.reason}`,line2:i.reason==="auth"?"Run `claude` in any terminal to refresh credentials, then Resume":k!==null&&k>0?`auto-resume ${le(Date.parse(i.resumeAt))} (in ${ee(k)})`:i.resumeAt?"resuming…":"no auto-resume scheduled",tooltip:i.resumeAt??"",action:{label:"Resume",onClick:()=>window.api.schedule.resume(),title:"Clear the pause and resume queue immediately"}}}if(x===0)return{kind:"idle",line1:"No work queued",line2:null};const j=c.firePolicy??"when-available";if(j==="manual")return{kind:"manual",line1:`Manual · ${u} pending`,line2:"click Fire next batch now to fire",action:{label:"Fire next batch now",onClick:()=>window.api.schedule.forceTick().then(q.fromOutcome).catch(()=>q.error("Failed to fire batch")),title:"Bypasses the billing-usage poll. Use when the meter is rate-limited or you want immediate progress."}};if(j==="on-reset"){if(!r)return{kind:"on-reset",line1:"On-reset · waiting for billing data",line2:null};const k=Date.parse(r)+c.offsetMinutes*6e4,E=k-s;return{kind:"on-reset",line1:`On-reset · ${u} pending`,line2:E>0?`fires ${le(k)} (in ${ee(E)})`:"firing now…"}}const D=c.utilizationThreshold??90;if(d==null)return{kind:"auto-soon",line1:`Auto · ${u} pending`,line2:"checking token availability…"};if(d>=D){const k=r?Date.parse(r)-s:null,E=o?un(o):null,m=k===null||Number.isNaN(k)||k>dn,T=k&&k>0?`resets ${le(Date.parse(r))} (in ${ee(k)})`:null;let $;return m?$=`${E??"binding"} window — long hold${T?`, ${T}`:", reset time unknown"}`:$=T?`${E?`${E} window `:""}next ${T}`:"will fire when usage drops",{kind:"auto-throttled",line1:`Auto · throttled (util ${d.toFixed(0)}% ≥ ${D}%)`,line2:$}}return{kind:"auto-soon",line1:`Auto · ${u} pending · util ${d.toFixed(0)}%`,line2:"fires within 2 min (poll cycle)"}}const pn=15e3,fn=new Set(["failed","needs_review","quarantined"]);function St(){var n;const s=Array.from(document.querySelectorAll("[data-job-row]")).find(a=>fn.has(a.dataset.jobStatus??""));(n=s==null?void 0:s.scrollIntoView)==null||n.call(s,{block:"center",behavior:"smooth"})}function hn(e,s){var n;switch(e.kind){case"paused":return`paused: scheduler is paused (${e.reason??"manual"})`;case"launch-blocked":return`launch-blocked: ${e.agentType} jobs can't launch${(n=e.block)!=null&&n.kind?` (${e.block.kind})`:""}`;case"idle":return"idle: 0 pending";case"saturated":{const a=s!=null?`, oldest ${ee(s)}`:"";return`saturated: ${e.totalSlots??"?"} slot(s) busy${a}`}case"blocked":{const a=e.blockedChains.length;return`blocked: ${e.pending} pending, ${e.dispatchable} dispatchable — ${a} chain${a===1?"":"s"} stuck behind a failed/skipped dependency`}case"stalled":return`stalled: no dispatch attempt in ${e.idleMs!=null?ee(e.idleMs):"?"} with ${e.dispatchable} dispatchable`;case"running":default:return`running: ${e.runningCount} in flight, ${e.pending} pending`}}function gn(e){const[s,n]=f.useState(null),a=st(),c=Ns(),l=a&&c;return f.useEffect(()=>{if(!l)return;let i=!0,r=!1,d=!1;const o=()=>{r||(r=!0,window.api.schedule.queueHealth(e).then(u=>{r=!1,d=!1,i&&n(u)},u=>{r=!1,!d&&(d=!0,q.error(`Queue health refresh failed: ${u instanceof Error?u.message:String(u)}`))}))};o();const p=setInterval(o,pn);return()=>{i=!1,clearInterval(p)}},[e,l]),s}const xn={running:{dot:"bg-sage",text:"text-sage-dark"},paused:{dot:"bg-amber-500",text:"text-amber-600"},idle:{dot:"bg-fg-faint",text:"text-fg-faint"}};function mn(e,s,n){return e==="paused"||e==="launch-blocked"?"paused":e==="running"||e==="saturated"?"running":e?"idle":s?"paused":n>0?"running":"idle"}const Qe="px-2.5 py-1.5 rounded border border-line text-[12.5px] font-medium text-fg-dim hover:text-fg hover:bg-bg-hi disabled:opacity-40 disabled:cursor-not-allowed whitespace-nowrap";function bn(e,s,n,a){var c;if(e==="agent"){const l=((c=a==null?void 0:a.cwd)==null?void 0:c.split("/").filter(Boolean).pop())||"another session",i=a!=null&&a.reason?` — "${a.reason}"`:"",r=s?new Date(s).getTime()-n:null,d=r==null?"":r>0?` — auto-resumes in ${ee(r)}`:" — auto-resume pending";return`Paused by an agent in ${l}${i}${d}. Click Resume to restart now.`}if(e==="auth")return"Scheduler paused: Claude sign-in expired or invalid. Restart the app or re-run `claude login`, then Resume.";if(e==="rate_limit"){if(s){const l=new Date(s).getTime()-n;return l>0?`Paused for rate limit — resumes in ${ee(l)}`:"Paused for rate limit — resume pending"}return"Paused for rate limit"}return e==="network"?"Paused: billing endpoint unreachable for 30+ min.":e==="manual"?"Scheduler paused manually — no new jobs start; running jobs continue. Click Resume to restart.":`Scheduler paused (${e})`}function wn({now:e}){const s=Fe(p=>p.snapshot);if(!s)return null;const n=s.paused,a=Object.entries(s.launchBlocks??{}),c=Object.entries(s.launchMitigations??{}),l=(n==null?void 0:n.reason)==="auth"||(n==null?void 0:n.reason)==="network",i="flex items-start gap-3 border-b px-0 py-1.5 text-[12.5px]",r="bg-red-950/10 border-red-700/30 text-red-800",d="bg-amber-400/10 border-amber-600/30 text-amber-700",o="shrink-0 px-2 py-0.5 rounded border border-current/40 hover:bg-white/20 text-[12px] font-medium";return t.jsxs(t.Fragment,{children:[n&&t.jsxs("div",{"data-testid":"pause-banner",className:`${i} ${l?r:d}`,children:[t.jsx("span",{className:"flex-1 leading-snug",children:bn(n.reason,n.resumeAt,e,n.by)}),t.jsx("button",{type:"button",onClick:()=>window.api.schedule.resume(),className:o,children:"Resume"})]}),a.map(([p,u])=>t.jsxs("div",{"data-testid":"launch-block-banner",className:`${i} ${r}`,children:[t.jsxs("div",{className:"flex-1 leading-snug min-w-0",children:[t.jsxs("div",{className:"font-medium",children:["Launches for ",t.jsx("span",{className:"font-mono",children:p})," jobs are failing before any work starts",u.httpStatus?` (HTTP ${u.httpStatus}, ${u.kind})`:` (${u.kind})`,u.exhausted?" — held until the Claude CLI version changes or you press Retry now.":u.until?` — next automatic probe ${new Date(u.until).getTime()>e?`in ${ee(new Date(u.until).getTime()-e)}`:"on the next tick"}.`:"."]}),t.jsx("div",{className:"opacity-80",children:u.hint}),t.jsxs("div",{className:"font-mono text-[11.5px] opacity-70 truncate",title:u.message,children:[u.attempts," failed probe",u.attempts===1?"":"s",u.claudeVersion?` · CLI ${u.claudeVersion}`:"",u.lastSlug?` · last: ${u.lastSlug}`:""," · ",u.message]})]}),t.jsx("button",{type:"button",onClick:()=>window.api.schedule.resume(),className:o,children:"Retry now"})]},`launch-block-${p}`)),c.map(([p,u])=>t.jsx("div",{"data-testid":"launch-mitigation-banner",className:`${i} ${d}`,children:t.jsxs("div",{className:"flex-1 leading-snug min-w-0",children:[t.jsxs("div",{className:"font-medium",children:[t.jsx("span",{className:"font-mono",children:p})," jobs are running in degraded mode"," ","(",t.jsx("span",{className:"font-mono",children:Object.entries(u.env).map(([h,g])=>`${h}=${g}`).join(" ")}),")",u.claudeVersion?` since CLI ${u.claudeVersion}`:"","."]}),t.jsx("div",{className:"opacity-80",children:u.hint})]})},`launch-mitigation-${p}`))]})}function vn({scopeCwd:e,subView:s,onSubView:n,filterText:a,onFilterText:c,planMode:l,onPlanMode:i,planToolsRef:r}){const d=Fe(C=>C.snapshot),o=pe(C=>C.sessions),p=gn(e),[u,h]=f.useState(()=>Date.now()),[g,x]=f.useState("—");f.useEffect(()=>{const C=setInterval(()=>h(Date.now()),3e4);return()=>clearInterval(C)},[]),f.useEffect(()=>{let C=!0;return qs(30).then(R=>{if(!C||!R.ok||!R.data)return;const L=new Date,_=He=>String(He).padStart(2,"0"),X=`${L.getFullYear()}-${_(L.getMonth()+1)}-${_(L.getDate())}`;x(Bs(Hs(R.data,{day:X})))}),()=>{C=!1}},[]);const w=f.useMemo(()=>((d==null?void 0:d.jobs)??[]).filter(C=>!e||C.cwd===e),[d,e]),j=f.useMemo(()=>ln(w,u),[w,u]),D=f.useMemo(()=>{const C=lt(w,{sessions:o,now:u}),R=L=>C.filter(_=>_.status===L).length;return{active:R("active"),queued:R("queued"),draft:R("draft")}},[w,o,u]),k=f.useMemo(()=>{const C=new Date(u).toDateString(),R=[];for(const L of w)if(L.status==="completed"&&L.startedAt&&L.finishedAt&&new Date(Date.parse(L.finishedAt)).toDateString()===C){const _=Date.parse(L.finishedAt)-Date.parse(L.startedAt);_>0&&R.push(_)}return R.length?Math.round(R.reduce((L,_)=>L+_,0)/R.length/6e4):null},[w,u]);if(!d)return null;const E=p&&!p.unknown?p.verdict??null:null,m=p&&!p.unknown?p.slots??null:null,T=d.paused,$=mn((E==null?void 0:E.kind)??null,!!T,j.inFlight),P=xn[$],O=w.filter(C=>C.status==="pending").length,J=w.filter(C=>C.status==="running").length,W=Qt({snap:{...d,jobs:w},now:u,avgDurationMs:0,runningJobs:w.filter(C=>C.status==="running")}),Q=p!=null&&p.unknown?`Queue health: unknown — ${p.reason??"state unavailable"}`:E?hn(E,(p==null?void 0:p.oldestRunningAgeMs)??null):"queue health loading…",K=xe(d.lastRunAt?Date.parse(d.lastRunAt):null,u),te=p!=null&&p.lastDispatchAttemptAt?xe(Date.parse(p.lastDispatchAttemptAt),u):"never",se=[Q,W.line1,E?`dispatchable ${E.dispatchable} · needs_review ${E.needsReviewCount}`:null,(p==null?void 0:p.oldestRunningAgeMs)!=null?`oldest running ${ee(p.oldestRunningAgeMs)} (any project)`:null,`last batch fired ${K} (lastRunAt — advances only when a job launches)`,`last dispatch attempt ${te} (advances on every driver evaluation)`].filter(Boolean).join(`
1
+ import{aL as Pe,aw as ie,af as Te,aR as gs,aj as Ce,ae as le,ah as ee,aW as q,ba as Fe,b8 as pe,aE as f,ac as xe,bh as xs,ao as t,b as Ue,I as me,L as bt,q as ms,K as ge,u as bs,Q as ws,d as vs,U as js,aQ as ys,b7 as st,b0 as Ns,a7 as wt,au as Tt,bg as $e,G as qe,aB as _e,A as nt,aP as at,N as _t,w as Ot,p as Lt,r as ks,o as rt,y as it,O as Ss,f as re,g as H,ag as Ft,bb as Cs,aD as $s,aG as qt,bk as Bt,V as Ps,ax as vt,b1 as jt,n as ke,x as yt,aM as Nt,m as Ds,aU as As,Y as Ms,v as Ht,b3 as Rs,aZ as ye,H as Is,C as Es,bc as Ts,aF as _s,T as Os,bj as Ls,bd as kt,aO as Fs}from"./index-DQSEUdx0.js";import{f as qs,a as Bs,s as Hs}from"./historyTotals-Bg0GVcsF.js";import{l as Gs}from"./listSkills-C1aWKf0T.js";import{T as Vs}from"./Toggle-CpR97XGM.js";import"./monaco-editor-BsIlgG7c.js";function Ws(e){const s=new Map(e.map(i=>[i.slug,i])),n=new Map,a=new Set,c=[];function l(i){n.set(i,1),c.push(i);const r=s.get(i);for(const d of(r==null?void 0:r.dependsOn)??[]){if(!s.has(d))continue;const o=n.get(d);if(o===1){const p=c.indexOf(d);for(let u=p;u<c.length;u++)a.add(c[u])}else o===void 0&&l(d)}c.pop(),n.set(i,2)}for(const i of e)n.has(i.slug)||l(i.slug);return a}function Us(e,s){return(e.dependsOn??[]).map(n=>{const a=s.get(n);return a?{slug:n,status:a.status,missing:!1,needsReview:a.status==="needs_review"}:{slug:n,status:null,missing:!0,needsReview:!1}})}function Qs(e,s,n){const a=new Set(e.map(o=>o.slug)),c=new Set;for(const o of e)for(const p of o.dependsOn??[])a.has(p)&&c.add(p);const l=new Map,i=[];for(const o of e){const p=n.has(o.slug)?void 0:(o.dependsOn??[]).find(u=>a.has(u)&&!n.has(u));p?(l.has(p)||l.set(p,[]),l.get(p).push(o)):i.push(o)}const r=(o,p)=>o.slug.localeCompare(p.slug);i.sort(r);for(const o of l.values())o.sort(r);function d(o,p,u){const h=Us(o,s),g=n.has(o.slug);u.add(o.slug);const x=g?[]:(l.get(o.slug)??[]).filter(w=>!u.has(w.slug)).map(w=>d(w,p+1,u));return u.delete(o.slug),{row:o,depth:p,children:x,blockers:h,blocked:h.some(w=>!w.missing&&w.status!=="completed"),hasNeedsReviewBlocker:h.some(w=>w.needsReview),hasMissingDep:h.some(w=>w.missing),cycle:g,parallelEligible:(o.dependsOn??[]).length===0&&!c.has(o.slug)}}return i.map(o=>d(o,0,new Set))}function Gt(e,s,n){const a=new Map((n??e).map(o=>[o.slug,o])),c=Ws(e),l=[],i=new Map,r=new Map;for(const o of e){const p=Pe(o,s),u=p.epicId??"__none__";i.has(u)||(l.push(u),i.set(u,[]),r.set(u,{epicId:p.epicId,label:p.known&&p.label?p.label:p.epicId?`Epic ${p.epicId.slice(0,12)}…`:"No Epic",known:p.known})),i.get(u).push(o)}const d=l.map(o=>{const p=r.get(o),u=i.get(o),h=Qs(u,a,c),g={};for(const x of u){const w=x.status??"unknown";g[w]=(g[w]??0)+1}return{epicId:p.epicId,label:p.label,known:p.known,nodes:h,counts:g,total:u.length}});return d.sort((o,p)=>o.epicId===null?1:p.epicId===null?-1:o.known!==p.known?o.known?-1:1:o.label.localeCompare(p.label)),d}function Be(e){const s=[],n=a=>{s.push(a);for(const c of a.children)n(c)};for(const a of e)n(a);return s}function Ke(e){return String(e??"").replace(/^\d+-/,"")}function Oe(e){const s=new Set,n=new Map;for(const a of e){s.add(a.slug);const c=Ke(a.slug),l=n.get(c);l?l.push(a.slug):n.set(c,[a.slug])}return e.map(a=>{const c=a.dependsOn;if(!c||c.length===0)return a;let l=!1;const i=c.map(r=>{if(s.has(r))return r;const d=n.get(Ke(r));return d&&d.length===1?(l=!0,d[0]):r});return l?{...a,dependsOn:i}:a})}const Ys=15e4,Xe=e=>e==="completed"||e==="skipped",Se=e=>e==="running"||e==="investigating",Vt=e=>e==="failed"||e==="needs_review"||e==="quarantined",zs=e=>e==="failed"||e==="needs_review"||e==="quarantined";function Wt(e){if(e<=5e3)return"~now";if(e<6e4)return`~${Math.round(e/1e3)}s`;const s=Math.round(e/6e4);return s<60?`~${s}m`:`~${Math.floor(s/60)}h${String(s%60).padStart(2,"0")}m`}function Ut(e,s){const n=e.estimateMinutes?e.estimateMinutes*6e4:null;return n?`${Math.min(99,Math.floor(s/n*100))}%`:Te(s)}function Js(e){let s=0,n=0;for(const a of e)if(a.status==="completed"&&a.startedAt&&a.finishedAt){const c=Date.parse(a.finishedAt)-Date.parse(a.startedAt);c>0&&(s+=c,n++)}return n===0?Ys:s/n}function Le(e){const s=ie(e);return s===null?1/0:Number(s)}function Ze(e,s){const n=Le(e.slug)-Le(s.slug);return n!==0&&!Number.isNaN(n)?n:e.slug.localeCompare(s.slug)}function Ks(e){let s=0;for(const n of e.statusHistory??[])n.to==="pending"&&n.from!==null&&s++;return s}function Xs(e){return e.some(n=>Se(n.status))?"active":e.every(n=>Xe(n.status))?"done":e.filter(n=>n.status!=="quarantined").length===0?"draft":"queued"}function Zs(e,s,n,a){switch(e){case"done":return`${s.doneCount}/${s.rows.length} done`;case"running":return`${s.runningCount} running · ${n}`;case"held":return`${s.heldCount} held`;case"blocked":return`${s.blockedCount+a} blocked`;default:return`${n} ready`}}function en(e,s){return e._firstNum!==s._firstNum?e._firstNum<s._firstNum?-1:1:e._firstSlug.localeCompare(s._firstSlug)}function tn(e,s){const n=new Map(e.map(l=>[l.row.slug,l.row.slug])),a=l=>{for(;n.get(l)!==l;)n.set(l,n.get(n.get(l))),l=n.get(l);return l};for(const l of e)for(const i of l.row.dependsOn??[])s.has(i)&&n.set(a(l.row.slug),a(i));const c=new Map;for(const l of e){const i=a(l.row.slug),r=c.get(i);r?r.push(l):c.set(i,[l])}return[...c.values()]}function sn(e,s){if(e.length>0&&e.every(n=>!!n.row.planId)){const n=new Map;for(const a of e){const c=n.get(a.row.planId);c?c.push(a):n.set(a.row.planId,[a])}return[...n.values()]}return tn(e,s)}function nn(e,s,n,a){const c=[],l=[e];for(a.add(e.row.slug);l.length>0;){const i=l.pop();c.push(i);for(const r of i.row.dependsOn??[])if(n.has(r)&&!a.has(r)){a.add(r);const d=s.get(r);d&&l.push(d)}}return c}function an(e,s){const n=new Map(e.map(r=>[r.row.slug,r])),a=new Set,c=[],l=e.filter(r=>Ke(r.row.slug).startsWith("validate-")).sort((r,d)=>Ze({slug:r.row.slug},{slug:d.row.slug}));for(const r of l)a.has(r.row.slug)||c.push({nodes:nn(r,n,s,a),validateSlug:r.row.slug});const i=e.filter(r=>!a.has(r.row.slug));if(i.length>0){const r=new Set(i.map(d=>d.row.slug));for(const d of sn(i,r))c.push({nodes:d,validateSlug:null})}return c}function rn(e){return e.replace(/^validate[\s:-]*/i,"").trim()}function lt(e,s){if(e.length===0)return[];const n=Oe(e),a=s.now??Date.now(),c=s.avgDurationMs??Js(n),l=Math.max(1,s.concurrency??1),i=new Map(n.map(u=>[u.slug,u])),r=u=>u.status==="pending"&&(u.dependsOn??[]).every(h=>i.get(h)===void 0||i.get(h).status==="completed"),d=new Map;n.filter(r).sort(Ze).forEach((u,h)=>d.set(u.slug,h));const o=Gt(n,s.sessions,n),p=[];for(const u of o){const h=Be(u.nodes),g=new Set(h.map(D=>D.row.slug)),x=new Map(h.map(D=>[D.row.slug,D])),w=[];for(const D of an(h,g)){const k=D.nodes,E=new Set(k.map(N=>N.row.slug)),m=new Map,T=new Set,$=N=>{const S=x.get(N);return(S.row.dependsOn??[]).filter(G=>E.has(G)&&!(S.cycle&&x.get(G).cycle))},P=N=>{const S=m.get(N);if(S!==void 0)return S;if(T.has(N))return 0;T.add(N);let G=0;for(const F of $(N))G=Math.max(G,P(F));return T.delete(N),m.set(N,G+1),G+1};for(const N of k)P(N.row.slug);const O=k.map(N=>{const S=N.row,G=(S.dependsOn??[]).filter(F=>g.has(F));return{slug:S.slug,title:S.title,status:S.status,stage:m.get(S.slug),prdNumber:ie(S.slug),rowKind:"dep",rowTrailing:"",cycle:N.cycle,estimateMinutes:S.estimateMinutes??null,deps:G,crossEpicDeps:(S.dependsOn??[]).filter(F=>!g.has(F)),blockers:N.blockers,job:S}});O.sort(Ze);const J=O.reduce((N,S)=>Math.max(N,S.stage),0),W=new Map;for(const N of O){const S=N.job,G=x.get(N.slug),F=S.status;let U;if(Xe(F)){const b=S.startedAt&&S.finishedAt?Date.parse(S.finishedAt)-Date.parse(S.startedAt):NaN;U={kind:"done",trailing:b>0?Te(b):"",held:!1,blocked:!1}}else if(Se(F)){const b=S.startedAt?Math.max(0,a-Date.parse(S.startedAt)):null;U={kind:"running",trailing:b===null?"":Ut(S,b),held:!1,blocked:!1}}else if(F==="failed")U={kind:"failed",trailing:"failed",held:!1,blocked:!1};else if(F==="needs_review")U={kind:"review",trailing:"review",held:!1,blocked:!1};else if(F==="quarantined")U={kind:"quarantined",trailing:"quarantined",held:!1,blocked:!1};else{const b=G.blockers.filter(y=>!y.missing&&y.status!=="completed");if(b.length>0){const y=b.some(C=>zs(C.status)),A=b[0].slug;U={kind:"dep",trailing:`←${ie(A)??A}`,held:!y,blocked:y}}else if(S.heldReason)U={kind:"gate",trailing:"gate",held:!0,blocked:!1};else{const y=Ks(S),A=d.get(S.slug)??0;U=y>0?{kind:"retry",trailing:`${y} ${y===1?"retry":"retries"}`,held:!1,blocked:!1}:{kind:"eta",trailing:Wt(A*c/l),held:!1,blocked:!1}}}W.set(N.slug,U)}const Q=[];for(let N=1;N<=J;N++){const S=O.filter(_=>_.stage===N),G=S.find(_=>{const X=W.get(_.slug).kind;return _.status==="pending"&&(X==="eta"||X==="retry")});if(G){const _=W.get(G.slug);_.kind="next",_.trailing="next"}let F=0,U=0,b=0,y=0,A=0,C=0;for(const _ of S){const X=W.get(_.slug);_.rowKind=X.kind,_.rowTrailing=X.trailing,Xe(_.status)?F++:Se(_.status)?U++:_.status==="pending"?(A++,X.held&&b++,X.blocked&&y++):Vt(_.status)&&C++}const R=F===S.length?"done":U>0?"running":y+C>0?"blocked":b>0?"held":"pending",L={n:N,rows:S,doneCount:F,runningCount:U,heldCount:b,blockedCount:y};Q.push({...L,state:R,summary:Zs(R,L,A,C)})}let K=0;for(const N of O){const S=N.estimateMinutes?N.estimateMinutes*6e4:c;if(N.status==="pending")K+=S;else if(Se(N.status)){const G=N.job.startedAt?Math.max(0,a-Date.parse(N.job.startedAt)):0;K+=Math.max(0,S-G)}}const te=O.reduce((N,S)=>Math.min(N,Le(S.slug)),1/0),se=O.reduce((N,S)=>Math.max(N,Le(S.slug)),-1/0),Y=u.known?gs(u.label).title:u.label,M=D.validateSlug?O.find(N=>N.slug===D.validateSlug):void 0,B=M&&rn(M.title)||Y;w.push({epicId:u.epicId,waveIndex:0,index:0,label:B,epicLabel:Y,validateSlug:D.validateSlug,width:Q.reduce((N,S)=>Math.max(N,S.rows.length),0),status:Xs(O),prdCount:O.length,stageCount:J,doneCount:Q.reduce((N,S)=>N+S.doneCount,0),runningCount:Q.reduce((N,S)=>N+S.runningCount,0),heldCount:Q.reduce((N,S)=>N+S.heldCount,0),blockedCount:Q.reduce((N,S)=>N+S.blockedCount,0),etaMs:K/l,stages:Q,_firstNum:te,_lastNum:se,_firstSlug:O[0].slug})}w.sort(en),w.forEach((D,k)=>{D.waveIndex=k+1});const j=w.filter(D=>D.validateSlug===null);j.forEach((D,k)=>{j.length>1&&(D.label=`${D.label} · plan ${k+1}/${j.length}`)});for(const D of w)p.push(D)}return p.sort((u,h)=>{if(u._lastNum!==h._lastNum)return u._lastNum>h._lastNum?-1:1;const g=(u.epicId??"").localeCompare(h.epicId??"");return g!==0?g:u.waveIndex-h.waveIndex}),p.map(({_firstNum:u,_lastNum:h,_firstSlug:g,...x},w)=>({...x,index:w+1}))}function ln(e,s=Date.now()){const n=Oe(e),a=new Map(n.map(g=>[g.slug,g])),c=new Date(s).toDateString();let l=0,i=0,r=0,d=0,o=0,p=0,u=0;for(const g of n)g.status==="pending"?(i++,(g.dependsOn??[]).every(w=>a.get(w)===void 0||a.get(w).status==="completed")&&l++):Se(g.status)?u++:g.status==="failed"?r++:g.status==="needs_review"?d++:g.status==="quarantined"?o++:g.status==="completed"&&g.finishedAt&&new Date(Date.parse(g.finishedAt)).toDateString()===c&&p++;let h=null;if(r+d+o>0){for(const g of lt(n,{sessions:{},now:s}))for(const x of g.stages)if(x.rows.some(w=>Vt(w.status))){(h===null||x.n<h)&&(h=x.n);break}}return{readyNow:l,totalQueued:i,heldByDeps:i-l,needsYou:r+d+o,needsYouStage:h,failedCount:r,needsReviewCount:d,doneToday:p,inFlight:u}}function on(e){const s=new Map;for(const d of e.stages)for(const o of d.rows)s.set(o.slug,o);const n=d=>{var o;return((o=s.get(d))==null?void 0:o.cycle)===!0},a=new Map,c=new Set,l=(d,o)=>d.chain.length!==o.chain.length?d.chain.length>o.chain.length:d.est!==o.est?d.est>o.est:d.chain.join("\0")<o.chain.join("\0"),i=d=>{const o=a.get(d);if(o)return o;const p=s.get(d),u=p.estimateMinutes??0;if(c.has(d))return{chain:[d],est:u};c.add(d);let h=null;for(const x of p.deps){if(!s.has(x)||p.cycle&&n(x))continue;const w=i(x);(!h||l(w,h))&&(h=w)}c.delete(d);const g=h?{chain:[...h.chain,d],est:h.est+u}:{chain:[d],est:u};return a.set(d,g),g};let r=null;for(const d of s.keys()){const o=i(d);(!r||l(o,r))&&(r=o)}return r?r.chain:[]}const dn=300*6e4,cn={five_hour:"5-hour",session:"5-hour",weekly_all:"weekly",weekly:"weekly"};function un(e){return cn[e]??e.replace(/_/g," ")}function Qt({snap:e,now:s,avgDurationMs:n,runningJobs:a}){const{config:c,jobs:l,paused:i,nextReset:r,utilization:d,utilizationWindow:o,effectiveConcurrency:p}=e;let u=0,h=0;for(const k of l)k.status==="pending"?u++:k.status==="completed"&&h++;const g=a.length,x=u+g,w=(p==null?void 0:p.cap)??5;if(g>0){const k=a.reduce((P,O)=>(P.startedAt??"")<(O.startedAt??"")?P:O),E=k.startedAt?s-Date.parse(k.startedAt):0,m=h+g,T=h+x,$=g>1?` · ${g}/${w} parallel`:"";return{kind:"running",line1:`Running ${m}/${T}${$} · ${Ce(E)}`,line2:g===1?k.title:a.map(P=>P.title).join(", "),tooltip:a.map(P=>`${P.slug} (g${P.parallelGroup})`).join("; ")}}if(i){const k=i.resumeAt?Date.parse(i.resumeAt)-s:null;return{kind:"paused",line1:{rate_limit:"Paused — tokens exhausted",auth:"Paused — authentication failed",network:"Paused — network unreachable",reset_failure:"Paused — billing data unavailable",manual:"Paused — manual (you paused the queue)"}[i.reason]??`Paused — ${i.reason}`,line2:i.reason==="auth"?"Run `claude` in any terminal to refresh credentials, then Resume":k!==null&&k>0?`auto-resume ${le(Date.parse(i.resumeAt))} (in ${ee(k)})`:i.resumeAt?"resuming…":"no auto-resume scheduled",tooltip:i.resumeAt??"",action:{label:"Resume",onClick:()=>window.api.schedule.resume(),title:"Clear the pause and resume queue immediately"}}}if(x===0)return{kind:"idle",line1:"No work queued",line2:null};const j=c.firePolicy??"when-available";if(j==="manual")return{kind:"manual",line1:`Manual · ${u} pending`,line2:"click Fire next batch now to fire",action:{label:"Fire next batch now",onClick:()=>window.api.schedule.forceTick().then(q.fromOutcome).catch(()=>q.error("Failed to fire batch")),title:"Bypasses the billing-usage poll. Use when the meter is rate-limited or you want immediate progress."}};if(j==="on-reset"){if(!r)return{kind:"on-reset",line1:"On-reset · waiting for billing data",line2:null};const k=Date.parse(r)+c.offsetMinutes*6e4,E=k-s;return{kind:"on-reset",line1:`On-reset · ${u} pending`,line2:E>0?`fires ${le(k)} (in ${ee(E)})`:"firing now…"}}const D=c.utilizationThreshold??90;if(d==null)return{kind:"auto-soon",line1:`Auto · ${u} pending`,line2:"checking token availability…"};if(d>=D){const k=r?Date.parse(r)-s:null,E=o?un(o):null,m=k===null||Number.isNaN(k)||k>dn,T=k&&k>0?`resets ${le(Date.parse(r))} (in ${ee(k)})`:null;let $;return m?$=`${E??"binding"} window — long hold${T?`, ${T}`:", reset time unknown"}`:$=T?`${E?`${E} window `:""}next ${T}`:"will fire when usage drops",{kind:"auto-throttled",line1:`Auto · throttled (util ${d.toFixed(0)}% ≥ ${D}%)`,line2:$}}return{kind:"auto-soon",line1:`Auto · ${u} pending · util ${d.toFixed(0)}%`,line2:"fires within 2 min (poll cycle)"}}const pn=15e3,fn=new Set(["failed","needs_review","quarantined"]);function St(){var n;const s=Array.from(document.querySelectorAll("[data-job-row]")).find(a=>fn.has(a.dataset.jobStatus??""));(n=s==null?void 0:s.scrollIntoView)==null||n.call(s,{block:"center",behavior:"smooth"})}function hn(e,s){var n;switch(e.kind){case"paused":return`paused: scheduler is paused (${e.reason??"manual"})`;case"launch-blocked":return`launch-blocked: ${e.agentType} jobs can't launch${(n=e.block)!=null&&n.kind?` (${e.block.kind})`:""}`;case"idle":return"idle: 0 pending";case"saturated":{const a=s!=null?`, oldest ${ee(s)}`:"";return`saturated: ${e.totalSlots??"?"} slot(s) busy${a}`}case"blocked":{const a=e.blockedChains.length;return`blocked: ${e.pending} pending, ${e.dispatchable} dispatchable — ${a} chain${a===1?"":"s"} stuck behind a failed/skipped dependency`}case"stalled":return`stalled: no dispatch attempt in ${e.idleMs!=null?ee(e.idleMs):"?"} with ${e.dispatchable} dispatchable`;case"running":default:return`running: ${e.runningCount} in flight, ${e.pending} pending`}}function gn(e){const[s,n]=f.useState(null),a=st(),c=Ns(),l=a&&c;return f.useEffect(()=>{if(!l)return;let i=!0,r=!1,d=!1;const o=()=>{r||(r=!0,window.api.schedule.queueHealth(e).then(u=>{r=!1,d=!1,i&&n(u)},u=>{r=!1,!d&&(d=!0,q.error(`Queue health refresh failed: ${u instanceof Error?u.message:String(u)}`))}))};o();const p=setInterval(o,pn);return()=>{i=!1,clearInterval(p)}},[e,l]),s}const xn={running:{dot:"bg-sage",text:"text-sage-dark"},paused:{dot:"bg-amber-500",text:"text-amber-600"},idle:{dot:"bg-fg-faint",text:"text-fg-faint"}};function mn(e,s,n){return e==="paused"||e==="launch-blocked"?"paused":e==="running"||e==="saturated"?"running":e?"idle":s?"paused":n>0?"running":"idle"}const Qe="px-2.5 py-1.5 rounded border border-line text-[12.5px] font-medium text-fg-dim hover:text-fg hover:bg-bg-hi disabled:opacity-40 disabled:cursor-not-allowed whitespace-nowrap";function bn(e,s,n,a){var c;if(e==="agent"){const l=((c=a==null?void 0:a.cwd)==null?void 0:c.split("/").filter(Boolean).pop())||"another session",i=a!=null&&a.reason?` — "${a.reason}"`:"",r=s?new Date(s).getTime()-n:null,d=r==null?"":r>0?` — auto-resumes in ${ee(r)}`:" — auto-resume pending";return`Paused by an agent in ${l}${i}${d}. Click Resume to restart now.`}if(e==="auth")return"Scheduler paused: Claude sign-in expired or invalid. Restart the app or re-run `claude login`, then Resume.";if(e==="rate_limit"){if(s){const l=new Date(s).getTime()-n;return l>0?`Paused for rate limit — resumes in ${ee(l)}`:"Paused for rate limit — resume pending"}return"Paused for rate limit"}return e==="network"?"Paused: billing endpoint unreachable for 30+ min.":e==="manual"?"Scheduler paused manually — no new jobs start; running jobs continue. Click Resume to restart.":`Scheduler paused (${e})`}function wn({now:e}){const s=Fe(p=>p.snapshot);if(!s)return null;const n=s.paused,a=Object.entries(s.launchBlocks??{}),c=Object.entries(s.launchMitigations??{}),l=(n==null?void 0:n.reason)==="auth"||(n==null?void 0:n.reason)==="network",i="flex items-start gap-3 border-b px-0 py-1.5 text-[12.5px]",r="bg-red-950/10 border-red-700/30 text-red-800",d="bg-amber-400/10 border-amber-600/30 text-amber-700",o="shrink-0 px-2 py-0.5 rounded border border-current/40 hover:bg-white/20 text-[12px] font-medium";return t.jsxs(t.Fragment,{children:[n&&t.jsxs("div",{"data-testid":"pause-banner",className:`${i} ${l?r:d}`,children:[t.jsx("span",{className:"flex-1 leading-snug",children:bn(n.reason,n.resumeAt,e,n.by)}),t.jsx("button",{type:"button",onClick:()=>window.api.schedule.resume(),className:o,children:"Resume"})]}),a.map(([p,u])=>t.jsxs("div",{"data-testid":"launch-block-banner",className:`${i} ${r}`,children:[t.jsxs("div",{className:"flex-1 leading-snug min-w-0",children:[t.jsxs("div",{className:"font-medium",children:["Launches for ",t.jsx("span",{className:"font-mono",children:p})," jobs are failing before any work starts",u.httpStatus?` (HTTP ${u.httpStatus}, ${u.kind})`:` (${u.kind})`,u.exhausted?" — held until the Claude CLI version changes or you press Retry now.":u.until?` — next automatic probe ${new Date(u.until).getTime()>e?`in ${ee(new Date(u.until).getTime()-e)}`:"on the next tick"}.`:"."]}),t.jsx("div",{className:"opacity-80",children:u.hint}),t.jsxs("div",{className:"font-mono text-[11.5px] opacity-70 truncate",title:u.message,children:[u.attempts," failed probe",u.attempts===1?"":"s",u.claudeVersion?` · CLI ${u.claudeVersion}`:"",u.lastSlug?` · last: ${u.lastSlug}`:""," · ",u.message]})]}),t.jsx("button",{type:"button",onClick:()=>window.api.schedule.resume(),className:o,children:"Retry now"})]},`launch-block-${p}`)),c.map(([p,u])=>t.jsx("div",{"data-testid":"launch-mitigation-banner",className:`${i} ${d}`,children:t.jsxs("div",{className:"flex-1 leading-snug min-w-0",children:[t.jsxs("div",{className:"font-medium",children:[t.jsx("span",{className:"font-mono",children:p})," jobs are running in degraded mode"," ","(",t.jsx("span",{className:"font-mono",children:Object.entries(u.env).map(([h,g])=>`${h}=${g}`).join(" ")}),")",u.claudeVersion?` since CLI ${u.claudeVersion}`:"","."]}),t.jsx("div",{className:"opacity-80",children:u.hint})]})},`launch-mitigation-${p}`))]})}function vn({scopeCwd:e,subView:s,onSubView:n,filterText:a,onFilterText:c,planMode:l,onPlanMode:i,planToolsRef:r}){const d=Fe(C=>C.snapshot),o=pe(C=>C.sessions),p=gn(e),[u,h]=f.useState(()=>Date.now()),[g,x]=f.useState("—");f.useEffect(()=>{const C=setInterval(()=>h(Date.now()),3e4);return()=>clearInterval(C)},[]),f.useEffect(()=>{let C=!0;return qs(30).then(R=>{if(!C||!R.ok||!R.data)return;const L=new Date,_=He=>String(He).padStart(2,"0"),X=`${L.getFullYear()}-${_(L.getMonth()+1)}-${_(L.getDate())}`;x(Bs(Hs(R.data,{day:X})))}),()=>{C=!1}},[]);const w=f.useMemo(()=>((d==null?void 0:d.jobs)??[]).filter(C=>!e||C.cwd===e),[d,e]),j=f.useMemo(()=>ln(w,u),[w,u]),D=f.useMemo(()=>{const C=lt(w,{sessions:o,now:u}),R=L=>C.filter(_=>_.status===L).length;return{active:R("active"),queued:R("queued"),draft:R("draft")}},[w,o,u]),k=f.useMemo(()=>{const C=new Date(u).toDateString(),R=[];for(const L of w)if(L.status==="completed"&&L.startedAt&&L.finishedAt&&new Date(Date.parse(L.finishedAt)).toDateString()===C){const _=Date.parse(L.finishedAt)-Date.parse(L.startedAt);_>0&&R.push(_)}return R.length?Math.round(R.reduce((L,_)=>L+_,0)/R.length/6e4):null},[w,u]);if(!d)return null;const E=p&&!p.unknown?p.verdict??null:null,m=p&&!p.unknown?p.slots??null:null,T=d.paused,$=mn((E==null?void 0:E.kind)??null,!!T,j.inFlight),P=xn[$],O=w.filter(C=>C.status==="pending").length,J=w.filter(C=>C.status==="running").length,W=Qt({snap:{...d,jobs:w},now:u,avgDurationMs:0,runningJobs:w.filter(C=>C.status==="running")}),Q=p!=null&&p.unknown?`Queue health: unknown — ${p.reason??"state unavailable"}`:E?hn(E,(p==null?void 0:p.oldestRunningAgeMs)??null):"queue health loading…",K=xe(d.lastRunAt?Date.parse(d.lastRunAt):null,u),te=p!=null&&p.lastDispatchAttemptAt?xe(Date.parse(p.lastDispatchAttemptAt),u):"never",se=[Q,W.line1,E?`dispatchable ${E.dispatchable} · needs_review ${E.needsReviewCount}`:null,(p==null?void 0:p.oldestRunningAgeMs)!=null?`oldest running ${ee(p.oldestRunningAgeMs)} (any project)`:null,`last batch fired ${K} (lastRunAt — advances only when a job launches)`,`last dispatch attempt ${te} (advances on every driver evaluation)`].filter(Boolean).join(`
2
2
  `),Y=d.utilization,M=d.pollHealth,B=M!=null&&!M.lastPollOk,N=xs(d.utilizationWindow),S=d.nextReset?Date.parse(d.nextReset):null,G=S?S>u?ee(S-u):"soon":"—",F=d.effectiveConcurrency,U=(F==null?void 0:F.cap)??5,b=(F==null?void 0:F.source)==="env",y=d.config.firePolicy??"when-available",A=O===0&&J===0;return t.jsxs("div",{"data-testid":"scheduler-top-bands",className:"shrink-0 px-[18px]",children:[t.jsxs(Ue,{height:40,testId:"queue-health-header",className:"gap-3",children:[t.jsx("h1",{className:"m-0 font-serif text-[21px] font-semibold leading-none tracking-tight text-fg",children:"Scheduler"}),t.jsx("span",{className:"w-px h-[20px] bg-rule-structural","aria-hidden":"true"}),t.jsxs("span",{className:`inline-flex items-center gap-1.5 text-[12.5px] font-medium ${P.text}`,"data-testid":"scheduler-state-word","data-state":$,children:[t.jsx("span",{className:`w-2 h-2 rounded-full ${P.dot}`,"aria-hidden":"true"}),$]}),t.jsxs("span",{className:"font-mono text-[12px] text-fg-faint whitespace-nowrap","data-testid":"scheduler-meta",children:[j.inFlight," in flight · ",j.heldByDeps," held · last batch ",K]}),t.jsxs(me,{title:se,testId:"scheduler-verdict-info",popoverTestId:"scheduler-info-popover",children:[t.jsx("pre",{className:"m-0 mb-2 whitespace-pre-wrap font-mono text-[11.5px] text-fg-dim",children:se}),bt.scheduler&&t.jsx(ms,{content:bt.scheduler})]}),t.jsxs("span",{className:"ml-auto flex items-center gap-2",children:[t.jsx("button",{type:"button",onClick:()=>window.api.schedule.rescan().then(q.fromOutcome).catch(()=>q.error("Failed to rescan")),title:"Re-scan the prds/ folder. Use when you've added or edited PRDs on disk and want the queue to reflect them immediately.",className:Qe,children:"Refresh"}),T?t.jsx("button",{type:"button",onClick:()=>window.api.schedule.resume(),title:"Clear the pause and resume queue immediately",className:Qe,children:"Resume"}):t.jsx("button",{type:"button",onClick:()=>window.api.schedule.pause(),title:"Stop NEW dispatch. Running jobs are not killed.",className:Qe,children:"Pause"}),t.jsx("button",{type:"button",onClick:()=>window.api.schedule.forceTick().then(q.fromOutcome).catch(()=>q.error("Failed to fire batch")),disabled:A,title:"Bypasses the billing-usage poll. Use when the meter is rate-limited or you want immediate progress.",className:"px-3 py-1.5 rounded bg-accent text-white text-[12.5px] font-semibold whitespace-nowrap disabled:opacity-40 disabled:cursor-not-allowed hover:opacity-90",children:"Fire next batch"})]})]}),t.jsx(wn,{now:u}),t.jsxs(Ue,{height:70,testId:"scheduler-kpi-band",children:[t.jsx(ge,{testId:"kpi-window",label:N?`${N} used`:"Window used",info:B?`Billing poll failing — this reading may be outdated (last good reading ${xe(M.lastPollAt,u)}). Machine-wide ${N??"binding"} window.`:`Share of the machine-wide ${N??"binding"} billing window consumed — the window closest to its limit.`,value:Y==null?"—":`${Math.round(Y)}%`,sub:`resets in ${G}`,third:t.jsx(bs,{pct:Y??0,tone:B?"bg-amber-500":"bg-accent"})}),t.jsx(ge,{testId:"kpi-slots",label:"Slots",info:`Machine-wide session pool (${(m==null?void 0:m.source)==="env"?"SM_SESSION_SLOTS override":"Home tab cap"}), not scoped to this project`,value:m?`${m.inUse}/${m.total}`:"—",sub:"in use",third:m?t.jsx(ws,{filled:m.inUse,total:m.total}):null}),t.jsx(ge,{testId:"kpi-ready",label:"Ready now",info:"Pending rows whose dependsOn chain is fully satisfied right now",value:j.readyNow,sub:`of ${j.totalQueued} queued`,third:`${j.heldByDeps} held by deps`}),j.needsYou>0?t.jsx(ge,{testId:"kpi-needs-you",label:"Needs you",value:t.jsx("button",{type:"button","data-testid":"kpi-needs-you-jump",onClick:St,className:"font-semibold text-accent hover:underline",title:"Scroll to the first failed / needs-review / quarantined row",children:j.needsYou}),sub:t.jsx("button",{type:"button",onClick:St,className:"hover:underline",children:j.needsYouStage!=null?`blocking stage ${j.needsYouStage}`:"need attention"}),third:[j.failedCount>0&&`${j.failedCount} failed`,j.needsReviewCount>0&&`${j.needsReviewCount} needs review`,j.needsYou-j.failedCount-j.needsReviewCount>0&&`${j.needsYou-j.failedCount-j.needsReviewCount} quarantined`].filter(Boolean).join(" · ")}):t.jsx(ge,{testId:"kpi-needs-you",label:"Needs you",value:t.jsxs("span",{className:"inline-flex items-center gap-1.5 text-[15px]",children:[t.jsx("span",{className:"w-2.5 h-2.5 rounded-full bg-sage","aria-hidden":"true"}),"all clear"]}),third:"0 failed · 0 needs review"}),t.jsx(ge,{testId:"kpi-done",label:"Done today",value:j.doneToday,sub:k!=null?`avg ${k}m`:"avg —",third:t.jsx("span",{"data-testid":"kpi-done-spend",children:g})}),t.jsx(ge,{testId:"kpi-concurrency",label:"Concurrency",info:"Start-jobs policy, concurrency cap and utilization threshold",infoTestId:"kpi-concurrency-info",infoAlignRight:!0,infoContent:t.jsxs("label",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-fg",children:"Start jobs"}),t.jsxs("select",{"data-testid":"kpi-fire-policy",value:y,onChange:C=>window.api.schedule.setConfig({firePolicy:C.target.value}),className:"border border-line bg-bg-hi rounded px-1 py-0.5 text-[12px] text-fg-dim",title:"when-available: poll usage and fire when tokens are below threshold. on-reset: fire after each 5h reset. manual: only on Run now.","aria-label":"Start jobs policy",children:[t.jsx("option",{value:"when-available",children:"when available"}),t.jsx("option",{value:"on-reset",children:"only on reset"}),t.jsx("option",{value:"manual",children:"manually"})]})]}),value:t.jsxs("span",{className:"inline-flex items-center gap-1",children:[t.jsx(js,{value:U,min:0,max:10,disabled:b,onChange:C=>{ys(C).catch(R=>{q.error(`Could not set session slots: ${R instanceof Error?R.message:String(R)}`)})},title:b?"pinned by SM_SESSION_SLOTS — unset the env var to edit":"Machine-wide claude -p session slots, shared with chat runs"}),b&&t.jsx("span",{className:"text-[10px] font-semibold uppercase tracking-wide text-amber-600 bg-amber-400/10 border border-amber-400/30 rounded px-1 py-0",title:"Pinned by SM_SESSION_SLOTS — unset the env var to edit",children:"env"})]}),sub:"at once",third:y==="when-available"?t.jsxs("span",{children:["pause above"," ",t.jsx(vs,{value:d.config.utilizationThreshold??90,min:0,max:100,testId:"kpi-threshold",title:"Holds new dispatches when the highest of the 5-hour and weekly usage windows is at/above this percent (when-available policy only). Not the executor rate-limit pause — click to edit",onCommit:C=>window.api.schedule.setConfig({utilizationThreshold:C})})]}):null})]}),t.jsxs(Ue,{height:30,testId:"scheduler-plans-toolbar",className:"gap-3",children:[t.jsx("span",{className:"text-[10.5px] font-semibold uppercase tracking-wide text-fg-faint",children:"Plans"}),t.jsxs("span",{className:"font-mono text-[12px] text-fg-faint whitespace-nowrap","data-testid":"scheduler-plans-meta",children:[D.active," active · ",D.queued," queued · ",D.draft," draft · ",w.length," PRDs"]}),t.jsxs("span",{className:"ml-auto flex items-center gap-3",children:[t.jsx("span",{ref:r,className:"contents","data-testid":"scheduler-plan-tools"}),t.jsx("input",{type:"text",value:a,onChange:C=>c(C.target.value),placeholder:"filter PRDs…","aria-label":"Filter PRDs by title, slug, or project","data-testid":"scheduler-filter-input",className:"w-[180px] bg-bg-hi border border-line rounded px-2 py-0.5 text-[12px] text-fg placeholder:text-fg-faint focus:outline-none focus:border-fg-faint"}),t.jsx("span",{className:"inline-flex border border-line rounded overflow-hidden",role:"group","aria-label":"Plan view mode",children:[["graph","Graph"],["list","List"],["critical","Critical path"]].map(([C,R])=>t.jsx("button",{type:"button","data-testid":`plan-mode-${C}`,"aria-pressed":l===C&&s==="queue",onClick:()=>{i(C),n("queue")},className:`px-2 py-0.5 text-[12px] ${l===C&&s==="queue"?"bg-bg-elev font-semibold text-fg":"text-fg-dim hover:text-fg"}`,children:R},C))}),t.jsx("span",{className:"w-px h-[16px] bg-rule-structural","aria-hidden":"true"}),[["prds","PRDs","Authored PRD source files on disk — edit, lint, archive, or queue them."],["history","History","The last 50 completed and failed jobs."],["machine","Machine","Machine-wide config that applies to every project — not this project’s live queue."]].map(([C,R,L])=>t.jsx("button",{type:"button",onClick:()=>n(C),"aria-pressed":s===C,title:L,className:`text-[12.5px] ${s===C?"font-semibold text-fg":"text-fg-faint hover:text-fg-dim"}`,children:R},C))]})]})]})}function Yt({options:e,value:s,onChange:n,pillPadding:a="px-3 py-1.5"}){return t.jsx("div",{className:"flex gap-1.5 flex-wrap",children:e.map(c=>{const l=c.value===s;return t.jsxs("button",{type:"button",onClick:()=>n(c.value),className:`rounded-full ${a} text-[12.5px] border transition-colors ${l?"bg-accent text-white border-accent font-semibold":"bg-bg-hi text-fg-dim border-line hover:border-fg-faint font-medium"}`,children:[c.label,c.count!==void 0&&t.jsxs("span",{children:[" ",c.count]})]},c.value)})})}function zt(e,s=60){const n=e.trim();return n.length<=s?n:`${n.slice(0,s-1)}…`}function jn(e){return Be([e]).filter(s=>s.children.length===0).map(s=>s.row.slug)}function Jt(e){return e.nodes.map(s=>({rootSlug:s.row.slug,label:s.row.title||s.row.slug,terminals:jn(s)}))}function yn(e){const s=new Map;for(const n of e){const a=Jt(n);n.nodes.forEach((c,l)=>{const i=a.filter((r,d)=>d!==l);for(const r of Be([c]))s.set(r.row.slug,i)})}return s}function Kt({job:e,headChoices:s}){const[n,a]=f.useState(!1),c=f.useCallback((l,i)=>{a(!0),window.api.schedule.setPrdDisposition({slug:e.slug,cwd:e.cwd??void 0,disposition:l,dependsOn:i}).then(q.fromOutcome).catch(()=>q.error("Failed to change disposition")).finally(()=>a(!1))},[e.slug,e.cwd]);return e.disposition!=="append"&&s.length===0?null:t.jsxs("select",{"data-testid":"job-row-disposition-control",disabled:n,value:"",onChange:l=>{const i=l.target.value;if(i==="__new-head__")c("new-head");else if(i){const r=s.find(d=>d.rootSlug===i);r&&c("append",r.terminals)}},className:"text-[13px] font-semibold text-fg-dim hover:text-fg bg-transparent border border-line/60 rounded px-1.5 py-0.5 cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed",title:"Change this wave's relationship to the rest of the Epic's plan",children:[t.jsx("option",{value:"",disabled:!0,children:"change disposition…"}),e.disposition==="append"&&t.jsx("option",{value:"__new-head__",children:"promote to new head"}),s.map(l=>t.jsxs("option",{value:l.rootSlug,children:["attach behind: ",zt(l.label,40)]},l.rootSlug))]})}function Nn(e,s,n=null){if(s.length===0||e.length===0)return e;const a=new Set,c=new Set;for(const i of e){a.add(i.slug);for(const r of wt(i))c.add(r)}const l=[];for(const i of s)i.archived!==!0||a.has(i.slug)||n&&i.cwd!==n||wt(i).some(r=>c.has(r))&&(a.add(i.slug),l.push({slug:i.slug,title:i.title,cwd:i.cwd,parallelGroup:i.parallelGroup,estimateMinutes:i.estimateMinutes,bodyPreview:"",status:i.archivedStatus??"completed",runId:null,startedAt:null,finishedAt:null,exitCode:null,error:null,dependsOn:i.dependsOn??void 0,sourcePromptId:i.sourcePromptId??null,epicId:i.epicId??null,synthetic:!0}));return l.length===0?e:[...e,...l]}const kn=[],Sn=new Set(["failed","needs_review","quarantined"]);function Cn(e){switch(e.status){case"completed":case"skipped":return"bg-sage";case"running":case"investigating":return"bg-accent";case"failed":return"bg-accent";case"needs_review":return"bg-butter";case"quarantined":return"bg-butter/60";default:return e.rowKind==="eta"||e.rowKind==="next"||e.rowKind==="retry"?"border border-fg-faint bg-transparent":"bg-fg-faint/40"}}function $n(e){switch(e.status){case"running":case"investigating":return"bg-butter/10";case"failed":return"bg-accent/10";case"needs_review":return"bg-butter/25";default:return""}}function Pn(e){switch(e.rowKind){case"running":case"dep":case"failed":return"text-accent";case"review":return"text-butter font-semibold";default:return"text-fg-faint"}}function Dn({row:e,elapsedMs:s,listIndex:n,onFocused:a,headChoices:c=kn}){const[l,i]=f.useState(!1),r=e.job,d=s!==null&&e.rowKind==="running"?Ut(r,s):e.rowTrailing,o=e.status==="completed"||e.status==="skipped",p=e.rowKind==="dep"&&e.blockers.some(h=>!h.missing&&h.status!==null&&Sn.has(h.status)),u=o||p;return t.jsxs("div",{role:"listitem","data-testid":"prd-row","data-slug":e.slug,className:"border-t border-rule-inner first:border-t-0",children:[t.jsxs("button",{type:"button","data-job-row":!0,"data-job-status":r.status,"data-job-index":n,onClick:()=>i(h=>!h),onFocus:()=>a(n),"aria-expanded":l,"aria-label":`${e.prdNumber?`PRD ${e.prdNumber}, `:""}${r.title}, ${r.status}${d?`, ${d}`:""}`,title:r.title,className:`w-full h-[31px] py-1 px-2 text-left flex items-center gap-1.5 hover:bg-bg/40 focus:outline-none focus:ring-1 focus:ring-accent focus:ring-inset ${$n(e)}`,children:[t.jsx("span",{"aria-hidden":"true",className:`shrink-0 w-[7px] h-[7px] rounded-full ${Cn(e)}`}),t.jsx("span",{className:"shrink-0 font-mono text-[10.5px] text-fg-faint w-[30px]",children:e.prdNumber?`#${e.prdNumber}`:""}),t.jsx("span",{className:`flex-1 min-w-0 truncate text-[12.5px] leading-tight ${u?"text-fg-faint":"text-fg font-medium"}`,children:r.title}),t.jsx("span",{"data-testid":"prd-row-trailing",className:`shrink-0 font-mono text-[10.5px] ${Pn(e)}`,children:d})]}),l&&t.jsx(An,{row:e,elapsedMs:s,headChoices:c})]})}const Xt=f.memo(Dn);function An({row:e,elapsedMs:s,headChoices:n}){const a=e.job,[c,l]=f.useState(!1),i=pe(g=>g.sessions),r=f.useMemo(()=>Pe(a,i),[a,i]),d=r.known&&r.epicId?i[r.epicId]:null,o=f.useCallback(g=>Tt(g),[]),p="font-mono text-[11.5px] text-fg-dim leading-snug break-words",u="text-[12px] font-semibold bg-transparent border-0 cursor-pointer p-0",h=a.error?a.error.split(`
3
3
  `)[0]:null;return t.jsxs("div",{"data-testid":"prd-row-detail",className:"px-3 py-2 bg-bg-elev/50 border-t border-rule-inner flex flex-col gap-1",children:[t.jsxs("div",{className:p,children:[a.status.replace(/_/g," "),a.exitCode!==null&&` · exit ${a.exitCode}`,a.verifierVerdict&&` · ${$e(a.verifierVerdict)}`,a.startedAt&&` · started ${le(Date.parse(a.startedAt))}`,a.finishedAt&&` · finished ${le(Date.parse(a.finishedAt))}`,s===null&&e.rowTrailing&&e.rowKind==="done"?` · took ${e.rowTrailing}`:""]}),e.cycle&&t.jsxs("div",{className:`${p} text-accent`,"data-testid":"job-row-cycle-warning",children:["⚠ dependsOn cycle — ",e.blockers.map(g=>g.slug).join(" ↔ ")||"self-referencing"]}),!e.cycle&&e.blockers.length>0&&t.jsxs("div",{className:p,"data-testid":"job-row-blockers",children:["depends on ",e.blockers.map(g=>`${g.slug} (${g.missing?"missing":(g.status??"unknown").replace(/_/g," ")})`).join(", ")]}),a.status==="pending"&&a.heldReason&&t.jsxs("div",{className:`${p} text-amber-400/90`,"data-testid":"job-row-held-reason",children:["held · ",a.heldReason]}),h&&t.jsx("div",{className:`${p} text-accent/80`,children:h}),!a.synthetic&&t.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1 pt-0.5",children:[d&&t.jsx("button",{type:"button","data-testid":"job-row-prompt-session-link",title:d.goalText,onClick:()=>o(d.id),className:`${u} text-accent hover:text-accent/80`,children:"view epic →"}),a.runId&&t.jsx("button",{type:"button",onClick:()=>l(!0),className:`${u} text-fg-dim hover:text-fg`,children:"view log →"}),a.status==="quarantined"&&t.jsx("button",{type:"button","data-testid":"job-row-adopt-prd",title:"Stamp this PRD's provenance so the scheduler will run it — no unstamped PRD runs automatically.",onClick:()=>{window.api.schedule.adoptPrd(a.slug).then(q.fromOutcome).catch(()=>q.error("Failed to adopt PRD"))},className:`${u} text-accent hover:text-accent/80`,children:"adopt PRD →"}),a.status!=="pending"&&a.status!=="running"&&a.status!=="quarantined"&&t.jsx("button",{type:"button",onClick:()=>window.api.schedule.resetJob(a.slug,a.cwd??void 0),className:`${u} text-fg-dim hover:text-fg`,children:"reset to pending →"}),a.disposition&&(a.status==="pending"||a.status==="quarantined")&&t.jsx(Kt,{job:a,headChoices:n})]}),c&&a.runId&&t.jsx(qe,{runId:a.runId,slug:a.slug,title:a.title||a.slug,onClose:()=>l(!1)})]})}const ue=190,Mn=7,Rn=5,In=[],Zt=e=>e==="completed"||e==="skipped",es=e=>e==="running"||e==="investigating",ts=e=>e==="failed"||e==="needs_review"||e==="quarantined";function Me(e){return es(e.status)?0:ts(e.status)?1:Zt(e.status)?3:2}const En={done:"text-sage",running:"text-accent",held:"text-fg-faint",pending:"text-fg-faint",blocked:"text-butter"},Tn={done:"bg-sage",running:"bg-accent",held:"bg-fg-faint/50",pending:"bg-fg-faint/50",blocked:"bg-butter"};function _n(e,s){return e.every(n=>Zt(n.status))?`+${e.length} done`:e.every(n=>n.rowKind==="dep"&&n.blockers.some(a=>!a.missing&&a.status!==null&&ts(a.status)))?`+${e.length} blocked`:`+${e.length} in stage ${s}`}function On({stage:e,epicId:s,now:n,hidden:a,indexBySlug:c,headChoicesBySlug:l,onRowFocused:i}){const[r,d]=f.useState(!1),o=f.useMemo(()=>e.rows.filter(m=>!(a.has(m.slug)&&(m.status==="completed"||m.status==="failed"))).map((m,T)=>({r:m,i:T})).sort((m,T)=>Me(m.r)-Me(T.r)||m.i-T.i).map(m=>m.r),[e.rows,a]),p=f.useMemo(()=>o.filter(m=>Me(m)<=1).length,[o]),u=Math.max(e.state==="done"?Rn:Mn,p),h=r?o:o.slice(0,u),g=r?[]:o.slice(u),x=o.find(m=>m.status==="failed"),w=o.find(m=>m.status==="needs_review"),j=p>0&&(x!==void 0||w!==void 0),D=h.reduce((m,T,$)=>Me(T)<=1?$:m,-1),k=m=>t.jsx(Xt,{row:m,elapsedMs:es(m.status)&&m.job.startedAt?n-Date.parse(m.job.startedAt):null,listIndex:c.get(m.slug)??0,onFocused:i,headChoices:l.get(m.slug)??In},m.slug),E="flex-1 min-w-0 truncate h-[24px] text-[11.5px] font-medium text-fg-dim hover:text-fg border border-rule-structural rounded-sm bg-transparent cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed";return t.jsxs("div",{"data-testid":"stage-column","data-stage":e.n,style:{width:ue},className:"shrink-0 border-l border-rule-structural first:border-l-0 flex flex-col self-stretch",children:[t.jsxs("div",{className:"h-[30px] shrink-0 flex items-center gap-1.5 px-2 border-b border-rule-inner","data-testid":"stage-header",children:[t.jsx("span",{"aria-hidden":"true",className:`w-[7px] h-[7px] rounded-full shrink-0 ${Tn[e.state]}`}),t.jsxs("span",{className:`text-[10px] font-semibold uppercase tracking-wide ${En[e.state]}`,children:["Stage ",e.n]}),e.state==="blocked"&&t.jsx(me,{title:"Rows in this stage are failed / need review / are quarantined, or wait on one that is."}),t.jsx("span",{"data-testid":"stage-summary",className:"ml-auto font-mono text-[10.5px] text-fg-dim truncate",children:e.summary})]}),t.jsx("div",{role:"presentation",children:h.map((m,T)=>t.jsxs("div",{children:[k(m),j&&T===D&&t.jsxs("div",{"data-testid":"stage-attention-actions",className:"flex gap-1.5 px-2 py-1.5 border-t border-rule-inner",children:[x&&t.jsxs("button",{type:"button","data-testid":"stage-retry",title:`Reset ${x.slug} to pending`,onClick:()=>{window.api.schedule.resetJob(x.slug,x.job.cwd??void 0).then($=>{$.ok||q.error($.error??`Failed to reset ${x.slug}`)}).catch(()=>q.error(`Failed to reset ${x.slug}`))},className:E,children:["Retry ",x.prdNumber?`#${x.prdNumber}`:x.slug]}),w&&t.jsxs("button",{type:"button","data-testid":"stage-review",disabled:!s,title:s?"Open the authoring Epic — a needs_review PRD is a question routed back to it":"No authoring Epic recorded for this plan",onClick:()=>{s&&Tt(s)},className:E,children:["Review ",w.prdNumber?`#${w.prdNumber}`:w.slug]})]})]},m.slug))}),(g.length>0||r&&o.length>u)&&t.jsx("button",{type:"button","data-testid":"stage-footer","aria-expanded":r,onClick:()=>d(m=>!m),className:"mt-auto h-[26px] border-t border-rule-inner font-mono text-[11px] text-fg-faint hover:text-fg-dim bg-transparent cursor-pointer",children:r?"show less ▴":`${_n(g,e.n)} ▾`})]})}const we=6,Ye=4,Ee=4,Ct=12,$t=5,ss=2,Pt=4,Ln={done:"bg-sage",running:"bg-accent",attention:"bg-butter",failed:"bg-red-600",pending:"bg-fg-faint/50"};function Fn(e){return e==="completed"||e==="skipped"?"done":e==="running"||e==="investigating"?"running":e==="failed"?"failed":e==="needs_review"||e==="quarantined"?"attention":"pending"}function qn(e){const s=[],n=[],a=[];let c=$t;for(const l of e){const i=Math.max(1,Math.ceil(l.rows.length/Ee));n.push(c),a.push(i*we),l.rows.forEach((r,d)=>{s.push({x:c+Math.floor(d/Ee)*we,y:ss+d%Ee*we,tone:Fn(r.status),title:`${r.prdNumber?`#${r.prdNumber}`:r.slug} ${r.title} — ${r.status}`})}),c+=i*we+Ct}return{dots:s,stageX:n,stageW:a,width:Math.max(0,c-Ct)+$t}}function ve(e,s){return e.findIndex(n=>n.rows.some(a=>s(a.status)))}const et=e=>e==="running"||e==="investigating",tt=e=>e==="failed"||e==="needs_review"||e==="quarantined";function Bn({stages:e,first:s,perView:n,onSeek:a}){const c=f.useMemo(()=>qn(e),[e]),l=f.useMemo(()=>ve(e,et)>=0,[e]),i=f.useMemo(()=>ve(e,tt)>=0,[e]),r=f.useRef(!1),d=e.length,o=Math.min(d-1,s+n-1),p=c.stageX[Math.min(s,d-1)]??0,u=(c.stageX[o]??0)+(c.stageW[o]??0),h=x=>{const w=x.currentTarget.getBoundingClientRect(),j=x.clientX-w.left;let D=0;for(let k=0;k<d;k++)c.stageX[k]<=j&&(D=k);a(Math.max(0,Math.min(d-1,D-Math.floor(n/2))))},g="px-2 h-[20px] text-[11.5px] disabled:opacity-40 disabled:cursor-not-allowed";return t.jsxs("div",{"data-testid":"plan-minimap",className:"h-[28px] flex items-center gap-3 px-3 border-t border-rule-inner",children:[t.jsxs("span",{className:"shrink-0 flex items-center gap-1 text-[10.5px] font-semibold uppercase tracking-wide text-fg-faint",children:["Whole graph",t.jsx(me,{title:"Every PRD in this plan as one dot, grouped by stage. The rust box is the range of stages shown below — drag it to scroll."})]}),t.jsxs("div",{"data-testid":"plan-minimap-dots",role:"presentation",className:"relative shrink min-w-0 overflow-hidden cursor-ew-resize touch-none",style:{width:c.width,height:Ee*we-(we-Ye)+2*ss},onPointerDown:x=>{var w,j;r.current=!0,(j=(w=x.currentTarget).setPointerCapture)==null||j.call(w,x.pointerId),h(x)},onPointerMove:x=>{r.current&&h(x)},onPointerUp:()=>{r.current=!1},onPointerCancel:()=>{r.current=!1},children:[c.dots.map((x,w)=>t.jsx("span",{title:x.title,"data-tone":x.tone,className:`absolute rounded-[1px] ${Ln[x.tone]}`,style:{left:x.x,top:x.y,width:Ye,height:Ye}},w)),t.jsx("span",{"data-testid":"plan-minimap-brush","aria-hidden":"true",className:"absolute top-0 bottom-0 border border-accent bg-accent/10 rounded-[2px] pointer-events-none",style:{left:p-Pt,width:u-p+2*Pt}})]}),t.jsxs("span",{className:"ml-auto shrink-0 font-mono text-[11.5px] text-fg-faint","data-testid":"plan-minimap-range",children:["stages ",Math.min(s+1,d),"–",o+1," of ",d]}),t.jsxs("span",{className:"shrink-0 inline-flex border border-line rounded overflow-hidden",role:"group","aria-label":"Jump the stage window",children:[t.jsx("button",{type:"button","data-testid":"minimap-running",disabled:!l,title:l?"Scroll to the lowest stage with a running PRD":"No stage has a running PRD",onClick:()=>a(ve(e,et)),className:`${g} text-fg-dim hover:text-fg`,children:"Running"}),t.jsx("button",{type:"button","data-testid":"minimap-blockers",disabled:!i,title:i?"Scroll to the lowest stage with a failed / needs-review / quarantined PRD":"No stage has a failed, needs-review or quarantined PRD",onClick:()=>a(ve(e,tt)),className:`${g} text-fg-dim hover:text-fg border-l border-line`,children:"Blockers"})]})]})}const Hn=148;function Gn({stages:e,onSeek:s}){if(e.length===0)return null;const n=e[0].n,a=e[e.length-1].n;return t.jsxs("div",{"data-testid":"further-stages",style:{width:Hn},className:"shrink-0 border-l border-rule-structural flex flex-col",children:[t.jsxs("div",{className:"h-[30px] shrink-0 flex items-center px-2 border-b border-rule-inner text-[10.5px] font-semibold uppercase tracking-wide text-fg-faint",children:["Stage ",n,"–",a]}),t.jsxs("div",{className:"h-[22px] shrink-0 flex items-center gap-1 px-2 text-[10.5px] font-semibold uppercase tracking-wide text-fg-faint",children:["Further stages",t.jsx(me,{title:"Stages beyond the visible window. Click one to scroll the stage columns to it."})]}),e.map(c=>{const l=c.rows.length===0?0:c.doneCount/c.rows.length*100;return t.jsxs("button",{type:"button","data-testid":"further-stage-row","data-stage":c.n,title:`${c.summary} — scroll to stage ${c.n}`,onClick:()=>s(c.n-1),className:"h-[26px] px-2 flex items-center gap-2 border-t border-rule-inner bg-transparent hover:bg-bg-hi cursor-pointer text-left",children:[t.jsxs("span",{className:"font-mono text-[10.5px] text-fg-dim w-[50px] whitespace-nowrap shrink-0",children:["stage ",c.n]}),t.jsx("span",{role:"progressbar","aria-valuenow":c.doneCount,"aria-valuemin":0,"aria-valuemax":c.rows.length,className:"flex-1 h-[4px] rounded-sm bg-rule-inner overflow-hidden",children:t.jsx("span",{className:"block h-full bg-sage",style:{width:`${l}%`}})})]},c.n)})]})}const Vn=[],Wn=e=>e==="running"||e==="investigating";function Un(e){const s=on(e),n=new Map,a=new Map;for(const r of e.stages){a.set(r.n,r.rows.length);for(const d of r.rows)n.set(d.slug,d)}const c=new Map;let l=0;const i=[];for(const r of s){const d=n.get(r);l+=d.estimateMinutes??0,c.set(d.stage,(c.get(d.stage)??0)+1),i.push({row:d,totalMinutes:l,othersInStage:0})}for(const r of i)r.othersInStage=(a.get(r.row.stage)??0)-(c.get(r.row.stage)??0);return i}function Qn({plan:e,now:s,indexBySlug:n,headChoicesBySlug:a,onRowFocused:c}){const l=f.useMemo(()=>Un(e),[e]);return t.jsx("div",{"data-testid":"critical-path",className:"border-t border-rule-structural max-w-[640px]",children:l.map(({row:i,totalMinutes:r,othersInStage:d})=>t.jsxs("div",{"data-testid":"critical-entry","data-slug":i.slug,children:[t.jsxs("div",{className:"flex items-start",children:[t.jsx("div",{className:"flex-1 min-w-0",children:t.jsx(Xt,{row:i,elapsedMs:Wn(i.status)&&i.job.startedAt?s-Date.parse(i.job.startedAt):null,listIndex:n.get(i.slug)??0,onFocused:c,headChoices:a.get(i.slug)??Vn})}),t.jsxs("span",{"data-testid":"critical-est",className:"shrink-0 h-[31px] px-3 flex items-center gap-2 font-mono text-[11.5px] text-fg-faint border-t border-rule-inner",children:[t.jsx("span",{title:"estimateMinutes",children:i.estimateMinutes?`${i.estimateMinutes}m`:"—"}),t.jsxs("span",{className:"text-fg-dim",title:"Running total along the chain",children:["Σ ",r,"m"]})]})]}),d>0&&t.jsxs("div",{"data-testid":"critical-others",className:"h-[22px] px-3 flex items-center font-mono text-[11.5px] text-fg-faint border-t border-rule-inner",children:["stage ",i.stage," · +",d," not on the critical path"]})]},i.slug))})}const Dt=1,At=1350,Yn={active:"border-l-accent",queued:"border-l-rule-structural",done:"border-l-sage",draft:"border-l-fg-faint/40 border-dashed"},zn={active:{label:"ACTIVE",cls:"bg-accent text-white border border-accent"},queued:{label:"QUEUED",cls:"text-fg-dim border border-fg-faint"},done:{label:"DONE",cls:"text-sage-dark border border-sage"},draft:{label:"DRAFT",cls:"text-fg-faint border border-dashed border-fg-faint"}},Jn=e=>String(e).padStart(2,"0");function Kn({plan:e}){const s=Math.max(1,e.prdCount),n=e.doneCount/s*100,a=e.runningCount/s*100;return t.jsxs("span",{"data-testid":"plan-progress",role:"progressbar","aria-valuenow":e.doneCount,"aria-valuemin":0,"aria-valuemax":e.prdCount,className:"flex w-[160px] h-[5px] rounded-sm overflow-hidden bg-rule-inner shrink-0",children:[t.jsx("span",{className:"h-full bg-sage",style:{width:`${n}%`}}),t.jsx("span",{className:"h-full bg-accent",style:{width:`${a}%`}})]})}function Xn({plan:e,mode:s="graph",now:n,hidden:a,indexBySlug:c,headChoicesBySlug:l,onRowFocused:i,onOpenPrds:r}){var se,Y;const[d,o]=f.useState(e.status==="active"||e.status==="queued"),[p,u]=f.useState(!1),h=f.useRef(null),[g,x]=f.useState(0),[w,j]=f.useState(At),D=f.useMemo(()=>{const M=ve(e.stages,et);return M>=0?M:Math.max(0,ve(e.stages,tt))},[e.stages]);f.useLayoutEffect(()=>{if(!d)return;const M=h.current,B=(M==null?void 0:M.clientWidth)||At,N=Math.max(0,Math.min(D,e.stageCount-Math.max(1,Math.ceil(B/ue))));M!=null&&M.clientWidth&&j(M.clientWidth),M&&(M.scrollLeft=N*ue),x(N)},[d]);const k=f.useMemo(()=>{let M=null;for(const B of e.stages)for(const N of B.rows){if(!N.job.runId)continue;const S=N.job.finishedAt?Date.parse(N.job.finishedAt):0;(!M||S>M.at)&&(M={runId:N.job.runId,slug:N.slug,title:N.title,at:S})}return M},[e.stages]),E=_e((Y=(se=e.stages[0])==null?void 0:se.rows[0])==null?void 0:Y.job.cwd)??"—",m=zn[e.status],T=Math.max(1,Math.ceil(w/ue)),$=Math.max(0,Math.min(g-Dt,e.stageCount)),P=Math.min(e.stageCount,g+T+Dt),O=M=>{const B=Math.max(0,Math.min(e.stageCount-1,M));h.current&&(h.current.scrollLeft=B*ue),x(B)},J=Math.min(e.stageCount,g+T),W=M=>{const B=M.currentTarget,N=Math.floor(B.scrollLeft/ue);N!==g&&x(N),B.clientWidth&&B.clientWidth!==w&&j(B.clientWidth)},Q="h-[24px] px-3 text-[12px] font-medium text-fg border border-rule-structural rounded-sm bg-transparent hover:bg-bg-hi cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed shrink-0",K=(()=>{switch(e.status){case"active":return t.jsx("button",{type:"button","data-testid":"plan-action",title:"Pauses the WHOLE scheduler (machine-wide) — there is no per-plan pause.",onClick:()=>{window.api.schedule.pause().catch(()=>q.error("Failed to pause the scheduler"))},className:Q,children:"Pause plan"});case"queued":return t.jsx("button",{type:"button","data-testid":"plan-action",title:"Fires the next scheduler batch machine-wide (force tick) — it does not target this plan.",onClick:()=>{window.api.schedule.forceTick().then(q.fromOutcome).catch(()=>q.error("Failed to fire the next batch"))},className:Q,children:"Run now"});case"done":return t.jsx("button",{type:"button","data-testid":"plan-action",disabled:!k,title:k?`Open the run log of ${k.slug}, the plan's last run`:"No run log recorded for this plan",onClick:()=>u(!0),className:Q,children:"View run"});case"draft":return t.jsx("button",{type:"button","data-testid":"plan-action",title:"Open the PRDs sub-view on this plan's first PRD (the PRDs view has no per-Epic filter).",onClick:()=>{var M,B;return r==null?void 0:r(((B=(M=e.stages[0])==null?void 0:M.rows[0])==null?void 0:B.slug)??null)},className:Q,children:"Schedule…"})}})(),te=e.etaMs>0?` · ${Wt(e.etaMs)} left`:"";return t.jsxs("section",{"data-testid":"plan-band","data-epic-id":e.epicId??"","data-plan-status":e.status,className:`border-l-[3px] ${Yn[e.status]} border-b border-rule-structural`,children:[t.jsxs("div",{className:"h-[32px] flex items-center gap-2.5 px-3","data-testid":"plan-header",children:[t.jsx("button",{type:"button","aria-expanded":d,"aria-label":d?"Collapse plan":"Expand plan","data-testid":"plan-toggle",onClick:()=>o(M=>!M),className:"shrink-0 w-[14px] text-[11px] text-fg-faint hover:text-fg bg-transparent border-0 cursor-pointer p-0",children:d?"▾":"▸"}),t.jsx("span",{className:"font-mono text-[11.5px] text-fg-faint shrink-0",children:Jn(e.index)}),t.jsx("span",{className:"font-serif text-[15px] font-bold text-fg truncate shrink-0 max-w-[320px]",title:e.epicLabel!==e.label?`${e.label} — ${e.epicLabel}`:e.label,"data-testid":"plan-label",children:e.label}),t.jsx("span",{"data-testid":"plan-chip",className:`shrink-0 rounded-sm px-1.5 py-[1px] text-[10px] font-bold tracking-wide ${m.cls}`,children:m.label}),t.jsx("span",{"aria-hidden":"true",className:"shrink-0 w-px h-[16px] bg-rule-structural"}),t.jsx("span",{className:"font-mono text-[11.5px] text-fg-faint truncate min-w-0","data-testid":"plan-meta",children:e.validateSlug!=null&&e.epicLabel!==e.label?t.jsxs(t.Fragment,{children:[E," · ",e.epicLabel," · ",e.prdCount," PRD",e.prdCount===1?"":"s"," · ",e.width," wide · ",e.stageCount," stage",e.stageCount===1?"":"s"]}):t.jsxs(t.Fragment,{children:[E," · ",e.prdCount," PRD",e.prdCount===1?"":"s",e.width>1?` · ${e.width} wide`:""," · ",e.stageCount," stage",e.stageCount===1?"":"s"]})}),t.jsx(me,{title:`${e.doneCount} done · ${e.runningCount} running · ${e.heldCount} held · ${e.blockedCount} blocked`}),t.jsxs("span",{className:"ml-auto font-mono text-[11.5px] text-fg-dim shrink-0","data-testid":"plan-progress-label",children:[e.doneCount,"/",e.prdCount,te]}),t.jsx(Kn,{plan:e}),K]}),d&&s==="critical"&&t.jsx(Qn,{plan:e,now:n,indexBySlug:c,headChoicesBySlug:l,onRowFocused:i}),d&&s!=="critical"&&e.status==="active"&&t.jsx(Bn,{stages:e.stages,first:g,perView:T,onSeek:O}),d&&s!=="critical"&&t.jsxs("div",{className:"flex border-t border-rule-structural",children:[t.jsxs("div",{ref:h,"data-testid":"plan-stages",onScroll:W,className:"flex flex-1 min-w-0 overflow-x-auto",children:[$>0&&t.jsx("div",{"aria-hidden":"true",className:"shrink-0",style:{width:$*ue}}),e.stages.slice($,P).map(M=>t.jsx(On,{stage:M,epicId:e.epicId,now:n,hidden:a,indexBySlug:c,headChoicesBySlug:l,onRowFocused:i},M.n)),P<e.stageCount&&t.jsx("div",{"aria-hidden":"true",className:"shrink-0",style:{width:(e.stageCount-P)*ue}})]}),t.jsx(Gn,{stages:e.stages.slice(J),onSeek:O})]}),p&&k&&t.jsx(qe,{runId:k.runId,slug:k.slug,title:k.title||k.slug,onClose:()=>u(!1)})]})}function Zn({page:e,pageSize:s,totalItems:n,onPageChange:a}){if(n<=s)return null;const c=Math.max(1,Math.ceil(n/s)),l=(e-1)*s+1,i=Math.min(e*s,n);return t.jsxs("div",{"data-testid":"plan-pager",className:"flex items-center justify-center gap-3 px-[18px] py-3 font-mono text-[12px] text-fg-faint",children:[t.jsx("button",{type:"button","data-testid":"plan-pager-prev",onClick:()=>a(e-1),disabled:e<=1,className:"px-2 py-1 rounded border border-line bg-bg-hi text-fg-dim hover:text-fg disabled:opacity-40 disabled:cursor-not-allowed cursor-pointer",children:"Prev"}),t.jsxs("span",{"data-testid":"plan-pager-range",children:[l,"–",i," of ",n]}),t.jsx("button",{type:"button","data-testid":"plan-pager-next",onClick:()=>a(e+1),disabled:e>=c,className:"px-2 py-1 rounded border border-line bg-bg-hi text-fg-dim hover:text-fg disabled:opacity-40 disabled:cursor-not-allowed cursor-pointer",children:"Next"})]})}function ea({section:e,children:s}){const[n,a]=f.useState(!0),c=Object.entries(e.counts).map(([l,i])=>`${i} ${l.replace(/_/g," ")}`).join(" · ");return t.jsxs("div",{className:"border-t border-line","data-testid":"backlog-epic-section","data-epic-id":e.epicId??"",children:[t.jsxs("button",{type:"button",onClick:()=>a(l=>!l),className:"w-full flex items-center gap-2.5 px-[18px] py-2.5 bg-bg-elev/60 hover:bg-bg-elev text-left","aria-expanded":n,title:e.label,children:[t.jsx("span",{className:`text-fg-faint inline-flex shrink-0 transition-transform duration-150 ${n?"rotate-90":""}`,"aria-hidden":"true",children:t.jsx(nt,{name:"chevron",size:12})}),t.jsx("span",{className:"font-serif text-[14.5px] font-semibold text-fg truncate","data-testid":"backlog-epic-label",children:e.label}),t.jsxs("span",{className:"font-mono text-[11px] text-fg-faint shrink-0",children:[e.total," PRD",e.total===1?"":"s"]}),t.jsx("span",{className:"font-mono text-[11px] text-fg-faint truncate",children:c})]}),n&&s]})}const ta=[],sa=[],na={depth:0,blockers:ta,blocked:!1,hasNeedsReviewBlocker:!1,hasMissingDep:!1,cycle:!1,parallelEligible:!1};function aa(e){return e.missing?`${e.slug} (missing)`:e.needsReview?`${e.slug} (needs review)`:`${e.slug} (${(e.status??"unknown").replace(/_/g," ")})`}function ra(e){return e.missing?"text-accent":e.needsReview?"text-butter font-semibold":e.status==="completed"?"text-sage":"text-amber-400/90"}function ia({job:e,eta:s,elapsedMs:n,avgDurationMs:a,listIndex:c,onFocused:l,hold:i,backlog:r=na,headChoices:d=sa}){const[o,p]=f.useState(!1),[u,h]=f.useState(!1),g=pe(P=>P.sessions),x=f.useMemo(()=>Pe(e,g),[e,g]),w=x.known&&x.epicId?g[x.epicId]:null,j=f.useCallback(P=>{at(P),window.dispatchEvent(new CustomEvent("sm:navigate",{detail:"terminal"}))},[]),D=e.status==="running",k=e.status==="failed";let E=null;D&&n!==null?E=`${Te(n)} elapsed`:e.status==="completed"&&e.startedAt&&e.finishedAt?E=`took ${Ce(Date.parse(e.finishedAt)-Date.parse(e.startedAt))}`:s&&(E=s);const m=e.error??null,T=k&&m?m.split(`
4
4
  `)[0]:e.status==="needs_review"&&e.verifierVerdict?$e(e.verifierVerdict):null,$=D&&n!==null?Math.min(.99,n/a):0;return t.jsxs("div",{role:"listitem",className:"border-t border-line",children:[t.jsxs("button",{type:"button","data-job-row":!0,"data-job-status":e.status,"data-job-index":c,"data-depth":r.depth,onClick:()=>p(P=>!P),onFocus:()=>l(c),style:r.depth>0?{paddingLeft:18+r.depth*20}:void 0,className:`w-full text-left grid grid-cols-[116px_1fr_auto_auto] items-center gap-4 px-[18px] py-3.5 hover:bg-bg/40 focus:outline-none focus:ring-1 focus:ring-accent focus:ring-inset ${o?"bg-bg-elev/40":""}`,"aria-expanded":o,"aria-label":`${ie(e.slug)?`PRD ${ie(e.slug)}, `:""}${e.title}, ${e.status}${E?`, ${E}`:""}`,title:e.title,children:[t.jsx(_t,{status:e.status}),t.jsxs("div",{className:"min-w-0",children:[t.jsxs("div",{className:"flex items-baseline gap-2 text-[14.5px] font-medium text-fg leading-snug",children:[ie(e.slug)&&t.jsx(Ot,{n:ie(e.slug)}),e.title,t.jsx(Lt,{leaked:e.leakedDescendants}),t.jsx(ks,{count:e.leftoverCount,truncated:e.leftoverPathsTruncated,salvagePatch:e.salvagePatch}),r.parallelEligible&&t.jsx("span",{"data-testid":"job-row-parallel-eligible",title:"No dependsOn, and nothing in this Epic depends on it — can run any time a slot is free",className:"text-[10px] font-semibold uppercase tracking-wide text-sage/90 bg-sage/10 border border-sage/30 rounded px-1.5 py-0.5",children:"parallel"})]}),r.cycle&&t.jsxs("div",{className:"text-[12.5px] mt-0.5 text-accent font-mono","data-testid":"job-row-cycle-warning",children:["⚠ dependsOn cycle — ",r.blockers.map(P=>P.slug).join(" ↔ ")||"self-referencing"]}),!r.cycle&&r.blockers.length>0&&t.jsxs("div",{className:"text-[12.5px] mt-0.5 font-mono","data-testid":"job-row-blockers",children:[t.jsx("span",{className:r.blocked||r.hasMissingDep?"text-amber-400/90":"text-fg-faint",children:r.blocked||r.hasMissingDep?"blocked by ":"depends on "}),r.blockers.map((P,O)=>t.jsxs("span",{className:ra(P),children:[O>0&&", ",aa(P)]},P.slug))]}),T&&t.jsx("div",{className:`text-[12.5px] mt-0.5 ${k?"text-accent/80":"text-fg-faint"}`,children:T}),i&&t.jsx("div",{className:"text-[12.5px] mt-0.5 text-amber-400/90 font-mono","data-testid":"job-row-hold",children:i.dep?t.jsxs(t.Fragment,{children:["held · waiting on ",i.dep," (",i.depStatus,")"]}):t.jsxs(t.Fragment,{children:["held · ",i.reason??"launch blocked"]})}),!i&&e.status==="pending"&&e.heldReason&&t.jsxs("div",{className:"text-[12.5px] mt-0.5 text-amber-400/90 font-mono","data-testid":"job-row-held-reason",children:["held · ",e.heldReason]}),t.jsx(rt,{epicId:x.epicId,label:x.label?zt(x.label):null,onOpen:j,testId:"job-row-prompt-session-chip",className:"mt-0.5"})]}),t.jsx(it,{cwd:e.cwd}),t.jsxs("span",{className:"inline-flex items-center gap-2.5 font-mono text-xs text-fg-faint shrink-0",children:[t.jsx(Ss,{status:e.status,overrun:e.overrun}),E,t.jsx("span",{className:`text-fg-faint inline-flex transition-transform duration-150 ${o?"rotate-90":""}`,"aria-hidden":"true",children:t.jsx(nt,{name:"chevron",size:14})})]})]}),D&&!o&&t.jsx("div",{className:"h-1 bg-line mx-[18px] mb-3 rounded-full overflow-hidden",children:t.jsx("div",{className:"h-full bg-accent transition-all duration-1000",style:{width:`${Math.max(4,$*100)}%`}})}),o&&t.jsxs("div",{className:"px-[18px] py-5 grid grid-cols-[repeat(auto-fit,minmax(160px,1fr))] gap-5 bg-bg-elev/50 border-t border-line",children:[t.jsxs(re,{label:"Status",children:[t.jsx(H,{k:"result",v:e.exitCode!==null?`exit ${e.exitCode}`:"—"}),t.jsx(H,{k:"state",v:e.status.replace(/_/g," ")}),e.verifierVerdict&&t.jsx(H,{k:"verdict",v:$e(e.verifierVerdict)}),e.leakedDescendants&&e.leakedDescendants.length>0&&t.jsx(H,{k:"leaked",v:Ft(e.leakedDescendants),wrap:!0}),e.leftoverCount!=null&&e.leftoverCount>0&&t.jsx(H,{k:"uncommitted",v:`${e.leftoverCount} file${e.leftoverCount===1?"":"s"}${e.leftoverPathsTruncated?"+":""}: ${(e.leftoverPaths??[]).join(", ")}${e.salvagePatch?` — salvaged to ${e.salvagePatch}`:""}`,wrap:!0}),m&&t.jsx(H,{k:"error",v:m.split(`
@@ -1 +1 @@
1
- import{ap as i,S as d}from"./index-t37UuEZu.js";function a({scopes:l,active:n,onChange:o,annotate:s}){return i.jsx("div",{className:"inline-flex rounded border border-line overflow-hidden",children:l.map(t=>{const r=d[t],e=s==null?void 0:s(t),c=t===n;return i.jsxs("button",{title:r.hint,onClick:()=>o(t),className:`px-2.5 py-1 text-xs flex items-center gap-1.5 transition-colors ${c?"bg-bg-hi text-fg":"bg-bg-elev text-fg-dim hover:text-fg hover:bg-bg-hi"}`,children:[i.jsx("span",{children:r.label}),(e==null?void 0:e.dirty)&&i.jsx("span",{className:"w-1 h-1 rounded-full bg-accent",title:"unsaved edits"}),e&&e.exists===!1&&!e.dirty&&i.jsx("span",{className:"w-1 h-1 rounded-full bg-fg-faint",title:"not yet created"})]},t)})})}export{a as S};
1
+ import{ao as i,S as d}from"./index-DQSEUdx0.js";function a({scopes:l,active:n,onChange:o,annotate:s}){return i.jsx("div",{className:"inline-flex rounded border border-line overflow-hidden",children:l.map(t=>{const r=d[t],e=s==null?void 0:s(t),c=t===n;return i.jsxs("button",{title:r.hint,onClick:()=>o(t),className:`px-2.5 py-1 text-xs flex items-center gap-1.5 transition-colors ${c?"bg-bg-hi text-fg":"bg-bg-elev text-fg-dim hover:text-fg hover:bg-bg-hi"}`,children:[i.jsx("span",{children:r.label}),(e==null?void 0:e.dirty)&&i.jsx("span",{className:"w-1 h-1 rounded-full bg-accent",title:"unsaved edits"}),e&&e.exists===!1&&!e.dirty&&i.jsx("span",{className:"w-1 h-1 rounded-full bg-fg-faint",title:"not yet created"})]},t)})})}export{a as S};