claude-code-session-manager 0.73.2 → 0.74.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 (49) hide show
  1. package/dist/assets/AgentLibrary-CSnWV6uv.js +3 -0
  2. package/dist/assets/{History-Dnx86P4n.js → History-ShwkUTny.js} +1 -1
  3. package/dist/assets/{Hooks-CAYlpqBp.js → Hooks-Dc5y1rZH.js} +1 -1
  4. package/dist/assets/{HostBilko-CXykS2ap.js → HostBilko-evd1hD8q.js} +1 -1
  5. package/dist/assets/{Library-DVbXlboP.js → Library-BOL6GqFX.js} +1 -1
  6. package/dist/assets/{ListDetail-DXd5rB2F.js → ListDetail-BPJb2et3.js} +1 -1
  7. package/dist/assets/{MarkdownEditor-D0mO1TUZ.js → MarkdownEditor-CACsHVuf.js} +1 -1
  8. package/dist/assets/{McpServers-BxUk1aR3.js → McpServers-DuOTxmc4.js} +1 -1
  9. package/dist/assets/{Memory-DVbPQFZw.js → Memory-BYJHDz7W.js} +1 -1
  10. package/dist/assets/{Panel-DigZB9Yd.js → Panel-n-p8OQLc.js} +1 -1
  11. package/dist/assets/{Permissions-CSLxAoTL.js → Permissions-DhYERDVR.js} +1 -1
  12. package/dist/assets/{Plugins-DOTiP9sQ.js → Plugins-D1ckVgo3.js} +2 -2
  13. package/dist/assets/{ProvenanceBadge-PsNd-CBq.js → ProvenanceBadge-ByTjDwAX.js} +1 -1
  14. package/dist/assets/{SaveBar-C4bgDklX.js → SaveBar-_ORUCmZw.js} +1 -1
  15. package/dist/assets/{Scheduler-CrBVVXN1.js → Scheduler-Bu6kSkl3.js} +7 -7
  16. package/dist/assets/{ScopeSwitcher-RMAwgmj4.js → ScopeSwitcher-Css6Sg7Y.js} +1 -1
  17. package/dist/assets/{Settings-CM4lZxnn.js → Settings-DlyJjexf.js} +1 -1
  18. package/dist/assets/{SkillReferenceGraph-B1DaeT2R.js → SkillReferenceGraph-rKaTHmOg.js} +1 -1
  19. package/dist/assets/{Skills-CSdxEC-f.js → Skills-BHlH2uG5.js} +1 -1
  20. package/dist/assets/{SystemPrompt-j-WYOC5f.js → SystemPrompt-DsgF8xsl.js} +1 -1
  21. package/dist/assets/TagLibrary-Q5QsKMes.js +1 -0
  22. package/dist/assets/{TiptapBody-4hzD0jjv.js → TiptapBody-XoQHiqfF.js} +1 -1
  23. package/dist/assets/{Toggle-H6pNcv3l.js → Toggle-BJHhHQOq.js} +1 -1
  24. package/dist/assets/{index-DJ6xdB0r.js → index-Cs_Lq9-w.js} +3 -3
  25. package/dist/assets/{settingsSchema-DVblsXFp.js → settingsSchema-BTDJcu2x.js} +1 -1
  26. package/dist/index.html +1 -1
  27. package/package.json +1 -1
  28. package/plugins/session-manager-dev/skills/memory-sanitation/SKILL.md +21 -1
  29. package/src/main/__tests__/agentModelResolve.test.cjs +19 -0
  30. package/src/main/__tests__/crossProjectFeedback.test.cjs +7 -0
  31. package/src/main/__tests__/crossProjectFeedbackRoutes.test.cjs +7 -0
  32. package/src/main/__tests__/epicMint.test.cjs +50 -2
  33. package/src/main/__tests__/health-claude-md-budget.test.cjs +57 -0
  34. package/src/main/__tests__/prdCreate.test.cjs +17 -0
  35. package/src/main/__tests__/promptSessionsCreateEpicHandler.test.cjs +7 -0
  36. package/src/main/__tests__/workTypeLibrary.test.cjs +89 -0
  37. package/src/main/health.cjs +51 -1
  38. package/src/main/index.cjs +2 -2
  39. package/src/main/ipcSchemas.cjs +21 -9
  40. package/src/main/lib/__tests__/agentPersonaSchema.test.cjs +67 -0
  41. package/src/main/lib/agentModelResolve.cjs +32 -1
  42. package/src/main/lib/agentPersonaSchema.cjs +82 -0
  43. package/src/main/lib/epicMint.cjs +74 -1
  44. package/src/main/lib/prdFrontmatter.cjs +6 -5
  45. package/src/main/lib/promptSessionSchema.cjs +6 -14
  46. package/src/main/lib/workTypeLibrary.cjs +48 -0
  47. package/src/preload/api.d.ts +7 -2
  48. package/dist/assets/AgentLibrary-D0frFrHG.js +0 -3
  49. package/dist/assets/TagLibrary-Fj0zrPru.js +0 -1
@@ -1,2 +1,2 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./SkillReferenceGraph-B1DaeT2R.js","./index-DJ6xdB0r.js","./monaco-editor-BW5C4Iv1.js","./monaco-editor-BTnBOi8r.css","./index-D9C8N3pn.css"])))=>i.map(i=>d[i]);
2
- import{_ as e,a5 as h,g as j,ak as U,ae as T,b as X}from"./index-DJ6xdB0r.js";import{P as R}from"./Panel-DigZB9Yd.js";import{P as K}from"./ProvenanceBadge-PsNd-CBq.js";import{e as Y}from"./Library-DVbXlboP.js";import{p as W}from"./skillFrontmatter-Dif5JIg7.js";import{_ as Z}from"./monaco-editor-BW5C4Iv1.js";import{L as ee}from"./ListDetail-DXd5rB2F.js";import{M as te}from"./MarkdownEditor-D0mO1TUZ.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-B1DaeT2R.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=U(),[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,q]=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}`))),_=[];J.forEach((k,D)=>{const C=Q[D];if(!C.exists)return;const A=W(C.text);_.push({id:k,name:A.name??k.replace(/\.md$/,""),description:A.description})});const F=[];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;F.push({id:D,name:D,description:typeof A=="string"?A:null})}}if(p)return;o(H),i(_),c(F),x(q),u(H.length>0?"skills":_.length>0?"agents":F.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(X,{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};
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./SkillReferenceGraph-rKaTHmOg.js","./index-Cs_Lq9-w.js","./monaco-editor-BW5C4Iv1.js","./monaco-editor-BTnBOi8r.css","./index-D9C8N3pn.css"])))=>i.map(i=>d[i]);
2
+ import{_ as e,a5 as h,g as j,ak as U,ae as T,b as X}from"./index-Cs_Lq9-w.js";import{P as R}from"./Panel-n-p8OQLc.js";import{P as K}from"./ProvenanceBadge-ByTjDwAX.js";import{e as Y}from"./Library-BOL6GqFX.js";import{p as W}from"./skillFrontmatter-Dif5JIg7.js";import{_ as Z}from"./monaco-editor-BW5C4Iv1.js";import{L as ee}from"./ListDetail-BPJb2et3.js";import{M as te}from"./MarkdownEditor-CACsHVuf.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-rKaTHmOg.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=U(),[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,q]=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}`))),_=[];J.forEach((k,D)=>{const C=Q[D];if(!C.exists)return;const A=W(C.text);_.push({id:k,name:A.name??k.replace(/\.md$/,""),description:A.description})});const F=[];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;F.push({id:D,name:D,description:typeof A=="string"?A:null})}}if(p)return;o(H),i(_),c(F),x(q),u(H.length>0?"skills":_.length>0?"agents":F.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(X,{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};
@@ -1 +1 @@
1
- import{x as P,ak as G,a5 as x,_ as i,Z as _,B as R,b as T}from"./index-DJ6xdB0r.js";import{a as E,C as B,c as L,d as S,b as I}from"./Library-DVbXlboP.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 I){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(B.flatMap(e=>[a(e.id),a(e.name)])),Z=new Set(E.flatMap(e=>[a(e.id),a(e.name)])),q=new Set(E.map(e=>e.command.trim())),F=new Set(["security-review","pr-comments","release-notes","add-dir","code-review","simplify"]),Q=/(@anthropic-ai\/|anthropic\.com|github\.com\/anthropics)/i,W=/(^|\s)(npx|uvx|pipx|bunx|mcp-remote|deno\s+run|docker\s+run)(\s|$)/i;function X(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 Z.has(t)||n&&q.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":W.test(t)?"installed from a package registry":null}function te(e){const t=a(e.name),n=X(e),o=Y(e.type,t,e.command);if(o)return o;if((e.type==="command"||e.type==="skill")&&F.has(t))return l("built-in Claude Code command");if(Q.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(),[b,m]=x.useState(!1),v=x.useRef(null);x.useEffect(()=>{r&&h(r)},[r,h]),x.useEffect(()=>{if(!b)return;const s=C=>{v.current&&!v.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)}},[b]);const w=ne(e.type,t??null,e.name),f=te(e),p=d[w],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(T,{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:v,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}),b&&i.jsxs("span",{className:`absolute ${_.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(w,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 ${R[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(w,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};
1
+ import{x as P,ak as G,a5 as x,_ as i,Z as _,B as R,b as T}from"./index-Cs_Lq9-w.js";import{a as E,C as B,c as L,d as S,b as I}from"./Library-BOL6GqFX.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 I){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(B.flatMap(e=>[a(e.id),a(e.name)])),Z=new Set(E.flatMap(e=>[a(e.id),a(e.name)])),q=new Set(E.map(e=>e.command.trim())),F=new Set(["security-review","pr-comments","release-notes","add-dir","code-review","simplify"]),Q=/(@anthropic-ai\/|anthropic\.com|github\.com\/anthropics)/i,W=/(^|\s)(npx|uvx|pipx|bunx|mcp-remote|deno\s+run|docker\s+run)(\s|$)/i;function X(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 Z.has(t)||n&&q.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":W.test(t)?"installed from a package registry":null}function te(e){const t=a(e.name),n=X(e),o=Y(e.type,t,e.command);if(o)return o;if((e.type==="command"||e.type==="skill")&&F.has(t))return l("built-in Claude Code command");if(Q.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(),[b,m]=x.useState(!1),v=x.useRef(null);x.useEffect(()=>{r&&h(r)},[r,h]),x.useEffect(()=>{if(!b)return;const s=C=>{v.current&&!v.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)}},[b]);const w=ne(e.type,t??null,e.name),f=te(e),p=d[w],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(T,{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:v,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}),b&&i.jsxs("span",{className:`absolute ${_.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(w,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 ${R[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(w,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};
@@ -1 +1 @@
1
- import{_ as e,Q as x}from"./index-DJ6xdB0r.js";function m({dirty:a,busy:n,parseError:t,lastSavedAt:c,onSave:i,onRevert:l,leading:d}){const s=a&&!n&&!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:d}),t&&e.jsx("span",{className:"text-red-400 truncate max-w-xs",title:t,children:t}),!a&&!t&&c&&e.jsx("span",{className:"text-fg-faint",children:x(c)}),a&&!t&&e.jsx("span",{className:"text-accent",children:"unsaved"}),e.jsx("button",{onClick:l,disabled:!a||n,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:i,disabled:!s,className:`px-2.5 py-0.5 rounded border ${s?"border-accent bg-accent/15 text-accent hover:bg-accent/25":"border-line text-fg-faint opacity-50 cursor-not-allowed"}`,children:n?"Saving…":"Save"})]})}export{m as S};
1
+ import{_ as e,Q as x}from"./index-Cs_Lq9-w.js";function m({dirty:a,busy:n,parseError:t,lastSavedAt:c,onSave:i,onRevert:l,leading:d}){const s=a&&!n&&!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:d}),t&&e.jsx("span",{className:"text-red-400 truncate max-w-xs",title:t,children:t}),!a&&!t&&c&&e.jsx("span",{className:"text-fg-faint",children:x(c)}),a&&!t&&e.jsx("span",{className:"text-accent",children:"unsaved"}),e.jsx("button",{onClick:l,disabled:!a||n,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:i,disabled:!s,className:`px-2.5 py-0.5 rounded border ${s?"border-accent bg-accent/15 text-accent hover:bg-accent/25":"border-line text-fg-faint opacity-50 cursor-not-allowed"}`,children:n?"Saving…":"Save"})]})}export{m as S};
@@ -1,14 +1,14 @@
1
- import{_ as e,aq as we,a5 as l,an as Te,a as ue,G as z,ae as L,O as B,U as re,I as V,a4 as be,ao as le,a8 as ve,a9 as je,K as ke,at as ce,s as Le,a0 as Y,l as Me,h as Ne,n as ye,D as q,d as R,q as Oe,a1 as Pe,ai as Ce,g as ae,m as Ae,f as Ue,ac as Ve,t as ze,k as Fe,ak as Qe,ah as se,r as We,C as Ye,ar as Ke,a6 as Xe,au as Ze,as as De,L as et,i as he}from"./index-DJ6xdB0r.js";import{l as tt}from"./listSkills-QORduPIk.js";import{T as st}from"./Toggle-H6pNcv3l.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:d})=>{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:d},a)})})}const at=5e3;let oe=null,ne=null;async function $e(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)}function _e({options:t,value:s,onChange:n,pillPadding:a="px-3 py-1.5"}){return e.jsx("div",{className:"flex gap-1.5 flex-wrap",children:t.map(d=>{const i=d.value===s;return e.jsxs("button",{type:"button",onClick:()=>n(d.value),className:`rounded-full ${a} text-[12.5px] border transition-colors ${i?"bg-accent text-white border-accent font-semibold":"bg-bg-hi text-fg-dim border-line hover:border-fg-faint font-medium"}`,children:[d.label,d.count!==void 0&&e.jsxs("span",{children:[" ",d.count]})]},d.value)})})}const rt=5,lt=1440*60*1e3,He="sm.scheduler.hiddenCompletedSlugs",de="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","quarantined"];function dt(){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 ct(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 d=be(a.cwd)??"";return a.title.toLowerCase().includes(n)||a.slug.toLowerCase().includes(n)||d.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(p=>p.snapshot),a=l.useMemo(()=>!n||!t?n:{...n,jobs:n.jobs.filter(p=>p.cwd===t)},[n,t]),[d,i]=l.useState(null),[c,x]=l.useState(!1),[o,u]=l.useState(()=>Date.now()),[b,w]=l.useState(()=>xt()),[h,v]=l.useState(!1),[N,C]=l.useState(()=>dt()),[f,j]=l.useState(!1),[D,k]=l.useState("queue"),g=l.useRef(null),[A,P]=l.useState(()=>{try{return Number(localStorage.getItem(de))||0}catch{return 0}}),[J,xe]=l.useState(""),G=Te();l.useEffect(()=>(window.api.schedule.health().then(i).catch(()=>{}),window.api.schedule.onState(()=>{window.api.schedule.health().then(i).catch(()=>{})})),[]),l.useEffect(()=>{if(!G)return;u(Date.now());const p=setInterval(()=>u(Date.now()),1e3);return()=>clearInterval(p)},[G]);const M=l.useMemo(()=>{if(!a)return 15e4;const p=[];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&&p.push(T)}return p.length===0?15e4:p.reduce((y,T)=>y+T,0)/p.length},[a]),K=l.useRef(new Map);l.useEffect(()=>{if(!a)return;const p=[];for(const y of a.jobs){const T=K.current.get(y.slug);T&&T!==y.status&&p.push(`${y.title}: ${T} → ${y.status}`),K.current.set(y.slug,y.status)}p.length>0&&xe(p.join("; "))},[a]);const X=l.useMemo(()=>{var y;const p=new Map;for(const T of((y=a==null?void 0:a.lastTick)==null?void 0:y.holds)??[])p.set(T.slug,T);return p},[a==null?void 0:a.lastTick]),Z=l.useCallback(p=>{var T,ie,Se;const y=(T=g.current)==null?void 0:T.querySelectorAll("[data-job-row]");if(!(!y||y.length===0)){if(p.key==="ArrowDown"){p.preventDefault();const U=Math.min(A+1,y.length-1);P(U);try{localStorage.setItem(de,String(U))}catch{}(ie=y[U])==null||ie.focus()}else if(p.key==="ArrowUp"){p.preventDefault();const U=Math.max(A-1,0);P(U);try{localStorage.setItem(de,String(U))}catch{}(Se=y[U])==null||Se.focus()}}},[A]),pe=l.useCallback(p=>{P(p);try{localStorage.setItem(de,String(p))}catch{}},[]);if(!a)return null;if(D==="supervisor")return e.jsx(Dt,{supervisorConfig:a.config.supervisor,onSetConfig:p=>window.api.schedule.setConfig({supervisor:p}),onBack:()=>k("queue")});const{config:ee,jobs:O,paused:me,lastRunAt:H,nextReset:Q,effectiveConcurrency:$}=a;if(O.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 p of O)p.status in F&&F[p.status]++;const te=O.filter(p=>p.status==="running"),r=gt({snap:a,now:o,avgDurationMs:M,runningJobs:te}),m=ut(O,N),S=bt(m),{inline:I,collapsedCount:E}=wt(m,b,o,h),_=kt(I,O,S,M,r.kind,o),W=()=>{const p=new Set(b);for(const y of O)(y.status==="completed"||y.status==="failed")&&p.add(y.slug);w(p),Re(p)},Be=async()=>{const p=O.filter(ie=>ie.status!=="running").length;if(p===0)return;const y=`Archive ${p} non-running PRD${p===1?"":"s"} and remove from the queue?
1
+ import{_ as e,aq as we,a5 as l,an as Te,a as ue,G as z,ae as L,O as B,U as re,I as V,a4 as be,ao as le,a8 as ve,a9 as je,K as ke,at as ce,s as Le,a0 as W,l as Me,h as Ne,n as ye,D as q,d as R,q as Oe,T as Ue,a1 as Pe,ai as Ce,g as ae,m as Ae,f as Ve,ac as ze,t as Qe,k as Fe,ak as Ye,ah as se,r as We,C as Ke,ar as Xe,a6 as Ze,au as et,as as De,L as tt,i as he}from"./index-Cs_Lq9-w.js";import{l as st}from"./listSkills-QORduPIk.js";import{T as nt}from"./Toggle-BJHhHQOq.js";import"./monaco-editor-BW5C4Iv1.js";function at({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:d})=>{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:d},a)})})}const rt=5e3;let oe=null,ne=null;async function $e(t){const s=Date.now();return!(t!=null&&t.fresh)&&oe&&s-oe.at<rt?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)}function _e({options:t,value:s,onChange:n,pillPadding:a="px-3 py-1.5"}){return e.jsx("div",{className:"flex gap-1.5 flex-wrap",children:t.map(d=>{const i=d.value===s;return e.jsxs("button",{type:"button",onClick:()=>n(d.value),className:`rounded-full ${a} text-[12.5px] border transition-colors ${i?"bg-accent text-white border-accent font-semibold":"bg-bg-hi text-fg-dim border-line hover:border-fg-faint font-medium"}`,children:[d.label,d.count!==void 0&&e.jsxs("span",{children:[" ",d.count]})]},d.value)})})}const lt=5,it=1440*60*1e3,He="sm.scheduler.hiddenCompletedSlugs",de="sm.scheduler.focusedJobIndex",qe="sm.scheduler.queueFilter";function ot(t,s=60){const n=t.trim();return n.length<=s?n:`${n.slice(0,s-1)}…`}const dt=["all","running","investigating","pending","completed","needs_review","failed","quarantined"];function ct(){try{const t=localStorage.getItem(qe);if(!t)return{text:"",status:"all"};const s=JSON.parse(t);return{text:"",status:dt.includes(s.status)?s.status:"all"}}catch{return{text:"",status:"all"}}}function ut(t){try{localStorage.setItem(qe,JSON.stringify({status:t.status}))}catch{}}function xt(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 d=be(a.cwd)??"";return a.title.toLowerCase().includes(n)||a.slug.toLowerCase().includes(n)||d.toLowerCase().includes(n)})}function pt(){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 mt({scopeCwd:t=null,navigate:s}){const n=we(p=>p.snapshot),a=l.useMemo(()=>!n||!t?n:{...n,jobs:n.jobs.filter(p=>p.cwd===t)},[n,t]),[d,i]=l.useState(null),[c,x]=l.useState(!1),[o,u]=l.useState(()=>Date.now()),[b,w]=l.useState(()=>pt()),[h,v]=l.useState(!1),[N,C]=l.useState(()=>ct()),[f,j]=l.useState(!1),[D,k]=l.useState("queue"),g=l.useRef(null),[A,P]=l.useState(()=>{try{return Number(localStorage.getItem(de))||0}catch{return 0}}),[G,xe]=l.useState(""),J=Te();l.useEffect(()=>(window.api.schedule.health().then(i).catch(()=>{}),window.api.schedule.onState(()=>{window.api.schedule.health().then(i).catch(()=>{})})),[]),l.useEffect(()=>{if(!J)return;u(Date.now());const p=setInterval(()=>u(Date.now()),1e3);return()=>clearInterval(p)},[J]);const M=l.useMemo(()=>{if(!a)return 15e4;const p=[];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&&p.push(T)}return p.length===0?15e4:p.reduce((y,T)=>y+T,0)/p.length},[a]),K=l.useRef(new Map);l.useEffect(()=>{if(!a)return;const p=[];for(const y of a.jobs){const T=K.current.get(y.slug);T&&T!==y.status&&p.push(`${y.title}: ${T} → ${y.status}`),K.current.set(y.slug,y.status)}p.length>0&&xe(p.join("; "))},[a]);const X=l.useMemo(()=>{var y;const p=new Map;for(const T of((y=a==null?void 0:a.lastTick)==null?void 0:y.holds)??[])p.set(T.slug,T);return p},[a==null?void 0:a.lastTick]),Z=l.useCallback(p=>{var T,ie,Se;const y=(T=g.current)==null?void 0:T.querySelectorAll("[data-job-row]");if(!(!y||y.length===0)){if(p.key==="ArrowDown"){p.preventDefault();const U=Math.min(A+1,y.length-1);P(U);try{localStorage.setItem(de,String(U))}catch{}(ie=y[U])==null||ie.focus()}else if(p.key==="ArrowUp"){p.preventDefault();const U=Math.max(A-1,0);P(U);try{localStorage.setItem(de,String(U))}catch{}(Se=y[U])==null||Se.focus()}}},[A]),pe=l.useCallback(p=>{P(p);try{localStorage.setItem(de,String(p))}catch{}},[]);if(!a)return null;if(D==="supervisor")return e.jsx($t,{supervisorConfig:a.config.supervisor,onSetConfig:p=>window.api.schedule.setConfig({supervisor:p}),onBack:()=>k("queue")});const{config:ee,jobs:O,paused:me,lastRunAt:H,nextReset:Q,effectiveConcurrency:$}=a;if(O.length===0)return e.jsx(gt,{navigate:s});const F={pending:0,running:0,investigating:0,completed:0,needs_review:0,failed:0};for(const p of O)p.status in F&&F[p.status]++;const te=O.filter(p=>p.status==="running"),r=bt({snap:a,now:o,avgDurationMs:M,runningJobs:te}),m=xt(O,N),S=wt(m),{inline:I,collapsedCount:E}=vt(m,b,o,h),_=Pt(I,O,S,M,r.kind,o),Y=()=>{const p=new Set(b);for(const y of O)(y.status==="completed"||y.status==="failed")&&p.add(y.slug);w(p),Re(p)},Be=async()=>{const p=O.filter(ie=>ie.status!=="running").length;if(p===0)return;const y=`Archive ${p} non-running PRD${p===1?"":"s"} and remove from the queue?
2
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||L.error(`Clear queue failed: ${T.error??"unknown error"}`)},Je=()=>{w(new Set),Re(new Set),v(!1)},Ge=I.some(p=>p.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:J}),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(r.kind)}`,title:r.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(r.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(r.line1,a.utilization))}),r.line2&&e.jsx("div",{className:"text-[12px] text-fg-faint font-mono mt-0.5 truncate",children:r.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 ",z(H?Date.parse(H):null,o)]}),r.action&&e.jsx("button",{type:"button",onClick:r.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:r.action.title,children:r.action.label})]}),d&&d.consecutiveFailures>5&&d.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"," ",z(d.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:p=>window.api.schedule.setConfig({firePolicy:p.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:p=>{window.api.schedule.setSessionSlots(Number(p.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:p=>window.api.schedule.setConfig({utilizationThreshold:Number(p.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(L.fromOutcome).catch(()=>L.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(L.fromOutcome).catch(()=>L.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 p=($==null?void 0:$.cap)??5,y=O.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,"/",p," running"]}),y>0&&e.jsxs("span",{className:"text-fg-faint",children:["+",y," ready in this group"]})]})})(),O.length>0&&e.jsx(At,{filter:N,onChange:p=>{C(p),ct(p)}}),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:W,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:O.every(p=>p.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…"})]})]}),I.length===0&&E===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:I.map((p,y)=>e.jsx(Ct,{job:p,eta:_.get(p.slug)??null,elapsedMs:p.status==="running"&&p.startedAt?o-Date.parse(p.startedAt):null,avgDurationMs:M,listIndex:y,hold:X.get(p.slug),onFocused:pe},p.slug))}),E>0&&e.jsxs("button",{type:"button",onClick:()=>v(p=>!p),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?"▾":"▸"," ",E," 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:p=>{p.stopPropagation(),Je()},children:"un-hide"})]})]}),e.jsx(Rt,{snap:a,health:d,now:o,open:c,setOpen:x}),!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:[Q&&e.jsxs("span",{title:`next 5h reset: ${Q}`,children:["reset ",B(Date.parse(Q)-o)]}),H&&e.jsxs("span",{className:"ml-2",title:H,children:["last run ",B(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:"Start a session",body:"In Sessions, pick an Agent and a Mission, describe the outcome you want, then Approve & start. Its thread writes the PRD files into that session's own folder."},{title:"Queue what it wrote",body:"The PRDs tab lists every file the session produced. Queue one, or the whole session, and they appear here."},{title:"Leave it alone",body:"Jobs start themselves inside your window, pause on rate-limit, and resume at the reset. History records how each ended."}],ht=[{term:"Session",def:"One goal, one Claude session, and the folder of PRDs written to reach it."},{term:"PRD",def:"One markdown file = one job. Authored by the session."},{term:"5-hour window",def:"Your Claude billing window, on a rolling clock."},{term:"Session pool",def:"5 slots shared with terminal and session chats."}];function 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 a session."}),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. A session 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 Sessions →"})]},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:d,jobs:i,paused:c,nextReset:x,utilization:o,effectiveConcurrency:u}=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=(u==null?void 0:u.cap)??5;if(h>0){const j=a.reduce((P,J)=>(P.startedAt??"")<(J.startedAt??"")?P:J),D=j.startedAt?s-Date.parse(j.startedAt):0,k=w+h,g=w+v,A=h>1?` · ${h}/${N} parallel`:"";return{kind:"running",line1:`Running ${k}/${g}${A} · ${re(D)}`,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 ${V(Date.parse(c.resumeAt))} (in ${B(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=d.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(L.fromOutcome).catch(()=>L.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(!x)return{kind:"on-reset",line1:"On-reset · waiting for billing data",line2:null};const j=Date.parse(x)+d.offsetMinutes*6e4,D=j-s;return{kind:"on-reset",line1:`On-reset · ${b} pending`,line2:D>0?`fires ${V(j)} (in ${B(D)})`:"firing now…"}}const f=d.utilizationThreshold??90;if(o==null)return{kind:"auto-soon",line1:`Auto · ${b} pending`,line2:"checking token availability…"};if(o>=f){const j=x?Date.parse(x)-s:null;return{kind:"auto-throttled",line1:`Auto · throttled (util ${o.toFixed(0)}% ≥ ${f}%)`,line2:j&&j>0?`next reset ${V(Date.parse(x))} (in ${B(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,d)=>a.parallelGroup-d.parallelGroup||a.slug.localeCompare(d.slug)),n=new Map;return s.forEach((a,d)=>n.set(a.slug,d)),n}function wt(t,s,n,a){if(a)return{inline:t,collapsedCount:0};const d=t.filter(u=>u.status==="completed").sort((u,b)=>{const w=u.finishedAt?Date.parse(u.finishedAt):0;return(b.finishedAt?Date.parse(b.finishedAt):0)-w}),i=new Set;let c=0;for(const u of d){if(c>=rt)break;s.has(u.slug)||u.finishedAt&&n-Date.parse(u.finishedAt)>lt||(i.add(u.slug),c++)}const x=[];let o=0;for(const u of t){if(u.status==="failed"&&s.has(u.slug)){o++;continue}if(u.status!=="completed"){x.push(u);continue}i.has(u.slug)?x.push(u):o++}return{inline:x,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,d,i){const c=new Map;if(d==="paused"||d==="manual"||d==="auto-throttled"){for(const u of t)c.set(u.slug,null);return c}const x=s.find(u=>u.status==="running"&&u.startedAt),o=x!=null&&x.startedAt?i-Date.parse(x.startedAt):0;for(const u of t){if(u.status!=="pending"){c.set(u.slug,null);continue}const b=n.get(u.slug)??0;let w=b*a;b>0&&(w-=Math.min(a,o)),c.set(u.slug,w<=5e3?"~now":`~${re(w)}`)}return c}function Pt({job:t,eta:s,elapsedMs:n,avgDurationMs:a,listIndex:d,onFocused:i,hold:c}){const[x,o]=l.useState(!1),[u,b]=l.useState(!1),w=le(A=>A.sessions),h=l.useMemo(()=>ve(t,w),[t,w]),v=h.known&&h.epicId?w[h.epicId]:null,N=l.useCallback(A=>{je(A),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 ${re(Date.parse(t.finishedAt)-Date.parse(t.startedAt))}`:s&&(j=s);const D=t.error??null,k=f&&D?D.split(`
4
- `)[0]:t.status==="needs_review"&&t.verifierVerdict?ce(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":d,onClick:()=>o(A=>!A),onFocus:()=>i(d),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 ${x?"bg-bg-elev/40":""}`,"aria-expanded":x,"aria-label":`${Y(t.slug)?`PRD ${Y(t.slug)}, `:""}${t.title}, ${t.status}${j?`, ${j}`:""}`,title:t.title,children:[e.jsx(Le,{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:[Y(t.slug)&&e.jsx(Me,{n:Y(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 ${x?"rotate-90":""}`,"aria-hidden":"true",children:e.jsx(ue,{name:"chevron",size:14})})]})]}),C&&!x&&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)}%`}})}),x&&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(q,{label:"Status",children:[e.jsx(R,{k:"result",v:t.exitCode!==null?`exit ${t.exitCode}`:"—"}),e.jsx(R,{k:"state",v:t.status.replace(/_/g," ")}),t.verifierVerdict&&e.jsx(R,{k:"verdict",v:ce(t.verifierVerdict)}),D&&e.jsx(R,{k:"error",v:D.split(`
5
- `)[0],wrap:!0})]}),t.statusHistory&&t.statusHistory.length>0&&e.jsx(q,{label:"History",children:e.jsx("div",{className:"grid gap-1",children:t.statusHistory.map((A,P)=>e.jsxs("div",{className:"font-mono text-xs leading-relaxed",children:[e.jsxs("div",{className:"text-fg",children:[A.from??"(new)"," → ",A.to,e.jsxs("span",{className:"text-fg-faint",children:[" · ",V(Date.parse(A.at))]})]}),A.reason&&e.jsx("div",{className:"text-fg-faint break-words",children:A.reason})]},P))})}),e.jsxs(q,{label:"Timing",children:[e.jsx(R,{k:"started",v:t.startedAt?V(Date.parse(t.startedAt)):"—"}),e.jsx(R,{k:"finished",v:t.finishedAt?V(Date.parse(t.finishedAt)):"—"}),e.jsx(R,{k:"duration",v:t.startedAt&&t.finishedAt?re(Date.parse(t.finishedAt)-Date.parse(t.startedAt)):C&&n!==null?ke(n):"—"})]}),e.jsxs(q,{label:"Location",children:[e.jsx(R,{k:"group",v:`${t.parallelGroup} · ${t.slug}`}),e.jsx(R,{k:"cwd",v:t.cwd??"—",wrap:!0}),e.jsx(R,{k:"session",v:h.label??h.epicId??"—",wrap:!0}),e.jsx(R,{k:"session id",v:h.epicId??"—",wrap:!0}),e.jsx(R,{k:"prompt id",v:t.sourcePromptId??"—",wrap:!0}),e.jsx(R,{k:"source tab",v:t.sourceTabId??"—",wrap:!0})]}),e.jsx(q,{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==="quarantined"&&e.jsx("button",{type:"button","data-testid":"job-row-adopt-prd",title:"Stamp this PRD's provenance so the scheduler will run it — no unstamped PRD runs automatically.",onClick:()=>{window.api.schedule.adoptPrd(t.slug).then(L.fromOutcome).catch(()=>L.error("Failed to adopt PRD"))},className:"text-[13px] font-semibold text-accent hover:text-accent/80 bg-transparent border-0 cursor-pointer p-0",children:"adopt PRD →"}),t.status!=="pending"&&t.status!=="running"&&t.status!=="quarantined"&&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 →"})]})})]}),u&&t.runId&&e.jsx(Oe,{runId:t.runId,slug:t.slug,title:t.title||t.slug,onClose:()=>b(!1)})]})}const Ct=l.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"},{label:"Quarantined",value:"quarantined"}];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(_e,{options:n,value:t.status,onChange:a=>s({...t,status:a})})]})}function Dt({supervisorConfig:t,onSetConfig:s,onBack:n}){const[a,d]=l.useState([]),[i,c]=l.useState(()=>Date.now()),x=Te();l.useEffect(()=>{if(!x)return;window.api.supervisor.getLog().then(d).catch(()=>{}),c(Date.now());const u=setInterval(()=>c(Date.now()),5e3);return()=>clearInterval(u)},[x]);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(d).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:u=>s({enabled:u.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:u=>s({intervalMinutes:Number(u.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:u=>s({maxConcurrentProbes:Number(u.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:u=>s({probeStaleThresholdMinutes:Number(u.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((u,b)=>e.jsx($t,{entry:u,now:i},`${u.ts}-${b}`))})]})]})}function $t({entry:t,now:s}){const n=t.action!=="none",a=B(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:d}){const[i,c]=l.useState(null),[x,o]=l.useState(!1),u=`${t.jobs.length}:${t.lastRunAt??""}`;l.useEffect(()=>{let k=!0;return o(!0),$e().then(g=>{k&&c(g)}).catch(()=>{}).finally(()=>{k&&o(!1)}),()=>{k=!1}},[u]);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"}`:""}`:x?"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,D=[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:()=>d(!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:D.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: ",z(s.bootedAt,n)]}),e.jsxs("div",{children:["last poll: ",z(s.lastPollAt,n)," · ",s.lastPollOk?"ok":"failed"]}),s.backoffNextAt!==null&&s.backoffNextAt>n&&e.jsxs("div",{children:["retry in: ",B(s.backoffNextAt-n)]}),s.nextResetCached&&e.jsxs("div",{children:["cached reset: ",V(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,A)=>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}-${A}`))]},k.slug)),e.jsx("button",{type:"button",onClick:()=>{o(!0),$e({fresh:!0}).then(c).catch(()=>{}).finally(()=>o(!1))},className:"text-fg-faint hover:text-fg-dim underline",children:x?"…":"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 d;const n=[];for(const i of Et){const c=t[i];if(c==null||c==="")continue;const x=(d=t._raw)==null?void 0:d[i];if(x&&x.parsed===c){n.push(x.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(`
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||L.error(`Clear queue failed: ${T.error??"unknown error"}`)},Ge=()=>{w(new Set),Re(new Set),v(!1)},Je=I.some(p=>p.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:G}),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 ${jt(r.kind)}`,title:r.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 ${Nt(r.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:St(kt(r.line1,a.utilization))}),r.line2&&e.jsx("div",{className:"text-[12px] text-fg-faint font-mono mt-0.5 truncate",children:r.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 ",z(H?Date.parse(H):null,o)]}),r.action&&e.jsx("button",{type:"button",onClick:r.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:r.action.title,children:r.action.label})]}),d&&d.consecutiveFailures>5&&d.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"," ",z(d.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:p=>window.api.schedule.setConfig({firePolicy:p.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:p=>{window.api.schedule.setSessionSlots(Number(p.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:p=>window.api.schedule.setConfig({utilizationThreshold:Number(p.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(L.fromOutcome).catch(()=>L.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(L.fromOutcome).catch(()=>L.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 p=($==null?void 0:$.cap)??5,y=O.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,"/",p," running"]}),y>0&&e.jsxs("span",{className:"text-fg-faint",children:["+",y," ready in this group"]})]})})(),O.length>0&&e.jsx(Dt,{filter:N,onChange:p=>{C(p),ut(p)}}),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"]})]}),Je&&e.jsx("button",{type:"button",onClick:Y,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:O.every(p=>p.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…"})]})]}),I.length===0&&E===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:I.map((p,y)=>e.jsx(At,{job:p,eta:_.get(p.slug)??null,elapsedMs:p.status==="running"&&p.startedAt?o-Date.parse(p.startedAt):null,avgDurationMs:M,listIndex:y,hold:X.get(p.slug),onFocused:pe},p.slug))}),E>0&&e.jsxs("button",{type:"button",onClick:()=>v(p=>!p),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?"▾":"▸"," ",E," 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:p=>{p.stopPropagation(),Ge()},children:"un-hide"})]})]}),e.jsx(Et,{snap:a,health:d,now:o,open:c,setOpen:x}),!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:[Q&&e.jsxs("span",{title:`next 5h reset: ${Q}`,children:["reset ",B(Date.parse(Q)-o)]}),H&&e.jsxs("span",{className:"ml-2",title:H,children:["last run ",B(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 ht=[{title:"Start a session",body:"In Sessions, pick an Agent and a Mission, describe the outcome you want, then Approve & start. Its thread writes the PRD files into that session's own folder."},{title:"Queue what it wrote",body:"The PRDs tab lists every file the session produced. Queue one, or the whole session, and they appear here."},{title:"Leave it alone",body:"Jobs start themselves inside your window, pause on rate-limit, and resume at the reset. History records how each ended."}],ft=[{term:"Session",def:"One goal, one Claude session, and the folder of PRDs written to reach it."},{term:"PRD",def:"One markdown file = one job. Authored by the session."},{term:"5-hour window",def:"Your Claude billing window, on a rolling clock."},{term:"Session pool",def:"5 slots shared with terminal and session chats."}];function gt({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 a session."}),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. A session 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:ht.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 Sessions →"})]},s.title)})}),e.jsx("dl",{className:"flex mt-[22px] pt-4 border-t border-line gap-5 flex-wrap",children:ft.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 bt({snap:t,now:s,avgDurationMs:n,runningJobs:a}){const{config:d,jobs:i,paused:c,nextReset:x,utilization:o,effectiveConcurrency:u}=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=(u==null?void 0:u.cap)??5;if(h>0){const j=a.reduce((P,G)=>(P.startedAt??"")<(G.startedAt??"")?P:G),D=j.startedAt?s-Date.parse(j.startedAt):0,k=w+h,g=w+v,A=h>1?` · ${h}/${N} parallel`:"";return{kind:"running",line1:`Running ${k}/${g}${A} · ${re(D)}`,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 ${V(Date.parse(c.resumeAt))} (in ${B(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=d.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(L.fromOutcome).catch(()=>L.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(!x)return{kind:"on-reset",line1:"On-reset · waiting for billing data",line2:null};const j=Date.parse(x)+d.offsetMinutes*6e4,D=j-s;return{kind:"on-reset",line1:`On-reset · ${b} pending`,line2:D>0?`fires ${V(j)} (in ${B(D)})`:"firing now…"}}const f=d.utilizationThreshold??90;if(o==null)return{kind:"auto-soon",line1:`Auto · ${b} pending`,line2:"checking token availability…"};if(o>=f){const j=x?Date.parse(x)-s:null;return{kind:"auto-throttled",line1:`Auto · throttled (util ${o.toFixed(0)}% ≥ ${f}%)`,line2:j&&j>0?`next reset ${V(Date.parse(x))} (in ${B(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 wt(t){const s=t.filter(a=>a.status==="running"||a.status==="pending").sort((a,d)=>a.parallelGroup-d.parallelGroup||a.slug.localeCompare(d.slug)),n=new Map;return s.forEach((a,d)=>n.set(a.slug,d)),n}function vt(t,s,n,a){if(a)return{inline:t,collapsedCount:0};const d=t.filter(u=>u.status==="completed").sort((u,b)=>{const w=u.finishedAt?Date.parse(u.finishedAt):0;return(b.finishedAt?Date.parse(b.finishedAt):0)-w}),i=new Set;let c=0;for(const u of d){if(c>=lt)break;s.has(u.slug)||u.finishedAt&&n-Date.parse(u.finishedAt)>it||(i.add(u.slug),c++)}const x=[];let o=0;for(const u of t){if(u.status==="failed"&&s.has(u.slug)){o++;continue}if(u.status!=="completed"){x.push(u);continue}i.has(u.slug)?x.push(u):o++}return{inline:x,collapsedCount:o}}function jt(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 Nt(t){return t==="running"||t==="auto-soon"?"text-accent":t==="idle"?"text-sage":t==="paused"||t==="auto-throttled"?"text-butter":"text-fg-faint"}const yt=["Running","Paused","Manual","On-reset","Auto"];function St(t){for(const s of yt)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 kt(t,s){return s==null||t.includes("util")?t:`${t} · util ${Math.round(s)}%`}function Pt(t,s,n,a,d,i){const c=new Map;if(d==="paused"||d==="manual"||d==="auto-throttled"){for(const u of t)c.set(u.slug,null);return c}const x=s.find(u=>u.status==="running"&&u.startedAt),o=x!=null&&x.startedAt?i-Date.parse(x.startedAt):0;for(const u of t){if(u.status!=="pending"){c.set(u.slug,null);continue}const b=n.get(u.slug)??0;let w=b*a;b>0&&(w-=Math.min(a,o)),c.set(u.slug,w<=5e3?"~now":`~${re(w)}`)}return c}function Ct({job:t,eta:s,elapsedMs:n,avgDurationMs:a,listIndex:d,onFocused:i,hold:c}){const[x,o]=l.useState(!1),[u,b]=l.useState(!1),w=le(A=>A.sessions),h=l.useMemo(()=>ve(t,w),[t,w]),v=h.known&&h.epicId?w[h.epicId]:null,N=l.useCallback(A=>{je(A),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 ${re(Date.parse(t.finishedAt)-Date.parse(t.startedAt))}`:s&&(j=s);const D=t.error??null,k=f&&D?D.split(`
4
+ `)[0]:t.status==="needs_review"&&t.verifierVerdict?ce(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":d,onClick:()=>o(A=>!A),onFocus:()=>i(d),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 ${x?"bg-bg-elev/40":""}`,"aria-expanded":x,"aria-label":`${W(t.slug)?`PRD ${W(t.slug)}, `:""}${t.title}, ${t.status}${j?`, ${j}`:""}`,title:t.title,children:[e.jsx(Le,{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(Me,{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?ot(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 ${x?"rotate-90":""}`,"aria-hidden":"true",children:e.jsx(ue,{name:"chevron",size:14})})]})]}),C&&!x&&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)}%`}})}),x&&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(q,{label:"Status",children:[e.jsx(R,{k:"result",v:t.exitCode!==null?`exit ${t.exitCode}`:"—"}),e.jsx(R,{k:"state",v:t.status.replace(/_/g," ")}),t.verifierVerdict&&e.jsx(R,{k:"verdict",v:ce(t.verifierVerdict)}),D&&e.jsx(R,{k:"error",v:D.split(`
5
+ `)[0],wrap:!0})]}),t.statusHistory&&t.statusHistory.length>0&&e.jsx(q,{label:"History",children:e.jsx("div",{className:"grid gap-1",children:t.statusHistory.map((A,P)=>e.jsxs("div",{className:"font-mono text-xs leading-relaxed",children:[e.jsxs("div",{className:"text-fg",children:[A.from??"(new)"," → ",A.to,e.jsxs("span",{className:"text-fg-faint",children:[" · ",V(Date.parse(A.at))]})]}),A.reason&&e.jsx("div",{className:"text-fg-faint break-words",children:A.reason})]},P))})}),e.jsxs(q,{label:"Timing",children:[e.jsx(R,{k:"started",v:t.startedAt?V(Date.parse(t.startedAt)):"—"}),e.jsx(R,{k:"finished",v:t.finishedAt?V(Date.parse(t.finishedAt)):"—"}),e.jsx(R,{k:"duration",v:t.startedAt&&t.finishedAt?re(Date.parse(t.finishedAt)-Date.parse(t.startedAt)):C&&n!==null?ke(n):"—"})]}),e.jsxs(q,{label:"Location",children:[e.jsx(R,{k:"group",v:`${t.parallelGroup} · ${t.slug}`}),e.jsx(R,{k:"cwd",v:t.cwd??"—",wrap:!0}),e.jsx(R,{k:"session",v:h.label??h.epicId??"—",wrap:!0}),e.jsx(R,{k:"session id",v:h.epicId??"—",wrap:!0}),e.jsx(R,{k:"prompt id",v:t.sourcePromptId??"—",wrap:!0}),e.jsx(R,{k:"source tab",v:t.sourceTabId??"—",wrap:!0})]}),e.jsx(q,{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==="quarantined"&&e.jsx("button",{type:"button","data-testid":"job-row-adopt-prd",title:"Stamp this PRD's provenance so the scheduler will run it — no unstamped PRD runs automatically.",onClick:()=>{window.api.schedule.adoptPrd(t.slug).then(L.fromOutcome).catch(()=>L.error("Failed to adopt PRD"))},className:"text-[13px] font-semibold text-accent hover:text-accent/80 bg-transparent border-0 cursor-pointer p-0",children:"adopt PRD →"}),t.status!=="pending"&&t.status!=="running"&&t.status!=="quarantined"&&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 →"})]})})]}),u&&t.runId&&e.jsx(Oe,{runId:t.runId,slug:t.slug,title:t.title||t.slug,onClose:()=>b(!1)})]})}const At=l.memo(Ct);function Dt({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"},{label:"Quarantined",value:"quarantined"}];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(_e,{options:n,value:t.status,onChange:a=>s({...t,status:a})})]})}function $t({supervisorConfig:t,onSetConfig:s,onBack:n}){const[a,d]=l.useState([]),[i,c]=l.useState(()=>Date.now()),x=Te();l.useEffect(()=>{if(!x)return;window.api.supervisor.getLog().then(d).catch(()=>{}),c(Date.now());const u=setInterval(()=>c(Date.now()),5e3);return()=>clearInterval(u)},[x]);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(d).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:u=>s({enabled:u.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:u=>s({intervalMinutes:Number(u.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:u=>s({maxConcurrentProbes:Number(u.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:u=>s({probeStaleThresholdMinutes:Number(u.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((u,b)=>e.jsx(Rt,{entry:u,now:i},`${u.ts}-${b}`))})]})]})}function Rt({entry:t,now:s}){const n=t.action!=="none",a=B(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 Et({snap:t,health:s,now:n,open:a,setOpen:d}){const[i,c]=l.useState(null),[x,o]=l.useState(!1),u=`${t.jobs.length}:${t.lastRunAt??""}`;l.useEffect(()=>{let k=!0;return o(!0),$e().then(g=>{k&&c(g)}).catch(()=>{}).finally(()=>{k&&o(!1)}),()=>{k=!1}},[u]);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"}`:""}`:x?"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,D=[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:()=>d(!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:D.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: ",z(s.bootedAt,n)]}),e.jsxs("div",{children:["last poll: ",z(s.lastPollAt,n)," · ",s.lastPollOk?"ok":"failed"]}),s.backoffNextAt!==null&&s.backoffNextAt>n&&e.jsxs("div",{children:["retry in: ",B(s.backoffNextAt-n)]}),s.nextResetCached&&e.jsxs("div",{children:["cached reset: ",V(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,A)=>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}-${A}`))]},k.slug)),e.jsx("button",{type:"button",onClick:()=>{o(!0),$e({fresh:!0}).then(c).catch(()=>{}).finally(()=>o(!1))},className:"text-fg-faint hover:text-fg-dim underline",children:x?"…":"rerun lint"})]})]})]})}new Set(Ue.map(t=>t.tag).filter(t=>t!=="discussion"));const It=["title","cwd","estimateMinutes","parallelGroup","sourcePromptId","sourceTabId","tag"];function Tt(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 Lt(t,s){var d;const n=[];for(const i of It){const c=t[i];if(c==null||c==="")continue;const x=(d=t._raw)==null?void 0:d[i];if(x&&x.parsed===c){n.push(x.line);continue}if(typeof c=="number"){n.push(`${i}: ${c}`);continue}n.push(`${i}: ${Tt(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
7
  `))}return`---
8
8
  ${n.join(`
9
9
  `)}
10
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:d}){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 ${d?"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]=l.useState([]),[a,d]=l.useState(null),[i,c]=l.useState(null),[x,o]=l.useState(null),[u,b]=l.useState(!1),[w,h]=l.useState(!0),[v,N]=l.useState(new Set),[C,f]=l.useState(!1),[j,D]=l.useState(!1),[k,g]=l.useState(!1),[A,P]=l.useState(null);l.useEffect(()=>{let r=!0;return window.api.schedule.listPrds().then(m=>{r&&(n(fe(m)),h(!1))}).catch(m=>{r&&(h(!1),L.error(`Scheduler: failed to load PRD list — ${m instanceof Error?m.message:"unknown error"}`))}),()=>{r=!1}},[]);const J=we(r=>r.snapshot),xe=le(r=>r.sessions);l.useEffect(()=>{J&&d(J)},[J]);const G=l.useMemo(()=>[...s].filter(r=>!t||r.cwd===t).sort((r,m)=>m.mtimeMs-r.mtimeMs||r.slug.localeCompare(m.slug)),[s,t]);l.useEffect(()=>{const r=Ve();r&&c(r);const m=S=>c(S.detail);return window.addEventListener("sm:select-prd",m),()=>window.removeEventListener("sm:select-prd",m)},[]);const M=l.useMemo(()=>(a==null?void 0:a.jobs.find(r=>r.slug===i))??null,[a,i]),K=Pe(M);function X(r){var S;const m=(S=s.find(I=>I.slug===r))==null?void 0:S.cwd;return m?`${m}/session-manager-operations/scheduler/prds/${r}.md`:null}l.useEffect(()=>{if(!i)return;const r=X(i);r&&Ce.getState().openFile(r)},[i,s]);function Z(r){c(r),o(null),b(!1)}function pe(){c(null)}async function ee(){if(!i)return;if(!(M!=null&&M.runId)){o("no log available (job has not run yet)"),b(m=>!m);return}const r=await window.api.schedule.readLog(M.runId,i);o(r.ok?r.text??"":`error: ${r.error}`),b(m=>!m)}if(w)return e.jsx(ae,{title:"loading PRDs…"});const O=r=>{N(m=>{const S=new Set(m);return S.has(r)?S.delete(r):S.add(r),S})};!(G.length>0&&G.every(r=>v.has(r.slug)))&&G.some(r=>v.has(r.slug));const H=()=>N(new Set);async function Q(){try{const r=await window.api.schedule.listPrds();n(fe(r))}catch{}}async function $(){const r=`new-prd-${Date.now()}`,m=Tt({title:"New PRD",cwd:"",estimateMinutes:60,parallelGroup:99},`## Task
11
+ ${s}`}function fe(t){return t.filter(s=>!s.archived)}function Mt(t){je(t),window.dispatchEvent(new CustomEvent("sm:navigate",{detail:"terminal"}))}function ge({label:t,tip:s,onClick:n,disabled:a,primary:d}){return e.jsx(Qe,{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 ${d?"text-accent border-accent/50 hover:bg-bg-hi":"text-fg-dim border-line hover:text-fg hover:bg-bg-hi"}`,children:t})})}function Ot({scopeCwd:t=null}){const[s,n]=l.useState([]),[a,d]=l.useState(null),[i,c]=l.useState(null),[x,o]=l.useState(null),[u,b]=l.useState(!1),[w,h]=l.useState(!0),[v,N]=l.useState(new Set),[C,f]=l.useState(!1),[j,D]=l.useState(!1),[k,g]=l.useState(!1),[A,P]=l.useState(null);l.useEffect(()=>{let r=!0;return window.api.schedule.listPrds().then(m=>{r&&(n(fe(m)),h(!1))}).catch(m=>{r&&(h(!1),L.error(`Scheduler: failed to load PRD list — ${m instanceof Error?m.message:"unknown error"}`))}),()=>{r=!1}},[]);const G=we(r=>r.snapshot),xe=le(r=>r.sessions);l.useEffect(()=>{G&&d(G)},[G]);const J=l.useMemo(()=>[...s].filter(r=>!t||r.cwd===t).sort((r,m)=>m.mtimeMs-r.mtimeMs||r.slug.localeCompare(m.slug)),[s,t]);l.useEffect(()=>{const r=ze();r&&c(r);const m=S=>c(S.detail);return window.addEventListener("sm:select-prd",m),()=>window.removeEventListener("sm:select-prd",m)},[]);const M=l.useMemo(()=>(a==null?void 0:a.jobs.find(r=>r.slug===i))??null,[a,i]),K=Pe(M);function X(r){var S;const m=(S=s.find(I=>I.slug===r))==null?void 0:S.cwd;return m?`${m}/session-manager-operations/scheduler/prds/${r}.md`:null}l.useEffect(()=>{if(!i)return;const r=X(i);r&&Ce.getState().openFile(r)},[i,s]);function Z(r){c(r),o(null),b(!1)}function pe(){c(null)}async function ee(){if(!i)return;if(!(M!=null&&M.runId)){o("no log available (job has not run yet)"),b(m=>!m);return}const r=await window.api.schedule.readLog(M.runId,i);o(r.ok?r.text??"":`error: ${r.error}`),b(m=>!m)}if(w)return e.jsx(ae,{title:"loading PRDs…"});const O=r=>{N(m=>{const S=new Set(m);return S.has(r)?S.delete(r):S.add(r),S})};!(J.length>0&&J.every(r=>v.has(r.slug)))&&J.some(r=>v.has(r.slug));const H=()=>N(new Set);async function Q(){try{const r=await window.api.schedule.listPrds();n(fe(r))}catch{}}async function $(){const r=`new-prd-${Date.now()}`,m=Lt({title:"New PRD",cwd:"",estimateMinutes:60,parallelGroup:99},`## Task
12
12
 
13
13
  Describe the task here.
14
- `);try{const S=await window.api.schedule.writePrd(r,m);if(!S.ok){L.error(`Failed to create PRD: ${S.error}`);return}const I=await window.api.schedule.listPrds();n(fe(I)),Z(r)}catch(S){L.error(`Failed to create PRD: ${S instanceof Error?S.message:String(S)}`)}}async function F(){var r;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 I=((r=S.results)==null?void 0:r.filter(E=>!E.ok))??[];I.length>0&&L.warn(`Archive: ${I.length} of ${S.results.length} PRD${I.length===1?"":"s"} failed to move`),H(),f(!1),await Q()}}catch(m){P(m instanceof Error?m.message:String(m))}finally{g(!1)}}async function te(r,m){g(!0),P(null);try{const S=[];for(const E of v){const _={slug:E};r!==null&&(_.parallelGroup=r),m!==null&&(_.estimateMinutes=m),S.push(_)}const I=await window.api.schedule.retagPrds(S);if(!I.ok)P(I.error??"retag failed");else{H(),D(!1),await Q();for(const E of I.results)if(E.newSlug&&E.newSlug!==E.slug){const _=X(E.slug),W=X(E.newSlug);_&&W&&Ce.getState().renameOpenFile(_,W)}i&&I.results.some(E=>E.slug===i&&E.newSlug&&E.newSlug!==E.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:u?"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,{})}),u&&x!==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",M!=null&&M.runId?` — ${M.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:x})]})]}):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:()=>D(!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"})]}),G.length===0?e.jsx(ae,{title:"no PRDs found"}):e.jsx("div",{className:"grid gap-3",children:G.map(r=>{const m=a==null?void 0:a.jobs.find(W=>W.slug===r.slug),S=Pe(m),I=ve({epicId:r.epicId??(m==null?void 0:m.epicId)??null,sourcePromptId:r.sourcePromptId??(m==null?void 0:m.sourcePromptId)??null,sourceTabId:(m==null?void 0:m.sourceTabId)??null},xe),E=(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(r.slug),onChange:()=>O(r.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:[Y(r.slug)&&e.jsx(Me,{n:Y(r.slug)}),e.jsx("button",{type:"button",onClick:()=>Z(r.slug),className:"font-serif text-[18px] font-semibold text-fg leading-tight hover:underline text-left",children:r.title||r.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:r.cwd}),e.jsx(Ne,{epicId:I.epicId,label:I.label,onOpen:Lt}),r.estimateMinutes!=null&&e.jsxs("span",{children:[r.estimateMinutes,"m"]}),e.jsxs("span",{children:["g",r.parallelGroup]}),e.jsxs("span",{children:["edited ",z(r.mtimeMs,Date.now())]})]}),e.jsx("button",{type:"button",onClick:()=>Z(r.slug),className:"mt-1.5 font-mono text-[11px] text-fg-faint hover:text-fg-dim leading-none",children:r.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:ce(m.verifierVerdict)})]}),e.jsx("button",{type:"button",onClick:()=>window.api.schedule.resetJob(r.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:E,className:"bg-fg text-bg rounded-lg px-[18px] py-2 text-[13px] font-semibold whitespace-nowrap disabled:opacity-50",children:E?"Running…":"Queue job"})})]},r.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:()=>D(!1),onConfirm:te})]})}function Ot({open:t,count:s,busy:n,onClose:a,onConfirm:d}){return e.jsxs(Fe,{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:d,disabled:n||s===0,className:"px-2 py-1 text-xs border border-accent/60 text-accent rounded hover:bg-bg-hi disabled:opacity-40",children:n?"Archiving…":`Archive ${s}`})]})]})}function Ft({open:t,count:s,busy:n,onClose:a,onConfirm:d}){const[i,c]=l.useState(""),[x,o]=l.useState(""),[u,b]=l.useState(null);l.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(x.trim()){const N=Number(x);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}d(h,v)}return e.jsxs(Fe,{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:x,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"})]})]}),u&&e.jsx("div",{className:"mt-2 text-[10px] text-red-300",children:u}),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]=l.useState(null),[a,d]=l.useState(!0),[i,c]=l.useState(""),[x,o]=l.useState(""),[u,b]=l.useState(""),[w,h]=l.useState("all");l.useEffect(()=>{d(!0),window.api.schedule.getHistory().then(f=>n(f)).catch(f=>n({ok:!1,jobs:[],error:f instanceof Error?f.message:String(f)})).finally(()=>d(!1))},[]);const v=l.useMemo(()=>{if(!(s!=null&&s.jobs))return[];const f=new Set;for(const j of s.jobs){const D=be(j.cwd);D&&f.add(D)}return[...f].sort()},[s]),N=l.useMemo(()=>s!=null&&s.jobs?s.jobs.filter(f=>!(t&&f.cwd!==t||w!=="all"&&f.status!==w||i&&be(f.cwd)!==i||x&&Ee(f.finishedAt)<x||u&&Ee(f.finishedAt)>u)):[],[s,w,i,x,u,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||!!x||!!u;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(_e,{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:x,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:u,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]=l.useState(!1),[a,d]=l.useState(!1),i=le(h=>h.sessions),c=l.useMemo(()=>ve(t,i),[t,i]),x=t.startedAt&&t.finishedAt?Date.parse(t.finishedAt)-Date.parse(t.startedAt):null,o=t.startedAt?new Date(t.startedAt).toLocaleString():"—",u=t.finishedAt?new Date(t.finishedAt).toLocaleString():"—",b=x!==null?re(x):"—",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(Le,{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(q,{label:"Status",children:[e.jsx(R,{k:"result",v:w}),e.jsx(R,{k:"state",v:t.status.replace("_"," ")}),t.verifierVerdict&&e.jsx(R,{k:"verifier",v:ce(t.verifierVerdict)})]}),e.jsxs(q,{label:"Timing",children:[e.jsx(R,{k:"started",v:o}),e.jsx(R,{k:"finished",v:u}),e.jsx(R,{k:"duration",v:b})]}),e.jsxs(q,{label:"Location",children:[e.jsx(R,{k:"group",v:t.parallelGroup!=null?String(t.parallelGroup):"—"}),e.jsx(R,{k:"slug",v:t.slug}),e.jsx(R,{k:"epic",v:c.label??c.epicId??"—",wrap:!0}),t.cwd&&e.jsx(R,{k:"cwd",v:t.cwd,wrap:!0})]}),e.jsx(q,{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(),d(!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(Oe,{runId:t.runId,slug:t.slug,title:t.title||t.slug,onClose:()=>d(!1)})]})}function Jt(t){return t?Object.values(t).reduce((s,n)=>s+(n??[]).reduce((a,d)=>{var i;return a+(((i=d.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),d=se(g=>g.loadText),i=se(g=>g.watchFile),c=se(g=>g.unwatchFile),x=s?We.resolve("user",s,null):null,o=s?Ye.resolve("user",s,null):null,u=s?`${s}/.claude.json`:null;l.useEffect(()=>{const g=[x,u].filter(Boolean);g.forEach(P=>{n[P]||a(P),i(P)});const A=[o].filter(Boolean);return A.forEach(P=>{n[P]||d(P),i(P)}),()=>{[...g,...A].forEach(P=>c(P))}},[x,o,u]);const[b,w]=l.useState(null);l.useEffect(()=>{if(!s)return;let g=!1;return(async()=>{const A=await tt(`${s}/.claude/skills`);g||w(A.length)})(),()=>{g=!0}},[s]);const h=x?n[x]:null,v=u?n[u]:null,N=o?n[o]:null,C=l.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=l.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…",D=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:D??(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]=l.useState(!1),[d,i]=l.useState(!1);l.useEffect(()=>{let x=!0;return Xe().then(o=>{x&&a(o.openToHomeOnLaunch===!0)}),()=>{x=!1}},[]);const c=async x=>{a(x),i(!0);try{await Ze({openToHomeOnLaunch:x})}catch{a(!x),L.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},(x,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((x,o)=>e.jsxs("li",{className:"font-mono text-[12px] text-fg-dim",children:[x.owner," ",e.jsxs("span",{className:"text-fg-faint",children:["since ",new Date(x.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:d,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 session"})]})]})]})]})}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 d=new Date(s).getTime()-n;return d>0?`Paused for rate limit — resumes in ${B(d)}`:"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]=l.useState(()=>Date.now());if(l.useEffect(()=>{const f=setInterval(()=>a(Date.now()),3e4);return()=>clearInterval(f)},[]),!s)return null;const d=(s.jobs??[]).filter(f=>!t||f.cwd===t),i=d.filter(f=>f.status==="pending").length,c=d.filter(f=>f.status==="running").length,x=d.filter(f=>f.status==="completed"&&(f.finishedAt?Qt(f.finishedAt,n):!1)).length,o=s.nextReset?new Date(s.nextReset).getTime():null,u=o?o>n?B(o-n):"soon":"—",b=z(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 ",u]}),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:x,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"," ",z(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 x;const[s,n]=l.useState(()=>{const o=localStorage.getItem(Ie);return o==="prds"||o==="history"||o==="machine"?o:"queue"}),a=De(o=>o.tabs),d=De(o=>o.activeTabId),i=((x=a.find(o=>o.id===d))==null?void 0:x.cwd)??null,c=i;return l.useEffect(()=>{i&&(le.getState().hydrate(i),le.getState().hydrateArchived(i))},[i]),l.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=l.memo(Kt);export{ss as Scheduler};
14
+ `);try{const S=await window.api.schedule.writePrd(r,m);if(!S.ok){L.error(`Failed to create PRD: ${S.error}`);return}const I=await window.api.schedule.listPrds();n(fe(I)),Z(r)}catch(S){L.error(`Failed to create PRD: ${S instanceof Error?S.message:String(S)}`)}}async function F(){var r;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 I=((r=S.results)==null?void 0:r.filter(E=>!E.ok))??[];I.length>0&&L.warn(`Archive: ${I.length} of ${S.results.length} PRD${I.length===1?"":"s"} failed to move`),H(),f(!1),await Q()}}catch(m){P(m instanceof Error?m.message:String(m))}finally{g(!1)}}async function te(r,m){g(!0),P(null);try{const S=[];for(const E of v){const _={slug:E};r!==null&&(_.parallelGroup=r),m!==null&&(_.estimateMinutes=m),S.push(_)}const I=await window.api.schedule.retagPrds(S);if(!I.ok)P(I.error??"retag failed");else{H(),D(!1),await Q();for(const E of I.results)if(E.newSlug&&E.newSlug!==E.slug){const _=X(E.slug),Y=X(E.newSlug);_&&Y&&Ce.getState().renameOpenFile(_,Y)}i&&I.results.some(E=>E.slug===i&&E.newSlug&&E.newSlug!==E.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:u?"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(Ve,{})}),u&&x!==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",M!=null&&M.runId?` — ${M.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:x})]})]}):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:()=>D(!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(r=>{const m=a==null?void 0:a.jobs.find(Y=>Y.slug===r.slug),S=Pe(m),I=ve({epicId:r.epicId??(m==null?void 0:m.epicId)??null,sourcePromptId:r.sourcePromptId??(m==null?void 0:m.sourcePromptId)??null,sourceTabId:(m==null?void 0:m.sourceTabId)??null},xe),E=(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(r.slug),onChange:()=>O(r.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(r.slug)&&e.jsx(Me,{n:W(r.slug)}),e.jsx("button",{type:"button",onClick:()=>Z(r.slug),className:"font-serif text-[18px] font-semibold text-fg leading-tight hover:underline text-left",children:r.title||r.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:r.cwd}),e.jsx(Ne,{epicId:I.epicId,label:I.label,onOpen:Mt}),r.estimateMinutes!=null&&e.jsxs("span",{children:[r.estimateMinutes,"m"]}),e.jsxs("span",{children:["g",r.parallelGroup]}),e.jsxs("span",{children:["edited ",z(r.mtimeMs,Date.now())]})]}),e.jsx("button",{type:"button",onClick:()=>Z(r.slug),className:"mt-1.5 font-mono text-[11px] text-fg-faint hover:text-fg-dim leading-none",children:r.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:ce(m.verifierVerdict)})]}),e.jsx("button",{type:"button",onClick:()=>window.api.schedule.resetJob(r.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:E,className:"bg-fg text-bg rounded-lg px-[18px] py-2 text-[13px] font-semibold whitespace-nowrap disabled:opacity-50",children:E?"Running…":"Queue job"})})]},r.slug)})})]}),e.jsx(Ft,{open:C,count:v.size,busy:k,onClose:()=>f(!1),onConfirm:F}),e.jsx(_t,{open:j,count:v.size,busy:k,onClose:()=>D(!1),onConfirm:te})]})}function Ft({open:t,count:s,busy:n,onClose:a,onConfirm:d}){return e.jsxs(Fe,{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:d,disabled:n||s===0,className:"px-2 py-1 text-xs border border-accent/60 text-accent rounded hover:bg-bg-hi disabled:opacity-40",children:n?"Archiving…":`Archive ${s}`})]})]})}function _t({open:t,count:s,busy:n,onClose:a,onConfirm:d}){const[i,c]=l.useState(""),[x,o]=l.useState(""),[u,b]=l.useState(null);l.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(x.trim()){const N=Number(x);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}d(h,v)}return e.jsxs(Fe,{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:x,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"})]})]}),u&&e.jsx("div",{className:"mt-2 text-[10px] text-red-300",children:u}),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 Ht(t){je(t),window.dispatchEvent(new CustomEvent("sm:navigate",{detail:"terminal"}))}function Ee(t){return t?t.slice(0,10):""}const qt=[{value:"all",label:"All"},{value:"completed",label:"Completed"},{value:"failed",label:"Failed"}];function Bt({scopeCwd:t=null}){const[s,n]=l.useState(null),[a,d]=l.useState(!0),[i,c]=l.useState(""),[x,o]=l.useState(""),[u,b]=l.useState(""),[w,h]=l.useState("all");l.useEffect(()=>{d(!0),window.api.schedule.getHistory().then(f=>n(f)).catch(f=>n({ok:!1,jobs:[],error:f instanceof Error?f.message:String(f)})).finally(()=>d(!1))},[]);const v=l.useMemo(()=>{if(!(s!=null&&s.jobs))return[];const f=new Set;for(const j of s.jobs){const D=be(j.cwd);D&&f.add(D)}return[...f].sort()},[s]),N=l.useMemo(()=>s!=null&&s.jobs?s.jobs.filter(f=>!(t&&f.cwd!==t||w!=="all"&&f.status!==w||i&&be(f.cwd)!==i||x&&Ee(f.finishedAt)<x||u&&Ee(f.finishedAt)>u)):[],[s,w,i,x,u,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||!!x||!!u;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(_e,{options:qt,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:x,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:u,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(Gt,{job:f},`${f.slug}-${f.finishedAt??""}`))]})})]})}function Gt({job:t}){const[s,n]=l.useState(!1),[a,d]=l.useState(!1),i=le(h=>h.sessions),c=l.useMemo(()=>ve(t,i),[t,i]),x=t.startedAt&&t.finishedAt?Date.parse(t.finishedAt)-Date.parse(t.startedAt):null,o=t.startedAt?new Date(t.startedAt).toLocaleString():"—",u=t.finishedAt?new Date(t.finishedAt).toLocaleString():"—",b=x!==null?re(x):"—",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(Le,{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:Ht})})]}),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(q,{label:"Status",children:[e.jsx(R,{k:"result",v:w}),e.jsx(R,{k:"state",v:t.status.replace("_"," ")}),t.verifierVerdict&&e.jsx(R,{k:"verifier",v:ce(t.verifierVerdict)})]}),e.jsxs(q,{label:"Timing",children:[e.jsx(R,{k:"started",v:o}),e.jsx(R,{k:"finished",v:u}),e.jsx(R,{k:"duration",v:b})]}),e.jsxs(q,{label:"Location",children:[e.jsx(R,{k:"group",v:t.parallelGroup!=null?String(t.parallelGroup):"—"}),e.jsx(R,{k:"slug",v:t.slug}),e.jsx(R,{k:"epic",v:c.label??c.epicId??"—",wrap:!0}),t.cwd&&e.jsx(R,{k:"cwd",v:t.cwd,wrap:!0})]}),e.jsx(q,{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(),d(!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(Oe,{runId:t.runId,slug:t.slug,title:t.title||t.slug,onClose:()=>d(!1)})]})}function Jt(t){return t?Object.values(t).reduce((s,n)=>s+(n??[]).reduce((a,d)=>{var i;return a+(((i=d.hooks)==null?void 0:i.length)??0)},0),0):0}function Ut(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 Vt({navigate:t}){const s=Ye(),n=se(g=>g.files),a=se(g=>g.loadJson),d=se(g=>g.loadText),i=se(g=>g.watchFile),c=se(g=>g.unwatchFile),x=s?We.resolve("user",s,null):null,o=s?Ke.resolve("user",s,null):null,u=s?`${s}/.claude.json`:null;l.useEffect(()=>{const g=[x,u].filter(Boolean);g.forEach(P=>{n[P]||a(P),i(P)});const A=[o].filter(Boolean);return A.forEach(P=>{n[P]||d(P),i(P)}),()=>{[...g,...A].forEach(P=>c(P))}},[x,o,u]);const[b,w]=l.useState(null);l.useEffect(()=>{if(!s)return;let g=!1;return(async()=>{const A=await st(`${s}/.claude/skills`);g||w(A.length)})(),()=>{g=!0}},[s]);const h=x?n[x]:null,v=u?n[u]:null,N=o?n[o]:null,C=l.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=l.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…",D=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?`${Ut(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:D??(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 zt({navigate:t}){const s=Xe(),[n,a]=l.useState(!1),[d,i]=l.useState(!1);l.useEffect(()=>{let x=!0;return Ze().then(o=>{x&&a(o.openToHomeOnLaunch===!0)}),()=>{x=!1}},[]);const c=async x=>{a(x),i(!0);try{await et({openToHomeOnLaunch:x})}catch{a(!x),L.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(Vt,{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},(x,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((x,o)=>e.jsxs("li",{className:"font-mono text-[12px] text-fg-dim",children:[x.owner," ",e.jsxs("span",{className:"text-fg-faint",children:["since ",new Date(x.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(nt,{checked:n,onChange:c,disabled:d,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 session"})]})]})]})]})}const Ie="sm.schedulerTab.subView",Qt=[{key:"queue",label:"Queue"},{key:"prds",label:"PRDs"},{key:"history",label:"History"}];function Yt(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 d=new Date(s).getTime()-n;return d>0?`Paused for rate limit — resumes in ${B(d)}`:"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 Kt({scopeCwd:t}){const{snapshot:s}=we(),[n,a]=l.useState(()=>Date.now());if(l.useEffect(()=>{const f=setInterval(()=>a(Date.now()),3e4);return()=>clearInterval(f)},[]),!s)return null;const d=(s.jobs??[]).filter(f=>!t||f.cwd===t),i=d.filter(f=>f.status==="pending").length,c=d.filter(f=>f.status==="running").length,x=d.filter(f=>f.status==="completed"&&(f.finishedAt?Yt(f.finishedAt,n):!1)).length,o=s.nextReset?new Date(s.nextReset).getTime():null,u=o?o>n?B(o-n):"soon":"—",b=z(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 ",u]}),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:x,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"," ",z(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 Xt({navigate:t}={}){var x;const[s,n]=l.useState(()=>{const o=localStorage.getItem(Ie);return o==="prds"||o==="history"||o==="machine"?o:"queue"}),a=De(o=>o.tabs),d=De(o=>o.activeTabId),i=((x=a.find(o=>o.id===d))==null?void 0:x.cwd)??null,c=i;return l.useEffect(()=>{i&&(le.getState().hydrate(i),le.getState().hydrateArchived(i))},[i]),l.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(tt,{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(Kt,{scopeCwd:c})}),e.jsxs("div",{className:"flex items-center gap-3 pb-0",children:[e.jsx(at,{options:Qt,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(mt,{scopeCwd:c,navigate:t}),s==="prds"&&e.jsx(Ot,{scopeCwd:c}),s==="history"&&e.jsx(Bt,{scopeCwd:c}),s==="machine"&&e.jsx("div",{className:"h-full overflow-y-auto px-9 py-6",children:e.jsx(zt,{navigate:t})})]})]})}const ns=l.memo(Xt);export{ns as Scheduler};
@@ -1 +1 @@
1
- import{_ as i,S as d}from"./index-DJ6xdB0r.js";function a({scopes:l,active:n,onChange:o,annotate:s}){return i.jsx("div",{className:"inline-flex rounded border border-line overflow-hidden",children:l.map(t=>{const r=d[t],e=s==null?void 0:s(t),c=t===n;return i.jsxs("button",{title:r.hint,onClick:()=>o(t),className:`px-2.5 py-1 text-xs flex items-center gap-1.5 transition-colors ${c?"bg-bg-hi text-fg":"bg-bg-elev text-fg-dim hover:text-fg hover:bg-bg-hi"}`,children:[i.jsx("span",{children:r.label}),(e==null?void 0:e.dirty)&&i.jsx("span",{className:"w-1 h-1 rounded-full bg-accent",title:"unsaved edits"}),e&&e.exists===!1&&!e.dirty&&i.jsx("span",{className:"w-1 h-1 rounded-full bg-fg-faint",title:"not yet created"})]},t)})})}export{a as S};
1
+ import{_ as i,S as d}from"./index-Cs_Lq9-w.js";function a({scopes:l,active:n,onChange:o,annotate:s}){return i.jsx("div",{className:"inline-flex rounded border border-line overflow-hidden",children:l.map(t=>{const r=d[t],e=s==null?void 0:s(t),c=t===n;return i.jsxs("button",{title:r.hint,onClick:()=>o(t),className:`px-2.5 py-1 text-xs flex items-center gap-1.5 transition-colors ${c?"bg-bg-hi text-fg":"bg-bg-elev text-fg-dim hover:text-fg hover:bg-bg-hi"}`,children:[i.jsx("span",{children:r.label}),(e==null?void 0:e.dirty)&&i.jsx("span",{className:"w-1 h-1 rounded-full bg-accent",title:"unsaved edits"}),e&&e.exists===!1&&!e.dirty&&i.jsx("span",{className:"w-1 h-1 rounded-full bg-fg-faint",title:"not yet created"})]},t)})})}export{a as S};