claude-code-session-manager 0.145.0 → 0.146.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/dist/assets/{AppSettings-BR5b6oof.js → AppSettings-BXfkoKQq.js} +1 -1
  2. package/dist/assets/{History-B4U0mCdK.js → History-l7pBt_vO.js} +1 -1
  3. package/dist/assets/{HomeClaudeConfig-DQqG7lFE.js → HomeClaudeConfig-DtFwZxTx.js} +2 -2
  4. package/dist/assets/{Panel-CwsOJ0nI.js → Panel-C5hihgUD.js} +1 -1
  5. package/dist/assets/{ProjectClaudeConfig-BzRowu8x.js → ProjectClaudeConfig-B3pODrM-.js} +1 -1
  6. package/dist/assets/{Scheduler-dr7CNOcL.js → Scheduler-IU9wo8_u.js} +1 -1
  7. package/dist/assets/{SkillReferenceGraph-CroBPY4C.js → SkillReferenceGraph-Bmen0OOC.js} +1 -1
  8. package/dist/assets/{Skills-BiW2lCnD.js → Skills-jYVxqJr2.js} +1 -1
  9. package/dist/assets/{TiptapBody-CYTkQiva.js → TiptapBody-Dp2gtbb-.js} +1 -1
  10. package/dist/assets/{Toggle-WFBYo8JI.js → Toggle-C_0yUCS5.js} +1 -1
  11. package/dist/assets/{VoiceButton-DZu8dTpO.js → VoiceButton-BRPzqDa-.js} +1 -1
  12. package/dist/assets/{historyTotals-B7KeXLSE.js → historyTotals-pAv-MFnY.js} +1 -1
  13. package/dist/assets/{index-hXRNm0UJ.js → index-C6nhp7m_.js} +496 -496
  14. package/dist/index.html +1 -1
  15. package/dist-web/app.js +408 -408
  16. package/package.json +1 -1
  17. package/plugins/session-manager-dev/skills/send-feedback/SKILL.md +4 -2
  18. package/scripts/scheduler-mcp-server.cjs +4 -3
  19. package/src/main/adminRouteRegistry.cjs +1 -1
  20. package/src/main/build-info.json +4 -4
  21. package/src/main/lib/claude/claudeJsonApproval.cjs +129 -0
  22. package/src/main/lib/demo-video-kit/resumableRun.cjs +15 -1
  23. package/src/main/lib/demo-video-kit/seedKit.cjs +2 -2
  24. package/src/main/lib/epic/epicSpawnCwd.cjs +1 -0
  25. package/src/main/lib/epic/planReviewInput.cjs +3 -6
  26. package/src/main/lib/feedback-remote/crossProjectFeedback.cjs +136 -37
  27. package/src/main/lib/feedback-remote/serviceMcpTools.cjs +23 -3
  28. package/src/main/lib/git/gitWorktree.cjs +17 -0
  29. package/src/main/lib/mcpToolCatalog.cjs +2 -1
  30. package/src/main/lib/scheduler/planReleaseRoute.cjs +53 -5
  31. package/src/main/lib/scheduler/rcaReport.cjs +1 -0
  32. package/src/main/lib/scheduler/terminalRunOutcome.cjs +1 -0
  33. package/src/main/runVerify.cjs +30 -0
  34. package/src/main/scheduler.cjs +60 -9
@@ -1,2 +1,2 @@
1
- import{aO as me,aW as Ze,bH as et,aD as e,aT as p,bc as X,aP as D,aQ as H,bA as Fe,bp as tt,by as Ce,aJ as st,bo as nt,m as ot}from"./index-hXRNm0UJ.js";import{P as at}from"./Panel-CwsOJ0nI.js";import{p as _e,i as B,m as Oe,t as I,u as $,f as rt}from"./historyTotals-B7KeXLSE.js";import"./monaco-editor-BsIlgG7c.js";function ie(){return{promptCount:0,inputTokens:0,outputTokens:0,cacheReadTokens:0,cacheCreationTokens:0,toolCallCount:0,sessionCount:0,errorCount:0,activeMinutes:0,estimatedCostUsd:0}}function we(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 ct(t){return t.promptCount>0||t.sessionCount>0||t.toolCallCount>0||t.inputTokens>0||t.outputTokens>0}function it(t,s){const n=s===null,a=[],o=ie(),c={},r={};let i=0;for(const f of t.days){const l=ie();let d=!1;for(const[m,u]of Object.entries(f.byProject)){if(!n&&!s.has(m))continue;we(l,u),we(o,u),ct(u)&&(d=!0);for(const[y,v]of Object.entries(u.byModel)){const x=c[y]??(c[y]={inputTokens:0,outputTokens:0,cacheReadTokens:0,cacheCreationTokens:0,costUsd:0});x.inputTokens+=v.inputTokens,x.outputTokens+=v.outputTokens,x.cacheReadTokens+=v.cacheReadTokens,x.cacheCreationTokens+=v.cacheCreationTokens,x.costUsd+=v.costUsd,v.estimated&&(x.estimated=!0)}const g=u.byLauncher??{};for(const[y,v]of Object.entries(g)){const x=r[y]??(r[y]={inputTokens:0,outputTokens:0,cacheReadTokens:0,cacheCreationTokens:0,costUsd:0,sessionCount:0});x.inputTokens+=v.inputTokens,x.outputTokens+=v.outputTokens,x.cacheReadTokens+=v.cacheReadTokens,x.cacheCreationTokens+=v.cacheCreationTokens,x.costUsd+=v.costUsd,x.sessionCount+=v.sessionCount}}d&&(i+=1),a.push({date:f.date,totals:l})}return{days:a,totals:o,prevTotals:n?t.prevTotals:ie(),prevAvailable:n,byModelTotals:c,byLauncherTotals:r,activeDays:i}}function He(t,s){if(!s)return{pct:null,direction:"flat"};const n=(t-s)/s*100,a=n>0?"up":n<0?"down":"flat";return{pct:n,direction:a}}function lt(t,s,n){return s<=0?0:t/s*n}const dt=["promptCount","inputTokens","outputTokens","cacheReadTokens","cacheCreationTokens","toolCallCount","sessionCount","errorCount","activeMinutes","estimatedCostUsd"],ut=["inputTokens","outputTokens","cacheReadTokens","cacheCreationTokens","costUsd"];function Re(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=a=>typeof a=="number"&&Number.isFinite(a)?a:0;for(const a of t){for(const o of dt)s[o]+=n(a[o]);for(const[o,c]of Object.entries(a.byModel??{})){const r=s.byModel[o]??(s.byModel[o]={inputTokens:0,outputTokens:0,cacheReadTokens:0,cacheCreationTokens:0,costUsd:0});for(const i of ut)r[i]+=n(c==null?void 0:c[i])}}return s}const Be={in:"In tokens",out:"Out tokens",total:"Total tokens",prompts:"Prompts",sessions:"Sessions",time:"Time",spend:"Spend"};function E(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 ft(t,s){const n=E(t.totals,s),a=t.prevAvailable?He(n,E(t.prevTotals,s)):null,o=t.days.map(c=>E(c.totals,s));return{value:n,delta:a,series:o}}function Se(t,s){const n=new Map,a=Math.ceil(t.length/2);t.forEach((r,i)=>{for(const[f,l]of Object.entries(r.byProject)){let d=n.get(f);d||(d={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(f,d)),d.totals.promptCount+=l.promptCount,d.totals.inputTokens+=l.inputTokens,d.totals.outputTokens+=l.outputTokens,d.totals.cacheReadTokens+=l.cacheReadTokens,d.totals.cacheCreationTokens+=l.cacheCreationTokens,d.totals.toolCallCount+=l.toolCallCount,d.totals.sessionCount+=l.sessionCount,d.totals.errorCount+=l.errorCount,d.totals.activeMinutes+=l.activeMinutes,d.totals.estimatedCostUsd+=l.estimatedCostUsd;for(const[u,g]of Object.entries(l.toolBreakdown))d.toolBreakdown[u]=(d.toolBreakdown[u]??0)+g;const m=E(l,s);i<a?d.firstHalf+=m:d.secondHalf+=m}});const o=Array.from(n.entries()).map(([r,i])=>{let f="",l=-1;for(const[d,m]of Object.entries(i.toolBreakdown))m>l&&(l=m,f=d);return{projectDir:r,value:E(i.totals,s),sharePct:0,trend:He(i.secondHalf,i.firstHalf),sessions:i.totals.sessionCount,topTool:f}}),c=o.reduce((r,i)=>r+i.value,0);for(const r of o)r.sharePct=c>0?r.value/c*100:0;return o.sort((r,i)=>i.value-r.value)}const xt=["date","cost_usd","input_tokens","output_tokens","cache_write_tokens","cache_read_tokens","total_tokens","cache_hit_pct","num_models","top_model"];function ht(t){return/[",\n]/.test(t)?`"${t.replace(/"/g,'""')}"`:t}function Me(t){return t.inputTokens+t.outputTokens+t.cacheReadTokens+t.cacheCreationTokens}function pt(t){const s=t.map(n=>{const a=n.inputTokens+n.outputTokens+n.cacheCreationTokens+n.cacheReadTokens,o=n.inputTokens+n.cacheReadTokens+n.cacheCreationTokens,c=o>0?n.cacheReadTokens/o*100:0,r=Object.entries(n.byModel).filter(([,d])=>Me(d)>0);let i="",f=-1;for(const[d,m]of r){const u=Me(m);u>f&&(f=u,i=d)}return[n.date,n.costUsd.toFixed(4),String(n.inputTokens),String(n.outputTokens),String(n.cacheCreationTokens),String(n.cacheReadTokens),String(a),c.toFixed(1),String(r.length),i?me(i):""].map(ht).join(",")});return[xt.join(","),...s].join(`
1
+ import{aO as me,aW as Ze,bH as et,aD as e,aT as p,bc as X,aP as D,aQ as H,bA as Fe,bp as tt,by as Ce,aJ as st,bo as nt,m as ot}from"./index-C6nhp7m_.js";import{P as at}from"./Panel-C5hihgUD.js";import{p as _e,i as B,m as Oe,t as I,u as $,f as rt}from"./historyTotals-pAv-MFnY.js";import"./monaco-editor-BsIlgG7c.js";function ie(){return{promptCount:0,inputTokens:0,outputTokens:0,cacheReadTokens:0,cacheCreationTokens:0,toolCallCount:0,sessionCount:0,errorCount:0,activeMinutes:0,estimatedCostUsd:0}}function we(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 ct(t){return t.promptCount>0||t.sessionCount>0||t.toolCallCount>0||t.inputTokens>0||t.outputTokens>0}function it(t,s){const n=s===null,a=[],o=ie(),c={},r={};let i=0;for(const f of t.days){const l=ie();let d=!1;for(const[m,u]of Object.entries(f.byProject)){if(!n&&!s.has(m))continue;we(l,u),we(o,u),ct(u)&&(d=!0);for(const[y,v]of Object.entries(u.byModel)){const x=c[y]??(c[y]={inputTokens:0,outputTokens:0,cacheReadTokens:0,cacheCreationTokens:0,costUsd:0});x.inputTokens+=v.inputTokens,x.outputTokens+=v.outputTokens,x.cacheReadTokens+=v.cacheReadTokens,x.cacheCreationTokens+=v.cacheCreationTokens,x.costUsd+=v.costUsd,v.estimated&&(x.estimated=!0)}const g=u.byLauncher??{};for(const[y,v]of Object.entries(g)){const x=r[y]??(r[y]={inputTokens:0,outputTokens:0,cacheReadTokens:0,cacheCreationTokens:0,costUsd:0,sessionCount:0});x.inputTokens+=v.inputTokens,x.outputTokens+=v.outputTokens,x.cacheReadTokens+=v.cacheReadTokens,x.cacheCreationTokens+=v.cacheCreationTokens,x.costUsd+=v.costUsd,x.sessionCount+=v.sessionCount}}d&&(i+=1),a.push({date:f.date,totals:l})}return{days:a,totals:o,prevTotals:n?t.prevTotals:ie(),prevAvailable:n,byModelTotals:c,byLauncherTotals:r,activeDays:i}}function He(t,s){if(!s)return{pct:null,direction:"flat"};const n=(t-s)/s*100,a=n>0?"up":n<0?"down":"flat";return{pct:n,direction:a}}function lt(t,s,n){return s<=0?0:t/s*n}const dt=["promptCount","inputTokens","outputTokens","cacheReadTokens","cacheCreationTokens","toolCallCount","sessionCount","errorCount","activeMinutes","estimatedCostUsd"],ut=["inputTokens","outputTokens","cacheReadTokens","cacheCreationTokens","costUsd"];function Re(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=a=>typeof a=="number"&&Number.isFinite(a)?a:0;for(const a of t){for(const o of dt)s[o]+=n(a[o]);for(const[o,c]of Object.entries(a.byModel??{})){const r=s.byModel[o]??(s.byModel[o]={inputTokens:0,outputTokens:0,cacheReadTokens:0,cacheCreationTokens:0,costUsd:0});for(const i of ut)r[i]+=n(c==null?void 0:c[i])}}return s}const Be={in:"In tokens",out:"Out tokens",total:"Total tokens",prompts:"Prompts",sessions:"Sessions",time:"Time",spend:"Spend"};function E(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 ft(t,s){const n=E(t.totals,s),a=t.prevAvailable?He(n,E(t.prevTotals,s)):null,o=t.days.map(c=>E(c.totals,s));return{value:n,delta:a,series:o}}function Se(t,s){const n=new Map,a=Math.ceil(t.length/2);t.forEach((r,i)=>{for(const[f,l]of Object.entries(r.byProject)){let d=n.get(f);d||(d={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(f,d)),d.totals.promptCount+=l.promptCount,d.totals.inputTokens+=l.inputTokens,d.totals.outputTokens+=l.outputTokens,d.totals.cacheReadTokens+=l.cacheReadTokens,d.totals.cacheCreationTokens+=l.cacheCreationTokens,d.totals.toolCallCount+=l.toolCallCount,d.totals.sessionCount+=l.sessionCount,d.totals.errorCount+=l.errorCount,d.totals.activeMinutes+=l.activeMinutes,d.totals.estimatedCostUsd+=l.estimatedCostUsd;for(const[u,g]of Object.entries(l.toolBreakdown))d.toolBreakdown[u]=(d.toolBreakdown[u]??0)+g;const m=E(l,s);i<a?d.firstHalf+=m:d.secondHalf+=m}});const o=Array.from(n.entries()).map(([r,i])=>{let f="",l=-1;for(const[d,m]of Object.entries(i.toolBreakdown))m>l&&(l=m,f=d);return{projectDir:r,value:E(i.totals,s),sharePct:0,trend:He(i.secondHalf,i.firstHalf),sessions:i.totals.sessionCount,topTool:f}}),c=o.reduce((r,i)=>r+i.value,0);for(const r of o)r.sharePct=c>0?r.value/c*100:0;return o.sort((r,i)=>i.value-r.value)}const xt=["date","cost_usd","input_tokens","output_tokens","cache_write_tokens","cache_read_tokens","total_tokens","cache_hit_pct","num_models","top_model"];function ht(t){return/[",\n]/.test(t)?`"${t.replace(/"/g,'""')}"`:t}function Me(t){return t.inputTokens+t.outputTokens+t.cacheReadTokens+t.cacheCreationTokens}function pt(t){const s=t.map(n=>{const a=n.inputTokens+n.outputTokens+n.cacheCreationTokens+n.cacheReadTokens,o=n.inputTokens+n.cacheReadTokens+n.cacheCreationTokens,c=o>0?n.cacheReadTokens/o*100:0,r=Object.entries(n.byModel).filter(([,d])=>Me(d)>0);let i="",f=-1;for(const[d,m]of r){const u=Me(m);u>f&&(f=u,i=d)}return[n.date,n.costUsd.toFixed(4),String(n.inputTokens),String(n.outputTokens),String(n.cacheCreationTokens),String(n.cacheReadTokens),String(a),c.toFixed(1),String(r.length),i?me(i):""].map(ht).join(",")});return[xt.join(","),...s].join(`
2
2
  `)}const mt=["epic","job","task","other"],xe="sm-task:";function gt(t){return t.startsWith(xe)?"task":t.includes("session-manager-epic-worktrees")?"epic":t.includes("session-manager-job-worktrees")?"job":"other"}const jt={folderCount:0,sessionCount:0,promptCount:0,estimatedCostUsd:0,totalTokens:0};function Ie(t,s,n){const a=t.byLauncher[s]??(t.byLauncher[s]={inputTokens:0,outputTokens:0,cacheReadTokens:0,cacheCreationTokens:0,costUsd:0,sessionCount:0});a.inputTokens+=n.inputTokens,a.outputTokens+=n.outputTokens,a.cacheReadTokens+=n.cacheReadTokens,a.cacheCreationTokens+=n.cacheCreationTokens,a.costUsd+=n.estimatedCostUsd,a.sessionCount+=n.sessionCount}function $e(t,s,n){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[a,o]of Object.entries(s.toolBreakdown??{}))t.toolBreakdown[a]=(t.toolBreakdown[a]??0)+o;for(const[a,o]of Object.entries(s.byModel??{})){const c=t.byModel[a]??(t.byModel[a]={inputTokens:0,outputTokens:0,cacheReadTokens:0,cacheCreationTokens:0,costUsd:0});c.inputTokens+=o.inputTokens,c.outputTokens+=o.outputTokens,c.cacheReadTokens+=o.cacheReadTokens,c.cacheCreationTokens+=o.cacheCreationTokens,c.costUsd+=o.costUsd,o.estimated&&(c.estimated=!0)}Ie(t,n,s)}function Ee(t,s,n){const a={};for(const[c,r]of Object.entries(t.byModel??{}))a[c]={...r};const o={...t,projectDir:s,toolBreakdown:{...t.toolBreakdown??{}},byModel:a,byLauncher:{}};return Ie(o,n,t),o}function vt(t,s){const n={...jt},a=new Set,o=t.map(c=>{const r={};for(const[i,f]of Object.entries(c.byProject)){if(i.startsWith(xe)){const u=i.slice(xe.length),g=r[u];g?$e(g,f,"task"):r[u]=Ee(f,u,"task");continue}const l=s[i];if(!l){a.add(i),n.sessionCount+=f.sessionCount,n.promptCount+=f.promptCount,n.estimatedCostUsd+=f.estimatedCostUsd,n.totalTokens+=f.inputTokens+f.outputTokens;continue}const d=gt(i),m=r[l];m?$e(m,f,d):r[l]=Ee(f,l,d)}return{...c,byProject:r}});return n.folderCount=a.size,{days:o,excluded:n}}function bt(t){return t.folderCount>0}function kt(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 ge(){return(await Ze()).history??{}}let De=Promise.resolve();function he(t){const s=De.then(async()=>{const n=await ge();await et({history:{...n,...t}})});return De=s.catch(()=>{}),s}const yt=["in","out","total","prompts","sessions","time","spend"],Nt=[{value:30,label:"30d"},{value:60,label:"60d"},{value:90,label:"90d"},{value:0,label:"All time"}];function Pe({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(a=>e.jsx("button",{onClick:()=>n(a.value),className:`px-2 py-1 rounded whitespace-nowrap font-mono ${t===a.value?"bg-bg-hi text-fg shadow-sm":"text-fg-faint hover:text-fg"}`,children:a.label},String(a.value)))})}function Tt({measure:t,onMeasure:s,range:n,onRange:a,projectsShown:o,projectsTotal:c,fromDate:r,toDate:i,onRefresh:f,onExport:l,exportDisabled:d}){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(Pe,{value:t,options:yt.map(m=>({value:m,label:Be[m]})),onChange:s}),e.jsx(Pe,{value:n,options:Nt,onChange:a}),e.jsxs("span",{className:"text-[11px] text-fg-faint font-mono",children:[o," / ",c," projects"]}),e.jsxs("span",{className:"text-[11px] text-fg-faint font-mono",children:[r," → ",i]}),e.jsx("div",{className:"flex-1"}),e.jsx("button",{onClick:f,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:l,disabled:d,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 C="rounded-card bg-bg-hi border border-line",Ct="#ded2bd",wt="#6f7d52";function w({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 $(s);case"in":case"out":case"total":return I(s);case"time":return Oe(s);default:return B(s)}}function Rt({measure:t,headline:s,activeDays:n,projectsTouched:a,totalSessions:o}){const c=n>0?s.value/n:0,r=o>0?s.value/o:0,{delta:i}=s,f=i&&(t==="spend"?i.direction==="down":i.direction==="up"),l=i&&i.direction!=="flat"&&(t==="spend"?i.direction==="up":i.direction==="down"),d=f?"text-delta-good":l?"text-delta-bad":"text-fg-faint";return e.jsxs("div",{className:`${C} p-4`,children:[e.jsx(w,{kicker:"01 · overview",title:Be[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)}),i?e.jsxs("div",{className:`text-xs font-mono mt-2 ${d}`,children:[i.direction==="up"?"▲":i.direction==="down"?"▼":"·"," ",_e(Math.abs(i.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(St,{series:s.series})})]}),e.jsxs("div",{className:"grid grid-cols-4 gap-3 mt-4 pt-3 border-t border-line",children:[e.jsx(Y,{label:"per active day",value:Q(t,c)}),e.jsx(Y,{label:"per session",value:Q(t,r)}),e.jsx(Y,{label:"active days",value:B(n)}),e.jsx(Y,{label:"projects touched",value:B(a)})]})]})}function Y({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 St({series:t}){if(t.length<2)return null;const a=Math.max(...t,0),o=Math.min(...t,0),c=a-o||1,r=160/(t.length-1),i=t.map((l,d)=>`${d*r},${48-(l-o)/c*48}`).join(" "),f=`0,48 ${i} 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:f,fill:"#b85c34",opacity:.15}),e.jsx("polyline",{points:i,fill:"none",stroke:"#b85c34",strokeWidth:1.5,vectorEffect:"non-scaling-stroke"})]})}const Mt=50;function $t({days:t}){const[s,n]=p.useState(Mt),a=p.useRef(!1);p.useEffect(()=>{let l=!1;return ge().then(d=>{l||a.current||typeof d.budgetCapUsd=="number"&&Number.isFinite(d.budgetCapUsd)&&d.budgetCapUsd>0&&n(d.budgetCapUsd)}),()=>{l=!0}},[]);const o=l=>{a.current=!0;const d=s;n(l),he({budgetCapUsd:l}).catch(()=>{n(d),X.error("Couldn't save the budget cap — reverted.")})},{mtdSpend:c,projectedSpend:r}=p.useMemo(()=>{const l=new Date,d=l.toLocaleDateString("en-CA").slice(0,7),m=new Date(l.getFullYear(),l.getMonth()+1,0).getDate(),u=l.getDate();let g=0;for(const y of t)if(y.date.startsWith(d))for(const v of Object.values(y.byProject))g+=v.estimatedCostUsd;return{mtdSpend:g,projectedSpend:lt(g,u,m)}},[t]),i=r>s,f=s>0?Math.min(100,c/s*100):0;return e.jsxs("div",{className:`${C} 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:l=>{const d=Number(l.target.value);Number.isFinite(d)&&d>0&&o(d)},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:[$(c)," ",e.jsx("span",{className:"text-fg-faint",children:"month-to-date"})]}),e.jsxs("span",{className:i?"text-delta-bad":"text-fg-dim",children:[$(r)," ",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 ${i?"bg-delta-bad":"bg-sage"}`,style:{width:`${Math.max(f,f>0?2:0)}%`}})}),e.jsx("div",{className:`text-[10px] mt-1 font-mono ${i?"text-delta-bad":"text-fg-faint"}`,children:i?`projected to exceed $${s.toFixed(0)} cap`:`${f.toFixed(0)}% of $${s.toFixed(0)} cap`})]})}function Et({chips:t,keep:s,onToggle:n,onIsolate:a,onShowAll:o}){const c=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 ${c?"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(r=>{const i=c||s.has(r.projectDir);return e.jsxs("button",{onClick:f=>f.shiftKey?a(r.projectDir):n(r.projectDir),title:r.projectDir,className:`inline-flex items-center gap-1.5 px-2 py-1 rounded text-[11px] font-mono border ${i?"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:D(r.projectDir)}}),H(r.projectDir)]},r.projectDir)})]})}function Dt(t,s){const n=new Map;for(const o of t)for(const[c,r]of Object.entries(o.values))n.set(c,(n.get(c)??0)+r);const a=Array.from(n.entries()).sort((o,c)=>c[1]-o[1]).map(([o])=>o);return t.map(o=>{const c=a.reduce((f,l)=>f+(o.values[l]??0),0);let r=0;const i=a.map(f=>{const l=o.values[f]??0;if(c<=0)return{projectDir:f,value:l,y0:0,y1:0};const d=s==="share"?l/c:l,m=r,u=r+d;return r=u,{projectDir:f,value:l,y0:m,y1:u}});return{date:o.date,bands:i,total:c}})}const le=720,de=220,ue=44,Pt=20;function Ut(t,s){return t==="spend"?$(s):I(s)}function At({days:t,measure:s,selected:n,onSelect:a}){const[o,c]=p.useState("absolute"),r=p.useMemo(()=>Dt(t,o),[t,o]),i=p.useMemo(()=>{if(o==="share")return 1;let x=0;for(const b of r)x=Math.max(x,b.total);return x||1},[r,o]),f=le-ue,l=de-Pt,d=r.length>1?f/(r.length-1):f,m=x=>ue+x*d,u=x=>l-x/i*l,g=Math.max(1,Math.ceil(r.length/8)),y=4,v=Array.from({length:y+1},(x,b)=>i/y*b);return e.jsxs("div",{className:`${C} p-4`,children:[e.jsx(w,{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(x=>e.jsx("button",{onClick:()=>c(x),className:`px-2 py-0.5 ${o===x?"bg-accent text-white":"text-fg-faint hover:text-fg"}`,children:x},x))})}),e.jsxs("svg",{width:"100%",viewBox:`0 0 ${le} ${de}`,className:"overflow-visible",children:[v.map((x,b)=>e.jsxs("g",{children:[e.jsx("line",{x1:ue,x2:le,y1:u(x),y2:u(x),stroke:"currentColor",className:"text-line",strokeWidth:1}),e.jsx("text",{x:0,y:u(x)+3,fontSize:9,className:"fill-fg-faint",children:o==="share"?`${Math.round(x*100)}%`:Ut(s,x)})]},b)),r.map((x,b)=>{if(b===0)return null;const P=r[b-1];return x.bands.map((j,ee)=>{const q=P.bands[ee],W=n!==null&&n!==j.projectDir,te=W?Ct:D(j.projectDir),se=[`${m(b-1)},${u(q.y0)}`,`${m(b)},${u(j.y0)}`,`${m(b)},${u(j.y1)}`,`${m(b-1)},${u(q.y1)}`].join(" ");return e.jsx("polygon",{points:se,fill:te,opacity:W?.6:.75,className:"cursor-pointer",onClick:()=>a(n===j.projectDir?null:j.projectDir),children:e.jsx("title",{children:H(j.projectDir)})},`${j.projectDir}-${b}`)})}),r.map((x,b)=>b%g!==0&&b!==r.length-1?null:e.jsx("text",{x:m(b),y:de-4,fontSize:9,textAnchor:"middle",className:"fill-fg-faint",children:x.date.slice(5)},x.date))]})]})}function Lt({rows:t,measure:s,selected:n,onSelect:a}){return t.length?e.jsxs("div",{className:`${C} overflow-hidden`,children:[e.jsx("div",{className:"p-4 pb-0",children:e.jsx(w,{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 c=D(o.projectDir),r=n===o.projectDir;return e.jsxs("tr",{onClick:()=>a(o.projectDir),className:`border-t border-line hover:bg-bg-elev cursor-pointer ${r?"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:c}}),H(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:c}})})}),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"?"▼":"·"," ",_e(Math.abs(o.trend.pct))]})}),e.jsx("td",{className:"px-3 py-2 text-fg-faint font-mono",children:B(o.sessions)}),e.jsx("td",{className:"px-3 py-2 text-fg-faint font-mono",children:o.topTool||"—"})]},o.projectDir)})})]})]}):e.jsxs("div",{className:`${C} p-4`,children:[e.jsx(w,{kicker:"03 · by project",title:"Ranking"}),e.jsx("div",{className:"text-xs text-fg-faint",children:"no projects in range"})]})}function Ft({projectDir:t,totals:s,byModel:n,toolBreakdown:a,onClear:o}){var d;const c=E(s,"in"),r=E(s,"out"),i=Object.entries(n).sort((m,u)=>u[1].costUsd-m[1].costUsd),f=Object.entries(a).sort((m,u)=>u[1]-m[1]),l=((d=f[0])==null?void 0:d[1])??0;return e.jsxs("div",{className:`${C} p-4`,children:[e.jsx(w,{kicker:"04 · drill in",title:H(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:D(t)}})}),e.jsxs("div",{className:"grid grid-cols-6 gap-3 mb-4",children:[e.jsx(O,{label:"prompts",value:B(s.promptCount)}),e.jsx(O,{label:"sessions",value:B(s.sessionCount)}),e.jsx(O,{label:"in tokens",value:I(c)}),e.jsx(O,{label:"out tokens",value:I(r)}),e.jsx(O,{label:"spend",value:$(s.estimatedCostUsd)}),e.jsx(O,{label:"time",value:Oe(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"}),i.length===0?e.jsx("div",{className:"text-xs text-fg-faint",children:"no model data"}):e.jsx("div",{className:"space-y-1",children:i.map(([m,u])=>e.jsxs("div",{className:"flex items-center justify-between text-[11px] font-mono text-fg-dim",children:[e.jsx("span",{children:me(m)}),e.jsx("span",{className:"text-fg-faint",children:$(u.costUsd)})]},m))})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] text-fg-faint uppercase tracking-wider mb-1.5",children:"tool mix"}),f.length===0?e.jsx("div",{className:"text-xs text-fg-faint",children:"no tool data"}):e.jsx("div",{className:"space-y-1",children:f.slice(0,6).map(([m,u])=>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:m}),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:`${l>0?u/l*100:0}%`}})}),e.jsx("span",{className:"text-fg-faint font-mono w-8 text-right",children:u})]},m))})]})]})]})}function O({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 _t({byModelTotals:t}){const s=Object.entries(t).sort((a,o)=>o[1].costUsd-a[1].costUsd),n=s.reduce((a,[,o])=>a+o.costUsd,0);return e.jsxs("div",{className:`${C} p-4`,children:[e.jsx(w,{kicker:"05 · composition",title:"Model mix",right:e.jsxs("span",{className:"text-xs font-mono text-fg-faint",children:[$(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(([a,o])=>{const c=n>0?o.costUsd/n*100:0,r=D(a);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:r}}),me(a),o.estimated&&e.jsx("span",{className:"text-fg-faint",children:"(est.)"})]}),e.jsxs("span",{className:"text-fg-faint whitespace-nowrap ml-2",children:[$(o.costUsd)," · ",c.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(c,c>0?2:0)}%`,backgroundColor:r}})})]},a)})})]})}const Ot={epic:"Epic sessions",job:"Scheduler jobs",task:"Tasks",other:"Other sessions"};function Ht({byLauncherTotals:t}){const s=mt.map(a=>{var o;return[a,((o=t[a])==null?void 0:o.costUsd)??0]}),n=s.reduce((a,[,o])=>a+o,0);return e.jsxs("div",{className:`${C} p-4`,children:[e.jsx(w,{kicker:"05 · composition",title:"Launcher mix",right:e.jsxs("span",{className:"text-xs font-mono text-fg-faint",children:[$(n)," total"]})}),n<=0?e.jsx("div",{className:"text-xs text-fg-faint",children:"no usage in range"}):e.jsx("div",{className:"space-y-2",children:s.map(([a,o])=>{const c=o/n*100,r=D(a);return e.jsxs("div",{"data-testid":`history-launcher-${a}`,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:r}}),Ot[a]]}),e.jsxs("span",{className:"text-fg-faint whitespace-nowrap ml-2",children:[$(o)," · ",c.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(c,c>0?2:0)}%`,backgroundColor:r}})})]},a)})})]})}function Bt({rows:t}){const s=t.slice(0,3),n=s.reduce((c,r)=>c+r.sharePct,0),a=t.slice(3),o=a.reduce((c,r)=>c+r.sharePct,0);return e.jsxs("div",{className:`${C} p-4`,children:[e.jsx(w,{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(c=>e.jsx("div",{style:{width:`${Math.max(c.sharePct,.5)}%`,backgroundColor:D(c.projectDir)},title:`${H(c.projectDir)} · ${c.sharePct.toFixed(1)}%`},c.projectDir))}),e.jsx("div",{className:"space-y-1 mb-2",children:s.map(c=>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:D(c.projectDir)}}),H(c.projectDir)]}),e.jsxs("span",{className:"text-fg-faint",children:[c.sharePct.toFixed(1),"%"]})]},c.projectDir))}),a.length>0&&e.jsxs("p",{className:"text-[10px] text-fg-faint",children:[a.length," more project",a.length===1?"":"s"," account for ",o.toFixed(1),"% (long tail)."]})]})]})}const J=30,pe=9,A=(J+pe)*2;function It({totals:t}){const s=t.inputTokens+t.cacheReadTokens+t.cacheCreationTokens,n=s>0?t.cacheReadTokens/s*100:0,a=2*Math.PI*J,o=A/2;return e.jsxs("div",{className:`${C} p-4`,children:[e.jsx(w,{kicker:"05 · composition",title:"Cache"}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("div",{className:"relative shrink-0",style:{width:A,height:A},children:[e.jsxs("svg",{width:A,height:A,viewBox:`0 0 ${A} ${A}`,className:"-rotate-90",children:[e.jsx("circle",{cx:o,cy:o,r:J,fill:"none",stroke:"currentColor",className:"text-bg-hi",strokeWidth:pe}),e.jsx("circle",{cx:o,cy:o,r:J,fill:"none",stroke:wt,strokeWidth:pe,strokeDasharray:a,strokeDashoffset:a*(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 Wt=.05,qt="—",Ue=t=>`$${t.toFixed(2)}`;function Kt(){const[t,s]=p.useState(null),[n,a]=p.useState(null),o=Fe(r=>r.show);p.useEffect(()=>{let r=!0;const i=()=>{window.api.history.loopEfficiency().then(l=>{r&&(s(l),a(null))}).catch(l=>{if(!r)return;const d=l instanceof Error?l.message:String(l);a(d),o("error",`Loop efficiency failed to load: ${d}`)})};i();const f=window.api.history.onUpdated(i);return()=>{r=!1,f()}},[o]);let c;if(n&&!t)c=e.jsxs("div",{"data-testid":"loop-eff-error",className:"text-[11px] font-mono text-fg-faint",children:["Failed to load: ",n]});else if(!t)c=e.jsx("div",{"data-testid":"loop-eff-loading",className:"text-[11px] font-mono text-fg-faint",children:"Loading…"});else if(t.rows.length===0)c=e.jsx("div",{"data-testid":"loop-eff-empty",className:"text-[11px] font-mono text-fg-faint",children:"No runs this week."});else{const r=t.totals.wastedRunRate>Wt;c=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(i=>e.jsxs("tr",{"data-testid":"loop-eff-row",children:[e.jsx("td",{children:i.project}),e.jsx("td",{className:"text-right",children:i.runs}),e.jsx("td",{className:"text-right",children:i.wastedRuns}),e.jsx("td",{className:"text-right",children:i.verified}),e.jsx("td",{className:"text-right",children:i.refuted}),e.jsx("td",{className:"text-right",children:Ue(i.executorUsd)}),e.jsx("td",{className:"text-right","data-testid":"loop-eff-per-verified",children:i.usdPerVerified==null?qt:Ue(i.usdPerVerified)})]},i.cwd))})]}),e.jsxs("div",{"data-testid":"loop-eff-totals","data-warning":r?"true":"false",className:`mt-2 text-[11px] font-mono ${r?"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:`${C} p-4`,"data-testid":"loop-efficiency",children:[e.jsx(w,{kicker:"06 · reliability",title:"Loop efficiency"}),c]})}const Z="—",Vt=Object.freeze({"not-landed":"nothing or the wrong thing was committed","gate-red":"a gate command fails","behavior-wrong":"runs but does not do what a criterion says","not-checked-live":"passes tests, wrong against real data or the real UI","missing-test":"a criterion or change has no test that checks it",regression:"breaks something that worked","spec-gap":"every criterion met but the goal is not",security:"introduces a security problem","docs-drift":"docs no longer match the code",other:"none of the above"}),Gt="Proposed for a human to approve: add it to standards.md or the validator persona through /develop.",Ae=t=>t==null?Z:`${t}%`;function zt(t,s){switch(s){case"firstPass":return Ae(t.firstPass.pct);case"refuted":return Ae(t.refuted.pct);case"fixWaves":return t.fixWaves.perPlan==null?Z:String(t.fixWaves.perPlan);case"escapes":return String(t.escapes.length)}}function Yt(t,s){switch(s){case"firstPass":return t.firstPass.prds;case"refuted":return t.refuted.prds;case"fixWaves":return t.fixWaves.plans.filter(n=>n.fixWaves.length>0).map(n=>`${n.plan}: ${n.fixWaves.join(", ")}`);case"escapes":return t.escapes.map(n=>`${n.fixPrd} fixes ${n.escapedPrd} — ${n.reason??Z}`)}}const fe=[{key:"firstPass",label:"First-pass verified"},{key:"refuted",label:"Refuted"},{key:"fixWaves",label:"Fix waves / plan"},{key:"escapes",label:"Escapes"}];function Xt(){var f;const[t,s]=p.useState(null),[n,a]=p.useState(null),[o,c]=p.useState(null),r=Fe(l=>l.show);p.useEffect(()=>{let l=!0;const d=g=>{l&&(a(g),r("error",`Validation quality failed to load: ${g}`))},m=()=>{window.api.history.validationQuality().then(g=>{if(l){if(!g.ok)return d(g.error);s(g.projects),a(null)}}).catch(g=>d(g instanceof Error?g.message:String(g)))};m();const u=window.api.history.onUpdated(m);return()=>{l=!1,u()}},[r]);let i;if(n&&!t)i=e.jsxs("div",{"data-testid":"val-q-error",className:"text-[11px] font-mono text-fg-faint",children:["Failed to load: ",n]});else if(!t)i=e.jsx("div",{"data-testid":"val-q-loading",className:"text-[11px] font-mono text-fg-faint",children:"Loading…"});else if(t.length===0)i=e.jsx("div",{"data-testid":"val-q-empty",className:"text-[11px] font-mono text-fg-faint",children:"No validated PRDs yet."});else{const l=o?t.find(u=>u.cwd===o.cwd):void 0,d=o&&l?Yt(l,o.metric):null,m=t.filter(u=>u.week.topMiss||u.week.unclassified.count>0);i=e.jsxs(e.Fragment,{children:[e.jsxs("table",{className:"w-full text-[11px] font-mono","data-testid":"val-q-table",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-fg-faint text-left",children:[e.jsx("th",{className:"font-normal",children:"Project"}),fe.map(u=>e.jsx("th",{className:"font-normal text-right",children:u.label},u.key))]})}),e.jsx("tbody",{className:"text-fg-dim",children:t.map(u=>e.jsxs("tr",{"data-testid":"val-q-row",children:[e.jsx("td",{children:u.project}),fe.map(g=>{const y=(o==null?void 0:o.cwd)===u.cwd&&o.metric===g.key;return e.jsx("td",{className:"text-right",children:e.jsx("button",{type:"button","data-testid":`val-q-${g.key}`,"aria-expanded":y,className:"underline decoration-dotted hover:text-fg",onClick:()=>c(y?null:{cwd:u.cwd,metric:g.key}),children:zt(u,g.key)})},g.key)})]},u.cwd))})]}),o&&l&&d&&e.jsxs("div",{"data-testid":"val-q-detail",className:"mt-2 text-[11px] font-mono text-fg-dim",children:[e.jsxs("div",{className:"text-fg-faint",children:[l.project," · ",(f=fe.find(u=>u.key===o.metric))==null?void 0:f.label]}),d.length===0?e.jsx("div",{className:"text-fg-faint",children:"No PRDs."}):e.jsx("ul",{children:d.map(u=>e.jsx("li",{"data-testid":"val-q-detail-item",children:u},u))})]}),e.jsxs("div",{"data-testid":"val-q-week",className:"mt-3 text-[11px] font-mono text-fg-dim",children:[e.jsx("div",{className:"text-fg-faint",children:"This week"}),m.length===0?e.jsx("div",{"data-testid":"val-q-week-empty",children:"No validator misses this week."}):m.map(u=>{const g=u.week.topMiss,y=u.week.unclassified;return e.jsxs("div",{children:[g&&e.jsxs("div",{"data-testid":"val-q-top-miss",className:"mt-1",children:[e.jsxs("div",{children:[u.project,": ",e.jsx("span",{className:"text-fg",children:g.missKind})," — ",Vt[g.missKind]??Z," ·"," ",g.count,"×"]}),e.jsxs("div",{children:["PRDs: ",g.prds.join(", ")]}),g.reasons.length>0&&e.jsx("ul",{className:"list-disc pl-4",children:g.reasons.slice(0,5).map(v=>e.jsx("li",{"data-testid":"val-q-reason",children:v},v))}),e.jsxs("div",{"data-testid":"val-q-proposal",children:["Proposed check: ",g.proposal]}),e.jsx("div",{className:"text-fg-faint",children:Gt})]}),y.count>0&&e.jsxs("div",{"data-testid":"val-q-unclassified",className:"mt-1",children:[e.jsxs("div",{children:[u.project,": Not classified (recorded before checked verdicts): ",y.count]}),e.jsxs("div",{children:["PRDs: ",y.prds.join(", ")]}),y.reasons.length>0&&e.jsx("ul",{className:"list-disc pl-4",children:y.reasons.slice(0,5).map(v=>e.jsx("li",{"data-testid":"val-q-unclassified-reason",children:v},v))})]})]},u.cwd)})]})]})}return e.jsxs("div",{className:`${C} p-4`,"data-testid":"validation-quality",children:[e.jsx(w,{kicker:"07 · reliability",title:"Validation quality"}),i]})}const Qt=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];function Jt({days:t,measure:s}){const{buckets:n,weekendShare:a,peakIdx:o}=p.useMemo(()=>{const r=new Array(7).fill(0);for(const d of t){const[m,u,g]=d.date.split("-").map(Number),y=new Date(m,u-1,g).getDay();r[y]+=E(d.totals,s)}const i=r.reduce((d,m)=>d+m,0),f=r[0]+r[6];let l=0;for(let d=1;d<7;d++)r[d]>r[l]&&(l=d);return{buckets:r,weekendShare:i>0?f/i*100:0,peakIdx:l}},[t,s]),c=Math.max(...n,1);return e.jsxs("div",{className:`${C} p-4`,children:[e.jsx(w,{kicker:"05 · composition",title:"Rhythm",right:e.jsxs("span",{className:"text-xs font-mono text-fg-faint",children:["weekend ",a.toFixed(0),"%"]})}),e.jsx("div",{className:"flex items-end gap-2 h-24",children:n.map((r,i)=>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 ${i===o?"bg-accent":"bg-rhythm"}`,style:{height:`${c>0?r/c*100:0}%`,minHeight:r>0?2:0}}),e.jsx("span",{className:"text-[9px] text-fg-faint font-mono",children:Qt[i]})]},i))})]})}const Zt=["in","out","total","prompts","sessions","time","spend"],es=[30,60,90,0],ts="spend",ss=30,ns=3e4,os=[];function as(){var Te;const[t,s]=p.useState(ts),[n,a]=p.useState(ss),o=p.useRef(!1),c=p.useRef(!1),r=h=>{o.current=!0;const k=t;s(h),he({measure:h}).catch(()=>{s(k),X.error("Couldn't save the measure preference — reverted.")})},i=h=>{c.current=!0;const k=n;a(h),he({range:h}).catch(()=>{a(k),X.error("Couldn't save the range preference — reverted.")})};p.useEffect(()=>{let h=!1;return ge().then(k=>{h||(!o.current&&k.measure&&Zt.includes(k.measure)&&s(k.measure),!c.current&&k.range!==void 0&&es.includes(k.range)&&a(k.range))}),()=>{h=!0}},[]);const f=tt(h=>h.navFace),l=Ce(h=>h.tabs),d=Ce(h=>h.activeTabId),m=((Te=l.find(h=>h.id===d))==null?void 0:Te.cwd)??null,u=p.useRef(f),g=m?st(m):null,[y,v]=p.useState(null),x=p.useMemo(()=>f==="project"&&g?new Set([g]):y,[f,g,y]),[b,P]=p.useState(null),[j,ee]=p.useState(null),[q,W]=p.useState(!0),[te,se]=p.useState(0),ne=p.useRef(n);ne.current=n;const K=p.useRef(!0),oe=p.useRef(0),je=p.useRef(0),L=p.useRef(null),V=p.useCallback(h=>{const k=ne.current;oe.current+=1,je.current=Date.now(),rt(k).then(N=>{if(oe.current-=1,!(!K.current||k!==ne.current)){if(W(!1),N.ok){ee(N.data);return}h||X.error(`History analytics failed to load: ${N.error}`)}})},[]);p.useEffect(()=>{K.current=!0,W(!0),V(!1)},[n,te,V]),p.useEffect(()=>{const h=()=>{if(!K.current)return;const R=je.current+ns-Date.now();if(oe.current===0&&R<=0){V(!0);return}L.current||(L.current=setTimeout(()=>{L.current=null,h()},Math.max(R,1e3)))},k=()=>{document.visibilityState==="visible"&&h()},N=window.api.history.onUpdated(h);return window.addEventListener("focus",h),document.addEventListener("visibilitychange",k),()=>{K.current=!1,N(),window.removeEventListener("focus",h),document.removeEventListener("visibilitychange",k),L.current&&(clearTimeout(L.current),L.current=null)}},[V]);const ve=p.useRef(!1);p.useEffect(()=>{if(!ve.current){ve.current=!0;return}v(null),P(null)},[n]),p.useEffect(()=>{u.current!==f&&(u.current=f,f==="home"&&v(null))},[f]);const{projects:be,resolving:ke}=nt(),ye=p.useMemo(()=>{const h={};for(const k of be)for(const N of k.encodedIds)h[N]=k.cwd;return h},[be]),F=p.useMemo(()=>j&&!ke?vt(j.days,ye):null,[j,ye,ke]),S=(F==null?void 0:F.days)??(j==null?void 0:j.days)??os,ae=(F==null?void 0:F.excluded)??null,M=p.useMemo(()=>j?it({days:S,totals:j.totals,prevTotals:j.prevTotals},x):null,[j,S,x]),_=p.useMemo(()=>x===null?S:S.map(h=>({date:h.date,byProject:Object.fromEntries(Object.entries(h.byProject).filter(([k])=>x.has(k)))})),[S,x]),G=p.useMemo(()=>Se(S,t),[S,t]),re=p.useMemo(()=>Se(_,t),[_,t]),We=p.useMemo(()=>_.map(h=>({date:h.date,values:Object.fromEntries(Object.entries(h.byProject).map(([k,N])=>[k,E(N,t)]))})),[_,t]),Ne=p.useMemo(()=>M?ft(M,t):null,[M,t]),z=p.useMemo(()=>{if(!j||!b)return null;const h=S.flatMap(T=>T.byProject[b]?[T.byProject[b]]:[]),{byModel:k,...N}=Re(h),R={};for(const T of h)for(const[U,ce]of Object.entries(T.toolBreakdown))R[U]=(R[U]??0)+ce;return{totals:N,byModel:k,toolBreakdown:R}},[j,S,b]);p.useEffect(()=>{b&&x!==null&&!x.has(b)&&P(null)},[b,x]);function qe(h){v(k=>{const N=new Set(G.map(U=>U.projectDir)),R=k??new Set(N),T=new Set(R);return T.has(h)?T.delete(h):T.add(h),T.size>=N.size?null:T})}function Ke(h){v(new Set([h]))}function Ve(){v(null)}function Ge(){if(!j)return;const h=_.map(U=>{const{byModel:ce,estimatedCostUsd:ze,inputTokens:Ye,outputTokens:Xe,cacheCreationTokens:Qe,cacheReadTokens:Je}=Re(Object.values(U.byProject));return{date:U.date,costUsd:ze,inputTokens:Ye,outputTokens:Xe,cacheCreationTokens:Qe,cacheReadTokens:Je,byModel:ce}}),k=pt(h),N=new Blob([k],{type:"text/csv"}),R=URL.createObjectURL(N),T=document.createElement("a");T.href=R,T.download=`usage-history-${j.from}-${j.to}.csv`,T.click(),URL.revokeObjectURL(R)}return q&&!j?e.jsx(Le,{}):j&&j.days.length===0?e.jsx(ot,{title:"no sessions in range",hint:"Widen the range or check back after your next session."}):!j||!M||!Ne?e.jsx(Le,{}):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(Tt,{measure:t,onMeasure:r,range:n,onRange:i,projectsShown:x===null?G.length:x.size,projectsTotal:G.length,fromDate:j.from,toDate:j.to,onRefresh:()=>se(h=>h+1),onExport:Ge,exportDisabled:_.length===0}),e.jsxs("div",{className:"flex-1 min-h-0 overflow-auto p-4 space-y-4",children:[e.jsx(Rt,{measure:t,headline:Ne,activeDays:M.activeDays,projectsTouched:re.length,totalSessions:M.totals.sessionCount}),e.jsx($t,{days:S}),ae&&bt(ae)&&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:kt(ae)}),j.legacyDates&&j.legacyDates.length>0&&e.jsx("div",{"data-testid":"history-legacy-note",className:"rounded-[10px] border border-line bg-bg-hi px-3 py-2 text-[11.5px] font-mono text-fg-faint",children:rs(j.legacyDates)}),f==="home"&&e.jsx(Et,{chips:G.map(h=>({projectDir:h.projectDir,value:h.value})),keep:x,onToggle:qe,onIsolate:Ke,onShowAll:Ve}),e.jsx(At,{days:We,measure:t,selected:b,onSelect:P}),e.jsx(Lt,{rows:re,measure:t,selected:b,onSelect:P}),b&&z&&e.jsx(Ft,{projectDir:b,totals:z.totals,byModel:z.byModel,toolBreakdown:z.toolBreakdown,onClear:()=>P(null)}),e.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-4",children:[e.jsx(_t,{byModelTotals:M.byModelTotals}),e.jsx(Ht,{byLauncherTotals:M.byLauncherTotals}),e.jsx(Bt,{rows:re}),e.jsx(It,{totals:M.totals}),e.jsx(Jt,{days:M.days,measure:t})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:[e.jsx(Kt,{}),e.jsx(Xt,{})]})]})]})}function rs(t){const s=t.reduce((a,o)=>o>a?o:a),n=t.length;return`${n} ${n===1?"day":"days"} in this range (last: ${s}) were counted with the older method and read about two to three times too high; they cannot be recounted because their transcripts are gone.`}function Le(){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 cs(){return e.jsx(at,{children:e.jsx(as,{})})}const fs=p.memo(cs);export{fs as History};