claude-code-session-manager 0.134.0 → 0.135.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/dist/assets/{AgentLibrary-C9KFGJQq.js → AgentLibrary-DRlcF1YD.js} +1 -1
  2. package/dist/assets/{AppSettings-CvVQ6ot5.js → AppSettings-CBhYHKGI.js} +1 -1
  3. package/dist/assets/{Button-BHvploNk.js → Button-DtBUGvGI.js} +1 -1
  4. package/dist/assets/{DocumentEditorPane-DaX4xag_.js → DocumentEditorPane-C82c7Qtl.js} +1 -1
  5. package/dist/assets/{Extensions-DbRY-KEz.js → Extensions-Kn-oUD2_.js} +2 -2
  6. package/dist/assets/{History-BE_mjM24.js → History-B4c3Uz9u.js} +1 -1
  7. package/dist/assets/{Library-I37dQ6pB.js → Library-1RpLT-aH.js} +1 -1
  8. package/dist/assets/{ListDetail-DJYMWYQd.js → ListDetail-xr0oxNkv.js} +1 -1
  9. package/dist/assets/{Panel-DP8eSKSs.js → Panel-O8XPrpJu.js} +1 -1
  10. package/dist/assets/{ProjectClaudeConfig-Cw8lc3Qi.js → ProjectClaudeConfig-DBGhhzg2.js} +1 -1
  11. package/dist/assets/{ProvenanceBadge-DUwhsmdA.js → ProvenanceBadge-DSaizfZL.js} +1 -1
  12. package/dist/assets/{Scheduler-B9D2gZqs.js → Scheduler-D2_5NyiR.js} +1 -1
  13. package/dist/assets/{Settings-DSk7bn-1.js → Settings-Clgqb3Lq.js} +1 -1
  14. package/dist/assets/{SkillReferenceGraph-DtJcJJHR.js → SkillReferenceGraph-D80RA7kR.js} +1 -1
  15. package/dist/assets/{Skills-BPZnSjsB.js → Skills-DNG7tHSf.js} +1 -1
  16. package/dist/assets/{SourceChip-DUxulNOp.js → SourceChip-D-Imzszd.js} +1 -1
  17. package/dist/assets/{SystemPrompt-BXAugVle.js → SystemPrompt-CGlOpUQA.js} +1 -1
  18. package/dist/assets/{TiptapBody-CDC1vrOo.js → TiptapBody-CJFGfBdz.js} +1 -1
  19. package/dist/assets/{Toggle-CrgM7OTR.js → Toggle-0Ff0bPa_.js} +1 -1
  20. package/dist/assets/{ViewTabs-DLwaU9RB.js → ViewTabs-BCMYQwo_.js} +1 -1
  21. package/dist/assets/{VoiceButton-C4hIBxIP.js → VoiceButton-JzyC6DAB.js} +1 -1
  22. package/dist/assets/{historyTotals-itA00dXm.js → historyTotals-B01WPBwh.js} +1 -1
  23. package/dist/assets/{index-Cjt8B7H9.css → index-CjQ_p5y7.css} +1 -1
  24. package/dist/assets/{index-Cznhnxhq.js → index-rt7pTODX.js} +362 -362
  25. package/dist/index.html +2 -2
  26. package/dist-web/app.css +1 -1
  27. package/dist-web/app.js +392 -392
  28. package/package.json +1 -1
  29. package/plugins/session-manager-dev/skills/develop/standards.md +1 -1
  30. package/src/main/build-info.json +4 -4
  31. package/src/main/lib/persona-macro/macroJobDispatch.cjs +3 -2
  32. package/src/main/lib/persona-macro/shippedPersonaSeeds.cjs +11 -0
  33. package/src/main/lib/prd/prdFrontmatter.cjs +25 -1
  34. package/src/main/lib/scheduler/scheduleJobSchema.cjs +3 -0
  35. package/src/main/promptSessionEvents.cjs +7 -1
  36. package/src/main/runVerify.cjs +2 -2
  37. package/src/main/scheduler/prdParser.cjs +17 -1
  38. package/src/main/scheduler.cjs +137 -15
  39. package/src/main/templates/PRD_AUTHORING.md +2 -2
  40. package/src/preload/api.d.ts +8 -2
  41. package/src/seed/agents/project-home-builder.md +4 -2
@@ -1,4 +1,4 @@
1
- import{aV as Ce,aH as ie,am as Ee,b2 as xs,ar as Se,al as ue,ap as te,b7 as H,bo as Le,bn as pe,br as _t,aO as f,aj as xe,bx as ms,ay as t,d as Ve,I as me,L as bt,q as bs,K as ge,v as ws,W as vs,f as js,Y as Ns,b1 as ys,bl as st,be as ks,aZ as Ss,ag as wt,aF as Tt,bw as $e,S as Fe,aM as _e,b as nt,b0 as at,V as Ot,z as Lt,p as Ft,r as $s,n as rt,N as it,O as Cs,h as re,i as B,an as qt,bp as Ps,aN as Ds,y as As,aQ as Bt,bA as Ht,_ as Rs,aT as Ue,aI as vt,bf as jt,m as ye,G as Nt,aX as yt,l as Ms,b5 as Is,a5 as Es,w as Gt,X as _s,bs as kt,a$ as Ts}from"./index-Cznhnxhq.js";import{f as Os,a as Ls,s as Fs}from"./historyTotals-itA00dXm.js";import"./monaco-editor-BsIlgG7c.js";function qs(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 Bs(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 Hs(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=Bs(c,s),x=n.has(c.slug);u.add(c.slug);const m=x?[]:(l.get(c.slug)??[]).filter(w=>!u.has(w.slug)).map(w=>o(w,p+1,u));return u.delete(c.slug),{row:c,depth:p,children:m,blockers:h,blocked:h.some(w=>!w.missing&&w.status!=="completed"),hasNeedsReviewBlocker:h.some(w=>w.needsReview),hasMissingDep:h.some(w=>w.missing),cycle:x,parallelEligible:(c.dependsOn??[]).length===0&&!d.has(c.slug)}}return i.map(c=>o(c,0,new Set))}function Wt(e,s,n){const a=new Map((n??e).map(c=>[c.slug,c])),d=qs(e),l=[],i=new Map,r=new Map;for(const c of e){const p=Ce(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=Hs(u,a,d),x={};for(const m of u){const w=m.status??"unknown";x[w]=(x[w]??0)+1}return{epicId:p.epicId,label:p.label,known:p.known,nodes:h,counts:x,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 qe(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 Je(e){return String(e??"").replace(/^\d+-/,"")}function Te(e){const s=new Set,n=new Map;for(const a of e){s.add(a.slug);const d=Je(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(Je(r));return o&&o.length===1?(l=!0,o[0]):r});return l?{...a,dependsOn:i}:a})}const Gs=15e4,Xe=e=>e==="completed"||e==="skipped",ke=e=>e==="running"||e==="investigating",Vt=e=>e==="failed"||e==="needs_review"||e==="quarantined",Ws=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))}%`:Ee(s)}function Vs(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?Gs:s/n}function Oe(e){const s=ie(e);return s===null?1/0:Number(s)}function Ze(e,s){const n=Oe(e.slug)-Oe(s.slug);return n!==0&&!Number.isNaN(n)?n:e.slug.localeCompare(s.slug)}function Us(e){let s=0;for(const n of e.statusHistory??[])n.to==="pending"&&n.from!==null&&s++;return s}function zs(e){return e.some(n=>ke(n.status))?"active":e.every(n=>Xe(n.status))?"done":e.filter(n=>n.status!=="quarantined").length===0?"draft":"queued"}function Qs(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 Ys(e,s){return e._firstNum!==s._firstNum?e._firstNum<s._firstNum?-1:1:e._firstSlug.localeCompare(s._firstSlug)}function Ks(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 Js(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 Ks(e,s)}function Xs(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 Zs(e,s){const n=new Map(e.map(r=>[r.row.slug,r])),a=new Set,d=[],l=e.filter(r=>Je(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:Xs(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 Js(i,r))d.push({nodes:o,validateSlug:null})}return d}function en(e){return e.replace(/^validate[\s:-]*/i,"").trim()}function lt(e,s){if(e.length===0)return[];const n=Te(e),a=s.now??Date.now(),d=s.avgDurationMs??Vs(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=Wt(n,s.sessions,n),p=[];for(const u of c){const h=qe(u.nodes),x=new Set(h.map(S=>S.row.slug)),m=new Map(h.map(S=>[S.row.slug,S])),w=[];for(const S of Zs(h,x)){const y=S.nodes,O=new Set(y.map(j=>j.row.slug)),k=new Map,E=new Set,D=j=>{const $=m.get(j);return($.row.dependsOn??[]).filter(q=>O.has(q)&&!($.cycle&&m.get(q).cycle))},P=j=>{const $=k.get(j);if($!==void 0)return $;if(E.has(j))return 0;E.add(j);let q=0;for(const W of D(j))q=Math.max(q,P(W));return E.delete(j),k.set(j,q+1),q+1};for(const j of y)P(j.row.slug);const T=y.map(j=>{const $=j.row,q=($.dependsOn??[]).filter(W=>x.has(W));return{slug:$.slug,title:$.title,status:$.status,stage:k.get($.slug),prdNumber:ie($.slug),rowKind:"dep",rowTrailing:"",cycle:j.cycle,estimateMinutes:$.estimateMinutes??null,deps:q,crossEpicDeps:($.dependsOn??[]).filter(W=>!x.has(W)),blockers:j.blockers,job:$}});T.sort(Ze);const K=T.reduce((j,$)=>Math.max(j,$.stage),0),V=new Map;for(const j of T){const $=j.job,q=m.get(j.slug),W=$.status;let U;if(Xe(W)){const g=$.startedAt&&$.finishedAt?Date.parse($.finishedAt)-Date.parse($.startedAt):NaN;U={kind:"done",trailing:g>0?Ee(g):"",held:!1,blocked:!1}}else if(ke(W)){const g=$.startedAt?Math.max(0,a-Date.parse($.startedAt)):null;U={kind:"running",trailing:g===null?"":zt($,g),held:!1,blocked:!1}}else if(W==="failed")U={kind:"failed",trailing:"failed",held:!1,blocked:!1};else if(W==="needs_review")U={kind:"review",trailing:"review",held:!1,blocked:!1};else if(W==="quarantined")U={kind:"quarantined",trailing:"quarantined",held:!1,blocked:!1};else{const g=q.blockers.filter(v=>!v.missing&&v.status!=="completed");if(g.length>0){const v=g.some(C=>Ws(C.status)),A=g[0].slug;U={kind:"dep",trailing:`←${ie(A)??A}`,held:!v,blocked:v}}else if($.heldReason)U={kind:"gate",trailing:"gate",held:!0,blocked:!1};else{const v=Us($),A=o.get($.slug)??0;U=v>0?{kind:"retry",trailing:`${v} ${v===1?"retry":"retries"}`,held:!1,blocked:!1}:{kind:"eta",trailing:Ut(A*d/l),held:!1,blocked:!1}}}V.set(j.slug,U)}const z=[];for(let j=1;j<=K;j++){const $=T.filter(_=>_.stage===j),q=$.find(_=>{const Z=V.get(_.slug).kind;return _.status==="pending"&&(Z==="eta"||Z==="retry")});if(q){const _=V.get(q.slug);_.kind="next",_.trailing="next"}let W=0,U=0,g=0,v=0,A=0,C=0;for(const _ of $){const Z=V.get(_.slug);_.rowKind=Z.kind,_.rowTrailing=Z.trailing,Xe(_.status)?W++:ke(_.status)?U++:_.status==="pending"?(A++,Z.held&&g++,Z.blocked&&v++):Vt(_.status)&&C++}const M=W===$.length?"done":U>0?"running":v+C>0?"blocked":g>0?"held":"pending",L={n:j,rows:$,doneCount:W,runningCount:U,heldCount:g,blockedCount:v};z.push({...L,state:M,summary:Qs(M,L,A,C)})}let J=0;for(const j of T){const $=j.estimateMinutes?j.estimateMinutes*6e4:d;if(j.status==="pending")J+=$;else if(ke(j.status)){const q=j.job.startedAt?Math.max(0,a-Date.parse(j.job.startedAt)):0;J+=Math.max(0,$-q)}}const X=T.reduce((j,$)=>Math.min(j,Oe($.slug)),1/0),se=T.reduce((j,$)=>Math.max(j,Oe($.slug)),-1/0),Y=u.known?xs(u.label).title:u.label,R=S.validateSlug?T.find(j=>j.slug===S.validateSlug):void 0,F=R&&en(R.title)||Y;w.push({epicId:u.epicId,waveIndex:0,index:0,label:F,epicLabel:Y,validateSlug:S.validateSlug,width:z.reduce((j,$)=>Math.max(j,$.rows.length),0),status:zs(T),prdCount:T.length,stageCount:K,doneCount:z.reduce((j,$)=>j+$.doneCount,0),runningCount:z.reduce((j,$)=>j+$.runningCount,0),heldCount:z.reduce((j,$)=>j+$.heldCount,0),blockedCount:z.reduce((j,$)=>j+$.blockedCount,0),etaMs:J/l,stages:z,_firstNum:X,_lastNum:se,_firstSlug:T[0].slug})}w.sort(Ys),w.forEach((S,y)=>{S.waveIndex=y+1});const N=w.filter(S=>S.validateSlug===null);N.forEach((S,y)=>{N.length>1&&(S.label=`${S.label} · plan ${y+1}/${N.length}`)});for(const S of w)p.push(S)}return p.sort((u,h)=>{if(u._lastNum!==h._lastNum)return u._lastNum>h._lastNum?-1:1;const x=(u.epicId??"").localeCompare(h.epicId??"");return x!==0?x:u.waveIndex-h.waveIndex}),p.map(({_firstNum:u,_lastNum:h,_firstSlug:x,...m},w)=>({...m,index:w+1}))}function tn(e,s=Date.now()){const n=Te(e),a=new Map(n.map(x=>[x.slug,x])),d=new Date(s).toDateString();let l=0,i=0,r=0,o=0,c=0,p=0,u=0;for(const x of n)x.status==="pending"?(i++,(x.dependsOn??[]).every(w=>a.get(w)===void 0||a.get(w).status==="completed")&&l++):ke(x.status)?u++:x.status==="failed"?r++:x.status==="needs_review"?o++:x.status==="quarantined"?c++:x.status==="completed"&&x.finishedAt&&new Date(Date.parse(x.finishedAt)).toDateString()===d&&p++;let h=null;if(r+o+c>0){for(const x of lt(n,{sessions:{},now:s}))for(const m of x.stages)if(m.rows.some(w=>Vt(w.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 sn(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 w=i(m);(!h||l(w,h))&&(h=w)}d.delete(o);const x=h?{chain:[...h.chain,o],est:h.est+u}:{chain:[o],est:u};return a.set(o,x),x};let r=null;for(const o of s.keys()){const c=i(o);(!r||l(c,r))&&(r=c)}return r?r.chain:[]}const nn=300*6e4,an={five_hour:"5-hour",session:"5-hour",weekly_all:"weekly",weekly:"weekly"};function rn(e){return an[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 y of l)y.status==="pending"?u++:y.status==="completed"&&h++;const x=a.length,m=u+x,w=(p==null?void 0:p.cap)??5;if(x>0){const y=a.reduce((P,T)=>(P.startedAt??"")<(T.startedAt??"")?P:T),O=y.startedAt?s-Date.parse(y.startedAt):0,k=h+x,E=h+m,D=x>1?` · ${x}/${w} parallel`:"";return{kind:"running",line1:`Running ${k}/${E}${D} · ${Se(O)}`,line2:x===1?y.title:a.map(P=>P.title).join(", "),tooltip:a.map(P=>`${P.slug} (g${P.parallelGroup})`).join("; ")}}if(i){const y=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":y!==null&&y>0?`auto-resume ${ue(Date.parse(i.resumeAt))} (in ${te(y)})`: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 S=d.utilizationThreshold??90;if(o==null)return{kind:"auto-soon",line1:`Auto · ${u} pending`,line2:"checking token availability…"};if(o>=S){const y=r?Date.parse(r)-s:null,O=c?rn(c):null,k=y===null||Number.isNaN(y)||y>nn,E=y&&y>0?`resets ${ue(Date.parse(r))} (in ${te(y)})`:null;let D;return k?D=`${O??"binding"} window — long hold${E?`, ${E}`:", reset time unknown"}`:D=E?`${O?`${O} window `:""}next ${E}`:"will fire when usage drops",{kind:"auto-throttled",line1:`Auto · throttled (util ${o.toFixed(0)}% ≥ ${S}%)`,line2:D}}return{kind:"auto-soon",line1:`Auto · ${u} pending · util ${o.toFixed(0)}%`,line2:"fires within 2 min (poll cycle)"}}const ln=15e3,on=new Set(["failed","needs_review","quarantined"]);function dn(e){for(let s=e.parentElement;s;s=s.parentElement){const n=getComputedStyle(s).overflowY;if(n==="auto"||n==="scroll")return s}return null}function St(){const s=Array.from(document.querySelectorAll("[data-job-row]")).find(a=>on.has(a.dataset.jobStatus??""));if(!s)return;const n=dn(s);n&&Ss(n,s,{block:"nearest",behavior:"smooth"})}function cn(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 un(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,ln);return()=>{i=!1,clearInterval(p)}},[e,l]),s}const pn={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 fn(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 hn(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 gn({now:e}){const s=Le(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:hn(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,x])=>`${h}=${x}`).join(" ")}),")",u.claudeVersion?` since CLI ${u.claudeVersion}`:"","."]}),t.jsx("div",{className:"opacity-80",children:u.hint})]})},`launch-mitigation-${p}`))]})}function xn({scopeCwd:e,subView:s,onSubView:n,filterText:a,onFilterText:d,planMode:l,onPlanMode:i,planToolsRef:r}){const o=Le(C=>C.snapshot),c=pe(C=>C.sessions),p=un(e),u=_t(),[h,x]=f.useState(()=>Date.now()),[m,w]=f.useState("—");f.useEffect(()=>{const C=setInterval(()=>x(Date.now()),3e4);return()=>clearInterval(C)},[]),f.useEffect(()=>{let C=!0;return Os(30).then(M=>{if(!C||!M.ok||!M.data)return;const L=new Date,_=Be=>String(Be).padStart(2,"0"),Z=`${L.getFullYear()}-${_(L.getMonth()+1)}-${_(L.getDate())}`;w(Ls(Fs(M.data,{day:Z})))}),()=>{C=!1}},[]);const N=f.useMemo(()=>((o==null?void 0:o.jobs)??[]).filter(C=>!e||C.cwd===e),[o,e]),S=f.useMemo(()=>tn(N,h),[N,h]),y=f.useMemo(()=>{const C=lt(N,{sessions:c,now:h}),M=L=>C.filter(_=>_.status===L).length;return{active:M("active"),queued:M("queued"),draft:M("draft")}},[N,c,h]),O=f.useMemo(()=>{const C=new Date(h).toDateString(),M=[];for(const L of N)if(L.status==="completed"&&L.startedAt&&L.finishedAt&&new Date(Date.parse(L.finishedAt)).toDateString()===C){const _=Date.parse(L.finishedAt)-Date.parse(L.startedAt);_>0&&M.push(_)}return M.length?Math.round(M.reduce((L,_)=>L+_,0)/M.length/6e4):null},[N,h]);if(!o)return null;const k=p&&!p.unknown?p.verdict??null:null,E=p&&!p.unknown?p.slots??null:null,D=o.paused,P=fn((k==null?void 0:k.kind)??null,!!D,S.inFlight),T=pn[P],K=N.filter(C=>C.status==="pending").length,V=N.filter(C=>C.status==="running").length,z=Qt({snap:{...o,jobs:N},now:h,avgDurationMs:0,runningJobs:N.filter(C=>C.status==="running")}),J=p!=null&&p.unknown?`Queue health: unknown — ${p.reason??"state unavailable"}`:k?cn(k,(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=[J,z.line1,k?`dispatchable ${k.dispatchable} · needs_review ${k.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(`
1
+ import{aV as Ce,aH as ie,am as Ee,b2 as xs,ar as Se,al as ue,ap as te,b7 as H,bo as Le,bn as pe,br as _t,aO as f,aj as xe,bx as ms,ay as t,d as Ve,I as me,L as bt,q as bs,K as ge,v as ws,W as vs,f as js,Y as Ns,b1 as ys,bl as st,be as ks,aZ as Ss,ag as wt,aF as Tt,bw as $e,S as Fe,aM as _e,b as nt,b0 as at,V as Ot,z as Lt,p as Ft,r as $s,n as rt,N as it,O as Cs,h as re,i as B,an as qt,bp as Ps,aN as Ds,y as As,aQ as Bt,bA as Ht,_ as Rs,aT as Ue,aI as vt,bf as jt,m as ye,G as Nt,aX as yt,l as Ms,b5 as Is,a5 as Es,w as Gt,X as _s,bs as kt,a$ as Ts}from"./index-rt7pTODX.js";import{f as Os,a as Ls,s as Fs}from"./historyTotals-B01WPBwh.js";import"./monaco-editor-BsIlgG7c.js";function qs(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 Bs(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 Hs(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=Bs(c,s),x=n.has(c.slug);u.add(c.slug);const m=x?[]:(l.get(c.slug)??[]).filter(w=>!u.has(w.slug)).map(w=>o(w,p+1,u));return u.delete(c.slug),{row:c,depth:p,children:m,blockers:h,blocked:h.some(w=>!w.missing&&w.status!=="completed"),hasNeedsReviewBlocker:h.some(w=>w.needsReview),hasMissingDep:h.some(w=>w.missing),cycle:x,parallelEligible:(c.dependsOn??[]).length===0&&!d.has(c.slug)}}return i.map(c=>o(c,0,new Set))}function Wt(e,s,n){const a=new Map((n??e).map(c=>[c.slug,c])),d=qs(e),l=[],i=new Map,r=new Map;for(const c of e){const p=Ce(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=Hs(u,a,d),x={};for(const m of u){const w=m.status??"unknown";x[w]=(x[w]??0)+1}return{epicId:p.epicId,label:p.label,known:p.known,nodes:h,counts:x,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 qe(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 Je(e){return String(e??"").replace(/^\d+-/,"")}function Te(e){const s=new Set,n=new Map;for(const a of e){s.add(a.slug);const d=Je(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(Je(r));return o&&o.length===1?(l=!0,o[0]):r});return l?{...a,dependsOn:i}:a})}const Gs=15e4,Xe=e=>e==="completed"||e==="skipped",ke=e=>e==="running"||e==="investigating",Vt=e=>e==="failed"||e==="needs_review"||e==="quarantined",Ws=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))}%`:Ee(s)}function Vs(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?Gs:s/n}function Oe(e){const s=ie(e);return s===null?1/0:Number(s)}function Ze(e,s){const n=Oe(e.slug)-Oe(s.slug);return n!==0&&!Number.isNaN(n)?n:e.slug.localeCompare(s.slug)}function Us(e){let s=0;for(const n of e.statusHistory??[])n.to==="pending"&&n.from!==null&&s++;return s}function zs(e){return e.some(n=>ke(n.status))?"active":e.every(n=>Xe(n.status))?"done":e.filter(n=>n.status!=="quarantined").length===0?"draft":"queued"}function Qs(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 Ys(e,s){return e._firstNum!==s._firstNum?e._firstNum<s._firstNum?-1:1:e._firstSlug.localeCompare(s._firstSlug)}function Ks(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 Js(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 Ks(e,s)}function Xs(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 Zs(e,s){const n=new Map(e.map(r=>[r.row.slug,r])),a=new Set,d=[],l=e.filter(r=>Je(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:Xs(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 Js(i,r))d.push({nodes:o,validateSlug:null})}return d}function en(e){return e.replace(/^validate[\s:-]*/i,"").trim()}function lt(e,s){if(e.length===0)return[];const n=Te(e),a=s.now??Date.now(),d=s.avgDurationMs??Vs(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=Wt(n,s.sessions,n),p=[];for(const u of c){const h=qe(u.nodes),x=new Set(h.map(S=>S.row.slug)),m=new Map(h.map(S=>[S.row.slug,S])),w=[];for(const S of Zs(h,x)){const y=S.nodes,O=new Set(y.map(j=>j.row.slug)),k=new Map,E=new Set,D=j=>{const $=m.get(j);return($.row.dependsOn??[]).filter(q=>O.has(q)&&!($.cycle&&m.get(q).cycle))},P=j=>{const $=k.get(j);if($!==void 0)return $;if(E.has(j))return 0;E.add(j);let q=0;for(const W of D(j))q=Math.max(q,P(W));return E.delete(j),k.set(j,q+1),q+1};for(const j of y)P(j.row.slug);const T=y.map(j=>{const $=j.row,q=($.dependsOn??[]).filter(W=>x.has(W));return{slug:$.slug,title:$.title,status:$.status,stage:k.get($.slug),prdNumber:ie($.slug),rowKind:"dep",rowTrailing:"",cycle:j.cycle,estimateMinutes:$.estimateMinutes??null,deps:q,crossEpicDeps:($.dependsOn??[]).filter(W=>!x.has(W)),blockers:j.blockers,job:$}});T.sort(Ze);const K=T.reduce((j,$)=>Math.max(j,$.stage),0),V=new Map;for(const j of T){const $=j.job,q=m.get(j.slug),W=$.status;let U;if(Xe(W)){const g=$.startedAt&&$.finishedAt?Date.parse($.finishedAt)-Date.parse($.startedAt):NaN;U={kind:"done",trailing:g>0?Ee(g):"",held:!1,blocked:!1}}else if(ke(W)){const g=$.startedAt?Math.max(0,a-Date.parse($.startedAt)):null;U={kind:"running",trailing:g===null?"":zt($,g),held:!1,blocked:!1}}else if(W==="failed")U={kind:"failed",trailing:"failed",held:!1,blocked:!1};else if(W==="needs_review")U={kind:"review",trailing:"review",held:!1,blocked:!1};else if(W==="quarantined")U={kind:"quarantined",trailing:"quarantined",held:!1,blocked:!1};else{const g=q.blockers.filter(v=>!v.missing&&v.status!=="completed");if(g.length>0){const v=g.some(C=>Ws(C.status)),A=g[0].slug;U={kind:"dep",trailing:`←${ie(A)??A}`,held:!v,blocked:v}}else if($.heldReason)U={kind:"gate",trailing:"gate",held:!0,blocked:!1};else{const v=Us($),A=o.get($.slug)??0;U=v>0?{kind:"retry",trailing:`${v} ${v===1?"retry":"retries"}`,held:!1,blocked:!1}:{kind:"eta",trailing:Ut(A*d/l),held:!1,blocked:!1}}}V.set(j.slug,U)}const z=[];for(let j=1;j<=K;j++){const $=T.filter(_=>_.stage===j),q=$.find(_=>{const Z=V.get(_.slug).kind;return _.status==="pending"&&(Z==="eta"||Z==="retry")});if(q){const _=V.get(q.slug);_.kind="next",_.trailing="next"}let W=0,U=0,g=0,v=0,A=0,C=0;for(const _ of $){const Z=V.get(_.slug);_.rowKind=Z.kind,_.rowTrailing=Z.trailing,Xe(_.status)?W++:ke(_.status)?U++:_.status==="pending"?(A++,Z.held&&g++,Z.blocked&&v++):Vt(_.status)&&C++}const M=W===$.length?"done":U>0?"running":v+C>0?"blocked":g>0?"held":"pending",L={n:j,rows:$,doneCount:W,runningCount:U,heldCount:g,blockedCount:v};z.push({...L,state:M,summary:Qs(M,L,A,C)})}let J=0;for(const j of T){const $=j.estimateMinutes?j.estimateMinutes*6e4:d;if(j.status==="pending")J+=$;else if(ke(j.status)){const q=j.job.startedAt?Math.max(0,a-Date.parse(j.job.startedAt)):0;J+=Math.max(0,$-q)}}const X=T.reduce((j,$)=>Math.min(j,Oe($.slug)),1/0),se=T.reduce((j,$)=>Math.max(j,Oe($.slug)),-1/0),Y=u.known?xs(u.label).title:u.label,R=S.validateSlug?T.find(j=>j.slug===S.validateSlug):void 0,F=R&&en(R.title)||Y;w.push({epicId:u.epicId,waveIndex:0,index:0,label:F,epicLabel:Y,validateSlug:S.validateSlug,width:z.reduce((j,$)=>Math.max(j,$.rows.length),0),status:zs(T),prdCount:T.length,stageCount:K,doneCount:z.reduce((j,$)=>j+$.doneCount,0),runningCount:z.reduce((j,$)=>j+$.runningCount,0),heldCount:z.reduce((j,$)=>j+$.heldCount,0),blockedCount:z.reduce((j,$)=>j+$.blockedCount,0),etaMs:J/l,stages:z,_firstNum:X,_lastNum:se,_firstSlug:T[0].slug})}w.sort(Ys),w.forEach((S,y)=>{S.waveIndex=y+1});const N=w.filter(S=>S.validateSlug===null);N.forEach((S,y)=>{N.length>1&&(S.label=`${S.label} · plan ${y+1}/${N.length}`)});for(const S of w)p.push(S)}return p.sort((u,h)=>{if(u._lastNum!==h._lastNum)return u._lastNum>h._lastNum?-1:1;const x=(u.epicId??"").localeCompare(h.epicId??"");return x!==0?x:u.waveIndex-h.waveIndex}),p.map(({_firstNum:u,_lastNum:h,_firstSlug:x,...m},w)=>({...m,index:w+1}))}function tn(e,s=Date.now()){const n=Te(e),a=new Map(n.map(x=>[x.slug,x])),d=new Date(s).toDateString();let l=0,i=0,r=0,o=0,c=0,p=0,u=0;for(const x of n)x.status==="pending"?(i++,(x.dependsOn??[]).every(w=>a.get(w)===void 0||a.get(w).status==="completed")&&l++):ke(x.status)?u++:x.status==="failed"?r++:x.status==="needs_review"?o++:x.status==="quarantined"?c++:x.status==="completed"&&x.finishedAt&&new Date(Date.parse(x.finishedAt)).toDateString()===d&&p++;let h=null;if(r+o+c>0){for(const x of lt(n,{sessions:{},now:s}))for(const m of x.stages)if(m.rows.some(w=>Vt(w.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 sn(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 w=i(m);(!h||l(w,h))&&(h=w)}d.delete(o);const x=h?{chain:[...h.chain,o],est:h.est+u}:{chain:[o],est:u};return a.set(o,x),x};let r=null;for(const o of s.keys()){const c=i(o);(!r||l(c,r))&&(r=c)}return r?r.chain:[]}const nn=300*6e4,an={five_hour:"5-hour",session:"5-hour",weekly_all:"weekly",weekly:"weekly"};function rn(e){return an[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 y of l)y.status==="pending"?u++:y.status==="completed"&&h++;const x=a.length,m=u+x,w=(p==null?void 0:p.cap)??5;if(x>0){const y=a.reduce((P,T)=>(P.startedAt??"")<(T.startedAt??"")?P:T),O=y.startedAt?s-Date.parse(y.startedAt):0,k=h+x,E=h+m,D=x>1?` · ${x}/${w} parallel`:"";return{kind:"running",line1:`Running ${k}/${E}${D} · ${Se(O)}`,line2:x===1?y.title:a.map(P=>P.title).join(", "),tooltip:a.map(P=>`${P.slug} (g${P.parallelGroup})`).join("; ")}}if(i){const y=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":y!==null&&y>0?`auto-resume ${ue(Date.parse(i.resumeAt))} (in ${te(y)})`: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 S=d.utilizationThreshold??90;if(o==null)return{kind:"auto-soon",line1:`Auto · ${u} pending`,line2:"checking token availability…"};if(o>=S){const y=r?Date.parse(r)-s:null,O=c?rn(c):null,k=y===null||Number.isNaN(y)||y>nn,E=y&&y>0?`resets ${ue(Date.parse(r))} (in ${te(y)})`:null;let D;return k?D=`${O??"binding"} window — long hold${E?`, ${E}`:", reset time unknown"}`:D=E?`${O?`${O} window `:""}next ${E}`:"will fire when usage drops",{kind:"auto-throttled",line1:`Auto · throttled (util ${o.toFixed(0)}% ≥ ${S}%)`,line2:D}}return{kind:"auto-soon",line1:`Auto · ${u} pending · util ${o.toFixed(0)}%`,line2:"fires within 2 min (poll cycle)"}}const ln=15e3,on=new Set(["failed","needs_review","quarantined"]);function dn(e){for(let s=e.parentElement;s;s=s.parentElement){const n=getComputedStyle(s).overflowY;if(n==="auto"||n==="scroll")return s}return null}function St(){const s=Array.from(document.querySelectorAll("[data-job-row]")).find(a=>on.has(a.dataset.jobStatus??""));if(!s)return;const n=dn(s);n&&Ss(n,s,{block:"nearest",behavior:"smooth"})}function cn(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 un(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,ln);return()=>{i=!1,clearInterval(p)}},[e,l]),s}const pn={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 fn(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 hn(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 gn({now:e}){const s=Le(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:hn(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,x])=>`${h}=${x}`).join(" ")}),")",u.claudeVersion?` since CLI ${u.claudeVersion}`:"","."]}),t.jsx("div",{className:"opacity-80",children:u.hint})]})},`launch-mitigation-${p}`))]})}function xn({scopeCwd:e,subView:s,onSubView:n,filterText:a,onFilterText:d,planMode:l,onPlanMode:i,planToolsRef:r}){const o=Le(C=>C.snapshot),c=pe(C=>C.sessions),p=un(e),u=_t(),[h,x]=f.useState(()=>Date.now()),[m,w]=f.useState("—");f.useEffect(()=>{const C=setInterval(()=>x(Date.now()),3e4);return()=>clearInterval(C)},[]),f.useEffect(()=>{let C=!0;return Os(30).then(M=>{if(!C||!M.ok||!M.data)return;const L=new Date,_=Be=>String(Be).padStart(2,"0"),Z=`${L.getFullYear()}-${_(L.getMonth()+1)}-${_(L.getDate())}`;w(Ls(Fs(M.data,{day:Z})))}),()=>{C=!1}},[]);const N=f.useMemo(()=>((o==null?void 0:o.jobs)??[]).filter(C=>!e||C.cwd===e),[o,e]),S=f.useMemo(()=>tn(N,h),[N,h]),y=f.useMemo(()=>{const C=lt(N,{sessions:c,now:h}),M=L=>C.filter(_=>_.status===L).length;return{active:M("active"),queued:M("queued"),draft:M("draft")}},[N,c,h]),O=f.useMemo(()=>{const C=new Date(h).toDateString(),M=[];for(const L of N)if(L.status==="completed"&&L.startedAt&&L.finishedAt&&new Date(Date.parse(L.finishedAt)).toDateString()===C){const _=Date.parse(L.finishedAt)-Date.parse(L.startedAt);_>0&&M.push(_)}return M.length?Math.round(M.reduce((L,_)=>L+_,0)/M.length/6e4):null},[N,h]);if(!o)return null;const k=p&&!p.unknown?p.verdict??null:null,E=p&&!p.unknown?p.slots??null:null,D=o.paused,P=fn((k==null?void 0:k.kind)??null,!!D,S.inFlight),T=pn[P],K=N.filter(C=>C.status==="pending").length,V=N.filter(C=>C.status==="running").length,z=Qt({snap:{...o,jobs:N},now:h,avgDurationMs:0,runningJobs:N.filter(C=>C.status==="running")}),J=p!=null&&p.unknown?`Queue health: unknown — ${p.reason??"state unavailable"}`:k?cn(k,(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=[J,z.line1,k?`dispatchable ${k.dispatchable} · needs_review ${k.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
2
  `),R=o.utilization,F=o.pollHealth,j=F!=null&&!F.lastPollOk,$=ms(o.utilizationWindow),q=o.nextReset?Date.parse(o.nextReset):null,W=q?q>h?te(q-h):"soon":"—",U=(u==null?void 0:u.total)??5,g=(u==null?void 0:u.envOverride)===!0,v=o.config.firePolicy??"when-available",A=K===0&&V===0;return t.jsxs("div",{"data-testid":"scheduler-top-bands",className:"shrink-0 px-[18px]",children:[t.jsxs(Ve,{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 ${T.text}`,"data-testid":"scheduler-state-word","data-state":P,children:[t.jsx("span",{className:`w-2 h-2 rounded-full ${T.dot}`,"aria-hidden":"true"}),P]}),t.jsxs("span",{className:"font-mono text-[12px] text-fg-faint whitespace-nowrap","data-testid":"scheduler-meta",children:[S.inFlight," in flight · ",S.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"}),D?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(gn,{now:h}),t.jsxs(Ve,{height:70,testId:"scheduler-kpi-band",children:[t.jsx(ge,{testId:"kpi-window",label:$?`${$} used`:"Window used",info:j?`Billing poll failing — this reading may be outdated (last good reading ${xe(F.lastPollAt,h)}). Machine-wide ${$??"binding"} window.`:`Share of the machine-wide ${$??"binding"} billing window consumed — the window closest to its limit.`,value:R==null?"—":`${Math.round(R)}%`,sub:`resets in ${W}`,third:t.jsx(ws,{pct:R??0,tone:j?"bg-amber-500":"bg-accent"})}),t.jsx(ge,{testId:"kpi-slots",label:"Slots",info:`Machine-wide session pool (${(E==null?void 0:E.source)==="env"?"SM_SESSION_SLOTS override":"Home tab cap"}), not scoped to this project`,value:E?`${E.inUse}/${E.total}`:"—",sub:"in use",third:E?t.jsx(vs,{filled:E.inUse,total:E.total}):null}),t.jsx(ge,{testId:"kpi-ready",label:"Ready now",info:"Pending rows whose dependsOn chain is fully satisfied right now",value:S.readyNow,sub:`of ${S.totalQueued} queued`,third:`${S.heldByDeps} held by deps`}),S.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:S.needsYou}),sub:t.jsx("button",{type:"button",onClick:St,className:"hover:underline",children:S.needsYouStage!=null?`blocking stage ${S.needsYouStage}`:"need attention"}),third:[S.failedCount>0&&`${S.failedCount} failed`,S.needsReviewCount>0&&`${S.needsReviewCount} needs review`,S.needsYou-S.failedCount-S.needsReviewCount>0&&`${S.needsYou-S.failedCount-S.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:S.doneToday,sub:O!=null?`avg ${O}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:v,onChange:C=>window.api.schedule.setConfig({firePolicy:C.target.value}),className:"border border-line bg-bg-hi rounded px-1 py-0.5 text-[12px] text-fg-dim",title:"when-available: poll usage and fire when tokens are below threshold. 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(Ns,{value:U,min:0,max:(u==null?void 0:u.max)??10,disabled:g,onChange:C=>{ys(C).catch(M=>{H.error(`Could not set session slots: ${M instanceof Error?M.message:String(M)}`)})},title:g?"pinned by SM_SESSION_SLOTS — unset the env var to edit":"Machine-wide claude -p session slots, shared with chat runs"}),g&&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:v==="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:C=>window.api.schedule.setConfig({utilizationThreshold:C})})]}):null})]}),t.jsxs(Ve,{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:[y.active," active · ",y.queued," queued · ",y.draft," draft · ",N.length," PRDs"]}),t.jsxs("span",{className:"ml-auto flex items-center gap-3",children:[t.jsx("span",{ref:r,className:"contents","data-testid":"scheduler-plan-tools"}),t.jsx("input",{type:"text",value:a,onChange:C=>d(C.target.value),placeholder:"filter PRDs…","aria-label":"Filter PRDs by title, slug, or project","data-testid":"scheduler-filter-input",className:"w-[180px] bg-bg-hi border border-line rounded px-2 py-0.5 text-[12px] text-fg placeholder:text-fg-faint focus:outline-none focus:border-fg-faint"}),t.jsx("span",{className:"inline-flex border border-line rounded overflow-hidden",role:"group","aria-label":"Plan view mode",children:[["graph","Graph"],["list","List"],["critical","Critical path"]].map(([C,M])=>t.jsx("button",{type:"button","data-testid":`plan-mode-${C}`,"aria-pressed":l===C&&s==="queue",onClick:()=>{i(C),n("queue")},className:`px-2 py-0.5 text-[12px] ${l===C&&s==="queue"?"bg-bg-elev font-semibold text-fg":"text-fg-dim hover:text-fg"}`,children:M},C))}),t.jsx("span",{className:"w-px h-[16px] bg-rule-structural","aria-hidden":"true"}),[["prds","PRDs","Authored PRD source files on disk — edit, lint, archive, or queue them."],["history","History","The last 50 completed and failed jobs."],["machine","Machine","Machine-wide config that applies to every project — not this project’s live queue."]].map(([C,M,L])=>t.jsx("button",{type:"button",onClick:()=>n(C),"aria-pressed":s===C,title:L,className:`text-[12.5px] ${s===C?"font-semibold text-fg":"text-fg-faint hover:text-fg-dim"}`,children:M},C))]})]})]})}function Yt({options:e,value:s,onChange:n,pillPadding:a="px-3 py-1.5"}){return t.jsx("div",{className:"flex gap-1.5 flex-wrap",children:e.map(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 Kt(e,s=60){const n=e.trim();return n.length<=s?n:`${n.slice(0,s-1)}…`}function mn(e){return qe([e]).filter(s=>s.children.length===0).map(s=>s.row.slug)}function Jt(e){return e.nodes.map(s=>({rootSlug:s.row.slug,label:s.row.title||s.row.slug,terminals:mn(s)}))}function bn(e){const s=new Map;for(const n of e){const a=Jt(n);n.nodes.forEach((d,l)=>{const i=a.filter((r,o)=>o!==l);for(const r of qe([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: ",Kt(l.label,40)]},l.rootSlug))]})}function wn(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 vn=[],jn=new Set(["failed","needs_review","quarantined"]);function Nn(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 yn(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 kn(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 Sn({row:e,elapsedMs:s,listIndex:n,onFocused:a,headChoices:d=vn}){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&&jn.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 ${yn(e)}`,children:[t.jsx("span",{"aria-hidden":"true",className:`shrink-0 w-[7px] h-[7px] rounded-full ${Nn(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] ${kn(e)}`,children:o})]}),l&&t.jsx($n,{row:e,elapsedMs:s,headChoices:d})]})}const Zt=f.memo(Sn);function $n({row:e,elapsedMs:s,headChoices:n}){const a=e.job,[d,l]=f.useState(!1),i=pe(x=>x.sessions),r=f.useMemo(()=>Ce(a,i),[a,i]),o=r.known&&r.epicId?i[r.epicId]:null,c=f.useCallback(x=>Tt(x),[]),p="font-mono text-[11.5px] text-fg-dim leading-snug break-words",u="text-[12px] font-semibold bg-transparent border-0 cursor-pointer p-0",h=a.error?a.error.split(`
3
3
  `)[0]:null;return t.jsxs("div",{"data-testid":"prd-row-detail",className:"px-3 py-2 bg-bg-elev/50 border-t border-rule-inner flex flex-col gap-1",children:[t.jsxs("div",{className:p,children:[a.status.replace(/_/g," "),a.exitCode!==null&&` · exit ${a.exitCode}`,a.verifierVerdict&&` · ${$e(a.verifierVerdict)}`,a.startedAt&&` · started ${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(x=>x.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(x=>`${x.slug} (${x.missing?"missing":(x.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(Fe,{runId:a.runId,slug:a.slug,title:a.title||a.slug,onClose:()=>l(!1)})]})}const ce=190,Cn=7,Pn=5,Dn=[],es=e=>e==="completed"||e==="skipped",ts=e=>e==="running"||e==="investigating",ss=e=>e==="failed"||e==="needs_review"||e==="quarantined";function Ae(e){return ts(e.status)?0:ss(e.status)?1:es(e.status)?3:2}const An={done:"text-sage",running:"text-accent",held:"text-fg-faint",pending:"text-fg-faint",blocked:"text-butter"},Rn={done:"bg-sage",running:"bg-accent",held:"bg-fg-faint/50",pending:"bg-fg-faint/50",blocked:"bg-butter"};function Mn(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 In({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(k=>!(a.has(k.slug)&&(k.status==="completed"||k.status==="failed"))).map((k,E)=>({r:k,i:E})).sort((k,E)=>Ae(k.r)-Ae(E.r)||k.i-E.i).map(k=>k.r),[e.rows,a]),p=f.useMemo(()=>c.filter(k=>Ae(k)<=1).length,[c]),u=Math.max(e.state==="done"?Pn:Cn,p),h=r?c:c.slice(0,u),x=r?[]:c.slice(u),m=c.find(k=>k.status==="failed"),w=c.find(k=>k.status==="needs_review"),N=p>0&&(m!==void 0||w!==void 0),S=h.reduce((k,E,D)=>Ae(E)<=1?D:k,-1),y=k=>t.jsx(Zt,{row:k,elapsedMs:ts(k.status)&&k.job.startedAt?n-Date.parse(k.job.startedAt):null,listIndex:d.get(k.slug)??0,onFocused:i,headChoices:l.get(k.slug)??Dn},k.slug),O="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 ${Rn[e.state]}`}),t.jsxs("span",{className:`text-[10px] font-semibold uppercase tracking-wide ${An[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((k,E)=>t.jsxs("div",{children:[y(k),N&&E===S&&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(D=>{D.ok||H.error(D.error??`Failed to reset ${m.slug}`)}).catch(()=>H.error(`Failed to reset ${m.slug}`))},className:O,children:["Retry ",m.prdNumber?`#${m.prdNumber}`:m.slug]}),w&&t.jsxs("button",{type:"button","data-testid":"stage-review",disabled:!s,title:s?"Open the authoring Epic — a needs_review PRD is a question routed back to it":"No authoring Epic recorded for this plan",onClick:()=>{s&&Tt(s)},className:O,children:["Review ",w.prdNumber?`#${w.prdNumber}`:w.slug]})]})]},k.slug))}),(x.length>0||r&&c.length>u)&&t.jsx("button",{type:"button","data-testid":"stage-footer","aria-expanded":r,onClick:()=>o(k=>!k),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 ▴":`${Mn(x,e.n)} ▾`})]})}const we=6,Qe=4,Ie=4,$t=12,Ct=5,ns=2,Pt=4,En={done:"bg-sage",running:"bg-accent",attention:"bg-butter",failed:"bg-red-600",pending:"bg-fg-faint/50"};function _n(e){return e==="completed"||e==="skipped"?"done":e==="running"||e==="investigating"?"running":e==="failed"?"failed":e==="needs_review"||e==="quarantined"?"attention":"pending"}function Tn(e){const s=[],n=[],a=[];let d=Ct;for(const l of e){const i=Math.max(1,Math.ceil(l.rows.length/Ie));n.push(d),a.push(i*we),l.rows.forEach((r,o)=>{s.push({x:d+Math.floor(o/Ie)*we,y:ns+o%Ie*we,tone:_n(r.status),title:`${r.prdNumber?`#${r.prdNumber}`:r.slug} ${r.title} — ${r.status}`})}),d+=i*we+$t}return{dots:s,stageX:n,stageW:a,width:Math.max(0,d-$t)+Ct}}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 On({stages:e,first:s,perView:n,onSeek:a}){const d=f.useMemo(()=>Tn(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 w=m.currentTarget.getBoundingClientRect(),N=m.clientX-w.left;let S=0;for(let y=0;y<o;y++)d.stageX[y]<=N&&(S=y);a(Math.max(0,Math.min(o-1,S-Math.floor(n/2))))},x="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:Ie*we-(we-Qe)+2*ns},onPointerDown:m=>{var w,N;r.current=!0,(N=(w=m.currentTarget).setPointerCapture)==null||N.call(w,m.pointerId),h(m)},onPointerMove:m=>{r.current&&h(m)},onPointerUp:()=>{r.current=!1},onPointerCancel:()=>{r.current=!1},children:[d.dots.map((m,w)=>t.jsx("span",{title:m.title,"data-tone":m.tone,className:`absolute rounded-[1px] ${En[m.tone]}`,style:{left:m.x,top:m.y,width:Qe,height:Qe}},w)),t.jsx("span",{"data-testid":"plan-minimap-brush","aria-hidden":"true",className:"absolute top-0 bottom-0 border border-accent bg-accent/10 rounded-[2px] pointer-events-none",style:{left:p-Pt,width:u-p+2*Pt}})]}),t.jsxs("span",{className:"ml-auto shrink-0 font-mono text-[11.5px] text-fg-faint","data-testid":"plan-minimap-range",children:["stages ",Math.min(s+1,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:`${x} 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:`${x} text-fg-dim hover:text-fg border-l border-line`,children:"Blockers"})]})]})}const Ln=148;function Fn({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:Ln},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 qn=[],Bn=e=>e==="running"||e==="investigating";function Hn(e){const s=sn(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 Gn({plan:e,now:s,indexBySlug:n,headChoicesBySlug:a,onRowFocused:d}){const l=f.useMemo(()=>Hn(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:Bn(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)??qn})}),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,Wn={active:"border-l-accent",queued:"border-l-rule-structural",done:"border-l-sage",draft:"border-l-fg-faint/40 border-dashed"},Vn={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"}},Un=e=>String(e).padStart(2,"0");function zn({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 Qn({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),[x,m]=f.useState(0),[w,N]=f.useState(At),S=f.useMemo(()=>{const R=ve(e.stages,et);return R>=0?R:Math.max(0,ve(e.stages,tt))},[e.stages]);f.useLayoutEffect(()=>{if(!o)return;const R=h.current,F=(R==null?void 0:R.clientWidth)||At,j=Math.max(0,Math.min(S,e.stageCount-Math.max(1,Math.ceil(F/ce))));R!=null&&R.clientWidth&&N(R.clientWidth),R&&(R.scrollLeft=j*ce),m(j)},[o]);const y=f.useMemo(()=>{let R=null;for(const F of e.stages)for(const j of F.rows){if(!j.job.runId)continue;const $=j.job.finishedAt?Date.parse(j.job.finishedAt):0;(!R||$>R.at)&&(R={runId:j.job.runId,slug:j.slug,title:j.title,at:$})}return R},[e.stages]),O=_e((Y=(se=e.stages[0])==null?void 0:se.rows[0])==null?void 0:Y.job.cwd)??"—",k=Vn[e.status],E=Math.max(1,Math.ceil(w/ce)),D=Math.max(0,Math.min(x-Dt,e.stageCount)),P=Math.min(e.stageCount,x+E+Dt),T=R=>{const F=Math.max(0,Math.min(e.stageCount-1,R));h.current&&(h.current.scrollLeft=F*ce),m(F)},K=Math.min(e.stageCount,x+E),V=R=>{const F=R.currentTarget,j=Math.floor(F.scrollLeft/ce);j!==x&&m(j),F.clientWidth&&F.clientWidth!==w&&N(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",J=(()=>{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:!y,title:y?`Open the run log of ${y.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 R,F;return r==null?void 0:r(((F=(R=e.stages[0])==null?void 0:R.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] ${Wn[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(R=>!R),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:Un(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 ${k.cls}`,children:k.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:[O," · ",e.epicLabel," · ",e.prdCount," PRD",e.prdCount===1?"":"s"," · ",e.width," wide · ",e.stageCount," stage",e.stageCount===1?"":"s"]}):t.jsxs(t.Fragment,{children:[O," · ",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(zn,{plan:e}),J]}),o&&s==="critical"&&t.jsx(Gn,{plan:e,now:n,indexBySlug:d,headChoicesBySlug:l,onRowFocused:i}),o&&s!=="critical"&&e.status==="active"&&t.jsx(On,{stages:e.stages,first:x,perView:E,onSeek:T}),o&&s!=="critical"&&t.jsxs("div",{className:"flex border-t border-rule-structural",children:[t.jsxs("div",{ref:h,"data-testid":"plan-stages",onScroll:V,className:"flex flex-1 min-w-0 overflow-x-auto",children:[D>0&&t.jsx("div",{"aria-hidden":"true",className:"shrink-0",style:{width:D*ce}}),e.stages.slice(D,P).map(R=>t.jsx(In,{stage:R,epicId:e.epicId,now:n,hidden:a,indexBySlug:d,headChoicesBySlug:l,onRowFocused:i},R.n)),P<e.stageCount&&t.jsx("div",{"aria-hidden":"true",className:"shrink-0",style:{width:(e.stageCount-P)*ce}})]}),t.jsx(Fn,{stages:e.stages.slice(K),onSeek:T})]}),p&&y&&t.jsx(Fe,{runId:y.runId,slug:y.slug,title:y.title||y.slug,onClose:()=>u(!1)})]})}function Yn({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 Kn=[],Jn=[],Xn={depth:0,blockers:Kn,blocked:!1,hasNeedsReviewBlocker:!1,hasMissingDep:!1,cycle:!1,parallelEligible:!1};function Zn(e){return e.missing?`${e.slug} (missing)`:e.needsReview?`${e.slug} (needs review)`:`${e.slug} (${(e.status??"unknown").replace(/_/g," ")})`}function ea(e){return e.missing?"text-accent":e.needsReview?"text-butter font-semibold":e.status==="completed"?"text-sage":"text-amber-400/90"}function ta({job:e,eta:s,elapsedMs:n,avgDurationMs:a,listIndex:d,onFocused:l,hold:i,backlog:r=Xn,headChoices:o=Jn}){const[c,p]=f.useState(!1),[u,h]=f.useState(!1),x=pe(P=>P.sessions),m=f.useMemo(()=>Ce(e,x),[e,x]),w=m.known&&m.epicId?x[m.epicId]:null,N=f.useCallback(P=>{at(P),window.dispatchEvent(new CustomEvent("sm:navigate",{detail:"terminal"}))},[]),S=e.status==="running",y=e.status==="failed";let O=null;S&&n!==null?O=`${Ee(n)} elapsed`:e.status==="completed"&&e.startedAt&&e.finishedAt?O=`took ${Se(Date.parse(e.finishedAt)-Date.parse(e.startedAt))}`:s&&(O=s);const k=e.error??null,E=y&&k?k.split(`
4
4
  `)[0]:e.status==="needs_review"&&e.verifierVerdict?$e(e.verifierVerdict):null,D=S&&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(P=>!P),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}${O?`, ${O}`:""}`,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($s,{count:e.leftoverCount,truncated:e.leftoverPathsTruncated,salvagePatch:e.salvagePatch}),r.parallelEligible&&t.jsx("span",{"data-testid":"job-row-parallel-eligible",title:"No dependsOn, and nothing in this Epic depends on it — can run any time a slot is free",className:"text-[10px] font-semibold uppercase tracking-wide text-sage/90 bg-sage/10 border border-sage/30 rounded px-1.5 py-0.5",children:"parallel"})]}),r.cycle&&t.jsxs("div",{className:"text-[12.5px] mt-0.5 text-accent font-mono","data-testid":"job-row-cycle-warning",children:["⚠ dependsOn cycle — ",r.blockers.map(P=>P.slug).join(" ↔ ")||"self-referencing"]}),!r.cycle&&r.blockers.length>0&&t.jsxs("div",{className:"text-[12.5px] mt-0.5 font-mono","data-testid":"job-row-blockers",children:[t.jsx("span",{className:r.blocked||r.hasMissingDep?"text-amber-400/90":"text-fg-faint",children:r.blocked||r.hasMissingDep?"blocked by ":"depends on "}),r.blockers.map((P,T)=>t.jsxs("span",{className:ea(P),children:[T>0&&", ",Zn(P)]},P.slug))]}),E&&t.jsx("div",{className:`text-[12.5px] mt-0.5 ${y?"text-accent/80":"text-fg-faint"}`,children:E}),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?Kt(m.label):null,onOpen:N,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}),O,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})})]})]}),S&&!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,D*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}),k&&t.jsx(B,{k:"error",v:k.split(`
@@ -1,2 +1,2 @@
1
- import{bb as A,ay as e,b7 as D,aO as b,bh as U,b8 as ee,bj as te,bq as G,x as he,m as P,a5 as fe,w as ge,U as se,aZ as be,T as _,b as ye,bs as q,bm as ve,aC as je,aG as we,J as ke,at as Ne}from"./index-Cznhnxhq.js";import{P as R}from"./Panel-DP8eSKSs.js";import{P as Se,H as Ce,S as _e}from"./Library-I37dQ6pB.js";import{S as V}from"./SourceChip-DUxulNOp.js";import{V as K}from"./ViewTabs-DLwaU9RB.js";import{r as ne}from"./claude-settings-schema-COigsajx.js";import{L as Ee}from"./ListDetail-DJYMWYQd.js";import{a as Pe}from"./ProvenanceBadge-DUwhsmdA.js";import"./monaco-editor-BsIlgG7c.js";import"./Button-BHvploNk.js";function Te(t){const n=t??{},s={...n.$defs??{},...n.definitions??{}},o=l=>{if(!l)return{};if(!l.$ref)return i(l);const m=/^#\/(\$defs|definitions)\/(.+)$/.exec(l.$ref);if(!m)return i(l);const h=s[m[2]];return h?o({...h,...u(l)}):i(l)},r=new Set(["__proto__","constructor","prototype"]),a=l=>{if(!l)return{};const m={};for(const[h,f]of Object.entries(l))r.has(h)||(m[h]=f);return m},i=l=>{if(!l.allOf||l.allOf.length===0)return l;const m={...l};delete m.allOf;for(const h of l.allOf){const f=o(h);Object.assign(m,{properties:{...a(m.properties),...a(f.properties)},required:Fe([...m.required??[],...f.required??[]])}),!m.description&&f.description&&(m.description=f.description),m.default===void 0&&f.default!==void 0&&(m.default=f.default),!m.type&&f.type&&(m.type=f.type)}return m},u=l=>{const{$ref:m,...h}=l;return h},d=(l,m)=>{let h=o(l);for(const f of m){if(!h)return null;if(/^\d+$/.test(f)){const E=Array.isArray(h.items)?h.items[Number(f)]:h.items;h=E?o(E):null;continue}const w=h.properties;if(w&&!r.has(f)&&f in w){h=o(w[f]);continue}const k=h.additionalProperties;if(k&&typeof k=="object"){h=o(k);continue}return null}return h},c=(l,m,h)=>{if(!l)return null;const f={};if(l.description&&(f.description=l.description),l.type&&(f.type=l.type),l.default!==void 0&&(f.default=l.default),l.enum&&(f.enum=l.enum),l.const!==void 0&&(f.const=l.const),l.deprecated&&(f.deprecated=!0),l.examples&&(f.examples=l.examples),l.properties&&(f.knownChildren=Object.keys(l.properties)),h&&(m!=null&&m.includes(h))&&(f.required=!0),l.items&&!Array.isArray(l.items)){const w=o(l.items),k=c(w,void 0,null);k&&(f.itemsInfo=k)}return(l.additionalProperties===!0||typeof l.additionalProperties=="object")&&(f.open=!0),f},x=l=>m=>{if(m.length===0)return c(o(l),void 0,null);const h=d(l,m.slice(0,-1));if(!h)return null;const f=m[m.length-1],w=d(h,[f]);return c(w,h.required,f)},y=l=>{const m=o(l);return Object.keys(m.properties??{})},g=l=>({at:x(l),rootKeys:()=>y(l),rootedAt:m=>{const h=d(l,m);return g(h??{})}});return g(n)}function Fe(t){return Array.from(new Set(t))}let H=null;function re(){return H||(H=Te(ne)),H}const Oe=["allow","deny","ask"],z="This settings file has invalid JSON. Fix it in the Settings raw editor first; Permissions will not overwrite it.";function Ae(t){if(t.trim()==="")return{perms:{},full:{},err:null};try{const n=JSON.parse(t);if(n===null||typeof n!="object"||Array.isArray(n))return{perms:{},full:{},err:"settings file is not a JSON object"};const s=n;return{perms:s.permissions??{},full:s,err:null}}catch(n){return{perms:{},full:{},err:n.message}}}function Me({scope:t="user"}={}){const n=U(),s=ee(),o=(s==null?void 0:s.cwd)??null,r=te(l=>l.navFace),[a,i]=b.useState("rules");b.useEffect(()=>{r==="project"&&a==="presets"&&i("rules")},[r,a]);const d=G(he,n,o)[t]??null,c=A(l=>l.files),x=e.jsx(K,{options:[{key:"rules",label:"Rules"},...r==="home"?[{key:"presets",label:"Presets"}]:[]],active:a,onChange:i});if(!n)return e.jsx(P,{title:"loading…"});if(a==="presets")return e.jsx(R,{toolbar:x,children:e.jsx(Se,{})});const y=l=>l!=="user"&&!o,g=d?c[d]:null;return e.jsx(R,{toolbar:e.jsxs(e.Fragment,{children:[x,e.jsx("span",{className:"ml-3 text-fg-faint truncate",children:d??"—"}),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:y(t)?e.jsx(P,{title:"no active project",hint:"open a tab in a project directory to edit project or local permissions"}):d&&g?e.jsx(ae,{scope:t,cwd:o,activePath:d}):e.jsx(P,{title:"resolving…"})})}b.memo(Me);function ae({scope:t,cwd:n,activePath:s}){const o=A(c=>c.files[s]),{perms:r,err:a}=o?Ae(o.draftRaw):{perms:{},err:null},i=(c,x)=>{if(a){D.error(z);return}window.api.claudeConfig.patch({fileId:"settings",scope:t,cwd:n,keyPath:["permissions",c],value:x}).catch(y=>D.error(y instanceof Error?y.message:String(y)))},u=(c,x)=>{const y=x.trim();if(!y)return;const g=r[c]??[];g.includes(y)||i(c,[...g,y])},d=(c,x)=>{const y=r[c]??[];i(c,y.filter((g,l)=>l!==x))};return e.jsxs("div",{className:"p-4 space-y-5 max-w-3xl",children:[a&&e.jsxs("div",{role:"alert",className:"text-xs text-red-400 border border-red-400/40 rounded px-3 py-2",children:[z," (",a,")"]}),e.jsx(Re,{value:r.defaultMode??"default",onChange:c=>i("defaultMode",c)}),Oe.map(c=>e.jsx($e,{list:c,rules:r[c]??[],disabled:!!a,onAdd:x=>u(c,x),onRemove:x=>d(c,x)},c)),e.jsx(Ie,{dirs:r.additionalDirectories??[],disabled:!!a,onChange:c=>i("additionalDirectories",c)})]})}function Re({value:t,onChange:n}){var a;const o=(((a=re().at(["permissions","defaultMode"]))==null?void 0:a.enum)??[]).filter(i=>typeof i=="string"),r=t&&!o.includes(t)?[...o,t]:o;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:r.map(i=>e.jsx("button",{onClick:()=>n(i),className:`px-2.5 py-1 text-xs transition-colors ${t===i?"bg-bg-hi text-fg":"bg-bg-elev text-fg-dim hover:text-fg hover:bg-bg-hi"}`,children:i},i))})]})}function $e({list:t,rules:n,onAdd:s,onRemove:o,disabled:r}){const[a,i]=b.useState(""),u=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 ${u}`,children:t}),e.jsxs("div",{className:"flex gap-2 mb-2",children:[e.jsx("input",{value:a,disabled:r,onChange:d=>i(d.target.value),onKeyDown:d=>{d.key==="Enter"&&(s(a),i(""))},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:()=>{s(a),i("")},disabled:r||!a.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"})]}),n.length===0?e.jsx("div",{className:"text-fg-faint text-xs",children:"no rules"}):e.jsx("ul",{className:"space-y-0.5",children:n.map((d,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:d}),e.jsx("button",{onClick:()=>o(c),className:"text-fg-faint hover:text-red-400",title:"remove",children:"×"})]},`${c}-${d}`))})]})}function Ie({dirs:t,onChange:n,disabled:s}){const[o,r]=b.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:o,disabled:s,onChange:a=>r(a.target.value),onKeyDown:a=>{a.key==="Enter"&&o.trim()&&(n([...t,o.trim()]),r(""))},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((a,i)=>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:a}),e.jsx("button",{onClick:()=>n(t.filter((u,d)=>d!==i)),className:"text-fg-faint hover:text-red-400",children:"×"})]},`${i}-${a}`))})]})}const De={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 }"}},oe=["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"],Le=new Set(oe),He=["command","http","prompt","agent","mcp_tool"],Ue={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:{}},Y="This settings file has invalid JSON. Fix it in the Settings raw editor first; Hooks will not overwrite it.";function Ge(t){if(t.trim()==="")return{full:{},hooks:{},err:null};try{const n=JSON.parse(t);if(n===null||typeof n!="object"||Array.isArray(n))return{full:{},hooks:{},err:"settings file is not a JSON object"};const s=n;return{full:s,hooks:s.hooks??{},err:null}}catch(n){return{full:{},hooks:{},err:n.message}}}function Ke(t,n){return(t[n]??[]).reduce((s,o)=>{var r;return s+(((r=o.hooks)==null?void 0:r.length)??0)},0)}function Be({scope:t="user"}={}){const n=U(),s=ee(),o=(s==null?void 0:s.cwd)??null,r=te(x=>x.navFace),[a,i]=b.useState("events");b.useEffect(()=>{r==="project"&&a==="library"&&i("events")},[r,a]);const d=G(se,n,o)[t]??null,c=e.jsx(K,{options:[{key:"events",label:"Events"},...r==="home"?[{key:"library",label:"Library"}]:[]],active:a,onChange:i});return n?a==="library"?e.jsx(R,{toolbar:c,children:e.jsx(Ce,{})}):t!=="user"&&!o?e.jsx(R,{toolbar:e.jsx(e.Fragment,{children:c}),children:e.jsx(P,{title:"no active project"})}):d?e.jsx(R,{toolbar:e.jsxs(e.Fragment,{children:[c,e.jsx("span",{className:"ml-3 text-fg-faint truncate",children:d}),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(ie,{scope:t,cwd:o,path:d})}):e.jsx(P,{title:"loading…"}):e.jsx(P,{title:"loading…"})}function ie({scope:t,cwd:n,path:s,renderLayout:o}){const[r,a]=b.useState("PreToolUse"),[i,u]=b.useState(null),d=(v,j)=>{window.api.claudeConfig.patch({fileId:"settings",scope:t,cwd:n,keyPath:v,value:j}).catch(p=>D.error(p instanceof Error?p.message:String(p)))},c=A(v=>v.files[s]),{hooks:x,err:y}=c?Ge(c.draftRaw):{hooks:{},err:null},g=Object.keys(x).filter(v=>!Le.has(v)),l=g.reduce((v,j)=>v+(x[j]??[]).reduce((p,T)=>{var M;return p+(((M=T.hooks)==null?void 0:M.length)??0)},0),0),m=(v,j)=>{if(y){D.error(Y);return}d(["hooks",v],j)},h=x[r]??[],f=()=>{m(r,[...h,{matcher:"",hooks:[{type:"command",command:""}]}])},w=(v,j)=>{const p=h.slice();p[v]=j,m(r,p)},k=v=>{m(r,h.filter((j,p)=>p!==v))},E=e.jsxs(e.Fragment,{children:[y?e.jsxs("div",{role:"alert",className:"px-3 py-2 border-b border-line text-xs text-red-400",children:[Y," (",y,")"]}):null,l>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:"⚠"})," ",l," hook(s) configured under unknown event names: ",e.jsx("span",{className:"font-mono text-fg",children:g.join(", ")}),e.jsx("span",{className:"text-fg-faint",children:" · these are ignored by Claude Code 2026; edit settings.json directly to remove."})]}):null]}),N=y||l>0?E:null,S=e.jsx("div",{className:"py-1",children:oe.map(v=>{const j=Ke(x,v),p=De[v],T=p?e.jsxs("span",{className:"block space-y-1",children:[e.jsx("span",{className:"block text-fg",children:p.when}),e.jsxs("span",{className:"block text-fg-faint font-mono",children:["payload: ",p.payload]}),p.example?e.jsxs("span",{className:"block text-fg-faint italic",children:["e.g. ",p.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(fe,{content:T,align:"bottom-center",children:e.jsxs("button",{onClick:()=>a(v),title:p==null?void 0:p.when,className:`w-full text-left px-3 py-1 text-xs ${r===v?"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:v}),j>0&&e.jsx("span",{className:"text-accent shrink-0 ml-2",children:j})]}),p?e.jsx("span",{className:"block text-[11px] leading-[1.3] text-fg-faint/80 font-normal truncate",children:p.when}):e.jsx("span",{className:"block text-[11px] leading-[1.3] text-fg-faint/80 italic font-normal truncate",children:"no documentation yet"})]})})},v)})}),C=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:r}),e.jsx("button",{onClick:f,disabled:!!y,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"})]}),h.length===0?e.jsx("div",{className:"text-fg-faint text-xs",children:"no hooks for this event"}):h.map((v,j)=>e.jsx(Je,{group:v,jsonInvalid:!!y,onChange:p=>w(j,p),onRemove:()=>k(j),onTestFire:p=>u({event:r,matcher:v.matcher??"",command:p.command??""})},j))]});return e.jsxs(e.Fragment,{children:[o?o({banners:N,list:S,detail:C}):e.jsxs("div",{className:"flex flex-col h-full",children:[N,e.jsx(Ee,{sidebarWidth:"14rem",sidebar:S,detail:C})]}),i?e.jsx(Ye,{event:i.event,matcher:i.matcher,command:i.command,onClose:()=>u(null)}):null]})}b.memo(Be);function I({value:t,onCommit:n,onDraft:s,...o}){const[r,a]=b.useState(t);b.useEffect(()=>a(t),[t]);const i=()=>{r!==t&&n(r)};return e.jsx("input",{...o,value:r,onChange:u=>{a(u.target.value),s==null||s(u.target.value)},onBlur:i,onKeyDown:u=>{u.key==="Enter"&&i()}})}function Je({group:t,jsonInvalid:n,onChange:s,onRemove:o,onTestFire:r}){const a=()=>s({...t,hooks:[...t.hooks??[],{type:"command",command:""}]}),i=(d,c)=>{const x=t.hooks.slice();x[d]=c,s({...t,hooks:x})},u=d=>s({...t,hooks:t.hooks.filter((c,x)=>x!==d)});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(I,{value:t.matcher??"",disabled:n,onCommit:d=>s({...t,matcher:d}),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:o,disabled:n,className:"text-fg-faint hover:text-red-400 text-xs disabled:opacity-40",title:"remove group",children:"× group"})]}),(t.hooks??[]).map((d,c)=>e.jsx(qe,{rule:d,jsonInvalid:n,onChange:x=>i(c,x),onRemove:()=>u(c),onTestFire:()=>r(d)},c)),e.jsx("button",{onClick:a,disabled:n,className:"text-xs text-fg-faint hover:text-fg disabled:opacity-40",children:"+ add hook"})]})}function We(t){var s,o,r;const n=((o=(s=ne.$defs)==null?void 0:s.hookCommand)==null?void 0:o.anyOf)??[];for(const a of n){const i=a.properties;if(((r=i==null?void 0:i.type)==null?void 0:r.const)!==t)continue;const u=i.timeout;if(typeof(u==null?void 0:u.default)=="number")return u.default;const d=/default:\s*(\d+)/.exec((u==null?void 0:u.description)??"");return d?Number(d[1]):null}return null}function Z(t){return/^\d+$/.test(t.trim())&&Number(t)>0?Number(t):null}function qe({rule:t,jsonInvalid:n,onChange:s,onRemove:o,onTestFire:r}){const a=l=>({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"})[l],i=t.type==="command"?"command":t.type==="http"?"url":t.type==="prompt"?"prompt":t.type==="mcp_tool"?"mcpTool":"agent",u=t[i]??"",d=(t.args??[]).join(" "),[c,x]=b.useState(null),y=We(t.type),g={type:"hook",name:u||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:n,onChange:l=>s({type:l.target.value}),className:"bg-bg border border-line rounded px-1 py-0.5 text-xs text-fg",children:He.map(l=>e.jsx("option",{value:l,children:l},l))}),e.jsx(Pe,{interactive:!1,input:g}),e.jsx(I,{value:u,disabled:n,onCommit:l=>s({...t,[i]:l}),placeholder:a(t.type),className:`flex-1 bg-bg border rounded px-2 py-0.5 text-xs text-fg font-mono ${n?"border-red-500/70":u.trim()?"border-line":"border-yellow-600/50"}`}),n?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(I,{value:t.timeout!=null?String(t.timeout):"",disabled:n,"aria-label":"timeout (seconds)","aria-invalid":c?!0:void 0,title:c??"Timeout in seconds",onDraft:l=>{x(!l.trim()||Z(l)!=null?null:"Timeout must be a positive whole number of seconds")},onCommit:l=>{if(!l.trim()){s({...t,timeout:void 0});return}const m=Z(l);m!=null&&s({...t,timeout:m})},placeholder:y!=null?`${y} (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:r,disabled:n||!u.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:o,disabled:n,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(I,{value:d,disabled:n,onCommit:l=>s({...t,args:l.trim()?l.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(I,{value:t.terminalSequence??"",disabled:n,onCommit:l=>s({...t,terminalSequence:l||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 Ve(t){return JSON.stringify(Ue[t]??{},null,2)}function ze(t,n){if(!t.trim())return{matched:!0,target:null,note:"empty matcher → matches all"};const s=n&&typeof n=="object"&&"tool_name"in n?String(n.tool_name??""):null;if(s==null)return{matched:!1,target:null,note:"payload has no tool_name to match against"};try{return{matched:new RegExp(`^(?:${t})$`).test(s),target:s}}catch{return{matched:t===s,target:s,note:"matcher not valid regex; fell back to exact match"}}}function Ye({event:t,matcher:n,command:s,onClose:o}){const[r,a]=b.useState(()=>Ve(t)),[i,u]=b.useState(!1),[d,c]=b.useState(null),[x,y]=b.useState(null);let g=null;try{JSON.parse(r)}catch(m){g=m.message}const l=async()=>{u(!0),c(null);let m=null;try{m=JSON.parse(r)}catch{}y(ze(n,m));try{const h=await window.api.app.testFireHook({command:s,payload:r,timeoutMs:5e3});c(h)}finally{u(!1)}};return e.jsx(ge,{open:!0,onClose:o,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:s})]}),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:n||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)"}),g?e.jsxs("span",{className:"text-red-400",children:["× ",g]}):null]}),e.jsx("textarea",{value:r,onChange:m=>a(m.target.value),rows:8,className:`w-full bg-bg border rounded px-2 py-1 font-mono text-fg ${g?"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,d?e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"text-fg-faint",children:["exit ",d.exitCode," · ",d.durationMs,"ms"]}),d.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:d.stdout})]}):null,d.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:d.stderr})]}):null]}):null,e.jsxs("div",{className:"flex items-center justify-end gap-2 pt-1",children:[e.jsx("button",{onClick:o,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:l,disabled:i||!!g||!s.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:i?"running…":"run"})]})]})})}const le=[{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"]}],Q=new Set(le.flatMap(t=>t.keys)),Ze=[{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"]}],Qe={mcp:"MCP",url:"URL",urls:"URLs",http:"HTTP",ui:"UI",id:"ID",uuid:"UUID",api:"API",aws:"AWS",otel:"OTel",json:"JSON"};function ce(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((o,r)=>{const a=Qe[o];return a||(r===0?o.charAt(0).toUpperCase()+o.slice(1):o)}).join(" ")}function de(t){const n=new Set,s=[];for(const r of Ze){const a=r.keys.filter(i=>t.has(i)&&!Q.has(i));a.forEach(i=>n.add(i)),a.length!==0&&s.push({id:r.id,title:r.title,summary:r.summary,advanced:!!r.advanced,keys:a})}const o=Array.from(t).filter(r=>!n.has(r)&&r!=="$schema"&&!Q.has(r)).sort();return o.length>0&&s.push({id:"other",title:"Other",summary:"Keys not yet grouped.",advanced:!1,keys:o}),s}function Xe(t,n){return de(t).map(s=>({id:s.id,title:s.title,advanced:s.advanced,total:s.keys.length,setCount:s.keys.filter(o=>n.has(o)).length}))}const et={};function ue(t,n){if(n)return{text:n,authored:!1};const s=et[t];return s?{text:s,authored:!0}:null}const me=b.createContext(null);function tt(){const t=b.useContext(me);if(!t)throw new Error("usePageShell() must be used inside a <PageShell>.");return t}function O({header:t,subnav:n,footer:s,children:o,subnavWidth:r=220}){const a=b.useRef(null),i=b.useCallback((d,c)=>{const x=a.current;if(!x)return;let y=null;for(const g of Array.from(x.querySelectorAll("[id]")))if(g.id===d){y=g;break}y&&be(x,y,{block:"start",behavior:c==null?void 0:c.behavior})},[]),u=b.useMemo(()=>({scrollToAnchor:i,contentRef:a}),[i]);return e.jsx(me.Provider,{value:u,children:e.jsxs("div",{"data-testid":"page-shell",className:"h-full w-full min-h-0 min-w-0 flex flex-col overflow-clip",children:[t!=null&&e.jsx("div",{"data-testid":"page-shell-header",className:"shrink-0 min-w-0 overflow-clip",children:t}),e.jsxs("div",{"data-testid":"page-shell-body",className:"flex-1 min-h-0 min-w-0 flex flex-row overflow-clip",children:[n!=null&&e.jsx("nav",{"data-testid":"page-shell-subnav",className:"shrink-0 min-h-0 overflow-y-auto overscroll-contain",style:{width:r},children:n}),e.jsx("div",{ref:a,"data-testid":"page-shell-content",className:"flex-1 min-w-0 min-h-0 overflow-y-auto overscroll-contain",children:o})]}),s!=null&&e.jsx("div",{"data-testid":"page-shell-footer",className:"shrink-0 min-w-0 overflow-clip",children:s})]})})}const st={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"},nt=["user","project","local","default"],rt={user:"user",project:"project",local:"local",default:"default"};function at({node:t,schema:n}){const[s,o]=b.useState(""),[r,a]=b.useState(!1),[i,u]=b.useState(!0),d=t.kind==="object"?t:null,c=d?Object.keys(d.children):[],x=n.rootKeys(),y=new Set([...c,...x]),g=Array.from(y).sort().join(","),l=c.join(","),m=b.useMemo(()=>de(y),[g]),h=b.useMemo(()=>Xe(y,new Set(c)),[g,l]),f=b.useMemo(()=>m.filter(w=>r||!w.advanced).map(w=>({...w,keys:w.keys.filter(k=>{const E=(d==null?void 0:d.children[k])!==void 0;if(!i&&!E)return!1;if(!s.trim())return!0;const N=n.at([k]);return[k,ce(k),(N==null?void 0:N.description)??""].join(" ").toLowerCase().includes(s.toLowerCase())})})).filter(w=>w.keys.length>0),[m,s,r,i,d,n]);return{filter:s,setFilter:o,showAdvanced:r,setShowAdvanced:a,showUnset:i,setShowUnset:u,rootNode:d,schema:n,groups:m,railGroups:h,visibleGroups:f}}function ot({cards:t,targetScope:n}){return e.jsxs("div",{className:"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:_[n].label})]}),e.jsxs("label",{className:"flex items-center gap-1 text-fg-faint cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:t.showUnset,onChange:s=>t.setShowUnset(s.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:t.showAdvanced,onChange:s=>t.setShowAdvanced(s.target.checked),className:"accent-accent"}),"show advanced"]}),e.jsx("div",{className:"flex-1"}),e.jsx("input",{value:t.filter,onChange:s=>t.setFilter(s.target.value),placeholder:"search settings…",className:"bg-bg border border-line rounded px-2 py-1 text-xs text-fg w-64"})]})}function it({cards:t,targetScope:n,onOverride:s}){const{visibleGroups:o,rootNode:r,schema:a,filter:i}=t;return e.jsxs("div",{className:"py-3",children:[o.map(u=>e.jsx(dt,{id:u.id,title:u.title,summary:u.summary,advanced:u.advanced,children:u.keys.map(d=>{const c=r==null?void 0:r.children[d],x=a.at([d]);return e.jsx(ut,{keyName:d,node:c,info:x,targetScope:n,onOverride:(y,g)=>s([d],y,g)},d)})},u.id)),o.length===0&&e.jsxs("div",{className:"px-6 py-12 text-center text-fg-faint text-sm",children:['no settings match "',i,'"']})]})}function lt({cards:t}){const n=tt(),[s,o]=b.useState(null),{groups:r,showAdvanced:a,setShowAdvanced:i}=t,u=d=>{const c=r.find(x=>x.id===d);c!=null&&c.advanced&&!a&&i(!0),o(d)};return b.useEffect(()=>{s&&(o(null),n.scrollToAnchor(`settings-group-${s}`,{behavior:"smooth"}))},[s,n]),e.jsx(ct,{groups:t.railGroups,onJump:u})}function ct({groups:t,onJump:n}){return e.jsx("div",{className:"min-h-full border-r border-line bg-bg-elev/30 py-3",children:t.map(s=>e.jsxs("button",{type:"button","data-group-id":s.id,onClick:()=>n(s.id),className:"w-full flex items-center gap-2 px-3 py-2 text-left hover:bg-bg-hi transition-colors",title:`jump to ${s.title}`,children:[e.jsx(ye,{name:st[s.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:s.title}),e.jsxs("span",{className:"text-[10px] text-fg-faint font-mono shrink-0",children:[s.setCount,"/",s.total]})]},s.id))})}function dt({id:t,title:n,summary:s,advanced:o,children:r}){const[a,i]=b.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:()=>i(!a),children:[e.jsx("span",{className:"text-fg-faint w-3",children:a?"▾":"▸"}),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:n}),o&&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:s})]})]}),a&&e.jsx("div",{className:"divide-y divide-line/60",children:r})]})}function ut({keyName:t,node:n,info:s,targetScope:o,onOverride:r}){const[a,i]=b.useState(!1),[u,d]=b.useState(!1),c=ce(t),x=n!==void 0,g=(n==null?void 0:n.kind)==="leaf"?n:null,l=(n==null?void 0:n.kind)==="object"||(n==null?void 0:n.kind)==="array",m=s==null?void 0:s.default,h=g&&m!==void 0&&xe(g.value,m),f=yt({isSet:x,leafNode:g,defaultVal:m,isDefault:!!h,node:n}),w=mt(g,m),k=w.length>=2,E=!!g&&!h,N=ue(t,s==null?void 0:s.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:()=>i(!a),className:"text-fg-faint hover:text-fg w-3 mt-0.5",title:a?"collapse":"expand",children:a?"▾":"▸"}),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(vt,{kind:f.kind,label:f.label}),k&&e.jsxs("button",{onClick:S=>{S.stopPropagation(),a||i(!0),d(C=>!C)},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 · ",w.map(S=>rt[S]).join(" · ")]}),E&&g&&e.jsx("button",{onClick:S=>{S.stopPropagation(),r(void 0,g.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 ${_[g.winner].label}`,children:"↺ reset"}),(s==null?void 0:s.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"}),(s==null?void 0:s.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"})]}),N&&e.jsx("p",{className:`text-fg-dim text-xs mt-0.5 leading-relaxed ${N.authored?"inline-block border-b border-dotted border-fg-faint/70 cursor-help":""}`,title:N.authored?"In-app-authored description — not from the official Claude Code schema":void 0,children:jt(N.text)}),a&&u&&g&&e.jsx(pt,{leaf:g,defaultVal:m,onReset:S=>r(void 0,S)}),a&&e.jsx(xt,{keyName:t,node:n,info:s,targetScope:o,onOverride:S=>r(S)})]}),e.jsx("div",{className:"shrink-0",children:!a&&e.jsx(bt,{node:n,info:s,onSet:S=>{r(S)},disabled:l&&x})})]})})}function mt(t,n){if(!t)return[];const s=new Set;s.add(t.winner);for(const o of t.shadowed)s.add(o.scope);return n!==void 0&&s.add("default"),nt.filter(o=>s.has(o))}function pt({leaf:t,defaultVal:n,onReset:s}){const o={};o[t.winner]={value:t.value,winner:!0};for(const r of t.shadowed)o[r.scope]={value:r.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(r=>{const a=o[r],i=a!==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:_[r].label}),e.jsx("span",{className:`font-mono truncate ${a!=null&&a.winner?"text-accent":"text-fg-dim"}`,children:i?$(a.value):e.jsx("span",{className:"text-fg-faint",children:"—"})}),i?e.jsx("button",{onClick:()=>s(r),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 ${_[r].label}`,children:"↺"}):e.jsx("span",{})]},r)}),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:n!==void 0?$(n):e.jsx("span",{className:"text-fg-faint",children:"—"})}),e.jsx("span",{})]})]})]})}function xt({keyName:t,node:n,info:s,targetScope:o,onOverride:r}){const i=(n==null?void 0:n.kind)==="leaf"?n:null,u=ue(t,s==null?void 0:s.description);return e.jsxs("div",{className:"mt-3 space-y-2 text-xs",children:[u&&e.jsx("p",{className:`text-fg-dim leading-relaxed whitespace-pre-wrap ${u.authored?"inline-block border-b border-dotted border-fg-faint/70 cursor-help":""}`,title:u.authored?"In-app-authored description — not from the official Claude Code schema":void 0,children:u.text}),e.jsxs("dl",{className:"grid grid-cols-[auto_1fr] gap-x-3 gap-y-1 text-fg-faint",children:[(s==null?void 0:s.type)&&e.jsxs(e.Fragment,{children:[e.jsx("dt",{children:"Type"}),e.jsx("dd",{className:"text-fg-dim font-mono",children:Array.isArray(s.type)?s.type.join(" | "):s.type})]}),(s==null?void 0:s.default)!==void 0&&e.jsxs(e.Fragment,{children:[e.jsx("dt",{children:"Default"}),e.jsx("dd",{className:"text-fg-dim font-mono",children:$(s.default)})]}),(s==null?void 0:s.enum)&&e.jsxs(e.Fragment,{children:[e.jsx("dt",{children:"Options"}),e.jsx("dd",{className:"text-fg-dim font-mono",children:s.enum.map(d=>String(d)).join(" | ")})]}),i&&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:$(i.value)}),e.jsxs("span",{className:"ml-2 text-fg-faint",children:["from ",_[i.winner].label]})]})]}),i&&i.shadowed.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("dt",{children:"Shadowed"}),e.jsx("dd",{className:"space-y-0.5",children:i.shadowed.map((d,c)=>e.jsxs("div",{className:"font-mono text-fg-faint line-through",children:[$(d.value)," —"," ",e.jsx("span",{className:"no-underline",children:_[d.scope].label})]},c))})]}),(n==null?void 0:n.kind)==="array"&&e.jsxs(e.Fragment,{children:[e.jsx("dt",{children:"Accumulated"}),e.jsxs("dd",{className:"text-fg-dim",children:[n.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(ht,{keyName:t,node:n,info:s,onChange:r,targetScope:o})})]})}function ht({node:t,info:n,onChange:s,targetScope:o}){const a=(t==null?void 0:t.kind)==="leaf"?t.value:n==null?void 0:n.default,i=pe(n==null?void 0:n.type);if(i==="boolean"){const u=a===!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:d,label:c})=>e.jsx("button",{onClick:()=>s(d),className:`px-3 py-0.5 text-xs transition-colors ${u===d?"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:["→ ",_[o].label]})]})}return n!=null&&n.enum?e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"text-fg-faint",children:"Choose:"}),n.enum.map(u=>{const d=xe(a,u);return e.jsx("button",{onClick:()=>s(u),className:`px-2 py-0.5 text-xs rounded border ${d?"bg-accent text-bg border-accent":"bg-bg-elev text-fg-dim border-line hover:text-fg hover:bg-bg-hi"}`,children:String(u)},String(u))}),e.jsxs("span",{className:"text-fg-faint",children:["→ ",_[o].label]})]}):i==="integer"||i==="number"?e.jsx(ft,{value:typeof a=="number"?a:void 0,integer:i==="integer",onCommit:s,target:_[o].label}):i==="string"?e.jsx(gt,{value:typeof a=="string"?a:"",onCommit:s,target:_[o].label}):e.jsxs("div",{className:"text-fg-faint",children:["Complex value (",i??"object/array",") — use the"," ",e.jsx("span",{className:"text-fg-dim",children:"Raw"})," tab to edit."]})}function ft({value:t,integer:n,onCommit:s,target:o}){const[r,a]=b.useState(t!==void 0?String(t):""),i=()=>{const u=n?parseInt(r,10):parseFloat(r);Number.isNaN(u)||s(u)};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:r,onChange:u=>a(u.target.value),onBlur:i,onKeyDown:u=>{u.key==="Enter"&&u.target.blur()},className:"w-24 bg-bg border border-line rounded px-2 py-0.5 text-xs text-fg"}),e.jsxs("button",{onClick:i,className:"px-2 py-0.5 text-xs border border-accent/50 rounded text-accent hover:bg-accent hover:text-bg",children:["save → ",o]})]})}function gt({value:t,onCommit:n,target:s}){const[o,r]=b.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:o,onChange:a=>r(a.target.value),onKeyDown:a=>{a.key==="Enter"&&n(o)},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:()=>n(o),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 → ",s]})]})}function bt({node:t,info:n,onSet:s,disabled:o}){const r=(t==null?void 0:t.kind)==="leaf",a=pe(n==null?void 0:n.type);if(o)return null;if(a==="boolean"){const i=r&&t.value===!0;return e.jsx("button",{onClick:()=>s(!i),className:`px-2.5 py-0.5 text-xs rounded border transition-colors ${i?"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:i?"on":"off"})}return null}function yt({isSet:t,leafNode:n,defaultVal:s,isDefault:o,node:r}){return t?(r==null?void 0:r.kind)==="array"?{kind:"accumulated",label:`${r.items.length} items`}:(r==null?void 0:r.kind)==="object"?{kind:"set",label:"configured"}:n?o?{kind:"default",label:`= default · ${_[n.winner].label}`}:n.shadowed.length>0?{kind:"override",label:`overriding ${n.shadowed.length} scope(s)`}:{kind:"set",label:`set in ${_[n.winner].label}`}:{kind:"set",label:"configured"}:s!==void 0?{kind:"default",label:`using default: ${$(s)}`}:{kind:"unset",label:"not configured"}}function vt({kind:t,label:n}){const s={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 ${s}`,children:n})}function pe(t){if(t)return Array.isArray(t)?t.find(s=>s!=="null")??t[0]:t}function xe(t,n){return t===n?!0:typeof t!=typeof n?!1:t&&n&&typeof t=="object"?JSON.stringify(t)===JSON.stringify(n):!1}function jt(t){const n=t.trim().split(`
1
+ import{bb as A,ay as e,b7 as D,aO as b,bh as U,b8 as ee,bj as te,bq as G,x as he,m as P,a5 as fe,w as ge,U as se,aZ as be,T as _,b as ye,bs as q,bm as ve,aC as je,aG as we,J as ke,at as Ne}from"./index-rt7pTODX.js";import{P as R}from"./Panel-O8XPrpJu.js";import{P as Se,H as Ce,S as _e}from"./Library-1RpLT-aH.js";import{S as V}from"./SourceChip-D-Imzszd.js";import{V as K}from"./ViewTabs-BCMYQwo_.js";import{r as ne}from"./claude-settings-schema-COigsajx.js";import{L as Ee}from"./ListDetail-xr0oxNkv.js";import{a as Pe}from"./ProvenanceBadge-DSaizfZL.js";import"./monaco-editor-BsIlgG7c.js";import"./Button-DtBUGvGI.js";function Te(t){const n=t??{},s={...n.$defs??{},...n.definitions??{}},o=l=>{if(!l)return{};if(!l.$ref)return i(l);const m=/^#\/(\$defs|definitions)\/(.+)$/.exec(l.$ref);if(!m)return i(l);const h=s[m[2]];return h?o({...h,...u(l)}):i(l)},r=new Set(["__proto__","constructor","prototype"]),a=l=>{if(!l)return{};const m={};for(const[h,f]of Object.entries(l))r.has(h)||(m[h]=f);return m},i=l=>{if(!l.allOf||l.allOf.length===0)return l;const m={...l};delete m.allOf;for(const h of l.allOf){const f=o(h);Object.assign(m,{properties:{...a(m.properties),...a(f.properties)},required:Fe([...m.required??[],...f.required??[]])}),!m.description&&f.description&&(m.description=f.description),m.default===void 0&&f.default!==void 0&&(m.default=f.default),!m.type&&f.type&&(m.type=f.type)}return m},u=l=>{const{$ref:m,...h}=l;return h},d=(l,m)=>{let h=o(l);for(const f of m){if(!h)return null;if(/^\d+$/.test(f)){const E=Array.isArray(h.items)?h.items[Number(f)]:h.items;h=E?o(E):null;continue}const w=h.properties;if(w&&!r.has(f)&&f in w){h=o(w[f]);continue}const k=h.additionalProperties;if(k&&typeof k=="object"){h=o(k);continue}return null}return h},c=(l,m,h)=>{if(!l)return null;const f={};if(l.description&&(f.description=l.description),l.type&&(f.type=l.type),l.default!==void 0&&(f.default=l.default),l.enum&&(f.enum=l.enum),l.const!==void 0&&(f.const=l.const),l.deprecated&&(f.deprecated=!0),l.examples&&(f.examples=l.examples),l.properties&&(f.knownChildren=Object.keys(l.properties)),h&&(m!=null&&m.includes(h))&&(f.required=!0),l.items&&!Array.isArray(l.items)){const w=o(l.items),k=c(w,void 0,null);k&&(f.itemsInfo=k)}return(l.additionalProperties===!0||typeof l.additionalProperties=="object")&&(f.open=!0),f},x=l=>m=>{if(m.length===0)return c(o(l),void 0,null);const h=d(l,m.slice(0,-1));if(!h)return null;const f=m[m.length-1],w=d(h,[f]);return c(w,h.required,f)},y=l=>{const m=o(l);return Object.keys(m.properties??{})},g=l=>({at:x(l),rootKeys:()=>y(l),rootedAt:m=>{const h=d(l,m);return g(h??{})}});return g(n)}function Fe(t){return Array.from(new Set(t))}let H=null;function re(){return H||(H=Te(ne)),H}const Oe=["allow","deny","ask"],z="This settings file has invalid JSON. Fix it in the Settings raw editor first; Permissions will not overwrite it.";function Ae(t){if(t.trim()==="")return{perms:{},full:{},err:null};try{const n=JSON.parse(t);if(n===null||typeof n!="object"||Array.isArray(n))return{perms:{},full:{},err:"settings file is not a JSON object"};const s=n;return{perms:s.permissions??{},full:s,err:null}}catch(n){return{perms:{},full:{},err:n.message}}}function Me({scope:t="user"}={}){const n=U(),s=ee(),o=(s==null?void 0:s.cwd)??null,r=te(l=>l.navFace),[a,i]=b.useState("rules");b.useEffect(()=>{r==="project"&&a==="presets"&&i("rules")},[r,a]);const d=G(he,n,o)[t]??null,c=A(l=>l.files),x=e.jsx(K,{options:[{key:"rules",label:"Rules"},...r==="home"?[{key:"presets",label:"Presets"}]:[]],active:a,onChange:i});if(!n)return e.jsx(P,{title:"loading…"});if(a==="presets")return e.jsx(R,{toolbar:x,children:e.jsx(Se,{})});const y=l=>l!=="user"&&!o,g=d?c[d]:null;return e.jsx(R,{toolbar:e.jsxs(e.Fragment,{children:[x,e.jsx("span",{className:"ml-3 text-fg-faint truncate",children:d??"—"}),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:y(t)?e.jsx(P,{title:"no active project",hint:"open a tab in a project directory to edit project or local permissions"}):d&&g?e.jsx(ae,{scope:t,cwd:o,activePath:d}):e.jsx(P,{title:"resolving…"})})}b.memo(Me);function ae({scope:t,cwd:n,activePath:s}){const o=A(c=>c.files[s]),{perms:r,err:a}=o?Ae(o.draftRaw):{perms:{},err:null},i=(c,x)=>{if(a){D.error(z);return}window.api.claudeConfig.patch({fileId:"settings",scope:t,cwd:n,keyPath:["permissions",c],value:x}).catch(y=>D.error(y instanceof Error?y.message:String(y)))},u=(c,x)=>{const y=x.trim();if(!y)return;const g=r[c]??[];g.includes(y)||i(c,[...g,y])},d=(c,x)=>{const y=r[c]??[];i(c,y.filter((g,l)=>l!==x))};return e.jsxs("div",{className:"p-4 space-y-5 max-w-3xl",children:[a&&e.jsxs("div",{role:"alert",className:"text-xs text-red-400 border border-red-400/40 rounded px-3 py-2",children:[z," (",a,")"]}),e.jsx(Re,{value:r.defaultMode??"default",onChange:c=>i("defaultMode",c)}),Oe.map(c=>e.jsx($e,{list:c,rules:r[c]??[],disabled:!!a,onAdd:x=>u(c,x),onRemove:x=>d(c,x)},c)),e.jsx(Ie,{dirs:r.additionalDirectories??[],disabled:!!a,onChange:c=>i("additionalDirectories",c)})]})}function Re({value:t,onChange:n}){var a;const o=(((a=re().at(["permissions","defaultMode"]))==null?void 0:a.enum)??[]).filter(i=>typeof i=="string"),r=t&&!o.includes(t)?[...o,t]:o;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:r.map(i=>e.jsx("button",{onClick:()=>n(i),className:`px-2.5 py-1 text-xs transition-colors ${t===i?"bg-bg-hi text-fg":"bg-bg-elev text-fg-dim hover:text-fg hover:bg-bg-hi"}`,children:i},i))})]})}function $e({list:t,rules:n,onAdd:s,onRemove:o,disabled:r}){const[a,i]=b.useState(""),u=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 ${u}`,children:t}),e.jsxs("div",{className:"flex gap-2 mb-2",children:[e.jsx("input",{value:a,disabled:r,onChange:d=>i(d.target.value),onKeyDown:d=>{d.key==="Enter"&&(s(a),i(""))},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:()=>{s(a),i("")},disabled:r||!a.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"})]}),n.length===0?e.jsx("div",{className:"text-fg-faint text-xs",children:"no rules"}):e.jsx("ul",{className:"space-y-0.5",children:n.map((d,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:d}),e.jsx("button",{onClick:()=>o(c),className:"text-fg-faint hover:text-red-400",title:"remove",children:"×"})]},`${c}-${d}`))})]})}function Ie({dirs:t,onChange:n,disabled:s}){const[o,r]=b.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:o,disabled:s,onChange:a=>r(a.target.value),onKeyDown:a=>{a.key==="Enter"&&o.trim()&&(n([...t,o.trim()]),r(""))},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((a,i)=>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:a}),e.jsx("button",{onClick:()=>n(t.filter((u,d)=>d!==i)),className:"text-fg-faint hover:text-red-400",children:"×"})]},`${i}-${a}`))})]})}const De={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 }"}},oe=["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"],Le=new Set(oe),He=["command","http","prompt","agent","mcp_tool"],Ue={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:{}},Y="This settings file has invalid JSON. Fix it in the Settings raw editor first; Hooks will not overwrite it.";function Ge(t){if(t.trim()==="")return{full:{},hooks:{},err:null};try{const n=JSON.parse(t);if(n===null||typeof n!="object"||Array.isArray(n))return{full:{},hooks:{},err:"settings file is not a JSON object"};const s=n;return{full:s,hooks:s.hooks??{},err:null}}catch(n){return{full:{},hooks:{},err:n.message}}}function Ke(t,n){return(t[n]??[]).reduce((s,o)=>{var r;return s+(((r=o.hooks)==null?void 0:r.length)??0)},0)}function Be({scope:t="user"}={}){const n=U(),s=ee(),o=(s==null?void 0:s.cwd)??null,r=te(x=>x.navFace),[a,i]=b.useState("events");b.useEffect(()=>{r==="project"&&a==="library"&&i("events")},[r,a]);const d=G(se,n,o)[t]??null,c=e.jsx(K,{options:[{key:"events",label:"Events"},...r==="home"?[{key:"library",label:"Library"}]:[]],active:a,onChange:i});return n?a==="library"?e.jsx(R,{toolbar:c,children:e.jsx(Ce,{})}):t!=="user"&&!o?e.jsx(R,{toolbar:e.jsx(e.Fragment,{children:c}),children:e.jsx(P,{title:"no active project"})}):d?e.jsx(R,{toolbar:e.jsxs(e.Fragment,{children:[c,e.jsx("span",{className:"ml-3 text-fg-faint truncate",children:d}),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(ie,{scope:t,cwd:o,path:d})}):e.jsx(P,{title:"loading…"}):e.jsx(P,{title:"loading…"})}function ie({scope:t,cwd:n,path:s,renderLayout:o}){const[r,a]=b.useState("PreToolUse"),[i,u]=b.useState(null),d=(v,j)=>{window.api.claudeConfig.patch({fileId:"settings",scope:t,cwd:n,keyPath:v,value:j}).catch(p=>D.error(p instanceof Error?p.message:String(p)))},c=A(v=>v.files[s]),{hooks:x,err:y}=c?Ge(c.draftRaw):{hooks:{},err:null},g=Object.keys(x).filter(v=>!Le.has(v)),l=g.reduce((v,j)=>v+(x[j]??[]).reduce((p,T)=>{var M;return p+(((M=T.hooks)==null?void 0:M.length)??0)},0),0),m=(v,j)=>{if(y){D.error(Y);return}d(["hooks",v],j)},h=x[r]??[],f=()=>{m(r,[...h,{matcher:"",hooks:[{type:"command",command:""}]}])},w=(v,j)=>{const p=h.slice();p[v]=j,m(r,p)},k=v=>{m(r,h.filter((j,p)=>p!==v))},E=e.jsxs(e.Fragment,{children:[y?e.jsxs("div",{role:"alert",className:"px-3 py-2 border-b border-line text-xs text-red-400",children:[Y," (",y,")"]}):null,l>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:"⚠"})," ",l," hook(s) configured under unknown event names: ",e.jsx("span",{className:"font-mono text-fg",children:g.join(", ")}),e.jsx("span",{className:"text-fg-faint",children:" · these are ignored by Claude Code 2026; edit settings.json directly to remove."})]}):null]}),N=y||l>0?E:null,S=e.jsx("div",{className:"py-1",children:oe.map(v=>{const j=Ke(x,v),p=De[v],T=p?e.jsxs("span",{className:"block space-y-1",children:[e.jsx("span",{className:"block text-fg",children:p.when}),e.jsxs("span",{className:"block text-fg-faint font-mono",children:["payload: ",p.payload]}),p.example?e.jsxs("span",{className:"block text-fg-faint italic",children:["e.g. ",p.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(fe,{content:T,align:"bottom-center",children:e.jsxs("button",{onClick:()=>a(v),title:p==null?void 0:p.when,className:`w-full text-left px-3 py-1 text-xs ${r===v?"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:v}),j>0&&e.jsx("span",{className:"text-accent shrink-0 ml-2",children:j})]}),p?e.jsx("span",{className:"block text-[11px] leading-[1.3] text-fg-faint/80 font-normal truncate",children:p.when}):e.jsx("span",{className:"block text-[11px] leading-[1.3] text-fg-faint/80 italic font-normal truncate",children:"no documentation yet"})]})})},v)})}),C=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:r}),e.jsx("button",{onClick:f,disabled:!!y,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"})]}),h.length===0?e.jsx("div",{className:"text-fg-faint text-xs",children:"no hooks for this event"}):h.map((v,j)=>e.jsx(Je,{group:v,jsonInvalid:!!y,onChange:p=>w(j,p),onRemove:()=>k(j),onTestFire:p=>u({event:r,matcher:v.matcher??"",command:p.command??""})},j))]});return e.jsxs(e.Fragment,{children:[o?o({banners:N,list:S,detail:C}):e.jsxs("div",{className:"flex flex-col h-full",children:[N,e.jsx(Ee,{sidebarWidth:"14rem",sidebar:S,detail:C})]}),i?e.jsx(Ye,{event:i.event,matcher:i.matcher,command:i.command,onClose:()=>u(null)}):null]})}b.memo(Be);function I({value:t,onCommit:n,onDraft:s,...o}){const[r,a]=b.useState(t);b.useEffect(()=>a(t),[t]);const i=()=>{r!==t&&n(r)};return e.jsx("input",{...o,value:r,onChange:u=>{a(u.target.value),s==null||s(u.target.value)},onBlur:i,onKeyDown:u=>{u.key==="Enter"&&i()}})}function Je({group:t,jsonInvalid:n,onChange:s,onRemove:o,onTestFire:r}){const a=()=>s({...t,hooks:[...t.hooks??[],{type:"command",command:""}]}),i=(d,c)=>{const x=t.hooks.slice();x[d]=c,s({...t,hooks:x})},u=d=>s({...t,hooks:t.hooks.filter((c,x)=>x!==d)});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(I,{value:t.matcher??"",disabled:n,onCommit:d=>s({...t,matcher:d}),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:o,disabled:n,className:"text-fg-faint hover:text-red-400 text-xs disabled:opacity-40",title:"remove group",children:"× group"})]}),(t.hooks??[]).map((d,c)=>e.jsx(qe,{rule:d,jsonInvalid:n,onChange:x=>i(c,x),onRemove:()=>u(c),onTestFire:()=>r(d)},c)),e.jsx("button",{onClick:a,disabled:n,className:"text-xs text-fg-faint hover:text-fg disabled:opacity-40",children:"+ add hook"})]})}function We(t){var s,o,r;const n=((o=(s=ne.$defs)==null?void 0:s.hookCommand)==null?void 0:o.anyOf)??[];for(const a of n){const i=a.properties;if(((r=i==null?void 0:i.type)==null?void 0:r.const)!==t)continue;const u=i.timeout;if(typeof(u==null?void 0:u.default)=="number")return u.default;const d=/default:\s*(\d+)/.exec((u==null?void 0:u.description)??"");return d?Number(d[1]):null}return null}function Z(t){return/^\d+$/.test(t.trim())&&Number(t)>0?Number(t):null}function qe({rule:t,jsonInvalid:n,onChange:s,onRemove:o,onTestFire:r}){const a=l=>({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"})[l],i=t.type==="command"?"command":t.type==="http"?"url":t.type==="prompt"?"prompt":t.type==="mcp_tool"?"mcpTool":"agent",u=t[i]??"",d=(t.args??[]).join(" "),[c,x]=b.useState(null),y=We(t.type),g={type:"hook",name:u||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:n,onChange:l=>s({type:l.target.value}),className:"bg-bg border border-line rounded px-1 py-0.5 text-xs text-fg",children:He.map(l=>e.jsx("option",{value:l,children:l},l))}),e.jsx(Pe,{interactive:!1,input:g}),e.jsx(I,{value:u,disabled:n,onCommit:l=>s({...t,[i]:l}),placeholder:a(t.type),className:`flex-1 bg-bg border rounded px-2 py-0.5 text-xs text-fg font-mono ${n?"border-red-500/70":u.trim()?"border-line":"border-yellow-600/50"}`}),n?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(I,{value:t.timeout!=null?String(t.timeout):"",disabled:n,"aria-label":"timeout (seconds)","aria-invalid":c?!0:void 0,title:c??"Timeout in seconds",onDraft:l=>{x(!l.trim()||Z(l)!=null?null:"Timeout must be a positive whole number of seconds")},onCommit:l=>{if(!l.trim()){s({...t,timeout:void 0});return}const m=Z(l);m!=null&&s({...t,timeout:m})},placeholder:y!=null?`${y} (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:r,disabled:n||!u.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:o,disabled:n,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(I,{value:d,disabled:n,onCommit:l=>s({...t,args:l.trim()?l.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(I,{value:t.terminalSequence??"",disabled:n,onCommit:l=>s({...t,terminalSequence:l||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 Ve(t){return JSON.stringify(Ue[t]??{},null,2)}function ze(t,n){if(!t.trim())return{matched:!0,target:null,note:"empty matcher → matches all"};const s=n&&typeof n=="object"&&"tool_name"in n?String(n.tool_name??""):null;if(s==null)return{matched:!1,target:null,note:"payload has no tool_name to match against"};try{return{matched:new RegExp(`^(?:${t})$`).test(s),target:s}}catch{return{matched:t===s,target:s,note:"matcher not valid regex; fell back to exact match"}}}function Ye({event:t,matcher:n,command:s,onClose:o}){const[r,a]=b.useState(()=>Ve(t)),[i,u]=b.useState(!1),[d,c]=b.useState(null),[x,y]=b.useState(null);let g=null;try{JSON.parse(r)}catch(m){g=m.message}const l=async()=>{u(!0),c(null);let m=null;try{m=JSON.parse(r)}catch{}y(ze(n,m));try{const h=await window.api.app.testFireHook({command:s,payload:r,timeoutMs:5e3});c(h)}finally{u(!1)}};return e.jsx(ge,{open:!0,onClose:o,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:s})]}),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:n||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)"}),g?e.jsxs("span",{className:"text-red-400",children:["× ",g]}):null]}),e.jsx("textarea",{value:r,onChange:m=>a(m.target.value),rows:8,className:`w-full bg-bg border rounded px-2 py-1 font-mono text-fg ${g?"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,d?e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"text-fg-faint",children:["exit ",d.exitCode," · ",d.durationMs,"ms"]}),d.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:d.stdout})]}):null,d.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:d.stderr})]}):null]}):null,e.jsxs("div",{className:"flex items-center justify-end gap-2 pt-1",children:[e.jsx("button",{onClick:o,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:l,disabled:i||!!g||!s.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:i?"running…":"run"})]})]})})}const le=[{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"]}],Q=new Set(le.flatMap(t=>t.keys)),Ze=[{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"]}],Qe={mcp:"MCP",url:"URL",urls:"URLs",http:"HTTP",ui:"UI",id:"ID",uuid:"UUID",api:"API",aws:"AWS",otel:"OTel",json:"JSON"};function ce(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((o,r)=>{const a=Qe[o];return a||(r===0?o.charAt(0).toUpperCase()+o.slice(1):o)}).join(" ")}function de(t){const n=new Set,s=[];for(const r of Ze){const a=r.keys.filter(i=>t.has(i)&&!Q.has(i));a.forEach(i=>n.add(i)),a.length!==0&&s.push({id:r.id,title:r.title,summary:r.summary,advanced:!!r.advanced,keys:a})}const o=Array.from(t).filter(r=>!n.has(r)&&r!=="$schema"&&!Q.has(r)).sort();return o.length>0&&s.push({id:"other",title:"Other",summary:"Keys not yet grouped.",advanced:!1,keys:o}),s}function Xe(t,n){return de(t).map(s=>({id:s.id,title:s.title,advanced:s.advanced,total:s.keys.length,setCount:s.keys.filter(o=>n.has(o)).length}))}const et={};function ue(t,n){if(n)return{text:n,authored:!1};const s=et[t];return s?{text:s,authored:!0}:null}const me=b.createContext(null);function tt(){const t=b.useContext(me);if(!t)throw new Error("usePageShell() must be used inside a <PageShell>.");return t}function O({header:t,subnav:n,footer:s,children:o,subnavWidth:r=220}){const a=b.useRef(null),i=b.useCallback((d,c)=>{const x=a.current;if(!x)return;let y=null;for(const g of Array.from(x.querySelectorAll("[id]")))if(g.id===d){y=g;break}y&&be(x,y,{block:"start",behavior:c==null?void 0:c.behavior})},[]),u=b.useMemo(()=>({scrollToAnchor:i,contentRef:a}),[i]);return e.jsx(me.Provider,{value:u,children:e.jsxs("div",{"data-testid":"page-shell",className:"h-full w-full min-h-0 min-w-0 flex flex-col overflow-clip",children:[t!=null&&e.jsx("div",{"data-testid":"page-shell-header",className:"shrink-0 min-w-0 overflow-clip",children:t}),e.jsxs("div",{"data-testid":"page-shell-body",className:"flex-1 min-h-0 min-w-0 flex flex-row overflow-clip",children:[n!=null&&e.jsx("nav",{"data-testid":"page-shell-subnav",className:"shrink-0 min-h-0 overflow-y-auto overscroll-contain",style:{width:r},children:n}),e.jsx("div",{ref:a,"data-testid":"page-shell-content",className:"flex-1 min-w-0 min-h-0 overflow-y-auto overscroll-contain",children:o})]}),s!=null&&e.jsx("div",{"data-testid":"page-shell-footer",className:"shrink-0 min-w-0 overflow-clip",children:s})]})})}const st={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"},nt=["user","project","local","default"],rt={user:"user",project:"project",local:"local",default:"default"};function at({node:t,schema:n}){const[s,o]=b.useState(""),[r,a]=b.useState(!1),[i,u]=b.useState(!0),d=t.kind==="object"?t:null,c=d?Object.keys(d.children):[],x=n.rootKeys(),y=new Set([...c,...x]),g=Array.from(y).sort().join(","),l=c.join(","),m=b.useMemo(()=>de(y),[g]),h=b.useMemo(()=>Xe(y,new Set(c)),[g,l]),f=b.useMemo(()=>m.filter(w=>r||!w.advanced).map(w=>({...w,keys:w.keys.filter(k=>{const E=(d==null?void 0:d.children[k])!==void 0;if(!i&&!E)return!1;if(!s.trim())return!0;const N=n.at([k]);return[k,ce(k),(N==null?void 0:N.description)??""].join(" ").toLowerCase().includes(s.toLowerCase())})})).filter(w=>w.keys.length>0),[m,s,r,i,d,n]);return{filter:s,setFilter:o,showAdvanced:r,setShowAdvanced:a,showUnset:i,setShowUnset:u,rootNode:d,schema:n,groups:m,railGroups:h,visibleGroups:f}}function ot({cards:t,targetScope:n}){return e.jsxs("div",{className:"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:_[n].label})]}),e.jsxs("label",{className:"flex items-center gap-1 text-fg-faint cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:t.showUnset,onChange:s=>t.setShowUnset(s.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:t.showAdvanced,onChange:s=>t.setShowAdvanced(s.target.checked),className:"accent-accent"}),"show advanced"]}),e.jsx("div",{className:"flex-1"}),e.jsx("input",{value:t.filter,onChange:s=>t.setFilter(s.target.value),placeholder:"search settings…",className:"bg-bg border border-line rounded px-2 py-1 text-xs text-fg w-64"})]})}function it({cards:t,targetScope:n,onOverride:s}){const{visibleGroups:o,rootNode:r,schema:a,filter:i}=t;return e.jsxs("div",{className:"py-3",children:[o.map(u=>e.jsx(dt,{id:u.id,title:u.title,summary:u.summary,advanced:u.advanced,children:u.keys.map(d=>{const c=r==null?void 0:r.children[d],x=a.at([d]);return e.jsx(ut,{keyName:d,node:c,info:x,targetScope:n,onOverride:(y,g)=>s([d],y,g)},d)})},u.id)),o.length===0&&e.jsxs("div",{className:"px-6 py-12 text-center text-fg-faint text-sm",children:['no settings match "',i,'"']})]})}function lt({cards:t}){const n=tt(),[s,o]=b.useState(null),{groups:r,showAdvanced:a,setShowAdvanced:i}=t,u=d=>{const c=r.find(x=>x.id===d);c!=null&&c.advanced&&!a&&i(!0),o(d)};return b.useEffect(()=>{s&&(o(null),n.scrollToAnchor(`settings-group-${s}`,{behavior:"smooth"}))},[s,n]),e.jsx(ct,{groups:t.railGroups,onJump:u})}function ct({groups:t,onJump:n}){return e.jsx("div",{className:"min-h-full border-r border-line bg-bg-elev/30 py-3",children:t.map(s=>e.jsxs("button",{type:"button","data-group-id":s.id,onClick:()=>n(s.id),className:"w-full flex items-center gap-2 px-3 py-2 text-left hover:bg-bg-hi transition-colors",title:`jump to ${s.title}`,children:[e.jsx(ye,{name:st[s.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:s.title}),e.jsxs("span",{className:"text-[10px] text-fg-faint font-mono shrink-0",children:[s.setCount,"/",s.total]})]},s.id))})}function dt({id:t,title:n,summary:s,advanced:o,children:r}){const[a,i]=b.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:()=>i(!a),children:[e.jsx("span",{className:"text-fg-faint w-3",children:a?"▾":"▸"}),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:n}),o&&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:s})]})]}),a&&e.jsx("div",{className:"divide-y divide-line/60",children:r})]})}function ut({keyName:t,node:n,info:s,targetScope:o,onOverride:r}){const[a,i]=b.useState(!1),[u,d]=b.useState(!1),c=ce(t),x=n!==void 0,g=(n==null?void 0:n.kind)==="leaf"?n:null,l=(n==null?void 0:n.kind)==="object"||(n==null?void 0:n.kind)==="array",m=s==null?void 0:s.default,h=g&&m!==void 0&&xe(g.value,m),f=yt({isSet:x,leafNode:g,defaultVal:m,isDefault:!!h,node:n}),w=mt(g,m),k=w.length>=2,E=!!g&&!h,N=ue(t,s==null?void 0:s.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:()=>i(!a),className:"text-fg-faint hover:text-fg w-3 mt-0.5",title:a?"collapse":"expand",children:a?"▾":"▸"}),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(vt,{kind:f.kind,label:f.label}),k&&e.jsxs("button",{onClick:S=>{S.stopPropagation(),a||i(!0),d(C=>!C)},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 · ",w.map(S=>rt[S]).join(" · ")]}),E&&g&&e.jsx("button",{onClick:S=>{S.stopPropagation(),r(void 0,g.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 ${_[g.winner].label}`,children:"↺ reset"}),(s==null?void 0:s.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"}),(s==null?void 0:s.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"})]}),N&&e.jsx("p",{className:`text-fg-dim text-xs mt-0.5 leading-relaxed ${N.authored?"inline-block border-b border-dotted border-fg-faint/70 cursor-help":""}`,title:N.authored?"In-app-authored description — not from the official Claude Code schema":void 0,children:jt(N.text)}),a&&u&&g&&e.jsx(pt,{leaf:g,defaultVal:m,onReset:S=>r(void 0,S)}),a&&e.jsx(xt,{keyName:t,node:n,info:s,targetScope:o,onOverride:S=>r(S)})]}),e.jsx("div",{className:"shrink-0",children:!a&&e.jsx(bt,{node:n,info:s,onSet:S=>{r(S)},disabled:l&&x})})]})})}function mt(t,n){if(!t)return[];const s=new Set;s.add(t.winner);for(const o of t.shadowed)s.add(o.scope);return n!==void 0&&s.add("default"),nt.filter(o=>s.has(o))}function pt({leaf:t,defaultVal:n,onReset:s}){const o={};o[t.winner]={value:t.value,winner:!0};for(const r of t.shadowed)o[r.scope]={value:r.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(r=>{const a=o[r],i=a!==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:_[r].label}),e.jsx("span",{className:`font-mono truncate ${a!=null&&a.winner?"text-accent":"text-fg-dim"}`,children:i?$(a.value):e.jsx("span",{className:"text-fg-faint",children:"—"})}),i?e.jsx("button",{onClick:()=>s(r),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 ${_[r].label}`,children:"↺"}):e.jsx("span",{})]},r)}),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:n!==void 0?$(n):e.jsx("span",{className:"text-fg-faint",children:"—"})}),e.jsx("span",{})]})]})]})}function xt({keyName:t,node:n,info:s,targetScope:o,onOverride:r}){const i=(n==null?void 0:n.kind)==="leaf"?n:null,u=ue(t,s==null?void 0:s.description);return e.jsxs("div",{className:"mt-3 space-y-2 text-xs",children:[u&&e.jsx("p",{className:`text-fg-dim leading-relaxed whitespace-pre-wrap ${u.authored?"inline-block border-b border-dotted border-fg-faint/70 cursor-help":""}`,title:u.authored?"In-app-authored description — not from the official Claude Code schema":void 0,children:u.text}),e.jsxs("dl",{className:"grid grid-cols-[auto_1fr] gap-x-3 gap-y-1 text-fg-faint",children:[(s==null?void 0:s.type)&&e.jsxs(e.Fragment,{children:[e.jsx("dt",{children:"Type"}),e.jsx("dd",{className:"text-fg-dim font-mono",children:Array.isArray(s.type)?s.type.join(" | "):s.type})]}),(s==null?void 0:s.default)!==void 0&&e.jsxs(e.Fragment,{children:[e.jsx("dt",{children:"Default"}),e.jsx("dd",{className:"text-fg-dim font-mono",children:$(s.default)})]}),(s==null?void 0:s.enum)&&e.jsxs(e.Fragment,{children:[e.jsx("dt",{children:"Options"}),e.jsx("dd",{className:"text-fg-dim font-mono",children:s.enum.map(d=>String(d)).join(" | ")})]}),i&&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:$(i.value)}),e.jsxs("span",{className:"ml-2 text-fg-faint",children:["from ",_[i.winner].label]})]})]}),i&&i.shadowed.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("dt",{children:"Shadowed"}),e.jsx("dd",{className:"space-y-0.5",children:i.shadowed.map((d,c)=>e.jsxs("div",{className:"font-mono text-fg-faint line-through",children:[$(d.value)," —"," ",e.jsx("span",{className:"no-underline",children:_[d.scope].label})]},c))})]}),(n==null?void 0:n.kind)==="array"&&e.jsxs(e.Fragment,{children:[e.jsx("dt",{children:"Accumulated"}),e.jsxs("dd",{className:"text-fg-dim",children:[n.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(ht,{keyName:t,node:n,info:s,onChange:r,targetScope:o})})]})}function ht({node:t,info:n,onChange:s,targetScope:o}){const a=(t==null?void 0:t.kind)==="leaf"?t.value:n==null?void 0:n.default,i=pe(n==null?void 0:n.type);if(i==="boolean"){const u=a===!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:d,label:c})=>e.jsx("button",{onClick:()=>s(d),className:`px-3 py-0.5 text-xs transition-colors ${u===d?"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:["→ ",_[o].label]})]})}return n!=null&&n.enum?e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"text-fg-faint",children:"Choose:"}),n.enum.map(u=>{const d=xe(a,u);return e.jsx("button",{onClick:()=>s(u),className:`px-2 py-0.5 text-xs rounded border ${d?"bg-accent text-bg border-accent":"bg-bg-elev text-fg-dim border-line hover:text-fg hover:bg-bg-hi"}`,children:String(u)},String(u))}),e.jsxs("span",{className:"text-fg-faint",children:["→ ",_[o].label]})]}):i==="integer"||i==="number"?e.jsx(ft,{value:typeof a=="number"?a:void 0,integer:i==="integer",onCommit:s,target:_[o].label}):i==="string"?e.jsx(gt,{value:typeof a=="string"?a:"",onCommit:s,target:_[o].label}):e.jsxs("div",{className:"text-fg-faint",children:["Complex value (",i??"object/array",") — use the"," ",e.jsx("span",{className:"text-fg-dim",children:"Raw"})," tab to edit."]})}function ft({value:t,integer:n,onCommit:s,target:o}){const[r,a]=b.useState(t!==void 0?String(t):""),i=()=>{const u=n?parseInt(r,10):parseFloat(r);Number.isNaN(u)||s(u)};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:r,onChange:u=>a(u.target.value),onBlur:i,onKeyDown:u=>{u.key==="Enter"&&u.target.blur()},className:"w-24 bg-bg border border-line rounded px-2 py-0.5 text-xs text-fg"}),e.jsxs("button",{onClick:i,className:"px-2 py-0.5 text-xs border border-accent/50 rounded text-accent hover:bg-accent hover:text-bg",children:["save → ",o]})]})}function gt({value:t,onCommit:n,target:s}){const[o,r]=b.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:o,onChange:a=>r(a.target.value),onKeyDown:a=>{a.key==="Enter"&&n(o)},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:()=>n(o),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 → ",s]})]})}function bt({node:t,info:n,onSet:s,disabled:o}){const r=(t==null?void 0:t.kind)==="leaf",a=pe(n==null?void 0:n.type);if(o)return null;if(a==="boolean"){const i=r&&t.value===!0;return e.jsx("button",{onClick:()=>s(!i),className:`px-2.5 py-0.5 text-xs rounded border transition-colors ${i?"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:i?"on":"off"})}return null}function yt({isSet:t,leafNode:n,defaultVal:s,isDefault:o,node:r}){return t?(r==null?void 0:r.kind)==="array"?{kind:"accumulated",label:`${r.items.length} items`}:(r==null?void 0:r.kind)==="object"?{kind:"set",label:"configured"}:n?o?{kind:"default",label:`= default · ${_[n.winner].label}`}:n.shadowed.length>0?{kind:"override",label:`overriding ${n.shadowed.length} scope(s)`}:{kind:"set",label:`set in ${_[n.winner].label}`}:{kind:"set",label:"configured"}:s!==void 0?{kind:"default",label:`using default: ${$(s)}`}:{kind:"unset",label:"not configured"}}function vt({kind:t,label:n}){const s={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 ${s}`,children:n})}function pe(t){if(t)return Array.isArray(t)?t.find(s=>s!=="null")??t[0]:t}function xe(t,n){return t===n?!0:typeof t!=typeof n?!1:t&&n&&typeof t=="object"?JSON.stringify(t)===JSON.stringify(n):!1}function jt(t){const n=t.trim().split(`
2
2
  `)[0],s=n.match(/^([^.!?]+[.!?])/);return s?s[1]:n.length>120?n.slice(0,120)+"…":n}function $(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 n=JSON.stringify(t);return n.length>60?n.slice(0,60)+"…":n}return String(t)}const X={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 wt({effective:t,onOpenTab:n}){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:le.map(s=>{const o=s.keys.filter(a=>Ne(t,[a])!==null),r=o.length?`${o.length} of ${s.keys.length} keys set (${o.join(", ")})`:"nothing set";return e.jsxs("li",{"data-testid":`owned-summary-${s.id}`,className:"flex items-center gap-2 text-fg-dim",children:[e.jsx("span",{className:"font-semibold text-fg w-28 shrink-0",children:s.label}),e.jsx("span",{className:"truncate",children:r}),s.tab?e.jsxs("button",{type:"button",onClick:()=>n(s.tab),className:"ml-auto text-accent hover:underline shrink-0",children:["edit in ",s.label," tab →"]}):e.jsxs("span",{className:"ml-auto text-fg-faint shrink-0",children:["managed on the ",s.label," page"]})]},s.id)})})}function kt({scope:t="user"}={}){const n=U(),s=q(p=>p.tabs),o=q(p=>p.activeTabId),r=s.find(p=>p.id===o)??null,a=(r==null?void 0:r.cwd)??null,[i,u]=b.useState("general");ve("settings",p=>{(p==="general"||p==="permissions"||p==="hooks"||p==="raw")&&u(p)});const d=G(se,n,a),c=d[t]??null,x=A(p=>p.files),y=A(p=>p.setDraft),g=A(p=>p.saveJson),l=A(p=>p.revert),[m,h]=b.useState(null),f=b.useMemo(()=>je(we(x,d)),[x,d]),w=re(),k=at({node:f,schema:w}),E=(p,T,M)=>{var W;const B=M??t,L=d[B];if(!L)return;const J=((W=x[L])==null?void 0:W.draftRaw)??"";if(J.trim())try{JSON.parse(J)}catch(F){h(`${L} is not valid JSON (${F instanceof Error?F.message:String(F)}) — fix it in Raw before editing from General.`);return}h(null),window.api.claudeConfig.patch({fileId:"settings",scope:B,cwd:a,keyPath:p,value:T}).catch(F=>D.error(F instanceof Error?F.message:String(F)))};if(!n)return e.jsx(P,{title:"loading…"});const N=c?x[c]:null,S=p=>p!=="user"&&!a,C=e.jsxs("div",{"data-testid":"settings-scope-note",className:"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:X[t].title}),e.jsx("span",{className:"mx-1.5 text-fg-faint",children:"·"}),e.jsx("span",{className:"text-fg-dim",children:X[t].body}),c&&e.jsx("span",{className:"ml-1.5 font-mono text-fg-faint",children:c})]}),v=p=>e.jsx("div",{className:"px-3 py-2",children:e.jsx(V,{path:c??"",keyPath:p})}),j=m&&i!=="raw"?e.jsx("div",{role:"alert",className:"px-3 py-2 border-b border-line text-xs text-red-400",children:m}):null;return e.jsx(R,{toolbar:e.jsxs(e.Fragment,{children:[e.jsx(K,{options:[{key:"general",label:"General"},{key:"permissions",label:"Permissions"},{key:"hooks",label:"Hooks"},{key:"raw",label:"Raw"}],active:i,onChange:u}),e.jsx(e.Fragment,{children:e.jsx("span",{className:"ml-3 text-fg-faint truncate",children:i==="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 ↗"})]}),children:i==="general"&&!S(t)?e.jsxs(O,{subnavWidth:192,header:e.jsxs(e.Fragment,{children:[C,j,e.jsx(ot,{cards:k,targetScope:t})]}),subnav:e.jsx(lt,{cards:k}),children:[e.jsx("div",{className:"px-3 pt-2",children:e.jsx(V,{path:c??""})}),e.jsx(wt,{effective:f,onOpenTab:u}),e.jsx(it,{cards:k,targetScope:t,onOverride:E})]}):S(t)?e.jsx(O,{header:e.jsxs(e.Fragment,{children:[C,j]}),children:e.jsx(P,{title:"no active project",hint:"open a tab in a project directory to edit project or local settings"})}):c?i==="permissions"?e.jsx(O,{header:e.jsxs(e.Fragment,{children:[C,j,v(["permissions"])]}),children:e.jsx(ae,{scope:t,cwd:a,activePath:c})}):i==="hooks"?e.jsx(ie,{scope:t,cwd:a,path:c,renderLayout:({banners:p,list:T,detail:M})=>e.jsx(O,{subnavWidth:224,header:e.jsxs(e.Fragment,{children:[C,j,v(["hooks"]),p]}),subnav:e.jsx("div",{className:"min-h-full border-r border-line",children:T}),children:M})}):N?e.jsx(O,{header:e.jsxs(e.Fragment,{children:[C,v()]}),footer:e.jsx("div",{className:"border-t border-line bg-bg-elev",children:e.jsx(_e,{dirty:N.dirty,busy:N.busy,parseError:m||N.parseError,lastSavedAt:N.lastSavedAt,leading:N.exists?null:e.jsx("span",{children:"file will be created on save"}),onSave:async()=>{h(null);const p=await g(c);p.ok||h(p.error??"save failed")},onRevert:()=>{h(null),l(c)}})}),children:e.jsx("div",{"data-testid":"settings-raw-editor",className:"h-full overflow-clip",children:e.jsx(ke,{path:c,value:N.draftRaw,onChange:p=>{h(null),y(c,p)}})})}):e.jsx(O,{header:e.jsxs(e.Fragment,{children:[C,j]}),children:e.jsx(P,{title:"resolving…"})}):e.jsx(O,{header:e.jsxs(e.Fragment,{children:[C,j]}),children:e.jsx(P,{title:"resolving…"})})})}const Mt=b.memo(kt);export{X as SETTINGS_SCOPE_NOTES,Mt as Settings};
@@ -1,4 +1,4 @@
1
- import{aO as Z,R as wo,au as ko,ay as tr}from"./index-Cznhnxhq.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.
1
+ import{aO as Z,R as wo,au as ko,ay as tr}from"./index-rt7pTODX.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.