claude-code-session-manager 0.129.0 → 0.130.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +1 -1
- package/dist/assets/AgentLibrary-ctvNes4y.js +2 -0
- package/dist/assets/AppSettings-C03qTDSi.js +2 -0
- package/dist/assets/Button-fOCJry21.js +1 -0
- package/dist/assets/Extensions-BWiDwigT.js +13 -0
- package/dist/assets/{History-B2x-LMlT.js → History-BIQFPXM8.js} +2 -2
- package/dist/assets/Library-BGmD-xZN.js +32 -0
- package/dist/assets/ListDetail-BeO3lY8t.js +1 -0
- package/dist/assets/{Memory-CnalwnFf.js → Memory-BeXuYIcE.js} +8 -8
- package/dist/assets/{Panel-BzIklgKf.js → Panel-OUbLHNsS.js} +1 -1
- package/dist/assets/ProvenanceBadge-kr7arZqu.js +1 -0
- package/dist/assets/Scheduler-DycegnjH.js +16 -0
- package/dist/assets/Settings-BSq6VASG.js +2 -0
- package/dist/assets/{SkillReferenceGraph-DOhiCxuL.js → SkillReferenceGraph-CvPdxg56.js} +1 -1
- package/dist/assets/SourceChip-C2YMnlV8.js +1 -0
- package/dist/assets/SystemPrompt-fpXEK_Rm.js +1 -0
- package/dist/assets/{TiptapBody-Du6jRBoW.js → TiptapBody-DusJg0je.js} +1 -1
- package/dist/assets/{Toggle-Qdi2Z7VD.js → Toggle-BnJF4V6k.js} +1 -1
- package/dist/assets/ViewTabs-BYrRSHb6.js +1 -0
- package/dist/assets/VoiceButton-Bk66E-fP.js +1 -0
- package/dist/assets/{historyTotals-8ecP_6wF.js → historyTotals-DnuVADtI.js} +1 -1
- package/dist/assets/{index-DtdWBGrI.css → index-Bp8XE9A6.css} +1 -1
- package/dist/assets/index-DfWJO7nP.js +3086 -0
- package/dist/index.html +2 -2
- package/dist-web/app.css +1 -1
- package/dist-web/app.js +390 -406
- package/package.json +1 -1
- package/plugins/CLAUDE.md +2 -2
- package/plugins/session-manager-dev/.claude-plugin/plugin.json +2 -2
- package/plugins/session-manager-dev/skills/builder/4-manual/SKILL.md +2 -2
- package/plugins/session-manager-dev/skills/develop/SKILL.md +3 -3
- package/plugins/session-manager-dev/skills/maintaining-md-network/SKILL.md +62 -0
- package/plugins/session-manager-dev/skills/maintaining-md-network/audit.md +169 -0
- package/plugins/session-manager-dev/skills/maintaining-md-network/drift-check.md +183 -0
- package/plugins/session-manager-dev/skills/maintaining-md-network/placement.md +39 -0
- package/plugins/session-manager-dev/skills/maintaining-md-network/plan.md +79 -0
- package/plugins/session-manager-dev/skills/maintaining-md-network/scripts/drift-check.cjs +400 -0
- package/scripts/scheduler-mcp-server.cjs +25 -6
- package/src/main/agentLibrary.cjs +36 -10
- package/src/main/build-info.json +4 -4
- package/src/main/config.cjs +15 -0
- package/src/main/health.cjs +49 -22
- package/src/main/index.cjs +19 -3
- package/src/main/ipcSchemas.cjs +36 -3
- package/src/main/lib/claude/modelCatalog.cjs +15 -31
- package/src/main/lib/claudeConfig.cjs +156 -0
- package/src/main/lib/effectiveSettings.cjs +120 -0
- package/src/main/lib/epic/delegationReadiness.cjs +3 -3
- package/src/main/lib/feedback-remote/macroAdminRoutes.cjs +84 -11
- package/src/main/lib/git/gitWorktree.cjs +400 -9
- package/src/main/lib/git/runtimeStateUntrack.cjs +124 -0
- package/src/main/lib/mcpToolCatalog.cjs +8 -2
- package/src/main/lib/memoryDirResolve.cjs +2 -8
- package/src/main/lib/opsOwnership.cjs +63 -2
- package/src/main/lib/persona-macro/builtinMacros.cjs +30 -0
- package/src/main/lib/persona-macro/macroLibrary.cjs +34 -6
- package/src/main/lib/persona-macro/shippedPersonaSeeds.cjs +22 -0
- package/src/main/lib/updateCheck.cjs +6 -1
- package/src/main/pluginInstall.cjs +100 -1
- package/src/main/scheduler.cjs +12 -2
- package/src/main/seedDevPlugin.cjs +2 -1
- package/src/main/templates/PRD_AUTHORING.md +3 -3
- package/src/main/updaterIpc.cjs +5 -1
- package/src/main/usage.cjs +5 -20
- package/src/main/voiceHotkey.cjs +16 -0
- package/src/main/voiceSettings.cjs +24 -0
- package/src/main/voiceWizard.cjs +27 -36
- package/src/preload/api.d.ts +53 -2
- package/src/preload/apiSurface.json +63 -7
- package/src/preload/index.cjs +12 -1
- package/src/seed/agents/demo-video-builder.md +2 -2
- package/src/seed/agents/validator.md +2 -2
- package/dist/assets/AgentLibrary-Cp250YHF.js +0 -2
- package/dist/assets/Button-DU5UF-6L.js +0 -1
- package/dist/assets/DataModel-CPf6f17e.js +0 -1
- package/dist/assets/Hooks-BWr33C4Q.js +0 -3
- package/dist/assets/Library-DBNLTAa8.js +0 -46
- package/dist/assets/ListDetail-BGBw6egp.js +0 -1
- package/dist/assets/McpServers-DywZ50Ec.js +0 -2
- package/dist/assets/Permissions-mgRifwQc.js +0 -3
- package/dist/assets/Plugins-CV42zfid.js +0 -2
- package/dist/assets/ProvenanceBadge-DYmX4xgB.js +0 -1
- package/dist/assets/SaveBar-DxrAfnlC.js +0 -1
- package/dist/assets/Scheduler-iyUl1NDl.js +0 -16
- package/dist/assets/ScopeSwitcher-CC8BDPgf.js +0 -1
- package/dist/assets/Settings-CWBnQghD.js +0 -4
- package/dist/assets/Skills-3Er-9YA9.js +0 -2
- package/dist/assets/SystemPrompt-BLxdvZ9K.js +0 -1
- package/dist/assets/TagLibrary-BZ6QHYMQ.js +0 -1
- package/dist/assets/ViewTabs-BKfFsziD.js +0 -1
- package/dist/assets/index-GI6F_j41.js +0 -3083
- package/dist/assets/listSkills-C1aWKf0T.js +0 -1
- package/dist/assets/settingsSchema-lHTHAabD.js +0 -1
- package/dist/assets/skillFrontmatter-8X1Uc282.js +0 -10
- package/dist/assets/useAgentsDirWatch-CcsoD1bp.js +0 -1
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import{aP as Pe,aC as ie,ai as Te,aW as xs,an as Ce,ah as ue,al as te,a$ as H,bg as Fe,bf as pe,bj as Tt,aJ as f,af as xe,bp as ms,at as t,c as Ue,I as me,L as bt,p as bs,K as ge,u as ws,U as vs,e as js,W as ys,aV as Ns,bd as st,b6 as ks,ac as wt,aA as _t,bo as $e,N as qe,aH as _e,a as nt,aU as at,T as Ot,x as Lt,o as Ft,q as Ss,m as rt,z as it,O as Cs,g as re,h as B,aj as qt,bh as $s,aI as Ps,w as Ds,aL as Bt,bs as Ht,Y as As,aD as vt,b7 as jt,l as ke,y as yt,aQ as Nt,k as Rs,aZ as Ms,a3 as Is,v as Gt,b9 as Es,b3 as ye,Q as Ts,C as _s,au as Os,bb as Ls,V as Fs,bk as kt,aT as qs}from"./index-DfWJO7nP.js";import{f as Bs,a as Hs,s as Gs}from"./historyTotals-DnuVADtI.js";import"./monaco-editor-BsIlgG7c.js";function Vs(e){const s=new Map(e.map(i=>[i.slug,i])),n=new Map,a=new Set,d=[];function l(i){n.set(i,1),d.push(i);const r=s.get(i);for(const o of(r==null?void 0:r.dependsOn)??[]){if(!s.has(o))continue;const c=n.get(o);if(c===1){const p=d.indexOf(o);for(let u=p;u<d.length;u++)a.add(d[u])}else c===void 0&&l(o)}d.pop(),n.set(i,2)}for(const i of e)n.has(i.slug)||l(i.slug);return a}function Ws(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 Us(e,s,n){const a=new Set(e.map(c=>c.slug)),d=new Set;for(const c of e)for(const p of c.dependsOn??[])a.has(p)&&d.add(p);const l=new Map,i=[];for(const c of e){const p=n.has(c.slug)?void 0:(c.dependsOn??[]).find(u=>a.has(u)&&!n.has(u));p?(l.has(p)||l.set(p,[]),l.get(p).push(c)):i.push(c)}const r=(c,p)=>c.slug.localeCompare(p.slug);i.sort(r);for(const c of l.values())c.sort(r);function o(c,p,u){const h=Ws(c,s),g=n.has(c.slug);u.add(c.slug);const m=g?[]:(l.get(c.slug)??[]).filter(v=>!u.has(v.slug)).map(v=>o(v,p+1,u));return u.delete(c.slug),{row:c,depth:p,children:m,blockers:h,blocked:h.some(v=>!v.missing&&v.status!=="completed"),hasNeedsReviewBlocker:h.some(v=>v.needsReview),hasMissingDep:h.some(v=>v.missing),cycle:g,parallelEligible:(c.dependsOn??[]).length===0&&!d.has(c.slug)}}return i.map(c=>o(c,0,new Set))}function Vt(e,s,n){const a=new Map((n??e).map(c=>[c.slug,c])),d=Vs(e),l=[],i=new Map,r=new Map;for(const c of e){const p=Pe(c,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(c)}const o=l.map(c=>{const p=r.get(c),u=i.get(c),h=Us(u,a,d),g={};for(const m of u){const v=m.status??"unknown";g[v]=(g[v]??0)+1}return{epicId:p.epicId,label:p.label,known:p.known,nodes:h,counts:g,total:u.length}});return o.sort((c,p)=>c.epicId===null?1:p.epicId===null?-1:c.known!==p.known?c.known?-1:1:c.label.localeCompare(p.label)),o}function Be(e){const s=[],n=a=>{s.push(a);for(const d of a.children)n(d)};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 d=Ke(a.slug),l=n.get(d);l?l.push(a.slug):n.set(d,[a.slug])}return e.map(a=>{const d=a.dependsOn;if(!d||d.length===0)return a;let l=!1;const i=d.map(r=>{if(s.has(r))return r;const o=n.get(Ke(r));return o&&o.length===1?(l=!0,o[0]):r});return l?{...a,dependsOn:i}:a})}const zs=15e4,Xe=e=>e==="completed"||e==="skipped",Se=e=>e==="running"||e==="investigating",Wt=e=>e==="failed"||e==="needs_review"||e==="quarantined",Qs=e=>e==="failed"||e==="needs_review"||e==="quarantined";function Ut(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 zt(e,s){const n=e.estimateMinutes?e.estimateMinutes*6e4:null;return n?`${Math.min(99,Math.floor(s/n*100))}%`:Te(s)}function Ys(e){let s=0,n=0;for(const a of e)if(a.status==="completed"&&a.startedAt&&a.finishedAt){const d=Date.parse(a.finishedAt)-Date.parse(a.startedAt);d>0&&(s+=d,n++)}return n===0?zs: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 Js(e){let s=0;for(const n of e.statusHistory??[])n.to==="pending"&&n.from!==null&&s++;return s}function Ks(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 Xs(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 Zs(e,s){return e._firstNum!==s._firstNum?e._firstNum<s._firstNum?-1:1:e._firstSlug.localeCompare(s._firstSlug)}function en(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 d=new Map;for(const l of e){const i=a(l.row.slug),r=d.get(i);r?r.push(l):d.set(i,[l])}return[...d.values()]}function tn(e,s){if(e.length>0&&e.every(n=>!!n.row.planId)){const n=new Map;for(const a of e){const d=n.get(a.row.planId);d?d.push(a):n.set(a.row.planId,[a])}return[...n.values()]}return en(e,s)}function sn(e,s,n,a){const d=[],l=[e];for(a.add(e.row.slug);l.length>0;){const i=l.pop();d.push(i);for(const r of i.row.dependsOn??[])if(n.has(r)&&!a.has(r)){a.add(r);const o=s.get(r);o&&l.push(o)}}return d}function nn(e,s){const n=new Map(e.map(r=>[r.row.slug,r])),a=new Set,d=[],l=e.filter(r=>Ke(r.row.slug).startsWith("validate-")).sort((r,o)=>Ze({slug:r.row.slug},{slug:o.row.slug}));for(const r of l)a.has(r.row.slug)||d.push({nodes:sn(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(o=>o.row.slug));for(const o of tn(i,r))d.push({nodes:o,validateSlug:null})}return d}function an(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(),d=s.avgDurationMs??Ys(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"),o=new Map;n.filter(r).sort(Ze).forEach((u,h)=>o.set(u.slug,h));const c=Vt(n,s.sessions,n),p=[];for(const u of c){const h=Be(u.nodes),g=new Set(h.map(k=>k.row.slug)),m=new Map(h.map(k=>[k.row.slug,k])),v=[];for(const k of nn(h,g)){const S=k.nodes,T=new Set(S.map(N=>N.row.slug)),x=new Map,R=new Set,P=N=>{const C=m.get(N);return(C.row.dependsOn??[]).filter(q=>T.has(q)&&!(C.cycle&&m.get(q).cycle))},D=N=>{const C=x.get(N);if(C!==void 0)return C;if(R.has(N))return 0;R.add(N);let q=0;for(const V of P(N))q=Math.max(q,D(V));return R.delete(N),x.set(N,q+1),q+1};for(const N of S)D(N.row.slug);const O=S.map(N=>{const C=N.row,q=(C.dependsOn??[]).filter(V=>g.has(V));return{slug:C.slug,title:C.title,status:C.status,stage:x.get(C.slug),prdNumber:ie(C.slug),rowKind:"dep",rowTrailing:"",cycle:N.cycle,estimateMinutes:C.estimateMinutes??null,deps:q,crossEpicDeps:(C.dependsOn??[]).filter(V=>!g.has(V)),blockers:N.blockers,job:C}});O.sort(Ze);const J=O.reduce((N,C)=>Math.max(N,C.stage),0),W=new Map;for(const N of O){const C=N.job,q=m.get(N.slug),V=C.status;let U;if(Xe(V)){const b=C.startedAt&&C.finishedAt?Date.parse(C.finishedAt)-Date.parse(C.startedAt):NaN;U={kind:"done",trailing:b>0?Te(b):"",held:!1,blocked:!1}}else if(Se(V)){const b=C.startedAt?Math.max(0,a-Date.parse(C.startedAt)):null;U={kind:"running",trailing:b===null?"":zt(C,b),held:!1,blocked:!1}}else if(V==="failed")U={kind:"failed",trailing:"failed",held:!1,blocked:!1};else if(V==="needs_review")U={kind:"review",trailing:"review",held:!1,blocked:!1};else if(V==="quarantined")U={kind:"quarantined",trailing:"quarantined",held:!1,blocked:!1};else{const b=q.blockers.filter(j=>!j.missing&&j.status!=="completed");if(b.length>0){const j=b.some($=>Qs($.status)),A=b[0].slug;U={kind:"dep",trailing:`←${ie(A)??A}`,held:!j,blocked:j}}else if(C.heldReason)U={kind:"gate",trailing:"gate",held:!0,blocked:!1};else{const j=Js(C),A=o.get(C.slug)??0;U=j>0?{kind:"retry",trailing:`${j} ${j===1?"retry":"retries"}`,held:!1,blocked:!1}:{kind:"eta",trailing:Ut(A*d/l),held:!1,blocked:!1}}}W.set(N.slug,U)}const z=[];for(let N=1;N<=J;N++){const C=O.filter(_=>_.stage===N),q=C.find(_=>{const Z=W.get(_.slug).kind;return _.status==="pending"&&(Z==="eta"||Z==="retry")});if(q){const _=W.get(q.slug);_.kind="next",_.trailing="next"}let V=0,U=0,b=0,j=0,A=0,$=0;for(const _ of C){const Z=W.get(_.slug);_.rowKind=Z.kind,_.rowTrailing=Z.trailing,Xe(_.status)?V++:Se(_.status)?U++:_.status==="pending"?(A++,Z.held&&b++,Z.blocked&&j++):Wt(_.status)&&$++}const I=V===C.length?"done":U>0?"running":j+$>0?"blocked":b>0?"held":"pending",L={n:N,rows:C,doneCount:V,runningCount:U,heldCount:b,blockedCount:j};z.push({...L,state:I,summary:Xs(I,L,A,$)})}let K=0;for(const N of O){const C=N.estimateMinutes?N.estimateMinutes*6e4:d;if(N.status==="pending")K+=C;else if(Se(N.status)){const q=N.job.startedAt?Math.max(0,a-Date.parse(N.job.startedAt)):0;K+=Math.max(0,C-q)}}const X=O.reduce((N,C)=>Math.min(N,Le(C.slug)),1/0),se=O.reduce((N,C)=>Math.max(N,Le(C.slug)),-1/0),Y=u.known?xs(u.label).title:u.label,M=k.validateSlug?O.find(N=>N.slug===k.validateSlug):void 0,F=M&&an(M.title)||Y;v.push({epicId:u.epicId,waveIndex:0,index:0,label:F,epicLabel:Y,validateSlug:k.validateSlug,width:z.reduce((N,C)=>Math.max(N,C.rows.length),0),status:Ks(O),prdCount:O.length,stageCount:J,doneCount:z.reduce((N,C)=>N+C.doneCount,0),runningCount:z.reduce((N,C)=>N+C.runningCount,0),heldCount:z.reduce((N,C)=>N+C.heldCount,0),blockedCount:z.reduce((N,C)=>N+C.blockedCount,0),etaMs:K/l,stages:z,_firstNum:X,_lastNum:se,_firstSlug:O[0].slug})}v.sort(Zs),v.forEach((k,S)=>{k.waveIndex=S+1});const y=v.filter(k=>k.validateSlug===null);y.forEach((k,S)=>{y.length>1&&(k.label=`${k.label} · plan ${S+1}/${y.length}`)});for(const k of v)p.push(k)}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,...m},v)=>({...m,index:v+1}))}function rn(e,s=Date.now()){const n=Oe(e),a=new Map(n.map(g=>[g.slug,g])),d=new Date(s).toDateString();let l=0,i=0,r=0,o=0,c=0,p=0,u=0;for(const g of n)g.status==="pending"?(i++,(g.dependsOn??[]).every(v=>a.get(v)===void 0||a.get(v).status==="completed")&&l++):Se(g.status)?u++:g.status==="failed"?r++:g.status==="needs_review"?o++:g.status==="quarantined"?c++:g.status==="completed"&&g.finishedAt&&new Date(Date.parse(g.finishedAt)).toDateString()===d&&p++;let h=null;if(r+o+c>0){for(const g of lt(n,{sessions:{},now:s}))for(const m of g.stages)if(m.rows.some(v=>Wt(v.status))){(h===null||m.n<h)&&(h=m.n);break}}return{readyNow:l,totalQueued:i,heldByDeps:i-l,needsYou:r+o+c,needsYouStage:h,failedCount:r,needsReviewCount:o,doneToday:p,inFlight:u}}function ln(e){const s=new Map;for(const o of e.stages)for(const c of o.rows)s.set(c.slug,c);const n=o=>{var c;return((c=s.get(o))==null?void 0:c.cycle)===!0},a=new Map,d=new Set,l=(o,c)=>o.chain.length!==c.chain.length?o.chain.length>c.chain.length:o.est!==c.est?o.est>c.est:o.chain.join("\0")<c.chain.join("\0"),i=o=>{const c=a.get(o);if(c)return c;const p=s.get(o),u=p.estimateMinutes??0;if(d.has(o))return{chain:[o],est:u};d.add(o);let h=null;for(const m of p.deps){if(!s.has(m)||p.cycle&&n(m))continue;const v=i(m);(!h||l(v,h))&&(h=v)}d.delete(o);const g=h?{chain:[...h.chain,o],est:h.est+u}:{chain:[o],est:u};return a.set(o,g),g};let r=null;for(const o of s.keys()){const c=i(o);(!r||l(c,r))&&(r=c)}return r?r.chain:[]}const on=300*6e4,dn={five_hour:"5-hour",session:"5-hour",weekly_all:"weekly",weekly:"weekly"};function cn(e){return dn[e]??e.replace(/_/g," ")}function Qt({snap:e,now:s,avgDurationMs:n,runningJobs:a}){const{config:d,jobs:l,paused:i,nextReset:r,utilization:o,utilizationWindow:c,effectiveConcurrency:p}=e;let u=0,h=0;for(const S of l)S.status==="pending"?u++:S.status==="completed"&&h++;const g=a.length,m=u+g,v=(p==null?void 0:p.cap)??5;if(g>0){const S=a.reduce((D,O)=>(D.startedAt??"")<(O.startedAt??"")?D:O),T=S.startedAt?s-Date.parse(S.startedAt):0,x=h+g,R=h+m,P=g>1?` · ${g}/${v} parallel`:"";return{kind:"running",line1:`Running ${x}/${R}${P} · ${Ce(T)}`,line2:g===1?S.title:a.map(D=>D.title).join(", "),tooltip:a.map(D=>`${D.slug} (g${D.parallelGroup})`).join("; ")}}if(i){const S=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":S!==null&&S>0?`auto-resume ${ue(Date.parse(i.resumeAt))} (in ${te(S)})`: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(m===0)return{kind:"idle",line1:"No work queued",line2:null};if((d.firePolicy??"when-available")==="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(H.fromOutcome).catch(()=>H.error("Failed to fire batch")),title:"Bypasses the billing-usage poll. Use when the meter is rate-limited or you want immediate progress."}};const k=d.utilizationThreshold??90;if(o==null)return{kind:"auto-soon",line1:`Auto · ${u} pending`,line2:"checking token availability…"};if(o>=k){const S=r?Date.parse(r)-s:null,T=c?cn(c):null,x=S===null||Number.isNaN(S)||S>on,R=S&&S>0?`resets ${ue(Date.parse(r))} (in ${te(S)})`:null;let P;return x?P=`${T??"binding"} window — long hold${R?`, ${R}`:", reset time unknown"}`:P=R?`${T?`${T} window `:""}next ${R}`:"will fire when usage drops",{kind:"auto-throttled",line1:`Auto · throttled (util ${o.toFixed(0)}% ≥ ${k}%)`,line2:P}}return{kind:"auto-soon",line1:`Auto · ${u} pending · util ${o.toFixed(0)}%`,line2:"fires within 2 min (poll cycle)"}}const un=15e3,pn=new Set(["failed","needs_review","quarantined"]);function St(){var n;const s=Array.from(document.querySelectorAll("[data-job-row]")).find(a=>pn.has(a.dataset.jobStatus??""));(n=s==null?void 0:s.scrollIntoView)==null||n.call(s,{block:"center",behavior:"smooth"})}function fn(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 ${te(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?te(e.idleMs):"?"} with ${e.dispatchable} dispatchable`;case"running":default:return`running: ${e.runningCount} in flight, ${e.pending} pending`}}function hn(e){const[s,n]=f.useState(null),a=st(),d=ks(),l=a&&d;return f.useEffect(()=>{if(!l)return;let i=!0,r=!1,o=!1;const c=()=>{r||(r=!0,window.api.schedule.queueHealth(e).then(u=>{r=!1,o=!1,i&&n(u)},u=>{r=!1,!o&&(o=!0,H.error(`Queue health refresh failed: ${u instanceof Error?u.message:String(u)}`))}))};c();const p=setInterval(c,un);return()=>{i=!1,clearInterval(p)}},[e,l]),s}const gn={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 xn(e,s,n){return e==="paused"||e==="launch-blocked"?"paused":e==="running"||e==="saturated"?"running":e?"idle":s?"paused":n>0?"running":"idle"}const ze="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 mn(e,s,n,a){var d;if(e==="agent"){const l=((d=a==null?void 0:a.cwd)==null?void 0:d.split("/").filter(Boolean).pop())||"another session",i=a!=null&&a.reason?` — "${a.reason}"`:"",r=s?new Date(s).getTime()-n:null,o=r==null?"":r>0?` — auto-resumes in ${te(r)}`:" — auto-resume pending";return`Paused by an agent in ${l}${i}${o}. 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 ${te(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 bn({now:e}){const s=Fe(p=>p.snapshot);if(!s)return null;const n=s.paused,a=Object.entries(s.launchBlocks??{}),d=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",o="bg-amber-400/10 border-amber-600/30 text-amber-700",c="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:o}`,children:[t.jsx("span",{className:"flex-1 leading-snug",children:mn(n.reason,n.resumeAt,e,n.by)}),t.jsx("button",{type:"button",onClick:()=>window.api.schedule.resume(),className:c,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 ${te(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:c,children:"Retry now"})]},`launch-block-${p}`)),d.map(([p,u])=>t.jsx("div",{"data-testid":"launch-mitigation-banner",className:`${i} ${o}`,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 wn({scopeCwd:e,subView:s,onSubView:n,filterText:a,onFilterText:d,planMode:l,onPlanMode:i,planToolsRef:r}){const o=Fe($=>$.snapshot),c=pe($=>$.sessions),p=hn(e),u=Tt(),[h,g]=f.useState(()=>Date.now()),[m,v]=f.useState("—");f.useEffect(()=>{const $=setInterval(()=>g(Date.now()),3e4);return()=>clearInterval($)},[]),f.useEffect(()=>{let $=!0;return Bs(30).then(I=>{if(!$||!I.ok||!I.data)return;const L=new Date,_=He=>String(He).padStart(2,"0"),Z=`${L.getFullYear()}-${_(L.getMonth()+1)}-${_(L.getDate())}`;v(Hs(Gs(I.data,{day:Z})))}),()=>{$=!1}},[]);const y=f.useMemo(()=>((o==null?void 0:o.jobs)??[]).filter($=>!e||$.cwd===e),[o,e]),k=f.useMemo(()=>rn(y,h),[y,h]),S=f.useMemo(()=>{const $=lt(y,{sessions:c,now:h}),I=L=>$.filter(_=>_.status===L).length;return{active:I("active"),queued:I("queued"),draft:I("draft")}},[y,c,h]),T=f.useMemo(()=>{const $=new Date(h).toDateString(),I=[];for(const L of y)if(L.status==="completed"&&L.startedAt&&L.finishedAt&&new Date(Date.parse(L.finishedAt)).toDateString()===$){const _=Date.parse(L.finishedAt)-Date.parse(L.startedAt);_>0&&I.push(_)}return I.length?Math.round(I.reduce((L,_)=>L+_,0)/I.length/6e4):null},[y,h]);if(!o)return null;const x=p&&!p.unknown?p.verdict??null:null,R=p&&!p.unknown?p.slots??null:null,P=o.paused,D=xn((x==null?void 0:x.kind)??null,!!P,k.inFlight),O=gn[D],J=y.filter($=>$.status==="pending").length,W=y.filter($=>$.status==="running").length,z=Qt({snap:{...o,jobs:y},now:h,avgDurationMs:0,runningJobs:y.filter($=>$.status==="running")}),K=p!=null&&p.unknown?`Queue health: unknown — ${p.reason??"state unavailable"}`:x?fn(x,(p==null?void 0:p.oldestRunningAgeMs)??null):"queue health loading…",X=xe(o.lastRunAt?Date.parse(o.lastRunAt):null,h),se=p!=null&&p.lastDispatchAttemptAt?xe(Date.parse(p.lastDispatchAttemptAt),h):"never",Y=[K,z.line1,x?`dispatchable ${x.dispatchable} · needs_review ${x.needsReviewCount}`:null,(p==null?void 0:p.oldestRunningAgeMs)!=null?`oldest running ${te(p.oldestRunningAgeMs)} (any project)`:null,`last batch fired ${X} (lastRunAt — advances only when a job launches)`,`last dispatch attempt ${se} (advances on every driver evaluation)`].filter(Boolean).join(`
|
|
2
|
+
`),M=o.utilization,F=o.pollHealth,N=F!=null&&!F.lastPollOk,C=ms(o.utilizationWindow),q=o.nextReset?Date.parse(o.nextReset):null,V=q?q>h?te(q-h):"soon":"—",U=(u==null?void 0:u.total)??5,b=(u==null?void 0:u.envOverride)===!0,j=o.config.firePolicy??"when-available",A=J===0&&W===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 ${O.text}`,"data-testid":"scheduler-state-word","data-state":D,children:[t.jsx("span",{className:`w-2 h-2 rounded-full ${O.dot}`,"aria-hidden":"true"}),D]}),t.jsxs("span",{className:"font-mono text-[12px] text-fg-faint whitespace-nowrap","data-testid":"scheduler-meta",children:[k.inFlight," in flight · ",k.heldByDeps," held · last batch ",X]}),t.jsxs(me,{title:Y,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:Y}),bt.scheduler&&t.jsx(bs,{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(H.fromOutcome).catch(()=>H.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:ze,children:"Refresh"}),P?t.jsx("button",{type:"button",onClick:()=>window.api.schedule.resume(),title:"Clear the pause and resume queue immediately",className:ze,children:"Resume"}):t.jsx("button",{type:"button",onClick:()=>window.api.schedule.pause(),title:"Stop NEW dispatch. Running jobs are not killed.",className:ze,children:"Pause"}),t.jsx("button",{type:"button",onClick:()=>window.api.schedule.forceTick().then(H.fromOutcome).catch(()=>H.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(bn,{now:h}),t.jsxs(Ue,{height:70,testId:"scheduler-kpi-band",children:[t.jsx(ge,{testId:"kpi-window",label:C?`${C} used`:"Window used",info:N?`Billing poll failing — this reading may be outdated (last good reading ${xe(F.lastPollAt,h)}). Machine-wide ${C??"binding"} window.`:`Share of the machine-wide ${C??"binding"} billing window consumed — the window closest to its limit.`,value:M==null?"—":`${Math.round(M)}%`,sub:`resets in ${V}`,third:t.jsx(ws,{pct:M??0,tone:N?"bg-amber-500":"bg-accent"})}),t.jsx(ge,{testId:"kpi-slots",label:"Slots",info:`Machine-wide session pool (${(R==null?void 0:R.source)==="env"?"SM_SESSION_SLOTS override":"Home tab cap"}), not scoped to this project`,value:R?`${R.inUse}/${R.total}`:"—",sub:"in use",third:R?t.jsx(vs,{filled:R.inUse,total:R.total}):null}),t.jsx(ge,{testId:"kpi-ready",label:"Ready now",info:"Pending rows whose dependsOn chain is fully satisfied right now",value:k.readyNow,sub:`of ${k.totalQueued} queued`,third:`${k.heldByDeps} held by deps`}),k.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:k.needsYou}),sub:t.jsx("button",{type:"button",onClick:St,className:"hover:underline",children:k.needsYouStage!=null?`blocking stage ${k.needsYouStage}`:"need attention"}),third:[k.failedCount>0&&`${k.failedCount} failed`,k.needsReviewCount>0&&`${k.needsReviewCount} needs review`,k.needsYou-k.failedCount-k.needsReviewCount>0&&`${k.needsYou-k.failedCount-k.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:k.doneToday,sub:T!=null?`avg ${T}m`:"avg —",third:t.jsx("span",{"data-testid":"kpi-done-spend",children:m})}),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:j,onChange:$=>window.api.schedule.setConfig({firePolicy:$.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. manual: only on Run now.","aria-label":"Start jobs policy",children:[t.jsx("option",{value:"when-available",children:"when available"}),t.jsx("option",{value:"manual",children:"manually"})]})]}),value:t.jsxs("span",{className:"inline-flex items-center gap-1",children:[t.jsx(ys,{value:U,min:0,max:(u==null?void 0:u.max)??10,disabled:b,onChange:$=>{Ns($).catch(I=>{H.error(`Could not set session slots: ${I instanceof Error?I.message:String(I)}`)})},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:j==="when-available"?t.jsxs("span",{children:["pause above"," ",t.jsx(js,{value:o.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:$=>window.api.schedule.setConfig({utilizationThreshold:$})})]}):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:[S.active," active · ",S.queued," queued · ",S.draft," draft · ",y.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:$=>d($.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(([$,I])=>t.jsx("button",{type:"button","data-testid":`plan-mode-${$}`,"aria-pressed":l===$&&s==="queue",onClick:()=>{i($),n("queue")},className:`px-2 py-0.5 text-[12px] ${l===$&&s==="queue"?"bg-bg-elev font-semibold text-fg":"text-fg-dim hover:text-fg"}`,children:I},$))}),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(([$,I,L])=>t.jsx("button",{type:"button",onClick:()=>n($),"aria-pressed":s===$,title:L,className:`text-[12.5px] ${s===$?"font-semibold text-fg":"text-fg-faint hover:text-fg-dim"}`,children:I},$))]})]})]})}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(d=>{const l=d.value===s;return t.jsxs("button",{type:"button",onClick:()=>n(d.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:[d.label,d.count!==void 0&&t.jsxs("span",{children:[" ",d.count]})]},d.value)})})}function Jt(e,s=60){const n=e.trim();return n.length<=s?n:`${n.slice(0,s-1)}…`}function vn(e){return Be([e]).filter(s=>s.children.length===0).map(s=>s.row.slug)}function Kt(e){return e.nodes.map(s=>({rootSlug:s.row.slug,label:s.row.title||s.row.slug,terminals:vn(s)}))}function jn(e){const s=new Map;for(const n of e){const a=Kt(n);n.nodes.forEach((d,l)=>{const i=a.filter((r,o)=>o!==l);for(const r of Be([d]))s.set(r.row.slug,i)})}return s}function Xt({job:e,headChoices:s}){const[n,a]=f.useState(!1),d=f.useCallback((l,i)=>{a(!0),window.api.schedule.setPrdDisposition({slug:e.slug,cwd:e.cwd??void 0,disposition:l,dependsOn:i}).then(H.fromOutcome).catch(()=>H.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__")d("new-head");else if(i){const r=s.find(o=>o.rootSlug===i);r&&d("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: ",Jt(l.label,40)]},l.rootSlug))]})}function yn(e,s,n=null){if(s.length===0||e.length===0)return e;const a=new Set,d=new Set;for(const i of e){a.add(i.slug);for(const r of wt(i))d.add(r)}const l=[];for(const i of s)i.archived!==!0||a.has(i.slug)||n&&i.cwd!==n||wt(i).some(r=>d.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 Nn=[],kn=new Set(["failed","needs_review","quarantined"]);function Sn(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 Cn(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 $n(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 Pn({row:e,elapsedMs:s,listIndex:n,onFocused:a,headChoices:d=Nn}){const[l,i]=f.useState(!1),r=e.job,o=s!==null&&e.rowKind==="running"?zt(r,s):e.rowTrailing,c=e.status==="completed"||e.status==="skipped",p=e.rowKind==="dep"&&e.blockers.some(h=>!h.missing&&h.status!==null&&kn.has(h.status)),u=c||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}${o?`, ${o}`:""}`,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 ${Cn(e)}`,children:[t.jsx("span",{"aria-hidden":"true",className:`shrink-0 w-[7px] h-[7px] rounded-full ${Sn(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] ${$n(e)}`,children:o})]}),l&&t.jsx(Dn,{row:e,elapsedMs:s,headChoices:d})]})}const Zt=f.memo(Pn);function Dn({row:e,elapsedMs:s,headChoices:n}){const a=e.job,[d,l]=f.useState(!1),i=pe(g=>g.sessions),r=f.useMemo(()=>Pe(a,i),[a,i]),o=r.known&&r.epicId?i[r.epicId]:null,c=f.useCallback(g=>_t(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
|
+
`)[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 ${ue(Date.parse(a.startedAt))}`,a.finishedAt&&` · finished ${ue(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:[o&&t.jsx("button",{type:"button","data-testid":"job-row-prompt-session-link",title:o.goalText,onClick:()=>c(o.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(H.fromOutcome).catch(()=>H.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(Xt,{job:a,headChoices:n})]}),d&&a.runId&&t.jsx(qe,{runId:a.runId,slug:a.slug,title:a.title||a.slug,onClose:()=>l(!1)})]})}const ce=190,An=7,Rn=5,Mn=[],es=e=>e==="completed"||e==="skipped",ts=e=>e==="running"||e==="investigating",ss=e=>e==="failed"||e==="needs_review"||e==="quarantined";function Re(e){return ts(e.status)?0:ss(e.status)?1:es(e.status)?3:2}const In={done:"text-sage",running:"text-accent",held:"text-fg-faint",pending:"text-fg-faint",blocked:"text-butter"},En={done:"bg-sage",running:"bg-accent",held:"bg-fg-faint/50",pending:"bg-fg-faint/50",blocked:"bg-butter"};function Tn(e,s){return e.every(n=>es(n.status))?`+${e.length} done`:e.every(n=>n.rowKind==="dep"&&n.blockers.some(a=>!a.missing&&a.status!==null&&ss(a.status)))?`+${e.length} blocked`:`+${e.length} in stage ${s}`}function _n({stage:e,epicId:s,now:n,hidden:a,indexBySlug:d,headChoicesBySlug:l,onRowFocused:i}){const[r,o]=f.useState(!1),c=f.useMemo(()=>e.rows.filter(x=>!(a.has(x.slug)&&(x.status==="completed"||x.status==="failed"))).map((x,R)=>({r:x,i:R})).sort((x,R)=>Re(x.r)-Re(R.r)||x.i-R.i).map(x=>x.r),[e.rows,a]),p=f.useMemo(()=>c.filter(x=>Re(x)<=1).length,[c]),u=Math.max(e.state==="done"?Rn:An,p),h=r?c:c.slice(0,u),g=r?[]:c.slice(u),m=c.find(x=>x.status==="failed"),v=c.find(x=>x.status==="needs_review"),y=p>0&&(m!==void 0||v!==void 0),k=h.reduce((x,R,P)=>Re(R)<=1?P:x,-1),S=x=>t.jsx(Zt,{row:x,elapsedMs:ts(x.status)&&x.job.startedAt?n-Date.parse(x.job.startedAt):null,listIndex:d.get(x.slug)??0,onFocused:i,headChoices:l.get(x.slug)??Mn},x.slug),T="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:ce},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 ${En[e.state]}`}),t.jsxs("span",{className:`text-[10px] font-semibold uppercase tracking-wide ${In[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((x,R)=>t.jsxs("div",{children:[S(x),y&&R===k&&t.jsxs("div",{"data-testid":"stage-attention-actions",className:"flex gap-1.5 px-2 py-1.5 border-t border-rule-inner",children:[m&&t.jsxs("button",{type:"button","data-testid":"stage-retry",title:`Reset ${m.slug} to pending`,onClick:()=>{window.api.schedule.resetJob(m.slug,m.job.cwd??void 0).then(P=>{P.ok||H.error(P.error??`Failed to reset ${m.slug}`)}).catch(()=>H.error(`Failed to reset ${m.slug}`))},className:T,children:["Retry ",m.prdNumber?`#${m.prdNumber}`:m.slug]}),v&&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&&_t(s)},className:T,children:["Review ",v.prdNumber?`#${v.prdNumber}`:v.slug]})]})]},x.slug))}),(g.length>0||r&&c.length>u)&&t.jsx("button",{type:"button","data-testid":"stage-footer","aria-expanded":r,onClick:()=>o(x=>!x),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 ▴":`${Tn(g,e.n)} ▾`})]})}const we=6,Qe=4,Ee=4,Ct=12,$t=5,ns=2,Pt=4,On={done:"bg-sage",running:"bg-accent",attention:"bg-butter",failed:"bg-red-600",pending:"bg-fg-faint/50"};function Ln(e){return e==="completed"||e==="skipped"?"done":e==="running"||e==="investigating"?"running":e==="failed"?"failed":e==="needs_review"||e==="quarantined"?"attention":"pending"}function Fn(e){const s=[],n=[],a=[];let d=$t;for(const l of e){const i=Math.max(1,Math.ceil(l.rows.length/Ee));n.push(d),a.push(i*we),l.rows.forEach((r,o)=>{s.push({x:d+Math.floor(o/Ee)*we,y:ns+o%Ee*we,tone:Ln(r.status),title:`${r.prdNumber?`#${r.prdNumber}`:r.slug} ${r.title} — ${r.status}`})}),d+=i*we+Ct}return{dots:s,stageX:n,stageW:a,width:Math.max(0,d-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 qn({stages:e,first:s,perView:n,onSeek:a}){const d=f.useMemo(()=>Fn(e),[e]),l=f.useMemo(()=>ve(e,et)>=0,[e]),i=f.useMemo(()=>ve(e,tt)>=0,[e]),r=f.useRef(!1),o=e.length,c=Math.min(o-1,s+n-1),p=d.stageX[Math.min(s,o-1)]??0,u=(d.stageX[c]??0)+(d.stageW[c]??0),h=m=>{const v=m.currentTarget.getBoundingClientRect(),y=m.clientX-v.left;let k=0;for(let S=0;S<o;S++)d.stageX[S]<=y&&(k=S);a(Math.max(0,Math.min(o-1,k-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:d.width,height:Ee*we-(we-Qe)+2*ns},onPointerDown:m=>{var v,y;r.current=!0,(y=(v=m.currentTarget).setPointerCapture)==null||y.call(v,m.pointerId),h(m)},onPointerMove:m=>{r.current&&h(m)},onPointerUp:()=>{r.current=!1},onPointerCancel:()=>{r.current=!1},children:[d.dots.map((m,v)=>t.jsx("span",{title:m.title,"data-tone":m.tone,className:`absolute rounded-[1px] ${On[m.tone]}`,style:{left:m.x,top:m.y,width:Qe,height:Qe}},v)),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,o),"–",c+1," of ",o]}),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 Bn=148;function Hn({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:Bn},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(d=>{const l=d.rows.length===0?0:d.doneCount/d.rows.length*100;return t.jsxs("button",{type:"button","data-testid":"further-stage-row","data-stage":d.n,title:`${d.summary} — scroll to stage ${d.n}`,onClick:()=>s(d.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 ",d.n]}),t.jsx("span",{role:"progressbar","aria-valuenow":d.doneCount,"aria-valuemin":0,"aria-valuemax":d.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}%`}})})]},d.n)})]})}const Gn=[],Vn=e=>e==="running"||e==="investigating";function Wn(e){const s=ln(e),n=new Map,a=new Map;for(const r of e.stages){a.set(r.n,r.rows.length);for(const o of r.rows)n.set(o.slug,o)}const d=new Map;let l=0;const i=[];for(const r of s){const o=n.get(r);l+=o.estimateMinutes??0,d.set(o.stage,(d.get(o.stage)??0)+1),i.push({row:o,totalMinutes:l,othersInStage:0})}for(const r of i)r.othersInStage=(a.get(r.row.stage)??0)-(d.get(r.row.stage)??0);return i}function Un({plan:e,now:s,indexBySlug:n,headChoicesBySlug:a,onRowFocused:d}){const l=f.useMemo(()=>Wn(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:o})=>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(Zt,{row:i,elapsedMs:Vn(i.status)&&i.job.startedAt?s-Date.parse(i.job.startedAt):null,listIndex:n.get(i.slug)??0,onFocused:d,headChoices:a.get(i.slug)??Gn})}),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"]})]})]}),o>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," · +",o," not on the critical path"]})]},i.slug))})}const Dt=1,At=1350,zn={active:"border-l-accent",queued:"border-l-rule-structural",done:"border-l-sage",draft:"border-l-fg-faint/40 border-dashed"},Qn={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"}},Yn=e=>String(e).padStart(2,"0");function Jn({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 Kn({plan:e,mode:s="graph",now:n,hidden:a,indexBySlug:d,headChoicesBySlug:l,onRowFocused:i,onOpenPrds:r}){var se,Y;const[o,c]=f.useState(e.status==="active"||e.status==="queued"),[p,u]=f.useState(!1),h=f.useRef(null),[g,m]=f.useState(0),[v,y]=f.useState(At),k=f.useMemo(()=>{const M=ve(e.stages,et);return M>=0?M:Math.max(0,ve(e.stages,tt))},[e.stages]);f.useLayoutEffect(()=>{if(!o)return;const M=h.current,F=(M==null?void 0:M.clientWidth)||At,N=Math.max(0,Math.min(k,e.stageCount-Math.max(1,Math.ceil(F/ce))));M!=null&&M.clientWidth&&y(M.clientWidth),M&&(M.scrollLeft=N*ce),m(N)},[o]);const S=f.useMemo(()=>{let M=null;for(const F of e.stages)for(const N of F.rows){if(!N.job.runId)continue;const C=N.job.finishedAt?Date.parse(N.job.finishedAt):0;(!M||C>M.at)&&(M={runId:N.job.runId,slug:N.slug,title:N.title,at:C})}return M},[e.stages]),T=_e((Y=(se=e.stages[0])==null?void 0:se.rows[0])==null?void 0:Y.job.cwd)??"—",x=Qn[e.status],R=Math.max(1,Math.ceil(v/ce)),P=Math.max(0,Math.min(g-Dt,e.stageCount)),D=Math.min(e.stageCount,g+R+Dt),O=M=>{const F=Math.max(0,Math.min(e.stageCount-1,M));h.current&&(h.current.scrollLeft=F*ce),m(F)},J=Math.min(e.stageCount,g+R),W=M=>{const F=M.currentTarget,N=Math.floor(F.scrollLeft/ce);N!==g&&m(N),F.clientWidth&&F.clientWidth!==v&&y(F.clientWidth)},z="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(()=>H.error("Failed to pause the scheduler"))},className:z,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(H.fromOutcome).catch(()=>H.error("Failed to fire the next batch"))},className:z,children:"Run now"});case"done":return t.jsx("button",{type:"button","data-testid":"plan-action",disabled:!S,title:S?`Open the run log of ${S.slug}, the plan's last run`:"No run log recorded for this plan",onClick:()=>u(!0),className:z,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,F;return r==null?void 0:r(((F=(M=e.stages[0])==null?void 0:M.rows[0])==null?void 0:F.slug)??null)},className:z,children:"Schedule…"})}})(),X=e.etaMs>0?` · ${Ut(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] ${zn[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":o,"aria-label":o?"Collapse plan":"Expand plan","data-testid":"plan-toggle",onClick:()=>c(M=>!M),className:"shrink-0 w-[14px] text-[11px] text-fg-faint hover:text-fg bg-transparent border-0 cursor-pointer p-0",children:o?"▾":"▸"}),t.jsx("span",{className:"font-mono text-[11.5px] text-fg-faint shrink-0",children:Yn(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 ${x.cls}`,children:x.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:[T," · ",e.epicLabel," · ",e.prdCount," PRD",e.prdCount===1?"":"s"," · ",e.width," wide · ",e.stageCount," stage",e.stageCount===1?"":"s"]}):t.jsxs(t.Fragment,{children:[T," · ",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,X]}),t.jsx(Jn,{plan:e}),K]}),o&&s==="critical"&&t.jsx(Un,{plan:e,now:n,indexBySlug:d,headChoicesBySlug:l,onRowFocused:i}),o&&s!=="critical"&&e.status==="active"&&t.jsx(qn,{stages:e.stages,first:g,perView:R,onSeek:O}),o&&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:[P>0&&t.jsx("div",{"aria-hidden":"true",className:"shrink-0",style:{width:P*ce}}),e.stages.slice(P,D).map(M=>t.jsx(_n,{stage:M,epicId:e.epicId,now:n,hidden:a,indexBySlug:d,headChoicesBySlug:l,onRowFocused:i},M.n)),D<e.stageCount&&t.jsx("div",{"aria-hidden":"true",className:"shrink-0",style:{width:(e.stageCount-D)*ce}})]}),t.jsx(Hn,{stages:e.stages.slice(J),onSeek:O})]}),p&&S&&t.jsx(qe,{runId:S.runId,slug:S.slug,title:S.title||S.slug,onClose:()=>u(!1)})]})}function Xn({section:e,children:s}){const[n,a]=f.useState(!0),d=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:d})]}),n&&s]})}const Zn=[],ea=[],ta={depth:0,blockers:Zn,blocked:!1,hasNeedsReviewBlocker:!1,hasMissingDep:!1,cycle:!1,parallelEligible:!1};function sa(e){return e.missing?`${e.slug} (missing)`:e.needsReview?`${e.slug} (needs review)`:`${e.slug} (${(e.status??"unknown").replace(/_/g," ")})`}function na(e){return e.missing?"text-accent":e.needsReview?"text-butter font-semibold":e.status==="completed"?"text-sage":"text-amber-400/90"}function aa({job:e,eta:s,elapsedMs:n,avgDurationMs:a,listIndex:d,onFocused:l,hold:i,backlog:r=ta,headChoices:o=ea}){const[c,p]=f.useState(!1),[u,h]=f.useState(!1),g=pe(D=>D.sessions),m=f.useMemo(()=>Pe(e,g),[e,g]),v=m.known&&m.epicId?g[m.epicId]:null,y=f.useCallback(D=>{at(D),window.dispatchEvent(new CustomEvent("sm:navigate",{detail:"terminal"}))},[]),k=e.status==="running",S=e.status==="failed";let T=null;k&&n!==null?T=`${Te(n)} elapsed`:e.status==="completed"&&e.startedAt&&e.finishedAt?T=`took ${Ce(Date.parse(e.finishedAt)-Date.parse(e.startedAt))}`:s&&(T=s);const x=e.error??null,R=S&&x?x.split(`
|
|
4
|
+
`)[0]:e.status==="needs_review"&&e.verifierVerdict?$e(e.verifierVerdict):null,P=k&&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":d,"data-depth":r.depth,onClick:()=>p(D=>!D),onFocus:()=>l(d),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 ${c?"bg-bg-elev/40":""}`,"aria-expanded":c,"aria-label":`${ie(e.slug)?`PRD ${ie(e.slug)}, `:""}${e.title}, ${e.status}${T?`, ${T}`:""}`,title:e.title,children:[t.jsx(Ot,{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(Lt,{n:ie(e.slug)}),e.title,t.jsx(Ft,{leaked:e.leakedDescendants}),t.jsx(Ss,{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(D=>D.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((D,O)=>t.jsxs("span",{className:na(D),children:[O>0&&", ",sa(D)]},D.slug))]}),R&&t.jsx("div",{className:`text-[12.5px] mt-0.5 ${S?"text-accent/80":"text-fg-faint"}`,children:R}),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:m.epicId,label:m.label?Jt(m.label):null,onOpen:y,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(Cs,{status:e.status,overrun:e.overrun}),T,t.jsx("span",{className:`text-fg-faint inline-flex transition-transform duration-150 ${c?"rotate-90":""}`,"aria-hidden":"true",children:t.jsx(nt,{name:"chevron",size:14})})]})]}),k&&!c&&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,P*100)}%`}})}),c&&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(B,{k:"result",v:e.exitCode!==null?`exit ${e.exitCode}`:"—"}),t.jsx(B,{k:"state",v:e.status.replace(/_/g," ")}),e.verifierVerdict&&t.jsx(B,{k:"verdict",v:$e(e.verifierVerdict)}),e.leakedDescendants&&e.leakedDescendants.length>0&&t.jsx(B,{k:"leaked",v:qt(e.leakedDescendants),wrap:!0}),e.leftoverCount!=null&&e.leftoverCount>0&&t.jsx(B,{k:"uncommitted",v:`${e.leftoverCount} file${e.leftoverCount===1?"":"s"}${e.leftoverPathsTruncated?"+":""}: ${(e.leftoverPaths??[]).join(", ")}${e.salvagePatch?` — salvaged to ${e.salvagePatch}`:""}`,wrap:!0}),x&&t.jsx(B,{k:"error",v:x.split(`
|
|
5
|
+
`)[0],wrap:!0})]}),e.statusHistory&&e.statusHistory.length>0&&t.jsx(re,{label:"History",children:t.jsx("div",{className:"grid gap-1",children:e.statusHistory.map((D,O)=>t.jsxs("div",{className:"font-mono text-xs leading-relaxed",children:[t.jsxs("div",{className:"text-fg",children:[D.from??"(new)"," → ",D.to,t.jsxs("span",{className:"text-fg-faint",children:[" · ",ue(Date.parse(D.at))]})]}),D.reason&&t.jsx("div",{className:"text-fg-faint break-words",children:D.reason})]},O))})}),t.jsxs(re,{label:"Timing",children:[t.jsx(B,{k:"started",v:e.startedAt?ue(Date.parse(e.startedAt)):"—"}),t.jsx(B,{k:"finished",v:e.finishedAt?ue(Date.parse(e.finishedAt)):"—"}),t.jsx(B,{k:"duration",v:e.startedAt&&e.finishedAt?Ce(Date.parse(e.finishedAt)-Date.parse(e.startedAt)):k&&n!==null?Te(n):"—"})]}),t.jsxs(re,{label:"Location",children:[t.jsx(B,{k:"group",v:`${e.parallelGroup} · ${e.slug}`}),t.jsx(B,{k:"cwd",v:e.cwd??"—",wrap:!0}),t.jsx(B,{k:"session",v:m.label??m.epicId??"—",wrap:!0}),t.jsx(B,{k:"session id",v:m.epicId??"—",wrap:!0}),t.jsx(B,{k:"prompt id",v:e.sourcePromptId??"—",wrap:!0}),t.jsx(B,{k:"source tab",v:e.sourceTabId??"—",wrap:!0})]}),t.jsx(re,{label:"Actions",children:t.jsxs("div",{className:"flex flex-col gap-1.5 items-start",children:[v&&t.jsx("button",{type:"button","data-testid":"job-row-prompt-session-link",title:v.goalText,onClick:()=>y(v.id),className:"text-[13px] font-semibold text-accent hover:text-accent/80 bg-transparent border-0 cursor-pointer p-0",children:"view epic →"}),e.runId&&t.jsx("button",{type:"button",onClick:()=>h(!0),className:"text-[13px] font-semibold text-fg-dim hover:text-fg bg-transparent border-0 cursor-pointer p-0",children:"view log →"}),e.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(e.slug).then(H.fromOutcome).catch(()=>H.error("Failed to adopt PRD"))},className:"text-[13px] font-semibold text-accent hover:text-accent/80 bg-transparent border-0 cursor-pointer p-0",children:"adopt PRD →"}),e.status!=="pending"&&e.status!=="running"&&e.status!=="quarantined"&&t.jsx("button",{type:"button",onClick:()=>window.api.schedule.resetJob(e.slug,e.cwd??void 0),className:"text-[13px] font-semibold text-fg-dim hover:text-fg bg-transparent border-0 cursor-pointer p-0",children:"reset to pending →"}),e.disposition&&(e.status==="pending"||e.status==="quarantined")&&t.jsx(Xt,{job:e,headChoices:o})]})})]}),u&&e.runId&&t.jsx(qe,{runId:e.runId,slug:e.slug,title:e.title||e.slug,onClose:()=>h(!1)})]})}const ra=f.memo(aa);function ia({supervisorConfig:e,onSetConfig:s,onBack:n}){const[a,d]=f.useState([]),[l,i]=f.useState(()=>Date.now()),r=st();f.useEffect(()=>{if(!r)return;window.api.supervisor.getLog().then(d).catch(()=>{}),i(Date.now());const c=setInterval(()=>i(Date.now()),5e3);return()=>clearInterval(c)},[r]);const o={enabled:(e==null?void 0:e.enabled)??!0,intervalMinutes:(e==null?void 0:e.intervalMinutes)??15,maxConcurrentProbes:(e==null?void 0:e.maxConcurrentProbes)??2,probeStaleThresholdMinutes:(e==null?void 0:e.probeStaleThresholdMinutes)??10};return t.jsxs("div",{className:"bg-bg-elev/60",children:[t.jsxs("div",{className:"px-3 py-2 flex items-center gap-2 border-b border-line",children:[t.jsx("button",{type:"button",onClick:n,className:"text-[10px] text-fg-faint hover:text-fg-dim",title:"Back to queue",children:"← queue"}),t.jsx("span",{className:"text-[11px] font-medium text-fg-dim",children:"Supervisor"}),t.jsx("button",{type:"button",onClick:()=>window.api.supervisor.getLog().then(d).catch(()=>{}),className:"ml-auto text-[10px] text-fg-faint hover:text-fg-dim underline",title:"Refresh log",children:"refresh"})]}),t.jsxs("div",{className:"px-3 py-2 space-y-1.5 border-b border-line",children:[t.jsx("div",{className:"text-[9px] text-fg-faint uppercase tracking-wider",children:"Config"}),t.jsxs("div",{className:"flex items-center gap-3 flex-wrap text-[10px] text-fg-faint",children:[t.jsxs("label",{className:"flex items-center gap-1",children:[t.jsx("input",{type:"checkbox",checked:o.enabled,onChange:c=>s({enabled:c.target.checked}),className:"cursor-pointer"}),t.jsx("span",{children:"enabled"})]}),t.jsxs("label",{className:"flex items-center gap-1",title:"How often to check for wedged jobs (minutes)",children:[t.jsx("span",{children:"interval"}),t.jsx("input",{type:"number",min:5,max:60,value:o.intervalMinutes,onChange:c=>s({intervalMinutes:Number(c.target.value)}),className:"w-10 bg-bg border border-line rounded px-1 py-0.5 font-mono"}),t.jsx("span",{children:"min"})]}),t.jsxs("label",{className:"flex items-center gap-1",title:"Max concurrent Opus probes per tick",children:[t.jsx("span",{children:"probes"}),t.jsx("input",{type:"number",min:1,max:5,value:o.maxConcurrentProbes,onChange:c=>s({maxConcurrentProbes:Number(c.target.value)}),className:"w-8 bg-bg border border-line rounded px-1 py-0.5 font-mono"})]}),t.jsxs("label",{className:"flex items-center gap-1",title:"Probe a job only if no JSONL event in this many minutes",children:[t.jsx("span",{children:"stale"}),t.jsx("input",{type:"number",min:5,max:30,value:o.probeStaleThresholdMinutes,onChange:c=>s({probeStaleThresholdMinutes:Number(c.target.value)}),className:"w-8 bg-bg border border-line rounded px-1 py-0.5 font-mono"}),t.jsx("span",{children:"min"})]})]})]}),t.jsxs("div",{className:"px-3 py-2",children:[t.jsxs("div",{className:"text-[9px] text-fg-faint uppercase tracking-wider mb-1",children:["Recent probes (last ",a.length,")"]}),a.length===0?t.jsx("div",{className:"text-[10px] text-fg-faint italic",children:"No probes yet."}):t.jsx("div",{className:"space-y-0.5 max-h-64 overflow-y-auto",children:a.map((c,p)=>t.jsx(la,{entry:c,now:l},`${c.ts}-${p}`))})]})]})}function la({entry:e,now:s}){const n=e.action!=="none",a=te(s-e.ts);return t.jsxs("div",{className:`text-[10px] px-1.5 py-1 rounded font-mono ${n?"bg-red-500/10 border border-red-500/20":"bg-bg/40"}`,title:e.reason,children:[t.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[t.jsxs("span",{className:"text-fg-faint shrink-0",children:[a," ago"]}),t.jsx("span",{className:`shrink-0 px-1 rounded ${e.verdict==="stuck"?"text-red-400 bg-red-500/10":"text-green-500/70"}`,children:e.verdict}),t.jsx("span",{className:"truncate text-fg-dim",children:e.jobSlug}),n&&t.jsxs("span",{className:"shrink-0 text-red-400",children:[e.action,e.targetPid?` pid=${e.targetPid}`:""]}),e.costUsd!==null&&t.jsxs("span",{className:"shrink-0 text-fg-faint",children:["$",e.costUsd.toFixed(3)]})]}),t.jsx("div",{className:"text-fg-faint truncate mt-0.5",children:e.reason})]})}const oa=[{title:"Start a session",body:"In Sessions, pick an Agent and a Mission, describe the outcome you want, then Approve & start. Its thread writes the PRD files into that session's own folder."},{title:"Queue what it wrote",body:"The PRDs tab lists every file the session produced. Queue one, or the whole session, and they appear here."},{title:"Leave it alone",body:"Jobs start themselves inside your window, pause on rate-limit, and resume at the reset. History records how each ended."}],da=[{term:"Session",def:"One goal, one Claude session, and the folder of PRDs written to reach it."},{term:"PRD",def:"One markdown file = one job. Authored by the session."},{term:"5-hour window",def:"Your Claude billing window, on a rolling clock."},{term:"Session pool",def:"5 slots shared with terminal and session chats."}];function ca({navigate:e}){return t.jsx("div",{className:"overflow-y-auto h-full",children:t.jsx("div",{className:"px-9 py-6 max-w-[900px] mx-auto",children:t.jsxs("div",{className:"bg-bg-hi border border-line rounded-2xl px-9 py-8",children:[t.jsx("h2",{className:"m-0 font-serif text-[25px] font-semibold text-fg",children:"Nothing to run yet — the scheduler needs a session."}),t.jsx("p",{className:"mt-2 mb-6 text-[14.5px] text-fg-dim leading-relaxed max-w-[580px]",children:"You don't write PRDs here. A session breaks its goal into numbered PRD files, and this page runs them in order. Two steps, once."}),t.jsx("div",{className:"grid grid-cols-3 gap-3.5",children:oa.map((s,n)=>{const a=n===0;return t.jsxs("div",{className:`bg-bg border rounded-xl px-4 py-4 flex flex-col gap-2 ${a?"border-accent shadow-[0_0_0_3px_rgba(184,92,52,.09)]":"border-line"}`,children:[t.jsx("span",{className:`w-6 h-6 rounded-full grid place-items-center font-mono text-[12px] font-semibold ${a?"bg-accent text-white":"bg-bg-elev text-fg-dim"}`,children:n+1}),t.jsx("h3",{className:"m-0 text-[15px] font-semibold text-fg",children:s.title}),t.jsx("p",{className:"m-0 text-[13.5px] text-fg-dim leading-relaxed",children:s.body}),a&&t.jsx("button",{type:"button",onClick:()=>e==null?void 0:e("terminal"),className:"self-start bg-accent text-white rounded-lg px-3.5 py-1.5 text-[13px] font-semibold mt-1",children:"Go to Sessions →"})]},s.title)})}),t.jsx("dl",{className:"flex mt-[22px] pt-4 border-t border-line gap-5 flex-wrap",children:da.map(({term:s,def:n})=>t.jsxs("div",{className:"flex-1 min-w-[150px]",children:[t.jsx("dt",{className:"text-[13.5px] font-semibold text-fg mb-0.5",children:s}),t.jsx("dd",{className:"m-0 text-[12.5px] text-fg-faint leading-relaxed",children:n})]},s))})]})})})}const ua=5e3;let Me=null,Ne=null;async function Rt(e){const s=Date.now();return!(e!=null&&e.fresh)&&Me&&s-Me.at<ua?Me.result:Ne||(Ne=(async()=>{try{const n=await window.api.schedule.lintQueue();return Me={result:n,at:Date.now()},n}finally{Ne=null}})(),Ne)}function pa({health:e,jobCount:s,lastRunAt:n,nextReset:a,now:d,onOpenSupervisor:l}){const[i,r]=f.useState(!1),[o,c]=f.useState(null),[p,u]=f.useState(!1),h=`${s}:${n??""}`;f.useEffect(()=>{let P=!0;return u(!0),Rt().then(D=>{P&&c(D)}).catch(()=>{}).finally(()=>{P&&u(!1)}),()=>{P=!1}},[h]);let g=0,m=0;const v=o?o.reports.filter(P=>P.findings.length>0):[];for(const P of v)for(const D of P.findings)D.severity==="error"?g++:m++;const y=g===0&&m===0,k=o?`graph lint ${g} error${g===1?"":"s"}, ${m} warn${m===1?"":"s"}`:`graph lint ${p?"scanning…":"idle"}`,S=(e==null?void 0:e.consecutiveFailures)??0,x=[e?`${S} poll failure${S===1?"":"s"} in current streak`:null,k].filter(Boolean).join(" · "),R="text-accent hover:underline bg-transparent border-0 p-0 cursor-pointer text-[12px]";return t.jsxs("div",{"data-testid":"scheduler-footer",className:"border-t border-rule-structural",children:[t.jsxs("div",{className:"h-[28px] flex items-center gap-2 px-[18px] font-mono text-[11.5px] text-fg-faint",children:[t.jsx("span",{"data-testid":"footer-summary",className:"truncate",children:x}),t.jsx("button",{type:"button","data-testid":"footer-info","aria-expanded":i,onClick:()=>r(P=>!P),className:"bg-transparent border-0 p-0 cursor-pointer",children:t.jsx(me,{title:"Scheduler poll health and queue-lint findings — click for the full detail"})}),t.jsxs("span",{className:"ml-auto flex items-center gap-3 shrink-0",children:[t.jsxs("span",{"data-testid":"footer-timing",children:[a?t.jsxs("span",{title:`next 5h reset: ${a}`,children:["reset ",te(Date.parse(a)-d)]}):null,a&&n?" · ":null,n?t.jsxs("span",{title:n,children:["last run ",te(d-Date.parse(n))," ago"]}):null]}),t.jsx("button",{type:"button","data-testid":"footer-supervisor",onClick:l,title:"Open supervisor log and settings",className:R,children:"supervisor"}),t.jsx("button",{type:"button","data-testid":"footer-folder",onClick:()=>window.api.schedule.openFolder(),className:R,children:"folder"})]})]}),i&&t.jsxs("div",{"data-testid":"footer-detail",className:"px-[18px] pb-2 space-y-2 font-mono text-[12px] text-fg-dim border-t border-rule-inner pt-2",children:[e&&t.jsxs("div",{className:"space-y-0.5",children:[t.jsxs("div",{children:["booted: ",xe(e.bootedAt,d)]}),t.jsxs("div",{children:["last poll: ",xe(e.lastPollAt,d)," · ",e.lastPollOk?"ok":"failed"]}),e.backoffNextAt!==null&&e.backoffNextAt>d&&t.jsxs("div",{children:["retry in: ",te(e.backoffNextAt-d)]}),e.nextResetCached&&t.jsxs("div",{children:["cached reset: ",ue(Date.parse(e.nextResetCached))]}),e.runningJobs.length>0&&t.jsxs("div",{children:["running: ",e.runningJobs.map(P=>`${P.slug}(pid ${P.pid})`).join(", ")]})]}),o&&t.jsxs("div",{className:"space-y-1",children:[y?t.jsxs("div",{className:"text-sage",children:["✓ no issues in ",o.reports.length," PRD",o.reports.length!==1?"s":""]}):v.map(P=>t.jsxs("div",{children:[t.jsx("div",{className:"text-fg-dim truncate",title:P.slug,children:P.slug}),P.findings.map((D,O)=>t.jsxs("div",{className:`pl-3 truncate ${D.severity==="error"?"text-accent/80":"text-butter/90"}`,title:D.snippet,children:[D.severity==="error"?"✗":"⚠"," L",D.line,": ",D.snippet]},`${P.slug}-${O}`))]},P.slug)),t.jsx("button",{type:"button","data-testid":"footer-rerun-lint",onClick:()=>{u(!0),Rt({fresh:!0}).then(c).catch(()=>{}).finally(()=>u(!1))},className:"text-fg-faint hover:text-fg-dim underline",children:p?"…":"rerun lint"})]})]})]})}const fa=5,ha=1440*60*1e3,Ie=10,ga=["all","running","investigating","pending","completed","skipped","needs_review","failed","quarantined"];async function xa(e){if(!e)return{text:"",status:"all"};const s=await Bt(e);return{text:"",status:ga.includes(s.queueFilterStatus)?s.queueFilterStatus:"all"}}function ma(e,s){return e?Ht(e,{queueFilterStatus:s.status}):Promise.resolve()}function Mt(e,s){if(s.status==="all"&&!s.text)return e;const n=s.text.toLowerCase();return e.filter(a=>{if(s.status!=="all"&&a.status!==s.status)return!1;if(!n)return!0;const d=_e(a.cwd)??"";return a.title.toLowerCase().includes(n)||a.slug.toLowerCase().includes(n)||d.toLowerCase().includes(n)})}async function ba(e){if(!e)return new Set;const s=await Bt(e);return Array.isArray(s.hiddenCompletedSlugs)?new Set(s.hiddenCompletedSlugs.filter(n=>typeof n=="string")):new Set}function wa(e,s){return e?Ht(e,{hiddenCompletedSlugs:[...s]}):Promise.resolve()}function va({scopeCwd:e=null,navigate:s,filterText:n,planMode:a="graph",onOpenPrds:d,planToolsEl:l=null}){var mt;const i=Fe(w=>w.snapshot),r=f.useMemo(()=>!i||!e?i:{...i,jobs:i.jobs.filter(w=>w.cwd===e)},[i,e]),[o,c]=f.useState(null),[p,u]=f.useState(()=>Date.now()),[h,g]=f.useState(new Set),[m,v]=f.useState(!1),[y,k]=f.useState({text:"",status:"all"}),S=f.useMemo(()=>n===void 0?y:{...y,text:n},[y,n]),[T,x]=f.useState(!1),[R,P]=f.useState("queue"),D=f.useRef(null),[O,J]=f.useState(0),[W,z]=f.useState(""),K=st(),X=f.useRef(!1),se=f.useRef(!1),Y=f.useRef(h);Y.current=h;const M=f.useRef(y);M.current=y,f.useEffect(()=>{let w=!1;return X.current=!1,se.current=!1,ba(e).then(E=>{!w&&!X.current&&g(E)}),xa(e).then(E=>{!w&&!se.current&&k(E)}),()=>{w=!0}},[e]),f.useEffect(()=>(window.api.schedule.health().then(c).catch(()=>{}),window.api.schedule.onState(()=>{window.api.schedule.health().then(c).catch(()=>{})})),[]),f.useEffect(()=>{if(!K)return;u(Date.now());const w=setInterval(()=>u(Date.now()),1e3);return()=>clearInterval(w)},[K]);const F=f.useMemo(()=>{if(!r)return 15e4;const w=[];for(const E of r.jobs)if(E.status==="completed"&&E.startedAt&&E.finishedAt){const G=Date.parse(E.finishedAt)-Date.parse(E.startedAt);G>0&&w.push(G)}return w.length===0?15e4:w.reduce((E,G)=>E+G,0)/w.length},[r]),N=f.useRef(new Map);f.useEffect(()=>{if(!r)return;const w=[];for(const E of r.jobs){const G=N.current.get(E.slug);G&&G!==E.status&&w.push(`${E.title}: ${G} → ${E.status}`),N.current.set(E.slug,E.status)}w.length>0&&z(w.join("; "))},[r]);const C=f.useMemo(()=>{var E;const w=new Map;for(const G of((E=r==null?void 0:r.lastTick)==null?void 0:E.holds)??[])w.set(G.slug,G);return w},[r==null?void 0:r.lastTick]),q=pe(w=>w.sessions),V=f.useMemo(()=>r?Vt(Oe(r.jobs),q,i!=null&&i.jobs?Oe(i.jobs):void 0):[],[r,q,i]),U=$s(),b=f.useMemo(()=>r?Mt(yn(r.jobs,U,e),S):[],[r,U,e,S]),j=(mt=r==null?void 0:r.effectiveConcurrency)==null?void 0:mt.cap,A=f.useMemo(()=>a==="list"?[]:lt(b,{sessions:q,avgDurationMs:F,concurrency:j}),[a,b,q,F,j]),[$,I]=f.useState(1),L=A.map(w=>`${w.epicId??""}#${w.waveIndex}`).join(",");f.useEffect(()=>{I(1)},[e,S.status,S.text,L]);const _=Math.max(1,Math.ceil(A.length/Ie)),Z=Math.min($,_),He=f.useMemo(()=>A.slice((Z-1)*Ie,Z*Ie),[A,Z]),rs=f.useMemo(()=>{const w=new Map;let E=0;for(const G of A)for(const Q of G.stages)for(const ae of Q.rows)w.set(ae.slug,E++);return w},[A]),is=f.useMemo(()=>jn(V),[V]),ls=h,ot=f.useCallback(w=>{var be;const E=(be=D.current)==null?void 0:be.querySelectorAll("[data-job-row]");if(!E||E.length===0)return;const G=Array.from(E),Q=G.findIndex(ne=>ne.dataset.jobIndex===String(O)),ae=ne=>{const fe=G[ne];if(!fe)return;const he=Number(fe.dataset.jobIndex);J(he),fe.focus()};w.key==="ArrowDown"?(w.preventDefault(),ae(Q===-1?0:Math.min(Q+1,G.length-1))):w.key==="ArrowUp"&&(w.preventDefault(),ae(Q===-1?G.length-1:Math.max(Q-1,0)))},[O]),dt=f.useCallback(w=>{J(w)},[]),ct=f.useCallback(w=>{const E=M.current;se.current=!0,M.current=w,k(w),ma(e,w).catch(()=>{M.current===w&&(M.current=E,k(E),H.error("Couldn't save queue filter — reverted."))})},[e]),ut=f.useCallback(w=>{const E=Y.current;X.current=!0,Y.current=w,g(w),wa(e,w).catch(()=>{Y.current===w&&(Y.current=E,g(E),H.error("Couldn't save hidden completed jobs — reverted."))})},[e]);if(!r)return null;if(R==="supervisor")return t.jsx(ia,{supervisorConfig:r.config.supervisor,onSetConfig:w=>window.api.schedule.setConfig({supervisor:w}),onBack:()=>P("queue")});const{jobs:ee,paused:pt,lastRunAt:os,nextReset:ds,effectiveConcurrency:Ge}=r;if(ee.length===0)return t.jsx(ca,{navigate:s});const le={pending:0,running:0,investigating:0,completed:0,needs_review:0,failed:0};for(const w of ee)w.status in le&&le[w.status]++;const Ve=ee.filter(w=>w.status==="running"),cs=Qt({snap:r,now:p,avgDurationMs:F,runningJobs:Ve}),je=Mt(ee,S),us=ja(je),{inline:De,collapsedCount:We}=ya(je,h,p,m),ps=Na(De,ee,us,F,cs.kind,p),ft=()=>{const w=new Set(h);for(const E of ee)(E.status==="completed"||E.status==="failed")&&w.add(E.slug);ut(w)},ht=async()=>{const w=ee.filter(Q=>Q.status!=="running").length;if(w===0)return;const E=`Archive ${w} non-running PRD${w===1?"":"s"} and remove from the queue?
|
|
6
|
+
|
|
7
|
+
Files are moved to prds-archived/<timestamp>/ and can be restored from disk. Running jobs are kept.`;if(!window.confirm(E))return;const G=await window.api.schedule.clearQueue();G.ok||H.error(`Clear queue failed: ${G.error??"unknown error"}`)},gt=()=>{ut(new Set),v(!1)},xt=a==="list"?De.some(w=>w.status==="completed"):ee.some(w=>(w.status==="completed"||w.status==="skipped")&&!h.has(w.slug)),fs=ee.filter(w=>(w.status==="completed"||w.status==="failed")&&h.has(w.slug)).length,oe=a==="list",Ae=oe?"":"px-[18px] py-2";return t.jsxs("div",{className:"overflow-y-auto h-full",children:[t.jsx("div",{"aria-live":"polite","aria-atomic":"true",className:"sr-only",children:W}),t.jsxs("div",{className:oe?"px-9 py-6 max-w-[1100px] mx-auto space-y-4":"",children:[o&&o.consecutiveFailures>5&&o.lastFailureKind==="meter_rate_limited"&&!pt&&!T&&t.jsx("div",{className:Ae,children:t.jsxs("div",{className:oe?"flex items-center gap-3 px-4 py-3 bg-amber-400/15 border border-amber-400/30 rounded-xl":"flex items-center gap-3 -mx-[18px] px-[18px] py-1 bg-amber-400/15 border-y border-amber-400/30",children:[t.jsx("span",{"aria-hidden":"true",children:"⚠"}),t.jsxs("span",{className:"text-[13.5px] text-amber-400/90",children:[t.jsx("strong",{className:"font-semibold",children:"Usage meter unavailable"})," — last good reading"," ",xe(o.lastPollAt,p),". Firing on a conservative estimate until it recovers."]}),t.jsx("button",{type:"button",onClick:()=>x(!0),className:"ml-auto text-[12px] text-amber-400/70 hover:text-amber-400 shrink-0",title:"Dismiss this banner. The scheduler continues firing normally.",children:"Dismiss"})]})}),oe&&Ve.length>0&&(()=>{const w=(Ge==null?void 0:Ge.cap)??5,E=ee.filter(G=>G.status==="pending").length;return t.jsxs("div",{className:`flex items-center gap-2 text-[12px] font-mono ${Ae}`,children:[t.jsxs("span",{className:"px-2 py-0.5 rounded bg-amber-400/20 text-amber-400 shrink-0",children:[Ve.length,"/",w," running"]}),E>0&&t.jsxs("span",{className:"text-fg-faint",children:["+",E," ready in this group"]})]})})(),oe&&ee.length>0&&t.jsx("div",{className:Ae,children:t.jsx(Sa,{showText:n===void 0,filter:S,onChange:ct})}),!oe&&t.jsxs("div",{"data-testid":"plan-graph",children:[l&&Ps.createPortal(t.jsx(ka,{jobCount:je.length,counts:le,filter:S,onFilter:ct,hiddenInGraph:fs,onUnhideAll:gt,hasInlineCompleted:xt,onClearCompleted:ft,onClearQueue:ht,clearQueueDisabled:ee.every(w=>w.status==="running")}),l),A.length===0&&t.jsx("div",{className:"px-[18px] py-6 text-[13px] text-fg-faint italic",children:"no matching jobs"}),t.jsx("div",{ref:D,role:"list","aria-label":"Job queue",onKeyDown:ot,children:He.map(w=>t.jsx(Kn,{plan:w,mode:a,now:p,hidden:ls,indexBySlug:rs,headChoicesBySlug:is,onRowFocused:dt,onOpenPrds:d},`${w.epicId??"__none__"}#${w.waveIndex}`))}),t.jsx(Ds,{page:Z,pageSize:Ie,totalItems:A.length,onPageChange:I})]}),oe&&t.jsxs("div",{className:"bg-bg-hi border border-line rounded-2xl overflow-hidden",children:[t.jsxs("div",{className:"flex items-center justify-between px-[18px] py-3 bg-bg-elev",children:[t.jsxs("span",{className:"font-serif text-base font-semibold text-fg",children:[je.length," job",je.length!==1?"s":""]}),t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsxs("span",{className:"font-mono text-[12px] text-fg-faint",children:[le.pending,"p · ",le.running,"r · ",le.completed,"d",le.failed>0&&t.jsxs("span",{className:"text-accent",children:[" · ",le.failed,"f"]})]}),xt&&t.jsx("button",{type:"button",onClick:ft,className:"text-[12.5px] text-fg-dim hover:text-fg bg-transparent border-0 cursor-pointer font-medium",title:"Hide completed jobs from this view (queue.json unchanged — they remain in history)",children:"Clear completed"}),t.jsx("button",{type:"button",onClick:ht,disabled:ee.every(w=>w.status==="running"),className:"text-[12px] text-accent border border-accent/40 hover:bg-accent/10 rounded-md px-2.5 py-1 cursor-pointer font-medium disabled:opacity-40 disabled:cursor-not-allowed",title:"Archive every non-running PRD (moved to prds-archived/<timestamp>/) and remove them from the queue. Running jobs are kept.",children:"Archive & clear queue…"})]})]}),De.length===0&&We===0&&t.jsx("div",{className:"px-[18px] py-6 text-[13px] text-fg-faint italic",children:"no matching jobs"}),t.jsx("div",{ref:D,role:"list","aria-label":"Job queue",onKeyDown:ot,children:(()=>{const w=new Set(De.map(Q=>Q.slug));let E=0;return V.map(Q=>{const ae=Kt(Q),be=Q.nodes.map(ne=>{const fe=Be([ne]).filter(he=>w.has(he.row.slug)).map(he=>({node:he,listIndex:E++}));return{headRootSlug:ne.row.slug,rows:fe}}).filter(ne=>ne.rows.length>0);return{section:Q,heads:be,headChoices:ae}}).filter(Q=>Q.heads.length>0).map(({section:Q,heads:ae,headChoices:be})=>t.jsx(Xn,{section:Q,children:ae.map(({headRootSlug:ne,rows:fe},he)=>t.jsxs("div",{"data-testid":"backlog-head-group",children:[ae.length>1&&t.jsxs("div",{className:"px-[18px] pt-2.5 pb-1 text-[11px] font-mono uppercase tracking-wide text-fg-faint bg-bg-elev/30 border-t border-line/60","data-testid":"backlog-head-label",children:["Plan ",he+1," of ",ae.length]}),fe.map(({node:de,listIndex:hs})=>t.jsx(ra,{job:de.row,backlog:de,eta:ps.get(de.row.slug)??null,elapsedMs:de.row.status==="running"&&de.row.startedAt?p-Date.parse(de.row.startedAt):null,avgDurationMs:F,listIndex:hs,hold:C.get(de.row.slug),onFocused:dt,headChoices:be.filter(gs=>gs.rootSlug!==ne)},de.row.slug))]},ne))},Q.epicId??"__none__"))})()}),We>0&&t.jsxs("button",{type:"button",onClick:()=>v(w=>!w),className:"w-full text-left text-[12px] text-fg-faint hover:text-fg-dim px-[18px] py-3 border-t border-line",title:m?"Re-collapse old/cleared completed":"Show all completed (incl. cleared and >24h)",children:[m?"▾":"▸"," ",We," more completed",t.jsx("span",{className:"ml-1.5 font-mono text-[11.5px] text-fg-faint",children:"· fresh & capped at 5 shown inline"}),h.size>0&&t.jsx("span",{className:"ml-2 underline",onClick:w=>{w.stopPropagation(),gt()},children:"un-hide"})]})]}),oe&&!pt&&t.jsx("div",{className:Ae,children:t.jsxs("div",{className:"flex gap-2.5 bg-sage/10 border border-sage/30 rounded-xl px-3.5 py-2.5 text-[13.5px] text-fg-dim leading-relaxed",children:[t.jsx("span",{"aria-hidden":"true",children:"✓"}),t.jsxs("span",{children:[t.jsx("strong",{className:"font-semibold text-fg",children:"Nothing needed from you."})," ","Close the app if you like — jobs keep running, and History shows how each one ended."]})]})})]}),t.jsx(pa,{health:o,jobCount:ee.length,lastRunAt:os,nextReset:ds,now:p,onOpenSupervisor:()=>P("supervisor")})]})}function ja(e){const s=new Map(e.map(l=>[l.slug,l])),n=l=>(l.dependsOn??[]).filter(i=>{var r;return((r=s.get(i))==null?void 0:r.status)!=="completed"}).length,a=e.filter(l=>l.status==="running"||l.status==="pending").sort((l,i)=>n(l)-n(i)||l.slug.localeCompare(i.slug)),d=new Map;return a.forEach((l,i)=>d.set(l.slug,i)),d}function ya(e,s,n,a){if(a)return{inline:e,collapsedCount:0};const d=e.filter(c=>c.status==="completed").sort((c,p)=>{const u=c.finishedAt?Date.parse(c.finishedAt):0;return(p.finishedAt?Date.parse(p.finishedAt):0)-u}),l=new Set;let i=0;for(const c of d){if(i>=fa)break;s.has(c.slug)||c.finishedAt&&n-Date.parse(c.finishedAt)>ha||(l.add(c.slug),i++)}const r=[];let o=0;for(const c of e){if(c.status==="failed"&&s.has(c.slug)){o++;continue}if(c.status!=="completed"){r.push(c);continue}l.has(c.slug)?r.push(c):o++}return{inline:r,collapsedCount:o}}function Na(e,s,n,a,d,l){const i=new Map;if(d==="paused"||d==="manual"||d==="auto-throttled"){for(const c of e)i.set(c.slug,null);return i}const r=s.find(c=>c.status==="running"&&c.startedAt),o=r!=null&&r.startedAt?l-Date.parse(r.startedAt):0;for(const c of e){if(c.status!=="pending"){i.set(c.slug,null);continue}const p=n.get(c.slug)??0;let u=p*a;p>0&&(u-=Math.min(a,o)),i.set(c.slug,u<=5e3?"~now":`~${Ce(u)}`)}return i}const as=[{label:"All",value:"all"},{label:"Running",value:"running"},{label:"Investigating",value:"investigating"},{label:"Pending",value:"pending"},{label:"Completed",value:"completed"},{label:"Skipped",value:"skipped"},{label:"Needs review",value:"needs_review"},{label:"Failed",value:"failed"},{label:"Quarantined",value:"quarantined"}];function ka({jobCount:e,counts:s,filter:n,onFilter:a,hiddenInGraph:d,onUnhideAll:l,hasInlineCompleted:i,onClearCompleted:r,onClearQueue:o,clearQueueDisabled:c}){const p="block w-full text-left px-2 py-1 text-[12px] hover:bg-bg-hi disabled:opacity-40 disabled:cursor-not-allowed bg-transparent border-0 cursor-pointer";return t.jsxs(t.Fragment,{children:[t.jsxs("span",{className:"font-mono text-[11.5px] text-fg-faint whitespace-nowrap","data-testid":"plan-tools-counts",children:[e," job",e!==1?"s":""," · ",s.pending,"p · ",s.running,"r · ",s.completed,"d",s.failed>0&&t.jsxs("span",{className:"text-accent",children:[" · ",s.failed,"f"]})]}),d>0&&t.jsxs("button",{type:"button",onClick:l,className:"text-[12px] text-fg-faint hover:text-fg-dim underline bg-transparent border-0 cursor-pointer whitespace-nowrap",title:"Show the completed/failed jobs hidden by Clear completed",children:[d," hidden · un-hide"]}),t.jsx("select",{"data-testid":"scheduler-status-filter","aria-label":"Filter by status",value:n.status,onChange:u=>a({...n,status:u.target.value}),className:"bg-bg-hi border border-line rounded px-1 py-0.5 text-[12px] text-fg-dim",title:"Filter the plan graph by job status",children:as.map(u=>t.jsx("option",{value:u.value,children:u.value==="all"?"all statuses":u.label.toLowerCase()},u.value))}),t.jsx(me,{title:"Queue actions",testId:"plan-tools-menu",popoverTestId:"plan-tools-menu-popover",alignRight:!0,glyph:"⋯",widthCls:"w-52",children:t.jsxs("div",{className:"-mx-3 -my-2",children:[i&&t.jsx("button",{type:"button",onClick:r,className:`${p} text-fg-dim`,title:"Hide completed jobs from this view (queue.json unchanged — they remain in history)",children:"Clear completed"}),t.jsx("button",{type:"button",onClick:o,disabled:c,className:`${p} text-accent`,title:"Archive every non-running PRD (moved to prds-archived/<timestamp>/) and remove them from the queue. Running jobs are kept.",children:"Archive & clear queue…"})]})})]})}function Sa({filter:e,onChange:s,showText:n}){const a=as;return t.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[n&&t.jsxs("div",{className:"relative flex-1 min-w-[200px] max-w-[320px]",children:[t.jsx("span",{className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-fg-faint inline-flex","aria-hidden":"true",children:t.jsx(nt,{name:"search",size:15})}),t.jsx("input",{type:"text",value:e.text,onChange:d=>s({...e,text:d.target.value}),placeholder:"filter jobs…",className:"w-full bg-bg-hi border border-line rounded-xl py-2 pl-9 pr-3 text-[13.5px] text-fg placeholder:text-fg-faint focus:outline-none focus:border-fg-faint","aria-label":"Filter jobs by title, slug, or project"})]}),t.jsx(Yt,{options:a,value:e.status,onChange:d=>s({...e,status:d})})]})}const Ca=new Set(["discussion","portfolio"]);new Set(As.map(e=>e.tag).filter(e=>!Ca.has(e)));const $a=["title","cwd","estimateMinutes","parallelGroup","sourcePromptId","sourceTabId","tag","agentType","dependsOn","disposition","planId"];function Pa(e,s){return!Array.isArray(e)||!Array.isArray(s)?!1:e.length===s.length&&e.every((n,a)=>n===s[a])}function Da(e){if(e==null)return"";if(typeof e=="boolean"||typeof e=="number")return String(e);const s=String(e);return s===""||/^(true|false|null|~)$/.test(s)||/^-?\d+(\.\d+)?$/.test(s)||/^\s|\s$/.test(s)||s.startsWith("'")||s.startsWith('"')||s.includes(`
|
|
8
|
+
`)?s.includes("'")?`"${s.replace(/"/g,'\\"')}"`:`'${s}'`:s}function Aa(e,s){var d;const n=[];for(const l of $a){const i=e[l];if(i==null||i===""||Array.isArray(i)&&i.length===0)continue;const r=(d=e._raw)==null?void 0:d[l];if(r&&(Array.isArray(i)?Pa(r.parsed,i):r.parsed===i)){n.push(r.line);continue}if(typeof i=="number"){n.push(`${l}: ${i}`);continue}if(Array.isArray(i)){n.push(`${l}: [${i.join(", ")}]`);continue}n.push(`${l}: ${Da(i)}`)}if(e.extras)for(const l of Object.keys(e.extras)){const i=e.extras[l];!i||!i.lines.length||n.push(i.lines.join(`
|
|
9
|
+
`))}return`---
|
|
10
|
+
${n.join(`
|
|
11
|
+
`)}
|
|
12
|
+
---
|
|
13
|
+
${s}`}function Ye(e){return e.filter(s=>!s.archived)}function Ra(e){at(e),window.dispatchEvent(new CustomEvent("sm:navigate",{detail:"terminal"}))}function Je({label:e,tip:s,onClick:n,disabled:a,primary:d}){return t.jsx(Is,{content:s,align:"bottom-center",children:t.jsx("button",{title:s,onClick:n,disabled:a,className:`px-2 py-0.5 text-xs rounded border disabled:opacity-40 disabled:cursor-not-allowed ${d?"text-accent border-accent/50 hover:bg-bg-hi":"text-fg-dim border-line hover:text-fg hover:bg-bg-hi"}`,children:e})})}function Ma({scopeCwd:e=null}){const[s,n]=f.useState([]),[a,d]=f.useState(null),[l,i]=f.useState(null),[r,o]=f.useState(null),[c,p]=f.useState(!1),[u,h]=f.useState(!0),[g,m]=f.useState(new Set),[v,y]=f.useState(!1),[k,S]=f.useState(!1),[T,x]=f.useState(!1),[R,P]=f.useState(null);f.useEffect(()=>{let b=!0;return window.api.schedule.listPrds().then(j=>{b&&(n(Ye(j)),h(!1))}).catch(j=>{b&&(h(!1),H.error(`Scheduler: failed to load PRD list — ${j instanceof Error?j.message:"unknown error"}`))}),()=>{b=!1}},[]);const D=Fe(b=>b.snapshot),O=pe(b=>b.sessions);f.useEffect(()=>{D&&d(D)},[D]);const J=f.useMemo(()=>[...s].filter(b=>!e||b.cwd===e).sort((b,j)=>j.mtimeMs-b.mtimeMs||b.slug.localeCompare(j.slug)),[s,e]);f.useEffect(()=>{const b=Ms();b&&i(b);const j=A=>i(A.detail);return window.addEventListener("sm:select-prd",j),()=>window.removeEventListener("sm:select-prd",j)},[]);const W=f.useMemo(()=>(a==null?void 0:a.jobs.find(b=>b.slug===l))??null,[a,l]),z=vt(W);function K(b){var A;const j=(A=s.find($=>$.slug===b))==null?void 0:A.cwd;return j?`${j}/session-manager-operations/scheduler/prds/${b}.md`:null}f.useEffect(()=>{if(!l)return;const b=K(l);b&&jt.getState().openFile(b)},[l,s]);function X(b){i(b),o(null),p(!1)}function se(){i(null)}async function Y(){if(!l)return;if(!(W!=null&&W.runId)){o("no log available (job has not run yet)"),p(j=>!j);return}const b=await window.api.schedule.readLog(W.runId,l);o(b.ok?b.text??"":`error: ${b.error}`),p(j=>!j)}if(u)return t.jsx(ke,{title:"loading PRDs…"});const M=b=>{m(j=>{const A=new Set(j);return A.has(b)?A.delete(b):A.add(b),A})};!(J.length>0&&J.every(b=>g.has(b.slug)))&&J.some(b=>g.has(b.slug));const N=()=>m(new Set);async function C(){try{const b=await window.api.schedule.listPrds();n(Ye(b))}catch{}}async function q(){const b=`new-prd-${Date.now()}`,j=Aa({title:"New PRD",cwd:"",estimateMinutes:60,parallelGroup:99},`## Task
|
|
14
|
+
|
|
15
|
+
Describe the task here.
|
|
16
|
+
`);try{const A=await window.api.schedule.writePrd(b,j);if(!A.ok){H.error(`Failed to create PRD: ${A.error}`);return}const $=await window.api.schedule.listPrds();n(Ye($)),X(b)}catch(A){H.error(`Failed to create PRD: ${A instanceof Error?A.message:String(A)}`)}}async function V(){var b;x(!0),P(null);try{const j=[...g],A=await window.api.schedule.archivePrds(j);if(!A.ok)P(A.error??"archive failed");else{const $=((b=A.results)==null?void 0:b.filter(I=>!I.ok))??[];$.length>0&&H.warn(`Archive: ${$.length} of ${A.results.length} PRD${$.length===1?"":"s"} failed to move`),N(),y(!1),await C()}}catch(j){P(j instanceof Error?j.message:String(j))}finally{x(!1)}}async function U(b,j){x(!0),P(null);try{const A=[];for(const I of g){const L={slug:I};b!==null&&(L.parallelGroup=b),j!==null&&(L.estimateMinutes=j),A.push(L)}const $=await window.api.schedule.retagPrds(A);if(!$.ok)P($.error??"retag failed");else{N(),S(!1),await C();for(const I of $.results)if(I.newSlug&&I.newSlug!==I.slug){const L=K(I.slug),_=K(I.newSlug);L&&_&&jt.getState().renameOpenFile(L,_)}l&&$.results.some(I=>I.slug===l&&I.newSlug&&I.newSlug!==I.slug)&&i(null)}}catch(A){P(A instanceof Error?A.message:String(A))}finally{x(!1)}}return t.jsxs(t.Fragment,{children:[l?t.jsxs("div",{className:"h-full flex flex-col min-h-0",children:[t.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 border-b border-line flex-wrap shrink-0",children:[t.jsx("button",{type:"button",onClick:se,className:"text-[11px] text-fg-faint hover:text-fg",children:"← PRDs"}),t.jsx("span",{className:"font-mono text-xs text-fg-dim truncate",children:l}),t.jsx(yt,{status:z}),t.jsx("div",{className:"flex-1"}),t.jsx(Je,{label:"Reset",tip:"Reset failed job to pending",onClick:()=>{var b;window.api.schedule.resetJob(l,((b=s.find(j=>j.slug===l))==null?void 0:b.cwd)||void 0)},disabled:z!=="failed"}),t.jsx(Je,{label:"Run now",tip:"Run all pending jobs immediately",onClick:()=>{Nt()}}),t.jsx(Je,{label:c?"Hide log":"Last run log",tip:"Toggle most recent run log",onClick:Y})]}),t.jsx("div",{className:"flex-1 min-h-0",children:t.jsx(Rs,{})}),c&&r!==null&&t.jsxs("div",{className:"border-t border-line max-h-64 overflow-auto bg-bg-elev",children:[t.jsxs("div",{className:"px-3 py-1.5 flex items-center gap-2 border-b border-line sticky top-0 bg-bg-elev",children:[t.jsxs("span",{className:"text-[10px] text-fg-faint font-mono",children:["run log",W!=null&&W.runId?` — ${W.runId}`:""]}),t.jsx("button",{onClick:()=>p(!1),className:"ml-auto text-[10px] text-fg-faint hover:text-fg",children:"close"})]}),t.jsx("pre",{className:"p-3 text-[11px] font-mono text-fg-dim whitespace-pre-wrap",children:r})]})]}):t.jsxs("div",{className:"px-6 py-5 overflow-auto",children:[t.jsxs("div",{className:"flex items-start justify-between mb-5 gap-4",children:[t.jsxs("p",{className:"text-[14px] text-fg-dim leading-relaxed max-w-[560px]",children:["PRDs are the source the scheduler runs from. Each one becomes a"," ",t.jsx("code",{className:"font-mono text-[13px]",children:"claude -p"})," job when you queue it. This is where you write and edit the source — to watch a run in progress, use the Queue tab."]}),t.jsx("button",{type:"button",onClick:q,className:"shrink-0 bg-accent text-white rounded-lg px-4 py-[9px] text-[13.5px] font-semibold leading-none",children:"+ New PRD"})]}),g.size>0&&t.jsxs("div",{className:"mb-4 px-4 py-2 bg-bg border border-line rounded-lg flex items-center gap-2",children:[t.jsxs("span",{className:"text-xs text-fg-dim",children:[g.size," selected"]}),t.jsx("div",{className:"flex-1"}),t.jsx("button",{type:"button",onClick:()=>y(!0),className:"text-xs px-3 py-1.5 rounded border border-line text-fg-dim hover:text-fg hover:bg-bg-hi",children:"Archive…"}),t.jsx("button",{type:"button",onClick:()=>S(!0),className:"text-xs px-3 py-1.5 rounded border border-line text-fg-dim hover:text-fg hover:bg-bg-hi",children:"Retag…"}),t.jsx("button",{type:"button",onClick:N,className:"text-xs px-3 py-1.5 rounded border border-line text-fg-dim hover:text-fg hover:bg-bg-hi",children:"Clear"})]}),J.length===0?t.jsx(ke,{title:"no PRDs found"}):t.jsx("div",{className:"grid gap-3",children:J.map(b=>{const j=a==null?void 0:a.jobs.find(_=>_.slug===b.slug),A=vt(j),$=Pe({epicId:b.epicId??(j==null?void 0:j.epicId)??null,sourcePromptId:b.sourcePromptId??(j==null?void 0:j.sourcePromptId)??null,sourceTabId:(j==null?void 0:j.sourceTabId)??null},O),I=(j==null?void 0:j.status)==="running",L=(j==null?void 0:j.status)==="needs_review";return t.jsxs("div",{className:"flex items-stretch bg-bg-elev border border-line rounded-2xl overflow-hidden",children:[t.jsx("label",{className:"flex items-center px-3 cursor-pointer hover:bg-bg-hi",children:t.jsx("input",{type:"checkbox",checked:g.has(b.slug),onChange:()=>M(b.slug),className:"accent-accent w-3.5 h-3.5"})}),t.jsxs("div",{className:"flex-1 min-w-0 py-4 pr-2",children:[t.jsxs("div",{className:"flex items-center gap-2.5 mb-[5px] flex-wrap",children:[ie(b.slug)&&t.jsx(Lt,{n:ie(b.slug)}),t.jsx("button",{type:"button",onClick:()=>X(b.slug),className:"font-serif text-[18px] font-semibold text-fg leading-tight hover:underline text-left",children:b.title||b.slug}),t.jsx(yt,{status:A}),(j==null?void 0:j.status)&&t.jsx("span",{className:"sr-only",children:j.status})]}),t.jsxs("div",{className:"flex items-center gap-4 font-mono text-xs text-fg-faint flex-wrap",children:[t.jsx(it,{cwd:b.cwd}),t.jsx(rt,{epicId:$.epicId,label:$.label,onOpen:Ra}),b.estimateMinutes!=null&&t.jsxs("span",{children:[b.estimateMinutes,"m"]}),t.jsxs("span",{className:"opacity-60",title:"parallelGroup — a unique-per-PRD display hint, never an ordering barrier. dependsOn is the real ordering primitive.",children:["g",b.parallelGroup]}),b.dependsOn&&b.dependsOn.length>0&&t.jsxs("span",{title:`depends on: ${b.dependsOn.join(", ")}`,children:["⛓ ",b.dependsOn.length," dep",b.dependsOn.length===1?"":"s"]}),t.jsxs("span",{children:["edited ",xe(b.mtimeMs,Date.now())]})]}),t.jsx("button",{type:"button",onClick:()=>X(b.slug),className:"mt-1.5 font-mono text-[11px] text-fg-faint hover:text-fg-dim leading-none",children:b.slug}),L&&t.jsxs("div",{className:"mt-3 space-y-2",children:[(j==null?void 0:j.verifierVerdict)&&t.jsxs("div",{className:"text-xs text-fg-faint",children:["verdict: ",t.jsx("span",{className:"font-mono",children:$e(j.verifierVerdict)})]}),t.jsx("button",{type:"button",onClick:()=>window.api.schedule.resetJob(b.slug,b.cwd||void 0),className:"text-xs px-2.5 py-1 rounded border border-line text-fg-dim hover:text-fg hover:bg-bg-hi",children:"Re-fire"})]})]}),t.jsx("div",{className:"flex flex-col gap-2 items-stretch px-[18px] py-4",children:t.jsx("button",{type:"button",onClick:()=>{Nt()},disabled:I,className:"bg-fg text-bg rounded-lg px-[18px] py-2 text-[13px] font-semibold whitespace-nowrap disabled:opacity-50",children:I?"Running…":"Queue job"})})]},b.slug)})})]}),t.jsx(Ia,{open:v,count:g.size,busy:T,onClose:()=>y(!1),onConfirm:V}),t.jsx(Ea,{open:k,count:g.size,busy:T,onClose:()=>S(!1),onConfirm:U})]})}function Ia({open:e,count:s,busy:n,onClose:a,onConfirm:d}){return t.jsxs(Gt,{open:e,onClose:a,title:"Archive PRDs",children:[t.jsxs("p",{className:"text-xs text-fg-dim",children:["Move ",t.jsx("span",{className:"font-mono",children:s})," PRD",s===1?"":"s"," to"," ",t.jsx("span",{className:"font-mono",children:"prds-archived/<timestamp>/"}),"?"]}),t.jsx("p",{className:"text-[10px] text-fg-faint mt-2",children:"Files are renamed, never deleted. Restore manually from disk if needed."}),t.jsxs("div",{className:"flex justify-end gap-2 mt-4",children:[t.jsx("button",{type:"button",onClick:a,disabled:n,className:"px-2 py-1 text-xs border border-line rounded text-fg-dim hover:text-fg disabled:opacity-40",children:"Cancel"}),t.jsx("button",{type:"button",onClick:d,disabled:n||s===0,className:"px-2 py-1 text-xs border border-accent/60 text-accent rounded hover:bg-bg-hi disabled:opacity-40",children:n?"Archiving…":`Archive ${s}`})]})]})}function Ea({open:e,count:s,busy:n,onClose:a,onConfirm:d}){const[l,i]=f.useState(""),[r,o]=f.useState(""),[c,p]=f.useState(null);f.useEffect(()=>{e&&(i(""),o(""),p(null))},[e]);function u(){p(null);let h=null,g=null;if(l.trim()){const m=Number(l);if(!Number.isInteger(m)||m<0||m>999){p("parallelGroup must be 0–999");return}h=m}if(r.trim()){const m=Number(r);if(!Number.isInteger(m)||m<=0){p("estimateMinutes must be a positive integer");return}g=m}if(h===null&&g===null){p("set at least one field");return}d(h,g)}return t.jsxs(Gt,{open:e,onClose:a,title:"Retag PRDs",children:[t.jsxs("p",{className:"text-xs text-fg-dim",children:["Update ",t.jsx("span",{className:"font-mono",children:s})," PRD",s===1?"":"s",". Leave a field blank to keep its current value."]}),t.jsxs("p",{className:"text-[10px] text-fg-faint mt-2",children:["Changing parallelGroup on an ",t.jsx("span",{className:"font-mono",children:"NN-kebab"})," slug renames the file. Every change is logged to ",t.jsx("span",{className:"font-mono",children:"retag-log.jsonl"})," so it's reversible."]}),t.jsxs("div",{className:"mt-3 space-y-2",children:[t.jsxs("label",{className:"flex items-center gap-2 text-xs",children:[t.jsx("span",{className:"w-32 text-fg-faint",children:"parallelGroup:"}),t.jsx("input",{type:"number",min:0,max:999,value:l,onChange:h=>i(h.target.value),placeholder:"(unchanged)",className:"flex-1 bg-bg border border-line rounded px-2 py-1 font-mono text-xs"})]}),t.jsxs("label",{className:"flex items-center gap-2 text-xs",children:[t.jsx("span",{className:"w-32 text-fg-faint",children:"estimateMinutes:"}),t.jsx("input",{type:"number",min:1,value:r,onChange:h=>o(h.target.value),placeholder:"(unchanged)",className:"flex-1 bg-bg border border-line rounded px-2 py-1 font-mono text-xs"})]})]}),c&&t.jsx("div",{className:"mt-2 text-[10px] text-red-300",children:c}),t.jsxs("div",{className:"flex justify-end gap-2 mt-4",children:[t.jsx("button",{type:"button",onClick:a,disabled:n,className:"px-2 py-1 text-xs border border-line rounded text-fg-dim hover:text-fg disabled:opacity-40",children:"Cancel"}),t.jsx("button",{type:"button",onClick:u,disabled:n||s===0,className:"px-2 py-1 text-xs border border-accent/60 text-accent rounded hover:bg-bg-hi disabled:opacity-40",children:n?"Retagging…":`Retag ${s}`})]})]})}function Ta(e){at(e),window.dispatchEvent(new CustomEvent("sm:navigate",{detail:"terminal"}))}function It(e){return e?e.slice(0,10):""}const _a=[{value:"all",label:"All"},{value:"completed",label:"Completed"},{value:"skipped",label:"Skipped"},{value:"failed",label:"Failed"}];function Oa({scopeCwd:e=null}){const[s,n]=f.useState(null),[a,d]=f.useState(!0),[l,i]=f.useState(""),[r,o]=f.useState(""),[c,p]=f.useState(""),[u,h]=f.useState("all");f.useEffect(()=>{d(!0),window.api.schedule.getHistory().then(y=>n(y)).catch(y=>n({ok:!1,jobs:[],error:y instanceof Error?y.message:String(y)})).finally(()=>d(!1))},[]);const g=f.useMemo(()=>{if(!(s!=null&&s.jobs))return[];const y=new Set;for(const k of s.jobs){const S=_e(k.cwd);S&&y.add(S)}return[...y].sort()},[s]),m=f.useMemo(()=>s!=null&&s.jobs?s.jobs.filter(y=>!(e&&y.cwd!==e||u!=="all"&&y.status!==u||l&&_e(y.cwd)!==l||r&&It(y.finishedAt)<r||c&&It(y.finishedAt)>c)):[],[s,u,l,r,c,e]);if(a)return t.jsx(ke,{title:"Loading history…"});if(!(s!=null&&s.ok)||s.error)return t.jsxs("div",{className:"p-4 text-xs text-red-300",children:["Failed to load history: ",(s==null?void 0:s.error)??"unknown error"]});if(s.jobs.length===0)return t.jsx(ke,{title:"No history yet",hint:"Completed and failed jobs appear here."});const v=u!=="all"||!!l||!!r||!!c;return t.jsxs("div",{className:"h-full flex flex-col",children:[t.jsxs("div",{className:"shrink-0 flex items-center gap-2 px-4 py-2.5 border-b border-line flex-wrap",children:[t.jsx(Yt,{options:_a,value:u,onChange:h,pillPadding:"px-3 py-1"}),t.jsx("span",{className:"w-px h-4 bg-line mx-1","aria-hidden":"true"}),g.length>0&&t.jsxs("select",{value:l,onChange:y=>i(y.target.value),className:"bg-bg-hi border border-line rounded-lg px-2 py-1 text-[12.5px] text-fg-dim max-w-[12rem] font-medium",children:[t.jsx("option",{value:"",children:"All projects"}),g.map(y=>t.jsx("option",{value:y,children:y},y))]}),t.jsxs("div",{className:"flex items-center gap-1.5 text-[12px] text-fg-faint",children:[t.jsx("span",{children:"from"}),t.jsx("input",{type:"date",value:r,onChange:y=>o(y.target.value),className:"bg-bg-hi border border-line rounded-lg px-2 py-1 text-fg-dim font-mono text-[12px]"})]}),t.jsxs("div",{className:"flex items-center gap-1.5 text-[12px] text-fg-faint",children:[t.jsx("span",{children:"to"}),t.jsx("input",{type:"date",value:c,onChange:y=>p(y.target.value),className:"bg-bg-hi border border-line rounded-lg px-2 py-1 text-fg-dim font-mono text-[12px]"})]}),t.jsxs("span",{className:"text-[12px] text-fg-faint ml-auto font-mono",children:[m.length," / ",s.jobs.length]}),v&&t.jsx("button",{type:"button",onClick:()=>{h("all"),i(""),o(""),p("")},className:"text-[12px] text-fg-faint hover:text-fg-dim underline",children:"clear"})]}),t.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto",children:m.length===0?t.jsx(ke,{title:"No matches",hint:"Try adjusting the filters."}):t.jsxs("div",{className:"mx-4 my-3 bg-bg-hi border border-line rounded-2xl overflow-hidden",children:[t.jsx("div",{className:"flex items-center px-[18px] py-3 bg-bg-elev",children:t.jsxs("span",{className:"font-serif text-base font-semibold text-fg",children:[m.length," job",m.length!==1?"s":""]})}),m.map(y=>t.jsx(La,{job:y},`${y.slug}-${y.finishedAt??""}`))]})})]})}function La({job:e}){const[s,n]=f.useState(!1),[a,d]=f.useState(!1),l=pe(h=>h.sessions),i=f.useMemo(()=>Pe(e,l),[e,l]),r=e.startedAt&&e.finishedAt?Date.parse(e.finishedAt)-Date.parse(e.startedAt):null,o=e.startedAt?new Date(e.startedAt).toLocaleString():"—",c=e.finishedAt?new Date(e.finishedAt).toLocaleString():"—",p=r!==null?Ce(r):"—",u=e.exitCode!==null?String(e.exitCode):"—";return t.jsxs("div",{className:"border-t border-line/60",children:[t.jsxs("button",{type:"button",className:`w-full text-left grid items-center gap-4 px-[18px] py-3.5 cursor-pointer transition-colors hover:bg-bg-elev ${s?"bg-bg-elev":"bg-transparent"}`,style:{gridTemplateColumns:"116px 1fr auto auto"},onClick:()=>n(h=>!h),"aria-expanded":s,children:[t.jsx(Ot,{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 text-pretty",children:[e.title,t.jsx(Ft,{leaked:e.leakedDescendants})]}),e.error&&!s&&(e.status==="failed"||e.status==="needs_review")&&t.jsx("div",{className:"text-[12.5px] mt-0.5 text-accent/80 truncate",children:e.error}),i.epicId&&t.jsx("span",{className:"flex mt-0.5",children:t.jsx(rt,{epicId:i.epicId,label:i.label,onOpen:Ta})})]}),t.jsx(it,{cwd:e.cwd}),t.jsxs("span",{className:"inline-flex items-center gap-2.5 font-mono text-xs text-fg-faint whitespace-nowrap",children:[p,t.jsx("span",{className:"inline-flex transition-transform duration-150",style:{transform:s?"rotate(90deg)":"none"},"aria-hidden":"true",children:"›"})]})]}),s&&t.jsxs("div",{className:"grid gap-5 px-[18px] pt-1 pb-5 bg-bg-elev",style:{gridTemplateColumns:"repeat(auto-fit, minmax(160px, 1fr))"},children:[t.jsxs(re,{label:"Status",children:[t.jsx(B,{k:"result",v:u}),t.jsx(B,{k:"state",v:e.status.replace("_"," ")}),e.verifierVerdict&&t.jsx(B,{k:"verifier",v:$e(e.verifierVerdict)}),e.leakedDescendants&&e.leakedDescendants.length>0&&t.jsx(B,{k:"leaked",v:qt(e.leakedDescendants),wrap:!0})]}),t.jsxs(re,{label:"Timing",children:[t.jsx(B,{k:"started",v:o}),t.jsx(B,{k:"finished",v:c}),t.jsx(B,{k:"duration",v:p})]}),t.jsxs(re,{label:"Location",children:[t.jsx(B,{k:"group",v:e.parallelGroup!=null?String(e.parallelGroup):"—"}),t.jsx(B,{k:"slug",v:e.slug}),t.jsx(B,{k:"epic",v:i.label??i.epicId??"—",wrap:!0}),e.cwd&&t.jsx(B,{k:"cwd",v:e.cwd,wrap:!0})]}),t.jsx(re,{label:"Actions",children:t.jsxs("div",{className:"flex flex-col gap-2 items-start",children:[e.runId&&t.jsx("button",{type:"button",onClick:h=>{h.stopPropagation(),d(!0)},className:"text-[13px] font-semibold text-fg-dim hover:text-fg bg-transparent border-0 p-0 cursor-pointer",children:"view log →"}),e.status!=="pending"&&t.jsx("button",{type:"button",onClick:h=>{h.stopPropagation(),window.api.schedule.resetJob(e.slug,e.cwd??void 0)},className:"text-[13px] font-semibold text-fg-dim hover:text-fg bg-transparent border-0 p-0 cursor-pointer",children:"reset to pending →"}),e.error&&t.jsx("p",{className:"text-[12px] text-accent/90 mt-1 break-words whitespace-pre-wrap max-w-sm m-0",children:e.error})]})})]}),a&&e.runId&&t.jsx(qe,{runId:e.runId,slug:e.slug,title:e.title||e.slug,onClose:()=>d(!1)})]})}function Fa(e){return e?Object.values(e).reduce((s,n)=>s+(n??[]).reduce((a,d)=>{var l;return a+(((l=d.hooks)==null?void 0:l.length)??0)},0),0):0}function qa(e){var s,n,a;return e?(((s=e.allow)==null?void 0:s.length)??0)+(((n=e.deny)==null?void 0:n.length)??0)+(((a=e.ask)==null?void 0:a.length)??0):0}function Ba({navigate:e}){const s=Es(),n=ye(x=>x.files),a=ye(x=>x.loadJson),d=ye(x=>x.loadText),l=ye(x=>x.watchFile),i=ye(x=>x.unwatchFile),r=s?Ts.resolve("user",s,null):null,o=s?_s.resolve("user",s,null):null,c=s?`${s}/.claude.json`:null;f.useEffect(()=>{const x=[r,c].filter(Boolean);x.forEach(P=>{n[P]||a(P),l(P)});const R=[o].filter(Boolean);return R.forEach(P=>{n[P]||d(P),l(P)}),()=>{[...x,...R].forEach(P=>i(P))}},[r,o,c]);const[p,u]=f.useState(null);f.useEffect(()=>{if(!s)return;let x=!1;return(async()=>{const{entries:R}=await Os(`${s}/.claude/skills`);x||u(R.length)})(),()=>{x=!0}},[s]);const h=r?n[r]:null,g=c?n[c]:null,m=o?n[o]:null,v=f.useMemo(()=>{if(!(h!=null&&h.exists)||h.parseError)return null;const x=h.diskData;return x===null||typeof x!="object"||Array.isArray(x)?{}:x},[h]),y=f.useMemo(()=>{if(!(g!=null&&g.exists)||g.parseError)return null;const x=g.diskData;return x===null||typeof x!="object"||Array.isArray(x)?{}:x},[g]),k=h?h.parseError?"invalid JSON":null:"loading…",S=g?g.parseError?"invalid JSON":null:"loading…",T=[{key:"settings",title:"Settings",summary:k??(v?`${Object.keys(v).length} top-level key${Object.keys(v).length===1?"":"s"} configured`:"not configured")},{key:"settings",tab:"permissions",title:"Permissions",summary:k??(v?`${qa(v.permissions)} rule(s) configured`:"not configured")},{key:"settings",tab:"hooks",title:"Hooks",summary:k??(v?`${Fa(v.hooks)} hook(s) configured`:"not configured")},{key:"extensions",tab:"mcp",title:"MCP Servers",summary:S??(y?`${Object.keys(y.mcpServers??{}).length} MCP server(s)`:"not configured")},{key:"system-prompt",title:"System Prompt",summary:m!=null&&m.exists&&m.diskRaw.trim().length>0?`configured (${m.diskRaw.length.toLocaleString()} chars)`:"not set"},{key:"extensions",tab:"skills",title:"Skills",summary:p===null?"loading…":`${p} skill(s) installed`}];return t.jsxs("section",{className:"border border-line rounded-xl bg-bg-hi px-5 py-4",children:[t.jsx("h2",{className:"m-0 mb-1 font-serif text-[18px] font-semibold text-fg",children:"Global Controls"}),t.jsx("p",{className:"mt-0 mb-3 text-[13px] text-fg-dim leading-relaxed",children:"Machine-wide (user-scope) config state for the tabs that default to global here on Home. Read-only summary — open a card to edit."}),t.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-3",children:T.map(x=>t.jsxs("button",{type:"button",onClick:()=>{x.tab&&Ls.getState().openPanel(x.key,x.tab),e==null||e(x.key)},className:"text-left border border-line rounded-lg bg-bg px-3 py-2.5 hover:border-accent transition-colors",children:[t.jsx("div",{className:"text-[13px] font-medium text-fg",children:x.title}),t.jsx("div",{className:"mt-0.5 text-[12px] text-fg-dim",children:x.summary})]},x.tab??x.key))})]})}function Ha({navigate:e}){const s=Tt(),[n,a]=f.useState(null);return f.useEffect(()=>{var l,i;let d=!0;return(i=(l=window.api.schedule).worktreeBase)==null||i.call(l).then(r=>{d&&a(r)}).catch(()=>{}),()=>{d=!1}},[]),t.jsxs("div",{className:"max-w-[760px] space-y-6",children:[t.jsx(Ba,{navigate:e}),t.jsxs("section",{className:"border border-line rounded-xl bg-bg-hi px-5 py-4",children:[t.jsx("h2",{className:"m-0 mb-1 font-serif text-[18px] font-semibold text-fg",children:"Session pool"}),t.jsxs("p",{className:"mt-0 mb-3 text-[13px] text-fg-dim leading-relaxed",children:["One machine-wide pool of concurrent Claude sessions. Scheduler jobs and Epic chat runs each request a slot before launching; work waits when the pool is full. Adjustable from 0 (pauses new launches) to ",(s==null?void 0:s.max)??10," on the Home tab, default 5 — or pin it with"," ",t.jsx("code",{className:"font-mono text-[12px]",children:"SM_SESSION_SLOTS"})," (clamped 0–",(s==null?void 0:s.max)??10,")."]}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(Fs,{total:(s==null?void 0:s.total)??5,inUse:(s==null?void 0:s.inUse)??0,size:"md"}),t.jsx("span",{className:"ml-2 font-mono text-[12.5px] text-fg-faint",children:s?`${s.inUse} / ${s.total} in use`:"loading…"})]}),s&&s.holders.length>0&&t.jsx("ul",{className:"mt-2 mb-0 pl-0 list-none space-y-0.5",children:s.holders.map((d,l)=>t.jsxs("li",{className:"font-mono text-[12px] text-fg-dim",children:[d.owner," ",t.jsxs("span",{className:"text-fg-faint",children:["since ",new Date(d.at).toLocaleTimeString()]})]},l))})]}),t.jsxs("section",{className:"border border-line rounded-xl bg-bg-hi px-5 py-4",children:[t.jsx("h2",{className:"m-0 mb-1 font-serif text-[18px] font-semibold text-fg",children:"On disk"}),t.jsxs("p",{className:"mt-0 mb-2 text-[13px] text-fg-dim leading-relaxed",children:["Global runtime state is deliberately small — everything project-scoped lives inside that project's ",t.jsx("code",{className:"font-mono text-[12px]",children:"session-manager-operations/"})," folder."]}),t.jsxs("ul",{className:"m-0 pl-0 list-none space-y-1 font-mono text-[12px] text-fg-dim",children:[t.jsxs("li",{children:["~/.claude/session-manager/scheduler-machine.json ",t.jsx("span",{className:"text-fg-faint",children:"— policy + pause state"})]}),t.jsxs("li",{"data-testid":"worktree-base-path",children:[n??"…","/session-manager-epic-worktrees/ ",t.jsx("span",{className:"text-fg-faint",children:"— Epic git worktrees (SM_WORKTREE_ROOT overrides)"})]}),t.jsxs("li",{children:["<project>/session-manager-operations/scheduler/state/ ",t.jsx("span",{className:"text-fg-faint",children:"— per-project queue + history"})]}),t.jsxs("li",{children:["<project>/session-manager-operations/scheduler/epics/<epic>/prds/ ",t.jsx("span",{className:"text-fg-faint",children:"— PRD sources, per session"})]})]})]})]})}const Et="sm.schedulerTab.subView";function Ga({navigate:e}={}){var m;const[s,n]=f.useState("graph"),[a,d]=f.useState(""),[l,i]=f.useState(null),[r,o]=f.useState(()=>{const v=localStorage.getItem(Et);return v==="prds"||v==="history"||v==="machine"?v:"queue"}),c=kt(v=>v.tabs),p=kt(v=>v.activeTabId),u=((m=c.find(v=>v.id===p))==null?void 0:m.cwd)??null,h=u;f.useEffect(()=>{u&&(pe.getState().hydrate(u),pe.getState().hydrateArchived(u))},[u]);const g=f.useCallback(v=>{v&&qs(v),o("prds")},[]);return f.useEffect(()=>{localStorage.setItem(Et,r)},[r]),t.jsxs("div",{className:"h-full flex flex-col",children:[t.jsx(wn,{scopeCwd:h,subView:r,onSubView:o,filterText:a,onFilterText:d,planMode:s,onPlanMode:n,planToolsRef:i}),t.jsxs("div",{className:"flex-1 min-h-0",children:[r==="queue"&&t.jsx(va,{scopeCwd:h,navigate:e,filterText:a,planMode:s,onOpenPrds:g,planToolsEl:l}),r==="prds"&&t.jsx(Ma,{scopeCwd:h}),r==="history"&&t.jsx(Oa,{scopeCwd:h}),r==="machine"&&t.jsx("div",{className:"h-full overflow-y-auto px-9 py-6",children:t.jsx(Ha,{navigate:e})})]})]})}const za=f.memo(Ga);export{za as Scheduler};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{b3 as T,at as e,a$ as A,aJ as j,b9 as L,b0 as V,bb as z,bi as H,P as ce,l as C,a3 as de,v as ue,Q as Y,S,a as pe,bk as B,be as me,ax as xe,aB as he,J as fe,ap as ge}from"./index-DfWJO7nP.js";import{P as F}from"./Panel-OUbLHNsS.js";import{P as be,H as ye,S as Z}from"./Library-BGmD-xZN.js";import{S as I}from"./SourceChip-C2YMnlV8.js";import{V as U}from"./ViewTabs-BYrRSHb6.js";import{r as Q}from"./claude-settings-schema-COigsajx.js";import{L as je}from"./ListDetail-BeO3lY8t.js";import{P as ve}from"./ProvenanceBadge-kr7arZqu.js";import"./monaco-editor-BsIlgG7c.js";import"./Button-fOCJry21.js";function ke(t){const s=t??{},n={...s.$defs??{},...s.definitions??{}},a=i=>{if(!i)return{};if(!i.$ref)return l(i);const d=/^#\/(\$defs|definitions)\/(.+)$/.exec(i.$ref);if(!d)return l(i);const h=n[d[2]];return h?a({...h,...p(i)}):l(i)},o=new Set(["__proto__","constructor","prototype"]),r=i=>{if(!i)return{};const d={};for(const[h,g]of Object.entries(i))o.has(h)||(d[h]=g);return d},l=i=>{if(!i.allOf||i.allOf.length===0)return i;const d={...i};delete d.allOf;for(const h of i.allOf){const g=a(h);Object.assign(d,{properties:{...r(d.properties),...r(g.properties)},required:we([...d.required??[],...g.required??[]])}),!d.description&&g.description&&(d.description=g.description),d.default===void 0&&g.default!==void 0&&(d.default=g.default),!d.type&&g.type&&(d.type=g.type)}return d},p=i=>{const{$ref:d,...h}=i;return h},u=(i,d)=>{let h=a(i);for(const g of d){if(!h)return null;if(/^\d+$/.test(g)){const k=Array.isArray(h.items)?h.items[Number(g)]:h.items;h=k?a(k):null;continue}const N=h.properties;if(N&&!o.has(g)&&g in N){h=a(N[g]);continue}const b=h.additionalProperties;if(b&&typeof b=="object"){h=a(b);continue}return null}return h},c=(i,d,h)=>{if(!i)return null;const g={};if(i.description&&(g.description=i.description),i.type&&(g.type=i.type),i.default!==void 0&&(g.default=i.default),i.enum&&(g.enum=i.enum),i.const!==void 0&&(g.const=i.const),i.deprecated&&(g.deprecated=!0),i.examples&&(g.examples=i.examples),i.properties&&(g.knownChildren=Object.keys(i.properties)),h&&(d!=null&&d.includes(h))&&(g.required=!0),i.items&&!Array.isArray(i.items)){const N=a(i.items),b=c(N,void 0,null);b&&(g.itemsInfo=b)}return(i.additionalProperties===!0||typeof i.additionalProperties=="object")&&(g.open=!0),g},x=i=>d=>{if(d.length===0)return c(a(i),void 0,null);const h=u(i,d.slice(0,-1));if(!h)return null;const g=d[d.length-1],N=u(h,[g]);return c(N,h.required,g)},v=i=>{const d=a(i);return Object.keys(d.properties??{})},f=i=>({at:x(i),rootKeys:()=>v(i),rootedAt:d=>{const h=u(i,d);return f(h??{})}});return f(s)}function we(t){return Array.from(new Set(t))}let D=null;function X(){return D||(D=ke(Q)),D}const Ne=["allow","deny","ask"],J="This settings file has invalid JSON. Fix it in the Settings raw editor first; Permissions will not overwrite it.";function Se(t){if(t.trim()==="")return{perms:{},full:{},err:null};try{const s=JSON.parse(t);if(s===null||typeof s!="object"||Array.isArray(s))return{perms:{},full:{},err:"settings file is not a JSON object"};const n=s;return{perms:n.permissions??{},full:n,err:null}}catch(s){return{perms:{},full:{},err:s.message}}}function Ce({scope:t="user"}={}){const s=L(),n=V(),a=(n==null?void 0:n.cwd)??null,o=z(i=>i.navFace),[r,l]=j.useState("rules");j.useEffect(()=>{o==="project"&&r==="presets"&&l("rules")},[o,r]);const u=H(ce,s,a)[t]??null,c=T(i=>i.files),x=e.jsx(U,{options:[{key:"rules",label:"Rules"},...o==="home"?[{key:"presets",label:"Presets"}]:[]],active:r,onChange:l});if(!s)return e.jsx(C,{title:"loading…"});if(r==="presets")return e.jsx(F,{toolbar:x,children:e.jsx(be,{})});const v=i=>i!=="user"&&!a,f=u?c[u]:null;return e.jsx(F,{toolbar:e.jsxs(e.Fragment,{children:[x,e.jsx("span",{className:"ml-3 text-fg-faint truncate",children:u??"—"}),e.jsx("div",{className:"flex-1"}),e.jsx("a",{href:"https://code.claude.com/docs/en/settings#permissions",target:"_blank",rel:"noreferrer",className:"text-fg-faint hover:text-fg-dim underline-offset-2 hover:underline",children:"rule syntax ↗"})]}),children:v(t)?e.jsx(C,{title:"no active project",hint:"open a tab in a project directory to edit project or local permissions"}):u&&f?e.jsx(ee,{scope:t,cwd:a,activePath:u}):e.jsx(C,{title:"resolving…"})})}j.memo(Ce);function ee({scope:t,cwd:s,activePath:n}){const a=T(c=>c.files[n]),{perms:o,err:r}=a?Se(a.draftRaw):{perms:{},err:null},l=(c,x)=>{if(r){A.error(J);return}window.api.claudeConfig.patch({fileId:"settings",scope:t,cwd:s,keyPath:["permissions",c],value:x}).catch(v=>A.error(v instanceof Error?v.message:String(v)))},p=(c,x)=>{const v=x.trim();if(!v)return;const f=o[c]??[];f.includes(v)||l(c,[...f,v])},u=(c,x)=>{const v=o[c]??[];l(c,v.filter((f,i)=>i!==x))};return e.jsxs("div",{className:"p-4 space-y-5 max-w-3xl",children:[r&&e.jsxs("div",{role:"alert",className:"text-xs text-red-400 border border-red-400/40 rounded px-3 py-2",children:[J," (",r,")"]}),e.jsx(_e,{value:o.defaultMode??"default",onChange:c=>l("defaultMode",c)}),Ne.map(c=>e.jsx(Ee,{list:c,rules:o[c]??[],disabled:!!r,onAdd:x=>p(c,x),onRemove:x=>u(c,x)},c)),e.jsx(Pe,{dirs:o.additionalDirectories??[],disabled:!!r,onChange:c=>l("additionalDirectories",c)})]})}function _e({value:t,onChange:s}){var r;const a=(((r=X().at(["permissions","defaultMode"]))==null?void 0:r.enum)??[]).filter(l=>typeof l=="string"),o=t&&!a.includes(t)?[...a,t]:a;return e.jsxs("section",{children:[e.jsx("h3",{className:"text-xs text-fg uppercase tracking-wider mb-2",children:"Default Mode"}),e.jsx("div",{className:"inline-flex rounded border border-line overflow-hidden",children:o.map(l=>e.jsx("button",{onClick:()=>s(l),className:`px-2.5 py-1 text-xs transition-colors ${t===l?"bg-bg-hi text-fg":"bg-bg-elev text-fg-dim hover:text-fg hover:bg-bg-hi"}`,children:l},l))})]})}function Ee({list:t,rules:s,onAdd:n,onRemove:a,disabled:o}){const[r,l]=j.useState(""),p=t==="allow"?"text-green-400":t==="deny"?"text-red-400":"text-yellow-400";return e.jsxs("section",{children:[e.jsx("h3",{className:`text-xs uppercase tracking-wider mb-2 ${p}`,children:t}),e.jsxs("div",{className:"flex gap-2 mb-2",children:[e.jsx("input",{value:r,disabled:o,onChange:u=>l(u.target.value),onKeyDown:u=>{u.key==="Enter"&&(n(r),l(""))},placeholder:t==="allow"?"e.g. Bash(ls:*) or Read(~/.claude/**)":"e.g. Write(/etc/**)",className:"flex-1 bg-bg-elev border border-line rounded px-2 py-1 text-xs text-fg placeholder-fg-faint"}),e.jsx("button",{onClick:()=>{n(r),l("")},disabled:o||!r.trim(),className:"px-2.5 py-1 border border-line rounded text-xs text-fg-dim hover:text-fg hover:bg-bg-hi disabled:opacity-40",children:"add"})]}),s.length===0?e.jsx("div",{className:"text-fg-faint text-xs",children:"no rules"}):e.jsx("ul",{className:"space-y-0.5",children:s.map((u,c)=>e.jsxs("li",{className:"flex items-center gap-2 text-xs font-mono bg-bg-elev border border-line rounded px-2 py-1",children:[e.jsx("span",{className:"flex-1 text-fg-dim truncate",children:u}),e.jsx("button",{onClick:()=>a(c),className:"text-fg-faint hover:text-red-400",title:"remove",children:"×"})]},`${c}-${u}`))})]})}function Pe({dirs:t,onChange:s,disabled:n}){const[a,o]=j.useState("");return e.jsxs("section",{children:[e.jsx("h3",{className:"text-xs text-fg uppercase tracking-wider mb-2",children:"Additional Directories"}),e.jsx("div",{className:"flex gap-2 mb-2",children:e.jsx("input",{value:a,disabled:n,onChange:r=>o(r.target.value),onKeyDown:r=>{r.key==="Enter"&&a.trim()&&(s([...t,a.trim()]),o(""))},placeholder:"/absolute/path/to/dir",className:"flex-1 bg-bg-elev border border-line rounded px-2 py-1 text-xs text-fg placeholder-fg-faint"})}),e.jsx("ul",{className:"space-y-0.5",children:t.map((r,l)=>e.jsxs("li",{className:"flex items-center gap-2 text-xs font-mono bg-bg-elev border border-line rounded px-2 py-1",children:[e.jsx("span",{className:"flex-1 text-fg-dim truncate",children:r}),e.jsx("button",{onClick:()=>s(t.filter((p,u)=>u!==l)),className:"text-fg-faint hover:text-red-400",children:"×"})]},`${l}-${r}`))})]})}const Te={UserPromptSubmit:{when:"Fires just before the user prompt is sent to the model.",payload:"{ prompt: string }",example:"Block submission if the prompt mentions a secret."},UserPromptExpansion:{when:"Fires when a slash command expands into its final prompt text.",payload:"{ command: string, expanded: string }",example:"Audit which slash commands actually run, post-expansion."},PreToolUse:{when:"Fires before any tool runs. Can block the call.",payload:"{ tool_name: string, tool_input: object }",example:'matcher="Bash" — block dangerous shell commands.'},PostToolUse:{when:"Fires after a tool completes successfully.",payload:"{ tool_name: string, tool_input: object, tool_result: string }",example:'matcher="Write|Edit" — run a linter on changed files.'},PostToolUseFailure:{when:"Fires after a tool errors out (non-zero exit, exception, or refusal).",payload:"{ tool_name: string, tool_input: object, error: string }",example:"Pipe failed Bash runs into a desktop notification."},PostToolBatch:{when:"Fires once after a parallel batch of tool calls all complete.",payload:"{ tool_uses: Array<{ tool_name, tool_input, tool_result? }> }",example:"Aggregate file-edit batches into a single commit message."},Stop:{when:"Fires when the model emits end_turn.",payload:"{ stop_reason: string, output_tokens: number }",example:"Play a chime when the agent finishes a long task."},StopFailure:{when:"Fires when a turn aborts without end_turn (rate-limit, network, OOM).",payload:'{ reason: "rate_limit"|"network"|"oom"|"killed"|string }',example:"Auto-resume on transient failures."},SessionStart:{when:"Fires once when a session boots (claude or claude -p).",payload:'{ source: "startup"|"resume", model: string, agent_type: string }',example:"Inject a project-specific system prompt addendum."},SessionEnd:{when:"Fires once when the session terminates.",payload:'{ reason: "user_quit"|"timeout"|"error"|string }',example:"Persist transcript summary to ~/.claude/projects/<>."},Setup:{when:"Fires during interactive setup (claude /setup, /init).",payload:'{ mode: "init"|"reconfigure"|string }'},PreCompact:{when:"Fires before transcript compaction runs.",payload:'{ transcript_path: string, trigger: "manual"|"auto" }',example:"Snapshot the pre-compact transcript for later diffing."},PostCompact:{when:"Fires after compaction; the active transcript is the compacted one.",payload:'{ transcript_path: string, trigger: "manual"|"auto" }'},InstructionsLoaded:{when:"Fires after CLAUDE.md and any imported memory files are loaded.",payload:'{ source: "session_start"|"reload" }'},Notification:{when:"Fires when Claude Code emits a desktop notification.",payload:"{ title: string, message: string }",example:"Forward to your own notify-send / osascript pipeline."},PermissionRequest:{when:"Fires when a tool needs user permission (per the permissions block).",payload:"{ tool_name: string, tool_input?: object }",example:"Auto-allow npm test invocations."},PermissionDenied:{when:"Fires when the user (or policy) denies a permission request.",payload:"{ tool_name: string, retry: boolean }",example:"Track which tools the user habitually rejects."},SubagentStart:{when:"Fires when a subagent (Task tool) spawns.",payload:"{ agent_type: string }",example:'matcher="security-reviewer" — log every security scan.'},SubagentStop:{when:"Fires when a subagent finishes.",payload:'{ agent_type: string, reason: "end_turn"|"error"|string }'},TeammateIdle:{when:"Fires when a teammate agent goes idle (waiting for input).",payload:"{ teammate_id?: string }"},TaskCreated:{when:"Fires when a new Task is created via the Task tool.",payload:"{ task: { description: string, ...} }",example:"Track each spawned task in an external queue."},TaskCompleted:{when:"Fires when a Task completes (success or failure).",payload:"{ task: { description: string, ...} }"},ConfigChange:{when:"Fires when settings.json (any scope) is mutated mid-session.",payload:'{ source: "user_settings"|"project_settings"|"local_settings" }',example:"Reload tooling that depends on env vars on config change."},CwdChanged:{when:"Fires when the working directory changes (e.g. agent cd-ing).",payload:"{ old_cwd: string, new_cwd: string }",example:"Refresh project-scoped indexers when cwd drifts."},FileChanged:{when:"Fires when a watched file outside Claude Code's edits changes.",payload:'{ file_path: string, change_type: "modified"|"created"|"deleted" }',example:"Re-run typecheck when any .ts file changes."},WorktreeCreate:{when:"Fires after a git worktree is created via /worktree or subagent isolation.",payload:"{ worktree_path?: string, branch?: string }"},WorktreeRemove:{when:"Fires after a git worktree is removed.",payload:"{ worktree_path?: string }"},Elicitation:{when:"Fires when Claude asks the user a multiple-choice question.",payload:'{ action: "accept"|"reject", ...}'},ElicitationResult:{when:"Fires after the user resolves an elicitation prompt.",payload:"{ choice?: string }"}},te=["UserPromptSubmit","UserPromptExpansion","PreToolUse","PostToolUse","PostToolUseFailure","PostToolBatch","Stop","StopFailure","SessionStart","SessionEnd","Setup","PreCompact","PostCompact","InstructionsLoaded","Notification","PermissionRequest","PermissionDenied","SubagentStart","SubagentStop","TeammateIdle","TaskCreated","TaskCompleted","ConfigChange","CwdChanged","FileChanged","WorktreeCreate","WorktreeRemove","Elicitation","ElicitationResult"],Fe=new Set(te),Oe=["command","http","prompt","agent","mcp_tool"],Ae={UserPromptSubmit:{prompt:"hello"},UserPromptExpansion:{command:"/example",expanded:"hello"},PreToolUse:{tool_name:"Bash",tool_input:{command:"ls"}},PostToolUse:{tool_name:"Bash",tool_input:{command:"ls"},tool_result:""},PostToolUseFailure:{tool_name:"Bash",tool_input:{command:"ls"},error:""},PostToolBatch:{tool_uses:[]},Stop:{stop_reason:"end_turn",output_tokens:0},StopFailure:{reason:"rate_limit"},SessionStart:{source:"startup",model:"",agent_type:""},SessionEnd:{reason:"user_quit"},Setup:{mode:"init"},PreCompact:{transcript_path:"",trigger:"manual"},PostCompact:{transcript_path:"",trigger:"manual"},InstructionsLoaded:{source:"session_start"},Notification:{title:"test",message:"test notification"},PermissionRequest:{tool_name:"Bash"},PermissionDenied:{tool_name:"Bash",retry:!1},SubagentStart:{agent_type:"general-purpose"},SubagentStop:{agent_type:"general-purpose",reason:"end_turn"},TeammateIdle:{},TaskCreated:{task:{description:""}},TaskCompleted:{task:{description:""}},ConfigChange:{source:"user_settings"},CwdChanged:{old_cwd:"",new_cwd:""},FileChanged:{file_path:"",change_type:"modified"},WorktreeCreate:{},WorktreeRemove:{},Elicitation:{action:"accept"},ElicitationResult:{}},K="This settings file has invalid JSON. Fix it in the Settings raw editor first; Hooks will not overwrite it.";function Re(t){if(t.trim()==="")return{full:{},hooks:{},err:null};try{const s=JSON.parse(t);if(s===null||typeof s!="object"||Array.isArray(s))return{full:{},hooks:{},err:"settings file is not a JSON object"};const n=s;return{full:n,hooks:n.hooks??{},err:null}}catch(s){return{full:{},hooks:{},err:s.message}}}function Me(t,s){return(t[s]??[]).reduce((n,a)=>{var o;return n+(((o=a.hooks)==null?void 0:o.length)??0)},0)}function $e({scope:t="user"}={}){const s=L(),n=V(),a=(n==null?void 0:n.cwd)??null,o=z(x=>x.navFace),[r,l]=j.useState("events");j.useEffect(()=>{o==="project"&&r==="library"&&l("events")},[o,r]);const u=H(Y,s,a)[t]??null,c=e.jsx(U,{options:[{key:"events",label:"Events"},...o==="home"?[{key:"library",label:"Library"}]:[]],active:r,onChange:l});return s?r==="library"?e.jsx(F,{toolbar:c,children:e.jsx(ye,{})}):t!=="user"&&!a?e.jsx(F,{toolbar:e.jsx(e.Fragment,{children:c}),children:e.jsx(C,{title:"no active project"})}):u?e.jsx(F,{toolbar:e.jsxs(e.Fragment,{children:[c,e.jsx("span",{className:"ml-3 text-fg-faint truncate",children:u}),e.jsx("div",{className:"flex-1"}),e.jsx("a",{href:"https://code.claude.com/docs/en/hooks",target:"_blank",rel:"noreferrer",className:"text-fg-faint hover:text-fg-dim underline-offset-2 hover:underline",children:"hook reference ↗"})]}),children:e.jsx(se,{scope:t,cwd:a,path:u})}):e.jsx(C,{title:"loading…"}):e.jsx(C,{title:"loading…"})}function se({scope:t,cwd:s,path:n}){const[a,o]=j.useState("PreToolUse"),[r,l]=j.useState(null),p=(b,k)=>{window.api.claudeConfig.patch({fileId:"settings",scope:t,cwd:s,keyPath:b,value:k}).catch(m=>A.error(m instanceof Error?m.message:String(m)))},u=T(b=>b.files[n]),{hooks:c,err:x}=u?Re(u.draftRaw):{hooks:{},err:null},v=Object.keys(c).filter(b=>!Fe.has(b)),f=v.reduce((b,k)=>b+(c[k]??[]).reduce((m,y)=>{var w;return m+(((w=y.hooks)==null?void 0:w.length)??0)},0),0),i=(b,k)=>{if(x){A.error(K);return}p(["hooks",b],k)},d=c[a]??[],h=()=>{i(a,[...d,{matcher:"",hooks:[{type:"command",command:""}]}])},g=(b,k)=>{const m=d.slice();m[b]=k,i(a,m)},N=b=>{i(a,d.filter((k,m)=>m!==b))};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-col h-full",children:[x?e.jsxs("div",{role:"alert",className:"px-3 py-2 border-b border-line text-xs text-red-400",children:[K," (",x,")"]}):null,f>0?e.jsxs("div",{className:"px-3 py-2 border-b border-line text-xs bg-bg-elev text-fg-dim",children:[e.jsx("span",{className:"text-yellow-400",children:"⚠"})," ",f," hook(s) configured under unknown event names: ",e.jsx("span",{className:"font-mono text-fg",children:v.join(", ")}),e.jsx("span",{className:"text-fg-faint",children:" · these are ignored by Claude Code 2026; edit settings.json directly to remove."})]}):null,e.jsx(je,{sidebarWidth:"14rem",sidebar:e.jsx("div",{className:"py-1",children:te.map(b=>{const k=Me(c,b),m=Te[b],y=m?e.jsxs("span",{className:"block space-y-1",children:[e.jsx("span",{className:"block text-fg",children:m.when}),e.jsxs("span",{className:"block text-fg-faint font-mono",children:["payload: ",m.payload]}),m.example?e.jsxs("span",{className:"block text-fg-faint italic",children:["e.g. ",m.example]}):null]}):e.jsx("span",{className:"text-fg-faint italic",children:"no documentation yet"});return e.jsx("div",{className:"[&>span]:w-full",children:e.jsx(de,{content:y,align:"bottom-center",children:e.jsxs("button",{onClick:()=>o(b),title:m==null?void 0:m.when,className:`w-full text-left px-3 py-1 text-xs ${a===b?"bg-bg-hi text-fg":"text-fg-dim hover:text-fg hover:bg-bg-hi"}`,children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"truncate",children:b}),k>0&&e.jsx("span",{className:"text-accent shrink-0 ml-2",children:k})]}),m?e.jsx("span",{className:"block text-[11px] leading-[1.3] text-fg-faint/80 font-normal truncate",children:m.when}):e.jsx("span",{className:"block text-[11px] leading-[1.3] text-fg-faint/80 italic font-normal truncate",children:"no documentation yet"})]})})},b)})}),detail:e.jsxs("div",{className:"p-4 space-y-3 max-w-3xl",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-xs uppercase tracking-wider text-fg",children:a}),e.jsx("button",{onClick:h,disabled:!!x,className:"px-2 py-0.5 text-xs border border-line rounded text-fg-dim hover:text-fg hover:bg-bg-hi disabled:opacity-40 disabled:cursor-not-allowed",children:"+ add group"})]}),d.length===0?e.jsx("div",{className:"text-fg-faint text-xs",children:"no hooks for this event"}):d.map((b,k)=>e.jsx(Ie,{group:b,jsonInvalid:!!x,onChange:m=>g(k,m),onRemove:()=>N(k),onTestFire:m=>l({event:a,matcher:b.matcher??"",command:m.command??""})},k))]})})]}),r?e.jsx(Be,{event:r.event,matcher:r.matcher,command:r.command,onClose:()=>l(null)}):null]})}j.memo($e);function M({value:t,onCommit:s,onDraft:n,...a}){const[o,r]=j.useState(t);j.useEffect(()=>r(t),[t]);const l=()=>{o!==t&&s(o)};return e.jsx("input",{...a,value:o,onChange:p=>{r(p.target.value),n==null||n(p.target.value)},onBlur:l,onKeyDown:p=>{p.key==="Enter"&&l()}})}function Ie({group:t,jsonInvalid:s,onChange:n,onRemove:a,onTestFire:o}){const r=()=>n({...t,hooks:[...t.hooks??[],{type:"command",command:""}]}),l=(u,c)=>{const x=t.hooks.slice();x[u]=c,n({...t,hooks:x})},p=u=>n({...t,hooks:t.hooks.filter((c,x)=>x!==u)});return e.jsxs("div",{className:"border border-line rounded p-3 bg-bg-elev space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-fg-faint w-16",children:"matcher"}),e.jsx(M,{value:t.matcher??"",disabled:s,onCommit:u=>n({...t,matcher:u}),placeholder:"tool name regex or exact match (optional)",className:"flex-1 bg-bg border border-line rounded px-2 py-0.5 text-xs text-fg font-mono"}),e.jsx("button",{onClick:a,disabled:s,className:"text-fg-faint hover:text-red-400 text-xs disabled:opacity-40",title:"remove group",children:"× group"})]}),(t.hooks??[]).map((u,c)=>e.jsx(Le,{rule:u,jsonInvalid:s,onChange:x=>l(c,x),onRemove:()=>p(c),onTestFire:()=>o(u)},c)),e.jsx("button",{onClick:r,disabled:s,className:"text-xs text-fg-faint hover:text-fg disabled:opacity-40",children:"+ add hook"})]})}function De(t){var n,a,o;const s=((a=(n=Q.$defs)==null?void 0:n.hookCommand)==null?void 0:a.anyOf)??[];for(const r of s){const l=r.properties;if(((o=l==null?void 0:l.type)==null?void 0:o.const)!==t)continue;const p=l.timeout;if(typeof(p==null?void 0:p.default)=="number")return p.default;const u=/default:\s*(\d+)/.exec((p==null?void 0:p.description)??"");return u?Number(u[1]):null}return null}function G(t){return/^\d+$/.test(t.trim())&&Number(t)>0?Number(t):null}function Le({rule:t,jsonInvalid:s,onChange:n,onRemove:a,onTestFire:o}){const r=i=>({command:"e.g. node ./scripts/lint.js $FILE",http:"e.g. https://hooks.example.com/notify",prompt:"e.g. Review this change for security issues",agent:"e.g. security-reviewer",mcp_tool:"e.g. mcp__server__tool"})[i],l=t.type==="command"?"command":t.type==="http"?"url":t.type==="prompt"?"prompt":t.type==="mcp_tool"?"mcpTool":"agent",p=t[l]??"",u=(t.args??[]).join(" "),[c,x]=j.useState(null),v=De(t.type),f={type:"hook",name:p||t.type,command:t.type==="command"?t.command:void 0,url:t.type==="http"?t.url:void 0};return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("select",{value:t.type,disabled:s,onChange:i=>n({type:i.target.value}),className:"bg-bg border border-line rounded px-1 py-0.5 text-xs text-fg",children:Oe.map(i=>e.jsx("option",{value:i,children:i},i))}),e.jsx(ve,{interactive:!1,input:f}),e.jsx(M,{value:p,disabled:s,onCommit:i=>n({...t,[l]:i}),placeholder:r(t.type),className:`flex-1 bg-bg border rounded px-2 py-0.5 text-xs text-fg font-mono ${s?"border-red-500/70":p.trim()?"border-line":"border-yellow-600/50"}`}),s?e.jsx("span",{className:"text-red-400 text-xs",title:"The enclosing settings.json is malformed; fix the JSON before editing.",children:"× invalid"}):null,e.jsx(M,{value:t.timeout!=null?String(t.timeout):"",disabled:s,"aria-label":"timeout (seconds)","aria-invalid":c?!0:void 0,title:c??"Timeout in seconds",onDraft:i=>{x(!i.trim()||G(i)!=null?null:"Timeout must be a positive whole number of seconds")},onCommit:i=>{if(!i.trim()){n({...t,timeout:void 0});return}const d=G(i);d!=null&&n({...t,timeout:d})},placeholder:v!=null?`${v} (seconds)`:"seconds",className:`w-24 bg-bg border rounded px-2 py-0.5 text-xs text-fg ${c?"border-red-500/70":"border-line"}`}),c?e.jsx("span",{role:"alert",className:"text-red-400 text-xs",children:c}):null,t.type==="command"?e.jsx("button",{onClick:o,disabled:s||!p.trim(),className:"px-2 py-0.5 text-xs border border-line rounded text-fg-dim hover:text-fg hover:bg-bg-hi disabled:opacity-40 disabled:cursor-not-allowed",title:"Run this command with a fake event payload",children:"test fire"}):null,e.jsx("button",{onClick:a,disabled:s,className:"text-fg-faint hover:text-red-400 text-xs disabled:opacity-40",children:"×"})]}),t.type==="command"?e.jsxs("div",{className:"flex items-center gap-2 pl-[3.75rem]",children:[e.jsx("span",{className:"text-xs text-fg-faint w-12",children:"args"}),e.jsx(M,{value:u,disabled:s,onCommit:i=>n({...t,args:i.trim()?i.split(/\s+/).filter(Boolean):void 0}),placeholder:"argv array (v2.1.139+ exec form, no shell)",className:"flex-1 bg-bg border border-line rounded px-2 py-0.5 text-xs text-fg font-mono"})]}):null,e.jsxs("div",{className:"flex items-center gap-2 pl-[3.75rem]",children:[e.jsx("span",{className:"text-xs text-fg-faint w-12",children:"term"}),e.jsx(M,{value:t.terminalSequence??"",disabled:s,onCommit:i=>n({...t,terminalSequence:i||void 0}),placeholder:"terminalSequence — e.g. \\\\a (bell), v2.1.141+",className:"flex-1 bg-bg border border-line rounded px-2 py-0.5 text-xs text-fg font-mono"})]})]})}function He(t){return JSON.stringify(Ae[t]??{},null,2)}function Ue(t,s){if(!t.trim())return{matched:!0,target:null,note:"empty matcher → matches all"};const n=s&&typeof s=="object"&&"tool_name"in s?String(s.tool_name??""):null;if(n==null)return{matched:!1,target:null,note:"payload has no tool_name to match against"};try{return{matched:new RegExp(`^(?:${t})$`).test(n),target:n}}catch{return{matched:t===n,target:n,note:"matcher not valid regex; fell back to exact match"}}}function Be({event:t,matcher:s,command:n,onClose:a}){const[o,r]=j.useState(()=>He(t)),[l,p]=j.useState(!1),[u,c]=j.useState(null),[x,v]=j.useState(null);let f=null;try{JSON.parse(o)}catch(d){f=d.message}const i=async()=>{p(!0),c(null);let d=null;try{d=JSON.parse(o)}catch{}v(Ue(s,d));try{const h=await window.api.app.testFireHook({command:n,payload:o,timeoutMs:5e3});c(h)}finally{p(!1)}};return e.jsx(ue,{open:!0,onClose:a,title:`Test fire — ${t}`,children:e.jsxs("div",{className:"space-y-3 text-xs",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-fg-faint mb-1",children:"resolved command"}),e.jsx("div",{className:"font-mono text-fg bg-bg border border-line rounded px-2 py-1 break-all",children:n})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-fg-faint mb-1",children:"matcher"}),e.jsx("div",{className:"font-mono text-fg bg-bg border border-line rounded px-2 py-1",children:s||e.jsx("span",{className:"text-fg-faint",children:"(empty — matches all)"})})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("span",{className:"text-fg-faint",children:"fake event payload (stdin)"}),f?e.jsxs("span",{className:"text-red-400",children:["× ",f]}):null]}),e.jsx("textarea",{value:o,onChange:d=>r(d.target.value),rows:8,className:`w-full bg-bg border rounded px-2 py-1 font-mono text-fg ${f?"border-red-500/70":"border-line"}`})]}),x?e.jsxs("div",{children:[e.jsx("div",{className:"text-fg-faint mb-1",children:"matcher result"}),e.jsxs("div",{className:"font-mono",children:[e.jsx("span",{className:x.matched?"text-green-400":"text-red-400",children:x.matched?"✓ match":"✗ no match"}),x.target!=null?e.jsxs("span",{className:"text-fg-dim",children:[' · target tool_name="',x.target,'"']}):null,x.note?e.jsx("div",{className:"text-fg-faint",children:x.note}):null]})]}):null,u?e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"text-fg-faint",children:["exit ",u.exitCode," · ",u.durationMs,"ms"]}),u.stdout?e.jsxs("div",{children:[e.jsx("div",{className:"text-fg-faint",children:"stdout"}),e.jsx("pre",{className:"bg-bg border border-line rounded p-2 font-mono text-fg whitespace-pre-wrap break-all max-h-40 overflow-auto",children:u.stdout})]}):null,u.stderr?e.jsxs("div",{children:[e.jsx("div",{className:"text-fg-faint",children:"stderr"}),e.jsx("pre",{className:"bg-bg border border-line rounded p-2 font-mono text-red-300 whitespace-pre-wrap break-all max-h-40 overflow-auto",children:u.stderr})]}):null]}):null,e.jsxs("div",{className:"flex items-center justify-end gap-2 pt-1",children:[e.jsx("button",{onClick:a,className:"px-2 py-0.5 text-xs border border-line rounded text-fg-dim hover:text-fg hover:bg-bg-hi",children:"close"}),e.jsx("button",{onClick:i,disabled:l||!!f||!n.trim(),className:"px-2 py-0.5 text-xs border border-line rounded text-fg hover:bg-bg-hi disabled:opacity-40 disabled:cursor-not-allowed",children:l?"running…":"run"})]})]})})}const ne=[{id:"permissions",label:"Permissions",tab:"permissions",keys:["permissions"]},{id:"hooks",label:"Hooks",tab:"hooks",keys:["hooks","disableAllHooks","allowedHttpHookUrls","httpHookAllowedEnvVars"]},{id:"mcp",label:"MCP Servers",tab:null,keys:["enabledMcpjsonServers","disabledMcpjsonServers","enableAllProjectMcpServers"]},{id:"plugins",label:"Plugins",tab:null,keys:["enabledPlugins"]}],W=new Set(ne.flatMap(t=>t.keys)),Je=[{id:"essentials",title:"Essentials",summary:"The knobs you reach for first.",keys:["model","language","outputStyle"]},{id:"git",title:"Git & Commits",summary:"How Claude writes commits and pull requests on your behalf.",keys:["attribution","includeGitInstructions","includeCoAuthoredBy"]},{id:"memory",title:"Memory & Plans",summary:"Context Claude keeps between sessions and where it files plans.",keys:["autoMemoryEnabled","plansDirectory","claudeMdExcludes","respectGitignore"]},{id:"model",title:"Model & Reasoning",summary:"Model allow/override lists, reasoning depth, and fast-mode toggles — machine-wide, with no per-Epic override yet. An Epic's Agent persona model (Agent Library) still wins over Essentials' plain model default.",advanced:!0,keys:["availableModels","modelOverrides","effortLevel","fastMode","fastModePerSessionOptIn","alwaysThinkingEnabled","fallbackModel","enforceAvailableModels","teammateDefaultModel","advisorModel"]},{id:"interface",title:"Interface",summary:"Visual polish — spinners, progress bars, motion.",keys:["spinnerTipsEnabled","spinnerTipsOverride","spinnerVerbs","terminalProgressBarEnabled","showTurnDuration","prefersReducedMotion","companyAnnouncements","statusLine","teammateMode"]},{id:"updates",title:"Updates & Cleanup",summary:"Release channel and how long transcripts stick around.",keys:["autoUpdatesChannel","cleanupPeriodDays"]},{id:"env",title:"Environment & Auth",summary:"Environment variables and auth-helper scripts.",keys:["env","apiKeyHelper","awsCredentialExport","awsAuthRefresh"]},{id:"hooks",title:"Hooks",summary:"Scripts Claude runs before/after tool use.",keys:["hooks","disableAllHooks","allowedHttpHookUrls","httpHookAllowedEnvVars"]},{id:"mcp",title:"MCP Servers",summary:"External tool providers Claude can talk to.",keys:["enableAllProjectMcpServers","enabledMcpjsonServers","disabledMcpjsonServers"]},{id:"plugins",title:"Plugins",summary:"Installed plugins, marketplaces, and per-plugin configuration.",keys:["enabledPlugins","extraKnownMarketplaces","skippedPlugins","skippedMarketplaces","pluginConfigs"]},{id:"filesystem",title:"File Picker & Sandbox",summary:"How Claude browses files and the sandbox it runs in.",keys:["fileSuggestion","sandbox","worktree"]},{id:"login",title:"Login",summary:"Which login method to force on startup.",keys:["forceLoginMethod","forceLoginOrgUUID"]},{id:"feedback",title:"Feedback",summary:"Session-quality surveys.",keys:["feedbackSurveyRate"]},{id:"advanced",title:"Advanced / Enterprise",summary:"Managed-settings-only keys and enterprise allow/denylists.",advanced:!0,keys:["allowedMcpServers","deniedMcpServers","allowManagedHooksOnly","allowManagedPermissionRulesOnly","allowManagedMcpServersOnly","strictKnownMarketplaces","blockedMarketplaces","pluginTrustMessage","otelHeadersHelper","skipWebFetchPreflight"]}],Ke={mcp:"MCP",url:"URL",urls:"URLs",http:"HTTP",ui:"UI",id:"ID",uuid:"UUID",api:"API",aws:"AWS",otel:"OTel",json:"JSON"};function re(t){return t.replace(/^\$/,"").replace(/([a-z])([A-Z])/g,"$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g,"$1 $2").toLowerCase().split(/\s+/).filter(Boolean).map((a,o)=>{const r=Ke[a];return r||(o===0?a.charAt(0).toUpperCase()+a.slice(1):a)}).join(" ")}function ae(t){const s=new Set,n=[];for(const o of Je){const r=o.keys.filter(l=>t.has(l)&&!W.has(l));r.forEach(l=>s.add(l)),r.length!==0&&n.push({id:o.id,title:o.title,summary:o.summary,advanced:!!o.advanced,keys:r})}const a=Array.from(t).filter(o=>!s.has(o)&&o!=="$schema"&&!W.has(o)).sort();return a.length>0&&n.push({id:"other",title:"Other",summary:"Keys not yet grouped.",advanced:!1,keys:a}),n}function Ge(t,s){return ae(t).map(n=>({id:n.id,title:n.title,advanced:n.advanced,total:n.keys.length,setCount:n.keys.filter(a=>s.has(a)).length}))}const We={};function oe(t,s){if(s)return{text:s,authored:!1};const n=We[t];return n?{text:n,authored:!0}:null}const qe={essentials:"star",git:"link",memory:"memory",model:"sparkle",interface:"eye",updates:"reload",env:"keys",hooks:"hooks",mcp:"mcp",plugins:"plugins",filesystem:"folder",login:"lock",feedback:"send",advanced:"shield",other:"dot"},Ve=["user","project","local","default"],ze={user:"user",project:"project",local:"local",default:"default"};function Ye({node:t,targetScope:s,onOverride:n,schema:a}){const[o,r]=j.useState(""),[l,p]=j.useState(!1),[u,c]=j.useState(!0),x=t.kind==="object"?t:null,v=x?Object.keys(x.children):[],f=a.rootKeys(),i=new Set([...v,...f]),d=j.useMemo(()=>ae(i),[Array.from(i).sort().join(",")]),h=j.useMemo(()=>Ge(i,new Set(v)),[Array.from(i).sort().join(","),v.join(",")]),[g,N]=j.useState(null),b=j.useRef(null),k=y=>{const w=d.find(_=>_.id===y);w!=null&&w.advanced&&!l&&p(!0),N(y)};j.useEffect(()=>{if(!g)return;N(null);const y=b.current,w=document.getElementById(`settings-group-${g}`);if(!y||!w)return;const _=w.getBoundingClientRect().top-y.getBoundingClientRect().top;y.scrollBy({top:_,behavior:"smooth"})},[g]);const m=j.useMemo(()=>d.filter(y=>l||!y.advanced).map(y=>({...y,keys:y.keys.filter(w=>{const _=(x==null?void 0:x.children[w])!==void 0;if(!u&&!_)return!1;if(!o.trim())return!0;const E=a.at([w]);return[w,re(w),(E==null?void 0:E.description)??""].join(" ").toLowerCase().includes(o.toLowerCase())})})).filter(y=>y.keys.length>0),[d,o,l,u,x,a]);return e.jsxs("div",{className:"h-full flex flex-col",children:[e.jsxs("div",{className:"shrink-0 border-b border-line bg-bg-elev px-3 py-1.5 flex items-center gap-3 text-xs",children:[e.jsxs("span",{className:"text-fg-faint",children:["writing overrides to"," ",e.jsx("span",{className:"text-fg-dim font-medium",children:S[s].label})]}),e.jsxs("label",{className:"flex items-center gap-1 text-fg-faint cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:u,onChange:y=>c(y.target.checked),className:"accent-accent"}),"show not-yet-configured"]}),e.jsxs("label",{className:"flex items-center gap-1 text-fg-faint cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:l,onChange:y=>p(y.target.checked),className:"accent-accent"}),"show advanced"]}),e.jsx("div",{className:"flex-1"}),e.jsx("input",{value:o,onChange:y=>r(y.target.value),placeholder:"search settings…",className:"bg-bg border border-line rounded px-2 py-1 text-xs text-fg w-64"})]}),e.jsxs("div",{className:"flex-1 flex overflow-hidden",children:[e.jsx(Ze,{groups:h,onJump:k}),e.jsxs("div",{ref:b,className:"flex-1 overflow-auto py-3",children:[m.map(y=>e.jsx(Qe,{id:y.id,title:y.title,summary:y.summary,advanced:y.advanced,children:y.keys.map(w=>{const _=x==null?void 0:x.children[w],E=a.at([w]);return e.jsx(Xe,{keyName:w,node:_,info:E,targetScope:s,onOverride:(R,$)=>n([w],R,$)},w)})},y.id)),m.length===0&&e.jsxs("div",{className:"px-6 py-12 text-center text-fg-faint text-sm",children:['no settings match "',o,'"']})]})]})]})}function Ze({groups:t,onJump:s}){return e.jsx("nav",{className:"shrink-0 w-48 border-r border-line bg-bg-elev/30 overflow-y-auto py-3",children:t.map(n=>e.jsxs("button",{onClick:()=>s(n.id),className:"w-full flex items-center gap-2 px-3 py-2 text-left hover:bg-bg-hi transition-colors",title:`jump to ${n.title}`,children:[e.jsx(pe,{name:qe[n.id]??"dot",size:15,className:"text-fg-faint shrink-0"}),e.jsx("span",{className:"flex-1 min-w-0 truncate text-xs text-fg-dim",children:n.title}),e.jsxs("span",{className:"text-[10px] text-fg-faint font-mono shrink-0",children:[n.setCount,"/",n.total]})]},n.id))})}function Qe({id:t,title:s,summary:n,advanced:a,children:o}){const[r,l]=j.useState(!0);return e.jsxs("section",{id:`settings-group-${t}`,className:"mx-4 mb-4 rounded-lg border border-line shadow-sm bg-bg-elev/50 overflow-hidden",children:[e.jsxs("header",{className:"px-4 py-3 bg-bg-elev cursor-pointer hover:bg-bg-hi flex items-center gap-3 border-b border-line",onClick:()=>l(!r),children:[e.jsx("span",{className:"text-fg-faint w-3",children:r?"▾":"▸"}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h2",{className:"text-fg text-base font-semibold",children:s}),a&&e.jsx("span",{className:"text-[9px] px-1.5 py-0 rounded border border-yellow-900/40 bg-yellow-950/30 text-yellow-500/80 uppercase tracking-wide",children:"advanced"})]}),e.jsx("p",{className:"text-fg-dim text-sm mt-0.5",children:n})]})]}),r&&e.jsx("div",{className:"divide-y divide-line/60",children:o})]})}function Xe({keyName:t,node:s,info:n,targetScope:a,onOverride:o}){const[r,l]=j.useState(!1),[p,u]=j.useState(!1),c=re(t),x=s!==void 0,f=(s==null?void 0:s.kind)==="leaf"?s:null,i=(s==null?void 0:s.kind)==="object"||(s==null?void 0:s.kind)==="array",d=n==null?void 0:n.default,h=f&&d!==void 0&&le(f.value,d),g=it({isSet:x,leafNode:f,defaultVal:d,isDefault:!!h,node:s}),N=et(f,d),b=N.length>=2,k=!!f&&!h,m=oe(t,n==null?void 0:n.description);return e.jsx("div",{className:"px-4 py-3 hover:bg-bg-elev/20",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("button",{onClick:()=>l(!r),className:"text-fg-faint hover:text-fg w-3 mt-0.5",title:r?"collapse":"expand",children:r?"▾":"▸"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-baseline gap-2 flex-wrap",children:[e.jsx("h3",{className:"text-fg text-sm",children:c}),e.jsx(lt,{kind:g.kind,label:g.label}),b&&e.jsxs("button",{onClick:y=>{y.stopPropagation(),r||l(!0),u(w=>!w)},className:"text-[9px] px-1.5 py-0 rounded border border-blue-900/40 bg-blue-950/30 text-blue-300/90 uppercase tracking-wide hover:bg-blue-900/40",title:"this key is defined in multiple scopes — click to expand",children:["drift · ",N.map(y=>ze[y]).join(" · ")]}),k&&f&&e.jsx("button",{onClick:y=>{y.stopPropagation(),o(void 0,f.winner)},className:"text-[9px] px-1.5 py-0 rounded border border-line bg-bg-elev text-fg-faint uppercase tracking-wide hover:text-fg hover:bg-bg-hi",title:`reset · delete from ${S[f.winner].label}`,children:"↺ reset"}),(n==null?void 0:n.deprecated)&&e.jsx("span",{className:"text-[9px] px-1 py-0 rounded border border-yellow-900/40 bg-yellow-950/30 text-yellow-500/80 uppercase tracking-wide",children:"deprecated"}),(n==null?void 0:n.required)&&!x&&e.jsx("span",{className:"text-[9px] px-1 py-0 rounded border border-red-900/40 bg-red-950/30 text-red-400/80 uppercase tracking-wide",children:"required"})]}),m&&e.jsx("p",{className:`text-fg-dim text-xs mt-0.5 leading-relaxed ${m.authored?"inline-block border-b border-dotted border-fg-faint/70 cursor-help":""}`,title:m.authored?"In-app-authored description — not from the official Claude Code schema":void 0,children:ct(m.text)}),r&&p&&f&&e.jsx(tt,{leaf:f,defaultVal:d,onReset:y=>o(void 0,y)}),r&&e.jsx(st,{keyName:t,node:s,info:n,targetScope:a,onOverride:y=>o(y)})]}),e.jsx("div",{className:"shrink-0",children:!r&&e.jsx(ot,{node:s,info:n,onSet:y=>{o(y)},disabled:i&&x})})]})})}function et(t,s){if(!t)return[];const n=new Set;n.add(t.winner);for(const a of t.shadowed)n.add(a.scope);return s!==void 0&&n.add("default"),Ve.filter(a=>n.has(a))}function tt({leaf:t,defaultVal:s,onReset:n}){const a={};a[t.winner]={value:t.value,winner:!0};for(const o of t.shadowed)a[o.scope]={value:o.value,winner:!1};return e.jsxs("div",{className:"mt-2 border border-line rounded bg-bg-elev/40 text-xs",children:[e.jsx("div",{className:"px-2 py-1 text-fg-faint border-b border-line/60",children:"Values across all scopes (winner highlighted · reset removes that scope's value):"}),e.jsxs("div",{className:"divide-y divide-line/60",children:[["user","project","local"].map(o=>{const r=a[o],l=r!==void 0;return e.jsxs("div",{className:"grid grid-cols-[5rem_1fr_auto] gap-2 px-2 py-1 items-center",children:[e.jsx("span",{className:"text-fg-faint",children:S[o].label}),e.jsx("span",{className:`font-mono truncate ${r!=null&&r.winner?"text-accent":"text-fg-dim"}`,children:l?O(r.value):e.jsx("span",{className:"text-fg-faint",children:"—"})}),l?e.jsx("button",{onClick:()=>n(o),className:"text-[9px] px-1.5 py-0 rounded border border-line text-fg-faint uppercase tracking-wide hover:text-fg hover:bg-bg-hi",title:`delete this key from ${S[o].label}`,children:"↺"}):e.jsx("span",{})]},o)}),e.jsxs("div",{className:"grid grid-cols-[5rem_1fr_auto] gap-2 px-2 py-1 items-center",children:[e.jsx("span",{className:"text-fg-faint",children:"Default"}),e.jsx("span",{className:"font-mono text-fg-dim truncate",children:s!==void 0?O(s):e.jsx("span",{className:"text-fg-faint",children:"—"})}),e.jsx("span",{})]})]})]})}function st({keyName:t,node:s,info:n,targetScope:a,onOverride:o}){const l=(s==null?void 0:s.kind)==="leaf"?s:null,p=oe(t,n==null?void 0:n.description);return e.jsxs("div",{className:"mt-3 space-y-2 text-xs",children:[p&&e.jsx("p",{className:`text-fg-dim leading-relaxed whitespace-pre-wrap ${p.authored?"inline-block border-b border-dotted border-fg-faint/70 cursor-help":""}`,title:p.authored?"In-app-authored description — not from the official Claude Code schema":void 0,children:p.text}),e.jsxs("dl",{className:"grid grid-cols-[auto_1fr] gap-x-3 gap-y-1 text-fg-faint",children:[(n==null?void 0:n.type)&&e.jsxs(e.Fragment,{children:[e.jsx("dt",{children:"Type"}),e.jsx("dd",{className:"text-fg-dim font-mono",children:Array.isArray(n.type)?n.type.join(" | "):n.type})]}),(n==null?void 0:n.default)!==void 0&&e.jsxs(e.Fragment,{children:[e.jsx("dt",{children:"Default"}),e.jsx("dd",{className:"text-fg-dim font-mono",children:O(n.default)})]}),(n==null?void 0:n.enum)&&e.jsxs(e.Fragment,{children:[e.jsx("dt",{children:"Options"}),e.jsx("dd",{className:"text-fg-dim font-mono",children:n.enum.map(u=>String(u)).join(" | ")})]}),l&&e.jsxs(e.Fragment,{children:[e.jsx("dt",{children:"Current"}),e.jsxs("dd",{className:"font-mono",children:[e.jsx("span",{className:"text-fg-dim",children:O(l.value)}),e.jsxs("span",{className:"ml-2 text-fg-faint",children:["from ",S[l.winner].label]})]})]}),l&&l.shadowed.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("dt",{children:"Shadowed"}),e.jsx("dd",{className:"space-y-0.5",children:l.shadowed.map((u,c)=>e.jsxs("div",{className:"font-mono text-fg-faint line-through",children:[O(u.value)," —"," ",e.jsx("span",{className:"no-underline",children:S[u.scope].label})]},c))})]}),(s==null?void 0:s.kind)==="array"&&e.jsxs(e.Fragment,{children:[e.jsx("dt",{children:"Accumulated"}),e.jsxs("dd",{className:"text-fg-dim",children:[s.items.length," items across all scopes"]})]})]}),e.jsx("div",{className:"pt-2 flex items-center gap-2 flex-wrap border-t border-line/60",children:e.jsx(nt,{keyName:t,node:s,info:n,onChange:o,targetScope:a})})]})}function nt({node:t,info:s,onChange:n,targetScope:a}){const r=(t==null?void 0:t.kind)==="leaf"?t.value:s==null?void 0:s.default,l=ie(s==null?void 0:s.type);if(l==="boolean"){const p=r===!0;return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-fg-faint",children:"Set to:"}),e.jsx("div",{className:"inline-flex rounded border border-line overflow-hidden",children:[{v:!0,label:"on"},{v:!1,label:"off"}].map(({v:u,label:c})=>e.jsx("button",{onClick:()=>n(u),className:`px-3 py-0.5 text-xs transition-colors ${p===u?"bg-accent text-bg":"bg-bg-elev text-fg-dim hover:bg-bg-hi hover:text-fg"}`,children:c},c))}),e.jsxs("span",{className:"text-fg-faint",children:["→ ",S[a].label]})]})}return s!=null&&s.enum?e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"text-fg-faint",children:"Choose:"}),s.enum.map(p=>{const u=le(r,p);return e.jsx("button",{onClick:()=>n(p),className:`px-2 py-0.5 text-xs rounded border ${u?"bg-accent text-bg border-accent":"bg-bg-elev text-fg-dim border-line hover:text-fg hover:bg-bg-hi"}`,children:String(p)},String(p))}),e.jsxs("span",{className:"text-fg-faint",children:["→ ",S[a].label]})]}):l==="integer"||l==="number"?e.jsx(rt,{value:typeof r=="number"?r:void 0,integer:l==="integer",onCommit:n,target:S[a].label}):l==="string"?e.jsx(at,{value:typeof r=="string"?r:"",onCommit:n,target:S[a].label}):e.jsxs("div",{className:"text-fg-faint",children:["Complex value (",l??"object/array",") — use the"," ",e.jsx("span",{className:"text-fg-dim",children:"Raw"})," tab to edit."]})}function rt({value:t,integer:s,onCommit:n,target:a}){const[o,r]=j.useState(t!==void 0?String(t):""),l=()=>{const p=s?parseInt(o,10):parseFloat(o);Number.isNaN(p)||n(p)};return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-fg-faint",children:"Set to:"}),e.jsx("input",{type:"number",value:o,onChange:p=>r(p.target.value),onBlur:l,onKeyDown:p=>{p.key==="Enter"&&p.target.blur()},className:"w-24 bg-bg border border-line rounded px-2 py-0.5 text-xs text-fg"}),e.jsxs("button",{onClick:l,className:"px-2 py-0.5 text-xs border border-accent/50 rounded text-accent hover:bg-accent hover:text-bg",children:["save → ",a]})]})}function at({value:t,onCommit:s,target:n}){const[a,o]=j.useState(t);return e.jsxs("div",{className:"flex items-center gap-2 flex-1 min-w-0",children:[e.jsx("span",{className:"text-fg-faint shrink-0",children:"Set to:"}),e.jsx("input",{type:"text",value:a,onChange:r=>o(r.target.value),onKeyDown:r=>{r.key==="Enter"&&s(a)},className:"flex-1 min-w-0 bg-bg border border-line rounded px-2 py-0.5 text-xs text-fg"}),e.jsxs("button",{onClick:()=>s(a),className:"shrink-0 px-2 py-0.5 text-xs border border-accent/50 rounded text-accent hover:bg-accent hover:text-bg",children:["save → ",n]})]})}function ot({node:t,info:s,onSet:n,disabled:a}){const o=(t==null?void 0:t.kind)==="leaf",r=ie(s==null?void 0:s.type);if(a)return null;if(r==="boolean"){const l=o&&t.value===!0;return e.jsx("button",{onClick:()=>n(!l),className:`px-2.5 py-0.5 text-xs rounded border transition-colors ${l?"bg-accent/15 text-accent border-accent/40 hover:bg-accent hover:text-bg":"bg-bg-elev text-fg-dim border-line hover:text-fg hover:bg-bg-hi"}`,title:"toggle",children:l?"on":"off"})}return null}function it({isSet:t,leafNode:s,defaultVal:n,isDefault:a,node:o}){return t?(o==null?void 0:o.kind)==="array"?{kind:"accumulated",label:`${o.items.length} items`}:(o==null?void 0:o.kind)==="object"?{kind:"set",label:"configured"}:s?a?{kind:"default",label:`= default · ${S[s.winner].label}`}:s.shadowed.length>0?{kind:"override",label:`overriding ${s.shadowed.length} scope(s)`}:{kind:"set",label:`set in ${S[s.winner].label}`}:{kind:"set",label:"configured"}:n!==void 0?{kind:"default",label:`using default: ${O(n)}`}:{kind:"unset",label:"not configured"}}function lt({kind:t,label:s}){const n={set:"bg-accent/15 text-accent border-accent/30",default:"bg-bg-hi text-fg-dim border-line",unset:"bg-bg-elev text-fg-faint border-line",override:"bg-purple-950/30 text-purple-400/80 border-purple-900/40",accumulated:"bg-blue-950/30 text-blue-400/80 border-blue-900/40"}[t];return e.jsx("span",{className:`text-[9px] px-1.5 py-0 rounded border uppercase tracking-wide ${n}`,children:s})}function ie(t){if(t)return Array.isArray(t)?t.find(n=>n!=="null")??t[0]:t}function le(t,s){return t===s?!0:typeof t!=typeof s?!1:t&&s&&typeof t=="object"?JSON.stringify(t)===JSON.stringify(s):!1}function ct(t){const s=t.trim().split(`
|
|
2
|
+
`)[0],n=s.match(/^([^.!?]+[.!?])/);return n?n[1]:s.length>120?s.slice(0,120)+"…":s}function O(t){if(typeof t=="string")return t===""?'""':JSON.stringify(t);if(t===null)return"null";if(t===void 0)return"—";if(typeof t=="object"){const s=JSON.stringify(t);return s.length>60?s.slice(0,60)+"…":s}return String(t)}function dt({cwd:t}){const[s,n]=j.useState(!1),[a,o]=j.useState(!1),[r,l]=j.useState(!1),[p,u]=j.useState(!1);j.useEffect(()=>{var i,d;let f=!1;return n(!1),Promise.resolve((d=(i=window.api.promptSessions)==null?void 0:i.getWorktreeDisabled)==null?void 0:d.call(i,{cwd:t})).then(h=>{f||(o((h==null?void 0:h.disabled)??!1),l((h==null?void 0:h.disabled)??!1),n(!0))},()=>{f||n(!0)}),()=>{f=!0}},[t]);const c=s&&r!==a,x=()=>{var f,i;u(!0),Promise.resolve((i=(f=window.api.promptSessions)==null?void 0:f.setWorktreeDisabled)==null?void 0:i.call(f,{cwd:t,disabled:r})).then(d=>{o((d==null?void 0:d.disabled)??r),l((d==null?void 0:d.disabled)??r)}).catch(d=>A.error(d instanceof Error?d.message:String(d))).finally(()=>u(!1))},v=()=>l(a);return e.jsxs("div",{"data-testid":"settings-epic-isolation",className:"border-b border-line bg-bg-elev px-3 py-2.5 text-[11.5px] leading-snug",children:[e.jsxs("label",{className:"flex items-start gap-2",children:[e.jsx("input",{type:"checkbox",checked:r,disabled:!s||p,onChange:f=>l(f.target.checked),"data-testid":"settings-epic-isolation-checkbox",className:"mt-0.5"}),e.jsxs("span",{children:[e.jsx("span",{className:"font-semibold text-fg",children:"Disable Epic worktree isolation for this project"}),e.jsxs("span",{className:"block text-fg-dim",children:["Off by default — each active Epic runs in its own isolated ",e.jsx("code",{children:"git worktree"})," (branch"," ",e.jsx("code",{children:"sm-epic/<id>"}),"), merged back to main at an explicit checkpoint. Turning this on makes every new Epic in this project run directly in the shared working tree instead, same as before this feature existed."]})]})]}),c&&e.jsx(Z,{dirty:c,busy:p,onSave:x,onRevert:v})]})}const q={user:{title:"Global settings",body:"This is the real ~/.claude/settings.json on disk — the same file the claude CLI reads on every session it starts. Edits apply machine-wide, to every project and every session."},project:{title:"Project settings",body:"This is the real <project>/.claude/settings.json on disk, checked into git. Edits apply to every current and future session in this project, for anyone who clones it."},local:{title:"Local settings",body:"This is the real <project>/.claude/settings.local.json on disk, gitignored. Edits apply to every current and future session in this project, on this machine only."}};function ut({effective:t,onOpenTab:s}){return e.jsx("ul",{"data-testid":"settings-owned-summaries",className:"px-3 py-2 space-y-1 text-[11.5px] border-b border-line",children:ne.map(n=>{const a=n.keys.filter(r=>ge(t,[r])!==null),o=a.length?`${a.length} of ${n.keys.length} keys set (${a.join(", ")})`:"nothing set";return e.jsxs("li",{"data-testid":`owned-summary-${n.id}`,className:"flex items-center gap-2 text-fg-dim",children:[e.jsx("span",{className:"font-semibold text-fg w-28 shrink-0",children:n.label}),e.jsx("span",{className:"truncate",children:o}),n.tab?e.jsxs("button",{type:"button",onClick:()=>s(n.tab),className:"ml-auto text-accent hover:underline shrink-0",children:["edit in ",n.label," tab →"]}):e.jsxs("span",{className:"ml-auto text-fg-faint shrink-0",children:["managed on the ",n.label," page"]})]},n.id)})})}function pt({scope:t="user"}={}){const s=L(),n=B(m=>m.tabs),a=B(m=>m.activeTabId),o=n.find(m=>m.id===a)??null,r=(o==null?void 0:o.cwd)??null,[l,p]=j.useState("general");me("settings",m=>{(m==="general"||m==="permissions"||m==="hooks"||m==="raw")&&p(m)});const u=H(Y,s,r),c=u[t]??null,x=T(m=>m.files),v=T(m=>m.setDraft),f=T(m=>m.saveJson),i=T(m=>m.revert),[d,h]=j.useState(null),g=j.useMemo(()=>xe(he(x,u)),[x,u]),N=(m,y,w)=>{var $;const _=w??t,E=u[_];if(!E)return;const R=(($=x[E])==null?void 0:$.draftRaw)??"";if(R.trim())try{JSON.parse(R)}catch(P){h(`${E} is not valid JSON (${P instanceof Error?P.message:String(P)}) — fix it in Raw before editing from General.`);return}h(null),window.api.claudeConfig.patch({fileId:"settings",scope:_,cwd:r,keyPath:m,value:y}).catch(P=>A.error(P instanceof Error?P.message:String(P)))};if(!s)return e.jsx(C,{title:"loading…"});const b=c?x[c]:null,k=m=>m!=="user"&&!r;return e.jsx(F,{toolbar:e.jsxs(e.Fragment,{children:[e.jsx(U,{options:[{key:"general",label:"General"},{key:"permissions",label:"Permissions"},{key:"hooks",label:"Hooks"},{key:"raw",label:"Raw"}],active:l,onChange:p}),e.jsx(e.Fragment,{children:e.jsx("span",{className:"ml-3 text-fg-faint truncate",children:l==="general"?`overrides → ${c??"—"}`:c??"—"})}),e.jsx("div",{className:"flex-1"}),e.jsx("a",{href:"https://code.claude.com/docs/en/settings",target:"_blank",rel:"noreferrer",className:"text-fg-faint hover:text-fg-dim underline-offset-2 hover:underline",children:"schema reference ↗"})]}),footer:l==="raw"&&c&&b?e.jsx(Z,{dirty:b.dirty,busy:b.busy,parseError:d||b.parseError,lastSavedAt:b.lastSavedAt,leading:b.exists?null:e.jsx("span",{children:"file will be created on save"}),onSave:async()=>{h(null);const m=await f(c);m.ok||h(m.error??"save failed")},onRevert:()=>{h(null),i(c)}}):null,children:e.jsxs(e.Fragment,{children:[e.jsxs("div",{"data-testid":"settings-scope-note",className:"sticky top-0 z-10 border-b border-line bg-bg-elev px-3 py-2 text-[11.5px] leading-snug",children:[e.jsx("span",{className:"font-semibold text-fg",children:q[t].title}),e.jsx("span",{className:"mx-1.5 text-fg-faint",children:"·"}),e.jsx("span",{className:"text-fg-dim",children:q[t].body}),c&&e.jsx("span",{className:"ml-1.5 font-mono text-fg-faint",children:c})]}),d&&l!=="raw"&&e.jsx("div",{role:"alert",className:"px-3 py-2 border-b border-line text-xs text-red-400",children:d}),t==="project"&&r&&e.jsx(dt,{cwd:r}),k(t)?e.jsx(C,{title:"no active project",hint:"open a tab in a project directory to edit project or local settings"}):l==="general"?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"px-3 pt-2",children:e.jsx(I,{path:c??""})}),e.jsx(ut,{effective:g,onOpenTab:p}),e.jsx(Ye,{node:g,targetScope:t,onOverride:N,schema:X()})]}):l==="permissions"?c?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"px-3 pt-2",children:e.jsx(I,{path:c,keyPath:["permissions"]})}),e.jsx(ee,{scope:t,cwd:r,activePath:c})]}):e.jsx(C,{title:"resolving…"}):l==="hooks"?c?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"px-3 pt-2",children:e.jsx(I,{path:c,keyPath:["hooks"]})}),e.jsx(se,{scope:t,cwd:r,path:c})]}):e.jsx(C,{title:"resolving…"}):c&&b?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"px-3 pt-2",children:e.jsx(I,{path:c})}),e.jsx(fe,{path:c,value:b.draftRaw,onChange:m=>{h(null),v(c,m)}})]}):e.jsx(C,{title:"resolving…"})]})})}const wt=j.memo(pt);export{q as SETTINGS_SCOPE_NOTES,wt as Settings};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{aJ as Z,R as wo,aq as ko,at as tr}from"./index-DfWJO7nP.js";import"./monaco-editor-BsIlgG7c.js";function Ao(e,n){var r=e==null?null:typeof Symbol<"u"&&e[Symbol.iterator]||e["@@iterator"];if(r!=null){var i,o,a,s,u=[],l=!0,f=!1;try{if(a=(r=r.call(e)).next,n===0){if(Object(r)!==r)return;l=!1}else for(;!(l=(i=a.call(r)).done)&&(u.push(i.value),u.length!==n);l=!0);}catch(h){f=!0,o=h}finally{try{if(!l&&r.return!=null&&(s=r.return(),Object(s)!==s))return}finally{if(f)throw o}}return u}}function Co(e,n,r){return n=zo(n),n in e?Object.defineProperty(e,n,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[n]=r,e}function er(e,n){return To(e)||Ao(e,n)||ci(e,n)||Eo()}function So(e){return Mo(e)||Po(e)||ci(e)||Oo()}function Mo(e){if(Array.isArray(e))return gn(e)}function To(e){if(Array.isArray(e))return e}function Po(e){if(typeof Symbol<"u"&&e[Symbol.iterator]!=null||e["@@iterator"]!=null)return Array.from(e)}function ci(e,n){if(e){if(typeof e=="string")return gn(e,n);var r=Object.prototype.toString.call(e).slice(8,-1);if(r==="Object"&&e.constructor&&(r=e.constructor.name),r==="Map"||r==="Set")return Array.from(e);if(r==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return gn(e,n)}}function gn(e,n){(n==null||n>e.length)&&(n=e.length);for(var r=0,i=new Array(n);r<n;r++)i[r]=e[r];return i}function Oo(){throw new TypeError(`Invalid attempt to spread non-iterable instance.
|
|
2
2
|
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function Eo(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
|
|
3
3
|
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function Ro(e,n){if(typeof e!="object"||e===null)return e;var r=e[Symbol.toPrimitive];if(r!==void 0){var i=r.call(e,n);if(typeof i!="object")return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return(n==="string"?String:Number)(e)}function zo(e){var n=Ro(e,"string");return typeof n=="symbol"?n:String(n)}var No=function(n,r){var i=new Set(r);return Object.assign.apply(Object,[{}].concat(So(Object.entries(n).filter(function(o){var a=er(o,1),s=a[0];return!i.has(s)}).map(function(o){var a=er(o,2),s=a[0],u=a[1];return Co({},s,u)}))))};function yn(e,n){(n==null||n>e.length)&&(n=e.length);for(var r=0,i=Array(n);r<n;r++)i[r]=e[r];return i}function Io(e){if(Array.isArray(e))return e}function $o(e){if(Array.isArray(e))return yn(e)}function Do(e){if(typeof Symbol<"u"&&e[Symbol.iterator]!=null||e["@@iterator"]!=null)return Array.from(e)}function jo(e,n){var r=e==null?null:typeof Symbol<"u"&&e[Symbol.iterator]||e["@@iterator"];if(r!=null){var i,o,a,s,u=[],l=!0,f=!1;try{if(a=(r=r.call(e)).next,n!==0)for(;!(l=(i=a.call(r)).done)&&(u.push(i.value),u.length!==n);l=!0);}catch(h){f=!0,o=h}finally{try{if(!l&&r.return!=null&&(s=r.return(),Object(s)!==s))return}finally{if(f)throw o}}return u}}function Fo(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
|
|
4
4
|
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function Lo(){throw new TypeError(`Invalid attempt to spread non-iterable instance.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{b9 as p,aJ as d,ak as g,at as o,b7 as b}from"./index-DfWJO7nP.js";function h(e,t){return t&&(e===t||e.startsWith(t+"/"))?"~"+e.slice(t.length):e}function w({path:e,keyPath:t,note:l}){const u=p(),[n,r]=d.useState(void 0);d.useEffect(()=>{let i=!0;const c=()=>{window.api.config.readText(e,{maxBytes:1}).then(s=>{i&&r(s.exists?s.mtimeMs:null)}).catch(()=>{i&&r(void 0)})};c();const x=window.api.config.onChanged(s=>{s.path===e&&c()});return()=>{i=!1,x()}},[e]);const f=h(e,u)+(t&&t.length?` › ${t.join(".")}`:""),a=n===void 0?"":n===null?"created on first save":g(n),m=()=>{b.getState().openFile(e),window.dispatchEvent(new CustomEvent("sm:open-editor"))};return o.jsxs("button",{type:"button","data-testid":"source-chip",title:l??`Open ${e} in the editor`,onClick:m,className:"inline-flex items-center gap-1.5 max-w-full text-[11px] px-2 py-0.5 rounded border border-line bg-bg-elev text-fg-dim hover:bg-bg-hi",children:[o.jsx("span",{className:"font-mono truncate","data-testid":"source-chip-path",children:f}),a&&o.jsxs("span",{className:"text-fg-dim/70 shrink-0","data-testid":"source-chip-age",children:["· ",a]})]})}export{w as S};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{aJ as a,b3 as g,at as e,a7 as M,a$ as B,b8 as $,ar as z,as as H,aX as J,ab as V,f as W,i as U,s as A,r as F,j as X,ae as q,b9 as G,C as K,l as I,ad as Q}from"./index-DfWJO7nP.js";import{P as Y}from"./Panel-OUbLHNsS.js";import{S as Z,I as ee}from"./Library-BGmD-xZN.js";import{S as te}from"./SourceChip-C2YMnlV8.js";import"./monaco-editor-BsIlgG7c.js";import"./Button-fOCJry21.js";const se=300;function re({activePath:r,selectedPath:s,onSelect:n}){const[u,t]=a.useState([]),p=a.useRef(0),N=a.useRef(n);N.current=n;const j=g(i=>{var o;return r?(o=i.files[r])==null?void 0:o.diskRaw:void 0}),m=a.useRef(null);if(a.useEffect(()=>{N.current(null)},[r]),a.useEffect(()=>{if(p.current+=1,!r){m.current=null,t([]);return}const i=m.current!==r;m.current=r;let o=!1;const f=()=>{p.current+=1;const h=p.current;window.api.config.parseImports(r).then(b=>{o||p.current!==h||(b.ok?t(b.imports):(t([]),B.error(b.error||"failed to parse @-imports")))})},y=i?null:setTimeout(f,se);return i&&f(),()=>{o=!0,y&&clearTimeout(y)}},[r,j]),u.length===0||!r)return null;const d=s===r||s===null;return e.jsxs("div",{className:"w-64 shrink-0 border-r border-line bg-bg-elev overflow-auto","data-testid":"referenced-files-rail",children:[e.jsxs("div",{className:"px-3 py-2 text-[10px] uppercase tracking-wide text-fg-faint border-b border-line",children:["Documents · ",u.length+1]}),e.jsxs("button",{type:"button",onClick:()=>n(null),"aria-current":d,"data-testid":"referenced-file-root",className:`w-full text-left px-3 py-2 border-b border-line ${d?"bg-bg-hi text-fg":"text-fg-dim hover:bg-bg"}`,children:[e.jsx("div",{className:"text-[11.5px] font-medium truncate",children:M(r)}),e.jsx("div",{className:"text-[10px] text-fg-faint truncate",title:r,children:"this system prompt"})]}),u.map(i=>{const o=!i.ok||!i.exists,f=s===i.path;return e.jsxs("button",{type:"button",onClick:()=>n(i),"aria-current":f,"data-testid":"referenced-file-row",className:`w-full text-left px-3 py-2 border-b border-line last:border-b-0 ${f?"bg-bg-hi text-fg":"text-fg-dim hover:bg-bg"}`,children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-[11.5px] font-medium truncate flex-1",children:M(i.path)}),o&&e.jsx("span",{className:"shrink-0 px-1.5 py-0.5 rounded text-[9px] uppercase tracking-wide text-amber-400/90 border border-amber-400/30","data-testid":"referenced-file-missing",children:"missing"})]}),e.jsx("div",{className:"text-[10px] text-fg-faint truncate",title:i.path,children:i.path}),e.jsxs("div",{className:"text-[10px] text-fg-faint",children:[i.sizeBytes.toLocaleString()," bytes · ~",i.tokenEstimate.toLocaleString()," tokens"]})]},i.path)})]})}function ne({path:r,value:s,onChange:n,onSave:u,readOnly:t,defaultMode:p,headerRight:N,hideStatusBar:j}){const m=$(),d=z(r),i=H(r),o=J(r),[f,y]=a.useState(()=>t&&i?"preview":p??V(r)),[h,b]=a.useState(!0),[D,v]=a.useState(null),C=a.useRef(null),k=a.useRef(null),x=a.useCallback(c=>{C.current=c},[]),S=a.useCallback(()=>C.current,[]),R=t?i?["preview","edit"]:[]:o?["edit","preview","split"]:i?["edit","preview"]:[],w=i?f:"edit",E=e.jsx(W,{path:r,name:M(r),value:s,onChange:n,onSave:()=>u==null?void 0:u(),onReady:x,onCursor:v,readOnly:t});return e.jsxs("div",{className:"flex flex-col h-full min-h-0","data-testid":"document-editor-pane",children:[e.jsxs("div",{className:"flex items-center gap-1 px-2 h-7 shrink-0 border-b border-line bg-bg-elev",children:[e.jsx("span",{className:"text-[11px] font-medium text-fg truncate",children:M(r)}),t&&e.jsx("span",{className:"ml-1 px-1.5 py-0.5 rounded text-[9px] uppercase tracking-wide text-fg-faint border border-line",children:"read-only"}),e.jsx("div",{className:"flex-1"}),N,d&&(w==="preview"||w==="split")&&e.jsx("button",{onClick:()=>b(c=>!c),"data-testid":"document-outline-toggle",className:`px-2 py-0.5 text-[10px] border border-line rounded ${h?"bg-bg-hi text-fg":"text-fg-faint hover:text-fg"}`,title:"Toggle document outline",children:"Outline"}),R.length>0&&e.jsx("div",{className:"flex items-center ml-1 rounded border border-line overflow-hidden","data-testid":"document-mode-toggle",children:R.map(c=>e.jsx("button",{onClick:()=>y(c),className:`px-2 py-0.5 text-[10px] capitalize transition-colors ${w===c?"bg-bg-hi text-fg":"text-fg-faint hover:text-fg"}`,children:c},c))})]}),e.jsx("div",{className:"flex-1 min-h-0",children:w==="split"&&d?e.jsxs("div",{className:"flex h-full",children:[h&&e.jsx(U,{text:s,scrollRef:k}),e.jsxs("div",{className:"flex-1 min-w-0 flex flex-col border-r border-line",children:[!t&&e.jsx(A,{getEditor:S}),e.jsx("div",{className:"flex-1 min-h-0",children:E})]}),e.jsx("div",{className:"flex-1 min-w-0",children:e.jsx(F,{ref:k,text:s,flush:!0,wideMeasure:m.wideMeasure})})]}):w==="preview"&&d?e.jsxs("div",{className:"flex h-full",children:[h&&e.jsx(U,{text:s,scrollRef:k}),e.jsx("div",{className:"flex-1 min-w-0",children:e.jsx(F,{ref:k,text:s,wideMeasure:m.wideMeasure})})]}):d?e.jsxs("div",{className:"flex flex-col h-full",children:[!t&&e.jsx(A,{getEditor:S}),e.jsx("div",{className:"flex-1 min-h-0",children:E})]}):E}),!j&&e.jsx(X,{text:s,cursor:D,language:q(r)||void 0})]})}const O={title:"User system prompt",body:"This is the real ~/.claude/CLAUDE.md on disk — the instructions the claude CLI loads into every session it starts on this machine, in every project. A project's own CLAUDE.md / CLAUDE.local.md are read from that project's directory when a session launches there; they are not edited here."};function le(){const r=G(),s=a.useMemo(()=>r?K.resolve("user",r,null):null,[r]),[n,u]=a.useState(null),t=(n==null?void 0:n.path)??s,[p,N]=a.useState({});a.useEffect(()=>{const l=n==null?void 0:n.path;if(!l||!n.ok||!n.exists)return;let L=!0;return Promise.resolve().then(()=>window.api.config.canWrite(l)).then(P=>{L&&N(_=>({..._,[l]:P===!1}))}).catch(()=>{}),()=>{L=!1}},[n]);const j=!!n&&p[n.path]===!0,m=!!n&&(!n.ok||!n.exists||j),d=g(l=>l.files),i=g(l=>l.loadText),o=g(l=>l.setDraft),f=g(l=>l.saveText),y=g(l=>l.revert),h=g(l=>l.watchFile),b=g(l=>l.unwatchFile);a.useEffect(()=>{if(s)return i(s,!0),h(s),()=>{b(s)}},[s]),a.useEffect(()=>{if(!(!t||t===s))return i(t,!0),h(t),()=>{b(t)}},[t,s]);const[D,v]=a.useState(null),C=a.useCallback(l=>{v(null),u(l)},[]);if(!r)return e.jsx(I,{title:"loading…"});const k=s?d[s]:null,x=t?d[t]:null,S=(x==null?void 0:x.draftRaw)??"",R=Q(S),w=S.length,E=m&&!j,c=m,T=async()=>{if(!t)return;v(null);const l=await f(t);l.ok||v(l.error??"save failed")};return e.jsx(Y,{toolbar:e.jsxs(e.Fragment,{children:[s&&e.jsx(ee,{path:s,disabled:!!n}),e.jsx("span",{className:"mx-2 text-fg-faint",children:"·"}),e.jsx("span",{className:"text-fg-dim",children:"User scope"}),e.jsx("span",{className:"ml-3 text-fg-faint truncate",children:t??"—"}),s&&e.jsx("span",{className:"ml-3",children:e.jsx(te,{path:s})}),e.jsx("div",{className:"flex-1"}),e.jsxs("span",{className:"text-fg-faint",children:[w.toLocaleString()," chars · ~",R.toLocaleString()," tokens"]})]}),footer:t&&x&&!c?e.jsx(Z,{dirty:x.dirty,busy:x.busy,parseError:D,lastSavedAt:x.lastSavedAt,leading:x.exists?n?e.jsx("span",{children:"editing an imported file"}):null:e.jsx("span",{children:"file will be created on save"}),onSave:T,onRevert:()=>{v(null),y(t)}}):null,children:s&&k?e.jsxs("div",{className:"h-full flex flex-col",children:[e.jsxs("div",{"data-testid":"system-prompt-scope-note",className:"shrink-0 border-b border-line bg-bg-elev px-3 py-2 text-[11.5px] leading-snug",children:[e.jsx("span",{className:"font-semibold text-fg",children:O.title}),e.jsx("span",{className:"mx-1.5 text-fg-faint",children:"·"}),e.jsx("span",{className:"text-fg-dim",children:O.body}),e.jsx("span",{className:"ml-1.5 font-mono text-fg-faint",children:s})]}),e.jsxs("div",{className:"flex-1 min-h-0 flex",children:[e.jsx(re,{activePath:s,selectedPath:t,onSelect:C}),e.jsxs("div",{className:"flex-1 min-w-0 flex flex-col",children:[E&&e.jsx("div",{"data-testid":"system-prompt-missing-note",className:"shrink-0 border-b border-line bg-bg-elev px-3 py-1.5 text-[11px] text-amber-400/90",children:"This import does not resolve to a readable file — the CLI will skip it."}),j&&n&&e.jsxs("div",{"data-testid":"system-prompt-readonly-note",className:"shrink-0 border-b border-line bg-bg-elev px-3 py-1.5 text-[11px] text-amber-400/90",children:["Read-only: ",e.jsx("span",{className:"font-mono",children:n.path})," is outside the folders Session Manager may write to."]}),t&&e.jsx("div",{className:"flex-1 min-h-0",children:e.jsx(ne,{path:t,value:S,readOnly:c,defaultMode:"split",onChange:l=>{v(null),o(t,l)},onSave:()=>{T()}},t)})]})]})]}):e.jsx(I,{title:"resolving…"})})}const ue=a.memo(le);export{ue as SystemPrompt};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{aO as aa,aJ as G,R as Pt,at as R,G as Nf,aq as If,a5 as Rf}from"./index-DfWJO7nP.js";import"./monaco-editor-BsIlgG7c.js";var zi={exports:{}},$i={};/**
|
|
2
2
|
* @license React
|
|
3
3
|
* use-sync-external-store-shim.production.js
|
|
4
4
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{at as r}from"./index-DfWJO7nP.js";function a({checked:t,onChange:e,label:n,disabled:s}){return r.jsxs("label",{className:`inline-flex items-center gap-2 text-xs ${s?"opacity-50 cursor-not-allowed":"cursor-pointer"}`,children:[r.jsx("button",{type:"button",role:"switch","aria-checked":t,disabled:s,onClick:()=>!s&&e(!t),className:`relative w-7 h-4 rounded-full transition-colors ${t?"bg-accent":"bg-bg-hi border border-line"}`,children:r.jsx("span",{className:`absolute top-0.5 w-3 h-3 rounded-full bg-fg transition-transform ${t?"translate-x-3.5":"translate-x-0.5"}`})}),n&&r.jsx("span",{className:"text-fg-dim",children:n})]})}export{a as T};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{at as t}from"./index-DfWJO7nP.js";function n({options:r,active:o,onChange:i}){return t.jsx("div",{className:"flex rounded border border-line overflow-hidden",children:r.map(({key:e,label:s})=>t.jsx("button",{onClick:()=>i(e),className:`px-2 py-0.5 text-xs ${o===e?"bg-bg-hi text-fg":"text-fg-dim hover:text-fg hover:bg-bg-hi"}`,children:s},e))})}export{n as V};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{bn as o,bl as m,a8 as j,at as e,aS as l,bk as b,aw as R}from"./index-DfWJO7nP.js";let u=0;const T=1e3;function w(n){const s=performance.now();s-u<T||(u=s,R.debug("voice","mic.gate.click_rejected",{reason:n}))}function y(){const n=o(t=>t.isRecording),s=o(t=>t.error),i=o(t=>t.loadingProgress),r=o(m(l)),x=()=>{const t=o.getState(),{canRecord:h,reason:a}=l(t);if(t.isRecording)return t.stopRecording();if(t.wizardArmed&&!t.wizardOpen){t.openWizard();return}if(a==="error"||a==="load-timeout"){t.resetAndRetryModel();return}if(!h)return w(a);const c=b.getState().activeTabId;c&&t.startRecording(c)},d=j(r.reason,{loadingPct:i,errorMessage:s,isRecording:n}),g=r.reason==="unsupported",p=!r.canRecord,f=r.reason==="loading"?"text-fg-faint animate-pulse cursor-wait":r.reason==="error"||r.reason==="load-timeout"?"text-red-400 cursor-pointer":r.reason==="permission-denied"?"text-amber-400 cursor-pointer":r.reason==="idle"?"text-fg-faint cursor-pointer":r.reason==="unsupported"?"text-fg-faint cursor-not-allowed":n?"text-red-400 ring-2 ring-red-400 animate-pulse":"text-fg-dim hover:text-fg";return e.jsx("button",{onClick:x,disabled:g,"aria-disabled":p,"aria-label":d,title:d,"data-testid":"mic-button","data-state":r.reason,className:`p-1.5 rounded transition-colors ${f}`,children:e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"9",y:"1",width:"6",height:"12",rx:"3"}),e.jsx("path",{d:"M5 10a7 7 0 0 0 14 0"}),e.jsx("line",{x1:"12",y1:"17",x2:"12",y2:"21"}),e.jsx("line",{x1:"8",y1:"21",x2:"16",y2:"21"})]})})}function v(){const n=o(i=>i.ttsEnabled),s=o(i=>i.toggleTTS);return e.jsxs("button",{onClick:s,title:n?"Read Claude replies aloud: ON":"Read Claude replies aloud: OFF",className:`px-1.5 py-1 rounded transition-colors flex items-center gap-1 ${n?"text-accent":"text-fg-dim hover:text-fg"}`,children:[e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),n?e.jsxs(e.Fragment,{children:[e.jsx("path",{d:"M15.54 8.46a5 5 0 0 1 0 7.07"}),e.jsx("path",{d:"M19.07 4.93a10 10 0 0 1 0 14.14"})]}):e.jsxs(e.Fragment,{children:[e.jsx("line",{x1:"23",y1:"9",x2:"17",y2:"15"}),e.jsx("line",{x1:"17",y1:"9",x2:"23",y2:"15"})]})]}),e.jsx("span",{className:"text-[10px] font-medium tracking-wide",children:"TTS"})]})}export{v as T,y as V};
|