claude-code-session-manager 0.143.0 → 0.145.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 (128) hide show
  1. package/README.md +3 -1
  2. package/dist/assets/AppSettings-BR5b6oof.js +2 -0
  3. package/dist/assets/{History-DTttbvPb.js → History-B4U0mCdK.js} +2 -2
  4. package/dist/assets/HomeClaudeConfig-DQqG7lFE.js +5 -0
  5. package/dist/assets/{Panel-B_D4Bg7L.js → Panel-CwsOJ0nI.js} +1 -1
  6. package/dist/assets/ProjectClaudeConfig-BzRowu8x.js +26 -0
  7. package/dist/assets/Scheduler-dr7CNOcL.js +16 -0
  8. package/dist/assets/{SkillReferenceGraph-D1b2aiol.js → SkillReferenceGraph-CroBPY4C.js} +1 -1
  9. package/dist/assets/{Skills-cfV7sgk6.js → Skills-BiW2lCnD.js} +23 -23
  10. package/dist/assets/{TiptapBody-DVXtEIVy.js → TiptapBody-CYTkQiva.js} +27 -27
  11. package/dist/assets/{Toggle-CYajnSdx.js → Toggle-WFBYo8JI.js} +1 -1
  12. package/dist/assets/{VoiceButton-DJ4gGRuE.js → VoiceButton-DZu8dTpO.js} +1 -1
  13. package/dist/assets/{historyTotals-D3MoHY2U.js → historyTotals-B7KeXLSE.js} +1 -1
  14. package/dist/assets/{index-DVHIHoJf.css → index-BJ5TJvmz.css} +1 -1
  15. package/dist/assets/{index-CdTppjKR.js → index-hXRNm0UJ.js} +698 -697
  16. package/dist/index.html +2 -2
  17. package/dist-web/app.css +1 -1
  18. package/dist-web/app.js +442 -439
  19. package/package.json +4 -2
  20. package/plugins/session-manager-dev/skills/develop/SKILL.md +25 -19
  21. package/plugins/session-manager-dev/skills/maintaining-md-network/SKILL.md +16 -2
  22. package/plugins/session-manager-dev/skills/maintaining-md-network/weekly-consolidation.md +91 -0
  23. package/plugins/session-manager-dev/skills/send-feedback/SKILL.md +9 -6
  24. package/scripts/README.md +1 -1
  25. package/scripts/scheduler-mcp-server.cjs +77 -0
  26. package/src/main/adminRouteRegistry.cjs +6 -0
  27. package/src/main/agentLibrary.cjs +60 -11
  28. package/src/main/agentsIpc.cjs +19 -0
  29. package/src/main/build-info.json +4 -4
  30. package/src/main/chatRunner.cjs +139 -0
  31. package/src/main/config.cjs +12 -0
  32. package/src/main/health.cjs +59 -17
  33. package/src/main/index.cjs +6 -2
  34. package/src/main/ipcSchemas.cjs +55 -1
  35. package/src/main/lib/claude/agentArmory.cjs +128 -0
  36. package/src/main/lib/claude/agentModelResolve.cjs +3 -2
  37. package/src/main/lib/claude/agentSnapshot.cjs +24 -3
  38. package/src/main/lib/claude/builtinTools.cjs +110 -0
  39. package/src/main/lib/claude/environmentProfiles.cjs +1 -1
  40. package/src/main/lib/claude/headlessMcpServers.cjs +138 -0
  41. package/src/main/lib/claude/jobSandboxPolicy.cjs +8 -2
  42. package/src/main/lib/claude/personaToolScope.cjs +100 -14
  43. package/src/main/lib/demo-video-kit/resumableRun.cjs +21 -14
  44. package/src/main/lib/demo-video-kit/seedKit.cjs +2 -2
  45. package/src/main/lib/epic/epicDepsSync.cjs +66 -0
  46. package/src/main/lib/epic/epicOutsideRead.cjs +74 -2
  47. package/src/main/lib/epic/epicSettle.cjs +48 -4
  48. package/src/main/lib/epic/epicSpawnPlan.cjs +3 -1
  49. package/src/main/lib/epic/epicValidationHook.cjs +9 -1
  50. package/src/main/lib/epic/planReviewInput.cjs +125 -0
  51. package/src/main/lib/epic/restorableSessions.cjs +1 -0
  52. package/src/main/lib/epic/scriptStartedBy.cjs +86 -0
  53. package/src/main/lib/externalContract.cjs +12 -0
  54. package/src/main/lib/feedback-remote/createdProjects.cjs +291 -0
  55. package/src/main/lib/feedback-remote/crossProjectFeedback.cjs +108 -14
  56. package/src/main/lib/feedback-remote/localAdminHttp.cjs +5 -1
  57. package/src/main/lib/feedback-remote/macroAdminRoutes.cjs +24 -3
  58. package/src/main/lib/feedback-remote/pendingReplies.cjs +8 -4
  59. package/src/main/lib/feedback-remote/projectCreate.cjs +415 -0
  60. package/src/main/lib/feedback-remote/replyClaims.cjs +15 -6
  61. package/src/main/lib/feedback-remote/serviceMcpSession.cjs +35 -4
  62. package/src/main/lib/feedback-remote/serviceMcpTools.cjs +43 -2
  63. package/src/main/lib/feedback-remote/servicePairLocalRoutes.cjs +91 -0
  64. package/src/main/lib/feedback-remote/servicePairings.cjs +95 -7
  65. package/src/main/lib/feedback-remote/serviceStdioBridge.cjs +104 -1
  66. package/src/main/lib/git/gitWorktree.cjs +1 -1
  67. package/src/main/lib/git/worktreeDeps.cjs +9 -3
  68. package/src/main/lib/mcpToolCatalog.cjs +47 -7
  69. package/src/main/lib/mcpToolsProbe.cjs +19 -2
  70. package/src/main/lib/opsOwnership.cjs +2 -0
  71. package/src/main/lib/packs/packCatalog.cjs +98 -5
  72. package/src/main/lib/persona-macro/agentPersonaSchema.cjs +6 -0
  73. package/src/main/lib/persona-macro/builtinMacros.cjs +6 -4
  74. package/src/main/lib/persona-macro/personaFrontmatterSchema.cjs +9 -0
  75. package/src/main/lib/persona-macro/personaLoadout.cjs +58 -0
  76. package/src/main/lib/persona-macro/personaMerge.cjs +11 -3
  77. package/src/main/lib/persona-macro/personaUpgrade.cjs +96 -0
  78. package/src/main/lib/persona-macro/projectVideoToolCheck.cjs +1 -1
  79. package/src/main/lib/persona-macro/shippedPersonaSeeds.cjs +94 -0
  80. package/src/main/lib/prd/prdCreate.cjs +49 -5
  81. package/src/main/lib/prd/prdFrontmatter.cjs +5 -2
  82. package/src/main/lib/prd/prdMcpReachWarnings.cjs +46 -0
  83. package/src/main/lib/prd/prdSandboxWarnings.cjs +49 -0
  84. package/src/main/lib/process/peerChatSession.cjs +165 -0
  85. package/src/main/lib/project-pages/videoScriptPress.cjs +6 -0
  86. package/src/main/lib/project-pages/videoScriptRunRoute.cjs +24 -4
  87. package/src/main/lib/promptSessionSchema.cjs +2 -0
  88. package/src/main/lib/scheduler/baselineGate.cjs +31 -2
  89. package/src/main/lib/scheduler/planRecordHarvest.cjs +104 -12
  90. package/src/main/lib/scheduler/planReleaseRoute.cjs +110 -0
  91. package/src/main/lib/scheduler/planReviewSchema.cjs +182 -0
  92. package/src/main/lib/scheduler/planReviewStats.cjs +63 -0
  93. package/src/main/lib/scheduler/planReviewStore.cjs +150 -0
  94. package/src/main/lib/scheduler/reviewNotice.cjs +3 -1
  95. package/src/main/lib/scheduler/sandboxEnvironmentLimit.cjs +141 -0
  96. package/src/main/lib/scheduler/scheduleJobSchema.cjs +2 -0
  97. package/src/main/lib/scheduler/upgradeDrain.cjs +32 -5
  98. package/src/main/lib/scheduler/validatorVerdictSchema.cjs +12 -2
  99. package/src/main/lib/tasks/memoryConsolidation.cjs +118 -37
  100. package/src/main/lib/tasks/taskAdminRoutes.cjs +26 -14
  101. package/src/main/lib/tasks/taskRun.cjs +3 -1
  102. package/src/main/lib/tasks/weeklyConsolidationInputs.cjs +298 -0
  103. package/src/main/projectPages.cjs +22 -14
  104. package/src/main/pty.cjs +3 -0
  105. package/src/main/runVerify.cjs +80 -5
  106. package/src/main/scheduler/gitTreeGuard.cjs +6 -0
  107. package/src/main/scheduler/planReviewHold.cjs +146 -0
  108. package/src/main/scheduler/prdParser.cjs +1 -0
  109. package/src/main/scheduler/prdPaths.cjs +10 -1
  110. package/src/main/scheduler/reviewLadder.cjs +2 -0
  111. package/src/main/scheduler/utilizationHold.cjs +7 -2
  112. package/src/main/scheduler.cjs +692 -86
  113. package/src/main/seedAgentPersonas.cjs +11 -6
  114. package/src/main/seedStatus.cjs +1 -1
  115. package/src/main/templates/PRD_AUTHORING.md +17 -2
  116. package/src/main/webRemote.cjs +69 -7
  117. package/src/preload/api.d.ts +79 -1
  118. package/src/preload/apiSurface.json +39 -0
  119. package/src/preload/index.cjs +11 -0
  120. package/src/seed/agents/architect.md +28 -43
  121. package/src/seed/agents/dev-lead.md +3 -1
  122. package/src/seed/agents/md-network-curator.md +27 -0
  123. package/src/seed/agents/plan-reviewer.md +47 -0
  124. package/src/seed/agents/validator.md +2 -1
  125. package/dist/assets/AppSettings-BO4jDVGO.js +0 -2
  126. package/dist/assets/HomeClaudeConfig-DADP5bfn.js +0 -3
  127. package/dist/assets/ProjectClaudeConfig-DPnDJKcr.js +0 -26
  128. package/dist/assets/Scheduler-CNLjn90m.js +0 -16
@@ -0,0 +1,5 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./SkillReferenceGraph-CroBPY4C.js","./index-hXRNm0UJ.js","./monaco-editor-BsIlgG7c.js","./monaco-editor-Cu5D__1H.css","./index-BJ5TJvmz.css"])))=>i.map(i=>d[i]);
2
+ import{bn as pe,aT as d,bi as de,aE as Dt,C as Mt,aD as e,m as le,F as Rt,P as Ot,ak as It,a9 as Ne,a$ as Ie,ai as _t,bc as Z,bA as ut,bp as je,$ as re,bf as _e,bb as Ee,aa as Ft,aI as Se,bq as Fe,M as Ut,E as Bt,be as pt,A as qt,aW as Wt,ae as ke,bH as Gt,af as Kt,by as Vt,c as He,aJ as Ht,aQ as Jt,b9 as Yt,aB as Je,H as zt,L as Xt}from"./index-hXRNm0UJ.js";import{a as Qt,I as Zt,o as en,L as xt,s as tn,y as nn,z as sn,A as an,t as ln,x as Ye,c as on,b as $e,g as rn,r as dn,q as cn,G as ce,d as mt,f as ft,e as Oe,h as gt,E as un,w as pn,D as xn,J as mn,B as fn,v as gn,F as hn,l as bn,C as vn,S as jn,i as Nn,j as kn,H as yn,k as wn,M as Cn,P as Sn,m as $n,n as En,u as Pn}from"./Skills-BiW2lCnD.js";import{s as Ln}from"./Toggle-WFBYo8JI.js";import{_ as An}from"./monaco-editor-BsIlgG7c.js";import{P as Tn}from"./Panel-CwsOJ0nI.js";import"./TiptapBody-CYTkQiva.js";const Dn={skills:null,mcp:null,plugins:null},Mn={fileId:"claudeJson",scope:"user"};function Rn(t){return{skillsDir:`${t}/.claude/skills`,commandsDir:`${t}/.claude/commands`,claudeJson:`${t}/.claude.json`,pluginsManifest:`${t}/.claude/plugins/installed_plugins.json`}}async function On(t,n){const[s,a]=await Promise.all([Dt(t),window.api.config.listDir(n,{filesOnly:!0})]),l=s.errors[0];if(l)throw new Error(`${l.path}: ${l.error}`);if(!a.ok)throw new Error(`${n}: ${a.error??"failed to list directory"}`);return s.entries.length+a.entries.filter(o=>o.name.endsWith(".md")).length}async function In(){const{data:t}=await window.api.claudeConfig.read(Mn),n=t==null?void 0:t.mcpServers;return n&&typeof n=="object"&&!Array.isArray(n)?Object.keys(n).length:0}async function _n(){return(await window.api.plugins.list()).length}function Fn(){const t=pe(),[n,s]=d.useState(Dn),a=d.useRef({skills:0,mcp:0,plugins:0}),l=d.useCallback((h,w)=>{const u=a.current,E=++u[h],k=p=>{u[h]===E&&s(C=>C[h]===p?C:{...C,[h]:p})};w().then(k,()=>k(null))},[]),o=d.useMemo(()=>t?Rn(t):null,[t]),i=d.useCallback(()=>{o&&l("skills",()=>On(o.skillsDir,o.commandsDir))},[o,l]),x=d.useCallback(()=>l("mcp",In),[l]),j=d.useCallback(()=>l("plugins",_n),[l]);return d.useEffect(()=>{const h=a.current;return i(),()=>{h.skills++}},[i]),d.useEffect(()=>{const h=a.current;return x(),j(),()=>{h.mcp++,h.plugins++}},[x,j]),de(o?[o.skillsDir,o.commandsDir]:[],i),de(o?[o.claudeJson]:[],x),de(o?[o.pluginsManifest]:[],j),n}const Un="User · every project on this machine",Bn={title:"Nothing tells Claude how you like to work yet.",body:"Claude loads this file into every session it starts on this machine, in every project."};function qn(){const t=pe(),n=d.useMemo(()=>t?Mt.resolve("user",t,null):null,[t]),s=d.useMemo(()=>n?[{path:n,label:Un,eyebrow:"YOUR INSTRUCTIONS FOR EVERY PROJECT"}]:[],[n]);return!t||!n?e.jsx(le,{title:"loading…"}):e.jsx("div",{className:"flex flex-col h-full min-h-0","data-testid":"system-prompt",children:e.jsx(Qt,{home:t,scope:"user",roots:s,activeRoot:n,empty:Bn,testIdPrefix:"system-prompt",moreMenu:({importSelected:a})=>e.jsx(Zt,{path:n,disabled:a})})})}const Wn=d.memo(qn);function Gn({value:t,onChange:n,path:s,readOnly:a,theme:l="dark"}){const o=l==="paper";return e.jsx(Rt,{path:`file://${s}`,defaultLanguage:"markdown",value:t,onChange:i=>n(i??""),beforeMount:o?It:void 0,theme:o?Ot:"vs-dark",options:{minimap:{enabled:!1},fontSize:13,fontFamily:"JetBrains Mono, ui-monospace, Menlo, monospace",lineNumbers:"on",renderLineHighlight:"line",scrollBeyondLastLine:!1,tabSize:2,wordWrap:"on",readOnly:a,automaticLayout:!0}})}const Kn=d.lazy(()=>An(()=>import("./SkillReferenceGraph-CroBPY4C.js"),__vite__mapDeps([0,1,2,3,4]),import.meta.url).then(t=>({default:t.SkillReferenceGraph})));function Vn({pluginName:t,skills:n,onBack:s,initialSelectedId:a}){var w;const[l,o]=d.useState(a??((w=n[0])==null?void 0:w.id)??null),i=l?n.find(u=>u.id===l)??null:null,x=d.useMemo(()=>en(n),[n]),[j,h]=d.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:s,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:()=>h("list"),className:`px-2 py-0.5 text-xs ${j==="list"?"bg-bg-hi text-fg":"text-fg-dim hover:text-fg hover:bg-bg-hi"}`,children:"list"}),e.jsx("button",{onClick:()=>h("graph"),className:`px-2 py-0.5 text-xs ${j==="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:[n.length," ",n.length===1?"skill":"skills"," · ",x.length," ",x.length===1?"reference":"references"]})]}),e.jsx("div",{className:"flex-1 min-h-0 overflow-hidden",children:n.length===0?e.jsx(le,{title:"no skills in this plugin"}):j==="graph"?e.jsx(d.Suspense,{fallback:e.jsx("div",{className:"p-6 text-xs text-fg-faint",children:"Loading graph…"}),children:e.jsx(Kn,{skills:n,edges:x,selectedId:l,onSelect:o})}):e.jsx(xt,{sidebar:e.jsx("div",{className:"py-1",children:n.map(u=>e.jsxs("button",{onClick:()=>o(u.id),className:`w-full px-3 py-1 text-xs text-left ${l===u.id?"bg-bg-hi text-fg":"text-fg-dim hover:text-fg hover:bg-bg-hi"}`,children:[e.jsx("div",{className:"truncate",children:u.name??u.id}),u.description?e.jsx("div",{className:"truncate text-fg-faint",children:u.description}):null]},u.id))}),detail:i?e.jsx("div",{className:"h-full min-h-0",children:e.jsx(Gn,{path:i.path,value:i.body,onChange:()=>{},readOnly:!0})}):e.jsx(le,{title:"select a skill"})})})]})}function Hn({row:t,busy:n,onUninstall:s}){const[a,l]=d.useState(!1),[o,i]=d.useState(!1),x=d.useRef(null),j=d.useId(),h=d.useCallback(()=>{l(!1),i(!1)},[]);d.useEffect(()=>{if(!a)return;const p=O=>{var L;(L=x.current)!=null&&L.contains(O.target)||h()},C=O=>{O.key==="Escape"&&h()};return window.addEventListener("mousedown",p),window.addEventListener("keydown",C),()=>{window.removeEventListener("mousedown",p),window.removeEventListener("keydown",C)}},[a,h]);const w=()=>{h(),Ie(t.path)},u=async()=>{h(),await _t(t.path)||Z.error(`Could not copy ${t.path} to the clipboard`)},E=()=>{h(),s(t)},k="px-2.5 py-[7px] rounded-[5px] text-left whitespace-nowrap hover:bg-bg-elev";return e.jsxs("div",{ref:x,className:"relative self-start",children:[e.jsx("button",{type:"button","data-testid":"plugin-menu","aria-label":`Actions for ${t.name}`,"aria-haspopup":"menu","aria-expanded":a,"aria-controls":a?j:void 0,onClick:()=>a?h():l(!0),className:"w-[30px] h-7 inline-flex items-center justify-center bg-bg border border-line rounded-md text-fg-dim hover:border-rule",children:e.jsxs("svg",{"aria-hidden":"true",width:"14",height:"14",viewBox:"0 0 24 24",fill:"currentColor",children:[e.jsx("circle",{cx:"5",cy:"12",r:"1.8"}),e.jsx("circle",{cx:"12",cy:"12",r:"1.8"}),e.jsx("circle",{cx:"19",cy:"12",r:"1.8"})]})}),a&&e.jsx("div",{id:j,role:"menu","aria-label":`Actions for ${t.name}`,className:`absolute ${Ne.dialog} right-0 top-[34px] w-[210px] p-[5px] flex flex-col bg-bg-hi border border-line rounded-lg shadow-lg text-[12.5px] text-fg`,children:o?e.jsxs("div",{className:"flex flex-col gap-2 px-2.5 py-[7px]",children:[e.jsxs("span",{className:"font-medium",children:["Uninstall ",t.name,"?"]}),e.jsxs("div",{className:"flex items-center justify-end gap-1.5",children:[e.jsx("button",{type:"button",role:"menuitem","data-testid":"plugin-uninstall",disabled:n,onClick:E,className:"h-6 px-2.5 rounded-[5px] bg-delta-bad text-bg-hi font-medium hover:bg-delta-bad/90 disabled:opacity-40",children:"Confirm"}),e.jsx("button",{type:"button",role:"menuitem",onClick:()=>i(!1),className:"h-6 px-2.5 rounded-[5px] border border-line text-fg-dim hover:bg-bg-elev",children:"Cancel"})]})]}):e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",role:"menuitem",onClick:w,className:k,children:"Reveal in File Explorer"}),e.jsx("button",{type:"button",role:"menuitem",onClick:()=>void u(),className:k,children:"Copy path"}),e.jsx("div",{role:"separator",className:"h-px mx-1.5 my-1 bg-line"}),e.jsxs("button",{type:"button",role:"menuitem",disabled:!t.marketplace||n,title:t.marketplace?void 0:"No marketplace is recorded for this install",onClick:()=>i(!0),className:`${k} font-medium text-delta-bad hover:bg-delta-bad/10 disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-transparent`,children:["Uninstall ",t.name]})]})})]})}function ht({name:t,enabled:n,disabled:s,onToggle:a,testId:l="plugin-enabled-switch"}){return e.jsx("button",{type:"button",role:"switch","aria-checked":n,"aria-label":`${n?"Disable":"Enable"} ${t}`,"data-testid":l,disabled:s,onClick:o=>{o.stopPropagation(),a()},onKeyDown:o=>o.stopPropagation(),className:`relative shrink-0 w-[30px] h-[18px] rounded-full transition-colors align-middle disabled:opacity-50 disabled:cursor-not-allowed focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent ${n?"bg-accent":"bg-rule"}`,children:e.jsx("span",{"aria-hidden":"true",className:`absolute top-0.5 w-3.5 h-3.5 rounded-full bg-bg-hi shadow transition-[left] ${n?"left-[14px]":"left-0.5"}`})})}const Jn="Saved — matches settings.json › enabledPlugins",Yn=250,zn=["hooks/hooks.json",".mcp.json","agents","skills","commands",".claude-plugin/plugin.json"],Xn=(t,n,s)=>`${t} ${t===1?n:s}`;function Qn(t){var s;const n=["PLUGIN"];return t.marketplace&&n.push(t.marketplace.toUpperCase()),(s=t.manifest)!=null&&s.version&&n.push(`V${t.manifest.version.toUpperCase()}`),n.push(`${(t.scope??"user").toUpperCase()} SCOPE`),n.join(" · ")}function Zn(t,n){const s=o=>{const x=o.trim().replace(/^v/i,"").split(/[-+]/)[0].split(".");return x.every(j=>/^\d+$/.test(j))?x.map(Number):null},a=s(t),l=s(n);if(!a||!l)return null;for(let o=0;o<Math.max(a.length,l.length);o++){const i=(a[o]??0)-(l[o]??0);if(i!==0)return Math.sign(i)}return 0}function es(t,n){if(!t||!n)return null;const s=Zn(n,t);return s===null?n.trim()===t.trim()?"up-to-date":"update-available":s>0?"update-available":"up-to-date"}const ts=t=>t.key&&t.key.includes("@")?t.key.slice(0,t.key.lastIndexOf("@")):t.name,be=t=>!!t&&typeof t=="object"&&!Array.isArray(t);function ze(t,n){if(!be(t))return[];const s=be(t.hooks)?t.hooks:t,a=[];for(const[l,o]of Object.entries(s))Array.isArray(o)&&o.forEach((i,x)=>{if(!be(i)||!Array.isArray(i.hooks))return;const j=typeof i.matcher=="string"&&i.matcher?` · ${i.matcher}`:"";i.hooks.forEach((h,w)=>{const u=be(h)?typeof h.command=="string"?h.command:typeof h.prompt=="string"?h.prompt:null:null;a.push({id:`${n}:${l}:${x}:${w}`,name:`${l}${j}`,description:u})})});return a}async function ns(t,n){const s=n==null?void 0:n.hooks,a=typeof s=="string"?[s]:Array.isArray(s)?s.filter(i=>typeof i=="string"):[],l=new Set;for(const i of a)i.startsWith("/")||i.split("/").includes("..")||l.add(`${t}/${i.replace(/^\.\//,"")}`);l.add(`${t}/hooks/hooks.json`);const o=await Promise.all([...l].map(async i=>{const x=await window.api.config.readJson(i);return{p:i,data:x.exists&&!x.parseError?x.data:null}}));return[...be(s)?ze(s,"manifest"):[],...o.flatMap(({p:i,data:x})=>ze(x,i))]}function ss({row:t,home:n,busy:s,onToggle:a,onUninstall:l,onJump:o}){var P,se,Q;const[i,x]=d.useState([]),[j,h]=d.useState([]),[w,u]=d.useState(null),[E,k]=d.useState(!0),[p,C]=d.useState([]),O=d.useRef(0),[L,b]=d.useState(null),D=t.marketplace,y=ts(t);d.useEffect(()=>{if(b(null),!n||!D)return;let m=!0;return tn(n,{quiet:!0}).then(T=>{if(!m)return;const _=T.find(V=>V.marketplace===D&&V.name===y);b((_==null?void 0:_.version)??null)}),()=>{m=!1}},[n,D,y]);const S=d.useCallback(async()=>{const m=++O.current;try{const{manifest:T}=await nn(t.path),[_,V,te]=await Promise.all([sn(t.path),an(t.path,T),ns(t.path,T)]),c=_?await ln(_):[],[g,M]=await Promise.all([Ye(V.agentFiles),Ye(V.commandFiles)]),q=await Promise.all([...new Set([...zn.map(r=>`${t.path}/${r}`),...V.sourcePaths])].map(async r=>await window.api.config.exists(r)?r:null));if(m!==O.current)return;const ne=(r,R)=>({kind:r,id:R.id,name:r==="command"?`/${R.name??R.id}`:R.name??R.id,description:R.description});x([...M.map(r=>ne("command",r)),...c.map(r=>({kind:"skill",id:r.id,name:r.name??r.id,description:r.description,skill:r})),...g.map(r=>ne("agent",r)),...te.map(r=>({kind:"hook",...r})),...V.mcpServers.map(r=>({kind:"mcp",id:r.id,name:r.name,description:r.description}))]),h(c);const J=q.filter(r=>r!==null);C(r=>r.join("\0")===J.join("\0")?r:J)}catch(T){if(m!==O.current)return;Z.error(`Failed to load plugin contents: ${T instanceof Error?T.message:String(T)}`)}finally{m===O.current&&k(!1)}},[t.path]);d.useEffect(()=>(k(!0),S(),()=>{O.current+=1}),[S]);const N=d.useRef(null),A=d.useRef(!1),W=d.useRef(!1),f=d.useCallback(async()=>{if(A.current){W.current=!0;return}A.current=!0;try{do W.current=!1,await S();while(W.current)}finally{A.current=!1}},[S]),F=d.useCallback(()=>{N.current&&clearTimeout(N.current),N.current=setTimeout(()=>{N.current=null,f()},Yn)},[f]);if(d.useEffect(()=>()=>{N.current&&clearTimeout(N.current)},[]),de(p,F,{depth:0}),w)return e.jsx(Vn,{pluginName:((P=t.manifest)==null?void 0:P.name)??t.name,skills:j,initialSelectedId:w.id,onBack:()=>u(null)},w.id);const z=t.enabled===!0,B=((se=t.manifest)==null?void 0:se.version)??null,ee=es(B,L),X=(Q=t.manifest)==null?void 0:Q.description,I=m=>i.filter(T=>T.kind===m).length,K=[["command","COMMAND","COMMANDS"],["skill","SKILL","SKILLS"],["agent","AGENT","AGENTS"],["hook","HOOK","HOOKS"],["mcp","MCP SERVER","MCP SERVERS"]].filter(([m])=>I(m)>0).map(([m,T,_])=>Xn(I(m),T,_)).join(" · "),$=I("skill")+I("command")>0;return e.jsxs("div",{"data-testid":"plugin-detail",className:"flex flex-col min-h-0",children:[e.jsx(on,{eyebrow:Qn(t),title:t.name,actions:e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"flex items-center gap-2 text-[13.5px] text-fg-dim",children:[e.jsx(ht,{name:t.name,enabled:z,disabled:!t.key||s,onToggle:()=>a(t),testId:"plugin-detail-switch"}),"Enabled"]}),ee&&e.jsx("span",{"data-testid":"plugin-update-state","data-state":ee,title:`Installed v${B} · ${t.marketplace} lists v${L}`,className:`h-7 inline-flex items-center px-3 bg-bg border rounded-md text-[13px] font-semibold ${ee==="update-available"?"border-accent text-accent":"border-line text-fg-dim"}`,children:ee==="update-available"?"Update available":"Up to date"}),e.jsx(Hn,{row:t,busy:s,onUninstall:l})]})}),e.jsxs("div",{className:"px-9 py-6 flex flex-col gap-4 max-w-[1100px]",children:[e.jsx($e,{label:"DESCRIPTION",labelNote:"FROM THE PLUGIN'S MANIFEST",children:e.jsx("span",{"data-testid":"plugin-description",className:X?void 0:"text-fg-faint",children:X??(t.hasManifest?"The manifest has no description.":"This plugin has no manifest.")})}),e.jsx($e,{label:"WHAT IT ADDS",labelNote:E?void 0:K||"NOTHING",action:$?e.jsx("button",{type:"button","data-testid":"plugin-open-in-skills",onClick:()=>o("skills"),className:"shrink-0 text-[13px] font-semibold text-accent hover:underline",children:"Open in Skills →"}):void 0,children:E?e.jsx(le,{title:"scanning…"}):i.length===0?e.jsx("span",{className:"text-fg-faint",children:t.error?`Inspection failed: ${t.error}`:"No commands, skills, agents or hooks."}):e.jsx("ul",{"data-testid":"plugin-adds",className:"-mx-[18px] mt-2 border-t border-line",children:i.map(m=>{const T=e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"w-[200px] shrink-0 truncate font-mono text-[14px] font-semibold text-fg",title:m.name,children:m.name}),e.jsx("span",{className:"flex-1 min-w-0 truncate text-[13.5px] text-fg-dim",title:m.description??void 0,children:m.description??""})]}),_="w-full flex items-baseline gap-4 px-[18px] py-3 text-left";return e.jsx("li",{"data-testid":`plugin-adds-${m.kind}`,className:"border-b border-line last:border-b-0",children:m.skill?e.jsx("button",{type:"button",onClick:()=>u(m.skill),className:`${_} hover:bg-bg-elev`,children:T}):e.jsx("div",{className:_,children:T})},`${m.kind}:${m.id}`)})})}),e.jsx($e,{label:"INSTALLED AT",action:e.jsx("button",{type:"button","data-testid":"plugin-reveal",onClick:()=>Ie(t.path),className:"shrink-0 text-[13px] text-fg-dim hover:text-fg",children:"Reveal"}),children:e.jsx("span",{"data-testid":"plugin-install-path",title:t.path,className:"block truncate font-mono text-[14px]",children:Ln(t.path,n)})}),e.jsx(rn,{text:Jn})]})]})}const as="~/.claude/plugins/installed_plugins.json",ls="On/off is saved in settings.json › enabledPlugins",is=t=>je.getState().openPanel("extensions",t);function os(t,n){var s,a;return[t.name,(s=t.manifest)==null?void 0:s.name,t.marketplace,(a=t.manifest)==null?void 0:a.description].some(l=>typeof l=="string"&&l.toLowerCase().includes(n))}const xe=(t,n,s)=>`${t} ${t===1?n:s}`;function rs(t){const n=un(t),s=[];if(t.marketplace&&s.push(t.marketplace),t.error)s.push("inspection failed");else{const a=[n.commands>0?xe(n.commands,"command","commands"):null,n.skills>0?xe(n.skills,"skill","skills"):null,n.agents>0?xe(n.agents,"agent","agents"):null,n.hooks>0?xe(n.hooks,"hook","hooks"):null,n.mcpServers>0?xe(n.mcpServers,"MCP server","MCP servers"):null].filter(l=>l!==null);s.push(...a.length>0?a:["empty"])}return t.scope&&t.scope!=="user"&&s.push(`${t.scope} scope`),s.join(" · ")}function ds({onAdd:t,onJump:n}){const s=pe(),[a,l]=d.useState([]),[o,i]=d.useState(!0),[x,j]=d.useState(null),[h,w]=d.useState(null),[u,E]=d.useState(""),[k,p]=d.useState(null),[C,O]=d.useState(new Set),L=ut(m=>m.show),[b,D]=d.useState(null);d.useEffect(()=>{var T,_;let m=!1;return(_=(T=window.api.app).seedStatus)==null||_.call(T).then(V=>{m||p(V)}).catch(()=>{}),()=>{m=!0}},[]);const y=d.useRef(0),S=d.useRef(!1),N=d.useCallback(async()=>{var te,c;const m=++y.current;if(!s)return;S.current||i(!0);const T=`${s}/.claude/plugins/installed_plugins.json`;let _=[],V=null;try{const g=await window.api.config.readJson(T);if(g.exists&&g.parseError)V=`could not parse installed_plugins.json${g.error?`: ${g.error}`:""}`;else if(g.exists&&g.data&&typeof g.data=="object"){const M=g.data,q=[];for(const[J,r]of Object.entries(M.plugins??{})){if(!Array.isArray(r))continue;const[R,H]=J.split("@");for(const Y of r)Y!=null&&Y.installPath&&q.push({name:R,marketplace:H,entry:Y})}let ne=new Map;try{const J=await((c=(te=window.api.plugins)==null?void 0:te.list)==null?void 0:c.call(te))??[];ne=new Map(J.map(r=>[r.key,r.enabled]))}catch{}_=await xs(q,ps,async({name:J,marketplace:r,entry:R})=>{var ae;const H={name:J,path:R.installPath,isDirectory:!0,isFile:!1,mtimeMs:0,size:0};let Y;try{Y=await dn(H)}catch(ue){Y=cn(H,ue instanceof Error?ue.message:String(ue))}return(ae=Y.manifest)!=null&&ae.version||(Y.manifest={...Y.manifest??{},version:R.version}),Y.marketplace=r,Y.scope=R.scope,Y.key=r?`${J}@${r}`:J,Y.enabled=ne.get(Y.key)===!0,Y})}}catch(g){V=`could not read installed_plugins.json: ${g instanceof Error?g.message:String(g)}`}y.current===m&&(j(V),V?Z.error(`Plugins: ${V}`):(_.sort((g,M)=>g.name.localeCompare(M.name)),S.current=_.length>0,l(_)),i(!1))},[s]);d.useEffect(()=>{N()},[N]);const A=ce(m=>m.tab),W=ce(m=>m.id),f=ce(m=>m.clear);d.useEffect(()=>{if(A!=="plugins"||!W||o)return;const m=W.startsWith("plugins:")?W.slice(8):null,T=m?a.find(_=>_.key===m):void 0;T&&(E(""),w(T.path)),f()},[A,W,o,a,f]),d.useEffect(()=>()=>{y.current+=1},[]),de(s?[`${s}/.claude/plugins/installed_plugins.json`]:[],N);const F=async m=>{if(m.key){D(m.key);try{const T=await window.api.plugins.setEnabled({key:m.key,enabled:!m.enabled});T.ok||L("error",`Could not ${m.enabled?"disable":"enable"} ${m.name}: ${T.error??"unknown error"}`)}catch(T){L("error",`Could not update ${m.name}: ${T instanceof Error?T.message:String(T)}`)}finally{D(null),await N()}}},z=async m=>{if(m.marketplace){D(m.key??m.name);try{const T=await window.api.plugins.uninstall({slug:m.name,marketplaceName:m.marketplace});T.ok||L("error",`Uninstall ${m.name} failed: ${T.error??`exit ${T.exitCode}`}`)}catch(T){L("error",`Uninstall ${m.name} failed: ${T instanceof Error?T.message:String(T)}`)}finally{D(null),await N()}}},B=d.useMemo(()=>k?Object.keys(k).filter(m=>(k[m].status==="exhausted"||k[m].status==="failed")&&!C.has(m)):[],[k,C]),ee=d.useMemo(()=>a.filter(m=>m.enabled===!0).length,[a]),X=u.trim().toLowerCase(),I=d.useMemo(()=>X?a.filter(m=>os(m,X)):a,[a,X]),G=I.find(m=>m.path===h)??I[0]??null,K=d.useCallback(()=>t==null?void 0:t(),[t]),$=n??is,P=m=>b!==null&&b===(m.key??m.name),se=e.jsxs(e.Fragment,{children:[e.jsx(mt,{eyebrow:"PLUGINS",badge:`${ee} on`,path:as,note:ls}),e.jsx(ft,{filter:u,onFilterChange:E,placeholder:"Filter",primaryLabel:"+ Add",onPrimary:K}),o&&a.length===0||x&&a.length===0?null:a.length===0?e.jsxs("div",{"data-testid":"plugins-empty",className:"flex flex-col gap-1 px-3 py-3 border border-dashed border-rule rounded-xl text-[13px] text-fg-dim",children:[e.jsx("span",{className:"font-semibold text-fg",children:"No plugins installed"}),e.jsxs("span",{children:["Use + Add, or run ",e.jsx("code",{className:"font-mono text-xs",children:"claude plugin install"}),"."]})]}):I.length===0?e.jsxs("p",{className:"px-1 text-[13px] text-fg-dim",children:["No plugins match “",u.trim(),"”."]}):e.jsx("div",{role:"listbox","aria-label":"Installed plugins",className:"flex flex-col gap-1",children:I.map(m=>e.jsx(Oe,{title:m.name,meta:rs(m),muted:m.enabled!==!0,selected:(G==null?void 0:G.path)===m.path,onSelect:()=>w(m.path),trailing:e.jsx(ht,{name:m.name,enabled:m.enabled===!0,disabled:!m.key||P(m),onToggle:()=>void F(m)})},m.path))})]}),Q=G?e.jsx(ss,{row:G,home:s,busy:P(G),onToggle:m=>void F(m),onUninstall:m=>void z(m),onJump:$},G.path):o?e.jsx(le,{title:"scanning plugins…"}):x?null:a.length===0?e.jsx(le,{title:"No plugins installed",hint:"+ Add browses the plugin catalog."}):e.jsx(le,{title:"No plugin matches the filter"});return e.jsxs("div",{className:"flex flex-col h-full min-h-0",children:[B.length>0?e.jsx(us,{seeders:B,seedStatus:k,onDismiss:m=>O(T=>new Set(T).add(m)),onOpenLibrary:K}):null,x?e.jsxs("div",{role:"alert",className:"shrink-0 px-3 py-2 border-b border-line bg-red-950/20 text-xs text-red-300",children:[x,a.length>0?" — showing the last known list":null]}):null,e.jsx(gt,{list:se,detail:Q})]})}const cs=d.memo(ds),Le={"dev-plugin":"session-manager-dev plugin","scheduler-mcp":"Scheduler MCP server","agent-personas":"Agent personas (Architect, Dev Lead)"};function us({seeders:t,seedStatus:n,onDismiss:s,onOpenLibrary:a}){return e.jsx("div",{className:"shrink-0 flex flex-col gap-1.5 px-3 py-2 border-b border-line bg-yellow-950/20",children:t.map(l=>e.jsxs("div",{className:"flex items-start gap-2 text-xs text-yellow-300",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"font-medium",children:n[l].status==="failed"?`${Le[l]} setup failed — it will retry on next launch. To fix it now:`:`${Le[l]} setup failed after retrying — manual fix needed`}),l==="dev-plugin"?e.jsxs("div",{className:"text-yellow-400/80 mt-0.5",children:["Click ",e.jsx("button",{onClick:a,className:"underline hover:no-underline",children:"here"}),' to open the Library tab, then click Install next to "session-manager-dev".']}):e.jsx("div",{className:"text-yellow-400/80 mt-0.5 font-mono",children:n[l].fix})]}),e.jsx("button",{onClick:()=>s(l),className:"shrink-0 text-yellow-400/70 hover:text-yellow-300","aria-label":`Dismiss ${Le[l]} warning`,children:"✕"})]},l))})}const ps=4;async function xs(t,n,s){const a=new Array(t.length);let l=0;const o=Array.from({length:Math.min(n,t.length)},async()=>{for(;l<t.length;){const i=l++;a[i]=await s(t[i])}});return await Promise.all(o),a}function bt(t,n){const s=pe();de([s?`${s}/.claude/agents`:null,...t.map(a=>`${a}/.claude/agents`)],n)}function ms({onOpenPersona:t}){const[n,s]=d.useState(re[0].tag),{personas:a,refresh:l}=_e(i=>Z.error(i.message||"failed to load agent personas"));bt([],()=>{l()});const o=re.find(i=>i.tag===n)??null;return e.jsx(Tn,{toolbar:e.jsxs("span",{className:"text-fg-faint",children:[re.length," tag",re.length===1?"":"s"]}),children:e.jsx(xt,{sidebar:e.jsx("div",{className:"py-1",children:re.map(i=>{const x=Ee(i.tag),j=n===i.tag,h=(a==null?void 0:a.filter(w=>w.tags.includes(i.tag)).length)??0;return e.jsxs("button",{onClick:()=>{s(i.tag)},className:`w-full text-left px-3 py-1.5 text-xs flex items-center gap-2 border-l-2 ${j?"bg-bg-hi text-fg border-accent":"text-fg-dim hover:text-fg hover:bg-bg-hi border-transparent"}`,children:[e.jsxs("span",{className:`px-1.5 py-0.5 rounded text-[10px] font-mono font-semibold ${x.bg} ${x.text} ${x.border?"border border-current/30":""}`,children:["#",i.tag]}),e.jsx("span",{className:"truncate",children:i.label}),h>0&&e.jsx("span",{className:"ml-auto text-[10.5px] text-fg-faint font-mono shrink-0",children:h})]},i.tag)})}),detail:o?e.jsx(gs,{entry:o,personas:a,onOpenPersona:t}):e.jsx(le,{title:"select a tag"})})})}const fs=d.memo(ms);function gs({entry:t,personas:n,onOpenPersona:s}){const a=Ee(t.tag),l=Ft(t.tag),o=(n==null?void 0:n.filter(i=>i.tags.includes(t.tag)))??[];return e.jsxs("div",{className:"p-4 space-y-4 max-w-3xl",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsxs("span",{className:`px-2 py-1 rounded text-xs font-mono font-semibold ${a.bg} ${a.text} ${a.border?"border border-current/30":""}`,children:["#",t.tag]}),e.jsx("span",{className:"text-sm font-semibold text-fg",children:t.label})]}),e.jsx("div",{className:"text-xs text-fg-dim leading-relaxed",children:t.description}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[10.5px] uppercase tracking-wide text-fg-faint mb-1.5 font-mono",children:"/develop eagerness"}),e.jsx("span",{className:"px-1.5 py-0.5 text-[10px] rounded border border-line text-fg-dim font-mono",children:t.developEagerness})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[10.5px] uppercase tracking-wide text-fg-faint mb-1.5 font-mono",children:"develops via"}),e.jsx("span",{className:"px-1.5 py-0.5 text-[10px] rounded border border-line text-fg-dim font-mono",children:t.developsVia})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[10.5px] uppercase tracking-wide text-fg-faint mb-1.5 font-mono",children:"agents carrying this tag"}),n===null?e.jsx("div",{className:"text-xs text-fg-faint italic",children:"loading…"}):e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[o.map(i=>e.jsx("button",{onClick:()=>s==null?void 0:s(i.name),title:`Open ${i.name} in Personas`,className:"inline-flex items-center bg-bg-elev border border-line rounded px-2 py-0.5 text-[11px] font-mono text-fg-dim hover:text-fg hover:bg-bg-hi",children:i.name},i.name)),o.length===0&&e.jsx("span",{className:"text-xs text-fg-faint italic mr-1",children:"no agent carries this tag yet."})]})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[10.5px] uppercase tracking-wide text-fg-faint mb-1.5 font-mono",children:"opening framing — sent before the human's goal"}),e.jsx("pre",{className:"text-xs text-fg-dim whitespace-pre-wrap bg-bg-elev border border-line rounded p-3 leading-relaxed font-sans",children:l.initialPromptTemplate})]})]})}const hs=t=>{const[n,s]=t.split(".");return Number(n)+(s?Number(s)/100:0)};function bs(t){const n=/Effort is supported on ([^.]*?)(?:, with|\.|$)/.exec(t);if(!n)return[];const s=[];for(const a of n[1].split(/,\s*|\s+and\s+/)){const l=/^(\w+)\s+(\d+(?:\.\d+)?)$/.exec(a.trim());l&&s.push({family:l[1].toLowerCase(),version:hs(l[2])})}return s}var dt,ct;const vs=bs(String(((ct=(dt=pn.properties)==null?void 0:dt.effortLevel)==null?void 0:ct.description)??""));function js(t,n){const s=new RegExp(`${n}-(\\d+)(?:-(\\d{1,2})(?!\\d))?`,"i").exec(t);if(s)return Number(s[1])+(s[2]?Number(s[2])/100:0);const a=new RegExp(`claude-(\\d+)(?:-(\\d{1,2}))?-${n}`,"i").exec(t);return a?Number(a[1])+(a[2]?Number(a[2])/100:0):null}function Ns(t,n=vs){if(!t||t==="inherit"||n.length===0)return null;const s=Se(t);if(!s)return null;const a=n.filter(o=>o.family===s);if(a.length===0)return!1;const l=js(t,s);return l===null?null:l>=Math.min(...a.map(o=>o.version))}const ks=["Read","Grep","Glob","Bash","Write","Edit","WebFetch","WebSearch","Task"],ys=["","red","orange","yellow","green","cyan","blue","purple","pink"],Pe={red:"#c0392b",orange:"#b85c34",yellow:"#c9a227",green:"#6f7d52",cyan:"#3f8f8a",blue:"#4a6fa5",purple:"#7a6a8a",pink:"#b45a80"},ws=["undecided","bare","equipped","unbound"];function Cs(t){return!t.tools||t.loadout?t:{...t,loadout:t.tools.length===0?"bare":"equipped"}}function ve(t){return{name:t.name,description:t.description??"",tools:t.tools,model:t.model??"inherit",effort:t.effort??"inherit",color:t.color??"",tags:t.tags,body:t.body,agentCli:t.agentCli??"claude",agentCliModel:t.agentCliModel??"",loadout:ws.includes(String(t.loadout))?t.loadout:"undecided",...Ss(t)}}function Xe(t){return t.loadout==="undecided"?void 0:t.loadout}function Ss(t){const n=t;return{...n.mcpServers?{mcpServers:n.mcpServers}:{},...n.packs?{packs:n.packs}:{},...n.environment?{environment:n.environment}:{}}}const Qe={name:"new-agent",description:"",tools:["Read","Grep"],model:"inherit",effort:"inherit",color:"",tags:[],body:"",agentCli:"claude",agentCliModel:"",loadout:"equipped"};function vt(t){return[...t.fields.filter(n=>n!=="name"),...t.bodyOverridden?["full body"]:[]]}const $s=["tools","mcpServers","packs"],Ae=t=>t.split(",").map(n=>n.trim()).filter(n=>n&&n!=="[]");function Es(t){const n=t.values??{},s={};if(t.fields.includes("model")&&n.model&&(s.model=n.model),t.fields.includes("effort")&&n.effort&&(s.effort=n.effort),t.fields.includes("environment")&&n.environment&&(s.environment=n.environment),t.fields.includes("tools")&&n.tools!==void 0){const a=Ae(String(n.tools));s.tools=a}return t.fields.includes("mcpServers")&&n.mcpServers!==void 0&&(s.mcpServers=Ae(String(n.mcpServers))),t.fields.includes("packs")&&n.packs!==void 0&&(s.packs=Ae(String(n.packs))),s}function Ps(t,n){const s={...t};for(const a of["model","effort","environment"]){if(!(a in n))continue;const l=n[a];!l||l==="inherit"?delete s[a]:s[a]=l}n.tools&&(s.tools=n.tools);for(const a of["mcpServers","packs"]){if(!(a in n))continue;const l=n[a];l?s[a]=l:delete s[a]}return s}function Ls(t,n,s="project"){const a=[];for(const l of["model","effort","environment"]){const o=n[l];o!==void 0&&a.push({label:l,keys:[l],lines:[`~ ${t[l]??"default"} → ${o}`]})}for(const l of $s){const o=n[l];if(o===void 0)continue;const i=t[l]??[];if(o.length===0&&(t[l]===void 0||i.length>0)){a.push({label:l,keys:[l],lines:[`${l}: none in ${s}`,...i.map(j=>`− ${j}`)]});continue}const x=[...o.filter(j=>!i.includes(j)).map(j=>`+ ${j}`),...i.filter(j=>!o.includes(j)).map(j=>`− ${j}`)];a.push({label:l,keys:[l],lines:x.length?x:["same as global"]})}return a}function As({items:t}){const[n,s]=d.useState(!1),a=d.useRef(null),l=d.useRef(null),o=d.useId();return d.useEffect(()=>{if(!n)return;const i=j=>{var w,u;const h=j.target;(w=a.current)!=null&&w.contains(h)||(u=l.current)!=null&&u.contains(h)||s(!1)},x=j=>{j.key==="Escape"&&s(!1)};return window.addEventListener("mousedown",i),window.addEventListener("keydown",x),()=>{window.removeEventListener("mousedown",i),window.removeEventListener("keydown",x)}},[n]),e.jsxs("div",{className:"relative",children:[e.jsx("button",{ref:a,type:"button","data-testid":"agent-detail-more","aria-label":"More actions","aria-haspopup":"menu","aria-expanded":n,"aria-controls":n?o:void 0,onClick:()=>s(i=>!i),className:"h-9 w-9 inline-flex items-center justify-center rounded-[10px] bg-bg-hi border border-line text-fg-dim hover:text-fg hover:border-rule",children:"⋯"}),n&&e.jsx("div",{ref:l,id:o,role:"menu","aria-label":"More actions","data-testid":"agent-detail-more-menu",className:`absolute ${Ne.dialog} right-0 top-[42px] min-w-[200px] p-[5px] flex flex-col bg-bg-hi border border-line rounded-lg shadow-lg text-[13px] text-fg`,children:t.map(i=>i.info?e.jsx("div",{role:"note","data-testid":i.testId,className:"px-2.5 pb-[7px] pt-0.5 text-[11px] text-fg-faint whitespace-nowrap border-b border-line mb-1",children:i.label},i.testId):e.jsx("button",{type:"button",role:"menuitem","data-testid":i.testId,disabled:i.disabled,onClick:()=>{s(!1),i.onSelect()},className:`px-2.5 py-[7px] rounded-[5px] text-left whitespace-nowrap hover:bg-bg-elev disabled:opacity-40 ${i.danger?"text-red-400":""}`,children:i.label},i.testId))})]})}function Te({children:t}){return e.jsx("span",{className:"shrink-0 w-[150px] text-[11px] font-semibold uppercase tracking-[0.1em] text-fg-faint pt-1",children:t})}const Ts="w-full h-9 appearance-none pl-3 pr-8 rounded border border-line bg-bg-hi font-mono text-[13px] text-fg focus:outline-none focus:border-fg-faint disabled:opacity-60";function Ue({label:t,hint:n,testId:s,value:a,onChange:l,children:o}){return e.jsxs("label",{className:"min-w-0 flex flex-col gap-1.5",children:[e.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-[0.1em] text-fg-faint",children:t}),e.jsxs("span",{className:"relative block",children:[e.jsx("select",{"data-testid":s,"aria-label":t,title:n,value:a,onChange:i=>l(i.target.value),className:Ts,children:o}),e.jsx("svg",{"aria-hidden":!0,"data-testid":`${s}-chevron`,viewBox:"0 0 16 16",className:"pointer-events-none absolute right-2.5 top-1/2 -translate-y-1/2 w-3.5 h-3.5 text-fg-faint",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:e.jsx("path",{d:"M4 6l4 4 4-4"})})]})]})}const Ze=t=>{var n;return((n=/\[[^\]]*\]$/.exec(t))==null?void 0:n[0])??""};function Ds({value:t,onChange:n}){const{catalog:s}=Fe(null),a=s?["inherit",...s.aliases]:[...Ut],l=(s==null?void 0:s.availableModels)??null,o=[];if(s){const u=new Set,E=k=>{!u.has(k)&&!a.includes(k)&&(u.add(k),o.push(k))};for(const k of s.models)E(k);for(const k of s.aliases){const p=Se(k),C=Ze(k);if(p&&C)for(const O of s.models)Se(O)===p&&E(O+C)}}const i=u=>!!l&&u!=="inherit"&&!l.includes(u),x=u=>{const E=Se(u);return!!l&&!l.includes(u)&&!(E&&l.includes(E+Ze(u)))&&!(E&&l.includes(E))},j=t||"inherit",h=a.includes(j)||o.includes(j);return e.jsxs(Ue,{label:"model",hint:"This persona's default model for its Epics — sets the --model an Epic launches with (Terminal + Chat both honor it). 'inherit' falls back to each view's own default, not this Settings page. Cheap models for read-only personas; opus for judgement calls. Pinned versions fix a concrete id; an alias floats to the latest.",testId:"model-select",value:j,onChange:n,children:[!h&&e.jsxs("option",{value:j,children:[j," (current)"]}),e.jsx("optgroup",{label:"Aliases",children:a.map(u=>e.jsx("option",{value:u,disabled:!!s&&i(u),title:i(u)?et:void 0,children:u},u))}),o.length>0&&e.jsx("optgroup",{label:"Pinned versions",children:o.map(u=>e.jsx("option",{value:u,disabled:x(u),title:x(u)?et:void 0,children:u},u))})]})}function Ms({value:t,model:n,onChange:s}){const{catalog:a}=Fe(null),l=a&&a.effortLevels.length?["inherit",...a.effortLevels]:[...Bt],o=(a==null?void 0:a.settingsEffortLevels)??[],i=a?l.filter(w=>w!=="inherit"&&!o.includes(w)):[],x=t||"inherit",j=x!=="inherit"&&Ns(n)===!1,h=a?`Effort levels are live-read from the installed claude CLI (what /effort accepts). ${i.length?`${i.join(", ")} ${i.length>1?"are":"is"} session-only — settings.json accepts ${o.join(", ")}. `:""}'inherit' writes no effort: line.`:"Catalog unavailable — showing the standard list. 'inherit' writes no effort: line.";return e.jsxs("div",{className:"min-w-0 flex flex-col gap-1",children:[e.jsxs(Ue,{label:"effort",hint:h,testId:"effort-select",value:x,onChange:s,children:[!l.includes(x)&&e.jsxs("option",{value:x,children:[x," (current)"]}),l.map(w=>e.jsx("option",{value:w,children:i.includes(w)?`${w} (session-only)`:w},w))]}),j&&e.jsx("div",{className:"text-[11px] text-amber-400 leading-snug","data-testid":"effort-unsupported-note",children:"This model ignores effort."})]})}const Rs=["codex","gemini","antigravity","cursor","opencode"];function Os({value:t,onChange:n}){const{rows:s}=pt(),a=new Map((s??[]).map(o=>[o.id,o]));return e.jsxs(Ue,{label:"runs on",hint:"Which coding-agent CLI New Session starts this persona on — override per session in New Session → advanced. On a non-Claude CLI the session has no develop loop, no Restore, and this persona's model/effort are not used. Macros, phone launches and scheduled PRDs always run Claude Code.",testId:"agent-persona-cli-select",value:t,onChange:o=>n(o),children:[e.jsx("option",{value:"claude",children:"Claude Code"}),Rs.map(o=>{const i=a.get(o),x=(i==null?void 0:i.label)||qt[o],j=!!(i!=null&&i.installed),h=i?j?"":" (not installed)":s===null?" (checking…)":" (not detected)",w=i?j?[i.version,i.path].filter(Boolean).join(" · ")||void 0:i.install??"Not installed":void 0;return e.jsxs("option",{value:o,disabled:!j&&t!==o,title:w,children:[x,h]},o)})]})}const et="Blocked by the availableModels allowlist in your Claude settings",Is=["undecided","equipped","bare","unbound"],De=4,ye="#d3a23c",Me="#7b560e",me="#a3441f";function ie(t){const n=t.loadout;return Is.includes(n??"")?n:"undecided"}const _s={undecided:0,unbound:1,equipped:2,bare:3};function Fs(t){const n=s=>_s[ie(s)];return[...t].sort((s,a)=>n(s)-n(a)||s.name.localeCompare(a.name))}function Us(t){const n={all:t.length,undecided:0,equipped:0,bare:0,unbound:0};for(const s of t)n[ie(s)]++;return n}function jt(t){const n=new Set;for(const s of t.tools){const a=/^mcp__(.+?)__/.exec(s);a&&n.add(a[1])}return[...n]}function Nt(t){return t.tools.filter(n=>n!=="*"&&!n.startsWith("mcp__"))}const Bs={undecided:"#d3a23c",equipped:"#6f7d52",bare:"#9a9a9a",unbound:"#a3441f"};function qs(t){return kt(t,ie(t))}function kt(t,n){var o;if(n==="undecided")return"Undecided — choose a loadout";if(n==="unbound")return"Unbound — every tool";if(n==="bare")return"Bare — floor only";const s=[`${Nt(t).length} tools`],a=jt(t).length;a&&s.push(`${a} server${a>1?"s":""}`);const l=((o=t.packs)==null?void 0:o.length)??0;return l&&s.push(`${l} pack${l>1?"s":""}`),s.join(" · ")}const Re={all:"",undecided:"?",equipped:"●",bare:"○",unbound:"∞"};function Ws(t,n){return n==="undecided"?"No tools decision on record":n==="unbound"?"Every tool on this machine, MCP included":n==="bare"?"Floor only — Agent, Skill, ToolSearch, TodoWrite":kt(t,n)}const Gs={tools:"gear",mcpServers:"gear",packs:"gear"};function Ks(t){return t?Pe[t]??(t.startsWith("#")?t:"#8a7a60"):"#8a7a60"}const tt=["low","medium","high","xhigh","max"];function Vs({value:t}){const n=t?tt.indexOf(t):-1;return e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx("span",{className:"inline-flex items-center gap-0.5","aria-hidden":"true",children:tt.map((s,a)=>e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${a<=n?"bg-accent":"bg-line"}`},s))}),e.jsx("span",{"data-testid":"agent-row-effort",className:"text-fg-dim",children:t??"inherit"})]})}const Hs=[{key:"all",label:"All"},{key:"undecided",label:"Undecided"},{key:"equipped",label:"Equipped"},{key:"bare",label:"Bare"},{key:"unbound",label:"Unbound"}];function Js({personas:t,filter:n,onFilterChange:s,onOpen:a,onNew:l,view:o,onView:i}){const[x,j]=d.useState("all"),[h,w]=d.useState(null);d.useEffect(()=>{var D,y;let b=!0;try{const S=(y=(D=window.api.agents).armory)==null?void 0:y.call(D,{});S==null||S.then(N=>{b&&w(N)}).catch(()=>{})}catch{}return()=>{b=!1}},[]);const u=d.useMemo(()=>new Set(((h==null?void 0:h.mcpServers)??[]).filter(b=>b.status==="failing").map(b=>b.label)),[h]),E=d.useMemo(()=>Us(t),[t]),k=n.toLowerCase(),p=d.useMemo(()=>Fs(t).filter(b=>(x==="all"||ie(b)===x)&&(!k||b.name.toLowerCase().includes(k)||(b.description??"").toLowerCase().includes(k))),[t,x,k]),C=d.useRef([]),O=(b,D)=>{var S;const y=b.key==="ArrowRight"?1:b.key==="ArrowLeft"?-1:b.key==="ArrowDown"?De:b.key==="ArrowUp"?-De:0;y?(b.preventDefault(),(S=C.current[Math.min(p.length-1,Math.max(0,D+y))])==null||S.focus()):b.key==="Enter"&&(b.preventDefault(),a(p[D].name))},L=E.undecided;return e.jsxs("div",{"data-testid":"agent-roster",className:"flex flex-col gap-4 p-6 h-full min-h-0 overflow-auto",children:[e.jsxs("div",{className:"flex items-end gap-4",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{"data-testid":"roster-kicker",className:"text-[10.5px] font-semibold tracking-[0.1em] text-fg-faint uppercase",children:["Agents folder · ~/.claude/agents/ · ",t.length," personas"]}),e.jsxs("h2",{className:"text-2xl font-semibold text-fg flex items-baseline gap-2.5 flex-wrap",children:[e.jsx("span",{children:"Agents"}),e.jsx("span",{className:"font-serif italic font-normal text-fg-dim",children:"the roster"}),e.jsx("span",{className:"text-[13px] font-normal text-fg-dim",children:"The actor a session opens with — “you are acting as …”"})]})]}),e.jsx("div",{role:"group","aria-label":"Agents view","data-testid":"agent-view-switch",className:"inline-flex items-center p-0.5 rounded bg-bg-hi border border-line",children:["personas","tags"].map(b=>e.jsx("button",{type:"button",onClick:()=>i(b),"aria-pressed":o===b,className:`px-2.5 py-0.5 text-[11px] rounded transition-colors ${o===b?"bg-bg text-fg font-medium shadow-sm":"text-fg-dim hover:text-fg"}`,children:b==="personas"?"Personas":"Tags"},b))}),e.jsx("input",{value:n,onChange:b=>s(b.target.value),placeholder:"Filter agents, tools, packs","aria-label":"Filter agents",className:"h-9 w-56 px-3 rounded-lg bg-bg-hi border border-line text-sm text-fg placeholder:text-fg-faint"}),e.jsx("button",{type:"button",onClick:l,className:"h-9 px-4 rounded-lg bg-accent text-white text-sm font-semibold",children:"+ New"})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",role:"group","aria-label":"Loadout state",children:[Hs.map(b=>e.jsxs("button",{type:"button","data-testid":`roster-chip-${b.key}`,"aria-pressed":x===b.key,onClick:()=>j(b.key),className:`px-3 py-1 rounded-full text-xs border transition-colors ${x===b.key?"bg-fg text-bg border-fg font-semibold":"bg-bg-hi text-fg-dim border-line hover:text-fg"}`,children:[Re[b.key]&&e.jsx("span",{"aria-hidden":"true",className:"mr-1",style:{color:b.key==="undecided"?ye:b.key==="unbound"?me:void 0},children:Re[b.key]}),b.label," ",e.jsx("span",{className:"opacity-70",children:E[b.key]})]},b.key)),e.jsx("span",{className:"flex-1"}),e.jsxs("span",{className:"text-xs text-fg-faint",children:["Sort ",e.jsx("b",{className:"text-fg font-semibold",children:"Needs a decision first"})," ▾"]})]}),L>0&&e.jsxs("div",{"data-testid":"roster-banner",role:"status",className:"flex items-center gap-3 px-4 py-2.5 rounded-xl border text-sm",style:{background:"rgba(211,162,60,.12)",borderColor:"rgba(211,162,60,.45)",color:Me},children:[e.jsx("span",{"aria-hidden":"true",className:"w-6 h-6 shrink-0 rounded-full border border-dashed flex items-center justify-center text-xs font-semibold",style:{borderColor:ye},children:"?"}),e.jsxs("span",{className:"flex-1",children:[e.jsxs("b",{children:[L," agent",L>1?"s have":" has"," no loadout decision."]})," Until you choose, they run with every tool on this machine — in Epic chat, scheduler jobs and Tasks."]}),e.jsxs("button",{type:"button","data-testid":"roster-review",onClick:()=>j("undecided"),className:"px-3 py-1.5 rounded-lg bg-accent text-white font-semibold",children:["Review the ",L," →"]})]}),p.length===0?e.jsx("div",{className:"text-sm text-fg-faint italic",children:"no agents match"}):e.jsx("div",{role:"listbox","aria-label":"Agents",className:"grid gap-3",style:{gridTemplateColumns:`repeat(${De}, minmax(0, 1fr))`},children:p.map((b,D)=>{var X;const y=ie(b),S=jt(b),N=S.filter(I=>u.has(I)),A=b.overridingProjects.length,W=b.overrideDetails??[],f=[...new Set(W.flatMap(I=>I.fields.map(G=>Gs[G]??G)))],F=W.length?`Overridden in ${W.map(I=>I.project).join(", ")}${f.length?` — ${f.join(", ")}`:""}`:A?`Overridden in ${b.overridingProjects.join(", ")}`:null,z=N.length?`${N[0]} is failing — check it in MCP`:F,B=Nt(b),ee=b.packs??[];return e.jsxs("button",{type:"button",role:"option","aria-selected":!1,"data-agent-row":b.name,"data-testid":"agent-card","data-loadout":y,ref:I=>{C.current[D]=I},onClick:()=>a(b.name),onKeyDown:I=>O(I,D),style:y==="undecided"?{borderColor:ye}:void 0,className:`relative text-left flex flex-col gap-2 p-3.5 pt-4 rounded-2xl bg-bg-hi border overflow-hidden hover:border-fg-faint ${y==="undecided"?"border-dashed":"border-line"} focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent`,children:[y==="unbound"&&e.jsx("span",{"data-testid":"agent-card-hatch","aria-hidden":"true",className:"absolute inset-x-0 top-0 h-1",style:{backgroundImage:`repeating-linear-gradient(135deg, ${me} 0 4px, transparent 4px 8px)`}}),e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{className:"w-9 h-9 shrink-0 rounded-lg flex items-center justify-center font-serif text-lg font-semibold text-white",style:{background:Ks(b.color)},children:(X=b.name[0])==null?void 0:X.toUpperCase()}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block font-mono text-[13px] font-semibold text-fg truncate",children:b.name}),e.jsx("span",{className:"block font-serif italic text-xs text-fg-dim truncate",children:b.title||b.description||"no description"})]}),e.jsx("span",{"aria-hidden":"true","data-testid":"agent-card-menu",className:"ml-auto self-start text-fg-faint",children:"…"})]}),e.jsxs("div",{className:"flex items-center gap-3 text-[10.5px] text-fg-faint",children:[e.jsxs("span",{className:"flex items-center gap-1.5",children:["MODEL ",e.jsx("span",{"data-testid":"agent-row-model",className:"font-mono text-fg-dim",children:b.model??"inherit"})]}),e.jsxs("span",{className:"flex items-center gap-1.5",children:["EFFORT ",e.jsx(Vs,{value:b.effort})]})]}),e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsxs("span",{className:"px-2 py-0.5 rounded-full text-[10.5px] font-semibold border capitalize",style:y==="undecided"?{background:"rgba(211,162,60,.18)",borderColor:ye,color:Me}:y==="unbound"?{borderColor:me,color:me}:void 0,children:[e.jsx("span",{"aria-hidden":"true",className:"mr-1",children:Re[y]}),y]}),e.jsx("span",{className:"text-fg-dim truncate",style:y==="undecided"?{color:Me}:void 0,children:Ws(b,y)})]}),b.upgrade&&e.jsx("div",{children:e.jsx("span",{"data-testid":`agent-roster-upgrade-${b.name}`,title:`v${b.upgrade.installedVersion} installed, v${b.upgrade.bundledVersion} bundled`,className:"inline-block px-2 py-0.5 rounded-full text-[10.5px] font-semibold border border-accent text-accent",children:"newer version available"})}),y==="equipped"&&e.jsxs("div",{className:"flex flex-wrap gap-1 min-h-[20px]",children:[B.length>0&&(B.length<=4?B.map(I=>e.jsx("span",{className:"px-1.5 py-0.5 rounded bg-bg border border-line text-[10.5px] font-mono text-fg-dim",children:I},I)):e.jsxs("span",{className:"px-1.5 py-0.5 rounded bg-bg border border-line text-[10.5px] font-mono text-fg-dim",children:[B.length," tools"]})),S.map(I=>e.jsx("span",{className:"px-1.5 py-0.5 rounded bg-bg border border-line text-[10.5px] font-mono text-fg-dim",children:I},I)),ee.map(I=>e.jsx("span",{className:"px-1.5 py-0.5 rounded bg-bg border border-line text-[10.5px] font-mono text-fg-dim",children:I},I))]}),y==="undecided"&&e.jsx("div",{className:"mt-auto pt-2 text-[11.5px] font-semibold text-accent",children:"Choose a loadout →"}),y==="unbound"&&!z&&e.jsx("div",{className:"mt-auto pt-2 text-[11px] text-fg-faint",children:"Risk marks and job bans still apply"}),z&&e.jsx("div",{"data-testid":"agent-card-note",className:"mt-auto pt-2 text-[11px] text-fg-faint",style:N.length?{color:me}:void 0,children:z})]},b.name)})})]})}const Ys=new Set(re.map(t=>t.tag));function Be(t){return t.filter(n=>Ys.has(n))}function zs(t,n={}){return{name:t.name,originalName:t.name,description:t.description??"",tools:t.tools,model:t.model??"inherit",effort:t.effort??void 0,color:t.color??"",tags:Be(t.tags),projects:t.projects,action:t.action??void 0,actionLabel:t.actionLabel??void 0,title:t.title??void 0,body:t.body,...t.agentCli?{agentCli:t.agentCli}:{},...t.agentCliModel?{agentCliModel:t.agentCliModel}:{},...n}}function qe({children:t,mark:n,className:s=""}){return e.jsx("span",{"data-badge":"risky","data-mark":n,className:`shrink-0 px-1 rounded text-[9.5px] uppercase tracking-wide bg-delta-bad/15 text-delta-bad ${s}`.trim(),children:t})}function Xs(t,n,s){return t[s]??t[`mcp__${n}__*`]??null}function Qs({server:t,chosen:n,onChange:s,onClose:a}){const[l,o]=d.useState({});d.useEffect(()=>{var k,p;let u=!0;const E=window.api;return(p=(k=E==null?void 0:E.toolRisk)==null?void 0:k.read)==null||p.call(k,{scope:"user"}).then(C=>{u&&(C!=null&&C.ok)&&o(C.marks??{})}).catch(()=>{}),()=>{u=!1}},[]);const i=t.tools.map(u=>u.id),x=new Set(n),j=i.filter(u=>x.has(u)).length,h=u=>s(i.filter(E=>E===u?!x.has(E):x.has(E))),w=u=>u.replace(`mcp__${t.id}__`,"");return e.jsxs("div",{"data-testid":"agent-mcp-powers","data-server":t.id,className:"rounded-[12px] border border-line bg-bg mt-1 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 border-b border-line",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{"data-testid":"agent-mcp-powers-name",className:"font-mono text-[13px] text-fg break-all",children:t.label||t.id}),e.jsx("div",{className:"text-[11.5px] text-fg-dim",children:t.status==="checked"?"connected":t.status==="failing"?"failing":"not checked"})]}),e.jsxs("span",{"data-testid":"agent-mcp-powers-count",className:"shrink-0 whitespace-nowrap font-mono text-[11.5px] text-fg-dim",children:[j," of ",i.length," powers"]}),e.jsx("button",{type:"button","data-testid":"agent-mcp-powers-all",onClick:()=>s(i),className:"shrink-0 px-2 h-6 rounded-md border border-line text-[11.5px]",children:"All"}),e.jsx("button",{type:"button","data-testid":"agent-mcp-powers-none",onClick:()=>s([]),className:"shrink-0 px-2 h-6 rounded-md border border-line text-[11.5px]",children:"None"}),e.jsx("button",{type:"button","aria-label":"Close powers","data-testid":"agent-mcp-powers-close",onClick:a,className:"px-1 text-fg-faint hover:text-fg",children:"▴"})]}),t.status==="not-checked"&&e.jsxs("div",{"data-testid":"agent-mcp-powers-unchecked",className:"px-3 py-1.5 text-[11.5px] text-fg-faint border-b border-line",children:[i.length===0?"No tools known yet. ":"Showing known tools. ",e.jsx("button",{type:"button","data-testid":"agent-mcp-powers-check",onClick:()=>je.getState().openPanel("claude-config","mcp"),className:"underline text-fg-dim",children:"Check in MCP"})]}),t.tools.map(u=>e.jsxs("label",{"data-power":u.id,className:"flex items-center gap-2 px-3 py-1.5 border-t border-line first:border-t-0 text-[12.5px] cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:x.has(u.id),onChange:()=>h(u.id)}),e.jsx("span",{title:u.id,className:`min-w-0 flex-1 truncate ${x.has(u.id)?"text-fg":"text-fg-dim"}`,children:u.label===u.id?w(u.id):u.label}),(()=>{const E=Xs(l,t.id,u.id);return E&&E!=="read"?e.jsx(qe,{mark:E,children:E}):null})()]},u.id)),e.jsxs("div",{className:"px-3 py-2 text-[11px] text-fg-faint border-t border-line",children:["Writes tools: ",j," × mcp__",t.id,"__… and mcpServers: ",t.id," — derived from the tools, so the two can't drift."]})]})}const Zs=[{id:"all",label:"All"},{id:"builtin",label:"Built-in"},{id:"mcp",label:"MCP"},{id:"pack",label:"Packs"}],nt={checked:"bg-green-600",failing:"bg-red-600","not-checked":"bg-fg-faint"};function ea({badges:t}){return e.jsxs(e.Fragment,{children:[t.includes("risky")&&e.jsx("span",{"data-badge":"risky",className:"ml-1 px-1 rounded text-[9.5px] uppercase bg-honey/20 text-honey-dark",children:"risky"}),t.includes("banned")&&e.jsx("span",{"data-badge":"banned",className:"ml-1 px-1 rounded text-[9.5px] uppercase bg-red-500/15 text-red-700",children:"banned"})]})}function fe({title:t,sub:n,children:s}){return e.jsxs("section",{className:"mb-4",children:[e.jsxs("h3",{className:"text-[11px] font-semibold uppercase tracking-[0.1em] text-fg-faint mb-1.5",children:[t," ",n&&e.jsx("span",{className:"font-serif italic normal-case tracking-normal font-normal",children:n})]}),e.jsx("div",{className:"flex flex-col gap-1.5",children:s})]})}function yt({initialTab:t="all",armory:n,equipped:s,onEquip:a,onUnequip:l,onDragStart:o,onDragEnd:i,onClose:x}){const[j,h]=d.useState(""),[w,u]=d.useState(t);d.useEffect(()=>{u(t)},[t]);const[E,k]=d.useState(null),p=d.useRef(null);d.useEffect(()=>{var f;(f=p.current)==null||f.focus()},[]);const C=j.trim().toLowerCase(),O=(...f)=>!C||f.some(F=>F.toLowerCase().includes(C)),L=({kind:f,id:F,label:z,badges:B,meta:ee,on:X,locked:I})=>e.jsxs("div",{"data-testid":"armory-item","data-kind":f,"data-item":F,"data-equipped":X?"true":void 0,draggable:!X&&!I,"data-moving":E===`${f}:${F}`?"true":void 0,onDragStart:G=>{var K;k(`${f}:${F}`),(K=G.dataTransfer)==null||K.setData("text/plain",`${f}:${F}`),G.dataTransfer&&(G.dataTransfer.effectAllowed="copy"),o(f,F)},onDragEnd:()=>{k(null),i()},className:`rounded-[10px] border px-2.5 py-1.5 flex items-center gap-2 ${E===`${f}:${F}`?"border-dashed border-accent/60 bg-accent/5":X?"border-line bg-bg-hi":"border-line bg-bg cursor-grab"}`,children:[e.jsx("span",{"data-testid":"armory-grip","aria-hidden":"true",className:"text-fg-faint text-[11px] leading-none select-none",children:"⋮⋮"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{title:F,className:"font-mono text-[12.5px] font-semibold text-fg truncate",children:[z,e.jsx(ea,{badges:B})]}),ee&&e.jsx("div",{className:"text-[11px] text-fg-dim flex items-center gap-1.5",children:ee})]}),E===`${f}:${F}`?e.jsx("span",{"data-testid":"armory-moving",className:"text-[11px] font-semibold text-accent-dark",children:"Moving…"}):I?e.jsx("span",{className:"text-[11px] text-fg-faint",children:"always granted"}):X?e.jsxs(e.Fragment,{children:[e.jsx("span",{"data-testid":"armory-on-sheet",className:"text-[11px] text-fg-dim",children:"✓ On sheet"}),e.jsx("button",{type:"button","data-testid":"armory-unequip","aria-label":`Unequip ${z}`,onClick:()=>l(f,F),className:"h-6 px-2 rounded-md border border-line text-[11.5px] text-fg-dim hover:text-fg",children:"Unequip"})]}):e.jsx("button",{type:"button","data-testid":"armory-equip","aria-label":`Equip ${z}`,onClick:()=>a(f,F),className:"h-6 px-2 rounded-md border border-line bg-bg-hi text-[11.5px] font-medium text-fg hover:border-rule",children:"Equip"})]}),b=f=>w==="all"||w===f,D=b("builtin")?((n==null?void 0:n.builtins)??[]).filter(f=>O(f.id,f.label)):[],y=b("mcp")?((n==null?void 0:n.mcpServers)??[]).filter(f=>O(f.id,f.label)):[],S=b("pack")?((n==null?void 0:n.packs)??[]).filter(f=>O(f.id,f.label,...f.skills)):[],N=w==="all"||w==="builtin"?((n==null?void 0:n.bundledSkills)??[]).filter(f=>O(f.id,f.label)):[],A=w==="all"||w==="pack"?((n==null?void 0:n.unpackedSkills)??[]).filter(f=>O(f)):[],W=f=>f==="all"?n?n.builtins.length+n.mcpServers.length+n.packs.length:0:f==="builtin"?(n==null?void 0:n.builtins.length)??0:f==="mcp"?(n==null?void 0:n.mcpServers.length)??0:(n==null?void 0:n.packs.length)??0;return e.jsxs("aside",{"data-testid":"agent-armory",role:"complementary","aria-label":"Armory",className:`fixed top-0 right-0 bottom-0 w-[340px] ${Ne.dialog} flex flex-col bg-bg-elev border-l border-line shadow-xl`,children:[e.jsxs("div",{className:"px-5 pt-4 pb-2 flex items-start gap-2",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-[0.1em] text-fg-faint",children:"Installed on this machine"}),e.jsxs("div",{className:"font-serif text-[24px] text-fg leading-tight",children:["Armory ",e.jsx("span",{className:"font-sans text-[12px] text-fg-dim",children:"Drag onto the sheet, or press Equip."})]})]}),e.jsx("button",{type:"button","aria-label":"Close armory","data-testid":"armory-close",onClick:x,className:"px-2 text-fg-faint hover:text-fg",children:"×"})]}),e.jsx("div",{className:"px-5 pb-3",children:e.jsx("input",{ref:p,type:"search","data-testid":"armory-search","aria-label":"Search the armory",placeholder:"Search tools, servers, packs…",value:j,onChange:f=>h(f.target.value),className:"w-full h-9 px-3 rounded-[10px] border border-line bg-bg text-[13px] text-fg"})}),e.jsxs("div",{role:"tablist","aria-label":"Armory kinds",className:"px-5 pb-2 flex flex-wrap items-center gap-1",children:[Zs.map(f=>e.jsxs("button",{type:"button",role:"tab","aria-selected":w===f.id,"data-testid":"armory-tab","data-tab":f.id,onClick:()=>u(f.id),className:`h-6 px-2 rounded-md text-[11.5px] ${w===f.id?"bg-bg-hi border border-line font-semibold text-fg":"text-fg-dim hover:text-fg"}`,children:[f.label," ",e.jsx("span",{className:"text-fg-faint",children:W(f.id)})]},f.id)),e.jsx("span",{"data-testid":"armory-tab-companions",className:"px-2 text-[11.5px] text-fg-faint",children:"Companions · later"})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto px-5",children:[D.length>0&&e.jsx(fe,{title:"Built-in tools",sub:"class abilities",children:D.map(f=>e.jsx(d.Fragment,{children:L({kind:"builtin",id:f.id,label:f.label,badges:f.badges,locked:f.badges.includes("floor"),on:s.allBuiltins||s.builtins.includes(f.id)})},f.id))}),N.length>0&&e.jsx(fe,{title:"Skills bundled with the CLI",children:e.jsx("div",{"data-testid":"armory-bundled",className:"flex flex-wrap gap-1.5",children:N.map(f=>e.jsxs("span",{"data-bundled":f.id,title:"Bundled with the CLI — not equippable",className:"px-2 py-0.5 rounded-md text-[12px] font-mono border border-line bg-bg text-fg-dim",children:[e.jsx("span",{"aria-hidden":"true",className:"text-fg-faint mr-1",children:"⋮⋮"}),f.label]},f.id))})}),y.length>0&&e.jsx(fe,{title:"MCP servers",sub:"magic items",children:y.map(f=>e.jsx(d.Fragment,{children:L({kind:"mcp",id:f.id,label:f.label,badges:f.badges,on:s.servers.includes(f.id),meta:e.jsxs(e.Fragment,{children:[e.jsx("span",{"data-testid":"armory-status-dot",className:`inline-block w-1.5 h-1.5 rounded-full ${nt[f.status]??nt["not-checked"]}`}),f.status==="checked"?"connected":f.status==="failing"?"failing":"not checked"," · ",f.tools.length," powers",f.status==="not-checked"&&e.jsxs(e.Fragment,{children:[" · ",e.jsx("button",{type:"button","data-testid":"armory-check-now",onClick:()=>je.getState().openPanel("claude-config","mcp"),className:"underline text-accent-dark",children:"Check now"})]})]})})},f.id))}),S.length>0&&e.jsx(fe,{title:"Packs",sub:"spellbooks",children:S.map(f=>e.jsx(d.Fragment,{children:L({kind:"pack",id:f.id,label:f.label,badges:f.badges,on:s.packs.includes(f.id),meta:e.jsxs(e.Fragment,{children:[f.source?`${f.source} · `:"",f.skills.length," skills"]})})},f.id))}),A.length>0&&e.jsx(fe,{title:"Unpacked skills · not equippable",children:e.jsxs("div",{"data-testid":"armory-unpacked",className:"rounded-[10px] border border-dashed border-rule px-2.5 py-1.5 text-[12px] text-fg-dim",children:[e.jsx("span",{className:"font-mono",children:A.join(" · ")})," — skills travel only inside packs"]})}),!D.length&&!y.length&&!S.length&&!A.length&&!N.length&&e.jsx("div",{"data-testid":"armory-empty",className:"text-[12px] text-fg-faint py-4",children:n?"Nothing matches.":"Loading the armory…"})]}),e.jsx("div",{className:"px-5 py-2 border-t border-line text-[11px] text-fg-faint",children:"Tab to move · Enter equips the focused item · Esc closes"})]})}const ge=t=>`mcp__${t}__`;function st(t){const n=new Set;for(const s of t){const a=/^mcp__(.+?)__/.exec(s);a&&n.add(a[1])}return[...n]}const at=t=>t.loadout==="unbound"||t.loadout==="undecided"||t.tools.includes("*");function ta(t){return t.loadout==="unbound"||t.tools.includes("*")?"unbound":t.loadout}function na({children:t}){return e.jsx("div",{className:"font-serif italic text-[12px] text-fg-faint font-normal",children:t})}function lt({badges:t}){return e.jsxs(e.Fragment,{children:[t.includes("risky")&&e.jsx(qe,{className:"ml-1",children:"risky"}),t.includes("banned")&&e.jsx("span",{"data-badge":"banned",className:"ml-1 px-1 rounded text-[9.5px] uppercase tracking-wide bg-red-500/15 text-red-700",children:"banned"})]})}function we({testid:t,title:n,sub:s,children:a,drop:l}){var j;const[o,i]=d.useState(!1),x=!!l&&((j=l.dragging)==null?void 0:j.kind)===l.kind;return e.jsxs("div",{"data-testid":t,"data-drop-target":x?o?"over":"ready":void 0,onDragEnter:x?h=>{h.preventDefault(),i(!0)}:void 0,onDragOver:x?h=>{h.preventDefault(),i(!0)}:void 0,onDragLeave:x?()=>i(!1):void 0,onDrop:l?h=>{h.preventDefault(),i(!1),l.onDrop()}:void 0,className:`relative grid grid-cols-[132px_1fr] gap-3 py-3 border-t border-line first:border-t-0 ${x?`rounded-[12px] border border-dashed border-accent/60 ${o?"bg-accent/15":"bg-accent/5"}`:""}`,children:[x&&o&&e.jsx("span",{"data-testid":"agent-release-hint",className:"absolute right-2 top-1 text-[11px] font-semibold text-accent-dark",children:"Release to equip"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[13px] font-semibold text-fg",children:n}),e.jsx(na,{children:s})]}),e.jsx("div",{className:"min-w-0",children:a})]})}const sa={checked:{dot:"bg-green-600",text:"connected"},failing:{dot:"bg-red-600",text:"failing"},"not-checked":{dot:"bg-fg-faint",text:"not checked"}};function aa({obj:t,set:n,baseline:s,onRestore:a,projectName:l,onOpenChange:o}){const[i,x]=d.useState(null),[j,h]=d.useState(!1);d.useEffect(()=>{o==null||o(j)},[j,o]),d.useEffect(()=>()=>{o==null||o(!1)},[o]);const[w,u]=d.useState(null),[E,k]=d.useState(null);d.useEffect(()=>{var q,ne;let c=!0;const g=async()=>{try{const J=await window.api.agents.armory({});c&&x(J)}catch(J){ut.getState().show("error",`Could not load the armory: ${J instanceof Error?J.message:String(J)}`)}};g();const M=(ne=(q=window.api.agents).onChanged)==null?void 0:ne.call(q,()=>{g()});return()=>{c=!1,M==null||M()}},[]);const p=at(t),C=t.loadout==="undecided"&&!t.tools.includes("*"),O=!p&&t.loadout==="bare",L=!!s&&!!a,b=(s==null?void 0:s.tools)??[],D=L&&!at(s),y=L?[...new Set([...(s==null?void 0:s.mcpServers)??[],...st(b)])]:[],S=L?(s==null?void 0:s.packs)??[]:[],N=c=>a==null?void 0:a(c),A=(c,g)=>e.jsx("button",{type:"button","data-testid":c,onClick:()=>N(g),className:"text-[12px] text-accent hover:underline px-1",children:"Restore"}),W=new Set(((i==null?void 0:i.builtins)??[]).filter(c=>c.badges.includes("floor")).map(c=>c.id)),f=i?i.builtins.filter(c=>!W.has(c.id)):ks.map(c=>({id:c,label:c,badges:[]})),F=i?i.builtins.filter(c=>W.has(c.id)):[],z=c=>{if(p){n({loadout:"equipped",tools:[...f.map(g=>g.id).filter(g=>g!==c),...t.tools.filter(g=>g.startsWith("mcp__"))]});return}n({tools:t.tools.includes(c)?t.tools.filter(g=>g!==c):[...t.tools,c]})},B=[...new Set([...t.mcpServers??[],...st(t.tools)])],ee=c=>i==null?void 0:i.mcpServers.find(g=>g.id===c),X=c=>{const g=p?t.tools:[...new Set([...t.tools,...c.tools.map(M=>M.id)])];n({tools:g,mcpServers:[...B,c.id],...p?{loadout:t.loadout}:{}})},I=c=>{const g=p?[...f.map(M=>M.id),...F.map(M=>M.id)]:t.tools;n({tools:g.filter(M=>!M.startsWith(ge(c))),mcpServers:B.filter(M=>M!==c)})},G=(c,g)=>{if(g.length===0){if(typeof window.confirm=="function"&&!window.confirm(`Unequip ${c.id}? Choosing no powers removes the server from this agent.`))return;I(c.id),u(null);return}const M=p?[...f.map(q=>q.id),...F.map(q=>q.id),...t.tools.filter(q=>q.startsWith("mcp__"))]:t.tools;n({tools:[...new Set([...M.filter(q=>!q.startsWith(ge(c.id))),...g])],mcpServers:B.includes(c.id)?B:[...B,c.id]})},K=t.packs??[],$=c=>i==null?void 0:i.packs.find(g=>g.id===c),P=(c,g)=>{if(c==="builtin")!p&&!t.tools.includes(g)&&n({tools:[...t.tools,g]});else if(c==="mcp"){const M=ee(g);M&&!B.includes(g)&&X(M)}else K.includes(g)||n({packs:[...K,g]})},se=(c,g)=>{c==="builtin"?(p||t.tools.includes(g))&&z(g):c==="mcp"?I(g):n({packs:K.filter(M=>M!==g)})},Q=c=>()=>{const g=E;k(null),g&&g.kind===c&&P(g.kind,g.id)},m=c=>({kind:c,dragging:E,onDrop:Q(c)});d.useEffect(()=>{if(!j)return;const c=g=>{g.key==="Escape"&&(E?k(null):h(!1))};return document.addEventListener("keydown",c),()=>document.removeEventListener("keydown",c)},[j,E]);const[T,_]=d.useState("all"),V=c=>{_(c??"all"),h(!0),k(null)},te="rounded-[12px] border border-dashed border-rule px-3 py-2 text-[12px] text-fg-faint flex items-center";return e.jsxs("section",{"data-testid":"agent-gear-slot",className:"px-[18px] py-4 rounded-[14px] bg-bg-hi border border-line flex flex-col",children:[e.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-[0.1em] text-fg-faint mb-1",children:e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"flex-1",children:["Gear ",e.jsx("span",{className:"font-serif italic normal-case tracking-normal font-normal text-fg-dim",children:"inventory"})]}),e.jsx("button",{type:"button","data-testid":"agent-open-armory","aria-expanded":j,onClick:()=>{h(c=>!c),k(null)},className:"h-7 px-2.5 rounded-[10px] border border-line bg-bg text-[12px] font-medium normal-case tracking-normal text-fg hover:border-rule",children:j?"Armory open":"Open Armory"})]})}),e.jsxs("div",{"data-testid":"agent-gear-hint",className:"text-[11.5px] text-fg-faint mb-1",children:["Drag items here from the Armory, or"," ",e.jsx("button",{type:"button","data-testid":"agent-gear-hint-open",onClick:()=>V(),className:"underline text-fg-dim hover:text-fg",children:"Open Armory"})]}),e.jsxs(we,{testid:"agent-tools-row",title:"Built-in tools",sub:"class abilities",drop:m("builtin"),children:[e.jsx("div",{className:"flex flex-wrap gap-1.5",children:f.map(c=>{const g=p||t.tools.includes(c.id),M=D&&g&&!p&&!b.includes(c.id);return D&&!g&&b.includes(c.id)?e.jsxs("span",{"data-tool":c.id,"data-marker":"removed",className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-md text-[12px] font-mono border border-dashed border-rule bg-transparent text-fg-faint",children:[e.jsx("span",{className:"line-through",children:c.label}),e.jsx("span",{className:"text-[10px]",children:"− removed"}),A("agent-restore-tool",["tools"])]},c.id):e.jsxs("button",{type:"button","aria-pressed":g,"data-tool":c.id,"data-marker":M?"added":void 0,onClick:()=>z(c.id),className:`px-2 py-0.5 rounded-md text-[12px] font-mono border ${M?"bg-bg text-accent border-accent":g?"bg-bg text-fg border-rule":"bg-transparent text-fg-faint border-dashed border-rule"}`,children:[M&&"+",c.label,e.jsx(lt,{badges:c.badges})]},c.id)})}),F.length>0&&e.jsxs("div",{"data-testid":"agent-floor-row",className:"flex flex-wrap items-center gap-1.5 mt-2",children:[e.jsx("span",{className:"text-[11.5px] text-fg-faint mr-1",children:"Always granted"}),F.map(c=>e.jsxs("span",{"data-floor":c.id,className:"px-2 py-0.5 rounded-md text-[12px] font-mono border border-line bg-bg text-fg-dim cursor-default",children:[c.label,e.jsx("span",{className:"ml-1 px-1 rounded text-[9.5px] uppercase tracking-wide bg-bg-hi text-fg-faint",children:"floor"})]},c.id))]}),e.jsx("div",{"data-testid":"agent-tools-note",className:"text-[11px] text-fg-faint mt-1 leading-snug",children:p?C?"Undecided — no loadout chosen, so it runs with every tool (MCP included). Click one to restrict.":"All tools — every tool (MCP included) is granted. Click one to restrict.":e.jsxs(e.Fragment,{children:[O&&e.jsx("span",{"data-testid":"agent-tools-bare",children:"Bare — floor only. "}),t.tools.filter(c=>!c.startsWith("mcp__")).length," of ",f.length+F.length," built-ins granted. Anything not filled is refused at call time."," ",e.jsx("button",{type:"button","data-testid":"agent-tools-all",onClick:()=>n({loadout:"unbound",tools:["*"]}),className:"underline text-fg-dim hover:text-fg",children:"Grant all tools"})]})})]}),e.jsx(we,{testid:"agent-mcp-row",title:"MCP servers",sub:"magic items",drop:m("mcp"),children:e.jsxs("div",{className:"flex flex-col gap-2",children:[y.filter(c=>!B.includes(c)).map(c=>e.jsxs("div",{"data-testid":"agent-mcp-removed","data-server":c,"data-marker":"removed",className:"rounded-[12px] border border-dashed border-rule bg-bg px-3 py-2 flex items-center gap-2 min-w-0 text-fg-faint",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{title:c,className:"font-mono text-[13px] font-semibold truncate line-through",children:c}),e.jsxs("div",{className:"text-[11.5px]",children:["− removed",l?` in ${l}`:""]})]}),A("agent-restore-mcp",["tools","mcpServers"])]},`removed-${c}`)),B.map(c=>{const g=ee(c),M=L&&!y.includes(c),q=sa[(g==null?void 0:g.status)??"not-checked"],ne=(g==null?void 0:g.tools.length)??0,J=p?ne:t.tools.filter(r=>r.startsWith(ge(c))).length;return e.jsxs("div",{children:[e.jsxs("div",{"data-testid":"agent-mcp-item","data-server":c,"data-marker":M?"added":void 0,className:"rounded-[12px] border border-line bg-bg px-3 py-2 flex items-center gap-2 min-w-0",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{title:c,className:"font-mono text-[13px] font-semibold text-fg truncate",children:[M&&e.jsx("span",{className:"text-accent",children:"+ "}),c,e.jsx(lt,{badges:(g==null?void 0:g.badges)??[]})]}),e.jsxs("div",{className:"text-[11.5px] text-fg-dim flex items-center gap-1.5",children:[e.jsx("span",{"data-testid":"agent-mcp-dot",className:`inline-block w-1.5 h-1.5 rounded-full ${q.dot}`}),q.text,g?` · ${J} of ${ne} powers`:""]}),t.tools.filter(r=>r.startsWith(ge(c))).length>0&&e.jsx("div",{className:"flex flex-wrap gap-1 mt-1",children:t.tools.filter(r=>r.startsWith(ge(c))).map(r=>e.jsx("span",{"data-mcp-tool":r,title:r,className:"max-w-[220px] truncate px-1.5 rounded text-[10.5px] font-mono bg-bg-hi border border-line text-fg-faint",children:r},r))})]}),g&&e.jsx("button",{type:"button","data-testid":"agent-mcp-powers-open","aria-expanded":w===c,onClick:()=>u(w===c?null:c),className:"text-[12px] text-fg-dim hover:text-fg px-1",children:"Powers ›"}),e.jsx("button",{type:"button","aria-label":`Remove ${c}`,"data-testid":"agent-mcp-remove",onClick:()=>I(c),className:"text-fg-faint hover:text-fg px-1",children:"×"})]}),g&&w===c&&e.jsx(Qs,{server:g,chosen:p?g.tools.map(r=>r.id):t.tools,onChange:r=>G(g,r),onClose:()=>u(null)})]},c)}),e.jsx("button",{type:"button","data-testid":"agent-mcp-slot","data-slot-kind":"mcp",onClick:()=>V("mcp"),className:`${te} w-full text-left`,children:"Drop an MCP server"})]})}),e.jsx(we,{testid:"agent-packs-row",title:"Packs",sub:"spellbooks",drop:m("pack"),children:e.jsxs("div",{className:"flex flex-col gap-2",children:[S.filter(c=>!K.includes(c)).map(c=>e.jsxs("div",{"data-testid":"agent-pack-removed","data-pack":c,"data-marker":"removed",className:"rounded-[12px] border border-dashed border-rule bg-bg px-3 py-2 flex items-center gap-2 text-fg-faint",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"font-mono text-[13px] font-semibold truncate line-through",children:c}),e.jsxs("div",{className:"text-[11.5px]",children:["− removed",l?` in ${l}`:""]})]}),A("agent-restore-pack",["packs"])]},`removed-${c}`)),K.map(c=>{const g=$(c),M=L&&!S.includes(c);return e.jsxs("div",{"data-testid":"agent-pack-item","data-pack":c,"data-marker":M?"added":void 0,className:"rounded-[12px] border border-line bg-bg px-3 py-2 flex items-start gap-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{title:c,className:"font-mono text-[13px] font-semibold text-fg truncate",children:[M&&e.jsx("span",{className:"text-accent",children:"+ "}),c]}),g&&e.jsxs("div",{className:"text-[11.5px] text-fg-dim",children:[g.source?`${g.source} · `:"",g.skills.length," skills"]}),g&&e.jsx("div",{className:"flex flex-wrap gap-1 mt-1",children:g.skills.map(q=>e.jsxs("span",{className:"px-1.5 rounded text-[10.5px] font-mono bg-bg-hi border border-line text-fg-dim",children:["/",q]},q))})]}),e.jsx("button",{type:"button","aria-label":`Remove ${c}`,"data-testid":"agent-pack-remove",onClick:()=>n({packs:K.filter(q=>q!==c)}),className:"text-fg-faint hover:text-fg px-1",children:"×"})]},c)}),e.jsx("button",{type:"button","data-testid":"agent-pack-slot","data-slot-kind":"pack",onClick:()=>V("pack"),className:`${te} w-full text-left`,children:"Drop a pack"})]})}),e.jsx(we,{testid:"agent-companions-row",title:"Companions",sub:"party",children:e.jsx("div",{"data-testid":"agent-companions-slot",className:te,children:"Other agents it can call — designed later, not part of this build"})}),j&&e.jsx(yt,{initialTab:T,armory:i,equipped:{allBuiltins:p,builtins:t.tools,servers:B,packs:K},onEquip:P,onUnequip:se,onDragStart:(c,g)=>k({kind:c,id:g}),onDragEnd:()=>k(null),onClose:()=>{h(!1),k(null)}})]})}const la=t=>`mcp__${t}__`;function ia(t,n){return t.loadout!=="undecided"||JSON.stringify(t.tools)!==JSON.stringify(n)}function oa(t,n,s,a,l){return t&&!l&&(a||!ia(n,s))}function ra({obj:t,set:n,picking:s,setPicking:a,onDismiss:l}){const[o,i]=d.useState(null),x=d.useRef(!1),[j,h]=d.useState([]);d.useEffect(()=>{var S,N;let y=!0;return Promise.resolve((N=(S=window.api.agents).armory)==null?void 0:N.call(S,{})).then(A=>{y&&A&&i(A)}).catch(()=>{}),()=>{y=!1}},[]);const w=()=>{var y,S;x.current||(x.current=!0,Promise.resolve((S=(y=window.api.agents).listPersonas)==null?void 0:S.call(y)).then(N=>{Array.isArray(N)&&h(N)}).catch(()=>{}))},u=o?o.builtins.filter(y=>y.badges.includes("floor")):[],E={allBuiltins:!1,builtins:t.tools,servers:[...new Set([...t.mcpServers??[],...t.tools.map(y=>{var S;return(S=/^mcp__(.+?)__/.exec(y))==null?void 0:S[1]}).filter(y=>!!y)])],packs:t.packs??[]},k=(y,S)=>{if(y==="builtin")t.tools.includes(S)||n({loadout:"equipped",tools:[...t.tools,S]});else if(y==="mcp"){const N=o==null?void 0:o.mcpServers.find(A=>A.id===S);n({loadout:"equipped",tools:[...new Set([...t.tools,...(N==null?void 0:N.tools.map(A=>A.id))??[]])],mcpServers:[...new Set([...t.mcpServers??[],S])]})}else n({loadout:"equipped",packs:[...new Set([...t.packs??[],S])]})},p=(y,S)=>{n(y==="builtin"?{tools:t.tools.filter(N=>N!==S)}:y==="mcp"?{tools:t.tools.filter(N=>!N.startsWith(la(S))),mcpServers:(t.mcpServers??[]).filter(N=>N!==S)}:{packs:(t.packs??[]).filter(N=>N!==S)})},C=y=>{const S=j.find(A=>A.name===y);if(!S)return;const N=S.tools.filter(A=>A!=="*");n({loadout:"equipped",tools:N,mcpServers:[...new Set(N.map(A=>{var W;return(W=/^mcp__(.+?)__/.exec(A))==null?void 0:W[1]}).filter(A=>!!A))]})},O="rounded-[14px] border border-line bg-bg-hi p-4 flex flex-col gap-2 min-w-0",L="h-9 px-4 rounded-[10px] border border-line bg-bg text-[13px] font-semibold text-fg hover:border-rule self-start",b="h-9 px-4 rounded-[10px] border border-transparent bg-accent text-bg text-[13px] font-semibold hover:opacity-90 self-start",D=j.filter(y=>y.name!==t.name);return e.jsxs("section",{"data-testid":"agent-undecided-choice",className:"px-[18px] py-4 rounded-[14px] border border-dashed border-honey bg-honey/10 flex flex-col gap-3",children:[e.jsxs("h2",{className:"font-serif text-[22px] text-fg",children:["Choose a loadout ",e.jsx("span",{className:"text-[13px] italic text-fg-dim",children:"before the adventure starts"})]}),e.jsxs("p",{className:"text-[13px] text-fg-dim",children:[e.jsx("span",{className:"font-mono",children:t.name})," has no tools decision on record, so today it runs with"," ",e.jsx("strong",{className:"text-fg",children:"every tool on this machine"}),". Pick one; you can change it any time."]}),e.jsxs("div",{className:`${O} w-full`,"data-choice":"bare",children:[e.jsxs("div",{className:"font-semibold text-fg",children:["Bare ",e.jsx("span",{className:"font-serif italic font-normal text-fg-dim text-[12px]",children:"empty-handed"})]}),e.jsx("p",{className:"text-[12.5px] text-fg-dim",children:"Nothing equipped — only the floor no agent can drop."}),u.length>0&&e.jsx("div",{"data-testid":"agent-choice-floor",className:"flex flex-wrap gap-1.5",children:u.map(y=>e.jsx("span",{className:"px-2 py-0.5 rounded-md text-[12px] font-mono border border-line bg-bg text-fg-dim",children:y.label},y.id))}),e.jsx("button",{type:"button","data-testid":"agent-choose-bare",onClick:()=>n({loadout:"bare",tools:[]}),className:L,children:"Go bare"})]}),e.jsxs("div",{className:`${O} w-full border-accent relative`,"data-choice":"pick",children:[e.jsx("span",{className:"absolute -top-2 right-4 px-2 rounded bg-accent text-bg text-[10px] font-semibold tracking-wide",children:"RECOMMENDED"}),e.jsxs("div",{className:"font-semibold text-fg",children:["Pick gear ",e.jsx("span",{className:"font-serif italic font-normal text-fg-dim text-[12px]",children:"outfit the character"})]}),e.jsxs("p",{className:"text-[12.5px] text-fg-dim",children:["Equip exactly what ",t.name," needs from the Armory."]}),e.jsxs("label",{className:"flex items-center gap-2 text-[12.5px] text-fg-dim",children:["Start from",e.jsxs("select",{"data-testid":"agent-start-from",onFocus:w,onMouseEnter:w,"aria-label":"Start from another agent",value:"",onChange:y=>{y.target.value&&C(y.target.value)},className:"h-8 rounded-md border border-line bg-bg px-2 font-mono text-fg max-w-[16rem]",children:[e.jsx("option",{value:"",children:"another agent's gear…"}),D.map(y=>e.jsx("option",{value:y.name,children:y.name},y.name))]})]}),e.jsx("button",{type:"button","data-testid":"agent-choose-pick",onClick:()=>a(!0),className:b,children:"Open the Armory"})]}),e.jsxs("div",{className:`${O} w-full`,"data-choice":"unbound",children:[e.jsxs("div",{className:"font-semibold text-fg",children:["Unbound ",e.jsx("span",{className:"font-serif italic font-normal text-fg-dim text-[12px]",children:"every relic in the vault"})]}),e.jsx("p",{className:"text-[12.5px] text-fg-dim",children:"Every tool on this machine — MCP servers too, including ones added later. Today's behaviour, chosen on purpose."}),e.jsx("button",{type:"button","data-testid":"agent-choose-unbound",onClick:()=>n({loadout:"unbound",tools:["*"]}),className:L,children:"Go unbound"})]}),e.jsxs("div",{"data-testid":"agent-runs-today",className:`${O} w-full`,children:[e.jsxs("div",{className:"text-[11px] font-semibold uppercase tracking-[0.1em] text-fg-faint",children:["Where ",t.name," runs today"]}),e.jsxs("ul",{className:"flex flex-col gap-1 text-[13px] text-fg",children:[e.jsx("li",{children:"Epic chat"}),e.jsx("li",{children:"Scheduler jobs"}),e.jsx("li",{children:"Tasks"})]}),e.jsx("div",{className:"text-[11.5px] text-fg-faint italic",children:"Your choice applies to their next sessions; running ones keep every tool until they end."})]}),e.jsxs("p",{className:"text-[12px] text-fg-dim",children:[e.jsx("button",{type:"button","data-testid":"agent-choose-later",onClick:l,className:"underline text-fg",children:"Not now"})," ","— ",t.name," keeps running with every tool and stays flagged in the roster."]}),s&&e.jsx(yt,{armory:o,equipped:E,onEquip:k,onUnequip:p,onDragStart:()=>{},onDragEnd:()=>{},onClose:()=>a(!1)})]})}const da="headless-default",ca={read:"READ",write:"WRITE",confirm:"CONFIRM",irreversible:"IRREVERSIBLE",money:"MONEY",public:"PUBLIC"};function Ce({testid:t,title:n,children:s}){return e.jsxs("div",{"data-testid":t,className:"flex flex-col gap-1.5 pt-3 border-t border-line first:border-t-0 first:pt-0",children:[e.jsx("div",{className:"font-serif italic text-[12px] text-fg-faint",children:n}),s]})}function it({obj:t,set:n,collapsed:s=!1}){const[a,l]=d.useState(!1);d.useEffect(()=>{l(!1)},[s]);const[o,i]=d.useState(null),[x,j]=d.useState({}),[h,w]=d.useState(null),u=t.environment||da;d.useEffect(()=>{var O,L,b,D,y,S;let p=!0;const C=window.api;return(L=(O=C==null?void 0:C.agents)==null?void 0:O.armory)==null||L.call(O,{}).then(N=>{p&&i(N)}).catch(()=>{}),(D=(b=C==null?void 0:C.toolRisk)==null?void 0:b.read)==null||D.call(b,{scope:"user"}).then(N=>{p&&(N!=null&&N.ok)&&j(N.marks??{})}).catch(()=>{}),(S=(y=C==null?void 0:C.claudeConfig)==null?void 0:y.read)==null||S.call(y,{fileId:"settings",scope:"user"}).then(N=>{var W;if(!p)return;const A=((W=N==null?void 0:N.data)==null?void 0:W.permissions)??{};w({allow:Array.isArray(A.allow)?A.allow.length:0,deny:Array.isArray(A.deny)?A.deny.length:0})}).catch(()=>{}),()=>{p=!1}},[]);const E=o?[...o.builtins,...o.bundledSkills,...o.mcpServers.flatMap(p=>[p,...p.tools])].filter(p=>p.badges.includes("banned")):[],k=Object.entries(x).filter(([,p])=>p!=="read");return s&&!a?e.jsxs("section",{"data-testid":"agent-constraints-slot","data-collapsed":"true",className:"px-[18px] py-3 rounded-[14px] bg-bg-hi border border-line flex items-center gap-2 text-[12px]",children:[e.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-[0.1em] text-fg-faint",children:"Constraints"}),e.jsxs("span",{"data-testid":"constraints-summary",className:"flex-1 min-w-0 truncate text-fg-dim",children:[e.jsx("span",{className:"font-mono text-fg",children:u})," · ",k.length," risk marks · ",E.length," banned in jobs"]}),e.jsx("button",{type:"button","data-testid":"constraints-show",onClick:()=>l(!0),className:"font-medium text-accent hover:underline",children:"Show ›"})]}):e.jsxs("section",{"data-testid":"agent-constraints-slot",className:"px-[18px] py-4 rounded-[14px] bg-bg-hi border border-line flex flex-col gap-3",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"text-[11px] font-semibold uppercase tracking-[0.1em] text-fg-faint",children:["Constraints ",e.jsx("span",{className:"font-serif italic normal-case tracking-normal",children:"rules of the realm"})]}),e.jsx("div",{className:"text-[12px] text-fg-faint italic",children:"Rules on the gear — not inventory."})]}),e.jsx(Ce,{testid:"constraints-environment",title:"Sandbox environment",children:e.jsx("div",{role:"radiogroup","aria-label":"Sandbox environment",className:"flex flex-col gap-1.5",children:((o==null?void 0:o.environments)??[]).map(p=>{const C=p.name===u;return e.jsxs("button",{type:"button",role:"radio","aria-checked":C,"data-environment":p.name,onClick:()=>n({environment:p.name}),className:`text-left px-3 py-2 rounded-[10px] border flex items-start gap-2 ${C?"border-accent bg-accent/10":"border-line bg-bg hover:border-rule"}`,children:[e.jsx("span",{"aria-hidden":"true","data-radio-dot":C?"on":"off",className:`mt-1 w-2.5 h-2.5 shrink-0 rounded-full border ${C?"border-accent bg-accent":"border-rule"}`}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("div",{className:"text-[13px] font-semibold text-fg font-mono",children:p.name}),e.jsx("div",{className:"text-[11.5px] text-fg-faint",children:p.summary})]})]},p.name)})})}),e.jsx(Ce,{testid:"constraints-risk-marks",title:"Risk marks",children:k.length===0?e.jsx("div",{className:"text-[12px] text-fg-faint italic",children:"No risk marks set."}):e.jsx("ul",{className:"flex flex-col gap-1",children:k.map(([p,C])=>e.jsxs("li",{"data-risk-mark":C,className:"flex items-center gap-2 text-[12px]",children:[e.jsx(qe,{mark:C,children:ca[C]}),e.jsx("span",{className:"font-mono text-fg-dim truncate",children:p})]},p))})}),e.jsx(Ce,{testid:"constraints-banned",title:"Banned in unattended runs",children:E.length===0?e.jsx("div",{className:"text-[12px] text-fg-faint italic",children:"Nothing banned."}):e.jsx("div",{className:"flex flex-wrap gap-1.5",children:E.map(p=>e.jsx("span",{"data-banned":p.id,className:"px-2 py-0.5 rounded-full text-[11px] font-mono bg-red-500/15 text-red-700",children:p.label||p.id},p.id))})}),e.jsx(Ce,{testid:"constraints-settings",title:"settings.json",children:e.jsxs("div",{className:"flex items-center gap-2 text-[12px] text-fg-dim",children:[e.jsx("span",{"data-testid":"constraints-settings-counts",className:"flex-1",children:h?`${h.allow} allow · ${h.deny} deny`:"— allow · — deny"}),e.jsx("button",{type:"button","data-testid":"constraints-open-settings",onClick:()=>window.dispatchEvent(new CustomEvent("sm:navigate",{detail:"settings"})),className:"text-[12px] font-medium text-accent hover:underline",children:"Open Settings ›"})]})})]})}function ua(t){return t?Pe[t]??(t.startsWith("#")?t:"#8a7a60"):"#8a7a60"}const wt={undecided:"#d3a23c",equipped:"#6f7d52",bare:"#9a9a9a",unbound:"#a3441f"},Ct={undecided:"Undecided",equipped:"Equipped",bare:"Bare",unbound:"Unbound"},ot=["low","medium","high","xhigh","max"];function St({name:t,color:n,size:s,badge:a}){const l=e.jsx("span",{"aria-hidden":"true",className:"inline-flex items-center justify-center rounded-full font-serif font-semibold text-white shrink-0",style:{width:s,height:s,background:ua(n),fontSize:Math.round(s*.45)},children:(t[0]??"?").toUpperCase()});return a?e.jsxs("span",{className:"relative inline-flex shrink-0",children:[l,e.jsx("span",{"data-testid":"agent-project-badge",title:a,className:"absolute -right-1 -bottom-1 w-5 h-5 rounded-full bg-[#6f7d52] border-2 border-bg text-white text-[10px] font-bold inline-flex items-center justify-center",children:(a[0]??"?").toUpperCase()})]}):l}function pa(){const[t,n]=d.useState(!1),s=d.useRef(!1);return d.useEffect(()=>{let l=!1;return Wt().then(o=>{!l&&!s.current&&typeof o.agentsListExpanded=="boolean"&&n(o.agentsListExpanded)}),()=>{l=!0}},[]),[t,()=>{s.current=!0;const l=!t;n(l),Gt({agentsListExpanded:l}).catch(()=>Z.error("Couldn't save the agent list layout."))}]}function xa({personas:t,selectedName:n,onPick:s}){return e.jsx("nav",{"data-testid":"agent-rail","aria-label":"Agents",className:"flex flex-col items-center gap-2",children:t.map(a=>{const l=ie(a),o=a.name===n;return e.jsxs("button",{type:"button","data-agent-rail":a.name,"data-loadout":l,"aria-label":`${a.name} — ${Ct[l]}`,"aria-current":o?"true":void 0,title:a.name,onClick:()=>s(a.name),className:`relative rounded-full p-0.5 focus:outline-none focus-visible:ring-2 focus-visible:ring-accent ${o?"ring-2 ring-accent":"hover:ring-2 hover:ring-line"}`,children:[e.jsx(St,{name:a.name,color:a.color,size:36}),e.jsx("span",{"data-testid":"agent-rail-dot","aria-hidden":"true",className:"absolute right-0 bottom-0 w-2.5 h-2.5 rounded-full border-2 border-bg-elev",style:{background:wt[l]}})]},a.name)})})}function ma({expanded:t,onToggle:n,list:s,personas:a,selectedName:l,onPick:o,detail:i}){return e.jsxs("div",{"data-testid":"config-workbench",className:"flex flex-1 min-h-0 min-w-0",children:[e.jsxs("div",{"data-testid":"agent-list-column","data-expanded":t?"true":"false",className:`${t?"w-[316px] px-4":"w-16 px-2 items-center"} shrink-0 bg-bg-elev border-r border-line py-[18px] flex flex-col gap-3 overflow-y-auto`,children:[e.jsx("button",{type:"button","data-testid":"agent-list-toggle","aria-expanded":t,"aria-label":t?"Collapse agent list":"Expand agent list",title:t?"Collapse agent list":"Expand agent list",onClick:n,className:`h-7 min-w-7 px-1.5 inline-flex items-center justify-center rounded-md border border-line bg-bg-hi text-fg-dim hover:text-fg ${t?"self-end":""}`,children:t?"«":"»"}),t?s:e.jsx(xa,{personas:a,selectedName:l,onPick:o})]}),e.jsx("div",{"data-testid":"config-workbench-detail",className:"flex-1 min-w-0 min-h-0 flex flex-col overflow-y-auto",children:i})]})}function fa({projects:t,selected:n,busy:s,onSelect:a}){const[l,o]=d.useState(!1);return e.jsxs("div",{className:"relative",children:[e.jsxs("button",{type:"button","data-testid":"agent-project-pill","aria-haspopup":"menu","aria-expanded":l,disabled:s,onClick:()=>o(i=>!i),className:"px-2.5 py-1 text-[12px] rounded-full bg-bg text-fg font-medium shadow-sm border border-accent max-w-[200px] truncate flex items-center gap-1.5",children:[e.jsx("span",{"aria-hidden":"true",className:"w-1.5 h-1.5 rounded-full bg-[#6f7d52]"}),n?`In ${n.name}`:"In project"," ▾"]}),l&&e.jsxs("div",{role:"menu","data-testid":"agent-project-menu",className:`absolute ${Ne.dialog} right-0 top-[34px] min-w-[180px] p-[5px] flex flex-col bg-bg-hi border border-line rounded-lg shadow-lg text-[13px] text-fg`,children:[t.map(i=>e.jsx("button",{type:"button",role:"menuitem","data-testid":"agent-project-option","data-cwd":i.cwd,onClick:()=>{o(!1),a(i.cwd)},className:"text-left px-2.5 py-1.5 rounded hover:bg-bg",children:i.name},i.cwd)),t.length===0&&e.jsx("div",{className:"px-2.5 py-1.5 text-fg-faint",children:"No open projects"})]})]})}function ga(){const t=[["Epic chat","the chat opens as this agent"],["Scheduler jobs","PRDs with this agentType"],["Tasks","headless runs that name it"]];return e.jsxs("section",{"data-testid":"agent-applies-to",className:"px-[18px] py-4 rounded-[14px] bg-bg-hi border border-line",children:[e.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-[0.1em] text-fg-faint",children:"This loadout applies to"}),e.jsx("ul",{className:"mt-2 flex flex-col gap-1.5 text-[13px] text-fg",children:t.map(([n,s])=>e.jsxs("li",{className:"flex items-baseline gap-2",children:[e.jsx("span",{className:"font-medium",children:n}),e.jsx("span",{className:"text-[11.5px] text-fg-faint",children:s})]},n))}),e.jsx("div",{className:"mt-2 text-[11.5px] text-fg-faint italic",children:"Changes apply to new sessions"})]})}const ha=[["name","name"],["description","description"],["tools","tools"],["model","model"],["effort","effort"],["color","colour"],["tags","tags"],["body","personality"],["agentCli","runs on"],["agentCliModel","CLI model"]];function ba(t,n,s){if(s||!n)return["new agent"];const a=ve(n);return ha.filter(([l])=>JSON.stringify(t[l])!==JSON.stringify(a[l])).map(([,l])=>l)}function va({obj:t,set:n,saved:s,dirty:a,isNew:l,busy:o,confirmDelete:i,setConfirmDelete:x,onDuplicate:j,onRevert:h,onSave:w,onDelete:u,onDropOverride:E,projects:k,selected:p,onSelect:C,onSaveOverride:O}){var Ke,Ve;const L=pe(),{catalog:b,loading:D,degraded:y,refresh:S}=Fe(null),{checking:N,recheck:A}=pt(),[W,f]=d.useState(!1),[F,z]=d.useState(!1),[B,ee]=d.useState(!1),[X,I]=d.useState(!1),G=!l&&s?s.path:`${L??"~"}/.claude/agents/${t.name}.md`,K=a||l,$=!l&&!!s&&(W||p!==null),P=$&&p?(Ke=s==null?void 0:s.overrideDetails)==null?void 0:Ke.find(v=>v.cwd===p.cwd):void 0,se=!!(P!=null&&P.bodyOverridden),Q=P?Es(P):{},m=s?ve(s):t,T={...m,...Q},_=$&&p?T:t,[V,te]=d.useState(!1),c=(s==null?void 0:s.name)??null;d.useEffect(()=>{te(!1)},[c]);const g=$&&p?Ls(m,Q,p.name):[],M=$&&p?((s==null?void 0:s.overrideDetails)??[]).filter(v=>v.cwd!==p.cwd&&k.some(U=>U.cwd===v.cwd)):[],q=$&&p?k.filter(v=>v.cwd!==p.cwd&&!M.some(U=>U.cwd===v.cwd)).length:0,ne=v=>{p&&!se&&!o&&O(Ps(Q,v))},J=v=>{const U={...Q};for(const oe of v)delete U[oe];O(U)},r=$&&p?ne:n,R=v=>g.some(U=>U.keys.includes(v)),H=K?ba(t,s,l):[],Y=s&&!l?ie(s):"undecided",ae=ta(_),ue=new Set(_.tools.map(v=>{var U;return(U=/^mcp__(.+?)__/.exec(v))==null?void 0:U[1]}).filter(Boolean)).size,We=_.tools.filter(v=>v!=="*"&&!v.startsWith("mcp__")).length,Ge=((Ve=_.packs)==null?void 0:Ve.length)??0,$t=ae==="unbound"?"every tool":ae==="bare"?"floor only":ae==="undecided"?"no decision — every tool":`${We} tool${We===1?"":"s"} · ${ue} server${ue===1?"":"s"} · ${Ge} pack${Ge===1?"":"s"}`;d.useEffect(()=>{if(!F)return;const v=U=>{U.key==="Escape"&&z(!1)};return window.addEventListener("keydown",v),()=>window.removeEventListener("keydown",v)},[F]);const Et=b?`Models live-read from claude${b.claudeVersion?` ${b.claudeVersion}`:""}${y?" (cached — CLI probe unavailable)":""}`:D?"Loading model catalog…":"Model catalog unavailable — showing the standard list",Pt=[{label:D||N?"Re-checking…":"Re-check models & CLIs",testId:"agent-detail-recheck",disabled:D||N,onSelect:()=>{S(),A()}},{label:Et,testId:"agent-detail-catalog-info",disabled:!0,info:!0,onSelect:()=>{}},{label:"Reveal in File Explorer",testId:"agent-detail-reveal",disabled:l,onSelect:()=>Ie(G)},...l?[]:[{label:"Delete agent…",testId:"agent-detail-delete",danger:!0,disabled:o,onSelect:()=>x(!0)}]],Lt=v=>{(v.ctrlKey||v.metaKey)&&v.key.toLowerCase()==="s"&&(v.preventDefault(),K&&!o&&w())},At=t.body.split(`
3
+ `).slice(0,9).join(`
4
+ `);return e.jsxs("div",{"data-testid":"agent-sheet",onKeyDown:Lt,className:"flex-1 shrink-0 min-h-full flex flex-col",children:[e.jsxs("div",{"data-testid":"agent-detail",className:"flex-1 shrink-0 flex flex-col",children:[e.jsxs("header",{"data-testid":"config-detail-header",className:"shrink-0 px-9 pt-6 pb-4 flex items-start gap-4 border-b border-line",children:[e.jsx(St,{name:t.name,color:t.color||null,size:56,badge:$&&p?p.name:void 0}),e.jsxs("div",{className:"flex-1 min-w-0 flex flex-col gap-1",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("h1",{className:"text-[22px] font-semibold text-fg font-mono truncate",children:t.name}),e.jsxs("span",{"data-testid":"agent-loadout-badge","data-loadout":ae,className:"inline-flex items-center gap-1.5 px-2 py-0.5 rounded-full border border-line bg-bg-hi text-[11px] text-fg-dim",children:[e.jsx("span",{"aria-hidden":"true",className:"w-2 h-2 rounded-full",style:{background:wt[ae]}}),Ct[ae]," · ",$t]}),(l||a)&&e.jsx("span",{"data-testid":"config-detail-pill",className:"px-2 py-0.5 rounded-full bg-accent/10 text-accent text-[11px] font-semibold",children:l?"unsaved draft":"edited"})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap text-[13px]",children:[e.jsx("span",{className:"font-serif italic text-fg-dim",children:t.description.split(/[.—]/)[0].trim()||"No description yet"}),e.jsx("span",{className:"text-[10.5px] uppercase tracking-[0.1em] text-fg-faint",children:"class"}),Be(t.tags).map(v=>{const U=Ee(v);return e.jsxs("span",{className:`px-2 py-0.5 rounded-full text-[11px] font-mono ${U.bg} ${U.text}`,children:["#",v]},v)})]}),e.jsx("div",{"data-testid":"agent-header-path",className:"text-[11px] text-fg-faint font-mono truncate",children:$&&p?`AGENT · PROJECT OVERLAY · ${ke(p.cwd,L)}/.claude/agents/${t.name}.md`:`AGENT · USER · ${ke(G,L)}`}),!$&&e.jsxs("details",{"data-testid":"agent-details",open:l||void 0,className:"group mt-1",children:[e.jsxs("summary",{className:"cursor-pointer select-none flex items-center gap-2 text-[11px] font-semibold uppercase tracking-[0.1em] text-fg-faint",children:[e.jsx("span",{children:"edit name · colour · tags"}),e.jsxs("span",{className:"normal-case tracking-normal font-normal font-mono text-fg-dim flex items-center gap-1.5",children:[t.color&&e.jsx("span",{className:"inline-block w-2.5 h-2.5 rounded-sm",style:{background:Pe[t.color]}}),t.color||"no colour"," · ",t.tags.length?t.tags.map(v=>`#${v}`).join(" "):"no tags"]})]}),e.jsxs("div",{className:"flex flex-col gap-3 pt-3",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Te,{children:"name"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("input",{"data-testid":"agent-detail-name","aria-label":"Name",value:t.name,onChange:v=>n({name:v.target.value.toLowerCase()}),className:"w-full max-w-sm bg-bg border border-line rounded px-2 py-1 text-xs text-fg font-mono"}),e.jsx("div",{className:"text-[11px] text-fg-faint mt-1 leading-snug",children:"Filename on disk — lowercase, hyphenated."})]})]}),e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Te,{children:"color"}),e.jsx("div",{className:"flex gap-1.5 pt-0.5",children:ys.map(v=>e.jsx("button",{type:"button",title:v||"none",onClick:()=>n({color:v}),className:"w-5 h-5 rounded",style:{background:v?Pe[v]:"transparent",border:t.color===v?"2px solid var(--accent, #b85c34)":"1px solid var(--line, #555)"}},v||"none"))})]}),e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Te,{children:"tags"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"flex flex-wrap gap-1.5",children:re.map(v=>{const U=t.tags.includes(v.tag),oe=Ee(v.tag);return e.jsxs("button",{type:"button",onClick:()=>n({tags:U?t.tags.filter(Tt=>Tt!==v.tag):[...t.tags,v.tag]}),className:`px-2 py-0.5 rounded-full text-[11px] font-mono border ${U?`${oe.bg} ${oe.text} ${oe.border?"border-current/30":"border-transparent"}`:"bg-bg-hi text-fg-faint border-line"}`,children:["#",v.tag]},v.tag)})}),e.jsx("div",{className:"text-[11px] text-fg-faint mt-1 leading-snug",children:"Session mission tags this persona is associated with — shown as the default agent on the Tags tab."})]})]})]})]})]}),e.jsxs("div",{className:"shrink-0 flex items-center gap-2",children:[e.jsx("div",{role:"group","aria-label":"Scope","data-testid":"agent-scope-switch",className:"inline-flex items-center p-0.5 rounded bg-bg-hi border border-line",children:["Global","In project"].map(v=>{const U=v==="In project"===$;return v==="In project"&&U?e.jsx(fa,{projects:k,selected:p,busy:o,onSelect:C},v):e.jsx("button",{type:"button","aria-pressed":U,disabled:v==="In project"&&(l||!s),onClick:()=>{v==="In project"?f(!0):(f(!1),C(null))},className:`px-2.5 py-1 text-[12px] rounded disabled:opacity-40 ${U?"bg-bg text-fg font-medium shadow-sm":"text-fg-dim hover:text-fg"}`,children:v},v)})}),e.jsx("button",{type:"button",onClick:j,disabled:o,className:"h-9 px-4 rounded-[10px] bg-bg-hi border border-line text-[13.5px] font-medium text-fg hover:border-rule disabled:opacity-40",children:"Duplicate"}),e.jsx(As,{items:Pt})]})]}),i&&e.jsxs("div",{"data-testid":"agent-detail-delete-confirm",role:"alert",className:"shrink-0 mx-9 mt-4 px-4 py-2.5 rounded-[10px] border border-red-400/40 bg-red-400/10 flex items-center gap-3 text-[13px] text-fg",children:[e.jsxs("span",{className:"flex-1 min-w-0",children:["Delete ",e.jsx("strong",{className:"font-mono",children:t.name})," and its file?"]}),e.jsx("button",{type:"button",onClick:u,disabled:o,className:"font-semibold text-red-400 hover:text-red-300",children:"Delete"}),e.jsx("button",{type:"button",onClick:()=>x(!1),className:"text-fg-faint hover:text-fg",children:"Keep"})]}),$&&!p?e.jsx("div",{"data-testid":k.length===0?"project-override-none":"project-override-unselected",className:"flex-1 px-9 py-6 text-[13px] text-fg-dim",children:k.length===0?"No open project tabs — open a project tab to override this agent for it.":`Pick an open project (In project ▾) to see ${t.name} as it runs there and override its model, effort, gear or environment for that project only.`}):e.jsxs("div",{"data-testid":"agent-detail-body",className:"flex-1 shrink-0 grid grid-cols-[minmax(0,1fr)_340px] gap-4 px-9 py-6 items-start",children:[e.jsxs("div",{className:"flex flex-col gap-4 min-w-0",children:[$&&p&&e.jsxs("section",{"data-testid":"agent-project-override",className:"px-[18px] py-3.5 rounded-[14px] border border-accent/40 bg-accent/5 flex items-center gap-3",children:[e.jsxs("span",{className:"px-2 py-0.5 rounded bg-accent text-white text-[10.5px] font-bold uppercase tracking-wide",children:[p.name," overlay"]}),e.jsxs("span",{className:"flex-1 text-[13px] text-fg",children:["Showing ",e.jsx("strong",{children:t.name})," as it runs in ",e.jsx("strong",{children:p.name}),". ",g.length?`This project overrides ${g.map(v=>v.label).join(", ")} — everything else comes from the global sheet.`:"Nothing is overridden yet — everything comes from the global sheet."]}),se&&e.jsx("span",{"data-testid":"project-override-fullbody",className:"text-[11px] text-amber-400",children:"full-body override — edit its file directly"}),P&&e.jsx("button",{type:"button","data-testid":"agent-reset-all",disabled:o,onClick:()=>E(p.cwd,p.name),className:"h-8 px-3 rounded-[10px] bg-bg border border-line text-[12.5px] font-medium text-fg hover:border-rule disabled:opacity-40",children:"Reset to global"})]}),e.jsx($e,{label:"DESCRIPTION",labelNote:"CLAUDE READS THIS TO PICK THE AGENT",children:e.jsx("textarea",{"data-testid":"agent-detail-description","aria-label":"Description",rows:2,value:t.description,readOnly:$,onKeyDown:v=>{v.key==="Enter"&&v.preventDefault()},onChange:v=>n({description:v.target.value.replace(/\r?\n/g," ")}),placeholder:"What this agent does — Claude reads it to decide when to use it",className:"w-full resize-none bg-transparent outline-none text-fg placeholder:text-fg-faint"})}),e.jsxs("section",{"data-testid":"agent-runtime-card",className:"px-[18px] py-4 rounded-[14px] bg-bg-hi border border-line flex flex-col gap-3",children:[e.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-[0.1em] text-fg-faint",children:"Stats"}),e.jsxs("div",{"data-testid":"agent-runtime-row",className:"grid grid-cols-3 gap-4",children:[e.jsxs("div",{className:"min-w-0","data-overridden":R("model")?"true":void 0,children:[$&&R("model")&&e.jsxs("div",{"data-testid":"agent-overridden-model",className:"mb-1 text-[10.5px] font-semibold uppercase tracking-wide text-accent",children:["overridden · global: ",m.model]}),e.jsx(Ds,{value:_.model,onChange:v=>r({model:v})})]}),e.jsxs("div",{className:"min-w-0","data-overridden":R("effort")?"true":void 0,children:[$&&R("effort")&&e.jsxs("div",{"data-testid":"agent-overridden-effort",className:"mb-1 text-[10.5px] font-semibold uppercase tracking-wide text-accent",children:["overridden · global: ",m.effort]}),e.jsxs("div",{className:"relative",children:[e.jsx(Ms,{value:_.effort,model:_.model,onChange:v=>r({effort:v})}),e.jsx("div",{"data-testid":"agent-effort-pips","aria-hidden":"true",className:"pointer-events-none absolute right-8 top-[22px] h-8 flex items-center gap-1",children:ot.map((v,U)=>e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${U<=ot.indexOf(_.effort)?"bg-fg-dim":"bg-line"}`},v))})]})]}),$?e.jsxs("div",{className:"min-w-0 text-[13px] font-mono text-fg-dim","data-testid":"agent-runs-on-readonly",children:["runs on ",t.agentCli," ",e.jsx("span",{className:"text-fg-faint",children:"(global)"})]}):e.jsxs("div",{className:"min-w-0 flex flex-col gap-1.5",children:[e.jsx(Os,{value:t.agentCli,onChange:v=>n({agentCli:v,agentCliModel:""})}),t.agentCli!=="claude"&&e.jsx("input",{"data-testid":"agent-persona-cli-model","aria-label":"CLI model",value:t.agentCliModel,maxLength:128,placeholder:"Blank = the CLI's own default",onChange:v=>n({agentCliModel:v.target.value}),className:"w-full bg-bg border border-line rounded-md px-2 py-1 text-xs text-fg font-mono"})]})]})]}),oa(Y==="undecided"&&!l&&!!s&&!$,t,(s==null?void 0:s.tools)??[],B,X)?e.jsx(ra,{obj:t,set:n,picking:B,setPicking:ee,onDismiss:()=>I(!0)}):e.jsx(aa,{obj:_,set:r,onOpenChange:te,...$&&p?{baseline:m,onRestore:J,projectName:p.name}:{}}),V&&e.jsx(it,{obj:_,set:r,collapsed:!0}),e.jsxs("section",{"data-testid":"agent-personality","data-busy":o?"true":void 0,className:"px-[18px] py-4 rounded-[14px] bg-bg-hi border border-line",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"flex-1 text-[11px] font-semibold uppercase tracking-[0.1em] text-fg-faint",children:["Personality & grounding ",e.jsx("span",{className:"font-serif italic normal-case tracking-normal font-normal text-fg-dim",children:"the persona body"})]}),!$&&e.jsx("button",{type:"button","data-testid":"agent-open-editor",onClick:()=>z(!0),className:"h-8 px-3 rounded-[10px] bg-bg border border-line text-[12.5px] font-medium text-fg hover:border-rule",children:"Open editor"})]}),e.jsx("pre",{"data-testid":"agent-personality-preview",className:"mt-2 max-h-44 overflow-hidden whitespace-pre-wrap font-sans text-[13px] leading-relaxed text-fg-dim",children:At||"No personality text yet."})]})]}),e.jsx("div",{className:"flex flex-col gap-4 min-w-0",children:!V&&e.jsxs(e.Fragment,{children:[$&&p&&e.jsxs("section",{"data-testid":"agent-changed-card",className:"px-[18px] py-4 rounded-[14px] bg-bg-hi border border-line",children:[e.jsxs("div",{className:"text-[11px] font-semibold uppercase tracking-[0.1em] text-fg-faint",children:["Changed in ",p.name," ",e.jsx("span",{className:"font-normal",children:g.length})]}),g.length===0&&e.jsx("div",{className:"mt-2 text-[12px] italic text-fg-faint",children:"Same as global."}),g.map(v=>e.jsxs("div",{"data-testid":`agent-overridden-${v.label}`,className:"mt-2 pt-2 border-t border-line first:border-0 first:pt-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"flex-1 text-[12.5px] font-mono text-fg",children:v.label}),e.jsx("span",{className:"px-1.5 rounded bg-accent/10 text-accent text-[10px] font-semibold uppercase",children:"overridden"}),e.jsx("button",{type:"button","data-testid":`agent-reset-${v.label}`,disabled:o||se,onClick:()=>J(v.keys),className:"text-[11.5px] text-accent hover:underline disabled:opacity-40",children:"Reset to global"})]}),v.lines.map(U=>e.jsx("div",{className:"text-[12px] font-mono text-fg-dim",children:U},U))]},v.label))]}),e.jsx(it,{obj:_,set:r}),$&&p&&e.jsxs("section",{"data-testid":"agent-other-projects",className:"px-[18px] py-4 rounded-[14px] bg-bg-hi border border-line",children:[e.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-[0.1em] text-fg-faint",children:"Other open projects"}),M.map(v=>{var U;return e.jsxs("div",{"data-testid":"agent-other-project","data-cwd":v.cwd,className:"mt-2 flex items-center gap-2 text-[12.5px]",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-accent"}),e.jsx("strong",{className:"text-fg",children:((U=k.find(oe=>oe.cwd===v.cwd))==null?void 0:U.name)??v.project}),e.jsx("span",{className:"flex-1 text-fg-dim",children:vt(v).join(", ")||"overlay"}),e.jsx("button",{type:"button","data-testid":"agent-other-project-view",onClick:()=>C(v.cwd),className:"text-accent hover:underline",children:"View ›"})]},v.cwd)}),e.jsxs("div",{className:"mt-2 text-[12px] text-fg-faint",children:[M.length===0?"No other open project overrides this agent.":"",q>0?`${q} more use the global sheet.`:""]})]}),e.jsx(ga,{})]})})]}),$?e.jsx("div",{"data-testid":"agent-project-bar",role:"status",className:"sticky bottom-0 shrink-0 px-9 py-3 border-t border-line bg-bg-elev text-[13px] text-fg-dim",children:p?`Project edits write on change to ${ke(p.cwd,L)}/.claude/agents/${t.name}.md · apply to new sessions in ${p.name}`:"Choose a project — project edits write on change"}):e.jsxs("div",{"data-testid":"agent-save-bar",role:"status",className:"sticky bottom-0 shrink-0 px-9 py-3 flex items-center gap-3 border-t border-line bg-bg-elev text-[13px]",children:[e.jsx("span",{"data-testid":"agent-save-summary",className:"flex-1 min-w-0 truncate text-fg-dim",children:K?`${H.length} unsaved change${H.length===1?"":"s"} · ${H.join(", ")} · applies to new sessions only`:"No unsaved changes"}),e.jsx("button",{type:"button","data-testid":"agent-revert",onClick:h,disabled:!K||o,className:"h-9 px-4 rounded-[10px] bg-bg-hi border border-line font-medium text-fg hover:border-rule disabled:opacity-40",children:"Revert"}),e.jsxs("button",{type:"button","data-testid":"agent-save",onClick:()=>{o||w()},disabled:!K||o,className:"h-9 px-4 rounded-[10px] bg-accent text-white font-semibold disabled:opacity-40",children:["Save ",e.jsx("span",{className:"font-normal opacity-80 text-[11px]",children:"Ctrl S"})]})]})]}),F&&e.jsxs("div",{"data-testid":"agent-detail-editor","data-busy":o?"true":void 0,role:"dialog","aria-label":`Edit ${t.name} personality`,className:`fixed inset-0 ${Ne.dialog} flex flex-col bg-bg`,children:[e.jsxs("div",{className:"flex items-center gap-3 px-4 h-11 shrink-0 border-b border-line bg-bg-elev",children:[e.jsx("span",{className:"flex-1 min-w-0 truncate text-[12px] font-mono text-fg-dim",children:ke(G,L)}),e.jsx("button",{type:"button","data-testid":"agent-editor-close",onClick:()=>z(!1),className:"px-3 py-1 rounded-md border border-line text-[12.5px] text-fg hover:bg-bg-hi",children:"Done"})]}),e.jsx("div",{className:"flex-1 min-h-0 grid",children:e.jsx(xn,{path:G,value:t.body,defaultMode:"document",dirty:K,isNew:l,onChange:v=>n({body:v}),onSave:()=>{o||w()},onRevert:h})})]})]})}function ja({persona:t,onDone:n}){const s=t.upgrade,[a,l]=d.useState(!1),o=d.useMemo(()=>s?Kt(t.body,s.bundledBody):null,[t.body,s]);if(!s||!o)return null;const i=async h=>{l(!0);try{Z.info(await h()),await n()}catch(w){Z.error(w.message||"failed to update agent")}finally{l(!1)}},x=()=>i(async()=>{const h=await window.api.agents.takeBundledPersona({name:t.name});return`updated ${t.name} to v${h.seedVersion}; old copy saved at ${h.backupPath}`}),j=()=>i(async()=>(await window.api.agents.dismissPersonaUpgrade({name:t.name,bundledVersion:s.bundledVersion}),`keeping your ${t.name}`));return e.jsxs("div",{"data-testid":"persona-upgrade-notice",className:"m-2 rounded border border-line bg-bg-hi p-3 text-xs text-fg flex flex-col gap-2",children:[e.jsxs("div",{children:["A newer ",t.name," is available (v",s.installedVersion," installed, v",s.bundledVersion," bundled).",s.edited?" You edited this agent, so your edits were kept and it was not updated automatically.":""]}),e.jsxs("details",{children:[e.jsxs("summary",{className:"cursor-pointer text-accent",children:["Show changes (+",o.added," / -",o.removed,")"]}),e.jsx("pre",{className:"mt-1 max-h-64 overflow-auto font-mono text-[11px] whitespace-pre-wrap",children:o.lines.map((h,w)=>e.jsxs("div",{"data-diff":h.type,className:h.type==="context"?"text-fg-dim":h.type==="add"?"text-accent":"text-fg line-through",children:[h.type==="add"?"+ ":h.type==="remove"?"- ":" ",h.text]},w))})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"button","data-testid":"persona-upgrade-take",disabled:a,onClick:x,className:"rounded border border-accent px-2 py-1 text-accent hover:bg-bg-elev disabled:opacity-50",children:"Take the new version"}),e.jsx("button",{type:"button","data-testid":"persona-upgrade-keep",disabled:a,onClick:j,className:"rounded border border-line px-2 py-1 text-fg hover:bg-bg-elev disabled:opacity-50",children:"Keep mine"})]})]})}function Na(t){return t.length===0?"bare":t.includes("*")?"unbound":"equipped"}function ka(t){const n=new Map;for(const s of t){const a=typeof s.cwd=="string"?Ht(s.cwd):"";a&&!n.has(a)&&n.set(a,{cwd:a,name:Jt(a)})}return[...n.values()].sort((s,a)=>s.name.localeCompare(a.name)||s.cwd.localeCompare(a.cwd))}function ya(t){return(t.overrideDetails??[]).map(n=>`${n.project}: ${vt(n).join(", ")||"overlay"}`).join(`
5
+ `)}const wa=[{key:"personas",label:"Personas"},{key:"tags",label:"Tags"}];function Ca(){const[t,n]=d.useState("personas"),[s,a]=pa(),{personas:l,refresh:o}=_e(r=>Z.error(r.message||"failed to load agent personas")),[i,x]=d.useState(null),[j,h]=d.useState(""),[w,u]=d.useState(null),[E,k]=d.useState(!1),[p,C]=d.useState(!1),[O,L]=d.useState(null),[b,D]=d.useState(!1),y=d.useRef(!0);d.useEffect(()=>()=>{y.current=!1},[]);const S=Vt(r=>r.tabs),N=d.useMemo(()=>ka(S),[S]),[A,W]=d.useState(null),f=N.find(r=>r.cwd===A)??null,F=async r=>{await o()&&r&&x(r)};bt(N.map(r=>r.cwd),()=>F()),d.useEffect(()=>{const r=Yt();r&&x(r);const R=H=>x(H.detail);return window.addEventListener("sm:select-persona",R),()=>window.removeEventListener("sm:select-persona",R)},[]);const z=ce(r=>r.tab),B=ce(r=>r.id),ee=ce(r=>r.clear);d.useEffect(()=>{if(z!=="agents"||!B||l===null)return;const r=B.startsWith("agents:")?B.slice(7):null;r&&l.some(R=>R.name===r)&&(n("personas"),h(""),u(null),k(!1),C(!1),L(null),x(r)),ee()},[z,B,l,ee]);const X=(l??[]).filter(r=>ie(r)==="undecided").length,I=e.jsxs(mt,{eyebrow:"AGENTS FOLDER",badge:l==null?void 0:l.length,path:"~/.claude/agents/",note:"The actor a session opens with — “you are acting as …”",children:[e.jsx("div",{role:"group","aria-label":"Agents view","data-testid":"agent-view-switch",className:"mt-1 self-start inline-flex items-center p-0.5 rounded bg-bg-hi border border-line",children:wa.map(r=>e.jsx("button",{type:"button",onClick:()=>n(r.key),"aria-pressed":t===r.key,className:`px-2.5 py-0.5 text-[11px] rounded transition-colors ${t===r.key?"bg-bg text-fg font-medium shadow-sm":"text-fg-dim hover:text-fg"}`,children:r.label},r.key))}),X>0&&e.jsxs("span",{"data-testid":"agent-folder-undecided",className:"mt-1 text-[11px] text-fg-dim",children:[X," undecided"]})]});if(t==="tags")return e.jsx("div",{className:"flex flex-col h-full min-h-0",children:e.jsx(gt,{list:I,detail:e.jsx(fs,{onOpenPersona:r=>{x(r),u(null),k(!1),n("personas")}})})});if(l===null)return e.jsx(le,{title:"loading…"});const G=j.toLowerCase(),K=l.filter(r=>!G||r.name.toLowerCase().includes(G)||(r.description??"").toLowerCase().includes(G)),$=l.find(r=>r.name===i)??null,P=w??($?ve($):null),se=!!w&&!!$&&JSON.stringify(w)!==JSON.stringify(ve($)),Q=E,m=r=>{u(null),k(!1),C(!1),L(null),x(r)},T=r=>u(R=>({...R??($?ve($):Qe),...Cs(r)})),_=()=>{u({...Qe}),k(!0),C(!1)},V=()=>{P&&(u({...P,name:P.name+"-copy"}),k(!0))},te=()=>{u(null),k(!1)},c=async()=>{if(P){if(!/^[a-z][a-z0-9-]*$/.test(P.name)){Z.error('agent name must be lowercase, hyphenated (e.g. "my-agent")');return}D(!0);try{const r=Q?null:$,R={name:P.name,originalName:r==null?void 0:r.name,description:P.description,tools:P.tools,model:P.model,effort:P.effort,color:P.color,tags:Be(P.tags),body:P.body,agentCli:P.agentCli,...P.mcpServers?{mcpServers:P.mcpServers}:{},...P.packs?{packs:P.packs}:{},...P.environment?{environment:P.environment}:{},...Xe(P)?{loadout:Xe(P)}:{},...P.agentCli!=="claude"&&P.agentCliModel.trim()?{agentCliModel:P.agentCliModel.trim()}:{}},H=r?zs(r,R):R;"agentCliModel"in R||delete H.agentCliModel,"mcpServers"in R||delete H.mcpServers,"packs"in R||delete H.packs,"environment"in R||delete H.environment,await window.api.agents.savePersona(H),Z.info(Q?`created ${P.name}`:`saved ${P.name}`),u(null),k(!1),await F(P.name)}catch(r){Z.error(r.message||"failed to save agent persona")}finally{D(!1)}}},g=async()=>{if($){D(!0);try{await window.api.agents.deletePersona({name:$.name}),Z.info(`deleted ${$.name}`),C(!1),u(null),k(!1),await F()}catch(r){Z.error(r.message||"failed to delete agent persona")}finally{D(!1)}}},M=async r=>{D(!0);try{await window.api.agents.deletePersona({name:r}),Z.info(`deleted ${r}`),L(null),i===r&&(u(null),k(!1)),await F()}catch(R){Z.error(R.message||"failed to delete agent persona")}finally{D(!1)}},q=async(r,R)=>{if($)try{await window.api.agents.removeOverride({name:$.name,projectCwd:r}),Z.info(`removed ${R}'s override of ${$.name}`),await F($.name)}catch(H){Z.error(H.message||"failed to remove override")}},ne=async r=>{if(!$||!f)return;const{cwd:R,name:H}=f;D(!0);try{Object.keys(r).length===0?(await window.api.agents.removeOverride({name:$.name,projectCwd:R}),Z.info(`cleared ${H}'s override of ${$.name}`)):(await window.api.agents.savePersona({name:$.name,projectCwd:R,description:"",tools:r.tools??[],color:"",tags:[],body:"",...r.model?{model:r.model}:{},...r.effort?{effort:r.effort}:{},...r.tools?{loadout:Na(r.tools)}:{},...r.mcpServers?{mcpServers:r.mcpServers}:{},...r.packs?{packs:r.packs}:{},...r.environment?{environment:r.environment}:{}}),Z.info(`saved ${H}'s override of ${$.name}`)),await F($.name)}catch(Y){Z.error(Y.message||"failed to save project override")}finally{D(!1)}};if(!i&&!E)return e.jsx("div",{className:"flex flex-col h-full min-h-0",children:e.jsx(Js,{personas:l,filter:j,onFilterChange:h,onOpen:r=>m(r),onNew:_,view:t,onView:n})});const J=e.jsxs(e.Fragment,{children:[I,e.jsx("button",{type:"button","data-testid":"agent-back-to-roster",onClick:()=>{u(null),k(!1),C(!1),L(null),x(null)},className:"self-start text-[11px] text-fg-dim hover:text-fg",children:"← All agents"}),e.jsx(ft,{filter:j,onFilterChange:h,placeholder:"Filter",primaryLabel:"+ New",onPrimary:_}),e.jsxs("div",{role:"listbox","aria-label":"Agents",className:"flex flex-col gap-0.5",children:[Q&&P&&e.jsx("div",{"data-agent-row-new":"",children:e.jsx(Oe,{title:P.name,trailing:e.jsx("span",{className:"text-[10px] font-semibold text-accent",children:"new"}),meta:P.description||void 0,selected:!0,onSelect:()=>{}})}),K.length===0&&!Q?e.jsx("div",{className:"px-3 py-1 text-xs text-fg-faint italic",children:"no agent personas found"}):K.map(r=>{const R=!Q&&r.name===($==null?void 0:$.name),H=R&&se,Y=O===r.name;return e.jsx("div",{"data-agent-row":r.name,className:"group",children:e.jsx(Oe,{title:r.name,selected:R,onSelect:()=>m(r.name),meta:e.jsxs("span",{"data-testid":"agent-row-loadout",className:"inline-flex items-center gap-1.5",children:[e.jsx("span",{"aria-hidden":"true",className:"w-2 h-2 rounded-full shrink-0",style:{background:Bs[ie(r)]}}),qs(r)]}),trailing:e.jsxs("span",{className:"flex items-center gap-1.5",children:[H&&e.jsx("span",{className:"text-[10px] font-semibold text-accent",children:"unsaved"}),r.upgrade&&e.jsx("span",{"data-testid":`agent-row-upgrade-${r.name}`,children:e.jsx(He,{tone:"accent",children:"update"})}),!H&&r.overridingProjects.length>0&&e.jsx("span",{title:ya(r),children:e.jsxs(He,{tone:"dim",children:[r.overridingProjects.length," override",r.overridingProjects.length>1?"s":""]})}),e.jsx("span",{"data-testid":"agent-row-model",className:"font-mono",children:r.model??"inherit"}),Y?e.jsxs("span",{className:"flex items-center gap-1",onClick:ae=>ae.stopPropagation(),children:[e.jsx("button",{type:"button",onClick:()=>M(r.name),disabled:b,title:`Delete ${r.name}`,className:"text-[10px] font-semibold text-red-400 hover:text-red-300",children:"confirm"}),e.jsx("button",{type:"button",onClick:()=>L(null),title:"Cancel",className:"text-[10px] text-fg-faint hover:text-fg",children:"cancel"})]}):e.jsx("button",{type:"button",onClick:ae=>{ae.stopPropagation(),L(r.name)},title:`Delete ${r.name}`,"aria-label":`Delete ${r.name}`,className:"opacity-0 group-hover:opacity-100 focus-visible:opacity-100 text-fg-faint hover:text-red-400 transition-opacity",children:"×"})]})})},r.name)})]})]});return e.jsx("div",{className:"flex flex-col h-full min-h-0",children:e.jsx(ma,{expanded:s,onToggle:a,list:J,personas:K,selectedName:Q?null:($==null?void 0:$.name)??null,onPick:m,detail:P?e.jsxs(e.Fragment,{children:[($==null?void 0:$.upgrade)&&!Q&&e.jsx(ja,{persona:$,onDone:()=>F($.name)}),e.jsx(va,{obj:P,set:T,saved:$,dirty:se,isNew:Q,busy:b,confirmDelete:p,setConfirmDelete:C,onDuplicate:V,onRevert:te,onSave:c,onDelete:g,onDropOverride:q,projects:N,selected:f,onSelect:W,onSaveOverride:ne})]}):e.jsx(le,{title:"select an agent"})})})}const Sa=d.memo(Ca),$a={"claude-md":"system-prompt",settings:"settings",mcp:"extensions",skills:"extensions",plugins:"extensions",agents:"agent-library"},Ea={skills:"Add skill",mcp:"Add MCP server",plugins:"Add plugin"},he=t=>t??void 0;async function rt(t){try{return await t()}catch{return null}}function Pa(){const t=pe(),[n,s]=d.useState({claudeMd:null,settings:null}),a=d.useRef(0),l=t?`${t}/.claude/CLAUDE.md`:null,o=t?`${t}/.claude/settings.json`:null,i=d.useCallback(()=>{if(!l||!o)return;const x=++a.current;Promise.all([rt(()=>$n(l)),rt(()=>En(o))]).then(([j,h])=>{x===a.current&&s({claudeMd:j,settings:h})})},[l,o]);return d.useEffect(()=>(i(),()=>{a.current++}),[i]),de([l,o],i),n}const La=()=>Pn({scope:"home",cwd:null,api:window.api});function Aa({initialTab:t="claude-md"}){const[n,s]=d.useState(t),[a,l]=d.useState(!1),[o,i]=d.useState({scope:"user",cwd:null}),x=Fn(),{personas:j}=_e(),h=Pa(),w=mn(fn),u=d.useMemo(()=>gn(w),[w]),E=je(N=>N.panelTabHint);d.useEffect(()=>{if(!E||E.id!=="claude-config")return;const[N,A]=E.tab.split(":");Je(N)&&(s(N),l(!1)),je.setState({panelTabHint:N==="settings"&&A?{id:"settings",tab:A}:null})},[E]);const k=d.useCallback(N=>{s(N),l(!1)},[]),p=d.useCallback(()=>l(!1),[]),C=d.useCallback(()=>l(!0),[]),O=d.useCallback(N=>{i(N),l(!0)},[]),L=d.useCallback(N=>{Je(N.tab)&&(k(N.tab),ce.getState().set(N.tab,N.id))},[k]),b=hn({load:La,loadKey:"home",onChoose:L}),D=d.useMemo(()=>{const N={"claude-md":bn(h.claudeMd),settings:{count:he(h.settings)},mcp:{count:he(x.mcp),attention:u},skills:{count:he(x.skills)},plugins:{count:he(x.plugins)},agents:{count:he(j==null?void 0:j.length)}};return zt.map(A=>({...A,...N[A.key]}))},[h.claudeMd,h.settings,x.mcp,x.skills,x.plugins,j,u]),y=Xt[$a[n]],S=n==="skills"||n==="mcp"||n==="plugins"?n:null;return e.jsxs(vn,{testId:"home-claude-config",eyebrow:"CLAUDE CODE · GLOBAL",title:"Claude config",scopePath:"~/.claude",tabs:D,activeKey:n,onSelect:k,search:b,learn:y,drawer:S&&e.jsxs(yn,{open:a,onClose:p,title:Ea[S],keyVals:[],children:[S==="skills"&&e.jsx(wn,{}),S==="mcp"&&e.jsx(Cn,{scope:o.scope,cwd:o.cwd}),S==="plugins"&&e.jsx(Sn,{})]}),children:[n==="claude-md"&&e.jsx(Wn,{}),n==="settings"&&e.jsx(jn,{scope:"user"}),n==="mcp"&&e.jsx(Nn,{onAdd:O,scope:"user"}),n==="skills"&&e.jsx(kn,{onAdd:C,scope:"user"}),n==="plugins"&&e.jsx(cs,{onAdd:C,onJump:k}),n==="agents"&&e.jsx(Sa,{})]})}const _a=d.memo(Aa);export{_a as HomeClaudeConfig};
@@ -1 +1 @@
1
- import{aC as e}from"./index-CdTppjKR.js";function n({toolbar:s,footer:l,children:r}){return e.jsxs("div",{className:"h-full flex flex-col",children:[s&&e.jsx("div",{className:"shrink-0 border-b border-line bg-bg-elev px-3 py-1.5 flex items-center gap-2 text-xs",children:s}),e.jsx("div",{className:"flex-1 min-h-0 overflow-auto",children:r}),l&&e.jsx("div",{className:"shrink-0 border-t border-line bg-bg-elev",children:l})]})}export{n as P};
1
+ import{aD as e}from"./index-hXRNm0UJ.js";function n({toolbar:s,footer:l,children:r}){return e.jsxs("div",{className:"h-full flex flex-col",children:[s&&e.jsx("div",{className:"shrink-0 border-b border-line bg-bg-elev px-3 py-1.5 flex items-center gap-2 text-xs",children:s}),e.jsx("div",{className:"flex-1 min-h-0 overflow-auto",children:r}),l&&e.jsx("div",{className:"shrink-0 border-t border-line bg-bg-elev",children:l})]})}export{n as P};
@@ -0,0 +1,26 @@
1
+ import{aT as l,bc as A,aD as e,aq as _t,aX as Bt,a9 as pe,ap as Ut,bn as at,bd as rt,m as we,bs as Kt,L as Wt,bi as Ht,C as Ke,ac as We,aE as Vt}from"./index-hXRNm0UJ.js";import{p as ot,d as Gt,D as Yt,G as xe,J as zt,B as qt,v as Xt,u as Jt,F as Qt,l as Zt,C as es,i as ts,j as ss,H as ns,M as as,a as rs,I as os,S as ls,m as is,n as He}from"./Skills-BiW2lCnD.js";import{s as ds}from"./Toggle-WFBYo8JI.js";import{V as cs}from"./VoiceButton-DZu8dTpO.js";import"./monaco-editor-BsIlgG7c.js";import"./Panel-CwsOJ0nI.js";import"./TiptapBody-CYTkQiva.js";const Ve=["bg-accent","bg-sage-dark","bg-honey","bg-fg-dim","bg-fg-faint","bg-hive-teal","bg-butter","bg-delta-bad"],lt=864e5,ms="MEMORY.md",Ge=2e3,Me=s=>s.replace(/\.md$/,"");function it(s,t,n,d){var y,x,c;const i=new Map(((t==null?void 0:t.entries)??[]).map(u=>[u.name,u])),a=new Set(((y=t==null?void 0:t.index)==null?void 0:y.orphans)??[]),m=new Map;for(const u of(n==null?void 0:n.clusters)??[])for(const f of u.memberSlugs)m.has(f)||m.set(f,u.id);const g=s.filter(u=>u.name!==ms),p=new Map;for(const u of g){const f=Me(u.name),k=((x=i.get(u.name))==null?void 0:x.outLinks)??((c=i.get(f))==null?void 0:c.outLinks)??[];for(const w of k){const $=Me(w),b=p.get($)??[];b.includes(f)||b.push(f),p.set($,b)}}return g.map(u=>{const f=Me(u.name),k=i.get(u.name)??i.get(f),w=(k==null?void 0:k.deadRefs)??[],$=(k==null?void 0:k.danglingLinks)??[],b=(k==null?void 0:k.stale)??!1;return{name:u.name,slug:f,path:u.path,description:(k==null?void 0:k.description)??"",bytes:u.bytes,mtimeMs:u.mtimeMs,ageDays:Math.floor((d-u.mtimeMs)/lt),stale:b,staleReasons:(k==null?void 0:k.reasons)??[],ageOnlyStale:b&&w.length===0,deadRefs:w,movedRefs:(k==null?void 0:k.movedRefs)??[],broken:w.length>0||$.length>0,danglingLinks:$,outLinks:(k==null?void 0:k.outLinks)??[],inLinks:p.get(f)??[],notIndexed:a.has(u.name)||a.has(f),clusterId:m.get(f)??null,type:(k==null?void 0:k.type)??null,originSessionId:(k==null?void 0:k.originSessionId)??null}})}function us(s,t){const n=new Set(t.filter(d=>d.stale).map(d=>d.slug));return((s==null?void 0:s.clusters)??[]).map((d,i)=>({id:d.id,name:d.name,summary:d.summary,memberSlugs:d.memberSlugs,linkCount:d.links.length,retireCount:d.links.filter(a=>/retire/i.test(a.label??"")).length,staleCount:d.memberSlugs.filter(a=>n.has(a)).length,dotClass:Ve[i%Ve.length]}))}function xs(s,t,n){const d=t.trim().toLowerCase(),i=d?s.filter(a=>a.slug.toLowerCase().includes(d)||a.description.toLowerCase().includes(d)):s;return n===void 0?i:i.slice(0,n)}function ue(s,t,n){let d;return t==="ask"||t==="clusters"||t==="archived"?[]:(t==="all"?d=s:t==="stale"?d=s.filter(i=>i.stale):t==="broken"?d=s.filter(i=>i.broken):t==="recent"?d=s.filter(i=>Date.now()-i.mtimeMs<=7*lt):t==="unindexed"?d=s.filter(i=>i.notIndexed):t==="cluster:unclustered"?d=s.filter(i=>i.clusterId===null):t.startsWith("cluster:")?d=s.filter(i=>i.clusterId===t.slice(8)):d=s,xs(d,n))}function ps(s,t){const n=[...s];return t==="recent"?n.sort((d,i)=>i.mtimeMs-d.mtimeMs):t==="name"?n.sort((d,i)=>d.slug<i.slug?-1:d.slug>i.slug?1:0):n.sort((d,i)=>i.bytes-d.bytes),n}function fs(s){return{all:s.length,stale:ue(s,"stale","").length,broken:ue(s,"broken","").length,recent:ue(s,"recent","").length,unindexed:ue(s,"unindexed","").length}}function dt(s){return s.toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,"")||"untitled_memory"}function hs(s,t){const n=s===""?[]:s.split(`
2
+ `),d=t===""?[]:t.split(`
3
+ `);if(n.length>Ge||d.length>Ge)return[...n.map(x=>({sign:"−",text:x})),...d.map(x=>({sign:"+",text:x}))];const i=n.length,a=d.length,m=Array.from({length:i+1},()=>new Array(a+1).fill(0));for(let x=i-1;x>=0;x--)for(let c=a-1;c>=0;c--)m[x][c]=n[x]===d[c]?m[x+1][c+1]+1:Math.max(m[x+1][c],m[x][c+1]);const g=[];let p=0,y=0;for(;p<i&&y<a;)n[p]===d[y]?(p++,y++):m[p+1][y]>=m[p][y+1]?g.push({sign:"−",text:n[p++]}):g.push({sign:"+",text:d[y++]});for(;p<i;)g.push({sign:"−",text:n[p++]});for(;y<a;)g.push({sign:"+",text:d[y++]});return g}const U=s=>s instanceof Error?s.message:String(s);function Ye(s){const t=/^---\r?\n[\s\S]*?\r?\n---[ \t]*(?:\r?\n|$)/.exec(s);return t?{front:t[0],body:s.slice(t[0].length)}:{front:"",body:s}}function gs(s){return s.split(`
4
+ `).map(t=>t.trim()).find(t=>t.length>0)??""}function bs(s,t){const n=s.kind==="agent"?s.agent:null,d=n?`${n.name}|${n.memoryScope??""}`:"",i=n!==null&&n.memoryScope===null,a=l.useMemo(()=>i?null:n&&n.memoryScope?{agent:{name:n.name,scope:n.memoryScope},...t?{cwd:t}:{}}:{workspace:ot(t),...t?{cwd:t}:{}},[d,i,t]),m=n===null,[g,p]=l.useState(!0),[y,x]=l.useState([]),[c,u]=l.useState(null),[f,k]=l.useState(null),[w,$]=l.useState(!1),[b,M]=l.useState(""),[K,z]=l.useState(!0),[ne,S]=l.useState([]),[D,L]=l.useState([]),[fe,Ne]=l.useState({}),[q,H]=l.useState(()=>Date.now()),ae=l.useRef(a);ae.current=a;const I=l.useCallback(async()=>{if(!a){x([]),u(null),k(null),S([]),M(""),p(!1);return}try{const o=await window.api.memory.list(a);if(ae.current!==a)return;x(o.entries??[]),M(o.dir??""),z(o.autoMemoryEnabled!==!1),o.error&&A.error(`Memory list failed: ${o.error}`);const[v,j]=await Promise.all([window.api.memory.stale(a).catch(C=>(A.error(`Memory staleness check failed: ${U(C)}`),null)),window.api.memory.listArchived(a).catch(()=>({names:[],error:null}))]);if(ae.current!==a)return;u(v),S(j.names??[]),H(Date.now())}catch(o){A.error(`Memory list failed: ${U(o)}`)}finally{p(!1)}},[a]);l.useEffect(()=>{p(!0),k(null),I(),a&&m&&a.workspace&&window.api.memory.aggregate(a.workspace,!1,t??void 0).then(o=>{ae.current===a&&k(o)}).catch(o=>A.error(`Memory clusters failed: ${U(o)}`))},[I]),l.useEffect(()=>{let o=!1;return(async()=>{try{const{agents:v}=await window.api.memory.agents(t??void 0);if(o)return;L(v);const j={};await Promise.all(v.filter(C=>C.memoryScope).map(async C=>{const O=await window.api.memory.list({agent:{name:C.name,scope:C.memoryScope},...t?{cwd:t}:{}});j[C.name]=(O.entries??[]).filter(R=>R.name!=="MEMORY.md").length})),o||Ne(j)}catch(v){o||A.error(`Memory agents failed: ${U(v)}`)}})(),()=>{o=!0}},[t]),l.useEffect(()=>{if(!b)return;const o=b;window.api.config.watch([o]);const v=window.api.config.onChanged(({path:j})=>{(j===o||j.startsWith(o+"/"))&&I()});return()=>{v(),window.api.config.unwatch([o])}},[b,I]);const P=l.useMemo(()=>it(y,c,f,q),[y,c,f,q]),de=l.useMemo(()=>us(f,P),[f,P]),Ce=l.useMemo(()=>({generatedAt:(f==null?void 0:f.generatedAt)??null,running:w}),[f,w]),_=l.useCallback(async o=>{if(!a)return null;try{const v=await window.api.memory.read(o,a);return v.error?(A.error(`Memory read failed: ${v.error}`),null):v.content}catch(v){return A.error(`Memory read failed: ${U(v)}`),null}},[a]),E=l.useCallback(async(o,v)=>{try{const j=await v();return j.ok?(await I(),!0):(A.error(`${o} failed: ${j.error??"unknown error"}`),!1)}catch(j){return A.error(`${o} failed: ${U(j)}`),!1}},[I]),X=l.useCallback(async(o,v)=>{if(!a)return!1;const j=await _(o);if(j===null)return!1;const{front:C}=Ye(j);return E("Memory save",()=>window.api.memory.write(o,C+v,a))},[a,_,E]),V=l.useCallback(async(o,v)=>a?E("Memory save",()=>window.api.memory.write(o,v,a)):!1,[a,E]),W=l.useCallback(async(o,v)=>{if(!a)return null;const j=dt(o),C=gs(v);if(!await E("Memory create",()=>window.api.memory.create(j,C,a)))return null;const R=`---
5
+ name: ${j}
6
+ description: ${C}
7
+ ---
8
+
9
+ ${v}
10
+ `;return await E("Memory create",()=>window.api.memory.write(j,R,a))?j:null},[a,E]),re=l.useCallback(async o=>{var O,R;if(!a)return null;const v=await _(o);if(v===null||!await E("Memory delete",()=>window.api.memory.delete(o,a)))return null;const C=((R=(O=Ye(v).front.match(/^description:\s*(.*)$/m))==null?void 0:O[1])==null?void 0:R.trim())??"";return async()=>{await E("Memory undo",()=>window.api.memory.create(o,C,a))&&await E("Memory undo",()=>window.api.memory.write(o,v,a))}},[a,_,E]),J=l.useCallback(o=>a?E("Memory archive",()=>window.api.memory.archive(o,a)):Promise.resolve(!1),[a,E]),oe=l.useCallback(o=>a?E("Memory restore",()=>window.api.memory.restore(o,a)):Promise.resolve(!1),[a,E]),ce=l.useCallback(o=>a?E("Memory verify",()=>window.api.memory.verify(o,a)):Promise.resolve(!1),[a,E]),le=l.useCallback(async(o,v)=>{if(!a)return!1;const j=await _(o);if(j===null)return!1;const C=j.split(`[[${v}]]`).join(v);return E("Memory link removal",()=>window.api.memory.write(o,C,a))},[a,_,E]),he=l.useCallback(async()=>{if(!(!a||!m||!a.workspace)){$(!0);try{const o=await window.api.memory.aggregate(a.workspace,!0,t??void 0);o.error?A.error(`Memory clustering failed: ${o.error}`):k(o)}catch(o){A.error(`Memory clustering failed: ${U(o)}`)}finally{$(!1)}}},[a,m,t]),Q=l.useCallback(async(o,v)=>{const j=C=>({ok:!1,answer:"",citations:[],error:C});if(!a)return j("no memory store");try{const C=await window.api.memory.ask({question:o,target:a,contextName:v});return C.ok||A.error(`Memory ask failed: ${C.error??"unknown error"}`),C}catch(C){return A.error(`Memory ask failed: ${U(C)}`),j(U(C))}},[a]),G=l.useCallback(async o=>{const v=j=>({ok:!1,action:"keep",summary:"",reason:"",content:"",fold:null,error:j});if(!a)return v("no memory store");try{const j=await window.api.memory.proposeFix({name:o,target:a});return j.ok||A.error(`Memory fix failed: ${j.error??"unknown error"}`),j}catch(j){return A.error(`Memory fix failed: ${U(j)}`),v(U(j))}},[a]),Z=l.useMemo(()=>({refresh:I,read:_,saveBody:X,saveFile:V,create:W,remove:re,archive:J,restore:oe,verify:ce,removeLink:le,regenerateClusters:he,ask:Q,proposeFix:G}),[I,_,X,V,W,re,J,oe,ce,le,he,Q,G]);return{loading:g,target:a,dir:b,autoMemoryEnabled:K,rows:P,clusters:de,clustersMeta:Ce,index:c==null?void 0:c.index,archived:ne,agents:D,agentCounts:fe,actions:Z}}const ys={recent:"name",name:"size",size:"recent"},ks={recent:"Recent",name:"Name",size:"Size"},Ee="text-[9.5px] font-semibold tracking-[.06em] px-[5px] py-px rounded-[3px]",vs="h-7 px-2.5 rounded-full border text-[12.5px] font-medium flex items-center gap-1.5 whitespace-nowrap",js=[{key:"all",label:"All",tone:"bg-butter/40 text-honey-dark"},{key:"stale",label:"Stale",tone:"bg-butter/40 text-honey-dark"},{key:"broken",label:"Broken",tone:"bg-accent-muted/30 text-accent-dark"},{key:"recent",label:"This week",tone:""},{key:"unindexed",label:"Unindexed",tone:""},{key:"archived",label:"Archived",tone:""},{key:"clusters",label:"Clusters",tone:""},{key:"ask",label:"Ask",tone:""}];function ws(s,t){if(s==="ask")return"+";if(s==="clusters")return String(t.clusterCount);if(s==="archived")return String(t.archivedCount);const n=t.counts[s];return s==="unindexed"&&n===0?"✓":String(n)}function Ns(s){return`${_t(s.bytes)} · ${s.ageDays>0?`${s.ageDays}d ago`:"just now"}`}const Cs=l.memo(function(t){return e.jsxs("div",{"data-testid":"mx-list",className:"flex flex-col min-h-0 bg-bg-elev border-r border-rule-structural",children:[e.jsxs("div",{className:"flex flex-col gap-3 px-4 pt-[18px] pb-3",children:[e.jsx(Gt,{eyebrow:"MEMORY FOLDER",badge:e.jsx("span",{"data-testid":"mx-list-folder-count",children:`${t.folder.count} files`}),path:t.folder.path||"—",children:e.jsxs("label",{className:"flex items-center gap-2 h-8 px-2.5 rounded-[8px] bg-bg-elev text-[12.5px]",children:[e.jsx("span",{className:"text-fg-faint",children:"Scope"}),e.jsx("select",{"data-testid":"mx-list-scope","aria-label":"Memory scope",value:t.scopeKey,onChange:n=>t.onScopeKey(n.target.value),className:"flex-1 min-w-0 bg-transparent outline-none font-medium text-fg cursor-pointer",children:t.scopeOptions.map(n=>e.jsx("option",{value:n.key,children:n.label},n.key))})]})}),e.jsx("div",{"data-testid":"mx-list-chips",className:"flex flex-wrap gap-1.5",children:js.filter(n=>n.key!=="archived"||t.archivedCount>0).map(n=>{const d=t.view===n.key||n.key==="clusters"&&t.view.startsWith("cluster:");return e.jsxs("button",{type:"button","data-testid":`mx-chip-${n.key}`,"aria-pressed":d,onClick:()=>t.onView(n.key),className:`${vs} ${n.tone?`${n.tone} border-transparent`:"border-rule-structural text-fg"} ${d?"ring-1 ring-fg-faint":""}`,children:[e.jsx("span",{children:n.label}),e.jsx("span",{className:"font-mono text-[11px]",children:ws(n.key,t)})]},n.key)})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-serif text-[15px] min-w-0 overflow-hidden text-ellipsis whitespace-nowrap",children:t.title}),e.jsx("span",{className:"text-[12px] text-fg-dim",children:t.rows.length}),e.jsx("span",{className:"flex-1"}),e.jsx("button",{type:"button","data-testid":"mx-list-new",onClick:t.onNew,className:"text-[12px] font-medium h-[26px] px-[10px] border border-rule-structural rounded-[5px] bg-bg-hi text-fg flex-none hover:border-fg",children:"+ New"})]}),e.jsxs("div",{className:"flex gap-[6px] items-center",children:[e.jsx("input",{"data-testid":"mx-list-filter",value:t.query,onChange:n=>t.onQuery(n.target.value),placeholder:"Filter by name or content…",className:"flex-1 min-w-0 h-7 border border-rule-structural rounded-[5px] px-[9px] text-[12px] text-fg bg-bg-hi outline-none"}),e.jsx("button",{type:"button","data-testid":"mx-list-sort",onClick:()=>t.onSort(ys[t.sort]),className:"h-7 px-[9px] border border-rule-structural rounded-[5px] flex items-center text-[12px] text-fg whitespace-nowrap hover:border-fg-faint",children:`${ks[t.sort]} ⇅`})]})]}),e.jsxs("div",{className:"overflow-auto flex-1 px-4 pb-4 flex flex-col gap-0.5",children:[t.rows.map(n=>{const d=t.selected===n.name;return e.jsxs("div",{role:"option","aria-selected":d,"data-testid":`mx-list-row-${n.name}`,onClick:()=>t.onSelect(n.name),className:`px-3 py-2.5 rounded-xl border cursor-pointer flex flex-col gap-0.5 ${d?"bg-bg-hi border-line shadow-sm":"border-transparent hover:bg-bg-hi/60"}`,children:[e.jsxs("div",{className:"flex items-center gap-[7px]",children:[e.jsx("span",{className:`w-[7px] h-[7px] rounded-[2px] flex-none ${t.clusterDot(n.clusterId)}`}),e.jsx("span",{className:`text-[13px] flex-1 min-w-0 overflow-hidden text-ellipsis whitespace-nowrap ${d?"font-semibold":"font-medium"}`,children:n.slug}),n.stale&&e.jsx("span",{className:`${Ee} bg-butter/40 text-honey-dark`,children:"STALE"}),n.broken&&!n.stale&&e.jsx("span",{className:`${Ee} bg-accent-muted/30 text-accent-dark`,children:"BROKEN"}),n.notIndexed&&e.jsx("span",{className:`${Ee} bg-rule-inner text-fg-dim`,children:"NOT INDEXED"})]}),e.jsx("div",{className:"font-mono text-[10.5px] text-fg-dim pl-[14px]",children:Ns(n)})]},n.name)}),t.empty&&t.rows.length===0&&e.jsxs("div",{"data-testid":"mx-list-empty",className:"px-[18px] py-10 flex flex-col gap-2 items-start",children:[e.jsx("span",{className:"font-serif text-[17px] text-fg",children:t.empty.title}),e.jsx("span",{className:"text-[12.5px] leading-normal text-fg-dim",children:t.empty.body}),e.jsx("button",{type:"button",onClick:t.empty.onAction,className:"mt-[6px] text-[12px] font-medium h-7 px-3 border border-rule-structural rounded-[5px] bg-bg-hi text-fg",children:t.empty.action})]})]})]})}),ct={update:{label:"UPDATE",apply:"Apply update",hint:"Writes the file · undoable"},delete:{label:"ARCHIVE",apply:"Archive",hint:"Moves to .archive · undoable"},keep:{label:"KEEP",apply:"Mark verified",hint:"Touches the file, clears age staleness"},fold:{label:"FOLD",apply:"Copy for an Epic",hint:"Memory stays until the doc change lands"}},ze="grid grid-cols-[20px_1fr] px-[18px] py-1.5 font-mono text-xs leading-normal border-t border-rule-inner",Ss=l.memo(function({fix:t,onApply:n,onEditFirst:d,onDiscard:i}){const a=ct[t.action];return e.jsxs("div",{"data-testid":"mx-suggestion",className:"mx-9 mt-6 max-w-[700px] border border-honey rounded-[12px] overflow-hidden bg-bg-hi shadow-sm",children:[e.jsxs("div",{className:"px-[18px] py-2.5 bg-butter/40 flex items-center gap-2 text-honey-dark",children:[e.jsx("span",{"aria-hidden":!0,className:"text-[13px]",children:"+"}),e.jsxs("span",{"data-testid":"mx-suggestion-head",className:"text-[11px] tracking-[.1em] font-semibold",children:["CLAUDE SUGGESTS · ",a.label]}),e.jsx("span",{className:"flex-1"}),e.jsx("span",{className:"text-[11.5px]",children:"one of keep · update · archive · fold"})]}),e.jsxs("div",{className:"px-[18px] py-3 flex flex-col gap-1",children:[e.jsx("span",{"data-testid":"mx-reader-summary",className:"text-[15px] font-semibold text-fg",children:t.summary}),t.reason&&e.jsx("span",{"data-testid":"mx-reader-reason",className:"text-[13px] leading-normal text-fg-dim",children:t.reason})]}),t.action==="fold"&&t.fold&&e.jsxs("div",{"data-testid":"mx-suggestion-fold",children:[e.jsxs("div",{className:"px-[18px] py-1.5 border-t border-rule-inner text-[11.5px] text-fg-dim font-mono break-all",children:[t.fold.target," · ",t.fold.anchor||"append at end"]}),t.fold.insert.split(`
11
+ `).map((m,g)=>e.jsxs("div",{className:`${ze} bg-sage/20 text-sage-dark`,children:[e.jsx("span",{children:"+"}),e.jsx("span",{className:"whitespace-pre-wrap break-words",children:m})]},g))]}),t.action==="update"&&e.jsx("div",{"data-testid":"mx-suggestion-diff",children:t.diff.map((m,g)=>e.jsxs("div",{className:`${ze} ${m.sign==="−"?"bg-accent-muted/30 text-accent-dark":m.sign==="+"?"bg-sage/20 text-sage-dark":"text-fg-dim"}`,children:[e.jsx("span",{children:m.sign}),e.jsx("span",{className:"whitespace-pre-wrap break-words",children:m.text})]},g))}),e.jsxs("div",{className:"flex gap-2 px-[18px] py-3 border-t border-rule-structural items-center",children:[e.jsx("button",{type:"button","data-testid":"mx-reader-apply",onClick:n,className:"text-[13.5px] font-semibold h-9 px-4 rounded-[9px] bg-accent text-bg-hi hover:bg-accent/90",children:a.apply}),t.action==="update"&&e.jsx("button",{type:"button","data-testid":"mx-reader-edit-first",onClick:d,className:"text-[13.5px] font-semibold h-9 px-3.5 rounded-[9px] border border-fg text-fg",children:"Edit first"}),e.jsx("button",{type:"button","data-testid":"mx-reader-discard",onClick:i,className:"text-[13.5px] font-medium h-9 px-3.5 rounded-[9px] border border-rule-structural text-fg",children:"Discard"}),e.jsx("span",{className:"flex-1"}),e.jsx("span",{className:"text-[12.5px] text-fg-dim",children:a.hint})]})]})}),$s="text-xs font-medium h-[26px] px-2.5 border border-rule-structural rounded-[5px] bg-bg text-fg hover:border-fg",qe="h-[30px] px-3 text-[13px] font-medium rounded-[7px]",ke="px-2.5 py-[7px] rounded-[5px] text-left text-[12.5px] hover:bg-bg-elev",Ms="max-w-[640px] text-sm leading-[1.65] text-fg flex flex-col gap-3 [&_p]:m-0 [&_h4]:mt-1.5 [&_h4]:mb-0 [&_h4]:text-[11px] [&_h4]:tracking-[.08em] [&_h4]:font-semibold [&_h4]:text-accent [&_code]:font-mono [&_code]:text-[12.5px] [&_code]:bg-bg-elev [&_code]:px-1 [&_code]:rounded-[3px] [&_ul]:m-0 [&_ul]:pl-5 [&_ul]:list-disc [&_ol]:m-0 [&_ol]:pl-5 [&_ol]:list-decimal";function Es(s){return s<1024?`${s} B`:`${(s/1024).toFixed(1)} KB`}function As(s){return s<=0?"just now":`${s}d ago`}function Ds(s,t){const n=[t];return s.type&&n.push(s.type),n.push(Es(s.bytes),`modified ${As(s.ageDays)}`),s.originSessionId&&n.push(`session ${s.originSessionId.slice(0,8)}`),n.join(" · ").toUpperCase()}function Rs(s){const t=/^---\r?\n[\s\S]*?\r?\n---[ \t]*(?:\r?\n|$)/.exec(s);return(t?s.slice(t[0].length):s).trim()}function Ls(s){return s.replace(/^\*\*Why:\*\*[ \t]*/gim,`#### WHY
12
+
13
+ `).replace(/^\*\*How to apply:\*\*[ \t]*/gim,`#### HOW TO APPLY
14
+
15
+ `)}const Ts=l.memo(function(t){const{row:n,fix:d}=t,[i,a]=l.useState(!1),m=l.useMemo(()=>t.content===null||t.editing?"":Bt(Ls(Rs(t.content))),[t.content,t.editing]),g=p=>()=>{a(!1),p()};return e.jsxs("div",{"data-testid":"mx-reader",className:"flex flex-col flex-1 min-w-0 min-h-0",children:[e.jsxs("div",{"data-testid":"mx-reader-header",className:"shrink-0 px-9 pt-6 pb-5 border-b border-rule-structural flex items-end gap-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{"data-testid":"mx-reader-eyebrow",className:"flex items-center gap-2 text-[11px] font-semibold tracking-[0.1em] text-fg-faint",children:[e.jsx("span",{className:`w-[7px] h-[7px] rounded-sm shrink-0 ${t.clusterDot}`}),e.jsx("span",{className:"truncate",children:Ds(n,t.clusterName)})]}),e.jsxs("div",{className:"mt-1.5 flex items-center gap-2.5 min-w-0",children:[e.jsx("span",{"data-testid":"mx-reader-title",className:"min-w-0 [overflow-wrap:anywhere] font-mono text-[27px] font-semibold tracking-[-0.015em] text-fg",children:n.slug}),t.editing?e.jsx("span",{"data-testid":"mx-reader-pill",className:"shrink-0 text-xs font-semibold px-2 py-0.5 rounded-full bg-butter/50 text-honey-dark",children:t.editingSuggestion?"Editing Claude's update":"Editing"}):!t.archived&&d.state==="proposed"?e.jsx("span",{"data-testid":"mx-reader-pill",className:"shrink-0 text-xs font-semibold px-2 py-0.5 rounded-full bg-butter/50 text-honey-dark",children:"Suggestion ready"}):null]})]}),!t.archived&&e.jsxs("div",{className:"shrink-0 flex items-center gap-2",children:[e.jsxs("div",{role:"group","aria-label":"View",className:"flex p-[3px] rounded-[10px] bg-bg-elev border border-rule-structural",children:[e.jsx("button",{type:"button","data-testid":"mx-reader-mode-read","aria-pressed":!t.editing,onClick:t.editing?t.onRead:void 0,className:`${qe} ${t.editing?"text-fg-dim hover:text-fg":"bg-bg-hi text-fg shadow-sm"}`,children:"Read"}),e.jsx("button",{type:"button","data-testid":"mx-reader-edit","aria-pressed":!!t.editing,disabled:t.content===null,onClick:t.editing?void 0:t.onEdit,className:`${qe} ${t.editing?"bg-bg-hi text-fg shadow-sm":"text-fg-dim hover:text-fg"} disabled:opacity-50`,children:"Edit"})]}),!t.editing&&!n.stale&&d.state==="idle"&&e.jsx("button",{type:"button","data-testid":"mx-reader-fix",title:"Uses Claude",onClick:t.onFix,className:"h-[38px] px-4 rounded-[10px] bg-accent text-bg-hi hover:bg-accent/90 text-[13.5px] font-semibold",children:"+ Review with Claude"}),e.jsxs("div",{className:"relative",children:[e.jsx("button",{type:"button","data-testid":"mx-reader-more","aria-label":"More actions",onClick:()=>a(p=>!p),className:"h-[38px] w-[38px] rounded-[10px] border border-rule-structural bg-bg-hi text-fg hover:border-fg",children:"⋯"}),i&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:`fixed inset-0 ${pe.dialog}`,onClick:()=>a(!1)}),e.jsxs("div",{className:`absolute right-0 top-11 w-[200px] ${pe.dialog} bg-bg-hi border border-rule-structural rounded-[7px] shadow-lg p-1 flex flex-col text-fg`,children:[e.jsx("button",{type:"button",className:ke,onClick:g(t.onCopyPath),children:"Copy path"}),e.jsx("button",{type:"button",className:ke,onClick:g(t.onReveal),children:"Reveal in folder"}),e.jsx("div",{className:"h-px bg-rule-inner mx-1.5 my-1"}),e.jsx("button",{type:"button",className:ke,onClick:g(t.onArchive),children:"Archive"}),e.jsx("button",{type:"button",className:`${ke} text-accent`,onClick:g(t.onAskDelete),children:"Delete…"})]})]})]})]})]}),t.editing?e.jsx("div",{"data-testid":"mx-reader-editor",className:"flex-1 min-h-0 flex flex-col px-9 py-6",children:t.editor}):e.jsxs(e.Fragment,{children:[t.archived&&e.jsxs("div",{className:"mx-9 mt-3 px-3 py-2.5 rounded-md bg-bg-elev flex items-center gap-2.5 text-[12.5px] text-fg-dim",children:[e.jsx("span",{className:"flex-1",children:"Archived — read-only. Claude no longer loads this memory."}),e.jsx("button",{type:"button","data-testid":"mx-reader-restore",onClick:t.onRestore,className:$s,children:"Restore"})]}),!t.archived&&n.stale&&d.state==="idle"&&e.jsxs("div",{"data-testid":"mx-reader-stale",className:"mx-9 mt-3 px-3 py-2.5 rounded-md bg-butter/40 text-honey-dark flex gap-2.5 items-center text-[12.5px]",children:[e.jsxs("div",{className:"flex-1 flex flex-col gap-0.5",children:[e.jsx("b",{className:"font-semibold",children:t.appliedStill?`Applied — still flagged: ${n.staleReasons[0]??"needs review"}`:`Stale — ${n.staleReasons[0]??"needs review"}`}),n.deadRefs.length>0&&e.jsx("span",{className:"font-mono text-[11px]",children:n.deadRefs.join(" · ")})]}),e.jsx("span",{className:"text-[11px]",children:"uses Claude"}),e.jsx("button",{type:"button","data-testid":"mx-reader-fix",onClick:t.onFix,className:"text-xs font-medium h-[26px] px-2.5 rounded-[5px] bg-fg text-bg",children:"Fix with assistant"}),n.ageOnlyStale&&e.jsx("button",{type:"button","data-testid":"mx-reader-verify",onClick:t.onVerify,className:"text-xs font-medium h-[26px] px-2.5 rounded-[5px] border border-honey text-honey-dark",children:"Mark verified"})]}),!t.archived&&d.state==="checking"&&e.jsxs("div",{className:"mx-9 mt-3 p-3 rounded-md border border-dashed border-honey bg-butter/20 text-[12.5px] text-honey-dark flex items-center gap-2.5",children:[e.jsx("span",{className:"font-mono text-accent",children:"●○○"}),"Assistant is checking ",n.deadRefs.length>0?`${n.deadRefs.length} references`:"this memory"," against the repo…"]}),!t.archived&&d.state==="proposed"&&e.jsx(Ss,{fix:d,onApply:t.onApplyFix,onEditFirst:t.onEditFirst,onDiscard:t.onDiscardFix}),n.broken&&!n.stale&&e.jsx("div",{className:"mx-9 mt-3 px-3 py-2.5 rounded-md bg-accent-muted/30 text-[12.5px] text-accent-dark",children:"Broken reference — a link or path in this memory points at nothing. See the red items in Links."}),n.notIndexed&&e.jsx("div",{className:"mx-9 mt-3 px-3 py-2.5 rounded-md bg-butter/40 text-[12.5px] text-honey-dark",children:"Claude won't load this — it has no line in MEMORY.md."}),e.jsx("div",{className:"flex-1 overflow-auto px-9 pt-6 pb-[22px]",children:t.content===null?e.jsx("div",{className:"text-xs text-fg-faint",children:"Loading…"}):e.jsxs("div",{className:Ms,children:[n.description&&e.jsx("p",{className:"font-serif text-[17px] leading-normal text-fg",children:n.description}),e.jsx("div",{className:"contents",dangerouslySetInnerHTML:{__html:m}})]})})]})]})});function Is({mode:s,name:t,title:n,onTitle:d,body:i,onBody:a,onSave:m,onCancel:g,saving:p,dirty:y,path:x,onRevert:c,changedFrom:u}){if(s==="none")return e.jsxs("div",{"data-testid":"mx-editor-none",className:"flex-1 flex flex-col items-center justify-center text-center gap-1.5 p-10",children:[e.jsx("div",{className:"font-serif text-[18px] text-fg",children:"No memory selected"}),e.jsx("div",{className:"text-[13px] text-fg-dim",children:"Pick one from the list, or press /."})]});if(s==="edit")return e.jsx("div",{"data-testid":"mx-editor",className:"flex-1 min-h-0 flex flex-col",children:e.jsx(Yt,{path:x??`${t??"memory"}.md`,value:i,onChange:a,onSave:()=>{!p&&y&&m()},onRevert:c,dirty:y,changedFrom:u,defaultMode:"document"},x??t??"")});const f=p,k=w=>{(w.metaKey||w.ctrlKey)&&w.key.toLowerCase()==="s"?(w.preventDefault(),f||m()):w.key==="Escape"&&(w.preventDefault(),g())};return e.jsxs("div",{"data-testid":"mx-editor",className:"flex-1 min-h-0 flex flex-col",onKeyDown:k,children:[e.jsxs("div",{className:"flex items-center gap-2 px-[22px] pt-3.5 pb-3 border-b border-rule-structural",children:[e.jsx("h2",{className:"flex-1 min-w-0 truncate font-mono text-[15px] font-medium text-fg",children:"New memory"}),e.jsx("button",{type:"button","data-testid":"mx-editor-cancel",onClick:g,className:"h-7 px-3 rounded-[5px] border border-rule-structural bg-bg text-xs font-medium text-fg",children:"Cancel"}),e.jsx("button",{type:"button","data-testid":"mx-editor-save",disabled:f,onClick:m,className:"h-7 px-3.5 rounded-[5px] bg-accent text-white text-xs font-medium disabled:opacity-50 disabled:cursor-not-allowed",children:"Save"})]}),e.jsxs("div",{className:"flex-1 min-h-0 flex flex-col gap-2.5 px-[22px] py-4",children:[e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("label",{htmlFor:"mx-editor-name",className:"text-[11px] tracking-[.06em] font-semibold text-fg-faint",children:"NAME"}),e.jsx("input",{id:"mx-editor-name","data-testid":"mx-editor-name",value:n,onChange:w=>d(w.target.value),placeholder:"e.g. deploy freeze fridays",className:"h-8 px-2.5 rounded-[5px] border border-rule bg-bg-hi font-mono text-[13px] font-normal text-fg outline-none"}),n.trim()!==""&&e.jsxs("div",{className:"font-mono text-[11px] text-fg-faint",children:["→ ",dt(n),".md"]})]}),e.jsx("textarea",{"data-testid":"mx-editor-body",value:i,onChange:w=>a(w.target.value),spellCheck:!1,className:"flex-1 min-h-0 w-full resize-none px-3.5 py-3 rounded-md border border-rule bg-bg-hi font-mono text-[13px] leading-[1.7] text-fg outline-none"}),e.jsx("div",{className:"flex items-center gap-2 text-[11.5px] text-fg-faint",children:e.jsx("span",{children:"Markdown. Frontmatter is added on save. Saving marks the memory verified."})})]})]})}const Ae=l.memo(Is);function Os(s){const t=Math.max(0,Math.round(s/1e3));return`${Math.floor(t/60)}:${String(t%60).padStart(2,"0")}`}function Fs({elapsedMs:s,evidence:t}){const[n,d]=l.useState(!1);return e.jsxs("div",{"data-testid":"mx-links-checked",className:"flex flex-col gap-2 px-4 py-3.5 rounded-[14px] border border-rule-inner bg-bg-hi",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{"aria-hidden":!0,className:"w-[7px] h-[7px] rounded-full bg-sage-dark shrink-0"}),e.jsxs("span",{className:`${se} flex-1`,children:["CHECKED IN ",Os(s)]}),t.length>0&&e.jsxs("button",{type:"button","data-testid":"mx-links-evidence","aria-expanded":n,onClick:()=>d(i=>!i),className:"text-[12px] font-medium text-accent hover:text-fg",children:["Evidence ",n?"▴":"▾"]})]}),n&&e.jsx("ul",{"data-testid":"mx-links-evidence-list",className:"m-0 pl-4 list-disc text-[12px] leading-normal text-fg-dim",children:t.map(i=>e.jsx("li",{className:"break-words",children:i},i))})]})}const se="text-[11px] tracking-[.1em] font-semibold text-fg-faint",Ps="flex flex-col gap-0.5 px-3.5 py-2.5 rounded-[10px] cursor-pointer bg-bg-hi border text-left hover:border-fg-faint";function ve({testid:s,slug:t,sub:n,dangling:d,onClick:i}){return e.jsxs("button",{type:"button","data-testid":s,onClick:i,className:`${Ps} ${d?"border-accent-muted":"border-rule-inner"}`,children:[e.jsx("span",{className:`font-mono text-[12.5px] font-medium break-all ${d?"text-accent":"text-fg"}`,children:t}),e.jsx("span",{className:`text-[10.5px] ${d?"text-accent":"text-fg-dim"}`,children:n})]})}const _s=l.memo(function({row:t,onOpen:n,onRemoveLink:d,onAskAbout:i,onUpdatePath:a,onReviewPath:m,onCheck:g,checkBusy:p,editing:y,editingSuggestion:x,check:c}){return e.jsx("aside",{"data-testid":"mx-links",className:"px-5 py-6 flex flex-col gap-[18px] overflow-auto",children:t&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-col gap-[6px]",children:[e.jsxs("span",{className:se,children:["LINKS TO · ",t.outLinks.length]}),t.outLinks.map(u=>{const f=t.danglingLinks.includes(u);return e.jsx(ve,{testid:`mx-link-out-${u}`,slug:u,dangling:f,sub:f?"missing · click to remove link":"wikilink",onClick:()=>f?d(u):n(u)},u)}),t.outLinks.length===0&&e.jsx("span",{className:"text-[12px] text-fg-dim",children:"No outgoing links."})]}),t.movedRefs.length+t.deadRefs.length>0&&e.jsxs("div",{className:"flex flex-col gap-[6px]",children:[e.jsxs("span",{className:se,children:["PATHS · ",t.movedRefs.length+t.deadRefs.length]}),t.movedRefs.map((u,f)=>e.jsx(ve,{testid:`mx-path-moved-${f}`,slug:u.from,dangling:!1,sub:`moved to ${u.to} · click to update`,onClick:()=>a({from:u.from,to:u.to})},`moved-${u.from}`)),t.deadRefs.map((u,f)=>e.jsx(ve,{testid:`mx-path-dead-${f}`,slug:u,dangling:!0,sub:"not found anywhere · review with assistant",onClick:m},`dead-${u}`))]}),e.jsxs("div",{className:"flex flex-col gap-[6px]",children:[e.jsxs("span",{className:se,children:["LINKED FROM · ",t.inLinks.length]}),t.inLinks.map(u=>e.jsx(ve,{testid:`mx-link-in-${u}`,slug:u,dangling:!1,sub:"wikilink",onClick:()=>n(u)},u)),t.inLinks.length===0&&e.jsx("span",{className:"text-[12px] text-fg-dim",children:"Nothing links here yet."})]}),y&&x?e.jsxs("div",{"data-testid":"mx-links-started",className:"flex flex-col gap-1.5 px-4 py-3.5 rounded-[14px] border border-honey/60 bg-butter/20 text-[12.5px] leading-normal text-fg",children:[e.jsx("span",{className:`${se} uppercase !text-honey-dark`,children:"Started from Claude's update"}),e.jsx("span",{children:"The suggested change is already in the editor, and the lines it touched are marked. Change anything before you save."}),e.jsx("span",{className:"text-fg-dim",children:"Revert goes back to the file on disk."})]}):y?e.jsxs("div",{"data-testid":"mx-links-editing",className:"flex flex-col gap-1.5 px-4 py-3.5 rounded-[14px] border border-dashed border-rule-structural text-[12px] leading-normal text-fg-dim",children:[e.jsx("span",{className:se,children:"EDITING THE FILE ON DISK"}),e.jsxs("span",{children:["Keep the frontmatter lines (name, description, type). Save writes"," ",e.jsx("span",{className:"font-mono break-all",children:t.name}),"."]})]}):c?e.jsx(Fs,{elapsedMs:c.elapsedMs,evidence:c.evidence}):e.jsxs("div",{"data-testid":"mx-links-askclaude",className:"flex flex-col gap-2 px-4 py-3.5 rounded-[14px] border border-honey/50 bg-butter/30",children:[e.jsx("span",{className:`${se} !text-honey-dark`,children:"ASK CLAUDE"}),e.jsx("span",{className:"font-serif text-[17px] leading-snug text-fg",children:"Is this memory still accurate?"}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("button",{type:"button","data-testid":"mx-links-check",disabled:p,onClick:g,className:"h-8 px-3 rounded-[8px] bg-accent text-bg-hi hover:bg-accent/90 text-[13px] font-semibold disabled:opacity-50 disabled:cursor-not-allowed",children:"Check against the repo"}),e.jsx("button",{type:"button","data-testid":"mx-links-ask",onClick:i,className:"text-[12px] text-honey-dark hover:text-fg",children:"Ask a question…"})]})]})]})})}),Bs=["What changed this week?","Find contradictions","Summarize stale memories","remember …"],Us=["Is this still accurate?","What links here?","Summarize it"],Ks=/^remember\b[\s:,-]*/i,Xe="text-xs font-medium h-[26px] px-2.5 rounded-[5px] bg-fg text-bg",Ws=s=>s.charAt(0).toUpperCase()+s.slice(1),Hs=l.memo(function({rows:t,context:n,onClearContext:d,onAsk:i,onOpen:a,onReverify:m,onDraft:g}){const[p,y]=l.useState(""),[x,c]=l.useState(!1),[u,f]=l.useState(null),k=async()=>{const b=p.trim();if(!b||x)return;if(/^remember\b/i.test(b)){f({kind:"draft",question:b,text:Ws(b.replace(Ks,""))}),y("");return}c(!0);let M=null;try{M=await i(b,n)}catch{M=null}c(!1),!(!M||!M.ok)&&(f({kind:"answer",question:b,answer:M.answer,citations:M.citations}),y(""))},w=(u==null?void 0:u.kind)==="answer"?u.citations.map(b=>({slug:b,row:t.find(M=>M.slug===b||M.name===b)})):[],$=w.filter(b=>{var M;return(M=b.row)==null?void 0:M.stale}).length;return e.jsxs("div",{"data-testid":"mx-ask",className:"flex flex-col h-full min-h-0",children:[e.jsxs("div",{className:"px-7 py-4 border-b border-rule-structural flex items-center gap-2.5",children:[e.jsx("span",{className:"font-serif text-[20px]",children:"Ask"}),e.jsx("span",{className:"text-xs text-fg-dim flex-1",children:"Search and edit this scope's memories in plain language. Answers cite the files they used."}),n&&e.jsxs("span",{"data-testid":"mx-ask-context",className:"flex items-center gap-1.5 pl-2 pr-1 py-[3px] border border-rule rounded-[5px] bg-bg-elev text-xs",children:["About ",e.jsx("span",{className:"font-mono text-[11.5px]",children:n}),e.jsx("button",{"aria-label":"Clear context",onClick:d,className:"px-1.5 text-fg-dim hover:text-accent",children:"×"})]})]}),e.jsxs("div",{className:"flex-1 overflow-auto px-7 py-6 flex flex-col gap-5 max-w-[820px]",children:[!u&&!x&&e.jsxs("div",{className:"my-auto flex flex-col gap-1.5 text-fg-dim text-[13px]",children:[e.jsx("span",{className:"font-serif text-[20px] text-fg",children:"What do you want to know?"}),e.jsx("span",{children:'Ask about a symptom, a file or a past decision, or start with "remember" to save something new.'})]}),u&&e.jsx("div",{className:"self-end max-w-[520px] px-3.5 py-2.5 rounded-[10px] bg-fg text-bg text-[14px]",children:u.question}),(u==null?void 0:u.kind)==="answer"&&e.jsxs("div",{className:"flex flex-col gap-2.5 text-[14px] leading-[1.65] text-fg max-w-[680px]",children:[e.jsx("p",{className:"m-0",children:u.answer}),e.jsx("div",{className:"flex flex-wrap gap-1.5 items-center",children:w.map((b,M)=>{var K;return e.jsxs("button",{"data-testid":`mx-ask-cite-${b.slug}`,onClick:()=>{var z;return a(((z=b.row)==null?void 0:z.name)??b.slug)},className:"flex items-center gap-1.5 px-[9px] py-1 border border-rule-structural rounded-[5px] bg-bg text-xs hover:border-fg",children:[e.jsxs("span",{className:"font-mono text-[10.5px] text-accent",children:["[",M+1,"]"]}),e.jsx("span",{children:b.slug}),b.row&&e.jsxs("span",{className:"text-fg-dim",children:[b.row.ageDays,"d"]}),((K=b.row)==null?void 0:K.stale)&&e.jsx("span",{className:"text-[9.5px] font-semibold px-1 rounded-[3px] bg-butter/40 text-honey-dark",children:"STALE"})]},b.slug)})}),$>0&&e.jsxs("div",{className:"px-3 py-2.5 rounded-md bg-butter/40 text-[12.5px] text-fg flex items-center gap-2.5",children:[e.jsxs("span",{className:"flex-1",children:[$," of these ",$===1?"is":"are"," flagged stale. Re-verify against the current code?"]}),e.jsx("button",{onClick:m,className:Xe,children:"Re-verify"})]})]}),(u==null?void 0:u.kind)==="draft"&&e.jsxs("div",{className:"max-w-[560px] border border-rule rounded-lg bg-bg-hi p-3.5 flex flex-col gap-2",children:[e.jsx("span",{"data-testid":"mx-ask-draft",className:"text-[10px] tracking-[.08em] text-sage-dark font-semibold",children:"DRAFT MEMORY · NOT SAVED YET"}),e.jsx("span",{className:"font-serif text-base",children:u.text}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:()=>g(u.text),className:`${Xe} h-7 px-3`,children:"Review draft"}),e.jsx("span",{className:"text-xs text-fg-dim self-center",children:"Opens it in the editor before anything is written"})]})]}),x&&e.jsx("span",{className:"text-xs text-fg-dim",children:"Thinking…"})]}),e.jsxs("div",{className:"px-7 pt-3 pb-4 border-t border-rule-structural flex flex-col gap-2.5",children:[e.jsx("div",{className:"flex gap-1.5 flex-wrap items-center",children:(n?Us:Bs).map(b=>e.jsx("button",{onClick:()=>y(b),className:"px-2.5 py-1 border border-rule-structural rounded-[14px] text-xs text-fg-dim hover:bg-bg-elev",children:b},b))}),e.jsxs("div",{className:"flex gap-2 items-center",children:[e.jsx("input",{"data-testid":"mx-ask-input",value:p,onChange:b=>y(b.target.value),onKeyDown:b=>{b.key==="Enter"&&k()},placeholder:"Ask, or say “remember …” to add a memory",className:"flex-1 h-11 border border-rule rounded-md bg-bg-hi px-3 text-[13px] text-fg focus:outline-none focus:border-fg-faint"}),e.jsx(cs,{}),e.jsx("button",{"data-testid":"mx-ask-send",onClick:()=>void k(),disabled:x,className:"h-11 px-4 rounded-md bg-accent text-white text-[13px] font-medium disabled:opacity-40",children:"Send"}),e.jsx("span",{className:"text-[10px] text-fg-faint",children:"uses Claude"})]})]})]})}),Je="text-xs font-medium h-[26px] px-2.5 border border-rule-structural rounded-[5px] bg-bg text-fg hover:border-fg disabled:opacity-50 disabled:cursor-default",Qe="text-[11px] text-fg-faint",Vs=l.memo(function({clusters:t,rows:n,generatedAt:d,running:i,unclusteredCount:a,available:m,onRegenerate:g,onOpenCluster:p,onOpen:y}){const x=l.useMemo(()=>new Map(n.map(c=>[c.slug,c])),[n]);return m?d===null&&t.length===0?e.jsxs("div",{"data-testid":"mx-clusters",className:"flex-1 flex flex-col items-center justify-center gap-2 p-6 text-center",children:[e.jsx("div",{className:"font-serif text-[20px] text-fg",children:"No clusters yet"}),e.jsx("button",{type:"button","data-testid":"mx-clusters-regenerate",className:Je,disabled:i,onClick:g,children:i?"Generating…":"Generate"}),e.jsx("span",{className:Qe,children:"uses Claude · up to 3 min"})]}):e.jsxs("div",{"data-testid":"mx-clusters",className:"flex-1 min-w-0 min-h-0 flex flex-col",children:[e.jsxs("div",{className:"px-6 py-4 border-b border-rule-structural flex items-center gap-2.5",children:[e.jsx("span",{className:"font-serif text-[20px] text-fg",children:"Clusters"}),e.jsxs("span",{className:"text-xs text-fg-dim",children:["Generated ",Ut(d,Date.now())," from shared references and links"]}),e.jsx("span",{className:"flex-1"}),a>0&&e.jsxs("span",{className:"text-xs text-honey-dark px-2 py-0.5 rounded bg-butter/40",children:[a," unclustered"]}),e.jsx("button",{type:"button","data-testid":"mx-clusters-regenerate",className:Je,disabled:i,onClick:g,children:i?"Generating…":"Regenerate"}),e.jsx("span",{className:Qe,children:"uses Claude"})]}),e.jsx("div",{className:"flex-1 overflow-auto px-6 py-[18px] grid grid-cols-2 gap-4 content-start",children:t.map(c=>e.jsxs("div",{"data-testid":`mx-cluster-${c.id}`,className:"bg-bg-hi border border-rule-structural rounded-lg p-4 flex flex-col gap-2.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`w-[9px] h-[9px] rounded-[2px] shrink-0 ${c.dotClass}`}),e.jsx("span",{className:"font-serif text-[17px] text-fg min-w-0 flex-1",children:c.name}),e.jsxs("button",{type:"button","data-testid":`mx-cluster-open-${c.id}`,className:"text-xs text-accent hover:text-fg",onClick:()=>p(c.id),children:["Open ",c.memberSlugs.length," →"]})]}),e.jsx("span",{className:"text-[12.5px] leading-normal text-fg-dim",children:c.summary}),e.jsx("div",{className:"flex flex-wrap gap-[5px] items-center",children:c.memberSlugs.map(u=>{const f=x.get(u);return e.jsx("button",{type:"button",className:`font-mono text-[11px] px-[7px] py-[3px] rounded border border-rule-inner text-fg hover:border-fg ${f!=null&&f.stale?"bg-butter/40":"bg-bg"}`,onClick:()=>y((f==null?void 0:f.name)??`${u}.md`),children:u},u)})}),e.jsxs("div",{className:"flex gap-3.5 text-[11.5px] text-fg-dim border-t border-rule-inner pt-[9px]",children:[e.jsxs("span",{children:[c.linkCount," links"]}),e.jsxs("span",{children:[c.retireCount," retires"]}),e.jsxs("span",{className:"text-honey-dark",children:[c.staleCount," stale"]})]})]},c.id))})]}):e.jsx("div",{"data-testid":"mx-clusters",className:"flex-1 p-6 text-[13px] text-fg-dim",children:"Clusters are available for workspace memory."})}),De="text-[12.5px] font-medium h-8 px-3 rounded-[5px] cursor-pointer text-fg";function Gs({open:s,name:t,inbound:n,onArchive:d,onCancel:i,onConfirm:a}){return l.useEffect(()=>{if(!s)return;const m=g=>{g.key==="Escape"&&i()};return document.addEventListener("keydown",m),()=>document.removeEventListener("keydown",m)},[s,i]),s?e.jsxs("div",{"data-testid":"mx-delete-dialog",children:[e.jsx("div",{className:`absolute inset-0 ${pe.dialog} bg-fg/30`,onClick:i}),e.jsxs("div",{className:`absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 w-[440px] ${pe.dialog} bg-bg-hi border border-rule rounded-[10px] shadow-lg p-5 flex flex-col gap-3`,children:[e.jsx("span",{className:"font-serif text-[20px] text-fg",children:"Delete this memory?"}),e.jsxs("span",{className:"font-mono text-[12.5px] text-fg",children:[t,".md"]}),n>0&&e.jsxs("div",{className:"px-3 py-[10px] rounded-[6px] bg-accent-muted/30 text-[12.5px] leading-normal text-accent-dark",children:[n," memories link here. Those links will show as broken until removed."]}),e.jsx("span",{className:"text-[12.5px] text-fg-dim",children:"The file is removed from disk. You can undo for a few seconds afterwards. To keep it out of sessions without deleting it, use Archive."}),e.jsxs("div",{className:"flex gap-2 justify-end mt-1",children:[e.jsx("button",{type:"button",onClick:d,className:`${De} border border-rule mr-auto`,children:"Archive instead"}),e.jsx("button",{type:"button",onClick:i,className:`${De} border border-rule bg-bg`,children:"Cancel"}),e.jsx("button",{type:"button","data-testid":"mx-delete-confirm",onClick:a,className:`${De} border-0 px-[14px] bg-accent text-white`,children:"Delete"})]})]})]}):null}const Ys=6e3;function zs({message:s,onUndo:t,onClose:n}){return l.useEffect(()=>{if(s===null)return;const d=setTimeout(n,Ys);return()=>clearTimeout(d)},[s]),s===null?null:e.jsxs("div",{"data-testid":"mx-undo-bar",className:`absolute bottom-[22px] left-1/2 -translate-x-1/2 ${pe.dialog} flex items-center gap-[14px] py-[10px] pl-4 pr-3 rounded-lg bg-fg text-bg text-[13px] shadow-lg whitespace-nowrap`,children:[e.jsx("span",{children:s}),t&&e.jsx("button",{type:"button","data-testid":"mx-undo",onClick:t,className:"font-semibold text-accent-muted hover:text-white",children:"Undo"}),e.jsx("button",{type:"button",onClick:n,"aria-label":"Dismiss",className:"text-fg-faint hover:text-white px-1",children:"×"})]})}const mt="sm.memoryTab.scope",Y="agent:",Re=`One-line summary of the fact or rule.
16
+
17
+ **Why:**
18
+
19
+ **How to apply:**`,F={state:"idle",diff:[],summary:"",action:"update",reason:"",fold:null,elapsedMs:0},Le=(s,t)=>`${s} ${t}${s===1?"":"s"}`;function qs(s){const t=[`Verdict: ${ct[s.action].label.toLowerCase()}`];if(s.action==="update"){const n=s.diff.filter(i=>i.sign==="−").length,d=s.diff.filter(i=>i.sign==="+").length;t.push(`${Le(n,"line")} removed · ${Le(d,"line")} added`)}return s.action==="fold"&&s.fold&&(t.push(`${Le(s.fold.insert.split(`
20
+ `).length,"line")} into ${s.fold.target}`),t.push(s.fold.anchor?`After: ${s.fold.anchor}`:"Appended at the end")),t}const Ze=s=>s.replace(/\.md$/,""),et=s=>s?s.split(/[\\/]/).filter(Boolean).pop()??s:"workspace";function tt(s){const t=/^---\r?\n[\s\S]*?\r?\n---[ \t]*(?:\r?\n|$)/.exec(s);return(t?s.slice(t[0].length):s).replace(/^\s*\n/,"")}const Xs=s=>s.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");function Js(s,t,n){return s.replace(new RegExp("`"+Xs(t)+"(:\\d+)?`","g"),(d,i)=>"`"+n+(i??"")+"`")}function Qs(){try{const s=localStorage.getItem(mt);return s&&s.startsWith(Y)?s:"workspace"}catch{return"workspace"}}function Zs({cwd:s}){const[t,n]=l.useState(Qs),[d,i]=l.useState([]),a=l.useMemo(()=>{if(!t.startsWith(Y))return"workspace";const x=t.slice(Y.length);return d.some(c=>c.name===x)?t:"workspace"},[t,d]),m=l.useMemo(()=>{if(a==="workspace")return{kind:"workspace"};const x=d.find(c=>c.name===a.slice(Y.length));return x?{kind:"agent",agent:x}:{kind:"workspace"}},[a]),g=l.useCallback(x=>{const c=x.kind==="agent"?`${Y}${x.agent.name}`:"workspace";try{localStorage.setItem(mt,c)}catch{}n(c)},[]),p=l.useCallback(x=>{x.length>0&&i(x)},[]),y=xe(x=>x.tab);return l.useEffect(()=>{y==="memory"&&a!=="workspace"&&g({kind:"workspace"})},[y,a,g]),e.jsx(en,{scope:m,cwd:s,onScope:g,onAgents:p},a)}function en({scope:s,cwd:t,onScope:n,onAgents:d}){var Be;const i=bs(s,t),{actions:a,rows:m,clusters:g}=i,p=s.kind==="agent"?s.agent:null,y=p!==null&&p.memoryScope===null,x=p?p.name:et(t),[c,u]=l.useState("all"),[f,k]=l.useState(null),[w,$]=l.useState("read"),[b,M]=l.useState(""),[K,z]=l.useState("recent"),[ne,S]=l.useState(null),[D,L]=l.useState(F),[fe,Ne]=l.useState(""),[q,H]=l.useState(!1),[ae,I]=l.useState(null),[P,de]=l.useState(null),[Ce,_]=l.useState(null),[E,X]=l.useState(""),[V,W]=l.useState(""),[re,J]=l.useState(""),[oe,ce]=l.useState(!1),[le,he]=l.useState(null);l.useEffect(()=>{d(i.agents)},[i.agents,d]);const Q=l.useMemo(()=>i.archived.map(r=>({name:r,slug:Ze(r),path:`${i.dir}/${r}`,description:"",bytes:0,mtimeMs:0,ageDays:0,stale:!1,staleReasons:[],ageOnlyStale:!1,deadRefs:[],movedRefs:[],broken:!1,danglingLinks:[],outLinks:[],inLinks:[],notIndexed:!1,clusterId:null,type:null,originSessionId:null})),[i.archived,i.dir]),G=c!=="ask"&&c!=="clusters",Z=l.useMemo(()=>{if(c==="archived"){const r=b.trim().toLowerCase();return Q.filter(h=>!r||h.slug.toLowerCase().includes(r))}return ps(ue(m,c,b),K)},[c,m,Q,b,K]),o=l.useMemo(()=>m.find(r=>r.name===f)??Q.find(r=>r.name===f)??null,[m,Q,f]),v=o!==null&&!m.some(r=>r.name===o.name),j=l.useCallback(r=>{var h;return((h=g.find(N=>N.id===r))==null?void 0:h.dotClass)??"bg-rule"},[g]),C=r=>{var h;return((h=g.find(N=>N.id===r))==null?void 0:h.name)??"Unclustered"},O=l.useCallback(r=>{k(r),$("read"),H(!1),L(F),I(null),S(null)},[]),R=l.useCallback(r=>{u(r),M(""),S(null),L(F),H(!1),$(h=>h==="edit"||h==="new"?"read":h)},[]);l.useEffect(()=>{var r;i.loading||!G||w==="new"||o&&Z.some(h=>h.name===o.name)||k(((r=Z[0])==null?void 0:r.name)??null)},[i.loading,G,w,o,Z]);const ee=o&&!v?o.name:null,pt=o==null?void 0:o.mtimeMs;l.useEffect(()=>{if(!ee)return;let r=!0;return a.read(ee).then(h=>{r&&he({name:ee,text:h})}),()=>{r=!1}},[ee,pt,a.read]);const B=v?"":le&&le.name===ee?le.text:null,T=(r,h)=>de({message:r,undo:h}),Se=(r="")=>{y||((c==="ask"||c==="clusters")&&u("all"),k(null),X(""),W(r),J(""),L(F),S(null),$("new"))},Te=r=>{R("all"),O(r)},ft=r=>{const h=m.find(N=>N.slug===r);h?O(h.name):A.error(`${r} is not in this scope`)},ht=()=>{B!==null&&(W(B),J(B),H(!1),$("edit"))},gt=()=>{B===null||D.state!=="proposed"||D.action!=="update"||(W(fe),J(B),H(!0),$("edit"))},ge=w==="edit"&&V!==re,Ie=xe(r=>r.tab),be=xe(r=>r.id),Oe=xe(r=>r.clear);l.useEffect(()=>{if(Ie!=="memory"||!be||p||i.loading)return;const r=be.startsWith("memory:")?be.slice(7):null,h=r?m.find(N=>N.path===r):void 0;h&&(!ge||window.confirm("Discard unsaved changes to this memory?"))&&(R("all"),O(h.name)),Oe()},[Ie,be,p,i.loading,m,ge,R,O,Oe]);const bt=async()=>{if(!o)return;const r=await a.read(o.name);r!==null&&(W(r),J(r),H(!1))},Fe=()=>{ge&&!window.confirm("Discard unsaved changes to this memory?")||(H(!1),$("read"))},Pe=async()=>{if(!oe){ce(!0);try{if(w==="new"){const r=await a.create(E,V);if(!r)return;const h=r.endsWith(".md")?r:`${r}.md`;R("all"),O(h),T(`Created ${Ze(h)}`)}else if(w==="edit"&&o){const r=o,h=re,N=q;if(!await a.saveFile(r.name,V))return;$("read"),H(!1),N?(L(F),I(r.slug),T(`Applied edited fix to ${r.slug}`,()=>{a.saveFile(r.name,h)})):T(`Saved ${r.slug}`)}}finally{ce(!1)}}},yt=()=>{$("read"),o||k(null)},$e=async()=>{if(!o||B===null)return;const r=o;L({...F,state:"checking"});const h=performance.now(),N=await a.proposeFix(r.name);if(!N.ok){L(F);return}Ne(N.content),L({state:"proposed",diff:N.action==="update"?hs(B,N.content):[],summary:N.summary,action:N.action,reason:N.reason,fold:N.fold,elapsedMs:performance.now()-h})},kt=async()=>{if(!o||B===null)return;const r=o;if(D.action==="delete"){if(!await a.archive(r.name))return;L(F),T(`Archived ${r.slug}`,()=>{a.restore(r.name)})}else if(D.action==="keep"){if(!await a.verify(r.name))return;L(F),T(`Marked ${r.slug} verified`)}else if(D.action==="fold"){if(!D.fold)return;const{target:h,anchor:N,insert:ie}=D.fold,ye=`Fold memory ${r.slug} into ${h}.
21
+ Insert after the line: ${N||"(append at end)"}
22
+ ---
23
+ ${ie}
24
+ ---
25
+ Tread lightly: add only these lines, do not restructure the doc. Once committed, archive the memory ${r.slug} from the Memory page.
26
+ Memory file: ${r.path}`,Ue=await window.api.clipboard.writeText(ye);if(!Ue.ok){A.error(`Copy failed: ${Ue.error??"unknown error"}`);return}L(F),T("Fold copied — paste it into a New Epic")}else{const h=B;if(!await a.saveBody(r.name,tt(fe)))return;L(F),I(r.slug),T(`Applied fix to ${r.slug}`,()=>{a.saveFile(r.name,h)})}},vt=async()=>{if(!o)return;const r=o;await a.verify(r.name)&&T(`Marked ${r.slug} verified`)},_e=async()=>{if(!o)return;const r=o;S(null),await a.archive(r.name)&&T(`Archived ${r.slug}`,()=>{a.restore(r.name)})},jt=async()=>{if(!o)return;const r=o;await a.restore(r.name)&&T(`Restored ${r.slug}`)},wt=async()=>{if(!o)return;const r=o;S(null);const h=await a.remove(r.name);if(!h)return;const N=r.inLinks.length;T(`Deleted ${r.slug}${N>0?` · ${N} inbound links now broken`:""}`,()=>{h()})},Nt=async()=>{if(!o)return;const r=await window.api.clipboard.writeText(o.path);r.ok?T("Path copied"):A.error(`Copy failed: ${r.error??"unknown error"}`)},Ct=()=>{o&&window.api.shell.open({as:"revealPath",path:o.path})},St=async r=>{if(!o)return;const h=o;await a.removeLink(h.name,r)&&T(`Dead link removed from ${h.slug}`)},$t=async r=>{if(!o)return;const h=o;try{const N=await a.read(h.name);if(N===null)return;const ie=tt(N),ye=Js(ie,r.from,r.to);if(ye===ie){A.error(`${r.from} is not referenced in backticks in ${h.slug}`),await a.refresh();return}if(!await a.saveBody(h.name,ye))return;T(`Updated ${r.from} → ${r.to} in ${h.slug}`,()=>{a.saveBody(h.name,ie)})}catch(N){A.error(`Path update failed: ${N instanceof Error?N.message:String(N)}`)}},Mt=()=>{o&&(_(o.slug),R("ask"))},Et=r=>{var h;return r?((h=m.find(N=>N.slug===r))==null?void 0:h.name)??`${r}.md`:void 0},At=l.useMemo(()=>D.state==="proposed"?{elapsedMs:D.elapsedMs,evidence:qs(D)}:null,[D]),Dt=l.useMemo(()=>fs(m),[m]),Rt=l.useMemo(()=>m.filter(r=>r.clusterId===null).length,[m]),Lt=l.useMemo(()=>new Set(m.map(r=>r.slug)),[m]),Tt=l.useMemo(()=>[{key:"workspace",label:`Workspace · ${et(t)}`},...i.agents.map(r=>({key:`${Y}${r.name}`,label:`Subagent · ${r.name}${r.memoryScope?"":" (off)"}`}))],[i.agents,t]),It=p?`${Y}${p.name}`:"workspace",Ot=l.useCallback(r=>{const h=r.startsWith(Y)?i.agents.find(N=>N.name===r.slice(Y.length)):void 0;n(h?{kind:"agent",agent:h}:{kind:"workspace"})},[i.agents,n]),Ft=c.startsWith("cluster:")?c==="cluster:unclustered"?"Unclustered":((Be=g.find(r=>r.id===c.slice(8)))==null?void 0:Be.name)??"Cluster":{all:"All memories",ask:"Ask",clusters:"Clusters",stale:"Stale",broken:"Broken references",recent:"Changed this week",unindexed:"Not in index",archived:"Archived"}[c]??"All memories";let me=null;Z.length===0&&(y?me={title:`${x} has no persistent memory`,body:"Add `memory: project` (or user/local) to its frontmatter in the Agent Library to turn it on.",action:"Back to workspace",onAction:()=>n({kind:"workspace"})}:b.trim()?me={title:`No memories match “${b}”`,body:"Filter checks names and descriptions in this view.",action:"Clear filter",onAction:()=>M("")}:m.length===0&&c==="all"?me={title:`${x} has no memories yet`,body:"They appear when this subagent saves one, or add one now.",action:"+ New memory",onAction:()=>Se(Re)}:me={title:"All clear",body:c==="stale"?"Nothing is stale in this scope.":"Nothing in this view.",action:"Back to all memories",onAction:()=>R("all")});const Pt=!i.autoMemoryEnabled;return e.jsxs("div",{"data-testid":"mx-shell",className:"relative h-full flex flex-col bg-bg text-fg leading-[normal]",children:[Pt&&e.jsx("div",{"data-testid":"mx-auto-off",className:"shrink-0 w-full px-6 py-2 bg-butter/40 text-honey-dark text-[12.5px]",children:"Auto memory is off — Claude Code is not reading or writing any of these files."}),e.jsxs("div",{className:`flex-1 min-h-0 grid ${G?"grid-cols-[316px_minmax(0,1fr)_268px]":"grid-cols-[316px_minmax(0,1fr)]"}`,children:[e.jsx(Cs,{title:Ft,rows:G?Z:[],clusterDot:j,selected:f,onSelect:O,query:b,onQuery:M,sort:K,onSort:z,onNew:()=>Se(Re),empty:G?me:null,folder:{count:m.length,path:i.dir},scopeOptions:Tt,scopeKey:It,onScopeKey:Ot,view:c,onView:R,counts:Dt,clusterCount:g.length,archivedCount:i.archived.length}),c==="ask"&&e.jsx("div",{className:"min-w-0 min-h-0 flex",children:e.jsx("div",{className:"flex-1 min-w-0",children:e.jsx(Hs,{rows:m,context:Ce,onClearContext:()=>_(null),onAsk:(r,h)=>a.ask(r,Et(h)),onOpen:Te,onReverify:()=>R("stale"),onDraft:r=>Se(r)})})}),c==="clusters"&&e.jsx("div",{className:"min-w-0 min-h-0 flex",children:e.jsx(Vs,{clusters:g,rows:m,generatedAt:i.clustersMeta.generatedAt,running:i.clustersMeta.running,unclusteredCount:Rt,available:!p,onRegenerate:()=>{a.regenerateClusters()},onOpenCluster:r=>R(`cluster:${r}`),onOpen:Te})}),G&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex flex-col min-w-0 min-h-0",children:w==="new"?e.jsx(Ae,{mode:"new",name:null,title:E,onTitle:X,body:V,onBody:W,onSave:()=>{Pe()},onCancel:yt,saving:oe,dirty:E.trim()!==""||V!==Re}):o?e.jsx(Ts,{row:o,content:B,clusterName:C(o.clusterId),clusterDot:j(o.clusterId),archived:v,editing:w==="edit",editingSuggestion:w==="edit"&&q,editor:w==="edit"?e.jsx(Ae,{mode:"edit",name:o.slug,path:o.path,title:"",onTitle:X,body:V,onBody:W,onSave:()=>{Pe()},onCancel:Fe,onRevert:()=>{bt()},changedFrom:q?re:void 0,saving:oe,dirty:ge}):void 0,onRead:Fe,onEdit:ht,onCopyPath:()=>{Nt()},onReveal:Ct,onArchive:()=>{_e()},onRestore:()=>{jt()},onAskDelete:()=>S("delete"),fix:D,appliedStill:ae===o.slug&&o.stale,onFix:()=>{$e()},onApplyFix:()=>{kt()},onEditFirst:gt,onDiscardFix:()=>L(F),onVerify:()=>{vt()}}):e.jsx(Ae,{mode:"none",name:null,title:"",onTitle:X,body:"",onBody:W,onSave:()=>{},onCancel:()=>{},saving:!1,dirty:!1})}),e.jsx(_s,{row:v||w==="new"?null:o,known:Lt,onOpen:ft,onRemoveLink:r=>{St(r)},onUpdatePath:r=>{$t(r)},onReviewPath:()=>{$e()},onAskAbout:Mt,onCheck:()=>{$e()},checkBusy:D.state!=="idle"||B===null,editing:w==="edit",editingSuggestion:w==="edit"&&q,check:w==="edit"?null:At})]})]}),e.jsx(Gs,{open:ne==="delete"&&o!==null,name:(o==null?void 0:o.slug)??"",inbound:(o==null?void 0:o.inLinks.length)??0,onArchive:()=>{_e()},onCancel:()=>S(null),onConfirm:()=>{wt()}}),e.jsx(zs,{message:(P==null?void 0:P.message)??null,onUndo:P!=null&&P.undo?()=>{const r=P.undo;de(null),r==null||r()}:void 0,onClose:()=>de(null)})]})}function tn(){const s=at(),t=rt();return s?e.jsx(Zs,{cwd:(t==null?void 0:t.cwd)??null}):e.jsx(we,{title:"loading…"})}const sn=l.memo(tn),nn=[{key:"memory",label:"Memory",icon:"memory"},{key:"claude-md",label:"CLAUDE.md",icon:"system-prompt"},{key:"settings",label:"Settings",icon:"settings"},{key:"mcp",label:"MCP",icon:"mcp"},{key:"skills",label:"Skills",icon:"skills"}],ut=nn,st=s=>ut.some(t=>t.key===s);function xt(s,t){return{claudeMd:[`${s}/CLAUDE.md`,`${s}/CLAUDE.local.md`],settings:{project:`${s}/.claude/settings.json`,local:`${s}/.claude/settings.local.json`},mcp:`${s}/.mcp.json`,skillsDir:`${s}/.claude/skills`,commandsDir:`${s}/.claude/commands`,memoryDir:t}}const an={memoryDir:null,memory:null,memoryAttention:!1,claudeMd:null,settings:{project:null,local:null},mcp:null,skills:null},nt=s=>!!s&&typeof s=="object"&&!Array.isArray(s);async function te(s){try{return await s()}catch{return null}}async function rn(s){const t={workspace:ot(s),cwd:s},n=await te(()=>window.api.memory.list(t)),d=xt(s,(n==null?void 0:n.dir)??null),[i,a,m,g,p,y]=await Promise.all([te(async()=>(await Promise.all(d.claudeMd.map(is))).reduce((x,c)=>x+c,0)),te(()=>He(d.settings.project)),te(()=>He(d.settings.local)),te(async()=>{const x=await window.api.config.readJson(d.mcp);if(x.error)throw new Error(x.error);const c=nt(x.data)?x.data.mcpServers:void 0;return nt(c)?Object.keys(c).length:0}),te(async()=>{const[x,c]=await Promise.all([Vt(d.skillsDir),window.api.config.listDir(d.commandsDir,{filesOnly:!0})]);if(x.errors[0])throw new Error(x.errors[0].error);const u=c.ok?c.entries.filter(f=>f.name.endsWith(".md")).length:0;return x.entries.length+u}),te(async()=>{if(!n||n.error)return!1;const x=await window.api.memory.stale(t);return it(n.entries??[],x,null,Date.now()).some(c=>c.stale||c.broken)})]);return{memoryDir:(n==null?void 0:n.dir)??null,memory:n&&!n.error?n.entries.length:null,memoryAttention:y??!1,claudeMd:i,settings:{project:a,local:m},mcp:g,skills:p}}function on(s){const[t,n]=l.useState(null),d=l.useRef(0),i=l.useCallback(()=>{if(!s)return;const g=++d.current;rn(s).then(p=>{g===d.current&&n({cwd:s,counts:p})})},[s]);l.useEffect(()=>(i(),()=>{d.current++}),[i]);const a=t&&t.cwd===s?t.counts:an,m=s?xt(s,a.memoryDir):null;return Ht(m?[...m.claudeMd,m.settings.project,m.settings.local,m.mcp,m.skillsDir,m.commandsDir,m.memoryDir]:[],i,{depth:1}),a}const je=s=>s??void 0;function ln({home:s,cwd:t,scope:n,onScopeChange:d}){const i=l.useMemo(()=>({project:Ke.resolve("project",s,t),local:Ke.resolve("local",s,t)}),[s,t]),a=l.useMemo(()=>{const y=[];return i.project&&y.push({path:i.project,label:"Project · shared via git",eyebrow:"PROJECT INSTRUCTIONS"}),i.local&&y.push({path:i.local,label:"Local · this machine only",eyebrow:"LOCAL INSTRUCTIONS"}),y},[i]),m=l.useCallback(y=>d(y===i.local?"local":"project"),[i.local,d]),g=l.useMemo(()=>({title:n==="local"?"No private notes for this project yet.":"Nothing tells Claude how this repo works yet.",body:n==="local"?`Claude loads this file into every session started in ${We(t)} on this machine. It stays out of git.`:`It loads this file into every session started in ${We(t)} — and so does anyone who clones the repo.`}),[n,t]),p=i[n];return p?e.jsx("div",{"data-testid":"project-claude-md",className:"flex flex-col h-full min-h-0",children:e.jsx(rs,{home:s,scope:"project",roots:a,activeRoot:p,onSelectRoot:m,empty:g,moreMenu:({importSelected:y})=>e.jsx(os,{path:p,disabled:y})})}):e.jsx(we,{title:"loading…"})}function dn({scope:s,onScopeChange:t}){return e.jsx("div",{className:"flex flex-col h-full min-h-0",children:e.jsx(ls,{scope:s,onScopeChange:t})})}function cn(){var ne;const s=at(),t=((ne=rt())==null?void 0:ne.cwd)??null,[n,d]=l.useState("memory"),[i,a]=l.useState("project"),[m,g]=l.useState("project"),[p,y]=l.useState(null),x=on(t),c=zt(qt),u=l.useMemo(()=>Xt(c),[c]),f=l.useCallback(S=>{d(S),y(null)},[]);Kt("memory",S=>{st(S)&&f(S)});const k=l.useCallback(S=>y(S),[]),w=l.useCallback(()=>y(null),[]),$=l.useCallback(S=>{st(S.tab)&&(f(S.tab),xe.getState().set(S.tab,S.id))},[f]),b=l.useCallback(()=>Jt({scope:"project",cwd:t,api:window.api}),[t]),M=Qt({load:b,loadKey:t??"",onChoose:$}),K=l.useMemo(()=>{const S={memory:{count:je(x.memory),attention:x.memoryAttention},"claude-md":Zt(x.claudeMd),settings:{count:je(x.settings[m])},mcp:{count:je(x.mcp),attention:u},skills:{count:je(x.skills)}};return ut.map(D=>({...D,...S[D.key]}))},[x,m,u]);if(!s)return e.jsx(we,{title:"loading…"});if(!t)return e.jsx(we,{title:"no active project",hint:"open a project tab to edit its CLAUDE.md, settings, MCP servers, skills and memory"});const z=Wt.memory;return e.jsxs(es,{testId:"project-claude-config",eyebrow:"CLAUDE CODE · PROJECT",title:"Claude config",scopePath:ds(t,s),tabs:K,activeKey:n,onSelect:f,search:M,learn:z,drawer:e.jsx(ns,{open:p!==null,onClose:w,title:"Add MCP server",keyVals:[],children:p&&e.jsx(as,{scope:p.scope,cwd:p.cwd})}),children:[n==="memory"&&e.jsx(sn,{}),n==="claude-md"&&e.jsx(ln,{home:s,cwd:t,scope:i,onScopeChange:a}),n==="settings"&&e.jsx(dn,{scope:m,onScopeChange:g}),n==="mcp"&&e.jsx(ts,{scope:"project",onAdd:k}),n==="skills"&&e.jsx(ss,{scope:"project"})]})}const bn=l.memo(cn);export{bn as ProjectClaudeConfig};