claude-code-session-manager 0.138.0 → 0.139.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 (91) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/README.md +339 -82
  3. package/dist/assets/{AppSettings-CgDhqrsU.js → AppSettings-CUfWY9vN.js} +2 -2
  4. package/dist/assets/History-DDnqaLyw.js +2 -0
  5. package/dist/assets/HomeClaudeConfig-CGD2Onjv.js +3 -0
  6. package/dist/assets/{Panel-CeDiyuNn.js → Panel-Csyd9HbD.js} +1 -1
  7. package/dist/assets/ProjectClaudeConfig-C-jlYpC_.js +26 -0
  8. package/dist/assets/{Scheduler-CkhTvG7C.js → Scheduler-NLs08fx7.js} +9 -9
  9. package/dist/assets/{SkillReferenceGraph-CFMK8NJh.js → SkillReferenceGraph-DcscPXAG.js} +1 -1
  10. package/dist/assets/Skills-BpGRKOcY.js +67 -0
  11. package/dist/assets/{TiptapBody-D1kTj-tn.js → TiptapBody-DSU3769X.js} +60 -54
  12. package/dist/assets/ViewTabs-C0PRZx4_.js +1 -0
  13. package/dist/assets/{VoiceButton-CZeyPM31.js → VoiceButton-D2rMurNg.js} +1 -1
  14. package/dist/assets/{historyTotals-B00l64Jw.js → historyTotals-TcIQs2sh.js} +1 -1
  15. package/dist/assets/{index-62tyjEQB.css → index-BCySPdtU.css} +1 -1
  16. package/dist/assets/{index-CgCxpunJ.js → index-C-d0DCre.js} +523 -515
  17. package/dist/index.html +2 -2
  18. package/dist-web/app.css +1 -1
  19. package/dist-web/app.js +469 -450
  20. package/package.json +13 -5
  21. package/plugins/session-manager-dev/.claude-plugin/plugin.json +1 -1
  22. package/plugins/session-manager-dev/skills/builder/SKILL.md +12 -4
  23. package/plugins/session-manager-dev/skills/builder/scripts/publish-preflight.cjs +255 -0
  24. package/plugins/session-manager-dev/skills/develop/SKILL.md +12 -5
  25. package/scripts/README.md +1 -0
  26. package/scripts/scheduler-mcp-server.cjs +161 -18
  27. package/src/main/build-info.json +4 -4
  28. package/src/main/chatRunner.cjs +2 -2
  29. package/src/main/exchanges.cjs +70 -5
  30. package/src/main/historyAggregator.cjs +84 -58
  31. package/src/main/historyDashboard.cjs +18 -13
  32. package/src/main/index.cjs +22 -2
  33. package/src/main/ipcSchemas.cjs +122 -5
  34. package/src/main/lib/claude/effectiveModelInfo.cjs +2 -2
  35. package/src/main/lib/claude/modelPricing.cjs +148 -0
  36. package/src/main/lib/epic/epicAdminRoutes.cjs +101 -0
  37. package/src/main/lib/epic/epicJobReceipt.cjs +87 -0
  38. package/src/main/lib/epic/epicOutsideRead.cjs +306 -0
  39. package/src/main/lib/epic/epicOutsideState.cjs +233 -0
  40. package/src/main/lib/epic/epicSettle.cjs +1 -1
  41. package/src/main/lib/epic/epicStateWatcher.cjs +157 -0
  42. package/src/main/lib/epic/externalRef.cjs +37 -0
  43. package/src/main/lib/epic/externalRefIndex.cjs +136 -0
  44. package/src/main/lib/epic/restorableSessions.cjs +151 -17
  45. package/src/main/lib/epic/transcriptUsage.cjs +197 -0
  46. package/src/main/lib/externalContract.cjs +111 -0
  47. package/src/main/lib/feedback-remote/crossProjectFeedback.cjs +121 -4
  48. package/src/main/lib/feedback-remote/crossProjectReply.cjs +83 -1
  49. package/src/main/lib/feedback-remote/customerFeedbackAdminRoutes.cjs +16 -6
  50. package/src/main/lib/feedback-remote/customerFeedbackClient.cjs +50 -8
  51. package/src/main/lib/feedback-remote/customerFeedbackInbox.cjs +218 -4
  52. package/src/main/lib/feedback-remote/customerFeedbackIpc.cjs +19 -3
  53. package/src/main/lib/feedback-remote/feedbackImages.cjs +171 -0
  54. package/src/main/lib/feedback-remote/localAdminHttp.cjs +11 -10
  55. package/src/main/lib/feedback-remote/macroAdminRoutes.cjs +120 -2
  56. package/src/main/lib/feedback-remote/needsYouAdminRoutes.cjs +133 -0
  57. package/src/main/lib/feedback-remote/needsYouIpc.cjs +50 -0
  58. package/src/main/lib/feedback-remote/needsYouStore.cjs +281 -0
  59. package/src/main/lib/historyRollup.cjs +32 -5
  60. package/src/main/lib/mcpToolCatalog.cjs +111 -14
  61. package/src/main/lib/persona-macro/agentAdminRoutes.cjs +121 -0
  62. package/src/main/lib/promptSessionSchema.cjs +4 -0
  63. package/src/main/lib/remoteTranscriptTail.cjs +32 -1
  64. package/src/main/lib/scheduler/schedulerPaths.cjs +9 -0
  65. package/src/main/lib/telemetry/auditEvents.cjs +176 -0
  66. package/src/main/lib/telemetry/eventsAdminRoutes.cjs +45 -0
  67. package/src/main/loopEfficiencyHandlers.cjs +1 -1
  68. package/src/main/scheduler.cjs +29 -0
  69. package/src/main/templates/PRD_AUTHORING.md +1 -0
  70. package/src/main/transcripts.cjs +62 -7
  71. package/src/main/webRemote.cjs +122 -18
  72. package/src/preload/api.d.ts +71 -8
  73. package/src/preload/apiSurface.cjs +7 -0
  74. package/src/preload/apiSurface.json +408 -83
  75. package/src/preload/index.cjs +15 -3
  76. package/dist/assets/AgentLibrary-C1d_D7uQ.js +0 -2
  77. package/dist/assets/Button-Bk23rEnZ.js +0 -1
  78. package/dist/assets/DocumentEditorPane-BqY5Nq6W.js +0 -1
  79. package/dist/assets/Extensions-CXem-uwI.js +0 -2
  80. package/dist/assets/History-BwO3coo4.js +0 -2
  81. package/dist/assets/Library-BDV69fSe.js +0 -32
  82. package/dist/assets/ListDetail-CD-Fm6mh.js +0 -1
  83. package/dist/assets/ProjectClaudeConfig-NjdKdwe8.js +0 -25
  84. package/dist/assets/ProvenanceBadge-Bu8NmI_R.js +0 -1
  85. package/dist/assets/Settings-COT34hBF.js +0 -2
  86. package/dist/assets/Skills-BgexoUkQ.js +0 -29
  87. package/dist/assets/SourceChip-BXjcdeb1.js +0 -1
  88. package/dist/assets/SystemPrompt-CeeH3EeW.js +0 -1
  89. package/dist/assets/Toggle-CENi19iK.js +0 -1
  90. package/dist/assets/ViewTabs-DDBb0x96.js +0 -1
  91. package/dist/assets/claude-settings-schema-COigsajx.js +0 -3
@@ -1,2 +1,2 @@
1
- import{ay as e,w as Ae,o as Me,bv as P,aO as o,as as Le,Z as Oe,u as De,aB as oe,D as $e,aA as _e,a2 as le,a1 as de,a3 as V,aY as He,a0 as Be,m as G,a4 as Fe,ac as Ue,b7 as he,$ as ze,b as H,bu as ee,c as L,ba as We,bm as Je,A as Ve,a6 as Ge,bh as qe,bd as Ye,e as Xe,aP as Ke,bz as Ze}from"./index-CgCxpunJ.js";import{V as xe}from"./ViewTabs-DDBb0x96.js";import{S as Qe}from"./SourceChip-BXjcdeb1.js";import{T as D}from"./Toggle-CENi19iK.js";import{V as et,T as tt}from"./VoiceButton-CZeyPM31.js";import{P as nt}from"./Panel-CeDiyuNn.js";import"./monaco-editor-BsIlgG7c.js";function st({open:t,onClose:n,title:s,children:r,variant:i="overlay"}){return e.jsxs(Ae,{open:t,onClose:n,size:"xl",fillHeight:!0,noPadding:!0,title:void 0,variant:i,children:[i==="overlay"&&e.jsxs("div",{className:"flex items-center justify-between px-4 py-2 border-b border-line shrink-0",children:[e.jsx("h2",{className:"text-xs uppercase tracking-wider text-fg-dim",children:s}),e.jsx("button",{type:"button",onClick:n,"aria-label":"Close",className:"px-2 py-0.5 text-fg-dim hover:text-fg hover:bg-bg-hi rounded text-base leading-none",children:"✕"})]}),e.jsx("div",{className:"flex-1 min-h-0 overflow-auto",children:e.jsx(Me,{children:r})})]})}function at(){const t=P(g=>g.isRecording),n=P(g=>g.levelMeterEnabled),[s,r]=o.useState(0),[i,a]=o.useState(0),d=o.useRef(0);d.current=i;const[u,y]=o.useState(0),[p,f]=o.useState(!1),m=o.useRef(null);if(o.useEffect(()=>{if(!t||!n){r(0),a(0);return}let g=0,j=!1,v=null,N=null;const S=()=>{if(j)return;const w=N??Le();if(!w){g=requestAnimationFrame(S);return}N!==w&&(N=w,v=new Uint8Array(new ArrayBuffer(w.fftSize)));const C=v;w.getByteTimeDomainData(C);let T=0;for(let R=0;R<C.length;R++){const F=C[R]-128;T+=F*F}const E=Math.sqrt(T/C.length)/128,b=E>0?20*Math.log10(E):-60,k=Math.max(0,Math.min(1,(b+60)/60));a(E),r(k),E>=.95&&(f(!0),m.current&&clearTimeout(m.current),m.current=setTimeout(()=>f(!1),150)),g=requestAnimationFrame(S)};g=requestAnimationFrame(S);const h=setInterval(()=>{j||y(Math.round(d.current*100))},250);return()=>{j=!0,cancelAnimationFrame(g),clearInterval(h),m.current&&(clearTimeout(m.current),m.current=null)}},[t,n]),!t||!n)return null;const c=p?"bg-red-500":i>=.7?"bg-amber-400":"bg-green-500";return e.jsx("div",{role:"meter","aria-label":"Microphone input level","aria-valuenow":u,"aria-valuemin":0,"aria-valuemax":100,"data-testid":"mic-level-meter",className:`mx-3 mb-2 h-1 rounded bg-bg overflow-hidden ${p?"ring-1 ring-red-500":""}`,children:e.jsx("div",{className:`h-full ${c} transition-[width] duration-75 ease-out`,style:{width:`${s*100}%`}})})}function rt({open:t,onClose:n,variant:s="overlay"}){return e.jsx(st,{open:t,onClose:n,title:"Voice / Microphone",variant:s,children:e.jsxs("div",{className:"p-4 space-y-4",children:[e.jsx(dt,{}),e.jsx(Oe,{}),e.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[e.jsx(et,{}),e.jsx(De,{}),e.jsx(tt,{})]}),e.jsx(it,{}),e.jsxs("div",{className:"flex items-center gap-4 flex-wrap",children:[e.jsx("button",{type:"button",onClick:()=>P.getState().openWizard(),className:"text-xs text-fg-faint hover:text-fg-dim underline","data-testid":"run-mic-check",children:"Run mic check"}),e.jsx(lt,{})]}),e.jsx(at,{})]})})}function it(){const t=P(a=>a.isRecording),[n,s]=o.useState(null);if(o.useEffect(()=>{let a=!1;window.api.voice.getHotkeyConfig().then(u=>{a||s(u)}).catch(()=>{});const d=window.api.voice.onHotkeyConfigChanged(u=>s(u));return()=>{a=!0,d()}},[]),t||!n)return null;const r=n.mode==="hold"?"Hold":"Press",i=ot(n.accelerator);return e.jsxs("div",{className:"text-[11px] text-fg-faint",children:[e.jsxs("span",{children:[r," "]}),e.jsx("kbd",{className:"px-1 py-0.5 rounded border border-line bg-bg font-mono text-fg-dim",children:i}),e.jsx("span",{children:" to record"})]})}function ot(t){const n=typeof navigator<"u"&&/Mac/.test(navigator.platform);return t.replace(/CommandOrControl/g,n?"⌘":"Ctrl").replace(/CmdOrCtrl/g,n?"⌘":"Ctrl").replace(/Command/g,"⌘").replace(/Control/g,"Ctrl").replace(/Option/g,n?"⌥":"Alt").replace(/Shift/g,n?"⇧":"Shift")}function lt(){const[t,n]=o.useState(null);if(o.useEffect(()=>{let r=!1;window.api.voice.getHotkeyConfig().then(a=>{r||n(a)}).catch(a=>oe.warn("voice-hotkey","getHotkeyConfig (toggle) failed",{error:String(a)}));const i=window.api.voice.onHotkeyConfigChanged(a=>{n(a)});return()=>{r=!0,i()}},[]),!t)return null;const s=async r=>{if(t.mode===r)return;const i={...t,mode:r};n(i);try{await window.api.voice.setHotkeyConfig(i)}catch(a){oe.warn("voice-hotkey","setHotkeyConfig (toggle) failed",{error:a instanceof Error?a.message:String(a)})}};return e.jsxs("div",{className:"flex items-center gap-3 text-[11px] text-fg-faint select-none",title:"Mic hotkey behavior. Tap on/off: press once to start, again to stop. Hold to talk: record only while held (push-to-talk).",children:[e.jsxs("label",{className:"flex items-center gap-1 cursor-pointer hover:text-fg-dim",children:[e.jsx("input",{type:"radio",name:"hotkey-mode",checked:t.mode==="toggle",onChange:()=>s("toggle"),className:"cursor-pointer","data-testid":"hotkey-mode-toggle"}),e.jsx("span",{children:"Tap on/off"})]}),e.jsxs("label",{className:"flex items-center gap-1 cursor-pointer hover:text-fg-dim",children:[e.jsx("input",{type:"radio",name:"hotkey-mode",checked:t.mode==="hold",onChange:()=>s("hold"),className:"cursor-pointer","data-testid":"hotkey-mode-hold"}),e.jsx("span",{children:"Hold to talk"})]})]})}function dt(){const t=P(a=>a.isRecording),n=P(a=>a.lastTranscript),s=P(a=>a.error),r=P(a=>a.modelStatus),i=P(a=>a.loadingProgress);return s?e.jsxs("div",{className:"text-[11px] text-red-400",title:s,children:["⚠ ",s]}):t?e.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-fg-dim border border-line rounded px-2 py-1.5",children:[e.jsx("span",{className:"inline-block w-2 h-2 rounded-full bg-red-400 animate-pulse shrink-0"}),e.jsx("span",{className:"truncate",title:n,children:n||"Listening…"})]}):r==="loading"?e.jsxs("div",{className:"text-[11px] text-fg-faint",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("span",{children:"Loading speech model"}),e.jsxs("span",{className:"font-mono",children:[i,"%"]})]}),e.jsx("div",{className:"h-1 rounded bg-bg overflow-hidden",children:e.jsx("div",{className:"h-full bg-accent transition-[width] duration-200",style:{width:`${i}%`}})})]}):null}const ct=["dark","light","paper"];function pt(){const[t,n]=o.useState($e),[s,r]=o.useState(!1);o.useEffect(()=>{let d=!1;return _e().then(u=>{d||(n(u),r(!0))}),()=>{d=!0}},[]);const i=d=>{s&&n(u=>{const y={...u,...d};return He(y),y})},a=d=>{i({fontSize:Math.min(de,Math.max(le,t.fontSize+d))})};return e.jsxs("section",{className:"mb-6","data-testid":"home-terminal-appearance",children:[e.jsxs("div",{className:"flex items-baseline justify-between mb-3",children:[e.jsx("h2",{className:"m-0 font-serif text-[22px] font-medium",children:"Terminal appearance"}),e.jsx("span",{className:"font-mono text-[12px] text-fg-faint",children:"every terminal, this machine"})]}),e.jsxs("div",{className:"border border-line rounded-xl bg-bg-hi px-5 py-4",children:[e.jsxs("p",{className:"mt-0 mb-4 text-[13px] text-fg-dim leading-relaxed",children:["Applies to ",e.jsx("strong",{className:"text-fg",children:"every terminal in the app at once"})," — project Terminal tabs, an Epic’s Terminal view of its session, and the inline permission prompt. It is not per project, per session, or per tab. It does not restyle the app chrome (there is no app theme switch), and the code editor keeps its own separate paper/dark setting in the Editor tab’s Display menu. Stored in"," ",e.jsx("code",{className:"font-mono text-[12px]",children:"~/.claude/session-manager/ui-settings-prefs.json"}),", applied live without restarting a session."]}),e.jsxs("div",{className:"grid gap-5",style:{gridTemplateColumns:"minmax(0,1fr) 220px"},children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wider text-fg-faint mb-1.5",children:"Theme"}),e.jsx("div",{className:"grid grid-cols-3 gap-2",children:ct.map(d=>e.jsxs("button",{type:"button",onClick:()=>i({theme:d}),disabled:!s,"aria-pressed":t.theme===d,"data-testid":`terminal-theme-${d}`,className:`px-2 py-2 rounded-lg text-[11px] font-medium border transition-colors disabled:opacity-40 disabled:cursor-not-allowed ${t.theme===d?"bg-bg border-accent text-fg":"bg-bg border-line text-fg-dim hover:text-fg hover:border-fg-faint"}`,children:[e.jsx(mt,{theme:d}),e.jsx("div",{className:"mt-1.5 capitalize",children:d})]},d))})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[e.jsx("span",{className:"text-[10px] uppercase tracking-wider text-fg-faint",children:"Font size"}),e.jsxs("span",{className:"font-mono text-[11px] text-fg-dim",children:[t.fontSize,"px"]})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("button",{type:"button",onClick:()=>a(-1),disabled:!s||t.fontSize<=le,"aria-label":"Decrease font size",className:"flex-1 py-1.5 rounded border border-line bg-bg text-fg-dim hover:text-fg hover:border-fg-faint disabled:opacity-40 disabled:cursor-not-allowed",children:"−"}),e.jsx("button",{type:"button",onClick:()=>i({fontSize:Be}),disabled:!s,className:"flex-1 py-1.5 rounded border border-line bg-bg text-[11px] text-fg-dim hover:text-fg hover:border-fg-faint disabled:opacity-40 disabled:cursor-not-allowed",children:"reset"}),e.jsx("button",{type:"button",onClick:()=>a(1),disabled:!s||t.fontSize>=de,"aria-label":"Increase font size",className:"flex-1 py-1.5 rounded border border-line bg-bg text-fg-dim hover:text-fg hover:border-fg-faint disabled:opacity-40 disabled:cursor-not-allowed",children:"+"})]}),e.jsxs("div",{className:"mt-3 rounded border border-line px-3 py-2 font-mono",style:{background:V[t.theme].background,color:V[t.theme].foreground,fontSize:`${t.fontSize}px`,lineHeight:1.35},"aria-hidden":!0,children:[e.jsx("span",{style:{color:V[t.theme].green},children:"$"})," claude"]})]})]})]})]})}function mt({theme:t}){const n=V[t];return e.jsxs("div",{"aria-hidden":!0,className:"w-full h-5 rounded border relative overflow-hidden",style:{background:n.background,borderColor:"rgba(0,0,0,0.15)"},children:[e.jsx("div",{style:{position:"absolute",top:3,left:4,width:"40%",height:2,background:n.foreground}}),e.jsx("div",{style:{position:"absolute",top:9,left:4,width:"25%",height:2,background:n.green??n.foreground}}),e.jsx("div",{style:{position:"absolute",top:15,left:4,width:"55%",height:2,background:n.cyan??n.foreground}})]})}const ut=1440*60*1e3;function ft(t){if(!t)return"never";const n=new Date(t).getTime();return Number.isNaN(n)?"never":new Date(n).toLocaleString()}function ce(t){return t?new Date(t).toLocaleString():"never"}function gt(){return e.jsxs("div",{className:"p-4 max-w-3xl space-y-8 text-sm",children:[e.jsx(ht,{}),e.jsx("hr",{className:"border-line"}),e.jsx(xt,{})]})}function ht(){const[t,n]=o.useState(null),[s,r]=o.useState(null),[i,a]=o.useState(null),[d,u]=o.useState(null),[y,p]=o.useState(!1),[f,m]=o.useState(null),[c,g]=o.useState(null);if(o.useEffect(()=>{let h=!1;return Promise.all([window.api.otel.getConfig(),window.api.otel.status(),window.api.otel.configPath()]).then(([w,C,T])=>{h||(n(w),a(w),r(C),u(T))}).catch(w=>{console.warn("[telemetry] load failed:",w==null?void 0:w.message)}),()=>{h=!0}},[]),!i||!t)return e.jsx(G,{title:"loading…"});const j=JSON.stringify(i)!==JSON.stringify(t),v=(h,w)=>{m(null),a({...i,[h]:w})},N=async()=>{p(!0),m(null);try{const h=await window.api.otel.setConfig(i);!h.ok&&h.error&&m(h.error),n(h.config),a(h.config),r(h.status),g(Date.now())}catch(h){m(h instanceof Error?h.message:String(h))}finally{p(!1)}},S=()=>{m(null),a(t)};return e.jsxs("div",{className:"space-y-5",children:[e.jsxs("header",{className:"space-y-1",children:[e.jsx("h2",{className:"text-fg text-base font-medium",children:"OpenTelemetry export"}),e.jsx("p",{className:"text-fg-dim text-xs leading-relaxed",children:"When enabled, every classified transcript event (tool_use, todo_write, plan, usage, agent_spawn) is mirrored as a 0-duration OTLP/HTTP span. Point this at a local collector (Jaeger, Grafana Tempo, SigNoz, Honeycomb) for cross-session analysis."}),d&&e.jsxs("p",{className:"text-fg-faint text-[11px]",children:["stored at ",e.jsx("span",{className:"font-mono",children:d})]})]}),e.jsxs("section",{className:"border border-line rounded p-3 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-fg",children:"Export transcripts to OTEL"}),e.jsx("div",{className:"text-fg-faint text-xs",children:"Toggle off to disable all span emission immediately."})]}),e.jsx(D,{checked:i.enabled,onChange:h=>v("enabled",h),label:i.enabled?"on":"off"})]}),e.jsxs("label",{className:"block space-y-1",children:[e.jsx("span",{className:"text-fg-dim text-xs",children:"OTLP/HTTP traces endpoint"}),e.jsx("input",{type:"text",value:i.endpoint,onChange:h=>v("endpoint",h.target.value),placeholder:"http://localhost:4318/v1/traces",className:"w-full bg-bg border border-line rounded px-2 py-1 text-fg font-mono text-xs"})]}),e.jsxs("label",{className:"block space-y-1",children:[e.jsxs("span",{className:"text-fg-dim text-xs",children:["Headers (newline-separated ",e.jsx("span",{className:"font-mono",children:"Key: Value"}),")"]}),e.jsx("textarea",{value:i.headers,onChange:h=>v("headers",h.target.value),placeholder:"x-honeycomb-team: YOUR_API_KEY",rows:3,className:"w-full bg-bg border border-line rounded px-2 py-1 text-fg font-mono text-xs"})]}),e.jsxs("label",{className:"block space-y-1",children:[e.jsx("span",{className:"text-fg-dim text-xs",children:"Service name"}),e.jsx("input",{type:"text",value:i.serviceName,onChange:h=>v("serviceName",h.target.value),placeholder:"session-manager",className:"w-full bg-bg border border-line rounded px-2 py-1 text-fg font-mono text-xs"})]}),e.jsxs("div",{className:"flex items-start justify-between gap-3 pt-1",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-fg",children:"Include content (PII)"}),e.jsxs("div",{className:"text-fg-faint text-xs leading-relaxed",children:["Adds tool inputs, plan text, and agent prompts to span attributes. Off by default — matches upstream Claude Code's ",e.jsx("span",{className:"font-mono",children:"OTEL_LOG_USER_PROMPTS"})," opt-in."]})]}),e.jsx(D,{checked:i.includeContent,onChange:h=>v("includeContent",h),label:i.includeContent?"on":"off"})]})]}),s&&e.jsxs("section",{className:"border border-line rounded p-3 text-xs space-y-1",children:[e.jsx("div",{className:"text-fg-dim",children:"Runtime status"}),e.jsxs("div",{children:[e.jsx("span",{className:"text-fg-faint",children:"enabled:"})," ",e.jsx("span",{className:s.enabled?"text-accent":"text-fg-dim",children:String(s.enabled)})]}),s.error&&e.jsxs("div",{className:"text-red-400 break-words",children:[e.jsx("span",{className:"text-fg-faint",children:"error:"})," ",s.error]}),!s.error&&s.enabled&&e.jsx("div",{className:"text-fg-faint",children:"spans batched and exported in the background. Verify by enabling and pointing at a local Jaeger."})]}),e.jsxs("footer",{className:"flex items-center gap-3 pt-2 border-t border-line",children:[e.jsx("button",{onClick:N,disabled:!j||y,className:"px-3 py-1 text-xs rounded bg-accent text-bg disabled:opacity-50 disabled:cursor-not-allowed",children:y?"saving…":"Save"}),e.jsx("button",{onClick:S,disabled:!j||y,className:"px-3 py-1 text-xs rounded border border-line text-fg-dim hover:text-fg disabled:opacity-50 disabled:cursor-not-allowed",children:"Revert"}),f&&e.jsx("span",{className:"text-red-400 text-xs",children:f}),!f&&c&&!j&&e.jsx("span",{className:"text-fg-faint text-xs",children:"saved"})]})]})}function xt(){const[t,n]=o.useState(null),[s,r]=o.useState(null),[i,a]=o.useState("Copy"),[d,u]=o.useState(!1),[y,p]=o.useState(null),[f,m]=o.useState(null),[c,g]=o.useState(null),[j,v]=o.useState(!1),N=()=>{window.api.telemetry.status().then(r).catch(b=>{console.warn("[product-telemetry] status reload failed:",b==null?void 0:b.message)})};if(o.useEffect(()=>{let b=!1;return Promise.all([window.api.telemetry.getConfig(),window.api.telemetry.status()]).then(([k,R])=>{b||(n(k),r(R))}).catch(k=>{console.warn("[product-telemetry] load failed:",k==null?void 0:k.message)}),()=>{b=!0}},[]),!t||!s)return e.jsx(G,{title:"loading…"});const S=async b=>{m(null);try{const k=await window.api.telemetry.setConfig(b);n(k.config),r(k.status),window.dispatchEvent(new CustomEvent(ze,{detail:k.config}))}catch(k){m(k instanceof Error?k.message:String(k))}},h=b=>{S({...t,enabled:b})},w=async()=>{await Ue(t.installId)?(a("Copied"),setTimeout(()=>a("Copy"),1500)):he.error("Could not copy install id to the clipboard")},C=async()=>{u(!0),p(null);try{const b=await window.api.telemetry.flushNow();p(`sent ${b.sent.length}, failed ${b.failed.length}`),N()}catch(b){p(b instanceof Error?b.message:String(b))}finally{u(!1)}},T=async()=>{if(j){v(!1);return}try{const b=await window.api.telemetry.recentRecords();g(b),v(!0)}catch(b){console.warn("[product-telemetry] recentRecords failed:",b instanceof Error?b.message:b)}},E=t.lastDailyFlushAt?new Date(t.lastDailyFlushAt).getTime()+ut:null;return e.jsxs("div",{className:"space-y-5","data-testid":"product-telemetry-section",children:[e.jsxs("header",{className:"space-y-1",children:[e.jsx("h2",{className:"text-fg text-base font-medium",children:"Product telemetry (bilko.run)"}),e.jsxs("p",{className:"text-fg-dim text-xs leading-relaxed",children:["Anonymous, strictly non-identifying usage/error reporting that helps improve this app. On by default; switchable off in one click. See"," ",e.jsx("span",{className:"font-mono",children:"session-manager-operations/architecture/telemetry.md"})," for the full data model."]})]}),e.jsx(Fe,{cfg:t,onSaved:(b,k)=>{n(b),r(k)}}),e.jsxs("section",{className:"border border-line rounded p-3 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-fg",children:"Send anonymous product telemetry"}),e.jsx("div",{className:"text-fg-faint text-xs",children:"Sent on start-up, after an update, and once a day. Strictly anonymous — an install id only, never an email, name, or other identifier."})]}),e.jsx(D,{checked:t.enabled,onChange:h,label:t.enabled?"on":"off"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"text-fg-dim text-xs",children:"Anonymous install id"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"text",readOnly:!0,value:t.installId,"aria-label":"Anonymous install identifier",className:"flex-1 bg-bg border border-line rounded px-2 py-1 text-fg font-mono text-xs"}),e.jsx("button",{onClick:w,className:"px-2 py-1 text-xs rounded border border-line text-fg-dim hover:text-fg",children:i})]})]}),e.jsxs("div",{className:"space-y-1 text-xs",children:[e.jsx("div",{className:"text-fg-faint",children:"Endpoint"}),e.jsx("div",{className:"font-mono text-fg-dim break-all",children:t.endpoint})]}),e.jsxs("div",{className:"space-y-1 text-xs",children:[e.jsx("div",{className:"text-fg-faint",children:"Send cadence"}),e.jsx("div",{className:"text-fg-dim",children:"on start-up, after an update, and once a day"})]}),f&&e.jsx("div",{className:"text-red-400 text-xs",children:f})]}),s.pendingCount>0&&s.sentCount===0&&e.jsxs("section",{"data-testid":"telemetry-never-delivered-warning",className:"border border-red-400 rounded p-3 text-xs space-y-1 text-red-400",children:[e.jsx("div",{className:"font-medium",children:"Never delivered"}),e.jsxs("div",{className:"leading-relaxed",children:[s.pendingCount," record",s.pendingCount===1?"":"s",' queued but none have ever been sent to bilko.run on this install. Check the endpoint/network, or click "Send now" below.']})]}),e.jsxs("section",{className:"border border-line rounded p-3 text-xs space-y-1.5",children:[e.jsx("div",{className:"text-fg-dim",children:"Runtime status"}),e.jsxs("div",{children:[e.jsx("span",{className:"text-fg-faint",children:"last send:"})," ",ce(s.lastFlushAt)]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-fg-faint",children:"next daily send due:"})," ",ft(E?new Date(E).toISOString():null)]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-fg-faint",children:"queued records:"})," ",s.pendingCount]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-fg-faint",children:"delivered so far:"})," ",s.sentCount]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-fg-faint",children:"de-duplicated:"})," ",s.dedupedAppends]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-fg-faint",children:"evicted:"})," ",s.evictedCount]}),s.lastError&&e.jsxs("div",{className:"text-red-400 break-words",children:[e.jsx("span",{className:"text-fg-faint",children:"last error:"})," ",s.lastError.message," ","(",ce(s.lastError.at),")"]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("button",{onClick:C,disabled:d,className:"px-3 py-1 text-xs rounded bg-accent text-bg disabled:opacity-50 disabled:cursor-not-allowed",children:d?"sending…":"Send now"}),y&&e.jsx("span",{className:"text-fg-faint text-xs",children:y})]}),e.jsxs("section",{className:"space-y-2",children:[e.jsx("button",{onClick:T,className:"px-3 py-1 text-xs rounded border border-line text-fg-dim hover:text-fg",children:j?"Hide last records":"Inspect last records sent"}),j&&e.jsx("pre",{"data-testid":"telemetry-inspector-json",className:"bg-bg border border-line rounded p-2 text-[11px] font-mono overflow-auto max-h-96 whitespace-pre-wrap",children:JSON.stringify(c??[],null,2)})]})]})}function U({children:t,right:n}){return e.jsxs("div",{className:"flex items-baseline justify-between mb-2.5",children:[e.jsx("span",{className:"text-[11.5px] font-bold uppercase tracking-[0.8px] text-fg-faint",children:t}),n]})}function K({kind:t="soft",icon:n,children:s,onClick:r,disabled:i,testId:a}){return e.jsxs("button",{type:"button","data-testid":a,onClick:r,disabled:i,className:`shrink-0 inline-flex items-center gap-2 rounded-lg px-3.5 py-2 text-[13px] font-semibold transition-colors disabled:opacity-50 ${t==="soft"?"bg-bg-hi border border-line text-fg hover:bg-bg":"text-fg-dim hover:text-fg"}`,children:[n&&e.jsx(H,{name:n,size:15}),s]})}function yt({icon:t,title:n,subtitle:s,badge:r,action:i,testId:a}){return e.jsxs("div",{"data-testid":a,className:"flex items-center gap-3.5 bg-bg-hi border border-line rounded-xl px-[18px] py-3.5",children:[e.jsx("span",{className:"w-[34px] h-[34px] rounded-lg bg-bg border border-line grid place-items-center text-fg-dim shrink-0",children:e.jsx(H,{name:t,size:17})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2.5 mb-0.5",children:[e.jsx("span",{className:"text-sm font-semibold text-fg truncate",children:n}),r]}),e.jsx("div",{className:"font-mono text-[11.5px] text-fg-faint truncate",children:s})]}),i]})}function bt({onClick:t,disabled:n,testId:s,children:r="Revoke"}){return e.jsx("button",{"data-testid":s,onClick:t,disabled:n,className:"shrink-0 rounded-lg border border-line bg-bg text-accent px-3.5 py-1.5 text-[12.5px] font-semibold hover:bg-bg-hi disabled:opacity-50 transition-colors",children:r})}function pe({code:t,onConfirm:n,testId:s,codeTestId:r,confirmTestId:i,peer:a="browser"}){return e.jsxs("div",{"data-testid":s,className:"flex items-start gap-3.5 px-5 py-4 rounded-2xl border border-accent/40 bg-accent/[0.06]",children:[e.jsx("span",{className:"w-[38px] h-[38px] rounded-[11px] shrink-0 grid place-items-center bg-bg-hi text-accent",children:e.jsx(H,{name:"shield",size:20})}),e.jsxs("div",{className:"flex-1 min-w-0 text-sm text-fg",children:[e.jsx("strong",{className:"font-semibold",children:"Verify E2E session."})," Compare this code with the ",a," — they must match.",e.jsx("div",{"data-testid":r,className:"my-2 text-3xl font-mono tracking-[0.3em] text-center text-accent select-all",children:t}),e.jsx("p",{className:"text-[12.5px] text-fg-faint mb-3",children:"If the codes match, confirm below. Mutating commands are blocked until confirmed."}),e.jsx("button",{"data-testid":i,onClick:n,className:"rounded-lg bg-accent text-white px-4 py-2 text-[13px] font-semibold hover:opacity-90 transition-opacity",children:"Codes match — confirm"})]})]})}function jt({children:t,testId:n}){return e.jsx("div",{"data-testid":n,className:"bg-bg-hi border border-line rounded-xl p-5 text-center text-[13.5px] text-fg-faint italic font-serif",children:t})}function me({label:t,hint:n,on:s,onChange:r,warn:i,disabled:a,first:d,testId:u}){return e.jsxs("div",{className:`flex items-center justify-between gap-4 px-[18px] py-[15px] ${d?"":"border-t border-rule"} ${a?"opacity-50":""}`,children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-sm font-semibold text-fg mb-0.5",children:t}),e.jsxs("div",{className:`text-[12.5px] leading-snug flex items-center gap-1.5 ${i?"text-honey-dark":"text-fg-faint"}`,children:[i&&e.jsx("span",{"aria-hidden":!0,children:"⚠"}),n]})]}),e.jsx("span",{"data-testid":u,className:"inline-flex",children:e.jsx(D,{checked:s,onChange:a?()=>{}:r,disabled:a})})]})}function vt({device:t,online:n,onRevoke:s,revoking:r}){const i=t.lastConnectedAt?new Date(t.lastConnectedAt).toLocaleString():`paired ${new Date(t.issuedAt).toLocaleDateString()}`;return e.jsx(yt,{testId:"settings-remote-device",icon:"wifi",title:t.deviceName,badge:n?e.jsx(L,{tone:"default",className:"!text-sage !border-sage/40",children:"online"}):void 0,subtitle:`${t.deviceId} · last seen ${i}`,action:e.jsx(bt,{testId:"settings-remote-revoke",onClick:()=>s(t.deviceId),disabled:r})})}const M=t=>(t==null?void 0:t.message)||String(t);function wt(){var ie;const t=ee(l=>l.show),[n,s]=o.useState(null),[r,i]=o.useState(!0),[a,d]=o.useState(!1),[u,y]=o.useState(!1),[p,f]=o.useState("idle"),[m,c]=o.useState(""),[g,j]=o.useState(null),[v,N]=o.useState(!1),[S,h]=o.useState([]),[w,C]=o.useState(!1),T=o.useRef(null);o.useEffect(()=>{let l=!1;const x=()=>window.api.webRemote.getStatus().then(I=>{l||s(I)}).catch(()=>{});window.api.webRemote.getStatus().then(I=>{l||(s(I),i(!1))}).catch(I=>{l||(t("error",`Remote status: ${M(I)}`),i(!1))});const Ie=window.api.webRemote.onStatus(I=>s(I)),Pe=window.api.webRemote.onTokenRevoked(()=>{t("warn","Remote device token was revoked. Re-pair to reconnect."),x()}),Re=window.api.webRemote.onRevokedAll(({revokedCount:I})=>{t("info",`Panic: all ${I} device(s) revoked and sessions torn down.`),x()});return()=>{l=!0,Ie(),Pe(),Re()}},[t]),o.useEffect(()=>{if(p!=="enter-otp")return;const l=setTimeout(()=>{var x;return(x=T.current)==null?void 0:x.focus()},50);return()=>clearTimeout(l)},[p]);const E=async()=>s(await window.api.webRemote.getStatus()),b=async()=>{if(n){d(!0);try{const l=n.enabled?await window.api.webRemote.disable():await window.api.webRemote.enable();l&&l.ok===!1&&t("error",l.error||"Failed to change remote state."),await E()}catch(l){t("error",`Failed: ${M(l)}`)}finally{d(!1)}}},k=async()=>{if(n){y(!0);try{const l=n.remoteControlEnabled?await window.api.webRemote.disableControl():await window.api.webRemote.enableControl();l&&l.ok===!1&&t("error",l.error||"Failed to change command writes."),await E()}catch(l){t("error",`Failed: ${M(l)}`)}finally{y(!1)}}},R=async()=>{const l=m.trim().toUpperCase();if(!/^[A-Z0-9]{8}$/.test(l)){t("warn","Pairing code must be 8 alphanumeric characters.");return}f("pairing");try{const x=await window.api.webRemote.pair(l);if(!x.ok){t("error",x.error||"Pairing failed."),f("enter-otp");return}t("info","Device paired successfully."),c(""),f("idle"),await E()}catch(x){t("error",`Pairing error: ${M(x)}`),f("enter-otp")}},F=async l=>{j(l);try{const x=await window.api.webRemote.revokeDevice(l);if(!x.ok){t("error",x.error||"Revoke failed.");return}await E()}catch(x){t("error",`Revoke error: ${M(x)}`)}finally{j(null)}},Ne=async()=>{N(!0);try{const l=await window.api.webRemote.revokeAll();l.ok||t("error",l.error||"Panic revoke failed.")}catch(l){t("error",`Panic revoke error: ${M(l)}`)}finally{N(!1)}},Se=async()=>{if(w){C(!1);return}try{const l=await window.api.webRemote.auditTail(100);if(!l.ok){t("error",`Audit log: ${l.error||"unavailable"}`);return}h(l.lines??[]),C(!0)}catch(l){t("error",`Audit log: ${M(l)}`)}},ne=async l=>{try{const x=await window.api.webRemote.confirmSas(l);x!=null&&x.ok||t("error",`SAS confirm failed: ${(x==null?void 0:x.error)??"unexpected state — reconnect the mobile app"}`)}catch(x){t("error",`SAS confirm failed: ${M(x)}`)}};if(r)return e.jsx("div",{className:"p-6 text-fg-faint text-sm",children:"Loading…"});const A=(n==null?void 0:n.enabled)??!1,Y=(n==null?void 0:n.remoteControlEnabled)??!1,se=(n==null?void 0:n.connected)??!1,ae=(n==null?void 0:n.e2eActive)??!1,Ce=(n==null?void 0:n.e2eAuthenticated)??!1,Ee=(n==null?void 0:n.e2eState)??"idle",re=(n==null?void 0:n.pendingSas)??null,X=((n==null?void 0:n.clients)??[]).filter(l=>l.state==="pending_sas"&&l.pendingSas),$=(n==null?void 0:n.devices)??[],_=A&&se,Te=se?((ie=$.reduce((l,x)=>x.lastConnectedAt&&(!l||(l.lastConnectedAt??"")<x.lastConnectedAt)?x:l,null))==null?void 0:ie.deviceId)??null:null;return e.jsxs("div",{"data-testid":"settings-remote",className:"p-4 max-w-[760px] space-y-[22px]",children:[X.length>0?X.map((l,x)=>e.jsxs("div",{"data-testid":"settings-remote-sas-row",children:[X.length>1&&e.jsxs("div",{className:"text-[12px] font-semibold text-fg-dim mb-1",children:["Browser ",x+1]}),e.jsx(pe,{testId:x===0?"settings-remote-sas":void 0,codeTestId:x===0?"settings-remote-sas-code":void 0,confirmTestId:x===0?"settings-remote-sas-confirm":void 0,code:l.pendingSas,onConfirm:()=>ne(l.key)})]},l.key)):re&&e.jsx(pe,{testId:"settings-remote-sas",codeTestId:"settings-remote-sas-code",confirmTestId:"settings-remote-sas-confirm",code:re,onConfirm:()=>ne()}),Ee==="failed"&&e.jsxs("div",{className:"flex items-center gap-3.5 px-5 py-4 rounded-2xl border border-[#eccdbe] bg-[#f8e8e0]",children:[e.jsx("span",{className:"w-4 h-4 rounded-full bg-accent text-white grid place-items-center text-[11px] font-bold shrink-0",children:"!"}),e.jsxs("div",{className:"text-[13px] text-[#9a3f1f]",children:[e.jsx("strong",{className:"font-semibold",children:"E2E key exchange failed."})," ",e.jsx("span",{className:"text-fg-dim",children:"The session key could not be established. Reconnect the mobile app to retry."})]})]}),e.jsxs("div",{className:`flex items-center gap-3.5 px-5 py-4 rounded-2xl border ${_?"border-[#e8cdb9] bg-[#f5e9df]":"border-line bg-bg-hi"}`,children:[e.jsx("span",{className:`w-[38px] h-[38px] rounded-[11px] shrink-0 grid place-items-center ${_?"bg-[#f0d9c8] text-accent":"bg-[#e4ebd6] text-sage"}`,children:e.jsx(H,{name:_?"wifi":"shield",size:20})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-[14.5px] font-semibold text-fg mb-0.5",children:_?"Remote control is active":A?"Remote control is idle":"Remote control is off"}),e.jsx("div",{className:"text-[13px] text-fg-dim leading-snug",children:_?"A web session can send commands to this machine. Revoke below if unexpected.":A&&(n==null?void 0:n.linkState)==="repair-needed"?"The relay no longer recognises this device. Re-pair it with a new code to reconnect.":A?"The relay is on but no device is connected. Pair a device to begin.":"The relay connection is closed — no remote commands are accepted. Enable it below only when you need it."})]}),ae&&Ce?e.jsx(L,{tone:"default",className:"!text-sage !border-sage/40",children:"E2E authenticated"}):ae?e.jsx(L,{tone:"warn",children:"E2E · awaiting SAS"}):e.jsx(L,{tone:"dim",children:"relay only · not E2E yet"})]}),e.jsxs("div",{children:[e.jsx(U,{children:"Remote control"}),e.jsxs("div",{className:"bg-bg-hi border border-line rounded-2xl overflow-hidden",children:[e.jsx(me,{first:!0,testId:"settings-remote-enable",label:"Allow remote control from the web",hint:"Master switch. When off, the relay refuses every connection.",on:A,disabled:a,onChange:()=>{a||b()}}),e.jsx(me,{testId:"settings-remote-control",label:"Allow command writes (pty + scheduler)",hint:Y?"A paired device can run shell commands and queue jobs on this machine.":"Paired devices can watch session output but cannot send commands.",warn:Y,disabled:!A||u,on:Y&&A,onChange:()=>{A&&!u&&k()}})]})]}),e.jsxs("div",{children:[e.jsx(U,{children:"Pair a device"}),p==="idle"?e.jsxs("div",{className:"flex items-center justify-between gap-4 bg-bg-hi border border-line rounded-2xl px-5 py-[18px]",children:[e.jsxs("div",{"data-testid":"settings-remote-pair-hint",className:"text-[13.5px] text-fg-dim leading-relaxed max-w-[420px]",children:["On your phone open ",e.jsx("strong",{className:"text-fg font-semibold",children:"bilko.run/projects/session-manager"}),", sign in, and tap"," ",e.jsx("strong",{className:"text-fg font-semibold",children:"Generate pairing code"}),". Enter the 8-character code here."]}),e.jsx(K,{testId:"settings-remote-pair-start",kind:"soft",icon:"link",onClick:()=>f("enter-otp"),children:"Pair Device…"})]}):e.jsxs("div",{className:"flex items-center gap-5 bg-bg-hi border border-accent/40 rounded-2xl px-6 py-[22px]",children:[e.jsx("span",{className:"w-[52px] h-[52px] rounded-xl bg-bg border border-line grid place-items-center text-accent shrink-0",children:e.jsx(H,{name:"link",size:24})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-[11.5px] font-bold uppercase tracking-[0.8px] text-fg-faint mb-2",children:"Enter the code from your phone"}),e.jsx("input",{ref:T,"data-testid":"settings-remote-otp",value:m,onChange:l=>c(l.target.value.toUpperCase().replace(/[^A-Z0-9]/g,"")),onKeyDown:l=>{l.key==="Enter"&&R()},maxLength:8,placeholder:"XXXXXXXX",disabled:p==="pairing",className:"w-full bg-transparent border-0 outline-none font-mono text-[30px] font-semibold tracking-[6px] text-fg placeholder:text-fg-faint/40 disabled:opacity-50"})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsx(K,{testId:"settings-remote-pair-confirm",kind:"soft",onClick:R,disabled:p==="pairing"||m.length<8,children:p==="pairing"?"Pairing…":"Confirm"}),e.jsx(K,{kind:"ghost",onClick:()=>{f("idle"),c("")},disabled:p==="pairing",children:"cancel"})]})]})]}),e.jsxs("div",{children:[e.jsx(U,{right:$.length>0?e.jsxs("span",{className:"text-[11.5px] text-fg-faint",children:[$.length," paired"]}):void 0,children:"Paired devices"}),$.length===0?e.jsx(jt,{children:"No devices paired yet."}):e.jsx("div",{className:"space-y-2",children:$.map(l=>e.jsx(vt,{device:l,online:l.deviceId===Te,onRevoke:F,revoking:g===l.deviceId},l.deviceId))})]}),e.jsxs("div",{children:[e.jsx(U,{right:e.jsx("button",{"data-testid":"settings-remote-audit-toggle",onClick:Se,className:"text-[12px] text-fg-faint hover:text-fg-dim transition-colors",children:w?"Hide":"Show last 100 · 0600, stays on this machine"}),children:"Audit log"}),w&&e.jsx("div",{className:"bg-bg-hi border border-line rounded-xl overflow-auto max-h-64 mb-2",children:S.length===0?e.jsx("p",{className:"p-4 text-[12.5px] text-fg-faint",children:"No entries today."}):e.jsx("pre",{"data-testid":"settings-remote-audit",className:"p-4 text-[12px] text-fg-dim font-mono whitespace-pre-wrap leading-relaxed",children:S.join(`
2
- `)})}),e.jsxs("p",{className:"text-[12px] text-fg-faint",children:["Full log at"," ",e.jsx("code",{className:"font-mono text-fg-faint",children:"~/.claude/session-manager/logs/remote-audit-YYYY-MM-DD.log"})," ","(0600, never leaves this machine)"]})]}),e.jsxs("div",{className:"flex items-center justify-between gap-4 bg-[#f8e8e0] border border-[#eccdbe] rounded-2xl px-5 py-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("span",{className:"w-4 h-4 rounded-full bg-accent text-white grid place-items-center text-[11px] font-bold shrink-0",children:"!"}),e.jsx("span",{className:"text-sm font-semibold text-[#9a3f1f]",children:"Panic — disconnect & revoke everything"})]}),e.jsx("div",{className:"text-[12.5px] text-fg-dim leading-snug max-w-[440px]",children:"Tears down every active session and invalidates all paired-device tokens. Devices must re-pair. Use if you suspect compromise."})]}),e.jsx("button",{"data-testid":"settings-remote-revoke-all",onClick:Ne,disabled:v,className:"shrink-0 rounded-lg bg-accent text-white px-[18px] py-2 text-[13px] font-semibold hover:opacity-90 disabled:opacity-50 transition-opacity",children:v?"Revoking…":"Revoke all"})]})]})}const z="px-2 py-1 rounded border border-line text-xs text-fg hover:bg-bg-hi disabled:opacity-50";function kt(){const t=We(),n=ee(u=>u.show),s=async u=>{try{const p=await u();p&&p.ok===!1&&n("error",p.error??"Update action failed")}catch(y){n("error",y instanceof Error?y.message:String(y))}};if(!t)return null;const{state:r}=t,i=r==="unsupported",a=t.latest?`v${t.latest}`:"—",d=()=>{window.confirm("Installing now will stop all running jobs and terminals. Continue?")&&s(()=>window.api.updater.install(!0))};return e.jsxs("section",{"data-testid":"settings-updates",className:"border border-line rounded p-3 space-y-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("span",{className:"text-fg text-xs font-medium",children:"Updates"}),e.jsxs("div",{className:"text-fg-dim text-xs flex gap-4",children:[e.jsxs("span",{children:["Current v",t.current]}),e.jsxs("span",{children:["Latest ",a]})]})]}),i?e.jsx("p",{className:"text-fg-faint text-[11px]",children:"Auto-update runs only in the installed Windows app or the Linux AppImage. npx builds update via npx."}):e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(D,{checked:t.enabled,onChange:u=>void s(()=>window.api.updater.setEnabled(u)),label:"Update automatically"}),e.jsx("button",{type:"button","data-testid":"updates-check",className:z,disabled:r==="checking"||r==="downloading",onClick:()=>void s(()=>window.api.updater.check()),children:"Check for updates"})]}),r==="checking"&&e.jsx("p",{className:"text-fg-dim text-xs",children:"Checking…"}),r==="downloading"&&e.jsxs("p",{className:"text-fg-dim text-xs",children:["Downloading… ",t.progress!=null?`${Math.round(t.progress)}%`:""]}),r==="ready"&&e.jsxs("button",{type:"button","data-testid":"updates-install",className:z,onClick:()=>void s(()=>window.api.updater.install(!1)),children:["Restart to install v",t.latest]}),r==="deferred"&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("p",{className:"text-fg-dim text-xs",children:["Waiting for ",t.busyReason??"work"," to finish"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"button",className:z,onClick:d,children:"Install now"}),e.jsx("button",{type:"button",className:z,onClick:()=>void s(()=>window.api.updater.cancelDeferred()),children:"Cancel"})]})]}),r==="error"&&e.jsx("p",{className:"text-red-400 text-xs",children:t.error})]})}const Nt=[{key:"maxAgeDays",label:"Run logs: keep for",unit:"days",min:3,max:3650},{key:"runsArchiveDays",label:"Runs archive: keep for",unit:"days",min:1,max:3650},{key:"auditLogMonths",label:"Audit log: keep for",unit:"months",min:1,max:120},{key:"reservedMarkersKeep",label:"Reserved markers: keep",unit:"markers",min:1,max:1e5}],St="w-24 px-2 py-1 rounded border border-line bg-transparent text-xs text-fg";function ue(t,n){return n==="maxAgeDays"?t.runLogs.maxAgeDays:t[n]}function Ct(t,n){return t==="maxAgeDays"?{runLogs:{maxAgeDays:n}}:{[t]:n}}function ye(t){if(!Number.isFinite(t)||t<=0)return"0 B";const n=["B","KB","MB","GB","TB"];let s=0,r=t;for(;r>=1024&&s<n.length-1;)r/=1024,s++;return`${s===0?r:r.toFixed(1)} ${n[s]}`}function Z(t,n,s){return`${t}: ${ye(n)} in ${s.toLocaleString("en-US")} files`}function Et(){const t=ee(c=>c.show),[n,s]=o.useState(null),[r,i]=o.useState({}),[a,d]=o.useState(null),u=o.useCallback(c=>t("error",c instanceof Error?c.message:String(c)),[t]),y=o.useCallback(async()=>{try{d(await window.api.opsRetention.preview())}catch(c){u(c)}},[u]);o.useEffect(()=>{let c=!0;return window.api.opsRetention.get().then(g=>{c&&s(g)}).catch(g=>{c&&u(g)}),y(),()=>{c=!1}},[u,y]);const p=async c=>{if(!n)return;const g=r[c.key];if(g===void 0)return;const j=Number(g);if(i(N=>{const{[c.key]:S,...h}=N;return h}),g.trim()===""||!Number.isFinite(j))return;const v=Math.min(c.max,Math.max(c.min,Math.round(j)));if(v!==ue(n,c.key))try{s(await window.api.opsRetention.set(Ct(c.key,v))),await y()}catch(N){u(N)}},f=a?a.runLogs.bytes+a.runsArchive.bytes+a.tmp.bytes:0,m=a?a.runLogs.files+a.runsArchive.entries+a.tmp.files:0;return e.jsxs("section",{"data-testid":"settings-ops-retention",className:"border border-line rounded p-3 space-y-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("span",{className:"text-fg text-xs font-medium",children:"Ops data retention"}),e.jsx("p",{className:"text-fg-faint text-[11px]",children:"How long the daily sweep keeps scheduler and audit data. Machine-wide."})]}),n&&e.jsxs("div",{className:"space-y-2",children:[Nt.map(c=>e.jsxs("label",{className:"flex items-center gap-2 text-xs text-fg-dim",children:[e.jsx("span",{className:"w-48",children:c.label}),e.jsx("input",{type:"number","data-testid":`ops-retention-${c.key}`,className:St,min:c.min,max:c.max,value:r[c.key]??String(ue(n,c.key)),onChange:g=>i(j=>({...j,[c.key]:g.target.value})),onBlur:()=>void p(c)}),e.jsx("span",{className:"text-fg-faint",children:c.unit})]},c.key)),e.jsx("p",{className:"text-fg-dim text-xs",children:"Archived transcripts: kept forever"})]}),a&&e.jsxs("div",{"data-testid":"ops-retention-preview",className:"space-y-1 text-xs text-fg-dim",children:[e.jsxs("div",{className:"text-fg",children:["Current policy would free ",ye(f)," in ",m.toLocaleString("en-US")," files"]}),e.jsx("div",{children:Z("Run logs",a.runLogs.bytes,a.runLogs.files)}),e.jsx("div",{children:Z("Runs archive",a.runsArchive.bytes,a.runsArchive.entries)}),e.jsx("div",{children:Z("Stale temp files",a.tmp.bytes,a.tmp.files)}),e.jsx("p",{className:"text-fg-faint text-[11px]",children:"Nothing is deleted until the daily sweep runs."})]})]})}const q=[{id:"project",label:"Project & Tab",realm:"machine",blurb:"A PROJECT is a cwd; a TAB is one open project.",tone:{chip:"bg-bg-elev text-fg-dim",border:"border-line",dot:"bg-fg-faint"}},{id:"epic",label:"Epic (PromptSession)",realm:"project",blurb:"The central aggregate root — one unit of work, one claude session.",tone:{chip:"bg-accent-muted text-accent-dark",border:"border-accent",dot:"bg-accent"}},{id:"scheduler",label:"Scheduler",realm:"project",blurb:"PRDs + the headless jobs that execute them.",tone:{chip:"bg-butter/30 text-honey-dark",border:"border-honey",dot:"bg-honey"}},{id:"agents",label:"Agents & Taxonomy",realm:"machine",blurb:"The ACTOR and MISSION halves of AIM.",tone:{chip:"bg-sage/20 text-sage-dark",border:"border-sage",dot:"bg-sage"}},{id:"memory",label:"Memory",realm:"machine",blurb:"Workspace, cross-project, and per-agent memory.",tone:{chip:"bg-hive-teal/20 text-hive-teal",border:"border-hive-teal",dot:"bg-hive-teal"}},{id:"transcript",label:"Transcript & Usage",realm:"machine",blurb:"The Claude CLI's own JSONL, classified events, and billing.",tone:{chip:"bg-bg-hi text-fg-dim",border:"border-rule",dot:"bg-fg-dim"}},{id:"brief",label:"Project Home & Publishing",realm:"project",blurb:"The synthesized Brief, generated pages, and bilko.run publish state.",tone:{chip:"bg-accent-muted/60 text-accent-dark",border:"border-accent-muted",dot:"bg-accent-muted"}},{id:"config",label:"Machine Config",realm:"machine",blurb:"Settings, layout, and the single-writer ownership map.",tone:{chip:"bg-line text-fg-faint",border:"border-rule",dot:"bg-fg-faint"}}];function be(t){const n=q.find(s=>s.id===t);if(!n)throw new Error(`unknown ErdGroupId: ${t}`);return n}const B=[{id:"project",name:"Project",aka:"cwd — Main Project",group:"project",store:{path:"identity only, no record of its own — folded at read time from ~/.claude/projects/<encoded>",format:"in-memory",definedIn:"src/renderer/lib/knownProjectAggregate.ts (aggregateProjectsByCwd) "},summary:"A folder whose cwd never resolved from transcript content is DROPPED, never guessed — the naive decode once reported 2044 phantom projects.",fields:[{name:"cwd",type:"string",key:"pk",note:"resolved working directory — the project's identity"},{name:"name",type:"string",note:"display name: the cwd's last path segment"},{name:"encoded",type:"string",note:"representative transcript folder (most recently active)"},{name:"encodedIds",type:"string[]",note:"every ~/.claude/projects/<encoded> folder that resolved to this cwd"},{name:"sessionCount",type:"number"},{name:"sizeBytes",type:"number"},{name:"lastSession",type:"number"}]},{id:"tab",name:"PersistedTab",aka:"TAB",group:"project",store:{path:"~/.claude/session-manager/tabs.json",format:"json",definedIn:"src/main/sessionsStore.cjs "},summary:"One TAB per project — extra sessions within a project are Epics, not tabs.",fields:[{name:"id",type:"string",key:"pk"},{name:"sessionId",type:"string"},{name:"cwd",type:"string",key:"fk",ref:"project.cwd"},{name:"label",type:"string"},{name:"presetId",type:"string | null"}]},{id:"epic",name:"PromptSession",aka:"EPIC",group:"epic",store:{path:"<cwd>/session-manager-operations/prompt-sessions/active-index.json -> sessions[id]",format:"json",writer:"epics",definedIn:"src/main/lib/epic/epicMint.cjs (ensureEpic) + src/renderer/state/promptSessions.ts "},summary:"The central aggregate root — created in exactly ONE place, a human pressing New Epic.",fields:[{name:"id",type:"string",key:"pk"},{name:"cwd",type:"string",key:"fk",ref:"project.cwd"},{name:"goalText",type:"string",note:"the original top-level prompt text that started this goal"},{name:"claudeSessionId",type:"string",note:"independently minted — never shared with any tab.sessionId"},{name:"status",type:"'proposed' | 'active' | 'completed'"},{name:"createdAt",type:"string"},{name:"completedAt",type:"string | null"},{name:"resumedFromId",type:"string",optional:!0,key:"fk",ref:"epic.id"},{name:"tag",type:"TicketTag",optional:!0,key:"fk",ref:"tag.tag"},{name:"openingPrompt",type:"string | null",optional:!0},{name:"source",type:"EpicSource",optional:!0,note:"{ producer, prdSlug?, runId?, sourceTabId?, fromCwd?, fromEpicId? }"},{name:"agentType",type:"string",optional:!0,key:"fk",ref:"agentPersona.name"},{name:"model",type:"string",optional:!0,note:"per-Epic model override; absent = the persona model"},{name:"effort",type:"string",optional:!0,note:"per-Epic effort override; absent = the persona effort"},{name:"developLoop",type:"false",optional:!0,note:"false = started with the develop loop off; absent = on"},{name:"restoredSession",type:"true",optional:!0,note:"claudeSessionId adopted from an existing CLI session"},{name:"agentCli",type:"string",optional:!0,note:"agent CLI running the session; absent = Claude Code; fixed for the session"},{name:"agentCliModel",type:"string",optional:!0,note:"model string passed to agentCli; absent = its default"},{name:"sections",type:"EpicIntakeSection[]",optional:!0},{name:"worktree",type:"{ dir, branch, baseCwd, status, conflictReason? }",optional:!0,note:"own git worktree on branch 'sm-epic/<id>' when Active"}],notes:["SINGLE-CREATOR LAW, fail-closed in epicMint.cjs — the New Epic IPC handler and crossProjectFeedback.cjs are the only mint authorities.","Every Epic is born proposed; nothing is created directly as active.","EPIC : claude-session is 1:1 — Chat and Terminal are two VIEWS over one session.","Title + objective are fixed for the life of the session — iterate in follow-up messages, don't repurpose."]},{id:"epicEvent",name:"PromptSessionEvent",group:"epic",store:{path:"<cwd>/session-manager-operations/prompt-sessions/active-index.json -> events[]",format:"json",writer:"epics",definedIn:"src/renderer/state/promptSessions.ts + src/main/lib/epic/activeIndexMerge.cjs "},summary:"One step in an Epic's Prompt → PRD → Response → ... → Closed chain.",fields:[{name:"id",type:"string",key:"pk"},{name:"promptSessionId",type:"string",key:"fk",ref:"epic.id"},{name:"kind",type:"'prompt' | 'prd_created' | 'response' | 'closed'"},{name:"causedByEventId",type:"string | null",key:"fk",ref:"epicEvent.id",note:"must be the session's current tail event — a chain, not a tree"},{name:"at",type:"string"},{name:"prdSlug",type:"string",optional:!0,key:"fk",ref:"prd.slug"},{name:"text",type:"string",optional:!0},{name:"outcome",type:"'completed' | 'failed' | 'needs_review'",optional:!0},{name:"validation",type:"'unvalidated' | 'validating' | 'verified' | 'refuted'",optional:!0}]},{id:"epicTranscriptTurn",name:"PromptSessionTranscriptTurn",group:"epic",store:{path:"<cwd>/session-manager-operations/prompt-sessions/transcripts/<epicId>.jsonl",format:"jsonl",writer:"epics",definedIn:"src/main/promptSessionTranscript.cjs "},summary:"The durable per-Epic transcript store, kept alongside the CLI's own JSONL as a fallback source of turns.",fields:[{name:"v",type:"1"},{name:"epicId",type:"string",key:"fk",ref:"epic.id"},{name:"eventId",type:"string | null",key:"fk",ref:"epicEvent.id"},{name:"role",type:"'user' | 'assistant'"},{name:"at",type:"string"},{name:"text",type:"string"}]},{id:"epicArchive",name:"PromptSessionArchive",group:"epic",store:{path:"<cwd>/session-manager-operations/prompt-sessions/<epicId>.json",format:"json",writer:"epics",definedIn:"src/renderer/state/promptSessions.ts (promptSessionArchivePath) "},summary:"On-disk archive written once at completion — freezes the Epic, its events, and its transcript.",fields:[{name:"session",type:"PromptSession"},{name:"events",type:"PromptSessionEvent[]"},{name:"transcript",type:"string"},{name:"archivedAt",type:"string"},{name:"durableTurns",type:"Array<{ role, text, at }>",optional:!0}]},{id:"epicWorktreeConfig",name:"EpicWorktreeConfig",group:"epic",store:{path:"<cwd>/session-manager-operations/prompt-sessions/epic-worktree-config.json",format:"json",writer:"epics",definedIn:"src/main/lib/epic/epicWorktreeProjectConfig.cjs "},summary:"Per-project 'disable Epic worktree isolation' toggle, read by gitWorktree.cjs's isWorktreeDisabled('epic', cwd) on every worktree creation attempt.",fields:[{name:"disabled",type:"boolean"}],notes:["One-shot migration from the legacy machine-wide ~/.claude/session-manager/epic-worktree-project-config.json map, keyed by project cwd — that file is left in place, never deleted."]},{id:"exchange",name:"Exchange",group:"epic",store:{path:"<cwd>/session-manager-operations/prompt-sessions/exchanges.jsonl",format:"jsonl",writer:"epics",definedIn:"src/main/exchanges.cjs "},summary:"One durable NDJSON record per completed terminal-chat exchange, appended off the hot path.",fields:[{name:"ts",type:"string"},{name:"sessionId",type:"string",key:"fk",ref:"epic.claudeSessionId",note:"the tab's claude session id"},{name:"cwd",type:"string",key:"fk",ref:"project.cwd"},{name:"prompt",type:"string"},{name:"result",type:"string"},{name:"summary",type:"string",note:"produced by the shared Haiku summarizer"},{name:"model",type:"string"},{name:"degraded",type:"string",optional:!0,note:"set when summarization failed — the exchange itself is never dropped"},{name:"promptId",type:"string",optional:!0,key:"fk",ref:"prd.slug",note:"originating PromptTicket.id when dispatched from the per-tab queue; forward-only, never backfilled"}],notes:["Written via raw fs O_APPEND (not config.cjs writeJson) for atomicity across concurrent writers — assertOpsWrite is called explicitly since raw fs bypasses the normal enforcement point.","Historical rows from before this store existed remain, untouched and unmigrated, in the old global ~/.claude/knowledge-log/exchanges/<encodeCwd(cwd)>.jsonl."]},{id:"prd",name:"PRD",group:"scheduler",store:{path:"<cwd>/session-manager-operations/scheduler/epics/<epicId>/prds/<slug>.md",format:"markdown",writer:"scheduler",definedIn:"src/main/lib/prd/prdLocations.cjs + scheduler_create_prd MCP tool "},summary:"PRD authoring is API-only via the scheduler_create_prd MCP tool — a PRD joins an EXISTING Epic and never conjures one.",fields:[{name:"slug",type:"string",key:"pk",note:"<nn>-<kebab-title>.md filename stem"},{name:"title",type:"string"},{name:"cwd",type:"string",key:"fk",ref:"project.cwd"},{name:"epicId",type:"string | null",key:"fk",ref:"epic.id",note:"derived from the PRD's DIRECTORY — fact on disk"},{name:"sourcePromptId",type:"string",optional:!0,key:"fk",ref:"epic.id",note:"frontmatter intent — can disagree with epicId"},{name:"sourceTabId",type:"string",optional:!0},{name:"estimateMinutes",type:"number"},{name:"tag",type:"'feature' | 'bug' | 'discussion' | 'build' | 'project-home-builder' | 'art' | 'portfolio'",optional:!0,key:"fk",ref:"tag.tag"},{name:"dependsOn",type:"string[]",optional:!0,key:"fk",ref:"prd.slug",note:"the SOLE ordering primitive"},{name:"goal",type:"string"},{name:"acceptanceCriteria",type:"string[]"},{name:"implementationNotes",type:"string"},{name:"outOfScope",type:"string[]",optional:!0},{name:"createdVia",type:"string",optional:!0},{name:"issuedAt",type:"string",optional:!0}],notes:["Flat scheduler/prds/ is RETIRED — auto-consolidated into prds-archived/ on every reconcile() pass.","epicId is derived from the DIRECTORY (fact on disk) while sourcePromptId is frontmatter intent and can disagree."]},{id:"scheduleJob",name:"ScheduleJob",group:"scheduler",store:{path:"<cwd>/session-manager-operations/scheduler/state/queue.json -> jobs[]",format:"json",writer:"scheduler",definedIn:"src/main/lib/scheduler/queueStore.cjs + src/main/lib/scheduler/scheduleJobSchema.cjs "},summary:"dependsOn is the SOLE ordering primitive — parallelGroup is a display hint, never a barrier.",fields:[{name:"slug",type:"string",key:"pk",note:"shared identity with the PRD it executes"},{name:"title",type:"string"},{name:"cwd",type:"string | null",key:"fk",ref:"project.cwd"},{name:"parallelGroup",type:"number"},{name:"estimateMinutes",type:"number | null"},{name:"bodyPreview",type:"string"},{name:"status",type:"'pending' | 'running' | 'investigating' | 'completed' | 'failed' | 'needs_review' | 'quarantined'"},{name:"runId",type:"string | null",key:"fk",ref:"runLog.runId"},{name:"startedAt",type:"string | null"},{name:"finishedAt",type:"string | null"},{name:"exitCode",type:"number | null"},{name:"error",type:"string | null"},{name:"sessionId",type:"string",optional:!0},{name:"runtime",type:"ScheduleJobRuntime",optional:!0,note:"{ pid, runId, startedAt, sessionId?, cwd? }"},{name:"verifierVerdict",type:"string",optional:!0},{name:"dependsOn",type:"string[]",optional:!0,key:"fk",ref:"prd.slug"},{name:"originSessionId",type:"string | null",optional:!0,key:"fk",ref:"epic.id"},{name:"sourceTabId",type:"string | null",optional:!0},{name:"sourcePromptId",type:"string | null",optional:!0,key:"fk",ref:"epic.id"},{name:"epicId",type:"string | null",optional:!0,key:"fk",ref:"epic.id",note:"authoritative — derived from the PRD directory"},{name:"statusHistory",type:"ScheduleJobStatusHistoryEntry[]",optional:!0}],notes:["Every launch must take a slot from lib/scheduler/sessionSlots.cjs — the single machine-wide concurrency limit.","--model is always pinned on every claude -p call site.","A job in needs_review is a QUESTION routed back to the authoring Epic and never creates work on its own."]},{id:"scheduleJobStatusHistory",name:"ScheduleJobStatusHistoryEntry",group:"scheduler",store:{path:"<cwd>/session-manager-operations/scheduler/state/queue.json -> jobs[].statusHistory[]",format:"json",writer:"scheduler",definedIn:"src/main/lib/scheduler/scheduleJobTransitions.cjs "},summary:"Bounded trail (~20 entries) of accepted status transitions for one ScheduleJob.",fields:[{name:"from",type:"string | null"},{name:"to",type:"string"},{name:"reason",type:"string | null"},{name:"source",type:"string | null"},{name:"at",type:"string"}]},{id:"scheduleHistoryEntry",name:"Schedule history entry",group:"scheduler",store:{path:"<cwd>/session-manager-operations/scheduler/state/history.jsonl",format:"jsonl",writer:"scheduler",definedIn:"src/main/lib/scheduler/queueStore.cjs "},summary:"Terminal jobs aged out of queue.json land here, one JSON object per line.",fields:[{name:"slug",type:"string",key:"fk",ref:"prd.slug"},{name:"status",type:"ScheduleJobStatus"},{name:"finishedAt",type:"string | null"},{name:"epicId",type:"string | null",optional:!0,key:"fk",ref:"epic.id"},{name:"runId",type:"string | null",optional:!0,key:"fk",ref:"runLog.runId"}]},{id:"scheduleConfig",name:"ScheduleConfig",group:"scheduler",store:{path:"~/.claude/session-manager/scheduler-machine.json",format:"json",writer:"scheduler",definedIn:"src/main/lib/scheduler/schedulerConfig.cjs + src/main/lib/scheduler/queueStore.cjs "},summary:"Machine-level auto-fire policy and utilization gate (scheduler-machine.json, not per-project queue.json).",fields:[{name:"enabled",type:"boolean",note:"legacy on/off, kept for v0.4 backwards compat"},{name:"offsetMinutes",type:"number"},{name:"defaultCwd",type:"string",key:"fk",ref:"project.cwd"},{name:"firePolicy",type:"'manual' | 'when-available'"},{name:"utilizationThreshold",type:"number"},{name:"schemaVersion",type:"1"}]},{id:"runLog",name:"Run log",group:"scheduler",store:{path:"~/.claude/session-manager/scheduled-plans/runs/<runId>/",format:"directory",definedIn:"src/main/scheduler.cjs (RUNS_DIR) "},summary:"One directory per headless claude -p invocation — stdout/stderr/exit capture for a ScheduleJob's run.",fields:[{name:"runId",type:"string",key:"pk"}]},{id:"agentPersona",name:"AgentPersona",aka:"ACTOR",group:"agents",store:{path:"~/.claude/agents/<name>.md",format:"markdown",definedIn:"src/main/agentLibrary.cjs + src/main/lib/persona-macro/agentPersonaSchema.cjs "},summary:"One global persona. The action/actionLabel frontmatter keys are retired legacy fields — no longer a live concept.",fields:[{name:"name",type:"string",key:"pk"},{name:"description",type:"string | null"},{name:"tools",type:"string[]"},{name:"model",type:"string | null",note:"wins over the Settings default for this Epic"},{name:"color",type:"string | null"},{name:"tags",type:"AgentPersonaTag[]",key:"fk",ref:"tag.tag"},{name:"projects",type:"string[]",key:"fk",ref:"project.cwd",note:"'*' means every project"},{name:"effort",type:"string | null",optional:!0,note:"per-Epic carve-out like model — persona frontmatter wins over the Settings default"},{name:"title",type:"string | null",optional:!0},{name:"path",type:"string"},{name:"body",type:"string"},{name:"overridingProjects",type:"string[]"}]},{id:"tag",name:"Tag",aka:"MISSION — EpicTag",group:"agents",store:{path:"src/renderer/lib/tagLibrary.ts (TAG_LIBRARY)",format:"code",definedIn:"src/renderer/lib/tagLibrary.ts + src/renderer/lib/agentTagDefs.ts "},summary:"The closed 7-tag union — Epic creation is agentType (who) + tag (what), two independent selections.",fields:[{name:"tag",type:"'feature' | 'bug' | 'discussion' | 'build' | 'project-home-builder' | 'art' | 'portfolio'",key:"pk"},{name:"label",type:"string"},{name:"description",type:"string"},{name:"developEagerness",type:"'expected-default' | 'available-not-assumed'"},{name:"developsVia",type:"string"}]},{id:"macro",name:"Macro",aka:"HOT KEY",group:"agents",store:{path:"~/.claude/session-manager/macros.json",format:"json",writer:"src/main/lib/persona-macro/macroLibrary.cjs",definedIn:"src/main/lib/persona-macro/macroLibrary.cjs "},summary:"A saved (agent, tag, prompt) hot key — machine-local library; a Sessions hot key is shown per project, a Project Home tool in every project; pressing it is the same act as New Session.",fields:[{name:"id",type:"string",key:"pk"},{name:"label",type:"string"},{name:"agentName",type:"string",key:"fk",ref:"agentPersona.name"},{name:"tag",type:"TicketTag",key:"fk",ref:"tag.tag"},{name:"prompt",type:"string"},{name:"projects",type:"string[]",key:"fk",ref:"project.cwd"},{name:"surface",type:"string"},{name:"builtin",type:"boolean",optional:!0},{name:"builtinVersion",type:"number",optional:!0},{name:"createdAt",type:"string"},{name:"updatedAt",type:"string"},{name:"inputs",type:"MacroInput[]",optional:!0},{name:"autoStartTargets",type:"string[]",optional:!0,key:"fk",ref:"project.cwd"}]},{id:"memoryEntry",name:"MemoryEntry",group:"memory",store:{path:"~/.claude/projects/<encodedCwd>/memory/<name>.md",format:"markdown",definedIn:"src/main/memoryTool.cjs "},summary:"One workspace memory file, semantically organized by topic.",fields:[{name:"name",type:"string",key:"pk"},{name:"path",type:"string"},{name:"mtimeMs",type:"number"},{name:"bytes",type:"number"},{name:"workspace",type:"string",key:"fk",ref:"project.cwd",note:"carried on MemoryListResult, denormalized here — the directory this entry lives under"}]},{id:"memoryCluster",name:"MemoryCluster",group:"memory",store:{path:"<cwd>/session-manager-operations/memory-clusters/clusters.json",format:"json",writer:"memory-clusters",definedIn:"src/main/memoryAggregate.cjs "},summary:"Derived grouping of related MemoryEntry files, computed and cached per workspace.",fields:[{name:"id",type:"string",key:"pk"},{name:"name",type:"string"},{name:"summary",type:"string"},{name:"memberSlugs",type:"string[]",key:"fk",ref:"memoryEntry.name"},{name:"links",type:"MemoryClusterLink[]",note:"{ from, to, label? }"}]},{id:"agentMemoryEntry",name:"AgentMemoryEntry",group:"memory",store:{path:"~/.claude/agent-memory/<agent>/ | .claude/agent-memory/<agent>/ | .claude/agent-memory-local/<agent>/",format:"directory",definedIn:"src/main/lib/memoryDirResolve.cjs (resolveAgentMemoryDir)"},summary:"Per-subagent memory in Claude Code's native agent-memory directories (user, project, local scope), keyed by agent name — markdown files with a MEMORY.md index.",fields:[{name:"agent",type:"string",key:"pk",ref:"agentPersona.name",note:"directory name under the scope root"},{name:"scope",type:"'user' | 'project' | 'local'",note:"selects which agent-memory root resolveAgentMemoryDir returns"},{name:"files",type:"markdown[]",note:"topic files plus MEMORY.md index, read live from disk"}]},{id:"claudeTranscript",name:"Claude transcript",group:"transcript",store:{path:"~/.claude/projects/<encodedCwd>/<sessionUuid>.jsonl",format:"jsonl",definedIn:"written by the Claude Code CLI; tailed by src/main/transcripts.cjs "},summary:"The CLI's own append-only transcript — Session Manager only tails and classifies it, never writes it.",fields:[{name:"sessionUuid",type:"string",key:"pk"},{name:"encodedCwd",type:"string",key:"fk",ref:"project.cwd"}]},{id:"transcriptEvent",name:"TranscriptEvent",group:"transcript",store:{path:"in-memory ring buffer, broadcast as transcript:event:<tabId>",format:"in-memory",definedIn:"src/main/transcripts.cjs -> src/renderer/state/live.ts "},summary:"Classified, bounded-preview view over one raw transcript line — never the source of truth.",fields:[{name:"kind",type:"TranscriptEventKind"},{name:"data",type:"unknown"},{name:"raw",type:"unknown"},{name:"previewText",type:"string"},{name:"ref",type:"TranscriptEventRef | null",note:"{ filePath, byteOffset, byteLength }"},{name:"tabId",type:"string",key:"fk",ref:"tab.id"}]},{id:"historyRollupDay",name:"History rollup day",group:"transcript",store:{path:"~/.claude/session-manager/history-rollup.jsonl",format:"jsonl",definedIn:"src/main/lib/historyRollup.cjs "},summary:"One finalized day-per-project analytics row (History tab is analytics/cost/charts only).",fields:[{name:"date",type:"string",key:"pk"},{name:"projectCwd",type:"string",key:"fk",ref:"project.cwd"},{name:"promptCount",type:"number"},{name:"inputTokens",type:"number"},{name:"outputTokens",type:"number"},{name:"estimatedCostUsd",type:"number"}]},{id:"billingUsage",name:"UsageSnapshot",group:"transcript",store:{path:"~/.claude/session-manager/billing-cache.json",format:"json",definedIn:"src/main/usage.cjs (CACHE_PATH) "},summary:"Cached rolling-window utilization percentages from the account's billing API.",fields:[{name:"five_hour",type:"UsageWindow | null"},{name:"seven_day",type:"UsageWindow | null"},{name:"seven_day_sonnet",type:"UsageWindow | null"},{name:"seven_day_opus",type:"UsageWindow | null"},{name:"seven_day_oauth_apps",type:"UsageWindow | null"},{name:"extra_usage",type:"{ is_enabled, monthly_limit, used_credits, utilization, currency } | null"}]},{id:"projectBrief",name:"ProjectBrief",group:"brief",store:{path:"<cwd>/session-manager-operations/project-brief/brief.json",format:"json",writer:"project-home",definedIn:"src/main/projectBrief.cjs "},summary:"The synthesized project Brief — generated, with a hand-edit escape hatch.",fields:[{name:"version",type:"number"},{name:"synthesizedAt",type:"string"},{name:"editedAt",type:"string | null"},{name:"model",type:"string"},{name:"purpose",type:"string"},{name:"what",type:"string[]"},{name:"areas",type:"ProjectBriefArea[]",note:"{ name, files, note, epic, heat }"},{name:"scope",type:"ProjectBriefScopeEntry[]",note:"{ when, kind, text, src }"},{name:"conventions",type:"string[]"},{name:"pins",type:"{ what: boolean; conventions: boolean }"},{name:"pinned",type:"{ what: string[] | null; conventions: string[] | null }"}]},{id:"projectPages",name:"ProjectPagesOutput",group:"brief",store:{path:"<cwd>/session-manager-operations/project-pages/ (knowledge/<id>/, videos/<id>/, videos/_character/)",format:"directory",writer:"project-home",definedIn:"src/main/lib/feedback-remote/projectHomeAdminRoutes.cjs (pages, videos and character routes)"},summary:"The Project Home library: Knowledge Pages and Video Pages, each a folder holding index.html + meta.json.",fields:[{name:"html",type:"string | null"},{name:"mtimeMs",type:"number | null"}]},{id:"settingsScope",name:"Settings (scoped)",group:"config",store:{path:"~/.claude/settings.json + <cwd>/.claude/settings.json + <cwd>/.claude/settings.local.json",format:"json",definedIn:"src/main/config.cjs + src/renderer/state/config.ts + src/renderer/lib/mergeScopes.ts "},summary:"Substrate, not per-Epic curation — model is the one field carved out per-Epic (persona wins over Settings).",fields:[{name:"scope",type:"'system' | 'project' | 'local'",key:"pk"},{name:"cwd",type:"string",optional:!0,key:"fk",ref:"project.cwd"},{name:"model",type:"string",optional:!0}]},{id:"layoutEnvelope",name:"LayoutEnvelope",group:"config",store:{path:"~/.claude/session-manager/workbench-layout.json",format:"json",definedIn:"src/main/layoutStore.cjs + src/renderer/state/layout.ts "},summary:"Persisted dockview panel layout, pruned against the live panel registry on hydrate.",fields:[{name:"version",type:"number"},{name:"panels",type:"string[]",key:"fk",ref:"tab.id"},{name:"dockview",type:"Record<string, unknown>",note:"opaque SerializedDockview blob"}]},{id:"opsNamespace",name:"Ops namespace ownership",aka:"the SINGLE-WRITER LAW",group:"config",store:{path:"src/main/lib/opsOwnership.cjs (OWNERS)",format:"code",definedIn:"src/main/lib/opsOwnership.cjs (assertOpsWrite) "},summary:"Fail-closed — a new top-level ops folder must land in OWNERS (or the deliberately-unowned list) in the same PR that creates it.",fields:[{name:"namespace",type:"string",key:"pk",note:"e.g. 'prompt-sessions', 'scheduler', 'project-brief'"},{name:"writer",type:"string",note:"e.g. 'epics', 'scheduler', 'project-home'"}]},{id:"mcpServerRegistry",name:"MCP server registry",aka:"mcpServers",group:"config",store:{path:"~/.claude.json -> mcpServers",format:"json",definedIn:"src/renderer/components/tabs/McpServers.tsx "},summary:"User-scope MCP server config — no single writer, since both the claude CLI and this app read/write the same file.",fields:[{name:"name",type:"string",key:"pk"},{name:"type",type:"'stdio' | 'http' | 'sse' | 'ws' | 'streamable-http'",optional:!0},{name:"command",type:"string",optional:!0},{name:"args",type:"string[]",optional:!0},{name:"url",type:"string",optional:!0},{name:"env",type:"Record<string, string>",optional:!0},{name:"headers",type:"Record<string, string>",optional:!0},{name:"alwaysLoad",type:"boolean",optional:!0},{name:"enabled",type:"boolean",optional:!0},{name:"disabledTools",type:"string[]",optional:!0}]},{id:"pluginRegistry",name:"Installed plugins manifest",aka:"installed_plugins.json",group:"config",store:{path:"~/.claude/plugins/installed_plugins.json",format:"json",definedIn:"src/renderer/components/tabs/Plugins.tsx "},summary:'Registry of installed plugin versions, keyed by "<name>@<marketplace>" — written by `claude plugin install`, read-only in the Plugins screen.',fields:[{name:"pluginKey",type:"string",key:"pk",note:"<name>@<marketplace>"},{name:"scope",type:"string"},{name:"installPath",type:"string"},{name:"version",type:"string"},{name:"installedAt",type:"string"},{name:"lastUpdated",type:"string"},{name:"gitCommitSha",type:"string",optional:!0}]},{id:"systemPrompt",name:"User CLAUDE.md",aka:"~/.claude/CLAUDE.md",group:"config",store:{path:"~/.claude/CLAUDE.md",format:"markdown",definedIn:"src/renderer/components/tabs/SystemPrompt.tsx "},summary:"The real ~/.claude/CLAUDE.md the claude CLI loads into every session it starts on this machine, in every project — edited here as plain markdown.",fields:[{name:"content",type:"string"},{name:"imports",type:"string[]",note:"@-imported files, listed in a left rail"}]},{id:"skillsAndCommands",name:"Skills & Commands",group:"config",store:{path:"~/.claude/skills/**/SKILL.md + ~/.claude/commands/*.md (and the <cwd>/.claude equivalents for project scope)",format:"directory",definedIn:"src/renderer/components/tabs/Skills.tsx "},summary:"User- and project-scope skill/command markdown files, each editable in place.",fields:[{name:"kind",type:"'skills' | 'commands'"},{name:"scope",type:"'user' | 'project'"},{name:"name",type:"string",key:"pk"},{name:"path",type:"string",note:"absolute path to the editable markdown file"},{name:"dir",type:"string | null",note:"skill directory, if applicable"},{name:"disabled",type:"boolean",note:"skills only — disable-model-invocation: true frontmatter"},{name:"description",type:"string",optional:!0}]},{id:"mcpStatusProbe",name:"MCP status probe",group:"config",store:{path:"in-memory result of `claude mcp list`, never persisted",format:"in-memory",definedIn:"src/main/mcpStatus.cjs (runProbe) "},summary:"Read-only, non-polling live connection probe — models an in-memory-only shape honestly, the same way transcriptEvent does.",fields:[{name:"ok",type:"boolean"},{name:"servers",type:"McpServerStatus[]",note:"{ name, target, transport, status }"},{name:"error",type:"string",optional:!0},{name:"checkedAt",type:"number"}]},{id:"appPrefs",name:"App preferences",aka:"app-prefs / ui-settings-prefs / ui-chrome-prefs",group:"config",store:{path:"~/.claude/session-manager/app-prefs.json + ~/.claude/session-manager/ui-settings-prefs.json + ~/.claude/session-manager/ui-chrome-prefs.json",format:"json",definedIn:"src/renderer/lib/appPrefs.ts (app-prefs.json) + src/renderer/lib/uiSettingsPrefs.ts (ui-settings-prefs.json) + src/renderer/state/uiChromePrefs.ts (ui-chrome-prefs.json) "},summary:"Three small machine-level renderer-owned pref files, read/written through window.api.config — distinct from scheduler-machine.json.",fields:[{name:"openToHomeOnLaunch",type:"boolean",optional:!0,note:"app-prefs.json — read by layout.ts at boot"},{name:"uiSettings",type:"Record<string, unknown>",optional:!0,note:"ui-settings-prefs.json — Settings page UI state"},{name:"uiChrome",type:"Record<string, unknown>",optional:!0,note:"ui-chrome-prefs.json — app chrome UI state"}]},{id:"uiPrefs",name:"UiPrefs",aka:"ui-prefs/prefs.json",group:"config",store:{path:"<cwd>/session-manager-operations/ui-prefs/prefs.json",format:"json",writer:"ui-prefs",definedIn:"src/renderer/lib/uiPrefs.ts "},summary:"Per-project UI state that used to live in scattered global/localStorage keys — one file per project keeps it scoped to the project it belongs to by construction (PRD 1398/1399).",fields:[{name:"fileTreeExpanded",type:"string[]",optional:!0,note:"FileTree.tsx — expanded folder paths in the Files sidebar"},{name:"hiddenCompletedSlugs",type:"string[]",optional:!0,note:'SchedulePanel.tsx — "Clear completed" hides, renderer-side only'},{name:"queueFilterStatus",type:"string",optional:!0,note:"SchedulePanel.tsx — the queue's status filter chip"},{name:"epicPins",type:"Record<string, boolean>",optional:!0,key:"fk",ref:"epic.id",note:"epicsPrefs.ts — pinned-to-top Epic ids, keyed by epicId (moved off the global epics-prefs.json)"},{name:"chatVerbosityPerEpic",type:"Record<string, ChatVerbosity>",optional:!0,key:"fk",ref:"epic.id",note:"chatPrefs.ts — per-Epic verbosity overrides, keyed by epicId (moved off the global chat-prefs.json)"},{name:"editorSession",type:"{ openFiles: string[]; activeFilePath: string | null; viewModeByPath: Record<string, string> }",optional:!0,note:"editor.ts — the Editor scene's structural tab strip only; buffers/baselines/dirty are never persisted (PRD 1400)"}]}];function te(t){const n=B.find(s=>s.id===t);if(!n)throw new Error(`unknown ErdEntity id: ${t}`);return n}const je=[{from:"tab",to:"project",cardinality:"N-1",label:"belongs to"},{from:"epic",to:"project",cardinality:"N-1",label:"belongs to"},{from:"epic",to:"tag",cardinality:"N-1",label:"mission",optional:!0},{from:"epic",to:"agentPersona",cardinality:"N-1",label:"actor",optional:!0},{from:"epic",to:"epic",cardinality:"N-1",label:"resumed from",optional:!0},{from:"epic",to:"claudeTranscript",cardinality:"1-1",label:"1:1 session"},{from:"epicEvent",to:"epic",cardinality:"N-1",label:"belongs to"},{from:"epicEvent",to:"epicEvent",cardinality:"N-1",label:"caused by",optional:!0},{from:"epicEvent",to:"prd",cardinality:"N-1",label:"about",optional:!0},{from:"epicTranscriptTurn",to:"epic",cardinality:"N-1",label:"belongs to"},{from:"epicTranscriptTurn",to:"epicEvent",cardinality:"N-1",label:"labeled by",optional:!0},{from:"epicArchive",to:"epic",cardinality:"1-1",label:"freezes"},{from:"exchange",to:"epic",cardinality:"N-1",label:"session for",optional:!0},{from:"exchange",to:"project",cardinality:"N-1",label:"belongs to"},{from:"prd",to:"epic",cardinality:"N-1",label:"joins (directory fact)"},{from:"prd",to:"epic",cardinality:"N-1",via:"sourcePromptId",label:"authored from (frontmatter intent)",optional:!0},{from:"prd",to:"project",cardinality:"N-1",label:"belongs to"},{from:"prd",to:"tag",cardinality:"N-1",label:"mission",optional:!0},{from:"scheduleJob",to:"prd",cardinality:"1-1",label:"executes"},{from:"scheduleJob",to:"prd",cardinality:"N-N",via:"dependsOn",label:"depends on",optional:!0},{from:"scheduleJob",to:"epic",cardinality:"N-1",label:"belongs to",optional:!0},{from:"scheduleJob",to:"runLog",cardinality:"N-1",label:"ran as",optional:!0},{from:"scheduleJob",to:"scheduleJob",cardinality:"N-N",via:"dependsOn",label:"depends on (self)",optional:!0},{from:"scheduleJobStatusHistory",to:"scheduleJob",cardinality:"N-1",label:"transitions of"},{from:"scheduleHistoryEntry",to:"prd",cardinality:"N-1",label:"archives"},{from:"scheduleHistoryEntry",to:"epic",cardinality:"N-1",label:"belongs to",optional:!0},{from:"scheduleHistoryEntry",to:"runLog",cardinality:"N-1",label:"ran as",optional:!0},{from:"scheduleConfig",to:"project",cardinality:"1-1",label:"configures"},{from:"agentPersona",to:"tag",cardinality:"N-N",label:"tagged with"},{from:"agentPersona",to:"project",cardinality:"N-N",label:"scoped to"},{from:"memoryEntry",to:"project",cardinality:"N-1",label:"workspace"},{from:"memoryCluster",to:"memoryEntry",cardinality:"1-N",label:"clusters"},{from:"agentMemoryEntry",to:"agentPersona",cardinality:"N-1",label:"belongs to"},{from:"transcriptEvent",to:"tab",cardinality:"N-1",label:"classified for"},{from:"transcriptEvent",to:"claudeTranscript",cardinality:"N-1",label:"classified from"},{from:"claudeTranscript",to:"project",cardinality:"N-1",label:"belongs to"},{from:"historyRollupDay",to:"project",cardinality:"N-N",label:"aggregates"},{from:"billingUsage",to:"scheduleConfig",cardinality:"1-N",label:"gates when-available firing"},{from:"projectBrief",to:"project",cardinality:"1-1",label:"describes"},{from:"projectBrief",to:"epic",cardinality:"N-1",via:"areas[].epic",label:"traces to",optional:!0},{from:"projectPages",to:"project",cardinality:"1-1",label:"generated for"},{from:"settingsScope",to:"project",cardinality:"N-1",label:"scoped to",optional:!0},{from:"layoutEnvelope",to:"tab",cardinality:"1-N",label:"panels for"},{from:"opsNamespace",to:"epic",cardinality:"1-N",label:"governs writes"},{from:"opsNamespace",to:"prd",cardinality:"1-N",label:"governs writes"},{from:"opsNamespace",to:"projectBrief",cardinality:"1-N",label:"governs writes"}];function ve(t){return je.filter(n=>n.from===t||n.to===t)}function Tt(t){const n=new Set;for(const s of ve(t)){const r=s.from===t?s.to:s.from;r!==t&&n.add(r)}return[...n]}function It(t){switch(t){case"1-1":return"1—1";case"1-N":return"1—N";case"N-1":return"N—1";case"N-N":return"N—N"}}const fe=220,Q=7,Pt=44,Rt=16,At=10,Mt=96,Lt=28,W=24;function Ot(t){const n=Math.min(t,Q)+(t>Q?1:0);return Pt+n*Rt+At}function Dt(t){const n=t.x+t.w,s=t.y+t.h*.35,r=t.y+t.h*.65,i=n+48;return{d:`M ${n} ${s} C ${i} ${s}, ${i} ${r}, ${n} ${r}`,mx:i,my:(s+r)/2}}function $t(t=B,n=je){const s=q.map(p=>p.id).filter(p=>t.some(f=>f.group===p)),r=[],i=new Map;s.forEach((p,f)=>{const m=W+f*(fe+Mt);let c=W;for(const g of t){if(g.group!==p)continue;const j=Ot(g.fields.length),v={id:g.id,group:p,x:m,y:c,w:fe,h:j};r.push(v),i.set(g.id,v),c+=j+Lt}});const a=new Set(t.map(p=>p.id)),d=[];for(const p of n){if(!a.has(p.from)||!a.has(p.to))continue;const f=i.get(p.from),m=i.get(p.to);if(!f||!m)continue;if(p.from===p.to){const T=Dt(f);d.push({relation:p,...T});continue}const c=f.x<m.x,g=c?f.x+f.w:f.x,j=f.y+f.h/2,v=c?m.x:m.x+m.w,N=m.y+m.h/2,S=Math.max(40,Math.abs(v-g)/2),h=g+(c?S:-S),w=v+(c?-S:S),C=`M ${g} ${j} C ${h} ${j}, ${w} ${N}, ${v} ${N}`;d.push({relation:p,d:C,mx:(g+v)/2,my:(j+N)/2})}const u=r.reduce((p,f)=>Math.max(p,f.x+f.w),0),y=r.reduce((p,f)=>Math.max(p,f.y+f.h),0);return{boxes:r,edges:d,width:u+W,height:y+W}}const _t=[{key:"diagram",label:"Diagram"},{key:"tables",label:"Tables"}];function Ht(){const[t,n]=o.useState("diagram"),[s,r]=o.useState(null),[i,a]=o.useState(()=>new Set),d=o.useMemo(()=>B.filter(m=>!i.has(m.group)),[i]),u=o.useMemo(()=>$t(d),[d]),y=m=>{a(c=>{const g=new Set(c);return g.has(m)?g.delete(m):g.add(m),g}),r(null)},p=s?te(s):null,f=m=>d.some(c=>c.id===m);return e.jsx(nt,{toolbar:e.jsxs(e.Fragment,{children:[e.jsx(xe,{options:_t,active:t,onChange:n}),e.jsx(Ft,{hiddenGroups:i,onToggle:y}),e.jsxs("span",{className:"ml-auto text-fg-faint",children:[B.length," entities"]})]}),children:t==="diagram"?e.jsxs("div",{className:"h-full flex",children:[e.jsx("div",{className:"flex-1 min-w-0 overflow-auto",children:e.jsx(Ut,{layout:u,selectedId:s,onSelect:m=>r(c=>c===m?null:m)})}),e.jsx("div",{className:"w-96 shrink-0 border-l border-line overflow-y-auto",children:p?e.jsx(Wt,{entity:p,onSelectRelated:m=>f(m)?r(m):void 0}):e.jsx(G,{title:"select an entity",hint:"click a box in the diagram to see its storage, fields, and relations"})})]}):e.jsx(Jt,{})})}const Bt=o.memo(Ht);function Ft({hiddenGroups:t,onToggle:n}){return e.jsx("div",{className:"flex items-center gap-1.5 flex-wrap",children:q.map(s=>{const r=t.has(s.id);return e.jsxs("button",{onClick:()=>n(s.id),title:`${s.blurb} (${s.realm})`,className:`flex items-center gap-1 px-1.5 py-0.5 rounded border text-[10.5px] ${r?"border-line text-fg-faint opacity-50":"border-line text-fg-dim hover:text-fg"}`,children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${s.tone.dot}`}),s.label,e.jsx("span",{className:"text-fg-faint",children:s.realm})]},s.id)})})}function Ut({layout:t,selectedId:n,onSelect:s}){const r=o.useMemo(()=>n?new Set(Tt(n)):null,[n]),i=a=>!!n&&(a.relation.from===n||a.relation.to===n);return t.boxes.length===0?e.jsx(G,{title:"no entities in view",hint:"toggle a group in the legend to show its entities"}):e.jsxs("div",{className:"relative p-4",style:{width:t.width+32,height:t.height+32},children:[e.jsxs("svg",{width:t.width,height:t.height,className:"absolute left-4 top-4 overflow-visible",children:[t.edges.map(a=>{const d=i(a);return e.jsx("path",{"data-testid":`erd-edge-${a.relation.from}-${a.relation.to}`,d:a.d,fill:"none",className:d?"stroke-accent":"stroke-line",strokeWidth:d?2:1,opacity:n&&!d?.25:1},`${a.relation.from}-${a.relation.to}-${a.relation.label}`)}),t.edges.map(a=>i(a)?e.jsx("text",{x:a.mx,y:a.my,textAnchor:"middle",className:"fill-fg-dim text-[10px]",children:a.relation.label},`label-${a.relation.from}-${a.relation.to}-${a.relation.label}`):null)]}),t.boxes.map(a=>e.jsx(zt,{box:a,selected:a.id===n,dimmed:!!n&&a.id!==n&&!(r!=null&&r.has(a.id)),onClick:()=>s(a.id)},a.id))]})}function zt({box:t,selected:n,dimmed:s,onClick:r}){const i=te(t.id),a=be(t.group),d=i.fields.slice(0,Q),u=i.fields.length-d.length;return e.jsxs("button",{type:"button","data-testid":`erd-box-${t.id}`,onClick:r,className:`absolute text-left rounded border overflow-hidden bg-bg-hi ${n?"border-accent ring-1 ring-accent":"border-line"} ${s?"opacity-30":""}`,style:{left:t.x,top:t.y,width:t.w,height:t.h},children:[e.jsxs("div",{className:"px-2 py-1 border-b border-line flex items-center gap-1.5",children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${a.tone.dot}`}),e.jsx("span",{className:"text-[11px] font-semibold text-fg truncate",children:i.name})]}),i.aka&&e.jsx("div",{className:"px-2 pt-0.5 text-[9.5px] text-fg-faint truncate",children:i.aka}),e.jsxs("div",{className:"px-2 py-0.5",children:[d.map(y=>e.jsxs("div",{className:"text-[9.5px] font-mono text-fg-dim truncate flex items-center gap-1",children:[y.key&&e.jsx("span",{className:"text-fg-faint",children:y.key}),e.jsx("span",{className:"truncate",children:y.name})]},y.name)),u>0&&e.jsxs("div",{className:"text-[9.5px] text-fg-faint italic",children:["+",u," more"]})]})]})}function we({fields:t}){return e.jsxs("table",{className:"w-full text-[11px] font-mono",children:[e.jsx("thead",{className:"text-fg-faint uppercase tracking-wide text-[9.5px]",children:e.jsxs("tr",{className:"border-b border-line",children:[e.jsx("th",{className:"text-left font-normal px-2 py-1",children:"name"}),e.jsx("th",{className:"text-left font-normal px-2 py-1",children:"type"}),e.jsx("th",{className:"text-left font-normal px-2 py-1",children:"key"}),e.jsx("th",{className:"text-left font-normal px-2 py-1",children:"note"})]})}),e.jsx("tbody",{children:t.map(n=>e.jsxs("tr",{className:"border-b border-line/50",children:[e.jsxs("td",{className:"px-2 py-1 text-fg",children:[n.name,n.optional&&e.jsx("span",{className:"text-fg-faint",children:"?"})]}),e.jsx("td",{className:"px-2 py-1 text-fg-dim",children:n.type}),e.jsx("td",{className:"px-2 py-1",children:n.key&&e.jsxs(L,{tone:n.key==="pk"?"accent":"dim",children:[n.key,n.ref?` → ${n.ref}`:""]})}),e.jsx("td",{className:"px-2 py-1 text-fg-faint",children:n.note})]},n.name))})]})}function ke({entity:t}){return e.jsxs("div",{className:"space-y-1 text-[11px]",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-fg-faint w-20 shrink-0",children:"path"}),e.jsx("span",{className:"font-mono text-fg-dim break-all",children:t.store.path})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-fg-faint w-20 shrink-0",children:"format"}),e.jsx("span",{className:"font-mono text-fg-dim",children:t.store.format})]}),t.store.writer&&e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-fg-faint w-20 shrink-0",children:"writer"}),e.jsxs(L,{tone:"accent",children:["single-writer: ",t.store.writer]})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-fg-faint w-20 shrink-0",children:"definedIn"}),e.jsx("span",{className:"font-mono text-fg-dim break-all",children:t.store.definedIn})]})]})}function Wt({entity:t,onSelectRelated:n}){const s=be(t.group),r=ve(t.id);return e.jsxs("div",{className:"p-3 space-y-3",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:`w-2 h-2 rounded-full ${s.tone.dot}`}),e.jsx("span",{className:"text-sm font-semibold text-fg",children:t.name})]}),t.aka&&e.jsx("div",{className:"text-[10.5px] text-fg-faint",children:t.aka}),e.jsx(L,{tone:"dim",className:"mt-1",children:s.label})]}),e.jsx("div",{className:"text-xs text-fg-dim leading-relaxed",children:t.summary}),e.jsxs("div",{children:[e.jsx(J,{children:"storage"}),e.jsx(ke,{entity:t})]}),e.jsxs("div",{children:[e.jsx(J,{children:"fields"}),e.jsx(we,{fields:t.fields})]}),t.notes&&t.notes.length>0&&e.jsxs("div",{children:[e.jsx(J,{children:"notes"}),e.jsx("ul",{className:"list-disc pl-4 space-y-0.5 text-xs text-fg-dim",children:t.notes.map(i=>e.jsx("li",{children:i},i))})]}),e.jsxs("div",{children:[e.jsx(J,{children:"relations"}),r.length===0?e.jsx("div",{className:"text-xs text-fg-faint italic",children:"no relations"}):e.jsx("ul",{className:"space-y-1",children:r.map(i=>{const a=i.from===t.id?i.to:i.from,d=te(a);return e.jsxs("li",{className:"flex items-center gap-1.5 text-xs",children:[e.jsx("span",{className:"font-mono text-fg-faint w-10 shrink-0",children:It(i.cardinality)}),e.jsx("span",{className:"text-fg-dim",children:i.label}),i.via&&e.jsxs("span",{className:"font-mono text-[10px] text-fg-faint",children:["via ",i.via]}),e.jsx("button",{type:"button",onClick:()=>n(a),className:"ml-auto text-accent hover:underline font-mono",children:d.name})]},`${i.from}-${i.to}-${i.label}`)})})]})]})}function J({children:t}){return e.jsx("div",{className:"text-[10.5px] uppercase tracking-wide text-fg-faint mb-1 font-mono",children:t})}function Jt(){return e.jsx("div",{className:"p-4 space-y-6",children:q.map(t=>{const n=B.filter(s=>s.group===t.id);return n.length===0?null:e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-2",children:[e.jsx("span",{className:`w-2 h-2 rounded-full ${t.tone.dot}`}),e.jsx("span",{className:"text-xs font-semibold text-fg",children:t.label}),e.jsx("span",{className:"text-[10.5px] text-fg-faint",children:t.realm})]}),e.jsx("div",{className:"grid grid-cols-1 xl:grid-cols-2 gap-3",children:n.map(s=>e.jsxs("div",{className:"border border-line rounded bg-bg-hi p-3 space-y-2",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-semibold text-fg",children:s.name}),s.aka&&e.jsx("span",{className:"text-[10.5px] text-fg-faint",children:s.aka})]}),e.jsx(L,{tone:"dim",className:"mt-1",children:t.label})]}),e.jsx("div",{className:"text-xs text-fg-dim leading-relaxed",children:s.summary}),e.jsx(ke,{entity:s}),e.jsx(we,{fields:s.fields}),s.notes&&s.notes.length>0&&e.jsx("ul",{className:"list-disc pl-4 space-y-0.5 text-xs text-fg-dim",children:s.notes.map(r=>e.jsx("li",{children:r},r))})]},s.id))})]},t.id)})})}const ge=[{key:"voice",label:"Voice"},{key:"appearance",label:"Appearance"},{key:"telemetry",label:"Telemetry"},{key:"remote",label:"Phone remote"},{key:"updates",label:"Updates & retention"},{key:"startup",label:"Startup"},{key:"storage",label:"Storage map"}],Vt={compact:"Compact",roomy:"Roomy"},Gt=".claude/session-manager";function qt({files:t}){const n=qe();return e.jsx("div",{className:"flex flex-wrap gap-2 px-4 pt-3","data-testid":"app-settings-chips",children:t.map(s=>{const r=s.path.startsWith("~/")?n?n+s.path.slice(1):null:s.path;return r?e.jsx(Qe,{path:r,keyPath:s.keyPath},s.path):null})})}function Yt(){const[t,n]=o.useState(!1),[s,r]=o.useState(!1);o.useEffect(()=>{let a=!0;return Ke().then(d=>{a&&n(d.openToHomeOnLaunch===!0)}),()=>{a=!1}},[]);const i=async a=>{n(a),r(!0);try{await Ze({openToHomeOnLaunch:a})}catch{n(!a),he.error('Failed to save "Open to Home on launch" — try again.')}finally{r(!1)}};return e.jsx("div",{className:"p-4 max-w-3xl space-y-3 text-sm",children:e.jsx(D,{checked:t,onChange:i,disabled:s,label:"Open to Home on launch"})})}function Xt(){const{density:t,setDensity:n}=Ye();return e.jsxs("div",{className:"p-4 max-w-3xl space-y-5 text-sm",children:[e.jsx(pt,{}),e.jsxs("section",{className:"border border-line rounded p-3 space-y-1",children:[e.jsx("span",{className:"text-fg-dim text-xs",children:"Density"}),e.jsx(Xe,{options:["compact","roomy"],value:t,onChange:s=>n(s),labels:Vt}),e.jsx("span",{className:"text-fg-faint text-[11px]",children:"Compact tightens spacing across the app's chrome; Roomy is the default."})]})]})}const O=(t,n)=>({path:`~/${Gt}/${t}`,keyPath:n}),Kt={voice:[O("voice.json")],appearance:[{path:Ge,keyPath:["terminal"]},O("ui-chrome-prefs.json")],telemetry:[O("telemetry.json"),O("otel.json")],remote:[O("web-remote.json")],updates:[O("updater.json"),O("ops-retention.json")],startup:[{path:Ve,keyPath:["openToHomeOnLaunch"]}],storage:[]};function rn(){const[t,n]=o.useState("voice");return Je("app-settings",s=>{ge.some(r=>r.key===s)&&n(s)}),e.jsxs("div",{className:"flex flex-col h-full min-h-0","data-testid":"app-settings",children:[e.jsx("div",{className:"flex items-center px-4 pt-3",children:e.jsx(xe,{options:ge,active:t,onChange:n})}),e.jsx(qt,{files:Kt[t]}),e.jsxs("div",{className:"flex-1 min-h-0 overflow-auto","data-testid":`app-settings-${t}`,children:[t==="voice"&&e.jsx(rt,{open:!0,onClose:()=>{},variant:"page"}),t==="appearance"&&e.jsx(Xt,{}),t==="telemetry"&&e.jsx(gt,{}),t==="remote"&&e.jsx(wt,{}),t==="updates"&&e.jsxs("div",{className:"p-4 max-w-3xl space-y-5",children:[e.jsx(kt,{}),e.jsx(Et,{})]}),t==="startup"&&e.jsx(Yt,{}),t==="storage"&&e.jsx(Bt,{})]})]})}export{rn as AppSettings};
1
+ import{aB as e,x as Ae,o as Me,bz as P,aR as o,aw as Le,$ as De,v as Oe,aE as oe,D as $e,aD as _e,a4 as le,a3 as de,a5 as V,a$ as He,a2 as Be,m as G,a6 as Fe,ag as Ue,ba as he,a1 as ze,b as H,by as ee,c as L,be as We,bq as Je,a as Ve,a8 as Ge,bl as qe,bh as Ye,e as Xe,aS as Ke,bD as Ze}from"./index-C-d0DCre.js";import{T as O,V as xe,S as Qe}from"./ViewTabs-C0PRZx4_.js";import{V as et,T as tt}from"./VoiceButton-D2rMurNg.js";import{P as nt}from"./Panel-Csyd9HbD.js";import"./monaco-editor-BsIlgG7c.js";function st({open:t,onClose:n,title:s,children:r,variant:i="overlay"}){return e.jsxs(Ae,{open:t,onClose:n,size:"xl",fillHeight:!0,noPadding:!0,title:void 0,variant:i,children:[i==="overlay"&&e.jsxs("div",{className:"flex items-center justify-between px-4 py-2 border-b border-line shrink-0",children:[e.jsx("h2",{className:"text-xs uppercase tracking-wider text-fg-dim",children:s}),e.jsx("button",{type:"button",onClick:n,"aria-label":"Close",className:"px-2 py-0.5 text-fg-dim hover:text-fg hover:bg-bg-hi rounded text-base leading-none",children:"✕"})]}),e.jsx("div",{className:"flex-1 min-h-0 overflow-auto",children:e.jsx(Me,{children:r})})]})}function at(){const t=P(g=>g.isRecording),n=P(g=>g.levelMeterEnabled),[s,r]=o.useState(0),[i,a]=o.useState(0),d=o.useRef(0);d.current=i;const[u,y]=o.useState(0),[p,f]=o.useState(!1),m=o.useRef(null);if(o.useEffect(()=>{if(!t||!n){r(0),a(0);return}let g=0,j=!1,v=null,N=null;const S=()=>{if(j)return;const w=N??Le();if(!w){g=requestAnimationFrame(S);return}N!==w&&(N=w,v=new Uint8Array(new ArrayBuffer(w.fftSize)));const C=v;w.getByteTimeDomainData(C);let T=0;for(let R=0;R<C.length;R++){const F=C[R]-128;T+=F*F}const E=Math.sqrt(T/C.length)/128,b=E>0?20*Math.log10(E):-60,k=Math.max(0,Math.min(1,(b+60)/60));a(E),r(k),E>=.95&&(f(!0),m.current&&clearTimeout(m.current),m.current=setTimeout(()=>f(!1),150)),g=requestAnimationFrame(S)};g=requestAnimationFrame(S);const h=setInterval(()=>{j||y(Math.round(d.current*100))},250);return()=>{j=!0,cancelAnimationFrame(g),clearInterval(h),m.current&&(clearTimeout(m.current),m.current=null)}},[t,n]),!t||!n)return null;const c=p?"bg-red-500":i>=.7?"bg-amber-400":"bg-green-500";return e.jsx("div",{role:"meter","aria-label":"Microphone input level","aria-valuenow":u,"aria-valuemin":0,"aria-valuemax":100,"data-testid":"mic-level-meter",className:`mx-3 mb-2 h-1 rounded bg-bg overflow-hidden ${p?"ring-1 ring-red-500":""}`,children:e.jsx("div",{className:`h-full ${c} transition-[width] duration-75 ease-out`,style:{width:`${s*100}%`}})})}function rt({open:t,onClose:n,variant:s="overlay"}){return e.jsx(st,{open:t,onClose:n,title:"Voice / Microphone",variant:s,children:e.jsxs("div",{className:"p-4 space-y-4",children:[e.jsx(dt,{}),e.jsx(De,{}),e.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[e.jsx(et,{}),e.jsx(Oe,{}),e.jsx(tt,{})]}),e.jsx(it,{}),e.jsxs("div",{className:"flex items-center gap-4 flex-wrap",children:[e.jsx("button",{type:"button",onClick:()=>P.getState().openWizard(),className:"text-xs text-fg-faint hover:text-fg-dim underline","data-testid":"run-mic-check",children:"Run mic check"}),e.jsx(lt,{})]}),e.jsx(at,{})]})})}function it(){const t=P(a=>a.isRecording),[n,s]=o.useState(null);if(o.useEffect(()=>{let a=!1;window.api.voice.getHotkeyConfig().then(u=>{a||s(u)}).catch(()=>{});const d=window.api.voice.onHotkeyConfigChanged(u=>s(u));return()=>{a=!0,d()}},[]),t||!n)return null;const r=n.mode==="hold"?"Hold":"Press",i=ot(n.accelerator);return e.jsxs("div",{className:"text-[11px] text-fg-faint",children:[e.jsxs("span",{children:[r," "]}),e.jsx("kbd",{className:"px-1 py-0.5 rounded border border-line bg-bg font-mono text-fg-dim",children:i}),e.jsx("span",{children:" to record"})]})}function ot(t){const n=typeof navigator<"u"&&/Mac/.test(navigator.platform);return t.replace(/CommandOrControl/g,n?"⌘":"Ctrl").replace(/CmdOrCtrl/g,n?"⌘":"Ctrl").replace(/Command/g,"⌘").replace(/Control/g,"Ctrl").replace(/Option/g,n?"⌥":"Alt").replace(/Shift/g,n?"⇧":"Shift")}function lt(){const[t,n]=o.useState(null);if(o.useEffect(()=>{let r=!1;window.api.voice.getHotkeyConfig().then(a=>{r||n(a)}).catch(a=>oe.warn("voice-hotkey","getHotkeyConfig (toggle) failed",{error:String(a)}));const i=window.api.voice.onHotkeyConfigChanged(a=>{n(a)});return()=>{r=!0,i()}},[]),!t)return null;const s=async r=>{if(t.mode===r)return;const i={...t,mode:r};n(i);try{await window.api.voice.setHotkeyConfig(i)}catch(a){oe.warn("voice-hotkey","setHotkeyConfig (toggle) failed",{error:a instanceof Error?a.message:String(a)})}};return e.jsxs("div",{className:"flex items-center gap-3 text-[11px] text-fg-faint select-none",title:"Mic hotkey behavior. Tap on/off: press once to start, again to stop. Hold to talk: record only while held (push-to-talk).",children:[e.jsxs("label",{className:"flex items-center gap-1 cursor-pointer hover:text-fg-dim",children:[e.jsx("input",{type:"radio",name:"hotkey-mode",checked:t.mode==="toggle",onChange:()=>s("toggle"),className:"cursor-pointer","data-testid":"hotkey-mode-toggle"}),e.jsx("span",{children:"Tap on/off"})]}),e.jsxs("label",{className:"flex items-center gap-1 cursor-pointer hover:text-fg-dim",children:[e.jsx("input",{type:"radio",name:"hotkey-mode",checked:t.mode==="hold",onChange:()=>s("hold"),className:"cursor-pointer","data-testid":"hotkey-mode-hold"}),e.jsx("span",{children:"Hold to talk"})]})]})}function dt(){const t=P(a=>a.isRecording),n=P(a=>a.lastTranscript),s=P(a=>a.error),r=P(a=>a.modelStatus),i=P(a=>a.loadingProgress);return s?e.jsxs("div",{className:"text-[11px] text-red-400",title:s,children:["⚠ ",s]}):t?e.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-fg-dim border border-line rounded px-2 py-1.5",children:[e.jsx("span",{className:"inline-block w-2 h-2 rounded-full bg-red-400 animate-pulse shrink-0"}),e.jsx("span",{className:"truncate",title:n,children:n||"Listening…"})]}):r==="loading"?e.jsxs("div",{className:"text-[11px] text-fg-faint",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("span",{children:"Loading speech model"}),e.jsxs("span",{className:"font-mono",children:[i,"%"]})]}),e.jsx("div",{className:"h-1 rounded bg-bg overflow-hidden",children:e.jsx("div",{className:"h-full bg-accent transition-[width] duration-200",style:{width:`${i}%`}})})]}):null}const ct=["dark","light","paper"];function pt(){const[t,n]=o.useState($e),[s,r]=o.useState(!1);o.useEffect(()=>{let d=!1;return _e().then(u=>{d||(n(u),r(!0))}),()=>{d=!0}},[]);const i=d=>{s&&n(u=>{const y={...u,...d};return He(y),y})},a=d=>{i({fontSize:Math.min(de,Math.max(le,t.fontSize+d))})};return e.jsxs("section",{className:"mb-6","data-testid":"home-terminal-appearance",children:[e.jsxs("div",{className:"flex items-baseline justify-between mb-3",children:[e.jsx("h2",{className:"m-0 font-serif text-[22px] font-medium",children:"Terminal appearance"}),e.jsx("span",{className:"font-mono text-[12px] text-fg-faint",children:"every terminal, this machine"})]}),e.jsxs("div",{className:"border border-line rounded-xl bg-bg-hi px-5 py-4",children:[e.jsxs("p",{className:"mt-0 mb-4 text-[13px] text-fg-dim leading-relaxed",children:["Applies to ",e.jsx("strong",{className:"text-fg",children:"every terminal in the app at once"})," — project Terminal tabs, an Epic’s Terminal view of its session, and the inline permission prompt. It is not per project, per session, or per tab. It does not restyle the app chrome (there is no app theme switch), and the code editor keeps its own separate paper/dark setting in the Editor tab’s Display menu. Stored in"," ",e.jsx("code",{className:"font-mono text-[12px]",children:"~/.claude/session-manager/ui-settings-prefs.json"}),", applied live without restarting a session."]}),e.jsxs("div",{className:"grid gap-5",style:{gridTemplateColumns:"minmax(0,1fr) 220px"},children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wider text-fg-faint mb-1.5",children:"Theme"}),e.jsx("div",{className:"grid grid-cols-3 gap-2",children:ct.map(d=>e.jsxs("button",{type:"button",onClick:()=>i({theme:d}),disabled:!s,"aria-pressed":t.theme===d,"data-testid":`terminal-theme-${d}`,className:`px-2 py-2 rounded-lg text-[11px] font-medium border transition-colors disabled:opacity-40 disabled:cursor-not-allowed ${t.theme===d?"bg-bg border-accent text-fg":"bg-bg border-line text-fg-dim hover:text-fg hover:border-fg-faint"}`,children:[e.jsx(mt,{theme:d}),e.jsx("div",{className:"mt-1.5 capitalize",children:d})]},d))})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[e.jsx("span",{className:"text-[10px] uppercase tracking-wider text-fg-faint",children:"Font size"}),e.jsxs("span",{className:"font-mono text-[11px] text-fg-dim",children:[t.fontSize,"px"]})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("button",{type:"button",onClick:()=>a(-1),disabled:!s||t.fontSize<=le,"aria-label":"Decrease font size",className:"flex-1 py-1.5 rounded border border-line bg-bg text-fg-dim hover:text-fg hover:border-fg-faint disabled:opacity-40 disabled:cursor-not-allowed",children:"−"}),e.jsx("button",{type:"button",onClick:()=>i({fontSize:Be}),disabled:!s,className:"flex-1 py-1.5 rounded border border-line bg-bg text-[11px] text-fg-dim hover:text-fg hover:border-fg-faint disabled:opacity-40 disabled:cursor-not-allowed",children:"reset"}),e.jsx("button",{type:"button",onClick:()=>a(1),disabled:!s||t.fontSize>=de,"aria-label":"Increase font size",className:"flex-1 py-1.5 rounded border border-line bg-bg text-fg-dim hover:text-fg hover:border-fg-faint disabled:opacity-40 disabled:cursor-not-allowed",children:"+"})]}),e.jsxs("div",{className:"mt-3 rounded border border-line px-3 py-2 font-mono",style:{background:V[t.theme].background,color:V[t.theme].foreground,fontSize:`${t.fontSize}px`,lineHeight:1.35},"aria-hidden":!0,children:[e.jsx("span",{style:{color:V[t.theme].green},children:"$"})," claude"]})]})]})]})]})}function mt({theme:t}){const n=V[t];return e.jsxs("div",{"aria-hidden":!0,className:"w-full h-5 rounded border relative overflow-hidden",style:{background:n.background,borderColor:"rgba(0,0,0,0.15)"},children:[e.jsx("div",{style:{position:"absolute",top:3,left:4,width:"40%",height:2,background:n.foreground}}),e.jsx("div",{style:{position:"absolute",top:9,left:4,width:"25%",height:2,background:n.green??n.foreground}}),e.jsx("div",{style:{position:"absolute",top:15,left:4,width:"55%",height:2,background:n.cyan??n.foreground}})]})}const ut=1440*60*1e3;function ft(t){if(!t)return"never";const n=new Date(t).getTime();return Number.isNaN(n)?"never":new Date(n).toLocaleString()}function ce(t){return t?new Date(t).toLocaleString():"never"}function gt(){return e.jsxs("div",{className:"p-4 max-w-3xl space-y-8 text-sm",children:[e.jsx(ht,{}),e.jsx("hr",{className:"border-line"}),e.jsx(xt,{})]})}function ht(){const[t,n]=o.useState(null),[s,r]=o.useState(null),[i,a]=o.useState(null),[d,u]=o.useState(null),[y,p]=o.useState(!1),[f,m]=o.useState(null),[c,g]=o.useState(null);if(o.useEffect(()=>{let h=!1;return Promise.all([window.api.otel.getConfig(),window.api.otel.status(),window.api.otel.configPath()]).then(([w,C,T])=>{h||(n(w),a(w),r(C),u(T))}).catch(w=>{console.warn("[telemetry] load failed:",w==null?void 0:w.message)}),()=>{h=!0}},[]),!i||!t)return e.jsx(G,{title:"loading…"});const j=JSON.stringify(i)!==JSON.stringify(t),v=(h,w)=>{m(null),a({...i,[h]:w})},N=async()=>{p(!0),m(null);try{const h=await window.api.otel.setConfig(i);!h.ok&&h.error&&m(h.error),n(h.config),a(h.config),r(h.status),g(Date.now())}catch(h){m(h instanceof Error?h.message:String(h))}finally{p(!1)}},S=()=>{m(null),a(t)};return e.jsxs("div",{className:"space-y-5",children:[e.jsxs("header",{className:"space-y-1",children:[e.jsx("h2",{className:"text-fg text-base font-medium",children:"OpenTelemetry export"}),e.jsx("p",{className:"text-fg-dim text-xs leading-relaxed",children:"When enabled, every classified transcript event (tool_use, todo_write, plan, usage, agent_spawn) is mirrored as a 0-duration OTLP/HTTP span. Point this at a local collector (Jaeger, Grafana Tempo, SigNoz, Honeycomb) for cross-session analysis."}),d&&e.jsxs("p",{className:"text-fg-faint text-[11px]",children:["stored at ",e.jsx("span",{className:"font-mono",children:d})]})]}),e.jsxs("section",{className:"border border-line rounded p-3 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-fg",children:"Export transcripts to OTEL"}),e.jsx("div",{className:"text-fg-faint text-xs",children:"Toggle off to disable all span emission immediately."})]}),e.jsx(O,{checked:i.enabled,onChange:h=>v("enabled",h),label:i.enabled?"on":"off"})]}),e.jsxs("label",{className:"block space-y-1",children:[e.jsx("span",{className:"text-fg-dim text-xs",children:"OTLP/HTTP traces endpoint"}),e.jsx("input",{type:"text",value:i.endpoint,onChange:h=>v("endpoint",h.target.value),placeholder:"http://localhost:4318/v1/traces",className:"w-full bg-bg border border-line rounded px-2 py-1 text-fg font-mono text-xs"})]}),e.jsxs("label",{className:"block space-y-1",children:[e.jsxs("span",{className:"text-fg-dim text-xs",children:["Headers (newline-separated ",e.jsx("span",{className:"font-mono",children:"Key: Value"}),")"]}),e.jsx("textarea",{value:i.headers,onChange:h=>v("headers",h.target.value),placeholder:"x-honeycomb-team: YOUR_API_KEY",rows:3,className:"w-full bg-bg border border-line rounded px-2 py-1 text-fg font-mono text-xs"})]}),e.jsxs("label",{className:"block space-y-1",children:[e.jsx("span",{className:"text-fg-dim text-xs",children:"Service name"}),e.jsx("input",{type:"text",value:i.serviceName,onChange:h=>v("serviceName",h.target.value),placeholder:"session-manager",className:"w-full bg-bg border border-line rounded px-2 py-1 text-fg font-mono text-xs"})]}),e.jsxs("div",{className:"flex items-start justify-between gap-3 pt-1",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-fg",children:"Include content (PII)"}),e.jsxs("div",{className:"text-fg-faint text-xs leading-relaxed",children:["Adds tool inputs, plan text, and agent prompts to span attributes. Off by default — matches upstream Claude Code's ",e.jsx("span",{className:"font-mono",children:"OTEL_LOG_USER_PROMPTS"})," opt-in."]})]}),e.jsx(O,{checked:i.includeContent,onChange:h=>v("includeContent",h),label:i.includeContent?"on":"off"})]})]}),s&&e.jsxs("section",{className:"border border-line rounded p-3 text-xs space-y-1",children:[e.jsx("div",{className:"text-fg-dim",children:"Runtime status"}),e.jsxs("div",{children:[e.jsx("span",{className:"text-fg-faint",children:"enabled:"})," ",e.jsx("span",{className:s.enabled?"text-accent":"text-fg-dim",children:String(s.enabled)})]}),s.error&&e.jsxs("div",{className:"text-red-400 break-words",children:[e.jsx("span",{className:"text-fg-faint",children:"error:"})," ",s.error]}),!s.error&&s.enabled&&e.jsx("div",{className:"text-fg-faint",children:"spans batched and exported in the background. Verify by enabling and pointing at a local Jaeger."})]}),e.jsxs("footer",{className:"flex items-center gap-3 pt-2 border-t border-line",children:[e.jsx("button",{onClick:N,disabled:!j||y,className:"px-3 py-1 text-xs rounded bg-accent text-bg disabled:opacity-50 disabled:cursor-not-allowed",children:y?"saving…":"Save"}),e.jsx("button",{onClick:S,disabled:!j||y,className:"px-3 py-1 text-xs rounded border border-line text-fg-dim hover:text-fg disabled:opacity-50 disabled:cursor-not-allowed",children:"Revert"}),f&&e.jsx("span",{className:"text-red-400 text-xs",children:f}),!f&&c&&!j&&e.jsx("span",{className:"text-fg-faint text-xs",children:"saved"})]})]})}function xt(){const[t,n]=o.useState(null),[s,r]=o.useState(null),[i,a]=o.useState("Copy"),[d,u]=o.useState(!1),[y,p]=o.useState(null),[f,m]=o.useState(null),[c,g]=o.useState(null),[j,v]=o.useState(!1),N=()=>{window.api.telemetry.status().then(r).catch(b=>{console.warn("[product-telemetry] status reload failed:",b==null?void 0:b.message)})};if(o.useEffect(()=>{let b=!1;return Promise.all([window.api.telemetry.getConfig(),window.api.telemetry.status()]).then(([k,R])=>{b||(n(k),r(R))}).catch(k=>{console.warn("[product-telemetry] load failed:",k==null?void 0:k.message)}),()=>{b=!0}},[]),!t||!s)return e.jsx(G,{title:"loading…"});const S=async b=>{m(null);try{const k=await window.api.telemetry.setConfig(b);n(k.config),r(k.status),window.dispatchEvent(new CustomEvent(ze,{detail:k.config}))}catch(k){m(k instanceof Error?k.message:String(k))}},h=b=>{S({...t,enabled:b})},w=async()=>{await Ue(t.installId)?(a("Copied"),setTimeout(()=>a("Copy"),1500)):he.error("Could not copy install id to the clipboard")},C=async()=>{u(!0),p(null);try{const b=await window.api.telemetry.flushNow();p(`sent ${b.sent.length}, failed ${b.failed.length}`),N()}catch(b){p(b instanceof Error?b.message:String(b))}finally{u(!1)}},T=async()=>{if(j){v(!1);return}try{const b=await window.api.telemetry.recentRecords();g(b),v(!0)}catch(b){console.warn("[product-telemetry] recentRecords failed:",b instanceof Error?b.message:b)}},E=t.lastDailyFlushAt?new Date(t.lastDailyFlushAt).getTime()+ut:null;return e.jsxs("div",{className:"space-y-5","data-testid":"product-telemetry-section",children:[e.jsxs("header",{className:"space-y-1",children:[e.jsx("h2",{className:"text-fg text-base font-medium",children:"Product telemetry (bilko.run)"}),e.jsxs("p",{className:"text-fg-dim text-xs leading-relaxed",children:["Anonymous, strictly non-identifying usage/error reporting that helps improve this app. On by default; switchable off in one click. See"," ",e.jsx("span",{className:"font-mono",children:"session-manager-operations/architecture/telemetry.md"})," for the full data model."]})]}),e.jsx(Fe,{cfg:t,onSaved:(b,k)=>{n(b),r(k)}}),e.jsxs("section",{className:"border border-line rounded p-3 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-fg",children:"Send anonymous product telemetry"}),e.jsx("div",{className:"text-fg-faint text-xs",children:"Sent on start-up, after an update, and once a day. Strictly anonymous — an install id only, never an email, name, or other identifier."})]}),e.jsx(O,{checked:t.enabled,onChange:h,label:t.enabled?"on":"off"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"text-fg-dim text-xs",children:"Anonymous install id"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"text",readOnly:!0,value:t.installId,"aria-label":"Anonymous install identifier",className:"flex-1 bg-bg border border-line rounded px-2 py-1 text-fg font-mono text-xs"}),e.jsx("button",{onClick:w,className:"px-2 py-1 text-xs rounded border border-line text-fg-dim hover:text-fg",children:i})]})]}),e.jsxs("div",{className:"space-y-1 text-xs",children:[e.jsx("div",{className:"text-fg-faint",children:"Endpoint"}),e.jsx("div",{className:"font-mono text-fg-dim break-all",children:t.endpoint})]}),e.jsxs("div",{className:"space-y-1 text-xs",children:[e.jsx("div",{className:"text-fg-faint",children:"Send cadence"}),e.jsx("div",{className:"text-fg-dim",children:"on start-up, after an update, and once a day"})]}),f&&e.jsx("div",{className:"text-red-400 text-xs",children:f})]}),s.pendingCount>0&&s.sentCount===0&&e.jsxs("section",{"data-testid":"telemetry-never-delivered-warning",className:"border border-red-400 rounded p-3 text-xs space-y-1 text-red-400",children:[e.jsx("div",{className:"font-medium",children:"Never delivered"}),e.jsxs("div",{className:"leading-relaxed",children:[s.pendingCount," record",s.pendingCount===1?"":"s",' queued but none have ever been sent to bilko.run on this install. Check the endpoint/network, or click "Send now" below.']})]}),e.jsxs("section",{className:"border border-line rounded p-3 text-xs space-y-1.5",children:[e.jsx("div",{className:"text-fg-dim",children:"Runtime status"}),e.jsxs("div",{children:[e.jsx("span",{className:"text-fg-faint",children:"last send:"})," ",ce(s.lastFlushAt)]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-fg-faint",children:"next daily send due:"})," ",ft(E?new Date(E).toISOString():null)]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-fg-faint",children:"queued records:"})," ",s.pendingCount]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-fg-faint",children:"delivered so far:"})," ",s.sentCount]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-fg-faint",children:"de-duplicated:"})," ",s.dedupedAppends]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-fg-faint",children:"evicted:"})," ",s.evictedCount]}),s.lastError&&e.jsxs("div",{className:"text-red-400 break-words",children:[e.jsx("span",{className:"text-fg-faint",children:"last error:"})," ",s.lastError.message," ","(",ce(s.lastError.at),")"]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("button",{onClick:C,disabled:d,className:"px-3 py-1 text-xs rounded bg-accent text-bg disabled:opacity-50 disabled:cursor-not-allowed",children:d?"sending…":"Send now"}),y&&e.jsx("span",{className:"text-fg-faint text-xs",children:y})]}),e.jsxs("section",{className:"space-y-2",children:[e.jsx("button",{onClick:T,className:"px-3 py-1 text-xs rounded border border-line text-fg-dim hover:text-fg",children:j?"Hide last records":"Inspect last records sent"}),j&&e.jsx("pre",{"data-testid":"telemetry-inspector-json",className:"bg-bg border border-line rounded p-2 text-[11px] font-mono overflow-auto max-h-96 whitespace-pre-wrap",children:JSON.stringify(c??[],null,2)})]})]})}function U({children:t,right:n}){return e.jsxs("div",{className:"flex items-baseline justify-between mb-2.5",children:[e.jsx("span",{className:"text-[11.5px] font-bold uppercase tracking-[0.8px] text-fg-faint",children:t}),n]})}function K({kind:t="soft",icon:n,children:s,onClick:r,disabled:i,testId:a}){return e.jsxs("button",{type:"button","data-testid":a,onClick:r,disabled:i,className:`shrink-0 inline-flex items-center gap-2 rounded-lg px-3.5 py-2 text-[13px] font-semibold transition-colors disabled:opacity-50 ${t==="soft"?"bg-bg-hi border border-line text-fg hover:bg-bg":"text-fg-dim hover:text-fg"}`,children:[n&&e.jsx(H,{name:n,size:15}),s]})}function yt({icon:t,title:n,subtitle:s,badge:r,action:i,testId:a}){return e.jsxs("div",{"data-testid":a,className:"flex items-center gap-3.5 bg-bg-hi border border-line rounded-xl px-[18px] py-3.5",children:[e.jsx("span",{className:"w-[34px] h-[34px] rounded-lg bg-bg border border-line grid place-items-center text-fg-dim shrink-0",children:e.jsx(H,{name:t,size:17})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2.5 mb-0.5",children:[e.jsx("span",{className:"text-sm font-semibold text-fg truncate",children:n}),r]}),e.jsx("div",{className:"font-mono text-[11.5px] text-fg-faint truncate",children:s})]}),i]})}function bt({onClick:t,disabled:n,testId:s,children:r="Revoke"}){return e.jsx("button",{"data-testid":s,onClick:t,disabled:n,className:"shrink-0 rounded-lg border border-line bg-bg text-accent px-3.5 py-1.5 text-[12.5px] font-semibold hover:bg-bg-hi disabled:opacity-50 transition-colors",children:r})}function pe({code:t,onConfirm:n,testId:s,codeTestId:r,confirmTestId:i,peer:a="browser"}){return e.jsxs("div",{"data-testid":s,className:"flex items-start gap-3.5 px-5 py-4 rounded-2xl border border-accent/40 bg-accent/[0.06]",children:[e.jsx("span",{className:"w-[38px] h-[38px] rounded-[11px] shrink-0 grid place-items-center bg-bg-hi text-accent",children:e.jsx(H,{name:"shield",size:20})}),e.jsxs("div",{className:"flex-1 min-w-0 text-sm text-fg",children:[e.jsx("strong",{className:"font-semibold",children:"Verify E2E session."})," Compare this code with the ",a," — they must match.",e.jsx("div",{"data-testid":r,className:"my-2 text-3xl font-mono tracking-[0.3em] text-center text-accent select-all",children:t}),e.jsx("p",{className:"text-[12.5px] text-fg-faint mb-3",children:"If the codes match, confirm below. Mutating commands are blocked until confirmed."}),e.jsx("button",{"data-testid":i,onClick:n,className:"rounded-lg bg-accent text-white px-4 py-2 text-[13px] font-semibold hover:opacity-90 transition-opacity",children:"Codes match — confirm"})]})]})}function jt({children:t,testId:n}){return e.jsx("div",{"data-testid":n,className:"bg-bg-hi border border-line rounded-xl p-5 text-center text-[13.5px] text-fg-faint italic font-serif",children:t})}function me({label:t,hint:n,on:s,onChange:r,warn:i,disabled:a,first:d,testId:u}){return e.jsxs("div",{className:`flex items-center justify-between gap-4 px-[18px] py-[15px] ${d?"":"border-t border-rule"} ${a?"opacity-50":""}`,children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-sm font-semibold text-fg mb-0.5",children:t}),e.jsxs("div",{className:`text-[12.5px] leading-snug flex items-center gap-1.5 ${i?"text-honey-dark":"text-fg-faint"}`,children:[i&&e.jsx("span",{"aria-hidden":!0,children:"⚠"}),n]})]}),e.jsx("span",{"data-testid":u,className:"inline-flex",children:e.jsx(O,{checked:s,onChange:a?()=>{}:r,disabled:a})})]})}function vt({device:t,online:n,onRevoke:s,revoking:r}){const i=t.lastConnectedAt?new Date(t.lastConnectedAt).toLocaleString():`paired ${new Date(t.issuedAt).toLocaleDateString()}`;return e.jsx(yt,{testId:"settings-remote-device",icon:"wifi",title:t.deviceName,badge:n?e.jsx(L,{tone:"default",className:"!text-sage !border-sage/40",children:"online"}):void 0,subtitle:`${t.deviceId} · last seen ${i}`,action:e.jsx(bt,{testId:"settings-remote-revoke",onClick:()=>s(t.deviceId),disabled:r})})}const M=t=>(t==null?void 0:t.message)||String(t);function wt(){var ie;const t=ee(l=>l.show),[n,s]=o.useState(null),[r,i]=o.useState(!0),[a,d]=o.useState(!1),[u,y]=o.useState(!1),[p,f]=o.useState("idle"),[m,c]=o.useState(""),[g,j]=o.useState(null),[v,N]=o.useState(!1),[S,h]=o.useState([]),[w,C]=o.useState(!1),T=o.useRef(null);o.useEffect(()=>{let l=!1;const x=()=>window.api.webRemote.getStatus().then(I=>{l||s(I)}).catch(()=>{});window.api.webRemote.getStatus().then(I=>{l||(s(I),i(!1))}).catch(I=>{l||(t("error",`Remote status: ${M(I)}`),i(!1))});const Ie=window.api.webRemote.onStatus(I=>s(I)),Pe=window.api.webRemote.onTokenRevoked(()=>{t("warn","Remote device token was revoked. Re-pair to reconnect."),x()}),Re=window.api.webRemote.onRevokedAll(({revokedCount:I})=>{t("info",`Panic: all ${I} device(s) revoked and sessions torn down.`),x()});return()=>{l=!0,Ie(),Pe(),Re()}},[t]),o.useEffect(()=>{if(p!=="enter-otp")return;const l=setTimeout(()=>{var x;return(x=T.current)==null?void 0:x.focus()},50);return()=>clearTimeout(l)},[p]);const E=async()=>s(await window.api.webRemote.getStatus()),b=async()=>{if(n){d(!0);try{const l=n.enabled?await window.api.webRemote.disable():await window.api.webRemote.enable();l&&l.ok===!1&&t("error",l.error||"Failed to change remote state."),await E()}catch(l){t("error",`Failed: ${M(l)}`)}finally{d(!1)}}},k=async()=>{if(n){y(!0);try{const l=n.remoteControlEnabled?await window.api.webRemote.disableControl():await window.api.webRemote.enableControl();l&&l.ok===!1&&t("error",l.error||"Failed to change command writes."),await E()}catch(l){t("error",`Failed: ${M(l)}`)}finally{y(!1)}}},R=async()=>{const l=m.trim().toUpperCase();if(!/^[A-Z0-9]{8}$/.test(l)){t("warn","Pairing code must be 8 alphanumeric characters.");return}f("pairing");try{const x=await window.api.webRemote.pair(l);if(!x.ok){t("error",x.error||"Pairing failed."),f("enter-otp");return}t("info","Device paired successfully."),c(""),f("idle"),await E()}catch(x){t("error",`Pairing error: ${M(x)}`),f("enter-otp")}},F=async l=>{j(l);try{const x=await window.api.webRemote.revokeDevice(l);if(!x.ok){t("error",x.error||"Revoke failed.");return}await E()}catch(x){t("error",`Revoke error: ${M(x)}`)}finally{j(null)}},Ne=async()=>{N(!0);try{const l=await window.api.webRemote.revokeAll();l.ok||t("error",l.error||"Panic revoke failed.")}catch(l){t("error",`Panic revoke error: ${M(l)}`)}finally{N(!1)}},Se=async()=>{if(w){C(!1);return}try{const l=await window.api.webRemote.auditTail(100);if(!l.ok){t("error",`Audit log: ${l.error||"unavailable"}`);return}h(l.lines??[]),C(!0)}catch(l){t("error",`Audit log: ${M(l)}`)}},ne=async l=>{try{const x=await window.api.webRemote.confirmSas(l);x!=null&&x.ok||t("error",`SAS confirm failed: ${(x==null?void 0:x.error)??"unexpected state — reconnect the mobile app"}`)}catch(x){t("error",`SAS confirm failed: ${M(x)}`)}};if(r)return e.jsx("div",{className:"p-6 text-fg-faint text-sm",children:"Loading…"});const A=(n==null?void 0:n.enabled)??!1,Y=(n==null?void 0:n.remoteControlEnabled)??!1,se=(n==null?void 0:n.connected)??!1,ae=(n==null?void 0:n.e2eActive)??!1,Ce=(n==null?void 0:n.e2eAuthenticated)??!1,Ee=(n==null?void 0:n.e2eState)??"idle",re=(n==null?void 0:n.pendingSas)??null,X=((n==null?void 0:n.clients)??[]).filter(l=>l.state==="pending_sas"&&l.pendingSas),$=(n==null?void 0:n.devices)??[],_=A&&se,Te=se?((ie=$.reduce((l,x)=>x.lastConnectedAt&&(!l||(l.lastConnectedAt??"")<x.lastConnectedAt)?x:l,null))==null?void 0:ie.deviceId)??null:null;return e.jsxs("div",{"data-testid":"settings-remote",className:"p-4 max-w-[760px] space-y-[22px]",children:[X.length>0?X.map((l,x)=>e.jsxs("div",{"data-testid":"settings-remote-sas-row",children:[X.length>1&&e.jsxs("div",{className:"text-[12px] font-semibold text-fg-dim mb-1",children:["Browser ",x+1]}),e.jsx(pe,{testId:x===0?"settings-remote-sas":void 0,codeTestId:x===0?"settings-remote-sas-code":void 0,confirmTestId:x===0?"settings-remote-sas-confirm":void 0,code:l.pendingSas,onConfirm:()=>ne(l.key)})]},l.key)):re&&e.jsx(pe,{testId:"settings-remote-sas",codeTestId:"settings-remote-sas-code",confirmTestId:"settings-remote-sas-confirm",code:re,onConfirm:()=>ne()}),Ee==="failed"&&e.jsxs("div",{className:"flex items-center gap-3.5 px-5 py-4 rounded-2xl border border-[#eccdbe] bg-[#f8e8e0]",children:[e.jsx("span",{className:"w-4 h-4 rounded-full bg-accent text-white grid place-items-center text-[11px] font-bold shrink-0",children:"!"}),e.jsxs("div",{className:"text-[13px] text-[#9a3f1f]",children:[e.jsx("strong",{className:"font-semibold",children:"E2E key exchange failed."})," ",e.jsx("span",{className:"text-fg-dim",children:"The session key could not be established. Reconnect the mobile app to retry."})]})]}),e.jsxs("div",{className:`flex items-center gap-3.5 px-5 py-4 rounded-2xl border ${_?"border-[#e8cdb9] bg-[#f5e9df]":"border-line bg-bg-hi"}`,children:[e.jsx("span",{className:`w-[38px] h-[38px] rounded-[11px] shrink-0 grid place-items-center ${_?"bg-[#f0d9c8] text-accent":"bg-[#e4ebd6] text-sage"}`,children:e.jsx(H,{name:_?"wifi":"shield",size:20})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-[14.5px] font-semibold text-fg mb-0.5",children:_?"Remote control is active":A?"Remote control is idle":"Remote control is off"}),e.jsx("div",{className:"text-[13px] text-fg-dim leading-snug",children:_?"A web session can send commands to this machine. Revoke below if unexpected.":A&&(n==null?void 0:n.linkState)==="repair-needed"?"The relay no longer recognises this device. Re-pair it with a new code to reconnect.":A?"The relay is on but no device is connected. Pair a device to begin.":"The relay connection is closed — no remote commands are accepted. Enable it below only when you need it."})]}),ae&&Ce?e.jsx(L,{tone:"default",className:"!text-sage !border-sage/40",children:"E2E authenticated"}):ae?e.jsx(L,{tone:"warn",children:"E2E · awaiting SAS"}):e.jsx(L,{tone:"dim",children:"relay only · not E2E yet"})]}),e.jsxs("div",{children:[e.jsx(U,{children:"Remote control"}),e.jsxs("div",{className:"bg-bg-hi border border-line rounded-2xl overflow-hidden",children:[e.jsx(me,{first:!0,testId:"settings-remote-enable",label:"Allow remote control from the web",hint:"Master switch. When off, the relay refuses every connection.",on:A,disabled:a,onChange:()=>{a||b()}}),e.jsx(me,{testId:"settings-remote-control",label:"Allow command writes (pty + scheduler)",hint:Y?"A paired device can run shell commands and queue jobs on this machine.":"Paired devices can watch session output but cannot send commands.",warn:Y,disabled:!A||u,on:Y&&A,onChange:()=>{A&&!u&&k()}})]})]}),e.jsxs("div",{children:[e.jsx(U,{children:"Pair a device"}),p==="idle"?e.jsxs("div",{className:"flex items-center justify-between gap-4 bg-bg-hi border border-line rounded-2xl px-5 py-[18px]",children:[e.jsxs("div",{"data-testid":"settings-remote-pair-hint",className:"text-[13.5px] text-fg-dim leading-relaxed max-w-[420px]",children:["On your phone open ",e.jsx("strong",{className:"text-fg font-semibold",children:"bilko.run/projects/session-manager"}),", sign in, and tap"," ",e.jsx("strong",{className:"text-fg font-semibold",children:"Generate pairing code"}),". Enter the 8-character code here."]}),e.jsx(K,{testId:"settings-remote-pair-start",kind:"soft",icon:"link",onClick:()=>f("enter-otp"),children:"Pair Device…"})]}):e.jsxs("div",{className:"flex items-center gap-5 bg-bg-hi border border-accent/40 rounded-2xl px-6 py-[22px]",children:[e.jsx("span",{className:"w-[52px] h-[52px] rounded-xl bg-bg border border-line grid place-items-center text-accent shrink-0",children:e.jsx(H,{name:"link",size:24})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-[11.5px] font-bold uppercase tracking-[0.8px] text-fg-faint mb-2",children:"Enter the code from your phone"}),e.jsx("input",{ref:T,"data-testid":"settings-remote-otp",value:m,onChange:l=>c(l.target.value.toUpperCase().replace(/[^A-Z0-9]/g,"")),onKeyDown:l=>{l.key==="Enter"&&R()},maxLength:8,placeholder:"XXXXXXXX",disabled:p==="pairing",className:"w-full bg-transparent border-0 outline-none font-mono text-[30px] font-semibold tracking-[6px] text-fg placeholder:text-fg-faint/40 disabled:opacity-50"})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsx(K,{testId:"settings-remote-pair-confirm",kind:"soft",onClick:R,disabled:p==="pairing"||m.length<8,children:p==="pairing"?"Pairing…":"Confirm"}),e.jsx(K,{kind:"ghost",onClick:()=>{f("idle"),c("")},disabled:p==="pairing",children:"cancel"})]})]})]}),e.jsxs("div",{children:[e.jsx(U,{right:$.length>0?e.jsxs("span",{className:"text-[11.5px] text-fg-faint",children:[$.length," paired"]}):void 0,children:"Paired devices"}),$.length===0?e.jsx(jt,{children:"No devices paired yet."}):e.jsx("div",{className:"space-y-2",children:$.map(l=>e.jsx(vt,{device:l,online:l.deviceId===Te,onRevoke:F,revoking:g===l.deviceId},l.deviceId))})]}),e.jsxs("div",{children:[e.jsx(U,{right:e.jsx("button",{"data-testid":"settings-remote-audit-toggle",onClick:Se,className:"text-[12px] text-fg-faint hover:text-fg-dim transition-colors",children:w?"Hide":"Show last 100 · 0600, stays on this machine"}),children:"Audit log"}),w&&e.jsx("div",{className:"bg-bg-hi border border-line rounded-xl overflow-auto max-h-64 mb-2",children:S.length===0?e.jsx("p",{className:"p-4 text-[12.5px] text-fg-faint",children:"No entries today."}):e.jsx("pre",{"data-testid":"settings-remote-audit",className:"p-4 text-[12px] text-fg-dim font-mono whitespace-pre-wrap leading-relaxed",children:S.join(`
2
+ `)})}),e.jsxs("p",{className:"text-[12px] text-fg-faint",children:["Full log at"," ",e.jsx("code",{className:"font-mono text-fg-faint",children:"~/.claude/session-manager/logs/remote-audit-YYYY-MM-DD.log"})," ","(0600, never leaves this machine)"]})]}),e.jsxs("div",{className:"flex items-center justify-between gap-4 bg-[#f8e8e0] border border-[#eccdbe] rounded-2xl px-5 py-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("span",{className:"w-4 h-4 rounded-full bg-accent text-white grid place-items-center text-[11px] font-bold shrink-0",children:"!"}),e.jsx("span",{className:"text-sm font-semibold text-[#9a3f1f]",children:"Panic — disconnect & revoke everything"})]}),e.jsx("div",{className:"text-[12.5px] text-fg-dim leading-snug max-w-[440px]",children:"Tears down every active session and invalidates all paired-device tokens. Devices must re-pair. Use if you suspect compromise."})]}),e.jsx("button",{"data-testid":"settings-remote-revoke-all",onClick:Ne,disabled:v,className:"shrink-0 rounded-lg bg-accent text-white px-[18px] py-2 text-[13px] font-semibold hover:opacity-90 disabled:opacity-50 transition-opacity",children:v?"Revoking…":"Revoke all"})]})]})}const z="px-2 py-1 rounded border border-line text-xs text-fg hover:bg-bg-hi disabled:opacity-50";function kt(){const t=We(),n=ee(u=>u.show),s=async u=>{try{const p=await u();p&&p.ok===!1&&n("error",p.error??"Update action failed")}catch(y){n("error",y instanceof Error?y.message:String(y))}};if(!t)return null;const{state:r}=t,i=r==="unsupported",a=t.latest?`v${t.latest}`:"—",d=()=>{window.confirm("Installing now will stop all running jobs and terminals. Continue?")&&s(()=>window.api.updater.install(!0))};return e.jsxs("section",{"data-testid":"settings-updates",className:"border border-line rounded p-3 space-y-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("span",{className:"text-fg text-xs font-medium",children:"Updates"}),e.jsxs("div",{className:"text-fg-dim text-xs flex gap-4",children:[e.jsxs("span",{children:["Current v",t.current]}),e.jsxs("span",{children:["Latest ",a]})]})]}),i?e.jsx("p",{className:"text-fg-faint text-[11px]",children:"Auto-update runs only in the installed Windows app or the Linux AppImage. npx builds update via npx."}):e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(O,{checked:t.enabled,onChange:u=>void s(()=>window.api.updater.setEnabled(u)),label:"Update automatically"}),e.jsx("button",{type:"button","data-testid":"updates-check",className:z,disabled:r==="checking"||r==="downloading",onClick:()=>void s(()=>window.api.updater.check()),children:"Check for updates"})]}),r==="checking"&&e.jsx("p",{className:"text-fg-dim text-xs",children:"Checking…"}),r==="downloading"&&e.jsxs("p",{className:"text-fg-dim text-xs",children:["Downloading… ",t.progress!=null?`${Math.round(t.progress)}%`:""]}),r==="ready"&&e.jsxs("button",{type:"button","data-testid":"updates-install",className:z,onClick:()=>void s(()=>window.api.updater.install(!1)),children:["Restart to install v",t.latest]}),r==="deferred"&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("p",{className:"text-fg-dim text-xs",children:["Waiting for ",t.busyReason??"work"," to finish"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"button",className:z,onClick:d,children:"Install now"}),e.jsx("button",{type:"button",className:z,onClick:()=>void s(()=>window.api.updater.cancelDeferred()),children:"Cancel"})]})]}),r==="error"&&e.jsx("p",{className:"text-red-400 text-xs",children:t.error})]})}const Nt=[{key:"maxAgeDays",label:"Run logs: keep for",unit:"days",min:3,max:3650},{key:"runsArchiveDays",label:"Runs archive: keep for",unit:"days",min:1,max:3650},{key:"auditLogMonths",label:"Audit log: keep for",unit:"months",min:1,max:120},{key:"reservedMarkersKeep",label:"Reserved markers: keep",unit:"markers",min:1,max:1e5}],St="w-24 px-2 py-1 rounded border border-line bg-transparent text-xs text-fg";function ue(t,n){return n==="maxAgeDays"?t.runLogs.maxAgeDays:t[n]}function Ct(t,n){return t==="maxAgeDays"?{runLogs:{maxAgeDays:n}}:{[t]:n}}function ye(t){if(!Number.isFinite(t)||t<=0)return"0 B";const n=["B","KB","MB","GB","TB"];let s=0,r=t;for(;r>=1024&&s<n.length-1;)r/=1024,s++;return`${s===0?r:r.toFixed(1)} ${n[s]}`}function Z(t,n,s){return`${t}: ${ye(n)} in ${s.toLocaleString("en-US")} files`}function Et(){const t=ee(c=>c.show),[n,s]=o.useState(null),[r,i]=o.useState({}),[a,d]=o.useState(null),u=o.useCallback(c=>t("error",c instanceof Error?c.message:String(c)),[t]),y=o.useCallback(async()=>{try{d(await window.api.opsRetention.preview())}catch(c){u(c)}},[u]);o.useEffect(()=>{let c=!0;return window.api.opsRetention.get().then(g=>{c&&s(g)}).catch(g=>{c&&u(g)}),y(),()=>{c=!1}},[u,y]);const p=async c=>{if(!n)return;const g=r[c.key];if(g===void 0)return;const j=Number(g);if(i(N=>{const{[c.key]:S,...h}=N;return h}),g.trim()===""||!Number.isFinite(j))return;const v=Math.min(c.max,Math.max(c.min,Math.round(j)));if(v!==ue(n,c.key))try{s(await window.api.opsRetention.set(Ct(c.key,v))),await y()}catch(N){u(N)}},f=a?a.runLogs.bytes+a.runsArchive.bytes+a.tmp.bytes:0,m=a?a.runLogs.files+a.runsArchive.entries+a.tmp.files:0;return e.jsxs("section",{"data-testid":"settings-ops-retention",className:"border border-line rounded p-3 space-y-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("span",{className:"text-fg text-xs font-medium",children:"Ops data retention"}),e.jsx("p",{className:"text-fg-faint text-[11px]",children:"How long the daily sweep keeps scheduler and audit data. Machine-wide."})]}),n&&e.jsxs("div",{className:"space-y-2",children:[Nt.map(c=>e.jsxs("label",{className:"flex items-center gap-2 text-xs text-fg-dim",children:[e.jsx("span",{className:"w-48",children:c.label}),e.jsx("input",{type:"number","data-testid":`ops-retention-${c.key}`,className:St,min:c.min,max:c.max,value:r[c.key]??String(ue(n,c.key)),onChange:g=>i(j=>({...j,[c.key]:g.target.value})),onBlur:()=>void p(c)}),e.jsx("span",{className:"text-fg-faint",children:c.unit})]},c.key)),e.jsx("p",{className:"text-fg-dim text-xs",children:"Archived transcripts: kept forever"})]}),a&&e.jsxs("div",{"data-testid":"ops-retention-preview",className:"space-y-1 text-xs text-fg-dim",children:[e.jsxs("div",{className:"text-fg",children:["Current policy would free ",ye(f)," in ",m.toLocaleString("en-US")," files"]}),e.jsx("div",{children:Z("Run logs",a.runLogs.bytes,a.runLogs.files)}),e.jsx("div",{children:Z("Runs archive",a.runsArchive.bytes,a.runsArchive.entries)}),e.jsx("div",{children:Z("Stale temp files",a.tmp.bytes,a.tmp.files)}),e.jsx("p",{className:"text-fg-faint text-[11px]",children:"Nothing is deleted until the daily sweep runs."})]})]})}const q=[{id:"project",label:"Project & Tab",realm:"machine",blurb:"A PROJECT is a cwd; a TAB is one open project.",tone:{chip:"bg-bg-elev text-fg-dim",border:"border-line",dot:"bg-fg-faint"}},{id:"epic",label:"Epic (PromptSession)",realm:"project",blurb:"The central aggregate root — one unit of work, one claude session.",tone:{chip:"bg-accent-muted text-accent-dark",border:"border-accent",dot:"bg-accent"}},{id:"scheduler",label:"Scheduler",realm:"project",blurb:"PRDs + the headless jobs that execute them.",tone:{chip:"bg-butter/30 text-honey-dark",border:"border-honey",dot:"bg-honey"}},{id:"agents",label:"Agents & Taxonomy",realm:"machine",blurb:"The ACTOR and MISSION halves of AIM.",tone:{chip:"bg-sage/20 text-sage-dark",border:"border-sage",dot:"bg-sage"}},{id:"memory",label:"Memory",realm:"machine",blurb:"Workspace, cross-project, and per-agent memory.",tone:{chip:"bg-hive-teal/20 text-hive-teal",border:"border-hive-teal",dot:"bg-hive-teal"}},{id:"transcript",label:"Transcript & Usage",realm:"machine",blurb:"The Claude CLI's own JSONL, classified events, and billing.",tone:{chip:"bg-bg-hi text-fg-dim",border:"border-rule",dot:"bg-fg-dim"}},{id:"brief",label:"Project Home & Publishing",realm:"project",blurb:"The synthesized Brief, generated pages, and bilko.run publish state.",tone:{chip:"bg-accent-muted/60 text-accent-dark",border:"border-accent-muted",dot:"bg-accent-muted"}},{id:"config",label:"Machine Config",realm:"machine",blurb:"Settings, layout, and the single-writer ownership map.",tone:{chip:"bg-line text-fg-faint",border:"border-rule",dot:"bg-fg-faint"}}];function be(t){const n=q.find(s=>s.id===t);if(!n)throw new Error(`unknown ErdGroupId: ${t}`);return n}const B=[{id:"project",name:"Project",aka:"cwd — Main Project",group:"project",store:{path:"identity only, no record of its own — folded at read time from ~/.claude/projects/<encoded>",format:"in-memory",definedIn:"src/renderer/lib/knownProjectAggregate.ts (aggregateProjectsByCwd) "},summary:"A folder whose cwd never resolved from transcript content is DROPPED, never guessed — the naive decode once reported 2044 phantom projects.",fields:[{name:"cwd",type:"string",key:"pk",note:"resolved working directory — the project's identity"},{name:"name",type:"string",note:"display name: the cwd's last path segment"},{name:"encoded",type:"string",note:"representative transcript folder (most recently active)"},{name:"encodedIds",type:"string[]",note:"every ~/.claude/projects/<encoded> folder that resolved to this cwd"},{name:"sessionCount",type:"number"},{name:"sizeBytes",type:"number"},{name:"lastSession",type:"number"}]},{id:"tab",name:"PersistedTab",aka:"TAB",group:"project",store:{path:"~/.claude/session-manager/tabs.json",format:"json",definedIn:"src/main/sessionsStore.cjs "},summary:"One TAB per project — extra sessions within a project are Epics, not tabs.",fields:[{name:"id",type:"string",key:"pk"},{name:"sessionId",type:"string"},{name:"cwd",type:"string",key:"fk",ref:"project.cwd"},{name:"label",type:"string"},{name:"presetId",type:"string | null"}]},{id:"epic",name:"PromptSession",aka:"EPIC",group:"epic",store:{path:"<cwd>/session-manager-operations/prompt-sessions/active-index.json -> sessions[id]",format:"json",writer:"epics",definedIn:"src/main/lib/epic/epicMint.cjs (ensureEpic) + src/renderer/state/promptSessions.ts "},summary:"The central aggregate root — created in exactly ONE place, a human pressing New Epic.",fields:[{name:"id",type:"string",key:"pk"},{name:"cwd",type:"string",key:"fk",ref:"project.cwd"},{name:"goalText",type:"string",note:"the original top-level prompt text that started this goal"},{name:"claudeSessionId",type:"string",note:"independently minted — never shared with any tab.sessionId"},{name:"status",type:"'proposed' | 'active' | 'completed'"},{name:"createdAt",type:"string"},{name:"completedAt",type:"string | null"},{name:"resumedFromId",type:"string",optional:!0,key:"fk",ref:"epic.id"},{name:"tag",type:"TicketTag",optional:!0,key:"fk",ref:"tag.tag"},{name:"openingPrompt",type:"string | null",optional:!0},{name:"source",type:"EpicSource",optional:!0,note:"{ producer, prdSlug?, runId?, sourceTabId?, fromCwd?, fromEpicId? }"},{name:"agentType",type:"string",optional:!0,key:"fk",ref:"agentPersona.name"},{name:"model",type:"string",optional:!0,note:"per-Epic model override; absent = the persona model"},{name:"effort",type:"string",optional:!0,note:"per-Epic effort override; absent = the persona effort"},{name:"developLoop",type:"false",optional:!0,note:"false = started with the develop loop off; absent = on"},{name:"restoredSession",type:"true",optional:!0,note:"claudeSessionId adopted from an existing CLI session"},{name:"agentCli",type:"string",optional:!0,note:"agent CLI running the session; absent = Claude Code; fixed for the session"},{name:"agentCliModel",type:"string",optional:!0,note:"model string passed to agentCli; absent = its default"},{name:"sections",type:"EpicIntakeSection[]",optional:!0},{name:"worktree",type:"{ dir, branch, baseCwd, status, conflictReason? }",optional:!0,note:"own git worktree on branch 'sm-epic/<id>' when Active"}],notes:["SINGLE-CREATOR LAW, fail-closed in epicMint.cjs — the New Epic IPC handler and crossProjectFeedback.cjs are the only mint authorities.","Every Epic is born proposed; nothing is created directly as active.","EPIC : claude-session is 1:1 — Chat and Terminal are two VIEWS over one session.","Title + objective are fixed for the life of the session — iterate in follow-up messages, don't repurpose."]},{id:"epicEvent",name:"PromptSessionEvent",group:"epic",store:{path:"<cwd>/session-manager-operations/prompt-sessions/active-index.json -> events[]",format:"json",writer:"epics",definedIn:"src/renderer/state/promptSessions.ts + src/main/lib/epic/activeIndexMerge.cjs "},summary:"One step in an Epic's Prompt → PRD → Response → ... → Closed chain.",fields:[{name:"id",type:"string",key:"pk"},{name:"promptSessionId",type:"string",key:"fk",ref:"epic.id"},{name:"kind",type:"'prompt' | 'prd_created' | 'response' | 'closed'"},{name:"causedByEventId",type:"string | null",key:"fk",ref:"epicEvent.id",note:"must be the session's current tail event — a chain, not a tree"},{name:"at",type:"string"},{name:"prdSlug",type:"string",optional:!0,key:"fk",ref:"prd.slug"},{name:"text",type:"string",optional:!0},{name:"outcome",type:"'completed' | 'failed' | 'needs_review'",optional:!0},{name:"validation",type:"'unvalidated' | 'validating' | 'verified' | 'refuted'",optional:!0}]},{id:"epicTranscriptTurn",name:"PromptSessionTranscriptTurn",group:"epic",store:{path:"<cwd>/session-manager-operations/prompt-sessions/transcripts/<epicId>.jsonl",format:"jsonl",writer:"epics",definedIn:"src/main/promptSessionTranscript.cjs "},summary:"The durable per-Epic transcript store, kept alongside the CLI's own JSONL as a fallback source of turns.",fields:[{name:"v",type:"1"},{name:"epicId",type:"string",key:"fk",ref:"epic.id"},{name:"eventId",type:"string | null",key:"fk",ref:"epicEvent.id"},{name:"role",type:"'user' | 'assistant'"},{name:"at",type:"string"},{name:"text",type:"string"}]},{id:"epicArchive",name:"PromptSessionArchive",group:"epic",store:{path:"<cwd>/session-manager-operations/prompt-sessions/<epicId>.json",format:"json",writer:"epics",definedIn:"src/renderer/state/promptSessions.ts (promptSessionArchivePath) "},summary:"On-disk archive written once at completion — freezes the Epic, its events, and its transcript.",fields:[{name:"session",type:"PromptSession"},{name:"events",type:"PromptSessionEvent[]"},{name:"transcript",type:"string"},{name:"archivedAt",type:"string"},{name:"durableTurns",type:"Array<{ role, text, at }>",optional:!0}]},{id:"epicWorktreeConfig",name:"EpicWorktreeConfig",group:"epic",store:{path:"<cwd>/session-manager-operations/prompt-sessions/epic-worktree-config.json",format:"json",writer:"epics",definedIn:"src/main/lib/epic/epicWorktreeProjectConfig.cjs "},summary:"Per-project 'disable Epic worktree isolation' toggle, read by gitWorktree.cjs's isWorktreeDisabled('epic', cwd) on every worktree creation attempt.",fields:[{name:"disabled",type:"boolean"}],notes:["One-shot migration from the legacy machine-wide ~/.claude/session-manager/epic-worktree-project-config.json map, keyed by project cwd — that file is left in place, never deleted."]},{id:"exchange",name:"Exchange",group:"epic",store:{path:"<cwd>/session-manager-operations/prompt-sessions/exchanges.jsonl",format:"jsonl",writer:"epics",definedIn:"src/main/exchanges.cjs "},summary:"One durable NDJSON record per completed terminal-chat exchange, appended off the hot path.",fields:[{name:"ts",type:"string"},{name:"sessionId",type:"string",key:"fk",ref:"epic.claudeSessionId",note:"the tab's claude session id"},{name:"cwd",type:"string",key:"fk",ref:"project.cwd"},{name:"prompt",type:"string"},{name:"result",type:"string"},{name:"summary",type:"string",note:"produced by the shared Haiku summarizer"},{name:"model",type:"string"},{name:"degraded",type:"string",optional:!0,note:"set when summarization failed — the exchange itself is never dropped"},{name:"promptId",type:"string",optional:!0,key:"fk",ref:"prd.slug",note:"originating PromptTicket.id when dispatched from the per-tab queue; forward-only, never backfilled"}],notes:["Written via raw fs O_APPEND (not config.cjs writeJson) for atomicity across concurrent writers — assertOpsWrite is called explicitly since raw fs bypasses the normal enforcement point.","Historical rows from before this store existed remain, untouched and unmigrated, in the old global ~/.claude/knowledge-log/exchanges/<encodeCwd(cwd)>.jsonl."]},{id:"prd",name:"PRD",group:"scheduler",store:{path:"<cwd>/session-manager-operations/scheduler/epics/<epicId>/prds/<slug>.md",format:"markdown",writer:"scheduler",definedIn:"src/main/lib/prd/prdLocations.cjs + scheduler_create_prd MCP tool "},summary:"PRD authoring is API-only via the scheduler_create_prd MCP tool — a PRD joins an EXISTING Epic and never conjures one.",fields:[{name:"slug",type:"string",key:"pk",note:"<nn>-<kebab-title>.md filename stem"},{name:"title",type:"string"},{name:"cwd",type:"string",key:"fk",ref:"project.cwd"},{name:"epicId",type:"string | null",key:"fk",ref:"epic.id",note:"derived from the PRD's DIRECTORY — fact on disk"},{name:"sourcePromptId",type:"string",optional:!0,key:"fk",ref:"epic.id",note:"frontmatter intent — can disagree with epicId"},{name:"sourceTabId",type:"string",optional:!0},{name:"estimateMinutes",type:"number"},{name:"tag",type:"'feature' | 'bug' | 'discussion' | 'build' | 'project-home-builder' | 'art' | 'portfolio'",optional:!0,key:"fk",ref:"tag.tag"},{name:"dependsOn",type:"string[]",optional:!0,key:"fk",ref:"prd.slug",note:"the SOLE ordering primitive"},{name:"goal",type:"string"},{name:"acceptanceCriteria",type:"string[]"},{name:"implementationNotes",type:"string"},{name:"outOfScope",type:"string[]",optional:!0},{name:"createdVia",type:"string",optional:!0},{name:"issuedAt",type:"string",optional:!0}],notes:["Flat scheduler/prds/ is RETIRED — auto-consolidated into prds-archived/ on every reconcile() pass.","epicId is derived from the DIRECTORY (fact on disk) while sourcePromptId is frontmatter intent and can disagree."]},{id:"scheduleJob",name:"ScheduleJob",group:"scheduler",store:{path:"<cwd>/session-manager-operations/scheduler/state/queue.json -> jobs[]",format:"json",writer:"scheduler",definedIn:"src/main/lib/scheduler/queueStore.cjs + src/main/lib/scheduler/scheduleJobSchema.cjs "},summary:"dependsOn is the SOLE ordering primitive — parallelGroup is a display hint, never a barrier.",fields:[{name:"slug",type:"string",key:"pk",note:"shared identity with the PRD it executes"},{name:"title",type:"string"},{name:"cwd",type:"string | null",key:"fk",ref:"project.cwd"},{name:"parallelGroup",type:"number"},{name:"estimateMinutes",type:"number | null"},{name:"bodyPreview",type:"string"},{name:"status",type:"'pending' | 'running' | 'investigating' | 'completed' | 'failed' | 'needs_review' | 'quarantined'"},{name:"runId",type:"string | null",key:"fk",ref:"runLog.runId"},{name:"startedAt",type:"string | null"},{name:"finishedAt",type:"string | null"},{name:"exitCode",type:"number | null"},{name:"error",type:"string | null"},{name:"sessionId",type:"string",optional:!0},{name:"runtime",type:"ScheduleJobRuntime",optional:!0,note:"{ pid, runId, startedAt, sessionId?, cwd? }"},{name:"verifierVerdict",type:"string",optional:!0},{name:"dependsOn",type:"string[]",optional:!0,key:"fk",ref:"prd.slug"},{name:"originSessionId",type:"string | null",optional:!0,key:"fk",ref:"epic.id"},{name:"sourceTabId",type:"string | null",optional:!0},{name:"sourcePromptId",type:"string | null",optional:!0,key:"fk",ref:"epic.id"},{name:"epicId",type:"string | null",optional:!0,key:"fk",ref:"epic.id",note:"authoritative — derived from the PRD directory"},{name:"statusHistory",type:"ScheduleJobStatusHistoryEntry[]",optional:!0}],notes:["Every launch must take a slot from lib/scheduler/sessionSlots.cjs — the single machine-wide concurrency limit.","--model is always pinned on every claude -p call site.","A job in needs_review is a QUESTION routed back to the authoring Epic and never creates work on its own."]},{id:"scheduleJobStatusHistory",name:"ScheduleJobStatusHistoryEntry",group:"scheduler",store:{path:"<cwd>/session-manager-operations/scheduler/state/queue.json -> jobs[].statusHistory[]",format:"json",writer:"scheduler",definedIn:"src/main/lib/scheduler/scheduleJobTransitions.cjs "},summary:"Bounded trail (~20 entries) of accepted status transitions for one ScheduleJob.",fields:[{name:"from",type:"string | null"},{name:"to",type:"string"},{name:"reason",type:"string | null"},{name:"source",type:"string | null"},{name:"at",type:"string"}]},{id:"scheduleHistoryEntry",name:"Schedule history entry",group:"scheduler",store:{path:"<cwd>/session-manager-operations/scheduler/state/history.jsonl",format:"jsonl",writer:"scheduler",definedIn:"src/main/lib/scheduler/queueStore.cjs "},summary:"Terminal jobs aged out of queue.json land here, one JSON object per line.",fields:[{name:"slug",type:"string",key:"fk",ref:"prd.slug"},{name:"status",type:"ScheduleJobStatus"},{name:"finishedAt",type:"string | null"},{name:"epicId",type:"string | null",optional:!0,key:"fk",ref:"epic.id"},{name:"runId",type:"string | null",optional:!0,key:"fk",ref:"runLog.runId"}]},{id:"scheduleConfig",name:"ScheduleConfig",group:"scheduler",store:{path:"~/.claude/session-manager/scheduler-machine.json",format:"json",writer:"scheduler",definedIn:"src/main/lib/scheduler/schedulerConfig.cjs + src/main/lib/scheduler/queueStore.cjs "},summary:"Machine-level auto-fire policy and utilization gate (scheduler-machine.json, not per-project queue.json).",fields:[{name:"enabled",type:"boolean",note:"legacy on/off, kept for v0.4 backwards compat"},{name:"offsetMinutes",type:"number"},{name:"defaultCwd",type:"string",key:"fk",ref:"project.cwd"},{name:"firePolicy",type:"'manual' | 'when-available'"},{name:"utilizationThreshold",type:"number"},{name:"schemaVersion",type:"1"}]},{id:"runLog",name:"Run log",group:"scheduler",store:{path:"~/.claude/session-manager/scheduled-plans/runs/<runId>/",format:"directory",definedIn:"src/main/scheduler.cjs (RUNS_DIR) "},summary:"One directory per headless claude -p invocation — stdout/stderr/exit capture for a ScheduleJob's run.",fields:[{name:"runId",type:"string",key:"pk"}]},{id:"agentPersona",name:"AgentPersona",aka:"ACTOR",group:"agents",store:{path:"~/.claude/agents/<name>.md",format:"markdown",definedIn:"src/main/agentLibrary.cjs + src/main/lib/persona-macro/agentPersonaSchema.cjs "},summary:"One global persona. The action/actionLabel frontmatter keys are retired legacy fields — no longer a live concept.",fields:[{name:"name",type:"string",key:"pk"},{name:"description",type:"string | null"},{name:"tools",type:"string[]"},{name:"model",type:"string | null",note:"wins over the Settings default for this Epic"},{name:"color",type:"string | null"},{name:"tags",type:"AgentPersonaTag[]",key:"fk",ref:"tag.tag"},{name:"projects",type:"string[]",key:"fk",ref:"project.cwd",note:"'*' means every project"},{name:"effort",type:"string | null",optional:!0,note:"per-Epic carve-out like model — persona frontmatter wins over the Settings default"},{name:"title",type:"string | null",optional:!0},{name:"path",type:"string"},{name:"body",type:"string"},{name:"overridingProjects",type:"string[]"}]},{id:"tag",name:"Tag",aka:"MISSION — EpicTag",group:"agents",store:{path:"src/renderer/lib/tagLibrary.ts (TAG_LIBRARY)",format:"code",definedIn:"src/renderer/lib/tagLibrary.ts + src/renderer/lib/agentTagDefs.ts "},summary:"The closed 7-tag union — Epic creation is agentType (who) + tag (what), two independent selections.",fields:[{name:"tag",type:"'feature' | 'bug' | 'discussion' | 'build' | 'project-home-builder' | 'art' | 'portfolio'",key:"pk"},{name:"label",type:"string"},{name:"description",type:"string"},{name:"developEagerness",type:"'expected-default' | 'available-not-assumed'"},{name:"developsVia",type:"string"}]},{id:"macro",name:"Macro",aka:"HOT KEY",group:"agents",store:{path:"~/.claude/session-manager/macros.json",format:"json",writer:"src/main/lib/persona-macro/macroLibrary.cjs",definedIn:"src/main/lib/persona-macro/macroLibrary.cjs "},summary:"A saved (agent, tag, prompt) hot key — machine-local library; a Sessions hot key is shown per project, a Project Home tool in every project; pressing it is the same act as New Session.",fields:[{name:"id",type:"string",key:"pk"},{name:"label",type:"string"},{name:"agentName",type:"string",key:"fk",ref:"agentPersona.name"},{name:"tag",type:"TicketTag",key:"fk",ref:"tag.tag"},{name:"prompt",type:"string"},{name:"projects",type:"string[]",key:"fk",ref:"project.cwd"},{name:"surface",type:"string"},{name:"builtin",type:"boolean",optional:!0},{name:"builtinVersion",type:"number",optional:!0},{name:"createdAt",type:"string"},{name:"updatedAt",type:"string"},{name:"inputs",type:"MacroInput[]",optional:!0},{name:"autoStartTargets",type:"string[]",optional:!0,key:"fk",ref:"project.cwd"}]},{id:"memoryEntry",name:"MemoryEntry",group:"memory",store:{path:"~/.claude/projects/<encodedCwd>/memory/<name>.md",format:"markdown",definedIn:"src/main/memoryTool.cjs "},summary:"One workspace memory file, semantically organized by topic.",fields:[{name:"name",type:"string",key:"pk"},{name:"path",type:"string"},{name:"mtimeMs",type:"number"},{name:"bytes",type:"number"},{name:"workspace",type:"string",key:"fk",ref:"project.cwd",note:"carried on MemoryListResult, denormalized here — the directory this entry lives under"}]},{id:"memoryCluster",name:"MemoryCluster",group:"memory",store:{path:"<cwd>/session-manager-operations/memory-clusters/clusters.json",format:"json",writer:"memory-clusters",definedIn:"src/main/memoryAggregate.cjs "},summary:"Derived grouping of related MemoryEntry files, computed and cached per workspace.",fields:[{name:"id",type:"string",key:"pk"},{name:"name",type:"string"},{name:"summary",type:"string"},{name:"memberSlugs",type:"string[]",key:"fk",ref:"memoryEntry.name"},{name:"links",type:"MemoryClusterLink[]",note:"{ from, to, label? }"}]},{id:"agentMemoryEntry",name:"AgentMemoryEntry",group:"memory",store:{path:"~/.claude/agent-memory/<agent>/ | .claude/agent-memory/<agent>/ | .claude/agent-memory-local/<agent>/",format:"directory",definedIn:"src/main/lib/memoryDirResolve.cjs (resolveAgentMemoryDir)"},summary:"Per-subagent memory in Claude Code's native agent-memory directories (user, project, local scope), keyed by agent name — markdown files with a MEMORY.md index.",fields:[{name:"agent",type:"string",key:"pk",ref:"agentPersona.name",note:"directory name under the scope root"},{name:"scope",type:"'user' | 'project' | 'local'",note:"selects which agent-memory root resolveAgentMemoryDir returns"},{name:"files",type:"markdown[]",note:"topic files plus MEMORY.md index, read live from disk"}]},{id:"claudeTranscript",name:"Claude transcript",group:"transcript",store:{path:"~/.claude/projects/<encodedCwd>/<sessionUuid>.jsonl",format:"jsonl",definedIn:"written by the Claude Code CLI; tailed by src/main/transcripts.cjs "},summary:"The CLI's own append-only transcript — Session Manager only tails and classifies it, never writes it.",fields:[{name:"sessionUuid",type:"string",key:"pk"},{name:"encodedCwd",type:"string",key:"fk",ref:"project.cwd"}]},{id:"transcriptEvent",name:"TranscriptEvent",group:"transcript",store:{path:"in-memory ring buffer, broadcast as transcript:event:<tabId>",format:"in-memory",definedIn:"src/main/transcripts.cjs -> src/renderer/state/live.ts "},summary:"Classified, bounded-preview view over one raw transcript line — never the source of truth.",fields:[{name:"kind",type:"TranscriptEventKind"},{name:"data",type:"unknown"},{name:"raw",type:"unknown"},{name:"previewText",type:"string"},{name:"ref",type:"TranscriptEventRef | null",note:"{ filePath, byteOffset, byteLength }"},{name:"tabId",type:"string",key:"fk",ref:"tab.id"}]},{id:"historyRollupDay",name:"History rollup day",group:"transcript",store:{path:"~/.claude/session-manager/history-rollup.jsonl",format:"jsonl",definedIn:"src/main/lib/historyRollup.cjs "},summary:"One finalized day-per-project analytics row (History tab is analytics/cost/charts only).",fields:[{name:"date",type:"string",key:"pk"},{name:"projectCwd",type:"string",key:"fk",ref:"project.cwd"},{name:"promptCount",type:"number"},{name:"inputTokens",type:"number"},{name:"outputTokens",type:"number"},{name:"estimatedCostUsd",type:"number"}]},{id:"billingUsage",name:"UsageSnapshot",group:"transcript",store:{path:"~/.claude/session-manager/billing-cache.json",format:"json",definedIn:"src/main/usage.cjs (CACHE_PATH) "},summary:"Cached rolling-window utilization percentages from the account's billing API.",fields:[{name:"five_hour",type:"UsageWindow | null"},{name:"seven_day",type:"UsageWindow | null"},{name:"seven_day_sonnet",type:"UsageWindow | null"},{name:"seven_day_opus",type:"UsageWindow | null"},{name:"seven_day_oauth_apps",type:"UsageWindow | null"},{name:"extra_usage",type:"{ is_enabled, monthly_limit, used_credits, utilization, currency } | null"}]},{id:"projectBrief",name:"ProjectBrief",group:"brief",store:{path:"<cwd>/session-manager-operations/project-brief/brief.json",format:"json",writer:"project-home",definedIn:"src/main/projectBrief.cjs "},summary:"The synthesized project Brief — generated, with a hand-edit escape hatch.",fields:[{name:"version",type:"number"},{name:"synthesizedAt",type:"string"},{name:"editedAt",type:"string | null"},{name:"model",type:"string"},{name:"purpose",type:"string"},{name:"what",type:"string[]"},{name:"areas",type:"ProjectBriefArea[]",note:"{ name, files, note, epic, heat }"},{name:"scope",type:"ProjectBriefScopeEntry[]",note:"{ when, kind, text, src }"},{name:"conventions",type:"string[]"},{name:"pins",type:"{ what: boolean; conventions: boolean }"},{name:"pinned",type:"{ what: string[] | null; conventions: string[] | null }"}]},{id:"projectPages",name:"ProjectPagesOutput",group:"brief",store:{path:"<cwd>/session-manager-operations/project-pages/ (knowledge/<id>/, videos/<id>/, videos/_character/)",format:"directory",writer:"project-home",definedIn:"src/main/lib/feedback-remote/projectHomeAdminRoutes.cjs (pages, videos and character routes)"},summary:"The Project Home library: Knowledge Pages and Video Pages, each a folder holding index.html + meta.json.",fields:[{name:"html",type:"string | null"},{name:"mtimeMs",type:"number | null"}]},{id:"settingsScope",name:"Settings (scoped)",group:"config",store:{path:"~/.claude/settings.json + <cwd>/.claude/settings.json + <cwd>/.claude/settings.local.json",format:"json",definedIn:"src/main/config.cjs + src/renderer/state/config.ts + src/renderer/lib/mergeScopes.ts "},summary:"Substrate, not per-Epic curation — model is the one field carved out per-Epic (persona wins over Settings).",fields:[{name:"scope",type:"'system' | 'project' | 'local'",key:"pk"},{name:"cwd",type:"string",optional:!0,key:"fk",ref:"project.cwd"},{name:"model",type:"string",optional:!0}]},{id:"layoutEnvelope",name:"LayoutEnvelope",group:"config",store:{path:"~/.claude/session-manager/workbench-layout.json",format:"json",definedIn:"src/main/layoutStore.cjs + src/renderer/state/layout.ts "},summary:"Persisted dockview panel layout, pruned against the live panel registry on hydrate.",fields:[{name:"version",type:"number"},{name:"panels",type:"string[]",key:"fk",ref:"tab.id"},{name:"dockview",type:"Record<string, unknown>",note:"opaque SerializedDockview blob"}]},{id:"opsNamespace",name:"Ops namespace ownership",aka:"the SINGLE-WRITER LAW",group:"config",store:{path:"src/main/lib/opsOwnership.cjs (OWNERS)",format:"code",definedIn:"src/main/lib/opsOwnership.cjs (assertOpsWrite) "},summary:"Fail-closed — a new top-level ops folder must land in OWNERS (or the deliberately-unowned list) in the same PR that creates it.",fields:[{name:"namespace",type:"string",key:"pk",note:"e.g. 'prompt-sessions', 'scheduler', 'project-brief'"},{name:"writer",type:"string",note:"e.g. 'epics', 'scheduler', 'project-home'"}]},{id:"mcpServerRegistry",name:"MCP server registry",aka:"mcpServers",group:"config",store:{path:"~/.claude.json -> mcpServers",format:"json",definedIn:"src/renderer/components/tabs/McpServers.tsx "},summary:"User-scope MCP server config — no single writer, since both the claude CLI and this app read/write the same file.",fields:[{name:"name",type:"string",key:"pk"},{name:"type",type:"'stdio' | 'http' | 'sse' | 'ws' | 'streamable-http'",optional:!0},{name:"command",type:"string",optional:!0},{name:"args",type:"string[]",optional:!0},{name:"url",type:"string",optional:!0},{name:"env",type:"Record<string, string>",optional:!0},{name:"headers",type:"Record<string, string>",optional:!0},{name:"alwaysLoad",type:"boolean",optional:!0},{name:"enabled",type:"boolean",optional:!0},{name:"disabledTools",type:"string[]",optional:!0}]},{id:"pluginRegistry",name:"Installed plugins manifest",aka:"installed_plugins.json",group:"config",store:{path:"~/.claude/plugins/installed_plugins.json",format:"json",definedIn:"src/renderer/components/tabs/Plugins.tsx "},summary:'Registry of installed plugin versions, keyed by "<name>@<marketplace>" — written by `claude plugin install`, read-only in the Plugins screen.',fields:[{name:"pluginKey",type:"string",key:"pk",note:"<name>@<marketplace>"},{name:"scope",type:"string"},{name:"installPath",type:"string"},{name:"version",type:"string"},{name:"installedAt",type:"string"},{name:"lastUpdated",type:"string"},{name:"gitCommitSha",type:"string",optional:!0}]},{id:"systemPrompt",name:"User CLAUDE.md",aka:"~/.claude/CLAUDE.md",group:"config",store:{path:"~/.claude/CLAUDE.md",format:"markdown",definedIn:"src/renderer/components/tabs/SystemPrompt.tsx "},summary:"The real ~/.claude/CLAUDE.md the claude CLI loads into every session it starts on this machine, in every project — edited here as plain markdown.",fields:[{name:"content",type:"string"},{name:"imports",type:"string[]",note:"@-imported files, listed in a left rail"}]},{id:"skillsAndCommands",name:"Skills & Commands",group:"config",store:{path:"~/.claude/skills/**/SKILL.md + ~/.claude/commands/*.md (and the <cwd>/.claude equivalents for project scope)",format:"directory",definedIn:"src/renderer/components/tabs/Skills.tsx "},summary:"User- and project-scope skill/command markdown files, each editable in place.",fields:[{name:"kind",type:"'skills' | 'commands'"},{name:"scope",type:"'user' | 'project'"},{name:"name",type:"string",key:"pk"},{name:"path",type:"string",note:"absolute path to the editable markdown file"},{name:"dir",type:"string | null",note:"skill directory, if applicable"},{name:"disabled",type:"boolean",note:"skills only — disable-model-invocation: true frontmatter"},{name:"description",type:"string",optional:!0}]},{id:"mcpStatusProbe",name:"MCP status probe",group:"config",store:{path:"in-memory result of `claude mcp list`, never persisted",format:"in-memory",definedIn:"src/main/mcpStatus.cjs (runProbe) "},summary:"Read-only, non-polling live connection probe — models an in-memory-only shape honestly, the same way transcriptEvent does.",fields:[{name:"ok",type:"boolean"},{name:"servers",type:"McpServerStatus[]",note:"{ name, target, transport, status }"},{name:"error",type:"string",optional:!0},{name:"checkedAt",type:"number"}]},{id:"appPrefs",name:"App preferences",aka:"app-prefs / ui-settings-prefs / ui-chrome-prefs",group:"config",store:{path:"~/.claude/session-manager/app-prefs.json + ~/.claude/session-manager/ui-settings-prefs.json + ~/.claude/session-manager/ui-chrome-prefs.json",format:"json",definedIn:"src/renderer/lib/appPrefs.ts (app-prefs.json) + src/renderer/lib/uiSettingsPrefs.ts (ui-settings-prefs.json) + src/renderer/state/uiChromePrefs.ts (ui-chrome-prefs.json) "},summary:"Three small machine-level renderer-owned pref files, read/written through window.api.config — distinct from scheduler-machine.json.",fields:[{name:"openToHomeOnLaunch",type:"boolean",optional:!0,note:"app-prefs.json — read by layout.ts at boot"},{name:"uiSettings",type:"Record<string, unknown>",optional:!0,note:"ui-settings-prefs.json — Settings page UI state"},{name:"uiChrome",type:"Record<string, unknown>",optional:!0,note:"ui-chrome-prefs.json — app chrome UI state"}]},{id:"uiPrefs",name:"UiPrefs",aka:"ui-prefs/prefs.json",group:"config",store:{path:"<cwd>/session-manager-operations/ui-prefs/prefs.json",format:"json",writer:"ui-prefs",definedIn:"src/renderer/lib/uiPrefs.ts "},summary:"Per-project UI state that used to live in scattered global/localStorage keys — one file per project keeps it scoped to the project it belongs to by construction (PRD 1398/1399).",fields:[{name:"fileTreeExpanded",type:"string[]",optional:!0,note:"FileTree.tsx — expanded folder paths in the Files sidebar"},{name:"hiddenCompletedSlugs",type:"string[]",optional:!0,note:'SchedulePanel.tsx — "Clear completed" hides, renderer-side only'},{name:"queueFilterStatus",type:"string",optional:!0,note:"SchedulePanel.tsx — the queue's status filter chip"},{name:"epicPins",type:"Record<string, boolean>",optional:!0,key:"fk",ref:"epic.id",note:"epicsPrefs.ts — pinned-to-top Epic ids, keyed by epicId (moved off the global epics-prefs.json)"},{name:"chatVerbosityPerEpic",type:"Record<string, ChatVerbosity>",optional:!0,key:"fk",ref:"epic.id",note:"chatPrefs.ts — per-Epic verbosity overrides, keyed by epicId (moved off the global chat-prefs.json)"},{name:"editorSession",type:"{ openFiles: string[]; activeFilePath: string | null; viewModeByPath: Record<string, string> }",optional:!0,note:"editor.ts — the Editor scene's structural tab strip only; buffers/baselines/dirty are never persisted (PRD 1400)"}]}];function te(t){const n=B.find(s=>s.id===t);if(!n)throw new Error(`unknown ErdEntity id: ${t}`);return n}const je=[{from:"tab",to:"project",cardinality:"N-1",label:"belongs to"},{from:"epic",to:"project",cardinality:"N-1",label:"belongs to"},{from:"epic",to:"tag",cardinality:"N-1",label:"mission",optional:!0},{from:"epic",to:"agentPersona",cardinality:"N-1",label:"actor",optional:!0},{from:"epic",to:"epic",cardinality:"N-1",label:"resumed from",optional:!0},{from:"epic",to:"claudeTranscript",cardinality:"1-1",label:"1:1 session"},{from:"epicEvent",to:"epic",cardinality:"N-1",label:"belongs to"},{from:"epicEvent",to:"epicEvent",cardinality:"N-1",label:"caused by",optional:!0},{from:"epicEvent",to:"prd",cardinality:"N-1",label:"about",optional:!0},{from:"epicTranscriptTurn",to:"epic",cardinality:"N-1",label:"belongs to"},{from:"epicTranscriptTurn",to:"epicEvent",cardinality:"N-1",label:"labeled by",optional:!0},{from:"epicArchive",to:"epic",cardinality:"1-1",label:"freezes"},{from:"exchange",to:"epic",cardinality:"N-1",label:"session for",optional:!0},{from:"exchange",to:"project",cardinality:"N-1",label:"belongs to"},{from:"prd",to:"epic",cardinality:"N-1",label:"joins (directory fact)"},{from:"prd",to:"epic",cardinality:"N-1",via:"sourcePromptId",label:"authored from (frontmatter intent)",optional:!0},{from:"prd",to:"project",cardinality:"N-1",label:"belongs to"},{from:"prd",to:"tag",cardinality:"N-1",label:"mission",optional:!0},{from:"scheduleJob",to:"prd",cardinality:"1-1",label:"executes"},{from:"scheduleJob",to:"prd",cardinality:"N-N",via:"dependsOn",label:"depends on",optional:!0},{from:"scheduleJob",to:"epic",cardinality:"N-1",label:"belongs to",optional:!0},{from:"scheduleJob",to:"runLog",cardinality:"N-1",label:"ran as",optional:!0},{from:"scheduleJob",to:"scheduleJob",cardinality:"N-N",via:"dependsOn",label:"depends on (self)",optional:!0},{from:"scheduleJobStatusHistory",to:"scheduleJob",cardinality:"N-1",label:"transitions of"},{from:"scheduleHistoryEntry",to:"prd",cardinality:"N-1",label:"archives"},{from:"scheduleHistoryEntry",to:"epic",cardinality:"N-1",label:"belongs to",optional:!0},{from:"scheduleHistoryEntry",to:"runLog",cardinality:"N-1",label:"ran as",optional:!0},{from:"scheduleConfig",to:"project",cardinality:"1-1",label:"configures"},{from:"agentPersona",to:"tag",cardinality:"N-N",label:"tagged with"},{from:"agentPersona",to:"project",cardinality:"N-N",label:"scoped to"},{from:"memoryEntry",to:"project",cardinality:"N-1",label:"workspace"},{from:"memoryCluster",to:"memoryEntry",cardinality:"1-N",label:"clusters"},{from:"agentMemoryEntry",to:"agentPersona",cardinality:"N-1",label:"belongs to"},{from:"transcriptEvent",to:"tab",cardinality:"N-1",label:"classified for"},{from:"transcriptEvent",to:"claudeTranscript",cardinality:"N-1",label:"classified from"},{from:"claudeTranscript",to:"project",cardinality:"N-1",label:"belongs to"},{from:"historyRollupDay",to:"project",cardinality:"N-N",label:"aggregates"},{from:"billingUsage",to:"scheduleConfig",cardinality:"1-N",label:"gates when-available firing"},{from:"projectBrief",to:"project",cardinality:"1-1",label:"describes"},{from:"projectBrief",to:"epic",cardinality:"N-1",via:"areas[].epic",label:"traces to",optional:!0},{from:"projectPages",to:"project",cardinality:"1-1",label:"generated for"},{from:"settingsScope",to:"project",cardinality:"N-1",label:"scoped to",optional:!0},{from:"layoutEnvelope",to:"tab",cardinality:"1-N",label:"panels for"},{from:"opsNamespace",to:"epic",cardinality:"1-N",label:"governs writes"},{from:"opsNamespace",to:"prd",cardinality:"1-N",label:"governs writes"},{from:"opsNamespace",to:"projectBrief",cardinality:"1-N",label:"governs writes"}];function ve(t){return je.filter(n=>n.from===t||n.to===t)}function Tt(t){const n=new Set;for(const s of ve(t)){const r=s.from===t?s.to:s.from;r!==t&&n.add(r)}return[...n]}function It(t){switch(t){case"1-1":return"1—1";case"1-N":return"1—N";case"N-1":return"N—1";case"N-N":return"N—N"}}const fe=220,Q=7,Pt=44,Rt=16,At=10,Mt=96,Lt=28,W=24;function Dt(t){const n=Math.min(t,Q)+(t>Q?1:0);return Pt+n*Rt+At}function Ot(t){const n=t.x+t.w,s=t.y+t.h*.35,r=t.y+t.h*.65,i=n+48;return{d:`M ${n} ${s} C ${i} ${s}, ${i} ${r}, ${n} ${r}`,mx:i,my:(s+r)/2}}function $t(t=B,n=je){const s=q.map(p=>p.id).filter(p=>t.some(f=>f.group===p)),r=[],i=new Map;s.forEach((p,f)=>{const m=W+f*(fe+Mt);let c=W;for(const g of t){if(g.group!==p)continue;const j=Dt(g.fields.length),v={id:g.id,group:p,x:m,y:c,w:fe,h:j};r.push(v),i.set(g.id,v),c+=j+Lt}});const a=new Set(t.map(p=>p.id)),d=[];for(const p of n){if(!a.has(p.from)||!a.has(p.to))continue;const f=i.get(p.from),m=i.get(p.to);if(!f||!m)continue;if(p.from===p.to){const T=Ot(f);d.push({relation:p,...T});continue}const c=f.x<m.x,g=c?f.x+f.w:f.x,j=f.y+f.h/2,v=c?m.x:m.x+m.w,N=m.y+m.h/2,S=Math.max(40,Math.abs(v-g)/2),h=g+(c?S:-S),w=v+(c?-S:S),C=`M ${g} ${j} C ${h} ${j}, ${w} ${N}, ${v} ${N}`;d.push({relation:p,d:C,mx:(g+v)/2,my:(j+N)/2})}const u=r.reduce((p,f)=>Math.max(p,f.x+f.w),0),y=r.reduce((p,f)=>Math.max(p,f.y+f.h),0);return{boxes:r,edges:d,width:u+W,height:y+W}}const _t=[{key:"diagram",label:"Diagram"},{key:"tables",label:"Tables"}];function Ht(){const[t,n]=o.useState("diagram"),[s,r]=o.useState(null),[i,a]=o.useState(()=>new Set),d=o.useMemo(()=>B.filter(m=>!i.has(m.group)),[i]),u=o.useMemo(()=>$t(d),[d]),y=m=>{a(c=>{const g=new Set(c);return g.has(m)?g.delete(m):g.add(m),g}),r(null)},p=s?te(s):null,f=m=>d.some(c=>c.id===m);return e.jsx(nt,{toolbar:e.jsxs(e.Fragment,{children:[e.jsx(xe,{options:_t,active:t,onChange:n}),e.jsx(Ft,{hiddenGroups:i,onToggle:y}),e.jsxs("span",{className:"ml-auto text-fg-faint",children:[B.length," entities"]})]}),children:t==="diagram"?e.jsxs("div",{className:"h-full flex",children:[e.jsx("div",{className:"flex-1 min-w-0 overflow-auto",children:e.jsx(Ut,{layout:u,selectedId:s,onSelect:m=>r(c=>c===m?null:m)})}),e.jsx("div",{className:"w-96 shrink-0 border-l border-line overflow-y-auto",children:p?e.jsx(Wt,{entity:p,onSelectRelated:m=>f(m)?r(m):void 0}):e.jsx(G,{title:"select an entity",hint:"click a box in the diagram to see its storage, fields, and relations"})})]}):e.jsx(Jt,{})})}const Bt=o.memo(Ht);function Ft({hiddenGroups:t,onToggle:n}){return e.jsx("div",{className:"flex items-center gap-1.5 flex-wrap",children:q.map(s=>{const r=t.has(s.id);return e.jsxs("button",{onClick:()=>n(s.id),title:`${s.blurb} (${s.realm})`,className:`flex items-center gap-1 px-1.5 py-0.5 rounded border text-[10.5px] ${r?"border-line text-fg-faint opacity-50":"border-line text-fg-dim hover:text-fg"}`,children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${s.tone.dot}`}),s.label,e.jsx("span",{className:"text-fg-faint",children:s.realm})]},s.id)})})}function Ut({layout:t,selectedId:n,onSelect:s}){const r=o.useMemo(()=>n?new Set(Tt(n)):null,[n]),i=a=>!!n&&(a.relation.from===n||a.relation.to===n);return t.boxes.length===0?e.jsx(G,{title:"no entities in view",hint:"toggle a group in the legend to show its entities"}):e.jsxs("div",{className:"relative p-4",style:{width:t.width+32,height:t.height+32},children:[e.jsxs("svg",{width:t.width,height:t.height,className:"absolute left-4 top-4 overflow-visible",children:[t.edges.map(a=>{const d=i(a);return e.jsx("path",{"data-testid":`erd-edge-${a.relation.from}-${a.relation.to}`,d:a.d,fill:"none",className:d?"stroke-accent":"stroke-line",strokeWidth:d?2:1,opacity:n&&!d?.25:1},`${a.relation.from}-${a.relation.to}-${a.relation.label}`)}),t.edges.map(a=>i(a)?e.jsx("text",{x:a.mx,y:a.my,textAnchor:"middle",className:"fill-fg-dim text-[10px]",children:a.relation.label},`label-${a.relation.from}-${a.relation.to}-${a.relation.label}`):null)]}),t.boxes.map(a=>e.jsx(zt,{box:a,selected:a.id===n,dimmed:!!n&&a.id!==n&&!(r!=null&&r.has(a.id)),onClick:()=>s(a.id)},a.id))]})}function zt({box:t,selected:n,dimmed:s,onClick:r}){const i=te(t.id),a=be(t.group),d=i.fields.slice(0,Q),u=i.fields.length-d.length;return e.jsxs("button",{type:"button","data-testid":`erd-box-${t.id}`,onClick:r,className:`absolute text-left rounded border overflow-hidden bg-bg-hi ${n?"border-accent ring-1 ring-accent":"border-line"} ${s?"opacity-30":""}`,style:{left:t.x,top:t.y,width:t.w,height:t.h},children:[e.jsxs("div",{className:"px-2 py-1 border-b border-line flex items-center gap-1.5",children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${a.tone.dot}`}),e.jsx("span",{className:"text-[11px] font-semibold text-fg truncate",children:i.name})]}),i.aka&&e.jsx("div",{className:"px-2 pt-0.5 text-[9.5px] text-fg-faint truncate",children:i.aka}),e.jsxs("div",{className:"px-2 py-0.5",children:[d.map(y=>e.jsxs("div",{className:"text-[9.5px] font-mono text-fg-dim truncate flex items-center gap-1",children:[y.key&&e.jsx("span",{className:"text-fg-faint",children:y.key}),e.jsx("span",{className:"truncate",children:y.name})]},y.name)),u>0&&e.jsxs("div",{className:"text-[9.5px] text-fg-faint italic",children:["+",u," more"]})]})]})}function we({fields:t}){return e.jsxs("table",{className:"w-full text-[11px] font-mono",children:[e.jsx("thead",{className:"text-fg-faint uppercase tracking-wide text-[9.5px]",children:e.jsxs("tr",{className:"border-b border-line",children:[e.jsx("th",{className:"text-left font-normal px-2 py-1",children:"name"}),e.jsx("th",{className:"text-left font-normal px-2 py-1",children:"type"}),e.jsx("th",{className:"text-left font-normal px-2 py-1",children:"key"}),e.jsx("th",{className:"text-left font-normal px-2 py-1",children:"note"})]})}),e.jsx("tbody",{children:t.map(n=>e.jsxs("tr",{className:"border-b border-line/50",children:[e.jsxs("td",{className:"px-2 py-1 text-fg",children:[n.name,n.optional&&e.jsx("span",{className:"text-fg-faint",children:"?"})]}),e.jsx("td",{className:"px-2 py-1 text-fg-dim",children:n.type}),e.jsx("td",{className:"px-2 py-1",children:n.key&&e.jsxs(L,{tone:n.key==="pk"?"accent":"dim",children:[n.key,n.ref?` → ${n.ref}`:""]})}),e.jsx("td",{className:"px-2 py-1 text-fg-faint",children:n.note})]},n.name))})]})}function ke({entity:t}){return e.jsxs("div",{className:"space-y-1 text-[11px]",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-fg-faint w-20 shrink-0",children:"path"}),e.jsx("span",{className:"font-mono text-fg-dim break-all",children:t.store.path})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-fg-faint w-20 shrink-0",children:"format"}),e.jsx("span",{className:"font-mono text-fg-dim",children:t.store.format})]}),t.store.writer&&e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-fg-faint w-20 shrink-0",children:"writer"}),e.jsxs(L,{tone:"accent",children:["single-writer: ",t.store.writer]})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-fg-faint w-20 shrink-0",children:"definedIn"}),e.jsx("span",{className:"font-mono text-fg-dim break-all",children:t.store.definedIn})]})]})}function Wt({entity:t,onSelectRelated:n}){const s=be(t.group),r=ve(t.id);return e.jsxs("div",{className:"p-3 space-y-3",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:`w-2 h-2 rounded-full ${s.tone.dot}`}),e.jsx("span",{className:"text-sm font-semibold text-fg",children:t.name})]}),t.aka&&e.jsx("div",{className:"text-[10.5px] text-fg-faint",children:t.aka}),e.jsx(L,{tone:"dim",className:"mt-1",children:s.label})]}),e.jsx("div",{className:"text-xs text-fg-dim leading-relaxed",children:t.summary}),e.jsxs("div",{children:[e.jsx(J,{children:"storage"}),e.jsx(ke,{entity:t})]}),e.jsxs("div",{children:[e.jsx(J,{children:"fields"}),e.jsx(we,{fields:t.fields})]}),t.notes&&t.notes.length>0&&e.jsxs("div",{children:[e.jsx(J,{children:"notes"}),e.jsx("ul",{className:"list-disc pl-4 space-y-0.5 text-xs text-fg-dim",children:t.notes.map(i=>e.jsx("li",{children:i},i))})]}),e.jsxs("div",{children:[e.jsx(J,{children:"relations"}),r.length===0?e.jsx("div",{className:"text-xs text-fg-faint italic",children:"no relations"}):e.jsx("ul",{className:"space-y-1",children:r.map(i=>{const a=i.from===t.id?i.to:i.from,d=te(a);return e.jsxs("li",{className:"flex items-center gap-1.5 text-xs",children:[e.jsx("span",{className:"font-mono text-fg-faint w-10 shrink-0",children:It(i.cardinality)}),e.jsx("span",{className:"text-fg-dim",children:i.label}),i.via&&e.jsxs("span",{className:"font-mono text-[10px] text-fg-faint",children:["via ",i.via]}),e.jsx("button",{type:"button",onClick:()=>n(a),className:"ml-auto text-accent hover:underline font-mono",children:d.name})]},`${i.from}-${i.to}-${i.label}`)})})]})]})}function J({children:t}){return e.jsx("div",{className:"text-[10.5px] uppercase tracking-wide text-fg-faint mb-1 font-mono",children:t})}function Jt(){return e.jsx("div",{className:"p-4 space-y-6",children:q.map(t=>{const n=B.filter(s=>s.group===t.id);return n.length===0?null:e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-2",children:[e.jsx("span",{className:`w-2 h-2 rounded-full ${t.tone.dot}`}),e.jsx("span",{className:"text-xs font-semibold text-fg",children:t.label}),e.jsx("span",{className:"text-[10.5px] text-fg-faint",children:t.realm})]}),e.jsx("div",{className:"grid grid-cols-1 xl:grid-cols-2 gap-3",children:n.map(s=>e.jsxs("div",{className:"border border-line rounded bg-bg-hi p-3 space-y-2",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-semibold text-fg",children:s.name}),s.aka&&e.jsx("span",{className:"text-[10.5px] text-fg-faint",children:s.aka})]}),e.jsx(L,{tone:"dim",className:"mt-1",children:t.label})]}),e.jsx("div",{className:"text-xs text-fg-dim leading-relaxed",children:s.summary}),e.jsx(ke,{entity:s}),e.jsx(we,{fields:s.fields}),s.notes&&s.notes.length>0&&e.jsx("ul",{className:"list-disc pl-4 space-y-0.5 text-xs text-fg-dim",children:s.notes.map(r=>e.jsx("li",{children:r},r))})]},s.id))})]},t.id)})})}const ge=[{key:"voice",label:"Voice"},{key:"appearance",label:"Appearance"},{key:"telemetry",label:"Telemetry"},{key:"remote",label:"Phone remote"},{key:"updates",label:"Updates & retention"},{key:"startup",label:"Startup"},{key:"storage",label:"Storage map"}],Vt={compact:"Compact",roomy:"Roomy"},Gt=".claude/session-manager";function qt({files:t}){const n=qe();return e.jsx("div",{className:"flex flex-wrap gap-2 px-4 pt-3","data-testid":"app-settings-chips",children:t.map(s=>{const r=s.path.startsWith("~/")?n?n+s.path.slice(1):null:s.path;return r?e.jsx(Qe,{path:r,keyPath:s.keyPath},s.path):null})})}function Yt(){const[t,n]=o.useState(!1),[s,r]=o.useState(!1);o.useEffect(()=>{let a=!0;return Ke().then(d=>{a&&n(d.openToHomeOnLaunch===!0)}),()=>{a=!1}},[]);const i=async a=>{n(a),r(!0);try{await Ze({openToHomeOnLaunch:a})}catch{n(!a),he.error('Failed to save "Open to Home on launch" — try again.')}finally{r(!1)}};return e.jsx("div",{className:"p-4 max-w-3xl space-y-3 text-sm",children:e.jsx(O,{checked:t,onChange:i,disabled:s,label:"Open to Home on launch"})})}function Xt(){const{density:t,setDensity:n}=Ye();return e.jsxs("div",{className:"p-4 max-w-3xl space-y-5 text-sm",children:[e.jsx(pt,{}),e.jsxs("section",{className:"border border-line rounded p-3 space-y-1",children:[e.jsx("span",{className:"text-fg-dim text-xs",children:"Density"}),e.jsx(Xe,{options:["compact","roomy"],value:t,onChange:s=>n(s),labels:Vt}),e.jsx("span",{className:"text-fg-faint text-[11px]",children:"Compact tightens spacing across the app's chrome; Roomy is the default."})]})]})}const D=(t,n)=>({path:`~/${Gt}/${t}`,keyPath:n}),Kt={voice:[D("voice.json")],appearance:[{path:Ge,keyPath:["terminal"]},D("ui-chrome-prefs.json")],telemetry:[D("telemetry.json"),D("otel.json")],remote:[D("web-remote.json")],updates:[D("updater.json"),D("ops-retention.json")],startup:[{path:Ve,keyPath:["openToHomeOnLaunch"]}],storage:[]};function sn(){const[t,n]=o.useState("voice");return Je("app-settings",s=>{ge.some(r=>r.key===s)&&n(s)}),e.jsxs("div",{className:"flex flex-col h-full min-h-0","data-testid":"app-settings",children:[e.jsx("div",{className:"flex items-center px-4 pt-3",children:e.jsx(xe,{options:ge,active:t,onChange:n})}),e.jsx(qt,{files:Kt[t]}),e.jsxs("div",{className:"flex-1 min-h-0 overflow-auto","data-testid":`app-settings-${t}`,children:[t==="voice"&&e.jsx(rt,{open:!0,onClose:()=>{},variant:"page"}),t==="appearance"&&e.jsx(Xt,{}),t==="telemetry"&&e.jsx(gt,{}),t==="remote"&&e.jsx(wt,{}),t==="updates"&&e.jsxs("div",{className:"p-4 max-w-3xl space-y-5",children:[e.jsx(kt,{}),e.jsx(Et,{})]}),t==="startup"&&e.jsx(Yt,{}),t==="storage"&&e.jsx(Bt,{})]})]})}export{sn as AppSettings};