@statforge/claudestat 1.5.0 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +27 -4
  3. package/dashboard/dist/assets/{AnalyticsView-BApcOGsD.js → AnalyticsView-5bUM3UHp.js} +1 -1
  4. package/dashboard/dist/assets/{HistoryView-B331k5oL.js → HistoryView-C-AsEqos.js} +1 -1
  5. package/dashboard/dist/assets/{ProjectsView-DUleaXsP.js → ProjectsView-D9bZBdY2.js} +1 -1
  6. package/dashboard/dist/assets/{SystemView-BGe__vl1.js → SystemView-DIYDCCF3.js} +1 -1
  7. package/dashboard/dist/assets/{TopView-CXggyydU.js → TopView-DhdLpsiA.js} +1 -1
  8. package/dashboard/dist/assets/index-DgbWvj42.js +84 -0
  9. package/dashboard/dist/index.html +1 -1
  10. package/dist/daemon.js +3 -1
  11. package/dist/db.d.ts +1 -0
  12. package/dist/db.js +8 -0
  13. package/dist/enricher.js +20 -11
  14. package/dist/paths.js +1 -1
  15. package/dist/routes/events.d.ts +0 -2
  16. package/dist/routes/events.js +3 -20
  17. package/dist/routes/helpers.d.ts +2 -0
  18. package/dist/routes/helpers.js +21 -0
  19. package/dist/routes/misc.js +34 -0
  20. package/dist/routes/opencode-reader.d.ts +7 -0
  21. package/dist/routes/opencode-reader.js +129 -0
  22. package/dist/routes/projects.d.ts +0 -2
  23. package/dist/routes/projects.js +3 -17
  24. package/dist/routes/stream.js +1 -1
  25. package/dist/watch.js +0 -1
  26. package/dist/watchdog.d.ts +5 -0
  27. package/dist/watchdog.js +6 -1
  28. package/dist/watchers/adapter.d.ts +10 -0
  29. package/dist/watchers/adapter.js +4 -0
  30. package/dist/watchers/claude-code.js +9 -9
  31. package/dist/watchers/opencode.d.ts +6 -6
  32. package/dist/watchers/opencode.js +49 -9
  33. package/package.json +3 -2
  34. package/dashboard/dist/assets/index-CB01c5lb.js +0 -84
@@ -1 +1 @@
1
- import{j as e,T as r}from"./index-CB01c5lb.js";import{L as T,a as h,Z as y,B as M,a8 as v,n as O,S as E,f as L,s as S,a9 as W,Y as R,aa as $}from"./vendor-lucide-Cym0q5l_.js";import"./vendor-react-B_Jzs0gY.js";function N(t,s){return s>0?Math.round(t/s*100):0}function b(t){if(!t)return"";const s=t.match(/(?:node|python3?|bash|sh|deno|bun)\s+[~\w/.]+\/([\w.-]+)/);return s?`…/${s[1]}`:t.slice(0,50)}function f({children:t,style:s}){return e.jsx("div",{style:{background:"#161b22",border:"1px solid #21262d",borderRadius:8,padding:"14px 16px",...s},children:t})}function x({icon:t,title:s,subtitle:l,color:n="#58a6ff",open:o,onToggle:i,badge:d}){return e.jsxs("button",{onClick:i,style:{display:"flex",alignItems:"center",gap:8,width:"100%",background:"none",border:"none",cursor:"pointer",padding:0,marginBottom:o?12:0},children:[e.jsx(t,{size:13,color:n}),e.jsx("span",{style:{fontSize:12,color:"#e6edf3",fontWeight:700,flex:1,textAlign:"left"},children:s}),l&&e.jsx("span",{style:{fontSize:10,color:"#484f58"},children:l}),d,o?e.jsx(R,{size:12,color:"#484f58"}):e.jsx($,{size:12,color:"#484f58"})]})}function a({label:t,value:s,last:l=!1,color:n="#8b949e",tip:o}){const i=e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:8,paddingLeft:16,position:"relative"},children:[e.jsx("div",{style:{position:"absolute",left:0,top:0,bottom:l?"50%":0,width:1,background:"#21262d"}}),e.jsx("div",{style:{position:"absolute",left:0,top:"50%",width:10,height:1,background:"#21262d"}}),e.jsx("span",{style:{fontSize:11,color:n,fontWeight:500},children:t}),s!==void 0&&e.jsx("span",{style:{fontSize:10,color:"#484f58",marginLeft:"auto",fontVariantNumeric:"tabular-nums"},children:s})]});return o?e.jsx(r,{position:"top",align:"left",content:e.jsx("div",{style:{color:"#8b949e",fontSize:10,lineHeight:1.5},children:o}),children:i}):i}function p({text:t,color:s}){return e.jsx("span",{style:{fontSize:10,fontWeight:600,color:s,background:s+"18",border:`1px solid ${s}35`,borderRadius:4,padding:"1px 6px"},children:t})}const I={SessionStart:{label:"SessionStart",tip:"Runs when each Claude Code session starts. Loads Engram context and the project HANDOFF."},PreToolUse:{label:"PreToolUse",tip:"Runs before each tool call. claudestat uses it to check the kill-switch and record the event start."},PostToolUse:{label:"PostToolUse",tip:"Runs after each tool call with the result. claudestat sends the event to the daemon to enrich it with cost and duration."},Stop:{label:"Stop",tip:"Runs when Claude finishes responding. claudestat records the full block and emits the stop event for SSE."}};function A({hooks:t}){const[s,l]=h.useState(!0),n=Object.keys(t),o=n.length;return e.jsxs(f,{children:[e.jsx(x,{icon:y,title:"Active hooks",color:"#d29922",subtitle:o>0?void 0:"none configured",badge:o>0?e.jsx(p,{text:`${o} hooks`,color:"#d29922"}):void 0,open:s,onToggle:()=>l(i=>!i)}),s&&e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:o===0?e.jsx("span",{style:{fontSize:11,color:"#484f58"},children:"No hooks in ~/.claude/settings.json — claudestat is not active"}):n.map((i,d)=>{var m;const u=t[i],c=I[i];return e.jsx(r,{position:"bottom",align:"left",content:e.jsxs("div",{children:[e.jsx("div",{style:{color:"#d29922",fontWeight:700,fontSize:11,marginBottom:3},children:(c==null?void 0:c.label)??i}),e.jsx("div",{style:{color:"#8b949e",fontSize:10,lineHeight:1.5},children:(c==null?void 0:c.tip)??""}),u.map((w,C)=>e.jsx("div",{style:{color:"#3d444d",fontFamily:"monospace",fontSize:9,marginTop:4},children:b(w.command)},C))]}),children:e.jsx(a,{label:(c==null?void 0:c.label)??i,value:e.jsx("span",{style:{fontFamily:"monospace",color:"#3d444d"},children:b(((m=u[0])==null?void 0:m.command)??"")}),last:d===n.length-1,color:"#d29922"})},i)})})]})}function B({agents:t}){const[s,l]=h.useState(!0);return e.jsxs(f,{children:[e.jsx(x,{icon:M,title:"Available agents",color:"#bc8cff",subtitle:"~/.claude/agents/",badge:t.length>0?e.jsx(p,{text:`${t.length}`,color:"#bc8cff"}):void 0,open:s,onToggle:()=>l(n=>!n)}),s&&e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:5},children:t.length===0?e.jsx("span",{style:{fontSize:11,color:"#484f58"},children:"No agents in ~/.claude/agents/"}):t.map((n,o)=>e.jsx(r,{position:"top",align:"left",content:e.jsxs("div",{children:[e.jsx("div",{style:{color:"#bc8cff",fontWeight:700,fontSize:11,marginBottom:3},children:n.name}),e.jsx("div",{style:{color:"#8b949e",fontSize:10,lineHeight:1.5},children:n.description||"No description in the .md file frontmatter"})]}),children:e.jsx(a,{label:n.name,last:o===t.length-1,color:"#bc8cff",value:n.description?e.jsxs("span",{style:{color:"#3d444d",maxWidth:220,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",display:"inline-block"},children:[n.description.slice(0,40),n.description.length>40?"…":""]}):void 0})},n.name))})]})}const g=500;function F({skills:t}){const[s,l]=h.useState(!0),n=t.filter(o=>o.lines>=g*.9).length;return e.jsxs(f,{children:[e.jsx(x,{icon:y,title:"Available skills",color:"#3fb950",subtitle:"~/.claude/commands/",badge:t.length>0?e.jsx(p,{text:`${t.length}${n>0?` · ${n} ⚠`:""}`,color:n>0?"#d29922":"#3fb950"}):void 0,open:s,onToggle:()=>l(o=>!o)}),s&&e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:5},children:t.length===0?e.jsx("span",{style:{fontSize:11,color:"#484f58"},children:"No skills in ~/.claude/commands/"}):t.map((o,i)=>{const d=o.lines/g,u=z(d),c=d>=.7;return e.jsx(r,{position:"top",align:"left",content:e.jsxs("div",{children:[e.jsxs("div",{style:{color:"#3fb950",fontWeight:700,fontSize:11,marginBottom:3},children:["/",o.name]}),e.jsx("div",{style:{color:"#8b949e",fontSize:10,lineHeight:1.5},children:o.description||"No description in the .md file frontmatter"}),e.jsxs("div",{style:{color:u,fontSize:9,marginTop:4},children:[o.lines," lines ",c?`— recommended limit: ${g}`:`/ ${g} recommended`]})]}),children:e.jsx(a,{label:`/${o.name}`,last:i===t.length-1,color:"#3fb950",value:e.jsxs("span",{style:{color:u,fontVariantNumeric:"tabular-nums"},children:[o.lines," ln ",c?"⚠":""]})})},o.name)})})]})}function D({memoryFiles:t}){const[s,l]=h.useState(!0),n=t.length>0;return e.jsxs(f,{children:[e.jsx(x,{icon:W,title:"Memory system",color:"#58a6ff",badge:n?e.jsx(p,{text:`${t.length} files`,color:"#58a6ff"}):void 0,open:s,onToggle:()=>l(o=>!o)}),s&&e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:5},children:n?t.map((o,i)=>e.jsx(a,{label:o,last:i===t.length-1,color:o==="MEMORY.md"?"#79c0ff":"#58a6ff",tip:o==="MEMORY.md"?"Auto-loaded index — every session reads this file automatically.":`Memory file: ~/.claude/projects/…/memory/${o}`},o)):e.jsx("span",{style:{fontSize:11,color:"#484f58"},children:"Engram not detected. Optional MCP plugin for persistent memory between sessions."})})]})}function H({workflows:t}){const[s,l]=h.useState(!0);return e.jsxs(f,{children:[e.jsx(x,{icon:v,title:"Workflows / pipelines",color:"#56d364",subtitle:"~/.claude/agents/workflows/",badge:t.length>0?e.jsx(p,{text:`${t.length}`,color:"#56d364"}):void 0,open:s,onToggle:()=>l(n=>!n)}),s&&e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:5},children:t.length===0?e.jsx("span",{style:{fontSize:11,color:"#484f58"},children:"No workflows in ~/.claude/agents/workflows/"}):t.map((n,o)=>e.jsx(r,{position:"top",align:"left",content:e.jsxs("div",{children:[e.jsx("div",{style:{color:"#56d364",fontWeight:700,fontSize:11,marginBottom:3},children:n.name}),e.jsx("div",{style:{color:"#8b949e",fontSize:10,lineHeight:1.5},children:n.description||"No description in the .md file frontmatter"})]}),children:e.jsx(a,{label:n.name,last:o===t.length-1,color:"#56d364",value:n.description?e.jsxs("span",{style:{color:"#3d444d"},children:[n.description.slice(0,40),n.description.length>40?"…":""]}):void 0})},n.name))})]})}const P={"CLAUDE.md global":"Permanent instructions for Claude: profile, response style, code rules and project protocol. Loaded every session.","MEMORY.md":"Engram auto-memory index. Auto-loaded into every session via system prompt. Keep under 200 lines — content after line 200 is truncated.","settings.json":"Claude Code configuration: installed hooks, permissions, default model. claudestat needs the hooks here to work.","config claudestat":"Active claudestat configuration: plan, kill switch and quota thresholds. Read on every PreToolUse hook evaluation."},k={"CLAUDE.md global":{lines:200},"MEMORY.md":{lines:200}};function z(t){return t>=.9?"#f85149":t>=.7?"#d29922":"#3fb950"}function K(t,s,l){const n=k[l];if(!n)return null;const o=n.lines?t/n.lines:0,i=n.kb?s/n.kb:0;return z(Math.max(o,i))}function U({f:t}){if(!t.exists)return e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:3,color:"#f85149"},children:[e.jsx(S,{size:9})," not found"]});const s=K(t.lines,t.sizeKb,t.key),l=s??"#3fb950",n=k[t.key],o=n!=null&&n.lines?`${t.lines} ln / ${n.lines}`:t.sizeKb>0?`${t.sizeKb} KB`:"< 1 KB";return e.jsxs("span",{style:{color:l},children:[o," ",s?"⚠":"✓"]})}function _({files:t}){const[s,l]=h.useState(!0),n=t.filter(o=>o.exists).length;return e.jsxs(f,{children:[e.jsx(x,{icon:O,title:"Context files",color:"#3fb950",badge:e.jsx(p,{text:`${n}/${t.length}`,color:"#3fb950"}),open:s,onToggle:()=>l(o=>!o)}),s&&e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:5},children:t.map((o,i)=>e.jsx(r,{position:"top",align:"left",content:e.jsxs("div",{children:[e.jsx("div",{style:{color:"#3fb950",fontWeight:700,fontSize:11,marginBottom:3},children:o.key}),e.jsx("div",{style:{color:"#8b949e",fontSize:10,lineHeight:1.5},children:P[o.key]??"System configuration file."})]}),children:e.jsx(a,{label:o.key,last:i===t.length-1,color:o.exists?"#e6edf3":"#484f58",value:e.jsx(U,{f:o})})},o.key))})]})}const Y={free:"Free",pro:"Pro",max5:"Max 5×",max20:"Max 20×"},j=[{key:"direct",label:"Claude direct",when:"≤ 2 files, no new endpoints",color:"#3fb950",tip:"Claude works alone. Ideal for small changes: CSS, text, simple bugs. No agents or pipeline."},{key:"mini",label:"Mini-pipeline",when:"3–5 files or 1–2 new endpoints",color:"#58a6ff",tip:"3 agents: implementer → quality-docs → tester. Git is not automatic — invoke with /git when the user decides."},{key:"pipeline",label:"Full pipeline",when:"≥ 6 files or new feature",color:"#d29922",tip:"Full agent team. Scrum master, backend, frontend, quality-docs, tester. Git separate — invoke /git when you decide. For large features."}];function q({dist:t}){const[s,l]=h.useState(!0),n=t.total>0?j.reduce((o,i)=>t[i.key]>t[o.key]?i:o,j[0]):null;return e.jsxs(f,{children:[e.jsx(x,{icon:v,title:"Work modes",color:"#f0883e",subtitle:"last 7 days",badge:n&&t.total>0?e.jsx(p,{text:`most used: ${n.label}`,color:n.color}):void 0,open:s,onToggle:()=>l(o=>!o)}),s&&e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[j.map(o=>{const i=t[o.key],d=N(i,t.total);return e.jsx(r,{position:"top",align:"left",content:e.jsxs("div",{children:[e.jsx("div",{style:{color:o.color,fontWeight:700,fontSize:11,marginBottom:3},children:o.label}),e.jsxs("div",{style:{color:"#8b949e",fontSize:10,lineHeight:1.5},children:[e.jsx("span",{style:{color:"#6e7681"},children:"When: "}),o.when,e.jsx("br",{}),o.tip]})]}),children:e.jsxs("div",{style:{cursor:"help"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:4},children:[e.jsx("span",{style:{fontSize:11,color:o.color,fontWeight:600,width:130,flexShrink:0},children:o.label}),e.jsx("span",{style:{fontSize:10,color:"#484f58",flex:1},children:o.when}),e.jsx("span",{style:{fontSize:11,color:"#e6edf3",fontVariantNumeric:"tabular-nums",fontWeight:600},children:t.total>0?`${i} (${d}%)`:"—"})]}),e.jsx("div",{style:{height:4,background:"#21262d",borderRadius:2,overflow:"hidden"},children:e.jsx("div",{style:{width:`${d}%`,height:"100%",background:o.color,borderRadius:2,transition:"width 0.5s"}})})]})},o.key)}),t.total===0&&e.jsx("span",{style:{fontSize:11,color:"#484f58"},children:"No sessions recorded in the last 7 days"}),t.total>0&&e.jsxs("div",{style:{fontSize:9,color:"#3d444d",marginTop:2},children:[t.total," sessions analyzed · Mode inferred by number of Agent tool calls per session"]})]})]})}function V({cfg:t}){const[s,l]=h.useState(!0),n=t.plan??"pro",o=t.killSwitchEnabled??!0,[i,d,u]=t.warnThresholds??[70,85,95];return e.jsxs(f,{children:[e.jsx(x,{icon:E,title:"claudestat config",color:"#8b949e",subtitle:"~/.claudestat/config.json",open:s,onToggle:()=>l(c=>!c)}),s&&e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:5},children:[e.jsx(a,{label:"Plan",value:e.jsx(p,{text:Y[n]??n,color:"#58a6ff"}),tip:"Claude Max plan that determines weekly hour limits per model."}),e.jsx(r,{position:"top",align:"left",content:e.jsxs("div",{children:[e.jsxs("div",{style:{color:o?"#3fb950":"#f85149",fontWeight:700,fontSize:11,marginBottom:3},children:["Kill switch ",o?"enabled":"disabled"]}),e.jsxs("div",{style:{color:"#8b949e",fontSize:10,lineHeight:1.5},children:["When ON, blocks new tool calls if the 5h quota exceeds the red threshold.",e.jsx("br",{}),"Configure with: ",e.jsx("code",{style:{color:"#d29922"},children:"claudestat config"})]})]}),children:e.jsx(a,{label:"Kill switch",value:e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4,color:o?"#3fb950":"#f85149"},children:[o?e.jsx(L,{size:10}):e.jsx(S,{size:10}),o?"ON":"OFF"]}),color:o?"#3fb950":"#f85149"})}),e.jsx(r,{position:"top",align:"left",content:e.jsxs("div",{children:[e.jsx("div",{style:{color:"#58a6ff",fontWeight:700,fontSize:11,marginBottom:3},children:"Quota alert thresholds"}),e.jsxs("div",{style:{color:"#8b949e",fontSize:10,lineHeight:1.5},children:["Percentage of the 5h quota that triggers each SSE alert level.",e.jsx("br",{}),"🟡 warning → 🟠 orange → 🔴 red (kill switch)"]})]}),children:e.jsx(a,{label:"Thresholds",last:!0,value:e.jsxs("span",{style:{display:"inline-flex",gap:6},children:[e.jsxs("span",{style:{color:"#d29922"},children:[i,"%"]}),e.jsxs("span",{style:{color:"#f0883e"},children:[d,"%"]}),e.jsxs("span",{style:{color:"#f85149"},children:[u,"%"]})]})})})]})]})}function Q({config:t,error:s,onRetry:l}){return t?e.jsxs("div",{style:{height:"100%",overflow:"auto",padding:"16px 20px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,marginBottom:16},children:[e.jsx(T,{size:16,color:"#58a6ff"}),e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:14,fontWeight:700,color:"#e6edf3"},children:"System map"}),e.jsx("div",{style:{fontSize:11,color:"#484f58"},children:"How Claude Code is configured on this machine"})]}),e.jsxs("div",{style:{marginLeft:"auto",display:"flex",gap:8,alignItems:"center"},children:[e.jsx(r,{position:"bottom",align:"right",content:e.jsx("div",{style:{color:"#8b949e",fontSize:10},children:"Active Claude Code hooks in settings.json"}),children:e.jsxs("span",{style:{fontSize:10,color:"#d29922",background:"#d2992215",border:"1px solid #d2992235",borderRadius:4,padding:"2px 7px",cursor:"help"},children:[Object.keys(t.hooks).length," hooks"]})}),e.jsx(r,{position:"bottom",align:"right",content:e.jsx("div",{style:{color:"#8b949e",fontSize:10},children:"Available agents in ~/.claude/agents/"}),children:e.jsxs("span",{style:{fontSize:10,color:"#bc8cff",background:"#bc8cff15",border:"1px solid #bc8cff35",borderRadius:4,padding:"2px 7px",cursor:"help"},children:[t.agents.length," agents"]})}),e.jsx(r,{position:"bottom",align:"right",content:e.jsx("div",{style:{color:"#8b949e",fontSize:10},children:"Workflows in ~/.claude/agents/workflows/"}),children:e.jsxs("span",{style:{fontSize:10,color:"#56d364",background:"#56d36415",border:"1px solid #56d36435",borderRadius:4,padding:"2px 7px",cursor:"help"},children:[t.workflows.length," workflows"]})}),e.jsx(r,{position:"bottom",align:"right",content:e.jsx("div",{style:{color:"#8b949e",fontSize:10},children:"Skills in ~/.claude/commands/"}),children:e.jsxs("span",{style:{fontSize:10,color:"#3fb950",background:"#3fb95015",border:"1px solid #3fb95035",borderRadius:4,padding:"2px 7px",cursor:"help"},children:[t.skills.length," skills"]})}),e.jsx(r,{position:"bottom",align:"right",content:e.jsx("div",{style:{color:"#8b949e",fontSize:10},children:"Memory files in Engram"}),children:e.jsxs("span",{style:{fontSize:10,color:"#58a6ff",background:"#58a6ff15",border:"1px solid #58a6ff35",borderRadius:4,padding:"2px 7px",cursor:"help"},children:[t.memoryFiles.length," memories"]})}),l&&e.jsx(r,{position:"bottom",align:"right",content:e.jsx("div",{style:{color:"#8b949e",fontSize:10},children:"Refresh system configuration"}),children:e.jsx("button",{onClick:l,style:{background:"none",border:"1px solid #30363d",borderRadius:4,padding:"2px 7px",cursor:"pointer",color:"#6e7681",fontSize:12,lineHeight:1,transition:"color 0.15s, border-color 0.15s"},onMouseEnter:n=>{n.currentTarget.style.color="#e6edf3",n.currentTarget.style.borderColor="#6e7681"},onMouseLeave:n=>{n.currentTarget.style.color="#6e7681",n.currentTarget.style.borderColor="#30363d"},children:"↺"})})]})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:12,maxWidth:1200,margin:"0 auto"},children:[e.jsx(F,{skills:t.skills}),e.jsx(B,{agents:t.agents}),e.jsx("div",{style:{gridColumn:"1 / -1"},children:e.jsx(H,{workflows:t.workflows??[]})}),e.jsx(q,{dist:t.modeDistribution}),e.jsx(A,{hooks:t.hooks}),e.jsx(_,{files:t.contextFiles}),e.jsx(V,{cfg:t.claudestatConfig}),e.jsx("div",{style:{gridColumn:"1 / -1"},children:e.jsx(D,{memoryFiles:t.memoryFiles})})]})]}):e.jsx("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",height:"100%",gap:12},children:s?e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{color:"#f85149",fontSize:13},children:"Error loading system configuration"}),l&&e.jsx("button",{onClick:l,style:{padding:"5px 14px",fontSize:12,fontWeight:600,cursor:"pointer",background:"none",border:"1px solid #f8514966",borderRadius:5,color:"#f85149",transition:"background 0.15s"},children:"Retry"})]}):e.jsx("span",{style:{color:"#6e7681",fontSize:13},children:"Loading system configuration…"})})}export{Q as SystemView};
1
+ import{j as e,T as r}from"./index-DgbWvj42.js";import{L as T,a as h,Z as y,B as M,a8 as v,n as O,S as E,f as L,s as S,a9 as W,Y as R,aa as $}from"./vendor-lucide-Cym0q5l_.js";import"./vendor-react-B_Jzs0gY.js";function N(t,s){return s>0?Math.round(t/s*100):0}function b(t){if(!t)return"";const s=t.match(/(?:node|python3?|bash|sh|deno|bun)\s+[~\w/.]+\/([\w.-]+)/);return s?`…/${s[1]}`:t.slice(0,50)}function f({children:t,style:s}){return e.jsx("div",{style:{background:"#161b22",border:"1px solid #21262d",borderRadius:8,padding:"14px 16px",...s},children:t})}function x({icon:t,title:s,subtitle:l,color:n="#58a6ff",open:o,onToggle:i,badge:d}){return e.jsxs("button",{onClick:i,style:{display:"flex",alignItems:"center",gap:8,width:"100%",background:"none",border:"none",cursor:"pointer",padding:0,marginBottom:o?12:0},children:[e.jsx(t,{size:13,color:n}),e.jsx("span",{style:{fontSize:12,color:"#e6edf3",fontWeight:700,flex:1,textAlign:"left"},children:s}),l&&e.jsx("span",{style:{fontSize:10,color:"#484f58"},children:l}),d,o?e.jsx(R,{size:12,color:"#484f58"}):e.jsx($,{size:12,color:"#484f58"})]})}function a({label:t,value:s,last:l=!1,color:n="#8b949e",tip:o}){const i=e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:8,paddingLeft:16,position:"relative"},children:[e.jsx("div",{style:{position:"absolute",left:0,top:0,bottom:l?"50%":0,width:1,background:"#21262d"}}),e.jsx("div",{style:{position:"absolute",left:0,top:"50%",width:10,height:1,background:"#21262d"}}),e.jsx("span",{style:{fontSize:11,color:n,fontWeight:500},children:t}),s!==void 0&&e.jsx("span",{style:{fontSize:10,color:"#484f58",marginLeft:"auto",fontVariantNumeric:"tabular-nums"},children:s})]});return o?e.jsx(r,{position:"top",align:"left",content:e.jsx("div",{style:{color:"#8b949e",fontSize:10,lineHeight:1.5},children:o}),children:i}):i}function p({text:t,color:s}){return e.jsx("span",{style:{fontSize:10,fontWeight:600,color:s,background:s+"18",border:`1px solid ${s}35`,borderRadius:4,padding:"1px 6px"},children:t})}const I={SessionStart:{label:"SessionStart",tip:"Runs when each Claude Code session starts. Loads Engram context and the project HANDOFF."},PreToolUse:{label:"PreToolUse",tip:"Runs before each tool call. claudestat uses it to check the kill-switch and record the event start."},PostToolUse:{label:"PostToolUse",tip:"Runs after each tool call with the result. claudestat sends the event to the daemon to enrich it with cost and duration."},Stop:{label:"Stop",tip:"Runs when Claude finishes responding. claudestat records the full block and emits the stop event for SSE."}};function A({hooks:t}){const[s,l]=h.useState(!0),n=Object.keys(t),o=n.length;return e.jsxs(f,{children:[e.jsx(x,{icon:y,title:"Active hooks",color:"#d29922",subtitle:o>0?void 0:"none configured",badge:o>0?e.jsx(p,{text:`${o} hooks`,color:"#d29922"}):void 0,open:s,onToggle:()=>l(i=>!i)}),s&&e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:o===0?e.jsx("span",{style:{fontSize:11,color:"#484f58"},children:"No hooks in ~/.claude/settings.json — claudestat is not active"}):n.map((i,d)=>{var m;const u=t[i],c=I[i];return e.jsx(r,{position:"bottom",align:"left",content:e.jsxs("div",{children:[e.jsx("div",{style:{color:"#d29922",fontWeight:700,fontSize:11,marginBottom:3},children:(c==null?void 0:c.label)??i}),e.jsx("div",{style:{color:"#8b949e",fontSize:10,lineHeight:1.5},children:(c==null?void 0:c.tip)??""}),u.map((w,C)=>e.jsx("div",{style:{color:"#3d444d",fontFamily:"monospace",fontSize:9,marginTop:4},children:b(w.command)},C))]}),children:e.jsx(a,{label:(c==null?void 0:c.label)??i,value:e.jsx("span",{style:{fontFamily:"monospace",color:"#3d444d"},children:b(((m=u[0])==null?void 0:m.command)??"")}),last:d===n.length-1,color:"#d29922"})},i)})})]})}function B({agents:t}){const[s,l]=h.useState(!0);return e.jsxs(f,{children:[e.jsx(x,{icon:M,title:"Available agents",color:"#bc8cff",subtitle:"~/.claude/agents/",badge:t.length>0?e.jsx(p,{text:`${t.length}`,color:"#bc8cff"}):void 0,open:s,onToggle:()=>l(n=>!n)}),s&&e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:5},children:t.length===0?e.jsx("span",{style:{fontSize:11,color:"#484f58"},children:"No agents in ~/.claude/agents/"}):t.map((n,o)=>e.jsx(r,{position:"top",align:"left",content:e.jsxs("div",{children:[e.jsx("div",{style:{color:"#bc8cff",fontWeight:700,fontSize:11,marginBottom:3},children:n.name}),e.jsx("div",{style:{color:"#8b949e",fontSize:10,lineHeight:1.5},children:n.description||"No description in the .md file frontmatter"})]}),children:e.jsx(a,{label:n.name,last:o===t.length-1,color:"#bc8cff",value:n.description?e.jsxs("span",{style:{color:"#3d444d",maxWidth:220,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",display:"inline-block"},children:[n.description.slice(0,40),n.description.length>40?"…":""]}):void 0})},n.name))})]})}const g=500;function F({skills:t}){const[s,l]=h.useState(!0),n=t.filter(o=>o.lines>=g*.9).length;return e.jsxs(f,{children:[e.jsx(x,{icon:y,title:"Available skills",color:"#3fb950",subtitle:"~/.claude/commands/",badge:t.length>0?e.jsx(p,{text:`${t.length}${n>0?` · ${n} ⚠`:""}`,color:n>0?"#d29922":"#3fb950"}):void 0,open:s,onToggle:()=>l(o=>!o)}),s&&e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:5},children:t.length===0?e.jsx("span",{style:{fontSize:11,color:"#484f58"},children:"No skills in ~/.claude/commands/"}):t.map((o,i)=>{const d=o.lines/g,u=z(d),c=d>=.7;return e.jsx(r,{position:"top",align:"left",content:e.jsxs("div",{children:[e.jsxs("div",{style:{color:"#3fb950",fontWeight:700,fontSize:11,marginBottom:3},children:["/",o.name]}),e.jsx("div",{style:{color:"#8b949e",fontSize:10,lineHeight:1.5},children:o.description||"No description in the .md file frontmatter"}),e.jsxs("div",{style:{color:u,fontSize:9,marginTop:4},children:[o.lines," lines ",c?`— recommended limit: ${g}`:`/ ${g} recommended`]})]}),children:e.jsx(a,{label:`/${o.name}`,last:i===t.length-1,color:"#3fb950",value:e.jsxs("span",{style:{color:u,fontVariantNumeric:"tabular-nums"},children:[o.lines," ln ",c?"⚠":""]})})},o.name)})})]})}function D({memoryFiles:t}){const[s,l]=h.useState(!0),n=t.length>0;return e.jsxs(f,{children:[e.jsx(x,{icon:W,title:"Memory system",color:"#58a6ff",badge:n?e.jsx(p,{text:`${t.length} files`,color:"#58a6ff"}):void 0,open:s,onToggle:()=>l(o=>!o)}),s&&e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:5},children:n?t.map((o,i)=>e.jsx(a,{label:o,last:i===t.length-1,color:o==="MEMORY.md"?"#79c0ff":"#58a6ff",tip:o==="MEMORY.md"?"Auto-loaded index — every session reads this file automatically.":`Memory file: ~/.claude/projects/…/memory/${o}`},o)):e.jsx("span",{style:{fontSize:11,color:"#484f58"},children:"Engram not detected. Optional MCP plugin for persistent memory between sessions."})})]})}function H({workflows:t}){const[s,l]=h.useState(!0);return e.jsxs(f,{children:[e.jsx(x,{icon:v,title:"Workflows / pipelines",color:"#56d364",subtitle:"~/.claude/agents/workflows/",badge:t.length>0?e.jsx(p,{text:`${t.length}`,color:"#56d364"}):void 0,open:s,onToggle:()=>l(n=>!n)}),s&&e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:5},children:t.length===0?e.jsx("span",{style:{fontSize:11,color:"#484f58"},children:"No workflows in ~/.claude/agents/workflows/"}):t.map((n,o)=>e.jsx(r,{position:"top",align:"left",content:e.jsxs("div",{children:[e.jsx("div",{style:{color:"#56d364",fontWeight:700,fontSize:11,marginBottom:3},children:n.name}),e.jsx("div",{style:{color:"#8b949e",fontSize:10,lineHeight:1.5},children:n.description||"No description in the .md file frontmatter"})]}),children:e.jsx(a,{label:n.name,last:o===t.length-1,color:"#56d364",value:n.description?e.jsxs("span",{style:{color:"#3d444d"},children:[n.description.slice(0,40),n.description.length>40?"…":""]}):void 0})},n.name))})]})}const P={"CLAUDE.md global":"Permanent instructions for Claude: profile, response style, code rules and project protocol. Loaded every session.","MEMORY.md":"Engram auto-memory index. Auto-loaded into every session via system prompt. Keep under 200 lines — content after line 200 is truncated.","settings.json":"Claude Code configuration: installed hooks, permissions, default model. claudestat needs the hooks here to work.","config claudestat":"Active claudestat configuration: plan, kill switch and quota thresholds. Read on every PreToolUse hook evaluation."},k={"CLAUDE.md global":{lines:200},"MEMORY.md":{lines:200}};function z(t){return t>=.9?"#f85149":t>=.7?"#d29922":"#3fb950"}function K(t,s,l){const n=k[l];if(!n)return null;const o=n.lines?t/n.lines:0,i=n.kb?s/n.kb:0;return z(Math.max(o,i))}function U({f:t}){if(!t.exists)return e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:3,color:"#f85149"},children:[e.jsx(S,{size:9})," not found"]});const s=K(t.lines,t.sizeKb,t.key),l=s??"#3fb950",n=k[t.key],o=n!=null&&n.lines?`${t.lines} ln / ${n.lines}`:t.sizeKb>0?`${t.sizeKb} KB`:"< 1 KB";return e.jsxs("span",{style:{color:l},children:[o," ",s?"⚠":"✓"]})}function _({files:t}){const[s,l]=h.useState(!0),n=t.filter(o=>o.exists).length;return e.jsxs(f,{children:[e.jsx(x,{icon:O,title:"Context files",color:"#3fb950",badge:e.jsx(p,{text:`${n}/${t.length}`,color:"#3fb950"}),open:s,onToggle:()=>l(o=>!o)}),s&&e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:5},children:t.map((o,i)=>e.jsx(r,{position:"top",align:"left",content:e.jsxs("div",{children:[e.jsx("div",{style:{color:"#3fb950",fontWeight:700,fontSize:11,marginBottom:3},children:o.key}),e.jsx("div",{style:{color:"#8b949e",fontSize:10,lineHeight:1.5},children:P[o.key]??"System configuration file."})]}),children:e.jsx(a,{label:o.key,last:i===t.length-1,color:o.exists?"#e6edf3":"#484f58",value:e.jsx(U,{f:o})})},o.key))})]})}const Y={free:"Free",pro:"Pro",max5:"Max 5×",max20:"Max 20×"},j=[{key:"direct",label:"Claude direct",when:"≤ 2 files, no new endpoints",color:"#3fb950",tip:"Claude works alone. Ideal for small changes: CSS, text, simple bugs. No agents or pipeline."},{key:"mini",label:"Mini-pipeline",when:"3–5 files or 1–2 new endpoints",color:"#58a6ff",tip:"3 agents: implementer → quality-docs → tester. Git is not automatic — invoke with /git when the user decides."},{key:"pipeline",label:"Full pipeline",when:"≥ 6 files or new feature",color:"#d29922",tip:"Full agent team. Scrum master, backend, frontend, quality-docs, tester. Git separate — invoke /git when you decide. For large features."}];function q({dist:t}){const[s,l]=h.useState(!0),n=t.total>0?j.reduce((o,i)=>t[i.key]>t[o.key]?i:o,j[0]):null;return e.jsxs(f,{children:[e.jsx(x,{icon:v,title:"Work modes",color:"#f0883e",subtitle:"last 7 days",badge:n&&t.total>0?e.jsx(p,{text:`most used: ${n.label}`,color:n.color}):void 0,open:s,onToggle:()=>l(o=>!o)}),s&&e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[j.map(o=>{const i=t[o.key],d=N(i,t.total);return e.jsx(r,{position:"top",align:"left",content:e.jsxs("div",{children:[e.jsx("div",{style:{color:o.color,fontWeight:700,fontSize:11,marginBottom:3},children:o.label}),e.jsxs("div",{style:{color:"#8b949e",fontSize:10,lineHeight:1.5},children:[e.jsx("span",{style:{color:"#6e7681"},children:"When: "}),o.when,e.jsx("br",{}),o.tip]})]}),children:e.jsxs("div",{style:{cursor:"help"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:4},children:[e.jsx("span",{style:{fontSize:11,color:o.color,fontWeight:600,width:130,flexShrink:0},children:o.label}),e.jsx("span",{style:{fontSize:10,color:"#484f58",flex:1},children:o.when}),e.jsx("span",{style:{fontSize:11,color:"#e6edf3",fontVariantNumeric:"tabular-nums",fontWeight:600},children:t.total>0?`${i} (${d}%)`:"—"})]}),e.jsx("div",{style:{height:4,background:"#21262d",borderRadius:2,overflow:"hidden"},children:e.jsx("div",{style:{width:`${d}%`,height:"100%",background:o.color,borderRadius:2,transition:"width 0.5s"}})})]})},o.key)}),t.total===0&&e.jsx("span",{style:{fontSize:11,color:"#484f58"},children:"No sessions recorded in the last 7 days"}),t.total>0&&e.jsxs("div",{style:{fontSize:9,color:"#3d444d",marginTop:2},children:[t.total," sessions analyzed · Mode inferred by number of Agent tool calls per session"]})]})]})}function V({cfg:t}){const[s,l]=h.useState(!0),n=t.plan??"pro",o=t.killSwitchEnabled??!0,[i,d,u]=t.warnThresholds??[70,85,95];return e.jsxs(f,{children:[e.jsx(x,{icon:E,title:"claudestat config",color:"#8b949e",subtitle:"~/.claudestat/config.json",open:s,onToggle:()=>l(c=>!c)}),s&&e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:5},children:[e.jsx(a,{label:"Plan",value:e.jsx(p,{text:Y[n]??n,color:"#58a6ff"}),tip:"Claude Max plan that determines weekly hour limits per model."}),e.jsx(r,{position:"top",align:"left",content:e.jsxs("div",{children:[e.jsxs("div",{style:{color:o?"#3fb950":"#f85149",fontWeight:700,fontSize:11,marginBottom:3},children:["Kill switch ",o?"enabled":"disabled"]}),e.jsxs("div",{style:{color:"#8b949e",fontSize:10,lineHeight:1.5},children:["When ON, blocks new tool calls if the 5h quota exceeds the red threshold.",e.jsx("br",{}),"Configure with: ",e.jsx("code",{style:{color:"#d29922"},children:"claudestat config"})]})]}),children:e.jsx(a,{label:"Kill switch",value:e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4,color:o?"#3fb950":"#f85149"},children:[o?e.jsx(L,{size:10}):e.jsx(S,{size:10}),o?"ON":"OFF"]}),color:o?"#3fb950":"#f85149"})}),e.jsx(r,{position:"top",align:"left",content:e.jsxs("div",{children:[e.jsx("div",{style:{color:"#58a6ff",fontWeight:700,fontSize:11,marginBottom:3},children:"Quota alert thresholds"}),e.jsxs("div",{style:{color:"#8b949e",fontSize:10,lineHeight:1.5},children:["Percentage of the 5h quota that triggers each SSE alert level.",e.jsx("br",{}),"🟡 warning → 🟠 orange → 🔴 red (kill switch)"]})]}),children:e.jsx(a,{label:"Thresholds",last:!0,value:e.jsxs("span",{style:{display:"inline-flex",gap:6},children:[e.jsxs("span",{style:{color:"#d29922"},children:[i,"%"]}),e.jsxs("span",{style:{color:"#f0883e"},children:[d,"%"]}),e.jsxs("span",{style:{color:"#f85149"},children:[u,"%"]})]})})})]})]})}function Q({config:t,error:s,onRetry:l}){return t?e.jsxs("div",{style:{height:"100%",overflow:"auto",padding:"16px 20px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,marginBottom:16},children:[e.jsx(T,{size:16,color:"#58a6ff"}),e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:14,fontWeight:700,color:"#e6edf3"},children:"System map"}),e.jsx("div",{style:{fontSize:11,color:"#484f58"},children:"How Claude Code is configured on this machine"})]}),e.jsxs("div",{style:{marginLeft:"auto",display:"flex",gap:8,alignItems:"center"},children:[e.jsx(r,{position:"bottom",align:"right",content:e.jsx("div",{style:{color:"#8b949e",fontSize:10},children:"Active Claude Code hooks in settings.json"}),children:e.jsxs("span",{style:{fontSize:10,color:"#d29922",background:"#d2992215",border:"1px solid #d2992235",borderRadius:4,padding:"2px 7px",cursor:"help"},children:[Object.keys(t.hooks).length," hooks"]})}),e.jsx(r,{position:"bottom",align:"right",content:e.jsx("div",{style:{color:"#8b949e",fontSize:10},children:"Available agents in ~/.claude/agents/"}),children:e.jsxs("span",{style:{fontSize:10,color:"#bc8cff",background:"#bc8cff15",border:"1px solid #bc8cff35",borderRadius:4,padding:"2px 7px",cursor:"help"},children:[t.agents.length," agents"]})}),e.jsx(r,{position:"bottom",align:"right",content:e.jsx("div",{style:{color:"#8b949e",fontSize:10},children:"Workflows in ~/.claude/agents/workflows/"}),children:e.jsxs("span",{style:{fontSize:10,color:"#56d364",background:"#56d36415",border:"1px solid #56d36435",borderRadius:4,padding:"2px 7px",cursor:"help"},children:[t.workflows.length," workflows"]})}),e.jsx(r,{position:"bottom",align:"right",content:e.jsx("div",{style:{color:"#8b949e",fontSize:10},children:"Skills in ~/.claude/commands/"}),children:e.jsxs("span",{style:{fontSize:10,color:"#3fb950",background:"#3fb95015",border:"1px solid #3fb95035",borderRadius:4,padding:"2px 7px",cursor:"help"},children:[t.skills.length," skills"]})}),e.jsx(r,{position:"bottom",align:"right",content:e.jsx("div",{style:{color:"#8b949e",fontSize:10},children:"Memory files in Engram"}),children:e.jsxs("span",{style:{fontSize:10,color:"#58a6ff",background:"#58a6ff15",border:"1px solid #58a6ff35",borderRadius:4,padding:"2px 7px",cursor:"help"},children:[t.memoryFiles.length," memories"]})}),l&&e.jsx(r,{position:"bottom",align:"right",content:e.jsx("div",{style:{color:"#8b949e",fontSize:10},children:"Refresh system configuration"}),children:e.jsx("button",{onClick:l,style:{background:"none",border:"1px solid #30363d",borderRadius:4,padding:"2px 7px",cursor:"pointer",color:"#6e7681",fontSize:12,lineHeight:1,transition:"color 0.15s, border-color 0.15s"},onMouseEnter:n=>{n.currentTarget.style.color="#e6edf3",n.currentTarget.style.borderColor="#6e7681"},onMouseLeave:n=>{n.currentTarget.style.color="#6e7681",n.currentTarget.style.borderColor="#30363d"},children:"↺"})})]})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:12,maxWidth:1200,margin:"0 auto"},children:[e.jsx(F,{skills:t.skills}),e.jsx(B,{agents:t.agents}),e.jsx("div",{style:{gridColumn:"1 / -1"},children:e.jsx(H,{workflows:t.workflows??[]})}),e.jsx(q,{dist:t.modeDistribution}),e.jsx(A,{hooks:t.hooks}),e.jsx(_,{files:t.contextFiles}),e.jsx(V,{cfg:t.claudestatConfig}),e.jsx("div",{style:{gridColumn:"1 / -1"},children:e.jsx(D,{memoryFiles:t.memoryFiles})})]})]}):e.jsx("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",height:"100%",gap:12},children:s?e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{color:"#f85149",fontSize:13},children:"Error loading system configuration"}),l&&e.jsx("button",{onClick:l,style:{padding:"5px 14px",fontSize:12,fontWeight:600,cursor:"pointer",background:"none",border:"1px solid #f8514966",borderRadius:5,color:"#f85149",transition:"background 0.15s"},children:"Retry"})]}):e.jsx("span",{style:{color:"#6e7681",fontSize:13},children:"Loading system configuration…"})})}export{Q as SystemView};
@@ -1 +1 @@
1
- import{j as t,T as l}from"./index-CB01c5lb.js";import{a as c,a3 as S,a6 as C,a0 as W,a7 as z,W as k}from"./vendor-lucide-Cym0q5l_.js";import"./vendor-react-B_Jzs0gY.js";function g(o){return o<.001?"$0":o<.01?`$${o.toFixed(4)}`:o<1?`$${o.toFixed(3)}`:`$${o.toFixed(2)}`}function $(o){return o<1e3?`${o}ms`:o<6e4?`${(o/1e3).toFixed(1)}s`:`${(o/6e4).toFixed(1)}m`}const a=["#58a6ff","#3fb950","#d29922","#f0883e","#bc8cff","#f778ba","#79c0ff","#56d364","#e3b341","#ff7b72"];function w(){const[o,h]=c.useState(),[s,p]=c.useState(),[i,j]=c.useState("cost"),[r,m]=c.useState(30);c.useEffect(()=>{fetch(`/api/top?by=${i}&limit=10&days=${r}`).then(e=>e.ok?e.json():void 0).then(e=>e&&h(e)).catch(()=>{}),fetch("/cost-projection").then(e=>e.ok?e.json():void 0).then(e=>e&&p(e)).catch(()=>{})},[i,r]);const d=(o==null?void 0:o.tools)??[],u=Math.max(...d.map(e=>e.estimatedCostUsd),.001),b=Math.max(...d.map(e=>e.count),1);return t.jsxs("div",{style:{height:"100%",overflow:"auto",padding:"20px 24px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:16,marginBottom:20,flexWrap:"wrap"},children:[t.jsx("h2",{style:{margin:0,fontSize:18,fontWeight:700,color:"#e6edf3"},children:"Tool Rankings"}),t.jsx("div",{style:{display:"flex",gap:6},children:[{key:"cost",label:"Cost",icon:S,color:"#3fb950",tip:"Estimated USD cost per tool, calculated from each tool's share of total token usage"},{key:"count",label:"Calls",icon:C,color:"#58a6ff",tip:"Total number of invocations in the selected period"},{key:"duration",label:"Duration",icon:W,color:"#e3b341",tip:"Cumulative execution time (sum of all calls)"}].map(({key:e,label:n,icon:x,color:f,tip:v})=>t.jsx(l,{position:"bottom",align:"left",content:t.jsxs("div",{style:{fontSize:11,lineHeight:1.7},children:[t.jsxs("div",{style:{fontWeight:700,color:f,marginBottom:4},children:["Sort by ",n.toLowerCase()]}),t.jsx("div",{style:{color:"#7d8590"},children:v})]}),children:t.jsxs("button",{onClick:()=>j(e),style:{display:"flex",alignItems:"center",gap:5,padding:"4px 10px",fontSize:11,fontWeight:i===e?600:400,color:i===e?"#e6edf3":"#8b949e",background:i===e?"#21262d":"transparent",border:`1px solid ${i===e?"#30363d":"transparent"}`,borderRadius:5,cursor:"pointer"},children:[t.jsx(x,{size:11})," ",n]})},e))}),t.jsx("div",{style:{display:"flex",gap:4},children:[7,30,90].map(e=>t.jsxs("button",{onClick:()=>m(e),style:{padding:"4px 8px",fontSize:11,fontWeight:r===e?600:400,color:r===e?"#e6edf3":"#8b949e",background:r===e?"#21262d":"transparent",border:`1px solid ${r===e?"#30363d":"transparent"}`,borderRadius:5,cursor:"pointer"},children:[e,"d"]},e))})]}),s&&t.jsxs("div",{style:{display:"flex",gap:12,marginBottom:20},children:[t.jsx(y,{label:"This week",tooltip:"Cost accumulated since Monday of the current week, extrapolated to 7 days",costSoFar:s.weekly.costSoFar,projected:s.weekly.projected,daysWithData:s.weekly.daysWithData}),t.jsx(y,{label:"This month",tooltip:"Cost accumulated since the 1st of the current month, extrapolated to 30 days",costSoFar:s.monthly.costSoFar,projected:s.monthly.projected,daysWithData:s.monthly.daysWithData})]}),d.length===0?t.jsx("div",{style:{color:"#8b949e",fontSize:13,textAlign:"center",marginTop:40},children:"No tool usage data for this period."}):t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"32px 140px 70px 80px 80px",gap:8,padding:"0 8px",fontSize:10,fontWeight:600,color:"#8b949e",textTransform:"uppercase",letterSpacing:"0.5px"},children:[t.jsx("span",{children:"#"}),t.jsx("span",{children:"Tool"}),t.jsx("span",{style:{textAlign:"right"},children:t.jsx(l,{position:"bottom",align:"right",content:t.jsxs("div",{style:{fontSize:11,lineHeight:1.7},children:[t.jsx("div",{style:{fontWeight:700,color:"#58a6ff",marginBottom:4},children:"Calls"}),t.jsx("div",{style:{color:"#7d8590"},children:"Total invocations in the selected period"})]}),children:"Calls"})}),t.jsx("span",{style:{textAlign:"right"},children:t.jsx(l,{position:"bottom",align:"right",content:t.jsxs("div",{style:{fontSize:11,lineHeight:1.7},children:[t.jsx("div",{style:{fontWeight:700,color:"#e3b341",marginBottom:4},children:"Duration"}),t.jsx("div",{style:{color:"#7d8590"},children:"Cumulative execution time across all calls"})]}),children:"Duration"})}),t.jsx("span",{style:{textAlign:"right"},children:t.jsx(l,{position:"bottom",align:"right",content:t.jsxs("div",{style:{fontSize:11,lineHeight:1.7},children:[t.jsx("div",{style:{fontWeight:700,color:"#3fb950",marginBottom:4},children:"Est. Cost"}),t.jsxs("div",{style:{color:"#7d8590"},children:["Proportion of total session cost",t.jsx("br",{}),"attributed to each tool by call count"]})]}),children:"Est. Cost"})})]}),d.map((e,n)=>{const x=i==="cost"?e.estimatedCostUsd/u:i==="count"?e.count/b:e.totalDurationMs/Math.max(...d.map(f=>f.totalDurationMs),1);return t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"32px 140px 70px 80px 80px",gap:8,padding:"8px",fontSize:12,color:"#e6edf3",background:"#161b22",border:"1px solid #21262d",borderRadius:6,position:"relative",overflow:"hidden"},children:[t.jsx("div",{style:{position:"absolute",top:0,left:0,bottom:0,width:`${Math.max(x*100,2)}%`,background:`${a[n%a.length]}12`,transition:"width 0.3s ease"}}),t.jsx("span",{style:{color:"#8b949e",fontWeight:600,position:"relative"},children:n+1}),t.jsx("span",{style:{display:"flex",alignItems:"center",gap:6,position:"relative"},children:e.tool==="Other"?t.jsx(l,{position:"top",align:"left",content:t.jsxs("div",{style:{fontSize:11,lineHeight:1.7},children:[t.jsx("div",{style:{fontWeight:700,color:"#8b949e",marginBottom:4},children:"Other tools"}),t.jsxs("div",{style:{color:"#7d8590"},children:["Remaining cost not attributed to the",t.jsx("br",{}),"top tools listed above"]})]}),children:t.jsxs("span",{style:{display:"flex",alignItems:"center",gap:6},children:[t.jsx(z,{size:11,color:"#8b949e"}),e.tool]})}):t.jsxs(t.Fragment,{children:[t.jsx(k,{size:11,color:a[n%a.length]}),e.tool]})}),t.jsx("span",{style:{textAlign:"right",color:"#8b949e",position:"relative"},children:e.tool==="Other"?"—":e.count.toLocaleString()}),t.jsx("span",{style:{textAlign:"right",color:"#8b949e",position:"relative"},children:e.tool==="Other"?"—":$(e.totalDurationMs)}),t.jsx("span",{style:{textAlign:"right",fontWeight:600,color:a[n%a.length],position:"relative"},children:g(e.estimatedCostUsd)})]},e.tool)})]})]})}function y({label:o,tooltip:h,costSoFar:s,projected:p,daysWithData:i}){return t.jsxs("div",{style:{flex:1,background:"#161b22",border:"1px solid #21262d",borderRadius:8,padding:"14px 16px"},children:[t.jsx(l,{position:"top",align:"left",content:t.jsxs("div",{style:{fontSize:11,lineHeight:1.7},children:[t.jsx("div",{style:{fontWeight:700,color:"#e6edf3",marginBottom:4},children:o}),t.jsx("div",{style:{color:"#7d8590"},children:h})]}),children:t.jsx("div",{style:{fontSize:11,fontWeight:600,color:"#8b949e",marginBottom:8,cursor:"default"},children:o})}),t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:8,marginBottom:4},children:[t.jsx("span",{style:{fontSize:22,fontWeight:700,color:"#e6edf3"},children:g(p)}),t.jsx(l,{position:"top",align:"left",content:t.jsxs("div",{style:{fontSize:11,lineHeight:1.7},children:[t.jsx("div",{style:{fontWeight:700,color:"#58a6ff",marginBottom:4},children:"Projected spend"}),t.jsxs("div",{style:{color:"#7d8590"},children:["Extrapolated from daily average based on ",i.toFixed(1)," days of data"]})]}),children:t.jsx("span",{style:{fontSize:11,color:"#8b949e",cursor:"default"},children:"projected"})})]}),t.jsxs("div",{style:{fontSize:11,color:"#484f58"},children:[g(s)," spent over ",i.toFixed(1)," days"]})]})}export{w as TopView};
1
+ import{j as t,T as l}from"./index-DgbWvj42.js";import{a as c,a3 as S,a6 as C,a0 as W,a7 as z,W as k}from"./vendor-lucide-Cym0q5l_.js";import"./vendor-react-B_Jzs0gY.js";function g(o){return o<.001?"$0":o<.01?`$${o.toFixed(4)}`:o<1?`$${o.toFixed(3)}`:`$${o.toFixed(2)}`}function $(o){return o<1e3?`${o}ms`:o<6e4?`${(o/1e3).toFixed(1)}s`:`${(o/6e4).toFixed(1)}m`}const a=["#58a6ff","#3fb950","#d29922","#f0883e","#bc8cff","#f778ba","#79c0ff","#56d364","#e3b341","#ff7b72"];function w(){const[o,h]=c.useState(),[s,p]=c.useState(),[i,j]=c.useState("cost"),[r,m]=c.useState(30);c.useEffect(()=>{fetch(`/api/top?by=${i}&limit=10&days=${r}`).then(e=>e.ok?e.json():void 0).then(e=>e&&h(e)).catch(()=>{}),fetch("/cost-projection").then(e=>e.ok?e.json():void 0).then(e=>e&&p(e)).catch(()=>{})},[i,r]);const d=(o==null?void 0:o.tools)??[],u=Math.max(...d.map(e=>e.estimatedCostUsd),.001),b=Math.max(...d.map(e=>e.count),1);return t.jsxs("div",{style:{height:"100%",overflow:"auto",padding:"20px 24px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:16,marginBottom:20,flexWrap:"wrap"},children:[t.jsx("h2",{style:{margin:0,fontSize:18,fontWeight:700,color:"#e6edf3"},children:"Tool Rankings"}),t.jsx("div",{style:{display:"flex",gap:6},children:[{key:"cost",label:"Cost",icon:S,color:"#3fb950",tip:"Estimated USD cost per tool, calculated from each tool's share of total token usage"},{key:"count",label:"Calls",icon:C,color:"#58a6ff",tip:"Total number of invocations in the selected period"},{key:"duration",label:"Duration",icon:W,color:"#e3b341",tip:"Cumulative execution time (sum of all calls)"}].map(({key:e,label:n,icon:x,color:f,tip:v})=>t.jsx(l,{position:"bottom",align:"left",content:t.jsxs("div",{style:{fontSize:11,lineHeight:1.7},children:[t.jsxs("div",{style:{fontWeight:700,color:f,marginBottom:4},children:["Sort by ",n.toLowerCase()]}),t.jsx("div",{style:{color:"#7d8590"},children:v})]}),children:t.jsxs("button",{onClick:()=>j(e),style:{display:"flex",alignItems:"center",gap:5,padding:"4px 10px",fontSize:11,fontWeight:i===e?600:400,color:i===e?"#e6edf3":"#8b949e",background:i===e?"#21262d":"transparent",border:`1px solid ${i===e?"#30363d":"transparent"}`,borderRadius:5,cursor:"pointer"},children:[t.jsx(x,{size:11})," ",n]})},e))}),t.jsx("div",{style:{display:"flex",gap:4},children:[7,30,90].map(e=>t.jsxs("button",{onClick:()=>m(e),style:{padding:"4px 8px",fontSize:11,fontWeight:r===e?600:400,color:r===e?"#e6edf3":"#8b949e",background:r===e?"#21262d":"transparent",border:`1px solid ${r===e?"#30363d":"transparent"}`,borderRadius:5,cursor:"pointer"},children:[e,"d"]},e))})]}),s&&t.jsxs("div",{style:{display:"flex",gap:12,marginBottom:20},children:[t.jsx(y,{label:"This week",tooltip:"Cost accumulated since Monday of the current week, extrapolated to 7 days",costSoFar:s.weekly.costSoFar,projected:s.weekly.projected,daysWithData:s.weekly.daysWithData}),t.jsx(y,{label:"This month",tooltip:"Cost accumulated since the 1st of the current month, extrapolated to 30 days",costSoFar:s.monthly.costSoFar,projected:s.monthly.projected,daysWithData:s.monthly.daysWithData})]}),d.length===0?t.jsx("div",{style:{color:"#8b949e",fontSize:13,textAlign:"center",marginTop:40},children:"No tool usage data for this period."}):t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"32px 140px 70px 80px 80px",gap:8,padding:"0 8px",fontSize:10,fontWeight:600,color:"#8b949e",textTransform:"uppercase",letterSpacing:"0.5px"},children:[t.jsx("span",{children:"#"}),t.jsx("span",{children:"Tool"}),t.jsx("span",{style:{textAlign:"right"},children:t.jsx(l,{position:"bottom",align:"right",content:t.jsxs("div",{style:{fontSize:11,lineHeight:1.7},children:[t.jsx("div",{style:{fontWeight:700,color:"#58a6ff",marginBottom:4},children:"Calls"}),t.jsx("div",{style:{color:"#7d8590"},children:"Total invocations in the selected period"})]}),children:"Calls"})}),t.jsx("span",{style:{textAlign:"right"},children:t.jsx(l,{position:"bottom",align:"right",content:t.jsxs("div",{style:{fontSize:11,lineHeight:1.7},children:[t.jsx("div",{style:{fontWeight:700,color:"#e3b341",marginBottom:4},children:"Duration"}),t.jsx("div",{style:{color:"#7d8590"},children:"Cumulative execution time across all calls"})]}),children:"Duration"})}),t.jsx("span",{style:{textAlign:"right"},children:t.jsx(l,{position:"bottom",align:"right",content:t.jsxs("div",{style:{fontSize:11,lineHeight:1.7},children:[t.jsx("div",{style:{fontWeight:700,color:"#3fb950",marginBottom:4},children:"Est. Cost"}),t.jsxs("div",{style:{color:"#7d8590"},children:["Proportion of total session cost",t.jsx("br",{}),"attributed to each tool by call count"]})]}),children:"Est. Cost"})})]}),d.map((e,n)=>{const x=i==="cost"?e.estimatedCostUsd/u:i==="count"?e.count/b:e.totalDurationMs/Math.max(...d.map(f=>f.totalDurationMs),1);return t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"32px 140px 70px 80px 80px",gap:8,padding:"8px",fontSize:12,color:"#e6edf3",background:"#161b22",border:"1px solid #21262d",borderRadius:6,position:"relative",overflow:"hidden"},children:[t.jsx("div",{style:{position:"absolute",top:0,left:0,bottom:0,width:`${Math.max(x*100,2)}%`,background:`${a[n%a.length]}12`,transition:"width 0.3s ease"}}),t.jsx("span",{style:{color:"#8b949e",fontWeight:600,position:"relative"},children:n+1}),t.jsx("span",{style:{display:"flex",alignItems:"center",gap:6,position:"relative"},children:e.tool==="Other"?t.jsx(l,{position:"top",align:"left",content:t.jsxs("div",{style:{fontSize:11,lineHeight:1.7},children:[t.jsx("div",{style:{fontWeight:700,color:"#8b949e",marginBottom:4},children:"Other tools"}),t.jsxs("div",{style:{color:"#7d8590"},children:["Remaining cost not attributed to the",t.jsx("br",{}),"top tools listed above"]})]}),children:t.jsxs("span",{style:{display:"flex",alignItems:"center",gap:6},children:[t.jsx(z,{size:11,color:"#8b949e"}),e.tool]})}):t.jsxs(t.Fragment,{children:[t.jsx(k,{size:11,color:a[n%a.length]}),e.tool]})}),t.jsx("span",{style:{textAlign:"right",color:"#8b949e",position:"relative"},children:e.tool==="Other"?"—":e.count.toLocaleString()}),t.jsx("span",{style:{textAlign:"right",color:"#8b949e",position:"relative"},children:e.tool==="Other"?"—":$(e.totalDurationMs)}),t.jsx("span",{style:{textAlign:"right",fontWeight:600,color:a[n%a.length],position:"relative"},children:g(e.estimatedCostUsd)})]},e.tool)})]})]})}function y({label:o,tooltip:h,costSoFar:s,projected:p,daysWithData:i}){return t.jsxs("div",{style:{flex:1,background:"#161b22",border:"1px solid #21262d",borderRadius:8,padding:"14px 16px"},children:[t.jsx(l,{position:"top",align:"left",content:t.jsxs("div",{style:{fontSize:11,lineHeight:1.7},children:[t.jsx("div",{style:{fontWeight:700,color:"#e6edf3",marginBottom:4},children:o}),t.jsx("div",{style:{color:"#7d8590"},children:h})]}),children:t.jsx("div",{style:{fontSize:11,fontWeight:600,color:"#8b949e",marginBottom:8,cursor:"default"},children:o})}),t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:8,marginBottom:4},children:[t.jsx("span",{style:{fontSize:22,fontWeight:700,color:"#e6edf3"},children:g(p)}),t.jsx(l,{position:"top",align:"left",content:t.jsxs("div",{style:{fontSize:11,lineHeight:1.7},children:[t.jsx("div",{style:{fontWeight:700,color:"#58a6ff",marginBottom:4},children:"Projected spend"}),t.jsxs("div",{style:{color:"#7d8590"},children:["Extrapolated from daily average based on ",i.toFixed(1)," days of data"]})]}),children:t.jsx("span",{style:{fontSize:11,color:"#8b949e",cursor:"default"},children:"projected"})})]}),t.jsxs("div",{style:{fontSize:11,color:"#484f58"},children:[g(s)," spent over ",i.toFixed(1)," days"]})]})}export{w as TopView};