claude-code-session-manager 0.62.1 → 0.64.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/dist/assets/AgentLibrary-9KJ4fedH.js +1 -0
  2. package/dist/assets/History-Dp3-_bjQ.js +2 -0
  3. package/dist/assets/Hooks-DMQFgGDd.js +3 -0
  4. package/dist/assets/HostBilko-zNU1NtBh.js +1 -0
  5. package/dist/assets/Library-BrODBbeL.js +46 -0
  6. package/dist/assets/ListDetail-C5vbA1gC.js +1 -0
  7. package/dist/assets/MarkdownEditor-CpzAEiiG.js +1 -0
  8. package/dist/assets/McpServers-DWuw-flj.js +2 -0
  9. package/dist/assets/Memory-B4TC9SsJ.js +8 -0
  10. package/dist/assets/Panel-Bap7G-pI.js +1 -0
  11. package/dist/assets/Permissions-BIpNWItH.js +3 -0
  12. package/dist/assets/Plugins-DrwklmW4.js +2 -0
  13. package/dist/assets/ProvenanceBadge-CCp_EhjV.js +1 -0
  14. package/dist/assets/Scheduler-DfoTegGG.js +14 -0
  15. package/dist/assets/ScopeSwitcher-BlQvpyLE.js +1 -0
  16. package/dist/assets/Settings-BzvmZvGa.js +3 -0
  17. package/dist/assets/SkillReferenceGraph-CGtwmCjm.js +46 -0
  18. package/dist/assets/Skills-Cauvbtk7.js +3 -0
  19. package/dist/assets/SystemPrompt-BqzM76PV.js +1 -0
  20. package/dist/assets/TagLibrary-DVKPjeRu.js +1 -0
  21. package/dist/assets/{TiptapBody-BwN4pNC0.js → TiptapBody-CUWdBAYf.js} +1 -1
  22. package/dist/assets/Toggle-Bos67yDJ.js +1 -0
  23. package/dist/assets/index-BfPVknuV.js +3066 -0
  24. package/dist/assets/{index-CVCCMw5o.css → index-LlWpj2VJ.css} +1 -1
  25. package/dist/assets/listSkills-QORduPIk.js +1 -0
  26. package/dist/assets/settingsSchema-DKuyaEK5.js +3 -0
  27. package/dist/assets/skillFrontmatter-Dif5JIg7.js +10 -0
  28. package/dist/index.html +2 -2
  29. package/package.json +1 -3
  30. package/src/main/__tests__/config-readText-bounded.test.cjs +84 -0
  31. package/src/main/__tests__/heapSnapshot.test.cjs +121 -0
  32. package/src/main/__tests__/historyAggregatorIntraday.test.cjs +313 -0
  33. package/src/main/__tests__/runLogRetention.test.cjs +430 -0
  34. package/src/main/__tests__/transcripts-batch-flush.test.cjs +249 -0
  35. package/src/main/config.cjs +31 -7
  36. package/src/main/health.cjs +32 -0
  37. package/src/main/heapSnapshot.cjs +122 -0
  38. package/src/main/historyAggregator.cjs +176 -36
  39. package/src/main/index.cjs +29 -0
  40. package/src/main/ipcSchemas.cjs +9 -0
  41. package/src/main/lib/runLogRetention.cjs +379 -0
  42. package/src/main/transcripts.cjs +29 -5
  43. package/src/preload/api.d.ts +16 -2
  44. package/src/preload/index.cjs +11 -2
  45. package/dist/assets/index-ZjTDk5b7.js +0 -3197
@@ -0,0 +1,2 @@
1
+ import{I as e,X as c,a9 as oe,a5 as ie,ab as ce,a7 as N,c as O,a as Z,a4 as q}from"./index-BfPVknuV.js";import{P as $}from"./Panel-Bap7G-pI.js";import{L as de}from"./ListDetail-C5vbA1gC.js";import{a as Y,S as xe}from"./ScopeSwitcher-BlQvpyLE.js";import{P as G}from"./ProvenanceBadge-CCp_EhjV.js";import{M as ue,V as D}from"./Library-BrODBbeL.js";import"./monaco-editor-BW5C4Iv1.js";const pe={live:"bg-emerald-400",idle:"bg-amber-400",offline:"bg-fg-faint",attention:"bg-accent",paused:"bg-zinc-500"},fe={sm:"w-1.5 h-1.5",md:"w-2 h-2"},me={on:"live",off:"offline",warn:"attention",live:"live",idle:"idle"};function Q({state:n,kind:t,pulse:a=!1,size:d="sm",className:p="",title:b,"aria-label":o}){const j=n??(t?me[t]:"idle"),r=pe[j],h=fe[d],x=a?"animate-pulse":"",u=o??b??j;return e.jsx("span",{role:"img","aria-label":u,className:`inline-block rounded-full ${h} ${r} ${x} ${p}`.trim(),title:b})}const ge={failed:"Failed","needs-auth":"Needs auth",pending:"Pending approval"};function H(n,t){const a=t!=null&&t.ok?t.servers.find(d=>d.name===n):void 0;return!a||a.status==="unknown"?{state:"unprobed",label:"Not checked",probeStatus:(a==null?void 0:a.status)??null,badgeTone:"dim",dotState:"offline"}:a.status==="connected"?{state:"ready",label:"Ready",probeStatus:a.status,badgeTone:"good",dotState:"live"}:{state:"not-ready",label:ge[a.status],probeStatus:a.status,badgeTone:"warn",dotState:"attention"}}const U=(n,t)=>({type:"mcp",name:n,command:t.command,args:t.args,url:t.url}),he=["stdio","http","streamable-http","sse","ws"],be=new Set(["workspace"]),je=new Set(["ide","tasks"]);function ve(n,t,a){return n==="user"?`${t}/.claude.json`:a?`${a}/.mcp.json`:null}function ye(n){if(n.trim()==="")return{full:{},servers:{},err:null};try{const t=JSON.parse(n),a=t.mcpServers??{};return{full:t,servers:a,err:null}}catch(t){return{full:{},servers:{},err:t.message}}}function Ne(n,t){return JSON.stringify({...n,mcpServers:t},null,2)+`
2
+ `}function we(n){let t=Object.keys(n).length+1,a=`server-${t}`;for(;n[a];)t+=1,a=`server-${t}`;return a}function Se(){const n=oe(),t=ie(),a=(t==null?void 0:t.cwd)??null,d=ce(s=>s.navFace),p=c.useRef(!1),b=c.useRef(d),[o,j]=c.useState(()=>d==="project"&&a?"project":"user"),[r,h]=c.useState(null),[x,u]=c.useState("installed"),[w,_]=c.useState("");c.useEffect(()=>{if(b.current!==d){if(b.current=d,p.current){p.current=!1;return}j(d==="project"&&a?"project":"user")}},[d,a]);const f=c.useMemo(()=>n?ve(o,n,a):null,[n,o,a]),k=N(s=>s.files),l=N(s=>s.loadJson),v=N(s=>s.setDraft),m=N(s=>s.saveJson),I=N(s=>s.revert),T=N(s=>s.watchFile),W=N(s=>s.unwatchFile);c.useEffect(()=>{if(f)return k[f]||l(f),T(f),()=>W(f)},[f]);const[ee,R]=c.useState(null),[J,z]=c.useState(null),[B,K]=c.useState(!1),F=c.useRef(0),A=c.useRef(!0);c.useEffect(()=>()=>{A.current=!1},[]);const V=async()=>{const s=++F.current;K(!0);try{const i=await window.api.mcp.status();if(!A.current||s!==F.current)return;z(i),i.ok||q.error(i.error??"MCP status probe failed")}catch(i){if(!A.current||s!==F.current)return;z(null),q.error(i.message||"MCP status probe failed")}finally{A.current&&s===F.current&&K(!1)}};if(c.useEffect(()=>{V()},[]),!n)return e.jsx(O,{title:"loading…"});if(x==="library")return e.jsx($,{toolbar:e.jsx(D,{active:x,onChange:u}),children:e.jsx(ue,{})});if(o==="project"&&!a)return e.jsx($,{toolbar:e.jsxs(e.Fragment,{children:[e.jsx(D,{active:x,onChange:u}),e.jsx("span",{className:"mx-2 text-fg-faint",children:"·"}),e.jsx(Y,{scopes:["user","project"],active:o,onChange:s=>{p.current=!0,j(s)}})]}),children:e.jsx(O,{title:"no active project"})});if(!f)return e.jsx(O,{title:"loading…"});const y=k[f],{full:te,servers:g,err:se}=y?ye(y.draftRaw):{full:{},servers:{},err:null},L=Object.keys(g).sort(),M=r?g[r]:null,P=s=>{R(null),v(f,Ne(te,s))},ae=()=>{const s=we(g);P({...g,[s]:{type:"stdio",command:"",args:[]}}),h(s)},le=s=>{const i={...g};delete i[s],P(i),r===s&&h(null)},ne=(s,i)=>{if(!i||i===s||g[i])return;const S={};for(const C of Object.keys(g))S[C===s?i:C]=g[C];P(S),h(i)},re=(s,i)=>{P({...g,[s]:i})};return e.jsx($,{toolbar:e.jsxs(e.Fragment,{children:[e.jsx(D,{active:x,onChange:u}),e.jsx("span",{className:"mx-2 text-fg-faint",children:"·"}),e.jsx(Y,{scopes:["user","project"],active:o,onChange:s=>{p.current=!0,j(s)}}),e.jsxs("span",{className:"ml-3 px-1.5 py-0.5 text-[10px] rounded border border-line text-fg-faint",children:[L.length," server",L.length===1?"":"s"]}),e.jsx("span",{className:"ml-2 text-fg-faint truncate",children:f}),e.jsx("div",{className:"flex-1"}),r&&M&&e.jsx(G,{scope:o,input:U(r,M),className:"mr-2"}),e.jsx("button",{onClick:V,disabled:B,className:"px-2 py-0.5 text-xs border border-line rounded text-fg-dim hover:text-fg hover:bg-bg-hi disabled:opacity-50 mr-2",children:B?"checking…":"⟳ test connections"}),e.jsx("button",{onClick:ae,className:"px-2 py-0.5 text-xs border border-line rounded text-fg-dim hover:text-fg hover:bg-bg-hi",children:"+ new server"})]}),footer:y?e.jsx(xe,{dirty:y.dirty,busy:y.busy,parseError:ee||se||y.parseError,lastSavedAt:y.lastSavedAt,onSave:async()=>{R(null);const s=await m(f);s.ok||R(s.error??"save failed")},onRevert:()=>{R(null),I(f)}}):null,children:e.jsx(de,{sidebar:e.jsxs("div",{className:"py-2",children:[e.jsx("div",{className:"px-2 pb-1",children:e.jsx("input",{value:w,onChange:s=>_(s.target.value),placeholder:"filter…",className:"w-full bg-bg border border-line rounded px-2 py-0.5 text-xs text-fg"})}),L.length===0?e.jsx("div",{className:"px-3 py-1 text-xs text-fg-faint italic",children:"no servers"}):L.filter(s=>!w||s.toLowerCase().includes(w.toLowerCase())).map(s=>{var C;const i=H(s,J),S=(C=g[s].description)==null?void 0:C.trim();return e.jsxs("button",{onClick:()=>h(s),className:`w-full text-left px-3 py-1 text-xs flex flex-col gap-0.5 ${r===s?"bg-bg-hi text-fg":"text-fg-dim hover:text-fg hover:bg-bg-hi"}`,children:[e.jsxs("span",{className:"flex items-center gap-2 justify-between w-full",children:[e.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[e.jsx(Q,{state:i.dotState,title:i.label}),e.jsx("span",{className:"truncate",children:s})]}),e.jsxs("span",{className:"ml-2 flex items-center gap-2 shrink-0",children:[e.jsx(Z,{tone:i.badgeTone,children:i.label}),e.jsx(G,{interactive:!1,scope:o,input:U(s,g[s])}),e.jsx("span",{className:"text-fg-faint",children:g[s].type??"stdio"})]})]}),S?e.jsx("span",{className:"pl-5 text-fg-faint truncate",title:S,children:S}):null]},s)})]}),detail:r&&M?e.jsx(Ce,{name:r,server:M,connection:H(r,J),onTestConnection:V,testing:B,onRename:s=>ne(r,s),onChange:s=>re(r,s),onRemove:()=>le(r)}):e.jsx(O,{title:"select a server or click + new"})})})}const Me=c.memo(Se);function Ce({name:n,server:t,connection:a,onTestConnection:d,testing:p,onRename:b,onChange:o,onRemove:j}){var k;const r=t.type??"stdio",h=be.has(n),x=je.has(n),u=(k=t.permissions)==null?void 0:k.tools,w=u===void 0?"inherit":u==="allow"?"allow":u==="deny"?"deny":"list",_=Array.isArray(u)?u:[],f=(t.disabledTools??[]).join(", ");return e.jsxs("div",{className:"p-4 space-y-4 max-w-2xl",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Q,{state:a.dotState,size:"md",title:a.label}),e.jsx(Z,{tone:a.badgeTone,children:a.label}),e.jsx("button",{onClick:d,disabled:p,className:"ml-auto px-2 py-0.5 text-xs border border-line rounded text-fg-dim hover:text-fg hover:bg-bg-hi disabled:opacity-50",children:p?"checking…":"test connection"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("label",{className:"text-xs text-fg-faint w-20",children:"name"}),e.jsx("input",{defaultValue:n,onBlur:l=>b(l.target.value.trim()),className:"flex-1 bg-bg-elev border border-line rounded px-2 py-1 text-xs text-fg font-mono"}),e.jsx("button",{onClick:j,className:"text-xs text-fg-faint hover:text-red-400 px-2 py-1 border border-line rounded",children:"delete"})]}),e.jsx(E,{label:"description",value:t.description??"",onChange:l=>o({...t,description:l||void 0}),placeholder:"what this server does…"}),h?e.jsxs("div",{className:"text-xs px-2 py-1 border border-red-500/50 rounded text-red-300 bg-red-500/5",children:["⚠ ",e.jsx("span",{className:"font-mono",children:n})," is a reserved name — Claude Code will refuse to load this server (v2.1.128+)."]}):x?e.jsxs("div",{className:"text-xs px-2 py-1 border border-yellow-600/50 rounded text-yellow-200 bg-yellow-500/5",children:["⚠ ",e.jsx("span",{className:"font-mono",children:n})," collides with a commonly-bundled MCP name; expect surprises in other tools."]}):null,e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("label",{className:"text-xs text-fg-faint w-20",children:"type"}),e.jsx("select",{value:r,onChange:l=>o({...t,type:l.target.value}),className:"bg-bg-elev border border-line rounded px-2 py-1 text-xs text-fg",children:he.map(l=>e.jsx("option",{value:l,children:l},l))}),r==="sse"?e.jsx("span",{className:"text-xs text-yellow-400/80",children:"sse is deprecated — prefer streamable-http"}):null]}),r==="stdio"?e.jsxs(e.Fragment,{children:[e.jsx(E,{label:"command",value:t.command??"",onChange:l=>o({...t,command:l}),placeholder:"npx / node / python …"}),e.jsx(E,{label:"args",value:(t.args??[]).join(" "),onChange:l=>o({...t,args:l.split(/\s+/).filter(Boolean)}),placeholder:"space-separated args"}),e.jsx(X,{label:"env",value:t.env??{},onChange:l=>o({...t,env:l})})]}):e.jsxs(e.Fragment,{children:[e.jsx(E,{label:"url",value:t.url??"",onChange:l=>o({...t,url:l}),placeholder:"https://…"}),e.jsx(X,{label:"headers",value:t.headers??{},onChange:l=>o({...t,headers:l})})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("label",{className:"text-xs text-fg-faint w-20",children:"alwaysLoad"}),e.jsxs("label",{className:"flex items-center gap-2 text-xs text-fg",children:[e.jsx("input",{type:"checkbox",checked:t.alwaysLoad===!0,onChange:l=>o({...t,alwaysLoad:l.target.checked||void 0})}),e.jsx("span",{className:"text-fg-dim",children:"bypass tool-search deferral (v2.1.121+)"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("label",{className:"text-xs text-fg-faint w-20",children:"enabled"}),e.jsxs("label",{className:"flex items-center gap-2 text-xs text-fg",children:[e.jsx("input",{type:"checkbox",checked:t.enabled!==!1,onChange:l=>o({...t,enabled:l.target.checked?void 0:!1})}),e.jsx("span",{className:"text-fg-dim",children:"load this server in new sessions"})]})]}),e.jsx(E,{label:"disabledTools",value:f,onChange:l=>{const v=l.split(",").map(m=>m.trim()).filter(Boolean);o({...t,disabledTools:v.length?v:void 0})},placeholder:"comma-separated tool names to hide"}),e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("label",{className:"text-xs text-fg-faint w-20 pt-1",children:"permissions"}),e.jsxs("div",{className:"flex-1 space-y-1",children:[e.jsxs("select",{value:w,onChange:l=>{const v=l.target.value,m={...t};if(v==="inherit"){if(m.permissions){const{tools:I,...T}=m.permissions;m.permissions=Object.keys(T).length?T:void 0}}else v==="list"?m.permissions={...m.permissions??{},tools:[]}:m.permissions={...m.permissions??{},tools:v};o(m)},className:"bg-bg-elev border border-line rounded px-2 py-1 text-xs text-fg",children:[e.jsx("option",{value:"inherit",children:"inherit (default)"}),e.jsx("option",{value:"allow",children:"allow all tools"}),e.jsx("option",{value:"deny",children:"deny all tools"}),e.jsx("option",{value:"list",children:"allowlist…"})]}),w==="list"?e.jsx("input",{value:_.join(", "),onChange:l=>{const v=l.target.value.split(",").map(m=>m.trim()).filter(Boolean);o({...t,permissions:{...t.permissions??{},tools:v}})},placeholder:"comma-separated tool names",className:"w-full bg-bg-elev border border-line rounded px-2 py-1 text-xs text-fg font-mono"}):null]})]})]})}function E({label:n,value:t,onChange:a,placeholder:d}){return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("label",{className:"text-xs text-fg-faint w-20",children:n}),e.jsx("input",{value:t,onChange:p=>a(p.target.value),placeholder:d,className:"flex-1 bg-bg-elev border border-line rounded px-2 py-1 text-xs text-fg font-mono"})]})}function X({label:n,value:t,onChange:a}){const[d,p]=c.useState(""),[b,o]=c.useState(""),j=Object.entries(t);return e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("label",{className:"text-xs text-fg-faint w-20 pt-1",children:n}),e.jsxs("div",{className:"flex-1 space-y-1",children:[j.map(([r,h])=>e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{value:r,onChange:x=>{const u={...t};delete u[r],u[x.target.value]=h,a(u)},className:"w-32 bg-bg-elev border border-line rounded px-2 py-0.5 text-xs text-fg font-mono"}),e.jsx("input",{value:h,onChange:x=>a({...t,[r]:x.target.value}),className:"flex-1 bg-bg-elev border border-line rounded px-2 py-0.5 text-xs text-fg font-mono"}),e.jsx("button",{onClick:()=>{const x={...t};delete x[r],a(x)},className:"text-fg-faint hover:text-red-400 text-xs px-1",children:"×"})]},r)),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{value:d,onChange:r=>p(r.target.value),placeholder:"key",className:"w-32 bg-bg border border-line rounded px-2 py-0.5 text-xs text-fg-dim font-mono"}),e.jsx("input",{value:b,onChange:r=>o(r.target.value),placeholder:"value",className:"flex-1 bg-bg border border-line rounded px-2 py-0.5 text-xs text-fg-dim font-mono"}),e.jsx("button",{onClick:()=>{d.trim()&&(a({...t,[d.trim()]:b}),p(""),o(""))},className:"px-2 text-xs border border-line rounded text-fg-dim hover:text-fg hover:bg-bg-hi",children:"+"})]})]})]})}export{Me as McpServers,we as nextServerName};
@@ -0,0 +1,8 @@
1
+ import{a9 as Y,a5 as K,X as l,a4 as A,I as e,c as W,p as oe,u as H,s as le,x as I,V as q}from"./index-BfPVknuV.js";import{P as ee}from"./Panel-Bap7G-pI.js";import{L as te}from"./ListDetail-C5vbA1gC.js";import{M as se}from"./MarkdownEditor-CpzAEiiG.js";import"./monaco-editor-BW5C4Iv1.js";function ie(t){return!t||!t.trim()?"default":t.replace(/[^a-zA-Z0-9]/g,"-")}const re=/^[a-z0-9-_]+$/;function ce(t,o,r,i){return t.filter(m=>!o||m.name.toLowerCase().includes(o.toLowerCase())).filter(m=>{var s;return!r||((s=i[m.name])==null?void 0:s.stale)===!0})}const de=["Commands:"," list — show all memory entries"," show <slug> — read one entry"," search <text> — find entries containing <text>"," forget <slug> — delete an entry (with confirm)"," remember <free-form> — ask Claude to save this"," help — this message","","Anything else: I will offer to send it to Claude in the terminal,","or add it as a new memory entry directly."].join(`
2
+ `);function me(t){const o=t.trim();if(!o)return{kind:"freeform",arg:"",raw:t};const r=o.toLowerCase();if(r==="help"||r==="?")return{kind:"help",arg:"",raw:t};if(r==="list"||r==="ls"||r==="list memories"||r==="list all"||r==="what do you remember"||r==="what do you remember?")return{kind:"list",arg:"",raw:t};const i=o.match(/^(?:show|read|open)\s+(.+)$/i);if(i)return{kind:"show",arg:i[1].trim(),raw:t};const m=o.match(/^(?:forget|delete|remove)\s+(.+)$/i);if(m)return{kind:"forget",arg:m[1].trim(),raw:t};const s=o.match(/^(?:search|find)\s+(.+)$/i)||o.match(/^what (?:do )?you know about\s+(.+?)\??$/i);if(s)return{kind:"search",arg:s[1].trim(),raw:t};const u=o.match(/^remember(?:\s+that)?\s+(.+)$/i)||o.match(/^note(?:\s+that)?\s+(.+)$/i)||o.match(/^save(?:\s+that)?\s+(.+)$/i);return u?{kind:"remember",arg:u[1].trim(),raw:t}:{kind:"freeform",arg:o,raw:t}}function G(t,o){const r=t.toLowerCase().replace(/\.md$/,""),i=o.find(u=>u.name.replace(/\.md$/,"").toLowerCase()===r);if(i)return i;const m=o.filter(u=>u.name.replace(/\.md$/,"").toLowerCase().startsWith(r));if(m.length===1)return m[0];const s=o.filter(u=>u.name.replace(/\.md$/,"").toLowerCase().includes(r));return s.length===1?s[0]:null}function Z(t){const o=new Set(["the","a","an","is","are","to","of","in","for","and","or"]);return t.toLowerCase().replace(/[^a-z0-9\s-]/g," ").split(/\s+/).filter(m=>m&&!o.has(m)).slice(0,4).join("-").replace(/-+/g,"-").replace(/^-|-$/g,"")||`note-${Date.now().toString(36).slice(-4)}`}function X(t,o){return[`Please save this to my workspace memory (workspace: ${t}).`,`Use the memory tool (or write a markdown file under ~/.claude/projects/${t}/memory/).`,"Pick a short kebab-case filename and add a one-line title at the top.","","Memory to save:",o].join(`
3
+ `)}function Q(){return`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`}function xe({workspace:t,entries:o,onChanged:r}){const i=Y(),m=K(),s=(m==null?void 0:m.id)??null,[u,f]=l.useState(""),[c,b]=l.useState(()=>[{id:Q(),role:"system",text:"Hi — I am the memory assistant for this workspace. Type `help` for what I understand, or just talk to me."}]),[C,g]=l.useState(!1),N=l.useRef(null),$=l.useRef(null);l.useEffect(()=>{const a=N.current;a&&(a.scrollTop=a.scrollHeight)},[c]);const x=l.useCallback(a=>{b(p=>[...p,{...a,id:Q()}])},[]),S=l.useCallback(()=>{if(o.length===0){x({role:"result",text:"No memories saved for this workspace yet."});return}x({role:"result",text:`Found ${o.length} ${o.length===1?"memory":"memories"}:`,payload:{kind:"entries",entries:o}})},[o,x]),T=l.useCallback(async a=>{const p=G(a,o);if(!p){x({role:"result",text:`No memory matches "${a}". Try \`list\` to see what is here.`});return}const y=await window.api.memory.read(p.name,t);if(y.error){A.error(`Memory read failed: ${y.error}`),x({role:"result",text:`Read failed: ${y.error}`});return}x({role:"result",text:`${p.name}`,payload:{kind:"entry",entry:p,content:y.content}})},[o,t,x]),B=l.useCallback(async a=>{const p=a.toLowerCase(),y=o.filter(k=>k.name.toLowerCase().includes(p)),O=[];for(const k of o){if(y.includes(k))continue;const L=await window.api.memory.read(k.name,t);if(L.error)continue;const d=L.content.split(`
4
+ `),h=d.findIndex(w=>w.toLowerCase().includes(p));h>=0&&O.push({entry:k,snippet:d[h].trim().slice(0,200)})}const n=[...y.map(k=>({entry:k,snippet:"(filename match)"})),...O];if(n.length===0){x({role:"result",text:`No matches for "${a}".`});return}x({role:"result",text:`Found ${n.length} ${n.length===1?"match":"matches"} for "${a}":`,payload:{kind:"search",query:a,hits:n}})},[o,t,x]),D=l.useCallback(async a=>{const p=G(a,o);if(!p){x({role:"result",text:`No memory matches "${a}". Try \`list\` to see what is here.`});return}if(!window.confirm(`Delete memory "${p.name}"? This cannot be undone.`))return;const y=await window.api.memory.delete(p.name,t);if(!y.ok){A.error(`Memory delete failed: ${y.error??"unknown error"}`),x({role:"result",text:`Delete failed: ${y.error??"unknown error"}`});return}x({role:"result",text:`Deleted ${p.name}.`}),r()},[o,t,x,r]),v=l.useCallback(a=>{const p=Z(a),y=X(t,a);x({role:"result",text:"I do not write to memory from this panel. Send the request to Claude in the active terminal, or add it directly as a new memory entry below.",payload:{kind:"suggest-send",prompt:y,original:a}}),x({role:"result",text:`Add it directly as \`${p}.md\` instead?`,payload:{kind:"suggest-add",slug:p,content:a}})},[t,x]),_=l.useCallback(a=>{const p=Z(a),y=X(t,a);x({role:"result",text:"Not a recognised command. Options:",payload:{kind:"suggest-send",prompt:y,original:a}}),x({role:"result",text:`…or save it directly as \`${p}.md\`.`,payload:{kind:"suggest-add",slug:p,content:a}})},[t,x]),M=l.useCallback(async a=>{g(!0);try{switch(a.kind){case"list":S();break;case"show":await T(a.arg);break;case"search":await B(a.arg);break;case"forget":await D(a.arg);break;case"help":x({role:"result",text:de});break;case"remember":v(a.arg);break;case"freeform":_(a.arg);break}}finally{g(!1)}},[S,T,B,D,v,_,x]),R=l.useCallback(async()=>{const a=u.trim();!a||C||(f(""),x({role:"user",text:a}),await M(me(a)))},[u,C,M,x]),j=a=>{a.key==="Enter"&&!a.shiftKey&&(a.preventDefault(),R())},E=l.useCallback(a=>{if(!s){A.error("No active terminal session — open or focus a tab first.");return}window.api.pty.write({tabId:s,data:a}),A.info("Prompt sent to active terminal (not submitted)")},[s]),P=l.useCallback(async(a,p)=>{if(!re.test(a)){A.error(`Invalid slug "${a}" — must be [a-z0-9-_]+`);return}const y=`${a}.md`,O=await window.api.memory.create(y,void 0,t);if(!O.ok){A.error(`Create failed: ${O.error??"unknown error"}`);return}const n=await window.api.memory.read(y,t),k=n.error?p:`${n.content.trimEnd()}
5
+
6
+ ${p}
7
+ `,L=await window.api.memory.write(y,k,t);if(!L.ok){A.error(`Write failed: ${L.error??"unknown error"}`);return}x({role:"result",text:`Saved as ${y}.`}),r()},[t,x,r]),F=l.useMemo(()=>[{label:"List memories",value:"list"},{label:"Help",value:"help"},{label:"Search…",value:"search "},{label:"Remember…",value:"remember "}],[]);return i?e.jsxs("div",{className:"h-full flex flex-col",children:[e.jsxs("div",{ref:N,className:"flex-1 min-h-0 overflow-y-auto px-3 py-2 space-y-2",children:[c.map(a=>e.jsx(ue,{message:a,entries:o,onShow:p=>{var y;f(`show ${p.replace(/\.md$/,"")}`),(y=$.current)==null||y.focus()},onSendToClaude:E,onAddDirect:P},a.id)),C&&e.jsx("div",{className:"text-xs text-fg-faint italic",children:"working…"})]}),e.jsxs("div",{className:"shrink-0 border-t border-line px-3 py-2 space-y-2",children:[e.jsx("div",{className:"flex gap-1 flex-wrap",children:F.map(a=>e.jsx("button",{onClick:()=>{var p;f(a.value),(p=$.current)==null||p.focus()},className:"px-2 py-0.5 text-[11px] text-fg-faint hover:text-fg-dim border border-line hover:border-fg-faint rounded transition-colors",children:a.label},a.label))}),e.jsxs("div",{className:"flex gap-2 items-end",children:[e.jsx(oe,{}),e.jsx("textarea",{ref:$,value:u,onChange:a=>f(a.target.value),onKeyDown:j,placeholder:"Type `list`, `show <slug>`, `search <text>`, `remember …`, or talk freely. Enter to send, Shift+Enter for newline.",rows:2,className:"flex-1 bg-bg border border-line rounded px-2 py-1 text-xs text-fg resize-none focus:outline-none focus:border-fg-faint"}),e.jsx("button",{onClick:R,disabled:!u.trim()||C,className:"px-3 py-1 text-xs text-fg border border-line hover:bg-bg-hi rounded transition-colors disabled:opacity-40 disabled:cursor-not-allowed",children:"Send"})]}),e.jsxs("div",{className:"text-[10px] text-fg-faint",children:["Workspace: ",e.jsx("span",{className:"font-mono",children:t}),!s&&e.jsx("span",{className:"ml-2 text-amber-400",children:"(no active terminal — Send-to-Claude disabled)"})]})]})]}):e.jsx(W,{title:"loading…"})}function ue({message:t,entries:o,onShow:r,onSendToClaude:i,onAddDirect:m}){var u,f,c,b,C;const s=t.role==="user"?"bg-bg-hi text-fg ml-8":t.role==="system"?"bg-bg text-fg-dim italic":"bg-bg text-fg-dim";return e.jsxs("div",{className:`text-xs rounded border border-line px-3 py-2 ${s}`,children:[e.jsx("div",{className:"whitespace-pre-wrap font-mono text-[11px] leading-relaxed",children:t.text}),((u=t.payload)==null?void 0:u.kind)==="entries"&&e.jsx("div",{className:"mt-2 space-y-0.5",children:t.payload.entries.map(g=>e.jsxs("button",{onClick:()=>r(g.name),className:"block w-full text-left px-2 py-0.5 text-[11px] text-fg-dim hover:text-fg hover:bg-bg-hi rounded font-mono",children:[g.name," ",e.jsxs("span",{className:"text-fg-faint",children:["(",H(g.bytes),")"]})]},g.name))}),((f=t.payload)==null?void 0:f.kind)==="entry"&&e.jsx("pre",{className:"mt-2 max-h-64 overflow-auto px-2 py-1 bg-bg-hi rounded text-[11px] whitespace-pre-wrap text-fg",children:t.payload.content}),((c=t.payload)==null?void 0:c.kind)==="search"&&e.jsx("div",{className:"mt-2 space-y-1",children:t.payload.hits.map((g,N)=>e.jsxs("button",{onClick:()=>r(g.entry.name),className:"block w-full text-left px-2 py-1 hover:bg-bg-hi rounded",children:[e.jsx("div",{className:"font-mono text-[11px] text-fg-dim",children:g.entry.name}),e.jsx("div",{className:"text-[10px] text-fg-faint truncate",children:g.snippet})]},`${g.entry.name}-${N}`))}),((b=t.payload)==null?void 0:b.kind)==="suggest-send"&&e.jsxs("div",{className:"mt-2 flex gap-2 items-center",children:[e.jsx("button",{onClick:()=>i(t.payload.kind==="suggest-send"?t.payload.prompt:""),className:"px-2 py-0.5 text-[11px] text-fg-dim hover:text-fg border border-line hover:border-fg-faint rounded transition-colors",children:"Send to Claude in terminal"}),e.jsx("span",{className:"text-[10px] text-fg-faint",children:"paste-only — you press Enter"})]}),((C=t.payload)==null?void 0:C.kind)==="suggest-add"&&e.jsxs("div",{className:"mt-2 flex gap-2 items-center",children:[e.jsx("button",{onClick:()=>{var g;return((g=t.payload)==null?void 0:g.kind)==="suggest-add"&&m(t.payload.slug,t.payload.content)},className:"px-2 py-0.5 text-[11px] text-fg-dim hover:text-fg border border-line hover:border-fg-faint rounded transition-colors",children:"Add as new memory"}),e.jsxs("span",{className:"text-[10px] text-fg-faint font-mono",children:[t.payload.slug,".md"]})]})]})}const z=le((t,o)=>({entriesByAgent:new Map,loading:null,errorByAgent:new Map,loadAgent:async r=>{t({loading:r});const i=await window.api.agentMemory.list(r),m=new Map(o().entriesByAgent);m.set(r,i.entries);const s=new Map(o().errorByAgent);i.error?(s.set(r,i.error),A.error(`Agent memory load failed: ${i.error}`)):s.delete(r),t({entriesByAgent:m,loading:null,errorByAgent:s})},setEntry:async(r,i,m,s)=>{const u=await window.api.agentMemory.set(r,i,m,s);return u.ok&&await o().loadAgent(r),u},deleteEntry:async(r,i)=>{const m=await window.api.agentMemory.delete(r,i);if(m.ok){const s=new Map(o().entriesByAgent),u=s.get(r)??[];s.set(r,u.filter(f=>f.id!==i)),t({entriesByAgent:s})}return m}})),U=/^[A-Za-z0-9._-]{1,128}$/,V={command:"Commands",preference:"Preferences",pattern:"Patterns",failure:"Avoid",workflow:"Workflow"},ne=["command","preference","pattern","failure","workflow"];async function fe(t,o){const r=[{dir:`${t}/.claude/agents`,scope:"user"}];o&&r.push({dir:`${o}/.claude/agents`,scope:"project"});const i=[];for(const{dir:s,scope:u}of r)try{const f=await window.api.config.listDir(s,{filesOnly:!0});for(const c of f.entries){if(!c.name.endsWith(".md"))continue;const b=c.name.replace(/\.md$/,"");U.test(b)&&i.push({id:b,label:b,scope:u})}}catch{}const m=new Map;for(const s of i)s.scope==="project"?m.set(s.id,s):m.has(s.id)||m.set(s.id,s);return Array.from(m.values()).sort((s,u)=>s.id.localeCompare(u.id))}function he(){const t=Y(),o=K(),r=(o==null?void 0:o.cwd)??null,[i,m]=l.useState([]),[s,u]=l.useState(null),[f,c]=l.useState(null),[b,C]=l.useState(""),[g,N]=l.useState(!1),[$,x]=l.useState(!1),[S,T]=l.useState({}),B=z(n=>n.entriesByAgent),D=z(n=>n.loadAgent),v=z(n=>n.setEntry),_=z(n=>n.deleteEntry);l.useEffect(()=>{if(!t)return;let n=!1;return fe(t,r).then(k=>{n||(m(k),u(L=>{var d;return L&&k.find(h=>h.id===L)?L:((d=k[0])==null?void 0:d.id)??null}))}),()=>{n=!0}},[t,r]),l.useEffect(()=>{s&&(c(null),D(s))},[s,D]);const M=s?B.get(s)??[]:[],R=l.useMemo(()=>M.filter(n=>!b||n.id.toLowerCase().includes(b.toLowerCase())||n.body.toLowerCase().includes(b.toLowerCase())),[M,b]),j=l.useMemo(()=>M.find(n=>n.id===f)??null,[M,f]);l.useEffect(()=>{var n;!f&&R.length>0?c(R[0].id):f&&!R.find(k=>k.id===f)&&c(((n=R[0])==null?void 0:n.id)??null)},[R,f]);const E=s&&f?`${s}::${f}`:null,P=E?S[E]??(j==null?void 0:j.body)??"":"",F=!!E&&j!==null&&P!==j.body,a=l.useCallback(async()=>{s&&await D(s)},[s,D]),p=async()=>{if(!s||!f||!E)return;N(!0);const n=await v(s,f,P,(j==null?void 0:j.category)??void 0);if(N(!1),!n.ok){A.error(`Save failed: ${n.error??"unknown"}`);return}T(k=>{const L={...k};return delete L[E],L})},y=async()=>{if(!s||!f||!window.confirm(`Delete memory "${f}"? This cannot be undone.`))return;N(!0);const n=await _(s,f);if(N(!1),!n.ok){A.error(`Delete failed: ${n.error??"unknown"}`);return}c(null)},O=async n=>{if(!s||!f||!j)return;N(!0);const k=await v(s,f,j.body,n??void 0);N(!1),k.ok||A.error(`Update failed: ${k.error??"unknown"}`)};return t?e.jsx(ee,{toolbar:e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-fg-faint",children:"Agent"}),e.jsxs("select",{value:s??"",onChange:n=>u(n.target.value||null),className:"bg-bg border border-line rounded px-2 py-0.5 text-xs text-fg max-w-[16rem]",children:[i.length===0&&e.jsx("option",{value:"",children:"(no agents found)"}),i.map(n=>e.jsxs("option",{value:n.id,children:[n.label," ",n.scope==="project"?"· project":""]},`${n.scope}:${n.id}`))]}),e.jsx("span",{className:"mx-2 text-fg-faint",children:"·"}),e.jsxs("span",{className:"text-fg-faint",children:[M.length," ",M.length===1?"entry":"entries"]}),e.jsx("div",{className:"flex-1"}),e.jsx("button",{onClick:()=>x(!0),disabled:!s,className:"px-2 py-0.5 text-xs text-fg-dim hover:text-fg border border-line hover:border-fg-faint rounded transition-colors disabled:opacity-40",children:"+ New entry"}),e.jsx("button",{onClick:a,disabled:!s,className:"ml-2 px-2 py-0.5 text-xs text-fg-faint hover:text-fg-dim border border-line hover:border-fg-faint rounded transition-colors disabled:opacity-40",children:"Refresh"})]}),footer:j?e.jsxs("div",{className:"px-3 py-1.5 flex items-center gap-3 text-xs",children:[e.jsx("button",{onClick:p,disabled:!F||g,className:"px-2 py-0.5 text-xs text-fg-dim hover:text-fg border border-line hover:border-fg-faint rounded transition-colors disabled:opacity-40 disabled:cursor-not-allowed",children:g?"Saving…":"Save"}),e.jsx("button",{onClick:y,disabled:g,className:"px-2 py-0.5 text-xs text-red-400 hover:text-red-300 border border-line hover:border-red-400/50 rounded transition-colors disabled:opacity-40",children:"Delete"}),e.jsx("span",{className:"text-fg-faint",children:"Category:"}),e.jsxs("select",{value:j.category??"",onChange:n=>O(n.target.value||null),disabled:g,className:"bg-bg border border-line rounded px-2 py-0.5 text-xs text-fg-dim disabled:opacity-40",children:[e.jsx("option",{value:"",children:"(none)"}),ne.map(n=>e.jsx("option",{value:n,children:V[n]},n))]}),e.jsx("span",{className:"text-fg-faint truncate flex-1",children:j.id}),F&&e.jsx("span",{className:"text-accent",children:"unsaved"})]}):null,children:e.jsx(te,{sidebar:e.jsxs("div",{className:"py-1",children:[e.jsx("div",{className:"px-2 pb-1",children:e.jsx("input",{value:b,onChange:n=>C(n.target.value),placeholder:"filter…",className:"w-full bg-bg border border-line rounded px-2 py-0.5 text-xs text-fg"})}),s?R.length===0?e.jsx("div",{className:"px-3 py-2 text-xs text-fg-faint italic",children:M.length===0?"no entries yet":"no matches"}):R.map(n=>e.jsxs("button",{onClick:()=>c(n.id),className:`w-full text-left px-3 py-1 text-xs flex items-center justify-between ${f===n.id?"bg-bg-hi text-fg":"text-fg-dim hover:text-fg hover:bg-bg-hi"}`,title:n.id,children:[e.jsx("span",{className:"truncate",children:n.id}),e.jsxs("span",{className:"ml-2 text-fg-faint shrink-0 text-[10px]",children:[H(n.bytes)," · ",I(n.updatedAt)]})]},n.id)):e.jsx("div",{className:"px-3 py-2 text-xs text-fg-faint italic",children:"select an agent first"})]}),detail:$&&s?e.jsx(pe,{agentId:s,existingIds:new Set(M.map(n=>n.id)),onCancel:()=>x(!1),onCreated:n=>{x(!1),c(n),D(s)}}):j&&s&&f&&E?e.jsxs("div",{className:"h-full flex flex-col",children:[e.jsxs("div",{className:"shrink-0 px-3 py-2 border-b border-line text-xs",children:[e.jsx("div",{className:"text-fg truncate",children:j.id}),e.jsxs("div",{className:"text-fg-faint truncate",children:[H(j.bytes)," · modified ",I(j.updatedAt),j.category?` · ${V[j.category]}`:""]})]}),e.jsx("div",{className:"flex-1 min-h-0",children:e.jsx(se,{path:`agent-memory/${s}/${j.id}.md`,value:P,onChange:n=>T(k=>({...k,[E]:n}))})})]}):e.jsx(W,{title:s?M.length===0?"no entries yet":"select an entry":"no agent selected",hint:s&&M.length===0?"Use “+ New entry” to give this subagent its first memory.":void 0})})}):e.jsx(W,{title:"loading…"})}function pe({agentId:t,existingIds:o,onCancel:r,onCreated:i}){const m=z(v=>v.setEntry),[s,u]=l.useState(""),[f,c]=l.useState(""),[b,C]=l.useState(""),[g,N]=l.useState(!1),[$,x]=l.useState(null),S=s.trim(),T=U.test(S)&&!o.has(S),B=s?U.test(S)?o.has(S)?"an entry with this id already exists":null:"must match [A-Za-z0-9._-]+":null,D=async()=>{if(!T)return;N(!0),x(null);const v=await m(t,S,f,b||void 0);if(N(!1),!v.ok){x(v.error??"create failed");return}i(S)};return e.jsxs("div",{className:"p-4 max-w-xl space-y-3",children:[e.jsxs("div",{className:"text-sm text-fg",children:["New memory entry for ",e.jsx("span",{className:"font-mono text-fg-dim",children:t})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"block text-xs text-fg-faint",children:"Entry id"}),e.jsx("input",{autoFocus:!0,value:s,onChange:v=>u(v.target.value),placeholder:"e.g. preferred-test-runner",className:"w-full bg-bg border border-line rounded px-2 py-1 text-xs text-fg font-mono"}),B&&e.jsx("div",{className:"text-[10px] text-red-400",children:B}),e.jsxs("div",{className:"text-[10px] text-fg-faint",children:["Letters, digits, dots, dashes, underscores. Persists at",e.jsxs("code",{className:"ml-1 font-mono text-fg-dim",children:["~/.claude/session-manager/agent-memory/",t,".json"]}),"."]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"block text-xs text-fg-faint",children:"Category (optional)"}),e.jsxs("select",{value:b,onChange:v=>C(v.target.value),className:"bg-bg border border-line rounded px-2 py-1 text-xs text-fg",children:[e.jsx("option",{value:"",children:"(none)"}),ne.map(v=>e.jsx("option",{value:v,children:V[v]},v))]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"block text-xs text-fg-faint",children:"Body (markdown)"}),e.jsx("textarea",{value:f,onChange:v=>c(v.target.value),rows:6,placeholder:"What should this subagent remember?",className:"w-full bg-bg border border-line rounded px-2 py-1 text-xs text-fg font-mono"})]}),$&&e.jsx("div",{className:"text-xs text-red-400",children:$}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:D,disabled:!T||g,className:"px-3 py-1 text-xs text-fg border border-line hover:bg-bg-hi rounded transition-colors disabled:opacity-40",children:g?"Creating…":"Create"}),e.jsx("button",{onClick:r,disabled:g,className:"px-3 py-1 text-xs text-fg-faint hover:text-fg-dim rounded transition-colors",children:"Cancel"})]})]})}function ge({workspace:t,onOpenMember:o}){const[r,i]=l.useState(null),[m,s]=l.useState(!1),[u,f]=l.useState(!1),c=l.useRef(0),b=l.useCallback(async $=>{const x=++c.current;s(!0);try{const S=await window.api.memory.aggregate(t,$);if(c.current!==x)return;i(S)}catch(S){if(c.current!==x)return;A.error(`Memory aggregate failed: ${S instanceof Error?S.message:String(S)}`)}finally{c.current===x&&(s(!1),f(!0))}},[t]);l.useEffect(()=>{i(null),f(!1),b(!1)},[b]);const C=(r==null?void 0:r.clusters)??[],g=(r==null?void 0:r.orphans)??[],N=C.length>0||g.length>0;return e.jsxs("div",{className:"h-full flex flex-col",children:[e.jsxs("div",{className:"shrink-0 flex items-center gap-2 px-3 py-2 border-b border-line text-xs",children:[e.jsx("span",{className:"text-fg-faint",children:r!=null&&r.generatedAt?`generated ${I(r.generatedAt)} ago`:"not yet aggregated"}),e.jsx("div",{className:"flex-1"}),e.jsx("button",{onClick:()=>b(!0),disabled:m,className:"px-2 py-0.5 text-xs text-fg-dim hover:text-fg border border-line hover:border-fg-faint rounded transition-colors disabled:opacity-40 disabled:cursor-not-allowed",children:m?"Aggregating…":r!=null&&r.generatedAt?"Refresh":"Aggregate"})]}),e.jsx("div",{className:"flex-1 min-h-0 overflow-auto p-3",children:u?N?e.jsxs("div",{className:"space-y-4",children:[C.length>0&&e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:C.map($=>e.jsx(be,{cluster:$,onOpenMember:o},$.id))}),g.length>0&&e.jsxs("div",{className:"border border-line rounded p-3",children:[e.jsx("div",{className:"text-xs text-fg mb-2",children:"Unclustered"}),e.jsx("div",{className:"flex flex-wrap gap-1",children:g.map($=>e.jsx("button",{onClick:()=>o($),className:"px-2 py-0.5 text-[11px] font-mono text-fg-dim hover:text-fg border border-line hover:border-fg-faint rounded transition-colors",children:$},$))})]})]}):e.jsx(W,{title:"no clusters yet",hint:"Click Aggregate to organize this workspace's memories into named clusters."}):e.jsx(W,{title:"loading…"})})]})}function be({cluster:t,onOpenMember:o}){return e.jsxs("div",{className:"border border-line rounded p-3",children:[e.jsx("div",{className:"text-sm text-fg",children:t.name}),t.summary&&e.jsx("div",{className:"text-xs text-fg-faint mt-0.5",children:t.summary}),e.jsx("div",{className:"mt-2 flex flex-wrap gap-1",children:t.memberSlugs.map(r=>e.jsx("button",{onClick:()=>o(r),className:"px-2 py-0.5 text-[11px] font-mono text-fg-dim hover:text-fg border border-line hover:border-fg-faint rounded transition-colors",children:r},r))}),t.links.length>0&&e.jsx("div",{className:"mt-2 space-y-0.5",children:t.links.map((r,i)=>e.jsxs("div",{className:"text-[10px] text-fg-faint font-mono",children:[r.from," → ",r.to,r.label?` (${r.label})`:""]},`${r.from}-${r.to}-${i}`))})]})}const ye=[{key:"workspace",label:"Workspace"},{key:"subagent",label:"Subagent"}],J="sm.memoryTab.scope";function je(){const[t,o]=l.useState(()=>localStorage.getItem(J)==="subagent"?"subagent":"workspace");return l.useEffect(()=>{localStorage.setItem(J,t)},[t]),e.jsxs("div",{className:"h-full flex flex-col",children:[e.jsxs("div",{className:"shrink-0 flex items-center gap-3 px-3 py-2 border-b border-line",children:[e.jsx(q,{options:ye,active:t,onChange:o}),e.jsx("span",{className:"text-[11px] text-fg-faint",children:t==="workspace"?"memories scoped to the active project":"long-term memory per subagent"})]}),e.jsx("div",{className:"flex-1 min-h-0",children:t==="workspace"?e.jsx(ve,{}):e.jsx(he,{})})]})}const Ee=l.memo(je);function ve(){const t=Y(),o=K(),r=(o==null?void 0:o.cwd)??null,i=l.useMemo(()=>ie(r),[r]),[m,s]=l.useState("classic"),[u,f]=l.useState([]),[c,b]=l.useState(null),[C,g]=l.useState(""),[N,$]=l.useState({}),[x,S]=l.useState(!1),[T,B]=l.useState({}),[D,v]=l.useState({}),[_,M]=l.useState(!1),[R,j]=l.useState(!1),E=l.useCallback(async()=>{if(!t)return;const d=await window.api.memory.list(i);f(d.entries),d.error&&A.error(`Memory list failed: ${d.error}`),b(h=>{var w;return h&&d.entries.some(ae=>ae.name===h)?h:((w=d.entries[0])==null?void 0:w.name)??null});try{const h=await window.api.memory.stale(i,r??void 0);$(Object.fromEntries(h.entries.map(w=>[w.name,w])))}catch(h){$({}),A.error(`Memory staleness check failed: ${h instanceof Error?h.message:String(h)}`)}},[t,i,r]);if(l.useEffect(()=>{B({}),v({}),b(null),E()},[i,E]),l.useEffect(()=>{if(!t)return;const d=`${t}/.claude/projects/${i}/memory`;window.api.config.watch([d]);const h=window.api.config.onChanged(({path:w})=>{(w===d||w.startsWith(d+"/"))&&E()});return()=>{h(),window.api.config.unwatch([d])}},[t,i,E]),l.useEffect(()=>{if(!c||T[c]!==void 0)return;let d=!1;return(async()=>{const h=await window.api.memory.read(c,i);if(!d){if(h.error){A.error(`Memory read failed: ${h.error}`);return}B(w=>({...w,[c]:h.content})),v(w=>({...w,[c]:h.content}))}})(),()=>{d=!0}},[c,i]),!t)return e.jsx(W,{title:"loading…"});const P=u.reduce((d,h)=>{var w;return d+((w=N[h.name])!=null&&w.stale?1:0)},0),F=ce(u,C,x,N),a=u.find(d=>d.name===c)??null,p=c?N[c]:void 0,y=c?T[c]??"":"",O=c?D[c]??"":"",n=c?y!==O:!1,k=async()=>{if(!c)return;M(!0);const d=await window.api.memory.write(c,y,i);if(M(!1),!d.ok){A.error(`Memory save failed: ${d.error??"unknown error"}`);return}v(h=>({...h,[c]:y})),E()},L=async()=>{if(!c||!window.confirm(`Delete memory "${c}"? This cannot be undone.`))return;M(!0);const d=await window.api.memory.delete(c,i);if(M(!1),!d.ok){A.error(`Memory delete failed: ${d.error??"unknown error"}`);return}B(h=>{const w={...h};return delete w[c],w}),v(h=>{const w={...h};return delete w[c],w}),b(null),E()};return e.jsx(ee,{toolbar:e.jsxs(e.Fragment,{children:[e.jsx(q,{options:[{key:"classic",label:"Editor"},{key:"natural",label:"Natural"},{key:"clusters",label:"Clusters"}],active:m,onChange:s}),e.jsx("span",{className:"mx-2 text-fg-faint",children:"·"}),e.jsx("span",{className:"text-fg-faint",children:"Workspace"}),e.jsx("span",{className:"font-mono text-fg-dim truncate max-w-[24rem]",title:i,children:i}),e.jsx("span",{className:"mx-2 text-fg-faint",children:"·"}),e.jsxs("span",{className:"text-fg-faint",children:[u.length," ",u.length===1?"entry":"entries"]}),e.jsx("div",{className:"flex-1"}),m==="classic"&&P>0&&e.jsxs("button",{onClick:()=>S(d=>!d),className:`px-2 py-0.5 text-xs border rounded transition-colors ${x?"text-amber-400 border-amber-400/50 bg-amber-400/10":"text-fg-dim hover:text-fg border-line hover:border-fg-faint"}`,children:["Stale only (",P,")"]}),m==="classic"&&e.jsx("button",{onClick:()=>j(!0),className:"px-2 py-0.5 text-xs text-fg-dim hover:text-fg border border-line hover:border-fg-faint rounded transition-colors",children:"+ New memory"}),m!=="clusters"&&e.jsx("button",{onClick:E,className:"ml-2 px-2 py-0.5 text-xs text-fg-faint hover:text-fg-dim border border-line hover:border-fg-faint rounded transition-colors",children:"Refresh"})]}),footer:m==="classic"&&a?e.jsxs("div",{className:"px-3 py-1.5 flex items-center gap-3 text-xs",children:[e.jsx("button",{onClick:k,disabled:!n||_,className:"px-2 py-0.5 text-xs text-fg-dim hover:text-fg border border-line hover:border-fg-faint rounded transition-colors disabled:opacity-40 disabled:cursor-not-allowed",children:_?"Saving…":"Save"}),e.jsx("button",{onClick:L,disabled:_,className:"px-2 py-0.5 text-xs text-red-400 hover:text-red-300 border border-line hover:border-red-400/50 rounded transition-colors disabled:opacity-40",children:"Delete"}),(p==null?void 0:p.stale)&&e.jsxs("span",{className:"text-amber-400/90 truncate",title:p.reasons.join("; "),children:["stale · ",p.reasons.join(", ")]}),e.jsx("span",{className:"text-fg-faint truncate flex-1",children:a.path}),n&&e.jsx("span",{className:"text-accent",children:"unsaved"})]}):null,children:m==="natural"?e.jsx(xe,{workspace:i,entries:u,onChanged:E}):m==="clusters"?e.jsx(ge,{workspace:i,onOpenMember:d=>{b(`${d}.md`),s("classic")}}):e.jsx(te,{sidebar:e.jsxs("div",{className:"py-1",children:[e.jsx("div",{className:"px-2 pb-1",children:e.jsx("input",{value:C,onChange:d=>g(d.target.value),placeholder:"filter…",className:"w-full bg-bg border border-line rounded px-2 py-0.5 text-xs text-fg"})}),F.length===0?e.jsx("div",{className:"px-3 py-2 text-xs text-fg-faint italic",children:u.length===0?"no memories yet":"no matches"}):F.map(d=>{const h=N[d.name],w=h!=null&&h.stale?`${d.path}
8
+ stale: ${h.reasons.join(", ")}`:d.path;return e.jsxs("button",{onClick:()=>b(d.name),className:`w-full text-left px-3 py-1 text-xs flex items-center justify-between ${c===d.name?"bg-bg-hi text-fg":"text-fg-dim hover:text-fg hover:bg-bg-hi"}`,title:w,children:[e.jsxs("span",{className:"truncate flex items-center",children:[e.jsx("span",{className:"truncate",children:d.name.replace(/\.md$/,"")}),(h==null?void 0:h.stale)&&e.jsx("span",{className:"ml-1.5 shrink-0 px-1 rounded text-[9px] uppercase tracking-wide text-amber-400/90 border border-amber-400/30",children:"stale"})]}),e.jsxs("span",{className:"ml-2 text-fg-faint shrink-0 text-[10px]",children:[H(d.bytes)," · ",I(d.mtimeMs)]})]},d.name)})]}),detail:R?e.jsx(we,{workspace:i,onCancel:()=>j(!1),onCreated:d=>{j(!1),b(d),E()}}):a&&c?e.jsxs("div",{className:"h-full flex flex-col",children:[e.jsxs("div",{className:"shrink-0 px-3 py-2 border-b border-line text-xs",children:[e.jsx("div",{className:"text-fg truncate",children:a.name}),e.jsxs("div",{className:"text-fg-faint truncate",children:[H(a.bytes)," · modified ",I(a.mtimeMs)]})]}),e.jsx("div",{className:"flex-1 min-h-0",children:e.jsx(se,{path:a.path,value:y,onChange:d=>B(h=>({...h,[c]:d}))})})]}):e.jsx(W,{title:u.length===0?"no memories yet":"select a memory",hint:u.length===0?"Claude writes to memories during sessions when you ask it to remember things, or you can create one manually with the + New memory button.":void 0})})})}function we({workspace:t,onCancel:o,onCreated:r}){const[i,m]=l.useState(""),[s,u]=l.useState(""),[f,c]=l.useState(!1),[b,C]=l.useState(null),g=i.trim().toLowerCase(),N=re.test(g),$=async()=>{if(!N){C("Slug must match [a-z0-9-_]+");return}c(!0),C(null);const x=`${g}.md`,S=await window.api.memory.create(x,s.trim()||void 0,t);if(c(!1),!S.ok){C(S.error??"create failed");return}r(x)};return e.jsxs("div",{className:"p-4 max-w-xl space-y-3",children:[e.jsx("div",{className:"text-sm text-fg",children:"New memory"}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"block text-xs text-fg-faint",children:"Slug"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{autoFocus:!0,value:i,onChange:x=>m(x.target.value),placeholder:"my-notes",className:"flex-1 bg-bg border border-line rounded px-2 py-1 text-xs text-fg font-mono"}),e.jsx("span",{className:"text-xs text-fg-faint",children:".md"})]}),e.jsxs("div",{className:"text-[10px] text-fg-faint",children:["Lowercase letters, digits, dashes, underscores. The file is created at",e.jsxs("code",{className:"ml-1 font-mono text-fg-dim",children:["~/.claude/projects/",t,"/memory/",g||"…",".md"]})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"block text-xs text-fg-faint",children:"Description (optional)"}),e.jsx("input",{value:s,onChange:x=>u(x.target.value),placeholder:"one-line summary",className:"w-full bg-bg border border-line rounded px-2 py-1 text-xs text-fg"})]}),b&&e.jsx("div",{className:"text-xs text-red-400",children:b}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:$,disabled:!N||f,className:"px-3 py-1 text-xs text-fg border border-line hover:bg-bg-hi rounded transition-colors disabled:opacity-40",children:f?"Creating…":"Create"}),e.jsx("button",{onClick:o,disabled:f,className:"px-3 py-1 text-xs text-fg-faint hover:text-fg-dim rounded transition-colors",children:"Cancel"})]})]})}export{Ee as Memory};
@@ -0,0 +1 @@
1
+ import{I as e}from"./index-BfPVknuV.js";function n({toolbar:s,footer:l,children:r}){return e.jsxs("div",{className:"h-full flex flex-col",children:[s&&e.jsx("div",{className:"shrink-0 border-b border-line bg-bg-elev px-3 py-1.5 flex items-center gap-2 text-xs",children:s}),e.jsx("div",{className:"flex-1 min-h-0 overflow-auto",children:r}),l&&e.jsx("div",{className:"shrink-0 border-t border-line bg-bg-elev",children:l})]})}export{n as P};
@@ -0,0 +1,3 @@
1
+ import{X as d,a9 as z,a5 as H,ab as W,a7 as N,I as e,c as w,P as D,V as X}from"./index-BfPVknuV.js";import{P as A}from"./Panel-Bap7G-pI.js";import{S as q,a as G}from"./ScopeSwitcher-BlQvpyLE.js";import{P as Q}from"./Library-BrODBbeL.js";import{u as U,m as Y,p as Z,g as ee,E as te,a as se,s as re}from"./settingsSchema-DKuyaEK5.js";import"./monaco-editor-BW5C4Iv1.js";const ne=["allow","deny","ask"];function ae(r){if(r.trim()==="")return{perms:{},full:{},err:null};try{const n=JSON.parse(r);return{perms:n.permissions??{},full:n,err:null}}catch(n){return{perms:{},full:{},err:n.message}}}function oe(r,n){const a={...r,permissions:n};return JSON.stringify(a,null,2)+`
2
+ `}function ie(){const r=z(),n=H(),a=(n==null?void 0:n.cwd)??null,s=W(t=>t.navFace),i=d.useRef(!1),u=d.useRef(s),[p,c]=d.useState(()=>s==="project"&&a?"project":"user"),[m,P]=d.useState("effective");d.useEffect(()=>{if(u.current!==s){if(u.current=s,i.current){i.current=!1;return}c(s==="project"&&a?"project":"user")}},[s,a]),d.useEffect(()=>{s==="project"&&m==="presets"&&P("effective")},[s,m]);const I=t=>{i.current=!0,c(t)},b=U(D,r,a),f=b[p]??null,j=N(t=>t.files),E=N(t=>t.setDraft),J=N(t=>t.saveJson),O=N(t=>t.revert),[M,y]=d.useState(null),k=e.jsx(X,{options:[{key:"effective",label:"Effective"},{key:"rules",label:"Rules"},...s==="home"?[{key:"presets",label:"Presets"}]:[]],active:m,onChange:P}),$=d.useMemo(()=>{const t=Y(Z(j,b));return ee(t,["permissions"])??{kind:"object",children:{}}},[j,b]),F=(t,l)=>{var R;const o=b[p];if(!o)return;y(null);const h=((R=j[o])==null?void 0:R.draftRaw)??"";let v={};if(h.trim())try{v=JSON.parse(h)}catch{v={}}const B=re(v.permissions??{},t,l),K={...v,permissions:B};E(o,JSON.stringify(K,null,2)+`
3
+ `)};if(!r)return e.jsx(w,{title:"loading…"});if(m==="presets")return e.jsx(A,{toolbar:k,children:e.jsx(Q,{})});const C=t=>t!=="user"&&!a,g=f?j[f]:null,{perms:x,full:L,err:T}=g?ae(g.draftRaw):{perms:{},full:{},err:null},S=t=>{f&&(y(null),E(f,oe(L,t)))},_=(t,l)=>{const o=l.trim();if(!o)return;const h=x[t]??[];h.includes(o)||S({...x,[t]:[...h,o]})},V=(t,l)=>{const o=x[t]??[];S({...x,[t]:o.filter((h,v)=>v!==l)})};return e.jsx(A,{toolbar:e.jsxs(e.Fragment,{children:[k,e.jsx("span",{className:"mx-2 text-fg-faint",children:"·"}),e.jsx(G,{scopes:D.scopes,active:p,onChange:I,annotate:t=>{if(C(t))return{exists:!1};const l=b[t];if(!l)return null;const o=j[l];return{exists:(o==null?void 0:o.exists)??!1,dirty:(o==null?void 0:o.dirty)??!1}}}),e.jsx("span",{className:"ml-3 text-fg-faint truncate",children:f??"—"}),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 ↗"})]}),footer:f&&g?e.jsx(q,{dirty:g.dirty,busy:g.busy,parseError:M||T||g.parseError,lastSavedAt:g.lastSavedAt,onSave:async()=>{y(null);const t=await J(f);t.ok||y(t.error??"save failed")},onRevert:()=>{y(null),O(f)}}):null,children:C(p)?e.jsx(w,{title:"no active project",hint:"open a tab in a project directory to edit project or local permissions"}):m==="effective"?e.jsx(te,{node:$,targetScope:p,onOverride:F,schema:se().rootedAt(["permissions"]),rootLabel:"permissions"}):f&&g?e.jsxs("div",{className:"p-4 space-y-5 max-w-3xl",children:[e.jsx(le,{value:x.defaultMode??"default",onChange:t=>S({...x,defaultMode:t})}),ne.map(t=>e.jsx(ce,{list:t,rules:x[t]??[],onAdd:l=>_(t,l),onRemove:l=>V(t,l)},t)),e.jsx(de,{dirs:x.additionalDirectories??[],onChange:t=>S({...x,additionalDirectories:t})})]}):e.jsx(w,{title:"resolving…"})})}const he=d.memo(ie);function le({value:r,onChange:n}){const a=["default","acceptEdits","plan","bypassPermissions"];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:a.map(s=>e.jsx("button",{onClick:()=>n(s),className:`px-2.5 py-1 text-xs transition-colors ${r===s?"bg-bg-hi text-fg":"bg-bg-elev text-fg-dim hover:text-fg hover:bg-bg-hi"}`,children:s},s))})]})}function ce({list:r,rules:n,onAdd:a,onRemove:s}){const[i,u]=d.useState(""),p=r==="allow"?"text-green-400":r==="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:r}),e.jsxs("div",{className:"flex gap-2 mb-2",children:[e.jsx("input",{value:i,onChange:c=>u(c.target.value),onKeyDown:c=>{c.key==="Enter"&&(a(i),u(""))},placeholder:r==="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:()=>{a(i),u("")},disabled:!i.trim(),className:"px-2.5 py-1 border border-line rounded text-xs text-fg-dim hover:text-fg hover:bg-bg-hi disabled:opacity-40",children:"add"})]}),n.length===0?e.jsx("div",{className:"text-fg-faint text-xs",children:"no rules"}):e.jsx("ul",{className:"space-y-0.5",children:n.map((c,m)=>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:c}),e.jsx("button",{onClick:()=>s(m),className:"text-fg-faint hover:text-red-400",title:"remove",children:"×"})]},`${m}-${c}`))})]})}function de({dirs:r,onChange:n}){const[a,s]=d.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,onChange:i=>s(i.target.value),onKeyDown:i=>{i.key==="Enter"&&a.trim()&&(n([...r,a.trim()]),s(""))},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:r.map((i,u)=>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:i}),e.jsx("button",{onClick:()=>n(r.filter((p,c)=>c!==u)),className:"text-fg-faint hover:text-red-400",children:"×"})]},`${u}-${i}`))})]})}export{he as Permissions};
@@ -0,0 +1,2 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./SkillReferenceGraph-CGtwmCjm.js","./index-BfPVknuV.js","./monaco-editor-BW5C4Iv1.js","./monaco-editor-BTnBOi8r.css","./index-LlWpj2VJ.css"])))=>i.map(i=>d[i]);
2
+ import{I as e,X as h,c as j,a9 as Q,a4 as T,a as U}from"./index-BfPVknuV.js";import{P as R}from"./Panel-Bap7G-pI.js";import{P as K}from"./ProvenanceBadge-CCp_EhjV.js";import{e as Y}from"./Library-BrODBbeL.js";import{p as W}from"./skillFrontmatter-Dif5JIg7.js";import{_ as Z}from"./monaco-editor-BW5C4Iv1.js";import{L as ee}from"./ListDetail-C5vbA1gC.js";import{M as te}from"./MarkdownEditor-CpzAEiiG.js";function ne({columns:t,rows:s,getKey:r,onRowClick:a,activeKey:o,empty:d}){return s.length===0?e.jsx("div",{className:"p-6 text-fg-faint text-xs text-center",children:d??"no entries"}):e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{className:"sticky top-0 bg-bg-elev text-fg-faint uppercase tracking-wider",children:e.jsx("tr",{className:"border-b border-line",children:t.map(i=>e.jsx("th",{className:`text-left font-normal px-3 py-1.5 ${i.className??""}`,style:i.width?{width:i.width}:void 0,children:i.header},i.key))})}),e.jsx("tbody",{children:s.map(i=>{const l=r(i),c=o===l;return e.jsx("tr",{"data-row-key":l,onClick:()=>a==null?void 0:a(i),className:`border-b border-line/50 transition-colors ${a?"cursor-pointer":""} ${c?"bg-bg-hi text-fg":"text-fg-dim hover:bg-bg-hi/50"}`,children:t.map(m=>e.jsx("td",{className:`px-3 py-1 ${m.className??""}`,children:m.render(i)},m.key))},l)})})]})}async function se(t,s,r){var m,x;const a=`${s}/skills`;try{const n=await window.api.config.listDir(a,{dirsOnly:!0});if(n.ok&&n.entries.length>0)return a}catch{}let o=null;try{const n=await window.api.config.readJson(`${r}/.claude/plugins/installed_plugins.json`);n.exists&&!n.parseError&&n.data&&typeof n.data=="object"&&(o=n.data)}catch{return null}if(!(o!=null&&o.plugins))return null;const d=Object.keys(o.plugins).find(n=>n===t||n.startsWith(`${t}@`));if(!d)return null;const i=(x=(m=o.plugins[d])==null?void 0:m[0])==null?void 0:x.installPath;if(!i)return null;const l=`${i}/skills`;return await window.api.config.exists(l)?l:null}async function ie(t){const s=await window.api.config.listDir(t,{dirsOnly:!0}),r=[];for(const a of s.entries){const o=`${a.path}/SKILL.md`,d=await window.api.config.readText(o);if(!d.exists)continue;const i=W(d.text);r.push({id:a.name,name:i.name,description:i.description,dir:a.path,path:o,body:i.body})}return r}function ae(t){const s=[],r=new Set;for(const a of t)for(const o of t){if(a.id===o.id)continue;const d=o.id.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),i=[`/${d}\\b`,`\`${d}\``];if(o.id.length>=4&&i.push(`\\b${d}\\b`),!i.some(m=>new RegExp(m,"i").test(a.body)))continue;const c=`${a.id}->${o.id}`;r.has(c)||(r.add(c),s.push({from:a.id,to:o.id}))}return s}const le=h.lazy(()=>Z(()=>import("./SkillReferenceGraph-CGtwmCjm.js"),__vite__mapDeps([0,1,2,3,4]),import.meta.url).then(t=>({default:t.SkillReferenceGraph})));function oe({pluginName:t,skills:s,onBack:r,initialSelectedId:a}){var x;const[o,d]=h.useState(a??((x=s[0])==null?void 0:x.id)??null),i=o?s.find(n=>n.id===o)??null:null,l=h.useMemo(()=>ae(s),[s]),[c,m]=h.useState("list");return e.jsxs("div",{className:"flex flex-col h-full min-h-0 overflow-hidden",children:[e.jsxs("div",{className:"shrink-0 h-11 flex items-baseline gap-3.5 px-3 border-b border-line bg-bg",children:[e.jsxs("button",{type:"button",onClick:r,className:"font-mono text-accent hover:underline shrink-0 text-xs",children:["← ",t]}),e.jsx("span",{className:"font-serif text-[22px] text-fg shrink-0 truncate max-w-[16rem]",children:(i==null?void 0:i.name)??(i==null?void 0:i.id)??"skill"}),e.jsx("span",{className:"flex-1"}),e.jsx("div",{className:"flex items-center gap-1.5 shrink-0",children:e.jsxs("div",{className:"flex rounded border border-line overflow-hidden",children:[e.jsx("button",{onClick:()=>m("list"),className:`px-2 py-0.5 text-xs ${c==="list"?"bg-bg-hi text-fg":"text-fg-dim hover:text-fg hover:bg-bg-hi"}`,children:"list"}),e.jsx("button",{onClick:()=>m("graph"),className:`px-2 py-0.5 text-xs ${c==="graph"?"bg-bg-hi text-fg":"text-fg-dim hover:text-fg hover:bg-bg-hi"}`,children:"graph"})]})})]}),e.jsxs("div",{className:"shrink-0 h-[26px] flex items-center gap-[18px] px-3 bg-bg-elev border-b border-line text-[9px] font-mono uppercase tracking-wide overflow-hidden",children:[i!=null&&i.description?e.jsx("span",{className:"text-fg-dim truncate normal-case",children:i.description}):null,e.jsxs("span",{className:"ml-auto text-fg-faint truncate normal-case",children:[s.length," ",s.length===1?"skill":"skills"," · ",l.length," ",l.length===1?"reference":"references"]})]}),e.jsx("div",{className:"flex-1 min-h-0 overflow-hidden",children:s.length===0?e.jsx(j,{title:"no skills in this plugin"}):c==="graph"?e.jsx(h.Suspense,{fallback:e.jsx("div",{className:"p-6 text-xs text-fg-faint",children:"Loading graph…"}),children:e.jsx(le,{skills:s,edges:l,selectedId:o,onSelect:d})}):e.jsx(ee,{sidebar:e.jsx("div",{className:"py-1",children:s.map(n=>e.jsxs("button",{onClick:()=>d(n.id),className:`w-full px-3 py-1 text-xs text-left ${o===n.id?"bg-bg-hi text-fg":"text-fg-dim hover:text-fg hover:bg-bg-hi"}`,children:[e.jsx("div",{className:"truncate",children:n.name??n.id}),n.description?e.jsx("div",{className:"truncate text-fg-faint",children:n.description}):null]},n.id))}),detail:i?e.jsx("div",{className:"h-full min-h-0",children:e.jsx(te,{path:i.path,value:i.body,onChange:()=>{},readOnly:!0})}):e.jsx(j,{title:"select a skill"})})})]})}const z=t=>{var s,r;return{type:"plugin",name:t.name,repository:(s=t.manifest)==null?void 0:s.repository,homepage:(r=t.manifest)==null?void 0:r.homepage}};function re(){const t=Q(),[s,r]=h.useState([]),[a,o]=h.useState(!0),[d,i]=h.useState(null),[l,c]=h.useState("installed");h.useEffect(()=>{if(!t)return;let n=!1;return(async()=>{var y;o(!0);const u=[];try{const g=await window.api.config.readJson(`${t}/.claude/plugins/installed_plugins.json`);if(g.exists&&!g.parseError&&g.data&&typeof g.data=="object"){const w=g.data;for(const[f,L]of Object.entries(w.plugins??{})){if(!Array.isArray(L))continue;const $=f.split("@")[0],E=f.split("@")[1];for(const b of L){if(!(b!=null&&b.installPath))continue;const S={name:$,path:b.installPath,isDirectory:!0,isFile:!1,mtimeMs:0,size:0},N=await fe(S);(y=N.manifest)!=null&&y.version||(N.manifest={...N.manifest??{},version:b.version}),N.marketplace=E,u.push(N)}}}}catch{}n||(u.sort((g,w)=>g.name.localeCompare(w.name)),n||(r(u),o(!1)))})(),()=>{n=!0}},[t]);const m=[{key:"name",header:"name",render:n=>{var u;return e.jsxs("div",{style:{maxWidth:"16rem"},children:[e.jsx("div",{className:"truncate",children:n.name}),(u=n.manifest)!=null&&u.description?e.jsx("div",{className:"truncate text-fg-faint",title:n.manifest.description,children:n.manifest.description}):null]})},width:"16rem"},{key:"origin",header:"origin",render:n=>e.jsx(K,{interactive:!1,input:z(n)}),width:"7rem"},{key:"version",header:"version",render:n=>{var u;return((u=n.manifest)==null?void 0:u.version)??e.jsx("span",{className:"text-fg-faint",children:"—"})},width:"6rem"},{key:"manifest",header:"manifest",render:n=>n.hasManifest?"plugin.json":e.jsx("span",{className:"text-fg-faint",children:"—"}),width:"8rem"},{key:"contents",header:"contents",render:n=>e.jsx("span",{className:"font-mono text-fg-faint text-xs",children:[n.agents>0?`${n.agents} agents`:null,n.skills>0?`${n.skills} skills`:null,n.hooks>0?`${n.hooks} hooks`:null,n.monitors>0?`${n.monitors} monitors`:null,n.binCount>0?`${n.binCount} bin`:null,n.hasLsp?"lsp":null,n.hasMcp?"mcp":null].filter(Boolean).join(" · ")||"—"})},{key:"path",header:"path",render:n=>e.jsx("span",{className:"font-mono text-fg-faint truncate",children:n.path})}];if(l==="library")return e.jsx(R,{toolbar:e.jsx(V,{active:l,onChange:c}),children:e.jsx(Y,{})});const x=d?s.find(n=>n.path===d)??null:null;return e.jsx(R,{toolbar:e.jsxs(e.Fragment,{children:[e.jsx(V,{active:l,onChange:c}),e.jsx("span",{className:"mx-2 text-fg-faint",children:"·"}),e.jsxs("span",{className:"text-fg-faint",children:[s.length," plugins"]}),e.jsx("div",{className:"flex-1"}),e.jsx("span",{className:"text-fg-faint font-mono truncate",children:"~/.claude/plugins/installed_plugins.json"})]}),children:a?e.jsx(j,{title:"scanning plugins…"}):x?e.jsx(ce,{row:x,home:t,onBack:()=>i(null)},x.path):e.jsx("div",{className:"flex flex-col h-full",children:e.jsx("div",{className:"flex-1 min-h-0 overflow-auto",children:e.jsx(ne,{columns:m,rows:s,getKey:n=>n.path,activeKey:d,onRowClick:n=>i(n.path),empty:e.jsxs(e.Fragment,{children:["no plugins installed",e.jsxs("div",{className:"mt-2 text-fg-faint",children:["drop a plugin into ",e.jsx("code",{children:"~/.claude/plugins/"})]})]})})})})})}const ke=h.memo(re);function V({active:t,onChange:s}){const r=[["installed","Installed"],["library","Library"]];return e.jsx("div",{className:"flex rounded border border-line overflow-hidden",role:"tablist","aria-label":"Plugins view",children:r.map(([a,o])=>e.jsx("button",{onClick:()=>s(a),role:"tab","aria-selected":t===a,className:`px-2 py-0.5 text-xs ${t===a?"bg-bg-hi text-fg":"text-fg-dim hover:text-fg hover:bg-bg-hi"}`,children:o},a))})}function ce({row:t,home:s,onBack:r}){var b,S,N,I,B;const[a,o]=h.useState([]),[d,i]=h.useState([]),[l,c]=h.useState([]),[m,x]=h.useState([]),[n,u]=h.useState("skills"),[y,g]=h.useState(null),[w,f]=h.useState(!0);h.useEffect(()=>{if(!s)return;let p=!1;return(async()=>{f(!0);try{const[v,G,M,X]=await Promise.all([se(t.name,t.path,s),O(`${t.path}/agents`,{filesOnly:!0}),t.hasMcp?window.api.config.readJson(`${t.path}/.mcp.json`):Promise.resolve(null),O(`${t.path}/bin`,{filesOnly:!0})]),H=v?await ie(v):[],J=G.filter(k=>k.endsWith(".md")),q=await Promise.all(J.map(k=>window.api.config.readText(`${t.path}/agents/${k}`))),F=[];J.forEach((k,D)=>{const C=q[D];if(!C.exists)return;const A=W(C.text);F.push({id:k,name:A.name??k.replace(/\.md$/,""),description:A.description})});const _=[];if(M&&M.exists&&!M.parseError&&M.data&&typeof M.data=="object"){const k=M.data.mcpServers;if(k&&typeof k=="object")for(const[D,C]of Object.entries(k)){const A=C&&typeof C=="object"?C.command:void 0;_.push({id:D,name:D,description:typeof A=="string"?A:null})}}if(p)return;o(H),i(F),c(_),x(X),u(H.length>0?"skills":F.length>0?"agents":_.length>0?"mcp":t.hooks>0?"hooks":t.monitors>0?"monitors":t.hasLsp?"lsp":"files")}catch(v){if(p)return;T.error(`Failed to load plugin contents: ${v instanceof Error?v.message:String(v)}`),o([]),i([]),c([]),x([])}finally{p||f(!1)}})(),()=>{p=!0}},[t.path,t.name,t.hasMcp,t.hooks,t.monitors,t.hasLsp,s]);const L=[{key:"skills",label:"Skills",count:a.length},{key:"agents",label:"Agents",count:d.length},{key:"mcp",label:"MCP server",count:l.length},{key:"hooks",label:"Hooks",count:t.hooks},{key:"monitors",label:"Monitors",count:t.monitors},{key:"lsp",label:"LSP",count:t.hasLsp?1:0},{key:"files",label:"Bin",count:m.length}],$=(b=t.manifest)!=null&&b.author?typeof t.manifest.author=="string"?t.manifest.author:t.manifest.author.name??null:null,E=async p=>{const v=await window.api.shell.open({as:"external",url:p});v.ok||T.error(v.error??`Failed to open ${p}`)};return y?e.jsx(oe,{pluginName:((S=t.manifest)==null?void 0:S.name)??t.name,skills:a,initialSelectedId:y.id,onBack:()=>g(null)},y.id):e.jsxs("div",{className:"flex flex-col h-full min-h-0 overflow-hidden",children:[e.jsxs("div",{className:"shrink-0 h-11 flex items-baseline gap-3.5 px-3 border-b border-line bg-bg",children:[e.jsx("button",{type:"button",onClick:r,className:"font-mono text-accent hover:underline shrink-0 text-xs",children:"← Plugins"}),e.jsx("span",{className:"font-serif text-[22px] text-fg shrink-0 truncate max-w-[16rem]",children:((N=t.manifest)==null?void 0:N.name)??t.name}),(I=t.manifest)!=null&&I.version?e.jsxs("span",{className:"font-mono text-fg-faint text-xs shrink-0",children:["v",t.manifest.version]}):null,(B=t.manifest)!=null&&B.description?e.jsx("span",{className:"text-fg-dim text-xs min-w-0 flex-1 overflow-hidden text-ellipsis whitespace-nowrap",children:t.manifest.description}):e.jsx("span",{className:"flex-1"}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[e.jsx(K,{input:z(t)}),t.hasMcp?e.jsx(U,{tone:"accent",children:"MCP"}):null]})]}),t.manifest?e.jsxs("div",{className:"shrink-0 h-[26px] flex items-center gap-[18px] px-3 bg-bg-elev border-b border-line text-[9px] font-mono uppercase tracking-wide overflow-hidden",children:[$?e.jsxs("span",{className:"text-fg-dim truncate",children:[e.jsx("span",{className:"text-fg-faint",children:"Author "}),$]}):null,t.manifest.license?e.jsxs("span",{className:"text-fg-dim truncate",children:[e.jsx("span",{className:"text-fg-faint",children:"License "}),t.manifest.license]}):null,t.manifest.homepage?e.jsxs("button",{onClick:()=>E(t.manifest.homepage),className:"text-accent hover:underline truncate normal-case",title:t.manifest.homepage,children:[e.jsx("span",{className:"text-fg-faint uppercase",children:"Homepage "}),t.manifest.homepage]}):null,e.jsx("span",{className:"ml-auto text-fg-faint truncate normal-case",children:t.path})]}):e.jsx("div",{className:"shrink-0 h-[26px] flex items-center px-3 bg-bg-elev border-b border-line text-[9px] font-mono uppercase tracking-wide overflow-hidden",children:e.jsx("span",{className:"ml-auto text-fg-faint truncate normal-case",children:t.path})}),e.jsxs("div",{className:"flex-1 min-h-0 grid overflow-hidden",style:{gridTemplateColumns:"170px 1fr"},children:[e.jsx("div",{className:"min-h-0 overflow-auto bg-bg-elev border-r border-line py-1",children:L.map(p=>e.jsxs("button",{type:"button",disabled:p.count===0,onClick:()=>u(p.key),className:`w-full text-left px-3 py-1.5 text-xs flex items-center justify-between ${p.count===0?"text-fg-faint opacity-50 cursor-default":n===p.key?"bg-bg-hi text-fg":"text-fg-dim hover:text-fg hover:bg-bg-hi"}`,children:[e.jsx("span",{children:p.label}),p.count>0?e.jsx("span",{className:"font-mono text-fg-faint",children:p.count}):null]},p.key))}),e.jsx("div",{className:"min-h-0 overflow-auto",children:w?e.jsx(j,{title:"scanning…"}):e.jsx(de,{active:n,row:t,skills:a,agents:d,mcpServers:l,files:m,onOpenSkill:g})})]})]})}function de({active:t,row:s,skills:r,agents:a,mcpServers:o,files:d,onOpenSkill:i}){return t==="skills"?r.length===0?e.jsx(j,{title:"no components"}):e.jsx("div",{children:r.map((l,c)=>e.jsx(P,{n:c+1,name:l.name??l.id,description:l.description,onClick:()=>i(l)},l.id))}):t==="agents"?a.length===0?e.jsx(j,{title:"no components"}):e.jsx("div",{children:a.map((l,c)=>e.jsx(P,{n:c+1,name:l.name??l.id,description:l.description},l.id))}):t==="mcp"?o.length===0?e.jsx(j,{title:"no components"}):e.jsx("div",{children:o.map((l,c)=>e.jsx(P,{n:c+1,name:l.name,description:l.description},l.id))}):t==="hooks"?s.hooks===0?e.jsx(j,{title:"no components"}):e.jsx("div",{children:e.jsx(P,{n:1,name:`${s.hooks} ${s.hooks===1?"hook":"hooks"} configured`,description:`${s.path}/hooks/hooks.json`})}):t==="monitors"?s.monitors===0?e.jsx(j,{title:"no components"}):e.jsx("div",{children:e.jsx(P,{n:1,name:`${s.monitors} ${s.monitors===1?"monitor":"monitors"} configured`,description:`${s.path}/monitors/monitors.json`})}):t==="lsp"?s.hasLsp?e.jsx("div",{children:e.jsx(P,{n:1,name:"LSP server enabled",description:`${s.path}/.lsp.json`})}):e.jsx(j,{title:"no components"}):d.length===0?e.jsx(j,{title:"no components"}):e.jsx("div",{children:d.map((l,c)=>e.jsx(P,{n:c+1,name:l,description:null},l))})}function P({n:t,name:s,description:r,onClick:a}){const o=a?"button":"div";return e.jsxs(o,{onClick:a,className:`w-full flex items-baseline gap-2.5 py-[9px] px-3 border-b border-line text-left min-w-0 ${a?"hover:bg-bg-hi cursor-pointer":""}`,children:[e.jsx("span",{className:"font-serif text-fg-faint text-xs shrink-0 w-6 text-right",children:String(t).padStart(2,"0")}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"font-mono font-semibold text-accent truncate",children:s}),r?e.jsx("div",{className:"text-fg-dim text-xs truncate",children:r}):null]})]})}async function fe(t){let s=`${t.path}/.claude-plugin/plugin.json`,r=await window.api.config.exists(s);r||(s=`${t.path}/plugin.json`,r=await window.api.config.exists(s));let a=null;if(r){const f=await window.api.config.readJson(s);f.exists&&!f.parseError&&f.data&&typeof f.data=="object"&&(a=f.data)}const[o,d,i,l]=await Promise.all([window.api.config.exists(`${t.path}/.lsp.json`),window.api.config.exists(`${t.path}/.mcp.json`),window.api.config.exists(`${t.path}/monitors/monitors.json`),window.api.config.exists(`${t.path}/hooks/hooks.json`)]);let c=0;if(i){const f=await window.api.config.readJson(`${t.path}/monitors/monitors.json`);Array.isArray(f.data)?c=f.data.length:f.data&&typeof f.data=="object"&&Array.isArray(f.data.monitors)&&(c=f.data.monitors.length)}let m=0;if(l){const f=await window.api.config.readJson(`${t.path}/hooks/hooks.json`);if(f.data&&typeof f.data=="object"){const L=f.data;m=Object.values(L).reduce(($,E)=>Array.isArray(E)?$+E.reduce((b,S)=>b+(Array.isArray(S.hooks)?S.hooks.length:0),0):$,0)}}const[x,n,u]=await Promise.all([O(`${t.path}/agents`,{filesOnly:!0}),O(`${t.path}/bin`,{filesOnly:!0}),O(`${t.path}/skills`,{dirsOnly:!0})]),y=x.filter(f=>f.endsWith(".md")).length,g=n.length,w=u.length;return{name:t.name,path:t.path,mtimeMs:t.mtimeMs,hasManifest:r,manifest:a,hasLsp:o,monitors:c,hooks:m,agents:y,skills:w,binCount:g,hasMcp:d}}async function O(t,s){try{return(await window.api.config.listDir(t,s)).entries.map(a=>a.name)}catch{return[]}}export{ke as Plugins};
@@ -0,0 +1 @@
1
+ import{s as P,a9 as G,X as x,I as i,Z as R,B as T,a as _}from"./index-BfPVknuV.js";import{a as E,C as I,c as L,d as S,b as B}from"./Library-BrODBbeL.js";const O=e=>`${e}/.claude/session-manager/provenance.json`;function D(e){if(!e||typeof e!="object")return{};const t={};for(const[n,o]of Object.entries(e))(o==="anthropic"||o==="community"||o==="local")&&(t[n]=o);return t}const K=P((e,t)=>({overrides:{},loaded:!1,loading:!1,home:null,load:async n=>{const o=t();if(!(o.home===n&&(o.loaded||o.loading))){e({home:n,loading:!0});try{const r=await window.api.config.readJson(O(n)),d=r.exists?D(r.data):{};e(h=>({overrides:{...d,...h.overrides},loaded:!0,loading:!1}))}catch{e({loaded:!0,loading:!1})}}},setOverride:async(n,o)=>{const r={...t().overrides};o===null?delete r[n]:r[n]=o,e({overrides:r});const d=t().home;if(d)try{await window.api.config.writeJson(O(d),r)}catch{}}})),a=e=>(e??"").toLowerCase().trim(),j=new Set,$=new Set;for(const e of B){const t=e.official?j:$;t.add(a(e.id)),t.add(a(e.name))}const H=new Set(S.filter(e=>e.official).flatMap(e=>[a(e.id),a(e.name)])),J=new Set(S.filter(e=>!e.official).flatMap(e=>[a(e.id),a(e.name)])),U=new Set(L.filter(e=>e.official).flatMap(e=>[a(e.id),a(e.name)])),V=new Set(L.filter(e=>!e.official).flatMap(e=>[a(e.id),a(e.name)])),z=new Set(I.flatMap(e=>[a(e.id),a(e.name)])),X=new Set(E.flatMap(e=>[a(e.id),a(e.name)])),Z=new Set(E.map(e=>e.command.trim())),q=new Set(["security-review","pr-comments","release-notes","add-dir","code-review","simplify"]),F=/(@anthropic-ai\/|anthropic\.com|github\.com\/anthropics)/i,Q=/(^|\s)(npx|uvx|pipx|bunx|mcp-remote|deno\s+run|docker\s+run)(\s|$)/i;function W(e){return[e.command,...e.args??[],e.url,e.repository,e.homepage].filter(Boolean).join(" ").toLowerCase()}const l=e=>({provenance:"anthropic",reason:e}),y=e=>({provenance:"community",reason:e});function Y(e,t,n){switch(e){case"mcp":return j.has(t)?l("official MCP server (catalog)"):$.has(t)?y("third-party server (catalog)"):null;case"skill":case"command":return H.has(t)?l("official Anthropic skill (catalog)"):J.has(t)?y("third-party skill (catalog)"):null;case"plugin":return U.has(t)?l("official Anthropic plugin (catalog)"):V.has(t)?y("third-party plugin (catalog)"):null;case"subagent":return z.has(t)?l("bundled Anthropic subagent (catalog)"):null;case"hook":return X.has(t)||n&&Z.has(n.trim())?l("bundled hook (catalog)"):null}}function ee(e,t){return e.repository?"has a source repository":e.homepage?"has a homepage":e.url?"remote endpoint":Q.test(t)?"installed from a package registry":null}function te(e){const t=a(e.name),n=W(e),o=Y(e.type,t,e.command);if(o)return o;if((e.type==="command"||e.type==="skill")&&q.has(t))return l("built-in Claude Code command");if(F.test(n))return l("Anthropic package or repo");const r=ee(e,n);return r?y(r):{provenance:"local",reason:"no external source — assumed self-created"}}function ne(e,t,n){return`${e}:${t??"-"}:${n}`}const c={anthropic:"Anthropic",community:"Community",local:"Local"},N={anthropic:"accent",community:"warn",local:"dim"},oe=["anthropic","community","local"];function se({input:e,scope:t,interactive:n=!0,className:o=""}){const r=G(),{overrides:d,load:h,setOverride:k}=K(),[v,m]=x.useState(!1),w=x.useRef(null);x.useEffect(()=>{r&&h(r)},[r,h]),x.useEffect(()=>{if(!v)return;const s=C=>{w.current&&!w.current.contains(C.target)&&m(!1)},g=C=>{C.key==="Escape"&&m(!1)};return window.addEventListener("mousedown",s),window.addEventListener("keydown",g),()=>{window.removeEventListener("mousedown",s),window.removeEventListener("keydown",g)}},[v]);const b=ne(e.type,t??null,e.name),f=te(e),p=d[b],u=p??f.provenance,M=p?`Origin manually set to ${c[u]} — auto-detected ${c[f.provenance]} (${f.reason})`:`Auto-detected ${c[u]}: ${f.reason}`,A=i.jsxs(_,{tone:N[u],title:M,className:`${n?"cursor-pointer hover:brightness-125":""} ${o}`,children:[c[u],p&&i.jsx("span",{className:"w-1 h-1 rounded-full bg-current opacity-70","aria-hidden":!0})]});return n?i.jsxs("span",{ref:w,className:"relative inline-flex",children:[i.jsx("button",{type:"button",onClick:s=>{s.stopPropagation(),m(g=>!g)},className:"inline-flex","aria-label":`Origin: ${c[u]}. Click to change.`,children:A}),v&&i.jsxs("span",{className:`absolute ${R.dialog} top-full right-0 mt-1 min-w-[7.5rem] rounded-md border border-line bg-bg-elev shadow-lg py-1 text-left`,onClick:s=>s.stopPropagation(),children:[i.jsx("span",{className:"block px-2 pb-1 text-[10px] uppercase tracking-wide text-fg-faint",children:"Mark origin as"}),oe.map(s=>i.jsxs("button",{type:"button",onClick:()=>{k(b,s),m(!1)},className:`flex w-full items-center gap-2 px-2 py-1 text-[12px] hover:bg-bg-hi/60 ${u===s?"text-fg":"text-fg-dim"}`,children:[i.jsx("span",{className:`w-2 h-2 rounded-full border ${T[N[s]]}`,"aria-hidden":!0}),c[s],p===s&&i.jsx("span",{className:"ml-auto text-[10px] text-fg-faint",children:"set"})]},s)),i.jsx("div",{className:"my-1 border-t border-line"}),i.jsxs("button",{type:"button",onClick:()=>{k(b,null),m(!1)},disabled:!p,className:"flex w-full items-center gap-2 px-2 py-1 text-[12px] text-fg-dim hover:bg-bg-hi/60 disabled:opacity-40 disabled:hover:bg-transparent",title:`Revert to auto-detection (${c[f.provenance]})`,children:["Auto-detect",i.jsx("span",{className:"ml-auto text-[10px] text-fg-faint",children:c[f.provenance]})]})]})]}):A}export{se as P};
@@ -0,0 +1,14 @@
1
+ import{I as e,af as we,X as r,ac as Te,A as ue,t as V,a4 as O,y as q,G as le,v as Y,W as be,F as Le,ad as re,$ as ve,a0 as je,w as ke,ai as de,n as Me,N as W,g as Oe,d as Ne,i as ye,D as G,b as D,l as Fe,O as Pe,a8 as Ce,c as ae,h as Ae,E as Ue,a2 as Ve,o as ze,M as _e,a9 as Qe,a7 as se,m as We,C as Ye,ag as Ke,Y as Xe,aj as Ze,ah as $e,L as et,f as he}from"./index-BfPVknuV.js";import{l as tt}from"./listSkills-QORduPIk.js";import{T as st}from"./Toggle-Bos67yDJ.js";import"./monaco-editor-BW5C4Iv1.js";function nt({options:t,active:s,onChange:n}){return e.jsx("div",{className:"inline-flex gap-1 bg-bg-hi p-1 rounded-xl shadow-[inset_0_0_0_1px] shadow-line",children:t.map(({key:a,label:p})=>{const i=s===a;return e.jsx("button",{type:"button",onClick:()=>n(a),className:`px-[18px] py-[7px] rounded-lg text-[13.5px] transition-colors ${i?"bg-bg-elev shadow-[inset_0_0_0_1px] shadow-line font-semibold text-fg":"font-medium text-fg-dim hover:text-fg"}`,children:p},a)})})}const at=5e3;let oe=null,ne=null;async function De(t){const s=Date.now();return!(t!=null&&t.fresh)&&oe&&s-oe.at<at?oe.result:ne||(ne=(async()=>{try{const n=await window.api.schedule.lintQueue();return oe={result:n,at:Date.now()},n}finally{ne=null}})(),ne)}const lt=5,rt=1440*60*1e3,He="sm.scheduler.hiddenCompletedSlugs",ce="sm.scheduler.focusedJobIndex",qe="sm.scheduler.queueFilter";function it(t,s=60){const n=t.trim();return n.length<=s?n:`${n.slice(0,s-1)}…`}const ot=["all","running","investigating","pending","completed","needs_review","failed"];function ct(){try{const t=localStorage.getItem(qe);if(!t)return{text:"",status:"all"};const s=JSON.parse(t);return{text:"",status:ot.includes(s.status)?s.status:"all"}}catch{return{text:"",status:"all"}}}function dt(t){try{localStorage.setItem(qe,JSON.stringify({status:t.status}))}catch{}}function ut(t,s){if(s.status==="all"&&!s.text)return t;const n=s.text.toLowerCase();return t.filter(a=>{if(s.status!=="all"&&a.status!==s.status)return!1;if(!n)return!0;const p=be(a.cwd)??"";return a.title.toLowerCase().includes(n)||a.slug.toLowerCase().includes(n)||p.toLowerCase().includes(n)})}function xt(){try{const t=localStorage.getItem(He);if(!t)return new Set;const s=JSON.parse(t);return Array.isArray(s)?new Set(s.filter(n=>typeof n=="string")):new Set}catch{return new Set}}function Re(t){try{localStorage.setItem(He,JSON.stringify([...t]))}catch{}}function pt({scopeCwd:t=null,navigate:s}){const n=we(x=>x.snapshot),a=r.useMemo(()=>!n||!t?n:{...n,jobs:n.jobs.filter(x=>x.cwd===t)},[n,t]),[p,i]=r.useState(null),[c,u]=r.useState(!1),[o,d]=r.useState(()=>Date.now()),[b,w]=r.useState(()=>xt()),[h,v]=r.useState(!1),[N,C]=r.useState(()=>ct()),[f,j]=r.useState(!1),[A,k]=r.useState("queue"),g=r.useRef(null),[I,P]=r.useState(()=>{try{return Number(localStorage.getItem(ce))||0}catch{return 0}}),[B,xe]=r.useState(""),J=Te();r.useEffect(()=>(window.api.schedule.health().then(i).catch(()=>{}),window.api.schedule.onState(()=>{window.api.schedule.health().then(i).catch(()=>{})})),[]),r.useEffect(()=>{if(!J)return;d(Date.now());const x=setInterval(()=>d(Date.now()),1e3);return()=>clearInterval(x)},[J]);const L=r.useMemo(()=>{if(!a)return 15e4;const x=[];for(const y of a.jobs)if(y.status==="completed"&&y.startedAt&&y.finishedAt){const T=Date.parse(y.finishedAt)-Date.parse(y.startedAt);T>0&&x.push(T)}return x.length===0?15e4:x.reduce((y,T)=>y+T,0)/x.length},[a]),K=r.useRef(new Map);r.useEffect(()=>{if(!a)return;const x=[];for(const y of a.jobs){const T=K.current.get(y.slug);T&&T!==y.status&&x.push(`${y.title}: ${T} → ${y.status}`),K.current.set(y.slug,y.status)}x.length>0&&xe(x.join("; "))},[a]);const X=r.useMemo(()=>{var y;const x=new Map;for(const T of((y=a==null?void 0:a.lastTick)==null?void 0:y.holds)??[])x.set(T.slug,T);return x},[a==null?void 0:a.lastTick]),Z=r.useCallback(x=>{var T,ie,Se;const y=(T=g.current)==null?void 0:T.querySelectorAll("[data-job-row]");if(!(!y||y.length===0)){if(x.key==="ArrowDown"){x.preventDefault();const U=Math.min(I+1,y.length-1);P(U);try{localStorage.setItem(ce,String(U))}catch{}(ie=y[U])==null||ie.focus()}else if(x.key==="ArrowUp"){x.preventDefault();const U=Math.max(I-1,0);P(U);try{localStorage.setItem(ce,String(U))}catch{}(Se=y[U])==null||Se.focus()}}},[I]),pe=r.useCallback(x=>{P(x);try{localStorage.setItem(ce,String(x))}catch{}},[]);if(!a)return null;if(A==="supervisor")return e.jsx($t,{supervisorConfig:a.config.supervisor,onSetConfig:x=>window.api.schedule.setConfig({supervisor:x}),onBack:()=>k("queue")});const{config:ee,jobs:M,paused:me,lastRunAt:H,nextReset:z,effectiveConcurrency:$}=a;if(M.length===0)return e.jsx(ft,{navigate:s});const F={pending:0,running:0,investigating:0,completed:0,needs_review:0,failed:0};for(const x of M)x.status in F&&F[x.status]++;const te=M.filter(x=>x.status==="running"),l=gt({snap:a,now:o,avgDurationMs:L,runningJobs:te}),m=ut(M,N),S=bt(m),{inline:E,collapsedCount:R}=wt(m,b,o,h),_=kt(E,M,S,L,l.kind,o),Q=()=>{const x=new Set(b);for(const y of M)(y.status==="completed"||y.status==="failed")&&x.add(y.slug);w(x),Re(x)},Be=async()=>{const x=M.filter(ie=>ie.status!=="running").length;if(x===0)return;const y=`Archive ${x} non-running PRD${x===1?"":"s"} and remove from the queue?
2
+
3
+ Files are moved to prds-archived/<timestamp>/ and can be restored from disk. Running jobs are kept.`;if(!window.confirm(y))return;const T=await window.api.schedule.clearQueue();T.ok||O.error(`Clear queue failed: ${T.error??"unknown error"}`)},Je=()=>{w(new Set),Re(new Set),v(!1)},Ge=E.some(x=>x.status==="completed");return e.jsxs("div",{className:"overflow-y-auto h-full",children:[e.jsx("div",{"aria-live":"polite","aria-atomic":"true",className:"sr-only",children:B}),e.jsxs("div",{className:"px-9 py-6 max-w-[1100px] mx-auto space-y-4",children:[e.jsxs("div",{className:`flex flex-wrap items-center gap-3 px-4 py-3 rounded-xl border ${vt(l.kind)}`,title:l.tooltip,children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0 flex-1",children:[e.jsx("div",{className:`w-[38px] h-[38px] rounded-xl bg-bg border border-line flex items-center justify-center shrink-0 ${jt(l.kind)}`,children:e.jsx(ue,{name:"clock",size:19})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[14px] text-fg truncate",children:yt(St(l.line1,a.utilization))}),l.line2&&e.jsx("div",{className:"text-[12px] text-fg-faint font-mono mt-0.5 truncate",children:l.line2})]})]}),e.jsxs("span",{className:"ml-auto font-mono text-[11.5px] text-fg-faint whitespace-nowrap",children:[($==null?void 0:$.cap)??5," slot",(($==null?void 0:$.cap)??5)!==1?"s":""," · last batch ",V(H?Date.parse(H):null,o)]}),l.action&&e.jsx("button",{type:"button",onClick:l.action.onClick,className:"text-[12px] px-3 py-1.5 border border-line hover:border-fg-faint rounded-lg shrink-0 hover:bg-bg-hi text-fg-dim hover:text-fg",title:l.action.title,children:l.action.label})]}),p&&p.consecutiveFailures>5&&p.lastFailureKind==="meter_rate_limited"&&!me&&!f&&e.jsxs("div",{className:"flex items-center gap-3 px-4 py-3 bg-amber-400/15 border border-amber-400/30 rounded-xl",children:[e.jsx("span",{"aria-hidden":"true",children:"⚠"}),e.jsxs("span",{className:"text-[13.5px] text-amber-400/90",children:[e.jsx("strong",{className:"font-semibold",children:"Usage meter unavailable"})," — last good reading"," ",V(p.lastPollAt,o),". Firing on a conservative estimate until it recovers."]}),e.jsx("button",{type:"button",onClick:()=>j(!0),className:"ml-auto text-[12px] text-amber-400/70 hover:text-amber-400 shrink-0",title:"Dismiss this banner. The scheduler continues firing normally.",children:"Dismiss"})]}),e.jsxs("div",{className:"flex items-center gap-[18px] flex-wrap bg-bg-elev border border-line rounded-xl px-4 py-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[13px] text-fg-dim",children:"Start jobs"}),e.jsxs("select",{value:ee.firePolicy??"when-available",onChange:x=>window.api.schedule.setConfig({firePolicy:x.target.value}),className:"appearance-none border border-line bg-bg-hi rounded-lg px-2.5 py-1.5 font-sans text-[13px] text-fg font-medium",title:"when-available: poll usage and fire when tokens are below threshold. on-reset: fire after each 5h reset. manual: only on Run now.",children:[e.jsx("option",{value:"when-available",children:"when available"}),e.jsx("option",{value:"on-reset",children:"only on reset"}),e.jsx("option",{value:"manual",children:"manually"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[13px] text-fg-dim",children:"Up to"}),($==null?void 0:$.source)==="env"&&e.jsx("span",{className:"text-[10px] font-semibold uppercase tracking-wide text-amber-400/90 bg-amber-400/10 border border-amber-400/30 rounded px-1.5 py-0.5",title:"Pinned by SM_SESSION_SLOTS — unset the env var to edit",children:"env"}),e.jsx("input",{type:"number",min:0,max:10,value:($==null?void 0:$.cap)??5,disabled:($==null?void 0:$.source)==="env",onChange:x=>{window.api.schedule.setSessionSlots(Number(x.target.value))},className:"w-11 text-center border border-line bg-bg-hi rounded-lg py-1.5 font-mono text-[13px] text-fg disabled:opacity-50 disabled:cursor-not-allowed",title:($==null?void 0:$.source)==="env"?"pinned by SM_SESSION_SLOTS — unset the env var to edit":"Machine-wide claude -p session slots, shared with chat runs"}),e.jsx("span",{className:"text-[13px] text-fg-dim",children:"at once"})]}),(ee.firePolicy??"when-available")==="when-available"&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[13px] text-fg-dim",children:"Pause above"}),e.jsx("input",{type:"number",min:0,max:100,value:ee.utilizationThreshold??90,onChange:x=>window.api.schedule.setConfig({utilizationThreshold:Number(x.target.value)}),className:"w-11 text-center border border-line bg-bg-hi rounded-lg py-1.5 font-mono text-[13px] text-fg",title:"Fire only when 5h utilization is below this percent"}),e.jsx("span",{className:"text-[13px] text-fg-dim",children:"% of window"})]}),e.jsxs("div",{className:"ml-auto flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>window.api.schedule.forceTick().then(O.fromOutcome).catch(()=>O.error("Failed to fire batch")),disabled:F.pending===0&&F.running===0,className:"bg-accent text-white rounded-lg px-4 py-2 text-[13px] font-semibold whitespace-nowrap disabled:opacity-40 disabled:cursor-not-allowed hover:opacity-90",title:"Bypasses the billing-usage poll. Use when the meter is rate-limited or you want immediate progress.",children:"Fire next batch now"}),e.jsx("button",{type:"button",onClick:()=>window.api.schedule.rescan().then(O.fromOutcome).catch(()=>O.error("Failed to rescan")),className:"bg-bg-hi border border-line text-fg-dim hover:text-fg rounded-lg px-3.5 py-2 text-[13px] font-medium",title:"Re-scan the prds/ folder. Use when you've added or edited PRDs on disk and want the queue to reflect them immediately.",children:"Refresh"})]})]}),te.length>0&&(()=>{const x=($==null?void 0:$.cap)??5,y=M.filter(T=>T.status==="pending").length;return e.jsxs("div",{className:"flex items-center gap-2 text-[12px] font-mono",children:[e.jsxs("span",{className:"px-2 py-0.5 rounded bg-amber-400/20 text-amber-400 shrink-0",children:[te.length,"/",x," running"]}),y>0&&e.jsxs("span",{className:"text-fg-faint",children:["+",y," ready in this group"]})]})})(),M.length>0&&e.jsx(At,{filter:N,onChange:x=>{C(x),dt(x)}}),e.jsxs("div",{className:"bg-bg-hi border border-line rounded-2xl overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between px-[18px] py-3 bg-bg-elev",children:[e.jsxs("span",{className:"font-serif text-base font-semibold text-fg",children:[m.length," job",m.length!==1?"s":""]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("span",{className:"font-mono text-[12px] text-fg-faint",children:[F.pending,"p · ",F.running,"r · ",F.completed,"d",F.failed>0&&e.jsxs("span",{className:"text-accent",children:[" · ",F.failed,"f"]})]}),Ge&&e.jsx("button",{type:"button",onClick:Q,className:"text-[12.5px] text-fg-dim hover:text-fg bg-transparent border-0 cursor-pointer font-medium",title:"Hide completed jobs from this view (queue.json unchanged — they remain in history)",children:"Clear completed"}),e.jsx("button",{type:"button",onClick:Be,disabled:M.every(x=>x.status==="running"),className:"text-[12px] text-accent border border-accent/40 hover:bg-accent/10 rounded-md px-2.5 py-1 cursor-pointer font-medium disabled:opacity-40 disabled:cursor-not-allowed",title:"Archive every non-running PRD (moved to prds-archived/<timestamp>/) and remove them from the queue. Running jobs are kept.",children:"Archive & clear queue…"})]})]}),E.length===0&&R===0&&e.jsx("div",{className:"px-[18px] py-6 text-[13px] text-fg-faint italic",children:"no matching jobs"}),e.jsx("div",{ref:g,role:"list","aria-label":"Job queue",onKeyDown:Z,children:E.map((x,y)=>e.jsx(Ct,{job:x,eta:_.get(x.slug)??null,elapsedMs:x.status==="running"&&x.startedAt?o-Date.parse(x.startedAt):null,avgDurationMs:L,listIndex:y,hold:X.get(x.slug),onFocused:pe},x.slug))}),R>0&&e.jsxs("button",{type:"button",onClick:()=>v(x=>!x),className:"w-full text-left text-[12px] text-fg-faint hover:text-fg-dim px-[18px] py-3 border-t border-line",title:h?"Re-collapse old/cleared completed":"Show all completed (incl. cleared and >24h)",children:[h?"▾":"▸"," ",R," more completed",e.jsx("span",{className:"ml-1.5 font-mono text-[11.5px] text-fg-faint",children:"· fresh & capped at 5 shown inline"}),b.size>0&&e.jsx("span",{className:"ml-2 underline",onClick:x=>{x.stopPropagation(),Je()},children:"un-hide"})]})]}),e.jsx(Rt,{snap:a,health:p,now:o,open:c,setOpen:u}),!me&&e.jsxs("div",{className:"flex gap-2.5 bg-sage/10 border border-sage/30 rounded-xl px-3.5 py-2.5 text-[13.5px] text-fg-dim leading-relaxed",children:[e.jsx("span",{"aria-hidden":"true",children:"✓"}),e.jsxs("span",{children:[e.jsx("strong",{className:"font-semibold text-fg",children:"Nothing needed from you."})," ","Close the app if you like — jobs keep running, and History shows how each one ended."]})]}),e.jsxs("div",{className:"flex items-center justify-between text-[12px] text-fg-faint pt-1 border-t border-line",children:[e.jsxs("span",{children:[z&&e.jsxs("span",{title:`next 5h reset: ${z}`,children:["reset ",q(Date.parse(z)-o)]}),H&&e.jsxs("span",{className:"ml-2",title:H,children:["last run ",q(o-Date.parse(H))," ago"]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("button",{type:"button",onClick:()=>k("supervisor"),className:"hover:text-fg-dim underline",title:"Open supervisor log and settings",children:"supervisor"}),e.jsx("button",{type:"button",onClick:()=>window.api.schedule.openFolder(),className:"hover:text-fg-dim underline",children:"folder"})]})]})]})]})}const mt=[{title:"Create an Epic",body:"Describe the outcome you want in the Epics tab. Its thread writes the PRD files into the epic's folder."},{title:"Queue what it wrote",body:"The PRDs tab lists every file the epic produced. Queue one, or the whole epic, and they appear here."},{title:"Leave it alone",body:"Jobs start themselves inside your window, pause on rate-limit, and resume at the reset. History records how each ended."}],ht=[{term:"Epic",def:"A goal, and the folder of PRDs written to reach it."},{term:"PRD",def:"One markdown file = one job. Authored by the epic."},{term:"5-hour window",def:"Your Claude billing window, on a rolling clock."},{term:"Session pool",def:"5 slots shared with terminal and epic chats."}];function ft({navigate:t}){return e.jsx("div",{className:"overflow-y-auto h-full",children:e.jsx("div",{className:"px-9 py-6 max-w-[900px] mx-auto",children:e.jsxs("div",{className:"bg-bg-hi border border-line rounded-2xl px-9 py-8",children:[e.jsx("h2",{className:"m-0 font-serif text-[25px] font-semibold text-fg",children:"Nothing to run yet — the scheduler needs an Epic."}),e.jsx("p",{className:"mt-2 mb-6 text-[14.5px] text-fg-dim leading-relaxed max-w-[580px]",children:"You don't write PRDs here. An Epic breaks its goal into numbered PRD files, and this page runs them in order. Two steps, once."}),e.jsx("div",{className:"grid grid-cols-3 gap-3.5",children:mt.map((s,n)=>{const a=n===0;return e.jsxs("div",{className:`bg-bg border rounded-xl px-4 py-4 flex flex-col gap-2 ${a?"border-accent shadow-[0_0_0_3px_rgba(184,92,52,.09)]":"border-line"}`,children:[e.jsx("span",{className:`w-6 h-6 rounded-full grid place-items-center font-mono text-[12px] font-semibold ${a?"bg-accent text-white":"bg-bg-elev text-fg-dim"}`,children:n+1}),e.jsx("h3",{className:"m-0 text-[15px] font-semibold text-fg",children:s.title}),e.jsx("p",{className:"m-0 text-[13.5px] text-fg-dim leading-relaxed",children:s.body}),a&&e.jsx("button",{type:"button",onClick:()=>t==null?void 0:t("terminal"),className:"self-start bg-accent text-white rounded-lg px-3.5 py-1.5 text-[13px] font-semibold mt-1",children:"Go to Epics →"})]},s.title)})}),e.jsx("dl",{className:"flex mt-[22px] pt-4 border-t border-line gap-5 flex-wrap",children:ht.map(({term:s,def:n})=>e.jsxs("div",{className:"flex-1 min-w-[150px]",children:[e.jsx("dt",{className:"text-[13.5px] font-semibold text-fg mb-0.5",children:s}),e.jsx("dd",{className:"m-0 text-[12.5px] text-fg-faint leading-relaxed",children:n})]},s))})]})})})}function gt({snap:t,now:s,avgDurationMs:n,runningJobs:a}){const{config:p,jobs:i,paused:c,nextReset:u,utilization:o,effectiveConcurrency:d}=t;let b=0,w=0;for(const j of i)j.status==="pending"?b++:j.status==="completed"&&w++;const h=a.length,v=b+h,N=(d==null?void 0:d.cap)??5;if(h>0){const j=a.reduce((P,B)=>(P.startedAt??"")<(B.startedAt??"")?P:B),A=j.startedAt?s-Date.parse(j.startedAt):0,k=w+h,g=w+v,I=h>1?` · ${h}/${N} parallel`:"";return{kind:"running",line1:`Running ${k}/${g}${I} · ${le(A)}`,line2:h===1?j.title:a.map(P=>P.title).join(", "),tooltip:a.map(P=>`${P.slug} (g${P.parallelGroup})`).join("; ")}}if(c){const j=c.resumeAt?Date.parse(c.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"}[c.reason]??`Paused — ${c.reason}`,line2:c.reason==="auth"?"Run `claude` in any terminal to refresh credentials, then Resume":j!==null&&j>0?`auto-resume ${Y(Date.parse(c.resumeAt))} (in ${q(j)})`:c.resumeAt?"resuming…":"no auto-resume scheduled",tooltip:c.resumeAt??"",action:{label:"Resume",onClick:()=>window.api.schedule.resume(),title:"Clear the pause and resume queue immediately"}}}if(v===0)return{kind:"idle",line1:"No work queued",line2:null};const C=p.firePolicy??"when-available";if(C==="manual")return{kind:"manual",line1:`Manual · ${b} pending`,line2:"click Fire next batch now to fire",action:{label:"Fire next batch now",onClick:()=>window.api.schedule.forceTick().then(O.fromOutcome).catch(()=>O.error("Failed to fire batch")),title:"Bypasses the billing-usage poll. Use when the meter is rate-limited or you want immediate progress."}};if(C==="on-reset"){if(!u)return{kind:"on-reset",line1:"On-reset · waiting for billing data",line2:null};const j=Date.parse(u)+p.offsetMinutes*6e4,A=j-s;return{kind:"on-reset",line1:`On-reset · ${b} pending`,line2:A>0?`fires ${Y(j)} (in ${q(A)})`:"firing now…"}}const f=p.utilizationThreshold??90;if(o==null)return{kind:"auto-soon",line1:`Auto · ${b} pending`,line2:"checking token availability…"};if(o>=f){const j=u?Date.parse(u)-s:null;return{kind:"auto-throttled",line1:`Auto · throttled (util ${o.toFixed(0)}% ≥ ${f}%)`,line2:j&&j>0?`next reset ${Y(Date.parse(u))} (in ${q(j)})`:"will fire when usage drops"}}return{kind:"auto-soon",line1:`Auto · ${b} pending · util ${o.toFixed(0)}%`,line2:"fires within 2 min (poll cycle)"}}function bt(t){const s=t.filter(a=>a.status==="running"||a.status==="pending").sort((a,p)=>a.parallelGroup-p.parallelGroup||a.slug.localeCompare(p.slug)),n=new Map;return s.forEach((a,p)=>n.set(a.slug,p)),n}function wt(t,s,n,a){if(a)return{inline:t,collapsedCount:0};const p=t.filter(d=>d.status==="completed").sort((d,b)=>{const w=d.finishedAt?Date.parse(d.finishedAt):0;return(b.finishedAt?Date.parse(b.finishedAt):0)-w}),i=new Set;let c=0;for(const d of p){if(c>=lt)break;s.has(d.slug)||d.finishedAt&&n-Date.parse(d.finishedAt)>rt||(i.add(d.slug),c++)}const u=[];let o=0;for(const d of t){if(d.status==="failed"&&s.has(d.slug)){o++;continue}if(d.status!=="completed"){u.push(d);continue}i.has(d.slug)?u.push(d):o++}return{inline:u,collapsedCount:o}}function vt(t){return t==="running"?"bg-amber-400/10 border-amber-400/25":t==="paused"?"bg-amber-500/10 border-amber-500/25":t==="auto-throttled"?"bg-amber-500/5 border-amber-500/15":"bg-bg-elev border-line"}function jt(t){return t==="running"||t==="auto-soon"?"text-accent":t==="idle"?"text-sage":t==="paused"||t==="auto-throttled"?"text-butter":"text-fg-faint"}const Nt=["Running","Paused","Manual","On-reset","Auto"];function yt(t){for(const s of Nt)if(t.startsWith(s))return e.jsxs(e.Fragment,{children:[e.jsx("strong",{className:"font-bold",children:s}),t.slice(s.length)]});return t}function St(t,s){return s==null||t.includes("util")?t:`${t} · util ${Math.round(s)}%`}function kt(t,s,n,a,p,i){const c=new Map;if(p==="paused"||p==="manual"||p==="auto-throttled"){for(const d of t)c.set(d.slug,null);return c}const u=s.find(d=>d.status==="running"&&d.startedAt),o=u!=null&&u.startedAt?i-Date.parse(u.startedAt):0;for(const d of t){if(d.status!=="pending"){c.set(d.slug,null);continue}const b=n.get(d.slug)??0;let w=b*a;b>0&&(w-=Math.min(a,o)),c.set(d.slug,w<=5e3?"~now":`~${le(w)}`)}return c}function Pt({job:t,eta:s,elapsedMs:n,avgDurationMs:a,listIndex:p,onFocused:i,hold:c}){const[u,o]=r.useState(!1),[d,b]=r.useState(!1),w=re(I=>I.sessions),h=r.useMemo(()=>ve(t,w),[t,w]),v=h.known&&h.epicId?w[h.epicId]:null,N=r.useCallback(I=>{je(I),window.dispatchEvent(new CustomEvent("sm:navigate",{detail:"terminal"}))},[]),C=t.status==="running",f=t.status==="failed";let j=null;C&&n!==null?j=`${ke(n)} elapsed`:t.status==="completed"&&t.startedAt&&t.finishedAt?j=`took ${le(Date.parse(t.finishedAt)-Date.parse(t.startedAt))}`:s&&(j=s);const A=t.error??null,k=f&&A?A.split(`
4
+ `)[0]:t.status==="needs_review"&&t.verifierVerdict?de(t.verifierVerdict):null,g=C&&n!==null?Math.min(.99,n/a):0;return e.jsxs("div",{role:"listitem",className:"border-t border-line",children:[e.jsxs("button",{type:"button","data-job-row":!0,"data-job-index":p,onClick:()=>o(I=>!I),onFocus:()=>i(p),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 ${u?"bg-bg-elev/40":""}`,"aria-expanded":u,"aria-label":`${W(t.slug)?`PRD ${W(t.slug)}, `:""}${t.title}, ${t.status}${j?`, ${j}`:""}`,title:t.title,children:[e.jsx(Me,{status:t.status}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-baseline gap-2 text-[14.5px] font-medium text-fg leading-snug",children:[W(t.slug)&&e.jsx(Oe,{n:W(t.slug)}),t.title]}),k&&e.jsx("div",{className:`text-[12.5px] mt-0.5 ${f?"text-accent/80":"text-fg-faint"}`,children:k}),c&&e.jsxs("div",{className:"text-[12.5px] mt-0.5 text-amber-400/90 font-mono",children:["held · waiting on ",c.dep," (",c.depStatus,")"]}),e.jsx(Ne,{epicId:h.epicId,label:h.label?it(h.label):null,onOpen:N,testId:"job-row-prompt-session-chip",className:"mt-0.5"})]}),e.jsx(ye,{cwd:t.cwd}),e.jsxs("span",{className:"inline-flex items-center gap-2.5 font-mono text-xs text-fg-faint shrink-0",children:[j,e.jsx("span",{className:`text-fg-faint inline-flex transition-transform duration-150 ${u?"rotate-90":""}`,"aria-hidden":"true",children:e.jsx(ue,{name:"chevron",size:14})})]})]}),C&&!u&&e.jsx("div",{className:"h-1 bg-line mx-[18px] mb-3 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-accent transition-all duration-1000",style:{width:`${Math.max(4,g*100)}%`}})}),u&&e.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:[e.jsxs(G,{label:"Status",children:[e.jsx(D,{k:"result",v:t.exitCode!==null?`exit ${t.exitCode}`:"—"}),e.jsx(D,{k:"state",v:t.status.replace(/_/g," ")}),t.verifierVerdict&&e.jsx(D,{k:"verdict",v:de(t.verifierVerdict)}),A&&e.jsx(D,{k:"error",v:A.split(`
5
+ `)[0],wrap:!0})]}),e.jsxs(G,{label:"Timing",children:[e.jsx(D,{k:"started",v:t.startedAt?Y(Date.parse(t.startedAt)):"—"}),e.jsx(D,{k:"finished",v:t.finishedAt?Y(Date.parse(t.finishedAt)):"—"}),e.jsx(D,{k:"duration",v:t.startedAt&&t.finishedAt?le(Date.parse(t.finishedAt)-Date.parse(t.startedAt)):C&&n!==null?ke(n):"—"})]}),e.jsxs(G,{label:"Location",children:[e.jsx(D,{k:"group",v:`${t.parallelGroup} · ${t.slug}`}),e.jsx(D,{k:"cwd",v:t.cwd??"—",wrap:!0}),e.jsx(D,{k:"epic",v:h.label??h.epicId??"—",wrap:!0}),e.jsx(D,{k:"epic id",v:h.epicId??"—",wrap:!0}),e.jsx(D,{k:"prompt id",v:t.sourcePromptId??"—",wrap:!0}),e.jsx(D,{k:"source tab",v:t.sourceTabId??"—",wrap:!0})]}),e.jsx(G,{label:"Actions",children:e.jsxs("div",{className:"flex flex-col gap-1.5 items-start",children:[v&&e.jsx("button",{type:"button","data-testid":"job-row-prompt-session-link",title:v.goalText,onClick:()=>N(v.id),className:"text-[13px] font-semibold text-accent hover:text-accent/80 bg-transparent border-0 cursor-pointer p-0",children:"view epic →"}),t.runId&&e.jsx("button",{type:"button",onClick:()=>b(!0),className:"text-[13px] font-semibold text-fg-dim hover:text-fg bg-transparent border-0 cursor-pointer p-0",children:"view log →"}),t.status!=="pending"&&t.status!=="running"&&e.jsx("button",{type:"button",onClick:()=>window.api.schedule.resetJob(t.slug),className:"text-[13px] font-semibold text-fg-dim hover:text-fg bg-transparent border-0 cursor-pointer p-0",children:"reset to pending →"})]})})]}),d&&t.runId&&e.jsx(Fe,{runId:t.runId,slug:t.slug,title:t.title||t.slug,onClose:()=>b(!1)})]})}const Ct=r.memo(Pt);function At({filter:t,onChange:s}){const n=[{label:"All",value:"all"},{label:"Running",value:"running"},{label:"Investigating",value:"investigating"},{label:"Pending",value:"pending"},{label:"Completed",value:"completed"},{label:"Needs review",value:"needs_review"},{label:"Failed",value:"failed"}];return e.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[e.jsxs("div",{className:"relative flex-1 min-w-[200px] max-w-[320px]",children:[e.jsx("span",{className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-fg-faint inline-flex","aria-hidden":"true",children:e.jsx(ue,{name:"search",size:15})}),e.jsx("input",{type:"text",value:t.text,onChange:a=>s({...t,text:a.target.value}),placeholder:"filter jobs…",className:"w-full bg-bg-hi border border-line rounded-xl py-2 pl-9 pr-3 text-[13.5px] text-fg placeholder:text-fg-faint focus:outline-none focus:border-fg-faint","aria-label":"Filter jobs by title, slug, or project"})]}),e.jsx(Le,{options:n,value:t.status,onChange:a=>s({...t,status:a})})]})}function $t({supervisorConfig:t,onSetConfig:s,onBack:n}){const[a,p]=r.useState([]),[i,c]=r.useState(()=>Date.now()),u=Te();r.useEffect(()=>{if(!u)return;window.api.supervisor.getLog().then(p).catch(()=>{}),c(Date.now());const d=setInterval(()=>c(Date.now()),5e3);return()=>clearInterval(d)},[u]);const o={enabled:(t==null?void 0:t.enabled)??!0,intervalMinutes:(t==null?void 0:t.intervalMinutes)??15,maxConcurrentProbes:(t==null?void 0:t.maxConcurrentProbes)??2,probeStaleThresholdMinutes:(t==null?void 0:t.probeStaleThresholdMinutes)??10};return e.jsxs("div",{className:"bg-bg-elev/60",children:[e.jsxs("div",{className:"px-3 py-2 flex items-center gap-2 border-b border-line",children:[e.jsx("button",{type:"button",onClick:n,className:"text-[10px] text-fg-faint hover:text-fg-dim",title:"Back to queue",children:"← queue"}),e.jsx("span",{className:"text-[11px] font-medium text-fg-dim",children:"Supervisor"}),e.jsx("button",{type:"button",onClick:()=>window.api.supervisor.getLog().then(p).catch(()=>{}),className:"ml-auto text-[10px] text-fg-faint hover:text-fg-dim underline",title:"Refresh log",children:"refresh"})]}),e.jsxs("div",{className:"px-3 py-2 space-y-1.5 border-b border-line",children:[e.jsx("div",{className:"text-[9px] text-fg-faint uppercase tracking-wider",children:"Config"}),e.jsxs("div",{className:"flex items-center gap-3 flex-wrap text-[10px] text-fg-faint",children:[e.jsxs("label",{className:"flex items-center gap-1",children:[e.jsx("input",{type:"checkbox",checked:o.enabled,onChange:d=>s({enabled:d.target.checked}),className:"cursor-pointer"}),e.jsx("span",{children:"enabled"})]}),e.jsxs("label",{className:"flex items-center gap-1",title:"How often to check for wedged jobs (minutes)",children:[e.jsx("span",{children:"interval"}),e.jsx("input",{type:"number",min:5,max:60,value:o.intervalMinutes,onChange:d=>s({intervalMinutes:Number(d.target.value)}),className:"w-10 bg-bg border border-line rounded px-1 py-0.5 font-mono"}),e.jsx("span",{children:"min"})]}),e.jsxs("label",{className:"flex items-center gap-1",title:"Max concurrent Opus probes per tick",children:[e.jsx("span",{children:"probes"}),e.jsx("input",{type:"number",min:1,max:5,value:o.maxConcurrentProbes,onChange:d=>s({maxConcurrentProbes:Number(d.target.value)}),className:"w-8 bg-bg border border-line rounded px-1 py-0.5 font-mono"})]}),e.jsxs("label",{className:"flex items-center gap-1",title:"Probe a job only if no JSONL event in this many minutes",children:[e.jsx("span",{children:"stale"}),e.jsx("input",{type:"number",min:5,max:30,value:o.probeStaleThresholdMinutes,onChange:d=>s({probeStaleThresholdMinutes:Number(d.target.value)}),className:"w-8 bg-bg border border-line rounded px-1 py-0.5 font-mono"}),e.jsx("span",{children:"min"})]})]})]}),e.jsxs("div",{className:"px-3 py-2",children:[e.jsxs("div",{className:"text-[9px] text-fg-faint uppercase tracking-wider mb-1",children:["Recent probes (last ",a.length,")"]}),a.length===0?e.jsx("div",{className:"text-[10px] text-fg-faint italic",children:"No probes yet."}):e.jsx("div",{className:"space-y-0.5 max-h-64 overflow-y-auto",children:a.map((d,b)=>e.jsx(Dt,{entry:d,now:i},`${d.ts}-${b}`))})]})]})}function Dt({entry:t,now:s}){const n=t.action!=="none",a=q(s-t.ts);return e.jsxs("div",{className:`text-[10px] px-1.5 py-1 rounded font-mono ${n?"bg-red-500/10 border border-red-500/20":"bg-bg/40"}`,title:t.reason,children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsxs("span",{className:"text-fg-faint shrink-0",children:[a," ago"]}),e.jsx("span",{className:`shrink-0 px-1 rounded ${t.verdict==="stuck"?"text-red-400 bg-red-500/10":"text-green-500/70"}`,children:t.verdict}),e.jsx("span",{className:"truncate text-fg-dim",children:t.jobSlug}),n&&e.jsxs("span",{className:"shrink-0 text-red-400",children:[t.action,t.targetPid?` pid=${t.targetPid}`:""]}),t.costUsd!==null&&e.jsxs("span",{className:"shrink-0 text-fg-faint",children:["$",t.costUsd.toFixed(3)]})]}),e.jsx("div",{className:"text-fg-faint truncate mt-0.5",children:t.reason})]})}function Rt({snap:t,health:s,now:n,open:a,setOpen:p}){const[i,c]=r.useState(null),[u,o]=r.useState(!1),d=`${t.jobs.length}:${t.lastRunAt??""}`;r.useEffect(()=>{let k=!0;return o(!0),De().then(g=>{k&&c(g)}).catch(()=>{}).finally(()=>{k&&o(!1)}),()=>{k=!1}},[d]);let b=0,w=0;const h=i?i.reports.filter(k=>k.findings.length>0):[];for(const k of h)for(const g of k.findings)g.severity==="error"?b++:w++;const v=b===0&&w===0,N=i?v?`queue lint clear (${i.reports.length} scanned)`:`queue lint ${b} error${b===1?"":"s"}${w>0?`, ${w} warn${w===1?"":"s"}`:""}`:u?"scanning…":"idle",C=(s==null?void 0:s.consecutiveFailures)??0,f=s?`${C} poll failure${C===1?"":"s"} since boot`:null,j=C>0||((s==null?void 0:s.pauseReason)??null)!==null||!v,A=[f,N].filter(Boolean);return e.jsxs("div",{className:"flex flex-col gap-2 bg-bg-hi border border-line rounded-xl px-4 py-3 text-[13.5px] text-fg-dim",children:[e.jsxs("button",{type:"button",onClick:()=>p(!a),className:"flex items-center gap-2.5 w-full text-left","aria-expanded":a,title:"Scheduler poll health and queue-lint findings, in one place",children:[e.jsx("span",{className:`w-2 h-2 rounded-full shrink-0 ${j?"bg-butter":"bg-sage"}`,"aria-hidden":"true"}),e.jsx("strong",{className:"text-fg font-semibold shrink-0",children:"Diagnostics"}),e.jsx("span",{className:"truncate",children:A.join(" · ")}),e.jsx("span",{className:"ml-auto text-fg-faint shrink-0","aria-hidden":"true",children:a?"▾":"▸"})]}),a&&e.jsxs("div",{className:"pl-[18px] space-y-3 font-mono text-[12px]",children:[s&&e.jsxs("div",{className:"space-y-0.5",children:[e.jsxs("div",{children:["booted: ",V(s.bootedAt,n)]}),e.jsxs("div",{children:["last poll: ",V(s.lastPollAt,n)," · ",s.lastPollOk?"ok":"failed"]}),s.backoffNextAt!==null&&s.backoffNextAt>n&&e.jsxs("div",{children:["retry in: ",q(s.backoffNextAt-n)]}),s.nextResetCached&&e.jsxs("div",{children:["cached reset: ",Y(Date.parse(s.nextResetCached))]}),s.runningJobs.length>0&&e.jsxs("div",{children:["running: ",s.runningJobs.map(k=>`${k.slug}(pid ${k.pid})`).join(", ")]})]}),i&&e.jsxs("div",{className:"space-y-1",children:[v?e.jsxs("div",{className:"text-sage",children:["✓ no issues in ",i.reports.length," PRD",i.reports.length!==1?"s":""]}):h.map(k=>e.jsxs("div",{children:[e.jsx("div",{className:"text-fg-dim truncate",title:k.slug,children:k.slug}),k.findings.map((g,I)=>e.jsxs("div",{className:`pl-3 truncate ${g.severity==="error"?"text-accent/80":"text-butter/90"}`,title:g.snippet,children:[g.severity==="error"?"✗":"⚠"," L",g.line,": ",g.snippet]},`${k.slug}-${I}`))]},k.slug)),e.jsx("button",{type:"button",onClick:()=>{o(!0),De({fresh:!0}).then(c).catch(()=>{}).finally(()=>o(!1))},className:"text-fg-faint hover:text-fg-dim underline",children:u?"…":"rerun lint"})]})]})]})}const Et=["title","cwd","estimateMinutes","parallelGroup","sourcePromptId","sourceTabId","tag"];function It(t){if(t==null)return"";if(typeof t=="boolean"||typeof t=="number")return String(t);const s=String(t);return s===""||/^(true|false|null|~)$/.test(s)||/^-?\d+(\.\d+)?$/.test(s)||/^\s|\s$/.test(s)||s.startsWith("'")||s.startsWith('"')||s.includes(`
6
+ `)?s.includes("'")?`"${s.replace(/"/g,'\\"')}"`:`'${s}'`:s}function Tt(t,s){var p;const n=[];for(const i of Et){const c=t[i];if(c==null||c==="")continue;const u=(p=t._raw)==null?void 0:p[i];if(u&&u.parsed===c){n.push(u.line);continue}if(typeof c=="number"){n.push(`${i}: ${c}`);continue}n.push(`${i}: ${It(c)}`)}if(t.extras)for(const i of Object.keys(t.extras)){const c=t.extras[i];!c||!c.lines.length||n.push(c.lines.join(`
7
+ `))}return`---
8
+ ${n.join(`
9
+ `)}
10
+ ---
11
+ ${s}`}function fe(t){return t.filter(s=>!s.archived)}function Lt(t){je(t),window.dispatchEvent(new CustomEvent("sm:navigate",{detail:"terminal"}))}function ge({label:t,tip:s,onClick:n,disabled:a,primary:p}){return e.jsx(ze,{content:s,align:"bottom-center",children:e.jsx("button",{title:s,onClick:n,disabled:a,className:`px-2 py-0.5 text-xs rounded border disabled:opacity-40 disabled:cursor-not-allowed ${p?"text-accent border-accent/50 hover:bg-bg-hi":"text-fg-dim border-line hover:text-fg hover:bg-bg-hi"}`,children:t})})}function Mt({scopeCwd:t=null}){const[s,n]=r.useState([]),[a,p]=r.useState(null),[i,c]=r.useState(null),[u,o]=r.useState(null),[d,b]=r.useState(!1),[w,h]=r.useState(!0),[v,N]=r.useState(new Set),[C,f]=r.useState(!1),[j,A]=r.useState(!1),[k,g]=r.useState(!1),[I,P]=r.useState(null);r.useEffect(()=>{let l=!0;return window.api.schedule.listPrds().then(m=>{l&&(n(fe(m)),h(!1))}).catch(m=>{l&&(h(!1),O.error(`Scheduler: failed to load PRD list — ${m instanceof Error?m.message:"unknown error"}`))}),()=>{l=!1}},[]);const B=we(l=>l.snapshot),xe=re(l=>l.sessions);r.useEffect(()=>{B&&p(B)},[B]);const J=r.useMemo(()=>[...s].filter(l=>!t||l.cwd===t).sort((l,m)=>m.mtimeMs-l.mtimeMs||l.slug.localeCompare(m.slug)),[s,t]);r.useEffect(()=>{const l=Ve();l&&c(l);const m=S=>c(S.detail);return window.addEventListener("sm:select-prd",m),()=>window.removeEventListener("sm:select-prd",m)},[]);const L=r.useMemo(()=>(a==null?void 0:a.jobs.find(l=>l.slug===i))??null,[a,i]),K=Pe(L);function X(l){var S;const m=(S=s.find(E=>E.slug===l))==null?void 0:S.cwd;return m?`${m}/session-manager-operations/scheduler/prds/${l}.md`:null}r.useEffect(()=>{if(!i)return;const l=X(i);l&&Ce.getState().openFile(l)},[i,s]);function Z(l){c(l),o(null),b(!1)}function pe(){c(null)}async function ee(){if(!i)return;if(!(L!=null&&L.runId)){o("no log available (job has not run yet)"),b(m=>!m);return}const l=await window.api.schedule.readLog(L.runId,i);o(l.ok?l.text??"":`error: ${l.error}`),b(m=>!m)}if(w)return e.jsx(ae,{title:"loading PRDs…"});const M=l=>{N(m=>{const S=new Set(m);return S.has(l)?S.delete(l):S.add(l),S})};!(J.length>0&&J.every(l=>v.has(l.slug)))&&J.some(l=>v.has(l.slug));const H=()=>N(new Set);async function z(){try{const l=await window.api.schedule.listPrds();n(fe(l))}catch{}}async function $(){const l=`new-prd-${Date.now()}`,m=Tt({title:"New PRD",cwd:"",estimateMinutes:60,parallelGroup:99},`## Task
12
+
13
+ Describe the task here.
14
+ `);try{const S=await window.api.schedule.writePrd(l,m);if(!S.ok){O.error(`Failed to create PRD: ${S.error}`);return}const E=await window.api.schedule.listPrds();n(fe(E)),Z(l)}catch(S){O.error(`Failed to create PRD: ${S instanceof Error?S.message:String(S)}`)}}async function F(){var l;g(!0),P(null);try{const m=[...v],S=await window.api.schedule.archivePrds(m);if(!S.ok)P(S.error??"archive failed");else{const E=((l=S.results)==null?void 0:l.filter(R=>!R.ok))??[];E.length>0&&O.warn(`Archive: ${E.length} of ${S.results.length} PRD${E.length===1?"":"s"} failed to move`),H(),f(!1),await z()}}catch(m){P(m instanceof Error?m.message:String(m))}finally{g(!1)}}async function te(l,m){g(!0),P(null);try{const S=[];for(const R of v){const _={slug:R};l!==null&&(_.parallelGroup=l),m!==null&&(_.estimateMinutes=m),S.push(_)}const E=await window.api.schedule.retagPrds(S);if(!E.ok)P(E.error??"retag failed");else{H(),A(!1),await z();for(const R of E.results)if(R.newSlug&&R.newSlug!==R.slug){const _=X(R.slug),Q=X(R.newSlug);_&&Q&&Ce.getState().renameOpenFile(_,Q)}i&&E.results.some(R=>R.slug===i&&R.newSlug&&R.newSlug!==R.slug)&&c(null)}}catch(S){P(S instanceof Error?S.message:String(S))}finally{g(!1)}}return e.jsxs(e.Fragment,{children:[i?e.jsxs("div",{className:"h-full flex flex-col min-h-0",children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 border-b border-line flex-wrap shrink-0",children:[e.jsx("button",{type:"button",onClick:pe,className:"text-[11px] text-fg-faint hover:text-fg",children:"← PRDs"}),e.jsx("span",{className:"font-mono text-xs text-fg-dim truncate",children:i}),e.jsx(Ae,{status:K}),e.jsx("div",{className:"flex-1"}),e.jsx(ge,{label:"Reset",tip:"Reset failed job to pending",onClick:()=>{window.api.schedule.resetJob(i)},disabled:K!=="failed"}),e.jsx(ge,{label:"Run now",tip:"Run all pending jobs immediately",onClick:()=>{window.api.schedule.runNow()}}),e.jsx(ge,{label:d?"Hide log":"Last run log",tip:"Toggle most recent run log",onClick:ee})]}),e.jsx("div",{className:"flex-1 min-h-0",children:e.jsx(Ue,{})}),d&&u!==null&&e.jsxs("div",{className:"border-t border-line max-h-64 overflow-auto bg-bg-elev",children:[e.jsxs("div",{className:"px-3 py-1.5 flex items-center gap-2 border-b border-line sticky top-0 bg-bg-elev",children:[e.jsxs("span",{className:"text-[10px] text-fg-faint font-mono",children:["run log",L!=null&&L.runId?` — ${L.runId}`:""]}),e.jsx("button",{onClick:()=>b(!1),className:"ml-auto text-[10px] text-fg-faint hover:text-fg",children:"close"})]}),e.jsx("pre",{className:"p-3 text-[11px] font-mono text-fg-dim whitespace-pre-wrap",children:u})]})]}):e.jsxs("div",{className:"px-6 py-5 overflow-auto",children:[e.jsxs("div",{className:"flex items-start justify-between mb-5 gap-4",children:[e.jsxs("p",{className:"text-[14px] text-fg-dim leading-relaxed max-w-[560px]",children:["PRDs are the source the scheduler runs from. Each one becomes a"," ",e.jsx("code",{className:"font-mono text-[13px]",children:"claude -p"})," job when you queue it. This is where you write and edit the source — to watch a run in progress, use the Queue tab."]}),e.jsx("button",{type:"button",onClick:$,className:"shrink-0 bg-accent text-white rounded-lg px-4 py-[9px] text-[13.5px] font-semibold leading-none",children:"+ New PRD"})]}),v.size>0&&e.jsxs("div",{className:"mb-4 px-4 py-2 bg-bg border border-line rounded-lg flex items-center gap-2",children:[e.jsxs("span",{className:"text-xs text-fg-dim",children:[v.size," selected"]}),e.jsx("div",{className:"flex-1"}),e.jsx("button",{type:"button",onClick:()=>f(!0),className:"text-xs px-3 py-1.5 rounded border border-line text-fg-dim hover:text-fg hover:bg-bg-hi",children:"Archive…"}),e.jsx("button",{type:"button",onClick:()=>A(!0),className:"text-xs px-3 py-1.5 rounded border border-line text-fg-dim hover:text-fg hover:bg-bg-hi",children:"Retag…"}),e.jsx("button",{type:"button",onClick:H,className:"text-xs px-3 py-1.5 rounded border border-line text-fg-dim hover:text-fg hover:bg-bg-hi",children:"Clear"})]}),J.length===0?e.jsx(ae,{title:"no PRDs found"}):e.jsx("div",{className:"grid gap-3",children:J.map(l=>{const m=a==null?void 0:a.jobs.find(Q=>Q.slug===l.slug),S=Pe(m),E=ve({epicId:l.epicId??(m==null?void 0:m.epicId)??null,sourcePromptId:l.sourcePromptId??(m==null?void 0:m.sourcePromptId)??null,sourceTabId:(m==null?void 0:m.sourceTabId)??null},xe),R=(m==null?void 0:m.status)==="running",_=(m==null?void 0:m.status)==="needs_review";return e.jsxs("div",{className:"flex items-stretch bg-bg-elev border border-line rounded-2xl overflow-hidden",children:[e.jsx("label",{className:"flex items-center px-3 cursor-pointer hover:bg-bg-hi",children:e.jsx("input",{type:"checkbox",checked:v.has(l.slug),onChange:()=>M(l.slug),className:"accent-accent w-3.5 h-3.5"})}),e.jsxs("div",{className:"flex-1 min-w-0 py-4 pr-2",children:[e.jsxs("div",{className:"flex items-center gap-2.5 mb-[5px] flex-wrap",children:[W(l.slug)&&e.jsx(Oe,{n:W(l.slug)}),e.jsx("button",{type:"button",onClick:()=>Z(l.slug),className:"font-serif text-[18px] font-semibold text-fg leading-tight hover:underline text-left",children:l.title||l.slug}),e.jsx(Ae,{status:S}),(m==null?void 0:m.status)&&e.jsx("span",{className:"sr-only",children:m.status})]}),e.jsxs("div",{className:"flex items-center gap-4 font-mono text-xs text-fg-faint flex-wrap",children:[e.jsx(ye,{cwd:l.cwd}),e.jsx(Ne,{epicId:E.epicId,label:E.label,onOpen:Lt}),l.estimateMinutes!=null&&e.jsxs("span",{children:[l.estimateMinutes,"m"]}),e.jsxs("span",{children:["g",l.parallelGroup]}),e.jsxs("span",{children:["edited ",V(l.mtimeMs,Date.now())]})]}),e.jsx("button",{type:"button",onClick:()=>Z(l.slug),className:"mt-1.5 font-mono text-[11px] text-fg-faint hover:text-fg-dim leading-none",children:l.slug}),_&&e.jsxs("div",{className:"mt-3 space-y-2",children:[(m==null?void 0:m.verifierVerdict)&&e.jsxs("div",{className:"text-xs text-fg-faint",children:["verdict: ",e.jsx("span",{className:"font-mono",children:de(m.verifierVerdict)})]}),e.jsx("button",{type:"button",onClick:()=>window.api.schedule.resetJob(l.slug),className:"text-xs px-2.5 py-1 rounded border border-line text-fg-dim hover:text-fg hover:bg-bg-hi",children:"Re-fire"})]})]}),e.jsx("div",{className:"flex flex-col gap-2 items-stretch px-[18px] py-4",children:e.jsx("button",{type:"button",onClick:()=>window.api.schedule.runNow(),disabled:R,className:"bg-fg text-bg rounded-lg px-[18px] py-2 text-[13px] font-semibold whitespace-nowrap disabled:opacity-50",children:R?"Running…":"Queue job"})})]},l.slug)})})]}),e.jsx(Ot,{open:C,count:v.size,busy:k,onClose:()=>f(!1),onConfirm:F}),e.jsx(Ft,{open:j,count:v.size,busy:k,onClose:()=>A(!1),onConfirm:te})]})}function Ot({open:t,count:s,busy:n,onClose:a,onConfirm:p}){return e.jsxs(_e,{open:t,onClose:a,title:"Archive PRDs",children:[e.jsxs("p",{className:"text-xs text-fg-dim",children:["Move ",e.jsx("span",{className:"font-mono",children:s})," PRD",s===1?"":"s"," to"," ",e.jsx("span",{className:"font-mono",children:"prds-archived/<timestamp>/"}),"?"]}),e.jsx("p",{className:"text-[10px] text-fg-faint mt-2",children:"Files are renamed, never deleted. Restore manually from disk if needed."}),e.jsxs("div",{className:"flex justify-end gap-2 mt-4",children:[e.jsx("button",{type:"button",onClick:a,disabled:n,className:"px-2 py-1 text-xs border border-line rounded text-fg-dim hover:text-fg disabled:opacity-40",children:"Cancel"}),e.jsx("button",{type:"button",onClick:p,disabled:n||s===0,className:"px-2 py-1 text-xs border border-accent/60 text-accent rounded hover:bg-bg-hi disabled:opacity-40",children:n?"Archiving…":`Archive ${s}`})]})]})}function Ft({open:t,count:s,busy:n,onClose:a,onConfirm:p}){const[i,c]=r.useState(""),[u,o]=r.useState(""),[d,b]=r.useState(null);r.useEffect(()=>{t&&(c(""),o(""),b(null))},[t]);function w(){b(null);let h=null,v=null;if(i.trim()){const N=Number(i);if(!Number.isInteger(N)||N<0||N>999){b("parallelGroup must be 0–999");return}h=N}if(u.trim()){const N=Number(u);if(!Number.isInteger(N)||N<=0){b("estimateMinutes must be a positive integer");return}v=N}if(h===null&&v===null){b("set at least one field");return}p(h,v)}return e.jsxs(_e,{open:t,onClose:a,title:"Retag PRDs",children:[e.jsxs("p",{className:"text-xs text-fg-dim",children:["Update ",e.jsx("span",{className:"font-mono",children:s})," PRD",s===1?"":"s",". Leave a field blank to keep its current value."]}),e.jsxs("p",{className:"text-[10px] text-fg-faint mt-2",children:["Changing parallelGroup on an ",e.jsx("span",{className:"font-mono",children:"NN-kebab"})," slug renames the file. Every change is logged to ",e.jsx("span",{className:"font-mono",children:"retag-log.jsonl"})," so it's reversible."]}),e.jsxs("div",{className:"mt-3 space-y-2",children:[e.jsxs("label",{className:"flex items-center gap-2 text-xs",children:[e.jsx("span",{className:"w-32 text-fg-faint",children:"parallelGroup:"}),e.jsx("input",{type:"number",min:0,max:999,value:i,onChange:h=>c(h.target.value),placeholder:"(unchanged)",className:"flex-1 bg-bg border border-line rounded px-2 py-1 font-mono text-xs"})]}),e.jsxs("label",{className:"flex items-center gap-2 text-xs",children:[e.jsx("span",{className:"w-32 text-fg-faint",children:"estimateMinutes:"}),e.jsx("input",{type:"number",min:1,value:u,onChange:h=>o(h.target.value),placeholder:"(unchanged)",className:"flex-1 bg-bg border border-line rounded px-2 py-1 font-mono text-xs"})]})]}),d&&e.jsx("div",{className:"mt-2 text-[10px] text-red-300",children:d}),e.jsxs("div",{className:"flex justify-end gap-2 mt-4",children:[e.jsx("button",{type:"button",onClick:a,disabled:n,className:"px-2 py-1 text-xs border border-line rounded text-fg-dim hover:text-fg disabled:opacity-40",children:"Cancel"}),e.jsx("button",{type:"button",onClick:w,disabled:n||s===0,className:"px-2 py-1 text-xs border border-accent/60 text-accent rounded hover:bg-bg-hi disabled:opacity-40",children:n?"Retagging…":`Retag ${s}`})]})]})}function _t(t){je(t),window.dispatchEvent(new CustomEvent("sm:navigate",{detail:"terminal"}))}function Ee(t){return t?t.slice(0,10):""}const Ht=[{value:"all",label:"All"},{value:"completed",label:"Completed"},{value:"failed",label:"Failed"}];function qt({scopeCwd:t=null}){const[s,n]=r.useState(null),[a,p]=r.useState(!0),[i,c]=r.useState(""),[u,o]=r.useState(""),[d,b]=r.useState(""),[w,h]=r.useState("all");r.useEffect(()=>{p(!0),window.api.schedule.getHistory().then(f=>n(f)).catch(f=>n({ok:!1,jobs:[],error:f instanceof Error?f.message:String(f)})).finally(()=>p(!1))},[]);const v=r.useMemo(()=>{if(!(s!=null&&s.jobs))return[];const f=new Set;for(const j of s.jobs){const A=be(j.cwd);A&&f.add(A)}return[...f].sort()},[s]),N=r.useMemo(()=>s!=null&&s.jobs?s.jobs.filter(f=>!(t&&f.cwd!==t||w!=="all"&&f.status!==w||i&&be(f.cwd)!==i||u&&Ee(f.finishedAt)<u||d&&Ee(f.finishedAt)>d)):[],[s,w,i,u,d,t]);if(a)return e.jsx(ae,{title:"Loading history…"});if(!(s!=null&&s.ok)||s.error)return e.jsxs("div",{className:"p-4 text-xs text-red-300",children:["Failed to load history: ",(s==null?void 0:s.error)??"unknown error"]});if(s.jobs.length===0)return e.jsx(ae,{title:"No history yet",hint:"Completed and failed jobs appear here."});const C=w!=="all"||!!i||!!u||!!d;return e.jsxs("div",{className:"h-full flex flex-col",children:[e.jsxs("div",{className:"shrink-0 flex items-center gap-2 px-4 py-2.5 border-b border-line flex-wrap",children:[e.jsx(Le,{options:Ht,value:w,onChange:h,pillPadding:"px-3 py-1"}),e.jsx("span",{className:"w-px h-4 bg-line mx-1","aria-hidden":"true"}),v.length>0&&e.jsxs("select",{value:i,onChange:f=>c(f.target.value),className:"bg-bg-hi border border-line rounded-lg px-2 py-1 text-[12.5px] text-fg-dim max-w-[12rem] font-medium",children:[e.jsx("option",{value:"",children:"All projects"}),v.map(f=>e.jsx("option",{value:f,children:f},f))]}),e.jsxs("div",{className:"flex items-center gap-1.5 text-[12px] text-fg-faint",children:[e.jsx("span",{children:"from"}),e.jsx("input",{type:"date",value:u,onChange:f=>o(f.target.value),className:"bg-bg-hi border border-line rounded-lg px-2 py-1 text-fg-dim font-mono text-[12px]"})]}),e.jsxs("div",{className:"flex items-center gap-1.5 text-[12px] text-fg-faint",children:[e.jsx("span",{children:"to"}),e.jsx("input",{type:"date",value:d,onChange:f=>b(f.target.value),className:"bg-bg-hi border border-line rounded-lg px-2 py-1 text-fg-dim font-mono text-[12px]"})]}),e.jsxs("span",{className:"text-[12px] text-fg-faint ml-auto font-mono",children:[N.length," / ",s.jobs.length]}),C&&e.jsx("button",{type:"button",onClick:()=>{h("all"),c(""),o(""),b("")},className:"text-[12px] text-fg-faint hover:text-fg-dim underline",children:"clear"})]}),e.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto",children:N.length===0?e.jsx(ae,{title:"No matches",hint:"Try adjusting the filters."}):e.jsxs("div",{className:"mx-4 my-3 bg-bg-hi border border-line rounded-2xl overflow-hidden",children:[e.jsx("div",{className:"flex items-center px-[18px] py-3 bg-bg-elev",children:e.jsxs("span",{className:"font-serif text-base font-semibold text-fg",children:[N.length," job",N.length!==1?"s":""]})}),N.map(f=>e.jsx(Bt,{job:f},`${f.slug}-${f.finishedAt??""}`))]})})]})}function Bt({job:t}){const[s,n]=r.useState(!1),[a,p]=r.useState(!1),i=re(h=>h.sessions),c=r.useMemo(()=>ve(t,i),[t,i]),u=t.startedAt&&t.finishedAt?Date.parse(t.finishedAt)-Date.parse(t.startedAt):null,o=t.startedAt?new Date(t.startedAt).toLocaleString():"—",d=t.finishedAt?new Date(t.finishedAt).toLocaleString():"—",b=u!==null?le(u):"—",w=t.exitCode!==null?String(t.exitCode):"—";return e.jsxs("div",{className:"border-t border-line/60",children:[e.jsxs("button",{type:"button",className:`w-full text-left grid items-center gap-4 px-[18px] py-3.5 cursor-pointer transition-colors hover:bg-bg-elev ${s?"bg-bg-elev":"bg-transparent"}`,style:{gridTemplateColumns:"116px 1fr auto auto"},onClick:()=>n(h=>!h),"aria-expanded":s,children:[e.jsx(Me,{status:t.status}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[14.5px] font-medium text-fg leading-snug text-pretty",children:t.title}),t.error&&!s&&(t.status==="failed"||t.status==="needs_review")&&e.jsx("div",{className:"text-[12.5px] mt-0.5 text-accent/80 truncate",children:t.error}),c.epicId&&e.jsx("span",{className:"flex mt-0.5",children:e.jsx(Ne,{epicId:c.epicId,label:c.label,onOpen:_t})})]}),e.jsx(ye,{cwd:t.cwd}),e.jsxs("span",{className:"inline-flex items-center gap-2.5 font-mono text-xs text-fg-faint whitespace-nowrap",children:[b,e.jsx("span",{className:"inline-flex transition-transform duration-150",style:{transform:s?"rotate(90deg)":"none"},"aria-hidden":"true",children:"›"})]})]}),s&&e.jsxs("div",{className:"grid gap-5 px-[18px] pt-1 pb-5 bg-bg-elev",style:{gridTemplateColumns:"repeat(auto-fit, minmax(160px, 1fr))"},children:[e.jsxs(G,{label:"Status",children:[e.jsx(D,{k:"result",v:w}),e.jsx(D,{k:"state",v:t.status.replace("_"," ")}),t.verifierVerdict&&e.jsx(D,{k:"verifier",v:de(t.verifierVerdict)})]}),e.jsxs(G,{label:"Timing",children:[e.jsx(D,{k:"started",v:o}),e.jsx(D,{k:"finished",v:d}),e.jsx(D,{k:"duration",v:b})]}),e.jsxs(G,{label:"Location",children:[e.jsx(D,{k:"group",v:t.parallelGroup!=null?String(t.parallelGroup):"—"}),e.jsx(D,{k:"slug",v:t.slug}),e.jsx(D,{k:"epic",v:c.label??c.epicId??"—",wrap:!0}),t.cwd&&e.jsx(D,{k:"cwd",v:t.cwd,wrap:!0})]}),e.jsx(G,{label:"Actions",children:e.jsxs("div",{className:"flex flex-col gap-2 items-start",children:[t.runId&&e.jsx("button",{type:"button",onClick:h=>{h.stopPropagation(),p(!0)},className:"text-[13px] font-semibold text-fg-dim hover:text-fg bg-transparent border-0 p-0 cursor-pointer",children:"view log →"}),t.status!=="pending"&&e.jsx("button",{type:"button",onClick:h=>{h.stopPropagation(),window.api.schedule.resetJob(t.slug)},className:"text-[13px] font-semibold text-fg-dim hover:text-fg bg-transparent border-0 p-0 cursor-pointer",children:"reset to pending →"}),t.error&&e.jsx("p",{className:"text-[12px] text-accent/90 mt-1 break-words whitespace-pre-wrap max-w-sm m-0",children:t.error})]})})]}),a&&t.runId&&e.jsx(Fe,{runId:t.runId,slug:t.slug,title:t.title||t.slug,onClose:()=>p(!1)})]})}function Jt(t){return t?Object.values(t).reduce((s,n)=>s+(n??[]).reduce((a,p)=>{var i;return a+(((i=p.hooks)==null?void 0:i.length)??0)},0),0):0}function Gt(t){var s,n,a;return t?(((s=t.allow)==null?void 0:s.length)??0)+(((n=t.deny)==null?void 0:n.length)??0)+(((a=t.ask)==null?void 0:a.length)??0):0}function Ut({navigate:t}){const s=Qe(),n=se(g=>g.files),a=se(g=>g.loadJson),p=se(g=>g.loadText),i=se(g=>g.watchFile),c=se(g=>g.unwatchFile),u=s?We.resolve("user",s,null):null,o=s?Ye.resolve("user",s,null):null,d=s?`${s}/.claude.json`:null;r.useEffect(()=>{const g=[u,d].filter(Boolean);g.forEach(P=>{n[P]||a(P),i(P)});const I=[o].filter(Boolean);return I.forEach(P=>{n[P]||p(P),i(P)}),()=>{[...g,...I].forEach(P=>c(P))}},[u,o,d]);const[b,w]=r.useState(null);r.useEffect(()=>{if(!s)return;let g=!1;return(async()=>{const I=await tt(`${s}/.claude/skills`);g||w(I.length)})(),()=>{g=!0}},[s]);const h=u?n[u]:null,v=d?n[d]:null,N=o?n[o]:null,C=r.useMemo(()=>{if(!(h!=null&&h.exists)||h.parseError)return null;const g=h.diskData;return g===null||typeof g!="object"||Array.isArray(g)?{}:g},[h]),f=r.useMemo(()=>{if(!(v!=null&&v.exists)||v.parseError)return null;const g=v.diskData;return g===null||typeof g!="object"||Array.isArray(g)?{}:g},[v]),j=h?h.parseError?"invalid JSON":null:"loading…",A=v?v.parseError?"invalid JSON":null:"loading…",k=[{key:"settings",title:"Settings",summary:j??(C?`${Object.keys(C).length} top-level key${Object.keys(C).length===1?"":"s"} configured`:"not configured")},{key:"permissions",title:"Permissions",summary:j??(C?`${Gt(C.permissions)} rule(s) configured`:"not configured")},{key:"hooks",title:"Hooks",summary:j??(C?`${Jt(C.hooks)} hook(s) configured`:"not configured")},{key:"mcp",title:"MCP Servers",summary:A??(f?`${Object.keys(f.mcpServers??{}).length} MCP server(s)`:"not configured")},{key:"system-prompt",title:"System Prompt",summary:N!=null&&N.exists&&N.diskRaw.trim().length>0?`configured (${N.diskRaw.length.toLocaleString()} chars)`:"not set"},{key:"skills",title:"Skills",summary:b===null?"loading…":`${b} skill(s) installed`}];return e.jsxs("section",{className:"border border-line rounded-xl bg-bg-hi px-5 py-4",children:[e.jsx("h2",{className:"m-0 mb-1 font-serif text-[18px] font-semibold text-fg",children:"Global Controls"}),e.jsx("p",{className:"mt-0 mb-3 text-[13px] text-fg-dim leading-relaxed",children:"Machine-wide (user-scope) config state for the tabs that default to global here on Home. Read-only summary — open a card to edit."}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-3",children:k.map(g=>e.jsxs("button",{type:"button",onClick:()=>t==null?void 0:t(g.key),className:"text-left border border-line rounded-lg bg-bg px-3 py-2.5 hover:border-accent transition-colors",children:[e.jsx("div",{className:"text-[13px] font-medium text-fg",children:g.title}),e.jsx("div",{className:"mt-0.5 text-[12px] text-fg-dim",children:g.summary})]},g.key))})]})}function Vt({navigate:t}){const s=Ke(),[n,a]=r.useState(!1),[p,i]=r.useState(!1);r.useEffect(()=>{let u=!0;return Xe().then(o=>{u&&a(o.openToHomeOnLaunch===!0)}),()=>{u=!1}},[]);const c=async u=>{a(u),i(!0);try{await Ze({openToHomeOnLaunch:u})}catch{a(!u),O.error('Failed to save "Open to Home on launch" — try again.')}finally{i(!1)}};return e.jsxs("div",{className:"max-w-[760px] space-y-6",children:[e.jsx(Ut,{navigate:t}),e.jsxs("section",{className:"border border-line rounded-xl bg-bg-hi px-5 py-4",children:[e.jsx("h2",{className:"m-0 mb-1 font-serif text-[18px] font-semibold text-fg",children:"Session pool"}),e.jsxs("p",{className:"mt-0 mb-3 text-[13px] text-fg-dim leading-relaxed",children:["One machine-wide pool of concurrent Claude sessions. Scheduler jobs and Epic chat runs each request a slot before launching; work waits when the pool is full. Adjustable from 0 (pauses new launches) to 10 on the Home tab, default 5 — or pin it with"," ",e.jsx("code",{className:"font-mono text-[12px]",children:"SM_SESSION_SLOTS"})," (clamped 0–10)."]}),e.jsxs("div",{className:"flex items-center gap-2",children:[Array.from({length:(s==null?void 0:s.total)??5},(u,o)=>e.jsx("span",{className:`w-3.5 h-3.5 rounded-full border ${o<((s==null?void 0:s.inUse)??0)?"bg-accent border-accent":"bg-bg border-line"}`},o)),e.jsx("span",{className:"ml-2 font-mono text-[12.5px] text-fg-faint",children:s?`${s.inUse} / ${s.total} in use`:"loading…"})]}),s&&s.holders.length>0&&e.jsx("ul",{className:"mt-2 mb-0 pl-0 list-none space-y-0.5",children:s.holders.map((u,o)=>e.jsxs("li",{className:"font-mono text-[12px] text-fg-dim",children:[u.owner," ",e.jsxs("span",{className:"text-fg-faint",children:["since ",new Date(u.at).toLocaleTimeString()]})]},o))})]}),e.jsxs("section",{className:"border border-line rounded-xl bg-bg-hi px-5 py-4",children:[e.jsx("h2",{className:"m-0 mb-1 font-serif text-[18px] font-semibold text-fg",children:"Behavior"}),e.jsx("p",{className:"mt-0 mb-3 text-[13px] text-fg-dim leading-relaxed",children:"Cross-project app behavior, independent of any single project's config."}),e.jsx(st,{checked:n,onChange:c,disabled:p,label:"Open to Home on launch"})]}),e.jsxs("section",{className:"border border-line rounded-xl bg-bg-hi px-5 py-4",children:[e.jsx("h2",{className:"m-0 mb-1 font-serif text-[18px] font-semibold text-fg",children:"On disk"}),e.jsxs("p",{className:"mt-0 mb-2 text-[13px] text-fg-dim leading-relaxed",children:["Global runtime state is deliberately small — everything project-scoped lives inside that project's ",e.jsx("code",{className:"font-mono text-[12px]",children:"session-manager-operations/"})," folder."]}),e.jsxs("ul",{className:"m-0 pl-0 list-none space-y-1 font-mono text-[12px] text-fg-dim",children:[e.jsxs("li",{children:["~/.claude/session-manager/scheduler-machine.json ",e.jsx("span",{className:"text-fg-faint",children:"— policy + pause state"})]}),e.jsxs("li",{children:["<project>/session-manager-operations/scheduler/state/ ",e.jsx("span",{className:"text-fg-faint",children:"— per-project queue + history"})]}),e.jsxs("li",{children:["<project>/session-manager-operations/scheduler/epics/<epic>/prds/ ",e.jsx("span",{className:"text-fg-faint",children:"— PRD sources, per Epic"})]})]})]})]})}const Ie="sm.schedulerTab.subView",zt=[{key:"queue",label:"Queue"},{key:"prds",label:"PRDs"},{key:"history",label:"History"}];function Qt(t,s){const n=new Date(t),a=new Date(s);return n.getFullYear()===a.getFullYear()&&n.getMonth()===a.getMonth()&&n.getDate()===a.getDate()}function Wt(t,s,n){if(t==="auth")return"Scheduler paused: Claude sign-in expired or invalid. Restart the app or re-run `claude login`, then Resume.";if(t==="rate_limit"){if(s){const p=new Date(s).getTime()-n;return p>0?`Paused for rate limit — resumes in ${q(p)}`:"Paused for rate limit — resume pending"}return"Paused for rate limit"}return t==="network"?"Paused: billing endpoint unreachable for 30+ min.":t==="manual"?"Scheduler paused manually. Click Resume to restart.":`Scheduler paused (${t})`}function Yt({scopeCwd:t}){const{snapshot:s}=we(),[n,a]=r.useState(()=>Date.now());if(r.useEffect(()=>{const f=setInterval(()=>a(Date.now()),3e4);return()=>clearInterval(f)},[]),!s)return null;const p=(s.jobs??[]).filter(f=>!t||f.cwd===t),i=p.filter(f=>f.status==="pending").length,c=p.filter(f=>f.status==="running").length,u=p.filter(f=>f.status==="completed"&&(f.finishedAt?Qt(f.finishedAt,n):!1)).length,o=s.nextReset?new Date(s.nextReset).getTime():null,d=o?o>n?q(o-n):"soon":"—",b=V(s.lastRunAt?new Date(s.lastRunAt).getTime():null,n),w=s.paused,h=s.pollHealth,v=h!=null&&!h.lastPollOk,C=(w==null?void 0:w.reason)==="auth"||(w==null?void 0:w.reason)==="network"?"bg-red-950/60 border-red-700/50 text-red-200":"bg-amber-950/60 border-amber-700/50 text-amber-200";return e.jsxs("div",{className:"flex flex-col gap-2",children:[w&&e.jsxs("div",{className:`flex items-center gap-3 border rounded-xl px-4 py-2.5 text-[13px] ${C}`,children:[e.jsx("span",{className:"flex-1 leading-snug",children:Wt(w.reason,w.resumeAt,n)}),e.jsx("button",{type:"button",onClick:()=>window.api.schedule.resume(),className:"shrink-0 px-2.5 py-1 rounded border border-current/40 hover:bg-white/10 transition-colors text-[12px] font-medium",children:"Resume"})]}),e.jsxs("div",{className:"flex items-center gap-5 flex-wrap bg-bg-hi border border-line rounded-xl px-4 py-3",children:[e.jsxs("span",{className:"inline-flex items-center gap-2 text-[13.5px] text-fg font-semibold whitespace-nowrap",children:[e.jsx("span",{className:"text-sage","aria-hidden":"true",children:e.jsx(ue,{name:"clock",size:15})}),"Window resets in ",d]}),e.jsx("span",{className:"w-px h-[18px] bg-rule shrink-0","aria-hidden":"true"}),e.jsx(he,{dotClass:"bg-fg-faint",n:i,label:"pending"}),e.jsx(he,{dotClass:"bg-accent",n:c,label:"running"}),e.jsx(he,{dotClass:"bg-sage",n:u,label:"completed today"}),s.utilization!==null&&s.utilization!==void 0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"w-px h-[18px] bg-rule shrink-0","aria-hidden":"true"}),v?e.jsxs("span",{className:"font-mono text-[12.5px] text-amber-400/70",title:"Billing poll failing — this reading may be outdated",children:[Math.round(s.utilization),"% of window used · last good reading"," ",V(h.lastPollAt,n)]}):e.jsxs("span",{className:"font-mono text-[12.5px] text-fg-faint",children:[Math.round(s.utilization),"% of window used"]})]}),e.jsxs("span",{className:"ml-auto font-mono text-[12.5px] text-fg-faint whitespace-nowrap",children:["last batch ",b]})]})]})}function Kt({navigate:t}={}){var u;const[s,n]=r.useState(()=>{const o=localStorage.getItem(Ie);return o==="prds"||o==="history"||o==="machine"?o:"queue"}),a=$e(o=>o.tabs),p=$e(o=>o.activeTabId),i=((u=a.find(o=>o.id===p))==null?void 0:u.cwd)??null,c=i;return r.useEffect(()=>{i&&(re.getState().hydrate(i),re.getState().hydrateArchived(i))},[i]),r.useEffect(()=>{localStorage.setItem(Ie,s)},[s]),e.jsxs("div",{className:"h-full flex flex-col",children:[e.jsxs("div",{className:"shrink-0 px-9 pt-7 pb-0",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsx("div",{className:"text-xs font-bold text-fg-faint tracking-[0.8px] uppercase mb-1",children:"Workspace"}),e.jsx(et,{active:"scheduler"})]}),e.jsx("h1",{className:"m-0 font-serif text-[40px] font-semibold leading-none tracking-tight text-fg",children:"Scheduler"}),e.jsxs("p",{className:"mt-2 text-[14.5px] text-fg-dim leading-relaxed max-w-[600px]",children:["Global scheduler policy and the machine-wide session pool, plus — when a project tab is active — that project's PRDs, run as"," ",e.jsx("code",{className:"font-mono text-[13.5px]",children:"claude -p"})," ","jobs against your 5-hour window. Jobs auto-pause on rate-limit and resume on the next reset."]}),e.jsx("div",{className:"mt-[18px] mb-[22px]",children:e.jsx(Yt,{scopeCwd:c})}),e.jsxs("div",{className:"flex items-center gap-3 pb-0",children:[e.jsx(nt,{options:zt,active:s,onChange:n}),e.jsxs("button",{type:"button",onClick:()=>n("machine"),"aria-pressed":s==="machine",className:`inline-flex items-center gap-1.5 px-[15px] py-2 rounded-lg text-[13.5px] transition-colors ${s==="machine"?"bg-bg-elev border border-line font-semibold text-fg":"text-fg-faint hover:text-fg-dim"}`,title:"Machine-wide config that applies to every project — not this project's live queue.",children:[e.jsx("span",{"aria-hidden":"true",children:"⚙"})," Machine"]})]}),s==="queue"&&e.jsx("p",{className:"mt-2 text-[14.5px] text-fg-dim leading-relaxed max-w-[600px]",children:"What's running right now, and what fires next."}),s==="prds"&&e.jsx("p",{className:"mt-2 text-[14.5px] text-fg-dim leading-relaxed max-w-[600px]",children:"Authored PRD source files on disk — edit, lint, archive, or queue them."}),s==="history"&&e.jsx("p",{className:"mt-2 text-[14.5px] text-fg-dim leading-relaxed max-w-[600px]",children:"The last 50 completed and failed jobs, for this project."}),s==="machine"&&e.jsx("p",{className:"mt-2 text-[14.5px] text-fg-dim leading-relaxed max-w-[600px]",children:"Machine-wide setup that applies to every project."})]}),e.jsxs("div",{className:"flex-1 min-h-0",children:[s==="queue"&&e.jsx(pt,{scopeCwd:c,navigate:t}),s==="prds"&&e.jsx(Mt,{scopeCwd:c}),s==="history"&&e.jsx(qt,{scopeCwd:c}),s==="machine"&&e.jsx("div",{className:"h-full overflow-y-auto px-9 py-6",children:e.jsx(Vt,{navigate:t})})]})]})}const ss=r.memo(Kt);export{ss as Scheduler};
@@ -0,0 +1 @@
1
+ import{I as e,z as o,S as x}from"./index-BfPVknuV.js";function f({dirty:i,busy:a,parseError:t,lastSavedAt:c,onSave:s,onRevert:l,leading:n}){const d=i&&!a&&!t;return e.jsxs("div",{className:"px-3 py-1.5 flex items-center gap-2 text-xs",children:[e.jsx("div",{className:"flex-1 min-w-0 truncate text-fg-faint",children:n}),t&&e.jsx("span",{className:"text-red-400 truncate max-w-xs",title:t,children:t}),!i&&!t&&c&&e.jsx("span",{className:"text-fg-faint",children:o(c)}),i&&!t&&e.jsx("span",{className:"text-accent",children:"unsaved"}),e.jsx("button",{onClick:l,disabled:!i||a,className:"px-2 py-0.5 border border-line rounded text-fg-dim hover:text-fg hover:bg-bg-hi disabled:opacity-40 disabled:cursor-not-allowed",children:"Revert"}),e.jsx("button",{onClick:s,disabled:!d,className:`px-2.5 py-0.5 rounded border ${d?"border-accent bg-accent/15 text-accent hover:bg-accent/25":"border-line text-fg-faint opacity-50 cursor-not-allowed"}`,children:a?"Saving…":"Save"})]})}function b({scopes:i,active:a,onChange:t,annotate:c}){return e.jsx("div",{className:"inline-flex rounded border border-line overflow-hidden",children:i.map(s=>{const l=x[s],n=c==null?void 0:c(s),d=s===a;return e.jsxs("button",{title:l.hint,onClick:()=>t(s),className:`px-2.5 py-1 text-xs flex items-center gap-1.5 transition-colors ${d?"bg-bg-hi text-fg":"bg-bg-elev text-fg-dim hover:text-fg hover:bg-bg-hi"}`,children:[e.jsx("span",{children:l.label}),(n==null?void 0:n.dirty)&&e.jsx("span",{className:"w-1 h-1 rounded-full bg-accent",title:"unsaved edits"}),n&&n.exists===!1&&!n.dirty&&e.jsx("span",{className:"w-1 h-1 rounded-full bg-fg-faint",title:"not yet created"})]},s)})})}export{f as S,b as a};
@@ -0,0 +1,3 @@
1
+ import{X as x,I as e,S as k,A as W,c as M,ae as q,R as Z,a9 as X,ah as $,ab as Y,a7 as R,J as Q,V as ee,m as F}from"./index-BfPVknuV.js";import{P as te}from"./Panel-Bap7G-pI.js";import{S as se,a as re}from"./ScopeSwitcher-BlQvpyLE.js";import{u as ae,m as ne,p as le,a as U,E as ie,s as oe}from"./settingsSchema-DKuyaEK5.js";import{T as H}from"./Toggle-Bos67yDJ.js";import"./monaco-editor-BW5C4Iv1.js";const ce=[{id:"essentials",title:"Essentials",summary:"The knobs you reach for first.",keys:["model","language","outputStyle","permissions"]},{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"]},{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"]}],de={mcp:"MCP",url:"URL",urls:"URLs",http:"HTTP",ui:"UI",id:"ID",uuid:"UUID",api:"API",aws:"AWS",otel:"OTel",json:"JSON"};function G(r){return r.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((l,a)=>{const n=de[l];return n||(a===0?l.charAt(0).toUpperCase()+l.slice(1):l)}).join(" ")}function J(r){const s=new Set,t=[];for(const a of ce){const n=a.keys.filter(i=>r.has(i));n.forEach(i=>s.add(i)),n.length!==0&&t.push({id:a.id,title:a.title,summary:a.summary,advanced:!!a.advanced,keys:n})}const l=Array.from(r).filter(a=>!s.has(a)&&a!=="$schema").sort();return l.length>0&&t.push({id:"other",title:"Other",summary:"Keys not yet grouped.",advanced:!1,keys:l}),t}function ue(r,s){return J(r).map(t=>({id:t.id,title:t.title,advanced:t.advanced,total:t.keys.length,setCount:t.keys.filter(l=>s.has(l)).length}))}const xe={};function B(r,s){if(s)return{text:s,authored:!1};const t=xe[r];return t?{text:t,authored:!0}:null}const pe={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"},me=["user","project","local","default"],fe={user:"user",project:"project",local:"local",default:"default"};function ge({node:r,targetScope:s,onOverride:t,schema:l}){const[a,n]=x.useState(""),[i,p]=x.useState(!1),[m,j]=x.useState(!0),u=r.kind==="object"?r:null,S=u?Object.keys(u.children):[],h=l.rootKeys(),N=new Set([...S,...h]),f=x.useMemo(()=>J(N),[Array.from(N).sort().join(",")]),b=x.useMemo(()=>ue(N,new Set(S)),[Array.from(N).sort().join(","),S.join(",")]),[C,E]=x.useState(null),c=x.useRef(null),w=o=>{const g=f.find(v=>v.id===o);g!=null&&g.advanced&&!i&&p(!0),E(o)};x.useEffect(()=>{if(!C)return;E(null);const o=c.current,g=document.getElementById(`settings-group-${C}`);if(!o||!g)return;const v=g.getBoundingClientRect().top-o.getBoundingClientRect().top;o.scrollBy({top:v,behavior:"smooth"})},[C]);const y=x.useMemo(()=>f.filter(o=>i||!o.advanced).map(o=>({...o,keys:o.keys.filter(g=>{const v=(u==null?void 0:u.children[g])!==void 0;if(!m&&!v)return!1;if(!a.trim())return!0;const T=l.at([g]);return[g,G(g),(T==null?void 0:T.description)??""].join(" ").toLowerCase().includes(a.toLowerCase())})})).filter(o=>o.keys.length>0),[f,a,i,m,u,l]);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:k[s].label})]}),e.jsxs("label",{className:"flex items-center gap-1 text-fg-faint cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:m,onChange:o=>j(o.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:i,onChange:o=>p(o.target.checked),className:"accent-accent"}),"show advanced"]}),e.jsx("div",{className:"flex-1"}),e.jsx("input",{value:a,onChange:o=>n(o.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(he,{groups:b,onJump:w}),e.jsxs("div",{ref:c,className:"flex-1 overflow-auto py-3",children:[y.map(o=>e.jsx(be,{id:o.id,title:o.title,summary:o.summary,advanced:o.advanced,children:o.keys.map(g=>{const v=u==null?void 0:u.children[g],T=l.at([g]);return e.jsx(ve,{keyName:g,node:v,info:T,targetScope:s,onOverride:(d,A)=>t([g],d,A)},g)})},o.id)),y.length===0&&e.jsxs("div",{className:"px-6 py-12 text-center text-fg-faint text-sm",children:['no settings match "',a,'"']})]})]})]})}function he({groups:r,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:r.map(t=>e.jsxs("button",{onClick:()=>s(t.id),className:"w-full flex items-center gap-2 px-3 py-2 text-left hover:bg-bg-hi transition-colors",title:`jump to ${t.title}`,children:[e.jsx(W,{name:pe[t.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:t.title}),e.jsxs("span",{className:"text-[10px] text-fg-faint font-mono shrink-0",children:[t.setCount,"/",t.total]})]},t.id))})}function be({id:r,title:s,summary:t,advanced:l,children:a}){const[n,i]=x.useState(!0);return e.jsxs("section",{id:`settings-group-${r}`,className:"mx-4 mb-4 rounded-lg border border-line shadow-sm bg-bg-elev/50 overflow-hidden",children:[e.jsxs("header",{className:"px-4 py-3 bg-bg-elev cursor-pointer hover:bg-bg-hi flex items-center gap-3 border-b border-line",onClick:()=>i(!n),children:[e.jsx("span",{className:"text-fg-faint w-3",children:n?"▾":"▸"}),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}),l&&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:t})]})]}),n&&e.jsx("div",{className:"divide-y divide-line/60",children:a})]})}function ve({keyName:r,node:s,info:t,targetScope:l,onOverride:a}){const[n,i]=x.useState(!1),[p,m]=x.useState(!1),j=G(r),u=s!==void 0,h=(s==null?void 0:s.kind)==="leaf"?s:null,N=(s==null?void 0:s.kind)==="object"||(s==null?void 0:s.kind)==="array",f=t==null?void 0:t.default,b=h&&f!==void 0&&V(h.value,f),C=Ee({isSet:u,leafNode:h,defaultVal:f,isDefault:!!b,node:s}),E=ye(h,f),c=E.length>=2,w=!!h&&!b,y=B(r,t==null?void 0:t.description);return e.jsx("div",{className:"px-4 py-3 hover:bg-bg-elev/20",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("button",{onClick:()=>i(!n),className:"text-fg-faint hover:text-fg w-3 mt-0.5",title:n?"collapse":"expand",children:n?"▾":"▸"}),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:j}),e.jsx(Te,{kind:C.kind,label:C.label}),c&&e.jsxs("button",{onClick:o=>{o.stopPropagation(),n||i(!0),m(g=>!g)},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 · ",E.map(o=>fe[o]).join(" · ")]}),w&&h&&e.jsx("button",{onClick:o=>{o.stopPropagation(),a(void 0,h.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 ${k[h.winner].label}`,children:"↺ reset"}),(t==null?void 0:t.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"}),(t==null?void 0:t.required)&&!u&&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"})]}),y&&e.jsx("p",{className:`text-fg-dim text-xs mt-0.5 leading-relaxed ${y.authored?"inline-block border-b border-dotted border-fg-faint/70 cursor-help":""}`,title:y.authored?"In-app-authored description — not from the official Claude Code schema":void 0,children:Oe(y.text)}),n&&p&&h&&e.jsx(je,{leaf:h,defaultVal:f,onReset:o=>a(void 0,o)}),n&&e.jsx(Ne,{keyName:r,node:s,info:t,targetScope:l,onOverride:o=>a(o)})]}),e.jsx("div",{className:"shrink-0",children:!n&&e.jsx(Ce,{node:s,info:t,onSet:o=>{a(o)},disabled:N&&u})})]})})}function ye(r,s){if(!r)return[];const t=new Set;t.add(r.winner);for(const l of r.shadowed)t.add(l.scope);return s!==void 0&&t.add("default"),me.filter(l=>t.has(l))}function je({leaf:r,defaultVal:s,onReset:t}){const l={};l[r.winner]={value:r.value,winner:!0};for(const a of r.shadowed)l[a.scope]={value:a.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(a=>{const n=l[a],i=n!==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:k[a].label}),e.jsx("span",{className:`font-mono truncate ${n!=null&&n.winner?"text-accent":"text-fg-dim"}`,children:i?P(n.value):e.jsx("span",{className:"text-fg-faint",children:"—"})}),i?e.jsx("button",{onClick:()=>t(a),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 ${k[a].label}`,children:"↺"}):e.jsx("span",{})]},a)}),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?P(s):e.jsx("span",{className:"text-fg-faint",children:"—"})}),e.jsx("span",{})]})]})]})}function Ne({keyName:r,node:s,info:t,targetScope:l,onOverride:a}){const i=(s==null?void 0:s.kind)==="leaf"?s:null,p=B(r,t==null?void 0:t.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:[(t==null?void 0:t.type)&&e.jsxs(e.Fragment,{children:[e.jsx("dt",{children:"Type"}),e.jsx("dd",{className:"text-fg-dim font-mono",children:Array.isArray(t.type)?t.type.join(" | "):t.type})]}),(t==null?void 0:t.default)!==void 0&&e.jsxs(e.Fragment,{children:[e.jsx("dt",{children:"Default"}),e.jsx("dd",{className:"text-fg-dim font-mono",children:P(t.default)})]}),(t==null?void 0:t.enum)&&e.jsxs(e.Fragment,{children:[e.jsx("dt",{children:"Options"}),e.jsx("dd",{className:"text-fg-dim font-mono",children:t.enum.map(m=>String(m)).join(" | ")})]}),i&&e.jsxs(e.Fragment,{children:[e.jsx("dt",{children:"Current"}),e.jsxs("dd",{className:"font-mono",children:[e.jsx("span",{className:"text-fg-dim",children:P(i.value)}),e.jsxs("span",{className:"ml-2 text-fg-faint",children:["from ",k[i.winner].label]})]})]}),i&&i.shadowed.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("dt",{children:"Shadowed"}),e.jsx("dd",{className:"space-y-0.5",children:i.shadowed.map((m,j)=>e.jsxs("div",{className:"font-mono text-fg-faint line-through",children:[P(m.value)," —"," ",e.jsx("span",{className:"no-underline",children:k[m.scope].label})]},j))})]}),(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(we,{keyName:r,node:s,info:t,onChange:a,targetScope:l})})]})}function we({node:r,info:s,onChange:t,targetScope:l}){const n=(r==null?void 0:r.kind)==="leaf"?r.value:s==null?void 0:s.default,i=K(s==null?void 0:s.type);if(i==="boolean"){const p=n===!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:m,label:j})=>e.jsx("button",{onClick:()=>t(m),className:`px-3 py-0.5 text-xs transition-colors ${p===m?"bg-accent text-bg":"bg-bg-elev text-fg-dim hover:bg-bg-hi hover:text-fg"}`,children:j},j))}),e.jsxs("span",{className:"text-fg-faint",children:["→ ",k[l].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 m=V(n,p);return e.jsx("button",{onClick:()=>t(p),className:`px-2 py-0.5 text-xs rounded border ${m?"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:["→ ",k[l].label]})]}):i==="integer"||i==="number"?e.jsx(Se,{value:typeof n=="number"?n:void 0,integer:i==="integer",onCommit:t,target:k[l].label}):i==="string"?e.jsx(ke,{value:typeof n=="string"?n:"",onCommit:t,target:k[l].label}):e.jsxs("div",{className:"text-fg-faint",children:["Complex value (",i??"object/array",") — use the"," ",e.jsx("span",{className:"text-fg-dim",children:"Raw"})," tab to edit."]})}function Se({value:r,integer:s,onCommit:t,target:l}){const[a,n]=x.useState(r!==void 0?String(r):""),i=()=>{const p=s?parseInt(a,10):parseFloat(a);Number.isNaN(p)||t(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:a,onChange:p=>n(p.target.value),onBlur:i,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:i,className:"px-2 py-0.5 text-xs border border-accent/50 rounded text-accent hover:bg-accent hover:text-bg",children:["save → ",l]})]})}function ke({value:r,onCommit:s,target:t}){const[l,a]=x.useState(r);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:l,onChange:n=>a(n.target.value),onKeyDown:n=>{n.key==="Enter"&&s(l)},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(l),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 → ",t]})]})}function Ce({node:r,info:s,onSet:t,disabled:l}){const a=(r==null?void 0:r.kind)==="leaf",n=K(s==null?void 0:s.type);if(l)return null;if(n==="boolean"){const i=a&&r.value===!0;return e.jsx("button",{onClick:()=>t(!i),className:`px-2.5 py-0.5 text-xs rounded border transition-colors ${i?"bg-accent/15 text-accent border-accent/40 hover:bg-accent hover:text-bg":"bg-bg-elev text-fg-dim border-line hover:text-fg hover:bg-bg-hi"}`,title:"toggle",children:i?"on":"off"})}return null}function Ee({isSet:r,leafNode:s,defaultVal:t,isDefault:l,node:a}){return r?(a==null?void 0:a.kind)==="array"?{kind:"accumulated",label:`${a.items.length} items`}:(a==null?void 0:a.kind)==="object"?{kind:"set",label:"configured"}:s?l?{kind:"default",label:`= default · ${k[s.winner].label}`}:s.shadowed.length>0?{kind:"override",label:`overriding ${s.shadowed.length} scope(s)`}:{kind:"set",label:`set in ${k[s.winner].label}`}:{kind:"set",label:"configured"}:t!==void 0?{kind:"default",label:`using default: ${P(t)}`}:{kind:"unset",label:"not configured"}}function Te({kind:r,label:s}){const t={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"}[r];return e.jsx("span",{className:`text-[9px] px-1.5 py-0 rounded border uppercase tracking-wide ${t}`,children:s})}function K(r){if(r)return Array.isArray(r)?r.find(t=>t!=="null")??r[0]:r}function V(r,s){return r===s?!0:typeof r!=typeof s?!1:r&&s&&typeof r=="object"?JSON.stringify(r)===JSON.stringify(s):!1}function Oe(r){const s=r.trim().split(`
2
+ `)[0],t=s.match(/^([^.!?]+[.!?])/);return t?t[1]:s.length>120?s.slice(0,120)+"…":s}function P(r){if(typeof r=="string")return r===""?'""':JSON.stringify(r);if(r===null)return"null";if(r===void 0)return"—";if(typeof r=="object"){const s=JSON.stringify(r);return s.length>60?s.slice(0,60)+"…":s}return String(r)}function Ae(){const[r,s]=x.useState(null),[t,l]=x.useState(null),[a,n]=x.useState(null),[i,p]=x.useState(null),[m,j]=x.useState(!1),[u,S]=x.useState(null),[h,N]=x.useState(null);if(x.useEffect(()=>{let c=!1;return Promise.all([window.api.otel.getConfig(),window.api.otel.status(),window.api.otel.configPath()]).then(([w,y,o])=>{c||(s(w),n(w),l(y),p(o))}).catch(w=>{console.warn("[telemetry] load failed:",w==null?void 0:w.message)}),()=>{c=!0}},[]),!a||!r)return e.jsx(M,{title:"loading…"});const f=JSON.stringify(a)!==JSON.stringify(r),b=(c,w)=>{S(null),n({...a,[c]:w})},C=async()=>{j(!0),S(null);try{const c=await window.api.otel.setConfig(a);!c.ok&&c.error&&S(c.error),s(c.config),n(c.config),l(c.status),N(Date.now())}catch(c){S(c instanceof Error?c.message:String(c))}finally{j(!1)}},E=()=>{S(null),n(r)};return e.jsxs("div",{className:"p-4 max-w-3xl space-y-5 text-sm",children:[e.jsxs("header",{className:"space-y-1",children:[e.jsx("h2",{className:"text-fg text-base font-medium",children:"Telemetry — OpenTelemetry export"}),e.jsx("p",{className:"text-fg-dim text-xs leading-relaxed",children:"When enabled, every classified transcript event (tool_use, todo_write, plan, usage, agent_spawn) is mirrored as a 0-duration OTLP/HTTP span. Point this at a local collector (Jaeger, Grafana Tempo, SigNoz, Honeycomb) for cross-session analysis."}),i&&e.jsxs("p",{className:"text-fg-faint text-[11px]",children:["stored at ",e.jsx("span",{className:"font-mono",children:i})]})]}),e.jsxs("section",{className:"border border-line rounded p-3 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-fg",children:"Export transcripts to OTEL"}),e.jsx("div",{className:"text-fg-faint text-xs",children:"Toggle off to disable all span emission immediately."})]}),e.jsx(H,{checked:a.enabled,onChange:c=>b("enabled",c),label:a.enabled?"on":"off"})]}),e.jsxs("label",{className:"block space-y-1",children:[e.jsx("span",{className:"text-fg-dim text-xs",children:"OTLP/HTTP traces endpoint"}),e.jsx("input",{type:"text",value:a.endpoint,onChange:c=>b("endpoint",c.target.value),placeholder:"http://localhost:4318/v1/traces",className:"w-full bg-bg border border-line rounded px-2 py-1 text-fg font-mono text-xs"})]}),e.jsxs("label",{className:"block space-y-1",children:[e.jsxs("span",{className:"text-fg-dim text-xs",children:["Headers (newline-separated ",e.jsx("span",{className:"font-mono",children:"Key: Value"}),")"]}),e.jsx("textarea",{value:a.headers,onChange:c=>b("headers",c.target.value),placeholder:"x-honeycomb-team: YOUR_API_KEY",rows:3,className:"w-full bg-bg border border-line rounded px-2 py-1 text-fg font-mono text-xs"})]}),e.jsxs("label",{className:"block space-y-1",children:[e.jsx("span",{className:"text-fg-dim text-xs",children:"Service name"}),e.jsx("input",{type:"text",value:a.serviceName,onChange:c=>b("serviceName",c.target.value),placeholder:"session-manager",className:"w-full bg-bg border border-line rounded px-2 py-1 text-fg font-mono text-xs"})]}),e.jsxs("div",{className:"flex items-start justify-between gap-3 pt-1",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-fg",children:"Include content (PII)"}),e.jsxs("div",{className:"text-fg-faint text-xs leading-relaxed",children:["Adds tool inputs, plan text, and agent prompts to span attributes. Off by default — matches upstream Claude Code's ",e.jsx("span",{className:"font-mono",children:"OTEL_LOG_USER_PROMPTS"})," opt-in."]})]}),e.jsx(H,{checked:a.includeContent,onChange:c=>b("includeContent",c),label:a.includeContent?"on":"off"})]})]}),t&&e.jsxs("section",{className:"border border-line rounded p-3 text-xs space-y-1",children:[e.jsx("div",{className:"text-fg-dim",children:"Runtime status"}),e.jsxs("div",{children:[e.jsx("span",{className:"text-fg-faint",children:"enabled:"})," ",e.jsx("span",{className:t.enabled?"text-accent":"text-fg-dim",children:String(t.enabled)})]}),t.error&&e.jsxs("div",{className:"text-red-400 break-words",children:[e.jsx("span",{className:"text-fg-faint",children:"error:"})," ",t.error]}),!t.error&&t.enabled&&e.jsx("div",{className:"text-fg-faint",children:"spans batched and exported in the background. Verify by enabling and pointing at a local Jaeger."})]}),e.jsxs("footer",{className:"flex items-center gap-3 pt-2 border-t border-line",children:[e.jsx("button",{onClick:C,disabled:!f||m,className:"px-3 py-1 text-xs rounded bg-accent text-bg disabled:opacity-50 disabled:cursor-not-allowed",children:m?"saving…":"Save"}),e.jsx("button",{onClick:E,disabled:!f||m,className:"px-3 py-1 text-xs rounded border border-line text-fg-dim hover:text-fg disabled:opacity-50 disabled:cursor-not-allowed",children:"Revert"}),u&&e.jsx("span",{className:"text-red-400 text-xs",children:u}),!u&&h&&!f&&e.jsx("span",{className:"text-fg-faint text-xs",children:"saved"})]})]})}function Pe(){const{model:r,setModel:s}=q();return e.jsxs("div",{className:"p-4 max-w-3xl space-y-5 text-sm",children:[e.jsxs("header",{className:"space-y-1",children:[e.jsx("h2",{className:"text-fg text-base font-medium",children:"Session Manager preferences"}),e.jsx("p",{className:"text-fg-dim text-xs leading-relaxed",children:"Native app preferences, stored locally — not part of Claude Code's own settings."})]}),e.jsx("section",{className:"border border-line rounded p-3 space-y-3",children:e.jsxs("label",{className:"block space-y-1",children:[e.jsx("span",{className:"text-fg-dim text-xs",children:"Default model for raw sessions"}),e.jsx("select",{value:r,onChange:t=>s(t.target.value),className:"w-full bg-bg border border-line rounded px-2 py-1 text-fg font-mono text-xs",children:Z.map(t=>e.jsx("option",{value:t,children:t.charAt(0).toUpperCase()+t.slice(1)},t))}),e.jsx("span",{className:"text-fg-faint text-[11px]",children:"Used when opening a raw interactive session without an explicit per-launch override."})]})})]})}function Re(){const r=X(),s=$(d=>d.tabs),t=$(d=>d.activeTabId),l=s.find(d=>d.id===t)??null,a=(l==null?void 0:l.cwd)??null,n=Y(d=>d.navFace),i=x.useRef(!1),p=x.useRef(n),[m,j]=x.useState(()=>n==="project"&&a?"project":"user"),[u,S]=x.useState("effective");x.useEffect(()=>{if(p.current!==n){if(p.current=n,i.current){i.current=!1;return}j(n==="project"&&a?"project":"user")}},[n,a]),x.useEffect(()=>{n==="project"&&(u==="telemetry"||u==="app")&&S("effective")},[n,u]);const h=d=>{i.current=!0,j(d)},N=ae(F,r,a),f=N[m]??null,b=R(d=>d.files),C=R(d=>d.setDraft),E=R(d=>d.saveJson),c=R(d=>d.revert),[w,y]=x.useState(null),o=x.useMemo(()=>ne(le(b,N)),[b,N]),g=(d,A,O)=>{var _;const I=N[O??m];if(!I)return;y(null);const D=((_=b[I])==null?void 0:_.draftRaw)??"";let L={};if(D.trim())try{L=JSON.parse(D)}catch{L={}}const z=oe(L,d,A);C(I,JSON.stringify(z,null,2)+`
3
+ `)};if(!r)return e.jsx(M,{title:"loading…"});const v=f?b[f]:null,T=d=>d!=="user"&&!a;return e.jsx(te,{toolbar:e.jsxs(e.Fragment,{children:[e.jsx(ee,{options:[{key:"effective",label:"Guided"},{key:"tree",label:"Tree"},{key:"raw",label:"Raw"},...n==="home"?[{key:"telemetry",label:"Telemetry"},{key:"app",label:"Session Manager"}]:[]],active:u,onChange:S}),u!=="telemetry"&&u!=="app"&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"mx-2 text-fg-faint",children:"·"}),e.jsx(re,{scopes:F.scopes,active:m,onChange:h,annotate:d=>{if(T(d))return{exists:!1};const A=N[d];if(!A)return null;const O=b[A];return{exists:(O==null?void 0:O.exists)??!1,dirty:(O==null?void 0:O.dirty)??!1}}}),e.jsx("span",{className:"ml-3 text-fg-faint truncate",children:u==="effective"?`overrides → ${f??"—"}`:f??"—"})]}),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:u!=="telemetry"&&u!=="app"&&f&&v?e.jsx(se,{dirty:v.dirty,busy:v.busy,parseError:w||v.parseError,lastSavedAt:v.lastSavedAt,leading:v.exists?null:e.jsx("span",{children:"file will be created on save"}),onSave:async()=>{y(null);const d=await E(f);d.ok||y(d.error??"save failed")},onRevert:()=>{y(null),c(f)}}):null,children:u==="telemetry"?e.jsx(Ae,{}):u==="app"?e.jsx(Pe,{}):T(m)?e.jsx(M,{title:"no active project",hint:"open a tab in a project directory to edit project or local settings"}):u==="effective"?e.jsx(ge,{node:o,targetScope:m,onOverride:g,schema:U()}):u==="tree"?e.jsx(ie,{node:o,targetScope:m,onOverride:g,schema:U()}):f&&v?e.jsx(Q,{path:f,value:v.draftRaw,onChange:d=>{y(null),C(f,d)}}):e.jsx(M,{title:"resolving…"})})}const Ue=x.memo(Re);export{Ue as Settings};