claude-code-session-manager 0.122.1 → 0.123.1

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 (93) hide show
  1. package/dist/assets/{AgentLibrary-C2qUX9WU.js → AgentLibrary-T14aM8ie.js} +2 -2
  2. package/dist/assets/{Button-ssBzvFha.js → Button-Dz1kV8Z_.js} +1 -1
  3. package/dist/assets/DataModel-DdYRn2Ec.js +1 -0
  4. package/dist/assets/{History-BRdRp1J_.js → History-zQPvqwE7.js} +2 -2
  5. package/dist/assets/{Hooks--hiGPBQy.js → Hooks-BTrbT742.js} +3 -3
  6. package/dist/assets/{Library-0XYvkhh2.js → Library-BwQ6GRHR.js} +7 -7
  7. package/dist/assets/ListDetail-CunxAhRC.js +1 -0
  8. package/dist/assets/{McpServers-CCjHSwFm.js → McpServers-DpoyxXaO.js} +2 -2
  9. package/dist/assets/{Memory-C7RXoVO4.js → Memory-KDtGYMc3.js} +8 -8
  10. package/dist/assets/{Panel-C92O_aAH.js → Panel-xXmUBo8l.js} +1 -1
  11. package/dist/assets/{Permissions-DuTJ1FUb.js → Permissions-lIzTUrW2.js} +3 -3
  12. package/dist/assets/{Plugins-DSXsP4hM.js → Plugins-BA1Zqk69.js} +2 -2
  13. package/dist/assets/{ProvenanceBadge-CWdDkU1m.js → ProvenanceBadge-CmeJG2Kw.js} +1 -1
  14. package/dist/assets/{SaveBar-ob2dJJjH.js → SaveBar-BTJg_9Uc.js} +1 -1
  15. package/dist/assets/{Scheduler-Du4HgPKY.js → Scheduler-CISTDNMU.js} +7 -7
  16. package/dist/assets/{ScopeSwitcher-Dv_6M_Ci.js → ScopeSwitcher-C6NWvzoj.js} +1 -1
  17. package/dist/assets/Settings-BBoGJ34v.js +4 -0
  18. package/dist/assets/{SkillReferenceGraph-Dx1Qs8Y0.js → SkillReferenceGraph-IJv60QAJ.js} +1 -1
  19. package/dist/assets/Skills-L6nGcNF1.js +2 -0
  20. package/dist/assets/SystemPrompt-Cm7I2gJz.js +1 -0
  21. package/dist/assets/TagLibrary-BxPwoPE6.js +1 -0
  22. package/dist/assets/{TiptapBody-Cihe5er3.js → TiptapBody-CR-Zr3Pz.js} +1 -1
  23. package/dist/assets/{Toggle-CpYVC8bF.js → Toggle-BFhlpZ-n.js} +1 -1
  24. package/dist/assets/{ViewTabs-C3FN6P_C.js → ViewTabs-CuGlZ9Ed.js} +1 -1
  25. package/dist/assets/{historyTotals-C4Rs37Cd.js → historyTotals-Dxv9Fzrs.js} +1 -1
  26. package/dist/assets/{index-Dd7UQabV.css → index-BnKaYERU.css} +1 -1
  27. package/dist/assets/{index-S-F5jp_h.js → index-Dx8owDeQ.js} +151 -151
  28. package/dist/assets/{settingsSchema-BZcdzHTQ.js → settingsSchema-DaqFSAQH.js} +1 -1
  29. package/dist/assets/{skillFrontmatter-EfNERt4b.js → skillFrontmatter-BIJddxVB.js} +1 -1
  30. package/dist/assets/{useAgentsDirWatch-BfbrFvB3.js → useAgentsDirWatch-1hjZ4knk.js} +1 -1
  31. package/dist/index.html +2 -2
  32. package/package.json +3 -3
  33. package/plugins/session-manager-dev/skills/develop/SKILL.md +29 -25
  34. package/scripts/scheduler-mcp-server.cjs +124 -74
  35. package/src/main/agentLibrary.cjs +8 -3
  36. package/src/main/build-info.json +4 -4
  37. package/src/main/crashDiagnostics.cjs +24 -0
  38. package/src/main/historyAggregator.cjs +41 -7
  39. package/src/main/index.cjs +13 -3
  40. package/src/main/ipcSchemas.cjs +30 -22
  41. package/src/main/lib/activeSessions.cjs +93 -32
  42. package/src/main/lib/epic/delegationReadiness.cjs +2 -0
  43. package/src/main/lib/epic/delegationSelfHeal.cjs +77 -0
  44. package/src/main/lib/epic/epicMint.cjs +1 -1
  45. package/src/main/lib/epic/epicStandingInstructions.cjs +73 -0
  46. package/src/main/lib/epic/guardSpawnSettings.cjs +76 -0
  47. package/src/main/lib/feedback-remote/crossProjectFeedback.cjs +9 -2
  48. package/src/main/lib/feedback-remote/remoteClientSessions.cjs +3 -11
  49. package/src/main/lib/feedback-remote/remoteE2eCrypto.cjs +1 -1
  50. package/src/main/lib/git/gitWorktree.cjs +9 -4
  51. package/src/main/lib/git/worktreeDeps.cjs +13 -2
  52. package/src/main/lib/git/worktreeSetup.cjs +212 -0
  53. package/src/main/lib/mcpToolCatalog.cjs +31 -2
  54. package/src/main/lib/persona-macro/agentPersonaSchema.cjs +4 -0
  55. package/src/main/lib/persona-macro/shippedPersonaSeeds.cjs +23 -0
  56. package/src/main/lib/prd/prdAgentType.cjs +28 -0
  57. package/src/main/lib/prd/prdBodyPatch.cjs +138 -0
  58. package/src/main/lib/prd/prdCreate.cjs +205 -32
  59. package/src/main/lib/prd/prdGateFiles.cjs +31 -0
  60. package/src/main/lib/scheduler/definitionOfDone.cjs +24 -3
  61. package/src/main/lib/scheduler/queueStore.cjs +5 -4
  62. package/src/main/lib/scheduler/scheduleJobSchema.cjs +1 -0
  63. package/src/main/lib/scheduler/schedulerBatch.cjs +43 -5
  64. package/src/main/lib/scheduler/schedulerPaths.cjs +2 -0
  65. package/src/main/lib/scheduler/watchdogHelpers.cjs +114 -22
  66. package/src/main/lib/telemetry/mainHeapSnapshot.cjs +69 -0
  67. package/src/main/lib/telemetry/telemetryBoot.cjs +25 -3
  68. package/src/main/lib/telemetry/telemetryClient.cjs +12 -0
  69. package/src/main/lib/telemetry/telemetryCounters.cjs +25 -2
  70. package/src/main/pty.cjs +0 -53
  71. package/src/main/runVerify.cjs +38 -11
  72. package/src/main/scheduler/prdParser.cjs +3 -0
  73. package/src/main/scheduler/prdPaths.cjs +48 -2
  74. package/src/main/scheduler.cjs +124 -29
  75. package/src/main/seedDevPlugin.cjs +1 -1
  76. package/src/main/seedSchedulerMcp.cjs +1 -1
  77. package/src/main/templates/PRD_AUTHORING.md +8 -4
  78. package/src/main/webRemote.cjs +38 -132
  79. package/src/preload/api.d.ts +4 -52
  80. package/src/preload/index.cjs +0 -24
  81. package/src/seed/agents/dev-lead.md +2 -1
  82. package/src/seed/agents/validator.md +2 -1
  83. package/dist/assets/DataModel-CENoTvc2.js +0 -1
  84. package/dist/assets/ListDetail-CkKXAM59.js +0 -1
  85. package/dist/assets/RemoteMachines-BFmbIGpW.js +0 -3
  86. package/dist/assets/Settings-DMoI0cqB.js +0 -4
  87. package/dist/assets/Skills-DYWQTQB1.js +0 -2
  88. package/dist/assets/SystemPrompt-Df0IfOuI.js +0 -1
  89. package/dist/assets/TagLibrary-BuMsGx-2.js +0 -1
  90. package/dist/assets/useRemotePeers-CKVakQPc.js +0 -1
  91. package/src/main/lib/feedback-remote/relayClientAuth.cjs +0 -133
  92. package/src/main/remoteClient.cjs +0 -334
  93. package/src/main/remoteClientIpc.cjs +0 -133
@@ -0,0 +1 @@
1
+ import{al as e}from"./index-Dx8owDeQ.js";function o({sidebar:r,detail:s,sidebarWidth:l="18rem"}){return e.jsxs("div",{className:"h-full flex",children:[e.jsx("div",{className:"shrink-0 border-r border-line overflow-y-auto",style:{width:l},children:r}),e.jsx("div",{className:"flex-1 min-w-0 overflow-auto",children:s})]})}export{o as L};
@@ -1,2 +1,2 @@
1
- import{ap as e,aF as c,b4 as xe,aY as ue,b6 as pe,a_ as S,n as _,a as z,bf as fe,aX as H}from"./index-S-F5jp_h.js";import{P as J}from"./Panel-C92O_aAH.js";import{L as me}from"./ListDetail-CkKXAM59.js";import{S as he}from"./SaveBar-ob2dJJjH.js";import{S as U}from"./ScopeSwitcher-Dv_6M_Ci.js";import{P as X}from"./ProvenanceBadge-CWdDkU1m.js";import{M as ge,V as I,g as Z}from"./Library-0XYvkhh2.js";import"./monaco-editor-BsIlgG7c.js";import"./Button-ssBzvFha.js";import"./listSkills-C1aWKf0T.js";const be={live:"bg-emerald-400",idle:"bg-amber-400",offline:"bg-fg-faint",attention:"bg-accent",paused:"bg-zinc-500"},je={sm:"w-1.5 h-1.5",md:"w-2 h-2"},ve={on:"live",off:"offline",warn:"attention",live:"live",idle:"idle"};function te({state:l,kind:t,pulse:a=!1,size:d="sm",className:f="",title:b,"aria-label":o}){const j=l??(t?ve[t]:"idle"),r=be[j],g=je[d],x=a?"animate-pulse":"",u=o??b??j;return e.jsx("span",{role:"img","aria-label":u,className:`inline-block rounded-full ${g} ${r} ${x} ${f}`.trim(),title:b})}const ye={failed:"Failed","needs-auth":"Needs auth",pending:"Pending approval"};function Q(l,t){const a=t!=null&&t.ok?t.servers.find(d=>d.name===l):void 0;return!a||a.status==="unknown"?{state:"unprobed",label:"Not checked",probeStatus:(a==null?void 0:a.status)??null,badgeTone:"dim",dotState:"offline"}:a.status==="connected"?{state:"ready",label:"Ready",probeStatus:a.status,badgeTone:"good",dotState:"live"}:{state:"not-ready",label:ye[a.status],probeStatus:a.status,badgeTone:"warn",dotState:"attention"}}const W=(l,t)=>({type:"mcp",name:l,command:t.command,args:t.args,url:t.url}),Ne=["stdio","http","streamable-http","sse","ws"],we=new Set(["workspace"]),Se=new Set(["ide","tasks"]);function Ce(l,t,a){return l==="user"?`${t}/.claude.json`:a?`${a}/.mcp.json`:null}function ke(l){if(l.trim()==="")return{full:{},servers:{},err:null};try{const t=JSON.parse(l),a=t.mcpServers??{};return{full:t,servers:a,err:null}}catch(t){return{full:{},servers:{},err:t.message}}}function Ee(l,t){return JSON.stringify({...l,mcpServers:t},null,2)+`
2
- `}function Te(l){let t=Object.keys(l).length+1,a=`server-${t}`;for(;l[a];)t+=1,a=`server-${t}`;return a}function Re(){const l=xe(),t=ue(),a=(t==null?void 0:t.cwd)??null,d=pe(s=>s.navFace),f=c.useRef(!1),b=c.useRef(d),[o,j]=c.useState(()=>d==="project"&&a?"project":"user"),[r,g]=c.useState(null),[x,u]=c.useState("installed"),[C,B]=c.useState("");c.useEffect(()=>{if(b.current!==d){if(b.current=d,f.current){f.current=!1;return}j(d==="project"&&a?"project":"user")}},[d,a]);const p=c.useMemo(()=>l?Ce(o,l,a):null,[l,o,a]),k=S(s=>s.files),n=S(s=>s.loadJson),v=S(s=>s.setDraft),m=S(s=>s.saveJson),K=S(s=>s.revert),R=S(s=>s.watchFile),se=S(s=>s.unwatchFile);c.useEffect(()=>{if(p)return k[p]||n(p),R(p),()=>se(p)},[p]);const[ae,F]=c.useState(null),[Y,q]=c.useState(null),[D,G]=c.useState(!1),A=c.useRef(0),L=c.useRef(!0);c.useEffect(()=>()=>{L.current=!1},[]);const V=async()=>{const s=++A.current;G(!0);try{const i=await window.api.mcp.status();if(!L.current||s!==A.current)return;q(i),i.ok||H.error(i.error??"MCP status probe failed")}catch(i){if(!L.current||s!==A.current)return;q(null),H.error(i.message||"MCP status probe failed")}finally{L.current&&s===A.current&&G(!1)}};if(c.useEffect(()=>{V()},[]),!l)return e.jsx(_,{title:"loading…"});if(x==="library")return e.jsx(J,{toolbar:e.jsx(I,{active:x,onChange:u}),children:e.jsx(ge,{})});if(o==="project"&&!a)return e.jsx(J,{toolbar:e.jsxs(e.Fragment,{children:[e.jsx(I,{active:x,onChange:u}),e.jsx("span",{className:"mx-2 text-fg-faint",children:"·"}),e.jsx(U,{scopes:["user","project"],active:o,onChange:s=>{f.current=!0,j(s)}})]}),children:e.jsx(_,{title:"no active project"})});if(!p)return e.jsx(_,{title:"loading…"});const w=k[p],{full:ne,servers:h,err:le}=w?ke(w.draftRaw):{full:{},servers:{},err:null},M=Object.keys(h).sort(),O=r?h[r]:null,P=s=>{F(null),v(p,Ee(ne,s))},re=()=>{const s=Te(h);P({...h,[s]:{type:"stdio",command:"",args:[]}}),g(s)},oe=s=>{const i={...h};delete i[s],P(i),r===s&&g(null)},ie=(s,i)=>{if(!i||i===s||h[i])return;const y={};for(const N of Object.keys(h))y[N===s?i:N]=h[N];P(y),g(i)},ce=(s,i)=>{P({...h,[s]:i})};return e.jsx(J,{toolbar:e.jsxs(e.Fragment,{children:[e.jsx(I,{active:x,onChange:u}),e.jsx("span",{className:"mx-2 text-fg-faint",children:"·"}),e.jsx(U,{scopes:["user","project"],active:o,onChange:s=>{f.current=!0,j(s)}}),e.jsxs("span",{className:"ml-3 px-1.5 py-0.5 text-[10px] rounded border border-line text-fg-faint",children:[M.length," server",M.length===1?"":"s"]}),e.jsx("span",{className:"ml-2 text-fg-faint truncate",children:p}),e.jsx("div",{className:"flex-1"}),r&&O&&e.jsx(X,{scope:o,input:W(r,O),className:"mr-2"}),e.jsx("button",{onClick:V,disabled:D,className:"px-2 py-0.5 text-xs border border-line rounded text-fg-dim hover:text-fg hover:bg-bg-hi disabled:opacity-50 mr-2",children:D?"checking…":"⟳ test connections"}),e.jsx("button",{onClick:re,className:"px-2 py-0.5 text-xs border border-line rounded text-fg-dim hover:text-fg hover:bg-bg-hi",children:"+ new server"})]}),footer:w?e.jsx(he,{dirty:w.dirty,busy:w.busy,parseError:ae||le||w.parseError,lastSavedAt:w.lastSavedAt,onSave:async()=>{var y;F(null);const s=((y=w.diskData)==null?void 0:y.mcpServers)??{};for(const[N,E]of Object.entries(h)){if(JSON.stringify(E)===JSON.stringify(s[N]))continue;const $=Z(E);if($.length>0){fe.getState().show("error",`Not saved: "${N}" still contains placeholder ${$.map(de=>de.token).join(", ")} — replace it with a real value`);return}}const i=await m(p);i.ok||F(i.error??"save failed")},onRevert:()=>{F(null),K(p)}}):null,children:e.jsx(me,{sidebar:e.jsxs("div",{className:"py-2",children:[e.jsx("div",{className:"px-2 pb-1",children:e.jsx("input",{value:C,onChange:s=>B(s.target.value),placeholder:"filter…",className:"w-full bg-bg border border-line rounded px-2 py-0.5 text-xs text-fg"})}),M.length===0?e.jsx("div",{className:"px-3 py-1 text-xs text-fg-faint italic",children:"no servers"}):M.filter(s=>!C||s.toLowerCase().includes(C.toLowerCase())).map(s=>{var N;const i=Q(s,Y),y=(N=h[s].description)==null?void 0:N.trim();return e.jsxs("button",{onClick:()=>g(s),className:`w-full text-left px-3 py-1 text-xs flex flex-col gap-0.5 ${r===s?"bg-bg-hi text-fg":"text-fg-dim hover:text-fg hover:bg-bg-hi"}`,children:[e.jsxs("span",{className:"flex items-center gap-2 justify-between w-full",children:[e.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[e.jsx(te,{state:i.dotState,title:i.label}),e.jsx("span",{className:"truncate",children:s})]}),e.jsxs("span",{className:"ml-2 flex items-center gap-2 shrink-0",children:[(()=>{const E=Z(h[s]);return E.length>0?e.jsxs(z,{tone:"warn",title:`${o} scope · ${p}`,children:["unconfigured placeholder: ",E.map($=>$.token).join(", ")]}):null})(),e.jsx(z,{tone:i.badgeTone,children:i.label}),e.jsx(X,{interactive:!1,scope:o,input:W(s,h[s])}),e.jsx("span",{className:"text-fg-faint",children:h[s].type??"stdio"})]})]}),y?e.jsx("span",{className:"pl-5 text-fg-faint truncate",title:y,children:y}):null]},s)})]}),detail:r&&O?e.jsx(Fe,{name:r,server:O,connection:Q(r,Y),onTestConnection:V,testing:D,onRename:s=>ie(r,s),onChange:s=>ce(r,s),onRemove:()=>oe(r)}):e.jsx(_,{title:"select a server or click + new"})})})}const Je=c.memo(Re);function Fe({name:l,server:t,connection:a,onTestConnection:d,testing:f,onRename:b,onChange:o,onRemove:j}){var k;const r=t.type??"stdio",g=we.has(l),x=Se.has(l),u=(k=t.permissions)==null?void 0:k.tools,C=u===void 0?"inherit":u==="allow"?"allow":u==="deny"?"deny":"list",B=Array.isArray(u)?u:[],p=(t.disabledTools??[]).join(", ");return e.jsxs("div",{className:"p-4 space-y-4 max-w-2xl",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(te,{state:a.dotState,size:"md",title:a.label}),e.jsx(z,{tone:a.badgeTone,children:a.label}),e.jsx("button",{onClick:d,disabled:f,className:"ml-auto px-2 py-0.5 text-xs border border-line rounded text-fg-dim hover:text-fg hover:bg-bg-hi disabled:opacity-50",children:f?"checking…":"test connection"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("label",{className:"text-xs text-fg-faint w-20",children:"name"}),e.jsx("input",{defaultValue:l,onBlur:n=>b(n.target.value.trim()),className:"flex-1 bg-bg-elev border border-line rounded px-2 py-1 text-xs text-fg font-mono"}),e.jsx("button",{onClick:j,className:"text-xs text-fg-faint hover:text-red-400 px-2 py-1 border border-line rounded",children:"delete"})]}),e.jsx(T,{label:"description",value:t.description??"",onChange:n=>o({...t,description:n||void 0}),placeholder:"what this server does…"}),g?e.jsxs("div",{className:"text-xs px-2 py-1 border border-red-500/50 rounded text-red-300 bg-red-500/5",children:["⚠ ",e.jsx("span",{className:"font-mono",children:l})," is a reserved name — Claude Code will refuse to load this server (v2.1.128+)."]}):x?e.jsxs("div",{className:"text-xs px-2 py-1 border border-yellow-600/50 rounded text-yellow-200 bg-yellow-500/5",children:["⚠ ",e.jsx("span",{className:"font-mono",children:l})," collides with a commonly-bundled MCP name; expect surprises in other tools."]}):null,e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("label",{className:"text-xs text-fg-faint w-20",children:"type"}),e.jsx("select",{value:r,onChange:n=>o({...t,type:n.target.value}),className:"bg-bg-elev border border-line rounded px-2 py-1 text-xs text-fg",children:Ne.map(n=>e.jsx("option",{value:n,children:n},n))}),r==="sse"?e.jsx("span",{className:"text-xs text-yellow-400/80",children:"sse is deprecated — prefer streamable-http"}):null]}),r==="stdio"?e.jsxs(e.Fragment,{children:[e.jsx(T,{label:"command",value:t.command??"",onChange:n=>o({...t,command:n}),placeholder:"npx / node / python …"}),e.jsx(T,{label:"args",value:(t.args??[]).join(" "),onChange:n=>o({...t,args:n.split(/\s+/).filter(Boolean)}),placeholder:"space-separated args"}),e.jsx(ee,{label:"env",value:t.env??{},onChange:n=>o({...t,env:n})})]}):e.jsxs(e.Fragment,{children:[e.jsx(T,{label:"url",value:t.url??"",onChange:n=>o({...t,url:n}),placeholder:"https://…"}),e.jsx(ee,{label:"headers",value:t.headers??{},onChange:n=>o({...t,headers:n})})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("label",{className:"text-xs text-fg-faint w-20",children:"alwaysLoad"}),e.jsxs("label",{className:"flex items-center gap-2 text-xs text-fg",children:[e.jsx("input",{type:"checkbox",checked:t.alwaysLoad===!0,onChange:n=>o({...t,alwaysLoad:n.target.checked||void 0})}),e.jsx("span",{className:"text-fg-dim",children:"bypass tool-search deferral (v2.1.121+)"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("label",{className:"text-xs text-fg-faint w-20",children:"enabled"}),e.jsxs("label",{className:"flex items-center gap-2 text-xs text-fg",children:[e.jsx("input",{type:"checkbox",checked:t.enabled!==!1,onChange:n=>o({...t,enabled:n.target.checked?void 0:!1})}),e.jsx("span",{className:"text-fg-dim",children:"load this server in new sessions"})]})]}),e.jsx(T,{label:"disabledTools",value:p,onChange:n=>{const v=n.split(",").map(m=>m.trim()).filter(Boolean);o({...t,disabledTools:v.length?v:void 0})},placeholder:"comma-separated tool names to hide"}),e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("label",{className:"text-xs text-fg-faint w-20 pt-1",children:"permissions"}),e.jsxs("div",{className:"flex-1 space-y-1",children:[e.jsxs("select",{value:C,onChange:n=>{const v=n.target.value,m={...t};if(v==="inherit"){if(m.permissions){const{tools:K,...R}=m.permissions;m.permissions=Object.keys(R).length?R:void 0}}else v==="list"?m.permissions={...m.permissions??{},tools:[]}:m.permissions={...m.permissions??{},tools:v};o(m)},className:"bg-bg-elev border border-line rounded px-2 py-1 text-xs text-fg",children:[e.jsx("option",{value:"inherit",children:"inherit (default)"}),e.jsx("option",{value:"allow",children:"allow all tools"}),e.jsx("option",{value:"deny",children:"deny all tools"}),e.jsx("option",{value:"list",children:"allowlist…"})]}),C==="list"?e.jsx("input",{value:B.join(", "),onChange:n=>{const v=n.target.value.split(",").map(m=>m.trim()).filter(Boolean);o({...t,permissions:{...t.permissions??{},tools:v}})},placeholder:"comma-separated tool names",className:"w-full bg-bg-elev border border-line rounded px-2 py-1 text-xs text-fg font-mono"}):null]})]})]})}function T({label:l,value:t,onChange:a,placeholder:d}){return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("label",{className:"text-xs text-fg-faint w-20",children:l}),e.jsx("input",{value:t,onChange:f=>a(f.target.value),placeholder:d,className:"flex-1 bg-bg-elev border border-line rounded px-2 py-1 text-xs text-fg font-mono"})]})}function ee({label:l,value:t,onChange:a}){const[d,f]=c.useState(""),[b,o]=c.useState(""),j=Object.entries(t);return e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("label",{className:"text-xs text-fg-faint w-20 pt-1",children:l}),e.jsxs("div",{className:"flex-1 space-y-1",children:[j.map(([r,g])=>e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{value:r,onChange:x=>{const u={...t};delete u[r],u[x.target.value]=g,a(u)},className:"w-32 bg-bg-elev border border-line rounded px-2 py-0.5 text-xs text-fg font-mono"}),e.jsx("input",{value:g,onChange:x=>a({...t,[r]:x.target.value}),className:"flex-1 bg-bg-elev border border-line rounded px-2 py-0.5 text-xs text-fg font-mono"}),e.jsx("button",{onClick:()=>{const x={...t};delete x[r],a(x)},className:"text-fg-faint hover:text-red-400 text-xs px-1",children:"×"})]},r)),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{value:d,onChange:r=>f(r.target.value),placeholder:"key",className:"w-32 bg-bg border border-line rounded px-2 py-0.5 text-xs text-fg-dim font-mono"}),e.jsx("input",{value:b,onChange:r=>o(r.target.value),placeholder:"value",className:"flex-1 bg-bg border border-line rounded px-2 py-0.5 text-xs text-fg-dim font-mono"}),e.jsx("button",{onClick:()=>{d.trim()&&(a({...t,[d.trim()]:b}),f(""),o(""))},className:"px-2 text-xs border border-line rounded text-fg-dim hover:text-fg hover:bg-bg-hi",children:"+"})]})]})]})}export{Je as McpServers,Te as nextServerName};
1
+ import{al as e,aB as c,b0 as xe,aU as ue,b2 as pe,aW as S,m as B,a as z,bb as fe,aT as G}from"./index-Dx8owDeQ.js";import{P as J}from"./Panel-xXmUBo8l.js";import{L as me}from"./ListDetail-CunxAhRC.js";import{S as he}from"./SaveBar-BTJg_9Uc.js";import{S as H}from"./ScopeSwitcher-C6NWvzoj.js";import{P as W}from"./ProvenanceBadge-CmeJG2Kw.js";import{M as ge,V as I,g as Z}from"./Library-BwQ6GRHR.js";import"./monaco-editor-BsIlgG7c.js";import"./Button-Dz1kV8Z_.js";import"./listSkills-C1aWKf0T.js";const be={live:"bg-emerald-400",idle:"bg-amber-400",offline:"bg-fg-faint",attention:"bg-accent",paused:"bg-zinc-500"},je={sm:"w-1.5 h-1.5",md:"w-2 h-2"},ve={on:"live",off:"offline",warn:"attention",live:"live",idle:"idle"};function te({state:l,kind:t,pulse:a=!1,size:d="sm",className:f="",title:b,"aria-label":o}){const j=l??(t?ve[t]:"idle"),r=be[j],g=je[d],x=a?"animate-pulse":"",u=o??b??j;return e.jsx("span",{role:"img","aria-label":u,className:`inline-block rounded-full ${g} ${r} ${x} ${f}`.trim(),title:b})}const ye={failed:"Failed","needs-auth":"Needs auth",pending:"Pending approval"};function Q(l,t){const a=t!=null&&t.ok?t.servers.find(d=>d.name===l):void 0;return!a||a.status==="unknown"?{state:"unprobed",label:"Not checked",probeStatus:(a==null?void 0:a.status)??null,badgeTone:"dim",dotState:"offline"}:a.status==="connected"?{state:"ready",label:"Ready",probeStatus:a.status,badgeTone:"good",dotState:"live"}:{state:"not-ready",label:ye[a.status],probeStatus:a.status,badgeTone:"warn",dotState:"attention"}}const X=(l,t)=>({type:"mcp",name:l,command:t.command,args:t.args,url:t.url}),Ne=["stdio","http","streamable-http","sse","ws"],we=new Set(["workspace"]),Se=new Set(["ide","tasks"]);function Ce(l,t,a){return l==="user"?`${t}/.claude.json`:a?`${a}/.mcp.json`:null}function ke(l){if(l.trim()==="")return{full:{},servers:{},err:null};try{const t=JSON.parse(l),a=t.mcpServers??{};return{full:t,servers:a,err:null}}catch(t){return{full:{},servers:{},err:t.message}}}function Ee(l,t){return JSON.stringify({...l,mcpServers:t},null,2)+`
2
+ `}function Te(l){let t=Object.keys(l).length+1,a=`server-${t}`;for(;l[a];)t+=1,a=`server-${t}`;return a}function Re(){const l=xe(),t=ue(),a=(t==null?void 0:t.cwd)??null,d=pe(s=>s.navFace),f=c.useRef(!1),b=c.useRef(d),[o,j]=c.useState(()=>d==="project"&&a?"project":"user"),[r,g]=c.useState(null),[x,u]=c.useState("installed"),[C,_]=c.useState("");c.useEffect(()=>{if(b.current!==d){if(b.current=d,f.current){f.current=!1;return}j(d==="project"&&a?"project":"user")}},[d,a]);const p=c.useMemo(()=>l?Ce(o,l,a):null,[l,o,a]),k=S(s=>s.files),n=S(s=>s.loadJson),v=S(s=>s.setDraft),m=S(s=>s.saveJson),K=S(s=>s.revert),R=S(s=>s.watchFile),se=S(s=>s.unwatchFile);c.useEffect(()=>{if(p)return k[p]||n(p),R(p),()=>se(p)},[p]);const[ae,F]=c.useState(null),[q,U]=c.useState(null),[D,Y]=c.useState(!1),A=c.useRef(0),L=c.useRef(!0);c.useEffect(()=>()=>{L.current=!1},[]);const V=async()=>{const s=++A.current;Y(!0);try{const i=await window.api.mcp.status();if(!L.current||s!==A.current)return;U(i),i.ok||G.error(i.error??"MCP status probe failed")}catch(i){if(!L.current||s!==A.current)return;U(null),G.error(i.message||"MCP status probe failed")}finally{L.current&&s===A.current&&Y(!1)}};if(c.useEffect(()=>{V()},[]),!l)return e.jsx(B,{title:"loading…"});if(x==="library")return e.jsx(J,{toolbar:e.jsx(I,{active:x,onChange:u}),children:e.jsx(ge,{})});if(o==="project"&&!a)return e.jsx(J,{toolbar:e.jsxs(e.Fragment,{children:[e.jsx(I,{active:x,onChange:u}),e.jsx("span",{className:"mx-2 text-fg-faint",children:"·"}),e.jsx(H,{scopes:["user","project"],active:o,onChange:s=>{f.current=!0,j(s)}})]}),children:e.jsx(B,{title:"no active project"})});if(!p)return e.jsx(B,{title:"loading…"});const w=k[p],{full:ne,servers:h,err:le}=w?ke(w.draftRaw):{full:{},servers:{},err:null},M=Object.keys(h).sort(),O=r?h[r]:null,P=s=>{F(null),v(p,Ee(ne,s))},re=()=>{const s=Te(h);P({...h,[s]:{type:"stdio",command:"",args:[]}}),g(s)},oe=s=>{const i={...h};delete i[s],P(i),r===s&&g(null)},ie=(s,i)=>{if(!i||i===s||h[i])return;const y={};for(const N of Object.keys(h))y[N===s?i:N]=h[N];P(y),g(i)},ce=(s,i)=>{P({...h,[s]:i})};return e.jsx(J,{toolbar:e.jsxs(e.Fragment,{children:[e.jsx(I,{active:x,onChange:u}),e.jsx("span",{className:"mx-2 text-fg-faint",children:"·"}),e.jsx(H,{scopes:["user","project"],active:o,onChange:s=>{f.current=!0,j(s)}}),e.jsxs("span",{className:"ml-3 px-1.5 py-0.5 text-[10px] rounded border border-line text-fg-faint",children:[M.length," server",M.length===1?"":"s"]}),e.jsx("span",{className:"ml-2 text-fg-faint truncate",children:p}),e.jsx("div",{className:"flex-1"}),r&&O&&e.jsx(W,{scope:o,input:X(r,O),className:"mr-2"}),e.jsx("button",{onClick:V,disabled:D,className:"px-2 py-0.5 text-xs border border-line rounded text-fg-dim hover:text-fg hover:bg-bg-hi disabled:opacity-50 mr-2",children:D?"checking…":"⟳ test connections"}),e.jsx("button",{onClick:re,className:"px-2 py-0.5 text-xs border border-line rounded text-fg-dim hover:text-fg hover:bg-bg-hi",children:"+ new server"})]}),footer:w?e.jsx(he,{dirty:w.dirty,busy:w.busy,parseError:ae||le||w.parseError,lastSavedAt:w.lastSavedAt,onSave:async()=>{var y;F(null);const s=((y=w.diskData)==null?void 0:y.mcpServers)??{};for(const[N,E]of Object.entries(h)){if(JSON.stringify(E)===JSON.stringify(s[N]))continue;const $=Z(E);if($.length>0){fe.getState().show("error",`Not saved: "${N}" still contains placeholder ${$.map(de=>de.token).join(", ")} — replace it with a real value`);return}}const i=await m(p);i.ok||F(i.error??"save failed")},onRevert:()=>{F(null),K(p)}}):null,children:e.jsx(me,{sidebar:e.jsxs("div",{className:"py-2",children:[e.jsx("div",{className:"px-2 pb-1",children:e.jsx("input",{value:C,onChange:s=>_(s.target.value),placeholder:"filter…",className:"w-full bg-bg border border-line rounded px-2 py-0.5 text-xs text-fg"})}),M.length===0?e.jsx("div",{className:"px-3 py-1 text-xs text-fg-faint italic",children:"no servers"}):M.filter(s=>!C||s.toLowerCase().includes(C.toLowerCase())).map(s=>{var N;const i=Q(s,q),y=(N=h[s].description)==null?void 0:N.trim();return e.jsxs("button",{onClick:()=>g(s),className:`w-full text-left px-3 py-1 text-xs flex flex-col gap-0.5 ${r===s?"bg-bg-hi text-fg":"text-fg-dim hover:text-fg hover:bg-bg-hi"}`,children:[e.jsxs("span",{className:"flex items-center gap-2 justify-between w-full",children:[e.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[e.jsx(te,{state:i.dotState,title:i.label}),e.jsx("span",{className:"truncate",children:s})]}),e.jsxs("span",{className:"ml-2 flex items-center gap-2 shrink-0",children:[(()=>{const E=Z(h[s]);return E.length>0?e.jsxs(z,{tone:"warn",title:`${o} scope · ${p}`,children:["unconfigured placeholder: ",E.map($=>$.token).join(", ")]}):null})(),e.jsx(z,{tone:i.badgeTone,children:i.label}),e.jsx(W,{interactive:!1,scope:o,input:X(s,h[s])}),e.jsx("span",{className:"text-fg-faint",children:h[s].type??"stdio"})]})]}),y?e.jsx("span",{className:"pl-5 text-fg-faint truncate",title:y,children:y}):null]},s)})]}),detail:r&&O?e.jsx(Fe,{name:r,server:O,connection:Q(r,q),onTestConnection:V,testing:D,onRename:s=>ie(r,s),onChange:s=>ce(r,s),onRemove:()=>oe(r)}):e.jsx(B,{title:"select a server or click + new"})})})}const Je=c.memo(Re);function Fe({name:l,server:t,connection:a,onTestConnection:d,testing:f,onRename:b,onChange:o,onRemove:j}){var k;const r=t.type??"stdio",g=we.has(l),x=Se.has(l),u=(k=t.permissions)==null?void 0:k.tools,C=u===void 0?"inherit":u==="allow"?"allow":u==="deny"?"deny":"list",_=Array.isArray(u)?u:[],p=(t.disabledTools??[]).join(", ");return e.jsxs("div",{className:"p-4 space-y-4 max-w-2xl",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(te,{state:a.dotState,size:"md",title:a.label}),e.jsx(z,{tone:a.badgeTone,children:a.label}),e.jsx("button",{onClick:d,disabled:f,className:"ml-auto px-2 py-0.5 text-xs border border-line rounded text-fg-dim hover:text-fg hover:bg-bg-hi disabled:opacity-50",children:f?"checking…":"test connection"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("label",{className:"text-xs text-fg-faint w-20",children:"name"}),e.jsx("input",{defaultValue:l,onBlur:n=>b(n.target.value.trim()),className:"flex-1 bg-bg-elev border border-line rounded px-2 py-1 text-xs text-fg font-mono"}),e.jsx("button",{onClick:j,className:"text-xs text-fg-faint hover:text-red-400 px-2 py-1 border border-line rounded",children:"delete"})]}),e.jsx(T,{label:"description",value:t.description??"",onChange:n=>o({...t,description:n||void 0}),placeholder:"what this server does…"}),g?e.jsxs("div",{className:"text-xs px-2 py-1 border border-red-500/50 rounded text-red-300 bg-red-500/5",children:["⚠ ",e.jsx("span",{className:"font-mono",children:l})," is a reserved name — Claude Code will refuse to load this server (v2.1.128+)."]}):x?e.jsxs("div",{className:"text-xs px-2 py-1 border border-yellow-600/50 rounded text-yellow-200 bg-yellow-500/5",children:["⚠ ",e.jsx("span",{className:"font-mono",children:l})," collides with a commonly-bundled MCP name; expect surprises in other tools."]}):null,e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("label",{className:"text-xs text-fg-faint w-20",children:"type"}),e.jsx("select",{value:r,onChange:n=>o({...t,type:n.target.value}),className:"bg-bg-elev border border-line rounded px-2 py-1 text-xs text-fg",children:Ne.map(n=>e.jsx("option",{value:n,children:n},n))}),r==="sse"?e.jsx("span",{className:"text-xs text-yellow-400/80",children:"sse is deprecated — prefer streamable-http"}):null]}),r==="stdio"?e.jsxs(e.Fragment,{children:[e.jsx(T,{label:"command",value:t.command??"",onChange:n=>o({...t,command:n}),placeholder:"npx / node / python …"}),e.jsx(T,{label:"args",value:(t.args??[]).join(" "),onChange:n=>o({...t,args:n.split(/\s+/).filter(Boolean)}),placeholder:"space-separated args"}),e.jsx(ee,{label:"env",value:t.env??{},onChange:n=>o({...t,env:n})})]}):e.jsxs(e.Fragment,{children:[e.jsx(T,{label:"url",value:t.url??"",onChange:n=>o({...t,url:n}),placeholder:"https://…"}),e.jsx(ee,{label:"headers",value:t.headers??{},onChange:n=>o({...t,headers:n})})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("label",{className:"text-xs text-fg-faint w-20",children:"alwaysLoad"}),e.jsxs("label",{className:"flex items-center gap-2 text-xs text-fg",children:[e.jsx("input",{type:"checkbox",checked:t.alwaysLoad===!0,onChange:n=>o({...t,alwaysLoad:n.target.checked||void 0})}),e.jsx("span",{className:"text-fg-dim",children:"bypass tool-search deferral (v2.1.121+)"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("label",{className:"text-xs text-fg-faint w-20",children:"enabled"}),e.jsxs("label",{className:"flex items-center gap-2 text-xs text-fg",children:[e.jsx("input",{type:"checkbox",checked:t.enabled!==!1,onChange:n=>o({...t,enabled:n.target.checked?void 0:!1})}),e.jsx("span",{className:"text-fg-dim",children:"load this server in new sessions"})]})]}),e.jsx(T,{label:"disabledTools",value:p,onChange:n=>{const v=n.split(",").map(m=>m.trim()).filter(Boolean);o({...t,disabledTools:v.length?v:void 0})},placeholder:"comma-separated tool names to hide"}),e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("label",{className:"text-xs text-fg-faint w-20 pt-1",children:"permissions"}),e.jsxs("div",{className:"flex-1 space-y-1",children:[e.jsxs("select",{value:C,onChange:n=>{const v=n.target.value,m={...t};if(v==="inherit"){if(m.permissions){const{tools:K,...R}=m.permissions;m.permissions=Object.keys(R).length?R:void 0}}else v==="list"?m.permissions={...m.permissions??{},tools:[]}:m.permissions={...m.permissions??{},tools:v};o(m)},className:"bg-bg-elev border border-line rounded px-2 py-1 text-xs text-fg",children:[e.jsx("option",{value:"inherit",children:"inherit (default)"}),e.jsx("option",{value:"allow",children:"allow all tools"}),e.jsx("option",{value:"deny",children:"deny all tools"}),e.jsx("option",{value:"list",children:"allowlist…"})]}),C==="list"?e.jsx("input",{value:_.join(", "),onChange:n=>{const v=n.target.value.split(",").map(m=>m.trim()).filter(Boolean);o({...t,permissions:{...t.permissions??{},tools:v}})},placeholder:"comma-separated tool names",className:"w-full bg-bg-elev border border-line rounded px-2 py-1 text-xs text-fg font-mono"}):null]})]})]})}function T({label:l,value:t,onChange:a,placeholder:d}){return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("label",{className:"text-xs text-fg-faint w-20",children:l}),e.jsx("input",{value:t,onChange:f=>a(f.target.value),placeholder:d,className:"flex-1 bg-bg-elev border border-line rounded px-2 py-1 text-xs text-fg font-mono"})]})}function ee({label:l,value:t,onChange:a}){const[d,f]=c.useState(""),[b,o]=c.useState(""),j=Object.entries(t);return e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("label",{className:"text-xs text-fg-faint w-20 pt-1",children:l}),e.jsxs("div",{className:"flex-1 space-y-1",children:[j.map(([r,g])=>e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{value:r,onChange:x=>{const u={...t};delete u[r],u[x.target.value]=g,a(u)},className:"w-32 bg-bg-elev border border-line rounded px-2 py-0.5 text-xs text-fg font-mono"}),e.jsx("input",{value:g,onChange:x=>a({...t,[r]:x.target.value}),className:"flex-1 bg-bg-elev border border-line rounded px-2 py-0.5 text-xs text-fg font-mono"}),e.jsx("button",{onClick:()=>{const x={...t};delete x[r],a(x)},className:"text-fg-faint hover:text-red-400 text-xs px-1",children:"×"})]},r)),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{value:d,onChange:r=>f(r.target.value),placeholder:"key",className:"w-32 bg-bg border border-line rounded px-2 py-0.5 text-xs text-fg-dim font-mono"}),e.jsx("input",{value:b,onChange:r=>o(r.target.value),placeholder:"value",className:"flex-1 bg-bg border border-line rounded px-2 py-0.5 text-xs text-fg-dim font-mono"}),e.jsx("button",{onClick:()=>{d.trim()&&(a({...t,[d.trim()]:b}),f(""),o(""))},className:"px-2 text-xs border border-line rounded text-fg-dim hover:text-fg hover:bg-bg-hi",children:"+"})]})]})]})}export{Je as McpServers,Te as nextServerName};
@@ -1,25 +1,25 @@
1
- import{aF as i,aX as E,ap as e,$ as K,ae as vt,aK as kt,_ as Nt,ad as wt,L as jt,b4 as Ct,aY as St,n as $t}from"./index-S-F5jp_h.js";import"./monaco-editor-BsIlgG7c.js";function Mt(s){return!s||!s.trim()?"default":s.replace(/[^a-zA-Z0-9]/g,"-")}const De=["bg-accent","bg-sage-dark","bg-honey","bg-fg-dim","bg-fg-faint","bg-hive-teal","bg-butter","bg-delta-bad"],ze=864e5,Et="MEMORY.md",Ie=2e3,we=s=>s.replace(/\.md$/,"");function At(s,t,n,l){var v,k,f;const x=new Map(((t==null?void 0:t.entries)??[]).map(o=>[o.name,o])),a=new Set(((v=t==null?void 0:t.index)==null?void 0:v.orphans)??[]),p=new Map;for(const o of(n==null?void 0:n.clusters)??[])for(const b of o.memberSlugs)p.has(b)||p.set(b,o.id);const m=s.filter(o=>o.name!==Et),c=new Map;for(const o of m){const b=we(o.name),u=((k=x.get(o.name))==null?void 0:k.outLinks)??((f=x.get(b))==null?void 0:f.outLinks)??[];for(const j of u){const M=we(j),y=c.get(M)??[];y.includes(b)||y.push(b),c.set(M,y)}}return m.map(o=>{const b=we(o.name),u=x.get(o.name)??x.get(b),j=(u==null?void 0:u.deadRefs)??[],M=(u==null?void 0:u.danglingLinks)??[],y=(u==null?void 0:u.stale)??!1;return{name:o.name,slug:b,path:o.path,description:(u==null?void 0:u.description)??"",bytes:o.bytes,mtimeMs:o.mtimeMs,ageDays:Math.floor((l-o.mtimeMs)/ze),stale:y,staleReasons:(u==null?void 0:u.reasons)??[],ageOnlyStale:y&&j.length===0,deadRefs:j,broken:j.length>0||M.length>0,danglingLinks:M,outLinks:(u==null?void 0:u.outLinks)??[],inLinks:c.get(b)??[],notIndexed:a.has(o.name)||a.has(b),clusterId:p.get(b)??null,type:(u==null?void 0:u.type)??null,originSessionId:(u==null?void 0:u.originSessionId)??null}})}function Lt(s,t){const n=new Set(t.filter(l=>l.stale).map(l=>l.slug));return((s==null?void 0:s.clusters)??[]).map((l,x)=>({id:l.id,name:l.name,summary:l.summary,memberSlugs:l.memberSlugs,linkCount:l.links.length,retireCount:l.links.filter(a=>/retire/i.test(a.label??"")).length,staleCount:l.memberSlugs.filter(a=>n.has(a)).length,dotClass:De[x%De.length]}))}function Ge(s,t,n){const l=t.trim().toLowerCase(),x=l?s.filter(a=>a.slug.toLowerCase().includes(l)||a.description.toLowerCase().includes(l)):s;return n===void 0?x:x.slice(0,n)}function de(s,t,n){let l;return t==="ask"||t==="clusters"||t==="archived"?[]:(t==="all"?l=s:t==="stale"?l=s.filter(x=>x.stale):t==="broken"?l=s.filter(x=>x.broken):t==="recent"?l=s.filter(x=>Date.now()-x.mtimeMs<=7*ze):t==="unindexed"?l=s.filter(x=>x.notIndexed):t==="cluster:unclustered"?l=s.filter(x=>x.clusterId===null):t.startsWith("cluster:")?l=s.filter(x=>x.clusterId===t.slice(8)):l=s,Ge(l,n))}function qe(s,t){const n=[...s];return t==="recent"?n.sort((l,x)=>x.mtimeMs-l.mtimeMs):t==="name"?n.sort((l,x)=>l.slug<x.slug?-1:l.slug>x.slug?1:0):n.sort((l,x)=>x.bytes-l.bytes),n}function Rt(s){return{all:s.length,stale:de(s,"stale","").length,broken:de(s,"broken","").length,recent:de(s,"recent","").length,unindexed:de(s,"unindexed","").length}}function Xe(s){return s.toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,"")||"untitled_memory"}function Dt(s,t){const n=s===""?[]:s.split(`
1
+ import{aB as i,aT as E,al as e,Z as K,aa as vt,aG as kt,Y as Nt,a9 as wt,L as jt,b0 as Ct,aU as St,m as $t}from"./index-Dx8owDeQ.js";import"./monaco-editor-BsIlgG7c.js";function Mt(s){return!s||!s.trim()?"default":s.replace(/[^a-zA-Z0-9]/g,"-")}const De=["bg-accent","bg-sage-dark","bg-honey","bg-fg-dim","bg-fg-faint","bg-hive-teal","bg-butter","bg-delta-bad"],Ye=864e5,Et="MEMORY.md",Te=2e3,we=s=>s.replace(/\.md$/,"");function At(s,t,n,l){var v,k,f;const x=new Map(((t==null?void 0:t.entries)??[]).map(o=>[o.name,o])),a=new Set(((v=t==null?void 0:t.index)==null?void 0:v.orphans)??[]),p=new Map;for(const o of(n==null?void 0:n.clusters)??[])for(const b of o.memberSlugs)p.has(b)||p.set(b,o.id);const m=s.filter(o=>o.name!==Et),c=new Map;for(const o of m){const b=we(o.name),u=((k=x.get(o.name))==null?void 0:k.outLinks)??((f=x.get(b))==null?void 0:f.outLinks)??[];for(const j of u){const M=we(j),y=c.get(M)??[];y.includes(b)||y.push(b),c.set(M,y)}}return m.map(o=>{const b=we(o.name),u=x.get(o.name)??x.get(b),j=(u==null?void 0:u.deadRefs)??[],M=(u==null?void 0:u.danglingLinks)??[],y=(u==null?void 0:u.stale)??!1;return{name:o.name,slug:b,path:o.path,description:(u==null?void 0:u.description)??"",bytes:o.bytes,mtimeMs:o.mtimeMs,ageDays:Math.floor((l-o.mtimeMs)/Ye),stale:y,staleReasons:(u==null?void 0:u.reasons)??[],ageOnlyStale:y&&j.length===0,deadRefs:j,broken:j.length>0||M.length>0,danglingLinks:M,outLinks:(u==null?void 0:u.outLinks)??[],inLinks:c.get(b)??[],notIndexed:a.has(o.name)||a.has(b),clusterId:p.get(b)??null,type:(u==null?void 0:u.type)??null,originSessionId:(u==null?void 0:u.originSessionId)??null}})}function Lt(s,t){const n=new Set(t.filter(l=>l.stale).map(l=>l.slug));return((s==null?void 0:s.clusters)??[]).map((l,x)=>({id:l.id,name:l.name,summary:l.summary,memberSlugs:l.memberSlugs,linkCount:l.links.length,retireCount:l.links.filter(a=>/retire/i.test(a.label??"")).length,staleCount:l.memberSlugs.filter(a=>n.has(a)).length,dotClass:De[x%De.length]}))}function ze(s,t,n){const l=t.trim().toLowerCase(),x=l?s.filter(a=>a.slug.toLowerCase().includes(l)||a.description.toLowerCase().includes(l)):s;return n===void 0?x:x.slice(0,n)}function de(s,t,n){let l;return t==="ask"||t==="clusters"||t==="archived"?[]:(t==="all"?l=s:t==="stale"?l=s.filter(x=>x.stale):t==="broken"?l=s.filter(x=>x.broken):t==="recent"?l=s.filter(x=>Date.now()-x.mtimeMs<=7*Ye):t==="unindexed"?l=s.filter(x=>x.notIndexed):t==="cluster:unclustered"?l=s.filter(x=>x.clusterId===null):t.startsWith("cluster:")?l=s.filter(x=>x.clusterId===t.slice(8)):l=s,ze(l,n))}function qe(s,t){const n=[...s];return t==="recent"?n.sort((l,x)=>x.mtimeMs-l.mtimeMs):t==="name"?n.sort((l,x)=>l.slug<x.slug?-1:l.slug>x.slug?1:0):n.sort((l,x)=>x.bytes-l.bytes),n}function Rt(s){return{all:s.length,stale:de(s,"stale","").length,broken:de(s,"broken","").length,recent:de(s,"recent","").length,unindexed:de(s,"unindexed","").length}}function Xe(s){return s.toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,"")||"untitled_memory"}function Dt(s,t){const n=s===""?[]:s.split(`
2
2
  `),l=t===""?[]:t.split(`
3
- `);if(n.length>Ie||l.length>Ie)return[...n.map(k=>({sign:"−",text:k})),...l.map(k=>({sign:"+",text:k}))];const x=n.length,a=l.length,p=Array.from({length:x+1},()=>new Array(a+1).fill(0));for(let k=x-1;k>=0;k--)for(let f=a-1;f>=0;f--)p[k][f]=n[k]===l[f]?p[k+1][f+1]+1:Math.max(p[k+1][f],p[k][f+1]);const m=[];let c=0,v=0;for(;c<x&&v<a;)n[c]===l[v]?(c++,v++):p[c+1][v]>=p[c][v+1]?m.push({sign:"−",text:n[c++]}):m.push({sign:"+",text:l[v++]});for(;c<x;)m.push({sign:"−",text:n[c++]});for(;v<a;)m.push({sign:"+",text:l[v++]});return m}const F=s=>s instanceof Error?s.message:String(s);function Te(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 It(s){return s.split(`
4
- `).map(t=>t.trim()).find(t=>t.length>0)??""}function Tt(s,t){const n=s.kind==="agent"?s.agent:null,l=n?`${n.name}|${n.memoryScope??""}`:"",x=n!==null&&n.memoryScope===null,a=i.useMemo(()=>x?null:n&&n.memoryScope?{agent:{name:n.name,scope:n.memoryScope},...t?{cwd:t}:{}}:{workspace:Mt(t),...t?{cwd:t}:{}},[l,x,t]),p=n===null,[m,c]=i.useState(!0),[v,k]=i.useState([]),[f,o]=i.useState(null),[b,u]=i.useState(null),[j,M]=i.useState(!1),[y,C]=i.useState(""),[I,W]=i.useState(!0),[ee,xe]=i.useState([]),[q,A]=i.useState([]),[U,L]=i.useState({}),[me,ye]=i.useState(()=>Date.now()),X=i.useRef(a);X.current=a;const T=i.useCallback(async()=>{if(!a){k([]),o(null),u(null),xe([]),C(""),c(!1);return}try{const h=await window.api.memory.list(a);if(X.current!==a)return;k(h.entries??[]),C(h.dir??""),W(h.autoMemoryEnabled!==!1),h.error&&E.error(`Memory list failed: ${h.error}`);const[d,N]=await Promise.all([window.api.memory.stale(a).catch(w=>(E.error(`Memory staleness check failed: ${F(w)}`),null)),window.api.memory.listArchived(a).catch(()=>({names:[],error:null}))]);if(X.current!==a)return;o(d),xe(N.names??[]),ye(Date.now())}catch(h){E.error(`Memory list failed: ${F(h)}`)}finally{c(!1)}},[a]);i.useEffect(()=>{c(!0),u(null),T(),a&&p&&a.workspace&&window.api.memory.aggregate(a.workspace,!1,t??void 0).then(h=>{X.current===a&&u(h)}).catch(h=>E.error(`Memory clusters failed: ${F(h)}`))},[T]),i.useEffect(()=>{let h=!1;return(async()=>{try{const{agents:d}=await window.api.memory.agents(t??void 0);if(h)return;A(d);const N={};await Promise.all(d.filter(w=>w.memoryScope).map(async w=>{const z=await window.api.memory.list({agent:{name:w.name,scope:w.memoryScope},...t?{cwd:t}:{}});N[w.name]=(z.entries??[]).filter(O=>O.name!=="MEMORY.md").length})),h||L(N)}catch(d){h||E.error(`Memory agents failed: ${F(d)}`)}})(),()=>{h=!0}},[t]),i.useEffect(()=>{if(!y)return;const h=y;window.api.config.watch([h]);const d=window.api.config.onChanged(({path:N})=>{(N===h||N.startsWith(h+"/"))&&T()});return()=>{d(),window.api.config.unwatch([h])}},[y,T]);const _=i.useMemo(()=>At(v,f,b,me),[v,f,b,me]),te=i.useMemo(()=>Lt(b,_),[b,_]),ve=i.useMemo(()=>({generatedAt:(b==null?void 0:b.generatedAt)??null,running:j}),[b,j]),R=i.useCallback(async h=>{if(!a)return null;try{const d=await window.api.memory.read(h,a);return d.error?(E.error(`Memory read failed: ${d.error}`),null):d.content}catch(d){return E.error(`Memory read failed: ${F(d)}`),null}},[a]),$=i.useCallback(async(h,d)=>{try{const N=await d();return N.ok?(await T(),!0):(E.error(`${h} failed: ${N.error??"unknown error"}`),!1)}catch(N){return E.error(`${h} failed: ${F(N)}`),!1}},[T]),Q=i.useCallback(async(h,d)=>{if(!a)return!1;const N=await R(h);if(N===null)return!1;const{front:w}=Te(N);return $("Memory save",()=>window.api.memory.write(h,w+d,a))},[a,R,$]),V=i.useCallback(async(h,d)=>{if(!a)return null;const N=Xe(h),w=It(d);if(!await $("Memory create",()=>window.api.memory.create(N,w,a)))return null;const O=`---
3
+ `);if(n.length>Te||l.length>Te)return[...n.map(k=>({sign:"−",text:k})),...l.map(k=>({sign:"+",text:k}))];const x=n.length,a=l.length,p=Array.from({length:x+1},()=>new Array(a+1).fill(0));for(let k=x-1;k>=0;k--)for(let f=a-1;f>=0;f--)p[k][f]=n[k]===l[f]?p[k+1][f+1]+1:Math.max(p[k+1][f],p[k][f+1]);const m=[];let c=0,v=0;for(;c<x&&v<a;)n[c]===l[v]?(c++,v++):p[c+1][v]>=p[c][v+1]?m.push({sign:"−",text:n[c++]}):m.push({sign:"+",text:l[v++]});for(;c<x;)m.push({sign:"−",text:n[c++]});for(;v<a;)m.push({sign:"+",text:l[v++]});return m}const B=s=>s instanceof Error?s.message:String(s);function Ie(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 Tt(s){return s.split(`
4
+ `).map(t=>t.trim()).find(t=>t.length>0)??""}function It(s,t){const n=s.kind==="agent"?s.agent:null,l=n?`${n.name}|${n.memoryScope??""}`:"",x=n!==null&&n.memoryScope===null,a=i.useMemo(()=>x?null:n&&n.memoryScope?{agent:{name:n.name,scope:n.memoryScope},...t?{cwd:t}:{}}:{workspace:Mt(t),...t?{cwd:t}:{}},[l,x,t]),p=n===null,[m,c]=i.useState(!0),[v,k]=i.useState([]),[f,o]=i.useState(null),[b,u]=i.useState(null),[j,M]=i.useState(!1),[y,C]=i.useState(""),[T,W]=i.useState(!0),[ee,xe]=i.useState([]),[q,A]=i.useState([]),[U,L]=i.useState({}),[me,ye]=i.useState(()=>Date.now()),X=i.useRef(a);X.current=a;const I=i.useCallback(async()=>{if(!a){k([]),o(null),u(null),xe([]),C(""),c(!1);return}try{const h=await window.api.memory.list(a);if(X.current!==a)return;k(h.entries??[]),C(h.dir??""),W(h.autoMemoryEnabled!==!1),h.error&&E.error(`Memory list failed: ${h.error}`);const[d,N]=await Promise.all([window.api.memory.stale(a).catch(w=>(E.error(`Memory staleness check failed: ${B(w)}`),null)),window.api.memory.listArchived(a).catch(()=>({names:[],error:null}))]);if(X.current!==a)return;o(d),xe(N.names??[]),ye(Date.now())}catch(h){E.error(`Memory list failed: ${B(h)}`)}finally{c(!1)}},[a]);i.useEffect(()=>{c(!0),u(null),I(),a&&p&&a.workspace&&window.api.memory.aggregate(a.workspace,!1,t??void 0).then(h=>{X.current===a&&u(h)}).catch(h=>E.error(`Memory clusters failed: ${B(h)}`))},[I]),i.useEffect(()=>{let h=!1;return(async()=>{try{const{agents:d}=await window.api.memory.agents(t??void 0);if(h)return;A(d);const N={};await Promise.all(d.filter(w=>w.memoryScope).map(async w=>{const Y=await window.api.memory.list({agent:{name:w.name,scope:w.memoryScope},...t?{cwd:t}:{}});N[w.name]=(Y.entries??[]).filter(O=>O.name!=="MEMORY.md").length})),h||L(N)}catch(d){h||E.error(`Memory agents failed: ${B(d)}`)}})(),()=>{h=!0}},[t]),i.useEffect(()=>{if(!y)return;const h=y;window.api.config.watch([h]);const d=window.api.config.onChanged(({path:N})=>{(N===h||N.startsWith(h+"/"))&&I()});return()=>{d(),window.api.config.unwatch([h])}},[y,I]);const _=i.useMemo(()=>At(v,f,b,me),[v,f,b,me]),te=i.useMemo(()=>Lt(b,_),[b,_]),ve=i.useMemo(()=>({generatedAt:(b==null?void 0:b.generatedAt)??null,running:j}),[b,j]),R=i.useCallback(async h=>{if(!a)return null;try{const d=await window.api.memory.read(h,a);return d.error?(E.error(`Memory read failed: ${d.error}`),null):d.content}catch(d){return E.error(`Memory read failed: ${B(d)}`),null}},[a]),$=i.useCallback(async(h,d)=>{try{const N=await d();return N.ok?(await I(),!0):(E.error(`${h} failed: ${N.error??"unknown error"}`),!1)}catch(N){return E.error(`${h} failed: ${B(N)}`),!1}},[I]),Q=i.useCallback(async(h,d)=>{if(!a)return!1;const N=await R(h);if(N===null)return!1;const{front:w}=Ie(N);return $("Memory save",()=>window.api.memory.write(h,w+d,a))},[a,R,$]),V=i.useCallback(async(h,d)=>{if(!a)return null;const N=Xe(h),w=Tt(d);if(!await $("Memory create",()=>window.api.memory.create(N,w,a)))return null;const O=`---
5
5
  name: ${N}
6
6
  description: ${w}
7
7
  ---
8
8
 
9
9
  ${d}
10
- `;return await $("Memory create",()=>window.api.memory.write(N,O,a))?N:null},[a,$]),H=i.useCallback(async h=>{var z,O;if(!a)return null;const d=await R(h);if(d===null||!await $("Memory delete",()=>window.api.memory.delete(h,a)))return null;const w=((O=(z=Te(d).front.match(/^description:\s*(.*)$/m))==null?void 0:z[1])==null?void 0:O.trim())??"";return async()=>{await $("Memory undo",()=>window.api.memory.create(h,w,a))&&await $("Memory undo",()=>window.api.memory.write(h,d,a))}},[a,R,$]),ue=i.useCallback(h=>a?$("Memory archive",()=>window.api.memory.archive(h,a)):Promise.resolve(!1),[a,$]),se=i.useCallback(h=>a?$("Memory restore",()=>window.api.memory.restore(h,a)):Promise.resolve(!1),[a,$]),ne=i.useCallback(h=>a?$("Memory verify",()=>window.api.memory.verify(h,a)):Promise.resolve(!1),[a,$]),re=i.useCallback(async(h,d)=>{if(!a)return!1;const N=await R(h);if(N===null)return!1;const w=N.split(`[[${d}]]`).join(d);return $("Memory link removal",()=>window.api.memory.write(h,w,a))},[a,R,$]),Z=i.useCallback(async()=>{if(!(!a||!p||!a.workspace)){M(!0);try{const h=await window.api.memory.aggregate(a.workspace,!0,t??void 0);h.error?E.error(`Memory clustering failed: ${h.error}`):u(h)}catch(h){E.error(`Memory clustering failed: ${F(h)}`)}finally{M(!1)}}},[a,p,t]),pe=i.useCallback(async(h,d)=>{const N=w=>({ok:!1,answer:"",citations:[],error:w});if(!a)return N("no memory store");try{const w=await window.api.memory.ask({question:h,target:a,contextName:d});return w.ok||E.error(`Memory ask failed: ${w.error??"unknown error"}`),w}catch(w){return E.error(`Memory ask failed: ${F(w)}`),N(F(w))}},[a]),Y=i.useCallback(async h=>{const d=N=>({ok:!1,action:"keep",summary:"",reason:"",content:"",fold:null,error:N});if(!a)return d("no memory store");try{const N=await window.api.memory.proposeFix({name:h,target:a});return N.ok||E.error(`Memory fix failed: ${N.error??"unknown error"}`),N}catch(N){return E.error(`Memory fix failed: ${F(N)}`),d(F(N))}},[a]),ae=i.useMemo(()=>({refresh:T,read:R,saveBody:Q,create:V,remove:H,archive:ue,restore:se,verify:ne,removeLink:re,regenerateClusters:Z,ask:pe,proposeFix:Y}),[T,R,Q,V,H,ue,se,ne,re,Z,pe,Y]);return{loading:m,target:a,dir:y,autoMemoryEnabled:I,rows:_,clusters:te,clustersMeta:ve,index:f==null?void 0:f.index,archived:ee,agents:q,agentCounts:U,actions:ae}}const _t={user:"user — all projects",project:"project — shared via git",local:"local — this machine only"},J="text-[10px] tracking-[.08em] font-semibold text-fg-faint",Qe="flex items-center gap-2 h-7 px-2.5 rounded-[5px] text-[13px] cursor-pointer hover:bg-muteband text-left w-full";function _e(s,t){return s.memoryScope===null?"off":String(t[s.name]??0)}function je({id:s,label:t,count:n,dot:l,active:x,mono:a,onClick:p,check:m}){return e.jsxs("button",{type:"button","data-testid":`mx-nav-${s}`,onClick:p,className:`${Qe} ${x?"bg-bg font-semibold text-fg":"text-fg-dim"}`,children:[e.jsx("span",{className:`w-[7px] h-[7px] rounded-sm shrink-0 ${l||"bg-transparent"}`}),e.jsx("span",{className:`flex-1 min-w-0 truncate ${a?"font-mono text-xs":""}`,children:t}),n!==void 0&&e.jsx("span",{className:`font-mono text-[11px] ${m&&n===0?"text-sage-dark":x?"text-fg":"text-fg-faint"}`,children:m&&n===0?"✓":n})]})}function Oe({label:s,value:t,max:n,tone:l}){const x=Math.min(100,Math.round(t/Math.max(1,n)*100));return e.jsxs("div",{className:"flex flex-col gap-0.5",children:[e.jsxs("span",{className:"font-mono text-[10px] text-fg-faint",children:[s," ",t,"/",n]}),e.jsx("div",{className:"h-1 rounded-full bg-bg-muteband overflow-hidden",children:e.jsx("div",{className:`h-full ${l}`,style:{width:`${x}%`}})})]})}const Ot=i.memo(function(t){var k,f;const[n,l]=i.useState(!1),x=i.useRef(null),a=t.scope.kind==="agent";i.useEffect(()=>{if(!n)return;const o=u=>{u.key==="Escape"&&l(!1)},b=u=>{x.current&&!x.current.contains(u.target)&&l(!1)};return document.addEventListener("keydown",o),document.addEventListener("mousedown",b),()=>{document.removeEventListener("keydown",o),document.removeEventListener("mousedown",b)}},[n]);const p=o=>{l(!1),t.onScope(o)},m=(o,b,u,j,M)=>e.jsx(je,{id:o,label:b,dot:u,count:j,check:M,active:t.view===o,onClick:()=>t.onView(o)}),c=t.scope.kind==="agent"?t.scope.agent:null,v=(k=t.index)!=null&&k.overBudget?"bg-accent":(f=t.index)!=null&&f.nearBudget?"bg-honey":"bg-sage-dark";return e.jsxs("nav",{"data-testid":"mx-nav",className:"w-[232px] shrink-0 flex flex-col gap-4 bg-bg-elev border-r border-rule-structural px-2.5 py-3.5 overflow-y-auto",children:[e.jsxs("div",{ref:x,className:"relative",children:[e.jsxs("button",{type:"button","data-testid":"mx-scope-card",onClick:()=>l(o=>!o),className:"w-full flex flex-col gap-0.5 px-2.5 py-2 border border-rule-structural rounded-md bg-bg cursor-pointer text-left hover:border-fg-faint",children:[e.jsx("span",{className:J,children:c?"SUBAGENT":"WORKSPACE"}),e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"font-mono text-xs text-fg flex-1 min-w-0 truncate",children:c?c.name:t.workspaceName}),e.jsx("span",{className:"text-[10px] text-fg-faint",children:"▾"})]}),e.jsx("span",{className:"font-mono text-[10px] text-fg-faint truncate",children:c?c.agentFile:t.workspacePath}),c&&c.memoryScope&&e.jsx("span",{className:"text-[10.5px] text-fg-faint",children:_t[c.memoryScope]})]}),n&&e.jsxs("div",{"data-testid":"mx-scope-menu",className:`absolute left-0 right-0 top-full mt-1 ${K.dialog} bg-bg-hi border border-rule-structural rounded-[7px] shadow-lg p-1 flex flex-col`,children:[e.jsxs("button",{type:"button",onClick:()=>p({kind:"workspace"}),className:"flex items-center gap-2 px-2 py-1.5 rounded-[5px] text-left hover:bg-bg-elev",children:[e.jsx("span",{className:"w-3 text-[11px] text-sage-dark",children:c?"":"✓"}),e.jsxs("span",{className:"flex flex-col flex-1 min-w-0",children:[e.jsx("span",{className:"font-mono text-xs text-fg truncate",children:t.workspaceName}),e.jsx("span",{className:"text-[10.5px] text-fg-faint",children:"workspace"})]}),e.jsx("span",{className:"font-mono text-[11px] text-fg-faint",children:t.workspaceCount})]}),t.agents.map(o=>e.jsxs("button",{type:"button",onClick:()=>p({kind:"agent",agent:o}),className:"flex items-center gap-2 px-2 py-1.5 rounded-[5px] text-left hover:bg-bg-elev",children:[e.jsx("span",{className:"w-3 text-[11px] text-sage-dark",children:(c==null?void 0:c.name)===o.name?"✓":""}),e.jsxs("span",{className:"flex flex-col flex-1 min-w-0",children:[e.jsx("span",{className:"font-mono text-xs text-fg truncate",children:o.name}),e.jsxs("span",{className:"text-[10.5px] text-fg-faint",children:["subagent",o.memoryScope?` · ${o.memoryScope}`:""]})]}),e.jsx("span",{className:"font-mono text-[11px] text-fg-faint",children:_e(o,t.agentCounts)})]},o.name))]})]}),e.jsxs("div",{className:"flex flex-col gap-px",children:[e.jsx("div",{className:`px-2.5 pb-1.5 ${J}`,children:"BROWSE"}),m("all","All memories","",t.counts.all),m("ask","Ask",""),m("clusters","Clusters","",t.clusters.length)]}),e.jsxs("div",{className:"flex flex-col gap-px",children:[e.jsx("div",{className:`px-2.5 pb-1.5 ${J}`,children:"REVIEW"}),m("stale","Stale","bg-honey",t.counts.stale,!0),m("broken","Broken references","bg-accent",t.counts.broken,!0),m("recent","Changed this week","",t.counts.recent),m("unindexed","Not in index","",t.counts.unindexed,!0),t.archivedCount>0&&m("archived","Archived","",t.archivedCount)]}),!a&&e.jsxs("div",{className:"flex flex-col gap-px",children:[e.jsx("div",{className:`px-2.5 pb-1.5 ${J}`,children:"CLUSTERS"}),t.clusters.map(o=>e.jsx(je,{id:`cluster:${o.id}`,label:o.name,dot:o.dotClass,count:t.clusterCounts[o.id]??0,active:t.view===`cluster:${o.id}`,onClick:()=>t.onView(`cluster:${o.id}`)},o.id)),t.unclusteredCount>0&&e.jsx(je,{id:"cluster:unclustered",label:"Unclustered",dot:"bg-rule",count:t.unclusteredCount,active:t.view==="cluster:unclustered",onClick:()=>t.onView("cluster:unclustered")})]}),t.agents.length>0&&e.jsxs("div",{className:"flex flex-col gap-px",children:[e.jsx("div",{className:`px-2.5 pb-1.5 ${J}`,children:"SUBAGENT SCOPES"}),t.agents.map(o=>e.jsxs("button",{type:"button","data-testid":`mx-nav-agent:${o.name}`,onClick:()=>t.onScope({kind:"agent",agent:o}),className:`${Qe} text-fg-dim ${(c==null?void 0:c.name)===o.name?"bg-bg font-semibold":""}`,children:[e.jsx("span",{className:"font-mono text-xs flex-1 truncate",children:o.name}),e.jsx("span",{className:"font-mono text-[11px] text-fg-faint",children:_e(o,t.agentCounts)})]},o.name))]}),t.index&&e.jsxs("div",{"data-testid":"mx-index-footer",className:"mt-auto flex flex-col gap-1.5 pt-3 border-t border-rule-inner",children:[e.jsx("span",{className:J,children:"MEMORY.md"}),e.jsx(Oe,{label:"lines",value:t.index.lines,max:t.index.maxLines,tone:v}),e.jsx(Oe,{label:"KB",value:Math.round(t.index.bytes/1024),max:Math.round(t.index.maxBytes/1024),tone:v}),t.index.dangling.length>0&&e.jsxs("span",{className:"text-[10.5px] text-accent-dark",children:[t.index.dangling.length," index lines point at missing files"]})]})]})}),Ft={recent:"name",name:"size",size:"recent"},Bt={recent:"Recent",name:"Name",size:"Size"},Ce="text-[9.5px] font-semibold tracking-[.06em] px-[5px] py-px rounded-[3px]";function Pt(s){return`${vt(s.bytes)} · ${s.ageDays>0?`${s.ageDays}d ago`:"just now"}`}const Kt=i.memo(function(t){return e.jsxs("div",{"data-testid":"mx-list",className:"flex flex-col min-h-0 border-r border-rule-structural",children:[e.jsxs("div",{className:"flex flex-col gap-[10px] px-[14px] pt-[14px] pb-[10px] border-b border-rule-structural",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-serif text-lg 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(Ft[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:`${Bt[t.sort]} ⇅`})]})]}),e.jsxs("div",{className:"overflow-auto flex-1 p-[6px]",children:[t.rows.map(n=>e.jsxs("div",{"data-testid":`mx-list-row-${n.name}`,onClick:()=>t.onSelect(n.name),className:`px-[10px] py-2 rounded-md cursor-pointer flex flex-col gap-[3px] hover:bg-bg-elev ${t.selected===n.name?"bg-muteband":""}`,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] font-medium flex-1 min-w-0 overflow-hidden text-ellipsis whitespace-nowrap",children:n.slug}),n.stale&&e.jsx("span",{className:`${Ce} bg-butter/40 text-honey-dark`,children:"STALE"}),n.broken&&!n.stale&&e.jsx("span",{className:`${Ce} bg-accent-muted/30 text-accent-dark`,children:"BROKEN"}),n.notIndexed&&e.jsx("span",{className:`${Ce} bg-rule-inner text-fg-dim`,children:"NOT INDEXED"})]}),e.jsx("div",{className:"text-[11.5px] text-fg-dim pl-[14px] overflow-hidden text-ellipsis whitespace-nowrap",children:n.description}),e.jsx("div",{className:"font-mono text-[10.5px] text-fg-dim pl-[14px]",children:Pt(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})]})]})]})}),Se="text-xs font-medium h-[26px] px-2.5 border border-rule-structural rounded-[5px] bg-bg text-fg hover:border-fg",ge="px-[7px] py-0.5 rounded bg-bg-elev",be="px-2.5 py-[7px] rounded-[5px] text-left text-[12.5px] hover:bg-bg-elev",Wt="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",Fe={update:{apply:"Apply",hint:"Writes the file"},delete:{apply:"Archive",hint:"Moves to .archive — undoable"},keep:{apply:"Mark verified",hint:"Touches the file, clears age staleness"},fold:{apply:"Copy for an Epic",hint:"Memory stays until the doc change lands"}};function Ut(s){var t;return s.action==="delete"?"Suggested: archive this memory":s.action==="fold"?`Suggested: move into ${((t=s.fold)==null?void 0:t.target)??"a doc"}`:s.action==="keep"?"Looks accurate — keep":"Suggested update"}function Vt(s){return s<1024?`${s} B`:`${(s/1024).toFixed(1)} KB`}function Ht(s){return s<=0?"just now":`${s}d ago`}function Yt(s){const t=/^---\r?\n[\s\S]*?\r?\n---[ \t]*(?:\r?\n|$)/.exec(s);return(t?s.slice(t[0].length):s).trim()}function zt(s){return s.replace(/^\*\*Why:\*\*[ \t]*/gim,`#### WHY
10
+ `;return await $("Memory create",()=>window.api.memory.write(N,O,a))?N:null},[a,$]),H=i.useCallback(async h=>{var Y,O;if(!a)return null;const d=await R(h);if(d===null||!await $("Memory delete",()=>window.api.memory.delete(h,a)))return null;const w=((O=(Y=Ie(d).front.match(/^description:\s*(.*)$/m))==null?void 0:Y[1])==null?void 0:O.trim())??"";return async()=>{await $("Memory undo",()=>window.api.memory.create(h,w,a))&&await $("Memory undo",()=>window.api.memory.write(h,d,a))}},[a,R,$]),ue=i.useCallback(h=>a?$("Memory archive",()=>window.api.memory.archive(h,a)):Promise.resolve(!1),[a,$]),se=i.useCallback(h=>a?$("Memory restore",()=>window.api.memory.restore(h,a)):Promise.resolve(!1),[a,$]),ne=i.useCallback(h=>a?$("Memory verify",()=>window.api.memory.verify(h,a)):Promise.resolve(!1),[a,$]),re=i.useCallback(async(h,d)=>{if(!a)return!1;const N=await R(h);if(N===null)return!1;const w=N.split(`[[${d}]]`).join(d);return $("Memory link removal",()=>window.api.memory.write(h,w,a))},[a,R,$]),Z=i.useCallback(async()=>{if(!(!a||!p||!a.workspace)){M(!0);try{const h=await window.api.memory.aggregate(a.workspace,!0,t??void 0);h.error?E.error(`Memory clustering failed: ${h.error}`):u(h)}catch(h){E.error(`Memory clustering failed: ${B(h)}`)}finally{M(!1)}}},[a,p,t]),pe=i.useCallback(async(h,d)=>{const N=w=>({ok:!1,answer:"",citations:[],error:w});if(!a)return N("no memory store");try{const w=await window.api.memory.ask({question:h,target:a,contextName:d});return w.ok||E.error(`Memory ask failed: ${w.error??"unknown error"}`),w}catch(w){return E.error(`Memory ask failed: ${B(w)}`),N(B(w))}},[a]),G=i.useCallback(async h=>{const d=N=>({ok:!1,action:"keep",summary:"",reason:"",content:"",fold:null,error:N});if(!a)return d("no memory store");try{const N=await window.api.memory.proposeFix({name:h,target:a});return N.ok||E.error(`Memory fix failed: ${N.error??"unknown error"}`),N}catch(N){return E.error(`Memory fix failed: ${B(N)}`),d(B(N))}},[a]),ae=i.useMemo(()=>({refresh:I,read:R,saveBody:Q,create:V,remove:H,archive:ue,restore:se,verify:ne,removeLink:re,regenerateClusters:Z,ask:pe,proposeFix:G}),[I,R,Q,V,H,ue,se,ne,re,Z,pe,G]);return{loading:m,target:a,dir:y,autoMemoryEnabled:T,rows:_,clusters:te,clustersMeta:ve,index:f==null?void 0:f.index,archived:ee,agents:q,agentCounts:U,actions:ae}}const _t={user:"user — all projects",project:"project — shared via git",local:"local — this machine only"},J="text-[10px] tracking-[.08em] font-semibold text-fg-faint",Qe="flex items-center gap-2 h-7 px-2.5 rounded-[5px] text-[13px] cursor-pointer hover:bg-muteband text-left w-full";function _e(s,t){return s.memoryScope===null?"off":String(t[s.name]??0)}function je({id:s,label:t,count:n,dot:l,active:x,mono:a,onClick:p,check:m}){return e.jsxs("button",{type:"button","data-testid":`mx-nav-${s}`,onClick:p,className:`${Qe} ${x?"bg-bg font-semibold text-fg":"text-fg-dim"}`,children:[e.jsx("span",{className:`w-[7px] h-[7px] rounded-sm shrink-0 ${l||"bg-transparent"}`}),e.jsx("span",{className:`flex-1 min-w-0 truncate ${a?"font-mono text-xs":""}`,children:t}),n!==void 0&&e.jsx("span",{className:`font-mono text-[11px] ${m&&n===0?"text-sage-dark":x?"text-fg":"text-fg-faint"}`,children:m&&n===0?"✓":n})]})}function Oe({label:s,value:t,max:n,tone:l}){const x=Math.min(100,Math.round(t/Math.max(1,n)*100));return e.jsxs("div",{className:"flex flex-col gap-0.5",children:[e.jsxs("span",{className:"font-mono text-[10px] text-fg-faint",children:[s," ",t,"/",n]}),e.jsx("div",{className:"h-1 rounded-full bg-bg-muteband overflow-hidden",children:e.jsx("div",{className:`h-full ${l}`,style:{width:`${x}%`}})})]})}const Ot=i.memo(function(t){var k,f;const[n,l]=i.useState(!1),x=i.useRef(null),a=t.scope.kind==="agent";i.useEffect(()=>{if(!n)return;const o=u=>{u.key==="Escape"&&l(!1)},b=u=>{x.current&&!x.current.contains(u.target)&&l(!1)};return document.addEventListener("keydown",o),document.addEventListener("mousedown",b),()=>{document.removeEventListener("keydown",o),document.removeEventListener("mousedown",b)}},[n]);const p=o=>{l(!1),t.onScope(o)},m=(o,b,u,j,M)=>e.jsx(je,{id:o,label:b,dot:u,count:j,check:M,active:t.view===o,onClick:()=>t.onView(o)}),c=t.scope.kind==="agent"?t.scope.agent:null,v=(k=t.index)!=null&&k.overBudget?"bg-accent":(f=t.index)!=null&&f.nearBudget?"bg-honey":"bg-sage-dark";return e.jsxs("nav",{"data-testid":"mx-nav",className:"w-[232px] shrink-0 flex flex-col gap-4 bg-bg-elev border-r border-rule-structural px-2.5 py-3.5 overflow-y-auto",children:[e.jsxs("div",{ref:x,className:"relative",children:[e.jsxs("button",{type:"button","data-testid":"mx-scope-card",onClick:()=>l(o=>!o),className:"w-full flex flex-col gap-0.5 px-2.5 py-2 border border-rule-structural rounded-md bg-bg cursor-pointer text-left hover:border-fg-faint",children:[e.jsx("span",{className:J,children:c?"SUBAGENT":"WORKSPACE"}),e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"font-mono text-xs text-fg flex-1 min-w-0 truncate",children:c?c.name:t.workspaceName}),e.jsx("span",{className:"text-[10px] text-fg-faint",children:"▾"})]}),e.jsx("span",{className:"font-mono text-[10px] text-fg-faint truncate",children:c?c.agentFile:t.workspacePath}),c&&c.memoryScope&&e.jsx("span",{className:"text-[10.5px] text-fg-faint",children:_t[c.memoryScope]})]}),n&&e.jsxs("div",{"data-testid":"mx-scope-menu",className:`absolute left-0 right-0 top-full mt-1 ${K.dialog} bg-bg-hi border border-rule-structural rounded-[7px] shadow-lg p-1 flex flex-col`,children:[e.jsxs("button",{type:"button",onClick:()=>p({kind:"workspace"}),className:"flex items-center gap-2 px-2 py-1.5 rounded-[5px] text-left hover:bg-bg-elev",children:[e.jsx("span",{className:"w-3 text-[11px] text-sage-dark",children:c?"":"✓"}),e.jsxs("span",{className:"flex flex-col flex-1 min-w-0",children:[e.jsx("span",{className:"font-mono text-xs text-fg truncate",children:t.workspaceName}),e.jsx("span",{className:"text-[10.5px] text-fg-faint",children:"workspace"})]}),e.jsx("span",{className:"font-mono text-[11px] text-fg-faint",children:t.workspaceCount})]}),t.agents.map(o=>e.jsxs("button",{type:"button",onClick:()=>p({kind:"agent",agent:o}),className:"flex items-center gap-2 px-2 py-1.5 rounded-[5px] text-left hover:bg-bg-elev",children:[e.jsx("span",{className:"w-3 text-[11px] text-sage-dark",children:(c==null?void 0:c.name)===o.name?"✓":""}),e.jsxs("span",{className:"flex flex-col flex-1 min-w-0",children:[e.jsx("span",{className:"font-mono text-xs text-fg truncate",children:o.name}),e.jsxs("span",{className:"text-[10.5px] text-fg-faint",children:["subagent",o.memoryScope?` · ${o.memoryScope}`:""]})]}),e.jsx("span",{className:"font-mono text-[11px] text-fg-faint",children:_e(o,t.agentCounts)})]},o.name))]})]}),e.jsxs("div",{className:"flex flex-col gap-px",children:[e.jsx("div",{className:`px-2.5 pb-1.5 ${J}`,children:"BROWSE"}),m("all","All memories","",t.counts.all),m("ask","Ask",""),m("clusters","Clusters","",t.clusters.length)]}),e.jsxs("div",{className:"flex flex-col gap-px",children:[e.jsx("div",{className:`px-2.5 pb-1.5 ${J}`,children:"REVIEW"}),m("stale","Stale","bg-honey",t.counts.stale,!0),m("broken","Broken references","bg-accent",t.counts.broken,!0),m("recent","Changed this week","",t.counts.recent),m("unindexed","Not in index","",t.counts.unindexed,!0),t.archivedCount>0&&m("archived","Archived","",t.archivedCount)]}),!a&&e.jsxs("div",{className:"flex flex-col gap-px",children:[e.jsx("div",{className:`px-2.5 pb-1.5 ${J}`,children:"CLUSTERS"}),t.clusters.map(o=>e.jsx(je,{id:`cluster:${o.id}`,label:o.name,dot:o.dotClass,count:t.clusterCounts[o.id]??0,active:t.view===`cluster:${o.id}`,onClick:()=>t.onView(`cluster:${o.id}`)},o.id)),t.unclusteredCount>0&&e.jsx(je,{id:"cluster:unclustered",label:"Unclustered",dot:"bg-rule",count:t.unclusteredCount,active:t.view==="cluster:unclustered",onClick:()=>t.onView("cluster:unclustered")})]}),t.agents.length>0&&e.jsxs("div",{className:"flex flex-col gap-px",children:[e.jsx("div",{className:`px-2.5 pb-1.5 ${J}`,children:"SUBAGENT SCOPES"}),t.agents.map(o=>e.jsxs("button",{type:"button","data-testid":`mx-nav-agent:${o.name}`,onClick:()=>t.onScope({kind:"agent",agent:o}),className:`${Qe} text-fg-dim ${(c==null?void 0:c.name)===o.name?"bg-bg font-semibold":""}`,children:[e.jsx("span",{className:"font-mono text-xs flex-1 truncate",children:o.name}),e.jsx("span",{className:"font-mono text-[11px] text-fg-faint",children:_e(o,t.agentCounts)})]},o.name))]}),t.index&&e.jsxs("div",{"data-testid":"mx-index-footer",className:"mt-auto flex flex-col gap-1.5 pt-3 border-t border-rule-inner",children:[e.jsx("span",{className:J,children:"MEMORY.md"}),e.jsx(Oe,{label:"lines",value:t.index.lines,max:t.index.maxLines,tone:v}),e.jsx(Oe,{label:"KB",value:Math.round(t.index.bytes/1024),max:Math.round(t.index.maxBytes/1024),tone:v}),t.index.dangling.length>0&&e.jsxs("span",{className:"text-[10.5px] text-accent-dark",children:[t.index.dangling.length," index lines point at missing files"]})]})]})}),Bt={recent:"name",name:"size",size:"recent"},Ft={recent:"Recent",name:"Name",size:"Size"},Ce="text-[9.5px] font-semibold tracking-[.06em] px-[5px] py-px rounded-[3px]";function Pt(s){return`${vt(s.bytes)} · ${s.ageDays>0?`${s.ageDays}d ago`:"just now"}`}const Kt=i.memo(function(t){return e.jsxs("div",{"data-testid":"mx-list",className:"flex flex-col min-h-0 border-r border-rule-structural",children:[e.jsxs("div",{className:"flex flex-col gap-[10px] px-[14px] pt-[14px] pb-[10px] border-b border-rule-structural",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-serif text-lg 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(Bt[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:`${Ft[t.sort]} ⇅`})]})]}),e.jsxs("div",{className:"overflow-auto flex-1 p-[6px]",children:[t.rows.map(n=>e.jsxs("div",{"data-testid":`mx-list-row-${n.name}`,onClick:()=>t.onSelect(n.name),className:`px-[10px] py-2 rounded-md cursor-pointer flex flex-col gap-[3px] hover:bg-bg-elev ${t.selected===n.name?"bg-muteband":""}`,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] font-medium flex-1 min-w-0 overflow-hidden text-ellipsis whitespace-nowrap",children:n.slug}),n.stale&&e.jsx("span",{className:`${Ce} bg-butter/40 text-honey-dark`,children:"STALE"}),n.broken&&!n.stale&&e.jsx("span",{className:`${Ce} bg-accent-muted/30 text-accent-dark`,children:"BROKEN"}),n.notIndexed&&e.jsx("span",{className:`${Ce} bg-rule-inner text-fg-dim`,children:"NOT INDEXED"})]}),e.jsx("div",{className:"text-[11.5px] text-fg-dim pl-[14px] overflow-hidden text-ellipsis whitespace-nowrap",children:n.description}),e.jsx("div",{className:"font-mono text-[10.5px] text-fg-dim pl-[14px]",children:Pt(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})]})]})]})}),Se="text-xs font-medium h-[26px] px-2.5 border border-rule-structural rounded-[5px] bg-bg text-fg hover:border-fg",ge="px-[7px] py-0.5 rounded bg-bg-elev",be="px-2.5 py-[7px] rounded-[5px] text-left text-[12.5px] hover:bg-bg-elev",Wt="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",Be={update:{apply:"Apply",hint:"Writes the file"},delete:{apply:"Archive",hint:"Moves to .archive — undoable"},keep:{apply:"Mark verified",hint:"Touches the file, clears age staleness"},fold:{apply:"Copy for an Epic",hint:"Memory stays until the doc change lands"}};function Ut(s){var t;return s.action==="delete"?"Suggested: archive this memory":s.action==="fold"?`Suggested: move into ${((t=s.fold)==null?void 0:t.target)??"a doc"}`:s.action==="keep"?"Looks accurate — keep":"Suggested update"}function Vt(s){return s<1024?`${s} B`:`${(s/1024).toFixed(1)} KB`}function Ht(s){return s<=0?"just now":`${s}d ago`}function Gt(s){const t=/^---\r?\n[\s\S]*?\r?\n---[ \t]*(?:\r?\n|$)/.exec(s);return(t?s.slice(t[0].length):s).trim()}function Yt(s){return s.replace(/^\*\*Why:\*\*[ \t]*/gim,`#### WHY
11
11
 
12
12
  `).replace(/^\*\*How to apply:\*\*[ \t]*/gim,`#### HOW TO APPLY
13
13
 
14
- `)}const Gt=i.memo(function(t){const{row:n,fix:l}=t,[x,a]=i.useState(!1),p=i.useMemo(()=>t.content===null||t.mode!=="read"?"":kt(zt(Yt(t.content))),[t.content,t.mode]),m=c=>()=>{a(!1),c()};return e.jsxs("div",{"data-testid":"mx-reader",className:"flex flex-col flex-1 min-w-0 min-h-0",children:[e.jsxs("div",{className:"px-[22px] pt-3.5 pb-3 border-b border-rule-structural flex flex-col gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs text-fg-dim",children:[e.jsx("span",{className:`w-[7px] h-[7px] rounded-sm ${t.clusterDot}`}),e.jsx("span",{children:t.clusterName}),e.jsx("span",{className:"flex-1"}),!t.archived&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex border border-rule-structural rounded-[5px] overflow-hidden",children:[e.jsx("button",{type:"button","data-testid":"mx-reader-mode-read",onClick:()=>t.onMode("read"),className:`px-2.5 py-[3px] text-fg ${t.mode==="read"?"bg-muteband":""}`,children:"Read"}),e.jsx("button",{type:"button","data-testid":"mx-reader-mode-source",onClick:()=>t.onMode("source"),className:`px-2.5 py-[3px] text-fg border-l border-rule-structural ${t.mode==="source"?"bg-muteband":""}`,children:"Source"})]}),e.jsx("button",{type:"button","data-testid":"mx-reader-edit",onClick:t.onEdit,className:Se,children:"Edit"}),e.jsxs("div",{className:"relative",children:[e.jsx("button",{type:"button","data-testid":"mx-reader-more",onClick:()=>a(c=>!c),className:`${Se} !px-2`,children:"⋯"}),x&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:`fixed inset-0 ${K.dialog}`,onClick:()=>a(!1)}),e.jsxs("div",{className:`absolute right-0 top-8 w-[200px] ${K.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:be,onClick:m(t.onCopyPath),children:"Copy path"}),e.jsx("button",{type:"button",className:be,onClick:m(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:be,onClick:m(t.onArchive),children:"Archive"}),e.jsx("button",{type:"button",className:`${be} text-accent`,onClick:m(t.onAskDelete),children:"Delete…"})]})]})]})]})]}),e.jsx("div",{className:"font-mono text-[18px] font-medium text-fg break-all",children:n.slug}),e.jsxs("div",{className:"flex flex-wrap gap-1.5 text-[11.5px] text-fg-dim",children:[n.type&&e.jsxs("span",{className:ge,children:["type · ",n.type]}),e.jsx("span",{className:ge,children:Vt(n.bytes)}),e.jsxs("span",{className:ge,children:["modified ",Ht(n.ageDays)]}),n.originSessionId&&e.jsxs("span",{className:`${ge} font-mono text-[10.5px]`,children:["session ",n.originSessionId.slice(0,8)]})]})]}),!t.archived&&!n.stale&&l.state==="idle"&&e.jsxs("div",{className:"mx-[22px] mt-3 flex items-center gap-2 text-[11px] text-fg-dim",children:[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] border border-rule-structural text-fg hover:border-fg",children:"Review with assistant"}),e.jsx("span",{children:"uses Claude"})]}),t.archived&&e.jsxs("div",{className:"mx-[22px] 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:Se,children:"Restore"})]}),!t.archived&&n.stale&&l.state==="idle"&&e.jsxs("div",{"data-testid":"mx-reader-stale",className:"mx-[22px] 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&&l.state==="checking"&&e.jsxs("div",{className:"mx-[22px] 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&&l.state==="proposed"&&e.jsxs("div",{className:"mx-[22px] mt-3 border border-honey rounded-md overflow-hidden bg-bg-hi",children:[e.jsx("div",{className:"px-3 py-[9px] bg-butter/40 text-[12.5px] text-honey-dark font-semibold",children:Ut(l)}),e.jsxs("div",{className:"px-3 py-2 text-[12.5px] text-fg flex flex-col gap-0.5",children:[e.jsx("span",{"data-testid":"mx-reader-summary",children:l.summary}),l.reason&&e.jsx("span",{"data-testid":"mx-reader-reason",className:"text-fg-dim",children:l.reason})]}),l.action==="fold"&&l.fold&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"px-3 py-1.5 border-t border-rule-inner text-[11.5px] text-fg-dim font-mono break-all",children:[l.fold.target," · ",l.fold.anchor||"append at end"]}),l.fold.insert.split(`
15
- `).map((c,v)=>e.jsxs("div",{className:"grid grid-cols-[20px_1fr] px-3 py-1.5 font-mono text-xs leading-normal border-t border-rule-inner bg-sage/20 text-sage-dark",children:[e.jsx("span",{children:"+"}),e.jsx("span",{className:"whitespace-pre-wrap break-words",children:c})]},v))]}),l.action==="update"&&l.diff.map((c,v)=>e.jsxs("div",{className:`grid grid-cols-[20px_1fr] px-3 py-1.5 font-mono text-xs leading-normal border-t border-rule-inner ${c.sign==="−"?"bg-accent-muted/30 text-accent-dark":c.sign==="+"?"bg-sage/20 text-sage-dark":"text-fg-dim"}`,children:[e.jsx("span",{children:c.sign}),e.jsx("span",{className:"whitespace-pre-wrap break-words",children:c.text})]},v)),e.jsxs("div",{className:"flex gap-2 px-3 py-2.5 border-t border-rule-structural items-center",children:[e.jsx("button",{type:"button","data-testid":"mx-reader-apply",onClick:t.onApplyFix,className:"text-xs font-medium h-7 px-3 rounded-[5px] bg-fg text-bg",children:Fe[l.action].apply}),e.jsx("button",{type:"button","data-testid":"mx-reader-discard",onClick:t.onDiscardFix,className:"text-xs font-medium h-7 px-3 rounded-[5px] border border-rule text-fg",children:"Discard"}),e.jsx("span",{className:"flex-1"}),e.jsx("span",{className:"text-[11.5px] text-fg-dim",children:Fe[l.action].hint})]})]}),n.broken&&!n.stale&&e.jsx("div",{className:"mx-[22px] 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-[22px] 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-[22px] pt-4 pb-[22px]",children:t.content===null?e.jsx("div",{className:"text-xs text-fg-faint",children:"Loading…"}):t.mode==="source"?e.jsx("pre",{className:"m-0 px-4 py-3.5 bg-fg text-bg-elev rounded-md font-mono text-xs leading-[1.7] whitespace-pre-wrap",children:t.content}):e.jsxs("div",{className:Wt,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:p}})]})}),e.jsx("div",{className:"px-[22px] py-2 border-t border-rule-structural font-mono text-[10.5px] text-fg-dim whitespace-nowrap overflow-hidden text-ellipsis",children:n.path})]})});function qt({mode:s,name:t,title:n,onTitle:l,body:x,onBody:a,onSave:p,onCancel:m,saving:c,dirty:v}){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 /."})]});const k=c||s==="edit"&&!v,f=o=>{(o.metaKey||o.ctrlKey)&&o.key.toLowerCase()==="s"?(o.preventDefault(),k||p()):o.key==="Escape"&&(o.preventDefault(),m())};return e.jsxs("div",{"data-testid":"mx-editor",className:"flex-1 min-h-0 flex flex-col",onKeyDown:f,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:s==="new"?"New memory":`Editing ${t??""}`}),e.jsx("button",{type:"button","data-testid":"mx-editor-cancel",onClick:m,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:k,onClick:p,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:[s==="new"&&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:o=>l(o.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:["→ ",Xe(n),".md"]})]}),e.jsx("textarea",{"data-testid":"mx-editor-body",value:x,onChange:o=>a(o.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.jsxs("div",{className:"flex items-center gap-2 text-[11.5px] text-fg-faint",children:[e.jsx("span",{children:`Markdown. Frontmatter is ${s==="new"?"added":"kept"} on save. Saving marks the memory verified.`}),v&&s==="edit"&&e.jsx("span",{className:"text-accent font-semibold",children:"unsaved"})]})]})]})}const Be=i.memo(qt),Pe="text-[10px] tracking-[.08em] font-semibold text-fg-dim",Xt="flex flex-col gap-px px-2 py-[6px] rounded-[5px] cursor-pointer bg-bg border text-left hover:border-fg-faint";function Ke({testid:s,slug:t,sub:n,dangling:l,onClick:x}){return e.jsxs("button",{type:"button","data-testid":s,onClick:x,className:`${Xt} ${l?"border-accent-muted":"border-rule-inner"}`,children:[e.jsx("span",{className:`text-[12px] font-medium overflow-hidden text-ellipsis whitespace-nowrap ${l?"text-accent":""}`,children:t}),e.jsx("span",{className:`text-[10.5px] ${l?"text-accent":"text-fg-dim"}`,children:n})]})}const Qt=i.memo(function({row:t,onOpen:n,onRemoveLink:l,onAskAbout:x}){return e.jsx("aside",{"data-testid":"mx-links",className:"bg-bg-elev border-l border-rule-structural px-[14px] py-4 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:Pe,children:["LINKS TO · ",t.outLinks.length]}),t.outLinks.map(a=>{const p=t.danglingLinks.includes(a);return e.jsx(Ke,{testid:`mx-link-out-${a}`,slug:a,dangling:p,sub:p?"missing · click to remove link":"wikilink",onClick:()=>p?l(a):n(a)},a)}),t.outLinks.length===0&&e.jsx("span",{className:"text-[12px] text-fg-dim",children:"No outgoing links."})]}),e.jsxs("div",{className:"flex flex-col gap-[6px]",children:[e.jsxs("span",{className:Pe,children:["LINKED FROM · ",t.inLinks.length]}),t.inLinks.map(a=>e.jsx(Ke,{testid:`mx-link-in-${a}`,slug:a,dangling:!1,sub:"wikilink",onClick:()=>n(a)},a)),t.inLinks.length===0&&e.jsx("span",{className:"text-[12px] text-fg-dim",children:"Nothing links here yet."})]}),e.jsxs("button",{type:"button","data-testid":"mx-links-ask",onClick:x,className:"mt-auto flex flex-col gap-[6px] p-[10px] border border-dashed border-rule rounded-[6px] cursor-pointer text-left hover:border-fg",children:[e.jsx("span",{className:"text-[12px] text-fg",children:"Ask about this memory"}),e.jsx("span",{className:"h-7 border border-rule-structural rounded-[5px] bg-bg-hi px-2 flex items-center text-[11.5px] text-fg-dim",children:"Is this still accurate?"})]})]})})}),Zt=["What changed this week?","Find contradictions","Summarize stale memories","remember …"],Jt=["Is this still accurate?","What links here?","Summarize it"],es=/^remember\b[\s:,-]*/i,We="text-xs font-medium h-[26px] px-2.5 rounded-[5px] bg-fg text-bg",ts=s=>s.charAt(0).toUpperCase()+s.slice(1),ss=i.memo(function({rows:t,context:n,onClearContext:l,onAsk:x,onOpen:a,onReverify:p,onDraft:m}){const[c,v]=i.useState(""),[k,f]=i.useState(!1),[o,b]=i.useState(null),u=async()=>{const y=c.trim();if(!y||k)return;if(/^remember\b/i.test(y)){b({kind:"draft",question:y,text:ts(y.replace(es,""))}),v("");return}f(!0);let C=null;try{C=await x(y,n)}catch{C=null}f(!1),!(!C||!C.ok)&&(b({kind:"answer",question:y,answer:C.answer,citations:C.citations}),v(""))},j=(o==null?void 0:o.kind)==="answer"?o.citations.map(y=>({slug:y,row:t.find(C=>C.slug===y||C.name===y)})):[],M=j.filter(y=>{var C;return(C=y.row)==null?void 0:C.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:l,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:[!o&&!k&&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.'})]}),o&&e.jsx("div",{className:"self-end max-w-[520px] px-3.5 py-2.5 rounded-[10px] bg-fg text-bg text-[14px]",children:o.question}),(o==null?void 0:o.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:o.answer}),e.jsx("div",{className:"flex flex-wrap gap-1.5 items-center",children:j.map((y,C)=>{var I;return e.jsxs("button",{"data-testid":`mx-ask-cite-${y.slug}`,onClick:()=>{var W;return a(((W=y.row)==null?void 0:W.name)??y.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:["[",C+1,"]"]}),e.jsx("span",{children:y.slug}),y.row&&e.jsxs("span",{className:"text-fg-dim",children:[y.row.ageDays,"d"]}),((I=y.row)==null?void 0:I.stale)&&e.jsx("span",{className:"text-[9.5px] font-semibold px-1 rounded-[3px] bg-butter/40 text-honey-dark",children:"STALE"})]},y.slug)})}),M>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:[M," of these ",M===1?"is":"are"," flagged stale. Re-verify against the current code?"]}),e.jsx("button",{onClick:p,className:We,children:"Re-verify"})]})]}),(o==null?void 0:o.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:o.text}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:()=>m(o.text),className:`${We} 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"})]})]}),k&&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?Jt:Zt).map(y=>e.jsx("button",{onClick:()=>v(y),className:"px-2.5 py-1 border border-rule-structural rounded-[14px] text-xs text-fg-dim hover:bg-bg-elev",children:y},y))}),e.jsxs("div",{className:"flex gap-2 items-center",children:[e.jsx("input",{"data-testid":"mx-ask-input",value:c,onChange:y=>v(y.target.value),onKeyDown:y=>{y.key==="Enter"&&u()},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(Nt,{}),e.jsx("button",{"data-testid":"mx-ask-send",onClick:()=>void u(),disabled:k,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"})]})]})]})}),Ue="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",Ve="text-[11px] text-fg-faint",ns=i.memo(function({clusters:t,rows:n,generatedAt:l,running:x,unclusteredCount:a,available:p,onRegenerate:m,onOpenCluster:c,onOpen:v}){const k=i.useMemo(()=>new Map(n.map(f=>[f.slug,f])),[n]);return p?l===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:Ue,disabled:x,onClick:m,children:x?"Generating…":"Generate"}),e.jsx("span",{className:Ve,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 ",wt(l,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:Ue,disabled:x,onClick:m,children:x?"Generating…":"Regenerate"}),e.jsx("span",{className:Ve,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(f=>e.jsxs("div",{"data-testid":`mx-cluster-${f.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 ${f.dotClass}`}),e.jsx("span",{className:"font-serif text-[17px] text-fg min-w-0 flex-1",children:f.name}),e.jsxs("button",{type:"button","data-testid":`mx-cluster-open-${f.id}`,className:"text-xs text-accent hover:text-fg",onClick:()=>c(f.id),children:["Open ",f.memberSlugs.length," →"]})]}),e.jsx("span",{className:"text-[12.5px] leading-normal text-fg-dim",children:f.summary}),e.jsx("div",{className:"flex flex-wrap gap-[5px] items-center",children:f.memberSlugs.map(o=>{const b=k.get(o);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 ${b!=null&&b.stale?"bg-butter/40":"bg-bg"}`,onClick:()=>v((b==null?void 0:b.name)??`${o}.md`),children:o},o)})}),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:[f.linkCount," links"]}),e.jsxs("span",{children:[f.retireCount," retires"]}),e.jsxs("span",{className:"text-honey-dark",children:[f.staleCount," stale"]})]})]},f.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."})});function rs({open:s,rows:t,clusterDot:n,onPick:l,onAsk:x,onClose:a}){const[p,m]=i.useState(""),[c,v]=i.useState(0);if(i.useEffect(()=>{s&&(m(""),v(0))},[s]),!s)return null;const k=Ge(qe(t,"recent"),p,6),f=k.length,o=u=>{u===f?x(p):l(k[u].name)},b=u=>{u.key==="ArrowDown"?(u.preventDefault(),v(j=>Math.min(j+1,f))):u.key==="ArrowUp"?(u.preventDefault(),v(j=>Math.max(j-1,0))):u.key==="Enter"?(u.preventDefault(),o(Math.min(c,f))):u.key==="Escape"&&(u.preventDefault(),a())};return e.jsxs("div",{"data-testid":"mx-palette",children:[e.jsx("div",{className:`absolute inset-0 ${K.dialog} bg-fg/30`,onClick:a}),e.jsxs("div",{className:`absolute left-1/2 top-[84px] -translate-x-1/2 w-[580px] ${K.dialog} bg-bg-hi border border-rule rounded-[10px] shadow-2xl overflow-hidden`,children:[e.jsx("input",{"data-testid":"mx-palette-input",autoFocus:!0,value:p,onChange:u=>{m(u.target.value),v(0)},onKeyDown:b,placeholder:"Search memories or ask a question…",className:"w-full h-[50px] border-0 border-b border-rule-inner px-[18px] text-[15px] text-fg bg-transparent outline-none"}),e.jsxs("div",{className:"p-[6px] flex flex-col max-h-[380px] overflow-auto",children:[k.map((u,j)=>e.jsxs("div",{"data-testid":"mx-palette-row",onClick:()=>o(j),onMouseEnter:()=>v(j),className:`flex items-center gap-[9px] px-3 py-2 rounded-[6px] cursor-pointer ${j===c?"bg-bg-deep":""}`,children:[e.jsx("span",{className:`w-[7px] h-[7px] rounded-[2px] flex-none ${n(u.clusterId)}`}),e.jsx("span",{className:"font-mono text-[12.5px] text-fg flex-none",children:u.slug}),e.jsx("span",{className:"text-[12px] text-fg-dim overflow-hidden text-ellipsis whitespace-nowrap",children:u.description})]},u.name)),e.jsxs("div",{"data-testid":"mx-palette-ask",onClick:()=>o(f),onMouseEnter:()=>v(f),className:`flex items-center gap-[9px] px-3 py-[10px] mt-1 border-t border-rule-inner cursor-pointer text-[13px] text-accent ${c===f?"bg-bg-deep":""}`,children:[e.jsx("span",{className:"font-mono text-[11px]",children:"↵"}),"Ask “",p,"” …",e.jsx("span",{className:"flex-1"}),e.jsx("span",{className:"text-[11px] text-fg-dim",children:"opens Ask"})]})]}),e.jsxs("div",{className:"px-[14px] py-2 border-t border-rule-inner text-[11px] text-fg-dim flex gap-[14px]",children:[e.jsx("span",{children:"↑↓ move"}),e.jsx("span",{children:"↵ open"}),e.jsx("span",{children:"esc close"})]})]})]})}const $e="text-[12.5px] font-medium h-8 px-3 rounded-[5px] cursor-pointer text-fg";function as({open:s,name:t,inbound:n,onArchive:l,onCancel:x,onConfirm:a}){return i.useEffect(()=>{if(!s)return;const p=m=>{m.key==="Escape"&&x()};return document.addEventListener("keydown",p),()=>document.removeEventListener("keydown",p)},[s,x]),s?e.jsxs("div",{"data-testid":"mx-delete-dialog",children:[e.jsx("div",{className:`absolute inset-0 ${K.dialog} bg-fg/30`,onClick:x}),e.jsxs("div",{className:`absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 w-[440px] ${K.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:l,className:`${$e} border border-rule mr-auto`,children:"Archive instead"}),e.jsx("button",{type:"button",onClick:x,className:`${$e} border border-rule bg-bg`,children:"Cancel"}),e.jsx("button",{type:"button","data-testid":"mx-delete-confirm",onClick:a,className:`${$e} border-0 px-[14px] bg-accent text-white`,children:"Delete"})]})]})]}):null}const os=6e3;function ls({message:s,onUndo:t,onClose:n}){return i.useEffect(()=>{if(s===null)return;const l=setTimeout(n,os);return()=>clearTimeout(l)},[s]),s===null?null:e.jsxs("div",{"data-testid":"mx-undo-bar",className:`absolute bottom-[22px] left-1/2 -translate-x-1/2 ${K.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 Ze="sm.memoryTab.scope",ce="agent:",Me=`One-line summary of the fact or rule.
14
+ `)}const zt=i.memo(function(t){const{row:n,fix:l}=t,[x,a]=i.useState(!1),p=i.useMemo(()=>t.content===null||t.mode!=="read"?"":kt(Yt(Gt(t.content))),[t.content,t.mode]),m=c=>()=>{a(!1),c()};return e.jsxs("div",{"data-testid":"mx-reader",className:"flex flex-col flex-1 min-w-0 min-h-0",children:[e.jsxs("div",{className:"px-[22px] pt-3.5 pb-3 border-b border-rule-structural flex flex-col gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs text-fg-dim",children:[e.jsx("span",{className:`w-[7px] h-[7px] rounded-sm ${t.clusterDot}`}),e.jsx("span",{children:t.clusterName}),e.jsx("span",{className:"flex-1"}),!t.archived&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex border border-rule-structural rounded-[5px] overflow-hidden",children:[e.jsx("button",{type:"button","data-testid":"mx-reader-mode-read",onClick:()=>t.onMode("read"),className:`px-2.5 py-[3px] text-fg ${t.mode==="read"?"bg-muteband":""}`,children:"Read"}),e.jsx("button",{type:"button","data-testid":"mx-reader-mode-source",onClick:()=>t.onMode("source"),className:`px-2.5 py-[3px] text-fg border-l border-rule-structural ${t.mode==="source"?"bg-muteband":""}`,children:"Source"})]}),e.jsx("button",{type:"button","data-testid":"mx-reader-edit",onClick:t.onEdit,className:Se,children:"Edit"}),e.jsxs("div",{className:"relative",children:[e.jsx("button",{type:"button","data-testid":"mx-reader-more",onClick:()=>a(c=>!c),className:`${Se} !px-2`,children:"⋯"}),x&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:`fixed inset-0 ${K.dialog}`,onClick:()=>a(!1)}),e.jsxs("div",{className:`absolute right-0 top-8 w-[200px] ${K.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:be,onClick:m(t.onCopyPath),children:"Copy path"}),e.jsx("button",{type:"button",className:be,onClick:m(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:be,onClick:m(t.onArchive),children:"Archive"}),e.jsx("button",{type:"button",className:`${be} text-accent`,onClick:m(t.onAskDelete),children:"Delete…"})]})]})]})]})]}),e.jsx("div",{className:"font-mono text-[18px] font-medium text-fg break-all",children:n.slug}),e.jsxs("div",{className:"flex flex-wrap gap-1.5 text-[11.5px] text-fg-dim",children:[n.type&&e.jsxs("span",{className:ge,children:["type · ",n.type]}),e.jsx("span",{className:ge,children:Vt(n.bytes)}),e.jsxs("span",{className:ge,children:["modified ",Ht(n.ageDays)]}),n.originSessionId&&e.jsxs("span",{className:`${ge} font-mono text-[10.5px]`,children:["session ",n.originSessionId.slice(0,8)]})]})]}),!t.archived&&!n.stale&&l.state==="idle"&&e.jsxs("div",{className:"mx-[22px] mt-3 flex items-center gap-2 text-[11px] text-fg-dim",children:[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] border border-rule-structural text-fg hover:border-fg",children:"Review with assistant"}),e.jsx("span",{children:"uses Claude"})]}),t.archived&&e.jsxs("div",{className:"mx-[22px] 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:Se,children:"Restore"})]}),!t.archived&&n.stale&&l.state==="idle"&&e.jsxs("div",{"data-testid":"mx-reader-stale",className:"mx-[22px] 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&&l.state==="checking"&&e.jsxs("div",{className:"mx-[22px] 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&&l.state==="proposed"&&e.jsxs("div",{className:"mx-[22px] mt-3 border border-honey rounded-md overflow-hidden bg-bg-hi",children:[e.jsx("div",{className:"px-3 py-[9px] bg-butter/40 text-[12.5px] text-honey-dark font-semibold",children:Ut(l)}),e.jsxs("div",{className:"px-3 py-2 text-[12.5px] text-fg flex flex-col gap-0.5",children:[e.jsx("span",{"data-testid":"mx-reader-summary",children:l.summary}),l.reason&&e.jsx("span",{"data-testid":"mx-reader-reason",className:"text-fg-dim",children:l.reason})]}),l.action==="fold"&&l.fold&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"px-3 py-1.5 border-t border-rule-inner text-[11.5px] text-fg-dim font-mono break-all",children:[l.fold.target," · ",l.fold.anchor||"append at end"]}),l.fold.insert.split(`
15
+ `).map((c,v)=>e.jsxs("div",{className:"grid grid-cols-[20px_1fr] px-3 py-1.5 font-mono text-xs leading-normal border-t border-rule-inner bg-sage/20 text-sage-dark",children:[e.jsx("span",{children:"+"}),e.jsx("span",{className:"whitespace-pre-wrap break-words",children:c})]},v))]}),l.action==="update"&&l.diff.map((c,v)=>e.jsxs("div",{className:`grid grid-cols-[20px_1fr] px-3 py-1.5 font-mono text-xs leading-normal border-t border-rule-inner ${c.sign==="−"?"bg-accent-muted/30 text-accent-dark":c.sign==="+"?"bg-sage/20 text-sage-dark":"text-fg-dim"}`,children:[e.jsx("span",{children:c.sign}),e.jsx("span",{className:"whitespace-pre-wrap break-words",children:c.text})]},v)),e.jsxs("div",{className:"flex gap-2 px-3 py-2.5 border-t border-rule-structural items-center",children:[e.jsx("button",{type:"button","data-testid":"mx-reader-apply",onClick:t.onApplyFix,className:"text-xs font-medium h-7 px-3 rounded-[5px] bg-fg text-bg",children:Be[l.action].apply}),e.jsx("button",{type:"button","data-testid":"mx-reader-discard",onClick:t.onDiscardFix,className:"text-xs font-medium h-7 px-3 rounded-[5px] border border-rule text-fg",children:"Discard"}),e.jsx("span",{className:"flex-1"}),e.jsx("span",{className:"text-[11.5px] text-fg-dim",children:Be[l.action].hint})]})]}),n.broken&&!n.stale&&e.jsx("div",{className:"mx-[22px] 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-[22px] 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-[22px] pt-4 pb-[22px]",children:t.content===null?e.jsx("div",{className:"text-xs text-fg-faint",children:"Loading…"}):t.mode==="source"?e.jsx("pre",{className:"m-0 px-4 py-3.5 bg-fg text-bg-elev rounded-md font-mono text-xs leading-[1.7] whitespace-pre-wrap",children:t.content}):e.jsxs("div",{className:Wt,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:p}})]})}),e.jsx("div",{className:"px-[22px] py-2 border-t border-rule-structural font-mono text-[10.5px] text-fg-dim whitespace-nowrap overflow-hidden text-ellipsis",children:n.path})]})});function qt({mode:s,name:t,title:n,onTitle:l,body:x,onBody:a,onSave:p,onCancel:m,saving:c,dirty:v}){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 /."})]});const k=c||s==="edit"&&!v,f=o=>{(o.metaKey||o.ctrlKey)&&o.key.toLowerCase()==="s"?(o.preventDefault(),k||p()):o.key==="Escape"&&(o.preventDefault(),m())};return e.jsxs("div",{"data-testid":"mx-editor",className:"flex-1 min-h-0 flex flex-col",onKeyDown:f,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:s==="new"?"New memory":`Editing ${t??""}`}),e.jsx("button",{type:"button","data-testid":"mx-editor-cancel",onClick:m,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:k,onClick:p,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:[s==="new"&&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:o=>l(o.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:["→ ",Xe(n),".md"]})]}),e.jsx("textarea",{"data-testid":"mx-editor-body",value:x,onChange:o=>a(o.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.jsxs("div",{className:"flex items-center gap-2 text-[11.5px] text-fg-faint",children:[e.jsx("span",{children:`Markdown. Frontmatter is ${s==="new"?"added":"kept"} on save. Saving marks the memory verified.`}),v&&s==="edit"&&e.jsx("span",{className:"text-accent font-semibold",children:"unsaved"})]})]})]})}const Fe=i.memo(qt),Pe="text-[10px] tracking-[.08em] font-semibold text-fg-dim",Xt="flex flex-col gap-px px-2 py-[6px] rounded-[5px] cursor-pointer bg-bg border text-left hover:border-fg-faint";function Ke({testid:s,slug:t,sub:n,dangling:l,onClick:x}){return e.jsxs("button",{type:"button","data-testid":s,onClick:x,className:`${Xt} ${l?"border-accent-muted":"border-rule-inner"}`,children:[e.jsx("span",{className:`text-[12px] font-medium overflow-hidden text-ellipsis whitespace-nowrap ${l?"text-accent":""}`,children:t}),e.jsx("span",{className:`text-[10.5px] ${l?"text-accent":"text-fg-dim"}`,children:n})]})}const Qt=i.memo(function({row:t,onOpen:n,onRemoveLink:l,onAskAbout:x}){return e.jsx("aside",{"data-testid":"mx-links",className:"bg-bg-elev border-l border-rule-structural px-[14px] py-4 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:Pe,children:["LINKS TO · ",t.outLinks.length]}),t.outLinks.map(a=>{const p=t.danglingLinks.includes(a);return e.jsx(Ke,{testid:`mx-link-out-${a}`,slug:a,dangling:p,sub:p?"missing · click to remove link":"wikilink",onClick:()=>p?l(a):n(a)},a)}),t.outLinks.length===0&&e.jsx("span",{className:"text-[12px] text-fg-dim",children:"No outgoing links."})]}),e.jsxs("div",{className:"flex flex-col gap-[6px]",children:[e.jsxs("span",{className:Pe,children:["LINKED FROM · ",t.inLinks.length]}),t.inLinks.map(a=>e.jsx(Ke,{testid:`mx-link-in-${a}`,slug:a,dangling:!1,sub:"wikilink",onClick:()=>n(a)},a)),t.inLinks.length===0&&e.jsx("span",{className:"text-[12px] text-fg-dim",children:"Nothing links here yet."})]}),e.jsxs("button",{type:"button","data-testid":"mx-links-ask",onClick:x,className:"mt-auto flex flex-col gap-[6px] p-[10px] border border-dashed border-rule rounded-[6px] cursor-pointer text-left hover:border-fg",children:[e.jsx("span",{className:"text-[12px] text-fg",children:"Ask about this memory"}),e.jsx("span",{className:"h-7 border border-rule-structural rounded-[5px] bg-bg-hi px-2 flex items-center text-[11.5px] text-fg-dim",children:"Is this still accurate?"})]})]})})}),Zt=["What changed this week?","Find contradictions","Summarize stale memories","remember …"],Jt=["Is this still accurate?","What links here?","Summarize it"],es=/^remember\b[\s:,-]*/i,We="text-xs font-medium h-[26px] px-2.5 rounded-[5px] bg-fg text-bg",ts=s=>s.charAt(0).toUpperCase()+s.slice(1),ss=i.memo(function({rows:t,context:n,onClearContext:l,onAsk:x,onOpen:a,onReverify:p,onDraft:m}){const[c,v]=i.useState(""),[k,f]=i.useState(!1),[o,b]=i.useState(null),u=async()=>{const y=c.trim();if(!y||k)return;if(/^remember\b/i.test(y)){b({kind:"draft",question:y,text:ts(y.replace(es,""))}),v("");return}f(!0);let C=null;try{C=await x(y,n)}catch{C=null}f(!1),!(!C||!C.ok)&&(b({kind:"answer",question:y,answer:C.answer,citations:C.citations}),v(""))},j=(o==null?void 0:o.kind)==="answer"?o.citations.map(y=>({slug:y,row:t.find(C=>C.slug===y||C.name===y)})):[],M=j.filter(y=>{var C;return(C=y.row)==null?void 0:C.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:l,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:[!o&&!k&&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.'})]}),o&&e.jsx("div",{className:"self-end max-w-[520px] px-3.5 py-2.5 rounded-[10px] bg-fg text-bg text-[14px]",children:o.question}),(o==null?void 0:o.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:o.answer}),e.jsx("div",{className:"flex flex-wrap gap-1.5 items-center",children:j.map((y,C)=>{var T;return e.jsxs("button",{"data-testid":`mx-ask-cite-${y.slug}`,onClick:()=>{var W;return a(((W=y.row)==null?void 0:W.name)??y.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:["[",C+1,"]"]}),e.jsx("span",{children:y.slug}),y.row&&e.jsxs("span",{className:"text-fg-dim",children:[y.row.ageDays,"d"]}),((T=y.row)==null?void 0:T.stale)&&e.jsx("span",{className:"text-[9.5px] font-semibold px-1 rounded-[3px] bg-butter/40 text-honey-dark",children:"STALE"})]},y.slug)})}),M>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:[M," of these ",M===1?"is":"are"," flagged stale. Re-verify against the current code?"]}),e.jsx("button",{onClick:p,className:We,children:"Re-verify"})]})]}),(o==null?void 0:o.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:o.text}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:()=>m(o.text),className:`${We} 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"})]})]}),k&&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?Jt:Zt).map(y=>e.jsx("button",{onClick:()=>v(y),className:"px-2.5 py-1 border border-rule-structural rounded-[14px] text-xs text-fg-dim hover:bg-bg-elev",children:y},y))}),e.jsxs("div",{className:"flex gap-2 items-center",children:[e.jsx("input",{"data-testid":"mx-ask-input",value:c,onChange:y=>v(y.target.value),onKeyDown:y=>{y.key==="Enter"&&u()},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(Nt,{}),e.jsx("button",{"data-testid":"mx-ask-send",onClick:()=>void u(),disabled:k,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"})]})]})]})}),Ue="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",Ve="text-[11px] text-fg-faint",ns=i.memo(function({clusters:t,rows:n,generatedAt:l,running:x,unclusteredCount:a,available:p,onRegenerate:m,onOpenCluster:c,onOpen:v}){const k=i.useMemo(()=>new Map(n.map(f=>[f.slug,f])),[n]);return p?l===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:Ue,disabled:x,onClick:m,children:x?"Generating…":"Generate"}),e.jsx("span",{className:Ve,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 ",wt(l,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:Ue,disabled:x,onClick:m,children:x?"Generating…":"Regenerate"}),e.jsx("span",{className:Ve,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(f=>e.jsxs("div",{"data-testid":`mx-cluster-${f.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 ${f.dotClass}`}),e.jsx("span",{className:"font-serif text-[17px] text-fg min-w-0 flex-1",children:f.name}),e.jsxs("button",{type:"button","data-testid":`mx-cluster-open-${f.id}`,className:"text-xs text-accent hover:text-fg",onClick:()=>c(f.id),children:["Open ",f.memberSlugs.length," →"]})]}),e.jsx("span",{className:"text-[12.5px] leading-normal text-fg-dim",children:f.summary}),e.jsx("div",{className:"flex flex-wrap gap-[5px] items-center",children:f.memberSlugs.map(o=>{const b=k.get(o);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 ${b!=null&&b.stale?"bg-butter/40":"bg-bg"}`,onClick:()=>v((b==null?void 0:b.name)??`${o}.md`),children:o},o)})}),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:[f.linkCount," links"]}),e.jsxs("span",{children:[f.retireCount," retires"]}),e.jsxs("span",{className:"text-honey-dark",children:[f.staleCount," stale"]})]})]},f.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."})});function rs({open:s,rows:t,clusterDot:n,onPick:l,onAsk:x,onClose:a}){const[p,m]=i.useState(""),[c,v]=i.useState(0);if(i.useEffect(()=>{s&&(m(""),v(0))},[s]),!s)return null;const k=ze(qe(t,"recent"),p,6),f=k.length,o=u=>{u===f?x(p):l(k[u].name)},b=u=>{u.key==="ArrowDown"?(u.preventDefault(),v(j=>Math.min(j+1,f))):u.key==="ArrowUp"?(u.preventDefault(),v(j=>Math.max(j-1,0))):u.key==="Enter"?(u.preventDefault(),o(Math.min(c,f))):u.key==="Escape"&&(u.preventDefault(),a())};return e.jsxs("div",{"data-testid":"mx-palette",children:[e.jsx("div",{className:`absolute inset-0 ${K.dialog} bg-fg/30`,onClick:a}),e.jsxs("div",{className:`absolute left-1/2 top-[84px] -translate-x-1/2 w-[580px] ${K.dialog} bg-bg-hi border border-rule rounded-[10px] shadow-2xl overflow-hidden`,children:[e.jsx("input",{"data-testid":"mx-palette-input",autoFocus:!0,value:p,onChange:u=>{m(u.target.value),v(0)},onKeyDown:b,placeholder:"Search memories or ask a question…",className:"w-full h-[50px] border-0 border-b border-rule-inner px-[18px] text-[15px] text-fg bg-transparent outline-none"}),e.jsxs("div",{className:"p-[6px] flex flex-col max-h-[380px] overflow-auto",children:[k.map((u,j)=>e.jsxs("div",{"data-testid":"mx-palette-row",onClick:()=>o(j),onMouseEnter:()=>v(j),className:`flex items-center gap-[9px] px-3 py-2 rounded-[6px] cursor-pointer ${j===c?"bg-bg-deep":""}`,children:[e.jsx("span",{className:`w-[7px] h-[7px] rounded-[2px] flex-none ${n(u.clusterId)}`}),e.jsx("span",{className:"font-mono text-[12.5px] text-fg flex-none",children:u.slug}),e.jsx("span",{className:"text-[12px] text-fg-dim overflow-hidden text-ellipsis whitespace-nowrap",children:u.description})]},u.name)),e.jsxs("div",{"data-testid":"mx-palette-ask",onClick:()=>o(f),onMouseEnter:()=>v(f),className:`flex items-center gap-[9px] px-3 py-[10px] mt-1 border-t border-rule-inner cursor-pointer text-[13px] text-accent ${c===f?"bg-bg-deep":""}`,children:[e.jsx("span",{className:"font-mono text-[11px]",children:"↵"}),"Ask “",p,"” …",e.jsx("span",{className:"flex-1"}),e.jsx("span",{className:"text-[11px] text-fg-dim",children:"opens Ask"})]})]}),e.jsxs("div",{className:"px-[14px] py-2 border-t border-rule-inner text-[11px] text-fg-dim flex gap-[14px]",children:[e.jsx("span",{children:"↑↓ move"}),e.jsx("span",{children:"↵ open"}),e.jsx("span",{children:"esc close"})]})]})]})}const $e="text-[12.5px] font-medium h-8 px-3 rounded-[5px] cursor-pointer text-fg";function as({open:s,name:t,inbound:n,onArchive:l,onCancel:x,onConfirm:a}){return i.useEffect(()=>{if(!s)return;const p=m=>{m.key==="Escape"&&x()};return document.addEventListener("keydown",p),()=>document.removeEventListener("keydown",p)},[s,x]),s?e.jsxs("div",{"data-testid":"mx-delete-dialog",children:[e.jsx("div",{className:`absolute inset-0 ${K.dialog} bg-fg/30`,onClick:x}),e.jsxs("div",{className:`absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 w-[440px] ${K.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:l,className:`${$e} border border-rule mr-auto`,children:"Archive instead"}),e.jsx("button",{type:"button",onClick:x,className:`${$e} border border-rule bg-bg`,children:"Cancel"}),e.jsx("button",{type:"button","data-testid":"mx-delete-confirm",onClick:a,className:`${$e} border-0 px-[14px] bg-accent text-white`,children:"Delete"})]})]})]}):null}const os=6e3;function ls({message:s,onUndo:t,onClose:n}){return i.useEffect(()=>{if(s===null)return;const l=setTimeout(n,os);return()=>clearTimeout(l)},[s]),s===null?null:e.jsxs("div",{"data-testid":"mx-undo-bar",className:`absolute bottom-[22px] left-1/2 -translate-x-1/2 ${K.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 Ze="sm.memoryTab.scope",ce="agent:",Me=`One-line summary of the fact or rule.
16
16
 
17
17
  **Why:**
18
18
 
19
- **How to apply:**`,B={state:"idle",diff:[],summary:"",action:"update",reason:"",fold:null},He=s=>s.replace(/\.md$/,""),Ye=s=>s?s.split(/[\\/]/).filter(Boolean).pop()??s:"workspace";function Ee(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/,"")}function is(){try{const s=localStorage.getItem(Ze);return s&&s.startsWith(ce)?s:"workspace"}catch{return"workspace"}}function ds({cwd:s}){const[t,n]=i.useState(is),[l,x]=i.useState([]),[a,p]=i.useState(0),m=i.useMemo(()=>{if(!t.startsWith(ce))return"workspace";const f=t.slice(ce.length);return l.some(o=>o.name===f)?t:"workspace"},[t,l]),c=i.useMemo(()=>{if(m==="workspace")return{kind:"workspace"};const f=l.find(o=>o.name===m.slice(ce.length));return f?{kind:"agent",agent:f}:{kind:"workspace"}},[m]),v=i.useCallback(f=>{const o=f.kind==="agent"?`${ce}${f.agent.name}`:"workspace";try{localStorage.setItem(Ze,o)}catch{}n(o)},[]),k=i.useCallback(f=>{f.length>0&&x(f)},[]);return e.jsx(cs,{scope:c,cwd:s,onScope:v,onAgents:k,wsCount:a,onWsCount:p},m)}function cs({scope:s,cwd:t,onScope:n,onAgents:l,wsCount:x,onWsCount:a}){var Re;const p=Tt(s,t),{actions:m,rows:c,clusters:v}=p,k=s.kind==="agent"?s.agent:null,f=k!==null&&k.memoryScope===null,o=k?k.name:Ye(t),[b,u]=i.useState("all"),[j,M]=i.useState(null),[y,C]=i.useState("read"),[I,W]=i.useState(""),[ee,xe]=i.useState("recent"),[q,A]=i.useState(null),[U,L]=i.useState(B),[me,ye]=i.useState(""),[X,T]=i.useState(null),[_,te]=i.useState(null),[ve,R]=i.useState(null),[$,Q]=i.useState(""),[V,H]=i.useState(""),[ue,se]=i.useState(""),[ne,re]=i.useState(!1),[Z,pe]=i.useState(null);i.useEffect(()=>{l(p.agents)},[p.agents,l]),i.useEffect(()=>{!k&&!p.loading&&a(c.length)},[k,p.loading,c.length,a]);const Y=i.useMemo(()=>p.archived.map(r=>({name:r,slug:He(r),path:`${p.dir}/${r}`,description:"",bytes:0,mtimeMs:0,ageDays:0,stale:!1,staleReasons:[],ageOnlyStale:!1,deadRefs:[],broken:!1,danglingLinks:[],outLinks:[],inLinks:[],notIndexed:!1,clusterId:null,type:null,originSessionId:null})),[p.archived,p.dir]),ae=b!=="ask"&&b!=="clusters",h=i.useMemo(()=>{if(b==="archived"){const r=I.trim().toLowerCase();return Y.filter(g=>!r||g.slug.toLowerCase().includes(r))}return qe(de(c,b,I),ee)},[b,c,Y,I,ee]),d=i.useMemo(()=>c.find(r=>r.name===j)??Y.find(r=>r.name===j)??null,[c,Y,j]),N=d!==null&&!c.some(r=>r.name===d.name),w=i.useCallback(r=>{var g;return((g=v.find(S=>S.id===r))==null?void 0:g.dotClass)??"bg-rule"},[v]),z=r=>{var g;return((g=v.find(S=>S.id===r))==null?void 0:g.name)??"Unclustered"},O=i.useCallback(r=>{M(r),C("read"),L(B),T(null),A(null)},[]),P=i.useCallback(r=>{u(r),W(""),A(null),L(B),C(g=>g==="edit"||g==="new"?"read":g)},[]);i.useEffect(()=>{var r;p.loading||!ae||y==="new"||d&&h.some(g=>g.name===d.name)||M(((r=h[0])==null?void 0:r.name)??null)},[p.loading,ae,y,d,h]);const oe=d&&!N?d.name:null,Je=d==null?void 0:d.mtimeMs;i.useEffect(()=>{if(!oe)return;let r=!0;return m.read(oe).then(g=>{r&&pe({name:oe,text:g})}),()=>{r=!1}},[oe,Je,m.read]);const G=N?"":Z&&Z.name===oe?Z.text:null;i.useEffect(()=>{const r=g=>{var he,ie;if(g.key!=="/"||g.metaKey||g.ctrlKey||g.altKey)return;const S=g.target,fe=((he=S==null?void 0:S.tagName)==null?void 0:he.toLowerCase())??"";fe==="input"||fe==="textarea"||S!=null&&S.isContentEditable||(ie=S==null?void 0:S.closest)!=null&&ie.call(S,".monaco-editor")||(g.preventDefault(),A("palette"))};return document.addEventListener("keydown",r),()=>document.removeEventListener("keydown",r)},[]);const D=(r,g)=>te({message:r,undo:g}),ke=(r="")=>{f||((b==="ask"||b==="clusters")&&u("all"),M(null),Q(""),H(r),se(""),L(B),A(null),C("new"))},Ne=r=>{P("all"),O(r)},et=r=>{const g=c.find(S=>S.slug===r);g?O(g.name):E.error(`${r} is not in this scope`)},tt=()=>{if(G===null)return;const r=Ee(G);H(r),se(r),C("edit")},st=async()=>{if(!ne){re(!0);try{if(y==="new"){const r=await m.create($,V);if(!r)return;const g=r.endsWith(".md")?r:`${r}.md`;P("all"),O(g),D(`Created ${He(g)}`)}else if(y==="edit"&&d){if(!await m.saveBody(d.name,V))return;C("read"),D(`Saved ${d.slug}`)}}finally{re(!1)}}},nt=()=>{C("read"),d||M(null)},rt=async()=>{if(!d||G===null)return;const r=d;L({...B,state:"checking"});const g=await m.proposeFix(r.name);if(!g.ok){L(B);return}ye(g.content),L({state:"proposed",diff:g.action==="update"?Dt(G,g.content):[],summary:g.summary,action:g.action,reason:g.reason,fold:g.fold})},at=async()=>{if(!d||G===null)return;const r=d;if(U.action==="delete"){if(!await m.archive(r.name))return;L(B),D(`Archived ${r.slug}`,()=>{m.restore(r.name)})}else if(U.action==="keep"){if(!await m.verify(r.name))return;L(B),D(`Marked ${r.slug} verified`)}else if(U.action==="fold"){if(!U.fold)return;const{target:g,anchor:S,insert:fe}=U.fold,he=`Fold memory ${r.slug} into ${g}.
19
+ **How to apply:**`,F={state:"idle",diff:[],summary:"",action:"update",reason:"",fold:null},He=s=>s.replace(/\.md$/,""),Ge=s=>s?s.split(/[\\/]/).filter(Boolean).pop()??s:"workspace";function Ee(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/,"")}function is(){try{const s=localStorage.getItem(Ze);return s&&s.startsWith(ce)?s:"workspace"}catch{return"workspace"}}function ds({cwd:s}){const[t,n]=i.useState(is),[l,x]=i.useState([]),[a,p]=i.useState(0),m=i.useMemo(()=>{if(!t.startsWith(ce))return"workspace";const f=t.slice(ce.length);return l.some(o=>o.name===f)?t:"workspace"},[t,l]),c=i.useMemo(()=>{if(m==="workspace")return{kind:"workspace"};const f=l.find(o=>o.name===m.slice(ce.length));return f?{kind:"agent",agent:f}:{kind:"workspace"}},[m]),v=i.useCallback(f=>{const o=f.kind==="agent"?`${ce}${f.agent.name}`:"workspace";try{localStorage.setItem(Ze,o)}catch{}n(o)},[]),k=i.useCallback(f=>{f.length>0&&x(f)},[]);return e.jsx(cs,{scope:c,cwd:s,onScope:v,onAgents:k,wsCount:a,onWsCount:p},m)}function cs({scope:s,cwd:t,onScope:n,onAgents:l,wsCount:x,onWsCount:a}){var Re;const p=It(s,t),{actions:m,rows:c,clusters:v}=p,k=s.kind==="agent"?s.agent:null,f=k!==null&&k.memoryScope===null,o=k?k.name:Ge(t),[b,u]=i.useState("all"),[j,M]=i.useState(null),[y,C]=i.useState("read"),[T,W]=i.useState(""),[ee,xe]=i.useState("recent"),[q,A]=i.useState(null),[U,L]=i.useState(F),[me,ye]=i.useState(""),[X,I]=i.useState(null),[_,te]=i.useState(null),[ve,R]=i.useState(null),[$,Q]=i.useState(""),[V,H]=i.useState(""),[ue,se]=i.useState(""),[ne,re]=i.useState(!1),[Z,pe]=i.useState(null);i.useEffect(()=>{l(p.agents)},[p.agents,l]),i.useEffect(()=>{!k&&!p.loading&&a(c.length)},[k,p.loading,c.length,a]);const G=i.useMemo(()=>p.archived.map(r=>({name:r,slug:He(r),path:`${p.dir}/${r}`,description:"",bytes:0,mtimeMs:0,ageDays:0,stale:!1,staleReasons:[],ageOnlyStale:!1,deadRefs:[],broken:!1,danglingLinks:[],outLinks:[],inLinks:[],notIndexed:!1,clusterId:null,type:null,originSessionId:null})),[p.archived,p.dir]),ae=b!=="ask"&&b!=="clusters",h=i.useMemo(()=>{if(b==="archived"){const r=T.trim().toLowerCase();return G.filter(g=>!r||g.slug.toLowerCase().includes(r))}return qe(de(c,b,T),ee)},[b,c,G,T,ee]),d=i.useMemo(()=>c.find(r=>r.name===j)??G.find(r=>r.name===j)??null,[c,G,j]),N=d!==null&&!c.some(r=>r.name===d.name),w=i.useCallback(r=>{var g;return((g=v.find(S=>S.id===r))==null?void 0:g.dotClass)??"bg-rule"},[v]),Y=r=>{var g;return((g=v.find(S=>S.id===r))==null?void 0:g.name)??"Unclustered"},O=i.useCallback(r=>{M(r),C("read"),L(F),I(null),A(null)},[]),P=i.useCallback(r=>{u(r),W(""),A(null),L(F),C(g=>g==="edit"||g==="new"?"read":g)},[]);i.useEffect(()=>{var r;p.loading||!ae||y==="new"||d&&h.some(g=>g.name===d.name)||M(((r=h[0])==null?void 0:r.name)??null)},[p.loading,ae,y,d,h]);const oe=d&&!N?d.name:null,Je=d==null?void 0:d.mtimeMs;i.useEffect(()=>{if(!oe)return;let r=!0;return m.read(oe).then(g=>{r&&pe({name:oe,text:g})}),()=>{r=!1}},[oe,Je,m.read]);const z=N?"":Z&&Z.name===oe?Z.text:null;i.useEffect(()=>{const r=g=>{var he,ie;if(g.key!=="/"||g.metaKey||g.ctrlKey||g.altKey)return;const S=g.target,fe=((he=S==null?void 0:S.tagName)==null?void 0:he.toLowerCase())??"";fe==="input"||fe==="textarea"||S!=null&&S.isContentEditable||(ie=S==null?void 0:S.closest)!=null&&ie.call(S,".monaco-editor")||(g.preventDefault(),A("palette"))};return document.addEventListener("keydown",r),()=>document.removeEventListener("keydown",r)},[]);const D=(r,g)=>te({message:r,undo:g}),ke=(r="")=>{f||((b==="ask"||b==="clusters")&&u("all"),M(null),Q(""),H(r),se(""),L(F),A(null),C("new"))},Ne=r=>{P("all"),O(r)},et=r=>{const g=c.find(S=>S.slug===r);g?O(g.name):E.error(`${r} is not in this scope`)},tt=()=>{if(z===null)return;const r=Ee(z);H(r),se(r),C("edit")},st=async()=>{if(!ne){re(!0);try{if(y==="new"){const r=await m.create($,V);if(!r)return;const g=r.endsWith(".md")?r:`${r}.md`;P("all"),O(g),D(`Created ${He(g)}`)}else if(y==="edit"&&d){if(!await m.saveBody(d.name,V))return;C("read"),D(`Saved ${d.slug}`)}}finally{re(!1)}}},nt=()=>{C("read"),d||M(null)},rt=async()=>{if(!d||z===null)return;const r=d;L({...F,state:"checking"});const g=await m.proposeFix(r.name);if(!g.ok){L(F);return}ye(g.content),L({state:"proposed",diff:g.action==="update"?Dt(z,g.content):[],summary:g.summary,action:g.action,reason:g.reason,fold:g.fold})},at=async()=>{if(!d||z===null)return;const r=d;if(U.action==="delete"){if(!await m.archive(r.name))return;L(F),D(`Archived ${r.slug}`,()=>{m.restore(r.name)})}else if(U.action==="keep"){if(!await m.verify(r.name))return;L(F),D(`Marked ${r.slug} verified`)}else if(U.action==="fold"){if(!U.fold)return;const{target:g,anchor:S,insert:fe}=U.fold,he=`Fold memory ${r.slug} into ${g}.
20
20
  Insert after the line: ${S||"(append at end)"}
21
21
  ---
22
22
  ${fe}
23
23
  ---
24
24
  Tread lightly: add only these lines, do not restructure the doc. Once committed, archive the memory ${r.slug} from the Memory page.
25
- Memory file: ${r.path}`,ie=await window.api.clipboard.writeText(he);if(!ie.ok){E.error(`Copy failed: ${ie.error??"unknown error"}`);return}L(B),D("Fold copied — paste it into a New Epic")}else{const g=Ee(G);if(!await m.saveBody(r.name,Ee(me)))return;L(B),T(r.slug),D(`Applied fix to ${r.slug}`,()=>{m.saveBody(r.name,g)})}},ot=async()=>{if(!d)return;const r=d;await m.verify(r.name)&&D(`Marked ${r.slug} verified`)},Ae=async()=>{if(!d)return;const r=d;A(null),await m.archive(r.name)&&D(`Archived ${r.slug}`,()=>{m.restore(r.name)})},lt=async()=>{if(!d)return;const r=d;await m.restore(r.name)&&D(`Restored ${r.slug}`)},it=async()=>{if(!d)return;const r=d;A(null);const g=await m.remove(r.name);if(!g)return;const S=r.inLinks.length;D(`Deleted ${r.slug}${S>0?` · ${S} inbound links now broken`:""}`,()=>{g()})},dt=async()=>{if(!d)return;const r=await window.api.clipboard.writeText(d.path);r.ok?D("Path copied"):E.error(`Copy failed: ${r.error??"unknown error"}`)},ct=()=>{d&&window.api.shell.open({as:"revealPath",path:d.path})},xt=async r=>{if(!d)return;const g=d;await m.removeLink(g.name,r)&&D(`Dead link removed from ${g.slug}`)},mt=()=>{d&&(R(d.slug),P("ask"))},ut=r=>{var g;return r?((g=c.find(S=>S.slug===r))==null?void 0:g.name)??`${r}.md`:void 0},pt=i.useMemo(()=>Rt(c),[c]),ft=i.useMemo(()=>{const r={};for(const g of c)g.clusterId&&(r[g.clusterId]=(r[g.clusterId]??0)+1);return r},[c]),Le=i.useMemo(()=>c.filter(r=>r.clusterId===null).length,[c]),ht=i.useMemo(()=>new Set(c.map(r=>r.slug)),[c]),gt=b.startsWith("cluster:")?b==="cluster:unclustered"?"Unclustered":((Re=v.find(r=>r.id===b.slice(8)))==null?void 0:Re.name)??"Cluster":{all:"All memories",stale:"Stale",broken:"Broken references",recent:"Changed this week",unindexed:"Not in index",archived:"Archived"}[b]??"All memories";let le=null;h.length===0&&(f?le={title:`${o} 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"})}:I.trim()?le={title:`No memories match “${I}”`,body:"Filter checks names and descriptions in this view.",action:"Clear filter",onAction:()=>W("")}:c.length===0&&b==="all"?le={title:`${o} has no memories yet`,body:"They appear when this subagent saves one, or add one now.",action:"+ New memory",onAction:()=>ke(Me)}:le={title:"All clear",body:b==="stale"?"Nothing is stale in this scope.":"Nothing in this view.",action:"Back to all memories",onAction:()=>P("all")});const bt=!p.autoMemoryEnabled,yt=jt.memory;return e.jsxs("div",{"data-testid":"mx-shell",className:"relative h-full flex flex-col bg-bg text-fg leading-[normal]",children:[e.jsxs("div",{className:"relative shrink-0 flex items-center gap-3 px-6 py-4 border-b border-rule-structural",children:[e.jsxs("div",{className:"flex items-baseline gap-3 pt-1",children:[e.jsx("span",{className:"text-[11px] tracking-[.08em] font-medium text-fg-dim",children:"CONFIGURE"}),e.jsx("span",{className:"font-serif text-[28px] leading-none",children:"Memory"}),e.jsx("span",{className:"text-xs text-fg-dim",children:"Claude Code's own memory files · stored on this machine"})]}),e.jsx("div",{className:"flex-1"}),e.jsxs("button",{type:"button","data-testid":"mx-search-trigger",onClick:()=>A("palette"),className:"flex items-center gap-2 h-[30px] px-2.5 border border-rule-structural rounded-md bg-bg-elev w-[300px] text-xs text-fg-dim hover:border-fg-faint",children:[e.jsx("span",{children:"Search all memories, or ask a question…"}),e.jsx("span",{className:"flex-1"}),e.jsx("span",{className:"font-mono text-[10px] px-[5px] py-px border border-rule-structural rounded-[3px] text-fg-dim",children:"/"})]}),e.jsx("button",{type:"button","data-testid":"mx-learn",onClick:()=>A(r=>r==="learn"?null:"learn"),className:`text-[11px] tracking-[.08em] font-semibold px-1 py-1.5 hover:text-fg ${q==="learn"?"text-fg":"text-accent"}`,children:"LEARN"}),q==="learn"&&e.jsxs("div",{"data-testid":"mx-learn-popover",className:`absolute right-5 top-[58px] w-[360px] ${K.dialog} bg-bg-hi border border-rule-structural rounded-lg shadow-2xl p-4 flex flex-col gap-2.5 text-[13px] leading-[1.55] text-fg`,children:[e.jsx("span",{className:"font-serif text-[17px]",children:"How memory works"}),e.jsx("span",{children:yt.intro}),e.jsx("div",{className:"flex justify-end",children:e.jsx("button",{type:"button","data-testid":"mx-learn-close",onClick:()=>A(null),className:"text-xs font-medium h-7 px-3 rounded-[5px] bg-fg text-bg",children:"Got it"})})]})]}),bt&&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 flex-1 min-h-0",children:[e.jsx(Ot,{scope:s,agents:p.agents,agentCounts:p.agentCounts,workspaceName:Ye(t),workspacePath:t??"",workspaceCount:k?x:c.length,onScope:n,view:b,onView:P,counts:pt,clusters:v,clusterCounts:ft,unclusteredCount:Le,archivedCount:p.archived.length,index:p.index}),e.jsxs("main",{className:"flex-1 min-w-0 min-h-0 flex",children:[b==="ask"&&e.jsx("div",{className:"flex-1 min-w-0",children:e.jsx(ss,{rows:c,context:ve,onClearContext:()=>R(null),onAsk:(r,g)=>m.ask(r,ut(g)),onOpen:Ne,onReverify:()=>P("stale"),onDraft:r=>ke(r)})}),b==="clusters"&&e.jsx(ns,{clusters:v,rows:c,generatedAt:p.clustersMeta.generatedAt,running:p.clustersMeta.running,unclusteredCount:Le,available:!k,onRegenerate:()=>{m.regenerateClusters()},onOpenCluster:r=>P(`cluster:${r}`),onOpen:Ne}),ae&&e.jsxs("div",{className:"flex-1 min-w-0 min-h-0 grid grid-cols-[316px_minmax(0,1fr)_236px]",children:[e.jsx(Kt,{title:gt,rows:h,clusterDot:w,selected:j,onSelect:O,query:I,onQuery:W,sort:ee,onSort:xe,onNew:()=>ke(Me),empty:le}),e.jsx("div",{className:"flex flex-col min-w-0 min-h-0",children:y==="edit"||y==="new"?e.jsx(Be,{mode:y,name:(d==null?void 0:d.slug)??null,title:$,onTitle:Q,body:V,onBody:H,onSave:()=>{st()},onCancel:nt,saving:ne,dirty:y==="new"?$.trim()!==""||V!==Me:V!==ue}):d?e.jsx(Gt,{row:d,content:G,clusterName:z(d.clusterId),clusterDot:w(d.clusterId),archived:N,mode:y,onMode:C,onEdit:tt,onCopyPath:()=>{dt()},onReveal:ct,onArchive:()=>{Ae()},onRestore:()=>{lt()},onAskDelete:()=>A("delete"),fix:U,appliedStill:X===d.slug&&d.stale,onFix:()=>{rt()},onApplyFix:()=>{at()},onDiscardFix:()=>L(B),onVerify:()=>{ot()}}):e.jsx(Be,{mode:"none",name:null,title:"",onTitle:Q,body:"",onBody:H,onSave:()=>{},onCancel:()=>{},saving:!1,dirty:!1})}),e.jsx(Qt,{row:N||y==="new"?null:d,known:ht,onOpen:et,onRemoveLink:r=>{xt(r)},onAskAbout:mt})]})]})]}),e.jsx(rs,{open:q==="palette",rows:c,clusterDot:w,onPick:Ne,onAsk:()=>{R(null),P("ask")},onClose:()=>A(null)}),e.jsx(as,{open:q==="delete"&&d!==null,name:(d==null?void 0:d.slug)??"",inbound:(d==null?void 0:d.inLinks.length)??0,onArchive:()=>{Ae()},onCancel:()=>A(null),onConfirm:()=>{it()}}),e.jsx(ls,{message:(_==null?void 0:_.message)??null,onUndo:_!=null&&_.undo?()=>{const r=_.undo;te(null),r==null||r()}:void 0,onClose:()=>te(null)})]})}function xs(){const s=Ct(),t=St();return s?e.jsx(ds,{cwd:(t==null?void 0:t.cwd)??null}):e.jsx($t,{title:"loading…"})}const ps=i.memo(xs);export{ps as Memory};
25
+ Memory file: ${r.path}`,ie=await window.api.clipboard.writeText(he);if(!ie.ok){E.error(`Copy failed: ${ie.error??"unknown error"}`);return}L(F),D("Fold copied — paste it into a New Epic")}else{const g=Ee(z);if(!await m.saveBody(r.name,Ee(me)))return;L(F),I(r.slug),D(`Applied fix to ${r.slug}`,()=>{m.saveBody(r.name,g)})}},ot=async()=>{if(!d)return;const r=d;await m.verify(r.name)&&D(`Marked ${r.slug} verified`)},Ae=async()=>{if(!d)return;const r=d;A(null),await m.archive(r.name)&&D(`Archived ${r.slug}`,()=>{m.restore(r.name)})},lt=async()=>{if(!d)return;const r=d;await m.restore(r.name)&&D(`Restored ${r.slug}`)},it=async()=>{if(!d)return;const r=d;A(null);const g=await m.remove(r.name);if(!g)return;const S=r.inLinks.length;D(`Deleted ${r.slug}${S>0?` · ${S} inbound links now broken`:""}`,()=>{g()})},dt=async()=>{if(!d)return;const r=await window.api.clipboard.writeText(d.path);r.ok?D("Path copied"):E.error(`Copy failed: ${r.error??"unknown error"}`)},ct=()=>{d&&window.api.shell.open({as:"revealPath",path:d.path})},xt=async r=>{if(!d)return;const g=d;await m.removeLink(g.name,r)&&D(`Dead link removed from ${g.slug}`)},mt=()=>{d&&(R(d.slug),P("ask"))},ut=r=>{var g;return r?((g=c.find(S=>S.slug===r))==null?void 0:g.name)??`${r}.md`:void 0},pt=i.useMemo(()=>Rt(c),[c]),ft=i.useMemo(()=>{const r={};for(const g of c)g.clusterId&&(r[g.clusterId]=(r[g.clusterId]??0)+1);return r},[c]),Le=i.useMemo(()=>c.filter(r=>r.clusterId===null).length,[c]),ht=i.useMemo(()=>new Set(c.map(r=>r.slug)),[c]),gt=b.startsWith("cluster:")?b==="cluster:unclustered"?"Unclustered":((Re=v.find(r=>r.id===b.slice(8)))==null?void 0:Re.name)??"Cluster":{all:"All memories",stale:"Stale",broken:"Broken references",recent:"Changed this week",unindexed:"Not in index",archived:"Archived"}[b]??"All memories";let le=null;h.length===0&&(f?le={title:`${o} 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"})}:T.trim()?le={title:`No memories match “${T}”`,body:"Filter checks names and descriptions in this view.",action:"Clear filter",onAction:()=>W("")}:c.length===0&&b==="all"?le={title:`${o} has no memories yet`,body:"They appear when this subagent saves one, or add one now.",action:"+ New memory",onAction:()=>ke(Me)}:le={title:"All clear",body:b==="stale"?"Nothing is stale in this scope.":"Nothing in this view.",action:"Back to all memories",onAction:()=>P("all")});const bt=!p.autoMemoryEnabled,yt=jt.memory;return e.jsxs("div",{"data-testid":"mx-shell",className:"relative h-full flex flex-col bg-bg text-fg leading-[normal]",children:[e.jsxs("div",{className:"relative shrink-0 flex items-center gap-3 px-6 py-4 border-b border-rule-structural",children:[e.jsxs("div",{className:"flex items-baseline gap-3 pt-1",children:[e.jsx("span",{className:"text-[11px] tracking-[.08em] font-medium text-fg-dim",children:"CONFIGURE"}),e.jsx("span",{className:"font-serif text-[28px] leading-none",children:"Memory"}),e.jsx("span",{className:"text-xs text-fg-dim",children:"Claude Code's own memory files · stored on this machine"})]}),e.jsx("div",{className:"flex-1"}),e.jsxs("button",{type:"button","data-testid":"mx-search-trigger",onClick:()=>A("palette"),className:"flex items-center gap-2 h-[30px] px-2.5 border border-rule-structural rounded-md bg-bg-elev w-[300px] text-xs text-fg-dim hover:border-fg-faint",children:[e.jsx("span",{children:"Search all memories, or ask a question…"}),e.jsx("span",{className:"flex-1"}),e.jsx("span",{className:"font-mono text-[10px] px-[5px] py-px border border-rule-structural rounded-[3px] text-fg-dim",children:"/"})]}),e.jsx("button",{type:"button","data-testid":"mx-learn",onClick:()=>A(r=>r==="learn"?null:"learn"),className:`text-[11px] tracking-[.08em] font-semibold px-1 py-1.5 hover:text-fg ${q==="learn"?"text-fg":"text-accent"}`,children:"LEARN"}),q==="learn"&&e.jsxs("div",{"data-testid":"mx-learn-popover",className:`absolute right-5 top-[58px] w-[360px] ${K.dialog} bg-bg-hi border border-rule-structural rounded-lg shadow-2xl p-4 flex flex-col gap-2.5 text-[13px] leading-[1.55] text-fg`,children:[e.jsx("span",{className:"font-serif text-[17px]",children:"How memory works"}),e.jsx("span",{children:yt.intro}),e.jsx("div",{className:"flex justify-end",children:e.jsx("button",{type:"button","data-testid":"mx-learn-close",onClick:()=>A(null),className:"text-xs font-medium h-7 px-3 rounded-[5px] bg-fg text-bg",children:"Got it"})})]})]}),bt&&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 flex-1 min-h-0",children:[e.jsx(Ot,{scope:s,agents:p.agents,agentCounts:p.agentCounts,workspaceName:Ge(t),workspacePath:t??"",workspaceCount:k?x:c.length,onScope:n,view:b,onView:P,counts:pt,clusters:v,clusterCounts:ft,unclusteredCount:Le,archivedCount:p.archived.length,index:p.index}),e.jsxs("main",{className:"flex-1 min-w-0 min-h-0 flex",children:[b==="ask"&&e.jsx("div",{className:"flex-1 min-w-0",children:e.jsx(ss,{rows:c,context:ve,onClearContext:()=>R(null),onAsk:(r,g)=>m.ask(r,ut(g)),onOpen:Ne,onReverify:()=>P("stale"),onDraft:r=>ke(r)})}),b==="clusters"&&e.jsx(ns,{clusters:v,rows:c,generatedAt:p.clustersMeta.generatedAt,running:p.clustersMeta.running,unclusteredCount:Le,available:!k,onRegenerate:()=>{m.regenerateClusters()},onOpenCluster:r=>P(`cluster:${r}`),onOpen:Ne}),ae&&e.jsxs("div",{className:"flex-1 min-w-0 min-h-0 grid grid-cols-[316px_minmax(0,1fr)_236px]",children:[e.jsx(Kt,{title:gt,rows:h,clusterDot:w,selected:j,onSelect:O,query:T,onQuery:W,sort:ee,onSort:xe,onNew:()=>ke(Me),empty:le}),e.jsx("div",{className:"flex flex-col min-w-0 min-h-0",children:y==="edit"||y==="new"?e.jsx(Fe,{mode:y,name:(d==null?void 0:d.slug)??null,title:$,onTitle:Q,body:V,onBody:H,onSave:()=>{st()},onCancel:nt,saving:ne,dirty:y==="new"?$.trim()!==""||V!==Me:V!==ue}):d?e.jsx(zt,{row:d,content:z,clusterName:Y(d.clusterId),clusterDot:w(d.clusterId),archived:N,mode:y,onMode:C,onEdit:tt,onCopyPath:()=>{dt()},onReveal:ct,onArchive:()=>{Ae()},onRestore:()=>{lt()},onAskDelete:()=>A("delete"),fix:U,appliedStill:X===d.slug&&d.stale,onFix:()=>{rt()},onApplyFix:()=>{at()},onDiscardFix:()=>L(F),onVerify:()=>{ot()}}):e.jsx(Fe,{mode:"none",name:null,title:"",onTitle:Q,body:"",onBody:H,onSave:()=>{},onCancel:()=>{},saving:!1,dirty:!1})}),e.jsx(Qt,{row:N||y==="new"?null:d,known:ht,onOpen:et,onRemoveLink:r=>{xt(r)},onAskAbout:mt})]})]})]}),e.jsx(rs,{open:q==="palette",rows:c,clusterDot:w,onPick:Ne,onAsk:()=>{R(null),P("ask")},onClose:()=>A(null)}),e.jsx(as,{open:q==="delete"&&d!==null,name:(d==null?void 0:d.slug)??"",inbound:(d==null?void 0:d.inLinks.length)??0,onArchive:()=>{Ae()},onCancel:()=>A(null),onConfirm:()=>{it()}}),e.jsx(ls,{message:(_==null?void 0:_.message)??null,onUndo:_!=null&&_.undo?()=>{const r=_.undo;te(null),r==null||r()}:void 0,onClose:()=>te(null)})]})}function xs(){const s=Ct(),t=St();return s?e.jsx(ds,{cwd:(t==null?void 0:t.cwd)??null}):e.jsx($t,{title:"loading…"})}const ps=i.memo(xs);export{ps as Memory};
@@ -1 +1 @@
1
- import{ap as e}from"./index-S-F5jp_h.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{al as e}from"./index-Dx8owDeQ.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,3 +1,3 @@
1
- import{aF as u,b4 as W,aY as X,b6 as Y,a_ as w,ar as q,aw as Q,al as U,ap as e,n as E,P as O,aX as J,aO as Z}from"./index-S-F5jp_h.js";import{P as I}from"./Panel-C92O_aAH.js";import{S as ee}from"./ScopeSwitcher-Dv_6M_Ci.js";import{S as te}from"./SaveBar-ob2dJJjH.js";import{P as se}from"./Library-0XYvkhh2.js";import{u as re,E as ne,s as oe}from"./settingsSchema-BZcdzHTQ.js";import{V as ae}from"./ViewTabs-C3FN6P_C.js";import"./monaco-editor-BsIlgG7c.js";import"./Button-ssBzvFha.js";import"./listSkills-C1aWKf0T.js";import"./claude-settings-schema-COigsajx.js";const ie=["allow","deny","ask"],k="This settings file has invalid JSON. Fix it in the Settings raw editor first; Permissions will not overwrite it.";function F(n){if(n.trim()==="")return{perms:{},full:{},err:null};try{const r=JSON.parse(n);if(r===null||typeof r!="object"||Array.isArray(r))return{perms:{},full:{},err:"settings file is not a JSON object"};const o=r;return{perms:o.permissions??{},full:o,err:null}}catch(r){return{perms:{},full:{},err:r.message}}}function le(n,r){const o={...n,permissions:r};return JSON.stringify(o,null,2)+`
2
- `}function ce(){const n=W(),r=X(),o=(r==null?void 0:r.cwd)??null,s=Y(t=>t.navFace),f=u.useRef(!1),i=u.useRef(s),[c,v]=u.useState(()=>s==="project"&&o?"project":"user"),[l,b]=u.useState("effective");u.useEffect(()=>{if(i.current!==s){if(i.current=s,f.current){f.current=!1;return}v(s==="project"&&o?"project":"user")}},[s,o]),u.useEffect(()=>{s==="project"&&l==="presets"&&b("effective")},[s,l]);const M=t=>{f.current=!0,v(t)},j=re(O,n,o),x=j[c]??null,y=w(t=>t.files),C=w(t=>t.setDraft),_=w(t=>t.saveJson),L=w(t=>t.revert),[T,S]=u.useState(null),R=e.jsx(ae,{options:[{key:"effective",label:"Effective"},{key:"rules",label:"Rules"},...s==="home"?[{key:"presets",label:"Presets"}]:[]],active:l,onChange:b}),$=u.useMemo(()=>{const t=q(Q(y,j));return U(t,["permissions"])??{kind:"object",children:{}}},[y,j]),V=(t,d)=>{var D;const a=j[c];if(!a)return;const{full:g,err:P}=F(((D=y[a])==null?void 0:D.draftRaw)??"");if(P){J.error(k);return}S(null);const G=Z(g.permissions??{},t,d),H={...g,permissions:G};C(a,JSON.stringify(H,null,2)+`
3
- `)};if(!n)return e.jsx(E,{title:"loading…"});if(l==="presets")return e.jsx(I,{toolbar:R,children:e.jsx(se,{})});const A=t=>t!=="user"&&!o,m=x?y[x]:null,{perms:p,full:B,err:h}=m?F(m.draftRaw):{perms:{},full:{},err:null},N=t=>{if(x){if(h){J.error(k);return}S(null),C(x,le(B,t))}},K=(t,d)=>{const a=d.trim();if(!a)return;const g=p[t]??[];g.includes(a)||N({...p,[t]:[...g,a]})},z=(t,d)=>{const a=p[t]??[];N({...p,[t]:a.filter((g,P)=>P!==d)})};return e.jsx(I,{toolbar:e.jsxs(e.Fragment,{children:[R,e.jsx("span",{className:"mx-2 text-fg-faint",children:"·"}),e.jsx(ee,{scopes:O.scopes,active:c,onChange:M,annotate:t=>{if(A(t))return{exists:!1};const d=j[t];if(!d)return null;const a=y[d];return{exists:(a==null?void 0:a.exists)??!1,dirty:(a==null?void 0:a.dirty)??!1}}}),e.jsx("span",{className:"ml-3 text-fg-faint truncate",children:x??"—"}),e.jsx("div",{className:"flex-1"}),e.jsx("a",{href:"https://code.claude.com/docs/en/settings#permissions",target:"_blank",rel:"noreferrer",className:"text-fg-faint hover:text-fg-dim underline-offset-2 hover:underline",children:"rule syntax ↗"})]}),footer:x&&m?e.jsx(te,{dirty:m.dirty,busy:m.busy,parseError:T||h||m.parseError,lastSavedAt:m.lastSavedAt,onSave:async()=>{S(null);const t=await _(x);t.ok||S(t.error??"save failed")},onRevert:()=>{S(null),L(x)}}):null,children:A(c)?e.jsx(E,{title:"no active project",hint:"open a tab in a project directory to edit project or local permissions"}):l==="effective"?e.jsx(ne,{node:$,targetScope:c,onOverride:V,schema:oe().rootedAt(["permissions"]),rootLabel:"permissions"}):x&&m?e.jsxs("div",{className:"p-4 space-y-5 max-w-3xl",children:[h&&e.jsxs("div",{role:"alert",className:"text-xs text-red-400 border border-red-400/40 rounded px-3 py-2",children:[k," (",h,")"]}),e.jsx(de,{value:p.defaultMode??"default",onChange:t=>N({...p,defaultMode:t})}),ie.map(t=>e.jsx(ue,{list:t,rules:p[t]??[],disabled:!!h,onAdd:d=>K(t,d),onRemove:d=>z(t,d)},t)),e.jsx(fe,{dirs:p.additionalDirectories??[],disabled:!!h,onChange:t=>N({...p,additionalDirectories:t})})]}):e.jsx(E,{title:"resolving…"})})}const we=u.memo(ce);function de({value:n,onChange:r}){const o=["default","acceptEdits","plan","bypassPermissions"];return e.jsxs("section",{children:[e.jsx("h3",{className:"text-xs text-fg uppercase tracking-wider mb-2",children:"Default Mode"}),e.jsx("div",{className:"inline-flex rounded border border-line overflow-hidden",children:o.map(s=>e.jsx("button",{onClick:()=>r(s),className:`px-2.5 py-1 text-xs transition-colors ${n===s?"bg-bg-hi text-fg":"bg-bg-elev text-fg-dim hover:text-fg hover:bg-bg-hi"}`,children:s},s))})]})}function ue({list:n,rules:r,onAdd:o,onRemove:s,disabled:f}){const[i,c]=u.useState(""),v=n==="allow"?"text-green-400":n==="deny"?"text-red-400":"text-yellow-400";return e.jsxs("section",{children:[e.jsx("h3",{className:`text-xs uppercase tracking-wider mb-2 ${v}`,children:n}),e.jsxs("div",{className:"flex gap-2 mb-2",children:[e.jsx("input",{value:i,disabled:f,onChange:l=>c(l.target.value),onKeyDown:l=>{l.key==="Enter"&&(o(i),c(""))},placeholder:n==="allow"?"e.g. Bash(ls:*) or Read(~/.claude/**)":"e.g. Write(/etc/**)",className:"flex-1 bg-bg-elev border border-line rounded px-2 py-1 text-xs text-fg placeholder-fg-faint"}),e.jsx("button",{onClick:()=>{o(i),c("")},disabled:f||!i.trim(),className:"px-2.5 py-1 border border-line rounded text-xs text-fg-dim hover:text-fg hover:bg-bg-hi disabled:opacity-40",children:"add"})]}),r.length===0?e.jsx("div",{className:"text-fg-faint text-xs",children:"no rules"}):e.jsx("ul",{className:"space-y-0.5",children:r.map((l,b)=>e.jsxs("li",{className:"flex items-center gap-2 text-xs font-mono bg-bg-elev border border-line rounded px-2 py-1",children:[e.jsx("span",{className:"flex-1 text-fg-dim truncate",children:l}),e.jsx("button",{onClick:()=>s(b),className:"text-fg-faint hover:text-red-400",title:"remove",children:"×"})]},`${b}-${l}`))})]})}function fe({dirs:n,onChange:r,disabled:o}){const[s,f]=u.useState("");return e.jsxs("section",{children:[e.jsx("h3",{className:"text-xs text-fg uppercase tracking-wider mb-2",children:"Additional Directories"}),e.jsx("div",{className:"flex gap-2 mb-2",children:e.jsx("input",{value:s,disabled:o,onChange:i=>f(i.target.value),onKeyDown:i=>{i.key==="Enter"&&s.trim()&&(r([...n,s.trim()]),f(""))},placeholder:"/absolute/path/to/dir",className:"flex-1 bg-bg-elev border border-line rounded px-2 py-1 text-xs text-fg placeholder-fg-faint"})}),e.jsx("ul",{className:"space-y-0.5",children:n.map((i,c)=>e.jsxs("li",{className:"flex items-center gap-2 text-xs font-mono bg-bg-elev border border-line rounded px-2 py-1",children:[e.jsx("span",{className:"flex-1 text-fg-dim truncate",children:i}),e.jsx("button",{onClick:()=>r(n.filter((v,l)=>l!==c)),className:"text-fg-faint hover:text-red-400",children:"×"})]},`${c}-${i}`))})]})}export{we as Permissions};
1
+ import{aB as u,b0 as H,aU as U,b2 as q,aW as w,an as Q,as as X,ah as Y,al as e,m as E,P as J,aT as O,aK as Z}from"./index-Dx8owDeQ.js";import{P as I}from"./Panel-xXmUBo8l.js";import{S as ee}from"./ScopeSwitcher-C6NWvzoj.js";import{S as te}from"./SaveBar-BTJg_9Uc.js";import{P as se}from"./Library-BwQ6GRHR.js";import{u as re,E as ne,s as oe}from"./settingsSchema-DaqFSAQH.js";import{V as ae}from"./ViewTabs-CuGlZ9Ed.js";import"./monaco-editor-BsIlgG7c.js";import"./Button-Dz1kV8Z_.js";import"./listSkills-C1aWKf0T.js";import"./claude-settings-schema-COigsajx.js";const ie=["allow","deny","ask"],k="This settings file has invalid JSON. Fix it in the Settings raw editor first; Permissions will not overwrite it.";function M(n){if(n.trim()==="")return{perms:{},full:{},err:null};try{const r=JSON.parse(n);if(r===null||typeof r!="object"||Array.isArray(r))return{perms:{},full:{},err:"settings file is not a JSON object"};const o=r;return{perms:o.permissions??{},full:o,err:null}}catch(r){return{perms:{},full:{},err:r.message}}}function le(n,r){const o={...n,permissions:r};return JSON.stringify(o,null,2)+`
2
+ `}function ce(){const n=H(),r=U(),o=(r==null?void 0:r.cwd)??null,s=q(t=>t.navFace),f=u.useRef(!1),i=u.useRef(s),[c,v]=u.useState(()=>s==="project"&&o?"project":"user"),[l,b]=u.useState("effective");u.useEffect(()=>{if(i.current!==s){if(i.current=s,f.current){f.current=!1;return}v(s==="project"&&o?"project":"user")}},[s,o]),u.useEffect(()=>{s==="project"&&l==="presets"&&b("effective")},[s,l]);const T=t=>{f.current=!0,v(t)},j=re(J,n,o),x=j[c]??null,y=w(t=>t.files),C=w(t=>t.setDraft),F=w(t=>t.saveJson),L=w(t=>t.revert),[_,S]=u.useState(null),R=e.jsx(ae,{options:[{key:"effective",label:"Effective"},{key:"rules",label:"Rules"},...s==="home"?[{key:"presets",label:"Presets"}]:[]],active:l,onChange:b}),$=u.useMemo(()=>{const t=Q(X(y,j));return Y(t,["permissions"])??{kind:"object",children:{}}},[y,j]),V=(t,d)=>{var D;const a=j[c];if(!a)return;const{full:g,err:P}=M(((D=y[a])==null?void 0:D.draftRaw)??"");if(P){O.error(k);return}S(null);const z=Z(g.permissions??{},t,d),G={...g,permissions:z};C(a,JSON.stringify(G,null,2)+`
3
+ `)};if(!n)return e.jsx(E,{title:"loading…"});if(l==="presets")return e.jsx(I,{toolbar:R,children:e.jsx(se,{})});const A=t=>t!=="user"&&!o,m=x?y[x]:null,{perms:p,full:B,err:h}=m?M(m.draftRaw):{perms:{},full:{},err:null},N=t=>{if(x){if(h){O.error(k);return}S(null),C(x,le(B,t))}},K=(t,d)=>{const a=d.trim();if(!a)return;const g=p[t]??[];g.includes(a)||N({...p,[t]:[...g,a]})},W=(t,d)=>{const a=p[t]??[];N({...p,[t]:a.filter((g,P)=>P!==d)})};return e.jsx(I,{toolbar:e.jsxs(e.Fragment,{children:[R,e.jsx("span",{className:"mx-2 text-fg-faint",children:"·"}),e.jsx(ee,{scopes:J.scopes,active:c,onChange:T,annotate:t=>{if(A(t))return{exists:!1};const d=j[t];if(!d)return null;const a=y[d];return{exists:(a==null?void 0:a.exists)??!1,dirty:(a==null?void 0:a.dirty)??!1}}}),e.jsx("span",{className:"ml-3 text-fg-faint truncate",children:x??"—"}),e.jsx("div",{className:"flex-1"}),e.jsx("a",{href:"https://code.claude.com/docs/en/settings#permissions",target:"_blank",rel:"noreferrer",className:"text-fg-faint hover:text-fg-dim underline-offset-2 hover:underline",children:"rule syntax ↗"})]}),footer:x&&m?e.jsx(te,{dirty:m.dirty,busy:m.busy,parseError:_||h||m.parseError,lastSavedAt:m.lastSavedAt,onSave:async()=>{S(null);const t=await F(x);t.ok||S(t.error??"save failed")},onRevert:()=>{S(null),L(x)}}):null,children:A(c)?e.jsx(E,{title:"no active project",hint:"open a tab in a project directory to edit project or local permissions"}):l==="effective"?e.jsx(ne,{node:$,targetScope:c,onOverride:V,schema:oe().rootedAt(["permissions"]),rootLabel:"permissions"}):x&&m?e.jsxs("div",{className:"p-4 space-y-5 max-w-3xl",children:[h&&e.jsxs("div",{role:"alert",className:"text-xs text-red-400 border border-red-400/40 rounded px-3 py-2",children:[k," (",h,")"]}),e.jsx(de,{value:p.defaultMode??"default",onChange:t=>N({...p,defaultMode:t})}),ie.map(t=>e.jsx(ue,{list:t,rules:p[t]??[],disabled:!!h,onAdd:d=>K(t,d),onRemove:d=>W(t,d)},t)),e.jsx(fe,{dirs:p.additionalDirectories??[],disabled:!!h,onChange:t=>N({...p,additionalDirectories:t})})]}):e.jsx(E,{title:"resolving…"})})}const we=u.memo(ce);function de({value:n,onChange:r}){const o=["default","acceptEdits","plan","bypassPermissions"];return e.jsxs("section",{children:[e.jsx("h3",{className:"text-xs text-fg uppercase tracking-wider mb-2",children:"Default Mode"}),e.jsx("div",{className:"inline-flex rounded border border-line overflow-hidden",children:o.map(s=>e.jsx("button",{onClick:()=>r(s),className:`px-2.5 py-1 text-xs transition-colors ${n===s?"bg-bg-hi text-fg":"bg-bg-elev text-fg-dim hover:text-fg hover:bg-bg-hi"}`,children:s},s))})]})}function ue({list:n,rules:r,onAdd:o,onRemove:s,disabled:f}){const[i,c]=u.useState(""),v=n==="allow"?"text-green-400":n==="deny"?"text-red-400":"text-yellow-400";return e.jsxs("section",{children:[e.jsx("h3",{className:`text-xs uppercase tracking-wider mb-2 ${v}`,children:n}),e.jsxs("div",{className:"flex gap-2 mb-2",children:[e.jsx("input",{value:i,disabled:f,onChange:l=>c(l.target.value),onKeyDown:l=>{l.key==="Enter"&&(o(i),c(""))},placeholder:n==="allow"?"e.g. Bash(ls:*) or Read(~/.claude/**)":"e.g. Write(/etc/**)",className:"flex-1 bg-bg-elev border border-line rounded px-2 py-1 text-xs text-fg placeholder-fg-faint"}),e.jsx("button",{onClick:()=>{o(i),c("")},disabled:f||!i.trim(),className:"px-2.5 py-1 border border-line rounded text-xs text-fg-dim hover:text-fg hover:bg-bg-hi disabled:opacity-40",children:"add"})]}),r.length===0?e.jsx("div",{className:"text-fg-faint text-xs",children:"no rules"}):e.jsx("ul",{className:"space-y-0.5",children:r.map((l,b)=>e.jsxs("li",{className:"flex items-center gap-2 text-xs font-mono bg-bg-elev border border-line rounded px-2 py-1",children:[e.jsx("span",{className:"flex-1 text-fg-dim truncate",children:l}),e.jsx("button",{onClick:()=>s(b),className:"text-fg-faint hover:text-red-400",title:"remove",children:"×"})]},`${b}-${l}`))})]})}function fe({dirs:n,onChange:r,disabled:o}){const[s,f]=u.useState("");return e.jsxs("section",{children:[e.jsx("h3",{className:"text-xs text-fg uppercase tracking-wider mb-2",children:"Additional Directories"}),e.jsx("div",{className:"flex gap-2 mb-2",children:e.jsx("input",{value:s,disabled:o,onChange:i=>f(i.target.value),onKeyDown:i=>{i.key==="Enter"&&s.trim()&&(r([...n,s.trim()]),f(""))},placeholder:"/absolute/path/to/dir",className:"flex-1 bg-bg-elev border border-line rounded px-2 py-1 text-xs text-fg placeholder-fg-faint"})}),e.jsx("ul",{className:"space-y-0.5",children:n.map((i,c)=>e.jsxs("li",{className:"flex items-center gap-2 text-xs font-mono bg-bg-elev border border-line rounded px-2 py-1",children:[e.jsx("span",{className:"flex-1 text-fg-dim truncate",children:i}),e.jsx("button",{onClick:()=>r(n.filter((v,l)=>l!==c)),className:"text-fg-faint hover:text-red-400",children:"×"})]},`${c}-${i}`))})]})}export{we as Permissions};