@shinobiapps/shinobi 0.1.3 → 0.1.5

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.
@@ -284,5 +284,5 @@ Error generating stack: `+i.message+`
284
284
  *
285
285
  * This source code is licensed under the ISC license.
286
286
  * See the LICENSE file in the root directory of this source tree.
287
- */const Kh=R("X",[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]]);function zd(e){var t,n,r="";if(typeof e=="string"||typeof e=="number")r+=e;else if(typeof e=="object")if(Array.isArray(e)){var l=e.length;for(t=0;t<l;t++)e[t]&&(n=zd(e[t]))&&(r&&(r+=" "),r+=n)}else for(n in e)e[n]&&(r&&(r+=" "),r+=n);return r}function _e(){for(var e,t,n=0,r="",l=arguments.length;n<l;n++)(e=arguments[n])&&(t=zd(e))&&(r&&(r+=" "),r+=t);return r}function G(e){if(!e)return"";const t=new Date(e.replace(" ","T")+(e.includes("T")||e.includes("Z")?"":"Z"));if(isNaN(t.getTime()))return e;const n=Math.max(0,(Date.now()-t.getTime())/1e3);if(n<60)return`${Math.floor(n)}s ago`;const r=n/60;if(r<60)return`${Math.floor(r)}m ago`;const l=r/60;if(l<24)return`${Math.floor(l)}h ago`;const i=l/24;if(i<30)return`${Math.floor(i)}d ago`;const a=i/30;return a<12?`${Math.floor(a)}mo ago`:`${Math.floor(a/12)}y ago`}function Yh(e){return e?e.toLowerCase().replace(/[^a-z0-9]+/g,"-"):"none"}function Gh(e){switch(Yh(e)){case"shinobi":return"bg-ws-shinobi text-white";case"shinobiapps":return"bg-ws-shinobiapps text-bg";case"sitesnap":return"bg-ws-sitesnap text-bg";default:return"bg-border-2 text-text-muted italic"}}function Na({workspace:e}){return s.jsx("span",{className:_e("inline-block rounded text-[10px] font-medium lowercase tracking-wider px-1.5 py-0.5",Gh(e)),children:e??"(no workspace)"})}const Xh={default:"bg-border-2 border-border text-text hover:bg-border",primary:"bg-accent-2 border-accent-2 text-white hover:bg-accent-3",ghost:"bg-transparent border-transparent text-text-muted hover:text-text hover:bg-panel",danger:"bg-danger border-danger text-white hover:opacity-90"},Jh={sm:"text-xs px-2 py-1",md:"text-sm px-3 py-1.5"},z=g.forwardRef(({variant:e="default",size:t="md",className:n,...r},l)=>s.jsx("button",{ref:l,className:_e("border rounded transition-colors font-medium cursor-pointer disabled:opacity-50 disabled:cursor-wait",Xh[e],Jh[t],n),...r}));z.displayName="Button";async function $(e,t){const n=await fetch(e,{...t,headers:{"Content-Type":"application/json",...(t==null?void 0:t.headers)??{}}});if(!n.ok){const r=await n.text();throw new Error(`${(t==null?void 0:t.method)??"GET"} ${e} → ${n.status}: ${r.slice(0,200)}`)}return await n.json()}function Id(e){const t=new URLSearchParams;e!=null&&e.sort&&t.set("sort",e.sort),e!=null&&e.include_archived&&t.set("include_archived","true");const n=t.toString();return $(`/api/projects${n?`?${n}`:""}`)}function qh(e){return $(`/api/projects/${e}/snapshot`)}function Zh(e,t=8){const n=new URLSearchParams({q:e,limit:String(t)});return $(`/api/recall?${n.toString()}`)}function ex(e,t){return $(`/api/subtasks/${e}`,{method:"PATCH",body:JSON.stringify(t)})}function tx(e,t){return $(`/api/decisions/${e}/status`,{method:"PATCH",body:JSON.stringify({status:t})})}function nx(e){return $(`/api/projects/${e}/decision-drafts`)}function rx(e){return $(`/api/decision-drafts/${e}/approve`,{method:"POST",body:"{}"})}function sx(e){return $(`/api/decision-drafts/${e}/reject`,{method:"POST",body:"{}"})}function lx(e=200){return $(`/api/sessions?limit=${e}`)}function ix(e){return $(`/api/sessions/${encodeURIComponent(e)}`)}function ax(){return $("/api/settings")}function ox(e){return $("/api/settings",{method:"POST",body:JSON.stringify({patch:e})})}function ux(){return $("/api/push/vapid-key")}function cx(){return $("/api/push/subscriptions")}function dx(e){return $("/api/push/subscribe",{method:"POST",body:JSON.stringify(e)})}function Qo(e){return $(`/api/push/subscriptions/${e}`,{method:"DELETE"})}function fx(){return $("/api/push/test",{method:"POST"})}function px(e){return $("/api/approvals")}function mx(e,t,n){return $(`/api/approvals/${e}/respond`,{method:"POST",body:JSON.stringify({value:t,note:n})})}function hx(e){return $(`/api/approvals/${e}/cancel`,{method:"POST",body:"{}"})}function xx(){return $("/api/sync/status")}function vx(){return $("/api/sync/push",{method:"POST"})}function gx(){return $("/api/sync/pull",{method:"POST"})}function Ko(e){return $(`/api/projects/${e}/time-stats`)}function Yo(e){return $(`/api/projects/${e}/cost-stats`)}function yx(e={}){return $("/api/cost/ingest",{method:"POST",body:JSON.stringify(e)})}function jx(){return $("/api/plugins")}function wx(e){return $("/api/plugins/search",{method:"POST",body:JSON.stringify({query:e})})}function kx(e){return $("/api/plugins/install",{method:"POST",body:JSON.stringify({pkg:e})})}function Nx(e){return $(`/api/plugins/${encodeURIComponent(e)}`,{method:"DELETE"})}function Sx(){return $("/api/telemetry/summary")}function bx(){return $("/api/telemetry/flush",{method:"POST",body:"{}"})}function _x(){return $("/api/relay/status")}function Ex(){return $("/api/relay/broadcast-sync",{method:"POST",body:"{}"})}function Cx(){const[e,t]=g.useState(null),[n,r]=g.useState({kind:"idle"});g.useEffect(()=>{l()},[]);async function l(){try{t(await xx())}catch(o){r({kind:"err",message:o instanceof Error?o.message:String(o)})}}async function i(o){if(!(o==="pull"&&!window.confirm("Pull overwrites the local DB with the latest snapshot from the sync repo. Continue?"))){r({kind:"busy",op:o});try{const u=o==="push"?await vx():await gx();if(!u.ok)throw new Error(u.error??"unknown error");r({kind:"ok",op:o,elapsedMs:u.elapsed_ms??0}),await l(),o==="pull"&&setTimeout(()=>location.reload(),500)}catch(u){r({kind:"err",message:u instanceof Error?u.message:String(u)})}}}const a=e==null?void 0:e.sync;return s.jsxs("div",{className:"bg-panel border border-border rounded-md p-3 mt-4",children:[s.jsx("div",{className:"text-[11px] uppercase tracking-wider text-text-muted mb-2",children:"Sync"}),s.jsxs("div",{className:"space-y-1 text-xs font-mono",children:[e!=null&&e.configured&&a?s.jsxs(s.Fragment,{children:[s.jsxs("div",{children:["push: ",s.jsx("span",{className:a.last_push_at?"text-success":"text-text-muted",children:G(a.last_push_at)||"never"})]}),s.jsxs("div",{children:["pull: ",s.jsx("span",{className:a.last_pull_at?"text-success":"text-text-muted",children:G(a.last_pull_at)||"never"})]}),s.jsxs("div",{className:"text-text-dim text-[10px] break-all",children:[a.repo_path,s.jsx("br",{}),"(branch: ",a.branch,")"]})]}):s.jsx("div",{className:"text-text-muted",children:"not configured"}),n.kind==="ok"&&s.jsxs("div",{className:"text-success",children:[n.op," OK (",n.elapsedMs,"ms)"]}),n.kind==="err"&&s.jsx("div",{className:"text-danger break-all",children:n.message})]}),s.jsxs("div",{className:"flex gap-1.5 mt-3",children:[s.jsxs(z,{size:"sm",variant:"default",className:"flex-1 flex items-center justify-center gap-1",disabled:n.kind==="busy",onClick:()=>void i("pull"),children:[n.kind==="busy"&&n.op==="pull"?s.jsx(Yt,{className:"w-3 h-3 animate-spin"}):s.jsx(Nh,{className:"w-3 h-3"}),"Pull"]}),s.jsxs(z,{size:"sm",variant:"primary",className:"flex-1 flex items-center justify-center gap-1",disabled:n.kind==="busy",onClick:()=>void i("push"),children:[n.kind==="busy"&&n.op==="push"?s.jsx(Yt,{className:"w-3 h-3 animate-spin"}):s.jsx(Sh,{className:"w-3 h-3"}),"Push"]})]})]})}function Go({projects:e}){const t=Jt(),n=ya(),r=n.id?Number(n.id):null,l=e.filter(p=>!p.archived_at),i=e.filter(p=>p.archived_at),a=new Map;for(const p of l){const d=p.workspace??"(no workspace)";a.has(d)||a.set(d,[]),a.get(d).push(p)}const[o,u]=g.useState(!1);g.useEffect(()=>{u(/Mac|iPhone|iPad/.test(navigator.platform??navigator.userAgent))},[]);const f=o?"⌘":"Ctrl";return s.jsxs("aside",{className:"bg-panel-2 border-r border-border w-64 flex-shrink-0 overflow-y-auto scrollbar-thin p-4",children:[s.jsx(X,{to:"/",className:"block text-lg font-bold tracking-wider mb-4 text-text",children:"Shinobi 🥷"}),s.jsxs("button",{onClick:()=>window.dispatchEvent(new CustomEvent("cmd-palette:open")),className:"w-full flex items-center gap-2 px-2 py-1.5 mb-4 rounded text-sm bg-panel border border-border text-text-muted hover:text-text hover:border-accent/60 transition-colors",children:[s.jsx(wa,{className:"w-3.5 h-3.5"}),s.jsx("span",{className:"flex-1 text-left",children:"Search..."}),s.jsxs("kbd",{className:"text-[10px] border border-border rounded px-1 py-0.5",children:[f," K"]})]}),s.jsx("div",{className:"text-[11px] uppercase tracking-wider text-text-muted mb-2",children:"Workspace"}),s.jsxs("ul",{className:"mb-4",children:[s.jsx("li",{children:s.jsx(X,{to:"/sessions",className:_e("block px-2 py-1.5 rounded text-sm transition-colors",t.pathname==="/sessions"?"bg-border text-text":"text-text hover:bg-panel"),children:"All sessions"})}),s.jsx("li",{children:s.jsxs(X,{to:"/voice",className:_e("flex items-center gap-2 px-2 py-1.5 rounded text-sm transition-colors",t.pathname==="/voice"?"bg-border text-text":"text-text hover:bg-panel"),children:[s.jsx(Ni,{className:"w-3.5 h-3.5"})," Voice capture"]})}),s.jsx("li",{children:s.jsxs(X,{to:"/approvals",className:_e("flex items-center gap-2 px-2 py-1.5 rounded text-sm transition-colors",t.pathname==="/approvals"?"bg-border text-text":"text-text hover:bg-panel"),children:[s.jsx(Ah,{className:"w-3.5 h-3.5"})," Approvals"]})}),s.jsx("li",{children:s.jsxs(X,{to:"/push",className:_e("flex items-center gap-2 px-2 py-1.5 rounded text-sm transition-colors",t.pathname==="/push"?"bg-border text-text":"text-text hover:bg-panel"),children:[s.jsx(ki,{className:"w-3.5 h-3.5"})," Push"]})}),s.jsx("li",{children:s.jsxs(X,{to:"/relay",className:_e("flex items-center gap-2 px-2 py-1.5 rounded text-sm transition-colors",t.pathname==="/relay"?"bg-border text-text":"text-text hover:bg-panel"),children:[s.jsx(Od,{className:"w-3.5 h-3.5"})," Relay"]})}),s.jsx("li",{children:s.jsxs(X,{to:"/plugins",className:_e("flex items-center gap-2 px-2 py-1.5 rounded text-sm transition-colors",t.pathname==="/plugins"?"bg-border text-text":"text-text hover:bg-panel"),children:[s.jsx(Rd,{className:"w-3.5 h-3.5"})," Plugins"]})}),s.jsx("li",{children:s.jsxs(X,{to:"/telemetry",className:_e("flex items-center gap-2 px-2 py-1.5 rounded text-sm transition-colors",t.pathname==="/telemetry"?"bg-border text-text":"text-text hover:bg-panel"),children:[s.jsx(Ld,{className:"w-3.5 h-3.5"})," Telemetry"]})}),s.jsx("li",{children:s.jsxs(X,{to:"/settings",className:_e("flex items-center gap-2 px-2 py-1.5 rounded text-sm transition-colors",t.pathname==="/settings"?"bg-border text-text":"text-text hover:bg-panel"),children:[s.jsx(Dh,{className:"w-3.5 h-3.5"})," Settings"]})})]}),s.jsx("div",{className:"text-[11px] uppercase tracking-wider text-text-muted mb-2",children:"Projects"}),a.size===0?s.jsx("div",{className:"text-text-muted text-sm italic",children:"(none)"}):[...a.entries()].map(([p,d])=>s.jsxs("div",{className:"mb-3",children:[s.jsxs("div",{className:"flex items-center gap-1.5 mt-3 mb-1 text-[10px] uppercase tracking-wider text-text-muted",children:[s.jsx(Na,{workspace:p==="(no workspace)"?null:p}),s.jsx("span",{children:d.length})]}),s.jsx("ul",{children:d.map(x=>s.jsx("li",{children:s.jsx(X,{to:`/projects/${x.id}`,className:_e("block px-2 py-1.5 rounded text-sm transition-colors",r===x.id?"bg-border text-text":"text-text hover:bg-panel"),children:x.title})},x.id))})]},p)),i.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"text-[11px] uppercase tracking-wider text-text-muted mt-4 mb-2 flex items-center gap-1.5",children:[s.jsx(Md,{className:"w-3 h-3"}),"Archived"]}),s.jsx("ul",{children:i.map(p=>s.jsx("li",{children:s.jsx(X,{to:`/projects/${p.id}`,className:"block px-2 py-1.5 rounded text-sm text-text-dim hover:bg-panel",children:p.title})},p.id))})]}),s.jsx(Cx,{})]})}const Px={project:{label:"Projects",icon:Lh},subtask:{label:"Tasks",icon:Rh},decision:{label:"Decisions",icon:Mh},dead_end:{label:"Dead ends",icon:Bh},note:{label:"Notes",icon:Th}};function Tx(e){const t=[];for(const n of e.projects)t.push({kind:"project",id:n.id,title:n.title,subtitle:n.workspace?`workspace: ${n.workspace}`:"no workspace",projectId:n.id,href:`/projects/${n.id}`});for(const n of e.subtasks)t.push({kind:"subtask",id:n.id,title:n.title,subtitle:`task #${n.id} · status: ${n.status}`,projectId:n.project_id,href:`/projects/${n.project_id}`});for(const n of e.decisions)t.push({kind:"decision",id:n.id,title:n.summary,subtitle:`decision #${n.id} · ${n.kind}`,projectId:n.project_id,href:`/projects/${n.project_id}/decisions`});for(const n of e.dead_ends)t.push({kind:"dead_end",id:n.id,title:n.attempted_approach.slice(0,100),subtitle:`dead end #${n.id}${n.never_retry?" · never retry":""}`,projectId:n.project_id,href:`/projects/${n.project_id}/dead-ends`});for(const n of e.notes)t.push({kind:"note",id:n.id,title:n.body.slice(0,100),subtitle:`note #${n.id}`,projectId:n.project_id,href:`/projects/${n.project_id}/notes`});return t}function Lx({open:e,onClose:t}){const n=Nd(),[r,l]=g.useState(""),[i,a]=g.useState(null),[o,u]=g.useState(!1),[f,p]=g.useState(0),d=g.useRef(null),x=g.useRef(null);g.useEffect(()=>{e&&(l(""),a(null),p(0),setTimeout(()=>{var j;return(j=d.current)==null?void 0:j.focus()},0))},[e]),g.useEffect(()=>{if(!e)return;const j=r.trim();if(j.length<2){a(null),u(!1);return}u(!0);const y=setTimeout(()=>{Zh(j,6).then(m=>{a(m),p(0)}).catch(()=>a(null)).finally(()=>u(!1))},150);return()=>clearTimeout(y)},[r,e]);const w=g.useMemo(()=>i?Tx(i):[],[i]);if(g.useEffect(()=>{if(!e)return;function j(y){if(y.key==="Escape")y.preventDefault(),t();else if(y.key==="ArrowDown")y.preventDefault(),p(m=>Math.min(m+1,w.length-1));else if(y.key==="ArrowUp")y.preventDefault(),p(m=>Math.max(m-1,0));else if(y.key==="Enter"){const m=w[f];m&&(y.preventDefault(),n(m.href),t())}}return window.addEventListener("keydown",j),()=>window.removeEventListener("keydown",j)},[e,w,f,n,t]),g.useEffect(()=>{var y;const j=(y=x.current)==null?void 0:y.querySelector(`[data-cmd-idx="${f}"]`);j==null||j.scrollIntoView({block:"nearest"})},[f]),!e)return null;const v=["project","subtask","decision","dead_end","note"].map(j=>({kind:j,items:w.filter(y=>y.kind===j)})).filter(j=>j.items.length>0);return pd.createPortal(s.jsxs("div",{className:"fixed inset-0 z-[100] flex items-start justify-center pt-20 px-4",onClick:t,children:[s.jsx("div",{className:"fixed inset-0 bg-black/60 backdrop-blur-sm","aria-hidden":!0}),s.jsxs("div",{className:"relative w-full max-w-2xl bg-panel border border-border rounded-lg shadow-2xl overflow-hidden",onClick:j=>j.stopPropagation(),children:[s.jsxs("div",{className:"flex items-center gap-3 px-4 py-3 border-b border-border",children:[s.jsx(wa,{className:"w-4 h-4 text-text-muted"}),s.jsx("input",{ref:d,type:"text",value:r,onChange:j=>l(j.target.value),placeholder:"Search projects, tasks, decisions, dead ends, notes...",className:"flex-1 bg-transparent text-text placeholder:text-text-dim outline-none text-sm"}),s.jsx("kbd",{className:"text-[10px] text-text-dim border border-border rounded px-1.5 py-0.5",children:"esc"})]}),s.jsx("div",{ref:x,className:"max-h-[60vh] overflow-y-auto",children:r.trim().length<2?s.jsx("div",{className:"px-4 py-6 text-center text-text-dim text-sm",children:"Type at least 2 characters to search."}):o&&w.length===0?s.jsx("div",{className:"px-4 py-6 text-center text-text-muted text-sm",children:"Searching..."}):w.length===0?s.jsxs("div",{className:"px-4 py-6 text-center text-text-muted text-sm",children:['No matches for "',r,'".']}):v.map(j=>{const y=Px[j.kind],m=y.icon;return s.jsxs("div",{className:"py-1",children:[s.jsxs("div",{className:"px-4 py-1.5 text-[10px] uppercase tracking-wider text-text-dim flex items-center gap-1.5",children:[s.jsx(m,{className:"w-3 h-3"}),y.label,s.jsxs("span",{className:"text-text-dim",children:["· ",j.items.length]})]}),j.items.map(c=>{const h=w.indexOf(c),k=h===f;return s.jsxs("button",{"data-cmd-idx":h,onMouseEnter:()=>p(h),onClick:()=>{n(c.href),t()},className:`w-full text-left px-4 py-2 flex flex-col gap-0.5 border-l-2 ${k?"bg-panel-2 border-accent":"border-transparent hover:bg-panel-2/60"}`,children:[s.jsx("span",{className:"text-sm text-text truncate",children:c.title}),s.jsx("span",{className:"text-[11px] text-text-muted truncate",children:c.subtitle})]},`${c.kind}-${c.id}`)})]},j.kind)})}),s.jsxs("div",{className:"px-4 py-2 border-t border-border text-[10px] text-text-dim flex items-center justify-between",children:[s.jsxs("span",{className:"flex items-center gap-3",children:[s.jsxs("span",{children:[s.jsx("kbd",{className:"border border-border rounded px-1 py-0.5",children:"↑"})," ",s.jsx("kbd",{className:"border border-border rounded px-1 py-0.5",children:"↓"})," navigate"]}),s.jsxs("span",{children:[s.jsx("kbd",{className:"border border-border rounded px-1 py-0.5",children:"↵"})," open"]}),s.jsxs("span",{children:[s.jsx("kbd",{className:"border border-border rounded px-1 py-0.5",children:"esc"})," close"]})]}),i&&s.jsxs("span",{children:[w.length," ",w.length===1?"result":"results"]})]})]})]}),document.body)}function Mx(){const[e,t]=g.useState(null),[n,r]=g.useState(null),[l,i]=g.useState(!1),[a,o]=g.useState(!1),u=Jt();return g.useEffect(()=>{i(!1)},[u.pathname]),g.useEffect(()=>{function f(d){(d.metaKey||d.ctrlKey)&&d.key.toLowerCase()==="k"&&(d.preventDefault(),o(w=>!w))}function p(){o(!0)}return window.addEventListener("keydown",f),window.addEventListener("cmd-palette:open",p),()=>{window.removeEventListener("keydown",f),window.removeEventListener("cmd-palette:open",p)}},[]),g.useEffect(()=>{let f=!1;return Id({sort:"active",include_archived:!0}).then(p=>{f||t(p)}).catch(p=>{f||r(p instanceof Error?p.message:String(p))}),()=>{f=!0}},[]),n?s.jsx("div",{className:"min-h-screen flex items-center justify-center text-danger",children:s.jsxs("div",{children:[s.jsx("h1",{className:"text-xl mb-2",children:"Failed to load projects"}),s.jsx("pre",{className:"text-sm",children:n})]})}):e?s.jsxs("div",{className:"min-h-screen flex",children:[s.jsx("div",{className:"hidden md:block",children:s.jsx(Go,{projects:e})}),l&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"md:hidden fixed inset-0 bg-black/50 z-40",onClick:()=>i(!1)}),s.jsx("div",{className:"md:hidden fixed inset-y-0 left-0 z-50 shadow-2xl",children:s.jsx(Go,{projects:e})})]}),s.jsxs("main",{className:"flex-1 overflow-y-auto min-w-0",children:[s.jsxs("div",{className:"md:hidden sticky top-0 z-30 bg-bg/95 backdrop-blur border-b border-border px-4 py-3 flex items-center gap-3",children:[s.jsx("button",{onClick:()=>i(f=>!f),className:"text-text hover:text-accent","aria-label":l?"Close menu":"Open menu",children:l?s.jsx(Kh,{className:"w-5 h-5"}):s.jsx(Oh,{className:"w-5 h-5"})}),s.jsx("span",{className:"text-text font-semibold tracking-wider",children:"Shinobi 🥷"})]}),s.jsx("div",{className:"p-4 md:p-8",children:s.jsx(Cd,{context:{projects:e}})})]}),s.jsx(Lx,{open:a,onClose:()=>o(!1)})]}):s.jsx("div",{className:"min-h-screen flex items-center justify-center text-text-muted",children:"loading..."})}const Rx={default:"bg-border-2 text-text","status-todo":"bg-border text-text","status-in_progress":"bg-accent-2 text-white","status-done":"bg-text-dim text-text","priority-urgent":"bg-danger text-white","priority-high":"bg-orange text-bg","priority-medium":"bg-warning text-bg","priority-low":"bg-text-dim text-text-muted"};function le({children:e,variant:t="default",className:n}){return s.jsx("span",{className:_e("inline-block rounded text-[10px] font-medium uppercase tracking-wider px-1.5 py-0.5",Rx[t],n),children:e})}function Gs({priority:e}){return s.jsx(le,{variant:`priority-${e}`,children:e})}function Sa({status:e}){return s.jsx(le,{variant:`status-${e}`,children:e})}const Xo="shinobi.home.workspaceFilter",Zt="__all__",Jo="__none__";function qo({rows:e,dim:t=!1}){return s.jsx("div",{className:"overflow-x-auto",children:s.jsxs("table",{className:"w-full text-sm",children:[s.jsx("thead",{children:s.jsxs("tr",{className:"text-[11px] uppercase tracking-wider text-text-muted text-left",children:[s.jsx("th",{className:"font-medium pb-2 pr-3",children:"Workspace"}),s.jsx("th",{className:"font-medium pb-2 pr-3",children:"Title"}),s.jsx("th",{className:"font-medium pb-2 pr-3",children:"Status"}),s.jsx("th",{className:"font-medium pb-2 pr-3",children:"Priority"}),s.jsx("th",{className:"font-medium pb-2 pr-3",children:"Type"}),s.jsx("th",{className:"font-medium pb-2 pr-3",children:"Target path"}),s.jsx("th",{className:"font-medium pb-2 pr-3",children:"Due"}),s.jsx("th",{className:"font-medium pb-2",children:"Created"})]})}),s.jsx("tbody",{className:t?"opacity-60":"",children:e.map(n=>s.jsxs("tr",{className:"border-b border-border/40 hover:bg-panel/40",children:[s.jsx("td",{className:"py-2 pr-3",children:s.jsx(Na,{workspace:n.workspace})}),s.jsx("td",{className:"py-2 pr-3",children:s.jsx(X,{to:`/projects/${n.id}`,className:"text-text hover:text-accent font-medium",children:n.title})}),s.jsx("td",{className:"py-2 pr-3",children:s.jsx(Sa,{status:n.status})}),s.jsx("td",{className:"py-2 pr-3",children:s.jsx(Gs,{priority:n.priority})}),s.jsx("td",{className:"py-2 pr-3 text-text-muted",children:n.project_type??""}),s.jsx("td",{className:"py-2 pr-3 text-text-muted font-mono text-xs",children:n.target_path??""}),s.jsx("td",{className:"py-2 pr-3 text-text-muted",children:n.due_date??""}),s.jsx("td",{className:"py-2 text-text-muted text-xs",title:n.created_at,children:G(n.created_at)})]},n.id))})]})})}function Ox(){const{projects:e}=Fe(),[t,n]=g.useState(!1),[r,l]=g.useState(()=>typeof window>"u"?Zt:window.localStorage.getItem(Xo)??Zt),i=g.useMemo(()=>{const d=new Set;let x=!1;for(const v of e)v.workspace?d.add(v.workspace):x=!0;return{named:Array.from(d).sort((v,j)=>v.localeCompare(j)),hasNoWorkspace:x}},[e]);function a(d){return r===Zt?d:r===Jo?d.filter(x=>!x.workspace):d.filter(x=>x.workspace===r)}const o=a(e.filter(d=>!d.archived_at)),u=a(e.filter(d=>d.archived_at));function f(d){l(d),typeof window<"u"&&window.localStorage.setItem(Xo,d)}const p=i.named.length>1||i.named.length>=1&&i.hasNoWorkspace;return s.jsxs("div",{children:[s.jsxs("header",{className:"flex items-baseline justify-between border-b border-border pb-3 mb-6",children:[s.jsx("h1",{className:"text-2xl text-text",children:"Projects"}),s.jsxs("span",{className:"text-text-muted text-xs",children:[o.length," active · ",u.length," archived"]})]}),p&&s.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[s.jsx("label",{htmlFor:"workspace-filter",className:"text-[11px] uppercase tracking-wider text-text-muted",children:"Workspace"}),s.jsxs("select",{id:"workspace-filter",value:r,onChange:d=>f(d.target.value),className:"bg-panel border border-border rounded px-2 py-1 text-sm text-text hover:border-accent/60 focus:outline-none focus:border-accent",children:[s.jsx("option",{value:Zt,children:"All workspaces"}),i.named.map(d=>s.jsx("option",{value:d,children:d},d)),i.hasNoWorkspace&&s.jsx("option",{value:Jo,children:"(no workspace)"})]}),r!==Zt&&s.jsx("button",{onClick:()=>f(Zt),className:"text-xs text-text-muted hover:text-text",children:"clear"})]}),e.length===0?s.jsxs("div",{className:"bg-panel border border-dashed border-border rounded p-6 text-center text-text-muted",children:["No projects yet. Create one via the ",s.jsx("code",{children:"create_project"})," MCP tool, then refresh."]}):o.length===0?s.jsx("div",{className:"bg-panel border border-dashed border-border rounded p-6 text-center text-text-muted",children:"No active projects match this workspace filter."}):s.jsx(qo,{rows:o}),u.length>0&&s.jsxs("section",{className:"mt-8",children:[s.jsxs("button",{onClick:()=>n(d=>!d),className:"flex items-center gap-1.5 text-[11px] uppercase tracking-wider text-text-muted hover:text-text mb-3",children:[t?s.jsx(_h,{className:"w-3.5 h-3.5"}):s.jsx(Eh,{className:"w-3.5 h-3.5"}),s.jsx(Md,{className:"w-3.5 h-3.5"}),"Archived (",u.length,")"]}),t&&s.jsx(qo,{rows:u,dim:!0})]})]})}function zx({projectId:e,draftPendingCount:t}){const n=`/projects/${e}`,r=[{to:n,label:"Kanban",end:!0},{to:`${n}/subtasks`,label:"Subtasks"},{to:`${n}/decisions`,label:"Decisions"},{to:`${n}/decision-drafts`,label:"Drafts",badge:t&&t>0?s.jsx("span",{className:"ml-1 inline-block bg-warning text-bg text-[9px] font-bold px-1.5 py-0.5 rounded-full",children:t}):null},{to:`${n}/dead-ends`,label:"Dead Ends"},{to:`${n}/notes`,label:"Notes"},{to:`${n}/plans`,label:"Plans"},{to:`${n}/context`,label:"Context"},{to:`${n}/sessions`,label:"Sessions"},{to:`${n}/timeline`,label:"Timeline"},{to:`${n}/analytics`,label:"Analytics"}];return s.jsx("nav",{className:"flex gap-1 mb-4 border-b border-border overflow-x-auto scrollbar-thin",children:r.map(l=>s.jsxs(xh,{to:l.to,end:l.end,className:({isActive:i})=>_e("px-3.5 py-2 text-sm -mb-px border-b-2 whitespace-nowrap transition-colors flex items-center",i?"text-text border-accent":"text-text-muted border-transparent hover:text-text hover:border-border-2"),children:[l.label,l.badge]},l.to))})}function Ix(){const e=ya(),t=Number(e.id),[n,r]=g.useState(null),[l,i]=g.useState(null),a=g.useCallback(async()=>{try{const u=await qh(t);r(u)}catch(u){i(u instanceof Error?u.message:String(u))}},[t]);if(g.useEffect(()=>{Number.isFinite(t)&&(r(null),i(null),a())},[t,a]),l)return s.jsxs("div",{className:"text-danger",children:["Error: ",l]});if(!n)return s.jsx("div",{className:"text-text-muted",children:"loading..."});const{project:o}=n;return s.jsxs("div",{children:[s.jsxs("header",{className:"border-b border-border pb-3 mb-4",children:[s.jsx("h1",{className:"text-2xl text-text",children:o.title}),s.jsxs("div",{className:"mt-2 text-xs text-text-muted flex items-center gap-2 flex-wrap",children:[s.jsx(Na,{workspace:o.workspace}),s.jsx("span",{children:"·"}),s.jsx(Sa,{status:o.status}),s.jsx("span",{children:"·"}),s.jsx(Gs,{priority:o.priority}),o.due_date&&s.jsxs(s.Fragment,{children:[s.jsx("span",{children:"·"}),s.jsxs("span",{children:["due ",o.due_date]})]}),o.target_path&&s.jsxs(s.Fragment,{children:[s.jsx("span",{children:"·"}),s.jsxs("span",{className:"font-mono",children:["target ",o.target_path]})]}),o.recent_summary_at&&s.jsxs(s.Fragment,{children:[s.jsx("span",{children:"·"}),s.jsxs("span",{children:["summary ",G(o.recent_summary_at)]})]})]})]}),s.jsx(zx,{projectId:t,draftPendingCount:n.draft_counts.pending}),s.jsx(Cd,{context:{snapshot:n,refresh:a}})]})}const $x=[{key:"todo",label:"Todo"},{key:"in_progress",label:"In Progress"},{key:"done",label:"Done"}];function Dx(){const{snapshot:e,refresh:t}=Fe(),{project:n,subtasks:r}=e,l={todo:[],in_progress:[],done:[]};for(const a of r)l[a.status].push(a);async function i(a,o){try{await ex(a,{status:o}),await t()}catch(u){alert("Transition failed: "+(u instanceof Error?u.message:String(u)))}}return s.jsxs(s.Fragment,{children:[n.description&&s.jsx("pre",{className:"bg-panel border border-border rounded p-3 mb-6 whitespace-pre-wrap text-xs font-mono text-text",children:n.description}),n.recent_summary_md&&s.jsxs("div",{className:"bg-panel border border-border border-l-4 border-l-accent rounded-md p-4 mb-6",children:[s.jsxs("div",{className:"text-[11px] uppercase tracking-wider text-text-muted mb-2",children:["Recent session summary",n.recent_summary_provider&&s.jsxs("span",{className:"text-text-dim normal-case ml-2 tracking-normal",children:["via ",n.recent_summary_provider]})]}),s.jsx("div",{className:"text-sm text-text whitespace-pre-wrap leading-relaxed",children:n.recent_summary_md})]}),s.jsx("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:$x.map(a=>s.jsxs("div",{className:"bg-panel border border-border rounded-md p-3 min-h-[200px]",children:[s.jsxs("h3",{className:"text-[11px] uppercase tracking-wider text-text-muted mb-3",children:[a.label," (",l[a.key].length,")"]}),s.jsx("div",{className:"space-y-2",children:l[a.key].length===0?s.jsx("div",{className:"text-text-dim text-xs",children:"(empty)"}):l[a.key].map(o=>s.jsxs("div",{className:"bg-panel-2 border border-border rounded p-2.5 text-xs",children:[s.jsx("div",{className:"text-text font-medium mb-1",children:o.title}),s.jsxs("div",{className:"text-text-muted flex flex-wrap gap-2 items-center text-[11px]",children:[s.jsx(Gs,{priority:o.priority}),o.due_date&&s.jsxs("span",{children:["due ",o.due_date]}),o.depends_on&&o.depends_on.length>0&&s.jsxs("span",{children:["deps: ",o.depends_on.join(",")]}),o.claude_session_id&&s.jsx("span",{title:o.claude_session_id,children:"session"})]}),s.jsxs("div",{className:"flex gap-1.5 mt-2",children:[o.status!=="todo"&&s.jsxs(z,{size:"sm",variant:"ghost",onClick:()=>void i(o.id,"todo"),className:"flex items-center gap-1",children:[s.jsx(Vh,{className:"w-3 h-3"})," todo"]}),o.status!=="in_progress"&&s.jsxs(z,{size:"sm",variant:"ghost",onClick:()=>void i(o.id,"in_progress"),className:"flex items-center gap-1",children:[s.jsx(zh,{className:"w-3 h-3"})," in progress"]}),o.status!=="done"&&s.jsxs(z,{size:"sm",variant:"ghost",onClick:()=>void i(o.id,"done"),className:"flex items-center gap-1",children:[s.jsx(bh,{className:"w-3 h-3"})," done"]})]})]},o.id))})]},a.key))})]})}function Fx(){const{snapshot:e}=Fe(),{subtasks:t}=e;return t.length===0?s.jsxs("div",{className:"bg-panel border border-dashed border-border rounded p-6 text-center text-text-muted",children:["No subtasks. Use ",s.jsx("code",{children:"create_task"})," or ",s.jsx("code",{children:"bulk_create_tasks"})," to seed."]}):s.jsx("div",{className:"overflow-x-auto",children:s.jsxs("table",{className:"w-full text-sm",children:[s.jsx("thead",{children:s.jsxs("tr",{className:"text-[11px] uppercase tracking-wider text-text-muted text-left",children:[s.jsx("th",{className:"font-medium pb-2 pr-3 w-12",children:"ID"}),s.jsx("th",{className:"font-medium pb-2 pr-3",children:"Title"}),s.jsx("th",{className:"font-medium pb-2 pr-3 w-28",children:"Status"}),s.jsx("th",{className:"font-medium pb-2 pr-3 w-24",children:"Priority"}),s.jsx("th",{className:"font-medium pb-2 pr-3 w-24",children:"Deps"}),s.jsx("th",{className:"font-medium pb-2 pr-3 w-24",children:"Due"}),s.jsx("th",{className:"font-medium pb-2 w-28",children:"Claimed"})]})}),s.jsx("tbody",{children:t.map(n=>s.jsxs("tr",{className:"border-b border-border/40 hover:bg-panel/40 align-top",children:[s.jsx("td",{className:"py-2 pr-3 text-text-muted font-mono",children:n.id}),s.jsxs("td",{className:"py-2 pr-3",children:[s.jsx("div",{className:"text-text font-medium",children:n.title}),n.description&&s.jsx("div",{className:"text-text-muted text-xs mt-1",children:n.description.length>200?n.description.slice(0,200)+"…":n.description})]}),s.jsx("td",{className:"py-2 pr-3",children:s.jsx(Sa,{status:n.status})}),s.jsx("td",{className:"py-2 pr-3",children:s.jsx(Gs,{priority:n.priority})}),s.jsx("td",{className:"py-2 pr-3 text-text-muted text-xs",children:n.depends_on&&n.depends_on.length>0?n.depends_on.join(", "):""}),s.jsx("td",{className:"py-2 pr-3 text-text-muted",children:n.due_date??""}),s.jsx("td",{className:"py-2 text-text-muted text-xs",title:n.last_claimed_at??"",children:G(n.last_claimed_at)})]},n.id))})]})})}const Ax=["open","fix_now","fix_later","wontfix","fixed","false_positive"];function Ux(e){switch(e){case"open":return"bg-accent-2 text-white";case"fix_now":return"bg-danger text-white";case"fix_later":return"bg-orange text-bg";case"wontfix":return"bg-text-dim text-text";case"fixed":return"bg-success text-bg";case"false_positive":return"bg-text-dim text-text";default:return"bg-border-2 text-text"}}function Bx(){const{snapshot:e,refresh:t}=Fe(),{decisions:n,draft_counts:r,project:l}=e;async function i(o,u){try{await tx(o,u),await t()}catch(f){alert("Transition failed: "+(f instanceof Error?f.message:String(f)))}}const a=r.pending>0?s.jsxs("div",{className:"bg-panel border-l-4 border-l-warning rounded-md p-3 mb-4 flex items-center justify-between",children:[s.jsxs("span",{className:"text-sm",children:[s.jsxs("strong",{children:[r.pending," pending decision draft",r.pending>1?"s":""]})," ",s.jsx("span",{className:"text-text-muted",children:"extracted via LLM"})]}),s.jsx(X,{to:`/projects/${l.id}/decision-drafts`,className:"text-accent text-sm hover:underline",children:"Review →"})]}):null;return n.length===0?s.jsxs("div",{children:[a,s.jsxs("div",{className:"bg-panel border border-dashed border-border rounded p-6 text-center text-text-muted",children:["No decisions logged. Use ",s.jsx("code",{children:"log_decision"})," via MCP."]})]}):s.jsxs("div",{children:[a,s.jsx("div",{className:"overflow-x-auto",children:s.jsxs("table",{className:"w-full text-sm",children:[s.jsx("thead",{children:s.jsxs("tr",{className:"text-[11px] uppercase tracking-wider text-text-muted text-left",children:[s.jsx("th",{className:"font-medium pb-2 pr-3 w-12",children:"ID"}),s.jsx("th",{className:"font-medium pb-2 pr-3 w-24",children:"Kind"}),s.jsx("th",{className:"font-medium pb-2 pr-3",children:"Summary + Rationale"}),s.jsx("th",{className:"font-medium pb-2 pr-3 w-44",children:"Status"}),s.jsx("th",{className:"font-medium pb-2 pr-3 w-40",children:"Files"}),s.jsx("th",{className:"font-medium pb-2 pr-3 w-32",children:"Tags"}),s.jsx("th",{className:"font-medium pb-2 w-24",children:"Logged"})]})}),s.jsx("tbody",{children:n.map(o=>s.jsxs("tr",{className:"border-b border-border/40 hover:bg-panel/40 align-top",children:[s.jsx("td",{className:"py-3 pr-3 text-text-muted font-mono",children:o.id}),s.jsx("td",{className:"py-3 pr-3",children:s.jsx(le,{children:o.kind})}),s.jsxs("td",{className:"py-3 pr-3",children:[s.jsx("div",{className:"text-text font-medium",children:o.summary}),s.jsx("div",{className:"text-text-muted text-xs mt-1",children:o.rationale.length>300?o.rationale.slice(0,300)+"…":o.rationale}),o.alternatives_considered&&s.jsxs("div",{className:"text-text-dim text-xs mt-1",children:["alt: ",o.alternatives_considered.slice(0,150)]})]}),s.jsxs("td",{className:"py-3 pr-3",children:[s.jsx("span",{className:`inline-block rounded text-[10px] font-medium uppercase tracking-wider px-1.5 py-0.5 ${Ux(o.status)}`,children:o.status}),s.jsx("div",{className:"flex flex-wrap gap-1 mt-2",children:Ax.filter(u=>u!==o.status).map(u=>s.jsx(z,{size:"sm",variant:"ghost",onClick:()=>void i(o.id,u),className:"text-[10px] px-1.5 py-0.5",children:u},u))})]}),s.jsx("td",{className:"py-3 pr-3 text-text-muted text-xs",children:(o.files_touched??[]).map(u=>s.jsx("div",{children:u},u))}),s.jsx("td",{className:"py-3 pr-3",children:(o.tags??[]).map(u=>s.jsx(le,{className:"mr-1 mb-1",children:u},u))}),s.jsx("td",{className:"py-3 text-text-muted text-xs",title:o.created_at,children:G(o.created_at)})]},o.id))})]})})]})}function Vx(){const{snapshot:e,refresh:t}=Fe(),n=e.project.id,[r,l]=g.useState(null),[i,a]=g.useState({pending:0,approved:0,rejected:0}),[o,u]=g.useState(null),[f,p]=g.useState(null),d=g.useCallback(async()=>{try{const v=await nx(n);l(v.drafts),a(v.counts)}catch(v){u(v instanceof Error?v.message:String(v))}},[n]);g.useEffect(()=>{d()},[d]);async function x(v,j){if(f===null){p(v);try{j==="approve"?await rx(v):await sx(v),await Promise.all([d(),t()])}catch(y){alert(`${j} failed: ${y instanceof Error?y.message:String(y)}`)}finally{p(null)}}}if(o)return s.jsxs("div",{className:"text-danger",children:["Error: ",o]});if(!r)return s.jsx("div",{className:"text-text-muted",children:"loading drafts..."});const w=(v,j,y)=>s.jsxs("div",{className:"bg-panel border border-border rounded p-3",children:[s.jsx("div",{className:"text-[11px] uppercase tracking-wider text-text-muted",children:v}),s.jsx("div",{className:`text-2xl mt-1 ${y}`,children:j})]});return s.jsxs("div",{children:[s.jsxs("div",{className:"grid grid-cols-3 gap-3 mb-4",children:[w("Pending",i.pending,"text-warning"),w("Approved",i.approved,"text-success"),w("Rejected",i.rejected,"text-danger")]}),r.length===0?s.jsxs("div",{className:"bg-panel border border-dashed border-border rounded p-6 text-center text-text-muted",children:["No drafts. Drafts appear when the agent calls ",s.jsx("code",{children:"extract_decisions(text)"})," — LLM scans a transcript and proposes decisions for you to approve."]}):s.jsx("div",{className:"overflow-x-auto",children:s.jsxs("table",{className:"w-full text-sm",children:[s.jsx("thead",{children:s.jsxs("tr",{className:"text-[11px] uppercase tracking-wider text-text-muted text-left",children:[s.jsx("th",{className:"font-medium pb-2 pr-3 w-12",children:"ID"}),s.jsx("th",{className:"font-medium pb-2 pr-3 w-24",children:"Kind"}),s.jsx("th",{className:"font-medium pb-2 pr-3",children:"Summary + Rationale"}),s.jsx("th",{className:"font-medium pb-2 pr-3 w-32",children:"Files"}),s.jsx("th",{className:"font-medium pb-2 pr-3 w-44",children:"Action"}),s.jsx("th",{className:"font-medium pb-2 pr-3 w-20",children:"Created"}),s.jsx("th",{className:"font-medium pb-2",children:"Extractor"})]})}),s.jsx("tbody",{children:r.map(v=>s.jsxs("tr",{className:"border-b border-border/40 hover:bg-panel/40 align-top",children:[s.jsx("td",{className:"py-3 pr-3 text-text-muted font-mono",children:v.id}),s.jsx("td",{className:"py-3 pr-3",children:s.jsx(le,{children:v.kind})}),s.jsxs("td",{className:"py-3 pr-3",children:[s.jsx("div",{className:"text-text font-medium",children:v.summary}),s.jsx("div",{className:"text-text-muted text-xs mt-1",children:v.rationale}),v.alternatives_considered&&s.jsxs("div",{className:"text-text-dim text-xs mt-1",children:["alt: ",v.alternatives_considered]})]}),s.jsx("td",{className:"py-3 pr-3 text-text-muted text-xs",children:(v.files_touched??[]).map(j=>s.jsx("div",{children:j},j))}),s.jsx("td",{className:"py-3 pr-3",children:v.status==="pending"?s.jsxs("div",{className:"flex gap-1.5",children:[s.jsx(z,{size:"sm",variant:"primary",disabled:f===v.id,onClick:()=>void x(v.id,"approve"),children:"Approve"}),s.jsx(z,{size:"sm",variant:"default",disabled:f===v.id,onClick:()=>void x(v.id,"reject"),children:"Reject"})]}):v.status==="approved"?s.jsxs(le,{className:"bg-success text-bg",children:["approved ",v.approved_decision_id?`→ #${v.approved_decision_id}`:""]}):s.jsx(le,{className:"bg-danger text-white",children:"rejected"})}),s.jsx("td",{className:"py-3 pr-3 text-text-muted text-xs",children:G(v.created_at)}),s.jsx("td",{className:"py-3 text-text-dim text-[10px] font-mono",children:v.extractor_model??""})]},v.id))})]})})]})}function Wx(){const{snapshot:e}=Fe(),{dead_ends:t}=e;return t.length===0?s.jsxs("div",{className:"bg-panel border border-dashed border-border rounded p-6 text-center text-text-muted",children:["No dead ends logged. Use ",s.jsx("code",{children:"log_dead_end"})," when an approach fails."]}):s.jsx("div",{className:"overflow-x-auto",children:s.jsxs("table",{className:"w-full text-sm",children:[s.jsx("thead",{children:s.jsxs("tr",{className:"text-[11px] uppercase tracking-wider text-text-muted text-left",children:[s.jsx("th",{className:"font-medium pb-2 pr-3 w-12",children:"ID"}),s.jsx("th",{className:"font-medium pb-2 pr-3",children:"Attempted"}),s.jsx("th",{className:"font-medium pb-2 pr-3",children:"Why failed"}),s.jsx("th",{className:"font-medium pb-2 pr-3 w-32",children:"Files"}),s.jsx("th",{className:"font-medium pb-2 pr-3 w-24",children:"Flag"}),s.jsx("th",{className:"font-medium pb-2 w-24",children:"Logged"})]})}),s.jsx("tbody",{children:t.map(n=>s.jsxs("tr",{className:"border-b border-border/40 hover:bg-panel/40 align-top",children:[s.jsx("td",{className:"py-3 pr-3 text-text-muted font-mono",children:n.id}),s.jsx("td",{className:"py-3 pr-3 text-text font-medium",children:n.attempted_approach}),s.jsx("td",{className:"py-3 pr-3 text-text-muted",children:n.failure_reason}),s.jsx("td",{className:"py-3 pr-3 text-text-muted text-xs",children:(n.files_involved??[]).map(r=>s.jsx("div",{children:r},r))}),s.jsx("td",{className:"py-3 pr-3",children:n.never_retry&&s.jsx(le,{className:"bg-danger text-white",children:"never retry"})}),s.jsx("td",{className:"py-3 text-text-muted text-xs",title:n.created_at,children:G(n.created_at)})]},n.id))})]})})}function Hx(){const{snapshot:e}=Fe(),{notes:t}=e;return t.length===0?s.jsxs("div",{className:"bg-panel border border-dashed border-border rounded p-6 text-center text-text-muted",children:["No notes yet. Use ",s.jsx("code",{children:"add_note"})," for stray observations."]}):s.jsx("div",{className:"space-y-6",children:t.map(n=>s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-2 mb-2 flex-wrap",children:[s.jsxs(le,{children:["note #",n.id]}),(n.tags??[]).map(r=>s.jsx(le,{children:r},r)),s.jsx("span",{className:"text-text-muted text-xs",children:G(n.created_at)}),n.audio_path&&s.jsx(le,{className:"bg-success text-bg",children:"audio"})]}),s.jsx("pre",{className:"bg-panel border border-border rounded p-3 text-xs font-mono text-text whitespace-pre-wrap",children:n.body}),n.audio_path&&s.jsx("audio",{controls:!0,className:"mt-2 w-full",src:n.audio_path}),n.files_touched&&n.files_touched.length>0&&s.jsxs("div",{className:"text-text-muted text-xs mt-1",children:["files: ",n.files_touched.join(", ")]})]},n.id))})}function Qx(){const{snapshot:e}=Fe(),{latest_plan:t,plan_history:n}=e;return t?s.jsxs("div",{children:[s.jsxs("section",{className:"mb-8",children:[s.jsxs("h3",{className:"text-sm text-text mb-2",children:["Latest plan — v",t.version]}),s.jsxs("div",{className:"text-text-muted text-xs mb-3",children:["saved ",G(t.created_at)]}),s.jsx("pre",{className:"bg-panel border border-border rounded p-4 text-xs font-mono text-text whitespace-pre-wrap overflow-x-auto",children:t.plan_md})]}),n.length>0&&s.jsxs("section",{children:[s.jsx("h3",{className:"text-sm text-text mb-3",children:"Version history"}),s.jsx("ul",{className:"space-y-1 text-sm",children:n.map(r=>s.jsxs("li",{className:"text-text-muted",children:[s.jsxs("span",{className:"text-text font-medium",children:["v",r.version]})," — ",r.created_at," (",r.plan_md_length," chars)"]},r.id))})]})]}):s.jsxs("div",{className:"bg-panel border border-dashed border-border rounded p-6 text-center text-text-muted",children:["No plans saved. Use ",s.jsx("code",{children:"save_plan"})," to persist an approved plan."]})}function en({title:e,children:t}){return s.jsxs("section",{className:"mb-6",children:[s.jsx("h3",{className:"text-sm text-text mb-2",children:e}),t]})}function Un(){return s.jsx("div",{className:"text-text-muted text-sm",children:"(none)"})}function Kx(){const{snapshot:e}=Fe(),t=e.context;if(!t)return s.jsxs("div",{className:"bg-panel border border-dashed border-border rounded p-6 text-center text-text-muted",children:["No context set. Use ",s.jsx("code",{children:"update_context"})," to record conventions / dont_touch / deploy_notes."]});const n=t.file_annotations??{},r=Object.entries(n);return s.jsxs("div",{children:[s.jsx(en,{title:"Conventions",children:t.conventions?s.jsx("pre",{className:"bg-panel border border-border rounded p-3 text-xs font-mono text-text whitespace-pre-wrap",children:t.conventions}):s.jsx(Un,{})}),s.jsx(en,{title:"Don't touch",children:t.dont_touch&&t.dont_touch.length>0?s.jsx("ul",{className:"list-disc list-inside text-sm text-text",children:t.dont_touch.map(l=>s.jsx("li",{children:l},l))}):s.jsx(Un,{})}),s.jsx(en,{title:"Test patterns",children:t.test_patterns?s.jsx("pre",{className:"bg-panel border border-border rounded p-3 text-xs font-mono text-text whitespace-pre-wrap",children:t.test_patterns}):s.jsx(Un,{})}),s.jsx(en,{title:"Deploy notes",children:t.deploy_notes?s.jsx("pre",{className:"bg-panel border border-border rounded p-3 text-xs font-mono text-text whitespace-pre-wrap",children:t.deploy_notes}):s.jsx(Un,{})}),s.jsx(en,{title:"File annotations",children:r.length>0?s.jsxs("table",{className:"w-full text-sm",children:[s.jsx("thead",{children:s.jsxs("tr",{className:"text-[11px] uppercase tracking-wider text-text-muted text-left",children:[s.jsx("th",{className:"pb-2 pr-3",children:"Path"}),s.jsx("th",{className:"pb-2",children:"Annotation"})]})}),s.jsx("tbody",{children:r.map(([l,i])=>s.jsxs("tr",{className:"border-b border-border/40 align-top",children:[s.jsx("td",{className:"py-2 pr-3 text-text font-mono text-xs",children:l}),s.jsx("td",{className:"py-2 text-text-muted",children:i})]},l))})]}):s.jsx(Un,{})}),s.jsx(en,{title:"Meta",children:s.jsxs("div",{className:"text-xs text-text-muted",children:["Last validated commit: ",t.last_validated_commit?s.jsx("code",{className:"text-text",children:t.last_validated_commit}):"(none)",s.jsx("br",{}),"Updated: ",t.updated_at]})})]})}function Yx(){const{snapshot:e}=Fe(),{activity:t}=e;return t.length===0?s.jsx("div",{className:"bg-panel border border-dashed border-border rounded p-6 text-center text-text-muted",children:"No activity yet. Write paths (claim_task, log_decision, etc.) populate this timeline."}):s.jsx("div",{className:"space-y-px",children:t.map(n=>s.jsxs("div",{className:"grid grid-cols-[110px_160px_1fr_140px] gap-3 py-2 border-b border-border/40 items-baseline text-xs",children:[s.jsx("div",{className:"text-text-muted font-mono",title:n.created_at,children:G(n.created_at)}),s.jsx("div",{className:"text-accent",children:n.action_type}),s.jsxs("div",{className:"text-text flex flex-wrap items-center gap-2",children:[n.action_details&&s.jsx("span",{children:n.action_details}),n.entity_type&&s.jsxs(le,{children:[n.entity_type,"#",n.entity_id??"?"]}),n.ref_url&&s.jsxs("span",{className:"text-text-dim font-mono",children:[n.ref_url.slice(0,16),"…"]})]}),s.jsx("div",{className:"text-text-muted font-mono text-[11px]",children:n.session_id??""})]},n.id))})}function Zo(e){if(e<60)return`${e}s`;const t=Math.round(e/60);if(t<60)return`${t}m`;const n=Math.floor(t/60),r=t%60;return r===0?`${n}h`:`${n}h ${r}m`}function ne({label:e,value:t}){return s.jsxs("div",{className:"bg-panel border border-border rounded p-3",children:[s.jsx("div",{className:"text-[11px] uppercase tracking-wider text-text-muted",children:e}),s.jsx("div",{className:"text-2xl text-text mt-1",children:t})]})}function Gx(){const{snapshot:e}=Fe(),{subtasks:t,decisions:n,dead_ends:r,notes:l,sessions:i,activity:a,plan_history:o,draft_counts:u,project:f}=e,[p,d]=g.useState(null),[x,w]=g.useState(null),[v,j]=g.useState(!1),[y,m]=g.useState(null),c=()=>{Ko(f.id).then(d),Yo(f.id).then(w)};g.useEffect(()=>{let C=!1;return Ko(f.id).then(ie=>{C||d(ie)}),Yo(f.id).then(ie=>{C||w(ie)}),()=>{C=!0}},[f.id]);const h=async()=>{j(!0),m(null);try{const C=await yx({since_hours:720});m(`parsed ${C.parsed} transcripts, upserted ${C.upserted}, total scanned ≈ $${C.total_cost_usd.toFixed(2)}`),c()}catch(C){m("ingest failed: "+(C instanceof Error?C.message:String(C)))}finally{j(!1)}},k=new Map(t.map(C=>[C.id,C.title])),b={total:t.length,todo:t.filter(C=>C.status==="todo").length,in_progress:t.filter(C=>C.status==="in_progress").length,done:t.filter(C=>C.status==="done").length},N={total:n.length,open:n.filter(C=>C.status==="open").length,fixed:n.filter(C=>C.status==="fixed").length},_=Date.now(),E=a.filter(C=>{const ie=new Date(C.created_at.replace(" ","T")+"Z").getTime();return!isNaN(ie)&&_-ie<864e5}).length,F=new Map;for(const C of a)F.set(C.action_type,(F.get(C.action_type)??0)+1);const L=[...F.entries()].sort((C,ie)=>ie[1]-C[1]).slice(0,20);return s.jsxs("div",{children:[s.jsxs("section",{className:"mb-6",children:[s.jsx("h3",{className:"text-sm text-text mb-3",children:"Subtasks"}),s.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[s.jsx(ne,{label:"total",value:b.total}),s.jsx(ne,{label:"todo",value:b.todo}),s.jsx(ne,{label:"in progress",value:b.in_progress}),s.jsx(ne,{label:"done",value:b.done})]})]}),s.jsxs("section",{className:"mb-6",children:[s.jsx("h3",{className:"text-sm text-text mb-3",children:"Memory"}),s.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[s.jsx(ne,{label:"decisions",value:N.total}),s.jsx(ne,{label:"decisions open",value:N.open}),s.jsx(ne,{label:"decisions fixed",value:N.fixed}),s.jsx(ne,{label:"drafts pending",value:u.pending}),s.jsx(ne,{label:"drafts approved",value:u.approved}),s.jsx(ne,{label:"dead ends",value:r.length}),s.jsx(ne,{label:"notes",value:l.length}),s.jsx(ne,{label:"plan versions",value:o.length})]})]}),s.jsxs("section",{className:"mb-6",children:[s.jsx("h3",{className:"text-sm text-text mb-3",children:"Time on task"}),p===null?s.jsx("div",{className:"text-text-muted text-sm",children:"loading…"}):s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 gap-3 mb-4",children:[s.jsxs("div",{className:"bg-panel border border-border rounded p-3",children:[s.jsx("div",{className:"text-[11px] uppercase tracking-wider text-text-muted",children:"total time"}),s.jsx("div",{className:"text-2xl text-text mt-1",children:Zo(p.total_seconds)})]}),s.jsx(ne,{label:"sessions w/ subtask",value:p.session_count}),s.jsx(ne,{label:"tasks tracked",value:p.per_subtask.length})]}),p.per_subtask.length===0?s.jsx("div",{className:"text-text-muted text-sm",children:"(no time-tracked sessions — sessions only count toward a task when claude_session_id is linked at claim)"}):s.jsxs("table",{className:"w-full text-sm",children:[s.jsx("thead",{children:s.jsxs("tr",{className:"text-[11px] uppercase tracking-wider text-text-muted text-left",children:[s.jsx("th",{className:"pb-2 pr-3",children:"Task"}),s.jsx("th",{className:"pb-2 pr-3 text-right",children:"Duration"}),s.jsx("th",{className:"pb-2 pr-3 text-right",children:"Sessions"}),s.jsx("th",{className:"pb-2 text-right",children:"Last touched"})]})}),s.jsx("tbody",{children:p.per_subtask.slice(0,20).map(C=>s.jsxs("tr",{className:"border-b border-border/40",children:[s.jsx("td",{className:"py-1.5 pr-3 text-text",children:s.jsxs("a",{href:`#subtask-${C.subtask_id}`,className:"hover:underline",children:["#",C.subtask_id," ",k.get(C.subtask_id)??"(deleted)"]})}),s.jsx("td",{className:"py-1.5 pr-3 text-text text-right font-mono",children:Zo(C.total_seconds)}),s.jsxs("td",{className:"py-1.5 pr-3 text-text text-right",children:[C.session_count,C.open_sessions>0?s.jsxs("span",{className:"text-warning",children:[" (",C.open_sessions," open)"]}):null]}),s.jsx("td",{className:"py-1.5 text-text-muted text-right text-xs",children:C.last_session_at??"—"})]},C.subtask_id))})]})]})]}),s.jsxs("section",{className:"mb-6",children:[s.jsxs("div",{className:"flex items-baseline justify-between mb-3",children:[s.jsx("h3",{className:"text-sm text-text",children:"AI token cost"}),s.jsx("button",{onClick:()=>void h(),disabled:v,className:"text-[11px] uppercase tracking-wider text-accent hover:underline disabled:text-text-dim",children:v?"ingesting…":"ingest transcripts"})]}),y&&s.jsx("div",{className:"text-text-muted text-xs mb-3",children:y}),x===null?s.jsx("div",{className:"text-text-muted text-sm",children:"loading…"}):s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 gap-3 mb-4",children:[s.jsxs("div",{className:"bg-panel border border-border rounded p-3",children:[s.jsx("div",{className:"text-[11px] uppercase tracking-wider text-text-muted",children:"total cost"}),s.jsxs("div",{className:"text-2xl text-text mt-1",children:["$",x.total_cost_usd.toFixed(2)]})]}),s.jsx(ne,{label:"costed sessions",value:x.session_count}),s.jsx(ne,{label:"tasks with cost",value:x.per_subtask.length})]}),x.per_subtask.length===0?s.jsxs("div",{className:"text-text-muted text-sm",children:["(no cost data yet — click ",s.jsx("em",{children:"ingest transcripts"})," above to parse ",s.jsx("code",{children:"~/.claude/projects/"})," JSONL files)"]}):s.jsxs("table",{className:"w-full text-sm",children:[s.jsx("thead",{children:s.jsxs("tr",{className:"text-[11px] uppercase tracking-wider text-text-muted text-left",children:[s.jsx("th",{className:"pb-2 pr-3",children:"Task"}),s.jsx("th",{className:"pb-2 pr-3 text-right",children:"Cost (USD)"}),s.jsx("th",{className:"pb-2 pr-3 text-right",children:"Input tok"}),s.jsx("th",{className:"pb-2 pr-3 text-right",children:"Output tok"}),s.jsx("th",{className:"pb-2 text-right",children:"Models"})]})}),s.jsx("tbody",{children:x.per_subtask.slice(0,20).map(C=>s.jsxs("tr",{className:"border-b border-border/40",children:[s.jsxs("td",{className:"py-1.5 pr-3 text-text",children:["#",C.subtask_id," ",k.get(C.subtask_id)??"(deleted)"]}),s.jsxs("td",{className:"py-1.5 pr-3 text-text text-right font-mono",children:["$",C.total_cost_usd.toFixed(4)]}),s.jsx("td",{className:"py-1.5 pr-3 text-text-muted text-right font-mono text-xs",children:C.total_input_tokens.toLocaleString()}),s.jsx("td",{className:"py-1.5 pr-3 text-text-muted text-right font-mono text-xs",children:C.total_output_tokens.toLocaleString()}),s.jsx("td",{className:"py-1.5 text-text-muted text-right text-xs",children:C.by_model.map(ie=>ie.model.replace("claude-","")).join(", ")})]},C.subtask_id))})]})]})]}),s.jsxs("section",{className:"mb-6",children:[s.jsx("h3",{className:"text-sm text-text mb-3",children:"Activity"}),s.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 gap-3 mb-4",children:[s.jsx(ne,{label:"sessions",value:i.length}),s.jsx(ne,{label:"events total",value:a.length}),s.jsx(ne,{label:"events 24h",value:E})]}),s.jsx("h3",{className:"text-sm text-text mb-3",children:"Recent action counts"}),L.length===0?s.jsx("div",{className:"text-text-muted text-sm",children:"(no activity)"}):s.jsxs("table",{className:"w-full text-sm",children:[s.jsx("thead",{children:s.jsxs("tr",{className:"text-[11px] uppercase tracking-wider text-text-muted text-left",children:[s.jsx("th",{className:"pb-2 pr-3",children:"Action"}),s.jsx("th",{className:"pb-2",children:"Count"})]})}),s.jsx("tbody",{children:L.map(([C,ie])=>s.jsxs("tr",{className:"border-b border-border/40",children:[s.jsx("td",{className:"py-1.5 pr-3 text-text font-mono text-xs",children:C}),s.jsx("td",{className:"py-1.5 text-text",children:ie})]},C))})]})]})]})}function Xx(){const{snapshot:e}=Fe(),{sessions:t}=e;return t.length===0?s.jsx("div",{className:"bg-panel border border-dashed border-border rounded p-6 text-center text-text-muted",children:"No sessions yet for this project. Sessions appear when agent_bootstrap or claim_task is called with a session_id."}):s.jsx("div",{className:"overflow-x-auto",children:s.jsxs("table",{className:"w-full text-sm",children:[s.jsx("thead",{children:s.jsxs("tr",{className:"text-[11px] uppercase tracking-wider text-text-muted text-left",children:[s.jsx("th",{className:"font-medium pb-2 pr-3",children:"Session ID"}),s.jsx("th",{className:"font-medium pb-2 pr-3 w-32",children:"Started"}),s.jsx("th",{className:"font-medium pb-2 pr-3 w-32",children:"Ended"}),s.jsx("th",{className:"font-medium pb-2 pr-3 w-24",children:"Duration"}),s.jsx("th",{className:"font-medium pb-2 pr-3 w-20",children:"Tool calls"}),s.jsx("th",{className:"font-medium pb-2 pr-3 w-20",children:"Files"}),s.jsx("th",{className:"font-medium pb-2",children:"Notes"})]})}),s.jsx("tbody",{children:t.map(n=>s.jsxs("tr",{className:"border-b border-border/40 hover:bg-panel/40 align-top",children:[s.jsx("td",{className:"py-2 pr-3 text-text font-mono text-xs",children:s.jsx(X,{to:`/sessions/${encodeURIComponent(n.session_id)}`,className:"text-accent hover:underline",children:n.session_id})}),s.jsx("td",{className:"py-2 pr-3 text-text-muted text-xs",children:G(n.started_at)}),s.jsx("td",{className:"py-2 pr-3 text-text-muted text-xs",children:n.ended_at?G(n.ended_at):"active"}),s.jsx("td",{className:"py-2 pr-3 text-text-muted text-xs",children:n.duration_seconds?`${Math.floor(n.duration_seconds/60)}m`:""}),s.jsx("td",{className:"py-2 pr-3 text-text-muted text-xs",children:n.tool_calls_count}),s.jsx("td",{className:"py-2 pr-3 text-text-muted text-xs",children:n.files_touched_count}),s.jsx("td",{className:"py-2 text-text-muted text-xs",children:n.notes??""})]},n.session_id))})]})})}function Jx(){const[e,t]=g.useState(null),[n,r]=g.useState(null);return g.useEffect(()=>{lx(500).then(t).catch(l=>r(l instanceof Error?l.message:String(l)))},[]),n?s.jsxs("div",{className:"text-danger",children:["Error: ",n]}):e?s.jsxs("div",{children:[s.jsxs("header",{className:"border-b border-border pb-3 mb-6",children:[s.jsx("h1",{className:"text-2xl text-text",children:"All sessions"}),s.jsxs("div",{className:"text-text-muted text-xs mt-1",children:[e.length," session(s)"]})]}),e.length===0?s.jsx("div",{className:"bg-panel border border-dashed border-border rounded p-6 text-center text-text-muted",children:"No sessions tracked yet."}):s.jsx("div",{className:"overflow-x-auto",children:s.jsxs("table",{className:"w-full text-sm",children:[s.jsx("thead",{children:s.jsxs("tr",{className:"text-[11px] uppercase tracking-wider text-text-muted text-left",children:[s.jsx("th",{className:"font-medium pb-2 pr-3",children:"Session ID"}),s.jsx("th",{className:"font-medium pb-2 pr-3 w-24",children:"Project"}),s.jsx("th",{className:"font-medium pb-2 pr-3 w-32",children:"Started"}),s.jsx("th",{className:"font-medium pb-2 pr-3 w-32",children:"Ended"}),s.jsx("th",{className:"font-medium pb-2 pr-3 w-24",children:"Duration"}),s.jsx("th",{className:"font-medium pb-2 w-20",children:"Tool calls"})]})}),s.jsx("tbody",{children:e.map(l=>s.jsxs("tr",{className:"border-b border-border/40 hover:bg-panel/40",children:[s.jsx("td",{className:"py-2 pr-3 text-text font-mono text-xs",children:s.jsx(X,{to:`/sessions/${encodeURIComponent(l.session_id)}`,className:"text-accent hover:underline",children:l.session_id})}),s.jsx("td",{className:"py-2 pr-3 text-text-muted",children:l.project_id?`#${l.project_id}`:""}),s.jsx("td",{className:"py-2 pr-3 text-text-muted text-xs",children:G(l.started_at)}),s.jsx("td",{className:"py-2 pr-3 text-text-muted text-xs",children:l.ended_at?G(l.ended_at):"active"}),s.jsx("td",{className:"py-2 pr-3 text-text-muted text-xs",children:l.duration_seconds?`${Math.floor(l.duration_seconds/60)}m`:""}),s.jsx("td",{className:"py-2 text-text-muted text-xs",children:l.tool_calls_count})]},l.session_id))})]})})]}):s.jsx("div",{className:"text-text-muted",children:"loading sessions..."})}function qx(){const{sessionId:e}=ya(),[t,n]=g.useState(null),[r,l]=g.useState(null);if(g.useEffect(()=>{e&&ix(e).then(n).catch(o=>l(o instanceof Error?o.message:String(o)))},[e]),r)return s.jsxs("div",{className:"text-danger",children:["Error: ",r]});if(!t)return s.jsx("div",{className:"text-text-muted",children:"loading session..."});const{session:i,activity:a}=t;return s.jsxs("div",{children:[s.jsxs("header",{className:"border-b border-border pb-3 mb-4",children:[s.jsx(X,{to:"/sessions",className:"text-accent text-xs hover:underline",children:"← all sessions"}),s.jsx("h1",{className:"text-2xl text-text mt-1 font-mono",children:i.session_id}),s.jsxs("div",{className:"text-text-muted text-xs mt-2 flex gap-3 flex-wrap",children:[s.jsxs("span",{children:["started ",i.started_at]}),i.ended_at&&s.jsxs("span",{children:["ended ",i.ended_at]}),i.duration_seconds!==null&&s.jsxs("span",{children:["duration ",Math.floor(i.duration_seconds/60),"m ",i.duration_seconds%60,"s"]}),s.jsxs("span",{children:[i.tool_calls_count," tool calls"]}),s.jsxs("span",{children:[i.files_touched_count," files touched"]})]}),i.notes&&s.jsx("pre",{className:"bg-panel border border-border rounded p-3 mt-3 text-xs font-mono text-text whitespace-pre-wrap",children:i.notes})]}),s.jsx("h2",{className:"text-sm text-text mb-3",children:"Activity"}),a.length===0?s.jsx("div",{className:"text-text-muted text-sm",children:"(no activity in this session)"}):s.jsx("div",{className:"space-y-px",children:a.map(o=>s.jsxs("div",{className:"grid grid-cols-[110px_160px_1fr] gap-3 py-2 border-b border-border/40 items-baseline text-xs",children:[s.jsx("div",{className:"text-text-muted font-mono",title:o.created_at,children:G(o.created_at)}),s.jsx("div",{className:"text-accent",children:o.action_type}),s.jsxs("div",{className:"text-text flex flex-wrap items-center gap-2",children:[o.action_details&&s.jsx("span",{children:o.action_details}),o.entity_type&&s.jsxs(le,{children:[o.entity_type,"#",o.entity_id??"?"]})]})]},o.id))})]})}const Zx={storage:"Storage",dashboard:"Dashboard",embedding:"Embedding (semantic recall)",llm:"LLM (extraction + summarization)",recall:"Recall mode",sync:"Sync"};function ev(){const[e,t]=g.useState(null),[n,r]=g.useState([]),[l,i]=g.useState({}),[a,o]=g.useState(null),u=g.useCallback(async()=>{try{const v=await ax();t(v.specs),r(v.values),i({})}catch(v){o({kind:"err",text:v instanceof Error?v.message:String(v)})}},[]);if(g.useEffect(()=>{u()},[u]),!e)return s.jsx("div",{className:"text-text-muted",children:"loading settings..."});const f=new Map(n.map(v=>[v.key,v])),p=new Map;for(const v of e)p.has(v.group)||p.set(v.group,[]),p.get(v.group).push(v);function d(v,j){i(y=>({...y,[v]:j}))}function x(v){i(j=>{const{[v]:y,...m}=j;return m})}async function w(){if(Object.keys(l).length===0){o({kind:"err",text:"no changes to save"});return}o({kind:"busy",text:"writing ~/.shinobi/.env ..."});try{const v=await ox(l);if(!v.ok)throw new Error(v.error??"unknown error");const j=Object.keys(l).filter(m=>{var c;return(c=e==null?void 0:e.find(h=>h.key===m))==null?void 0:c.requiresRestart}),y=`wrote ${v.written??0}, cleared ${v.cleared??0}${j.length>0?` (restart required: ${j.join(", ")})`:""}`;o({kind:"ok",text:y}),await u()}catch(v){o({kind:"err",text:v instanceof Error?v.message:String(v)})}}return s.jsxs("div",{className:"max-w-3xl",children:[s.jsxs("header",{className:"border-b border-border pb-3 mb-6 flex items-baseline justify-between",children:[s.jsx("h1",{className:"text-2xl text-text",children:"Settings"}),s.jsx("span",{className:"text-text-muted text-xs",children:"writes to ~/.shinobi/.env with backup"})]}),a&&s.jsxs("div",{className:`mb-4 px-4 py-2 rounded text-sm flex items-center gap-2 ${a.kind==="ok"?"bg-success/20 text-success border border-success/40":a.kind==="err"?"bg-danger/20 text-danger border border-danger/40":"bg-warning/20 text-warning border border-warning/40"}`,children:[a.kind==="ok"&&s.jsx(Rt,{className:"w-4 h-4"}),a.kind==="err"&&s.jsx(at,{className:"w-4 h-4"}),a.kind==="busy"&&s.jsx(Yt,{className:"w-4 h-4 animate-spin"}),a.text]}),[...p.entries()].map(([v,j])=>s.jsxs("section",{className:"mb-8",children:[s.jsx("h2",{className:"text-sm text-text mb-3 uppercase tracking-wider text-text-muted",children:Zx[v]}),s.jsx("div",{className:"space-y-3",children:j.map(y=>{const m=f.get(y.key),c=y.key in l,h=l[y.key];return s.jsxs("div",{className:"bg-panel border border-border rounded p-3",children:[s.jsxs("div",{className:"flex items-baseline justify-between gap-3 mb-1",children:[s.jsxs("div",{children:[s.jsxs("label",{className:"text-sm text-text font-medium",children:[y.label,y.requiresRestart&&s.jsx("span",{className:"ml-2 text-[10px] uppercase tracking-wider text-warning",children:"restart required"})]}),s.jsx("code",{className:"ml-2 text-[11px] text-text-muted font-mono",children:y.key})]}),(m==null?void 0:m.is_set)&&!c&&s.jsx("span",{className:"text-[10px] uppercase tracking-wider text-success",children:"set"}),c&&s.jsx("span",{className:"text-[10px] uppercase tracking-wider text-warning",children:"unsaved"})]}),s.jsx("p",{className:"text-xs text-text-muted mb-2",children:y.description}),s.jsxs("div",{className:"flex gap-2 items-center",children:[y.enumValues?s.jsxs("select",{value:c?h??"":(m==null?void 0:m.value)??"",onChange:k=>d(y.key,k.target.value||null),className:"bg-panel-2 border border-border rounded px-2 py-1 text-sm text-text font-mono flex-1",children:[s.jsx("option",{value:"",children:"(unset)"}),y.enumValues.map(k=>s.jsx("option",{value:k,children:k},k))]}):s.jsx("input",{type:y.secret?"password":"text",value:c?h??"":(m==null?void 0:m.value)??"",placeholder:m!=null&&m.is_set&&y.secret?"(secret set — type to replace)":y.placeholder??"(unset)",onChange:k=>d(y.key,k.target.value||null),className:"bg-panel-2 border border-border rounded px-2 py-1 text-sm text-text font-mono flex-1 placeholder:text-text-dim"}),c&&s.jsx(z,{size:"sm",variant:"ghost",onClick:()=>x(y.key),title:"discard change",children:s.jsx(Ih,{className:"w-3 h-3"})})]})]},y.key)})})]},v)),s.jsxs("div",{className:"sticky bottom-0 bg-bg/95 backdrop-blur border-t border-border py-3 -mx-8 px-8 flex justify-end gap-2",children:[s.jsx(z,{variant:"default",onClick:()=>i({}),disabled:Object.keys(l).length===0,children:"Discard all"}),s.jsxs(z,{variant:"primary",onClick:()=>void w(),disabled:Object.keys(l).length===0,children:["Save (",Object.keys(l).length," change",Object.keys(l).length===1?"":"s",")"]})]})]})}async function $d(e,t){const n=await fetch(e,t);if(!n.ok){const r=await n.text();throw new Error(`${(t==null?void 0:t.method)??"GET"} ${e} → ${n.status}: ${r.slice(0,200)}`)}return await n.json()}async function tv(e,t="recording.webm"){const n=new FormData;return n.append("audio",e,t),await(await fetch("/api/audio/transcribe",{method:"POST",body:n})).json()}function nv(e){return $d("/api/voice/save-note",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})}function rv(e){return $d("/api/voice/extract-decisions",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})}async function sv(e){const t=new FormData;return t.append("audio",e.file),t.append("project_id",String(e.project_id)),e.title&&t.append("title",e.title),e.session_id&&t.append("session_id",e.session_id),await(await fetch("/api/voice/meeting/process",{method:"POST",body:t})).json()}async function lv(e){var o;if(!((o=navigator.mediaDevices)!=null&&o.getUserMedia))throw new Error("mic API unavailable in this browser");const t=await navigator.mediaDevices.getUserMedia({audio:!0}),r=["audio/webm;codecs=opus","audio/webm","audio/mp4","audio/ogg;codecs=opus"].find(u=>MediaRecorder.isTypeSupported(u))??"",l=r?new MediaRecorder(t,{mimeType:r}):new MediaRecorder(t),i=[],a=Date.now();return l.addEventListener("dataavailable",u=>{u.data&&u.data.size>0&&i.push(u.data)}),l.addEventListener("stop",()=>{const u=new Blob(i,{type:l.mimeType||"audio/webm"});e(u,Date.now()-a),t.getTracks().forEach(f=>f.stop())}),l.start(),l}function iv(){const[e,t]=g.useState({kind:"idle"}),[n,r]=g.useState([]),[l,i]=g.useState(null),[a,o]=g.useState("voice"),[u,f]=g.useState(""),p=g.useRef(null),[d,x]=g.useState(0);g.useEffect(()=>{Id({sort:"active"}).then(N=>{r(N);const _=localStorage.getItem("voice-project-id");_&&N.some(E=>String(E.id)===_)&&i(Number(_))}).catch(()=>{})},[]),g.useEffect(()=>(e.kind==="recording"?p.current=window.setInterval(()=>x(N=>N+1),250):p.current!==null&&(clearInterval(p.current),p.current=null),()=>{p.current!==null&&clearInterval(p.current)}),[e.kind]);function w(N){i(N),N!==null?localStorage.setItem("voice-project-id",String(N)):localStorage.removeItem("voice-project-id")}async function v(){try{const N=await lv((_,E)=>{t({kind:"recorded",blob:_,durationMs:E})});t({kind:"recording",startedAt:Date.now(),recorder:N})}catch(N){t({kind:"error",message:N instanceof Error?N.message:String(N)})}}function j(){e.kind==="recording"&&e.recorder.stop()}function y(){t({kind:"idle"}),f("")}async function m(){if(e.kind==="recorded"){t({kind:"transcribing"});try{const N=e.blob.type.includes("mp4")?"mp4":e.blob.type.includes("ogg")?"ogg":"webm",_=await tv(e.blob,`recording.${N}`);if(!_.ok||!_.text){t({kind:"error",message:_.error??"transcription returned empty"});return}f(_.text),t({kind:"transcribed",blob:e.blob,text:_.text,provider:_.provider??"unknown",model:_.model??"unknown",durationMs:e.durationMs})}catch(N){t({kind:"error",message:N instanceof Error?N.message:String(N)})}}}async function c(){var N;if(!(e.kind!=="transcribed"||u.trim()==="")){t({kind:"saving"});try{const _=a.split(",").map(F=>F.trim()).filter(Boolean),E=await nv({project_id:l??void 0,text:u.trim(),tags:_.length>0?_:["voice"]});if(!E.ok){t({kind:"error",message:E.error??"save failed"});return}t({kind:"done",message:`note #${(N=E.note)==null?void 0:N.id} saved${l?` to project #${l}`:" to inbox"}`})}catch(_){t({kind:"error",message:_ instanceof Error?_.message:String(_)})}}}async function h(){if(e.kind!=="transcribed"||u.trim()===""||l===null){l===null&&t({kind:"error",message:"pick a project to extract decisions into"});return}t({kind:"saving"});try{const N=await rv({project_id:l,text:u.trim()});if(!N.ok){t({kind:"error",message:N.error??"extract failed"});return}t({kind:"done",message:`${N.drafts_extracted??0} draft(s) created via ${N.provider}:${N.model} — open project Drafts tab to review`})}catch(N){t({kind:"error",message:N instanceof Error?N.message:String(N)})}}function k(){t({kind:"idle"}),f("")}const b=e.kind==="recording"?Math.floor((Date.now()-e.startedAt)/1e3):0;return s.jsxs("div",{className:"max-w-2xl mx-auto",children:[s.jsxs("header",{className:"border-b border-border pb-3 mb-6",children:[s.jsxs("h1",{className:"text-2xl text-text flex items-center gap-2",children:[s.jsx(Ni,{className:"w-6 h-6 text-accent"})," Voice capture"]}),s.jsx("p",{className:"text-text-muted text-xs mt-1",children:"Record audio → Whisper transcribe → save as note or extract decisions into drafts for review."})]}),s.jsxs("div",{className:"bg-panel border border-border rounded-lg p-6 mb-4",children:[s.jsx("label",{className:"block text-[11px] uppercase tracking-wider text-text-muted mb-2",children:"Project"}),s.jsxs("select",{value:l??"",onChange:N=>w(N.target.value?Number(N.target.value):null),className:"w-full bg-panel-2 border border-border rounded px-3 py-2 text-sm text-text",children:[s.jsx("option",{value:"",children:"(inbox — no project)"}),n.map(N=>s.jsxs("option",{value:N.id,children:[N.workspace?`[${N.workspace}] `:"",N.title]},N.id))]}),s.jsxs("div",{className:"flex flex-col items-center my-8",children:[e.kind==="idle"&&s.jsx(z,{variant:"primary",onClick:()=>void v(),className:"w-32 h-32 rounded-full flex items-center justify-center text-base",children:s.jsx(Ni,{className:"w-12 h-12"})}),e.kind==="recording"&&s.jsxs(s.Fragment,{children:[s.jsx(z,{variant:"danger",onClick:j,className:"w-32 h-32 rounded-full flex items-center justify-center animate-pulse",children:s.jsx(Uh,{className:"w-12 h-12"})}),s.jsxs("div",{className:"mt-3 text-warning text-sm font-mono",children:["recording ",b,"s"]})]}),e.kind==="recorded"&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"text-text text-sm",children:["recorded ",Math.floor(e.durationMs/1e3),"s"]}),s.jsx("audio",{controls:!0,className:"my-3",src:URL.createObjectURL(e.blob)}),s.jsxs("div",{className:"flex gap-2",children:[s.jsx(z,{variant:"default",onClick:y,children:s.jsx(jr,{className:"w-4 h-4"})}),s.jsx(z,{variant:"primary",onClick:()=>void m(),children:"Transcribe"})]})]}),e.kind==="transcribing"&&s.jsxs("div",{className:"text-warning text-sm flex items-center gap-2",children:[s.jsx(Yt,{className:"w-4 h-4 animate-spin"})," transcribing..."]}),e.kind==="transcribed"&&s.jsxs("div",{className:"w-full",children:[s.jsx("label",{className:"block text-[11px] uppercase tracking-wider text-text-muted mb-2",children:"Transcript (edit before saving)"}),s.jsx("textarea",{value:u,onChange:N=>f(N.target.value),rows:6,className:"w-full bg-panel-2 border border-border rounded px-3 py-2 text-sm text-text font-mono"}),s.jsxs("div",{className:"text-text-dim text-[10px] mt-1",children:["via ",e.provider,":",e.model," · ",Math.floor(e.durationMs/1e3),"s audio"]}),s.jsx("label",{className:"block text-[11px] uppercase tracking-wider text-text-muted mt-4 mb-2",children:"Tags (comma-separated, applied to note only)"}),s.jsx("input",{type:"text",value:a,onChange:N=>o(N.target.value),className:"w-full bg-panel-2 border border-border rounded px-3 py-2 text-sm text-text font-mono"}),s.jsxs("div",{className:"flex gap-2 mt-4 flex-wrap",children:[s.jsxs(z,{variant:"default",onClick:k,children:[s.jsx(jr,{className:"w-4 h-4 mr-1"})," Discard"]}),s.jsxs(z,{variant:"primary",onClick:()=>void c(),className:"flex items-center",children:[s.jsx($h,{className:"w-4 h-4 mr-1"})," Save as note"]}),s.jsxs(z,{variant:"primary",onClick:()=>void h(),disabled:l===null,className:"flex items-center",title:l===null?"pick a project first":"extract decisions to drafts",children:[s.jsx(Fh,{className:"w-4 h-4 mr-1"})," Extract decisions"]})]})]}),e.kind==="saving"&&s.jsxs("div",{className:"text-warning text-sm flex items-center gap-2",children:[s.jsx(Yt,{className:"w-4 h-4 animate-spin"})," saving..."]}),e.kind==="done"&&s.jsxs("div",{className:"text-success text-sm flex items-center gap-2 flex-col",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Rt,{className:"w-4 h-4"})," ",e.message]}),s.jsx(z,{variant:"primary",onClick:k,className:"mt-3",children:"Record another"})]}),e.kind==="error"&&s.jsxs("div",{className:"text-danger text-sm flex items-center gap-2 flex-col",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(at,{className:"w-4 h-4"})," ",e.message]}),s.jsx(z,{variant:"default",onClick:k,className:"mt-3",children:"Reset"})]})]})]}),s.jsx(av,{projects:n,defaultProjectId:l}),s.jsxs("div",{className:"text-text-muted text-xs mt-6",children:[s.jsxs("p",{children:["Requires a transcription provider: ",s.jsx("code",{children:"SHINOBI_TRANSCRIPTION_PROVIDER"})," in ",s.jsx(X,{to:"/settings",className:"text-accent underline",children:"Settings"})," (or canonical ",s.jsx("code",{children:"GROQ_API_KEY"})," / ",s.jsx("code",{children:"OPENAI_API_KEY"}),")."]}),s.jsx("p",{className:"mt-1",children:`Install as PWA on mobile via browser's "Add to home screen" — works offline for read-only.`})]})]})}function av({projects:e,defaultProjectId:t}){var y,m;const[n,r]=g.useState(null),[l,i]=g.useState(""),[a,o]=g.useState(t),[u,f]=g.useState(!1),[p,d]=g.useState(null),[x,w]=g.useState(null);g.useEffect(()=>{o(t)},[t]);async function v(){if(!n||a===null){w("pick an audio file and a project");return}f(!0),w(null),d(null);try{const c={file:n,project_id:a};l.trim()&&(c.title=l.trim());const h=await sv(c);if(!h.ok){w(h.error??"meeting processing failed");return}d(h)}catch(c){w(c instanceof Error?c.message:String(c))}finally{f(!1)}}function j(){r(null),i(""),d(null),w(null)}return s.jsxs("div",{className:"bg-panel border border-border rounded-lg p-6 mt-6",children:[s.jsxs("h2",{className:"text-sm text-text mb-2 flex items-center gap-2",children:[s.jsx(Hh,{className:"w-4 h-4 text-accent"})," Meeting capture (upload longer audio)"]}),s.jsxs("p",{className:"text-text-muted text-xs mb-4",children:["Upload a meeting recording (.mp3 / .m4a / .wav / .webm, max ~25 MB on Groq free tier). Whisper transcribes → transcript saved as a note tagged ",s.jsx("code",{children:"meeting"})," → decision extractor runs → review drafts on the project's Drafts tab."]}),s.jsx("label",{className:"block text-[11px] uppercase tracking-wider text-text-muted mb-2",children:"Project"}),s.jsxs("select",{value:a??"",onChange:c=>o(c.target.value?Number(c.target.value):null),className:"w-full bg-panel-2 border border-border rounded px-3 py-2 text-sm text-text mb-3",children:[s.jsx("option",{value:"",children:"(pick a project — required for meetings)"}),e.map(c=>s.jsxs("option",{value:c.id,children:[c.workspace?`[${c.workspace}] `:"",c.title]},c.id))]}),s.jsx("label",{className:"block text-[11px] uppercase tracking-wider text-text-muted mb-2",children:"Title (optional)"}),s.jsx("input",{type:"text",value:l,onChange:c=>i(c.target.value),placeholder:"e.g. Standup 2026-05-24",className:"w-full bg-panel-2 border border-border rounded px-3 py-2 text-sm text-text mb-3"}),s.jsx("label",{className:"block text-[11px] uppercase tracking-wider text-text-muted mb-2",children:"Audio file"}),s.jsx("input",{type:"file",accept:"audio/*,.mp3,.m4a,.wav,.webm,.ogg",onChange:c=>{var h;return r(((h=c.target.files)==null?void 0:h[0])??null)},className:"block w-full text-sm text-text-muted file:mr-3 file:py-1.5 file:px-3 file:rounded file:border-0 file:bg-accent file:text-bg file:cursor-pointer mb-3"}),n&&s.jsxs("div",{className:"text-text-dim text-[11px] mb-3",children:[n.name," · ",(n.size/1024/1024).toFixed(2)," MB",n.size>25*1024*1024&&s.jsx("span",{className:"text-warning ml-2",children:"⚠️ over 25 MB — Groq/OpenAI will reject. Pre-split with ffmpeg."})]}),s.jsxs("div",{className:"flex gap-2",children:[s.jsxs(z,{variant:"primary",onClick:()=>void v(),disabled:u||!n||a===null,children:[u?s.jsx(Yt,{className:"w-4 h-4 mr-1 animate-spin"}):s.jsx(Wh,{className:"w-4 h-4 mr-1"}),u?"processing...":"Process meeting"]}),(p||x)&&s.jsx(z,{variant:"default",onClick:j,children:"Reset"})]}),x&&s.jsxs("div",{className:"mt-4 px-3 py-2 rounded text-sm flex items-center gap-2 bg-danger/20 text-danger border border-danger/40",children:[s.jsx(at,{className:"w-4 h-4"})," ",x]}),p&&s.jsxs("div",{className:"mt-4 px-3 py-2 rounded text-sm bg-success/20 text-success border border-success/40",children:[s.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[s.jsx(Rt,{className:"w-4 h-4"})," Meeting processed"]}),s.jsxs("div",{className:"text-xs text-text grid grid-cols-[8rem_1fr] gap-y-1",children:[s.jsx("div",{className:"text-text-muted",children:"title"}),s.jsx("div",{children:p.title}),s.jsx("div",{className:"text-text-muted",children:"transcript"}),s.jsxs("div",{children:[(y=p.transcript_chars)==null?void 0:y.toLocaleString()," chars · ",((m=p.audio_duration_seconds)==null?void 0:m.toFixed(0))??"?","s audio · via ",p.transcription_provider,":",p.transcription_model]}),s.jsx("div",{className:"text-text-muted",children:"drafts extracted"}),s.jsxs("div",{children:[p.drafts_extracted??0," via ",p.extractor_provider,":",p.extractor_model]}),s.jsx("div",{className:"text-text-muted",children:"note id"}),s.jsxs("div",{children:["#",p.note_id]})]}),a!==null&&s.jsx(X,{to:`/projects/${a}/decision-drafts`,className:"inline-block mt-2 text-accent hover:underline text-xs",children:"→ Review drafts on project Drafts tab"})]})]})}const eu=4e3;function ov(){const[e,t]=g.useState(null),[n,r]=g.useState(null),[l,i]=g.useState(null),a=g.useCallback(async()=>{try{const d=await px();t(d),r(null)}catch(d){r(d instanceof Error?d.message:String(d))}},[]);g.useEffect(()=>{a();const d=setInterval(()=>void a(),eu);return()=>clearInterval(d)},[a]);async function o(d,x){i(d);try{await mx(d,x),await a()}catch(w){alert("respond failed: "+(w instanceof Error?w.message:String(w)))}finally{i(null)}}async function u(d){i(d);try{await hx(d),await a()}catch(x){alert("cancel failed: "+(x instanceof Error?x.message:String(x)))}finally{i(null)}}if(n)return s.jsxs("div",{className:"text-danger",children:["Error: ",n]});if(!e)return s.jsx("div",{className:"text-text-muted",children:"loading approvals..."});const f=e.filter(d=>d.status==="pending"),p=e.filter(d=>d.status!=="pending").slice(0,50);return s.jsxs("div",{className:"max-w-3xl",children:[s.jsxs("header",{className:"border-b border-border pb-3 mb-6 flex items-baseline justify-between",children:[s.jsx("h1",{className:"text-2xl text-text",children:"Approvals"}),s.jsxs("span",{className:"text-text-muted text-xs flex items-center gap-1",children:[s.jsx(Yt,{className:"w-3 h-3 animate-spin"}),"polling every ",eu/1e3,"s"]})]}),s.jsxs("section",{className:"mb-8",children:[s.jsxs("h2",{className:"text-sm text-text mb-3 uppercase tracking-wider text-text-muted",children:["Pending (",f.length,")"]}),f.length===0?s.jsxs("div",{className:"bg-panel border border-dashed border-border rounded p-6 text-center text-text-muted",children:["No pending approvals. Approvals appear when the agent calls ",s.jsx("code",{children:"request_approval"})," via MCP. They also fire web push to subscribed devices — see ",s.jsx(X,{to:"/push",className:"text-accent underline",children:"Push settings"}),"."]}):s.jsx("div",{className:"space-y-3",children:f.map(d=>s.jsxs("div",{id:`approval-${d.id}`,className:"bg-panel border border-warning/40 border-l-4 border-l-warning rounded-md p-4",children:[s.jsxs("div",{className:"flex items-baseline justify-between gap-3 mb-2",children:[s.jsxs("div",{className:"text-text-muted text-xs",children:["#",d.id,d.project_id&&s.jsxs(s.Fragment,{children:[" · project #",d.project_id]}),s.jsxs(s.Fragment,{children:[" · ",G(d.created_at)]})]}),s.jsx(le,{className:"bg-warning text-bg",children:"pending"})]}),s.jsx("div",{className:"text-text mb-3 whitespace-pre-wrap",children:d.prompt}),s.jsxs("div",{className:"flex flex-wrap gap-2",children:[d.options.map(x=>s.jsx(z,{variant:"primary",disabled:l===d.id,onClick:()=>void o(d.id,x),children:x},x)),s.jsx(z,{variant:"default",disabled:l===d.id,onClick:()=>void u(d.id),children:"Cancel"})]})]},d.id))})]}),s.jsxs("section",{children:[s.jsxs("h2",{className:"text-sm text-text mb-3 uppercase tracking-wider text-text-muted",children:["Recent (",p.length,")"]}),p.length===0?s.jsx("div",{className:"text-text-muted text-sm",children:"(none)"}):s.jsx("div",{className:"space-y-1.5",children:p.map(d=>s.jsxs("div",{className:"bg-panel border border-border rounded p-3 text-sm",children:[s.jsxs("div",{className:"flex items-baseline justify-between gap-3 mb-1",children:[s.jsxs("div",{className:"text-text-muted text-xs",children:["#",d.id,d.project_id&&s.jsxs(s.Fragment,{children:[" · project #",d.project_id]}),s.jsxs(s.Fragment,{children:[" · ",G(d.created_at)]})]}),d.status==="responded"?s.jsxs(le,{className:"bg-success text-bg",children:[s.jsx(Rt,{className:"w-3 h-3 inline mr-0.5"}),d.response_value]}):d.status==="expired"?s.jsx(le,{className:"bg-text-dim text-text",children:"expired"}):s.jsxs(le,{className:"bg-text-dim text-text",children:[s.jsx(at,{className:"w-3 h-3 inline mr-0.5"}),d.status]})]}),s.jsxs("div",{className:"text-text text-xs",children:[d.prompt.slice(0,200),d.prompt.length>200?"…":""]}),d.response_note&&s.jsxs("div",{className:"text-text-muted text-xs mt-1",children:["note: ",d.response_note]})]},d.id))})]})]})}function uv(e){const t="=".repeat((4-e.length%4)%4),n=(e+t).replace(/-/g,"+").replace(/_/g,"/"),r=atob(n),l=new ArrayBuffer(r.length),i=new Uint8Array(l);for(let a=0;a<r.length;a++)i[a]=r.charCodeAt(a);return i}function cv(){const[e,t]=g.useState({kind:"loading"}),[n,r]=g.useState(null),[l,i]=g.useState(!1),a=g.useCallback(async()=>{try{const y=await cx();let m=null,c="default";const h="serviceWorker"in navigator&&"PushManager"in window;if(h){c=Notification.permission;const b=await(await navigator.serviceWorker.ready).pushManager.getSubscription();m=(b==null?void 0:b.endpoint)??null}t({kind:"ready",subscriptions:y,selfEndpoint:m,permission:c,supported:h})}catch(y){t({kind:"error",message:y instanceof Error?y.message:String(y)})}},[]);g.useEffect(()=>{a()},[a]);async function o(){if(e.kind==="ready"){i(!0);try{const{public_key:y}=await ux(),h=(await(await navigator.serviceWorker.ready).pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:uv(y)})).toJSON();await dx({endpoint:h.endpoint,keys:{p256dh:h.keys.p256dh,auth:h.keys.auth},device_label:navigator.userAgent.slice(0,60)}),r({kind:"ok",text:"subscribed — try Test push below"}),await a()}catch(y){r({kind:"err",text:y instanceof Error?y.message:String(y)})}finally{i(!1)}}}async function u(){i(!0);try{const m=await(await navigator.serviceWorker.ready).pushManager.getSubscription();if(m&&await m.unsubscribe(),e.kind==="ready"&&m){const c=e.subscriptions.find(h=>h.endpoint===m.endpoint);c&&await Qo(c.id)}r({kind:"ok",text:"unsubscribed"}),await a()}catch(y){r({kind:"err",text:y instanceof Error?y.message:String(y)})}finally{i(!1)}}async function f(){i(!0);try{const y=await fx();r({kind:"ok",text:`pushed to ${y.succeeded}/${y.total} (failed ${y.failed}, pruned ${y.pruned_endpoints.length})`}),await a()}catch(y){r({kind:"err",text:y instanceof Error?y.message:String(y)})}finally{i(!1)}}async function p(y){i(!0);try{await Qo(y),await a()}catch(m){r({kind:"err",text:m instanceof Error?m.message:String(m)})}finally{i(!1)}}if(e.kind==="loading")return s.jsx("div",{className:"text-text-muted",children:"loading push state..."});if(e.kind==="error")return s.jsxs("div",{className:"text-danger",children:["Error: ",e.message]});const{subscriptions:d,selfEndpoint:x,permission:w,supported:v}=e,j=x!==null;return s.jsxs("div",{className:"max-w-3xl",children:[s.jsxs("header",{className:"border-b border-border pb-3 mb-6",children:[s.jsxs("h1",{className:"text-2xl text-text flex items-center gap-2",children:[s.jsx(ki,{className:"w-6 h-6 text-accent"})," Push notifications"]}),s.jsxs("p",{className:"text-text-muted text-xs mt-1",children:["Subscribe this device to receive push alerts when the agent fires ",s.jsx("code",{children:"request_approval"})," from MCP. Tap action buttons in the notification to respond from anywhere."]})]}),n&&s.jsxs("div",{className:`mb-4 px-4 py-2 rounded text-sm flex items-center gap-2 ${n.kind==="ok"?"bg-success/20 text-success border border-success/40":"bg-danger/20 text-danger border border-danger/40"}`,children:[n.kind==="ok"?s.jsx(Rt,{className:"w-4 h-4"}):s.jsx(at,{className:"w-4 h-4"}),n.text]}),s.jsxs("section",{className:"bg-panel border border-border rounded-lg p-5 mb-6",children:[s.jsx("h2",{className:"text-sm text-text mb-3",children:"This device"}),v?w==="denied"?s.jsxs("div",{className:"text-danger text-sm flex items-center gap-2",children:[s.jsx(Wo,{className:"w-4 h-4"})," Notifications blocked at browser level. Enable in browser settings and refresh."]}):s.jsxs("div",{className:"flex flex-wrap gap-2 items-center",children:[s.jsxs("span",{className:"text-text-muted text-sm mr-2",children:["Status: ",j?s.jsx("span",{className:"text-success",children:"subscribed"}):s.jsx("span",{className:"text-text-dim",children:"not subscribed"})]}),j?s.jsxs(z,{variant:"default",onClick:()=>void u(),disabled:l,children:[s.jsx(Wo,{className:"w-4 h-4 mr-1"})," Unsubscribe"]}):s.jsxs(z,{variant:"primary",onClick:()=>void o(),disabled:l,children:[s.jsx(ki,{className:"w-4 h-4 mr-1"})," Subscribe this device"]}),s.jsxs(z,{variant:"default",onClick:()=>void f(),disabled:l||d.length===0,title:d.length===0?"no subscriptions to push to":"send test push to all subscribed devices",children:[s.jsx(ka,{className:"w-4 h-4 mr-1"})," Test push"]})]}):s.jsxs("div",{className:"text-warning text-sm flex items-center gap-2",children:[s.jsx(at,{className:"w-4 h-4"})," Push API not supported in this browser (try Chrome / Firefox / Edge on desktop, or Safari 16+ as PWA on iOS)."]})]}),s.jsxs("section",{children:[s.jsxs("h2",{className:"text-sm text-text mb-3",children:["All subscribed devices (",d.length,")"]}),d.length===0?s.jsx("div",{className:"bg-panel border border-dashed border-border rounded p-6 text-center text-text-muted",children:"No devices subscribed yet."}):s.jsx("div",{className:"space-y-2",children:d.map(y=>s.jsxs("div",{className:"bg-panel border border-border rounded p-3 flex items-start justify-between gap-3",children:[s.jsxs("div",{className:"text-xs flex-1 min-w-0",children:[s.jsx("div",{className:"text-text font-medium",children:y.device_label??"(unknown device)"}),s.jsxs("div",{className:"text-text-muted mt-1 font-mono break-all",children:[y.endpoint.slice(0,100),"…"]}),s.jsxs("div",{className:"text-text-dim text-[10px] mt-1",children:["added ",G(y.created_at),y.last_sent_at?` · last push ${G(y.last_sent_at)}`:"",y.last_error?` · last error: ${y.last_error.slice(0,80)}`:""]})]}),s.jsx(z,{variant:"ghost",onClick:()=>void p(y.id),disabled:l,title:"remove subscription",children:s.jsx(jr,{className:"w-3 h-3"})})]},y.id))})]})]})}const dv=3e3;function fv(){const[e,t]=g.useState(null),[n,r]=g.useState(null),[l,i]=g.useState(!1),[a,o]=g.useState(null),u=g.useCallback(async()=>{try{const d=await _x();t(d),r(null)}catch(d){r(d instanceof Error?d.message:String(d))}},[]);g.useEffect(()=>{u();const d=setInterval(()=>void u(),dv);return()=>clearInterval(d)},[u]);async function f(){i(!0);try{const d=await Ex();o({kind:d.ok?"ok":"err",text:d.ok?"sync-available broadcast sent to peers":d.error??"broadcast failed"})}catch(d){o({kind:"err",text:d instanceof Error?d.message:String(d)})}finally{i(!1)}}if(n)return s.jsxs("div",{className:"text-danger",children:["Error: ",n]});if(!e)return s.jsx("div",{className:"text-text-muted",children:"loading relay status..."});const p=e.url!==null&&e.workspace!==null;return s.jsxs("div",{className:"max-w-3xl",children:[s.jsxs("header",{className:"border-b border-border pb-3 mb-6",children:[s.jsxs("h1",{className:"text-2xl text-text flex items-center gap-2",children:[s.jsx(Od,{className:"w-6 h-6 text-accent"})," Multi-agent relay"]}),s.jsxs("p",{className:"text-text-muted text-xs mt-1",children:["Real-time fan-out across multiple machines / agents working on the same workspace. When one agent runs ",s.jsx("code",{children:"shinobi sync push"}),", all other connected agents auto-pull within ~1.5s. Backed by a Cloudflare Worker + Durable Object — see ",s.jsx("code",{children:"relay-worker/"}),"."]})]}),a&&s.jsxs("div",{className:`mb-4 px-4 py-2 rounded text-sm flex items-center gap-2 ${a.kind==="ok"?"bg-success/20 text-success border border-success/40":"bg-danger/20 text-danger border border-danger/40"}`,children:[a.kind==="ok"?s.jsx(Rt,{className:"w-4 h-4"}):s.jsx(at,{className:"w-4 h-4"}),a.text]}),p?s.jsxs(s.Fragment,{children:[s.jsxs("section",{className:"bg-panel border border-border rounded-lg p-5 mb-4",children:[s.jsxs("div",{className:"flex items-center justify-between mb-3",children:[s.jsx("h2",{className:"text-sm text-text flex items-center gap-2",children:e.connected?s.jsxs(s.Fragment,{children:[s.jsx(Qh,{className:"w-4 h-4 text-success"}),s.jsx("span",{className:"text-success",children:"Connected"})]}):s.jsxs(s.Fragment,{children:[s.jsx(Ho,{className:"w-4 h-4 text-warning"}),s.jsx("span",{className:"text-warning",children:"Disconnected"}),e.reconnect_attempts>0&&s.jsxs("span",{className:"text-text-muted text-xs",children:["— attempt #",e.reconnect_attempts]})]})}),s.jsxs(z,{variant:"default",onClick:()=>void u(),disabled:l,children:[s.jsx(ja,{className:"w-3.5 h-3.5 mr-1"})," Refresh"]})]}),s.jsxs("dl",{className:"text-sm grid grid-cols-[10rem_1fr] gap-y-1.5",children:[s.jsx("dt",{className:"text-text-muted",children:"Agent ID"}),s.jsx("dd",{className:"text-text font-mono text-xs",children:e.agent_id}),s.jsx("dt",{className:"text-text-muted",children:"Workspace"}),s.jsx("dd",{className:"text-text font-mono text-xs",children:e.workspace}),s.jsx("dt",{className:"text-text-muted",children:"Relay URL"}),s.jsx("dd",{className:"text-text font-mono text-xs break-all",children:e.url}),s.jsx("dt",{className:"text-text-muted",children:"Last event"}),s.jsx("dd",{className:"text-text text-xs",children:e.last_event_at?s.jsxs(s.Fragment,{children:[s.jsx(le,{className:"bg-accent/20 text-accent mr-2",children:e.last_event_type}),G(e.last_event_at)]}):s.jsx("span",{className:"text-text-dim",children:"none"})}),e.last_error&&s.jsxs(s.Fragment,{children:[s.jsx("dt",{className:"text-danger",children:"Last error"}),s.jsx("dd",{className:"text-danger text-xs",children:e.last_error})]})]})]}),s.jsxs("section",{className:"bg-panel border border-border rounded-lg p-5",children:[s.jsx("h2",{className:"text-sm text-text mb-2",children:"Test broadcast"}),s.jsxs("p",{className:"text-text-muted text-xs mb-3",children:["Sends a ",s.jsx("code",{children:"sync-available"})," event to every other connected agent in this workspace. They will auto-pull the latest snapshot."]}),s.jsxs(z,{variant:"primary",onClick:()=>void f(),disabled:l||!e.connected,children:[s.jsx(ka,{className:"w-4 h-4 mr-1"})," Broadcast sync-available"]})]})]}):s.jsxs("div",{className:"bg-panel border border-dashed border-border rounded-lg p-6",children:[s.jsxs("h2",{className:"text-text mb-2 flex items-center gap-2",children:[s.jsx(Ho,{className:"w-4 h-4 text-text-muted"})," Relay not configured"]}),s.jsxs("p",{className:"text-text-muted text-sm mb-3",children:["Set ",s.jsx("code",{children:"SHINOBI_RELAY_URL"}),", ",s.jsx("code",{children:"SHINOBI_RELAY_TOKEN"}),", and ",s.jsx("code",{children:"SHINOBI_RELAY_WORKSPACE"})," in Settings to enable."]}),s.jsxs("ol",{className:"text-text-muted text-sm list-decimal pl-5 space-y-1",children:[s.jsxs("li",{children:["Deploy the Worker: ",s.jsx("code",{children:"cd relay-worker && npx wrangler deploy"})]}),s.jsxs("li",{children:["Set the secret: ",s.jsx("code",{children:"npx wrangler secret put SHINOBI_RELAY_TOKEN"})]}),s.jsxs("li",{children:["Configure each agent's ",s.jsx("code",{children:"~/.shinobi/.env"})," with matching URL/token/workspace and restart the dashboard."]})]})]})]})}function pv(){const[e,t]=g.useState(null),[n,r]=g.useState(null),[l,i]=g.useState(""),[a,o]=g.useState(!1),[u,f]=g.useState(null),[p,d]=g.useState(null),[x,w]=g.useState(null),v=g.useCallback(async()=>{try{const c=await jx();t(c),r(null)}catch(c){r(c instanceof Error?c.message:String(c))}},[]);g.useEffect(()=>{v()},[v]);async function j(){if(!l.trim()){f(null);return}o(!0);try{const c=await wx(l.trim());f(c.results)}catch(c){w({kind:"err",text:c instanceof Error?c.message:String(c)})}finally{o(!1)}}async function y(c){d(c);try{const h=await kx(c);w({kind:h.ok?"ok":"err",text:h.ok?`installed ${c} — restart dashboard to load tools`:(h.stderr||"install failed").slice(0,200)}),await v(),u&&await j()}catch(h){w({kind:"err",text:h instanceof Error?h.message:String(h)})}finally{d(null)}}async function m(c){d(c);try{const h=await Nx(c);w({kind:h.ok?"ok":"err",text:h.ok?`uninstalled ${c} — restart dashboard to drop tools`:(h.stderr||"uninstall failed").slice(0,200)}),await v(),u&&await j()}catch(h){w({kind:"err",text:h instanceof Error?h.message:String(h)})}finally{d(null)}}return n?s.jsxs("div",{className:"text-danger",children:["Error: ",n]}):e?s.jsxs("div",{className:"max-w-4xl",children:[s.jsxs("header",{className:"border-b border-border pb-3 mb-6",children:[s.jsxs("h1",{className:"text-2xl text-text flex items-center gap-2",children:[s.jsx(Rd,{className:"w-6 h-6 text-accent"})," Plugins"]}),s.jsxs("p",{className:"text-text-muted text-xs mt-1",children:["Extend Shinobi with community-maintained packages from npm. Install location: ",s.jsx("code",{children:e.install_prefix})]})]}),x&&s.jsxs("div",{className:`mb-4 px-4 py-2 rounded text-sm flex items-center gap-2 ${x.kind==="ok"?"bg-success/20 text-success border border-success/40":"bg-danger/20 text-danger border border-danger/40"}`,children:[x.kind==="ok"?s.jsx(Rt,{className:"w-4 h-4"}):s.jsx(at,{className:"w-4 h-4"}),x.text]}),s.jsxs("section",{className:"bg-panel border border-border rounded-lg p-5 mb-6",children:[s.jsx("h2",{className:"text-sm text-text mb-3",children:"Search npm registry"}),s.jsxs("div",{className:"flex gap-2 mb-3",children:[s.jsx("input",{type:"text",className:"flex-1 bg-bg border border-border rounded px-3 py-1.5 text-sm text-text",placeholder:"e.g. github, jira, time-tracking (looks under @shinobi/plugin-* and shinobi-plugin-*)",value:l,onChange:c=>i(c.target.value),onKeyDown:c=>{c.key==="Enter"&&j()}}),s.jsxs(z,{variant:"primary",onClick:()=>void j(),disabled:a,children:[s.jsx(wa,{className:"w-4 h-4 mr-1"})," Search"]})]}),u!==null&&(u.length===0?s.jsx("div",{className:"text-text-muted text-sm",children:"no matching plugins published yet"}):s.jsx("div",{className:"space-y-2",children:u.map(c=>s.jsxs("div",{className:"bg-bg border border-border rounded p-3 flex items-start justify-between gap-3",children:[s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsxs("div",{className:"flex items-baseline gap-2",children:[s.jsx("div",{className:"text-text font-medium",children:c.name}),s.jsxs("div",{className:"text-text-muted text-xs",children:["v",c.version,c.author?" · "+c.author:""]}),c.links.npm&&s.jsxs("a",{href:c.links.npm,target:"_blank",rel:"noreferrer",className:"text-accent text-xs hover:underline",children:["npm ",s.jsx(Ph,{className:"w-3 h-3 inline"})]})]}),s.jsx("div",{className:"text-text-muted text-xs mt-1",children:c.description||"(no description)"})]}),c.installed?s.jsxs(z,{variant:"default",onClick:()=>void m(c.name),disabled:p===c.name,children:[s.jsx(jr,{className:"w-3.5 h-3.5 mr-1"})," Uninstall"]}):s.jsxs(z,{variant:"primary",onClick:()=>void y(c.name),disabled:p===c.name,children:[s.jsx(Ch,{className:"w-3.5 h-3.5 mr-1"})," ",p===c.name?"installing…":"Install"]})]},c.name))}))]}),s.jsxs("section",{className:"mb-6",children:[s.jsxs("div",{className:"flex items-baseline justify-between mb-3",children:[s.jsxs("h2",{className:"text-sm text-text",children:["Installed (",e.installed.length,")"]}),s.jsxs("button",{onClick:()=>void v(),className:"text-[11px] uppercase tracking-wider text-accent hover:underline",children:[s.jsx(ja,{className:"w-3 h-3 inline mr-0.5"})," refresh"]})]}),e.installed.length===0?s.jsx("div",{className:"text-text-muted text-sm",children:"(no plugins installed yet)"}):s.jsx("div",{className:"space-y-2",children:e.installed.map(c=>s.jsxs("div",{className:"bg-panel border border-border rounded p-3 flex items-center justify-between gap-3",children:[s.jsxs("div",{children:[s.jsxs("div",{className:"text-text font-medium",children:[c.name," ",s.jsxs("span",{className:"text-text-muted text-xs",children:["v",c.version]})]}),s.jsx("div",{className:"text-text-muted text-xs",children:c.description})]}),s.jsx(z,{variant:"ghost",onClick:()=>void m(c.name),disabled:p===c.name,title:"uninstall",children:s.jsx(jr,{className:"w-3.5 h-3.5"})})]},c.name))})]}),s.jsxs("section",{children:[s.jsxs("h2",{className:"text-sm text-text mb-3",children:["Loaded at last startup (",e.loaded.length,")"]}),e.loaded.length===0?s.jsx("div",{className:"text-text-muted text-sm",children:"(none yet — install + restart dashboard)"}):s.jsx("div",{className:"space-y-2",children:e.loaded.map(c=>s.jsxs("div",{className:"bg-panel border border-border rounded p-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsx("div",{className:"text-text font-medium",children:c.name}),s.jsx(le,{className:c.source==="user"?"bg-warning/30 text-warning":"bg-accent/30 text-accent",children:c.source})]}),s.jsx("div",{className:"text-text-muted text-xs font-mono break-all mt-1",children:c.module_path}),c.tools_registered.length>0&&s.jsxs("div",{className:"text-text-dim text-[11px] mt-2",children:["tools: ",c.tools_registered.join(", ")]}),c.error&&s.jsxs("div",{className:"text-danger text-xs mt-2",children:["error: ",c.error]})]},c.name))})]})]}):s.jsx("div",{className:"text-text-muted",children:"loading plugins..."})}function mv(){const[e,t]=g.useState(null),[n,r]=g.useState(null),[l,i]=g.useState(!1),[a,o]=g.useState(null),u=g.useCallback(async()=>{try{t(await Sx()),r(null)}catch(p){r(p instanceof Error?p.message:String(p))}},[]);g.useEffect(()=>{u()},[u]);async function f(){i(!0);try{const p=await bx();p.ok?o({kind:"ok",text:`sent ${p.sent}/${p.attempted} events to ${p.endpoint}`}):o({kind:"err",text:p.error??"flush failed"}),await u()}catch(p){o({kind:"err",text:p instanceof Error?p.message:String(p)})}finally{i(!1)}}return n?s.jsxs("div",{className:"text-danger",children:["Error: ",n]}):e?s.jsxs("div",{className:"max-w-3xl",children:[s.jsxs("header",{className:"border-b border-border pb-3 mb-6",children:[s.jsxs("h1",{className:"text-2xl text-text flex items-center gap-2",children:[s.jsx(Ld,{className:"w-6 h-6 text-accent"})," Telemetry"]}),s.jsx("p",{className:"text-text-muted text-xs mt-1",children:"Anonymous, opt-in usage stats. Everything below stays in your local SQLite buffer until you flush it to an endpoint. No project content, task titles, decision bodies, prompts, or usernames are ever recorded."})]}),a&&s.jsxs("div",{className:`mb-4 px-4 py-2 rounded text-sm flex items-center gap-2 ${a.kind==="ok"?"bg-success/20 text-success border border-success/40":"bg-danger/20 text-danger border border-danger/40"}`,children:[a.kind==="ok"?s.jsx(Rt,{className:"w-4 h-4"}):s.jsx(at,{className:"w-4 h-4"}),a.text]}),s.jsxs("section",{className:"bg-panel border border-border rounded-lg p-5 mb-6",children:[s.jsx("h2",{className:"text-sm text-text mb-3",children:"Status"}),s.jsxs("dl",{className:"text-sm grid grid-cols-[12rem_1fr] gap-y-1.5",children:[s.jsx("dt",{className:"text-text-muted",children:"Recording"}),s.jsx("dd",{className:e.enabled?"text-success":"text-text-dim",children:e.enabled?"ON (SHINOBI_TELEMETRY=on)":"OFF (default)"}),s.jsx("dt",{className:"text-text-muted",children:"Endpoint"}),s.jsx("dd",{className:"text-text",children:e.endpoint_configured?"configured":s.jsx("span",{className:"text-text-dim",children:"local-only (no SHINOBI_TELEMETRY_ENDPOINT)"})}),s.jsx("dt",{className:"text-text-muted",children:"Total events"}),s.jsx("dd",{className:"text-text",children:e.total_events.toLocaleString()}),s.jsx("dt",{className:"text-text-muted",children:"Unsent"}),s.jsx("dd",{className:"text-text",children:e.unsent_events.toLocaleString()}),s.jsx("dt",{className:"text-text-muted",children:"Events last 7d"}),s.jsx("dd",{className:"text-text",children:e.last_7d_count.toLocaleString()}),s.jsx("dt",{className:"text-text-muted",children:"Last recorded"}),s.jsx("dd",{className:"text-text-muted text-xs",children:e.last_recorded_at?`${G(e.last_recorded_at)} ago`:"never"}),s.jsx("dt",{className:"text-text-muted",children:"Last sent"}),s.jsx("dd",{className:"text-text-muted text-xs",children:e.last_sent_at?`${G(e.last_sent_at)} ago`:"never"})]}),s.jsxs("div",{className:"mt-4 flex gap-2",children:[s.jsxs(z,{variant:"default",onClick:()=>void u(),children:[s.jsx(ja,{className:"w-3.5 h-3.5 mr-1"})," Refresh"]}),s.jsxs(z,{variant:"primary",onClick:()=>void f(),disabled:l||!e.endpoint_configured||e.unsent_events===0,children:[s.jsx(ka,{className:"w-3.5 h-3.5 mr-1"})," Flush unsent"]})]})]}),s.jsxs("section",{className:"mb-6",children:[s.jsx("h2",{className:"text-sm text-text mb-3",children:"Counts by event type (top 30)"}),e.by_event_type.length===0?s.jsxs("div",{className:"text-text-muted text-sm",children:["(no events recorded yet",!e.enabled&&s.jsxs(s.Fragment,{children:[" — enable in ",s.jsx(X,{to:"/settings",className:"text-accent hover:underline",children:"Settings"})," and restart the dashboard)"]})]}):s.jsxs("table",{className:"w-full text-sm",children:[s.jsx("thead",{children:s.jsxs("tr",{className:"text-[11px] uppercase tracking-wider text-text-muted text-left",children:[s.jsx("th",{className:"pb-2 pr-3",children:"Event type"}),s.jsx("th",{className:"pb-2 text-right",children:"Count"})]})}),s.jsx("tbody",{children:e.by_event_type.map(p=>s.jsxs("tr",{className:"border-b border-border/40",children:[s.jsx("td",{className:"py-1.5 pr-3 text-text font-mono text-xs",children:p.event_type}),s.jsx("td",{className:"py-1.5 text-text text-right",children:p.count.toLocaleString()})]},p.event_type))})]})]}),s.jsxs("section",{className:"text-text-muted text-xs",children:[s.jsx("h2",{className:"text-text text-sm mb-2",children:"What is recorded"}),s.jsxs("ul",{className:"list-disc pl-5 space-y-1",children:[s.jsxs("li",{children:[s.jsx("code",{children:"tool_called"})," — MCP tool name + ok flag"]}),s.jsxs("li",{children:[s.jsx("code",{children:"view_hit"})," — dashboard route bucket (e.g. ",s.jsx("code",{children:"/projects/:tab"}),") + HTTP status. Project IDs are stripped."]})]}),s.jsx("h2",{className:"text-text text-sm mt-4 mb-2",children:"What is NEVER recorded"}),s.jsxs("ul",{className:"list-disc pl-5 space-y-1",children:[s.jsx("li",{children:"Project titles, task titles, decision bodies, notes, plans, prompts, model output, code snippets, file paths."}),s.jsx("li",{children:"IP addresses, usernames, machine IDs."}),s.jsxs("li",{children:["The contents of ",s.jsx("code",{children:"~/.shinobi/.env"}),", API keys, or any setting value."]})]})]})]}):s.jsx("div",{className:"text-text-muted",children:"loading telemetry..."})}function hv(){return s.jsxs("div",{className:"text-center py-16",children:[s.jsx("div",{className:"text-6xl mb-4",children:"🥷"}),s.jsx("h1",{className:"text-2xl text-text mb-2",children:"Not found"}),s.jsx("p",{className:"text-text-muted mb-4",children:"The page you're looking for doesn't exist."}),s.jsx(X,{to:"/",className:"text-accent hover:underline",children:"← Back to home"})]})}function xv(){return s.jsx(ph,{children:s.jsx(lh,{children:s.jsxs(V,{element:s.jsx(Mx,{}),children:[s.jsx(V,{path:"/",element:s.jsx(Ox,{})}),s.jsx(V,{path:"/settings",element:s.jsx(ev,{})}),s.jsx(V,{path:"/voice",element:s.jsx(iv,{})}),s.jsx(V,{path:"/approvals",element:s.jsx(ov,{})}),s.jsx(V,{path:"/push",element:s.jsx(cv,{})}),s.jsx(V,{path:"/relay",element:s.jsx(fv,{})}),s.jsx(V,{path:"/plugins",element:s.jsx(pv,{})}),s.jsx(V,{path:"/telemetry",element:s.jsx(mv,{})}),s.jsx(V,{path:"/sessions",element:s.jsx(Jx,{})}),s.jsx(V,{path:"/sessions/:sessionId",element:s.jsx(qx,{})}),s.jsxs(V,{path:"/projects/:id",element:s.jsx(Ix,{}),children:[s.jsx(V,{index:!0,element:s.jsx(Dx,{})}),s.jsx(V,{path:"subtasks",element:s.jsx(Fx,{})}),s.jsx(V,{path:"decisions",element:s.jsx(Bx,{})}),s.jsx(V,{path:"decision-drafts",element:s.jsx(Vx,{})}),s.jsx(V,{path:"dead-ends",element:s.jsx(Wx,{})}),s.jsx(V,{path:"notes",element:s.jsx(Hx,{})}),s.jsx(V,{path:"plans",element:s.jsx(Qx,{})}),s.jsx(V,{path:"context",element:s.jsx(Kx,{})}),s.jsx(V,{path:"sessions",element:s.jsx(Xx,{})}),s.jsx(V,{path:"timeline",element:s.jsx(Yx,{})}),s.jsx(V,{path:"analytics",element:s.jsx(Gx,{})})]}),s.jsx(V,{path:"*",element:s.jsx(hv,{})})]})})})}md(document.getElementById("root")).render(s.jsx(g.StrictMode,{children:s.jsx(xv,{})}));
288
- //# sourceMappingURL=index-BiTX3zpZ.js.map
287
+ */const Kh=R("X",[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]]);function zd(e){var t,n,r="";if(typeof e=="string"||typeof e=="number")r+=e;else if(typeof e=="object")if(Array.isArray(e)){var l=e.length;for(t=0;t<l;t++)e[t]&&(n=zd(e[t]))&&(r&&(r+=" "),r+=n)}else for(n in e)e[n]&&(r&&(r+=" "),r+=n);return r}function _e(){for(var e,t,n=0,r="",l=arguments.length;n<l;n++)(e=arguments[n])&&(t=zd(e))&&(r&&(r+=" "),r+=t);return r}function G(e){if(!e)return"";const t=new Date(e.replace(" ","T")+(e.includes("T")||e.includes("Z")?"":"Z"));if(isNaN(t.getTime()))return e;const n=Math.max(0,(Date.now()-t.getTime())/1e3);if(n<60)return`${Math.floor(n)}s ago`;const r=n/60;if(r<60)return`${Math.floor(r)}m ago`;const l=r/60;if(l<24)return`${Math.floor(l)}h ago`;const i=l/24;if(i<30)return`${Math.floor(i)}d ago`;const a=i/30;return a<12?`${Math.floor(a)}mo ago`:`${Math.floor(a/12)}y ago`}function Yh(e){return e?e.toLowerCase().replace(/[^a-z0-9]+/g,"-"):"none"}function Gh(e){switch(Yh(e)){case"shinobi":return"bg-ws-shinobi text-white";case"shinobiapps":return"bg-ws-shinobiapps text-bg";case"sitesnap":return"bg-ws-sitesnap text-bg";default:return"bg-border-2 text-text-muted italic"}}function Na({workspace:e}){return s.jsx("span",{className:_e("inline-block rounded text-[10px] font-medium lowercase tracking-wider px-1.5 py-0.5",Gh(e)),children:e??"(no workspace)"})}const Xh={default:"bg-border-2 border-border text-text hover:bg-border",primary:"bg-accent-2 border-accent-2 text-white hover:bg-accent-3",ghost:"bg-transparent border-transparent text-text-muted hover:text-text hover:bg-panel",danger:"bg-danger border-danger text-white hover:opacity-90"},Jh={sm:"text-xs px-2 py-1",md:"text-sm px-3 py-1.5"},z=g.forwardRef(({variant:e="default",size:t="md",className:n,...r},l)=>s.jsx("button",{ref:l,className:_e("border rounded transition-colors font-medium cursor-pointer disabled:opacity-50 disabled:cursor-wait",Xh[e],Jh[t],n),...r}));z.displayName="Button";async function $(e,t){const n=await fetch(e,{...t,headers:{"Content-Type":"application/json",...(t==null?void 0:t.headers)??{}}});if(!n.ok){const r=await n.text();throw new Error(`${(t==null?void 0:t.method)??"GET"} ${e} → ${n.status}: ${r.slice(0,200)}`)}return await n.json()}function Id(e){const t=new URLSearchParams;e!=null&&e.sort&&t.set("sort",e.sort),e!=null&&e.include_archived&&t.set("include_archived","true");const n=t.toString();return $(`/api/projects${n?`?${n}`:""}`)}function qh(e){return $(`/api/projects/${e}/snapshot`)}function Zh(e,t=8){const n=new URLSearchParams({q:e,limit:String(t)});return $(`/api/recall?${n.toString()}`)}function ex(e,t){return $(`/api/subtasks/${e}`,{method:"PATCH",body:JSON.stringify(t)})}function tx(e,t){return $(`/api/decisions/${e}/status`,{method:"PATCH",body:JSON.stringify({status:t})})}function nx(e){return $(`/api/projects/${e}/decision-drafts`)}function rx(e){return $(`/api/decision-drafts/${e}/approve`,{method:"POST",body:"{}"})}function sx(e){return $(`/api/decision-drafts/${e}/reject`,{method:"POST",body:"{}"})}function lx(e=200){return $(`/api/sessions?limit=${e}`)}function ix(e){return $(`/api/sessions/${encodeURIComponent(e)}`)}function ax(){return $("/api/settings")}function ox(e){return $("/api/settings",{method:"POST",body:JSON.stringify({patch:e})})}function ux(){return $("/api/push/vapid-key")}function cx(){return $("/api/push/subscriptions")}function dx(e){return $("/api/push/subscribe",{method:"POST",body:JSON.stringify(e)})}function Qo(e){return $(`/api/push/subscriptions/${e}`,{method:"DELETE"})}function fx(){return $("/api/push/test",{method:"POST"})}function px(e){return $("/api/approvals")}function mx(e,t,n){return $(`/api/approvals/${e}/respond`,{method:"POST",body:JSON.stringify({value:t,note:n})})}function hx(e){return $(`/api/approvals/${e}/cancel`,{method:"POST",body:"{}"})}function xx(){return $("/api/sync/status")}function vx(){return $("/api/sync/push",{method:"POST"})}function gx(){return $("/api/sync/pull",{method:"POST"})}function Ko(e){return $(`/api/projects/${e}/time-stats`)}function Yo(e){return $(`/api/projects/${e}/cost-stats`)}function yx(e={}){return $("/api/cost/ingest",{method:"POST",body:JSON.stringify(e)})}function jx(){return $("/api/plugins")}function wx(e){return $("/api/plugins/search",{method:"POST",body:JSON.stringify({query:e})})}function kx(e){return $("/api/plugins/install",{method:"POST",body:JSON.stringify({pkg:e})})}function Nx(e){return $(`/api/plugins/${encodeURIComponent(e)}`,{method:"DELETE"})}function Sx(){return $("/api/telemetry/summary")}function bx(){return $("/api/telemetry/flush",{method:"POST",body:"{}"})}function _x(){return $("/api/relay/status")}function Ex(){return $("/api/relay/broadcast-sync",{method:"POST",body:"{}"})}function Cx(){const[e,t]=g.useState(null),[n,r]=g.useState({kind:"idle"});g.useEffect(()=>{l()},[]);async function l(){try{t(await xx())}catch(o){r({kind:"err",message:o instanceof Error?o.message:String(o)})}}async function i(o){if(!(o==="pull"&&!window.confirm("Pull overwrites the local DB with the latest snapshot from the sync repo. Continue?"))){r({kind:"busy",op:o});try{const u=o==="push"?await vx():await gx();if(!u.ok)throw new Error(u.error??"unknown error");r({kind:"ok",op:o,elapsedMs:u.elapsed_ms??0}),await l(),o==="pull"&&setTimeout(()=>location.reload(),500)}catch(u){r({kind:"err",message:u instanceof Error?u.message:String(u)})}}}const a=e==null?void 0:e.sync;return s.jsxs("div",{className:"bg-panel border border-border rounded-md p-3 mt-4",children:[s.jsx("div",{className:"text-[11px] uppercase tracking-wider text-text-muted mb-2",children:"Sync"}),s.jsxs("div",{className:"space-y-1 text-xs font-mono",children:[e!=null&&e.configured&&a?s.jsxs(s.Fragment,{children:[s.jsxs("div",{children:["push: ",s.jsx("span",{className:a.last_push_at?"text-success":"text-text-muted",children:G(a.last_push_at)||"never"})]}),s.jsxs("div",{children:["pull: ",s.jsx("span",{className:a.last_pull_at?"text-success":"text-text-muted",children:G(a.last_pull_at)||"never"})]}),s.jsxs("div",{className:"text-text-dim text-[10px] break-all",children:[a.repo_path,s.jsx("br",{}),"(branch: ",a.branch,")"]})]}):s.jsx("div",{className:"text-text-muted",children:"not configured"}),n.kind==="ok"&&s.jsxs("div",{className:"text-success",children:[n.op," OK (",n.elapsedMs,"ms)"]}),n.kind==="err"&&s.jsx("div",{className:"text-danger break-all",children:n.message})]}),s.jsxs("div",{className:"flex gap-1.5 mt-3",children:[s.jsxs(z,{size:"sm",variant:"default",className:"flex-1 flex items-center justify-center gap-1",disabled:n.kind==="busy",onClick:()=>void i("pull"),children:[n.kind==="busy"&&n.op==="pull"?s.jsx(Yt,{className:"w-3 h-3 animate-spin"}):s.jsx(Nh,{className:"w-3 h-3"}),"Pull"]}),s.jsxs(z,{size:"sm",variant:"primary",className:"flex-1 flex items-center justify-center gap-1",disabled:n.kind==="busy",onClick:()=>void i("push"),children:[n.kind==="busy"&&n.op==="push"?s.jsx(Yt,{className:"w-3 h-3 animate-spin"}):s.jsx(Sh,{className:"w-3 h-3"}),"Push"]})]})]})}function Go({projects:e}){const t=Jt(),n=ya(),r=n.id?Number(n.id):null,l=e.filter(p=>!p.archived_at),i=e.filter(p=>p.archived_at),a=new Map;for(const p of l){const d=p.workspace??"(no workspace)";a.has(d)||a.set(d,[]),a.get(d).push(p)}const[o,u]=g.useState(!1);g.useEffect(()=>{u(/Mac|iPhone|iPad/.test(navigator.platform??navigator.userAgent))},[]);const f=o?"⌘":"Ctrl";return s.jsxs("aside",{className:"bg-panel-2 border-r border-border w-64 flex-shrink-0 overflow-y-auto scrollbar-thin p-4",children:[s.jsx(X,{to:"/",className:"block text-lg font-bold tracking-wider mb-4 text-text",children:"Shinobi 🥷"}),s.jsxs("button",{onClick:()=>window.dispatchEvent(new CustomEvent("cmd-palette:open")),className:"w-full flex items-center gap-2 px-2 py-1.5 mb-4 rounded text-sm bg-panel border border-border text-text-muted hover:text-text hover:border-accent/60 transition-colors",children:[s.jsx(wa,{className:"w-3.5 h-3.5"}),s.jsx("span",{className:"flex-1 text-left",children:"Search..."}),s.jsxs("kbd",{className:"text-[10px] border border-border rounded px-1 py-0.5",children:[f," K"]})]}),s.jsx("div",{className:"text-[11px] uppercase tracking-wider text-text-muted mb-2",children:"Workspace"}),s.jsxs("ul",{className:"mb-4",children:[s.jsx("li",{children:s.jsx(X,{to:"/sessions",className:_e("block px-2 py-1.5 rounded text-sm transition-colors",t.pathname==="/sessions"?"bg-border text-text":"text-text hover:bg-panel"),children:"All sessions"})}),s.jsx("li",{children:s.jsxs(X,{to:"/voice",className:_e("flex items-center gap-2 px-2 py-1.5 rounded text-sm transition-colors",t.pathname==="/voice"?"bg-border text-text":"text-text hover:bg-panel"),children:[s.jsx(Ni,{className:"w-3.5 h-3.5"})," Voice capture"]})}),s.jsx("li",{children:s.jsxs(X,{to:"/approvals",className:_e("flex items-center gap-2 px-2 py-1.5 rounded text-sm transition-colors",t.pathname==="/approvals"?"bg-border text-text":"text-text hover:bg-panel"),children:[s.jsx(Ah,{className:"w-3.5 h-3.5"})," Approvals"]})}),s.jsx("li",{children:s.jsxs(X,{to:"/push",className:_e("flex items-center gap-2 px-2 py-1.5 rounded text-sm transition-colors",t.pathname==="/push"?"bg-border text-text":"text-text hover:bg-panel"),children:[s.jsx(ki,{className:"w-3.5 h-3.5"})," Push"]})}),s.jsx("li",{children:s.jsxs(X,{to:"/relay",className:_e("flex items-center gap-2 px-2 py-1.5 rounded text-sm transition-colors",t.pathname==="/relay"?"bg-border text-text":"text-text hover:bg-panel"),children:[s.jsx(Od,{className:"w-3.5 h-3.5"})," Relay"]})}),s.jsx("li",{children:s.jsxs(X,{to:"/plugins",className:_e("flex items-center gap-2 px-2 py-1.5 rounded text-sm transition-colors",t.pathname==="/plugins"?"bg-border text-text":"text-text hover:bg-panel"),children:[s.jsx(Rd,{className:"w-3.5 h-3.5"})," Plugins"]})}),s.jsx("li",{children:s.jsxs(X,{to:"/telemetry",className:_e("flex items-center gap-2 px-2 py-1.5 rounded text-sm transition-colors",t.pathname==="/telemetry"?"bg-border text-text":"text-text hover:bg-panel"),children:[s.jsx(Ld,{className:"w-3.5 h-3.5"})," Telemetry"]})}),s.jsx("li",{children:s.jsxs(X,{to:"/settings",className:_e("flex items-center gap-2 px-2 py-1.5 rounded text-sm transition-colors",t.pathname==="/settings"?"bg-border text-text":"text-text hover:bg-panel"),children:[s.jsx(Dh,{className:"w-3.5 h-3.5"})," Settings"]})})]}),s.jsx("div",{className:"text-[11px] uppercase tracking-wider text-text-muted mb-2",children:"Projects"}),a.size===0?s.jsx("div",{className:"text-text-muted text-sm italic",children:"(none)"}):[...a.entries()].map(([p,d])=>s.jsxs("div",{className:"mb-3",children:[s.jsxs("div",{className:"flex items-center gap-1.5 mt-3 mb-1 text-[10px] uppercase tracking-wider text-text-muted",children:[s.jsx(Na,{workspace:p==="(no workspace)"?null:p}),s.jsx("span",{children:d.length})]}),s.jsx("ul",{children:d.map(x=>s.jsx("li",{children:s.jsx(X,{to:`/projects/${x.id}`,className:_e("block px-2 py-1.5 rounded text-sm transition-colors",r===x.id?"bg-border text-text":"text-text hover:bg-panel"),children:x.title})},x.id))})]},p)),i.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"text-[11px] uppercase tracking-wider text-text-muted mt-4 mb-2 flex items-center gap-1.5",children:[s.jsx(Md,{className:"w-3 h-3"}),"Archived"]}),s.jsx("ul",{children:i.map(p=>s.jsx("li",{children:s.jsx(X,{to:`/projects/${p.id}`,className:"block px-2 py-1.5 rounded text-sm text-text-dim hover:bg-panel",children:p.title})},p.id))})]}),s.jsx(Cx,{})]})}const Px={project:{label:"Projects",icon:Lh},subtask:{label:"Tasks",icon:Rh},decision:{label:"Decisions",icon:Mh},dead_end:{label:"Dead ends",icon:Bh},note:{label:"Notes",icon:Th}};function Tx(e){const t=[];for(const n of e.projects)t.push({kind:"project",id:n.id,title:n.title,subtitle:n.workspace?`workspace: ${n.workspace}`:"no workspace",projectId:n.id,href:`/projects/${n.id}`});for(const n of e.subtasks)t.push({kind:"subtask",id:n.id,title:n.title,subtitle:`task #${n.id} · status: ${n.status}`,projectId:n.project_id,href:`/projects/${n.project_id}`});for(const n of e.decisions)t.push({kind:"decision",id:n.id,title:n.summary,subtitle:`decision #${n.id} · ${n.kind}`,projectId:n.project_id,href:`/projects/${n.project_id}/decisions`});for(const n of e.dead_ends)t.push({kind:"dead_end",id:n.id,title:n.attempted_approach.slice(0,100),subtitle:`dead end #${n.id}${n.never_retry?" · never retry":""}`,projectId:n.project_id,href:`/projects/${n.project_id}/dead-ends`});for(const n of e.notes)t.push({kind:"note",id:n.id,title:n.body.slice(0,100),subtitle:`note #${n.id}`,projectId:n.project_id,href:`/projects/${n.project_id}/notes`});return t}function Lx({open:e,onClose:t}){const n=Nd(),[r,l]=g.useState(""),[i,a]=g.useState(null),[o,u]=g.useState(!1),[f,p]=g.useState(0),d=g.useRef(null),x=g.useRef(null);g.useEffect(()=>{e&&(l(""),a(null),p(0),setTimeout(()=>{var j;return(j=d.current)==null?void 0:j.focus()},0))},[e]),g.useEffect(()=>{if(!e)return;const j=r.trim();if(j.length<2){a(null),u(!1);return}u(!0);const y=setTimeout(()=>{Zh(j,6).then(m=>{a(m),p(0)}).catch(()=>a(null)).finally(()=>u(!1))},150);return()=>clearTimeout(y)},[r,e]);const w=g.useMemo(()=>i?Tx(i):[],[i]);if(g.useEffect(()=>{if(!e)return;function j(y){if(y.key==="Escape")y.preventDefault(),t();else if(y.key==="ArrowDown")y.preventDefault(),p(m=>Math.min(m+1,w.length-1));else if(y.key==="ArrowUp")y.preventDefault(),p(m=>Math.max(m-1,0));else if(y.key==="Enter"){const m=w[f];m&&(y.preventDefault(),n(m.href),t())}}return window.addEventListener("keydown",j),()=>window.removeEventListener("keydown",j)},[e,w,f,n,t]),g.useEffect(()=>{var y;const j=(y=x.current)==null?void 0:y.querySelector(`[data-cmd-idx="${f}"]`);j==null||j.scrollIntoView({block:"nearest"})},[f]),!e)return null;const v=["project","subtask","decision","dead_end","note"].map(j=>({kind:j,items:w.filter(y=>y.kind===j)})).filter(j=>j.items.length>0);return pd.createPortal(s.jsxs("div",{className:"fixed inset-0 z-[100] flex items-start justify-center pt-20 px-4",onClick:t,children:[s.jsx("div",{className:"fixed inset-0 bg-black/60 backdrop-blur-sm","aria-hidden":!0}),s.jsxs("div",{className:"relative w-full max-w-2xl bg-panel border border-border rounded-lg shadow-2xl overflow-hidden",onClick:j=>j.stopPropagation(),children:[s.jsxs("div",{className:"flex items-center gap-3 px-4 py-3 border-b border-border",children:[s.jsx(wa,{className:"w-4 h-4 text-text-muted"}),s.jsx("input",{ref:d,type:"text",value:r,onChange:j=>l(j.target.value),placeholder:"Search projects, tasks, decisions, dead ends, notes...",className:"flex-1 bg-transparent text-text placeholder:text-text-dim outline-none text-sm"}),s.jsx("kbd",{className:"text-[10px] text-text-dim border border-border rounded px-1.5 py-0.5",children:"esc"})]}),s.jsx("div",{ref:x,className:"max-h-[60vh] overflow-y-auto",children:r.trim().length<2?s.jsx("div",{className:"px-4 py-6 text-center text-text-dim text-sm",children:"Type at least 2 characters to search."}):o&&w.length===0?s.jsx("div",{className:"px-4 py-6 text-center text-text-muted text-sm",children:"Searching..."}):w.length===0?s.jsxs("div",{className:"px-4 py-6 text-center text-text-muted text-sm",children:['No matches for "',r,'".']}):v.map(j=>{const y=Px[j.kind],m=y.icon;return s.jsxs("div",{className:"py-1",children:[s.jsxs("div",{className:"px-4 py-1.5 text-[10px] uppercase tracking-wider text-text-dim flex items-center gap-1.5",children:[s.jsx(m,{className:"w-3 h-3"}),y.label,s.jsxs("span",{className:"text-text-dim",children:["· ",j.items.length]})]}),j.items.map(c=>{const h=w.indexOf(c),k=h===f;return s.jsxs("button",{"data-cmd-idx":h,onMouseEnter:()=>p(h),onClick:()=>{n(c.href),t()},className:`w-full text-left px-4 py-2 flex flex-col gap-0.5 border-l-2 ${k?"bg-panel-2 border-accent":"border-transparent hover:bg-panel-2/60"}`,children:[s.jsx("span",{className:"text-sm text-text truncate",children:c.title}),s.jsx("span",{className:"text-[11px] text-text-muted truncate",children:c.subtitle})]},`${c.kind}-${c.id}`)})]},j.kind)})}),s.jsxs("div",{className:"px-4 py-2 border-t border-border text-[10px] text-text-dim flex items-center justify-between",children:[s.jsxs("span",{className:"flex items-center gap-3",children:[s.jsxs("span",{children:[s.jsx("kbd",{className:"border border-border rounded px-1 py-0.5",children:"↑"})," ",s.jsx("kbd",{className:"border border-border rounded px-1 py-0.5",children:"↓"})," navigate"]}),s.jsxs("span",{children:[s.jsx("kbd",{className:"border border-border rounded px-1 py-0.5",children:"↵"})," open"]}),s.jsxs("span",{children:[s.jsx("kbd",{className:"border border-border rounded px-1 py-0.5",children:"esc"})," close"]})]}),i&&s.jsxs("span",{children:[w.length," ",w.length===1?"result":"results"]})]})]})]}),document.body)}function Mx(){const[e,t]=g.useState(null),[n,r]=g.useState(null),[l,i]=g.useState(!1),[a,o]=g.useState(!1),u=Jt();return g.useEffect(()=>{i(!1)},[u.pathname]),g.useEffect(()=>{function f(d){(d.metaKey||d.ctrlKey)&&d.key.toLowerCase()==="k"&&(d.preventDefault(),o(w=>!w))}function p(){o(!0)}return window.addEventListener("keydown",f),window.addEventListener("cmd-palette:open",p),()=>{window.removeEventListener("keydown",f),window.removeEventListener("cmd-palette:open",p)}},[]),g.useEffect(()=>{let f=!1;return Id({sort:"active",include_archived:!0}).then(p=>{f||t(p)}).catch(p=>{f||r(p instanceof Error?p.message:String(p))}),()=>{f=!0}},[]),n?s.jsx("div",{className:"min-h-screen flex items-center justify-center text-danger",children:s.jsxs("div",{children:[s.jsx("h1",{className:"text-xl mb-2",children:"Failed to load projects"}),s.jsx("pre",{className:"text-sm",children:n})]})}):e?s.jsxs("div",{className:"min-h-screen flex",children:[s.jsx("div",{className:"hidden md:block",children:s.jsx(Go,{projects:e})}),l&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"md:hidden fixed inset-0 bg-black/50 z-40",onClick:()=>i(!1)}),s.jsx("div",{className:"md:hidden fixed inset-y-0 left-0 z-50 shadow-2xl",children:s.jsx(Go,{projects:e})})]}),s.jsxs("main",{className:"flex-1 overflow-y-auto min-w-0",children:[s.jsxs("div",{className:"md:hidden sticky top-0 z-30 bg-bg/95 backdrop-blur border-b border-border px-4 py-3 flex items-center gap-3",children:[s.jsx("button",{onClick:()=>i(f=>!f),className:"text-text hover:text-accent","aria-label":l?"Close menu":"Open menu",children:l?s.jsx(Kh,{className:"w-5 h-5"}):s.jsx(Oh,{className:"w-5 h-5"})}),s.jsx("span",{className:"text-text font-semibold tracking-wider",children:"Shinobi 🥷"})]}),s.jsx("div",{className:"p-4 md:p-8",children:s.jsx(Cd,{context:{projects:e}})})]}),s.jsx(Lx,{open:a,onClose:()=>o(!1)})]}):s.jsx("div",{className:"min-h-screen flex items-center justify-center text-text-muted",children:"loading..."})}const Rx={default:"bg-border-2 text-text","status-todo":"bg-border text-text","status-in_progress":"bg-accent-2 text-white","status-done":"bg-text-dim text-text","priority-urgent":"bg-danger text-white","priority-high":"bg-orange text-bg","priority-medium":"bg-warning text-bg","priority-low":"bg-text-dim text-text-muted"};function le({children:e,variant:t="default",className:n}){return s.jsx("span",{className:_e("inline-block rounded text-[10px] font-medium uppercase tracking-wider px-1.5 py-0.5",Rx[t],n),children:e})}function Gs({priority:e}){return s.jsx(le,{variant:`priority-${e}`,children:e})}function Sa({status:e}){return s.jsx(le,{variant:`status-${e}`,children:e})}const Xo="shinobi.home.workspaceFilter",Zt="__all__",Jo="__none__";function Ox({done:e,total:t}){if(t===0)return s.jsx("span",{className:"text-text-muted text-xs",children:"—"});const n=Math.round(e/t*100),l=e===t?"bg-emerald-500":n>=50?"bg-accent":"bg-amber-500";return s.jsxs("div",{className:"flex items-center gap-2 min-w-[140px]",children:[s.jsx("div",{className:"flex-1 h-1.5 bg-border/40 rounded overflow-hidden",children:s.jsx("div",{className:`h-full ${l} transition-all`,style:{width:`${n}%`},role:"progressbar","aria-valuenow":n,"aria-valuemin":0,"aria-valuemax":100,"aria-label":`${e} of ${t} subtasks done`})}),s.jsxs("span",{className:"text-text-muted text-xs tabular-nums whitespace-nowrap",children:[e,"/",t," · ",n,"%"]})]})}function qo({rows:e,dim:t=!1}){return s.jsx("div",{className:"overflow-x-auto",children:s.jsxs("table",{className:"w-full text-sm",children:[s.jsx("thead",{children:s.jsxs("tr",{className:"text-[11px] uppercase tracking-wider text-text-muted text-left",children:[s.jsx("th",{className:"font-medium pb-2 pr-3",children:"Workspace"}),s.jsx("th",{className:"font-medium pb-2 pr-3",children:"Title"}),s.jsx("th",{className:"font-medium pb-2 pr-3",children:"Status"}),s.jsx("th",{className:"font-medium pb-2 pr-3",children:"Priority"}),s.jsx("th",{className:"font-medium pb-2 pr-3",children:"Progress"}),s.jsx("th",{className:"font-medium pb-2 pr-3",children:"Type"}),s.jsx("th",{className:"font-medium pb-2 pr-3",children:"Target path"}),s.jsx("th",{className:"font-medium pb-2 pr-3",children:"Due"}),s.jsx("th",{className:"font-medium pb-2",children:"Created"})]})}),s.jsx("tbody",{className:t?"opacity-60":"",children:e.map(n=>s.jsxs("tr",{className:"border-b border-border/40 hover:bg-panel/40",children:[s.jsx("td",{className:"py-2 pr-3",children:s.jsx(Na,{workspace:n.workspace})}),s.jsx("td",{className:"py-2 pr-3",children:s.jsx(X,{to:`/projects/${n.id}`,className:"text-text hover:text-accent font-medium",children:n.title})}),s.jsx("td",{className:"py-2 pr-3",children:s.jsx(Sa,{status:n.status})}),s.jsx("td",{className:"py-2 pr-3",children:s.jsx(Gs,{priority:n.priority})}),s.jsx("td",{className:"py-2 pr-3",children:s.jsx(Ox,{done:n.subtasks_done,total:n.subtasks_total})}),s.jsx("td",{className:"py-2 pr-3 text-text-muted",children:n.project_type??""}),s.jsx("td",{className:"py-2 pr-3 text-text-muted font-mono text-xs",children:n.target_path??""}),s.jsx("td",{className:"py-2 pr-3 text-text-muted",children:n.due_date??""}),s.jsx("td",{className:"py-2 text-text-muted text-xs",title:n.created_at,children:G(n.created_at)})]},n.id))})]})})}function zx(){const{projects:e}=Fe(),[t,n]=g.useState(!1),[r,l]=g.useState(()=>typeof window>"u"?Zt:window.localStorage.getItem(Xo)??Zt),i=g.useMemo(()=>{const d=new Set;let x=!1;for(const v of e)v.workspace?d.add(v.workspace):x=!0;return{named:Array.from(d).sort((v,j)=>v.localeCompare(j)),hasNoWorkspace:x}},[e]);function a(d){return r===Zt?d:r===Jo?d.filter(x=>!x.workspace):d.filter(x=>x.workspace===r)}const o=a(e.filter(d=>!d.archived_at)),u=a(e.filter(d=>d.archived_at));function f(d){l(d),typeof window<"u"&&window.localStorage.setItem(Xo,d)}const p=i.named.length>1||i.named.length>=1&&i.hasNoWorkspace;return s.jsxs("div",{children:[s.jsxs("header",{className:"flex items-baseline justify-between border-b border-border pb-3 mb-6",children:[s.jsx("h1",{className:"text-2xl text-text",children:"Projects"}),s.jsxs("span",{className:"text-text-muted text-xs",children:[o.length," active · ",u.length," archived"]})]}),p&&s.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[s.jsx("label",{htmlFor:"workspace-filter",className:"text-[11px] uppercase tracking-wider text-text-muted",children:"Workspace"}),s.jsxs("select",{id:"workspace-filter",value:r,onChange:d=>f(d.target.value),className:"bg-panel border border-border rounded px-2 py-1 text-sm text-text hover:border-accent/60 focus:outline-none focus:border-accent",children:[s.jsx("option",{value:Zt,children:"All workspaces"}),i.named.map(d=>s.jsx("option",{value:d,children:d},d)),i.hasNoWorkspace&&s.jsx("option",{value:Jo,children:"(no workspace)"})]}),r!==Zt&&s.jsx("button",{onClick:()=>f(Zt),className:"text-xs text-text-muted hover:text-text",children:"clear"})]}),e.length===0?s.jsxs("div",{className:"bg-panel border border-dashed border-border rounded p-6 text-center text-text-muted",children:["No projects yet. Create one via the ",s.jsx("code",{children:"create_project"})," MCP tool, then refresh."]}):o.length===0?s.jsx("div",{className:"bg-panel border border-dashed border-border rounded p-6 text-center text-text-muted",children:"No active projects match this workspace filter."}):s.jsx(qo,{rows:o}),u.length>0&&s.jsxs("section",{className:"mt-8",children:[s.jsxs("button",{onClick:()=>n(d=>!d),className:"flex items-center gap-1.5 text-[11px] uppercase tracking-wider text-text-muted hover:text-text mb-3",children:[t?s.jsx(_h,{className:"w-3.5 h-3.5"}):s.jsx(Eh,{className:"w-3.5 h-3.5"}),s.jsx(Md,{className:"w-3.5 h-3.5"}),"Archived (",u.length,")"]}),t&&s.jsx(qo,{rows:u,dim:!0})]})]})}function Ix({projectId:e,draftPendingCount:t}){const n=`/projects/${e}`,r=[{to:n,label:"Kanban",end:!0},{to:`${n}/subtasks`,label:"Subtasks"},{to:`${n}/decisions`,label:"Decisions"},{to:`${n}/decision-drafts`,label:"Drafts",badge:t&&t>0?s.jsx("span",{className:"ml-1 inline-block bg-warning text-bg text-[9px] font-bold px-1.5 py-0.5 rounded-full",children:t}):null},{to:`${n}/dead-ends`,label:"Dead Ends"},{to:`${n}/notes`,label:"Notes"},{to:`${n}/plans`,label:"Plans"},{to:`${n}/context`,label:"Context"},{to:`${n}/sessions`,label:"Sessions"},{to:`${n}/timeline`,label:"Timeline"},{to:`${n}/analytics`,label:"Analytics"}];return s.jsx("nav",{className:"flex gap-1 mb-4 border-b border-border overflow-x-auto scrollbar-thin",children:r.map(l=>s.jsxs(xh,{to:l.to,end:l.end,className:({isActive:i})=>_e("px-3.5 py-2 text-sm -mb-px border-b-2 whitespace-nowrap transition-colors flex items-center",i?"text-text border-accent":"text-text-muted border-transparent hover:text-text hover:border-border-2"),children:[l.label,l.badge]},l.to))})}function $x(){const e=ya(),t=Number(e.id),[n,r]=g.useState(null),[l,i]=g.useState(null),a=g.useCallback(async()=>{try{const u=await qh(t);r(u)}catch(u){i(u instanceof Error?u.message:String(u))}},[t]);if(g.useEffect(()=>{Number.isFinite(t)&&(r(null),i(null),a())},[t,a]),l)return s.jsxs("div",{className:"text-danger",children:["Error: ",l]});if(!n)return s.jsx("div",{className:"text-text-muted",children:"loading..."});const{project:o}=n;return s.jsxs("div",{children:[s.jsxs("header",{className:"border-b border-border pb-3 mb-4",children:[s.jsx("h1",{className:"text-2xl text-text",children:o.title}),s.jsxs("div",{className:"mt-2 text-xs text-text-muted flex items-center gap-2 flex-wrap",children:[s.jsx(Na,{workspace:o.workspace}),s.jsx("span",{children:"·"}),s.jsx(Sa,{status:o.status}),s.jsx("span",{children:"·"}),s.jsx(Gs,{priority:o.priority}),o.due_date&&s.jsxs(s.Fragment,{children:[s.jsx("span",{children:"·"}),s.jsxs("span",{children:["due ",o.due_date]})]}),o.target_path&&s.jsxs(s.Fragment,{children:[s.jsx("span",{children:"·"}),s.jsxs("span",{className:"font-mono",children:["target ",o.target_path]})]}),o.recent_summary_at&&s.jsxs(s.Fragment,{children:[s.jsx("span",{children:"·"}),s.jsxs("span",{children:["summary ",G(o.recent_summary_at)]})]})]})]}),s.jsx(Ix,{projectId:t,draftPendingCount:n.draft_counts.pending}),s.jsx(Cd,{context:{snapshot:n,refresh:a}})]})}const Dx=[{key:"todo",label:"Todo"},{key:"in_progress",label:"In Progress"},{key:"done",label:"Done"}];function Fx(){const{snapshot:e,refresh:t}=Fe(),{project:n,subtasks:r}=e,l={todo:[],in_progress:[],done:[]};for(const a of r)l[a.status].push(a);async function i(a,o){try{await ex(a,{status:o}),await t()}catch(u){alert("Transition failed: "+(u instanceof Error?u.message:String(u)))}}return s.jsxs(s.Fragment,{children:[n.description&&s.jsx("pre",{className:"bg-panel border border-border rounded p-3 mb-6 whitespace-pre-wrap text-xs font-mono text-text",children:n.description}),n.recent_summary_md&&s.jsxs("div",{className:"bg-panel border border-border border-l-4 border-l-accent rounded-md p-4 mb-6",children:[s.jsxs("div",{className:"text-[11px] uppercase tracking-wider text-text-muted mb-2",children:["Recent session summary",n.recent_summary_provider&&s.jsxs("span",{className:"text-text-dim normal-case ml-2 tracking-normal",children:["via ",n.recent_summary_provider]})]}),s.jsx("div",{className:"text-sm text-text whitespace-pre-wrap leading-relaxed",children:n.recent_summary_md})]}),s.jsx("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:Dx.map(a=>s.jsxs("div",{className:"bg-panel border border-border rounded-md p-3 min-h-[200px]",children:[s.jsxs("h3",{className:"text-[11px] uppercase tracking-wider text-text-muted mb-3",children:[a.label," (",l[a.key].length,")"]}),s.jsx("div",{className:"space-y-2",children:l[a.key].length===0?s.jsx("div",{className:"text-text-dim text-xs",children:"(empty)"}):l[a.key].map(o=>s.jsxs("div",{className:"bg-panel-2 border border-border rounded p-2.5 text-xs",children:[s.jsx("div",{className:"text-text font-medium mb-1",children:o.title}),s.jsxs("div",{className:"text-text-muted flex flex-wrap gap-2 items-center text-[11px]",children:[s.jsx(Gs,{priority:o.priority}),o.due_date&&s.jsxs("span",{children:["due ",o.due_date]}),o.depends_on&&o.depends_on.length>0&&s.jsxs("span",{children:["deps: ",o.depends_on.join(",")]}),o.claude_session_id&&s.jsx("span",{title:o.claude_session_id,children:"session"})]}),s.jsxs("div",{className:"flex gap-1.5 mt-2",children:[o.status!=="todo"&&s.jsxs(z,{size:"sm",variant:"ghost",onClick:()=>void i(o.id,"todo"),className:"flex items-center gap-1",children:[s.jsx(Vh,{className:"w-3 h-3"})," todo"]}),o.status!=="in_progress"&&s.jsxs(z,{size:"sm",variant:"ghost",onClick:()=>void i(o.id,"in_progress"),className:"flex items-center gap-1",children:[s.jsx(zh,{className:"w-3 h-3"})," in progress"]}),o.status!=="done"&&s.jsxs(z,{size:"sm",variant:"ghost",onClick:()=>void i(o.id,"done"),className:"flex items-center gap-1",children:[s.jsx(bh,{className:"w-3 h-3"})," done"]})]})]},o.id))})]},a.key))})]})}function Ax(){const{snapshot:e}=Fe(),{subtasks:t}=e;return t.length===0?s.jsxs("div",{className:"bg-panel border border-dashed border-border rounded p-6 text-center text-text-muted",children:["No subtasks. Use ",s.jsx("code",{children:"create_task"})," or ",s.jsx("code",{children:"bulk_create_tasks"})," to seed."]}):s.jsx("div",{className:"overflow-x-auto",children:s.jsxs("table",{className:"w-full text-sm",children:[s.jsx("thead",{children:s.jsxs("tr",{className:"text-[11px] uppercase tracking-wider text-text-muted text-left",children:[s.jsx("th",{className:"font-medium pb-2 pr-3 w-12",children:"ID"}),s.jsx("th",{className:"font-medium pb-2 pr-3",children:"Title"}),s.jsx("th",{className:"font-medium pb-2 pr-3 w-28",children:"Status"}),s.jsx("th",{className:"font-medium pb-2 pr-3 w-24",children:"Priority"}),s.jsx("th",{className:"font-medium pb-2 pr-3 w-24",children:"Deps"}),s.jsx("th",{className:"font-medium pb-2 pr-3 w-24",children:"Due"}),s.jsx("th",{className:"font-medium pb-2 w-28",children:"Claimed"})]})}),s.jsx("tbody",{children:t.map(n=>s.jsxs("tr",{className:"border-b border-border/40 hover:bg-panel/40 align-top",children:[s.jsx("td",{className:"py-2 pr-3 text-text-muted font-mono",children:n.id}),s.jsxs("td",{className:"py-2 pr-3",children:[s.jsx("div",{className:"text-text font-medium",children:n.title}),n.description&&s.jsx("div",{className:"text-text-muted text-xs mt-1",children:n.description.length>200?n.description.slice(0,200)+"…":n.description})]}),s.jsx("td",{className:"py-2 pr-3",children:s.jsx(Sa,{status:n.status})}),s.jsx("td",{className:"py-2 pr-3",children:s.jsx(Gs,{priority:n.priority})}),s.jsx("td",{className:"py-2 pr-3 text-text-muted text-xs",children:n.depends_on&&n.depends_on.length>0?n.depends_on.join(", "):""}),s.jsx("td",{className:"py-2 pr-3 text-text-muted",children:n.due_date??""}),s.jsx("td",{className:"py-2 text-text-muted text-xs",title:n.last_claimed_at??"",children:G(n.last_claimed_at)})]},n.id))})]})})}const Ux=["open","fix_now","fix_later","wontfix","fixed","false_positive"];function Bx(e){switch(e){case"open":return"bg-accent-2 text-white";case"fix_now":return"bg-danger text-white";case"fix_later":return"bg-orange text-bg";case"wontfix":return"bg-text-dim text-text";case"fixed":return"bg-success text-bg";case"false_positive":return"bg-text-dim text-text";default:return"bg-border-2 text-text"}}function Vx(){const{snapshot:e,refresh:t}=Fe(),{decisions:n,draft_counts:r,project:l}=e;async function i(o,u){try{await tx(o,u),await t()}catch(f){alert("Transition failed: "+(f instanceof Error?f.message:String(f)))}}const a=r.pending>0?s.jsxs("div",{className:"bg-panel border-l-4 border-l-warning rounded-md p-3 mb-4 flex items-center justify-between",children:[s.jsxs("span",{className:"text-sm",children:[s.jsxs("strong",{children:[r.pending," pending decision draft",r.pending>1?"s":""]})," ",s.jsx("span",{className:"text-text-muted",children:"extracted via LLM"})]}),s.jsx(X,{to:`/projects/${l.id}/decision-drafts`,className:"text-accent text-sm hover:underline",children:"Review →"})]}):null;return n.length===0?s.jsxs("div",{children:[a,s.jsxs("div",{className:"bg-panel border border-dashed border-border rounded p-6 text-center text-text-muted",children:["No decisions logged. Use ",s.jsx("code",{children:"log_decision"})," via MCP."]})]}):s.jsxs("div",{children:[a,s.jsx("div",{className:"overflow-x-auto",children:s.jsxs("table",{className:"w-full text-sm",children:[s.jsx("thead",{children:s.jsxs("tr",{className:"text-[11px] uppercase tracking-wider text-text-muted text-left",children:[s.jsx("th",{className:"font-medium pb-2 pr-3 w-12",children:"ID"}),s.jsx("th",{className:"font-medium pb-2 pr-3 w-24",children:"Kind"}),s.jsx("th",{className:"font-medium pb-2 pr-3",children:"Summary + Rationale"}),s.jsx("th",{className:"font-medium pb-2 pr-3 w-44",children:"Status"}),s.jsx("th",{className:"font-medium pb-2 pr-3 w-40",children:"Files"}),s.jsx("th",{className:"font-medium pb-2 pr-3 w-32",children:"Tags"}),s.jsx("th",{className:"font-medium pb-2 w-24",children:"Logged"})]})}),s.jsx("tbody",{children:n.map(o=>s.jsxs("tr",{className:"border-b border-border/40 hover:bg-panel/40 align-top",children:[s.jsx("td",{className:"py-3 pr-3 text-text-muted font-mono",children:o.id}),s.jsx("td",{className:"py-3 pr-3",children:s.jsx(le,{children:o.kind})}),s.jsxs("td",{className:"py-3 pr-3",children:[s.jsx("div",{className:"text-text font-medium",children:o.summary}),s.jsx("div",{className:"text-text-muted text-xs mt-1",children:o.rationale.length>300?o.rationale.slice(0,300)+"…":o.rationale}),o.alternatives_considered&&s.jsxs("div",{className:"text-text-dim text-xs mt-1",children:["alt: ",o.alternatives_considered.slice(0,150)]})]}),s.jsxs("td",{className:"py-3 pr-3",children:[s.jsx("span",{className:`inline-block rounded text-[10px] font-medium uppercase tracking-wider px-1.5 py-0.5 ${Bx(o.status)}`,children:o.status}),s.jsx("div",{className:"flex flex-wrap gap-1 mt-2",children:Ux.filter(u=>u!==o.status).map(u=>s.jsx(z,{size:"sm",variant:"ghost",onClick:()=>void i(o.id,u),className:"text-[10px] px-1.5 py-0.5",children:u},u))})]}),s.jsx("td",{className:"py-3 pr-3 text-text-muted text-xs",children:(o.files_touched??[]).map(u=>s.jsx("div",{children:u},u))}),s.jsx("td",{className:"py-3 pr-3",children:(o.tags??[]).map(u=>s.jsx(le,{className:"mr-1 mb-1",children:u},u))}),s.jsx("td",{className:"py-3 text-text-muted text-xs",title:o.created_at,children:G(o.created_at)})]},o.id))})]})})]})}function Wx(){const{snapshot:e,refresh:t}=Fe(),n=e.project.id,[r,l]=g.useState(null),[i,a]=g.useState({pending:0,approved:0,rejected:0}),[o,u]=g.useState(null),[f,p]=g.useState(null),d=g.useCallback(async()=>{try{const v=await nx(n);l(v.drafts),a(v.counts)}catch(v){u(v instanceof Error?v.message:String(v))}},[n]);g.useEffect(()=>{d()},[d]);async function x(v,j){if(f===null){p(v);try{j==="approve"?await rx(v):await sx(v),await Promise.all([d(),t()])}catch(y){alert(`${j} failed: ${y instanceof Error?y.message:String(y)}`)}finally{p(null)}}}if(o)return s.jsxs("div",{className:"text-danger",children:["Error: ",o]});if(!r)return s.jsx("div",{className:"text-text-muted",children:"loading drafts..."});const w=(v,j,y)=>s.jsxs("div",{className:"bg-panel border border-border rounded p-3",children:[s.jsx("div",{className:"text-[11px] uppercase tracking-wider text-text-muted",children:v}),s.jsx("div",{className:`text-2xl mt-1 ${y}`,children:j})]});return s.jsxs("div",{children:[s.jsxs("div",{className:"grid grid-cols-3 gap-3 mb-4",children:[w("Pending",i.pending,"text-warning"),w("Approved",i.approved,"text-success"),w("Rejected",i.rejected,"text-danger")]}),r.length===0?s.jsxs("div",{className:"bg-panel border border-dashed border-border rounded p-6 text-center text-text-muted",children:["No drafts. Drafts appear when the agent calls ",s.jsx("code",{children:"extract_decisions(text)"})," — LLM scans a transcript and proposes decisions for you to approve."]}):s.jsx("div",{className:"overflow-x-auto",children:s.jsxs("table",{className:"w-full text-sm",children:[s.jsx("thead",{children:s.jsxs("tr",{className:"text-[11px] uppercase tracking-wider text-text-muted text-left",children:[s.jsx("th",{className:"font-medium pb-2 pr-3 w-12",children:"ID"}),s.jsx("th",{className:"font-medium pb-2 pr-3 w-24",children:"Kind"}),s.jsx("th",{className:"font-medium pb-2 pr-3",children:"Summary + Rationale"}),s.jsx("th",{className:"font-medium pb-2 pr-3 w-32",children:"Files"}),s.jsx("th",{className:"font-medium pb-2 pr-3 w-44",children:"Action"}),s.jsx("th",{className:"font-medium pb-2 pr-3 w-20",children:"Created"}),s.jsx("th",{className:"font-medium pb-2",children:"Extractor"})]})}),s.jsx("tbody",{children:r.map(v=>s.jsxs("tr",{className:"border-b border-border/40 hover:bg-panel/40 align-top",children:[s.jsx("td",{className:"py-3 pr-3 text-text-muted font-mono",children:v.id}),s.jsx("td",{className:"py-3 pr-3",children:s.jsx(le,{children:v.kind})}),s.jsxs("td",{className:"py-3 pr-3",children:[s.jsx("div",{className:"text-text font-medium",children:v.summary}),s.jsx("div",{className:"text-text-muted text-xs mt-1",children:v.rationale}),v.alternatives_considered&&s.jsxs("div",{className:"text-text-dim text-xs mt-1",children:["alt: ",v.alternatives_considered]})]}),s.jsx("td",{className:"py-3 pr-3 text-text-muted text-xs",children:(v.files_touched??[]).map(j=>s.jsx("div",{children:j},j))}),s.jsx("td",{className:"py-3 pr-3",children:v.status==="pending"?s.jsxs("div",{className:"flex gap-1.5",children:[s.jsx(z,{size:"sm",variant:"primary",disabled:f===v.id,onClick:()=>void x(v.id,"approve"),children:"Approve"}),s.jsx(z,{size:"sm",variant:"default",disabled:f===v.id,onClick:()=>void x(v.id,"reject"),children:"Reject"})]}):v.status==="approved"?s.jsxs(le,{className:"bg-success text-bg",children:["approved ",v.approved_decision_id?`→ #${v.approved_decision_id}`:""]}):s.jsx(le,{className:"bg-danger text-white",children:"rejected"})}),s.jsx("td",{className:"py-3 pr-3 text-text-muted text-xs",children:G(v.created_at)}),s.jsx("td",{className:"py-3 text-text-dim text-[10px] font-mono",children:v.extractor_model??""})]},v.id))})]})})]})}function Hx(){const{snapshot:e}=Fe(),{dead_ends:t}=e;return t.length===0?s.jsxs("div",{className:"bg-panel border border-dashed border-border rounded p-6 text-center text-text-muted",children:["No dead ends logged. Use ",s.jsx("code",{children:"log_dead_end"})," when an approach fails."]}):s.jsx("div",{className:"overflow-x-auto",children:s.jsxs("table",{className:"w-full text-sm",children:[s.jsx("thead",{children:s.jsxs("tr",{className:"text-[11px] uppercase tracking-wider text-text-muted text-left",children:[s.jsx("th",{className:"font-medium pb-2 pr-3 w-12",children:"ID"}),s.jsx("th",{className:"font-medium pb-2 pr-3",children:"Attempted"}),s.jsx("th",{className:"font-medium pb-2 pr-3",children:"Why failed"}),s.jsx("th",{className:"font-medium pb-2 pr-3 w-32",children:"Files"}),s.jsx("th",{className:"font-medium pb-2 pr-3 w-24",children:"Flag"}),s.jsx("th",{className:"font-medium pb-2 w-24",children:"Logged"})]})}),s.jsx("tbody",{children:t.map(n=>s.jsxs("tr",{className:"border-b border-border/40 hover:bg-panel/40 align-top",children:[s.jsx("td",{className:"py-3 pr-3 text-text-muted font-mono",children:n.id}),s.jsx("td",{className:"py-3 pr-3 text-text font-medium",children:n.attempted_approach}),s.jsx("td",{className:"py-3 pr-3 text-text-muted",children:n.failure_reason}),s.jsx("td",{className:"py-3 pr-3 text-text-muted text-xs",children:(n.files_involved??[]).map(r=>s.jsx("div",{children:r},r))}),s.jsx("td",{className:"py-3 pr-3",children:n.never_retry&&s.jsx(le,{className:"bg-danger text-white",children:"never retry"})}),s.jsx("td",{className:"py-3 text-text-muted text-xs",title:n.created_at,children:G(n.created_at)})]},n.id))})]})})}function Qx(){const{snapshot:e}=Fe(),{notes:t}=e;return t.length===0?s.jsxs("div",{className:"bg-panel border border-dashed border-border rounded p-6 text-center text-text-muted",children:["No notes yet. Use ",s.jsx("code",{children:"add_note"})," for stray observations."]}):s.jsx("div",{className:"space-y-6",children:t.map(n=>s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-2 mb-2 flex-wrap",children:[s.jsxs(le,{children:["note #",n.id]}),(n.tags??[]).map(r=>s.jsx(le,{children:r},r)),s.jsx("span",{className:"text-text-muted text-xs",children:G(n.created_at)}),n.audio_path&&s.jsx(le,{className:"bg-success text-bg",children:"audio"})]}),s.jsx("pre",{className:"bg-panel border border-border rounded p-3 text-xs font-mono text-text whitespace-pre-wrap",children:n.body}),n.audio_path&&s.jsx("audio",{controls:!0,className:"mt-2 w-full",src:n.audio_path}),n.files_touched&&n.files_touched.length>0&&s.jsxs("div",{className:"text-text-muted text-xs mt-1",children:["files: ",n.files_touched.join(", ")]})]},n.id))})}function Kx(){const{snapshot:e}=Fe(),{latest_plan:t,plan_history:n}=e;return t?s.jsxs("div",{children:[s.jsxs("section",{className:"mb-8",children:[s.jsxs("h3",{className:"text-sm text-text mb-2",children:["Latest plan — v",t.version]}),s.jsxs("div",{className:"text-text-muted text-xs mb-3",children:["saved ",G(t.created_at)]}),s.jsx("pre",{className:"bg-panel border border-border rounded p-4 text-xs font-mono text-text whitespace-pre-wrap overflow-x-auto",children:t.plan_md})]}),n.length>0&&s.jsxs("section",{children:[s.jsx("h3",{className:"text-sm text-text mb-3",children:"Version history"}),s.jsx("ul",{className:"space-y-1 text-sm",children:n.map(r=>s.jsxs("li",{className:"text-text-muted",children:[s.jsxs("span",{className:"text-text font-medium",children:["v",r.version]})," — ",r.created_at," (",r.plan_md_length," chars)"]},r.id))})]})]}):s.jsxs("div",{className:"bg-panel border border-dashed border-border rounded p-6 text-center text-text-muted",children:["No plans saved. Use ",s.jsx("code",{children:"save_plan"})," to persist an approved plan."]})}function en({title:e,children:t}){return s.jsxs("section",{className:"mb-6",children:[s.jsx("h3",{className:"text-sm text-text mb-2",children:e}),t]})}function Un(){return s.jsx("div",{className:"text-text-muted text-sm",children:"(none)"})}function Yx(){const{snapshot:e}=Fe(),t=e.context;if(!t)return s.jsxs("div",{className:"bg-panel border border-dashed border-border rounded p-6 text-center text-text-muted",children:["No context set. Use ",s.jsx("code",{children:"update_context"})," to record conventions / dont_touch / deploy_notes."]});const n=t.file_annotations??{},r=Object.entries(n);return s.jsxs("div",{children:[s.jsx(en,{title:"Conventions",children:t.conventions?s.jsx("pre",{className:"bg-panel border border-border rounded p-3 text-xs font-mono text-text whitespace-pre-wrap",children:t.conventions}):s.jsx(Un,{})}),s.jsx(en,{title:"Don't touch",children:t.dont_touch&&t.dont_touch.length>0?s.jsx("ul",{className:"list-disc list-inside text-sm text-text",children:t.dont_touch.map(l=>s.jsx("li",{children:l},l))}):s.jsx(Un,{})}),s.jsx(en,{title:"Test patterns",children:t.test_patterns?s.jsx("pre",{className:"bg-panel border border-border rounded p-3 text-xs font-mono text-text whitespace-pre-wrap",children:t.test_patterns}):s.jsx(Un,{})}),s.jsx(en,{title:"Deploy notes",children:t.deploy_notes?s.jsx("pre",{className:"bg-panel border border-border rounded p-3 text-xs font-mono text-text whitespace-pre-wrap",children:t.deploy_notes}):s.jsx(Un,{})}),s.jsx(en,{title:"File annotations",children:r.length>0?s.jsxs("table",{className:"w-full text-sm",children:[s.jsx("thead",{children:s.jsxs("tr",{className:"text-[11px] uppercase tracking-wider text-text-muted text-left",children:[s.jsx("th",{className:"pb-2 pr-3",children:"Path"}),s.jsx("th",{className:"pb-2",children:"Annotation"})]})}),s.jsx("tbody",{children:r.map(([l,i])=>s.jsxs("tr",{className:"border-b border-border/40 align-top",children:[s.jsx("td",{className:"py-2 pr-3 text-text font-mono text-xs",children:l}),s.jsx("td",{className:"py-2 text-text-muted",children:i})]},l))})]}):s.jsx(Un,{})}),s.jsx(en,{title:"Meta",children:s.jsxs("div",{className:"text-xs text-text-muted",children:["Last validated commit: ",t.last_validated_commit?s.jsx("code",{className:"text-text",children:t.last_validated_commit}):"(none)",s.jsx("br",{}),"Updated: ",t.updated_at]})})]})}function Gx(){const{snapshot:e}=Fe(),{activity:t}=e;return t.length===0?s.jsx("div",{className:"bg-panel border border-dashed border-border rounded p-6 text-center text-text-muted",children:"No activity yet. Write paths (claim_task, log_decision, etc.) populate this timeline."}):s.jsx("div",{className:"space-y-px",children:t.map(n=>s.jsxs("div",{className:"grid grid-cols-[110px_160px_1fr_140px] gap-3 py-2 border-b border-border/40 items-baseline text-xs",children:[s.jsx("div",{className:"text-text-muted font-mono",title:n.created_at,children:G(n.created_at)}),s.jsx("div",{className:"text-accent",children:n.action_type}),s.jsxs("div",{className:"text-text flex flex-wrap items-center gap-2",children:[n.action_details&&s.jsx("span",{children:n.action_details}),n.entity_type&&s.jsxs(le,{children:[n.entity_type,"#",n.entity_id??"?"]}),n.ref_url&&s.jsxs("span",{className:"text-text-dim font-mono",children:[n.ref_url.slice(0,16),"…"]})]}),s.jsx("div",{className:"text-text-muted font-mono text-[11px]",children:n.session_id??""})]},n.id))})}function Zo(e){if(e<60)return`${e}s`;const t=Math.round(e/60);if(t<60)return`${t}m`;const n=Math.floor(t/60),r=t%60;return r===0?`${n}h`:`${n}h ${r}m`}function ne({label:e,value:t}){return s.jsxs("div",{className:"bg-panel border border-border rounded p-3",children:[s.jsx("div",{className:"text-[11px] uppercase tracking-wider text-text-muted",children:e}),s.jsx("div",{className:"text-2xl text-text mt-1",children:t})]})}function Xx(){const{snapshot:e}=Fe(),{subtasks:t,decisions:n,dead_ends:r,notes:l,sessions:i,activity:a,plan_history:o,draft_counts:u,project:f}=e,[p,d]=g.useState(null),[x,w]=g.useState(null),[v,j]=g.useState(!1),[y,m]=g.useState(null),c=()=>{Ko(f.id).then(d),Yo(f.id).then(w)};g.useEffect(()=>{let C=!1;return Ko(f.id).then(ie=>{C||d(ie)}),Yo(f.id).then(ie=>{C||w(ie)}),()=>{C=!0}},[f.id]);const h=async()=>{j(!0),m(null);try{const C=await yx({since_hours:720});m(`parsed ${C.parsed} transcripts, upserted ${C.upserted}, total scanned ≈ $${C.total_cost_usd.toFixed(2)}`),c()}catch(C){m("ingest failed: "+(C instanceof Error?C.message:String(C)))}finally{j(!1)}},k=new Map(t.map(C=>[C.id,C.title])),b={total:t.length,todo:t.filter(C=>C.status==="todo").length,in_progress:t.filter(C=>C.status==="in_progress").length,done:t.filter(C=>C.status==="done").length},N={total:n.length,open:n.filter(C=>C.status==="open").length,fixed:n.filter(C=>C.status==="fixed").length},_=Date.now(),E=a.filter(C=>{const ie=new Date(C.created_at.replace(" ","T")+"Z").getTime();return!isNaN(ie)&&_-ie<864e5}).length,F=new Map;for(const C of a)F.set(C.action_type,(F.get(C.action_type)??0)+1);const L=[...F.entries()].sort((C,ie)=>ie[1]-C[1]).slice(0,20);return s.jsxs("div",{children:[s.jsxs("section",{className:"mb-6",children:[s.jsx("h3",{className:"text-sm text-text mb-3",children:"Subtasks"}),s.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[s.jsx(ne,{label:"total",value:b.total}),s.jsx(ne,{label:"todo",value:b.todo}),s.jsx(ne,{label:"in progress",value:b.in_progress}),s.jsx(ne,{label:"done",value:b.done})]})]}),s.jsxs("section",{className:"mb-6",children:[s.jsx("h3",{className:"text-sm text-text mb-3",children:"Memory"}),s.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[s.jsx(ne,{label:"decisions",value:N.total}),s.jsx(ne,{label:"decisions open",value:N.open}),s.jsx(ne,{label:"decisions fixed",value:N.fixed}),s.jsx(ne,{label:"drafts pending",value:u.pending}),s.jsx(ne,{label:"drafts approved",value:u.approved}),s.jsx(ne,{label:"dead ends",value:r.length}),s.jsx(ne,{label:"notes",value:l.length}),s.jsx(ne,{label:"plan versions",value:o.length})]})]}),s.jsxs("section",{className:"mb-6",children:[s.jsx("h3",{className:"text-sm text-text mb-3",children:"Time on task"}),p===null?s.jsx("div",{className:"text-text-muted text-sm",children:"loading…"}):s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 gap-3 mb-4",children:[s.jsxs("div",{className:"bg-panel border border-border rounded p-3",children:[s.jsx("div",{className:"text-[11px] uppercase tracking-wider text-text-muted",children:"total time"}),s.jsx("div",{className:"text-2xl text-text mt-1",children:Zo(p.total_seconds)})]}),s.jsx(ne,{label:"sessions w/ subtask",value:p.session_count}),s.jsx(ne,{label:"tasks tracked",value:p.per_subtask.length})]}),p.per_subtask.length===0?s.jsx("div",{className:"text-text-muted text-sm",children:"(no time-tracked sessions — sessions only count toward a task when claude_session_id is linked at claim)"}):s.jsxs("table",{className:"w-full text-sm",children:[s.jsx("thead",{children:s.jsxs("tr",{className:"text-[11px] uppercase tracking-wider text-text-muted text-left",children:[s.jsx("th",{className:"pb-2 pr-3",children:"Task"}),s.jsx("th",{className:"pb-2 pr-3 text-right",children:"Duration"}),s.jsx("th",{className:"pb-2 pr-3 text-right",children:"Sessions"}),s.jsx("th",{className:"pb-2 text-right",children:"Last touched"})]})}),s.jsx("tbody",{children:p.per_subtask.slice(0,20).map(C=>s.jsxs("tr",{className:"border-b border-border/40",children:[s.jsx("td",{className:"py-1.5 pr-3 text-text",children:s.jsxs("a",{href:`#subtask-${C.subtask_id}`,className:"hover:underline",children:["#",C.subtask_id," ",k.get(C.subtask_id)??"(deleted)"]})}),s.jsx("td",{className:"py-1.5 pr-3 text-text text-right font-mono",children:Zo(C.total_seconds)}),s.jsxs("td",{className:"py-1.5 pr-3 text-text text-right",children:[C.session_count,C.open_sessions>0?s.jsxs("span",{className:"text-warning",children:[" (",C.open_sessions," open)"]}):null]}),s.jsx("td",{className:"py-1.5 text-text-muted text-right text-xs",children:C.last_session_at??"—"})]},C.subtask_id))})]})]})]}),s.jsxs("section",{className:"mb-6",children:[s.jsxs("div",{className:"flex items-baseline justify-between mb-3",children:[s.jsx("h3",{className:"text-sm text-text",children:"AI token cost"}),s.jsx("button",{onClick:()=>void h(),disabled:v,className:"text-[11px] uppercase tracking-wider text-accent hover:underline disabled:text-text-dim",children:v?"ingesting…":"ingest transcripts"})]}),y&&s.jsx("div",{className:"text-text-muted text-xs mb-3",children:y}),x===null?s.jsx("div",{className:"text-text-muted text-sm",children:"loading…"}):s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 gap-3 mb-4",children:[s.jsxs("div",{className:"bg-panel border border-border rounded p-3",children:[s.jsx("div",{className:"text-[11px] uppercase tracking-wider text-text-muted",children:"total cost"}),s.jsxs("div",{className:"text-2xl text-text mt-1",children:["$",x.total_cost_usd.toFixed(2)]})]}),s.jsx(ne,{label:"costed sessions",value:x.session_count}),s.jsx(ne,{label:"tasks with cost",value:x.per_subtask.length})]}),x.per_subtask.length===0?s.jsxs("div",{className:"text-text-muted text-sm",children:["(no cost data yet — click ",s.jsx("em",{children:"ingest transcripts"})," above to parse ",s.jsx("code",{children:"~/.claude/projects/"})," JSONL files)"]}):s.jsxs("table",{className:"w-full text-sm",children:[s.jsx("thead",{children:s.jsxs("tr",{className:"text-[11px] uppercase tracking-wider text-text-muted text-left",children:[s.jsx("th",{className:"pb-2 pr-3",children:"Task"}),s.jsx("th",{className:"pb-2 pr-3 text-right",children:"Cost (USD)"}),s.jsx("th",{className:"pb-2 pr-3 text-right",children:"Input tok"}),s.jsx("th",{className:"pb-2 pr-3 text-right",children:"Output tok"}),s.jsx("th",{className:"pb-2 text-right",children:"Models"})]})}),s.jsx("tbody",{children:x.per_subtask.slice(0,20).map(C=>s.jsxs("tr",{className:"border-b border-border/40",children:[s.jsxs("td",{className:"py-1.5 pr-3 text-text",children:["#",C.subtask_id," ",k.get(C.subtask_id)??"(deleted)"]}),s.jsxs("td",{className:"py-1.5 pr-3 text-text text-right font-mono",children:["$",C.total_cost_usd.toFixed(4)]}),s.jsx("td",{className:"py-1.5 pr-3 text-text-muted text-right font-mono text-xs",children:C.total_input_tokens.toLocaleString()}),s.jsx("td",{className:"py-1.5 pr-3 text-text-muted text-right font-mono text-xs",children:C.total_output_tokens.toLocaleString()}),s.jsx("td",{className:"py-1.5 text-text-muted text-right text-xs",children:C.by_model.map(ie=>ie.model.replace("claude-","")).join(", ")})]},C.subtask_id))})]})]})]}),s.jsxs("section",{className:"mb-6",children:[s.jsx("h3",{className:"text-sm text-text mb-3",children:"Activity"}),s.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 gap-3 mb-4",children:[s.jsx(ne,{label:"sessions",value:i.length}),s.jsx(ne,{label:"events total",value:a.length}),s.jsx(ne,{label:"events 24h",value:E})]}),s.jsx("h3",{className:"text-sm text-text mb-3",children:"Recent action counts"}),L.length===0?s.jsx("div",{className:"text-text-muted text-sm",children:"(no activity)"}):s.jsxs("table",{className:"w-full text-sm",children:[s.jsx("thead",{children:s.jsxs("tr",{className:"text-[11px] uppercase tracking-wider text-text-muted text-left",children:[s.jsx("th",{className:"pb-2 pr-3",children:"Action"}),s.jsx("th",{className:"pb-2",children:"Count"})]})}),s.jsx("tbody",{children:L.map(([C,ie])=>s.jsxs("tr",{className:"border-b border-border/40",children:[s.jsx("td",{className:"py-1.5 pr-3 text-text font-mono text-xs",children:C}),s.jsx("td",{className:"py-1.5 text-text",children:ie})]},C))})]})]})]})}function Jx(){const{snapshot:e}=Fe(),{sessions:t}=e;return t.length===0?s.jsx("div",{className:"bg-panel border border-dashed border-border rounded p-6 text-center text-text-muted",children:"No sessions yet for this project. Sessions appear when agent_bootstrap or claim_task is called with a session_id."}):s.jsx("div",{className:"overflow-x-auto",children:s.jsxs("table",{className:"w-full text-sm",children:[s.jsx("thead",{children:s.jsxs("tr",{className:"text-[11px] uppercase tracking-wider text-text-muted text-left",children:[s.jsx("th",{className:"font-medium pb-2 pr-3",children:"Session ID"}),s.jsx("th",{className:"font-medium pb-2 pr-3 w-32",children:"Started"}),s.jsx("th",{className:"font-medium pb-2 pr-3 w-32",children:"Ended"}),s.jsx("th",{className:"font-medium pb-2 pr-3 w-24",children:"Duration"}),s.jsx("th",{className:"font-medium pb-2 pr-3 w-20",children:"Tool calls"}),s.jsx("th",{className:"font-medium pb-2 pr-3 w-20",children:"Files"}),s.jsx("th",{className:"font-medium pb-2",children:"Notes"})]})}),s.jsx("tbody",{children:t.map(n=>s.jsxs("tr",{className:"border-b border-border/40 hover:bg-panel/40 align-top",children:[s.jsx("td",{className:"py-2 pr-3 text-text font-mono text-xs",children:s.jsx(X,{to:`/sessions/${encodeURIComponent(n.session_id)}`,className:"text-accent hover:underline",children:n.session_id})}),s.jsx("td",{className:"py-2 pr-3 text-text-muted text-xs",children:G(n.started_at)}),s.jsx("td",{className:"py-2 pr-3 text-text-muted text-xs",children:n.ended_at?G(n.ended_at):"active"}),s.jsx("td",{className:"py-2 pr-3 text-text-muted text-xs",children:n.duration_seconds?`${Math.floor(n.duration_seconds/60)}m`:""}),s.jsx("td",{className:"py-2 pr-3 text-text-muted text-xs",children:n.tool_calls_count}),s.jsx("td",{className:"py-2 pr-3 text-text-muted text-xs",children:n.files_touched_count}),s.jsx("td",{className:"py-2 text-text-muted text-xs",children:n.notes??""})]},n.session_id))})]})})}function qx(){const[e,t]=g.useState(null),[n,r]=g.useState(null);return g.useEffect(()=>{lx(500).then(t).catch(l=>r(l instanceof Error?l.message:String(l)))},[]),n?s.jsxs("div",{className:"text-danger",children:["Error: ",n]}):e?s.jsxs("div",{children:[s.jsxs("header",{className:"border-b border-border pb-3 mb-6",children:[s.jsx("h1",{className:"text-2xl text-text",children:"All sessions"}),s.jsxs("div",{className:"text-text-muted text-xs mt-1",children:[e.length," session(s)"]})]}),e.length===0?s.jsx("div",{className:"bg-panel border border-dashed border-border rounded p-6 text-center text-text-muted",children:"No sessions tracked yet."}):s.jsx("div",{className:"overflow-x-auto",children:s.jsxs("table",{className:"w-full text-sm",children:[s.jsx("thead",{children:s.jsxs("tr",{className:"text-[11px] uppercase tracking-wider text-text-muted text-left",children:[s.jsx("th",{className:"font-medium pb-2 pr-3",children:"Session ID"}),s.jsx("th",{className:"font-medium pb-2 pr-3 w-24",children:"Project"}),s.jsx("th",{className:"font-medium pb-2 pr-3 w-32",children:"Started"}),s.jsx("th",{className:"font-medium pb-2 pr-3 w-32",children:"Ended"}),s.jsx("th",{className:"font-medium pb-2 pr-3 w-24",children:"Duration"}),s.jsx("th",{className:"font-medium pb-2 w-20",children:"Tool calls"})]})}),s.jsx("tbody",{children:e.map(l=>s.jsxs("tr",{className:"border-b border-border/40 hover:bg-panel/40",children:[s.jsx("td",{className:"py-2 pr-3 text-text font-mono text-xs",children:s.jsx(X,{to:`/sessions/${encodeURIComponent(l.session_id)}`,className:"text-accent hover:underline",children:l.session_id})}),s.jsx("td",{className:"py-2 pr-3 text-text-muted",children:l.project_id?`#${l.project_id}`:""}),s.jsx("td",{className:"py-2 pr-3 text-text-muted text-xs",children:G(l.started_at)}),s.jsx("td",{className:"py-2 pr-3 text-text-muted text-xs",children:l.ended_at?G(l.ended_at):"active"}),s.jsx("td",{className:"py-2 pr-3 text-text-muted text-xs",children:l.duration_seconds?`${Math.floor(l.duration_seconds/60)}m`:""}),s.jsx("td",{className:"py-2 text-text-muted text-xs",children:l.tool_calls_count})]},l.session_id))})]})})]}):s.jsx("div",{className:"text-text-muted",children:"loading sessions..."})}function Zx(){const{sessionId:e}=ya(),[t,n]=g.useState(null),[r,l]=g.useState(null);if(g.useEffect(()=>{e&&ix(e).then(n).catch(o=>l(o instanceof Error?o.message:String(o)))},[e]),r)return s.jsxs("div",{className:"text-danger",children:["Error: ",r]});if(!t)return s.jsx("div",{className:"text-text-muted",children:"loading session..."});const{session:i,activity:a}=t;return s.jsxs("div",{children:[s.jsxs("header",{className:"border-b border-border pb-3 mb-4",children:[s.jsx(X,{to:"/sessions",className:"text-accent text-xs hover:underline",children:"← all sessions"}),s.jsx("h1",{className:"text-2xl text-text mt-1 font-mono",children:i.session_id}),s.jsxs("div",{className:"text-text-muted text-xs mt-2 flex gap-3 flex-wrap",children:[s.jsxs("span",{children:["started ",i.started_at]}),i.ended_at&&s.jsxs("span",{children:["ended ",i.ended_at]}),i.duration_seconds!==null&&s.jsxs("span",{children:["duration ",Math.floor(i.duration_seconds/60),"m ",i.duration_seconds%60,"s"]}),s.jsxs("span",{children:[i.tool_calls_count," tool calls"]}),s.jsxs("span",{children:[i.files_touched_count," files touched"]})]}),i.notes&&s.jsx("pre",{className:"bg-panel border border-border rounded p-3 mt-3 text-xs font-mono text-text whitespace-pre-wrap",children:i.notes})]}),s.jsx("h2",{className:"text-sm text-text mb-3",children:"Activity"}),a.length===0?s.jsx("div",{className:"text-text-muted text-sm",children:"(no activity in this session)"}):s.jsx("div",{className:"space-y-px",children:a.map(o=>s.jsxs("div",{className:"grid grid-cols-[110px_160px_1fr] gap-3 py-2 border-b border-border/40 items-baseline text-xs",children:[s.jsx("div",{className:"text-text-muted font-mono",title:o.created_at,children:G(o.created_at)}),s.jsx("div",{className:"text-accent",children:o.action_type}),s.jsxs("div",{className:"text-text flex flex-wrap items-center gap-2",children:[o.action_details&&s.jsx("span",{children:o.action_details}),o.entity_type&&s.jsxs(le,{children:[o.entity_type,"#",o.entity_id??"?"]})]})]},o.id))})]})}const ev={storage:"Storage",dashboard:"Dashboard",embedding:"Embedding (semantic recall)",llm:"LLM (extraction + summarization)",recall:"Recall mode",sync:"Sync"};function tv(){const[e,t]=g.useState(null),[n,r]=g.useState([]),[l,i]=g.useState({}),[a,o]=g.useState(null),u=g.useCallback(async()=>{try{const v=await ax();t(v.specs),r(v.values),i({})}catch(v){o({kind:"err",text:v instanceof Error?v.message:String(v)})}},[]);if(g.useEffect(()=>{u()},[u]),!e)return s.jsx("div",{className:"text-text-muted",children:"loading settings..."});const f=new Map(n.map(v=>[v.key,v])),p=new Map;for(const v of e)p.has(v.group)||p.set(v.group,[]),p.get(v.group).push(v);function d(v,j){i(y=>({...y,[v]:j}))}function x(v){i(j=>{const{[v]:y,...m}=j;return m})}async function w(){if(Object.keys(l).length===0){o({kind:"err",text:"no changes to save"});return}o({kind:"busy",text:"writing ~/.shinobi/.env ..."});try{const v=await ox(l);if(!v.ok)throw new Error(v.error??"unknown error");const j=Object.keys(l).filter(m=>{var c;return(c=e==null?void 0:e.find(h=>h.key===m))==null?void 0:c.requiresRestart}),y=`wrote ${v.written??0}, cleared ${v.cleared??0}${j.length>0?` (restart required: ${j.join(", ")})`:""}`;o({kind:"ok",text:y}),await u()}catch(v){o({kind:"err",text:v instanceof Error?v.message:String(v)})}}return s.jsxs("div",{className:"max-w-3xl",children:[s.jsxs("header",{className:"border-b border-border pb-3 mb-6 flex items-baseline justify-between",children:[s.jsx("h1",{className:"text-2xl text-text",children:"Settings"}),s.jsx("span",{className:"text-text-muted text-xs",children:"writes to ~/.shinobi/.env with backup"})]}),a&&s.jsxs("div",{className:`mb-4 px-4 py-2 rounded text-sm flex items-center gap-2 ${a.kind==="ok"?"bg-success/20 text-success border border-success/40":a.kind==="err"?"bg-danger/20 text-danger border border-danger/40":"bg-warning/20 text-warning border border-warning/40"}`,children:[a.kind==="ok"&&s.jsx(Rt,{className:"w-4 h-4"}),a.kind==="err"&&s.jsx(at,{className:"w-4 h-4"}),a.kind==="busy"&&s.jsx(Yt,{className:"w-4 h-4 animate-spin"}),a.text]}),[...p.entries()].map(([v,j])=>s.jsxs("section",{className:"mb-8",children:[s.jsx("h2",{className:"text-sm text-text mb-3 uppercase tracking-wider text-text-muted",children:ev[v]}),s.jsx("div",{className:"space-y-3",children:j.map(y=>{const m=f.get(y.key),c=y.key in l,h=l[y.key];return s.jsxs("div",{className:"bg-panel border border-border rounded p-3",children:[s.jsxs("div",{className:"flex items-baseline justify-between gap-3 mb-1",children:[s.jsxs("div",{children:[s.jsxs("label",{className:"text-sm text-text font-medium",children:[y.label,y.requiresRestart&&s.jsx("span",{className:"ml-2 text-[10px] uppercase tracking-wider text-warning",children:"restart required"})]}),s.jsx("code",{className:"ml-2 text-[11px] text-text-muted font-mono",children:y.key})]}),(m==null?void 0:m.is_set)&&!c&&s.jsx("span",{className:"text-[10px] uppercase tracking-wider text-success",children:"set"}),c&&s.jsx("span",{className:"text-[10px] uppercase tracking-wider text-warning",children:"unsaved"})]}),s.jsx("p",{className:"text-xs text-text-muted mb-2",children:y.description}),s.jsxs("div",{className:"flex gap-2 items-center",children:[y.enumValues?s.jsxs("select",{value:c?h??"":(m==null?void 0:m.value)??"",onChange:k=>d(y.key,k.target.value||null),className:"bg-panel-2 border border-border rounded px-2 py-1 text-sm text-text font-mono flex-1",children:[s.jsx("option",{value:"",children:"(unset)"}),y.enumValues.map(k=>s.jsx("option",{value:k,children:k},k))]}):s.jsx("input",{type:y.secret?"password":"text",value:c?h??"":(m==null?void 0:m.value)??"",placeholder:m!=null&&m.is_set&&y.secret?"(secret set — type to replace)":y.placeholder??"(unset)",onChange:k=>d(y.key,k.target.value||null),className:"bg-panel-2 border border-border rounded px-2 py-1 text-sm text-text font-mono flex-1 placeholder:text-text-dim"}),c&&s.jsx(z,{size:"sm",variant:"ghost",onClick:()=>x(y.key),title:"discard change",children:s.jsx(Ih,{className:"w-3 h-3"})})]})]},y.key)})})]},v)),s.jsxs("div",{className:"sticky bottom-0 bg-bg/95 backdrop-blur border-t border-border py-3 -mx-8 px-8 flex justify-end gap-2",children:[s.jsx(z,{variant:"default",onClick:()=>i({}),disabled:Object.keys(l).length===0,children:"Discard all"}),s.jsxs(z,{variant:"primary",onClick:()=>void w(),disabled:Object.keys(l).length===0,children:["Save (",Object.keys(l).length," change",Object.keys(l).length===1?"":"s",")"]})]})]})}async function $d(e,t){const n=await fetch(e,t);if(!n.ok){const r=await n.text();throw new Error(`${(t==null?void 0:t.method)??"GET"} ${e} → ${n.status}: ${r.slice(0,200)}`)}return await n.json()}async function nv(e,t="recording.webm"){const n=new FormData;return n.append("audio",e,t),await(await fetch("/api/audio/transcribe",{method:"POST",body:n})).json()}function rv(e){return $d("/api/voice/save-note",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})}function sv(e){return $d("/api/voice/extract-decisions",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})}async function lv(e){const t=new FormData;return t.append("audio",e.file),t.append("project_id",String(e.project_id)),e.title&&t.append("title",e.title),e.session_id&&t.append("session_id",e.session_id),await(await fetch("/api/voice/meeting/process",{method:"POST",body:t})).json()}async function iv(e){var o;if(!((o=navigator.mediaDevices)!=null&&o.getUserMedia))throw new Error("mic API unavailable in this browser");const t=await navigator.mediaDevices.getUserMedia({audio:!0}),r=["audio/webm;codecs=opus","audio/webm","audio/mp4","audio/ogg;codecs=opus"].find(u=>MediaRecorder.isTypeSupported(u))??"",l=r?new MediaRecorder(t,{mimeType:r}):new MediaRecorder(t),i=[],a=Date.now();return l.addEventListener("dataavailable",u=>{u.data&&u.data.size>0&&i.push(u.data)}),l.addEventListener("stop",()=>{const u=new Blob(i,{type:l.mimeType||"audio/webm"});e(u,Date.now()-a),t.getTracks().forEach(f=>f.stop())}),l.start(),l}function av(){const[e,t]=g.useState({kind:"idle"}),[n,r]=g.useState([]),[l,i]=g.useState(null),[a,o]=g.useState("voice"),[u,f]=g.useState(""),p=g.useRef(null),[d,x]=g.useState(0);g.useEffect(()=>{Id({sort:"active"}).then(N=>{r(N);const _=localStorage.getItem("voice-project-id");_&&N.some(E=>String(E.id)===_)&&i(Number(_))}).catch(()=>{})},[]),g.useEffect(()=>(e.kind==="recording"?p.current=window.setInterval(()=>x(N=>N+1),250):p.current!==null&&(clearInterval(p.current),p.current=null),()=>{p.current!==null&&clearInterval(p.current)}),[e.kind]);function w(N){i(N),N!==null?localStorage.setItem("voice-project-id",String(N)):localStorage.removeItem("voice-project-id")}async function v(){try{const N=await iv((_,E)=>{t({kind:"recorded",blob:_,durationMs:E})});t({kind:"recording",startedAt:Date.now(),recorder:N})}catch(N){t({kind:"error",message:N instanceof Error?N.message:String(N)})}}function j(){e.kind==="recording"&&e.recorder.stop()}function y(){t({kind:"idle"}),f("")}async function m(){if(e.kind==="recorded"){t({kind:"transcribing"});try{const N=e.blob.type.includes("mp4")?"mp4":e.blob.type.includes("ogg")?"ogg":"webm",_=await nv(e.blob,`recording.${N}`);if(!_.ok||!_.text){t({kind:"error",message:_.error??"transcription returned empty"});return}f(_.text),t({kind:"transcribed",blob:e.blob,text:_.text,provider:_.provider??"unknown",model:_.model??"unknown",durationMs:e.durationMs})}catch(N){t({kind:"error",message:N instanceof Error?N.message:String(N)})}}}async function c(){var N;if(!(e.kind!=="transcribed"||u.trim()==="")){t({kind:"saving"});try{const _=a.split(",").map(F=>F.trim()).filter(Boolean),E=await rv({project_id:l??void 0,text:u.trim(),tags:_.length>0?_:["voice"]});if(!E.ok){t({kind:"error",message:E.error??"save failed"});return}t({kind:"done",message:`note #${(N=E.note)==null?void 0:N.id} saved${l?` to project #${l}`:" to inbox"}`})}catch(_){t({kind:"error",message:_ instanceof Error?_.message:String(_)})}}}async function h(){if(e.kind!=="transcribed"||u.trim()===""||l===null){l===null&&t({kind:"error",message:"pick a project to extract decisions into"});return}t({kind:"saving"});try{const N=await sv({project_id:l,text:u.trim()});if(!N.ok){t({kind:"error",message:N.error??"extract failed"});return}t({kind:"done",message:`${N.drafts_extracted??0} draft(s) created via ${N.provider}:${N.model} — open project Drafts tab to review`})}catch(N){t({kind:"error",message:N instanceof Error?N.message:String(N)})}}function k(){t({kind:"idle"}),f("")}const b=e.kind==="recording"?Math.floor((Date.now()-e.startedAt)/1e3):0;return s.jsxs("div",{className:"max-w-2xl mx-auto",children:[s.jsxs("header",{className:"border-b border-border pb-3 mb-6",children:[s.jsxs("h1",{className:"text-2xl text-text flex items-center gap-2",children:[s.jsx(Ni,{className:"w-6 h-6 text-accent"})," Voice capture"]}),s.jsx("p",{className:"text-text-muted text-xs mt-1",children:"Record audio → Whisper transcribe → save as note or extract decisions into drafts for review."})]}),s.jsxs("div",{className:"bg-panel border border-border rounded-lg p-6 mb-4",children:[s.jsx("label",{className:"block text-[11px] uppercase tracking-wider text-text-muted mb-2",children:"Project"}),s.jsxs("select",{value:l??"",onChange:N=>w(N.target.value?Number(N.target.value):null),className:"w-full bg-panel-2 border border-border rounded px-3 py-2 text-sm text-text",children:[s.jsx("option",{value:"",children:"(inbox — no project)"}),n.map(N=>s.jsxs("option",{value:N.id,children:[N.workspace?`[${N.workspace}] `:"",N.title]},N.id))]}),s.jsxs("div",{className:"flex flex-col items-center my-8",children:[e.kind==="idle"&&s.jsx(z,{variant:"primary",onClick:()=>void v(),className:"w-32 h-32 rounded-full flex items-center justify-center text-base",children:s.jsx(Ni,{className:"w-12 h-12"})}),e.kind==="recording"&&s.jsxs(s.Fragment,{children:[s.jsx(z,{variant:"danger",onClick:j,className:"w-32 h-32 rounded-full flex items-center justify-center animate-pulse",children:s.jsx(Uh,{className:"w-12 h-12"})}),s.jsxs("div",{className:"mt-3 text-warning text-sm font-mono",children:["recording ",b,"s"]})]}),e.kind==="recorded"&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"text-text text-sm",children:["recorded ",Math.floor(e.durationMs/1e3),"s"]}),s.jsx("audio",{controls:!0,className:"my-3",src:URL.createObjectURL(e.blob)}),s.jsxs("div",{className:"flex gap-2",children:[s.jsx(z,{variant:"default",onClick:y,children:s.jsx(jr,{className:"w-4 h-4"})}),s.jsx(z,{variant:"primary",onClick:()=>void m(),children:"Transcribe"})]})]}),e.kind==="transcribing"&&s.jsxs("div",{className:"text-warning text-sm flex items-center gap-2",children:[s.jsx(Yt,{className:"w-4 h-4 animate-spin"})," transcribing..."]}),e.kind==="transcribed"&&s.jsxs("div",{className:"w-full",children:[s.jsx("label",{className:"block text-[11px] uppercase tracking-wider text-text-muted mb-2",children:"Transcript (edit before saving)"}),s.jsx("textarea",{value:u,onChange:N=>f(N.target.value),rows:6,className:"w-full bg-panel-2 border border-border rounded px-3 py-2 text-sm text-text font-mono"}),s.jsxs("div",{className:"text-text-dim text-[10px] mt-1",children:["via ",e.provider,":",e.model," · ",Math.floor(e.durationMs/1e3),"s audio"]}),s.jsx("label",{className:"block text-[11px] uppercase tracking-wider text-text-muted mt-4 mb-2",children:"Tags (comma-separated, applied to note only)"}),s.jsx("input",{type:"text",value:a,onChange:N=>o(N.target.value),className:"w-full bg-panel-2 border border-border rounded px-3 py-2 text-sm text-text font-mono"}),s.jsxs("div",{className:"flex gap-2 mt-4 flex-wrap",children:[s.jsxs(z,{variant:"default",onClick:k,children:[s.jsx(jr,{className:"w-4 h-4 mr-1"})," Discard"]}),s.jsxs(z,{variant:"primary",onClick:()=>void c(),className:"flex items-center",children:[s.jsx($h,{className:"w-4 h-4 mr-1"})," Save as note"]}),s.jsxs(z,{variant:"primary",onClick:()=>void h(),disabled:l===null,className:"flex items-center",title:l===null?"pick a project first":"extract decisions to drafts",children:[s.jsx(Fh,{className:"w-4 h-4 mr-1"})," Extract decisions"]})]})]}),e.kind==="saving"&&s.jsxs("div",{className:"text-warning text-sm flex items-center gap-2",children:[s.jsx(Yt,{className:"w-4 h-4 animate-spin"})," saving..."]}),e.kind==="done"&&s.jsxs("div",{className:"text-success text-sm flex items-center gap-2 flex-col",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Rt,{className:"w-4 h-4"})," ",e.message]}),s.jsx(z,{variant:"primary",onClick:k,className:"mt-3",children:"Record another"})]}),e.kind==="error"&&s.jsxs("div",{className:"text-danger text-sm flex items-center gap-2 flex-col",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(at,{className:"w-4 h-4"})," ",e.message]}),s.jsx(z,{variant:"default",onClick:k,className:"mt-3",children:"Reset"})]})]})]}),s.jsx(ov,{projects:n,defaultProjectId:l}),s.jsxs("div",{className:"text-text-muted text-xs mt-6",children:[s.jsxs("p",{children:["Requires a transcription provider: ",s.jsx("code",{children:"SHINOBI_TRANSCRIPTION_PROVIDER"})," in ",s.jsx(X,{to:"/settings",className:"text-accent underline",children:"Settings"})," (or canonical ",s.jsx("code",{children:"GROQ_API_KEY"})," / ",s.jsx("code",{children:"OPENAI_API_KEY"}),")."]}),s.jsx("p",{className:"mt-1",children:`Install as PWA on mobile via browser's "Add to home screen" — works offline for read-only.`})]})]})}function ov({projects:e,defaultProjectId:t}){var y,m;const[n,r]=g.useState(null),[l,i]=g.useState(""),[a,o]=g.useState(t),[u,f]=g.useState(!1),[p,d]=g.useState(null),[x,w]=g.useState(null);g.useEffect(()=>{o(t)},[t]);async function v(){if(!n||a===null){w("pick an audio file and a project");return}f(!0),w(null),d(null);try{const c={file:n,project_id:a};l.trim()&&(c.title=l.trim());const h=await lv(c);if(!h.ok){w(h.error??"meeting processing failed");return}d(h)}catch(c){w(c instanceof Error?c.message:String(c))}finally{f(!1)}}function j(){r(null),i(""),d(null),w(null)}return s.jsxs("div",{className:"bg-panel border border-border rounded-lg p-6 mt-6",children:[s.jsxs("h2",{className:"text-sm text-text mb-2 flex items-center gap-2",children:[s.jsx(Hh,{className:"w-4 h-4 text-accent"})," Meeting capture (upload longer audio)"]}),s.jsxs("p",{className:"text-text-muted text-xs mb-4",children:["Upload a meeting recording (.mp3 / .m4a / .wav / .webm, max ~25 MB on Groq free tier). Whisper transcribes → transcript saved as a note tagged ",s.jsx("code",{children:"meeting"})," → decision extractor runs → review drafts on the project's Drafts tab."]}),s.jsx("label",{className:"block text-[11px] uppercase tracking-wider text-text-muted mb-2",children:"Project"}),s.jsxs("select",{value:a??"",onChange:c=>o(c.target.value?Number(c.target.value):null),className:"w-full bg-panel-2 border border-border rounded px-3 py-2 text-sm text-text mb-3",children:[s.jsx("option",{value:"",children:"(pick a project — required for meetings)"}),e.map(c=>s.jsxs("option",{value:c.id,children:[c.workspace?`[${c.workspace}] `:"",c.title]},c.id))]}),s.jsx("label",{className:"block text-[11px] uppercase tracking-wider text-text-muted mb-2",children:"Title (optional)"}),s.jsx("input",{type:"text",value:l,onChange:c=>i(c.target.value),placeholder:"e.g. Standup 2026-05-24",className:"w-full bg-panel-2 border border-border rounded px-3 py-2 text-sm text-text mb-3"}),s.jsx("label",{className:"block text-[11px] uppercase tracking-wider text-text-muted mb-2",children:"Audio file"}),s.jsx("input",{type:"file",accept:"audio/*,.mp3,.m4a,.wav,.webm,.ogg",onChange:c=>{var h;return r(((h=c.target.files)==null?void 0:h[0])??null)},className:"block w-full text-sm text-text-muted file:mr-3 file:py-1.5 file:px-3 file:rounded file:border-0 file:bg-accent file:text-bg file:cursor-pointer mb-3"}),n&&s.jsxs("div",{className:"text-text-dim text-[11px] mb-3",children:[n.name," · ",(n.size/1024/1024).toFixed(2)," MB",n.size>25*1024*1024&&s.jsx("span",{className:"text-warning ml-2",children:"⚠️ over 25 MB — Groq/OpenAI will reject. Pre-split with ffmpeg."})]}),s.jsxs("div",{className:"flex gap-2",children:[s.jsxs(z,{variant:"primary",onClick:()=>void v(),disabled:u||!n||a===null,children:[u?s.jsx(Yt,{className:"w-4 h-4 mr-1 animate-spin"}):s.jsx(Wh,{className:"w-4 h-4 mr-1"}),u?"processing...":"Process meeting"]}),(p||x)&&s.jsx(z,{variant:"default",onClick:j,children:"Reset"})]}),x&&s.jsxs("div",{className:"mt-4 px-3 py-2 rounded text-sm flex items-center gap-2 bg-danger/20 text-danger border border-danger/40",children:[s.jsx(at,{className:"w-4 h-4"})," ",x]}),p&&s.jsxs("div",{className:"mt-4 px-3 py-2 rounded text-sm bg-success/20 text-success border border-success/40",children:[s.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[s.jsx(Rt,{className:"w-4 h-4"})," Meeting processed"]}),s.jsxs("div",{className:"text-xs text-text grid grid-cols-[8rem_1fr] gap-y-1",children:[s.jsx("div",{className:"text-text-muted",children:"title"}),s.jsx("div",{children:p.title}),s.jsx("div",{className:"text-text-muted",children:"transcript"}),s.jsxs("div",{children:[(y=p.transcript_chars)==null?void 0:y.toLocaleString()," chars · ",((m=p.audio_duration_seconds)==null?void 0:m.toFixed(0))??"?","s audio · via ",p.transcription_provider,":",p.transcription_model]}),s.jsx("div",{className:"text-text-muted",children:"drafts extracted"}),s.jsxs("div",{children:[p.drafts_extracted??0," via ",p.extractor_provider,":",p.extractor_model]}),s.jsx("div",{className:"text-text-muted",children:"note id"}),s.jsxs("div",{children:["#",p.note_id]})]}),a!==null&&s.jsx(X,{to:`/projects/${a}/decision-drafts`,className:"inline-block mt-2 text-accent hover:underline text-xs",children:"→ Review drafts on project Drafts tab"})]})]})}const eu=4e3;function uv(){const[e,t]=g.useState(null),[n,r]=g.useState(null),[l,i]=g.useState(null),a=g.useCallback(async()=>{try{const d=await px();t(d),r(null)}catch(d){r(d instanceof Error?d.message:String(d))}},[]);g.useEffect(()=>{a();const d=setInterval(()=>void a(),eu);return()=>clearInterval(d)},[a]);async function o(d,x){i(d);try{await mx(d,x),await a()}catch(w){alert("respond failed: "+(w instanceof Error?w.message:String(w)))}finally{i(null)}}async function u(d){i(d);try{await hx(d),await a()}catch(x){alert("cancel failed: "+(x instanceof Error?x.message:String(x)))}finally{i(null)}}if(n)return s.jsxs("div",{className:"text-danger",children:["Error: ",n]});if(!e)return s.jsx("div",{className:"text-text-muted",children:"loading approvals..."});const f=e.filter(d=>d.status==="pending"),p=e.filter(d=>d.status!=="pending").slice(0,50);return s.jsxs("div",{className:"max-w-3xl",children:[s.jsxs("header",{className:"border-b border-border pb-3 mb-6 flex items-baseline justify-between",children:[s.jsx("h1",{className:"text-2xl text-text",children:"Approvals"}),s.jsxs("span",{className:"text-text-muted text-xs flex items-center gap-1",children:[s.jsx(Yt,{className:"w-3 h-3 animate-spin"}),"polling every ",eu/1e3,"s"]})]}),s.jsxs("section",{className:"mb-8",children:[s.jsxs("h2",{className:"text-sm text-text mb-3 uppercase tracking-wider text-text-muted",children:["Pending (",f.length,")"]}),f.length===0?s.jsxs("div",{className:"bg-panel border border-dashed border-border rounded p-6 text-center text-text-muted",children:["No pending approvals. Approvals appear when the agent calls ",s.jsx("code",{children:"request_approval"})," via MCP. They also fire web push to subscribed devices — see ",s.jsx(X,{to:"/push",className:"text-accent underline",children:"Push settings"}),"."]}):s.jsx("div",{className:"space-y-3",children:f.map(d=>s.jsxs("div",{id:`approval-${d.id}`,className:"bg-panel border border-warning/40 border-l-4 border-l-warning rounded-md p-4",children:[s.jsxs("div",{className:"flex items-baseline justify-between gap-3 mb-2",children:[s.jsxs("div",{className:"text-text-muted text-xs",children:["#",d.id,d.project_id&&s.jsxs(s.Fragment,{children:[" · project #",d.project_id]}),s.jsxs(s.Fragment,{children:[" · ",G(d.created_at)]})]}),s.jsx(le,{className:"bg-warning text-bg",children:"pending"})]}),s.jsx("div",{className:"text-text mb-3 whitespace-pre-wrap",children:d.prompt}),s.jsxs("div",{className:"flex flex-wrap gap-2",children:[d.options.map(x=>s.jsx(z,{variant:"primary",disabled:l===d.id,onClick:()=>void o(d.id,x),children:x},x)),s.jsx(z,{variant:"default",disabled:l===d.id,onClick:()=>void u(d.id),children:"Cancel"})]})]},d.id))})]}),s.jsxs("section",{children:[s.jsxs("h2",{className:"text-sm text-text mb-3 uppercase tracking-wider text-text-muted",children:["Recent (",p.length,")"]}),p.length===0?s.jsx("div",{className:"text-text-muted text-sm",children:"(none)"}):s.jsx("div",{className:"space-y-1.5",children:p.map(d=>s.jsxs("div",{className:"bg-panel border border-border rounded p-3 text-sm",children:[s.jsxs("div",{className:"flex items-baseline justify-between gap-3 mb-1",children:[s.jsxs("div",{className:"text-text-muted text-xs",children:["#",d.id,d.project_id&&s.jsxs(s.Fragment,{children:[" · project #",d.project_id]}),s.jsxs(s.Fragment,{children:[" · ",G(d.created_at)]})]}),d.status==="responded"?s.jsxs(le,{className:"bg-success text-bg",children:[s.jsx(Rt,{className:"w-3 h-3 inline mr-0.5"}),d.response_value]}):d.status==="expired"?s.jsx(le,{className:"bg-text-dim text-text",children:"expired"}):s.jsxs(le,{className:"bg-text-dim text-text",children:[s.jsx(at,{className:"w-3 h-3 inline mr-0.5"}),d.status]})]}),s.jsxs("div",{className:"text-text text-xs",children:[d.prompt.slice(0,200),d.prompt.length>200?"…":""]}),d.response_note&&s.jsxs("div",{className:"text-text-muted text-xs mt-1",children:["note: ",d.response_note]})]},d.id))})]})]})}function cv(e){const t="=".repeat((4-e.length%4)%4),n=(e+t).replace(/-/g,"+").replace(/_/g,"/"),r=atob(n),l=new ArrayBuffer(r.length),i=new Uint8Array(l);for(let a=0;a<r.length;a++)i[a]=r.charCodeAt(a);return i}function dv(){const[e,t]=g.useState({kind:"loading"}),[n,r]=g.useState(null),[l,i]=g.useState(!1),a=g.useCallback(async()=>{try{const y=await cx();let m=null,c="default";const h="serviceWorker"in navigator&&"PushManager"in window;if(h){c=Notification.permission;const b=await(await navigator.serviceWorker.ready).pushManager.getSubscription();m=(b==null?void 0:b.endpoint)??null}t({kind:"ready",subscriptions:y,selfEndpoint:m,permission:c,supported:h})}catch(y){t({kind:"error",message:y instanceof Error?y.message:String(y)})}},[]);g.useEffect(()=>{a()},[a]);async function o(){if(e.kind==="ready"){i(!0);try{const{public_key:y}=await ux(),h=(await(await navigator.serviceWorker.ready).pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:cv(y)})).toJSON();await dx({endpoint:h.endpoint,keys:{p256dh:h.keys.p256dh,auth:h.keys.auth},device_label:navigator.userAgent.slice(0,60)}),r({kind:"ok",text:"subscribed — try Test push below"}),await a()}catch(y){r({kind:"err",text:y instanceof Error?y.message:String(y)})}finally{i(!1)}}}async function u(){i(!0);try{const m=await(await navigator.serviceWorker.ready).pushManager.getSubscription();if(m&&await m.unsubscribe(),e.kind==="ready"&&m){const c=e.subscriptions.find(h=>h.endpoint===m.endpoint);c&&await Qo(c.id)}r({kind:"ok",text:"unsubscribed"}),await a()}catch(y){r({kind:"err",text:y instanceof Error?y.message:String(y)})}finally{i(!1)}}async function f(){i(!0);try{const y=await fx();r({kind:"ok",text:`pushed to ${y.succeeded}/${y.total} (failed ${y.failed}, pruned ${y.pruned_endpoints.length})`}),await a()}catch(y){r({kind:"err",text:y instanceof Error?y.message:String(y)})}finally{i(!1)}}async function p(y){i(!0);try{await Qo(y),await a()}catch(m){r({kind:"err",text:m instanceof Error?m.message:String(m)})}finally{i(!1)}}if(e.kind==="loading")return s.jsx("div",{className:"text-text-muted",children:"loading push state..."});if(e.kind==="error")return s.jsxs("div",{className:"text-danger",children:["Error: ",e.message]});const{subscriptions:d,selfEndpoint:x,permission:w,supported:v}=e,j=x!==null;return s.jsxs("div",{className:"max-w-3xl",children:[s.jsxs("header",{className:"border-b border-border pb-3 mb-6",children:[s.jsxs("h1",{className:"text-2xl text-text flex items-center gap-2",children:[s.jsx(ki,{className:"w-6 h-6 text-accent"})," Push notifications"]}),s.jsxs("p",{className:"text-text-muted text-xs mt-1",children:["Subscribe this device to receive push alerts when the agent fires ",s.jsx("code",{children:"request_approval"})," from MCP. Tap action buttons in the notification to respond from anywhere."]})]}),n&&s.jsxs("div",{className:`mb-4 px-4 py-2 rounded text-sm flex items-center gap-2 ${n.kind==="ok"?"bg-success/20 text-success border border-success/40":"bg-danger/20 text-danger border border-danger/40"}`,children:[n.kind==="ok"?s.jsx(Rt,{className:"w-4 h-4"}):s.jsx(at,{className:"w-4 h-4"}),n.text]}),s.jsxs("section",{className:"bg-panel border border-border rounded-lg p-5 mb-6",children:[s.jsx("h2",{className:"text-sm text-text mb-3",children:"This device"}),v?w==="denied"?s.jsxs("div",{className:"text-danger text-sm flex items-center gap-2",children:[s.jsx(Wo,{className:"w-4 h-4"})," Notifications blocked at browser level. Enable in browser settings and refresh."]}):s.jsxs("div",{className:"flex flex-wrap gap-2 items-center",children:[s.jsxs("span",{className:"text-text-muted text-sm mr-2",children:["Status: ",j?s.jsx("span",{className:"text-success",children:"subscribed"}):s.jsx("span",{className:"text-text-dim",children:"not subscribed"})]}),j?s.jsxs(z,{variant:"default",onClick:()=>void u(),disabled:l,children:[s.jsx(Wo,{className:"w-4 h-4 mr-1"})," Unsubscribe"]}):s.jsxs(z,{variant:"primary",onClick:()=>void o(),disabled:l,children:[s.jsx(ki,{className:"w-4 h-4 mr-1"})," Subscribe this device"]}),s.jsxs(z,{variant:"default",onClick:()=>void f(),disabled:l||d.length===0,title:d.length===0?"no subscriptions to push to":"send test push to all subscribed devices",children:[s.jsx(ka,{className:"w-4 h-4 mr-1"})," Test push"]})]}):s.jsxs("div",{className:"text-warning text-sm flex items-center gap-2",children:[s.jsx(at,{className:"w-4 h-4"})," Push API not supported in this browser (try Chrome / Firefox / Edge on desktop, or Safari 16+ as PWA on iOS)."]})]}),s.jsxs("section",{children:[s.jsxs("h2",{className:"text-sm text-text mb-3",children:["All subscribed devices (",d.length,")"]}),d.length===0?s.jsx("div",{className:"bg-panel border border-dashed border-border rounded p-6 text-center text-text-muted",children:"No devices subscribed yet."}):s.jsx("div",{className:"space-y-2",children:d.map(y=>s.jsxs("div",{className:"bg-panel border border-border rounded p-3 flex items-start justify-between gap-3",children:[s.jsxs("div",{className:"text-xs flex-1 min-w-0",children:[s.jsx("div",{className:"text-text font-medium",children:y.device_label??"(unknown device)"}),s.jsxs("div",{className:"text-text-muted mt-1 font-mono break-all",children:[y.endpoint.slice(0,100),"…"]}),s.jsxs("div",{className:"text-text-dim text-[10px] mt-1",children:["added ",G(y.created_at),y.last_sent_at?` · last push ${G(y.last_sent_at)}`:"",y.last_error?` · last error: ${y.last_error.slice(0,80)}`:""]})]}),s.jsx(z,{variant:"ghost",onClick:()=>void p(y.id),disabled:l,title:"remove subscription",children:s.jsx(jr,{className:"w-3 h-3"})})]},y.id))})]})]})}const fv=3e3;function pv(){const[e,t]=g.useState(null),[n,r]=g.useState(null),[l,i]=g.useState(!1),[a,o]=g.useState(null),u=g.useCallback(async()=>{try{const d=await _x();t(d),r(null)}catch(d){r(d instanceof Error?d.message:String(d))}},[]);g.useEffect(()=>{u();const d=setInterval(()=>void u(),fv);return()=>clearInterval(d)},[u]);async function f(){i(!0);try{const d=await Ex();o({kind:d.ok?"ok":"err",text:d.ok?"sync-available broadcast sent to peers":d.error??"broadcast failed"})}catch(d){o({kind:"err",text:d instanceof Error?d.message:String(d)})}finally{i(!1)}}if(n)return s.jsxs("div",{className:"text-danger",children:["Error: ",n]});if(!e)return s.jsx("div",{className:"text-text-muted",children:"loading relay status..."});const p=e.url!==null&&e.workspace!==null;return s.jsxs("div",{className:"max-w-3xl",children:[s.jsxs("header",{className:"border-b border-border pb-3 mb-6",children:[s.jsxs("h1",{className:"text-2xl text-text flex items-center gap-2",children:[s.jsx(Od,{className:"w-6 h-6 text-accent"})," Multi-agent relay"]}),s.jsxs("p",{className:"text-text-muted text-xs mt-1",children:["Real-time fan-out across multiple machines / agents working on the same workspace. When one agent runs ",s.jsx("code",{children:"shinobi sync push"}),", all other connected agents auto-pull within ~1.5s. Backed by a Cloudflare Worker + Durable Object — see ",s.jsx("code",{children:"relay-worker/"}),"."]})]}),a&&s.jsxs("div",{className:`mb-4 px-4 py-2 rounded text-sm flex items-center gap-2 ${a.kind==="ok"?"bg-success/20 text-success border border-success/40":"bg-danger/20 text-danger border border-danger/40"}`,children:[a.kind==="ok"?s.jsx(Rt,{className:"w-4 h-4"}):s.jsx(at,{className:"w-4 h-4"}),a.text]}),p?s.jsxs(s.Fragment,{children:[s.jsxs("section",{className:"bg-panel border border-border rounded-lg p-5 mb-4",children:[s.jsxs("div",{className:"flex items-center justify-between mb-3",children:[s.jsx("h2",{className:"text-sm text-text flex items-center gap-2",children:e.connected?s.jsxs(s.Fragment,{children:[s.jsx(Qh,{className:"w-4 h-4 text-success"}),s.jsx("span",{className:"text-success",children:"Connected"})]}):s.jsxs(s.Fragment,{children:[s.jsx(Ho,{className:"w-4 h-4 text-warning"}),s.jsx("span",{className:"text-warning",children:"Disconnected"}),e.reconnect_attempts>0&&s.jsxs("span",{className:"text-text-muted text-xs",children:["— attempt #",e.reconnect_attempts]})]})}),s.jsxs(z,{variant:"default",onClick:()=>void u(),disabled:l,children:[s.jsx(ja,{className:"w-3.5 h-3.5 mr-1"})," Refresh"]})]}),s.jsxs("dl",{className:"text-sm grid grid-cols-[10rem_1fr] gap-y-1.5",children:[s.jsx("dt",{className:"text-text-muted",children:"Agent ID"}),s.jsx("dd",{className:"text-text font-mono text-xs",children:e.agent_id}),s.jsx("dt",{className:"text-text-muted",children:"Workspace"}),s.jsx("dd",{className:"text-text font-mono text-xs",children:e.workspace}),s.jsx("dt",{className:"text-text-muted",children:"Relay URL"}),s.jsx("dd",{className:"text-text font-mono text-xs break-all",children:e.url}),s.jsx("dt",{className:"text-text-muted",children:"Last event"}),s.jsx("dd",{className:"text-text text-xs",children:e.last_event_at?s.jsxs(s.Fragment,{children:[s.jsx(le,{className:"bg-accent/20 text-accent mr-2",children:e.last_event_type}),G(e.last_event_at)]}):s.jsx("span",{className:"text-text-dim",children:"none"})}),e.last_error&&s.jsxs(s.Fragment,{children:[s.jsx("dt",{className:"text-danger",children:"Last error"}),s.jsx("dd",{className:"text-danger text-xs",children:e.last_error})]})]})]}),s.jsxs("section",{className:"bg-panel border border-border rounded-lg p-5",children:[s.jsx("h2",{className:"text-sm text-text mb-2",children:"Test broadcast"}),s.jsxs("p",{className:"text-text-muted text-xs mb-3",children:["Sends a ",s.jsx("code",{children:"sync-available"})," event to every other connected agent in this workspace. They will auto-pull the latest snapshot."]}),s.jsxs(z,{variant:"primary",onClick:()=>void f(),disabled:l||!e.connected,children:[s.jsx(ka,{className:"w-4 h-4 mr-1"})," Broadcast sync-available"]})]})]}):s.jsxs("div",{className:"bg-panel border border-dashed border-border rounded-lg p-6",children:[s.jsxs("h2",{className:"text-text mb-2 flex items-center gap-2",children:[s.jsx(Ho,{className:"w-4 h-4 text-text-muted"})," Relay not configured"]}),s.jsxs("p",{className:"text-text-muted text-sm mb-3",children:["Set ",s.jsx("code",{children:"SHINOBI_RELAY_URL"}),", ",s.jsx("code",{children:"SHINOBI_RELAY_TOKEN"}),", and ",s.jsx("code",{children:"SHINOBI_RELAY_WORKSPACE"})," in Settings to enable."]}),s.jsxs("ol",{className:"text-text-muted text-sm list-decimal pl-5 space-y-1",children:[s.jsxs("li",{children:["Deploy the Worker: ",s.jsx("code",{children:"cd relay-worker && npx wrangler deploy"})]}),s.jsxs("li",{children:["Set the secret: ",s.jsx("code",{children:"npx wrangler secret put SHINOBI_RELAY_TOKEN"})]}),s.jsxs("li",{children:["Configure each agent's ",s.jsx("code",{children:"~/.shinobi/.env"})," with matching URL/token/workspace and restart the dashboard."]})]})]})]})}function mv(){const[e,t]=g.useState(null),[n,r]=g.useState(null),[l,i]=g.useState(""),[a,o]=g.useState(!1),[u,f]=g.useState(null),[p,d]=g.useState(null),[x,w]=g.useState(null),v=g.useCallback(async()=>{try{const c=await jx();t(c),r(null)}catch(c){r(c instanceof Error?c.message:String(c))}},[]);g.useEffect(()=>{v()},[v]);async function j(){if(!l.trim()){f(null);return}o(!0);try{const c=await wx(l.trim());f(c.results)}catch(c){w({kind:"err",text:c instanceof Error?c.message:String(c)})}finally{o(!1)}}async function y(c){d(c);try{const h=await kx(c);w({kind:h.ok?"ok":"err",text:h.ok?`installed ${c} — restart dashboard to load tools`:(h.stderr||"install failed").slice(0,200)}),await v(),u&&await j()}catch(h){w({kind:"err",text:h instanceof Error?h.message:String(h)})}finally{d(null)}}async function m(c){d(c);try{const h=await Nx(c);w({kind:h.ok?"ok":"err",text:h.ok?`uninstalled ${c} — restart dashboard to drop tools`:(h.stderr||"uninstall failed").slice(0,200)}),await v(),u&&await j()}catch(h){w({kind:"err",text:h instanceof Error?h.message:String(h)})}finally{d(null)}}return n?s.jsxs("div",{className:"text-danger",children:["Error: ",n]}):e?s.jsxs("div",{className:"max-w-4xl",children:[s.jsxs("header",{className:"border-b border-border pb-3 mb-6",children:[s.jsxs("h1",{className:"text-2xl text-text flex items-center gap-2",children:[s.jsx(Rd,{className:"w-6 h-6 text-accent"})," Plugins"]}),s.jsxs("p",{className:"text-text-muted text-xs mt-1",children:["Extend Shinobi with community-maintained packages from npm. Install location: ",s.jsx("code",{children:e.install_prefix})]})]}),x&&s.jsxs("div",{className:`mb-4 px-4 py-2 rounded text-sm flex items-center gap-2 ${x.kind==="ok"?"bg-success/20 text-success border border-success/40":"bg-danger/20 text-danger border border-danger/40"}`,children:[x.kind==="ok"?s.jsx(Rt,{className:"w-4 h-4"}):s.jsx(at,{className:"w-4 h-4"}),x.text]}),s.jsxs("section",{className:"bg-panel border border-border rounded-lg p-5 mb-6",children:[s.jsx("h2",{className:"text-sm text-text mb-3",children:"Search npm registry"}),s.jsxs("div",{className:"flex gap-2 mb-3",children:[s.jsx("input",{type:"text",className:"flex-1 bg-bg border border-border rounded px-3 py-1.5 text-sm text-text",placeholder:"e.g. github, jira, time-tracking (looks under @shinobi/plugin-* and shinobi-plugin-*)",value:l,onChange:c=>i(c.target.value),onKeyDown:c=>{c.key==="Enter"&&j()}}),s.jsxs(z,{variant:"primary",onClick:()=>void j(),disabled:a,children:[s.jsx(wa,{className:"w-4 h-4 mr-1"})," Search"]})]}),u!==null&&(u.length===0?s.jsx("div",{className:"text-text-muted text-sm",children:"no matching plugins published yet"}):s.jsx("div",{className:"space-y-2",children:u.map(c=>s.jsxs("div",{className:"bg-bg border border-border rounded p-3 flex items-start justify-between gap-3",children:[s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsxs("div",{className:"flex items-baseline gap-2",children:[s.jsx("div",{className:"text-text font-medium",children:c.name}),s.jsxs("div",{className:"text-text-muted text-xs",children:["v",c.version,c.author?" · "+c.author:""]}),c.links.npm&&s.jsxs("a",{href:c.links.npm,target:"_blank",rel:"noreferrer",className:"text-accent text-xs hover:underline",children:["npm ",s.jsx(Ph,{className:"w-3 h-3 inline"})]})]}),s.jsx("div",{className:"text-text-muted text-xs mt-1",children:c.description||"(no description)"})]}),c.installed?s.jsxs(z,{variant:"default",onClick:()=>void m(c.name),disabled:p===c.name,children:[s.jsx(jr,{className:"w-3.5 h-3.5 mr-1"})," Uninstall"]}):s.jsxs(z,{variant:"primary",onClick:()=>void y(c.name),disabled:p===c.name,children:[s.jsx(Ch,{className:"w-3.5 h-3.5 mr-1"})," ",p===c.name?"installing…":"Install"]})]},c.name))}))]}),s.jsxs("section",{className:"mb-6",children:[s.jsxs("div",{className:"flex items-baseline justify-between mb-3",children:[s.jsxs("h2",{className:"text-sm text-text",children:["Installed (",e.installed.length,")"]}),s.jsxs("button",{onClick:()=>void v(),className:"text-[11px] uppercase tracking-wider text-accent hover:underline",children:[s.jsx(ja,{className:"w-3 h-3 inline mr-0.5"})," refresh"]})]}),e.installed.length===0?s.jsx("div",{className:"text-text-muted text-sm",children:"(no plugins installed yet)"}):s.jsx("div",{className:"space-y-2",children:e.installed.map(c=>s.jsxs("div",{className:"bg-panel border border-border rounded p-3 flex items-center justify-between gap-3",children:[s.jsxs("div",{children:[s.jsxs("div",{className:"text-text font-medium",children:[c.name," ",s.jsxs("span",{className:"text-text-muted text-xs",children:["v",c.version]})]}),s.jsx("div",{className:"text-text-muted text-xs",children:c.description})]}),s.jsx(z,{variant:"ghost",onClick:()=>void m(c.name),disabled:p===c.name,title:"uninstall",children:s.jsx(jr,{className:"w-3.5 h-3.5"})})]},c.name))})]}),s.jsxs("section",{children:[s.jsxs("h2",{className:"text-sm text-text mb-3",children:["Loaded at last startup (",e.loaded.length,")"]}),e.loaded.length===0?s.jsx("div",{className:"text-text-muted text-sm",children:"(none yet — install + restart dashboard)"}):s.jsx("div",{className:"space-y-2",children:e.loaded.map(c=>s.jsxs("div",{className:"bg-panel border border-border rounded p-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsx("div",{className:"text-text font-medium",children:c.name}),s.jsx(le,{className:c.source==="user"?"bg-warning/30 text-warning":"bg-accent/30 text-accent",children:c.source})]}),s.jsx("div",{className:"text-text-muted text-xs font-mono break-all mt-1",children:c.module_path}),c.tools_registered.length>0&&s.jsxs("div",{className:"text-text-dim text-[11px] mt-2",children:["tools: ",c.tools_registered.join(", ")]}),c.error&&s.jsxs("div",{className:"text-danger text-xs mt-2",children:["error: ",c.error]})]},c.name))})]})]}):s.jsx("div",{className:"text-text-muted",children:"loading plugins..."})}function hv(){const[e,t]=g.useState(null),[n,r]=g.useState(null),[l,i]=g.useState(!1),[a,o]=g.useState(null),u=g.useCallback(async()=>{try{t(await Sx()),r(null)}catch(p){r(p instanceof Error?p.message:String(p))}},[]);g.useEffect(()=>{u()},[u]);async function f(){i(!0);try{const p=await bx();p.ok?o({kind:"ok",text:`sent ${p.sent}/${p.attempted} events to ${p.endpoint}`}):o({kind:"err",text:p.error??"flush failed"}),await u()}catch(p){o({kind:"err",text:p instanceof Error?p.message:String(p)})}finally{i(!1)}}return n?s.jsxs("div",{className:"text-danger",children:["Error: ",n]}):e?s.jsxs("div",{className:"max-w-3xl",children:[s.jsxs("header",{className:"border-b border-border pb-3 mb-6",children:[s.jsxs("h1",{className:"text-2xl text-text flex items-center gap-2",children:[s.jsx(Ld,{className:"w-6 h-6 text-accent"})," Telemetry"]}),s.jsx("p",{className:"text-text-muted text-xs mt-1",children:"Anonymous, opt-in usage stats. Everything below stays in your local SQLite buffer until you flush it to an endpoint. No project content, task titles, decision bodies, prompts, or usernames are ever recorded."})]}),a&&s.jsxs("div",{className:`mb-4 px-4 py-2 rounded text-sm flex items-center gap-2 ${a.kind==="ok"?"bg-success/20 text-success border border-success/40":"bg-danger/20 text-danger border border-danger/40"}`,children:[a.kind==="ok"?s.jsx(Rt,{className:"w-4 h-4"}):s.jsx(at,{className:"w-4 h-4"}),a.text]}),s.jsxs("section",{className:"bg-panel border border-border rounded-lg p-5 mb-6",children:[s.jsx("h2",{className:"text-sm text-text mb-3",children:"Status"}),s.jsxs("dl",{className:"text-sm grid grid-cols-[12rem_1fr] gap-y-1.5",children:[s.jsx("dt",{className:"text-text-muted",children:"Recording"}),s.jsx("dd",{className:e.enabled?"text-success":"text-text-dim",children:e.enabled?"ON (SHINOBI_TELEMETRY=on)":"OFF (default)"}),s.jsx("dt",{className:"text-text-muted",children:"Endpoint"}),s.jsx("dd",{className:"text-text",children:e.endpoint_configured?"configured":s.jsx("span",{className:"text-text-dim",children:"local-only (no SHINOBI_TELEMETRY_ENDPOINT)"})}),s.jsx("dt",{className:"text-text-muted",children:"Total events"}),s.jsx("dd",{className:"text-text",children:e.total_events.toLocaleString()}),s.jsx("dt",{className:"text-text-muted",children:"Unsent"}),s.jsx("dd",{className:"text-text",children:e.unsent_events.toLocaleString()}),s.jsx("dt",{className:"text-text-muted",children:"Events last 7d"}),s.jsx("dd",{className:"text-text",children:e.last_7d_count.toLocaleString()}),s.jsx("dt",{className:"text-text-muted",children:"Last recorded"}),s.jsx("dd",{className:"text-text-muted text-xs",children:e.last_recorded_at?`${G(e.last_recorded_at)} ago`:"never"}),s.jsx("dt",{className:"text-text-muted",children:"Last sent"}),s.jsx("dd",{className:"text-text-muted text-xs",children:e.last_sent_at?`${G(e.last_sent_at)} ago`:"never"})]}),s.jsxs("div",{className:"mt-4 flex gap-2",children:[s.jsxs(z,{variant:"default",onClick:()=>void u(),children:[s.jsx(ja,{className:"w-3.5 h-3.5 mr-1"})," Refresh"]}),s.jsxs(z,{variant:"primary",onClick:()=>void f(),disabled:l||!e.endpoint_configured||e.unsent_events===0,children:[s.jsx(ka,{className:"w-3.5 h-3.5 mr-1"})," Flush unsent"]})]})]}),s.jsxs("section",{className:"mb-6",children:[s.jsx("h2",{className:"text-sm text-text mb-3",children:"Counts by event type (top 30)"}),e.by_event_type.length===0?s.jsxs("div",{className:"text-text-muted text-sm",children:["(no events recorded yet",!e.enabled&&s.jsxs(s.Fragment,{children:[" — enable in ",s.jsx(X,{to:"/settings",className:"text-accent hover:underline",children:"Settings"})," and restart the dashboard)"]})]}):s.jsxs("table",{className:"w-full text-sm",children:[s.jsx("thead",{children:s.jsxs("tr",{className:"text-[11px] uppercase tracking-wider text-text-muted text-left",children:[s.jsx("th",{className:"pb-2 pr-3",children:"Event type"}),s.jsx("th",{className:"pb-2 text-right",children:"Count"})]})}),s.jsx("tbody",{children:e.by_event_type.map(p=>s.jsxs("tr",{className:"border-b border-border/40",children:[s.jsx("td",{className:"py-1.5 pr-3 text-text font-mono text-xs",children:p.event_type}),s.jsx("td",{className:"py-1.5 text-text text-right",children:p.count.toLocaleString()})]},p.event_type))})]})]}),s.jsxs("section",{className:"text-text-muted text-xs",children:[s.jsx("h2",{className:"text-text text-sm mb-2",children:"What is recorded"}),s.jsxs("ul",{className:"list-disc pl-5 space-y-1",children:[s.jsxs("li",{children:[s.jsx("code",{children:"tool_called"})," — MCP tool name + ok flag"]}),s.jsxs("li",{children:[s.jsx("code",{children:"view_hit"})," — dashboard route bucket (e.g. ",s.jsx("code",{children:"/projects/:tab"}),") + HTTP status. Project IDs are stripped."]})]}),s.jsx("h2",{className:"text-text text-sm mt-4 mb-2",children:"What is NEVER recorded"}),s.jsxs("ul",{className:"list-disc pl-5 space-y-1",children:[s.jsx("li",{children:"Project titles, task titles, decision bodies, notes, plans, prompts, model output, code snippets, file paths."}),s.jsx("li",{children:"IP addresses, usernames, machine IDs."}),s.jsxs("li",{children:["The contents of ",s.jsx("code",{children:"~/.shinobi/.env"}),", API keys, or any setting value."]})]})]})]}):s.jsx("div",{className:"text-text-muted",children:"loading telemetry..."})}function xv(){return s.jsxs("div",{className:"text-center py-16",children:[s.jsx("div",{className:"text-6xl mb-4",children:"🥷"}),s.jsx("h1",{className:"text-2xl text-text mb-2",children:"Not found"}),s.jsx("p",{className:"text-text-muted mb-4",children:"The page you're looking for doesn't exist."}),s.jsx(X,{to:"/",className:"text-accent hover:underline",children:"← Back to home"})]})}function vv(){return s.jsx(ph,{children:s.jsx(lh,{children:s.jsxs(V,{element:s.jsx(Mx,{}),children:[s.jsx(V,{path:"/",element:s.jsx(zx,{})}),s.jsx(V,{path:"/settings",element:s.jsx(tv,{})}),s.jsx(V,{path:"/voice",element:s.jsx(av,{})}),s.jsx(V,{path:"/approvals",element:s.jsx(uv,{})}),s.jsx(V,{path:"/push",element:s.jsx(dv,{})}),s.jsx(V,{path:"/relay",element:s.jsx(pv,{})}),s.jsx(V,{path:"/plugins",element:s.jsx(mv,{})}),s.jsx(V,{path:"/telemetry",element:s.jsx(hv,{})}),s.jsx(V,{path:"/sessions",element:s.jsx(qx,{})}),s.jsx(V,{path:"/sessions/:sessionId",element:s.jsx(Zx,{})}),s.jsxs(V,{path:"/projects/:id",element:s.jsx($x,{}),children:[s.jsx(V,{index:!0,element:s.jsx(Fx,{})}),s.jsx(V,{path:"subtasks",element:s.jsx(Ax,{})}),s.jsx(V,{path:"decisions",element:s.jsx(Vx,{})}),s.jsx(V,{path:"decision-drafts",element:s.jsx(Wx,{})}),s.jsx(V,{path:"dead-ends",element:s.jsx(Hx,{})}),s.jsx(V,{path:"notes",element:s.jsx(Qx,{})}),s.jsx(V,{path:"plans",element:s.jsx(Kx,{})}),s.jsx(V,{path:"context",element:s.jsx(Yx,{})}),s.jsx(V,{path:"sessions",element:s.jsx(Jx,{})}),s.jsx(V,{path:"timeline",element:s.jsx(Gx,{})}),s.jsx(V,{path:"analytics",element:s.jsx(Xx,{})})]}),s.jsx(V,{path:"*",element:s.jsx(xv,{})})]})})})}md(document.getElementById("root")).render(s.jsx(g.StrictMode,{children:s.jsx(vv,{})}));
288
+ //# sourceMappingURL=index-BgInVUB2.js.map