claude-code-session-manager 0.130.2 → 0.130.3
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/bin/cli.cjs +19 -2
- package/dist/assets/AgentLibrary-BmrXNwK8.js +2 -0
- package/dist/assets/{AppSettings-Bpwynea4.js → AppSettings-Cs4POznd.js} +1 -1
- package/dist/assets/{Button-DSoqrxCB.js → Button-UUr5giu8.js} +1 -1
- package/dist/assets/DocumentEditorPane-C46Hj0lz.js +1 -0
- package/dist/assets/Extensions-B9QdiNOV.js +2 -0
- package/dist/assets/{History-DzMo9Otn.js → History-Bndupj87.js} +2 -2
- package/dist/assets/{Library-C5wKMTSn.js → Library-DFn0YPIW.js} +5 -5
- package/dist/assets/{ListDetail-DDQ1S0yu.js → ListDetail-DjMn8a_3.js} +1 -1
- package/dist/assets/{Panel-B-3NWUlv.js → Panel-CIvb-XXN.js} +1 -1
- package/dist/assets/ProjectClaudeConfig-BQQRtMdK.js +25 -0
- package/dist/assets/{ProvenanceBadge-CUChwz4Z.js → ProvenanceBadge-ej8W2ZIK.js} +1 -1
- package/dist/assets/{Scheduler-CkGHMXvo.js → Scheduler-DSVBWqRK.js} +8 -8
- package/dist/assets/Settings-DqxUna06.js +2 -0
- package/dist/assets/{SkillReferenceGraph-C6JEdypC.js → SkillReferenceGraph-BEMTdxdD.js} +1 -1
- package/dist/assets/Skills-DTXehVS7.js +12 -0
- package/dist/assets/{SourceChip-DcBNYYhe.js → SourceChip-BrPci8FX.js} +1 -1
- package/dist/assets/SystemPrompt-B43hNP0X.js +1 -0
- package/dist/assets/{TiptapBody-DiVYC-_O.js → TiptapBody-B-R2Bpda.js} +1 -1
- package/dist/assets/{Toggle-Cs3k6I96.js → Toggle-DKb4x1BP.js} +1 -1
- package/dist/assets/ViewTabs-CcJdFZgv.js +1 -0
- package/dist/assets/{VoiceButton-C3NLotUZ.js → VoiceButton-BSH0UI3u.js} +1 -1
- package/dist/assets/{historyTotals-f-E0L9Xw.js → historyTotals-5oUEu_fe.js} +1 -1
- package/dist/assets/index-C9w-dVzo.js +3090 -0
- package/dist/assets/{index-Bp8XE9A6.css → index-CMCcT2yg.css} +1 -1
- package/dist/index.html +2 -2
- package/dist-web/app.css +1 -1
- package/dist-web/app.js +420 -416
- package/package.json +1 -1
- package/plugins/session-manager-dev/.claude-plugin/plugin.json +1 -1
- package/plugins/session-manager-dev/skills/maintaining-md-network/drift-check.md +15 -5
- package/plugins/session-manager-dev/skills/maintaining-md-network/scripts/drift-check.cjs +8 -4
- package/src/main/agentLibrary.cjs +81 -29
- package/src/main/agentsIpc.cjs +21 -16
- package/src/main/build-info.json +4 -4
- package/src/main/ipcSchemas.cjs +7 -1
- package/src/main/lib/epic/epicWorktreeMerge.cjs +11 -9
- package/src/main/lib/feedback-remote/remoteIpcDispatch.cjs +2 -0
- package/src/main/lib/git/gitWorktree.cjs +216 -43
- package/src/main/lib/mdNetworkScan.cjs +555 -0
- package/src/main/lib/persona-macro/agentPersonaSchema.cjs +18 -5
- package/src/main/lib/persona-macro/builtinMacros.cjs +6 -4
- package/src/main/lib/persona-macro/macroJobDispatch.cjs +9 -2
- package/src/main/lib/scheduler/terminalRunOutcome.cjs +61 -15
- package/src/main/projectPages.cjs +32 -7
- package/src/main/scheduler/gitTreeGuard.cjs +85 -12
- package/src/main/scheduler.cjs +16 -5
- package/src/preload/api.d.ts +91 -6
- package/src/preload/apiSurface.json +7 -0
- package/src/preload/index.cjs +1 -0
- package/dist/assets/AgentLibrary-Bfj862qf.js +0 -2
- package/dist/assets/Extensions-BziIutWV.js +0 -13
- package/dist/assets/Memory-Bq5T33d2.js +0 -25
- package/dist/assets/Settings-DGxvyajs.js +0 -2
- package/dist/assets/SystemPrompt-CfozyVQx.js +0 -1
- package/dist/assets/ViewTabs-DFXH03tb.js +0 -1
- package/dist/assets/index-CuAfFXNd.js +0 -3086
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
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 ze()).history??{}}let Re=Promise.resolve();function ue(t){const s=Re.then(async()=>{const n=await pe();await Ke({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 G=D.bands[Z],W=n!==null&&n!==j.projectDir,ee=W?gt:A(j.projectDir),te=[`${p(g-1)},${m(G.y0)}`,`${p(g)},${m(j.y0)}`,`${p(g)},${m(j.y1)}`,`${p(g-1)},${m(G.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,Gt=[];function zt(){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),[G,W]=x.useState(!0),[ee,te]=x.useState(0),se=x.useRef(n);se.current=n;const z=x.useRef(!0),ne=x.useRef(0),he=x.useRef(0),F=x.useRef(null),K=x.useCallback(f=>{const b=se.current;ne.current+=1,he.current=Date.now(),Ze(b).then(y=>{if(ne.current-=1,!(!z.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(()=>{z.current=!0,W(!0),K(!1)},[n,ee,K]),x.useEffect(()=>{const f=()=>{if(!z.current)return;const N=he.current+Wt-Date.now();if(ne.current===0&&N<=0){K(!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),()=>{z.current=!1,y(),window.removeEventListener("focus",f),document.removeEventListener("visibilitychange",b),F.current&&(clearTimeout(F.current),F.current=null)}},[K]);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)??Gt,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:Ge}=Ne(Object.values(U.byProject));return{date:U.date,costUsd:Le,inputTokens:Oe,outputTokens:Ie,cacheCreationTokens:We,cacheReadTokens:Ge,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 G&&!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 Kt(){return e.jsx(Qe,{children:e.jsx(zt,{})})}const Jt=x.memo(Kt);export{Jt as History};
|
|
1
|
+
import{aF as xe,aN as Ke,bu as ze,au as e,aK as x,b0 as q,aG as A,aH as L,bn as Ve,bc as Ye,bl as ye,aA as Xe,bb as qe,l as Qe}from"./index-C9w-dVzo.js";import{P as Ze}from"./Panel-CIvb-XXN.js";import{p as De,i as O,m as Ee,t as I,u as D,f as Je}from"./historyTotals-5oUEu_fe.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 Ke()).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 Q(t,s){switch(t){case"spend":return D(s);case"in":case"out":case"total":return I(s);case"time":return Ee(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:Q(t,s.value)}),c?e.jsxs("div",{className:`text-xs font-mono mt-2 ${l}`,children:[c.direction==="up"?"▲":c.direction==="down"?"▼":"·"," ",De(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:Q(t,i)}),e.jsx(X,{label:"per session",value:Q(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:[D(i)," ",e.jsx("span",{className:"text-fg-faint",children:"month-to-date"})]}),e.jsxs("span",{className:c?"text-delta-bad":"text-fg-dim",children:[D(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"?D(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 E=a[g-1];return h.bands.map((j,J)=>{const G=E.bands[J],W=n!==null&&n!==j.projectDir,ee=W?gt:A(j.projectDir),te=[`${p(g-1)},${m(G.y0)}`,`${p(g)},${m(j.y0)}`,`${p(g)},${m(j.y1)}`,`${p(g-1)},${m(G.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:Q(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"?"▼":"·"," ",De(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:D(s.estimatedCostUsd)}),e.jsx(H,{label:"time",value:Ee(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:D(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 Dt({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:[D(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:[D(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 Et({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 Z=30,fe=9,P=(Z+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*Z,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:Z,fill:"none",stroke:"currentColor",className:"text-bg-hi",strokeWidth:fe}),e.jsx("circle",{cx:o,cy:o,r:Z,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,Gt=[];function Kt(){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,E]=x.useState(null),[j,J]=x.useState(null),[G,W]=x.useState(!0),[ee,te]=x.useState(0),se=x.useRef(n);se.current=n;const K=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(),Je(b).then(y=>{if(ne.current-=1,!(!K.current||b!==se.current)){if(W(!1),y.ok){J(y.data);return}f||q.error(`History analytics failed to load: ${y.error}`)}})},[]);x.useEffect(()=>{K.current=!0,W(!0),z(!1)},[n,ee,z]),x.useEffect(()=>{const f=()=>{if(!K.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),()=>{K.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),E(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)??Gt,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)&&E(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:Ge}=Ne(Object.values(U.byProject));return{date:U.date,costUsd:Le,inputTokens:Oe,outputTokens:Ie,cacheCreationTokens:We,cacheReadTokens:Ge,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 G&&!j?e.jsx($e,{}):j&&j.days.length===0?e.jsx(Qe,{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:E}),e.jsx(St,{rows:ae,measure:t,selected:g,onSelect:E}),g&&Y&&e.jsx($t,{projectDir:g,totals:Y.totals,byModel:Y.byModel,toolBreakdown:Y.toolBreakdown,onClear:()=>E(null)}),e.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-4",children:[e.jsx(Dt,{byModelTotals:S.byModelTotals}),e.jsx(Et,{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(Ze,{children:e.jsx(Kt,{})})}const Qt=x.memo(zt);export{Qt as History};
|