toolroll 0.9.97 → 0.9.99

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/approval-authority.d.ts +10 -1
  3. package/dist/approval-authority.js +18 -2
  4. package/dist/browser/workspace.js +1 -1
  5. package/dist/browser-workspace.d.ts +4 -3
  6. package/dist/chat-actions.d.ts +40 -5
  7. package/dist/chat-actions.js +124 -13
  8. package/dist/chat-card.js +4 -1
  9. package/dist/chat-channel.d.ts +3 -0
  10. package/dist/chat-channel.js +24 -7
  11. package/dist/chat-decide.js +4 -2
  12. package/dist/chat-task-actions.js +1 -1
  13. package/dist/chat-terms.d.ts +8 -0
  14. package/dist/chat-terms.js +14 -0
  15. package/dist/chat-voice.js +1 -1
  16. package/dist/checkout-cleanup.js +2 -1
  17. package/dist/contracts/chat-actions.d.ts +6 -0
  18. package/dist/contracts/chat-actions.js +2 -0
  19. package/dist/contracts/cli.d.ts +6 -0
  20. package/dist/contracts/cli.js +3 -0
  21. package/dist/contracts/lead-tools.d.ts +17 -0
  22. package/dist/contracts/lead-tools.js +4 -1
  23. package/dist/contracts/store-json.d.ts +1 -0
  24. package/dist/deploy-phase-data.json +21 -0
  25. package/dist/deploy-phase.d.ts +37 -0
  26. package/dist/deploy-phase.js +64 -0
  27. package/dist/deploy-rescue.d.ts +2 -1
  28. package/dist/deploy-rescue.js +6 -7
  29. package/dist/desktop-update.d.ts +2 -2
  30. package/dist/fast-start.d.ts +83 -6
  31. package/dist/fast-start.js +112 -15
  32. package/dist/home-groups.d.ts +39 -0
  33. package/dist/home-groups.js +33 -0
  34. package/dist/lead-answer-eval.d.ts +7 -0
  35. package/dist/lead-answer-eval.js +6 -2
  36. package/dist/lead-capabilities.js +1 -1
  37. package/dist/lead-context.js +2 -2
  38. package/dist/lead-contract.d.ts +1 -1
  39. package/dist/lead-contract.js +10 -7
  40. package/dist/lead-doors.d.ts +32 -0
  41. package/dist/lead-doors.js +80 -14
  42. package/dist/lead-status.d.ts +3 -0
  43. package/dist/lead-status.js +8 -3
  44. package/dist/lead-tools.d.ts +20 -0
  45. package/dist/lead-tools.js +66 -3
  46. package/dist/lead-voice.js +1 -1
  47. package/dist/lead.js +18 -2
  48. package/dist/local-owner.js +2 -0
  49. package/dist/one-step-chat-schema.d.ts +22 -0
  50. package/dist/one-step-chat-schema.js +37 -0
  51. package/dist/operate.d.ts +27 -1
  52. package/dist/operate.js +206 -32
  53. package/dist/project-delete.js +9 -0
  54. package/dist/project-knowledge.d.ts +7 -7
  55. package/dist/publish.d.ts +2 -0
  56. package/dist/publish.js +1 -1
  57. package/dist/pull-request-flow.d.ts +4 -0
  58. package/dist/pull-request-flow.js +16 -1
  59. package/dist/release-adapters.js +30 -14
  60. package/dist/release-gate.d.ts +3 -3
  61. package/dist/release-gate.js +7 -4
  62. package/dist/release-next.d.ts +3 -3
  63. package/dist/release-next.js +13 -16
  64. package/dist/reply-voice.d.ts +23 -0
  65. package/dist/reply-voice.js +37 -0
  66. package/dist/scope.d.ts +6 -1
  67. package/dist/scope.js +3 -2
  68. package/dist/server/chat.js +4 -4
  69. package/dist/server/chrome.js +2 -2
  70. package/dist/server/home.d.ts +4 -3
  71. package/dist/server/home.js +33 -28
  72. package/dist/server/render-chat.js +11 -6
  73. package/dist/server/render-pages.js +2 -2
  74. package/dist/setup-guide.d.ts +2 -2
  75. package/dist/staged-runtimes.js +2 -1
  76. package/dist/store.d.ts +4 -2
  77. package/dist/store.js +35 -12
  78. package/dist/telegram-lead.js +69 -5
  79. package/dist/telegram-status.js +9 -4
  80. package/dist/telegram.d.ts +10 -0
  81. package/dist/telegram.js +92 -8
  82. package/dist/toolroll-update.js +3 -1
  83. package/dist/tui-contract.d.ts +2 -0
  84. package/dist/tui-source.js +3 -0
  85. package/dist/tui.js +41 -41
  86. package/dist/typed-start.d.ts +51 -0
  87. package/dist/typed-start.js +98 -0
  88. package/dist/wake-hub.d.ts +72 -0
  89. package/dist/wake-hub.js +151 -0
  90. package/package.json +1 -1
@@ -76,7 +76,7 @@ How bad is it?`})})]}),r==="schedule"&&(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx
76
76
  `)},r.key));continue}if(r.kind==="marker"){t.push((0,Re.jsx)("li",{className:"k-muted","data-terminal-marker":!0,children:`— ${r.words} —`},r.key));continue}let s=r.done,i=r.once?"":s===null?e.final?" [no result]":" [running]":s.ok===!0?"":s.ok===!1?" [failed]":" [ended without a result]",l=r.step==="command"&&r.target!==null?`$ ${r.target}`:`› ${L4[r.step]??S1[r.step]}${r.target===null?"":` ${r.target}`}`,u=s?.out??[],f=u.slice(-AQ);t.push((0,Re.jsxs)("li",{"data-terminal-step":r.step,children:[(0,Re.jsx)("span",{className:r.step==="command"?void 0:"k-muted",children:l}),i!==""&&(0,Re.jsx)("span",{className:s?.ok===!1?"agents-step-failed":"k-muted",children:i}),f.length>0&&(0,Re.jsxs)("span",{className:"agents-t-out k-muted","data-terminal-output":!0,children:[u.length>f.length?`… ${u.length-f.length} earlier lines
77
77
  `:"",f.join(`
78
78
  `)]})]},r.key))}for(;n<a.length;n+=1)o(a[n]);return(0,Re.jsx)("ol",{className:"agents-term","data-terminal":!0,children:t})}function I4({url:e,live:t,agent:a="Agent"}){let n=LQ(e,t),o=(0,Un.useRef)(null),r=(0,Un.useRef)(!0),s=(0,Un.useRef)(null),i=()=>{let y=o.current;return y===null?null:y.scrollHeight>y.clientHeight+1?y:y.closest("[data-agent-scroll]")??y},l=y=>{s.current?.(),s.current=null,o.current=y;let b=y?.closest("[data-agent-scroll]")??null;if(b===null)return;let g=()=>{i()===b&&(r.current=b.scrollTop+b.clientHeight>=b.scrollHeight-24)};b.addEventListener("scroll",g,{passive:!0}),s.current=()=>b.removeEventListener("scroll",g)};(0,Un.useEffect)(()=>()=>s.current?.(),[]),(0,Un.useLayoutEffect)(()=>{let y=i();y!==null&&r.current&&(y.scrollTop=y.scrollHeight)},[n.revision]);let u=RQ(n,a),[f,d]=(0,Un.useState)(EQ),c=y=>{d(y);try{window.localStorage.setItem(N4,y)}catch{}};(0,Un.useLayoutEffect)(()=>{let y=i();y!==null&&r.current&&(y.scrollTop=y.scrollHeight)},[f]);let m="Couldn't read the conversation just now. Trying again.",h=n.state==="off"?"Output from other computers isn't shown yet.":n.state==="unavailable"||n.state==="error"?m:n.state==="loading"?"Reading the conversation…":t?"Nothing yet. What the agent says and does shows here as it works.":"This agent left no transcript.";return(0,Re.jsxs)("section",{"aria-label":"Conversation",className:"agents-conv",children:[(0,Re.jsxs)("div",{className:"agents-conv-h",children:[(0,Re.jsx)("h3",{className:"k-sr",children:f==="terminal"?"Terminal":"Conversation"}),(0,Re.jsx)("span",{"data-conversation-view":f,children:(0,Re.jsx)(Ur,{label:"How to show it",current:f,onChange:y=>c(y==="terminal"?"terminal":"conversation"),items:[{key:"conversation",label:"Conversation"},{key:"terminal",label:"Terminal"}]})})]}),u.length===0?(0,Re.jsx)("p",{className:"agents-conv-empty","data-transcript-empty":!0,children:h}):(0,Re.jsxs)("div",{ref:l,tabIndex:0,"aria-label":"Agent conversation","data-agent-transcript":!0,className:"agents-tx",onScroll:y=>{let b=y.currentTarget;i()===b&&(r.current=b.scrollTop+b.clientHeight>=b.scrollHeight-24)},children:[n.older>0&&(0,Re.jsxs)("p",{className:"k-note",children:[n.older," earlier ",n.older===1?"note is":"notes are"," on the task page."]}),f==="terminal"?(0,Re.jsx)(MQ,{conversation:n}):(0,Re.jsx)("ol",{className:"agents-lines",children:u.map(y=>y.node)}),n.state==="off"&&(0,Re.jsx)("p",{className:"k-note","data-conversation-state":"off",children:h}),(n.state==="error"||n.state==="unavailable")&&(0,Re.jsx)("p",{role:"status",className:"k-note","data-conversation-state":"error",children:m})]}),n.detail==="base"&&(0,Re.jsxs)("p",{className:"k-note","data-conversation-detail":"base",children:["Commands were hidden for this run. ",(0,Re.jsx)("a",{className:"k-link",href:"/settings/project",children:"Change this in project settings"})]})]})}var je=O(he(),1);var J=O(G(),1),DQ=2e3,zy=200,T4=24,_Q=4,PQ=1e4,OQ=3e4,BQ=3e4,ym={working:"Working","needs-you":"Needs you",done:"Done",failed:"Failed",stopped:"Stopped",parked:"Parked"},R4={edit:"Editing",command:"Running",read:"Reading",search:"Searching for",lookup:"Looking up",plan:"Planning",delegate:"Handing off",tool:"Using a tool",session:"Starting",message:""},zQ={command:"Running a command",edit:"Editing files",read:"Reading the code",search:"Searching the code",lookup:"Looking something up"},HQ=e=>e.target?`${R4[e.kind??"tool"]??"Working"} ${e.target}`:zQ[e.kind??""]??R4[e.kind??"tool"]??"Working",D4=()=>({lines:[],open:[]});function A4(e,t,a){let n=[...e.lines],o=e.open;if(t.k==="say")n.push(...t.t??[]);else if(t.k==="step"){let r=HQ(t);n.push(`→ ${r}`),t.once!==!0&&t.id!==void 0&&(o=[...o.filter(([s])=>s!==t.id),[t.id,r]])}else t.k==="done"?(o=o.filter(([r])=>r!==t.id),n.push(...(t.out??[]).map(r=>` ${r}`)),t.ok===!1&&n.push("✗ failed")):t.k==="start"?n.push("The agent session started."):t.k==="cut"?n.push("A line was too long to show."):t.k==="cap"&&n.push("Output stopped at its size limit.");return{lines:n.slice(-a),open:o}}var N1=e=>e.open.at(-1)?.[1]??null,vm={main:D4(),children:new Map,mainState:"loading",subState:"loading",earlier:!1,restarted:!1,subRestarted:!1,over:!1},E4=e=>e!==void 0&&Number.isFinite(Date.parse(e))?Date.parse(e):Date.now();function FQ(e,t,a,n=zy){if(a.error!==void 0){if(a.error==="missing")return t==="main"?{...e,mainState:"ready"}:{...e,subState:"ready"};let l=a.error==="off"?"off":a.error==="gone"||a.error==="unavailable"?"unavailable":"error";return t==="main"?{...e,mainState:l}:{...e,subState:l}}let o=a.restarted===!0,r=t==="main"&&o?{lines:["Output restarted."],open:[]}:e.main,s=t==="sub"&&o?new Map:new Map(e.children),i=e.over&&!(t==="sub"&&o);for(let l of a.records??[]){if(t==="main"){l.s===void 0&&(r=A4(r,l,n));continue}if(l.k==="over"){i=!0;continue}if(l.s===void 0)continue;if(l.k==="child"){s.set(l.s,{...D4(),s:l.s,...l.via===void 0?{}:{via:l.via},desc:l.desc??"Subagent",startedAt:E4(l.at),endedAt:null,ok:null,expired:!1});continue}let u=s.get(l.s);u!==void 0&&(l.k==="end"?s.set(l.s,{...u,open:[],endedAt:l.at===void 0?0:Math.max(E4(l.at),u.startedAt),ok:l.ok??null}):s.set(l.s,{...u,...A4(u,l,n)}))}return{...e,main:r,children:s,over:i,earlier:e.earlier||a.earlier===!0,restarted:e.restarted||o,subRestarted:t==="sub"?e.subRestarted||o:e.subRestarted,...t==="main"?{mainState:"ready"}:{subState:"ready"}}}function qQ(e,t=(...a)=>fetch(...a)){let a=new Map,n=new Set,o=new Map,r=new Map,s=new Map,i=!1,l=null,u=()=>{if(i||l!==null||n.size===0)return;let m=Math.min(...[...n].map(h=>r.get(h)??Date.now()));l=setTimeout(()=>{l=null,c()},Math.max(50,m-Date.now()))},f=(m,h)=>{let y=Math.min(BQ,(s.get(m)??500)*2);s.set(m,y),r.set(m,Date.now()+Math.max(y,h??0)),n.add(m),e(m,{error:"retry"})},d=m=>{if(m===null)return;let h=Number(m);if(Number.isFinite(h)&&h>0)return h*1e3;let y=Date.parse(m);return Number.isFinite(y)?Math.max(0,y-Date.now()):void 0},c=()=>{if(!i){for(let m of[...n]){if(o.size>=_Q)break;if(o.has(m)||(r.get(m)??0)>Date.now())continue;n.delete(m);let h=new AbortController;o.set(m,h);let[y,b]=m.split(":"),g=a.get(m),x=setTimeout(()=>h.abort(),PQ);t(`/agents/live/${y}?file=${b}${g===void 0?"":`&cursor=${encodeURIComponent(g)}`}`,{signal:h.signal,credentials:"same-origin"}).then(async v=>{if(i)return;if(v.status===404){e(m,{error:"gone"});return}if(!v.ok){f(m,d(v.headers.get("retry-after")));return}let w=await v.json();i||(w.cursor!==void 0&&a.set(m,w.cursor),s.delete(m),r.delete(m),w.more===!0&&n.add(m),e(m,w))}).catch(()=>{i||f(m)}).finally(()=>{clearTimeout(x),o.delete(m),i||c()})}u()}};return{want(m){if(!i){for(let h of m)n.add(h);c()}},keep(m){for(let h of[...n,...o.keys(),...a.keys(),...r.keys()])m.has(h)||(o.get(h)?.abort(),o.delete(h),n.delete(h),a.delete(h),r.delete(h),s.delete(h))},dispose(){i=!0,l!==null&&clearTimeout(l);for(let m of o.values())m.abort();o.clear(),n.clear()}}}var Cd={working:"info",done:"success",failed:"danger",stopped:"neutral",parked:"neutral"},$Q="border-warning";function Ld({tone:e,children:t}){return(0,J.jsx)(Or,{size:"chip",dot:!0,tone:e,"data-live-chip":!0,children:t})}function Hy({lines:e,short:t,tall:a=!1}){let n=(0,je.useRef)(null),[o,r]=(0,je.useState)(!0),[s,i]=(0,je.useState)(!1);return(0,je.useLayoutEffect)(()=>{let l=n.current;l!==null&&(o&&(l.scrollTop=l.scrollHeight),i(l.scrollTop>1))}),e.length===0?(0,J.jsx)("p",{className:"text-[12px] text-muted-foreground",children:"No output yet."}):(0,J.jsxs)("div",{className:"relative",children:[(0,J.jsx)("div",{ref:n,tabIndex:0,role:"log","aria-label":"Output",onScroll:l=>{let u=l.currentTarget;r(u.scrollHeight-u.scrollTop-u.clientHeight<4),i(u.scrollTop>1)},className:pe("overflow-y-auto overscroll-contain rounded-md border border-border bg-code-bg px-2.5 py-2",a?"max-h-[60vh]":t?"max-h-[calc(4*1.5*12px+1rem)]":"max-h-[calc(12*1.5*12px+1rem)] phone:max-h-[calc(4*1.5*12px+1rem)]"),children:(0,J.jsx)("pre",{className:"whitespace-pre-wrap break-words font-mono text-[12px] leading-[1.5] text-foreground","data-live-lines":!0,children:e.join(`
79
- `)})}),s&&(0,J.jsx)("span",{"aria-hidden":"true",className:"pointer-events-none absolute inset-x-px top-px h-6 rounded-t-md bg-[linear-gradient(to_bottom,var(--so-code-bg)_30%,transparent)]"}),!o&&(0,J.jsx)("button",{type:"button",onClick:()=>r(!0),className:"absolute bottom-2 right-2 rounded-sm border border-border bg-card px-2 py-0.5 text-[11.5px] text-foreground shadow-pill phone:min-h-11",children:"Jump to latest"})]})}var _4=e=>pe("relative pl-5",!e&&"pb-2","before:absolute before:left-0 before:top-0 before:h-[22px] before:w-3.5 before:rounded-bl-sm before:border-b before:border-l before:border-border before:content-['']",!e&&"after:absolute after:bottom-0 after:left-0 after:top-[22px] after:border-l after:border-border after:content-['']");function I1({child:e,all:t,now:a,last:n}){let o=e.endedAt===null?"Working":e.ok===!1?"Ended with an error":e.ok===!0?"Done":"Ended",r=e.endedAt===null?"working":e.ok===!1?"failed":e.ok===!0?"done":"stopped",s=t.filter(i=>i.via===e.s);return(0,J.jsxs)("li",{className:_4(n),"data-live-child":e.s,children:[(0,J.jsxs)("article",{className:"flex flex-col gap-2 rounded-card border border-border bg-card p-3",children:[(0,J.jsxs)("header",{className:"flex items-start gap-2",children:[(0,J.jsx)("h3",{className:"line-clamp-2 min-w-0 flex-1 text-[13px] font-semibold leading-[1.35]",title:e.desc,children:e.desc}),(0,J.jsx)(Ld,{tone:Cd[r]??"info",children:o})]}),(0,J.jsxs)("p",{className:"flex gap-2 text-[12px] text-muted-foreground",children:[(0,J.jsx)("span",{className:"min-w-0 flex-1 truncate",children:e.endedAt===null?N1(e)??"":""}),(0,J.jsx)("span",{className:"shrink-0 tabular-nums",children:Vn(new Date(e.startedAt).toISOString(),e.endedAt??a)})]}),(0,J.jsx)(Hy,{lines:e.lines,short:!0})]}),s.length>0&&(0,J.jsx)("ul",{"aria-label":`Subagents of ${e.desc}`,className:"ml-4 mt-2 flex flex-col",children:s.map((i,l)=>(0,J.jsx)(I1,{child:i,all:t,now:a,last:l===s.length-1},i.s))})]})}function P4({tile:e,stream:t,streamed:a,showLive:n,tall:o=!1,lost:r=!1}){let s="text-[12px] text-muted-foreground",i="text-[11.5px] text-muted-foreground",l=!e.local||t.mainState==="off"?(0,J.jsx)("p",{className:s,children:"Output is on another computer."}):a?t.mainState==="unavailable"?(0,J.jsx)("p",{className:s,children:"Output unavailable."}):(0,J.jsxs)(J.Fragment,{children:[t.earlier&&(0,J.jsx)("p",{className:i,children:"Earlier output isn't shown."}),t.mainState==="error"&&(0,J.jsx)("p",{className:i,children:"Couldn't read the latest output. Retrying."}),t.mainState==="loading"?(0,J.jsx)("p",{className:s,children:"Loading output…"}):(0,J.jsx)(Hy,{lines:t.main.lines,short:!1,tall:o})]}):(0,J.jsxs)("p",{className:pe(s,"flex items-center gap-2"),children:["Not shown live.",(0,J.jsx)("button",{type:"button",onClick:n,className:"rounded-sm border border-border bg-card px-2 py-0.5 text-[11.5px] text-foreground phone:min-h-11",children:"Show live"})]});return(0,J.jsxs)(J.Fragment,{children:[r&&(0,J.jsx)("p",{className:i,children:"Reconnecting… these lines may not be the latest."}),l,t.subState==="unavailable"&&(0,J.jsx)("p",{className:i,children:"Subagents' output unavailable."}),t.subState==="error"&&(0,J.jsx)("p",{className:i,children:"Couldn't read the subagents' output. Retrying."}),t.subRestarted&&(0,J.jsx)("p",{className:i,children:"Subagents' output restarted."}),t.over&&(0,J.jsx)("p",{className:i,children:"More subagents started than are shown."})]})}function L1({tile:e,stream:t,streamed:a,now:n,repairs:o,streams:r,streamedIds:s,showLive:i,openRun:l,nested:u}){let f=e.state==="needs-you",d=e.why==="quiet"&&e.quietSince!==null?`Quiet for ${Vn(e.quietSince,n)}`:e.why==="question"?"Asked a question":e.endedAt===null?N1(t.main)??"":"",c=[...t.children.values()].filter(b=>!b.expired).sort((b,g)=>b.s-g.s),m=c.filter(b=>b.via===void 0||!c.some(g=>g.s===b.via)),h=[e.project?.split("/").pop(),e.role,e.agent,e.model].filter(Boolean).join(" · "),y=f?"needs":e.state;return(0,J.jsxs)("li",{className:pe("flex min-w-0 flex-col gap-2",u!==void 0&&_4(u.last)),"data-live-tile":e.runId,"data-live-state":e.state,children:[(0,J.jsxs)("article",{className:pe("flex min-w-0 flex-col gap-2.5 rounded-card border bg-card p-3.5",f?$Q:"border-border"),children:[(0,J.jsxs)("header",{className:"flex flex-col gap-1",children:[(0,J.jsxs)("div",{className:"flex items-start gap-2",children:[(0,J.jsx)("h2",{className:"line-clamp-2 min-w-0 flex-1 text-[15px] font-semibold leading-[1.3]",title:e.title,children:(0,J.jsx)("button",{type:"button","data-live-open":e.runId,onClick:()=>l(e.runId),className:"text-left hover:underline hover:underline-offset-4 phone:min-h-11",children:e.title})}),(0,J.jsx)(Ld,{tone:y==="needs"?"needs":Cd[y]??"info",children:ym[e.state]})]}),(0,J.jsx)("p",{className:"truncate font-mono text-[11px] text-muted-foreground",title:h,children:h})]}),(0,J.jsxs)("p",{className:"flex gap-2 text-[13px]",children:[(0,J.jsx)("span",{className:"min-w-0 flex-1 truncate",children:d}),(0,J.jsx)("span",{className:"shrink-0 text-[12px] tabular-nums text-muted-foreground",children:Vn(e.startedAt,e.endedAt===null?n:Date.parse(e.endedAt))})]}),(0,J.jsx)(P4,{tile:e,stream:t,streamed:a,showLive:()=>i(e.runId)})]}),o.length>0&&(0,J.jsx)("ul",{"aria-label":`Repairs of ${e.title}`,className:"ml-4 flex flex-col gap-2",children:o.map(b=>(0,J.jsx)(L1,{tile:b,stream:r.get(b.runId)??vm,streamed:s.has(b.runId),now:n,repairs:[],streams:r,streamedIds:s,showLive:i,openRun:l},b.runId))}),m.length>0&&(0,J.jsx)("ul",{"aria-label":`Subagents of ${e.title}`,className:"ml-4 flex flex-col",children:m.map((b,g)=>(0,J.jsx)(I1,{child:b,all:c,now:n,last:g===m.length-1},b.s))})]})}function UQ({runId:e,tile:t,stream:a,streamed:n,now:o,lost:r,onClose:s,showLive:i}){let l=(0,je.useRef)(null),u=[...a.children.values()].sort((d,c)=>d.s-c.s),f=u.filter(d=>d.via===void 0||!u.some(c=>c.s===d.via));return(0,J.jsx)(P0,{open:!0,onOpenChange:d=>{d||s()},children:(0,J.jsxs)(O0,{container:typeof document>"u"?void 0:document.querySelector("[data-view]")??void 0,children:[(0,J.jsx)(B0,{className:"ui-dialog-overlay"}),(0,J.jsxs)(z0,{"data-live-full":!0,"aria-describedby":void 0,onOpenAutoFocus:d=>{d.preventDefault(),l.current?.focus()},onCloseAutoFocus:d=>{d.preventDefault(),(document.querySelector(`[data-live-open="${e}"]`)??document.querySelector("[data-live-grid]"))?.focus()},className:"ui-dialog-content flex !w-[min(1100px,calc(100vw-48px))] flex-col gap-3 !p-5 phone:!bottom-0 phone:!left-0 phone:!top-auto phone:!max-h-[calc(100dvh-2rem)] phone:!w-full phone:!rounded-b-none phone:!p-4 phone:!pb-[max(1rem,env(safe-area-inset-bottom))] phone:![transform:none]",children:[(0,J.jsxs)("header",{className:"flex items-start gap-3",children:[(0,J.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,J.jsx)(H0,{className:"text-[18px] font-semibold leading-[1.3]","data-live-full-title":!0,children:t?.title??"This agent isn't on the grid anymore"}),t!==null&&(0,J.jsx)("p",{className:"truncate font-mono text-[11px] text-muted-foreground",children:[t.project?.split("/").pop(),t.role,t.agent,t.model].filter(Boolean).join(" · ")})]}),t!==null&&(0,J.jsx)(Ld,{tone:t.state==="needs-you"?"needs":Cd[t.state]??"info",children:ym[t.state]}),(0,J.jsx)(F0,{ref:l,className:"shrink-0 rounded-sm border border-border px-2.5 py-1 text-[12.5px] phone:min-h-11",children:"Close"})]}),t!==null&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)("p",{className:"flex items-center gap-3 text-[13px]",children:[(0,J.jsx)("span",{className:"min-w-0 flex-1 truncate",children:t.why==="quiet"&&t.quietSince!==null?`Quiet for ${Vn(t.quietSince,o)}`:t.why==="question"?"Asked a question":t.endedAt===null?N1(a.main)??"":""}),(0,J.jsx)("span",{className:"shrink-0 text-[12px] tabular-nums text-muted-foreground",children:Vn(t.startedAt,t.endedAt===null?o:Date.parse(t.endedAt))}),t.taskHref!==null&&(0,J.jsx)("a",{href:t.taskHref,className:"shrink-0 text-[12.5px] underline decoration-border underline-offset-4 hover:decoration-current phone:inline-flex phone:min-h-11 phone:items-center",children:"Open task"})]}),(0,J.jsx)(P4,{tile:t,stream:a,streamed:n,showLive:i,tall:!0,lost:r}),f.length>0&&(0,J.jsxs)("section",{"aria-label":"Subagents",className:"flex flex-col gap-2",children:[(0,J.jsxs)("h3",{className:"text-[13px] font-semibold",children:["Subagents ",(0,J.jsx)("span",{className:"font-normal tabular-nums text-muted-foreground",children:u.length})]}),(0,J.jsx)("ul",{className:"flex flex-col",children:f.map((d,c)=>(0,J.jsx)(I1,{child:d,all:u,now:o,last:c===f.length-1},d.s))})]})]})]})]})})}var O4=e=>["lead chat",e.project?.split("/").pop(),e.stepAt.length>1?`step ${e.stepAt.length}`:null].filter(Boolean).join(" · "),VQ={lead:"lead chat",project:"project chat",task:"task chat"};function jQ({thread:e,runs:t,label:a,render:n}){return t.length===0?null:(0,J.jsx)("ul",{"aria-label":a,className:"ml-4 flex flex-col","data-live-filed":e,children:t.map((o,r)=>n(o,r===t.length-1))})}function KQ({lead:e,now:t,openLead:a}){return(0,J.jsxs)("article",{className:"flex min-w-0 flex-col gap-2.5 rounded-card border border-border bg-card p-3.5",children:[(0,J.jsxs)("header",{className:"flex flex-col gap-1",children:[(0,J.jsxs)("div",{className:"flex items-start gap-2",children:[(0,J.jsx)("h2",{className:"line-clamp-2 min-w-0 flex-1 text-[15px] font-semibold leading-[1.3]",title:e.title,children:(0,J.jsx)("button",{type:"button","data-live-open-lead":e.thread,onClick:()=>a(e.thread),className:"text-left hover:underline hover:underline-offset-4 phone:min-h-11",children:e.title})}),(0,J.jsx)(Ld,{tone:Cd[e.state]??"info",children:ym[e.state]})]}),(0,J.jsx)("p",{className:"truncate font-mono text-[11px] text-muted-foreground",children:O4(e)})]}),(0,J.jsxs)("p",{className:"flex gap-2 text-[13px]",children:[(0,J.jsx)("span",{className:"min-w-0 flex-1 truncate",children:e.doing??""}),(0,J.jsx)("span",{className:"shrink-0 text-[12px] tabular-nums text-muted-foreground",children:Vn(e.startedAt,e.endedAt===null?t:Date.parse(e.endedAt))})]}),e.earlier&&(0,J.jsx)("p",{className:"text-[11.5px] text-muted-foreground",children:"Earlier lines aren't shown."}),(0,J.jsx)(Hy,{lines:e.lines,short:!1})]})}function M4({thread:e,lead:t,runs:a,now:n,openLead:o,render:r}){let s=[...new Set(a.map(l=>l.project?.split("/").pop()).filter(Boolean))].join(", "),i=a.length===0?"":`Filed by ${VQ[a[0].filedBy.chat]}${s===""?"":` · ${s}`}`;return(0,J.jsxs)("li",{className:"flex min-w-0 flex-col gap-2",...t!==null?{"data-live-lead":e,"data-live-state":t.state}:{"data-live-filed-group":e},children:[t!==null?(0,J.jsx)(KQ,{lead:t,now:n,openLead:o}):(0,J.jsx)("p",{className:"truncate text-[12px] text-muted-foreground",title:i,children:i}),(0,J.jsx)(jQ,{thread:e,runs:a,label:t!==null?`Filed by ${t.title}`:i,render:r})]})}function GQ({thread:e,lead:t,now:a,lost:n,onClose:o,filed:r}){let s=(0,je.useRef)(null),i="shrink-0 text-[12.5px] underline decoration-border underline-offset-4 hover:decoration-current phone:inline-flex phone:min-h-11 phone:items-center";return(0,J.jsx)(P0,{open:!0,onOpenChange:l=>{l||o()},children:(0,J.jsxs)(O0,{container:typeof document>"u"?void 0:document.querySelector("[data-view]")??void 0,children:[(0,J.jsx)(B0,{className:"ui-dialog-overlay"}),(0,J.jsxs)(z0,{"data-live-full":!0,"aria-describedby":void 0,onOpenAutoFocus:l=>{l.preventDefault(),s.current?.focus()},onCloseAutoFocus:l=>{l.preventDefault(),(document.querySelector(`[data-live-open-lead="${e}"]`)??document.querySelector("[data-live-grid]"))?.focus()},className:"ui-dialog-content flex !w-[min(1100px,calc(100vw-48px))] flex-col gap-3 !p-5 phone:!bottom-0 phone:!left-0 phone:!top-auto phone:!max-h-[calc(100dvh-2rem)] phone:!w-full phone:!rounded-b-none phone:!p-4 phone:!pb-[max(1rem,env(safe-area-inset-bottom))] phone:![transform:none]",children:[(0,J.jsxs)("header",{className:"flex items-start gap-3",children:[(0,J.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,J.jsx)(H0,{className:"text-[18px] font-semibold leading-[1.3]","data-live-full-title":!0,children:t?.title??"This reply isn't on the grid anymore"}),t!==null&&(0,J.jsx)("p",{className:"truncate font-mono text-[11px] text-muted-foreground",children:O4(t)})]}),t!==null&&(0,J.jsx)(Ld,{tone:Cd[t.state]??"info",children:ym[t.state]}),(0,J.jsx)(F0,{ref:s,className:"shrink-0 rounded-sm border border-border px-2.5 py-1 text-[12.5px] phone:min-h-11",children:"Close"})]}),t!==null&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)("p",{className:"flex items-center gap-3 text-[13px]",children:[(0,J.jsx)("span",{className:"min-w-0 flex-1 truncate",children:t.doing??""}),(0,J.jsx)("span",{className:"shrink-0 text-[12px] tabular-nums text-muted-foreground",children:Vn(t.startedAt,t.endedAt===null?a:Date.parse(t.endedAt))}),(0,J.jsx)("a",{href:t.chatHref,className:i,children:"Open chat"}),t.taskHref!==null&&(0,J.jsx)("a",{href:t.taskHref,className:i,children:"Open task"})]}),t.earlier&&(0,J.jsx)("p",{className:"text-[11.5px] text-muted-foreground",children:"Earlier lines aren't shown."}),(0,J.jsx)(Hy,{lines:t.lines,short:!1,tall:!0})]}),n&&(t!==null||r.length>0)&&(0,J.jsx)("p",{className:"text-[11.5px] text-muted-foreground",children:"Reconnecting… these lines may not be the latest."}),r.length>0&&(0,J.jsxs)("section",{"aria-label":"Tasks it filed",className:"flex flex-col gap-2","data-live-full-filed":!0,children:[(0,J.jsxs)("h3",{className:"text-[13px] font-semibold",children:["Tasks it filed ",(0,J.jsx)("span",{className:"font-normal tabular-nums text-muted-foreground",children:r.length})]}),(0,J.jsx)("ul",{className:"flex flex-col gap-1.5",children:r.map(l=>(0,J.jsxs)("li",{className:"flex items-center gap-2 text-[13px]",children:[(0,J.jsx)("span",{className:"min-w-0 flex-1 truncate",title:l.title,children:l.title}),(0,J.jsx)(Ld,{tone:l.state==="needs-you"?"needs":Cd[l.state]??"info",children:ym[l.state]}),l.taskHref!==null&&(0,J.jsx)("a",{href:l.taskHref,className:i,children:"Open task"})]},l.runId))})]})]})]})})}function WQ({working:e,needsYou:t,shownLive:a,local:n}){let o=r=>(0,J.jsx)("span",{className:"font-semibold tabular-nums text-foreground",children:r});return(0,J.jsxs)("p",{className:"text-[13px] text-muted-foreground","data-live-headline":!0,children:[o(e)," ",e===1?"agent":"agents"," working",t>0&&(0,J.jsxs)(J.Fragment,{children:[" · ",o(t)," ",t===1?"needs":"need"," you"]}),n>a&&(0,J.jsxs)(J.Fragment,{children:[" · ",o(a)," of ",o(n)," shown live"]})]})}function B4(){let[e,t]=(0,je.useState)([]),[a,n]=(0,je.useState)([]),[o,r]=(0,je.useState)([]),[s,i]=(0,je.useState)(new Map),[l,u]=(0,je.useState)("loading"),[f,d]=(0,je.useState)(!1),[c,m]=(0,je.useState)(0),h=(0,je.useRef)(!1),y=(0,je.useRef)(!1),[b,g]=(0,je.useState)(!1),x=Wr(1e3),v=(0,je.useRef)(null),w=()=>{let W=Number(new URLSearchParams(location.search).get("run"));return Number.isSafeInteger(W)&&W>0?W:null},[k,C]=(0,je.useState)(w),N=(0,je.useRef)(k);N.current=k;let S=(0,je.useRef)(new Set),T=(0,je.useRef)(null),q=(0,je.useRef)(0);(0,je.useEffect)(()=>{let W=qQ((Ie,ze)=>{let[lt,rt]=Ie.split(":");i(Ze=>new Map(Ze).set(Number(lt),FQ(Ze.get(Number(lt))??vm,rt,ze,Number(lt)===N.current?DQ:zy)))});return v.current=W,()=>{W.dispose(),v.current=null}},[]);let[z,U]=(0,je.useState)([]),$=[...e,...o.filter(W=>!e.some(Ie=>Ie.runId===W.runId))].filter(W=>W.local),L=new Set([...new Set([...k!==null&&$.some(W=>W.runId===k)?[k]:[],...z.filter(W=>$.some(Ie=>Ie.runId===W)),...$.map(W=>W.runId)])].slice(0,T4)),I=[...L].sort((W,Ie)=>W-Ie).join(",");(0,je.useEffect)(()=>{let W=I===""?[]:I.split(",").flatMap(Ie=>[`${Ie}:main`,`${Ie}:sub`]);v.current?.keep(new Set(W)),v.current?.want(W)},[I]),S.current=L,(0,je.useEffect)(()=>{let W=()=>C(w());return window.addEventListener("popstate",W),()=>window.removeEventListener("popstate",W)},[]);let R=W=>{N.current!==W&&(N.current=W,history.pushState({liveRun:W},"",`/agents?view=live&run=${W}`),C(W))},A=()=>{let W=N.current;W!==null&&(N.current=null,history.state?.liveRun===W?history.back():history.replaceState(null,"","/agents?view=live"),C(null))},H=(0,je.useRef)(k);(0,je.useEffect)(()=>{let W=H.current;H.current=k,!(W===null||W===k)&&i(Ie=>{let ze=Ie.get(W);if(ze===void 0)return Ie;let lt=new Map([...ze.children].map(([rt,Ze])=>[rt,{...Ze,lines:Ze.lines.slice(-zy)}]));return new Map(Ie).set(W,{...ze,main:{...ze.main,lines:ze.main.lines.slice(-zy)},children:lt})})},[k]);let M=()=>{if(w()!==null)return null;let W=Number(new URLSearchParams(location.search).get("lead"));return Number.isSafeInteger(W)&&W>0?W:null},[_,F]=(0,je.useState)(M),Q=(0,je.useRef)(_);Q.current=_,(0,je.useEffect)(()=>{let W=()=>F(M());return window.addEventListener("popstate",W),()=>window.removeEventListener("popstate",W)},[]);let ue=W=>{Q.current!==W&&(Q.current=W,history.pushState({liveLead:W},"",`/agents?view=live&lead=${W}`),F(W))},oe=()=>{let W=Q.current;W!==null&&(Q.current=null,history.state?.liveLead===W?history.back():history.replaceState(null,"","/agents?view=live"),F(null))},Z=W=>U(Ie=>[W,...Ie.filter(ze=>ze!==W)].slice(0,T4)),ne=(0,je.useCallback)(()=>{let W=++q.current;fetch("/agents/live",{credentials:"same-origin"}).then(Ie=>Ie.ok?Ie.json():null).then(Ie=>{if(W===q.current){if(Ie===null){u(ze=>ze==="ready"?"ready":"error");return}t(Ie.tiles),n(Ie.leads??[]),u("ready"),v.current?.want([...S.current].flatMap(ze=>[`${ze}:main`,`${ze}:sub`]))}}).catch(()=>{W===q.current&&u(Ie=>Ie==="ready"?"ready":"error")})},[]);(0,je.useEffect)(()=>{ne()},[ne]),hn("agents-live",W=>{if(W==="lost"||W==="retrying"){d(!0);return}(W==="change"||W==="reload")&&(d(!1),ne())}),(0,je.useEffect)(()=>{fetch("/term/state",{credentials:"same-origin"}).then(W=>W.ok?W.json():null).then(W=>m((W?.sessions??[]).filter(Ie=>Ie.endedAt===null).length)).catch(()=>{})},[]);let le=(0,je.useCallback)(W=>r(Ie=>[...Ie.flatMap(lt=>{let rt=e.find(Ze=>Ze.runId===lt.runId);return rt!==void 0?[rt]:W?[lt]:[]}),...e.filter(lt=>!Ie.some(rt=>rt.runId===lt.runId)).sort((lt,rt)=>Date.parse(lt.startedAt)-Date.parse(rt.startedAt))]),[e]);(0,je.useEffect)(()=>{le(h.current||y.current)},[le]),(0,je.useEffect)(()=>{y.current&&T.current!==null&&!T.current.contains(document.activeElement)&&K(null,!1)}),(0,je.useEffect)(()=>{b||i(W=>{let Ie=!1,ze=new Map(W);for(let[lt,rt]of W){let Ze=[...rt.children.values()].filter($t=>!$t.expired&&$t.endedAt!==null&&x-$t.endedAt>=OQ);if(Ze.length===0)continue;let Wa=new Map(rt.children);for(let $t of Ze)Wa.set($t.s,{...$t,expired:!0});ze.set(lt,{...rt,children:Wa}),Ie=!0}return Ie?ze:W})},[x,b,s]);let K=(W,Ie)=>{W!==null&&(h.current=W),Ie!==null&&(y.current=Ie);let ze=h.current||y.current;g(ze),ze||le(!1)},B=new Set(o.map(W=>W.runId)),X=W=>o.filter(Ie=>Ie.role==="repair"&&Ie.parentRun===W),de=o.filter(W=>!(W.role==="repair"&&W.parentRun!==null&&B.has(W.parentRun))),fe=W=>de.filter(Ie=>Ie.filedBy?.thread===W),Se=(W,Ie)=>(0,J.jsx)(L1,{tile:W,stream:s.get(W.runId)??vm,streamed:L.has(W.runId),now:x,repairs:X(W.runId),streams:s,streamedIds:L,showLive:Z,openRun:R,nested:{last:Ie}},W.runId),Ee=o.filter(W=>W.endedAt===null).length+a.filter(W=>W.endedAt===null).length,Oe=o.filter(W=>W.state==="needs-you").length,Ue=e.length!==o.length||e.some(W=>!B.has(W.runId));return(0,J.jsxs)("section",{className:"flex w-full flex-col gap-4 outline-none","data-live-grid":!0,"aria-label":"Live",tabIndex:-1,children:[(0,J.jsxs)("div",{className:"flex flex-wrap items-baseline gap-x-3 gap-y-1 phone:sticky phone:top-0 phone:z-10 phone:bg-card phone:py-2",children:[(0,J.jsx)(WQ,{working:Ee,needsYou:Oe,shownLive:L.size,local:e.filter(W=>W.local).length}),Ue&&b&&(0,J.jsx)("p",{className:"text-[12px] text-muted-foreground",children:"Changes wait while you look."}),f&&(0,J.jsx)("p",{className:"text-[12px] text-muted-foreground",role:"status",children:"Reconnecting…"})]}),l==="error"?(0,J.jsx)("p",{className:"text-[13px] text-muted-foreground",role:"status",children:"Couldn't load the agents. Retrying."}):l==="ready"&&de.length===0&&a.length===0?(0,J.jsx)("p",{className:"text-[13px] text-muted-foreground",children:"No agents running."}):(0,J.jsxs)("ul",{ref:T,className:"grid items-start gap-4 [grid-template-columns:repeat(auto-fill,minmax(min(100%,340px),1fr))]",onPointerEnter:()=>K(!0,null),onPointerLeave:()=>K(!1,null),onFocus:()=>K(null,!0),onBlur:W=>{W.currentTarget.contains(W.relatedTarget)||K(null,!1)},children:[a.filter(W=>fe(W.thread).length===0).map(W=>(0,J.jsx)(M4,{thread:W.thread,lead:W,runs:[],now:x,openLead:ue,render:Se},`lead-${W.thread}`)),de.map(W=>{let Ie=W.filedBy?.thread;if(Ie===void 0)return(0,J.jsx)(L1,{tile:W,stream:s.get(W.runId)??vm,streamed:L.has(W.runId),now:x,repairs:X(W.runId),streams:s,streamedIds:L,showLive:Z,openRun:R},W.runId);let ze=fe(Ie),lt=a.find(rt=>rt.thread===Ie);return ze[0]!==W?null:(0,J.jsx)(M4,{thread:Ie,lead:lt??null,runs:ze,now:x,openLead:ue,render:Se},`group-${Ie}`)})]}),k!==null&&(0,J.jsx)(UQ,{runId:k,tile:[...e,...o].find(W=>W.runId===k)??null,stream:s.get(k)??vm,streamed:L.has(k),now:x,lost:f,onClose:A,showLive:()=>Z(k)},k),_!==null&&(0,J.jsx)(GQ,{thread:_,lead:a.find(W=>W.thread===_)??null,now:x,lost:f,onClose:oe,filed:o.filter(W=>W.filedBy?.thread===_)},`lead-${_}`),c>0&&(0,J.jsx)("p",{className:"border-t border-border pt-3 text-[12px] text-muted-foreground",children:(0,J.jsxs)("a",{href:"/term",className:"inline-block underline decoration-border underline-offset-4 hover:text-foreground hover:decoration-current phone:min-h-11 phone:py-3",children:[(0,J.jsx)("span",{className:"tabular-nums",children:c})," ",c===1?"terminal":"terminals"," you're driving"]})})]})}var D=O(G(),1);function Vn(e,t){let a=Math.max(0,Math.floor((t-Date.parse(e))/1e3));if(!Number.isFinite(a))return"";if(a<60)return`${a} s`;let n=Math.floor(a/60);if(n<60)return`${n} min`;let o=Math.floor(n/60);return n%60===0?`${o} h`:`${o} h ${n%60} min`}function R1(e,t){if(e.endedAt===null)return`Running ${Vn(e.startedAt,t)}`;let a=t-Date.parse(e.endedAt);return`Ran ${Vn(e.startedAt,Date.parse(e.endedAt))} · finished ${a<6e4?"just now":`${Vn(e.endedAt,t)} ago`}`}var A1=e=>{let t=Date.parse(e);return Number.isNaN(t)?"":new Date(t).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})},xm=(e,t)=>{let a=Date.parse(e);return Number.isNaN(a)?"":new Date(a).toDateString()===new Date(t).toDateString()?A1(e):new Date(a).toLocaleString([],{weekday:"short",hour:"2-digit",minute:"2-digit"})},Nd=(e,t,a)=>`${e} ${e===1?t:a}`;function E1(e){return e.group==="needs-you"?{word:e.label,tone:"ask"}:e.group==="stuck"?{word:"Stuck",tone:""}:e.group==="working"?{word:"Building",tone:"live"}:e.label==="Done"?{word:"Finished",tone:"done"}:e.label==="No changes"?{word:"No changes",tone:"done"}:e.label==="Failed"?{word:"Failed",tone:"failed"}:{word:e.label,tone:""}}function XQ({row:e}){let{word:t,tone:a}=E1(e);return(0,D.jsx)("span",{className:"agents-chip","data-agent-state":e.label,children:(0,D.jsx)($e,{word:t,tone:a})})}function YQ({row:e}){let t=Wr();return(0,D.jsx)("time",{dateTime:e.endedAt??e.startedAt,className:"k-num","data-agent-time":!0,children:R1(e,t)})}function q4({text:e}){let[t,a]=(0,Bt.useState)("no");return(0,D.jsxs)("span",{className:"agents-copy",children:[(0,D.jsx)("code",{className:"k-code",children:e}),(0,D.jsx)(se,{sm:!0,label:t==="yes"?"Copied":"Copy",onClick:()=>{if(navigator.clipboard?.writeText===void 0){a("failed");return}navigator.clipboard.writeText(e).then(()=>a("yes"),()=>a("failed"))}}),t==="failed"&&(0,D.jsx)("span",{className:"k-note",role:"status",children:"Couldn't copy. Select it and copy it yourself."})]})}var ZQ={"30m":30*6e4,"2h":120*6e4,"24h":1440*6e4},z4={"30m":"the last 30 minutes","2h":"the last 2 hours","24h":"the last 24 hours"};function QQ({row:e}){let t=e.endedAt!==null&&e.group!=="needs-you",a=e.group==="needs-you"?e.label==="Question"?(0,D.jsx)(He,{sm:!0,href:e.href,label:"Answer"}):(0,D.jsx)(He,{sm:!0,href:`/t/${encodeURIComponent(e.taskId)}`,label:"Open task"}):t?(0,D.jsx)(He,{sm:!0,href:`/r/${e.runId}`,label:"Open record"}):(0,D.jsx)(He,{sm:!0,href:e.href,label:"Watch"}),n=[e.line??(t?e.diff:null),e.agent].filter(Boolean).join(" · ");return(0,D.jsx)("div",{"data-agent-row":e.runId,"data-agent-group":e.group,children:(0,D.jsx)(xn,{href:e.href,wait:e.group==="needs-you",chip:(0,D.jsx)(XQ,{row:e}),title:e.title,desc:(0,D.jsx)("span",{"data-agent-line":!0,title:e.line??void 0,children:n}),meta:(0,D.jsxs)(D.Fragment,{children:[e.project&&(0,D.jsx)("span",{children:e.project}),(0,D.jsx)(YQ,{row:e}),e.diff!==null&&!t&&(0,D.jsx)("span",{className:"k-num","data-agent-diff":!0,children:e.diff})]}),action:a})})}function T1({id:e,label:t,rows:a,ink:n,right:o}){return(0,D.jsxs)("section",{"data-agent-group-section":e,"aria-labelledby":`agents-${e}`,children:[(0,D.jsx)(ur,{id:`agents-${e}`,label:t,count:(0,D.jsx)(Ct,{n:a.length,ink:n===!0}),right:o}),a.map(r=>(0,D.jsx)(QQ,{row:r},r.runId))]})}function JQ(e,t){let a=`heard ${Vn(e.heardAt,t)} ago`,n=e.reserved.length>0?` · ${e.reserved.length} reserved`:"";if(e.retired)return`Retired${n}`;if(e.state==="offline")return`Stopped answering at ${xm(e.heardAt,t)} · ${Vn(e.heardAt,t)} ago${n}`;let o=e.building.length+e.hidden;return e.state==="building"?`${o} of ${e.capacity} building · ${a}${n}`:`Free · ${Nd(e.capacity,"slot","slots")} · ${a}${n}`}var $4=e=>e.retired?(0,D.jsx)($e,{word:"Retired"}):(0,D.jsx)($e,{word:Bk[e.state].word,tone:Bk[e.state].tone});function eJ({one:e,others:t}){let a=Wr(3e4);return(0,D.jsx)("div",{"data-computer-offline":e.name,children:(0,D.jsx)(fo,{status:(0,D.jsxs)(D.Fragment,{children:[$4(e),(0,D.jsxs)("h2",{children:[e.name," is offline"]})]}),text:`It stopped answering at ${xm(e.heardAt,a)}. Nothing is lost: work it would take waits in the queue${t?", and the other computers keep building":""}. To bring it back, open a terminal on ${e.host}, go to the project's folder and run:`,acts:(0,D.jsx)(q4,{text:"toolroll up"}),terms:`Keep it running; it picks up queued work on its own. If ${e.name} is gone for good, retire it below.`})})}function tJ(){return(0,D.jsx)("div",{"data-computer-none":!0,children:(0,D.jsx)(fo,{status:(0,D.jsx)("h2",{children:"No computer is building yet"}),text:"Approved tasks wait until one is connected. On the computer where the project lives, open the project's folder in a terminal and run:",acts:(0,D.jsx)(q4,{text:"toolroll up"}),terms:"Keep it running. The console alone (toolroll serve) doesn't build."})})}function aJ({one:e,computers:t,trigger:a,onClose:n}){let o=Wr(3e4),r=(0,Bt.useContext)(Jo),s=(0,Bt.useContext)(so),i={passwordless:r,remembered:!1},l=e.retired?"Retired":e.state==="offline"?`Offline since ${xm(e.heardAt,o)}`:e.state==="building"?"Online, building":"Online",u=async f=>{try{let d=await fetch("/fleet/runner/retire",{method:"POST",credentials:"same-origin",redirect:"manual",headers:Wt({}),body:new URLSearchParams({csrf:s,name:e.name,token:f??""})});return d.type==="opaqueredirect"||d.status>=300&&d.status<400?(location.assign(`/agents?retired=${encodeURIComponent(e.name)}#computers`),null):d.status===404?"There's no computer by that name any more. Nothing changed.":f===null?"Retiring needs your password now. Nothing changed.":"That password didn't match. Nothing changed."}catch{return"The console didn't answer. Nothing changed; try again."}};return(0,D.jsx)(co,{kind:"drawer",title:e.name,trigger:a,onClose:n,children:(0,D.jsxs)("div",{className:"agents-cpanel","data-computer-panel":e.name,children:[(0,D.jsx)(Yc,{rows:[["Status",l],["Computer",e.host],["Takes work from",e.projects.length>0?e.projects.join(", "):"No projects yet"],["Building now",e.building.length===0&&e.hidden===0?"Nothing":(0,D.jsxs)(D.Fragment,{children:[e.building.map(f=>(0,D.jsx)("span",{className:"agents-fact-line",children:(0,D.jsx)("a",{href:f.href,children:f.title})},f.taskId)),e.hidden>0&&(0,D.jsxs)("span",{className:"agents-fact-line",children:[Nd(e.hidden,"task","tasks")," in projects you can't see"]})]})],["At a time",Nd(e.capacity,"task","tasks")],["Last heard",`${xm(e.heardAt,o)} (${Vn(e.heardAt,o)} ago)`],["Registered",xm(e.registeredAt,o)]]}),(0,D.jsxs)("section",{className:"k-sec","aria-label":"Reserved for it",children:[(0,D.jsx)("h3",{children:"Reserved for it"}),e.reserved.length===0?(0,D.jsx)(ea,{children:"Nothing. It takes from the shared queue, top first."}):(0,D.jsx)("ul",{className:"agents-list",children:e.reserved.map(f=>(0,D.jsxs)("li",{"data-reserved":f.id,children:[(0,D.jsxs)("span",{className:"agents-list-t",children:[(0,D.jsx)("a",{href:f.href,children:f.title}),f.project&&(0,D.jsxs)("span",{className:"k-muted",children:[" · ",f.project]})]}),t.manage&&!f.taken&&(0,D.jsxs)(Ae,{action:"/queue/move",className:"agents-move",children:[(0,D.jsx)("input",{type:"hidden",name:"queueRevision",value:String(t.queueRevision)}),(0,D.jsx)("input",{type:"hidden",name:"task",value:f.id}),(0,D.jsx)("input",{type:"hidden",name:"before",value:""}),(0,D.jsx)(lo,{sm:!0,name:"column","aria-label":`Move ${f.title} to`,defaultValue:"anyone",items:[["anyone","Shared queue"],...t.list.filter(d=>d.name!==e.name&&!d.retired).map(d=>[d.name,d.name])]}),(0,D.jsx)(se,{sm:!0,type:"submit",label:"Move"})]}),f.taken&&(0,D.jsx)("span",{className:"k-note",children:"Being taken"})]},f.id))})]}),t.manage&&!e.retired&&(0,D.jsxs)(Ae,{action:"/queue/note",className:"k-sec",children:[(0,D.jsx)("input",{type:"hidden",name:"runner",value:e.name}),(0,D.jsx)("input",{type:"hidden",name:"from",value:"fleet"}),(0,D.jsx)(ki,{label:"Note on its queue",hint:"What it is working through, for whoever looks next.",children:f=>(0,D.jsx)(Na,{id:f.id,name:"note",maxLength:200,defaultValue:e.note??"","aria-describedby":f.describedBy})}),(0,D.jsx)(uo,{children:(0,D.jsx)(se,{sm:!0,type:"submit",label:"Save note"})})]}),!t.manage&&e.note&&(0,D.jsx)(Yc,{rows:[["Note",e.note]]}),t.manage&&!e.retired&&(0,D.jsxs)("div",{className:"k-sec","data-computer-retire":e.name,children:[(0,D.jsx)(uo,{children:(0,D.jsx)(Bi,{kind:"step-up",facts:i,label:"Retire computer",primary:!1,terms:`Retire ${e.name}: it takes no more work.`,onApprove:u})}),(0,D.jsx)(ea,{children:`Retiring stops it taking work. Tasks reserved for it wait until you move them. ${_i("step-up",i)}`})]})]})})}var H4=e=>e===""?"Name the computer first.":e.length>60||/[\p{Cc}\p{Cf}]/u.test(e)?"Use one short line: up to 60 characters, no control characters.":null;function nJ({onCancel:e}){let t=(0,Bt.useContext)(so),a=(0,Bt.useContext)(Jo),[n,o]=(0,Bt.useState)(""),[r,s]=(0,Bt.useState)("1"),[i,l]=(0,Bt.useState)(null),u=(0,Bt.useRef)(null),f=n.trim(),d={passwordless:a,remembered:!1},c=async h=>{let y=document.createElement("form");y.setAttribute("method","post"),y.setAttribute("action","/fleet/runner/register"),y.hidden=!0;for(let[b,g]of Object.entries({csrf:t,name:f,capacity:r,token:h??""})){let x=document.createElement("input");x.type="hidden",x.name=b,x.value=g,y.append(x)}return document.body.append(y),y.submit(),null},m=()=>{l(H4(f)),u.current?.focus()};return(0,D.jsxs)("div",{className:"k-sec agents-reg",id:"agents-register","data-computer-register":!0,children:[(0,D.jsx)("h3",{children:"Add a computer"}),(0,D.jsx)(ki,{label:"Computer name",error:i,children:h=>(0,D.jsx)(Na,{ref:u,id:h.id,value:n,autoComplete:"off",spellCheck:!1,maxLength:60,"aria-describedby":h.describedBy,"aria-invalid":h.invalid||void 0,onChange:y=>{o(y.target.value),l(null)}})}),(0,D.jsx)(ki,{label:"Tasks at a time",children:h=>(0,D.jsx)(lo,{id:h.id,wide:!0,value:r,onChange:y=>s(y.target.value),items:["1","2","3","4","6","8"]})}),(0,D.jsxs)("p",{className:"agents-terms",children:[f||"New computer"," · up to ",r," at a time · takes from the shared queue"]}),(0,D.jsxs)(uo,{children:[H4(f)===null?(0,D.jsx)(Bi,{kind:"way-in",facts:d,label:"Register computer",terms:`Register ${f}: up to ${r} at a time.`,onApprove:c}):(0,D.jsx)(se,{variant:"primary",label:"Register computer",onClick:m}),(0,D.jsx)(se,{variant:"ghost",label:"Cancel",onClick:e})]}),(0,D.jsx)(ea,{children:`${_i("way-in",d)} Registering makes a token that lets the computer take work; it is shown once.`})]})}function oJ({computers:e,terminals:t}){let a=Wr(3e4),[n,o]=(0,Bt.useState)(!1),[r,s]=(0,Bt.useState)(null),i=r===null?null:e.list.find(u=>u.name===r.name)??null,l=e.manage&&!n?(0,D.jsx)(se,{variant:"ghost",sm:!0,lead:"plus",label:"Add a computer",onClick:()=>o(!0)}):void 0;return(0,D.jsxs)("section",{id:"computers",className:"agents-sec","aria-labelledby":"agents-computers","data-computers":!0,children:[(0,D.jsx)(ur,{id:"agents-computers",label:"Computers that build",count:(0,D.jsx)(Ct,{n:e.list.length}),right:l}),e.list.length===0&&(0,D.jsx)("div",{className:"agents-pad",children:(0,D.jsx)(tJ,{})}),e.list.map(u=>(0,D.jsx)("div",{"data-computer":u.name,children:(0,D.jsx)(xn,{chip:$4(u),title:u.name,desc:`${u.host} · ${JQ(u,a)}`,meta:(0,D.jsx)("span",{children:u.projects.length>0?u.projects.join(", "):"No projects yet"}),action:(0,D.jsx)(se,{sm:!0,label:"Details","aria-haspopup":"dialog",onClick:f=>s({name:u.name,trigger:f.currentTarget})})})},u.name)),e.shared>0&&(0,D.jsxs)("p",{className:"agents-line",children:[Nd(e.shared,"task waits","tasks wait")," in the shared queue for any free computer. ",(0,D.jsx)("a",{className:"k-link",href:"/tasks?view=order",children:"Reserve one for a computer"})]}),n&&(0,D.jsx)(nJ,{onCancel:()=>o(!1)}),t&&(0,D.jsx)("p",{className:"agents-line k-phone-only",children:(0,D.jsx)("a",{className:"k-link",href:"/agents/terminals",children:"Terminals on these computers"})}),r!==null&&i!==null&&(0,D.jsx)(aJ,{one:i,computers:e,trigger:r.trigger,onClose:()=>s(null)})]})}var F4={plan:["Plan","Writes the plan you approve"],build:["Build","Does the work inside the approved plan"],repair:["Repair","Fixes a malformed handoff in the same session"],review:["Review","Reads the result against the requirements"]};function rJ({view:e}){let[t]=(0,Bt.useState)(()=>typeof location<"u"&&location.hash==="#models"),a=e.system??null,n=a!==null&&(a.workspaces.length>0||a.service!==null||a.outbox>0||a.external.length>0);return(0,D.jsxs)("section",{id:"models",className:"agents-sec agents-models","data-agent-phases":!0,children:[(0,D.jsx)(lr,{summary:"Model per phase",open:t,children:(0,D.jsxs)("div",{className:"agents-phases",children:[(e.phases??[]).map(o=>(0,D.jsxs)("div",{className:"agents-phase","data-phase":o.phase,children:[(0,D.jsx)("b",{children:F4[o.phase]?.[0]??o.phase}),(0,D.jsx)("span",{className:"k-muted",children:F4[o.phase]?.[1]??""}),o.model===null?(0,D.jsx)("span",{children:o.problem}):(0,D.jsxs)("span",{children:[o.model,o.noDollars&&(0,D.jsx)("span",{className:"k-muted",children:" · reports tokens, not dollars"})]}),(0,D.jsx)("span",{className:"k-muted",children:o.source})]},o.phase)),(0,D.jsxs)(ea,{children:["Repair always stays on the provider that built; only its model can differ. ",(0,D.jsx)("a",{className:"k-link",href:"/settings/agents",children:"Change in Settings → Agents and models"})]})]})}),n&&a!==null&&(0,D.jsx)(lr,{summary:"Workspaces and sync",children:(0,D.jsxs)("div",{className:"agents-phases",children:[a.service!==null&&(0,D.jsx)("p",{children:a.service.running?`The background service is running, since ${A1(a.service.at)}.`:`The background service last ran: ${a.service.built} built, ${a.service.broke} broke · ended ${A1(a.service.at)}.`}),a.workspaces.length>0&&(0,D.jsx)("ul",{className:"agents-list",children:a.workspaces.map(o=>(0,D.jsxs)("li",{children:[(0,D.jsx)("span",{className:"k-mono",children:o.name}),(0,D.jsxs)("span",{className:"k-muted",children:[o.branch," · ",o.state]})]},o.name))}),a.outbox>0&&(0,D.jsxs)("p",{children:[Nd(a.outbox,"notification waits","notifications wait")," to be delivered."]}),a.external.map(o=>(0,D.jsxs)("p",{children:[(0,D.jsx)("span",{className:"k-mono",children:o.repo})," · ",o.state]},o.repo))]})})]})}function sJ({view:e}){let t=Wr(3e4),[a,n]=(0,Bt.useState)(e.window??"24h"),o=m=>{let h=m==="30m"||m==="2h"?m:"24h";n(h);try{let y=new URL(location.href);h==="24h"?y.searchParams.delete("window"):y.searchParams.set("window",h),history.replaceState(history.state,"",y)}catch{}},r=e.groups.flatMap(m=>m.rows),s=r.filter(m=>m.group==="needs-you"),i=r.filter(m=>m.endedAt===null&&m.group!=="needs-you"),l=r.filter(m=>m.endedAt!==null&&m.group!=="needs-you"&&t-Date.parse(m.endedAt)<=ZQ[a]),u=(e.computers?.list??[]).filter(m=>m.state==="offline"&&!m.retired),f=(e.computers?.list??[]).some(m=>m.state!=="offline"),c=(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(Ur,{label:"Finished in",current:a,onChange:o,items:[{key:"30m",label:"30 min"},{key:"2h",label:"2 h"},{key:"24h",label:"24 h"}]}),(0,D.jsx)(He,{sm:!0,variant:"ghost",href:"/agents?view=live",label:"Live view"}),e.terminals===!0&&(0,D.jsx)(He,{sm:!0,href:"/agents/terminals",label:"Terminals"})]});return(0,D.jsxs)("div",{className:"agents-page",id:"agents-view","data-agents-board":!0,children:[(0,D.jsx)(tn,{title:"Agents",ctx:`All projects · ${Nd(i.length,"agent","agents")} building`,right:c}),e.computerSaid&&(0,D.jsx)("div",{className:"agents-pad","data-computer-said":!0,children:e.computerSaid.tone==="error"?(0,D.jsx)($a,{children:e.computerSaid.text}):(0,D.jsx)(Pi,{children:e.computerSaid.text})}),u.map(m=>(0,D.jsx)("div",{className:"agents-pad",children:(0,D.jsx)(eJ,{one:m,others:f})},m.name)),s.length===0&&i.length===0&&(0,D.jsx)("div",{"data-agents-empty":!0,children:(0,D.jsx)(Ua,{title:"No agents are working.",text:"An agent starts when you approve a plan. What finished in the window you pick shows below.",action:(0,D.jsx)(He,{sm:!0,href:"/tasks",label:"Open Tasks"})})}),s.length>0&&(0,D.jsx)(T1,{id:"needs-you",label:"Needs you",rows:s,ink:!0}),i.length>0&&(0,D.jsx)(T1,{id:"working",label:"Working",rows:i}),(0,D.jsx)(T1,{id:"finished",label:(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)("span",{className:"k-desk-only",children:["Finished in ",z4[a]]}),(0,D.jsx)("span",{className:"k-phone-only",children:"Finished"})]}),rows:l,right:(0,D.jsx)("span",{className:"k-phone-only",children:(0,D.jsx)(lo,{sm:!0,"aria-label":"Finished in",value:a,onChange:m=>o(m.target.value),items:[["30m","Last 30 min"],["2h","Last 2 h"],["24h","Last 24 h"]]})})}),l.length===0&&(0,D.jsxs)("p",{className:"agents-none",children:["Nothing finished in ",z4[a],"."]}),e.computers!=null&&(0,D.jsx)(oJ,{computers:e.computers,terminals:e.terminals===!0}),e.phases!=null&&(0,D.jsx)(rJ,{view:e}),e.computers==null&&e.terminals===!0&&(0,D.jsx)("p",{className:"agents-line k-phone-only",children:(0,D.jsx)("a",{className:"k-link",href:"/agents/terminals",children:"Terminals"})})]})}function iJ(e,t){let[a,n]=(0,Bt.useState)(null);return(0,Bt.useEffect)(()=>{if(e===null||!t)return;let o=!1,r=0,s=async()=>{try{let i=await fetch(e,{cache:"no-store",credentials:"same-origin",redirect:"manual"});i.ok&&!o&&n(await i.text())}catch{}o||(r=window.setTimeout(()=>{s()},1e4))};return s(),()=>{o=!0,window.clearTimeout(r)}},[e,t]),a}function lJ({detail:e,open:t}){let a=iJ(e.peek,t);return(0,D.jsx)("div",{"data-agent-changes":!0,className:"agents-changes",children:e.live?e.peek===null?(0,D.jsx)(ea,{children:"Output from other computers isn't shown yet."}):a===null?(0,D.jsx)(ea,{children:"Looking at the checkout…"}):(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(St,{html:a,className:"so-native-region"}),(0,D.jsx)(ea,{children:"A live look at its working copy, refreshed every 10 seconds. Not yet a result: the record is sealed when the build ends."})]}):e.files.length===0?(0,D.jsx)(ea,{children:"No saved changes."}):(0,D.jsxs)("ul",{className:"agents-files",children:[e.files.map(n=>(0,D.jsxs)("li",{children:[(0,D.jsx)("span",{className:"k-mono",title:n.path,children:n.path}),(0,D.jsx)("span",{className:"k-num agents-add",children:n.added===null?"":`+${n.added}`}),(0,D.jsx)("span",{className:"k-num agents-del",children:n.removed===null?"":`−${n.removed}`})]},n.path)),e.filesMore>0&&(0,D.jsxs)("li",{className:"k-muted",children:[e.filesMore," more in the result"]})]})})}function uJ({checkout:e}){let[t,a]=(0,Bt.useState)("no"),n=()=>{if(navigator.clipboard?.writeText===void 0){a("failed");return}navigator.clipboard.writeText(e.cd).then(()=>a("yes"),()=>a("failed"))};return(0,D.jsxs)("section",{"aria-label":"Its files",className:"k-sec agents-checkout","data-agent-checkout":!0,children:[(0,D.jsx)("h3",{children:"Its files"}),(0,D.jsx)(ea,{children:"These files were written by an agent. Your shell's startup scripts and prompt tools (git status in the prompt, direnv, .envrc) can run code from them when you open a terminal there."}),(0,D.jsx)("code",{className:"k-code","data-agent-checkout-path":!0,children:e.path}),(0,D.jsxs)("div",{className:"k-acts k-desk-only",children:[(0,D.jsx)(se,{sm:!0,onClick:n,"data-agent-copy-cd":!0,label:t==="yes"?"Copied":"Copy the command"}),e.reveal!==null&&(0,D.jsxs)(Ae,{action:e.reveal,"data-agent-reveal":!0,children:[(0,D.jsx)("input",{type:"hidden",name:"return",value:"agents"}),(0,D.jsx)(se,{sm:!0,type:"submit",label:"Show in Finder"})]})]}),t==="failed"&&(0,D.jsxs)("div",{role:"status",className:"agents-checkout","data-agent-copy-failed":!0,children:[(0,D.jsx)(ea,{children:"Couldn't copy. Select the command and copy it yourself:"}),(0,D.jsx)("code",{className:"k-code",children:e.cd})]})]})}function cJ({controls:e}){let t=e.pause,a=e.stop,[n,o]=(0,Bt.useState)(null);return(0,D.jsxs)(D.Fragment,{children:[t!==null&&(t.state==="paused"?(0,D.jsxs)(Ae,{action:t.action,"data-agent-resume":!0,children:[(0,D.jsx)("input",{type:"hidden",name:"run",value:String(t.run)}),(0,D.jsx)("input",{type:"hidden",name:"request",value:t.requests[2]}),(0,D.jsx)("input",{type:"hidden",name:"mode",value:"resume"}),(0,D.jsx)("input",{type:"hidden",name:"return",value:"agents"}),(0,D.jsx)(se,{type:"submit",label:"Resume"})]}):(0,D.jsxs)(Ae,{action:t.action,"data-agent-pause":!0,children:[(0,D.jsx)("input",{type:"hidden",name:"run",value:String(t.run)}),(0,D.jsx)("input",{type:"hidden",name:"request",value:t.requests[0]}),(0,D.jsx)("input",{type:"hidden",name:"return",value:"agents"}),(0,D.jsx)(se,{type:"submit",label:"Pause",busy:t.state==="pausing"?"Pausing…":!1,disabled:t.state==="pausing"})]})),a!==null&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(se,{variant:"ghost",label:a.label,"aria-haspopup":"dialog","data-agent-stop-open":a.run,onClick:r=>o(r.currentTarget)}),n!==null&&(0,D.jsxs)(co,{kind:"popover",title:`${a.label}?`,trigger:n,onClose:()=>o(null),children:[(0,D.jsx)("p",{className:"k-pop-terms",children:"It ends now and keeps the work so far. The task waits for you: retry it, or change the plan."}),(0,D.jsxs)(Ae,{action:a.action,"data-agent-stop":a.run,children:[(0,D.jsx)("input",{type:"hidden",name:"run",value:String(a.run)}),(0,D.jsx)("input",{type:"hidden",name:"return",value:"agents"}),(0,D.jsxs)(uo,{children:[(0,D.jsx)(se,{type:"submit",variant:"danger",label:a.label}),(0,D.jsx)(se,{variant:"ghost",label:"Cancel","data-k-close":""})]})]})]})]})]})}function dJ({detail:e}){let t=Wr(),a=e.canAct&&e.controls!=null?e.controls:null,n=a!==null?(0,D.jsx)("div",{className:"k-acts","data-agent-controls":a.send??"none",children:(0,D.jsx)(cJ,{controls:a})}):null;if(e.question!==null)return(0,D.jsx)(fo,{wait:!0,status:(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)($e,{word:"Question",tone:"ask"}),(0,D.jsxs)("h2",{children:[e.agent," asks"]})]}),text:(0,D.jsx)("span",{"data-agent-question":e.question.key,children:e.question.text}),acts:n,terms:e.canAct?"Answer below. It reads your reply at its next check.":"An approver answers it."});if(e.live){let s=a?.pause?.state==="paused",{word:i,tone:l}=s?{word:"Paused",tone:""}:E1(e);return(0,D.jsx)(fo,{status:(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)($e,{word:i,tone:l}),(0,D.jsx)("h2",{children:R1(e,t)})]}),text:(0,D.jsx)("span",{"data-agent-line":!0,children:e.line??"Working."}),acts:n,terms:a===null?"":(0,D.jsx)("span",{"data-agent-capability":!0,children:a.words})})}let{word:o,tone:r}=E1(e);return(0,D.jsx)(fo,{status:(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)($e,{word:o,tone:r}),(0,D.jsx)("h2",{children:R1(e,t)})]}),text:(0,D.jsx)("span",{"data-agent-line":!0,children:e.line??e.diff??"It has finished."}),acts:(0,D.jsx)(He,{href:e.open?.href??e.taskHref,label:e.open?`Open ${e.open.label.toLowerCase()}`:"Open task"}),terms:e.diff??""})}var fJ=e=>e.canAct&&(e.question!==null||e.steer!==null&&!(e.live&&e.controls!=null&&e.controls.send===null));function pJ({detail:e}){let t=e.question,a=(0,Bt.useRef)(null),[n,o]=(0,Bt.useState)(()=>t!==null?Po():nd(e.runId)),r=n.text,s=f=>o(d=>{let c=d.submitted?{...Po(),text:f}:{...d,text:f};return Gr(e.runId,c),c});if(!e.canAct)return e.live?(0,D.jsxs)("section",{className:"k-sec agents-steer","aria-label":"Send a note",children:[(0,D.jsx)("h3",{children:"Send a note"}),(0,D.jsx)(ea,{children:"Your sign-in can watch this agent. Sending it a note takes an approver; ask an operator to change your role in Settings → People and sign-in."})]}):null;if(t===null&&e.live&&e.controls!=null&&e.controls.send===null)return null;if(t===null&&e.steer===null){if(r.trim()==="")return null;let f=()=>{Gr(e.runId,{...Po(),text:""}),o(Po())};return(0,D.jsxs)(Ae,{action:`${e.taskHref}/steer`,"data-agent-unsent":!0,className:"k-sec agents-steer",children:[(0,D.jsx)("h3",{children:"Your note wasn't sent: this attempt ended first"}),(0,D.jsx)("p",{className:"agents-unsent","data-agent-unsent-text":!0,children:r}),(0,D.jsx)("input",{type:"hidden",name:"note",value:r}),(0,D.jsx)("input",{type:"hidden",name:"after",value:String(e.runId)}),(0,D.jsx)("input",{type:"hidden",name:"key",value:n.key}),(0,D.jsxs)(uo,{children:[(0,D.jsx)(se,{type:"submit",variant:"primary",label:"Send to the next attempt"}),(0,D.jsx)(se,{variant:"ghost",label:"Discard",onClick:f})]}),(0,D.jsx)(ea,{children:"The task's next attempt reads it before starting. No password needed."})]})}let i=t!==null,l=e.controls?.pause!=null&&e.controls.pause.state===null?e.controls.pause:null,u=i?"It reads your reply at its next check.":"Notes reach the agent; it answers in the conversation above.";return(0,D.jsxs)(Ae,{ref:a,action:i?t.action:e.steer.action,"data-agent-composer":i?"reply":"steer",className:"k-sec agents-steer",onSubmit:f=>{if(r.trim()===""){f.preventDefault();return}i||o(d=>{let c={...d,submitted:!0};return Gr(e.runId,c),c})},children:[(0,D.jsx)("h3",{children:i?`Reply to ${e.agent}`:`Send a note to ${e.agent}`}),i?(0,D.jsx)("input",{type:"hidden",name:"question",value:String(t.id)}):(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)("input",{type:"hidden",name:"return",value:"agents"}),(0,D.jsx)("input",{type:"hidden",name:"run",value:String(e.steer.run)}),(0,D.jsx)("input",{type:"hidden",name:"key",value:n.key}),l!==null&&(0,D.jsx)("input",{type:"hidden",name:"request",value:`steer-${n.key}`})]}),(0,D.jsx)(ed,{id:`agent-composer-${e.runId}`,label:i?`Reply to: ${t.text}`:`Send a note to ${e.agent}`,name:i?"answer":"note",maxLength:i?1500:4e3,rows:3,value:r,onChange:f=>{i?o(d=>({...d,text:f})):s(f)},placeholder:i?"Your answer":"For example: keep the flag off in staging until Wednesday.",sendLabel:i?"Reply":"Send note",onSend:()=>a.current?.requestSubmit(),error:e.said?.tone==="error"?e.said.text:null,before:!i&&l!==null?(0,D.jsx)(se,{sm:!0,type:"submit",formAction:l.action,label:"Pause and send",disabled:r.trim()==="","data-agent-pause-send":!0}):void 0,note:`${u} No password needed.`})]})}function mJ({detail:e}){let[t,a]=(0,Bt.useState)("conversation");return(0,D.jsxs)("div",{className:"agents-tabs","data-agent-tabs":!0,children:[(0,D.jsx)(dv,{label:"Agent",current:t,onChange:n=>a(n==="changes"?"changes":"conversation"),items:[{key:"conversation",label:"Conversation"},{key:"changes",label:e.diff===null?"Changes":`Changes · ${e.diff}`}]}),(0,D.jsx)("div",{role:"tabpanel","aria-label":"Conversation",hidden:t!=="conversation",children:(0,D.jsx)(I4,{url:e.transcript,live:e.live,agent:e.agent})}),(0,D.jsx)("div",{role:"tabpanel","aria-label":"Changes",hidden:t!=="changes",children:(0,D.jsxs)("div",{className:"agents-changes-wrap",children:[(0,D.jsx)(lJ,{detail:e,open:t==="changes"}),e.checkout!=null&&e.canAct&&(0,D.jsx)(uJ,{checkout:e.checkout})]})})]})}function hJ({detail:e}){hn(e.room,o=>{(o==="change"||o==="reload")&&window.dispatchEvent(new Event(Fi))});let t=(0,Bt.useContext)(so);(0,Bt.useEffect)(()=>e.live?vA(e.runId,t):(Dg(e.runId,t),void 0),[e.runId,e.live,t]);let a=[e.project,`run ${e.runId}`,e.agent].filter(Boolean).join(" · "),n=e.task??null;return(0,D.jsxs)("div",{className:"agents-agent",id:"agents-view","data-agent-detail":e.runId,children:[(0,D.jsx)(hv,{title:e.project??"Agent",back:"/agents"}),(0,D.jsxs)(b_,{children:[(0,D.jsx)(gv,{back:["/agents","Agents"],title:e.title,meta:a,right:(0,D.jsx)(He,{variant:"ghost",sm:!0,href:e.taskHref,label:"Open task","data-agent-open":"Task"})}),e.said&&e.said.tone==="info"&&(0,D.jsx)("div",{"data-agent-said":!0,children:(0,D.jsx)(Pi,{children:e.said.text})}),e.said&&e.said.tone==="error"&&!fJ(e)&&(0,D.jsx)("div",{"data-agent-said":!0,children:(0,D.jsx)($a,{children:e.said.text})}),(0,D.jsx)("div",{id:"agents-box",children:(0,D.jsx)(dJ,{detail:e})}),n!==null&&(0,D.jsxs)("p",{className:"agents-task","data-agent-task":n.headline,children:["The task: ",(0,D.jsx)("b",{children:n.headline}),". ",n.sentence," ",(0,D.jsx)("a",{className:"k-link",href:n.action.href,"data-agent-task-action":!0,children:n.action.label})]}),(0,D.jsx)(mJ,{detail:e}),(0,D.jsx)(pJ,{detail:e},`${e.runId}:${e.question?.id??"steer"}`)]})]})}function gJ(){return(0,D.jsxs)("div",{className:"agents-page",id:"agents-view","data-agents-board":!0,children:[(0,D.jsx)(tn,{title:"Live",back:"/agents",ctx:"Every running agent's output, watching only",right:(0,D.jsx)(He,{sm:!0,variant:"ghost",href:"/agents",label:"Back to Agents"})}),(0,D.jsx)("div",{className:"agents-live",children:(0,D.jsx)(B4,{})})]})}function U4({view:e}){return e.live===!0?(0,D.jsx)(gJ,{}):e.selected!==null?(0,D.jsx)(hJ,{detail:e.selected},e.selected.runId):(0,D.jsx)(sJ,{view:e})}var Ga=O(he(),1);var ge=O(G(),1),vJ=()=>window.dispatchEvent(new CustomEvent(Fi)),yJ=e=>e.groups.flatMap(t=>t.rows);async function xJ(e){try{let t=await e.text(),n=new DOMParser().parseFromString(t,"text/html").querySelector(".problem")?.textContent?.trim();return n?`Couldn’t answer: ${n}. Nothing changed.`:"Couldn’t answer. Nothing changed."}catch{return"Couldn’t answer. Nothing changed."}}function bJ({row:e}){let t=e.question,a=(0,Ga.useContext)(so),[n,o]=(0,Ga.useState)(t.options.find(c=>c.recommended)?.id??t.options[0]?.id??""),[r,s]=(0,Ga.useState)(!1),[i,l]=(0,Ga.useState)(!1),[u,f]=(0,Ga.useState)(null),d=async()=>{if(!(r||i||n==="")){s(!0),f(null);try{let c=await fetch(`/d/${t.id}/answer`,{method:"POST",credentials:"same-origin",headers:Wt({}),body:new URLSearchParams({csrf:a,choice:n}),signal:AbortSignal.timeout(15e3)});if(!c.ok){f(await xJ(c));return}l(!0),window.setTimeout(vJ,500)}catch{f("Couldn’t reach Toolroll. Nothing changed; try again.")}finally{s(!1)}}};return(0,ge.jsxs)(ge.Fragment,{children:[(0,ge.jsx)("h2",{className:"so-open-t",children:t.text}),t.recap&&(0,ge.jsx)("p",{className:"so-open-x",children:t.recap}),(0,ge.jsx)(v_,{name:`answer-${t.id}`,legend:"Choose one",current:n,onChange:o,items:t.options.map(c=>({value:c.id,label:c.label,text:c.consequence,...c.recommended?{tag:(0,ge.jsx)($e,{word:"Recommended",dot:!1})}:{}}))}),(0,ge.jsxs)("div",{className:"k-acts",children:[(0,ge.jsx)(se,{variant:"primary",label:i?"Answered":"Answer",busy:r?"Sending…":!1,onClick:()=>{d()},"aria-disabled":i?!0:void 0}),(0,ge.jsx)(He,{variant:"ghost",label:"Open the question",href:`/d/${t.id}`})]}),u&&(0,ge.jsx)($a,{children:u})]})}function wJ({row:e,waits:t}){if(e===null)return(0,ge.jsxs)("div",{className:"k-empty",children:[(0,ge.jsx)("p",{className:"k-empty-t",children:"Nothing needs you."}),(0,ge.jsx)(He,{sm:!0,label:"Open Tasks",href:"/tasks"})]});let a=(0,ge.jsxs)("div",{className:"so-open-k",children:[(0,ge.jsx)("span",{children:[e.project,e.age].filter(Boolean).join(" · ")}),(0,ge.jsx)("span",{className:"k-grow"}),(0,ge.jsx)(He,{variant:"ghost",sm:!0,label:"Open task",href:e.href})]});return e.question?(0,ge.jsxs)(ge.Fragment,{children:[a,(0,ge.jsx)("p",{className:"so-open-of",children:e.title}),(0,ge.jsx)(bJ,{row:e},e.question.id)]}):(0,ge.jsxs)(ge.Fragment,{children:[a,(0,ge.jsx)("h2",{className:"so-open-t",children:e.title}),(0,ge.jsxs)("p",{className:"so-open-chip",children:[(0,ge.jsx)($e,{word:t?"Needs you":e.chip.word,tone:t?"needs":e.chip.tone}),t&&(0,ge.jsx)("span",{children:e.chip.word})]}),e.line&&(0,ge.jsx)("p",{className:"so-open-x",children:e.line}),(0,ge.jsx)("div",{className:"k-acts",children:e.action?(0,ge.jsx)(He,{label:e.action.label,href:e.action.href}):(0,ge.jsx)(He,{label:"Open task",href:e.href})})]})}function kJ({ask:e}){let t=(0,Ga.useContext)(so),a=(0,Ga.useRef)(null),[n,o]=(0,Ga.useState)(""),[r,s]=(0,Ga.useState)(!1),i=(0,Ga.useRef)(Array.from(crypto.getRandomValues(new Uint8Array(16)),u=>u.toString(16).padStart(2,"0")).join("")),l=()=>{if(r||n.trim()==="")return;s(!0);let u=a.current?.querySelector('input[name="message"]');u&&(u.value=n),a.current?.requestSubmit()};return(0,ge.jsxs)("form",{ref:a,method:"post",action:"/chat",className:"so-home-ask","aria-label":"Ask the lead",onSubmit:()=>s(!0),children:[(0,ge.jsx)("input",{type:"hidden",name:"csrf",value:t}),(0,ge.jsx)("input",{type:"hidden",name:"request",value:i.current}),e.project!==null&&(0,ge.jsx)("input",{type:"hidden",name:"project",value:e.project}),(0,ge.jsx)("input",{type:"hidden",name:"message",value:n}),(0,ge.jsx)(ed,{id:"home-ask",label:"Ask the lead",placeholder:e.placeholder,value:n,onChange:o,onSend:l,line:!0,sendLabel:"Ask the lead",disabled:r})]})}function V4({view:e}){let t=yJ(e),a=e.groups.find(f=>f.key!=="running"&&f.key!=="waiting")?.rows[0]??t[0]??null,[n,o]=(0,Ga.useState)(a?.id??null),r=(0,Ga.useRef)(null);(0,Ga.useEffect)(()=>{(n===null||!t.some(f=>f.id===n))&&o(a?.id??null)},[e]);let s=t.find(f=>f.id===n)??null,i=s!==null&&e.groups.some(f=>f.key!=="running"&&f.key!=="waiting"&&f.rows.includes(s)),l=f=>{let d=t.findIndex(m=>m.id===n),c=t[Math.max(0,Math.min(t.length-1,d+f))];c&&(o(c.id),r.current?.querySelector(`[data-row="${CSS.escape(c.id)}"]`)?.focus())},u=e.scopes&&(0,ge.jsx)("nav",{className:"k-seg","aria-label":"Project",children:e.scopes.map(f=>(0,ge.jsx)("a",{href:f.href,"aria-current":f.active?"page":void 0,children:f.label},f.key||"all"))});return(0,ge.jsxs)("div",{className:"so-home","data-kit-page":!0,"data-home":!0,children:[(0,ge.jsx)(tn,{title:"Home",right:(0,ge.jsxs)(ge.Fragment,{children:[u,(0,ge.jsx)(He,{sm:!0,lead:"plus",label:"New task",href:e.newTask})]})}),e.empty?(0,ge.jsxs)("section",{className:"so-hello so-hello-empty",children:[(0,ge.jsx)("p",{className:"so-say","data-home-say":!0,children:e.empty.title}),(0,ge.jsx)("p",{className:"so-hello-x",children:e.empty.text}),e.setup&&(0,ge.jsx)("p",{className:"so-hello-x","data-home-setup":!0,children:(0,ge.jsx)("a",{className:"k-link",href:e.setup,children:"Finish setup"})}),(0,ge.jsx)(He,{variant:"primary",label:"New task",lead:"plus",href:e.newTask,className:"k-desk-only"})]}):(0,ge.jsxs)(ge.Fragment,{children:[(0,ge.jsxs)("section",{className:"so-hello","aria-label":"At a glance",children:[(0,ge.jsx)("p",{className:"so-say","data-home-say":!0,children:e.say}),e.setup&&(0,ge.jsx)("p",{className:"so-hello-x","data-home-setup":!0,children:(0,ge.jsx)("a",{className:"k-link",href:e.setup,children:"Finish setup"})}),(0,ge.jsx)("div",{className:"so-counts",children:e.counts.map(f=>(0,ge.jsxs)("a",{className:"so-count",href:f.href,"data-home-count":f.key,children:[(0,ge.jsxs)("span",{className:"so-count-k",children:[f.key==="needs"&&(0,ge.jsx)("span",{className:"k-dot needs","aria-hidden":"true"}),f.label]}),(0,ge.jsx)("span",{className:`so-count-v k-num${f.value===0?" zero":""}`,children:f.value})]},f.key))})]}),(0,ge.jsxs)("div",{className:"so-triage",children:[(0,ge.jsxs)("div",{className:"so-tri-list",ref:r,role:"listbox","aria-label":"Needs you, running and waiting",onKeyDown:f=>{(f.key==="ArrowDown"||f.key==="ArrowUp")&&(f.preventDefault(),l(f.key==="ArrowDown"?1:-1))},children:[e.groups.length===0&&(0,ge.jsx)("p",{className:"so-tri-none",children:"Nothing needs you, runs or waits."}),e.groups.map(f=>(0,ge.jsxs)("div",{role:"group","aria-label":f.label,children:[(0,ge.jsx)("p",{className:"so-tri-g","aria-hidden":"true",children:f.label}),f.rows.map(d=>(0,ge.jsxs)("a",{className:"so-ti",href:d.href,role:"option","aria-selected":d.id===n,"data-row":d.id,tabIndex:d.id===n?0:-1,onClick:c=>{!Ns()&&!c.metaKey&&!c.ctrlKey&&!c.shiftKey&&(c.preventDefault(),o(d.id))},onFocus:()=>{Ns()||o(d.id)},children:[(0,ge.jsx)("span",{className:"so-ti-t",children:d.title}),(0,ge.jsxs)("span",{className:"so-ti-m",children:[(0,ge.jsx)($e,{word:d.chip.word,tone:d.chip.tone}),d.project&&(0,ge.jsx)("span",{children:d.project}),(0,ge.jsx)("span",{className:"k-num",children:d.age})]}),(f.key==="running"||f.key==="waiting")&&d.line&&(0,ge.jsx)("span",{className:"so-ti-d",children:d.line})]},d.id))]},f.key)),e.more&&(0,ge.jsx)("p",{className:"so-tri-more",children:(0,ge.jsxs)("a",{className:"k-link",href:e.more.href,children:[e.more.count," more in Tasks"]})})]}),(0,ge.jsx)("section",{className:"so-tri-open k-desk-only","aria-label":"Selected","aria-live":"polite",children:(0,ge.jsx)(wJ,{row:s,waits:i})})]})]}),e.ask&&(0,ge.jsx)("div",{className:"so-home-ask-dock k-desk-only",children:(0,ge.jsx)(kJ,{ask:e.ask})}),(0,ge.jsx)(_o,{children:(0,ge.jsx)(He,{variant:"primary",lead:"plus",label:"New task",href:e.newTask})})]})}var Uy=O(he(),1);var Kn=O(he(),1);var xa=O(he(),1),Q4=O(xr(),1);var M1="toolroll.chime",K4="toolroll.chime.v2",SJ="toolroll.chime.heard",G4="toolroll-chime";function CJ(e){return e.flatMap(t=>t.asks)}var Id=()=>{try{return window.localStorage}catch{return null}};function D1(){try{return Id()?.getItem(M1)==="1"}catch{return!1}}function W4(e){try{e?Id()?.setItem(M1,"1"):Id()?.removeItem(M1)}catch{}}var X4=/^[A-Za-z0-9_-]{8,64}$/;function Y4(){try{Id()?.removeItem(SJ)}catch{}try{let e=JSON.parse(Id()?.getItem(K4)??"null"),t={};for(let[a,n]of Object.entries(e?.keys??{}))X4.test(a)&&typeof n=="number"&&(t[a]=n);return{since:typeof e?.since=="number"?e.since:0,keys:t}}catch{return{since:0,keys:{}}}}function j4(e,t){let a=Y4(),n=t-2592e6;for(let[o,r]of Object.entries(a.keys))r<n&&(delete a.keys[o],a.since=Math.max(a.since,r));for(let o of e)X4.test(o)&&(a.keys[o]=t);try{Id()?.setItem(K4,JSON.stringify(a))}catch{}}function LJ(e,t){return Object.hasOwn(t.keys,e.key)||t.since>0&&Date.parse(e.at)<=t.since}function NJ(){try{let e=window.AudioContext??window.webkitAudioContext;if(e===void 0)return;let t=new e;[880,1175].forEach((a,n)=>{let o=t.createOscillator(),r=t.createGain(),s=t.currentTime+n*.12;o.frequency.value=a,r.gain.setValueAtTime(1e-4,s),r.gain.exponentialRampToValueAtTime(.12,s+.02),r.gain.exponentialRampToValueAtTime(1e-4,s+.22),o.connect(r).connect(t.destination),o.start(s),o.stop(s+.25)}),window.setTimeout(()=>{t.close()},1e3)}catch{}}async function IJ(e){let t=navigator.locks;if(t===void 0){e();return}await t.request(G4,()=>{e()})}function Z4(e=NJ,t=()=>({visible:document.visibilityState==="visible",task:null,run:null})){let a=null,n=new Set,o=null;try{o=typeof BroadcastChannel>"u"?null:new BroadcastChannel(G4)}catch{o=null}return o!==null&&(o.onmessage=r=>{let s=r.data?.showing;typeof s=="string"&&n.add(s)}),{see(r){let s=CJ(r),i=a;a=new Set(s.map(d=>d.key));let l=t(),u=s.filter(d=>l.visible&&(d.task!==null&&d.task===l.task||d.run!==null&&d.run===l.run)).map(d=>d.key);for(let d of u)n.add(d),o?.postMessage({showing:d});if(i===null){j4(s.map(d=>d.key),Date.now());return}let f=s.filter(d=>!i.has(d.key));f.length!==0&&window.setTimeout(()=>{IJ(()=>{let d=Y4(),c=f.filter(m=>!LJ(m,d));j4(f.map(m=>m.key),Date.now()),D1()&&c.some(m=>!n.has(m.key))&&e()})},200)},close(){o?.close()}}}var ce=O(G(),1);function _1(e){if(e.needsYou)return{...e.needsYou};let t=e.navigation.find(n=>n.label==="Home"||n.label==="Tasks"),a=t?.count??0;return{count:a,saturated:!1,scope:null,label:t?.countLabel??`${a} ${a===1?"needs":"need"} you`,href:"/tasks?view=needs-you"}}var jn={from:void 0,value:null,listeners:new Set};function J4(e,t){if(!(jn.value===null||jn.value.href!==e||jn.value.count===t)){jn.value={...jn.value,count:t,label:jn.value.label.replace(/^\d+\+?\s+needs?\b/,`${t} ${t===1?"needs":"need"}`),saturated:!1};for(let a of[...jn.listeners])a()}}function bm(e){jn.from!==e.needsYou&&(jn.from=e.needsYou,jn.value=_1(e));let[,t]=(0,xa.useState)(0);return(0,xa.useEffect)(()=>{let a=()=>t(n=>n+1);return jn.listeners.add(a),()=>{jn.listeners.delete(a)}},[]),jn.value??_1(e)}async function TJ(e){try{let t=new URL(e,window.location.origin);t.searchParams.set("format","workspace");let a=await fetch(t.pathname+t.search,{credentials:"same-origin",cache:"no-store",headers:{accept:"application/json"},signal:AbortSignal.timeout(12e3)});if(!a.ok||a.redirected)return;let n=await a.json();n.view?.kind==="tasks"&&typeof n.view.needsYou=="number"&&J4(e,n.view.needsYou)}catch{}}function e5(e,t){let a=(0,xa.useRef)(!0);(0,xa.useEffect)(()=>{if(a.current){a.current=!1;return}if(e.sensitive||t===null)return;let n=(jn.value??_1(e)).href,o=window.setTimeout(()=>{TJ(n)},400);return()=>window.clearTimeout(o)},[t])}var RJ={Home:"home",Tasks:"tasks",Flows:"flows",Agents:"agents",Projects:"projects",Settings:"settings"},Fy="so:open-search",t5=e=>{window.dispatchEvent(new CustomEvent(Fy,{detail:e??null}))};function AJ(){return(0,ce.jsxs)("a",{className:"so-rail-brand",href:"/",children:[(0,ce.jsxs)("span",{className:"so-brand-mark","aria-hidden":"true",children:[(0,ce.jsx)("i",{}),(0,ce.jsx)("i",{}),(0,ce.jsx)("i",{})]}),"Toolroll"]})}function a5({workspace:e,needs:t}){return(0,ce.jsx)(ce.Fragment,{children:e.navigation.map(a=>{let n=a.label==="Home"&&t.count>0;return(0,ce.jsxs)("a",{className:"so-nav",href:a.href,"aria-current":a.active?"page":void 0,children:[(0,ce.jsx)(Ye,{name:RJ[a.label]??"more"}),(0,ce.jsx)("span",{className:"so-nav-l",children:a.label}),n&&(0,ce.jsxs)(ce.Fragment,{children:[(0,ce.jsxs)("span",{className:"k-count ink",title:t.label,"data-needs-count":!0,children:[t.count,t.saturated?"+":""]}),(0,ce.jsx)("span",{className:"k-sr",children:`, ${t.label}`})]})]},a.href)})})}function n5({workspace:e,states:t,current:a}){let n=t!==null&&t.length>0?t.filter(o=>o.path!==null&&!o.others).map(o=>({key:o.path,name:o.name,href:o.href,needs:0})):e.projects.map(o=>({key:o.path,name:o.name,href:o.href,needs:0}));if(n.length===0)return null;for(let o of n)o.needs=e.needsYouByProject?.find(r=>r.path===o.key)?.count??0;return(0,ce.jsxs)("nav",{"aria-label":"Projects",className:"so-rail-projects","data-live":!0,"data-sidebar-slot":"projects",children:[(0,ce.jsx)("p",{className:"so-rail-h",children:"Projects"}),n.map(o=>(0,ce.jsxs)("a",{className:"so-nav so-nav-sub",href:o.href,"aria-current":o.key===a?"true":void 0,title:o.name,children:[(0,ce.jsx)("span",{className:"so-pdot","aria-hidden":"true"}),(0,ce.jsx)("span",{className:"so-nav-l",children:o.name}),o.needs>0&&!e.sensitive&&(0,ce.jsx)("span",{className:"so-nav-n k-num","aria-label":`${o.needs} ${o.needs===1?"needs":"need"} you`,children:o.needs})]},o.key))]})}function o5({workspace:e}){let t=(0,xa.useRef)(null),[a,n]=(0,xa.useState)(D1),o=r=>{let s=[...e.usage&&!e.sensitive?[{label:`Plan use · ${e.usage.text}`,act:()=>{window.location.assign(e.usage.href)}}]:[],...!e.sensitive&&e.projectStates!==void 0?[{label:a?"Turn the chime off":"Chime when something needs me",act:()=>{W4(!a),n(!a)}}]:[],{label:"Sign out",act:()=>{t.current?.requestSubmit()}}];dr(r,e.user||"Account",s)};return(0,ce.jsxs)("div",{className:"so-acct",children:[(0,ce.jsxs)("div",{className:"so-acct-row",children:[(0,ce.jsx)("span",{className:"so-av","aria-hidden":"true",children:(e.user||"?").slice(0,1).toUpperCase()}),(0,ce.jsx)("span",{className:"so-acct-name",title:e.user,children:e.user}),(0,ce.jsx)(se,{variant:"ghost",sm:!0,iconOnly:"more",label:"Account",onClick:r=>o(r.currentTarget)})]}),(0,ce.jsx)("div",{"data-live":!0,"data-sidebar-slot":"chips",children:e.fresh&&!e.sensitive?(0,ce.jsxs)(Ae,{action:e.fresh.forget,className:"so-acct-note","data-fresh-chip":!0,children:[(0,ce.jsx)("input",{type:"hidden",name:"return",value:e.path}),(0,ce.jsx)("span",{children:"Password remembered"}),(0,ce.jsxs)("span",{children:[e.fresh.minutes," min left"]}),(0,ce.jsx)(se,{variant:"ghost",sm:!0,type:"submit",label:"Forget",className:"so-acct-forget"})]}):e.passwordless?(0,ce.jsx)("p",{className:"so-acct-note",children:"Passwordless is on"}):null}),(0,ce.jsx)(Ae,{action:"/logout",ref:t,hidden:!0})]})}function r5({workspace:e,states:t,current:a}){let n=bm(e);return(0,ce.jsxs)("nav",{className:"so-rail","aria-label":"Main",children:[(0,ce.jsxs)("div",{className:"so-rail-top",children:[(0,ce.jsx)(AJ,{}),(0,ce.jsx)("span",{className:"k-grow"}),(0,ce.jsx)("a",{className:"k-btn k-btn-ghost k-btn-sm k-btn-icon",href:"/tasks/new","aria-label":"New task",title:"New task",children:(0,ce.jsx)(Ye,{name:"pen"})})]}),(0,ce.jsxs)("a",{className:"so-nav",href:"/search","data-rail-search":!0,onClick:o=>{e.sensitive||o.metaKey||o.ctrlKey||(o.preventDefault(),t5(o.currentTarget))},children:[(0,ce.jsx)(Ye,{name:"search"}),(0,ce.jsx)("span",{className:"so-nav-l",children:"Search"}),(0,ce.jsx)("kbd",{className:"so-kbd","aria-hidden":"true",children:"⌘K"})]}),(0,ce.jsx)(a5,{workspace:e,needs:n}),(0,ce.jsx)(n5,{workspace:e,states:e.sensitive?null:t,current:a}),(0,ce.jsx)("span",{className:"k-grow"}),(0,ce.jsx)(o5,{workspace:e})]})}function qy({className:e,label:t,trigger:a,dim:n=!0,onClose:o,children:r}){let s=(0,xa.useRef)(null),i=(0,xa.useRef)(o);return i.current=o,(0,xa.useLayoutEffect)(()=>{let l=s.current;if(!l)return;let u=!1,f=Do(l,a,{dim:n,onClose:()=>{u=!0,i.current()}});return()=>{u||f()}},[a,n]),(0,Q4.createPortal)((0,ce.jsx)("div",{ref:s,className:e,role:"dialog","aria-modal":"true","aria-label":t,tabIndex:-1,children:r}),document.body)}function EJ({workspace:e,trigger:t,onClose:a,states:n,current:o}){let r=bm(e);return(0,ce.jsxs)(qy,{className:"k-sheet so-nav-sheet",label:"Navigation",trigger:t,onClose:a,children:[(0,ce.jsxs)("div",{className:"k-sheet-h",children:[(0,ce.jsx)("div",{className:"k-sheet-ht",children:(0,ce.jsxs)("h2",{children:[(0,ce.jsxs)("span",{className:"so-brand-mark","aria-hidden":"true",children:[(0,ce.jsx)("i",{}),(0,ce.jsx)("i",{}),(0,ce.jsx)("i",{})]}),"Toolroll"]})}),(0,ce.jsx)(se,{variant:"ghost",iconOnly:"x",label:"Close","data-k-close":""})]}),(0,ce.jsxs)("div",{className:"k-sheet-b so-nav-sheet-b",children:[(0,ce.jsxs)("a",{className:"so-nav",href:"/tasks/new",children:[(0,ce.jsx)(Ye,{name:"plus"}),(0,ce.jsx)("span",{className:"so-nav-l",children:"New task"})]}),(0,ce.jsx)(a5,{workspace:e,needs:r}),(0,ce.jsx)(n5,{workspace:e,states:e.sensitive?null:n,current:o}),(0,ce.jsx)(o5,{workspace:e})]})]})}function s5({workspace:e,title:t,back:a,states:n,current:o,trailing:r}){let[s,i]=(0,xa.useState)(null);return(0,ce.jsxs)("header",{className:"so-ph",children:[a?(0,ce.jsx)("a",{className:"k-btn k-btn-ghost k-btn-icon",href:a,"aria-label":"Back",title:"Back",children:(0,ce.jsx)(Ye,{name:"back"})}):(0,ce.jsx)(se,{variant:"ghost",iconOnly:"menu",label:"Open navigation","aria-haspopup":"dialog",onClick:l=>i(l.currentTarget)}),(0,ce.jsx)("p",{className:"so-ph-t",children:t}),r,!e.sensitive&&(0,ce.jsx)(se,{variant:"ghost",iconOnly:"search",label:"Search",onClick:l=>t5(l.currentTarget)}),s&&(0,ce.jsx)(EJ,{workspace:e,trigger:s,onClose:()=>i(null),states:n,current:o})]})}var MJ={decide:"Decision",review:"Result",unblock:"Blocked"};async function DJ(e){let t=new URL(e,window.location.origin);t.searchParams.set("format","workspace");let a=await fetch(t.pathname+t.search,{credentials:"same-origin",cache:"no-store",headers:{accept:"application/json"},signal:AbortSignal.timeout(12e3)});if(!a.ok||a.redirected)throw new Error("unavailable");let o=(await a.json()).view;if(!o||o.kind!=="tasks")throw new Error("unavailable");let r=s=>s in Pk?Pk[s]:"Waiting on you";return J4(e,o.needsYou),{rows:o.rows.map(s=>({id:s.id,title:s.title,href:s.href,project:s.project,age:s.age,group:r(s.group),word:s.chip??(s.status.label==="Needs you"?MJ[s.group]??s.status.label:s.status.label)})),more:o.pages.next!==null}}function _J({needs:e,trigger:t,onClose:a}){let[n,o]=(0,xa.useState)({state:"loading"});(0,xa.useEffect)(()=>{let s=!0;return DJ(e.href).then(i=>{s&&o({state:"ready",...i})},()=>{s&&o({state:"failed"})}),()=>{s=!1}},[e.href]);let r=[];if(n.state==="ready")for(let s of n.rows){let i=r.find(l=>l.label===s.group);i?i.rows.push(s):r.push({label:s.group,rows:[s]})}return(0,ce.jsxs)(qy,{className:"k-sheet so-needs-sheet",label:"Needs you",trigger:t,onClose:a,children:[(0,ce.jsxs)("div",{className:"k-sheet-h",children:[(0,ce.jsxs)("div",{className:"k-sheet-ht",children:[(0,ce.jsxs)("h2",{children:["Needs you ",(0,ce.jsx)(Ct,{n:e.count,ink:!0})]}),(0,ce.jsx)(ea,{children:e.label})]}),(0,ce.jsx)(se,{variant:"ghost",iconOnly:"x",label:"Close","data-k-close":""})]}),(0,ce.jsxs)("div",{className:"k-sheet-b",children:[n.state==="loading"&&(0,ce.jsx)("p",{className:"so-sheet-line",role:"status",children:"Loading…"}),n.state==="failed"&&(0,ce.jsxs)("p",{className:"so-sheet-line",role:"alert",children:["Couldn’t load the list. ",(0,ce.jsx)("a",{className:"k-link",href:e.href,children:"Open it in Tasks"})]}),n.state==="ready"&&n.rows.length===0&&(0,ce.jsx)("p",{className:"so-sheet-line",children:"Nothing needs you."}),r.map(s=>(0,ce.jsxs)("div",{children:[(0,ce.jsx)("p",{className:"so-tri-g",children:s.label}),s.rows.map(i=>(0,ce.jsxs)("a",{className:"so-ti",href:i.href,children:[(0,ce.jsx)("span",{className:"so-ti-t",children:i.title}),(0,ce.jsxs)("span",{className:"so-ti-m",children:[(0,ce.jsx)($e,{word:i.word,tone:"ask"}),i.project&&(0,ce.jsx)("span",{children:i.project}),(0,ce.jsx)("span",{className:"k-num",children:i.age})]})]},i.id))]},s.label)),n.state==="ready"&&n.more&&(0,ce.jsx)("p",{className:"so-sheet-line",children:(0,ce.jsx)("a",{className:"k-link",href:e.href,children:"See them all in Tasks"})})]})]})}function i5({workspace:e}){let t=bm(e),[a,n]=(0,xa.useState)(null),o=(0,xa.useCallback)(()=>n(null),[]);return t.count===0?null:(0,ce.jsxs)("div",{className:"so-dock","data-needs-dock":!0,children:[(0,ce.jsx)(X_,{count:t.count,label:t.label,scope:t.scope===null?"All projects":t.label,onOpen:r=>n(r.currentTarget)}),a&&(0,ce.jsx)(_J,{needs:t,trigger:a,onClose:o})]})}var Et=O(G(),1),PJ=[["Models","/settings/models","Settings → Agents and models","planner builder reviewer opus sonnet haiku codex model per phase"],["Lead and subagents","/settings/lead","Settings → Agents and models","lead chat subagent"],["Tools","/settings/tools","Settings → Agents and models","mcp"],["Knowledge","/settings/knowledge","Settings → Agents and models","instructions project knowledge"],["Skills","/settings/skills","Settings → Agents and models","skill tests"],["Learning","/settings/learning","Settings → Agents and models","lessons"],["Chat apps","/settings/alerts#chat-apps","Settings → Chat apps and alerts","telegram slack discord teams phone"],["Operating mode","/mode","Settings → Approvals and safety","hands-off mode"],["Approval rules","/settings/approval","Settings → Approvals and safety","automatic approval auto-approve"],["Policy","/settings/policy","Settings → Approvals and safety","protected paths"],["Checks","/settings/checks","Settings → Approvals and safety","tests release check"],["Pull requests","/settings/pull-requests","Settings → Projects","github publish merge"],["People","/people","Settings → People and sign-in","invite roles members"],["Sessions and tokens","/settings/sessions","Settings → People and sign-in","api token"],["Sign-in with a provider","/settings/sign-in","Settings → People and sign-in","sso oauth github google"],["Passwordless","/settings/passwordless","Settings → People and sign-in","password"],["Audit log","/ledger","Settings → People and sign-in","history ledger action ledger"],["Updates","/settings/updates","Settings → System","version upgrade"],["Backups","/settings/backups","Settings → System","backup restore"],["Storage","/settings/storage","Settings → System","disk checkouts"],["Retention","/settings/retention","Settings → System"],["Monitoring","/settings/monitoring","Settings → System","traces otel audit stream"],["Data export","/settings/data","Settings → System","export zip"],["Integrations","/settings/integrations","Settings → System","webhooks"],["Spend","/spend","Settings → Spend","monthly limits budget cap cost usage"],["Terminals","/term","Agents","shell console"]],OJ=[["Recipes","/flows/new","Flows → New flow","recipe one-time work"],["Kits","/kits","Flows → New flow","kit starter"],["Limits","/spend","Spend → Monthly limits","budget"],["Live","/agents","Agents","live view peek"],["Builders","/agents#computers","Agents → Computers that build","builder computers runner fleet"],["System","/agents","Agents","agents per phase"],["Board","/tasks?view=board","Tasks → Board","kanban"],["Inbox","/tasks?view=needs-you","Tasks → Needs you","waiting"],["Queue","/tasks?view=order","Tasks → Board","order"],["Done","/tasks?view=completed","Tasks → Finished","finished complete"],["Runs","/agents","Agents → Finished","builds attempts history"],["Activity","/","Home","morning summary"],["Workspace tools","/menu","Settings","menu"],["All settings","/settings","Settings"]],l5={attention:"needs",ready:"needs",live:"live",done:"done",problem:"failed",muted:"",neutral:""};function $y(e){let t=a=>a===null?"":e.projects.find(n=>n.path===a)?.name??a.split(/[\\/]/).filter(Boolean).pop()??"";return[...e.crew.map(a=>{let n=l5[a.tone]==="needs";return{kind:"task",title:a.title,sub:[t(a.project),a.label].filter(Boolean).join(" · "),href:a.resultHref??a.href,chip:{word:a.label,tone:n?"ask":l5[a.tone]??""},also:a.id,needs:n}}),...e.projects.map(a=>({kind:"project",title:a.name,sub:"Project",href:a.href})),...(e.chats??[]).map(a=>({kind:"chat",title:a.title,sub:a.kind==="task"?"Task chat":"Project chat",href:a.href})),...e.navigation.map(a=>({kind:"page",title:a.label,sub:"",href:a.href})),{kind:"page",title:"Chat with the lead",sub:"Home",href:"/chat",also:"lead ask"},...PJ.map(([a,n,o,r])=>({kind:"setting",title:a,sub:o,href:n,...r?{also:r}:{}})),...OJ.map(([a,n,o,r])=>({kind:"page",title:a,sub:`Now ${o}`,href:n,legacy:!0,...r?{also:r}:{}}))]}var c5=(e,t)=>{let a=`${e.title} ${e.sub} ${e.also??""}`.toLowerCase();return t.every(n=>a.includes(n))},u5=(e,t)=>{let a=e.title.toLowerCase();return a.startsWith(t)?0:a.includes(t)?1:2},P1={task:"Tasks",project:"Projects",chat:"Chats",setting:"Settings",page:"Go to",action:"Actions"};function BJ(e,t){let a=t.trim().toLowerCase(),n=$y(e),o=[{kind:"action",title:"New task",sub:a?"Describe the change on the next page":"Describe a change in a sentence",href:"/tasks/new"},{kind:"action",title:"Ask the lead",sub:a?`“${t.trim()}”`:"A question about your projects",href:a?`/chat?draft=${encodeURIComponent(t.trim())}`:"/chat"}];if(a==="")return[...n.filter(l=>l.kind==="task"&&l.needs).slice(0,4),...o,...n.filter(l=>l.kind==="page"&&!l.legacy)];let r=a.split(/\s+/),s=n.filter(l=>c5(l,r)),i=s.filter(l=>l.kind==="setting"||l.kind==="page").map((l,u)=>[l,u]).sort((l,u)=>u5(l[0],a)-u5(u[0],a)||l[1]-u[1]).map(([l])=>l).slice(0,5);return[...s.filter(l=>l.kind==="task").slice(0,5),...s.filter(l=>l.kind==="project").slice(0,3),...s.filter(l=>l.kind==="chat").slice(0,3),...i,...o]}function d5({workspace:e}){let[t,a]=(0,Kn.useState)(!1);return(0,Kn.useEffect)(()=>{if(e.sensitive)return;let n=r=>{!(r.metaKey||r.ctrlKey)||r.altKey||r.key.toLowerCase()!=="k"||r.target instanceof Element&&r.target.closest('input, textarea, select, [contenteditable="true"], [role="textbox"]')&&!r.target.closest(".so-cmdk")||(r.preventDefault(),a(s=>s===!1?document.activeElement instanceof HTMLElement?document.activeElement:null:!1))},o=r=>{if(window.location.pathname==="/search"){document.getElementById("search-page-q")?.focus();return}a(r.detail??null)};return window.addEventListener("keydown",n),window.addEventListener(Fy,o),()=>{window.removeEventListener("keydown",n),window.removeEventListener(Fy,o)}},[e.sensitive]),e.sensitive||t===!1?null:(0,Et.jsx)(zJ,{workspace:e,trigger:t,onClose:()=>a(!1)})}function zJ({workspace:e,trigger:t,onClose:a}){let[n,o]=(0,Kn.useState)(""),[r,s]=(0,Kn.useState)(0),i=(0,Kn.useId)(),l=(0,Kn.useRef)(null),u=(0,Kn.useMemo)(()=>BJ(e,n),[e,n]),f=u.filter(y=>y.kind!=="action").length,d=n.trim()===""?0:$y(e).filter(y=>c5(y,n.trim().toLowerCase().split(/\s+/))).length;(0,Kn.useEffect)(()=>{s(0)},[n]),(0,Kn.useEffect)(()=>{l.current?.querySelector(`[data-index="${r}"]`)?.scrollIntoView({block:"nearest"})},[r]);let c=y=>{y&&window.location.assign(y.href)},m=`/search${n.trim()?`?q=${encodeURIComponent(n.trim())}`:""}`,h=null;return(0,Et.jsxs)(qy,{className:"so-cmdk",label:"Search",trigger:t,onClose:a,children:[(0,Et.jsxs)("div",{className:"so-cmdk-h",children:[(0,Et.jsx)(Ye,{name:"search"}),(0,Et.jsx)("label",{className:"k-sr",htmlFor:`${i}-q`,children:"Search tasks, projects, chats and settings"}),(0,Et.jsx)(Na,{id:`${i}-q`,className:"so-cmdk-in",type:"search",autoFocus:!0,autoComplete:"off",spellCheck:!1,placeholder:"Search or type a command",role:"combobox","aria-expanded":"true","aria-controls":i,"aria-activedescendant":u.length>0?`${i}-${r}`:void 0,value:n,onChange:y=>o(y.target.value),onKeyDown:y=>{(y.key==="ArrowDown"||y.key==="ArrowUp")&&(y.preventDefault(),u.length&&s(b=>(b+(y.key==="ArrowDown"?1:u.length-1))%u.length)),y.key==="Enter"&&!y.nativeEvent.isComposing&&(y.preventDefault(),c(u[r]))}}),(0,Et.jsx)(se,{variant:"ghost",sm:!Ns(),iconOnly:"x",label:"Close",className:"so-cmdk-x","data-k-close":""})]}),(0,Et.jsxs)("div",{className:"so-cmdk-list",id:i,role:"listbox","aria-label":"Results",ref:l,children:[n.trim()!==""&&f===0&&(0,Et.jsxs)("p",{className:"so-cmdk-none",children:["Nothing here matches “",n.trim(),"”. See all results to look through older tasks too."]}),u.map((y,b)=>{let g=n.trim()===""&&y.kind==="task"?"Needs you":P1[y.kind],x=g!==h?(0,Et.jsx)("p",{className:"so-cmdk-g",role:"presentation",children:g}):null;return h=g,(0,Et.jsxs)("div",{children:[x,(0,Et.jsxs)("a",{id:`${i}-${b}`,className:"so-cmdk-i",role:"option","aria-selected":b===r,"data-index":b,href:y.href,onMouseMove:()=>{b!==r&&s(b)},children:[(0,Et.jsxs)("span",{className:"so-cmdk-t",children:[y.kind==="action"&&(0,Et.jsx)(Ye,{name:y.title==="New task"?"plus":"arrow",small:!0}),(0,Et.jsx)("span",{children:y.title})]}),y.chip&&(0,Et.jsx)($e,{word:y.chip.word,tone:y.chip.tone}),y.sub&&(0,Et.jsx)("span",{className:"so-cmdk-s",children:y.sub})]})]},`${y.kind}:${y.href}:${y.title}`)})]}),(0,Et.jsxs)("div",{className:"so-cmdk-f",children:[(0,Et.jsxs)("span",{className:"k-desk-only",children:[(0,Et.jsx)("kbd",{className:"so-kbd",children:"↑"}),(0,Et.jsx)("kbd",{className:"so-kbd",children:"↓"})," move"]}),(0,Et.jsxs)("span",{className:"k-desk-only",children:[(0,Et.jsx)("kbd",{className:"so-kbd",children:"↵"})," open"]}),(0,Et.jsx)("span",{className:"k-grow"}),(0,Et.jsx)("a",{className:"k-link",href:m,children:d>f?`See all ${d} results`:"See all results"})]})]})}var gt=O(G(),1);function f5({view:e,workspace:t}){let[a,n]=(0,Uy.useState)(e.q),o=a.trim().toLowerCase().split(/\s+/).filter(Boolean),r=(0,Uy.useMemo)(()=>t===null||o.length===0?[]:$y(t).filter(u=>u.kind!=="task"&&o.every(f=>`${u.title} ${u.sub} ${u.also??""}`.toLowerCase().includes(f))),[t,a]),s=e.q.trim().toLowerCase()===a.trim().toLowerCase()?e.tasks:e.tasks.filter(u=>o.every(f=>`${u.title} ${u.id}`.toLowerCase().includes(f))),i=["project","chat","setting","page"];return(0,gt.jsxs)("div",{className:"so-search","data-kit-page":!0,"data-search":!0,children:[(0,gt.jsx)(tn,{title:"Search",right:null}),(0,gt.jsx)("div",{className:"so-search-bar",children:(0,gt.jsxs)("form",{action:"/search",method:"get",role:"search",className:"so-search-box",onSubmit:u=>{a.trim()===""&&u.preventDefault()},children:[(0,gt.jsx)(Ye,{name:"search",small:!0}),(0,gt.jsx)("label",{className:"k-sr",htmlFor:"search-page-q",children:"Search"}),(0,gt.jsx)(Na,{id:"search-page-q",className:"so-search-in",type:"search",name:"q",value:a,onChange:u=>n(u.target.value),placeholder:"Search tasks, projects, chats and settings",autoComplete:"off",spellCheck:!1,autoFocus:!0})]})}),o.length===0?(0,gt.jsx)(Ua,{title:"Search everything in this Toolroll.",text:"Tasks, including finished and archived ones, projects, chats, every page and setting, and the old names of things."}):s.length===0&&r.length===0?(0,gt.jsx)(Ua,{title:`Nothing matches “${a.trim()}” here.`,text:e.truncated?"Search reads your 100 most recent tasks and 40 most recent archived ones, so an older task may not show. Every task is in Tasks.":"Search looks in task titles and ids, projects, chats, pages and settings.",...e.truncated?{action:(0,gt.jsx)(He,{sm:!0,label:"Open every task in Tasks",href:"/tasks?view=all"})}:{}}):(0,gt.jsxs)("div",{className:"so-search-results","aria-live":"polite",children:[s.length>0&&(0,gt.jsxs)(gt.Fragment,{children:[(0,gt.jsxs)("h2",{className:"k-grp",children:["Tasks",(0,gt.jsx)(Ct,{n:s.length})]}),s.map(u=>(0,gt.jsx)(xn,{href:u.href,chip:(0,gt.jsx)($e,{word:u.chip.word,tone:u.chip.tone}),title:u.title,desc:u.archived?"Archived":"",meta:(0,gt.jsxs)(gt.Fragment,{children:[u.project&&(0,gt.jsx)("span",{children:u.project}),(0,gt.jsx)("span",{className:"k-num",children:u.age})]})},u.id))]}),e.truncated&&(0,gt.jsxs)("p",{className:"so-search-note",children:["Search reads your 100 most recent tasks and 40 most recent archived ones. ",(0,gt.jsx)("a",{className:"k-link",href:"/tasks?view=all",children:"Every task is in Tasks"}),"."]}),i.map(u=>{let f=r.filter(d=>d.kind===u);return f.length===0?null:(0,gt.jsxs)("div",{children:[(0,gt.jsxs)("h2",{className:"k-grp",children:[P1[u],(0,gt.jsx)(Ct,{n:f.length})]}),f.map(d=>(0,gt.jsx)(xn,{href:d.href,chip:null,title:d.title,desc:d.sub},`${d.href}:${d.title}`))]},u)})]})]})}var hr=O(G(),1),HJ=(e,t,a)=>(0,hr.jsx)(vS,{selected:e,csrf:t,inTask:{current:a}},`${e.taskId}:${e.build??""}`);function p5({view:e,csrf:t,taskChat:a=null,taskDetails:n=!0,workspace:o=null}){return(0,hr.jsx)("div",{"data-view":e.kind,className:"w-full",children:e.kind==="tasks"?(0,hr.jsx)(FP,{view:e}):e.kind==="task"?(0,hr.jsx)(EP,{view:e,chat:a,details:n,csrf:t,result:HJ}):e.kind==="projects"?(0,hr.jsx)(DP,{view:e,csrf:t}):e.kind==="result"?(0,hr.jsx)(OP,{view:e,csrf:t}):e.kind==="flow"?(0,hr.jsx)(w4,{view:e,csrf:t}):e.kind==="agents"?(0,hr.jsx)(U4,{view:e}):e.kind==="home"?(0,hr.jsx)(V4,{view:e}):e.kind==="search"?(0,hr.jsx)(f5,{view:e,workspace:o}):null})}function m5(e){return e.security?`Toolroll ${e.version} is available, with security fixes`:`Toolroll ${e.version} is available`}function h5(e){return e==="/settings"||e.startsWith("/settings/")||e==="/setup"||e.startsWith("/setup/")||e==="/people"||e==="/mode"||e==="/control"||e==="/spend"}var pt=O(G(),1);function Hs({name:e}){return(0,pt.jsx)("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",width:"20",height:"20",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",children:{menu:(0,pt.jsx)("path",{d:"M4 6h16M4 12h16M4 18h16"}),chat:(0,pt.jsx)("path",{d:"M5 4h14a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H9l-6 3V6a2 2 0 0 1 2-2Z"}),tasks:(0,pt.jsx)(pt.Fragment,{children:(0,pt.jsx)("path",{d:"m3 6 2 2 4-4m-6 9 2 2 4-4m-6 9 2 2 4-4M13 6h8M13 13h8M13 20h8"})}),agents:(0,pt.jsxs)(pt.Fragment,{children:[(0,pt.jsx)("rect",{width:"18",height:"14",x:"3",y:"5",rx:"2"}),(0,pt.jsx)("path",{d:"m7 10 3 2-3 2M13 14h4"})]}),flows:(0,pt.jsxs)(pt.Fragment,{children:[(0,pt.jsx)("rect",{width:"8",height:"8",x:"3",y:"3",rx:"2"}),(0,pt.jsx)("path",{d:"M7 11v4a2 2 0 0 0 2 2h4"}),(0,pt.jsx)("rect",{width:"8",height:"8",x:"13",y:"13",rx:"2"})]}),projects:(0,pt.jsx)("path",{d:"M3 7V5a2 2 0 0 1 2-2h5l3 4h6a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V7Z"}),knowledge:(0,pt.jsx)("path",{d:"M12 5c-3-2-7-2-10-1v15c3-1 7-1 10 1 3-2 7-2 10-1V4c-3-1-7-1-10 1Zm0 0v15"}),settings:(0,pt.jsxs)(pt.Fragment,{children:[(0,pt.jsx)("path",{d:"M4 6h16M4 12h16M4 18h16"}),(0,pt.jsx)("path",{d:"M8 3v6M16 9v6M10 15v6"})]}),arrow:(0,pt.jsx)("path",{d:"m10 6-6 6 6 6M4 12h16"}),close:(0,pt.jsx)("path",{d:"m6 6 12 12M6 18 18 6"}),send:(0,pt.jsx)("path",{d:"m12 19 0-14m-6 6 6-6 6 6"}),tools:(0,pt.jsx)(pt.Fragment,{children:(0,pt.jsx)("path",{d:"M4 4h6v6H4zM14 4h6v6h-6zM4 14h6v6H4zM14 14h6v6h-6z"})}),plus:(0,pt.jsx)("path",{d:"M12 5v14M5 12h14"})}[e]})}var ra=O(he(),1);var xe=O(G(),1),FJ=[["support-desk","Support desk"],["bug-triage","Bug triage"],["sales-follow-up","Sales follow-up"],["ops-requests","Ops requests"]],g5={task:{title:"Ask about this task",hint:"Questions, changes and next steps. Actions come back as cards you confirm.",placeholder:"Ask about this task…",suggestions:["Where does this task stand?","Move this forward","Request changes: "]},result:{title:"Ask about this result",hint:"Ask what changed or why, or request a revision. Actions come back as cards you confirm.",placeholder:"Ask about this result…",suggestions:["Summarize what changed","What does the check log say?","Request changes: "]},tasks:{title:"Ask about this project",hint:"Plan work, file tasks and check progress. Actions come back as cards you confirm.",placeholder:"Ask about this project…",suggestions:["What needs my attention here?","What should we build next?","File a task: "]}},v5={lead:["What needs my attention right now?","What should we work on next?","File a task: ","Make a flow for "],tasks:["What needs my attention here?","What should we build next?","File a task: ","Make a flow for "]},w5="New conversation — the projects I can reach changed";function k5(e,t){if(e.role!=="assistant"||t?.role!=="operator")return null;let a=Date.parse(e.createdAt)-Date.parse(t.createdAt);return!Number.isFinite(a)||a<0||a>=60*6e4?null:a<6e4?`${Math.max(1,Math.round(a/1e3))} s`:`${Math.round(a/6e4)} min`}function qJ(e,t){for(let a=t-1;a>=0;a--)if(e[a].role==="operator")return e[a].text.trim()||null;return null}var $J=e=>e.trim().replace(/:$/,"…").replace(/ (for|to)$/," $1…");function S5({at:e}){let t=io();return(0,xe.jsx)("time",{className:"lc-time",dateTime:e,title:Pl(e,t),children:tr(e,new Date,t)})}async function C5(e){try{return await navigator.clipboard.writeText(e),!0}catch{return!1}}function y5({label:e,act:t,ariaLabel:a}){let[n,o]=(0,ra.useState)(null),r=(0,ra.useRef)(0);return(0,ra.useEffect)(()=>()=>window.clearTimeout(r.current),[]),(0,xe.jsx)(se,{variant:"ghost",sm:!0,className:"lc-act","aria-label":n??a,label:n??e,onClick:()=>{t().then(s=>{s!==null&&(o(s),window.clearTimeout(r.current),r.current=window.setTimeout(()=>o(null),1600))})}})}function UJ(e,t){(0,ra.useLayoutEffect)(()=>{e.current?.querySelectorAll("pre").forEach(a=>{if(a.parentElement?.classList.contains("lc-code"))return;let n=document.createElement("div");n.className="lc-code";let o=document.createElement("button");o.type="button",o.className="lc-codecopy",o.dataset.codeCopy="",o.setAttribute("aria-label","Copy code"),o.textContent="Copy",a.replaceWith(n),n.append(o,a)})},[e,t])}var VJ=e=>{let t=e.target.closest("[data-code-copy]"),a=t?.nextElementSibling?.textContent;!t||a==null||C5(a).then(n=>{t.textContent=n?"Copied":"Couldn't copy",window.setTimeout(()=>{t.textContent="Copy"},1600)})};function x5({message:e,onEdit:t,arrived:a=!1}){return(0,xe.jsxs)("article",{className:a?"lc-msg lc-you lc-new":"lc-msg lc-you","data-message-id":e.id,"aria-label":"You",children:[(0,xe.jsx)("div",{className:"lc-bubble",children:(0,xe.jsx)(St,{html:e.html})}),(0,xe.jsxs)("div",{className:"lc-meta",children:[(0,xe.jsx)(S5,{at:e.createdAt}),t&&(0,xe.jsx)(se,{variant:"ghost",sm:!0,className:"lc-act",label:"Edit","aria-label":"Edit: put these words back in the message box",onClick:t})]})]})}function b5({message:e,workspace:t,onChanged:a,took:n,retry:o,arrived:r=!1}){let s=(0,ra.useRef)(null),[i,l]=(0,ra.useState)(null);UJ(s,e.html);let u=t.leadName??"Lead",f=o===null;return(0,xe.jsxs)("article",{className:r?"lc-msg lc-lead lc-new":"lc-msg lc-lead","data-message-id":e.id,"aria-label":u,children:[(0,xe.jsxs)("header",{className:"lc-who",children:[(0,xe.jsx)(Cv,{}),(0,xe.jsx)("b",{children:u}),(0,xe.jsx)(S5,{at:e.createdAt})]}),e.activity&&(0,xe.jsxs)("p",{className:"lc-activity","data-activity":!0,children:[n===null?"Worked":`Worked ${n}`," · ",e.activity]}),(0,xe.jsx)("div",{className:"lc-body",ref:s,onClick:VJ,children:(0,xe.jsx)(St,{html:e.html})}),e.cards!==void 0&&e.cards.length>0?(0,xe.jsx)(td,{look:"row",cards:e.cards,csrf:t.csrf,onChanged:a,readOnly:f}):e.cardsHtml&&(0,xe.jsx)(St,{html:e.cardsHtml,className:"so-message-cards lc-cards-html"}),!f&&(0,xe.jsxs)("div",{className:"lc-meta",children:[(0,xe.jsx)(y5,{label:"Copy",ariaLabel:`Copy ${u}'s answer`,act:async()=>await C5(e.text)?"Copied":"Couldn't copy"}),(0,xe.jsx)(y5,{label:"Retry",ariaLabel:"Retry: ask the same question again",act:async()=>{let d=await o();return l(d),d===null?"Sent":null}})]}),i!==null&&(0,xe.jsx)("p",{className:"lc-said k-err",role:"alert",children:i})]})}function jJ(){let{isAtBottom:e,scrollToBottom:t}=Kf();return(0,xe.jsx)(se,{variant:"outline",iconOnly:"chevron",label:"Jump to the latest message",className:e?"lc-jump":"lc-jump show",tabIndex:e?-1:0,"aria-hidden":e?!0:void 0,onClick:()=>{t({animation:"instant"})}})}function O1({title:e,text:t,children:a}){return(0,xe.jsxs)("div",{className:"lc-empty","data-chat-empty":!0,children:[(0,xe.jsx)(Cv,{}),(0,xe.jsx)("h2",{children:e}),t!==""&&(0,xe.jsx)("p",{children:t}),a]})}function z1({controller:e,docked:t=null}){let{workspace:a,draft:n,notice:o,storageAvailable:r,sending:s,stale:i,offline:l}=e,u=a.conversation,f=t===null?null:g5[t]??g5.task,d=(0,ra.useRef)(null),c=(0,ra.useRef)(null),m=u.pendingTurnId!==null,h=a.leadName??"Lead",y=t??(u.taskId?"task":u.project?"tasks":"lead"),b=eS[y]??eS.lead,g=/^\/(\w*)$/.exec(n.text)?.[1]?.toLowerCase(),[x,v]=(0,ra.useState)(0),[w,k]=(0,ra.useState)(!1),C=g===void 0||w?[]:b.filter(X=>X.command.startsWith(g)),N=(0,ra.useId)(),[S,T]=(0,ra.useState)(!1),[q,z]=(0,ra.useState)("idle"),U=()=>requestAnimationFrame(()=>{let X=d.current;X&&(X.focus(),X.setSelectionRange(X.value.length,X.value.length))}),$=X=>{T(!1),e.edit(X)},L=X=>{$(X.text),v(0),U()},I=Sv(u,m||n.pending!==null&&!s,()=>{e.check()}),R=s||i||l||n.pending!==null,A=l?"Offline. Your draft stays in this tab.":s?"Sending…":S?"":o;(0,ra.useEffect)(()=>{f||window.location.hash!==""||!matchMedia("(pointer: fine) and (min-width: 761px)").matches||document.activeElement!==null&&document.activeElement!==document.body||d.current?.focus({preventScroll:!0})},[]),(0,ra.useEffect)(()=>{m||z("idle")},[m]);let[H,M]=(0,ra.useState)(null),_=async X=>{T(!1),await e.send(X)==="refused"&&T(!0)},F=async()=>{if(!(u.pendingTurnId===null||q==="busy")){z("busy");try{let X=await fetch("/chat/mate/stop",{method:"POST",credentials:"same-origin",redirect:"manual",headers:Wt({}),body:new URLSearchParams({csrf:a.csrf,turn:String(u.pendingTurnId),return:window.location.pathname+window.location.search})});z(X.type==="opaqueredirect"||X.ok?"idle":"The lead didn't stop. Try again.")}catch{z("The lead didn't stop. Check your connection and try again.")}e.check()}},Q=f?[]:u.previous?.messages??[],ue=(0,ra.useRef)(new Set(u.messages.map(X=>X.id))),oe=u.messages.length===0&&Q.length===0,Z=u.project?a.projects.find(X=>X.path===u.project)?.name??u.project.split("/").filter(Boolean).at(-1)??u.project:null,ne=!f&&!u.project&&!u.taskId&&u.sessionId!==0&&u.messages.length>0,le=X=>{if(C.length===0)return;let de=Math.min(x,C.length-1);if(X.key==="ArrowDown"||X.key==="ArrowUp"){X.preventDefault(),v((de+(X.key==="ArrowDown"?1:C.length-1))%C.length);return}if(X.key==="Enter"&&!X.shiftKey||X.key==="Tab"){X.preventDefault(),L(C[de]);return}X.key==="Escape"&&(X.preventDefault(),k(!0))},K=r?n.text.length>u.maxChars-200?`${n.text.length} / ${u.maxChars}`:null:"Draft stays on this page only.",B=X=>(0,xe.jsx)("div",{className:"lc-sugs",role:"list",children:X.map(de=>(0,xe.jsx)(se,{role:"listitem",variant:"outline",sm:!0,className:"lc-sug",label:$J(de),onClick:()=>{$(de),U()}},de))});return(0,xe.jsxs)("div",{className:f?"so-lead-chat lc lc-docked":"so-lead-chat lc","data-workspace-chat":!0,children:[!f&&(0,xe.jsx)(tn,{title:"Chat",ctx:[h,Z].filter(Boolean).join(" · "),right:(0,xe.jsxs)(xe.Fragment,{children:[ne&&(0,xe.jsxs)(Ae,{action:"/chat/mate/end",className:"lc-tb-form",children:[(0,xe.jsx)("input",{type:"hidden",name:"return",value:"/chat"}),(0,xe.jsx)(se,{type:"submit",variant:"ghost",sm:!0,lead:"plus",label:"New chat",title:"End this conversation and start a new one"})]}),(0,xe.jsx)(He,{variant:"ghost",sm:!0,href:"/settings/lead",label:"Lead settings"})]})}),(0,xe.jsxs)(dA,{className:"so-conversation lc-scroll",children:[(0,xe.jsxs)(fA,{className:"lc-thread",children:[!f&&a.firstRun&&(0,xe.jsx)(wv,{firstRun:a.firstRun}),!f&&!a.home&&a.catchUpHtml&&(0,xe.jsx)(St,{html:a.catchUpHtml,className:"so-catch-up lc-brief"}),Q.length>0&&(0,xe.jsxs)(xe.Fragment,{children:[(0,xe.jsx)("section",{className:"lc-previous","aria-label":"Earlier conversation","data-previous-thread":!0,children:Q.map(X=>X.role==="operator"?(0,xe.jsx)(x5,{message:X,onEdit:null},X.id):(0,xe.jsx)(b5,{message:X,workspace:a,took:null,retry:null,onChanged:()=>{e.check()}},X.id))}),(0,xe.jsx)("p",{className:"lc-divider",role:"separator","data-thread-divider":!0,children:(0,xe.jsx)("span",{children:w5})})]}),oe&&(f?(0,xe.jsx)(O1,{title:f.title,text:f.hint,children:B(f.suggestions)}):a.firstRun?!m&&(0,xe.jsx)(O1,{title:"What should we work on?",text:a.firstRun.intro??"",children:(0,xe.jsx)(J_,{firstRun:{...a.firstRun,intro:""},onDraft:X=>{$(Q_(n.text,X)),U()}})}):(0,xe.jsxs)(O1,{title:"What should we work on?",text:`${h} reads ${Z??"your projects"}, files tasks and opens what needs you. Nothing is built until you approve its plan.`,children:[B(v5[y]??v5.lead),!Z&&(0,xe.jsxs)("nav",{className:"lc-kits","aria-label":"Starter kits","data-kit-links":!0,children:[(0,xe.jsx)("span",{children:"Or start from a kit:"}),FJ.map(([X,de])=>(0,xe.jsx)("a",{href:`/kits/${X}`,children:de},X))]})]})),(0,xe.jsxs)("div",{id:"chat-thread",className:"lc-messages","data-chat-region":"thread",children:[u.messages.map((X,de)=>{if(X.role==="operator")return(0,xe.jsx)(x5,{message:X,arrived:!ue.current.has(X.id),onEdit:()=>{$(X.text),U()}},X.id);let fe=qJ(u.messages,de);return(0,xe.jsx)(b5,{message:X,workspace:a,arrived:!ue.current.has(X.id),took:k5(X,u.messages[de-1]),onChanged:()=>{e.check()},retry:fe===null?null:()=>e.steer(fe)},X.id)}),(m||I!==null)&&(0,xe.jsx)(Lv,{look:"lead",live:I,leadName:h}),!m&&I===null&&u.failure&&(0,xe.jsx)("p",{className:"so-live-failed",role:"alert","data-lead-failed":!0,children:u.failure})]})]}),(0,xe.jsx)(jJ,{})]}),(0,xe.jsxs)("div",{className:"so-composer-area lc-dock",children:[A&&(0,xe.jsxs)("div",{className:"lc-connection",role:i?"alert":"status",children:[(0,xe.jsx)("span",{children:A}),i?(0,xe.jsx)(se,{variant:"outline",sm:!0,onClick:e.reconnect,label:"Reconnect"}):!s&&!l&&(0,xe.jsx)(se,{variant:"ghost",sm:!0,onClick:()=>{e.check()},label:"Check again"})]}),q!=="idle"&&q!=="busy"&&(0,xe.jsx)("p",{className:"lc-said k-err",role:"alert",children:q}),(0,xe.jsxs)(Ae,{ref:c,onSubmit:X=>{_(X)},action:"/chat","data-workspace-composer":!0,"aria-busy":s,className:"lc-form",children:[C.length>0&&(0,xe.jsx)("ul",{id:N,role:"listbox","aria-label":"Commands",className:"lc-slash",children:C.map((X,de)=>(0,xe.jsxs)("li",{role:"option","aria-selected":de===Math.min(x,C.length-1),onMouseDown:fe=>{fe.preventDefault(),L(X)},children:[(0,xe.jsxs)("span",{className:"lc-slash-name",children:["/",X.command]}),(0,xe.jsx)("span",{className:"lc-slash-hint",children:X.hint})]},X.command))}),(0,xe.jsx)(ed,{id:"lead-chat",textareaId:"lead-message",name:"message",maxLength:u.maxChars,label:"Message your lead",textareaRef:d,placeholder:f?.placeholder??(Z?`Ask about ${Z}…`:"Message your lead…"),value:n.text,onChange:X=>{k(!1),$(X)},onSend:()=>c.current?.requestSubmit(),submit:!0,sendDisabled:R,sendLabel:m?"Queue message":"Send message",working:m&&n.text.trim()==="",onStop:()=>{F()},stopLabel:q==="busy"?"Stopping…":"Stop the lead",...!f&&!u.taskId?{project:{current:Z??B1,sub:h,items:[B1,...a.projects.map(X=>X.name)]},onProject:X=>{if(X===B1){u.project&&window.location.assign("/chat");return}let de=a.projects.find(fe=>fe.name===X);de&&de.path!==u.project&&window.location.assign(`/chat?project=${encodeURIComponent(de.path)}`)}}:{},...!f&&a.controlsHtml?{menu:[{label:"Conversation settings",act:()=>M(document.querySelector('[data-k-composer="lead-chat"] .k-composer-plus'))}]}:{},combobox:C.length>0?{expanded:!0,controls:N}:null,onKeyDown:le,enterSends:X=>H1()||X.metaKey||X.ctrlKey,note:K,error:S&&o?o:null})]}),!f&&a.controlsHtml&&H&&(0,xe.jsx)(co,{kind:"popover",title:"Conversation settings",trigger:H,onClose:()=>M(null),children:(0,xe.jsx)(St,{html:a.controlsHtml,immutable:!0,className:"lc-settings"})})]})]})}var B1="All projects",KJ="(hover: none) and (pointer: coarse) and (max-width: 900px)";function H1(){return!document.documentElement.hasAttribute("data-mobile-keyboard")&&!matchMedia(KJ).matches}var V=O(G(),1);function Vy(){try{return window.sessionStorage}catch{return{getItem:()=>null,removeItem:()=>{},setItem:()=>{throw new Error("Storage unavailable")}}}}function jy(e){let t=e.conversation;return t?{user:e.user,session:t.sessionId,task:t.taskId??(t.project?`project:${t.project}`:null)}:null}function F1(){return!document.hidden&&navigator.onLine!==!1}var GJ=new Set(["/tasks","/tasks/archive","/agents","/code"]);function WJ(e){let[t,a]=(0,De.useState)(e),n=jy(e),[o,r]=(0,De.useState)(()=>{let A=e.conversation&&n?wA(Vy(),n,e.conversation.requestId,e.conversation.maxChars):Dc(""),H=e.conversation?new URLSearchParams(window.location.search).get("draft"):null;return H&&A.text===""&&A.pending===null?{...A,text:H.slice(0,e.conversation.maxChars)}:A});(0,De.useEffect)(()=>{let A=new URL(window.location.href);A.searchParams.has("draft")&&(A.searchParams.delete("draft"),window.history.replaceState(window.history.state,"",A.pathname+A.search+A.hash))},[]);let[s,i]=(0,De.useState)(""),[l,u]=(0,De.useState)(!0),[f,d]=(0,De.useState)(!1),[c,m]=(0,De.useState)(!1),[h,y]=(0,De.useState)(()=>navigator.onLine===!1),b=(0,De.useRef)({workspace:t,draft:o,stale:c,sending:f,notice:s});b.current={workspace:t,draft:o,stale:c,sending:f,notice:s};let g=(0,De.useRef)(!1),x=(0,De.useRef)(!1),v=(0,De.useRef)(null),w=(0,De.useRef)(null),k=(0,De.useCallback)(()=>{w.current!==null&&clearTimeout(w.current),w.current=null},[]),C=(0,De.useRef)(!0),N=(0,De.useRef)(!1),S=(0,De.useRef)(null),T=(0,De.useCallback)(A=>{b.current.draft=A,r(A);let H=jy(b.current.workspace);H&&u(X0(Vy(),H,A))},[]),q=e.view?.kind==="task"&&e.view.live!=null&&!e.sensitive,z=(e.view?.kind==="agents"||e.view?.kind==="home")&&!e.sensitive,U=!!(e.conversation||e.refreshSeconds||z),$=(0,De.useCallback)(async(A=!0,H=!1)=>{if(k(),!C.current||b.current.stale||!(U||q)||!F1())return;if(g.current){x.current=!0;return}x.current=!1,g.current=!0;let M=b.current.draft.pending?.request??null;try{let _=await TA(b.current.workspace,M,fetch,{etag:v.current,force:A});if(!C.current)return;if(v.current=M?null:_.etag,_.kind==="unchanged"){!b.current.draft.pending&&b.current.notice&&i("");return}let F=_.workspace,Q=S.current??(M!==null&&F.receipt?.request===M&&F.receipt.received?F.conversation?.sessionId??null:null);if(!IA(b.current.workspace,F,Q)){if(b.current.workspace.conversation?.sessionId===0&&N.current)return;b.current.stale=!0,m(!0),i("This conversation changed or ended. Reconnect to continue with your draft.");return}let ue=CA(b.current.draft,M,F.receipt),oe=jy(b.current.workspace),Z=b.current.workspace.conversation?.sessionId!==F.conversation?.sessionId;b.current.workspace=F,(ue!==b.current.draft||Z)&&T(ue),Z&&oe&&X0(Vy(),oe,Dc("")),a(F),i(ue.pending?"Delivery is not confirmed. Check again before sending another message.":"")}catch(_){if(!C.current)return;_ instanceof Pr&&(b.current.stale=!0,m(!0)),i(_ instanceof Error?_.message:"Updates are unavailable. Your work is still saved."),!H&&!b.current.stale&&F1()&&(w.current=setTimeout(()=>{w.current=null,$(!0,!0)},2e3))}finally{g.current=!1,x.current&&C.current&&!b.current.stale&&F1()&&(x.current=!1,$(!0))}},[e,U,q,T,k]);hn(U&&!c?"workspace":null,A=>{A==="change"||A==="reload"?$(!1):A==="lost"&&$(!0)}),(0,De.useEffect)(()=>{if(!q&&!z)return;let A=()=>{$(!0)};return window.addEventListener(Fi,A),()=>{window.removeEventListener(Fi,A)}},[$,q,z]),(0,De.useEffect)(()=>{if(C.current=!0,!U&&!q)return()=>{C.current=!1};let A=()=>{document.hidden?k():$(!0)},H=()=>{y(!1),$()},M=()=>{k(),y(!0)};return document.addEventListener("visibilitychange",A),window.addEventListener("online",H),window.addEventListener("offline",M),()=>{C.current=!1,k(),document.removeEventListener("visibilitychange",A),window.removeEventListener("online",H),window.removeEventListener("offline",M)}},[$,U,q,k]),(0,De.useEffect)(()=>{c&&k()},[c,k]);let L=async(A,H=null)=>{A.preventDefault();let M=b.current;if(N.current||M.stale||navigator.onLine===!1||M.draft.pending||!M.draft.text.trim())return"skipped";let _=SA(M.draft);if(!_.pending)return"skipped";N.current=!0,d(!0),T(_),i("");try{let F=await RA(M.workspace,_.pending,fetch,H);return M.workspace.conversation?.sessionId===0&&F.session!==void 0&&(S.current=F.session),C.current?F.refused?(T(NA(b.current.draft,_.pending.request)),i(F.message??"Message not sent. Your draft is saved."),"refused"):F.queued===!0?(T(LA(b.current.draft,_.pending.request)),i("Queued: it goes to the lead when it finishes."),$(),"queued"):(i("Checking delivery…"),$(),"accepted"):F.refused?"refused":F.queued===!0?"queued":"accepted"}catch(F){return C.current&&(F instanceof Pr&&(b.current.stale=!0,m(!0)),i(F instanceof Pr?F.message:"Delivery is not confirmed. Check again before sending another message."),$()),"unconfirmed"}finally{N.current=!1,C.current&&d(!1)}},I=()=>{let A=jy(b.current.workspace);A&&kA(Vy(),A,b.current.draft.text),window.location.reload()};return(0,De.useEffect)(()=>{let A=M=>{let _=M.target;if(!(_ instanceof HTMLFormElement)||_.dataset.workspaceComposer!==void 0||_.getAttribute("action")!=="/chat")return;let F=b.current;if(!F.workspace.conversation)return;if(F.stale||N.current||F.draft.pending||navigator.onLine===!1){M.preventDefault(),i("Wait for the current message before sending another.");return}if(_.getAttribute("aria-busy")==="true"){M.preventDefault();return}let Q=(ue,oe)=>{if(_.querySelector(`[name="${ue}"]`))return;let Z=document.createElement("input");Z.type="hidden",Z.name=ue,Z.value=oe,_.append(Z)};Q("request",F.workspace.conversation.requestId),Q("request-session",String(F.workspace.conversation.sessionId)),F.workspace.conversation.taskId&&Q("task",F.workspace.conversation.taskId),F.workspace.conversation.resultRunId!==null&&Q("result",String(F.workspace.conversation.resultRunId)),!M.defaultPrevented&&(N.current=!0,_.setAttribute("aria-busy","true"))},H=()=>{N.current=!1,document.querySelectorAll('form[action="/chat"][aria-busy="true"]:not([data-workspace-composer])').forEach(M=>M.removeAttribute("aria-busy")),$()};return document.addEventListener("submit",A),window.addEventListener("pageshow",H),()=>{document.removeEventListener("submit",A),window.removeEventListener("pageshow",H)}},[$]),{workspace:t,draft:o,notice:s,storageAvailable:l,sending:f,stale:c,offline:h,send:L,check:$,reconnect:I,steer:async A=>{let H=b.current;if(H.draft.text.trim()!==""||H.draft.pending)return"Send or clear the message you're writing first.";if(N.current||H.stale||navigator.onLine===!1)return"The conversation isn't connected. Try again in a moment.";T(Pg(H.draft,A));let M=b.current.draft.request,_=await L({preventDefault(){}});if(_==="queued")return null;if(_==="accepted")return await AA(()=>b.current.draft.pending?.request??null,M,()=>$())?null:"Delivery isn't confirmed. Check the chat for it before sending it again.";let F=b.current.draft;return F.pending===null&&F.text===A&&T(Pg(F,"")),_==="unconfirmed"?"Delivery isn't confirmed. Check the chat for it before sending it again.":"The lead didn't take it. The note above the message box says why."},edit:A=>T(Pg(b.current.draft,A))}}function XJ({at:e}){let t=DE(e);return t===""?null:(0,V.jsx)("time",{className:"so-work-age",dateTime:e,title:qi(e),children:t})}function q1({workspace:e,items:t}){return(0,V.jsx)("ul",{className:"so-work-list",children:t.map(a=>(0,V.jsx)("li",{"data-workspace-task":a.id,"data-work-status":a.state,children:(0,V.jsxs)("div",{className:"so-work-row",children:[(0,V.jsxs)("a",{className:"so-work-link",href:a.resultHref??a.href,"aria-current":e.focus?.id===a.id?"page":void 0,children:[(0,V.jsxs)("div",{className:"so-work-heading",children:[(0,V.jsx)(Us,{kind:cS(a.tone),className:"so-work-glyph"}),(0,V.jsx)("span",{className:"so-work-title",title:a.title,children:a.title}),(0,V.jsx)(XJ,{at:a.updatedAt})]}),(0,V.jsxs)("p",{className:"so-work-meta",children:[(0,V.jsx)("span",{className:"so-work-state","data-headline":a.label,children:a.label}),a.lead&&!a.detail?.includes(a.lead)&&(0,V.jsx)("span",{className:"so-work-project","data-crew-lead":!0,children:a.lead}),a.project&&(0,V.jsx)("span",{className:"so-work-project",children:e.projects.find(n=>n.path===a.project)?.name??a.project.split(/[\\/]/).filter(Boolean).pop()})]}),a.activity!==void 0&&(0,V.jsx)(Ev,{activity:a.activity,className:"so-work-activity text-caption"})]}),a.detail&&(0,V.jsx)("details",{className:"so-work-reason",children:(0,V.jsxs)("summary",{title:a.detail,children:[(0,V.jsx)("span",{children:a.detail}),(0,V.jsx)("svg",{"aria-hidden":"true",viewBox:"0 0 16 16",width:"12",height:"12",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:(0,V.jsx)("path",{d:"m4 6 4 4 4-4"})})]})},a.detail),a.action&&a.action.href!==(a.resultHref??a.href)&&(0,V.jsx)("a",{className:"so-work-action",href:a.action.href,children:a.action.label})]})},a.id))})}function YJ(e){let t=cS(e.tone);return t==="decide"||t==="failed"||t==="review"?"needs":t==="building"?"running":"waiting"}var ZJ=5,QJ=[{key:"needs",label:"Needs you",glyph:"decide"},{key:"running",label:"Running",glyph:"building"},{key:"waiting",label:"Waiting",glyph:"idle"}];function JJ({workspace:e}){let t=o=>o.tone==="done"||o.state==="cancelled",a=e.crew.filter(o=>!t(o)),n=e.crew.filter(t);return(0,V.jsxs)("section",{className:"so-crew","aria-labelledby":"crew-title","data-workspace-crew":!0,children:[(0,V.jsxs)("div",{className:"so-section-heading",children:[(0,V.jsx)("h2",{id:"crew-title",children:"Crew"}),(0,V.jsx)("a",{href:"/tasks",children:"All tasks"})]}),e.crew.length===0?(0,V.jsxs)("div",{className:"so-crew-empty",children:[(0,V.jsx)("p",{children:"No tasks yet."}),(0,V.jsx)("p",{children:"Work you start with the lead appears here."})]}):(0,V.jsxs)(V.Fragment,{children:[a.length===0&&(0,V.jsx)("p",{className:"so-crew-quiet",children:"Nothing is running or waiting on you."}),QJ.map(o=>{let r=a.filter(l=>YJ(l)===o.key);if(r.length===0)return null;let s=o.key==="running"?r.slice(0,ZJ):r,i=r.slice(s.length);return(0,V.jsxs)("div",{className:"so-crew-group","data-crew-group":o.key,children:[(0,V.jsxs)("h3",{className:"so-crew-group-title",children:[(0,V.jsx)(Us,{kind:o.glyph}),o.label,(0,V.jsx)("span",{children:r.length})]}),(0,V.jsx)(q1,{workspace:e,items:s}),i.length>0&&(0,V.jsx)(Qo,{summary:`${i.length} more running`,className:"so-crew-more",children:(0,V.jsx)(q1,{workspace:e,items:i})})]},o.key)}),n.length>0&&(0,V.jsx)(Qo,{summary:`Finished (${n.length}${e.crewTruncated?"+":""})`,className:"so-crew-finished",children:(0,V.jsx)(q1,{workspace:e,items:n})})]}),e.crewTruncated&&(0,V.jsx)("a",{className:"so-all-work",href:"/tasks",children:"View more tasks"})]})}var L5={"needs-you":"decide",failed:"failed",stuck:"unblock",paused:"idle",working:"building",waiting:"idle",done:"done",idle:"idle"};function eee(e){if(typeof e!="string")return null;let t;try{t=JSON.parse(e)}catch{return null}if(!Array.isArray(t))return null;let a=(o,r)=>typeof o=="string"&&o.length<=r,n=[];for(let o of t){if(o===null||typeof o!="object")return null;let{path:r,name:s,href:i,state:l,counts:u,tasks:f,more:d,others:c,asks:m}=o;if(!Array.isArray(m))return null;let h=[];for(let g of m){if(g===null||typeof g!="object")return null;let x=g;if(typeof x.key!="string"||!/^[A-Za-z0-9_-]{8,64}$/.test(x.key)||!(x.task===null||a(x.task,400))||!(x.run===null||typeof x.run=="number"&&Number.isInteger(x.run)&&x.run>0)||!a(x.at,64))return null;h.push({key:x.key,task:x.task,run:x.run,at:x.at})}if(c!==void 0&&c!==!0||!(r===null||a(r,4096))||!a(s,400)||!a(i,8192)||!i.startsWith("/")||!Bf.includes(l)||u===null||typeof u!="object"||!Array.isArray(f)||typeof d!="number"||!Number.isInteger(d)||d<0)return null;let y=Object.fromEntries(Bf.map(g=>[g,u[g]]));if(Object.values(y).some(g=>typeof g!="number"||!Number.isInteger(g)||g<0))return null;let b=[];for(let g of f){if(g===null||typeof g!="object")return null;let x=g;if(!a(x.id,400)||!a(x.title,2e3)||!a(x.href,8192)||!x.href.startsWith("/")||!Bf.includes(x.state)||!a(x.line,2e3))return null;b.push({id:x.id,title:x.title,href:x.href,state:x.state,line:x.line})}n.push({path:r,name:s,href:i,state:l,counts:y,tasks:b,more:d,asks:h,...c===!0?{others:!0}:{}})}return n}var tee=2e3,Zi={states:null,from:null,listeners:new Set};function $1(e){Zi.states=e;for(let t of[...Zi.listeners])t()}function A5(e){let t=e.sensitive||e.projectStates===void 0;!t&&Zi.from!==e.projectStates&&(Zi.from=e.projectStates,Zi.states=e.projectStates??null);let[,a]=(0,De.useState)(0),[n,o]=(0,De.useState)(!1);return(0,De.useEffect)(()=>{let r=()=>a(s=>s+1);return Zi.listeners.add(r),()=>{Zi.listeners.delete(r)}},[]),(0,De.useEffect)(()=>{if(!n)return;let r=window.setTimeout(()=>o(!1),tee);return()=>window.clearTimeout(r)},[n]),hn(t||n?null:"summary",(r,s)=>{if(r==="gone"){$1(null),o(!0);return}if(r==="lost"){$1(null);return}if(r!=="change")return;let i=eee(s.at);i!==null&&$1(i)},!0),t?null:Zi.states}function Pwe(e){return e?.reduce((t,a)=>t+a.counts["needs-you"],0)??0}function aee(e,t){let a=e.replace(/^\(\d+\+?\) /,"");return t>0?`(${t>99?"99+":t}) ${a}`:a}function nee({workspace:e}){let t=A5(e),a=bm(e).count;e5(e,t);let n=(0,De.useRef)(null);return(0,De.useEffect)(()=>(n.current=Z4(void 0,()=>{let o=new URL(window.location.href),r=o.pathname.startsWith("/t/")&&decodeURIComponent(o.pathname.slice(3).split("/")[0]??"")||null,s=o.pathname==="/agents"&&/^[1-9][0-9]{0,9}$/.test(o.searchParams.get("run")??"")?Number(o.searchParams.get("run")):null;return{visible:document.visibilityState==="visible",task:r,run:s}}),()=>{n.current?.close(),n.current=null}),[]),(0,De.useEffect)(()=>{t!==null&&n.current?.see(t)},[t]),(0,De.useEffect)(()=>{document.title=aee(document.title,a);let o=document.querySelector('link[rel="icon"][type="image/svg+xml"]');o!==null&&(o.href=a>0?"/icon-attention.svg":"/icon.svg")},[a,e.title]),null}function oee(e){return Bf.filter(t=>t!=="idle"&&e.counts[t]>0).map(t=>`${e.counts[t]} ${t==="needs-you"?e.counts[t]===1?"needs you":"need you":pg[t].toLowerCase()}`).join(" · ")}function Owe({states:e,current:t}){return(0,V.jsx)("nav",{"aria-label":"Projects now",className:"so-project-states","data-project-states":!0,children:e.map(a=>{let n=oee(a),o=a.path!==null&&a.path===t;return(0,V.jsxs)("div",{className:"so-project-state","data-project-state":a.state,"data-project-others":a.others?"":void 0,children:[(0,V.jsxs)("a",{href:a.href,"aria-current":o?"true":void 0,title:n===""?pg.idle:n,children:[(0,V.jsx)(Us,{kind:L5[a.state]}),(0,V.jsx)("span",{className:"so-project-state-name",children:a.name}),n!==""&&(0,V.jsx)("span",{className:"so-project-state-counts",children:n}),(0,V.jsx)("span",{className:"so-sr-only",children:pg[a.state]})]}),(o||a.path===null&&!a.others)&&a.tasks.length>0&&(0,V.jsxs)("ul",{className:"so-project-tasks",children:[a.tasks.map(r=>(0,V.jsx)("li",{"data-rail-task":r.state,children:(0,V.jsxs)("a",{href:r.href,title:r.title,children:[(0,V.jsx)(Us,{kind:L5[r.state]}),(0,V.jsx)("span",{className:"so-project-task-title",children:r.title}),(0,V.jsx)("span",{className:"so-project-task-line",children:r.line})]})},r.id)),a.more>0&&(0,V.jsx)("li",{children:(0,V.jsxs)("a",{className:"so-project-tasks-more",href:a.href,children:[a.more," more"]})})]})]},a.others?"(others)":a.path??"(none)")})})}function ree(e){let t=new URL(e.path,window.location.origin).searchParams,a=t.get("project")??t.get("repo")??e.crew.find(n=>n.id===e.focus?.id)?.project??e.openProject??null;return a===null?void 0:e.projects.find(n=>n.path===a)}var N5=[{id:"build",label:"Build",hint:"Changes come back for you to confirm"},{id:"plan",label:"Plan only",hint:"A plan only; nothing is filed"},{id:"answer",label:"Just answer",hint:"An answer only"}];function see(e){let{workspace:t,draft:a,notice:n,storageAvailable:o,sending:r,stale:s,offline:i}=e,l=t.conversation,u=(0,De.useRef)(null),f=(0,De.useId)(),[d,c]=(0,De.useState)("build"),m=l!==null&&!!l.taskId&&!t.team&&t.view?.kind==="task",h=l!==null&&l.pendingTurnId!==null,y=Sv(l,m&&(h||a.pending!==null&&!r),()=>{e.check()});if((0,De.useLayoutEffect)(()=>{let v=u.current;if(v){let w=matchMedia("(max-width: 760px)").matches;v.style.height=w?"0px":"auto",v.style.height=`${Math.min(180,Math.max(w?44:48,v.scrollHeight))}px`}},[a.text]),!m||l===null)return null;let b=r||s||i||a.pending!==null||!a.text.trim(),g=i?"Offline. Your draft stays in this tab.":r?"Sending…":n,x=N5.find(v=>v.id===d).hint;return{entries:l.messages.map(v=>({key:`message-${v.id}`,at:v.createdAt,node:(0,V.jsxs)("li",{"data-message-id":v.id,"data-thread-kind":"message",className:"so-thread-entry relative flex gap-3",children:[(0,V.jsx)("span",{"aria-hidden":"true",className:"relative z-[1] flex size-6 shrink-0 items-center justify-center rounded-full border border-border bg-card text-[10.5px] font-semibold text-muted-foreground",children:v.role==="operator"?"Y":(t.leadName??"Lead").slice(0,1).toUpperCase()}),(0,V.jsxs)("div",{className:"min-w-0 flex-1 pb-5 phone:pb-4",children:[(0,V.jsxs)("p",{className:"flex min-h-6 flex-wrap items-baseline gap-x-2 text-body leading-6",children:[(0,V.jsx)("span",{className:"font-medium",children:v.role==="operator"?"You":t.leadName??"Lead"}),(0,V.jsx)("time",{dateTime:v.createdAt,className:"ml-auto text-xs tabular-nums text-muted-foreground",children:qn(v.createdAt)})]}),(0,V.jsxs)(Mg,{className:v.role==="operator"?"so-thread-mine":"so-thread-theirs",children:[(0,V.jsx)(St,{html:v.html}),v.activity&&(0,V.jsx)(Qo,{summary:"Activity",children:(0,V.jsx)("p",{className:"so-activity-copy",children:v.activity})}),v.cards!==void 0&&v.cards.length>0?(0,V.jsx)(td,{cards:v.cards,csrf:t.csrf,onChanged:()=>{e.check()}}):v.cardsHtml&&(0,V.jsx)(St,{html:v.cardsHtml,className:"so-message-cards"})]})]})]},`message-${v.id}`)})),footer:(0,V.jsxs)("div",{className:"so-task-composer flex flex-col gap-2",children:[(h||y!==null)&&(0,V.jsx)(Lv,{live:y,leadName:t.leadName??"Lead"}),!h&&y===null&&l.failure&&(0,V.jsx)("p",{className:"so-live-failed",role:"alert","data-lead-failed":!0,children:l.failure}),g&&(0,V.jsxs)("div",{className:"so-connection",role:s?"alert":"status",children:[(0,V.jsx)("span",{children:g}),s?(0,V.jsx)(ie,{variant:"outline",size:"sm",onClick:e.reconnect,children:"Reconnect"}):!r&&!i&&(0,V.jsx)(ie,{variant:"ghost",size:"sm",onClick:()=>{e.check()},children:"Check again"})]}),(0,V.jsxs)(Ae,{onSubmit:v=>{e.send(v,d)},action:"/chat","data-workspace-composer":!0,"data-task-composer":!0,"aria-busy":r,className:"so-task-composer-box rounded-[28px] border border-transparent bg-composer px-4 pb-2.5 pt-3 transition-[border-color] duration-100 phone:px-3",children:[(0,V.jsx)("label",{htmlFor:"task-message",className:"sr-only",children:"Message the agent"}),(0,V.jsx)("textarea",{ref:u,id:"task-message",name:"message",rows:2,maxLength:l.maxChars,placeholder:"Message the agent: ask, or ask for a change",value:a.text,className:"block max-h-[180px] min-h-12 w-full resize-none px-0.5 pb-2 text-[16px] leading-relaxed outline-none placeholder:text-muted-foreground phone:min-h-11 phone:text-[17px]",onChange:v=>e.edit(v.target.value),onKeyDown:v=>{v.key==="Enter"&&!v.shiftKey&&!v.nativeEvent.isComposing&&(H1()||v.metaKey||v.ctrlKey)&&(v.preventDefault(),b||v.currentTarget.form?.requestSubmit())},"aria-describedby":"task-composer-hint"}),(0,V.jsxs)("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-2",children:[(0,V.jsx)("div",{role:"radiogroup","aria-label":"Mode",className:"so-mode-switch",children:N5.map(v=>(0,V.jsxs)("label",{className:"so-mode","data-mode":v.id,children:[(0,V.jsx)("input",{type:"radio",name:f,value:v.id,checked:d===v.id,onChange:()=>c(v.id)}),(0,V.jsx)("span",{children:v.label})]},v.id))}),(0,V.jsx)("span",{id:"task-composer-hint",className:"min-w-0 flex-1 truncate text-xs text-muted-foreground",children:o?a.text.length>l.maxChars-200?`${a.text.length} / ${l.maxChars}`:x:"Draft stays on this page only."}),(0,V.jsxs)(ie,{type:"submit",size:"sm",disabled:b,"aria-label":"Send message",className:pe("ml-auto"),children:[(0,V.jsx)(Hs,{name:"send"}),(0,V.jsx)("span",{children:"Send"})]})]})]})]})}}function I5({demo:e}){return e===void 0?null:(0,V.jsxs)(mn,{className:"so-demo-notice","data-demo-notice":!0,title:e.text,children:[(0,V.jsx)("span",{className:"so-demo-notice-full",children:e.text}),(0,V.jsx)("span",{className:"so-demo-notice-short",children:e.short})]})}function iee(){(0,De.useEffect)(()=>{let e=()=>{(window.scrollX!==0||window.scrollY!==0)&&window.scrollTo(0,0)},t=()=>{let n=decodeURIComponent(window.location.hash.slice(1)),o=n===""||n==="workspace-main"?null:document.getElementById(n);for(let r=o?.parentElement??null;r!==null;r=r.parentElement)r instanceof HTMLDetailsElement&&(r.open=!0);o?.scrollIntoView({block:"start"}),e()},a=requestAnimationFrame(t);return window.addEventListener("scroll",e,{passive:!0}),window.addEventListener("hashchange",t),()=>{cancelAnimationFrame(a),window.removeEventListener("scroll",e),window.removeEventListener("hashchange",t)}},[])}var lee=new Set(["tasks","task","agents","home","search","projects","flow"]),uee=/data-kit-page|class="k-ph"/;function cee(e){return e.team?!1:e.view!=null?lee.has(e.view.kind):e.conversation&&new URL(e.path,window.location.origin).pathname==="/chat"&&!e.focus&&!e.result?!0:!e.conversation&&uee.test(e.pageHtml??"")}function dee({initial:e}){let t=WJ(e);(0,De.useLayoutEffect)(()=>{J0(t.workspace.sensitive)},[t.workspace.sensitive]);let a=(0,De.useRef)(null),[n,o]=(0,De.useState)(e.team),r=n?.tasks?{...t.workspace,...uP(n.tasks,n.selected?.id)}:t.workspace,[s,i]=(0,De.useState)(r.result||r.focus?"work":"chat"),l=r.result?.runId??null;(0,De.useEffect)(()=>{l!==null&&Dg(l,r.csrf)},[l,r.csrf]);let u=r.focus!==null||r.result!==null,f=r.crew.find(F=>F.id===r.focus?.id),d=new URL(r.path,window.location.origin).pathname==="/chat",c=d?"Chat":r.navigation.find(F=>F.active)?.label??r.title.charAt(0).toUpperCase()+r.title.slice(1),m=!r.team&&r.view?.kind==="task"?r.view:null,h=!r.team&&r.conversation!==null&&r.view!=null&&m===null,[y,b]=(0,De.useState)("chat"),g=!r.team&&(!r.conversation||h||m!==null),x=see(t);(0,De.useEffect)(()=>{if(m===null)return;let F=()=>i("work");window.addEventListener("so:show-details",F);let Q=decodeURIComponent(window.location.hash.slice(1));return Q!==""&&document.getElementById(Q)?.closest("[data-task-details]")&&F(),()=>window.removeEventListener("so:show-details",F)},[m===null]);let v=new URL(r.path,window.location.origin).pathname,w=!r.team&&!r.conversation&&h5(v),k=cee(r),C=w&&!k,N=C||k||!u||g&&!h&&GJ.has(v),S=w?(r.crumbs??[]).filter(F=>F.href===null||F.href.startsWith("/")&&!F.href.startsWith("//")):[],[T,q]=(0,De.useState)(null),z=r.update!==void 0&&r.update.version!==T?r.update:null,U=r.demo,$=!r.team&&!(r.conversation&&!h&&m===null),[L,I]=(0,De.useState)(!1),R=d&&r.conversation!==null&&!h&&m===null&&!L?r.phone??null:null,A=A5(r),H=ree(r)?.path??null;(0,De.useEffect)(ok,[]),iee();let M=(0,De.useRef)(null),_=s==="work"&&u&&!h&&m===null&&!N;return(0,De.useEffect)(()=>{let F=M.current;if(!F)return;let Q=matchMedia("(max-width: 760px)"),ue=()=>F.toggleAttribute("inert",_&&Q.matches);return ue(),Q.addEventListener("change",ue),()=>{Q.removeEventListener("change",ue),F.removeAttribute("inert")}},[_]),(0,V.jsx)(so.Provider,{value:r.csrf,children:(0,V.jsxs)(Jo.Provider,{value:r.passwordless===!0,children:[(0,V.jsx)(dD,{}),(0,V.jsx)(nee,{workspace:r}),(0,V.jsxs)("div",{className:`so-workspace${N?" so-workspace--single":""}${k?" so-workspace--kit":""}${C?" so-workspace--settings":""}${h||m!==null&&!k?" so-workspace--docked":""}${m!==null&&!k?" so-workspace--details":""}`,"data-workspace-shell":!0,"data-workspace-phone-view":s,"data-workspace-has-result":r.result!==null,children:[(0,V.jsx)("a",{href:"#workspace-main",className:"so-skip-link",children:"Skip to content"}),(0,V.jsx)("aside",{className:"so-sidebar",children:(0,V.jsx)(r5,{workspace:r,states:A,current:H})}),(0,V.jsxs)("div",{ref:M,className:`so-main-column${d?" so-main-column--chat":""}`,children:[(0,V.jsx)(s5,{workspace:r,title:S.length>0?S[S.length-1].label:c,states:A,current:H,trailing:(0,V.jsxs)(V.Fragment,{children:[d&&u&&(0,V.jsx)(ie,{variant:"outline",size:"sm",className:"so-phone-work-button h-11 min-h-11",onClick:()=>i("work"),children:"Open work"}),h&&(0,V.jsxs)(ie,{variant:"outline",size:"sm",className:"so-phone-work-button h-11 min-h-11",onClick:()=>{b("chat"),i("work")},children:[(0,V.jsx)(Hs,{name:"chat"}),"Ask"]}),m!==null&&!k&&(0,V.jsx)(ie,{variant:"outline",size:"sm",className:"so-phone-work-button h-11 min-h-11","data-open-details":!0,onClick:()=>i("work"),children:"Task details"})]})}),!k&&(0,V.jsxs)("header",{className:"so-workspace-header",children:[S.length>0?(0,V.jsx)("nav",{className:"kit-crumbs so-header-title","aria-label":"Breadcrumb",children:(0,V.jsx)("ol",{children:S.map((F,Q)=>F.href===null?(0,V.jsx)("li",{"aria-current":"page",children:F.label},Q):(0,V.jsx)("li",{children:(0,V.jsx)("a",{href:F.href,children:F.label})},Q))})}):g||C?(0,V.jsx)("p",{className:"so-header-title",children:c}):(0,V.jsx)("h1",{children:d?r.leadName??"Lead":c}),r.focus&&d&&(0,V.jsx)("span",{className:"so-focus-label",title:r.focus.title,children:r.focus.title})]}),(r.notices.length>0||(r.signIn?.length??0)>0||z!==null||R!==null||r.reconnect!==void 0||U!==void 0&&!$)&&(0,V.jsxs)("div",{className:"so-workspace-notices",children:[!$&&(0,V.jsx)(I5,{demo:U}),r.reconnect!==void 0&&(0,V.jsx)(mn,{className:"so-update","data-reconnect":r.reconnect.kind,children:r.reconnect.kind==="password"?(0,V.jsxs)("p",{children:[(0,V.jsx)("span",{children:"Toolroll restarted"})," · ",(0,V.jsx)("a",{href:r.reconnect.href,children:"Reconnect"})]}):(0,V.jsx)("p",{children:(0,V.jsxs)("span",{children:["Toolroll restarted. Run ",(0,V.jsx)("code",{children:r.reconnect.command})," to reconnect."]})})}),r.signIn?.map(F=>(0,V.jsxs)(mn,{className:"so-sign-in","data-sign-in":F.provider,children:[(0,V.jsx)("p",{className:"so-sign-in-title",children:F.title}),(0,V.jsxs)("p",{className:"so-sign-in-detail",children:["Run ",(0,V.jsx)("code",{children:F.command})," on this computer, then resume.",F.detail===""?"":` ${F.detail}`]}),(0,V.jsx)(Ae,{action:F.resumeHref,children:(0,V.jsx)(ie,{className:"max-[761px]:h-11 max-[761px]:min-h-11",size:"sm",type:"submit",children:F.resumeLabel})})]},F.provider)),r.notices.map((F,Q)=>(0,V.jsx)(mn,{children:F},Q)),z!==null&&(0,V.jsxs)(mn,{className:"so-update","data-update":z.version,children:[(0,V.jsxs)("p",{children:[(0,V.jsx)("span",{children:m5(z)})," · ",(0,V.jsx)("a",{href:z.href,children:"What's new"})]}),(0,V.jsxs)(Ae,{action:z.dismissHref,onSubmit:F=>{F.preventDefault(),q(z.version),fetch(z.dismissHref,{method:"POST",headers:Wt({}),body:new URLSearchParams({csrf:r.csrf,version:z.version,quiet:"1"})}).catch(()=>{})},children:[(0,V.jsx)("input",{type:"hidden",name:"version",value:z.version}),(0,V.jsx)(ie,{className:"max-[761px]:size-11 max-[761px]:min-h-11",variant:"ghost",size:"icon",type:"submit","aria-label":`Dismiss the notice about ${z.version}`,children:(0,V.jsx)(Hs,{name:"close"})})]})]}),R!==null&&(0,V.jsxs)(mn,{className:"so-update so-phone-notice","data-phone-notice":!0,children:[(0,V.jsxs)("p",{children:[(0,V.jsx)("span",{children:"Use it from your phone too"})," · ",(0,V.jsx)("a",{href:"/settings/alerts#chat-apps",children:"Set up"})]}),(0,V.jsx)(Ae,{action:R.dismissHref,onSubmit:F=>{F.preventDefault(),I(!0),fetch(R.dismissHref,{method:"POST",headers:Wt({}),body:new URLSearchParams({csrf:r.csrf,quiet:"1"})}).catch(()=>{})},children:(0,V.jsx)(ie,{className:"max-[761px]:size-11 max-[761px]:min-h-11",variant:"ghost",size:"icon",type:"submit","aria-label":"Dismiss the phone notice",children:(0,V.jsx)(Hs,{name:"close"})})})]})]}),(0,V.jsx)("main",{id:"workspace-main",className:"so-main-content",tabIndex:-1,children:r.team?(0,V.jsx)(tP,{initial:r.team,user:r.user,csrf:r.csrf,onSnapshot:o}):r.conversation&&!h&&m===null?(0,V.jsx)(z1,{controller:t}):(0,V.jsxs)("div",{className:"so-page-content","data-workspace-page":!0,children:[(0,V.jsx)(I5,{demo:U}),d&&r.firstRun&&(0,V.jsx)(wv,{firstRun:r.firstRun}),r.view?(0,V.jsx)(p5,{view:r.view,csrf:r.csrf,taskChat:x,taskDetails:!1,workspace:r}):(0,V.jsx)(St,{html:e.pageHtml??"",immutable:!0})]})})]}),h&&(0,V.jsxs)("aside",{className:"so-supporting-panel so-ask-panel","data-workspace-detail":!0,"aria-label":"Ask",children:[(0,V.jsxs)("div",{className:"so-ask-header",children:[(0,V.jsxs)(ie,{variant:"ghost",size:"sm",className:"so-phone-back min-[761px]:hidden max-[761px]:h-11 max-[761px]:min-h-11",onClick:()=>i("chat"),children:[(0,V.jsx)(Hs,{name:"arrow"}),"Back"]}),(0,V.jsxs)("div",{role:"tablist","aria-label":"Panel",className:"so-ask-tabs",children:[(0,V.jsx)("button",{type:"button",role:"tab","aria-selected":y==="chat",onClick:()=>b("chat"),children:"Chat"}),(0,V.jsx)("button",{type:"button",role:"tab","aria-selected":y==="crew",onClick:()=>b("crew"),children:"Crew"})]})]}),(0,V.jsx)("div",{className:"so-ask-body",hidden:y!=="chat",children:(0,V.jsx)(z1,{controller:t,docked:r.view?.kind??"task"})}),y==="crew"&&(0,V.jsx)(JJ,{workspace:r})]}),m!==null&&!k&&(0,V.jsxs)("aside",{className:"so-supporting-panel so-details-panel","data-workspace-detail":!0,"aria-label":"Task details",children:[(0,V.jsxs)("div",{className:"so-details-header",children:[(0,V.jsxs)(ie,{variant:"ghost",size:"sm",className:"so-phone-back min-[761px]:hidden max-[761px]:h-11 max-[761px]:min-h-11",onClick:()=>i("chat"),children:[(0,V.jsx)(Hs,{name:"arrow"}),"Back"]}),(0,V.jsx)("h2",{children:"Task details"})]}),(0,V.jsx)("div",{"data-view":"task-details",className:"w-full",children:(0,V.jsx)(_v,{view:m})})]}),!N&&!h&&m===null&&(0,V.jsxs)("aside",{className:`so-supporting-panel${u?" so-supporting-panel--detail":""}`,"data-workspace-detail":!0,children:[(0,V.jsxs)("div",{className:"so-work-panel-header",children:[(0,V.jsxs)(ie,{variant:"ghost",size:"sm",className:"so-phone-back min-[761px]:hidden max-[761px]:h-11 max-[761px]:min-h-11",onClick:()=>i("chat"),children:[(0,V.jsx)(Hs,{name:"arrow"}),d?"Back to chat":"Back"]}),u&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)("h2",{children:r.result?"Result":"Task"}),r.result&&f&&(0,V.jsx)(kP,{label:f.label,tone:f.tone,className:"so-current-task-state","data-workspace-current-task-state":""}),r.result&&(0,V.jsxs)("span",{className:"so-work-run",children:["run #",r.result.runId]}),(0,V.jsx)("a",{href:n?.selected?"/chat?conversation="+encodeURIComponent(n.selected.id):"/chat",className:"so-close-work","aria-label":"Close work and return to the main chat",children:(0,V.jsx)(Hs,{name:"close"})})]})]}),u?(0,V.jsxs)("div",{className:"so-work-detail-content",children:[r.focus&&(r.result?(0,V.jsx)(Qo,{summary:"Task details",className:"so-result-task-details",children:(0,V.jsx)(St,{html:r.focus.html,className:"so-task-context"},r.focus.id)}):(0,V.jsx)(St,{html:r.focus.html,className:"so-task-context"},r.focus.id)),r.result&&(0,V.jsxs)("div",{ref:a,className:"so-result-host",children:[(0,V.jsx)(mA,{"data-workspace-result":r.result.runId,children:(0,V.jsx)(hA,{children:(0,V.jsx)(St,{html:r.result.html,immutable:!0},r.result.runId)})}),r.conversation&&(0,V.jsx)(fP,{host:a,run:r.result.runId,maxChars:r.conversation.maxChars,steer:t.steer},r.result.runId)]})]}):null]}),(0,V.jsx)(i5,{workspace:r}),(0,V.jsx)(d5,{workspace:r})]})]})})}var E5=e=>{let t=e.viewTransition;for(let a of[t?.finished,t?.ready,t?.updateCallbackDone])a?.catch(()=>{})};window.addEventListener("pageswap",E5);window.addEventListener("pagereveal",E5);Hp();var U1=document.getElementById("standing-orders-workspace"),T5=document.getElementById("standing-orders-workspace-data");if(U1&&T5)try{let e=JSON.parse(T5.textContent??"null");if(!Y0(e))throw new Error("Workspace data is incomplete");J0(e.sensitive),(0,R5.createRoot)(U1).render((0,V.jsx)(dee,{initial:e}))}catch{U1.setAttribute("data-workspace-unavailable","true")}export{ZJ as CREW_RUNNING_SHOWN,q1 as CrewRows,St as GuardedHtml,Owe as ProjectStates,w5 as REPLACED_THREAD_DIVIDER,tee as SUMMARY_REJOIN_MS,dee as WorkspaceApp,YJ as crewGroupOf,ree as currentProjectOf,cee as isKitPage,Pwe as needsYouTotal,oee as projectCountWords,eee as readProjectStates,PE as regionIsEditing,k5 as replyTook,aee as titleWithCount,A5 as useProjectStates,WJ as useWorkspace};
79
+ `)})}),s&&(0,J.jsx)("span",{"aria-hidden":"true",className:"pointer-events-none absolute inset-x-px top-px h-6 rounded-t-md bg-[linear-gradient(to_bottom,var(--so-code-bg)_30%,transparent)]"}),!o&&(0,J.jsx)("button",{type:"button",onClick:()=>r(!0),className:"absolute bottom-2 right-2 rounded-sm border border-border bg-card px-2 py-0.5 text-[11.5px] text-foreground shadow-pill phone:min-h-11",children:"Jump to latest"})]})}var _4=e=>pe("relative pl-5",!e&&"pb-2","before:absolute before:left-0 before:top-0 before:h-[22px] before:w-3.5 before:rounded-bl-sm before:border-b before:border-l before:border-border before:content-['']",!e&&"after:absolute after:bottom-0 after:left-0 after:top-[22px] after:border-l after:border-border after:content-['']");function I1({child:e,all:t,now:a,last:n}){let o=e.endedAt===null?"Working":e.ok===!1?"Ended with an error":e.ok===!0?"Done":"Ended",r=e.endedAt===null?"working":e.ok===!1?"failed":e.ok===!0?"done":"stopped",s=t.filter(i=>i.via===e.s);return(0,J.jsxs)("li",{className:_4(n),"data-live-child":e.s,children:[(0,J.jsxs)("article",{className:"flex flex-col gap-2 rounded-card border border-border bg-card p-3",children:[(0,J.jsxs)("header",{className:"flex items-start gap-2",children:[(0,J.jsx)("h3",{className:"line-clamp-2 min-w-0 flex-1 text-[13px] font-semibold leading-[1.35]",title:e.desc,children:e.desc}),(0,J.jsx)(Ld,{tone:Cd[r]??"info",children:o})]}),(0,J.jsxs)("p",{className:"flex gap-2 text-[12px] text-muted-foreground",children:[(0,J.jsx)("span",{className:"min-w-0 flex-1 truncate",children:e.endedAt===null?N1(e)??"":""}),(0,J.jsx)("span",{className:"shrink-0 tabular-nums",children:Vn(new Date(e.startedAt).toISOString(),e.endedAt??a)})]}),(0,J.jsx)(Hy,{lines:e.lines,short:!0})]}),s.length>0&&(0,J.jsx)("ul",{"aria-label":`Subagents of ${e.desc}`,className:"ml-4 mt-2 flex flex-col",children:s.map((i,l)=>(0,J.jsx)(I1,{child:i,all:t,now:a,last:l===s.length-1},i.s))})]})}function P4({tile:e,stream:t,streamed:a,showLive:n,tall:o=!1,lost:r=!1}){let s="text-[12px] text-muted-foreground",i="text-[11.5px] text-muted-foreground",l=!e.local||t.mainState==="off"?(0,J.jsx)("p",{className:s,children:"Output is on another computer."}):a?t.mainState==="unavailable"?(0,J.jsx)("p",{className:s,children:"Output unavailable."}):(0,J.jsxs)(J.Fragment,{children:[t.earlier&&(0,J.jsx)("p",{className:i,children:"Earlier output isn't shown."}),t.mainState==="error"&&(0,J.jsx)("p",{className:i,children:"Couldn't read the latest output. Retrying."}),t.mainState==="loading"?(0,J.jsx)("p",{className:s,children:"Loading output…"}):(0,J.jsx)(Hy,{lines:t.main.lines,short:!1,tall:o})]}):(0,J.jsxs)("p",{className:pe(s,"flex items-center gap-2"),children:["Not shown live.",(0,J.jsx)("button",{type:"button",onClick:n,className:"rounded-sm border border-border bg-card px-2 py-0.5 text-[11.5px] text-foreground phone:min-h-11",children:"Show live"})]});return(0,J.jsxs)(J.Fragment,{children:[r&&(0,J.jsx)("p",{className:i,children:"Reconnecting… these lines may not be the latest."}),l,t.subState==="unavailable"&&(0,J.jsx)("p",{className:i,children:"Subagents' output unavailable."}),t.subState==="error"&&(0,J.jsx)("p",{className:i,children:"Couldn't read the subagents' output. Retrying."}),t.subRestarted&&(0,J.jsx)("p",{className:i,children:"Subagents' output restarted."}),t.over&&(0,J.jsx)("p",{className:i,children:"More subagents started than are shown."})]})}function L1({tile:e,stream:t,streamed:a,now:n,repairs:o,streams:r,streamedIds:s,showLive:i,openRun:l,nested:u}){let f=e.state==="needs-you",d=e.why==="quiet"&&e.quietSince!==null?`Quiet for ${Vn(e.quietSince,n)}`:e.why==="question"?"Asked a question":e.endedAt===null?N1(t.main)??"":"",c=[...t.children.values()].filter(b=>!b.expired).sort((b,g)=>b.s-g.s),m=c.filter(b=>b.via===void 0||!c.some(g=>g.s===b.via)),h=[e.project?.split("/").pop(),e.role,e.agent,e.model].filter(Boolean).join(" · "),y=f?"needs":e.state;return(0,J.jsxs)("li",{className:pe("flex min-w-0 flex-col gap-2",u!==void 0&&_4(u.last)),"data-live-tile":e.runId,"data-live-state":e.state,children:[(0,J.jsxs)("article",{className:pe("flex min-w-0 flex-col gap-2.5 rounded-card border bg-card p-3.5",f?$Q:"border-border"),children:[(0,J.jsxs)("header",{className:"flex flex-col gap-1",children:[(0,J.jsxs)("div",{className:"flex items-start gap-2",children:[(0,J.jsx)("h2",{className:"line-clamp-2 min-w-0 flex-1 text-[15px] font-semibold leading-[1.3]",title:e.title,children:(0,J.jsx)("button",{type:"button","data-live-open":e.runId,onClick:()=>l(e.runId),className:"text-left hover:underline hover:underline-offset-4 phone:min-h-11",children:e.title})}),(0,J.jsx)(Ld,{tone:y==="needs"?"needs":Cd[y]??"info",children:ym[e.state]})]}),(0,J.jsx)("p",{className:"truncate font-mono text-[11px] text-muted-foreground",title:h,children:h})]}),(0,J.jsxs)("p",{className:"flex gap-2 text-[13px]",children:[(0,J.jsx)("span",{className:"min-w-0 flex-1 truncate",children:d}),(0,J.jsx)("span",{className:"shrink-0 text-[12px] tabular-nums text-muted-foreground",children:Vn(e.startedAt,e.endedAt===null?n:Date.parse(e.endedAt))})]}),(0,J.jsx)(P4,{tile:e,stream:t,streamed:a,showLive:()=>i(e.runId)})]}),o.length>0&&(0,J.jsx)("ul",{"aria-label":`Repairs of ${e.title}`,className:"ml-4 flex flex-col gap-2",children:o.map(b=>(0,J.jsx)(L1,{tile:b,stream:r.get(b.runId)??vm,streamed:s.has(b.runId),now:n,repairs:[],streams:r,streamedIds:s,showLive:i,openRun:l},b.runId))}),m.length>0&&(0,J.jsx)("ul",{"aria-label":`Subagents of ${e.title}`,className:"ml-4 flex flex-col",children:m.map((b,g)=>(0,J.jsx)(I1,{child:b,all:c,now:n,last:g===m.length-1},b.s))})]})}function UQ({runId:e,tile:t,stream:a,streamed:n,now:o,lost:r,onClose:s,showLive:i}){let l=(0,je.useRef)(null),u=[...a.children.values()].sort((d,c)=>d.s-c.s),f=u.filter(d=>d.via===void 0||!u.some(c=>c.s===d.via));return(0,J.jsx)(P0,{open:!0,onOpenChange:d=>{d||s()},children:(0,J.jsxs)(O0,{container:typeof document>"u"?void 0:document.querySelector("[data-view]")??void 0,children:[(0,J.jsx)(B0,{className:"ui-dialog-overlay"}),(0,J.jsxs)(z0,{"data-live-full":!0,"aria-describedby":void 0,onOpenAutoFocus:d=>{d.preventDefault(),l.current?.focus()},onCloseAutoFocus:d=>{d.preventDefault(),(document.querySelector(`[data-live-open="${e}"]`)??document.querySelector("[data-live-grid]"))?.focus()},className:"ui-dialog-content flex !w-[min(1100px,calc(100vw-48px))] flex-col gap-3 !p-5 phone:!bottom-0 phone:!left-0 phone:!top-auto phone:!max-h-[calc(100dvh-2rem)] phone:!w-full phone:!rounded-b-none phone:!p-4 phone:!pb-[max(1rem,env(safe-area-inset-bottom))] phone:![transform:none]",children:[(0,J.jsxs)("header",{className:"flex items-start gap-3",children:[(0,J.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,J.jsx)(H0,{className:"text-[18px] font-semibold leading-[1.3]","data-live-full-title":!0,children:t?.title??"This agent isn't on the grid anymore"}),t!==null&&(0,J.jsx)("p",{className:"truncate font-mono text-[11px] text-muted-foreground",children:[t.project?.split("/").pop(),t.role,t.agent,t.model].filter(Boolean).join(" · ")})]}),t!==null&&(0,J.jsx)(Ld,{tone:t.state==="needs-you"?"needs":Cd[t.state]??"info",children:ym[t.state]}),(0,J.jsx)(F0,{ref:l,className:"shrink-0 rounded-sm border border-border px-2.5 py-1 text-[12.5px] phone:min-h-11",children:"Close"})]}),t!==null&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)("p",{className:"flex items-center gap-3 text-[13px]",children:[(0,J.jsx)("span",{className:"min-w-0 flex-1 truncate",children:t.why==="quiet"&&t.quietSince!==null?`Quiet for ${Vn(t.quietSince,o)}`:t.why==="question"?"Asked a question":t.endedAt===null?N1(a.main)??"":""}),(0,J.jsx)("span",{className:"shrink-0 text-[12px] tabular-nums text-muted-foreground",children:Vn(t.startedAt,t.endedAt===null?o:Date.parse(t.endedAt))}),t.taskHref!==null&&(0,J.jsx)("a",{href:t.taskHref,className:"shrink-0 text-[12.5px] underline decoration-border underline-offset-4 hover:decoration-current phone:inline-flex phone:min-h-11 phone:items-center",children:"Open task"})]}),(0,J.jsx)(P4,{tile:t,stream:a,streamed:n,showLive:i,tall:!0,lost:r}),f.length>0&&(0,J.jsxs)("section",{"aria-label":"Subagents",className:"flex flex-col gap-2",children:[(0,J.jsxs)("h3",{className:"text-[13px] font-semibold",children:["Subagents ",(0,J.jsx)("span",{className:"font-normal tabular-nums text-muted-foreground",children:u.length})]}),(0,J.jsx)("ul",{className:"flex flex-col",children:f.map((d,c)=>(0,J.jsx)(I1,{child:d,all:u,now:o,last:c===f.length-1},d.s))})]})]})]})]})})}var O4=e=>["lead chat",e.project?.split("/").pop(),e.stepAt.length>1?`step ${e.stepAt.length}`:null].filter(Boolean).join(" · "),VQ={lead:"lead chat",project:"project chat",task:"task chat"};function jQ({thread:e,runs:t,label:a,render:n}){return t.length===0?null:(0,J.jsx)("ul",{"aria-label":a,className:"ml-4 flex flex-col","data-live-filed":e,children:t.map((o,r)=>n(o,r===t.length-1))})}function KQ({lead:e,now:t,openLead:a}){return(0,J.jsxs)("article",{className:"flex min-w-0 flex-col gap-2.5 rounded-card border border-border bg-card p-3.5",children:[(0,J.jsxs)("header",{className:"flex flex-col gap-1",children:[(0,J.jsxs)("div",{className:"flex items-start gap-2",children:[(0,J.jsx)("h2",{className:"line-clamp-2 min-w-0 flex-1 text-[15px] font-semibold leading-[1.3]",title:e.title,children:(0,J.jsx)("button",{type:"button","data-live-open-lead":e.thread,onClick:()=>a(e.thread),className:"text-left hover:underline hover:underline-offset-4 phone:min-h-11",children:e.title})}),(0,J.jsx)(Ld,{tone:Cd[e.state]??"info",children:ym[e.state]})]}),(0,J.jsx)("p",{className:"truncate font-mono text-[11px] text-muted-foreground",children:O4(e)})]}),(0,J.jsxs)("p",{className:"flex gap-2 text-[13px]",children:[(0,J.jsx)("span",{className:"min-w-0 flex-1 truncate",children:e.doing??""}),(0,J.jsx)("span",{className:"shrink-0 text-[12px] tabular-nums text-muted-foreground",children:Vn(e.startedAt,e.endedAt===null?t:Date.parse(e.endedAt))})]}),e.earlier&&(0,J.jsx)("p",{className:"text-[11.5px] text-muted-foreground",children:"Earlier lines aren't shown."}),(0,J.jsx)(Hy,{lines:e.lines,short:!1})]})}function M4({thread:e,lead:t,runs:a,now:n,openLead:o,render:r}){let s=[...new Set(a.map(l=>l.project?.split("/").pop()).filter(Boolean))].join(", "),i=a.length===0?"":`Filed by ${VQ[a[0].filedBy.chat]}${s===""?"":` · ${s}`}`;return(0,J.jsxs)("li",{className:"flex min-w-0 flex-col gap-2",...t!==null?{"data-live-lead":e,"data-live-state":t.state}:{"data-live-filed-group":e},children:[t!==null?(0,J.jsx)(KQ,{lead:t,now:n,openLead:o}):(0,J.jsx)("p",{className:"truncate text-[12px] text-muted-foreground",title:i,children:i}),(0,J.jsx)(jQ,{thread:e,runs:a,label:t!==null?`Filed by ${t.title}`:i,render:r})]})}function GQ({thread:e,lead:t,now:a,lost:n,onClose:o,filed:r}){let s=(0,je.useRef)(null),i="shrink-0 text-[12.5px] underline decoration-border underline-offset-4 hover:decoration-current phone:inline-flex phone:min-h-11 phone:items-center";return(0,J.jsx)(P0,{open:!0,onOpenChange:l=>{l||o()},children:(0,J.jsxs)(O0,{container:typeof document>"u"?void 0:document.querySelector("[data-view]")??void 0,children:[(0,J.jsx)(B0,{className:"ui-dialog-overlay"}),(0,J.jsxs)(z0,{"data-live-full":!0,"aria-describedby":void 0,onOpenAutoFocus:l=>{l.preventDefault(),s.current?.focus()},onCloseAutoFocus:l=>{l.preventDefault(),(document.querySelector(`[data-live-open-lead="${e}"]`)??document.querySelector("[data-live-grid]"))?.focus()},className:"ui-dialog-content flex !w-[min(1100px,calc(100vw-48px))] flex-col gap-3 !p-5 phone:!bottom-0 phone:!left-0 phone:!top-auto phone:!max-h-[calc(100dvh-2rem)] phone:!w-full phone:!rounded-b-none phone:!p-4 phone:!pb-[max(1rem,env(safe-area-inset-bottom))] phone:![transform:none]",children:[(0,J.jsxs)("header",{className:"flex items-start gap-3",children:[(0,J.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,J.jsx)(H0,{className:"text-[18px] font-semibold leading-[1.3]","data-live-full-title":!0,children:t?.title??"This reply isn't on the grid anymore"}),t!==null&&(0,J.jsx)("p",{className:"truncate font-mono text-[11px] text-muted-foreground",children:O4(t)})]}),t!==null&&(0,J.jsx)(Ld,{tone:Cd[t.state]??"info",children:ym[t.state]}),(0,J.jsx)(F0,{ref:s,className:"shrink-0 rounded-sm border border-border px-2.5 py-1 text-[12.5px] phone:min-h-11",children:"Close"})]}),t!==null&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)("p",{className:"flex items-center gap-3 text-[13px]",children:[(0,J.jsx)("span",{className:"min-w-0 flex-1 truncate",children:t.doing??""}),(0,J.jsx)("span",{className:"shrink-0 text-[12px] tabular-nums text-muted-foreground",children:Vn(t.startedAt,t.endedAt===null?a:Date.parse(t.endedAt))}),(0,J.jsx)("a",{href:t.chatHref,className:i,children:"Open chat"}),t.taskHref!==null&&(0,J.jsx)("a",{href:t.taskHref,className:i,children:"Open task"})]}),t.earlier&&(0,J.jsx)("p",{className:"text-[11.5px] text-muted-foreground",children:"Earlier lines aren't shown."}),(0,J.jsx)(Hy,{lines:t.lines,short:!1,tall:!0})]}),n&&(t!==null||r.length>0)&&(0,J.jsx)("p",{className:"text-[11.5px] text-muted-foreground",children:"Reconnecting… these lines may not be the latest."}),r.length>0&&(0,J.jsxs)("section",{"aria-label":"Tasks it filed",className:"flex flex-col gap-2","data-live-full-filed":!0,children:[(0,J.jsxs)("h3",{className:"text-[13px] font-semibold",children:["Tasks it filed ",(0,J.jsx)("span",{className:"font-normal tabular-nums text-muted-foreground",children:r.length})]}),(0,J.jsx)("ul",{className:"flex flex-col gap-1.5",children:r.map(l=>(0,J.jsxs)("li",{className:"flex items-center gap-2 text-[13px]",children:[(0,J.jsx)("span",{className:"min-w-0 flex-1 truncate",title:l.title,children:l.title}),(0,J.jsx)(Ld,{tone:l.state==="needs-you"?"needs":Cd[l.state]??"info",children:ym[l.state]}),l.taskHref!==null&&(0,J.jsx)("a",{href:l.taskHref,className:i,children:"Open task"})]},l.runId))})]})]})]})})}function WQ({working:e,needsYou:t,shownLive:a,local:n}){let o=r=>(0,J.jsx)("span",{className:"font-semibold tabular-nums text-foreground",children:r});return(0,J.jsxs)("p",{className:"text-[13px] text-muted-foreground","data-live-headline":!0,children:[o(e)," ",e===1?"agent":"agents"," working",t>0&&(0,J.jsxs)(J.Fragment,{children:[" · ",o(t)," ",t===1?"needs":"need"," you"]}),n>a&&(0,J.jsxs)(J.Fragment,{children:[" · ",o(a)," of ",o(n)," shown live"]})]})}function B4(){let[e,t]=(0,je.useState)([]),[a,n]=(0,je.useState)([]),[o,r]=(0,je.useState)([]),[s,i]=(0,je.useState)(new Map),[l,u]=(0,je.useState)("loading"),[f,d]=(0,je.useState)(!1),[c,m]=(0,je.useState)(0),h=(0,je.useRef)(!1),y=(0,je.useRef)(!1),[b,g]=(0,je.useState)(!1),x=Wr(1e3),v=(0,je.useRef)(null),w=()=>{let W=Number(new URLSearchParams(location.search).get("run"));return Number.isSafeInteger(W)&&W>0?W:null},[k,C]=(0,je.useState)(w),N=(0,je.useRef)(k);N.current=k;let S=(0,je.useRef)(new Set),T=(0,je.useRef)(null),q=(0,je.useRef)(0);(0,je.useEffect)(()=>{let W=qQ((Ie,ze)=>{let[lt,rt]=Ie.split(":");i(Ze=>new Map(Ze).set(Number(lt),FQ(Ze.get(Number(lt))??vm,rt,ze,Number(lt)===N.current?DQ:zy)))});return v.current=W,()=>{W.dispose(),v.current=null}},[]);let[z,U]=(0,je.useState)([]),$=[...e,...o.filter(W=>!e.some(Ie=>Ie.runId===W.runId))].filter(W=>W.local),L=new Set([...new Set([...k!==null&&$.some(W=>W.runId===k)?[k]:[],...z.filter(W=>$.some(Ie=>Ie.runId===W)),...$.map(W=>W.runId)])].slice(0,T4)),I=[...L].sort((W,Ie)=>W-Ie).join(",");(0,je.useEffect)(()=>{let W=I===""?[]:I.split(",").flatMap(Ie=>[`${Ie}:main`,`${Ie}:sub`]);v.current?.keep(new Set(W)),v.current?.want(W)},[I]),S.current=L,(0,je.useEffect)(()=>{let W=()=>C(w());return window.addEventListener("popstate",W),()=>window.removeEventListener("popstate",W)},[]);let R=W=>{N.current!==W&&(N.current=W,history.pushState({liveRun:W},"",`/agents?view=live&run=${W}`),C(W))},A=()=>{let W=N.current;W!==null&&(N.current=null,history.state?.liveRun===W?history.back():history.replaceState(null,"","/agents?view=live"),C(null))},H=(0,je.useRef)(k);(0,je.useEffect)(()=>{let W=H.current;H.current=k,!(W===null||W===k)&&i(Ie=>{let ze=Ie.get(W);if(ze===void 0)return Ie;let lt=new Map([...ze.children].map(([rt,Ze])=>[rt,{...Ze,lines:Ze.lines.slice(-zy)}]));return new Map(Ie).set(W,{...ze,main:{...ze.main,lines:ze.main.lines.slice(-zy)},children:lt})})},[k]);let M=()=>{if(w()!==null)return null;let W=Number(new URLSearchParams(location.search).get("lead"));return Number.isSafeInteger(W)&&W>0?W:null},[_,F]=(0,je.useState)(M),Q=(0,je.useRef)(_);Q.current=_,(0,je.useEffect)(()=>{let W=()=>F(M());return window.addEventListener("popstate",W),()=>window.removeEventListener("popstate",W)},[]);let ue=W=>{Q.current!==W&&(Q.current=W,history.pushState({liveLead:W},"",`/agents?view=live&lead=${W}`),F(W))},oe=()=>{let W=Q.current;W!==null&&(Q.current=null,history.state?.liveLead===W?history.back():history.replaceState(null,"","/agents?view=live"),F(null))},Z=W=>U(Ie=>[W,...Ie.filter(ze=>ze!==W)].slice(0,T4)),ne=(0,je.useCallback)(()=>{let W=++q.current;fetch("/agents/live",{credentials:"same-origin"}).then(Ie=>Ie.ok?Ie.json():null).then(Ie=>{if(W===q.current){if(Ie===null){u(ze=>ze==="ready"?"ready":"error");return}t(Ie.tiles),n(Ie.leads??[]),u("ready"),v.current?.want([...S.current].flatMap(ze=>[`${ze}:main`,`${ze}:sub`]))}}).catch(()=>{W===q.current&&u(Ie=>Ie==="ready"?"ready":"error")})},[]);(0,je.useEffect)(()=>{ne()},[ne]),hn("agents-live",W=>{if(W==="lost"||W==="retrying"){d(!0);return}(W==="change"||W==="reload")&&(d(!1),ne())}),(0,je.useEffect)(()=>{fetch("/term/state",{credentials:"same-origin"}).then(W=>W.ok?W.json():null).then(W=>m((W?.sessions??[]).filter(Ie=>Ie.endedAt===null).length)).catch(()=>{})},[]);let le=(0,je.useCallback)(W=>r(Ie=>[...Ie.flatMap(lt=>{let rt=e.find(Ze=>Ze.runId===lt.runId);return rt!==void 0?[rt]:W?[lt]:[]}),...e.filter(lt=>!Ie.some(rt=>rt.runId===lt.runId)).sort((lt,rt)=>Date.parse(lt.startedAt)-Date.parse(rt.startedAt))]),[e]);(0,je.useEffect)(()=>{le(h.current||y.current)},[le]),(0,je.useEffect)(()=>{y.current&&T.current!==null&&!T.current.contains(document.activeElement)&&K(null,!1)}),(0,je.useEffect)(()=>{b||i(W=>{let Ie=!1,ze=new Map(W);for(let[lt,rt]of W){let Ze=[...rt.children.values()].filter($t=>!$t.expired&&$t.endedAt!==null&&x-$t.endedAt>=OQ);if(Ze.length===0)continue;let Wa=new Map(rt.children);for(let $t of Ze)Wa.set($t.s,{...$t,expired:!0});ze.set(lt,{...rt,children:Wa}),Ie=!0}return Ie?ze:W})},[x,b,s]);let K=(W,Ie)=>{W!==null&&(h.current=W),Ie!==null&&(y.current=Ie);let ze=h.current||y.current;g(ze),ze||le(!1)},B=new Set(o.map(W=>W.runId)),X=W=>o.filter(Ie=>Ie.role==="repair"&&Ie.parentRun===W),de=o.filter(W=>!(W.role==="repair"&&W.parentRun!==null&&B.has(W.parentRun))),fe=W=>de.filter(Ie=>Ie.filedBy?.thread===W),Se=(W,Ie)=>(0,J.jsx)(L1,{tile:W,stream:s.get(W.runId)??vm,streamed:L.has(W.runId),now:x,repairs:X(W.runId),streams:s,streamedIds:L,showLive:Z,openRun:R,nested:{last:Ie}},W.runId),Ee=o.filter(W=>W.endedAt===null).length+a.filter(W=>W.endedAt===null).length,Oe=o.filter(W=>W.state==="needs-you").length,Ue=e.length!==o.length||e.some(W=>!B.has(W.runId));return(0,J.jsxs)("section",{className:"flex w-full flex-col gap-4 outline-none","data-live-grid":!0,"aria-label":"Live",tabIndex:-1,children:[(0,J.jsxs)("div",{className:"flex flex-wrap items-baseline gap-x-3 gap-y-1 phone:sticky phone:top-0 phone:z-10 phone:bg-card phone:py-2",children:[(0,J.jsx)(WQ,{working:Ee,needsYou:Oe,shownLive:L.size,local:e.filter(W=>W.local).length}),Ue&&b&&(0,J.jsx)("p",{className:"text-[12px] text-muted-foreground",children:"Changes wait while you look."}),f&&(0,J.jsx)("p",{className:"text-[12px] text-muted-foreground",role:"status",children:"Reconnecting…"})]}),l==="error"?(0,J.jsx)("p",{className:"text-[13px] text-muted-foreground",role:"status",children:"Couldn't load the agents. Retrying."}):l==="ready"&&de.length===0&&a.length===0?(0,J.jsx)("p",{className:"text-[13px] text-muted-foreground",children:"No agents running."}):(0,J.jsxs)("ul",{ref:T,className:"grid items-start gap-4 [grid-template-columns:repeat(auto-fill,minmax(min(100%,340px),1fr))]",onPointerEnter:()=>K(!0,null),onPointerLeave:()=>K(!1,null),onFocus:()=>K(null,!0),onBlur:W=>{W.currentTarget.contains(W.relatedTarget)||K(null,!1)},children:[a.filter(W=>fe(W.thread).length===0).map(W=>(0,J.jsx)(M4,{thread:W.thread,lead:W,runs:[],now:x,openLead:ue,render:Se},`lead-${W.thread}`)),de.map(W=>{let Ie=W.filedBy?.thread;if(Ie===void 0)return(0,J.jsx)(L1,{tile:W,stream:s.get(W.runId)??vm,streamed:L.has(W.runId),now:x,repairs:X(W.runId),streams:s,streamedIds:L,showLive:Z,openRun:R},W.runId);let ze=fe(Ie),lt=a.find(rt=>rt.thread===Ie);return ze[0]!==W?null:(0,J.jsx)(M4,{thread:Ie,lead:lt??null,runs:ze,now:x,openLead:ue,render:Se},`group-${Ie}`)})]}),k!==null&&(0,J.jsx)(UQ,{runId:k,tile:[...e,...o].find(W=>W.runId===k)??null,stream:s.get(k)??vm,streamed:L.has(k),now:x,lost:f,onClose:A,showLive:()=>Z(k)},k),_!==null&&(0,J.jsx)(GQ,{thread:_,lead:a.find(W=>W.thread===_)??null,now:x,lost:f,onClose:oe,filed:o.filter(W=>W.filedBy?.thread===_)},`lead-${_}`),c>0&&(0,J.jsx)("p",{className:"border-t border-border pt-3 text-[12px] text-muted-foreground",children:(0,J.jsxs)("a",{href:"/term",className:"inline-block underline decoration-border underline-offset-4 hover:text-foreground hover:decoration-current phone:min-h-11 phone:py-3",children:[(0,J.jsx)("span",{className:"tabular-nums",children:c})," ",c===1?"terminal":"terminals"," you're driving"]})})]})}var D=O(G(),1);function Vn(e,t){let a=Math.max(0,Math.floor((t-Date.parse(e))/1e3));if(!Number.isFinite(a))return"";if(a<60)return`${a} s`;let n=Math.floor(a/60);if(n<60)return`${n} min`;let o=Math.floor(n/60);return n%60===0?`${o} h`:`${o} h ${n%60} min`}function R1(e,t){if(e.endedAt===null)return`Running ${Vn(e.startedAt,t)}`;let a=t-Date.parse(e.endedAt);return`Ran ${Vn(e.startedAt,Date.parse(e.endedAt))} · finished ${a<6e4?"just now":`${Vn(e.endedAt,t)} ago`}`}var A1=e=>{let t=Date.parse(e);return Number.isNaN(t)?"":new Date(t).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})},xm=(e,t)=>{let a=Date.parse(e);return Number.isNaN(a)?"":new Date(a).toDateString()===new Date(t).toDateString()?A1(e):new Date(a).toLocaleString([],{weekday:"short",hour:"2-digit",minute:"2-digit"})},Nd=(e,t,a)=>`${e} ${e===1?t:a}`;function E1(e){return e.group==="needs-you"?{word:e.label,tone:"ask"}:e.group==="stuck"?{word:"Stuck",tone:""}:e.group==="working"?{word:"Building",tone:"live"}:e.label==="Done"?{word:"Finished",tone:"done"}:e.label==="No changes"?{word:"No changes",tone:"done"}:e.label==="Failed"?{word:"Failed",tone:"failed"}:{word:e.label,tone:""}}function XQ({row:e}){let{word:t,tone:a}=E1(e);return(0,D.jsx)("span",{className:"agents-chip","data-agent-state":e.label,children:(0,D.jsx)($e,{word:t,tone:a})})}function YQ({row:e}){let t=Wr();return(0,D.jsx)("time",{dateTime:e.endedAt??e.startedAt,className:"k-num","data-agent-time":!0,children:R1(e,t)})}function q4({text:e}){let[t,a]=(0,Bt.useState)("no");return(0,D.jsxs)("span",{className:"agents-copy",children:[(0,D.jsx)("code",{className:"k-code",children:e}),(0,D.jsx)(se,{sm:!0,label:t==="yes"?"Copied":"Copy",onClick:()=>{if(navigator.clipboard?.writeText===void 0){a("failed");return}navigator.clipboard.writeText(e).then(()=>a("yes"),()=>a("failed"))}}),t==="failed"&&(0,D.jsx)("span",{className:"k-note",role:"status",children:"Couldn't copy. Select it and copy it yourself."})]})}var ZQ={"30m":30*6e4,"2h":120*6e4,"24h":1440*6e4},z4={"30m":"the last 30 minutes","2h":"the last 2 hours","24h":"the last 24 hours"};function QQ({row:e}){let t=e.endedAt!==null&&e.group!=="needs-you",a=e.group==="needs-you"?e.label==="Question"?(0,D.jsx)(He,{sm:!0,href:e.href,label:"Answer"}):(0,D.jsx)(He,{sm:!0,href:`/t/${encodeURIComponent(e.taskId)}`,label:"Open task"}):t?(0,D.jsx)(He,{sm:!0,href:`/r/${e.runId}`,label:"Open record"}):(0,D.jsx)(He,{sm:!0,href:e.href,label:"Watch"}),n=[e.line??(t?e.diff:null),e.agent].filter(Boolean).join(" · ");return(0,D.jsx)("div",{"data-agent-row":e.runId,"data-agent-group":e.group,children:(0,D.jsx)(xn,{href:e.href,wait:e.group==="needs-you",chip:(0,D.jsx)(XQ,{row:e}),title:e.title,desc:(0,D.jsx)("span",{"data-agent-line":!0,title:e.line??void 0,children:n}),meta:(0,D.jsxs)(D.Fragment,{children:[e.project&&(0,D.jsx)("span",{children:e.project}),(0,D.jsx)(YQ,{row:e}),e.diff!==null&&!t&&(0,D.jsx)("span",{className:"k-num","data-agent-diff":!0,children:e.diff})]}),action:a})})}function T1({id:e,label:t,rows:a,ink:n,right:o}){return(0,D.jsxs)("section",{"data-agent-group-section":e,"aria-labelledby":`agents-${e}`,children:[(0,D.jsx)(ur,{id:`agents-${e}`,label:t,count:(0,D.jsx)(Ct,{n:a.length,ink:n===!0}),right:o}),a.map(r=>(0,D.jsx)(QQ,{row:r},r.runId))]})}function JQ(e,t){let a=`heard ${Vn(e.heardAt,t)} ago`,n=e.reserved.length>0?` · ${e.reserved.length} reserved`:"";if(e.retired)return`Retired${n}`;if(e.state==="offline")return`Stopped answering at ${xm(e.heardAt,t)} · ${Vn(e.heardAt,t)} ago${n}`;let o=e.building.length+e.hidden;return e.state==="building"?`${o} of ${e.capacity} building · ${a}${n}`:`Free · ${Nd(e.capacity,"slot","slots")} · ${a}${n}`}var $4=e=>e.retired?(0,D.jsx)($e,{word:"Retired"}):(0,D.jsx)($e,{word:Bk[e.state].word,tone:Bk[e.state].tone});function eJ({one:e,others:t}){let a=Wr(3e4);return(0,D.jsx)("div",{"data-computer-offline":e.name,children:(0,D.jsx)(fo,{status:(0,D.jsxs)(D.Fragment,{children:[$4(e),(0,D.jsxs)("h2",{children:[e.name," is offline"]})]}),text:`It stopped answering at ${xm(e.heardAt,a)}. Nothing is lost: work it would take waits in the queue${t?", and the other computers keep building":""}. To bring it back, open a terminal on ${e.host}, go to the project's folder and run:`,acts:(0,D.jsx)(q4,{text:"toolroll up"}),terms:`Keep it running; it picks up queued work on its own. If ${e.name} is gone for good, retire it below.`})})}function tJ(){return(0,D.jsx)("div",{"data-computer-none":!0,children:(0,D.jsx)(fo,{status:(0,D.jsx)("h2",{children:"No computer is building yet"}),text:"Approved tasks wait until one is connected. On the computer where the project lives, open the project's folder in a terminal and run:",acts:(0,D.jsx)(q4,{text:"toolroll up"}),terms:"Keep it running. The console alone (toolroll serve) doesn't build."})})}function aJ({one:e,computers:t,trigger:a,onClose:n}){let o=Wr(3e4),r=(0,Bt.useContext)(Jo),s=(0,Bt.useContext)(so),i={passwordless:r,remembered:!1},l=e.retired?"Retired":e.state==="offline"?`Offline since ${xm(e.heardAt,o)}`:e.state==="building"?"Online, building":"Online",u=async f=>{try{let d=await fetch("/fleet/runner/retire",{method:"POST",credentials:"same-origin",redirect:"manual",headers:Wt({}),body:new URLSearchParams({csrf:s,name:e.name,token:f??""})});return d.type==="opaqueredirect"||d.status>=300&&d.status<400?(location.assign(`/agents?retired=${encodeURIComponent(e.name)}#computers`),null):d.status===404?"There's no computer by that name any more. Nothing changed.":f===null?"Retiring needs your password now. Nothing changed.":"That password didn't match. Nothing changed."}catch{return"The console didn't answer. Nothing changed; try again."}};return(0,D.jsx)(co,{kind:"drawer",title:e.name,trigger:a,onClose:n,children:(0,D.jsxs)("div",{className:"agents-cpanel","data-computer-panel":e.name,children:[(0,D.jsx)(Yc,{rows:[["Status",l],["Computer",e.host],["Takes work from",e.projects.length>0?e.projects.join(", "):"No projects yet"],["Building now",e.building.length===0&&e.hidden===0?"Nothing":(0,D.jsxs)(D.Fragment,{children:[e.building.map(f=>(0,D.jsx)("span",{className:"agents-fact-line",children:(0,D.jsx)("a",{href:f.href,children:f.title})},f.taskId)),e.hidden>0&&(0,D.jsxs)("span",{className:"agents-fact-line",children:[Nd(e.hidden,"task","tasks")," in projects you can't see"]})]})],["At a time",Nd(e.capacity,"task","tasks")],["Last heard",`${xm(e.heardAt,o)} (${Vn(e.heardAt,o)} ago)`],["Registered",xm(e.registeredAt,o)]]}),(0,D.jsxs)("section",{className:"k-sec","aria-label":"Reserved for it",children:[(0,D.jsx)("h3",{children:"Reserved for it"}),e.reserved.length===0?(0,D.jsx)(ea,{children:"Nothing. It takes from the shared queue, top first."}):(0,D.jsx)("ul",{className:"agents-list",children:e.reserved.map(f=>(0,D.jsxs)("li",{"data-reserved":f.id,children:[(0,D.jsxs)("span",{className:"agents-list-t",children:[(0,D.jsx)("a",{href:f.href,children:f.title}),f.project&&(0,D.jsxs)("span",{className:"k-muted",children:[" · ",f.project]})]}),t.manage&&!f.taken&&(0,D.jsxs)(Ae,{action:"/queue/move",className:"agents-move",children:[(0,D.jsx)("input",{type:"hidden",name:"queueRevision",value:String(t.queueRevision)}),(0,D.jsx)("input",{type:"hidden",name:"task",value:f.id}),(0,D.jsx)("input",{type:"hidden",name:"before",value:""}),(0,D.jsx)(lo,{sm:!0,name:"column","aria-label":`Move ${f.title} to`,defaultValue:"anyone",items:[["anyone","Shared queue"],...t.list.filter(d=>d.name!==e.name&&!d.retired).map(d=>[d.name,d.name])]}),(0,D.jsx)(se,{sm:!0,type:"submit",label:"Move"})]}),f.taken&&(0,D.jsx)("span",{className:"k-note",children:"Being taken"})]},f.id))})]}),t.manage&&!e.retired&&(0,D.jsxs)(Ae,{action:"/queue/note",className:"k-sec",children:[(0,D.jsx)("input",{type:"hidden",name:"runner",value:e.name}),(0,D.jsx)("input",{type:"hidden",name:"from",value:"fleet"}),(0,D.jsx)(ki,{label:"Note on its queue",hint:"What it is working through, for whoever looks next.",children:f=>(0,D.jsx)(Na,{id:f.id,name:"note",maxLength:200,defaultValue:e.note??"","aria-describedby":f.describedBy})}),(0,D.jsx)(uo,{children:(0,D.jsx)(se,{sm:!0,type:"submit",label:"Save note"})})]}),!t.manage&&e.note&&(0,D.jsx)(Yc,{rows:[["Note",e.note]]}),t.manage&&!e.retired&&(0,D.jsxs)("div",{className:"k-sec","data-computer-retire":e.name,children:[(0,D.jsx)(uo,{children:(0,D.jsx)(Bi,{kind:"step-up",facts:i,label:"Retire computer",primary:!1,terms:`Retire ${e.name}: it takes no more work.`,onApprove:u})}),(0,D.jsx)(ea,{children:`Retiring stops it taking work. Tasks reserved for it wait until you move them. ${_i("step-up",i)}`})]})]})})}var H4=e=>e===""?"Name the computer first.":e.length>60||/[\p{Cc}\p{Cf}]/u.test(e)?"Use one short line: up to 60 characters, no control characters.":null;function nJ({onCancel:e}){let t=(0,Bt.useContext)(so),a=(0,Bt.useContext)(Jo),[n,o]=(0,Bt.useState)(""),[r,s]=(0,Bt.useState)("1"),[i,l]=(0,Bt.useState)(null),u=(0,Bt.useRef)(null),f=n.trim(),d={passwordless:a,remembered:!1},c=async h=>{let y=document.createElement("form");y.setAttribute("method","post"),y.setAttribute("action","/fleet/runner/register"),y.hidden=!0;for(let[b,g]of Object.entries({csrf:t,name:f,capacity:r,token:h??""})){let x=document.createElement("input");x.type="hidden",x.name=b,x.value=g,y.append(x)}return document.body.append(y),y.submit(),null},m=()=>{l(H4(f)),u.current?.focus()};return(0,D.jsxs)("div",{className:"k-sec agents-reg",id:"agents-register","data-computer-register":!0,children:[(0,D.jsx)("h3",{children:"Add a computer"}),(0,D.jsx)(ki,{label:"Computer name",error:i,children:h=>(0,D.jsx)(Na,{ref:u,id:h.id,value:n,autoComplete:"off",spellCheck:!1,maxLength:60,"aria-describedby":h.describedBy,"aria-invalid":h.invalid||void 0,onChange:y=>{o(y.target.value),l(null)}})}),(0,D.jsx)(ki,{label:"Tasks at a time",children:h=>(0,D.jsx)(lo,{id:h.id,wide:!0,value:r,onChange:y=>s(y.target.value),items:["1","2","3","4","6","8"]})}),(0,D.jsxs)("p",{className:"agents-terms",children:[f||"New computer"," · up to ",r," at a time · takes from the shared queue"]}),(0,D.jsxs)(uo,{children:[H4(f)===null?(0,D.jsx)(Bi,{kind:"way-in",facts:d,label:"Register computer",terms:`Register ${f}: up to ${r} at a time.`,onApprove:c}):(0,D.jsx)(se,{variant:"primary",label:"Register computer",onClick:m}),(0,D.jsx)(se,{variant:"ghost",label:"Cancel",onClick:e})]}),(0,D.jsx)(ea,{children:`${_i("way-in",d)} Registering makes a token that lets the computer take work; it is shown once.`})]})}function oJ({computers:e,terminals:t}){let a=Wr(3e4),[n,o]=(0,Bt.useState)(!1),[r,s]=(0,Bt.useState)(null),i=r===null?null:e.list.find(u=>u.name===r.name)??null,l=e.manage&&!n?(0,D.jsx)(se,{variant:"ghost",sm:!0,lead:"plus",label:"Add a computer",onClick:()=>o(!0)}):void 0;return(0,D.jsxs)("section",{id:"computers",className:"agents-sec","aria-labelledby":"agents-computers","data-computers":!0,children:[(0,D.jsx)(ur,{id:"agents-computers",label:"Computers that build",count:(0,D.jsx)(Ct,{n:e.list.length}),right:l}),e.list.length===0&&(0,D.jsx)("div",{className:"agents-pad",children:(0,D.jsx)(tJ,{})}),e.list.map(u=>(0,D.jsx)("div",{"data-computer":u.name,children:(0,D.jsx)(xn,{chip:$4(u),title:u.name,desc:`${u.host} · ${JQ(u,a)}`,meta:(0,D.jsx)("span",{children:u.projects.length>0?u.projects.join(", "):"No projects yet"}),action:(0,D.jsx)(se,{sm:!0,label:"Details","aria-haspopup":"dialog",onClick:f=>s({name:u.name,trigger:f.currentTarget})})})},u.name)),e.shared>0&&(0,D.jsxs)("p",{className:"agents-line",children:[Nd(e.shared,"task waits","tasks wait")," in the shared queue for any free computer. ",(0,D.jsx)("a",{className:"k-link",href:"/tasks?view=order",children:"Reserve one for a computer"})]}),n&&(0,D.jsx)(nJ,{onCancel:()=>o(!1)}),t&&(0,D.jsx)("p",{className:"agents-line k-phone-only",children:(0,D.jsx)("a",{className:"k-link",href:"/agents/terminals",children:"Terminals on these computers"})}),r!==null&&i!==null&&(0,D.jsx)(aJ,{one:i,computers:e,trigger:r.trigger,onClose:()=>s(null)})]})}var F4={plan:["Plan","Writes the plan you approve"],build:["Build","Does the work inside the approved plan"],repair:["Repair","Fixes a malformed handoff in the same session"],review:["Review","Reads the result against the requirements"]};function rJ({view:e}){let[t]=(0,Bt.useState)(()=>typeof location<"u"&&location.hash==="#models"),a=e.system??null,n=a!==null&&(a.workspaces.length>0||a.service!==null||a.outbox>0||a.external.length>0);return(0,D.jsxs)("section",{id:"models",className:"agents-sec agents-models","data-agent-phases":!0,children:[(0,D.jsx)(lr,{summary:"Model per phase",open:t,children:(0,D.jsxs)("div",{className:"agents-phases",children:[(e.phases??[]).map(o=>(0,D.jsxs)("div",{className:"agents-phase","data-phase":o.phase,children:[(0,D.jsx)("b",{children:F4[o.phase]?.[0]??o.phase}),(0,D.jsx)("span",{className:"k-muted",children:F4[o.phase]?.[1]??""}),o.model===null?(0,D.jsx)("span",{children:o.problem}):(0,D.jsxs)("span",{children:[o.model,o.noDollars&&(0,D.jsx)("span",{className:"k-muted",children:" · reports tokens, not dollars"})]}),(0,D.jsx)("span",{className:"k-muted",children:o.source})]},o.phase)),(0,D.jsxs)(ea,{children:["Repair always stays on the provider that built; only its model can differ. ",(0,D.jsx)("a",{className:"k-link",href:"/settings/agents",children:"Change in Settings → Agents and models"})]})]})}),n&&a!==null&&(0,D.jsx)(lr,{summary:"Workspaces and sync",children:(0,D.jsxs)("div",{className:"agents-phases",children:[a.service!==null&&(0,D.jsx)("p",{children:a.service.running?`The background service is running, since ${A1(a.service.at)}.`:`The background service last ran: ${a.service.built} built, ${a.service.broke} broke · ended ${A1(a.service.at)}.`}),a.workspaces.length>0&&(0,D.jsx)("ul",{className:"agents-list",children:a.workspaces.map(o=>(0,D.jsxs)("li",{children:[(0,D.jsx)("span",{className:"k-mono",children:o.name}),(0,D.jsxs)("span",{className:"k-muted",children:[o.branch," · ",o.state]})]},o.name))}),a.outbox>0&&(0,D.jsxs)("p",{children:[Nd(a.outbox,"notification waits","notifications wait")," to be delivered."]}),a.external.map(o=>(0,D.jsxs)("p",{children:[(0,D.jsx)("span",{className:"k-mono",children:o.repo})," · ",o.state]},o.repo))]})})]})}function sJ({view:e}){let t=Wr(3e4),[a,n]=(0,Bt.useState)(e.window??"24h"),o=m=>{let h=m==="30m"||m==="2h"?m:"24h";n(h);try{let y=new URL(location.href);h==="24h"?y.searchParams.delete("window"):y.searchParams.set("window",h),history.replaceState(history.state,"",y)}catch{}},r=e.groups.flatMap(m=>m.rows),s=r.filter(m=>m.group==="needs-you"),i=r.filter(m=>m.endedAt===null&&m.group!=="needs-you"),l=r.filter(m=>m.endedAt!==null&&m.group!=="needs-you"&&t-Date.parse(m.endedAt)<=ZQ[a]),u=(e.computers?.list??[]).filter(m=>m.state==="offline"&&!m.retired),f=(e.computers?.list??[]).some(m=>m.state!=="offline"),c=(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(Ur,{label:"Finished in",current:a,onChange:o,items:[{key:"30m",label:"30 min"},{key:"2h",label:"2 h"},{key:"24h",label:"24 h"}]}),(0,D.jsx)(He,{sm:!0,variant:"ghost",href:"/agents?view=live",label:"Live view"}),e.terminals===!0&&(0,D.jsx)(He,{sm:!0,href:"/agents/terminals",label:"Terminals"})]});return(0,D.jsxs)("div",{className:"agents-page",id:"agents-view","data-agents-board":!0,children:[(0,D.jsx)(tn,{title:"Agents",ctx:`All projects · ${Nd(i.length,"agent","agents")} building`,right:c}),e.computerSaid&&(0,D.jsx)("div",{className:"agents-pad","data-computer-said":!0,children:e.computerSaid.tone==="error"?(0,D.jsx)($a,{children:e.computerSaid.text}):(0,D.jsx)(Pi,{children:e.computerSaid.text})}),u.map(m=>(0,D.jsx)("div",{className:"agents-pad",children:(0,D.jsx)(eJ,{one:m,others:f})},m.name)),s.length===0&&i.length===0&&(0,D.jsx)("div",{"data-agents-empty":!0,children:(0,D.jsx)(Ua,{title:"No agents are working.",text:"An agent starts when you approve a plan. What finished in the window you pick shows below.",action:(0,D.jsx)(He,{sm:!0,href:"/tasks",label:"Open Tasks"})})}),s.length>0&&(0,D.jsx)(T1,{id:"needs-you",label:"Needs you",rows:s,ink:!0}),i.length>0&&(0,D.jsx)(T1,{id:"working",label:"Working",rows:i}),(0,D.jsx)(T1,{id:"finished",label:(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)("span",{className:"k-desk-only",children:["Finished in ",z4[a]]}),(0,D.jsx)("span",{className:"k-phone-only",children:"Finished"})]}),rows:l,right:(0,D.jsx)("span",{className:"k-phone-only",children:(0,D.jsx)(lo,{sm:!0,"aria-label":"Finished in",value:a,onChange:m=>o(m.target.value),items:[["30m","Last 30 min"],["2h","Last 2 h"],["24h","Last 24 h"]]})})}),l.length===0&&(0,D.jsxs)("p",{className:"agents-none",children:["Nothing finished in ",z4[a],"."]}),e.computers!=null&&(0,D.jsx)(oJ,{computers:e.computers,terminals:e.terminals===!0}),e.phases!=null&&(0,D.jsx)(rJ,{view:e}),e.computers==null&&e.terminals===!0&&(0,D.jsx)("p",{className:"agents-line k-phone-only",children:(0,D.jsx)("a",{className:"k-link",href:"/agents/terminals",children:"Terminals"})})]})}function iJ(e,t){let[a,n]=(0,Bt.useState)(null);return(0,Bt.useEffect)(()=>{if(e===null||!t)return;let o=!1,r=0,s=async()=>{try{let i=await fetch(e,{cache:"no-store",credentials:"same-origin",redirect:"manual"});i.ok&&!o&&n(await i.text())}catch{}o||(r=window.setTimeout(()=>{s()},1e4))};return s(),()=>{o=!0,window.clearTimeout(r)}},[e,t]),a}function lJ({detail:e,open:t}){let a=iJ(e.peek,t);return(0,D.jsx)("div",{"data-agent-changes":!0,className:"agents-changes",children:e.live?e.peek===null?(0,D.jsx)(ea,{children:"Output from other computers isn't shown yet."}):a===null?(0,D.jsx)(ea,{children:"Looking at the checkout…"}):(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(St,{html:a,className:"so-native-region"}),(0,D.jsx)(ea,{children:"A live look at its working copy, refreshed every 10 seconds. Not yet a result: the record is sealed when the build ends."})]}):e.files.length===0?(0,D.jsx)(ea,{children:"No saved changes."}):(0,D.jsxs)("ul",{className:"agents-files",children:[e.files.map(n=>(0,D.jsxs)("li",{children:[(0,D.jsx)("span",{className:"k-mono",title:n.path,children:n.path}),(0,D.jsx)("span",{className:"k-num agents-add",children:n.added===null?"":`+${n.added}`}),(0,D.jsx)("span",{className:"k-num agents-del",children:n.removed===null?"":`−${n.removed}`})]},n.path)),e.filesMore>0&&(0,D.jsxs)("li",{className:"k-muted",children:[e.filesMore," more in the result"]})]})})}function uJ({checkout:e}){let[t,a]=(0,Bt.useState)("no"),n=()=>{if(navigator.clipboard?.writeText===void 0){a("failed");return}navigator.clipboard.writeText(e.cd).then(()=>a("yes"),()=>a("failed"))};return(0,D.jsxs)("section",{"aria-label":"Its files",className:"k-sec agents-checkout","data-agent-checkout":!0,children:[(0,D.jsx)("h3",{children:"Its files"}),(0,D.jsx)(ea,{children:"These files were written by an agent. Your shell's startup scripts and prompt tools (git status in the prompt, direnv, .envrc) can run code from them when you open a terminal there."}),(0,D.jsx)("code",{className:"k-code","data-agent-checkout-path":!0,children:e.path}),(0,D.jsxs)("div",{className:"k-acts k-desk-only",children:[(0,D.jsx)(se,{sm:!0,onClick:n,"data-agent-copy-cd":!0,label:t==="yes"?"Copied":"Copy the command"}),e.reveal!==null&&(0,D.jsxs)(Ae,{action:e.reveal,"data-agent-reveal":!0,children:[(0,D.jsx)("input",{type:"hidden",name:"return",value:"agents"}),(0,D.jsx)(se,{sm:!0,type:"submit",label:"Show in Finder"})]})]}),t==="failed"&&(0,D.jsxs)("div",{role:"status",className:"agents-checkout","data-agent-copy-failed":!0,children:[(0,D.jsx)(ea,{children:"Couldn't copy. Select the command and copy it yourself:"}),(0,D.jsx)("code",{className:"k-code",children:e.cd})]})]})}function cJ({controls:e}){let t=e.pause,a=e.stop,[n,o]=(0,Bt.useState)(null);return(0,D.jsxs)(D.Fragment,{children:[t!==null&&(t.state==="paused"?(0,D.jsxs)(Ae,{action:t.action,"data-agent-resume":!0,children:[(0,D.jsx)("input",{type:"hidden",name:"run",value:String(t.run)}),(0,D.jsx)("input",{type:"hidden",name:"request",value:t.requests[2]}),(0,D.jsx)("input",{type:"hidden",name:"mode",value:"resume"}),(0,D.jsx)("input",{type:"hidden",name:"return",value:"agents"}),(0,D.jsx)(se,{type:"submit",label:"Resume"})]}):(0,D.jsxs)(Ae,{action:t.action,"data-agent-pause":!0,children:[(0,D.jsx)("input",{type:"hidden",name:"run",value:String(t.run)}),(0,D.jsx)("input",{type:"hidden",name:"request",value:t.requests[0]}),(0,D.jsx)("input",{type:"hidden",name:"return",value:"agents"}),(0,D.jsx)(se,{type:"submit",label:"Pause",busy:t.state==="pausing"?"Pausing…":!1,disabled:t.state==="pausing"})]})),a!==null&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(se,{variant:"ghost",label:a.label,"aria-haspopup":"dialog","data-agent-stop-open":a.run,onClick:r=>o(r.currentTarget)}),n!==null&&(0,D.jsxs)(co,{kind:"popover",title:`${a.label}?`,trigger:n,onClose:()=>o(null),children:[(0,D.jsx)("p",{className:"k-pop-terms",children:"It ends now and keeps the work so far. The task waits for you: retry it, or change the plan."}),(0,D.jsxs)(Ae,{action:a.action,"data-agent-stop":a.run,children:[(0,D.jsx)("input",{type:"hidden",name:"run",value:String(a.run)}),(0,D.jsx)("input",{type:"hidden",name:"return",value:"agents"}),(0,D.jsxs)(uo,{children:[(0,D.jsx)(se,{type:"submit",variant:"danger",label:a.label}),(0,D.jsx)(se,{variant:"ghost",label:"Cancel","data-k-close":""})]})]})]})]})]})}function dJ({detail:e}){let t=Wr(),a=e.canAct&&e.controls!=null?e.controls:null,n=a!==null?(0,D.jsx)("div",{className:"k-acts","data-agent-controls":a.send??"none",children:(0,D.jsx)(cJ,{controls:a})}):null;if(e.question!==null)return(0,D.jsx)(fo,{wait:!0,status:(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)($e,{word:"Question",tone:"ask"}),(0,D.jsxs)("h2",{children:[e.agent," asks"]})]}),text:(0,D.jsx)("span",{"data-agent-question":e.question.key,children:e.question.text}),acts:n,terms:e.canAct?"Answer below. It reads your reply at its next check.":"An approver answers it."});if(e.live){let s=a?.pause?.state==="paused",{word:i,tone:l}=s?{word:"Paused",tone:""}:E1(e);return(0,D.jsx)(fo,{status:(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)($e,{word:i,tone:l}),(0,D.jsx)("h2",{children:R1(e,t)})]}),text:(0,D.jsx)("span",{"data-agent-line":!0,children:e.line??"Working."}),acts:n,terms:a===null?"":(0,D.jsx)("span",{"data-agent-capability":!0,children:a.words})})}let{word:o,tone:r}=E1(e);return(0,D.jsx)(fo,{status:(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)($e,{word:o,tone:r}),(0,D.jsx)("h2",{children:R1(e,t)})]}),text:(0,D.jsx)("span",{"data-agent-line":!0,children:e.line??e.diff??"It has finished."}),acts:(0,D.jsx)(He,{href:e.open?.href??e.taskHref,label:e.open?`Open ${e.open.label.toLowerCase()}`:"Open task"}),terms:e.diff??""})}var fJ=e=>e.canAct&&(e.question!==null||e.steer!==null&&!(e.live&&e.controls!=null&&e.controls.send===null));function pJ({detail:e}){let t=e.question,a=(0,Bt.useRef)(null),[n,o]=(0,Bt.useState)(()=>t!==null?Po():nd(e.runId)),r=n.text,s=f=>o(d=>{let c=d.submitted?{...Po(),text:f}:{...d,text:f};return Gr(e.runId,c),c});if(!e.canAct)return e.live?(0,D.jsxs)("section",{className:"k-sec agents-steer","aria-label":"Send a note",children:[(0,D.jsx)("h3",{children:"Send a note"}),(0,D.jsx)(ea,{children:"Your sign-in can watch this agent. Sending it a note takes an approver; ask an operator to change your role in Settings → People and sign-in."})]}):null;if(t===null&&e.live&&e.controls!=null&&e.controls.send===null)return null;if(t===null&&e.steer===null){if(r.trim()==="")return null;let f=()=>{Gr(e.runId,{...Po(),text:""}),o(Po())};return(0,D.jsxs)(Ae,{action:`${e.taskHref}/steer`,"data-agent-unsent":!0,className:"k-sec agents-steer",children:[(0,D.jsx)("h3",{children:"Your note wasn't sent: this attempt ended first"}),(0,D.jsx)("p",{className:"agents-unsent","data-agent-unsent-text":!0,children:r}),(0,D.jsx)("input",{type:"hidden",name:"note",value:r}),(0,D.jsx)("input",{type:"hidden",name:"after",value:String(e.runId)}),(0,D.jsx)("input",{type:"hidden",name:"key",value:n.key}),(0,D.jsxs)(uo,{children:[(0,D.jsx)(se,{type:"submit",variant:"primary",label:"Send to the next attempt"}),(0,D.jsx)(se,{variant:"ghost",label:"Discard",onClick:f})]}),(0,D.jsx)(ea,{children:"The task's next attempt reads it before starting. No password needed."})]})}let i=t!==null,l=e.controls?.pause!=null&&e.controls.pause.state===null?e.controls.pause:null,u=i?"It reads your reply at its next check.":"Notes reach the agent; it answers in the conversation above.";return(0,D.jsxs)(Ae,{ref:a,action:i?t.action:e.steer.action,"data-agent-composer":i?"reply":"steer",className:"k-sec agents-steer",onSubmit:f=>{if(r.trim()===""){f.preventDefault();return}i||o(d=>{let c={...d,submitted:!0};return Gr(e.runId,c),c})},children:[(0,D.jsx)("h3",{children:i?`Reply to ${e.agent}`:`Send a note to ${e.agent}`}),i?(0,D.jsx)("input",{type:"hidden",name:"question",value:String(t.id)}):(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)("input",{type:"hidden",name:"return",value:"agents"}),(0,D.jsx)("input",{type:"hidden",name:"run",value:String(e.steer.run)}),(0,D.jsx)("input",{type:"hidden",name:"key",value:n.key}),l!==null&&(0,D.jsx)("input",{type:"hidden",name:"request",value:`steer-${n.key}`})]}),(0,D.jsx)(ed,{id:`agent-composer-${e.runId}`,label:i?`Reply to: ${t.text}`:`Send a note to ${e.agent}`,name:i?"answer":"note",maxLength:i?1500:4e3,rows:3,value:r,onChange:f=>{i?o(d=>({...d,text:f})):s(f)},placeholder:i?"Your answer":"For example: keep the flag off in staging until Wednesday.",sendLabel:i?"Reply":"Send note",onSend:()=>a.current?.requestSubmit(),error:e.said?.tone==="error"?e.said.text:null,before:!i&&l!==null?(0,D.jsx)(se,{sm:!0,type:"submit",formAction:l.action,label:"Pause and send",disabled:r.trim()==="","data-agent-pause-send":!0}):void 0,note:`${u} No password needed.`})]})}function mJ({detail:e}){let[t,a]=(0,Bt.useState)("conversation");return(0,D.jsxs)("div",{className:"agents-tabs","data-agent-tabs":!0,children:[(0,D.jsx)(dv,{label:"Agent",current:t,onChange:n=>a(n==="changes"?"changes":"conversation"),items:[{key:"conversation",label:"Conversation"},{key:"changes",label:e.diff===null?"Changes":`Changes · ${e.diff}`}]}),(0,D.jsx)("div",{role:"tabpanel","aria-label":"Conversation",hidden:t!=="conversation",children:(0,D.jsx)(I4,{url:e.transcript,live:e.live,agent:e.agent})}),(0,D.jsx)("div",{role:"tabpanel","aria-label":"Changes",hidden:t!=="changes",children:(0,D.jsxs)("div",{className:"agents-changes-wrap",children:[(0,D.jsx)(lJ,{detail:e,open:t==="changes"}),e.checkout!=null&&e.canAct&&(0,D.jsx)(uJ,{checkout:e.checkout})]})})]})}function hJ({detail:e}){hn(e.room,o=>{(o==="change"||o==="reload")&&window.dispatchEvent(new Event(Fi))});let t=(0,Bt.useContext)(so);(0,Bt.useEffect)(()=>e.live?vA(e.runId,t):(Dg(e.runId,t),void 0),[e.runId,e.live,t]);let a=[e.project,`run ${e.runId}`,e.agent].filter(Boolean).join(" · "),n=e.task??null;return(0,D.jsxs)("div",{className:"agents-agent",id:"agents-view","data-agent-detail":e.runId,children:[(0,D.jsx)(hv,{title:e.project??"Agent",back:"/agents"}),(0,D.jsxs)(b_,{children:[(0,D.jsx)(gv,{back:["/agents","Agents"],title:e.title,meta:a,right:(0,D.jsx)(He,{variant:"ghost",sm:!0,href:e.taskHref,label:"Open task","data-agent-open":"Task"})}),e.said&&e.said.tone==="info"&&(0,D.jsx)("div",{"data-agent-said":!0,children:(0,D.jsx)(Pi,{children:e.said.text})}),e.said&&e.said.tone==="error"&&!fJ(e)&&(0,D.jsx)("div",{"data-agent-said":!0,children:(0,D.jsx)($a,{children:e.said.text})}),(0,D.jsx)("div",{id:"agents-box",children:(0,D.jsx)(dJ,{detail:e})}),n!==null&&(0,D.jsxs)("p",{className:"agents-task","data-agent-task":n.headline,children:["The task: ",(0,D.jsx)("b",{children:n.headline}),". ",n.sentence," ",(0,D.jsx)("a",{className:"k-link",href:n.action.href,"data-agent-task-action":!0,children:n.action.label})]}),(0,D.jsx)(mJ,{detail:e}),(0,D.jsx)(pJ,{detail:e},`${e.runId}:${e.question?.id??"steer"}`)]})]})}function gJ(){return(0,D.jsxs)("div",{className:"agents-page",id:"agents-view","data-agents-board":!0,children:[(0,D.jsx)(tn,{title:"Live",back:"/agents",ctx:"Every running agent's output, watching only",right:(0,D.jsx)(He,{sm:!0,variant:"ghost",href:"/agents",label:"Back to Agents"})}),(0,D.jsx)("div",{className:"agents-live",children:(0,D.jsx)(B4,{})})]})}function U4({view:e}){return e.live===!0?(0,D.jsx)(gJ,{}):e.selected!==null?(0,D.jsx)(hJ,{detail:e.selected},e.selected.runId):(0,D.jsx)(sJ,{view:e})}var Ga=O(he(),1);var ge=O(G(),1),vJ=()=>window.dispatchEvent(new CustomEvent(Fi)),yJ=e=>e.groups.flatMap(t=>t.rows);async function xJ(e){try{let t=await e.text(),n=new DOMParser().parseFromString(t,"text/html").querySelector(".problem")?.textContent?.trim();return n?`Couldn’t answer: ${n}. Nothing changed.`:"Couldn’t answer. Nothing changed."}catch{return"Couldn’t answer. Nothing changed."}}function bJ({row:e}){let t=e.question,a=(0,Ga.useContext)(so),[n,o]=(0,Ga.useState)(t.options.find(c=>c.recommended)?.id??t.options[0]?.id??""),[r,s]=(0,Ga.useState)(!1),[i,l]=(0,Ga.useState)(!1),[u,f]=(0,Ga.useState)(null),d=async()=>{if(!(r||i||n==="")){s(!0),f(null);try{let c=await fetch(`/d/${t.id}/answer`,{method:"POST",credentials:"same-origin",headers:Wt({}),body:new URLSearchParams({csrf:a,choice:n}),signal:AbortSignal.timeout(15e3)});if(!c.ok){f(await xJ(c));return}l(!0),window.setTimeout(vJ,500)}catch{f("Couldn’t reach Toolroll. Nothing changed; try again.")}finally{s(!1)}}};return(0,ge.jsxs)(ge.Fragment,{children:[(0,ge.jsx)("h2",{className:"so-open-t",children:t.text}),t.recap&&(0,ge.jsx)("p",{className:"so-open-x",children:t.recap}),(0,ge.jsx)(v_,{name:`answer-${t.id}`,legend:"Choose one",current:n,onChange:o,items:t.options.map(c=>({value:c.id,label:c.label,text:c.consequence,...c.recommended?{tag:(0,ge.jsx)($e,{word:"Recommended",dot:!1})}:{}}))}),(0,ge.jsxs)("div",{className:"k-acts",children:[(0,ge.jsx)(se,{variant:"primary",label:i?"Answered":"Answer",busy:r?"Sending…":!1,onClick:()=>{d()},"aria-disabled":i?!0:void 0}),(0,ge.jsx)(He,{variant:"ghost",label:"Open the question",href:`/d/${t.id}`})]}),u&&(0,ge.jsx)($a,{children:u})]})}function wJ({row:e,waits:t}){if(e===null)return(0,ge.jsxs)("div",{className:"k-empty",children:[(0,ge.jsx)("p",{className:"k-empty-t",children:"Nothing needs you."}),(0,ge.jsx)(He,{sm:!0,label:"Open Tasks",href:"/tasks"})]});let a=(0,ge.jsxs)("div",{className:"so-open-k",children:[(0,ge.jsx)("span",{children:[e.project,e.age].filter(Boolean).join(" · ")}),(0,ge.jsx)("span",{className:"k-grow"}),(0,ge.jsx)(He,{variant:"ghost",sm:!0,label:"Open task",href:e.href})]});return e.question?(0,ge.jsxs)(ge.Fragment,{children:[a,(0,ge.jsx)("p",{className:"so-open-of",children:e.title}),(0,ge.jsx)(bJ,{row:e},e.question.id)]}):(0,ge.jsxs)(ge.Fragment,{children:[a,(0,ge.jsx)("h2",{className:"so-open-t",children:e.title}),(0,ge.jsxs)("p",{className:"so-open-chip",children:[(0,ge.jsx)($e,{word:t?"Needs you":e.chip.word,tone:t?"needs":e.chip.tone}),t&&(0,ge.jsx)("span",{children:e.chip.word})]}),e.line&&(0,ge.jsx)("p",{className:"so-open-x",children:e.line}),(0,ge.jsx)("div",{className:"k-acts",children:e.action?(0,ge.jsx)(He,{label:e.action.label,href:e.action.href}):(0,ge.jsx)(He,{label:"Open task",href:e.href})})]})}function kJ({ask:e}){let t=(0,Ga.useContext)(so),a=(0,Ga.useRef)(null),[n,o]=(0,Ga.useState)(""),[r,s]=(0,Ga.useState)(!1),i=(0,Ga.useRef)(Array.from(crypto.getRandomValues(new Uint8Array(16)),u=>u.toString(16).padStart(2,"0")).join("")),l=()=>{if(r||n.trim()==="")return;s(!0);let u=a.current?.querySelector('input[name="message"]');u&&(u.value=n),a.current?.requestSubmit()};return(0,ge.jsxs)("form",{ref:a,method:"post",action:"/chat",className:"so-home-ask","aria-label":"Ask the lead",onSubmit:()=>s(!0),children:[(0,ge.jsx)("input",{type:"hidden",name:"csrf",value:t}),(0,ge.jsx)("input",{type:"hidden",name:"request",value:i.current}),e.project!==null&&(0,ge.jsx)("input",{type:"hidden",name:"project",value:e.project}),(0,ge.jsx)("input",{type:"hidden",name:"message",value:n}),(0,ge.jsx)(ed,{id:"home-ask",label:"Ask the lead",placeholder:e.placeholder,value:n,onChange:o,onSend:l,line:!0,sendLabel:"Ask the lead",disabled:r})]})}function V4({view:e}){let t=yJ(e),a=e.groups.find(f=>f.key==="you")?.rows[0]??t[0]??null,[n,o]=(0,Ga.useState)(a?.id??null),r=(0,Ga.useRef)(null);(0,Ga.useEffect)(()=>{(n===null||!t.some(f=>f.id===n))&&o(a?.id??null)},[e]);let s=t.find(f=>f.id===n)??null,i=s!==null&&e.groups.some(f=>f.key==="you"&&f.rows.includes(s)),l=f=>{let d=t.findIndex(m=>m.id===n),c=t[Math.max(0,Math.min(t.length-1,d+f))];c&&(o(c.id),r.current?.querySelector(`[data-row="${CSS.escape(c.id)}"]`)?.focus())},u=e.scopes&&(0,ge.jsx)("nav",{className:"k-seg","aria-label":"Project",children:e.scopes.map(f=>(0,ge.jsx)("a",{href:f.href,"aria-current":f.active?"page":void 0,children:f.label},f.key||"all"))});return(0,ge.jsxs)("div",{className:"so-home","data-kit-page":!0,"data-home":!0,children:[(0,ge.jsx)(tn,{title:"Home",right:(0,ge.jsxs)(ge.Fragment,{children:[u,(0,ge.jsx)(He,{sm:!0,lead:"plus",label:"New task",href:e.newTask})]})}),e.empty?(0,ge.jsxs)("section",{className:"so-hello so-hello-empty",children:[(0,ge.jsx)("p",{className:"so-say","data-home-say":!0,children:e.empty.title}),(0,ge.jsx)("p",{className:"so-hello-x",children:e.empty.text}),e.setup&&(0,ge.jsx)("p",{className:"so-hello-x","data-home-setup":!0,children:(0,ge.jsx)("a",{className:"k-link",href:e.setup,children:"Finish setup"})}),(0,ge.jsx)(He,{variant:"primary",label:"New task",lead:"plus",href:e.newTask,className:"k-desk-only"})]}):(0,ge.jsxs)(ge.Fragment,{children:[(0,ge.jsxs)("section",{className:"so-hello","aria-label":"At a glance",children:[(0,ge.jsx)("p",{className:"so-say","data-home-say":!0,children:e.say}),e.setup&&(0,ge.jsx)("p",{className:"so-hello-x","data-home-setup":!0,children:(0,ge.jsx)("a",{className:"k-link",href:e.setup,children:"Finish setup"})}),(0,ge.jsx)("div",{className:"so-counts",children:e.counts.map(f=>(0,ge.jsxs)("a",{className:"so-count",href:f.href,"data-home-count":f.key,children:[(0,ge.jsxs)("span",{className:"so-count-k",children:[f.key==="needs"&&(0,ge.jsx)("span",{className:"k-dot needs","aria-hidden":"true"}),f.label]}),(0,ge.jsx)("span",{className:`so-count-v k-num${f.value===0?" zero":""}`,children:f.value})]},f.key))})]}),(0,ge.jsxs)("div",{className:"so-triage",children:[(0,ge.jsxs)("div",{className:"so-tri-list",ref:r,role:"listbox","aria-label":"Waiting on you, working and done",onKeyDown:f=>{(f.key==="ArrowDown"||f.key==="ArrowUp")&&(f.preventDefault(),l(f.key==="ArrowDown"?1:-1))},children:[e.groups.length===0&&(0,ge.jsx)("p",{className:"so-tri-none",children:"Nothing is waiting on you, working or done this week."}),e.groups.map(f=>(0,ge.jsxs)("div",{role:"group","aria-label":f.label,children:[(0,ge.jsx)("p",{className:"so-tri-g","aria-hidden":"true",children:f.label}),f.rows.map(d=>(0,ge.jsxs)("a",{className:"so-ti",href:d.href,role:"option","aria-selected":d.id===n,"data-row":d.id,tabIndex:d.id===n?0:-1,onClick:c=>{!Ns()&&!c.metaKey&&!c.ctrlKey&&!c.shiftKey&&(c.preventDefault(),o(d.id))},onFocus:()=>{Ns()||o(d.id)},children:[(0,ge.jsx)("span",{className:"so-ti-t",children:d.title}),(0,ge.jsxs)("span",{className:"so-ti-m",children:[(0,ge.jsx)($e,{word:d.chip.word,tone:d.chip.tone}),d.project&&(0,ge.jsx)("span",{children:d.project}),(0,ge.jsx)("span",{className:"k-num",children:d.age})]}),f.key==="working"&&d.line&&(0,ge.jsx)("span",{className:"so-ti-d",children:d.line})]},d.id))]},f.key)),e.more&&(0,ge.jsx)("p",{className:"so-tri-more",children:(0,ge.jsxs)("a",{className:"k-link",href:e.more.href,children:[e.more.count," more in Tasks"]})})]}),(0,ge.jsx)("section",{className:"so-tri-open k-desk-only","aria-label":"Selected","aria-live":"polite",children:(0,ge.jsx)(wJ,{row:s,waits:i})})]})]}),e.ask&&(0,ge.jsx)("div",{className:"so-home-ask-dock k-desk-only",children:(0,ge.jsx)(kJ,{ask:e.ask})}),(0,ge.jsx)(_o,{children:(0,ge.jsx)(He,{variant:"primary",lead:"plus",label:"New task",href:e.newTask})})]})}var Uy=O(he(),1);var Kn=O(he(),1);var xa=O(he(),1),Q4=O(xr(),1);var M1="toolroll.chime",K4="toolroll.chime.v2",SJ="toolroll.chime.heard",G4="toolroll-chime";function CJ(e){return e.flatMap(t=>t.asks)}var Id=()=>{try{return window.localStorage}catch{return null}};function D1(){try{return Id()?.getItem(M1)==="1"}catch{return!1}}function W4(e){try{e?Id()?.setItem(M1,"1"):Id()?.removeItem(M1)}catch{}}var X4=/^[A-Za-z0-9_-]{8,64}$/;function Y4(){try{Id()?.removeItem(SJ)}catch{}try{let e=JSON.parse(Id()?.getItem(K4)??"null"),t={};for(let[a,n]of Object.entries(e?.keys??{}))X4.test(a)&&typeof n=="number"&&(t[a]=n);return{since:typeof e?.since=="number"?e.since:0,keys:t}}catch{return{since:0,keys:{}}}}function j4(e,t){let a=Y4(),n=t-2592e6;for(let[o,r]of Object.entries(a.keys))r<n&&(delete a.keys[o],a.since=Math.max(a.since,r));for(let o of e)X4.test(o)&&(a.keys[o]=t);try{Id()?.setItem(K4,JSON.stringify(a))}catch{}}function LJ(e,t){return Object.hasOwn(t.keys,e.key)||t.since>0&&Date.parse(e.at)<=t.since}function NJ(){try{let e=window.AudioContext??window.webkitAudioContext;if(e===void 0)return;let t=new e;[880,1175].forEach((a,n)=>{let o=t.createOscillator(),r=t.createGain(),s=t.currentTime+n*.12;o.frequency.value=a,r.gain.setValueAtTime(1e-4,s),r.gain.exponentialRampToValueAtTime(.12,s+.02),r.gain.exponentialRampToValueAtTime(1e-4,s+.22),o.connect(r).connect(t.destination),o.start(s),o.stop(s+.25)}),window.setTimeout(()=>{t.close()},1e3)}catch{}}async function IJ(e){let t=navigator.locks;if(t===void 0){e();return}await t.request(G4,()=>{e()})}function Z4(e=NJ,t=()=>({visible:document.visibilityState==="visible",task:null,run:null})){let a=null,n=new Set,o=null;try{o=typeof BroadcastChannel>"u"?null:new BroadcastChannel(G4)}catch{o=null}return o!==null&&(o.onmessage=r=>{let s=r.data?.showing;typeof s=="string"&&n.add(s)}),{see(r){let s=CJ(r),i=a;a=new Set(s.map(d=>d.key));let l=t(),u=s.filter(d=>l.visible&&(d.task!==null&&d.task===l.task||d.run!==null&&d.run===l.run)).map(d=>d.key);for(let d of u)n.add(d),o?.postMessage({showing:d});if(i===null){j4(s.map(d=>d.key),Date.now());return}let f=s.filter(d=>!i.has(d.key));f.length!==0&&window.setTimeout(()=>{IJ(()=>{let d=Y4(),c=f.filter(m=>!LJ(m,d));j4(f.map(m=>m.key),Date.now()),D1()&&c.some(m=>!n.has(m.key))&&e()})},200)},close(){o?.close()}}}var ce=O(G(),1);function _1(e){if(e.needsYou)return{...e.needsYou};let t=e.navigation.find(n=>n.label==="Home"||n.label==="Tasks"),a=t?.count??0;return{count:a,saturated:!1,scope:null,label:t?.countLabel??`${a} ${a===1?"needs":"need"} you`,href:"/tasks?view=needs-you"}}var jn={from:void 0,value:null,listeners:new Set};function J4(e,t){if(!(jn.value===null||jn.value.href!==e||jn.value.count===t)){jn.value={...jn.value,count:t,label:jn.value.label.replace(/^\d+\+?\s+needs?\b/,`${t} ${t===1?"needs":"need"}`),saturated:!1};for(let a of[...jn.listeners])a()}}function bm(e){jn.from!==e.needsYou&&(jn.from=e.needsYou,jn.value=_1(e));let[,t]=(0,xa.useState)(0);return(0,xa.useEffect)(()=>{let a=()=>t(n=>n+1);return jn.listeners.add(a),()=>{jn.listeners.delete(a)}},[]),jn.value??_1(e)}async function TJ(e){try{let t=new URL(e,window.location.origin);t.searchParams.set("format","workspace");let a=await fetch(t.pathname+t.search,{credentials:"same-origin",cache:"no-store",headers:{accept:"application/json"},signal:AbortSignal.timeout(12e3)});if(!a.ok||a.redirected)return;let n=await a.json();n.view?.kind==="tasks"&&typeof n.view.needsYou=="number"&&J4(e,n.view.needsYou)}catch{}}function e5(e,t){let a=(0,xa.useRef)(!0);(0,xa.useEffect)(()=>{if(a.current){a.current=!1;return}if(e.sensitive||t===null)return;let n=(jn.value??_1(e)).href,o=window.setTimeout(()=>{TJ(n)},400);return()=>window.clearTimeout(o)},[t])}var RJ={Home:"home",Tasks:"tasks",Flows:"flows",Agents:"agents",Projects:"projects",Settings:"settings"},Fy="so:open-search",t5=e=>{window.dispatchEvent(new CustomEvent(Fy,{detail:e??null}))};function AJ(){return(0,ce.jsxs)("a",{className:"so-rail-brand",href:"/",children:[(0,ce.jsxs)("span",{className:"so-brand-mark","aria-hidden":"true",children:[(0,ce.jsx)("i",{}),(0,ce.jsx)("i",{}),(0,ce.jsx)("i",{})]}),"Toolroll"]})}function a5({workspace:e,needs:t}){return(0,ce.jsx)(ce.Fragment,{children:e.navigation.map(a=>{let n=a.label==="Home"&&t.count>0;return(0,ce.jsxs)("a",{className:"so-nav",href:a.href,"aria-current":a.active?"page":void 0,children:[(0,ce.jsx)(Ye,{name:RJ[a.label]??"more"}),(0,ce.jsx)("span",{className:"so-nav-l",children:a.label}),n&&(0,ce.jsxs)(ce.Fragment,{children:[(0,ce.jsxs)("span",{className:"k-count ink",title:t.label,"data-needs-count":!0,children:[t.count,t.saturated?"+":""]}),(0,ce.jsx)("span",{className:"k-sr",children:`, ${t.label}`})]})]},a.href)})})}function n5({workspace:e,states:t,current:a}){let n=t!==null&&t.length>0?t.filter(o=>o.path!==null&&!o.others).map(o=>({key:o.path,name:o.name,href:o.href,needs:0})):e.projects.map(o=>({key:o.path,name:o.name,href:o.href,needs:0}));if(n.length===0)return null;for(let o of n)o.needs=e.needsYouByProject?.find(r=>r.path===o.key)?.count??0;return(0,ce.jsxs)("nav",{"aria-label":"Projects",className:"so-rail-projects","data-live":!0,"data-sidebar-slot":"projects",children:[(0,ce.jsx)("p",{className:"so-rail-h",children:"Projects"}),n.map(o=>(0,ce.jsxs)("a",{className:"so-nav so-nav-sub",href:o.href,"aria-current":o.key===a?"true":void 0,title:o.name,children:[(0,ce.jsx)("span",{className:"so-pdot","aria-hidden":"true"}),(0,ce.jsx)("span",{className:"so-nav-l",children:o.name}),o.needs>0&&!e.sensitive&&(0,ce.jsx)("span",{className:"so-nav-n k-num","aria-label":`${o.needs} ${o.needs===1?"needs":"need"} you`,children:o.needs})]},o.key))]})}function o5({workspace:e}){let t=(0,xa.useRef)(null),[a,n]=(0,xa.useState)(D1),o=r=>{let s=[...e.usage&&!e.sensitive?[{label:`Plan use · ${e.usage.text}`,act:()=>{window.location.assign(e.usage.href)}}]:[],...!e.sensitive&&e.projectStates!==void 0?[{label:a?"Turn the chime off":"Chime when something needs me",act:()=>{W4(!a),n(!a)}}]:[],{label:"Sign out",act:()=>{t.current?.requestSubmit()}}];dr(r,e.user||"Account",s)};return(0,ce.jsxs)("div",{className:"so-acct",children:[(0,ce.jsxs)("div",{className:"so-acct-row",children:[(0,ce.jsx)("span",{className:"so-av","aria-hidden":"true",children:(e.user||"?").slice(0,1).toUpperCase()}),(0,ce.jsx)("span",{className:"so-acct-name",title:e.user,children:e.user}),(0,ce.jsx)(se,{variant:"ghost",sm:!0,iconOnly:"more",label:"Account",onClick:r=>o(r.currentTarget)})]}),(0,ce.jsx)("div",{"data-live":!0,"data-sidebar-slot":"chips",children:e.fresh&&!e.sensitive?(0,ce.jsxs)(Ae,{action:e.fresh.forget,className:"so-acct-note","data-fresh-chip":!0,children:[(0,ce.jsx)("input",{type:"hidden",name:"return",value:e.path}),(0,ce.jsx)("span",{children:"Password remembered"}),(0,ce.jsxs)("span",{children:[e.fresh.minutes," min left"]}),(0,ce.jsx)(se,{variant:"ghost",sm:!0,type:"submit",label:"Forget",className:"so-acct-forget"})]}):e.passwordless?(0,ce.jsx)("p",{className:"so-acct-note",children:"Passwordless is on"}):null}),(0,ce.jsx)(Ae,{action:"/logout",ref:t,hidden:!0})]})}function r5({workspace:e,states:t,current:a}){let n=bm(e);return(0,ce.jsxs)("nav",{className:"so-rail","aria-label":"Main",children:[(0,ce.jsxs)("div",{className:"so-rail-top",children:[(0,ce.jsx)(AJ,{}),(0,ce.jsx)("span",{className:"k-grow"}),(0,ce.jsx)("a",{className:"k-btn k-btn-ghost k-btn-sm k-btn-icon",href:"/tasks/new","aria-label":"New task",title:"New task",children:(0,ce.jsx)(Ye,{name:"pen"})})]}),(0,ce.jsxs)("a",{className:"so-nav",href:"/search","data-rail-search":!0,onClick:o=>{e.sensitive||o.metaKey||o.ctrlKey||(o.preventDefault(),t5(o.currentTarget))},children:[(0,ce.jsx)(Ye,{name:"search"}),(0,ce.jsx)("span",{className:"so-nav-l",children:"Search"}),(0,ce.jsx)("kbd",{className:"so-kbd","aria-hidden":"true",children:"⌘K"})]}),(0,ce.jsx)(a5,{workspace:e,needs:n}),(0,ce.jsx)(n5,{workspace:e,states:e.sensitive?null:t,current:a}),(0,ce.jsx)("span",{className:"k-grow"}),(0,ce.jsx)(o5,{workspace:e})]})}function qy({className:e,label:t,trigger:a,dim:n=!0,onClose:o,children:r}){let s=(0,xa.useRef)(null),i=(0,xa.useRef)(o);return i.current=o,(0,xa.useLayoutEffect)(()=>{let l=s.current;if(!l)return;let u=!1,f=Do(l,a,{dim:n,onClose:()=>{u=!0,i.current()}});return()=>{u||f()}},[a,n]),(0,Q4.createPortal)((0,ce.jsx)("div",{ref:s,className:e,role:"dialog","aria-modal":"true","aria-label":t,tabIndex:-1,children:r}),document.body)}function EJ({workspace:e,trigger:t,onClose:a,states:n,current:o}){let r=bm(e);return(0,ce.jsxs)(qy,{className:"k-sheet so-nav-sheet",label:"Navigation",trigger:t,onClose:a,children:[(0,ce.jsxs)("div",{className:"k-sheet-h",children:[(0,ce.jsx)("div",{className:"k-sheet-ht",children:(0,ce.jsxs)("h2",{children:[(0,ce.jsxs)("span",{className:"so-brand-mark","aria-hidden":"true",children:[(0,ce.jsx)("i",{}),(0,ce.jsx)("i",{}),(0,ce.jsx)("i",{})]}),"Toolroll"]})}),(0,ce.jsx)(se,{variant:"ghost",iconOnly:"x",label:"Close","data-k-close":""})]}),(0,ce.jsxs)("div",{className:"k-sheet-b so-nav-sheet-b",children:[(0,ce.jsxs)("a",{className:"so-nav",href:"/tasks/new",children:[(0,ce.jsx)(Ye,{name:"plus"}),(0,ce.jsx)("span",{className:"so-nav-l",children:"New task"})]}),(0,ce.jsx)(a5,{workspace:e,needs:r}),(0,ce.jsx)(n5,{workspace:e,states:e.sensitive?null:n,current:o}),(0,ce.jsx)(o5,{workspace:e})]})]})}function s5({workspace:e,title:t,back:a,states:n,current:o,trailing:r}){let[s,i]=(0,xa.useState)(null);return(0,ce.jsxs)("header",{className:"so-ph",children:[a?(0,ce.jsx)("a",{className:"k-btn k-btn-ghost k-btn-icon",href:a,"aria-label":"Back",title:"Back",children:(0,ce.jsx)(Ye,{name:"back"})}):(0,ce.jsx)(se,{variant:"ghost",iconOnly:"menu",label:"Open navigation","aria-haspopup":"dialog",onClick:l=>i(l.currentTarget)}),(0,ce.jsx)("p",{className:"so-ph-t",children:t}),r,!e.sensitive&&(0,ce.jsx)(se,{variant:"ghost",iconOnly:"search",label:"Search",onClick:l=>t5(l.currentTarget)}),s&&(0,ce.jsx)(EJ,{workspace:e,trigger:s,onClose:()=>i(null),states:n,current:o})]})}var MJ={decide:"Decision",review:"Result",unblock:"Blocked"};async function DJ(e){let t=new URL(e,window.location.origin);t.searchParams.set("format","workspace");let a=await fetch(t.pathname+t.search,{credentials:"same-origin",cache:"no-store",headers:{accept:"application/json"},signal:AbortSignal.timeout(12e3)});if(!a.ok||a.redirected)throw new Error("unavailable");let o=(await a.json()).view;if(!o||o.kind!=="tasks")throw new Error("unavailable");let r=s=>s in Pk?Pk[s]:"Waiting on you";return J4(e,o.needsYou),{rows:o.rows.map(s=>({id:s.id,title:s.title,href:s.href,project:s.project,age:s.age,group:r(s.group),word:s.chip??(s.status.label==="Needs you"?MJ[s.group]??s.status.label:s.status.label)})),more:o.pages.next!==null}}function _J({needs:e,trigger:t,onClose:a}){let[n,o]=(0,xa.useState)({state:"loading"});(0,xa.useEffect)(()=>{let s=!0;return DJ(e.href).then(i=>{s&&o({state:"ready",...i})},()=>{s&&o({state:"failed"})}),()=>{s=!1}},[e.href]);let r=[];if(n.state==="ready")for(let s of n.rows){let i=r.find(l=>l.label===s.group);i?i.rows.push(s):r.push({label:s.group,rows:[s]})}return(0,ce.jsxs)(qy,{className:"k-sheet so-needs-sheet",label:"Needs you",trigger:t,onClose:a,children:[(0,ce.jsxs)("div",{className:"k-sheet-h",children:[(0,ce.jsxs)("div",{className:"k-sheet-ht",children:[(0,ce.jsxs)("h2",{children:["Needs you ",(0,ce.jsx)(Ct,{n:e.count,ink:!0})]}),(0,ce.jsx)(ea,{children:e.label})]}),(0,ce.jsx)(se,{variant:"ghost",iconOnly:"x",label:"Close","data-k-close":""})]}),(0,ce.jsxs)("div",{className:"k-sheet-b",children:[n.state==="loading"&&(0,ce.jsx)("p",{className:"so-sheet-line",role:"status",children:"Loading…"}),n.state==="failed"&&(0,ce.jsxs)("p",{className:"so-sheet-line",role:"alert",children:["Couldn’t load the list. ",(0,ce.jsx)("a",{className:"k-link",href:e.href,children:"Open it in Tasks"})]}),n.state==="ready"&&n.rows.length===0&&(0,ce.jsx)("p",{className:"so-sheet-line",children:"Nothing needs you."}),r.map(s=>(0,ce.jsxs)("div",{children:[(0,ce.jsx)("p",{className:"so-tri-g",children:s.label}),s.rows.map(i=>(0,ce.jsxs)("a",{className:"so-ti",href:i.href,children:[(0,ce.jsx)("span",{className:"so-ti-t",children:i.title}),(0,ce.jsxs)("span",{className:"so-ti-m",children:[(0,ce.jsx)($e,{word:i.word,tone:"ask"}),i.project&&(0,ce.jsx)("span",{children:i.project}),(0,ce.jsx)("span",{className:"k-num",children:i.age})]})]},i.id))]},s.label)),n.state==="ready"&&n.more&&(0,ce.jsx)("p",{className:"so-sheet-line",children:(0,ce.jsx)("a",{className:"k-link",href:e.href,children:"See them all in Tasks"})})]})]})}function i5({workspace:e}){let t=bm(e),[a,n]=(0,xa.useState)(null),o=(0,xa.useCallback)(()=>n(null),[]);return t.count===0?null:(0,ce.jsxs)("div",{className:"so-dock","data-needs-dock":!0,children:[(0,ce.jsx)(X_,{count:t.count,label:t.label,scope:t.scope===null?"All projects":t.label,onOpen:r=>n(r.currentTarget)}),a&&(0,ce.jsx)(_J,{needs:t,trigger:a,onClose:o})]})}var Et=O(G(),1),PJ=[["Models","/settings/models","Settings → Agents and models","planner builder reviewer opus sonnet haiku codex model per phase"],["Lead and subagents","/settings/lead","Settings → Agents and models","lead chat subagent"],["Tools","/settings/tools","Settings → Agents and models","mcp"],["Knowledge","/settings/knowledge","Settings → Agents and models","instructions project knowledge"],["Skills","/settings/skills","Settings → Agents and models","skill tests"],["Learning","/settings/learning","Settings → Agents and models","lessons"],["Chat apps","/settings/alerts#chat-apps","Settings → Chat apps and alerts","telegram slack discord teams phone"],["Operating mode","/mode","Settings → Approvals and safety","hands-off mode"],["Approval rules","/settings/approval","Settings → Approvals and safety","automatic approval auto-approve"],["Policy","/settings/policy","Settings → Approvals and safety","protected paths"],["Checks","/settings/checks","Settings → Approvals and safety","tests release check"],["Pull requests","/settings/pull-requests","Settings → Projects","github publish merge"],["People","/people","Settings → People and sign-in","invite roles members"],["Sessions and tokens","/settings/sessions","Settings → People and sign-in","api token"],["Sign-in with a provider","/settings/sign-in","Settings → People and sign-in","sso oauth github google"],["Passwordless","/settings/passwordless","Settings → People and sign-in","password"],["Audit log","/ledger","Settings → People and sign-in","history ledger action ledger"],["Updates","/settings/updates","Settings → System","version upgrade"],["Backups","/settings/backups","Settings → System","backup restore"],["Storage","/settings/storage","Settings → System","disk checkouts"],["Retention","/settings/retention","Settings → System"],["Monitoring","/settings/monitoring","Settings → System","traces otel audit stream"],["Data export","/settings/data","Settings → System","export zip"],["Integrations","/settings/integrations","Settings → System","webhooks"],["Spend","/spend","Settings → Spend","monthly limits budget cap cost usage"],["Terminals","/term","Agents","shell console"]],OJ=[["Recipes","/flows/new","Flows → New flow","recipe one-time work"],["Kits","/kits","Flows → New flow","kit starter"],["Limits","/spend","Spend → Monthly limits","budget"],["Live","/agents","Agents","live view peek"],["Builders","/agents#computers","Agents → Computers that build","builder computers runner fleet"],["System","/agents","Agents","agents per phase"],["Board","/tasks?view=board","Tasks → Board","kanban"],["Inbox","/tasks?view=needs-you","Tasks → Needs you","waiting"],["Queue","/tasks?view=order","Tasks → Board","order"],["Done","/tasks?view=completed","Tasks → Finished","finished complete"],["Runs","/agents","Agents → Finished","builds attempts history"],["Activity","/","Home","morning summary"],["Workspace tools","/menu","Settings","menu"],["All settings","/settings","Settings"]],l5={attention:"needs",ready:"needs",live:"live",done:"done",problem:"failed",muted:"",neutral:""};function $y(e){let t=a=>a===null?"":e.projects.find(n=>n.path===a)?.name??a.split(/[\\/]/).filter(Boolean).pop()??"";return[...e.crew.map(a=>{let n=l5[a.tone]==="needs";return{kind:"task",title:a.title,sub:[t(a.project),a.label].filter(Boolean).join(" · "),href:a.resultHref??a.href,chip:{word:a.label,tone:n?"ask":l5[a.tone]??""},also:a.id,needs:n}}),...e.projects.map(a=>({kind:"project",title:a.name,sub:"Project",href:a.href})),...(e.chats??[]).map(a=>({kind:"chat",title:a.title,sub:a.kind==="task"?"Task chat":"Project chat",href:a.href})),...e.navigation.map(a=>({kind:"page",title:a.label,sub:"",href:a.href})),{kind:"page",title:"Chat with the lead",sub:"Home",href:"/chat",also:"lead ask"},...PJ.map(([a,n,o,r])=>({kind:"setting",title:a,sub:o,href:n,...r?{also:r}:{}})),...OJ.map(([a,n,o,r])=>({kind:"page",title:a,sub:`Now ${o}`,href:n,legacy:!0,...r?{also:r}:{}}))]}var c5=(e,t)=>{let a=`${e.title} ${e.sub} ${e.also??""}`.toLowerCase();return t.every(n=>a.includes(n))},u5=(e,t)=>{let a=e.title.toLowerCase();return a.startsWith(t)?0:a.includes(t)?1:2},P1={task:"Tasks",project:"Projects",chat:"Chats",setting:"Settings",page:"Go to",action:"Actions"};function BJ(e,t){let a=t.trim().toLowerCase(),n=$y(e),o=[{kind:"action",title:"New task",sub:a?"Describe the change on the next page":"Describe a change in a sentence",href:"/tasks/new"},{kind:"action",title:"Ask the lead",sub:a?`“${t.trim()}”`:"A question about your projects",href:a?`/chat?draft=${encodeURIComponent(t.trim())}`:"/chat"}];if(a==="")return[...n.filter(l=>l.kind==="task"&&l.needs).slice(0,4),...o,...n.filter(l=>l.kind==="page"&&!l.legacy)];let r=a.split(/\s+/),s=n.filter(l=>c5(l,r)),i=s.filter(l=>l.kind==="setting"||l.kind==="page").map((l,u)=>[l,u]).sort((l,u)=>u5(l[0],a)-u5(u[0],a)||l[1]-u[1]).map(([l])=>l).slice(0,5);return[...s.filter(l=>l.kind==="task").slice(0,5),...s.filter(l=>l.kind==="project").slice(0,3),...s.filter(l=>l.kind==="chat").slice(0,3),...i,...o]}function d5({workspace:e}){let[t,a]=(0,Kn.useState)(!1);return(0,Kn.useEffect)(()=>{if(e.sensitive)return;let n=r=>{!(r.metaKey||r.ctrlKey)||r.altKey||r.key.toLowerCase()!=="k"||r.target instanceof Element&&r.target.closest('input, textarea, select, [contenteditable="true"], [role="textbox"]')&&!r.target.closest(".so-cmdk")||(r.preventDefault(),a(s=>s===!1?document.activeElement instanceof HTMLElement?document.activeElement:null:!1))},o=r=>{if(window.location.pathname==="/search"){document.getElementById("search-page-q")?.focus();return}a(r.detail??null)};return window.addEventListener("keydown",n),window.addEventListener(Fy,o),()=>{window.removeEventListener("keydown",n),window.removeEventListener(Fy,o)}},[e.sensitive]),e.sensitive||t===!1?null:(0,Et.jsx)(zJ,{workspace:e,trigger:t,onClose:()=>a(!1)})}function zJ({workspace:e,trigger:t,onClose:a}){let[n,o]=(0,Kn.useState)(""),[r,s]=(0,Kn.useState)(0),i=(0,Kn.useId)(),l=(0,Kn.useRef)(null),u=(0,Kn.useMemo)(()=>BJ(e,n),[e,n]),f=u.filter(y=>y.kind!=="action").length,d=n.trim()===""?0:$y(e).filter(y=>c5(y,n.trim().toLowerCase().split(/\s+/))).length;(0,Kn.useEffect)(()=>{s(0)},[n]),(0,Kn.useEffect)(()=>{l.current?.querySelector(`[data-index="${r}"]`)?.scrollIntoView({block:"nearest"})},[r]);let c=y=>{y&&window.location.assign(y.href)},m=`/search${n.trim()?`?q=${encodeURIComponent(n.trim())}`:""}`,h=null;return(0,Et.jsxs)(qy,{className:"so-cmdk",label:"Search",trigger:t,onClose:a,children:[(0,Et.jsxs)("div",{className:"so-cmdk-h",children:[(0,Et.jsx)(Ye,{name:"search"}),(0,Et.jsx)("label",{className:"k-sr",htmlFor:`${i}-q`,children:"Search tasks, projects, chats and settings"}),(0,Et.jsx)(Na,{id:`${i}-q`,className:"so-cmdk-in",type:"search",autoFocus:!0,autoComplete:"off",spellCheck:!1,placeholder:"Search or type a command",role:"combobox","aria-expanded":"true","aria-controls":i,"aria-activedescendant":u.length>0?`${i}-${r}`:void 0,value:n,onChange:y=>o(y.target.value),onKeyDown:y=>{(y.key==="ArrowDown"||y.key==="ArrowUp")&&(y.preventDefault(),u.length&&s(b=>(b+(y.key==="ArrowDown"?1:u.length-1))%u.length)),y.key==="Enter"&&!y.nativeEvent.isComposing&&(y.preventDefault(),c(u[r]))}}),(0,Et.jsx)(se,{variant:"ghost",sm:!Ns(),iconOnly:"x",label:"Close",className:"so-cmdk-x","data-k-close":""})]}),(0,Et.jsxs)("div",{className:"so-cmdk-list",id:i,role:"listbox","aria-label":"Results",ref:l,children:[n.trim()!==""&&f===0&&(0,Et.jsxs)("p",{className:"so-cmdk-none",children:["Nothing here matches “",n.trim(),"”. See all results to look through older tasks too."]}),u.map((y,b)=>{let g=n.trim()===""&&y.kind==="task"?"Needs you":P1[y.kind],x=g!==h?(0,Et.jsx)("p",{className:"so-cmdk-g",role:"presentation",children:g}):null;return h=g,(0,Et.jsxs)("div",{children:[x,(0,Et.jsxs)("a",{id:`${i}-${b}`,className:"so-cmdk-i",role:"option","aria-selected":b===r,"data-index":b,href:y.href,onMouseMove:()=>{b!==r&&s(b)},children:[(0,Et.jsxs)("span",{className:"so-cmdk-t",children:[y.kind==="action"&&(0,Et.jsx)(Ye,{name:y.title==="New task"?"plus":"arrow",small:!0}),(0,Et.jsx)("span",{children:y.title})]}),y.chip&&(0,Et.jsx)($e,{word:y.chip.word,tone:y.chip.tone}),y.sub&&(0,Et.jsx)("span",{className:"so-cmdk-s",children:y.sub})]})]},`${y.kind}:${y.href}:${y.title}`)})]}),(0,Et.jsxs)("div",{className:"so-cmdk-f",children:[(0,Et.jsxs)("span",{className:"k-desk-only",children:[(0,Et.jsx)("kbd",{className:"so-kbd",children:"↑"}),(0,Et.jsx)("kbd",{className:"so-kbd",children:"↓"})," move"]}),(0,Et.jsxs)("span",{className:"k-desk-only",children:[(0,Et.jsx)("kbd",{className:"so-kbd",children:"↵"})," open"]}),(0,Et.jsx)("span",{className:"k-grow"}),(0,Et.jsx)("a",{className:"k-link",href:m,children:d>f?`See all ${d} results`:"See all results"})]})]})}var gt=O(G(),1);function f5({view:e,workspace:t}){let[a,n]=(0,Uy.useState)(e.q),o=a.trim().toLowerCase().split(/\s+/).filter(Boolean),r=(0,Uy.useMemo)(()=>t===null||o.length===0?[]:$y(t).filter(u=>u.kind!=="task"&&o.every(f=>`${u.title} ${u.sub} ${u.also??""}`.toLowerCase().includes(f))),[t,a]),s=e.q.trim().toLowerCase()===a.trim().toLowerCase()?e.tasks:e.tasks.filter(u=>o.every(f=>`${u.title} ${u.id}`.toLowerCase().includes(f))),i=["project","chat","setting","page"];return(0,gt.jsxs)("div",{className:"so-search","data-kit-page":!0,"data-search":!0,children:[(0,gt.jsx)(tn,{title:"Search",right:null}),(0,gt.jsx)("div",{className:"so-search-bar",children:(0,gt.jsxs)("form",{action:"/search",method:"get",role:"search",className:"so-search-box",onSubmit:u=>{a.trim()===""&&u.preventDefault()},children:[(0,gt.jsx)(Ye,{name:"search",small:!0}),(0,gt.jsx)("label",{className:"k-sr",htmlFor:"search-page-q",children:"Search"}),(0,gt.jsx)(Na,{id:"search-page-q",className:"so-search-in",type:"search",name:"q",value:a,onChange:u=>n(u.target.value),placeholder:"Search tasks, projects, chats and settings",autoComplete:"off",spellCheck:!1,autoFocus:!0})]})}),o.length===0?(0,gt.jsx)(Ua,{title:"Search everything in this Toolroll.",text:"Tasks, including finished and archived ones, projects, chats, every page and setting, and the old names of things."}):s.length===0&&r.length===0?(0,gt.jsx)(Ua,{title:`Nothing matches “${a.trim()}” here.`,text:e.truncated?"Search reads your 100 most recent tasks and 40 most recent archived ones, so an older task may not show. Every task is in Tasks.":"Search looks in task titles and ids, projects, chats, pages and settings.",...e.truncated?{action:(0,gt.jsx)(He,{sm:!0,label:"Open every task in Tasks",href:"/tasks?view=all"})}:{}}):(0,gt.jsxs)("div",{className:"so-search-results","aria-live":"polite",children:[s.length>0&&(0,gt.jsxs)(gt.Fragment,{children:[(0,gt.jsxs)("h2",{className:"k-grp",children:["Tasks",(0,gt.jsx)(Ct,{n:s.length})]}),s.map(u=>(0,gt.jsx)(xn,{href:u.href,chip:(0,gt.jsx)($e,{word:u.chip.word,tone:u.chip.tone}),title:u.title,desc:u.archived?"Archived":"",meta:(0,gt.jsxs)(gt.Fragment,{children:[u.project&&(0,gt.jsx)("span",{children:u.project}),(0,gt.jsx)("span",{className:"k-num",children:u.age})]})},u.id))]}),e.truncated&&(0,gt.jsxs)("p",{className:"so-search-note",children:["Search reads your 100 most recent tasks and 40 most recent archived ones. ",(0,gt.jsx)("a",{className:"k-link",href:"/tasks?view=all",children:"Every task is in Tasks"}),"."]}),i.map(u=>{let f=r.filter(d=>d.kind===u);return f.length===0?null:(0,gt.jsxs)("div",{children:[(0,gt.jsxs)("h2",{className:"k-grp",children:[P1[u],(0,gt.jsx)(Ct,{n:f.length})]}),f.map(d=>(0,gt.jsx)(xn,{href:d.href,chip:null,title:d.title,desc:d.sub},`${d.href}:${d.title}`))]},u)})]})]})}var hr=O(G(),1),HJ=(e,t,a)=>(0,hr.jsx)(vS,{selected:e,csrf:t,inTask:{current:a}},`${e.taskId}:${e.build??""}`);function p5({view:e,csrf:t,taskChat:a=null,taskDetails:n=!0,workspace:o=null}){return(0,hr.jsx)("div",{"data-view":e.kind,className:"w-full",children:e.kind==="tasks"?(0,hr.jsx)(FP,{view:e}):e.kind==="task"?(0,hr.jsx)(EP,{view:e,chat:a,details:n,csrf:t,result:HJ}):e.kind==="projects"?(0,hr.jsx)(DP,{view:e,csrf:t}):e.kind==="result"?(0,hr.jsx)(OP,{view:e,csrf:t}):e.kind==="flow"?(0,hr.jsx)(w4,{view:e,csrf:t}):e.kind==="agents"?(0,hr.jsx)(U4,{view:e}):e.kind==="home"?(0,hr.jsx)(V4,{view:e}):e.kind==="search"?(0,hr.jsx)(f5,{view:e,workspace:o}):null})}function m5(e){return e.security?`Toolroll ${e.version} is available, with security fixes`:`Toolroll ${e.version} is available`}function h5(e){return e==="/settings"||e.startsWith("/settings/")||e==="/setup"||e.startsWith("/setup/")||e==="/people"||e==="/mode"||e==="/control"||e==="/spend"}var pt=O(G(),1);function Hs({name:e}){return(0,pt.jsx)("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",width:"20",height:"20",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",children:{menu:(0,pt.jsx)("path",{d:"M4 6h16M4 12h16M4 18h16"}),chat:(0,pt.jsx)("path",{d:"M5 4h14a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H9l-6 3V6a2 2 0 0 1 2-2Z"}),tasks:(0,pt.jsx)(pt.Fragment,{children:(0,pt.jsx)("path",{d:"m3 6 2 2 4-4m-6 9 2 2 4-4m-6 9 2 2 4-4M13 6h8M13 13h8M13 20h8"})}),agents:(0,pt.jsxs)(pt.Fragment,{children:[(0,pt.jsx)("rect",{width:"18",height:"14",x:"3",y:"5",rx:"2"}),(0,pt.jsx)("path",{d:"m7 10 3 2-3 2M13 14h4"})]}),flows:(0,pt.jsxs)(pt.Fragment,{children:[(0,pt.jsx)("rect",{width:"8",height:"8",x:"3",y:"3",rx:"2"}),(0,pt.jsx)("path",{d:"M7 11v4a2 2 0 0 0 2 2h4"}),(0,pt.jsx)("rect",{width:"8",height:"8",x:"13",y:"13",rx:"2"})]}),projects:(0,pt.jsx)("path",{d:"M3 7V5a2 2 0 0 1 2-2h5l3 4h6a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V7Z"}),knowledge:(0,pt.jsx)("path",{d:"M12 5c-3-2-7-2-10-1v15c3-1 7-1 10 1 3-2 7-2 10-1V4c-3-1-7-1-10 1Zm0 0v15"}),settings:(0,pt.jsxs)(pt.Fragment,{children:[(0,pt.jsx)("path",{d:"M4 6h16M4 12h16M4 18h16"}),(0,pt.jsx)("path",{d:"M8 3v6M16 9v6M10 15v6"})]}),arrow:(0,pt.jsx)("path",{d:"m10 6-6 6 6 6M4 12h16"}),close:(0,pt.jsx)("path",{d:"m6 6 12 12M6 18 18 6"}),send:(0,pt.jsx)("path",{d:"m12 19 0-14m-6 6 6-6 6 6"}),tools:(0,pt.jsx)(pt.Fragment,{children:(0,pt.jsx)("path",{d:"M4 4h6v6H4zM14 4h6v6h-6zM4 14h6v6H4zM14 14h6v6h-6z"})}),plus:(0,pt.jsx)("path",{d:"M12 5v14M5 12h14"})}[e]})}var ra=O(he(),1);var xe=O(G(),1),FJ=[["support-desk","Support desk"],["bug-triage","Bug triage"],["sales-follow-up","Sales follow-up"],["ops-requests","Ops requests"]],g5={task:{title:"Ask about this task",hint:"Questions, changes and next steps. Actions come back as cards you confirm.",placeholder:"Ask about this task…",suggestions:["Where does this task stand?","Move this forward","Request changes: "]},result:{title:"Ask about this result",hint:"Ask what changed or why, or request a revision. Actions come back as cards you confirm.",placeholder:"Ask about this result…",suggestions:["Summarize what changed","What does the check log say?","Request changes: "]},tasks:{title:"Ask about this project",hint:"Plan work, file tasks and check progress. Actions come back as cards you confirm.",placeholder:"Ask about this project…",suggestions:["What needs my attention here?","What should we build next?","File a task: "]}},v5={lead:["What needs my attention right now?","What should we work on next?","File a task: ","Make a flow for "],tasks:["What needs my attention here?","What should we build next?","File a task: ","Make a flow for "]},w5="New conversation — the projects I can reach changed";function k5(e,t){if(e.role!=="assistant"||t?.role!=="operator")return null;let a=Date.parse(e.createdAt)-Date.parse(t.createdAt);return!Number.isFinite(a)||a<0||a>=60*6e4?null:a<6e4?`${Math.max(1,Math.round(a/1e3))} s`:`${Math.round(a/6e4)} min`}function qJ(e,t){for(let a=t-1;a>=0;a--)if(e[a].role==="operator")return e[a].text.trim()||null;return null}var $J=e=>e.trim().replace(/:$/,"…").replace(/ (for|to)$/," $1…");function S5({at:e}){let t=io();return(0,xe.jsx)("time",{className:"lc-time",dateTime:e,title:Pl(e,t),children:tr(e,new Date,t)})}async function C5(e){try{return await navigator.clipboard.writeText(e),!0}catch{return!1}}function y5({label:e,act:t,ariaLabel:a}){let[n,o]=(0,ra.useState)(null),r=(0,ra.useRef)(0);return(0,ra.useEffect)(()=>()=>window.clearTimeout(r.current),[]),(0,xe.jsx)(se,{variant:"ghost",sm:!0,className:"lc-act","aria-label":n??a,label:n??e,onClick:()=>{t().then(s=>{s!==null&&(o(s),window.clearTimeout(r.current),r.current=window.setTimeout(()=>o(null),1600))})}})}function UJ(e,t){(0,ra.useLayoutEffect)(()=>{e.current?.querySelectorAll("pre").forEach(a=>{if(a.parentElement?.classList.contains("lc-code"))return;let n=document.createElement("div");n.className="lc-code";let o=document.createElement("button");o.type="button",o.className="lc-codecopy",o.dataset.codeCopy="",o.setAttribute("aria-label","Copy code"),o.textContent="Copy",a.replaceWith(n),n.append(o,a)})},[e,t])}var VJ=e=>{let t=e.target.closest("[data-code-copy]"),a=t?.nextElementSibling?.textContent;!t||a==null||C5(a).then(n=>{t.textContent=n?"Copied":"Couldn't copy",window.setTimeout(()=>{t.textContent="Copy"},1600)})};function x5({message:e,onEdit:t,arrived:a=!1}){return(0,xe.jsxs)("article",{className:a?"lc-msg lc-you lc-new":"lc-msg lc-you","data-message-id":e.id,"aria-label":"You",children:[(0,xe.jsx)("div",{className:"lc-bubble",children:(0,xe.jsx)(St,{html:e.html})}),(0,xe.jsxs)("div",{className:"lc-meta",children:[(0,xe.jsx)(S5,{at:e.createdAt}),t&&(0,xe.jsx)(se,{variant:"ghost",sm:!0,className:"lc-act",label:"Edit","aria-label":"Edit: put these words back in the message box",onClick:t})]})]})}function b5({message:e,workspace:t,onChanged:a,took:n,retry:o,arrived:r=!1}){let s=(0,ra.useRef)(null),[i,l]=(0,ra.useState)(null);UJ(s,e.html);let u=t.leadName??"Lead",f=o===null;return(0,xe.jsxs)("article",{className:r?"lc-msg lc-lead lc-new":"lc-msg lc-lead","data-message-id":e.id,"aria-label":u,children:[(0,xe.jsxs)("header",{className:"lc-who",children:[(0,xe.jsx)(Cv,{}),(0,xe.jsx)("b",{children:u}),(0,xe.jsx)(S5,{at:e.createdAt})]}),e.activity&&(0,xe.jsxs)("p",{className:"lc-activity","data-activity":!0,children:[n===null?"Worked":`Worked ${n}`," · ",e.activity]}),(0,xe.jsx)("div",{className:"lc-body",ref:s,onClick:VJ,children:(0,xe.jsx)(St,{html:e.html})}),e.cards!==void 0&&e.cards.length>0?(0,xe.jsx)(td,{look:"row",cards:e.cards,csrf:t.csrf,onChanged:a,readOnly:f}):e.cardsHtml&&(0,xe.jsx)(St,{html:e.cardsHtml,className:"so-message-cards lc-cards-html"}),!f&&(0,xe.jsxs)("div",{className:"lc-meta",children:[(0,xe.jsx)(y5,{label:"Copy",ariaLabel:`Copy ${u}'s answer`,act:async()=>await C5(e.text)?"Copied":"Couldn't copy"}),(0,xe.jsx)(y5,{label:"Retry",ariaLabel:"Retry: ask the same question again",act:async()=>{let d=await o();return l(d),d===null?"Sent":null}})]}),i!==null&&(0,xe.jsx)("p",{className:"lc-said k-err",role:"alert",children:i})]})}function jJ(){let{isAtBottom:e,scrollToBottom:t}=Kf();return(0,xe.jsx)(se,{variant:"outline",iconOnly:"chevron",label:"Jump to the latest message",className:e?"lc-jump":"lc-jump show",tabIndex:e?-1:0,"aria-hidden":e?!0:void 0,onClick:()=>{t({animation:"instant"})}})}function O1({title:e,text:t,children:a}){return(0,xe.jsxs)("div",{className:"lc-empty","data-chat-empty":!0,children:[(0,xe.jsx)(Cv,{}),(0,xe.jsx)("h2",{children:e}),t!==""&&(0,xe.jsx)("p",{children:t}),a]})}function z1({controller:e,docked:t=null}){let{workspace:a,draft:n,notice:o,storageAvailable:r,sending:s,stale:i,offline:l}=e,u=a.conversation,f=t===null?null:g5[t]??g5.task,d=(0,ra.useRef)(null),c=(0,ra.useRef)(null),m=u.pendingTurnId!==null,h=a.leadName??"Lead",y=t??(u.taskId?"task":u.project?"tasks":"lead"),b=eS[y]??eS.lead,g=/^\/(\w*)$/.exec(n.text)?.[1]?.toLowerCase(),[x,v]=(0,ra.useState)(0),[w,k]=(0,ra.useState)(!1),C=g===void 0||w?[]:b.filter(X=>X.command.startsWith(g)),N=(0,ra.useId)(),[S,T]=(0,ra.useState)(!1),[q,z]=(0,ra.useState)("idle"),U=()=>requestAnimationFrame(()=>{let X=d.current;X&&(X.focus(),X.setSelectionRange(X.value.length,X.value.length))}),$=X=>{T(!1),e.edit(X)},L=X=>{$(X.text),v(0),U()},I=Sv(u,m||n.pending!==null&&!s,()=>{e.check()}),R=s||i||l||n.pending!==null,A=l?"Offline. Your draft stays in this tab.":s?"Sending…":S?"":o;(0,ra.useEffect)(()=>{f||window.location.hash!==""||!matchMedia("(pointer: fine) and (min-width: 761px)").matches||document.activeElement!==null&&document.activeElement!==document.body||d.current?.focus({preventScroll:!0})},[]),(0,ra.useEffect)(()=>{m||z("idle")},[m]);let[H,M]=(0,ra.useState)(null),_=async X=>{T(!1),await e.send(X)==="refused"&&T(!0)},F=async()=>{if(!(u.pendingTurnId===null||q==="busy")){z("busy");try{let X=await fetch("/chat/mate/stop",{method:"POST",credentials:"same-origin",redirect:"manual",headers:Wt({}),body:new URLSearchParams({csrf:a.csrf,turn:String(u.pendingTurnId),return:window.location.pathname+window.location.search})});z(X.type==="opaqueredirect"||X.ok?"idle":"The lead didn't stop. Try again.")}catch{z("The lead didn't stop. Check your connection and try again.")}e.check()}},Q=f?[]:u.previous?.messages??[],ue=(0,ra.useRef)(new Set(u.messages.map(X=>X.id))),oe=u.messages.length===0&&Q.length===0,Z=u.project?a.projects.find(X=>X.path===u.project)?.name??u.project.split("/").filter(Boolean).at(-1)??u.project:null,ne=!f&&!u.project&&!u.taskId&&u.sessionId!==0&&u.messages.length>0,le=X=>{if(C.length===0)return;let de=Math.min(x,C.length-1);if(X.key==="ArrowDown"||X.key==="ArrowUp"){X.preventDefault(),v((de+(X.key==="ArrowDown"?1:C.length-1))%C.length);return}if(X.key==="Enter"&&!X.shiftKey||X.key==="Tab"){X.preventDefault(),L(C[de]);return}X.key==="Escape"&&(X.preventDefault(),k(!0))},K=r?n.text.length>u.maxChars-200?`${n.text.length} / ${u.maxChars}`:null:"Draft stays on this page only.",B=X=>(0,xe.jsx)("div",{className:"lc-sugs",role:"list",children:X.map(de=>(0,xe.jsx)(se,{role:"listitem",variant:"outline",sm:!0,className:"lc-sug",label:$J(de),onClick:()=>{$(de),U()}},de))});return(0,xe.jsxs)("div",{className:f?"so-lead-chat lc lc-docked":"so-lead-chat lc","data-workspace-chat":!0,children:[!f&&(0,xe.jsx)(tn,{title:"Chat",ctx:[h,Z].filter(Boolean).join(" · "),right:(0,xe.jsxs)(xe.Fragment,{children:[ne&&(0,xe.jsxs)(Ae,{action:"/chat/mate/end",className:"lc-tb-form",children:[(0,xe.jsx)("input",{type:"hidden",name:"return",value:"/chat"}),(0,xe.jsx)(se,{type:"submit",variant:"ghost",sm:!0,lead:"plus",label:"New chat",title:"End this conversation and start a new one"})]}),(0,xe.jsx)(He,{variant:"ghost",sm:!0,href:"/settings/lead",label:"Lead settings"})]})}),(0,xe.jsxs)(dA,{className:"so-conversation lc-scroll",children:[(0,xe.jsxs)(fA,{className:"lc-thread",children:[!f&&a.firstRun&&(0,xe.jsx)(wv,{firstRun:a.firstRun}),!f&&!a.home&&a.catchUpHtml&&(0,xe.jsx)(St,{html:a.catchUpHtml,className:"so-catch-up lc-brief"}),Q.length>0&&(0,xe.jsxs)(xe.Fragment,{children:[(0,xe.jsx)("section",{className:"lc-previous","aria-label":"Earlier conversation","data-previous-thread":!0,children:Q.map(X=>X.role==="operator"?(0,xe.jsx)(x5,{message:X,onEdit:null},X.id):(0,xe.jsx)(b5,{message:X,workspace:a,took:null,retry:null,onChanged:()=>{e.check()}},X.id))}),(0,xe.jsx)("p",{className:"lc-divider",role:"separator","data-thread-divider":!0,children:(0,xe.jsx)("span",{children:w5})})]}),oe&&(f?(0,xe.jsx)(O1,{title:f.title,text:f.hint,children:B(f.suggestions)}):a.firstRun?!m&&(0,xe.jsx)(O1,{title:"What should we work on?",text:a.firstRun.intro??"",children:(0,xe.jsx)(J_,{firstRun:{...a.firstRun,intro:""},onDraft:X=>{$(Q_(n.text,X)),U()}})}):(0,xe.jsxs)(O1,{title:"What should we work on?",text:`${h} reads ${Z??"your projects"}, files tasks and opens what needs you. Nothing is built until you approve its plan.`,children:[B(v5[y]??v5.lead),!Z&&(0,xe.jsxs)("nav",{className:"lc-kits","aria-label":"Starter kits","data-kit-links":!0,children:[(0,xe.jsx)("span",{children:"Or start from a kit:"}),FJ.map(([X,de])=>(0,xe.jsx)("a",{href:`/kits/${X}`,children:de},X))]})]})),(0,xe.jsxs)("div",{id:"chat-thread",className:"lc-messages","data-chat-region":"thread",children:[u.messages.map((X,de)=>{if(X.role==="operator")return(0,xe.jsx)(x5,{message:X,arrived:!ue.current.has(X.id),onEdit:()=>{$(X.text),U()}},X.id);let fe=qJ(u.messages,de);return(0,xe.jsx)(b5,{message:X,workspace:a,arrived:!ue.current.has(X.id),took:k5(X,u.messages[de-1]),onChanged:()=>{e.check()},retry:fe===null?null:()=>e.steer(fe)},X.id)}),(m||I!==null)&&(0,xe.jsx)(Lv,{look:"lead",live:I,leadName:h}),!m&&I===null&&u.failure&&(0,xe.jsx)("p",{className:"so-live-failed",role:"alert","data-lead-failed":!0,children:u.failure})]})]}),(0,xe.jsx)(jJ,{})]}),(0,xe.jsxs)("div",{className:"so-composer-area lc-dock",children:[A&&(0,xe.jsxs)("div",{className:"lc-connection",role:i?"alert":"status",children:[(0,xe.jsx)("span",{children:A}),i?(0,xe.jsx)(se,{variant:"outline",sm:!0,onClick:e.reconnect,label:"Reconnect"}):!s&&!l&&(0,xe.jsx)(se,{variant:"ghost",sm:!0,onClick:()=>{e.check()},label:"Check again"})]}),q!=="idle"&&q!=="busy"&&(0,xe.jsx)("p",{className:"lc-said k-err",role:"alert",children:q}),(0,xe.jsxs)(Ae,{ref:c,onSubmit:X=>{_(X)},action:"/chat","data-workspace-composer":!0,"aria-busy":s,className:"lc-form",children:[C.length>0&&(0,xe.jsx)("ul",{id:N,role:"listbox","aria-label":"Commands",className:"lc-slash",children:C.map((X,de)=>(0,xe.jsxs)("li",{role:"option","aria-selected":de===Math.min(x,C.length-1),onMouseDown:fe=>{fe.preventDefault(),L(X)},children:[(0,xe.jsxs)("span",{className:"lc-slash-name",children:["/",X.command]}),(0,xe.jsx)("span",{className:"lc-slash-hint",children:X.hint})]},X.command))}),(0,xe.jsx)(ed,{id:"lead-chat",textareaId:"lead-message",name:"message",maxLength:u.maxChars,label:"Message your lead",textareaRef:d,placeholder:f?.placeholder??(Z?`Ask about ${Z}…`:"Message your lead…"),value:n.text,onChange:X=>{k(!1),$(X)},onSend:()=>c.current?.requestSubmit(),submit:!0,sendDisabled:R,sendLabel:m?"Queue message":"Send message",working:m&&n.text.trim()==="",onStop:()=>{F()},stopLabel:q==="busy"?"Stopping…":"Stop the lead",...!f&&!u.taskId?{project:{current:Z??B1,sub:h,items:[B1,...a.projects.map(X=>X.name)]},onProject:X=>{if(X===B1){u.project&&window.location.assign("/chat");return}let de=a.projects.find(fe=>fe.name===X);de&&de.path!==u.project&&window.location.assign(`/chat?project=${encodeURIComponent(de.path)}`)}}:{},...!f&&a.controlsHtml?{menu:[{label:"Conversation settings",act:()=>M(document.querySelector('[data-k-composer="lead-chat"] .k-composer-plus'))}]}:{},combobox:C.length>0?{expanded:!0,controls:N}:null,onKeyDown:le,enterSends:X=>H1()||X.metaKey||X.ctrlKey,note:K,error:S&&o?o:null})]}),!f&&a.controlsHtml&&H&&(0,xe.jsx)(co,{kind:"popover",title:"Conversation settings",trigger:H,onClose:()=>M(null),children:(0,xe.jsx)(St,{html:a.controlsHtml,immutable:!0,className:"lc-settings"})})]})]})}var B1="All projects",KJ="(hover: none) and (pointer: coarse) and (max-width: 900px)";function H1(){return!document.documentElement.hasAttribute("data-mobile-keyboard")&&!matchMedia(KJ).matches}var V=O(G(),1);function Vy(){try{return window.sessionStorage}catch{return{getItem:()=>null,removeItem:()=>{},setItem:()=>{throw new Error("Storage unavailable")}}}}function jy(e){let t=e.conversation;return t?{user:e.user,session:t.sessionId,task:t.taskId??(t.project?`project:${t.project}`:null)}:null}function F1(){return!document.hidden&&navigator.onLine!==!1}var GJ=new Set(["/tasks","/tasks/archive","/agents","/code"]);function WJ(e){let[t,a]=(0,De.useState)(e),n=jy(e),[o,r]=(0,De.useState)(()=>{let A=e.conversation&&n?wA(Vy(),n,e.conversation.requestId,e.conversation.maxChars):Dc(""),H=e.conversation?new URLSearchParams(window.location.search).get("draft"):null;return H&&A.text===""&&A.pending===null?{...A,text:H.slice(0,e.conversation.maxChars)}:A});(0,De.useEffect)(()=>{let A=new URL(window.location.href);A.searchParams.has("draft")&&(A.searchParams.delete("draft"),window.history.replaceState(window.history.state,"",A.pathname+A.search+A.hash))},[]);let[s,i]=(0,De.useState)(""),[l,u]=(0,De.useState)(!0),[f,d]=(0,De.useState)(!1),[c,m]=(0,De.useState)(!1),[h,y]=(0,De.useState)(()=>navigator.onLine===!1),b=(0,De.useRef)({workspace:t,draft:o,stale:c,sending:f,notice:s});b.current={workspace:t,draft:o,stale:c,sending:f,notice:s};let g=(0,De.useRef)(!1),x=(0,De.useRef)(!1),v=(0,De.useRef)(null),w=(0,De.useRef)(null),k=(0,De.useCallback)(()=>{w.current!==null&&clearTimeout(w.current),w.current=null},[]),C=(0,De.useRef)(!0),N=(0,De.useRef)(!1),S=(0,De.useRef)(null),T=(0,De.useCallback)(A=>{b.current.draft=A,r(A);let H=jy(b.current.workspace);H&&u(X0(Vy(),H,A))},[]),q=e.view?.kind==="task"&&e.view.live!=null&&!e.sensitive,z=(e.view?.kind==="agents"||e.view?.kind==="home")&&!e.sensitive,U=!!(e.conversation||e.refreshSeconds||z),$=(0,De.useCallback)(async(A=!0,H=!1)=>{if(k(),!C.current||b.current.stale||!(U||q)||!F1())return;if(g.current){x.current=!0;return}x.current=!1,g.current=!0;let M=b.current.draft.pending?.request??null;try{let _=await TA(b.current.workspace,M,fetch,{etag:v.current,force:A});if(!C.current)return;if(v.current=M?null:_.etag,_.kind==="unchanged"){!b.current.draft.pending&&b.current.notice&&i("");return}let F=_.workspace,Q=S.current??(M!==null&&F.receipt?.request===M&&F.receipt.received?F.conversation?.sessionId??null:null);if(!IA(b.current.workspace,F,Q)){if(b.current.workspace.conversation?.sessionId===0&&N.current)return;b.current.stale=!0,m(!0),i("This conversation changed or ended. Reconnect to continue with your draft.");return}let ue=CA(b.current.draft,M,F.receipt),oe=jy(b.current.workspace),Z=b.current.workspace.conversation?.sessionId!==F.conversation?.sessionId;b.current.workspace=F,(ue!==b.current.draft||Z)&&T(ue),Z&&oe&&X0(Vy(),oe,Dc("")),a(F),i(ue.pending?"Delivery is not confirmed. Check again before sending another message.":"")}catch(_){if(!C.current)return;_ instanceof Pr&&(b.current.stale=!0,m(!0)),i(_ instanceof Error?_.message:"Updates are unavailable. Your work is still saved."),!H&&!b.current.stale&&F1()&&(w.current=setTimeout(()=>{w.current=null,$(!0,!0)},2e3))}finally{g.current=!1,x.current&&C.current&&!b.current.stale&&F1()&&(x.current=!1,$(!0))}},[e,U,q,T,k]);hn(U&&!c?"workspace":null,A=>{A==="change"||A==="reload"?$(!1):A==="lost"&&$(!0)}),(0,De.useEffect)(()=>{if(!q&&!z)return;let A=()=>{$(!0)};return window.addEventListener(Fi,A),()=>{window.removeEventListener(Fi,A)}},[$,q,z]),(0,De.useEffect)(()=>{if(C.current=!0,!U&&!q)return()=>{C.current=!1};let A=()=>{document.hidden?k():$(!0)},H=()=>{y(!1),$()},M=()=>{k(),y(!0)};return document.addEventListener("visibilitychange",A),window.addEventListener("online",H),window.addEventListener("offline",M),()=>{C.current=!1,k(),document.removeEventListener("visibilitychange",A),window.removeEventListener("online",H),window.removeEventListener("offline",M)}},[$,U,q,k]),(0,De.useEffect)(()=>{c&&k()},[c,k]);let L=async(A,H=null)=>{A.preventDefault();let M=b.current;if(N.current||M.stale||navigator.onLine===!1||M.draft.pending||!M.draft.text.trim())return"skipped";let _=SA(M.draft);if(!_.pending)return"skipped";N.current=!0,d(!0),T(_),i("");try{let F=await RA(M.workspace,_.pending,fetch,H);return M.workspace.conversation?.sessionId===0&&F.session!==void 0&&(S.current=F.session),C.current?F.refused?(T(NA(b.current.draft,_.pending.request)),i(F.message??"Message not sent. Your draft is saved."),"refused"):F.queued===!0?(T(LA(b.current.draft,_.pending.request)),i("Queued: it goes to the lead when it finishes."),$(),"queued"):(i("Checking delivery…"),$(),"accepted"):F.refused?"refused":F.queued===!0?"queued":"accepted"}catch(F){return C.current&&(F instanceof Pr&&(b.current.stale=!0,m(!0)),i(F instanceof Pr?F.message:"Delivery is not confirmed. Check again before sending another message."),$()),"unconfirmed"}finally{N.current=!1,C.current&&d(!1)}},I=()=>{let A=jy(b.current.workspace);A&&kA(Vy(),A,b.current.draft.text),window.location.reload()};return(0,De.useEffect)(()=>{let A=M=>{let _=M.target;if(!(_ instanceof HTMLFormElement)||_.dataset.workspaceComposer!==void 0||_.getAttribute("action")!=="/chat")return;let F=b.current;if(!F.workspace.conversation)return;if(F.stale||N.current||F.draft.pending||navigator.onLine===!1){M.preventDefault(),i("Wait for the current message before sending another.");return}if(_.getAttribute("aria-busy")==="true"){M.preventDefault();return}let Q=(ue,oe)=>{if(_.querySelector(`[name="${ue}"]`))return;let Z=document.createElement("input");Z.type="hidden",Z.name=ue,Z.value=oe,_.append(Z)};Q("request",F.workspace.conversation.requestId),Q("request-session",String(F.workspace.conversation.sessionId)),F.workspace.conversation.taskId&&Q("task",F.workspace.conversation.taskId),F.workspace.conversation.resultRunId!==null&&Q("result",String(F.workspace.conversation.resultRunId)),!M.defaultPrevented&&(N.current=!0,_.setAttribute("aria-busy","true"))},H=()=>{N.current=!1,document.querySelectorAll('form[action="/chat"][aria-busy="true"]:not([data-workspace-composer])').forEach(M=>M.removeAttribute("aria-busy")),$()};return document.addEventListener("submit",A),window.addEventListener("pageshow",H),()=>{document.removeEventListener("submit",A),window.removeEventListener("pageshow",H)}},[$]),{workspace:t,draft:o,notice:s,storageAvailable:l,sending:f,stale:c,offline:h,send:L,check:$,reconnect:I,steer:async A=>{let H=b.current;if(H.draft.text.trim()!==""||H.draft.pending)return"Send or clear the message you're writing first.";if(N.current||H.stale||navigator.onLine===!1)return"The conversation isn't connected. Try again in a moment.";T(Pg(H.draft,A));let M=b.current.draft.request,_=await L({preventDefault(){}});if(_==="queued")return null;if(_==="accepted")return await AA(()=>b.current.draft.pending?.request??null,M,()=>$())?null:"Delivery isn't confirmed. Check the chat for it before sending it again.";let F=b.current.draft;return F.pending===null&&F.text===A&&T(Pg(F,"")),_==="unconfirmed"?"Delivery isn't confirmed. Check the chat for it before sending it again.":"The lead didn't take it. The note above the message box says why."},edit:A=>T(Pg(b.current.draft,A))}}function XJ({at:e}){let t=DE(e);return t===""?null:(0,V.jsx)("time",{className:"so-work-age",dateTime:e,title:qi(e),children:t})}function q1({workspace:e,items:t}){return(0,V.jsx)("ul",{className:"so-work-list",children:t.map(a=>(0,V.jsx)("li",{"data-workspace-task":a.id,"data-work-status":a.state,children:(0,V.jsxs)("div",{className:"so-work-row",children:[(0,V.jsxs)("a",{className:"so-work-link",href:a.resultHref??a.href,"aria-current":e.focus?.id===a.id?"page":void 0,children:[(0,V.jsxs)("div",{className:"so-work-heading",children:[(0,V.jsx)(Us,{kind:cS(a.tone),className:"so-work-glyph"}),(0,V.jsx)("span",{className:"so-work-title",title:a.title,children:a.title}),(0,V.jsx)(XJ,{at:a.updatedAt})]}),(0,V.jsxs)("p",{className:"so-work-meta",children:[(0,V.jsx)("span",{className:"so-work-state","data-headline":a.label,children:a.label}),a.lead&&!a.detail?.includes(a.lead)&&(0,V.jsx)("span",{className:"so-work-project","data-crew-lead":!0,children:a.lead}),a.project&&(0,V.jsx)("span",{className:"so-work-project",children:e.projects.find(n=>n.path===a.project)?.name??a.project.split(/[\\/]/).filter(Boolean).pop()})]}),a.activity!==void 0&&(0,V.jsx)(Ev,{activity:a.activity,className:"so-work-activity text-caption"})]}),a.detail&&(0,V.jsx)("details",{className:"so-work-reason",children:(0,V.jsxs)("summary",{title:a.detail,children:[(0,V.jsx)("span",{children:a.detail}),(0,V.jsx)("svg",{"aria-hidden":"true",viewBox:"0 0 16 16",width:"12",height:"12",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:(0,V.jsx)("path",{d:"m4 6 4 4 4-4"})})]})},a.detail),a.action&&a.action.href!==(a.resultHref??a.href)&&(0,V.jsx)("a",{className:"so-work-action",href:a.action.href,children:a.action.label})]})},a.id))})}function YJ(e){let t=cS(e.tone);return t==="decide"||t==="failed"||t==="review"?"needs":t==="building"?"running":"waiting"}var ZJ=5,QJ=[{key:"needs",label:"Needs you",glyph:"decide"},{key:"running",label:"Running",glyph:"building"},{key:"waiting",label:"Waiting",glyph:"idle"}];function JJ({workspace:e}){let t=o=>o.tone==="done"||o.state==="cancelled",a=e.crew.filter(o=>!t(o)),n=e.crew.filter(t);return(0,V.jsxs)("section",{className:"so-crew","aria-labelledby":"crew-title","data-workspace-crew":!0,children:[(0,V.jsxs)("div",{className:"so-section-heading",children:[(0,V.jsx)("h2",{id:"crew-title",children:"Crew"}),(0,V.jsx)("a",{href:"/tasks",children:"All tasks"})]}),e.crew.length===0?(0,V.jsxs)("div",{className:"so-crew-empty",children:[(0,V.jsx)("p",{children:"No tasks yet."}),(0,V.jsx)("p",{children:"Work you start with the lead appears here."})]}):(0,V.jsxs)(V.Fragment,{children:[a.length===0&&(0,V.jsx)("p",{className:"so-crew-quiet",children:"Nothing is running or waiting on you."}),QJ.map(o=>{let r=a.filter(l=>YJ(l)===o.key);if(r.length===0)return null;let s=o.key==="running"?r.slice(0,ZJ):r,i=r.slice(s.length);return(0,V.jsxs)("div",{className:"so-crew-group","data-crew-group":o.key,children:[(0,V.jsxs)("h3",{className:"so-crew-group-title",children:[(0,V.jsx)(Us,{kind:o.glyph}),o.label,(0,V.jsx)("span",{children:r.length})]}),(0,V.jsx)(q1,{workspace:e,items:s}),i.length>0&&(0,V.jsx)(Qo,{summary:`${i.length} more running`,className:"so-crew-more",children:(0,V.jsx)(q1,{workspace:e,items:i})})]},o.key)}),n.length>0&&(0,V.jsx)(Qo,{summary:`Finished (${n.length}${e.crewTruncated?"+":""})`,className:"so-crew-finished",children:(0,V.jsx)(q1,{workspace:e,items:n})})]}),e.crewTruncated&&(0,V.jsx)("a",{className:"so-all-work",href:"/tasks",children:"View more tasks"})]})}var L5={"needs-you":"decide",failed:"failed",stuck:"unblock",paused:"idle",working:"building",waiting:"idle",done:"done",idle:"idle"};function eee(e){if(typeof e!="string")return null;let t;try{t=JSON.parse(e)}catch{return null}if(!Array.isArray(t))return null;let a=(o,r)=>typeof o=="string"&&o.length<=r,n=[];for(let o of t){if(o===null||typeof o!="object")return null;let{path:r,name:s,href:i,state:l,counts:u,tasks:f,more:d,others:c,asks:m}=o;if(!Array.isArray(m))return null;let h=[];for(let g of m){if(g===null||typeof g!="object")return null;let x=g;if(typeof x.key!="string"||!/^[A-Za-z0-9_-]{8,64}$/.test(x.key)||!(x.task===null||a(x.task,400))||!(x.run===null||typeof x.run=="number"&&Number.isInteger(x.run)&&x.run>0)||!a(x.at,64))return null;h.push({key:x.key,task:x.task,run:x.run,at:x.at})}if(c!==void 0&&c!==!0||!(r===null||a(r,4096))||!a(s,400)||!a(i,8192)||!i.startsWith("/")||!Bf.includes(l)||u===null||typeof u!="object"||!Array.isArray(f)||typeof d!="number"||!Number.isInteger(d)||d<0)return null;let y=Object.fromEntries(Bf.map(g=>[g,u[g]]));if(Object.values(y).some(g=>typeof g!="number"||!Number.isInteger(g)||g<0))return null;let b=[];for(let g of f){if(g===null||typeof g!="object")return null;let x=g;if(!a(x.id,400)||!a(x.title,2e3)||!a(x.href,8192)||!x.href.startsWith("/")||!Bf.includes(x.state)||!a(x.line,2e3))return null;b.push({id:x.id,title:x.title,href:x.href,state:x.state,line:x.line})}n.push({path:r,name:s,href:i,state:l,counts:y,tasks:b,more:d,asks:h,...c===!0?{others:!0}:{}})}return n}var tee=2e3,Zi={states:null,from:null,listeners:new Set};function $1(e){Zi.states=e;for(let t of[...Zi.listeners])t()}function A5(e){let t=e.sensitive||e.projectStates===void 0;!t&&Zi.from!==e.projectStates&&(Zi.from=e.projectStates,Zi.states=e.projectStates??null);let[,a]=(0,De.useState)(0),[n,o]=(0,De.useState)(!1);return(0,De.useEffect)(()=>{let r=()=>a(s=>s+1);return Zi.listeners.add(r),()=>{Zi.listeners.delete(r)}},[]),(0,De.useEffect)(()=>{if(!n)return;let r=window.setTimeout(()=>o(!1),tee);return()=>window.clearTimeout(r)},[n]),hn(t||n?null:"summary",(r,s)=>{if(r==="gone"){$1(null),o(!0);return}if(r==="lost"){$1(null);return}if(r!=="change")return;let i=eee(s.at);i!==null&&$1(i)},!0),t?null:Zi.states}function Pwe(e){return e?.reduce((t,a)=>t+a.counts["needs-you"],0)??0}function aee(e,t){let a=e.replace(/^\(\d+\+?\) /,"");return t>0?`(${t>99?"99+":t}) ${a}`:a}function nee({workspace:e}){let t=A5(e),a=bm(e).count;e5(e,t);let n=(0,De.useRef)(null);return(0,De.useEffect)(()=>(n.current=Z4(void 0,()=>{let o=new URL(window.location.href),r=o.pathname.startsWith("/t/")&&decodeURIComponent(o.pathname.slice(3).split("/")[0]??"")||null,s=o.pathname==="/agents"&&/^[1-9][0-9]{0,9}$/.test(o.searchParams.get("run")??"")?Number(o.searchParams.get("run")):null;return{visible:document.visibilityState==="visible",task:r,run:s}}),()=>{n.current?.close(),n.current=null}),[]),(0,De.useEffect)(()=>{t!==null&&n.current?.see(t)},[t]),(0,De.useEffect)(()=>{document.title=aee(document.title,a);let o=document.querySelector('link[rel="icon"][type="image/svg+xml"]');o!==null&&(o.href=a>0?"/icon-attention.svg":"/icon.svg")},[a,e.title]),null}function oee(e){return Bf.filter(t=>t!=="idle"&&e.counts[t]>0).map(t=>`${e.counts[t]} ${t==="needs-you"?e.counts[t]===1?"needs you":"need you":pg[t].toLowerCase()}`).join(" · ")}function Owe({states:e,current:t}){return(0,V.jsx)("nav",{"aria-label":"Projects now",className:"so-project-states","data-project-states":!0,children:e.map(a=>{let n=oee(a),o=a.path!==null&&a.path===t;return(0,V.jsxs)("div",{className:"so-project-state","data-project-state":a.state,"data-project-others":a.others?"":void 0,children:[(0,V.jsxs)("a",{href:a.href,"aria-current":o?"true":void 0,title:n===""?pg.idle:n,children:[(0,V.jsx)(Us,{kind:L5[a.state]}),(0,V.jsx)("span",{className:"so-project-state-name",children:a.name}),n!==""&&(0,V.jsx)("span",{className:"so-project-state-counts",children:n}),(0,V.jsx)("span",{className:"so-sr-only",children:pg[a.state]})]}),(o||a.path===null&&!a.others)&&a.tasks.length>0&&(0,V.jsxs)("ul",{className:"so-project-tasks",children:[a.tasks.map(r=>(0,V.jsx)("li",{"data-rail-task":r.state,children:(0,V.jsxs)("a",{href:r.href,title:r.title,children:[(0,V.jsx)(Us,{kind:L5[r.state]}),(0,V.jsx)("span",{className:"so-project-task-title",children:r.title}),(0,V.jsx)("span",{className:"so-project-task-line",children:r.line})]})},r.id)),a.more>0&&(0,V.jsx)("li",{children:(0,V.jsxs)("a",{className:"so-project-tasks-more",href:a.href,children:[a.more," more"]})})]})]},a.others?"(others)":a.path??"(none)")})})}function ree(e){let t=new URL(e.path,window.location.origin).searchParams,a=t.get("project")??t.get("repo")??e.crew.find(n=>n.id===e.focus?.id)?.project??e.openProject??null;return a===null?void 0:e.projects.find(n=>n.path===a)}var N5=[{id:"build",label:"Build",hint:"Changes come back for you to confirm"},{id:"plan",label:"Plan only",hint:"A plan only; nothing is filed"},{id:"answer",label:"Just answer",hint:"An answer only"}];function see(e){let{workspace:t,draft:a,notice:n,storageAvailable:o,sending:r,stale:s,offline:i}=e,l=t.conversation,u=(0,De.useRef)(null),f=(0,De.useId)(),[d,c]=(0,De.useState)("build"),m=l!==null&&!!l.taskId&&!t.team&&t.view?.kind==="task",h=l!==null&&l.pendingTurnId!==null,y=Sv(l,m&&(h||a.pending!==null&&!r),()=>{e.check()});if((0,De.useLayoutEffect)(()=>{let v=u.current;if(v){let w=matchMedia("(max-width: 760px)").matches;v.style.height=w?"0px":"auto",v.style.height=`${Math.min(180,Math.max(w?44:48,v.scrollHeight))}px`}},[a.text]),!m||l===null)return null;let b=r||s||i||a.pending!==null||!a.text.trim(),g=i?"Offline. Your draft stays in this tab.":r?"Sending…":n,x=N5.find(v=>v.id===d).hint;return{entries:l.messages.map(v=>({key:`message-${v.id}`,at:v.createdAt,node:(0,V.jsxs)("li",{"data-message-id":v.id,"data-thread-kind":"message",className:"so-thread-entry relative flex gap-3",children:[(0,V.jsx)("span",{"aria-hidden":"true",className:"relative z-[1] flex size-6 shrink-0 items-center justify-center rounded-full border border-border bg-card text-[10.5px] font-semibold text-muted-foreground",children:v.role==="operator"?"Y":(t.leadName??"Lead").slice(0,1).toUpperCase()}),(0,V.jsxs)("div",{className:"min-w-0 flex-1 pb-5 phone:pb-4",children:[(0,V.jsxs)("p",{className:"flex min-h-6 flex-wrap items-baseline gap-x-2 text-body leading-6",children:[(0,V.jsx)("span",{className:"font-medium",children:v.role==="operator"?"You":t.leadName??"Lead"}),(0,V.jsx)("time",{dateTime:v.createdAt,className:"ml-auto text-xs tabular-nums text-muted-foreground",children:qn(v.createdAt)})]}),(0,V.jsxs)(Mg,{className:v.role==="operator"?"so-thread-mine":"so-thread-theirs",children:[(0,V.jsx)(St,{html:v.html}),v.activity&&(0,V.jsx)(Qo,{summary:"Activity",children:(0,V.jsx)("p",{className:"so-activity-copy",children:v.activity})}),v.cards!==void 0&&v.cards.length>0?(0,V.jsx)(td,{cards:v.cards,csrf:t.csrf,onChanged:()=>{e.check()}}):v.cardsHtml&&(0,V.jsx)(St,{html:v.cardsHtml,className:"so-message-cards"})]})]})]},`message-${v.id}`)})),footer:(0,V.jsxs)("div",{className:"so-task-composer flex flex-col gap-2",children:[(h||y!==null)&&(0,V.jsx)(Lv,{live:y,leadName:t.leadName??"Lead"}),!h&&y===null&&l.failure&&(0,V.jsx)("p",{className:"so-live-failed",role:"alert","data-lead-failed":!0,children:l.failure}),g&&(0,V.jsxs)("div",{className:"so-connection",role:s?"alert":"status",children:[(0,V.jsx)("span",{children:g}),s?(0,V.jsx)(ie,{variant:"outline",size:"sm",onClick:e.reconnect,children:"Reconnect"}):!r&&!i&&(0,V.jsx)(ie,{variant:"ghost",size:"sm",onClick:()=>{e.check()},children:"Check again"})]}),(0,V.jsxs)(Ae,{onSubmit:v=>{e.send(v,d)},action:"/chat","data-workspace-composer":!0,"data-task-composer":!0,"aria-busy":r,className:"so-task-composer-box rounded-[28px] border border-transparent bg-composer px-4 pb-2.5 pt-3 transition-[border-color] duration-100 phone:px-3",children:[(0,V.jsx)("label",{htmlFor:"task-message",className:"sr-only",children:"Message the agent"}),(0,V.jsx)("textarea",{ref:u,id:"task-message",name:"message",rows:2,maxLength:l.maxChars,placeholder:"Message the agent: ask, or ask for a change",value:a.text,className:"block max-h-[180px] min-h-12 w-full resize-none px-0.5 pb-2 text-[16px] leading-relaxed outline-none placeholder:text-muted-foreground phone:min-h-11 phone:text-[17px]",onChange:v=>e.edit(v.target.value),onKeyDown:v=>{v.key==="Enter"&&!v.shiftKey&&!v.nativeEvent.isComposing&&(H1()||v.metaKey||v.ctrlKey)&&(v.preventDefault(),b||v.currentTarget.form?.requestSubmit())},"aria-describedby":"task-composer-hint"}),(0,V.jsxs)("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-2",children:[(0,V.jsx)("div",{role:"radiogroup","aria-label":"Mode",className:"so-mode-switch",children:N5.map(v=>(0,V.jsxs)("label",{className:"so-mode","data-mode":v.id,children:[(0,V.jsx)("input",{type:"radio",name:f,value:v.id,checked:d===v.id,onChange:()=>c(v.id)}),(0,V.jsx)("span",{children:v.label})]},v.id))}),(0,V.jsx)("span",{id:"task-composer-hint",className:"min-w-0 flex-1 truncate text-xs text-muted-foreground",children:o?a.text.length>l.maxChars-200?`${a.text.length} / ${l.maxChars}`:x:"Draft stays on this page only."}),(0,V.jsxs)(ie,{type:"submit",size:"sm",disabled:b,"aria-label":"Send message",className:pe("ml-auto"),children:[(0,V.jsx)(Hs,{name:"send"}),(0,V.jsx)("span",{children:"Send"})]})]})]})]})}}function I5({demo:e}){return e===void 0?null:(0,V.jsxs)(mn,{className:"so-demo-notice","data-demo-notice":!0,title:e.text,children:[(0,V.jsx)("span",{className:"so-demo-notice-full",children:e.text}),(0,V.jsx)("span",{className:"so-demo-notice-short",children:e.short})]})}function iee(){(0,De.useEffect)(()=>{let e=()=>{(window.scrollX!==0||window.scrollY!==0)&&window.scrollTo(0,0)},t=()=>{let n=decodeURIComponent(window.location.hash.slice(1)),o=n===""||n==="workspace-main"?null:document.getElementById(n);for(let r=o?.parentElement??null;r!==null;r=r.parentElement)r instanceof HTMLDetailsElement&&(r.open=!0);o?.scrollIntoView({block:"start"}),e()},a=requestAnimationFrame(t);return window.addEventListener("scroll",e,{passive:!0}),window.addEventListener("hashchange",t),()=>{cancelAnimationFrame(a),window.removeEventListener("scroll",e),window.removeEventListener("hashchange",t)}},[])}var lee=new Set(["tasks","task","agents","home","search","projects","flow"]),uee=/data-kit-page|class="k-ph"/;function cee(e){return e.team?!1:e.view!=null?lee.has(e.view.kind):e.conversation&&new URL(e.path,window.location.origin).pathname==="/chat"&&!e.focus&&!e.result?!0:!e.conversation&&uee.test(e.pageHtml??"")}function dee({initial:e}){let t=WJ(e);(0,De.useLayoutEffect)(()=>{J0(t.workspace.sensitive)},[t.workspace.sensitive]);let a=(0,De.useRef)(null),[n,o]=(0,De.useState)(e.team),r=n?.tasks?{...t.workspace,...uP(n.tasks,n.selected?.id)}:t.workspace,[s,i]=(0,De.useState)(r.result||r.focus?"work":"chat"),l=r.result?.runId??null;(0,De.useEffect)(()=>{l!==null&&Dg(l,r.csrf)},[l,r.csrf]);let u=r.focus!==null||r.result!==null,f=r.crew.find(F=>F.id===r.focus?.id),d=new URL(r.path,window.location.origin).pathname==="/chat",c=d?"Chat":r.navigation.find(F=>F.active)?.label??r.title.charAt(0).toUpperCase()+r.title.slice(1),m=!r.team&&r.view?.kind==="task"?r.view:null,h=!r.team&&r.conversation!==null&&r.view!=null&&m===null,[y,b]=(0,De.useState)("chat"),g=!r.team&&(!r.conversation||h||m!==null),x=see(t);(0,De.useEffect)(()=>{if(m===null)return;let F=()=>i("work");window.addEventListener("so:show-details",F);let Q=decodeURIComponent(window.location.hash.slice(1));return Q!==""&&document.getElementById(Q)?.closest("[data-task-details]")&&F(),()=>window.removeEventListener("so:show-details",F)},[m===null]);let v=new URL(r.path,window.location.origin).pathname,w=!r.team&&!r.conversation&&h5(v),k=cee(r),C=w&&!k,N=C||k||!u||g&&!h&&GJ.has(v),S=w?(r.crumbs??[]).filter(F=>F.href===null||F.href.startsWith("/")&&!F.href.startsWith("//")):[],[T,q]=(0,De.useState)(null),z=r.update!==void 0&&r.update.version!==T?r.update:null,U=r.demo,$=!r.team&&!(r.conversation&&!h&&m===null),[L,I]=(0,De.useState)(!1),R=d&&r.conversation!==null&&!h&&m===null&&!L?r.phone??null:null,A=A5(r),H=ree(r)?.path??null;(0,De.useEffect)(ok,[]),iee();let M=(0,De.useRef)(null),_=s==="work"&&u&&!h&&m===null&&!N;return(0,De.useEffect)(()=>{let F=M.current;if(!F)return;let Q=matchMedia("(max-width: 760px)"),ue=()=>F.toggleAttribute("inert",_&&Q.matches);return ue(),Q.addEventListener("change",ue),()=>{Q.removeEventListener("change",ue),F.removeAttribute("inert")}},[_]),(0,V.jsx)(so.Provider,{value:r.csrf,children:(0,V.jsxs)(Jo.Provider,{value:r.passwordless===!0,children:[(0,V.jsx)(dD,{}),(0,V.jsx)(nee,{workspace:r}),(0,V.jsxs)("div",{className:`so-workspace${N?" so-workspace--single":""}${k?" so-workspace--kit":""}${C?" so-workspace--settings":""}${h||m!==null&&!k?" so-workspace--docked":""}${m!==null&&!k?" so-workspace--details":""}`,"data-workspace-shell":!0,"data-workspace-phone-view":s,"data-workspace-has-result":r.result!==null,children:[(0,V.jsx)("a",{href:"#workspace-main",className:"so-skip-link",children:"Skip to content"}),(0,V.jsx)("aside",{className:"so-sidebar",children:(0,V.jsx)(r5,{workspace:r,states:A,current:H})}),(0,V.jsxs)("div",{ref:M,className:`so-main-column${d?" so-main-column--chat":""}`,children:[(0,V.jsx)(s5,{workspace:r,title:S.length>0?S[S.length-1].label:c,states:A,current:H,trailing:(0,V.jsxs)(V.Fragment,{children:[d&&u&&(0,V.jsx)(ie,{variant:"outline",size:"sm",className:"so-phone-work-button h-11 min-h-11",onClick:()=>i("work"),children:"Open work"}),h&&(0,V.jsxs)(ie,{variant:"outline",size:"sm",className:"so-phone-work-button h-11 min-h-11",onClick:()=>{b("chat"),i("work")},children:[(0,V.jsx)(Hs,{name:"chat"}),"Ask"]}),m!==null&&!k&&(0,V.jsx)(ie,{variant:"outline",size:"sm",className:"so-phone-work-button h-11 min-h-11","data-open-details":!0,onClick:()=>i("work"),children:"Task details"})]})}),!k&&(0,V.jsxs)("header",{className:"so-workspace-header",children:[S.length>0?(0,V.jsx)("nav",{className:"kit-crumbs so-header-title","aria-label":"Breadcrumb",children:(0,V.jsx)("ol",{children:S.map((F,Q)=>F.href===null?(0,V.jsx)("li",{"aria-current":"page",children:F.label},Q):(0,V.jsx)("li",{children:(0,V.jsx)("a",{href:F.href,children:F.label})},Q))})}):g||C?(0,V.jsx)("p",{className:"so-header-title",children:c}):(0,V.jsx)("h1",{children:d?r.leadName??"Lead":c}),r.focus&&d&&(0,V.jsx)("span",{className:"so-focus-label",title:r.focus.title,children:r.focus.title})]}),(r.notices.length>0||(r.signIn?.length??0)>0||z!==null||R!==null||r.reconnect!==void 0||U!==void 0&&!$)&&(0,V.jsxs)("div",{className:"so-workspace-notices",children:[!$&&(0,V.jsx)(I5,{demo:U}),r.reconnect!==void 0&&(0,V.jsx)(mn,{className:"so-update","data-reconnect":r.reconnect.kind,children:r.reconnect.kind==="password"?(0,V.jsxs)("p",{children:[(0,V.jsx)("span",{children:"Toolroll restarted"})," · ",(0,V.jsx)("a",{href:r.reconnect.href,children:"Reconnect"})]}):(0,V.jsx)("p",{children:(0,V.jsxs)("span",{children:["Toolroll restarted. Run ",(0,V.jsx)("code",{children:r.reconnect.command})," to reconnect."]})})}),r.signIn?.map(F=>(0,V.jsxs)(mn,{className:"so-sign-in","data-sign-in":F.provider,children:[(0,V.jsx)("p",{className:"so-sign-in-title",children:F.title}),(0,V.jsxs)("p",{className:"so-sign-in-detail",children:["Run ",(0,V.jsx)("code",{children:F.command})," on this computer, then resume.",F.detail===""?"":` ${F.detail}`]}),(0,V.jsx)(Ae,{action:F.resumeHref,children:(0,V.jsx)(ie,{className:"max-[761px]:h-11 max-[761px]:min-h-11",size:"sm",type:"submit",children:F.resumeLabel})})]},F.provider)),r.notices.map((F,Q)=>(0,V.jsx)(mn,{children:F},Q)),z!==null&&(0,V.jsxs)(mn,{className:"so-update","data-update":z.version,children:[(0,V.jsxs)("p",{children:[(0,V.jsx)("span",{children:m5(z)})," · ",(0,V.jsx)("a",{href:z.href,children:"What's new"})]}),(0,V.jsxs)(Ae,{action:z.dismissHref,onSubmit:F=>{F.preventDefault(),q(z.version),fetch(z.dismissHref,{method:"POST",headers:Wt({}),body:new URLSearchParams({csrf:r.csrf,version:z.version,quiet:"1"})}).catch(()=>{})},children:[(0,V.jsx)("input",{type:"hidden",name:"version",value:z.version}),(0,V.jsx)(ie,{className:"max-[761px]:size-11 max-[761px]:min-h-11",variant:"ghost",size:"icon",type:"submit","aria-label":`Dismiss the notice about ${z.version}`,children:(0,V.jsx)(Hs,{name:"close"})})]})]}),R!==null&&(0,V.jsxs)(mn,{className:"so-update so-phone-notice","data-phone-notice":!0,children:[(0,V.jsxs)("p",{children:[(0,V.jsx)("span",{children:"Use it from your phone too"})," · ",(0,V.jsx)("a",{href:"/settings/alerts#chat-apps",children:"Set up"})]}),(0,V.jsx)(Ae,{action:R.dismissHref,onSubmit:F=>{F.preventDefault(),I(!0),fetch(R.dismissHref,{method:"POST",headers:Wt({}),body:new URLSearchParams({csrf:r.csrf,quiet:"1"})}).catch(()=>{})},children:(0,V.jsx)(ie,{className:"max-[761px]:size-11 max-[761px]:min-h-11",variant:"ghost",size:"icon",type:"submit","aria-label":"Dismiss the phone notice",children:(0,V.jsx)(Hs,{name:"close"})})})]})]}),(0,V.jsx)("main",{id:"workspace-main",className:"so-main-content",tabIndex:-1,children:r.team?(0,V.jsx)(tP,{initial:r.team,user:r.user,csrf:r.csrf,onSnapshot:o}):r.conversation&&!h&&m===null?(0,V.jsx)(z1,{controller:t}):(0,V.jsxs)("div",{className:"so-page-content","data-workspace-page":!0,children:[(0,V.jsx)(I5,{demo:U}),d&&r.firstRun&&(0,V.jsx)(wv,{firstRun:r.firstRun}),r.view?(0,V.jsx)(p5,{view:r.view,csrf:r.csrf,taskChat:x,taskDetails:!1,workspace:r}):(0,V.jsx)(St,{html:e.pageHtml??"",immutable:!0})]})})]}),h&&(0,V.jsxs)("aside",{className:"so-supporting-panel so-ask-panel","data-workspace-detail":!0,"aria-label":"Ask",children:[(0,V.jsxs)("div",{className:"so-ask-header",children:[(0,V.jsxs)(ie,{variant:"ghost",size:"sm",className:"so-phone-back min-[761px]:hidden max-[761px]:h-11 max-[761px]:min-h-11",onClick:()=>i("chat"),children:[(0,V.jsx)(Hs,{name:"arrow"}),"Back"]}),(0,V.jsxs)("div",{role:"tablist","aria-label":"Panel",className:"so-ask-tabs",children:[(0,V.jsx)("button",{type:"button",role:"tab","aria-selected":y==="chat",onClick:()=>b("chat"),children:"Chat"}),(0,V.jsx)("button",{type:"button",role:"tab","aria-selected":y==="crew",onClick:()=>b("crew"),children:"Crew"})]})]}),(0,V.jsx)("div",{className:"so-ask-body",hidden:y!=="chat",children:(0,V.jsx)(z1,{controller:t,docked:r.view?.kind??"task"})}),y==="crew"&&(0,V.jsx)(JJ,{workspace:r})]}),m!==null&&!k&&(0,V.jsxs)("aside",{className:"so-supporting-panel so-details-panel","data-workspace-detail":!0,"aria-label":"Task details",children:[(0,V.jsxs)("div",{className:"so-details-header",children:[(0,V.jsxs)(ie,{variant:"ghost",size:"sm",className:"so-phone-back min-[761px]:hidden max-[761px]:h-11 max-[761px]:min-h-11",onClick:()=>i("chat"),children:[(0,V.jsx)(Hs,{name:"arrow"}),"Back"]}),(0,V.jsx)("h2",{children:"Task details"})]}),(0,V.jsx)("div",{"data-view":"task-details",className:"w-full",children:(0,V.jsx)(_v,{view:m})})]}),!N&&!h&&m===null&&(0,V.jsxs)("aside",{className:`so-supporting-panel${u?" so-supporting-panel--detail":""}`,"data-workspace-detail":!0,children:[(0,V.jsxs)("div",{className:"so-work-panel-header",children:[(0,V.jsxs)(ie,{variant:"ghost",size:"sm",className:"so-phone-back min-[761px]:hidden max-[761px]:h-11 max-[761px]:min-h-11",onClick:()=>i("chat"),children:[(0,V.jsx)(Hs,{name:"arrow"}),d?"Back to chat":"Back"]}),u&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)("h2",{children:r.result?"Result":"Task"}),r.result&&f&&(0,V.jsx)(kP,{label:f.label,tone:f.tone,className:"so-current-task-state","data-workspace-current-task-state":""}),r.result&&(0,V.jsxs)("span",{className:"so-work-run",children:["run #",r.result.runId]}),(0,V.jsx)("a",{href:n?.selected?"/chat?conversation="+encodeURIComponent(n.selected.id):"/chat",className:"so-close-work","aria-label":"Close work and return to the main chat",children:(0,V.jsx)(Hs,{name:"close"})})]})]}),u?(0,V.jsxs)("div",{className:"so-work-detail-content",children:[r.focus&&(r.result?(0,V.jsx)(Qo,{summary:"Task details",className:"so-result-task-details",children:(0,V.jsx)(St,{html:r.focus.html,className:"so-task-context"},r.focus.id)}):(0,V.jsx)(St,{html:r.focus.html,className:"so-task-context"},r.focus.id)),r.result&&(0,V.jsxs)("div",{ref:a,className:"so-result-host",children:[(0,V.jsx)(mA,{"data-workspace-result":r.result.runId,children:(0,V.jsx)(hA,{children:(0,V.jsx)(St,{html:r.result.html,immutable:!0},r.result.runId)})}),r.conversation&&(0,V.jsx)(fP,{host:a,run:r.result.runId,maxChars:r.conversation.maxChars,steer:t.steer},r.result.runId)]})]}):null]}),(0,V.jsx)(i5,{workspace:r}),(0,V.jsx)(d5,{workspace:r})]})]})})}var E5=e=>{let t=e.viewTransition;for(let a of[t?.finished,t?.ready,t?.updateCallbackDone])a?.catch(()=>{})};window.addEventListener("pageswap",E5);window.addEventListener("pagereveal",E5);Hp();var U1=document.getElementById("standing-orders-workspace"),T5=document.getElementById("standing-orders-workspace-data");if(U1&&T5)try{let e=JSON.parse(T5.textContent??"null");if(!Y0(e))throw new Error("Workspace data is incomplete");J0(e.sensitive),(0,R5.createRoot)(U1).render((0,V.jsx)(dee,{initial:e}))}catch{U1.setAttribute("data-workspace-unavailable","true")}export{ZJ as CREW_RUNNING_SHOWN,q1 as CrewRows,St as GuardedHtml,Owe as ProjectStates,w5 as REPLACED_THREAD_DIVIDER,tee as SUMMARY_REJOIN_MS,dee as WorkspaceApp,YJ as crewGroupOf,ree as currentProjectOf,cee as isKitPage,Pwe as needsYouTotal,oee as projectCountWords,eee as readProjectStates,PE as regionIsEditing,k5 as replyTook,aee as titleWithCount,A5 as useProjectStates,WJ as useWorkspace};
80
80
  /*! Bundled license information:
81
81
 
82
82
  react/cjs/react.production.js: