claude-code-session-manager 0.137.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.
- package/.claude-plugin/marketplace.json +1 -1
- package/README.md +339 -82
- package/dist/assets/{AppSettings-l7NTc0yu.js → AppSettings-CUfWY9vN.js} +2 -2
- package/dist/assets/History-DDnqaLyw.js +2 -0
- package/dist/assets/HomeClaudeConfig-CGD2Onjv.js +3 -0
- package/dist/assets/{Panel-BuInRmA0.js → Panel-Csyd9HbD.js} +1 -1
- package/dist/assets/ProjectClaudeConfig-C-jlYpC_.js +26 -0
- package/dist/assets/{Scheduler-B7sn2mUw.js → Scheduler-NLs08fx7.js} +9 -9
- package/dist/assets/{SkillReferenceGraph-DwV0Ueyc.js → SkillReferenceGraph-DcscPXAG.js} +1 -1
- package/dist/assets/Skills-BpGRKOcY.js +67 -0
- package/dist/assets/{TiptapBody-Bl8hDhhS.js → TiptapBody-DSU3769X.js} +60 -54
- package/dist/assets/ViewTabs-C0PRZx4_.js +1 -0
- package/dist/assets/{VoiceButton-DJx-jY4r.js → VoiceButton-D2rMurNg.js} +1 -1
- package/dist/assets/{historyTotals-Cgjm5q24.js → historyTotals-TcIQs2sh.js} +1 -1
- package/dist/assets/{index-62tyjEQB.css → index-BCySPdtU.css} +1 -1
- package/dist/assets/index-C-d0DCre.js +3124 -0
- package/dist/index.html +2 -2
- package/dist-web/app.css +1 -1
- package/dist-web/app.js +471 -452
- package/package.json +13 -5
- package/plugins/session-manager-dev/.claude-plugin/plugin.json +1 -1
- package/plugins/session-manager-dev/skills/builder/SKILL.md +12 -4
- package/plugins/session-manager-dev/skills/builder/scripts/publish-preflight.cjs +255 -0
- package/plugins/session-manager-dev/skills/develop/SKILL.md +12 -5
- package/scripts/README.md +1 -0
- package/scripts/scheduler-mcp-server.cjs +161 -18
- package/src/main/build-info.json +4 -4
- package/src/main/chatRunner.cjs +53 -2
- package/src/main/exchanges.cjs +70 -5
- package/src/main/historyAggregator.cjs +84 -58
- package/src/main/historyDashboard.cjs +18 -13
- package/src/main/index.cjs +35 -9
- package/src/main/ipcSchemas.cjs +133 -5
- package/src/main/lib/claude/effectiveModelInfo.cjs +2 -2
- package/src/main/lib/claude/modelPricing.cjs +148 -0
- package/src/main/lib/demo-video-kit/checks.cjs +16 -0
- package/src/main/lib/epic/epicAdminRoutes.cjs +101 -0
- package/src/main/lib/epic/epicAttachments.cjs +143 -0
- package/src/main/lib/epic/epicJobReceipt.cjs +87 -0
- package/src/main/lib/epic/epicMint.cjs +4 -0
- package/src/main/lib/epic/epicOutsideRead.cjs +306 -0
- package/src/main/lib/epic/epicOutsideState.cjs +233 -0
- package/src/main/lib/epic/epicSettle.cjs +1 -1
- package/src/main/lib/epic/epicStateWatcher.cjs +157 -0
- package/src/main/lib/epic/externalRef.cjs +37 -0
- package/src/main/lib/epic/externalRefIndex.cjs +136 -0
- package/src/main/lib/epic/restorableSessions.cjs +151 -17
- package/src/main/lib/epic/transcriptUsage.cjs +197 -0
- package/src/main/lib/externalContract.cjs +111 -0
- package/src/main/lib/feedback-remote/crossProjectFeedback.cjs +121 -4
- package/src/main/lib/feedback-remote/crossProjectReply.cjs +83 -1
- package/src/main/lib/feedback-remote/customerFeedbackAdminRoutes.cjs +16 -6
- package/src/main/lib/feedback-remote/customerFeedbackClient.cjs +50 -8
- package/src/main/lib/feedback-remote/customerFeedbackInbox.cjs +218 -4
- package/src/main/lib/feedback-remote/customerFeedbackIpc.cjs +19 -3
- package/src/main/lib/feedback-remote/feedbackImages.cjs +171 -0
- package/src/main/lib/feedback-remote/localAdminHttp.cjs +11 -10
- package/src/main/lib/feedback-remote/macroAdminRoutes.cjs +287 -1
- package/src/main/lib/feedback-remote/needsYouAdminRoutes.cjs +133 -0
- package/src/main/lib/feedback-remote/needsYouIpc.cjs +50 -0
- package/src/main/lib/feedback-remote/needsYouStore.cjs +281 -0
- package/src/main/lib/feedback-remote/remoteFrameAssembler.cjs +113 -0
- package/src/main/lib/historyRollup.cjs +32 -5
- package/src/main/lib/mcpToolCatalog.cjs +111 -14
- package/src/main/lib/persona-macro/agentAdminRoutes.cjs +121 -0
- package/src/main/lib/persona-macro/macroLibrary.cjs +7 -0
- package/src/main/lib/persona-macro/shippedPersonaSeeds.cjs +11 -0
- package/src/main/lib/process/bootStdioGuard.cjs +32 -0
- package/src/main/lib/process/stdioGuard.cjs +115 -0
- package/src/main/lib/promptSessionSchema.cjs +4 -0
- package/src/main/lib/remoteTranscriptTail.cjs +32 -1
- package/src/main/lib/scheduler/schedulerPaths.cjs +9 -0
- package/src/main/lib/telemetry/auditEvents.cjs +176 -0
- package/src/main/lib/telemetry/eventsAdminRoutes.cjs +45 -0
- package/src/main/loopEfficiencyHandlers.cjs +1 -1
- package/src/main/scheduler.cjs +29 -0
- package/src/main/templates/PRD_AUTHORING.md +1 -0
- package/src/main/transcripts.cjs +62 -7
- package/src/main/webRemote.cjs +122 -18
- package/src/preload/api.d.ts +98 -9
- package/src/preload/apiSurface.cjs +7 -0
- package/src/preload/apiSurface.json +415 -83
- package/src/preload/index.cjs +17 -3
- package/src/seed/agents/demo-video-builder.md +10 -7
- package/dist/assets/AgentLibrary-DV0DTZDC.js +0 -2
- package/dist/assets/Button-Cmfkgjfa.js +0 -1
- package/dist/assets/DocumentEditorPane-MTljV-Uw.js +0 -1
- package/dist/assets/Extensions-Cc1Q_8id.js +0 -2
- package/dist/assets/History-CFo-1DHo.js +0 -2
- package/dist/assets/Library-C_ibFiOx.js +0 -32
- package/dist/assets/ListDetail-ByULG209.js +0 -1
- package/dist/assets/ProjectClaudeConfig-yqqVtHY7.js +0 -25
- package/dist/assets/ProvenanceBadge-CJvnQReI.js +0 -1
- package/dist/assets/Settings-DRRSJksU.js +0 -2
- package/dist/assets/Skills-DVYHA9gV.js +0 -29
- package/dist/assets/SourceChip-DfJ5_5rV.js +0 -1
- package/dist/assets/SystemPrompt-f11wGllK.js +0 -1
- package/dist/assets/Toggle-DaxeFDFp.js +0 -1
- package/dist/assets/ViewTabs-DRtgFKRw.js +0 -1
- package/dist/assets/claude-settings-schema-COigsajx.js +0 -3
- package/dist/assets/index-iQ6pdyuS.js +0 -3116
package/src/preload/index.cjs
CHANGED
|
@@ -164,6 +164,17 @@ contextBridge.exposeInMainWorld('api', {
|
|
|
164
164
|
return () => ipcRenderer.removeListener('macros:changed', listener);
|
|
165
165
|
},
|
|
166
166
|
},
|
|
167
|
+
// Dashboard "Needs you": outside apps' open questions (main/lib/feedback-remote/needsYouIpc.cjs).
|
|
168
|
+
needsYou: {
|
|
169
|
+
list: () => ipcRenderer.invoke('needsYou:list'),
|
|
170
|
+
answer: (payload) => ipcRenderer.invoke('needsYou:answer', payload),
|
|
171
|
+
// Fired after any post/withdraw/answer so every subscriber re-fetches list().
|
|
172
|
+
onChanged: (handler) => {
|
|
173
|
+
const listener = () => handler();
|
|
174
|
+
ipcRenderer.on('needsYou:changed', listener);
|
|
175
|
+
return () => ipcRenderer.removeListener('needsYou:changed', listener);
|
|
176
|
+
},
|
|
177
|
+
},
|
|
167
178
|
appPreview: {
|
|
168
179
|
scripts: (payload) => ipcRenderer.invoke('appPreview:scripts', payload),
|
|
169
180
|
start: (payload) => ipcRenderer.invoke('appPreview:start', payload),
|
|
@@ -276,6 +287,7 @@ contextBridge.exposeInMainWorld('api', {
|
|
|
276
287
|
inboxList: (p) => ipcRenderer.invoke('customerFeedback:inbox-list', p),
|
|
277
288
|
inboxSetStatus: (p) => ipcRenderer.invoke('customerFeedback:inbox-set-status', p),
|
|
278
289
|
inboxLinkEpic: (p) => ipcRenderer.invoke('customerFeedback:inbox-link-epic', p),
|
|
290
|
+
inboxImage: (p) => ipcRenderer.invoke('customerFeedback:inbox-image', p),
|
|
279
291
|
},
|
|
280
292
|
// Diagnostic only — no handler is registered unless the main process was
|
|
281
293
|
// launched with SM_HEAP_SNAPSHOT=1, so this rejects by default.
|
|
@@ -409,9 +421,9 @@ contextBridge.exposeInMainWorld('api', {
|
|
|
409
421
|
archive: (name, target) => ipcRenderer.invoke('memory:archive', { name, ...memoryTarget(target) }),
|
|
410
422
|
restore: (name, target) => ipcRenderer.invoke('memory:restore', { name, ...memoryTarget(target) }),
|
|
411
423
|
listArchived: (target) => ipcRenderer.invoke('memory:listArchived', memoryTarget(target)),
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
proposeFix: (
|
|
424
|
+
// Forwarded unchanged: main's schema flattens `target` (same shape as the relay remote sends).
|
|
425
|
+
ask: (arg) => ipcRenderer.invoke('memory:ask', arg),
|
|
426
|
+
proposeFix: (arg) => ipcRenderer.invoke('memory:proposeFix', arg),
|
|
415
427
|
},
|
|
416
428
|
projectBrief: {
|
|
417
429
|
get: (cwd) => ipcRenderer.invoke('project-brief:get', { cwd }),
|
|
@@ -570,6 +582,8 @@ contextBridge.exposeInMainWorld('api', {
|
|
|
570
582
|
},
|
|
571
583
|
/** Reports the renderer's disposition for an external send back to main. */
|
|
572
584
|
reportExternalSendResult: (result) => ipcRenderer.invoke('chat:external-send-result', result),
|
|
585
|
+
/** Reports the minted epicId (or an error) for a requestId-carrying external new-session back to main. */
|
|
586
|
+
reportExternalNewSessionResult: (result) => ipcRenderer.invoke('chat:external-new-session-result', result),
|
|
573
587
|
/** Fires when a paired phone asks main to start a new Session. */
|
|
574
588
|
onExternalNewSession: (handler) => {
|
|
575
589
|
const listener = (_e, payload) => handler(payload);
|
|
@@ -5,7 +5,7 @@ tools: Read, Grep, Glob, Bash, Write, Edit, mcp__session-manager-scheduler__proj
|
|
|
5
5
|
title: 'Project Home — Demo Video'
|
|
6
6
|
model: opus
|
|
7
7
|
effort: max
|
|
8
|
-
seedVersion:
|
|
8
|
+
seedVersion: 14
|
|
9
9
|
---
|
|
10
10
|
|
|
11
11
|
You are the demo-video-builder. You make a short animated demo, 30 seconds or 1 minute long per `<length_and_pacing>`, that shows someone what this
|
|
@@ -168,15 +168,18 @@ Produce exactly one complete HTML document:
|
|
|
168
168
|
- A 16:9 stage, 1280x720 logical pixels, scaled to fit the viewport with letterboxing.
|
|
169
169
|
- A single clock drives every scene via `requestAnimationFrame` — no per-scene timers of their
|
|
170
170
|
own, so seeking is exact.
|
|
171
|
-
- Expose `window.smDemo = { duration: D, seek(t), play(), pause() }`, where `seek(t)`
|
|
172
|
-
the exact frame for time `t` in seconds, independent of whatever played before it
|
|
173
|
-
|
|
171
|
+
- Expose `window.smDemo = { duration: D, seek(t), play(), pause(), scenes }`, where `seek(t)`
|
|
172
|
+
renders the exact frame for time `t` in seconds, independent of whatever played before it, and
|
|
173
|
+
`scenes` is an array of scene start times in seconds, used for the host's scene markers.
|
|
174
|
+
- Autoplays once on load and draws no playback UI at all: no buttons, no progress/scrub bar, no
|
|
175
|
+
time readout, no prev/next, no sound button, and no `controls` attribute on `<audio>`/`<video>`.
|
|
176
|
+
Project Home's player supplies every control through `window.smDemo`.
|
|
174
177
|
- Narration audio built per `<audio_policy>`; the video must still make sense muted.
|
|
175
178
|
- No network: no `fetch`, `XMLHttpRequest`, `WebSocket`, `EventSource`, `sendBeacon`, `import()`,
|
|
176
179
|
`Worker`, `<iframe>`, `<form>`, or outbound `src`/`href`, and no navigating with `window.open` or
|
|
177
180
|
`location`. No external fonts or images — system font stack only, and any images as `data:` URIs.
|
|
178
|
-
- Respects `prefers-reduced-motion` by rendering the scenes as a static
|
|
179
|
-
|
|
181
|
+
- Respects `prefers-reduced-motion` by rendering the scenes as a static storyboard instead of
|
|
182
|
+
animating them, stepped by the host's `seek(t)` — no in-video prev/next buttons.
|
|
180
183
|
- Under 2 MB total.
|
|
181
184
|
</output_contract>
|
|
182
185
|
|
|
@@ -242,7 +245,7 @@ open('demo.html', 'w').write(html)
|
|
|
242
245
|
Keep the whole document under the 2 MB cap.
|
|
243
246
|
- Wire `play()`/`pause()`/`seek(t)` to the `<audio>` element too (`audio.currentTime = t` on
|
|
244
247
|
seek) so narration never drifts from the visual clock; call `.play()` on load and, on rejection
|
|
245
|
-
(autoplay-blocked),
|
|
248
|
+
(autoplay-blocked), keep playing muted — the host player's sound button unmutes it.
|
|
246
249
|
- Never write the literal pattern `function (` or `function(` in the inline `<script>` —
|
|
247
250
|
`project_video_write`'s safety scanner blocks anything matching `/\bFunction\s*\(/i`.
|
|
248
251
|
Use arrow functions (`() => { ... }`) throughout.
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{bh as J,bc as Ne,aO as b,_ as R,b9 as ne,b7 as C,ay as e,m as H,b6 as Y,a8 as Ce,aD as B,bs as $e,c as W,aE as ke,aL as Se,b4 as Le,a as De,bk as ae,M as Ee,e as U,E as Oe,aa as Pe}from"./index-iQ6pdyuS.js";import{P as se}from"./Panel-BuInRmA0.js";import{L as oe}from"./ListDetail-ByULG209.js";import{V as Te}from"./ViewTabs-DRtgFKRw.js";import{S as re}from"./SourceChip-DfJ5_5rV.js";import{B as M}from"./Button-Cmfkgjfa.js";import{r as Me}from"./claude-settings-schema-COigsajx.js";import"./monaco-editor-BsIlgG7c.js";function ie(t,s){const a=J();Ne([a?`${a}/.claude/agents`:null,...t.map(i=>`${i}/.claude/agents`)],s)}function Re({onOpenPersona:t}){const[s,a]=b.useState(R[0].tag),{personas:i,refresh:d}=ne(r=>C.error(r.message||"failed to load agent personas"));ie([],()=>{d()});const f=R.find(r=>r.tag===s)??null;return e.jsx(se,{toolbar:e.jsxs("span",{className:"text-fg-faint",children:[R.length," tag",R.length===1?"":"s"]}),children:e.jsx(oe,{sidebar:e.jsx("div",{className:"py-1",children:R.map(r=>{const u=Y(r.tag),y=s===r.tag,m=(i==null?void 0:i.filter(h=>h.tags.includes(r.tag)).length)??0;return e.jsxs("button",{onClick:()=>{a(r.tag)},className:`w-full text-left px-3 py-1.5 text-xs flex items-center gap-2 border-l-2 ${y?"bg-bg-hi text-fg border-accent":"text-fg-dim hover:text-fg hover:bg-bg-hi border-transparent"}`,children:[e.jsxs("span",{className:`px-1.5 py-0.5 rounded text-[10px] font-mono font-semibold ${u.bg} ${u.text} ${u.border?"border border-current/30":""}`,children:["#",r.tag]}),e.jsx("span",{className:"truncate",children:r.label}),m>0&&e.jsx("span",{className:"ml-auto text-[10.5px] text-fg-faint font-mono shrink-0",children:m})]},r.tag)})}),detail:f?e.jsx(Fe,{entry:f,personas:i,onOpenPersona:t}):e.jsx(H,{title:"select a tag"})})})}const Ae=b.memo(Re);function Fe({entry:t,personas:s,onOpenPersona:a}){const i=Y(t.tag),d=Ce(t.tag),f=(s==null?void 0:s.filter(r=>r.tags.includes(t.tag)))??[];return e.jsxs("div",{className:"p-4 space-y-4 max-w-3xl",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsxs("span",{className:`px-2 py-1 rounded text-xs font-mono font-semibold ${i.bg} ${i.text} ${i.border?"border border-current/30":""}`,children:["#",t.tag]}),e.jsx("span",{className:"text-sm font-semibold text-fg",children:t.label})]}),e.jsx("div",{className:"text-xs text-fg-dim leading-relaxed",children:t.description}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[10.5px] uppercase tracking-wide text-fg-faint mb-1.5 font-mono",children:"/develop eagerness"}),e.jsx("span",{className:"px-1.5 py-0.5 text-[10px] rounded border border-line text-fg-dim font-mono",children:t.developEagerness})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[10.5px] uppercase tracking-wide text-fg-faint mb-1.5 font-mono",children:"develops via"}),e.jsx("span",{className:"px-1.5 py-0.5 text-[10px] rounded border border-line text-fg-dim font-mono",children:t.developsVia})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[10.5px] uppercase tracking-wide text-fg-faint mb-1.5 font-mono",children:"agents carrying this tag"}),s===null?e.jsx("div",{className:"text-xs text-fg-faint italic",children:"loading…"}):e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[f.map(r=>e.jsx("button",{onClick:()=>a==null?void 0:a(r.name),title:`Open ${r.name} in Personas`,className:"inline-flex items-center bg-bg-elev border border-line rounded px-2 py-0.5 text-[11px] font-mono text-fg-dim hover:text-fg hover:bg-bg-hi",children:r.name},r.name)),f.length===0&&e.jsx("span",{className:"text-xs text-fg-faint italic mr-1",children:"no agent carries this tag yet."})]})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[10.5px] uppercase tracking-wide text-fg-faint mb-1.5 font-mono",children:"opening framing — sent before the human's goal"}),e.jsx("pre",{className:"text-xs text-fg-dim whitespace-pre-wrap bg-bg-elev border border-line rounded p-3 leading-relaxed font-sans",children:d.initialPromptTemplate})]})]})}const Be=new Set(R.map(t=>t.tag));function le(t){return t.filter(s=>Be.has(s))}function Ie(t,s={}){return{name:t.name,originalName:t.name,description:t.description??"",tools:t.tools,model:t.model??"inherit",effort:t.effort??void 0,color:t.color??"",tags:le(t.tags),projects:t.projects,action:t.action??void 0,actionLabel:t.actionLabel??void 0,title:t.title??void 0,body:t.body,...t.agentCli?{agentCli:t.agentCli}:{},...t.agentCliModel?{agentCliModel:t.agentCliModel}:{},...s}}const Ve=t=>{const[s,a]=t.split(".");return Number(s)+(a?Number(a)/100:0)};function We(t){const s=/Effort is supported on ([^.]*?)(?:, with|\.|$)/.exec(t);if(!s)return[];const a=[];for(const i of s[1].split(/,\s*|\s+and\s+/)){const d=/^(\w+)\s+(\d+(?:\.\d+)?)$/.exec(i.trim());d&&a.push({family:d[1].toLowerCase(),version:Ve(d[2])})}return a}var ee,te;const _e=We(String(((te=(ee=Me.properties)==null?void 0:ee.effortLevel)==null?void 0:te.description)??""));function Ge(t,s){const a=new RegExp(`${s}-(\\d+)(?:-(\\d{1,2})(?!\\d))?`,"i").exec(t);if(a)return Number(a[1])+(a[2]?Number(a[2])/100:0);const i=new RegExp(`claude-(\\d+)(?:-(\\d{1,2}))?-${s}`,"i").exec(t);return i?Number(i[1])+(i[2]?Number(i[2])/100:0):null}function Ke(t,s=_e){if(!t||t==="inherit"||s.length===0)return null;const a=B(t);if(!a)return null;const i=s.filter(f=>f.family===a);if(i.length===0)return!1;const d=Ge(t,a);return d===null?null:d>=Math.min(...i.map(f=>f.version))}const Q=["Read","Grep","Glob","Bash","Write","Edit","WebFetch","WebSearch","Task"],ze=["","red","orange","yellow","green","cyan","blue","purple","pink"],de={red:"#c0392b",orange:"#b85c34",yellow:"#c9a227",green:"#6f7d52",cyan:"#3f8f8a",blue:"#4a6fa5",purple:"#7a6a8a",pink:"#b45a80"};function K(t){return{name:t.name,description:t.description??"",tools:t.tools,model:t.model??"inherit",effort:t.effort??"inherit",color:t.color??"",tags:t.tags,body:t.body,agentCli:t.agentCli??"claude",agentCliModel:t.agentCliModel??""}}const X={name:"new-agent",description:"",tools:["Read","Grep"],model:"inherit",effort:"inherit",color:"",tags:[],body:"",agentCli:"claude",agentCliModel:""};function He(t){const s=new Map;for(const a of t){const i=typeof a.cwd=="string"?ke(a.cwd):"";i&&!s.has(i)&&s.set(i,{cwd:i,name:Se(i)})}return[...s.values()].sort((a,i)=>a.name.localeCompare(i.name)||a.cwd.localeCompare(i.cwd))}function ce(t){return[...t.fields.filter(s=>s!=="name"),...t.bodyOverridden?["full body"]:[]]}function Ue(t){return(t.overrideDetails??[]).map(s=>`${s.project}: ${ce(s).join(", ")||"overlay"}`).join(`
|
|
2
|
-
`)}function Je(){const[t,s]=b.useState("personas"),{personas:a,refresh:i}=ne(n=>C.error(n.message||"failed to load agent personas")),[d,f]=b.useState(null),[r,u]=b.useState(""),[y,m]=b.useState(null),[h,g]=b.useState(!1),[N,D]=b.useState(!1),[j,S]=b.useState(null),[E,w]=b.useState(!1),c=b.useRef(!0);b.useEffect(()=>()=>{c.current=!1},[]);const v=$e(n=>n.tabs),o=b.useMemo(()=>He(v),[v]),[$,k]=b.useState(null),P=o.find(n=>n.cwd===$)??null,T=async n=>{await i()&&n&&f(n)};ie(o.map(n=>n.cwd),()=>T()),b.useEffect(()=>{const n=Le();n&&f(n);const p=L=>f(L.detail);return window.addEventListener("sm:select-persona",p),()=>window.removeEventListener("sm:select-persona",p)},[]);const I=e.jsx(Te,{options:[{key:"personas",label:"Personas"},{key:"tags",label:"Tags"}],active:t,onChange:s});if(t==="tags")return e.jsxs("div",{className:"flex flex-col h-full min-h-0",children:[e.jsx("div",{className:"px-3 py-1.5 border-b border-line",children:I}),e.jsx("div",{className:"flex-1 min-h-0",children:e.jsx(Ae,{onOpenPersona:n=>{f(n),m(null),g(!1),s("personas")}})})]});if(a===null)return e.jsx(H,{title:"loading…"});const A=r.toLowerCase(),V=a.filter(n=>!A||n.name.toLowerCase().includes(A)||(n.description??"").toLowerCase().includes(A)),l=a.find(n=>n.name===d)??a[0]??null,x=y??(l?K(l):null),q=!!y&&!!l&&JSON.stringify(y)!==JSON.stringify(K(l)),F=h,xe=n=>{m(null),g(!1),D(!1),S(null),f(n)},ge=n=>m(p=>({...p??(l?K(l):X),...n})),he=()=>{m({...X}),g(!0),D(!1)},pe=()=>{x&&(m({...x,name:x.name+"-copy"}),g(!0))},ue=()=>{m(null),g(!1)},ve=async()=>{if(x){if(!/^[a-z][a-z0-9-]*$/.test(x.name)){C.error('agent name must be lowercase, hyphenated (e.g. "my-agent")');return}w(!0);try{const n=F?null:l,p={name:x.name,originalName:n==null?void 0:n.name,description:x.description,tools:x.tools,model:x.model,effort:x.effort,color:x.color,tags:le(x.tags),body:x.body,agentCli:x.agentCli,...x.agentCli!=="claude"&&x.agentCliModel.trim()?{agentCliModel:x.agentCliModel.trim()}:{}},L=n?Ie(n,p):p;"agentCliModel"in p||delete L.agentCliModel,await window.api.agents.savePersona(L),C.info(F?`created ${x.name}`:`saved ${x.name}`),m(null),g(!1),await T(x.name)}catch(n){C.error(n.message||"failed to save agent persona")}finally{w(!1)}}},be=async()=>{if(l){w(!0);try{await window.api.agents.deletePersona({name:l.name}),C.info(`deleted ${l.name}`),D(!1),m(null),g(!1),await T()}catch(n){C.error(n.message||"failed to delete agent persona")}finally{w(!1)}}},je=async n=>{w(!0);try{await window.api.agents.deletePersona({name:n}),C.info(`deleted ${n}`),S(null),d===n&&(m(null),g(!1)),await T()}catch(p){C.error(p.message||"failed to delete agent persona")}finally{w(!1)}},we=async(n,p)=>{if(l)try{await window.api.agents.removeOverride({name:l.name,projectCwd:n}),C.info(`removed ${p}'s override of ${l.name}`),await T(l.name)}catch(L){C.error(L.message||"failed to remove override")}},ye=async n=>{if(!l||!P)return;const{cwd:p,name:L}=P;w(!0);try{n.model==="inherit"&&n.effort==="inherit"?(await window.api.agents.removeOverride({name:l.name,projectCwd:p}),C.info(`cleared ${L}'s override of ${l.name}`)):(await window.api.agents.savePersona({name:l.name,projectCwd:p,description:"",tools:[],color:"",tags:[],body:"",model:n.model,effort:n.effort}),C.info(`saved ${L}'s override of ${l.name}`)),await T(l.name)}catch(_){C.error(_.message||"failed to save project override")}finally{w(!1)}};return e.jsx(se,{toolbar:e.jsxs(e.Fragment,{children:[I,e.jsxs("span",{className:"text-fg-faint",children:[a.length," persona",a.length===1?"":"s"]}),e.jsx("input",{value:r,onChange:n=>u(n.target.value),placeholder:"filter…",className:"bg-bg border border-line rounded px-2 py-0.5 text-xs text-fg w-40"}),e.jsx("div",{className:"flex-1"}),e.jsx(M,{variant:"primary",onClick:he,children:"+ New agent"})]}),children:e.jsx(oe,{sidebar:e.jsxs("div",{className:"py-1",children:[F&&e.jsx("div",{className:"w-full text-left px-3 py-1 text-xs flex flex-col gap-0.5 bg-bg-hi text-fg border-l-2 border-accent",children:e.jsxs("span",{className:"flex items-center gap-2 justify-between w-full",children:[e.jsx("span",{className:"truncate font-mono",children:x==null?void 0:x.name}),e.jsx("span",{className:"shrink-0 text-[10px] font-semibold text-accent",children:"new"})]})}),V.length===0&&!F?e.jsx("div",{className:"px-3 py-1 text-xs text-fg-faint italic",children:"no agent personas found"}):V.map(n=>{const p=!F&&n.name===d,L=p&&q,_=j===n.name;return e.jsxs("div",{"data-agent-row":n.name,className:`group w-full text-left px-3 py-1 text-xs flex flex-col gap-0.5 border-l-2 cursor-pointer ${p?"bg-bg-hi text-fg border-accent":"text-fg-dim hover:text-fg hover:bg-bg-hi border-transparent"}`,onClick:()=>xe(n.name),children:[e.jsxs("span",{className:"flex items-center gap-2 justify-between w-full",children:[e.jsxs("span",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsx("span",{className:"w-2 h-2 rounded-sm shrink-0",style:{background:n.color?de[n.color]??n.color:"var(--fg-faint, #999)",opacity:n.color?1:.35}}),e.jsx("span",{className:"truncate font-mono",children:n.name})]}),e.jsxs("span",{className:"shrink-0 flex items-center gap-1.5",children:[L&&e.jsx("span",{className:"text-[10px] font-semibold text-accent",children:"unsaved"}),!L&&n.overridingProjects.length>0&&e.jsx("span",{title:Ue(n),children:e.jsxs(W,{tone:"dim",children:[n.overridingProjects.length," override",n.overridingProjects.length>1?"s":""]})}),_?e.jsxs("span",{className:"flex items-center gap-1",onClick:G=>G.stopPropagation(),children:[e.jsx("button",{onClick:()=>je(n.name),disabled:E,title:`Delete ${n.name}`,className:"text-[10px] font-semibold text-red-400 hover:text-red-300",children:"confirm"}),e.jsx("button",{onClick:()=>S(null),title:"Cancel",className:"text-[10px] text-fg-faint hover:text-fg",children:"cancel"})]}):e.jsx("button",{onClick:G=>{G.stopPropagation(),S(n.name)},title:`Delete ${n.name}`,className:"opacity-0 group-hover:opacity-100 text-fg-faint hover:text-red-400 transition-opacity",children:"×"})]})]}),n.description&&e.jsx("span",{className:"truncate text-fg-faint",children:n.description})]},n.name)})]}),detail:x?e.jsx(Ye,{obj:x,set:ge,saved:l,dirty:q,isNew:F,busy:E,confirmDelete:N,setConfirmDelete:D,onDuplicate:pe,onRevert:ue,onSave:ve,onDelete:be,onDropOverride:we,projects:o,selected:P,onSelect:k,onSaveOverride:ye}):e.jsx(H,{title:"select an agent"})})})}const ot=b.memo(Je);function Ye({obj:t,set:s,saved:a,dirty:i,isNew:d,busy:f,confirmDelete:r,setConfirmDelete:u,onDuplicate:y,onRevert:m,onSave:h,onDelete:g,onDropOverride:N,projects:D,selected:j,onSelect:S,onSaveOverride:E}){const w=J(),c=!d&&a?a.path:`${w??"~"}/.claude/agents/${t.name}.md`,v=i||d;return e.jsxs("div",{className:"max-w-3xl",children:[e.jsxs("div",{className:"px-4 py-3 border-b border-line flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"text-sm font-semibold text-fg font-mono",children:t.name}),d?e.jsx(W,{tone:"accent",children:"unsaved draft"}):i?e.jsx(W,{tone:"warn",children:"edited"}):e.jsx(W,{tone:"good",children:"saved"}),e.jsx("span",{className:"ml-auto min-w-0",children:e.jsx(re,{path:c})})]}),e.jsxs("div",{className:"p-4 space-y-4",children:[e.jsx(O,{label:"name",hint:"Filename on disk — lowercase, hyphenated.",children:e.jsx("input",{value:t.name,onChange:o=>s({name:o.target.value.toLowerCase()}),className:"w-full bg-bg border border-line rounded px-2 py-1 text-xs text-fg font-mono"})}),e.jsx(O,{label:"description",hint:"Shown in the list and in agent pickers.",children:e.jsx("input",{value:t.description,onChange:o=>s({description:o.target.value}),className:"w-full bg-bg border border-line rounded px-2 py-1 text-xs text-fg"})}),e.jsx(fe,{value:t.model,onChange:o=>s({model:o})}),e.jsx(me,{value:t.effort,model:t.model,onChange:o=>s({effort:o})}),e.jsx(O,{label:"cli",hint:"Which coding-agent CLI New Session starts this persona on — override per session in New Session → advanced. On a non-Claude CLI the session has no develop loop, no Restore, and this persona's model/effort are not used. Macros, phone launches and scheduled PRDs always run Claude Code.",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(De,{testIdPrefix:"agent-persona-cli",value:t.agentCli,onChange:o=>s({agentCli:o,agentCliModel:""})}),t.agentCli!=="claude"&&e.jsx("input",{"data-testid":"agent-persona-cli-model","aria-label":"CLI model",value:t.agentCliModel,maxLength:128,placeholder:"Blank = the CLI's own default",onChange:o=>s({agentCliModel:o.target.value}),className:"w-full bg-bg border border-line rounded px-2 py-1 text-xs text-fg font-mono"})]})}),!d&&a&&e.jsx(qe,{saved:a,projects:D,selected:j,onSelect:S,busy:f,onSave:E}),e.jsx(O,{label:"tools",hint:`${t.tools.length} of ${Q.length} granted. Anything not ticked is refused at call time.`,children:e.jsx("div",{className:"flex flex-wrap gap-1.5",children:Q.map(o=>{const $=t.tools.includes(o);return e.jsx("button",{onClick:()=>s({tools:$?t.tools.filter(k=>k!==o):[...t.tools,o]}),className:`px-2 py-0.5 rounded-full text-[11px] font-mono border ${$?"bg-sage/15 text-sage-dark border-sage/30":"bg-bg-hi text-fg-faint border-line"}`,children:o},o)})})}),e.jsx(O,{label:"color",children:e.jsx("div",{className:"flex gap-1.5",children:ze.map(o=>e.jsx("button",{title:o||"none",onClick:()=>s({color:o}),className:"w-5 h-5 rounded",style:{background:o?de[o]:"transparent",border:t.color===o?"2px solid var(--accent, #b85c34)":"1px solid var(--line, #555)"}},o||"none"))})}),e.jsx(O,{label:"tags",hint:"Session mission tags this persona is associated with — shown as the default agent on the Tags tab.",children:e.jsx("div",{className:"flex flex-wrap gap-1.5",children:R.map(o=>{const $=t.tags.includes(o.tag),k=Y(o.tag);return e.jsxs("button",{onClick:()=>s({tags:$?t.tags.filter(P=>P!==o.tag):[...t.tags,o.tag]}),className:`px-2 py-0.5 rounded-full text-[11px] font-mono border ${$?`${k.bg} ${k.text} ${k.border?"border-current/30":"border-transparent"}`:"bg-bg-hi text-fg-faint border-line"}`,children:["#",o.tag]},o.tag)})})}),e.jsx(O,{label:"definition",hint:"The system prompt this persona runs under.",children:e.jsx("textarea",{rows:9,value:t.body,onChange:o=>s({body:o.target.value}),className:"w-full bg-bg border border-line rounded px-2 py-1.5 text-xs text-fg font-mono leading-relaxed resize-y"})}),e.jsx(O,{label:"project overrides",hint:"Open projects that shadow this definition with a local copy.",children:a&&(a.overrideDetails??[]).length>0?e.jsx("div",{className:"flex flex-wrap gap-1.5",children:(a.overrideDetails??[]).map(o=>e.jsxs("span",{className:"inline-flex items-center gap-1.5 bg-bg-elev border border-line rounded px-2 py-0.5 text-[11px] font-mono text-fg-dim",children:[o.project,e.jsx("button",{onClick:()=>N(o.cwd,o.project),title:"Drop the local copy",className:"text-fg-faint hover:text-fg",children:"×"})]},o.cwd))}):e.jsx("div",{className:"text-xs text-fg-faint italic",children:d?"save first to see project overrides.":"no open project overlays this agent — the global definition applies everywhere."})})]}),e.jsx("div",{className:"px-4 py-2.5 border-t border-line flex items-center gap-2 flex-wrap",children:r?e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"text-xs text-fg-dim",children:["Delete ",e.jsx("strong",{className:"font-mono",children:t.name})," and its file?"]}),e.jsx(M,{variant:"danger",onClick:g,disabled:f,children:"Delete"}),e.jsx(M,{onClick:()=>u(!1),children:"Keep"})]}):e.jsxs(e.Fragment,{children:[e.jsx(M,{onClick:y,disabled:f,children:"Duplicate"}),!d&&e.jsx(M,{variant:"danger",onClick:()=>u(!0),disabled:f,children:"Delete"}),e.jsx("div",{className:"flex-1"}),v&&e.jsx("span",{className:"text-[11px] text-fg-faint",children:"unsaved changes"}),e.jsx(M,{onClick:m,disabled:!v||f,children:"Revert"}),e.jsx(M,{variant:"primary",onClick:h,disabled:!v||f,children:f?"Saving…":d?"Create":"Save"})]})})]})}function O({label:t,hint:s,children:a}){return e.jsxs("div",{children:[e.jsx("div",{className:"text-[10.5px] font-semibold uppercase tracking-wide text-fg-faint mb-1.5 font-mono",children:t}),a,s&&e.jsx("div",{className:"text-[11px] text-fg-faint mt-1 leading-snug",children:s})]})}const z="latest",Z="Blocked by the availableModels allowlist in your Claude settings";function fe({value:t,onChange:s,label:a="default model",hint:i,testIdPrefix:d="",inheritLabel:f}){var A,V;const{catalog:r,loading:u,degraded:y,refresh:m}=ae(null),h=r?["inherit",...r.aliases]:[...Ee],g=(r==null?void 0:r.availableModels)??null,N=l=>!!g&&l!=="inherit"&&!g.includes(l),D=(l,x)=>!!g&&!g.includes(l)&&!(x&&g.includes(x)),j=t||"inherit",S=((A=/\[[^\]]*\]$/.exec(j))==null?void 0:A[0])??"",E=h.includes(j),w=!E&&r&&B(j)&&h.includes(B(j)+S)?B(j)+S:null,c=E?j:w??j,v=B(c),o=((V=/\[[^\]]*\]$/.exec(c))==null?void 0:V[0])??"",$=!!r&&j!=="inherit"&&!!v&&h.includes(c),k=$?r.models.filter(l=>B(l)===v).map(l=>l+o):[],P=E?z:j,T={};if(r)for(const l of h)N(l)&&(T[l]=Z);const I={};for(const l of k)D(l,v)&&(I[l]=Z);return e.jsxs(O,{label:a,hint:i??"This persona's default model for its Epics — sets the --model an Epic launches with (Terminal + Chat both honor it). 'inherit' falls back to each view's own default, not this Settings page. Cheap models for read-only personas; opus for judgement calls.",children:[e.jsx("div",{"data-testid":`${d}model-row`,children:e.jsx(U,{options:h,value:c,onChange:s,mono:!0,blocked:T,labels:f?{inherit:f}:void 0})}),$&&e.jsxs("div",{className:"mt-2","data-testid":`${d}model-version-row`,children:[e.jsx("div",{className:"text-[10.5px] text-fg-faint mb-1 font-mono",children:"version"}),e.jsx(U,{options:[z,...k],value:P,onChange:l=>s(l===z?c:l),mono:!0,blocked:I})]}),e.jsxs("div",{className:"text-[11px] text-fg-faint mt-1 leading-snug flex items-center gap-2",children:[e.jsx("span",{children:r?`Models are live-read from the installed claude CLI${y?" (cached — CLI probe unavailable)":""}. "latest" keeps the floating alias.`:u?"Loading model catalog…":"catalog unavailable — showing the standard list."}),e.jsx("button",{"data-testid":`${d}model-catalog-refresh`,onClick:()=>{m()},disabled:u,className:"underline text-fg-dim disabled:opacity-40",children:"refresh"})]})]})}function me({value:t,model:s,onChange:a,label:i="effort",testIdPrefix:d="",inheritLabel:f}){const{catalog:r}=ae(null),u=r&&r.effortLevels.length?["inherit",...r.effortLevels]:[...Oe],y=(r==null?void 0:r.settingsEffortLevels)??[],m=r?u.filter(N=>N!=="inherit"&&!y.includes(N)):[],h=t||"inherit",g=h!=="inherit"&&Ke(s)===!1;return e.jsxs(O,{label:i,hint:r?`Effort levels are live-read from the installed claude CLI (what /effort accepts). ${m.length?`${m.join(", ")} ${m.length>1?"are":"is"} session-only — settings.json accepts ${y.join(", ")}. `:""}'inherit' writes no effort: line.`:"catalog unavailable — showing the standard list. 'inherit' writes no effort: line.",children:[e.jsx("div",{"data-testid":`${d}effort-row`,children:e.jsx(U,{options:u,value:h,onChange:a,mono:!0,labels:f?{inherit:f}:void 0})}),m.length>0&&e.jsx("div",{className:"text-[11px] text-fg-faint mt-1 font-mono","data-testid":`${d}effort-session-only`,children:m.map(N=>`${N} (session-only)`).join(" · ")}),g&&e.jsx("div",{className:"text-[11px] text-amber-400 mt-1 leading-snug","data-testid":`${d}effort-unsupported-note`,children:"The selected model does not support effort — the CLI will ignore this setting."})]})}function qe({saved:t,projects:s,selected:a,onSelect:i,busy:d,onSave:f}){var S,E,w;const r=J(),u=new Map;for(const c of s)u.set(c.name,(u.get(c.name)??0)+1);const y=c=>{var k;const v=(u.get(c.name)??0)>1?Pe(c.cwd,r):c.name,o=(k=t.overrideDetails)==null?void 0:k.find(P=>P.cwd===c.cwd);if(!o)return v;const $=ce(o);return`${v} — ${$.length?`overrides ${$.join(", ")}`:"overlay"}`},m=a?(S=t.overrideDetails)==null?void 0:S.find(c=>c.cwd===a.cwd):void 0,h=!!(m!=null&&m.bodyOverridden),g=((E=m==null?void 0:m.values)==null?void 0:E.model)??"inherit",N=((w=m==null?void 0:m.values)==null?void 0:w.effort)??"inherit",D=t.model??"inherit",j=t.effort??"inherit";return e.jsxs("div",{"data-testid":"project-override-block",className:a?"border border-accent/40 rounded p-3 space-y-3 bg-accent/5":"border border-dashed border-line rounded p-3 space-y-3",children:[e.jsxs("label",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:`text-[10.5px] font-semibold uppercase tracking-wide font-mono ${a?"text-accent":"text-fg-faint"}`,children:"project override"}),e.jsxs("select",{"data-testid":"override-project-select",value:(a==null?void 0:a.cwd)??"",onChange:c=>i(c.target.value||null),disabled:d||s.length===0,className:"rounded-md border border-line bg-bg px-2 py-1.5 font-mono text-[12.5px] text-fg disabled:opacity-60",children:[e.jsx("option",{value:"",children:"Choose a project…"}),s.map(c=>e.jsx("option",{value:c.cwd,children:y(c)},c.cwd))]})]}),s.length===0?e.jsx("div",{"data-testid":"project-override-none",className:"text-[11px] text-fg-faint leading-snug",children:"No open project tabs — open a project tab to override this persona's model or effort for it."}):a?e.jsxs("div",{"data-testid":"project-override",className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsxs(W,{tone:"accent",children:[a.name," only"]}),e.jsx("span",{className:"ml-auto min-w-0",children:e.jsx(re,{path:`${a.cwd}/.claude/agents/${t.name}.md`})})]}),e.jsxs("div",{className:"text-[11px] text-fg-faint leading-snug",children:["Changes what the SCHEDULER (and new Epics) spawn for ",e.jsx("strong",{children:a.name})," only — a frontmatter-only overlay with just the keys you set; the persona's body stays the global one. The global model/effort rows edit the machine-wide persona and are never touched here."]}),h&&e.jsxs("div",{"data-testid":"project-override-fullbody",className:"text-[11px] text-amber-400 leading-snug",children:[a.name,' already has a FULL-BODY override of this persona (its own definition text). It is shown as-is and not converted to a frontmatter-only overlay — edit that file directly, or drop it with × under "project overrides" below.']}),e.jsxs("fieldset",{disabled:d||h,className:"space-y-3 border-0 p-0 m-0 min-w-0",children:[e.jsx(fe,{value:g,onChange:c=>{h||f({model:c,effort:N})},label:"project model",hint:"'use global' writes no model: line in the overlay.",testIdPrefix:"override-",inheritLabel:"use global"}),e.jsx(me,{value:N,model:g!=="inherit"?g:D,onChange:c=>{h||f({model:g,effort:c})},label:"project effort",testIdPrefix:"override-",inheritLabel:"use global"})]}),e.jsx("div",{"data-testid":"override-provenance",className:"text-[11px] font-mono text-fg-dim space-y-0.5",children:[["model",D,g],["effort",j,N]].map(([c,v,o])=>e.jsxs("div",{"data-testid":`override-provenance-${c}`,children:[c,": ",o!=="inherit"?e.jsxs(e.Fragment,{children:[v," ",e.jsx("span",{className:"text-fg-faint",children:"(global)"})," → ",e.jsx("span",{className:"text-accent",children:o})," ",e.jsx("span",{className:"text-fg-faint",children:"(this project)"})]}):e.jsxs(e.Fragment,{children:[v," ",e.jsx("span",{className:"text-fg-faint",children:"(global — not overridden)"})]})]},c))})]}):e.jsx("div",{"data-testid":"project-override-unselected",className:"text-[11px] text-fg-faint leading-snug",children:"Pick an open project to see or set this persona's model and effort for that project only. A project that already overrides this persona says what it overrides."})]})}export{ot as AgentLibrary};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{ay as o,a5 as b}from"./index-iQ6pdyuS.js";function u({children:n,onClick:s,disabled:a,variant:e="default",tooltip:t,type:d="button",className:c}){const i=`px-2 py-0.5 text-xs rounded border transition-colors disabled:opacity-40 disabled:cursor-not-allowed ${e==="primary"?"text-accent border-accent/50 hover:bg-bg-hi":e==="danger"?"text-red-400 hover:text-red-300 border-line hover:border-red-400/50":"text-fg-dim border-line hover:text-fg hover:bg-bg-hi"} ${c??""}`,r=o.jsx("button",{type:d,title:t,onClick:s,disabled:a,className:i,children:n});return t?o.jsx(b,{content:t,align:"bottom-center",children:r}):r}export{u as B};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{bg as $,av as y,aw as z,b3 as B,aO as i,ae as O,ay as e,g as V,a9 as b,j as h,t as j,s as w,k as q,ai as A}from"./index-iQ6pdyuS.js";function G({path:s,value:l,onChange:v,onSave:c,readOnly:r,defaultMode:N,headerRight:k,hideStatusBar:M}){const u=$(),n=y(s),a=z(s),R=B(s),[E,C]=i.useState(()=>r&&a?"preview":N??O(s)),[x,P]=i.useState(!0),[S,D]=i.useState(null),m=i.useRef(null),d=i.useRef(null),T=i.useCallback(t=>{m.current=t},[]),p=i.useCallback(()=>m.current,[]),g=r?a?["preview","edit"]:[]:R?["edit","preview","split"]:a?["edit","preview"]:[],o=a?E:"edit",f=e.jsx(V,{path:s,name:b(s),value:l,onChange:v,onSave:()=>c==null?void 0:c(),onReady:T,onCursor:D,readOnly:r});return e.jsxs("div",{className:"flex flex-col h-full min-h-0","data-testid":"document-editor-pane",children:[e.jsxs("div",{className:"flex items-center gap-1 px-2 h-7 shrink-0 border-b border-line bg-bg-elev",children:[e.jsx("span",{className:"text-[11px] font-medium text-fg truncate",children:b(s)}),r&&e.jsx("span",{className:"ml-1 px-1.5 py-0.5 rounded text-[9px] uppercase tracking-wide text-fg-faint border border-line",children:"read-only"}),e.jsx("div",{className:"flex-1"}),k,n&&(o==="preview"||o==="split")&&e.jsx("button",{onClick:()=>P(t=>!t),"data-testid":"document-outline-toggle",className:`px-2 py-0.5 text-[10px] border border-line rounded ${x?"bg-bg-hi text-fg":"text-fg-faint hover:text-fg"}`,title:"Toggle document outline",children:"Outline"}),g.length>0&&e.jsx("div",{className:"flex items-center ml-1 rounded border border-line overflow-clip","data-testid":"document-mode-toggle",children:g.map(t=>e.jsx("button",{onClick:()=>C(t),className:`px-2 py-0.5 text-[10px] capitalize transition-colors ${o===t?"bg-bg-hi text-fg":"text-fg-faint hover:text-fg"}`,children:t},t))})]}),e.jsx("div",{className:"flex-1 min-h-0",children:o==="split"&&n?e.jsxs("div",{className:"flex h-full overflow-clip",children:[x&&e.jsx(h,{text:l,scrollRef:d}),e.jsxs("div",{className:"flex-1 min-w-0 flex flex-col border-r border-line",children:[!r&&e.jsx(j,{getEditor:p}),e.jsx("div",{className:"flex-1 min-h-0",children:f})]}),e.jsx("div",{className:"flex-1 min-w-0",children:e.jsx(w,{ref:d,text:l,flush:!0,wideMeasure:u.wideMeasure})})]}):o==="preview"&&n?e.jsxs("div",{className:"flex h-full overflow-clip",children:[x&&e.jsx(h,{text:l,scrollRef:d}),e.jsx("div",{className:"flex-1 min-w-0",children:e.jsx(w,{ref:d,text:l,wideMeasure:u.wideMeasure})})]}):n?e.jsxs("div",{className:"flex flex-col h-full",children:[!r&&e.jsx(j,{getEditor:p}),e.jsx("div",{className:"flex-1 min-h-0",children:f})]}):f}),!M&&e.jsx(q,{text:l,cursor:S,language:A(s)||void 0})]})}export{G as D};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./SkillReferenceGraph-DwV0Ueyc.js","./index-iQ6pdyuS.js","./monaco-editor-BsIlgG7c.js","./monaco-editor-Cu5D__1H.css","./index-62tyjEQB.css"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{aO as a,ay as t,bh as re,bc as Y,az as fe,ax as xe,m as S,a7 as he,aW as ge,ac as be,b7 as te,bj as ie,bu as ke,c as je,bm as ve,H as ye}from"./index-iQ6pdyuS.js";import{s as ue}from"./SourceChip-DfJ5_5rV.js";import{d as Ne,M as we,s as Se,i as Ce,f as $e,E as Ee,c as Pe,e as Me,g as Ae,l as Oe,b as Re,r as ce,S as Le,a as Te}from"./Skills-DVYHA9gV.js";import{a as pe}from"./ProvenanceBadge-CJvnQReI.js";import{_ as De}from"./monaco-editor-BsIlgG7c.js";import{L as _e}from"./ListDetail-ByULG209.js";import{e as Ie,M as Fe,d as Ue}from"./Library-C_ibFiOx.js";import"./Panel-BuInRmA0.js";import"./Toggle-DaxeFDFp.js";import"./Button-Cmfkgjfa.js";const Be="flex items-center gap-[9px] px-5 whitespace-nowrap cursor-default h-[41px] bg-bg-elev border border-accent border-t-2 border-b-bg-elev rounded-t-[9px] text-[14.5px] font-semibold text-fg",He="flex items-center gap-[9px] px-5 whitespace-nowrap cursor-pointer h-[38px] border border-b-0 border-transparent rounded-t-[9px] text-[14.5px] font-medium text-fg-dim hover:bg-bg-elev hover:border-line hover:text-fg",Ve="font-mono text-[11px] font-semibold text-accent",We="font-mono text-[11px] font-medium text-fg-faint";function qe({options:e,active:s,onChange:n,ariaLabel:l,trailing:o}){const c=a.useRef([]),u=Math.max(0,e.findIndex(i=>i.key===s)),f=i=>{i!==s&&n(i)},r=(i,g)=>{var j;if(i.key!=="ArrowRight"&&i.key!=="ArrowLeft")return;i.preventDefault();const p=(g+(i.key==="ArrowRight"?1:-1)+e.length)%e.length;(j=c.current[p])==null||j.focus(),f(e[p].key)};return t.jsxs("div",{className:"flex items-end gap-0.5",children:[t.jsx("div",{role:"tablist","aria-label":l,className:"flex flex-none items-end gap-0.5",children:e.map(({key:i,label:g,count:p},j)=>{const m=i===s;return t.jsxs("button",{ref:y=>{c.current[j]=y},type:"button",role:"tab","aria-selected":m,tabIndex:j===u?0:-1,"data-testid":`folder-tab-${i}`,onClick:()=>f(i),onKeyDown:y=>r(y,j),className:m?Be:He,children:[g,typeof p=="number"&&t.jsx("span",{"data-testid":`folder-tab-count-${i}`,className:m?Ve:We,children:p})]},i)})}),o!=null&&t.jsx("div",{className:"ml-auto self-center min-w-0",children:o})]})}const Je={skills:null,mcp:null,plugins:null},Ke={fileId:"claudeJson",scope:"user"};function ze(e){return{skillsDir:`${e}/.claude/skills`,commandsDir:`${e}/.claude/commands`,claudeJson:`${e}/.claude.json`,pluginsManifest:`${e}/.claude/plugins/installed_plugins.json`}}async function Ge(e,s){const[n,l]=await Promise.all([fe(e),window.api.config.listDir(s,{filesOnly:!0})]),o=n.errors[0];if(o)throw new Error(`${o.path}: ${o.error}`);if(!l.ok)throw new Error(`${s}: ${l.error??"failed to list directory"}`);return n.entries.length+l.entries.filter(c=>c.name.endsWith(".md")).length}async function Ye(){const{data:e}=await window.api.claudeConfig.read(Ke),s=e==null?void 0:e.mcpServers;return s&&typeof s=="object"&&!Array.isArray(s)?Object.keys(s).length:0}async function Xe(){return(await window.api.plugins.list()).length}function Ze(){const e=re(),[s,n]=a.useState(Je),l=a.useRef({skills:0,mcp:0,plugins:0}),o=a.useCallback((i,g)=>{const p=l.current,j=++p[i],m=y=>{p[i]===j&&n(k=>k[i]===y?k:{...k,[i]:y})};g().then(m,()=>m(null))},[]),c=a.useMemo(()=>e?ze(e):null,[e]),u=a.useCallback(()=>{c&&o("skills",()=>Ge(c.skillsDir,c.commandsDir))},[c,o]),f=a.useCallback(()=>o("mcp",Ye),[o]),r=a.useCallback(()=>o("plugins",Xe),[o]);return a.useEffect(()=>{const i=l.current;return u(),()=>{i.skills++}},[u]),a.useEffect(()=>{const i=l.current;return f(),r(),()=>{i.mcp++,i.plugins++}},[f,r]),Y(c?[c.skillsDir,c.commandsDir]:[],u),Y(c?[c.claudeJson]:[],f),Y(c?[c.pluginsManifest]:[],r),s}const Q=6e4,ee=60*Q,de=24*ee;function Qe(e,s=Date.now()){if(e===null)return"created on first save";if(e==="present"||!Number.isFinite(e))return null;const n=Math.max(0,s-e);return n<Q?"just now":n<ee?`${Math.floor(n/Q)}m ago`:n<de?`${Math.floor(n/ee)}h ${Math.floor(n%ee/Q)}m ago`:`${Math.floor(n/de)}d ago`}async function et(e){try{if(e.kind==="dir")return await window.api.config.exists(e.path)?"present":null;const s=await window.api.config.readText(e.path,{maxBytes:1});return s.exists?Number.isFinite(s.mtimeMs)?s.mtimeMs:void 0:s.error?void 0:null}catch{return}}function tt(e,s){const n=Object.keys(e);return n.length!==Object.keys(s).length?!1:n.every(l=>Object.prototype.hasOwnProperty.call(s,l)&&Object.is(e[l],s[l]))}function nt(e){const s=JSON.stringify(e.map(c=>[c.path,c.kind])),[n,l]=a.useState({}),o=a.useRef(0);return a.useEffect(()=>{const c=JSON.parse(s).map(([r,i])=>({path:r,kind:i})),u=()=>{const r=++o.current;Promise.all(c.map(et)).then(i=>{if(r!==o.current)return;const g={};c.forEach((p,j)=>{const m=i[j];m!==void 0&&(g[p.path]=m)}),l(p=>tt(p,g)?p:g)})};u();const f=window.api.config.onChanged(r=>{c.some(i=>r.path===i.path||i.kind==="dir"&&xe(r.path,i.path))&&u()});return()=>{o.current++,f()}},[s]),n}const st=a.lazy(()=>De(()=>import("./SkillReferenceGraph-DwV0Ueyc.js"),__vite__mapDeps([0,1,2,3,4]),import.meta.url).then(e=>({default:e.SkillReferenceGraph})));function lt({pluginName:e,skills:s,onBack:n,initialSelectedId:l}){var g;const[o,c]=a.useState(l??((g=s[0])==null?void 0:g.id)??null),u=o?s.find(p=>p.id===o)??null:null,f=a.useMemo(()=>Ne(s),[s]),[r,i]=a.useState("list");return t.jsxs("div",{className:"flex flex-col h-full min-h-0 overflow-hidden",children:[t.jsxs("div",{className:"shrink-0 h-11 flex items-baseline gap-3.5 px-3 border-b border-line bg-bg",children:[t.jsxs("button",{type:"button",onClick:n,className:"font-mono text-accent hover:underline shrink-0 text-xs",children:["← ",e]}),t.jsx("span",{className:"font-serif text-[22px] text-fg shrink-0 truncate max-w-[16rem]",children:(u==null?void 0:u.name)??(u==null?void 0:u.id)??"skill"}),t.jsx("span",{className:"flex-1"}),t.jsx("div",{className:"flex items-center gap-1.5 shrink-0",children:t.jsxs("div",{className:"flex rounded border border-line overflow-hidden",children:[t.jsx("button",{onClick:()=>i("list"),className:`px-2 py-0.5 text-xs ${r==="list"?"bg-bg-hi text-fg":"text-fg-dim hover:text-fg hover:bg-bg-hi"}`,children:"list"}),t.jsx("button",{onClick:()=>i("graph"),className:`px-2 py-0.5 text-xs ${r==="graph"?"bg-bg-hi text-fg":"text-fg-dim hover:text-fg hover:bg-bg-hi"}`,children:"graph"})]})})]}),t.jsxs("div",{className:"shrink-0 h-[26px] flex items-center gap-[18px] px-3 bg-bg-elev border-b border-line text-[9px] font-mono uppercase tracking-wide overflow-hidden",children:[u!=null&&u.description?t.jsx("span",{className:"text-fg-dim truncate normal-case",children:u.description}):null,t.jsxs("span",{className:"ml-auto text-fg-faint truncate normal-case",children:[s.length," ",s.length===1?"skill":"skills"," · ",f.length," ",f.length===1?"reference":"references"]})]}),t.jsx("div",{className:"flex-1 min-h-0 overflow-hidden",children:s.length===0?t.jsx(S,{title:"no skills in this plugin"}):r==="graph"?t.jsx(a.Suspense,{fallback:t.jsx("div",{className:"p-6 text-xs text-fg-faint",children:"Loading graph…"}),children:t.jsx(st,{skills:s,edges:f,selectedId:o,onSelect:c})}):t.jsx(_e,{sidebar:t.jsx("div",{className:"py-1",children:s.map(p=>t.jsxs("button",{onClick:()=>c(p.id),className:`w-full px-3 py-1 text-xs text-left ${o===p.id?"bg-bg-hi text-fg":"text-fg-dim hover:text-fg hover:bg-bg-hi"}`,children:[t.jsx("div",{className:"truncate",children:p.name??p.id}),p.description?t.jsx("div",{className:"truncate text-fg-faint",children:p.description}):null]},p.id))}),detail:u?t.jsx("div",{className:"h-full min-h-0",children:t.jsx(we,{path:u.path,value:u.body,onChange:()=>{},readOnly:!0})}):t.jsx(S,{title:"select a skill"})})})]})}const me=e=>{var s,n;return{type:"plugin",name:e.name,repository:(s=e.manifest)==null?void 0:s.repository,homepage:(n=e.manifest)==null?void 0:n.homepage}},G=(e,s,n)=>e===1?s:n;function at(e,s){const n=Se(e),l=[];return n.skills>0&&l.push({kind:"skills",count:n.skills,label:G(n.skills,"skill","skills"),arrow:"›",title:"Show in the Skills tab",onClick:()=>s("skills")}),n.commands>0&&l.push({kind:"commands",count:n.commands,label:G(n.commands,"command","commands"),arrow:"›",title:"Show in the Skills tab",onClick:()=>s("skills")}),n.mcpServers>0&&l.push({kind:"mcp",count:n.mcpServers===1?null:n.mcpServers,label:G(n.mcpServers,"MCP server","MCP servers"),arrow:"›",title:"Show in the MCP Servers tab",onClick:()=>s("mcp")}),n.agents>0&&l.push({kind:"agents",count:n.agents,label:G(n.agents,"agent","agents"),arrow:"↗",title:"Open the Agents page",onClick:()=>ie.getState().openPanel("agent-library")}),n.hooks>0&&l.push({kind:"hooks",count:n.hooks,label:G(n.hooks,"hook","hooks"),arrow:"↗",title:"Open Settings ▸ Hooks",onClick:()=>ie.getState().openPanel("settings","hooks")}),l}const it=e=>`${e.charAt(0).toUpperCase()}${e.slice(1)} scope`;function rt({row:e,home:s,busy:n,onToggle:l,onOpen:o,onUninstall:c,onJump:u}){var p,j;const f=e.enabled===!0,r=(p=e.manifest)==null?void 0:p.version,i=(j=e.manifest)==null?void 0:j.description,g=at(e,u);return t.jsxs("div",{"data-testid":"plugin-card",className:"grid grid-cols-[36px_minmax(0,1fr)_auto] gap-x-4 px-[18px] py-4 bg-bg-hi border border-line rounded-[10px]",children:[t.jsx("button",{type:"button",role:"switch","aria-checked":f,"aria-label":`${f?"Disable":"Enable"} ${e.name}`,"data-testid":"plugin-enabled-switch",disabled:!e.key||n,onClick:()=>l(e),className:`relative mt-px w-9 h-5 rounded-full transition-colors disabled:opacity-50 disabled:cursor-not-allowed ${f?"bg-accent":"bg-rule"}`,children:t.jsx("span",{"aria-hidden":"true",className:`absolute top-0.5 w-4 h-4 rounded-full bg-bg-hi shadow transition-[left] ${f?"left-[18px]":"left-0.5"}`})}),t.jsxs("div",{className:"min-w-0 flex flex-col gap-2",children:[t.jsxs("div",{className:"flex flex-wrap items-baseline gap-x-2.5 gap-y-1.5",children:[t.jsx("button",{type:"button","data-testid":"plugin-card-name",onClick:()=>o(e),title:`Open ${e.name}`,className:"text-left text-[15px] font-semibold text-fg hover:text-accent hover:underline",children:e.name}),r?t.jsxs("span",{className:"font-mono text-[11.5px] text-fg-faint",children:["v",r]}):null,t.jsx(pe,{interactive:!1,input:me(e)}),e.scope?t.jsx("span",{"data-testid":"plugin-scope",className:"text-xs text-fg-faint",children:it(e.scope)}):null]}),i?t.jsx("p",{"data-testid":"plugin-card-description",title:i,className:"text-[13px] text-fg-dim",children:i}):null,g.length>0||e.error?t.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[g.map(m=>t.jsxs("button",{type:"button","data-testid":`plugin-chip-${m.kind}`,title:m.title,onClick:m.onClick,className:"inline-flex items-center gap-[5px] h-6 px-2.5 bg-bg border border-line rounded-full text-xs text-fg-dim hover:border-accent hover:text-fg",children:[m.count!==null?t.jsx("b",{className:"font-mono font-semibold text-fg",children:m.count}):null,m.count!==null?" ":null,m.label," ",t.jsx("span",{"aria-hidden":"true",className:"text-fg-faint/60",children:m.arrow})]},m.kind)),e.error?t.jsx("span",{title:e.error,className:"inline-flex items-center h-6 px-2.5 border border-delta-bad/30 rounded-full text-xs text-delta-bad",children:"inspection failed"}):null]}):null,t.jsx("span",{"data-testid":"plugin-card-path",title:e.path,className:"font-mono text-[11px] text-fg-faint/80 whitespace-nowrap overflow-hidden text-ellipsis",children:ue(e.path,s)})]}),t.jsx(ot,{row:e,busy:n,onUninstall:c})]})}function ot({row:e,busy:s,onUninstall:n}){const[l,o]=a.useState(!1),[c,u]=a.useState(!1),f=a.useRef(null),r=a.useId(),i=a.useCallback(()=>{o(!1),u(!1)},[]);a.useEffect(()=>{if(!l)return;const y=P=>{var E;(E=f.current)!=null&&E.contains(P.target)||i()},k=P=>{P.key==="Escape"&&i()};return window.addEventListener("mousedown",y),window.addEventListener("keydown",k),()=>{window.removeEventListener("mousedown",y),window.removeEventListener("keydown",k)}},[l,i]);const g=()=>{i(),ge(e.path)},p=async()=>{i(),await be(e.path)||te.error(`Could not copy ${e.path} to the clipboard`)},j=()=>{i(),n(e)},m="px-2.5 py-[7px] rounded-[5px] text-left whitespace-nowrap hover:bg-bg-elev";return t.jsxs("div",{ref:f,className:"relative self-start",children:[t.jsx("button",{type:"button","data-testid":"plugin-menu","aria-label":`Actions for ${e.name}`,"aria-haspopup":"menu","aria-expanded":l,"aria-controls":l?r:void 0,onClick:()=>l?i():o(!0),className:"w-[30px] h-7 inline-flex items-center justify-center bg-bg border border-line rounded-md text-fg-dim hover:border-rule",children:t.jsxs("svg",{"aria-hidden":"true",width:"14",height:"14",viewBox:"0 0 24 24",fill:"currentColor",children:[t.jsx("circle",{cx:"5",cy:"12",r:"1.8"}),t.jsx("circle",{cx:"12",cy:"12",r:"1.8"}),t.jsx("circle",{cx:"19",cy:"12",r:"1.8"})]})}),l&&t.jsx("div",{id:r,role:"menu","aria-label":`Actions for ${e.name}`,className:`absolute ${he.dialog} right-0 top-[34px] w-[210px] p-[5px] flex flex-col bg-bg-hi border border-line rounded-lg shadow-lg text-[12.5px] text-fg`,children:c?t.jsxs("div",{className:"flex flex-col gap-2 px-2.5 py-[7px]",children:[t.jsxs("span",{className:"font-medium",children:["Uninstall ",e.name,"?"]}),t.jsxs("div",{className:"flex items-center justify-end gap-1.5",children:[t.jsx("button",{type:"button",role:"menuitem","data-testid":"plugin-uninstall",disabled:s,onClick:j,className:"h-6 px-2.5 rounded-[5px] bg-delta-bad text-bg-hi font-medium hover:bg-delta-bad/90 disabled:opacity-40",children:"Confirm"}),t.jsx("button",{type:"button",role:"menuitem",onClick:()=>u(!1),className:"h-6 px-2.5 rounded-[5px] border border-line text-fg-dim hover:bg-bg-elev",children:"Cancel"})]})]}):t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",role:"menuitem",onClick:g,className:m,children:"Reveal in File Explorer"}),t.jsx("button",{type:"button",role:"menuitem",onClick:()=>void p(),className:m,children:"Copy path"}),t.jsx("div",{role:"separator",className:"h-px mx-1.5 my-1 bg-line"}),t.jsxs("button",{type:"button",role:"menuitem",disabled:!e.marketplace||s,title:e.marketplace?void 0:"No marketplace is recorded for this install",onClick:()=>u(!0),className:`${m} font-medium text-delta-bad hover:bg-delta-bad/10 disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-transparent`,children:["Uninstall ",e.name]})]})})]})}const ct="Plugin contents also appear, read-only, in Skills and MCP Servers — tagged with the plugin that added them.",dt=e=>ie.getState().openPanel("extensions",e);function ut(e,s){var n,l;return[e.name,(n=e.manifest)==null?void 0:n.name,(l=e.manifest)==null?void 0:l.description].some(o=>typeof o=="string"&&o.toLowerCase().includes(s))}function pt({onAdd:e,onJump:s}){const n=re(),[l,o]=a.useState([]),[c,u]=a.useState(!0),[f,r]=a.useState(null),[i,g]=a.useState(null),[p,j]=a.useState(""),[m,y]=a.useState(null),[k,P]=a.useState(new Set),E=ke(d=>d.show),[U,D]=a.useState(null);a.useEffect(()=>{var x,C;let d=!1;return(C=(x=window.api.app).seedStatus)==null||C.call(x).then(b=>{d||y(b)}).catch(()=>{}),()=>{d=!0}},[]);const B=a.useRef(0),M=a.useRef(!1),A=a.useCallback(async()=>{var N,q;const d=++B.current;if(!n)return;M.current||u(!0);const x=`${n}/.claude/plugins/installed_plugins.json`;let C=[],b=null;try{const v=await window.api.config.readJson(x);if(v.exists&&v.parseError)b=`could not parse installed_plugins.json${v.error?`: ${v.error}`:""}`;else if(v.exists&&v.data&&typeof v.data=="object"){const J=v.data,K=[];for(const[$,w]of Object.entries(J.plugins??{})){if(!Array.isArray(w))continue;const[L,T]=$.split("@");for(const h of w)h!=null&&h.installPath&&K.push({name:L,marketplace:T,entry:h})}let z=new Map;try{const $=await((q=(N=window.api.plugins)==null?void 0:N.list)==null?void 0:q.call(N))??[];z=new Map($.map(w=>[w.key,w.enabled]))}catch{}C=await jt(K,kt,async({name:$,marketplace:w,entry:L})=>{var oe;const T={name:$,path:L.installPath,isDirectory:!0,isFile:!1,mtimeMs:0,size:0};let h;try{h=await Ce(T)}catch(le){h=$e(T,le instanceof Error?le.message:String(le))}return(oe=h.manifest)!=null&&oe.version||(h.manifest={...h.manifest??{},version:L.version}),h.marketplace=w,h.scope=L.scope,h.key=w?`${$}@${w}`:$,h.enabled=z.get(h.key)===!0,h})}}catch(v){b=`could not read installed_plugins.json: ${v instanceof Error?v.message:String(v)}`}B.current===d&&(r(b),b?te.error(`Plugins: ${b}`):(C.sort((v,J)=>v.name.localeCompare(J.name)),M.current=C.length>0,o(C)),u(!1))},[n]);a.useEffect(()=>{A()},[A]),a.useEffect(()=>()=>{B.current+=1},[]),Y(n?[`${n}/.claude/plugins/installed_plugins.json`]:[],A);const _=async d=>{if(d.key){D(d.key);try{const x=await window.api.plugins.setEnabled({key:d.key,enabled:!d.enabled});x.ok||E("error",`Could not ${d.enabled?"disable":"enable"} ${d.name}: ${x.error??"unknown error"}`)}catch(x){E("error",`Could not update ${d.name}: ${x instanceof Error?x.message:String(x)}`)}finally{D(null),await A()}}},O=async d=>{if(d.marketplace){D(d.key??d.name);try{const x=await window.api.plugins.uninstall({slug:d.name,marketplaceName:d.marketplace});x.ok||E("error",`Uninstall ${d.name} failed: ${x.error??`exit ${x.exitCode}`}`)}catch(x){E("error",`Uninstall ${d.name} failed: ${x instanceof Error?x.message:String(x)}`)}finally{D(null),await A()}}},I=a.useMemo(()=>m?Object.keys(m).filter(d=>(m[d].status==="exhausted"||m[d].status==="failed")&&!k.has(d)):[],[m,k]),H=I.length>0?t.jsx(ft,{seeders:I,seedStatus:m,onDismiss:d=>P(x=>new Set(x).add(d)),onOpenLibrary:()=>e==null?void 0:e()}):null,F=i?l.find(d=>d.path===i)??null:null,ne=a.useMemo(()=>l.filter(d=>d.enabled===!0).length,[l]),V=p.trim().toLowerCase(),W=a.useMemo(()=>V?l.filter(d=>ut(d,V)):l,[l,V]),se=a.useMemo(()=>({label:"+ Add plugin",testId:"plugins-add",items:[{label:"Browse catalog…",testId:"plugins-add-catalog",onSelect:()=>e==null?void 0:e()}]}),[e]),X=a.useCallback(d=>g(d.path),[]),Z=s??dt;return F?t.jsx(gt,{row:F,home:n,onBack:()=>g(null)},F.path):t.jsxs("div",{className:"flex flex-col h-full min-h-0",children:[t.jsx(Ee,{filter:p,onFilterChange:j,placeholder:"Filter plugins",summary:`${l.length} installed · ${ne} enabled`,primary:se}),H,f?t.jsxs("div",{role:"alert",className:"shrink-0 px-3 py-2 border-b border-line bg-red-950/20 text-xs text-red-300",children:[f,l.length>0?" — showing the last known list":null]}):null,t.jsx("div",{className:"flex-1 min-h-0 overflow-auto",children:c&&l.length===0?t.jsx(S,{title:"scanning plugins…"}):f&&l.length===0?null:t.jsxs("div",{className:"flex flex-col gap-3 p-4",children:[l.length===0?t.jsxs("div",{"data-testid":"plugins-empty",className:"flex flex-col gap-1 px-[18px] py-4 border border-dashed border-rule rounded-[10px] text-[13px] text-fg-dim",children:[t.jsx("span",{className:"font-semibold text-fg",children:"No plugins installed"}),t.jsxs("span",{children:["Use + Add plugin, or run ",t.jsx("code",{className:"font-mono text-xs",children:"claude plugin install"}),"."]})]}):W.length===0?t.jsxs("p",{className:"px-1 text-[13px] text-fg-dim",children:["No plugins match “",p.trim(),"”."]}):W.map(d=>t.jsx(rt,{row:d,home:n,busy:U!==null&&U===(d.key??d.name),onToggle:x=>void _(x),onOpen:X,onUninstall:x=>void O(x),onJump:Z},d.path)),t.jsx("p",{className:"px-1 text-xs text-fg-faint",children:ct})]})})]})}const mt=a.memo(pt),ae={"dev-plugin":"session-manager-dev plugin","scheduler-mcp":"Scheduler MCP server","agent-personas":"Agent personas (Architect, Dev Lead)"};function ft({seeders:e,seedStatus:s,onDismiss:n,onOpenLibrary:l}){return t.jsx("div",{className:"shrink-0 flex flex-col gap-1.5 px-3 py-2 border-b border-line bg-yellow-950/20",children:e.map(o=>t.jsxs("div",{className:"flex items-start gap-2 text-xs text-yellow-300",children:[t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("div",{className:"font-medium",children:s[o].status==="failed"?`${ae[o]} setup failed — it will retry on next launch. To fix it now:`:`${ae[o]} setup failed after retrying — manual fix needed`}),o==="dev-plugin"?t.jsxs("div",{className:"text-yellow-400/80 mt-0.5",children:["Click ",t.jsx("button",{onClick:l,className:"underline hover:no-underline",children:"here"}),' to open the Library tab, then click Install next to "session-manager-dev".']}):t.jsx("div",{className:"text-yellow-400/80 mt-0.5 font-mono",children:s[o].fix})]}),t.jsx("button",{onClick:()=>n(o),className:"shrink-0 text-yellow-400/70 hover:text-yellow-300","aria-label":`Dismiss ${ae[o]} warning`,children:"✕"})]},o))})}const xt=250,ht=["hooks/hooks.json",".mcp.json",".lsp.json","agents","skills","commands",".claude-plugin/plugin.json"];function gt({row:e,home:s,onBack:n}){var X,Z,d,x,C;const[l,o]=a.useState([]),[c,u]=a.useState([]),[f,r]=a.useState([]),[i,g]=a.useState([]),[p,j]=a.useState([]),[m,y]=a.useState("skills"),[k,P]=a.useState(null),[E,U]=a.useState(!0),[D,B]=a.useState([]),M=a.useRef(0),A=a.useRef(!1),_=a.useCallback(async()=>{if(!s)return;const b=++M.current;try{const{manifest:N}=await Pe(e.path),[q,v,J]=await Promise.all([Me(e.path),Ae(e.path,N),Oe(`${e.path}/bin`,{filesOnly:!0})]),K=q?await Re(q):[],[z,$]=await Promise.all([ce(v.agentFiles),ce(v.commandFiles)]),w=v.mcpServers,L=await Promise.all([...new Set([...ht.map(h=>`${e.path}/${h}`),...v.sourcePaths])].map(async h=>await window.api.config.exists(h)?h:null));if(b!==M.current)return;o(K),u(z),r($),g(w),j(J);const T=L.filter(h=>h!==null);B(h=>h.join("\0")===T.join("\0")?h:T),A.current||(A.current=!0,y(K.length>0?"skills":z.length>0?"agents":$.length>0?"commands":w.length>0?"mcp":e.hooks>0?"hooks":e.monitors>0?"monitors":e.hasLsp?"lsp":"files"))}catch(N){if(b!==M.current)return;te.error(`Failed to load plugin contents: ${N instanceof Error?N.message:String(N)}`)}finally{b===M.current&&U(!1)}},[e.path,e.name,e.hooks,e.monitors,e.hasLsp,s]);a.useEffect(()=>(U(!0),_(),()=>{M.current+=1}),[_]);const O=a.useRef(null),I=a.useRef(!1),H=a.useRef(!1),F=a.useCallback(async()=>{if(I.current){H.current=!0;return}I.current=!0;try{do H.current=!1,await _();while(H.current)}finally{I.current=!1}},[_]),ne=a.useCallback(()=>{O.current&&clearTimeout(O.current),O.current=setTimeout(()=>{O.current=null,F()},xt)},[F]);a.useEffect(()=>()=>{O.current&&clearTimeout(O.current)},[]),Y(D,ne,{depth:0});const V=[{key:"skills",label:"Skills",count:l.length},{key:"agents",label:"Agents",count:c.length},{key:"commands",label:"Commands",count:f.length},{key:"mcp",label:"MCP server",count:i.length},{key:"hooks",label:"Hooks",count:e.hooks},{key:"monitors",label:"Monitors",count:e.monitors},{key:"lsp",label:"LSP",count:e.hasLsp?1:0},{key:"files",label:"Bin",count:p.length}],W=(X=e.manifest)!=null&&X.author?typeof e.manifest.author=="string"?e.manifest.author:e.manifest.author.name??null:null,se=async b=>{const N=await window.api.shell.open({as:"external",url:b});N.ok||te.error(N.error??`Failed to open ${b}`)};return k?t.jsx(lt,{pluginName:((Z=e.manifest)==null?void 0:Z.name)??e.name,skills:l,initialSelectedId:k.id,onBack:()=>P(null)},k.id):t.jsxs("div",{className:"flex flex-col h-full min-h-0 overflow-hidden",children:[t.jsxs("div",{className:"shrink-0 h-11 flex items-baseline gap-3.5 px-3 border-b border-line bg-bg",children:[t.jsx("button",{type:"button",onClick:n,className:"font-mono text-accent hover:underline shrink-0 text-xs",children:"← Plugins"}),t.jsx("span",{className:"font-serif text-[22px] text-fg shrink-0 truncate max-w-[16rem]",children:((d=e.manifest)==null?void 0:d.name)??e.name}),(x=e.manifest)!=null&&x.version?t.jsxs("span",{className:"font-mono text-fg-faint text-xs shrink-0",children:["v",e.manifest.version]}):null,(C=e.manifest)!=null&&C.description?t.jsx("span",{className:"text-fg-dim text-xs min-w-0 flex-1 overflow-hidden text-ellipsis whitespace-nowrap",children:e.manifest.description}):t.jsx("span",{className:"flex-1"}),t.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[t.jsx(pe,{input:me(e)}),e.hasMcp?t.jsx(je,{tone:"accent",children:"MCP"}):null]})]}),e.manifest?t.jsxs("div",{className:"shrink-0 h-[26px] flex items-center gap-[18px] px-3 bg-bg-elev border-b border-line text-[9px] font-mono uppercase tracking-wide overflow-hidden",children:[W?t.jsxs("span",{className:"text-fg-dim truncate",children:[t.jsx("span",{className:"text-fg-faint",children:"Author "}),W]}):null,e.manifest.license?t.jsxs("span",{className:"text-fg-dim truncate",children:[t.jsx("span",{className:"text-fg-faint",children:"License "}),e.manifest.license]}):null,e.manifest.homepage?t.jsxs("button",{onClick:()=>se(e.manifest.homepage),className:"text-accent hover:underline truncate normal-case",title:e.manifest.homepage,children:[t.jsx("span",{className:"text-fg-faint uppercase",children:"Homepage "}),e.manifest.homepage]}):null,t.jsx("span",{className:"ml-auto text-fg-faint truncate normal-case",children:e.path})]}):t.jsx("div",{className:"shrink-0 h-[26px] flex items-center px-3 bg-bg-elev border-b border-line text-[9px] font-mono uppercase tracking-wide overflow-hidden",children:t.jsx("span",{className:"ml-auto text-fg-faint truncate normal-case",children:e.path})}),t.jsxs("div",{className:"flex-1 min-h-0 grid overflow-hidden",style:{gridTemplateColumns:"170px 1fr"},children:[t.jsx("div",{className:"min-h-0 overflow-auto bg-bg-elev border-r border-line py-1",children:V.map(b=>t.jsxs("button",{type:"button",disabled:b.count===0,onClick:()=>y(b.key),className:`w-full text-left px-3 py-1.5 text-xs flex items-center justify-between ${b.count===0?"text-fg-faint opacity-50 cursor-default":m===b.key?"bg-bg-hi text-fg":"text-fg-dim hover:text-fg hover:bg-bg-hi"}`,children:[t.jsx("span",{children:b.label}),b.count>0?t.jsx("span",{className:"font-mono text-fg-faint",children:b.count}):null]},b.key))}),t.jsx("div",{className:"min-h-0 overflow-auto",children:E?t.jsx(S,{title:"scanning…"}):t.jsx(bt,{active:m,row:e,skills:l,agents:c,commands:f,mcpServers:i,files:p,onOpenSkill:P})})]})]})}function bt({active:e,row:s,skills:n,agents:l,commands:o,mcpServers:c,files:u,onOpenSkill:f}){return e==="skills"?n.length===0?t.jsx(S,{title:"no components"}):t.jsx("div",{children:n.map((r,i)=>t.jsx(R,{n:i+1,name:r.name??r.id,description:r.description,onClick:()=>f(r)},r.id))}):e==="agents"?l.length===0?t.jsx(S,{title:"no components"}):t.jsx("div",{children:l.map((r,i)=>t.jsx(R,{n:i+1,name:r.name??r.id,description:r.description},r.id))}):e==="commands"?o.length===0?t.jsx(S,{title:"no components"}):t.jsx("div",{children:o.map((r,i)=>t.jsx(R,{n:i+1,name:r.name??r.id,description:r.description},r.id))}):e==="mcp"?c.length===0?t.jsx(S,{title:"no components"}):t.jsx("div",{children:c.map((r,i)=>t.jsx(R,{n:i+1,name:r.name,description:r.description},r.id))}):e==="hooks"?s.hooks===0?t.jsx(S,{title:"no components"}):t.jsx("div",{children:t.jsx(R,{n:1,name:`${s.hooks} ${s.hooks===1?"hook":"hooks"} configured`,description:`${s.path}/hooks/hooks.json`})}):e==="monitors"?s.monitors===0?t.jsx(S,{title:"no components"}):t.jsx("div",{children:t.jsx(R,{n:1,name:`${s.monitors} ${s.monitors===1?"monitor":"monitors"} configured`,description:`${s.path}/monitors/monitors.json`})}):e==="lsp"?s.hasLsp?t.jsx("div",{children:t.jsx(R,{n:1,name:"LSP server enabled",description:`${s.path}/.lsp.json`})}):t.jsx(S,{title:"no components"}):u.length===0?t.jsx(S,{title:"no components"}):t.jsx("div",{children:u.map((r,i)=>t.jsx(R,{n:i+1,name:r,description:null},r))})}function R({n:e,name:s,description:n,onClick:l}){const o=l?"button":"div";return t.jsxs(o,{onClick:l,className:`w-full flex items-baseline gap-2.5 py-[9px] px-3 border-b border-line text-left min-w-0 ${l?"hover:bg-bg-hi cursor-pointer":""}`,children:[t.jsx("span",{className:"font-serif text-fg-faint text-xs shrink-0 w-6 text-right",children:String(e).padStart(2,"0")}),t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx("div",{className:"font-mono font-semibold text-accent truncate",children:s}),n?t.jsx("div",{className:"text-fg-dim text-xs truncate",children:n}):null]})]})}const kt=4;async function jt(e,s,n){const l=new Array(e.length);let o=0;const c=Array.from({length:Math.min(s,e.length)},async()=>{for(;o<e.length;){const u=o++;l[u]=await n(e[u])}});return await Promise.all(c),l}const vt={skills:"Add skill",mcp:"Add MCP server",plugins:"Add plugin"};function yt(e){return{skills:[{path:`${e}/.claude/skills`,kind:"dir"}],mcp:[{path:`${e}/.claude.json`,kind:"file",keyPath:"mcpServers"}],plugins:[{path:`${e}/.claude/plugins/installed_plugins.json`,kind:"file"},{path:`${e}/.claude/settings.json`,kind:"file",keyPath:"enabledPlugins"}]}}const Nt=[];function wt({sources:e,ages:s,home:n}){return t.jsx("div",{className:"flex flex-wrap justify-end gap-x-[18px] gap-y-1 text-[11.5px] text-fg-faint",children:e.map(l=>{const o=s[l.path],c=o===void 0?null:Qe(o);return t.jsxs("span",{"data-testid":"extensions-source",title:l.path,className:"whitespace-nowrap",children:[t.jsxs("span",{className:"font-mono text-fg-dim",children:[ue(l.path,n),l.keyPath?` › ${l.keyPath}`:""]}),c&&` · ${c}`]},l.path)})})}function St(){const e=re(),s=Ze(),[n,l]=a.useState("skills"),[o,c]=a.useState(!1),[u,f]=a.useState({scope:"user",cwd:null});ve("extensions",k=>{(k==="skills"||k==="mcp"||k==="plugins")&&(l(k),c(!1))});const r=a.useMemo(()=>e?yt(e):null,[e]),i=a.useMemo(()=>r?[...r.skills,...r.mcp,...r.plugins]:Nt,[r]),g=nt(i),p=a.useCallback(k=>{l(k),c(!1)},[]),j=a.useCallback(()=>c(!1),[]),m=a.useCallback(k=>{f(k),c(!0)},[]),y=a.useCallback(()=>c(!0),[]);return t.jsxs("div",{className:"flex flex-col h-full min-h-0","data-testid":"extensions",children:[t.jsx("div",{className:"shrink-0 mt-6 -mb-px relative z-[1]","data-testid":"extensions-tabs",children:t.jsx(qe,{ariaLabel:"Extensions",options:[{key:"skills",label:"Skills",count:s.skills},{key:"mcp",label:"MCP Servers",count:s.mcp},{key:"plugins",label:"Plugins",count:s.plugins}],active:n,onChange:p,trailing:e&&r?t.jsx(wt,{sources:r[n],ages:g,home:e}):null})}),t.jsxs("div",{className:"flex-1 min-h-0 border border-line bg-bg","data-testid":"extensions-panel",children:[n==="skills"&&t.jsx(Le,{onAdd:y,scope:"user"}),n==="mcp"&&t.jsx(Te,{onAdd:m,scope:"user"}),n==="plugins"&&t.jsx(mt,{onAdd:y,onJump:p})]}),t.jsxs(ye,{open:o,onClose:j,title:vt[n],keyVals:[],children:[n==="skills"&&t.jsx(Ie,{}),n==="mcp"&&t.jsx(Fe,{scope:u.scope,cwd:u.cwd}),n==="plugins"&&t.jsx(Ue,{})]})]})}const Dt=a.memo(St);export{Dt as Extensions};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{aJ as xe,aR as Ge,bB as ze,ay as e,aO as x,b7 as q,aK as A,aL as L,bu as Ve,bj as Ye,bs as ye,aE as Xe,bi as qe,m as Je}from"./index-iQ6pdyuS.js";import{P as Qe}from"./Panel-BuInRmA0.js";import{p as Ee,i as O,m as De,t as I,u as E,f as Ze}from"./historyTotals-Cgjm5q24.js";import"./monaco-editor-BsIlgG7c.js";function ce(){return{promptCount:0,inputTokens:0,outputTokens:0,cacheReadTokens:0,cacheCreationTokens:0,toolCallCount:0,sessionCount:0,errorCount:0,activeMinutes:0,estimatedCostUsd:0}}function Ce(t,s){t.promptCount+=s.promptCount,t.inputTokens+=s.inputTokens,t.outputTokens+=s.outputTokens,t.cacheReadTokens+=s.cacheReadTokens,t.cacheCreationTokens+=s.cacheCreationTokens,t.toolCallCount+=s.toolCallCount,t.sessionCount+=s.sessionCount,t.errorCount+=s.errorCount,t.activeMinutes+=s.activeMinutes,t.estimatedCostUsd+=s.estimatedCostUsd}function et(t){return t.promptCount>0||t.sessionCount>0||t.toolCallCount>0||t.inputTokens>0||t.outputTokens>0}function tt(t,s){const n=s===null,r=[],o=ce(),i={};let a=0;for(const c of t.days){const u=ce();let d=!1;for(const[l,p]of Object.entries(c.byProject))if(!(!n&&!s.has(l))){Ce(u,p),Ce(o,p),et(p)&&(d=!0);for(const[m,v]of Object.entries(p.byModel)){const k=i[m]??(i[m]={inputTokens:0,outputTokens:0,cacheReadTokens:0,cacheCreationTokens:0,costUsd:0});k.inputTokens+=v.inputTokens,k.outputTokens+=v.outputTokens,k.cacheReadTokens+=v.cacheReadTokens,k.cacheCreationTokens+=v.cacheCreationTokens,k.costUsd+=v.costUsd,v.estimated&&(k.estimated=!0)}}d&&(a+=1),r.push({date:c.date,totals:u})}return{days:r,totals:o,prevTotals:n?t.prevTotals:ce(),prevAvailable:n,byModelTotals:i,activeDays:a}}function Ue(t,s){if(!s)return{pct:null,direction:"flat"};const n=(t-s)/s*100,r=n>0?"up":n<0?"down":"flat";return{pct:n,direction:r}}function st(t,s,n){return s<=0?0:t/s*n}const nt=["promptCount","inputTokens","outputTokens","cacheReadTokens","cacheCreationTokens","toolCallCount","sessionCount","errorCount","activeMinutes","estimatedCostUsd"],ot=["inputTokens","outputTokens","cacheReadTokens","cacheCreationTokens","costUsd"];function Ne(t){const s={promptCount:0,inputTokens:0,outputTokens:0,cacheReadTokens:0,cacheCreationTokens:0,toolCallCount:0,sessionCount:0,errorCount:0,activeMinutes:0,estimatedCostUsd:0,byModel:{}},n=r=>typeof r=="number"&&Number.isFinite(r)?r:0;for(const r of t){for(const o of nt)s[o]+=n(r[o]);for(const[o,i]of Object.entries(r.byModel??{})){const a=s.byModel[o]??(s.byModel[o]={inputTokens:0,outputTokens:0,cacheReadTokens:0,cacheCreationTokens:0,costUsd:0});for(const c of ot)a[c]+=n(i==null?void 0:i[c])}}return s}const Pe={in:"In tokens",out:"Out tokens",total:"Total tokens",prompts:"Prompts",sessions:"Sessions",time:"Time",spend:"Spend"};function $(t,s){const n=t.inputTokens+t.cacheReadTokens+t.cacheCreationTokens;switch(s){case"in":return n;case"out":return t.outputTokens;case"total":return n+t.outputTokens;case"prompts":return t.promptCount;case"sessions":return t.sessionCount;case"time":return t.activeMinutes;case"spend":return t.estimatedCostUsd}}function at(t,s){const n=$(t.totals,s),r=t.prevAvailable?Ue(n,$(t.prevTotals,s)):null,o=t.days.map(i=>$(i.totals,s));return{value:n,delta:r,series:o}}function Te(t,s){const n=new Map,r=Math.ceil(t.length/2);t.forEach((a,c)=>{for(const[u,d]of Object.entries(a.byProject)){let l=n.get(u);l||(l={totals:{promptCount:0,inputTokens:0,outputTokens:0,cacheReadTokens:0,cacheCreationTokens:0,toolCallCount:0,sessionCount:0,errorCount:0,activeMinutes:0,estimatedCostUsd:0},toolBreakdown:{},firstHalf:0,secondHalf:0},n.set(u,l)),l.totals.promptCount+=d.promptCount,l.totals.inputTokens+=d.inputTokens,l.totals.outputTokens+=d.outputTokens,l.totals.cacheReadTokens+=d.cacheReadTokens,l.totals.cacheCreationTokens+=d.cacheCreationTokens,l.totals.toolCallCount+=d.toolCallCount,l.totals.sessionCount+=d.sessionCount,l.totals.errorCount+=d.errorCount,l.totals.activeMinutes+=d.activeMinutes,l.totals.estimatedCostUsd+=d.estimatedCostUsd;for(const[m,v]of Object.entries(d.toolBreakdown))l.toolBreakdown[m]=(l.toolBreakdown[m]??0)+v;const p=$(d,s);c<r?l.firstHalf+=p:l.secondHalf+=p}});const o=Array.from(n.entries()).map(([a,c])=>{let u="",d=-1;for(const[l,p]of Object.entries(c.toolBreakdown))p>d&&(d=p,u=l);return{projectDir:a,value:$(c.totals,s),sharePct:0,trend:Ue(c.secondHalf,c.firstHalf),sessions:c.totals.sessionCount,topTool:u}}),i=o.reduce((a,c)=>a+c.value,0);for(const a of o)a.sharePct=i>0?a.value/i*100:0;return o.sort((a,c)=>c.value-a.value)}const rt=["date","cost_usd","input_tokens","output_tokens","cache_write_tokens","cache_read_tokens","total_tokens","cache_hit_pct","num_models","top_model"];function ct(t){return/[",\n]/.test(t)?`"${t.replace(/"/g,'""')}"`:t}function we(t){return t.inputTokens+t.outputTokens+t.cacheReadTokens+t.cacheCreationTokens}function it(t){const s=t.map(n=>{const r=n.inputTokens+n.outputTokens+n.cacheCreationTokens+n.cacheReadTokens,o=n.inputTokens+n.cacheReadTokens+n.cacheCreationTokens,i=o>0?n.cacheReadTokens/o*100:0,a=Object.entries(n.byModel).filter(([,l])=>we(l)>0);let c="",u=-1;for(const[l,p]of a){const m=we(p);m>u&&(u=m,c=l)}return[n.date,n.costUsd.toFixed(4),String(n.inputTokens),String(n.outputTokens),String(n.cacheCreationTokens),String(n.cacheReadTokens),String(r),i.toFixed(1),String(a.length),c?xe(c):""].map(ct).join(",")});return[rt.join(","),...s].join(`
|
|
2
|
-
`)}const lt={folderCount:0,sessionCount:0,promptCount:0,estimatedCostUsd:0,totalTokens:0};function dt(t,s){t.promptCount+=s.promptCount,t.inputTokens+=s.inputTokens,t.outputTokens+=s.outputTokens,t.cacheReadTokens+=s.cacheReadTokens,t.cacheCreationTokens+=s.cacheCreationTokens,t.toolCallCount+=s.toolCallCount,t.sessionCount+=s.sessionCount,t.errorCount+=s.errorCount,t.activeMinutes+=s.activeMinutes,t.estimatedCostUsd+=s.estimatedCostUsd;for(const[n,r]of Object.entries(s.toolBreakdown??{}))t.toolBreakdown[n]=(t.toolBreakdown[n]??0)+r;for(const[n,r]of Object.entries(s.byModel??{})){const o=t.byModel[n]??(t.byModel[n]={inputTokens:0,outputTokens:0,cacheReadTokens:0,cacheCreationTokens:0,costUsd:0});o.inputTokens+=r.inputTokens,o.outputTokens+=r.outputTokens,o.cacheReadTokens+=r.cacheReadTokens,o.cacheCreationTokens+=r.cacheCreationTokens,o.costUsd+=r.costUsd,r.estimated&&(o.estimated=!0)}}function ut(t,s){const n={};for(const[r,o]of Object.entries(t.byModel??{}))n[r]={...o};return{...t,projectDir:s,toolBreakdown:{...t.toolBreakdown??{}},byModel:n}}function ft(t,s){const n={...lt},r=new Set,o=t.map(i=>{const a={};for(const[c,u]of Object.entries(i.byProject)){const d=s[c];if(!d){r.add(c),n.sessionCount+=u.sessionCount,n.promptCount+=u.promptCount,n.estimatedCostUsd+=u.estimatedCostUsd,n.totalTokens+=u.inputTokens+u.outputTokens;continue}const l=a[d];l?dt(l,u):a[d]=ut(u,d)}return{...i,byProject:a}});return n.folderCount=r.size,{days:o,excluded:n}}function xt(t){return t.folderCount>0}function pt(t){const s=[`${t.folderCount} transcript folder${t.folderCount===1?"":"s"} with no resolvable working directory`];return t.sessionCount&&s.push(`${t.sessionCount.toLocaleString()} sessions`),t.promptCount&&s.push(`${t.promptCount.toLocaleString()} prompts`),t.estimatedCostUsd>=.005&&s.push(`$${t.estimatedCostUsd.toFixed(2)}`),`Excluded: ${s.join(" · ")}`}async function pe(){return(await Ge()).history??{}}let Re=Promise.resolve();function ue(t){const s=Re.then(async()=>{const n=await pe();await ze({history:{...n,...t}})});return Re=s.catch(()=>{}),s}const ht=["in","out","total","prompts","sessions","time","spend"],mt=[{value:30,label:"30d"},{value:60,label:"60d"},{value:90,label:"90d"},{value:0,label:"All time"}];function Me({value:t,options:s,onChange:n}){return e.jsx("div",{className:"flex gap-0.5 p-0.5 rounded bg-bg-elev shadow-[inset_0_0_0_1px_rgba(0,0,0,0.06)] text-[11px]",children:s.map(r=>e.jsx("button",{onClick:()=>n(r.value),className:`px-2 py-1 rounded whitespace-nowrap font-mono ${t===r.value?"bg-bg-hi text-fg shadow-sm":"text-fg-faint hover:text-fg"}`,children:r.label},String(r.value)))})}function jt({measure:t,onMeasure:s,range:n,onRange:r,projectsShown:o,projectsTotal:i,fromDate:a,toDate:c,onRefresh:u,onExport:d,exportDisabled:l}){return e.jsxs("div",{className:"sticky top-0 z-10 border-b border-line px-4 py-2.5 flex flex-wrap items-center gap-3 backdrop-blur-sm",style:{backgroundColor:"rgba(246,239,225,0.93)"},children:[e.jsx(Me,{value:t,options:ht.map(p=>({value:p,label:Pe[p]})),onChange:s}),e.jsx(Me,{value:n,options:mt,onChange:r}),e.jsxs("span",{className:"text-[11px] text-fg-faint font-mono",children:[o," / ",i," projects"]}),e.jsxs("span",{className:"text-[11px] text-fg-faint font-mono",children:[a," → ",c]}),e.jsx("div",{className:"flex-1"}),e.jsx("button",{onClick:u,className:"px-2 py-1 text-[11px] border border-line rounded hover:text-fg hover:bg-bg-hi text-fg-faint",title:"Re-fetch the rollup (no scan)",children:"↻ Refresh"}),e.jsx("button",{onClick:d,disabled:l,className:"px-2 py-1 text-[11px] border border-line rounded hover:text-fg hover:bg-bg-hi text-fg-faint disabled:opacity-40 disabled:pointer-events-none",children:"Export CSV"})]})}const T="rounded-card bg-bg-hi border border-line",gt="#ded2bd",bt="#6f7d52";function R({kicker:t,title:s,right:n}){return e.jsxs("div",{className:"flex items-baseline justify-between gap-3 mb-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[10.5px] uppercase tracking-wider text-accent font-mono",children:t}),e.jsx("h2",{className:"font-serif text-[25px] leading-tight tracking-tight text-fg",children:s})]}),n]})}function J(t,s){switch(t){case"spend":return E(s);case"in":case"out":case"total":return I(s);case"time":return De(s);default:return O(s)}}function vt({measure:t,headline:s,activeDays:n,projectsTouched:r,totalSessions:o}){const i=n>0?s.value/n:0,a=o>0?s.value/o:0,{delta:c}=s,u=c&&(t==="spend"?c.direction==="down":c.direction==="up"),d=c&&c.direction!=="flat"&&(t==="spend"?c.direction==="up":c.direction==="down"),l=u?"text-delta-good":d?"text-delta-bad":"text-fg-faint";return e.jsxs("div",{className:`${T} p-4`,children:[e.jsx(R,{kicker:"01 · overview",title:Pe[t]}),e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[52px] leading-none font-mono tracking-tight text-fg",children:J(t,s.value)}),c?e.jsxs("div",{className:`text-xs font-mono mt-2 ${l}`,children:[c.direction==="up"?"▲":c.direction==="down"?"▼":"·"," ",Ee(Math.abs(c.pct??0))," vs prior period"]}):e.jsx("div",{className:"text-xs text-fg-faint mt-2",children:"no prior window to compare"})]}),e.jsx("div",{className:"flex-1 min-w-0 self-stretch",children:e.jsx(kt,{series:s.series})})]}),e.jsxs("div",{className:"grid grid-cols-4 gap-3 mt-4 pt-3 border-t border-line",children:[e.jsx(X,{label:"per active day",value:J(t,i)}),e.jsx(X,{label:"per session",value:J(t,a)}),e.jsx(X,{label:"active days",value:O(n)}),e.jsx(X,{label:"projects touched",value:O(r)})]})]})}function X({label:t,value:s}){return e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] text-fg-faint uppercase tracking-wider",children:t}),e.jsx("div",{className:"text-[17px] font-mono tracking-tight text-fg-dim",children:s})]})}function kt({series:t}){if(t.length<2)return null;const r=Math.max(...t,0),o=Math.min(...t,0),i=r-o||1,a=160/(t.length-1),c=t.map((d,l)=>`${l*a},${48-(d-o)/i*48}`).join(" "),u=`0,48 ${c} 160,48`;return e.jsxs("svg",{viewBox:"0 0 160 48",preserveAspectRatio:"none",className:"w-full h-full min-h-[48px]",children:[e.jsx("polygon",{points:u,fill:"#b85c34",opacity:.15}),e.jsx("polyline",{points:c,fill:"none",stroke:"#b85c34",strokeWidth:1.5,vectorEffect:"non-scaling-stroke"})]})}const yt=50;function Ct({days:t}){const[s,n]=x.useState(yt),r=x.useRef(!1);x.useEffect(()=>{let d=!1;return pe().then(l=>{d||r.current||typeof l.budgetCapUsd=="number"&&Number.isFinite(l.budgetCapUsd)&&l.budgetCapUsd>0&&n(l.budgetCapUsd)}),()=>{d=!0}},[]);const o=d=>{r.current=!0;const l=s;n(d),ue({budgetCapUsd:d}).catch(()=>{n(l),q.error("Couldn't save the budget cap — reverted.")})},{mtdSpend:i,projectedSpend:a}=x.useMemo(()=>{const d=new Date,l=d.toLocaleDateString("en-CA").slice(0,7),p=new Date(d.getFullYear(),d.getMonth()+1,0).getDate(),m=d.getDate();let v=0;for(const k of t)if(k.date.startsWith(l))for(const M of Object.values(k.byProject))v+=M.estimatedCostUsd;return{mtdSpend:v,projectedSpend:st(v,m,p)}},[t]),c=a>s,u=s>0?Math.min(100,i/s*100):0;return e.jsxs("div",{className:`${T} p-3`,children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("h3",{className:"text-[10.5px] uppercase tracking-wider text-fg-faint font-mono",children:"Monthly budget"}),e.jsxs("label",{className:"flex items-center gap-1.5 text-[10px] text-fg-faint",children:["cap",e.jsx("span",{children:"$"}),e.jsx("input",{type:"number",min:1,step:1,value:s,onChange:d=>{const l=Number(d.target.value);Number.isFinite(l)&&l>0&&o(l)},className:"w-16 bg-bg border border-line rounded px-1.5 py-0.5 text-xs text-fg font-mono"})]})]}),e.jsxs("div",{className:"flex items-center gap-4 text-xs font-mono mb-1.5",children:[e.jsxs("span",{className:"text-fg",children:[E(i)," ",e.jsx("span",{className:"text-fg-faint",children:"month-to-date"})]}),e.jsxs("span",{className:c?"text-delta-bad":"text-fg-dim",children:[E(a)," ",e.jsx("span",{className:"text-fg-faint",children:"projected"})]})]}),e.jsx("div",{className:"h-1.5 rounded bg-bg-hi overflow-hidden",children:e.jsx("div",{className:`h-full ${c?"bg-delta-bad":"bg-sage"}`,style:{width:`${Math.max(u,u>0?2:0)}%`}})}),e.jsx("div",{className:`text-[10px] mt-1 font-mono ${c?"text-delta-bad":"text-fg-faint"}`,children:c?`projected to exceed $${s.toFixed(0)} cap`:`${u.toFixed(0)}% of $${s.toFixed(0)} cap`})]})}function Nt({chips:t,keep:s,onToggle:n,onIsolate:r,onShowAll:o}){const i=s===null;return e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.jsxs("button",{onClick:o,className:`px-2 py-1 rounded text-[11px] font-mono border ${i?"bg-accent text-white border-accent":"border-line text-fg-faint hover:text-fg hover:bg-bg-hi"}`,children:["show all (",t.length,")"]}),t.map(a=>{const c=i||s.has(a.projectDir);return e.jsxs("button",{onClick:u=>u.shiftKey?r(a.projectDir):n(a.projectDir),title:a.projectDir,className:`inline-flex items-center gap-1.5 px-2 py-1 rounded text-[11px] font-mono border ${c?"border-line text-fg-dim bg-bg-hi":"border-line text-fg-faint opacity-40 hover:opacity-70"}`,children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full shrink-0",style:{backgroundColor:A(a.projectDir)}}),L(a.projectDir)]},a.projectDir)})]})}function Tt(t,s){const n=new Map;for(const o of t)for(const[i,a]of Object.entries(o.values))n.set(i,(n.get(i)??0)+a);const r=Array.from(n.entries()).sort((o,i)=>i[1]-o[1]).map(([o])=>o);return t.map(o=>{const i=r.reduce((u,d)=>u+(o.values[d]??0),0);let a=0;const c=r.map(u=>{const d=o.values[u]??0;if(i<=0)return{projectDir:u,value:d,y0:0,y1:0};const l=s==="share"?d/i:d,p=a,m=a+l;return a=m,{projectDir:u,value:d,y0:p,y1:m}});return{date:o.date,bands:c,total:i}})}const ie=720,le=220,de=44,wt=20;function Rt(t,s){return t==="spend"?E(s):I(s)}function Mt({days:t,measure:s,selected:n,onSelect:r}){const[o,i]=x.useState("absolute"),a=x.useMemo(()=>Tt(t,o),[t,o]),c=x.useMemo(()=>{if(o==="share")return 1;let h=0;for(const g of a)h=Math.max(h,g.total);return h||1},[a,o]),u=ie-de,d=le-wt,l=a.length>1?u/(a.length-1):u,p=h=>de+h*l,m=h=>d-h/c*d,v=Math.max(1,Math.ceil(a.length/8)),k=4,M=Array.from({length:k+1},(h,g)=>c/k*g);return e.jsxs("div",{className:`${T} p-4`,children:[e.jsx(R,{kicker:"02 · over time",title:"Trend by project",right:e.jsx("div",{className:"flex border border-line rounded overflow-hidden text-[10px] font-mono",children:["absolute","share"].map(h=>e.jsx("button",{onClick:()=>i(h),className:`px-2 py-0.5 ${o===h?"bg-accent text-white":"text-fg-faint hover:text-fg"}`,children:h},h))})}),e.jsxs("svg",{width:"100%",viewBox:`0 0 ${ie} ${le}`,className:"overflow-visible",children:[M.map((h,g)=>e.jsxs("g",{children:[e.jsx("line",{x1:de,x2:ie,y1:m(h),y2:m(h),stroke:"currentColor",className:"text-line",strokeWidth:1}),e.jsx("text",{x:0,y:m(h)+3,fontSize:9,className:"fill-fg-faint",children:o==="share"?`${Math.round(h*100)}%`:Rt(s,h)})]},g)),a.map((h,g)=>{if(g===0)return null;const D=a[g-1];return h.bands.map((j,Z)=>{const K=D.bands[Z],W=n!==null&&n!==j.projectDir,ee=W?gt:A(j.projectDir),te=[`${p(g-1)},${m(K.y0)}`,`${p(g)},${m(j.y0)}`,`${p(g)},${m(j.y1)}`,`${p(g-1)},${m(K.y1)}`].join(" ");return e.jsx("polygon",{points:te,fill:ee,opacity:W?.6:.75,className:"cursor-pointer",onClick:()=>r(n===j.projectDir?null:j.projectDir),children:e.jsx("title",{children:L(j.projectDir)})},`${j.projectDir}-${g}`)})}),a.map((h,g)=>g%v!==0&&g!==a.length-1?null:e.jsx("text",{x:p(g),y:le-4,fontSize:9,textAnchor:"middle",className:"fill-fg-faint",children:h.date.slice(5)},h.date))]})]})}function St({rows:t,measure:s,selected:n,onSelect:r}){return t.length?e.jsxs("div",{className:`${T} overflow-hidden`,children:[e.jsx("div",{className:"p-4 pb-0",children:e.jsx(R,{kicker:"03 · by project",title:"Ranking"})}),e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{className:"bg-bg-elev",children:e.jsx("tr",{children:["project","share","value","share %","trend","sessions","top tool"].map(o=>e.jsx("th",{className:"text-left px-3 py-2 text-fg-faint uppercase tracking-wider whitespace-nowrap",children:o},o))})}),e.jsx("tbody",{children:t.map(o=>{const i=A(o.projectDir),a=n===o.projectDir;return e.jsxs("tr",{onClick:()=>r(o.projectDir),className:`border-t border-line hover:bg-bg-elev cursor-pointer ${a?"bg-bg-elev":""}`,children:[e.jsx("td",{className:"px-3 py-2 font-mono text-fg-dim",children:e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full shrink-0",style:{backgroundColor:i}}),L(o.projectDir)]})}),e.jsx("td",{className:"px-3 py-2 w-32",children:e.jsx("div",{className:"h-1.5 rounded bg-bg-hi overflow-hidden",children:e.jsx("div",{className:"h-full",style:{width:`${Math.max(o.sharePct,o.sharePct>0?2:0)}%`,backgroundColor:i}})})}),e.jsx("td",{className:"px-3 py-2 text-fg-faint font-mono",children:J(s,o.value)}),e.jsxs("td",{className:"px-3 py-2 text-fg-faint font-mono",children:[o.sharePct.toFixed(1),"%"]}),e.jsx("td",{className:"px-3 py-2 font-mono",children:o.trend.pct===null?e.jsx("span",{className:"text-fg-faint",children:"—"}):e.jsxs("span",{className:o.trend.direction==="up"?"text-delta-good":o.trend.direction==="down"?"text-delta-bad":"text-fg-faint",children:[o.trend.direction==="up"?"▲":o.trend.direction==="down"?"▼":"·"," ",Ee(Math.abs(o.trend.pct))]})}),e.jsx("td",{className:"px-3 py-2 text-fg-faint font-mono",children:O(o.sessions)}),e.jsx("td",{className:"px-3 py-2 text-fg-faint font-mono",children:o.topTool||"—"})]},o.projectDir)})})]})]}):e.jsxs("div",{className:`${T} p-4`,children:[e.jsx(R,{kicker:"03 · by project",title:"Ranking"}),e.jsx("div",{className:"text-xs text-fg-faint",children:"no projects in range"})]})}function $t({projectDir:t,totals:s,byModel:n,toolBreakdown:r,onClear:o}){var l;const i=$(s,"in"),a=$(s,"out"),c=Object.entries(n).sort((p,m)=>m[1].costUsd-p[1].costUsd),u=Object.entries(r).sort((p,m)=>m[1]-p[1]),d=((l=u[0])==null?void 0:l[1])??0;return e.jsxs("div",{className:`${T} p-4`,children:[e.jsx(R,{kicker:"04 · drill in",title:L(t),right:e.jsx("button",{onClick:o,className:"text-[11px] text-fg-faint hover:text-fg font-mono",children:"clear ✕"})}),e.jsx("div",{className:"flex items-center gap-1.5 -mt-2 mb-3",children:e.jsx("span",{className:"w-1.5 h-1.5 rounded-full shrink-0",style:{backgroundColor:A(t)}})}),e.jsxs("div",{className:"grid grid-cols-6 gap-3 mb-4",children:[e.jsx(H,{label:"prompts",value:O(s.promptCount)}),e.jsx(H,{label:"sessions",value:O(s.sessionCount)}),e.jsx(H,{label:"in tokens",value:I(i)}),e.jsx(H,{label:"out tokens",value:I(a)}),e.jsx(H,{label:"spend",value:E(s.estimatedCostUsd)}),e.jsx(H,{label:"time",value:De(s.activeMinutes)})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] text-fg-faint uppercase tracking-wider mb-1.5",children:"model mix"}),c.length===0?e.jsx("div",{className:"text-xs text-fg-faint",children:"no model data"}):e.jsx("div",{className:"space-y-1",children:c.map(([p,m])=>e.jsxs("div",{className:"flex items-center justify-between text-[11px] font-mono text-fg-dim",children:[e.jsx("span",{children:xe(p)}),e.jsx("span",{className:"text-fg-faint",children:E(m.costUsd)})]},p))})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] text-fg-faint uppercase tracking-wider mb-1.5",children:"tool mix"}),u.length===0?e.jsx("div",{className:"text-xs text-fg-faint",children:"no tool data"}):e.jsx("div",{className:"space-y-1",children:u.slice(0,6).map(([p,m])=>e.jsxs("div",{className:"flex items-center gap-2 text-[11px]",children:[e.jsx("span",{className:"w-20 shrink-0 truncate text-fg-dim font-mono",children:p}),e.jsx("div",{className:"flex-1 h-1.5 rounded bg-bg-hi overflow-hidden",children:e.jsx("div",{className:"h-full bg-hive-teal",style:{width:`${d>0?m/d*100:0}%`}})}),e.jsx("span",{className:"text-fg-faint font-mono w-8 text-right",children:m})]},p))})]})]})]})}function H({label:t,value:s}){return e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] text-fg-faint uppercase tracking-wider",children:t}),e.jsx("div",{className:"text-[17px] font-mono tracking-tight text-fg",children:s})]})}function Et({byModelTotals:t}){const s=Object.entries(t).sort((r,o)=>o[1].costUsd-r[1].costUsd),n=s.reduce((r,[,o])=>r+o.costUsd,0);return e.jsxs("div",{className:`${T} p-4`,children:[e.jsx(R,{kicker:"05 · composition",title:"Model mix",right:e.jsxs("span",{className:"text-xs font-mono text-fg-faint",children:[E(n)," total"]})}),s.length===0?e.jsx("div",{className:"text-xs text-fg-faint",children:"no model data in range"}):e.jsx("div",{className:"space-y-2",children:s.map(([r,o])=>{const i=n>0?o.costUsd/n*100:0,a=A(r);return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between text-xs mb-0.5",children:[e.jsxs("span",{className:"flex items-center gap-1.5 font-mono text-fg-dim truncate",children:[e.jsx("span",{className:"w-2 h-2 rounded-sm shrink-0",style:{backgroundColor:a}}),xe(r),o.estimated&&e.jsx("span",{className:"text-fg-faint",children:"(est.)"})]}),e.jsxs("span",{className:"text-fg-faint whitespace-nowrap ml-2",children:[E(o.costUsd)," · ",i.toFixed(0),"%"]})]}),e.jsx("div",{className:"h-1.5 rounded bg-bg-hi overflow-hidden",children:e.jsx("div",{className:"h-full",style:{width:`${Math.max(i,i>0?2:0)}%`,backgroundColor:a}})})]},r)})})]})}function Dt({rows:t}){const s=t.slice(0,3),n=s.reduce((i,a)=>i+a.sharePct,0),r=t.slice(3),o=r.reduce((i,a)=>i+a.sharePct,0);return e.jsxs("div",{className:`${T} p-4`,children:[e.jsx(R,{kicker:"05 · composition",title:"Concentration",right:e.jsxs("span",{className:"text-xs font-mono text-fg-faint",children:["top 3 = ",n.toFixed(0),"%"]})}),t.length===0?e.jsx("div",{className:"text-xs text-fg-faint",children:"no projects in range"}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex h-3 rounded overflow-hidden mb-2",children:t.map(i=>e.jsx("div",{style:{width:`${Math.max(i.sharePct,.5)}%`,backgroundColor:A(i.projectDir)},title:`${L(i.projectDir)} · ${i.sharePct.toFixed(1)}%`},i.projectDir))}),e.jsx("div",{className:"space-y-1 mb-2",children:s.map(i=>e.jsxs("div",{className:"flex items-center justify-between text-[11px] font-mono",children:[e.jsxs("span",{className:"flex items-center gap-1.5 text-fg-dim truncate",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full shrink-0",style:{backgroundColor:A(i.projectDir)}}),L(i.projectDir)]}),e.jsxs("span",{className:"text-fg-faint",children:[i.sharePct.toFixed(1),"%"]})]},i.projectDir))}),r.length>0&&e.jsxs("p",{className:"text-[10px] text-fg-faint",children:[r.length," more project",r.length===1?"":"s"," account for ",o.toFixed(1),"% (long tail)."]})]})]})}const Q=30,fe=9,P=(Q+fe)*2;function Ut({totals:t}){const s=t.inputTokens+t.cacheReadTokens+t.cacheCreationTokens,n=s>0?t.cacheReadTokens/s*100:0,r=2*Math.PI*Q,o=P/2;return e.jsxs("div",{className:`${T} p-4`,children:[e.jsx(R,{kicker:"05 · composition",title:"Cache"}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("div",{className:"relative shrink-0",style:{width:P,height:P},children:[e.jsxs("svg",{width:P,height:P,viewBox:`0 0 ${P} ${P}`,className:"-rotate-90",children:[e.jsx("circle",{cx:o,cy:o,r:Q,fill:"none",stroke:"currentColor",className:"text-bg-hi",strokeWidth:fe}),e.jsx("circle",{cx:o,cy:o,r:Q,fill:"none",stroke:bt,strokeWidth:fe,strokeDasharray:r,strokeDashoffset:r*(1-n/100),strokeLinecap:"round"})]}),e.jsxs("div",{className:"absolute inset-0 flex items-center justify-center text-[13px] font-mono text-fg",children:[n.toFixed(0),"%"]})]}),e.jsxs("div",{className:"text-[11px] space-y-1 font-mono",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("span",{className:"text-fg-faint",children:"reused (cache read)"}),e.jsx("span",{className:"text-fg-dim",children:I(t.cacheReadTokens)})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("span",{className:"text-fg-faint",children:"written to cache"}),e.jsx("span",{className:"text-fg-dim",children:I(t.cacheCreationTokens)})]})]})]})]})}const Pt=.05,At="—",Se=t=>`$${t.toFixed(2)}`;function Ft(){const[t,s]=x.useState(null),[n,r]=x.useState(null),o=Ve(a=>a.show);x.useEffect(()=>{let a=!0;const c=()=>{window.api.history.loopEfficiency().then(d=>{a&&(s(d),r(null))}).catch(d=>{if(!a)return;const l=d instanceof Error?d.message:String(d);r(l),o("error",`Loop efficiency failed to load: ${l}`)})};c();const u=window.api.history.onUpdated(c);return()=>{a=!1,u()}},[o]);let i;if(n&&!t)i=e.jsxs("div",{"data-testid":"loop-eff-error",className:"text-[11px] font-mono text-fg-faint",children:["Failed to load: ",n]});else if(!t)i=e.jsx("div",{"data-testid":"loop-eff-loading",className:"text-[11px] font-mono text-fg-faint",children:"Loading…"});else if(t.rows.length===0)i=e.jsx("div",{"data-testid":"loop-eff-empty",className:"text-[11px] font-mono text-fg-faint",children:"No runs this week."});else{const a=t.totals.wastedRunRate>Pt;i=e.jsxs(e.Fragment,{children:[e.jsxs("table",{className:"w-full text-[11px] font-mono","data-testid":"loop-eff-table",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-fg-faint text-left",children:[e.jsx("th",{className:"font-normal",children:"Project"}),e.jsx("th",{className:"font-normal text-right",children:"Runs"}),e.jsx("th",{className:"font-normal text-right",children:"Wasted"}),e.jsx("th",{className:"font-normal text-right",children:"Verified"}),e.jsx("th",{className:"font-normal text-right",children:"Refuted"}),e.jsx("th",{className:"font-normal text-right",children:"List-price $"}),e.jsx("th",{className:"font-normal text-right",children:"$ / verified"})]})}),e.jsx("tbody",{className:"text-fg-dim",children:t.rows.map(c=>e.jsxs("tr",{"data-testid":"loop-eff-row",children:[e.jsx("td",{children:c.project}),e.jsx("td",{className:"text-right",children:c.runs}),e.jsx("td",{className:"text-right",children:c.wastedRuns}),e.jsx("td",{className:"text-right",children:c.verified}),e.jsx("td",{className:"text-right",children:c.refuted}),e.jsx("td",{className:"text-right",children:Se(c.executorUsd)}),e.jsx("td",{className:"text-right","data-testid":"loop-eff-per-verified",children:c.usdPerVerified==null?At:Se(c.usdPerVerified)})]},c.cwd))})]}),e.jsxs("div",{"data-testid":"loop-eff-totals","data-warning":a?"true":"false",className:`mt-2 text-[11px] font-mono ${a?"text-amber-300":"text-fg-dim"}`,children:["wasted runs ",(t.totals.wastedRunRate*100).toFixed(1),"% (",t.totals.wastedRuns,"/",t.totals.runs,") · target ≤ 5%"]}),e.jsx("div",{"data-testid":"loop-eff-usage",className:"mt-1 text-[11px] font-mono text-fg-faint",children:t.verifiedPerUsagePct!=null?`${t.verifiedPerUsagePct} verified PRDs per 1% of weekly usage`:"weekly usage unavailable"})]})}return e.jsxs("div",{className:`${T} p-4`,"data-testid":"loop-efficiency",children:[e.jsx(R,{kicker:"06 · reliability",title:"Loop efficiency"}),i]})}const _t=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];function Bt({days:t,measure:s}){const{buckets:n,weekendShare:r,peakIdx:o}=x.useMemo(()=>{const a=new Array(7).fill(0);for(const l of t){const[p,m,v]=l.date.split("-").map(Number),k=new Date(p,m-1,v).getDay();a[k]+=$(l.totals,s)}const c=a.reduce((l,p)=>l+p,0),u=a[0]+a[6];let d=0;for(let l=1;l<7;l++)a[l]>a[d]&&(d=l);return{buckets:a,weekendShare:c>0?u/c*100:0,peakIdx:d}},[t,s]),i=Math.max(...n,1);return e.jsxs("div",{className:`${T} p-4`,children:[e.jsx(R,{kicker:"05 · composition",title:"Rhythm",right:e.jsxs("span",{className:"text-xs font-mono text-fg-faint",children:["weekend ",r.toFixed(0),"%"]})}),e.jsx("div",{className:"flex items-end gap-2 h-24",children:n.map((a,c)=>e.jsxs("div",{className:"flex-1 flex flex-col items-center justify-end gap-1 h-full",children:[e.jsx("div",{className:`w-full rounded-t ${c===o?"bg-accent":"bg-rhythm"}`,style:{height:`${i>0?a/i*100:0}%`,minHeight:a>0?2:0}}),e.jsx("span",{className:"text-[9px] text-fg-faint font-mono",children:_t[c]})]},c))})]})}const Ht=["in","out","total","prompts","sessions","time","spend"],Lt=[30,60,90,0],Ot="spend",It=30,Wt=3e4,Kt=[];function Gt(){var ke;const[t,s]=x.useState(Ot),[n,r]=x.useState(It),o=x.useRef(!1),i=x.useRef(!1),a=f=>{o.current=!0;const b=t;s(f),ue({measure:f}).catch(()=>{s(b),q.error("Couldn't save the measure preference — reverted.")})},c=f=>{i.current=!0;const b=n;r(f),ue({range:f}).catch(()=>{r(b),q.error("Couldn't save the range preference — reverted.")})};x.useEffect(()=>{let f=!1;return pe().then(b=>{f||(!o.current&&b.measure&&Ht.includes(b.measure)&&s(b.measure),!i.current&&b.range!==void 0&&Lt.includes(b.range)&&r(b.range))}),()=>{f=!0}},[]);const u=Ye(f=>f.navFace),d=ye(f=>f.tabs),l=ye(f=>f.activeTabId),p=((ke=d.find(f=>f.id===l))==null?void 0:ke.cwd)??null,m=x.useRef(u),v=p?Xe(p):null,[k,M]=x.useState(null),h=x.useMemo(()=>u==="project"&&v?new Set([v]):k,[u,v,k]),[g,D]=x.useState(null),[j,Z]=x.useState(null),[K,W]=x.useState(!0),[ee,te]=x.useState(0),se=x.useRef(n);se.current=n;const G=x.useRef(!0),ne=x.useRef(0),he=x.useRef(0),F=x.useRef(null),z=x.useCallback(f=>{const b=se.current;ne.current+=1,he.current=Date.now(),Ze(b).then(y=>{if(ne.current-=1,!(!G.current||b!==se.current)){if(W(!1),y.ok){Z(y.data);return}f||q.error(`History analytics failed to load: ${y.error}`)}})},[]);x.useEffect(()=>{G.current=!0,W(!0),z(!1)},[n,ee,z]),x.useEffect(()=>{const f=()=>{if(!G.current)return;const N=he.current+Wt-Date.now();if(ne.current===0&&N<=0){z(!0);return}F.current||(F.current=setTimeout(()=>{F.current=null,f()},Math.max(N,1e3)))},b=()=>{document.visibilityState==="visible"&&f()},y=window.api.history.onUpdated(f);return window.addEventListener("focus",f),document.addEventListener("visibilitychange",b),()=>{G.current=!1,y(),window.removeEventListener("focus",f),document.removeEventListener("visibilitychange",b),F.current&&(clearTimeout(F.current),F.current=null)}},[z]);const me=x.useRef(!1);x.useEffect(()=>{if(!me.current){me.current=!0;return}M(null),D(null)},[n]),x.useEffect(()=>{m.current!==u&&(m.current=u,u==="home"&&M(null))},[u]);const{projects:je,resolving:ge}=qe(),be=x.useMemo(()=>{const f={};for(const b of je)for(const y of b.encodedIds)f[y]=b.cwd;return f},[je]),_=x.useMemo(()=>j&&!ge?ft(j.days,be):null,[j,be,ge]),w=(_==null?void 0:_.days)??(j==null?void 0:j.days)??Kt,oe=(_==null?void 0:_.excluded)??null,S=x.useMemo(()=>j?tt({days:w,totals:j.totals,prevTotals:j.prevTotals},h):null,[j,w,h]),B=x.useMemo(()=>h===null?w:w.map(f=>({date:f.date,byProject:Object.fromEntries(Object.entries(f.byProject).filter(([b])=>h.has(b)))})),[w,h]),V=x.useMemo(()=>Te(w,t),[w,t]),ae=x.useMemo(()=>Te(B,t),[B,t]),Ae=x.useMemo(()=>B.map(f=>({date:f.date,values:Object.fromEntries(Object.entries(f.byProject).map(([b,y])=>[b,$(y,t)]))})),[B,t]),ve=x.useMemo(()=>S?at(S,t):null,[S,t]),Y=x.useMemo(()=>{if(!j||!g)return null;const f=w.flatMap(C=>C.byProject[g]?[C.byProject[g]]:[]),{byModel:b,...y}=Ne(f),N={};for(const C of f)for(const[U,re]of Object.entries(C.toolBreakdown))N[U]=(N[U]??0)+re;return{totals:y,byModel:b,toolBreakdown:N}},[j,w,g]);x.useEffect(()=>{g&&h!==null&&!h.has(g)&&D(null)},[g,h]);function Fe(f){M(b=>{const y=new Set(V.map(U=>U.projectDir)),N=b??new Set(y),C=new Set(N);return C.has(f)?C.delete(f):C.add(f),C.size>=y.size?null:C})}function _e(f){M(new Set([f]))}function Be(){M(null)}function He(){if(!j)return;const f=B.map(U=>{const{byModel:re,estimatedCostUsd:Le,inputTokens:Oe,outputTokens:Ie,cacheCreationTokens:We,cacheReadTokens:Ke}=Ne(Object.values(U.byProject));return{date:U.date,costUsd:Le,inputTokens:Oe,outputTokens:Ie,cacheCreationTokens:We,cacheReadTokens:Ke,byModel:re}}),b=it(f),y=new Blob([b],{type:"text/csv"}),N=URL.createObjectURL(y),C=document.createElement("a");C.href=N,C.download=`usage-history-${j.from}-${j.to}.csv`,C.click(),URL.revokeObjectURL(N)}return K&&!j?e.jsx($e,{}):j&&j.days.length===0?e.jsx(Je,{title:"no sessions in range",hint:"Widen the range or check back after your next session."}):!j||!S||!ve?e.jsx($e,{}):e.jsxs("div",{"data-testid":"history-dashboard",className:"flex flex-col h-full",children:[e.jsxs("h1",{className:"font-serif text-[42px] leading-tight tracking-tight text-fg px-4 pt-4",children:["Where your ",e.jsx("em",{className:"italic text-accent",children:"Claude time"})," goes"]}),e.jsx(jt,{measure:t,onMeasure:a,range:n,onRange:c,projectsShown:h===null?V.length:h.size,projectsTotal:V.length,fromDate:j.from,toDate:j.to,onRefresh:()=>te(f=>f+1),onExport:He,exportDisabled:B.length===0}),e.jsxs("div",{className:"flex-1 min-h-0 overflow-auto p-4 space-y-4",children:[e.jsx(vt,{measure:t,headline:ve,activeDays:S.activeDays,projectsTouched:ae.length,totalSessions:S.totals.sessionCount}),e.jsx(Ct,{days:w}),oe&&xt(oe)&&e.jsx("div",{"data-testid":"history-excluded-note",className:"rounded-[10px] border border-line bg-bg-hi px-3 py-2 text-[11.5px] font-mono text-fg-faint",title:"A project is a working directory. ~/.claude/projects holds one folder per path the CLI was ever launched from — throwaway /tmp dirs and test fixtures included — and a folder whose cwd can't be recovered from its transcripts is not a project. Their totals are stated here rather than silently folded into the charts.",children:pt(oe)}),u==="home"&&e.jsx(Nt,{chips:V.map(f=>({projectDir:f.projectDir,value:f.value})),keep:h,onToggle:Fe,onIsolate:_e,onShowAll:Be}),e.jsx(Mt,{days:Ae,measure:t,selected:g,onSelect:D}),e.jsx(St,{rows:ae,measure:t,selected:g,onSelect:D}),g&&Y&&e.jsx($t,{projectDir:g,totals:Y.totals,byModel:Y.byModel,toolBreakdown:Y.toolBreakdown,onClear:()=>D(null)}),e.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-4",children:[e.jsx(Et,{byModelTotals:S.byModelTotals}),e.jsx(Dt,{rows:ae}),e.jsx(Ut,{totals:S.totals}),e.jsx(Bt,{days:S.days,measure:t})]}),e.jsx(Ft,{})]})]})}function $e(){return e.jsxs("div",{className:"p-4 space-y-4 animate-pulse",children:[e.jsx("div",{className:"h-24 bg-bg-elev rounded"}),e.jsx("div",{className:"h-16 bg-bg-elev rounded"}),e.jsx("div",{className:"h-8 bg-bg-elev rounded"}),e.jsx("div",{className:"h-56 bg-bg-elev rounded"}),e.jsx("div",{className:"h-40 bg-bg-elev rounded"})]})}function zt(){return e.jsx(Qe,{children:e.jsx(Gt,{})})}const Jt=x.memo(zt);export{Jt as History};
|