claude-code-session-manager 0.116.1 → 0.118.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{AgentLibrary-CkS69HnN.js → AgentLibrary-CEI6vsmu.js} +2 -2
- package/dist/assets/{Button-BQxkfIbW.js → Button-BuyzGzO8.js} +1 -1
- package/dist/assets/{DataModel-YVgdJTZF.js → DataModel-CbXI_rEf.js} +1 -1
- package/dist/assets/{History-DneHh4jI.js → History-axy4nJyY.js} +2 -2
- package/dist/assets/{Hooks-Bt4xIjfo.js → Hooks-D5ghOppL.js} +3 -3
- package/dist/assets/{Library-DoP5FdXq.js → Library-wBI4Fwh3.js} +7 -7
- package/dist/assets/{ListDetail-BYxyl13e.js → ListDetail-CY5hhwn9.js} +1 -1
- package/dist/assets/{McpServers-CKm_iZsf.js → McpServers-CwEVZqfu.js} +2 -2
- package/dist/assets/Memory-Beh2r4Xk.js +25 -0
- package/dist/assets/{Panel-Cv8aYElQ.js → Panel-yOYf80ax.js} +1 -1
- package/dist/assets/{Permissions-CFmWwqyV.js → Permissions-DA-SMXO3.js} +3 -3
- package/dist/assets/{Plugins-CuYNgf_d.js → Plugins-qfKt6BxH.js} +2 -2
- package/dist/assets/ProvenanceBadge-DFyBe7Po.js +1 -0
- package/dist/assets/RemoteMachines-AG0K7kqS.js +3 -0
- package/dist/assets/{SaveBar-Cb4Q8TBK.js → SaveBar-35Nw2YsZ.js} +1 -1
- package/dist/assets/{Scheduler-ysJHQvW4.js → Scheduler-BPBAU0TO.js} +8 -8
- package/dist/assets/{ScopeSwitcher-BTOWfifI.js → ScopeSwitcher-BCXNrrrs.js} +1 -1
- package/dist/assets/{Settings-C6fH8diZ.js → Settings-C4yhzfZI.js} +4 -4
- package/dist/assets/{SkillReferenceGraph-esAcniTQ.js → SkillReferenceGraph-Ca5z2avC.js} +1 -1
- package/dist/assets/{Skills-4_vqzrSF.js → Skills-5WWusmKG.js} +1 -1
- package/dist/assets/SystemPrompt-ofVCdHAW.js +1 -0
- package/dist/assets/TagLibrary-rSrpD-Bz.js +1 -0
- package/dist/assets/{TiptapBody-EkZlmD9k.js → TiptapBody-DAYcdcVt.js} +1 -1
- package/dist/assets/{Toggle-CpR97XGM.js → Toggle-BzHdpXZI.js} +1 -1
- package/dist/assets/{ViewTabs-ekJfFek8.js → ViewTabs-D82jJ4VS.js} +1 -1
- package/dist/assets/{historyTotals-Bg0GVcsF.js → historyTotals-DMGFqK5h.js} +1 -1
- package/dist/assets/{index-CZsDDyLy.css → index-DAMBm3UN.css} +1 -1
- package/dist/assets/{index-DQSEUdx0.js → index-DZ5TJKNI.js} +501 -500
- package/dist/assets/{settingsSchema-BG5jZbhn.js → settingsSchema-BfnNE6ne.js} +1 -1
- package/dist/assets/{skillFrontmatter-DF6xI6Wb.js → skillFrontmatter-ED1DjPE1.js} +1 -1
- package/dist/assets/{useAgentsDirWatch-Dox-xCx9.js → useAgentsDirWatch-CbpQIu3P.js} +1 -1
- package/dist/assets/{useRemotePeers-DHo62LbA.js → useRemotePeers-Dy_o0WlY.js} +1 -1
- package/dist/index.html +2 -2
- package/package.json +1 -1
- package/plugins/session-manager-dev/skills/develop/SKILL.md +23 -10
- package/scripts/scheduler-mcp-server.cjs +16 -1
- package/src/main/build-info.json +4 -4
- package/src/main/lib/epic/epicSettle.cjs +105 -0
- package/src/main/lib/epic/epicSweepValidator.cjs +74 -0
- package/src/main/lib/epic/epicValidationHook.cjs +171 -141
- package/src/main/lib/feedback-remote/macroAdminRoutes.cjs +2 -1
- package/src/main/lib/git/gitWorktree.cjs +7 -0
- package/src/main/lib/git/worktreeDeps.cjs +77 -0
- package/src/main/lib/mcpToolCatalog.cjs +6 -2
- package/src/main/lib/memoryMdNetwork.cjs +121 -0
- package/src/main/lib/memoryRefResolve.cjs +64 -0
- package/src/main/lib/memoryStale.cjs +27 -11
- package/src/main/lib/persona-macro/macroLibrary.cjs +49 -2
- package/src/main/lib/scheduler/baselineGate.cjs +128 -0
- package/src/main/lib/scheduler/definitionOfDone.cjs +9 -3
- package/src/main/lib/scheduler/needsReviewLedger.cjs +1 -1
- package/src/main/lib/scheduler/reviewNotice.cjs +53 -0
- package/src/main/memoryAssist.cjs +71 -31
- package/src/main/memoryTool.cjs +18 -6
- package/src/main/promptSessionEvents.cjs +6 -2
- package/src/main/runVerify.cjs +39 -3
- package/src/main/scheduler/reviewLadder.cjs +25 -6
- package/src/main/scheduler.cjs +121 -62
- package/src/main/templates/PRD_AUTHORING.md +2 -0
- package/src/preload/api.d.ts +24 -2
- package/dist/assets/Memory-BWMQuAoC.js +0 -18
- package/dist/assets/ProvenanceBadge-BMLVPyHr.js +0 -1
- package/dist/assets/RemoteMachines-D04Mby_W.js +0 -3
- package/dist/assets/SystemPrompt-CdUq4KXx.js +0 -1
- package/dist/assets/TagLibrary-CVFIphBv.js +0 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
2
|
-
`)}function Se(){const[n,s]=y.useState(null),[r,d]=y.useState(null),[o,l]=y.useState(""),[i,x]=y.useState(null),[L,h]=y.useState(!1),[w,v]=y.useState(!1),[N,u]=y.useState(null),[b,j]=y.useState(!1),E=y.useRef(!0);y.useEffect(()=>()=>{E.current=!1},[]);const a=le(t=>{var m;return((m=t.tabs.find(k=>k.id===t.activeTabId))==null?void 0:m.cwd)??null}),g=a?a.replace(/\/+$/,"").split("/").pop()||a:null,C=y.useRef(0),S=async t=>{const m=++C.current;try{const k=await window.api.agents.listPersonas();if(!E.current||C.current!==m)return;s(k),d(W=>{var P;return t??W??((P=k[0])==null?void 0:P.name)??null})}catch(k){if(!E.current||C.current!==m)return;s([]),$.error(k.message||"failed to load agent personas")}};if(y.useEffect(()=>{S()},[]),y.useEffect(()=>window.api.agents.onChanged(()=>S()),[]),ue(a,()=>S()),y.useEffect(()=>{const t=de();t&&d(t);const m=k=>d(k.detail);return window.addEventListener("sm:select-persona",m),()=>window.removeEventListener("sm:select-persona",m)},[]),n===null)return e.jsx(z,{title:"loading…"});const T=o.toLowerCase(),F=n.filter(t=>!T||t.name.toLowerCase().includes(T)||(t.description??"").toLowerCase().includes(T)),f=n.find(t=>t.name===r)??n[0]??null,c=i??(f?G(f):null),B=!!i&&!!f&&JSON.stringify(i)!==JSON.stringify(G(f)),O=L,I=t=>{x(null),h(!1),v(!1),u(null),d(t)},p=t=>x(m=>({...m??(f?G(f):q),...t})),V=()=>{x({...q}),h(!0),v(!1)},te=()=>{c&&(x({...c,name:c.name+"-copy"}),h(!0))},ne=()=>{x(null),h(!1)},se=async()=>{if(c){if(!/^[a-z][a-z0-9-]*$/.test(c.name)){$.error('agent name must be lowercase, hyphenated (e.g. "my-agent")');return}j(!0);try{const t=O?null:f,m={name:c.name,originalName:t==null?void 0:t.name,description:c.description,tools:c.tools,model:c.model,effort:c.effort,color:c.color,tags:ge(c.tags),body:c.body},k=t?ve(t,m):m;await window.api.agents.savePersona(k),$.info(O?`created ${c.name}`:`saved ${c.name}`),x(null),h(!1),await S(c.name)}catch(t){$.error(t.message||"failed to save agent persona")}finally{j(!1)}}},ae=async()=>{if(f){j(!0);try{await window.api.agents.deletePersona({name:f.name}),$.info(`deleted ${f.name}`),v(!1),x(null),h(!1),await S()}catch(t){$.error(t.message||"failed to delete agent persona")}finally{j(!1)}}},oe=async t=>{j(!0);try{await window.api.agents.deletePersona({name:t}),$.info(`deleted ${t}`),u(null),r===t&&(x(null),h(!1)),await S()}catch(m){$.error(m.message||"failed to delete agent persona")}finally{j(!1)}},re=async t=>{if(f)try{await window.api.agents.removeOverride({name:f.name,projectName:t}),$.info(`removed ${t}'s override of ${f.name}`),await S(f.name)}catch(m){$.error(m.message||"failed to remove override")}},ie=async t=>{if(!(!f||!g)){j(!0);try{t.model==="inherit"&&t.effort==="inherit"?(await window.api.agents.removeOverride({name:f.name,projectName:g}),$.info(`cleared ${g}'s override of ${f.name}`)):(await window.api.agents.savePersona({name:f.name,projectName:g,description:"",tools:[],color:"",tags:[],body:"",model:t.model,effort:t.effort}),$.info(`saved ${g}'s override of ${f.name}`)),await S(f.name)}catch(m){$.error(m.message||"failed to save project override")}finally{j(!1)}}};return e.jsx(he,{toolbar:e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"text-fg-faint",children:[n.length," persona",n.length===1?"":"s"]}),e.jsx("input",{value:o,onChange:t=>l(t.target.value),placeholder:"filter…",className:"bg-bg border border-line rounded px-2 py-0.5 text-xs text-fg w-40"}),e.jsx("div",{className:"flex-1"}),e.jsx(R,{variant:"primary",onClick:V,children:"+ New agent"})]}),children:e.jsx(pe,{sidebar:e.jsxs("div",{className:"py-1",children:[O&&e.jsx("div",{className:"w-full text-left px-3 py-1 text-xs flex flex-col gap-0.5 bg-bg-hi text-fg border-l-2 border-accent",children:e.jsxs("span",{className:"flex items-center gap-2 justify-between w-full",children:[e.jsx("span",{className:"truncate font-mono",children:c==null?void 0:c.name}),e.jsx("span",{className:"shrink-0 text-[10px] font-semibold text-accent",children:"new"})]})}),F.length===0&&!O?e.jsx("div",{className:"px-3 py-1 text-xs text-fg-faint italic",children:"no agent personas found"}):F.map(t=>{const m=!O&&t.name===r,k=m&&B,W=N===t.name;return e.jsxs("div",{"data-agent-row":t.name,className:`group w-full text-left px-3 py-1 text-xs flex flex-col gap-0.5 border-l-2 cursor-pointer ${m?"bg-bg-hi text-fg border-accent":"text-fg-dim hover:text-fg hover:bg-bg-hi border-transparent"}`,onClick:()=>I(t.name),children:[e.jsxs("span",{className:"flex items-center gap-2 justify-between w-full",children:[e.jsxs("span",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsx("span",{className:"w-2 h-2 rounded-sm shrink-0",style:{background:t.color?X[t.color]??t.color:"var(--fg-faint, #999)",opacity:t.color?1:.35}}),e.jsx("span",{className:"truncate font-mono",children:t.name})]}),e.jsxs("span",{className:"shrink-0 flex items-center gap-1.5",children:[k&&e.jsx("span",{className:"text-[10px] font-semibold text-accent",children:"unsaved"}),!k&&t.overridingProjects.length>0&&e.jsx("span",{title:$e(t),children:e.jsxs(M,{tone:"dim",children:[t.overridingProjects.length," override",t.overridingProjects.length>1?"s":""]})}),W?e.jsxs("span",{className:"flex items-center gap-1",onClick:P=>P.stopPropagation(),children:[e.jsx("button",{onClick:()=>oe(t.name),disabled:b,title:`Delete ${t.name}`,className:"text-[10px] font-semibold text-red-400 hover:text-red-300",children:"confirm"}),e.jsx("button",{onClick:()=>u(null),title:"Cancel",className:"text-[10px] text-fg-faint hover:text-fg",children:"cancel"})]}):e.jsx("button",{onClick:P=>{P.stopPropagation(),u(t.name)},title:`Delete ${t.name}`,className:"opacity-0 group-hover:opacity-100 text-fg-faint hover:text-red-400 transition-opacity",children:"×"})]})]}),t.description&&e.jsx("span",{className:"truncate text-fg-faint",children:t.description})]},t.name)})]}),detail:c?e.jsx(Le,{obj:c,set:p,saved:f,dirty:B,isNew:O,busy:b,confirmDelete:w,setConfirmDelete:v,onDuplicate:te,onRevert:ne,onSave:se,onDelete:ae,onDropOverride:re,activeProject:g,onSaveOverride:ie}):e.jsx(z,{title:"select an agent"})})})}const Be=y.memo(Se);function Le({obj:n,set:s,saved:r,dirty:d,isNew:o,busy:l,confirmDelete:i,setConfirmDelete:x,onDuplicate:L,onRevert:h,onSave:w,onDelete:v,onDropOverride:N,activeProject:u,onSaveOverride:b}){const j=`~/.claude/agents/${n.name}.md`,E=d||o;return e.jsxs("div",{className:"max-w-3xl",children:[e.jsxs("div",{className:"px-4 py-3 border-b border-line flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"text-sm font-semibold text-fg font-mono",children:n.name}),o?e.jsx(M,{tone:"accent",children:"unsaved draft"}):d?e.jsx(M,{tone:"warn",children:"edited"}):e.jsx(M,{tone:"good",children:"saved"}),e.jsx("span",{className:"ml-auto text-[11px] text-fg-faint font-mono",children:j})]}),e.jsxs("div",{className:"p-4 space-y-4",children:[e.jsx(D,{label:"name",hint:"Filename on disk — lowercase, hyphenated.",children:e.jsx("input",{value:n.name,onChange:a=>s({name:a.target.value.toLowerCase()}),className:"w-full bg-bg border border-line rounded px-2 py-1 text-xs text-fg font-mono"})}),e.jsx(D,{label:"description",hint:"Shown in the list and in agent pickers.",children:e.jsx("input",{value:n.description,onChange:a=>s({description:a.target.value}),className:"w-full bg-bg border border-line rounded px-2 py-1 text-xs text-fg"})}),e.jsx(Z,{value:n.model,onChange:a=>s({model:a})}),e.jsx(ee,{value:n.effort,model:n.model,onChange:a=>s({effort:a})}),!o&&r&&e.jsx(Ee,{saved:r,activeProject:u,busy:l,onSave:b}),e.jsx(D,{label:"tools",hint:`${n.tools.length} of ${U.length} granted. Anything not ticked is refused at call time.`,children:e.jsx("div",{className:"flex flex-wrap gap-1.5",children:U.map(a=>{const g=n.tools.includes(a);return e.jsx("button",{onClick:()=>s({tools:g?n.tools.filter(C=>C!==a):[...n.tools,a]}),className:`px-2 py-0.5 rounded-full text-[11px] font-mono border ${g?"bg-sage/15 text-sage-dark border-sage/30":"bg-bg-hi text-fg-faint border-line"}`,children:a},a)})})}),e.jsx(D,{label:"color",children:e.jsx("div",{className:"flex gap-1.5",children:ke.map(a=>e.jsx("button",{title:a||"none",onClick:()=>s({color:a}),className:"w-5 h-5 rounded",style:{background:a?X[a]:"transparent",border:n.color===a?"2px solid var(--accent, #b85c34)":"1px solid var(--line, #555)"}},a||"none"))})}),e.jsx(D,{label:"tags",hint:"Session mission tags this persona is associated with — shown as the default agent on that tag's own page. The first one (in Tag Library order) is the MISSION an Action button's session opens with.",children:e.jsx("div",{className:"flex flex-wrap gap-1.5",children:ce.map(a=>{const g=n.tags.includes(a.tag),C=fe(a.tag);return e.jsxs("button",{onClick:()=>s({tags:g?n.tags.filter(S=>S!==a.tag):[...n.tags,a.tag]}),className:`px-2 py-0.5 rounded-full text-[11px] font-mono border ${g?`${C.bg} ${C.text} ${C.border?"border-current/30":"border-transparent"}`:"bg-bg-hi text-fg-faint border-line"}`,children:["#",a.tag]},a.tag)})})}),e.jsx(D,{label:"definition",hint:"The system prompt this persona runs under.",children:e.jsx("textarea",{rows:9,value:n.body,onChange:a=>s({body:a.target.value}),className:"w-full bg-bg border border-line rounded px-2 py-1.5 text-xs text-fg font-mono leading-relaxed resize-y"})}),e.jsx(D,{label:"project overrides",hint:"Open projects that shadow this definition with a local copy.",children:r&&r.overridingProjects.length>0?e.jsx("div",{className:"flex flex-wrap gap-1.5",children:r.overridingProjects.map(a=>e.jsxs("span",{className:"inline-flex items-center gap-1.5 bg-bg-elev border border-line rounded px-2 py-0.5 text-[11px] font-mono text-fg-dim",children:[a,e.jsx("button",{onClick:()=>N(a),title:"Drop the local copy",className:"text-fg-faint hover:text-fg",children:"×"})]},a))}):e.jsx("div",{className:"text-xs text-fg-faint italic",children:o?"save first to see project overrides.":"no open project overlays this agent — the global definition applies everywhere."})})]}),e.jsx("div",{className:"px-4 py-2.5 border-t border-line flex items-center gap-2 flex-wrap",children:i?e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"text-xs text-fg-dim",children:["Delete ",e.jsx("strong",{className:"font-mono",children:n.name})," and its file?"]}),e.jsx(R,{variant:"danger",onClick:v,disabled:l,children:"Delete"}),e.jsx(R,{onClick:()=>x(!1),children:"Keep"})]}):e.jsxs(e.Fragment,{children:[e.jsx(R,{onClick:L,disabled:l,children:"Duplicate"}),!o&&e.jsx(R,{variant:"danger",onClick:()=>x(!0),disabled:l,children:"Delete"}),e.jsx("div",{className:"flex-1"}),E&&e.jsx("span",{className:"text-[11px] text-fg-faint",children:"unsaved changes"}),e.jsx(R,{onClick:h,disabled:!E||l,children:"Revert"}),e.jsx(R,{variant:"primary",onClick:w,disabled:!E||l,children:l?"Saving…":o?"Create":"Save"})]})})]})}function D({label:n,hint:s,children:r}){return e.jsxs("div",{children:[e.jsx("div",{className:"text-[10.5px] font-semibold uppercase tracking-wide text-fg-faint mb-1.5 font-mono",children:n}),r,s&&e.jsx("div",{className:"text-[11px] text-fg-faint mt-1 leading-snug",children:s})]})}const K="latest",H="Blocked by the availableModels allowlist in your Claude settings";function Z({value:n,onChange:s,label:r="default model",hint:d,testIdPrefix:o="",inheritLabel:l}){var O,I;const{catalog:i,loading:x,degraded:L,refresh:h}=Q(null),w=i?["inherit",...i.aliases]:[...me],v=(i==null?void 0:i.availableModels)??null,N=p=>!!v&&p!=="inherit"&&!v.includes(p),u=(p,V)=>!!v&&!v.includes(p)&&!(V&&v.includes(V)),b=n||"inherit",j=((O=/\[[^\]]*\]$/.exec(b))==null?void 0:O[0])??"",E=w.includes(b),a=!E&&i&&A(b)&&w.includes(A(b)+j)?A(b)+j:null,g=E?b:a??b,C=A(g),S=((I=/\[[^\]]*\]$/.exec(g))==null?void 0:I[0])??"",T=!!i&&b!=="inherit"&&!!C&&w.includes(g),F=T?i.models.filter(p=>A(p)===C).map(p=>p+S):[],f=E?K:b,c={};if(i)for(const p of w)N(p)&&(c[p]=H);const B={};for(const p of F)u(p,C)&&(B[p]=H);return e.jsxs(D,{label:r,hint:d??"This persona's default model for its Epics — sets the --model an Epic launches with (Terminal + Chat both honor it). 'inherit' falls back to each view's own default, not this Settings page. Cheap models for read-only personas; opus for judgement calls.",children:[e.jsx("div",{"data-testid":`${o}model-row`,children:e.jsx(_,{options:w,value:g,onChange:s,mono:!0,blocked:c,labels:l?{inherit:l}:void 0})}),T&&e.jsxs("div",{className:"mt-2","data-testid":`${o}model-version-row`,children:[e.jsx("div",{className:"text-[10.5px] text-fg-faint mb-1 font-mono",children:"version"}),e.jsx(_,{options:[K,...F],value:f,onChange:p=>s(p===K?g:p),mono:!0,blocked:B})]}),e.jsxs("div",{className:"text-[11px] text-fg-faint mt-1 leading-snug flex items-center gap-2",children:[e.jsx("span",{children:i?`Models are live-read from the installed claude CLI${L?" (cached — CLI probe unavailable)":""}. "latest" keeps the floating alias.`:x?"Loading model catalog…":"catalog unavailable — showing the standard list."}),e.jsx("button",{"data-testid":`${o}model-catalog-refresh`,onClick:()=>{h()},disabled:x,className:"underline text-fg-dim disabled:opacity-40",children:"refresh"})]})]})}function ee({value:n,model:s,onChange:r,label:d="effort",testIdPrefix:o="",inheritLabel:l}){const{catalog:i}=Q(null),x=i&&i.effortLevels.length?["inherit",...i.effortLevels]:[...xe],L=(i==null?void 0:i.settingsEffortLevels)??[],h=i?x.filter(N=>N!=="inherit"&&!L.includes(N)):[],w=n||"inherit",v=w!=="inherit"&&Ce(s)===!1;return e.jsxs(D,{label:d,hint:i?`Effort levels are live-read from the installed claude CLI (what /effort accepts). ${h.length?`${h.join(", ")} ${h.length>1?"are":"is"} session-only — settings.json accepts ${L.join(", ")}. `:""}'inherit' writes no effort: line.`:"catalog unavailable — showing the standard list. 'inherit' writes no effort: line.",children:[e.jsx("div",{"data-testid":`${o}effort-row`,children:e.jsx(_,{options:x,value:w,onChange:r,mono:!0,labels:l?{inherit:l}:void 0})}),h.length>0&&e.jsx("div",{className:"text-[11px] text-fg-faint mt-1 font-mono","data-testid":`${o}effort-session-only`,children:h.map(N=>`${N} (session-only)`).join(" · ")}),v&&e.jsx("div",{className:"text-[11px] text-amber-400 mt-1 leading-snug","data-testid":`${o}effort-unsupported-note`,children:"The selected model does not support effort — the CLI will ignore this setting."})]})}function Ee({saved:n,activeProject:s,busy:r,onSave:d}){var w,v,N;if(!s)return e.jsxs("div",{"data-testid":"project-override-none",className:"border border-dashed border-line rounded p-3 text-[11px] text-fg-faint",children:[e.jsx("div",{className:"text-[10.5px] font-semibold uppercase tracking-wide mb-1 font-mono",children:"project override"}),"No active project — open a project tab to override this persona's model or effort for that project only."]});const o=(w=n.overrideDetails)==null?void 0:w.find(u=>u.project===s),l=!!(o!=null&&o.bodyOverridden),i=((v=o==null?void 0:o.values)==null?void 0:v.model)??"inherit",x=((N=o==null?void 0:o.values)==null?void 0:N.effort)??"inherit",L=n.model??"inherit",h=n.effort??"inherit";return e.jsxs("div",{"data-testid":"project-override",className:"border border-accent/40 rounded p-3 space-y-3 bg-accent/5",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"text-[10.5px] font-semibold uppercase tracking-wide text-accent font-mono",children:"project override"}),e.jsxs(M,{tone:"accent",children:[s," only"]}),e.jsx("span",{className:"ml-auto text-[11px] text-fg-faint font-mono",children:`<project>/.claude/agents/${n.name}.md`})]}),e.jsxs("div",{className:"text-[11px] text-fg-faint leading-snug",children:["Changes what the SCHEDULER (and new Epics) spawn for ",e.jsx("strong",{children:s})," only — a frontmatter-only overlay with just the keys you set; the persona's body stays the global one. The global model/effort rows edit the machine-wide persona and are never touched here."]}),l&&e.jsxs("div",{"data-testid":"project-override-fullbody",className:"text-[11px] text-amber-400 leading-snug",children:[s,' already has a FULL-BODY override of this persona (its own definition text). It is shown as-is and not converted to a frontmatter-only overlay — edit that file directly, or drop it with × under "project overrides" below.']}),e.jsxs("fieldset",{disabled:r||l,className:"space-y-3 border-0 p-0 m-0 min-w-0",children:[e.jsx(Z,{value:i,onChange:u=>{l||d({model:u,effort:x})},label:"project model",hint:"'use global' writes no model: line in the overlay.",testIdPrefix:"override-",inheritLabel:"use global"}),e.jsx(ee,{value:x,model:i!=="inherit"?i:L,onChange:u=>{l||d({model:i,effort:u})},label:"project effort",testIdPrefix:"override-",inheritLabel:"use global"})]}),e.jsx("div",{"data-testid":"override-provenance",className:"text-[11px] font-mono text-fg-dim space-y-0.5",children:[["model",L,i],["effort",h,x]].map(([u,b,j])=>e.jsxs("div",{"data-testid":`override-provenance-${u}`,children:[u,": ",j!=="inherit"?e.jsxs(e.Fragment,{children:[b," ",e.jsx("span",{className:"text-fg-faint",children:"(global)"})," → ",e.jsx("span",{className:"text-accent",children:j})," ",e.jsx("span",{className:"text-fg-faint",children:"(this project)"})]}):e.jsxs(e.Fragment,{children:[b," ",e.jsx("span",{className:"text-fg-faint",children:"(global — not overridden)"})]})]},u))})]})}export{Be as AgentLibrary};
|
|
1
|
+
import{as as A,aF as y,be as le,ap as e,n as _,a as M,aX as $,aU as de,W as ce,aW as fe,b7 as X,M as me,c as U,E as xe}from"./index-DZ5TJKNI.js";import{P as he}from"./Panel-yOYf80ax.js";import{L as pe}from"./ListDetail-CY5hhwn9.js";import{B as R}from"./Button-BuyzGzO8.js";import{u as ue,t as ge,a as ve}from"./useAgentsDirWatch-CbpQIu3P.js";import{r as be}from"./claude-settings-schema-COigsajx.js";import"./monaco-editor-BsIlgG7c.js";const je=n=>{const[s,r]=n.split(".");return Number(s)+(r?Number(r)/100:0)};function we(n){const s=/Effort is supported on ([^.]*?)(?:, with|\.|$)/.exec(n);if(!s)return[];const r=[];for(const d of s[1].split(/,\s*|\s+and\s+/)){const o=/^(\w+)\s+(\d+(?:\.\d+)?)$/.exec(d.trim());o&&r.push({family:o[1].toLowerCase(),version:je(o[2])})}return r}var J,Y;const ye=we(String(((Y=(J=be.properties)==null?void 0:J.effortLevel)==null?void 0:Y.description)??""));function Ne(n,s){const r=new RegExp(`${s}-(\\d+)(?:-(\\d{1,2})(?!\\d))?`,"i").exec(n);if(r)return Number(r[1])+(r[2]?Number(r[2])/100:0);const d=new RegExp(`claude-(\\d+)(?:-(\\d{1,2}))?-${s}`,"i").exec(n);return d?Number(d[1])+(d[2]?Number(d[2])/100:0):null}function Ce(n,s=ye){if(!n||n==="inherit"||s.length===0)return null;const r=A(n);if(!r)return null;const d=s.filter(l=>l.family===r);if(d.length===0)return!1;const o=Ne(n,r);return o===null?null:o>=Math.min(...d.map(l=>l.version))}const z=["Read","Grep","Glob","Bash","Write","Edit","WebFetch","WebSearch","Task"],ke=["","red","orange","yellow","green","cyan","blue","purple","pink"],Q={red:"#c0392b",orange:"#b85c34",yellow:"#c9a227",green:"#6f7d52",cyan:"#3f8f8a",blue:"#4a6fa5",purple:"#7a6a8a",pink:"#b45a80"};function G(n){return{name:n.name,description:n.description??"",tools:n.tools,model:n.model??"inherit",effort:n.effort??"inherit",color:n.color??"",tags:n.tags,body:n.body}}const q={name:"new-agent",description:"",tools:["Read","Grep"],model:"inherit",effort:"inherit",color:"",tags:[],body:""};function $e(n){return n.overridingProjects.map(s=>{var o;const r=(o=n.overrideDetails)==null?void 0:o.find(l=>l.project===s);if(!r)return s;const d=[...r.fields.filter(l=>l!=="name"),...r.bodyOverridden?["full body"]:[]];return`${s}: ${d.join(", ")||"overlay"}`}).join(`
|
|
2
|
+
`)}function Se(){const[n,s]=y.useState(null),[r,d]=y.useState(null),[o,l]=y.useState(""),[i,x]=y.useState(null),[L,h]=y.useState(!1),[w,v]=y.useState(!1),[N,u]=y.useState(null),[b,j]=y.useState(!1),E=y.useRef(!0);y.useEffect(()=>()=>{E.current=!1},[]);const a=le(t=>{var m;return((m=t.tabs.find(k=>k.id===t.activeTabId))==null?void 0:m.cwd)??null}),g=a?a.replace(/\/+$/,"").split("/").pop()||a:null,C=y.useRef(0),S=async t=>{const m=++C.current;try{const k=await window.api.agents.listPersonas();if(!E.current||C.current!==m)return;s(k),d(V=>{var T;return t??V??((T=k[0])==null?void 0:T.name)??null})}catch(k){if(!E.current||C.current!==m)return;s([]),$.error(k.message||"failed to load agent personas")}};if(y.useEffect(()=>{S()},[]),y.useEffect(()=>window.api.agents.onChanged(()=>S()),[]),ue(a,()=>S()),y.useEffect(()=>{const t=de();t&&d(t);const m=k=>d(k.detail);return window.addEventListener("sm:select-persona",m),()=>window.removeEventListener("sm:select-persona",m)},[]),n===null)return e.jsx(_,{title:"loading…"});const P=o.toLowerCase(),F=n.filter(t=>!P||t.name.toLowerCase().includes(P)||(t.description??"").toLowerCase().includes(P)),f=n.find(t=>t.name===r)??n[0]??null,c=i??(f?G(f):null),B=!!i&&!!f&&JSON.stringify(i)!==JSON.stringify(G(f)),O=L,I=t=>{x(null),h(!1),v(!1),u(null),d(t)},p=t=>x(m=>({...m??(f?G(f):q),...t})),W=()=>{x({...q}),h(!0),v(!1)},te=()=>{c&&(x({...c,name:c.name+"-copy"}),h(!0))},ne=()=>{x(null),h(!1)},se=async()=>{if(c){if(!/^[a-z][a-z0-9-]*$/.test(c.name)){$.error('agent name must be lowercase, hyphenated (e.g. "my-agent")');return}j(!0);try{const t=O?null:f,m={name:c.name,originalName:t==null?void 0:t.name,description:c.description,tools:c.tools,model:c.model,effort:c.effort,color:c.color,tags:ge(c.tags),body:c.body},k=t?ve(t,m):m;await window.api.agents.savePersona(k),$.info(O?`created ${c.name}`:`saved ${c.name}`),x(null),h(!1),await S(c.name)}catch(t){$.error(t.message||"failed to save agent persona")}finally{j(!1)}}},ae=async()=>{if(f){j(!0);try{await window.api.agents.deletePersona({name:f.name}),$.info(`deleted ${f.name}`),v(!1),x(null),h(!1),await S()}catch(t){$.error(t.message||"failed to delete agent persona")}finally{j(!1)}}},oe=async t=>{j(!0);try{await window.api.agents.deletePersona({name:t}),$.info(`deleted ${t}`),u(null),r===t&&(x(null),h(!1)),await S()}catch(m){$.error(m.message||"failed to delete agent persona")}finally{j(!1)}},re=async t=>{if(f)try{await window.api.agents.removeOverride({name:f.name,projectName:t}),$.info(`removed ${t}'s override of ${f.name}`),await S(f.name)}catch(m){$.error(m.message||"failed to remove override")}},ie=async t=>{if(!(!f||!g)){j(!0);try{t.model==="inherit"&&t.effort==="inherit"?(await window.api.agents.removeOverride({name:f.name,projectName:g}),$.info(`cleared ${g}'s override of ${f.name}`)):(await window.api.agents.savePersona({name:f.name,projectName:g,description:"",tools:[],color:"",tags:[],body:"",model:t.model,effort:t.effort}),$.info(`saved ${g}'s override of ${f.name}`)),await S(f.name)}catch(m){$.error(m.message||"failed to save project override")}finally{j(!1)}}};return e.jsx(he,{toolbar:e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"text-fg-faint",children:[n.length," persona",n.length===1?"":"s"]}),e.jsx("input",{value:o,onChange:t=>l(t.target.value),placeholder:"filter…",className:"bg-bg border border-line rounded px-2 py-0.5 text-xs text-fg w-40"}),e.jsx("div",{className:"flex-1"}),e.jsx(R,{variant:"primary",onClick:W,children:"+ New agent"})]}),children:e.jsx(pe,{sidebar:e.jsxs("div",{className:"py-1",children:[O&&e.jsx("div",{className:"w-full text-left px-3 py-1 text-xs flex flex-col gap-0.5 bg-bg-hi text-fg border-l-2 border-accent",children:e.jsxs("span",{className:"flex items-center gap-2 justify-between w-full",children:[e.jsx("span",{className:"truncate font-mono",children:c==null?void 0:c.name}),e.jsx("span",{className:"shrink-0 text-[10px] font-semibold text-accent",children:"new"})]})}),F.length===0&&!O?e.jsx("div",{className:"px-3 py-1 text-xs text-fg-faint italic",children:"no agent personas found"}):F.map(t=>{const m=!O&&t.name===r,k=m&&B,V=N===t.name;return e.jsxs("div",{"data-agent-row":t.name,className:`group w-full text-left px-3 py-1 text-xs flex flex-col gap-0.5 border-l-2 cursor-pointer ${m?"bg-bg-hi text-fg border-accent":"text-fg-dim hover:text-fg hover:bg-bg-hi border-transparent"}`,onClick:()=>I(t.name),children:[e.jsxs("span",{className:"flex items-center gap-2 justify-between w-full",children:[e.jsxs("span",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsx("span",{className:"w-2 h-2 rounded-sm shrink-0",style:{background:t.color?Q[t.color]??t.color:"var(--fg-faint, #999)",opacity:t.color?1:.35}}),e.jsx("span",{className:"truncate font-mono",children:t.name})]}),e.jsxs("span",{className:"shrink-0 flex items-center gap-1.5",children:[k&&e.jsx("span",{className:"text-[10px] font-semibold text-accent",children:"unsaved"}),!k&&t.overridingProjects.length>0&&e.jsx("span",{title:$e(t),children:e.jsxs(M,{tone:"dim",children:[t.overridingProjects.length," override",t.overridingProjects.length>1?"s":""]})}),V?e.jsxs("span",{className:"flex items-center gap-1",onClick:T=>T.stopPropagation(),children:[e.jsx("button",{onClick:()=>oe(t.name),disabled:b,title:`Delete ${t.name}`,className:"text-[10px] font-semibold text-red-400 hover:text-red-300",children:"confirm"}),e.jsx("button",{onClick:()=>u(null),title:"Cancel",className:"text-[10px] text-fg-faint hover:text-fg",children:"cancel"})]}):e.jsx("button",{onClick:T=>{T.stopPropagation(),u(t.name)},title:`Delete ${t.name}`,className:"opacity-0 group-hover:opacity-100 text-fg-faint hover:text-red-400 transition-opacity",children:"×"})]})]}),t.description&&e.jsx("span",{className:"truncate text-fg-faint",children:t.description})]},t.name)})]}),detail:c?e.jsx(Le,{obj:c,set:p,saved:f,dirty:B,isNew:O,busy:b,confirmDelete:w,setConfirmDelete:v,onDuplicate:te,onRevert:ne,onSave:se,onDelete:ae,onDropOverride:re,activeProject:g,onSaveOverride:ie}):e.jsx(_,{title:"select an agent"})})})}const Be=y.memo(Se);function Le({obj:n,set:s,saved:r,dirty:d,isNew:o,busy:l,confirmDelete:i,setConfirmDelete:x,onDuplicate:L,onRevert:h,onSave:w,onDelete:v,onDropOverride:N,activeProject:u,onSaveOverride:b}){const j=`~/.claude/agents/${n.name}.md`,E=d||o;return e.jsxs("div",{className:"max-w-3xl",children:[e.jsxs("div",{className:"px-4 py-3 border-b border-line flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"text-sm font-semibold text-fg font-mono",children:n.name}),o?e.jsx(M,{tone:"accent",children:"unsaved draft"}):d?e.jsx(M,{tone:"warn",children:"edited"}):e.jsx(M,{tone:"good",children:"saved"}),e.jsx("span",{className:"ml-auto text-[11px] text-fg-faint font-mono",children:j})]}),e.jsxs("div",{className:"p-4 space-y-4",children:[e.jsx(D,{label:"name",hint:"Filename on disk — lowercase, hyphenated.",children:e.jsx("input",{value:n.name,onChange:a=>s({name:a.target.value.toLowerCase()}),className:"w-full bg-bg border border-line rounded px-2 py-1 text-xs text-fg font-mono"})}),e.jsx(D,{label:"description",hint:"Shown in the list and in agent pickers.",children:e.jsx("input",{value:n.description,onChange:a=>s({description:a.target.value}),className:"w-full bg-bg border border-line rounded px-2 py-1 text-xs text-fg"})}),e.jsx(Z,{value:n.model,onChange:a=>s({model:a})}),e.jsx(ee,{value:n.effort,model:n.model,onChange:a=>s({effort:a})}),!o&&r&&e.jsx(Ee,{saved:r,activeProject:u,busy:l,onSave:b}),e.jsx(D,{label:"tools",hint:`${n.tools.length} of ${z.length} granted. Anything not ticked is refused at call time.`,children:e.jsx("div",{className:"flex flex-wrap gap-1.5",children:z.map(a=>{const g=n.tools.includes(a);return e.jsx("button",{onClick:()=>s({tools:g?n.tools.filter(C=>C!==a):[...n.tools,a]}),className:`px-2 py-0.5 rounded-full text-[11px] font-mono border ${g?"bg-sage/15 text-sage-dark border-sage/30":"bg-bg-hi text-fg-faint border-line"}`,children:a},a)})})}),e.jsx(D,{label:"color",children:e.jsx("div",{className:"flex gap-1.5",children:ke.map(a=>e.jsx("button",{title:a||"none",onClick:()=>s({color:a}),className:"w-5 h-5 rounded",style:{background:a?Q[a]:"transparent",border:n.color===a?"2px solid var(--accent, #b85c34)":"1px solid var(--line, #555)"}},a||"none"))})}),e.jsx(D,{label:"tags",hint:"Session mission tags this persona is associated with — shown as the default agent on that tag's own page. The first one (in Tag Library order) is the MISSION an Action button's session opens with.",children:e.jsx("div",{className:"flex flex-wrap gap-1.5",children:ce.map(a=>{const g=n.tags.includes(a.tag),C=fe(a.tag);return e.jsxs("button",{onClick:()=>s({tags:g?n.tags.filter(S=>S!==a.tag):[...n.tags,a.tag]}),className:`px-2 py-0.5 rounded-full text-[11px] font-mono border ${g?`${C.bg} ${C.text} ${C.border?"border-current/30":"border-transparent"}`:"bg-bg-hi text-fg-faint border-line"}`,children:["#",a.tag]},a.tag)})})}),e.jsx(D,{label:"definition",hint:"The system prompt this persona runs under.",children:e.jsx("textarea",{rows:9,value:n.body,onChange:a=>s({body:a.target.value}),className:"w-full bg-bg border border-line rounded px-2 py-1.5 text-xs text-fg font-mono leading-relaxed resize-y"})}),e.jsx(D,{label:"project overrides",hint:"Open projects that shadow this definition with a local copy.",children:r&&r.overridingProjects.length>0?e.jsx("div",{className:"flex flex-wrap gap-1.5",children:r.overridingProjects.map(a=>e.jsxs("span",{className:"inline-flex items-center gap-1.5 bg-bg-elev border border-line rounded px-2 py-0.5 text-[11px] font-mono text-fg-dim",children:[a,e.jsx("button",{onClick:()=>N(a),title:"Drop the local copy",className:"text-fg-faint hover:text-fg",children:"×"})]},a))}):e.jsx("div",{className:"text-xs text-fg-faint italic",children:o?"save first to see project overrides.":"no open project overlays this agent — the global definition applies everywhere."})})]}),e.jsx("div",{className:"px-4 py-2.5 border-t border-line flex items-center gap-2 flex-wrap",children:i?e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"text-xs text-fg-dim",children:["Delete ",e.jsx("strong",{className:"font-mono",children:n.name})," and its file?"]}),e.jsx(R,{variant:"danger",onClick:v,disabled:l,children:"Delete"}),e.jsx(R,{onClick:()=>x(!1),children:"Keep"})]}):e.jsxs(e.Fragment,{children:[e.jsx(R,{onClick:L,disabled:l,children:"Duplicate"}),!o&&e.jsx(R,{variant:"danger",onClick:()=>x(!0),disabled:l,children:"Delete"}),e.jsx("div",{className:"flex-1"}),E&&e.jsx("span",{className:"text-[11px] text-fg-faint",children:"unsaved changes"}),e.jsx(R,{onClick:h,disabled:!E||l,children:"Revert"}),e.jsx(R,{variant:"primary",onClick:w,disabled:!E||l,children:l?"Saving…":o?"Create":"Save"})]})})]})}function D({label:n,hint:s,children:r}){return e.jsxs("div",{children:[e.jsx("div",{className:"text-[10.5px] font-semibold uppercase tracking-wide text-fg-faint mb-1.5 font-mono",children:n}),r,s&&e.jsx("div",{className:"text-[11px] text-fg-faint mt-1 leading-snug",children:s})]})}const K="latest",H="Blocked by the availableModels allowlist in your Claude settings";function Z({value:n,onChange:s,label:r="default model",hint:d,testIdPrefix:o="",inheritLabel:l}){var O,I;const{catalog:i,loading:x,degraded:L,refresh:h}=X(null),w=i?["inherit",...i.aliases]:[...me],v=(i==null?void 0:i.availableModels)??null,N=p=>!!v&&p!=="inherit"&&!v.includes(p),u=(p,W)=>!!v&&!v.includes(p)&&!(W&&v.includes(W)),b=n||"inherit",j=((O=/\[[^\]]*\]$/.exec(b))==null?void 0:O[0])??"",E=w.includes(b),a=!E&&i&&A(b)&&w.includes(A(b)+j)?A(b)+j:null,g=E?b:a??b,C=A(g),S=((I=/\[[^\]]*\]$/.exec(g))==null?void 0:I[0])??"",P=!!i&&b!=="inherit"&&!!C&&w.includes(g),F=P?i.models.filter(p=>A(p)===C).map(p=>p+S):[],f=E?K:b,c={};if(i)for(const p of w)N(p)&&(c[p]=H);const B={};for(const p of F)u(p,C)&&(B[p]=H);return e.jsxs(D,{label:r,hint:d??"This persona's default model for its Epics — sets the --model an Epic launches with (Terminal + Chat both honor it). 'inherit' falls back to each view's own default, not this Settings page. Cheap models for read-only personas; opus for judgement calls.",children:[e.jsx("div",{"data-testid":`${o}model-row`,children:e.jsx(U,{options:w,value:g,onChange:s,mono:!0,blocked:c,labels:l?{inherit:l}:void 0})}),P&&e.jsxs("div",{className:"mt-2","data-testid":`${o}model-version-row`,children:[e.jsx("div",{className:"text-[10.5px] text-fg-faint mb-1 font-mono",children:"version"}),e.jsx(U,{options:[K,...F],value:f,onChange:p=>s(p===K?g:p),mono:!0,blocked:B})]}),e.jsxs("div",{className:"text-[11px] text-fg-faint mt-1 leading-snug flex items-center gap-2",children:[e.jsx("span",{children:i?`Models are live-read from the installed claude CLI${L?" (cached — CLI probe unavailable)":""}. "latest" keeps the floating alias.`:x?"Loading model catalog…":"catalog unavailable — showing the standard list."}),e.jsx("button",{"data-testid":`${o}model-catalog-refresh`,onClick:()=>{h()},disabled:x,className:"underline text-fg-dim disabled:opacity-40",children:"refresh"})]})]})}function ee({value:n,model:s,onChange:r,label:d="effort",testIdPrefix:o="",inheritLabel:l}){const{catalog:i}=X(null),x=i&&i.effortLevels.length?["inherit",...i.effortLevels]:[...xe],L=(i==null?void 0:i.settingsEffortLevels)??[],h=i?x.filter(N=>N!=="inherit"&&!L.includes(N)):[],w=n||"inherit",v=w!=="inherit"&&Ce(s)===!1;return e.jsxs(D,{label:d,hint:i?`Effort levels are live-read from the installed claude CLI (what /effort accepts). ${h.length?`${h.join(", ")} ${h.length>1?"are":"is"} session-only — settings.json accepts ${L.join(", ")}. `:""}'inherit' writes no effort: line.`:"catalog unavailable — showing the standard list. 'inherit' writes no effort: line.",children:[e.jsx("div",{"data-testid":`${o}effort-row`,children:e.jsx(U,{options:x,value:w,onChange:r,mono:!0,labels:l?{inherit:l}:void 0})}),h.length>0&&e.jsx("div",{className:"text-[11px] text-fg-faint mt-1 font-mono","data-testid":`${o}effort-session-only`,children:h.map(N=>`${N} (session-only)`).join(" · ")}),v&&e.jsx("div",{className:"text-[11px] text-amber-400 mt-1 leading-snug","data-testid":`${o}effort-unsupported-note`,children:"The selected model does not support effort — the CLI will ignore this setting."})]})}function Ee({saved:n,activeProject:s,busy:r,onSave:d}){var w,v,N;if(!s)return e.jsxs("div",{"data-testid":"project-override-none",className:"border border-dashed border-line rounded p-3 text-[11px] text-fg-faint",children:[e.jsx("div",{className:"text-[10.5px] font-semibold uppercase tracking-wide mb-1 font-mono",children:"project override"}),"No active project — open a project tab to override this persona's model or effort for that project only."]});const o=(w=n.overrideDetails)==null?void 0:w.find(u=>u.project===s),l=!!(o!=null&&o.bodyOverridden),i=((v=o==null?void 0:o.values)==null?void 0:v.model)??"inherit",x=((N=o==null?void 0:o.values)==null?void 0:N.effort)??"inherit",L=n.model??"inherit",h=n.effort??"inherit";return e.jsxs("div",{"data-testid":"project-override",className:"border border-accent/40 rounded p-3 space-y-3 bg-accent/5",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"text-[10.5px] font-semibold uppercase tracking-wide text-accent font-mono",children:"project override"}),e.jsxs(M,{tone:"accent",children:[s," only"]}),e.jsx("span",{className:"ml-auto text-[11px] text-fg-faint font-mono",children:`<project>/.claude/agents/${n.name}.md`})]}),e.jsxs("div",{className:"text-[11px] text-fg-faint leading-snug",children:["Changes what the SCHEDULER (and new Epics) spawn for ",e.jsx("strong",{children:s})," only — a frontmatter-only overlay with just the keys you set; the persona's body stays the global one. The global model/effort rows edit the machine-wide persona and are never touched here."]}),l&&e.jsxs("div",{"data-testid":"project-override-fullbody",className:"text-[11px] text-amber-400 leading-snug",children:[s,' already has a FULL-BODY override of this persona (its own definition text). It is shown as-is and not converted to a frontmatter-only overlay — edit that file directly, or drop it with × under "project overrides" below.']}),e.jsxs("fieldset",{disabled:r||l,className:"space-y-3 border-0 p-0 m-0 min-w-0",children:[e.jsx(Z,{value:i,onChange:u=>{l||d({model:u,effort:x})},label:"project model",hint:"'use global' writes no model: line in the overlay.",testIdPrefix:"override-",inheritLabel:"use global"}),e.jsx(ee,{value:x,model:i!=="inherit"?i:L,onChange:u=>{l||d({model:i,effort:u})},label:"project effort",testIdPrefix:"override-",inheritLabel:"use global"})]}),e.jsx("div",{"data-testid":"override-provenance",className:"text-[11px] font-mono text-fg-dim space-y-0.5",children:[["model",L,i],["effort",h,x]].map(([u,b,j])=>e.jsxs("div",{"data-testid":`override-provenance-${u}`,children:[u,": ",j!=="inherit"?e.jsxs(e.Fragment,{children:[b," ",e.jsx("span",{className:"text-fg-faint",children:"(global)"})," → ",e.jsx("span",{className:"text-accent",children:j})," ",e.jsx("span",{className:"text-fg-faint",children:"(this project)"})]}):e.jsxs(e.Fragment,{children:[b," ",e.jsx("span",{className:"text-fg-faint",children:"(global — not overridden)"})]})]},u))})]})}export{Be as AgentLibrary};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{ap as o,Z as b}from"./index-DZ5TJKNI.js";function u({children:n,onClick:s,disabled:a,variant:e="default",tooltip:t,type:d="button",className:c}){const i=`px-2 py-0.5 text-xs rounded border transition-colors disabled:opacity-40 disabled:cursor-not-allowed ${e==="primary"?"text-accent border-accent/50 hover:bg-bg-hi":e==="danger"?"text-red-400 hover:text-red-300 border-line hover:border-red-400/50":"text-fg-dim border-line hover:text-fg hover:bg-bg-hi"} ${c??""}`,r=o.jsx("button",{type:d,title:t,onClick:s,disabled:a,className:i,children:n});return t?o.jsx(b,{content:t,align:"bottom-center",children:r}):r}export{u as B};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{aF as d,j,aq as $,a9 as g,ap as e,n as N,at as E,aa as b,aJ as S,a as f,a4 as T,k as v,i as D}from"./index-DZ5TJKNI.js";import{P as R}from"./Panel-yOYf80ax.js";import{V}from"./ViewTabs-D82jJ4VS.js";import"./monaco-editor-BsIlgG7c.js";const C=[{key:"diagram",label:"Diagram"},{key:"tables",label:"Tables"}];function G(){const[s,t]=d.useState("diagram"),[a,i]=d.useState(null),[l,n]=d.useState(()=>new Set),c=d.useMemo(()=>j.filter(r=>!l.has(r.group)),[l]),m=d.useMemo(()=>$(c),[c]),o=r=>{n(x=>{const h=new Set(x);return h.has(r)?h.delete(r):h.add(r),h}),i(null)},u=a?g(a):null,y=r=>c.some(x=>x.id===r);return e.jsx(R,{toolbar:e.jsxs(e.Fragment,{children:[e.jsx(V,{options:C,active:s,onChange:t}),e.jsx(M,{hiddenGroups:l,onToggle:o}),e.jsxs("span",{className:"ml-auto text-fg-faint",children:[j.length," entities"]})]}),children:s==="diagram"?e.jsxs("div",{className:"h-full flex",children:[e.jsx("div",{className:"flex-1 min-w-0 overflow-auto",children:e.jsx(O,{layout:m,selectedId:a,onSelect:r=>i(x=>x===r?null:r)})}),e.jsx("div",{className:"w-96 shrink-0 border-l border-line overflow-y-auto",children:u?e.jsx(F,{entity:u,onSelectRelated:r=>y(r)?i(r):void 0}):e.jsx(N,{title:"select an entity",hint:"click a box in the diagram to see its storage, fields, and relations"})})]}):e.jsx(P,{})})}const X=d.memo(G);function M({hiddenGroups:s,onToggle:t}){return e.jsx("div",{className:"flex items-center gap-1.5 flex-wrap",children:v.map(a=>{const i=s.has(a.id);return e.jsxs("button",{onClick:()=>t(a.id),title:`${a.blurb} (${a.realm})`,className:`flex items-center gap-1 px-1.5 py-0.5 rounded border text-[10.5px] ${i?"border-line text-fg-faint opacity-50":"border-line text-fg-dim hover:text-fg"}`,children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${a.tone.dot}`}),a.label,e.jsx("span",{className:"text-fg-faint",children:a.realm})]},a.id)})})}function O({layout:s,selectedId:t,onSelect:a}){const i=d.useMemo(()=>t?new Set(E(t)):null,[t]),l=n=>!!t&&(n.relation.from===t||n.relation.to===t);return s.boxes.length===0?e.jsx(N,{title:"no entities in view",hint:"toggle a group in the legend to show its entities"}):e.jsxs("div",{className:"relative p-4",style:{width:s.width+32,height:s.height+32},children:[e.jsxs("svg",{width:s.width,height:s.height,className:"absolute left-4 top-4 overflow-visible",children:[s.edges.map(n=>{const c=l(n);return e.jsx("path",{"data-testid":`erd-edge-${n.relation.from}-${n.relation.to}`,d:n.d,fill:"none",className:c?"stroke-accent":"stroke-line",strokeWidth:c?2:1,opacity:t&&!c?.25:1},`${n.relation.from}-${n.relation.to}-${n.relation.label}`)}),s.edges.map(n=>l(n)?e.jsx("text",{x:n.mx,y:n.my,textAnchor:"middle",className:"fill-fg-dim text-[10px]",children:n.relation.label},`label-${n.relation.from}-${n.relation.to}-${n.relation.label}`):null)]}),s.boxes.map(n=>e.jsx(_,{box:n,selected:n.id===t,dimmed:!!t&&n.id!==t&&!(i!=null&&i.has(n.id)),onClick:()=>a(n.id)},n.id))]})}function _({box:s,selected:t,dimmed:a,onClick:i}){const l=g(s.id),n=b(s.group),c=l.fields.slice(0,D),m=l.fields.length-c.length;return e.jsxs("button",{type:"button","data-testid":`erd-box-${s.id}`,onClick:i,className:`absolute text-left rounded border overflow-hidden bg-bg-hi ${t?"border-accent ring-1 ring-accent":"border-line"} ${a?"opacity-30":""}`,style:{left:s.x,top:s.y,width:s.w,height:s.h},children:[e.jsxs("div",{className:"px-2 py-1 border-b border-line flex items-center gap-1.5",children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${n.tone.dot}`}),e.jsx("span",{className:"text-[11px] font-semibold text-fg truncate",children:l.name})]}),l.aka&&e.jsx("div",{className:"px-2 pt-0.5 text-[9.5px] text-fg-faint truncate",children:l.aka}),e.jsxs("div",{className:"px-2 py-0.5",children:[c.map(o=>e.jsxs("div",{className:"text-[9.5px] font-mono text-fg-dim truncate flex items-center gap-1",children:[o.key&&e.jsx("span",{className:"text-fg-faint",children:o.key}),e.jsx("span",{className:"truncate",children:o.name})]},o.name)),m>0&&e.jsxs("div",{className:"text-[9.5px] text-fg-faint italic",children:["+",m," more"]})]})]})}function w({fields:s}){return e.jsxs("table",{className:"w-full text-[11px] font-mono",children:[e.jsx("thead",{className:"text-fg-faint uppercase tracking-wide text-[9.5px]",children:e.jsxs("tr",{className:"border-b border-line",children:[e.jsx("th",{className:"text-left font-normal px-2 py-1",children:"name"}),e.jsx("th",{className:"text-left font-normal px-2 py-1",children:"type"}),e.jsx("th",{className:"text-left font-normal px-2 py-1",children:"key"}),e.jsx("th",{className:"text-left font-normal px-2 py-1",children:"note"})]})}),e.jsx("tbody",{children:s.map(t=>e.jsxs("tr",{className:"border-b border-line/50",children:[e.jsxs("td",{className:"px-2 py-1 text-fg",children:[t.name,t.optional&&e.jsx("span",{className:"text-fg-faint",children:"?"})]}),e.jsx("td",{className:"px-2 py-1 text-fg-dim",children:t.type}),e.jsx("td",{className:"px-2 py-1",children:t.key&&e.jsxs(f,{tone:t.key==="pk"?"accent":"dim",children:[t.key,t.ref?` → ${t.ref}`:""]})}),e.jsx("td",{className:"px-2 py-1 text-fg-faint",children:t.note})]},t.name))})]})}function k({entity:s}){return e.jsxs("div",{className:"space-y-1 text-[11px]",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-fg-faint w-20 shrink-0",children:"path"}),e.jsx("span",{className:"font-mono text-fg-dim break-all",children:s.store.path})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-fg-faint w-20 shrink-0",children:"format"}),e.jsx("span",{className:"font-mono text-fg-dim",children:s.store.format})]}),s.store.writer&&e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-fg-faint w-20 shrink-0",children:"writer"}),e.jsxs(f,{tone:"accent",children:["single-writer: ",s.store.writer]})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-fg-faint w-20 shrink-0",children:"definedIn"}),e.jsx("span",{className:"font-mono text-fg-dim break-all",children:s.store.definedIn})]})]})}function F({entity:s,onSelectRelated:t}){const a=b(s.group),i=S(s.id);return e.jsxs("div",{className:"p-3 space-y-3",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:`w-2 h-2 rounded-full ${a.tone.dot}`}),e.jsx("span",{className:"text-sm font-semibold text-fg",children:s.name})]}),s.aka&&e.jsx("div",{className:"text-[10.5px] text-fg-faint",children:s.aka}),e.jsx(f,{tone:"dim",className:"mt-1",children:a.label})]}),e.jsx("div",{className:"text-xs text-fg-dim leading-relaxed",children:s.summary}),e.jsxs("div",{children:[e.jsx(p,{children:"storage"}),e.jsx(k,{entity:s})]}),e.jsxs("div",{children:[e.jsx(p,{children:"fields"}),e.jsx(w,{fields:s.fields})]}),s.notes&&s.notes.length>0&&e.jsxs("div",{children:[e.jsx(p,{children:"notes"}),e.jsx("ul",{className:"list-disc pl-4 space-y-0.5 text-xs text-fg-dim",children:s.notes.map(l=>e.jsx("li",{children:l},l))})]}),e.jsxs("div",{children:[e.jsx(p,{children:"relations"}),i.length===0?e.jsx("div",{className:"text-xs text-fg-faint italic",children:"no relations"}):e.jsx("ul",{className:"space-y-1",children:i.map(l=>{const n=l.from===s.id?l.to:l.from,c=g(n);return e.jsxs("li",{className:"flex items-center gap-1.5 text-xs",children:[e.jsx("span",{className:"font-mono text-fg-faint w-10 shrink-0",children:T(l.cardinality)}),e.jsx("span",{className:"text-fg-dim",children:l.label}),l.via&&e.jsxs("span",{className:"font-mono text-[10px] text-fg-faint",children:["via ",l.via]}),e.jsx("button",{type:"button",onClick:()=>t(n),className:"ml-auto text-accent hover:underline font-mono",children:c.name})]},`${l.from}-${l.to}-${l.label}`)})})]})]})}function p({children:s}){return e.jsx("div",{className:"text-[10.5px] uppercase tracking-wide text-fg-faint mb-1 font-mono",children:s})}function P(){return e.jsx("div",{className:"p-4 space-y-6",children:v.map(s=>{const t=j.filter(a=>a.group===s.id);return t.length===0?null:e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-2",children:[e.jsx("span",{className:`w-2 h-2 rounded-full ${s.tone.dot}`}),e.jsx("span",{className:"text-xs font-semibold text-fg",children:s.label}),e.jsx("span",{className:"text-[10.5px] text-fg-faint",children:s.realm})]}),e.jsx("div",{className:"grid grid-cols-1 xl:grid-cols-2 gap-3",children:t.map(a=>e.jsxs("div",{className:"border border-line rounded bg-bg-hi p-3 space-y-2",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-semibold text-fg",children:a.name}),a.aka&&e.jsx("span",{className:"text-[10.5px] text-fg-faint",children:a.aka})]}),e.jsx(f,{tone:"dim",className:"mt-1",children:s.label})]}),e.jsx("div",{className:"text-xs text-fg-dim leading-relaxed",children:a.summary}),e.jsx(k,{entity:a}),e.jsx(w,{fields:a.fields}),a.notes&&a.notes.length>0&&e.jsx("ul",{className:"list-disc pl-4 space-y-0.5 text-xs text-fg-dim",children:a.notes.map(i=>e.jsx("li",{children:i},i))})]},a.id))})]},s.id)})})}export{X as DataModel};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
2
|
-
`)}const rt={folderCount:0,sessionCount:0,promptCount:0,estimatedCostUsd:0,totalTokens:0};function it(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,c]of Object.entries(s.toolBreakdown??{}))t.toolBreakdown[n]=(t.toolBreakdown[n]??0)+c;for(const[n,c]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+=c.inputTokens,o.outputTokens+=c.outputTokens,o.cacheReadTokens+=c.cacheReadTokens,o.cacheCreationTokens+=c.cacheCreationTokens,o.costUsd+=c.costUsd,c.estimated&&(o.estimated=!0)}}function lt(t,s){const n={};for(const[c,o]of Object.entries(t.byModel??{}))n[c]={...o};return{...t,projectDir:s,toolBreakdown:{...t.toolBreakdown??{}},byModel:n}}function dt(t,s){const n={...rt},c=new Set,o=t.map(r=>{const a={};for(const[l,u]of Object.entries(r.byProject)){const d=s[l];if(!d){c.add(l),n.sessionCount+=u.sessionCount,n.promptCount+=u.promptCount,n.estimatedCostUsd+=u.estimatedCostUsd,n.totalTokens+=u.inputTokens+u.outputTokens;continue}const i=a[d];i?it(i,u):a[d]=lt(u,d)}return{...r,byProject:a}});return n.folderCount=c.size,{days:o,excluded:n}}function ut(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 fe(){return(await ze()).history??{}}let Me=Promise.resolve();function ue(t){const s=Me.then(async()=>{const n=await fe();await Ke({history:{...n,...t}})});return Me=s.catch(()=>{}),s}const xt=["in","out","total","prompts","sessions","time","spend"],ft=[{value:30,label:"30d"},{value:60,label:"60d"},{value:90,label:"90d"},{value:0,label:"All time"}];function Re({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(c=>e.jsx("button",{onClick:()=>n(c.value),className:`px-2 py-1 rounded whitespace-nowrap font-mono ${t===c.value?"bg-bg-hi text-fg shadow-sm":"text-fg-faint hover:text-fg"}`,children:c.label},String(c.value)))})}function ht({measure:t,onMeasure:s,range:n,onRange:c,projectsShown:o,projectsTotal:r,fromDate:a,toDate:l,onRefresh:u,onExport:d,exportDisabled:i}){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(Re,{value:t,options:xt.map(x=>({value:x,label:Ue[x]})),onChange:s}),e.jsx(Re,{value:n,options:ft,onChange:c}),e.jsxs("span",{className:"text-[11px] text-fg-faint font-mono",children:[o," / ",r," projects"]}),e.jsxs("span",{className:"text-[11px] text-fg-faint font-mono",children:[a," → ",l]}),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:i,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 w="rounded-card bg-bg-hi border border-line",mt="#ded2bd",jt="#6f7d52";function D({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 E(s);case"in":case"out":case"total":return I(s);case"time":return Ee(s);default:return L(s)}}function gt({measure:t,headline:s,activeDays:n,projectsTouched:c,totalSessions:o}){const r=n>0?s.value/n:0,a=o>0?s.value/o:0,{delta:l}=s,u=l&&(t==="spend"?l.direction==="down":l.direction==="up"),d=l&&l.direction!=="flat"&&(t==="spend"?l.direction==="up":l.direction==="down"),i=u?"text-delta-good":d?"text-delta-bad":"text-fg-faint";return e.jsxs("div",{className:`${w} p-4`,children:[e.jsx(D,{kicker:"01 · overview",title:Ue[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)}),l?e.jsxs("div",{className:`text-xs font-mono mt-2 ${i}`,children:[l.direction==="up"?"▲":l.direction==="down"?"▼":"·"," ",De(Math.abs(l.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(bt,{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,r)}),e.jsx(X,{label:"per session",value:Q(t,a)}),e.jsx(X,{label:"active days",value:L(n)}),e.jsx(X,{label:"projects touched",value:L(c)})]})]})}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 bt({series:t}){if(t.length<2)return null;const c=Math.max(...t,0),o=Math.min(...t,0),r=c-o||1,a=160/(t.length-1),l=t.map((d,i)=>`${i*a},${48-(d-o)/r*48}`).join(" "),u=`0,48 ${l} 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:l,fill:"none",stroke:"#b85c34",strokeWidth:1.5,vectorEffect:"non-scaling-stroke"})]})}const kt=50;function vt({days:t}){const[s,n]=f.useState(kt),c=f.useRef(!1);f.useEffect(()=>{let d=!1;return fe().then(i=>{d||c.current||typeof i.budgetCapUsd=="number"&&Number.isFinite(i.budgetCapUsd)&&i.budgetCapUsd>0&&n(i.budgetCapUsd)}),()=>{d=!0}},[]);const o=d=>{c.current=!0;const i=s;n(d),ue({budgetCapUsd:d}).catch(()=>{n(i),q.error("Couldn't save the budget cap — reverted.")})},{mtdSpend:r,projectedSpend:a}=f.useMemo(()=>{const d=new Date,i=d.toLocaleDateString("en-CA").slice(0,7),x=new Date(d.getFullYear(),d.getMonth()+1,0).getDate(),m=d.getDate();let k=0;for(const v of t)if(v.date.startsWith(i))for(const M of Object.values(v.byProject))k+=M.estimatedCostUsd;return{mtdSpend:k,projectedSpend:et(k,m,x)}},[t]),l=a>s,u=s>0?Math.min(100,r/s*100):0;return e.jsxs("div",{className:`${w} 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 i=Number(d.target.value);Number.isFinite(i)&&i>0&&o(i)},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(r)," ",e.jsx("span",{className:"text-fg-faint",children:"month-to-date"})]}),e.jsxs("span",{className:l?"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 ${l?"bg-delta-bad":"bg-sage"}`,style:{width:`${Math.max(u,u>0?2:0)}%`}})}),e.jsx("div",{className:`text-[10px] mt-1 font-mono ${l?"text-delta-bad":"text-fg-faint"}`,children:l?`projected to exceed $${s.toFixed(0)} cap`:`${u.toFixed(0)}% of $${s.toFixed(0)} cap`})]})}function yt({chips:t,keep:s,onToggle:n,onIsolate:c,onShowAll:o}){const r=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 ${r?"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 l=r||s.has(a.projectDir);return e.jsxs("button",{onClick:u=>u.shiftKey?c(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 ${l?"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)}}),O(a.projectDir)]},a.projectDir)})]})}function Ct(t,s){const n=new Map;for(const o of t)for(const[r,a]of Object.entries(o.values))n.set(r,(n.get(r)??0)+a);const c=Array.from(n.entries()).sort((o,r)=>r[1]-o[1]).map(([o])=>o);return t.map(o=>{const r=c.reduce((u,d)=>u+(o.values[d]??0),0);let a=0;const l=c.map(u=>{const d=o.values[u]??0;if(r<=0)return{projectDir:u,value:d,y0:0,y1:0};const i=s==="share"?d/r:d,x=a,m=a+i;return a=m,{projectDir:u,value:d,y0:x,y1:m}});return{date:o.date,bands:l,total:r}})}const ie=720,le=220,de=44,Tt=20;function Nt(t,s){return t==="spend"?E(s):I(s)}function wt({days:t,measure:s,selected:n,onSelect:c}){const[o,r]=f.useState("absolute"),a=f.useMemo(()=>Ct(t,o),[t,o]),l=f.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-Tt,i=a.length>1?u/(a.length-1):u,x=h=>de+h*i,m=h=>d-h/l*d,k=Math.max(1,Math.ceil(a.length/8)),v=4,M=Array.from({length:v+1},(h,g)=>l/v*g);return e.jsxs("div",{className:`${w} p-4`,children:[e.jsx(D,{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:()=>r(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)}%`:Nt(s,h)})]},g)),a.map((h,g)=>{if(g===0)return null;const $=a[g-1];return h.bands.map((j,J)=>{const z=$.bands[J],W=n!==null&&n!==j.projectDir,ee=W?mt:A(j.projectDir),te=[`${x(g-1)},${m(z.y0)}`,`${x(g)},${m(j.y0)}`,`${x(g)},${m(j.y1)}`,`${x(g-1)},${m(z.y1)}`].join(" ");return e.jsx("polygon",{points:te,fill:ee,opacity:W?.6:.75,className:"cursor-pointer",onClick:()=>c(n===j.projectDir?null:j.projectDir),children:e.jsx("title",{children:O(j.projectDir)})},`${j.projectDir}-${g}`)})}),a.map((h,g)=>g%k!==0&&g!==a.length-1?null:e.jsx("text",{x:x(g),y:le-4,fontSize:9,textAnchor:"middle",className:"fill-fg-faint",children:h.date.slice(5)},h.date))]})]})}function Mt({rows:t,measure:s,selected:n,onSelect:c}){return t.length?e.jsxs("div",{className:`${w} overflow-hidden`,children:[e.jsx("div",{className:"p-4 pb-0",children:e.jsx(D,{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 r=A(o.projectDir),a=n===o.projectDir;return e.jsxs("tr",{onClick:()=>c(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:r}}),O(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:r}})})}),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:L(o.sessions)}),e.jsx("td",{className:"px-3 py-2 text-fg-faint font-mono",children:o.topTool||"—"})]},o.projectDir)})})]})]}):e.jsxs("div",{className:`${w} p-4`,children:[e.jsx(D,{kicker:"03 · by project",title:"Ranking"}),e.jsx("div",{className:"text-xs text-fg-faint",children:"no projects in range"})]})}function Rt({projectDir:t,totals:s,byModel:n,toolBreakdown:c,onClear:o}){var i;const r=S(s,"in"),a=S(s,"out"),l=Object.entries(n).sort((x,m)=>m[1].costUsd-x[1].costUsd),u=Object.entries(c).sort((x,m)=>m[1]-x[1]),d=((i=u[0])==null?void 0:i[1])??0;return e.jsxs("div",{className:`${w} p-4`,children:[e.jsx(D,{kicker:"04 · drill in",title:O(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:L(s.promptCount)}),e.jsx(H,{label:"sessions",value:L(s.sessionCount)}),e.jsx(H,{label:"in tokens",value:I(r)}),e.jsx(H,{label:"out tokens",value:I(a)}),e.jsx(H,{label:"spend",value:E(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"}),l.length===0?e.jsx("div",{className:"text-xs text-fg-faint",children:"no model data"}):e.jsx("div",{className:"space-y-1",children:l.map(([x,m])=>e.jsxs("div",{className:"flex items-center justify-between text-[11px] font-mono text-fg-dim",children:[e.jsx("span",{children:xe(x)}),e.jsx("span",{className:"text-fg-faint",children:E(m.costUsd)})]},x))})]}),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(([x,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:x}),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})]},x))})]})]})]})}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 St({byModelTotals:t}){const s=Object.entries(t).sort((c,o)=>o[1].costUsd-c[1].costUsd),n=s.reduce((c,[,o])=>c+o.costUsd,0);return e.jsxs("div",{className:`${w} p-4`,children:[e.jsx(D,{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(([c,o])=>{const r=n>0?o.costUsd/n*100:0,a=A(c);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(c),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)," · ",r.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(r,r>0?2:0)}%`,backgroundColor:a}})})]},c)})})]})}function Dt({rows:t}){const s=t.slice(0,3),n=s.reduce((r,a)=>r+a.sharePct,0),c=t.slice(3),o=c.reduce((r,a)=>r+a.sharePct,0);return e.jsxs("div",{className:`${w} p-4`,children:[e.jsx(D,{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(r=>e.jsx("div",{style:{width:`${Math.max(r.sharePct,.5)}%`,backgroundColor:A(r.projectDir)},title:`${O(r.projectDir)} · ${r.sharePct.toFixed(1)}%`},r.projectDir))}),e.jsx("div",{className:"space-y-1 mb-2",children:s.map(r=>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(r.projectDir)}}),O(r.projectDir)]}),e.jsxs("span",{className:"text-fg-faint",children:[r.sharePct.toFixed(1),"%"]})]},r.projectDir))}),c.length>0&&e.jsxs("p",{className:"text-[10px] text-fg-faint",children:[c.length," more project",c.length===1?"":"s"," account for ",o.toFixed(1),"% (long tail)."]})]})]})}const Z=30,pe=9,P=(Z+pe)*2;function Et({totals:t}){const s=t.inputTokens+t.cacheReadTokens+t.cacheCreationTokens,n=s>0?t.cacheReadTokens/s*100:0,c=2*Math.PI*Z,o=P/2;return e.jsxs("div",{className:`${w} p-4`,children:[e.jsx(D,{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:pe}),e.jsx("circle",{cx:o,cy:o,r:Z,fill:"none",stroke:jt,strokeWidth:pe,strokeDasharray:c,strokeDashoffset:c*(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 $t=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];function Ut({days:t,measure:s}){const{buckets:n,weekendShare:c,peakIdx:o}=f.useMemo(()=>{const a=new Array(7).fill(0);for(const i of t){const[x,m,k]=i.date.split("-").map(Number),v=new Date(x,m-1,k).getDay();a[v]+=S(i.totals,s)}const l=a.reduce((i,x)=>i+x,0),u=a[0]+a[6];let d=0;for(let i=1;i<7;i++)a[i]>a[d]&&(d=i);return{buckets:a,weekendShare:l>0?u/l*100:0,peakIdx:d}},[t,s]),r=Math.max(...n,1);return e.jsxs("div",{className:`${w} p-4`,children:[e.jsx(D,{kicker:"05 · composition",title:"Rhythm",right:e.jsxs("span",{className:"text-xs font-mono text-fg-faint",children:["weekend ",c.toFixed(0),"%"]})}),e.jsx("div",{className:"flex items-end gap-2 h-24",children:n.map((a,l)=>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 ${l===o?"bg-accent":"bg-rhythm"}`,style:{height:`${r>0?a/r*100:0}%`,minHeight:a>0?2:0}}),e.jsx("span",{className:"text-[9px] text-fg-faint font-mono",children:$t[l]})]},l))})]})}const Pt=["in","out","total","prompts","sessions","time","spend"],At=[30,60,90,0],Ft="spend",_t=30,Bt=3e4,Ht=[];function Ot(){var ve;const[t,s]=f.useState(Ft),[n,c]=f.useState(_t),o=f.useRef(!1),r=f.useRef(!1),a=p=>{o.current=!0;const b=t;s(p),ue({measure:p}).catch(()=>{s(b),q.error("Couldn't save the measure preference — reverted.")})},l=p=>{r.current=!0;const b=n;c(p),ue({range:p}).catch(()=>{c(b),q.error("Couldn't save the range preference — reverted.")})};f.useEffect(()=>{let p=!1;return fe().then(b=>{p||(!o.current&&b.measure&&Pt.includes(b.measure)&&s(b.measure),!r.current&&b.range!==void 0&&At.includes(b.range)&&c(b.range))}),()=>{p=!0}},[]);const u=Ge(p=>p.navFace),d=ye(p=>p.tabs),i=ye(p=>p.activeTabId),x=((ve=d.find(p=>p.id===i))==null?void 0:ve.cwd)??null,m=f.useRef(u),k=x?Ye(x):null,[v,M]=f.useState(null),h=f.useMemo(()=>u==="project"&&k?new Set([k]):v,[u,k,v]),[g,$]=f.useState(null),[j,J]=f.useState(null),[z,W]=f.useState(!0),[ee,te]=f.useState(0),se=f.useRef(n);se.current=n;const K=f.useRef(!0),ne=f.useRef(0),he=f.useRef(0),F=f.useRef(null),G=f.useCallback(p=>{const b=se.current;ne.current+=1,he.current=Date.now(),Qe(b).then(y=>{if(ne.current-=1,!(!K.current||b!==se.current)){if(W(!1),y.ok){J(y.data);return}p||q.error(`History analytics failed to load: ${y.error}`)}})},[]);f.useEffect(()=>{K.current=!0,W(!0),G(!1)},[n,ee,G]),f.useEffect(()=>{const p=()=>{if(!K.current)return;const T=he.current+Bt-Date.now();if(ne.current===0&&T<=0){G(!0);return}F.current||(F.current=setTimeout(()=>{F.current=null,p()},Math.max(T,1e3)))},b=()=>{document.visibilityState==="visible"&&p()},y=window.api.history.onUpdated(p);return window.addEventListener("focus",p),document.addEventListener("visibilitychange",b),()=>{K.current=!1,y(),window.removeEventListener("focus",p),document.removeEventListener("visibilitychange",b),F.current&&(clearTimeout(F.current),F.current=null)}},[G]);const me=f.useRef(!1);f.useEffect(()=>{if(!me.current){me.current=!0;return}M(null),$(null)},[n]),f.useEffect(()=>{m.current!==u&&(m.current=u,u==="home"&&M(null))},[u]);const{projects:je,resolving:ge}=Ve(),be=f.useMemo(()=>{const p={};for(const b of je)for(const y of b.encodedIds)p[y]=b.cwd;return p},[je]),_=f.useMemo(()=>j&&!ge?dt(j.days,be):null,[j,be,ge]),N=(_==null?void 0:_.days)??(j==null?void 0:j.days)??Ht,oe=(_==null?void 0:_.excluded)??null,R=f.useMemo(()=>j?Je({days:N,totals:j.totals,prevTotals:j.prevTotals},h):null,[j,N,h]),B=f.useMemo(()=>h===null?N:N.map(p=>({date:p.date,byProject:Object.fromEntries(Object.entries(p.byProject).filter(([b])=>h.has(b)))})),[N,h]),Y=f.useMemo(()=>Ne(N,t),[N,t]),ae=f.useMemo(()=>Ne(B,t),[B,t]),Pe=f.useMemo(()=>B.map(p=>({date:p.date,values:Object.fromEntries(Object.entries(p.byProject).map(([b,y])=>[b,S(y,t)]))})),[B,t]),ke=f.useMemo(()=>R?nt(R,t):null,[R,t]),V=f.useMemo(()=>{if(!j||!g)return null;const p=N.flatMap(C=>C.byProject[g]?[C.byProject[g]]:[]),{byModel:b,...y}=Te(p),T={};for(const C of p)for(const[U,ce]of Object.entries(C.toolBreakdown))T[U]=(T[U]??0)+ce;return{totals:y,byModel:b,toolBreakdown:T}},[j,N,g]);f.useEffect(()=>{g&&h!==null&&!h.has(g)&&$(null)},[g,h]);function Ae(p){M(b=>{const y=new Set(Y.map(U=>U.projectDir)),T=b??new Set(y),C=new Set(T);return C.has(p)?C.delete(p):C.add(p),C.size>=y.size?null:C})}function Fe(p){M(new Set([p]))}function _e(){M(null)}function Be(){if(!j)return;const p=B.map(U=>{const{byModel:ce,estimatedCostUsd:He,inputTokens:Oe,outputTokens:Le,cacheCreationTokens:Ie,cacheReadTokens:We}=Te(Object.values(U.byProject));return{date:U.date,costUsd:He,inputTokens:Oe,outputTokens:Le,cacheCreationTokens:Ie,cacheReadTokens:We,byModel:ce}}),b=ct(p),y=new Blob([b],{type:"text/csv"}),T=URL.createObjectURL(y),C=document.createElement("a");C.href=T,C.download=`usage-history-${j.from}-${j.to}.csv`,C.click(),URL.revokeObjectURL(T)}return z&&!j?e.jsx(Se,{}):j&&j.days.length===0?e.jsx(Xe,{title:"no sessions in range",hint:"Widen the range or check back after your next session."}):!j||!R||!ke?e.jsx(Se,{}):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(ht,{measure:t,onMeasure:a,range:n,onRange:l,projectsShown:h===null?Y.length:h.size,projectsTotal:Y.length,fromDate:j.from,toDate:j.to,onRefresh:()=>te(p=>p+1),onExport:Be,exportDisabled:B.length===0}),e.jsxs("div",{className:"flex-1 min-h-0 overflow-auto p-4 space-y-4",children:[e.jsx(gt,{measure:t,headline:ke,activeDays:R.activeDays,projectsTouched:ae.length,totalSessions:R.totals.sessionCount}),e.jsx(vt,{days:N}),oe&&ut(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(yt,{chips:Y.map(p=>({projectDir:p.projectDir,value:p.value})),keep:h,onToggle:Ae,onIsolate:Fe,onShowAll:_e}),e.jsx(wt,{days:Pe,measure:t,selected:g,onSelect:$}),e.jsx(Mt,{rows:ae,measure:t,selected:g,onSelect:$}),g&&V&&e.jsx(Rt,{projectDir:g,totals:V.totals,byModel:V.byModel,toolBreakdown:V.toolBreakdown,onClear:()=>$(null)}),e.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-4",children:[e.jsx(St,{byModelTotals:R.byModelTotals}),e.jsx(Dt,{rows:ae}),e.jsx(Et,{totals:R.totals}),e.jsx(Ut,{days:R.days,measure:t})]})]})]})}function Se(){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 Lt(){return e.jsx(qe,{children:e.jsx(Ot,{})})}const Gt=f.memo(Lt);export{Gt as History};
|
|
1
|
+
import{az as xe,aI as ze,bm as Ke,ap as e,aF as f,aX as q,aA as A,aB as O,b6 as Ge,be as ye,au as Ye,b5 as Ve,n as Xe}from"./index-DZ5TJKNI.js";import{P as qe}from"./Panel-yOYf80ax.js";import{p as De,i as L,m as $e,t as I,u as $,f as Qe}from"./historyTotals-DMGFqK5h.js";import"./monaco-editor-BsIlgG7c.js";function re(){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 Ze(t){return t.promptCount>0||t.sessionCount>0||t.toolCallCount>0||t.inputTokens>0||t.outputTokens>0}function Je(t,s){const n=s===null,c=[],o=re(),r={};let a=0;for(const l of t.days){const u=re();let d=!1;for(const[i,x]of Object.entries(l.byProject))if(!(!n&&!s.has(i))){Ce(u,x),Ce(o,x),Ze(x)&&(d=!0);for(const[m,k]of Object.entries(x.byModel)){const v=r[m]??(r[m]={inputTokens:0,outputTokens:0,cacheReadTokens:0,cacheCreationTokens:0,costUsd:0});v.inputTokens+=k.inputTokens,v.outputTokens+=k.outputTokens,v.cacheReadTokens+=k.cacheReadTokens,v.cacheCreationTokens+=k.cacheCreationTokens,v.costUsd+=k.costUsd,k.estimated&&(v.estimated=!0)}}d&&(a+=1),c.push({date:l.date,totals:u})}return{days:c,totals:o,prevTotals:n?t.prevTotals:re(),prevAvailable:n,byModelTotals:r,activeDays:a}}function Ee(t,s){if(!s)return{pct:null,direction:"flat"};const n=(t-s)/s*100,c=n>0?"up":n<0?"down":"flat";return{pct:n,direction:c}}function et(t,s,n){return s<=0?0:t/s*n}const tt=["promptCount","inputTokens","outputTokens","cacheReadTokens","cacheCreationTokens","toolCallCount","sessionCount","errorCount","activeMinutes","estimatedCostUsd"],st=["inputTokens","outputTokens","cacheReadTokens","cacheCreationTokens","costUsd"];function Te(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=c=>typeof c=="number"&&Number.isFinite(c)?c:0;for(const c of t){for(const o of tt)s[o]+=n(c[o]);for(const[o,r]of Object.entries(c.byModel??{})){const a=s.byModel[o]??(s.byModel[o]={inputTokens:0,outputTokens:0,cacheReadTokens:0,cacheCreationTokens:0,costUsd:0});for(const l of st)a[l]+=n(r==null?void 0:r[l])}}return s}const Ue={in:"In tokens",out:"Out tokens",total:"Total tokens",prompts:"Prompts",sessions:"Sessions",time:"Time",spend:"Spend"};function S(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 nt(t,s){const n=S(t.totals,s),c=t.prevAvailable?Ee(n,S(t.prevTotals,s)):null,o=t.days.map(r=>S(r.totals,s));return{value:n,delta:c,series:o}}function Ne(t,s){const n=new Map,c=Math.ceil(t.length/2);t.forEach((a,l)=>{for(const[u,d]of Object.entries(a.byProject)){let i=n.get(u);i||(i={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,i)),i.totals.promptCount+=d.promptCount,i.totals.inputTokens+=d.inputTokens,i.totals.outputTokens+=d.outputTokens,i.totals.cacheReadTokens+=d.cacheReadTokens,i.totals.cacheCreationTokens+=d.cacheCreationTokens,i.totals.toolCallCount+=d.toolCallCount,i.totals.sessionCount+=d.sessionCount,i.totals.errorCount+=d.errorCount,i.totals.activeMinutes+=d.activeMinutes,i.totals.estimatedCostUsd+=d.estimatedCostUsd;for(const[m,k]of Object.entries(d.toolBreakdown))i.toolBreakdown[m]=(i.toolBreakdown[m]??0)+k;const x=S(d,s);l<c?i.firstHalf+=x:i.secondHalf+=x}});const o=Array.from(n.entries()).map(([a,l])=>{let u="",d=-1;for(const[i,x]of Object.entries(l.toolBreakdown))x>d&&(d=x,u=i);return{projectDir:a,value:S(l.totals,s),sharePct:0,trend:Ee(l.secondHalf,l.firstHalf),sessions:l.totals.sessionCount,topTool:u}}),r=o.reduce((a,l)=>a+l.value,0);for(const a of o)a.sharePct=r>0?a.value/r*100:0;return o.sort((a,l)=>l.value-a.value)}const ot=["date","cost_usd","input_tokens","output_tokens","cache_write_tokens","cache_read_tokens","total_tokens","cache_hit_pct","num_models","top_model"];function at(t){return/[",\n]/.test(t)?`"${t.replace(/"/g,'""')}"`:t}function we(t){return t.inputTokens+t.outputTokens+t.cacheReadTokens+t.cacheCreationTokens}function ct(t){const s=t.map(n=>{const c=n.inputTokens+n.outputTokens+n.cacheCreationTokens+n.cacheReadTokens,o=n.inputTokens+n.cacheReadTokens+n.cacheCreationTokens,r=o>0?n.cacheReadTokens/o*100:0,a=Object.entries(n.byModel).filter(([,i])=>we(i)>0);let l="",u=-1;for(const[i,x]of a){const m=we(x);m>u&&(u=m,l=i)}return[n.date,n.costUsd.toFixed(4),String(n.inputTokens),String(n.outputTokens),String(n.cacheCreationTokens),String(n.cacheReadTokens),String(c),r.toFixed(1),String(a.length),l?xe(l):""].map(at).join(",")});return[ot.join(","),...s].join(`
|
|
2
|
+
`)}const rt={folderCount:0,sessionCount:0,promptCount:0,estimatedCostUsd:0,totalTokens:0};function it(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,c]of Object.entries(s.toolBreakdown??{}))t.toolBreakdown[n]=(t.toolBreakdown[n]??0)+c;for(const[n,c]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+=c.inputTokens,o.outputTokens+=c.outputTokens,o.cacheReadTokens+=c.cacheReadTokens,o.cacheCreationTokens+=c.cacheCreationTokens,o.costUsd+=c.costUsd,c.estimated&&(o.estimated=!0)}}function lt(t,s){const n={};for(const[c,o]of Object.entries(t.byModel??{}))n[c]={...o};return{...t,projectDir:s,toolBreakdown:{...t.toolBreakdown??{}},byModel:n}}function dt(t,s){const n={...rt},c=new Set,o=t.map(r=>{const a={};for(const[l,u]of Object.entries(r.byProject)){const d=s[l];if(!d){c.add(l),n.sessionCount+=u.sessionCount,n.promptCount+=u.promptCount,n.estimatedCostUsd+=u.estimatedCostUsd,n.totalTokens+=u.inputTokens+u.outputTokens;continue}const i=a[d];i?it(i,u):a[d]=lt(u,d)}return{...r,byProject:a}});return n.folderCount=c.size,{days:o,excluded:n}}function ut(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 fe(){return(await ze()).history??{}}let Me=Promise.resolve();function ue(t){const s=Me.then(async()=>{const n=await fe();await Ke({history:{...n,...t}})});return Me=s.catch(()=>{}),s}const xt=["in","out","total","prompts","sessions","time","spend"],ft=[{value:30,label:"30d"},{value:60,label:"60d"},{value:90,label:"90d"},{value:0,label:"All time"}];function Re({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(c=>e.jsx("button",{onClick:()=>n(c.value),className:`px-2 py-1 rounded whitespace-nowrap font-mono ${t===c.value?"bg-bg-hi text-fg shadow-sm":"text-fg-faint hover:text-fg"}`,children:c.label},String(c.value)))})}function ht({measure:t,onMeasure:s,range:n,onRange:c,projectsShown:o,projectsTotal:r,fromDate:a,toDate:l,onRefresh:u,onExport:d,exportDisabled:i}){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(Re,{value:t,options:xt.map(x=>({value:x,label:Ue[x]})),onChange:s}),e.jsx(Re,{value:n,options:ft,onChange:c}),e.jsxs("span",{className:"text-[11px] text-fg-faint font-mono",children:[o," / ",r," projects"]}),e.jsxs("span",{className:"text-[11px] text-fg-faint font-mono",children:[a," → ",l]}),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:i,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 w="rounded-card bg-bg-hi border border-line",mt="#ded2bd",jt="#6f7d52";function D({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 $e(s);default:return L(s)}}function gt({measure:t,headline:s,activeDays:n,projectsTouched:c,totalSessions:o}){const r=n>0?s.value/n:0,a=o>0?s.value/o:0,{delta:l}=s,u=l&&(t==="spend"?l.direction==="down":l.direction==="up"),d=l&&l.direction!=="flat"&&(t==="spend"?l.direction==="up":l.direction==="down"),i=u?"text-delta-good":d?"text-delta-bad":"text-fg-faint";return e.jsxs("div",{className:`${w} p-4`,children:[e.jsx(D,{kicker:"01 · overview",title:Ue[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)}),l?e.jsxs("div",{className:`text-xs font-mono mt-2 ${i}`,children:[l.direction==="up"?"▲":l.direction==="down"?"▼":"·"," ",De(Math.abs(l.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(bt,{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,r)}),e.jsx(X,{label:"per session",value:Q(t,a)}),e.jsx(X,{label:"active days",value:L(n)}),e.jsx(X,{label:"projects touched",value:L(c)})]})]})}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 bt({series:t}){if(t.length<2)return null;const c=Math.max(...t,0),o=Math.min(...t,0),r=c-o||1,a=160/(t.length-1),l=t.map((d,i)=>`${i*a},${48-(d-o)/r*48}`).join(" "),u=`0,48 ${l} 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:l,fill:"none",stroke:"#b85c34",strokeWidth:1.5,vectorEffect:"non-scaling-stroke"})]})}const kt=50;function vt({days:t}){const[s,n]=f.useState(kt),c=f.useRef(!1);f.useEffect(()=>{let d=!1;return fe().then(i=>{d||c.current||typeof i.budgetCapUsd=="number"&&Number.isFinite(i.budgetCapUsd)&&i.budgetCapUsd>0&&n(i.budgetCapUsd)}),()=>{d=!0}},[]);const o=d=>{c.current=!0;const i=s;n(d),ue({budgetCapUsd:d}).catch(()=>{n(i),q.error("Couldn't save the budget cap — reverted.")})},{mtdSpend:r,projectedSpend:a}=f.useMemo(()=>{const d=new Date,i=d.toLocaleDateString("en-CA").slice(0,7),x=new Date(d.getFullYear(),d.getMonth()+1,0).getDate(),m=d.getDate();let k=0;for(const v of t)if(v.date.startsWith(i))for(const M of Object.values(v.byProject))k+=M.estimatedCostUsd;return{mtdSpend:k,projectedSpend:et(k,m,x)}},[t]),l=a>s,u=s>0?Math.min(100,r/s*100):0;return e.jsxs("div",{className:`${w} 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 i=Number(d.target.value);Number.isFinite(i)&&i>0&&o(i)},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:[$(r)," ",e.jsx("span",{className:"text-fg-faint",children:"month-to-date"})]}),e.jsxs("span",{className:l?"text-delta-bad":"text-fg-dim",children:[$(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 ${l?"bg-delta-bad":"bg-sage"}`,style:{width:`${Math.max(u,u>0?2:0)}%`}})}),e.jsx("div",{className:`text-[10px] mt-1 font-mono ${l?"text-delta-bad":"text-fg-faint"}`,children:l?`projected to exceed $${s.toFixed(0)} cap`:`${u.toFixed(0)}% of $${s.toFixed(0)} cap`})]})}function yt({chips:t,keep:s,onToggle:n,onIsolate:c,onShowAll:o}){const r=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 ${r?"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 l=r||s.has(a.projectDir);return e.jsxs("button",{onClick:u=>u.shiftKey?c(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 ${l?"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)}}),O(a.projectDir)]},a.projectDir)})]})}function Ct(t,s){const n=new Map;for(const o of t)for(const[r,a]of Object.entries(o.values))n.set(r,(n.get(r)??0)+a);const c=Array.from(n.entries()).sort((o,r)=>r[1]-o[1]).map(([o])=>o);return t.map(o=>{const r=c.reduce((u,d)=>u+(o.values[d]??0),0);let a=0;const l=c.map(u=>{const d=o.values[u]??0;if(r<=0)return{projectDir:u,value:d,y0:0,y1:0};const i=s==="share"?d/r:d,x=a,m=a+i;return a=m,{projectDir:u,value:d,y0:x,y1:m}});return{date:o.date,bands:l,total:r}})}const ie=720,le=220,de=44,Tt=20;function Nt(t,s){return t==="spend"?$(s):I(s)}function wt({days:t,measure:s,selected:n,onSelect:c}){const[o,r]=f.useState("absolute"),a=f.useMemo(()=>Ct(t,o),[t,o]),l=f.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-Tt,i=a.length>1?u/(a.length-1):u,x=h=>de+h*i,m=h=>d-h/l*d,k=Math.max(1,Math.ceil(a.length/8)),v=4,M=Array.from({length:v+1},(h,g)=>l/v*g);return e.jsxs("div",{className:`${w} p-4`,children:[e.jsx(D,{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:()=>r(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)}%`:Nt(s,h)})]},g)),a.map((h,g)=>{if(g===0)return null;const E=a[g-1];return h.bands.map((j,J)=>{const z=E.bands[J],W=n!==null&&n!==j.projectDir,ee=W?mt:A(j.projectDir),te=[`${x(g-1)},${m(z.y0)}`,`${x(g)},${m(j.y0)}`,`${x(g)},${m(j.y1)}`,`${x(g-1)},${m(z.y1)}`].join(" ");return e.jsx("polygon",{points:te,fill:ee,opacity:W?.6:.75,className:"cursor-pointer",onClick:()=>c(n===j.projectDir?null:j.projectDir),children:e.jsx("title",{children:O(j.projectDir)})},`${j.projectDir}-${g}`)})}),a.map((h,g)=>g%k!==0&&g!==a.length-1?null:e.jsx("text",{x:x(g),y:le-4,fontSize:9,textAnchor:"middle",className:"fill-fg-faint",children:h.date.slice(5)},h.date))]})]})}function Mt({rows:t,measure:s,selected:n,onSelect:c}){return t.length?e.jsxs("div",{className:`${w} overflow-hidden`,children:[e.jsx("div",{className:"p-4 pb-0",children:e.jsx(D,{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 r=A(o.projectDir),a=n===o.projectDir;return e.jsxs("tr",{onClick:()=>c(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:r}}),O(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:r}})})}),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:L(o.sessions)}),e.jsx("td",{className:"px-3 py-2 text-fg-faint font-mono",children:o.topTool||"—"})]},o.projectDir)})})]})]}):e.jsxs("div",{className:`${w} p-4`,children:[e.jsx(D,{kicker:"03 · by project",title:"Ranking"}),e.jsx("div",{className:"text-xs text-fg-faint",children:"no projects in range"})]})}function Rt({projectDir:t,totals:s,byModel:n,toolBreakdown:c,onClear:o}){var i;const r=S(s,"in"),a=S(s,"out"),l=Object.entries(n).sort((x,m)=>m[1].costUsd-x[1].costUsd),u=Object.entries(c).sort((x,m)=>m[1]-x[1]),d=((i=u[0])==null?void 0:i[1])??0;return e.jsxs("div",{className:`${w} p-4`,children:[e.jsx(D,{kicker:"04 · drill in",title:O(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:L(s.promptCount)}),e.jsx(H,{label:"sessions",value:L(s.sessionCount)}),e.jsx(H,{label:"in tokens",value:I(r)}),e.jsx(H,{label:"out tokens",value:I(a)}),e.jsx(H,{label:"spend",value:$(s.estimatedCostUsd)}),e.jsx(H,{label:"time",value:$e(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"}),l.length===0?e.jsx("div",{className:"text-xs text-fg-faint",children:"no model data"}):e.jsx("div",{className:"space-y-1",children:l.map(([x,m])=>e.jsxs("div",{className:"flex items-center justify-between text-[11px] font-mono text-fg-dim",children:[e.jsx("span",{children:xe(x)}),e.jsx("span",{className:"text-fg-faint",children:$(m.costUsd)})]},x))})]}),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(([x,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:x}),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})]},x))})]})]})]})}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 St({byModelTotals:t}){const s=Object.entries(t).sort((c,o)=>o[1].costUsd-c[1].costUsd),n=s.reduce((c,[,o])=>c+o.costUsd,0);return e.jsxs("div",{className:`${w} p-4`,children:[e.jsx(D,{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(([c,o])=>{const r=n>0?o.costUsd/n*100:0,a=A(c);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(c),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)," · ",r.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(r,r>0?2:0)}%`,backgroundColor:a}})})]},c)})})]})}function Dt({rows:t}){const s=t.slice(0,3),n=s.reduce((r,a)=>r+a.sharePct,0),c=t.slice(3),o=c.reduce((r,a)=>r+a.sharePct,0);return e.jsxs("div",{className:`${w} p-4`,children:[e.jsx(D,{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(r=>e.jsx("div",{style:{width:`${Math.max(r.sharePct,.5)}%`,backgroundColor:A(r.projectDir)},title:`${O(r.projectDir)} · ${r.sharePct.toFixed(1)}%`},r.projectDir))}),e.jsx("div",{className:"space-y-1 mb-2",children:s.map(r=>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(r.projectDir)}}),O(r.projectDir)]}),e.jsxs("span",{className:"text-fg-faint",children:[r.sharePct.toFixed(1),"%"]})]},r.projectDir))}),c.length>0&&e.jsxs("p",{className:"text-[10px] text-fg-faint",children:[c.length," more project",c.length===1?"":"s"," account for ",o.toFixed(1),"% (long tail)."]})]})]})}const Z=30,pe=9,P=(Z+pe)*2;function $t({totals:t}){const s=t.inputTokens+t.cacheReadTokens+t.cacheCreationTokens,n=s>0?t.cacheReadTokens/s*100:0,c=2*Math.PI*Z,o=P/2;return e.jsxs("div",{className:`${w} p-4`,children:[e.jsx(D,{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:pe}),e.jsx("circle",{cx:o,cy:o,r:Z,fill:"none",stroke:jt,strokeWidth:pe,strokeDasharray:c,strokeDashoffset:c*(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 Et=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];function Ut({days:t,measure:s}){const{buckets:n,weekendShare:c,peakIdx:o}=f.useMemo(()=>{const a=new Array(7).fill(0);for(const i of t){const[x,m,k]=i.date.split("-").map(Number),v=new Date(x,m-1,k).getDay();a[v]+=S(i.totals,s)}const l=a.reduce((i,x)=>i+x,0),u=a[0]+a[6];let d=0;for(let i=1;i<7;i++)a[i]>a[d]&&(d=i);return{buckets:a,weekendShare:l>0?u/l*100:0,peakIdx:d}},[t,s]),r=Math.max(...n,1);return e.jsxs("div",{className:`${w} p-4`,children:[e.jsx(D,{kicker:"05 · composition",title:"Rhythm",right:e.jsxs("span",{className:"text-xs font-mono text-fg-faint",children:["weekend ",c.toFixed(0),"%"]})}),e.jsx("div",{className:"flex items-end gap-2 h-24",children:n.map((a,l)=>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 ${l===o?"bg-accent":"bg-rhythm"}`,style:{height:`${r>0?a/r*100:0}%`,minHeight:a>0?2:0}}),e.jsx("span",{className:"text-[9px] text-fg-faint font-mono",children:Et[l]})]},l))})]})}const Pt=["in","out","total","prompts","sessions","time","spend"],At=[30,60,90,0],Ft="spend",_t=30,Bt=3e4,Ht=[];function Ot(){var ve;const[t,s]=f.useState(Ft),[n,c]=f.useState(_t),o=f.useRef(!1),r=f.useRef(!1),a=p=>{o.current=!0;const b=t;s(p),ue({measure:p}).catch(()=>{s(b),q.error("Couldn't save the measure preference — reverted.")})},l=p=>{r.current=!0;const b=n;c(p),ue({range:p}).catch(()=>{c(b),q.error("Couldn't save the range preference — reverted.")})};f.useEffect(()=>{let p=!1;return fe().then(b=>{p||(!o.current&&b.measure&&Pt.includes(b.measure)&&s(b.measure),!r.current&&b.range!==void 0&&At.includes(b.range)&&c(b.range))}),()=>{p=!0}},[]);const u=Ge(p=>p.navFace),d=ye(p=>p.tabs),i=ye(p=>p.activeTabId),x=((ve=d.find(p=>p.id===i))==null?void 0:ve.cwd)??null,m=f.useRef(u),k=x?Ye(x):null,[v,M]=f.useState(null),h=f.useMemo(()=>u==="project"&&k?new Set([k]):v,[u,k,v]),[g,E]=f.useState(null),[j,J]=f.useState(null),[z,W]=f.useState(!0),[ee,te]=f.useState(0),se=f.useRef(n);se.current=n;const K=f.useRef(!0),ne=f.useRef(0),he=f.useRef(0),F=f.useRef(null),G=f.useCallback(p=>{const b=se.current;ne.current+=1,he.current=Date.now(),Qe(b).then(y=>{if(ne.current-=1,!(!K.current||b!==se.current)){if(W(!1),y.ok){J(y.data);return}p||q.error(`History analytics failed to load: ${y.error}`)}})},[]);f.useEffect(()=>{K.current=!0,W(!0),G(!1)},[n,ee,G]),f.useEffect(()=>{const p=()=>{if(!K.current)return;const T=he.current+Bt-Date.now();if(ne.current===0&&T<=0){G(!0);return}F.current||(F.current=setTimeout(()=>{F.current=null,p()},Math.max(T,1e3)))},b=()=>{document.visibilityState==="visible"&&p()},y=window.api.history.onUpdated(p);return window.addEventListener("focus",p),document.addEventListener("visibilitychange",b),()=>{K.current=!1,y(),window.removeEventListener("focus",p),document.removeEventListener("visibilitychange",b),F.current&&(clearTimeout(F.current),F.current=null)}},[G]);const me=f.useRef(!1);f.useEffect(()=>{if(!me.current){me.current=!0;return}M(null),E(null)},[n]),f.useEffect(()=>{m.current!==u&&(m.current=u,u==="home"&&M(null))},[u]);const{projects:je,resolving:ge}=Ve(),be=f.useMemo(()=>{const p={};for(const b of je)for(const y of b.encodedIds)p[y]=b.cwd;return p},[je]),_=f.useMemo(()=>j&&!ge?dt(j.days,be):null,[j,be,ge]),N=(_==null?void 0:_.days)??(j==null?void 0:j.days)??Ht,oe=(_==null?void 0:_.excluded)??null,R=f.useMemo(()=>j?Je({days:N,totals:j.totals,prevTotals:j.prevTotals},h):null,[j,N,h]),B=f.useMemo(()=>h===null?N:N.map(p=>({date:p.date,byProject:Object.fromEntries(Object.entries(p.byProject).filter(([b])=>h.has(b)))})),[N,h]),Y=f.useMemo(()=>Ne(N,t),[N,t]),ae=f.useMemo(()=>Ne(B,t),[B,t]),Pe=f.useMemo(()=>B.map(p=>({date:p.date,values:Object.fromEntries(Object.entries(p.byProject).map(([b,y])=>[b,S(y,t)]))})),[B,t]),ke=f.useMemo(()=>R?nt(R,t):null,[R,t]),V=f.useMemo(()=>{if(!j||!g)return null;const p=N.flatMap(C=>C.byProject[g]?[C.byProject[g]]:[]),{byModel:b,...y}=Te(p),T={};for(const C of p)for(const[U,ce]of Object.entries(C.toolBreakdown))T[U]=(T[U]??0)+ce;return{totals:y,byModel:b,toolBreakdown:T}},[j,N,g]);f.useEffect(()=>{g&&h!==null&&!h.has(g)&&E(null)},[g,h]);function Ae(p){M(b=>{const y=new Set(Y.map(U=>U.projectDir)),T=b??new Set(y),C=new Set(T);return C.has(p)?C.delete(p):C.add(p),C.size>=y.size?null:C})}function Fe(p){M(new Set([p]))}function _e(){M(null)}function Be(){if(!j)return;const p=B.map(U=>{const{byModel:ce,estimatedCostUsd:He,inputTokens:Oe,outputTokens:Le,cacheCreationTokens:Ie,cacheReadTokens:We}=Te(Object.values(U.byProject));return{date:U.date,costUsd:He,inputTokens:Oe,outputTokens:Le,cacheCreationTokens:Ie,cacheReadTokens:We,byModel:ce}}),b=ct(p),y=new Blob([b],{type:"text/csv"}),T=URL.createObjectURL(y),C=document.createElement("a");C.href=T,C.download=`usage-history-${j.from}-${j.to}.csv`,C.click(),URL.revokeObjectURL(T)}return z&&!j?e.jsx(Se,{}):j&&j.days.length===0?e.jsx(Xe,{title:"no sessions in range",hint:"Widen the range or check back after your next session."}):!j||!R||!ke?e.jsx(Se,{}):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(ht,{measure:t,onMeasure:a,range:n,onRange:l,projectsShown:h===null?Y.length:h.size,projectsTotal:Y.length,fromDate:j.from,toDate:j.to,onRefresh:()=>te(p=>p+1),onExport:Be,exportDisabled:B.length===0}),e.jsxs("div",{className:"flex-1 min-h-0 overflow-auto p-4 space-y-4",children:[e.jsx(gt,{measure:t,headline:ke,activeDays:R.activeDays,projectsTouched:ae.length,totalSessions:R.totals.sessionCount}),e.jsx(vt,{days:N}),oe&&ut(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(yt,{chips:Y.map(p=>({projectDir:p.projectDir,value:p.value})),keep:h,onToggle:Ae,onIsolate:Fe,onShowAll:_e}),e.jsx(wt,{days:Pe,measure:t,selected:g,onSelect:E}),e.jsx(Mt,{rows:ae,measure:t,selected:g,onSelect:E}),g&&V&&e.jsx(Rt,{projectDir:g,totals:V.totals,byModel:V.byModel,toolBreakdown:V.toolBreakdown,onClear:()=>E(null)}),e.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-4",children:[e.jsx(St,{byModelTotals:R.byModelTotals}),e.jsx(Dt,{rows:ae}),e.jsx($t,{totals:R.totals}),e.jsx(Ut,{days:R.days,measure:t})]})]})]})}function Se(){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 Lt(){return e.jsx(qe,{children:e.jsx(Ot,{})})}const Gt=f.memo(Lt);export{Gt as History};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{
|
|
2
|
-
`}function Ne(t,o){return(t[o]??[]).reduce((n,l)=>{var c;return n+(((c=l.hooks)==null?void 0:c.length)??0)},0)}function _e(){const t=te(),o=se(),n=(o==null?void 0:o.cwd)??null,l=ae(a=>a.navFace),c=d.useRef(!1),f=d.useRef(l),[m,x]=d.useState(()=>l==="project"&&n?"project":"user"),[r,u]=d.useState("PreToolUse"),[s,S]=d.useState("effective");d.useEffect(()=>{if(f.current!==l){if(f.current=l,c.current){c.current=!1;return}x(l==="project"&&n?"project":"user")}},[l,n]),d.useEffect(()=>{l==="project"&&s==="library"&&S("effective")},[l,s]);const g=a=>{c.current=!0,x(a)},v=he(le,t,n),p=v[m]??null,w=T(a=>a.files),
|
|
3
|
-
`)};if(!t)return e.jsx(R,{title:"loading…"});if(s==="library")return e.jsx(O,{toolbar:E,children:e.jsx(ge,{})});if(m!=="user"&&!n)return e.jsx(O,{toolbar:e.jsxs(e.Fragment,{children:[E,e.jsx("span",{className:"mx-2 text-fg-faint",children:"·"}),e.jsx(D,{scopes:["user","project","local"],active:m,onChange:g})]}),children:e.jsx(R,{title:"no active project"})});if(!p)return e.jsx(R,{title:"loading…"});const b=w[p],{full:Y,hooks:y,err:j}=b?W(b.draftRaw):{full:{},hooks:{},err:null},B=Object.keys(y).filter(a=>!ve.has(a)),L=B.reduce((a,h)=>a+(y[h]??[]).reduce((i,k)=>{var F;return i+(((F=k.hooks)==null?void 0:F.length)??0)},0),0),P=a=>{if(j){q.error(H);return}N(null),A(p,ke(Y,a))},_=y[r]??[],z=()=>{P({...y,[r]:[..._,{matcher:"",hooks:[{type:"command",command:""}]}]})},X=(a,h)=>{const i=_.slice();i[a]=h,P({...y,[r]:i})},Z=a=>{P({...y,[r]:_.filter((h,i)=>i!==a)})};return e.jsxs(O,{toolbar:e.jsxs(e.Fragment,{children:[E,e.jsx("span",{className:"mx-2 text-fg-faint",children:"·"}),e.jsx(D,{scopes:["user","project","local"],active:m,onChange:g}),e.jsx("span",{className:"ml-3 text-fg-faint truncate",children:s==="effective"?`overrides → ${p}`:p}),e.jsx("div",{className:"flex-1"}),e.jsx("a",{href:"https://code.claude.com/docs/en/hooks",target:"_blank",rel:"noreferrer",className:"text-fg-faint hover:text-fg-dim underline-offset-2 hover:underline",children:"hook reference ↗"})]}),footer:b?e.jsx(pe,{dirty:b.dirty,busy:b.busy,parseError:G||j||b.parseError,lastSavedAt:b.lastSavedAt,onSave:async()=>{N(null);const a=await $(p);a.ok||N(a.error??"save failed")},onRevert:()=>{N(null),V(p)}}):null,children:[s==="effective"?e.jsx(xe,{node:K,targetScope:m,onOverride:I,schema:fe().rootedAt(["hooks"]),rootLabel:"hooks"}):e.jsxs("div",{className:"flex flex-col h-full",children:[j?e.jsxs("div",{role:"alert",className:"px-3 py-2 border-b border-line text-xs text-red-400",children:[H," (",j,")"]}):null,L>0?e.jsxs("div",{className:"px-3 py-2 border-b border-line text-xs bg-bg-elev text-fg-dim",children:[e.jsx("span",{className:"text-yellow-400",children:"⚠"})," ",L," hook(s) configured under unknown event names: ",e.jsx("span",{className:"font-mono text-fg",children:B.join(", ")}),e.jsx("span",{className:"text-fg-faint",children:" · these are ignored by Claude Code 2026; edit settings.json directly to remove."})]}):null,e.jsx(me,{sidebarWidth:"14rem",sidebar:e.jsx("div",{className:"py-1",children:M.map(a=>{const h=Ne(y,a),i=ye[a],k=i?e.jsxs("span",{className:"block space-y-1",children:[e.jsx("span",{className:"block text-fg",children:i.when}),e.jsxs("span",{className:"block text-fg-faint font-mono",children:["payload: ",i.payload]}),i.example?e.jsxs("span",{className:"block text-fg-faint italic",children:["e.g. ",i.example]}):null]}):e.jsx("span",{className:"text-fg-faint italic",children:"no documentation yet"});return e.jsx("div",{className:"[&>span]:w-full",children:e.jsx(ie,{content:k,align:"bottom-center",children:e.jsxs("button",{onClick:()=>u(a),title:i==null?void 0:i.when,className:`w-full text-left px-3 py-1 text-xs ${r===a?"bg-bg-hi text-fg":"text-fg-dim hover:text-fg hover:bg-bg-hi"}`,children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"truncate",children:a}),h>0&&e.jsx("span",{className:"text-accent shrink-0 ml-2",children:h})]}),i?e.jsx("span",{className:"block text-[11px] leading-[1.3] text-fg-faint/80 font-normal truncate",children:i.when}):e.jsx("span",{className:"block text-[11px] leading-[1.3] text-fg-faint/80 italic font-normal truncate",children:"no documentation yet"})]})})},a)})}),detail:e.jsxs("div",{className:"p-4 space-y-3 max-w-3xl",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-xs uppercase tracking-wider text-fg",children:r}),e.jsx("button",{onClick:z,disabled:!!j,className:"px-2 py-0.5 text-xs border border-line rounded text-fg-dim hover:text-fg hover:bg-bg-hi disabled:opacity-40 disabled:cursor-not-allowed",children:"+ add group"})]}),_.length===0?e.jsx("div",{className:"text-fg-faint text-xs",children:"no hooks for this event"}):_.map((a,h)=>e.jsx(Se,{group:a,jsonInvalid:!!j,onChange:i=>X(h,i),onRemove:()=>Z(h),onTestFire:i=>U({event:r,matcher:a.matcher??"",command:i.command??""})},h))]})})]}),C?e.jsx(Ee,{event:C.event,matcher:C.matcher,command:C.command,onClose:()=>U(null)}):null]})}const $e=d.memo(_e);function Se({group:t,jsonInvalid:o,onChange:n,onRemove:l,onTestFire:c}){const f=()=>n({...t,hooks:[...t.hooks??[],{type:"command",command:""}]}),m=(r,u)=>{const s=t.hooks.slice();s[r]=u,n({...t,hooks:s})},x=r=>n({...t,hooks:t.hooks.filter((u,s)=>s!==r)});return e.jsxs("div",{className:"border border-line rounded p-3 bg-bg-elev space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-fg-faint w-16",children:"matcher"}),e.jsx("input",{value:t.matcher??"",disabled:o,onChange:r=>n({...t,matcher:r.target.value}),placeholder:"tool name regex or exact match (optional)",className:"flex-1 bg-bg border border-line rounded px-2 py-0.5 text-xs text-fg font-mono"}),e.jsx("button",{onClick:l,disabled:o,className:"text-fg-faint hover:text-red-400 text-xs disabled:opacity-40",title:"remove group",children:"× group"})]}),(t.hooks??[]).map((r,u)=>e.jsx(Ce,{rule:r,jsonInvalid:o,onChange:s=>m(u,s),onRemove:()=>x(u),onTestFire:()=>c(r)},u)),e.jsx("button",{onClick:f,disabled:o,className:"text-xs text-fg-faint hover:text-fg disabled:opacity-40",children:"+ add hook"})]})}function Ce({rule:t,jsonInvalid:o,onChange:n,onRemove:l,onTestFire:c}){const f=s=>({command:"e.g. node ./scripts/lint.js $FILE",http:"e.g. https://hooks.example.com/notify",prompt:"e.g. Review this change for security issues",agent:"e.g. security-reviewer",mcp_tool:"e.g. mcp__server__tool"})[s],m=t.type==="command"?"command":t.type==="http"?"url":t.type==="prompt"?"prompt":t.type==="mcp_tool"?"mcpTool":"agent",x=t[m]??"",r=(t.args??[]).join(" "),u={type:"hook",name:x||t.type,command:t.type==="command"?t.command:void 0,url:t.type==="http"?t.url:void 0};return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("select",{value:t.type,disabled:o,onChange:s=>n({type:s.target.value}),className:"bg-bg border border-line rounded px-1 py-0.5 text-xs text-fg",children:we.map(s=>e.jsx("option",{value:s,children:s},s))}),e.jsx(ue,{interactive:!1,input:u}),e.jsx("input",{value:x,disabled:o,onChange:s=>n({...t,[m]:s.target.value}),placeholder:f(t.type),className:`flex-1 bg-bg border rounded px-2 py-0.5 text-xs text-fg font-mono ${o?"border-red-500/70":x.trim()?"border-line":"border-yellow-600/50"}`}),o?e.jsx("span",{className:"text-red-400 text-xs",title:"The enclosing settings.json is malformed; fix the JSON before editing.",children:"× invalid"}):null,e.jsx("input",{value:t.timeout??"",disabled:o,onChange:s=>n({...t,timeout:s.target.value?Number(s.target.value):void 0}),placeholder:"timeout ms",className:"w-20 bg-bg border border-line rounded px-2 py-0.5 text-xs text-fg"}),t.type==="command"?e.jsx("button",{onClick:c,disabled:o||!x.trim(),className:"px-2 py-0.5 text-xs border border-line rounded text-fg-dim hover:text-fg hover:bg-bg-hi disabled:opacity-40 disabled:cursor-not-allowed",title:"Run this command with a fake event payload",children:"test fire"}):null,e.jsx("button",{onClick:l,disabled:o,className:"text-fg-faint hover:text-red-400 text-xs disabled:opacity-40",children:"×"})]}),t.type==="command"?e.jsxs("div",{className:"flex items-center gap-2 pl-[3.75rem]",children:[e.jsx("span",{className:"text-xs text-fg-faint w-12",children:"args"}),e.jsx("input",{value:r,disabled:o,onChange:s=>n({...t,args:s.target.value.trim()?s.target.value.split(/\s+/).filter(Boolean):void 0}),placeholder:"argv array (v2.1.139+ exec form, no shell)",className:"flex-1 bg-bg border border-line rounded px-2 py-0.5 text-xs text-fg font-mono"})]}):null,e.jsxs("div",{className:"flex items-center gap-2 pl-[3.75rem]",children:[e.jsx("span",{className:"text-xs text-fg-faint w-12",children:"term"}),e.jsx("input",{value:t.terminalSequence??"",disabled:o,onChange:s=>n({...t,terminalSequence:s.target.value||void 0}),placeholder:"terminalSequence — e.g. \\\\a (bell), v2.1.141+",className:"flex-1 bg-bg border border-line rounded px-2 py-0.5 text-xs text-fg font-mono"})]})]})}function Fe(t){return JSON.stringify(je[t]??{},null,2)}function Te(t,o){if(!t.trim())return{matched:!0,target:null,note:"empty matcher → matches all"};const n=o&&typeof o=="object"&&"tool_name"in o?String(o.tool_name??""):null;if(n==null)return{matched:!1,target:null,note:"payload has no tool_name to match against"};try{return{matched:new RegExp(`^(?:${t})$`).test(n),target:n}}catch{return{matched:t===n,target:n,note:"matcher not valid regex; fell back to exact match"}}}function Ee({event:t,matcher:o,command:n,onClose:l}){const[c,f]=d.useState(()=>Fe(t)),[m,x]=d.useState(!1),[r,u]=d.useState(null),[s,S]=d.useState(null);let g=null;try{JSON.parse(c)}catch(p){g=p.message}const v=async()=>{x(!0),u(null);let p=null;try{p=JSON.parse(c)}catch{}S(Te(o,p));try{const w=await window.api.app.testFireHook({command:n,payload:c,timeoutMs:5e3});u(w)}finally{x(!1)}};return e.jsx(de,{open:!0,onClose:l,title:`Test fire — ${t}`,children:e.jsxs("div",{className:"space-y-3 text-xs",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-fg-faint mb-1",children:"resolved command"}),e.jsx("div",{className:"font-mono text-fg bg-bg border border-line rounded px-2 py-1 break-all",children:n})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-fg-faint mb-1",children:"matcher"}),e.jsx("div",{className:"font-mono text-fg bg-bg border border-line rounded px-2 py-1",children:o||e.jsx("span",{className:"text-fg-faint",children:"(empty — matches all)"})})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("span",{className:"text-fg-faint",children:"fake event payload (stdin)"}),g?e.jsxs("span",{className:"text-red-400",children:["× ",g]}):null]}),e.jsx("textarea",{value:c,onChange:p=>f(p.target.value),rows:8,className:`w-full bg-bg border rounded px-2 py-1 font-mono text-fg ${g?"border-red-500/70":"border-line"}`})]}),s?e.jsxs("div",{children:[e.jsx("div",{className:"text-fg-faint mb-1",children:"matcher result"}),e.jsxs("div",{className:"font-mono",children:[e.jsx("span",{className:s.matched?"text-green-400":"text-red-400",children:s.matched?"✓ match":"✗ no match"}),s.target!=null?e.jsxs("span",{className:"text-fg-dim",children:[' · target tool_name="',s.target,'"']}):null,s.note?e.jsx("div",{className:"text-fg-faint",children:s.note}):null]})]}):null,r?e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"text-fg-faint",children:["exit ",r.exitCode," · ",r.durationMs,"ms"]}),r.stdout?e.jsxs("div",{children:[e.jsx("div",{className:"text-fg-faint",children:"stdout"}),e.jsx("pre",{className:"bg-bg border border-line rounded p-2 font-mono text-fg whitespace-pre-wrap break-all max-h-40 overflow-auto",children:r.stdout})]}):null,r.stderr?e.jsxs("div",{children:[e.jsx("div",{className:"text-fg-faint",children:"stderr"}),e.jsx("pre",{className:"bg-bg border border-line rounded p-2 font-mono text-red-300 whitespace-pre-wrap break-all max-h-40 overflow-auto",children:r.stderr})]}):null]}):null,e.jsxs("div",{className:"flex items-center justify-end gap-2 pt-1",children:[e.jsx("button",{onClick:l,className:"px-2 py-0.5 text-xs border border-line rounded text-fg-dim hover:text-fg hover:bg-bg-hi",children:"close"}),e.jsx("button",{onClick:v,disabled:m||!!g||!n.trim(),className:"px-2 py-0.5 text-xs border border-line rounded text-fg hover:bg-bg-hi disabled:opacity-40 disabled:cursor-not-allowed",children:m?"running…":"run"})]})]})})}export{$e as Hooks};
|
|
1
|
+
import{aF as d,b4 as te,aY as se,b6 as ae,a_ as T,ar as oe,aw as ne,al as re,ap as e,n as R,Z as ie,N as le,aX as D,aO as ce,v as de}from"./index-DZ5TJKNI.js";import{P as O}from"./Panel-yOYf80ax.js";import{L as me}from"./ListDetail-CY5hhwn9.js";import{S as pe}from"./SaveBar-35Nw2YsZ.js";import{S as q}from"./ScopeSwitcher-BCXNrrrs.js";import{P as ue}from"./ProvenanceBadge-DFyBe7Po.js";import{u as he,E as xe,s as fe}from"./settingsSchema-BfnNE6ne.js";import{H as ge}from"./Library-wBI4Fwh3.js";import{V as be}from"./ViewTabs-D82jJ4VS.js";import"./monaco-editor-BsIlgG7c.js";import"./claude-settings-schema-COigsajx.js";import"./Button-BuyzGzO8.js";import"./listSkills-C1aWKf0T.js";const ye={UserPromptSubmit:{when:"Fires just before the user prompt is sent to the model.",payload:"{ prompt: string }",example:"Block submission if the prompt mentions a secret."},UserPromptExpansion:{when:"Fires when a slash command expands into its final prompt text.",payload:"{ command: string, expanded: string }",example:"Audit which slash commands actually run, post-expansion."},PreToolUse:{when:"Fires before any tool runs. Can block the call.",payload:"{ tool_name: string, tool_input: object }",example:'matcher="Bash" — block dangerous shell commands.'},PostToolUse:{when:"Fires after a tool completes successfully.",payload:"{ tool_name: string, tool_input: object, tool_result: string }",example:'matcher="Write|Edit" — run a linter on changed files.'},PostToolUseFailure:{when:"Fires after a tool errors out (non-zero exit, exception, or refusal).",payload:"{ tool_name: string, tool_input: object, error: string }",example:"Pipe failed Bash runs into a desktop notification."},PostToolBatch:{when:"Fires once after a parallel batch of tool calls all complete.",payload:"{ tool_uses: Array<{ tool_name, tool_input, tool_result? }> }",example:"Aggregate file-edit batches into a single commit message."},Stop:{when:"Fires when the model emits end_turn.",payload:"{ stop_reason: string, output_tokens: number }",example:"Play a chime when the agent finishes a long task."},StopFailure:{when:"Fires when a turn aborts without end_turn (rate-limit, network, OOM).",payload:'{ reason: "rate_limit"|"network"|"oom"|"killed"|string }',example:"Auto-resume on transient failures."},SessionStart:{when:"Fires once when a session boots (claude or claude -p).",payload:'{ source: "startup"|"resume", model: string, agent_type: string }',example:"Inject a project-specific system prompt addendum."},SessionEnd:{when:"Fires once when the session terminates.",payload:'{ reason: "user_quit"|"timeout"|"error"|string }',example:"Persist transcript summary to ~/.claude/projects/<>."},Setup:{when:"Fires during interactive setup (claude /setup, /init).",payload:'{ mode: "init"|"reconfigure"|string }'},PreCompact:{when:"Fires before transcript compaction runs.",payload:'{ transcript_path: string, trigger: "manual"|"auto" }',example:"Snapshot the pre-compact transcript for later diffing."},PostCompact:{when:"Fires after compaction; the active transcript is the compacted one.",payload:'{ transcript_path: string, trigger: "manual"|"auto" }'},InstructionsLoaded:{when:"Fires after CLAUDE.md and any imported memory files are loaded.",payload:'{ source: "session_start"|"reload" }'},Notification:{when:"Fires when Claude Code emits a desktop notification.",payload:"{ title: string, message: string }",example:"Forward to your own notify-send / osascript pipeline."},PermissionRequest:{when:"Fires when a tool needs user permission (per the permissions block).",payload:"{ tool_name: string, tool_input?: object }",example:"Auto-allow npm test invocations."},PermissionDenied:{when:"Fires when the user (or policy) denies a permission request.",payload:"{ tool_name: string, retry: boolean }",example:"Track which tools the user habitually rejects."},SubagentStart:{when:"Fires when a subagent (Task tool) spawns.",payload:"{ agent_type: string }",example:'matcher="security-reviewer" — log every security scan.'},SubagentStop:{when:"Fires when a subagent finishes.",payload:'{ agent_type: string, reason: "end_turn"|"error"|string }'},TeammateIdle:{when:"Fires when a teammate agent goes idle (waiting for input).",payload:"{ teammate_id?: string }"},TaskCreated:{when:"Fires when a new Task is created via the Task tool.",payload:"{ task: { description: string, ...} }",example:"Track each spawned task in an external queue."},TaskCompleted:{when:"Fires when a Task completes (success or failure).",payload:"{ task: { description: string, ...} }"},ConfigChange:{when:"Fires when settings.json (any scope) is mutated mid-session.",payload:'{ source: "user_settings"|"project_settings"|"local_settings" }',example:"Reload tooling that depends on env vars on config change."},CwdChanged:{when:"Fires when the working directory changes (e.g. agent cd-ing).",payload:"{ old_cwd: string, new_cwd: string }",example:"Refresh project-scoped indexers when cwd drifts."},FileChanged:{when:"Fires when a watched file outside Claude Code's edits changes.",payload:'{ file_path: string, change_type: "modified"|"created"|"deleted" }',example:"Re-run typecheck when any .ts file changes."},WorktreeCreate:{when:"Fires after a git worktree is created via /worktree or subagent isolation.",payload:"{ worktree_path?: string, branch?: string }"},WorktreeRemove:{when:"Fires after a git worktree is removed.",payload:"{ worktree_path?: string }"},Elicitation:{when:"Fires when Claude asks the user a multiple-choice question.",payload:'{ action: "accept"|"reject", ...}'},ElicitationResult:{when:"Fires after the user resolves an elicitation prompt.",payload:"{ choice?: string }"}},W=["UserPromptSubmit","UserPromptExpansion","PreToolUse","PostToolUse","PostToolUseFailure","PostToolBatch","Stop","StopFailure","SessionStart","SessionEnd","Setup","PreCompact","PostCompact","InstructionsLoaded","Notification","PermissionRequest","PermissionDenied","SubagentStart","SubagentStop","TeammateIdle","TaskCreated","TaskCompleted","ConfigChange","CwdChanged","FileChanged","WorktreeCreate","WorktreeRemove","Elicitation","ElicitationResult"],ve=new Set(W),we=["command","http","prompt","agent","mcp_tool"],je={UserPromptSubmit:{prompt:"hello"},UserPromptExpansion:{command:"/example",expanded:"hello"},PreToolUse:{tool_name:"Bash",tool_input:{command:"ls"}},PostToolUse:{tool_name:"Bash",tool_input:{command:"ls"},tool_result:""},PostToolUseFailure:{tool_name:"Bash",tool_input:{command:"ls"},error:""},PostToolBatch:{tool_uses:[]},Stop:{stop_reason:"end_turn",output_tokens:0},StopFailure:{reason:"rate_limit"},SessionStart:{source:"startup",model:"",agent_type:""},SessionEnd:{reason:"user_quit"},Setup:{mode:"init"},PreCompact:{transcript_path:"",trigger:"manual"},PostCompact:{transcript_path:"",trigger:"manual"},InstructionsLoaded:{source:"session_start"},Notification:{title:"test",message:"test notification"},PermissionRequest:{tool_name:"Bash"},PermissionDenied:{tool_name:"Bash",retry:!1},SubagentStart:{agent_type:"general-purpose"},SubagentStop:{agent_type:"general-purpose",reason:"end_turn"},TeammateIdle:{},TaskCreated:{task:{description:""}},TaskCompleted:{task:{description:""}},ConfigChange:{source:"user_settings"},CwdChanged:{old_cwd:"",new_cwd:""},FileChanged:{file_path:"",change_type:"modified"},WorktreeCreate:{},WorktreeRemove:{},Elicitation:{action:"accept"},ElicitationResult:{}},A="This settings file has invalid JSON. Fix it in the Settings raw editor first; Hooks will not overwrite it.";function M(t){if(t.trim()==="")return{full:{},hooks:{},err:null};try{const o=JSON.parse(t);if(o===null||typeof o!="object"||Array.isArray(o))return{full:{},hooks:{},err:"settings file is not a JSON object"};const n=o;return{full:n,hooks:n.hooks??{},err:null}}catch(o){return{full:{},hooks:{},err:o.message}}}function ke(t,o){return JSON.stringify({...t,hooks:o},null,2)+`
|
|
2
|
+
`}function Ne(t,o){return(t[o]??[]).reduce((n,l)=>{var c;return n+(((c=l.hooks)==null?void 0:c.length)??0)},0)}function _e(){const t=te(),o=se(),n=(o==null?void 0:o.cwd)??null,l=ae(a=>a.navFace),c=d.useRef(!1),f=d.useRef(l),[m,x]=d.useState(()=>l==="project"&&n?"project":"user"),[r,u]=d.useState("PreToolUse"),[s,S]=d.useState("effective");d.useEffect(()=>{if(f.current!==l){if(f.current=l,c.current){c.current=!1;return}x(l==="project"&&n?"project":"user")}},[l,n]),d.useEffect(()=>{l==="project"&&s==="library"&&S("effective")},[l,s]);const g=a=>{c.current=!0,x(a)},v=he(le,t,n),p=v[m]??null,w=T(a=>a.files),H=T(a=>a.setDraft),$=T(a=>a.saveJson),V=T(a=>a.revert),[G,N]=d.useState(null),[C,U]=d.useState(null),P=e.jsx(be,{options:[{key:"effective",label:"Effective"},{key:"events",label:"Events"},...l==="home"?[{key:"library",label:"Library"}]:[]],active:s,onChange:S}),K=d.useMemo(()=>{const a=oe(ne(w,v));return re(a,["hooks"])??{kind:"object",children:{}}},[w,v]),I=(a,h)=>{var J;const i=v[m];if(!i)return;const{full:k,err:F}=M(((J=w[i])==null?void 0:J.draftRaw)??"");if(F){D.error(A);return}N(null);const Q=ce(k.hooks??{},a,h),ee={...k,hooks:Q};H(i,JSON.stringify(ee,null,2)+`
|
|
3
|
+
`)};if(!t)return e.jsx(R,{title:"loading…"});if(s==="library")return e.jsx(O,{toolbar:P,children:e.jsx(ge,{})});if(m!=="user"&&!n)return e.jsx(O,{toolbar:e.jsxs(e.Fragment,{children:[P,e.jsx("span",{className:"mx-2 text-fg-faint",children:"·"}),e.jsx(q,{scopes:["user","project","local"],active:m,onChange:g})]}),children:e.jsx(R,{title:"no active project"})});if(!p)return e.jsx(R,{title:"loading…"});const b=w[p],{full:Y,hooks:y,err:j}=b?M(b.draftRaw):{full:{},hooks:{},err:null},B=Object.keys(y).filter(a=>!ve.has(a)),L=B.reduce((a,h)=>a+(y[h]??[]).reduce((i,k)=>{var F;return i+(((F=k.hooks)==null?void 0:F.length)??0)},0),0),E=a=>{if(j){D.error(A);return}N(null),H(p,ke(Y,a))},_=y[r]??[],z=()=>{E({...y,[r]:[..._,{matcher:"",hooks:[{type:"command",command:""}]}]})},X=(a,h)=>{const i=_.slice();i[a]=h,E({...y,[r]:i})},Z=a=>{E({...y,[r]:_.filter((h,i)=>i!==a)})};return e.jsxs(O,{toolbar:e.jsxs(e.Fragment,{children:[P,e.jsx("span",{className:"mx-2 text-fg-faint",children:"·"}),e.jsx(q,{scopes:["user","project","local"],active:m,onChange:g}),e.jsx("span",{className:"ml-3 text-fg-faint truncate",children:s==="effective"?`overrides → ${p}`:p}),e.jsx("div",{className:"flex-1"}),e.jsx("a",{href:"https://code.claude.com/docs/en/hooks",target:"_blank",rel:"noreferrer",className:"text-fg-faint hover:text-fg-dim underline-offset-2 hover:underline",children:"hook reference ↗"})]}),footer:b?e.jsx(pe,{dirty:b.dirty,busy:b.busy,parseError:G||j||b.parseError,lastSavedAt:b.lastSavedAt,onSave:async()=>{N(null);const a=await $(p);a.ok||N(a.error??"save failed")},onRevert:()=>{N(null),V(p)}}):null,children:[s==="effective"?e.jsx(xe,{node:K,targetScope:m,onOverride:I,schema:fe().rootedAt(["hooks"]),rootLabel:"hooks"}):e.jsxs("div",{className:"flex flex-col h-full",children:[j?e.jsxs("div",{role:"alert",className:"px-3 py-2 border-b border-line text-xs text-red-400",children:[A," (",j,")"]}):null,L>0?e.jsxs("div",{className:"px-3 py-2 border-b border-line text-xs bg-bg-elev text-fg-dim",children:[e.jsx("span",{className:"text-yellow-400",children:"⚠"})," ",L," hook(s) configured under unknown event names: ",e.jsx("span",{className:"font-mono text-fg",children:B.join(", ")}),e.jsx("span",{className:"text-fg-faint",children:" · these are ignored by Claude Code 2026; edit settings.json directly to remove."})]}):null,e.jsx(me,{sidebarWidth:"14rem",sidebar:e.jsx("div",{className:"py-1",children:W.map(a=>{const h=Ne(y,a),i=ye[a],k=i?e.jsxs("span",{className:"block space-y-1",children:[e.jsx("span",{className:"block text-fg",children:i.when}),e.jsxs("span",{className:"block text-fg-faint font-mono",children:["payload: ",i.payload]}),i.example?e.jsxs("span",{className:"block text-fg-faint italic",children:["e.g. ",i.example]}):null]}):e.jsx("span",{className:"text-fg-faint italic",children:"no documentation yet"});return e.jsx("div",{className:"[&>span]:w-full",children:e.jsx(ie,{content:k,align:"bottom-center",children:e.jsxs("button",{onClick:()=>u(a),title:i==null?void 0:i.when,className:`w-full text-left px-3 py-1 text-xs ${r===a?"bg-bg-hi text-fg":"text-fg-dim hover:text-fg hover:bg-bg-hi"}`,children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"truncate",children:a}),h>0&&e.jsx("span",{className:"text-accent shrink-0 ml-2",children:h})]}),i?e.jsx("span",{className:"block text-[11px] leading-[1.3] text-fg-faint/80 font-normal truncate",children:i.when}):e.jsx("span",{className:"block text-[11px] leading-[1.3] text-fg-faint/80 italic font-normal truncate",children:"no documentation yet"})]})})},a)})}),detail:e.jsxs("div",{className:"p-4 space-y-3 max-w-3xl",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-xs uppercase tracking-wider text-fg",children:r}),e.jsx("button",{onClick:z,disabled:!!j,className:"px-2 py-0.5 text-xs border border-line rounded text-fg-dim hover:text-fg hover:bg-bg-hi disabled:opacity-40 disabled:cursor-not-allowed",children:"+ add group"})]}),_.length===0?e.jsx("div",{className:"text-fg-faint text-xs",children:"no hooks for this event"}):_.map((a,h)=>e.jsx(Se,{group:a,jsonInvalid:!!j,onChange:i=>X(h,i),onRemove:()=>Z(h),onTestFire:i=>U({event:r,matcher:a.matcher??"",command:i.command??""})},h))]})})]}),C?e.jsx(Pe,{event:C.event,matcher:C.matcher,command:C.command,onClose:()=>U(null)}):null]})}const $e=d.memo(_e);function Se({group:t,jsonInvalid:o,onChange:n,onRemove:l,onTestFire:c}){const f=()=>n({...t,hooks:[...t.hooks??[],{type:"command",command:""}]}),m=(r,u)=>{const s=t.hooks.slice();s[r]=u,n({...t,hooks:s})},x=r=>n({...t,hooks:t.hooks.filter((u,s)=>s!==r)});return e.jsxs("div",{className:"border border-line rounded p-3 bg-bg-elev space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-fg-faint w-16",children:"matcher"}),e.jsx("input",{value:t.matcher??"",disabled:o,onChange:r=>n({...t,matcher:r.target.value}),placeholder:"tool name regex or exact match (optional)",className:"flex-1 bg-bg border border-line rounded px-2 py-0.5 text-xs text-fg font-mono"}),e.jsx("button",{onClick:l,disabled:o,className:"text-fg-faint hover:text-red-400 text-xs disabled:opacity-40",title:"remove group",children:"× group"})]}),(t.hooks??[]).map((r,u)=>e.jsx(Ce,{rule:r,jsonInvalid:o,onChange:s=>m(u,s),onRemove:()=>x(u),onTestFire:()=>c(r)},u)),e.jsx("button",{onClick:f,disabled:o,className:"text-xs text-fg-faint hover:text-fg disabled:opacity-40",children:"+ add hook"})]})}function Ce({rule:t,jsonInvalid:o,onChange:n,onRemove:l,onTestFire:c}){const f=s=>({command:"e.g. node ./scripts/lint.js $FILE",http:"e.g. https://hooks.example.com/notify",prompt:"e.g. Review this change for security issues",agent:"e.g. security-reviewer",mcp_tool:"e.g. mcp__server__tool"})[s],m=t.type==="command"?"command":t.type==="http"?"url":t.type==="prompt"?"prompt":t.type==="mcp_tool"?"mcpTool":"agent",x=t[m]??"",r=(t.args??[]).join(" "),u={type:"hook",name:x||t.type,command:t.type==="command"?t.command:void 0,url:t.type==="http"?t.url:void 0};return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("select",{value:t.type,disabled:o,onChange:s=>n({type:s.target.value}),className:"bg-bg border border-line rounded px-1 py-0.5 text-xs text-fg",children:we.map(s=>e.jsx("option",{value:s,children:s},s))}),e.jsx(ue,{interactive:!1,input:u}),e.jsx("input",{value:x,disabled:o,onChange:s=>n({...t,[m]:s.target.value}),placeholder:f(t.type),className:`flex-1 bg-bg border rounded px-2 py-0.5 text-xs text-fg font-mono ${o?"border-red-500/70":x.trim()?"border-line":"border-yellow-600/50"}`}),o?e.jsx("span",{className:"text-red-400 text-xs",title:"The enclosing settings.json is malformed; fix the JSON before editing.",children:"× invalid"}):null,e.jsx("input",{value:t.timeout??"",disabled:o,onChange:s=>n({...t,timeout:s.target.value?Number(s.target.value):void 0}),placeholder:"timeout ms",className:"w-20 bg-bg border border-line rounded px-2 py-0.5 text-xs text-fg"}),t.type==="command"?e.jsx("button",{onClick:c,disabled:o||!x.trim(),className:"px-2 py-0.5 text-xs border border-line rounded text-fg-dim hover:text-fg hover:bg-bg-hi disabled:opacity-40 disabled:cursor-not-allowed",title:"Run this command with a fake event payload",children:"test fire"}):null,e.jsx("button",{onClick:l,disabled:o,className:"text-fg-faint hover:text-red-400 text-xs disabled:opacity-40",children:"×"})]}),t.type==="command"?e.jsxs("div",{className:"flex items-center gap-2 pl-[3.75rem]",children:[e.jsx("span",{className:"text-xs text-fg-faint w-12",children:"args"}),e.jsx("input",{value:r,disabled:o,onChange:s=>n({...t,args:s.target.value.trim()?s.target.value.split(/\s+/).filter(Boolean):void 0}),placeholder:"argv array (v2.1.139+ exec form, no shell)",className:"flex-1 bg-bg border border-line rounded px-2 py-0.5 text-xs text-fg font-mono"})]}):null,e.jsxs("div",{className:"flex items-center gap-2 pl-[3.75rem]",children:[e.jsx("span",{className:"text-xs text-fg-faint w-12",children:"term"}),e.jsx("input",{value:t.terminalSequence??"",disabled:o,onChange:s=>n({...t,terminalSequence:s.target.value||void 0}),placeholder:"terminalSequence — e.g. \\\\a (bell), v2.1.141+",className:"flex-1 bg-bg border border-line rounded px-2 py-0.5 text-xs text-fg font-mono"})]})]})}function Fe(t){return JSON.stringify(je[t]??{},null,2)}function Te(t,o){if(!t.trim())return{matched:!0,target:null,note:"empty matcher → matches all"};const n=o&&typeof o=="object"&&"tool_name"in o?String(o.tool_name??""):null;if(n==null)return{matched:!1,target:null,note:"payload has no tool_name to match against"};try{return{matched:new RegExp(`^(?:${t})$`).test(n),target:n}}catch{return{matched:t===n,target:n,note:"matcher not valid regex; fell back to exact match"}}}function Pe({event:t,matcher:o,command:n,onClose:l}){const[c,f]=d.useState(()=>Fe(t)),[m,x]=d.useState(!1),[r,u]=d.useState(null),[s,S]=d.useState(null);let g=null;try{JSON.parse(c)}catch(p){g=p.message}const v=async()=>{x(!0),u(null);let p=null;try{p=JSON.parse(c)}catch{}S(Te(o,p));try{const w=await window.api.app.testFireHook({command:n,payload:c,timeoutMs:5e3});u(w)}finally{x(!1)}};return e.jsx(de,{open:!0,onClose:l,title:`Test fire — ${t}`,children:e.jsxs("div",{className:"space-y-3 text-xs",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-fg-faint mb-1",children:"resolved command"}),e.jsx("div",{className:"font-mono text-fg bg-bg border border-line rounded px-2 py-1 break-all",children:n})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-fg-faint mb-1",children:"matcher"}),e.jsx("div",{className:"font-mono text-fg bg-bg border border-line rounded px-2 py-1",children:o||e.jsx("span",{className:"text-fg-faint",children:"(empty — matches all)"})})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("span",{className:"text-fg-faint",children:"fake event payload (stdin)"}),g?e.jsxs("span",{className:"text-red-400",children:["× ",g]}):null]}),e.jsx("textarea",{value:c,onChange:p=>f(p.target.value),rows:8,className:`w-full bg-bg border rounded px-2 py-1 font-mono text-fg ${g?"border-red-500/70":"border-line"}`})]}),s?e.jsxs("div",{children:[e.jsx("div",{className:"text-fg-faint mb-1",children:"matcher result"}),e.jsxs("div",{className:"font-mono",children:[e.jsx("span",{className:s.matched?"text-green-400":"text-red-400",children:s.matched?"✓ match":"✗ no match"}),s.target!=null?e.jsxs("span",{className:"text-fg-dim",children:[' · target tool_name="',s.target,'"']}):null,s.note?e.jsx("div",{className:"text-fg-faint",children:s.note}):null]})]}):null,r?e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"text-fg-faint",children:["exit ",r.exitCode," · ",r.durationMs,"ms"]}),r.stdout?e.jsxs("div",{children:[e.jsx("div",{className:"text-fg-faint",children:"stdout"}),e.jsx("pre",{className:"bg-bg border border-line rounded p-2 font-mono text-fg whitespace-pre-wrap break-all max-h-40 overflow-auto",children:r.stdout})]}):null,r.stderr?e.jsxs("div",{children:[e.jsx("div",{className:"text-fg-faint",children:"stderr"}),e.jsx("pre",{className:"bg-bg border border-line rounded p-2 font-mono text-red-300 whitespace-pre-wrap break-all max-h-40 overflow-auto",children:r.stderr})]}):null]}):null,e.jsxs("div",{className:"flex items-center justify-end gap-2 pt-1",children:[e.jsx("button",{onClick:l,className:"px-2 py-0.5 text-xs border border-line rounded text-fg-dim hover:text-fg hover:bg-bg-hi",children:"close"}),e.jsx("button",{onClick:v,disabled:m||!!g||!n.trim(),className:"px-2 py-0.5 text-xs border border-line rounded text-fg hover:bg-bg-hi disabled:opacity-40 disabled:cursor-not-allowed",children:m?"running…":"run"})]})]})})}export{$e as Hooks};
|