claude-code-session-manager 0.136.2 → 0.138.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/dist/assets/{AgentLibrary-CbvVbzm2.js → AgentLibrary-C1d_D7uQ.js} +1 -1
  3. package/dist/assets/{AppSettings-Blks3xh_.js → AppSettings-CgDhqrsU.js} +1 -1
  4. package/dist/assets/{Button-hPwe-y_4.js → Button-Bk23rEnZ.js} +1 -1
  5. package/dist/assets/{DocumentEditorPane-C_fgkNoa.js → DocumentEditorPane-BqY5Nq6W.js} +1 -1
  6. package/dist/assets/{Extensions-CcDjNq7W.js → Extensions-CXem-uwI.js} +2 -2
  7. package/dist/assets/{History-D4s5ykcm.js → History-BwO3coo4.js} +1 -1
  8. package/dist/assets/{Library-BtJ7gnDM.js → Library-BDV69fSe.js} +1 -1
  9. package/dist/assets/{ListDetail-Bbwwd-HR.js → ListDetail-CD-Fm6mh.js} +1 -1
  10. package/dist/assets/{Panel-8xYPYH7R.js → Panel-CeDiyuNn.js} +1 -1
  11. package/dist/assets/ProjectClaudeConfig-NjdKdwe8.js +25 -0
  12. package/dist/assets/{ProvenanceBadge-COnyY49b.js → ProvenanceBadge-Bu8NmI_R.js} +1 -1
  13. package/dist/assets/{Scheduler-CpmSitKx.js → Scheduler-CkhTvG7C.js} +1 -1
  14. package/dist/assets/{Settings-Blfjp8Bp.js → Settings-COT34hBF.js} +1 -1
  15. package/dist/assets/{SkillReferenceGraph-pYSyx841.js → SkillReferenceGraph-CFMK8NJh.js} +1 -1
  16. package/dist/assets/{Skills-C4fV80-T.js → Skills-BgexoUkQ.js} +1 -1
  17. package/dist/assets/{SourceChip-Bx9marLv.js → SourceChip-BXjcdeb1.js} +1 -1
  18. package/dist/assets/{SystemPrompt-CBvedERn.js → SystemPrompt-CeeH3EeW.js} +1 -1
  19. package/dist/assets/{TiptapBody-BV7WhKYF.js → TiptapBody-D1kTj-tn.js} +1 -1
  20. package/dist/assets/{Toggle-BUPbeHTj.js → Toggle-CENi19iK.js} +1 -1
  21. package/dist/assets/{ViewTabs-oXSVRUrm.js → ViewTabs-DDBb0x96.js} +1 -1
  22. package/dist/assets/{VoiceButton-Ca6X_WNA.js → VoiceButton-CZeyPM31.js} +1 -1
  23. package/dist/assets/{historyTotals-BcJ7QH96.js → historyTotals-B00l64Jw.js} +1 -1
  24. package/dist/assets/index-CgCxpunJ.js +3116 -0
  25. package/dist/index.html +1 -1
  26. package/dist-web/app.js +384 -384
  27. package/package.json +1 -1
  28. package/plugins/CLAUDE.md +1 -0
  29. package/plugins/session-manager-dev/.claude-plugin/plugin.json +1 -1
  30. package/plugins/session-manager-dev/skills/builder/SKILL.md +1 -0
  31. package/plugins/session-manager-dev/skills/send-feedback/SKILL.md +2 -0
  32. package/scripts/scheduler-mcp-server.cjs +46 -2
  33. package/src/main/build-info.json +4 -4
  34. package/src/main/chatRunner.cjs +51 -0
  35. package/src/main/index.cjs +13 -7
  36. package/src/main/ipcSchemas.cjs +11 -0
  37. package/src/main/lib/CLAUDE.md +2 -0
  38. package/src/main/lib/demo-video-kit/checks.cjs +16 -0
  39. package/src/main/lib/epic/epicAttachments.cjs +143 -0
  40. package/src/main/lib/epic/epicMint.cjs +4 -0
  41. package/src/main/lib/feedback-remote/crossProjectReply.cjs +58 -12
  42. package/src/main/lib/feedback-remote/localAdminHttp.cjs +14 -1
  43. package/src/main/lib/feedback-remote/macroAdminRoutes.cjs +169 -1
  44. package/src/main/lib/feedback-remote/remoteFrameAssembler.cjs +113 -0
  45. package/src/main/lib/memoryRefResolve.cjs +64 -2
  46. package/src/main/lib/memoryStale.cjs +111 -18
  47. package/src/main/lib/persona-macro/macroLibrary.cjs +7 -0
  48. package/src/main/lib/persona-macro/shippedPersonaSeeds.cjs +11 -0
  49. package/src/main/lib/process/bootStdioGuard.cjs +32 -0
  50. package/src/main/lib/process/stdioGuard.cjs +115 -0
  51. package/src/main/memoryAssist.cjs +23 -7
  52. package/src/main/memoryTool.cjs +58 -5
  53. package/src/main/promptSessionsIpc.cjs +1 -1
  54. package/src/main/templates/PRD_AUTHORING.md +3 -1
  55. package/src/preload/api.d.ts +29 -1
  56. package/src/preload/apiSurface.json +7 -0
  57. package/src/preload/index.cjs +2 -0
  58. package/src/seed/agents/demo-video-builder.md +10 -7
  59. package/dist/assets/ProjectClaudeConfig-B9PlbaSV.js +0 -25
  60. package/dist/assets/index-h8BmSc_8.js +0 -3116
@@ -1,25 +0,0 @@
1
- import{aO as o,b7 as E,ay as e,a7 as W,ak as Lt,aS as Dt,aj as Tt,L as Rt,bh as Je,b8 as et,m as ve,bm as It,C as Ot,H as _t,bb as J}from"./index-h8BmSc_8.js";import{V as Se}from"./ViewTabs-oXSVRUrm.js";import{S as de}from"./SourceChip-Bx9marLv.js";import{S as tt,M as Pt}from"./Library-BtJ7gnDM.js";import{D as Ft}from"./DocumentEditorPane-C_fgkNoa.js";import{V as Bt}from"./VoiceButton-Ca6X_WNA.js";import{Settings as Wt}from"./Settings-Blfjp8Bp.js";import{a as Kt,S as Ut}from"./Skills-C4fV80-T.js";import"./monaco-editor-BsIlgG7c.js";import"./Button-hPwe-y_4.js";import"./Panel-8xYPYH7R.js";import"./claude-settings-schema-COigsajx.js";import"./ListDetail-Bbwwd-HR.js";import"./ProvenanceBadge-COnyY49b.js";import"./Toggle-BUPbeHTj.js";function st(s){return!s||!s.trim()?"default":s.replace(/[^a-zA-Z0-9]/g,"-")}const _e=["bg-accent","bg-sage-dark","bg-honey","bg-fg-dim","bg-fg-faint","bg-hive-teal","bg-butter","bg-delta-bad"],nt=864e5,Vt="MEMORY.md",Pe=2e3,$e=s=>s.replace(/\.md$/,"");function Ht(s,t,n,l){var b,j,h;const m=new Map(((t==null?void 0:t.entries)??[]).map(a=>[a.name,a])),r=new Set(((b=t==null?void 0:t.index)==null?void 0:b.orphans)??[]),p=new Map;for(const a of(n==null?void 0:n.clusters)??[])for(const d of a.memberSlugs)p.has(d)||p.set(d,a.id);const f=s.filter(a=>a.name!==Vt),c=new Map;for(const a of f){const d=$e(a.name),u=((j=m.get(a.name))==null?void 0:j.outLinks)??((h=m.get(d))==null?void 0:h.outLinks)??[];for(const N of u){const C=$e(N),v=c.get(C)??[];v.includes(d)||v.push(d),c.set(C,v)}}return f.map(a=>{const d=$e(a.name),u=m.get(a.name)??m.get(d),N=(u==null?void 0:u.deadRefs)??[],C=(u==null?void 0:u.danglingLinks)??[],v=(u==null?void 0:u.stale)??!1;return{name:a.name,slug:d,path:a.path,description:(u==null?void 0:u.description)??"",bytes:a.bytes,mtimeMs:a.mtimeMs,ageDays:Math.floor((l-a.mtimeMs)/nt),stale:v,staleReasons:(u==null?void 0:u.reasons)??[],ageOnlyStale:v&&N.length===0,deadRefs:N,broken:N.length>0||C.length>0,danglingLinks:C,outLinks:(u==null?void 0:u.outLinks)??[],inLinks:c.get(d)??[],notIndexed:r.has(a.name)||r.has(d),clusterId:p.get(d)??null,type:(u==null?void 0:u.type)??null,originSessionId:(u==null?void 0:u.originSessionId)??null}})}function zt(s,t){const n=new Set(t.filter(l=>l.stale).map(l=>l.slug));return((s==null?void 0:s.clusters)??[]).map((l,m)=>({id:l.id,name:l.name,summary:l.summary,memberSlugs:l.memberSlugs,linkCount:l.links.length,retireCount:l.links.filter(r=>/retire/i.test(r.label??"")).length,staleCount:l.memberSlugs.filter(r=>n.has(r)).length,dotClass:_e[m%_e.length]}))}function at(s,t,n){const l=t.trim().toLowerCase(),m=l?s.filter(r=>r.slug.toLowerCase().includes(l)||r.description.toLowerCase().includes(l)):s;return n===void 0?m:m.slice(0,n)}function xe(s,t,n){let l;return t==="ask"||t==="clusters"||t==="archived"?[]:(t==="all"?l=s:t==="stale"?l=s.filter(m=>m.stale):t==="broken"?l=s.filter(m=>m.broken):t==="recent"?l=s.filter(m=>Date.now()-m.mtimeMs<=7*nt):t==="unindexed"?l=s.filter(m=>m.notIndexed):t==="cluster:unclustered"?l=s.filter(m=>m.clusterId===null):t.startsWith("cluster:")?l=s.filter(m=>m.clusterId===t.slice(8)):l=s,at(l,n))}function rt(s,t){const n=[...s];return t==="recent"?n.sort((l,m)=>m.mtimeMs-l.mtimeMs):t==="name"?n.sort((l,m)=>l.slug<m.slug?-1:l.slug>m.slug?1:0):n.sort((l,m)=>m.bytes-l.bytes),n}function Gt(s){return{all:s.length,stale:xe(s,"stale","").length,broken:xe(s,"broken","").length,recent:xe(s,"recent","").length,unindexed:xe(s,"unindexed","").length}}function ot(s){return s.toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,"")||"untitled_memory"}function Yt(s,t){const n=s===""?[]:s.split(`
2
- `),l=t===""?[]:t.split(`
3
- `);if(n.length>Pe||l.length>Pe)return[...n.map(j=>({sign:"−",text:j})),...l.map(j=>({sign:"+",text:j}))];const m=n.length,r=l.length,p=Array.from({length:m+1},()=>new Array(r+1).fill(0));for(let j=m-1;j>=0;j--)for(let h=r-1;h>=0;h--)p[j][h]=n[j]===l[h]?p[j+1][h+1]+1:Math.max(p[j+1][h],p[j][h+1]);const f=[];let c=0,b=0;for(;c<m&&b<r;)n[c]===l[b]?(c++,b++):p[c+1][b]>=p[c][b+1]?f.push({sign:"−",text:n[c++]}):f.push({sign:"+",text:l[b++]});for(;c<m;)f.push({sign:"−",text:n[c++]});for(;b<r;)f.push({sign:"+",text:l[b++]});return f}const P=s=>s instanceof Error?s.message:String(s);function Fe(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 qt(s){return s.split(`
4
- `).map(t=>t.trim()).find(t=>t.length>0)??""}function Xt(s,t){const n=s.kind==="agent"?s.agent:null,l=n?`${n.name}|${n.memoryScope??""}`:"",m=n!==null&&n.memoryScope===null,r=o.useMemo(()=>m?null:n&&n.memoryScope?{agent:{name:n.name,scope:n.memoryScope},...t?{cwd:t}:{}}:{workspace:st(t),...t?{cwd:t}:{}},[l,m,t]),p=n===null,[f,c]=o.useState(!0),[b,j]=o.useState([]),[h,a]=o.useState(null),[d,u]=o.useState(null),[N,C]=o.useState(!1),[v,S]=o.useState(""),[R,K]=o.useState(!0),[te,ue]=o.useState([]),[q,A]=o.useState([]),[U,L]=o.useState({}),[pe,ke]=o.useState(()=>Date.now()),X=o.useRef(r);X.current=r;const I=o.useCallback(async()=>{if(!r){j([]),a(null),u(null),ue([]),S(""),c(!1);return}try{const g=await window.api.memory.list(r);if(X.current!==r)return;j(g.entries??[]),S(g.dir??""),K(g.autoMemoryEnabled!==!1),g.error&&E.error(`Memory list failed: ${g.error}`);const[x,k]=await Promise.all([window.api.memory.stale(r).catch(w=>(E.error(`Memory staleness check failed: ${P(w)}`),null)),window.api.memory.listArchived(r).catch(()=>({names:[],error:null}))]);if(X.current!==r)return;a(x),ue(k.names??[]),ke(Date.now())}catch(g){E.error(`Memory list failed: ${P(g)}`)}finally{c(!1)}},[r]);o.useEffect(()=>{c(!0),u(null),I(),r&&p&&r.workspace&&window.api.memory.aggregate(r.workspace,!1,t??void 0).then(g=>{X.current===r&&u(g)}).catch(g=>E.error(`Memory clusters failed: ${P(g)}`))},[I]),o.useEffect(()=>{let g=!1;return(async()=>{try{const{agents:x}=await window.api.memory.agents(t??void 0);if(g)return;A(x);const k={};await Promise.all(x.filter(w=>w.memoryScope).map(async w=>{const G=await window.api.memory.list({agent:{name:w.name,scope:w.memoryScope},...t?{cwd:t}:{}});k[w.name]=(G.entries??[]).filter(_=>_.name!=="MEMORY.md").length})),g||L(k)}catch(x){g||E.error(`Memory agents failed: ${P(x)}`)}})(),()=>{g=!0}},[t]),o.useEffect(()=>{if(!v)return;const g=v;window.api.config.watch([g]);const x=window.api.config.onChanged(({path:k})=>{(k===g||k.startsWith(g+"/"))&&I()});return()=>{x(),window.api.config.unwatch([g])}},[v,I]);const O=o.useMemo(()=>Ht(b,h,d,pe),[b,h,d,pe]),se=o.useMemo(()=>zt(d,O),[d,O]),Ne=o.useMemo(()=>({generatedAt:(d==null?void 0:d.generatedAt)??null,running:N}),[d,N]),D=o.useCallback(async g=>{if(!r)return null;try{const x=await window.api.memory.read(g,r);return x.error?(E.error(`Memory read failed: ${x.error}`),null):x.content}catch(x){return E.error(`Memory read failed: ${P(x)}`),null}},[r]),M=o.useCallback(async(g,x)=>{try{const k=await x();return k.ok?(await I(),!0):(E.error(`${g} failed: ${k.error??"unknown error"}`),!1)}catch(k){return E.error(`${g} failed: ${P(k)}`),!1}},[I]),Q=o.useCallback(async(g,x)=>{if(!r)return!1;const k=await D(g);if(k===null)return!1;const{front:w}=Fe(k);return M("Memory save",()=>window.api.memory.write(g,w+x,r))},[r,D,M]),V=o.useCallback(async(g,x)=>{if(!r)return null;const k=ot(g),w=qt(x);if(!await M("Memory create",()=>window.api.memory.create(k,w,r)))return null;const _=`---
5
- name: ${k}
6
- description: ${w}
7
- ---
8
-
9
- ${x}
10
- `;return await M("Memory create",()=>window.api.memory.write(k,_,r))?k:null},[r,M]),H=o.useCallback(async g=>{var G,_;if(!r)return null;const x=await D(g);if(x===null||!await M("Memory delete",()=>window.api.memory.delete(g,r)))return null;const w=((_=(G=Fe(x).front.match(/^description:\s*(.*)$/m))==null?void 0:G[1])==null?void 0:_.trim())??"";return async()=>{await M("Memory undo",()=>window.api.memory.create(g,w,r))&&await M("Memory undo",()=>window.api.memory.write(g,x,r))}},[r,D,M]),fe=o.useCallback(g=>r?M("Memory archive",()=>window.api.memory.archive(g,r)):Promise.resolve(!1),[r,M]),ne=o.useCallback(g=>r?M("Memory restore",()=>window.api.memory.restore(g,r)):Promise.resolve(!1),[r,M]),ae=o.useCallback(g=>r?M("Memory verify",()=>window.api.memory.verify(g,r)):Promise.resolve(!1),[r,M]),re=o.useCallback(async(g,x)=>{if(!r)return!1;const k=await D(g);if(k===null)return!1;const w=k.split(`[[${x}]]`).join(x);return M("Memory link removal",()=>window.api.memory.write(g,w,r))},[r,D,M]),Z=o.useCallback(async()=>{if(!(!r||!p||!r.workspace)){C(!0);try{const g=await window.api.memory.aggregate(r.workspace,!0,t??void 0);g.error?E.error(`Memory clustering failed: ${g.error}`):u(g)}catch(g){E.error(`Memory clustering failed: ${P(g)}`)}finally{C(!1)}}},[r,p,t]),he=o.useCallback(async(g,x)=>{const k=w=>({ok:!1,answer:"",citations:[],error:w});if(!r)return k("no memory store");try{const w=await window.api.memory.ask({question:g,target:r,contextName:x});return w.ok||E.error(`Memory ask failed: ${w.error??"unknown error"}`),w}catch(w){return E.error(`Memory ask failed: ${P(w)}`),k(P(w))}},[r]),z=o.useCallback(async g=>{const x=k=>({ok:!1,action:"keep",summary:"",reason:"",content:"",fold:null,error:k});if(!r)return x("no memory store");try{const k=await window.api.memory.proposeFix({name:g,target:r});return k.ok||E.error(`Memory fix failed: ${k.error??"unknown error"}`),k}catch(k){return E.error(`Memory fix failed: ${P(k)}`),x(P(k))}},[r]),oe=o.useMemo(()=>({refresh:I,read:D,saveBody:Q,create:V,remove:H,archive:fe,restore:ne,verify:ae,removeLink:re,regenerateClusters:Z,ask:he,proposeFix:z}),[I,D,Q,V,H,fe,ne,ae,re,Z,he,z]);return{loading:f,target:r,dir:v,autoMemoryEnabled:R,rows:O,clusters:se,clustersMeta:Ne,index:h==null?void 0:h.index,archived:te,agents:q,agentCounts:U,actions:oe}}const Qt={user:"user — all projects",project:"project — shared via git",local:"local — this machine only"},ee="text-[10px] tracking-[.08em] font-semibold text-fg-faint",lt="flex items-center gap-2 h-7 px-2.5 rounded-[5px] text-[13px] cursor-pointer hover:bg-muteband text-left w-full";function Be(s,t){return s.memoryScope===null?"off":String(t[s.name]??0)}function Me({id:s,label:t,count:n,dot:l,active:m,mono:r,onClick:p,check:f}){return e.jsxs("button",{type:"button","data-testid":`mx-nav-${s}`,onClick:p,className:`${lt} ${m?"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 ${r?"font-mono text-xs":""}`,children:t}),n!==void 0&&e.jsx("span",{className:`font-mono text-[11px] ${f&&n===0?"text-sage-dark":m?"text-fg":"text-fg-faint"}`,children:f&&n===0?"✓":n})]})}function We({label:s,value:t,max:n,tone:l}){const m=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:`${m}%`}})})]})}const Zt=o.memo(function(t){var j,h;const[n,l]=o.useState(!1),m=o.useRef(null),r=t.scope.kind==="agent";o.useEffect(()=>{if(!n)return;const a=u=>{u.key==="Escape"&&l(!1)},d=u=>{m.current&&!m.current.contains(u.target)&&l(!1)};return document.addEventListener("keydown",a),document.addEventListener("mousedown",d),()=>{document.removeEventListener("keydown",a),document.removeEventListener("mousedown",d)}},[n]);const p=a=>{l(!1),t.onScope(a)},f=(a,d,u,N,C)=>e.jsx(Me,{id:a,label:d,dot:u,count:N,check:C,active:t.view===a,onClick:()=>t.onView(a)}),c=t.scope.kind==="agent"?t.scope.agent:null,b=(j=t.index)!=null&&j.overBudget?"bg-accent":(h=t.index)!=null&&h.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:m,className:"relative",children:[e.jsxs("button",{type:"button","data-testid":"mx-scope-card",onClick:()=>l(a=>!a),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:ee,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:Qt[c.memoryScope]})]}),n&&e.jsxs("div",{"data-testid":"mx-scope-menu",className:`absolute left-0 right-0 top-full mt-1 ${W.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(a=>e.jsxs("button",{type:"button",onClick:()=>p({kind:"agent",agent:a}),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)===a.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:a.name}),e.jsxs("span",{className:"text-[10.5px] text-fg-faint",children:["subagent",a.memoryScope?` · ${a.memoryScope}`:""]})]}),e.jsx("span",{className:"font-mono text-[11px] text-fg-faint",children:Be(a,t.agentCounts)})]},a.name))]})]}),e.jsxs("div",{className:"flex flex-col gap-px",children:[e.jsx("div",{className:`px-2.5 pb-1.5 ${ee}`,children:"BROWSE"}),f("all","All memories","",t.counts.all),f("ask","Ask",""),f("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 ${ee}`,children:"REVIEW"}),f("stale","Stale","bg-honey",t.counts.stale,!0),f("broken","Broken references","bg-accent",t.counts.broken,!0),f("recent","Changed this week","",t.counts.recent),f("unindexed","Not in index","",t.counts.unindexed,!0),t.archivedCount>0&&f("archived","Archived","",t.archivedCount)]}),!r&&e.jsxs("div",{className:"flex flex-col gap-px",children:[e.jsx("div",{className:`px-2.5 pb-1.5 ${ee}`,children:"CLUSTERS"}),t.clusters.map(a=>e.jsx(Me,{id:`cluster:${a.id}`,label:a.name,dot:a.dotClass,count:t.clusterCounts[a.id]??0,active:t.view===`cluster:${a.id}`,onClick:()=>t.onView(`cluster:${a.id}`)},a.id)),t.unclusteredCount>0&&e.jsx(Me,{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 ${ee}`,children:"SUBAGENT SCOPES"}),t.agents.map(a=>e.jsxs("button",{type:"button","data-testid":`mx-nav-agent:${a.name}`,onClick:()=>t.onScope({kind:"agent",agent:a}),className:`${lt} text-fg-dim ${(c==null?void 0:c.name)===a.name?"bg-bg font-semibold":""}`,children:[e.jsx("span",{className:"font-mono text-xs flex-1 truncate",children:a.name}),e.jsx("span",{className:"font-mono text-[11px] text-fg-faint",children:Be(a,t.agentCounts)})]},a.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:ee,children:"MEMORY.md"}),e.jsx(We,{label:"lines",value:t.index.lines,max:t.index.maxLines,tone:b}),e.jsx(We,{label:"KB",value:Math.round(t.index.bytes/1024),max:Math.round(t.index.maxBytes/1024),tone:b}),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"]})]})]})}),Jt={recent:"name",name:"size",size:"recent"},es={recent:"Recent",name:"Name",size:"Size"},Ee="text-[9.5px] font-semibold tracking-[.06em] px-[5px] py-px rounded-[3px]";function ts(s){return`${Lt(s.bytes)} · ${s.ageDays>0?`${s.ageDays}d ago`:"just now"}`}const ss=o.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(Jt[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:`${es[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:`${Ee} bg-butter/40 text-honey-dark`,children:"STALE"}),n.broken&&!n.stale&&e.jsx("span",{className:`${Ee} bg-accent-muted/30 text-accent-dark`,children:"BROKEN"}),n.notIndexed&&e.jsx("span",{className:`${Ee} bg-rule-inner text-fg-dim`,children:"NOT INDEXED"})]}),e.jsx("div",{className:"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:ts(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})]})]})]})}),Ae="text-xs font-medium h-[26px] px-2.5 border border-rule-structural rounded-[5px] bg-bg text-fg hover:border-fg",ye="px-[7px] py-0.5 rounded bg-bg-elev",je="px-2.5 py-[7px] rounded-[5px] text-left text-[12.5px] hover:bg-bg-elev",ns="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",Ke={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 as(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 rs(s){return s<1024?`${s} B`:`${(s/1024).toFixed(1)} KB`}function os(s){return s<=0?"just now":`${s}d ago`}function ls(s){const t=/^---\r?\n[\s\S]*?\r?\n---[ \t]*(?:\r?\n|$)/.exec(s);return(t?s.slice(t[0].length):s).trim()}function is(s){return s.replace(/^\*\*Why:\*\*[ \t]*/gim,`#### WHY
11
-
12
- `).replace(/^\*\*How to apply:\*\*[ \t]*/gim,`#### HOW TO APPLY
13
-
14
- `)}const cs=o.memo(function(t){const{row:n,fix:l}=t,[m,r]=o.useState(!1),p=o.useMemo(()=>t.content===null||t.mode!=="read"?"":Dt(is(ls(t.content))),[t.content,t.mode]),f=c=>()=>{r(!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:Ae,children:"Edit"}),e.jsxs("div",{className:"relative",children:[e.jsx("button",{type:"button","data-testid":"mx-reader-more",onClick:()=>r(c=>!c),className:`${Ae} !px-2`,children:"⋯"}),m&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:`fixed inset-0 ${W.dialog}`,onClick:()=>r(!1)}),e.jsxs("div",{className:`absolute right-0 top-8 w-[200px] ${W.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:je,onClick:f(t.onCopyPath),children:"Copy path"}),e.jsx("button",{type:"button",className:je,onClick:f(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:je,onClick:f(t.onArchive),children:"Archive"}),e.jsx("button",{type:"button",className:`${je} text-accent`,onClick:f(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:ye,children:["type · ",n.type]}),e.jsx("span",{className:ye,children:rs(n.bytes)}),e.jsxs("span",{className:ye,children:["modified ",os(n.ageDays)]}),n.originSessionId&&e.jsxs("span",{className:`${ye} 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:Ae,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:as(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,b)=>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})]},b))]}),l.action==="update"&&l.diff.map((c,b)=>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})]},b)),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:Ke[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:Ke[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:ns,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 ds({mode:s,name:t,title:n,onTitle:l,body:m,onBody:r,onSave:p,onCancel:f,saving:c,dirty:b}){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 j=c||s==="edit"&&!b,h=a=>{(a.metaKey||a.ctrlKey)&&a.key.toLowerCase()==="s"?(a.preventDefault(),j||p()):a.key==="Escape"&&(a.preventDefault(),f())};return e.jsxs("div",{"data-testid":"mx-editor",className:"flex-1 min-h-0 flex flex-col",onKeyDown:h,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:f,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:j,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:a=>l(a.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:["→ ",ot(n),".md"]})]}),e.jsx("textarea",{"data-testid":"mx-editor-body",value:m,onChange:a=>r(a.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.`}),b&&s==="edit"&&e.jsx("span",{className:"text-accent font-semibold",children:"unsaved"})]})]})]})}const Ue=o.memo(ds),Ve="text-[10px] tracking-[.08em] font-semibold text-fg-dim",xs="flex flex-col gap-px px-2 py-[6px] rounded-[5px] cursor-pointer bg-bg border text-left hover:border-fg-faint";function He({testid:s,slug:t,sub:n,dangling:l,onClick:m}){return e.jsxs("button",{type:"button","data-testid":s,onClick:m,className:`${xs} ${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 ms=o.memo(function({row:t,onOpen:n,onRemoveLink:l,onAskAbout:m}){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:Ve,children:["LINKS TO · ",t.outLinks.length]}),t.outLinks.map(r=>{const p=t.danglingLinks.includes(r);return e.jsx(He,{testid:`mx-link-out-${r}`,slug:r,dangling:p,sub:p?"missing · click to remove link":"wikilink",onClick:()=>p?l(r):n(r)},r)}),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:Ve,children:["LINKED FROM · ",t.inLinks.length]}),t.inLinks.map(r=>e.jsx(He,{testid:`mx-link-in-${r}`,slug:r,dangling:!1,sub:"wikilink",onClick:()=>n(r)},r)),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:m,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?"})]})]})})}),us=["What changed this week?","Find contradictions","Summarize stale memories","remember …"],ps=["Is this still accurate?","What links here?","Summarize it"],fs=/^remember\b[\s:,-]*/i,ze="text-xs font-medium h-[26px] px-2.5 rounded-[5px] bg-fg text-bg",hs=s=>s.charAt(0).toUpperCase()+s.slice(1),gs=o.memo(function({rows:t,context:n,onClearContext:l,onAsk:m,onOpen:r,onReverify:p,onDraft:f}){const[c,b]=o.useState(""),[j,h]=o.useState(!1),[a,d]=o.useState(null),u=async()=>{const v=c.trim();if(!v||j)return;if(/^remember\b/i.test(v)){d({kind:"draft",question:v,text:hs(v.replace(fs,""))}),b("");return}h(!0);let S=null;try{S=await m(v,n)}catch{S=null}h(!1),!(!S||!S.ok)&&(d({kind:"answer",question:v,answer:S.answer,citations:S.citations}),b(""))},N=(a==null?void 0:a.kind)==="answer"?a.citations.map(v=>({slug:v,row:t.find(S=>S.slug===v||S.name===v)})):[],C=N.filter(v=>{var S;return(S=v.row)==null?void 0:S.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:[!a&&!j&&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.'})]}),a&&e.jsx("div",{className:"self-end max-w-[520px] px-3.5 py-2.5 rounded-[10px] bg-fg text-bg text-[14px]",children:a.question}),(a==null?void 0:a.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:a.answer}),e.jsx("div",{className:"flex flex-wrap gap-1.5 items-center",children:N.map((v,S)=>{var R;return e.jsxs("button",{"data-testid":`mx-ask-cite-${v.slug}`,onClick:()=>{var K;return r(((K=v.row)==null?void 0:K.name)??v.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:["[",S+1,"]"]}),e.jsx("span",{children:v.slug}),v.row&&e.jsxs("span",{className:"text-fg-dim",children:[v.row.ageDays,"d"]}),((R=v.row)==null?void 0:R.stale)&&e.jsx("span",{className:"text-[9.5px] font-semibold px-1 rounded-[3px] bg-butter/40 text-honey-dark",children:"STALE"})]},v.slug)})}),C>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:[C," of these ",C===1?"is":"are"," flagged stale. Re-verify against the current code?"]}),e.jsx("button",{onClick:p,className:ze,children:"Re-verify"})]})]}),(a==null?void 0:a.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:a.text}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:()=>f(a.text),className:`${ze} 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"})]})]}),j&&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?ps:us).map(v=>e.jsx("button",{onClick:()=>b(v),className:"px-2.5 py-1 border border-rule-structural rounded-[14px] text-xs text-fg-dim hover:bg-bg-elev",children:v},v))}),e.jsxs("div",{className:"flex gap-2 items-center",children:[e.jsx("input",{"data-testid":"mx-ask-input",value:c,onChange:v=>b(v.target.value),onKeyDown:v=>{v.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(Bt,{}),e.jsx("button",{"data-testid":"mx-ask-send",onClick:()=>void u(),disabled:j,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"})]})]})]})}),Ge="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",Ye="text-[11px] text-fg-faint",bs=o.memo(function({clusters:t,rows:n,generatedAt:l,running:m,unclusteredCount:r,available:p,onRegenerate:f,onOpenCluster:c,onOpen:b}){const j=o.useMemo(()=>new Map(n.map(h=>[h.slug,h])),[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:Ge,disabled:m,onClick:f,children:m?"Generating…":"Generate"}),e.jsx("span",{className:Ye,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 ",Tt(l,Date.now())," from shared references and links"]}),e.jsx("span",{className:"flex-1"}),r>0&&e.jsxs("span",{className:"text-xs text-honey-dark px-2 py-0.5 rounded bg-butter/40",children:[r," unclustered"]}),e.jsx("button",{type:"button","data-testid":"mx-clusters-regenerate",className:Ge,disabled:m,onClick:f,children:m?"Generating…":"Regenerate"}),e.jsx("span",{className:Ye,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(h=>e.jsxs("div",{"data-testid":`mx-cluster-${h.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 ${h.dotClass}`}),e.jsx("span",{className:"font-serif text-[17px] text-fg min-w-0 flex-1",children:h.name}),e.jsxs("button",{type:"button","data-testid":`mx-cluster-open-${h.id}`,className:"text-xs text-accent hover:text-fg",onClick:()=>c(h.id),children:["Open ",h.memberSlugs.length," →"]})]}),e.jsx("span",{className:"text-[12.5px] leading-normal text-fg-dim",children:h.summary}),e.jsx("div",{className:"flex flex-wrap gap-[5px] items-center",children:h.memberSlugs.map(a=>{const d=j.get(a);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 ${d!=null&&d.stale?"bg-butter/40":"bg-bg"}`,onClick:()=>b((d==null?void 0:d.name)??`${a}.md`),children:a},a)})}),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:[h.linkCount," links"]}),e.jsxs("span",{children:[h.retireCount," retires"]}),e.jsxs("span",{className:"text-honey-dark",children:[h.staleCount," stale"]})]})]},h.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 ys({open:s,rows:t,clusterDot:n,onPick:l,onAsk:m,onClose:r}){const[p,f]=o.useState(""),[c,b]=o.useState(0);if(o.useEffect(()=>{s&&(f(""),b(0))},[s]),!s)return null;const j=at(rt(t,"recent"),p,6),h=j.length,a=u=>{u===h?m(p):l(j[u].name)},d=u=>{u.key==="ArrowDown"?(u.preventDefault(),b(N=>Math.min(N+1,h))):u.key==="ArrowUp"?(u.preventDefault(),b(N=>Math.max(N-1,0))):u.key==="Enter"?(u.preventDefault(),a(Math.min(c,h))):u.key==="Escape"&&(u.preventDefault(),r())};return e.jsxs("div",{"data-testid":"mx-palette",children:[e.jsx("div",{className:`absolute inset-0 ${W.dialog} bg-fg/30`,onClick:r}),e.jsxs("div",{className:`absolute left-1/2 top-[84px] -translate-x-1/2 w-[580px] ${W.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=>{f(u.target.value),b(0)},onKeyDown:d,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:[j.map((u,N)=>e.jsxs("div",{"data-testid":"mx-palette-row",onClick:()=>a(N),onMouseEnter:()=>b(N),className:`flex items-center gap-[9px] px-3 py-2 rounded-[6px] cursor-pointer ${N===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:()=>a(h),onMouseEnter:()=>b(h),className:`flex items-center gap-[9px] px-3 py-[10px] mt-1 border-t border-rule-inner cursor-pointer text-[13px] text-accent ${c===h?"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 Le="text-[12.5px] font-medium h-8 px-3 rounded-[5px] cursor-pointer text-fg";function js({open:s,name:t,inbound:n,onArchive:l,onCancel:m,onConfirm:r}){return o.useEffect(()=>{if(!s)return;const p=f=>{f.key==="Escape"&&m()};return document.addEventListener("keydown",p),()=>document.removeEventListener("keydown",p)},[s,m]),s?e.jsxs("div",{"data-testid":"mx-delete-dialog",children:[e.jsx("div",{className:`absolute inset-0 ${W.dialog} bg-fg/30`,onClick:m}),e.jsxs("div",{className:`absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 w-[440px] ${W.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:`${Le} border border-rule mr-auto`,children:"Archive instead"}),e.jsx("button",{type:"button",onClick:m,className:`${Le} border border-rule bg-bg`,children:"Cancel"}),e.jsx("button",{type:"button","data-testid":"mx-delete-confirm",onClick:r,className:`${Le} border-0 px-[14px] bg-accent text-white`,children:"Delete"})]})]})]}):null}const vs=6e3;function ks({message:s,onUndo:t,onClose:n}){return o.useEffect(()=>{if(s===null)return;const l=setTimeout(n,vs);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 ${W.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 it="sm.memoryTab.scope",me="agent:",De=`One-line summary of the fact or rule.
16
-
17
- **Why:**
18
-
19
- **How to apply:**`,F={state:"idle",diff:[],summary:"",action:"update",reason:"",fold:null},qe=s=>s.replace(/\.md$/,""),Xe=s=>s?s.split(/[\\/]/).filter(Boolean).pop()??s:"workspace";function Te(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 Ns(){try{const s=localStorage.getItem(it);return s&&s.startsWith(me)?s:"workspace"}catch{return"workspace"}}function ws({cwd:s}){const[t,n]=o.useState(Ns),[l,m]=o.useState([]),[r,p]=o.useState(0),f=o.useMemo(()=>{if(!t.startsWith(me))return"workspace";const h=t.slice(me.length);return l.some(a=>a.name===h)?t:"workspace"},[t,l]),c=o.useMemo(()=>{if(f==="workspace")return{kind:"workspace"};const h=l.find(a=>a.name===f.slice(me.length));return h?{kind:"agent",agent:h}:{kind:"workspace"}},[f]),b=o.useCallback(h=>{const a=h.kind==="agent"?`${me}${h.agent.name}`:"workspace";try{localStorage.setItem(it,a)}catch{}n(a)},[]),j=o.useCallback(h=>{h.length>0&&m(h)},[]);return e.jsx(Cs,{scope:c,cwd:s,onScope:b,onAgents:j,wsCount:r,onWsCount:p},f)}function Cs({scope:s,cwd:t,onScope:n,onAgents:l,wsCount:m,onWsCount:r}){var Oe;const p=Xt(s,t),{actions:f,rows:c,clusters:b}=p,j=s.kind==="agent"?s.agent:null,h=j!==null&&j.memoryScope===null,a=j?j.name:Xe(t),[d,u]=o.useState("all"),[N,C]=o.useState(null),[v,S]=o.useState("read"),[R,K]=o.useState(""),[te,ue]=o.useState("recent"),[q,A]=o.useState(null),[U,L]=o.useState(F),[pe,ke]=o.useState(""),[X,I]=o.useState(null),[O,se]=o.useState(null),[Ne,D]=o.useState(null),[M,Q]=o.useState(""),[V,H]=o.useState(""),[fe,ne]=o.useState(""),[ae,re]=o.useState(!1),[Z,he]=o.useState(null);o.useEffect(()=>{l(p.agents)},[p.agents,l]),o.useEffect(()=>{!j&&!p.loading&&r(c.length)},[j,p.loading,c.length,r]);const z=o.useMemo(()=>p.archived.map(i=>({name:i,slug:qe(i),path:`${p.dir}/${i}`,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]),oe=d!=="ask"&&d!=="clusters",g=o.useMemo(()=>{if(d==="archived"){const i=R.trim().toLowerCase();return z.filter(y=>!i||y.slug.toLowerCase().includes(i))}return rt(xe(c,d,R),te)},[d,c,z,R,te]),x=o.useMemo(()=>c.find(i=>i.name===N)??z.find(i=>i.name===N)??null,[c,z,N]),k=x!==null&&!c.some(i=>i.name===x.name),w=o.useCallback(i=>{var y;return((y=b.find($=>$.id===i))==null?void 0:y.dotClass)??"bg-rule"},[b]),G=i=>{var y;return((y=b.find($=>$.id===i))==null?void 0:y.name)??"Unclustered"},_=o.useCallback(i=>{C(i),S("read"),L(F),I(null),A(null)},[]),B=o.useCallback(i=>{u(i),K(""),A(null),L(F),S(y=>y==="edit"||y==="new"?"read":y)},[]);o.useEffect(()=>{var i;p.loading||!oe||v==="new"||x&&g.some(y=>y.name===x.name)||C(((i=g[0])==null?void 0:i.name)??null)},[p.loading,oe,v,x,g]);const le=x&&!k?x.name:null,dt=x==null?void 0:x.mtimeMs;o.useEffect(()=>{if(!le)return;let i=!0;return f.read(le).then(y=>{i&&he({name:le,text:y})}),()=>{i=!1}},[le,dt,f.read]);const Y=k?"":Z&&Z.name===le?Z.text:null;o.useEffect(()=>{const i=y=>{var be,ce;if(y.key!=="/"||y.metaKey||y.ctrlKey||y.altKey)return;const $=y.target,ge=((be=$==null?void 0:$.tagName)==null?void 0:be.toLowerCase())??"";ge==="input"||ge==="textarea"||$!=null&&$.isContentEditable||(ce=$==null?void 0:$.closest)!=null&&ce.call($,".monaco-editor")||(y.preventDefault(),A("palette"))};return document.addEventListener("keydown",i),()=>document.removeEventListener("keydown",i)},[]);const T=(i,y)=>se({message:i,undo:y}),we=(i="")=>{h||((d==="ask"||d==="clusters")&&u("all"),C(null),Q(""),H(i),ne(""),L(F),A(null),S("new"))},Ce=i=>{B("all"),_(i)},xt=i=>{const y=c.find($=>$.slug===i);y?_(y.name):E.error(`${i} is not in this scope`)},mt=()=>{if(Y===null)return;const i=Te(Y);H(i),ne(i),S("edit")},ut=async()=>{if(!ae){re(!0);try{if(v==="new"){const i=await f.create(M,V);if(!i)return;const y=i.endsWith(".md")?i:`${i}.md`;B("all"),_(y),T(`Created ${qe(y)}`)}else if(v==="edit"&&x){if(!await f.saveBody(x.name,V))return;S("read"),T(`Saved ${x.slug}`)}}finally{re(!1)}}},pt=()=>{S("read"),x||C(null)},ft=async()=>{if(!x||Y===null)return;const i=x;L({...F,state:"checking"});const y=await f.proposeFix(i.name);if(!y.ok){L(F);return}ke(y.content),L({state:"proposed",diff:y.action==="update"?Yt(Y,y.content):[],summary:y.summary,action:y.action,reason:y.reason,fold:y.fold})},ht=async()=>{if(!x||Y===null)return;const i=x;if(U.action==="delete"){if(!await f.archive(i.name))return;L(F),T(`Archived ${i.slug}`,()=>{f.restore(i.name)})}else if(U.action==="keep"){if(!await f.verify(i.name))return;L(F),T(`Marked ${i.slug} verified`)}else if(U.action==="fold"){if(!U.fold)return;const{target:y,anchor:$,insert:ge}=U.fold,be=`Fold memory ${i.slug} into ${y}.
20
- Insert after the line: ${$||"(append at end)"}
21
- ---
22
- ${ge}
23
- ---
24
- Tread lightly: add only these lines, do not restructure the doc. Once committed, archive the memory ${i.slug} from the Memory page.
25
- Memory file: ${i.path}`,ce=await window.api.clipboard.writeText(be);if(!ce.ok){E.error(`Copy failed: ${ce.error??"unknown error"}`);return}L(F),T("Fold copied — paste it into a New Epic")}else{const y=Te(Y);if(!await f.saveBody(i.name,Te(pe)))return;L(F),I(i.slug),T(`Applied fix to ${i.slug}`,()=>{f.saveBody(i.name,y)})}},gt=async()=>{if(!x)return;const i=x;await f.verify(i.name)&&T(`Marked ${i.slug} verified`)},Re=async()=>{if(!x)return;const i=x;A(null),await f.archive(i.name)&&T(`Archived ${i.slug}`,()=>{f.restore(i.name)})},bt=async()=>{if(!x)return;const i=x;await f.restore(i.name)&&T(`Restored ${i.slug}`)},yt=async()=>{if(!x)return;const i=x;A(null);const y=await f.remove(i.name);if(!y)return;const $=i.inLinks.length;T(`Deleted ${i.slug}${$>0?` · ${$} inbound links now broken`:""}`,()=>{y()})},jt=async()=>{if(!x)return;const i=await window.api.clipboard.writeText(x.path);i.ok?T("Path copied"):E.error(`Copy failed: ${i.error??"unknown error"}`)},vt=()=>{x&&window.api.shell.open({as:"revealPath",path:x.path})},kt=async i=>{if(!x)return;const y=x;await f.removeLink(y.name,i)&&T(`Dead link removed from ${y.slug}`)},Nt=()=>{x&&(D(x.slug),B("ask"))},wt=i=>{var y;return i?((y=c.find($=>$.slug===i))==null?void 0:y.name)??`${i}.md`:void 0},Ct=o.useMemo(()=>Gt(c),[c]),St=o.useMemo(()=>{const i={};for(const y of c)y.clusterId&&(i[y.clusterId]=(i[y.clusterId]??0)+1);return i},[c]),Ie=o.useMemo(()=>c.filter(i=>i.clusterId===null).length,[c]),$t=o.useMemo(()=>new Set(c.map(i=>i.slug)),[c]),Mt=d.startsWith("cluster:")?d==="cluster:unclustered"?"Unclustered":((Oe=b.find(i=>i.id===d.slice(8)))==null?void 0:Oe.name)??"Cluster":{all:"All memories",stale:"Stale",broken:"Broken references",recent:"Changed this week",unindexed:"Not in index",archived:"Archived"}[d]??"All memories";let ie=null;g.length===0&&(h?ie={title:`${a} 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"})}:R.trim()?ie={title:`No memories match “${R}”`,body:"Filter checks names and descriptions in this view.",action:"Clear filter",onAction:()=>K("")}:c.length===0&&d==="all"?ie={title:`${a} has no memories yet`,body:"They appear when this subagent saves one, or add one now.",action:"+ New memory",onAction:()=>we(De)}:ie={title:"All clear",body:d==="stale"?"Nothing is stale in this scope.":"Nothing in this view.",action:"Back to all memories",onAction:()=>B("all")});const Et=!p.autoMemoryEnabled,At=Rt.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(i=>i==="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] ${W.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:At.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"})})]})]}),Et&&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(Zt,{scope:s,agents:p.agents,agentCounts:p.agentCounts,workspaceName:Xe(t),workspacePath:t??"",workspaceCount:j?m:c.length,onScope:n,view:d,onView:B,counts:Ct,clusters:b,clusterCounts:St,unclusteredCount:Ie,archivedCount:p.archived.length,index:p.index}),e.jsxs("main",{className:"flex-1 min-w-0 min-h-0 flex",children:[d==="ask"&&e.jsx("div",{className:"flex-1 min-w-0",children:e.jsx(gs,{rows:c,context:Ne,onClearContext:()=>D(null),onAsk:(i,y)=>f.ask(i,wt(y)),onOpen:Ce,onReverify:()=>B("stale"),onDraft:i=>we(i)})}),d==="clusters"&&e.jsx(bs,{clusters:b,rows:c,generatedAt:p.clustersMeta.generatedAt,running:p.clustersMeta.running,unclusteredCount:Ie,available:!j,onRegenerate:()=>{f.regenerateClusters()},onOpenCluster:i=>B(`cluster:${i}`),onOpen:Ce}),oe&&e.jsxs("div",{className:"flex-1 min-w-0 min-h-0 grid grid-cols-[316px_minmax(0,1fr)_236px]",children:[e.jsx(ss,{title:Mt,rows:g,clusterDot:w,selected:N,onSelect:_,query:R,onQuery:K,sort:te,onSort:ue,onNew:()=>we(De),empty:ie}),e.jsx("div",{className:"flex flex-col min-w-0 min-h-0",children:v==="edit"||v==="new"?e.jsx(Ue,{mode:v,name:(x==null?void 0:x.slug)??null,title:M,onTitle:Q,body:V,onBody:H,onSave:()=>{ut()},onCancel:pt,saving:ae,dirty:v==="new"?M.trim()!==""||V!==De:V!==fe}):x?e.jsx(cs,{row:x,content:Y,clusterName:G(x.clusterId),clusterDot:w(x.clusterId),archived:k,mode:v,onMode:S,onEdit:mt,onCopyPath:()=>{jt()},onReveal:vt,onArchive:()=>{Re()},onRestore:()=>{bt()},onAskDelete:()=>A("delete"),fix:U,appliedStill:X===x.slug&&x.stale,onFix:()=>{ft()},onApplyFix:()=>{ht()},onDiscardFix:()=>L(F),onVerify:()=>{gt()}}):e.jsx(Ue,{mode:"none",name:null,title:"",onTitle:Q,body:"",onBody:H,onSave:()=>{},onCancel:()=>{},saving:!1,dirty:!1})}),e.jsx(ms,{row:k||v==="new"?null:x,known:$t,onOpen:xt,onRemoveLink:i=>{kt(i)},onAskAbout:Nt})]})]})]}),e.jsx(ys,{open:q==="palette",rows:c,clusterDot:w,onPick:Ce,onAsk:()=>{D(null),B("ask")},onClose:()=>A(null)}),e.jsx(js,{open:q==="delete"&&x!==null,name:(x==null?void 0:x.slug)??"",inbound:(x==null?void 0:x.inLinks.length)??0,onArchive:()=>{Re()},onCancel:()=>A(null),onConfirm:()=>{yt()}}),e.jsx(ks,{message:(O==null?void 0:O.message)??null,onUndo:O!=null&&O.undo?()=>{const i=O.undo;se(null),i==null||i()}:void 0,onClose:()=>se(null)})]})}function Ss(){const s=Je(),t=et();return s?e.jsx(ws,{cwd:(t==null?void 0:t.cwd)??null}):e.jsx(ve,{title:"loading…"})}const $s=o.memo(Ss);function Ms({cwd:s}){const[t,n]=o.useState(!1),[l,m]=o.useState(!1),[r,p]=o.useState(!1),[f,c]=o.useState(!1);o.useEffect(()=>{var d,u;let a=!1;return n(!1),Promise.resolve((u=(d=window.api.promptSessions)==null?void 0:d.getWorktreeDisabled)==null?void 0:u.call(d,{cwd:s})).then(N=>{a||(m((N==null?void 0:N.disabled)??!1),p((N==null?void 0:N.disabled)??!1),n(!0))},()=>{a||n(!0)}),()=>{a=!0}},[s]);const b=t&&r!==l,j=()=>{var a,d;c(!0),Promise.resolve((d=(a=window.api.promptSessions)==null?void 0:a.setWorktreeDisabled)==null?void 0:d.call(a,{cwd:s,disabled:r})).then(u=>{m((u==null?void 0:u.disabled)??r),p((u==null?void 0:u.disabled)??r)}).catch(u=>E.error(u instanceof Error?u.message:String(u))).finally(()=>c(!1))},h=()=>p(l);return e.jsxs("div",{"data-testid":"settings-epic-isolation",className:"border-b border-line bg-bg-elev px-3 py-2.5 text-[11.5px] leading-snug",children:[e.jsxs("label",{className:"flex items-start gap-2",children:[e.jsx("input",{type:"checkbox",checked:r,disabled:!t||f,onChange:a=>p(a.target.checked),"data-testid":"settings-epic-isolation-checkbox",className:"mt-0.5"}),e.jsxs("span",{children:[e.jsx("span",{className:"font-semibold text-fg",children:"Disable Epic worktree isolation for this project"}),e.jsxs("span",{className:"block text-fg-dim",children:["Off by default — each active Epic runs in its own isolated ",e.jsx("code",{children:"git worktree"})," (branch"," ",e.jsx("code",{children:"sm-epic/<id>"}),"), merged back to main at an explicit checkpoint. Turning this on makes every new Epic in this project run directly in the shared working tree instead, same as before this feature existed."]})]})]}),b&&e.jsx(tt,{dirty:b,busy:f,onSave:j,onRevert:h})]})}const ct=[{key:"memory",label:"Memory"},{key:"claude-md",label:"CLAUDE.md"},{key:"settings",label:"Settings"},{key:"mcp",label:"MCP"},{key:"skills",label:"Skills"}],Qe=[{key:"project",label:"Project"},{key:"local",label:"Local"}],Es=s=>ct.some(t=>t.key===s),As=s=>`${s}/session-manager-operations/prompt-sessions/epic-worktree-config.json`,Ls={project:{title:"Project instructions",body:"This is the real <project>/CLAUDE.md on disk, normally checked into git. The claude CLI loads it into every session started in this project, for anyone who clones it."},local:{title:"Local instructions",body:"This is the real <project>/CLAUDE.local.md on disk: your own notes for this project on this machine, kept out of git. The claude CLI loads it alongside CLAUDE.md."}},Ds="changed on disk since it was loaded. Revert reloads it",Ze=s=>s instanceof Error?s.message:String(s);function Ts(s){const[t,n]=o.useState(null);return o.useEffect(()=>{if(!s)return;let l=!0;return Promise.resolve().then(()=>window.api.memory.list({workspace:st(s),cwd:s})).then(m=>{l&&m.dir&&n({cwd:s,dir:m.dir})}).catch(()=>{}),()=>{l=!1}},[s]),t&&t.cwd===s?t.dir:null}function Rs({path:s,scope:t}){const n=J(d=>d.files[s]),l=J(d=>d.loadText),m=J(d=>d.setDraft),r=J(d=>d.saveText),p=J(d=>d.watchFile),f=J(d=>d.unwatchFile),[c,b]=o.useState(null);o.useEffect(()=>(l(s,!0).catch(d=>E.error(`Couldn't read ${s}: ${Ze(d)}`)),p(s),()=>{f(s)}),[s,l,p,f]);const j=o.useCallback(async()=>{b(null);const d=await r(s);d.ok||b(d.error==="conflict"?Ds:d.error??"save failed")},[s,r]),h=o.useCallback(()=>{b(null),l(s).catch(d=>E.error(`Couldn't read ${s}: ${Ze(d)}`))},[s,l]);if(!n)return e.jsx(ve,{title:"loading…"});const a=Ls[t];return e.jsxs("div",{"data-testid":"project-claude-md",className:"flex flex-col h-full min-h-0",children:[e.jsxs("div",{className:"shrink-0 border-b border-line bg-bg-elev px-3 py-2 text-[11.5px] leading-snug",children:[e.jsx("span",{className:"font-semibold text-fg",children:a.title}),e.jsx("span",{className:"mx-1.5 text-fg-faint",children:"·"}),e.jsx("span",{className:"text-fg-dim",children:a.body})]}),n.loadError&&e.jsx("div",{role:"alert",className:"shrink-0 border-b border-line px-3 py-1.5 text-[11px] text-red-400",children:n.loadError}),e.jsx("div",{className:"flex-1 min-h-0",children:e.jsx(Ft,{path:s,value:n.draftRaw,defaultMode:"split",onChange:d=>{b(null),m(s,d)},onSave:()=>{j()}})}),e.jsx("div",{className:"shrink-0 border-t border-line",children:e.jsx(tt,{dirty:n.dirty,busy:n.busy,parseError:c,lastSavedAt:n.lastSavedAt,leading:n.exists?null:e.jsx("span",{children:"file will be created on save"}),onSave:()=>{j()},onRevert:h})})]})}function Is({cwd:s,scope:t}){return e.jsxs("div",{className:"flex flex-col h-full min-h-0",children:[e.jsxs("div",{"data-testid":"project-claude-config-epic-isolation",className:"shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-2 border-b border-line bg-bg-elev px-3 pt-2 pb-1.5 text-[11px] text-fg-dim",children:[e.jsx("span",{className:"font-semibold text-fg",children:"Epic isolation"}),e.jsx("span",{className:"truncate",children:"Session Manager's own setting for this project, not a settings.json key"}),e.jsx(de,{path:As(s)})]}),e.jsx(Ms,{cwd:s})]}),e.jsx("div",{className:"flex-1 min-h-0",children:e.jsx(Wt,{scope:t})})]})}function Os(){var N;const s=Je(),t=((N=et())==null?void 0:N.cwd)??null,[n,l]=o.useState("memory"),[m,r]=o.useState("project"),[p,f]=o.useState("project"),[c,b]=o.useState(null),j=Ts(t),h=o.useCallback(C=>{l(C),b(null)},[]);It("memory",C=>{Es(C)&&h(C)});const a=o.useCallback(C=>b(C),[]),d=o.useCallback(()=>b(null),[]);if(!s)return e.jsx(ve,{title:"loading…"});if(!t)return e.jsx(ve,{title:"no active project",hint:"open a project tab to edit its CLAUDE.md, settings, MCP servers, skills and memory"});const u=Ot.resolve(m,s,t);return e.jsxs("div",{className:"flex flex-col h-full min-h-0","data-testid":"project-claude-config",children:[e.jsxs("div",{"data-testid":"project-claude-config-toolbar",className:"shrink-0 flex items-center gap-3 min-w-0 px-3 py-1.5 border-b border-line",children:[e.jsx(Se,{options:ct,active:n,onChange:h}),n==="claude-md"&&e.jsx(Se,{options:Qe,active:m,onChange:r}),n==="settings"&&e.jsx(Se,{options:Qe,active:p,onChange:f}),n==="memory"&&j&&e.jsx(de,{path:j,note:"Open this project's memory folder"}),n==="claude-md"&&u&&e.jsx(de,{path:u}),n==="mcp"&&e.jsx(de,{path:`${t}/.mcp.json`,keyPath:["mcpServers"]}),n==="skills"&&e.jsx(de,{path:`${t}/.claude/skills`,note:`Open ${t}/.claude/skills/`})]}),e.jsxs("div",{className:"flex-1 min-h-0",children:[n==="memory"&&e.jsx($s,{}),n==="claude-md"&&u&&e.jsx(Rs,{path:u,scope:m},u),n==="settings"&&e.jsx(Is,{cwd:t,scope:p}),n==="mcp"&&e.jsx(Kt,{scope:"project",onAdd:a}),n==="skills"&&e.jsx(Ut,{scope:"project"})]}),e.jsx(_t,{open:c!==null,onClose:d,title:"Add MCP server",keyVals:[],children:c&&e.jsx(Pt,{scope:c.scope,cwd:c.cwd})})]})}const Zs=o.memo(Os);export{Zs as ProjectClaudeConfig};