claude-code-session-manager 0.130.1 → 0.130.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{AgentLibrary-Dlhtc8Ty.js → AgentLibrary-Bfj862qf.js} +1 -1
- package/dist/assets/{AppSettings-A3KoPcmL.js → AppSettings-Bpwynea4.js} +1 -1
- package/dist/assets/{Button-DvTXa_-4.js → Button-DSoqrxCB.js} +1 -1
- package/dist/assets/{Extensions-Ddb4sQpO.js → Extensions-BziIutWV.js} +3 -3
- package/dist/assets/{History-DcnZxMoU.js → History-DzMo9Otn.js} +1 -1
- package/dist/assets/{Library-LftcMs6C.js → Library-C5wKMTSn.js} +1 -1
- package/dist/assets/{ListDetail-CnL1azR0.js → ListDetail-DDQ1S0yu.js} +1 -1
- package/dist/assets/{Memory-smN9-Yoo.js → Memory-Bq5T33d2.js} +1 -1
- package/dist/assets/{Panel-CA6TdCHv.js → Panel-B-3NWUlv.js} +1 -1
- package/dist/assets/{ProvenanceBadge-Y3DhyiJo.js → ProvenanceBadge-CUChwz4Z.js} +1 -1
- package/dist/assets/{Scheduler-Ca1qo_kp.js → Scheduler-CkGHMXvo.js} +1 -1
- package/dist/assets/{Settings-BFwlV-as.js → Settings-DGxvyajs.js} +1 -1
- package/dist/assets/{SkillReferenceGraph-2WMsKdmr.js → SkillReferenceGraph-C6JEdypC.js} +1 -1
- package/dist/assets/{SourceChip-CeprSxwb.js → SourceChip-DcBNYYhe.js} +1 -1
- package/dist/assets/{SystemPrompt-B8TXIGXo.js → SystemPrompt-CfozyVQx.js} +1 -1
- package/dist/assets/{TiptapBody-BvxcQ_tS.js → TiptapBody-DiVYC-_O.js} +1 -1
- package/dist/assets/{Toggle-keTV_HDb.js → Toggle-Cs3k6I96.js} +1 -1
- package/dist/assets/{ViewTabs-fupn9keJ.js → ViewTabs-DFXH03tb.js} +1 -1
- package/dist/assets/{VoiceButton-5ETBv9eI.js → VoiceButton-C3NLotUZ.js} +1 -1
- package/dist/assets/{historyTotals-NAZqiuzd.js → historyTotals-f-E0L9Xw.js} +1 -1
- package/dist/assets/{index-QJxszEhM.js → index-CuAfFXNd.js} +3 -3
- package/dist/index.html +1 -1
- package/dist-web/app.js +1 -1
- package/package.json +1 -1
- package/src/main/build-info.json +4 -4
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{aP as Pe,aC as ie,ai as Te,aW as xs,an as Ce,ah as ue,al as te,a$ as H,bg as Fe,bf as pe,bj as Tt,aJ as f,af as xe,bp as ms,at as t,c as Ue,I as me,L as bt,p as bs,K as ge,u as ws,U as vs,e as js,W as ys,aV as Ns,bd as st,b6 as ks,ac as wt,aA as _t,bo as $e,N as qe,aH as _e,a as nt,aU as at,T as Ot,x as Lt,o as Ft,q as Ss,m as rt,z as it,O as Cs,g as re,h as B,aj as qt,bh as $s,aI as Ps,w as Ds,aL as Bt,bs as Ht,Y as As,aD as vt,b7 as jt,l as ke,y as yt,aQ as Nt,k as Rs,aZ as Ms,a3 as Is,v as Gt,b9 as Es,b3 as ye,Q as Ts,C as _s,au as Os,bb as Ls,V as Fs,bk as kt,aT as qs}from"./index-QJxszEhM.js";import{f as Bs,a as Hs,s as Gs}from"./historyTotals-NAZqiuzd.js";import"./monaco-editor-BsIlgG7c.js";function Vs(e){const s=new Map(e.map(i=>[i.slug,i])),n=new Map,a=new Set,d=[];function l(i){n.set(i,1),d.push(i);const r=s.get(i);for(const o of(r==null?void 0:r.dependsOn)??[]){if(!s.has(o))continue;const c=n.get(o);if(c===1){const p=d.indexOf(o);for(let u=p;u<d.length;u++)a.add(d[u])}else c===void 0&&l(o)}d.pop(),n.set(i,2)}for(const i of e)n.has(i.slug)||l(i.slug);return a}function Ws(e,s){return(e.dependsOn??[]).map(n=>{const a=s.get(n);return a?{slug:n,status:a.status,missing:!1,needsReview:a.status==="needs_review"}:{slug:n,status:null,missing:!0,needsReview:!1}})}function Us(e,s,n){const a=new Set(e.map(c=>c.slug)),d=new Set;for(const c of e)for(const p of c.dependsOn??[])a.has(p)&&d.add(p);const l=new Map,i=[];for(const c of e){const p=n.has(c.slug)?void 0:(c.dependsOn??[]).find(u=>a.has(u)&&!n.has(u));p?(l.has(p)||l.set(p,[]),l.get(p).push(c)):i.push(c)}const r=(c,p)=>c.slug.localeCompare(p.slug);i.sort(r);for(const c of l.values())c.sort(r);function o(c,p,u){const h=Ws(c,s),g=n.has(c.slug);u.add(c.slug);const m=g?[]:(l.get(c.slug)??[]).filter(v=>!u.has(v.slug)).map(v=>o(v,p+1,u));return u.delete(c.slug),{row:c,depth:p,children:m,blockers:h,blocked:h.some(v=>!v.missing&&v.status!=="completed"),hasNeedsReviewBlocker:h.some(v=>v.needsReview),hasMissingDep:h.some(v=>v.missing),cycle:g,parallelEligible:(c.dependsOn??[]).length===0&&!d.has(c.slug)}}return i.map(c=>o(c,0,new Set))}function Vt(e,s,n){const a=new Map((n??e).map(c=>[c.slug,c])),d=Vs(e),l=[],i=new Map,r=new Map;for(const c of e){const p=Pe(c,s),u=p.epicId??"__none__";i.has(u)||(l.push(u),i.set(u,[]),r.set(u,{epicId:p.epicId,label:p.known&&p.label?p.label:p.epicId?`Epic ${p.epicId.slice(0,12)}…`:"No Epic",known:p.known})),i.get(u).push(c)}const o=l.map(c=>{const p=r.get(c),u=i.get(c),h=Us(u,a,d),g={};for(const m of u){const v=m.status??"unknown";g[v]=(g[v]??0)+1}return{epicId:p.epicId,label:p.label,known:p.known,nodes:h,counts:g,total:u.length}});return o.sort((c,p)=>c.epicId===null?1:p.epicId===null?-1:c.known!==p.known?c.known?-1:1:c.label.localeCompare(p.label)),o}function Be(e){const s=[],n=a=>{s.push(a);for(const d of a.children)n(d)};for(const a of e)n(a);return s}function Ke(e){return String(e??"").replace(/^\d+-/,"")}function Oe(e){const s=new Set,n=new Map;for(const a of e){s.add(a.slug);const d=Ke(a.slug),l=n.get(d);l?l.push(a.slug):n.set(d,[a.slug])}return e.map(a=>{const d=a.dependsOn;if(!d||d.length===0)return a;let l=!1;const i=d.map(r=>{if(s.has(r))return r;const o=n.get(Ke(r));return o&&o.length===1?(l=!0,o[0]):r});return l?{...a,dependsOn:i}:a})}const zs=15e4,Xe=e=>e==="completed"||e==="skipped",Se=e=>e==="running"||e==="investigating",Wt=e=>e==="failed"||e==="needs_review"||e==="quarantined",Qs=e=>e==="failed"||e==="needs_review"||e==="quarantined";function Ut(e){if(e<=5e3)return"~now";if(e<6e4)return`~${Math.round(e/1e3)}s`;const s=Math.round(e/6e4);return s<60?`~${s}m`:`~${Math.floor(s/60)}h${String(s%60).padStart(2,"0")}m`}function zt(e,s){const n=e.estimateMinutes?e.estimateMinutes*6e4:null;return n?`${Math.min(99,Math.floor(s/n*100))}%`:Te(s)}function Ys(e){let s=0,n=0;for(const a of e)if(a.status==="completed"&&a.startedAt&&a.finishedAt){const d=Date.parse(a.finishedAt)-Date.parse(a.startedAt);d>0&&(s+=d,n++)}return n===0?zs:s/n}function Le(e){const s=ie(e);return s===null?1/0:Number(s)}function Ze(e,s){const n=Le(e.slug)-Le(s.slug);return n!==0&&!Number.isNaN(n)?n:e.slug.localeCompare(s.slug)}function Js(e){let s=0;for(const n of e.statusHistory??[])n.to==="pending"&&n.from!==null&&s++;return s}function Ks(e){return e.some(n=>Se(n.status))?"active":e.every(n=>Xe(n.status))?"done":e.filter(n=>n.status!=="quarantined").length===0?"draft":"queued"}function Xs(e,s,n,a){switch(e){case"done":return`${s.doneCount}/${s.rows.length} done`;case"running":return`${s.runningCount} running · ${n}`;case"held":return`${s.heldCount} held`;case"blocked":return`${s.blockedCount+a} blocked`;default:return`${n} ready`}}function Zs(e,s){return e._firstNum!==s._firstNum?e._firstNum<s._firstNum?-1:1:e._firstSlug.localeCompare(s._firstSlug)}function en(e,s){const n=new Map(e.map(l=>[l.row.slug,l.row.slug])),a=l=>{for(;n.get(l)!==l;)n.set(l,n.get(n.get(l))),l=n.get(l);return l};for(const l of e)for(const i of l.row.dependsOn??[])s.has(i)&&n.set(a(l.row.slug),a(i));const d=new Map;for(const l of e){const i=a(l.row.slug),r=d.get(i);r?r.push(l):d.set(i,[l])}return[...d.values()]}function tn(e,s){if(e.length>0&&e.every(n=>!!n.row.planId)){const n=new Map;for(const a of e){const d=n.get(a.row.planId);d?d.push(a):n.set(a.row.planId,[a])}return[...n.values()]}return en(e,s)}function sn(e,s,n,a){const d=[],l=[e];for(a.add(e.row.slug);l.length>0;){const i=l.pop();d.push(i);for(const r of i.row.dependsOn??[])if(n.has(r)&&!a.has(r)){a.add(r);const o=s.get(r);o&&l.push(o)}}return d}function nn(e,s){const n=new Map(e.map(r=>[r.row.slug,r])),a=new Set,d=[],l=e.filter(r=>Ke(r.row.slug).startsWith("validate-")).sort((r,o)=>Ze({slug:r.row.slug},{slug:o.row.slug}));for(const r of l)a.has(r.row.slug)||d.push({nodes:sn(r,n,s,a),validateSlug:r.row.slug});const i=e.filter(r=>!a.has(r.row.slug));if(i.length>0){const r=new Set(i.map(o=>o.row.slug));for(const o of tn(i,r))d.push({nodes:o,validateSlug:null})}return d}function an(e){return e.replace(/^validate[\s:-]*/i,"").trim()}function lt(e,s){if(e.length===0)return[];const n=Oe(e),a=s.now??Date.now(),d=s.avgDurationMs??Ys(n),l=Math.max(1,s.concurrency??1),i=new Map(n.map(u=>[u.slug,u])),r=u=>u.status==="pending"&&(u.dependsOn??[]).every(h=>i.get(h)===void 0||i.get(h).status==="completed"),o=new Map;n.filter(r).sort(Ze).forEach((u,h)=>o.set(u.slug,h));const c=Vt(n,s.sessions,n),p=[];for(const u of c){const h=Be(u.nodes),g=new Set(h.map(k=>k.row.slug)),m=new Map(h.map(k=>[k.row.slug,k])),v=[];for(const k of nn(h,g)){const S=k.nodes,T=new Set(S.map(N=>N.row.slug)),x=new Map,R=new Set,P=N=>{const C=m.get(N);return(C.row.dependsOn??[]).filter(q=>T.has(q)&&!(C.cycle&&m.get(q).cycle))},D=N=>{const C=x.get(N);if(C!==void 0)return C;if(R.has(N))return 0;R.add(N);let q=0;for(const V of P(N))q=Math.max(q,D(V));return R.delete(N),x.set(N,q+1),q+1};for(const N of S)D(N.row.slug);const O=S.map(N=>{const C=N.row,q=(C.dependsOn??[]).filter(V=>g.has(V));return{slug:C.slug,title:C.title,status:C.status,stage:x.get(C.slug),prdNumber:ie(C.slug),rowKind:"dep",rowTrailing:"",cycle:N.cycle,estimateMinutes:C.estimateMinutes??null,deps:q,crossEpicDeps:(C.dependsOn??[]).filter(V=>!g.has(V)),blockers:N.blockers,job:C}});O.sort(Ze);const J=O.reduce((N,C)=>Math.max(N,C.stage),0),W=new Map;for(const N of O){const C=N.job,q=m.get(N.slug),V=C.status;let U;if(Xe(V)){const b=C.startedAt&&C.finishedAt?Date.parse(C.finishedAt)-Date.parse(C.startedAt):NaN;U={kind:"done",trailing:b>0?Te(b):"",held:!1,blocked:!1}}else if(Se(V)){const b=C.startedAt?Math.max(0,a-Date.parse(C.startedAt)):null;U={kind:"running",trailing:b===null?"":zt(C,b),held:!1,blocked:!1}}else if(V==="failed")U={kind:"failed",trailing:"failed",held:!1,blocked:!1};else if(V==="needs_review")U={kind:"review",trailing:"review",held:!1,blocked:!1};else if(V==="quarantined")U={kind:"quarantined",trailing:"quarantined",held:!1,blocked:!1};else{const b=q.blockers.filter(j=>!j.missing&&j.status!=="completed");if(b.length>0){const j=b.some($=>Qs($.status)),A=b[0].slug;U={kind:"dep",trailing:`←${ie(A)??A}`,held:!j,blocked:j}}else if(C.heldReason)U={kind:"gate",trailing:"gate",held:!0,blocked:!1};else{const j=Js(C),A=o.get(C.slug)??0;U=j>0?{kind:"retry",trailing:`${j} ${j===1?"retry":"retries"}`,held:!1,blocked:!1}:{kind:"eta",trailing:Ut(A*d/l),held:!1,blocked:!1}}}W.set(N.slug,U)}const z=[];for(let N=1;N<=J;N++){const C=O.filter(_=>_.stage===N),q=C.find(_=>{const Z=W.get(_.slug).kind;return _.status==="pending"&&(Z==="eta"||Z==="retry")});if(q){const _=W.get(q.slug);_.kind="next",_.trailing="next"}let V=0,U=0,b=0,j=0,A=0,$=0;for(const _ of C){const Z=W.get(_.slug);_.rowKind=Z.kind,_.rowTrailing=Z.trailing,Xe(_.status)?V++:Se(_.status)?U++:_.status==="pending"?(A++,Z.held&&b++,Z.blocked&&j++):Wt(_.status)&&$++}const I=V===C.length?"done":U>0?"running":j+$>0?"blocked":b>0?"held":"pending",L={n:N,rows:C,doneCount:V,runningCount:U,heldCount:b,blockedCount:j};z.push({...L,state:I,summary:Xs(I,L,A,$)})}let K=0;for(const N of O){const C=N.estimateMinutes?N.estimateMinutes*6e4:d;if(N.status==="pending")K+=C;else if(Se(N.status)){const q=N.job.startedAt?Math.max(0,a-Date.parse(N.job.startedAt)):0;K+=Math.max(0,C-q)}}const X=O.reduce((N,C)=>Math.min(N,Le(C.slug)),1/0),se=O.reduce((N,C)=>Math.max(N,Le(C.slug)),-1/0),Y=u.known?xs(u.label).title:u.label,M=k.validateSlug?O.find(N=>N.slug===k.validateSlug):void 0,F=M&&an(M.title)||Y;v.push({epicId:u.epicId,waveIndex:0,index:0,label:F,epicLabel:Y,validateSlug:k.validateSlug,width:z.reduce((N,C)=>Math.max(N,C.rows.length),0),status:Ks(O),prdCount:O.length,stageCount:J,doneCount:z.reduce((N,C)=>N+C.doneCount,0),runningCount:z.reduce((N,C)=>N+C.runningCount,0),heldCount:z.reduce((N,C)=>N+C.heldCount,0),blockedCount:z.reduce((N,C)=>N+C.blockedCount,0),etaMs:K/l,stages:z,_firstNum:X,_lastNum:se,_firstSlug:O[0].slug})}v.sort(Zs),v.forEach((k,S)=>{k.waveIndex=S+1});const y=v.filter(k=>k.validateSlug===null);y.forEach((k,S)=>{y.length>1&&(k.label=`${k.label} · plan ${S+1}/${y.length}`)});for(const k of v)p.push(k)}return p.sort((u,h)=>{if(u._lastNum!==h._lastNum)return u._lastNum>h._lastNum?-1:1;const g=(u.epicId??"").localeCompare(h.epicId??"");return g!==0?g:u.waveIndex-h.waveIndex}),p.map(({_firstNum:u,_lastNum:h,_firstSlug:g,...m},v)=>({...m,index:v+1}))}function rn(e,s=Date.now()){const n=Oe(e),a=new Map(n.map(g=>[g.slug,g])),d=new Date(s).toDateString();let l=0,i=0,r=0,o=0,c=0,p=0,u=0;for(const g of n)g.status==="pending"?(i++,(g.dependsOn??[]).every(v=>a.get(v)===void 0||a.get(v).status==="completed")&&l++):Se(g.status)?u++:g.status==="failed"?r++:g.status==="needs_review"?o++:g.status==="quarantined"?c++:g.status==="completed"&&g.finishedAt&&new Date(Date.parse(g.finishedAt)).toDateString()===d&&p++;let h=null;if(r+o+c>0){for(const g of lt(n,{sessions:{},now:s}))for(const m of g.stages)if(m.rows.some(v=>Wt(v.status))){(h===null||m.n<h)&&(h=m.n);break}}return{readyNow:l,totalQueued:i,heldByDeps:i-l,needsYou:r+o+c,needsYouStage:h,failedCount:r,needsReviewCount:o,doneToday:p,inFlight:u}}function ln(e){const s=new Map;for(const o of e.stages)for(const c of o.rows)s.set(c.slug,c);const n=o=>{var c;return((c=s.get(o))==null?void 0:c.cycle)===!0},a=new Map,d=new Set,l=(o,c)=>o.chain.length!==c.chain.length?o.chain.length>c.chain.length:o.est!==c.est?o.est>c.est:o.chain.join("\0")<c.chain.join("\0"),i=o=>{const c=a.get(o);if(c)return c;const p=s.get(o),u=p.estimateMinutes??0;if(d.has(o))return{chain:[o],est:u};d.add(o);let h=null;for(const m of p.deps){if(!s.has(m)||p.cycle&&n(m))continue;const v=i(m);(!h||l(v,h))&&(h=v)}d.delete(o);const g=h?{chain:[...h.chain,o],est:h.est+u}:{chain:[o],est:u};return a.set(o,g),g};let r=null;for(const o of s.keys()){const c=i(o);(!r||l(c,r))&&(r=c)}return r?r.chain:[]}const on=300*6e4,dn={five_hour:"5-hour",session:"5-hour",weekly_all:"weekly",weekly:"weekly"};function cn(e){return dn[e]??e.replace(/_/g," ")}function Qt({snap:e,now:s,avgDurationMs:n,runningJobs:a}){const{config:d,jobs:l,paused:i,nextReset:r,utilization:o,utilizationWindow:c,effectiveConcurrency:p}=e;let u=0,h=0;for(const S of l)S.status==="pending"?u++:S.status==="completed"&&h++;const g=a.length,m=u+g,v=(p==null?void 0:p.cap)??5;if(g>0){const S=a.reduce((D,O)=>(D.startedAt??"")<(O.startedAt??"")?D:O),T=S.startedAt?s-Date.parse(S.startedAt):0,x=h+g,R=h+m,P=g>1?` · ${g}/${v} parallel`:"";return{kind:"running",line1:`Running ${x}/${R}${P} · ${Ce(T)}`,line2:g===1?S.title:a.map(D=>D.title).join(", "),tooltip:a.map(D=>`${D.slug} (g${D.parallelGroup})`).join("; ")}}if(i){const S=i.resumeAt?Date.parse(i.resumeAt)-s:null;return{kind:"paused",line1:{rate_limit:"Paused — tokens exhausted",auth:"Paused — authentication failed",network:"Paused — network unreachable",reset_failure:"Paused — billing data unavailable",manual:"Paused — manual (you paused the queue)"}[i.reason]??`Paused — ${i.reason}`,line2:i.reason==="auth"?"Run `claude` in any terminal to refresh credentials, then Resume":S!==null&&S>0?`auto-resume ${ue(Date.parse(i.resumeAt))} (in ${te(S)})`:i.resumeAt?"resuming…":"no auto-resume scheduled",tooltip:i.resumeAt??"",action:{label:"Resume",onClick:()=>window.api.schedule.resume(),title:"Clear the pause and resume queue immediately"}}}if(m===0)return{kind:"idle",line1:"No work queued",line2:null};if((d.firePolicy??"when-available")==="manual")return{kind:"manual",line1:`Manual · ${u} pending`,line2:"click Fire next batch now to fire",action:{label:"Fire next batch now",onClick:()=>window.api.schedule.forceTick().then(H.fromOutcome).catch(()=>H.error("Failed to fire batch")),title:"Bypasses the billing-usage poll. Use when the meter is rate-limited or you want immediate progress."}};const k=d.utilizationThreshold??90;if(o==null)return{kind:"auto-soon",line1:`Auto · ${u} pending`,line2:"checking token availability…"};if(o>=k){const S=r?Date.parse(r)-s:null,T=c?cn(c):null,x=S===null||Number.isNaN(S)||S>on,R=S&&S>0?`resets ${ue(Date.parse(r))} (in ${te(S)})`:null;let P;return x?P=`${T??"binding"} window — long hold${R?`, ${R}`:", reset time unknown"}`:P=R?`${T?`${T} window `:""}next ${R}`:"will fire when usage drops",{kind:"auto-throttled",line1:`Auto · throttled (util ${o.toFixed(0)}% ≥ ${k}%)`,line2:P}}return{kind:"auto-soon",line1:`Auto · ${u} pending · util ${o.toFixed(0)}%`,line2:"fires within 2 min (poll cycle)"}}const un=15e3,pn=new Set(["failed","needs_review","quarantined"]);function St(){var n;const s=Array.from(document.querySelectorAll("[data-job-row]")).find(a=>pn.has(a.dataset.jobStatus??""));(n=s==null?void 0:s.scrollIntoView)==null||n.call(s,{block:"center",behavior:"smooth"})}function fn(e,s){var n;switch(e.kind){case"paused":return`paused: scheduler is paused (${e.reason??"manual"})`;case"launch-blocked":return`launch-blocked: ${e.agentType} jobs can't launch${(n=e.block)!=null&&n.kind?` (${e.block.kind})`:""}`;case"idle":return"idle: 0 pending";case"saturated":{const a=s!=null?`, oldest ${te(s)}`:"";return`saturated: ${e.totalSlots??"?"} slot(s) busy${a}`}case"blocked":{const a=e.blockedChains.length;return`blocked: ${e.pending} pending, ${e.dispatchable} dispatchable — ${a} chain${a===1?"":"s"} stuck behind a failed/skipped dependency`}case"stalled":return`stalled: no dispatch attempt in ${e.idleMs!=null?te(e.idleMs):"?"} with ${e.dispatchable} dispatchable`;case"running":default:return`running: ${e.runningCount} in flight, ${e.pending} pending`}}function hn(e){const[s,n]=f.useState(null),a=st(),d=ks(),l=a&&d;return f.useEffect(()=>{if(!l)return;let i=!0,r=!1,o=!1;const c=()=>{r||(r=!0,window.api.schedule.queueHealth(e).then(u=>{r=!1,o=!1,i&&n(u)},u=>{r=!1,!o&&(o=!0,H.error(`Queue health refresh failed: ${u instanceof Error?u.message:String(u)}`))}))};c();const p=setInterval(c,un);return()=>{i=!1,clearInterval(p)}},[e,l]),s}const gn={running:{dot:"bg-sage",text:"text-sage-dark"},paused:{dot:"bg-amber-500",text:"text-amber-600"},idle:{dot:"bg-fg-faint",text:"text-fg-faint"}};function xn(e,s,n){return e==="paused"||e==="launch-blocked"?"paused":e==="running"||e==="saturated"?"running":e?"idle":s?"paused":n>0?"running":"idle"}const ze="px-2.5 py-1.5 rounded border border-line text-[12.5px] font-medium text-fg-dim hover:text-fg hover:bg-bg-hi disabled:opacity-40 disabled:cursor-not-allowed whitespace-nowrap";function mn(e,s,n,a){var d;if(e==="agent"){const l=((d=a==null?void 0:a.cwd)==null?void 0:d.split("/").filter(Boolean).pop())||"another session",i=a!=null&&a.reason?` — "${a.reason}"`:"",r=s?new Date(s).getTime()-n:null,o=r==null?"":r>0?` — auto-resumes in ${te(r)}`:" — auto-resume pending";return`Paused by an agent in ${l}${i}${o}. Click Resume to restart now.`}if(e==="auth")return"Scheduler paused: Claude sign-in expired or invalid. Restart the app or re-run `claude login`, then Resume.";if(e==="rate_limit"){if(s){const l=new Date(s).getTime()-n;return l>0?`Paused for rate limit — resumes in ${te(l)}`:"Paused for rate limit — resume pending"}return"Paused for rate limit"}return e==="network"?"Paused: billing endpoint unreachable for 30+ min.":e==="manual"?"Scheduler paused manually — no new jobs start; running jobs continue. Click Resume to restart.":`Scheduler paused (${e})`}function bn({now:e}){const s=Fe(p=>p.snapshot);if(!s)return null;const n=s.paused,a=Object.entries(s.launchBlocks??{}),d=Object.entries(s.launchMitigations??{}),l=(n==null?void 0:n.reason)==="auth"||(n==null?void 0:n.reason)==="network",i="flex items-start gap-3 border-b px-0 py-1.5 text-[12.5px]",r="bg-red-950/10 border-red-700/30 text-red-800",o="bg-amber-400/10 border-amber-600/30 text-amber-700",c="shrink-0 px-2 py-0.5 rounded border border-current/40 hover:bg-white/20 text-[12px] font-medium";return t.jsxs(t.Fragment,{children:[n&&t.jsxs("div",{"data-testid":"pause-banner",className:`${i} ${l?r:o}`,children:[t.jsx("span",{className:"flex-1 leading-snug",children:mn(n.reason,n.resumeAt,e,n.by)}),t.jsx("button",{type:"button",onClick:()=>window.api.schedule.resume(),className:c,children:"Resume"})]}),a.map(([p,u])=>t.jsxs("div",{"data-testid":"launch-block-banner",className:`${i} ${r}`,children:[t.jsxs("div",{className:"flex-1 leading-snug min-w-0",children:[t.jsxs("div",{className:"font-medium",children:["Launches for ",t.jsx("span",{className:"font-mono",children:p})," jobs are failing before any work starts",u.httpStatus?` (HTTP ${u.httpStatus}, ${u.kind})`:` (${u.kind})`,u.exhausted?" — held until the Claude CLI version changes or you press Retry now.":u.until?` — next automatic probe ${new Date(u.until).getTime()>e?`in ${te(new Date(u.until).getTime()-e)}`:"on the next tick"}.`:"."]}),t.jsx("div",{className:"opacity-80",children:u.hint}),t.jsxs("div",{className:"font-mono text-[11.5px] opacity-70 truncate",title:u.message,children:[u.attempts," failed probe",u.attempts===1?"":"s",u.claudeVersion?` · CLI ${u.claudeVersion}`:"",u.lastSlug?` · last: ${u.lastSlug}`:""," · ",u.message]})]}),t.jsx("button",{type:"button",onClick:()=>window.api.schedule.resume(),className:c,children:"Retry now"})]},`launch-block-${p}`)),d.map(([p,u])=>t.jsx("div",{"data-testid":"launch-mitigation-banner",className:`${i} ${o}`,children:t.jsxs("div",{className:"flex-1 leading-snug min-w-0",children:[t.jsxs("div",{className:"font-medium",children:[t.jsx("span",{className:"font-mono",children:p})," jobs are running in degraded mode"," ","(",t.jsx("span",{className:"font-mono",children:Object.entries(u.env).map(([h,g])=>`${h}=${g}`).join(" ")}),")",u.claudeVersion?` since CLI ${u.claudeVersion}`:"","."]}),t.jsx("div",{className:"opacity-80",children:u.hint})]})},`launch-mitigation-${p}`))]})}function wn({scopeCwd:e,subView:s,onSubView:n,filterText:a,onFilterText:d,planMode:l,onPlanMode:i,planToolsRef:r}){const o=Fe($=>$.snapshot),c=pe($=>$.sessions),p=hn(e),u=Tt(),[h,g]=f.useState(()=>Date.now()),[m,v]=f.useState("—");f.useEffect(()=>{const $=setInterval(()=>g(Date.now()),3e4);return()=>clearInterval($)},[]),f.useEffect(()=>{let $=!0;return Bs(30).then(I=>{if(!$||!I.ok||!I.data)return;const L=new Date,_=He=>String(He).padStart(2,"0"),Z=`${L.getFullYear()}-${_(L.getMonth()+1)}-${_(L.getDate())}`;v(Hs(Gs(I.data,{day:Z})))}),()=>{$=!1}},[]);const y=f.useMemo(()=>((o==null?void 0:o.jobs)??[]).filter($=>!e||$.cwd===e),[o,e]),k=f.useMemo(()=>rn(y,h),[y,h]),S=f.useMemo(()=>{const $=lt(y,{sessions:c,now:h}),I=L=>$.filter(_=>_.status===L).length;return{active:I("active"),queued:I("queued"),draft:I("draft")}},[y,c,h]),T=f.useMemo(()=>{const $=new Date(h).toDateString(),I=[];for(const L of y)if(L.status==="completed"&&L.startedAt&&L.finishedAt&&new Date(Date.parse(L.finishedAt)).toDateString()===$){const _=Date.parse(L.finishedAt)-Date.parse(L.startedAt);_>0&&I.push(_)}return I.length?Math.round(I.reduce((L,_)=>L+_,0)/I.length/6e4):null},[y,h]);if(!o)return null;const x=p&&!p.unknown?p.verdict??null:null,R=p&&!p.unknown?p.slots??null:null,P=o.paused,D=xn((x==null?void 0:x.kind)??null,!!P,k.inFlight),O=gn[D],J=y.filter($=>$.status==="pending").length,W=y.filter($=>$.status==="running").length,z=Qt({snap:{...o,jobs:y},now:h,avgDurationMs:0,runningJobs:y.filter($=>$.status==="running")}),K=p!=null&&p.unknown?`Queue health: unknown — ${p.reason??"state unavailable"}`:x?fn(x,(p==null?void 0:p.oldestRunningAgeMs)??null):"queue health loading…",X=xe(o.lastRunAt?Date.parse(o.lastRunAt):null,h),se=p!=null&&p.lastDispatchAttemptAt?xe(Date.parse(p.lastDispatchAttemptAt),h):"never",Y=[K,z.line1,x?`dispatchable ${x.dispatchable} · needs_review ${x.needsReviewCount}`:null,(p==null?void 0:p.oldestRunningAgeMs)!=null?`oldest running ${te(p.oldestRunningAgeMs)} (any project)`:null,`last batch fired ${X} (lastRunAt — advances only when a job launches)`,`last dispatch attempt ${se} (advances on every driver evaluation)`].filter(Boolean).join(`
|
|
1
|
+
import{aP as Pe,aC as ie,ai as Te,aW as xs,an as Ce,ah as ue,al as te,a$ as H,bg as Fe,bf as pe,bj as Tt,aJ as f,af as xe,bp as ms,at as t,c as Ue,I as me,L as bt,p as bs,K as ge,u as ws,U as vs,e as js,W as ys,aV as Ns,bd as st,b6 as ks,ac as wt,aA as _t,bo as $e,N as qe,aH as _e,a as nt,aU as at,T as Ot,x as Lt,o as Ft,q as Ss,m as rt,z as it,O as Cs,g as re,h as B,aj as qt,bh as $s,aI as Ps,w as Ds,aL as Bt,bs as Ht,Y as As,aD as vt,b7 as jt,l as ke,y as yt,aQ as Nt,k as Rs,aZ as Ms,a3 as Is,v as Gt,b9 as Es,b3 as ye,Q as Ts,C as _s,au as Os,bb as Ls,V as Fs,bk as kt,aT as qs}from"./index-CuAfFXNd.js";import{f as Bs,a as Hs,s as Gs}from"./historyTotals-f-E0L9Xw.js";import"./monaco-editor-BsIlgG7c.js";function Vs(e){const s=new Map(e.map(i=>[i.slug,i])),n=new Map,a=new Set,d=[];function l(i){n.set(i,1),d.push(i);const r=s.get(i);for(const o of(r==null?void 0:r.dependsOn)??[]){if(!s.has(o))continue;const c=n.get(o);if(c===1){const p=d.indexOf(o);for(let u=p;u<d.length;u++)a.add(d[u])}else c===void 0&&l(o)}d.pop(),n.set(i,2)}for(const i of e)n.has(i.slug)||l(i.slug);return a}function Ws(e,s){return(e.dependsOn??[]).map(n=>{const a=s.get(n);return a?{slug:n,status:a.status,missing:!1,needsReview:a.status==="needs_review"}:{slug:n,status:null,missing:!0,needsReview:!1}})}function Us(e,s,n){const a=new Set(e.map(c=>c.slug)),d=new Set;for(const c of e)for(const p of c.dependsOn??[])a.has(p)&&d.add(p);const l=new Map,i=[];for(const c of e){const p=n.has(c.slug)?void 0:(c.dependsOn??[]).find(u=>a.has(u)&&!n.has(u));p?(l.has(p)||l.set(p,[]),l.get(p).push(c)):i.push(c)}const r=(c,p)=>c.slug.localeCompare(p.slug);i.sort(r);for(const c of l.values())c.sort(r);function o(c,p,u){const h=Ws(c,s),g=n.has(c.slug);u.add(c.slug);const m=g?[]:(l.get(c.slug)??[]).filter(v=>!u.has(v.slug)).map(v=>o(v,p+1,u));return u.delete(c.slug),{row:c,depth:p,children:m,blockers:h,blocked:h.some(v=>!v.missing&&v.status!=="completed"),hasNeedsReviewBlocker:h.some(v=>v.needsReview),hasMissingDep:h.some(v=>v.missing),cycle:g,parallelEligible:(c.dependsOn??[]).length===0&&!d.has(c.slug)}}return i.map(c=>o(c,0,new Set))}function Vt(e,s,n){const a=new Map((n??e).map(c=>[c.slug,c])),d=Vs(e),l=[],i=new Map,r=new Map;for(const c of e){const p=Pe(c,s),u=p.epicId??"__none__";i.has(u)||(l.push(u),i.set(u,[]),r.set(u,{epicId:p.epicId,label:p.known&&p.label?p.label:p.epicId?`Epic ${p.epicId.slice(0,12)}…`:"No Epic",known:p.known})),i.get(u).push(c)}const o=l.map(c=>{const p=r.get(c),u=i.get(c),h=Us(u,a,d),g={};for(const m of u){const v=m.status??"unknown";g[v]=(g[v]??0)+1}return{epicId:p.epicId,label:p.label,known:p.known,nodes:h,counts:g,total:u.length}});return o.sort((c,p)=>c.epicId===null?1:p.epicId===null?-1:c.known!==p.known?c.known?-1:1:c.label.localeCompare(p.label)),o}function Be(e){const s=[],n=a=>{s.push(a);for(const d of a.children)n(d)};for(const a of e)n(a);return s}function Ke(e){return String(e??"").replace(/^\d+-/,"")}function Oe(e){const s=new Set,n=new Map;for(const a of e){s.add(a.slug);const d=Ke(a.slug),l=n.get(d);l?l.push(a.slug):n.set(d,[a.slug])}return e.map(a=>{const d=a.dependsOn;if(!d||d.length===0)return a;let l=!1;const i=d.map(r=>{if(s.has(r))return r;const o=n.get(Ke(r));return o&&o.length===1?(l=!0,o[0]):r});return l?{...a,dependsOn:i}:a})}const zs=15e4,Xe=e=>e==="completed"||e==="skipped",Se=e=>e==="running"||e==="investigating",Wt=e=>e==="failed"||e==="needs_review"||e==="quarantined",Qs=e=>e==="failed"||e==="needs_review"||e==="quarantined";function Ut(e){if(e<=5e3)return"~now";if(e<6e4)return`~${Math.round(e/1e3)}s`;const s=Math.round(e/6e4);return s<60?`~${s}m`:`~${Math.floor(s/60)}h${String(s%60).padStart(2,"0")}m`}function zt(e,s){const n=e.estimateMinutes?e.estimateMinutes*6e4:null;return n?`${Math.min(99,Math.floor(s/n*100))}%`:Te(s)}function Ys(e){let s=0,n=0;for(const a of e)if(a.status==="completed"&&a.startedAt&&a.finishedAt){const d=Date.parse(a.finishedAt)-Date.parse(a.startedAt);d>0&&(s+=d,n++)}return n===0?zs:s/n}function Le(e){const s=ie(e);return s===null?1/0:Number(s)}function Ze(e,s){const n=Le(e.slug)-Le(s.slug);return n!==0&&!Number.isNaN(n)?n:e.slug.localeCompare(s.slug)}function Js(e){let s=0;for(const n of e.statusHistory??[])n.to==="pending"&&n.from!==null&&s++;return s}function Ks(e){return e.some(n=>Se(n.status))?"active":e.every(n=>Xe(n.status))?"done":e.filter(n=>n.status!=="quarantined").length===0?"draft":"queued"}function Xs(e,s,n,a){switch(e){case"done":return`${s.doneCount}/${s.rows.length} done`;case"running":return`${s.runningCount} running · ${n}`;case"held":return`${s.heldCount} held`;case"blocked":return`${s.blockedCount+a} blocked`;default:return`${n} ready`}}function Zs(e,s){return e._firstNum!==s._firstNum?e._firstNum<s._firstNum?-1:1:e._firstSlug.localeCompare(s._firstSlug)}function en(e,s){const n=new Map(e.map(l=>[l.row.slug,l.row.slug])),a=l=>{for(;n.get(l)!==l;)n.set(l,n.get(n.get(l))),l=n.get(l);return l};for(const l of e)for(const i of l.row.dependsOn??[])s.has(i)&&n.set(a(l.row.slug),a(i));const d=new Map;for(const l of e){const i=a(l.row.slug),r=d.get(i);r?r.push(l):d.set(i,[l])}return[...d.values()]}function tn(e,s){if(e.length>0&&e.every(n=>!!n.row.planId)){const n=new Map;for(const a of e){const d=n.get(a.row.planId);d?d.push(a):n.set(a.row.planId,[a])}return[...n.values()]}return en(e,s)}function sn(e,s,n,a){const d=[],l=[e];for(a.add(e.row.slug);l.length>0;){const i=l.pop();d.push(i);for(const r of i.row.dependsOn??[])if(n.has(r)&&!a.has(r)){a.add(r);const o=s.get(r);o&&l.push(o)}}return d}function nn(e,s){const n=new Map(e.map(r=>[r.row.slug,r])),a=new Set,d=[],l=e.filter(r=>Ke(r.row.slug).startsWith("validate-")).sort((r,o)=>Ze({slug:r.row.slug},{slug:o.row.slug}));for(const r of l)a.has(r.row.slug)||d.push({nodes:sn(r,n,s,a),validateSlug:r.row.slug});const i=e.filter(r=>!a.has(r.row.slug));if(i.length>0){const r=new Set(i.map(o=>o.row.slug));for(const o of tn(i,r))d.push({nodes:o,validateSlug:null})}return d}function an(e){return e.replace(/^validate[\s:-]*/i,"").trim()}function lt(e,s){if(e.length===0)return[];const n=Oe(e),a=s.now??Date.now(),d=s.avgDurationMs??Ys(n),l=Math.max(1,s.concurrency??1),i=new Map(n.map(u=>[u.slug,u])),r=u=>u.status==="pending"&&(u.dependsOn??[]).every(h=>i.get(h)===void 0||i.get(h).status==="completed"),o=new Map;n.filter(r).sort(Ze).forEach((u,h)=>o.set(u.slug,h));const c=Vt(n,s.sessions,n),p=[];for(const u of c){const h=Be(u.nodes),g=new Set(h.map(k=>k.row.slug)),m=new Map(h.map(k=>[k.row.slug,k])),v=[];for(const k of nn(h,g)){const S=k.nodes,T=new Set(S.map(N=>N.row.slug)),x=new Map,R=new Set,P=N=>{const C=m.get(N);return(C.row.dependsOn??[]).filter(q=>T.has(q)&&!(C.cycle&&m.get(q).cycle))},D=N=>{const C=x.get(N);if(C!==void 0)return C;if(R.has(N))return 0;R.add(N);let q=0;for(const V of P(N))q=Math.max(q,D(V));return R.delete(N),x.set(N,q+1),q+1};for(const N of S)D(N.row.slug);const O=S.map(N=>{const C=N.row,q=(C.dependsOn??[]).filter(V=>g.has(V));return{slug:C.slug,title:C.title,status:C.status,stage:x.get(C.slug),prdNumber:ie(C.slug),rowKind:"dep",rowTrailing:"",cycle:N.cycle,estimateMinutes:C.estimateMinutes??null,deps:q,crossEpicDeps:(C.dependsOn??[]).filter(V=>!g.has(V)),blockers:N.blockers,job:C}});O.sort(Ze);const J=O.reduce((N,C)=>Math.max(N,C.stage),0),W=new Map;for(const N of O){const C=N.job,q=m.get(N.slug),V=C.status;let U;if(Xe(V)){const b=C.startedAt&&C.finishedAt?Date.parse(C.finishedAt)-Date.parse(C.startedAt):NaN;U={kind:"done",trailing:b>0?Te(b):"",held:!1,blocked:!1}}else if(Se(V)){const b=C.startedAt?Math.max(0,a-Date.parse(C.startedAt)):null;U={kind:"running",trailing:b===null?"":zt(C,b),held:!1,blocked:!1}}else if(V==="failed")U={kind:"failed",trailing:"failed",held:!1,blocked:!1};else if(V==="needs_review")U={kind:"review",trailing:"review",held:!1,blocked:!1};else if(V==="quarantined")U={kind:"quarantined",trailing:"quarantined",held:!1,blocked:!1};else{const b=q.blockers.filter(j=>!j.missing&&j.status!=="completed");if(b.length>0){const j=b.some($=>Qs($.status)),A=b[0].slug;U={kind:"dep",trailing:`←${ie(A)??A}`,held:!j,blocked:j}}else if(C.heldReason)U={kind:"gate",trailing:"gate",held:!0,blocked:!1};else{const j=Js(C),A=o.get(C.slug)??0;U=j>0?{kind:"retry",trailing:`${j} ${j===1?"retry":"retries"}`,held:!1,blocked:!1}:{kind:"eta",trailing:Ut(A*d/l),held:!1,blocked:!1}}}W.set(N.slug,U)}const z=[];for(let N=1;N<=J;N++){const C=O.filter(_=>_.stage===N),q=C.find(_=>{const Z=W.get(_.slug).kind;return _.status==="pending"&&(Z==="eta"||Z==="retry")});if(q){const _=W.get(q.slug);_.kind="next",_.trailing="next"}let V=0,U=0,b=0,j=0,A=0,$=0;for(const _ of C){const Z=W.get(_.slug);_.rowKind=Z.kind,_.rowTrailing=Z.trailing,Xe(_.status)?V++:Se(_.status)?U++:_.status==="pending"?(A++,Z.held&&b++,Z.blocked&&j++):Wt(_.status)&&$++}const I=V===C.length?"done":U>0?"running":j+$>0?"blocked":b>0?"held":"pending",L={n:N,rows:C,doneCount:V,runningCount:U,heldCount:b,blockedCount:j};z.push({...L,state:I,summary:Xs(I,L,A,$)})}let K=0;for(const N of O){const C=N.estimateMinutes?N.estimateMinutes*6e4:d;if(N.status==="pending")K+=C;else if(Se(N.status)){const q=N.job.startedAt?Math.max(0,a-Date.parse(N.job.startedAt)):0;K+=Math.max(0,C-q)}}const X=O.reduce((N,C)=>Math.min(N,Le(C.slug)),1/0),se=O.reduce((N,C)=>Math.max(N,Le(C.slug)),-1/0),Y=u.known?xs(u.label).title:u.label,M=k.validateSlug?O.find(N=>N.slug===k.validateSlug):void 0,F=M&&an(M.title)||Y;v.push({epicId:u.epicId,waveIndex:0,index:0,label:F,epicLabel:Y,validateSlug:k.validateSlug,width:z.reduce((N,C)=>Math.max(N,C.rows.length),0),status:Ks(O),prdCount:O.length,stageCount:J,doneCount:z.reduce((N,C)=>N+C.doneCount,0),runningCount:z.reduce((N,C)=>N+C.runningCount,0),heldCount:z.reduce((N,C)=>N+C.heldCount,0),blockedCount:z.reduce((N,C)=>N+C.blockedCount,0),etaMs:K/l,stages:z,_firstNum:X,_lastNum:se,_firstSlug:O[0].slug})}v.sort(Zs),v.forEach((k,S)=>{k.waveIndex=S+1});const y=v.filter(k=>k.validateSlug===null);y.forEach((k,S)=>{y.length>1&&(k.label=`${k.label} · plan ${S+1}/${y.length}`)});for(const k of v)p.push(k)}return p.sort((u,h)=>{if(u._lastNum!==h._lastNum)return u._lastNum>h._lastNum?-1:1;const g=(u.epicId??"").localeCompare(h.epicId??"");return g!==0?g:u.waveIndex-h.waveIndex}),p.map(({_firstNum:u,_lastNum:h,_firstSlug:g,...m},v)=>({...m,index:v+1}))}function rn(e,s=Date.now()){const n=Oe(e),a=new Map(n.map(g=>[g.slug,g])),d=new Date(s).toDateString();let l=0,i=0,r=0,o=0,c=0,p=0,u=0;for(const g of n)g.status==="pending"?(i++,(g.dependsOn??[]).every(v=>a.get(v)===void 0||a.get(v).status==="completed")&&l++):Se(g.status)?u++:g.status==="failed"?r++:g.status==="needs_review"?o++:g.status==="quarantined"?c++:g.status==="completed"&&g.finishedAt&&new Date(Date.parse(g.finishedAt)).toDateString()===d&&p++;let h=null;if(r+o+c>0){for(const g of lt(n,{sessions:{},now:s}))for(const m of g.stages)if(m.rows.some(v=>Wt(v.status))){(h===null||m.n<h)&&(h=m.n);break}}return{readyNow:l,totalQueued:i,heldByDeps:i-l,needsYou:r+o+c,needsYouStage:h,failedCount:r,needsReviewCount:o,doneToday:p,inFlight:u}}function ln(e){const s=new Map;for(const o of e.stages)for(const c of o.rows)s.set(c.slug,c);const n=o=>{var c;return((c=s.get(o))==null?void 0:c.cycle)===!0},a=new Map,d=new Set,l=(o,c)=>o.chain.length!==c.chain.length?o.chain.length>c.chain.length:o.est!==c.est?o.est>c.est:o.chain.join("\0")<c.chain.join("\0"),i=o=>{const c=a.get(o);if(c)return c;const p=s.get(o),u=p.estimateMinutes??0;if(d.has(o))return{chain:[o],est:u};d.add(o);let h=null;for(const m of p.deps){if(!s.has(m)||p.cycle&&n(m))continue;const v=i(m);(!h||l(v,h))&&(h=v)}d.delete(o);const g=h?{chain:[...h.chain,o],est:h.est+u}:{chain:[o],est:u};return a.set(o,g),g};let r=null;for(const o of s.keys()){const c=i(o);(!r||l(c,r))&&(r=c)}return r?r.chain:[]}const on=300*6e4,dn={five_hour:"5-hour",session:"5-hour",weekly_all:"weekly",weekly:"weekly"};function cn(e){return dn[e]??e.replace(/_/g," ")}function Qt({snap:e,now:s,avgDurationMs:n,runningJobs:a}){const{config:d,jobs:l,paused:i,nextReset:r,utilization:o,utilizationWindow:c,effectiveConcurrency:p}=e;let u=0,h=0;for(const S of l)S.status==="pending"?u++:S.status==="completed"&&h++;const g=a.length,m=u+g,v=(p==null?void 0:p.cap)??5;if(g>0){const S=a.reduce((D,O)=>(D.startedAt??"")<(O.startedAt??"")?D:O),T=S.startedAt?s-Date.parse(S.startedAt):0,x=h+g,R=h+m,P=g>1?` · ${g}/${v} parallel`:"";return{kind:"running",line1:`Running ${x}/${R}${P} · ${Ce(T)}`,line2:g===1?S.title:a.map(D=>D.title).join(", "),tooltip:a.map(D=>`${D.slug} (g${D.parallelGroup})`).join("; ")}}if(i){const S=i.resumeAt?Date.parse(i.resumeAt)-s:null;return{kind:"paused",line1:{rate_limit:"Paused — tokens exhausted",auth:"Paused — authentication failed",network:"Paused — network unreachable",reset_failure:"Paused — billing data unavailable",manual:"Paused — manual (you paused the queue)"}[i.reason]??`Paused — ${i.reason}`,line2:i.reason==="auth"?"Run `claude` in any terminal to refresh credentials, then Resume":S!==null&&S>0?`auto-resume ${ue(Date.parse(i.resumeAt))} (in ${te(S)})`:i.resumeAt?"resuming…":"no auto-resume scheduled",tooltip:i.resumeAt??"",action:{label:"Resume",onClick:()=>window.api.schedule.resume(),title:"Clear the pause and resume queue immediately"}}}if(m===0)return{kind:"idle",line1:"No work queued",line2:null};if((d.firePolicy??"when-available")==="manual")return{kind:"manual",line1:`Manual · ${u} pending`,line2:"click Fire next batch now to fire",action:{label:"Fire next batch now",onClick:()=>window.api.schedule.forceTick().then(H.fromOutcome).catch(()=>H.error("Failed to fire batch")),title:"Bypasses the billing-usage poll. Use when the meter is rate-limited or you want immediate progress."}};const k=d.utilizationThreshold??90;if(o==null)return{kind:"auto-soon",line1:`Auto · ${u} pending`,line2:"checking token availability…"};if(o>=k){const S=r?Date.parse(r)-s:null,T=c?cn(c):null,x=S===null||Number.isNaN(S)||S>on,R=S&&S>0?`resets ${ue(Date.parse(r))} (in ${te(S)})`:null;let P;return x?P=`${T??"binding"} window — long hold${R?`, ${R}`:", reset time unknown"}`:P=R?`${T?`${T} window `:""}next ${R}`:"will fire when usage drops",{kind:"auto-throttled",line1:`Auto · throttled (util ${o.toFixed(0)}% ≥ ${k}%)`,line2:P}}return{kind:"auto-soon",line1:`Auto · ${u} pending · util ${o.toFixed(0)}%`,line2:"fires within 2 min (poll cycle)"}}const un=15e3,pn=new Set(["failed","needs_review","quarantined"]);function St(){var n;const s=Array.from(document.querySelectorAll("[data-job-row]")).find(a=>pn.has(a.dataset.jobStatus??""));(n=s==null?void 0:s.scrollIntoView)==null||n.call(s,{block:"center",behavior:"smooth"})}function fn(e,s){var n;switch(e.kind){case"paused":return`paused: scheduler is paused (${e.reason??"manual"})`;case"launch-blocked":return`launch-blocked: ${e.agentType} jobs can't launch${(n=e.block)!=null&&n.kind?` (${e.block.kind})`:""}`;case"idle":return"idle: 0 pending";case"saturated":{const a=s!=null?`, oldest ${te(s)}`:"";return`saturated: ${e.totalSlots??"?"} slot(s) busy${a}`}case"blocked":{const a=e.blockedChains.length;return`blocked: ${e.pending} pending, ${e.dispatchable} dispatchable — ${a} chain${a===1?"":"s"} stuck behind a failed/skipped dependency`}case"stalled":return`stalled: no dispatch attempt in ${e.idleMs!=null?te(e.idleMs):"?"} with ${e.dispatchable} dispatchable`;case"running":default:return`running: ${e.runningCount} in flight, ${e.pending} pending`}}function hn(e){const[s,n]=f.useState(null),a=st(),d=ks(),l=a&&d;return f.useEffect(()=>{if(!l)return;let i=!0,r=!1,o=!1;const c=()=>{r||(r=!0,window.api.schedule.queueHealth(e).then(u=>{r=!1,o=!1,i&&n(u)},u=>{r=!1,!o&&(o=!0,H.error(`Queue health refresh failed: ${u instanceof Error?u.message:String(u)}`))}))};c();const p=setInterval(c,un);return()=>{i=!1,clearInterval(p)}},[e,l]),s}const gn={running:{dot:"bg-sage",text:"text-sage-dark"},paused:{dot:"bg-amber-500",text:"text-amber-600"},idle:{dot:"bg-fg-faint",text:"text-fg-faint"}};function xn(e,s,n){return e==="paused"||e==="launch-blocked"?"paused":e==="running"||e==="saturated"?"running":e?"idle":s?"paused":n>0?"running":"idle"}const ze="px-2.5 py-1.5 rounded border border-line text-[12.5px] font-medium text-fg-dim hover:text-fg hover:bg-bg-hi disabled:opacity-40 disabled:cursor-not-allowed whitespace-nowrap";function mn(e,s,n,a){var d;if(e==="agent"){const l=((d=a==null?void 0:a.cwd)==null?void 0:d.split("/").filter(Boolean).pop())||"another session",i=a!=null&&a.reason?` — "${a.reason}"`:"",r=s?new Date(s).getTime()-n:null,o=r==null?"":r>0?` — auto-resumes in ${te(r)}`:" — auto-resume pending";return`Paused by an agent in ${l}${i}${o}. Click Resume to restart now.`}if(e==="auth")return"Scheduler paused: Claude sign-in expired or invalid. Restart the app or re-run `claude login`, then Resume.";if(e==="rate_limit"){if(s){const l=new Date(s).getTime()-n;return l>0?`Paused for rate limit — resumes in ${te(l)}`:"Paused for rate limit — resume pending"}return"Paused for rate limit"}return e==="network"?"Paused: billing endpoint unreachable for 30+ min.":e==="manual"?"Scheduler paused manually — no new jobs start; running jobs continue. Click Resume to restart.":`Scheduler paused (${e})`}function bn({now:e}){const s=Fe(p=>p.snapshot);if(!s)return null;const n=s.paused,a=Object.entries(s.launchBlocks??{}),d=Object.entries(s.launchMitigations??{}),l=(n==null?void 0:n.reason)==="auth"||(n==null?void 0:n.reason)==="network",i="flex items-start gap-3 border-b px-0 py-1.5 text-[12.5px]",r="bg-red-950/10 border-red-700/30 text-red-800",o="bg-amber-400/10 border-amber-600/30 text-amber-700",c="shrink-0 px-2 py-0.5 rounded border border-current/40 hover:bg-white/20 text-[12px] font-medium";return t.jsxs(t.Fragment,{children:[n&&t.jsxs("div",{"data-testid":"pause-banner",className:`${i} ${l?r:o}`,children:[t.jsx("span",{className:"flex-1 leading-snug",children:mn(n.reason,n.resumeAt,e,n.by)}),t.jsx("button",{type:"button",onClick:()=>window.api.schedule.resume(),className:c,children:"Resume"})]}),a.map(([p,u])=>t.jsxs("div",{"data-testid":"launch-block-banner",className:`${i} ${r}`,children:[t.jsxs("div",{className:"flex-1 leading-snug min-w-0",children:[t.jsxs("div",{className:"font-medium",children:["Launches for ",t.jsx("span",{className:"font-mono",children:p})," jobs are failing before any work starts",u.httpStatus?` (HTTP ${u.httpStatus}, ${u.kind})`:` (${u.kind})`,u.exhausted?" — held until the Claude CLI version changes or you press Retry now.":u.until?` — next automatic probe ${new Date(u.until).getTime()>e?`in ${te(new Date(u.until).getTime()-e)}`:"on the next tick"}.`:"."]}),t.jsx("div",{className:"opacity-80",children:u.hint}),t.jsxs("div",{className:"font-mono text-[11.5px] opacity-70 truncate",title:u.message,children:[u.attempts," failed probe",u.attempts===1?"":"s",u.claudeVersion?` · CLI ${u.claudeVersion}`:"",u.lastSlug?` · last: ${u.lastSlug}`:""," · ",u.message]})]}),t.jsx("button",{type:"button",onClick:()=>window.api.schedule.resume(),className:c,children:"Retry now"})]},`launch-block-${p}`)),d.map(([p,u])=>t.jsx("div",{"data-testid":"launch-mitigation-banner",className:`${i} ${o}`,children:t.jsxs("div",{className:"flex-1 leading-snug min-w-0",children:[t.jsxs("div",{className:"font-medium",children:[t.jsx("span",{className:"font-mono",children:p})," jobs are running in degraded mode"," ","(",t.jsx("span",{className:"font-mono",children:Object.entries(u.env).map(([h,g])=>`${h}=${g}`).join(" ")}),")",u.claudeVersion?` since CLI ${u.claudeVersion}`:"","."]}),t.jsx("div",{className:"opacity-80",children:u.hint})]})},`launch-mitigation-${p}`))]})}function wn({scopeCwd:e,subView:s,onSubView:n,filterText:a,onFilterText:d,planMode:l,onPlanMode:i,planToolsRef:r}){const o=Fe($=>$.snapshot),c=pe($=>$.sessions),p=hn(e),u=Tt(),[h,g]=f.useState(()=>Date.now()),[m,v]=f.useState("—");f.useEffect(()=>{const $=setInterval(()=>g(Date.now()),3e4);return()=>clearInterval($)},[]),f.useEffect(()=>{let $=!0;return Bs(30).then(I=>{if(!$||!I.ok||!I.data)return;const L=new Date,_=He=>String(He).padStart(2,"0"),Z=`${L.getFullYear()}-${_(L.getMonth()+1)}-${_(L.getDate())}`;v(Hs(Gs(I.data,{day:Z})))}),()=>{$=!1}},[]);const y=f.useMemo(()=>((o==null?void 0:o.jobs)??[]).filter($=>!e||$.cwd===e),[o,e]),k=f.useMemo(()=>rn(y,h),[y,h]),S=f.useMemo(()=>{const $=lt(y,{sessions:c,now:h}),I=L=>$.filter(_=>_.status===L).length;return{active:I("active"),queued:I("queued"),draft:I("draft")}},[y,c,h]),T=f.useMemo(()=>{const $=new Date(h).toDateString(),I=[];for(const L of y)if(L.status==="completed"&&L.startedAt&&L.finishedAt&&new Date(Date.parse(L.finishedAt)).toDateString()===$){const _=Date.parse(L.finishedAt)-Date.parse(L.startedAt);_>0&&I.push(_)}return I.length?Math.round(I.reduce((L,_)=>L+_,0)/I.length/6e4):null},[y,h]);if(!o)return null;const x=p&&!p.unknown?p.verdict??null:null,R=p&&!p.unknown?p.slots??null:null,P=o.paused,D=xn((x==null?void 0:x.kind)??null,!!P,k.inFlight),O=gn[D],J=y.filter($=>$.status==="pending").length,W=y.filter($=>$.status==="running").length,z=Qt({snap:{...o,jobs:y},now:h,avgDurationMs:0,runningJobs:y.filter($=>$.status==="running")}),K=p!=null&&p.unknown?`Queue health: unknown — ${p.reason??"state unavailable"}`:x?fn(x,(p==null?void 0:p.oldestRunningAgeMs)??null):"queue health loading…",X=xe(o.lastRunAt?Date.parse(o.lastRunAt):null,h),se=p!=null&&p.lastDispatchAttemptAt?xe(Date.parse(p.lastDispatchAttemptAt),h):"never",Y=[K,z.line1,x?`dispatchable ${x.dispatchable} · needs_review ${x.needsReviewCount}`:null,(p==null?void 0:p.oldestRunningAgeMs)!=null?`oldest running ${te(p.oldestRunningAgeMs)} (any project)`:null,`last batch fired ${X} (lastRunAt — advances only when a job launches)`,`last dispatch attempt ${se} (advances on every driver evaluation)`].filter(Boolean).join(`
|
|
2
2
|
`),M=o.utilization,F=o.pollHealth,N=F!=null&&!F.lastPollOk,C=ms(o.utilizationWindow),q=o.nextReset?Date.parse(o.nextReset):null,V=q?q>h?te(q-h):"soon":"—",U=(u==null?void 0:u.total)??5,b=(u==null?void 0:u.envOverride)===!0,j=o.config.firePolicy??"when-available",A=J===0&&W===0;return t.jsxs("div",{"data-testid":"scheduler-top-bands",className:"shrink-0 px-[18px]",children:[t.jsxs(Ue,{height:40,testId:"queue-health-header",className:"gap-3",children:[t.jsx("h1",{className:"m-0 font-serif text-[21px] font-semibold leading-none tracking-tight text-fg",children:"Scheduler"}),t.jsx("span",{className:"w-px h-[20px] bg-rule-structural","aria-hidden":"true"}),t.jsxs("span",{className:`inline-flex items-center gap-1.5 text-[12.5px] font-medium ${O.text}`,"data-testid":"scheduler-state-word","data-state":D,children:[t.jsx("span",{className:`w-2 h-2 rounded-full ${O.dot}`,"aria-hidden":"true"}),D]}),t.jsxs("span",{className:"font-mono text-[12px] text-fg-faint whitespace-nowrap","data-testid":"scheduler-meta",children:[k.inFlight," in flight · ",k.heldByDeps," held · last batch ",X]}),t.jsxs(me,{title:Y,testId:"scheduler-verdict-info",popoverTestId:"scheduler-info-popover",children:[t.jsx("pre",{className:"m-0 mb-2 whitespace-pre-wrap font-mono text-[11.5px] text-fg-dim",children:Y}),bt.scheduler&&t.jsx(bs,{content:bt.scheduler})]}),t.jsxs("span",{className:"ml-auto flex items-center gap-2",children:[t.jsx("button",{type:"button",onClick:()=>window.api.schedule.rescan().then(H.fromOutcome).catch(()=>H.error("Failed to rescan")),title:"Re-scan the prds/ folder. Use when you've added or edited PRDs on disk and want the queue to reflect them immediately.",className:ze,children:"Refresh"}),P?t.jsx("button",{type:"button",onClick:()=>window.api.schedule.resume(),title:"Clear the pause and resume queue immediately",className:ze,children:"Resume"}):t.jsx("button",{type:"button",onClick:()=>window.api.schedule.pause(),title:"Stop NEW dispatch. Running jobs are not killed.",className:ze,children:"Pause"}),t.jsx("button",{type:"button",onClick:()=>window.api.schedule.forceTick().then(H.fromOutcome).catch(()=>H.error("Failed to fire batch")),disabled:A,title:"Bypasses the billing-usage poll. Use when the meter is rate-limited or you want immediate progress.",className:"px-3 py-1.5 rounded bg-accent text-white text-[12.5px] font-semibold whitespace-nowrap disabled:opacity-40 disabled:cursor-not-allowed hover:opacity-90",children:"Fire next batch"})]})]}),t.jsx(bn,{now:h}),t.jsxs(Ue,{height:70,testId:"scheduler-kpi-band",children:[t.jsx(ge,{testId:"kpi-window",label:C?`${C} used`:"Window used",info:N?`Billing poll failing — this reading may be outdated (last good reading ${xe(F.lastPollAt,h)}). Machine-wide ${C??"binding"} window.`:`Share of the machine-wide ${C??"binding"} billing window consumed — the window closest to its limit.`,value:M==null?"—":`${Math.round(M)}%`,sub:`resets in ${V}`,third:t.jsx(ws,{pct:M??0,tone:N?"bg-amber-500":"bg-accent"})}),t.jsx(ge,{testId:"kpi-slots",label:"Slots",info:`Machine-wide session pool (${(R==null?void 0:R.source)==="env"?"SM_SESSION_SLOTS override":"Home tab cap"}), not scoped to this project`,value:R?`${R.inUse}/${R.total}`:"—",sub:"in use",third:R?t.jsx(vs,{filled:R.inUse,total:R.total}):null}),t.jsx(ge,{testId:"kpi-ready",label:"Ready now",info:"Pending rows whose dependsOn chain is fully satisfied right now",value:k.readyNow,sub:`of ${k.totalQueued} queued`,third:`${k.heldByDeps} held by deps`}),k.needsYou>0?t.jsx(ge,{testId:"kpi-needs-you",label:"Needs you",value:t.jsx("button",{type:"button","data-testid":"kpi-needs-you-jump",onClick:St,className:"font-semibold text-accent hover:underline",title:"Scroll to the first failed / needs-review / quarantined row",children:k.needsYou}),sub:t.jsx("button",{type:"button",onClick:St,className:"hover:underline",children:k.needsYouStage!=null?`blocking stage ${k.needsYouStage}`:"need attention"}),third:[k.failedCount>0&&`${k.failedCount} failed`,k.needsReviewCount>0&&`${k.needsReviewCount} needs review`,k.needsYou-k.failedCount-k.needsReviewCount>0&&`${k.needsYou-k.failedCount-k.needsReviewCount} quarantined`].filter(Boolean).join(" · ")}):t.jsx(ge,{testId:"kpi-needs-you",label:"Needs you",value:t.jsxs("span",{className:"inline-flex items-center gap-1.5 text-[15px]",children:[t.jsx("span",{className:"w-2.5 h-2.5 rounded-full bg-sage","aria-hidden":"true"}),"all clear"]}),third:"0 failed · 0 needs review"}),t.jsx(ge,{testId:"kpi-done",label:"Done today",value:k.doneToday,sub:T!=null?`avg ${T}m`:"avg —",third:t.jsx("span",{"data-testid":"kpi-done-spend",children:m})}),t.jsx(ge,{testId:"kpi-concurrency",label:"Concurrency",info:"Start-jobs policy, concurrency cap and utilization threshold",infoTestId:"kpi-concurrency-info",infoAlignRight:!0,infoContent:t.jsxs("label",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-fg",children:"Start jobs"}),t.jsxs("select",{"data-testid":"kpi-fire-policy",value:j,onChange:$=>window.api.schedule.setConfig({firePolicy:$.target.value}),className:"border border-line bg-bg-hi rounded px-1 py-0.5 text-[12px] text-fg-dim",title:"when-available: poll usage and fire when tokens are below threshold. manual: only on Run now.","aria-label":"Start jobs policy",children:[t.jsx("option",{value:"when-available",children:"when available"}),t.jsx("option",{value:"manual",children:"manually"})]})]}),value:t.jsxs("span",{className:"inline-flex items-center gap-1",children:[t.jsx(ys,{value:U,min:0,max:(u==null?void 0:u.max)??10,disabled:b,onChange:$=>{Ns($).catch(I=>{H.error(`Could not set session slots: ${I instanceof Error?I.message:String(I)}`)})},title:b?"pinned by SM_SESSION_SLOTS — unset the env var to edit":"Machine-wide claude -p session slots, shared with chat runs"}),b&&t.jsx("span",{className:"text-[10px] font-semibold uppercase tracking-wide text-amber-600 bg-amber-400/10 border border-amber-400/30 rounded px-1 py-0",title:"Pinned by SM_SESSION_SLOTS — unset the env var to edit",children:"env"})]}),sub:"at once",third:j==="when-available"?t.jsxs("span",{children:["pause above"," ",t.jsx(js,{value:o.config.utilizationThreshold??90,min:0,max:100,testId:"kpi-threshold",title:"Holds new dispatches when the highest of the 5-hour and weekly usage windows is at/above this percent (when-available policy only). Not the executor rate-limit pause — click to edit",onCommit:$=>window.api.schedule.setConfig({utilizationThreshold:$})})]}):null})]}),t.jsxs(Ue,{height:30,testId:"scheduler-plans-toolbar",className:"gap-3",children:[t.jsx("span",{className:"text-[10.5px] font-semibold uppercase tracking-wide text-fg-faint",children:"Plans"}),t.jsxs("span",{className:"font-mono text-[12px] text-fg-faint whitespace-nowrap","data-testid":"scheduler-plans-meta",children:[S.active," active · ",S.queued," queued · ",S.draft," draft · ",y.length," PRDs"]}),t.jsxs("span",{className:"ml-auto flex items-center gap-3",children:[t.jsx("span",{ref:r,className:"contents","data-testid":"scheduler-plan-tools"}),t.jsx("input",{type:"text",value:a,onChange:$=>d($.target.value),placeholder:"filter PRDs…","aria-label":"Filter PRDs by title, slug, or project","data-testid":"scheduler-filter-input",className:"w-[180px] bg-bg-hi border border-line rounded px-2 py-0.5 text-[12px] text-fg placeholder:text-fg-faint focus:outline-none focus:border-fg-faint"}),t.jsx("span",{className:"inline-flex border border-line rounded overflow-hidden",role:"group","aria-label":"Plan view mode",children:[["graph","Graph"],["list","List"],["critical","Critical path"]].map(([$,I])=>t.jsx("button",{type:"button","data-testid":`plan-mode-${$}`,"aria-pressed":l===$&&s==="queue",onClick:()=>{i($),n("queue")},className:`px-2 py-0.5 text-[12px] ${l===$&&s==="queue"?"bg-bg-elev font-semibold text-fg":"text-fg-dim hover:text-fg"}`,children:I},$))}),t.jsx("span",{className:"w-px h-[16px] bg-rule-structural","aria-hidden":"true"}),[["prds","PRDs","Authored PRD source files on disk — edit, lint, archive, or queue them."],["history","History","The last 50 completed and failed jobs."],["machine","Machine","Machine-wide config that applies to every project — not this project’s live queue."]].map(([$,I,L])=>t.jsx("button",{type:"button",onClick:()=>n($),"aria-pressed":s===$,title:L,className:`text-[12.5px] ${s===$?"font-semibold text-fg":"text-fg-faint hover:text-fg-dim"}`,children:I},$))]})]})]})}function Yt({options:e,value:s,onChange:n,pillPadding:a="px-3 py-1.5"}){return t.jsx("div",{className:"flex gap-1.5 flex-wrap",children:e.map(d=>{const l=d.value===s;return t.jsxs("button",{type:"button",onClick:()=>n(d.value),className:`rounded-full ${a} text-[12.5px] border transition-colors ${l?"bg-accent text-white border-accent font-semibold":"bg-bg-hi text-fg-dim border-line hover:border-fg-faint font-medium"}`,children:[d.label,d.count!==void 0&&t.jsxs("span",{children:[" ",d.count]})]},d.value)})})}function Jt(e,s=60){const n=e.trim();return n.length<=s?n:`${n.slice(0,s-1)}…`}function vn(e){return Be([e]).filter(s=>s.children.length===0).map(s=>s.row.slug)}function Kt(e){return e.nodes.map(s=>({rootSlug:s.row.slug,label:s.row.title||s.row.slug,terminals:vn(s)}))}function jn(e){const s=new Map;for(const n of e){const a=Kt(n);n.nodes.forEach((d,l)=>{const i=a.filter((r,o)=>o!==l);for(const r of Be([d]))s.set(r.row.slug,i)})}return s}function Xt({job:e,headChoices:s}){const[n,a]=f.useState(!1),d=f.useCallback((l,i)=>{a(!0),window.api.schedule.setPrdDisposition({slug:e.slug,cwd:e.cwd??void 0,disposition:l,dependsOn:i}).then(H.fromOutcome).catch(()=>H.error("Failed to change disposition")).finally(()=>a(!1))},[e.slug,e.cwd]);return e.disposition!=="append"&&s.length===0?null:t.jsxs("select",{"data-testid":"job-row-disposition-control",disabled:n,value:"",onChange:l=>{const i=l.target.value;if(i==="__new-head__")d("new-head");else if(i){const r=s.find(o=>o.rootSlug===i);r&&d("append",r.terminals)}},className:"text-[13px] font-semibold text-fg-dim hover:text-fg bg-transparent border border-line/60 rounded px-1.5 py-0.5 cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed",title:"Change this wave's relationship to the rest of the Epic's plan",children:[t.jsx("option",{value:"",disabled:!0,children:"change disposition…"}),e.disposition==="append"&&t.jsx("option",{value:"__new-head__",children:"promote to new head"}),s.map(l=>t.jsxs("option",{value:l.rootSlug,children:["attach behind: ",Jt(l.label,40)]},l.rootSlug))]})}function yn(e,s,n=null){if(s.length===0||e.length===0)return e;const a=new Set,d=new Set;for(const i of e){a.add(i.slug);for(const r of wt(i))d.add(r)}const l=[];for(const i of s)i.archived!==!0||a.has(i.slug)||n&&i.cwd!==n||wt(i).some(r=>d.has(r))&&(a.add(i.slug),l.push({slug:i.slug,title:i.title,cwd:i.cwd,parallelGroup:i.parallelGroup,estimateMinutes:i.estimateMinutes,bodyPreview:"",status:i.archivedStatus??"completed",runId:null,startedAt:null,finishedAt:null,exitCode:null,error:null,dependsOn:i.dependsOn??void 0,sourcePromptId:i.sourcePromptId??null,epicId:i.epicId??null,synthetic:!0}));return l.length===0?e:[...e,...l]}const Nn=[],kn=new Set(["failed","needs_review","quarantined"]);function Sn(e){switch(e.status){case"completed":case"skipped":return"bg-sage";case"running":case"investigating":return"bg-accent";case"failed":return"bg-accent";case"needs_review":return"bg-butter";case"quarantined":return"bg-butter/60";default:return e.rowKind==="eta"||e.rowKind==="next"||e.rowKind==="retry"?"border border-fg-faint bg-transparent":"bg-fg-faint/40"}}function Cn(e){switch(e.status){case"running":case"investigating":return"bg-butter/10";case"failed":return"bg-accent/10";case"needs_review":return"bg-butter/25";default:return""}}function $n(e){switch(e.rowKind){case"running":case"dep":case"failed":return"text-accent";case"review":return"text-butter font-semibold";default:return"text-fg-faint"}}function Pn({row:e,elapsedMs:s,listIndex:n,onFocused:a,headChoices:d=Nn}){const[l,i]=f.useState(!1),r=e.job,o=s!==null&&e.rowKind==="running"?zt(r,s):e.rowTrailing,c=e.status==="completed"||e.status==="skipped",p=e.rowKind==="dep"&&e.blockers.some(h=>!h.missing&&h.status!==null&&kn.has(h.status)),u=c||p;return t.jsxs("div",{role:"listitem","data-testid":"prd-row","data-slug":e.slug,className:"border-t border-rule-inner first:border-t-0",children:[t.jsxs("button",{type:"button","data-job-row":!0,"data-job-status":r.status,"data-job-index":n,onClick:()=>i(h=>!h),onFocus:()=>a(n),"aria-expanded":l,"aria-label":`${e.prdNumber?`PRD ${e.prdNumber}, `:""}${r.title}, ${r.status}${o?`, ${o}`:""}`,title:r.title,className:`w-full h-[31px] py-1 px-2 text-left flex items-center gap-1.5 hover:bg-bg/40 focus:outline-none focus:ring-1 focus:ring-accent focus:ring-inset ${Cn(e)}`,children:[t.jsx("span",{"aria-hidden":"true",className:`shrink-0 w-[7px] h-[7px] rounded-full ${Sn(e)}`}),t.jsx("span",{className:"shrink-0 font-mono text-[10.5px] text-fg-faint w-[30px]",children:e.prdNumber?`#${e.prdNumber}`:""}),t.jsx("span",{className:`flex-1 min-w-0 truncate text-[12.5px] leading-tight ${u?"text-fg-faint":"text-fg font-medium"}`,children:r.title}),t.jsx("span",{"data-testid":"prd-row-trailing",className:`shrink-0 font-mono text-[10.5px] ${$n(e)}`,children:o})]}),l&&t.jsx(Dn,{row:e,elapsedMs:s,headChoices:d})]})}const Zt=f.memo(Pn);function Dn({row:e,elapsedMs:s,headChoices:n}){const a=e.job,[d,l]=f.useState(!1),i=pe(g=>g.sessions),r=f.useMemo(()=>Pe(a,i),[a,i]),o=r.known&&r.epicId?i[r.epicId]:null,c=f.useCallback(g=>_t(g),[]),p="font-mono text-[11.5px] text-fg-dim leading-snug break-words",u="text-[12px] font-semibold bg-transparent border-0 cursor-pointer p-0",h=a.error?a.error.split(`
|
|
3
3
|
`)[0]:null;return t.jsxs("div",{"data-testid":"prd-row-detail",className:"px-3 py-2 bg-bg-elev/50 border-t border-rule-inner flex flex-col gap-1",children:[t.jsxs("div",{className:p,children:[a.status.replace(/_/g," "),a.exitCode!==null&&` · exit ${a.exitCode}`,a.verifierVerdict&&` · ${$e(a.verifierVerdict)}`,a.startedAt&&` · started ${ue(Date.parse(a.startedAt))}`,a.finishedAt&&` · finished ${ue(Date.parse(a.finishedAt))}`,s===null&&e.rowTrailing&&e.rowKind==="done"?` · took ${e.rowTrailing}`:""]}),e.cycle&&t.jsxs("div",{className:`${p} text-accent`,"data-testid":"job-row-cycle-warning",children:["⚠ dependsOn cycle — ",e.blockers.map(g=>g.slug).join(" ↔ ")||"self-referencing"]}),!e.cycle&&e.blockers.length>0&&t.jsxs("div",{className:p,"data-testid":"job-row-blockers",children:["depends on ",e.blockers.map(g=>`${g.slug} (${g.missing?"missing":(g.status??"unknown").replace(/_/g," ")})`).join(", ")]}),a.status==="pending"&&a.heldReason&&t.jsxs("div",{className:`${p} text-amber-400/90`,"data-testid":"job-row-held-reason",children:["held · ",a.heldReason]}),h&&t.jsx("div",{className:`${p} text-accent/80`,children:h}),!a.synthetic&&t.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1 pt-0.5",children:[o&&t.jsx("button",{type:"button","data-testid":"job-row-prompt-session-link",title:o.goalText,onClick:()=>c(o.id),className:`${u} text-accent hover:text-accent/80`,children:"view epic →"}),a.runId&&t.jsx("button",{type:"button",onClick:()=>l(!0),className:`${u} text-fg-dim hover:text-fg`,children:"view log →"}),a.status==="quarantined"&&t.jsx("button",{type:"button","data-testid":"job-row-adopt-prd",title:"Stamp this PRD's provenance so the scheduler will run it — no unstamped PRD runs automatically.",onClick:()=>{window.api.schedule.adoptPrd(a.slug).then(H.fromOutcome).catch(()=>H.error("Failed to adopt PRD"))},className:`${u} text-accent hover:text-accent/80`,children:"adopt PRD →"}),a.status!=="pending"&&a.status!=="running"&&a.status!=="quarantined"&&t.jsx("button",{type:"button",onClick:()=>window.api.schedule.resetJob(a.slug,a.cwd??void 0),className:`${u} text-fg-dim hover:text-fg`,children:"reset to pending →"}),a.disposition&&(a.status==="pending"||a.status==="quarantined")&&t.jsx(Xt,{job:a,headChoices:n})]}),d&&a.runId&&t.jsx(qe,{runId:a.runId,slug:a.slug,title:a.title||a.slug,onClose:()=>l(!1)})]})}const ce=190,An=7,Rn=5,Mn=[],es=e=>e==="completed"||e==="skipped",ts=e=>e==="running"||e==="investigating",ss=e=>e==="failed"||e==="needs_review"||e==="quarantined";function Re(e){return ts(e.status)?0:ss(e.status)?1:es(e.status)?3:2}const In={done:"text-sage",running:"text-accent",held:"text-fg-faint",pending:"text-fg-faint",blocked:"text-butter"},En={done:"bg-sage",running:"bg-accent",held:"bg-fg-faint/50",pending:"bg-fg-faint/50",blocked:"bg-butter"};function Tn(e,s){return e.every(n=>es(n.status))?`+${e.length} done`:e.every(n=>n.rowKind==="dep"&&n.blockers.some(a=>!a.missing&&a.status!==null&&ss(a.status)))?`+${e.length} blocked`:`+${e.length} in stage ${s}`}function _n({stage:e,epicId:s,now:n,hidden:a,indexBySlug:d,headChoicesBySlug:l,onRowFocused:i}){const[r,o]=f.useState(!1),c=f.useMemo(()=>e.rows.filter(x=>!(a.has(x.slug)&&(x.status==="completed"||x.status==="failed"))).map((x,R)=>({r:x,i:R})).sort((x,R)=>Re(x.r)-Re(R.r)||x.i-R.i).map(x=>x.r),[e.rows,a]),p=f.useMemo(()=>c.filter(x=>Re(x)<=1).length,[c]),u=Math.max(e.state==="done"?Rn:An,p),h=r?c:c.slice(0,u),g=r?[]:c.slice(u),m=c.find(x=>x.status==="failed"),v=c.find(x=>x.status==="needs_review"),y=p>0&&(m!==void 0||v!==void 0),k=h.reduce((x,R,P)=>Re(R)<=1?P:x,-1),S=x=>t.jsx(Zt,{row:x,elapsedMs:ts(x.status)&&x.job.startedAt?n-Date.parse(x.job.startedAt):null,listIndex:d.get(x.slug)??0,onFocused:i,headChoices:l.get(x.slug)??Mn},x.slug),T="flex-1 min-w-0 truncate h-[24px] text-[11.5px] font-medium text-fg-dim hover:text-fg border border-rule-structural rounded-sm bg-transparent cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed";return t.jsxs("div",{"data-testid":"stage-column","data-stage":e.n,style:{width:ce},className:"shrink-0 border-l border-rule-structural first:border-l-0 flex flex-col self-stretch",children:[t.jsxs("div",{className:"h-[30px] shrink-0 flex items-center gap-1.5 px-2 border-b border-rule-inner","data-testid":"stage-header",children:[t.jsx("span",{"aria-hidden":"true",className:`w-[7px] h-[7px] rounded-full shrink-0 ${En[e.state]}`}),t.jsxs("span",{className:`text-[10px] font-semibold uppercase tracking-wide ${In[e.state]}`,children:["Stage ",e.n]}),e.state==="blocked"&&t.jsx(me,{title:"Rows in this stage are failed / need review / are quarantined, or wait on one that is."}),t.jsx("span",{"data-testid":"stage-summary",className:"ml-auto font-mono text-[10.5px] text-fg-dim truncate",children:e.summary})]}),t.jsx("div",{role:"presentation",children:h.map((x,R)=>t.jsxs("div",{children:[S(x),y&&R===k&&t.jsxs("div",{"data-testid":"stage-attention-actions",className:"flex gap-1.5 px-2 py-1.5 border-t border-rule-inner",children:[m&&t.jsxs("button",{type:"button","data-testid":"stage-retry",title:`Reset ${m.slug} to pending`,onClick:()=>{window.api.schedule.resetJob(m.slug,m.job.cwd??void 0).then(P=>{P.ok||H.error(P.error??`Failed to reset ${m.slug}`)}).catch(()=>H.error(`Failed to reset ${m.slug}`))},className:T,children:["Retry ",m.prdNumber?`#${m.prdNumber}`:m.slug]}),v&&t.jsxs("button",{type:"button","data-testid":"stage-review",disabled:!s,title:s?"Open the authoring Epic — a needs_review PRD is a question routed back to it":"No authoring Epic recorded for this plan",onClick:()=>{s&&_t(s)},className:T,children:["Review ",v.prdNumber?`#${v.prdNumber}`:v.slug]})]})]},x.slug))}),(g.length>0||r&&c.length>u)&&t.jsx("button",{type:"button","data-testid":"stage-footer","aria-expanded":r,onClick:()=>o(x=>!x),className:"mt-auto h-[26px] border-t border-rule-inner font-mono text-[11px] text-fg-faint hover:text-fg-dim bg-transparent cursor-pointer",children:r?"show less ▴":`${Tn(g,e.n)} ▾`})]})}const we=6,Qe=4,Ee=4,Ct=12,$t=5,ns=2,Pt=4,On={done:"bg-sage",running:"bg-accent",attention:"bg-butter",failed:"bg-red-600",pending:"bg-fg-faint/50"};function Ln(e){return e==="completed"||e==="skipped"?"done":e==="running"||e==="investigating"?"running":e==="failed"?"failed":e==="needs_review"||e==="quarantined"?"attention":"pending"}function Fn(e){const s=[],n=[],a=[];let d=$t;for(const l of e){const i=Math.max(1,Math.ceil(l.rows.length/Ee));n.push(d),a.push(i*we),l.rows.forEach((r,o)=>{s.push({x:d+Math.floor(o/Ee)*we,y:ns+o%Ee*we,tone:Ln(r.status),title:`${r.prdNumber?`#${r.prdNumber}`:r.slug} ${r.title} — ${r.status}`})}),d+=i*we+Ct}return{dots:s,stageX:n,stageW:a,width:Math.max(0,d-Ct)+$t}}function ve(e,s){return e.findIndex(n=>n.rows.some(a=>s(a.status)))}const et=e=>e==="running"||e==="investigating",tt=e=>e==="failed"||e==="needs_review"||e==="quarantined";function qn({stages:e,first:s,perView:n,onSeek:a}){const d=f.useMemo(()=>Fn(e),[e]),l=f.useMemo(()=>ve(e,et)>=0,[e]),i=f.useMemo(()=>ve(e,tt)>=0,[e]),r=f.useRef(!1),o=e.length,c=Math.min(o-1,s+n-1),p=d.stageX[Math.min(s,o-1)]??0,u=(d.stageX[c]??0)+(d.stageW[c]??0),h=m=>{const v=m.currentTarget.getBoundingClientRect(),y=m.clientX-v.left;let k=0;for(let S=0;S<o;S++)d.stageX[S]<=y&&(k=S);a(Math.max(0,Math.min(o-1,k-Math.floor(n/2))))},g="px-2 h-[20px] text-[11.5px] disabled:opacity-40 disabled:cursor-not-allowed";return t.jsxs("div",{"data-testid":"plan-minimap",className:"h-[28px] flex items-center gap-3 px-3 border-t border-rule-inner",children:[t.jsxs("span",{className:"shrink-0 flex items-center gap-1 text-[10.5px] font-semibold uppercase tracking-wide text-fg-faint",children:["Whole graph",t.jsx(me,{title:"Every PRD in this plan as one dot, grouped by stage. The rust box is the range of stages shown below — drag it to scroll."})]}),t.jsxs("div",{"data-testid":"plan-minimap-dots",role:"presentation",className:"relative shrink min-w-0 overflow-hidden cursor-ew-resize touch-none",style:{width:d.width,height:Ee*we-(we-Qe)+2*ns},onPointerDown:m=>{var v,y;r.current=!0,(y=(v=m.currentTarget).setPointerCapture)==null||y.call(v,m.pointerId),h(m)},onPointerMove:m=>{r.current&&h(m)},onPointerUp:()=>{r.current=!1},onPointerCancel:()=>{r.current=!1},children:[d.dots.map((m,v)=>t.jsx("span",{title:m.title,"data-tone":m.tone,className:`absolute rounded-[1px] ${On[m.tone]}`,style:{left:m.x,top:m.y,width:Qe,height:Qe}},v)),t.jsx("span",{"data-testid":"plan-minimap-brush","aria-hidden":"true",className:"absolute top-0 bottom-0 border border-accent bg-accent/10 rounded-[2px] pointer-events-none",style:{left:p-Pt,width:u-p+2*Pt}})]}),t.jsxs("span",{className:"ml-auto shrink-0 font-mono text-[11.5px] text-fg-faint","data-testid":"plan-minimap-range",children:["stages ",Math.min(s+1,o),"–",c+1," of ",o]}),t.jsxs("span",{className:"shrink-0 inline-flex border border-line rounded overflow-hidden",role:"group","aria-label":"Jump the stage window",children:[t.jsx("button",{type:"button","data-testid":"minimap-running",disabled:!l,title:l?"Scroll to the lowest stage with a running PRD":"No stage has a running PRD",onClick:()=>a(ve(e,et)),className:`${g} text-fg-dim hover:text-fg`,children:"Running"}),t.jsx("button",{type:"button","data-testid":"minimap-blockers",disabled:!i,title:i?"Scroll to the lowest stage with a failed / needs-review / quarantined PRD":"No stage has a failed, needs-review or quarantined PRD",onClick:()=>a(ve(e,tt)),className:`${g} text-fg-dim hover:text-fg border-l border-line`,children:"Blockers"})]})]})}const Bn=148;function Hn({stages:e,onSeek:s}){if(e.length===0)return null;const n=e[0].n,a=e[e.length-1].n;return t.jsxs("div",{"data-testid":"further-stages",style:{width:Bn},className:"shrink-0 border-l border-rule-structural flex flex-col",children:[t.jsxs("div",{className:"h-[30px] shrink-0 flex items-center px-2 border-b border-rule-inner text-[10.5px] font-semibold uppercase tracking-wide text-fg-faint",children:["Stage ",n,"–",a]}),t.jsxs("div",{className:"h-[22px] shrink-0 flex items-center gap-1 px-2 text-[10.5px] font-semibold uppercase tracking-wide text-fg-faint",children:["Further stages",t.jsx(me,{title:"Stages beyond the visible window. Click one to scroll the stage columns to it."})]}),e.map(d=>{const l=d.rows.length===0?0:d.doneCount/d.rows.length*100;return t.jsxs("button",{type:"button","data-testid":"further-stage-row","data-stage":d.n,title:`${d.summary} — scroll to stage ${d.n}`,onClick:()=>s(d.n-1),className:"h-[26px] px-2 flex items-center gap-2 border-t border-rule-inner bg-transparent hover:bg-bg-hi cursor-pointer text-left",children:[t.jsxs("span",{className:"font-mono text-[10.5px] text-fg-dim w-[50px] whitespace-nowrap shrink-0",children:["stage ",d.n]}),t.jsx("span",{role:"progressbar","aria-valuenow":d.doneCount,"aria-valuemin":0,"aria-valuemax":d.rows.length,className:"flex-1 h-[4px] rounded-sm bg-rule-inner overflow-hidden",children:t.jsx("span",{className:"block h-full bg-sage",style:{width:`${l}%`}})})]},d.n)})]})}const Gn=[],Vn=e=>e==="running"||e==="investigating";function Wn(e){const s=ln(e),n=new Map,a=new Map;for(const r of e.stages){a.set(r.n,r.rows.length);for(const o of r.rows)n.set(o.slug,o)}const d=new Map;let l=0;const i=[];for(const r of s){const o=n.get(r);l+=o.estimateMinutes??0,d.set(o.stage,(d.get(o.stage)??0)+1),i.push({row:o,totalMinutes:l,othersInStage:0})}for(const r of i)r.othersInStage=(a.get(r.row.stage)??0)-(d.get(r.row.stage)??0);return i}function Un({plan:e,now:s,indexBySlug:n,headChoicesBySlug:a,onRowFocused:d}){const l=f.useMemo(()=>Wn(e),[e]);return t.jsx("div",{"data-testid":"critical-path",className:"border-t border-rule-structural max-w-[640px]",children:l.map(({row:i,totalMinutes:r,othersInStage:o})=>t.jsxs("div",{"data-testid":"critical-entry","data-slug":i.slug,children:[t.jsxs("div",{className:"flex items-start",children:[t.jsx("div",{className:"flex-1 min-w-0",children:t.jsx(Zt,{row:i,elapsedMs:Vn(i.status)&&i.job.startedAt?s-Date.parse(i.job.startedAt):null,listIndex:n.get(i.slug)??0,onFocused:d,headChoices:a.get(i.slug)??Gn})}),t.jsxs("span",{"data-testid":"critical-est",className:"shrink-0 h-[31px] px-3 flex items-center gap-2 font-mono text-[11.5px] text-fg-faint border-t border-rule-inner",children:[t.jsx("span",{title:"estimateMinutes",children:i.estimateMinutes?`${i.estimateMinutes}m`:"—"}),t.jsxs("span",{className:"text-fg-dim",title:"Running total along the chain",children:["Σ ",r,"m"]})]})]}),o>0&&t.jsxs("div",{"data-testid":"critical-others",className:"h-[22px] px-3 flex items-center font-mono text-[11.5px] text-fg-faint border-t border-rule-inner",children:["stage ",i.stage," · +",o," not on the critical path"]})]},i.slug))})}const Dt=1,At=1350,zn={active:"border-l-accent",queued:"border-l-rule-structural",done:"border-l-sage",draft:"border-l-fg-faint/40 border-dashed"},Qn={active:{label:"ACTIVE",cls:"bg-accent text-white border border-accent"},queued:{label:"QUEUED",cls:"text-fg-dim border border-fg-faint"},done:{label:"DONE",cls:"text-sage-dark border border-sage"},draft:{label:"DRAFT",cls:"text-fg-faint border border-dashed border-fg-faint"}},Yn=e=>String(e).padStart(2,"0");function Jn({plan:e}){const s=Math.max(1,e.prdCount),n=e.doneCount/s*100,a=e.runningCount/s*100;return t.jsxs("span",{"data-testid":"plan-progress",role:"progressbar","aria-valuenow":e.doneCount,"aria-valuemin":0,"aria-valuemax":e.prdCount,className:"flex w-[160px] h-[5px] rounded-sm overflow-hidden bg-rule-inner shrink-0",children:[t.jsx("span",{className:"h-full bg-sage",style:{width:`${n}%`}}),t.jsx("span",{className:"h-full bg-accent",style:{width:`${a}%`}})]})}function Kn({plan:e,mode:s="graph",now:n,hidden:a,indexBySlug:d,headChoicesBySlug:l,onRowFocused:i,onOpenPrds:r}){var se,Y;const[o,c]=f.useState(e.status==="active"||e.status==="queued"),[p,u]=f.useState(!1),h=f.useRef(null),[g,m]=f.useState(0),[v,y]=f.useState(At),k=f.useMemo(()=>{const M=ve(e.stages,et);return M>=0?M:Math.max(0,ve(e.stages,tt))},[e.stages]);f.useLayoutEffect(()=>{if(!o)return;const M=h.current,F=(M==null?void 0:M.clientWidth)||At,N=Math.max(0,Math.min(k,e.stageCount-Math.max(1,Math.ceil(F/ce))));M!=null&&M.clientWidth&&y(M.clientWidth),M&&(M.scrollLeft=N*ce),m(N)},[o]);const S=f.useMemo(()=>{let M=null;for(const F of e.stages)for(const N of F.rows){if(!N.job.runId)continue;const C=N.job.finishedAt?Date.parse(N.job.finishedAt):0;(!M||C>M.at)&&(M={runId:N.job.runId,slug:N.slug,title:N.title,at:C})}return M},[e.stages]),T=_e((Y=(se=e.stages[0])==null?void 0:se.rows[0])==null?void 0:Y.job.cwd)??"—",x=Qn[e.status],R=Math.max(1,Math.ceil(v/ce)),P=Math.max(0,Math.min(g-Dt,e.stageCount)),D=Math.min(e.stageCount,g+R+Dt),O=M=>{const F=Math.max(0,Math.min(e.stageCount-1,M));h.current&&(h.current.scrollLeft=F*ce),m(F)},J=Math.min(e.stageCount,g+R),W=M=>{const F=M.currentTarget,N=Math.floor(F.scrollLeft/ce);N!==g&&m(N),F.clientWidth&&F.clientWidth!==v&&y(F.clientWidth)},z="h-[24px] px-3 text-[12px] font-medium text-fg border border-rule-structural rounded-sm bg-transparent hover:bg-bg-hi cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed shrink-0",K=(()=>{switch(e.status){case"active":return t.jsx("button",{type:"button","data-testid":"plan-action",title:"Pauses the WHOLE scheduler (machine-wide) — there is no per-plan pause.",onClick:()=>{window.api.schedule.pause().catch(()=>H.error("Failed to pause the scheduler"))},className:z,children:"Pause plan"});case"queued":return t.jsx("button",{type:"button","data-testid":"plan-action",title:"Fires the next scheduler batch machine-wide (force tick) — it does not target this plan.",onClick:()=>{window.api.schedule.forceTick().then(H.fromOutcome).catch(()=>H.error("Failed to fire the next batch"))},className:z,children:"Run now"});case"done":return t.jsx("button",{type:"button","data-testid":"plan-action",disabled:!S,title:S?`Open the run log of ${S.slug}, the plan's last run`:"No run log recorded for this plan",onClick:()=>u(!0),className:z,children:"View run"});case"draft":return t.jsx("button",{type:"button","data-testid":"plan-action",title:"Open the PRDs sub-view on this plan's first PRD (the PRDs view has no per-Epic filter).",onClick:()=>{var M,F;return r==null?void 0:r(((F=(M=e.stages[0])==null?void 0:M.rows[0])==null?void 0:F.slug)??null)},className:z,children:"Schedule…"})}})(),X=e.etaMs>0?` · ${Ut(e.etaMs)} left`:"";return t.jsxs("section",{"data-testid":"plan-band","data-epic-id":e.epicId??"","data-plan-status":e.status,className:`border-l-[3px] ${zn[e.status]} border-b border-rule-structural`,children:[t.jsxs("div",{className:"h-[32px] flex items-center gap-2.5 px-3","data-testid":"plan-header",children:[t.jsx("button",{type:"button","aria-expanded":o,"aria-label":o?"Collapse plan":"Expand plan","data-testid":"plan-toggle",onClick:()=>c(M=>!M),className:"shrink-0 w-[14px] text-[11px] text-fg-faint hover:text-fg bg-transparent border-0 cursor-pointer p-0",children:o?"▾":"▸"}),t.jsx("span",{className:"font-mono text-[11.5px] text-fg-faint shrink-0",children:Yn(e.index)}),t.jsx("span",{className:"font-serif text-[15px] font-bold text-fg truncate shrink-0 max-w-[320px]",title:e.epicLabel!==e.label?`${e.label} — ${e.epicLabel}`:e.label,"data-testid":"plan-label",children:e.label}),t.jsx("span",{"data-testid":"plan-chip",className:`shrink-0 rounded-sm px-1.5 py-[1px] text-[10px] font-bold tracking-wide ${x.cls}`,children:x.label}),t.jsx("span",{"aria-hidden":"true",className:"shrink-0 w-px h-[16px] bg-rule-structural"}),t.jsx("span",{className:"font-mono text-[11.5px] text-fg-faint truncate min-w-0","data-testid":"plan-meta",children:e.validateSlug!=null&&e.epicLabel!==e.label?t.jsxs(t.Fragment,{children:[T," · ",e.epicLabel," · ",e.prdCount," PRD",e.prdCount===1?"":"s"," · ",e.width," wide · ",e.stageCount," stage",e.stageCount===1?"":"s"]}):t.jsxs(t.Fragment,{children:[T," · ",e.prdCount," PRD",e.prdCount===1?"":"s",e.width>1?` · ${e.width} wide`:""," · ",e.stageCount," stage",e.stageCount===1?"":"s"]})}),t.jsx(me,{title:`${e.doneCount} done · ${e.runningCount} running · ${e.heldCount} held · ${e.blockedCount} blocked`}),t.jsxs("span",{className:"ml-auto font-mono text-[11.5px] text-fg-dim shrink-0","data-testid":"plan-progress-label",children:[e.doneCount,"/",e.prdCount,X]}),t.jsx(Jn,{plan:e}),K]}),o&&s==="critical"&&t.jsx(Un,{plan:e,now:n,indexBySlug:d,headChoicesBySlug:l,onRowFocused:i}),o&&s!=="critical"&&e.status==="active"&&t.jsx(qn,{stages:e.stages,first:g,perView:R,onSeek:O}),o&&s!=="critical"&&t.jsxs("div",{className:"flex border-t border-rule-structural",children:[t.jsxs("div",{ref:h,"data-testid":"plan-stages",onScroll:W,className:"flex flex-1 min-w-0 overflow-x-auto",children:[P>0&&t.jsx("div",{"aria-hidden":"true",className:"shrink-0",style:{width:P*ce}}),e.stages.slice(P,D).map(M=>t.jsx(_n,{stage:M,epicId:e.epicId,now:n,hidden:a,indexBySlug:d,headChoicesBySlug:l,onRowFocused:i},M.n)),D<e.stageCount&&t.jsx("div",{"aria-hidden":"true",className:"shrink-0",style:{width:(e.stageCount-D)*ce}})]}),t.jsx(Hn,{stages:e.stages.slice(J),onSeek:O})]}),p&&S&&t.jsx(qe,{runId:S.runId,slug:S.slug,title:S.title||S.slug,onClose:()=>u(!1)})]})}function Xn({section:e,children:s}){const[n,a]=f.useState(!0),d=Object.entries(e.counts).map(([l,i])=>`${i} ${l.replace(/_/g," ")}`).join(" · ");return t.jsxs("div",{className:"border-t border-line","data-testid":"backlog-epic-section","data-epic-id":e.epicId??"",children:[t.jsxs("button",{type:"button",onClick:()=>a(l=>!l),className:"w-full flex items-center gap-2.5 px-[18px] py-2.5 bg-bg-elev/60 hover:bg-bg-elev text-left","aria-expanded":n,title:e.label,children:[t.jsx("span",{className:`text-fg-faint inline-flex shrink-0 transition-transform duration-150 ${n?"rotate-90":""}`,"aria-hidden":"true",children:t.jsx(nt,{name:"chevron",size:12})}),t.jsx("span",{className:"font-serif text-[14.5px] font-semibold text-fg truncate","data-testid":"backlog-epic-label",children:e.label}),t.jsxs("span",{className:"font-mono text-[11px] text-fg-faint shrink-0",children:[e.total," PRD",e.total===1?"":"s"]}),t.jsx("span",{className:"font-mono text-[11px] text-fg-faint truncate",children:d})]}),n&&s]})}const Zn=[],ea=[],ta={depth:0,blockers:Zn,blocked:!1,hasNeedsReviewBlocker:!1,hasMissingDep:!1,cycle:!1,parallelEligible:!1};function sa(e){return e.missing?`${e.slug} (missing)`:e.needsReview?`${e.slug} (needs review)`:`${e.slug} (${(e.status??"unknown").replace(/_/g," ")})`}function na(e){return e.missing?"text-accent":e.needsReview?"text-butter font-semibold":e.status==="completed"?"text-sage":"text-amber-400/90"}function aa({job:e,eta:s,elapsedMs:n,avgDurationMs:a,listIndex:d,onFocused:l,hold:i,backlog:r=ta,headChoices:o=ea}){const[c,p]=f.useState(!1),[u,h]=f.useState(!1),g=pe(D=>D.sessions),m=f.useMemo(()=>Pe(e,g),[e,g]),v=m.known&&m.epicId?g[m.epicId]:null,y=f.useCallback(D=>{at(D),window.dispatchEvent(new CustomEvent("sm:navigate",{detail:"terminal"}))},[]),k=e.status==="running",S=e.status==="failed";let T=null;k&&n!==null?T=`${Te(n)} elapsed`:e.status==="completed"&&e.startedAt&&e.finishedAt?T=`took ${Ce(Date.parse(e.finishedAt)-Date.parse(e.startedAt))}`:s&&(T=s);const x=e.error??null,R=S&&x?x.split(`
|
|
4
4
|
`)[0]:e.status==="needs_review"&&e.verifierVerdict?$e(e.verifierVerdict):null,P=k&&n!==null?Math.min(.99,n/a):0;return t.jsxs("div",{role:"listitem",className:"border-t border-line",children:[t.jsxs("button",{type:"button","data-job-row":!0,"data-job-status":e.status,"data-job-index":d,"data-depth":r.depth,onClick:()=>p(D=>!D),onFocus:()=>l(d),style:r.depth>0?{paddingLeft:18+r.depth*20}:void 0,className:`w-full text-left grid grid-cols-[116px_1fr_auto_auto] items-center gap-4 px-[18px] py-3.5 hover:bg-bg/40 focus:outline-none focus:ring-1 focus:ring-accent focus:ring-inset ${c?"bg-bg-elev/40":""}`,"aria-expanded":c,"aria-label":`${ie(e.slug)?`PRD ${ie(e.slug)}, `:""}${e.title}, ${e.status}${T?`, ${T}`:""}`,title:e.title,children:[t.jsx(Ot,{status:e.status}),t.jsxs("div",{className:"min-w-0",children:[t.jsxs("div",{className:"flex items-baseline gap-2 text-[14.5px] font-medium text-fg leading-snug",children:[ie(e.slug)&&t.jsx(Lt,{n:ie(e.slug)}),e.title,t.jsx(Ft,{leaked:e.leakedDescendants}),t.jsx(Ss,{count:e.leftoverCount,truncated:e.leftoverPathsTruncated,salvagePatch:e.salvagePatch}),r.parallelEligible&&t.jsx("span",{"data-testid":"job-row-parallel-eligible",title:"No dependsOn, and nothing in this Epic depends on it — can run any time a slot is free",className:"text-[10px] font-semibold uppercase tracking-wide text-sage/90 bg-sage/10 border border-sage/30 rounded px-1.5 py-0.5",children:"parallel"})]}),r.cycle&&t.jsxs("div",{className:"text-[12.5px] mt-0.5 text-accent font-mono","data-testid":"job-row-cycle-warning",children:["⚠ dependsOn cycle — ",r.blockers.map(D=>D.slug).join(" ↔ ")||"self-referencing"]}),!r.cycle&&r.blockers.length>0&&t.jsxs("div",{className:"text-[12.5px] mt-0.5 font-mono","data-testid":"job-row-blockers",children:[t.jsx("span",{className:r.blocked||r.hasMissingDep?"text-amber-400/90":"text-fg-faint",children:r.blocked||r.hasMissingDep?"blocked by ":"depends on "}),r.blockers.map((D,O)=>t.jsxs("span",{className:na(D),children:[O>0&&", ",sa(D)]},D.slug))]}),R&&t.jsx("div",{className:`text-[12.5px] mt-0.5 ${S?"text-accent/80":"text-fg-faint"}`,children:R}),i&&t.jsx("div",{className:"text-[12.5px] mt-0.5 text-amber-400/90 font-mono","data-testid":"job-row-hold",children:i.dep?t.jsxs(t.Fragment,{children:["held · waiting on ",i.dep," (",i.depStatus,")"]}):t.jsxs(t.Fragment,{children:["held · ",i.reason??"launch blocked"]})}),!i&&e.status==="pending"&&e.heldReason&&t.jsxs("div",{className:"text-[12.5px] mt-0.5 text-amber-400/90 font-mono","data-testid":"job-row-held-reason",children:["held · ",e.heldReason]}),t.jsx(rt,{epicId:m.epicId,label:m.label?Jt(m.label):null,onOpen:y,testId:"job-row-prompt-session-chip",className:"mt-0.5"})]}),t.jsx(it,{cwd:e.cwd}),t.jsxs("span",{className:"inline-flex items-center gap-2.5 font-mono text-xs text-fg-faint shrink-0",children:[t.jsx(Cs,{status:e.status,overrun:e.overrun}),T,t.jsx("span",{className:`text-fg-faint inline-flex transition-transform duration-150 ${c?"rotate-90":""}`,"aria-hidden":"true",children:t.jsx(nt,{name:"chevron",size:14})})]})]}),k&&!c&&t.jsx("div",{className:"h-1 bg-line mx-[18px] mb-3 rounded-full overflow-hidden",children:t.jsx("div",{className:"h-full bg-accent transition-all duration-1000",style:{width:`${Math.max(4,P*100)}%`}})}),c&&t.jsxs("div",{className:"px-[18px] py-5 grid grid-cols-[repeat(auto-fit,minmax(160px,1fr))] gap-5 bg-bg-elev/50 border-t border-line",children:[t.jsxs(re,{label:"Status",children:[t.jsx(B,{k:"result",v:e.exitCode!==null?`exit ${e.exitCode}`:"—"}),t.jsx(B,{k:"state",v:e.status.replace(/_/g," ")}),e.verifierVerdict&&t.jsx(B,{k:"verdict",v:$e(e.verifierVerdict)}),e.leakedDescendants&&e.leakedDescendants.length>0&&t.jsx(B,{k:"leaked",v:qt(e.leakedDescendants),wrap:!0}),e.leftoverCount!=null&&e.leftoverCount>0&&t.jsx(B,{k:"uncommitted",v:`${e.leftoverCount} file${e.leftoverCount===1?"":"s"}${e.leftoverPathsTruncated?"+":""}: ${(e.leftoverPaths??[]).join(", ")}${e.salvagePatch?` — salvaged to ${e.salvagePatch}`:""}`,wrap:!0}),x&&t.jsx(B,{k:"error",v:x.split(`
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{b3 as T,at as e,a$ as A,aJ as j,b9 as L,b0 as V,bb as z,bi as H,P as ce,l as C,a3 as de,v as ue,Q as Y,S,a as pe,bk as B,be as me,ax as xe,aB as he,J as fe,ap as ge}from"./index-QJxszEhM.js";import{P as F}from"./Panel-CA6TdCHv.js";import{P as be,H as ye,S as Z}from"./Library-LftcMs6C.js";import{S as I}from"./SourceChip-CeprSxwb.js";import{V as U}from"./ViewTabs-fupn9keJ.js";import{r as Q}from"./claude-settings-schema-COigsajx.js";import{L as je}from"./ListDetail-CnL1azR0.js";import{P as ve}from"./ProvenanceBadge-Y3DhyiJo.js";import"./monaco-editor-BsIlgG7c.js";import"./Button-DvTXa_-4.js";function ke(t){const s=t??{},n={...s.$defs??{},...s.definitions??{}},a=i=>{if(!i)return{};if(!i.$ref)return l(i);const d=/^#\/(\$defs|definitions)\/(.+)$/.exec(i.$ref);if(!d)return l(i);const h=n[d[2]];return h?a({...h,...p(i)}):l(i)},o=new Set(["__proto__","constructor","prototype"]),r=i=>{if(!i)return{};const d={};for(const[h,g]of Object.entries(i))o.has(h)||(d[h]=g);return d},l=i=>{if(!i.allOf||i.allOf.length===0)return i;const d={...i};delete d.allOf;for(const h of i.allOf){const g=a(h);Object.assign(d,{properties:{...r(d.properties),...r(g.properties)},required:we([...d.required??[],...g.required??[]])}),!d.description&&g.description&&(d.description=g.description),d.default===void 0&&g.default!==void 0&&(d.default=g.default),!d.type&&g.type&&(d.type=g.type)}return d},p=i=>{const{$ref:d,...h}=i;return h},u=(i,d)=>{let h=a(i);for(const g of d){if(!h)return null;if(/^\d+$/.test(g)){const k=Array.isArray(h.items)?h.items[Number(g)]:h.items;h=k?a(k):null;continue}const N=h.properties;if(N&&!o.has(g)&&g in N){h=a(N[g]);continue}const b=h.additionalProperties;if(b&&typeof b=="object"){h=a(b);continue}return null}return h},c=(i,d,h)=>{if(!i)return null;const g={};if(i.description&&(g.description=i.description),i.type&&(g.type=i.type),i.default!==void 0&&(g.default=i.default),i.enum&&(g.enum=i.enum),i.const!==void 0&&(g.const=i.const),i.deprecated&&(g.deprecated=!0),i.examples&&(g.examples=i.examples),i.properties&&(g.knownChildren=Object.keys(i.properties)),h&&(d!=null&&d.includes(h))&&(g.required=!0),i.items&&!Array.isArray(i.items)){const N=a(i.items),b=c(N,void 0,null);b&&(g.itemsInfo=b)}return(i.additionalProperties===!0||typeof i.additionalProperties=="object")&&(g.open=!0),g},x=i=>d=>{if(d.length===0)return c(a(i),void 0,null);const h=u(i,d.slice(0,-1));if(!h)return null;const g=d[d.length-1],N=u(h,[g]);return c(N,h.required,g)},v=i=>{const d=a(i);return Object.keys(d.properties??{})},f=i=>({at:x(i),rootKeys:()=>v(i),rootedAt:d=>{const h=u(i,d);return f(h??{})}});return f(s)}function we(t){return Array.from(new Set(t))}let D=null;function X(){return D||(D=ke(Q)),D}const Ne=["allow","deny","ask"],J="This settings file has invalid JSON. Fix it in the Settings raw editor first; Permissions will not overwrite it.";function Se(t){if(t.trim()==="")return{perms:{},full:{},err:null};try{const s=JSON.parse(t);if(s===null||typeof s!="object"||Array.isArray(s))return{perms:{},full:{},err:"settings file is not a JSON object"};const n=s;return{perms:n.permissions??{},full:n,err:null}}catch(s){return{perms:{},full:{},err:s.message}}}function Ce({scope:t="user"}={}){const s=L(),n=V(),a=(n==null?void 0:n.cwd)??null,o=z(i=>i.navFace),[r,l]=j.useState("rules");j.useEffect(()=>{o==="project"&&r==="presets"&&l("rules")},[o,r]);const u=H(ce,s,a)[t]??null,c=T(i=>i.files),x=e.jsx(U,{options:[{key:"rules",label:"Rules"},...o==="home"?[{key:"presets",label:"Presets"}]:[]],active:r,onChange:l});if(!s)return e.jsx(C,{title:"loading…"});if(r==="presets")return e.jsx(F,{toolbar:x,children:e.jsx(be,{})});const v=i=>i!=="user"&&!a,f=u?c[u]:null;return e.jsx(F,{toolbar:e.jsxs(e.Fragment,{children:[x,e.jsx("span",{className:"ml-3 text-fg-faint truncate",children:u??"—"}),e.jsx("div",{className:"flex-1"}),e.jsx("a",{href:"https://code.claude.com/docs/en/settings#permissions",target:"_blank",rel:"noreferrer",className:"text-fg-faint hover:text-fg-dim underline-offset-2 hover:underline",children:"rule syntax ↗"})]}),children:v(t)?e.jsx(C,{title:"no active project",hint:"open a tab in a project directory to edit project or local permissions"}):u&&f?e.jsx(ee,{scope:t,cwd:a,activePath:u}):e.jsx(C,{title:"resolving…"})})}j.memo(Ce);function ee({scope:t,cwd:s,activePath:n}){const a=T(c=>c.files[n]),{perms:o,err:r}=a?Se(a.draftRaw):{perms:{},err:null},l=(c,x)=>{if(r){A.error(J);return}window.api.claudeConfig.patch({fileId:"settings",scope:t,cwd:s,keyPath:["permissions",c],value:x}).catch(v=>A.error(v instanceof Error?v.message:String(v)))},p=(c,x)=>{const v=x.trim();if(!v)return;const f=o[c]??[];f.includes(v)||l(c,[...f,v])},u=(c,x)=>{const v=o[c]??[];l(c,v.filter((f,i)=>i!==x))};return e.jsxs("div",{className:"p-4 space-y-5 max-w-3xl",children:[r&&e.jsxs("div",{role:"alert",className:"text-xs text-red-400 border border-red-400/40 rounded px-3 py-2",children:[J," (",r,")"]}),e.jsx(_e,{value:o.defaultMode??"default",onChange:c=>l("defaultMode",c)}),Ne.map(c=>e.jsx(Ee,{list:c,rules:o[c]??[],disabled:!!r,onAdd:x=>p(c,x),onRemove:x=>u(c,x)},c)),e.jsx(Pe,{dirs:o.additionalDirectories??[],disabled:!!r,onChange:c=>l("additionalDirectories",c)})]})}function _e({value:t,onChange:s}){var r;const a=(((r=X().at(["permissions","defaultMode"]))==null?void 0:r.enum)??[]).filter(l=>typeof l=="string"),o=t&&!a.includes(t)?[...a,t]:a;return e.jsxs("section",{children:[e.jsx("h3",{className:"text-xs text-fg uppercase tracking-wider mb-2",children:"Default Mode"}),e.jsx("div",{className:"inline-flex rounded border border-line overflow-hidden",children:o.map(l=>e.jsx("button",{onClick:()=>s(l),className:`px-2.5 py-1 text-xs transition-colors ${t===l?"bg-bg-hi text-fg":"bg-bg-elev text-fg-dim hover:text-fg hover:bg-bg-hi"}`,children:l},l))})]})}function Ee({list:t,rules:s,onAdd:n,onRemove:a,disabled:o}){const[r,l]=j.useState(""),p=t==="allow"?"text-green-400":t==="deny"?"text-red-400":"text-yellow-400";return e.jsxs("section",{children:[e.jsx("h3",{className:`text-xs uppercase tracking-wider mb-2 ${p}`,children:t}),e.jsxs("div",{className:"flex gap-2 mb-2",children:[e.jsx("input",{value:r,disabled:o,onChange:u=>l(u.target.value),onKeyDown:u=>{u.key==="Enter"&&(n(r),l(""))},placeholder:t==="allow"?"e.g. Bash(ls:*) or Read(~/.claude/**)":"e.g. Write(/etc/**)",className:"flex-1 bg-bg-elev border border-line rounded px-2 py-1 text-xs text-fg placeholder-fg-faint"}),e.jsx("button",{onClick:()=>{n(r),l("")},disabled:o||!r.trim(),className:"px-2.5 py-1 border border-line rounded text-xs text-fg-dim hover:text-fg hover:bg-bg-hi disabled:opacity-40",children:"add"})]}),s.length===0?e.jsx("div",{className:"text-fg-faint text-xs",children:"no rules"}):e.jsx("ul",{className:"space-y-0.5",children:s.map((u,c)=>e.jsxs("li",{className:"flex items-center gap-2 text-xs font-mono bg-bg-elev border border-line rounded px-2 py-1",children:[e.jsx("span",{className:"flex-1 text-fg-dim truncate",children:u}),e.jsx("button",{onClick:()=>a(c),className:"text-fg-faint hover:text-red-400",title:"remove",children:"×"})]},`${c}-${u}`))})]})}function Pe({dirs:t,onChange:s,disabled:n}){const[a,o]=j.useState("");return e.jsxs("section",{children:[e.jsx("h3",{className:"text-xs text-fg uppercase tracking-wider mb-2",children:"Additional Directories"}),e.jsx("div",{className:"flex gap-2 mb-2",children:e.jsx("input",{value:a,disabled:n,onChange:r=>o(r.target.value),onKeyDown:r=>{r.key==="Enter"&&a.trim()&&(s([...t,a.trim()]),o(""))},placeholder:"/absolute/path/to/dir",className:"flex-1 bg-bg-elev border border-line rounded px-2 py-1 text-xs text-fg placeholder-fg-faint"})}),e.jsx("ul",{className:"space-y-0.5",children:t.map((r,l)=>e.jsxs("li",{className:"flex items-center gap-2 text-xs font-mono bg-bg-elev border border-line rounded px-2 py-1",children:[e.jsx("span",{className:"flex-1 text-fg-dim truncate",children:r}),e.jsx("button",{onClick:()=>s(t.filter((p,u)=>u!==l)),className:"text-fg-faint hover:text-red-400",children:"×"})]},`${l}-${r}`))})]})}const Te={UserPromptSubmit:{when:"Fires just before the user prompt is sent to the model.",payload:"{ prompt: string }",example:"Block submission if the prompt mentions a secret."},UserPromptExpansion:{when:"Fires when a slash command expands into its final prompt text.",payload:"{ command: string, expanded: string }",example:"Audit which slash commands actually run, post-expansion."},PreToolUse:{when:"Fires before any tool runs. Can block the call.",payload:"{ tool_name: string, tool_input: object }",example:'matcher="Bash" — block dangerous shell commands.'},PostToolUse:{when:"Fires after a tool completes successfully.",payload:"{ tool_name: string, tool_input: object, tool_result: string }",example:'matcher="Write|Edit" — run a linter on changed files.'},PostToolUseFailure:{when:"Fires after a tool errors out (non-zero exit, exception, or refusal).",payload:"{ tool_name: string, tool_input: object, error: string }",example:"Pipe failed Bash runs into a desktop notification."},PostToolBatch:{when:"Fires once after a parallel batch of tool calls all complete.",payload:"{ tool_uses: Array<{ tool_name, tool_input, tool_result? }> }",example:"Aggregate file-edit batches into a single commit message."},Stop:{when:"Fires when the model emits end_turn.",payload:"{ stop_reason: string, output_tokens: number }",example:"Play a chime when the agent finishes a long task."},StopFailure:{when:"Fires when a turn aborts without end_turn (rate-limit, network, OOM).",payload:'{ reason: "rate_limit"|"network"|"oom"|"killed"|string }',example:"Auto-resume on transient failures."},SessionStart:{when:"Fires once when a session boots (claude or claude -p).",payload:'{ source: "startup"|"resume", model: string, agent_type: string }',example:"Inject a project-specific system prompt addendum."},SessionEnd:{when:"Fires once when the session terminates.",payload:'{ reason: "user_quit"|"timeout"|"error"|string }',example:"Persist transcript summary to ~/.claude/projects/<>."},Setup:{when:"Fires during interactive setup (claude /setup, /init).",payload:'{ mode: "init"|"reconfigure"|string }'},PreCompact:{when:"Fires before transcript compaction runs.",payload:'{ transcript_path: string, trigger: "manual"|"auto" }',example:"Snapshot the pre-compact transcript for later diffing."},PostCompact:{when:"Fires after compaction; the active transcript is the compacted one.",payload:'{ transcript_path: string, trigger: "manual"|"auto" }'},InstructionsLoaded:{when:"Fires after CLAUDE.md and any imported memory files are loaded.",payload:'{ source: "session_start"|"reload" }'},Notification:{when:"Fires when Claude Code emits a desktop notification.",payload:"{ title: string, message: string }",example:"Forward to your own notify-send / osascript pipeline."},PermissionRequest:{when:"Fires when a tool needs user permission (per the permissions block).",payload:"{ tool_name: string, tool_input?: object }",example:"Auto-allow npm test invocations."},PermissionDenied:{when:"Fires when the user (or policy) denies a permission request.",payload:"{ tool_name: string, retry: boolean }",example:"Track which tools the user habitually rejects."},SubagentStart:{when:"Fires when a subagent (Task tool) spawns.",payload:"{ agent_type: string }",example:'matcher="security-reviewer" — log every security scan.'},SubagentStop:{when:"Fires when a subagent finishes.",payload:'{ agent_type: string, reason: "end_turn"|"error"|string }'},TeammateIdle:{when:"Fires when a teammate agent goes idle (waiting for input).",payload:"{ teammate_id?: string }"},TaskCreated:{when:"Fires when a new Task is created via the Task tool.",payload:"{ task: { description: string, ...} }",example:"Track each spawned task in an external queue."},TaskCompleted:{when:"Fires when a Task completes (success or failure).",payload:"{ task: { description: string, ...} }"},ConfigChange:{when:"Fires when settings.json (any scope) is mutated mid-session.",payload:'{ source: "user_settings"|"project_settings"|"local_settings" }',example:"Reload tooling that depends on env vars on config change."},CwdChanged:{when:"Fires when the working directory changes (e.g. agent cd-ing).",payload:"{ old_cwd: string, new_cwd: string }",example:"Refresh project-scoped indexers when cwd drifts."},FileChanged:{when:"Fires when a watched file outside Claude Code's edits changes.",payload:'{ file_path: string, change_type: "modified"|"created"|"deleted" }',example:"Re-run typecheck when any .ts file changes."},WorktreeCreate:{when:"Fires after a git worktree is created via /worktree or subagent isolation.",payload:"{ worktree_path?: string, branch?: string }"},WorktreeRemove:{when:"Fires after a git worktree is removed.",payload:"{ worktree_path?: string }"},Elicitation:{when:"Fires when Claude asks the user a multiple-choice question.",payload:'{ action: "accept"|"reject", ...}'},ElicitationResult:{when:"Fires after the user resolves an elicitation prompt.",payload:"{ choice?: string }"}},te=["UserPromptSubmit","UserPromptExpansion","PreToolUse","PostToolUse","PostToolUseFailure","PostToolBatch","Stop","StopFailure","SessionStart","SessionEnd","Setup","PreCompact","PostCompact","InstructionsLoaded","Notification","PermissionRequest","PermissionDenied","SubagentStart","SubagentStop","TeammateIdle","TaskCreated","TaskCompleted","ConfigChange","CwdChanged","FileChanged","WorktreeCreate","WorktreeRemove","Elicitation","ElicitationResult"],Fe=new Set(te),Oe=["command","http","prompt","agent","mcp_tool"],Ae={UserPromptSubmit:{prompt:"hello"},UserPromptExpansion:{command:"/example",expanded:"hello"},PreToolUse:{tool_name:"Bash",tool_input:{command:"ls"}},PostToolUse:{tool_name:"Bash",tool_input:{command:"ls"},tool_result:""},PostToolUseFailure:{tool_name:"Bash",tool_input:{command:"ls"},error:""},PostToolBatch:{tool_uses:[]},Stop:{stop_reason:"end_turn",output_tokens:0},StopFailure:{reason:"rate_limit"},SessionStart:{source:"startup",model:"",agent_type:""},SessionEnd:{reason:"user_quit"},Setup:{mode:"init"},PreCompact:{transcript_path:"",trigger:"manual"},PostCompact:{transcript_path:"",trigger:"manual"},InstructionsLoaded:{source:"session_start"},Notification:{title:"test",message:"test notification"},PermissionRequest:{tool_name:"Bash"},PermissionDenied:{tool_name:"Bash",retry:!1},SubagentStart:{agent_type:"general-purpose"},SubagentStop:{agent_type:"general-purpose",reason:"end_turn"},TeammateIdle:{},TaskCreated:{task:{description:""}},TaskCompleted:{task:{description:""}},ConfigChange:{source:"user_settings"},CwdChanged:{old_cwd:"",new_cwd:""},FileChanged:{file_path:"",change_type:"modified"},WorktreeCreate:{},WorktreeRemove:{},Elicitation:{action:"accept"},ElicitationResult:{}},K="This settings file has invalid JSON. Fix it in the Settings raw editor first; Hooks will not overwrite it.";function Re(t){if(t.trim()==="")return{full:{},hooks:{},err:null};try{const s=JSON.parse(t);if(s===null||typeof s!="object"||Array.isArray(s))return{full:{},hooks:{},err:"settings file is not a JSON object"};const n=s;return{full:n,hooks:n.hooks??{},err:null}}catch(s){return{full:{},hooks:{},err:s.message}}}function Me(t,s){return(t[s]??[]).reduce((n,a)=>{var o;return n+(((o=a.hooks)==null?void 0:o.length)??0)},0)}function $e({scope:t="user"}={}){const s=L(),n=V(),a=(n==null?void 0:n.cwd)??null,o=z(x=>x.navFace),[r,l]=j.useState("events");j.useEffect(()=>{o==="project"&&r==="library"&&l("events")},[o,r]);const u=H(Y,s,a)[t]??null,c=e.jsx(U,{options:[{key:"events",label:"Events"},...o==="home"?[{key:"library",label:"Library"}]:[]],active:r,onChange:l});return s?r==="library"?e.jsx(F,{toolbar:c,children:e.jsx(ye,{})}):t!=="user"&&!a?e.jsx(F,{toolbar:e.jsx(e.Fragment,{children:c}),children:e.jsx(C,{title:"no active project"})}):u?e.jsx(F,{toolbar:e.jsxs(e.Fragment,{children:[c,e.jsx("span",{className:"ml-3 text-fg-faint truncate",children:u}),e.jsx("div",{className:"flex-1"}),e.jsx("a",{href:"https://code.claude.com/docs/en/hooks",target:"_blank",rel:"noreferrer",className:"text-fg-faint hover:text-fg-dim underline-offset-2 hover:underline",children:"hook reference ↗"})]}),children:e.jsx(se,{scope:t,cwd:a,path:u})}):e.jsx(C,{title:"loading…"}):e.jsx(C,{title:"loading…"})}function se({scope:t,cwd:s,path:n}){const[a,o]=j.useState("PreToolUse"),[r,l]=j.useState(null),p=(b,k)=>{window.api.claudeConfig.patch({fileId:"settings",scope:t,cwd:s,keyPath:b,value:k}).catch(m=>A.error(m instanceof Error?m.message:String(m)))},u=T(b=>b.files[n]),{hooks:c,err:x}=u?Re(u.draftRaw):{hooks:{},err:null},v=Object.keys(c).filter(b=>!Fe.has(b)),f=v.reduce((b,k)=>b+(c[k]??[]).reduce((m,y)=>{var w;return m+(((w=y.hooks)==null?void 0:w.length)??0)},0),0),i=(b,k)=>{if(x){A.error(K);return}p(["hooks",b],k)},d=c[a]??[],h=()=>{i(a,[...d,{matcher:"",hooks:[{type:"command",command:""}]}])},g=(b,k)=>{const m=d.slice();m[b]=k,i(a,m)},N=b=>{i(a,d.filter((k,m)=>m!==b))};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-col h-full",children:[x?e.jsxs("div",{role:"alert",className:"px-3 py-2 border-b border-line text-xs text-red-400",children:[K," (",x,")"]}):null,f>0?e.jsxs("div",{className:"px-3 py-2 border-b border-line text-xs bg-bg-elev text-fg-dim",children:[e.jsx("span",{className:"text-yellow-400",children:"⚠"})," ",f," hook(s) configured under unknown event names: ",e.jsx("span",{className:"font-mono text-fg",children:v.join(", ")}),e.jsx("span",{className:"text-fg-faint",children:" · these are ignored by Claude Code 2026; edit settings.json directly to remove."})]}):null,e.jsx(je,{sidebarWidth:"14rem",sidebar:e.jsx("div",{className:"py-1",children:te.map(b=>{const k=Me(c,b),m=Te[b],y=m?e.jsxs("span",{className:"block space-y-1",children:[e.jsx("span",{className:"block text-fg",children:m.when}),e.jsxs("span",{className:"block text-fg-faint font-mono",children:["payload: ",m.payload]}),m.example?e.jsxs("span",{className:"block text-fg-faint italic",children:["e.g. ",m.example]}):null]}):e.jsx("span",{className:"text-fg-faint italic",children:"no documentation yet"});return e.jsx("div",{className:"[&>span]:w-full",children:e.jsx(de,{content:y,align:"bottom-center",children:e.jsxs("button",{onClick:()=>o(b),title:m==null?void 0:m.when,className:`w-full text-left px-3 py-1 text-xs ${a===b?"bg-bg-hi text-fg":"text-fg-dim hover:text-fg hover:bg-bg-hi"}`,children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"truncate",children:b}),k>0&&e.jsx("span",{className:"text-accent shrink-0 ml-2",children:k})]}),m?e.jsx("span",{className:"block text-[11px] leading-[1.3] text-fg-faint/80 font-normal truncate",children:m.when}):e.jsx("span",{className:"block text-[11px] leading-[1.3] text-fg-faint/80 italic font-normal truncate",children:"no documentation yet"})]})})},b)})}),detail:e.jsxs("div",{className:"p-4 space-y-3 max-w-3xl",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-xs uppercase tracking-wider text-fg",children:a}),e.jsx("button",{onClick:h,disabled:!!x,className:"px-2 py-0.5 text-xs border border-line rounded text-fg-dim hover:text-fg hover:bg-bg-hi disabled:opacity-40 disabled:cursor-not-allowed",children:"+ add group"})]}),d.length===0?e.jsx("div",{className:"text-fg-faint text-xs",children:"no hooks for this event"}):d.map((b,k)=>e.jsx(Ie,{group:b,jsonInvalid:!!x,onChange:m=>g(k,m),onRemove:()=>N(k),onTestFire:m=>l({event:a,matcher:b.matcher??"",command:m.command??""})},k))]})})]}),r?e.jsx(Be,{event:r.event,matcher:r.matcher,command:r.command,onClose:()=>l(null)}):null]})}j.memo($e);function M({value:t,onCommit:s,onDraft:n,...a}){const[o,r]=j.useState(t);j.useEffect(()=>r(t),[t]);const l=()=>{o!==t&&s(o)};return e.jsx("input",{...a,value:o,onChange:p=>{r(p.target.value),n==null||n(p.target.value)},onBlur:l,onKeyDown:p=>{p.key==="Enter"&&l()}})}function Ie({group:t,jsonInvalid:s,onChange:n,onRemove:a,onTestFire:o}){const r=()=>n({...t,hooks:[...t.hooks??[],{type:"command",command:""}]}),l=(u,c)=>{const x=t.hooks.slice();x[u]=c,n({...t,hooks:x})},p=u=>n({...t,hooks:t.hooks.filter((c,x)=>x!==u)});return e.jsxs("div",{className:"border border-line rounded p-3 bg-bg-elev space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-fg-faint w-16",children:"matcher"}),e.jsx(M,{value:t.matcher??"",disabled:s,onCommit:u=>n({...t,matcher:u}),placeholder:"tool name regex or exact match (optional)",className:"flex-1 bg-bg border border-line rounded px-2 py-0.5 text-xs text-fg font-mono"}),e.jsx("button",{onClick:a,disabled:s,className:"text-fg-faint hover:text-red-400 text-xs disabled:opacity-40",title:"remove group",children:"× group"})]}),(t.hooks??[]).map((u,c)=>e.jsx(Le,{rule:u,jsonInvalid:s,onChange:x=>l(c,x),onRemove:()=>p(c),onTestFire:()=>o(u)},c)),e.jsx("button",{onClick:r,disabled:s,className:"text-xs text-fg-faint hover:text-fg disabled:opacity-40",children:"+ add hook"})]})}function De(t){var n,a,o;const s=((a=(n=Q.$defs)==null?void 0:n.hookCommand)==null?void 0:a.anyOf)??[];for(const r of s){const l=r.properties;if(((o=l==null?void 0:l.type)==null?void 0:o.const)!==t)continue;const p=l.timeout;if(typeof(p==null?void 0:p.default)=="number")return p.default;const u=/default:\s*(\d+)/.exec((p==null?void 0:p.description)??"");return u?Number(u[1]):null}return null}function G(t){return/^\d+$/.test(t.trim())&&Number(t)>0?Number(t):null}function Le({rule:t,jsonInvalid:s,onChange:n,onRemove:a,onTestFire:o}){const r=i=>({command:"e.g. node ./scripts/lint.js $FILE",http:"e.g. https://hooks.example.com/notify",prompt:"e.g. Review this change for security issues",agent:"e.g. security-reviewer",mcp_tool:"e.g. mcp__server__tool"})[i],l=t.type==="command"?"command":t.type==="http"?"url":t.type==="prompt"?"prompt":t.type==="mcp_tool"?"mcpTool":"agent",p=t[l]??"",u=(t.args??[]).join(" "),[c,x]=j.useState(null),v=De(t.type),f={type:"hook",name:p||t.type,command:t.type==="command"?t.command:void 0,url:t.type==="http"?t.url:void 0};return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("select",{value:t.type,disabled:s,onChange:i=>n({type:i.target.value}),className:"bg-bg border border-line rounded px-1 py-0.5 text-xs text-fg",children:Oe.map(i=>e.jsx("option",{value:i,children:i},i))}),e.jsx(ve,{interactive:!1,input:f}),e.jsx(M,{value:p,disabled:s,onCommit:i=>n({...t,[l]:i}),placeholder:r(t.type),className:`flex-1 bg-bg border rounded px-2 py-0.5 text-xs text-fg font-mono ${s?"border-red-500/70":p.trim()?"border-line":"border-yellow-600/50"}`}),s?e.jsx("span",{className:"text-red-400 text-xs",title:"The enclosing settings.json is malformed; fix the JSON before editing.",children:"× invalid"}):null,e.jsx(M,{value:t.timeout!=null?String(t.timeout):"",disabled:s,"aria-label":"timeout (seconds)","aria-invalid":c?!0:void 0,title:c??"Timeout in seconds",onDraft:i=>{x(!i.trim()||G(i)!=null?null:"Timeout must be a positive whole number of seconds")},onCommit:i=>{if(!i.trim()){n({...t,timeout:void 0});return}const d=G(i);d!=null&&n({...t,timeout:d})},placeholder:v!=null?`${v} (seconds)`:"seconds",className:`w-24 bg-bg border rounded px-2 py-0.5 text-xs text-fg ${c?"border-red-500/70":"border-line"}`}),c?e.jsx("span",{role:"alert",className:"text-red-400 text-xs",children:c}):null,t.type==="command"?e.jsx("button",{onClick:o,disabled:s||!p.trim(),className:"px-2 py-0.5 text-xs border border-line rounded text-fg-dim hover:text-fg hover:bg-bg-hi disabled:opacity-40 disabled:cursor-not-allowed",title:"Run this command with a fake event payload",children:"test fire"}):null,e.jsx("button",{onClick:a,disabled:s,className:"text-fg-faint hover:text-red-400 text-xs disabled:opacity-40",children:"×"})]}),t.type==="command"?e.jsxs("div",{className:"flex items-center gap-2 pl-[3.75rem]",children:[e.jsx("span",{className:"text-xs text-fg-faint w-12",children:"args"}),e.jsx(M,{value:u,disabled:s,onCommit:i=>n({...t,args:i.trim()?i.split(/\s+/).filter(Boolean):void 0}),placeholder:"argv array (v2.1.139+ exec form, no shell)",className:"flex-1 bg-bg border border-line rounded px-2 py-0.5 text-xs text-fg font-mono"})]}):null,e.jsxs("div",{className:"flex items-center gap-2 pl-[3.75rem]",children:[e.jsx("span",{className:"text-xs text-fg-faint w-12",children:"term"}),e.jsx(M,{value:t.terminalSequence??"",disabled:s,onCommit:i=>n({...t,terminalSequence:i||void 0}),placeholder:"terminalSequence — e.g. \\\\a (bell), v2.1.141+",className:"flex-1 bg-bg border border-line rounded px-2 py-0.5 text-xs text-fg font-mono"})]})]})}function He(t){return JSON.stringify(Ae[t]??{},null,2)}function Ue(t,s){if(!t.trim())return{matched:!0,target:null,note:"empty matcher → matches all"};const n=s&&typeof s=="object"&&"tool_name"in s?String(s.tool_name??""):null;if(n==null)return{matched:!1,target:null,note:"payload has no tool_name to match against"};try{return{matched:new RegExp(`^(?:${t})$`).test(n),target:n}}catch{return{matched:t===n,target:n,note:"matcher not valid regex; fell back to exact match"}}}function Be({event:t,matcher:s,command:n,onClose:a}){const[o,r]=j.useState(()=>He(t)),[l,p]=j.useState(!1),[u,c]=j.useState(null),[x,v]=j.useState(null);let f=null;try{JSON.parse(o)}catch(d){f=d.message}const i=async()=>{p(!0),c(null);let d=null;try{d=JSON.parse(o)}catch{}v(Ue(s,d));try{const h=await window.api.app.testFireHook({command:n,payload:o,timeoutMs:5e3});c(h)}finally{p(!1)}};return e.jsx(ue,{open:!0,onClose:a,title:`Test fire — ${t}`,children:e.jsxs("div",{className:"space-y-3 text-xs",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-fg-faint mb-1",children:"resolved command"}),e.jsx("div",{className:"font-mono text-fg bg-bg border border-line rounded px-2 py-1 break-all",children:n})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-fg-faint mb-1",children:"matcher"}),e.jsx("div",{className:"font-mono text-fg bg-bg border border-line rounded px-2 py-1",children:s||e.jsx("span",{className:"text-fg-faint",children:"(empty — matches all)"})})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("span",{className:"text-fg-faint",children:"fake event payload (stdin)"}),f?e.jsxs("span",{className:"text-red-400",children:["× ",f]}):null]}),e.jsx("textarea",{value:o,onChange:d=>r(d.target.value),rows:8,className:`w-full bg-bg border rounded px-2 py-1 font-mono text-fg ${f?"border-red-500/70":"border-line"}`})]}),x?e.jsxs("div",{children:[e.jsx("div",{className:"text-fg-faint mb-1",children:"matcher result"}),e.jsxs("div",{className:"font-mono",children:[e.jsx("span",{className:x.matched?"text-green-400":"text-red-400",children:x.matched?"✓ match":"✗ no match"}),x.target!=null?e.jsxs("span",{className:"text-fg-dim",children:[' · target tool_name="',x.target,'"']}):null,x.note?e.jsx("div",{className:"text-fg-faint",children:x.note}):null]})]}):null,u?e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"text-fg-faint",children:["exit ",u.exitCode," · ",u.durationMs,"ms"]}),u.stdout?e.jsxs("div",{children:[e.jsx("div",{className:"text-fg-faint",children:"stdout"}),e.jsx("pre",{className:"bg-bg border border-line rounded p-2 font-mono text-fg whitespace-pre-wrap break-all max-h-40 overflow-auto",children:u.stdout})]}):null,u.stderr?e.jsxs("div",{children:[e.jsx("div",{className:"text-fg-faint",children:"stderr"}),e.jsx("pre",{className:"bg-bg border border-line rounded p-2 font-mono text-red-300 whitespace-pre-wrap break-all max-h-40 overflow-auto",children:u.stderr})]}):null]}):null,e.jsxs("div",{className:"flex items-center justify-end gap-2 pt-1",children:[e.jsx("button",{onClick:a,className:"px-2 py-0.5 text-xs border border-line rounded text-fg-dim hover:text-fg hover:bg-bg-hi",children:"close"}),e.jsx("button",{onClick:i,disabled:l||!!f||!n.trim(),className:"px-2 py-0.5 text-xs border border-line rounded text-fg hover:bg-bg-hi disabled:opacity-40 disabled:cursor-not-allowed",children:l?"running…":"run"})]})]})})}const ne=[{id:"permissions",label:"Permissions",tab:"permissions",keys:["permissions"]},{id:"hooks",label:"Hooks",tab:"hooks",keys:["hooks","disableAllHooks","allowedHttpHookUrls","httpHookAllowedEnvVars"]},{id:"mcp",label:"MCP Servers",tab:null,keys:["enabledMcpjsonServers","disabledMcpjsonServers","enableAllProjectMcpServers"]},{id:"plugins",label:"Plugins",tab:null,keys:["enabledPlugins"]}],W=new Set(ne.flatMap(t=>t.keys)),Je=[{id:"essentials",title:"Essentials",summary:"The knobs you reach for first.",keys:["model","language","outputStyle"]},{id:"git",title:"Git & Commits",summary:"How Claude writes commits and pull requests on your behalf.",keys:["attribution","includeGitInstructions","includeCoAuthoredBy"]},{id:"memory",title:"Memory & Plans",summary:"Context Claude keeps between sessions and where it files plans.",keys:["autoMemoryEnabled","plansDirectory","claudeMdExcludes","respectGitignore"]},{id:"model",title:"Model & Reasoning",summary:"Model allow/override lists, reasoning depth, and fast-mode toggles — machine-wide, with no per-Epic override yet. An Epic's Agent persona model (Agent Library) still wins over Essentials' plain model default.",advanced:!0,keys:["availableModels","modelOverrides","effortLevel","fastMode","fastModePerSessionOptIn","alwaysThinkingEnabled","fallbackModel","enforceAvailableModels","teammateDefaultModel","advisorModel"]},{id:"interface",title:"Interface",summary:"Visual polish — spinners, progress bars, motion.",keys:["spinnerTipsEnabled","spinnerTipsOverride","spinnerVerbs","terminalProgressBarEnabled","showTurnDuration","prefersReducedMotion","companyAnnouncements","statusLine","teammateMode"]},{id:"updates",title:"Updates & Cleanup",summary:"Release channel and how long transcripts stick around.",keys:["autoUpdatesChannel","cleanupPeriodDays"]},{id:"env",title:"Environment & Auth",summary:"Environment variables and auth-helper scripts.",keys:["env","apiKeyHelper","awsCredentialExport","awsAuthRefresh"]},{id:"hooks",title:"Hooks",summary:"Scripts Claude runs before/after tool use.",keys:["hooks","disableAllHooks","allowedHttpHookUrls","httpHookAllowedEnvVars"]},{id:"mcp",title:"MCP Servers",summary:"External tool providers Claude can talk to.",keys:["enableAllProjectMcpServers","enabledMcpjsonServers","disabledMcpjsonServers"]},{id:"plugins",title:"Plugins",summary:"Installed plugins, marketplaces, and per-plugin configuration.",keys:["enabledPlugins","extraKnownMarketplaces","skippedPlugins","skippedMarketplaces","pluginConfigs"]},{id:"filesystem",title:"File Picker & Sandbox",summary:"How Claude browses files and the sandbox it runs in.",keys:["fileSuggestion","sandbox","worktree"]},{id:"login",title:"Login",summary:"Which login method to force on startup.",keys:["forceLoginMethod","forceLoginOrgUUID"]},{id:"feedback",title:"Feedback",summary:"Session-quality surveys.",keys:["feedbackSurveyRate"]},{id:"advanced",title:"Advanced / Enterprise",summary:"Managed-settings-only keys and enterprise allow/denylists.",advanced:!0,keys:["allowedMcpServers","deniedMcpServers","allowManagedHooksOnly","allowManagedPermissionRulesOnly","allowManagedMcpServersOnly","strictKnownMarketplaces","blockedMarketplaces","pluginTrustMessage","otelHeadersHelper","skipWebFetchPreflight"]}],Ke={mcp:"MCP",url:"URL",urls:"URLs",http:"HTTP",ui:"UI",id:"ID",uuid:"UUID",api:"API",aws:"AWS",otel:"OTel",json:"JSON"};function re(t){return t.replace(/^\$/,"").replace(/([a-z])([A-Z])/g,"$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g,"$1 $2").toLowerCase().split(/\s+/).filter(Boolean).map((a,o)=>{const r=Ke[a];return r||(o===0?a.charAt(0).toUpperCase()+a.slice(1):a)}).join(" ")}function ae(t){const s=new Set,n=[];for(const o of Je){const r=o.keys.filter(l=>t.has(l)&&!W.has(l));r.forEach(l=>s.add(l)),r.length!==0&&n.push({id:o.id,title:o.title,summary:o.summary,advanced:!!o.advanced,keys:r})}const a=Array.from(t).filter(o=>!s.has(o)&&o!=="$schema"&&!W.has(o)).sort();return a.length>0&&n.push({id:"other",title:"Other",summary:"Keys not yet grouped.",advanced:!1,keys:a}),n}function Ge(t,s){return ae(t).map(n=>({id:n.id,title:n.title,advanced:n.advanced,total:n.keys.length,setCount:n.keys.filter(a=>s.has(a)).length}))}const We={};function oe(t,s){if(s)return{text:s,authored:!1};const n=We[t];return n?{text:n,authored:!0}:null}const qe={essentials:"star",git:"link",memory:"memory",model:"sparkle",interface:"eye",updates:"reload",env:"keys",hooks:"hooks",mcp:"mcp",plugins:"plugins",filesystem:"folder",login:"lock",feedback:"send",advanced:"shield",other:"dot"},Ve=["user","project","local","default"],ze={user:"user",project:"project",local:"local",default:"default"};function Ye({node:t,targetScope:s,onOverride:n,schema:a}){const[o,r]=j.useState(""),[l,p]=j.useState(!1),[u,c]=j.useState(!0),x=t.kind==="object"?t:null,v=x?Object.keys(x.children):[],f=a.rootKeys(),i=new Set([...v,...f]),d=j.useMemo(()=>ae(i),[Array.from(i).sort().join(",")]),h=j.useMemo(()=>Ge(i,new Set(v)),[Array.from(i).sort().join(","),v.join(",")]),[g,N]=j.useState(null),b=j.useRef(null),k=y=>{const w=d.find(_=>_.id===y);w!=null&&w.advanced&&!l&&p(!0),N(y)};j.useEffect(()=>{if(!g)return;N(null);const y=b.current,w=document.getElementById(`settings-group-${g}`);if(!y||!w)return;const _=w.getBoundingClientRect().top-y.getBoundingClientRect().top;y.scrollBy({top:_,behavior:"smooth"})},[g]);const m=j.useMemo(()=>d.filter(y=>l||!y.advanced).map(y=>({...y,keys:y.keys.filter(w=>{const _=(x==null?void 0:x.children[w])!==void 0;if(!u&&!_)return!1;if(!o.trim())return!0;const E=a.at([w]);return[w,re(w),(E==null?void 0:E.description)??""].join(" ").toLowerCase().includes(o.toLowerCase())})})).filter(y=>y.keys.length>0),[d,o,l,u,x,a]);return e.jsxs("div",{className:"h-full flex flex-col",children:[e.jsxs("div",{className:"shrink-0 border-b border-line bg-bg-elev px-3 py-1.5 flex items-center gap-3 text-xs",children:[e.jsxs("span",{className:"text-fg-faint",children:["writing overrides to"," ",e.jsx("span",{className:"text-fg-dim font-medium",children:S[s].label})]}),e.jsxs("label",{className:"flex items-center gap-1 text-fg-faint cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:u,onChange:y=>c(y.target.checked),className:"accent-accent"}),"show not-yet-configured"]}),e.jsxs("label",{className:"flex items-center gap-1 text-fg-faint cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:l,onChange:y=>p(y.target.checked),className:"accent-accent"}),"show advanced"]}),e.jsx("div",{className:"flex-1"}),e.jsx("input",{value:o,onChange:y=>r(y.target.value),placeholder:"search settings…",className:"bg-bg border border-line rounded px-2 py-1 text-xs text-fg w-64"})]}),e.jsxs("div",{className:"flex-1 flex overflow-hidden",children:[e.jsx(Ze,{groups:h,onJump:k}),e.jsxs("div",{ref:b,className:"flex-1 overflow-auto py-3",children:[m.map(y=>e.jsx(Qe,{id:y.id,title:y.title,summary:y.summary,advanced:y.advanced,children:y.keys.map(w=>{const _=x==null?void 0:x.children[w],E=a.at([w]);return e.jsx(Xe,{keyName:w,node:_,info:E,targetScope:s,onOverride:(R,$)=>n([w],R,$)},w)})},y.id)),m.length===0&&e.jsxs("div",{className:"px-6 py-12 text-center text-fg-faint text-sm",children:['no settings match "',o,'"']})]})]})]})}function Ze({groups:t,onJump:s}){return e.jsx("nav",{className:"shrink-0 w-48 border-r border-line bg-bg-elev/30 overflow-y-auto py-3",children:t.map(n=>e.jsxs("button",{onClick:()=>s(n.id),className:"w-full flex items-center gap-2 px-3 py-2 text-left hover:bg-bg-hi transition-colors",title:`jump to ${n.title}`,children:[e.jsx(pe,{name:qe[n.id]??"dot",size:15,className:"text-fg-faint shrink-0"}),e.jsx("span",{className:"flex-1 min-w-0 truncate text-xs text-fg-dim",children:n.title}),e.jsxs("span",{className:"text-[10px] text-fg-faint font-mono shrink-0",children:[n.setCount,"/",n.total]})]},n.id))})}function Qe({id:t,title:s,summary:n,advanced:a,children:o}){const[r,l]=j.useState(!0);return e.jsxs("section",{id:`settings-group-${t}`,className:"mx-4 mb-4 rounded-lg border border-line shadow-sm bg-bg-elev/50 overflow-hidden",children:[e.jsxs("header",{className:"px-4 py-3 bg-bg-elev cursor-pointer hover:bg-bg-hi flex items-center gap-3 border-b border-line",onClick:()=>l(!r),children:[e.jsx("span",{className:"text-fg-faint w-3",children:r?"▾":"▸"}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h2",{className:"text-fg text-base font-semibold",children:s}),a&&e.jsx("span",{className:"text-[9px] px-1.5 py-0 rounded border border-yellow-900/40 bg-yellow-950/30 text-yellow-500/80 uppercase tracking-wide",children:"advanced"})]}),e.jsx("p",{className:"text-fg-dim text-sm mt-0.5",children:n})]})]}),r&&e.jsx("div",{className:"divide-y divide-line/60",children:o})]})}function Xe({keyName:t,node:s,info:n,targetScope:a,onOverride:o}){const[r,l]=j.useState(!1),[p,u]=j.useState(!1),c=re(t),x=s!==void 0,f=(s==null?void 0:s.kind)==="leaf"?s:null,i=(s==null?void 0:s.kind)==="object"||(s==null?void 0:s.kind)==="array",d=n==null?void 0:n.default,h=f&&d!==void 0&&le(f.value,d),g=it({isSet:x,leafNode:f,defaultVal:d,isDefault:!!h,node:s}),N=et(f,d),b=N.length>=2,k=!!f&&!h,m=oe(t,n==null?void 0:n.description);return e.jsx("div",{className:"px-4 py-3 hover:bg-bg-elev/20",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("button",{onClick:()=>l(!r),className:"text-fg-faint hover:text-fg w-3 mt-0.5",title:r?"collapse":"expand",children:r?"▾":"▸"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-baseline gap-2 flex-wrap",children:[e.jsx("h3",{className:"text-fg text-sm",children:c}),e.jsx(lt,{kind:g.kind,label:g.label}),b&&e.jsxs("button",{onClick:y=>{y.stopPropagation(),r||l(!0),u(w=>!w)},className:"text-[9px] px-1.5 py-0 rounded border border-blue-900/40 bg-blue-950/30 text-blue-300/90 uppercase tracking-wide hover:bg-blue-900/40",title:"this key is defined in multiple scopes — click to expand",children:["drift · ",N.map(y=>ze[y]).join(" · ")]}),k&&f&&e.jsx("button",{onClick:y=>{y.stopPropagation(),o(void 0,f.winner)},className:"text-[9px] px-1.5 py-0 rounded border border-line bg-bg-elev text-fg-faint uppercase tracking-wide hover:text-fg hover:bg-bg-hi",title:`reset · delete from ${S[f.winner].label}`,children:"↺ reset"}),(n==null?void 0:n.deprecated)&&e.jsx("span",{className:"text-[9px] px-1 py-0 rounded border border-yellow-900/40 bg-yellow-950/30 text-yellow-500/80 uppercase tracking-wide",children:"deprecated"}),(n==null?void 0:n.required)&&!x&&e.jsx("span",{className:"text-[9px] px-1 py-0 rounded border border-red-900/40 bg-red-950/30 text-red-400/80 uppercase tracking-wide",children:"required"})]}),m&&e.jsx("p",{className:`text-fg-dim text-xs mt-0.5 leading-relaxed ${m.authored?"inline-block border-b border-dotted border-fg-faint/70 cursor-help":""}`,title:m.authored?"In-app-authored description — not from the official Claude Code schema":void 0,children:ct(m.text)}),r&&p&&f&&e.jsx(tt,{leaf:f,defaultVal:d,onReset:y=>o(void 0,y)}),r&&e.jsx(st,{keyName:t,node:s,info:n,targetScope:a,onOverride:y=>o(y)})]}),e.jsx("div",{className:"shrink-0",children:!r&&e.jsx(ot,{node:s,info:n,onSet:y=>{o(y)},disabled:i&&x})})]})})}function et(t,s){if(!t)return[];const n=new Set;n.add(t.winner);for(const a of t.shadowed)n.add(a.scope);return s!==void 0&&n.add("default"),Ve.filter(a=>n.has(a))}function tt({leaf:t,defaultVal:s,onReset:n}){const a={};a[t.winner]={value:t.value,winner:!0};for(const o of t.shadowed)a[o.scope]={value:o.value,winner:!1};return e.jsxs("div",{className:"mt-2 border border-line rounded bg-bg-elev/40 text-xs",children:[e.jsx("div",{className:"px-2 py-1 text-fg-faint border-b border-line/60",children:"Values across all scopes (winner highlighted · reset removes that scope's value):"}),e.jsxs("div",{className:"divide-y divide-line/60",children:[["user","project","local"].map(o=>{const r=a[o],l=r!==void 0;return e.jsxs("div",{className:"grid grid-cols-[5rem_1fr_auto] gap-2 px-2 py-1 items-center",children:[e.jsx("span",{className:"text-fg-faint",children:S[o].label}),e.jsx("span",{className:`font-mono truncate ${r!=null&&r.winner?"text-accent":"text-fg-dim"}`,children:l?O(r.value):e.jsx("span",{className:"text-fg-faint",children:"—"})}),l?e.jsx("button",{onClick:()=>n(o),className:"text-[9px] px-1.5 py-0 rounded border border-line text-fg-faint uppercase tracking-wide hover:text-fg hover:bg-bg-hi",title:`delete this key from ${S[o].label}`,children:"↺"}):e.jsx("span",{})]},o)}),e.jsxs("div",{className:"grid grid-cols-[5rem_1fr_auto] gap-2 px-2 py-1 items-center",children:[e.jsx("span",{className:"text-fg-faint",children:"Default"}),e.jsx("span",{className:"font-mono text-fg-dim truncate",children:s!==void 0?O(s):e.jsx("span",{className:"text-fg-faint",children:"—"})}),e.jsx("span",{})]})]})]})}function st({keyName:t,node:s,info:n,targetScope:a,onOverride:o}){const l=(s==null?void 0:s.kind)==="leaf"?s:null,p=oe(t,n==null?void 0:n.description);return e.jsxs("div",{className:"mt-3 space-y-2 text-xs",children:[p&&e.jsx("p",{className:`text-fg-dim leading-relaxed whitespace-pre-wrap ${p.authored?"inline-block border-b border-dotted border-fg-faint/70 cursor-help":""}`,title:p.authored?"In-app-authored description — not from the official Claude Code schema":void 0,children:p.text}),e.jsxs("dl",{className:"grid grid-cols-[auto_1fr] gap-x-3 gap-y-1 text-fg-faint",children:[(n==null?void 0:n.type)&&e.jsxs(e.Fragment,{children:[e.jsx("dt",{children:"Type"}),e.jsx("dd",{className:"text-fg-dim font-mono",children:Array.isArray(n.type)?n.type.join(" | "):n.type})]}),(n==null?void 0:n.default)!==void 0&&e.jsxs(e.Fragment,{children:[e.jsx("dt",{children:"Default"}),e.jsx("dd",{className:"text-fg-dim font-mono",children:O(n.default)})]}),(n==null?void 0:n.enum)&&e.jsxs(e.Fragment,{children:[e.jsx("dt",{children:"Options"}),e.jsx("dd",{className:"text-fg-dim font-mono",children:n.enum.map(u=>String(u)).join(" | ")})]}),l&&e.jsxs(e.Fragment,{children:[e.jsx("dt",{children:"Current"}),e.jsxs("dd",{className:"font-mono",children:[e.jsx("span",{className:"text-fg-dim",children:O(l.value)}),e.jsxs("span",{className:"ml-2 text-fg-faint",children:["from ",S[l.winner].label]})]})]}),l&&l.shadowed.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("dt",{children:"Shadowed"}),e.jsx("dd",{className:"space-y-0.5",children:l.shadowed.map((u,c)=>e.jsxs("div",{className:"font-mono text-fg-faint line-through",children:[O(u.value)," —"," ",e.jsx("span",{className:"no-underline",children:S[u.scope].label})]},c))})]}),(s==null?void 0:s.kind)==="array"&&e.jsxs(e.Fragment,{children:[e.jsx("dt",{children:"Accumulated"}),e.jsxs("dd",{className:"text-fg-dim",children:[s.items.length," items across all scopes"]})]})]}),e.jsx("div",{className:"pt-2 flex items-center gap-2 flex-wrap border-t border-line/60",children:e.jsx(nt,{keyName:t,node:s,info:n,onChange:o,targetScope:a})})]})}function nt({node:t,info:s,onChange:n,targetScope:a}){const r=(t==null?void 0:t.kind)==="leaf"?t.value:s==null?void 0:s.default,l=ie(s==null?void 0:s.type);if(l==="boolean"){const p=r===!0;return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-fg-faint",children:"Set to:"}),e.jsx("div",{className:"inline-flex rounded border border-line overflow-hidden",children:[{v:!0,label:"on"},{v:!1,label:"off"}].map(({v:u,label:c})=>e.jsx("button",{onClick:()=>n(u),className:`px-3 py-0.5 text-xs transition-colors ${p===u?"bg-accent text-bg":"bg-bg-elev text-fg-dim hover:bg-bg-hi hover:text-fg"}`,children:c},c))}),e.jsxs("span",{className:"text-fg-faint",children:["→ ",S[a].label]})]})}return s!=null&&s.enum?e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"text-fg-faint",children:"Choose:"}),s.enum.map(p=>{const u=le(r,p);return e.jsx("button",{onClick:()=>n(p),className:`px-2 py-0.5 text-xs rounded border ${u?"bg-accent text-bg border-accent":"bg-bg-elev text-fg-dim border-line hover:text-fg hover:bg-bg-hi"}`,children:String(p)},String(p))}),e.jsxs("span",{className:"text-fg-faint",children:["→ ",S[a].label]})]}):l==="integer"||l==="number"?e.jsx(rt,{value:typeof r=="number"?r:void 0,integer:l==="integer",onCommit:n,target:S[a].label}):l==="string"?e.jsx(at,{value:typeof r=="string"?r:"",onCommit:n,target:S[a].label}):e.jsxs("div",{className:"text-fg-faint",children:["Complex value (",l??"object/array",") — use the"," ",e.jsx("span",{className:"text-fg-dim",children:"Raw"})," tab to edit."]})}function rt({value:t,integer:s,onCommit:n,target:a}){const[o,r]=j.useState(t!==void 0?String(t):""),l=()=>{const p=s?parseInt(o,10):parseFloat(o);Number.isNaN(p)||n(p)};return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-fg-faint",children:"Set to:"}),e.jsx("input",{type:"number",value:o,onChange:p=>r(p.target.value),onBlur:l,onKeyDown:p=>{p.key==="Enter"&&p.target.blur()},className:"w-24 bg-bg border border-line rounded px-2 py-0.5 text-xs text-fg"}),e.jsxs("button",{onClick:l,className:"px-2 py-0.5 text-xs border border-accent/50 rounded text-accent hover:bg-accent hover:text-bg",children:["save → ",a]})]})}function at({value:t,onCommit:s,target:n}){const[a,o]=j.useState(t);return e.jsxs("div",{className:"flex items-center gap-2 flex-1 min-w-0",children:[e.jsx("span",{className:"text-fg-faint shrink-0",children:"Set to:"}),e.jsx("input",{type:"text",value:a,onChange:r=>o(r.target.value),onKeyDown:r=>{r.key==="Enter"&&s(a)},className:"flex-1 min-w-0 bg-bg border border-line rounded px-2 py-0.5 text-xs text-fg"}),e.jsxs("button",{onClick:()=>s(a),className:"shrink-0 px-2 py-0.5 text-xs border border-accent/50 rounded text-accent hover:bg-accent hover:text-bg",children:["save → ",n]})]})}function ot({node:t,info:s,onSet:n,disabled:a}){const o=(t==null?void 0:t.kind)==="leaf",r=ie(s==null?void 0:s.type);if(a)return null;if(r==="boolean"){const l=o&&t.value===!0;return e.jsx("button",{onClick:()=>n(!l),className:`px-2.5 py-0.5 text-xs rounded border transition-colors ${l?"bg-accent/15 text-accent border-accent/40 hover:bg-accent hover:text-bg":"bg-bg-elev text-fg-dim border-line hover:text-fg hover:bg-bg-hi"}`,title:"toggle",children:l?"on":"off"})}return null}function it({isSet:t,leafNode:s,defaultVal:n,isDefault:a,node:o}){return t?(o==null?void 0:o.kind)==="array"?{kind:"accumulated",label:`${o.items.length} items`}:(o==null?void 0:o.kind)==="object"?{kind:"set",label:"configured"}:s?a?{kind:"default",label:`= default · ${S[s.winner].label}`}:s.shadowed.length>0?{kind:"override",label:`overriding ${s.shadowed.length} scope(s)`}:{kind:"set",label:`set in ${S[s.winner].label}`}:{kind:"set",label:"configured"}:n!==void 0?{kind:"default",label:`using default: ${O(n)}`}:{kind:"unset",label:"not configured"}}function lt({kind:t,label:s}){const n={set:"bg-accent/15 text-accent border-accent/30",default:"bg-bg-hi text-fg-dim border-line",unset:"bg-bg-elev text-fg-faint border-line",override:"bg-purple-950/30 text-purple-400/80 border-purple-900/40",accumulated:"bg-blue-950/30 text-blue-400/80 border-blue-900/40"}[t];return e.jsx("span",{className:`text-[9px] px-1.5 py-0 rounded border uppercase tracking-wide ${n}`,children:s})}function ie(t){if(t)return Array.isArray(t)?t.find(n=>n!=="null")??t[0]:t}function le(t,s){return t===s?!0:typeof t!=typeof s?!1:t&&s&&typeof t=="object"?JSON.stringify(t)===JSON.stringify(s):!1}function ct(t){const s=t.trim().split(`
|
|
1
|
+
import{b3 as T,at as e,a$ as A,aJ as j,b9 as L,b0 as V,bb as z,bi as H,P as ce,l as C,a3 as de,v as ue,Q as Y,S,a as pe,bk as B,be as me,ax as xe,aB as he,J as fe,ap as ge}from"./index-CuAfFXNd.js";import{P as F}from"./Panel-B-3NWUlv.js";import{P as be,H as ye,S as Z}from"./Library-C5wKMTSn.js";import{S as I}from"./SourceChip-DcBNYYhe.js";import{V as U}from"./ViewTabs-DFXH03tb.js";import{r as Q}from"./claude-settings-schema-COigsajx.js";import{L as je}from"./ListDetail-DDQ1S0yu.js";import{P as ve}from"./ProvenanceBadge-CUChwz4Z.js";import"./monaco-editor-BsIlgG7c.js";import"./Button-DSoqrxCB.js";function ke(t){const s=t??{},n={...s.$defs??{},...s.definitions??{}},a=i=>{if(!i)return{};if(!i.$ref)return l(i);const d=/^#\/(\$defs|definitions)\/(.+)$/.exec(i.$ref);if(!d)return l(i);const h=n[d[2]];return h?a({...h,...p(i)}):l(i)},o=new Set(["__proto__","constructor","prototype"]),r=i=>{if(!i)return{};const d={};for(const[h,g]of Object.entries(i))o.has(h)||(d[h]=g);return d},l=i=>{if(!i.allOf||i.allOf.length===0)return i;const d={...i};delete d.allOf;for(const h of i.allOf){const g=a(h);Object.assign(d,{properties:{...r(d.properties),...r(g.properties)},required:we([...d.required??[],...g.required??[]])}),!d.description&&g.description&&(d.description=g.description),d.default===void 0&&g.default!==void 0&&(d.default=g.default),!d.type&&g.type&&(d.type=g.type)}return d},p=i=>{const{$ref:d,...h}=i;return h},u=(i,d)=>{let h=a(i);for(const g of d){if(!h)return null;if(/^\d+$/.test(g)){const k=Array.isArray(h.items)?h.items[Number(g)]:h.items;h=k?a(k):null;continue}const N=h.properties;if(N&&!o.has(g)&&g in N){h=a(N[g]);continue}const b=h.additionalProperties;if(b&&typeof b=="object"){h=a(b);continue}return null}return h},c=(i,d,h)=>{if(!i)return null;const g={};if(i.description&&(g.description=i.description),i.type&&(g.type=i.type),i.default!==void 0&&(g.default=i.default),i.enum&&(g.enum=i.enum),i.const!==void 0&&(g.const=i.const),i.deprecated&&(g.deprecated=!0),i.examples&&(g.examples=i.examples),i.properties&&(g.knownChildren=Object.keys(i.properties)),h&&(d!=null&&d.includes(h))&&(g.required=!0),i.items&&!Array.isArray(i.items)){const N=a(i.items),b=c(N,void 0,null);b&&(g.itemsInfo=b)}return(i.additionalProperties===!0||typeof i.additionalProperties=="object")&&(g.open=!0),g},x=i=>d=>{if(d.length===0)return c(a(i),void 0,null);const h=u(i,d.slice(0,-1));if(!h)return null;const g=d[d.length-1],N=u(h,[g]);return c(N,h.required,g)},v=i=>{const d=a(i);return Object.keys(d.properties??{})},f=i=>({at:x(i),rootKeys:()=>v(i),rootedAt:d=>{const h=u(i,d);return f(h??{})}});return f(s)}function we(t){return Array.from(new Set(t))}let D=null;function X(){return D||(D=ke(Q)),D}const Ne=["allow","deny","ask"],J="This settings file has invalid JSON. Fix it in the Settings raw editor first; Permissions will not overwrite it.";function Se(t){if(t.trim()==="")return{perms:{},full:{},err:null};try{const s=JSON.parse(t);if(s===null||typeof s!="object"||Array.isArray(s))return{perms:{},full:{},err:"settings file is not a JSON object"};const n=s;return{perms:n.permissions??{},full:n,err:null}}catch(s){return{perms:{},full:{},err:s.message}}}function Ce({scope:t="user"}={}){const s=L(),n=V(),a=(n==null?void 0:n.cwd)??null,o=z(i=>i.navFace),[r,l]=j.useState("rules");j.useEffect(()=>{o==="project"&&r==="presets"&&l("rules")},[o,r]);const u=H(ce,s,a)[t]??null,c=T(i=>i.files),x=e.jsx(U,{options:[{key:"rules",label:"Rules"},...o==="home"?[{key:"presets",label:"Presets"}]:[]],active:r,onChange:l});if(!s)return e.jsx(C,{title:"loading…"});if(r==="presets")return e.jsx(F,{toolbar:x,children:e.jsx(be,{})});const v=i=>i!=="user"&&!a,f=u?c[u]:null;return e.jsx(F,{toolbar:e.jsxs(e.Fragment,{children:[x,e.jsx("span",{className:"ml-3 text-fg-faint truncate",children:u??"—"}),e.jsx("div",{className:"flex-1"}),e.jsx("a",{href:"https://code.claude.com/docs/en/settings#permissions",target:"_blank",rel:"noreferrer",className:"text-fg-faint hover:text-fg-dim underline-offset-2 hover:underline",children:"rule syntax ↗"})]}),children:v(t)?e.jsx(C,{title:"no active project",hint:"open a tab in a project directory to edit project or local permissions"}):u&&f?e.jsx(ee,{scope:t,cwd:a,activePath:u}):e.jsx(C,{title:"resolving…"})})}j.memo(Ce);function ee({scope:t,cwd:s,activePath:n}){const a=T(c=>c.files[n]),{perms:o,err:r}=a?Se(a.draftRaw):{perms:{},err:null},l=(c,x)=>{if(r){A.error(J);return}window.api.claudeConfig.patch({fileId:"settings",scope:t,cwd:s,keyPath:["permissions",c],value:x}).catch(v=>A.error(v instanceof Error?v.message:String(v)))},p=(c,x)=>{const v=x.trim();if(!v)return;const f=o[c]??[];f.includes(v)||l(c,[...f,v])},u=(c,x)=>{const v=o[c]??[];l(c,v.filter((f,i)=>i!==x))};return e.jsxs("div",{className:"p-4 space-y-5 max-w-3xl",children:[r&&e.jsxs("div",{role:"alert",className:"text-xs text-red-400 border border-red-400/40 rounded px-3 py-2",children:[J," (",r,")"]}),e.jsx(_e,{value:o.defaultMode??"default",onChange:c=>l("defaultMode",c)}),Ne.map(c=>e.jsx(Ee,{list:c,rules:o[c]??[],disabled:!!r,onAdd:x=>p(c,x),onRemove:x=>u(c,x)},c)),e.jsx(Pe,{dirs:o.additionalDirectories??[],disabled:!!r,onChange:c=>l("additionalDirectories",c)})]})}function _e({value:t,onChange:s}){var r;const a=(((r=X().at(["permissions","defaultMode"]))==null?void 0:r.enum)??[]).filter(l=>typeof l=="string"),o=t&&!a.includes(t)?[...a,t]:a;return e.jsxs("section",{children:[e.jsx("h3",{className:"text-xs text-fg uppercase tracking-wider mb-2",children:"Default Mode"}),e.jsx("div",{className:"inline-flex rounded border border-line overflow-hidden",children:o.map(l=>e.jsx("button",{onClick:()=>s(l),className:`px-2.5 py-1 text-xs transition-colors ${t===l?"bg-bg-hi text-fg":"bg-bg-elev text-fg-dim hover:text-fg hover:bg-bg-hi"}`,children:l},l))})]})}function Ee({list:t,rules:s,onAdd:n,onRemove:a,disabled:o}){const[r,l]=j.useState(""),p=t==="allow"?"text-green-400":t==="deny"?"text-red-400":"text-yellow-400";return e.jsxs("section",{children:[e.jsx("h3",{className:`text-xs uppercase tracking-wider mb-2 ${p}`,children:t}),e.jsxs("div",{className:"flex gap-2 mb-2",children:[e.jsx("input",{value:r,disabled:o,onChange:u=>l(u.target.value),onKeyDown:u=>{u.key==="Enter"&&(n(r),l(""))},placeholder:t==="allow"?"e.g. Bash(ls:*) or Read(~/.claude/**)":"e.g. Write(/etc/**)",className:"flex-1 bg-bg-elev border border-line rounded px-2 py-1 text-xs text-fg placeholder-fg-faint"}),e.jsx("button",{onClick:()=>{n(r),l("")},disabled:o||!r.trim(),className:"px-2.5 py-1 border border-line rounded text-xs text-fg-dim hover:text-fg hover:bg-bg-hi disabled:opacity-40",children:"add"})]}),s.length===0?e.jsx("div",{className:"text-fg-faint text-xs",children:"no rules"}):e.jsx("ul",{className:"space-y-0.5",children:s.map((u,c)=>e.jsxs("li",{className:"flex items-center gap-2 text-xs font-mono bg-bg-elev border border-line rounded px-2 py-1",children:[e.jsx("span",{className:"flex-1 text-fg-dim truncate",children:u}),e.jsx("button",{onClick:()=>a(c),className:"text-fg-faint hover:text-red-400",title:"remove",children:"×"})]},`${c}-${u}`))})]})}function Pe({dirs:t,onChange:s,disabled:n}){const[a,o]=j.useState("");return e.jsxs("section",{children:[e.jsx("h3",{className:"text-xs text-fg uppercase tracking-wider mb-2",children:"Additional Directories"}),e.jsx("div",{className:"flex gap-2 mb-2",children:e.jsx("input",{value:a,disabled:n,onChange:r=>o(r.target.value),onKeyDown:r=>{r.key==="Enter"&&a.trim()&&(s([...t,a.trim()]),o(""))},placeholder:"/absolute/path/to/dir",className:"flex-1 bg-bg-elev border border-line rounded px-2 py-1 text-xs text-fg placeholder-fg-faint"})}),e.jsx("ul",{className:"space-y-0.5",children:t.map((r,l)=>e.jsxs("li",{className:"flex items-center gap-2 text-xs font-mono bg-bg-elev border border-line rounded px-2 py-1",children:[e.jsx("span",{className:"flex-1 text-fg-dim truncate",children:r}),e.jsx("button",{onClick:()=>s(t.filter((p,u)=>u!==l)),className:"text-fg-faint hover:text-red-400",children:"×"})]},`${l}-${r}`))})]})}const Te={UserPromptSubmit:{when:"Fires just before the user prompt is sent to the model.",payload:"{ prompt: string }",example:"Block submission if the prompt mentions a secret."},UserPromptExpansion:{when:"Fires when a slash command expands into its final prompt text.",payload:"{ command: string, expanded: string }",example:"Audit which slash commands actually run, post-expansion."},PreToolUse:{when:"Fires before any tool runs. Can block the call.",payload:"{ tool_name: string, tool_input: object }",example:'matcher="Bash" — block dangerous shell commands.'},PostToolUse:{when:"Fires after a tool completes successfully.",payload:"{ tool_name: string, tool_input: object, tool_result: string }",example:'matcher="Write|Edit" — run a linter on changed files.'},PostToolUseFailure:{when:"Fires after a tool errors out (non-zero exit, exception, or refusal).",payload:"{ tool_name: string, tool_input: object, error: string }",example:"Pipe failed Bash runs into a desktop notification."},PostToolBatch:{when:"Fires once after a parallel batch of tool calls all complete.",payload:"{ tool_uses: Array<{ tool_name, tool_input, tool_result? }> }",example:"Aggregate file-edit batches into a single commit message."},Stop:{when:"Fires when the model emits end_turn.",payload:"{ stop_reason: string, output_tokens: number }",example:"Play a chime when the agent finishes a long task."},StopFailure:{when:"Fires when a turn aborts without end_turn (rate-limit, network, OOM).",payload:'{ reason: "rate_limit"|"network"|"oom"|"killed"|string }',example:"Auto-resume on transient failures."},SessionStart:{when:"Fires once when a session boots (claude or claude -p).",payload:'{ source: "startup"|"resume", model: string, agent_type: string }',example:"Inject a project-specific system prompt addendum."},SessionEnd:{when:"Fires once when the session terminates.",payload:'{ reason: "user_quit"|"timeout"|"error"|string }',example:"Persist transcript summary to ~/.claude/projects/<>."},Setup:{when:"Fires during interactive setup (claude /setup, /init).",payload:'{ mode: "init"|"reconfigure"|string }'},PreCompact:{when:"Fires before transcript compaction runs.",payload:'{ transcript_path: string, trigger: "manual"|"auto" }',example:"Snapshot the pre-compact transcript for later diffing."},PostCompact:{when:"Fires after compaction; the active transcript is the compacted one.",payload:'{ transcript_path: string, trigger: "manual"|"auto" }'},InstructionsLoaded:{when:"Fires after CLAUDE.md and any imported memory files are loaded.",payload:'{ source: "session_start"|"reload" }'},Notification:{when:"Fires when Claude Code emits a desktop notification.",payload:"{ title: string, message: string }",example:"Forward to your own notify-send / osascript pipeline."},PermissionRequest:{when:"Fires when a tool needs user permission (per the permissions block).",payload:"{ tool_name: string, tool_input?: object }",example:"Auto-allow npm test invocations."},PermissionDenied:{when:"Fires when the user (or policy) denies a permission request.",payload:"{ tool_name: string, retry: boolean }",example:"Track which tools the user habitually rejects."},SubagentStart:{when:"Fires when a subagent (Task tool) spawns.",payload:"{ agent_type: string }",example:'matcher="security-reviewer" — log every security scan.'},SubagentStop:{when:"Fires when a subagent finishes.",payload:'{ agent_type: string, reason: "end_turn"|"error"|string }'},TeammateIdle:{when:"Fires when a teammate agent goes idle (waiting for input).",payload:"{ teammate_id?: string }"},TaskCreated:{when:"Fires when a new Task is created via the Task tool.",payload:"{ task: { description: string, ...} }",example:"Track each spawned task in an external queue."},TaskCompleted:{when:"Fires when a Task completes (success or failure).",payload:"{ task: { description: string, ...} }"},ConfigChange:{when:"Fires when settings.json (any scope) is mutated mid-session.",payload:'{ source: "user_settings"|"project_settings"|"local_settings" }',example:"Reload tooling that depends on env vars on config change."},CwdChanged:{when:"Fires when the working directory changes (e.g. agent cd-ing).",payload:"{ old_cwd: string, new_cwd: string }",example:"Refresh project-scoped indexers when cwd drifts."},FileChanged:{when:"Fires when a watched file outside Claude Code's edits changes.",payload:'{ file_path: string, change_type: "modified"|"created"|"deleted" }',example:"Re-run typecheck when any .ts file changes."},WorktreeCreate:{when:"Fires after a git worktree is created via /worktree or subagent isolation.",payload:"{ worktree_path?: string, branch?: string }"},WorktreeRemove:{when:"Fires after a git worktree is removed.",payload:"{ worktree_path?: string }"},Elicitation:{when:"Fires when Claude asks the user a multiple-choice question.",payload:'{ action: "accept"|"reject", ...}'},ElicitationResult:{when:"Fires after the user resolves an elicitation prompt.",payload:"{ choice?: string }"}},te=["UserPromptSubmit","UserPromptExpansion","PreToolUse","PostToolUse","PostToolUseFailure","PostToolBatch","Stop","StopFailure","SessionStart","SessionEnd","Setup","PreCompact","PostCompact","InstructionsLoaded","Notification","PermissionRequest","PermissionDenied","SubagentStart","SubagentStop","TeammateIdle","TaskCreated","TaskCompleted","ConfigChange","CwdChanged","FileChanged","WorktreeCreate","WorktreeRemove","Elicitation","ElicitationResult"],Fe=new Set(te),Oe=["command","http","prompt","agent","mcp_tool"],Ae={UserPromptSubmit:{prompt:"hello"},UserPromptExpansion:{command:"/example",expanded:"hello"},PreToolUse:{tool_name:"Bash",tool_input:{command:"ls"}},PostToolUse:{tool_name:"Bash",tool_input:{command:"ls"},tool_result:""},PostToolUseFailure:{tool_name:"Bash",tool_input:{command:"ls"},error:""},PostToolBatch:{tool_uses:[]},Stop:{stop_reason:"end_turn",output_tokens:0},StopFailure:{reason:"rate_limit"},SessionStart:{source:"startup",model:"",agent_type:""},SessionEnd:{reason:"user_quit"},Setup:{mode:"init"},PreCompact:{transcript_path:"",trigger:"manual"},PostCompact:{transcript_path:"",trigger:"manual"},InstructionsLoaded:{source:"session_start"},Notification:{title:"test",message:"test notification"},PermissionRequest:{tool_name:"Bash"},PermissionDenied:{tool_name:"Bash",retry:!1},SubagentStart:{agent_type:"general-purpose"},SubagentStop:{agent_type:"general-purpose",reason:"end_turn"},TeammateIdle:{},TaskCreated:{task:{description:""}},TaskCompleted:{task:{description:""}},ConfigChange:{source:"user_settings"},CwdChanged:{old_cwd:"",new_cwd:""},FileChanged:{file_path:"",change_type:"modified"},WorktreeCreate:{},WorktreeRemove:{},Elicitation:{action:"accept"},ElicitationResult:{}},K="This settings file has invalid JSON. Fix it in the Settings raw editor first; Hooks will not overwrite it.";function Re(t){if(t.trim()==="")return{full:{},hooks:{},err:null};try{const s=JSON.parse(t);if(s===null||typeof s!="object"||Array.isArray(s))return{full:{},hooks:{},err:"settings file is not a JSON object"};const n=s;return{full:n,hooks:n.hooks??{},err:null}}catch(s){return{full:{},hooks:{},err:s.message}}}function Me(t,s){return(t[s]??[]).reduce((n,a)=>{var o;return n+(((o=a.hooks)==null?void 0:o.length)??0)},0)}function $e({scope:t="user"}={}){const s=L(),n=V(),a=(n==null?void 0:n.cwd)??null,o=z(x=>x.navFace),[r,l]=j.useState("events");j.useEffect(()=>{o==="project"&&r==="library"&&l("events")},[o,r]);const u=H(Y,s,a)[t]??null,c=e.jsx(U,{options:[{key:"events",label:"Events"},...o==="home"?[{key:"library",label:"Library"}]:[]],active:r,onChange:l});return s?r==="library"?e.jsx(F,{toolbar:c,children:e.jsx(ye,{})}):t!=="user"&&!a?e.jsx(F,{toolbar:e.jsx(e.Fragment,{children:c}),children:e.jsx(C,{title:"no active project"})}):u?e.jsx(F,{toolbar:e.jsxs(e.Fragment,{children:[c,e.jsx("span",{className:"ml-3 text-fg-faint truncate",children:u}),e.jsx("div",{className:"flex-1"}),e.jsx("a",{href:"https://code.claude.com/docs/en/hooks",target:"_blank",rel:"noreferrer",className:"text-fg-faint hover:text-fg-dim underline-offset-2 hover:underline",children:"hook reference ↗"})]}),children:e.jsx(se,{scope:t,cwd:a,path:u})}):e.jsx(C,{title:"loading…"}):e.jsx(C,{title:"loading…"})}function se({scope:t,cwd:s,path:n}){const[a,o]=j.useState("PreToolUse"),[r,l]=j.useState(null),p=(b,k)=>{window.api.claudeConfig.patch({fileId:"settings",scope:t,cwd:s,keyPath:b,value:k}).catch(m=>A.error(m instanceof Error?m.message:String(m)))},u=T(b=>b.files[n]),{hooks:c,err:x}=u?Re(u.draftRaw):{hooks:{},err:null},v=Object.keys(c).filter(b=>!Fe.has(b)),f=v.reduce((b,k)=>b+(c[k]??[]).reduce((m,y)=>{var w;return m+(((w=y.hooks)==null?void 0:w.length)??0)},0),0),i=(b,k)=>{if(x){A.error(K);return}p(["hooks",b],k)},d=c[a]??[],h=()=>{i(a,[...d,{matcher:"",hooks:[{type:"command",command:""}]}])},g=(b,k)=>{const m=d.slice();m[b]=k,i(a,m)},N=b=>{i(a,d.filter((k,m)=>m!==b))};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-col h-full",children:[x?e.jsxs("div",{role:"alert",className:"px-3 py-2 border-b border-line text-xs text-red-400",children:[K," (",x,")"]}):null,f>0?e.jsxs("div",{className:"px-3 py-2 border-b border-line text-xs bg-bg-elev text-fg-dim",children:[e.jsx("span",{className:"text-yellow-400",children:"⚠"})," ",f," hook(s) configured under unknown event names: ",e.jsx("span",{className:"font-mono text-fg",children:v.join(", ")}),e.jsx("span",{className:"text-fg-faint",children:" · these are ignored by Claude Code 2026; edit settings.json directly to remove."})]}):null,e.jsx(je,{sidebarWidth:"14rem",sidebar:e.jsx("div",{className:"py-1",children:te.map(b=>{const k=Me(c,b),m=Te[b],y=m?e.jsxs("span",{className:"block space-y-1",children:[e.jsx("span",{className:"block text-fg",children:m.when}),e.jsxs("span",{className:"block text-fg-faint font-mono",children:["payload: ",m.payload]}),m.example?e.jsxs("span",{className:"block text-fg-faint italic",children:["e.g. ",m.example]}):null]}):e.jsx("span",{className:"text-fg-faint italic",children:"no documentation yet"});return e.jsx("div",{className:"[&>span]:w-full",children:e.jsx(de,{content:y,align:"bottom-center",children:e.jsxs("button",{onClick:()=>o(b),title:m==null?void 0:m.when,className:`w-full text-left px-3 py-1 text-xs ${a===b?"bg-bg-hi text-fg":"text-fg-dim hover:text-fg hover:bg-bg-hi"}`,children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"truncate",children:b}),k>0&&e.jsx("span",{className:"text-accent shrink-0 ml-2",children:k})]}),m?e.jsx("span",{className:"block text-[11px] leading-[1.3] text-fg-faint/80 font-normal truncate",children:m.when}):e.jsx("span",{className:"block text-[11px] leading-[1.3] text-fg-faint/80 italic font-normal truncate",children:"no documentation yet"})]})})},b)})}),detail:e.jsxs("div",{className:"p-4 space-y-3 max-w-3xl",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-xs uppercase tracking-wider text-fg",children:a}),e.jsx("button",{onClick:h,disabled:!!x,className:"px-2 py-0.5 text-xs border border-line rounded text-fg-dim hover:text-fg hover:bg-bg-hi disabled:opacity-40 disabled:cursor-not-allowed",children:"+ add group"})]}),d.length===0?e.jsx("div",{className:"text-fg-faint text-xs",children:"no hooks for this event"}):d.map((b,k)=>e.jsx(Ie,{group:b,jsonInvalid:!!x,onChange:m=>g(k,m),onRemove:()=>N(k),onTestFire:m=>l({event:a,matcher:b.matcher??"",command:m.command??""})},k))]})})]}),r?e.jsx(Be,{event:r.event,matcher:r.matcher,command:r.command,onClose:()=>l(null)}):null]})}j.memo($e);function M({value:t,onCommit:s,onDraft:n,...a}){const[o,r]=j.useState(t);j.useEffect(()=>r(t),[t]);const l=()=>{o!==t&&s(o)};return e.jsx("input",{...a,value:o,onChange:p=>{r(p.target.value),n==null||n(p.target.value)},onBlur:l,onKeyDown:p=>{p.key==="Enter"&&l()}})}function Ie({group:t,jsonInvalid:s,onChange:n,onRemove:a,onTestFire:o}){const r=()=>n({...t,hooks:[...t.hooks??[],{type:"command",command:""}]}),l=(u,c)=>{const x=t.hooks.slice();x[u]=c,n({...t,hooks:x})},p=u=>n({...t,hooks:t.hooks.filter((c,x)=>x!==u)});return e.jsxs("div",{className:"border border-line rounded p-3 bg-bg-elev space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-fg-faint w-16",children:"matcher"}),e.jsx(M,{value:t.matcher??"",disabled:s,onCommit:u=>n({...t,matcher:u}),placeholder:"tool name regex or exact match (optional)",className:"flex-1 bg-bg border border-line rounded px-2 py-0.5 text-xs text-fg font-mono"}),e.jsx("button",{onClick:a,disabled:s,className:"text-fg-faint hover:text-red-400 text-xs disabled:opacity-40",title:"remove group",children:"× group"})]}),(t.hooks??[]).map((u,c)=>e.jsx(Le,{rule:u,jsonInvalid:s,onChange:x=>l(c,x),onRemove:()=>p(c),onTestFire:()=>o(u)},c)),e.jsx("button",{onClick:r,disabled:s,className:"text-xs text-fg-faint hover:text-fg disabled:opacity-40",children:"+ add hook"})]})}function De(t){var n,a,o;const s=((a=(n=Q.$defs)==null?void 0:n.hookCommand)==null?void 0:a.anyOf)??[];for(const r of s){const l=r.properties;if(((o=l==null?void 0:l.type)==null?void 0:o.const)!==t)continue;const p=l.timeout;if(typeof(p==null?void 0:p.default)=="number")return p.default;const u=/default:\s*(\d+)/.exec((p==null?void 0:p.description)??"");return u?Number(u[1]):null}return null}function G(t){return/^\d+$/.test(t.trim())&&Number(t)>0?Number(t):null}function Le({rule:t,jsonInvalid:s,onChange:n,onRemove:a,onTestFire:o}){const r=i=>({command:"e.g. node ./scripts/lint.js $FILE",http:"e.g. https://hooks.example.com/notify",prompt:"e.g. Review this change for security issues",agent:"e.g. security-reviewer",mcp_tool:"e.g. mcp__server__tool"})[i],l=t.type==="command"?"command":t.type==="http"?"url":t.type==="prompt"?"prompt":t.type==="mcp_tool"?"mcpTool":"agent",p=t[l]??"",u=(t.args??[]).join(" "),[c,x]=j.useState(null),v=De(t.type),f={type:"hook",name:p||t.type,command:t.type==="command"?t.command:void 0,url:t.type==="http"?t.url:void 0};return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("select",{value:t.type,disabled:s,onChange:i=>n({type:i.target.value}),className:"bg-bg border border-line rounded px-1 py-0.5 text-xs text-fg",children:Oe.map(i=>e.jsx("option",{value:i,children:i},i))}),e.jsx(ve,{interactive:!1,input:f}),e.jsx(M,{value:p,disabled:s,onCommit:i=>n({...t,[l]:i}),placeholder:r(t.type),className:`flex-1 bg-bg border rounded px-2 py-0.5 text-xs text-fg font-mono ${s?"border-red-500/70":p.trim()?"border-line":"border-yellow-600/50"}`}),s?e.jsx("span",{className:"text-red-400 text-xs",title:"The enclosing settings.json is malformed; fix the JSON before editing.",children:"× invalid"}):null,e.jsx(M,{value:t.timeout!=null?String(t.timeout):"",disabled:s,"aria-label":"timeout (seconds)","aria-invalid":c?!0:void 0,title:c??"Timeout in seconds",onDraft:i=>{x(!i.trim()||G(i)!=null?null:"Timeout must be a positive whole number of seconds")},onCommit:i=>{if(!i.trim()){n({...t,timeout:void 0});return}const d=G(i);d!=null&&n({...t,timeout:d})},placeholder:v!=null?`${v} (seconds)`:"seconds",className:`w-24 bg-bg border rounded px-2 py-0.5 text-xs text-fg ${c?"border-red-500/70":"border-line"}`}),c?e.jsx("span",{role:"alert",className:"text-red-400 text-xs",children:c}):null,t.type==="command"?e.jsx("button",{onClick:o,disabled:s||!p.trim(),className:"px-2 py-0.5 text-xs border border-line rounded text-fg-dim hover:text-fg hover:bg-bg-hi disabled:opacity-40 disabled:cursor-not-allowed",title:"Run this command with a fake event payload",children:"test fire"}):null,e.jsx("button",{onClick:a,disabled:s,className:"text-fg-faint hover:text-red-400 text-xs disabled:opacity-40",children:"×"})]}),t.type==="command"?e.jsxs("div",{className:"flex items-center gap-2 pl-[3.75rem]",children:[e.jsx("span",{className:"text-xs text-fg-faint w-12",children:"args"}),e.jsx(M,{value:u,disabled:s,onCommit:i=>n({...t,args:i.trim()?i.split(/\s+/).filter(Boolean):void 0}),placeholder:"argv array (v2.1.139+ exec form, no shell)",className:"flex-1 bg-bg border border-line rounded px-2 py-0.5 text-xs text-fg font-mono"})]}):null,e.jsxs("div",{className:"flex items-center gap-2 pl-[3.75rem]",children:[e.jsx("span",{className:"text-xs text-fg-faint w-12",children:"term"}),e.jsx(M,{value:t.terminalSequence??"",disabled:s,onCommit:i=>n({...t,terminalSequence:i||void 0}),placeholder:"terminalSequence — e.g. \\\\a (bell), v2.1.141+",className:"flex-1 bg-bg border border-line rounded px-2 py-0.5 text-xs text-fg font-mono"})]})]})}function He(t){return JSON.stringify(Ae[t]??{},null,2)}function Ue(t,s){if(!t.trim())return{matched:!0,target:null,note:"empty matcher → matches all"};const n=s&&typeof s=="object"&&"tool_name"in s?String(s.tool_name??""):null;if(n==null)return{matched:!1,target:null,note:"payload has no tool_name to match against"};try{return{matched:new RegExp(`^(?:${t})$`).test(n),target:n}}catch{return{matched:t===n,target:n,note:"matcher not valid regex; fell back to exact match"}}}function Be({event:t,matcher:s,command:n,onClose:a}){const[o,r]=j.useState(()=>He(t)),[l,p]=j.useState(!1),[u,c]=j.useState(null),[x,v]=j.useState(null);let f=null;try{JSON.parse(o)}catch(d){f=d.message}const i=async()=>{p(!0),c(null);let d=null;try{d=JSON.parse(o)}catch{}v(Ue(s,d));try{const h=await window.api.app.testFireHook({command:n,payload:o,timeoutMs:5e3});c(h)}finally{p(!1)}};return e.jsx(ue,{open:!0,onClose:a,title:`Test fire — ${t}`,children:e.jsxs("div",{className:"space-y-3 text-xs",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-fg-faint mb-1",children:"resolved command"}),e.jsx("div",{className:"font-mono text-fg bg-bg border border-line rounded px-2 py-1 break-all",children:n})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-fg-faint mb-1",children:"matcher"}),e.jsx("div",{className:"font-mono text-fg bg-bg border border-line rounded px-2 py-1",children:s||e.jsx("span",{className:"text-fg-faint",children:"(empty — matches all)"})})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("span",{className:"text-fg-faint",children:"fake event payload (stdin)"}),f?e.jsxs("span",{className:"text-red-400",children:["× ",f]}):null]}),e.jsx("textarea",{value:o,onChange:d=>r(d.target.value),rows:8,className:`w-full bg-bg border rounded px-2 py-1 font-mono text-fg ${f?"border-red-500/70":"border-line"}`})]}),x?e.jsxs("div",{children:[e.jsx("div",{className:"text-fg-faint mb-1",children:"matcher result"}),e.jsxs("div",{className:"font-mono",children:[e.jsx("span",{className:x.matched?"text-green-400":"text-red-400",children:x.matched?"✓ match":"✗ no match"}),x.target!=null?e.jsxs("span",{className:"text-fg-dim",children:[' · target tool_name="',x.target,'"']}):null,x.note?e.jsx("div",{className:"text-fg-faint",children:x.note}):null]})]}):null,u?e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"text-fg-faint",children:["exit ",u.exitCode," · ",u.durationMs,"ms"]}),u.stdout?e.jsxs("div",{children:[e.jsx("div",{className:"text-fg-faint",children:"stdout"}),e.jsx("pre",{className:"bg-bg border border-line rounded p-2 font-mono text-fg whitespace-pre-wrap break-all max-h-40 overflow-auto",children:u.stdout})]}):null,u.stderr?e.jsxs("div",{children:[e.jsx("div",{className:"text-fg-faint",children:"stderr"}),e.jsx("pre",{className:"bg-bg border border-line rounded p-2 font-mono text-red-300 whitespace-pre-wrap break-all max-h-40 overflow-auto",children:u.stderr})]}):null]}):null,e.jsxs("div",{className:"flex items-center justify-end gap-2 pt-1",children:[e.jsx("button",{onClick:a,className:"px-2 py-0.5 text-xs border border-line rounded text-fg-dim hover:text-fg hover:bg-bg-hi",children:"close"}),e.jsx("button",{onClick:i,disabled:l||!!f||!n.trim(),className:"px-2 py-0.5 text-xs border border-line rounded text-fg hover:bg-bg-hi disabled:opacity-40 disabled:cursor-not-allowed",children:l?"running…":"run"})]})]})})}const ne=[{id:"permissions",label:"Permissions",tab:"permissions",keys:["permissions"]},{id:"hooks",label:"Hooks",tab:"hooks",keys:["hooks","disableAllHooks","allowedHttpHookUrls","httpHookAllowedEnvVars"]},{id:"mcp",label:"MCP Servers",tab:null,keys:["enabledMcpjsonServers","disabledMcpjsonServers","enableAllProjectMcpServers"]},{id:"plugins",label:"Plugins",tab:null,keys:["enabledPlugins"]}],W=new Set(ne.flatMap(t=>t.keys)),Je=[{id:"essentials",title:"Essentials",summary:"The knobs you reach for first.",keys:["model","language","outputStyle"]},{id:"git",title:"Git & Commits",summary:"How Claude writes commits and pull requests on your behalf.",keys:["attribution","includeGitInstructions","includeCoAuthoredBy"]},{id:"memory",title:"Memory & Plans",summary:"Context Claude keeps between sessions and where it files plans.",keys:["autoMemoryEnabled","plansDirectory","claudeMdExcludes","respectGitignore"]},{id:"model",title:"Model & Reasoning",summary:"Model allow/override lists, reasoning depth, and fast-mode toggles — machine-wide, with no per-Epic override yet. An Epic's Agent persona model (Agent Library) still wins over Essentials' plain model default.",advanced:!0,keys:["availableModels","modelOverrides","effortLevel","fastMode","fastModePerSessionOptIn","alwaysThinkingEnabled","fallbackModel","enforceAvailableModels","teammateDefaultModel","advisorModel"]},{id:"interface",title:"Interface",summary:"Visual polish — spinners, progress bars, motion.",keys:["spinnerTipsEnabled","spinnerTipsOverride","spinnerVerbs","terminalProgressBarEnabled","showTurnDuration","prefersReducedMotion","companyAnnouncements","statusLine","teammateMode"]},{id:"updates",title:"Updates & Cleanup",summary:"Release channel and how long transcripts stick around.",keys:["autoUpdatesChannel","cleanupPeriodDays"]},{id:"env",title:"Environment & Auth",summary:"Environment variables and auth-helper scripts.",keys:["env","apiKeyHelper","awsCredentialExport","awsAuthRefresh"]},{id:"hooks",title:"Hooks",summary:"Scripts Claude runs before/after tool use.",keys:["hooks","disableAllHooks","allowedHttpHookUrls","httpHookAllowedEnvVars"]},{id:"mcp",title:"MCP Servers",summary:"External tool providers Claude can talk to.",keys:["enableAllProjectMcpServers","enabledMcpjsonServers","disabledMcpjsonServers"]},{id:"plugins",title:"Plugins",summary:"Installed plugins, marketplaces, and per-plugin configuration.",keys:["enabledPlugins","extraKnownMarketplaces","skippedPlugins","skippedMarketplaces","pluginConfigs"]},{id:"filesystem",title:"File Picker & Sandbox",summary:"How Claude browses files and the sandbox it runs in.",keys:["fileSuggestion","sandbox","worktree"]},{id:"login",title:"Login",summary:"Which login method to force on startup.",keys:["forceLoginMethod","forceLoginOrgUUID"]},{id:"feedback",title:"Feedback",summary:"Session-quality surveys.",keys:["feedbackSurveyRate"]},{id:"advanced",title:"Advanced / Enterprise",summary:"Managed-settings-only keys and enterprise allow/denylists.",advanced:!0,keys:["allowedMcpServers","deniedMcpServers","allowManagedHooksOnly","allowManagedPermissionRulesOnly","allowManagedMcpServersOnly","strictKnownMarketplaces","blockedMarketplaces","pluginTrustMessage","otelHeadersHelper","skipWebFetchPreflight"]}],Ke={mcp:"MCP",url:"URL",urls:"URLs",http:"HTTP",ui:"UI",id:"ID",uuid:"UUID",api:"API",aws:"AWS",otel:"OTel",json:"JSON"};function re(t){return t.replace(/^\$/,"").replace(/([a-z])([A-Z])/g,"$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g,"$1 $2").toLowerCase().split(/\s+/).filter(Boolean).map((a,o)=>{const r=Ke[a];return r||(o===0?a.charAt(0).toUpperCase()+a.slice(1):a)}).join(" ")}function ae(t){const s=new Set,n=[];for(const o of Je){const r=o.keys.filter(l=>t.has(l)&&!W.has(l));r.forEach(l=>s.add(l)),r.length!==0&&n.push({id:o.id,title:o.title,summary:o.summary,advanced:!!o.advanced,keys:r})}const a=Array.from(t).filter(o=>!s.has(o)&&o!=="$schema"&&!W.has(o)).sort();return a.length>0&&n.push({id:"other",title:"Other",summary:"Keys not yet grouped.",advanced:!1,keys:a}),n}function Ge(t,s){return ae(t).map(n=>({id:n.id,title:n.title,advanced:n.advanced,total:n.keys.length,setCount:n.keys.filter(a=>s.has(a)).length}))}const We={};function oe(t,s){if(s)return{text:s,authored:!1};const n=We[t];return n?{text:n,authored:!0}:null}const qe={essentials:"star",git:"link",memory:"memory",model:"sparkle",interface:"eye",updates:"reload",env:"keys",hooks:"hooks",mcp:"mcp",plugins:"plugins",filesystem:"folder",login:"lock",feedback:"send",advanced:"shield",other:"dot"},Ve=["user","project","local","default"],ze={user:"user",project:"project",local:"local",default:"default"};function Ye({node:t,targetScope:s,onOverride:n,schema:a}){const[o,r]=j.useState(""),[l,p]=j.useState(!1),[u,c]=j.useState(!0),x=t.kind==="object"?t:null,v=x?Object.keys(x.children):[],f=a.rootKeys(),i=new Set([...v,...f]),d=j.useMemo(()=>ae(i),[Array.from(i).sort().join(",")]),h=j.useMemo(()=>Ge(i,new Set(v)),[Array.from(i).sort().join(","),v.join(",")]),[g,N]=j.useState(null),b=j.useRef(null),k=y=>{const w=d.find(_=>_.id===y);w!=null&&w.advanced&&!l&&p(!0),N(y)};j.useEffect(()=>{if(!g)return;N(null);const y=b.current,w=document.getElementById(`settings-group-${g}`);if(!y||!w)return;const _=w.getBoundingClientRect().top-y.getBoundingClientRect().top;y.scrollBy({top:_,behavior:"smooth"})},[g]);const m=j.useMemo(()=>d.filter(y=>l||!y.advanced).map(y=>({...y,keys:y.keys.filter(w=>{const _=(x==null?void 0:x.children[w])!==void 0;if(!u&&!_)return!1;if(!o.trim())return!0;const E=a.at([w]);return[w,re(w),(E==null?void 0:E.description)??""].join(" ").toLowerCase().includes(o.toLowerCase())})})).filter(y=>y.keys.length>0),[d,o,l,u,x,a]);return e.jsxs("div",{className:"h-full flex flex-col",children:[e.jsxs("div",{className:"shrink-0 border-b border-line bg-bg-elev px-3 py-1.5 flex items-center gap-3 text-xs",children:[e.jsxs("span",{className:"text-fg-faint",children:["writing overrides to"," ",e.jsx("span",{className:"text-fg-dim font-medium",children:S[s].label})]}),e.jsxs("label",{className:"flex items-center gap-1 text-fg-faint cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:u,onChange:y=>c(y.target.checked),className:"accent-accent"}),"show not-yet-configured"]}),e.jsxs("label",{className:"flex items-center gap-1 text-fg-faint cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:l,onChange:y=>p(y.target.checked),className:"accent-accent"}),"show advanced"]}),e.jsx("div",{className:"flex-1"}),e.jsx("input",{value:o,onChange:y=>r(y.target.value),placeholder:"search settings…",className:"bg-bg border border-line rounded px-2 py-1 text-xs text-fg w-64"})]}),e.jsxs("div",{className:"flex-1 flex overflow-hidden",children:[e.jsx(Ze,{groups:h,onJump:k}),e.jsxs("div",{ref:b,className:"flex-1 overflow-auto py-3",children:[m.map(y=>e.jsx(Qe,{id:y.id,title:y.title,summary:y.summary,advanced:y.advanced,children:y.keys.map(w=>{const _=x==null?void 0:x.children[w],E=a.at([w]);return e.jsx(Xe,{keyName:w,node:_,info:E,targetScope:s,onOverride:(R,$)=>n([w],R,$)},w)})},y.id)),m.length===0&&e.jsxs("div",{className:"px-6 py-12 text-center text-fg-faint text-sm",children:['no settings match "',o,'"']})]})]})]})}function Ze({groups:t,onJump:s}){return e.jsx("nav",{className:"shrink-0 w-48 border-r border-line bg-bg-elev/30 overflow-y-auto py-3",children:t.map(n=>e.jsxs("button",{onClick:()=>s(n.id),className:"w-full flex items-center gap-2 px-3 py-2 text-left hover:bg-bg-hi transition-colors",title:`jump to ${n.title}`,children:[e.jsx(pe,{name:qe[n.id]??"dot",size:15,className:"text-fg-faint shrink-0"}),e.jsx("span",{className:"flex-1 min-w-0 truncate text-xs text-fg-dim",children:n.title}),e.jsxs("span",{className:"text-[10px] text-fg-faint font-mono shrink-0",children:[n.setCount,"/",n.total]})]},n.id))})}function Qe({id:t,title:s,summary:n,advanced:a,children:o}){const[r,l]=j.useState(!0);return e.jsxs("section",{id:`settings-group-${t}`,className:"mx-4 mb-4 rounded-lg border border-line shadow-sm bg-bg-elev/50 overflow-hidden",children:[e.jsxs("header",{className:"px-4 py-3 bg-bg-elev cursor-pointer hover:bg-bg-hi flex items-center gap-3 border-b border-line",onClick:()=>l(!r),children:[e.jsx("span",{className:"text-fg-faint w-3",children:r?"▾":"▸"}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h2",{className:"text-fg text-base font-semibold",children:s}),a&&e.jsx("span",{className:"text-[9px] px-1.5 py-0 rounded border border-yellow-900/40 bg-yellow-950/30 text-yellow-500/80 uppercase tracking-wide",children:"advanced"})]}),e.jsx("p",{className:"text-fg-dim text-sm mt-0.5",children:n})]})]}),r&&e.jsx("div",{className:"divide-y divide-line/60",children:o})]})}function Xe({keyName:t,node:s,info:n,targetScope:a,onOverride:o}){const[r,l]=j.useState(!1),[p,u]=j.useState(!1),c=re(t),x=s!==void 0,f=(s==null?void 0:s.kind)==="leaf"?s:null,i=(s==null?void 0:s.kind)==="object"||(s==null?void 0:s.kind)==="array",d=n==null?void 0:n.default,h=f&&d!==void 0&&le(f.value,d),g=it({isSet:x,leafNode:f,defaultVal:d,isDefault:!!h,node:s}),N=et(f,d),b=N.length>=2,k=!!f&&!h,m=oe(t,n==null?void 0:n.description);return e.jsx("div",{className:"px-4 py-3 hover:bg-bg-elev/20",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("button",{onClick:()=>l(!r),className:"text-fg-faint hover:text-fg w-3 mt-0.5",title:r?"collapse":"expand",children:r?"▾":"▸"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-baseline gap-2 flex-wrap",children:[e.jsx("h3",{className:"text-fg text-sm",children:c}),e.jsx(lt,{kind:g.kind,label:g.label}),b&&e.jsxs("button",{onClick:y=>{y.stopPropagation(),r||l(!0),u(w=>!w)},className:"text-[9px] px-1.5 py-0 rounded border border-blue-900/40 bg-blue-950/30 text-blue-300/90 uppercase tracking-wide hover:bg-blue-900/40",title:"this key is defined in multiple scopes — click to expand",children:["drift · ",N.map(y=>ze[y]).join(" · ")]}),k&&f&&e.jsx("button",{onClick:y=>{y.stopPropagation(),o(void 0,f.winner)},className:"text-[9px] px-1.5 py-0 rounded border border-line bg-bg-elev text-fg-faint uppercase tracking-wide hover:text-fg hover:bg-bg-hi",title:`reset · delete from ${S[f.winner].label}`,children:"↺ reset"}),(n==null?void 0:n.deprecated)&&e.jsx("span",{className:"text-[9px] px-1 py-0 rounded border border-yellow-900/40 bg-yellow-950/30 text-yellow-500/80 uppercase tracking-wide",children:"deprecated"}),(n==null?void 0:n.required)&&!x&&e.jsx("span",{className:"text-[9px] px-1 py-0 rounded border border-red-900/40 bg-red-950/30 text-red-400/80 uppercase tracking-wide",children:"required"})]}),m&&e.jsx("p",{className:`text-fg-dim text-xs mt-0.5 leading-relaxed ${m.authored?"inline-block border-b border-dotted border-fg-faint/70 cursor-help":""}`,title:m.authored?"In-app-authored description — not from the official Claude Code schema":void 0,children:ct(m.text)}),r&&p&&f&&e.jsx(tt,{leaf:f,defaultVal:d,onReset:y=>o(void 0,y)}),r&&e.jsx(st,{keyName:t,node:s,info:n,targetScope:a,onOverride:y=>o(y)})]}),e.jsx("div",{className:"shrink-0",children:!r&&e.jsx(ot,{node:s,info:n,onSet:y=>{o(y)},disabled:i&&x})})]})})}function et(t,s){if(!t)return[];const n=new Set;n.add(t.winner);for(const a of t.shadowed)n.add(a.scope);return s!==void 0&&n.add("default"),Ve.filter(a=>n.has(a))}function tt({leaf:t,defaultVal:s,onReset:n}){const a={};a[t.winner]={value:t.value,winner:!0};for(const o of t.shadowed)a[o.scope]={value:o.value,winner:!1};return e.jsxs("div",{className:"mt-2 border border-line rounded bg-bg-elev/40 text-xs",children:[e.jsx("div",{className:"px-2 py-1 text-fg-faint border-b border-line/60",children:"Values across all scopes (winner highlighted · reset removes that scope's value):"}),e.jsxs("div",{className:"divide-y divide-line/60",children:[["user","project","local"].map(o=>{const r=a[o],l=r!==void 0;return e.jsxs("div",{className:"grid grid-cols-[5rem_1fr_auto] gap-2 px-2 py-1 items-center",children:[e.jsx("span",{className:"text-fg-faint",children:S[o].label}),e.jsx("span",{className:`font-mono truncate ${r!=null&&r.winner?"text-accent":"text-fg-dim"}`,children:l?O(r.value):e.jsx("span",{className:"text-fg-faint",children:"—"})}),l?e.jsx("button",{onClick:()=>n(o),className:"text-[9px] px-1.5 py-0 rounded border border-line text-fg-faint uppercase tracking-wide hover:text-fg hover:bg-bg-hi",title:`delete this key from ${S[o].label}`,children:"↺"}):e.jsx("span",{})]},o)}),e.jsxs("div",{className:"grid grid-cols-[5rem_1fr_auto] gap-2 px-2 py-1 items-center",children:[e.jsx("span",{className:"text-fg-faint",children:"Default"}),e.jsx("span",{className:"font-mono text-fg-dim truncate",children:s!==void 0?O(s):e.jsx("span",{className:"text-fg-faint",children:"—"})}),e.jsx("span",{})]})]})]})}function st({keyName:t,node:s,info:n,targetScope:a,onOverride:o}){const l=(s==null?void 0:s.kind)==="leaf"?s:null,p=oe(t,n==null?void 0:n.description);return e.jsxs("div",{className:"mt-3 space-y-2 text-xs",children:[p&&e.jsx("p",{className:`text-fg-dim leading-relaxed whitespace-pre-wrap ${p.authored?"inline-block border-b border-dotted border-fg-faint/70 cursor-help":""}`,title:p.authored?"In-app-authored description — not from the official Claude Code schema":void 0,children:p.text}),e.jsxs("dl",{className:"grid grid-cols-[auto_1fr] gap-x-3 gap-y-1 text-fg-faint",children:[(n==null?void 0:n.type)&&e.jsxs(e.Fragment,{children:[e.jsx("dt",{children:"Type"}),e.jsx("dd",{className:"text-fg-dim font-mono",children:Array.isArray(n.type)?n.type.join(" | "):n.type})]}),(n==null?void 0:n.default)!==void 0&&e.jsxs(e.Fragment,{children:[e.jsx("dt",{children:"Default"}),e.jsx("dd",{className:"text-fg-dim font-mono",children:O(n.default)})]}),(n==null?void 0:n.enum)&&e.jsxs(e.Fragment,{children:[e.jsx("dt",{children:"Options"}),e.jsx("dd",{className:"text-fg-dim font-mono",children:n.enum.map(u=>String(u)).join(" | ")})]}),l&&e.jsxs(e.Fragment,{children:[e.jsx("dt",{children:"Current"}),e.jsxs("dd",{className:"font-mono",children:[e.jsx("span",{className:"text-fg-dim",children:O(l.value)}),e.jsxs("span",{className:"ml-2 text-fg-faint",children:["from ",S[l.winner].label]})]})]}),l&&l.shadowed.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("dt",{children:"Shadowed"}),e.jsx("dd",{className:"space-y-0.5",children:l.shadowed.map((u,c)=>e.jsxs("div",{className:"font-mono text-fg-faint line-through",children:[O(u.value)," —"," ",e.jsx("span",{className:"no-underline",children:S[u.scope].label})]},c))})]}),(s==null?void 0:s.kind)==="array"&&e.jsxs(e.Fragment,{children:[e.jsx("dt",{children:"Accumulated"}),e.jsxs("dd",{className:"text-fg-dim",children:[s.items.length," items across all scopes"]})]})]}),e.jsx("div",{className:"pt-2 flex items-center gap-2 flex-wrap border-t border-line/60",children:e.jsx(nt,{keyName:t,node:s,info:n,onChange:o,targetScope:a})})]})}function nt({node:t,info:s,onChange:n,targetScope:a}){const r=(t==null?void 0:t.kind)==="leaf"?t.value:s==null?void 0:s.default,l=ie(s==null?void 0:s.type);if(l==="boolean"){const p=r===!0;return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-fg-faint",children:"Set to:"}),e.jsx("div",{className:"inline-flex rounded border border-line overflow-hidden",children:[{v:!0,label:"on"},{v:!1,label:"off"}].map(({v:u,label:c})=>e.jsx("button",{onClick:()=>n(u),className:`px-3 py-0.5 text-xs transition-colors ${p===u?"bg-accent text-bg":"bg-bg-elev text-fg-dim hover:bg-bg-hi hover:text-fg"}`,children:c},c))}),e.jsxs("span",{className:"text-fg-faint",children:["→ ",S[a].label]})]})}return s!=null&&s.enum?e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"text-fg-faint",children:"Choose:"}),s.enum.map(p=>{const u=le(r,p);return e.jsx("button",{onClick:()=>n(p),className:`px-2 py-0.5 text-xs rounded border ${u?"bg-accent text-bg border-accent":"bg-bg-elev text-fg-dim border-line hover:text-fg hover:bg-bg-hi"}`,children:String(p)},String(p))}),e.jsxs("span",{className:"text-fg-faint",children:["→ ",S[a].label]})]}):l==="integer"||l==="number"?e.jsx(rt,{value:typeof r=="number"?r:void 0,integer:l==="integer",onCommit:n,target:S[a].label}):l==="string"?e.jsx(at,{value:typeof r=="string"?r:"",onCommit:n,target:S[a].label}):e.jsxs("div",{className:"text-fg-faint",children:["Complex value (",l??"object/array",") — use the"," ",e.jsx("span",{className:"text-fg-dim",children:"Raw"})," tab to edit."]})}function rt({value:t,integer:s,onCommit:n,target:a}){const[o,r]=j.useState(t!==void 0?String(t):""),l=()=>{const p=s?parseInt(o,10):parseFloat(o);Number.isNaN(p)||n(p)};return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-fg-faint",children:"Set to:"}),e.jsx("input",{type:"number",value:o,onChange:p=>r(p.target.value),onBlur:l,onKeyDown:p=>{p.key==="Enter"&&p.target.blur()},className:"w-24 bg-bg border border-line rounded px-2 py-0.5 text-xs text-fg"}),e.jsxs("button",{onClick:l,className:"px-2 py-0.5 text-xs border border-accent/50 rounded text-accent hover:bg-accent hover:text-bg",children:["save → ",a]})]})}function at({value:t,onCommit:s,target:n}){const[a,o]=j.useState(t);return e.jsxs("div",{className:"flex items-center gap-2 flex-1 min-w-0",children:[e.jsx("span",{className:"text-fg-faint shrink-0",children:"Set to:"}),e.jsx("input",{type:"text",value:a,onChange:r=>o(r.target.value),onKeyDown:r=>{r.key==="Enter"&&s(a)},className:"flex-1 min-w-0 bg-bg border border-line rounded px-2 py-0.5 text-xs text-fg"}),e.jsxs("button",{onClick:()=>s(a),className:"shrink-0 px-2 py-0.5 text-xs border border-accent/50 rounded text-accent hover:bg-accent hover:text-bg",children:["save → ",n]})]})}function ot({node:t,info:s,onSet:n,disabled:a}){const o=(t==null?void 0:t.kind)==="leaf",r=ie(s==null?void 0:s.type);if(a)return null;if(r==="boolean"){const l=o&&t.value===!0;return e.jsx("button",{onClick:()=>n(!l),className:`px-2.5 py-0.5 text-xs rounded border transition-colors ${l?"bg-accent/15 text-accent border-accent/40 hover:bg-accent hover:text-bg":"bg-bg-elev text-fg-dim border-line hover:text-fg hover:bg-bg-hi"}`,title:"toggle",children:l?"on":"off"})}return null}function it({isSet:t,leafNode:s,defaultVal:n,isDefault:a,node:o}){return t?(o==null?void 0:o.kind)==="array"?{kind:"accumulated",label:`${o.items.length} items`}:(o==null?void 0:o.kind)==="object"?{kind:"set",label:"configured"}:s?a?{kind:"default",label:`= default · ${S[s.winner].label}`}:s.shadowed.length>0?{kind:"override",label:`overriding ${s.shadowed.length} scope(s)`}:{kind:"set",label:`set in ${S[s.winner].label}`}:{kind:"set",label:"configured"}:n!==void 0?{kind:"default",label:`using default: ${O(n)}`}:{kind:"unset",label:"not configured"}}function lt({kind:t,label:s}){const n={set:"bg-accent/15 text-accent border-accent/30",default:"bg-bg-hi text-fg-dim border-line",unset:"bg-bg-elev text-fg-faint border-line",override:"bg-purple-950/30 text-purple-400/80 border-purple-900/40",accumulated:"bg-blue-950/30 text-blue-400/80 border-blue-900/40"}[t];return e.jsx("span",{className:`text-[9px] px-1.5 py-0 rounded border uppercase tracking-wide ${n}`,children:s})}function ie(t){if(t)return Array.isArray(t)?t.find(n=>n!=="null")??t[0]:t}function le(t,s){return t===s?!0:typeof t!=typeof s?!1:t&&s&&typeof t=="object"?JSON.stringify(t)===JSON.stringify(s):!1}function ct(t){const s=t.trim().split(`
|
|
2
2
|
`)[0],n=s.match(/^([^.!?]+[.!?])/);return n?n[1]:s.length>120?s.slice(0,120)+"…":s}function O(t){if(typeof t=="string")return t===""?'""':JSON.stringify(t);if(t===null)return"null";if(t===void 0)return"—";if(typeof t=="object"){const s=JSON.stringify(t);return s.length>60?s.slice(0,60)+"…":s}return String(t)}function dt({cwd:t}){const[s,n]=j.useState(!1),[a,o]=j.useState(!1),[r,l]=j.useState(!1),[p,u]=j.useState(!1);j.useEffect(()=>{var i,d;let f=!1;return n(!1),Promise.resolve((d=(i=window.api.promptSessions)==null?void 0:i.getWorktreeDisabled)==null?void 0:d.call(i,{cwd:t})).then(h=>{f||(o((h==null?void 0:h.disabled)??!1),l((h==null?void 0:h.disabled)??!1),n(!0))},()=>{f||n(!0)}),()=>{f=!0}},[t]);const c=s&&r!==a,x=()=>{var f,i;u(!0),Promise.resolve((i=(f=window.api.promptSessions)==null?void 0:f.setWorktreeDisabled)==null?void 0:i.call(f,{cwd:t,disabled:r})).then(d=>{o((d==null?void 0:d.disabled)??r),l((d==null?void 0:d.disabled)??r)}).catch(d=>A.error(d instanceof Error?d.message:String(d))).finally(()=>u(!1))},v=()=>l(a);return e.jsxs("div",{"data-testid":"settings-epic-isolation",className:"border-b border-line bg-bg-elev px-3 py-2.5 text-[11.5px] leading-snug",children:[e.jsxs("label",{className:"flex items-start gap-2",children:[e.jsx("input",{type:"checkbox",checked:r,disabled:!s||p,onChange:f=>l(f.target.checked),"data-testid":"settings-epic-isolation-checkbox",className:"mt-0.5"}),e.jsxs("span",{children:[e.jsx("span",{className:"font-semibold text-fg",children:"Disable Epic worktree isolation for this project"}),e.jsxs("span",{className:"block text-fg-dim",children:["Off by default — each active Epic runs in its own isolated ",e.jsx("code",{children:"git worktree"})," (branch"," ",e.jsx("code",{children:"sm-epic/<id>"}),"), merged back to main at an explicit checkpoint. Turning this on makes every new Epic in this project run directly in the shared working tree instead, same as before this feature existed."]})]})]}),c&&e.jsx(Z,{dirty:c,busy:p,onSave:x,onRevert:v})]})}const q={user:{title:"Global settings",body:"This is the real ~/.claude/settings.json on disk — the same file the claude CLI reads on every session it starts. Edits apply machine-wide, to every project and every session."},project:{title:"Project settings",body:"This is the real <project>/.claude/settings.json on disk, checked into git. Edits apply to every current and future session in this project, for anyone who clones it."},local:{title:"Local settings",body:"This is the real <project>/.claude/settings.local.json on disk, gitignored. Edits apply to every current and future session in this project, on this machine only."}};function ut({effective:t,onOpenTab:s}){return e.jsx("ul",{"data-testid":"settings-owned-summaries",className:"px-3 py-2 space-y-1 text-[11.5px] border-b border-line",children:ne.map(n=>{const a=n.keys.filter(r=>ge(t,[r])!==null),o=a.length?`${a.length} of ${n.keys.length} keys set (${a.join(", ")})`:"nothing set";return e.jsxs("li",{"data-testid":`owned-summary-${n.id}`,className:"flex items-center gap-2 text-fg-dim",children:[e.jsx("span",{className:"font-semibold text-fg w-28 shrink-0",children:n.label}),e.jsx("span",{className:"truncate",children:o}),n.tab?e.jsxs("button",{type:"button",onClick:()=>s(n.tab),className:"ml-auto text-accent hover:underline shrink-0",children:["edit in ",n.label," tab →"]}):e.jsxs("span",{className:"ml-auto text-fg-faint shrink-0",children:["managed on the ",n.label," page"]})]},n.id)})})}function pt({scope:t="user"}={}){const s=L(),n=B(m=>m.tabs),a=B(m=>m.activeTabId),o=n.find(m=>m.id===a)??null,r=(o==null?void 0:o.cwd)??null,[l,p]=j.useState("general");me("settings",m=>{(m==="general"||m==="permissions"||m==="hooks"||m==="raw")&&p(m)});const u=H(Y,s,r),c=u[t]??null,x=T(m=>m.files),v=T(m=>m.setDraft),f=T(m=>m.saveJson),i=T(m=>m.revert),[d,h]=j.useState(null),g=j.useMemo(()=>xe(he(x,u)),[x,u]),N=(m,y,w)=>{var $;const _=w??t,E=u[_];if(!E)return;const R=(($=x[E])==null?void 0:$.draftRaw)??"";if(R.trim())try{JSON.parse(R)}catch(P){h(`${E} is not valid JSON (${P instanceof Error?P.message:String(P)}) — fix it in Raw before editing from General.`);return}h(null),window.api.claudeConfig.patch({fileId:"settings",scope:_,cwd:r,keyPath:m,value:y}).catch(P=>A.error(P instanceof Error?P.message:String(P)))};if(!s)return e.jsx(C,{title:"loading…"});const b=c?x[c]:null,k=m=>m!=="user"&&!r;return e.jsx(F,{toolbar:e.jsxs(e.Fragment,{children:[e.jsx(U,{options:[{key:"general",label:"General"},{key:"permissions",label:"Permissions"},{key:"hooks",label:"Hooks"},{key:"raw",label:"Raw"}],active:l,onChange:p}),e.jsx(e.Fragment,{children:e.jsx("span",{className:"ml-3 text-fg-faint truncate",children:l==="general"?`overrides → ${c??"—"}`:c??"—"})}),e.jsx("div",{className:"flex-1"}),e.jsx("a",{href:"https://code.claude.com/docs/en/settings",target:"_blank",rel:"noreferrer",className:"text-fg-faint hover:text-fg-dim underline-offset-2 hover:underline",children:"schema reference ↗"})]}),footer:l==="raw"&&c&&b?e.jsx(Z,{dirty:b.dirty,busy:b.busy,parseError:d||b.parseError,lastSavedAt:b.lastSavedAt,leading:b.exists?null:e.jsx("span",{children:"file will be created on save"}),onSave:async()=>{h(null);const m=await f(c);m.ok||h(m.error??"save failed")},onRevert:()=>{h(null),i(c)}}):null,children:e.jsxs(e.Fragment,{children:[e.jsxs("div",{"data-testid":"settings-scope-note",className:"sticky top-0 z-10 border-b border-line bg-bg-elev px-3 py-2 text-[11.5px] leading-snug",children:[e.jsx("span",{className:"font-semibold text-fg",children:q[t].title}),e.jsx("span",{className:"mx-1.5 text-fg-faint",children:"·"}),e.jsx("span",{className:"text-fg-dim",children:q[t].body}),c&&e.jsx("span",{className:"ml-1.5 font-mono text-fg-faint",children:c})]}),d&&l!=="raw"&&e.jsx("div",{role:"alert",className:"px-3 py-2 border-b border-line text-xs text-red-400",children:d}),t==="project"&&r&&e.jsx(dt,{cwd:r}),k(t)?e.jsx(C,{title:"no active project",hint:"open a tab in a project directory to edit project or local settings"}):l==="general"?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"px-3 pt-2",children:e.jsx(I,{path:c??""})}),e.jsx(ut,{effective:g,onOpenTab:p}),e.jsx(Ye,{node:g,targetScope:t,onOverride:N,schema:X()})]}):l==="permissions"?c?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"px-3 pt-2",children:e.jsx(I,{path:c,keyPath:["permissions"]})}),e.jsx(ee,{scope:t,cwd:r,activePath:c})]}):e.jsx(C,{title:"resolving…"}):l==="hooks"?c?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"px-3 pt-2",children:e.jsx(I,{path:c,keyPath:["hooks"]})}),e.jsx(se,{scope:t,cwd:r,path:c})]}):e.jsx(C,{title:"resolving…"}):c&&b?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"px-3 pt-2",children:e.jsx(I,{path:c})}),e.jsx(fe,{path:c,value:b.draftRaw,onChange:m=>{h(null),v(c,m)}})]}):e.jsx(C,{title:"resolving…"})]})})}const wt=j.memo(pt);export{q as SETTINGS_SCOPE_NOTES,wt as Settings};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{aJ as Z,R as wo,aq as ko,at as tr}from"./index-
|
|
1
|
+
import{aJ as Z,R as wo,aq as ko,at as tr}from"./index-CuAfFXNd.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.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{b9 as p,aJ as d,ak as g,at as o,b7 as b}from"./index-
|
|
1
|
+
import{b9 as p,aJ as d,ak as g,at as o,b7 as b}from"./index-CuAfFXNd.js";function h(e,t){return t&&(e===t||e.startsWith(t+"/"))?"~"+e.slice(t.length):e}function w({path:e,keyPath:t,note:l}){const u=p(),[n,r]=d.useState(void 0);d.useEffect(()=>{let i=!0;const c=()=>{window.api.config.readText(e,{maxBytes:1}).then(s=>{i&&r(s.exists?s.mtimeMs:null)}).catch(()=>{i&&r(void 0)})};c();const x=window.api.config.onChanged(s=>{s.path===e&&c()});return()=>{i=!1,x()}},[e]);const f=h(e,u)+(t&&t.length?` › ${t.join(".")}`:""),a=n===void 0?"":n===null?"created on first save":g(n),m=()=>{b.getState().openFile(e),window.dispatchEvent(new CustomEvent("sm:open-editor"))};return o.jsxs("button",{type:"button","data-testid":"source-chip",title:l??`Open ${e} in the editor`,onClick:m,className:"inline-flex items-center gap-1.5 max-w-full text-[11px] px-2 py-0.5 rounded border border-line bg-bg-elev text-fg-dim hover:bg-bg-hi",children:[o.jsx("span",{className:"font-mono truncate","data-testid":"source-chip-path",children:f}),a&&o.jsxs("span",{className:"text-fg-dim/70 shrink-0","data-testid":"source-chip-age",children:["· ",a]})]})}export{w as S};
|