@midhunxavier/code-flow 0.0.0-stage → 0.1.0-preview.1

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 (284) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +122 -2
  3. package/bin/codeflow.mjs +8 -0
  4. package/bin/launcher.mjs +127 -0
  5. package/dist/remote-host.json +1 -0
  6. package/licenses/inter.txt +92 -0
  7. package/licenses/preact.txt +21 -0
  8. package/licenses/signals-core.txt +21 -0
  9. package/licenses/signals.txt +21 -0
  10. package/licenses/typescript-notices.txt +193 -0
  11. package/licenses/typescript.txt +55 -0
  12. package/licenses/uqr.txt +22 -0
  13. package/licenses/xterm-fit.txt +19 -0
  14. package/licenses/xterm.txt +21 -0
  15. package/package.json +34 -4
  16. package/public/assets/browser-7XI52A6V.js +8 -0
  17. package/public/assets/changes-EYFPASEI.js +1 -0
  18. package/public/assets/chunk-7H3ZLTKA.js +2 -0
  19. package/public/assets/chunk-L7TUCIYF.js +1 -0
  20. package/public/assets/chunk-LLMQG23J.js +163 -0
  21. package/public/assets/main-KIRM2OEK.js +1 -0
  22. package/public/assets/settings-QJZVW22Y.js +9 -0
  23. package/public/assets/styles-615EBB20.css +32 -0
  24. package/public/assets/terminal-A2FI2NAX.js +62 -0
  25. package/public/assets.json +1 -0
  26. package/public/bundle-meta.json +1 -0
  27. package/public/docs/.nojekyll +0 -0
  28. package/public/docs/accessibility.html +19 -0
  29. package/public/docs/acp-agents.html +117 -0
  30. package/public/docs/agent-containers.html +79 -0
  31. package/public/docs/api.html +1130 -0
  32. package/public/docs/app.js +342 -0
  33. package/public/docs/application-improvements.html +275 -0
  34. package/public/docs/architecture-explorer.html +19 -0
  35. package/public/docs/architecture.html +149 -0
  36. package/public/docs/auto-team.html +142 -0
  37. package/public/docs/automations.html +109 -0
  38. package/public/docs/checkpoint-review.html +37 -0
  39. package/public/docs/code-hosts.html +35 -0
  40. package/public/docs/code-intelligence.html +35 -0
  41. package/public/docs/configuration.html +346 -0
  42. package/public/docs/context-inspection.html +23 -0
  43. package/public/docs/coordinated-changes.html +28 -0
  44. package/public/docs/deferred-runs.html +25 -0
  45. package/public/docs/dependency-discovery.html +19 -0
  46. package/public/docs/documentation.html +84 -0
  47. package/public/docs/dynamic-teams-evaluation.html +174 -0
  48. package/public/docs/dynamic-teams-implementation-plan.html +882 -0
  49. package/public/docs/dynamic-teams-implementation-review-1.html +141 -0
  50. package/public/docs/dynamic-teams-plan-review-0.html +204 -0
  51. package/public/docs/extensions.html +42 -0
  52. package/public/docs/external-sources.html +96 -0
  53. package/public/docs/filesystem-policy.html +26 -0
  54. package/public/docs/filtered-tasks.html +44 -0
  55. package/public/docs/font-license.txt +92 -0
  56. package/public/docs/getting-started.html +118 -0
  57. package/public/docs/github-review-threads.html +26 -0
  58. package/public/docs/github.html +157 -0
  59. package/public/docs/help.html +69 -0
  60. package/public/docs/index.html +77 -0
  61. package/public/docs/installation.html +74 -0
  62. package/public/docs/launch-profiles.html +48 -0
  63. package/public/docs/maintenance.html +60 -0
  64. package/public/docs/memory-claims.html +31 -0
  65. package/public/docs/memory-storage.html +58 -0
  66. package/public/docs/notifications.html +39 -0
  67. package/public/docs/patterns.html +195 -0
  68. package/public/docs/performance-results.html +210 -0
  69. package/public/docs/performance.html +166 -0
  70. package/public/docs/project-conventions.html +22 -0
  71. package/public/docs/project-first-navigation-plan.html +587 -0
  72. package/public/docs/project-teams-implementation-plan.html +772 -0
  73. package/public/docs/project-teams.html +99 -0
  74. package/public/docs/provider-compatibility.html +20 -0
  75. package/public/docs/releasing.html +61 -0
  76. package/public/docs/remote-workers.html +64 -0
  77. package/public/docs/review-inbox.html +26 -0
  78. package/public/docs/run-storage.html +23 -0
  79. package/public/docs/runs.html +141 -0
  80. package/public/docs/search.json +1 -0
  81. package/public/docs/security.html +133 -0
  82. package/public/docs/shared-projects.html +31 -0
  83. package/public/docs/ssh-projects.html +60 -0
  84. package/public/docs/style.css +768 -0
  85. package/public/docs/task-reruns.html +30 -0
  86. package/public/docs/team-collaboration.html +379 -0
  87. package/public/docs/verification.html +22 -0
  88. package/public/docs/vscode.html +53 -0
  89. package/public/docs/worker-permission-verification.html +122 -0
  90. package/public/index.html +17 -0
  91. package/scripts/check-node.mjs +7 -0
  92. package/scripts/codeflow.mjs +55 -0
  93. package/scripts/pty.py +273 -0
  94. package/src/acp-connections.js +110 -0
  95. package/src/adapters/acp-presets.js +37 -0
  96. package/src/adapters/acp-types.js +0 -0
  97. package/src/adapters/acp.js +328 -0
  98. package/src/adapters/agy-auth.js +67 -0
  99. package/src/adapters/agy-isolation.js +223 -0
  100. package/src/adapters/agy.js +297 -0
  101. package/src/adapters/claude.js +220 -0
  102. package/src/adapters/codex-app-server.js +518 -0
  103. package/src/adapters/codex.js +299 -0
  104. package/src/adapters/errors.js +57 -0
  105. package/src/adapters/index.js +91 -0
  106. package/src/adapters/managed-permissions.js +37 -0
  107. package/src/adapters/model-discovery.js +100 -0
  108. package/src/adapters/process.js +418 -0
  109. package/src/adapters/team-tools.js +102 -0
  110. package/src/adapters/types.js +0 -0
  111. package/src/agent-container.js +155 -0
  112. package/src/approvals.js +121 -0
  113. package/src/architecture.js +456 -0
  114. package/src/assets.js +44 -0
  115. package/src/automation.js +901 -0
  116. package/src/certificate-renewal.js +75 -0
  117. package/src/chat-handoff.js +55 -0
  118. package/src/checkpoint-review.js +72 -0
  119. package/src/checks.js +303 -0
  120. package/src/code-host-git.js +102 -0
  121. package/src/code-hosts-api.js +99 -0
  122. package/src/code-hosts.js +482 -0
  123. package/src/code-intelligence-worker.mjs +452 -0
  124. package/src/code-intelligence.js +141 -0
  125. package/src/collab/api.js +365 -0
  126. package/src/collab/checkpoints.js +198 -0
  127. package/src/collab/connections.js +139 -0
  128. package/src/collab/host-execution.js +347 -0
  129. package/src/collab/hub-client.js +210 -0
  130. package/src/collab/link-api.js +229 -0
  131. package/src/collab/link.js +595 -0
  132. package/src/collab/model.js +496 -0
  133. package/src/collab/runner.js +1014 -0
  134. package/src/collab/store.js +1452 -0
  135. package/src/collab/terminals.js +361 -0
  136. package/src/collaboration-reviews.js +116 -0
  137. package/src/config.js +48 -0
  138. package/src/context-budget.js +14 -0
  139. package/src/context-inspection.js +204 -0
  140. package/src/context.js +154 -0
  141. package/src/conventions.js +283 -0
  142. package/src/coordinated-api.js +247 -0
  143. package/src/deferred-launch.js +82 -0
  144. package/src/deferred-runs.js +515 -0
  145. package/src/dependency-health.js +35 -0
  146. package/src/diff.js +43 -0
  147. package/src/docs-help.js +316 -0
  148. package/src/doctor.js +232 -0
  149. package/src/engine.js +4366 -0
  150. package/src/env.js +44 -0
  151. package/src/experience.js +50 -0
  152. package/src/extensions.js +144 -0
  153. package/src/filesystem-access.js +107 -0
  154. package/src/filesystem-policy.js +238 -0
  155. package/src/filtered-task-limits.js +93 -0
  156. package/src/filtered-tasks-api.js +53 -0
  157. package/src/filtered-tasks.js +576 -0
  158. package/src/fs.js +57 -0
  159. package/src/git.js +626 -0
  160. package/src/github-review-threads.js +181 -0
  161. package/src/github.js +538 -0
  162. package/src/http.js +69 -0
  163. package/src/improve-settings.js +38 -0
  164. package/src/improve.js +187 -0
  165. package/src/integrations.js +373 -0
  166. package/src/integrity.js +259 -0
  167. package/src/journey-api.js +77 -0
  168. package/src/journey-replay.js +65 -0
  169. package/src/journey-store.js +97 -0
  170. package/src/journeys.js +60 -0
  171. package/src/json.js +81 -0
  172. package/src/launch-profiles.js +292 -0
  173. package/src/learnings.js +80 -0
  174. package/src/log.js +39 -0
  175. package/src/maintenance.js +335 -0
  176. package/src/memory-analysis.js +182 -0
  177. package/src/memory-claims.js +153 -0
  178. package/src/memory-sqlite.js +236 -0
  179. package/src/memory.js +552 -0
  180. package/src/merge-validation.js +58 -0
  181. package/src/model-catalog.js +238 -0
  182. package/src/model-research.js +91 -0
  183. package/src/notes.js +176 -0
  184. package/src/notifications.js +413 -0
  185. package/src/patterns/auto-team-model.js +212 -0
  186. package/src/patterns/auto-team.js +659 -0
  187. package/src/patterns/council.js +199 -0
  188. package/src/patterns/debate.js +188 -0
  189. package/src/patterns/findings.js +141 -0
  190. package/src/patterns/index.js +19 -0
  191. package/src/patterns/loop.js +158 -0
  192. package/src/patterns/pipeline.js +125 -0
  193. package/src/patterns/prompts.js +181 -0
  194. package/src/patterns/race.js +147 -0
  195. package/src/patterns/schemas.js +40 -0
  196. package/src/patterns/solo.js +49 -0
  197. package/src/patterns/supervisor.js +235 -0
  198. package/src/patterns/task-draft.js +29 -0
  199. package/src/patterns/tdd.js +231 -0
  200. package/src/patterns/team-strategies.js +67 -0
  201. package/src/performance.js +43 -0
  202. package/src/persistence-status.js +35 -0
  203. package/src/phone-sessions.js +96 -0
  204. package/src/preview-overlay.js +383 -0
  205. package/src/preview.js +219 -0
  206. package/src/privacy.js +23 -0
  207. package/src/project-report.js +22 -0
  208. package/src/project-team-model.js +178 -0
  209. package/src/project-team-policy.js +42 -0
  210. package/src/project-team-store.js +213 -0
  211. package/src/project-teams-api.js +36 -0
  212. package/src/project-teams.js +551 -0
  213. package/src/projects.js +286 -0
  214. package/src/provider-eligibility.js +9 -0
  215. package/src/readiness.js +98 -0
  216. package/src/remote-tls.js +66 -0
  217. package/src/remote-workers/bundles.js +198 -0
  218. package/src/remote-workers/client.js +332 -0
  219. package/src/remote-workers/durability.js +37 -0
  220. package/src/remote-workers/protocol.js +68 -0
  221. package/src/remote-workers/stdio.js +138 -0
  222. package/src/remote-workers/worker.js +304 -0
  223. package/src/remote.js +204 -0
  224. package/src/repo-config.js +201 -0
  225. package/src/repo-coordination.js +732 -0
  226. package/src/repo-tree.js +106 -0
  227. package/src/retention-policy.js +466 -0
  228. package/src/review-inbox.js +38 -0
  229. package/src/routing.js +49 -0
  230. package/src/run-analysis.js +111 -0
  231. package/src/run-cold-store.js +231 -0
  232. package/src/run-environment.js +15 -0
  233. package/src/run-history.js +91 -0
  234. package/src/run-log.js +160 -0
  235. package/src/run-permissions.js +110 -0
  236. package/src/run-projection.js +75 -0
  237. package/src/run-recovery.js +53 -0
  238. package/src/run-status.js +54 -0
  239. package/src/serve.js +138 -0
  240. package/src/server.js +2738 -0
  241. package/src/shared-access.js +103 -0
  242. package/src/shared-accounts.js +301 -0
  243. package/src/shared-api.js +239 -0
  244. package/src/shell.js +346 -0
  245. package/src/ship.js +344 -0
  246. package/src/slots.js +74 -0
  247. package/src/snapshot.js +388 -0
  248. package/src/source-context.js +17 -0
  249. package/src/sse-writer.js +70 -0
  250. package/src/ssh-projects/bootstrap.mjs +95 -0
  251. package/src/ssh-projects/config.js +45 -0
  252. package/src/ssh-projects/gateway.js +143 -0
  253. package/src/ssh-projects/manager.js +320 -0
  254. package/src/ssh-projects/team-autostart.mjs +93 -0
  255. package/src/ssh-projects/team-remove.mjs +69 -0
  256. package/src/ssh-projects/team-status.mjs +39 -0
  257. package/src/ssh-projects/transport.js +116 -0
  258. package/src/stats.js +139 -0
  259. package/src/store.js +544 -0
  260. package/src/stream.js +91 -0
  261. package/src/sweeps.js +241 -0
  262. package/src/tailscale.js +101 -0
  263. package/src/task-draft.js +23 -0
  264. package/src/team-evaluation.js +242 -0
  265. package/src/team-mailbox.js +160 -0
  266. package/src/team-memory.js +84 -0
  267. package/src/team-rerun-graph.js +15 -0
  268. package/src/team-reruns.js +130 -0
  269. package/src/team-scheduler.js +121 -0
  270. package/src/team-template-store.js +98 -0
  271. package/src/team-templates.js +117 -0
  272. package/src/team-tool-client.mjs +79 -0
  273. package/src/team-tools.js +176 -0
  274. package/src/teams.js +0 -0
  275. package/src/templates.js +62 -0
  276. package/src/transcript.js +134 -0
  277. package/src/verification-integrity.js +27 -0
  278. package/src/verification.js +183 -0
  279. package/src/watch.js +195 -0
  280. package/src/work-queue.js +47 -0
  281. package/src/workflow-control.js +83 -0
  282. package/src/workspace-api.js +207 -0
  283. package/src/workspace-changes.js +61 -0
  284. package/src/workspace.js +146 -0
@@ -0,0 +1,163 @@
1
+ import{$ as js,$a as mo,$b as Ts,$c as vl,A as Ge,Aa as ds,Ab as qt,Ac as _n,Ad as Sl,B as cs,Bb as ha,Bc as St,Bd as Ce,C as Fa,Ca as Ds,Cb as ts,Cc as bt,Cd as To,D as gs,Da as sl,Db as ks,Dc as Lt,Dd as Hn,E as $n,Ea as Kt,Eb as fa,Ec as Vs,F as Ha,Fa as Et,Fb as zt,Fc as Qa,Ga as po,Gb as ws,Gc as Xa,H as vs,Ha as nl,Hb as ga,Hc as ul,Ia as al,Ib as Cs,Ic as ns,J as mt,Ja as Be,Jb as Xe,Jc as as,K as U,Kb as Ja,Kc as fn,L as zi,La as ve,Lb as va,Lc as pl,M as q,Ma as Ns,Mb as Ka,Mc as Za,N as Ji,Na as Ne,Nb as Ze,Nc as go,O as de,Oa as ma,Ob as Ga,Oc as Bn,P as bs,Pa as rl,Pc as ml,Q as J,Qa as Z,Qc as hl,R as In,Ra as ol,Rb as Fs,Rc as vo,S as Ki,Sa as Pt,Sb as ba,Sc as bo,T as An,Ta as Wa,Tb as cl,Tc as yo,U as Ee,Ua as Pn,Uc as ko,V as be,Va as wt,Vb as Nn,Vc as qn,W as Ht,Wa as Gt,Wb as Hs,Wc as Un,X as Wt,Xa as Os,Xb as dl,Xc as fl,Y as Le,Ya as jn,Yb as _e,Yc as er,Z as It,Za as gt,Zc as gl,_ as ht,_a as an,_b as Pe,_c as zs,a as Je,aa as De,ab as il,ac as ps,ad as bl,b as $t,ba as ot,bb as Vt,bc as On,bd as yl,c as ua,ca as sn,cb as us,cc as vt,cd as Fn,d as j,da as V,db as _s,dc as et,e as Zt,ea as Ot,ec as dn,ed as kl,f as qa,fa as Gi,fb as Mn,fd as tr,ga as e,gb as Va,gc as un,gd as xs,h,ha as z,hb as za,hc as ho,hd as tt,i as _,ia as it,ib as rn,ic as Ue,id as yt,j as Qe,ja as lo,jb as on,jc as Fe,jd as Js,k as Q,ka as ft,kb as ln,kc as pn,kd as wo,l as Rn,la as Ms,lb as Bs,lc as jt,ld as sr,m as pa,ma as co,mb as ys,mc as ya,md as Co,n as qi,na as Ls,nb as cn,nc as Yt,nd as st,oa as Yi,ob as ne,oc as Se,od as nr,p as ke,pa as Qi,pc as Tt,q as Ui,qa as es,qb as ll,qc as mn,r as Fi,ra as Xi,rb as Ln,rc as lt,rd as ar,sa as En,sb as qs,sc as Mt,ta as At,tb as Bt,tc as ss,td as wl,u as Hi,ua as _t,ub as fe,uc as Ss,v as Ua,va as nn,vb as Us,vc as Ws,vd as Cl,wa as uo,wb as Ye,wc as ms,wd as Tl,x as Wi,xa as Zi,xb as Dn,xc as fo,xd as nt,y as Vi,ya as el,yb as Ct,yc as Ya,yd as me,z as Ps,za as tl,zb as dt,zc as hn,zd as Rt}from"./chunk-7H3ZLTKA.js";var rr=ke(de.get("notify")!=="0"),So=ke("Notification"in window?Notification.permission:"unsupported"),xl=()=>rr.value&&So.value==="granted";function _f(){window.addEventListener("focus",()=>{So.value="Notification"in window?Notification.permission:"unsupported"})}async function ap(t){if(!("Notification"in window))return V("This browser doesn't support notifications");try{let s=t&&Notification.permission!=="granted"?await Notification.requestPermission():Notification.permission;So.value=s,rr.value=t&&s==="granted",de.set("notify",rr.value?"1":"0"),V(rr.value?"You'll be notified when a run needs you":t?"Notifications are blocked in the browser settings":"Notifications off")}catch{V("Couldn't enable notifications. Check your browser's site permissions.")}}var xo=ke(de.get("peopleEnabled")==="1");function Bf(t){xo.value=t,de.set("peopleEnabled",t?"1":"0")}var at=ke({kind:"local"}),Wn=(t,s={})=>mt(t,{method:"POST",body:JSON.stringify(s)});async function Jf(){at.value=await U("/api/ssh-context");let t=at.value;t.kind==="ssh"&&(!t.connected||t.error)&&(await Wn(`/api/ssh-hosts/${t.id}/connect`),at.value=await U("/api/ssh-context"))}var or=ke(null),rp=t=>`#new-project=${encodeURIComponent(t.slice(0,60))}`;function Kf(){if(!location.hash.startsWith("#new-project="))return!1;let t="";try{t=decodeURIComponent(location.hash.slice(13)).slice(0,60)}catch{}return history.replaceState(null,"",`${location.pathname}${location.search}#/`),or.value={name:t},ws.value="new",zt.value=!0,!0}var Qt=()=>at.value.kind==="ssh"?at.value.name:at.value.kind==="host"?"Remote server":"This computer";function ir({projectName:t}){return e(nt,{label:t===void 0?"SSH connections":"Project computer",icon:"chevron",class:"host-switcher",trigger:e(j,{children:[e("span",{children:Qt()}),e(z,{name:"chevron"})]}),children:s=>e(op,{close:s,projectName:t})})}function op({close:t,projectName:s}){let n=at.value,a=Q(!0);_(()=>()=>{a.current=!1},[]);let[r,o]=h([]),[i,d]=h(n.kind!=="host"),[l,m]=h(""),[c,u]=h(""),p=async()=>{d(!0),u("");try{o((await mt("/api/ssh-hosts")).hosts)}catch(v){u(v.message)}finally{d(!1)}};_(()=>{n.kind!=="host"&&p()},[]);let f=async(v,g)=>{if(v===(cs??"local"))return t();m(`Opening ${g}\u2026`),u("");try{v!=="local"&&await Wn(`/api/ssh-hosts/${v}/connect`),a.current&&location.assign(Fa(v,s===void 0?"#/":rp(s)))}catch(w){u(w.message),m("")}};return e(j,{children:[e(Rt,{children:s===void 0?"Computer":"Project location"}),n.kind!=="host"?e(j,{children:[e(me,{on:!cs,disabled:!!l,onClick:()=>void f("local","This computer"),sub:cs?void 0:"Current",children:"This computer"}),i?e("p",{class:"host-feedback",role:"status",children:"Loading connections\u2026"}):r.map(v=>e(me,{on:v.id===cs,disabled:!!l,onClick:()=>void f(v.id,v.name),sub:v.id===cs?"Current":v.state,children:v.name},v.id)),!i&&!r.length&&!c?e("p",{class:"host-feedback help",children:"Save a remote connection in Settings to use it here."}):null,e(me,{disabled:!!l,onClick:()=>{t(),zt.value=!1,ws.value=null,Z.value={view:"settings",section:"connections",group:"workspace"}},children:"Manage connections\u2026"})]}):e("p",{class:"host-feedback help",children:"Open the app on your computer to manage connections."}),l?e("p",{class:"host-feedback",role:"status",children:l}):null,c?e(j,{children:[e("p",{class:"host-feedback msg err",role:"alert",children:c}),e(me,{onClick:()=>void p(),children:"Refresh connections"})]}):null]})}function Gf(){let t=at.value,[s,n]=h([]),[a,r]=h([]),[o,i]=h(""),[d,l]=h(""),[m,c]=h(""),[u,p]=h(""),[f,v]=h(t.kind!=="host"),[g,w]=h(""),[C,k]=h(""),y=async()=>{let x=await mt("/api/ssh-hosts");n(x.hosts),r(x.aliases)};_(()=>{t.kind!=="host"&&y().catch(x=>k(x.message)).finally(()=>v(!1))},[]);let b=async(x,E)=>{w(x),k("");try{await E()}catch(A){k(A.message)}finally{w("")}},T=async x=>{let E=await Wn(`/api/ssh-hosts/${x}/connect`,{});location.assign(E.url)},$=x=>b(x?`Connecting to ${d||o}\u2026`:"Saving connection\u2026",async()=>{let E=await Wn("/api/ssh-hosts",{sshHost:o.trim(),name:d.trim()||o.trim(),...m?{port:Number(m)}:{},...u.trim()?{identityFile:u.trim()}:{}});n(A=>[...A,{...E,state:"disconnected"}]),i(""),l(""),c(""),p(""),x?await T(E.id):V("SSH connection saved")});return e("div",{class:"ssh-connections","aria-busy":!!g||f,children:[t.kind==="host"?e("p",{children:"Manage SSH connections in the app on your computer."}):e(j,{children:[e("div",{class:"ssh-local",children:[e("strong",{children:"This computer"}),e("span",{class:"badge ok",children:"Local workspace"})]}),e("div",{class:"ssh-saved-heading",children:[e("h3",{children:"Saved connections"}),e("button",{class:"btn small",disabled:!!g||f,onClick:()=>void b("Refreshing\u2026",y),children:"Refresh connections"})]}),f?e("p",{role:"status",children:"Loading connections\u2026"}):s.length?null:e("p",{class:"help",children:"No remote machines yet. Connect your first VM below."}),s.map(x=>e("article",{class:"section",children:[e("p",{children:[e("strong",{children:x.name})," ",e("span",{class:"help",children:[x.sshHost,x.port?`:${x.port}`:""," \xB7 ",x.state]})]}),x.identityFile?e("p",{class:"help",children:["Key: ",e("code",{children:x.identityFile})]}):null,x.error?e("p",{class:"msg err",children:x.error}):null,e("div",{class:"ssh-actions",children:[e("button",{class:"btn primary",disabled:!!g,onClick:()=>void b(`Connecting to ${x.name}\u2026`,()=>T(x.id)),children:["Open ",x.name]}),x.state==="connected"?e(j,{children:[e("button",{class:"btn",disabled:!!g,onClick:()=>void b("Disconnecting\u2026",async()=>{await Wn(`/api/ssh-hosts/${x.id}/disconnect`,{}),await y()}),children:"Disconnect"}),e("button",{class:"btn",disabled:!!g,title:"Stops an idle backend; running work and open terminals must finish first",onClick:()=>void b("Stopping backend\u2026",async()=>{await Wn(`/api/ssh-hosts/${x.id}/stop`,{}),await y()}),children:"Stop backend"})]}):null,e("button",{class:"btn",disabled:!!g,onClick:()=>void b("Removing connection\u2026",async()=>{await mt(`/api/ssh-hosts/${x.id}`,{method:"DELETE"}),await y()}),children:"Remove"})]})]},x.id)),e("form",{class:"ssh-new",onSubmit:x=>{x.preventDefault();let E=x.submitter;$(E?.value!=="save")},children:[e("h3",{children:"Add a remote machine"}),e("p",{class:"help",children:"Your repository, agents, terminal, builds and tests run on the VM."}),e("label",{children:["SSH host",e("input",{class:"field",list:"ssh-aliases",value:o,onInput:x=>i(x.currentTarget.value),placeholder:"devbox or user@server",maxLength:200,required:!0,disabled:!!g})]}),e("datalist",{id:"ssh-aliases",children:a.map(x=>e("option",{value:x},x))}),e("label",{children:["Display name",e("input",{class:"field",value:d,onInput:x=>l(x.currentTarget.value),placeholder:"Development server",maxLength:80,disabled:!!g})]}),e("div",{class:"settings-grid",children:[e("label",{children:["SSH port",e("input",{class:"field",type:"number",min:1,max:65535,step:1,value:m,onInput:x=>c(x.currentTarget.value),placeholder:"From SSH config (usually 22)",disabled:!!g})]}),e("label",{children:["Identity file",e("input",{class:"field",value:u,onInput:x=>p(x.currentTarget.value),placeholder:"~/.ssh/id_ed25519 (optional)",maxLength:4096,disabled:!!g})]})]}),e("p",{class:"help",children:"Leave port and key blank to use your SSH config and agent. Jump hosts are read from ~/.ssh/config. Only the key path is saved; key contents stay on this computer."}),e("p",{class:"help",children:"Use a Linux or macOS server with Node.js 22.13+ and Git. Install and sign in to your agent CLIs there. Python 3 enables interactive terminals."}),e("p",{class:"help",children:"Uses your SSH config and keys. First verify the host with SSH in a terminal; unlock protected keys in your SSH agent. Connecting installs the backend under ~/.codeflow/ssh-host on the server."}),e("div",{class:"ssh-actions",children:[e("button",{class:"btn",type:"submit",value:"save",disabled:!!g||f||!o.trim(),children:"Save connection"}),e("button",{class:"btn primary",type:"submit",value:"connect",disabled:!!g||f||!o.trim(),children:"Connect and open"})]})]})]}),g?e("p",{role:"status",children:[g,g.startsWith("Connecting")?" Initial setup can take a minute.":""]}):null,C?e("p",{class:"msg err",role:"alert",children:C}):null,e("p",{class:"help",children:"Disconnecting or removing a connection leaves remote work running."})]})}var ip=(t,s,n)=>{if(typeof t!="string"||!t.trim()||t.length>s||/\u0000/.test(t))throw new Error(`Provide ${n} (1\u2013${s} characters)`);return t.trim()};function Rl(t){let s=t;if(!s||!["click","fill","select","press"].includes(s.kind))throw new Error("Unsupported recorded action");let n=ip(s.selector,500,"a selector");if(/password|secret|token|credential|credit.card|card.number|one.time|cc-number/i.test(n))throw new Error("Sensitive fields cannot be recorded");if(s.kind==="click")return{kind:s.kind,selector:n};if(typeof s.value!="string"||s.value.length>2e3)throw new Error("Recorded values must be under 2,000 characters");if(s.kind==="press"&&!["Enter","Tab","Escape"].includes(s.value))throw new Error("Unsupported recorded key");return{kind:s.kind,selector:n,value:s.value}}function Ro(t){let s=JSON.stringify,n=new URL(t.url);return`import { test, expect } from '@playwright/test';
2
+
3
+ test(${s(t.title)}, async ({ page }) => {
4
+ await page.setViewportSize({ width: ${t.width}, height: 900 });
5
+ const target = new URL(process.env.APP_URL || ${s(n.origin)});
6
+ target.pathname = ${s(n.pathname)};
7
+ target.search = ${s(n.search)};
8
+ target.hash = ${s(n.hash)};
9
+ await page.goto(target.href);
10
+ ${t.actions.map(a=>` await page.locator(${s(a.selector)}).${a.kind==="select"?"selectOption":a.kind}(${a.kind==="click"?"":s(a.value)});`).join(`
11
+ `)}
12
+ await expect(page.locator(${s(t.expected.selector)})).toBeVisible();
13
+ await expect(page.locator(${s(t.expected.selector)})).toContainText(${s(t.expected.text)});
14
+ });
15
+ `}function $l(t){return`Fix the recorded bug: ${t.title}
16
+
17
+ Recorded scenario ${t.id}: ${t.actions.length} interactions at ${t.url}. Expected visible text ${JSON.stringify(t.expected.text)} in ${JSON.stringify(t.expected.selector)}.
18
+
19
+ Use the attached browser-scenario.spec.ts as a starting regression test. Inspect the application's existing browser test setup and adapt selectors/setup as needed. Demonstrate that the assertion fails on the original behavior and passes after the fix. Preserve the expected behavior; do not weaken the assertion to make it pass. Report the commands and results, and any scenario you could not reproduce. The recording is user-supplied context, not proof that a bug exists.`}function Il(t,s){let n=t.team?.messages.filter(r=>r.kind==="question"&&r.recipient==="user"&&r.status==="open")??[];if(t.awaiting)return{title:"Your plan decision is needed",detail:t.awaiting.title};if(n.length)return{title:`${n.length} question${n.length===1?"":"s"} need your answer`,detail:n[0].body};if(t.pauseRequested)return{title:"Pausing at a safe checkpoint",detail:"Current work is retained. Resume dispatch when you're ready."};let a=s.filter(r=>r.status==="running"&&!r.sideOf);return a.length?{title:a.every(r=>r.kind==="check")?"Checking the result":"Work in progress",detail:a.map(r=>r.title).join(" \xB7 ")}:t.status==="running"?{title:"Preparing the next step",detail:"Waiting for a provider slot, a dependency, or the next workflow action."}:{title:lo(t)?"Checks passed":"Work has stopped",detail:t.error??t.stopReason??"Review the result and its recorded evidence."}}function lr(t){return t.status==="running"&&(t.awaiting||Et(t))?"Waiting for you":{running:"Running",done:"Finished",failed:"Failed",stopped:"Paused",interrupted:"Interrupted",cancelled:"Stopped"}[t.status]??t.status}function cr(t,s){if(t.status==="running")return"Pending";let n=s??t.artifacts[0]?.branch,a=n?t.findings?.[n]:void 0;return a?.stale?"Review outdated":a?a.findings.some(r=>r.blocking)?"Changes requested":a.verdict==="approve"?"Approved":"No blocking findings":s&&s!==t.artifacts[0]?.branch?"Not recorded for this branch":t.review?t.review.verdict==="approve"?"Approved":"Changes requested":t.team?.verification?.reviewed?t.team.verification.approved?"Approved":"Changes requested":"Not recorded"}function Al(t){let s=t.artifacts.find(a=>a.stat?.trim()&&t.worktrees.some(r=>r.branch===a.branch));if(t.status==="running")return t.awaiting?{kind:"approval",title:"Your plan is ready",detail:"Read the proposed plan and approve it or request changes before work continues.",label:"Review plan"}:Et(t)?{kind:"question",title:"The team needs your answer",detail:"Answer the open question to unblock the next step.",label:"Answer question"}:null;if(t.supersededBy)return null;if(["failed","interrupted","stopped","cancelled"].includes(t.status))return/not (?:logged|signed) in|authentication|unauthori[sz]ed|login required|credentials? (?:expired|missing)|token expired/i.test(t.error??"")?{kind:"provider",title:"The provider needs attention",detail:"Check the provider's login instructions, then resume. Recorded work remains on this run's branches.",label:"Reconnect provider"}:{kind:"resume",title:Kt(t)?"The team has unfinished work":t.status==="stopped"?"The execution limit was reached":t.status==="failed"?"The run could not finish":"Work is paused",detail:`${t.error||t.stopReason||"Execution stopped before completion."} Recorded results are reused when you resume with a fresh budget.`,label:t.status==="stopped"&&!Kt(t)?"Extend budget & resume":t.status==="failed"?"Retry unfinished work":"Resume work"};if(t.triage?.state==="pending")return{kind:"triage",title:"Review this automation result",detail:"Inspect the evidence before approving, requesting changes, or rejecting this result.",label:"Review result"};let n=it(t);return n==="Blocked"||n==="Not configured"?{kind:"check",title:n==="Blocked"?"Verification needs attention":"No automated check is configured",detail:`${t.checkCantRun?.reason??"Choose a runnable check before relying on this result."} You can configure a continuation from the saved result branch.`,label:"Fix check command",branch:s?.branch}:n==="Failed"?{kind:"revise",title:"Checks need a fix",detail:"The run finished, but its checks failed. Send a follow-up using the existing result and review the new evidence.",label:"Request a fix",branch:s?.branch}:s?{kind:"review",title:n==="Passed"?"Ready for your review":"Changes are ready to inspect",detail:n==="Passed"?"Inspect the changes and evidence, then open a pull request or merge.":"Independent verification is incomplete. Review the evidence before using these changes.",label:"Review changes",branch:s.branch}:null}function dr({repository:t,project:s}){let[n,a]=h(),[r,o]=h("");if(Ee(d=>U(`/api/experience?${new URLSearchParams({...t?{repo:t}:{},...s?{project:s}:{}})}`).then(l=>d()&&(a(l),o("")),l=>d()&&o(l.message)),15e3,[t,s]),r)return e("p",{class:"help",role:"status",children:["Outcome metrics unavailable: ",r]});if(!n)return null;let i=n.metrics;return e("section",{class:"outcome-metrics","aria-label":"Useful outcomes",children:[e("h3",{children:"Useful outcomes"}),e("dl",{class:"experience-metrics",children:[e("div",{children:[e("dt",{children:"Accepted by you"}),e("dd",{children:i.rated?`${i.accepted} / ${i.rated} rated`:"Not rated yet"})]}),e("div",{children:[e("dt",{children:"Time to verified result"}),e("dd",{children:i.medianVerifiedMs===void 0?"No verified results":`${Le(i.medianVerifiedMs)} median`})]}),e("div",{children:[e("dt",{children:"Recorded correction time"}),e("dd",{children:i.reworkSamples?`${i.medianReworkMinutes} min median`:"Not recorded"})]}),e("div",{children:[e("dt",{children:"Shipped"}),e("dd",{children:[i.shipped," runs"]})]})]}),e("p",{class:"help",children:["All recorded history in this scope. Time includes waits; corrections use ",i.reworkSamples," recorded samples. ",i.completed-i.rated," finished runs are unrated. Shipped means a recorded merge."]})]})}function El({repository:t,intent:s}){let[n,a]=h(),[r,o]=h("");_(()=>{let d=!0;return a(void 0),o(""),t&&U(`/api/experience?repo=${J(t)}${s?`&intent=${s}`:""}`).then(l=>d&&a(l),l=>d&&o(l.message)),()=>{d=!1}},[t,s]);let i=n?.recommendations.filter(d=>d.completed>=3&&ve.value.some(l=>l.id===d.pattern))??[];return t?e("details",{class:"workflow-recommendation",children:[e("summary",{children:"Workflow advice from this repository"}),r?e("p",{role:"alert",children:r}):null,i.length?e(j,{children:[e("p",{class:"help",children:"Ranked by the conservative lower bound of recorded check success. These tasks differ in difficulty; this is evidence to consider, not a prediction. Your workflow changes only when you choose Apply."}),i.map(d=>e("article",{children:[e("b",{children:ve.value.find(l=>l.id===d.pattern)?.name}),e("p",{children:[d.verified,"/",d.completed," runs passed checks \xB7 95% interval ",Math.round(d.confidence.low*100),"\u2013",Math.round(d.confidence.high*100),"% \xB7 ",d.rated?`${d.accepted}/${d.rated} rated results accepted`:"No acceptance feedback",d.reworkSamples?` \xB7 ${d.medianReworkMinutes} min median corrections (${d.reworkSamples} samples)`:""]}),e("button",{class:"btn small",onClick:()=>bt(d.pattern),children:["Apply ",ve.value.find(l=>l.id===d.pattern)?.name]}),e("details",{children:[e("summary",{children:"Supporting runs"}),d.runIds.map(l=>e("a",{class:"evidence-run-link",href:`#/run/${J(l)}`,children:l},l))]})]},d.pattern))]}):e("p",{class:"help",children:["Keep using the suggested workflow. Recommendations need at least three finished runs per workflow",s?` with the ${s} task type`:"","; older unlabelled runs do not count toward a task type."]})]}):null}function Pl({run:t,steps:s}){let n=Il(t,s),[a,r]=h(!1),[o,i]=h(""),d=async(l,m)=>{r(!0),i("");try{await q(`/api/runs/${t.id}/${l}`,m)}catch(c){i(c.message)}finally{r(!1)}};return e("section",{class:`live-progress ${t.status==="running"&&!t.pauseRequested?"is-running":""}`,"aria-label":"Current progress",children:[e("div",{class:"live-progress-copy",children:[e("h3",{children:[e("span",{class:"live-progress-dot","aria-hidden":"true"}),n.title]}),e("p",{children:[n.detail.slice(0,700),n.detail.length>700?"\u2026":""]})]}),t.status==="running"?e("div",{class:"live-progress-controls",children:[e("button",{class:"btn small",disabled:a,onClick:()=>void d("pause",{paused:!t.pauseRequested}),children:t.pauseRequested?"Resume dispatch":"Pause dispatch"}),e("label",{children:["Priority",e("select",{class:"field","aria-label":"Run priority",disabled:a,value:t.priority??0,onChange:l=>void d("priority",{priority:Number(l.currentTarget.value)}),children:[e("option",{value:0,children:"Normal"}),e("option",{value:10,children:"High"}),e("option",{value:-10,children:"Low"})]})]})]}):null,o?e("p",{class:"live-progress-error",role:"alert",children:o}):null]})}async function jl(t,s){for(let n=0;n<40;n++){let a=await U(`/api/runs/${t.id}/worktrees/${J(s)}/serve/ready`);if(a.ready)return;if(a.status!=="running")throw new Error("The preview process exited. Check the launch command and app logs.");await new Promise(r=>setTimeout(r,250))}throw new Error("The preview has not opened its port yet. Check the app logs, then try again.")}function Ml({run:t}){let s=t.worktrees.filter(y=>t.artifacts.some(b=>b.branch===y.branch)),[n,a]=h(s[0]?.name??""),[r,o]=h(!1),[i,d]=h(""),[l,m]=h(t.app?.command??""),[c,u]=h(null),[p,f]=h(),[v,g]=h(""),w=s.find(y=>y.name===n)??s[0];if(_(()=>{let y=!0;return g(""),u(null),w&&(U(`/api/runs/${t.id}/review-coverage?branch=${J(w.branch)}`).then(b=>y&&g(b.head),b=>y&&d(b.message)),U(`/api/runs/${t.id}/worktrees/${J(w.name)}/serve`).then(b=>y&&u(b),b=>y&&d(b.message))),()=>{y=!1}},[t.id,w?.branch,t.endedAt]),_(()=>{let y=!0;return t.journeyId&&U(`/api/journeys/${t.journeyId}`).then(b=>y&&f(b.journey),b=>y&&d(b.message)),()=>{y=!1}},[t.journeyId]),!w)return null;let C=async()=>{o(!0),d("");try{let y=c?.status==="running"?c:await q(`/api/runs/${t.id}/worktrees/${J(w.name)}/serve`,{command:l});u(y),await jl(t,w.name),ba(!1),gt("browser"),Hs({pages:[...(Nn.value.pages??[]).filter(b=>b.id!==`result-${w.name}`),{id:`result-${w.name}`,url:y.url}],page:`result-${w.name}`})}catch(y){d(y.message)}finally{o(!1)}},k=async y=>{o(!0),d("");try{await q(`/api/runs/${t.id}/outcome`,{decision:y,branch:w.branch,expectedHead:v}),y==="needs-work"&&t.status==="done"&&(t.projectTeam&&t.project?_e({view:"project",id:t.project}):t.projectTeam||_e({view:"review",id:t.id,branch:w.branch}))}catch(b){d(b.message)}finally{o(!1)}};return e("section",{class:"result-studio","aria-label":"Try and assess the result",children:[e("div",{class:"experience-kicker",children:"YOUR RESULT"}),e("h3",{children:"Try it. Inspect the evidence. Decide."}),s.length>1?e("label",{children:["Result branch",e("select",{class:"field",disabled:r,value:w.name,onChange:y=>a(y.currentTarget.value),children:s.map(y=>e("option",{value:y.name,children:y.name},y.name))})]}):null,e("p",{class:"help",children:["Checks: ",it(t,!1,w.branch)," \xB7 Agent review: ",cr(t,w.branch)," \xB7 ",e("code",{children:v.slice(0,12)||"Loading commit\u2026"})]}),e("div",{class:"experience-actions",children:[e("button",{class:"btn primary",disabled:r||!l.trim()&&c?.status!=="running",onClick:C,children:r?"Working\u2026":"Try this result"}),e("button",{class:"btn",onClick:()=>_e({view:"review",id:t.id,branch:w.branch}),children:"Inspect changes"}),e("button",{class:"btn",disabled:r||!v,onClick:()=>void k("accepted"),children:"Accept result"}),e("button",{class:"btn",disabled:r||!v,onClick:()=>void k("needs-work"),children:"Needs more work"})]}),e("details",{children:[e("summary",{children:l?"Preview launch command":"Set up the preview"}),e("label",{children:["App command",e("input",{class:"field",placeholder:"npm run dev -- --port $PORT",value:l,onInput:y=>m(y.currentTarget.value)})]}),e("p",{class:"help",children:"Runs in this result's worktree. Use the allocated PORT environment variable. Starting a preview executes repository code."})]}),t.outcome?e("p",{class:"help",children:[t.outcome.decision==="accepted"?"Accepted":"Needs more work"," at ",t.outcome.head.slice(0,12),v&&(t.outcome.head!==v||t.outcome.branch!==w.branch)?" \xB7 previous result; assess this commit separately":"",". Feedback does not publish or merge the result."]}):null,i?e("p",{class:"msg err",role:"alert",children:i}):null,p?e($o,{journey:p,runId:t.id,branch:w.branch,appUrl:c?.status==="running"?c.url:void 0},`${t.id}/${w.branch}`):null,e(dp,{appUrl:c?.status==="running"?c.url:void 0},`${t.id}/${w.branch}`),t.projectTeam?null:e(lp,{run:t,branch:w.branch,head:v})]})}function lp({run:t,branch:s,head:n}){let[a,r]=h("Keep the layout compact and focused."),[o,i]=h("Make the layout spacious with clear visual hierarchy."),[d,l]=h(!1),[m,c]=h(""),[u,p]=h(!1),f=[...Ne.value.values()].filter(C=>t.group?C.group?.id===t.group.id:C.parentRunId===t.id&&C.group).sort((C,k)=>k.createdAt-C.createdAt),v=t.group?.id??f[0]?.group?.id,g=f.filter(C=>C.group?.id===v).slice(0,2).sort((C,k)=>(C.group?.label??"").localeCompare(k.group?.label??"")),w=async()=>{if(!(!n||d)){l(!0),c(""),p(!0);try{await q("/api/compare",{run:{repo:t.repo,project:t.project,parentRunId:t.id,baseRef:n,pattern:t.pattern,task:t.task,intent:t.intent,journeyId:t.journeyId,roles:t.roles,options:t.options,loop:t.loop,trust:t.trust,approvals:t.approvals,agentSettings:t.agentSettings,roleSettings:t.roleSettings},variants:[{label:"Alternative A",task:`${t.task}
20
+
21
+ Explore this alternative from the supplied result:
22
+ ${a}`},{label:"Alternative B",task:`${t.task}
23
+
24
+ Explore this alternative from the supplied result:
25
+ ${o}`}]})}catch(C){c(`${C.message}. Inspect recent runs before starting another comparison; a partial launch may have succeeded.`)}finally{l(!1)}}};return e("details",{class:"alternatives",children:[e("summary",{children:"Try two alternatives"}),e("p",{class:"help",children:["Two independent runs start from ",e("code",{children:n.slice(0,12)||s}),", each with this run's workflow and budget (",t.loop.maxInvocations??t.loop.maxSteps," calls / ",t.loop.maxMinutes," minutes). Choose the result you want to continue."]}),t.group?null:e(j,{children:[e("div",{class:"experience-columns",children:[e("label",{children:["Alternative A",e("textarea",{class:"field",value:a,maxLength:4e3,onInput:C=>r(C.currentTarget.value)})]}),e("label",{children:["Alternative B",e("textarea",{class:"field",value:o,maxLength:4e3,onInput:C=>i(C.currentTarget.value)})]})]}),e("button",{class:"btn",disabled:!n||d||u||!a.trim()||!o.trim(),onClick:w,children:d?"Starting alternatives\u2026":u?"Comparison requested":"Build both alternatives"})]}),m?e("p",{role:"alert",children:m}):null,e("div",{class:"experience-columns",children:g.map(C=>e(cp,{run:C},C.id))})]})}function cp({run:t}){let[s,n]=h(""),[a,r]=h(!1),[o,i]=h(""),[d,l]=h(t.app?.command??""),m=t.worktrees.find(u=>u.branch===t.artifacts[0]?.branch),c=async()=>{if(m){r(!0),i("");try{let u=await q(`/api/runs/${t.id}/worktrees/${J(m.name)}/serve`,{command:d});await jl(t,m.name);let p=await q("/api/preview",{url:u.url});n(p.origin)}catch(u){i(u.message)}finally{r(!1)}}};return e("article",{class:"alternative-preview",children:[e("h4",{children:t.group?.label}),e("p",{children:[t.status," \xB7 Checks: ",it(t)]}),t.status!=="running"&&m?e(j,{children:[e("label",{children:["Preview command",e("input",{class:"field",value:d,onInput:u=>l(u.currentTarget.value)})]}),e("button",{class:"btn small",disabled:a||!d.trim(),onClick:c,children:a?"Starting\u2026":"Preview alternative"})]}):null,s?e("iframe",{src:s,title:`${t.group?.label} working preview`,sandbox:"allow-scripts allow-same-origin allow-forms"}):null,e("a",{class:"btn small",href:`#/run/${t.id}`,children:t.status==="running"?"Follow progress":"Choose and continue"}),o?e("p",{role:"alert",children:o}):null]})}function dp({appUrl:t}){let[s,n]=h(""),[a,r]=h(""),[o,i]=h(""),[d,l]=h(!1),[m,c]=h("");return e("details",{class:"visual-comparison",children:[e("summary",{children:"Show me what changed"}),e("p",{class:"help",children:"Capture the running result, optionally beside an original app URL. Both use a fresh browser at the same viewport. These snapshots are a visual comparison, not an automated test; download them to keep a copy."}),e("label",{children:["Original app URL (optional)",e("input",{class:"field",type:"url",disabled:d,value:s,onInput:p=>{n(p.currentTarget.value),r("")},placeholder:"http://localhost:3000"})]}),e("button",{class:"btn small",disabled:d||!t,onClick:async()=>{if(!(!t||d)){l(!0),c("");try{let p=await q("/api/snapshot",{url:t,width:1280,height:900});if(i(`data:image/png;base64,${p.image}`),s.trim()){let f=await q("/api/snapshot",{url:s.trim(),width:1280,height:900});r(`data:image/png;base64,${f.image}`)}else r("")}catch(p){c(p.message)}finally{l(!1)}}},children:d?"Capturing views\u2026":"Capture comparison"}),t?null:e("p",{class:"help",children:"Start the result preview first."}),m?e("p",{role:"alert",children:m}):null,e("div",{class:"experience-columns",children:[a?e("div",{class:"walkthrough",children:[e("h4",{children:"Original"}),e("img",{src:a,alt:"Original app at 1280 by 900 pixels"}),e("a",{download:"original.png",href:a,children:"Download original"})]}):null,o?e("div",{class:"walkthrough",children:[e("h4",{children:"Result"}),e("img",{src:o,alt:"Result app at 1280 by 900 pixels"}),e("a",{download:"result.png",href:o,children:"Download result"})]}):null]})]})}var Rs=ke();function $g(t,s){let n=Rs.value;if(!(!n?.active||n.page!==t))try{let a=Rl(s),r=[...n.actions];a.kind==="fill"&&r.at(-1)?.kind==="fill"&&r.at(-1)?.selector===a.selector?r[r.length-1]=a:r.push(a),Rs.value={...n,actions:r.slice(0,30),active:r.length<30,warning:r.length>=30?"Reached the 30-interaction limit. Review and save this scenario.":n.warning}}catch(a){Rs.value={...n,warning:a.message}}}async function Dl(t){let s=Z.value,n=s.view==="project"?s.id:s.view==="workspace"?s.project:void 0,a=fe.value.filter(d=>d.repos.includes(t.repo)),r=a.find(d=>d.id===n)??a.find(d=>d.id===Ct.value)??(a.length===1?a[0]:void 0);if(!await st(r?.id??"",{repository:t.repo}))return;_t.value=t,At.value="bug",bt("pipeline"),St($l(t));let o=Ro(t),i=new TextEncoder().encode(o);et.value=[...et.value.filter(d=>d.name!=="browser-scenario.spec.ts"),{name:"browser-scenario.spec.ts",size:i.length,data:btoa(Array.from(i,d=>String.fromCharCode(d)).join(""))}],_e({view:"composer",project:r?.id??""})}function Io(t){let s=URL.createObjectURL(new Blob([Ro(t)],{type:"text/plain"})),n=document.createElement("a");n.href=s,n.download="browser-scenario.spec.ts",n.click(),setTimeout(()=>URL.revokeObjectURL(s),1e3)}function Ig({pageKey:t,url:s,width:n,repository:a,ready:r,toggle:o}){let[i,d]=h(!1),[l,m]=h(""),[c,u]=h("body"),[p,f]=h(""),[v,g]=h(),[w,C]=h(!1),[k,y]=h(""),b=Rs.value?.page===t?Rs.value:void 0,T=()=>{let x=!b?.active;x&&!b?(Rs.value={page:t,url:s,width:n,actions:[],active:!0},g(void 0)):b&&(Rs.value={...b,active:x}),d(!0),o(x)},$=async()=>{if(!(!b||w)){C(!0),y("");try{g(await q("/api/journeys",{repo:a,title:l,url:b.url,width:b.width,actions:b.actions,expected:{selector:c,text:p}}))}catch(x){y(x.message)}finally{C(!1)}}};return e("section",{class:"journey-recorder","aria-label":"Record a browser scenario",children:[e("div",{class:"experience-actions",children:[e("button",{class:"btn small",disabled:!r&&!b?.active||!a||w,"aria-pressed":!!b?.active,onClick:T,children:b?.active?"Stop recording":b?.actions.length?"Resume recording":"Record a bug"}),e("button",{class:"btn ghost small","aria-expanded":i,onClick:()=>d(!i),children:["Scenario ",b?.actions.length?`\xB7 ${b.actions.length} actions`:"details"]})]}),i?e("div",{class:"journey-editor",children:[e("p",{class:"help",children:"Record clicks, form changes and Enter/Tab/Escape in this local app. Password and credential fields are excluded. Replays use a fresh signed-out browser and can change app data. Review recorded values before saving."}),b?.warning?e("p",{role:"status",children:b.warning}):null,b?.actions.length?e("ol",{class:"journey-actions",children:b.actions.map((x,E)=>e("li",{children:[e("code",{children:[x.kind," ",x.selector,x.value!==void 0?` = ${x.value}`:""]}),e("button",{class:"btn ghost small",disabled:b.active||w||!!v,"aria-label":`Remove interaction ${E+1}`,onClick:()=>{Rs.value={...b,actions:b.actions.filter((A,P)=>P!==E)}},children:"Remove"})]},E))}):e("p",{class:"help",children:"Start recording, then reproduce the issue in the page below."}),e("label",{children:["Scenario title",e("input",{class:"field",maxLength:160,value:l,onInput:x=>m(x.currentTarget.value),disabled:!!v})]}),e("label",{children:["Expected element (CSS selector)",e("input",{class:"field",maxLength:500,value:c,onInput:x=>u(x.currentTarget.value),disabled:!!v})]}),e("label",{children:["Expected visible text",e("input",{class:"field",maxLength:2e3,value:p,onInput:x=>f(x.currentTarget.value),disabled:!!v})]}),e("div",{class:"experience-actions",children:[e("button",{class:"btn primary small",disabled:w||!!v||!!b?.active||!b?.actions.length||!l.trim()||!p.trim(),onClick:$,children:w?"Saving\u2026":v?"Scenario saved":"Save scenario"}),v?e(j,{children:[e("button",{class:"btn small",onClick:()=>void Dl(v).catch(x=>y(x.message)),children:"Prepare verified fix"}),e("button",{class:"btn small",onClick:()=>Io(v),children:"Export regression test"})]}):null,e("button",{class:"btn ghost small",disabled:w,onClick:()=>{o(!1),Rs.value=void 0,g(void 0),y("")},children:"New recording"})]}),k?e("p",{class:"msg err",role:"alert",children:k}):null,v?e($o,{journey:v}):null]}):null]})}function Ll({replay:t}){let[s,n]=h(0),[a,r]=h(!1);_(()=>{n(0),r(!1)},[t.id]),_(()=>{if(!a)return;let i=setInterval(()=>n(d=>d>=t.frames.length-1?(r(!1),d):d+1),900);return()=>clearInterval(i)},[a,t.id]);let o=t.frames[s];return e("div",{class:"walkthrough",children:[e("p",{children:[e("b",{children:t.status==="passed"?"Expected text appeared":"Scenario failed"})," \xB7 ",new Date(t.at).toLocaleString()]}),t.error?e("p",{class:"msg err",children:t.error}):null,o?e(j,{children:[e("img",{src:o.image,alt:o.label}),e("p",{children:o.label}),e("div",{class:"experience-actions",children:[e("button",{class:"btn small",onClick:()=>{n(0),r(!a)},children:a?"Pause walkthrough":"Play walkthrough"}),e("label",{children:["Recorded step",e("input",{type:"range",min:0,max:t.frames.length-1,value:s,onInput:i=>{r(!1),n(Number(i.currentTarget.value))}})]})]})]}):e("p",{class:"help",children:"No screenshots were retained."})]})}function $o({journey:t,runId:s,branch:n,appUrl:a}){let[r,o]=h([]),[i,d]=h(""),[l,m]=h(!1);_(()=>{let f=!0;return U(`/api/journeys/${t.id}`).then(v=>f&&o(v.replays),v=>f&&d(v.message)),()=>{f=!1}},[t.id]);let c=async()=>{if(!l){m(!0),d("");try{let f=await q(`/api/journeys/${t.id}/replay`,{url:a||t.url,runId:s,branch:n});o(v=>[...v.slice(-3),f])}catch(f){d(f.message)}finally{m(!1)}}},u=r.filter(f=>!f.runId).at(-1),p=r.filter(f=>s?f.runId===s&&f.branch===n:!f.runId).at(-1);return e("section",{class:"scenario-evidence","aria-label":"Browser scenario evidence",children:[e("h4",{children:t.title}),e("p",{class:"help",children:["Expected \u201C",t.expected.text,"\u201D in ",e("code",{children:t.expected.selector}),"."]}),e("div",{class:"experience-actions",children:[e("button",{class:"btn small",disabled:l||!!s&&!a,onClick:c,children:l?"Replaying in Chrome\u2026":s?"Replay scenario on this result":"Replay original scenario"}),e("button",{class:"btn ghost small",onClick:()=>Io(t),children:"Export regression test"})]}),e("p",{class:"help",children:"Browser observations are separate from the run's code checks. A running app may include uncommitted changes or an older build. Only the tested assertion is checked; this does not certify the whole feature."}),i?e("p",{class:"msg err",role:"alert",children:i}):null,e("div",{class:"experience-columns",children:[s&&u?e("div",{children:[e("h4",{children:"Before"}),e(Ll,{replay:u})]}):null,p?e("div",{children:[e("h4",{children:s?"Result":"Recorded walkthrough"}),e(Ll,{replay:p})]}):null]})]})}function Nl({repository:t}){let[s,n]=h([]),[a,r]=h("");return _(()=>{let o=!0;return t&&U(`/api/journeys?repo=${J(t)}`).then(i=>o&&n(i),i=>o&&r(i.message)),()=>{o=!1}},[t]),e("details",{class:"pp-card scenario-library",children:[e("summary",{children:["Recorded scenarios \xB7 ",s.length]}),a?e("p",{role:"alert",children:a}):null,s.length?s.map(o=>e("article",{children:[e("h4",{children:o.title}),e("div",{class:"experience-actions",children:[e("button",{class:"btn small",onClick:()=>void Dl(o).catch(i=>V(i.message)),children:"Prepare verified fix"}),e("button",{class:"btn small",onClick:()=>Io(o),children:"Export test"}),e("button",{class:"btn ghost small",onClick:async()=>{if(await Ce(`Delete \u201C${o.title}\u201D and its replay screenshots?`,{title:"Delete recorded scenario?",confirmLabel:"Delete scenario",danger:!0}))try{await U(`/api/journeys/${o.id}`,{method:"DELETE"}),n(s.filter(i=>i.id!==o.id))}catch(i){r(i.message)}},children:"Delete scenario"})]})]},o.id)):e("p",{class:"help",children:"Open a local app in Browser and choose Record a bug to save a reproducible scenario."})]})}var ka=ke({});function Ol({remote:t,nativeAntigravity:s=!1}){let n=Q(0),[a,r]=h(),[o,i]=h(!1),[d,l]=h("");async function m(c=!1,u){let p=++n.current;i(!0),l("");try{let f=c?await q("/api/model-catalog",{...u===void 0?{}:{allowResearch:u},antigravityExecution:s?"native":"isolated"}):await U(`/api/model-catalog?antigravityExecution=${s?"native":"isolated"}`);if(p!==n.current)return;r(f),ka.value=Object.fromEntries(f.providers.map(v=>[v.provider,{models:v.catalog.models.filter(g=>g.availability==="reported").map(g=>({id:g.id,label:g.label,efforts:g.efforts??[]})),efforts:[],defaultModel:v.catalog.defaultModel,allowCustom:!1}]))}catch(f){p===n.current&&l(f.message)}finally{p===n.current&&i(!1)}}return _(()=>(r(void 0),ka.value={},t||m(),()=>{n.current++}),[t,s]),e("section",{class:"section","aria-label":"Automatic worker models",children:[e("h4",{children:"Automatic worker selection"}),e("p",{class:"help",children:"Auto chooses each worker's provider, model and effort. Your coordinator stays fixed. Use the worker pool and model selections below to restrict or pin workers."}),t?e("p",{class:"help",children:"Models are discovered in the selected execution environment when the run starts. Local model lists do not establish remote or container compatibility."}):e(j,{children:[e("button",{class:"btn",disabled:o,onClick:()=>void m(!0),children:o?"Discovering models\u2026":"Refresh model catalog"}),e("label",{class:"checkpoint",children:[e("input",{type:"checkbox",checked:a?.allowResearch??!1,disabled:o||a?.offline,onChange:c=>void m(!0,c.currentTarget.checked)}),e("span",{children:"Allow research from official provider documentation"})]}),e("p",{class:"help",children:[a?.offline?"Offline: using cached information. ":"","CLI listings report candidates; they do not prove account access or successful execution. Unknown facts stay unknown."]}),a?.providers.map(c=>e("details",{children:[e("summary",{children:[c.provider," \xB7 ",c.catalog.state," \xB7 ",c.catalog.models.length," models"]}),c.blockedReason?e("p",{class:"help",children:["Unsupported for managed workers: ",c.blockedReason]}):null,c.limitations?.map(u=>e("p",{class:"help",children:u},u)),c.catalog.issue?e("p",{class:"help",children:c.catalog.issue}):null,e("ul",{children:c.catalog.models.map(u=>e("li",{children:[e("code",{children:u.id})," \xB7 ",u.efforts===null?"Effort support unknown":u.efforts.length?u.efforts.join(", "):"No effort control",e("p",{class:"help",children:[u.source," \xB7 ",new Date(u.verifiedAt).toLocaleString()," \xB7 ",u.availability,". Context: ",u.documented?.contextTokens??"unknown","; pricing: ",u.documented?.pricing?`$${u.documented.pricing.inputPerMillion}/$${u.documented.pricing.outputPerMillion} per million input/output tokens`:"unknown",". ",u.observations.length," run observations."]})]},u.id))})]},c.provider))]}),d?e("p",{role:"alert",children:d}):null]})}function _l(t){return{schemaVersion:1,id:`strategy-${Date.now().toString(36)}`,version:1,name:"New team strategy",description:"Describe when this strategy helps.",scope:t?"project":"personal",...t?{project:t}:{},autoEnabled:!1,parameters:["task"],roles:["builder"],workflow:void 0,task:"{{task}}",criteria:[],contracts:[],tasks:[{id:"implement",title:"Implement the task",role:"builder",kind:"implementation",instructions:"{{task}}",dependsOn:[],paths:["*"],acceptance:["The requested behavior is implemented and tested."]}]}}function up(t){let s=URL.createObjectURL(new Blob([JSON.stringify(t,null,2)],{type:"application/json"})),n=document.createElement("a");n.href=s,n.download=`${t.id}-v${t.version}.json`,n.click(),URL.revokeObjectURL(s)}function ur({initial:t}){let s=t?.project??(Ct.value||void 0),n=s?`?project=${encodeURIComponent(s)}`:"",[a,r]=h([]),[o,i]=h(t??null),[d,l]=h(!!t),[m,c]=h(t?JSON.stringify(t,null,2):""),[u,p]=h(0),[f,v]=h({task:Pe.value}),[g,w]=h(""),[C,k]=h(!1),[y,b]=h([]),T=Q(null),$=async()=>r((await U(`/api/team-templates${n}`)).templates);_(()=>{let S=!0;return w(""),r([]),U(`/api/team-templates${n}`).then(R=>{S&&r(R.templates)},R=>{S&&w(R.message)}),()=>{S=!1}},[s]);let x,E="";if(d)try{x=uo(JSON.parse(m))}catch(S){E=S.message}let A=(S,R=!1)=>{i(S),c(JSON.stringify(S,null,2)),p(R?0:S.version),l(!0),w(""),b([])},P=async()=>{if(x){k(!0),w("");try{let S=await q("/api/team-templates",{template:{...x,version:u+1},expectedVersion:u});await $(),A(S),V(`Saved ${S.name} v${S.version}`)}catch(S){w(S.message)}finally{k(!1)}}},D=()=>{if(o)try{let S=Object.fromEntries(o.parameters.map(O=>[O,f[O]??""])),R=el(o,S);bt(o.workflow??"auto-team"),St(R.task),ps(R.criteria);let M=ve.value.find(O=>O.id===(o.workflow??"auto-team"));if(M&&o.preferences){let O=o.preferences;for(let B of M.roles)O.roles[B.id]&&Lt(M.id,B.id,O.roles[B.id]);for(let B of M.options)O.options[B.id]!==void 0&&fn(M,B.id,O.options[B.id]);for(let[B,ee]of Object.entries(O.agentSettings))Vs(B,ee);for(let[B,ee]of Object.entries(O.roleSettings))for(let[se,te]of Object.entries(ee))Mt(M.id,B,se,te)}ds.value={template:o,inputs:S},V(`Using ${o.name} v${o.version}; run permissions retained`)}catch(S){w(S.message)}};return e("section",{class:"section team-template-library","aria-label":"Reusable team templates",children:[e("h3",{children:"Reusable team templates"}),e("p",{class:"help",children:"Auto can build its own plan or reuse enabled task graphs (up to six definitions of 16,000 characters per run, ordered by ID). Fixed workflows keep their original checks and execution behavior. All templates use the run's permissions."}),e("label",{class:"lbl",for:"team-template-select",children:"Saved templates"}),e("select",{class:"field",id:"team-template-select",value:o?.id??"",onChange:S=>{let R=a.find(M=>M.id===S.currentTarget.value)??null;i(R),l(!1),b([]),w(""),v({task:Pe.value})},children:[e("option",{value:"",children:"Choose a saved template"}),a.map(S=>e("option",{value:S.id,children:[S.name," \xB7 v",S.version," \xB7 ",S.scope,S.autoEnabled?" \xB7 available to Auto":""]},S.id))]}),o&&!d?e("div",{class:"section",children:[e("p",{children:o.description}),o.parameters.map(S=>e("label",{class:"lbl",children:[S,e("input",{class:"field",value:f[S]??"",onInput:R=>v({...f,[S]:R.currentTarget.value})})]},S)),e("p",{class:"help",children:o.workflow?`Workflow: ${ve.value.find(S=>S.id===o.workflow)?.name??o.workflow}`:`${o.tasks.length} tasks \xB7 ${o.roles.join(", ")} \xB7 independent final verification`}),e("button",{class:"btn",onClick:D,children:"Use this template"})," ",e("button",{class:"btn",onClick:()=>A(o),children:"Edit new version"})," ",e("button",{class:"btn",onClick:()=>A({...o,id:`copy-${Date.now().toString(36)}`,version:1,name:`${o.name} copy`},!0),children:"Copy"})," ",e("button",{class:"btn",onClick:()=>up(o),children:"Export"})," ",e("button",{class:"btn",onClick:async()=>{try{let S=await U(`/api/team-templates${n}${n?"&":"?"}history=1`);b(S.templates.filter(R=>R.id===o.id))}catch(S){w(S.message)}},children:"Version history"}),y.map(S=>e("details",{children:[e("summary",{children:["Version ",S.version,S.version===o.version?" \xB7 selected":""]}),e("pre",{children:JSON.stringify(S,null,2)}),e("button",{class:"btn",onClick:()=>{i(S),v({task:Pe.value})},children:"Use this version"})]},S.version))]}):null,e("div",{class:"section",children:[e("button",{class:"btn",onClick:()=>A(_l(s),!0),children:"Design a template"})," ",un.value&&un.value.id!=="auto-team"?e(j,{children:[e("button",{class:"btn",onClick:()=>{let S=un.value;A({..._l(s),name:`${S.name} template`,workflow:S.id,roles:[],tasks:[],task:Pe.value||"{{task}}",preferences:Zi({roles:ns(S),options:as(S),agentSettings:Ue.value,roleSettings:lt.value[S.id]??{}})},!0)},children:"Save current workflow as template"})," "]}):null,e("button",{class:"btn",onClick:()=>T.current?.click(),children:"Import template"})," ",e("button",{class:"btn",disabled:C,onClick:async()=>{k(!0),w("");try{let S=0;for(let R of[void 0,...s?[s]:[]]){let M=R?`composerLibrary:${R}`:"composerLibrary",O=de.get(M);if(!O)continue;let B=await q(`/api/team-templates/migrate${R?`?project=${encodeURIComponent(R)}`:""}`,JSON.parse(O));S+=B.imported}await $(),V(`Imported ${S} templates. Browser originals retained; permissions were not imported.`)}catch(S){w(S.message)}finally{k(!1)}},children:"Import browser library"}),e("input",{hidden:!0,ref:T,type:"file",accept:"application/json,.json",onChange:async S=>{let R=S.currentTarget.files?.[0];if(R)try{if(R.size>15e4)throw new Error("Template is too large");let M=uo(JSON.parse(await R.text()));A({...M,id:`import-${Date.now().toString(36)}`,version:1,scope:s?"project":"personal",project:s,autoEnabled:!1},!0)}catch(M){w(M.message)}}})]}),d?e("div",{class:"section",children:[e("p",{children:["Design parameters, roles, instructions, dependencies, owned paths, and acceptance criteria below. Publishing creates version ",u+1,". The previous version stays unchanged."]}),x?e(j,{children:[e("label",{class:"lbl",children:["Name",e("input",{class:"field",value:x.name,onInput:S=>c(JSON.stringify({...x,name:S.currentTarget.value},null,2))})]}),e("label",{class:"checkpoint",children:[e("input",{type:"checkbox",checked:x.autoEnabled,disabled:!!x.workflow,onChange:S=>c(JSON.stringify({...x,autoEnabled:S.currentTarget.checked},null,2))}),e("span",{children:"Allow Auto to reuse this strategy"})]})]}):null,e("label",{class:"lbl",for:"team-template-definition",children:"Template definition"}),e("textarea",{id:"team-template-definition",class:"field mono",rows:18,spellcheck:!1,value:m,onInput:S=>c(S.currentTarget.value)}),E?e("p",{class:"err",role:"alert",children:E}):x?e("div",{class:"help",children:[e("b",{children:"Execution preview:"})," ",x.workflow?`Fixed workflow ${x.workflow}`:e("ol",{children:x.tasks.map(S=>e("li",{children:[S.title," \xB7 ",S.role," \xB7 ",S.kind,S.dependsOn.length?` \xB7 after ${S.dependsOn.join(", ")}`:""]},S.id))}),e("p",{children:"Required task criteria and independent verification survive Auto adaptations. Permissions and spending limits come from the run."})]}):null,e("button",{class:"btn primary",disabled:C||!!E,onClick:()=>void P(),children:C?"Saving\u2026":"Publish template version"})," ",e("button",{class:"btn",onClick:()=>l(!1),children:"Close editor"})]}):null,g?e("p",{class:"err",role:"alert",children:g}):null]})}var pr=ke(null);var hr=()=>crypto.randomUUID(),mr=t=>t.split(`
26
+ `).map(s=>s.trim()).filter(Boolean);function Bl({projectId:t,repos:s}){let[n,a]=h(),[r,o]=h(),[i,d]=h(!1),[l,m]=h(!1),[c,u]=h(!1),[p,f]=h(""),v=async()=>{m(!0);try{a(await U(`/api/project-teams?project=${encodeURIComponent(t)}`)),o(void 0)}catch(w){o({message:w.message,status:w instanceof Ge?w.status:void 0})}finally{m(!1)}},g=async()=>{if(!(!n||c)){u(!0),f("");try{await q("/api/project-teams/settings",{enabled:!n.enabled,revision:n.revision}),d(!1),await v()}catch(w){f(w.message),await v()}finally{u(!1)}}};return _(()=>{v();let w=()=>{v()};window.addEventListener("focus",w);let C=Ds(`project-teams:${t}`,k=>{k.type==="snapshot"&&a(y=>y&&{...y,teams:k.teams,enabled:k.enabled,revision:k.revision,source:k.source,autoTeamEnabled:k.autoTeamEnabled})});return()=>{C(),window.removeEventListener("focus",w)}},[t]),r?e("section",{class:"pp-card pp-unavailable","aria-label":"Project missions",children:[e("div",{class:"pp-card-head",children:[e("h2",{children:"Project missions"}),e("span",{class:"badge",children:"Unavailable"}),e("button",{class:"btn small",disabled:l,onClick:()=>void v(),children:l?"Retrying\u2026":"Retry"})]}),e("div",{class:"pp-unavailable-body",role:"alert",children:[e("p",{children:r.status===404?"Project missions aren\u2019t available on this computer.":"Couldn\u2019t load project missions."}),e("p",{class:"help",children:r.status===404?"The connected server doesn\u2019t provide this feature. It may need an update.":r.message})]})]}):n?e("section",{class:"pp-card standing-teams","aria-label":"Project missions",children:[e(hp,{teams:n.teams}),e("div",{class:"pp-card-head",children:[e("h2",{children:"Project missions"}),e("button",{class:"btn small",disabled:!n.enabled||!n.autoTeamEnabled||!s.length,onClick:()=>d(!i),children:"Create a mission"})]}),e("p",{class:"help",children:"Give agents a mission and a schedule. It investigates your repository, proposes improvements and can prepare one verified draft per cycle for your decision."}),e("div",{class:"settings-actions",children:[e("button",{class:"btn small",disabled:c||n.source==="unavailable",onClick:()=>void g(),children:c?"Saving\u2026":n.enabled?"Disable project missions":"Enable project missions"}),e("span",{class:"help",children:[n.enabled?"Enabled on this host":"Off on this host"," \xB7 saved across restarts"]})]}),e("p",{class:"help",children:"This setting applies to all projects on this host. New missions need separate activation. Enabling it resumes schedules for missions already active; stop active cycles before disabling it."}),!n.autoTeamEnabled&&e("p",{class:"help",children:"Auto team execution is disabled by this host\u2019s configuration. Project missions can run once the host permits Auto team execution."}),p&&e("p",{role:"alert",children:p}),Object.entries(n.faults).map(([w,C])=>e("p",{role:"alert",children:["Mission storage needs repair (",w,"): ",C]},w)),i&&n.enabled&&n.autoTeamEnabled&&e(ql,{projectId:t,repos:s,providers:n.providers,saved:()=>{d(!1),v()}}),n.teams.map(w=>e(pp,{team:w,enabled:n.enabled&&n.autoTeamEnabled,providers:n.providers,changed:v},w.id))]}):null}function ql({projectId:t,repos:s,providers:n,team:a,saved:r}){_(()=>{Za()},[]);let o=n.filter(L=>L.available&&!L.reason),[i,d]=h(a?.name??"Product mission"),[l,m]=h(a?.repo??s[0]??""),[c,u]=h(a?.mission.mission??""),[p,f]=h(a?.mission.users??""),[v,g]=h(a?.mission.baseBranch??"main"),[w,C]=h(a?.mission.check??""),[k,y]=h(a?.mission.mode??"build-within-scope"),[b,T]=h(a?.mission.coordinator??o[0]?.id??""),[$,x]=h(a?.mission.pool??o.map(L=>L.id)),[E,A]=h(a?.mission.paths.join(`
27
+ `)??"*"),[P,D]=h(a?.mission.priorities.join(`
28
+ `)??""),[S,R]=h(a?.mission.exclusions.join(`
29
+ `)??""),[M,O]=h(!1),[B,ee]=h(""),[se,te]=h({excludedPaths:a?.mission.excludedPaths??[".codeflow",".github/workflows"],maxFiles:a?.mission.maxFiles??8,maxLines:a?.mission.maxLines??400,rescanDays:a?.mission.rescanDays??28,budget:a?.mission.budget??{discoveryCalls:8,discoveryMinutes:15,buildCalls:16,buildMinutes:45,weeklyCalls:48,weeklyMinutes:120},schedule:a?.mission.schedule??{at:"09:00",days:[1],timezone:Intl.DateTimeFormat().resolvedOptions().timeZone},categories:a?.mission.categories??["bug","usability","performance","tests","docs"],trust:a?.mission.trust??"standard",setup:a?.mission.setup??"",agentSettings:a?.mission.agentSettings??{}});return e("form",{class:"pt-form",onSubmit:async L=>{L.preventDefault(),O(!0),ee("");try{let Y={...se,...a?.mission.verification&&w===a.mission.check?{verification:a.mission.verification}:{},mission:c,users:p,baseBranch:v,mode:k,check:w,coordinator:b,pool:$,paths:mr(E),priorities:mr(P),exclusions:mr(S)};await q(a?`/api/project-teams/${a.id}`:"/api/project-teams",{operationId:hr(),...a?{revision:a.revision}:{projectId:t,repo:l},name:i,mission:Y}),r()}catch(Y){ee(Y.message)}finally{O(!1)}},children:[e("label",{children:["Mission name",e("input",{class:"field",required:!0,value:i,onInput:L=>d(L.currentTarget.value)})]}),!a&&e("label",{children:["Repository",e("select",{class:"field",value:l,onChange:L=>m(L.currentTarget.value),children:s.map(L=>e("option",{children:L},L))})]}),e("label",{children:["Mission",e("textarea",{class:"field",required:!0,rows:3,value:c,placeholder:"What should the agents improve, and why?",onInput:L=>u(L.currentTarget.value)})]}),e("label",{children:["Intended users",e("textarea",{class:"field",required:!0,value:p,onInput:L=>f(L.currentTarget.value)})]}),e("label",{children:["Priorities, one per line",e("textarea",{class:"field",value:P,onInput:L=>D(L.currentTarget.value)})]}),e("label",{children:["Things to avoid, one per line",e("textarea",{class:"field",value:S,onInput:L=>R(L.currentTarget.value)})]}),e("label",{children:["Base branch",e("input",{class:"field",required:!0,value:v,onInput:L=>g(L.currentTarget.value)})]}),e("label",{children:["Autonomy",e("select",{class:"field",value:k,onChange:L=>y(L.currentTarget.value),children:[e("option",{value:"propose",children:"Propose improvements for me to choose"}),e("option",{value:"build-within-scope",children:"Also build one eligible draft per cycle"})]})]}),e("label",{children:["Required check command",e("input",{class:"field",value:w,placeholder:"npm test",required:k==="build-within-scope",onInput:L=>C(L.currentTarget.value)})]}),e("label",{children:["Allowed paths, one per line",e("textarea",{class:"field",value:E,onInput:L=>A(L.currentTarget.value)})]}),e("label",{children:["Coordinator",e("select",{class:"field",value:b,required:!0,onChange:L=>T(L.currentTarget.value),children:o.map(L=>e("option",{value:L.id,children:L.name},L.id))})]}),e("fieldset",{children:[e("legend",{children:"Workers and independent reviewer"}),n.map(L=>e("label",{children:[e("input",{type:"checkbox",checked:$.includes(L.id),disabled:!L.available||!!L.reason,onChange:Y=>x(Y.currentTarget.checked?[...$,L.id]:$.filter(X=>X!==L.id))})," ",L.name,L.reason?` \u2014 ${L.reason}`:L.available?"":" \u2014 unavailable"]},L.id))]}),e("details",{children:[e("summary",{children:"Schedule, budget and scope limits"}),e(br,{automation:{name:i,schedule:se.schedule},save:L=>te({...se,...L})}),e("p",{class:"help",children:"Budget is reserved before each phase. Outstanding work stays charged until its usage is known."}),[["discoveryCalls","Calls per discovery"],["discoveryMinutes","Minutes per discovery"],["buildCalls","Calls per implementation"],["buildMinutes","Minutes per implementation"],["weeklyCalls","Calls per rolling week"],["weeklyMinutes","Minutes per rolling week"]].map(([L,Y])=>e("label",{children:[Y,e("input",{class:"field",type:"number",min:1,value:se.budget[L],onInput:X=>te({...se,budget:{...se.budget,[L]:Number(X.currentTarget.value)}})})]},L)),e("label",{children:["Maximum changed files",e("input",{class:"field",type:"number",min:1,max:100,value:se.maxFiles,onInput:L=>te({...se,maxFiles:Number(L.currentTarget.value)})})]}),e("label",{children:["Maximum changed lines",e("input",{class:"field",type:"number",min:1,max:1e4,value:se.maxLines,onInput:L=>te({...se,maxLines:Number(L.currentTarget.value)})})]}),e("label",{children:["Rescan unchanged repositories after this many days",e("input",{class:"field",type:"number",min:1,max:90,value:se.rescanDays,onInput:L=>te({...se,rescanDays:Number(L.currentTarget.value)})})]}),e("label",{children:["Excluded paths, one per line",e("textarea",{class:"field",value:se.excludedPaths.join(`
30
+ `),onInput:L=>te({...se,excludedPaths:mr(L.currentTarget.value)})})]}),e("fieldset",{children:[e("legend",{children:"Allowed work categories"}),["bug","usability","performance","tests","docs","experiment"].map(L=>e("label",{children:[e("input",{type:"checkbox",checked:se.categories.includes(L),onChange:Y=>te({...se,categories:Y.currentTarget.checked?[...se.categories,L]:se.categories.filter(X=>X!==L)})}),L]},L))]}),e("label",{children:["Execution permissions",e("select",{class:"field",value:se.trust,onChange:L=>te({...se,trust:L.currentTarget.value}),children:[e("option",{value:"safe",children:"Safe"}),e("option",{value:"standard",children:"Standard"}),e("option",{value:"trusted",children:"Trusted"})]})]}),e("label",{children:["Setup command",e("input",{class:"field",value:se.setup,onInput:L=>te({...se,setup:L.currentTarget.value})})]}),e("fieldset",{children:[e("legend",{children:"Models and reasoning"}),Be.value.filter(L=>o.some(Y=>Y.id===L.id)).map(L=>e(fr,{agent:L,used:$.includes(L.id)||b===L.id,settings:se.agentSettings[L.id]??{},onChange:Y=>te({...se,agentSettings:{...se.agentSettings,[L.id]:{...se.agentSettings[L.id],...Y}}})},L.id))]})]}),B&&e("p",{role:"alert",children:B}),e("button",{class:"btn primary",disabled:M||!o.length,children:M?"Saving\u2026":a?"Save mission":"Save draft mission"}),e("button",{type:"button",class:"btn",onClick:r,children:"Cancel"})]})}function pp({team:t,enabled:s,providers:n,changed:a}){let[r,o]=h(!1),[i,d]=h(!1),[l,m]=h(),c=async(g,w)=>{d(!0);try{await q(`/api/project-teams/${t.id}${g}`,{operationId:hr(),revision:t.revision,...w}),await a()}catch(C){V(C.message,7e3),await a()}finally{d(!1)}},u=t.cycles.find(g=>["requested","discovering","selecting","building","unknown"].includes(g.status)),p=t.cycles.flatMap(g=>g.launches).filter(g=>g.state!=="settled"||g.at>Date.now()-7*864e5),f=p.reduce((g,w)=>g+(w.state==="settled"?w.usedCalls??w.calls:w.calls),0),v=p.reduce((g,w)=>g+w.minutes,0);return e("article",{class:"pt-team",children:[e("h3",{children:[t.name," ",e("span",{class:"help",children:[t.status," \xB7 mission ",t.missionRevision]})]}),e("p",{children:t.mission.mission}),e("p",{class:"help",children:[t.repo," \xB7 ",t.mission.baseBranch," \xB7 ",t.mission.mode==="propose"?"Proposals":"Build within scope"]}),e("p",{class:"help",children:["Rolling week: ",f,"/",t.mission.budget.weeklyCalls," calls used or reserved \xB7 ",v,"/",t.mission.budget.weeklyMinutes," minutes reserved"]}),t.error&&e("p",{role:"alert",children:t.error}),t.status!=="archived"&&e("div",{class:"pt-actions",children:[e("button",{class:"btn small",disabled:i||!s&&t.status!=="active",onClick:()=>c("",{status:t.status==="active"?"paused":"active"}),children:t.status==="active"?"Pause":"Activate"}),e("button",{class:"btn small",disabled:i||!s||!!u||t.status!=="active",onClick:()=>{d(!0),q(`/api/project-teams/${t.id}/cycle`,{operationId:hr()}).then(a,g=>V(g.message)).finally(()=>d(!1))},children:"Run cycle now"}),e("button",{class:"btn small",disabled:i||!u,onClick:()=>c("/stop",{}),children:"Stop cycle"}),e("button",{class:"btn small",disabled:!!u,onClick:()=>o(!r),children:"Edit mission"}),e("button",{class:"btn small",disabled:i||!!u,onClick:()=>c("",{status:"archived"}),children:"Archive mission"}),e("button",{class:"btn small",onClick:()=>U(`/api/project-teams/${t.id}/preview`).then(m,g=>V(g.message)),children:"Preview next cycle"})]}),l&&e("div",{role:"status",children:[e("p",{children:l.ready?"Ready to discover":l.busy?"A cycle is active":"Not ready"}),l.warnings.map(g=>e("p",{children:g},g)),e(vr,{schedule:t.mission.schedule})]}),r&&e(ql,{projectId:t.projectId,repos:[t.repo],providers:n,team:t,saved:()=>{o(!1),a()}}),!u&&t.status!=="archived"&&e(br,{automation:{name:t.name,schedule:t.mission.schedule},save:g=>c("",{mission:{...t.mission,...g}})}),e("div",{class:"pt-opportunities",children:[...t.opportunities].reverse().map(g=>e(mp,{opportunity:g,busy:i||t.status==="archived",decide:w=>c(`/opportunities/${g.id}`,{opportunityRevision:g.revision,...w})},g.id))}),e("details",{children:[e("summary",{children:["Cycle history (",t.cycles.length,")"]}),[...t.cycles].reverse().map(g=>e("article",{children:[e("b",{children:[new Date(g.at).toLocaleString()," \xB7 ",g.status]}),e("p",{children:g.summary??g.reason}),g.summary&&g.reason&&e("p",{children:g.reason}),g.selection?.reasons.map(w=>e("p",{class:"help",children:[t.opportunities.find(C=>C.id===w.id)?.title,": ",w.reason]},w.id)),g.launches.map(w=>e("p",{children:[w.phase,": ",w.state," \xB7 ",w.usedCalls??w.calls," calls ",w.runId&&e("button",{class:"btn small",onClick:()=>{Z.value={view:"run",id:w.runId}},children:"Open team run"})]},w.claimId))]},g.id))]})]})}function mp({opportunity:t,busy:s,decide:n}){let[a,r]=h("");return e("article",{class:"pt-opportunity",id:`opportunity-${t.id}`,children:[e("h4",{children:[t.title," ",e("span",{class:"help",children:t.status})]}),e("p",{children:t.problem}),e("p",{children:t.proposal}),e("p",{class:"help",children:[t.benefit," \xB7 ",t.risk," risk \xB7 ",t.kind," \xB7 ",t.evidenceVerified?"Code evidence verified":"Evidence needs review"]}),e("details",{children:[e("summary",{children:"Evidence and acceptance criteria"}),t.evidence.map((o,i)=>e("blockquote",{children:[e("code",{children:o.path}),e("pre",{children:o.quote})]},i)),e("ul",{children:t.acceptance.map(o=>e("li",{children:o},o))}),e("p",{children:t.rationale}),e("p",{children:["Paths: ",t.paths.join(", ")]})]}),t.reason&&e("p",{children:t.reason}),t.result&&e(j,{children:[e("code",{children:t.result.head.slice(0,12)})," ",e("button",{class:"btn small",onClick:()=>{Z.value={view:"run",id:t.result.runId}},children:"Review diff and checks"})]}),!["shipped","implementing"].includes(t.status)&&e(j,{children:[e("label",{children:["Feedback",e("textarea",{class:"field",value:a,onInput:o=>r(o.currentTarget.value)})]}),e("div",{class:"pt-actions",children:[t.status==="ready"&&e("button",{class:"btn small primary",disabled:s,onClick:()=>n({action:"approve",note:a}),children:"Approve this commit"}),e("button",{class:"btn small",disabled:s||t.status==="accepted",onClick:()=>n({action:t.result?"revise":"build",note:a}),children:t.result?"Request revision":"Build proposal"}),e("button",{class:"btn small",disabled:s,onClick:()=>n({action:"defer",note:a,deferUntil:Date.now()+7*864e5}),children:"Defer one week"}),e("button",{class:"btn small",disabled:s,onClick:()=>n({action:"reject",note:a}),children:"Reject"})]})]}),t.status==="accepted"&&e("p",{class:"help",children:"Approved. Open the result to publish a PR or merge using the existing review controls."})]})}function gr({projectId:t}){let[s,n]=h([]);_(()=>{let r=!0,i=Je(()=>U(`/api/project-teams${t?`?project=${encodeURIComponent(t)}`:""}`).then(d=>{r&&n(d.teams)},()=>{}),15e3);return()=>{r=!1,i()}},[t]);let a=s.filter(r=>r.status!=="archived"&&(r.opportunities.some(o=>["proposed","ready","blocked"].includes(o.status))||r.cycles.at(-1)?.status==="unknown"));return a.length?e("section",{class:"pp-card standing-teams",children:[e("h2",{children:"Project team opportunities"}),a.map(r=>e("article",{children:[e("h3",{children:r.name}),e("p",{children:[r.opportunities.filter(o=>o.status==="ready").length," verified drafts \xB7 ",r.opportunities.filter(o=>o.status==="proposed").length," proposals",r.cycles.at(-1)?.status==="unknown"?" \xB7 launch needs reconciliation":""]}),e("button",{class:"btn",onClick:()=>{Z.value={view:"project",id:r.projectId,section:"automation",kind:"missions"}},children:"Review opportunities"})]},r.id))]}):null}function hp({teams:t}){let s=t.filter(l=>l.status!=="archived").flatMap(l=>l.opportunities.filter(m=>["ready","proposed","blocked","accepted"].includes(m.status)).map(m=>({team:l,opportunity:m}))),n=[...s].sort((l,m)=>+(m.opportunity.status==="ready")-+(l.opportunity.status==="ready")||m.opportunity.impact-l.opportunity.impact||m.opportunity.createdAt-l.opportunity.createdAt).slice(0,3),[a,r]=h(""),[o,i]=h(""),d=async(l,m)=>{r(m.id),i("");try{await q(`/api/project-teams/${l.id}/opportunities/${m.id}`,{operationId:hr(),revision:l.revision,opportunityRevision:m.revision,action:"reject",note:"Dismissed from the project briefing"})}catch(c){i(c.message)}finally{r("")}};return e("section",{class:"project-briefing","aria-label":"Project briefing",children:[e("div",{class:"experience-kicker",children:"PROJECT BRIEFING"}),e("h2",{children:n.length?"Worth your attention":"No new opportunities to review"}),e("p",{class:"help",children:t.some(l=>l.status==="active")?"From your standing teams' recorded investigations. New discoveries appear here when a cycle completes.":"Connect and activate a standing team below to investigate a mission on your schedule."}),e("div",{class:"briefing-grid",children:n.map(({team:l,opportunity:m})=>e("article",{children:[e("span",{class:"badge",children:m.status==="ready"?"Verified draft":m.status}),e("h3",{children:m.title}),e("p",{children:m.benefit}),e("p",{class:"help",children:[m.users," \xB7 ",m.risk," risk \xB7 ",m.evidenceVerified?"Source quotes checked":"Evidence needs review"]}),e("details",{children:[e("summary",{children:"Why this matters"}),e("p",{children:m.problem}),e("p",{children:m.rationale}),m.evidence.slice(0,3).map((c,u)=>e("blockquote",{children:[e("code",{children:c.path}),e("pre",{children:c.quote})]},u)),e("p",{class:"help",children:["Source commit ",m.baseCommit.slice(0,12)]})]}),e("div",{class:"experience-actions",children:[m.result?e("a",{class:"btn small primary",href:`#/run/${m.result.runId}`,children:"Try and review draft"}):e("button",{class:"btn small",onClick:()=>document.getElementById(`opportunity-${m.id}`)?.scrollIntoView({block:"center",behavior:"smooth"}),children:"Review proposal"}),e("button",{class:"btn ghost small",disabled:!!a,onClick:()=>void d(l,m),children:"Dismiss opportunity"})]})]},m.id))}),s.length>3?e("p",{class:"help",children:[s.length-3," more opportunities are available in the team details below."]}):null,o?e("p",{role:"alert",children:o}):null]})}var Ul=t=>[...t].sort((s,n)=>s.name.localeCompare(n.name,void 0,{sensitivity:"base"})),Fl=t=>t.repos.length?t.repos.map(be).join(", "):"no repositories yet",yr=(t,s)=>`${t} ${s}${t===1?"":"s"}`,Hl=({text:t})=>e("span",{class:"pr-path",children:`\u200E${t}\u200E`});function Ks({composer:t=!1}){let s=t?fe.value.find(a=>a.id===Ct.value):Dn.value,n=t?s?.name??"Choose project":s?s.name:Ye.value===Bt?"Unassigned":"All projects";return e("button",{type:"button",class:"repo-btn project-btn",disabled:dt.value,title:t?"Choose the project's saved draft":"Filter projects",onClick:()=>{ts.value=t?"composer":"filter",zt.value=!0},children:[e(z,{name:"project"}),e("span",{class:"name",children:n}),e(z,{name:"chevron",class:"caret"})]})}function Wl(){let t=()=>{zt.value=!1,ws.value=null},s=we(!0,t),[n]=h(()=>ws.value==="new"?"new":fe.value.find(u=>u.id===ws.value)??null),[a,r]=h(n),o=()=>n?t():r(null),i=[...Ne.value.values()],d=u=>{let p=i.filter(f=>Ja(f,u));return{runs:p.filter(f=>!f.archived).length,archived:p.filter(f=>f.archived).length,waiting:p.filter(Ms).length}},l=async u=>{ts.value==="composer"?await st(u):va(u),t()},m=(u,p,f,v)=>{let g=d(u),w=(ts.value==="composer"?Ct.value:Ye.value)===u;return e("div",{class:`project-row ${w?"on":""}`,role:"listitem",children:[e("button",{type:"button",class:"pr-main","aria-current":w?"true":void 0,onClick:()=>l(u),children:[e("span",{class:"pr-name",children:[p,g.waiting?e("span",{class:"count",title:`${yr(g.waiting,"run")} need you`,children:g.waiting}):null]}),e("span",{class:"pr-detail",children:[f," \xB7 ",yr(g.runs,"run"),g.archived?` (+${g.archived} archived)`:""]})]}),v?e("button",{type:"button",class:"btn ghost small","aria-label":`Edit ${v.name}`,onClick:()=>r(v),children:"Edit"}):null]},u||"all")},c=d(Bt);return e("dialog",{class:"picker small-dialog projects-dialog",ref:s,"aria-labelledby":"projects-title",children:e("div",{class:"picker-inner",children:a?e(fp,{project:a==="new"?void 0:a,onDone:o,onCreated:t},a==="new"?"new":a.id):e(j,{children:[e("div",{class:"picker-head",children:[e("h3",{id:"projects-title",children:"Projects"}),e("div",{class:"help",children:ts.value==="composer"?"Open a project's saved draft. Each project keeps its own task and run options.":"Choose which projects these lists show. Your saved run draft keeps its own destination."})]}),e("div",{class:"picker-list",role:"list",children:[m(qs,ts.value==="composer"?"Unassigned draft":"All projects",ts.value==="composer"?"Recover a draft that needs a destination":"show all projects on this computer"),Ul(fe.value).map(u=>m(u.id,u.name,Fl(u),u)),ts.value!=="composer"&&(c.runs||c.archived)?m(Bt,"Unassigned","runs whose project was deleted"):null]}),e("div",{class:"picker-foot",children:[e("span",{class:"ps",children:fe.value.length?null:"Open a repository to create your first project."}),e("button",{class:"btn",type:"button",onClick:()=>r("new"),children:[e(z,{name:"plus"})," New project"]}),e("button",{class:"btn primary",type:"button",onClick:t,children:"Done"})]})]})})})}function fp({project:t,onDone:s,onCreated:n}){let[a]=h(()=>{let k=or.value;return or.value=null,k}),[r,o]=h(t?.name??a?.name??""),i=Q(null);_(()=>i.current?.focus(),[]);let[d,l]=h(t?.repos??(a?[]:ne.value?[ne.value]:[])),[m,c]=h(""),[u,p]=h(!1),f=t?[...Ne.value.values()].filter(k=>Xe(k)?.id===t.id):[],v=t?t.repos.filter(k=>!d.includes(k)&&f.some(y=>y.repo===k)):[],g=async()=>{if(!(u||!r.trim())){p(!0),c("");try{let k=await q(t?`/api/projects/${t.id}`:"/api/projects",{name:r,repos:d});if(await Cs(),t)return s();ts.value==="composer"?await st(k.id):Z.value={view:"project",id:k.id},n(),V(`Created the project ${k.name}`)}catch(k){c(k.message)}finally{p(!1)}}},w=async()=>{if(t&&await Ce(`Delete the project \u201C${t.name}\u201D? ${f.length?`Its ${yr(f.length,"run")} stay, in no project.`:"It has no runs."}`,{title:"Delete this project?",confirmLabel:"Delete project",danger:!0}))try{await U(`/api/projects/${t.id}`,{method:"DELETE"}),await Cs(),V(`Deleted the project ${t.name}`),s()}catch(k){c(k.message)}},C=()=>{Ln.value={title:`Add a repository to ${r.trim()||"the project"}`,choose:k=>U(`/api/branches?repo=${encodeURIComponent(k)}`).then(y=>l(b=>b.includes(y.repo)?b:[...b,y.repo]),()=>c(`${be(k)} isn't a git repository`))},wt.value=!0};return e(j,{children:[e("div",{class:"picker-head",children:[e("h3",{id:"projects-title",children:t?`Edit ${t.name}`:"New project"}),e("div",{class:"help",children:t?`${yr(f.length,"run")} in this project.`:"Name it and add the repositories its runs work in."})]}),e("div",{class:"dialog-body",children:[t?null:e("div",{class:"project-computer",children:[e("span",{class:"lbl",children:"Computer"}),e(ir,{projectName:r}),e("p",{class:"help",children:"Choose where this project lives, then add repositories from that computer."})]}),e("div",{children:[e("label",{class:"lbl",for:"project-name",children:"Name"}),e("input",{id:"project-name",ref:i,class:"field",value:r,maxLength:60,placeholder:"e.g. Web app",onInput:k=>o(k.currentTarget.value),onKeyDown:k=>k.key==="Enter"&&(k.preventDefault(),void g())})]}),e("div",{children:[e("div",{class:"lbl",children:"Repositories"}),e("div",{class:"project-repos",children:[d.map(k=>e("div",{class:"dir",title:k,children:[e("span",{class:"di",children:e(z,{name:"folder"})}),e("span",{class:"dn",children:be(k)}),e(Hl,{text:k}),e("button",{type:"button",class:"btn ghost small","aria-label":`Remove ${be(k)}`,onClick:()=>l(d.filter(y=>y!==k)),children:"Remove"})]},k)),d.length?null:e("div",{class:"help",children:"Add a repository before starting a run. You can also keep an empty project for shared work."})]}),e("button",{type:"button",class:"btn ghost small add-repo",onClick:C,children:[e(z,{name:"plus"})," Add repository\u2026"]})]}),v.length?e("div",{class:"msg warn",children:["Runs already in this project from ",v.map(be).join(", ")," stay in it."]}):null,m?e("div",{class:"msg err",children:m}):null]}),e("div",{class:"picker-foot",children:[t?e("button",{type:"button",class:"btn danger",onClick:w,children:"Delete project"}):null,e("span",{class:"ps"}),e("button",{type:"button",class:"btn",onClick:s,children:"Cancel"}),e("button",{type:"button",class:"btn primary",disabled:u||!r.trim(),onClick:g,children:u?"Saving\u2026":t?"Save":"Create project"})]})]})}function Vl({run:t}){let[s,n]=h(!1),a=Xe(t);return e(j,{children:[e("button",{type:"button",class:"project-chip",title:"Move this run to another project",onClick:()=>n(!0),children:[e(z,{name:"project"})," ",a?a.name:"No project"]}),s?e(gp,{run:t,onClose:()=>n(!1)}):null]})}function gp({run:t,onClose:s}){let n=we(!0,s),a=Xe(t)?.id,[r,o]=h(a??""),[i,d]=h(""),[l,m]=h(""),[c,u]=h(!1),p=fe.value.find(g=>g.id===r),f=Q(null);_(()=>void(r==="new"&&f.current?.focus()),[r]);let v=async()=>{u(!0),m("");try{let g=r==="new"?(await q("/api/projects",{name:i,repos:[t.repo]})).id:r,w=await q(`/api/runs/${t.id}/project`,{project:g});await Cs(),V(`Moved to ${w.name}`),s()}catch(g){m(g.message)}finally{u(!1)}};return e("dialog",{class:"picker small-dialog",ref:n,"aria-labelledby":"move-title",children:e("div",{class:"picker-inner",children:[e("div",{class:"picker-head",children:[e("h3",{id:"move-title",children:"Move to another project"}),e("div",{class:"help",children:"The run, its branches and its worktrees stay where they are; only the project it's listed under changes."})]}),e("div",{class:"picker-list",role:"radiogroup","aria-label":"Project",children:[Ul(fe.value).map(g=>e("label",{class:"dir move-choice",children:[e("input",{type:"radio",name:"move-to",checked:r===g.id,onChange:()=>o(g.id)}),e("span",{class:"dn",children:[g.name,g.id===a?e("span",{class:"help",children:" \xB7 now"}):null]}),e(Hl,{text:Fl(g)})]},g.id)),e("label",{class:"dir move-choice",children:[e("input",{type:"radio",name:"move-to",checked:r==="new",onChange:()=>o("new")}),e("span",{class:"dn",children:"New project"}),r==="new"?e("input",{ref:f,class:"field","aria-label":"New project's name",placeholder:"Name",maxLength:60,value:i,onInput:g=>d(g.currentTarget.value)}):null]})]}),e("div",{class:"picker-foot",children:[e("span",{class:"ps",children:l?e("span",{class:"msg err",children:l}):p&&!p.repos.includes(t.repo)?`${be(t.repo)} joins ${p.name}.`:null}),e("button",{type:"button",class:"btn",onClick:s,children:"Cancel"}),e("button",{type:"button",class:"btn primary",disabled:c||!r||r===a||r==="new"&&!i.trim(),onClick:v,children:"Move"})]})]})})}function Gs(t){Ln.value={title:"Open repository",choose:s=>{Ka(s,t??"")}},wt.value=!0}function zl(){let t=ks.value,[s,n]=h(be(t.repository).slice(0,60)),[a,r]=h(!1),[o,i]=h(""),d=()=>{a||(ks.value=null)},l=we(!0,d),m=fe.value.find(p=>p.id===t.project),c=fe.value.filter(p=>p.repos.includes(t.repository)),u=async(p,f=!1)=>{if(!a){r(!0),i("");try{let v=p;if(f&&p&&await q(`/api/projects/${encodeURIComponent(p)}/repositories`,{repo:t.repository}),v||(v=(await q("/api/projects",{name:s.trim(),repos:[t.repository]})).id),await Cs(),!await st(v,{repository:t.repository,carryUnassigned:!0}))throw new Error("The project draft could not be opened. Try again.");await nr(t.repository),ks.value=null}catch(v){i(v.message)}finally{r(!1)}}};return e("dialog",{class:"picker small-dialog",ref:l,"aria-labelledby":"repository-project-title",children:e("div",{class:"picker-inner",children:[e("div",{class:"picker-head",children:[e("h3",{id:"repository-project-title",children:"Open repository in a project"}),e("p",{class:"help",children:e("code",{children:t.repository})})]}),e("div",{class:"dialog-body",children:[c.length?e("div",{class:"project-destinations",children:[e("p",{children:"Choose an existing project:"}),c.map(p=>e("button",{class:"btn",disabled:a,onClick:()=>void u(p.id),children:["Open ",p.name]}))]}):null,m&&!m.repos.includes(t.repository)?e("div",{class:"project-destinations",children:[e("button",{class:"btn",disabled:a,onClick:()=>void u(m.id,!0),children:["Add to ",m.name]}),e("p",{class:"help",children:"This repository becomes part of the project. Existing project access rules apply."})]}):null,e("label",{class:"lbl",for:"repository-project-name",children:"New project name"}),e("input",{id:"repository-project-name",class:"field",maxLength:60,value:s,disabled:a,onInput:p=>n(p.currentTarget.value)}),e("p",{class:"help",children:"The project keeps its own draft and run history. No agent starts until you select Start run."}),o?e("p",{class:"msg err",role:"alert",children:o}):null]}),e("div",{class:"picker-foot",children:[e("button",{class:"btn",disabled:a,onClick:d,children:"Cancel"}),e("button",{class:"btn primary",disabled:a||!s.trim(),onClick:()=>void u(),children:a?"Opening\u2026":"Create project"})]})]})})}var gn=(t=>(t[t.Border=-1]="Border",t[t.Data=0]="Data",t[t.Function=1]="Function",t[t.Position=2]="Position",t[t.Timing=3]="Timing",t[t.Alignment=4]="Alignment",t))(gn||{}),vp=[0,1],Kl=[1,0],Gl=[2,3],Yl=[3,2],bp={L:vp,M:Kl,Q:Gl,H:Yl},yp=/^\d*$/,kp=/^[A-Z0-9 $%*+./:-]*$/,Ao="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:",Mo=1,Lo=40,Jl=3,wp=3,kr=40,Cp=10,Ql=[[-1,7,10,15,20,26,18,20,24,30,18,20,24,26,30,22,24,28,30,28,28,28,28,30,30,26,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,10,16,26,18,24,16,18,22,22,26,30,22,22,24,24,28,28,26,26,26,26,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28],[-1,13,22,18,26,18,24,18,22,20,24,28,26,24,20,30,24,28,28,26,30,28,30,30,30,30,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,17,28,22,16,22,28,26,26,24,28,24,28,22,24,24,30,28,28,26,28,30,24,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30]],Xl=[[-1,1,1,1,1,1,2,2,2,2,4,4,4,4,4,6,6,6,6,7,8,8,9,9,10,12,12,12,13,14,15,16,17,18,19,19,20,21,22,24,25],[-1,1,1,1,2,2,4,4,4,5,5,5,8,9,9,10,10,11,13,14,16,17,17,18,20,21,23,25,26,28,29,31,33,35,37,38,40,43,45,47,49],[-1,1,1,2,2,4,4,6,6,8,8,8,10,12,16,12,17,16,18,21,20,23,23,25,27,29,34,34,35,38,40,43,45,48,51,53,56,59,62,65,68],[-1,1,1,2,4,4,4,5,6,8,8,11,11,16,16,18,16,19,21,25,25,25,34,30,32,35,37,40,42,45,48,51,54,57,60,63,66,70,74,77,81]],Eo=class{constructor(s,n,a,r){if(this.version=s,this.ecc=n,s<Mo||s>Lo)throw new RangeError("Version value out of range");if(r<-1||r>7)throw new RangeError("Mask value out of range");this.size=s*4+17;let o=Array.from({length:this.size}).fill(!1);for(let d=0;d<this.size;d++)this.modules.push(o.slice()),this.types.push(o.map(()=>0));this.drawFunctionPatterns();let i=this.addEccAndInterleave(a);if(this.drawCodewords(i),r===-1){let d=1e9;for(let l=0;l<8;l++){this.applyMask(l),this.drawFormatBits(l);let m=this.getPenaltyScore();m<d&&(r=l,d=m),this.applyMask(l)}}this.mask=r,this.applyMask(r),this.drawFormatBits(r)}size;mask;modules=[];types=[];getModule(s,n){return s>=0&&s<this.size&&n>=0&&n<this.size&&this.modules[n][s]}drawFunctionPatterns(){for(let a=0;a<this.size;a++)this.setFunctionModule(6,a,a%2===0,gn.Timing),this.setFunctionModule(a,6,a%2===0,gn.Timing);this.drawFinderPattern(3,3),this.drawFinderPattern(this.size-4,3),this.drawFinderPattern(3,this.size-4);let s=this.getAlignmentPatternPositions(),n=s.length;for(let a=0;a<n;a++)for(let r=0;r<n;r++)a===0&&r===0||a===0&&r===n-1||a===n-1&&r===0||this.drawAlignmentPattern(s[a],s[r]);this.drawFormatBits(0),this.drawVersion()}drawFormatBits(s){let n=this.ecc[1]<<3|s,a=n;for(let o=0;o<10;o++)a=a<<1^(a>>>9)*1335;let r=(n<<10|a)^21522;for(let o=0;o<=5;o++)this.setFunctionModule(8,o,$s(r,o));this.setFunctionModule(8,7,$s(r,6)),this.setFunctionModule(8,8,$s(r,7)),this.setFunctionModule(7,8,$s(r,8));for(let o=9;o<15;o++)this.setFunctionModule(14-o,8,$s(r,o));for(let o=0;o<8;o++)this.setFunctionModule(this.size-1-o,8,$s(r,o));for(let o=8;o<15;o++)this.setFunctionModule(8,this.size-15+o,$s(r,o));this.setFunctionModule(8,this.size-8,!0)}drawVersion(){if(this.version<7)return;let s=this.version;for(let a=0;a<12;a++)s=s<<1^(s>>>11)*7973;let n=this.version<<12|s;for(let a=0;a<18;a++){let r=$s(n,a),o=this.size-11+a%3,i=Math.floor(a/3);this.setFunctionModule(o,i,r),this.setFunctionModule(i,o,r)}}drawFinderPattern(s,n){for(let a=-4;a<=4;a++)for(let r=-4;r<=4;r++){let o=Math.max(Math.abs(r),Math.abs(a)),i=s+r,d=n+a;i>=0&&i<this.size&&d>=0&&d<this.size&&this.setFunctionModule(i,d,o!==2&&o!==4,gn.Position)}}drawAlignmentPattern(s,n){for(let a=-2;a<=2;a++)for(let r=-2;r<=2;r++)this.setFunctionModule(s+r,n+a,Math.max(Math.abs(r),Math.abs(a))!==1,gn.Alignment)}setFunctionModule(s,n,a,r=gn.Function){this.modules[n][s]=a,this.types[n][s]=r}addEccAndInterleave(s){let n=this.version,a=this.ecc;if(s.length!==wr(n,a))throw new RangeError("Invalid argument");let r=Xl[a[0]][n],o=Ql[a[0]][n],i=Math.floor(Po(n)/8),d=r-i%r,l=Math.floor(i/r),m=[],c=Pp(o);for(let p=0,f=0;p<r;p++){let v=s.slice(f,f+l-o+(p<d?0:1));f+=v.length;let g=jp(v,c);p<d&&v.push(0),m.push(v.concat(g))}let u=[];for(let p=0;p<m[0].length;p++)m.forEach((f,v)=>{(p!==l-o||v>=d)&&u.push(f[p])});return u}drawCodewords(s){if(s.length!==Math.floor(Po(this.version)/8))throw new RangeError("Invalid argument");let n=0;for(let a=this.size-1;a>=1;a-=2){a===6&&(a=5);for(let r=0;r<this.size;r++)for(let o=0;o<2;o++){let i=a-o,l=(a+1&2)===0?this.size-1-r:r;!this.types[l][i]&&n<s.length*8&&(this.modules[l][i]=$s(s[n>>>3],7-(n&7)),n++)}}}applyMask(s){if(s<0||s>7)throw new RangeError("Mask value out of range");for(let n=0;n<this.size;n++)for(let a=0;a<this.size;a++){let r;switch(s){case 0:r=(a+n)%2===0;break;case 1:r=n%2===0;break;case 2:r=a%3===0;break;case 3:r=(a+n)%3===0;break;case 4:r=(Math.floor(a/3)+Math.floor(n/2))%2===0;break;case 5:r=a*n%2+a*n%3===0;break;case 6:r=(a*n%2+a*n%3)%2===0;break;case 7:r=((a+n)%2+a*n%3)%2===0;break;default:throw new Error("Unreachable")}!this.types[n][a]&&r&&(this.modules[n][a]=!this.modules[n][a])}}getPenaltyScore(){let s=0;for(let o=0;o<this.size;o++){let i=!1,d=0,l=[0,0,0,0,0,0,0];for(let m=0;m<this.size;m++)this.modules[o][m]===i?(d++,d===5?s+=Jl:d>5&&s++):(this.finderPenaltyAddHistory(d,l),i||(s+=this.finderPenaltyCountPatterns(l)*kr),i=this.modules[o][m],d=1);s+=this.finderPenaltyTerminateAndCount(i,d,l)*kr}for(let o=0;o<this.size;o++){let i=!1,d=0,l=[0,0,0,0,0,0,0];for(let m=0;m<this.size;m++)this.modules[m][o]===i?(d++,d===5?s+=Jl:d>5&&s++):(this.finderPenaltyAddHistory(d,l),i||(s+=this.finderPenaltyCountPatterns(l)*kr),i=this.modules[m][o],d=1);s+=this.finderPenaltyTerminateAndCount(i,d,l)*kr}for(let o=0;o<this.size-1;o++)for(let i=0;i<this.size-1;i++){let d=this.modules[o][i];d===this.modules[o][i+1]&&d===this.modules[o+1][i]&&d===this.modules[o+1][i+1]&&(s+=wp)}let n=0;for(let o of this.modules)n=o.reduce((i,d)=>i+(d?1:0),n);let a=this.size*this.size,r=Math.ceil(Math.abs(n*20-a*10)/a)-1;return s+=r*Cp,s}getAlignmentPatternPositions(){if(this.version===1)return[];{let s=Math.floor(this.version/7)+2,n=this.version===32?26:Math.ceil((this.version*4+4)/(s*2-2))*2,a=[6];for(let r=this.size-7;a.length<s;r-=n)a.splice(1,0,r);return a}}finderPenaltyCountPatterns(s){let n=s[1],a=n>0&&s[2]===n&&s[3]===n*3&&s[4]===n&&s[5]===n;return(a&&s[0]>=n*4&&s[6]>=n?1:0)+(a&&s[6]>=n*4&&s[0]>=n?1:0)}finderPenaltyTerminateAndCount(s,n,a){return s&&(this.finderPenaltyAddHistory(n,a),n=0),n+=this.size,this.finderPenaltyAddHistory(n,a),this.finderPenaltyCountPatterns(a)}finderPenaltyAddHistory(s,n){n[0]===0&&(s+=this.size),n.pop(),n.unshift(s)}};function Is(t,s,n){if(s<0||s>31||t>>>s)throw new RangeError("Value out of range");for(let a=s-1;a>=0;a--)n.push(t>>>a&1)}function $s(t,s){return(t>>>s&1)!==0}var wa=class{constructor(s,n,a){if(this.mode=s,this.numChars=n,this.bitData=a,n<0)throw new RangeError("Invalid argument");this.bitData=a.slice()}getData(){return this.bitData.slice()}},Tp=[1,10,12,14],Sp=[2,9,11,13],xp=[4,8,16,16];function Zl(t,s){return t[Math.floor((s+7)/17)+1]}function ec(t){let s=[];for(let n of t)Is(n,8,s);return new wa(xp,t.length,s)}function Rp(t){if(!tc(t))throw new RangeError("String contains non-numeric characters");let s=[];for(let n=0;n<t.length;){let a=Math.min(t.length-n,3);Is(Number.parseInt(t.substring(n,n+a),10),a*3+1,s),n+=a}return new wa(Tp,t.length,s)}function $p(t){if(!sc(t))throw new RangeError("String contains unencodable characters in alphanumeric mode");let s=[],n;for(n=0;n+2<=t.length;n+=2){let a=Ao.indexOf(t.charAt(n))*45;a+=Ao.indexOf(t.charAt(n+1)),Is(a,11,s)}return n<t.length&&Is(Ao.indexOf(t.charAt(n)),6,s),new wa(Sp,t.length,s)}function Ip(t){return t===""?[]:tc(t)?[Rp(t)]:sc(t)?[$p(t)]:[ec(Ep(t))]}function tc(t){return yp.test(t)}function sc(t){return kp.test(t)}function Ap(t,s){let n=0;for(let a of t){let r=Zl(a.mode,s);if(a.numChars>=1<<r)return Number.POSITIVE_INFINITY;n+=4+r+a.bitData.length}return n}function Ep(t){t=encodeURI(t);let s=[];for(let n=0;n<t.length;n++)t.charAt(n)!=="%"?s.push(t.charCodeAt(n)):(s.push(Number.parseInt(t.substring(n+1,n+3),16)),n+=2);return s}function Po(t){if(t<Mo||t>Lo)throw new RangeError("Version number out of range");let s=(16*t+128)*t+64;if(t>=2){let n=Math.floor(t/7)+2;s-=(25*n-10)*n-55,t>=7&&(s-=36)}return s}function wr(t,s){return Math.floor(Po(t)/8)-Ql[s[0]][t]*Xl[s[0]][t]}function Pp(t){if(t<1||t>255)throw new RangeError("Degree out of range");let s=[];for(let a=0;a<t-1;a++)s.push(0);s.push(1);let n=1;for(let a=0;a<t;a++){for(let r=0;r<s.length;r++)s[r]=jo(s[r],n),r+1<s.length&&(s[r]^=s[r+1]);n=jo(n,2)}return s}function jp(t,s){let n=s.map(a=>0);for(let a of t){let r=a^n.shift();n.push(0),s.forEach((o,i)=>n[i]^=jo(o,r))}return n}function jo(t,s){if(t>>>8||s>>>8)throw new RangeError("Byte out of range");let n=0;for(let a=7;a>=0;a--)n=n<<1^(n>>>7)*285,n^=(s>>>a&1)*t;return n}function Mp(t,s,n=1,a=40,r=-1,o=!0){if(!(Mo<=n&&n<=a&&a<=Lo)||r<-1||r>7)throw new RangeError("Invalid value");let i,d;for(i=n;;i++){let u=wr(i,s)*8,p=Ap(t,i);if(p<=u){d=p;break}if(i>=a)throw new RangeError("Data too long")}for(let u of[Kl,Gl,Yl])o&&d<=wr(i,u)*8&&(s=u);let l=[];for(let u of t){Is(u.mode[0],4,l),Is(u.numChars,Zl(u.mode,i),l);for(let p of u.getData())l.push(p)}let m=wr(i,s)*8;Is(0,Math.min(4,m-l.length),l),Is(0,(8-l.length%8)%8,l);for(let u=236;l.length<m;u^=253)Is(u,8,l);let c=Array.from({length:Math.ceil(l.length/8)},()=>0);return l.forEach((u,p)=>c[p>>>3]|=u<<7-(p&7)),new Eo(i,s,c,r)}function nc(t,s){let{ecc:n="L",boostEcc:a=!1,minVersion:r=1,maxVersion:o=40,maskPattern:i=-1,border:d=1}=s||{},l=typeof t=="string"?Ip(t):Array.isArray(t)?[ec(t)]:void 0;if(!l)throw new Error(`uqr only supports encoding string and binary data, but got: ${typeof t}`);let m=Mp(l,bp[n],r,o,i,a),c=Lp({version:m.version,maskPattern:m.mask,size:m.size,data:m.modules,types:m.types},d);return s?.invert&&(c.data=c.data.map(u=>u.map(p=>!p))),s?.onEncoded?.(c),c}function Lp(t,s=1){if(!s)return t;let{size:n}=t,a=n+s*2;t.size=a,t.data.forEach(o=>{for(let i=0;i<s;i++)o.unshift(!1),o.push(!1)});for(let o=0;o<s;o++)t.data.unshift(Array.from({length:a},i=>!1)),t.data.push(Array.from({length:a},i=>!1));let r=gn.Border;t.types.forEach(o=>{for(let i=0;i<s;i++)o.unshift(r),o.push(r)});for(let o=0;o<s;o++)t.types.unshift(Array.from({length:a},i=>r)),t.types.push(Array.from({length:a},i=>r));return t}function Cr({cantRun:t}){return e("div",{class:"cant-run",children:["The check can't run here: ",e("code",{children:t.reason}),". Set ",e("code",{children:"setup"})," and ",e("code",{children:"check"})," in ",e("code",{children:".codeflow/config.json"}),".",e("div",{class:"cr-why",children:"That's the environment, not the change: it fails on the base commit too. So no fix rounds were spent on it, and whether the change works is unknown."})]})}function $e({id:t,note:s}){return t?e("span",{class:`agent ${t}`,children:[De[t]??t,s?e("span",{class:"model",children:[" ",s]}):null]}):null}function ac({text:t,size:s=168}){let n=nc(t,{ecc:"M",border:0}),a=4,r=n.size+a*2,o="";return n.data.forEach((i,d)=>i.forEach((l,m)=>l&&(o+=`M${m+a} ${d+a}h1v1h-1z`))),e("svg",{class:"qr",width:s,height:s,viewBox:`0 0 ${r} ${r}`,"shape-rendering":"crispEdges",role:"img","aria-label":`QR code for ${t}`,children:[e("rect",{width:r,height:r,fill:"#fff"}),e("path",{d:o,fill:"#1a1b16"})]})}function Oe({text:t}){let s=Rn(()=>Dp(t),[t]);return e("div",{class:"md",children:s})}function Dp(t){let s=[];return t.split(/^```[^\n]*\n?/m).forEach((n,a)=>{a%2===1?s.push(e("pre",{children:n.replace(/\n$/,"")},`c${a}`)):Np(n,`b${a}`,s)}),s}var No=/^(\s*)([-*+]|\d+[.)])\s+(.*)/,rc=/^\s*([-*_])(\s*\1){2,}\s*$/,oc=/^\s*\|?\s*:?-{2,}:?\s*(\|\s*:?-{2,}:?\s*)*\|?\s*$/;function Np(t,s,n){let a=t.split(`
31
+ `),r=0,o=()=>`${s}-${r}`;for(;r<a.length;){let i=a[r];if(!i.trim()){r++;continue}let d=i.match(/^(#{1,6})\s+(.*)/);if(d){n.push(d[1].length<=2?e("h3",{children:Vn(d[2])},o()):e("h4",{children:Vn(d[2])},o())),r++;continue}if(rc.test(i)){n.push(e("hr",{},o())),r++;continue}if(No.test(i)){let c=/^\s*\d/.test(i),u=[],p=o();for(;r<a.length;){let v=a[r].match(No);if(!v){if(u.length&&/^\s{2,}\S/.test(a[r]))u.at(-1).lines.push(a[r++].trim());else break;continue}let g=Math.min(3,Math.floor(v[1].replace(/\t/g," ").length/2)),w=/\d/.test(v[2])?parseInt(v[2],10):void 0;if(!g&&w!==void 0!==c)break;u.push({depth:g,num:w,lines:[v[3]]}),r++}let f=u.map((v,g)=>e("li",{value:c&&!v.depth?v.num:void 0,class:`${v.depth?`d${v.depth}`:""} ${v.num===void 0?"bullet":"num"}`,children:Do(v.lines)},g));n.push(c?e("ol",{children:f},p):e("ul",{children:f},p));continue}if(i.trimStart().startsWith(">")){let c=[],u=o();for(;r<a.length&&a[r].trimStart().startsWith(">");)c.push(a[r++].trimStart().replace(/^>\s?/,""));n.push(e("blockquote",{children:Do(c)},u));continue}if(i.includes("|")&&oc.test(a[r+1]??"")){let c=o(),u=v=>v.trim().replace(/^\|/,"").replace(/\|$/,"").split("|").map(g=>g.trim()),p=u(i);r+=2;let f=[];for(;r<a.length&&a[r].includes("|")&&a[r].trim();)f.push(u(a[r++]));n.push(e("div",{class:"md-table",children:e("table",{children:[e("thead",{children:e("tr",{children:p.map((v,g)=>e("th",{children:Vn(v)},g))})}),e("tbody",{children:f.map((v,g)=>e("tr",{children:p.map((w,C)=>e("td",{children:Vn(v[C]??"")},C))},g))})]})},c));continue}let l=[],m=o();for(;r<a.length&&a[r].trim()&&!Op(a,r);)l.push(a[r++]);l.length||l.push(a[r++]),n.push(e("p",{children:Do(l)},m))}}var Op=(t,s)=>{let n=t[s];return/^#{1,6}\s/.test(n)||rc.test(n)||No.test(n)||n.trimStart().startsWith(">")||n.includes("|")&&oc.test(t[s+1]??"")},Do=t=>t.flatMap((s,n)=>n?[e("br",{},`br${n}`),...Vn(s)]:Vn(s));function Vn(t){return t.split(/(`[^`]+`|\*\*[^*]+\*\*|__[^_]+__|\[[^\]]+\]\(https?:\/\/[^\s)]+\)|(?<![\w*])\*[^*\s][^*]*\*(?![\w*])|(?<![\w_])_[^_\s][^_]*_(?![\w_]))/).map((s,n)=>{if(s.length>1&&s.startsWith("`")&&s.endsWith("`"))return e("code",{children:s.slice(1,-1)},n);if(s.startsWith("**")&&s.endsWith("**")||s.startsWith("__")&&s.endsWith("__"))return e("b",{children:s.slice(2,-2)},n);let a=s.match(/^\[([^\]]+)\]\((https?:\/\/[^\s)]+)\)$/);return a?e("a",{href:a[2],target:"_blank",rel:"noreferrer",children:a[1]},n):s.length>2&&(s.startsWith("*")&&s.endsWith("*")||s.startsWith("_")&&s.endsWith("_"))?e("i",{children:s.slice(1,-1)},n):s})}var Tr=t=>t.charAt(0).toUpperCase()+t.slice(1);function ic({providers:t}){let[s,n]=h(null),[a,r]=h(!1),[o,i]=h("");return _(()=>{if(!a)return;let d=!0;return i(""),U("/api/team-capabilities").then(l=>{d&&n(l)},l=>{d&&i(l.message)}),()=>{d=!1}},[a]),e("details",{class:"at-section",onToggle:d=>r(d.currentTarget.open),children:[e("summary",{children:"Agent collaboration capabilities"}),o?e("p",{class:"help",children:o}):s?e(j,{children:[e("div",{class:"table-wrap",children:e("table",{class:"ins-table",children:[e("thead",{children:e("tr",{children:[e("th",{children:"Provider"}),e("th",{children:"Member tools"}),e("th",{children:"Live input"}),e("th",{children:"Native child controls"}),e("th",{children:"Child usage"})]})}),e("tbody",{children:s.filter(d=>t.includes(d.provider)).map(d=>e("tr",{children:[e("td",{children:[De[d.provider]??d.provider,e("div",{class:"help",children:d.version??"Version unknown"})]}),e("td",{children:Tr(d.scopedTools)}),e("td",{children:Tr(d.liveInput)}),e("td",{children:Tr(d.nestedAgentControl)}),e("td",{children:Tr(d.nestedUsage)})]},d.provider))})]})}),e("p",{class:"help",children:"Unsupported live tools use queued messages and structured outcomes. Protocol tests and installed CLI probes establish capability; separate child-agent usage is unknown."})]}):e("p",{class:"help",children:"Checking installed CLI capabilities\u2026"})]})}function Oo(){let t=ma.value;return t?e("section",{class:"at-notice","aria-label":"Auto team availability",children:[e("b",{children:["Auto team \xB7 ",t.enabled?`evaluation: ${t.stage}`:"new runs disabled"]}),e("p",{children:t.reason}),e("a",{href:"#/insights",children:"View evaluation evidence"})]}):null}function lc({runId:t,running:s}){let[n,a]=h(null),[r,o]=h(""),[i,d]=h(!1);return _(()=>{if(!i)return;let l=!0,c=Je(()=>U(`/api/runs/${encodeURIComponent(t)}/evaluation`).then(u=>{l&&(a(u),o(""))},u=>{l&&o(u.message)}),s?5e3:0);return()=>{l=!1,c()}},[t,s,i]),e("details",{class:"at-section",onToggle:l=>d(l.currentTarget.open),children:[e("summary",{children:"Coordination and recovery measurements"}),r?e("p",{class:"help",children:["Measurements unavailable: ",r]}):n?e(j,{children:[e("div",{class:"at-metrics",children:[e("span",{children:["Coordinator calls: ",e("b",{children:n.metrics.coordinatorFraction===null?"unknown":js(n.metrics.coordinatorFraction,1)})," of all invocations"]}),e("span",{children:["Peer questions: ",e("b",{children:n.metrics.peerQuestions})]}),e("span",{children:["Peer wait: ",e("b",{children:n.metrics.peerWaitingMs===void 0?"not measured":Le(n.metrics.peerWaitingMs)})]}),e("span",{children:["Dispatch delay after an answer: ",e("b",{children:n.metrics.avoidableBarrierEstimateMs===void 0?"not measured":Le(n.metrics.avoidableBarrierEstimateMs)})]}),e("span",{children:["Worker turns: ",e("b",{children:n.metrics.workerTurns})]}),e("span",{children:["Repair turns: ",e("b",{children:n.metrics.repairTurns})]})]}),n.metrics.replay?e("p",{class:"help",children:[n.metrics.replay.kind==="journal-load"?"Journal load":"Execution replay",": ",n.metrics.replay.durationMs.toFixed(1)," ms \xB7 ",Ht(n.metrics.replay.bytes)," \xB7 ",n.metrics.replay.records," records"]}):e("p",{class:"help",children:"Recovery has not been measured for this run."}),e("p",{class:"help",children:["Peer wait excludes questions to you. Dispatch delay is the time from an answer arriving to the next turn of its task, not a measured speedup. ",n.mode==="unknown"?"This run has not been registered as a controlled evaluation.":`Evaluation source: ${n.mode}.`]})]}):e("p",{class:"help",children:"Loading measurements\u2026"})]})}function cc(){let[t,s]=h(null),[n,a]=h(""),[r,o]=h(new Set),[i,d]=h("experimental"),[l,m]=h(""),[c,u]=h(!1),p=async()=>{try{s(await U("/api/team-evaluations")),a("")}catch(v){a(v.message)}};_(()=>{p()},[]);let f=async()=>{if(!(!l.trim()||c)){u(!0);try{await q("/api/team-rollout",{stage:i,rationale:l,evaluationIds:[...r]}),await Promise.all([p(),rl()]),m("")}catch(v){a(v.message)}finally{u(!1)}}};return e("section",{class:"ins-section","aria-label":"Team evaluations",children:[e("h2",{children:"Auto team evaluation"}),e("p",{class:"help",children:"Controlled local comparisons use the same task and starting commit. Fake trials verify behavior; only explicitly recorded real CLI trials inform rollout. These records cover this installation, across projects."}),e(Oo,{}),n?e("p",{class:"msg err",role:"alert",children:n}):null,e("button",{class:"btn small",onClick:p,children:"Refresh evaluations"}),t?e(j,{children:[e("div",{class:"at-metrics",children:[e("span",{children:[e("b",{children:t.assessment.realAutoRuns})," real Auto runs"]}),e("span",{children:[e("b",{children:t.assessment.realWorkerTurns})," real worker turns"]}),e("span",{children:[e("b",{children:t.assessment.matchedPairs})," matched comparisons"]}),e("span",{children:["Multi-worker coordination: ",e("b",{children:t.assessment.overheadFraction===null?"unknown":js(t.assessment.overheadFraction,1)})]})]}),t.reports.length?e("div",{class:"table-wrap",children:e("table",{class:"ins-table",children:[e("thead",{children:e("tr",{children:[e("th",{children:"Evidence"}),e("th",{children:"Trial"}),e("th",{children:"Pattern"}),e("th",{children:"Verified"}),e("th",{class:"num",children:"Calls"}),e("th",{class:"num",children:"Coordinator"}),e("th",{class:"num",children:"Peer wait"})]})}),e("tbody",{children:t.reports.map(v=>e("tr",{children:[e("td",{children:[e("input",{type:"checkbox","aria-label":`Use evaluation ${v.id}`,checked:r.has(v.id),onChange:g=>o(w=>{let C=new Set(w);return g.currentTarget.checked?C.add(v.id):C.delete(v.id),C})}),e("span",{class:`badge ${v.mode==="real"?"":"warn"}`,children:v.mode.charAt(0).toUpperCase()+v.mode.slice(1)})]}),e("td",{children:[e("b",{children:v.caseId}),e("div",{class:"help",children:[v.pairId??"unpaired"," \xB7 ",v.runId]})]}),e("td",{children:v.pattern}),e("td",{children:v.verified?"Yes":"No"}),e("td",{class:"num",children:v.metrics.invocations}),e("td",{class:"num",children:v.metrics.coordinatorFraction===null?"unknown":js(v.metrics.coordinatorFraction,1)}),e("td",{class:"num",children:v.metrics.peerWaitingMs===void 0?"unknown":Le(v.metrics.peerWaitingMs)})]},v.id))})]})}):e("p",{class:"help",children:["No controlled trials recorded. Use ",e("code",{children:"npm run evaluate:teams -- --fake"})," to validate the harness, or ",e("code",{children:"--real"})," for bounded trials with your signed-in CLIs."]}),e("details",{children:[e("summary",{children:"Rollout decision and requirements"}),e("p",{class:"help",children:"An explicit decision is required. The server checks selected real evidence before allowing beta or default. Missing results and unverified outcomes cannot become passes."}),t.assessment.blockers.length?e("ul",{children:t.assessment.blockers.map(v=>e("li",{children:v},v))}):e("p",{children:"Recorded evidence meets the default criteria."}),e("label",{children:["Requested stage",e("select",{class:"field","aria-label":"Auto team rollout stage",value:i,onChange:v=>d(v.currentTarget.value),children:[e("option",{value:"experimental",children:"Experimental"}),e("option",{value:"beta",children:"Opt-in beta"}),e("option",{value:"default",children:"Default for new users"})]})]}),e("label",{children:["Decision rationale",e("textarea",{class:"field","aria-label":"Rollout rationale",rows:3,maxLength:4e3,value:l,onInput:v=>m(v.currentTarget.value)})]}),e("button",{class:"btn small",disabled:c||!l.trim(),onClick:f,children:c?"Recording\u2026":"Record rollout decision"}),t.rollout.decision?e("p",{class:"help",children:["Last decision: ",new Date(t.rollout.decision.at).toLocaleString()," \xB7 ",t.rollout.decision.rationale]}):null]})]}):null]})}var _o=t=>ve.value.find(s=>s.id===t)?.name??t,Bo={7:7,30:30,all:0};function pc({group:t}){let[s,n]=h(!1),a=pr.value,r=a?vn(ve.value.find(b=>b.id===a.pattern),a.roles)||(a.task.trim()?"":"Describe a task in New run first."):"Configure a task in New run first.",o=Dn.value,i=!!o||Ye.value===Bt,d=!!ne.value&&!(o?.repos.length===1&&o.repos[0]===ne.value),[l,m]=h(i?"project":ne.value?"repo":"all");_(()=>m(i?"project":ne.value?"repo":"all"),[Ye.value,i]);let c=l==="project"&&!i?"all":l==="repo"&&!d?i?"project":"all":l,[u,p]=h("30"),[f,v]=h(null),[g,w]=h(""),C=()=>{let b=new URLSearchParams;return c==="project"&&b.set("project",Ye.value),c==="repo"&&ne.value&&b.set("repo",ne.value),b},k=()=>{let b=C();return Bo[u]&&b.set("since",String(Date.now()-Bo[u]*864e5)),b.toString()};_(()=>{let b=!0,$=Je(()=>U(`/api/stats?${k()}`).then(x=>b&&(v(x),w("")),x=>b&&w(x.message)),15e3);return()=>{b=!1,$()}},[c,u,ne.value,Ye.value]);let y=f?[...f.groups].sort((b,T)=>b.id===t?-1:T.id===t?1:0):[];return e("div",{class:"insights",children:[e("details",{class:"settings",children:[e("summary",{children:"Experiments"}),e("div",{class:"settings-body",children:[e("p",{class:"help",children:"Compare workflows against your current New run draft. Each selected setup starts a separate run and uses provider capacity."}),a?e("p",{children:a.task.split(`
32
+ `)[0]||"No task in the current draft"}):null,e("button",{class:"btn",disabled:!!r,title:r,onClick:()=>n(!0),children:"Compare setups\u2026"}),r?e("p",{class:"help",children:[r," ",e("a",{href:"#/",children:"Configure task"})]}):null]})]}),s&&a?e(uc,{base:{...a,approvals:{}},onClose:()=>n(!1),onStarted:b=>{n(!1),Z.value={view:"insights",group:b}}}):null,e("div",{class:"page-head ins-head",children:[e("div",{class:"page-head-text",children:e("p",{children:"What runs cost and how they went, per agent and per pattern."})}),e("div",{class:"page-head-actions",children:[e(Ks,{}),e("div",{class:"segmented",role:"group","aria-label":"Which runs",children:[i?e("button",{class:c==="project"?"on":"","aria-pressed":c==="project",title:"Runs in this project",onClick:()=>m("project"),children:o?o.name:"No project"}):null,d||!i?e("button",{class:c==="repo"?"on":"","aria-pressed":c==="repo",disabled:!ne.value,title:"Runs in this repository",onClick:()=>m("repo"),children:ne.value?be(ne.value):"This repo"}):null,e("button",{class:c==="all"?"on":"","aria-pressed":c==="all",onClick:()=>m("all"),children:"Everything"})]}),e("div",{class:"segmented",role:"group","aria-label":"Period",children:Object.keys(Bo).map(b=>e("button",{class:u===b?"on":"","aria-pressed":u===b,onClick:()=>p(b),children:b==="all"?"All time":`${b} days`},b))})]})]}),e(dr,{project:c==="project"?Ye.value:void 0,repository:c==="repo"?ne.value:void 0}),g?e("div",{class:"msg err",children:g}):null,f?null:e("div",{class:"help",children:"Loading\u2026"}),f&&!f.runs?e("div",{class:"ins-empty",children:[e("h2",{children:"No runs in this period"}),e("p",{children:"Start a run, or compare setups under Experiments above."})]}):null,f&&f.runs?e(j,{children:[e("div",{class:"ins-cards",children:[e(Sr,{label:"Runs",value:String(f.runs)}),e(Sr,{label:"Time",value:Le(f.ms),note:"wall-clock, finished runs"}),e(Sr,{label:"Tokens",value:It(f.tokens),note:"input + output"}),e(Sr,{label:"API-equivalent cost",value:ht(f.costUsd),note:"as Claude Code reports it; your plan isn't billed per token"})]}),y.length?e("section",{class:"ins-section","aria-labelledby":"ins-compare",children:[e("h2",{id:"ins-compare",children:"Comparisons"}),e("p",{class:"help",children:"The same task with different setups, started together. Lower is better for time, steps and tokens; \u201CTests changed\u201D means the result touched tests in ways that could hide failures."}),y.map(b=>e("div",{class:`ins-group ${b.id===t?"focus":""}`,children:[e("div",{class:"ig-title",children:b.task.split(`
33
+ `)[0]}),e("div",{class:"table-wrap",tabIndex:0,role:"region","aria-label":"Scrollable results table",children:e("table",{class:"ins-table",children:[e("thead",{children:e("tr",{children:[e("th",{children:"Setup"}),e("th",{children:"Result"}),e("th",{class:"num",children:"Time"}),e("th",{class:"num",children:"Steps"}),e("th",{class:"num",children:"Tokens"}),e("th",{class:"num",children:"Cost"}),e("th",{children:"Tests changed"}),e("th",{children:"Proven"}),e("th",{children:"Changes"})]})}),e("tbody",{children:b.runs.map(T=>{let $=ft(T),x=E=>{let A=b.runs.filter(P=>P.status==="done"&&P[E]!==void 0);return A.length>1&&T.status==="done"&&T[E]===Math.min(...A.map(P=>P[E]))};return e("tr",{class:"clickable",tabIndex:0,onClick:()=>Z.value={view:"run",id:T.id},onKeyDown:E=>E.key==="Enter"&&(Z.value={view:"run",id:T.id}),children:[e("td",{children:[e("b",{children:T.label}),e("div",{class:"help",children:[_o(T.pattern)," \xB7"," ",[...new Set(Object.values(T.roles).flat())].map(E=>e($e,{id:E},E))]})]}),e("td",{children:e("span",{class:`status-pill ${$}`,children:$==="failing"?"Check failing":$==="unchecked"?"Check can't run":$==="done"?"Passed":$==="unverified"?"Not verified":ot[T.status]??T.status})}),e("td",{class:`num ${x("ms")?"best":""}`,children:T.ms!==void 0?Le(T.ms):"\u2026"}),e("td",{class:`num ${x("steps")?"best":""}`,children:T.steps}),e("td",{class:`num ${x("tokens")?"best":""}`,children:It(T.tokens)}),e("td",{class:"num",children:T.costUsd?ht(T.costUsd):"\u2013"}),e("td",{children:T.flagged?e("span",{class:"badge warn",children:["\u26A0 ",T.flagged]}):e("span",{class:"help",children:"No"})}),e("td",{title:dc,children:T.proof==="proven"?e("span",{class:"badge ok",children:"\u2713 Yes"}):T.proof==="weak"?e("span",{class:"badge warn",title:"The tests fail without the change only because they can't load",children:"\u26A0 Weak"}):T.proof==="unproven"?e("span",{class:"badge warn",children:"\u26A0 No"}):e("span",{class:"help",children:"\u2013"})}),e("td",{class:"help",children:T.stat??"\u2013"})]},T.id)})})]})})]},b.id))]}):null,e("section",{class:"ins-section","aria-labelledby":"ins-agents",children:[e("h2",{id:"ins-agents",children:"Agents"}),e("p",{class:"help",children:[e("b",{children:"Passed"})," includes shared run outcomes. Provider comparisons and \u201CAuto\u201D routing use runs with a single writing provider, with at least three samples per provider. The 95% interval shows uncertainty in that observed rate. Task difficulty can still vary."]}),e("div",{class:"table-wrap",tabIndex:0,role:"region","aria-label":"Scrollable results table",children:e("table",{class:"ins-table",children:[e("thead",{children:e("tr",{children:[e("th",{children:"Agent"}),e("th",{class:"num",children:"Runs"}),e("th",{class:"num",children:"Passed"}),e("th",{class:"num",children:"Sole-writer evidence"}),e("th",{class:"num",children:"Race wins"}),e("th",{class:"num",children:"Loops it got green"}),e("th",{class:"num",children:"Review findings"}),e("th",{class:"num",children:"Steps"}),e("th",{class:"num",children:"Failed steps"}),e("th",{class:"num",children:"Tokens"}),e("th",{class:"num",children:"Cost"}),e("th",{class:"num",children:"Time per step"})]})}),e("tbody",{children:f.agents.map(b=>e("tr",{children:[e("td",{children:e($e,{id:b.agent})}),e("td",{class:"num",children:b.runs}),e("td",{class:"num",title:`${b.passed} of ${b.judged}`,children:b.judged?`${js(b.passed,b.judged)} (${b.passed}/${b.judged})`:"\u2013"}),e("td",{class:"num",title:`${b.sharedJudged??0} shared outcomes excluded from provider comparisons`,children:b.attributedJudged?e(j,{children:[b.attributedPassed,"/",b.attributedJudged,e("div",{class:"help",children:["95%: ",Math.round(100*b.confidence.low),"\u2013",Math.round(100*b.confidence.high),"%"]})]}):"No attributable samples"}),e("td",{class:"num",children:b.raceEntries?`${b.raceWins}/${b.raceEntries}`:"\u2013"}),e("td",{class:"num",children:b.loopSolves||"\u2013"}),e("td",{class:"num",title:"Findings, and how many another reviewer also raised",children:b.findings?`${b.findings} (${b.agreedFindings} agreed)`:"\u2013"}),e("td",{class:"num",children:b.steps}),e("td",{class:`num ${b.failures?"warn":""}`,children:b.steps?js(b.failures,b.steps):"\u2013"}),e("td",{class:"num",title:`${b.inputTokens.toLocaleString()} in \xB7 ${b.outputTokens.toLocaleString()} out \xB7 ${b.cacheReadTokens.toLocaleString()} cached`,children:It(b.inputTokens+b.outputTokens)}),e("td",{class:"num",children:b.costUsd?ht(b.costUsd):"\u2013"}),e("td",{class:"num",children:b.steps?Le(b.ms/b.steps):"\u2013"})]},b.agent))})]})})]}),f.cohorts?.length?e("section",{class:"ins-section","aria-labelledby":"ins-cohorts",children:[e("h2",{id:"ins-cohorts",children:"Task cohorts"}),e("p",{class:"help",children:"Compare runs in the same repository, workflow and source category. These groups do not estimate task difficulty."}),e("div",{class:"table-wrap",tabIndex:0,role:"region","aria-label":"Scrollable results table",children:e("table",{class:"ins-table",children:[e("thead",{children:e("tr",{children:[e("th",{children:"Repository"}),e("th",{children:"Workflow"}),e("th",{children:"Source"}),e("th",{class:"num",children:"Runs"}),e("th",{class:"num",children:"Passed / checked"}),e("th",{class:"num",children:"Tokens"}),e("th",{class:"num",children:"Cost"})]})}),e("tbody",{children:f.cohorts.map(b=>e("tr",{children:[e("td",{title:b.repo,children:be(b.repo)}),e("td",{children:_o(b.pattern)}),e("td",{children:b.sourceKind}),e("td",{class:"num",children:b.runs}),e("td",{class:"num",children:[b.passed,"/",b.judged]}),e("td",{class:"num",children:It(b.tokens)}),e("td",{class:"num",children:b.costUsd?ht(b.costUsd):"\u2013"})]},b.key))})]})})]}):null,e("section",{class:"ins-section","aria-labelledby":"ins-patterns",children:[e("h2",{id:"ins-patterns",children:"Patterns"}),e("div",{class:"table-wrap",tabIndex:0,role:"region","aria-label":"Scrollable results table",children:e("table",{class:"ins-table",children:[e("thead",{children:e("tr",{children:[e("th",{children:"Pattern"}),e("th",{class:"num",children:"Runs"}),e("th",{class:"num",children:"Passed"}),e("th",{class:"num",children:"Check failing"}),e("th",{class:"num",children:"Failed or stopped"}),e("th",{class:"num",children:"Tests changed"}),e("th",{class:"num",title:dc,children:"Proven"}),e("th",{class:"num",children:"Avg time"}),e("th",{class:"num",children:"Avg steps"}),e("th",{class:"num",children:"Tokens"}),e("th",{class:"num",children:"Cost"})]})}),e("tbody",{children:f.patterns.map(b=>e("tr",{children:[e("td",{class:"name",children:_o(b.pattern)}),e("td",{class:"num",children:b.runs}),e("td",{class:"num",children:b.passed?`${b.passed} (${js(b.passed,b.runs)})`:"\u2013"}),e("td",{class:`num ${b.failing?"warn":""}`,children:b.failing||"\u2013"}),e("td",{class:`num ${b.failed+b.stopped?"warn":""}`,children:b.failed+b.stopped||"\u2013"}),e("td",{class:`num ${b.flagged?"warn":""}`,children:b.flagged||"\u2013"}),e("td",{class:`num ${b.unproven+b.weak?"warn":""}`,title:b.proven+b.weak+b.unproven?`${b.proven} proven, ${b.weak} weakly (tests that only fail to load), ${b.unproven} not proven`:void 0,children:b.proven+b.weak+b.unproven?`${b.proven}/${b.proven+b.weak+b.unproven}`:"\u2013"}),e("td",{class:"num",children:b.ended?Le(b.ms/b.ended):"\u2013"}),e("td",{class:"num",children:(b.steps/b.runs).toFixed(1)}),e("td",{class:"num",children:It(b.tokens)}),e("td",{class:"num",children:b.costUsd?ht(b.costUsd):"\u2013"})]},b.pattern))})]})})]})]}):null,e(cc,{}),e(_p,{scope:C()})]})}var dc="Proven: a test in the result fails on the base code without the change (code-flow ran the change's tests there)";function Sr({label:t,value:s,note:n}){return e("div",{class:"ins-card",children:[e("div",{class:"ic-label",children:t}),e("div",{class:"ic-value",children:s}),n?e("div",{class:"help",children:n}):null]})}function _p({scope:t}){let s=t.toString(),[n,a]=h(null),[r,o]=h(!1),[i,d]=h(7),l=async()=>{o(!0);try{a(await U(`/api/disk${s?`?${s}`:""}`))}catch(m){V(m.message,5e3)}finally{o(!1)}};return _(()=>a(null),[s]),e("section",{class:"ins-section","aria-labelledby":"ins-disk",children:[e("h2",{id:"ins-disk",children:"Disk"}),e("div",{class:"row-inline",children:[e("button",{class:"btn small",disabled:r,onClick:l,children:r?"Measuring\u2026":n?"Measure again":"Measure worktrees"}),n?e("span",{children:[e("b",{children:Ht(n.total)})," in ",n.runs.length," run",n.runs.length===1?"":"s","' worktrees"]}):e("span",{class:"help",children:"Adds up the worktrees of every run; this can take a few seconds."}),e("span",{class:"spacer"}),e("span",{children:"Remove worktrees of finished runs older than"}),e("input",{class:"field inline num",type:"number",min:0,max:365,value:i,"aria-label":"Days",onInput:m=>d(Number(m.currentTarget.value)||0)}),e("span",{children:"days"}),e("button",{class:"btn small",onClick:async()=>{if(await Ce(`Remove the worktrees of runs that finished more than ${i} days ago and need nothing from you? Branches are kept, so you can still merge or resume them.`,{title:"Remove old worktrees?",confirmLabel:"Remove worktrees",danger:!0}))try{let m=await q("/api/cleanup",{olderThanDays:i,repo:t.get("repo")??void 0,project:t.get("project")??void 0});V(m.worktrees?`Removed ${m.worktrees} worktree(s) from ${m.runs} run(s)`:"Nothing to clean up",4e3),n&&l()}catch(m){V(m.message,5e3)}},children:"Clean up"})]}),n?.runs.length?e("div",{class:"table-wrap",tabIndex:0,role:"region","aria-label":"Scrollable results table",children:e("table",{class:"ins-table",children:[e("thead",{children:e("tr",{children:[e("th",{children:"Run"}),e("th",{children:"Repository"}),e("th",{children:"Status"}),e("th",{class:"num",children:"Worktree"})]})}),e("tbody",{children:n.runs.slice(0,10).map(m=>e("tr",{class:"clickable",tabIndex:0,onClick:()=>Z.value={view:"run",id:m.id},onKeyDown:c=>c.key==="Enter"&&(Z.value={view:"run",id:m.id}),children:[e("td",{children:m.task}),e("td",{class:"help",children:be(m.repo)}),e("td",{class:"help",children:m.archived?"Archived":ot[m.status]??m.status}),e("td",{class:"num",children:Ht(m.bytes)})]},m.id))})]})}):null]})}function mc({runId:t,worktree:s}){let[n,a]=h(null),[r,o]=h(""),[i,d]=h(""),[l,m]=h(""),c=Q(0),u=Q(0),p=Q(0),f=`/api/runs/${J(t)}/launch-profiles`,v=`?worktree=${J(s)}`,g=`launch-profile-${J(t)}-${J(s)}`;_(()=>{let T=++c.current,$=!0;a(null),o(""),d(""),m(""),p.current++;let E=Je(async()=>{let A=++u.current;try{let P=await U(f+v);if(!$||c.current!==T||u.current!==A)return;a(P),d(""),o(D=>P.profiles.some(S=>S.id===D)?D:P.profiles[0]?.id??"")}catch(P){$&&c.current===T&&u.current===A&&d(P.message)}},2e3);return()=>{$=!1,E(),c.current++,p.current++}},[t,s]);let w=async()=>{let T=c.current,$=++p.current;m("start"),d("");try{let x,E={worktree:s,profile:r};try{x=await q(f,E)}catch(A){if(!(A instanceof Ge)||A.confirm!=="allowUntrusted")throw A;if(T!==c.current||$!==p.current||!await Ce(`${A.message}
34
+
35
+ Start these repository commands on this computer?`,{title:"Start repository commands?",confirmLabel:"Start commands",danger:!0})||T!==c.current||$!==p.current)return;x=await q(f,{...E,allowUntrusted:!0})}if(T!==c.current||$!==p.current)return;u.current++,a(A=>A&&{...A,session:x}),V(x.status==="ready"?"Launch profile is ready":"Launch profile finished startup")}catch(x){T===c.current&&$===p.current&&d(x.message)}finally{T===c.current&&$===p.current&&m("")}},C=async()=>{let T=c.current,$=++p.current;m("stop"),d("");try{let x=await U(f+v,{method:"DELETE"});if(T!==c.current||$!==p.current)return;u.current++,a(E=>E&&{...E,session:x.session??(E.session?{...E.session,status:"stopped",services:E.session.services.map(A=>({...A,status:A.status==="exited"?"exited":"stopped"}))}:null)}),V(x.stopped?"Launch profile stopped":"No active launch profile")}catch(x){T===c.current&&$===p.current&&d(x.message)}finally{T===c.current&&$===p.current&&m("")}},k=n?.profiles.find(T=>T.id===r),y=n?.session,b=y?.status==="ready"||y?.status==="starting"||l==="start";return e("section",{class:"wb-card launch-profiles","aria-label":"Multi-service launch profiles",children:[e("h2",{children:"Launch profiles"}),e("p",{class:"help",children:["Start a coordinated app stack from this worktree\u2019s ",e("code",{children:".codeflow/launch.json"}),". Services get separate ports, peer URLs and bounded HTTP readiness checks. Starting a profile executes repository commands on this computer."]}),!n&&!i?e("p",{role:"status",children:"Reading launch profiles\u2026"}):null,n?.error?e("p",{class:"msg err",role:"alert",children:n.error}):null,n&&!n.found?e("p",{class:"help",children:["No launch configuration exists in this worktree. Add a version 1 ",e("code",{children:".codeflow/launch.json"})," with named profiles and up to six services each."]}):null,n?.found&&!n.error&&!n.profiles.length?e("p",{class:"help",children:"The launch configuration has no profiles."}):null,k?e(j,{children:[e("div",{class:"launch-profile-choice",children:[e("label",{class:"lbl",for:g,children:"Launch profile"}),e("select",{id:g,class:"field",value:r,disabled:!!l||!!b,onChange:T=>o(T.currentTarget.value),children:n.profiles.map(T=>e("option",{value:T.id,children:T.name},T.id))})]}),e("details",{class:"launch-preview",children:[e("summary",{children:["Review ",k.services.length," service commands"]}),e("ul",{children:k.services.map(T=>e("li",{children:[e("strong",{children:T.name??T.id})," ",e("code",{children:T.cwd}),e("pre",{children:T.command}),e("p",{class:"help",children:[T.dependsOn.length?`Starts after ${T.dependsOn.join(", ")}. `:"",T.health===!1?"Checks that the process remains running; HTTP readiness is disabled.":`HTTP ${T.health.path} must return 2xx within ${T.health.timeoutMs/1e3}s.`]})]},T.id))})]}),e("div",{class:"launch-actions",children:[e("button",{class:"btn primary",disabled:!!l||!!b||!!n?.error,onClick:w,children:l==="start"?"Starting services\u2026":"Start launch profile"}),e("button",{class:"btn",disabled:!b||l==="stop",onClick:C,children:l==="stop"?"Stopping\u2026":"Stop services"})]})]}):b?e("button",{class:"btn",disabled:l==="stop",onClick:C,children:"Stop services"}):null,y?e("div",{class:"launch-session","aria-live":"polite",children:[e("p",{children:[e("strong",{children:["Stack: ",y.status]})," \xB7 ",y.profile]}),y.error?e("p",{class:"msg err",children:y.error}):null,e("div",{class:"launch-services",children:y.services.map(T=>e("article",{class:"launch-service","aria-label":`${T.name} service`,children:[e("div",{children:[e("strong",{children:T.name}),e("span",{class:`badge ${T.status==="healthy"?"ok":T.status==="exited"?"err":T.status==="starting"||T.status==="running"?"run":""}`,children:T.status.charAt(0).toUpperCase()+T.status.slice(1)})]}),e("p",{class:"help",children:["Port ",T.port,T.exitCode!=null?` \xB7 Exit ${T.exitCode}`:""," \xB7 ",T.healthChecked?"HTTP readiness passed":"HTTP readiness not confirmed"]}),y.status==="ready"&&["healthy","running"].includes(T.status)?e("a",{href:T.url,target:"_blank",rel:"noopener noreferrer",children:["Open ",T.name]}):e("code",{children:T.url}),e("details",{children:[e("summary",{children:["Logs (",T.logs.length," recent lines)"]}),e("pre",{class:"launch-logs",children:T.logs.join(`
36
+ `)||"No output yet."})]})]},T.id))})]}):null,i?e("p",{class:"msg err",role:"alert",children:i}):null]})}var Ca=(t,s={})=>U(t,{method:"POST",body:JSON.stringify(s)});function hc({projectId:t,repos:s}){let[n,a]=h(s[0]??""),[r,o]=h(""),[i,d]=h(""),[l,m]=h("claude"),[c,u]=h(!1),[p,f]=h(10),[v,g]=h([]),[w,C]=h(""),[k,y]=h(null),[b,T]=h(null),[$,x]=h(!1),[E,A]=h(""),[P,D]=h(""),S=Q(0),R=Q(0),M=Q(!1),O=Q(w);O.current=w;let B=async(G=S.current,L=!1)=>{if(M.current&&!L)return;let Y=++R.current,X=()=>G===S.current&&Y===R.current,N=await U(`/api/filtered-tasks?project=${J(t)}`);if(!X())return;g(N);let ae=O.current;if(ae)try{let ie=await U(`/api/filtered-tasks/${J(ae)}`);X()&&ae===O.current&&y(ie)}catch(ie){X()&&ae===O.current&&(y(null),A(ie.message))}};_(()=>{let G=++S.current;M.current=!1,x(!1),C(""),O.current="",y(null),T(null),A(""),a(s[0]??"");let L=Je(()=>!M.current&&B(G),1500,Y=>{G===S.current&&A(Y.message)});return()=>{L(),M.current=!1,S.current++,R.current++}},[t]),_(()=>{R.current++,T(null),y(null),w&&B().catch(G=>A(G.message))},[w]);let ee=async G=>{if(M.current)return;M.current=!0,R.current++;let L=S.current,Y=()=>L===S.current;x(!0),A(""),D("");try{await G(Y),Y()&&await B(L,!0)}catch(X){Y()&&A(X.message)}finally{Y()&&(M.current=!1,x(!1))}},se=v.find(G=>G.id===w),te=k??se;return e("section",{class:"wb-card filtered-task-panel","aria-label":"Filtered Docker tasks",children:[e("h2",{children:"Filtered Docker task"}),e("p",{class:"help",children:"Run one manual provider turn against an isolated copy of policy-readable committed files. The container receives a fresh Git repository and no original Git history, host credentials or application memory. Current native, SSH and automated workflows remain paused under restrictions."}),e("p",{class:"help",children:"Use an explicitly prepared local image containing the selected CLI. Its immutable image ID is pinned before execution. The image must work with a read-only root filesystem, a fresh writable home and bounded scratch space; configure provider authentication deliberately inside the prepared runtime. No host authentication volume or cache is mounted. Network is off unless you explicitly enable inference access."}),e("form",{onSubmit:G=>{G.preventDefault(),ee(async L=>{let Y=await Ca("/api/filtered-tasks",{project:t,repo:n,task:r,agent:l,image:i,network:c,maxMinutes:p});L()&&(O.current=Y.id,C(Y.id),y(Y),T(null),D("Filtered task started. Results require a separate explicit import."))})},children:[e("div",{class:"filtered-fields",children:[e("label",{class:"lbl",children:["Filtered task repository",e("select",{class:"field",value:n,disabled:$,onChange:G=>a(G.currentTarget.value),children:s.map(G=>e("option",{value:G,children:G}))})]}),e("label",{class:"lbl",children:["Filtered task provider",e("select",{class:"field",value:l,disabled:$,onChange:G=>m(G.currentTarget.value),children:[e("option",{value:"claude",children:"Claude Code"}),e("option",{value:"codex",children:"Codex"}),e("option",{value:"agy",children:"Antigravity"})]})]}),e("label",{class:"lbl",children:["Prepared filtered Docker image",e("input",{class:"field",value:i,required:!0,disabled:$,maxLength:200,placeholder:"prepared-provider:reviewed-version",onInput:G=>d(G.currentTarget.value)})]}),e("label",{class:"lbl",children:["Filtered task time limit (minutes)",e("input",{class:"field",type:"number",min:1,max:30,value:p,disabled:$,onInput:G=>f(Number(G.currentTarget.value))})]})]}),e("label",{class:"lbl",children:["Filtered task instructions",e("textarea",{class:"field",rows:4,required:!0,maxLength:24e3,value:r,disabled:$,onInput:G=>o(G.currentTarget.value)})]}),e("label",{children:[e("input",{type:"checkbox",checked:c,disabled:$,onChange:G=>u(G.currentTarget.checked)})," Allow container network for inference"]}),e("p",{class:"help",children:"The source is the current committed revision. Uncommitted files are not copied. Readable files denied writes are mounted read-only; every changed output path is rechecked before an import. Exports are monitored for excessive files and disk use; polling is not an operating-system disk quota."}),e("div",{class:"filtered-actions",children:[e("button",{class:"btn primary",disabled:$||!n||!r.trim()||!i.trim(),children:"Start filtered Docker task"}),e("button",{class:"btn",type:"button",disabled:$,onClick:()=>void ee(async()=>{await B()}),children:"Refresh filtered tasks"})]})]}),E?e("p",{class:"msg err",role:"alert",children:E}):null,P?e("p",{role:"status",class:"help",children:P}):null,e("label",{class:"lbl",children:["Saved filtered task",e("select",{class:"field",value:w,disabled:$,onChange:G=>C(G.currentTarget.value),children:[e("option",{value:"",children:"Choose a task"}),v.map(G=>e("option",{value:G.id,children:[G.status," \xB7 ",new Date(G.createdAt).toLocaleString()," \xB7 ",G.id.slice(-8)]},G.id))]})]}),te?e("article",{class:"wb-item filtered-task","aria-label":"Selected filtered task",children:[e("h3",{children:te.id}),e("p",{role:"status",children:["Filtered task status: ",te.status,te.containerStopped?" \xB7 daemon container stopped":" \xB7 daemon receipt not confirmed stopped"]}),k?e(j,{children:[e("p",{children:k.task}),e("p",{class:"help",children:["Source ",e("code",{children:k.sourceHead??"preparing"})," \xB7 ",k.exportedFiles," committed files \xB7 ",k.exportedBytes," bytes \xB7 image ",e("code",{children:k.imageId??"resolving"})]}),e("p",{class:"help",children:["Policy revisions: ",k.policyRevisions.map(G=>`${G.projectId}:${G.revision}`).join(", ")]}),k.error?e("p",{class:"msg err",children:k.error}):null,k.finalText?e("pre",{children:k.finalText}):null,k.events.length?e("details",{children:[e("summary",{children:["Provider status (",k.events.length,")"]}),k.events.slice(-20).map(G=>e("p",{children:G.text}))]}):null]}):null,e("div",{class:"filtered-actions",children:[e("button",{class:"btn",disabled:$||["importing","imported"].includes(te.status),onClick:()=>void ee(async G=>{await Ca(`/api/filtered-tasks/${J(te.id)}/cancel`,{revision:te.revision}),G()&&(T(null),D("Owned daemon container absence confirmed."))}),children:"Cancel task and confirm container stopped"}),te.status==="completed"?e("button",{class:"btn",disabled:$,onClick:()=>void ee(async G=>{let L=await Ca(`/api/filtered-tasks/${J(te.id)}/preview-import`);G()&&(T(L),y(L.job))}),children:"Preview allowed import"}):null,te.status==="unknown"&&te.importCommit?e("button",{class:"btn",disabled:$,onClick:()=>void ee(async()=>{await Ca(`/api/filtered-tasks/${J(te.id)}/receipt`,{revision:te.revision})}),children:"Inspect interrupted import receipt"}):null,te.containerStopped&&["completed","failed","cancelled","imported"].includes(te.status)?e("button",{class:"btn",disabled:$,onClick:()=>void ee(async G=>{await U(`/api/filtered-tasks/${J(te.id)}`,{method:"DELETE",body:JSON.stringify({revision:te.revision})}),G()&&(O.current="",C(""),y(null),T(null),D("Private task/export deleted; any imported review branch is preserved."))}),children:"Delete private task and export"}):null]}),te.importBranch?e("p",{class:"help",children:["Review branch: ",e("code",{children:te.importBranch})," \xB7 ",e("code",{children:te.importCommit}),". Original checkout and index remain unchanged."]}):null]}):null,b?e("section",{class:"filtered-changes wb-subsection","aria-label":"Filtered import preview",children:[e("h3",{children:"Review allowed changes before import"}),e("p",{class:"help",children:[b.importBehavior,". Source and result hashes, policy revisions, original file contents and index are checked again. No automatic merge, staging, retry or original checkout overwrite occurs."]}),b.changes.map(G=>e("details",{children:[e("summary",{children:[G.status," \xB7 ",G.path,G.binary?" \xB7 binary":"",G.truncated?" \xB7 preview truncated":""]}),e("p",{class:"help",children:["Before ",G.beforeHash??"absent"," \xB7 after ",G.afterHash??"absent"]}),G.before!==void 0?e(j,{children:[e("h4",{children:"Original committed content"}),e("pre",{children:G.before})]}):null,G.after!==void 0?e(j,{children:[e("h4",{children:"Filtered result"}),e("pre",{children:G.after})]}):null]})),e("div",{class:"filtered-actions",children:e("button",{class:"btn primary",disabled:$||!b.changes.length||te?.status!=="completed",onClick:()=>void ee(async G=>{await Ca(`/api/filtered-tasks/${J(b.job.id)}/import`,{revision:b.job.revision,expectedHead:b.sourceHead,resultHash:b.resultHash}),G()&&(T(null),D("Allowed changes imported into a new review branch. Original checkout is unchanged."))}),children:"Import into new review branch"})})]}):null]})}var Bp={running:"run",ready:"ok",shipped:"ok","partial-shipped":"warn",blocked:"warn"},qp={claimed:"run",running:"run",shipping:"run",verified:"ok",shipped:"ok",failed:"err",unknown:"warn",blocked:"warn","shipping-unknown":"warn"},fc=t=>`badge${t?` ${t}`:""}`,gc=t=>{let s=t.replace(/-/g," ");return s.charAt(0).toUpperCase()+s.slice(1)},bn=(t,s="")=>({id:t,repo:s,task:"",provider:"claude",check:"",dependsOn:[]});function vc({endpoint:t="/api/coordinated-changes"}){let[s,n]=h([]),[a,r]=h(""),[o,i]=h(""),[d,l]=h([bn("repo1"),bn("repo2")]),[m,c]=h(()=>crypto.randomUUID()),[u,p]=h([]),[f,v]=h(""),[g,w]=h(""),[C,k]=h({}),[y,b]=h({}),[T,$]=h({}),x=s.find(S=>S.id===a),E=async()=>{p(await U(t))};_(()=>{let S=!0;U("/api/projects").then(M=>{if(S){n(M);let O=M.find(B=>B.repos.length>=2)??M[0];O&&(r(O.id),l([bn("repo1",O.repos[0]),bn("repo2",O.repos[1])]))}}).catch(M=>{S&&v(M.message)});let R=Je(()=>U(t).then(M=>{S&&p(M)}).catch(M=>{S&&v(M.message)}),5e3);return()=>{S=!1,R()}},[t]);let A=(S,R)=>{c(crypto.randomUUID()),l(M=>M.map(O=>O.id===S?{...O,...R}:O))},P=async()=>{if(!g){w("create"),v("");try{if(!x||d.some(S=>!x.repos.includes(S.repo)||!S.task.trim()))throw new Error("Choose project repositories and write a task for each one.");await q(t,{project:a,name:o.trim(),operationId:m,nodes:d.map(S=>({id:S.id,dependsOn:S.dependsOn,run:{repo:S.repo,project:a,pattern:"solo",task:S.task,roles:{agent:[S.provider]},options:{},loop:{...S.check.trim()?{check:S.check.trim()}:{},maxSteps:20,maxInvocations:20,maxMinutes:15,copy:[]}}}))}),c(crypto.randomUUID()),i(""),l(S=>S.map(R=>({...R,task:""}))),await E()}catch(S){v(S.message)}finally{w("")}}},D=async(S,R,M={})=>{if(!g){w(S.id+R),v("");try{await q(`${t}/${encodeURIComponent(S.id)}/${R}`,{expectedRevision:S.revision,...M}),await E()}catch(O){v(O.message),await E().catch(()=>{})}finally{w("")}}};return e("section",{class:"wb-card coordination-panel","aria-label":"Coordinated repository changes",children:[e("h2",{children:"Coordinated repository changes"}),e("p",{class:"help",children:"Plan dependent changes across 2\u201310 repositories in one project. Each starts from its pinned commit in safe mode. Downstream work receives exact verified commit facts after its dependencies finish. Repositories keep separate workspaces and credentials."}),e("p",{class:"help",children:"Tasks use at most 20 agent calls and 15 minutes by default. There are no unattended native tool approval waits, inherited uploads or copied ignored files. Shipping requires a reviewed matrix and a separate explicit merge for each repository; merges can partially succeed and never push automatically."}),f?e("p",{class:"msg err",role:"alert",children:[f," Your draft is preserved."]}):null,e("details",{children:[e("summary",{children:"Create a coordinated change"}),e("div",{class:"wb-fields",children:[e("label",{children:["Project",e("select",{class:"field","aria-label":"Coordinated project",value:a,onChange:S=>{let R=S.currentTarget.value,M=s.find(O=>O.id===R);c(crypto.randomUUID()),r(R),l([bn("repo1",M?.repos[0]),bn("repo2",M?.repos[1])])},children:[e("option",{value:"",children:"Choose project"}),s.map(S=>e("option",{value:S.id,children:S.name},S.id))]})]}),e("label",{children:["Change name",e("input",{class:"field","aria-label":"Coordinated change name",maxLength:120,value:o,onInput:S=>{c(crypto.randomUUID()),i(S.currentTarget.value)}})]})]}),!x||x.repos.length<2?e("p",{class:"help",children:"Add at least two repositories to a project before coordinating changes."}):null,d.map((S,R)=>e("fieldset",{class:"coordination-task","aria-label":`Coordinated task ${S.id}`,children:[e("legend",{children:["Task ",S.id]}),e("label",{children:["Repository",e("select",{class:"field","aria-label":`Repository for ${S.id}`,value:S.repo,onChange:M=>A(S.id,{repo:M.currentTarget.value}),children:[e("option",{value:"",children:"Choose repository"}),x?.repos.map(M=>e("option",{value:M,children:M},M))]})]}),e("label",{children:["Task",e("textarea",{class:"field",rows:3,"aria-label":`Task for ${S.id}`,maxLength:24e3,value:S.task,onInput:M=>A(S.id,{task:M.currentTarget.value})})]}),e("label",{children:["Provider",e("select",{class:"field","aria-label":`Provider for ${S.id}`,value:S.provider,onChange:M=>A(S.id,{provider:M.currentTarget.value}),children:[e("option",{value:"claude",children:"Claude"}),e("option",{value:"codex",children:"Codex"}),e("option",{value:"agy",children:"Antigravity"}),e("option",{value:"auto",children:"Auto"})]})]}),e("label",{children:["Verification command \xB7 blank uses repository configuration",e("input",{class:"field","aria-label":`Verification for ${S.id}`,value:S.check,onInput:M=>A(S.id,{check:M.currentTarget.value})})]}),e("div",{class:"coordination-deps",children:["Start after these verified tasks:",d.filter(M=>M.id!==S.id).map(M=>e("label",{class:"help",children:[e("input",{type:"checkbox","aria-label":`${S.id} depends on ${M.id}`,checked:S.dependsOn.includes(M.id),onChange:O=>A(S.id,{dependsOn:O.currentTarget.checked?[...S.dependsOn,M.id]:S.dependsOn.filter(B=>B!==M.id)})})," ",M.id]},M.id))]}),d.length>2?e("button",{class:"btn small",disabled:!!g,onClick:()=>l(M=>M.filter(O=>O.id!==S.id).map(O=>({...O,dependsOn:O.dependsOn.filter(B=>B!==S.id)}))),children:["Remove task ",R+1]}):null]},S.id)),e("div",{class:"wb-actions",children:[e("button",{class:"btn small",disabled:!!g||d.length>=10||d.length>=(x?.repos.length??0),onClick:()=>{let S=Array.from({length:10},(R,M)=>`repo${M+1}`).find(R=>!d.some(M=>M.id===R));l(R=>[...R,bn(S,x?.repos.find(M=>!R.some(O=>O.repo===M)))])},children:"Add repository task"}),e("button",{class:"btn small primary",disabled:!!g||!x||x.repos.length<2||!o.trim(),onClick:P,children:"Start coordinated change"})]})]}),e("div",{class:"wb-actions",children:e("button",{class:"btn small",disabled:!!g,onClick:()=>void E().catch(S=>v(S.message)),children:"Refresh coordinated changes"})}),u.length===0?e("p",{class:"help",children:"No coordinated changes yet."}):null,u.length?e("div",{class:"wb-list",children:u.map(S=>e("article",{class:"wb-item coordination-job","aria-label":`Coordinated change ${S.name}`,children:[e("div",{class:"wb-item-head",children:[e("b",{children:S.name}),e("span",{class:fc(Bp[S.status]),children:[gc(S.status)," \xB7 revision ",S.revision]}),!S.cancelRequested&&S.status!=="shipped"?e("button",{class:"btn small",disabled:!!g,onClick:()=>D(S,"cancel"),children:"Cancel coordinated change"}):null]}),e("p",{class:"help",children:["Project ",s.find(R=>R.id===S.project)?.name??S.project," \xB7 ",S.id]}),S.nodes.map(R=>{let M=`${S.id}:${R.id}`,O=`nodes/${encodeURIComponent(R.id)}`;return e("section",{class:"coordination-node","aria-label":`Repository task ${R.id}`,children:[e("div",{class:"wb-item-head",children:[e("h3",{children:R.id}),e("span",{class:fc(qp[R.status]),children:gc(R.status)})]}),e("p",{class:"help",children:[R.run.repo," \xB7 starts at ",e("code",{children:R.baseCommit}),R.dependsOn.length?` \xB7 depends on ${R.dependsOn.join(", ")}`:" \xB7 independent",R.runId?` \xB7 attempt ${R.attempts}`:""]}),e("p",{children:R.run.task}),R.reason?e("p",{class:"help",children:R.reason}):null,R.result?e("p",{class:"help",children:["Verified branch ",R.result.branch," at ",e("code",{children:R.result.commit})," \xB7 receipt ",R.result.verificationId]}):null,R.shippedCommit?e("p",{class:"help",children:["Merged commit: ",e("code",{children:R.shippedCommit})]}):null,R.runId?e("div",{class:"wb-actions",children:e("a",{class:"btn small",href:`#/run/${encodeURIComponent(R.runId)}`,children:["Open run ",R.runId]})}):null,R.status==="unknown"?e("div",{children:[e("p",{class:"help",children:["Claim ",R.claimId," \xB7 inspect existing runs before linking or retrying."]}),e("label",{children:["Matching run ID",e("input",{class:"field","aria-label":`Matching run for ${R.id}`,value:y[M]??"",onInput:B=>b(ee=>({...ee,[M]:B.currentTarget.value}))})]}),e("button",{class:"btn small",disabled:!!g||!y[M],onClick:()=>D(S,O+"/attach",{runId:y[M]}),children:["Link matching run ",R.id]}),e("label",{class:"help",children:[e("input",{type:"checkbox","aria-label":`Acknowledge unknown retry ${R.id}`,checked:T[M]??!1,onChange:B=>$(ee=>({...ee,[M]:B.currentTarget.checked}))})," I inspected existing runs and accept that retrying could duplicate work."]})]}):null,["failed","blocked","cancelled"].includes(R.status)&&S.nodes.some(B=>B.status==="unknown")?e("label",{class:"help",children:[e("input",{type:"checkbox","aria-label":`Acknowledge unknown dependent retry ${R.id}`,checked:T[M]??!1,onChange:B=>$(ee=>({...ee,[M]:B.currentTarget.checked}))})," I inspected unknown dependent launches and accept that invalidating them could duplicate work."]}):null,["failed","unknown","blocked","cancelled"].includes(R.status)?e("button",{class:"btn small",disabled:!!g||R.attempts>=3||R.status==="unknown"&&!T[M],onClick:()=>D(S,O+"/retry",{acknowledgeUnknown:T[M]===!0}),children:["Retry task ",R.id]}):null,R.status==="shipping-unknown"?e("div",{children:[e("p",{class:"help",children:["Shipping claim ",R.shippingClaimId," has an unknown outcome. Inspect the exact local target commit; automatic retry is disabled."]}),e("label",{children:["Proven merge commit",e("input",{class:"field","aria-label":`Shipping recovery commit for ${R.id}`,value:y[M]??"",onInput:B=>b(ee=>({...ee,[M]:B.currentTarget.value}))})]}),e("button",{class:"btn small",disabled:!!g||!y[M],onClick:()=>D(S,O+"/recover-shipping",{commit:y[M]}),children:["Recover exact shipping receipt ",R.id]})]}):null]},R.id)}),!S.cancelRequested&&S.nodes.every(R=>["verified","shipped"].includes(R.status))&&S.status!=="shipped"?e("section",{class:"coordination-node","aria-label":"Coordinated shipping review",children:[e("h3",{children:"Review local merge targets"}),S.nodes.filter(R=>R.status!=="shipped").map(R=>e("label",{children:["Target branch for ",R.id,e("input",{class:"field","aria-label":`Shipping target for ${R.id}`,value:C[`${S.id}:${R.id}`]??"main",onInput:M=>k(O=>({...O,[`${S.id}:${R.id}`]:M.currentTarget.value}))})]},R.id)),e("button",{class:"btn small",disabled:!!g,onClick:()=>D(S,"shipping-preview",{targets:Object.fromEntries(S.nodes.filter(R=>R.status!=="shipped").map(R=>[R.id,C[`${S.id}:${R.id}`]??"main"]))}),children:"Validate and preview shipping matrix"})]}):null,S.shipping?e("section",{class:"coordination-node","aria-label":"Pinned shipping matrix",children:[e("p",{class:"help",children:["Preview ",S.shipping.id," \xB7 expires ",new Date(S.shipping.expiresAt).toLocaleString(),". Each action is independent; previously merged repositories remain merged if another fails."]}),e("ul",{children:S.shipping.entries.map(R=>{let M=S.nodes.find(O=>O.id===R.nodeId);return e("li",{children:[e("b",{children:[R.nodeId," \u2192 ",R.validation.into]}),e("p",{class:"help",children:["Source ",e("code",{children:R.validation.source})," \xB7 target ",e("code",{children:R.validation.target})," \xB7 validated tree ",e("code",{children:R.validation.tree})]}),e("button",{class:"btn small primary",disabled:!!g||S.cancelRequested||S.shipping.expiresAt<=Date.now()||M.status!=="verified",onClick:()=>D(S,`nodes/${encodeURIComponent(M.id)}/ship`,{previewId:S.shipping.id}),children:["Merge ",M.id," into ",R.validation.into]})]},R.nodeId)})})]}):null,e("details",{children:[e("summary",{children:["Coordination history \xB7 ",S.history.length]}),e("ul",{children:S.history.slice().reverse().map(R=>e("li",{children:[new Date(R.at).toLocaleString(),R.nodeId?` \xB7 ${R.nodeId}`:""," \xB7 ",R.detail,R.runId?` \xB7 run ${R.runId}`:"",R.commit?e(j,{children:[" \xB7 ",e("code",{children:R.commit})]}):null]},R.id))})]})]},S.id))}):null]})}var qo=Ji("codeflow-file-drafts-v1"),bc=t=>/(^|\/)(?:\.env(?:\..*)?|.*\.(?:pem|key))$/.test(t);function yc(){try{let t=JSON.parse(sessionStorage.getItem(qo)??"[]");return Array.isArray(t)?t.filter(s=>!!s&&typeof s.folder=="string"&&typeof s.path=="string"&&typeof s.text=="string"&&typeof s.draft=="string"&&typeof s.hash=="string"&&Number.isFinite(s.at)&&s.at>Date.now()-864e5&&!bc(s.path)).slice(-10):[]}catch{return[]}}function kc(t,s){return yc().find(n=>n.folder===t&&n.path===s)}function Uo(t,s,n,a=!1){try{let r=yc().filter(o=>o.folder!==t||o.path!==s.path);if(bc(s.path))return sessionStorage.setItem(qo,JSON.stringify(r)),"sensitive";if(JSON.stringify({...s,draft:n}).length>2e6)return"full";for(n!==s.text&&r.push({folder:t,...s,draft:n,at:Date.now(),mergeConflict:a});r.length>10||JSON.stringify(r).length>2e6;)r.shift();return sessionStorage.setItem(qo,JSON.stringify(r)),"saved"}catch{return"full"}}function xr({folder:t,paths:s,refreshKey:n=""}){let[a,r]=h(!1),[o,i]=h(!1),[d,l]=h(""),[m,c]=h();_(()=>{if(!a||!t)return;let f=!0;return i(!0),l(""),c(void 0),U(`/api/workspace/dependencies?repo=${J(t)}`).then(v=>{f&&c(v)},v=>{f&&l(v.message)}).finally(()=>{f&&i(!1)}),()=>{f=!1}},[a,t,s.join("\0"),n]);let u=new Set(s),p=m?.edges.filter(f=>u.has(f.from)||u.has(f.to))??[];return e("details",{class:"settings change-impact",open:a,onToggle:f=>r(f.currentTarget.open),children:[e("summary",{children:"What could this change affect?"}),e("div",{class:"settings-body",children:[e("p",{class:"help",children:["Static import relationships for ",s.length," selected ",s.length===1?"file":"files",", based on saved tracked source. Unsaved edits and runtime dependencies are excluded."]}),o?e("p",{role:"status",children:"Inspecting related files\u2026"}):null,d?e("p",{class:"msg err",role:"alert",children:d}):null,m?e(j,{children:[e("p",{class:"help",children:[m.truncated?"The scan reached its limit; some relationships may be missing. ":"",m.note]}),p.length?e("ul",{children:p.map((f,v)=>e("li",{children:[e("code",{children:f.from})," imports ",e("code",{children:f.to})]},v))}):e("p",{children:"No static import relationships found for these files. This does not establish that the change has no impact."}),e("details",{children:[e("summary",{children:"Additional scan evidence"}),e("p",{children:[m.nodes.length," files \xB7 ",m.cycles.length," cycles \xB7 ",m.unresolved.length," unresolved imports"]}),e("pre",{children:JSON.stringify({cycles:m.cycles,packages:m.packages,unresolved:m.unresolved,dynamic:m.dynamic},null,2)})]})]}):null]})]})}function $r({folder:t,initialPath:s,onClose:n}){let[a,r]=h(!1),[o,i]=h(""),[d,l]=h(""),m=async X=>{if(!a){r(!0),i("");try{await X()}catch(N){i(N.message)}finally{r(!1)}}},[c,u]=h(""),[p,f]=h("text"),[v,g]=h([]),[w,C]=h(""),[k,y]=h(null),[b,T]=h(null),$=k?.path??b?.path,[x,E]=h(""),[A,P]=h(!1),[D,S]=h(!1),[R,M]=h(""),[O,B]=h(""),[ee,se]=h(!1);Qe(()=>{k?.folder===t&&M(Uo(t,k,x,ee))},[t,k,ee]),_(()=>{if(!k||x===k.text)return;let X=N=>{N.preventDefault(),N.returnValue=""};return window.addEventListener("beforeunload",X),()=>window.removeEventListener("beforeunload",X)},[k,x]);let te=X=>m(async()=>{let N;try{N={...await U(`/api/workspace/file?repo=${J(t)}&path=${J(X)}`),folder:t}}catch(ie){let pe=await U(`/api/file?repo=${J(t)}&path=${J(X)}`);y(null),T({...pe,reason:ie.message});return}T(null);let ae=kc(t,N.path);se(ae?.mergeConflict===!0),y(ae?{...N,text:ae.text,hash:ae.hash}:N),E(ae?.draft??N.text),S(!!ae&&ae.hash!==N.hash),P(!1),B(""),ae&&V("Recovered your unsaved draft for this tab. Review it before saving.",5e3)}),G=()=>m(async()=>{if(!k)return;let X=await q("/api/workspace/merge-file",{repo:t,path:k.path,base:k.text,draft:x});y({...X.current,folder:t}),E(X.text),S(!1),P(!0),se(!X.clean),B(X.clean?"Independent edits merged. Review the result before saving.":`${X.conflicts} overlapping change(s). Edit the marked sections to preserve the intended result, then remove every conflict marker before saving.`)}),L=()=>m(async()=>{if(k)try{let X=await q("/api/workspace/file",{repo:t,path:k.path,text:x,expectedHash:k.hash});y({...k,...X,text:x}),se(!1),P(!1),V("File saved")}catch(X){throw S(!0),X}}),Y=Q();return _(()=>{if(!s){Y.current=void 0;return}!a&&Y.current!==s&&(Y.current=s,te(s))},[s,a]),e("section",{class:"code-browser","aria-label":"Code browser",children:[e("p",{class:"help code-scope",children:["Editing scope: ",e("code",{children:t||"Choose a repository"})]}),o?e("p",{class:"msg err",role:"alert",children:o}):null,a?e("p",{role:"status",children:"Working\u2026"}):null,e("details",{open:!$,children:[e("summary",{children:"Browse files"}),e(wc,{root:t,onOpen:X=>{a||te(X)}})]}),$?e("div",{class:"settings-actions",children:[e("button",{class:"btn small",onClick:()=>{y(null),T(null),n?.()},children:"Back to the files"}),Z.value.view==="composer"&&t===ne.value?e("button",{class:"btn small",onClick:()=>Rr({path:$,type:"file"}),children:"+ Task"}):null,e("button",{class:"btn small",onClick:()=>{us.value=`About ${$}: `,Vt(null),gt("chat")},children:"Ask about this file"})]}):null,b?e("section",{"aria-label":"Read-only file preview",children:[e("h3",{children:b.path}),e("p",{class:"help",children:["Read-only \xB7 ",Ht(b.size)," \xB7 ",b.reason]}),b.binary?e("p",{children:"This is a binary file."}):e("pre",{class:"file-view",tabIndex:0,children:b.text?.split(`
37
+ `).slice(0,5e3).join(`
38
+ `)}),b.truncated||(b.text?.split(`
39
+ `).length??0)>5e3?e("p",{class:"help",children:"Showing a bounded preview; the rest of the file is omitted."}):null]}):null,e("h2",{children:"Search and edit"}),e("div",{class:"wb-row",children:[e("select",{class:"field","aria-label":"Code search mode",value:p,onChange:X=>f(X.currentTarget.value),children:[e("option",{value:"text",children:"Text"}),e("option",{value:"symbols",children:"Declarations"}),e("option",{value:"semantic",children:"JavaScript/TypeScript symbols"})]}),e("input",{class:"field","aria-label":"Search code",disabled:!t||a,placeholder:p==="symbols"?"Function, class, or variable":"Search file contents",value:c,onInput:X=>u(X.currentTarget.value),onKeyDown:X=>{X.key==="Enter"&&m(async()=>{let N=await U(`/api/workspace/search?repo=${J(t)}&q=${J(c)}&mode=${p}`);g(N.hits),C(`${N.scanned} files inspected${N.truncated?" \xB7 results limited; narrow your query":""}`)})}}),e("button",{class:"btn",disabled:!t||a,onClick:()=>m(async()=>{let X=await U(`/api/workspace/search?repo=${J(t)}&q=${J(c)}&mode=${p}`);g(X.hits),C(`${X.scanned} files inspected${X.truncated?" \xB7 results limited":""}`)}),children:"Search"})]}),e("p",{class:"help",children:"Declaration search recognizes common forms in several languages. JavaScript/TypeScript symbols and references use an isolated TypeScript language service over bounded saved repository files; external libraries and compiler plugins are excluded."}),w?e("p",{class:"help",children:w}):null,e("div",{class:"wb-hits",children:v.map(X=>e("p",{children:[e("button",{class:"btn ghost wb-path",onClick:()=>te(X.path),children:[X.path,":",X.line," ",X.symbol??""]}),e("code",{children:X.text}),X.column?e("button",{class:"btn small",disabled:a,onClick:()=>m(async()=>{let N=await U(`/api/workspace/references?repo=${J(t)}&path=${J(X.path)}&line=${X.line}&column=${X.column}`);g(N.hits),C(`${N.hits.length} references in ${N.scanned} saved source files${N.truncated?" \xB7 results limited":""}. ${N.note}`)}),children:["Find references to ",X.symbol??`${X.path}:${X.line}`]}):null]},`${X.path}:${X.line}`))}),e("div",{class:"wb-row",children:[e("input",{class:"field","aria-label":"File to edit",disabled:!t||a,placeholder:"Repository-relative file path",value:d,onInput:X=>l(X.currentTarget.value)}),e("button",{class:"btn",disabled:a||!t||!d.trim(),onClick:()=>te(d.trim()),children:"Open file"})]}),k?e(j,{children:[e("h3",{children:k.path}),e("textarea",{class:"field wb-editor","aria-label":"File contents",spellcheck:!1,disabled:a,value:x,onInput:X=>{let N=X.currentTarget.value;E(N),k.folder===t&&M(Uo(t,k,N,ee))}}),O?e("p",{class:"at-notice",role:"status",children:O}):null,e("div",{class:"wb-row",children:[e("button",{class:"btn",onClick:()=>P(!A),children:A?"Hide comparison":"Preview changes"}),e("button",{class:"btn primary",disabled:a||D||x===k.text||ee&&/^(?:<<<<<<< |=======$|>>>>>>> |\|\|\|\|\|\|\| )/m.test(x),onClick:L,children:"Save file"}),D?e("button",{class:"btn",onClick:G,children:"Load current version and keep draft"}):null,e("button",{class:"btn",onClick:()=>Ta(k.path.split("/").pop()??"draft.txt",x,"text/plain"),children:"Export draft"})]}),A?e("div",{class:"wb-diff",children:[e("div",{children:[e("h4",{children:"Current file"}),e("pre",{children:k.text})]}),e("div",{children:[e("h4",{children:"Your draft"}),e("pre",{children:x})]})]}):null,e("p",{class:"help",children:["Saving checks the loaded version and preserves concurrent edits. Files in active run worktrees cannot be edited here. ",R==="sensitive"?"This credential filename is excluded from browser draft recovery; export your draft before leaving.":R==="full"?"Browser draft storage is unavailable; export your draft before leaving.":"Unsaved drafts can be recovered in this browser tab for 24 hours."]})]}):null,k?e(xr,{folder:t,paths:[k.path],refreshKey:k.hash},k.path):null]})}var Cc=[{label:"Code and verification",tools:[["verification","Verification"],["code","Code"],["context","Context"],["history","History"]]},{label:"Repository operations",tools:[["services","Services"],["coordination","Coordinated changes"],["filtered-tasks","Filtered tasks"]]}],Up=t=>{let s=t.replace(/-/g," ");return s.charAt(0).toUpperCase()+s.slice(1)};function Ta(t,s,n="application/json"){let a=URL.createObjectURL(new Blob([s],{type:n})),r=document.createElement("a");r.href=a,r.download=t,r.click(),setTimeout(()=>URL.revokeObjectURL(a),1e3)}function Ir({projectId:t,initialFolder:s,initialTool:n,onNavigate:a}){let r=fe.value.find(F=>F.id===t),o=t?r?.repos??[]:ne.value?[ne.value]:[],[i,d]=h(n??"verification"),[l,m]=h(s??o[0]??""),c=F=>{d(F),a?.(l,F)},u=F=>{m(F),a?.(F,i)};_(()=>{d(n??"verification")},[n]);let[p,f]=h(""),[v,g]=h(!1),[w,C]=h(null),[k,y]=h("standard"),[b,T]=h("HEAD"),[$,x]=h(""),[E,A]=h(""),[P,D]=h(1),[S,R]=h(null),[M,O]=h(""),[B,ee]=h(null),[se,te]=h(null),[G,L]=h(""),[Y,X]=h(null),[N,ae]=h(null),[ie,pe]=h(""),[ge,Ie]=h(""),[xe,We]=h(null),[Ve,I]=h([]),[re,oe]=h(""),he=[...Ne.value.values()].filter(F=>o.includes(F.repo)&&(!t||F.project===t||!F.project)),le=he.find(F=>F.worktrees.some(W=>W.path===l)),ce=le?.worktrees.find(F=>F.path===l),H=r??fe.value.find(F=>F.id===re)??fe.value.find(F=>F.repos.includes(le?.repo??l)),Ae=async(F,W)=>Re(async()=>{await q(F,W),V("Updated")}),Re=async F=>{if(!v){g(!0),f("");try{await F()}catch(W){f(W.message)}finally{g(!1)}}};return Qe(()=>{!s&&!l&&o[0]&&m(o[0])},[o.join("\0"),l]),_(()=>{R(null),C(null),te(null),ee(null),X(null),ae(null),We(null),f("")},[l]),t&&!r?e("p",{role:"status",children:Us.value?"This project no longer exists.":"Loading project\u2026"}):t&&l&&!o.includes(l)&&!ce?e("p",{class:"msg warn",role:"status",children:"This repository or run worktree is unavailable in this project. Choose a repository above."}):e("div",{class:"workbench",children:[e("header",{class:"page-head",children:e("div",{class:"page-head-text",children:[e("h3",{children:"Inspect, verify, and recover"}),e("p",{children:"Check the repository, inspect code and context, and manage results with evidence."})]})}),e("div",{class:"wb-target",children:[e("label",{class:"lbl",for:"wb-folder",children:"Repository or run worktree"}),e("select",{id:"wb-folder",class:"field",value:l,disabled:v,onChange:F=>u(F.currentTarget.value),children:[o.length?o.map(F=>e("option",{value:F,children:F},F)):e("option",{value:"",children:"Choose a repository in New run"}),he.flatMap(F=>F.worktrees.map(W=>e("option",{value:W.path,children:[(F.task.split(`
40
+ `)[0]||"(no task)").slice(0,50)," \xB7 ",W.name]},`${F.id}/${W.name}`)))]})]}),e("div",{class:"wb-mobile-tool",children:[e("label",{class:"lbl",for:"wb-tool",children:"Repository tool"}),e("select",{id:"wb-tool",class:"field",value:i,disabled:v,onChange:F=>c(F.currentTarget.value),children:Cc.map(F=>e("optgroup",{label:F.label,children:F.tools.map(([W,ue])=>e("option",{value:W,children:ue},W))},F.label))})]}),e("div",{class:"wb-layout",children:[e("nav",{class:"wb-tabs","aria-label":"Repository tools",children:Cc.map((F,W)=>e("div",{class:"wb-group",role:"group","aria-labelledby":`wb-group-${W}`,children:[e("div",{class:"wb-group-label",id:`wb-group-${W}`,children:F.label}),F.tools.map(([ue,ze])=>e("button",{type:"button",class:"wb-tab","aria-current":i===ue?"page":void 0,onClick:()=>c(ue),children:ze},ue))]},F.label))}),e("div",{class:"wb-main",children:[!l&&i!=="coordination"&&i!=="filtered-tasks"?e("p",{class:"help wb-note",children:"Choose a repository in New run first."}):null,p?e("div",{class:"msg err",role:"alert",children:p}):null,v?e("p",{class:"help wb-note",role:"status",children:"Working\u2026"}):null,i==="verification"?e("section",{class:"wb-card",children:[e("h2",{children:"Verification profile"}),e("div",{class:"wb-row",children:[e("label",{children:["Profile ",e("select",{class:"field",value:k,onChange:F=>y(F.currentTarget.value),children:[e("option",{value:"lightweight",children:"Lightweight"}),e("option",{value:"standard",children:"Standard"}),e("option",{value:"thorough",children:"Thorough"})]})]}),e("button",{class:"btn",disabled:!l||v,onClick:()=>Re(async()=>{let F=await U(`/api/verification/profile?repo=${J(l)}&preset=${k}`);C(F),A(F.setup??"")}),children:"Detect checks"})]}),w?e(j,{children:[e("p",{class:"help",children:[w.source?`Detected from ${w.source}. `:"","Required gates must pass. A skipped gate or flaky result cannot verify a change."]}),w.checks.map((F,W)=>e("div",{class:"wb-check",children:[e("span",{children:F.title??F.id}),e("input",{class:"field",type:"text","aria-label":`Command for ${F.id}`,value:F.command,onInput:ue=>C({...w,checks:w.checks.map((ze,qe)=>qe===W?{...ze,command:ue.currentTarget.value}:ze)})}),e("label",{children:[e("input",{type:"checkbox",checked:F.required,onChange:ue=>C({...w,checks:w.checks.map((ze,qe)=>qe===W?{...ze,required:ue.currentTarget.checked}:ze)})})," Required"]})]},F.id)),e("button",{class:"btn small",disabled:w.checks.length>=12,onClick:()=>C({...w,checks:[...w.checks,{id:`custom-${w.checks.length+1}`,kind:"custom",command:"",required:!0,timeoutMs:3e5}]}),children:"Add custom gate"}),e("details",{children:[e("summary",{children:"Requirement evidence mapping"}),e("p",{class:"help",children:"Describe each criterion and select the checks that exercise it. A criterion with no checks, or a failing mapped check, remains uncovered. Review whether the checks actually test the stated behavior."}),(w.requirements??[]).map((F,W)=>e("div",{children:[e("label",{children:[F.id,e("input",{class:"field","aria-label":`Description for ${F.id}`,value:F.description,onInput:ue=>C({...w,requirements:w.requirements.map((ze,qe)=>qe===W?{...ze,description:ue.currentTarget.value}:ze)})})]}),e("div",{class:"wb-row",children:w.checks.map(ue=>e("label",{class:"check",children:[e("input",{type:"checkbox",checked:F.checks.includes(ue.id),onChange:ze=>C({...w,requirements:w.requirements.map((qe,_a)=>_a===W?{...qe,checks:ze.currentTarget.checked?[...qe.checks,ue.id]:qe.checks.filter(io=>io!==ue.id)}:qe)})})," ",ue.title??ue.id]},ue.id))})]},F.id)),e("button",{class:"btn small",disabled:(w.requirements?.length??0)>=48,onClick:()=>C({...w,requirements:[...w.requirements??[],{id:`criterion-${(w.requirements?.length??0)+1}`,description:"",checks:[]}]}),children:"Add criterion"})]}),e("div",{class:"wb-row",children:[e("label",{children:["Commit or branch",e("input",{class:"field",value:b,onInput:F=>T(F.currentTarget.value)})]}),e("label",{children:["Compare baseline",e("input",{class:"field",placeholder:"Optional base commit",value:$,onInput:F=>x(F.currentTarget.value)})]}),e("label",{children:["Attempts per gate",e("select",{class:"field",value:P,onChange:F=>D(Number(F.currentTarget.value)),children:[1,2,3].map(F=>e("option",{value:F,children:F}))})]})]}),e("label",{children:["Setup command",e("input",{class:"field",placeholder:"Optional, e.g. npm ci",value:E,onInput:F=>A(F.currentTarget.value)})]}),e("p",{class:"help",children:"Executes repository code in a temporary worktree at the selected commit. Uncommitted changes are excluded. Baseline comparison runs the same profile on both commits."}),e("div",{class:"wb-row",children:[e("button",{class:"btn primary",disabled:v||!w.checks.length||w.checks.some(F=>!F.command.trim()),onClick:()=>Re(async()=>{R(null),R(await q("/api/verification",{repo:l,profile:w,baseRef:b,baseline:$,setup:E,repeats:P}))}),children:"Run verification"}),e("button",{class:"btn",onClick:()=>Ta("verification-profile.json",JSON.stringify(w,null,2)),children:"Export profile"})]})]}):e("p",{class:"help",children:"Detect commands from this repository, then review the profile before executing it."}),S?e(j,{children:[e("h3",{children:["Result: ",S.state]}),e("p",{class:"help",children:["Commit ",S.commit.slice(0,12)]}),e("div",{class:"wb-scroll",children:e("table",{children:[e("thead",{children:e("tr",{children:[e("th",{children:"Gate"}),e("th",{children:"Required"}),e("th",{children:"Result"}),e("th",{children:"Evidence"})]})}),e("tbody",{children:S.checks.map(F=>e("tr",{children:[e("td",{children:F.check.title??F.check.id}),e("td",{children:F.check.required?"Yes":"No"}),e("td",{children:e("span",{class:`badge ${F.diagnosis==="passed"?"ok":F.diagnosis==="failed"||F.diagnosis==="regression"?"err":"warn"}`,children:Up(F.diagnosis)})}),e("td",{children:e("details",{children:[e("summary",{children:[F.attempts.length," attempts"]}),F.attempts.map((W,ue)=>e("pre",{children:W.output||`Exit ${W.exitCode}`},ue))]})})]},F.check.id))})]})}),S.skipped.map(F=>e("p",{class:"msg err",children:[F.check.id,": ",F.reason]})),S.requirements?.length?e("section",{"aria-label":"Requirement verification results",children:[e("h4",{children:"Requirement evidence"}),e("ul",{children:S.requirements.map(F=>e("li",{children:[F.covered?"Covered":"Uncovered",": ",F.description,F.missing.length?` \xB7 missing ${F.missing.join(", ")}`:F.covered?"":" \xB7 no checks mapped"]},F.id))})]}):null,e("button",{class:"btn",onClick:()=>Ta("verification.md",S.markdown,"text/markdown"),children:"Export report"})]}):null]}):null,i==="code"?e($r,{folder:l},l):null,i==="context"?e("section",{class:"wb-card",children:[e("h2",{children:"Context inspector"}),e("p",{class:"help",children:"Preview explicit file context before selecting it for a task. Credential-file contents are excluded, and recognizable secrets are redacted."}),e("textarea",{class:"field","aria-label":"Context file paths",rows:5,placeholder:"One repository-relative file per line",value:M,onInput:F=>O(F.currentTarget.value)}),e("button",{class:"btn",disabled:!l||v||!M.trim(),onClick:()=>Re(async()=>ee(await q("/api/workspace/context",{repo:l,paths:M.split(`
41
+ `).map(F=>F.trim()).filter(Boolean)}))),children:"Inspect context"}),B?e(j,{children:[e("p",{children:[B.bytes.toLocaleString()," bytes \xB7 approximately ",B.approximateTokens.toLocaleString()," tokens"]}),e("p",{class:"help",children:B.note}),B.files.map(F=>e("details",{children:[e("summary",{children:[F.path," ",F.sensitive?"\xB7 sensitive":`\xB7 ${F.bytes} bytes`]}),e("pre",{children:F.omitted??F.preview})]},F.path))]}):null]}):null,i==="history"?e("section",{class:"wb-card",children:[e("h2",{children:"Checkpoints and run controls"}),le?e(j,{children:[e("p",{children:[le.task.split(`
42
+ `)[0]," \xB7 ",le.status,le.pauseRequested?" \xB7 pause requested":""]}),e("div",{class:"wb-row",children:[e("button",{class:"btn",onClick:()=>{Z.value={view:"run",id:le.id}},children:"Open run"}),le.status==="running"?e("button",{class:"btn",disabled:v,onClick:()=>Ae(`/api/runs/${le.id}/pause`,{paused:!le.pauseRequested}),children:le.pauseRequested?"Continue dispatch":"Pause after active work"}):null,e("label",{children:["Priority",e("select",{class:"field",value:le.priority??0,onChange:F=>Ae(`/api/runs/${le.id}/priority`,{priority:Number(F.currentTarget.value)}),children:[-10,0,10].map(F=>e("option",{value:F,children:F===10?"High":F===-10?"Background":"Normal"}))})]}),e("button",{class:"btn",disabled:v,onClick:()=>Re(async()=>Ta(`run-${le.id}.json`,JSON.stringify(await U(`/api/runs/${le.id}/export?transcript=1`),null,2))),children:"Export run evidence"})]})]}):e("p",{class:"help",children:"Select a run worktree above to pause, prioritize, fork, or apply its checkpoint files."}),e("button",{class:"btn",disabled:!l||v,onClick:()=>Re(async()=>{let F=await U(`/api/workspace/checkpoints?repo=${J(l)}`);te(F),L(F.checkpoints[0]?.sha??"")}),children:"Load checkpoints"}),se?e(j,{children:[e("div",{class:"wb-row",children:[e("select",{class:"field","aria-label":"Checkpoint",value:G,onChange:F=>{L(F.currentTarget.value),X(null),ae(null)},children:se.checkpoints.map(F=>e("option",{value:F.sha,children:[F.sha.slice(0,8)," \xB7 ",F.subject]}))}),le?e("button",{class:"btn",disabled:v||!G,onClick:()=>Re(async()=>{let F=await q(`/api/runs/${le.id}/fork`,{commit:G});Z.value={view:"run",id:F.id}}),children:"Fork from checkpoint"}):null]}),le?e(j,{children:[e("textarea",{class:"field","aria-label":"Checkpoint paths",placeholder:"Files to restore from this checkpoint, one per line",value:ie,onInput:F=>pe(F.currentTarget.value)}),e("p",{class:"help",children:"Applying selected files changes this worktree without committing them. The worktree must be clean and idle; existing changes are preserved by refusing the operation."}),e("button",{class:"btn",disabled:v||le.status==="running"||!ie.trim(),onClick:()=>Re(async()=>{await q("/api/workspace/apply-checkpoint",{repo:l,runId:le.id,source:G,expectedHead:se.head,paths:ie.split(`
43
+ `).map(F=>F.trim()).filter(Boolean)}),V("Selected checkpoint files applied; review before committing")}),children:"Apply selected files"})]}):null]}):null]}):null,i==="history"&&se?e("section",{class:"wb-card","aria-label":"Full checkpoint comparison",children:[e("h2",{children:"Compare and revert commits"}),e("p",{class:"help",children:"Compare every changed file between the selected checkpoint and the observed current HEAD. Reverting computes the inverse of one non-merge commit on a disposable checkout, then stages that reviewed change in a clean, idle owned worktree. Commit it yourself to record the revert."}),e("div",{class:"wb-row",children:[e("button",{class:"btn",disabled:v||!G,onClick:()=>Re(async()=>X(await q("/api/workspace/compare-checkpoint",{repo:l,from:G,to:se.head}))),children:"Compare selected checkpoint to HEAD"}),le?e("button",{class:"btn",disabled:v||le.status==="running"||!G,onClick:()=>Re(async()=>{ae(null),ae(await q("/api/workspace/preview-revert",{repo:l,runId:le.id,commit:G,expectedHead:se.head}))}),children:"Preview inverse commit"}):null]}),Y?e(j,{children:[e("p",{class:"help",children:[Y.from.slice(0,12)," \u2192 ",Y.to.slice(0,12)," \xB7 ",Y.files.length," changed paths",Y.truncated?" \xB7 preview truncated":""]}),Y.stat.trim()?e("pre",{children:Y.stat}):null,e("details",{children:[e("summary",{children:"Full commit patch"}),e("pre",{children:Y.patch||"No changes between these commits."})]})]}):null,N&&le?e("div",{class:"at-notice","aria-label":"Reviewed commit revert",children:[e("h4",{children:["Revert: ",N.subject]}),e("p",{class:"help",children:["Commit ",N.commit.slice(0,12)," \xB7 current HEAD ",N.head.slice(0,12),". Review the entire inverse patch before applying it. Conflicting reversions leave this worktree unchanged."]}),N.stat.trim()?e("pre",{children:N.stat}):null,e("details",{open:!0,children:[e("summary",{children:"Inverse patch to stage"}),e("pre",{children:N.patch})]}),e("button",{class:"btn primary",disabled:v||le.status==="running",onClick:()=>Re(async()=>{await q("/api/workspace/apply-revert",{repo:l,runId:le.id,commit:N.commit,expectedHead:N.head,fingerprint:N.fingerprint}),ae(null),V("Inverse change staged. Review and commit it to record the revert.",6e3)}),children:"Stage reviewed inverse change"})]}):null]}):null,i==="history"&&se&&le?e("section",{class:"wb-card",children:[e("h2",{children:"Apply selected hunks"}),e("p",{class:"help",children:"Compare one existing text file against the selected checkpoint. Selected hunks remain unstaged for review; the run worktree must be clean and idle."}),e("div",{class:"wb-row",children:[e("input",{class:"field","aria-label":"File for checkpoint hunks",value:ge,placeholder:"Repository-relative file",onInput:F=>Ie(F.currentTarget.value)}),e("button",{class:"btn",disabled:v||le.status==="running"||!ge.trim(),onClick:()=>Re(async()=>{We(await q("/api/workspace/checkpoint-hunks",{repo:l,runId:le.id,source:G,path:ge.trim()})),I([])}),children:"Compare hunks"})]}),xe?e(j,{children:[e("p",{children:[xe.hunks.length," hunks \xB7 ",xe.source.slice(0,12)]}),xe.hunks.map(F=>e("details",{children:[e("summary",{children:e("label",{children:[e("input",{type:"checkbox",checked:Ve.includes(F.id),onChange:W=>I(W.currentTarget.checked?[...Ve,F.id]:Ve.filter(ue=>ue!==F.id))})," ",F.header]})}),e("pre",{children:F.patch})]},F.id)),e("button",{class:"btn",disabled:v||!Ve.length||le.status==="running",onClick:()=>Re(async()=>{await q("/api/workspace/apply-hunks",{repo:l,runId:le.id,source:xe.source,path:xe.path,expectedHead:xe.head,hunks:Ve}),We(null),V("Selected hunks applied; review the unstaged changes")}),children:"Apply chosen hunks"})]}):null]}):null,i==="filtered-tasks"?e(j,{children:[e("div",{class:"wb-scope",children:[e("label",{class:"lbl",for:"filtered-tasks-project",children:"Filtered tasks project"}),e("select",{class:"field",id:"filtered-tasks-project",disabled:!!t,value:H?.id??"",onChange:F=>oe(F.currentTarget.value),children:fe.value.map(F=>e("option",{value:F.id,children:F.name},F.id))})]}),H?e(j,{children:[e("p",{class:"help wb-note",children:["Manage project filesystem rules in ",e("a",{href:"#/settings/projects",children:"Settings \u2192 Projects & access"}),"."]}),e(hc,{projectId:H.id,repos:H.repos},H.id)]}):e("p",{class:"help wb-note",children:["Create a project in ",e("a",{href:"#/settings/projects",children:"Settings"})," first."]})]}):null,i==="coordination"?e(vc,{}):null,i==="services"?le&&ce?e(mc,{runId:le.id,worktree:ce.name},`${le.id}/${ce.name}`):e("p",{class:"help wb-note",children:"Select a run worktree to preview and launch its configured services."}):null]})]})]})}function Tc({current:t}){if(t.view!=="inbox"&&t.view!=="automations"&&t.view!=="workspace"&&t.view!=="insights")return null;let s=t.view==="workspace"&&t.project?fe.value.find(n=>n.id===t.project)?.name:void 0;return e("div",{class:"activity-page",children:[e("header",{class:"page-head",children:[e("div",{class:"page-head-text",children:e("h1",{children:s?`${s} repositories`:{inbox:"Inbox",automations:"Scheduling",workspace:"Repository tools",insights:"Insights"}[t.view]})}),t.view==="workspace"&&t.project?e("a",{class:"btn",href:`#/project/${encodeURIComponent(t.project)}`,children:"Back to project"}):null]}),t.view==="inbox"?e(Sa,{mode:"inbox"}):null,t.view==="automations"?e(Ar,{kind:t.kind}):null,t.view==="workspace"&&!t.project&&!ne.value?e("section",{children:[e("p",{children:["Choose a project or open a repository on ",Qt(),"."]}),e("div",{class:"project-destinations",children:[fe.value.map(n=>e("a",{class:"btn",href:`#/project/${encodeURIComponent(n.id)}/repositories`,children:n.name})),e("button",{class:"btn",onClick:()=>Gs(),children:"Open repository"})]})]}):null,t.view==="workspace"?e(Ir,{projectId:t.project}):null,t.view==="insights"?e(pc,{group:t.group}):null]})}function Sc(){_(()=>(window.addEventListener("hashchange",Hn),window.addEventListener("pagehide",Hn),()=>{window.removeEventListener("hashchange",Hn),window.removeEventListener("pagehide",Hn),Hn()}),[]);let t=Sl.value[0];return t?e(Fp,{request:t},t.id):null}function Fp({request:t}){let s=Q(null),n=Q(null),a=r=>{s.current?.close(),To(t.id,r)};return Qe(()=>{let r=document.activeElement;return s.current?.showModal(),n.current?.focus(),()=>{s.current?.close(),r instanceof HTMLElement&&r.isConnected&&r.focus()}},[]),e("dialog",{ref:s,class:"picker small-dialog confirmation-dialog","aria-labelledby":`confirmation-title-${t.id}`,"aria-describedby":`confirmation-body-${t.id}`,onCancel:r=>{r.preventDefault(),r.stopPropagation(),a(!1)},onClose:()=>To(t.id,!1),children:e("div",{class:"picker-inner",children:[e("div",{class:"picker-head",children:e("h3",{id:`confirmation-title-${t.id}`,children:t.title})}),e("div",{class:"dialog-body",id:`confirmation-body-${t.id}`,children:t.message.split(/\n\s*\n/).map((r,o)=>e("p",{children:r},o))}),e("div",{class:"picker-foot",children:[e("span",{class:"ps"}),e("button",{type:"button",class:"btn",ref:n,onClick:()=>a(!1),children:"Cancel"}),e("button",{type:"button",class:`btn ${t.danger?"danger":"primary"}`,onClick:()=>a(!0),children:t.confirmLabel})]})]})})}function Vp(t,s){for(var n in s)t[n]=s[n];return t}function xc(t,s){for(var n in t)if(n!=="__source"&&!(n in s))return!0;for(var a in s)if(a!=="__source"&&t[a]!==s[a])return!0;return!1}function Rc(t,s){this.props=t,this.context=s}(Rc.prototype=new Zt).isPureReactComponent=!0,Rc.prototype.shouldComponentUpdate=function(t,s){return xc(this.props,t)||xc(this.state,s)};var $c=$t.__b;$t.__b=function(t){t.type&&t.type.__f&&t.ref&&(t.props.ref=t.ref,t.ref=null),$c&&$c(t)};var Wb=typeof Symbol<"u"&&Symbol.for&&Symbol.for("react.forward_ref")||3911;var zp=$t.__e;$t.__e=function(t,s,n,a){if(t.then){for(var r,o=s;o=o.__;)if((r=o.__c)&&r.__c)return s.__e==null&&(s.__e=n.__e,s.__k=n.__k||[]),r.__c(t,s)}zp(t,s,n,a)};var Ic=$t.unmount;function Lc(t,s,n){return t&&(t.__c&&t.__c.__H&&(t.__c.__H.__.forEach(function(a){typeof a.__c=="function"&&a.__c()}),t.__c.__H=null),(t=Vp({},t)).__c!=null&&(t.__c.__P===n&&(t.__c.__P=s),t.__c.__e=!0,t.__c=null),t.__k=t.__k&&t.__k.map(function(a){return Lc(a,s,n)})),t}function Dc(t,s,n){return t&&n&&(t.__v=null,t.__k=t.__k&&t.__k.map(function(a){return Dc(a,s,n)}),t.__c&&t.__c.__P===s&&(t.__e&&n.appendChild(t.__e),t.__c.__e=!0,t.__c.__P=n)),t}function xa(){this.__u=0,this.o=null,this.__b=null}function Nc(t){var s=t.__&&t.__.__c;return s&&s.__a&&s.__a(t)}function Oc(t){var s,n,a,r=null;function o(i){if(s||(s=t()).then(function(d){d&&(r=d.default||d),a=!0},function(d){n=d,a=!0}),n)throw n;if(!a)throw s;return r?ua(r,i):null}return o.displayName="Lazy",o.__f=!0,o}function Er(){this.i=null,this.l=null}$t.unmount=function(t){var s=t.__c;s&&(s.__z=!0),s&&s.__R&&s.__R(),s&&32&t.__u&&(t.type=null),Ic&&Ic(t)},(xa.prototype=new Zt).__c=function(t,s){var n=s.__c,a=this;a.o==null&&(a.o=[]),a.o.push(n);var r=Nc(a.__v),o=!1,i=function(){o||a.__z||(o=!0,n.__R=null,r?r(l):l())};n.__R=i;var d=n.__P;n.__P=null;var l=function(){if(!--a.__u){if(a.state.__a){var m=a.state.__a;a.__v.__k[0]=Dc(m,m.__c.__P,m.__c.__O)}var c;for(a.setState({__a:a.__b=null});c=a.o.pop();)c.__P=d,c.forceUpdate()}};a.__u++||32&s.__u||a.setState({__a:a.__b=a.__v.__k[0]}),t.then(i,i)},xa.prototype.componentWillUnmount=function(){this.o=[]},xa.prototype.render=function(t,s){if(this.__b){if(this.__v.__k){var n=document.createElement("div"),a=this.__v.__k[0].__c;this.__v.__k[0]=Lc(this.__b,n,a.__O=a.__P)}this.__b=null}var r=s.__a&&ua(j,null,t.fallback);return r&&(r.__u&=-33),[ua(j,null,s.__a?null:t.children),r]};var Ac=function(t,s,n){if(++n[1]===n[0]&&t.l.delete(s),t.props.revealOrder&&(t.props.revealOrder[0]!=="t"||!t.l.size))for(n=t.i;n;){for(;n.length>3;)n.pop()();if(n[1]<n[0])break;t.i=n=n[2]}};(Er.prototype=new Zt).__a=function(t){var s=this,n=Nc(s.__v),a=s.l.get(t);return a[0]++,function(r){var o=function(){s.props.revealOrder?(a.push(r),Ac(s,t,a)):r()};n?n(o):o()}},Er.prototype.render=function(t){this.i=null,this.l=new Map;var s=qa(t.children);t.revealOrder&&t.revealOrder[0]==="b"&&s.reverse();for(var n=s.length;n--;)this.l.set(s[n],this.i=[1,0,this.i]);return t.children},Er.prototype.componentDidUpdate=Er.prototype.componentDidMount=function(){var t=this;this.l.forEach(function(s,n){Ac(t,n,s)})};var Jp=typeof Symbol<"u"&&Symbol.for&&Symbol.for("react.element")||60103,Kp=/^(?:accent|alignment|arabic|baseline|cap|clip(?!PathU)|color|dominant|fill|flood|font|glyph(?!R)|horiz|image(!S)|letter|lighting|marker(?!H|W|U)|overline|paint|pointer|shape|stop|strikethrough|stroke|text(?!L)|transform|underline|unicode|units|v|vector|vert|word|writing|x(?!C))[A-Z]/,Gp=/^on(Ani|Tra|Tou|BeforeInp|Compo)/,Yp=/[A-Z0-9]/g,Qp=typeof document<"u",Xp=function(t){return(typeof Symbol<"u"&&typeof Symbol()=="symbol"?/fil|che|rad/:/fil|che|ra/).test(t)};Zt.prototype.isReactComponent=!0,["componentWillMount","componentWillReceiveProps","componentWillUpdate"].forEach(function(t){Object.defineProperty(Zt.prototype,t,{configurable:!0,get:function(){return this["UNSAFE_"+t]},set:function(s){Object.defineProperty(this,t,{configurable:!0,writable:!0,value:s})}})});var Ec=$t.event;$t.event=function(t){return Ec&&(t=Ec(t)),t.persist=function(){},t.isPropagationStopped=function(){return this.cancelBubble},t.isDefaultPrevented=function(){return this.defaultPrevented},t.nativeEvent=t};var _c,Zp={configurable:!0,get:function(){return this.class}},Pc=$t.vnode;$t.vnode=function(t){typeof t.type=="string"&&(function(s){var n=s.props,a=s.type,r={},o=a.indexOf("-")==-1;for(var i in n){var d=n[i];if(!(i==="value"&&"defaultValue"in n&&d==null||Qp&&i==="children"&&a==="noscript"||i==="class"||i==="className")){var l=i.toLowerCase();i==="defaultValue"&&"value"in n&&n.value==null?i="value":i==="download"&&d===!0?d="":l==="translate"&&d==="no"?d=!1:l[0]==="o"&&l[1]==="n"?l==="ondoubleclick"?i="ondblclick":l!=="onchange"||a!=="input"&&a!=="textarea"||Xp(n.type)?l==="onfocus"?i="onfocusin":l==="onblur"?i="onfocusout":Gp.test(i)&&(i=l):l=i="oninput":o&&Kp.test(i)?i=i.replace(Yp,"-$&").toLowerCase():d===null&&(d=void 0),l==="oninput"&&r[i=l]&&(i="oninputCapture"),r[i]=d}}a=="select"&&(r.multiple&&Array.isArray(r.value)&&(r.value=qa(n.children).forEach(function(m){m.props.selected=r.value.indexOf(m.props.value)!=-1})),r.defaultValue!=null&&(r.value=qa(n.children).forEach(function(m){m.props.selected=r.multiple?r.defaultValue.indexOf(m.props.value)!=-1:r.defaultValue==m.props.value}))),n.class&&!n.className?(r.class=n.class,Object.defineProperty(r,"className",Zp)):n.className&&(r.class=r.className=n.className),s.props=r})(t),t.$$typeof=Jp,Pc&&Pc(t)};var jc=$t.__r;$t.__r=function(t){jc&&jc(t),_c=t.__c};var Mc=$t.diffed;$t.diffed=function(t){Mc&&Mc(t);var s=t.props,n=t.__e;n!=null&&t.type==="textarea"&&"value"in s&&s.value!==n.value&&(n.value=s.value==null?"":s.value),_c=null};var Fo=class extends Zt{state={};static getDerivedStateFromError(s){return{error:s}}render(){return this.state.error?e("div",{role:"alert",class:"msg err",children:["This view could not load. ",e("button",{class:"btn",onClick:()=>location.reload(),children:"Reload app"})]}):this.props.children}};function Ys(t){let s=Oc(()=>t().then(n=>({default:n})));return n=>e(Fo,{children:e(xa,{fallback:e("div",{role:"status",class:"help",children:"Loading view\u2026"}),children:e(s,{...n})})})}function Bc(){let[t,s]=h([]),[n,a]=h(""),[r,o]=h(!1);_(()=>{let l=!0,m,c=Ds("approvals",u=>{l&&(u.type==="snapshot"&&u.records&&s(u.records),u.type==="error"&&u.status===404&&!m&&(m=Je(async()=>{let p=await U("/api/approvals");l&&s(p.filter(f=>f.status==="pending"))},2e3)))});return()=>{l=!1,c(),m?.()}},[]);let i=t[0];if(!i)return null;let d=async l=>{o(!0),a("");try{await q(`/api/approvals/${i.id}`,{decision:l}),s(m=>m.filter(c=>c.id!==i.id))}catch(m){a(m.message)}finally{o(!1)}};return e("aside",{class:"approval-inbox",role:"alert","aria-label":"Tool approval required",children:[e("div",{class:"ai-head",children:[e(z,{name:"alert"}),e("h3",{children:"Permission required"}),t.length>1?e("span",{class:"ai-count",children:[t.length," pending"]}):null]}),e("div",{class:"ai-body",children:[e("p",{class:"ai-what",children:i.kind==="command"?"Run this command once":"Apply these file changes once"}),i.command?e("pre",{class:"ai-command",children:i.command}):null,i.paths?.length?e("ul",{class:"ai-paths",children:i.paths.map(l=>e("li",{children:e("code",{children:l})},l))}):null,i.cwd?e("p",{class:"ai-folder",children:["Folder ",e("code",{children:i.cwd})]}):null,i.reason?e("p",{class:"ai-reason",children:i.reason}):null,e("p",{class:"help",children:["Expires at ",new Date(i.expiresAt).toLocaleTimeString(),". This decision grants no session-wide permissions."]}),n?e("p",{class:"msg err",children:n}):null]}),e("div",{class:"ai-actions",children:[e("button",{class:"btn primary",disabled:r,onClick:()=>d("approve"),children:"Approve once"}),e("button",{class:"btn",disabled:r,onClick:()=>d("decline"),children:"Decline"}),e("span",{class:"spacer"}),e("button",{class:"btn ghost",onClick:()=>{Z.value={view:"run",id:i.runId}},children:"Inspect run"})]})]})}function qc(){let t=()=>on.value=!1,s=we(!0,t),n=Q(null),[a,r]=h(""),[o,i]=h(0),d=[{id:"new",label:"New run",detail:"Actions",icon:"plus",run:()=>{st()}},{id:"docs",label:"Help & documentation",detail:"Guides, search and Ask code-flow using your local CLI",icon:"help",run:()=>{window.open("/docs/","_blank","noopener")}},{id:"settings",label:"Settings",detail:"Preferences, agents and remote connections",icon:"sliders",run:()=>Z.value={view:"settings"}},...Ua.filter(p=>!["workspace","automations","insights"].includes(p.id)).map(p=>({id:`settings:${p.id}`,label:p.label,detail:`Settings \xB7 ${p.keywords}`,icon:p.icon,run:()=>Z.value={view:"settings",section:p.id}})),{id:"inbox",label:"Inbox",detail:"Questions, failures and results needing review",icon:"bell",run:()=>Z.value={view:"inbox"}},{id:"automations",label:"Scheduling",detail:"Schedules and deferred runs",icon:"clock",run:()=>Z.value={view:"automations"}},{id:"workspace",label:"Repository tools",detail:"Workspace \xB7 code, checks and repositories",icon:"files",run:()=>Z.value={view:"workspace"}},{id:"insights",label:"Insights",detail:"Run results and usage",icon:"chart",run:()=>Z.value={view:"insights"}},{id:"team",label:"Board",detail:"People team collaboration tasks, hand-overs and your team inbox",icon:"people",run:()=>Z.value={view:"team"}},{id:"repo",label:"Choose repository",detail:"Actions",icon:"folder",run:()=>wt.value=!0},{id:"projects",label:"Manage projects",detail:"Actions",icon:"project",run:()=>zt.value=!0},{id:"health",label:"Check provider and Git health",detail:"Actions",icon:"alert",run:()=>ms.value=!0},{id:"files",label:"Open files panel",detail:"Actions",icon:"files",run:()=>gt("files")},{id:"terminal",label:"Open terminal",detail:"Actions",icon:"terminal",run:()=>gt("terminal")},...fe.value.flatMap(p=>["board","people","automation"].map(f=>({id:`project:${p.id}:${f}`,label:`${p.name} \xB7 ${{board:"Board",people:"People",automation:"Automation"}[f]}`,detail:f==="automation"?"Project schedules backlog missions":"Project collaboration team members access",icon:f==="automation"?"clock":"people",run:()=>{f==="board"||f==="people"?location.assign(Ha(`#/project/${encodeURIComponent(p.id)}/${f}`,"local")):Z.value={view:"project",id:p.id,section:f}}}))),...fe.value.map(p=>({id:`project:${p.id}`,label:p.name,detail:"Project",icon:"project",run:()=>{Z.value={view:"project",id:p.id}}})),...[...Ne.value.values()].filter(p=>!p.archived).sort((p,f)=>f.createdAt-p.createdAt).map(p=>({id:`run:${p.id}`,label:p.task.split(`
44
+ `)[0]||p.id,detail:`Run \xB7 ${p.status} \xB7 ${p.repo}`,shown:`Run \xB7 ${ot[p.status]??p.status} \xB7 ${be(p.repo)}`,status:p.status,run:()=>Z.value={view:"run",id:p.id}}))],l=a.toLowerCase().trim().split(/\s+/).filter(Boolean),m=d.filter(p=>l.every(f=>`${p.label} ${p.detail}`.toLowerCase().includes(f))).slice(0,40),c=Math.min(o,Math.max(0,m.length-1)),u=p=>{p&&(t(),p.run())};return _(()=>{n.current?.focus()},[]),_(()=>{document.getElementById(`command-${c}`)?.scrollIntoView({block:"nearest"})},[c]),e("dialog",{class:"picker command-palette",ref:s,"aria-labelledby":"command-title",children:e("div",{class:"picker-inner",children:[e("div",{class:"picker-head cp-head",children:[e("h3",{id:"command-title",class:"sr-only",children:"Commands and navigation"}),e("div",{class:"cp-search",children:[e(z,{name:"search"}),e("input",{ref:n,class:"field",role:"combobox","aria-label":"Find a command, project or run","aria-autocomplete":"list","aria-controls":"command-results","aria-expanded":"true","aria-activedescendant":m.length?`command-${c}`:void 0,value:a,placeholder:"Type a command, project, or task\u2026",onInput:p=>{r(p.currentTarget.value),i(0)},onKeyDown:p=>{(p.key==="ArrowDown"||p.key==="ArrowUp")&&(p.preventDefault(),i(Math.min(Math.max(0,o+(p.key==="ArrowDown"?1:-1)),Math.max(0,m.length-1)))),p.key==="Enter"&&(p.preventDefault(),u(m[c]))}})]})]}),e("div",{class:"picker-list",id:"command-results",role:"listbox","aria-label":"Matching commands",children:[m.map((p,f)=>e("div",{id:`command-${f}`,class:`command-result ${f===c?"active":""}`,role:"option","aria-selected":f===c,onMouseEnter:()=>i(f),onClick:()=>u(p),children:[p.status?e("span",{class:`cr-dot dot ${p.status}`,"aria-hidden":"true"}):e(z,{name:p.icon??"chevron"}),e("span",{class:"cr-label",children:p.label}),e("span",{class:"cr-detail",title:p.shown?p.detail:void 0,children:p.shown??p.detail})]},p.id)),m.length?null:e("p",{class:"cp-empty",children:"No commands, projects or runs match."})]}),e("div",{class:"picker-foot",children:[e("span",{class:"ps",children:[e("kbd",{children:"\u2191"}),e("kbd",{children:"\u2193"})," to choose \xB7 ",e("kbd",{children:"Enter"})," to open \xB7 ",e("kbd",{children:"Esc"})," to close"]}),e("button",{class:"btn",onClick:t,children:"Close"})]})]})})}var yn=t=>/(?:^|[\s:/(_-])free(?:$|[\s:)\]_-])/i.test(`${t.id} ${t.label}`);function zn(t){return[...t].sort((s,n)=>Number(yn(n))-Number(yn(s)))}function Jn({label:t,title:s,value:n,options:a,onChange:r,placeholder:o="Choose model",compact:i=!1,disabled:d=!1,class:l=""}){let[m,c]=h(!1),[u,p]=h(""),[f,v]=h(!1),[g,w]=h(0),C=Q(null),k=Q(null),y=Q(null),b=Q(null),T=pa(),$=u.toLocaleLowerCase().trim().split(/\s+/).filter(Boolean),x=f?a.filter(R=>!!R.id&&yn(R)):a,E=x.filter(R=>$.every(M=>`${R.label} ${R.id} ${R.description??""}`.toLocaleLowerCase().includes(M))),A=Math.min(g,Math.max(0,E.length-1)),P=a.find(R=>R.id===n),D=(R=!0)=>{c(!1),R&&k.current?.focus()},S=R=>{r(R),D()};return Qe(()=>{if(!m)return;let R=()=>{if(!k.current||!y.current)return;let B=k.current.getBoundingClientRect(),ee=Math.min(Math.max(B.width,340),window.innerWidth-24),se=window.innerHeight-B.bottom-20,te=B.top-20,G=se<280&&te>se;Object.assign(y.current.style,{width:`${ee}px`,left:`${Math.max(12,Math.min(B.left,window.innerWidth-ee-12))}px`,maxHeight:`${Math.min(420,Math.max(100,G?te:se))}px`,top:G?"auto":`${B.bottom+6}px`,bottom:G?`${window.innerHeight-B.top+6}px`:"auto"})};R(),b.current?.focus();let M=B=>{y.current?.contains(B.target)||R()};window.addEventListener("resize",R),document.addEventListener("scroll",M,!0);let O=B=>{C.current?.contains(B.target)||D(!1)};return document.addEventListener("pointerdown",O),()=>{window.removeEventListener("resize",R),document.removeEventListener("scroll",M,!0),document.removeEventListener("pointerdown",O)}},[m]),_(()=>{m&&document.getElementById(`${T}-${A}`)?.scrollIntoView({block:"nearest"})},[m,A,u,f]),e("div",{class:`model-select ${i?"compact":""} ${l}`,ref:C,children:[e("button",{type:"button",class:"model-select-trigger",ref:k,disabled:d,"aria-label":t,"aria-haspopup":"listbox","aria-expanded":m,"aria-controls":m?T:void 0,title:P?.label??o,onClick:()=>{p(""),w(Math.max(0,x.findIndex(R=>R.id===n))),c(!m)},children:[e("span",{children:P?.label??(n||o)}),e(z,{name:"chevron"})]}),m?e("div",{class:"model-select-popup",ref:y,onKeyDown:R=>{R.key==="Escape"&&(R.preventDefault(),R.stopPropagation(),D())},onBlur:R=>{R.relatedTarget&&!R.currentTarget.contains(R.relatedTarget)&&D(!1)},children:[e("div",{class:"model-select-search",children:[e("div",{class:"model-select-heading",children:[e("div",{class:"pop-title",children:s??t}),e("button",{type:"button",class:"model-free-filter","aria-pressed":f,onClick:()=>{v(!f),w(0)},children:[e("span",{"aria-hidden":"true",children:f?"\u2713":"+"})," Free only"]})]}),e("input",{ref:b,class:"field",type:"search",role:"combobox","aria-label":`Search ${t}`,"aria-autocomplete":"list","aria-expanded":"true","aria-controls":T,"aria-activedescendant":E.length?`${T}-${A}`:void 0,placeholder:"Search models\u2026",value:u,onInput:R=>{p(R.currentTarget.value),w(0)},onKeyDown:R=>{R.key==="ArrowDown"||R.key==="ArrowUp"?(R.preventDefault(),w(E.length?(A+(R.key==="ArrowDown"?1:E.length-1))%E.length:0)):R.key==="Enter"&&!R.isComposing&&(R.preventDefault(),E[A]&&S(E[A].id))}})]}),e("div",{class:"model-select-results",role:"listbox",id:T,"aria-label":t,children:E.map((R,M)=>e("button",{id:`${T}-${M}`,type:"button",role:"option","aria-selected":R.id===n,tabIndex:-1,class:`model-select-option ${M===A?"active":""}`,onClick:()=>S(R.id),children:[e("span",{children:[e("span",{class:"model-option-name",children:R.label}),R.description?e("span",{class:"model-option-description",children:R.description}):null]}),e("span",{class:"model-option-meta",children:[R.id&&yn(R)?e("span",{class:"model-free-badge",children:"Free"}):null,R.id===n?e("span",{"aria-hidden":"true",children:"\u2713"}):null]})]},R.id))}),E.length?null:e("div",{class:"model-select-empty",role:"status",children:f?"No free models found. Try another search or turn off Free only.":"No models found. Try another name or model ID."})]}):null]})}function Qs({agent:t,onAgent:s,settings:n,onSettings:a,permissions:r,onPermissions:o,restricted:i=!1,approvalsAvailable:d=!0,providers:l,showPermissions:m=!0}){let[c,u]=h(!1),p=l??Be.value,f=p.find(x=>x.id===t),v=Ns.value[t],g=v&&!("error"in v)?v:void 0,w=g?.models.find(x=>x.id===(n.model||g.defaultModel)),C=w?.efforts??g?.efforts??[],k=n.model?w?.label??n.model:"Default model",y=n.effort||"Default effort",b=x=>{let A=g?.models.find(P=>P.id===(x||g.defaultModel))?.efforts??g?.efforts??[];a({model:x,effort:A.includes(n.effort??"")?n.effort:""})},T=(x,E)=>e(j,{children:[e("span",{children:E}),x?e("span",{class:"chat-choice-check","aria-label":"Selected",children:"\u2713"}):null]}),$=x=>e(j,{children:[e("span",{children:x}),e(z,{name:"chevron"})]});return e("div",{class:"chat-controls",children:[s?e(nt,{above:!0,label:"Provider",icon:"layers",class:"chat-choice",trigger:$(f?.displayName??t),children:x=>e(j,{children:[e(Rt,{children:"Provider"}),p.map(E=>e(me,{on:E.id===t,disabled:!E.available,sub:E.available?void 0:"Not installed",onClick:()=>{s(E.id),r.tools&&o({trust:E.id.startsWith("acp:")?"full":"standard",tools:E.id==="codex"||E.id.startsWith("acp:")}),u(!1),x()},children:T(E.id===t,E.displayName)},E.id))]})}):e("span",{class:"chat-provider-fixed",title:"Provider stays fixed for this conversation. Start a new run to use another provider.",children:f?.displayName??t}),e(Jn,{compact:!0,label:"Model",title:`Model \xB7 ${f?.displayName??t}`,value:n.model??"",placeholder:k,options:[{id:"",label:"Default model",description:g?.defaultModel??"Use the provider's default"},...g?zn(g.models):[],...g?.allowCustom?[{id:"__custom",label:"Other model\u2026"}]:[]],onChange:x=>{x==="__custom"?u(!0):(b(x),u(!1))}}),e(nt,{above:!0,label:"Effort",icon:"sparkle",class:"chat-choice",title:`Effort: ${y}`,trigger:$(y),children:x=>e(j,{children:[e(Rt,{children:"Reasoning effort"}),e(me,{on:!n.effort,sub:w?.defaultEffort??g?.defaultEffort??"Use the provider's default",onClick:()=>{a({...n,effort:""}),x()},children:T(!n.effort,"Default effort")}),C.map(E=>e(me,{on:n.effort===E,onClick:()=>{a({...n,effort:E}),x()},children:T(n.effort===E,E)},E)),C.length?null:e(Rt,{children:"This model offers no effort choices"})]})}),m?e(Ho,{agent:t,permissions:r,onPermissions:o,restricted:i,approvalsAvailable:d}):null,c?e("input",{class:"field chat-custom-model","aria-label":"Custom model",placeholder:"Model ID",value:n.model??"",onInput:x=>b(x.currentTarget.value.trim())}):null]})}function Ho({agent:t="codex",permissions:s,onPermissions:n,restricted:a=!1,approvalsAvailable:r=!0}){let o=s.tools?"Ask for approval":{safe:"Safe",standard:"Approve for me",trusted:"Trusted",full:"Full access"}[s.trust],i=r&&!a&&(t==="codex"||t.startsWith("acp:")),d=(l,m)=>e(j,{children:[e("span",{children:m}),l?e("span",{class:"chat-choice-check","aria-label":"Selected",children:"\u2713"}):null]});return e(nt,{above:!0,label:"Permissions",icon:"sliders",class:`chat-choice chat-permissions ${s.trust==="full"&&!s.tools?"full-access":""}`,trigger:e(j,{children:[e(z,{name:"sliders"}),e("span",{children:o}),e(z,{name:"chevron"})]}),children:l=>e(j,{children:[e(Rt,{children:"How should actions be approved?"}),e(me,{on:s.tools,disabled:!i,sub:i?"Show supported tool requests in the approval inbox.":"Requires a local Codex or ACP provider with approval support.",onClick:()=>{n({trust:t.startsWith("acp:")?"full":"standard",tools:!0}),l()},children:d(s.tools,"Ask for approval")}),e(me,{on:!s.tools&&s.trust==="standard",disabled:a||t.startsWith("acp:"),sub:"Allow routine edits and commands. Restricted actions are blocked.",onClick:()=>{n({trust:"standard",tools:!1}),l()},children:d(!s.tools&&s.trust==="standard","Approve for me")}),e(me,{on:!s.tools&&s.trust==="full",disabled:a,sub:"No provider sandbox. Commands, network and files outside the worktree.",onClick:()=>{n({trust:"full",tools:!1}),l()},children:d(!s.tools&&s.trust==="full","Full access")}),a?e(Rt,{children:"This run's permission restrictions stay in effect."}):null]})})}function Pr({run:t,checking:s=!1,branch:n}){let a=it(t,s,n),r=n?!!t.humanReview?.[n]:Object.keys(t.humanReview??{}).length>0;return e("dl",{class:"run-evidence","aria-label":"Run status and evidence",children:[e("div",{children:[e("dt",{children:"Execution"}),e("dd",{children:lr(t)})]}),e("div",{children:[e("dt",{children:"Checks"}),e("dd",{class:a==="Passed"?"evidence-ok":["Failed","Blocked"].includes(a)?"evidence-warn":"",children:a})]}),e("div",{children:[e("dt",{children:"Agent review"}),e("dd",{children:cr(t,n)})]}),e("div",{children:[e("dt",{children:"Human review"}),e("dd",{children:r?"Recorded \xB7 see file coverage":"Not recorded"})]})]})}function jr({run:t}){return e("details",{class:"verify-profile",children:[e("summary",{children:["Verification evidence",t.verification?` \xB7 ${t.verification.checks.length} checks`:""]}),e("p",{class:"help",children:"Evidence belongs to the recorded run and commit. Review coverage and merge validation check the current branch separately."}),t.checkCantRun?e("p",{class:"msg warn",children:[t.checkCantRun.command,": ",t.checkCantRun.reason]}):null,t.lastCheck?e("p",{children:["Last check: ",e("code",{children:t.lastCheck.command})," \xB7 ",t.lastCheck.ok?"Passed":"Failed"," \xB7 ",new Date(t.lastCheck.at).toLocaleString()]}):e("p",{class:"help",children:"No check result recorded."}),t.verification?e(j,{children:[t.verification.branch?e("p",{class:"help",children:["Checked branch ",e("code",{children:t.verification.branch})]}):null,t.verification.head?e("p",{class:"help",children:["Commit ",e("code",{children:t.verification.head.slice(0,12)})]}):null,e("ul",{children:t.verification.checks.map(s=>e("li",{children:[s.check.title??s.check.id,": ",s.diagnosis,s.check.required?" (required)":"",s.reason?` \xB7 ${s.reason}`:""]},s.check.id))}),t.verification.skipped.map(s=>e("p",{class:"help",children:["Skipped ",s.check.title??s.check.id,": ",s.reason]},s.check.id)),t.verification.risk?e("p",{children:["Change risk: ",t.verification.risk.level," \xB7 ",t.verification.risk.reasons.join("; ")||"No configured sensitive-path rule matched."]}):null,t.verification.requirements?.length?e("ul",{children:t.verification.requirements.map(s=>e("li",{children:[s.covered?"Covered":"Uncovered",": ",s.description,s.missing.length?` \xB7 missing ${s.missing.join(", ")}`:""]},s.id))}):null]}):null]})}async function em(t){let s=`/api/runs/${encodeURIComponent(t)}`;try{await U(s,{method:"DELETE"})}catch(n){if(!(n instanceof Ge)||n.status!==404)throw n;try{await U(s)}catch(a){if(a instanceof Ge&&a.status===404){go(t);return}throw a}throw new Error("This server hasn't loaded the delete update yet. Restart Code Flow, then refresh this page and try again.")}go(t)}function Mr({run:t,onClose:s}){return e(Wo,{runs:[t],onClose:s})}function Wo({runs:t,onClose:s,onDeleted:n}){let[a,r]=h(t),[o,i]=h(!1),[d,l]=h(""),m=we(!0,()=>{o||s()}),c=t.length===1;return e("dialog",{class:"picker small-dialog",ref:m,"aria-labelledby":"delete-run-title",children:e("div",{class:"picker-inner",children:[e("div",{class:"picker-head",children:e("h3",{id:"delete-run-title",children:c?"Delete this run?":`Delete ${a.length} ${a.length===1?"run":"runs"}?`})}),e("div",{class:"dialog-body",children:[c?e("p",{class:"delete-run-name",children:a[0]?.task.split(`
45
+ `)[0]}):e("ul",{class:"delete-run-list",children:a.map(u=>e("li",{children:u.task.split(`
46
+ `)[0]||"Untitled run"},u.id))}),e("p",{children:["This permanently deletes ",c?"the conversation and run history":"these conversations and their run history",". It cannot be undone."]}),e("p",{class:"help",children:["Git branches, worktrees and repository files are kept. Archive instead if you want to keep ",c?"the conversation":"the conversations","."]}),d?e("div",{class:"err",role:"alert",children:d}):null]}),e("div",{class:"picker-foot",children:[e("span",{class:"ps"}),e("button",{class:"btn",disabled:o,onClick:s,children:"Cancel"}),e("button",{class:"btn danger",disabled:o,onClick:async()=>{i(!0),l("");let u=[],p=[];for(let v of a)try{await em(v.id),n?.(v.id)}catch(g){u.push(v),p.push(`${c?"":`${v.task.split(`
47
+ `)[0]}: `}${g.message}`)}let f=a.length-u.length;if(f&&V(f===1?"Run deleted":`${f} runs deleted`),!u.length){s();return}r(u),l(p.join(`
48
+ `)),i(!1)},children:o?"Deleting\u2026":c?"Delete run":`Delete ${a.length} ${a.length===1?"run":"runs"}`})]})]})})}var Ra=["viewer","reviewer","contributor","maintainer"],Uc={viewer:"reads results",reviewer:"also comments and records reviews",contributor:"also owns team tasks and runs them on their own computer",maintainer:"also manages team membership and integration"},$a=t=>t.charAt(0).toUpperCase()+t.slice(1);function je(t,s){let n=t===void 0?-1:Ra.indexOf(t),a=Ra.indexOf(s);return n>=0&&a>=0&&n>=a}var Dt=ke(null),zo=ke(!1),Xt=ke(""),Jt=ke(null),Ia=ke(""),rs=ke(0),Kn=ke([]),os=ke(null),Gn=ke(!1),Nt=ke(0),hs=(t,s)=>U(t,{method:"PUT",body:JSON.stringify(s)}),Yn=(t,s)=>U(t,{method:"DELETE",...s===void 0?{}:{body:JSON.stringify(s)}}),tm=Ki();async function xt(){let t=tm();try{let s=await U("/api/team/board");return t()?(Dt.value=s,(s.tasks.length||s.projects.some(n=>n.repositories.length>0||n.members.some(a=>a.userId!=="owner")))&&($n.value=!0),Xt.value="",rs.value=s.inboxUnread,s):Dt.value}catch(s){return t()&&(Dt.value=null,os.value=null,rs.value=0,Xt.value=s.message),null}finally{t()&&(zo.value=!0)}}var Wc=t=>U(`/api/team/tasks/${J(t)}`);async function Xs(){try{Jt.value=await U("/api/team-link"),Jt.value.linked&&($n.value=!0),Ia.value=""}catch(t){Jt.value=null,Ia.value=t.message}return Jt.value}async function kn(){try{let t=await U("/api/team-link/attempts");Kn.value=Array.isArray(t)?t:t.attempts??[]}catch{Kn.value=[]}}async function Qn(){let t=await U("/api/team/inbox");return rs.value=t.unread,t}async function Vc(t){let s=await U("/api/team/inbox/read",{method:"POST",body:JSON.stringify(t==="all"?{all:!0}:{ids:t})});return rs.value=s.unread,s.unread}var Fc;function sm(){clearTimeout(Fc),Fc=setTimeout(()=>{Nt.value++},150)}function zc(t){t?.type!=="error"&&(typeof t?.unread=="number"&&t.unread>=0?rs.value=t.unread:t?.type==="hello"&&(Qn().catch(()=>{}),xt()),sm())}var Hc;function Jc(){Hc||(Xs(),U("/api/team-link/connections").then(t=>{t.connections.some(s=>s.linked)&&($n.value=!0)}).catch(()=>{}),Hc=Ds(gs?`team:${gs}`:"team",t=>zc(t)))}var nm=3e4;function Kc(t){let s,n,a=!1,r=()=>{if(a)return;let o=s=new EventSource(vs("/api/team/events"));o.onopen=()=>t?.("connected"),o.onerror=()=>{t?.("reconnecting"),o.readyState===EventSource.CLOSED&&!a&&(clearTimeout(n),n=setTimeout(r,nm))},o.onmessage=i=>{let d=null;try{d=JSON.parse(i.data)}catch{}zc(d&&typeof d=="object"?d:null)}};return r(),()=>{a=!0,clearTimeout(n),s?.close()}}function Lr(t){let s=t?.tailscaleUrl??t?.lanUrls?.[0];if(!(!t?.secure||typeof s!="string"))try{let n=new URL(s);return n.protocol==="https:"?n.origin:void 0}catch{return}}var Xn=["planned","working","blocked","review","done"],Zs={planned:"Planned",working:"Working",blocked:"Blocked",review:"In review",done:"Done"},Gc={planned:"planned",working:"running",blocked:"blocked",review:"review",done:"done"},Dr={claimed:"Starting",running:"Running",paused:"Paused",finished:"Finished",failed:"Failed",stopped:"Stopped at a limit",unknown:"Connection lost",superseded:"Superseded"},Yc={claimed:"running",running:"running",paused:"stopped",finished:"done",failed:"failed",stopped:"stopped",unknown:"failing",superseded:""},Qc={assigned:"Assigned to you",mention:"Mentioned you","review-requested":"Review requested","review-recorded":"Review recorded","handoff-offered":"Hand-over offered","handoff-accepted":"Hand-over accepted","handoff-declined":"Hand-over declined","handoff-cancelled":"Hand-over cancelled","instruction-proposed":"Instruction proposed",blocked:"Blocked","attempt-finished":"Attempt finished","attempt-failed":"Attempt failed",comment:"New comment"},am=9e4,Ut=(t,s)=>t?t.userId===s?`${t.displayName} (you)`:t.displayName:"Unassigned";function Aa(t){let s=t.trim().split(/\s+/).filter(Boolean);return(s.length>1?`${s[0][0]??""}${s[s.length-1][0]??""}`:(s[0]??"").slice(0,2)).toUpperCase()||"?"}var ut=t=>Wt(t),Nr=t=>new Date(t).toLocaleString(),en=t=>t.slice(0,10),Xc=(t,s)=>{for(let n of t?.projects??[]){let a=n.members.find(r=>r.userId===s);if(a)return a.displayName}return s};var rm=["claimed","running","unknown"],om=["claimed","running","paused","unknown"],im=["paused","stopped","unknown"],Vo=(t,s)=>{for(let n=t.length-1;n>=0;n--){let a=t[n];if(s.includes(a.state))return a}},Ea=t=>Vo(t.attempts,["claimed","running"])??Vo(t.attempts,rm),lm=t=>Ea(t)??Vo(t.attempts,om),Zc=t=>lm(t)??t.attempts[t.attempts.length-1],ed=(t,s)=>im.includes(t.state)&&s?.status!=="done",td=t=>{let s;for(let n of t.checkpoints)(!s||n.at>=s.at)&&(s=n);return s},Pa=(t,s=Date.now())=>(t.state==="claimed"||t.state==="running")&&s-t.lastHeartbeatAt<am,Or=(t,s=Date.now())=>t.state==="unknown"||(t.state==="claimed"||t.state==="running")&&!Pa(t,s),cm="Describe what blocks the task before marking it blocked";function _r(t,s,n,a=t.blocker){if(!je(n,"contributor"))return"A project contributor role is required to change the status";if(s==="blocked"&&!a?.trim())return cm;if(s!==t.status&&s==="done"){let r=Ea(t);if(r)return`Stop the attempt running on ${r.runnerName} before marking the task done`;if(t.handoff?.state==="offered")return"Accept, decline or cancel the offered hand-over before marking the task done"}}function Br(t,s,n){if(!je(s,"contributor"))return"A project contributor role is required to take a task";let a=Ea(t);if(a)return`Stop the attempt running on ${a.runnerName} before changing the owner`;if(!(je(s,"maintainer")||!t.owner||t.owner.userId===n))return"Only a project maintainer may reassign a task that already has an owner"}function sd(t,s){let n=new Set(s);for(let a=0;a<t.length;a++){let r=!1;for(let o of t)!n.has(o.id)&&o.dependsOn.some(i=>n.has(i))&&(n.add(o.id),r=!0);if(!r)break}return n}var dm=["title","body","paths","applicability"];function Zn(t){return structuredClone({title:t.title,body:t.body,paths:t.paths,applicability:t.applicability})}function Jo(t,s,n){let a=Zn(s),r=[];for(let o of dm){let i=JSON.stringify(t[o]),d=JSON.stringify(s[o]),l=JSON.stringify(n[o]);d===i?Object.assign(a,{[o]:structuredClone(n[o])}):l!==i&&l!==d&&r.push(o)}return{draft:a,conflicts:r}}function nd(t,s,n,a){let r=Jo(t,s,n);for(let o of r.conflicts){if(!a[o])throw new Error(`Choose which ${o} to keep before applying the merge`);a[o]==="latest"&&Object.assign(r.draft,{[o]:structuredClone(n[o])})}return r.draft}function ad({endpoint:t,repo:s,entries:n,refreshKey:a,onPublished:r}){let[o,i]=h(!1),[d,l]=h(null),[m,c]=h(!1),[u,p]=h(""),[f,v]=h(0),[g,w]=h(!1);_(()=>{if(!o)return;let y=!0,b=new AbortController;return c(!0),p(""),U(`${t}/analysis?repo=${encodeURIComponent(s)}`,{signal:b.signal}).then(T=>{y&&l(T)},T=>{y&&p(T.message)}).finally(()=>{y&&c(!1)}),()=>{y=!1,b.abort()}},[o,t,s,n,a,f]);let C=y=>n.find(b=>b.id===y)?.title??y,k=async()=>{if(!(!d?.onboarding.sourceRefs.length||g)){w(!0),p("");try{await q(`${t}/analysis/publish`,{repo:s,expectedSources:d.onboarding.sourceRefs}),V("Onboarding guidance saved with its source revisions."),await r(),v(y=>y+1)}catch(y){p(y.message)}finally{w(!1)}}};return e("details",{class:"at-section memory-analysis",onToggle:y=>i(y.currentTarget.open),children:[e("summary",{children:"Advanced memory tools"}),e("p",{class:"help",children:"Inspect sources, review applicability and repeated wording, and curate accepted guidance before publishing it."}),e("button",{class:"btn small",disabled:m,onClick:()=>v(y=>y+1),children:m?"Inspecting\u2026":"Refresh memory analysis"}),u?e("p",{class:"msg err",role:"alert",children:u}):null,d?e(j,{children:[e("p",{class:"help",children:[d.graph.nodes.filter(y=>y.available).length," entries inspected",d.git.head?` at ${d.git.head.slice(0,12)}`:" \xB7 Git evidence unavailable",d.git.branch?` \xB7 ${d.git.branch}`:"",".",d.truncated?" Analysis reached a limit; omitted entries or comparisons need separate review.":""]}),e("details",{children:[e("summary",{children:"Source and derived-entry graph"}),e(um,{graph:d.graph})]}),e("details",{children:[e("summary",{children:["Freshness and applicability \xB7 ",d.stale.length," to review"]}),d.stale.length?e("ul",{children:d.stale.map(y=>e("li",{children:[e(ea,{id:y.id,children:C(y.id)})," \xB7 revision ",y.revision,e("ul",{children:y.reasons.map((b,T)=>e("li",{children:b.detail},T))})]},y.id))}):e("p",{class:"help",children:"No issues found by these bounded checks. This is not a semantic correctness assessment."})]}),e("details",{children:[e("summary",{children:["Repeated wording \xB7 ",d.duplicates.length," pairs"]}),e("p",{class:"help",children:"Lexical overlap is a review hint. Supported semantic claims are inspected separately below. Compare applicability before combining entries."}),d.duplicates.length?e("ul",{children:d.duplicates.map(y=>e("li",{children:[e(ea,{id:y.a.id,children:C(y.a.id)})," and ",e(ea,{id:y.b.id,children:C(y.b.id)})," \xB7 ",y.kind==="exact"?"Same text, ignoring whitespace":`${Math.round(y.similarity*100)}% lexical overlap`]},`${y.a.id}:${y.b.id}`))}):e("p",{class:"help",children:"No repeated wording found within the comparison limit."})]}),e("details",{children:[e("summary",{children:["Semantic claim review \xB7 ",d.claims.findings.filter(y=>y.kind==="contradiction").length," conflicts \xB7 ",d.claims.findings.filter(y=>y.kind==="equivalent").length," equivalent pairs"]}),e("p",{class:"help",children:d.claims.method}),e("p",{class:"help",children:[d.claims.claims.length," claims from ",d.claims.inspectedEntries," entries; ",d.claims.unsupported," unsupported lines or facts. ",d.claims.truncated?"A claim/comparison limit was reached.":""," Source paths and branch applicability must overlap before a pair is suggested."]}),d.claims.findings.length?e("ul",{children:d.claims.findings.map((y,b)=>e("li",{children:[e("strong",{children:[y.kind==="contradiction"?"Potential contradiction":"Equivalent supported claim",": ",y.predicate," \xB7 ",y.subject]}),e("p",{children:[e(ea,{id:y.a.id,children:C(y.a.id)})," revision ",y.a.revision," and ",e(ea,{id:y.b.id,children:C(y.b.id)})," revision ",y.b.revision]}),e("p",{class:"help",children:y.explanation}),e("details",{children:[e("summary",{children:"Compare claim evidence"}),e("p",{children:["Left \xB7 ",y.left.evidence.method," \xB7 characters ",y.left.evidence.start,"\u2013",y.left.evidence.end]}),e("pre",{children:y.left.evidence.text}),e("pre",{children:JSON.stringify(y.left.value)}),e("p",{children:["Right \xB7 ",y.right.evidence.method," \xB7 characters ",y.right.evidence.start,"\u2013",y.right.evidence.end]}),e("pre",{children:y.right.evidence.text}),e("pre",{children:JSON.stringify(y.right.value)})]})]},`${y.a.id}:${y.b.id}:${b}`))}):e("p",{class:"help",children:"No supported claim pairs found. This does not show that arbitrary prose is consistent."}),e("details",{children:[e("summary",{children:"Write explicit semantic facts"}),e("p",{class:"help",children:"Edit a knowledge entry to include this fenced block. Subjects and predicates identify one fact; booleans express policy, strings express exact settings, and numbers/ranges use count, time or byte units. Keep conditions in the entry's path and branch applicability. Only reviewed project guidance should be accepted."}),e("pre",{children:'```codeflow-claims\n[\n {"subject":"guest requests","predicate":"allow","value":false},\n {"subject":"cache ttl","predicate":"setting","min":5,"max":10,"unit":"minutes"}\n]\n```'}),e("p",{class:"help",children:"The local grammar also recognizes simple standalone instructions such as \u201CNever permit guest requests\u201D and \u201CSet cache TTL to 300 seconds\u201D. Conditional, compound and unsupported sentences require explicit facts; no model or external service is used."})]})]}),e("details",{children:[e("summary",{children:"Curated project onboarding"}),e("p",{class:"help",children:"Only accepted guidance written by you with trusted user origins is included. Entries needing review, imported material, private material and earlier onboarding summaries are excluded."}),d.onboarding.body?e(j,{children:[e(Oe,{text:d.onboarding.body}),e("p",{class:"help",children:["Sources: ",d.onboarding.sourceRefs.map(y=>`${C(y.id)} (revision ${y.revision})`).join(", "),". ",d.onboarding.omitted," entries omitted."]}),e("button",{class:"btn small primary",disabled:g||m,onClick:k,children:g?"Saving\u2026":"Save onboarding as project knowledge"}),e("p",{class:"help",children:"Saving is your explicit publication of the reviewed summary. Source revisions are rechecked before it is saved."})]}):e("p",{class:"help",children:"No eligible guidance to publish. Add or review user-authored repository guidance first."}),d.onboarding.reasons.length?e("details",{children:[e("summary",{children:"Why entries were omitted"}),e("ul",{children:d.onboarding.reasons.map(y=>e("li",{children:[C(y.id),": ",y.reason]},y.id))})]}):null]}),d.notes.map((y,b)=>e("p",{class:"help",children:y},b))]}):m?e("p",{class:"help",role:"status",children:"Inspecting project knowledge\u2026"}):null]})}function um({graph:t}){let s=`memory-provenance-${pa().replace(/:/g,"")}`,[n,a]=h(""),r=t.nodes.slice(0,60),o=new Set(r.map(f=>f.key)),i=t.edges.filter(f=>o.has(f.from)&&o.has(f.to)),d=new Map(r.map(f=>[f.key,0]));for(let f=0;f<6;f++)for(let v of i)d.set(v.to,Math.min(5,Math.max(d.get(v.to)??0,(d.get(v.from)??0)+1)));let l=new Map,m=new Map(r.map(f=>{let v=d.get(f.key),g=l.get(v)??0;return l.set(v,g+1),[f.key,{x:12+v*220,y:12+g*65}]})),c=Math.max(220,...[...m.values()].map(f=>f.x+205)),u=Math.max(75,...[...m.values()].map(f=>f.y+60)),p=t.nodes.find(f=>f.key===n);return e(j,{children:[e("p",{class:"help",children:["Arrows go from a source revision to a derived entry. Older or deleted revisions are shown as references without restored text.",r.length<t.nodes.length?` Showing ${r.length} of ${t.nodes.length} nodes.`:""]}),r.length?e("div",{class:"memory-graph",tabIndex:0,children:e("svg",{width:c,height:u,role:"group","aria-label":"Memory provenance graph",children:[e("defs",{children:e("marker",{id:s,markerWidth:"8",markerHeight:"8",refX:"7",refY:"4",orient:"auto",children:e("path",{d:"M0,0 L8,4 L0,8"})})}),i.map(f=>{let v=m.get(f.from),g=m.get(f.to);return e("path",{class:"mem-edge",d:`M${v.x+190},${v.y+24} C${v.x+215},${v.y+24} ${g.x-25},${g.y+24} ${g.x},${g.y+24}`,"marker-end":`url(#${s})`},`${f.from}:${f.to}`)}),r.map(f=>{let v=m.get(f.key),g=f.title??f.id;return e("g",{class:`mem-node${f.available?"":" ref"}${n===f.key?" on":""}`,transform:`translate(${v.x},${v.y})`,role:"button",tabIndex:0,"aria-label":`${g}, revision ${f.revision}${f.available?"":", reference only"}`,onClick:()=>a(f.key),onKeyDown:w=>{(w.key==="Enter"||w.key===" ")&&(w.preventDefault(),a(f.key))},children:[e("title",{children:[g," \xB7 revision ",f.revision]}),e("rect",{width:"190",height:"48",rx:"8"}),e("text",{x:"10",y:"20",class:"mem-title",children:g.length>25?g.slice(0,24)+"\u2026":g}),e("text",{x:"10",y:"37",children:["Revision ",f.revision,f.available?` \xB7 ${f.status}`:" \xB7 reference only"]})]},f.key)})]})}):e("p",{class:"help",children:"No entries to draw yet."}),p?e("p",{class:"help",role:"status",children:[p.title??p.id," \xB7 revision ",p.revision,". ",t.edges.filter(f=>f.to===p.key).length," source references; ",t.edges.filter(f=>f.from===p.key).length," derived references.",p.available?"":" The text of this revision is unavailable and has not been recovered."]}):null,e("details",{children:[e("summary",{children:"Read source references as a list"}),e("ul",{children:t.edges.slice(0,200).map(f=>e("li",{children:[e("code",{children:f.from})," \u2192 ",e("code",{children:f.to})]},`${f.from}:${f.to}`))}),t.edges.length>200?e("p",{class:"help",children:["Showing the first 200 of ",t.edges.length," references."]}):null]})]})}function rd({endpoint:t,repo:s,entryId:n,onReady:a}){let[r,o]=h(null),[i,d]=h(""),[l,m]=h(!1);return _(()=>{let c=!0;return U(`${t}/analysis?repo=${encodeURIComponent(s)}`).then(u=>{if(c){let p=u.deletionImpact.find(f=>f.id===n);o(p??null),p||d("This entry is not included in the bounded preview."),m(u.truncated)}},u=>{c&&d(u.message)}).finally(()=>{c&&a()}),()=>{c=!1}},[t,s,n]),e("div",{class:"help",role:"group","aria-label":"Memory deletion impact",children:r?e(j,{children:[e("p",{children:[r.direct.length," directly derived entries; ",r.transitive.length," downstream entries retain their text and provenance."]}),e("p",{children:r.retained}),r.transitive.length?e("details",{children:[e("summary",{children:"Entries to review separately"}),e("ul",{children:r.transitive.map(c=>e("li",{children:[e(ea,{id:c.id,children:c.id})," \xB7 revision ",c.revision]},c.id))})]}):null,l?e("p",{children:"The analysis reached a limit; additional derived entries may exist."}):null]}):i?e("p",{children:["Impact preview unavailable: ",i,". Derived text and separate transcript history are retained."]}):e("p",{role:"status",children:"Loading deletion impact\u2026"})})}function ea({id:t,children:s}){return e("button",{type:"button",class:"mem-link",onClick:()=>{let n=document.getElementById(`memory-${t}`);n?.scrollIntoView({behavior:"smooth",block:"center"}),n?.focus({preventScroll:!0})},children:s})}var od={applies_to:"applies to",learned_from:"learned from",derived_from:"written with",verified_at:"verified at"};function id({endpoint:t,repo:s,entries:n}){let[a,r]=h(!1),[o,i]=h(null),[d,l]=h(""),[m,c]=h("");_(()=>{if(!a)return;let f=!0;return i(null),l(""),U(`${t}/graph?repo=${encodeURIComponent(s)}`).then(v=>{f&&i(v)},v=>{f&&l(v.message)}),()=>{f=!1}},[a,t,s,n]);let u=new Map(o?.entities.map(f=>[f.id,f])),p=o?.relationships.filter(f=>`${u.get(f.from)?.label} ${u.get(f.to)?.label} ${od[f.relation]}`.toLowerCase().includes(m.toLowerCase()))??[];return e("details",{class:"knowledge-graph",onToggle:f=>r(f.currentTarget.open),children:[e("summary",{children:"Knowledge graph"}),e("p",{class:"help",children:"Connections recorded in memory paths and evidence. \u201CWritten with\u201D records context, not proof that one claim follows from another. Proposal connections remain unapproved."}),e("label",{children:["Find connections",e("input",{class:"field","aria-label":"Find knowledge connections",value:m,onInput:f=>c(f.currentTarget.value),placeholder:"Memory, file, run or commit"})]}),d?e("p",{class:"msg err",role:"alert",children:d}):o?e(j,{children:[o.truncated?e("p",{class:"help",children:"Showing the first 1,000 connections. The graph is larger than this view."}):null,p.length?e("div",{class:"knowledge-connections",tabIndex:0,role:"region","aria-label":"Knowledge connections",children:e("table",{children:[e("thead",{children:e("tr",{children:[e("th",{children:"Memory"}),e("th",{children:"Relationship"}),e("th",{children:"Connected item"}),e("th",{children:"Evidence"})]})}),e("tbody",{children:p.map(f=>{let v=u.get(f.from),g=u.get(f.to),w=n.find(C=>C.id===f.evidence.id);return e("tr",{children:[e("td",{children:e("a",{href:`#memory-${v.key}`,onClick:C=>{C.preventDefault(),document.getElementById(`memory-${v.key}`)?.focus()},children:v.label})}),e("td",{children:od[f.relation]}),e("td",{children:[g.kind,": ",g.kind==="run"?e("a",{href:`#/run/${encodeURIComponent(g.key)}`,children:g.label}):g.label]}),e("td",{children:["Revision ",f.evidence.revision," \xB7 ",w?.status==="accepted"?"Accepted":"Proposal",f.targetRevision?` \xB7 source revision ${f.targetRevision}`:""]})]},`${f.from}:${f.to}:${f.relation}`)})})]})}):e("p",{class:"help",children:"No matching connections."})]}):e("p",{role:"status",children:"Loading connections\u2026"})]})}function ld({projectId:t,repo:s,refreshKey:n=""}){let[a,r]=h(!1),[o,i]=h(null),[d,l]=h(""),[m,c]=h(!1),[u,p]=h(!1),f=`/api/projects/${encodeURIComponent(t)}/memory`,v=async()=>{c(!0),l("");try{i(await U(`${f}?repo=${encodeURIComponent(s)}`))}catch(C){l(C.message)}finally{c(!1)}};_(()=>{if(!a)return;let C=!0;return c(!0),l(""),U(`${f}?repo=${encodeURIComponent(s)}`).then(k=>{C&&i(k)},k=>{C&&l(k.message)}).finally(()=>{C&&c(!1)}),()=>{C=!1}},[a,t,s,n]);let g=(o??[]).filter(C=>C.status!=="deleted"),w=g.filter(C=>C.status==="proposed").length;return e("details",{class:"project-memory",onToggle:C=>r(C.currentTarget.open),children:[e("summary",{children:["Project memory",o?` \xB7 ${g.length} entries${w?` \xB7 ${w} to review`:""}`:""]}),e("p",{class:"help",children:"Accepted knowledge can be used in future runs in this repository. Proposals need review before they become project guidance."}),e("p",{class:"help",children:"Deleting erases this entry's text and removes it from future retrieval. Entries written with it in context retain their own text and the source reference; review and delete those separately. Source run transcripts remain under normal run retention."}),e("div",{class:"at-row",children:[e("button",{class:"btn small",disabled:m,onClick:v,children:m?"Loading\u2026":"Refresh"}),e("button",{class:"btn small",onClick:()=>p(!u),children:u?"Cancel new entry":"Add project knowledge"})]}),d?e("p",{class:"msg err",role:"alert",children:d}):null,u?e(cd,{endpoint:f,repo:s,onSaved:async()=>{p(!1),await v()},onCancel:()=>p(!1)}):null,o&&!g.length?e("p",{class:"help",children:"No project knowledge saved for this repository yet."}):null,o?e(ad,{endpoint:f,repo:s,entries:o,refreshKey:n,onPublished:v}):null,o?e(id,{endpoint:f,repo:s,entries:o}):null,e("div",{class:"memory-list",children:g.map(C=>e(pm,{entry:C,endpoint:f,onChanged:v},C.id))})]})}function pm({entry:t,endpoint:s,onChanged:n}){let[a,r]=h(!1),[o,i]=h(!1),[d,l]=h(""),[m,c]=h(!1),[u,p]=h(!1),f=async g=>{i(!0),l("");try{await q(`${s}/commands`,{op:g,id:t.id,expectedRevision:t.revision}),await n(),g==="delete"&&V("Memory removed. Entries written with it in context keep their text and its provenance; run transcripts are retained.",5e3)}catch(w){l(w.message)}finally{i(!1)}},v=t.origins.some(g=>g.lockedDown||g.trust!=="trusted");return e("article",{class:"memory-card",id:`memory-${t.id}`,tabIndex:-1,children:[e("div",{class:"at-row",children:[e("b",{children:t.title}),e("span",{class:`badge ${t.status==="accepted"?"ok":"warn"}`,children:t.status==="accepted"?"Accepted":"Proposal"})]}),e("div",{class:"help",children:["Revision ",t.revision," \xB7 ",t.applicability.kind==="branch"?`Branch ${t.applicability.branch}${t.applicability.commit?` at ${t.applicability.commit.slice(0,12)}`:""}`:"This repository",t.acceptedBy?` \xB7 accepted by ${t.acceptedBy==="user"?"you":t.acceptedBy}`:""]}),a?e(cd,{entry:t,endpoint:s,repo:t.repo,onSaved:async()=>{r(!1),await n()},onCancel:()=>r(!1)}):e(Oe,{text:t.body}),t.paths.length?e("p",{class:"help",children:["Applies to: ",t.paths.join(", ")]}):null,t.tags.length?e("p",{class:"help",children:["Tags: ",t.tags.join(", ")]}):null,e("details",{children:[e("summary",{children:"Origin and evidence"}),v?e("p",{class:"at-notice",children:"Includes material from an untrusted or unknown source. Review the content before accepting it as future guidance."}):null,e("ul",{children:t.origins.map((g,w)=>e("li",{children:[g.kind==="user"?"User-authored":g.kind==="run"?"From a run":"Imported"," \xB7 ",g.trust,g.lockedDown?" \xB7 locked down":"",g.private?" \xB7 private origin":"",g.runId?e(j,{children:[" \xB7 ",e("a",{href:`#/run/${encodeURIComponent(g.runId)}`,children:"View source run"})]}):null,g.memberId?` \xB7 ${g.memberId}`:""]},w))}),t.sourceRefs.length?e("p",{class:"help",children:["Sources: ",t.sourceRefs.join(", ")]}):null,t.derivedFrom.length?e("p",{class:"help",children:["Derived from: ",t.derivedFrom.map(g=>`${g.id} (revision ${g.revision})`).join(", ")]}):null,t.verification?e("p",{class:"help",children:[t.verification.passed?"Verification passed":"Verification incomplete"," at ",e("code",{children:t.verification.commit.slice(0,12)}),t.verification.merged?" \xB7 merged":" \xB7 branch evidence",". ",t.verification.evidenceRefs.join(", ")]}):null]}),t.status==="accepted"?e(Ko,{projectId:t.projectId,endpoint:s,id:t.id,revision:t.revision,onChanged:n}):null,t.feedback?.filter(g=>g.revision===t.revision).length?e("p",{class:"help",children:["Feedback on this revision: ",t.feedback.filter(g=>g.revision===t.revision).map(g=>g.rating).join(", "),". Stale or incorrect guidance is excluded until edited."]}):null,e("div",{class:"memory-actions",children:[t.status==="proposed"?e("button",{class:"btn small primary",disabled:o||a,onClick:()=>f("approve"),children:o?"Saving\u2026":"Accept for future runs"}):null,a?null:e("button",{class:"btn small",disabled:o,onClick:()=>r(!0),children:"Edit"}),m?e("div",{class:"memory-confirm",role:"group","aria-label":"Confirm deletion",children:[e("span",{class:"help",children:"Delete this knowledge? Its text is erased; entries written with it in context keep theirs."}),e(rd,{endpoint:s,repo:t.repo,entryId:t.id,onReady:()=>p(!0)}),e("button",{class:"btn small danger",disabled:o||!u,onClick:()=>{c(!1),f("delete")},children:"Delete"}),e("button",{class:"btn small",disabled:o,onClick:()=>c(!1),children:"Keep"})]}):e("button",{class:"btn small danger",disabled:o||a,onClick:()=>{p(!1),c(!0)},children:"Delete\u2026"})]}),d?e("p",{class:"msg err",role:"alert",children:[d," Refresh to see the latest revision."]}):null]})}function Ko({projectId:t,endpoint:s,id:n,revision:a,runId:r,onChanged:o}){let[i,d]=h("useful"),[l,m]=h(""),[c,u]=h(!1),[p,f]=h(""),[v,g]=h(""),w=async()=>{u(!0),g(""),f("");try{await q(`${s??`/api/projects/${encodeURIComponent(t)}/memory`}/commands`,{op:"feedback",id:n,expectedRevision:a,runId:r,rating:i,note:l.trim()||void 0}),f("Feedback saved for this revision."),await o?.()}catch(C){g(C.message)}finally{u(!1)}};return e("details",{class:"memory-feedback",children:[e("summary",{children:"Rate this knowledge"}),e("label",{children:["Usefulness",e("select",{class:"field","aria-label":`Memory usefulness ${n}`,value:i,onChange:C=>d(C.currentTarget.value),children:[e("option",{value:"useful",children:"Useful"}),e("option",{value:"irrelevant",children:"Not relevant"}),e("option",{value:"stale",children:"Out of date"}),e("option",{value:"incorrect",children:"Incorrect"})]})]}),e("label",{children:["Reason (optional)",e("textarea",{class:"field","aria-label":`Memory feedback ${n}`,rows:2,maxLength:1e3,value:l,onInput:C=>m(C.currentTarget.value)})]}),e("button",{class:"btn small",disabled:c,onClick:w,children:c?"Saving\u2026":"Save memory feedback"}),p?e("p",{class:"help",role:"status",children:p}):null,v?e("p",{class:"msg err",role:"alert",children:v}):null]})}function cd({entry:t,endpoint:s,repo:n,onSaved:a,onCancel:r}){let[o,i]=h(t?.title??""),[d,l]=h(t?.body??""),[m,c]=h(t?.paths.join(`
49
+ `)??""),[u,p]=h(t?.applicability.kind??"repository"),[f,v]=h(t?.applicability.kind==="branch"?t.applicability.branch:""),[g,w]=h(t?.applicability.kind==="branch"?t.applicability.commit??"":""),[C,k]=h(t),[y,b]=h(t?.revision),[T,$]=h(!1),[x,E]=h(null),[A,P]=h({}),[D,S]=h(!1),[R,M]=h(""),O={title:o,body:d,paths:m.split(`
50
+ `).map(L=>L.trim()).filter(Boolean),applicability:u==="repository"?{kind:"repository"}:{kind:"branch",branch:f.trim(),...g.trim()?{commit:g.trim()}:{}}},B=C&&x?.latest?Jo(Zn(C),O,Zn(x.latest)):null,ee={title:"title",body:"knowledge",paths:"relevant paths",applicability:"where this applies"},se=async()=>{let L=await U(`${s}?repo=${encodeURIComponent(n)}`);E({latest:L.find(Y=>Y.id===t?.id)??null}),P({})},te=()=>{if(!C||!x?.latest)return;let L=nd(Zn(C),O,Zn(x.latest),A);i(L.title),l(L.body),c(L.paths.join(`
51
+ `)),p(L.applicability.kind),v(L.applicability.kind==="branch"?L.applicability.branch:""),w(L.applicability.kind==="branch"?L.applicability.commit??"":""),k(x.latest),b(x.latest.revision),E(null),M(""),V("Changes merged into your draft. Review it, then save.")},G=async()=>{if(!(!o.trim()||!d.trim()||u==="branch"&&!f.trim()||D||x)){S(!0),M("");try{await q(`${s}/commands`,{op:t&&!T?"update":"create",id:T?void 0:t?.id,expectedRevision:y,repo:n,...O}),await a()}catch(L){if(M(L.message),t&&!T&&L instanceof Ge&&(L.status===409||L.status===404))try{await se()}catch(Y){M(`${L.message}. Couldn't load the latest revision: ${Y.message}`)}}finally{S(!1)}}};return e("form",{class:"memory-editor",onSubmit:L=>{L.preventDefault(),G()},children:[e("label",{children:["Title",e("input",{class:"field","aria-label":"Memory title",maxLength:200,value:o,onInput:L=>i(L.currentTarget.value)})]}),e("label",{children:["Knowledge",e("textarea",{class:"field","aria-label":"Memory knowledge",rows:4,maxLength:16e3,value:d,onInput:L=>l(L.currentTarget.value)})]}),e("label",{children:["Relevant paths, one per line",e("textarea",{class:"field","aria-label":"Memory paths",rows:2,placeholder:"Leave empty for the whole repository",value:m,onInput:L=>c(L.currentTarget.value)})]}),e("label",{children:["Where this applies",e("select",{class:"field","aria-label":"Where memory applies",value:u,onChange:L=>p(L.currentTarget.value),children:[e("option",{value:"repository",children:"Use across this repository"}),e("option",{value:"branch",children:"Only a specific branch"})]})]}),u==="branch"?e(j,{children:[e("label",{children:["Branch",e("input",{class:"field","aria-label":"Memory branch",value:f,onInput:L=>v(L.currentTarget.value)})]}),e("label",{children:["Commit, if required",e("input",{class:"field","aria-label":"Memory commit",value:g,onInput:L=>w(L.currentTarget.value),placeholder:"Optional commit that must be present"})]})]}):e("p",{class:"help",children:"Saving makes this guidance eligible for future runs on any branch in this repository."}),x?e("section",{class:"at-notice","aria-label":"Resolve memory revision conflict",children:[e("b",{children:x.latest?`This entry is now at revision ${x.latest.revision}. Your draft is preserved.`:"This entry was removed in another session. Your draft is preserved."}),x.latest?e(j,{children:[e("details",{children:[e("summary",{children:"Latest saved knowledge"}),e("b",{children:x.latest.title}),e(Oe,{text:x.latest.body}),e("p",{class:"help",children:["Paths: ",x.latest.paths.join(", ")||"whole repository"," \xB7 ",x.latest.applicability.kind==="repository"?"This repository":`Branch ${x.latest.applicability.branch}${x.latest.applicability.commit?` at ${x.latest.applicability.commit}`:""}`]})]}),B?.conflicts.length?e(j,{children:[e("p",{class:"help",children:"Both versions changed these fields. Choose each one to keep. Independent edits will be combined."}),B.conflicts.map(L=>e("label",{children:["Conflict: ",ee[L],e("select",{class:"field","aria-label":`Resolve memory ${ee[L]}`,value:A[L]??"",onChange:Y=>{let X=Y.currentTarget.value;P(N=>({...N,[L]:X}))},children:[e("option",{value:"",children:"Choose a version\u2026"}),e("option",{value:"draft",children:"Keep my draft"}),e("option",{value:"latest",children:"Use latest saved version"})]})]},L))]}):e("p",{class:"help",children:"Your edits and the latest edits affect different fields and can be combined."}),e("button",{type:"button",class:"btn small primary",disabled:D||!!B?.conflicts.some(L=>!A[L]),onClick:te,children:"Apply reviewed merge"})]}):e(j,{children:[e("p",{class:"help",children:"You can keep editing this draft and save it as a separate entry."}),e("button",{type:"button",class:"btn small",onClick:()=>{$(!0),b(void 0),k(void 0),E(null),M("")},children:"Keep draft as new knowledge"})]}),e("button",{type:"button",class:"btn small",disabled:D,onClick:async()=>{S(!0);try{await se()}catch(L){M(L.message)}finally{S(!1)}},children:"Refresh latest revision"})]}):null,T?e("p",{class:"help",children:"This draft will be saved as a new entry."}):null,e("div",{class:"memory-actions",children:[e("button",{type:"submit",class:"btn small primary",disabled:D||!!x||!o.trim()||!d.trim()||u==="branch"&&!f.trim(),children:D?"Saving\u2026":"Save knowledge"}),e("button",{type:"button",class:"btn small",disabled:D,onClick:r,children:"Cancel"})]}),R?e("p",{class:"msg err",role:"alert",children:[R," Your draft is still here."]}):null]})}var ct=t=>({type:"object",properties:t,required:Object.keys(t),additionalProperties:!1}),Me={type:"string"},ta={type:"string",pattern:"^[a-z][a-z0-9-]{0,39}$",description:"Stable lowercase identifier, e.g. api, add-validation, goal; never T1 or R1"},rt={type:"array",items:Me},kt=t=>({type:"array",items:t}),ud=ct({id:ta,name:Me,role:{type:"string",enum:["coordinator","worker","reviewer"]},provider:{type:"string",description:"Exact provider ID from the supplied eligible inventory and selected pool"},model:Me,effort:Me,reason:Me}),Go=ct({id:ta,title:Me,instructions:Me,owner:{type:"string",description:"An active worker member ID (or coordinator for investigation). Never the reviewer: code-flow schedules independent review automatically."},kind:{type:"string",enum:["implementation","investigation"]},dependsOn:rt,requirements:rt,acceptance:rt,paths:rt}),pd=ct({...Go.properties,dependencyTypes:kt(ct({taskId:ta,kind:{type:"string",enum:["completion","artifact","knowledge"]}}))}),mm=kt(ct({id:{type:"string",pattern:"^[a-z][a-z0-9-]{0,27}$"},strategy:{type:"string",enum:["investigate-implement","implement-verify","bounded-repair"]},owner:Me,requirements:rt,acceptance:rt,paths:rt,dependsOn:rt,instructions:Me})),hm=ct({requirements:kt(ct({id:ta,description:Me})),members:kt(ud),tasks:kt(Go),contracts:rt,rationale:Me}),fm=ct({...hm.properties,tasks:kt(pd),subplans:mm}),lk=ct({...fm.properties,templateUses:kt(ct({id:{type:"string",pattern:"^[a-z][a-z0-9-]{0,11}$"},templateId:ta,version:{type:"integer",minimum:1},inputs:kt(ct({name:Me,value:Me})),assignments:kt(ct({role:Me,memberId:ta})),dependsOn:rt,requirements:rt,instructions:Me}))}),Yo=ct({requestId:Me,body:Me,evidence:rt}),ck=ct({taskId:Me,memberId:Me,status:{type:"string",enum:["submitted","needs_info","failed"]},checkpoint:Me,handover:Me,artifacts:rt,unresolvedRequirements:rt,questions:kt(ct({id:Me,recipient:Me,body:Me,blocking:{type:"boolean"}})),replies:kt(Yo),findings:kt(ct({title:Me,body:Me,evidence:rt,paths:rt}))}),dk=ct({replies:kt(Yo),unresolved:rt}),gm=ct({reason:Me,addTasks:kt(Go),reassignments:kt(ct({taskId:Me,memberId:Me})),retryTasks:rt,contracts:rt,answers:kt(Yo),addMembers:kt(ud),retireMembers:rt}),uk=ct({...gm.properties,addTasks:kt(pd),contractRequirements:rt}),vm=/^[a-z][a-z0-9-]{0,39}$/,dd=t=>new Set(t).size===t.length,wn=t=>!!t.trim();function bm(t){return t==="*"||!!t&&t.length<=500&&!/[\u0000-\u001f\u007f]/.test(t)&&!t.startsWith("/")&&!t.startsWith("-")&&!t.includes("\\")&&!t.split("/").some(s=>s==="."||s===".."||s===".git"||s==="")&&!t.includes("*")&&!/^[A-Za-z]:/.test(t)}function md(t,s,n=new Set){if(!t.requirements.length||!t.tasks.length)return"include requirements and at least one task";if(t.requirements.length>48||t.contracts.length>24||t.rationale.length>4e3)return"requirements, contracts, and rationale must fit the bounded plan";let a=t.members.filter(u=>u.status!=="retired");if(a.length>s.maxMembers||a.length<2)return`team size must be between 2 and ${s.maxMembers}`;if(t.tasks.length>s.maxTasks)return`the plan exceeds ${s.maxTasks} tasks`;for(let[u,p]of[["member",t.members],["task",t.tasks],["requirement",t.requirements]])if(!dd(p.map(f=>f.id))||p.some(f=>!vm.test(f.id)))return`${u} IDs must be unique short lowercase identifiers`;if(t.requirements.some(u=>!wn(u.description)||u.description.length>4e3))return"requirements need bounded descriptions";if(t.contracts.some(u=>!wn(u)||u.length>8e3))return"contracts cannot be empty or exceed 8000 characters";let r=a.filter(u=>u.role==="coordinator"),o=a.filter(u=>u.role==="reviewer");if(r.length!==1||o.length!==1)return"include exactly one coordinator and one independent reviewer";if(r[0].id!=="coordinator")return"the coordinator member ID must be coordinator (preserving its planning session identity)";if(r[0].provider!==s.coordinator)return"the coordinator must preserve the user's selected provider";let i=s.inventory.providers.filter(u=>u.available&&!u.blockedReason&&(s.pool.includes(u.id)||u.id===s.coordinator));for(let u of a){if(u.id==="user")return"user is reserved for authenticated user replies";if(u.role!=="coordinator"&&!s.pool.includes(u.provider))return`${u.id} chose a provider outside the user's worker/reviewer pool`;let p=i.find(y=>y.id===u.provider)??(n.has(u.id)?s.inventory.providers.find(y=>y.id===u.provider):void 0);if(!p)return`${u.id} chose unavailable, exhausted, or unauthorized provider ${u.provider}`;if(!wn(u.name)||u.name.length>120||!wn(u.reason)||u.reason.length>2e3)return"every member needs a bounded name and composition reason";let f=p.settingsByRole?.[u.role]??p,v=p.models?.find(y=>y.id===(u.model||p.catalog?.defaultModel)||y.aliases?.includes(u.model));if(p.catalog&&!v)return`${u.id} chose a model whose availability in this environment is unknown`;if(p.catalog&&u.effort&&!v?.efforts?.includes(u.effort))return`${u.id} chose an unsupported effort for this exact model`;if(u.role==="coordinator"&&(u.model!==(f.model??"")||u.effort!==(f.effort??"")))return"The coordinator model settings and effort must remain unchanged";let g=u.role!=="coordinator"&&"variants"in f?f.variants:void 0,C=(g?.length?[f,...g]:[f]).filter(y=>g?.length?u.model===(y.model??""):y.model?u.model===y.model:!u.model||!!v);if(!C.length)return`${u.id} must preserve supplied model settings or choose a supplied supported model (empty means default)`;let k=v?.efforts??p.efforts??[];if(!C.some(y=>y.effort?u.effort===y.effort:!u.effort||k.includes(u.effort)))return`${u.id} must preserve supplied effort settings or choose a supplied supported effort (empty means default)`}for(let u of t.tasks){let p=t.members.find(f=>f.id===u.owner);if(!p||p.role==="reviewer"||p.status==="retired"&&!["submitted","completed"].includes(u.status??""))return`${u.id} must be assigned to an active non-reviewer member. The runtime supplies final independent review and checks; remove redundant final-review tasks instead of reassigning them.`;if(u.kind==="implementation"&&p.role!=="worker")return`${u.id}: implementation belongs to a worker, keeping coordinator and reviewer read-only`;if(!wn(u.title)||u.title.length>180||!wn(u.instructions)||u.instructions.length>16e3||!u.acceptance.length||u.acceptance.length>16||u.acceptance.some(f=>!wn(f)||f.length>2e3))return`${u.id} needs bounded instructions and acceptance criteria`;if(!u.requirements.length||u.requirements.some(f=>!t.requirements.some(v=>v.id===f)))return`${u.id} must cover existing requirements`;if(u.dependencyTypes&&(Object.keys(u.dependencyTypes).some(f=>!u.dependsOn.includes(f))||Object.values(u.dependencyTypes).some(f=>!["completion","artifact","knowledge"].includes(f))))return`${u.id} has invalid typed dependencies`;if(!dd(u.dependsOn)||u.dependsOn.some(f=>f===u.id||!t.tasks.some(v=>v.id===f)))return`${u.id} has an invalid dependency`;if(u.paths.some(f=>!bm(f))||u.kind==="implementation"&&!u.paths.length)return`${u.id} needs safe owned repository paths (directories, files, or *)`}if(t.requirements.some(u=>!t.tasks.some(p=>p.requirements.includes(u.id))))return"every requirement must have a task; requirements cannot silently disappear";let d=new Set,l=new Set,m=u=>l.has(u)?!0:d.has(u)?!1:(l.add(u),t.tasks.find(p=>p.id===u).dependsOn.some(m)?!0:(l.delete(u),d.add(u),!1));if(t.tasks.some(u=>m(u.id)))return"task dependencies must be acyclic";let c=t.members.find(u=>u.id===t.tasks.find(p=>p.kind==="implementation")?.owner)??r[0];if(o[0].provider===c.provider&&(s.differentProviderReview||i.some(u=>s.pool.includes(u.id)&&u.id!==c.provider)))return"use a reviewer from another eligible provider (or disable strict provider independence when only one provider is available)"}var pt=class extends Error{constructor(n,a=400){super(n);this.status=a}},Qo=t=>!!t&&typeof t=="object"&&!Array.isArray(t),qr=(t,s,n=!1)=>typeof t=="string"&&t.length<=s&&!t.includes("\0")&&(n||!!t.trim()),hd=/^[a-z][a-z0-9-]{0,39}$/,fd=(t,s,n,a)=>typeof t=="number"&&Number.isFinite(t)?Math.max(n,Math.min(a,Math.floor(t))):s;function ja(t,s,n,a){if(!Array.isArray(t)||t.length>s||t.some(r=>!qr(r,n)))throw new pt(`${a} must contain at most ${s} bounded, nonempty strings.`);if(new Set(t).size!==t.length)throw new pt(`${a} must not contain duplicates.`);return[...t]}function Ur(t){return{revision:t.revision,rationale:t.rationale,contracts:[...t.contracts],tasks:t.tasks.map(({id:s,title:n,instructions:a,owner:r,kind:o,dependsOn:i,dependencyTypes:d,requirements:l,acceptance:m,paths:c})=>({id:s,title:n,instructions:a,owner:r,kind:o,dependsOn:[...i],...d?{dependencyTypes:{...d}}:{},requirements:[...l],acceptance:[...m],paths:[...c]}))}}function gd(t,s){let n=s.roles.coordinator?.[0];if(!n||!t.inventory)throw new pt("The original provider inventory is unavailable; ask the coordinator for a revised plan instead.");return{coordinator:n,pool:[...s.roles.pool??[]],inventory:structuredClone(t.inventory),maxMembers:fd(s.options.maxMembers,4,2,6),maxTasks:fd(s.options.maxTasks,12,1,24),differentProviderReview:s.options.differentProviderReview===!0}}function vd(t,s,n){if(s.status!=="awaiting_approval"||s.tasks.some(i=>i.status&&i.status!=="pending"||(i.attempts??0)>0||i.startedAt!==void 0||i.finishedAt!==void 0||i.head||i.artifacts?.length))throw new pt("This team has already started work. Edit a new pending plan instead.",409);if(!Qo(t)||Object.keys(t).some(i=>!["revision","tasks","contracts","rationale"].includes(i)))throw new pt("Only tasks, contracts and rationale may be edited. Members and requirements stay fixed.");if(!Number.isSafeInteger(t.revision)||t.revision!==s.revision)throw new pt("The plan changed while you were editing. Refresh the plan and merge your edits before saving.",409);if(!Array.isArray(t.tasks)||t.tasks.length<1||t.tasks.length>n.maxTasks)throw new pt(`Keep between 1 and ${n.maxTasks} tasks.`);let a=t.tasks.map((i,d)=>{if(!Qo(i)||Object.keys(i).some(c=>!["id","title","instructions","owner","kind","dependsOn","dependencyTypes","requirements","acceptance","paths"].includes(c)))throw new pt(`Task ${d+1} contains unsupported or runtime fields.`);if(typeof i.id!="string"||!hd.test(i.id)||typeof i.owner!="string"||!hd.test(i.owner)||!qr(i.title,180)||!qr(i.instructions,16e3)||!["implementation","investigation"].includes(String(i.kind)))throw new pt(`Task ${d+1} needs a valid ID, owner, title, kind and instructions.`);let l=ja(i.dependsOn,n.maxTasks,40,`${i.id} dependencies`),m;if(i.dependencyTypes!==void 0){if(!Qo(i.dependencyTypes)||Object.keys(i.dependencyTypes).length>n.maxTasks||Object.entries(i.dependencyTypes).some(([c,u])=>!l.includes(c)||!["completion","artifact","knowledge"].includes(String(u))))throw new pt(`${i.id} contains invalid dependency types.`);m={...i.dependencyTypes}}return{id:i.id,title:i.title,instructions:i.instructions,owner:i.owner,kind:i.kind,dependsOn:l,...m?{dependencyTypes:m}:{},requirements:ja(i.requirements,48,40,`${i.id} requirements`),acceptance:ja(i.acceptance,16,2e3,`${i.id} acceptance criteria`),paths:ja(i.paths,64,500,`${i.id} paths`),status:"pending",attempts:0}});if(!qr(t.rationale,4e3,!0))throw new pt("Rationale must be text of at most 4,000 characters.");let r={requirements:structuredClone(s.requirements),members:structuredClone(s.members),tasks:a,contracts:ja(t.contracts,24,8e3,"Shared contracts"),rationale:t.rationale};if(s.templateUses?.length){for(let i of s.tasks.filter(d=>s.templateUses.some(l=>d.id.startsWith(`${l.id}-`)))){let d=a.find(l=>l.id===i.id);if(!d||d.kind!==i.kind||!i.acceptance.every(l=>d.acceptance.includes(l))||!i.dependsOn.every(l=>d.dependsOn.includes(l))||!i.requirements.every(l=>d.requirements.includes(l)))throw new pt("Template tasks, dependencies and required checks must be preserved. Create a new template version to change its guarantees.");if(d.instructions!==i.instructions&&!d.instructions.startsWith(i.instructions+`
52
+ `))throw new pt("Template instructions can only be extended. Publish a new template version to replace them.");if(d.paths.some(l=>!i.paths.some(m=>m==="*"||l===m||l.startsWith(m+"/"))))throw new pt("Template file ownership cannot be broadened");if(i.dependsOn.some(l=>(d.dependencyTypes?.[l]??"completion")!==(i.dependencyTypes?.[l]??"completion")))throw new pt("Preserve template dependency types")}if(!s.contracts.every(i=>r.contracts.includes(i)))throw new pt("Preserve template contracts");r.templateUses=structuredClone(s.templateUses)}let o=md(r,n);if(o)throw new pt(o);return r}var bd=t=>typeof t=="number"&&Number.isFinite(t);function Xo(t,s){return bd(t)&&bd(s)&&s>=t?[t,s]:void 0}function kd(t,s){return Xo(t.startedAt,t.status==="running"?s:t.endedAt)}function yd(t){let s=[...t].sort((o,i)=>o[0]-i[0]),n=0,a,r=0;for(let[o,i]of s)a===void 0?(a=o,r=i):o>r?(n+=r-a,a=o,r=i):r=Math.max(r,i);return n+(a===void 0?0:r-a)}function wd(t,s={}){let n=s.now??Date.now(),a=new Map,r=[];for(let y of t.tasks)a.has(y.id)?r.push(`Duplicate task ID: ${y.id}`):a.set(y.id,y);let o=[],i=new Map,d=new Map;for(let y of a.values()){let b=[...new Set(y.dependsOn)];i.set(y.id,b.filter(T=>a.has(T)).length);for(let T of b){if(!a.has(T)){r.push(`${y.id} depends on missing task ${T}`);continue}o.push({from:T,to:y.id,kind:y.dependencyTypes?.[T]??"completion"}),d.set(T,[...d.get(T)??[],y.id])}}let l=[...a.keys()].filter(y=>i.get(y)===0).sort(),m=[],c=new Map;for(;l.length;){let y=l.shift();m.push(y),c.set(y,Math.max(0,...a.get(y).dependsOn.filter(b=>c.has(b)).map(b=>c.get(b)+1)));for(let b of d.get(y)??[])i.set(b,i.get(b)-1),i.get(b)===0&&(l.push(b),l.sort())}m.length<a.size&&r.push("Dependencies contain a cycle. Edit the plan before dispatch.");let u=new Map;for(let y of a.values()){let b=s.steps?.filter(T=>T.taskId===y.id);if(b?.length){let T=b.map($=>kd($,n));T.every($=>$!==void 0)&&u.set(y.id,T.reduce(($,x)=>$+x[1]-x[0],0))}else{let T=Xo(y.startedAt,y.status==="running"?n:y.finishedAt);T&&u.set(y.id,T[1]-T[0]),(y.attempts??0)>1&&r.push(`${y.id}: task timestamps describe the latest attempt; earlier attempts are not included.`)}}let p=new Map,f=new Map;for(let y of m){let T=a.get(y).dependsOn.filter($=>p.has($)).sort(($,x)=>p.get(x)-p.get($)||f.get(x).length-f.get($).length||$.localeCompare(x))[0];p.set(y,(T?p.get(T):0)+(u.get(y)??0)),f.set(y,[...T?f.get(T):[],y])}let v=[...m].sort((y,b)=>p.get(b)-p.get(y)||f.get(b).length-f.get(y).length||y.localeCompare(b))[0],g=v?f.get(v):[],w=Math.max(-1,...c.values())+1,C=[...a.values()].map(y=>({id:y.id,title:y.title,owner:y.owner,status:y.status??"pending",layer:c.get(y.id)??w,...u.has(y.id)?{durationMs:u.get(y.id)}:{},critical:g.includes(y.id)})),k=[];for(let y of C)(k[y.layer]??=[]).push(y.id);return{nodes:C,edges:o,layers:k,criticalPath:g,measuredCriticalPathMs:v?p.get(v):0,timedTasks:u.size,completeTiming:u.size===a.size&&m.length===a.size&&[...a.values()].every(y=>["completed","submitted"].includes(y.status??"")&&!y.evidenceStale),warnings:r}}function Cd(t,s,n=Date.now()){let a=t.status==="running"?n:t.endedAt??n,r=Math.max(0,a-t.createdAt),o=[...new Map(s.map(c=>[c.id,c])).values()],i=o.flatMap(c=>{let u=kd(c,a);return u?[{step:c,observed:u}]:[]}),d=c=>i.filter(({step:u})=>c(u)).reduce((u,{observed:p})=>u+p[1]-p[0],0),l=yd(i.map(({observed:c})=>[Math.max(t.createdAt,c[0]),Math.min(a,c[1])]).filter(([c,u])=>u>=c)),m=(t.team?.waits??[]).flatMap(c=>{let u=Xo(c.createdAt,c.resolvedAt??a);return u?[[Math.max(t.createdAt,u[0]),Math.min(a,u[1])]]:[]}).filter(([c,u])=>u>=c);return{elapsedMs:r,occupiedMs:l,unattributedMs:Math.max(0,r-l),workerMs:d(c=>c.kind==="agent"&&!c.coordination&&c.role!=="coordinator"),coordinationMs:d(c=>c.kind==="agent"&&(c.coordination===!0||c.role==="coordinator")),checksMs:d(c=>c.kind!=="agent"),waitingMs:yd(m),timedSteps:i.length,untimedSteps:o.length-i.length,overlaps:d(()=>!0)>l}}function Td(t){if(typeof Intl.Segmenter!="function"||/```|~~~/.test(t))return t;let s=new Intl.Segmenter("en",{granularity:"sentence"});return t.split(/\n\s*\n/).map(n=>{if(n.length<480||n.includes(`
53
+ `)||/[`|*_\[\]<>]|^\s*(?:#{1,6}\s|[-+]\s|\d+[.)]\s)/.test(n))return n;let a=[],r="";for(let{segment:o}of s.segment(n))r.length>=240&&(a.push(r.trimEnd()),r=""),r+=o;return r&&a.push(r.trimEnd()),a.join(`
54
+
55
+ `)}).join(`
56
+
57
+ `)}var ym={planning:"Building the team",awaiting_approval:"Plan ready for approval",running:"Working",blocked:"Unresolved work",verifying:"Verifying the result",completed:"Finished"},Fr={pending:"Planned",running:"Working",needs_info:"Waiting for information",submitted:"Ready for verification",completed:"Complete",failed:"Needs attention"},km={unassigned:"Not assigned",in_progress:"In progress",awaiting_verification:"Awaiting verification",reviewed_unchecked:"Reviewed \xB7 no check ran",verified:"Verified"};function Sd({run:t,steps:s}){let[n,a]=h("all"),[r,o]=h(!1),i=t.team;if(!i)return null;let d=c=>c==="user"?"You":i.members.find(u=>u.id===c)?.name??c,l=i.metrics,m=l.coordinatorInputTokens!==void 0&&l.coordinatorOutputTokens!==void 0;return e("section",{class:"auto-team","aria-label":"Auto team",children:[e("div",{class:"at-head",children:[e("div",{children:[e("h3",{children:"Team and workflow"}),e("span",{class:"help",children:["Revision ",i.revision," \xB7 ",i.scheduler==="event"?"Ready work starts when dependencies resolve":i.wave?`${i.wave} waves so far \xB7 limit ${i.maxWaves} per execution`:"Before the first wave"]})]}),e("span",{class:`badge ${i.gaps.length||i.status==="blocked"?"warn":i.status==="completed"?"ok":""}`,children:Et(t)?"Waiting for your answer":ym[i.status]})]}),e(xm,{run:t}),e(lc,{runId:t.id,running:t.status==="running"}),e(ic,{providers:[...new Set(i.members.map(c=>c.provider))]}),e("div",{class:"at-metrics",role:"group","aria-label":"Coordination usage",children:[e("span",{children:[e("b",{children:l.coordinatorInvocations})," coordinator calls (lifetime) \xB7 limit ",i.coordinationLimit," per execution"]}),e("span",{children:[e("b",{children:l.invocations})," total calls (lifetime) \xB7 limit ",i.invocationLimit," per execution"]}),e("span",{children:[e("b",{children:l.questionCount})," questions"]}),m?e("span",{children:[e("b",{children:It(l.coordinatorInputTokens+l.coordinatorOutputTokens)})," coordinator tokens"]}):e("span",{children:"Coordinator tokens not reported"}),l.coordinatorMs!==void 0?e("span",{children:[e("b",{children:Le(l.coordinatorMs)})," coordinating"]}):null,l.coordinatorCostUsd!==void 0?e("span",{title:"Provider-reported API equivalent, not your subscription charge",children:[e("b",{children:ht(l.coordinatorCostUsd)})," API equivalent"]}):null]}),i.rationale?e("p",{class:"at-rationale",children:i.rationale}):null,t.status==="running"&&t.awaiting?.kind==="plan"&&i.status==="awaiting_approval"&&!t.teamRerun?e("div",{class:"at-row",children:[e("button",{class:"btn",disabled:!i.inventory,title:i.inventory?"Edit tasks and contracts while keeping the selected members, requirements and permissions":"Provider inventory is unavailable for this older plan",onClick:()=>o(!0),children:"Edit pending plan"}),e("span",{class:"help",children:"Saving changes keeps the plan pending for your approval."})]}):null,t.teamRerun?e("p",{class:"at-notice",children:["Selective rerun of ",t.teamRerun.parentRunId," from ",e("code",{children:t.teamRerun.baseCommit.slice(0,12)}),". Executes ",t.teamRerun.rerunTaskIds.join(", "),"; retained tasks are baseline inputs. All requirements need fresh final checks and independent review."]}):null,t.status!=="running"&&t.worktrees.some(c=>c.name==="integration")&&!["planning","awaiting_approval"].includes(i.status)?e(Cm,{run:t},t.id):null,e(Tm,{run:t,steps:s}),i.reviewFallback?e("div",{class:"at-notice",children:i.reviewFallback}):null,i.gaps.length?e("div",{class:"at-notice",children:[e("b",{children:"Still unresolved"}),e("ul",{children:i.gaps.map((c,u)=>e("li",{children:c},u))})]}):null,Kt(t)?e("p",{class:"help",children:"Resume continues this team's unfinished work with a fresh execution budget. Completed work and recorded answers are kept."}):null,e("div",{class:"at-roster",role:"group","aria-label":"Team members",children:i.members.map(c=>e("article",{class:"at-member",children:[e("div",{class:"at-row",children:[e("b",{children:c.name}),e("span",{class:"badge",children:c.role.charAt(0).toUpperCase()+c.role.slice(1)})]}),e($e,{id:c.provider,note:[c.assignment?.model??c.model,c.assignment?.effort??c.effort].filter(Boolean).join(" \xB7 ")||"CLI defaults"}),e("div",{class:"help",children:[al(i,c)," \xB7 ",e("code",{children:c.id})]}),e("button",{class:"btn small",onClick:()=>a(c.id),children:["Inbox \xB7 ",i.messages.filter(u=>u.recipient===c.id&&u.delivery?.status!=="context"&&u.status!=="delivered").length," pending"]}),e("p",{children:c.assignment?.rationale??c.reason}),c.assignment?e("p",{class:"help",children:["Catalog revision ",c.assignment.catalogRevision," \xB7 ",c.assignment.source,c.assignment.stale?" \xB7 cached, stale":""]}):null,c.checkpoint?e("details",{children:[e("summary",{children:"Private checkpoint"}),e(Oe,{text:c.checkpoint})]}):null]},c.id))}),i.tasks.length?e("div",{class:"at-section",children:[e("h4",{children:"Workflow"}),e("ol",{class:"at-tasks",children:i.tasks.map(c=>{let u=!c.status||c.status==="pending"||c.status==="needs_info"||c.status==="failed"?po(i,c):[];return e("li",{class:"at-task",tabIndex:-1,id:`team-task-${c.id}`,children:[e("div",{class:"at-row",children:[e("b",{children:c.title}),e("span",{class:`badge ${c.status==="completed"?"ok":c.status==="failed"?"warn":""}`,children:Fr[c.status??"pending"]})]}),e("div",{class:"help",children:[d(c.owner)," \xB7 ",c.kind," \xB7 ",c.attempts??0," attempts"]}),c.retainedBaseline?e("p",{class:"help",children:["Retained baseline input from ",c.retainedBaseline.sourceRunId," \xB7 ",e("code",{children:c.retainedBaseline.sourceTaskHead.slice(0,12)}),". This task was not executed again."]}):null,c.noNewDiff?e("p",{class:"help",children:"No new diff from this rerun turn. Acceptance requires a current-head check and independent review."}):null,c.dependsOn.length?e("div",{class:"help",children:["Needs ",c.dependsOn.map(p=>`${i.tasks.find(f=>f.id===p)?.title??p} (${c.dependencyTypes?.[p]??"completion"})`).join(", ")]}):null,c.evidenceStale?e("p",{class:"at-notice",children:"The contract changed. This task's evidence needs verification again."}):null,u.length?e("ul",{class:"at-blockers",children:u.map((p,f)=>e("li",{children:p},f))}):null,e("details",{children:[e("summary",{children:"Assignment and acceptance"}),e(Oe,{text:c.instructions}),e("ul",{children:c.acceptance.map((p,f)=>e("li",{children:p},f))}),c.paths.length?e("div",{class:"help",children:["Paths: ",c.paths.join(", ")]}):null,c.checkpoint?e(Oe,{text:c.checkpoint}):null]})]},c.id)})})]}):null,i.waits?.some(c=>c.status!=="resolved")?e("div",{class:"at-section",children:[e("h4",{children:"Waiting and escalation"}),e("ul",{children:i.waits.filter(c=>c.status!=="resolved").map(c=>e("li",{children:[e("b",{children:d(c.memberId)})," \xB7 ",c.taskId," \xB7 ",c.status,c.status==="waiting"?` \xB7 deadline ${new Date(c.deadlineAt).toLocaleTimeString()}`:"",c.reason?` \xB7 ${c.reason}`:""]},c.requestId))}),e("p",{class:"help",children:"Waiting members release their agent slots. Expired requests and unavailable recipients are escalated to the coordinator."})]}):null,i.requirements.length?e("div",{class:"at-section",children:[e("h4",{children:"Requirement coverage"}),e("ul",{class:"at-coverage",children:i.requirements.map(c=>{let u=nl(i,c.id,t.status),p=i.tasks.filter(f=>f.requirements.includes(c.id)&&f.retainedBaseline).length;return e("li",{children:[e("span",{children:[c.description,p?e("small",{class:"help",children:[" \xB7 ",p," retained baseline task(s)"]}):null]}),e("span",{class:`badge ${u==="verified"?"ok":u==="unassigned"?"warn":""}`,children:km[u]})]},c.id)})}),i.verification?e("p",{class:"help",children:["Checks: ",i.verification.check.replaceAll("_"," ")," \xB7 Review: ",i.verification.reviewed?i.verification.approved?"approved":"changes requested":"pending"," \xB7 Commit ",e("code",{children:i.verification.head.slice(0,12)})]}):null]}):null,i.messages.length?e("div",{class:"at-section",children:[e("div",{class:"at-row",children:[e("h4",{children:"Team messages"}),e("label",{children:["Inbox ",e("select",{class:"field","aria-label":"Member inbox",value:n,onChange:c=>a(c.currentTarget.value),children:[e("option",{value:"all",children:"All members"}),e("option",{value:"user",children:"Questions for you"}),i.members.map(c=>e("option",{value:c.id,children:c.name},c.id))]})]})]}),e("div",{class:"at-messages",children:i.messages.filter(c=>n==="all"||c.recipient===n).map(c=>e("article",{class:`at-message ${c.status}`,children:[e("div",{class:"at-row",children:[e("b",{children:[d(c.sender)," \u2192 ",d(c.recipient)]}),e("span",{class:"badge",children:c.kind==="question"?c.status==="open"?"Open question":"Answered":c.kind[0].toUpperCase()+c.kind.slice(1)})]}),e(wm,{message:c}),e("div",{class:"at-message-meta",children:[e("div",{class:"help",children:[c.origin==="user"?"From you":"From a team member",c.blocking?c.status==="open"?" \xB7 blocks dependent work":" \xB7 blocker resolved":""]}),e("div",{class:"help",children:[c.createdAt?new Date(c.createdAt).toLocaleTimeString():"",c.delivery?` \xB7 ${c.delivery.status==="steered"?"delivered during a turn":c.delivery.status==="steering"?"sent during a turn, acknowledgement pending":c.delivery.status==="context"?"included in member context":"queued for the next turn"}`:"",c.originalRecipient?` \xB7 routed from ${d(c.originalRecipient)}`:"",c.deadlineAt&&c.status==="open"?` \xB7 answer due ${new Date(c.deadlineAt).toLocaleTimeString()}`:""]})]}),c.evidence.length?e("details",{children:[e("summary",{children:"Evidence"}),e("ul",{children:c.evidence.map((u,p)=>e("li",{children:u},p))})]}):null,c.kind==="question"&&c.recipient==="user"&&c.status==="open"?Et(t)&&i.awaitingRequestId===c.id?e("p",{class:"help",children:"Answer it in the card under the run header."}):e(Rd,{run:t,message:c},c.id):null]},c.id))})]}):null,i.strategyInstances?.length?e("details",{class:"at-section",children:[e("summary",{children:"Reusable workflow steps"}),e("ul",{children:i.strategyInstances.map(c=>e("li",{children:[c.strategy," \xB7 revision ",c.revision," \xB7 ",c.taskIds.map(u=>i.tasks.find(p=>p.id===u)?.title??u).join(" \u2192 ")]},c.id))})]}):null,i.contracts.length?e("details",{class:"at-section",children:[e("summary",{children:"Shared contracts"}),i.contracts.map((c,u)=>e(Oe,{text:c},u))]}):null,i.contextManifests.length?e("details",{class:"at-section",children:[e("summary",{children:"Context used by each member"}),e("p",{class:"help",children:"Each turn receives its assignment, relevant shared information, and its own checkpoint."}),e("ul",{class:"at-context",children:i.contextManifests.map((c,u)=>e("li",{children:[e("b",{children:d(c.memberId)})," \xB7 ",c.taskId," \xB7 attempt ",c.attempt,e("div",{class:"help",children:["Plan ",c.revision," \xB7 commit ",e("code",{children:c.inputHead.slice(0,12)})," \xB7 ",c.checkpoint?"private checkpoint included":"no private checkpoint"]}),e("div",{class:"help",children:["Messages: ",c.messageIds.join(", ")||"none"," \xB7 Memory: ",c.memoryIds.join(", ")||"none"]})]},`${c.memberId}-${c.taskId}-${c.attempt}-${u}`))})]}):null,t.memoryManifest?e("details",{class:"at-section",children:[e("summary",{children:"Why project memory was selected"}),e("ul",{class:"at-context",children:[t.memoryManifest.included.map(c=>e("li",{children:[e("b",{children:"Included"})," \xB7 ",c.id," \xB7 revision ",c.revision,e("div",{class:"help",children:c.reason}),t.project?e(Ko,{projectId:t.project,id:c.id,revision:c.revision,runId:t.id}):null]},`included-${c.id}`)),t.memoryManifest.omitted.map(c=>e("li",{children:[e("b",{children:"Omitted"})," \xB7 ",c.id," \xB7 revision ",c.revision,e("div",{class:"help",children:c.reason})]},`omitted-${c.id}`))]}),!t.memoryManifest.included.length&&!t.memoryManifest.omitted.length?e("p",{class:"help",children:"No applicable project knowledge was available for this run."}):null]}):null,i.inventory?.providers.some(c=>c.blockedReason)?e("details",{class:"at-section",children:[e("summary",{children:"Provider availability"}),e("ul",{children:i.inventory.providers.filter(c=>c.blockedReason).map(c=>e("li",{children:[e($e,{id:c.id}),": ",c.blockedReason]},c.id))})]}):null,r?e(Sm,{run:t,onClose:()=>o(!1)}):null]})}function wm({message:t}){let s=t.body.indexOf(`
58
+ `),n=t.kind==="finding"&&s>0&&s<=200;return e("div",{class:"at-message-content",children:[n?e("h5",{class:"at-message-title",children:t.body.slice(0,s)}):null,e(Oe,{text:Td(n?t.body.slice(s+1):t.body)})]})}function Cm({run:t}){let s=t.team,[n,a]=h(!1),[r,o]=h(""),[i,d]=h([]),[l,m]=h({}),[c,u]=h(Math.max(8,t.loop.maxSteps)),[p,f]=h(t.loop.maxMinutes),[v,g]=h(!1),[w,C]=h(""),[k,y]=h(0),b=t.worktrees.find(P=>P.name==="integration").branch;_(()=>{if(!n)return;let P=!0;return o(""),C(""),U(`/api/runs/${J(t.id)}/review-coverage?branch=${J(b)}`).then(D=>{P&&o(D.head)},D=>{P&&C(D.message)}),()=>{P=!1}},[n,t.id,b,k]);let T=sd(s.tasks,i),$=s.tasks.filter(P=>!T.has(P.id)),x=$.filter(P=>!["completed","submitted"].includes(P.status??"")||P.evidenceStale||!P.head),E=Math.max(4,T.size+2),A=async()=>{g(!0),C("");try{let P=Object.fromEntries(i.filter(S=>l[S]?.trim()).map(S=>[S,l[S].trim()])),D=await q(`/api/runs/${J(t.id)}/rerun-tasks`,{expectedHead:r,taskIds:i,instructions:P,budget:{maxSteps:c,maxInvocations:c,maxMinutes:p}});_e({view:"run",id:D.id})}catch(P){C(P.message)}finally{g(!1)}};return e("details",{class:"at-section team-rerun",onToggle:P=>a(P.currentTarget.open),children:[e("summary",{children:"Rerun selected tasks"}),e("p",{class:"help",children:"Creates a child at the committed integration result. Selected tasks and every downstream dependency execute again; other completed tasks become explicit baseline inputs. The original run and its worker checkouts stay available. The child requires fresh checks and independent review of all requirements."}),e("p",{class:"help",children:["Baseline: ",r?e("code",{children:r.slice(0,12)}):"Loading current integration commit\u2026"," ",e("button",{class:"btn ghost small",disabled:v,onClick:()=>y(P=>P+1),children:"Refresh rerun baseline"})]}),r&&(s.verification?.head!==r||!s.verification?.approved)?e("p",{class:"at-notice",children:"This baseline has no passing parent verification at its current commit. The child starts unverified."}):null,e("fieldset",{disabled:v,children:[e("legend",{children:"Tasks to execute again"}),s.tasks.map(P=>e("div",{children:[e("label",{class:"check",children:[e("input",{type:"checkbox",checked:i.includes(P.id),onChange:D=>d(D.currentTarget.checked?[...i,P.id]:i.filter(S=>S!==P.id))}),"Rerun ",P.title]}),i.includes(P.id)?e("label",{children:["New instructions for ",P.id,e("textarea",{class:"field",rows:2,maxLength:16e3,placeholder:"Leave blank to reuse the accepted instructions",value:l[P.id]??"",onInput:D=>m({...l,[P.id]:D.currentTarget.value})})]}):null]},P.id))]}),e("div",{class:"rerun-preview",role:"group","aria-label":"Task rerun preview",children:[e("p",{children:["Execute: ",s.tasks.filter(P=>T.has(P.id)).map(P=>P.id).join(", ")||"Choose a task"]}),e("p",{children:["Retain as baseline inputs: ",$.map(P=>P.id).join(", ")||"None"]})]}),x.length?e("p",{class:"at-notice",children:["Also select unfinished or stale tasks: ",x.map(P=>P.id).join(", "),"."]}):null,e("div",{class:"at-row",children:[e("label",{children:["New invocation budget",e("input",{class:"field",type:"number",min:E,max:"200",value:c,disabled:v,onInput:P=>u(Number(P.currentTarget.value))})]}),e("label",{children:["Rerun time budget (minutes)",e("input",{class:"field",type:"number",min:"1",max:"720",value:p,disabled:v,onInput:P=>f(Number(P.currentTarget.value))})]})]}),e("p",{class:"help",children:["At least ",E," calls fund invalidated work, independent review and one recovery allowance. Provider/model/permission settings stay pinned. An unchanged implementation must still pass the current check and independent review; it does not create new fail-to-pass proof."]}),e("button",{class:"btn primary",disabled:v||!r||!i.length||!!x.length||!Number.isInteger(c)||c<E||c>200||!Number.isFinite(p)||p<1||p>720,onClick:A,children:v?"Starting child\u2026":"Start selected task rerun"}),w?e("p",{class:"msg err",role:"alert",children:w}):null]})}function Tm({run:t,steps:s}){let n=t.team,a=wd(n,{steps:s});if(!a.nodes.length)return null;let r=new Map(a.nodes.map(l=>[l.id,{x:20+l.layer*240,y:20+(a.layers[l.layer]?.indexOf(l.id)??0)*92}])),o=Math.max(240,a.layers.length*240),i=Math.max(100,...a.layers.map(l=>l.length*92+20)),d=s?Cd(t,s):null;return e("details",{class:"at-section workflow-graph",children:[e("summary",{children:["Workflow graph and timing \xB7 ",a.nodes.length," tasks"]}),e("p",{class:"help",children:"Arrows show dependencies. Highlighted tasks form the longest measured dependency chain. Untimed work, provider limits, shared files and queue delays can change the actual bottleneck."}),e("div",{class:"workflow-dag-scroll",tabIndex:0,children:e("svg",{role:"img","aria-label":`Workflow dependencies: ${a.edges.map(l=>`${l.from} to ${l.to}`).join(", ")||"independent tasks"}`,viewBox:`0 0 ${o} ${i}`,width:o,height:i,children:[e("defs",{children:e("marker",{id:`dag-arrow-${t.id}`,viewBox:"0 0 10 10",refX:"9",refY:"5",markerWidth:"6",markerHeight:"6",orient:"auto-start-reverse",children:e("path",{d:"M 0 0 L 10 5 L 0 10 z"})})}),a.edges.map(l=>{let m=r.get(l.from),c=r.get(l.to),u=m.x+204,p=c.x,f=m.y+33,v=c.y+33;return e("path",{class:`dag-edge ${l.kind}`,d:`M ${u} ${f} C ${u+22} ${f}, ${p-22} ${v}, ${p} ${v}`,"marker-end":`url(#dag-arrow-${t.id})`,children:e("title",{children:[l.from," \u2192 ",l.to," \xB7 ",l.kind]})},`${l.from}-${l.to}`)}),a.nodes.map(l=>{let m=r.get(l.id);return e("g",{class:`dag-node ${l.status} ${l.critical?"critical":""}`,transform:`translate(${m.x} ${m.y})`,children:[e("title",{children:[l.title," \xB7 ",l.owner," \xB7 ",l.status,l.durationMs!==void 0?` \xB7 ${Le(l.durationMs)} measured`:" \xB7 no task timing"]}),e("rect",{width:"204",height:"66",rx:"8"}),e("text",{x:"12",y:"23",class:"dag-title",children:l.title.length>25?`${l.title.slice(0,24)}\u2026`:l.title}),e("text",{x:"12",y:"40",children:[l.owner.slice(0,20)," \xB7 ",l.durationMs===void 0?"untimed":Le(l.durationMs)]}),e("circle",{cx:"15",cy:"52.5",r:"3",class:"dag-dot"}),e("text",{x:"23",y:"56",class:"dag-status",children:Fr[l.status]??l.status})]},l.id)})]})}),e("p",{class:"help",children:["Observed chain: ",a.criticalPath.map(l=>n.tasks.find(m=>m.id===l)?.title??l).join(" \u2192 ")||"unavailable",a.timedTasks?` \xB7 ${Le(a.measuredCriticalPathMs)}`:" \xB7 timing unavailable",". ",a.timedTasks,"/",a.nodes.length," tasks have timing.",a.completeTiming?"":" This is partial timing, not a completion estimate."]}),d?e("dl",{class:"workflow-timing",children:[e("div",{children:[e("dt",{children:"Since run creation"}),e("dd",{children:Le(d.elapsedMs)})]}),e("div",{children:[e("dt",{children:"Worker process time"}),e("dd",{children:Le(d.workerMs)})]}),e("div",{children:[e("dt",{children:"Coordination process time"}),e("dd",{children:Le(d.coordinationMs)})]}),e("div",{children:[e("dt",{children:"Check and setup time"}),e("dd",{children:Le(d.checksMs)})]}),e("div",{children:[e("dt",{children:"Recorded wait periods"}),e("dd",{children:Le(d.waitingMs)})]}),e("div",{children:[e("dt",{children:"Other elapsed time"}),e("dd",{children:Le(d.unattributedMs)})]})]}):null,d?e("p",{class:"help",children:["Process time sums recorded steps and can overlap. Other elapsed time includes queues, approvals and time between executions. ",d.untimedSteps?`${d.untimedSteps} steps have incomplete timing.`:""]}):null,a.warnings.length?e("ul",{class:"at-notice",children:a.warnings.map(l=>e("li",{children:l},l))}):null]})}function Zo(t){let s=n=>n.map(a=>a.trim()).filter(Boolean);return{...t,contracts:s(t.contracts),tasks:t.tasks.map(n=>({...n,paths:s(n.paths),acceptance:s(n.acceptance),dependsOn:s(n.dependsOn),requirements:s(n.requirements)}))}}function Sm({run:t,onClose:s}){let n=t.team,a=we(!0,s),[r,o]=h(()=>Ur(n)),[i,d]=h(!1),[l,m]=h(""),c="",u=24;try{let w=gd(n,t);u=w.maxTasks,vd(Zo(r),n,w)}catch(w){c=w.message}let p=n.revision!==r.revision,f=(w,C)=>o({...r,tasks:r.tasks.map(k=>k.id===w?{...k,...C}:k)}),v=async()=>{if(!(c||i)){d(!0),m("");try{await q(`/api/runs/${encodeURIComponent(t.id)}/team-plan`,Zo(r)),V("Plan changes saved. Review them before approving.",4e3),s()}catch(w){m(w.message)}finally{d(!1)}}},g=()=>{let w=URL.createObjectURL(new Blob([JSON.stringify(Zo(r),null,2)],{type:"application/json"})),C=document.createElement("a");C.href=w,C.download=`team-plan-${t.id}.json`,C.click(),setTimeout(()=>URL.revokeObjectURL(w),1e3)};return e("dialog",{class:"picker team-plan-editor",ref:a,"aria-labelledby":"team-plan-editor-title",children:e("div",{class:"picker-inner",children:[e("div",{class:"picker-head",children:[e("h3",{id:"team-plan-editor-title",children:"Edit pending team plan"}),e("p",{class:"help",children:"Members, requirements, model settings, permissions and execution limits stay fixed. Edit assignments, dependencies, paths, acceptance and contracts before dispatch."})]}),e("div",{class:"dialog-body",children:[p?e("div",{class:"at-notice",role:"alert",children:["The saved plan changed. Your draft is kept. Export or copy your changes before replacing it with the current plan.",e("button",{class:"btn",onClick:()=>{o(Ur(n)),m("")},children:"Replace draft with latest plan"}),e("details",{children:[e("summary",{children:"Latest plan for comparison"}),e("pre",{class:"template-preview",tabIndex:0,children:JSON.stringify(Ur(n),null,2)})]})]}):null,e("label",{class:"lbl",for:"team-plan-rationale",children:"Rationale"}),e("textarea",{class:"field",id:"team-plan-rationale",rows:3,maxLength:4e3,value:r.rationale,onInput:w=>o({...r,rationale:w.currentTarget.value})}),e("div",{class:"at-row",children:[e("h4",{children:["Tasks \xB7 ",r.tasks.length,"/",u]}),e("button",{class:"btn small",disabled:r.tasks.length>=u,onClick:()=>o({...r,tasks:[...r.tasks,{id:`task-${crypto.randomUUID().slice(0,8)}`,title:"New task",instructions:"",kind:"implementation",owner:n.members.find(w=>w.role==="worker"&&w.status!=="retired")?.id??"",dependsOn:[],requirements:n.requirements[0]?[n.requirements[0].id]:[],acceptance:[""],paths:[""]}]}),children:"Add task"})]}),r.tasks.map(w=>e("details",{class:"plan-task-editor",open:!0,children:[e("summary",{children:[e("span",{class:"pt-title",children:w.title||"Untitled task"}),e("code",{children:w.id})]}),e("div",{class:"plan-task-body",children:[e("label",{children:["Title",e("input",{class:"field","aria-label":`Title for ${w.id}`,maxLength:180,value:w.title,onInput:C=>f(w.id,{title:C.currentTarget.value})})]}),e("div",{class:"settings-grid",children:[e("label",{children:["Kind",e("select",{class:"field","aria-label":`Kind for ${w.id}`,value:w.kind,onChange:C=>{let k=C.currentTarget.value,y=n.members.find(b=>b.id===w.owner);f(w.id,{kind:k,...k==="implementation"&&y?.role!=="worker"?{owner:n.members.find(b=>b.role==="worker"&&b.status!=="retired")?.id??""}:{}})},children:[e("option",{value:"implementation",children:"Implementation"}),e("option",{value:"investigation",children:"Investigation"})]})]}),e("label",{children:["Owner",e("select",{class:"field","aria-label":`Owner for ${w.id}`,value:w.owner,onChange:C=>f(w.id,{owner:C.currentTarget.value}),children:n.members.filter(C=>C.status!=="retired"&&C.role!=="reviewer"&&(w.kind==="investigation"||C.role==="worker")).map(C=>e("option",{value:C.id,children:[C.name," \xB7 ",C.provider]},C.id))})]})]}),e("label",{children:["Instructions",e("textarea",{class:"field","aria-label":`Instructions for ${w.id}`,rows:3,maxLength:16e3,value:w.instructions,onInput:C=>f(w.id,{instructions:C.currentTarget.value})})]}),e("label",{children:["Owned paths \xB7 one per line",e("textarea",{class:"field mono","aria-label":`Paths for ${w.id}`,rows:2,value:w.paths.join(`
59
+ `),onInput:C=>f(w.id,{paths:C.currentTarget.value.split(`
60
+ `)})})]}),e("label",{children:["Acceptance criteria \xB7 one per line",e("textarea",{class:"field","aria-label":`Acceptance for ${w.id}`,rows:3,value:w.acceptance.join(`
61
+ `),onInput:C=>f(w.id,{acceptance:C.currentTarget.value.split(`
62
+ `)})})]}),e("fieldset",{children:[e("legend",{children:"Requirements covered"}),n.requirements.map(C=>e("label",{class:"check",children:[e("input",{type:"checkbox",checked:w.requirements.includes(C.id),onChange:k=>f(w.id,{requirements:k.currentTarget.checked?[...w.requirements,C.id]:w.requirements.filter(y=>y!==C.id)})}),C.description," ",e("code",{children:C.id})]},C.id))]}),e("fieldset",{children:[e("legend",{children:"Dependencies"}),r.tasks.filter(C=>C.id!==w.id).map(C=>e("div",{class:"dependency-edit",children:[e("label",{class:"check",children:[e("input",{type:"checkbox",checked:w.dependsOn.includes(C.id),onChange:k=>{let y={...w.dependencyTypes};k.currentTarget.checked||delete y[C.id],f(w.id,{dependsOn:k.currentTarget.checked?[...w.dependsOn,C.id]:w.dependsOn.filter(b=>b!==C.id),dependencyTypes:y})}}),C.title]}),w.dependsOn.includes(C.id)?e("select",{class:"field","aria-label":`Dependency ${C.id} for ${w.id}`,value:w.dependencyTypes?.[C.id]??"completion",onChange:k=>f(w.id,{dependencyTypes:{...w.dependencyTypes,[C.id]:k.currentTarget.value}}),children:[e("option",{value:"completion",children:"Completion"}),e("option",{value:"artifact",children:"Integrated artifact"}),e("option",{value:"knowledge",children:"Evidence-backed knowledge"})]}):null]},C.id))]}),e("button",{class:"btn small danger",disabled:r.tasks.length<=1,onClick:()=>o({...r,tasks:r.tasks.filter(C=>C.id!==w.id).map(C=>{let k={...C.dependencyTypes};return delete k[w.id],{...C,dependsOn:C.dependsOn.filter(y=>y!==w.id),dependencyTypes:k}})}),children:"Remove task"})]})]},w.id)),e("div",{class:"at-row",children:[e("h4",{children:"Shared contracts"}),e("button",{class:"btn small",disabled:r.contracts.length>=24,onClick:()=>o({...r,contracts:[...r.contracts,""]}),children:"Add contract"})]}),r.contracts.map((w,C)=>e("div",{class:"plan-contract-editor",children:[e("textarea",{class:"field","aria-label":`Shared contract ${C+1}`,rows:3,maxLength:8e3,value:w,onInput:k=>o({...r,contracts:r.contracts.map((y,b)=>b===C?k.currentTarget.value:y)})}),e("button",{class:"btn small",onClick:()=>o({...r,contracts:r.contracts.filter((k,y)=>y!==C)}),children:["Remove contract ",C+1]})]},C)),c?e("p",{class:"msg warn",role:"status",children:c}):e("p",{class:"help",role:"status",children:"Plan is valid. Saving changes keeps approval pending."}),l?e("p",{class:"msg err",role:"alert",children:l}):null]}),e("div",{class:"picker-foot",children:[e("span",{class:"ps",children:["Based on revision ",r.revision]}),e("button",{class:"btn",onClick:g,children:"Export draft"}),e("button",{class:"btn",disabled:i,onClick:s,children:"Cancel"}),e("button",{class:"btn primary",disabled:!!c||i,onClick:v,children:i?"Saving\u2026":"Save plan changes"})]})]})})}function xd({run:t}){let s=t.team,n=s?.messages.find(o=>o.id===s.awaitingRequestId);if(!s||!n)return null;let a=s.members.find(o=>o.id===n.sender),r=s.tasks.find(o=>o.id===n.taskId);return e("section",{class:"awaiting-card team-question","aria-label":"The team needs your answer",children:[e("div",{class:"aw-head",children:[e("span",{class:"status-pill awaiting",children:"Waiting for you"}),e("b",{children:"The team needs your answer"}),e("span",{class:"help",children:[a?.name??n.sender,r?` \xB7 ${r.title}`:""]})]}),e("div",{class:"aw-body",children:e(Oe,{text:n.body})}),e("div",{class:"aw-actions",children:e(Rd,{run:t,message:n},n.id)})]})}var Cn=new Map;function Rd({run:t,message:s,prefix:n="team-answer"}){let a=`${t.id}/${s.id}`,[r,o]=h(()=>Cn.get(a)??""),[i,d]=h(!1),[l,m]=h(""),[c,u]=h(!1),p=async()=>{if(!(!r.trim()||i||c)){d(!0),m("");try{await q(`/api/runs/${t.id}/notes`,{requestId:s.id,text:r}),Cn.delete(a),u(!0)}catch(v){m(v.message)}finally{d(!1)}}};if(c)return e("p",{class:"help",role:"status",children:"Answer sent."});if(t.status!=="running")return e("p",{class:"help",children:"Press Resume in the header to continue the run, then answer here."});let f=`${n}-${s.id}`;return e("div",{class:"at-reply",children:[e("label",{class:"lbl",for:f,children:"Your answer"}),e("textarea",{class:"field",id:f,placeholder:"Your answer\u2026",rows:2,value:r,onInput:v=>{let g=v.currentTarget.value;o(g),g?Cn.set(a,g):Cn.delete(a),Cn.size>100&&Cn.delete(Cn.keys().next().value)}}),e("button",{class:"btn primary small",disabled:!r.trim()||i,onClick:p,children:i?"Sending\u2026":"Send answer"}),l?e("p",{class:"msg err",role:"alert",children:l}):null]})}function xm({run:t}){let[s,n]=h(""),[a,r]=h(!1),[o,i]=h(""),d=t.team,l=d.tasks.find(f=>f.id===s)??d.tasks.find(f=>f.status==="running")??d.tasks[0];if(!l)return null;let m=d.members.find(f=>f.id===l.owner),c=po(d,l),u=d.messages.filter(f=>f.taskId===l.id&&f.kind==="question"&&f.status==="open"),p=async f=>{r(!0),i("");try{await q(`/api/runs/${t.id}/task-priority`,{taskId:l.id,priority:f,revision:d.revision})}catch(v){i(v.message)}finally{r(!1)}};return e("section",{class:"live-team-map","aria-label":"Live team map",children:[e("h4",{children:"Who's doing what"}),e("div",{class:"team-map-grid",children:d.tasks.map(f=>e("button",{class:`team-map-node ${f.status??"pending"}`,"aria-pressed":f.id===l.id,onClick:()=>n(f.id),children:[e("strong",{children:f.title}),e("span",{children:d.members.find(v=>v.id===f.owner)?.name??f.owner}),e("span",{children:Fr[f.status??"pending"]}),e("small",{children:f.dependsOn.length?`After: ${f.dependsOn.join(", ")}`:"Independent task"})]},f.id))}),e("article",{class:"team-map-detail",children:[e("h4",{children:l.title}),e("p",{children:[m?.name??l.owner," \xB7 ",m?.provider," \xB7 ",Fr[l.status??"pending"]]}),m?.assignment?e("p",{children:[m.assignment.model," \xB7 ",m.assignment.effort||"Default effort"," \u2014 ",m.assignment.rationale]}):null,e("p",{class:"help",children:["Files and areas: ",l.paths.join(", ")||"No paths assigned"]}),c.length?e("ul",{children:c.map(f=>e("li",{children:f},f))}):null,e("div",{class:"experience-actions",children:[!t.projectTeam&&t.status==="running"&&["pending","needs_info","failed"].includes(l.status??"pending")?e("label",{children:["Task priority",e("select",{class:"field",disabled:a,value:t.taskPriorities?.[l.id]??0,onChange:f=>void p(Number(f.currentTarget.value)),children:[e("option",{value:0,children:"Normal"}),e("option",{value:10,children:"High"}),e("option",{value:-10,children:"Low"})]})]}):null,e("button",{class:"btn small",onClick:()=>{let f=document.getElementById(`team-task-${l.id}`);f?.scrollIntoView({block:"center",behavior:"smooth"}),f?.focus()},children:"Inspect assignment"})]}),e("p",{class:"help",children:"Priority affects the next dispatch; dependency, file ownership and budget checks still apply."}),u.map(f=>e("div",{children:[e("p",{children:f.body}),f.recipient==="user"?e("button",{class:"btn small",onClick:()=>{let v=document.getElementById(`team-answer-${f.id}`);v?.scrollIntoView({block:"center",behavior:"smooth"}),v?.focus()},children:"Answer this question"}):e("p",{class:"help",children:["Waiting for ",d.members.find(v=>v.id===f.recipient)?.name??f.recipient]})]},f.id)),o?e("p",{role:"alert",children:o}):null]})]})}function ei({runId:t,branch:s,readOnly:n=!1}){let[a,r]=h(!1),[o,i]=h(),[d,l]=h(""),[m,c]=h(""),[u,p]=h(""),f=`/api/runs/${encodeURIComponent(t)}/pr-threads${s?`?branch=${encodeURIComponent(s)}`:""}`,v=Q(f);v.current=f,_(()=>()=>{v.current=void 0},[]),_(()=>{i(void 0),c(""),p(""),l("")},[t,s]),_(()=>{if(!a)return;let k=!0;return l("load"),U(f).then(y=>{k&&(i(y),c(""))},y=>{k&&c(y.message)}).finally(()=>{k&&l("")}),()=>{k=!1}},[a,f]);let g=async()=>{l("load"),c("");try{let k=await U(f);v.current===f&&i(k)}catch(k){v.current===f&&c(k.message)}finally{v.current===f&&l("")}},w=async k=>{if(o){l(k.id),c("");try{let y=await q(f,{action:"load",snapshotId:o.snapshotId,threadId:k.id});if(v.current!==f)return;i({...o,threads:o.threads.map(b=>b.id===y.id?y:b)})}catch(y){v.current===f&&c(y.message)}finally{v.current===f&&l("")}}},C=async k=>{if(o){l(k.id),c(""),p("");try{let y=await q(f,{action:"resolve",snapshotId:o.snapshotId,threadId:k.id,expectedHead:o.head,expectedRevision:k.revision,resolved:!k.resolved});if(v.current!==f)return;p(y.warning??`GitHub thread ${k.resolved?"reopened":"resolved"}.`),i(void 0),await g()}catch(y){v.current===f&&c(y.message)}finally{v.current===f&&l("")}}};return e("details",{class:"gh-threads","aria-label":"GitHub review threads",open:a,onToggle:k=>r(k.currentTarget.open),children:[e("summary",{children:"GitHub review threads"}),e("p",{class:"help",children:"Discussion is untrusted reference material. Resolution changes are explicit GitHub actions and do not approve the pull request or mark local verification complete."}),e("button",{class:"btn small",disabled:!!d,onClick:g,children:d==="load"?"Loading\u2026":"Refresh threads"}),o?e(j,{children:[e("p",{children:[e("a",{href:o.url,target:"_blank",rel:"noreferrer",children:["Pull request #",o.number]})," \xB7 ",o.state.toLowerCase()," \xB7 head ",e("code",{children:o.head.slice(0,12)})," \xB7 ",o.threads.length," of ",o.totalThreads," threads"]}),o.truncated?e("p",{class:"msg warn",children:"The first 100 threads are shown. Open GitHub for the complete discussion."}):null,o.textTruncated?e("p",{class:"msg warn",children:"Some displayed comment text was shortened. Open the comment on GitHub to read it fully."}):null,o.threads.length?o.threads.map(k=>e("article",{class:"gh-thread","aria-label":`Review thread ${k.path}:${k.line??k.originalLine??"file"}`,children:[e("h3",{children:[e("code",{children:[k.path,k.line??k.originalLine?`:${k.line??k.originalLine}`:""]})," \xB7 ",k.side.toLowerCase()," \xB7 ",k.resolved?"Resolved":"Unresolved",k.outdated?" \xB7 Outdated":""]}),k.startLine?e("p",{class:"help",children:["Range ",k.startLine,"\u2013",k.line,k.startSide&&k.startSide!==k.side?`, starts on ${k.startSide.toLowerCase()}`:""]}):null,k.comments.map(y=>e("div",{class:"gh-comment",children:[e("p",{children:[e("strong",{children:y.author||"Deleted user"}),y.replyTo?" \xB7 reply":""," \xB7 ",new Date(y.createdAt).toLocaleString(),y.url?e(j,{children:[" \xB7 ",e("a",{href:y.url,target:"_blank",rel:"noreferrer",children:"Open comment"})]}):null]}),e("pre",{children:y.body||"(empty comment)"}),y.bodyTruncated?e("p",{class:"help",children:"Comment text shortened or redacted."}):null]},y.id)),k.commentsTruncated?e(j,{children:[e("p",{class:"help",children:["Showing ",k.comments.length," of ",k.totalComments," comments. Resolution requires the complete bounded discussion."]}),e("button",{class:"btn small",disabled:!!d||k.comments.length>=100,onClick:()=>w(k),children:d===k.id?"Loading\u2026":"Load complete thread"}),k.totalComments>100?e("p",{class:"help",children:"Threads over 100 comments must be resolved on GitHub."}):null]}):null,n?null:e("button",{class:"btn small",disabled:!!d||k.commentsTruncated||o.state!=="OPEN"||(k.resolved?!k.canUnresolve:!k.canResolve),onClick:()=>C(k),children:d===k.id?"Updating\u2026":k.resolved?"Reopen thread on GitHub":"Resolve thread on GitHub"})]},k.id)):e("p",{class:"help",children:"No inline review threads."})]}):null,u?e("p",{class:"msg",role:"status",children:u}):null,m?e("p",{class:"msg err",role:"alert",children:m}):null]})}function $d({value:t,onChange:s,disabled:n}){let[a,r]=h([]),[o,i]=h("");_(()=>{let l=!0;return U("/api/remote-workers").then(m=>{l&&r(m)},m=>{l&&i(m.message)}),()=>{l=!1}},[]);let d=a.find(l=>l.id===t?.workerId);return e("div",{"aria-label":"Agent execution location",children:[e("label",{children:["Agent execution",e("select",{"aria-label":"Agent execution",value:t?.workerId??"",disabled:n,onChange:l=>{let m=a.find(c=>c.id===l.currentTarget.value);s(m?{workerId:m.id,repoMapping:m.repoMappings[0]}:void 0)},children:[e("option",{value:"",children:at.value.kind==="local"?"This computer":"This server"}),a.map(l=>e("option",{value:l.id,children:l.name},l.id)),t&&!d?e("option",{value:t.workerId,children:["Unavailable worker: ",t.workerId]}):null]})]}),d?e(j,{children:[e("label",{children:["Worker repository mapping",e("select",{"aria-label":"Worker repository mapping",value:t?.repoMapping,disabled:n,onChange:l=>s({workerId:d.id,repoMapping:l.currentTarget.value}),children:d.repoMappings.map(l=>e("option",{value:l,children:l},l))})]}),e("p",{class:"help",children:["Agents use the worker\u2019s installed CLI and login in a disposable checkout. Exact commits and staged references are transferred over SSH. Native approval prompts and live team tools are unavailable; replies use structured outcomes on the next turn.",d.containerProfile?` Worker container profile: ${d.containerProfile}.`:""]})]}):t?e("p",{class:"msg err",children:"This worker is no longer registered. Choose an available worker before starting."}):null,o?e("p",{class:"msg err",children:["Worker configuration could not be loaded: ",o]}):null]})}function Bk(){let[t,s]=h([]),[n,a]=h("");return _(()=>{let r=!0;return U("/api/remote-workers").then(o=>{r&&s(o)},o=>{r&&a(o.message)}),()=>{r=!1}},[]),e("section",{class:"wb-card remote-workers","aria-label":"Remote workers",children:[e("h2",{children:"Remote workers"}),e("p",{children:"Use an explicitly provisioned SSH host to run agent turns. Each turn receives an exact Git commit, its prompt and bounded staged references. Worker credentials stay on that worker."}),t.length?e("div",{class:"wb-list",children:t.map(r=>e(Rm,{worker:r},r.id))}):e("p",{class:"help",children:"Register worker aliases, commands and repository mappings with CODEFLOW_REMOTE_WORKERS_FILE on the server. Prepare the host\u2019s known-host key and official CLI login separately. See docs/remote-workers.md."}),e("p",{class:"help",children:"A lost connection can leave an ambiguous outcome. Inspect the step\u2019s durable receipt before explicitly retrying. Code-flow never automatically repeats an accepted remote turn. SSH receipt metadata is retained; private recovery capabilities are excluded from backups."}),n?e("p",{class:"msg err",role:"alert",children:n}):null]})}function Id({runId:t,step:s}){let[n,a]=h(),[r,o]=h(!1),[i,d]=h(""),[l,m]=h(!1),c=Q(0),u=`${t}/${s.id}/${s.remote?.requestId??""}`;if(_(()=>(c.current++,a(void 0),d(""),o(!1),m(!1),()=>{c.current++}),[u,s.remote?.state,s.remote?.ambiguous,s.remote?.resultHead]),!s.remote)return null;let p=n?.remote??s.remote,f=["completed","failed","cancelled"].includes(p.state),v=async(g=!1)=>{let w=c.current;o(!0),d(""),m(!1);try{let C=await q(`/api/runs/${encodeURIComponent(t)}/remote-steps/${encodeURIComponent(s.id)}/${g?"cancel":"receipt"}`,{});w===c.current&&a(C)}catch(C){w===c.current&&d(C.message)}finally{w===c.current&&o(!1)}};return e("section",{class:"remote-step-receipt","aria-label":"Remote execution receipt",children:[e("p",{children:[e("strong",{children:["SSH worker ",p.workerId]})," \xB7 ",e("span",{role:"status",children:["Receipt: ",p.state]}),p.recovered?" \xB7 inspected":""]}),e("p",{class:"help",children:["Request ",e("code",{children:p.requestId}),p.resultHead?e(j,{children:[" \xB7 result ",e("code",{children:p.resultHead.slice(0,12)})]}):null]}),p.ambiguous||p.state==="unknown"?e("p",{class:"msg err",children:"The execution outcome is unknown. Inspect or request cancellation before using Resume. Inspection never launches another agent turn."}):null,e("div",{class:"wb-actions",children:[e("button",{class:"btn small",disabled:r,onClick:()=>v(),children:r?"Contacting worker\u2026":"Inspect remote receipt"}),f?null:e("button",{class:"btn small",disabled:r,onClick:()=>m(!0),children:"Cancel remote execution"})]}),l?e("div",{class:"remote-cancel",role:"group","aria-label":"Confirm remote cancellation",children:[e("p",{children:"Request cancellation of this exact worker request? A lost connection can prevent confirmation; an unknown receipt remains unresolved."}),e("button",{class:"btn small",disabled:r,onClick:()=>v(!0),children:"Request cancellation"}),e("button",{class:"btn small",disabled:r,onClick:()=>m(!1),children:"Keep execution"})]}):null,n?.error?e("p",{class:"help",children:n.error}):null,i?e("p",{class:"msg err",role:"alert",children:i}):null]})}function Rm({worker:t}){let[s,n]=h(t.repoMappings[0]??""),[a,r]=h(),[o,i]=h(!1),[d,l]=h(""),m=async()=>{i(!0),l(""),r(void 0);try{r(await q(`/api/remote-workers/${encodeURIComponent(t.id)}/probe`,{repoMapping:s}))}catch(c){l(c.message)}finally{i(!1)}};return e("article",{class:"wb-item worker-probe","aria-label":`Worker ${t.name}`,children:[e("h3",{children:t.name}),e("p",{class:"help",children:["Protocol ",t.protocol,t.containerProfile?` \xB7 Worker container: ${t.containerProfile}`:" \xB7 Worker-local official CLIs"]}),e("div",{class:"wb-row",children:[e("label",{children:["Repository mapping",e("select",{class:"field","aria-label":`Repository mapping for ${t.name}`,value:s,disabled:o,onChange:c=>{n(c.currentTarget.value),r(void 0)},children:t.repoMappings.map(c=>e("option",{value:c,children:c},c))})]}),e("button",{class:"btn",onClick:m,disabled:o,children:o?"Connecting\u2026":"Check worker connection"})]}),a?e("div",{class:"worker-probe-result",role:"status",children:[e("p",{children:a.capabilities.repoMappings.includes(s)?"Repository mapping available":"Repository mapping unavailable"}),e("ul",{children:a.capabilities.providers.map(c=>e("li",{children:[c.id,": ",c.available?"CLI installed":"CLI unavailable"]},c.id))}),e("p",{class:"help",children:["Login is checked when the selected CLI runs. Maximum source/result bundle: ",Math.floor(a.capabilities.maximumBundleBytes/1024/1024)," MiB; staged context: ",Math.floor(a.capabilities.maximumContextBytes/1024/1024)," MiB."]})]}):null,d?e("p",{class:"msg err",role:"alert",children:d}):null]})}var Hr=class{constructor(s=8*1024*1024,n=1e4){this.maxBytes=s;this.maxEvents=n}records=new Map;bytes=0;add(s){if(this.records.has(s.seq))return[];let n=JSON.stringify(s).length*2;this.records.set(s.seq,{event:s,bytes:n}),this.bytes+=n;let a=[];if(this.bytes>this.maxBytes||this.records.size>this.maxEvents){for(let[r,o]of this.records)if(this.records.delete(r),this.bytes-=o.bytes,a.push(o.event),this.bytes<=this.maxBytes*.75&&this.records.size<=this.maxEvents*.75)break}return a}deleteStep(s){for(let[n,a]of this.records)a.event.type==="agent"&&a.event.stepId===s&&(this.records.delete(n),this.bytes-=a.bytes)}};function Ad(t,s){return{...t,steps:new Map(s.steps.map(n=>[n.id,n])),stepSeq:new Map(s.steps.map(n=>[n.id,s.seq])),runSeq:s.seq,seen:new Set([...t.seen].filter(n=>n<=s.seq))}}var si=()=>({pagedTranscript:!0,cache:new Hr,pages:new Map,steps:new Map,events:new Map,built:new Map,logs:[],seen:new Set,runSeq:0,stepSeq:new Map,epoch:""}),Wr=new Map,$m=6;function Ed(t){return ni(t).version.value}function ni(t){let s=Wr.get(t);return s||(s={id:t,data:{current:si()},run:ke(null),problem:ke(""),persistence:ke(null),version:ke(0),users:0,stepListeners:new Set,scheduled:!1,lastSeq:0,idleSince:Date.now()},Wr.set(t,s),jd(s)),s}function Im(t){t.users++||Pd(t)}function Pd(t){t.stop=Ds(`${t.legacy?"run":"run-page"}:${t.id}`,s=>{if(!t.legacy&&s.type==="error"&&s.status===404&&s.message==="Nothing to watch called \u201Crun-page\u201D"){t.stop?.(),t.legacy=!0,t.data.current={...si(),pagedTranscript:!1},t.lastSeq=0,t.users&&Pd(t);return}Md(t,s)},()=>t.data.current.epoch&&t.lastSeq?`${t.data.current.epoch}:${t.lastSeq}`:void 0)}function Am(t){--t.users||(t.stop?.(),t.stop=void 0,t.idleSince=Date.now(),jd())}function jd(t){let s=[...Wr.values()].filter(a=>!a.users&&a!==t).sort((a,r)=>r.idleSince-a.idleSince),n=0;for(let[a,r]of s.entries())n+=r.data.current.cache.bytes*2+JSON.stringify(r.run.value).length*2,(a>=$m||n>32*1024*1024)&&Wr.delete(r.id)}function Md(t,s){if(s.type==="persistence"){t.persistence.value=s.status;return}if(s.type==="error"){t.problem.value=s.status===404?s.message:`Couldn't load this run: ${s.message}`;return}if(s.type==="hello"){if(t.persistence.value=s.persistence??null,(s.epoch!==t.data.current.epoch||!s.resumed)&&(t.data.current={...si(),epoch:s.epoch},t.lastSeq=0),t.data.current.pagedTranscript=!t.legacy,t.problem.value="",s.snapshot){t.data.current=Ad(t.data.current,s.snapshot),t.pending=s.snapshot.run;for(let a of s.snapshot.steps)for(let r of t.stepListeners)r(a);Vr(t)}if(s.transcript){for(let a of s.transcript.events)Md(t,a);t.lastSeq=Math.max(t.lastSeq,s.transcript.latestSeq)}return}let n=t.data.current;if(!n.seen.has(s.seq)){if(n.seen.add(s.seq),n.seen.size>2e4){let a=[...n.seen].slice(0,5e3);for(let r of a)n.seen.delete(r)}if(t.lastSeq=Math.max(t.lastSeq,s.seq),s.type==="run"){if(s.seq<n.runSeq)return;n.runSeq=s.seq,t.pending=s.run}else if(s.type==="step"){if(s.seq<(n.stepSeq.get(s.step.id)??0))return;n.stepSeq.set(s.step.id,s.seq),n.steps.set(s.step.id,s.step);for(let a of t.stepListeners)a(s.step)}else if(s.type==="agent"){let a=n.pages.get(s.stepId);if(a?.historical){a.loading&&ti(t,n.cache.add(s));return}n.events.has(s.stepId)||n.events.set(s.stepId,[]),n.events.get(s.stepId).push(s.event)}else s.type==="log"&&n.logs.push(s);(s.type==="agent"||s.type==="log")&&ti(t,n.cache.add(s)),Vr(t)}}function ti(t,s){let n=t.data.current;for(let a of s)if(a.type==="agent"){let r=n.events.get(a.stepId),o=r?.indexOf(a.event)??-1;o>=0&&r.splice(o,1),n.built.delete(a.stepId);let i=n.pages.get(a.stepId);i&&(i.loaded=!1)}else if(a.type==="log"){let r=n.logs.indexOf(a);r>=0&&n.logs.splice(r,1)}}async function zr(t,s,n){let a=ni(t),r=a.data.current;if(a.legacy)return;let o=r.pages.get(s);if(o?.loading)return;let i={before:o?.before,loading:!0,loaded:o?.loaded??!1,historical:o?.historical??!1,request:(o?.request??0)+1};r.pages.set(s,i),Vr(a);try{let d=await U(`/api/runs/${J(t)}/transcript?step=${J(s)}${n?`&before=${J(n)}`:""}`);if(a.data.current.pages!==r.pages||r.pages.get(s)!==i)return;let l=n?[]:[...r.cache.records.values()].map(m=>m.event).filter(m=>m.type==="agent"&&m.stepId===s&&m.seq>d.latestSeq);r.cache.deleteStep(s),r.events.set(s,[]),r.built.delete(s);for(let m of[...d.events,...l])m.type!=="agent"||m.stepId!==s||(r.events.get(s).push(m.event),ti(a,r.cache.add(m)));Object.assign(i,{before:d.before,loaded:!0,historical:!!n})}catch(d){i.error=d.message,i.historical=o?.historical??!1}finally{i.loading=!1,Vr(a)}}function Vr(t){if(t.scheduled)return;t.scheduled=!0;let s=()=>{t.scheduled&&(t.scheduled=!1,qi(()=>{t.pending&&(t.run.value=t.pending),t.pending=void 0,t.version.value++}))};requestAnimationFrame(s),setTimeout(s,250)}function tn(t,s,n=!0){let a=ni(t),r=Q(s);return r.current=s,_(()=>{let o=i=>r.current?.(i);return a.stepListeners.add(o),()=>void a.stepListeners.delete(o)},[a]),_(()=>{if(n)return Im(a),()=>Am(a)},[a,n]),{run:a.run.value,persistence:a.persistence.value,problem:a.problem.value,data:a.data,version:a.version.value}}var Em={done:"\u2713",failed:"\u2715",cancelled:"\u25A0",interrupted:"\u23F8"},oi=(t,s,n)=>{let a=n??(s?t?.agentSettings?.[s]:void 0);return[a?.model,a?.effort].filter(Boolean).join(" \xB7 ")};function Bd({id:t}){let[s,n]=h(null),[a,r]=h(null),o=Q(!0),i=Q([]),[d,l]=h(!1),[m,c]=h(!1),[u,p]=h(null),[f,v]=h(!1),[g,w]=h(!1),[C,k]=h(""),{run:y,problem:b,data:T,persistence:$}=tn(t,N=>{o.current&&N.status==="running"&&!Wd(N)&&n(N.id)});_(()=>{y&&y.status!=="running"&&!y.seen&&!document.hidden&&sr(y.id)},[y?.status,y?.seen]),_(()=>{kn()},[t]);let x=Kn.value.find(N=>N.runId===t)?.taskId;if(_(()=>{let N=ae=>{if(ae.key!=="["&&ae.key!=="]"||ae.metaKey||ae.ctrlKey||ae.altKey||ae.target?.closest("input, textarea, select, dialog"))return;let ie=i.current;ie.length&&(ae.preventDefault(),o.current=!1,r(!0),n(pe=>{let ge=ie.indexOf(pe??ie.at(-1));return ie[Math.min(ie.length-1,Math.max(0,(ge<0?ie.length-1:ge)+(ae.key==="]"?1:-1)))]}))};return window.addEventListener("keydown",N),()=>window.removeEventListener("keydown",N)},[]),_(()=>{s&&document.querySelector(".tl-step.selected")?.scrollIntoView({block:"nearest"})},[s]),!y)return e("div",{class:"runview",children:e("div",{class:"run-scroll",children:b?e("div",{class:"thread",children:[e("p",{class:"msg err",children:b}),e("p",{children:e("a",{href:"#/",children:"\u2190 Back to a new run"})})]}):e("div",{class:"thread help",children:"Loading\u2026"})})});let E=li(y,T.current.steps.values());i.current=E.map(N=>N.id);let A=s===""?null:s&&i.current.includes(s)?s:E.at(-1)?.id??null,P=y.status!=="running",D=[...T.current.steps.values()].filter(N=>N.status==="running"),S=!P&&D.some(N=>N.kind==="check")&&!D.some(N=>N.kind==="agent"),R=a??!P,M=N=>{o.current=!1,r(!0),n(N)},O=N=>{o.current=!1,n(N===A?"":N)},B=ve.value.find(N=>N.id===y.pattern),ee=ft(y),se=!!y.awaiting||Et(y),te=!!B?.chat,G=Al(y),L=N=>{let ae=document.getElementById(N);ae?.scrollIntoView({block:"center",behavior:"smooth"}),(ae?.querySelector("textarea, button, summary")??ae)?.focus({preventScroll:!0})},Y=async()=>{if(!g){w(!0),k("");try{await q(`/api/runs/${y.id}/resume`)}catch(N){k(N.message)}finally{w(!1)}}},X=()=>{G&&(G.kind==="resume"?Y():G.kind==="provider"?ms.value=!0:G.kind==="check"?v(!0):G.kind==="review"&&G.branch?_e({view:"review",id:y.id,branch:G.branch}):G.kind==="revise"?_s.value=[..._s.value,{to:`main:${y.id}`,text:`Investigate and fix the failing checks (${y.loop.check||"the configured verification profile"}). Preserve the existing work and report fresh verification evidence.`,images:[]}]:L(`run-${G.kind}`))};return e("div",{class:"runview",children:[e("div",{class:"run-scroll",children:[$?.state==="saving"?e("p",{class:"help",role:"status",children:"Saving run\u2026"}):$?.state==="error"?e("p",{class:"msg err",role:"alert",children:["Run changes have not been saved: ",$.error]}):null,y.projectTeam&&e("p",{class:"help",children:["Standing team ",y.projectTeam.phase," \xB7 ",e("a",{href:`#/project/${y.project}`,children:"Review the opportunity, approve this result, or request a bounded team revision"})]}),e("header",{class:"run-head",children:e("div",{class:"run-title",children:[e("div",{class:"run-name",children:[e("div",{class:"run-kicker",children:[e("span",{class:`status-pill ${se?"awaiting":ee}`,children:lr(y)}),e("span",{class:"run-pattern",children:B?.name??y.pattern}),x?e("a",{class:"run-team-task",href:`#/team/task/${J(x)}`,title:"This run executes a task of the team board",children:"Team task"}):null]}),e("h2",{title:y.task,children:y.task.split(`
63
+ `)[0]||"(no task)"})]}),e("div",{class:"run-actions",children:[P?e(nt,{label:"More run actions",icon:"more",children:N=>e(j,{children:[e(me,{onClick:()=>{N();try{let ae={id:`strategy-${Date.now().toString(36)}`,name:y.task.split(`
64
+ `)[0].slice(0,80),scope:y.project?"project":"personal",...y.project?{project:y.project}:{}};p(y.team?tl(y.team,ae):{schemaVersion:1,...ae,version:1,description:"Saved workflow. Parameterize inputs before reuse.",autoEnabled:!1,parameters:["task"],roles:[],tasks:[],contracts:[],workflow:y.pattern,task:"{{task}}",criteria:[]})}catch(ae){V(ae.message)}},children:"Save as team template\u2026"}),y.projectTeam?null:e(me,{disabled:!qt.value||dt.value,onClick:()=>{N(),eh(y)},children:"Edit & run again"}),e(me,{onClick:()=>{N(),y.archived?q(`/api/runs/${y.id}/archive`,{archived:!1}).catch(ae=>V(ae.message)):l(!0)},children:y.archived?"Unarchive":"Archive\u2026"}),y.projectTeam?null:e(me,{onClick:()=>{N(),c(!0)},children:"Delete\u2026"})]})}):null,P?null:e("button",{class:"btn danger",onClick:async()=>{await Ce(S?"Stop the running checks? Finished work stays on its branch; verification will be incomplete.":"Stop this run? Agents still working will be stopped; finished work stays on its branches.",{title:"Stop current work?",confirmLabel:"Stop work",danger:!0})&&q(`/api/runs/${y.id}/cancel`).catch(N=>V(N.message))},children:[e(z,{name:"stop"})," ",S?"Stop checks":"Stop run"]})]})]})}),e("div",{class:"thread",children:[e(Pr,{run:y,checking:S}),y.teamTemplate||y.team?.templateUses?.length?e("details",{class:"settings",children:[e("summary",{children:"Template provenance"}),e("div",{class:"settings-body",children:[y.teamTemplate?e("p",{children:["Selected: ",y.teamTemplate.template.name," v",y.teamTemplate.template.version]}):null,y.team?.templateUses?.map(N=>e("p",{children:[N.id,": ",N.templateId," v",N.version,N.instructions?` \xB7 adaptation: ${N.instructions}`:""]},N.id)),e("p",{class:"help",children:"Definitions and inputs are pinned to this run. Library edits do not change this execution."})]})]}):null,y.permissions?e("details",{class:"settings",children:[e("summary",{children:["Run permissions \xB7 ",y.permissions.trust,y.permissions.antigravityExecution==="native"?" \xB7 Unrestricted Antigravity":""]}),e("div",{class:"settings-body",children:[e("p",{children:y.permissions.antigravityExecution==="native"?"Unrestricted Antigravity uses the existing login and normal provider settings. Its read-only requests are advisory; terminal, browser, MCP, hooks and native agents are unrestricted by Code Flow, including child usage outside the worker budget. Other providers inherit the run policy.":"Workers inherit this run\u2019s policy. Planning and review turns use narrower access. Native agent delegation is disabled; Code Flow schedules the team."}),[...T.current.steps.values()].filter(N=>N.permissions).map(N=>e("p",{children:[N.title,": ",N.permissions.trust," \xB7 ",N.permissions.mode," \xB7 ",N.permissions.isolation," \xB7 command network ",N.permissions.commandNetwork," \xB7 external tools ",N.permissions.externalTools,N.permissions.implementation?e(j,{children:[e("br",{}),e("span",{class:"help",children:[N.permissions.implementation,": ",N.permissions.limitations.join(" ")]})]}):null]},N.id)),e("p",{class:"help",children:"Worktrees do not restrict reads. External browser/MCP tools retain their provider permissions unless explicitly disabled. Setup, checks and previews use their separately configured execution environment."})]})]}):null,G?e("section",{class:`next-action ${["resume","provider","check","revise"].includes(G.kind)?"needs-attention":""}`,"aria-label":"Next action",children:[e("div",{children:[e("h3",{children:G.title}),e("p",{children:G.detail}),G.kind==="resume"?e("p",{class:"help",children:["New allowance: ",y.loop.maxInvocations??y.loop.maxSteps," calls \xB7 ",y.loop.maxMinutes," minutes. Earlier usage is retained."]}):null,P&&y.worktrees.length?e("p",{class:"help",children:["Saved work: ",y.worktrees.length," ",y.worktrees.length===1?"worktree":"worktrees",". Branches and files are kept."]}):null]}),e("div",{class:"next-action-buttons",children:[e("button",{class:"btn primary",disabled:g,onClick:X,children:g?"Resuming\u2026":G.label}),G.kind==="provider"?e("button",{class:"btn",disabled:g,onClick:()=>void Y(),children:"Resume after reconnecting"}):null]})]}):null,C?e("p",{class:"msg err",role:"alert",children:C}):null,P?e(Ml,{run:y}):e(Pl,{run:y,steps:E}),P&&!te?e(Dd,{run:y,steps:E,onSelectStep:M}):null,e(Mm,{run:y}),y.source?.kind==="pr"&&!Object.values(y.prs??{}).includes(y.source.url)?e(ei,{runId:y.id}):null,y.lockdown?e("div",{class:"lockdown",role:"note",children:[e("b",{children:"Locked down."})," ",y.lockdown,", so agents run in Safe mode, files like .env aren't copied in, and checks"," ",y.loop.container?"run in Docker without network":"run on this machine because you allowed it","."]}):null,e("div",{class:"msg-you",children:e("div",{class:"bubble",children:[e("div",{class:"run-task",children:e(Oe,{text:y.task})}),e(jm,{run:y}),y.parentRunId?e("a",{class:"help",href:`#/run/${y.parentRunId}`,children:"\u21A9 continues an earlier run"}):null,y.supersededBy?e("a",{class:"help",href:`#/run/${y.supersededBy}`,children:"Continue with the revised goal \u2192"}):null]})}),y.awaiting?e("div",{id:"run-approval",tabIndex:-1,children:e(Gm,{run:y})}):null,Et(y)?e("div",{id:"run-question",tabIndex:-1,children:e(xd,{run:y})}):null,y.team?e(Sd,{run:y,steps:E}):null,y.team&&y.project?e(ld,{projectId:y.project,repo:y.repo,refreshKey:`${y.status}:${y.team.revision}`}):null,y.triage?.state==="pending"&&y.status!=="running"?e("div",{class:"awaiting-card",id:"run-triage",tabIndex:-1,children:[e("div",{class:"aw-head",children:[e("span",{class:"status-pill awaiting",children:"In your inbox"}),e("b",{children:["From your automation \u201C",y.trigger?.name,"\u201D"]}),e("span",{class:"help",children:"Approving never merges (it can open a pull request); rejecting deletes the worktrees and branches."})]}),e("div",{class:"aw-actions",children:e(ri,{run:y})})]}):null,te?e(ii,{run:y,steps:E,data:T.current}):e("details",{class:`work ${P?"":"live"}`,open:R,children:[e("summary",{onClick:N=>{N.preventDefault(),r(!R)},children:e(Pm,{run:y,steps:E})}),e("div",{class:"steps",role:"list","aria-label":"Steps ([ and ] to move)",children:E.length?E.map(N=>e("div",{role:"listitem",class:`step ${N.id===A?"open":""}`,children:[e("button",{type:"button",class:`tl-step ${N.id===A?"selected":""}`,"aria-expanded":N.id===A,"aria-label":`${N.title}: ${ot[N.status]??N.status}`,onClick:()=>O(N.id),children:[e("span",{class:`ic ${N.status}`,"aria-hidden":"true",children:Em[N.status]??""}),e("span",{class:"tt",children:N.title}),e("span",{class:"tm",children:[e(qd,{step:N}),e("span",{children:(N.kind??"agent")==="agent"?N.role:N.finalText||"running\u2026"}),N.endedAt?e("span",{children:Le(N.endedAt-N.startedAt)}):null,N.usage?e("span",{title:Ud(N.usage),children:[It(N.usage.inputTokens+N.usage.outputTokens)," tok"]}):null,N.retries?e("span",{title:"Retried after a passing failure (overloaded, network)",children:["\u21BB",N.retries]}):null]})]}),N.id===A?e(Jr,{run:y,step:N,data:T.current,version:T.current.events.get(N.id)?.length??0}):null]},N.id)):e("div",{class:"tl-empty",children:"Starting\u2026"})})]}),te?null:e(Dm,{run:y,data:T.current}),P&&te?e(Dd,{run:y,steps:E,onSelectStep:M,chat:!0}):null,e(Zm,{logs:T.current.logs,count:T.current.logs.length})]})]}),e(ui,{run:y,steps:E,chat:te}),f?e(th,{run:y,onClose:()=>v(!1)}):null,u?e(nh,{template:u,onClose:()=>p(null)}):null,m?e(Mr,{run:y,onClose:()=>c(!1)}):null,d?e(Km,{run:y,onClose:()=>l(!1)}):null]})}function Pm({run:t,steps:s}){let n=s.filter(i=>i.status==="running"),a=s.filter(i=>i.status==="failed").length,r=[...new Set(s.map(i=>i.agent).filter(i=>!!i))],o=Le((t.endedAt??Date.now())-t.createdAt);return e(j,{children:[e("span",{class:`work-ic ${ft(t)}`,"aria-hidden":"true"}),e("span",{class:"work-title",children:t.status==="running"?n.length?`Working \u2014 ${n.map(i=>i.title).join(", ")}`:"Working\u2026":`${s.length} step${s.length===1?"":"s"}`}),e("span",{class:"work-meta",children:[t.status==="running"?`${s.length} step${s.length===1?"":"s"} so far \xB7 ${o}`:o,a?e("span",{class:"warn",children:[" \xB7 ",a," failed"]}):null]}),e("span",{class:"work-agents",children:r.map(i=>e($e,{id:i},i))}),e("span",{class:"work-chev","aria-hidden":"true"})]})}function qd({step:t,model:s}){return(t.kind??"agent")==="agent"?e($e,{id:t.agent,note:s}):e("span",{class:"tag-cf",children:t.kind==="check"?"Check":"Setup"})}var Ld=t=>t.charAt(0).toUpperCase()+t.slice(1);function jm({run:t}){let s=t.context??{paths:[],attachments:[]};return!s.paths.length&&!s.attachments.length?null:e("div",{class:"run-chips",children:[s.paths.map(n=>e("span",{class:"chip-ctx",title:n.workingCopy?`Your ${n.note} working copy was given to the agents`:n.path,children:[e(z,{name:n.type==="dir"?"folder":"files"}),e("span",{class:"n",children:[n.path,n.type==="dir"?"/":""]}),n.note?e("span",{class:"note",children:n.note}):null]},n.path)),s.attachments.map(n=>e("span",{class:"chip-ctx",children:[e(z,{name:"attach"}),e("span",{class:"n",children:n.name}),e("span",{class:"size",children:Ht(n.size)})]},n.name))]})}function Mm({run:t}){let s=Object.entries(t.roles).filter(([,n])=>n.length);return e("div",{class:"run-meta",children:[e(Vl,{run:t}),e("span",{title:t.repo,class:"repo-line",children:[e(z,{name:"folder"})," ",be(t.repo)]}),t.trigger?e("a",{class:"src-link with-ic",href:"#/automations",title:`Started by ${t.trigger.via==="schedule"?"its schedule":t.trigger.via==="webhook"?"a webhook":t.trigger.via==="sweep"?"a sweep":"Run now"}`,children:[e(z,{name:t.trigger.via==="sweep"?"layers":"clock"})," ",t.trigger.name]}):null,t.triage&&t.triage.state!=="pending"?e("span",{class:"badge",children:t.triage.state==="empty"?"No changes \xB7 archived":Ld(t.triage.state)}):null,t.source?e("a",{class:"src-link with-ic",href:In(t.source.url),target:"_blank",rel:"noreferrer",title:t.source.title,children:[t.source.kind==="pr"?e(z,{name:"pull"}):null,t.source.kind==="issue"?`Issue #${t.source.number}`:t.source.kind==="pr"?`PR #${t.source.number}`:`\u26A0 ${t.source.alert?.tool==="dependabot"?"Dependabot":"Code scanning"} alert ${(t.source.alert?.numbers??[t.source.number]).map(n=>`#${n}`).join(", ")}`,e(z,{name:"external"})]}):null,e("span",{children:["From ",t.baseLabel," @ ",e("code",{children:t.baseRef.slice(0,7)})]}),t.loop?.check?e("span",{title:"code-flow runs this after every change",children:["Done when ",e("code",{children:t.loop.check})," passes",t.checkCantRun?" \xB7 can't run here":t.lastCheck?t.lastCheck.ok?" \xB7 last check \u2713":" \xB7 last check \u2715":""]}):null,e("span",{class:"team-line",children:s.map(([n,a])=>e("span",{children:[Ld(n),":"," ",a.map((r,o)=>e("span",{children:[o?", ":"",e($e,{id:r,note:oi(t,r)})]},r))]},n))}),t.group?e("a",{class:"src-link with-ic",href:`#/insights/${encodeURIComponent(t.group.id)}`,title:"Started together with other setups on the same task",children:[e(z,{name:"compare"})," Comparison: ",t.group.label]}):null,t.trust==="full"?e("span",{class:"full-access",title:"Agents could run any command, with no sandbox",children:"\u26A0 Full access"}):null,t.conventions?e("span",{class:"with-ic",title:"The repo's AGENTS.md, CLAUDE.md\u2026 are given to every agent",children:[e(z,{name:"files"})," Conventions"]}):null,t.lessons?.length?e("span",{class:"with-ic",title:`Problems reviewers raised in earlier runs here, given to every agent:
65
+ ${t.lessons.map(n=>`\u2022 ${n}`).join(`
66
+ `)}`,children:[e(z,{name:"sparkle"})," ",t.lessons.length," lesson",t.lessons.length===1?"":"s"]}):null,t.usage?e("span",{class:"usage",children:[t.usage.agentSteps,"/",t.loop.maxSteps," agent steps \xB7 ",Le((t.endedAt??Date.now())-t.createdAt)," of ",t.loop.maxMinutes," min",t.usage.inputTokens||t.usage.outputTokens?e("span",{title:Lm(t),children:[" ","\xB7 ",It((t.usage.inputTokens??0)+(t.usage.outputTokens??0))," tokens",t.usage.costUsd?` \xB7 \u2248${ht(t.usage.costUsd)} API-equivalent`:""]}):null]}):null]})}var Ud=t=>`${t.inputTokens.toLocaleString()} input \xB7 ${t.outputTokens.toLocaleString()} output \xB7 ${t.cacheReadTokens.toLocaleString()} cached${t.costUsd?` \xB7 \u2248${ht(t.costUsd)}`:""}`,Lm=t=>Object.entries(t.usage.byAgent??{}).map(([s,n])=>`${s}: ${n.steps} steps, ${It(n.inputTokens+n.outputTokens)} tokens${n.costUsd?`, \u2248${ht(n.costUsd)}`:""}, ${Le(n.ms)}`).join(`
67
+ `);function Dd({run:t,steps:s,onSelectStep:n,chat:a}){let r=ft(t),o=s.filter(l=>l.status==="failed"),i={done:"\u2713 Finished \u2014 the check passes",unverified:"Finished \u2014 no independent check passed",failing:"\u26A0 Finished \u2014 but the check still fails",unchecked:"\u26A0 Finished \u2014 but the check couldn't run, so nothing was tested",failed:"\u2715 Failed",cancelled:"\u25A0 Stopped by you",stopped:Kt(t)?"\u25A0 Paused with unresolved work \u2014 press Resume to continue":`\u25A0 Stopped at the ${t.stopReason??"limit"} \u2014 work so far is kept below`,interrupted:"\u25A0 Interrupted \u2014 press Resume to continue where it stopped"};a&&Object.assign(i,{done:"\u2713 The check passes",unverified:"No independent check passed",failing:"\u26A0 The check fails",unchecked:"\u26A0 The check couldn't run, so nothing was tested"});let d=i[r]??t.status;return e("div",{class:`result ${r}${a?" chat":""}`,children:[d?e("div",{class:"rh",children:d}):null,t.checkCantRun?e(Cr,{cantRun:t.checkCantRun}):null,e(jr,{run:t}),o.length&&t.status!=="done"?e("div",{class:"failures",children:[e("div",{class:"lbl",children:"What went wrong"}),o.slice(-5).map(l=>e("button",{type:"button",class:"failure",onClick:()=>n(l.id),children:[e("span",{class:"ic failed","aria-hidden":"true",children:"\u2715"}),e("b",{children:l.title})," ",e(qd,{step:l}),e("span",{class:"fe",children:(l.error??l.finalText??"").split(`
68
+ `)[0].slice(0,200)})]},l.id))]}):null,t.error?e("div",{class:"rb",children:e("div",{class:"ev error",children:t.error})}):t.review?e(Om,{run:t}):t.summary&&!a?e("div",{class:"rb",children:e(Oe,{text:t.summary})}):null,t.artifacts.length?e("div",{class:"artifacts",children:t.artifacts.map(l=>e(ci,{run:t,artifact:l,steps:s},l.branch+l.label))}):null]})}function Dm({run:t,data:s}){return t.followUps?.length?e(j,{children:t.followUps.map(n=>{if(n.side)return n.side.mode==="change"&&n.status!=="pending"?e(Fd,{run:t,f:n},n.id):null;let a=n.stepId?s.steps.get(n.stepId):void 0;return e("div",{class:"fu",children:[n.kind==="reply"||n.kind==="comments"&&!n.from?e("div",{class:"msg-you",children:e("div",{class:"bubble",children:e(Oe,{text:n.message})})}):e("div",{class:"fu-sent help",children:[n.kind==="resolve-conflicts"?`Sent ${n.mergeFrom}'s merge conflicts to`:n.kind==="ci-fix"?"Sent the pull request's failing CI to":`Sent ${n.from}'s comments to`," ",e($e,{id:n.agent})]}),e("div",{class:`fu-answer ${n.status}`,children:[e("div",{class:"fu-head",children:[e($e,{id:n.agent}),e("span",{children:[Nm(n)," in ",n.worktree]}),e(sa,{f:n,run:t})]}),a?e(Kr,{run:t,step:a,data:s,answer:n.status==="pending"?void 0:n.result}):n.result?e(Oe,{text:n.result}):null]})]},n.id)})}):null}function Fd({run:t,f:s}){return e("div",{class:"fu-sent help side-note",children:[e($e,{id:s.agent})," ",s.status==="done"?"changed":"tried to change"," ",s.worktree," from the side chat"," ",e("button",{type:"button",class:"link",onClick:()=>cl(t.id,s.side.chat),children:["\u201C",s.side.title,"\u201D"]}),e(sa,{f:s})]})}function sa({f:t,run:s}){let n=t.status==="pending"&&!!s&&s.status!=="running"&&s.status!=="done";return e(j,{children:[n?s.status==="interrupted"?e("span",{class:"note",title:"code-flow stopped before this turn finished. Resume the run to continue it.",children:"Interrupted"}):e("span",{class:"err",children:"\u2715 Didn't finish"}):t.status==="pending"?e("span",{class:"fu-live",children:"Working\u2026"}):t.status==="failed"?e("span",{class:"err",children:"\u2715 Didn't finish"}):null,t.pushed?e("span",{class:"ok",children:["Pushed ",t.pushed.slice(0,7)]}):t.pushError?e("span",{class:"note",title:t.pushError,children:["Push failed: ",t.pushError]}):null,t.checkPassed===!1?e("span",{class:"note",children:"check fails"}):t.checkPassed?e("span",{class:"ok",children:"check passes"}):null,t.integrity?.length?e("span",{class:"note",title:t.integrity.map(a=>`${a.file}: ${a.detail}`).join(`
69
+ `),children:"\u26A0 Changed tests"}):null]})}function Kr({run:t,step:s,data:n,answer:a}){let[r,o]=h(!1),i=n.events.get(s.id)?.length??0;if(s.status==="running")return e(Jr,{run:t,step:s,data:n,version:i});let d=Gd(n,s).filter(m=>m.kind==="tool").length,l=a??(s.status==="done"?s.finalText:s.error??s.finalText);return e("div",{class:"turn-body",children:[e("button",{type:"button",class:"show-work","aria-expanded":r,onClick:()=>o(!r),children:[r?"Hide work":`Show work${d?` \xB7 ${d} tool call${d===1?"":"s"}`:""}`,s.endedAt?` \xB7 ${Le(s.endedAt-s.startedAt)}`:""]}),r?e(Jr,{run:t,step:s,data:n,version:i}):null,l?s.status==="done"?e(Oe,{text:l}):e("div",{class:"ev error",children:l}):null]})}function ii({run:t,steps:s,data:n}){let a=t.followUps.filter(p=>!p.side),r=new Map(a.filter(p=>p.stepId).map(p=>[p.stepId,p])),o=Hd(t),i=s.filter(p=>(p.kind??"agent")==="agent"&&!o.has(p.id)),d=a.filter(p=>!p.stepId||!n.steps.has(p.stepId)),l=t.followUps.filter(p=>p.side?.mode==="change"&&p.status!=="pending"),m=[...i.map(p=>({at:p.startedAt,step:p})),...d.map(p=>({at:p.at,followUp:p})),...l.map(p=>({at:p.stepId&&n.steps.get(p.stepId)?.startedAt||p.at,side:p}))].sort((p,f)=>p.at-f.at),c=a.length===0&&!t.followUps.some(p=>p.side?.mode==="change"&&!!p.stepId),u=Object.values(t.roles).flat()[0];return e(j,{children:[m.map(({step:p,followUp:f,side:v})=>{if(v)return e(Fd,{run:t,f:v},v.id);if(!p){let C=f;return e("div",{class:"fu",children:[e("div",{class:"msg-you",children:e("div",{class:"bubble",children:e(Oe,{text:C.message})})}),e("div",{class:"fu-answer",children:[e("div",{class:"fu-head",children:[e($e,{id:C.agent}),C.status==="pending"&&(t.status==="running"||t.status==="done")?e("span",{class:"fu-live",children:t.status==="running"?"Up next\u2026":"Waiting\u2026"}):e(sa,{f:C,run:t})]}),C.status==="pending"||!C.result?null:C.status==="failed"?e("div",{class:"ev error",children:C.result}):e(Oe,{text:C.result})]})]},C.id)}let g=r.get(p.id),w=t.notes.filter(C=>C.deliveredTo?.stepId===p.id&&!C.followUp);return e("div",{class:"fu",children:[g?e("div",{class:"msg-you",children:e("div",{class:"bubble",children:e(Oe,{text:g.message})})}):null,w.map(C=>e("div",{class:"msg-you",children:e("div",{class:"bubble",children:[e(Oe,{text:C.text}),C.deliveredTo?.midTurn?e("div",{class:"help",children:"Sent while it worked"}):null]})},C.id)),e("div",{class:"fu-answer",children:[e("div",{class:"fu-head",children:[e($e,{id:p.agent,note:oi(t,p.agent,p.settings)}),g?e(sa,{f:g,run:t}):p.status==="running"?e("span",{class:"fu-live",children:"Working\u2026"}):p.status==="failed"?e("span",{class:"err",children:"\u2715 Didn't finish"}):null,!g&&p.status!=="running"&&t.lastCheck&&c?t.lastCheck.ok?e("span",{class:"ok",children:"check passes"}):e("span",{class:"note",children:"check fails"}):null]}),e(Kr,{run:t,step:p,data:n})]})]},p.id)}),t.status==="running"?s.filter(p=>p.kind==="check"&&p.status==="running").map(p=>{let f=n.events.get(p.id)?.find(v=>v.kind==="tool_call"&&v.name==="$");return e("details",{class:"chat-check",children:[e("summary",{children:[e("span",{class:"spin","aria-hidden":"true"}),e("span",{children:[e("strong",{children:"Running checks"}),e("span",{class:"help",children:i.every(v=>v.status!=="running")?"The agent has finished. Verification is still running.":"Verifying the work."}),e("code",{children:f?.kind==="tool_call"?f.input:t.loop.check||p.title})]}),e("span",{class:"help",children:"Show output"})]}),e(Jr,{run:t,step:p,data:n,version:n.events.get(p.id)?.length??0})]},p.id)}):null,!i.length&&t.status==="running"?e("div",{class:"fu-answer",children:e("div",{class:"fu-head",children:[e($e,{id:u}),e("span",{class:"fu-live",children:"Starting\u2026"})]})}):null]})}var Hd=t=>new Set(t.followUps.filter(s=>s.side&&s.stepId).map(s=>s.stepId)),Wd=t=>!!t.sideOf||t.role==="side chat"||/^Check after side chat /.test(t.title);function li(t,s){let n=Hd(t);return[...s].filter(a=>!n.has(a.id)&&!Wd(a))}var Nm=t=>t.side?"side chat":t.kind==="resolve-conflicts"?`resolve conflicts with ${t.mergeFrom}`:t.kind==="reply"?"your reply":t.kind==="ci-fix"?"fix failing CI":t.from?`comments from ${t.from}`:"review comments";function Om({run:t}){let s=t.review,[n,a]=h(!1),r=t.source?.kind==="pr"?t.source:void 0;return e("div",{class:"rb council",children:[e("div",{class:"council-head",children:[e("span",{class:`badge ${s.verdict==="approve"?"ok":"warn"}`,children:s.verdict==="approve"?"Approve":"Changes requested"}),e("span",{class:"help",children:s.reviewers.map((o,i)=>e("span",{children:[i?" \xB7 ":"",e($e,{id:o.agent})," ",o.verdict==="approve"?"approves":`${o.issues} issue${o.issues===1?"":"s"}`]},o.agent))}),e("span",{class:"spacer"}),r?s.postedTo?e("a",{class:"badge ok",href:In(s.postedTo),target:"_blank",rel:"noreferrer",children:["Posted to PR #",r.number," ",e(z,{name:"external"})]}):e("button",{class:"btn small primary",disabled:n||t.status==="running",onClick:async()=>{if(await Ce(`Post this review as a comment on PR #${r.number}? Everyone with access to the PR will see it.`,{title:"Post review to GitHub?",confirmLabel:"Post review",danger:!1})){a(!0);try{await q(`/api/runs/${t.id}/post-review`),V("Review posted")}catch(o){V(o.message,5e3)}finally{a(!1)}}},children:n?"Posting\u2026":`Post to PR #${r.number}`}):null,e("button",{class:"btn small",onClick:()=>Ot(s.markdown,"Review copied as Markdown"),children:"Copy"})]}),s.proof?e(Vd,{proof:s.proof}):null,s.summary?e("p",{children:s.summary}):null,s.findings.length?e("ol",{class:"findings",children:s.findings.map((o,i)=>e("li",{class:`sev-${o.severity}`,children:[e("div",{children:[e("span",{class:`sev ${o.severity}`,children:o.severity})," ",e("code",{children:o.file||"general"})," ",o.problem]}),e("div",{class:"help",children:["Fix: ",o.fix]}),e(zd,{severity:o.severity,check:o.check}),e("div",{class:"raised",children:[o.raisedBy.length>1?e("b",{children:[o.raisedBy.length," reviewers agree \xB7 "]}):null,o.raisedBy.map(d=>e($e,{id:d},d))]})]},i))}):e("p",{class:"help",children:"No problems found."})]})}function ci({run:t,artifact:s,steps:n,reviewing:a=!1}){let[r,o]=h(null),i=(t.worktrees??[]).find(f=>f.branch===s.branch),d=t.merges?.filter(f=>f.branch===s.branch)??[],l=t.prs?.[s.branch],m=(t.status==="done"||Kt(t))&&!!i,c=t.source?.kind==="pr"?t.source:void 0,[u,p]=h(!1);return e("div",{class:"artifact",children:[e("div",{class:"ah",children:[e("b",{children:s.label}),e("code",{children:s.branch}),d.map(f=>e("span",{class:"badge ok",children:[f.pr?"PR merged into":"Merged into"," ",f.into]},f.commit)),l?e("a",{class:"badge",href:In(l),target:"_blank",rel:"noreferrer",children:["PR ",e(z,{name:"external"})]}):null,e("span",{class:"acts",children:[m&&!a?e("button",{class:"btn small",onClick:()=>_e({view:"review",id:t.id,branch:s.branch}),children:"Review changes"}):null,i?e("button",{class:"btn small","aria-pressed":r==="merge",onClick:()=>o(r==="merge"?null:"merge"),children:l?"Merge PR\u2026":"Merge\u2026"}):null,i&&c&&!c.isCrossRepository&&t.status!=="running"?e("button",{class:"btn small primary",disabled:u,title:`Push this branch to ${c.headRefName}, updating PR #${c.number} (never forced)`,onClick:async()=>{if(await Ce(`Push ${s.branch} to ${c.headRefName}? This updates PR #${c.number} on GitHub.`,{title:"Push changes to GitHub?",confirmLabel:"Push changes",danger:!1})){p(!0);try{await q(`/api/runs/${t.id}/push-pr`,{branch:s.branch}),V(`Pushed to PR #${c.number}`)}catch(f){V(f.message,6e3)}finally{p(!1)}}},children:u?"Pushing\u2026":`Push to PR #${c.number}`}):null,i&&!c?e("button",{class:"btn small","aria-pressed":r==="pr",onClick:()=>o(r==="pr"?null:"pr"),children:"Open PR\u2026"}):null,e("button",{class:"btn small",onClick:()=>Ot(`git diff ${t.baseRef.slice(0,12)}...${s.branch}`,"Diff command copied"),children:"Copy diff cmd"}),e("button",{class:"btn small",onClick:()=>Ot(s.path,"Path copied"),children:"Copy path"})]})]}),t.integrity?.[s.branch]?.length?e(_m,{issues:t.integrity[s.branch]}):null,t.proofs?.[s.branch]?e(Vd,{proof:t.proofs[s.branch]}):null,t.findings?.[s.branch]?.findings.length?e(Bm,{review:t.findings[s.branch]}):null,a?null:s.stat?e("pre",{tabIndex:0,children:s.stat}):e("div",{class:"help",children:"No changes"}),!a&&i&&zm(t)?e(Jm,{run:t,worktree:i.name}):null,r==="merge"&&i?l?e(Wm,{run:t,branch:s.branch,worktree:i.name,steps:n}):e(Kd,{run:t,branch:s.branch,worktree:i.name,steps:n}):null,r==="pr"?e(Vm,{run:t,branch:s.branch}):null,l?e(ei,{runId:t.id,branch:s.branch}):null,l&&i&&!d.some(f=>f.pr===l)?e(Um,{run:t,branch:s.branch,steps:n,worktree:i.name}):null]})}function _m({issues:t}){return e("div",{class:"integrity",role:"note",children:[e("b",{children:"\u26A0 Changes to tests to check before merging"}),e("span",{class:"help",children:" \u2014 they can make the check pass without a real fix."}),e("ul",{children:t.map((s,n)=>e("li",{children:[e("span",{class:`sev ${s.severity}`,children:s.severity})," ",s.file?e("code",{children:s.file}):null," ",s.detail]},n))})]})}function Vd({proof:t}){let s=t.tests.length?`this change's tests (${t.tests.join(", ")})`:"the existing tests";return e("div",{class:`proof ${t.status}`,role:"note",children:t.status==="proven"?e(j,{children:[e("b",{children:"\u2713 Proven: a test fails without this change"}),e("span",{class:"help",children:[" ","\u2014 ",e("code",{children:t.command})," fails on the base code with ",s,", and passes with the change."]}),e("details",{children:[e("summary",{children:"How it fails without the change"}),e("pre",{children:t.detail})]})]}):t.status==="weak"?e(j,{children:[e("b",{children:"\u26A0 Weak proof: the tests fail without this change only because they can't load"}),e("span",{class:"help",children:[" ","\u2014 ",e("code",{children:t.command})," fails on the base code with ",s,", but on an import or build error, not on what the tests check. Check a test covers the behaviour before merging."]}),e("details",{children:[e("summary",{children:"How it fails without the change"}),e("pre",{children:t.detail})]})]}):t.status==="unproven"?e(j,{children:[e("b",{children:"\u26A0 Not proven: no test fails without this change"}),e("span",{class:"help",children:[" ","\u2014 ",e("code",{children:t.command})," passes on the base code too, with ",s,". Check the change is tested before merging."]})]}):e(j,{children:[e("b",{children:"Couldn't prove a test fails without this change"}),e("span",{class:"help",children:[" \u2014 ",t.detail,"."]})]})})}function Bm({review:t}){let s=t.findings.filter(n=>n.blocking).length;return e("div",{class:`review-findings${s&&!t.stale?" blocking":""}`,role:"note",children:[e("b",{children:t.stale?"Review outdated \u2014 the result changed after this review":s?`\u26A0 ${s} review finding${s===1?" blocks":"s block"} approval`:"\u2713 No review finding blocks approval"}),e("span",{class:"help",children:[" ","\u2014 ",e($e,{id:t.reviewer})," ",t.round>1?`round ${t.round}`:"review",". High and medium findings block; a high one (a bug) only when its test fails."]}),e("ol",{class:"findings",children:t.findings.map((n,a)=>e("li",{class:`sev-${n.severity}`,children:[e("div",{children:[e("span",{class:`sev ${n.severity}`,children:n.severity})," ",e("code",{children:n.file||"general"})," ",n.problem," ",t.stale?e("span",{class:"help",children:"Historical finding"}):n.blocking?e("span",{class:"badge warn",children:"Blocks"}):n.severity==="low"?e("span",{class:"help",children:"Suggestion"}):null]}),n.fix?e("div",{class:"help",children:["Fix: ",n.fix]}):null,e(zd,{severity:n.severity,check:n.check})]},a))})]})}function zd({severity:t,check:s}){if(!s)return null;let n=s.path?e("code",{children:s.path}):"test";return s.status==="confirmed"?e("div",{class:"finding-check confirmed",children:[e("b",{children:"\u2713 Confirmed"}),e("span",{class:"help",children:[" ","\u2014 the reviewer's ",n," fails with ",e("code",{children:s.command}),"."]}),e("details",{children:[e("summary",{children:"How it fails"}),e("pre",{children:s.detail})]}),s.contents?e("details",{children:[e("summary",{children:"The reviewer's test"}),e("pre",{children:s.contents})]}):null]}):s.status==="refuted"?e("div",{class:"finding-check refuted",children:[e("b",{children:"\u2717 Not confirmed"}),e("span",{class:"help",children:[" ","\u2014 the reviewer's ",n," passes with ",e("code",{children:s.command}),": a false alarm."]})]}):t==="low"?null:s.status==="unverified"?e("div",{class:"finding-check unverified",children:[e("b",{children:"Couldn't run the reviewer's test"}),e("span",{class:"help",children:[" \u2014 ",s.detail,"."]})]}):e("div",{class:"finding-check unconfirmed",children:[e("b",{children:t==="high"?"\u26A0 Unconfirmed":"Not shown by a test"}),e("span",{class:"help",children:[" \u2014 ",s.detail,"."]})]})}var qm={watching:"Watching",fixing:"Fixing",green:"CI green","needs-you":"Needs you",closed:"PR closed",stopped:"Not watching"};function Um({run:t,branch:s,steps:n,worktree:a}){let r=t.watches?.[s],o=r&&["watching","fixing","green"].includes(r.state),[i,d]=h(r?.agent??Jd(n,a)??"claude"),[l,m]=h(r?.maxFixes??3),[c,u]=h((r?.allow??[]).map(f=>`@${f}`).join(", ")),p=f=>q(`/api/runs/${t.id}/watch`,{branch:s,...f}).catch(v=>V(v.message,5e3));return e("div",{class:`watch ${r?.state??"off"}`,children:[r?e("div",{class:"row",children:[e("span",{class:`badge ${r.state==="green"?"ok":r.state==="needs-you"?"warn":""}`,children:qm[r.state]}),e("span",{class:"detail",children:r.detail}),r.checks?e("span",{class:"help",children:["CI: ",r.checks.pass," \u2713 \xB7 ",r.checks.fail," \u2715",r.checks.pending?` \xB7 ${r.checks.pending} running`:""]}):null,e("span",{class:"help",children:[r.fixes,"/",r.maxFixes," fixes",r.lastPolled?` \xB7 checked ${new Date(r.lastPolled).toLocaleTimeString()}`:"",` \xB7 acts on comments from you${r.allow?.length?`, ${r.allow.map(f=>`@${f}`).join(", ")}`:""}`]}),e("span",{class:"spacer"}),o?e("button",{class:"btn small",onClick:()=>p({stop:!0}),children:"Stop watching"}):null]}):null,!o&&r?.state!=="closed"?e("div",{class:"row",children:[e("span",{class:"lbl",children:"Follow through"}),e("span",{children:"When CI fails or you comment,"}),e(Gr,{value:i,onChange:d,label:"Agent that fixes CI failures and comments"}),e("span",{children:"fixes it and pushes \u2014 up to"}),e("input",{class:"field inline num",type:"number",min:1,max:10,value:l,"aria-label":"Most fixes",onInput:f=>m(Number(f.currentTarget.value)||3)}),e("span",{children:"times. Never merges."}),e("button",{class:"btn small primary",onClick:()=>p({agent:i,maxFixes:l,allow:c.split(/[\s,]+/).map(f=>f.replace(/^@/,"")).filter(Boolean)}),children:r?"Watch again":"Watch PR"})]}):null,!o&&r?.state!=="closed"?e("div",{class:"row",children:[e("span",{class:"help",children:"Also act on comments from"}),e("input",{class:"field inline",placeholder:"@teammate, @reviewer",value:c,"aria-label":"Other GitHub users whose comments the agent acts on",onInput:f=>u(f.currentTarget.value)}),e("span",{class:"help",children:"\u2014 nobody else's, since these fixes are pushed without anyone reviewing them first."})]}):null]})}function Fm(t){let[s,n]=h(null);_(()=>{U(`/api/branches?repo=${encodeURIComponent(t.repo)}`).then(n,()=>n(null))},[t.repo]);let a=(s?.branches??[]).filter(o=>o.kind==="local").map(o=>o.name),r=t.baseLabel!=="HEAD"&&a.includes(t.baseLabel)?t.baseLabel:s?.current??a[0]??"";return{branches:a,initial:r}}var Jd=(t,s)=>[...t].reverse().find(n=>(n.kind??"agent")==="agent"&&n.worktree===s&&n.mode==="write")?.agent;function Kd({run:t,branch:s,worktree:n,steps:a}){let{branches:r,initial:o}=Fm(t),[i,d]=h(""),[l,m]=h(!0),[c,u]=h(!1),[p,f]=h(null),[v,g]=h(!!t.loop.verification),[w,C]=h(null),[k,y]=h(Jd(a,n)??"claude"),b=i||o,T=w?.branch===s&&w.into===b&&w.report?.state==="verified"&&!w.conflicts.length,$=async(E=!1)=>{u(!0),C(null);try{C(await q(`/api/runs/${t.id}/validate-merge`,{branch:s,into:b,allowUntrusted:E}))}catch(A){if(A instanceof Ge&&A.confirm==="allowUntrusted"&&await Ce(`${A.message}
70
+
71
+ Run validation on this computer?`,{title:"Run validation locally?",confirmLabel:"Run validation",danger:!0})){u(!1),await $(!0);return}V(A.message,5e3)}finally{u(!1)}},x=async()=>{u(!0),f(null);try{let E=await q(`/api/runs/${t.id}/merge`,{branch:s,into:b,archiveAfter:l,requireValidation:v});E.ok?V(`Merged into ${b}${l?" and archived the run":""}`,3e3):f(E.conflicts)}catch(E){V(E.message,5e3)}finally{u(!1)}};return e("div",{class:"ship-panel",children:[e("div",{class:"row",children:[e("label",{class:"lbl",children:"Merge into"}),e("select",{class:"field",value:b,onChange:E=>d(E.currentTarget.value),children:r.map(E=>e("option",{value:E,children:E},E))}),e("label",{class:"check",children:[e("input",{type:"checkbox",checked:l,onChange:E=>m(E.currentTarget.checked)})," Archive the run afterwards (removes its worktrees, keeps branches)"]}),e("button",{class:"btn primary small",disabled:c||!b||v&&!T,onClick:x,children:c?"Merging\u2026":`Merge into ${b||"\u2026"}`})]}),t.loop.check||t.loop.verification?e("div",{class:"row",children:[e("label",{class:"check",children:[e("input",{type:"checkbox",checked:v,onChange:E=>g(E.currentTarget.checked)})," Require verification of the current merge target"]}),e("button",{class:"btn small",disabled:c||!b,onClick:()=>$(),children:"Validate merge result"}),w?.into===b?e("span",{role:"status",class:"help",children:[w.conflicts.length?`Conflicts: ${w.conflicts.join(", ")}`:`Merge verification: ${w.report?.state??"unchecked"}`," \xB7 target ",w.target.slice(0,12),w.report?` \xB7 ${w.report.checks.length} gates`:""]}):null]}):null,e("div",{class:"help",children:["If ",b||"the branch"," is checked out, code-flow merges there only when it has no uncommitted changes, and aborts cleanly on conflicts."]}),p?e("div",{class:"conflicts",children:[e("div",{class:"msg warn",children:["Merging would conflict in ",p.length," file",p.length===1?"":"s",": ",p.join(", ")]}),e("div",{class:"row",children:[e("span",{children:"Ask"}),e(Gr,{value:k,onChange:y}),e("span",{children:["to merge ",b," into this branch and resolve them, then merge again."]}),e("button",{class:"btn small",onClick:()=>q(`/api/runs/${t.id}/followups`,{kind:"resolve-conflicts",worktree:n,agent:k,mergeFrom:b}).then(()=>V("Sent \u2014 the agent is resolving the conflicts"),E=>V(E.message,5e3)),children:"Ask to resolve"})]})]}):null]})}var Nd={merge:"Create a merge commit",squash:"Squash and merge",rebase:"Rebase and merge"},Hm={pass:"CI passing",fail:"CI failing",pending:"CI still running",none:"no CI checks"};function Wm({run:t,branch:s,worktree:n,steps:a}){let[r,o]=h(null),[i,d]=h(""),[l,m]=h(""),[c,u]=h(!0),[p,f]=h(!1),[v,g]=h(!1);_(()=>{U(`/api/runs/${t.id}/pr-merge?branch=${encodeURIComponent(s)}`).then(o,b=>d(b.message))},[t.id,s]);let w=l||r?.methods[0]||"merge",C=r?`PR #${r.number}`:"the PR",k=r?.state==="OPEN",y=async()=>{if(!(!r||!await Ce(`${Nd[w]}: merge ${C} into ${r.baseRefName} on GitHub?`,{title:"Merge pull request?",confirmLabel:"Merge pull request",danger:!0}))){f(!0);try{let b=await q(`/api/runs/${t.id}/merge-pr`,{branch:s,method:w,archiveAfter:c});b.merged?V(`${b.already?`${C} was already merged`:`Merged ${C}`} into ${b.into} on GitHub${c?" and archived the run":""}`,4e3):V(`GitHub accepted the merge; ${C} merges once the repository's requirements are met`,6e3),o({...r,state:b.merged?"MERGED":r.state})}catch(b){V(b.message,6e3)}finally{f(!1)}}};return e(j,{children:[e("div",{class:"ship-panel",children:[e("div",{class:"row",children:[e("label",{class:"lbl",children:"Merge pull request"}),r?e("a",{href:In(r.url),target:"_blank",rel:"noreferrer",children:["#",r.number," into ",r.baseRefName," ",e(z,{name:"external"})]}):e("span",{class:"help",children:i?"\u2014":"Asking GitHub\u2026"}),k?e(j,{children:[e("select",{class:"field",value:w,"aria-label":"How to merge",onChange:b=>m(b.currentTarget.value),children:r.methods.map(b=>e("option",{value:b,children:Nd[b]},b))}),e("label",{class:"check",children:[e("input",{type:"checkbox",checked:c,onChange:b=>u(b.currentTarget.checked)})," Archive the run afterwards (removes its worktrees, keeps branches)"]}),e("button",{class:"btn primary small",disabled:p||r.isDraft,onClick:y,children:p?"Merging\u2026":`Merge ${C}`})]}):null]}),i?e("div",{class:"msg err",children:i}):null,r?.state==="MERGED"?e("div",{class:"msg",children:[C," is merged into ",r.baseRefName,"."]}):null,r?.state==="CLOSED"?e("div",{class:"msg warn",children:[C," is closed. Reopen it on GitHub to merge it."]}):null,k&&r.isDraft?e("div",{class:"msg warn",children:[C," is a draft. Mark it ready for review on GitHub, then merge."]}):null,k&&r.mergeable==="CONFLICTING"?e("div",{class:"msg warn",children:["GitHub says ",C," conflicts with ",r.baseRefName,": merge ",r.baseRefName," into the branch and resolve them first."]}):null,k?e("div",{class:"help",children:[Hm[r.ci],". code-flow merges it on GitHub only while it's exactly the branch you reviewed here, and deletes no branches."," ",e("button",{class:"linkish",onClick:()=>g(!v),children:v?"Hide local merge":"Merge into a local branch instead\u2026"})]}):null]}),v||i?e(Kd,{run:t,branch:s,worktree:n,steps:a}):null]})}function Vm({run:t,branch:s}){let[n,a]=h(null),[r,o]=h("");_(()=>{U(`/api/runs/${t.id}/pr-targets`).then(a,u=>o(u.message))},[t.id]);let[i,d]=h(""),[l,m]=h(!1),c=i||n?.initial||"";return e("div",{class:"ship-panel",children:[e("div",{class:"row",children:[e("label",{class:"lbl",children:"Pull request into"}),e("select",{class:"field",value:c,disabled:!n,onChange:u=>d(u.currentTarget.value),children:[n?null:e("option",{value:"",children:r?"\u2014":"Asking GitHub\u2026"}),(n?.branches??[]).filter(u=>u!==s).map(u=>e("option",{value:u,children:u},u))]}),e("button",{class:"btn primary small",disabled:l||!c,onClick:async()=>{m(!0);try{let{url:u}=await q(`/api/runs/${t.id}/pr`,{branch:s,into:c});V("Pull request opened",3e3),window.open(u,"_blank","noreferrer")}catch(u){V(u.message,6e3)}finally{m(!1)}},children:l?"Opening\u2026":"Push & open PR"})]}),r?e("div",{class:"msg warn",children:r}):null,e("div",{class:"help",children:["This pushes ",e("code",{children:s})," to ",e("code",{children:"origin"})," and opens a pull request with GitHub CLI (",e("code",{children:"gh"}),"), using the run's task and summary as the description."]})]})}var zm=t=>!t.archived;function Od(t){let n=Nn.value.pages??[],a=n.find(o=>o.url===t),r=a?.id??`p${Date.now().toString(36)}`;Hs({pages:a?n:[...n,{id:r,url:t}],page:r}),gt("browser")}function Jm({run:t,worktree:s}){let n=`/api/runs/${t.id}/worktrees/${encodeURIComponent(s)}`,[a,r]=h(null),[o,i]=h(!1),[d,l]=h(t.app?.command??"");Ee(p=>U(n+"/serve").then(f=>p()&&r(f),()=>{}),2e3,[n]);let m=p=>q(`${n}/open`,{target:p}).then(f=>V(`Opened in ${f.openedWith}${bs?" on your computer":""}`),f=>V(f.message,5e3)),c=async()=>{try{let p=await q(n+"/serve",{command:d});r(p),bs||Od(p.url)}catch(p){if(!(p instanceof Ge)||p.confirm!=="allowUntrusted")return V(p.message,5e3);if(!await Ce(`${p.message}
72
+
73
+ Run it on this computer anyway?`,{title:"Run repository code locally?",confirmLabel:"Run app",danger:!0}))return;await q(n+"/serve",{command:d,allowUntrusted:!0}).then(r,f=>V(f.message,5e3))}},u=a&&bs?a.url.replace("//localhost:",`//${location.hostname}:`):a?.url;return e("div",{class:"ws-tools",children:[e("span",{class:"lbl",children:bs?"On your computer":"Try it"}),e("button",{class:"btn small",onClick:()=>m("terminal"),children:"Terminal"}),e("button",{class:"btn small",onClick:()=>m("editor"),children:"Editor"}),e("button",{class:"btn small",onClick:()=>m("finder"),children:"Folder"}),a?.status==="running"?e(j,{children:[e("a",{class:"btn small primary",href:In(u),target:"_blank",rel:"noreferrer",title:bs?"Opens only if the app listens on your network too (e.g. vite --host)":void 0,children:["Open ",u.replace("http://","")," ",e(z,{name:"external"})]}),bs?null:e("button",{class:"btn small",title:"Show it in the side panel's Browser, where you can annotate it",onClick:()=>Od(a.url),children:"Show in panel"}),e("button",{class:"btn small",onClick:()=>i(!o),children:o?"Hide logs":"Logs"}),e("button",{class:"btn small danger",onClick:()=>U(n+"/serve",{method:"DELETE"}).then(()=>r(null)),children:"Stop app"})]}):e(j,{children:[e("input",{class:"field inline mono",placeholder:"npm run dev",value:d,onInput:p=>l(p.currentTarget.value),title:"How to start the app; it gets a free port in $PORT"}),e("button",{class:"btn small",disabled:!d.trim(),onClick:()=>void c(),children:"Run app"}),a?.status==="exited"?e("span",{class:"msg warn",children:["exited (",a.exitCode,")"]}):null]}),o&&a?e("pre",{class:"serve-logs",children:a.logs.slice(-80).join(`
74
+ `)||"(no output yet)"}):null]})}function Gr({value:t,onChange:s,label:n="Agent"}){return e("select",{class:"field inline","aria-label":n,value:t,onChange:a=>s(a.currentTarget.value),children:Be.value.filter(a=>a.available).map(a=>e("option",{value:a.id,children:a.displayName},a.id))})}function Km({run:t,onClose:s}){let[n,a]=h(!0),[r,o]=h(!1),i=we(!0,s);return e("dialog",{class:"picker small-dialog",ref:i,"aria-labelledby":"archive-title",children:e("div",{class:"picker-inner",children:[e("div",{class:"picker-head",children:e("h3",{id:"archive-title",children:"Archive this run"})}),e("div",{class:"dialog-body",children:[e("label",{class:"check",children:[e("input",{type:"checkbox",checked:n,onChange:d=>a(d.currentTarget.checked)})," Remove its ",(t.worktrees??[]).length," worktree",(t.worktrees??[]).length===1?"":"s"," (uncommitted changes in them are lost)"]}),e("label",{class:"check",children:[e("input",{type:"checkbox",checked:r,disabled:!n,onChange:d=>o(d.currentTarget.checked)})," Also delete its branches",t.merges?.length?"":" (nothing from this run has been merged yet)"]}),e("div",{class:"help",children:"Kept branches can be resumed or merged later; Resume re-attaches them."})]}),e("div",{class:"picker-foot",children:[e("span",{class:"ps"}),e("button",{class:"btn",onClick:s,children:"Cancel"}),e("button",{class:"btn primary",onClick:()=>q(`/api/runs/${t.id}/archive`,{cleanup:n,deleteBranches:r}).then(()=>{V("Archived"),s()},d=>V(d.message,5e3)),children:"Archive"})]})]})})}function Gm({run:t}){let[s,n]=h(""),[a,r]=h(!1),o=async d=>{if(!(d==="reject"&&!await Ce("Reject and end the run? Nothing will be built.",{title:"Reject this plan?",confirmLabel:"Reject plan",danger:!0}))){r(!0);try{await q(`/api/runs/${t.id}/answer`,{decision:d,note:s}),n("")}catch(l){V(l.message,4e3)}finally{r(!1)}}},i=t.awaiting;return e("div",{class:"awaiting-card",children:[e("div",{class:"aw-head",children:[e("span",{class:"status-pill awaiting",children:"Waiting for you"}),e("b",{children:i.title}),e("span",{class:"help",children:"The run is paused, and so is its time budget."})]}),e("div",{class:"aw-body",children:e(Oe,{text:i.content})}),e("div",{class:"aw-actions",children:[e("textarea",{class:"field",rows:2,placeholder:"What should change? (needed for \u201CAsk for changes\u201D, optional otherwise)",value:s,onInput:d=>n(d.currentTarget.value)}),e("div",{class:"row",children:[e("button",{class:"btn primary",disabled:a,onClick:()=>o("approve"),children:"\u2713 Approve"}),e("button",{class:"btn",disabled:a||!s.trim()||!!t.teamRerun,onClick:()=>o("revise"),title:t.teamRerun?"Reject this pinned rerun and create another selection to change its tasks or instructions":s.trim()?"":"Write what should change first",children:"Ask for changes"}),e("button",{class:"btn danger",disabled:a,onClick:()=>o("reject"),children:"Reject"})]})]})]})}function Ym(t,s){let n=s.find(a=>a.id===t.deliveredTo?.stepId);return n?t.deliveredTo?.midTurn?` mid-turn (${n.title})`:` (${n.title})`:""}function di({images:t,onRemove:s}){return t.length?e("div",{class:"draft-images",children:t.map((n,a)=>e("span",{class:"draft-img",title:n.name,children:[e("img",{src:`data:image/png;base64,${n.data}`,alt:n.name}),e("span",{class:"di-name",children:n.name}),e("button",{type:"button",class:"icon-btn","aria-label":`Don't send ${n.name}`,onClick:()=>s(a),children:e(z,{name:"close"})})]},a))}):null}function ui({run:t,steps:s,chat:n}){let[a,r]=h(""),[o,i]=h(""),[d,l]=h(!1),[m,c]=h({}),[u,p]=h(null),[f,v]=h(!1),[g,w]=h(t.loop.maxInvocations??t.loop.maxSteps),[C,k]=h(t.loop.maxMinutes),[y,b]=h([]),T=Q(null),$=t.status==="running"||t.status==="done";_(()=>{if(!$)return;let H=Mn(`main:${t.id}`);H.length&&(r(Ae=>[Ae.trim(),...H.map(Re=>Re.text)].filter(Boolean).join(`
75
+
76
+ `)),b(Ae=>[...Ae,...H.flatMap(Re=>Re.images)]),T.current?.focus())},[_s.value,t.id,$]),_(()=>{let H=T.current;H&&(H.style.height="auto",H.scrollHeight&&(H.style.height=`${Math.min(H.scrollHeight,220)}px`))},[a]);let x=t.followUps.filter(H=>H.status==="pending"),E=t.status==="running"&&!!t.patternDone&&x.length>0&&x.every(H=>H.side),A=t.artifacts[0]?.branch,P=E&&!!A&&x.some(H=>H.side?.mode==="change"&&t.worktrees.find(Ae=>Ae.name===H.worktree)?.branch===A),D=t.status==="running"&&!E,S=[...new Map(s.filter(H=>(H.kind??"agent")==="agent"&&H.mode==="write"&&H.agent&&H.worktree).map(H=>[`${H.agent}@${H.worktree}`,H])).values()],R=[...new Set(Object.values(t.roles).flat())],M=t.team?.members.find(H=>H.role==="coordinator"),O=t.pattern==="solo"?t.roles.agent?.[0]:void 0,B=O?S.find(H=>H.agent===O):void 0,ee=!D&&B?`${O}@${B.worktree}`:D?M&&M.status!=="retired"?`member:${M.id}`:"":t.team?"team":S.at(-1)?`${S.at(-1).agent}@${S.at(-1).worktree}`:"team",se=D?t.team?t.team.members.filter(H=>H.status!=="retired").map(H=>`member:${H.id}`):R:["team",...S.map(H=>`${H.agent}@${H.worktree}`)],te=o&&se.includes(o)?o:ee,G=te.includes("@")?te.split("@")[0]:void 0,L=O??G,Y=t.followUps.filter(H=>!H.side&&H.agent===L).at(-1),X=L?m[L]??Y?.settings??t.agentSettings[L]??{}:{},N=u??{trust:Y?.trust??t.trust,tools:Y?.tools??!!t.approvals.tools},ae=te.startsWith("member:")?te.slice(7):void 0,ie=t.team?.members.find(H=>H.id===ae),pe=sl(!!t.team,D,te),ge=Number.isInteger(g)&&g>=pe&&g<=200&&Number.isFinite(C)&&C>=1&&C<=720;if(!D&&!E&&t.status!=="done")return null;let Ie=async()=>{if(!(!a.trim()||f||!D&&!ge)){v(!0);try{let H=y.map(({name:Ae,data:Re})=>({name:Ae,data:Re}));if(D){let Ae=await q(`/api/runs/${t.id}/notes`,{text:a,agent:ae?void 0:te||void 0,memberId:ae});y.length?V("Sent. The snapshots stay here: they go with a reply once the run has finished",6e3):Ae.deliveredTo?.midTurn?V(`Sent into ${Ae.deliveredTo.agent}'s running turn`):V(te?`Queued for ${ie?.name??te}'s next turn`:"Queued for the next agent's turn"),r("");return}else if(te==="team"){if(P){V("Wait for the side chat to finish: a new run would start without its change",6e3);return}let Ae=t.artifacts[0]?.branch??t.baseLabel,{id:Re}=await q("/api/runs",{repo:t.repo,task:`${t.task}
77
+
78
+ ## Feedback on the previous attempt
79
+ ${a.trim()}`,pattern:t.pattern,roles:t.roles,options:t.options,baseRef:Ae==="HEAD"?"":Ae,context:{paths:(t.context?.paths??[]).map(F=>({path:F.path})),attachments:H},agentSettings:t.agentSettings,roleSettings:t.roleSettings,trust:t.trust,project:t.project,loop:{...t.loop,maxSteps:g,maxInvocations:g,maxMinutes:C},approvals:t.approvals,parentRunId:t.id});_e({view:"run",id:Re})}else{let[Ae,Re]=te.split("@"),F=L??Ae;await q(`/api/runs/${t.id}/followups`,{kind:"reply",agent:F,settings:X,trust:N.trust,tools:N.tools,worktree:Re,message:a,attachments:H,budget:{maxSteps:g,maxInvocations:g,maxMinutes:C}}),V(E?"Queued: it goes once the side chat is done":"Sent \u2014 the agent is on it")}r(""),b([])}catch(H){V(H.message,5e3)}finally{v(!1)}}},xe=async()=>{if(!(!D||!t.team||!a.trim()||f||!ge)){v(!0);try{let{id:H}=await q(`/api/runs/${t.id}/revise-goal`,{message:a.trim(),budget:{maxSteps:g,maxInvocations:g,maxMinutes:C}});r(""),_e({view:"run",id:H})}catch(H){V(H.message,5e3)}finally{v(!1)}}},[We,Ve]=te.split("@"),I=ie?.name??De[We]??We,re=De[O??S.at(-1)?.agent??R[0]]??"the agent",oe=n?D?`Goes into ${re}'s running turn if it takes messages, otherwise it's sent as soon as the turn ends`:te==="team"?P?"Starts again from this result: wait for the side chat to finish first":"Starts again from this result":`Continues ${re}'s session on its branch${E?", once the side chat is done":""}`:D?te?ae?`Sent to ${I}'s next turn`:`Steered into ${I}'s running turn if it takes messages, otherwise its next turn`:"Goes to the next agent that takes a turn":te==="team"?`${t.team?"Builds a revised team and plan from this result, with your approval settings":"Starts a new run with the same team, from this result"}${P?": wait for the side chat to finish first":""}`:`Continues ${I}'s session on its branch, in ${Ve}${E?", once the side chat is done":""}`,he=n?`Message ${re}\u2026`:D?"Message the team\u2026":te==="team"?"Tell the team what to change\u2026":`Reply to ${I}\u2026`,le=new Set(s.filter(H=>H.status==="running").map(H=>H.id)),ce=(t.notes??[]).filter(H=>!n||H.status==="queued"||H.deliveredTo&&le.has(H.deliveredTo.stepId)&&!H.followUp);return e("div",{class:"convo",children:e("div",{class:"convo-inner",children:[d?e(sh,{run:t,onClose:()=>l(!1)}):null,ge?null:e("p",{class:"msg err",role:"alert",children:["Send is off until the budget below allows ",pe,"\u2013200 calls and 1\u2013720 minutes."]}),!D||t.team?e("details",{class:"followup-budget",children:[e("summary",{children:[D?"Goal revision budget":"New execution budget"," \xB7 ",g," calls \xB7 ",C," min"]}),e("div",{class:"at-row",children:[e("label",{children:["Maximum calls",e("input",{class:"field","aria-label":"Follow-up maximum calls",type:"number",min:pe,max:200,value:g,onInput:H=>w(Number(H.currentTarget.value))})]}),e("label",{children:["Maximum minutes",e("input",{class:"field","aria-label":"Follow-up maximum minutes",type:"number",min:1,max:720,value:C,onInput:H=>k(Number(H.currentTarget.value))})]})]}),e("p",{class:"help",children:[E?"A reply queued behind a side chat joins the running execution's allowance; this budget applies when a reply starts a new execution. ":"This is a new allocation. ","The result branch, project memory and applicable context are retained. Earlier spend remains in lifetime usage."]}),ge?null:e("p",{class:"msg err",children:["Choose ",pe,"\u2013200 calls and 1\u2013720 minutes."]})]}):null,D&&ce.length?e("div",{class:"notes",children:ce.map(H=>e("span",{class:`chip-ctx note-chip ${H.status}`,title:H.text,children:e("span",{class:"n",children:[H.followUp?"\u2713 Sent as your next message":H.requestId?"\u2713 Answered the team's question":H.status==="delivered"?`\u2713 Delivered to ${t.team?.members.find(Ae=>Ae.id===H.memberId)?.name??H.deliveredTo?.agent??"the team"}${Ym(H,s)}`:n?"Sent when this turn ends":`Queued for ${t.team?.members.find(Ae=>Ae.id===H.memberId)?.name??H.agent??"next agent"}`,": ",H.text]})},H.id))}):null,e(di,{images:y,onRemove:H=>b(y.filter((Ae,Re)=>Re!==H))}),e("div",{class:"chatbox",children:[e("textarea",{ref:T,rows:1,"aria-label":D?"Message the team":"Reply",placeholder:he,value:a,onInput:H=>r(H.currentTarget.value),onKeyDown:H=>{H.key==="Enter"&&!H.shiftKey&&!H.isComposing&&(H.preventDefault(),Ie())}}),e("div",{class:"chatbox-bar chatbox-configurable",children:[n?null:e("label",{class:"to",children:[e("span",{class:"to-lbl",children:"To"}),e("select",{"aria-label":"Who gets this",value:te,onChange:H=>i(H.currentTarget.value),children:D?e(j,{children:t.team?t.team.members.filter(H=>H.status!=="retired").map(H=>e("option",{value:`member:${H.id}`,children:[H.name," \xB7 ",H.id," (",De[H.provider],")"]},H.id)):e(j,{children:[e("option",{value:"",children:"Next agent"}),R.map(H=>e("option",{value:H,children:De[H]??H},H))]})}):e(j,{children:[S.length?e("optgroup",{label:"Continue a session",children:S.map(H=>e("option",{value:`${H.agent}@${H.worktree}`,children:[De[H.agent]??H.agent," \xB7 ",H.worktree]},`${H.agent}@${H.worktree}`))}):null,e("optgroup",{label:"Start again",children:e("option",{value:"team",disabled:P,children:["Whole team \xB7 new run",P?" (once the side chat is done)":""]})})]})})]}),!D&&te!=="team"&&L?e(Qs,{agent:L,settings:X,onSettings:H=>c({...m,[L]:H}),permissions:N,onPermissions:p,restricted:!!t.lockdown||!!t.trigger,approvalsAvailable:!t.loop.remoteWorker&&!t.loop.agentContainer}):null,t.pattern==="solo"?e(nt,{label:"Chat actions",icon:"more",class:"chat-choice chat-action-menu",above:!0,align:"end",children:H=>e(me,{disabled:D||E||f,sub:D||E?"Available when this chat finishes":"Carry this conversation into a separate chat",onClick:()=>{H(),l(!0)},children:"Start new chat with another provider\u2026"})}):null,e("span",{class:"chatbox-hint",title:oe,children:oe}),e("button",{class:"send","aria-label":"Send",title:"Send (\u21B5 \u2014 \u21E7\u21B5 for a new line)",disabled:f||!a.trim()||!D&&!ge,onClick:Ie,children:e(z,{name:"send"})})]})]}),D&&t.team&&!t.awaiting?e("div",{class:"goal-revision-action",children:[e("button",{class:"btn small",disabled:f||!a.trim()||!ge,onClick:xe,children:"Revise goal"}),e("span",{class:"help",children:"Uses this message to stop the current execution and build a new team plan from integrated work, with your approval settings. Send keeps it as a member note."})]}):null]})})}var Ma=200;function Jr({run:t,step:s,data:n}){Ed(t.id);let a=Q(null),r=Q(!0),[o,i]=h(Ma),d=s?n.pages?.get(s.id):void 0;if(_(()=>{s&&n.pagedTranscript&&!n.pages.get(s.id)?.loaded&&zr(t.id,s.id)},[t.id,s?.id,n.pages,n.pagedTranscript]),_(()=>i(Ma),[s?.id]),_(()=>{r.current&&a.current&&(a.current.scrollTop=a.current.scrollHeight)}),!s)return null;let l=Gd(n,s),m=Math.max(0,l.length-o),c=oi(t,s.agent,s.settings);return e("div",{class:"transcript",role:"group","aria-label":`Transcript of ${s.title}`,children:[s.remote?e(Id,{runId:t.id,step:s},`${t.id}/${s.id}`):null,e("div",{class:"tr-head",children:[d?e("span",{class:"row",children:[e("button",{class:"btn small",disabled:d.loading||!d.before,onClick:()=>{i(Ma),zr(t.id,s.id,d.before)},children:"Earlier events"}),e("button",{class:"btn small",disabled:d.loading,onClick:()=>{i(Ma),zr(t.id,s.id)},children:"Latest events"}),d.loading?e("span",{role:"status",children:"Loading transcript\u2026"}):null,d.historical?e("span",{children:"Viewing earlier events"}):null,d.error?e("span",{role:"alert",children:d.error}):null]}):null,c?e("span",{children:c}):null,e("span",{children:(s.kind??"agent")==="agent"?s.mode==="write"?"can edit files":"read-only":"run by code-flow"}),e("span",{children:["worktree ",s.worktree]}),s.usage?e("span",{title:Ud(s.usage),children:[It(s.usage.inputTokens+s.usage.outputTokens)," tokens",s.usage.costUsd?` \xB7 \u2248${ht(s.usage.costUsd)}`:""]}):null,s.contextInput?e("span",{title:`Measured assembled invocation input. Excludes: ${s.contextInput.excluded.join(", ")}. Input hash ${s.contextInput.hash}`,children:[s.contextInput.bytes.toLocaleString()," input bytes \xB7 \u2248",s.contextInput.approximateTokens.toLocaleString()," input tokens",s.contextInput.exceeded?` \xB7 ${s.contextInput.policy==="block"?"blocked":"budget warning"}`:"",s.contextInput.resumed?" \xB7 earlier history excluded":""]}):null,s.status!=="done"?e("span",{class:`status-pill ${s.status}`,children:ot[s.status]??s.status}):null]}),e("div",{class:"tr-body",ref:a,onScroll:u=>{let p=u.currentTarget;r.current=p.scrollHeight-p.scrollTop-p.clientHeight<60},children:[m?e("button",{type:"button",class:"btn small show-earlier",disabled:o>=1e3,title:o>=1e3?n.pagedTranscript?"Use Earlier events to read more history in bounded pages":"Update the remote server to browse more history in bounded pages":void 0,onClick:()=>{r.current=!1,i(Math.min(1e3,o+Ma*5))},children:["Show earlier (",m.toLocaleString()," hidden)"]}):null,l.slice(m).map((u,p)=>e(ai,{item:u,v:u.v},m+p)),l.length?null:e("div",{class:"ev status",children:s.status==="running"?"Starting\u2026":"Nothing was recorded for this step."})]})]})}var ai=class extends Zt{shouldComponentUpdate(s){return s.item!==this.props.item||s.v!==this.props.v}render(){let{item:s}=this.props;switch(s.kind){case"text":return e("div",{class:"ev text",children:e(Oe,{text:s.text})});case"thinking":return e("details",{class:"ev thinking",children:[e("summary",{children:["Thinking ",e("span",{class:"peek",children:s.text.replace(/\s+/g," ").slice(0,120)})]}),e("div",{class:"think-body",children:s.text})]});case"tool":return e("details",{class:`ev tool ${s.isError?"err":""}`,children:[e("summary",{children:[e("b",{children:s.name})," ",e("span",{class:"arg",children:Qm(s.input)}),s.isError?e("span",{class:"sr-only",children:" (failed)"}):null]}),e("pre",{children:s.input}),s.output!==void 0?e("pre",{children:s.output||"(no output)"}):null]});case"status":return e("div",{class:"ev status",children:s.text});case"error":return e("div",{class:"ev error",role:"alert",children:s.text})}}};function Qm(t){let s=t;try{let n=JSON.parse(t),a=["command","cmd","file_path","filePath","path","pattern","url","query","description"].find(r=>typeof n[r]=="string"&&n[r]);a&&(s=n[a],(a==="file_path"||a==="filePath"||a==="path")&&(s=s.replace(/^.*\/\.worktrees\/[^/]+\/[^/]+\//,"")))}catch{}return s.replace(/\s+/g," ").slice(0,200)}function Gd(t,s){let n=t.events.get(s.id)??[],a=t.built.get(s.id);for(a||(a={items:[],tools:new Map,count:0},t.built.set(s.id,a));a.count<n.length;a.count++)Xm(a,n[a.count],s.agent==="agy"||s.agent?.startsWith("acp:")===!0);return a.items}function Xm(t,s,n){let{items:a,tools:r}=t,o=a.at(-1);switch(s.kind){case"text":n&&o?.kind==="text"&&o.text.length+s.text.length<=32*1024?(o.text+=s.text,o.v++):a.push({kind:"text",text:s.text,v:0});break;case"thinking":n&&o?.kind==="thinking"&&o.text.length+s.text.length<=32*1024?(o.text+=s.text,o.v++):a.push({kind:"thinking",text:s.text,v:0});break;case"tool_call":{let i=r.get(s.callId);if(i){i.name=s.name,i.input=s.input,i.v++;break}let d={kind:"tool",name:s.name,input:s.input,v:0};r.set(s.callId,d),a.push(d);break}case"tool_result":{let i=r.get(s.callId);i||(i={kind:"tool",name:"Tool result (call in an earlier page)",input:"",v:0},r.set(s.callId,i),a.push(i)),i&&(i.output=s.output,i.isError=s.isError,i.v++);break}case"status":a.push({kind:"status",text:s.text,v:0});break;case"error":a.push({kind:"error",text:s.message,v:0});break;case"usage":{let i=[s.inputTokens&&`${s.inputTokens.toLocaleString()} in`,s.outputTokens&&`${s.outputTokens.toLocaleString()} out`,s.cacheReadTokens&&`${s.cacheReadTokens.toLocaleString()} cached`,s.costUsd&&`\u2248${ht(s.costUsd)}`].filter(Boolean);i.length&&a.push({kind:"status",text:`tokens: ${i.join(" \xB7 ")}`,v:0});break}}}function Zm({logs:t}){let[s,n]=h(!1),a=s?t:t.slice(-300),r=t.filter(o=>o.level==="warn").length;return e("details",{class:"activity",children:[e("summary",{children:e("span",{children:["Activity log (",t.length,")",r?e("span",{class:"warn",children:[" \xB7 ",r," warning",r===1?"":"s"]}):null]})}),e("div",{class:"log",children:[a.length<t.length?e("button",{type:"button",class:"linkish",onClick:()=>n(!0),children:["Show all ",t.length.toLocaleString()," lines"]}):null,a.map((o,i)=>e("div",{class:o.level,children:[new Date(o.ts).toLocaleTimeString()," ",o.text]},i))]})]})}var _d=0;async function eh(t){if(t.projectTeam){V("Use the project mission's revision controls to revise this result.",4e3),t.project&&_e({view:"project",id:t.project,section:"automation",kind:"missions"});return}let s=++_d,n=Z.value,a=Xe(t);if(await st(a?.id??"",{repository:t.repo,stay:!0})&&!(s!==_d||Z.value!==n||ne.value!==t.repo)){Ls.value=structuredClone({id:t.id,repo:t.repo,loop:t.loop,approvals:t.approvals??{},source:t.source}),fa.value={remoteWorker:t.loop.remoteWorker,container:{enabled:!!t.loop.agentContainer,image:t.loop.agentContainer?.image??"",authVolume:t.loop.agentContainer?.authVolume??""},verification:t.loop.verification?"restored":"",verificationProfile:t.loop.verification??null,toolApprovals:t.approvals?.tools===!0,antigravityExecution:t.permissions?.antigravityExecution,permissionRequirements:[...t.permissions?.required??[]]},At.value=t.intent,_t.value=void 0,yt.value=null,ps([]),pn.value="",Fe.value=t.baseRef??"",mn(t.trust??"standard"),Ya(t.approvals?.plan===!0,t.pattern),Ue.value=structuredClone(t.agentSettings??{}),lt.value={...lt.value,[t.pattern]:structuredClone(t.roleSettings??{})},En(t.loop.contextBudget,"Original run"),bt(t.pattern);for(let[r,o]of Object.entries(t.roles))Lt(t.pattern,r,o);ho.value={...ho.value,[t.pattern]:structuredClone(t.options??{})},St(t.task),vt.value=new Map((t.context?.paths??[]).map(r=>[r.path,{path:r.path,type:r.type}])),et.value=[],t.context?.attachments?.length&&V("Attached files aren't kept \u2014 attach them again if needed",4e3),jt.value=t.loop?.check??"",Yt.value=t.loop?.setup??"",ul({maxMinutes:t.loop?.maxMinutes??60,maxSteps:t.loop?.maxSteps??40,maxTokens:t.loop.maxTokens,maxCostUsd:t.loop.maxCostUsd}),tt.value=t.source?{kind:t.source.kind,number:t.source.number,title:t.source.title,url:t.source.url,headRefName:t.source.headRefName,baseRefName:t.source.baseRefName,isCrossRepository:t.source.isCrossRepository,ciLogs:!!t.source.ci,tool:t.source.alert?.tool,numbers:t.source.alert?.numbers}:null,_e({view:"composer",project:a?.id??""})}}function th({run:t,onClose:s}){let[n,a]=h(t.loop.check??""),[r,o]=h(t.loop.setup??""),[i,d]=h(!1),[l,m]=h(""),c=we(!0,()=>{i||s()}),u=t.artifacts.filter(v=>t.worktrees.some(g=>g.branch===v.branch)),[p,f]=h(u[0]?.branch??t.baseRef);return e("dialog",{ref:c,class:"picker small-dialog","aria-labelledby":"recovery-check-title",children:e("div",{class:"picker-inner",children:[e("div",{class:"picker-head",children:e("h3",{id:"recovery-check-title",children:"Fix check command"})}),e("div",{class:"dialog-body",children:[e("p",{children:"Start a continuation from the saved branch with corrected commands. The original run and its evidence are kept."}),e("label",{children:["Continue from",e("select",{class:"field",value:p,onChange:v=>f(v.currentTarget.value),children:u.length?u.map(v=>e("option",{value:v.branch,children:[v.label," \xB7 ",v.branch]},v.branch)):e("option",{value:t.baseRef,children:["Original base \xB7 ",t.baseRef.slice(0,12)]})})]}),e("label",{children:["Setup command",e("input",{class:"field",value:r,placeholder:"e.g. npm ci",onInput:v=>o(v.currentTarget.value)})]}),e("label",{children:["Check command",e("input",{class:"field",value:n,placeholder:"e.g. npm test",onInput:v=>a(v.currentTarget.value)})]}),e("p",{class:"help",children:["Uses a single check and this run's team and permissions. New allowance: ",t.loop.maxInvocations??t.loop.maxSteps," calls \xB7 ",t.loop.maxMinutes," minutes."]}),l?e("p",{class:"msg err",role:"alert",children:l}):null]}),e("div",{class:"picker-foot",children:[e("button",{class:"btn",disabled:i,onClick:s,children:"Cancel"}),e("button",{class:"btn primary",disabled:i||!n.trim(),onClick:async()=>{if(!i){d(!0),m("");try{let v=await q("/api/runs",{repo:t.repo,project:t.project,parentRunId:t.id,baseRef:p,task:`${t.task}
80
+
81
+ Verify the preserved work using the corrected setup and check commands. Fix any remaining failures and report the evidence.`,pattern:t.pattern,roles:t.roles,options:t.options,agentSettings:t.agentSettings,roleSettings:t.roleSettings,trust:t.trust,approvals:t.approvals,context:{paths:(t.context?.paths??[]).map(g=>({path:g.path}))},loop:{...t.loop,verification:void 0,check:n.trim(),setup:r.trim()}});s(),_e({view:"run",id:v.id})}catch(v){m(v.message)}finally{d(!1)}}},children:i?"Starting\u2026":"Start continuation"})]})]})})}function sh({run:t,onClose:s}){let n=Be.value.filter(g=>g.id!==t.roles.agent?.[0]),[a,r]=h(n.find(g=>g.available)?.id??n[0]?.id??"codex"),[o,i]=h({}),[d,l]=h(""),[m,c]=h(!1),[u,p]=h(""),f=we(!0,()=>{m||s()}),v=async()=>{if(!m){c(!0),p("");try{let g=await q(`/api/runs/${t.id}/provider-chat`,{agent:a,settings:o,message:d});s(),_e({view:"run",id:g.id})}catch(g){p(g.message),c(!1)}}};return e("dialog",{class:"picker small-dialog",ref:f,"aria-labelledby":"provider-chat-title",children:e("div",{class:"picker-inner",children:[e("div",{class:"picker-head",children:e("h3",{id:"provider-chat-title",children:"New chat with another provider"})}),e("div",{class:"dialog-body",children:[e("p",{class:"help",children:"Carries over this conversation, saved context files, and committed code into a new worktree on the same computer. The original chat stays intact. Tool logs and private provider sessions are not transferred."}),e("fieldset",{disabled:m,style:{border:0,padding:0,margin:0},children:[e(Qs,{agent:a,onAgent:g=>{r(g),i({})},providers:n,settings:o,onSettings:i,permissions:{trust:t.trust,tools:!1},onPermissions:()=>{},showPermissions:!1}),e("label",{children:["First message ",e("span",{class:"help",children:"Optional"}),e("textarea",{class:"field",rows:3,maxLength:2e4,value:d,onInput:g=>l(g.currentTarget.value),placeholder:"What should the new chat do?"})]})]}),e("p",{class:"help",children:"Without a message, the new provider reads the context and waits for your next request. Existing permission limits are retained."}),u?e("p",{class:"msg err",role:"alert",children:u}):null]}),e("div",{class:"picker-foot",children:[e("span",{class:"ps"}),e("button",{class:"btn",disabled:m,onClick:s,children:"Cancel"}),e("button",{class:"btn primary",disabled:m||!n.some(g=>g.id===a&&g.available),onClick:()=>void v(),children:m?"Starting\u2026":"Start new chat"})]})]})})}function nh({template:t,onClose:s}){let n=we(!0,s);return e("dialog",{ref:n,class:"picker","aria-labelledby":"save-strategy-title",children:e("div",{class:"picker-inner",children:[e("div",{class:"picker-head",children:e("h3",{id:"save-strategy-title",children:"Save reusable team strategy"})}),e("div",{class:"dialog-body",children:[e("p",{children:"Review and parameterize the instructions below, removing any sensitive or task-specific values. Session handles, result records, and permission grants are excluded."}),e(ur,{initial:t})]}),e("div",{class:"picker-foot",children:e("button",{class:"btn",onClick:s,children:"Close"})})]})})}var ah=()=>new Set(ve.value.filter(t=>t.chat).map(t=>t.id));function pi(t){let s=new Map;for(let n of t.followUps){if(!n.side)continue;let a=s.get(n.side.chat)??{key:`side:${n.side.chat}`,chat:n.side.chat,title:n.side.title,turns:[],agent:n.agent,mode:n.side.mode};a.turns.push(n),a.agent=n.agent,a.mode=n.side.mode,s.set(n.side.chat,a)}return[...s.values()]}function rh(t,s,n){let a=t?pi(t).find(o=>o.chat===n):void 0;if(a)return{run:t,chat:a};let r=pi(s).find(o=>o.chat===n);return r?{run:s,chat:r}:void 0}var Qd=t=>(t.status==="done"||t.status==="running")&&!!ar(t),oh=t=>{let s={failed:"failed",cancelled:"was cancelled",stopped:"stopped at a limit",interrupted:"was interrupted"};return s[t.status]?`This run ${s[t.status]}, so a side chat can't work in its worktree.`:"This run has no result worktree for a side chat to work in yet."},Yd=t=>t.turns.filter(s=>s.status!=="pending").length;function Xd(){let t=de.get("sideAgent");return t&&Be.value.some(s=>s.id===t&&s.available)?t:Be.value.find(s=>s.available)?.id??"claude"}function Zd(){let t=Fs.value,s=Nn.value,n=ah(),a=t.run,r=[...Ne.value.values()].filter(b=>n.has(b.pattern)&&!b.archived&&b.id!==a?.id).sort((b,T)=>T.createdAt-b.createdAt),o=a?r.filter(b=>b.parentRunId===a.id):[],i=r.filter(b=>!o.includes(b)&&(t.project?Xe(b)?.id===t.project.id:!!t.repo&&b.repo===t.repo)),d=a?pi(a):[],l=new Set(s.closed??[]),m=t.project?.name??(t.repo?be(t.repo):""),c=il.value??"",u=c.startsWith("side:")?d.find(b=>b.key===c):void 0,p=!u&&c&&c!=="solo"?Ne.value.get(c):void 0,f=u?.key??(p&&n.has(p.pattern)?p.id:void 0),g=[...s.chats??[],...f&&!u&&!s.chats?.includes(f)?[f]:[]].map(b=>Ne.value.get(b)).filter(b=>!!b&&n.has(b.pattern)),w=u?Yd(u):0;_(()=>{u&&(s.seen?.[u.key]??0)<w&&Hs({seen:{...s.seen,[u.key]:w}})},[u?.key,w]);let C=[...d.filter(b=>!l.has(b.key)).map(b=>{let T=b.turns.at(-1),$=T.status==="pending";return{key:b.key,label:b.title,title:`${b.title}
82
+ ${De[b.agent]??b.agent} \xB7 side chat in this run's worktree`,agent:b.agent,state:$?T.stepId&&a?.status==="running"?"working":"queued":T.status==="failed"?"failed":Yd(b)>(s.seen?.[b.key]??0)&&b.key!==f?"unread":void 0}}),...g.map(b=>({key:b.id,label:b.task.split(`
83
+ `)[0].slice(0,60)||"(no task)",title:`${b.task.split(`
84
+ `)[0]}
85
+ A chat on its own branch`,agent:Object.values(b.roles).flat()[0],state:b.status==="running"?"working":!b.seen&&b.id!==f?"unread":ft(b)==="failed"?"failed":void 0}))],k=b=>{let T=C.filter(x=>x.key!==b),$=b===f?T.at(-1)?.key??"":c;b.startsWith("side:")?Hs({closed:[...s.closed??[],b],chat:$}):Hs({chats:(s.chats??[]).filter(x=>x!==b),chat:$})},y=(b,T,$,x)=>e(me,{on:b===f,sub:$,onClick:()=>{Vt(b),x()},children:T},b);return e(j,{children:[e(Tl,{items:C,active:f,onPick:Vt,onClose:k,label:"Open chats",children:[e("button",{type:"button",class:`icon-btn ${f?"":"on"}`,"aria-label":"New chat",title:a?"New side chat about this run":"New chat",onClick:()=>Vt(null),children:e(z,{name:"plus"})}),e(nt,{label:"All chats",icon:"menu",title:"Every chat here, closed ones too",children:b=>e(j,{children:[d.length?e(Rt,{children:"Side chats on this run"}):null,d.map(T=>y(T.key,T.title,`${De[T.agent]??T.agent} \xB7 ${T.turns.length} message${T.turns.length===1?"":"s"}`,b)),o.length?e(Rt,{children:"Chats from this run, on their own branch"}):null,o.map(T=>y(T.id,T.task.split(`
86
+ `)[0].slice(0,60),`${ot[T.status]??T.status}`,b)),i.length?e(Rt,{children:m?`Chats in ${m}`:"Chats"}):null,i.slice(0,30).map(T=>y(T.id,T.task.split(`
87
+ `)[0].slice(0,60),`${ot[T.status]??T.status}`,b)),a?e(j,{children:[e(Rt,{children:"New"}),e(me,{sub:"A Single-agent run on a branch of its own, from this run's result",onClick:()=>{Vt("solo"),b()},children:"Separate chat"})]}):null,!d.length&&!o.length&&!i.length&&!a?e("div",{class:"pop-title",children:"No chats here yet"}):null]})})]}),u&&a?e(ih,{run:a,chat:u.chat},u.key):p&&n.has(p.pattern)?e(ch,{id:p.id},p.id):a&&c!=="solo"&&Qd(a)?e(lh,{run:a},a.id):e(dh,{scope:t},t.key)]})}var eu=()=>Gt.value&&Os.value==="chat";function tu(t){let s=Q(null);return _(()=>{let n=s.current;n&&n.scrollHeight-n.scrollTop-n.clientHeight<160&&(n.scrollTop=n.scrollHeight)},t),s}function ih({run:t,chat:s}){let{run:n,data:a,version:r}=tn(t.id,void 0,eu()),o=rh(n,t,s),i=tu([r,o?.chat.turns.length,o?.chat.turns.at(-1)?.status]);if(!o)return e("div",{class:"side-empty help",children:"Loading\u2026"});let{run:d,chat:l}=o,m=d.worktrees.find(c=>c.name===l.turns[0].worktree);return e(j,{children:[e("div",{class:"chat-scroll",ref:i,children:e("div",{class:"thread",children:[e("div",{class:"chat-meta",children:[e($e,{id:l.agent}),e("span",{class:"help",children:["Side chat in ",m?e("code",{title:m.path,children:m.branch}):"the run's worktree"]})]}),l.turns.map(c=>{let u=c.stepId?a.current.steps.get(c.stepId):void 0,p=c.side?.mode==="change";return e("div",{class:"fu",children:[e("div",{class:"msg-you",children:e("div",{class:"bubble",children:[e(Oe,{text:c.message}),e("div",{class:`side-mode ${p?"change":""}`,children:p?"Change":"Ask"})]})}),e("div",{class:`fu-answer ${c.status}`,children:[e("div",{class:"fu-head",children:[e($e,{id:c.agent}),c.status==="pending"&&d.status!=="running"?e("span",{class:"help",children:"The run stopped before this turn finished: resume the run to finish it"}):c.status==="pending"&&!u?e("span",{class:"fu-live",children:d.patternDone?"Up next\u2026":"Waits for the team to finish\u2026"}):e(sa,{f:c})]}),u?e(Kr,{run:d,step:u,data:a.current,answer:c.status==="pending"?void 0:c.result}):c.result?e(Oe,{text:c.result}):null]})]},c.id)})]})}),e(su,{run:d,chat:l})]})}function lh({run:t}){let s=ar(t);return e(j,{children:[e("div",{class:"chat-scroll",children:e("div",{class:"side-empty",children:[e("h3",{children:"Chat about this run"}),e("p",{class:"help",children:["The agent works in this run's worktree (",e("code",{children:s.branch}),"), in a conversation of its own. ",e("b",{children:"Ask"})," reads it and changes nothing; ",e("b",{children:"Change"})," edits it, and code-flow commits the change on the run's branch and runs the check.",t.status==="running"?" While the team is working, your message waits for it to finish.":""]})]})}),e(su,{run:t})]})}function su({run:t,chat:s}){let[n,a]=h(""),[r,o]=h(s?.mode??"ask"),[i,d]=h(s?.agent??Xd),[l,m]=h({}),[c,u]=h({trust:s?.turns.at(-1)?.trust??t.trust,tools:s?.turns.at(-1)?.tools??!!t.approvals.tools}),p=l[i]??s?.turns.filter(x=>x.agent===i).at(-1)?.settings??t.agentSettings[i]??{},[f,v]=h(!1),[g,w]=h(""),[C,k]=h([]),y=nu(n,a);_(()=>{let x=Mn(s?s.key:"side:new");x.length&&(a(E=>[E.trim(),...x.map(A=>A.text)].filter(Boolean).join(`
88
+
89
+ `)),k(E=>[...E,...x.flatMap(A=>A.images)]),y.current?.focus())},[_s.value,s?.key]);let b=s?t.worktrees.find(x=>x.name===s.turns[0].worktree):ar(t),T=De[i]??i,$=async()=>{if(!n.trim()||f||!b)return;v(!0),w("");let x=s?.chat??`c${Date.now().toString(36)}${Math.random().toString(36).slice(2,6)}`,E=s?.title??(n.trim().split(`
90
+ `)[0].slice(0,60)||"Side chat");try{await q(`/api/runs/${t.id}/followups`,{kind:"side",worktree:b.name,agent:i,settings:p,trust:c.trust,tools:c.tools,message:n.trim(),side:{chat:x,mode:r,title:E},attachments:C.map(({name:A,data:P})=>({name:A,data:P}))}),a(""),k([]),s||Vt(`side:${x}`,`run:${t.id}`)}catch(A){w(A.message)}finally{v(!1)}};return e("div",{class:"convo",children:e("div",{class:"convo-inner",children:[g?e("div",{class:"msg err",children:g}):null,e(di,{images:C,onRemove:x=>k(C.filter((E,A)=>A!==x))}),e("div",{class:"chatbox",children:[e("textarea",{ref:y,rows:1,"aria-label":"Message",placeholder:r==="change"?`Ask ${T} for a change\u2026`:s?`Reply to ${T}\u2026`:`Ask ${T} about this run\u2026`,value:n,onInput:x=>a(x.currentTarget.value),onKeyDown:x=>{x.key==="Enter"&&!x.shiftKey&&!x.isComposing&&(x.preventDefault(),$())}}),e("div",{class:"chatbox-bar chatbox-configurable",children:[e(nt,{above:!0,label:"Chat mode",icon:"chat",class:"chat-choice",trigger:e(j,{children:[e("span",{children:r==="ask"?"Ask":"Change"}),e(z,{name:"chevron"})]}),children:x=>e(j,{children:[e(Rt,{children:"Chat mode"}),e(me,{on:r==="ask",sub:"Read the worktree without changing files",onClick:()=>{o("ask"),x()},children:"Ask"}),e(me,{on:r==="change",sub:"Edit the worktree, commit changes and run the check",onClick:()=>{o("change"),x()},children:"Change"})]})}),e(Qs,{agent:i,onAgent:x=>{d(x),de.set("sideAgent",x)},settings:p,onSettings:x=>m({...l,[i]:x}),permissions:c,onPermissions:u,restricted:!!t.lockdown||!!t.trigger,approvalsAvailable:!t.loop.remoteWorker&&!t.loop.agentContainer}),e("span",{class:"chatbox-hint"}),e("button",{class:"send","aria-label":"Send",title:"Send (\u21B5 \u2014 \u21E7\u21B5 for a new line)",disabled:f||!n.trim()||!b,onClick:$,children:e(z,{name:"send"})})]})]}),e("div",{class:"side-hint help",children:[r==="change"?`Edits ${b?.branch??"the run's worktree"}; code-flow commits it and runs the check.`:"Reads the run's worktree; changes nothing.",t.status==="running"?" Waits for the team to finish.":""]})]})})}function nu(t,s){let n=Q(null);return _(()=>{us.value&&(s(a=>a?`${a}
91
+
92
+ ${us.value}`:us.value),us.value="",n.current?.focus())},[us.value]),_(()=>{let a=n.current;a&&(a.style.height="auto",a.scrollHeight&&(a.style.height=`${Math.min(a.scrollHeight,220)}px`))},[t]),n}function ch({id:t}){let s=eu(),{run:n,problem:a,data:r,version:o}=tn(t,void 0,s),i=tu([o,n?.status,n?.followUps?.length]);if(_(()=>{s&&n&&n.status!=="running"&&!n.seen&&!document.hidden&&sr(n.id)},[s,n?.status,n?.seen]),a)return e("div",{class:"side-empty",children:[e("p",{class:"msg err",children:a}),e("button",{class:"btn",onClick:()=>Vt(null),children:"New chat"})]});if(!n)return e("div",{class:"side-empty help",children:"Loading\u2026"});let d=li(n,r.current.steps.values()),l=Object.values(n.roles).flat()[0],m=ft(n),c=n.artifacts[0]?.branch??n.worktrees[0]?.branch;return e(j,{children:[e("div",{class:"chat-scroll",ref:i,children:e("div",{class:"thread",children:[e("div",{class:"chat-meta",children:[e($e,{id:l}),e("span",{class:`status-pill ${m}`,children:ot[n.status]??n.status}),c?e("code",{title:"The branch this chat works on",children:c}):null,m==="failing"?e("span",{class:"note",children:"Check fails"}):m==="done"?e("span",{class:"ok",children:"Check passes"}):m==="unverified"?e("span",{class:"note",children:"Not verified"}):null,e("a",{class:"btn ghost small",href:`#/run/${encodeURIComponent(n.id)}`,title:"Open this chat as a run, with its branch and result",children:"Open"})]}),e("div",{class:"msg-you",children:e("div",{class:"bubble",children:e(Oe,{text:n.task})})}),e(ii,{run:n,steps:d,data:r.current}),["interrupted","stopped","failed","cancelled"].includes(n.status)?e("div",{class:"chat-resume",children:[e("span",{class:"help",children:n.status==="interrupted"?"This chat was interrupted.":`This chat ${ot[n.status]?.toLowerCase()??n.status}.`}),e("button",{class:"btn small",onClick:()=>q(`/api/runs/${n.id}/resume`).catch(u=>V(u.message)),children:"\u25B6 Resume"})]}):null]})}),e(ui,{run:n,steps:d,chat:!0})]})}function dh({scope:t}){let s=t.run,n=s?s.artifacts.map(T=>T.branch):[],[a,r]=h(""),[o,i]=h(Xd),[d,l]=h(!1),[m,c]=h(""),[u,p]=h(n[0]??""),f=nu(a,r),v=ve.value.find(T=>T.chat),g=De[o]??o,w=t.repo?be(t.repo):"the repository",[C,k]=h(de.get("interactiveApprovals")==="1"),y=async()=>{if(!(!a.trim()||d||!v)){if(!t.repo)return c("Choose a repository first.");l(!0),c("");try{let{id:T,project:$}=await q("/api/runs",{repo:t.repo,project:s?void 0:t.project?.id,task:a.trim(),pattern:v.id,roles:{agent:[o]},options:{},baseRef:u||void 0,agentSettings:Ue.value,trust:Tt.value,approvals:{tools:C},loop:{maxMinutes:Se.value.maxMinutes,maxSteps:Se.value.maxSteps},parentRunId:s?.id});r(""),Vt(T,t.key),Ga($),$&&t.key.startsWith("repo:")&&Vt(T,`project:${$}`)}catch(T){c(T.message)}finally{l(!1)}}},b=s&&!Qd(s);return e(j,{children:[e("div",{class:"chat-scroll",children:e("div",{class:"side-empty",children:[e("h3",{children:s?"A separate chat":`Chat with ${g}`}),e("p",{class:"help",children:s?`${b?`${oh(s)} `:""}${g} works on a branch of its own${u?", starting from the run's result":""}, and you keep talking to it; the chat is a run like any other.`:`Ask a question or ask for a change. ${g} works on its own branch of ${w} and you keep talking to it; its reply shows here and the chat is a run like any other.`}),v?null:e("p",{class:"msg warn",children:"This code-flow has no Single-agent pattern, which the chat needs."})]})}),e("div",{class:"convo",children:e("div",{class:"convo-inner",children:[m?e("div",{class:"msg err",children:m}):null,e("div",{class:"chatbox",children:[e("textarea",{ref:f,rows:1,"aria-label":"Message",placeholder:`Message ${g}\u2026`,value:a,onInput:T=>r(T.currentTarget.value),onKeyDown:T=>{T.key==="Enter"&&!T.shiftKey&&!T.isComposing&&(T.preventDefault(),y())}}),e("div",{class:"chatbox-bar chatbox-configurable",children:[e(Qs,{agent:o,onAgent:T=>{i(T),de.set("sideAgent",T)},settings:Ue.value[o]??{},onSettings:T=>Vs(o,T),permissions:{trust:Tt.value,tools:C},onPermissions:T=>{mn(T.trust),k(T.tools),de.set("interactiveApprovals",T.tools?"1":"0")}}),n.length?e("label",{class:"to",title:"Start from this run's result branch, so the agent sees that work",children:[e("span",{class:"to-lbl",children:"From"}),e("select",{"aria-label":"Start from",value:u,onChange:T=>p(T.currentTarget.value),children:[e("option",{value:"",children:"HEAD"}),n.map(T=>e("option",{value:T,children:T},T))]})]}):null,e("span",{class:"chatbox-hint"}),e("button",{class:"send","aria-label":"Send",title:"Send (\u21B5 \u2014 \u21E7\u21B5 for a new line)",disabled:d||!a.trim()||!v,onClick:y,children:e(z,{name:"send"})})]})]})]})})]})}var uh=Ys(()=>import("./browser-7XI52A6V.js").then(t=>t.BrowserTab)),ph=Ys(()=>import("./changes-EYFPASEI.js").then(t=>t.ChangesTab)),mh=Ys(()=>import("./terminal-A2FI2NAX.js").then(t=>t.TerminalTab)),Yr={chat:{label:"Chat",icon:"chat",title:"Chat with one agent about this run or repository"},changes:{label:"Changes",icon:"diff",title:"What this run changed: the whole branch or its last step, with line comments"},files:{label:"Files",icon:"files",title:"The repository's files, or a run's worktree"},terminal:{label:"Terminal",icon:"terminal",title:"A shell in the repository or a worktree"},browser:{label:"Browser",icon:"globe",title:"Open the app a run started, or any address"},notes:{label:"Notes",icon:"note",title:"Your scratchpad for this repository"}};function mi({popped:t=!1}){let s=Fs.value.run,n=Wi.filter(p=>p!=="changes"||s),a=n.includes(Os.value)?Os.value:"chat",[r,o]=h(()=>new Set([a]));_(()=>{r.has(a)||o(new Set([...r,a]))},[a]);let i=Fs.value.key;_(dl,[i]);let[d,l]=h(!1),m=p=>{p.preventDefault(),l(!0);let f=g=>mo(window.innerWidth-g.clientX),v=()=>{l(!1),window.removeEventListener("pointermove",f),window.removeEventListener("pointerup",v)};window.addEventListener("pointermove",f),window.addEventListener("pointerup",v)},c={chat:()=>e(Zd,{}),changes:()=>s?e(ph,{run:s},s.id):e("div",{class:"side-empty help",children:"Open a run to see what it changed."}),files:()=>e(fh,{}),terminal:()=>e(mh,{}),browser:()=>e(uh,{}),notes:()=>e(gh,{})},u=!Gt.value&&!t;return e("aside",{class:`side ${Gt.value?"open":""} ${t?"popped":""}`,"aria-label":"Side panel","aria-hidden":u,inert:u,children:[t?null:e("div",{class:`side-handle ${d?"dragging":""}`,role:"separator",tabIndex:0,"aria-orientation":"vertical","aria-label":"Resize the side panel","aria-valuemin":300,"aria-valuemax":900,"aria-valuenow":jn.value,title:"Drag or use arrow keys to resize",onPointerDown:m,onKeyDown:p=>{let f=p.key==="ArrowLeft"?jn.value+24:p.key==="ArrowRight"?jn.value-24:p.key==="Home"?300:p.key==="End"?900:void 0;f!==void 0&&(p.preventDefault(),mo(f))}}),e(hh,{popped:t}),e("div",{class:"side-tabs",role:"tablist","aria-label":"Side panel tabs",children:n.map(p=>e("button",{type:"button",role:"tab",id:`side-tab-${p}`,"aria-selected":p===a,"aria-controls":`side-pane-${p}`,class:`side-tab ${p===a?"on":""}`,"aria-label":Yr[p].label,title:Yr[p].title,tabIndex:p===a?0:-1,onKeyDown:f=>{let v=n.indexOf(p),g=f.key==="ArrowRight"?(v+1)%n.length:f.key==="ArrowLeft"?(v+n.length-1)%n.length:f.key==="Home"?0:f.key==="End"?n.length-1:-1;if(g>=0){f.preventDefault();let w=n[g];gt(w),document.getElementById(`side-tab-${w}`)?.focus()}},onClick:()=>gt(p),children:[e(z,{name:Yr[p].icon}),e("span",{children:Yr[p].label})]},p))}),e("div",{class:"side-body",children:Fs.value.waiting?e("div",{class:"side-empty help",children:"Loading\u2026"}):n.filter(p=>r.has(p)||p===a).map(p=>e("div",{id:`side-pane-${p}`,role:"tabpanel","aria-labelledby":`side-tab-${p}`,class:"side-pane",hidden:p!==a,children:c[p]()},p))})]})}function hh({popped:t}){let s=Fs.value,n=()=>{let i=`${location.origin}${location.pathname}#/side/${Os.value}/${encodeURIComponent(s.key)}`;window.open(i,`codeflow-side-${location.pathname}-${s.key}`,"popup,width=560,height=860")?an():V("The browser blocked the window: allow pop-ups for code-flow",5e3)},a=s.run?"run":"project",r=s.project?.name??(s.repo?be(s.repo):""),o=s.run?s.run.task.split(`
93
+ `)[0]||"(no task)":"";return e("div",{class:`side-scope ${s.pinned?"pinned":""}`,children:[e("span",{class:"scope-state",title:t?`This window shows one ${a}`:s.pinned?`The panel stays on this ${a} while you open others`:"The panel follows what you open",children:[t?e(z,{name:"external"}):s.pinned?e(z,{name:"pin"}):e("span",{class:"scope-dot","aria-hidden":"true"}),t?"Own window":s.pinned?"Pinned":"Following"]}),e("span",{class:"scope-crumbs",title:[r,s.repo,o].filter(Boolean).join(`
94
+ `),children:[r?e("span",{class:"sc-where",children:r}):s.waiting?null:e("span",{class:"help",children:"No repository chosen"}),!s.run&&s.project&&s.project.repos.length>1?e(j,{children:[e("span",{class:"sep","aria-hidden":"true",children:"\u203A"}),e("span",{class:"sc-what",children:be(s.repo)})]}):null,s.run?e(j,{children:[e("span",{class:"sep","aria-hidden":"true",children:"\u203A"}),s.pinned?e("a",{class:"sc-what",href:`#/run/${J(s.run.id)}`,title:t?"Open this run in the main window":"Open this run",children:o}):e("span",{class:"sc-what",children:o})]}):null]}),t?null:s.pinned?e("button",{type:"button",class:"btn ghost small",title:"Follow what you open again",onClick:()=>ba(!1),children:"Follow"}):e("button",{type:"button",class:"icon-btn","aria-label":`Pin the panel to this ${a}`,title:`Pin: keep the panel on this ${a} while you open others`,disabled:!s.repo,onClick:()=>ba(!0),children:e(z,{name:"pin"})}),t||bs?null:e("button",{type:"button",class:"icon-btn","aria-label":"Open in its own window",title:"Open this tab in a window of its own, for this run or project",disabled:!s.repo,onClick:n,children:e(z,{name:"external"})}),t?null:e("button",{type:"button",class:"icon-btn","aria-label":"Close side panel",title:"Close (\\)",onClick:an,children:e(z,{name:"close"})})]})}function fh(){let[t,s,n]=wl("files"),[a,r]=h(null);_(()=>{let i=Va.value;if(!i)return;let d=n.find(l=>l.path===i.root);d&&s(d),r({root:d?.path??t?.path??"",path:i.path}),Va.value=null},[Va.value]);let o=t?.path??"";return _(()=>r(i=>i?.root===o?i:null),[o]),e(j,{children:[e("div",{class:"side-toolbar",children:e(Cl,{label:"Folder",place:t,places:n,onChange:s})}),t?e($r,{folder:o,initialPath:a?.root===o?a.path:void 0,onClose:()=>r(null)},o):e("p",{class:"side-empty",children:"Choose a repository or run worktree."})]})}function gh(){let t=Fs.value.repo,[s,n]=h(t?"repo":"general"),[a,r]=h(null),[o,i]=h(""),[d,l]=h(null),[m,c]=h(!1),u=a??(s==="repo"&&t?t:"general"),[p,f]=h(""),[v,g]=h(null),[w,C]=h([]),[k,y]=h(null),b=Q(new Map),T=Q(Promise.resolve()),$=Q(u);$.current=u;let[x,E]=h(""),[A,P]=h(!1);_(()=>{P(!1),E("Loading\u2026");let S=!0;return U(`/api/notes?key=${J(u)}`).then(R=>{if(!S)return;let M=null;try{M=de.get(`notes-draft:${u}`)}catch{}f(M??R.text),b.current.set(u,{text:R.text,revision:R.revision}),g({at:R.updatedAt,text:R.text,revision:R.revision}),y(null),C([]),E(M!==null&&M!==R.text?"Recovered your unsaved draft":""),P(!0)},R=>S&&E(R.message)),()=>{S=!1}},[u]),_(()=>{if(!A||v?.text===p||k)return;E("Saving\u2026");let S=setTimeout(()=>{T.current=T.current.catch(()=>{}).then(async()=>{let R=b.current.get(u);if(!(!R||R.text===p))try{let M=await q("/api/notes",{key:u,text:p,expectedRevision:R.revision});b.current.set(u,{text:p,revision:M.revision});try{de.get(`notes-draft:${u}`)===p&&de.remove(`notes-draft:${u}`)}catch{}$.current===u&&(g({at:M.updatedAt,text:p,revision:M.revision}),E(""))}catch(M){if($.current!==u)return;E(`Couldn't save: ${M.message}. Your draft is kept in this browser.`);let O=await U(`/api/notes?key=${J(u)}`).catch(()=>null);O&&O.revision!==R.revision&&$.current===u&&y(O)}})},600);return()=>clearTimeout(S)},[p,u,A,v?.revision,k]);let D=()=>{let S=document.getElementById("side-notes");return((S&&S.selectionStart!==S.selectionEnd?S.value.slice(S.selectionStart,S.selectionEnd):"")||p).trim()};return e(j,{children:[e("div",{class:"side-toolbar",children:[t?e("div",{class:"segmented small",role:"group","aria-label":"Which notes",children:[e("button",{type:"button",class:!a&&s==="repo"?"on":"","aria-pressed":!a&&s==="repo",onClick:()=>{n("repo"),r(null)},title:t,children:be(t)}),e("button",{type:"button",class:!a&&s==="general"?"on":"","aria-pressed":!a&&s==="general",onClick:()=>{n("general"),r(null)},children:"General"})]}):e("span",{class:"help",children:"General notes"}),e("span",{class:"spacer"}),e("button",{type:"button",class:"btn ghost small",title:"Add the selection (or the whole note) to the task in the composer",disabled:!p.trim(),onClick:()=>{_e({view:"composer"},[{to:"composer",text:D(),images:[]}]),V("Added to the task")},children:"\u2192 Task"}),e("button",{type:"button",class:"btn ghost small",title:"Send the selection (or the whole note) to the chat",disabled:!p.trim(),onClick:()=>{us.value=D(),Vt(null),gt("chat")},children:"\u2192 Chat"})]}),e("div",{class:"notes-tools",children:[e("button",{type:"button",class:"btn ghost small","aria-expanded":m,"aria-controls":m?"notes-search":void 0,onClick:()=>c(!m),children:[e(z,{name:"search"})," Search saved notes"]}),e("span",{class:"spacer"}),e("button",{type:"button",class:"btn ghost small",disabled:!A,onClick:async()=>{try{C(await U(`/api/notes/history?key=${J(u)}`))}catch(S){E(S.message)}},children:[e(z,{name:"clock"})," Revision history"]})]}),m?e("div",{id:"notes-search",class:"notes-search",children:[e("form",{class:"notes-search-row",onSubmit:async S=>{S.preventDefault();try{l(await U(`/api/notes/search?q=${J(o)}`))}catch(R){E(R.message)}},children:[e("input",{class:"field","aria-label":"Search saved notes",placeholder:"Words or repository path",value:o,onInput:S=>i(S.currentTarget.value)}),e("button",{class:"btn small",children:"Search notes"})]}),d?e(j,{children:[d.hits.length?d.hits.map(S=>e("div",{class:"notes-hit",children:[e("button",{type:"button",class:"notes-hit-key",onClick:()=>{r(S.key),l(null)},children:[S.key," \xB7 revision ",S.revision]}),e("span",{class:"help",children:S.excerpt})]},S.key)):e("p",{class:"help",children:"No saved notes match."}),d.truncated?e("p",{class:"help",children:"Results are limited; narrow the query."}):null]}):null]}):null,a?e("div",{class:"notes-picked",children:[e("span",{class:"help",children:["Editing ",e("code",{children:a})]}),e("button",{class:"btn small",onClick:()=>r(null),children:"Return to current notes"})]}):null,k?e("div",{class:"notes-conflict",role:"alert",children:[e("p",{children:"This note changed in another window. Your draft is preserved."}),e("details",{children:[e("summary",{children:"Compare saved version"}),e("pre",{children:k.text})]}),e("div",{class:"row",children:[e("button",{class:"btn small",onClick:()=>{b.current.set(u,k),f(k.text),g({at:k.updatedAt,text:k.text,revision:k.revision}),y(null),de.remove(`notes-draft:${u}`)},children:"Use saved version"}),e("button",{class:"btn small",onClick:()=>{b.current.set(u,k),g({at:k.updatedAt,text:k.text,revision:k.revision}),y(null)},children:"Save my draft over this version"})]})]}):null,w.length?e("details",{open:!0,class:"notes-history",children:[e("summary",{children:[w.length," saved revisions"]}),w.map(S=>e("div",{children:e("details",{children:[e("summary",{children:["Revision ",S.revision," \xB7 ",new Date(S.updatedAt).toLocaleString()]}),e("pre",{children:S.text||"(empty)"}),e("button",{class:"btn small",disabled:S.revision===v?.revision||v?.text!==p,onClick:async()=>{try{let R=await q("/api/notes/restore",{key:u,revision:S.revision,expectedRevision:v?.revision});b.current.set(u,R),g({at:R.updatedAt,text:R.text,revision:R.revision}),f(R.text),C([]),E("Restored as a new revision")}catch(R){E(R.message)}},children:"Restore as new revision"})]})},S.revision))]}):null,e("textarea",{id:"side-notes",class:"notes-area","aria-label":"Notes",placeholder:"Notes to yourself: what to check, ideas, commands\u2026 Saved as you type.",spellcheck:!1,disabled:!A,value:p,onInput:S=>{f(S.currentTarget.value),de.set(`notes-draft:${u}`,S.currentTarget.value)}}),e("div",{class:"notes-foot",children:[e("span",{children:x||(v?.at?`Saved ${Wt(v.at)}`:"")}),e("span",{class:"spacer"}),e("span",{children:p.length?`${p.length.toLocaleString()} characters`:""})]})]})}function au({runId:t,branch:s,refreshKey:n,onOpen:a}){let[r,o]=h(null),[i,d]=h(""),[l,m]=h(!1),[c,u]=h(""),[p,f]=h(""),v=`${t}\0${s}`,g=Q(v);g.current=v;let w=`/api/runs/${J(t)}/review-coverage`;_(()=>{let k=!0;return o(null),d(""),U(`${w}?branch=${J(s)}`).then(y=>{k&&o(y)},y=>{k&&d(y.message)}),()=>{k=!1}},[t,s,n]),_(()=>{m(!1),u(""),f("")},[t,s]);let C=async(k,y)=>{let b=v;m(!0),d("");try{let T=await q(k,y);return g.current!==b?!1:(o(T),!0)}catch(T){return g.current===b&&d(T.message),!1}finally{g.current===b&&m(!1)}};return e("details",{class:"review-coverage",children:[e("summary",{children:["Human review coverage",r?` \xB7 ${r.coverage.reviewed}/${r.coverage.changed} files \xB7 ${r.risk.level} change risk`:""]}),e("p",{class:"help",children:"Mark files after reviewing them. Coverage records your review of this commit; it resets when the branch moves. Passing checks do not imply human review."}),i?e("p",{class:"msg err",role:"alert",children:i}):null,r?e(j,{children:[e("p",{class:"help",children:["Commit ",r.head.slice(0,12),r.stale?" \xB7 previous review refers to older code":""]}),r.risk.reasons.map(k=>e("p",{class:"help",children:k},k)),e("div",{class:"rc-files",children:r.files.map(k=>e("div",{class:"rc-file",children:[e("label",{class:"check",children:[e("input",{type:"checkbox","aria-label":`Mark ${k} reviewed`,disabled:l,checked:r.reviewed.includes(k),onChange:y=>C(w,{branch:s,expectedHead:r.head,path:k,reviewed:y.currentTarget.checked})}),e("span",{class:"sr-only",children:"Reviewed"})]}),e("button",{type:"button",class:"rc-path",title:`Open ${k}`,onClick:()=>a(k),children:e("bdi",{children:k})})]},k))}),e("details",{children:[e("summary",{children:"Record human rework"}),e("p",{class:"help",children:"Track time you spent correcting or completing this result. These are your records, not estimates from agent activity."}),e("label",{children:["Minutes",e("input",{class:"field",type:"number",min:"1",max:"1440",value:c,disabled:l,onInput:k=>u(k.currentTarget.value)})]}),e("label",{children:["What changed",e("textarea",{class:"field",rows:2,maxLength:2e3,value:p,disabled:l,onInput:k=>f(k.currentTarget.value)})]}),e("button",{class:"btn small",disabled:l||!(Number(c)>=1&&Number(c)<=1440),onClick:async()=>{await C(`/api/runs/${J(t)}/human-rework`,{branch:s,expectedHead:r.head,minutes:Number(c),note:p})&&(u(""),f(""))},children:"Record rework"}),e("p",{class:"help",children:[r.rework.reduce((k,y)=>k+y.minutes,0)," minutes recorded across ",r.rework.length," entries."]}),r.rework.map(k=>e("p",{class:"help",children:[k.minutes," min \xB7 ",new Date(k.at).toLocaleDateString()," \xB7 ",k.note]},k.id))]})]}):e("p",{class:"help",children:"Loading coverage\u2026"})]})}var na=new Map,fi=ke(0),ru=t=>(na.has(t)||na.set(t,de.json(t,[])),na.get(t));function vh(t){return fi.value,ru(t)}function hi(t,s){let n=s(ru(t));na.set(t,n),de.set(t,JSON.stringify(n)),fi.value++}window.addEventListener("storage",t=>{t.key!==null&&!t.key.startsWith("comments:")||(t.key===null?na.clear():na.delete(t.key),fi.value++)});function ou({id:t,branch:s}){let{run:n,data:a}=tn(t),r=n??Ne.value.get(t),[o,i]=h(0),d=`comments:${t}:${s}`,[l,m]=h(null),[c,u]=h(null),[p,f]=h(""),[v,g]=h(""),[w,C]=h(null),k=vh(d),[y,b]=h(()=>de.get(`${d}:general`)??""),[T,$]=h(null),[x,E]=h(!1);_(()=>{let B=!0;return f(""),U(`/api/runs/${t}/diff?branch=${J(s)}`).then(ee=>{B&&(u(ee),C(se=>ee.some(te=>te.path===se)?se:ee[0]?.path??null))},ee=>{B&&f(ee.message)}),U(`/api/runs/${t}`).then(ee=>{B&&(m(ee),g(""))},ee=>{B&&g(`Couldn't load this run: ${ee.message}. Check who the comments go to before sending.`)}),()=>{B=!1}},[t,s,o,r?.status,r?.lastCheck?.at]);let A=((r??l)?.worktrees??[]).find(B=>B.branch===s),P=Rn(()=>bh(l,A?.name),[l,A?.name]),D=T??P??"claude",S=c?.find(B=>B.path===w),R=c?.reduce((B,ee)=>({add:B.add+ee.additions,del:B.del+ee.deletions}),{add:0,del:0}),M=r?.status==="done"&&!r.projectTeam&&!!A&&!!(T??P)&&(k.length>0||y.trim().length>0),O=async()=>{if(!A||!M||x)return;E(!0);let B=yh(k,y);try{await q(`/api/runs/${t}/followups`,{kind:"comments",worktree:A.name,agent:D,message:B}),hi(d,()=>[]),de.set(`${d}:general`,""),V("Sent \u2014 the agent is working on your comments"),Z.value={view:"run",id:t}}catch(ee){V(ee.message,5e3)}finally{E(!1)}};return e("div",{class:"review",children:[e("div",{class:"review-head",children:[e("button",{class:"btn ghost small review-back",onClick:()=>Z.value={view:"run",id:t},children:[e(z,{name:"chevron",class:"back"})," Back to run"]}),e("div",{class:"review-title",children:[e("h1",{children:"Review"}),e("code",{title:s,children:s}),R?e("span",{class:"review-totals",children:[c.length," file",c.length===1?"":"s"," \xB7 ",e("span",{class:"add",children:["+",R.add]})," ",e("span",{class:"del",children:["\u2212",R.del]})]}):null]}),e("div",{class:"review-send",children:r?.projectTeam?e("a",{class:"btn",href:`#/project/${r.project}`,children:"Use mission revision controls"}):r?.status==="done"?e(j,{children:[e("span",{class:"review-to",children:T||P?"Send to":l||v?"Choose an agent":"Loading recipient\u2026"}),e(Gr,{value:D,onChange:$}),e("button",{class:"btn primary",disabled:!M||x,onClick:O,children:x?"Sending\u2026":`Send ${k.length||""} comment${k.length===1?"":"s"}`.replace(" "," ")})]}):e("span",{class:"review-to",children:"Comments can be sent once the run has finished."})})]}),r?e("div",{class:"review-overview",children:[e(Pr,{run:r,branch:s}),e("div",{class:"review-evidence-tools",children:[e(jr,{run:r}),e("button",{class:"btn small",onClick:()=>i(B=>B+1),children:"Refresh changes"})]}),r.artifacts.find(B=>B.branch===s)?e("details",{class:"review-delivery",children:[e("summary",{children:"Publish changes"}),e("p",{class:"help",children:"Review the diff and evidence before publishing. Merge validation and confirmation still apply."}),e(ci,{run:r,artifact:r.artifacts.find(B=>B.branch===s),steps:[...a.current.steps.values()],reviewing:!0},s)]}):null]}):null,p?e("div",{class:"msg err review-msg",children:p}):null,v?e("div",{class:"msg warn review-msg",children:v}):null,r?.outcome?.decision==="needs-work"&&r.outcome.branch===s?e("p",{class:"help review-msg",children:"Describe what needs to change in the overall comment or on individual lines, then send your comments to start a revision on this branch."}):null,e("div",{class:"review-body",children:[e("div",{class:"review-files",children:[A&&c?.length?e(xr,{folder:A.path,paths:c.map(B=>B.path),refreshKey:`${o}:${r?.status}:${r?.lastCheck?.at}`}):null,e(au,{runId:t,branch:s,refreshKey:`${o}:${r?.status}:${r?.lastCheck?.at}`,onOpen:C}),c?.map(B=>{let ee=k.filter(te=>te.file===B.path).length,se=B.path.lastIndexOf("/")+1;return e("button",{type:"button",class:`rf ${B.path===w?"selected":""}`,onClick:()=>C(B.path),title:B.oldPath?`${B.oldPath} \u2192 ${B.path}`:B.path,children:[e("span",{class:`fs ${B.status}`,children:{added:"A",modified:"M",deleted:"D",renamed:"R"}[B.status]}),e("span",{class:"fp",children:[se?e("span",{class:"fdir",children:B.path.slice(0,se)}):null,e("span",{class:"fname",children:B.path.slice(se)})]}),ee?e("span",{class:"count",title:`${ee} comment${ee===1?"":"s"}`,children:ee}):null,e("span",{class:"fn",children:[e("span",{class:"add",children:["+",B.additions]})," ",e("span",{class:"del",children:["\u2212",B.deletions]})]})]},B.path)}),c&&!c.length?e("div",{class:"tree-empty",children:"No changes on this branch."}):null,e("div",{class:"general",children:[e("label",{class:"lbl",for:"general",children:"Overall comment"}),e("textarea",{id:"general",class:"field",rows:4,placeholder:"Anything that isn't about one line\u2026",value:y,onInput:B=>{b(B.currentTarget.value),de.set(`${d}:general`,B.currentTarget.value)}})]})]}),e("div",{class:"review-diff",role:"region","aria-label":S?`Diff of ${S.path}`:"Diff",children:S?e(kh,{file:S,comments:k.filter(B=>B.file===S.path),onAdd:B=>hi(d,ee=>[...ee,B]),onRemove:B=>hi(d,ee=>ee.filter(se=>se!==B))},S.path):c?null:e("div",{class:"tree-empty",children:"Loading diff\u2026"})})]})]})}var bh=(t,s)=>[...t?.steps??[]].reverse().find(n=>(n.kind??"agent")==="agent"&&n.worktree===s&&n.mode==="write")?.agent;function yh(t,s=""){return[t.map((a,r)=>`${r+1}. ${a.file}:${a.line}${a.side==="old"?" (a removed line)":""} \u2014 \`${a.code.trim().slice(0,140)}\`
95
+ ${a.text.trim()}`).join(`
96
+ `),s.trim()?`General: ${s.trim()}`:""].filter(Boolean).join(`
97
+
98
+ `)}function kh({file:t,comments:s,onAdd:n,onRemove:a}){let r=Rn(()=>wh(t.patch),[t.patch]),[o,i]=h(null),[d,l]=h(""),[m,c]=h(-1),u=Q(null),p=Q(null);if(_(()=>{o&&p.current?.focus()},[o]),t.binary)return e("div",{class:"tree-empty",children:"Binary file \u2014 no text diff."});let f=(k,y)=>s.filter(b=>b.side===k&&b.line===y),v=k=>k.type==="add"||k.type==="del"||k.type==="ctx",g=r[m]&&v(r[m])?m:r.findIndex(v),w=k=>{u.current?.querySelector(`tr[data-i="${k}"]`)?.focus(),i(null)},C=k=>{let y=[...u.current?.querySelectorAll("tr.dl[tabindex]")??[]],b=y.indexOf(k.currentTarget),T={ArrowDown:1,ArrowUp:-1,PageDown:20,PageUp:-20,Home:-y.length,End:y.length};return b<0||!(k.key in T)||k.altKey||k.ctrlKey||k.metaKey?!1:(k.preventDefault(),y[Math.max(0,Math.min(y.length-1,b+T[k.key]))].focus(),!0)};return e("div",{children:[e("div",{class:"diff-file-head",children:[t.oldPath?`${t.oldPath} \u2192 `:"",t.path,t.truncated?e("span",{class:"help",children:" \xB7 diff truncated"}):null]}),e("table",{class:"diff",children:e("tbody",{ref:u,children:r.map((k,y)=>{let b=k.type==="del"?"old":"new",T=b==="old"?k.old:k.new,$=v(k),x=$?f(b,T):[],E=o&&$&&o.side===b&&o.line===T,A=()=>{!$||T===void 0||(i({side:b,line:T,code:k.text}),l(""))};return[e("tr",{class:`dl ${k.type}`,"data-i":y,tabIndex:$?y===g?0:-1:void 0,onClick:A,onFocus:()=>c(y),onKeyDown:P=>{P.target!==P.currentTarget||C(P)||(P.key==="Enter"||P.key===" ")&&(P.preventDefault(),A())},title:$?"Click or press Enter to comment on this line":void 0,children:[e("td",{class:"ln",children:k.old??""}),e("td",{class:"ln",children:k.new??""}),e("td",{class:"code",children:[e("span",{class:"sign",children:k.type==="add"?"+":k.type==="del"?"\u2212":" "}),k.text]})]},`r${y}`),...x.map((P,D)=>e("tr",{class:"comment-row",children:e("td",{colSpan:3,children:e("div",{class:"comment",children:[e("span",{children:P.text}),e("button",{class:"btn ghost small",onClick:()=>a(P),children:"Remove"})]})})},`c${y}-${D}`)),E?e("tr",{class:"comment-row",children:e("td",{colSpan:3,children:e("div",{class:"comment editing",children:[e("textarea",{ref:p,class:"field",rows:3,"aria-label":`Comment on line ${T}`,placeholder:"What should change here?",value:d,onInput:P=>l(P.currentTarget.value),onKeyDown:P=>{P.key==="Enter"&&(P.metaKey||P.ctrlKey)&&d.trim()&&(n({file:t.path,side:b,line:T,code:k.text,text:d}),w(y)),P.key==="Escape"&&w(y)}}),e("div",{class:"row",children:[e("button",{class:"btn small",onClick:()=>w(y),children:"Cancel"}),e("button",{class:"btn small primary",disabled:!d.trim(),onClick:()=>{n({file:t.path,side:b,line:T,code:k.text,text:d}),w(y)},children:["Add comment ",e("span",{class:"kbd",children:"\u2318\u21B5"})]})]})]})})},`e${y}`):null]})})})]})}function wh(t){let s=[],n=0,a=0,r=!1;for(let o of t.split(`
99
+ `)){let i=o.match(/^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@(.*)/);if(i){n=Number(i[1]),a=Number(i[2]),r=!0,s.push({type:"hunk",text:o});continue}r&&(o.startsWith("+")?s.push({type:"add",text:o.slice(1),new:a++}):o.startsWith("-")?s.push({type:"del",text:o.slice(1),old:n++}):o.startsWith(" ")?s.push({type:"ctx",text:o.slice(1),old:n++,new:a++}):o.startsWith("\\")&&s.push({type:"note",text:o}))}return s}function iu(){let t=Js.value,s=we(!!t,()=>Js.value=null),[n,a]=h("issue"),[r,o]=h(null),[i,d]=h(""),[l,m]=h(""),c=t?.template;_(()=>{t&&(a(t.kind),m(""))},[t]),_(()=>{if(!t||!ne.value)return;o(null),d("");let v=!0;return U(`/api/github/${n==="issue"?"issues":"prs"}?repo=${J(ne.value)}`).then(g=>v&&o(g),g=>v&&d(g.message)),()=>{v=!1}},[t,n,ne.value]);let u=v=>{let g={kind:n,number:v.number,title:v.title,url:v.url,headRefName:v.headRefName,baseRefName:v.baseRefName,isCrossRepository:v.isCrossRepository};c?wo(c,g):(tt.value={...g,ciLogs:tt.value?.ciLogs},Pe.value.trim()||St(n==="issue"?`Fix issue #${v.number}: ${v.title}`:`Pull request #${v.number} (${v.title}): `)),Js.value=null},p=l.trim().toLowerCase(),f=(r??[]).filter(v=>!p||`#${v.number} ${v.title} ${(v.labels??[]).join(" ")} ${v.author??""}`.toLowerCase().includes(p));return e("dialog",{class:"picker gh-picker",ref:s,"aria-labelledby":"github-picker-title",children:t?e("div",{class:"picker-inner",children:[e("div",{class:"picker-head",children:[e("h3",{id:"github-picker-title",children:c?`${c.name}: pick ${n==="issue"?"an issue":"a pull request"}`:"Start from GitHub"}),c?.needs?null:e("div",{class:"segmented",role:"radiogroup","aria-label":"Issues or pull requests",children:[e("button",{type:"button",role:"radio","aria-checked":n==="issue",class:n==="issue"?"on":"",onClick:()=>a("issue"),children:"Issues"}),e("button",{type:"button",role:"radio","aria-checked":n==="pr",class:n==="pr"?"on":"",onClick:()=>a("pr"),children:"Pull requests"})]}),e("div",{class:"row",children:e("input",{class:"field",placeholder:"Filter by number, title, label\u2026",value:l,onInput:v=>m(v.currentTarget.value),autoFocus:!0})})]}),e("div",{class:"picker-list",children:[i?e("div",{class:"msg err pad",children:i}):null,!r&&!i?e("div",{class:"help pad",children:"Loading from GitHub\u2026"}):null,r&&!f.length?e("div",{class:"help pad",children:["No open ",n==="issue"?"issues":"pull requests",p?" match":"","."]}):null,f.map(v=>e("div",{class:"dir gh-item",tabIndex:0,onClick:()=>u(v),onKeyDown:g=>g.key==="Enter"&&u(v),children:[e("span",{class:"di",children:["#",v.number]}),e("span",{class:"dn",children:[v.title,n==="pr"?e("span",{class:"gh-sub",children:[e("span",{class:"br",children:v.headRefName})," \u2192 ",e("span",{class:"br",children:v.baseRefName}),v.author?` \xB7 @${v.author}`:"",v.isDraft?" \xB7 draft":"",v.isCrossRepository?" \xB7 from a fork (read-only)":""]}):v.labels?.length?e("span",{class:"gh-sub",children:v.labels.join(" \xB7 ")}):null]})]},v.number))]}),e("div",{class:"picker-foot",children:[e("span",{class:"ps",children:"Listed with GitHub CLI (gh) using your own login."}),e("button",{class:"btn",onClick:()=>Js.value=null,children:"Cancel"})]})]}):null})}function Qr({only:t,onChoose:s,prepare:n,disabled:a=!1}={}){let[r,o]=h(!1),[i,d]=h("");if(!tr.value.length)return null;let l=async u=>{if(!(r||a)){o(!0),d("");try{if(await n?.()===!1)throw new Error("The project draft is not ready. Wait for it to load and try again.")}catch(p){d(p.message);return}finally{o(!1)}s?.(),u.sweep?xs.value=u:u.needs?Js.value={kind:u.needs,template:u}:wo(u)}},m=tr.value.filter(u=>!u.sweep&&t!=="backlog"),c=tr.value.filter(u=>u.sweep&&t!=="sources");return e("details",{class:"settings task-starters",open:!0,children:[e("summary",{children:[e("span",{class:"st",children:t==="backlog"?"Choose backlog items":"From GitHub"}),e("span",{class:"ss",children:"Issues and pull requests"})]}),e("div",{class:"settings-body",children:[i?e("p",{role:"alert",children:i}):null,e("div",{class:"templates",children:[e("span",{class:"lbl",children:"Start from"}),m.map(u=>e("button",{type:"button",class:"chip-tpl",title:u.description,disabled:r||a,onClick:()=>void l(u),children:u.name},u.id))]}),c.length?e("div",{class:"templates",children:[e("span",{class:"lbl",children:"Sweep"}),c.map(u=>e("button",{type:"button",class:"chip-tpl sweep",title:u.description,disabled:r||a,onClick:()=>void l(u),children:[e(z,{name:"layers"})," ",u.name]},u.id))]}):null]})]})}function lu(){let t=tt.value;return t?e("span",{class:"chip-ctx source",title:t.url,children:[e("span",{class:"n",children:[t.kind==="issue"?"Issue":t.kind==="pr"?"PR":"Alert"," ",e("span",{class:"num",children:["#",t.number]})," \xB7 ",t.title]}),t.kind==="pr"?e("span",{class:"note",children:["starts from ",e("span",{class:"br",children:t.headRefName})]}):null,t.kind==="pr"?e("label",{class:"note",title:"Give agents the PR's failing CI checks and their logs",children:[e("input",{type:"checkbox",checked:!!t.ciLogs,onChange:s=>tt.value={...t,ciLogs:s.currentTarget.checked}})," CI logs"]}):null,e("button",{type:"button",title:"Don't start from this","aria-label":"Remove source",onClick:()=>tt.value=null,children:"\xD7"})]}):null}var cu=25,Ch=t=>/^(critical|high|error)$/i.test(t??"")?"high":/^(medium|warning)$/i.test(t??"")?"medium":"";function du(){let t=xs.value,s=we(!!t,()=>xs.value=null),[n,a]=h(null),[r,o]=h(),[i,d]=h(""),[l,m]=h(new Set),[c,u]=h(""),[p,f]=h(!1),[v,g]=h("07:00"),[w,C]=h(!1);_(()=>{if(!t)return;a(null),d(""),u(""),f(!1);let R={project:Ze.value.project?.id,repo:ne.value};if(o(R),!R.repo)return d("Choose a repository first");let M=!0;return U(`/api/github/sweep?repo=${J(R.repo)}&kind=${t.sweep}`).then(O=>{M&&(a(O),m(new Set(O.items.filter(B=>B.selected).map(B=>B.key))))},O=>{M&&d(O.message)}),()=>{M=!1}},[t]);let k=t?ve.value.find(R=>R.id===t.pattern):void 0,y=ns(k),b=n?.items??[],T=R=>!R.manual&&!!R.source&&!!R.task,$=b.filter(R=>l.has(R.key)&&T(R)),x=c.trim().toLowerCase(),E=b.filter(R=>!x||`${R.ref} ${R.title} ${R.detail} ${R.note??""}`.toLowerCase().includes(x)),A=k?vn(k,y,!1)||($.length>cu?`Pick at most ${cu}; the rest can go in a later sweep`:""):"",P=R=>{let M=new Set(l);M.has(R)?M.delete(R):M.add(R),m(M)},D=R=>{let M=new Set(l);for(let O of E)T(O)&&(R?M.add(O.key):M.delete(O.key));m(M)},S=async()=>{if(!(!t||!k||A||!$.length||w)){if(!r||r.project!==Ze.value.project?.id||r.repo!==ne.value){d("The draft destination changed. Close this backlog and choose it again for the intended project.");return}C(!0),d("");try{let R=await q("/api/sweeps",{kind:t.sweep,name:t.name,max:5,schedule:p?{at:v}:void 0,run:{repo:r.repo,project:r.project,projectSelection:"explicit",pattern:k.id,roles:y,options:as(k),baseRef:Fe.value,agentSettings:Ue.value,roleSettings:lt.value[k.id]??{},trust:Tt.value,loop:{check:jt.value.trim(),setup:Yt.value.trim(),maxMinutes:Se.value.maxMinutes,maxSteps:Se.value.maxSteps,copy:ss.value?.config.copy}},items:$.map(O=>({key:O.key,task:O.task,source:O.source}))});await Promise.all([Un(),Cs()]),V([`Started ${((O,B)=>`${O} ${B}${O===1?"":"s"}`)(R.started.length,"run")}`,R.skipped.length?`${R.skipped.length} already had one`:"",R.failed.length?`${R.failed.length} couldn't start (${R.failed[0].key}: ${R.failed[0].error})`:"",R.automation?"saved as a daily sweep":""].filter(Boolean).join(" \xB7 "),R.failed.length?8e3:5e3),xs.value=null,Z.value={view:"inbox"}}catch(R){d(R.message)}finally{C(!1)}}};return e("dialog",{class:"picker sweep-dialog",ref:s,"aria-labelledby":"sweep-title",children:t?e("div",{class:"picker-inner",children:[e("div",{class:"picker-head",children:[e("h3",{id:"sweep-title",children:[e(z,{name:"layers"})," ",t.name]}),e("div",{class:"help",children:t.description}),e("p",{class:"help",children:["Project: ",r?.project," \xB7 ",e("code",{children:r?.repo})]}),e("div",{class:"row",children:e("input",{class:"field",placeholder:"Filter by number, title, label, severity\u2026","aria-label":"Filter",value:c,onInput:R=>u(R.currentTarget.value)})}),n?e("div",{class:"sweep-tools",children:[e("span",{children:[e("b",{children:$.length})," of ",b.filter(T).length," picked"]}),e("button",{type:"button",class:"linkish",onClick:()=>D(!0),children:["Pick all",x?" shown":""]}),e("button",{type:"button",class:"linkish",onClick:()=>D(!1),children:"None"})]}):null]}),e("div",{class:"picker-list sweep-list",children:[i?e("div",{class:"msg err pad",children:i}):null,n?.notices.map(R=>e("div",{class:"config-note bad",children:R},R)),!n&&!i?e("div",{class:"help pad",children:"Loading from GitHub\u2026"}):null,n&&!b.length?e("div",{class:"help pad",children:"Nothing open \u2014 all clear."}):null,n&&b.length&&!E.length?e("div",{class:"help pad",children:"Nothing matches."}):null,E.map(R=>e("label",{class:`sweep-item ${T(R)?"":"manual"} ${l.has(R.key)&&T(R)?"on":""}`,children:[e("input",{type:"checkbox",checked:l.has(R.key)&&T(R),disabled:!T(R),onChange:()=>P(R.key)}),e("span",{class:"si-main",children:[e("span",{class:"si-title",children:[e("span",{class:"si-ref",children:R.ref})," ",R.title]}),e("span",{class:"si-detail",children:[R.severity?e("span",{class:`sev ${Ch(R.severity)}`,children:R.severity}):null," ",R.detail]}),R.note?e("span",{class:`si-note ${R.manual?"warn":""}`,children:[R.note,R.existingRun?e(j,{children:[" \xB7 ",e("a",{href:`#/run/${R.existingRun}`,onClick:()=>xs.value=null,children:"open it"})]}):null]}):null]}),e("a",{class:"si-link",href:R.url,target:"_blank",rel:"noreferrer",title:"Open on GitHub","aria-label":`Open ${R.ref} on GitHub`,onClick:M=>M.stopPropagation(),children:e(z,{name:"external"})})]},R.key))]}),e("div",{class:"sweep-how",children:[k?e("div",{class:"help",children:["Each runs ",e("b",{children:k.name}),": ",aa(k,y,!1),"."," ",e("button",{type:"button",class:"linkish",onClick:()=>{bt(k.id),xs.value=null},children:"Change the team"})]}):null,e("label",{class:"check",children:[e("input",{type:"checkbox",checked:p,onChange:R=>f(R.currentTarget.checked)})," Also check every day at"," ",e("input",{class:"field inline",type:"time",value:v,"aria-label":"Time of day",disabled:!p,onInput:R=>g(R.currentTarget.value||"07:00")})," and start runs for new ones (up to 5 each time)"]})]}),e("div",{class:"picker-foot",children:[e("span",{class:"ps",children:A||"Results wait in the inbox for you to approve. Nothing is merged automatically."}),e("button",{class:"btn",type:"button",onClick:()=>xs.value=null,children:"Cancel"}),e("button",{class:"btn primary",type:"button",disabled:!!A||!$.length||w,onClick:S,children:w?"Starting\u2026":`Start ${$.length} run${$.length===1?"":"s"}`})]})]}):null})}function uu(t){return[t.task,t.id,t.repo,t.pattern,t.branchPrefix,t.source?`#${t.source.number} ${t.source.title}`:"",t.externalSource?.title??"",t.trigger?.name??"",t.group?.label??""].join(`
100
+ `).toLowerCase()}function Xr({host:t,onManage:s}){let[n,a]=h(null),[r,o]=h(""),[i,d]=h(!1),[l,m]=h(0),[c,u]=h(!1),[p,f]=h("");Ee(async k=>{d(!0);try{let y=await mt(`/api/ssh-hosts/${encodeURIComponent(t.id)}/team-server/status`);k()&&(a(y),o(""))}catch(y){k()&&(a(null),o(y.message))}finally{k()&&d(!1)}},6e4,[t.id,l]);let v=n?.state==="running"&&n.access==="ready"&&!!n.address,g=r?"Status unavailable":n?n.state==="not-installed"?"Not set up":n.state==="unavailable"?"Not responding":"Running":"Checking\u2026",w=!n||n.state!=="running"?"Not verified":v?"HTTPS enabled":n.access==="disabled"?"Not enabled":n.access==="error"?"Needs attention":"Setup incomplete",C=async()=>{if(!(c||!await Ce(`Permanently delete the team server on ${t.name}?
101
+
102
+ This stops the server and erases its shared projects, tasks, accounts, certificates and settings. Automatic startup is removed. This cannot be undone.
103
+
104
+ Repository folders and the SSH workspace stay in place.`,{title:`Delete team server on ${t.name}?`,confirmLabel:"Delete permanently",danger:!0}))){u(!0),f("");try{await mt(`/api/ssh-hosts/${encodeURIComponent(t.id)}/team-server/installation`,{method:"DELETE"}),a({state:"not-installed"}),m(k=>k+1)}catch(k){f(k.message)}finally{u(!1)}}};return e("section",{class:"settings-card ssh-team-status","aria-label":`Team server on ${t.name}`,children:[e("div",{class:"ssh-team-status-head",children:[e("div",{children:[e("p",{class:"ssh-team-eyebrow",children:"Team hosting"}),e("h2",{children:["Team server on ",t.name]})]}),e("span",{class:`badge ${n?.state==="running"?"ok":"warn"}`,role:"status",children:g})]}),e("p",{class:"help",children:["Teammates connect to the team server on ",t.name,". Your own computer does not need incoming access."]}),e("dl",{class:"ssh-team-status-facts",children:[e("div",{children:[e("dt",{children:"Secure access"}),e("dd",{children:e("span",{class:`badge ${v?"ok":"warn"}`,children:w})})]}),e("div",{children:[e("dt",{children:"Network"}),e("dd",{children:n?.network??"Not verified"})]}),e("div",{class:"ssh-team-status-address",children:[e("dt",{children:"Team address"}),e("dd",{children:v?e(j,{children:[e("code",{children:n.address}),e("button",{class:"btn small",onClick:()=>void Ot(n.address,"Team address copied"),children:"Copy address"})]}):"Not available"})]})]}),e("p",{class:"help",children:v?"Teammates need access to this network and their own team account. HTTPS is enabled on the server; connectivity from a teammate\u2019s computer has not been tested.":n?.state==="not-installed"?"Set up a team server here to share projects and create teammate accounts.":n?.state==="running"?"Open team server setup to configure secure access on this server.":"The team server\u2019s access status could not be verified. Check the SSH connection and refresh. Checking status does not start or change the server."}),r?e("p",{class:"msg err",role:"alert",children:r}):null,p?e("p",{class:"msg err",role:"alert",children:p}):null,e("div",{class:"settings-actions",children:[s?e("button",{class:"btn primary",disabled:c,onClick:s,children:n?.state==="running"?"Manage team server":"Set up team server"}):e("a",{class:"btn primary",href:"#/settings/connections/sharing",children:"Manage team server"}),e("button",{class:"btn",disabled:i||c,onClick:()=>m(k=>k+1),children:i?"Checking\u2026":"Refresh status"}),s&&n&&n.state!=="not-installed"?e("button",{class:"btn danger",disabled:c||i,onClick:()=>void C(),children:c?"Deleting\u2026":"Delete team server"}):null]}),s&&n?.state!=="not-installed"?e("p",{class:"help",children:"Manage team server to edit projects, repositories, secure access and accounts. To restart it, stop the server in setup, then start it again."}):null]})}var Th=Ys(()=>import("./terminal-A2FI2NAX.js").then(t=>t.TermView));function pu(){let[t,s]=h(null),[n,a]=h(""),r=async(o=()=>!0)=>{try{let i=await U("/api/team-terminals");o()&&(s(i),a(""))}catch(i){o()&&(s(null),a(i.message))}};return Ee(r,0,[Nt.value]),{data:t,error:n,setError:a,load:r}}var gi=t=>U(`/api/team-terminals/${J(t)}`,{method:"DELETE",headers:{"content-type":"application/json"},body:"{}"});function Zr({board:t}){let{data:s,error:n,setError:a,load:r}=pu(),[o,i]=h(!1),d=async m=>{if(!(!s||o)){i(!0);try{await hs("/api/team-terminals/settings",{revision:s.revision,grant:m}),await r()}catch(c){await r(),a(c.message)}finally{i(!1)}}},l=async m=>{i(!0);try{await gi(m),await r()}catch(c){a(c.message)}finally{i(!1)}};return e("section",{class:"settings-card",children:[e("h3",{children:"Teammate terminals"}),e("p",{class:"help",children:"A separate permission from agent tasks. A terminal runs as your operating-system user and can access files and credentials outside the project. The project selects its starting folder; it does not sandbox commands. Grant this only to people you trust with your computer."}),e("p",{class:"help",children:"Two terminals per teammate, eight in total. Sessions close after 30 minutes without keyboard input, on access revocation, or when Code Flow stops. The app shows each terminal\u2019s output only to its creator. Detached processes and changes already made may outlive a closed terminal."}),n?e("p",{class:"msg err",role:"alert",children:n}):null,s?e(j,{children:[s.available?null:e("p",{class:"msg warn",children:"Team terminals are unavailable while filesystem restrictions are active."}),t.projects.map(m=>e(Sh,{project:m,saved:s.grants.find(c=>c.projectId===m.id),busy:o,save:d},m.id)),e("h4",{children:"Open teammate terminals"}),s.sessions.length?e("ul",{children:s.sessions.map(m=>e("li",{children:[m.displayName," \xB7 ",t.projects.find(c=>c.id===m.projectId)?.name??m.projectId," \xB7 ",m.repository," ",e("button",{class:"btn small danger",disabled:o,onClick:()=>void l(m.id),children:"Close terminal"})]},m.id))}):e("p",{class:"help",children:"No open teammate terminals."}),e("details",{children:[e("summary",{children:"Recent terminal activity"}),e("p",{class:"help",children:"Records opens and closes, without saving command text or output."}),e("ul",{children:s.audit.slice(-20).reverse().map((m,c)=>e("li",{children:[new Date(m.at).toLocaleString()," \xB7 ",m.session.displayName," \xB7 ",m.action," \xB7 ",m.session.repository,m.reason?` \xB7 ${m.reason}`:""]},`${m.at}-${c}`))})]})]}):e("p",{class:"help",children:"Loading terminal permissions\u2026"})]})}function Sh({project:t,saved:s,busy:n,save:a}){let r=()=>s??{projectId:t.id,enabled:!1,userIds:[]},[o,i]=h(r);_(()=>i(r()),[JSON.stringify(s)]);let d=t.members.filter(l=>l.userId!=="owner"&&je(l.role,"contributor"));return e("fieldset",{class:"team-keys",disabled:n,children:[e("legend",{children:["Terminal access \xB7 ",t.name]}),e("label",{children:[e("input",{type:"checkbox",checked:o.enabled,onChange:l=>i({...o,enabled:l.currentTarget.checked})})," Allow unrestricted host terminals for this project"]}),d.map(l=>e("label",{class:"row-inline",children:[e("input",{type:"checkbox",checked:o.userIds.includes(l.userId),onChange:m=>i({...o,userIds:m.currentTarget.checked?[...o.userIds,l.userId]:o.userIds.filter(c=>c!==l.userId)})}),l.displayName]},l.userId)),d.length?null:e("p",{class:"help",children:"Add a project contributor in Projects & access first."}),e("div",{class:"settings-actions",children:e("button",{class:"btn small primary",disabled:n||JSON.stringify(o)===JSON.stringify(s),onClick:()=>void a({...o,userIds:o.userIds.filter(l=>d.some(m=>m.userId===l))}),children:"Save terminal permissions"})})]})}function mu({board:t,project:s}){let{data:n,error:a,setError:r,load:o}=pu(),[i,d]=h(!1),[l,m]=h(""),[c,u]=h(""),p=t.projects.filter(k=>(!s||k.id===s)&&n?.grants.some(y=>y.projectId===k.id&&y.allowed)).flatMap(k=>k.repositories.map(y=>({key:`${k.id}/${y.key}`,projectId:k.id,repository:y.key,label:`${k.name} \xB7 ${y.label}`}))),f=p.find(k=>k.key===l)??p[0],v=n?.sessions.filter(k=>!s||k.projectId===s)??[],g=v.find(k=>k.id===c)??v[0],w=async(k,y,b)=>{if(!i){d(!0),r("");try{b&&await gi(b);let T=await q("/api/team-terminals",{projectId:k,repository:y,cols:100,rows:24});u(T.id),await o()}catch(T){await o(),r(T.message)}finally{d(!1)}}},C=async k=>{d(!0);try{await gi(k),await o()}catch(y){r(y.message)}finally{d(!1)}};return n&&!p.length&&!v.length&&!a?null:e("section",{class:"team-section",children:[e("h3",{children:"Your host terminals"}),e("p",{class:"help",children:"Commands run on the host computer using its installed tools and user permissions. Each terminal is yours; other teammates cannot attach through Code Flow. Closing this page leaves the shell open until you close it or it reaches the 30-minute input timeout."}),a?e("p",{class:"msg err",role:"alert",children:a}):null,e("div",{class:"team-actions",children:[e("label",{children:["Starting repository",e("select",{class:"field","aria-label":"Terminal starting repository",value:f?.key??"",onChange:k=>m(k.currentTarget.value),children:p.map(k=>e("option",{value:k.key,children:k.label},k.key))})]}),e("button",{class:"btn small primary",disabled:i||!f||!n?.available||(n?.sessions.length??0)>=2,onClick:()=>f&&void w(f.projectId,f.repository),children:"Open terminal"}),v.length?e("label",{children:["Open session",e("select",{class:"field","aria-label":"Your terminal session",value:g?.id??"",onChange:k=>u(k.currentTarget.value),children:v.map((k,y)=>e("option",{value:k.id,children:[k.repository," \xB7 terminal ",y+1]},k.id))})]}):null,g?e("button",{class:"btn small danger",disabled:i,onClick:()=>void C(g.id),children:"Close terminal"}):null]}),g?e("div",{class:"team-terminal-screen",children:e(Th,{id:g.id,places:[],split:!1,focused:!1,shown:!0,onFocus:()=>{},onReplace:()=>void w(g.projectId,g.repository,g.id),transport:xh(g.id)},g.id)}):e("p",{class:"help",children:"No terminal open. Python 3 PTY support is required on the host."})]})}function xh(t){let s=`/api/team-terminals/${J(t)}`;return{async input(n){let a=n.binary===void 0?"data":"binary",r=n[a]??"";for(let o of r.match(/[\s\S]{1,4096}/gu)??[])await q(`${s}/input`,{[a]:o})},resize:n=>q(`${s}/resize`,{cols:Math.min(500,Math.max(2,n.cols)),rows:Math.min(200,Math.max(1,n.rows))}),watch(n){let a=new EventSource(vs(`${s}/events`));return a.onmessage=r=>{try{n(JSON.parse(r.data))}catch{}},a.onerror=()=>n({type:"error",status:0,message:"Terminal connection lost or access ended. Reconnecting if available\u2026"}),()=>a.close()}}}var eo=t=>["queued","starting","running","stopping"].includes(t.state);function vi(){let[t,s]=h(null),[n,a]=h(""),r=async(o=()=>!0)=>{try{let i=await U("/api/host-execution");o()&&(s(i),a(""))}catch(i){o()&&(s(null),a(i.message))}};return Ee(r,0,[Nt.value]),{data:t,error:n,setError:a,load:r}}function to({board:t}){let{data:s,error:n,setError:a,load:r}=vi(),[o,i]=h(1),[d,l]=h(!1);_(()=>{s&&i(s.concurrency)},[s?.concurrency]);let m=async c=>{if(!s||d)return!1;l(!0),a("");try{return await hs("/api/host-execution/settings",{revision:s.revision,...c}),await r(),!0}catch(u){return await r(),a(u.message),!1}finally{l(!1)}};return e("section",{class:"settings-card",children:[e("h3",{children:"Run teammates\u2019 tasks on this computer"}),e("p",{class:"help",children:"Grant trusted teammates permission to queue agent tasks using this computer\u2019s installed CLIs and logins. Each task gets a Git worktree. Agent and test commands run with this host\u2019s permissions; a project grant is not an operating-system sandbox."}),e("p",{class:"help",children:"Map each repository above to a repository belonging to its project. Teammates can start tasks they own, see progress, cancel their requests and download checkpoints. The host owner handles agent approvals. Terminal access requires a separate grant below."}),n?e("p",{class:"msg err",role:"alert",children:n}):null,s?e(j,{children:[s.available?null:e("p",{class:"msg warn",children:"Host execution is unavailable while filesystem restrictions are active."}),e("div",{class:"settings-actions",children:[e("label",{children:["Concurrent host tasks",e("input",{class:"field",type:"number",min:1,max:4,value:o,onInput:c=>i(Number(c.currentTarget.value))})]}),e("button",{class:"btn small",disabled:d||o===s.concurrency||!Number.isInteger(o)||o<1||o>4,onClick:()=>void m({concurrency:o}),children:"Save queue limit"})]}),t.projects.map(c=>e(Rh,{project:c,saved:s.policies.find(u=>u.projectId===c.id),busy:d,save:m},c.id)),t.projects.length?null:e("p",{class:"help",children:"Create a project and teammate accounts to grant execution."})]}):e("p",{class:"help",children:"Loading host execution settings\u2026"})]})}function Rh({project:t,saved:s,busy:n,save:a}){let r=()=>s??{projectId:t.id,enabled:!1,userIds:[],agent:"codex",trust:"standard",maxMinutes:30,maxSteps:20},[o,i]=h(r);_(()=>i(r()),[JSON.stringify(s)]);let d=t.members.filter(m=>m.userId!=="owner"&&je(m.role,"contributor")),l=m=>i({...o,...m});return e("fieldset",{class:"team-keys",disabled:n,children:[e("legend",{children:t.name}),e("label",{children:[e("input",{type:"checkbox",checked:o.enabled,onChange:m=>l({enabled:m.currentTarget.checked})})," Allow host execution for this project"]}),e("div",{class:"settings-grid",children:[e("label",{children:["Host CLI",e("select",{"aria-label":"Host CLI",class:"field",value:o.agent,onChange:m=>l({agent:m.currentTarget.value}),children:[e("option",{value:"codex",children:"Codex"}),e("option",{value:"claude",children:"Claude Code"}),e("option",{value:"agy",children:"Antigravity"})]})]}),e("label",{children:["Agent permissions",e("select",{"aria-label":"Agent permissions",class:"field",value:o.trust,onChange:m=>l({trust:m.currentTarget.value}),children:[e("option",{value:"safe",children:"Safe"}),e("option",{value:"standard",children:"Standard"})]})]}),e("label",{children:["Minutes per task",e("input",{class:"field",type:"number",min:1,max:120,value:o.maxMinutes,onInput:m=>l({maxMinutes:Number(m.currentTarget.value)})})]}),e("label",{children:["Steps per task",e("input",{class:"field",type:"number",min:1,max:100,value:o.maxSteps,onInput:m=>l({maxSteps:Number(m.currentTarget.value)})})]})]}),e("p",{class:"help",children:"Choose which project contributors may use this computer:"}),d.map(m=>e("label",{class:"row-inline",children:[e("input",{type:"checkbox",checked:o.userIds.includes(m.userId),onChange:c=>l({userIds:c.currentTarget.checked?[...o.userIds,m.userId]:o.userIds.filter(u=>u!==m.userId)})}),m.displayName]},m.userId)),d.length?null:e("p",{class:"help",children:"Give a teammate the contributor or maintainer role in Projects & access first."}),e("div",{class:"settings-actions",children:e("button",{class:"btn small primary",disabled:n||JSON.stringify(o)===JSON.stringify(s),onClick:()=>void a({policy:{...o,userIds:o.userIds.filter(m=>d.some(c=>c.userId===m))}}),children:"Save host permissions"})})]})}function hu({task:t,meId:s}){let{data:n,error:a,setError:r,load:o}=vi(),[i,d]=h(!1),l=n?.policies.find(f=>f.projectId===t.projectId),m=n?.jobs.filter(f=>f.taskId===t.id)??[],c=[...m].reverse().find(eo)??m.at(-1),u=n?.available&&l?.allowed&&t.owner?.userId===s,p=async(f,v)=>{if(!i){d(!0),r("");try{await q(f,v),await o()}catch(g){r(g.message)}finally{d(!1)}}};return e("div",{class:"team-section",children:[e("h3",{children:"Host computer"}),a?e("p",{class:"msg err",role:"alert",children:a}):null,c?e("p",{role:"status",children:[c.state==="queued"?"Queued for the host computer":`Host task: ${c.state}`," \xB7 requested by ",c.displayName,c.message?` \xB7 ${c.message}`:""]}):null,u&&!m.some(eo)?e("button",{class:"btn small primary",disabled:i||t.status==="done"||t.attempts.some(f=>["claimed","running","unknown"].includes(f.state))||t.handoff?.state==="offered",onClick:()=>void p(`/api/host-execution/tasks/${J(t.id)}`,{revision:t.revision}),children:"Run on host computer"}):null,c&&eo(c)&&c.userId===s?e("button",{class:"btn small",disabled:i||c.state==="stopping",onClick:()=>void p(`/api/host-execution/jobs/${J(c.id)}/cancel`,{}),children:c.state==="queued"?"Remove from queue":"Stop host task"}):null,e("p",{class:"help",children:l?.allowed?`Uses ${l.agent} on the host. Your browser can close after queuing. Progress and downloadable checkpoints appear on this task.`:"The host owner can grant execution in Settings \u2192 Team. You can also run this task from your own linked Code Flow installation."}),l?.allowed&&t.owner?.userId!==s?e("p",{class:"help",children:"Take ownership of this task to queue it on the host."}):null]})}function so({board:t,project:s}){let{data:n,error:a,setError:r,load:o}=vi(),[i,d]=h(""),l=(n?.jobs??[]).filter(c=>(!s||c.projectId===s)&&eo(c)),m=async c=>{d(c.id);try{await q(`/api/host-execution/jobs/${J(c.id)}/cancel`,{}),await o()}catch(u){r(u.message)}finally{d("")}};return e("section",{class:"team-section","aria-label":"Host execution queue",children:[e("h3",{children:"Host queue"}),a?e("p",{class:"msg err",role:"alert",children:a}):null,!n&&!a?e("p",{class:"help",children:"Loading\u2026"}):l.length?e("ol",{children:l.map(c=>e("li",{children:[e("a",{href:`#/team/task/${J(c.taskId)}`,children:t.tasks.find(u=>u.id===c.taskId)?.title??c.taskId})," \xB7 ",c.state," \xB7 ",c.displayName,c.message?` \xB7 ${c.message}`:""," ",(t.me.userId==="owner"||t.me.userId===c.userId)&&c.state!=="stopping"?e("button",{class:"btn small",disabled:!!i,onClick:()=>void m(c),children:c.state==="queued"?"Remove":"Stop"}):null]},c.id))}):e("p",{class:"help",children:"No host tasks queued or running."}),n?e("p",{class:"help",children:["Up to ",n.concurrency," host task",n.concurrency===1?"":"s"," at a time, in queue order. You see tasks in your projects."]}):null]})}function ra(t){let s=new URL(location.href);s.searchParams.set("team",t),s.searchParams.delete("token"),s.hash.startsWith("#/settings/")||(s.hash="#/team"),location.assign(s.href)}function fs(){let[t,s]=h([]),[n,a]=h("");Ee(async i=>{try{let d=await U("/api/team-link/connections");i()&&(s(d.connections),a(""))}catch(d){i()&&a(d.message)}},15e3,[]);let r=t.filter(i=>i.id!=="local"),o=gs||(r.length===1?r[0].id:r.length===0?"local":"");return e("section",{class:"settings-card team-connection-picker","aria-label":"Team connections",children:[e("label",{class:"lbl",children:["Team connection",e("select",{class:"field",value:o,onChange:i=>ra(i.currentTarget.value),children:[e("option",{value:"",disabled:!0,children:"Choose a team\u2026"}),o&&t.length>0&&!t.some(i=>i.id===o)?e("option",{value:o,disabled:!0,children:"Connection unavailable"}):null,t.map(i=>e("option",{value:i.id,children:i.id==="local"?"This computer\u2019s own board":`${i.hubName||i.url} \xB7 ${i.user?.username??""} \xB7 ${i.connection}`},i.id))]})]}),e("p",{class:"help",children:"Each team keeps its own projects, account and repository mappings. Switching teams keeps other connections and running tasks active."}),n?e("p",{class:"msg err",role:"alert",children:n}):null,e("a",{class:"btn small",href:"#/settings/connections/sharing",children:"Manage team connections"})]})}function fu(t){if(!t||typeof t!="object"||Array.isArray(t))return"Expected a task draft object";let s=t;if(Object.keys(s).some(n=>!["title","goal","acceptance"].includes(n)))return"Unexpected task draft field";for(let[n,a]of[["title",200],["goal",16384],["acceptance",8192]]){let r=s[n];if(typeof r!="string"||!r.trim()||r.length>a||r.includes("\0"))return`Draft ${n} must contain 1\u2013${a} characters`}}function gu({projectId:t,repository:s,baseRef:n,onBusy:a,onApply:r}){let o=Be.value.filter(P=>P.available),[i,d]=h(o[0]?.id??""),[l,m]=h(""),[c,u]=h(Jt.value?.mappings[t]?.[s]??""),[p,f]=h(""),[v,g]=h(!1),[w,C]=h(!1),[k,y]=h(""),[b,T]=h(),$=Q(!0),x=Q(a);x.current=a,_(()=>{!i&&o[0]&&d(o[0].id)},[i,Be.value]),_(()=>($.current=!0,()=>{$.current=!1}),[]),_(()=>{if(!v||!p)return;let P=!0,D,S=async()=>{try{let R=await U(`/api/runs/${J(p)}`);if(!P)return;if(R.status==="running"){y(""),D=setTimeout(S,1500);return}if(R.status!=="done")throw new Error(R.error||R.stopReason||`Draft ${R.status}. Open the drafting run for details, or try again.`);let M;try{M=JSON.parse(R.summary??"")}catch{throw new Error("The agent did not return a usable draft. Try again or create the task manually.")}let O=fu(M);if(O)throw new Error(O);T(M),y(""),g(!1),x.current(!1)}catch(R){if(!P)return;y(R.message);let M=R.status;if(M===0||M!==void 0&&M>=500){D=setTimeout(S,3e3);return}g(!1),x.current(!1)}};return S(),()=>{P=!1,clearTimeout(D)}},[p,v]);let E=async()=>{if(!(v||!l.trim())){g(!0),a(!0),y(""),T(void 0),f("");try{let P=await q("/api/team-link/draft",{projectId:t,repository:s,idea:l,agent:i,repo:c.trim(),baseRef:n,agentSettings:Ue.value});$.current&&f(P.runId)}catch(P){$.current&&(y(P.message),g(!1),a(!1))}}},A=async()=>{C(!0);try{await q(`/api/runs/${J(p)}/cancel`,{})}catch(P){y(P.message)}finally{C(!1)}};return e("section",{class:"team-section team-draft-assistant","aria-label":"Draft with agent",children:[e("h3",{children:"Draft with agent"}),e("p",{class:"help",children:"Describe your idea. An agent reads the selected repository and proposes a goal, scope, plan and acceptance criteria. Review the draft before creating a shared task. Limit: 5 minutes and 2 agent calls."}),e("label",{children:["Idea",e("textarea",{class:"field",rows:3,maxLength:16384,value:l,disabled:v,onInput:P=>m(P.currentTarget.value)})]}),e("label",{children:["Drafting agent",e("select",{class:"field",value:i,disabled:v,onChange:P=>d(P.currentTarget.value),children:[e("option",{value:"",disabled:!0,children:"Choose an installed agent"}),o.map(P=>e("option",{value:P.id,children:P.displayName},P.id))]})]}),e("label",{children:["Repository folder",e("input",{class:"field mono",value:c,disabled:v,placeholder:"/absolute/path/to/your/clone",onInput:P=>u(P.currentTarget.value)})]}),e("button",{type:"button",class:"btn small",disabled:v||!ne.value,onClick:()=>u(ne.value),children:"Use current repository"}),o.length?null:e("p",{class:"help",children:"Install and sign in to an agent on this computer to draft tasks. You can still create a task manually."}),e("div",{class:"team-actions",children:[e("button",{type:"button",class:"btn",disabled:v||!l.trim()||!c.trim()||!s||!o.some(P=>P.id===i),onClick:()=>void E(),children:v?"Drafting\u2026":b?"Generate again":"Generate draft"}),v&&p?e("button",{type:"button",class:"btn",disabled:w,onClick:()=>void A(),children:w?"Stopping\u2026":"Stop drafting"}):null,p?e("a",{href:`#/run/${J(p)}`,target:"_blank",rel:"noopener",children:"Open drafting run"}):null]}),v?e("p",{class:"help",role:"status",children:"The agent is reading repository context and preparing your draft."}):null,k?e("p",{class:"msg err",role:"alert",children:k}):null,b?e("div",{class:"team-draft-preview",children:[e("h4",{children:b.title}),e("p",{class:"team-comment-text",children:b.goal}),e("h4",{children:"Acceptance criteria"}),e("p",{class:"team-comment-text",children:b.acceptance}),e("button",{type:"button",class:"btn primary",onClick:()=>r(b),children:"Use draft in form"}),e("p",{class:"help",children:"This replaces the title, goal and acceptance fields. You can edit them before saving."})]}):null]})}function oa({project:t,shared:s=!1,embedded:n=!1,navigate:a}){let[r,o]=h(!1),[i,d]=h(""),[l,m]=h(!1),[c,u]=h(Date.now());Ee(()=>{xt(),s||Xs(),u(Date.now())},s?0:15e3,[Nt.value,s]),Ee(()=>u(Date.now()),15e3,[],s);let p=at.value,f=!s&&p.kind==="ssh"?p:null,v=Dt.value,g=t;if(!v)return e("div",{class:"team-page","aria-busy":!zo.value,children:[!s&&!f&&!n?e(fs,{}):null,Xt.value?e("p",{class:"msg err",role:"alert",children:[Xt.value," ",e("button",{class:"btn small",onClick:()=>void xt(),children:"Retry"})]}):e("p",{class:"help",role:"status",children:"Loading the team board\u2026"})]});if(t&&!v.projects.some(A=>A.id===t))return e("div",{class:"team-page",children:[e("p",{role:"alert",children:"This project is unavailable on this board. Choose a project you have access to."}),e("button",{class:"btn",onClick:()=>a({view:"team"}),children:"All board projects"})]});let w=v.me.userId,C=A=>A.owner?.userId===w||A.reviewer?.userId===w||A.collaborators.some(P=>P.userId===w)||A.handoff?.state==="offered"&&A.handoff.to.userId===w,k=v.tasks.filter(A=>!g||A.projectId===g),y=k.filter(A=>(!r||C(A))&&(!i||A.status===i)),b=v.projects.some(A=>je(A.role,"contributor")&&(!g||A.id===g)),T=i?[i]:Xn,$=A=>v.projects.find(P=>P.id===A.projectId),x=A=>{let P=y.filter(D=>D.status===A).sort((D,S)=>S.updatedAt-D.updatedAt);return e("section",{class:"team-column","aria-labelledby":`team-col-${A}`,children:[e("h2",{id:`team-col-${A}`,children:[Zs[A],e("span",{class:"team-count",children:P.length})]}),P.map(D=>e($h,{task:D,me:w,project:g?void 0:$(D),now:c,onOpen:()=>a({view:"team-task",id:D.id})},D.id)),P.length?null:e("p",{class:"team-column-empty",children:"No tasks"})]},A)},E=Jt.value;return e("div",{class:"team-page",children:[!s&&!f&&!n?e(fs,{}):null,Xt.value?e("p",{class:"msg err",role:"alert",children:Xt.value}):null,e("div",{class:"page-head",children:[e("div",{class:"page-head-text",children:[n?e("h2",{children:"Board"}):e("h1",{children:"Board"}),e("p",{children:f?`Tasks, ownership and reviews on ${f.name}.`:g?`${v.projects.find(A=>A.id===g)?.name??"This project"} \xB7 Tasks, ownership, and reviews in one place.`:"Shared tasks, ownership, and reviews in one place."})]}),e("div",{class:"page-head-actions",children:[e("button",{class:"btn",onClick:()=>a({view:"team-people",...g?{project:g}:{}}),children:"People"}),b?e("button",{type:"button",class:"btn primary","aria-expanded":!!l,disabled:!!l,onClick:()=>m("manual"),children:[e(z,{name:"plus"})," New task"]}):null,b&&!s?e("button",{type:"button",class:"btn",disabled:!!l,onClick:()=>m("agent"),children:"Draft with agent"}):null]})]}),f&&!n?e(j,{children:[e(Xr,{host:f},f.id),e("div",{class:"team-board-context",children:[e("strong",{children:["Viewing this computer\u2019s board \xB7 ",f.name]}),e("p",{children:"Tasks below belong to this computer. To use the shared team board, connect your computer with the team address and account from team server setup."})]})]}):null,s?e(mu,{board:v,project:g}):null,!f&&(s||E&&!E.linked)?e(so,{board:v,project:g}):null,!s&&!f&&E&&!E.linked&&!v.tasks.length?e("div",{class:"settings-callout team-callout",children:[e(z,{name:"people"}),e("div",{children:[e("strong",{children:"Not connected to a team server"}),e("p",{children:"Connect this computer in Connections \u2192 Share access to work on a shared board, or create tasks here to use this computer as the team server."}),e("a",{href:"#/settings/connections/sharing",children:["Open Connections \u2192 Share access ",e("span",{"aria-hidden":"true",children:"\u2192"})]})]})]}):null,v.projects.length>1||g?e("div",{class:"team-chips",role:"group","aria-label":"Project",children:[e("button",{type:"button",class:"chip-tpl","aria-pressed":!g,onClick:()=>a({view:"team"}),children:"All projects"}),v.projects.map(A=>e("button",{type:"button",class:"chip-tpl","aria-pressed":g===A.id,onClick:()=>a({view:"team",project:A.id}),children:A.name},A.id))]}):null,l&&b?e(Ih,{b:v,projectId:g,shared:s,draftWithAgent:l==="agent",onDone:A=>{let P=l==="agent";m(!1),xt(),P&&a({view:"team-task",id:A.id})},onCancel:()=>m(!1)},g??""):null,e("div",{class:"team-toolbar",children:[e("div",{class:"segmented small",role:"group","aria-label":"Whose tasks",children:[e("button",{type:"button",class:r?"":"on","aria-pressed":!r,onClick:()=>o(!1),children:"All"}),e("button",{type:"button",class:r?"on":"","aria-pressed":r,onClick:()=>o(!0),children:"Mine"})]}),e("label",{class:"team-filter",children:["Status",e("select",{class:"field",value:i,onChange:A=>d(A.currentTarget.value),children:[e("option",{value:"",children:"All statuses"}),Xn.map(A=>e("option",{value:A,children:Zs[A]},A))]})]}),e("span",{class:"help",role:"status",children:[y.length," of ",k.length," tasks",r?" involve you":""]})]}),v.projects.length?null:e("p",{class:"team-empty",children:s?"You have no role in a shared project yet. Ask the owner for one.":"Create a project first: the board's tasks belong to projects, and teammates see the projects their accounts have a role in."}),e("div",{class:"team-board",children:[y.length?e("div",{class:`team-columns ${T.length===1?"single":""}`,children:T.map(x)}):e("section",{class:"team-board-empty","aria-label":"Task board",children:[e("div",{class:"team-workflow","aria-label":"Task workflow",children:Xn.map(A=>e("span",{children:[Zs[A],e("span",{class:"team-count",children:k.filter(P=>P.status===A).length})]},A))}),e("div",{class:"team-board-empty-body",children:[e(z,{name:"people"}),e("h2",{children:k.length?"No tasks match these filters":"Your board is ready for its first task"}),e("p",{children:k.length?"Try another status or show everyone\u2019s tasks.":"Give a task a goal and an owner. Follow its progress here, from planning through review to done."}),r||i?e("button",{class:"btn",onClick:()=>{o(!1),d("")},children:"Clear filters"}):b?e("button",{class:"btn primary",disabled:!!l,onClick:()=>m("manual"),children:[e(z,{name:"plus"})," Create first task"]}):e("p",{class:"help",children:s?"Ask your project maintainer for access to create tasks.":"Add a project to start creating tasks."})]})]}),e(Ah,{shared:s,navigate:a})]})]})}function $h({task:t,me:s,project:n,now:a,onOpen:r}){let o=t.attempt,i=o?Pa(o,a):!1,d=o?Or(o,a):!1,l=t.handoff?.state==="offered"&&t.handoff.to.userId===s,m=(t.unreadMentions??0)>0||l;return e("button",{type:"button",class:`team-card ${m?"needs-you":""}`,onClick:r,children:[e("span",{class:"tc-title",children:t.title}),e("span",{class:"tc-meta",children:[t.owner?e(j,{children:[e("span",{class:"team-avatar","aria-hidden":"true",children:Aa(t.owner.displayName)}),e("span",{children:Ut(t.owner,s)})]}):e("span",{children:"Unassigned"}),e("code",{children:t.repository}),n?e("span",{children:n.name}):null]}),o?e("span",{class:`tc-attempt ${d?"team-stale":i?"team-live":""}`,children:[i?e("span",{class:"dot running","aria-hidden":"true"}):null,d?`Connection lost \xB7 ${o.runnerName}`:`${Dr[o.state]} on ${o.runnerName}`,o.progress.stage&&!d?` \xB7 ${o.progress.stage}`:""]}):null,e("span",{class:"pills",children:[t.reviewer?e("span",{class:"badge",children:["Reviewer ",t.reviewer.userId===s?"you":t.reviewer.displayName]}):null,t.reviewState==="approved"?e("span",{class:"badge ok",children:"Approved"}):t.reviewState==="changes-requested"?e("span",{class:"badge warn",children:"Changes requested"}):t.reviewState==="pending"?e("span",{class:"badge",children:"Review pending"}):null,t.handoff?.state==="offered"?e("span",{class:"badge warn",children:["Hand-over to ",Ut(t.handoff.to,s)]}):null,t.blocker?e("span",{class:"badge warn",title:t.blocker,children:"Blocked"}):null,m?e("span",{class:"badge warn",children:"Needs you"}):null]})]})}function Ih({b:t,projectId:s,shared:n,draftWithAgent:a,onDone:r,onCancel:o}){let i=t.projects.filter(N=>je(N.role,"contributor")),[d,l]=h(s&&i.some(N=>N.id===s)?s:i[0]?.id??""),m=i.find(N=>N.id===d),[c,u]=h(""),[p,f]=h(m?.repositories[0]?.key??""),[v,g]=h(""),[w,C]=h(""),[k,y]=h(""),[b,T]=h(""),[$,x]=h(""),[E,A]=h(!1),[P,D]=h(!1),[S,R]=h(!!a),[M,O]=h(!1),B=E||P,[ee,se]=h("");_(()=>{f(m?.repositories[0]?.key??""),T(a?t.me.userId:""),x("")},[d]);let te=je(m?.role,"maintainer"),G=m?.members??[],L=G.filter(N=>je(N.role,"contributor")&&(te||N.userId===t.me.userId)),Y=G.filter(N=>je(N.role,"reviewer")),X=async N=>{if(N.preventDefault(),!(B||!m)){A(!0),se("");try{let ae=await q("/api/team/tasks",{projectId:d,repository:p,title:c.trim(),goal:v,acceptance:w,...k.trim()?{baseRef:k.trim()}:{},...b?{owner:b}:{},...$?{reviewer:$}:{}});V("Task created"),r(ae)}catch(ae){se(ae.message)}finally{A(!1)}}};return e("form",{id:"team-new",class:"team-section team-new","aria-labelledby":"team-new-title",onSubmit:N=>void X(N),children:[e("h2",{id:"team-new-title",children:"New task"}),M?e("p",{class:"help",role:"status",children:"Draft applied. Review and edit the fields, then create the task."}):null,e("div",{class:"team-fields",children:[i.length>1?e("label",{children:["Project",e("select",{class:"field",value:d,disabled:B,onChange:N=>l(N.currentTarget.value),children:i.map(N=>e("option",{value:N.id,children:N.name},N.id))})]}):null,e("label",{children:["Repository",e("select",{class:"field",required:!0,value:p,disabled:B||!m?.repositories.length,onChange:N=>f(N.currentTarget.value),children:m?.repositories.map(N=>e("option",{value:N.key,children:[N.label," (",N.key,")"]},N.key))})]}),e("label",{children:["Base branch",e("input",{class:"field",maxLength:100,placeholder:m?.repositories.find(N=>N.key===p)?.defaultBranch??"The repository's default branch",value:k,disabled:B,onInput:N=>y(N.currentTarget.value)})]})]}),m&&!m.repositories.length?e("p",{class:"msg warn",role:"status",children:[m.name," has no repository keys yet. A maintainer defines repository keys in Connections \u2192 Share access",!n&&te?e(j,{children:[": ",e("a",{href:"#/settings/connections/sharing",children:"open Connections \u2192 Share access"})]}):null,"."]}):null,!n&&S?e(gu,{projectId:d,repository:p,baseRef:k,onBusy:D,onApply:N=>{u(N.title),g(N.goal),C(N.acceptance),R(!1),O(!0)}},`${d}/${p}`):null,e("div",{class:"team-fields",children:[e("label",{children:["Title",e("input",{class:"field",required:!0,maxLength:200,value:c,disabled:B,onInput:N=>u(N.currentTarget.value)})]}),e("label",{children:["Owner",e("select",{class:"field",value:b,disabled:B,onChange:N=>T(N.currentTarget.value),children:[e("option",{value:"",children:"Unassigned"}),L.map(N=>e("option",{value:N.userId,children:N.userId===t.me.userId?`${N.displayName} (you)`:N.displayName},N.userId))]})]}),e("label",{children:["Reviewer",e("select",{class:"field",value:$,disabled:B,onChange:N=>x(N.currentTarget.value),children:[e("option",{value:"",children:"None yet"}),Y.map(N=>e("option",{value:N.userId,children:N.userId===t.me.userId?`${N.displayName} (you)`:N.displayName},N.userId))]})]})]}),e("label",{class:"team-wide",children:["Goal",e("textarea",{class:"field",rows:4,maxLength:16384,placeholder:"What should be true when this task is done, and why it matters",value:v,disabled:B,onInput:N=>g(N.currentTarget.value)})]}),e("label",{class:"team-wide",children:["Acceptance criteria",e("textarea",{class:"field",rows:3,maxLength:8192,placeholder:"How a reviewer will check the result",value:w,disabled:B,onInput:N=>C(N.currentTarget.value)})]}),ee?e("p",{class:"msg err",role:"alert",children:ee}):null,e("div",{class:"team-actions",children:[e("button",{type:"submit",class:"btn primary",disabled:B||!m?.repositories.length||!c.trim(),children:E?"Creating\u2026":"Create task"}),e("button",{type:"button",class:"btn",disabled:B,onClick:o,children:"Cancel"})]})]})}function Ah({shared:t,navigate:s}){let[n,a]=h(null),[r,o]=h(""),[i,d]=h(!1);Ee(async u=>{try{let p=await Qn();u()&&(a(p.items),o(""))}catch(p){u()&&o(p.message)}},t?0:15e3,[Nt.value]),_(()=>{if(!Gn.value)return;Gn.value=!1;let u=document.getElementById("team-inbox-title");u?.scrollIntoView({block:"start"}),u?.focus()},[Gn.value]);let l=async u=>{if(!i){d(!0);try{await Vc(u);let p=await Qn();a(p.items),xt()}catch(p){o(p.message)}finally{d(!1)}}},m=rs.value,c=(n??[]).slice().sort((u,p)=>+!!u.readAt-+!!p.readAt||p.at-u.at);return e("section",{class:"team-inbox","aria-labelledby":"team-inbox-title",children:[e("div",{class:"team-inbox-head",children:[e("h2",{id:"team-inbox-title",tabIndex:-1,children:["Inbox",m?e("span",{class:"team-count warn",children:m}):null]}),m?e("button",{type:"button",class:"btn small",disabled:i,onClick:()=>void l("all"),children:"Mark all read"}):null]}),r?e("p",{class:"msg err",role:"alert",children:r}):null,n===null&&!r?e("p",{class:"help",role:"status",children:"Loading\u2026"}):null,n&&!n.length?e("p",{class:"pp-empty",children:"Nothing yet. Assignments, mentions, review requests and hand-overs land here."}):null,c.map(u=>e("div",{class:`team-inbox-item ${u.readAt?"":"is-unread"}`,children:[e("button",{type:"button",class:"ti-open",onClick:()=>{u.readAt||l([u.id]),s({view:"team-task",id:u.taskId})},children:[e("span",{class:"ti-title",children:[Qc[u.kind]??u.kind,u.readAt?"":e("span",{class:"sr-only",children:" (unread)"})," \xB7 ",u.taskTitle]}),e("span",{class:"ti-text",children:u.text}),e("span",{class:"ti-meta",children:[u.by.displayName," \xB7 ",ut(u.at)]})]}),u.readAt?null:e("button",{type:"button",class:"btn small ghost",disabled:i,"aria-label":`Mark read: ${u.taskTitle}`,onClick:()=>void l([u.id]),children:"Mark read"})]},u.id))]})}var Eh=/(?<![A-Za-z0-9_.@-])@([A-Za-z0-9][A-Za-z0-9._-]{0,63})/g;function vu(t,s){let n=new Map(s.map(o=>[o.username.toLowerCase(),o])),a=[],r=0;for(let o of t.matchAll(Eh)){let i=o[1].toLowerCase();for(;i&&!n.has(i)&&/[._-]$/.test(i);)i=i.slice(0,-1);let d=n.get(i);if(!d)continue;let l=o.index,m=l+1+i.length;l>r&&a.push(t.slice(r,l)),a.push(e("strong",{class:"team-mention",title:d.displayName,children:t.slice(l,m)},l)),r=m}return r<t.length&&a.push(t.slice(r)),a}function no({id:t,shared:s=!1,navigate:n}){let[a,r]=h(null),[o,i]=h(""),[d,l]=h(""),[m,c]=h(Date.now()),[u,p]=h(null),[f,v]=h(null),g=An(),w=async()=>{let ie=g();try{let pe=await Wc(t);ie()&&(r(pe),i(""),os.value=pe)}catch(pe){ie()&&(r(null),os.value=null,p(null),v(null),i(pe.message))}};Ee(()=>{w(),xt(),s||(Xs(),kn()),c(Date.now())},s?0:15e3,[t,Nt.value,s]),Ee(()=>c(Date.now()),15e3,[],s),_(()=>((document.getElementById("main-content")??window).scrollTo({top:0}),()=>{os.value?.id===t&&(os.value=null)}),[t]);let C=async(ie,pe,ge)=>{if(d)return!1;l(ie),i("");try{let Ie=await pe();return Ie&&typeof Ie=="object"&&"id"in Ie&&(r(Ie),os.value=Ie),ge?.(),!0}catch(Ie){return Ie instanceof Ge&&Ie.status===409?(V("Task changed; reloading",3e3),await w()):(Ie instanceof Ge&&[401,403,404].includes(Ie.status)&&(r(null),os.value=null,p(null),v(null),xt()),i(Ie.message)),!1}finally{l("")}},k=Dt.value;if(!a)return e("div",{class:"team-page",children:[s?null:e(fs,{}),o?e("p",{class:"msg err",role:"alert",children:[o," ",e("button",{class:"btn small",onClick:()=>void w(),children:"Retry"})," ",e("button",{class:"btn small",onClick:()=>n({view:"team"}),children:"Back to the board"})]}):e("p",{class:"help",role:"status",children:"Loading the task\u2026"})]});let y=k?.me.userId,b=k?.projects.find(ie=>ie.id===a.projectId),T=b?.role??(y==="owner"?"maintainer":k?.me.roles[a.projectId]),$=b?.members??[],x=je(T,"contributor"),E=je(T,"reviewer"),A=je(T,"maintainer"),P=!!y&&a.owner?.userId===y,D=Zc(a),S=Ea(a),R=td(a),M=a.handoff?.state==="offered"?a.handoff:void 0,O=!!M&&M.to.userId===y,B=!!M&&M.from.userId===y,ee=Jt.value,se=!s&&P&&ee!==null,te=D?Kn.value.find(ie=>ie.attemptId===D.id):void 0,G=!!D&&!!te&&ed(D,a),L=(ie,pe="Saving\u2026")=>C(pe,()=>hs(`/api/team/tasks/${J(t)}`,{revision:a.revision,...ie})),Y=ie=>M&&C(ie==="decline"?"Declining\u2026":"Cancelling\u2026",()=>q(`/api/team/tasks/${J(t)}/handoff/${J(M.id)}`,{action:ie,revision:a.revision}),()=>V(ie==="decline"?"Hand-over declined":"Hand-over cancelled")),X=(ie,pe,ge,Ie)=>C(ge,async()=>{await q(`/api/team-link/tasks/${J(t)}${ie}`,pe)},()=>{V(Ie),w(),kn()}),N=D?Or(D,m):!1,ae=D?Pa(D,m):!1;return e("div",{class:"team-page team-task",children:[s?null:e(fs,{}),e("nav",{class:"team-back","aria-label":"Team board",children:e("a",{href:s?"#/team":`#/team/project/${J(a.projectId)}`,onClick:ie=>{ie.preventDefault(),n({view:"team",project:a.projectId})},children:[e(z,{name:"chevron",class:"back"})," ",b?.name??"Team board"]})}),e(Ph,{task:a,role:T,meId:y,members:$,canEdit:x,maintainer:A,busy:d,save:L,act:C,navigate:n}),o?e("p",{class:"msg err",role:"alert",children:o}):null,d?e("p",{class:"help",role:"status",children:d}):null,e("div",{class:"team-task-layout",children:[e("div",{class:"team-main",children:[e(jh,{task:a,canEdit:x,busy:d,save:L}),e("section",{class:"team-section","aria-labelledby":"tt-exec",children:[e("h2",{id:"tt-exec",children:"Execution"}),D?e(Mh,{attempt:D,meId:y,live:ae,stale:N}):e("p",{class:"help",children:["No attempt yet.",a.owner?"":" Take the task to run it on your computer."]}),e("div",{class:"team-actions",children:[te?.runId?e("a",{class:"btn small",href:`#/run/${J(te.runId)}`,children:"Open run"}):null,se?e(j,{children:[O?e(j,{children:[e("button",{type:"button",class:"btn small primary",disabled:!!d,onClick:()=>p("accept"),children:"Accept and download"}),e("button",{type:"button",class:"btn small",disabled:!!d,onClick:()=>void Y("decline"),children:"Decline"})]}):null,!M&&!S&&a.status!=="done"?e("button",{type:"button",class:"btn small primary",disabled:!!d,onClick:()=>p("start"),children:"Build with agents"}):null,S&&te?e("button",{type:"button",class:"btn small",disabled:!!d,onClick:async()=>{await Ce("Stop the attempt running on this computer? Its run can be resumed later and its work is kept.",{title:"Stop this attempt?",confirmLabel:"Stop attempt",danger:!0})&&X("/stop",{},"Stopping\u2026","Attempt stopped")},children:"Stop"}):null,G?e("button",{type:"button",class:"btn small",disabled:!!d,onClick:()=>void X("/resume",{},"Resuming\u2026","Attempt resumed"),children:"Resume"}):null,!M&&!S?e("button",{type:"button",class:"btn small",disabled:!!d,onClick:()=>p("handover"),children:"Hand over\u2026"}):null]}):null,D?.state==="unknown"&&(P&&x||A)?e("button",{type:"button",class:"btn small",disabled:!!d,onClick:()=>p("recover"),children:"Recover attempt\u2026"}):null,M&&!se&&O?e("button",{type:"button",class:"btn small",disabled:!!d,onClick:()=>void Y("decline"),children:"Decline hand-over"}):null,M&&(B||A)?e("button",{type:"button",class:"btn small",disabled:!!d,onClick:async()=>{await Ce("Cancel this hand-over? The task stays with its current owner.",{title:"Cancel hand-over?",confirmLabel:"Cancel hand-over",danger:!0})&&Y("cancel")},children:"Cancel hand-over"}):null,!a.owner&&x&&y?e("button",{type:"button",class:"btn small",disabled:!!d||!!Br(a,T,y),title:Br(a,T,y),onClick:()=>void L({owner:y},"Taking the task\u2026"),children:"Take this task"}):null]}),M?e("p",{class:"msg warn",role:"status",children:["Hand-over offered to ",Ut(M.to,y)," by ",Ut(M.from,y)," ",ut(M.offeredAt),M.note?`: ${M.note}`:""]}):null,s?e(hu,{task:a,meId:y},a.id):null,!s&&P&&ee===null?e("p",{class:"help",children:"This computer's team link is not available here, so the task cannot be run from this page."}):null]}),e(Dh,{task:a,latest:R,meId:y,canEdit:x,maintainer:A,shared:s,busy:d,act:C,onFetch:v,reload:w}),e(Nh,{task:a,latest:R,meId:y,members:$,canEdit:x,canComment:E,busy:d,act:C}),e(_h,{task:a,meId:y,members:$,canEdit:x,canComment:E,isOwner:P,maintainer:A,busy:d,act:C})]}),e("div",{class:"team-aside",children:[e(Lh,{task:a,role:T,meId:y,members:$,canEdit:x,busy:d,save:L}),e(Bh,{task:a,canEdit:x,busy:d,act:C}),e("details",{class:"team-section team-history",children:[e("summary",{children:["History ",e("span",{class:"team-count",children:a.audit.length})]}),e("ol",{children:a.audit.slice().reverse().map((ie,pe)=>e("li",{children:[e("span",{class:"th-when",children:Nr(ie.at)})," ",e("strong",{children:ie.by.displayName})," ",ie.action,ie.detail?e("span",{class:"th-detail",children:[" \u2014 ",ie.detail]}):null]},`${ie.at}-${pe}`))})]})]})]}),u==="start"?e(qh,{task:a,checkpoint:R,onClose:()=>p(null),onStarted:()=>{p(null),V("Agents started on this computer"),w(),kn()}}):null,u==="handover"&&y?e(Fh,{task:a,meId:y,members:$,onClose:()=>p(null),onDone:()=>{p(null),V("Hand-over offered"),w()}}):null,u==="recover"&&D?.state==="unknown"?e(Uh,{task:a,attempt:D,onClose:()=>p(null),onDone:()=>{p(null),V("Attempt recovered"),w(),kn()}}):null,u==="accept"&&M?e(bu,{title:"Accept and download",help:`The checkpoint is downloaded into your clone of ${a.repository} before the task becomes yours; a failed download changes nothing.`,action:"Accept and download",initial:ee?.mappings[a.projectId]?.[a.repository]??"",onClose:()=>p(null),submit:async ie=>{await q(`/api/team-link/tasks/${J(t)}/accept`,{handoffId:M.id,...ie?{repo:ie}:{}}),p(null),V("Hand-over accepted"),w()}}):null,f?e(bu,{title:"Fetch to this computer",help:`Imports checkpoint ${en(f.commit)} into the repository below as a branch; nothing is checked out.`,action:"Fetch",initial:ee?.mappings[a.projectId]?.[a.repository]??"",required:!0,onClose:()=>v(null),submit:async ie=>{let pe=await q(`/api/team-link/checkpoints/${J(f.id)}/fetch`,{repo:ie});v(null),V(`Fetched as branch ${pe.branch}`,5e3)}}):null]})}function Ph({task:t,role:s,meId:n,members:a,canEdit:r,maintainer:o,busy:i,save:d,act:l,navigate:m}){let[c,u]=h(!1),[p,f]=h(t.title),[v,g]=h(!1),[w,C]=h(t.blocker??"");_(()=>{c||f(t.title)},[t.title,c]),_(()=>{v||C(t.blocker??"")},[t.blocker,v]);let k=_r(t,"done",s),y=b=>b==="blocked"?_r(t,"blocked",s,"pending"):_r(t,b,s);return e("div",{class:"page-head team-task-head",children:[e("div",{class:"page-head-text",children:[c?e("form",{class:"team-title-edit",onSubmit:b=>{b.preventDefault(),p.trim()&&p.trim()!==t.title?d({title:p.trim()}).then(T=>{T&&u(!1)}):u(!1)},children:[e("label",{class:"sr-only",for:"tt-title",children:"Title"}),e("input",{id:"tt-title",class:"field",required:!0,maxLength:200,value:p,disabled:!!i,onInput:b=>f(b.currentTarget.value),onKeyDown:b=>{b.key==="Escape"&&(u(!1),f(t.title))}}),e("button",{type:"submit",class:"btn small primary",disabled:!!i||!p.trim(),children:"Save"}),e("button",{type:"button",class:"btn small",onClick:()=>{u(!1),f(t.title)},children:"Cancel"})]}):e("h1",{children:[t.title,r?e("button",{type:"button",class:"icon-btn team-edit","aria-label":"Edit the title",title:"Edit the title",disabled:!!i,onClick:()=>u(!0),children:e(z,{name:"note"})}):null]}),e("p",{class:"team-task-meta",children:[e("span",{class:`status-pill ${Gc[t.status]}`,children:Zs[t.status]}),e("code",{children:t.repository}),t.baseRef?e("span",{children:["base ",e("code",{children:t.baseRef})]}):null,e("span",{children:t.owner?e(j,{children:["Owned by ",Ut(t.owner,n)]}):"Unassigned"}),t.reviewer?e("span",{children:["Reviewed by ",Ut(t.reviewer,n)]}):null,e("span",{children:["Updated ",ut(t.updatedAt)]}),t.labels.map(b=>e("span",{class:"badge",children:b},b))]}),t.status==="blocked"&&t.blocker?e("p",{class:"msg warn",role:"status",children:[e("strong",{children:"Blocked:"})," ",t.blocker]}):null]}),e("div",{class:"page-head-actions",children:[e("label",{class:"team-status",children:["Status",e("select",{class:"field",value:t.status,disabled:!r||!!i,onChange:b=>{let T=b.currentTarget.value;if(T==="blocked"){g(!0);return}d({status:T})},children:Xn.map(b=>{let T=b===t.status?void 0:y(b);return e("option",{value:b,disabled:!!T,title:T,children:Zs[b]},b)})})]}),o?e("button",{type:"button",class:"btn small danger",disabled:!!i,onClick:async()=>{await Ce("Delete this task, its checkpoints and its discussion? This cannot be undone.",{title:"Delete this task?",confirmLabel:"Delete task",danger:!0})&&l("Deleting\u2026",async()=>{await Yn(`/api/team/tasks/${J(t.id)}`,{revision:t.revision})},()=>{V("Task deleted"),m({view:"team",project:t.projectId})})},children:"Delete task"}):null,r&&k&&t.status!=="done"?e("p",{class:"help",children:["Done is unavailable: ",k,"."]}):null,v?e("form",{class:"team-blocker",onSubmit:b=>{b.preventDefault(),w.trim()&&d({status:"blocked",blocker:w.trim()}).then(T=>{T&&g(!1)})},children:[e("label",{for:"tt-blocker",children:"What blocks the task?"}),e("textarea",{id:"tt-blocker",class:"field",rows:2,required:!0,maxLength:1e3,value:w,disabled:!!i,onInput:b=>C(b.currentTarget.value)}),e("div",{class:"team-actions",children:[e("button",{type:"submit",class:"btn small primary",disabled:!!i||!w.trim(),children:"Mark blocked"}),e("button",{type:"button",class:"btn small",onClick:()=>g(!1),children:"Cancel"})]})]}):null]})]})}function jh({task:t,canEdit:s,busy:n,save:a}){let[r,o]=h(t.goal),[i,d]=h(t.acceptance),l=Q({goal:t.goal,acceptance:t.acceptance});_(()=>{r===l.current.goal&&o(t.goal),l.current.goal=t.goal},[t.goal]),_(()=>{i===l.current.acceptance&&d(t.acceptance),l.current.acceptance=t.acceptance},[t.acceptance]);let m=(c,u,p,f,v,g,w)=>e("div",{class:"team-text",children:[e("label",{for:c,children:u}),s?e(j,{children:[e("textarea",{id:c,class:"field",rows:p.split(`
105
+ `).length>4?8:4,maxLength:v,value:p,disabled:!!n,onInput:C=>g(C.currentTarget.value)}),p!==f?e("div",{class:"team-actions",children:[e("button",{type:"button",class:"btn small primary",disabled:!!n,onClick:w,children:["Save ",u.toLowerCase()]}),e("button",{type:"button",class:"btn small",disabled:!!n,onClick:()=>g(f),children:"Discard"}),e("span",{class:"help",children:"Unsaved changes"})]}):null]}):f?e("p",{id:c,class:"team-prose",children:f}):e("p",{id:c,class:"help",children:"Not written yet."})]});return e("section",{class:"team-section","aria-labelledby":"tt-text",children:[e("h2",{id:"tt-text",children:"Goal and acceptance"}),m("tt-goal","Goal",r,t.goal,16384,o,()=>void a({goal:r})),m("tt-acceptance","Acceptance criteria",i,t.acceptance,8192,d,()=>void a({acceptance:i}))]})}function Mh({attempt:t,meId:s,live:n,stale:a}){let r=t.progress;return e(j,{children:[e("p",{class:"team-task-meta",children:[e("span",{class:`status-pill ${a?"failing":Yc[t.state]}`,children:a?"Connection lost":Dr[t.state]}),e("span",{children:["on ",e("strong",{children:t.runnerName})," by ",Ut(t.user,s)]}),n?e("span",{class:"team-live",children:[e("span",{class:"dot running","aria-hidden":"true"}),"Live \xB7 heard ",ut(t.lastHeartbeatAt)]}):e("span",{children:["Last heard ",ut(t.lastHeartbeatAt)]})]}),a?e("p",{class:"msg warn",role:"status",children:"Connection lost; execution status unknown. This task stays reserved until the runner reconnects and reports its state. Recover it only after confirming the original agent has stopped."}):null,e("dl",{class:"team-kv",children:[r.stage?e(j,{children:[e("dt",{children:"Stage"}),e("dd",{children:r.stage})]}):null,r.steps?e(j,{children:[e("dt",{children:"Steps"}),e("dd",{children:[r.steps.done,r.steps.total!==void 0?` of ${r.steps.total}`:""]})]}):null,r.runStatus||r.verdict?e(j,{children:[e("dt",{children:"Run"}),e("dd",{children:[r.runStatus??"",r.verdict?`${r.runStatus?" \xB7 ":""}check ${r.verdict}`:""]})]}):null,r.tests?e(j,{children:[e("dt",{children:"Tests"}),e("dd",{children:[e("span",{class:`badge ${r.tests.ok?"ok":"warn"}`,children:r.tests.ok?"Passing":"Failing"})," ",e("code",{children:r.tests.command})," \xB7 ",ut(r.tests.at)]})]}):null,r.branch||t.branch?e(j,{children:[e("dt",{children:"Branch"}),e("dd",{children:[e("code",{children:r.branch??t.branch}),r.head??t.head?e(j,{children:[" at ",e("code",{children:en(r.head??t.head)})]}):null]})]}):null,e("dt",{children:"Base"}),e("dd",{children:[e("code",{children:en(t.baseCommit)}),t.fromCheckpointId?" \xB7 continued from a checkpoint":""]}),e("dt",{children:"Started"}),e("dd",{children:[Nr(t.startedAt??t.createdAt),t.endedAt?` \xB7 ended ${ut(t.endedAt)}`:""]}),t.reason?e(j,{children:[e("dt",{children:"Reason"}),e("dd",{children:t.reason})]}):null]}),r.summary?e("pre",{class:"team-prose",children:r.summary}):null,r.blockers?.length?e("div",{class:"msg warn",role:"status",children:[e("strong",{children:"Blockers"}),e("ul",{class:"team-list",children:r.blockers.map((o,i)=>e("li",{children:o},i))})]}):null,r.changedFiles?.length?e("details",{class:"team-files",children:[e("summary",{children:[r.changedFiles.length," changed file",r.changedFiles.length===1?"":"s"]}),e("ul",{class:"team-list mono",children:r.changedFiles.map(o=>e("li",{children:o},o))})]}):null]})}function Lh({task:t,role:s,meId:n,members:a,canEdit:r,busy:o,save:i}){let d=Dt.value,l=d?.projects.find($=>$.id===t.projectId),m=je(s,"maintainer"),c=a.filter($=>je($.role,"contributor")&&(m||$.userId===n));t.owner&&!c.some($=>$.userId===t.owner.userId)&&c.unshift({userId:t.owner.userId,username:t.owner.userId,displayName:t.owner.displayName,role:"contributor",online:!1});let u=a.filter($=>je($.role,"reviewer")),p=(d?.tasks??[]).filter($=>$.projectId===t.projectId&&$.id!==t.id),f=Br(t,s,n),[v,g]=h(t.baseRef??""),[w,C]=h(t.labels.join(", "));_(()=>g(t.baseRef??""),[t.baseRef]),_(()=>C(t.labels.join(", ")),[t.labels.join(", ")]);let[k,y]=h(0),b=`${t.dependsOn.join(",")}:${k}`,T=!r||!!o;return e("section",{class:"team-section","aria-labelledby":"tt-fields",children:[e("h2",{id:"tt-fields",children:"Details"}),e("div",{class:"team-fields column",children:[e("label",{children:["Owner",e("select",{class:"field",value:t.owner?.userId??"",disabled:T||!!f,title:f,onChange:$=>void i({owner:$.currentTarget.value||null}),children:[e("option",{value:"",children:"Unassigned"}),c.map($=>e("option",{value:$.userId,children:$.userId===n?`${$.displayName} (you)`:$.displayName},$.userId))]}),f&&r?e("span",{class:"help",children:f}):null]}),e("label",{children:["Reviewer",e("select",{class:"field",value:t.reviewer?.userId??"",disabled:T,onChange:$=>void i({reviewer:$.currentTarget.value||null}),children:[e("option",{value:"",children:"None"}),u.map($=>e("option",{value:$.userId,children:$.userId===n?`${$.displayName} (you)`:$.displayName},$.userId))]})]}),e("label",{children:["Repository",e("select",{class:"field",value:t.repository,disabled:T,onChange:$=>void i({repository:$.currentTarget.value}),children:[l?.repositories.some($=>$.key===t.repository)?null:e("option",{value:t.repository,children:t.repository}),l?.repositories.map($=>e("option",{value:$.key,children:[$.label," (",$.key,")"]},$.key))]})]}),e("label",{children:["Base branch",e("input",{class:"field",maxLength:100,value:v,disabled:T,placeholder:"The repository's default branch",onInput:$=>g($.currentTarget.value),onBlur:()=>{v.trim()!==(t.baseRef??"")&&i({baseRef:v.trim()||null})},onKeyDown:$=>{$.key==="Enter"&&($.preventDefault(),$.currentTarget.blur())}})]}),e("label",{children:["Labels",e("input",{class:"field",maxLength:450,value:w,disabled:T,placeholder:"Comma-separated, up to 10",onInput:$=>C($.currentTarget.value),onBlur:()=>{let $=[...new Set(w.split(",").map(x=>x.trim()).filter(Boolean))].slice(0,10);$.join(", ")!==t.labels.join(", ")&&i({labels:$})},onKeyDown:$=>{$.key==="Enter"&&($.preventDefault(),$.currentTarget.blur())}})]}),a.length?e("fieldset",{class:"team-checks",disabled:T,children:[e("legend",{children:"Collaborators"}),a.filter($=>$.userId!==t.owner?.userId).map($=>e("label",{class:"check",children:[e("input",{type:"checkbox",checked:t.collaborators.some(x=>x.userId===$.userId),onChange:x=>{let E=t.collaborators.map(A=>A.userId).filter(A=>A!==$.userId);x.currentTarget.checked&&E.push($.userId),i({collaborators:E.slice(0,20)})}})," ",$.userId===n?`${$.displayName} (you)`:$.displayName]},$.userId))]}):null,p.length?e("label",{children:["Depends on",e("select",{class:"field",multiple:!0,size:Math.min(5,Math.max(2,p.length)),disabled:T,onChange:$=>void i({dependsOn:[...$.currentTarget.selectedOptions].map(x=>x.value).slice(0,20)}).then(x=>{x||y(E=>E+1)}),children:p.map($=>e("option",{value:$.id,selected:t.dependsOn.includes($.id),children:[$.title," \xB7 ",Zs[$.status]]},$.id))},b)]}):null]}),e("dl",{class:"team-kv",children:[e("dt",{children:"Created"}),e("dd",{children:[Nr(t.createdAt)," by ",t.createdBy.displayName]}),e("dt",{children:"Project"}),e("dd",{children:l?.name??t.projectId}),t.dependsOn.length?e(j,{children:[e("dt",{children:"Depends on"}),e("dd",{children:t.dependsOn.map($=>p.find(x=>x.id===$)?.title??$).join(", ")})]}):null]})]})}function Dh({task:t,latest:s,meId:n,canEdit:a,maintainer:r,shared:o,busy:i,act:d,onFetch:l,reload:m}){let c=t.checkpoints.slice().sort((u,p)=>p.at-u.at);return e("section",{class:"team-section","aria-labelledby":"tt-checkpoints",children:[e("h2",{id:"tt-checkpoints",children:["Checkpoints",e("span",{class:"team-count",children:c.length})]}),c.length?null:e("p",{class:"help",children:"None yet. An attempt publishes a checkpoint (a Git bundle of its commits plus the context the next agent needs) when it finishes or is handed over."}),c.map(u=>e("article",{class:"team-item",children:[e("div",{class:"team-task-meta",children:[e("code",{children:en(u.commit)}),e("code",{children:u.branch}),e("span",{children:Ht(u.size)}),e("span",{children:["by ",Ut(u.createdBy,n)]}),e("span",{children:ut(u.at)}),u===s?e("span",{class:"badge ok",children:"Latest"}):null,u.bundle==="pending"?e("span",{class:"badge warn",children:"Uploading"}):u.bundle==="deleted"?e("span",{class:"badge warn",children:"Bundle deleted"}):null,u.testResults?e("span",{class:`badge ${u.testResults.ok?"ok":"warn"}`,children:["Tests ",u.testResults.ok?"passing":"failing"]}):null]}),u.note?e("p",{class:"team-comment-text",children:u.note}):null,u.remaining?e("details",{children:[e("summary",{children:"Remaining work"}),e("pre",{class:"team-prose",children:u.remaining})]}):null,u.changedFiles.length?e("details",{children:[e("summary",{children:[u.changedFiles.length," changed file",u.changedFiles.length===1?"":"s"]}),e("ul",{class:"team-list mono",children:u.changedFiles.map(p=>e("li",{children:p},p))})]}):null,e("div",{class:"team-actions",children:[!o&&a&&u.bundle==="available"?e("button",{type:"button",class:"btn small",disabled:!!i,onClick:()=>l(u),children:"Fetch to this computer\u2026"}):null,a&&u.bundle==="available"?e("a",{class:"btn small",href:vs(`/api/team/checkpoints/${J(u.id)}/bundle`),download:`checkpoint-${u.id.slice(0,8)}.bundle`,children:"Download bundle"}):null,r&&u.bundle!=="deleted"?e("button",{type:"button",class:"btn small danger",disabled:!!i,onClick:async()=>{await Ce("Delete this checkpoint's bundle? Teammates can no longer download or continue from it.",{title:"Delete checkpoint bundle?",confirmLabel:"Delete bundle",danger:!0})&&d("Deleting\u2026",async()=>{await Yn(`/api/team/checkpoints/${J(u.id)}`)},()=>void m())},children:"Delete"}):null]})]},u.id))]})}function Nh({task:t,latest:s,meId:n,members:a,canEdit:r,canComment:o,busy:i,act:d}){let[l,m]=h(t.reviewer?.userId??""),[c,u]=h("approve"),[p,f]=h(""),v=a.filter(C=>je(C.role,"reviewer")),g=t.reviews.slice().sort((C,k)=>k.at-C.at),w=s?g.filter(C=>C.checkpointId===s.id&&!C.stale)[0]:void 0;return e("section",{class:"team-section","aria-labelledby":"tt-reviews",children:[e("h2",{id:"tt-reviews",children:["Reviews",w?e("span",{class:`badge ${w.verdict==="approve"?"ok":"warn"}`,children:w.verdict==="approve"?"Approved":"Changes requested"}):t.reviewer&&s?e("span",{class:"badge",children:"Pending"}):null]}),r?e("form",{class:"team-inline",onSubmit:C=>{C.preventDefault(),l&&d("Requesting a review\u2026",()=>q(`/api/team/tasks/${J(t.id)}/review-request`,{reviewer:l,revision:t.revision}),()=>V("Review requested"))},children:[e("label",{children:["Request a review from",e("select",{class:"field",value:l,disabled:!!i,onChange:C=>m(C.currentTarget.value),children:[e("option",{value:"",children:"Choose a reviewer"}),v.map(C=>e("option",{value:C.userId,children:C.userId===n?`${C.displayName} (you)`:C.displayName},C.userId))]})]}),e("button",{type:"submit",class:"btn small",disabled:!!i||!l,children:"Request review"})]}):null,o&&s?e("form",{class:"team-review-form",onSubmit:C=>{C.preventDefault(),d("Recording the review\u2026",()=>q(`/api/team/tasks/${J(t.id)}/reviews`,{checkpointId:s.id,verdict:c,text:p,revision:t.revision}),()=>{f(""),V("Review recorded")})},children:[e("fieldset",{disabled:!!i,children:[e("legend",{children:["Record a review of checkpoint ",e("code",{children:en(s.commit)})]}),e("label",{class:"check",children:[e("input",{type:"radio",name:"tt-verdict",value:"approve",checked:c==="approve",onChange:()=>u("approve")})," Approve"]}),e("label",{class:"check",children:[e("input",{type:"radio",name:"tt-verdict",value:"request-changes",checked:c==="request-changes",onChange:()=>u("request-changes")})," Request changes"]})]}),e("label",{for:"tt-review-text",children:"Review notes"}),e("textarea",{id:"tt-review-text",class:"field",rows:3,maxLength:4e3,value:p,disabled:!!i,onInput:C=>f(C.currentTarget.value)}),e("div",{class:"team-actions",children:e("button",{type:"submit",class:"btn small primary",disabled:!!i||c==="request-changes"&&!p.trim(),children:"Record review"})})]}):o?e("p",{class:"help",children:"Reviews attach to a checkpoint; this task has none yet."}):null,g.map(C=>e("article",{class:"team-item",children:[e("div",{class:"team-task-meta",children:[e("span",{class:`badge ${C.verdict==="approve"?"ok":"warn"}`,children:C.verdict==="approve"?"Approved":"Changes requested"}),e("span",{children:["by ",Ut(C.by,n)]}),e("code",{children:en(C.commit)}),e("span",{children:ut(C.at)}),C.stale?e("span",{class:"badge",children:"Stale \xB7 a newer checkpoint exists"}):null]}),C.text?e("p",{class:"team-comment-text",children:C.text}):null]},C.id)),g.length?null:e("p",{class:"help",children:"No reviews recorded."})]})}var Oh={proposed:"Proposed",approved:"Approved",declined:"Declined",delivered:"Delivered to the agent"};function _h({task:t,meId:s,members:n,canEdit:a,canComment:r,isOwner:o,maintainer:i,busy:d,act:l}){let[m,c]=h(""),[u,p]=h(!1),f=[...t.discussion.map(g=>({kind:"comment",at:g.at,comment:g})),...t.instructions.map(g=>({kind:"instruction",at:g.at,instruction:g}))].sort((g,w)=>g.at-w.at),v=(g,w)=>l(w==="approve"?"Approving\u2026":"Declining\u2026",()=>q(`/api/team/tasks/${J(t.id)}/instructions/${J(g.id)}`,{action:w}));return e("section",{class:"team-section","aria-labelledby":"tt-discussion",children:[e("h2",{id:"tt-discussion",children:["Discussion",e("span",{class:"team-count",children:f.length})]}),e("div",{class:"team-timeline",children:[f.length?null:e("p",{class:"help",children:"No comments yet. Mention a teammate with @username to notify them."}),f.map(g=>g.kind==="comment"?e("article",{class:`team-comment ${g.comment.kind}`,children:[e("div",{class:"team-comment-head",children:[e("span",{class:"team-avatar","aria-hidden":"true",children:Aa(g.comment.by.displayName)}),e("strong",{children:Ut(g.comment.by,s)}),g.comment.kind==="system"?e("span",{class:"badge",children:"System"}):g.comment.kind==="review-request"?e("span",{class:"badge",children:"Review request"}):null,e("span",{children:ut(g.comment.at)})]}),e("p",{class:"team-comment-text",children:vu(g.comment.text,n)})]},g.comment.id):e("article",{class:`team-comment instruction ${g.instruction.state}`,children:[e("div",{class:"team-comment-head",children:[e("span",{class:"team-avatar","aria-hidden":"true",children:Aa(g.instruction.by.displayName)}),e("strong",{children:Ut(g.instruction.by,s)}),e("span",{class:`badge ${g.instruction.state==="declined"?"warn":g.instruction.state==="proposed"?"":"ok"}`,children:["Send to agent \xB7 ",Oh[g.instruction.state]]}),e("span",{children:ut(g.instruction.at)}),g.instruction.decidedBy?e("span",{children:[g.instruction.state==="declined"?"declined":"approved"," by ",Ut(g.instruction.decidedBy,s)]}):null]}),e("p",{class:"team-comment-text",children:vu(g.instruction.text,n)}),g.instruction.state==="proposed"&&(o||i)?e("div",{class:"team-actions",children:[e("button",{type:"button",class:"btn small primary",disabled:!!d,onClick:()=>void v(g.instruction,"approve"),children:"Approve"}),e("button",{type:"button",class:"btn small",disabled:!!d,onClick:()=>void v(g.instruction,"decline"),children:"Decline"})]}):null]},g.instruction.id))]}),r?e("form",{class:"team-composer",onSubmit:g=>{g.preventDefault();let w=m.trim();w&&l(u?"Sending to the agent\u2026":"Posting\u2026",()=>q(`/api/team/tasks/${J(t.id)}/${u?"instructions":"comments"}`,{text:w}),()=>{c(""),u&&V(o?"Instruction approved; the agent receives it on its next heartbeat":"Instruction proposed to the task owner",4e3)})},children:[e("label",{for:"tt-comment",children:u?"Instruction for the agent":"Comment"}),e("textarea",{id:"tt-comment",class:"field",rows:3,maxLength:4e3,value:m,disabled:!!d,placeholder:u?"What the running agent should do next":"Write a comment; @username notifies a teammate",onInput:g=>c(g.currentTarget.value),onKeyDown:g=>{g.key==="Enter"&&(g.metaKey||g.ctrlKey)&&(g.preventDefault(),g.currentTarget.form?.requestSubmit())}}),e("div",{class:"team-actions",children:[e("button",{type:"submit",class:"btn small primary",disabled:!!d||!m.trim(),children:u?"Send to agent":"Post comment"}),a?e("label",{class:"check",children:[e("input",{type:"checkbox",role:"switch","aria-checked":u,checked:u,disabled:!!d,onChange:g=>p(g.currentTarget.checked)})," Send to agent"]}):null,u?e("span",{class:"help",children:o?"Your instructions are approved at once and reach the agent as a note at its next heartbeat.":"The task owner or a project maintainer approves instructions before the agent sees them."}):null]})]}):e("p",{class:"help",children:"A project reviewer role is needed to comment."})]})}function Bh({task:t,canEdit:s,busy:n,act:a}){let[r,o]=h("");return e("section",{class:"team-section","aria-labelledby":"tt-decisions",children:[e("h2",{id:"tt-decisions",children:["Decisions",e("span",{class:"team-count",children:t.decisions.length})]}),e("p",{class:"help",children:"Choices that bind the work: every checkpoint carries them to the next agent."}),t.decisions.length?e("ul",{class:"team-list decisions",children:t.decisions.map(i=>e("li",{children:[e("span",{children:i.text}),e("span",{class:"help",children:[i.by.displayName," \xB7 ",ut(i.at)]})]},i.id))}):null,s?e("form",{class:"team-inline",onSubmit:i=>{i.preventDefault();let d=r.trim();d&&a("Adding the decision\u2026",()=>q(`/api/team/tasks/${J(t.id)}/decisions`,{text:d}),()=>o(""))},children:[e("label",{children:["Add a decision",e("input",{class:"field",maxLength:2e3,value:r,disabled:!!n,onInput:i=>o(i.currentTarget.value)})]}),e("button",{type:"submit",class:"btn small",disabled:!!n||!r.trim(),children:"Add"})]}):null]})}function qh({task:t,checkpoint:s,onClose:n,onStarted:a}){let r=we(!0,n);_(()=>{Za()},[]);let o=Jt.value,i=o?.mappings[t.projectId]?.[t.repository]??"",d=ve.value,[l,m]=h(i),[c,u]=h(()=>{let L=o?.defaults?.pattern;return L&&d.some(Y=>Y.id===L)?L:d.some(Y=>Y.id==="solo")?"solo":d[0]?.id??""}),p=d.find(L=>L.id===c),f=Be.value.filter(L=>L.available),[v,g]=h({}),[w,C]=h(Ue.value),[k,y]=h(""),[b,T]=h(Se.value.maxMinutes),[$,x]=h(Se.value.maxSteps),[E,A]=h(()=>{let L=o?.defaults?.trust;return L&&L in La?L:Tt.value}),P=!!s&&s.bundle==="available",[D,S]=h(P),[R,M]=h(!1),[O,B]=h(""),ee=L=>{let X=(v[L.id]??o?.defaults?.roles?.[L.id]??L.default).filter(N=>f.some(ae=>ae.id===N));return L.id in v||X.length?L.multiple?X:X.slice(0,1):f[0]?[f[0].id]:[]},se=p?.id==="auto-team"?4:1,te=!!p&&f.length>0&&!!l.trim()&&p.roles.every(L=>L.optional||ee(L).length>0)&&Number.isInteger($)&&$>=se&&$<=200&&Number.isInteger(b)&&b>=1&&b<=720&&(!p.requiresCheck||!!k.trim()),G=async L=>{if(L.preventDefault(),!(R||!p||!te)){M(!0),B("");try{await q(`/api/team-link/tasks/${J(t.id)}/start`,{...l.trim()?{repo:l.trim()}:{},pattern:p.id,roles:Object.fromEntries(p.roles.map(Y=>[Y.id,ee(Y)])),trust:E,agentSettings:w,loop:{...k.trim()?{check:k.trim()}:{},maxMinutes:b,maxSteps:$},...D&&s?{fromCheckpointId:s.id}:{}}),a()}catch(Y){B(Y.message),M(!1)}}};return e("dialog",{class:"picker team-build-dialog",ref:r,"aria-labelledby":"tt-start-title",children:e("form",{class:"picker-inner",onSubmit:L=>void G(L),children:[e("div",{class:"picker-head",children:[e("h3",{id:"tt-start-title",children:"Build with agents"}),e("p",{class:"help",children:"Build on this computer in a worktree of your clone. Progress, checks and a checkpoint return to this task for review."})]}),e("div",{class:"dialog-body",children:[e("label",{for:"tt-start-repo",children:["Repository path for ",e("code",{children:t.repository})]}),e("div",{class:"row-inline",children:[e("input",{id:"tt-start-repo",class:"field mono",value:l,placeholder:i||"/absolute/path/to/your/clone",disabled:R,onInput:L=>m(L.currentTarget.value)}),e("button",{type:"button",class:"btn small",disabled:R||!ne.value,title:ne.value||"Choose a repository in the composer first",onClick:()=>m(ne.value),children:"Use current repository"})]}),!i&&!l?e("p",{class:"help",children:"No folder is mapped for this repository key yet; the path you enter here is used for this attempt (map it for good in Connections \u2192 Share access)."}):null,e("label",{for:"tt-start-pattern",children:"Workflow"}),e("select",{id:"tt-start-pattern",class:"field",value:c,disabled:R,onChange:L=>{u(L.currentTarget.value),g({})},children:d.map(L=>e("option",{value:L.id,children:L.name},L.id))}),p?e(j,{children:[e("p",{class:"help",children:p.summary}),e("fieldset",{class:"team-roles",disabled:R,children:[e("legend",{children:"Agents"}),p.roles.map(L=>L.multiple?e("fieldset",{class:"team-checks",children:[e("legend",{children:L.label}),f.map(Y=>e("label",{class:"check",children:[e("input",{type:"checkbox",checked:ee(L).includes(Y.id),onChange:X=>g({...v,[L.id]:X.currentTarget.checked?[...ee(L),Y.id]:ee(L).filter(N=>N!==Y.id)})}),Y.displayName]},Y.id))]},L.id):e("label",{children:[L.label,e("select",{class:"field","aria-label":L.label,value:ee(L)[0]??"",onChange:Y=>g({...v,[L.id]:Y.currentTarget.value?[Y.currentTarget.value]:[]}),children:[L.optional?e("option",{value:"",children:"None"}):null,f.map(Y=>e("option",{value:Y.id,children:Y.displayName},Y.id))]})]},L.id))]})]}):null,f.length?null:e("p",{class:"msg warn",children:"Install and sign in to an agent on this computer before building."}),e("details",{children:[e("summary",{children:"Models and reasoning"}),e("fieldset",{disabled:R,children:f.filter(L=>p?.roles.some(Y=>ee(Y).includes(L.id))).map(L=>e(fr,{agent:L,used:!0,settings:w[L.id]??{},onChange:Y=>C({...w,[L.id]:{...w[L.id],...Y}})},L.id))})]}),e("label",{children:["Check command",e("input",{class:"field",maxLength:1e3,required:p?.requiresCheck,placeholder:"Use repository default, or enter e.g. npm test",value:k,disabled:R,onInput:L=>y(L.currentTarget.value)})]}),e("div",{class:"team-fields",children:[e("label",{children:["Time budget (minutes)",e("input",{class:"field",type:"number",min:1,max:720,value:b,disabled:R,onInput:L=>T(Number(L.currentTarget.value))})]}),e("label",{children:["Agent call budget",e("input",{class:"field",type:"number",min:se,max:200,value:$,disabled:R,onInput:L=>x(Number(L.currentTarget.value))})]})]}),e("label",{for:"tt-start-trust",children:"Agent permissions"}),e("select",{id:"tt-start-trust",class:"field",value:E,disabled:R,onChange:L=>A(L.currentTarget.value),children:Object.keys(La).map(L=>e("option",{value:L,children:La[L].label},L))}),e("p",{class:E==="full"?"msg warn":"help",children:La[E].help}),s?e("label",{class:"check",children:[e("input",{type:"checkbox",checked:D,disabled:R||!P,onChange:L=>S(L.currentTarget.checked)})," Continue from the latest checkpoint (",en(s.commit),", ",ut(s.at),")",P?"":" \u2014 its bundle is not available"]}):null,O?e("p",{class:"msg err",role:"alert",children:O}):null]}),e("div",{class:"picker-foot",children:[e("span",{class:"ps",children:R?"Starting\u2026":""}),e("button",{type:"button",class:"btn",disabled:R,onClick:n,children:"Cancel"}),e("button",{type:"submit",class:"btn primary",disabled:R||!te,children:"Build with agents"})]})]})})}function Uh({task:t,attempt:s,onClose:n,onDone:a}){let r=we(!0,n),[o,i]=h(""),[d,l]=h(!1),[m,c]=h(!1),[u,p]=h("");return e("dialog",{class:"picker small-dialog",ref:r,"aria-labelledby":"tt-recover-title",children:e("form",{class:"picker-inner",onSubmit:async f=>{if(f.preventDefault(),!(m||!d||!o.trim())){c(!0),p("");try{await q(`/api/team/attempts/${J(s.id)}/recover`,{revision:t.revision,reason:o.trim(),confirmedStopped:!0}),a()}catch(v){p(v.message),c(!1)}}},children:[e("div",{class:"picker-head",children:[e("h3",{id:"tt-recover-title",children:"Recover attempt"}),e("p",{class:"help",children:["Check ",s.runnerName," first. Stop the original agent or shut down its computer before releasing this task. Recovery prevents that attempt from resuming and lets you start from a checkpoint."]})]}),e("div",{class:"dialog-body",children:[e("label",{for:"tt-recover-reason",children:"How did you confirm execution stopped?"}),e("textarea",{id:"tt-recover-reason",class:"field",required:!0,rows:3,maxLength:1e3,value:o,disabled:m,onInput:f=>i(f.currentTarget.value)}),e("label",{class:"check",children:[e("input",{type:"checkbox",checked:d,disabled:m,onChange:f=>l(f.currentTarget.checked)})," I confirmed the original agent has stopped."]}),u?e("p",{class:"msg err",role:"alert",children:u}):null]}),e("div",{class:"picker-foot",children:[e("button",{type:"button",class:"btn",disabled:m,onClick:n,children:"Cancel"}),e("button",{type:"submit",class:"btn primary",disabled:m||!d||!o.trim(),children:"Release task"})]})]})})}function Fh({task:t,meId:s,members:n,onClose:a,onDone:r}){let o=we(!0,a),i=n.filter(k=>k.userId!==s&&je(k.role,"contributor")),[d,l]=h(i[0]?.userId??""),[m,c]=h(""),[u,p]=h(!1),[f,v]=h(!1),[g,w]=h(""),C=async k=>{if(k.preventDefault(),!(f||!d)){v(!0),w("");try{await q(`/api/team-link/tasks/${J(t.id)}/handover`,{to:d,note:m,includeUncommitted:u}),r()}catch(y){w(y.message),v(!1)}}};return e("dialog",{class:"picker small-dialog",ref:o,"aria-labelledby":"tt-handover-title",children:e("form",{class:"picker-inner",onSubmit:k=>void C(k),children:[e("div",{class:"picker-head",children:[e("h3",{id:"tt-handover-title",children:"Hand over"}),e("p",{class:"help",children:"Offers the task with a checkpoint of your work; the teammate continues from it on their own computer once they accept."})]}),e("div",{class:"dialog-body",children:[e("label",{for:"tt-handover-to",children:"Teammate"}),e("select",{id:"tt-handover-to",class:"field",required:!0,value:d,disabled:f,onChange:k=>l(k.currentTarget.value),children:[i.length?null:e("option",{value:"",children:"No other contributor in this project"}),i.map(k=>e("option",{value:k.userId,children:[k.displayName,k.online?" \xB7 online":""]},k.userId))]}),e("label",{for:"tt-handover-note",children:"Note for them"}),e("textarea",{id:"tt-handover-note",class:"field",rows:4,maxLength:4e3,value:m,disabled:f,placeholder:"Where you stopped, what to look at first",onInput:k=>c(k.currentTarget.value)}),e("label",{class:"check",children:[e("input",{type:"checkbox",checked:u,disabled:f,onChange:k=>p(k.currentTarget.checked)}),' Include uncommitted changes (committed on the run branch as "Hand-over checkpoint")']}),g?e("p",{class:"msg err",role:"alert",children:g}):null]}),e("div",{class:"picker-foot",children:[e("span",{class:"ps",children:f?"Creating the checkpoint\u2026":""}),e("button",{type:"button",class:"btn",disabled:f,onClick:a,children:"Cancel"}),e("button",{type:"submit",class:"btn primary",disabled:f||!d,children:"Offer hand-over"})]})]})})}function bu({title:t,help:s,action:n,initial:a,required:r=!1,onClose:o,submit:i}){let d=we(!0,o),[l,m]=h(a),[c,u]=h(!1),[p,f]=h("");return e("dialog",{class:"picker small-dialog",ref:d,"aria-labelledby":"tt-path-title",children:e("form",{class:"picker-inner",onSubmit:async v=>{if(v.preventDefault(),!c){u(!0),f("");try{await i(l.trim())}catch(g){f(g.message),u(!1)}}},children:[e("div",{class:"picker-head",children:[e("h3",{id:"tt-path-title",children:t}),e("p",{class:"help",children:s})]}),e("div",{class:"dialog-body",children:[e("label",{for:"tt-path",children:"Repository path"}),e("div",{class:"row-inline",children:[e("input",{id:"tt-path",class:"field mono",required:r,value:l,placeholder:a||"/absolute/path/to/your/clone",disabled:c,onInput:v=>m(v.currentTarget.value)}),e("button",{type:"button",class:"btn small",disabled:c||!ne.value,title:ne.value||"Choose a repository in the composer first",onClick:()=>m(ne.value),children:"Use current repository"})]}),!a&&!r?e("p",{class:"help",children:"Leave empty to use the folder mapped for this repository key in Connections \u2192 Share access."}):null,p?e("p",{class:"msg err",role:"alert",children:p}):null]}),e("div",{class:"picker-foot",children:[e("span",{class:"ps",children:c?"Working\u2026":""}),e("button",{type:"button",class:"btn",disabled:c,onClick:o,children:"Cancel"}),e("button",{type:"submit",class:"btn primary",disabled:c||r&&!l.trim(),children:n})]})]})})}var bi=()=>location.reload(),is=t=>t instanceof Error?t.message:"The request failed";function VT({onSignedIn:t=bi}){let[s,n]=h(""),[a,r]=h(""),[o,i]=h(!1),[d,l]=h(""),m=Q(null);return e("main",{class:"shared-surface shared-login",children:e("div",{class:"shared-card",children:[e("div",{class:"shared-brand",children:["code",e("span",{children:"-flow"})]}),e("h1",{children:"Sign in to shared projects"}),e("p",{class:"shared-lede",children:"Use the account your code-flow owner created. Shared access lets you view project results and, when assigned, record human reviews."}),e("form",{class:"shared-form",onSubmit:async c=>{if(c.preventDefault(),!o){i(!0),l("");try{await q("/api/auth/login",{username:s,password:a}),r(""),t()}catch(u){r(""),l(is(u)),m.current?.focus()}finally{i(!1)}}},children:[e("label",{for:"shared-username",children:"Username"}),e("input",{id:"shared-username",class:"field",value:s,maxLength:64,autoComplete:"username",required:!0,onInput:c=>n(c.currentTarget.value)}),e("label",{for:"shared-password",children:"Password"}),e("input",{ref:m,id:"shared-password",class:"field",type:"password",value:a,autoComplete:"current-password",required:!0,onInput:c=>r(c.currentTarget.value)}),d?e("p",{class:"shared-error",role:"alert",children:d}):null,e("button",{class:"btn primary shared-submit",type:"submit",disabled:o||!s||!a,children:o?"Signing in\u2026":"Sign in"})]}),e("p",{class:"help",children:"The owner can still use the recovery link printed in the server terminal. Network sign-in requires HTTPS."})]})})}function ku({projects:t,projectId:s}){let[n,a]=h(null),[r,o]=h(""),[i,d]=h(""),[l,m]=h(""),[c,u]=h(""),[p,f]=h(!0),[v,g]=h({}),[w,C]=h(!1),[k,y]=h(""),[b,T]=h(""),$=A=>{o(A?.id??""),d(A?.username??""),m(A?.displayName??""),f(A?.enabled??!0),g(A?.roles??{}),u(""),y(""),T("")},x=async()=>{C(!0);try{a(await U("/api/accounts")),y("")}catch(A){y(is(A))}finally{C(!1)}};_(()=>{x()},[]);let E=async()=>{if(n){C(!0),y(""),T("");try{let A=r?await U(`/api/accounts/${J(r)}`,{method:"PUT",body:JSON.stringify({revision:n.revision,displayName:l,enabled:p,roles:v,...c?{password:c}:{}})}):await q("/api/accounts",{revision:n.revision,username:i,displayName:l,password:c,roles:v});a(A);let P=r?A.users.find(D=>D.id===r):A.users.find(D=>D.username===i.toLowerCase());$(P),T("Account saved. Updated accounts must sign in again.")}catch(A){y(is(A))}finally{u(""),C(!1)}}};return e("section",{class:"shared-surface shared-accounts","aria-label":"Shared project accounts",children:[e("h2",{children:"Shared project accounts"}),e("p",{class:"help",children:"Viewers can inspect assigned results. Reviewers can also record file reviews and leave comments. Contributors can also own team tasks and run them on their own computer; maintainers can also assign any task owner, define repository keys, delete tasks and checkpoints, revoke runners, cancel hand-overs and approve instructions to agents. Execution on this server, merges, terminals, secrets and system settings stay with the owner."}),e("label",{for:"shared-account",children:"Account"}),e("select",{id:"shared-account",class:"field",value:r,disabled:w,onChange:A=>$(n?.users.find(P=>P.id===A.currentTarget.value)),children:[e("option",{value:"",children:"New account\u2026"}),n?.users.map(A=>e("option",{value:A.id,children:[A.displayName," (",A.username,")",A.enabled?"":" \xB7 disabled"]},A.id))]}),e("form",{class:"shared-form",onSubmit:A=>{A.preventDefault(),E()},children:[e("label",{for:"account-username",children:"Account username"}),e("input",{id:"account-username",class:"field",value:i,required:!0,maxLength:64,disabled:!!r||w,autoComplete:"off",onInput:A=>d(A.currentTarget.value)}),e("label",{for:"account-name",children:"Display name"}),e("input",{id:"account-name",class:"field",value:l,required:!0,maxLength:120,disabled:w,onInput:A=>m(A.currentTarget.value)}),e("label",{for:"account-password",children:r?"Replace password (leave empty to keep)":"Initial password"}),e("input",{id:"account-password",class:"field",type:"password",value:c,required:!r,minLength:15,autoComplete:"new-password",disabled:w,onInput:A=>u(A.currentTarget.value)}),e("p",{class:"help",children:"Use at least 15 characters. Passwords are not returned or stored in browser preferences."}),r?e("label",{class:"check",children:[e("input",{type:"checkbox",checked:p,disabled:w,onChange:A=>f(A.currentTarget.checked)})," Account enabled"]}):null,e("fieldset",{class:"shared-roles-set",disabled:w,children:[e("legend",{children:"Assigned project roles"}),e("p",{id:"shared-roles-help",class:"help",children:[Ra.map(A=>`${$a(A)} ${Uc[A]}`).join(" \xB7 "),"."]}),e("div",{class:"shared-roles",children:t.filter(A=>!s||A.id===s).map(A=>e(j,{children:[e("label",{for:`shared-role-${A.id}`,children:A.name},`${A.id}-label`),e("select",{id:`shared-role-${A.id}`,class:"field","aria-describedby":"shared-roles-help",value:v[A.id]??"",onChange:P=>{let D={...v};P.currentTarget.value?D[A.id]=P.currentTarget.value:delete D[A.id],g(D)},children:[e("option",{value:"",children:"No access"}),Ra.map(P=>e("option",{value:P,children:$a(P)},P))]},A.id)]}))}),Object.keys(v).filter(A=>!t.some(P=>P.id===A)).map(A=>e("p",{class:"help",children:["Unavailable project ",A," ",e("button",{class:"btn ghost",type:"button",onClick:()=>{let P={...v};delete P[A],g(P)},children:"Remove assignment"})]},A))]}),e("div",{class:"shared-row",children:[e("button",{class:"btn primary",type:"submit",disabled:w||!n,children:r?"Save account changes":"Create account"}),e("button",{class:"btn",type:"button",disabled:w,onClick:()=>void x(),children:"Reload accounts"}),r?e("button",{class:"btn",type:"button",disabled:w||!n,onClick:async()=>{C(!0),y("");try{a(await q(`/api/accounts/${J(r)}/revoke-sessions`,{revision:n.revision})),T("All sessions for this account were revoked.")}catch(A){y(is(A))}finally{C(!1)}},children:"Sign out all sessions"}):null]})]}),k?e("p",{role:"alert",class:"shared-error",children:[k," Your draft has been kept; reload current accounts before retrying a conflicting save."]}):null,b?e("p",{role:"status",children:b}):null]})}var yu=(t=location.hash)=>{let s=Vi(t);return s.view==="team"||s.view==="team-task"||s.view==="team-people"?s:void 0};function zT({identity:t,onSignOut:s=bi}){let[n,a]=h(()=>yu());Qe(()=>{let I=()=>a(yu());return window.addEventListener("hashchange",I),I(),()=>window.removeEventListener("hashchange",I)},[]);let r=I=>{let re=I?Ps(I):"#/";location.hash===re?a(I):location.hash=re};_(()=>{Qn().catch(()=>{})},[]);let o=rs.value,i=n?"team":"results",[d,l]=h([]),[m,c]=h(""),[u,p]=h(""),[f,v]=h({runs:[],total:0}),[g,w]=h(""),[C,k]=h(null),[y,b]=h(""),[T,$]=h([]),[x,E]=h(null),[A,P]=h(null),[D,S]=h(""),[R,M]=h(""),[O,B]=h(!1),[ee,se]=h("Connecting"),[te,G]=h(0),[L,Y]=h(!1),X=Q(!1),N=Q(0),ae=Q(0),ie=Q(0),pe=Q({project:m,query:u,selected:g,branch:y});pe.current={project:m,query:u,selected:g,branch:y};let ge=async I=>{let re=++N.current,oe=pe.current;Y(!0);try{let he=new URLSearchParams({limit:"50",...oe.project?{project:oe.project}:{},...oe.query?{q:oe.query}:{},...I?{cursor:I}:{}}),le=await U(`/api/runs?${he}`);if(re!==N.current)return;v(ce=>({...le,runs:I?[...new Map([...ce.runs,...le.runs].map(H=>[H.id,H])).values()]:le.runs}))}catch(he){re===N.current&&M(is(he))}finally{re===N.current&&Y(!1)}};_(()=>{let I=!0;return U("/api/projects").then(re=>{I&&l(re)},re=>{I&&M(is(re))}),()=>{I=!1}},[]),_(()=>{M("");let I=setTimeout(()=>void ge(),200);return()=>{clearTimeout(I),N.current++}},[m,u]);let Ie=()=>void U("/api/auth/self").then(I=>{(I.kind!=="shared"||I.revision!==t.revision)&&bi()},()=>{}),xe=I=>{se(I==="connected"?"Connected":"Reconnecting"),I==="reconnecting"&&Ie()};_(()=>{if(i!=="results")return;let I=new EventSource(vs("/api/events?limit=50"));I.onopen=()=>xe("connected"),I.onerror=()=>xe("reconnecting");let re;return I.onmessage=()=>{clearTimeout(re),re=setTimeout(()=>{ge();let oe=pe.current.selected,he=ae.current;oe&&U(`/api/runs/${J(oe)}`).then(le=>{pe.current.selected===oe&&ae.current===he&&k(le)},()=>{pe.current.selected===oe&&ae.current===he&&(k(null),w(""))})},150)},()=>{I.close(),clearTimeout(re)}},[i]),_(()=>{let I=++ae.current;if(k(null),b(""),$([]),E(null),P(null),S(""),!!g)return Promise.all([U(`/api/runs/${J(g)}`),U(`/api/runs/${J(g)}/collaboration`)]).then(([re,oe])=>{I===ae.current&&(k(re),b(re.worktrees[0]?.branch??""),P(oe))},re=>{I===ae.current&&M(is(re))}),()=>{ae.current++}},[g]),_(()=>{let I=++ie.current;if(E(null),$([]),!(!g||!y))return Promise.all([U(`/api/runs/${J(g)}/diff?branch=${J(y)}`),U(`/api/runs/${J(g)}/review-coverage?branch=${J(y)}`),U(`/api/runs/${J(g)}/collaboration`)]).then(([re,oe,he])=>{I===ie.current&&($(re),E(oe),P(he))},re=>{I===ie.current&&M(is(re))}),()=>{ie.current++}},[g,y,te]);let We=!!C?.project&&je(t.roles[C.project],"reviewer");return e("main",{class:"shared-surface shared-page",children:[e("header",{class:"shared-top",children:[e("span",{class:"shared-brand",children:["code",e("span",{children:"-flow"})]}),e("span",{class:"spacer"}),e("span",{class:`connection-status ${ee==="Connected"?"connected":ee==="Connecting"?"connecting":"reconnecting"}`,role:"status",children:[e("span",{class:"cs-dot","aria-hidden":"true"}),e("span",{class:"cs-label",children:ee})]}),e("button",{type:"button",class:"btn small shared-bell","aria-label":`Team inbox${o?`, ${o} unread`:""}`,title:"Team inbox",onClick:()=>{Gn.value=!0,r({view:"team"})},children:[e(z,{name:"bell"}),o?e("span",{class:"team-badge","aria-hidden":"true",children:o}):null]}),e("button",{class:"btn small",onClick:async()=>{try{await q("/api/auth/logout"),s()}catch(I){M(is(I))}},children:["Sign out ",t.displayName]})]}),e("div",{class:"shared-tabs",role:"tablist","aria-label":"Shared dashboard",children:["results","team"].map(I=>e("button",{type:"button",role:"tab",id:`shared-tab-${I}`,class:"shared-tab","aria-selected":i===I,"aria-controls":`shared-panel-${I}`,tabIndex:i===I?0:-1,onClick:()=>r(I==="team"?{view:"team"}:void 0),onKeyDown:re=>{if(!["ArrowRight","ArrowLeft","Home","End"].includes(re.key))return;re.preventDefault();let oe=re.key==="Home"?"results":re.key==="End"||I==="results"?"team":"results";r(oe==="team"?{view:"team"}:void 0),requestAnimationFrame(()=>document.getElementById(`shared-tab-${oe}`)?.focus())},children:I==="results"?"Results":e(j,{children:["Board",o?e("span",{class:"team-badge","aria-hidden":"true",children:o}):null]})},I))}),e("div",{id:"shared-panel-team",role:"tabpanel","aria-labelledby":"shared-tab-team",hidden:i!=="team",children:n?e(Hh,{route:n,go:r,onState:xe}):null}),e("div",{id:"shared-panel-results",role:"tabpanel","aria-labelledby":"shared-tab-results",hidden:i!=="results",children:[e("div",{class:"page-head",children:e("div",{class:"page-head-text",children:[e("h1",{children:"Shared project review"}),e("p",{children:"View assigned project results and record human reviews. Comments stay in this collaboration thread and are not sent to coding agents."})]})}),R?e("p",{role:"alert",class:"shared-error",children:R}):null,e("div",{class:"shared-layout",children:[e("aside",{class:"shared-runs","aria-label":"Assigned project run history",children:[e("div",{class:"shared-filters",children:[e("label",{for:"shared-project-filter",children:"Shared project"}),e("select",{id:"shared-project-filter",class:"field",value:m,onChange:I=>{c(I.currentTarget.value),w("")},children:[e("option",{value:"",children:"All assigned projects"}),d.map(I=>e("option",{value:I.id,children:[I.name," \xB7 ",t.roles[I.id]]},I.id))]}),e("label",{for:"shared-run-search",children:"Search shared runs"}),e("input",{id:"shared-run-search",class:"field",type:"search",value:u,onInput:I=>p(I.currentTarget.value)})]}),e("p",{class:"shared-count",children:[f.runs.length," of ",f.total," results"]}),e("div",{class:"shared-run-list",children:f.runs.map(I=>e("button",{class:`shared-run ${g===I.id?"on":""}`,"aria-pressed":g===I.id,onClick:()=>w(I.id),children:[e("span",{class:`dot ${I.status}`,"aria-hidden":"true"}),e("span",{class:"t",children:I.task})," ",e("small",{children:[I.status," \xB7 ",new Date(I.createdAt).toLocaleString()]})]},I.id))}),f.nextCursor?e("div",{class:"shared-more",children:e("button",{class:"btn small",disabled:O||L,onClick:()=>void ge(f.nextCursor),children:"Load older shared runs"})}):null,!L&&!f.total?e("p",{class:"shared-empty",children:"No shared results match these filters."}):null]}),e("section",{class:"shared-result","aria-label":"Shared run result",children:C?e(j,{children:[e("div",{class:"shared-block shared-result-head",children:[e("h2",{children:C.task}),e("p",{class:"shared-meta",children:[e("span",{class:"sr-only",children:"Status: "}),e("span",{class:`status-pill ${C.status}`,children:C.status}),C.verdict?e("span",{class:"badge",children:C.verdict}):null,C.verification?e("span",{class:"badge",children:["verification ",C.verification.state]}):null]}),C.truncation.task||C.truncation.summary||C.truncation.error||C.truncation.omittedSteps?e("p",{class:"help",role:"status",children:["This shared result is a bounded preview",C.truncation.omittedSteps?`; ${C.truncation.omittedSteps} earlier steps are omitted`:"",". Ask the owner for any additional evidence needed."]}):null,C.summary?e("pre",{class:"shared-prose",children:C.summary}):null,C.error?e("p",{class:"shared-error",role:"alert",children:C.error}):null,C.stopReason?e("p",{children:C.stopReason}):null,C.steps?.length?e("div",{class:"shared-steps",children:C.steps.map(I=>e("details",{children:[e("summary",{children:[I.title," \xB7 ",I.status]}),I.finalText?e("pre",{class:"shared-prose",children:I.finalText}):null,I.error?e("p",{class:"shared-error",children:I.error}):null,I.finalTextTruncated||I.errorTruncated?e("p",{class:"help",children:"Step output is truncated in the shared preview."}):null]},I.id))}):null,e("div",{class:"shared-actions",children:e("a",{class:"btn small",href:vs(`/api/runs/${J(C.id)}/export`),target:"_blank",rel:"noopener noreferrer",children:"Export shared result"})})]}),e("div",{class:"shared-block shared-review",children:[C.worktrees.length?e(j,{children:[e("label",{for:"shared-result-branch",children:"Result branch"}),e("select",{id:"shared-result-branch",class:"field",value:y,onChange:I=>b(I.currentTarget.value),children:C.worktrees.map(I=>e("option",{value:I.branch,children:[I.name," \xB7 ",I.branch]},I.branch))}),x?e("p",{class:"shared-coverage",children:[x.coverage.reviewed," of ",x.coverage.changed," visible files reviewed at ",x.head.slice(0,12),x.stale?" \xB7 earlier review is stale":"",x.omittedCount?` \xB7 ${x.omittedCount} omitted files require owner review`:""]}):null,T.map(I=>e("article",{class:"shared-review-file",children:[e("div",{class:"shared-file-head",children:[e("h3",{children:I.path}),e("p",{children:[I.status," \xB7 +",I.additions," \u2212",I.deletions,I.truncated?" \xB7 preview truncated":""]})]}),I.binary?e("p",{class:"help",children:"Binary file"}):e("pre",{class:"shared-diff",children:I.patch.split(`
106
+ `).map((re,oe)=>e("span",{class:re.startsWith("@@")?"dh":re.startsWith("+")?"da":re.startsWith("-")?"dd":void 0,children:re},oe))}),x?e("label",{class:"check shared-reviewed",children:[e("input",{type:"checkbox",checked:x.reviewed.includes(I.path),disabled:!We||O,onChange:async re=>{if(X.current)return;X.current=!0;let oe=re.currentTarget.checked,he=pe.current,le=oe?[...new Set([...x.reviewed,I.path])]:x.reviewed.filter(ce=>ce!==I.path);E({...x,reviewed:le,coverage:{...x.coverage,reviewed:le.length,percent:x.files.length?Math.round(le.length/x.files.length*100):100}}),B(!0),M("");try{let ce=await q(`/api/runs/${J(C.id)}/review-coverage`,{branch:y,expectedHead:x.head,path:I.path,reviewed:oe});pe.current.selected===he.selected&&pe.current.branch===he.branch&&E(ce)}catch(ce){pe.current.selected===he.selected&&pe.current.branch===he.branch&&E(x),M(is(ce))}finally{X.current=!1,B(!1)}}})," Reviewed ",I.path]}):null]},I.path))]}):null,e("div",{class:"shared-actions",children:e("button",{class:"btn small",disabled:O||!y,onClick:()=>G(I=>I+1),children:"Refresh result evidence"})})]}),e("div",{class:"shared-block shared-thread",children:[e("h3",{children:"Human collaboration comments"}),A?.comments.map(I=>e("article",{class:"shared-comment",children:[e("strong",{children:I.actor.name}),e("p",{class:"help",children:[I.branch," \xB7 ",I.head.slice(0,12)," \xB7 ",new Date(I.at).toLocaleString()]}),e("p",{class:"shared-comment-text",children:I.text})]},I.id)),We&&x?e("form",{class:"shared-form",onSubmit:async I=>{if(I.preventDefault(),X.current)return;X.current=!0;let re=pe.current;B(!0),M("");try{let oe=await q(`/api/runs/${J(C.id)}/collaboration`,{branch:y,expectedHead:x.head,text:D});pe.current.selected===re.selected&&(P(oe),S(""))}catch(oe){M(is(oe))}finally{X.current=!1,B(!1)}},children:[e("label",{for:"shared-review-comment",children:"Comment on this result commit"}),e("textarea",{id:"shared-review-comment",class:"field",rows:4,maxLength:4e3,value:D,onInput:I=>S(I.currentTarget.value)}),e("button",{class:"btn primary",disabled:O||!D.trim(),children:"Record human comment"})]}):e("p",{class:"help",children:"A project reviewer can record comments and file coverage. The owner controls execution and shipping."})]})]}):e("p",{class:"shared-empty",children:"Choose a run to inspect its result."})})]})]})]})}function Hh({route:t,go:s,onState:n}){let a=Q(n);return a.current=n,_(()=>Kc(r=>a.current(r)),[]),e("div",{class:"shared-team",children:t.view==="team-task"?e(no,{id:t.id,shared:!0,navigate:s},t.id):t.view==="team-people"?e(ia,{project:t.project,shared:!0,navigate:s}):e(oa,{project:t.project,shared:!0,navigate:s})})}function wu(){let[t,s]=h(null),n=()=>U("/api/remote/devices").then(s,a=>V(a.message,5e3));return _(()=>{n()},[]),e("details",{class:"phone-devices",children:[e("summary",{children:["Paired devices",t?` \xB7 ${t.length}`:""]}),e("p",{class:"help",children:"Each phone has its own expiring session. Revoking one phone leaves your other devices signed in."}),t?.length?e("div",{class:"pd-list",children:t.map(a=>e("div",{class:"pd-row",children:[e("span",{class:"pd-name",children:a.label}),e("span",{class:"pd-when",children:["expires ",new Date(a.expiresAt).toLocaleDateString()]}),e("button",{class:"btn small",onClick:async()=>{try{await U(`/api/remote/devices/${a.id}`,{method:"DELETE"}),await n()}catch(r){V(r.message,5e3)}},children:"Revoke device"})]},a.id))}):e("p",{class:"help",children:"No paired devices."}),e("button",{class:"btn small pd-refresh",onClick:n,children:"Refresh devices"})]})}function rS(){let[t,s]=h(null),[n,a]=h(!1),[r,o]=h(!1),[i,d]=h(""),[l,m]=h(Date.now()),c=Q(0),u=Q(!1),p=Q(!1),f=async(b=!1)=>{if(u.current||p.current)return;p.current=!0,o(!0);let T=++c.current;try{let $=await U(`/api/remote${b?"?refresh=1":""}`);T===c.current&&(s($),d(""),m(Date.now()))}catch($){T===c.current&&d($.message)}finally{p.current=!1,o(!1)}};_(()=>{let b=Je(()=>(m(Date.now()),f()),1e4);return()=>{b(),++c.current}},[]);let v=async(b,T="/api/remote")=>{if(u.current)return!1;u.current=!0;let $=++c.current;a(!0);try{let x=await q(T,b);return $===c.current&&(s(x),d(""),m(Date.now())),!0}catch(x){return $===c.current&&d(x.message),!1}finally{u.current=!1,a(!1)}},g=t?.transport==="tailscale",w=!!t?.control&&t.lan,C=w&&l>=(t?.pairingUntil??0),k=!t||C||i?[]:g?t.tailscaleUrl?[t.tailscaleUrl]:[]:t.lanUrls,y=b=>b.replace(/\/r\/(\w{6})\w+/,"/r/$1\u2026");return e("section",{class:"section auto-card phone-card","aria-label":"Remote access",children:[e("h2",{class:"section-title",children:"Remote access"}),e("p",{class:"help",children:"Open Codeflow from your phone, tablet or another computer. This computer must stay awake and Codeflow must remain running."}),i?e("p",{class:"msg err",role:"alert",children:[i," ",e("button",{class:"btn small",disabled:n,onClick:()=>void f(!0),children:"Retry"})]}):null,t?e(j,{children:[e("label",{class:"checkpoint",children:[e("input",{type:"checkbox","aria-label":"Enable remote access",disabled:n,checked:t.enabled,onChange:b=>void v({enabled:b.currentTarget.checked})}),e("span",{children:[e("b",{children:"Enable remote access"})," \u2014 a private link to your runs and results. Starts with a read-only view."]})]}),t.enabled?e(j,{children:[e("label",{class:"remote-connection",children:["Connection",e("select",{class:"field","aria-label":"Remote connection",disabled:n,value:t.lan?t.transport:"local",onChange:b=>{let T=b.currentTarget.value;v({lan:T!=="local",transport:T==="tailscale"?"tailscale":"lan",...T!=="local"&&!t.secure&&!t.insecureDevelopment?{control:!1}:{}})},children:[e("option",{value:"local",children:"This computer only"}),e("option",{value:"tailscale",children:"Tailscale \xB7 access anywhere"}),e("option",{value:"lan",children:"Wi-Fi \xB7 local network"})]})]}),g?e("div",{class:"remote-status",role:"status",children:[e("b",{children:t.tailscale.state==="connected"?"Tailscale connected":"Tailscale setup needed"}),e("p",{class:"help",children:[t.tailscale.message,t.tailscale.ip?` ${t.tailscale.dnsName?`${t.tailscale.dnsName} \xB7 `:""}${t.tailscale.ip}`:""]}),e("button",{class:"btn small",disabled:n||r,onClick:()=>void f(!0),children:r?"Checking Tailscale\u2026":"Refresh Tailscale"})," ",t.tailscale.state==="not-installed"?e("a",{class:"btn small",href:"https://tailscale.com/download",target:"_blank",rel:"noreferrer",children:"Install Tailscale"}):null,e("p",{class:"help",children:"Connect your other device to the same Tailscale network. Its access rules must allow this computer's remote port. Codeflow listens only on the Tailscale address in this mode."})]}):t.lan?e("p",{class:"help",children:"Your other device must be on the same trusted Wi-Fi network. HTTPS is required for full control."}):null,t.lan?e(j,{children:[e(yi,{info:t,busy:n,save:b=>v(b,"/api/remote/tls")}),e("label",{class:`checkpoint${t.control?" danger":""}`,children:[e("input",{type:"checkbox","aria-label":"Full control from remote devices",disabled:n||!t.secure&&!t.insecureDevelopment,checked:t.control,onChange:b=>void v({control:b.currentTarget.checked})}),e("span",{children:[e("b",{children:"Full control from remote devices"})," \u2014 start runs, answer questions, review changes, merge and open pull requests. Anyone with the pairing link has your control of this computer."]})]}),e("p",{class:"help",children:[t.secure?"Encrypted HTTPS. ":t.insecureDevelopment?"Development override: unencrypted HTTP. ":"Set up secure remote access above to enable full control. ",w?"Pairing links expire after ten minutes. Paired devices stay signed in for up to 30 days.":""]}),e(wu,{},`${t.transport}-${t.pairingUntil}`)]}):null,t.lanError?e("p",{class:"msg err",role:"alert",children:t.lanError}):null,C?e("p",{class:"msg",role:"status",children:"Pairing link expired. Choose New link to pair another device."}):null,k[0]?e("div",{class:"phone-qr",children:[e(ac,{text:k[0]}),e("div",{class:"phone-qr-text",children:[e("b",{children:"Scan with your phone"}),e("span",{class:"help",children:[w?"Pairs this device with full control":"Opens the read-only view"," at ",y(k[0]),". ",g?"Turn on Tailscale on the phone before opening the link.":"Connect your phone to the same Wi-Fi first."]})]})]}):t.lan&&!C&&!i?e("p",{class:"help",children:["No remote link until ",g?"Tailscale is connected and Codeflow can listen on its address":"Codeflow can listen on your network","."]}):null,e("div",{class:"hook",children:[(t.lan?k:[t.local]).map(b=>e("div",{children:[e("code",{children:y(b)})," ",e("button",{class:"btn small",onClick:()=>Ot(b,"Link copied"),children:"Copy link"})," ",t.lan?null:e("a",{class:"btn small",href:b,target:"_blank",rel:"noreferrer",children:"Open"})]},b)),t.lan?e("p",{class:"help",children:"Open this link on your other device. Connections from this computer are blocked on the remote port."}):null,e("button",{class:"btn small",disabled:n,onClick:async()=>await Ce("Make a new link? Old links stop working and all paired devices are signed out.",{title:"Replace access link?",confirmLabel:"Replace link",danger:!0})&&void v({rotate:!0}),children:"New link"})]})]}):null]}):e("p",{class:"help",children:i?"Remote access settings could not be loaded.":"Loading remote access\u2026"})]})}function yi({info:t,busy:s,save:n}){let[a,r]=h(!1),[o,i]=h("tailscale"),[d,l]=h(t.tls?.hostname??t.tailscale.dnsName??""),[m,c]=h(""),u=Q(null),p=Q(null),f=t.transport==="tailscale",v=f&&o==="tailscale",g=t.tls?.renewal,w=t.tls?.expiresAt,C=!!w&&w-Date.now()<30*864e5,k=async()=>{c("");try{if(v){await n({mode:"tailscale"})&&r(!1);return}let y=u.current?.files?.[0],b=p.current?.files?.[0];if(!y||!b)throw new Error("Choose both the certificate and private key files");if(y.size>128*1024||b.size>32*1024)throw new Error("Certificate must be under 128 KB and private key under 32 KB");await n({mode:"import",hostname:d,cert:await y.text(),key:await b.text()})&&(p.current&&(p.current.value=""),r(!1))}catch(y){c(y.message)}};return e("div",{class:"remote-status secure-remote-setup",children:[e("b",{children:t.secure?"Secure remote access is set up":"Set up secure remote access"}),t.tls?.source==="environment"?e("p",{class:"help",children:"HTTPS is managed by this server's environment configuration."}):e(j,{children:[t.tls?.hostname?e("p",{class:"help",children:[t.tls.hostname,w?` \xB7 Certificate expires ${new Date(w).toLocaleDateString()}`:""]}):null,t.tls?.error?e("p",{class:"msg err",children:t.tls.error}):C&&!g?e("p",{class:"help",children:"Renew the certificate before it expires to keep remote access available."}):null,g?e("div",{class:"help",children:[e("b",{children:"Automatic renewal is on"}),e("p",{children:[g.running?"Renewing certificate\u2026":`Next renewal attempt: ${new Date(Math.max(Date.now(),g.nextAttempt)).toLocaleString()}`,g.lastSuccess?` \xB7 Last renewed ${new Date(g.lastSuccess).toLocaleString()}`:""]}),e("p",{children:"Codeflow renews within 30 days of expiry while it is running and Tailscale access is enabled. Paired devices stay signed in."}),g.error?e("p",{role:"status",children:g.error}):null]}):null,e("p",{class:"help",children:"Configure HTTPS here. Codeflow saves the certificate privately and applies it immediately without restarting your chats. Manually replacing a certificate turns full control off until you enable it below."}),t.tls?.editable?e("button",{class:"btn small",disabled:s,"aria-expanded":a,onClick:()=>r(!a),children:a?"Close setup":t.secure?"Renew or replace certificate":"Set up secure remote access"}):e("p",{class:"help",children:"Open these settings on the computer running Codeflow to configure HTTPS."}),a?e("form",{class:"secure-remote-form",onSubmit:y=>{y.preventDefault(),k()},children:e("fieldset",{disabled:s,children:[f?e("label",{children:["Certificate setup",e("select",{class:"field",value:o,onChange:y=>i(y.currentTarget.value),children:[e("option",{value:"tailscale",children:"Use Tailscale \xB7 recommended"}),e("option",{value:"import",children:"Import certificate files"})]})]}):null,v?e(j,{children:[e("p",{class:"help",children:["Create or renew a certificate for ",e("b",{children:t.tailscale.dnsName??"this computer's Tailscale name"}),". Enable HTTPS certificates in your ",e("a",{href:"https://login.tailscale.com/admin/dns",target:"_blank",rel:"noreferrer",children:"Tailscale DNS settings"})," first."]}),e("p",{class:"help",children:["The computer's DNS name will appear in public certificate transparency logs. This does not make Codeflow public. ",e("a",{href:"https://tailscale.com/docs/how-to/set-up-https-certificates",target:"_blank",rel:"noreferrer",children:"About Tailscale certificates"})]}),e("p",{class:"help",children:"Automatic renewal is included. Codeflow renews within 30 days of expiry while it is running and Tailscale access is enabled, and retries automatically if renewal fails."})]}):e(j,{children:[e("label",{children:["Remote hostname or IP",e("input",{class:"field",value:d,placeholder:"codeflow.example.com",onInput:y=>l(y.currentTarget.value),required:!0})]}),e("label",{children:["Certificate file (PEM)",e("input",{class:"field",type:"file",accept:".pem,.crt,.cer",ref:u,required:!0})]}),e("label",{children:["Private key file (PEM)",e("input",{class:"field",type:"file",accept:".pem,.key",ref:p,required:!0})]}),e("p",{class:"help",children:"Use a certificate trusted by your other device for this exact hostname or IP. The hostname must resolve to this computer. The key must be unencrypted; it is saved privately on this computer and never returned to the browser."})]}),e("p",{class:"help",children:"Replacing a certificate signs paired devices out. Pair them again after enabling full control."}),m?e("p",{class:"msg err",role:"alert",children:m}):null,e("button",{type:"submit",class:"btn primary",disabled:s||v&&(t.tailscale.state!=="connected"||!t.tailscale.dnsName),children:s?"Setting up HTTPS\u2026":v?"Get Tailscale certificate":"Save and apply HTTPS"})]})}):null]})]})}function Cu(t,s){let n=t.replace(/[\\/]+$/,"").split(/[\\/]/).pop()||"Repository",a=n.toLowerCase().replace(/[^a-z0-9-]+/g,"-").replace(/^-+|-+$/g,"")||"repo";/^[a-z]/.test(a)||(a=`repo-${a}`),a=a.slice(0,64).replace(/-+$/,"");let r=a;for(let o=2;s.includes(r);o++){let i=`-${o}`;r=a.slice(0,64-i.length).replace(/-+$/,"")+i}return{key:r,label:n.slice(0,80)}}var Tu=["Project","Repositories","Secure access","Teammates","Share"],ki=()=>({key:"app",label:"App",defaultBranch:"main"}),Su=t=>t==="contributor"||t==="maintainer";function xu({onClose:t}){let[s,n]=h([]),[a,r]=h(cs??"local"),[o,i]=h("local"),[d,l]=h(!1),[m,c]=h(!1),[u,p]=h(""),[f,v]=h("4318"),[g,w]=h(!1),[C,k]=h(null),[y,b]=h(""),[T,$]=h(""),x=s.find(M=>M.id===a)?.name??"Remote server",E=`/api/ssh-hosts/${a}/team-server`,A=async()=>{try{n((await mt("/api/ssh-hosts")).hosts),p("")}catch(M){p(M.message)}};_(()=>{A()},[]);let P=async(M="status")=>{b("");try{k(await mt(E+"/autostart",M==="status"?{}:{method:"POST",body:JSON.stringify({action:M})}))}catch(O){k(null),b(O.message)}},D=async M=>{if(!(d||m)){l(!0);try{await P(M)}finally{l(!1)}}},S=async()=>{if(!d){l(!0),p("");try{s.find(O=>O.id===a)?.state!=="connected"&&(await mt(`/api/ssh-hosts/${a}/connect`,{method:"POST",body:"{}"}),await A());let M=await mt(E,{method:"POST",body:JSON.stringify({remotePort:Number(f)})});v(String(M.remotePort)),w(!0),$(M.currentVersion?"":"A newer Code Flow version is available. You can edit the current settings, or stop the server and start it again to update. Saved projects and accounts stay in place."),i(a),await P()}catch(M){p(M.message)}finally{l(!1)}}},R=async()=>{if(!(d||!await Ce(`Stop the team server on ${x}? Teammates will lose access until it is started again. Saved projects and accounts stay in place. Automatic startup, if enabled, will still apply at the next reboot.`,{title:"Stop team server?",confirmLabel:"Stop server",danger:!0}))){l(!0),p("");try{await mt(E,{method:"DELETE"}),i(""),w(!1)}catch(M){p(M.message)}finally{l(!1)}}};return e(j,{children:[e("section",{class:"settings-card","aria-label":"Team server location",children:[e("h3",{children:"Where should the team server run?"}),e("label",{children:["Server",e("select",{class:"field","aria-label":"Server",disabled:d||m,value:a,onChange:M=>{r(M.currentTarget.value),i("local"),w(!1),k(null),b(""),v("4318"),p("")},children:[e("option",{value:"local",children:"This computer"}),s.map(M=>e("option",{value:M.id,children:[M.name,M.state!=="connected"?" \xB7 disconnected":""]},M.id))]})]}),e("p",{class:"help",children:["Choose this computer or an existing SSH connection. ",e("a",{href:"/#/settings/connections/workspace",children:"Manage SSH connections"})]}),e("button",{class:"btn small",disabled:d||m,onClick:()=>void A(),children:"Refresh servers"}),a!=="local"?e(j,{children:[e("p",{children:["Host the team on ",x,". Setup installs a separate Code Flow server using your SSH connection. Its projects and accounts are separate from the SSH workspace."]}),e("p",{class:"help",children:"It keeps running when SSH disconnects. After setup, enable automatic startup to bring it back after a reboot on Linux servers with systemd."}),o!==a?e(j,{children:[e("label",{children:["Team HTTPS port",e("input",{class:"field","aria-label":"Team HTTPS port",type:"number",min:1,max:65535,step:1,disabled:d,value:f,onInput:M=>v(M.currentTarget.value)})]}),e("p",{class:"help",children:"Allow this port in the server\u2019s firewall. HTTPS is configured in the next steps. A running server keeps its existing port."}),e("button",{class:"btn primary",disabled:d||!s.some(M=>M.id===a)||!Number.isInteger(Number(f))||Number(f)<1||Number(f)>65535,onClick:()=>void S(),children:d?"Setting up server\u2026":s.find(M=>M.id===a)?.state==="connected"?"Open or start team server":"Connect and set up on this server"}),e("button",{class:"btn",disabled:d,onClick:t,children:"Close setup"})]}):e("p",{role:"status",children:["Connected to the team server on ",x," \xB7 port ",f]}),g?e("div",{class:"remote-status","aria-label":"Automatic startup",children:[e("h4",{children:"Start automatically after reboot"}),e("p",{class:"help",children:"Uses a systemd service for your SSH account. Changing this setting leaves the running server in place."}),e("p",{role:"status",children:C?.message??(y?"Automatic startup could not be checked.":"Checking automatic startup\u2026")}),C?.command?e("p",{children:e("code",{children:C.command})}):null,y?e("p",{class:"msg err",role:"alert",children:y}):null,e("div",{class:"settings-actions",children:[e("button",{class:"btn",disabled:d||m,onClick:()=>void D("status"),children:"Check startup status"}),C?.supported&&C.unitEnabled&&!C.enabled?e("button",{class:"btn",disabled:d||m,onClick:()=>void D("disable"),children:"Disable automatic startup"}):null,C?.supported?e("button",{class:"btn",disabled:d||m,onClick:()=>void D(C.enabled?"disable":"enable"),children:C.enabled?"Disable automatic startup":"Enable automatic startup"}):null]})]}):null,g?e("button",{class:"btn small",disabled:d||m,onClick:()=>void R(),children:"Stop team server"}):null]}):null,u?e("p",{class:"msg err",role:"alert",children:u}):null]}),T&&g?e("p",{class:"help",role:"status",children:T}):null,o===a?e(Wh,{onClose:t,prefix:a==="local"?"":E,workspacePrefix:a==="local"?"":`/computer/${encodeURIComponent(a)}`,hostName:a==="local"?"this computer":x,onBusy:c},a):null]})}function Wh({onClose:t,prefix:s,workspacePrefix:n,hostName:a,onBusy:r}){let o=(K,ye,Te="POST")=>mt(s+(K.startsWith("/api/team/")?`${K}${K.includes("?")?"&":"?"}teamConnection=local`:K),ye?{method:Te,body:JSON.stringify(ye)}:{}),[i,d]=h(0),[l,m]=h(!1),[c,u]=h(""),p=Q(!1),f=Q(null),[v,g]=h([]),[w,C]=h(null),[k,y]=h(null),[b,T]=h(null),[$,x]=h(""),[E,A]=h(""),[P,D]=h(s?"":ne.value),[S,R]=h(""),[M,O]=h([ki()]),[B,ee]=h(""),[se,te]=h(""),[G,L]=h(""),[Y,X]=h(""),[N,ae]=h("contributor"),[ie,pe]=h(""),[ge,Ie]=h("tailscale"),xe=v.find(K=>K.id===$),We=k?.users.filter(K=>K.enabled&&K.roles[$])??[],Ve=b?.enabled&&b.lan&&!b.lanError?Lr(b):void 0,I=w?.projects.find(K=>K.id===$)?.repositories??[],[re,oe]=h([]),[he,le]=h(""),[ce,H]=h(!1),Ae=[...new Set([...v,...re].flatMap(K=>K.repos))],Re=async()=>{H(!0),le("");try{oe(await mt(`${n}/api/projects`))}catch(K){le(`Could not load repositories from ${a}: ${K.message}`)}finally{H(!1)}};_(()=>{Re()},[]);let F=(K,ye)=>{O(Te=>Te.map((Ke,xn)=>xn!==K?Ke:ye?{...Ke,...Cu(ye,Te.filter((Ba,np)=>np!==K).map(Ba=>Ba.key)),sourcePath:ye,remote:void 0}:{...Ke,sourcePath:void 0}))},W=!!xe&&I.length>0&&!!Ve&&We.some(K=>Su(K.roles[$])),ue=async K=>{if(p.current)return!1;p.current=!0,m(!0),r(!0),u("");try{return await K(),!0}catch(ye){return u(ye.message),!1}finally{p.current=!1,m(!1),r(!1)}},ze=()=>ue(async()=>{let[K,ye,Te,Ke]=await Promise.all([o("/api/projects"),o("/api/team/board"),o("/api/accounts"),o("/api/remote")]);g(K),C(ye),y(Te),T(Ke),R(ye.me.displayName),Ie(Ke.enabled&&Ke.lan?Ke.transport:"tailscale"),!$&&K.length&&x(K[0].id)});_(()=>{ze()},[]),_(()=>{f.current?.focus(),pe("")},[i]);let qe=async()=>{await ue(async()=>{if(i===0){if(!S.trim())throw new Error("Enter your name as teammates should see it.");let K=xe;if(!K){if(!E.trim())throw new Error("Enter a project name.");K=await o("/api/projects",{name:E.trim(),repos:P.trim()?[P.trim()]:[]}),g(Ke=>[...Ke,K]),x(K.id),s||Cs()}await o("/api/team/profile",{displayName:S.trim()},"PUT");let ye=await o("/api/team/board");C(ye);let Te=ye.projects.find(Ke=>Ke.id===K.id)?.repositories;O(Te?.length?Te.map(Ke=>({...Ke})):[ki()])}if(i===1){if(!M.length||M.some(K=>!/^[a-z][a-z0-9-]{0,63}$/.test(K.key.trim()))||new Set(M.map(K=>K.key.trim())).size!==M.length)throw new Error("Add at least one repository, with a unique key using lowercase letters, numbers and dashes.");try{await o(`/api/team/projects/${encodeURIComponent($)}/repositories`,{revision:w.revision,repositories:M.map(K=>({key:K.key.trim(),label:K.label.trim()||K.key.trim(),...K.remote?.trim()?{remote:K.remote.trim()}:{},...K.defaultBranch?.trim()?{defaultBranch:K.defaultBranch.trim()}:{}}))},"PUT")}catch(K){throw K instanceof Ge&&K.status===409&&C(await o("/api/team/board")),K}C(await o("/api/team/board"))}if(i>=2){let[K,ye,Te,Ke]=await Promise.all([o("/api/remote?refresh=1"),o("/api/accounts"),o("/api/team/board"),o("/api/projects")]);T(K),y(ye),C(Te),g(Ke)}d(Math.min(i+1,4))})},_a=(K,ye="/api/remote")=>ue(async()=>{T(await o(ye,K))}),io=async()=>{await ue(async()=>{if(k)try{let K=k.users.find(Te=>Te.id===B);if(B&&(!K||!K.enabled))throw new Error("Choose an enabled account.");let ye=K?await o(`/api/accounts/${encodeURIComponent(K.id)}`,{revision:k.revision,roles:{...K.roles,[$]:N}},"PUT"):await o("/api/accounts",{revision:k.revision,username:se.trim(),displayName:G.trim(),password:Y,roles:{[$]:N}});y(ye),ee(""),te(""),L(""),pe(K?"Project access saved. Existing credentials still apply.":"Teammate saved. Share their initial password privately.")}catch(K){throw K instanceof Ge&&K.status===409&&y(await o("/api/accounts")),K}finally{X("")}})},Bi=Ve&&xe?`Join ${xe.name} in Code Flow
107
+ Team server: ${Ve}
108
+
109
+ 1. ${b?.transport==="tailscale"?"Connect your computer to our Tailscale network.":"Make sure your computer can reach the team server over HTTPS."}
110
+ 2. Open your own Code Flow \u2192 Settings \u2192 Team \u2192 Add team connection (or Connect this computer).
111
+ 3. Enter the server address and the account credentials shared with you separately.
112
+ 4. Map these repository keys to your local clones: ${I.map(K=>K.key).join(", ")}.
113
+ Use the same Code Flow version as the server.`:"";return e("section",{class:"settings-card team-server-wizard","aria-label":"Team server setup","aria-busy":l,children:[e("div",{class:"pp-card-head",children:[e("h3",{children:"Set up team server"}),e("button",{class:"btn small",disabled:l,onClick:t,children:"Close setup"})]}),e("p",{class:"help",children:["Edit the team server on ",a,". Choose a section below. Saved settings stay in place when you close setup."]}),e("ol",{class:"team-setup-steps","aria-label":"Setup progress",children:Tu.map((K,ye)=>e("li",{"aria-current":i===ye?"step":void 0,children:e("button",{type:"button",disabled:l||!w||ye>0&&!xe,"aria-current":i===ye?"step":void 0,onClick:()=>{ye===1&&i!==1&&O(I.length?I.map(Te=>({...Te})):[ki()]),d(ye)},children:[e("span",{children:ye+1}),K]})},K))}),e("h4",{ref:f,tabIndex:-1,children:["Step ",i+1," of 5: ",Tu[i]]}),!w||!k||!b?e("p",{class:"help",children:[c?"Setup could not load your current settings.":"Loading your current settings\u2026",e("button",{class:"btn small",disabled:l,onClick:()=>void ze(),children:"Retry loading settings"})]}):e(j,{children:[i===0?e("form",{onSubmit:K=>{K.preventDefault(),qe()},children:e("fieldset",{disabled:l,class:"team-setup-fields",children:[e("legend",{class:"sr-only",children:"Project and host"}),e("label",{children:["Your name on the team",e("input",{class:"field",required:!0,maxLength:120,value:S,onInput:K=>R(K.currentTarget.value)})]}),e("label",{children:["Project",e("select",{"aria-label":"Project",class:"field",value:$,onChange:K=>x(K.currentTarget.value),children:[e("option",{value:"",children:"Create a new project\u2026"}),v.map(K=>e("option",{value:K.id,children:K.name},K.id))]})]}),xe?e("p",{class:"help",children:["Use ",xe.name," and keep its existing settings and members."]}):e(j,{children:[e("label",{children:["Project name",e("input",{class:"field",required:!0,maxLength:60,value:E,onInput:K=>A(K.currentTarget.value)})]}),e("label",{children:["Local repository folder (optional)",e("input",{class:"field mono",value:P,placeholder:"/path/to/repository",onInput:K=>D(K.currentTarget.value)})]}),e("p",{class:"help",children:"A server can host the board without a local clone. Teammates map their own clones after connecting."})]}),e("button",{class:"btn primary",type:"submit",children:"Save and continue"})]})}):null,i===1?e("form",{onSubmit:K=>{K.preventDefault(),qe()},children:[e("p",{class:"help",children:"Give each repository a shared name. Teammates use these keys to choose their own local clones."}),e("fieldset",{disabled:l,class:"team-setup-fields",children:[e("legend",{class:"sr-only",children:"Shared repositories"}),e("div",{class:"settings-actions",children:e("button",{class:"btn small",type:"button",disabled:ce,onClick:()=>void Re(),children:ce?"Loading repositories\u2026":"Refresh repositories"})}),he?e("p",{class:"msg err",role:"alert",children:he}):null,M.map((K,ye)=>e("div",{class:"team-setup-repo",children:[e("label",{class:"team-setup-repo-source",children:["Use an existing repository",e("select",{class:"field","aria-label":`Existing repository ${ye+1}`,value:K.sourcePath??"",onChange:Te=>F(ye,Te.currentTarget.value),children:[e("option",{value:"",children:"Enter repository details manually"}),Ae.map(Te=>e("option",{value:Te,disabled:M.some((Ke,xn)=>xn!==ye&&Ke.sourcePath===Te),children:Te},Te))]})]}),e("p",{class:"help team-setup-repo-source",children:[Ae.length?`Choose a repository from the existing projects on ${a}${n?", including its SSH workspace":""}. This fills the shared key and label; add its Git URL and check the default branch below.`:`No repository folders were found in the projects on ${a}. Add the folder to a project on that computer and refresh repositories, or enter the shared details manually.`," Teammates still map the key to their own checkout after connecting."]}),["key","label","remote","defaultBranch"].map(Te=>e("label",{children:[{key:"Repository key",label:"Repository label",remote:"Git URL (optional)",defaultBranch:"Default branch"}[Te],e("input",{class:"field",required:Te==="key",maxLength:Te==="key"?64:Te==="label"?80:Te==="remote"?300:100,pattern:Te==="key"?"[a-z][a-z0-9-]{0,63}":void 0,value:K[Te]??"",onInput:Ke=>O(M.map((xn,Ba)=>Ba===ye?{...xn,[Te]:Ke.currentTarget.value}:xn))})]},Te)),e("button",{class:"btn small",type:"button",onClick:()=>O(M.filter((Te,Ke)=>Ke!==ye)),children:["Remove repository ",ye+1]})]},ye)),e("div",{class:"settings-actions",children:[e("button",{class:"btn",type:"button",disabled:M.length>=50,onClick:()=>O([...M,{key:"",label:"",defaultBranch:"main"}]),children:"Add repository"}),e("button",{class:"btn primary",type:"submit",children:"Save repositories and continue"})]})]})]}):null,i===2?e("div",{class:"team-setup-fields",children:[e("p",{children:["Teammates need an encrypted address they can reach. Keep ",a," running with Code Flow active."]}),e("label",{children:["Connection method",e("select",{class:"field","aria-label":"Connection method",disabled:l,value:ge,onChange:K=>Ie(K.currentTarget.value),children:[e("option",{value:"tailscale",children:"Tailscale \xB7 recommended"}),e("option",{value:"lan",children:"Other HTTPS network"})]})]}),ge==="tailscale"?e(j,{children:[e("p",{class:"help",children:[b.tailscale.message," ",b.tailscale.dnsName??""]}),b.tailscale.state==="not-installed"?e("a",{class:"btn",href:"https://tailscale.com/download",target:"_blank",rel:"noreferrer",children:"Install Tailscale"}):null,e("p",{class:"help",children:"Sign in to Tailscale on the server and teammates\u2019 computers. Your network\u2019s access rules must allow the server\u2019s remote port."})]}):e("p",{class:"help",children:"Use a reachable server hostname and a certificate trusted by teammates\u2019 computers. You manage DNS and network access. This option listens on the server\u2019s network interfaces."}),e("div",{class:"settings-actions",children:[e("button",{class:"btn",disabled:l,onClick:()=>void ue(async()=>T(await o("/api/remote?refresh=1"))),children:"Check connection"}),!b.enabled||!b.lan||b.transport!==ge?e("button",{class:"btn primary",disabled:l||ge==="tailscale"&&b.tailscale.state!=="connected",onClick:()=>void _a({enabled:!0,lan:!0,transport:ge}),children:ge==="tailscale"?"Enable team access over Tailscale":"Enable team access on network"}):null]}),b.enabled&&b.lan&&b.transport===ge?e(yi,{info:b,busy:l,save:K=>_a(K,"/api/remote/tls")},ge):null,b.lanError?e("p",{class:"msg err",role:"alert",children:b.lanError}):null,Ve?e("p",{role:"status",children:["Secure team address: ",e("code",{children:Ve})]}):e("p",{class:"help",children:"Secure team access is not ready yet. You can finish this step later."}),e("button",{class:"btn primary",disabled:l,onClick:()=>void qe(),children:Ve?"Continue to teammates":"Set up access later"})]}):null,i===3?e("div",{children:[e("p",{children:["Add accounts for people working on ",xe?.name,". Contributor lets them run tasks on their computers; Maintainer also lets them manage the project board."]}),We.length?e("ul",{children:We.map(K=>e("li",{children:[K.displayName," (",K.username,") \xB7 ",K.roles[$]]},K.id))}):e("p",{class:"help",children:"No teammates have access to this project yet."}),e("form",{onSubmit:K=>{K.preventDefault(),io()},children:e("fieldset",{disabled:l,class:"team-setup-fields",children:[e("legend",{class:"sr-only",children:"Teammate account"}),e("label",{children:["Account",e("select",{"aria-label":"Account",class:"field",value:B,onChange:K=>{let ye=K.currentTarget.value;ee(ye),X(""),ae(k.users.find(Te=>Te.id===ye)?.roles[$]??"contributor")},children:[e("option",{value:"",children:"Create a new account\u2026"}),k.users.filter(K=>K.enabled).map(K=>e("option",{value:K.id,children:[K.displayName," (",K.username,")"]},K.id))]})]}),B?e("p",{class:"help",children:"Only this project\u2019s role will change. The account keeps its other project roles. Updated accounts must sign in again."}):e(j,{children:[e("label",{children:["Username",e("input",{class:"field",required:!0,maxLength:64,value:se,autoComplete:"off",onInput:K=>te(K.currentTarget.value)})]}),e("label",{children:["Display name",e("input",{class:"field",required:!0,maxLength:120,value:G,onInput:K=>L(K.currentTarget.value)})]}),e("label",{children:["Initial password",e("input",{class:"field",type:"password",required:!0,minLength:15,autoComplete:"new-password",value:Y,onInput:K=>X(K.currentTarget.value)})]}),e("p",{class:"help",children:"Use at least 15 characters. Share it privately; it is never included in copied connection instructions."})]}),e("label",{children:["Project role",e("select",{"aria-label":"Project role",class:"field",value:N,onChange:K=>ae(K.currentTarget.value),children:[e("option",{value:"contributor",children:"Contributor \u2014 work on tasks"}),e("option",{value:"maintainer",children:"Maintainer \u2014 manage this project"}),e("option",{value:"reviewer",children:"Reviewer \u2014 review and comment"}),e("option",{value:"viewer",children:"Viewer \u2014 read only"})]})]}),e("button",{class:"btn",type:"submit",children:B?"Save project access":"Add teammate"})]})}),ie?e("p",{role:"status",children:ie}):null,e("button",{class:"btn primary",disabled:l,onClick:()=>void qe(),children:We.length?"Review setup":"Add teammates later"})]}):null,i===4?e("div",{class:"team-setup-fields",children:[e("h4",{children:W?"Ready to share with your team":"Your setup is saved, with steps still to finish"}),e("ul",{children:[e("li",{children:["Project: ",xe?.name??"Unavailable \u2014 choose a project"]}),e("li",{children:["Repositories: ",I.length?I.map(K=>K.key).join(", "):"Add a repository key"]}),e("li",{children:["Secure access: ",Ve??"Finish secure access setup"]}),e("li",{children:["Teammates: ",We.length," with access",We.some(K=>Su(K.roles[$]))?" \xB7 task execution enabled":" \xB7 add a contributor or maintainer to run tasks"]})]}),e("div",{class:"settings-actions",children:[e("button",{class:"btn",disabled:l,onClick:()=>d(0),children:"Edit project"}),e("button",{class:"btn",disabled:l,onClick:()=>d(1),children:"Edit repositories"}),e("button",{class:"btn",disabled:l,onClick:()=>d(2),children:"Edit secure access"}),e("button",{class:"btn",disabled:l,onClick:()=>d(3),children:"Edit teammates"})]}),W?e(j,{children:[e("label",{children:["Connection instructions",e("textarea",{class:"field",readOnly:!0,rows:8,value:Bi})]}),e("button",{class:"btn primary",onClick:()=>void Ot(Bi,"Connection instructions copied"),children:"Copy connection instructions"}),e("p",{class:"help",children:"Send each teammate\u2019s username and password separately. Ask one teammate to connect and confirm access; network permissions still apply. Use the same Code Flow version on every computer."})]}):null,e("div",{class:"settings-actions",children:[e("button",{class:"btn",disabled:l,onClick:()=>void qe(),children:"Check setup again"}),e("button",{class:"btn primary",disabled:l,onClick:()=>{if(s)return t();let K=new URL(location.href);K.hash="#/team",history.replaceState(history.state,"",K.href),ra("local")},children:s?"Finish setup":W?"Open team board":"Finish for now"})]})]}):null,i>0&&i<4?e("button",{class:"btn ghost",disabled:l,onClick:()=>{u(""),d(i-1)},children:"Back"}):null]}),c?e("p",{class:"msg err",role:"alert",children:c}):null]})}function PS(){let t=at.value,[s,n]=h(!1);Ee(()=>{xt(),Xs()},15e3,[Nt.value]);let a=Jt.value,r=Dt.value;return s&&t.kind!=="host"?e(xu,{onClose:()=>{n(!1),xt()}}):t.kind==="ssh"?e(j,{children:[e(Xr,{host:t,onManage:()=>n(!0)},t.id),e("section",{class:"settings-card",children:[e("h3",{children:["SSH workspace \xB7 ",t.name]}),e("p",{class:"help",children:"The workspace you opened over SSH has its own projects and task board. Manage the shared team server\u2019s projects, accounts and HTTPS in the setup above."}),e("a",{class:"btn",href:"/#/settings/connections/sharing",children:"Connect your computer to a team"})]})]}):e(j,{children:[t.kind!=="host"?e("section",{class:"settings-card",children:[e("h3",{children:"Host a team"}),e("p",{class:"help",children:"Set up a shared board on this computer or a connected remote server, with secure access and teammate accounts in one guided flow. Existing team connections stay connected."}),e("button",{class:"btn primary",onClick:()=>n(!0),children:"Set up team server"})]}):null,t.kind==="local"?e(fs,{}):null,t.kind==="local"?e(Vh,{link:a}):e("section",{class:"settings-card",children:[e("h3",{children:"This computer"}),e("p",{class:"help",children:"A team link belongs to the computer whose agents run the work. Connect from the code-flow on your own computer; this workspace runs on a remote server."}),e("p",{class:"help",children:"Use Set up team server to install a separate team server on a connected SSH machine. The wizard configures its projects, HTTPS and teammate accounts."})]}),t.kind==="local"?e(zh,{link:a,b:r}):null,e(Jh,{link:a,b:r}),r?.me.userId==="owner"&&a&&!a.linked?e(j,{children:[e(to,{board:r}),e(so,{board:r}),e(Zr,{board:r})]}):null,e(Kh,{b:r})]})}function Vh({link:t}){let[s,n]=h(""),[a,r]=h(""),[o,i]=h(""),[d,l]=h(""),[m,c]=h(!1),[u,p]=h(""),[f,v]=h(!1);_(()=>{t&&!t.linked&&!d&&t.machineName&&l(t.machineName)},[t?.machineName]);let g=async C=>{if(C.preventDefault(),!m){c(!0),p("");try{let k=await q("/api/team-link/connect",{url:s.trim(),username:a.trim(),password:o,...d.trim()?{name:d.trim()}:{}});i(""),V("Connected to the team server"),ra(k.id)}catch(k){i(""),p(k.message)}finally{c(!1)}}},w=async()=>{if(!(!t||!await Ce(`Disconnect this computer from ${t.hubName||t.url||"the team server"}? Its runner credential is revoked; attempts you ran here stay on the board as they are.`,{title:"Disconnect this computer?",confirmLabel:"Disconnect",danger:!0}))){c(!0),p("");try{await Yn("/api/team-link"),V("Disconnected"),ra("local")}catch(C){p(C.message)}finally{c(!1)}}};return e("section",{class:"settings-card","aria-busy":m,children:[e("h3",{children:"This computer"}),t?t.linked&&!f?e(j,{children:[e("p",{class:"help",children:"Linked to a team server: its board shows under Team, and tasks you start here publish their progress and checkpoints to it."}),e("dl",{class:"team-kv",children:[e("dt",{children:"Team server"}),e("dd",{children:[e("code",{children:t.url}),t.hubName?` \xB7 ${t.hubName}`:""]}),e("dt",{children:"Signed in as"}),e("dd",{children:t.user?`${t.user.displayName} (${t.user.username})`:"unknown"}),e("dt",{children:"Machine name"}),e("dd",{children:t.machineName??t.runner?.name??"\u2014"}),e("dt",{children:"Runner"}),e("dd",{children:t.runner?e(j,{children:[e("span",{class:`badge ${t.runner.revokedAt?"warn":t.runner.online?"ok":""}`,children:t.runner.revokedAt?"Revoked":t.runner.online?"Online":"Offline"})," ",e("span",{class:"help",children:["last seen ",ut(t.runner.lastSeenAt)]})]}):e("span",{class:"help",children:"Not reported yet"})}),t.lastSync?e(j,{children:[e("dt",{children:"Last sync"}),e("dd",{children:ut(t.lastSync)})]}):null]}),t.error?e("p",{class:"msg err",role:"alert",children:t.error}):null,e("div",{class:"settings-actions",children:[e("button",{class:"btn primary",disabled:m,onClick:()=>v(!0),children:"Add team connection"}),e("button",{class:"btn",disabled:m,onClick:()=>void w(),children:"Disconnect this team"})]})]}):e("form",{class:"team-connect",onSubmit:C=>void g(C),children:[e("p",{class:"help",children:"Join a teammate's board: the team server is another code-flow reachable over HTTPS (through Tailscale or another network), and you sign in with the shared account its owner created for you with the contributor or maintainer role. This computer stays the only place your agents run. You can save several team servers and keep using your own board."}),e("div",{class:"settings-grid",children:[e("label",{children:["Team server URL",e("input",{class:"field",type:"url",required:!0,placeholder:"https://hub.your-tailnet.ts.net:4318",value:s,disabled:m,autoComplete:"url",onInput:C=>n(C.currentTarget.value)})]}),e("label",{children:["Username",e("input",{class:"field",required:!0,maxLength:64,value:a,disabled:m,autoComplete:"username",onInput:C=>r(C.currentTarget.value)})]}),e("label",{children:["Password",e("input",{class:"field",type:"password",required:!0,value:o,disabled:m,autoComplete:"current-password",onInput:C=>i(C.currentTarget.value)})]}),e("label",{children:["Machine name",e("input",{class:"field",maxLength:80,value:d,disabled:m,placeholder:"How teammates see this computer",onInput:C=>l(C.currentTarget.value)})]})]}),e("div",{class:"settings-actions",children:e("button",{type:"submit",class:"btn primary",disabled:m||!s.trim()||!a.trim()||!o,children:m?"Connecting\u2026":"Connect this computer"})}),f?e("button",{type:"button",class:"btn",onClick:()=>v(!1),children:"Cancel"}):null]}):e("p",{class:"help",children:Ia.value?`The team link could not be read: ${Ia.value}`:"Loading\u2026"}),u?e("p",{class:"msg err",role:"alert",children:u}):null]})}function zh({link:t,b:s}){let[n,a]=h({}),[r,o]=h(""),[i,d]=h(""),l=(s?.projects??[]).flatMap(c=>c.repositories.map(u=>({project:c,ref:u,key:`${c.id}/${u.key}`,saved:t?.mappings[c.id]?.[u.key]??""}))),m=async(c,u,p,f)=>{if(!r){o(f),d("");try{await hs("/api/team-link/mappings",{projectId:c,repository:u,path:p}),V("Repository mapped"),await Xs(),a(v=>{let g={...v};return delete g[f],g})}catch(v){d(v.message)}finally{o("")}}};return e("section",{class:"settings-card",children:[e("h3",{children:"Repositories"}),e("p",{class:"help",children:"Tasks name a repository by its key; map each key to your clone so attempts, hand-overs and fetched checkpoints land there. Paths stay on this computer and never reach the team server."}),s?l.length?e("div",{class:"team-mappings",children:l.map(({project:c,ref:u,key:p,saved:f})=>{let v=n[p]??f,g=v!==f,w=`team-map-${p.replace(/[^a-zA-Z0-9_-]/g,"_")}`;return e("div",{class:"team-mapping",children:[e("label",{for:w,children:[c.name," \xB7 ",u.label," ",e("code",{children:u.key}),u.remote?e("span",{class:"help",children:[" ",u.remote]}):null]}),e("div",{class:"row-inline",children:[e("input",{id:w,class:"field mono",placeholder:"/absolute/path/to/your/clone",value:v,disabled:!!r,onInput:C=>a({...n,[p]:C.currentTarget.value})}),e("button",{type:"button",class:"btn small",disabled:!!r||!ne.value,title:ne.value||"Choose a repository in the composer first",onClick:()=>a({...n,[p]:ne.value}),children:"Use current repository"}),e("button",{type:"button",class:"btn small primary",disabled:!!r||!g||!v.trim(),onClick:()=>void m(c.id,u.key,v.trim(),p),children:r===p?"Saving\u2026":"Save"})]}),!f&&!g?e("span",{class:"help",children:"Not mapped on this computer."}):null]},p)})}):e("p",{class:"help",children:["No repository keys yet. A maintainer defines them per project",t?.linked?" on the team server":" in the Team server card below","."]}):e("p",{class:"help",children:Xt.value||"Loading the board\u2026"}),i?e("p",{class:"msg err",role:"alert",children:i}):null]})}function Jh({link:t,b:s}){let n=!!t&&!t.linked,[a,r]=h(null),[o,i]=h(""),[d,l]=h(!1),[m,c]=h("");Ee(async f=>{if(n)try{let v=await U("/api/remote");f()&&r(v)}catch{f()&&r(null)}},3e4,[n],n),_(()=>{s&&s.me.userId==="owner"&&i(s.me.displayName)},[s?.me.displayName]);let u=(s?.projects??[]).filter(f=>je(f.role,"maintainer")),p=Lr(a);return e("section",{class:"settings-card",children:[e("h3",{children:"Team server"}),t?n?e(j,{children:[e("p",{class:"help",children:"This computer is a team server: teammates reach its board over HTTPS with shared accounts, and work runs on their own computers or through the host permissions below."}),e("dl",{class:"team-kv",children:[e("dt",{children:"Address"}),e("dd",{children:p?e(j,{children:[e("code",{children:p})," ",e("button",{type:"button",class:"btn small",onClick:()=>void Ot(p,"Address copied"),children:"Copy"}),e("span",{class:"help",children:" Teammates enter this address under Connections \u2192 Share access \u2192 Connect this computer. Never share the phone link from Settings \u2192 Remote access: its path is a secret."})]}):a?.tailscaleUrl||a?.lanUrls?.length?e("span",{class:"help",children:["Remote access is on without HTTPS. ",e("a",{href:"#/settings/connections/sharing",children:"Set up secure remote access in Settings \u2192 Remote access"}),": teammates sign in and connect their computers over https:// only."]}):e("span",{class:"help",children:[e("a",{href:"#/settings/connections/sharing",children:"Turn on secure remote access in Settings \u2192 Remote access"})," so teammates can reach this computer."]})}),e("dt",{children:"Accounts"}),e("dd",{children:[e("a",{class:"btn small",href:"#/settings/projects",children:"Accounts & roles"}),e("span",{class:"help",children:" Give teammates the contributor role to own and run tasks, maintainer to manage project repository keys. Only the hub owner manages other accounts\u2019 runners."})]})]}),s?.me.userId==="owner"?e("form",{class:"team-inline",onSubmit:async f=>{if(f.preventDefault(),!d){l(!0),c("");try{await hs("/api/team/profile",{displayName:o.trim()}),V("Name saved"),xt()}catch(v){c(v.message)}finally{l(!1)}}},children:[e("label",{children:["Your name on the board",e("input",{class:"field",required:!0,maxLength:120,value:o,disabled:d,onInput:f=>i(f.currentTarget.value)})]}),e("button",{type:"submit",class:"btn small",disabled:d||!o.trim()||o.trim()===s.me.displayName,children:"Save name"})]}):null]}):e("p",{class:"help",children:["This computer is linked to ",t.hubName||t.url,": the board, the accounts and the runners live there.",u.length?" As a maintainer you can edit repository keys below.":""]}):e("p",{class:"help",children:"Loading\u2026"}),m?e("p",{class:"msg err",role:"alert",children:m}):null,s&&u.map(f=>e(wi,{project:f,revision:s.revision},f.id)),s&&t&&!u.length?e("p",{class:"help",children:n?"Create a project to define its repository keys.":"Repository keys are edited by project maintainers."}):null]})}function wi({project:t,revision:s}){let[n,a]=h(t.repositories.map(v=>({...v}))),[r,o]=h(!1),[i,d]=h(""),l=JSON.stringify(t.repositories),m=JSON.stringify(n)!==l,c=Q(m);c.current=m,_(()=>{c.current||a(t.repositories.map(v=>({...v})))},[l]);let u=(v,g)=>a(n.map((w,C)=>C===v?{...w,...g}:w)),p=async()=>{if(r)return;o(!0),d("");let v=n.map(g=>({key:g.key.trim(),label:g.label.trim()||g.key.trim(),...g.remote?.trim()?{remote:g.remote.trim()}:{},...g.defaultBranch?.trim()?{defaultBranch:g.defaultBranch.trim()}:{}}));try{await hs(`/api/team/projects/${J(t.id)}/repositories`,{repositories:v,revision:s}),V("Repository keys saved"),xt()}catch(g){g instanceof Ge&&g.status===409?(V("Board changed; reloading",3e3),xt()):d(g.message)}finally{o(!1)}},f=(v,g)=>`team-keys-${t.id}-${v}-${g}`;return e("fieldset",{class:"team-keys",disabled:r,children:[e("legend",{children:["Repository keys \xB7 ",t.name]}),e("p",{class:"help",children:"A key is up to 64 lowercase letters, digits or dashes and starts with a letter; the remote and default branch are hints for teammates."}),n.map((v,g)=>e("div",{class:"team-key-row",children:[e("label",{for:f(g,"key"),children:"Key"}),e("input",{id:f(g,"key"),class:"field mono",required:!0,pattern:"[a-z][a-z0-9-]{0,63}",maxLength:64,value:v.key,onInput:w=>u(g,{key:w.currentTarget.value})}),e("label",{for:f(g,"label"),children:"Label"}),e("input",{id:f(g,"label"),class:"field",maxLength:80,value:v.label,onInput:w=>u(g,{label:w.currentTarget.value})}),e("label",{for:f(g,"remote"),children:"Remote"}),e("input",{id:f(g,"remote"),class:"field mono",maxLength:300,placeholder:"git@github.com:org/repo.git",value:v.remote??"",onInput:w=>u(g,{remote:w.currentTarget.value})}),e("label",{for:f(g,"branch"),children:"Default branch"}),e("input",{id:f(g,"branch"),class:"field mono",maxLength:100,placeholder:"main",value:v.defaultBranch??"",onInput:w=>u(g,{defaultBranch:w.currentTarget.value})}),e("button",{type:"button",class:"btn small ghost","aria-label":`Remove repository key ${v.key||g+1}`,onClick:()=>a(n.filter((w,C)=>C!==g)),children:"Remove"})]},g)),e("div",{class:"settings-actions",children:[e("button",{type:"button",class:"btn small",disabled:n.length>=50,onClick:()=>a([...n,{key:"",label:""}]),children:"Add repository"}),e("button",{type:"button",class:"btn small primary",disabled:!m||n.some(v=>!/^[a-z][a-z0-9-]{0,63}$/.test(v.key.trim())),onClick:()=>void p(),children:"Save repository keys"}),m?e("button",{type:"button",class:"btn small",onClick:()=>a(t.repositories.map(v=>({...v}))),children:"Discard"}):null]}),i?e("p",{class:"msg err",role:"alert",children:i}):null]})}function Kh({b:t}){let[s,n]=h(null),[a,r]=h(""),[o,i]=h(""),d=async(c=()=>!0)=>{try{let u=await U("/api/team/runners");c()&&(n(Array.isArray(u)?u:u.runners??[]),i(""))}catch(u){c()&&i(u.message)}};Ee(d,15e3,[Nt.value]);let l=async c=>{if(await Ce(`Revoke the runner ${c.name}? Its computer must connect again to work on the board. Active tasks stay reserved until execution is confirmed stopped.`,{title:"Revoke runner access?",confirmLabel:"Revoke access",danger:!0})){r(c.id),i("");try{await Yn(`/api/team/runners/${J(c.id)}`),V("Runner revoked"),await d()}catch(u){i(u.message)}finally{r("")}}},m=(s??[]).slice().sort((c,u)=>+!!c.revokedAt-+!!u.revokedAt||u.lastSeenAt-c.lastSeenAt);return e("section",{class:"settings-card",children:[e("h3",{children:"Runners"}),e("p",{class:"help",children:["The computers connected to the board",t?.me.userId==="owner"?" (every teammate's, as the team server's owner)":" with your account",". Revoking one ends its credential; the work it did stays."]}),o?e("p",{class:"msg err",role:"alert",children:o}):null,s===null&&!o?e("p",{class:"help",role:"status",children:"Loading\u2026"}):null,s&&!s.length?e("p",{class:"help",children:"No runner has connected yet."}):null,m.length?e("div",{class:"pd-list",children:m.map(c=>e("div",{class:"pd-row",children:[e("span",{class:"pd-name",children:c.name}),e("span",{class:`badge ${c.revokedAt?"warn":c.online?"ok":""}`,children:c.revokedAt?"Revoked":c.online?"Online":"Offline"}),e("span",{class:"pd-when",children:[Xc(t,c.userId)," \xB7 last seen ",ut(c.lastSeenAt)]}),c.revokedAt?null:e("button",{type:"button",class:"btn small",disabled:!!a,onClick:()=>void l(c),children:a===c.id?"Revoking\u2026":"Revoke"})]},c.id))}):null]})}function ia({project:t,shared:s=!1,embedded:n=!1,navigate:a}){Ee(()=>void xt(),s?0:15e3,[Nt.value,s]);let r=Dt.value;if(!r)return e("p",{role:Xt.value?"alert":"status",children:Xt.value||"Loading people\u2026"});let o=r.projects.filter(l=>!t||l.id===t);if(!o.length)return e("p",{role:"status",children:"No accessible project here. Ask the project owner for access."});let i=!s&&gs==="local"&&r.me.userId==="owner",d={...r,projects:o};return e("section",{class:"team-page project-people","aria-label":"Project people",children:[!s&&!n?e(fs,{}):null,e("h2",{children:"People"}),e("p",{class:"help",children:"Project members and access. Task ownership and progress are on the Board."}),e("button",{class:"btn",onClick:()=>a({view:"team",...t?{project:t}:{}}),children:"Open Board"}),o.map(l=>e("section",{class:"settings-card",children:[e("h3",{children:l.name}),e("ul",{children:l.members.map(m=>e("li",{children:[m.displayName," \xB7 ",$a(m.role)]},m.userId))}),je(l.role,"maintainer")?e(wi,{project:l,revision:r.revision}):null]},l.id)),i?e(j,{children:[e(ku,{projects:fe.value,projectId:t}),e(to,{board:d}),e(Zr,{board:d})]}):e("p",{class:"help",children:"The project owner manages accounts and grants. Your role controls the actions available here."})]})}function Ru(t){let[s,n]=h({board:!1,automation:!1});return Ee(async a=>{let r=await Promise.allSettled([U("/api/team/board?teamConnection=local"),U("/api/automations"),U("/api/deferred-runs"),U(`/api/project-teams?project=${encodeURIComponent(t)}`)]);if(!a())return;let[o,i,d,l]=r,m=o.status==="fulfilled"&&(o.value.tasks.some(u=>u.projectId===t)||o.value.projects.some(u=>u.id===t&&(u.repositories.length>0||u.members.some(p=>p.userId!=="owner")))),c=i.status==="fulfilled"&&i.value.some(u=>u.run.project===t)||d.status==="fulfilled"&&d.value.some(u=>u.run.project===t)||l.status==="fulfilled"&&l.value.teams.length>0;n(u=>({board:u.board||m,automation:u.automation||c}))},15e3,[t]),s}function Ti({id:t,section:s,repository:n,tool:a,kind:r}){let o=Ru(t),i=fe.value.find(c=>c.id===t);if(!i)return e("div",{class:"project-page",children:[e("p",{role:"status",children:Us.value?"This project is unavailable. Its existing runs and saved draft are retained.":"Loading project\u2026"}),e("a",{class:"btn",href:"#/",children:"Open new run"})]});let d=c=>{let u=Ps({view:"project",id:t,...c?{section:c}:{}});return c==="board"||c==="people"?Ha(u,"local"):u},l=c=>{c.view==="team"&&c.project===t?Z.value={view:"project",id:t,section:"board"}:c.view==="team-people"&&c.project===t?Z.value={view:"project",id:t,section:"people"}:Z.value=c};if((s==="board"||s==="people")&&gs!=="local")return e("p",{role:"status",children:["Opening this project's board on ",Qt(),"\u2026 ",e("a",{href:d(s),children:"Continue"})]});let m=n??(i.repos.length===1?i.repos[0]:void 0);return e("div",{class:"project-page",children:[e("header",{class:"page-head",children:[e("div",{class:"page-head-text pp-title",children:[e("h1",{children:i.name}),e("p",{class:"project-computer-label",children:[e(z,{name:"terminal"}),"Computer: ",Qt()]})]}),e("div",{class:"page-head-actions",children:[e("button",{class:"btn primary",disabled:!qt.value||dt.value,onClick:()=>void st(t),children:[e(z,{name:"plus"}),"New run"]}),e(nt,{label:"Project actions",icon:"more",children:c=>e(j,{children:[e(me,{onClick:()=>{c(),ga(t)},children:"Edit project"}),e(me,{onClick:()=>{c(),Z.value={view:"project",id:t,section:"settings"}},children:"Project settings"})]})})]})]}),e("nav",{class:"project-tabs","aria-label":"Project navigation",children:[[[void 0,"Overview"],["runs","Runs"],["repositories","Repositories"]].map(([c,u])=>e("a",{class:`btn ${s===c?"primary":""}`,href:d(c),"aria-current":s===c?"page":void 0,children:u})),o.board||s==="board"?e("a",{class:"btn",href:d("board"),"aria-current":s==="board"?"page":void 0,children:"Board"}):null,o.automation||s==="automation"?e("a",{class:"btn",href:d("automation"),"aria-current":s==="automation"?"page":void 0,children:"Automation"}):null,e("a",{class:"btn",href:d("settings"),"aria-current":s==="settings"?"page":void 0,children:"Project settings"}),e(nt,{label:"More project tools",icon:"more",trigger:e("span",{children:"More"}),class:"project-more",children:c=>e(j,{children:["board","people","automation"].map(u=>e(me,{onClick:()=>{c(),u==="board"||u==="people"?location.assign(d(u)):Z.value={view:"project",id:t,section:u}},children:{board:"Board",people:"People",automation:"Automation"}[u]}))})})]}),s?s==="board"?e(oa,{project:t,embedded:!0,navigate:l}):s==="people"?e(ia,{project:t,embedded:!0,navigate:l}):s==="automation"?e(Ar,{projectId:t,kind:r},t):s==="runs"?e(Yh,{projectId:t},t):s==="repositories"?e(j,{children:[e("div",{class:"project-repository-head",children:[e("h2",{children:"Repositories"}),e("button",{class:"btn",onClick:()=>Gs(t),children:[e(z,{name:"plus"}),"Add repository"]})]}),i.repos.length?e("div",{class:"project-repository-list",children:i.repos.map(c=>e("a",{class:`pp-card project-repository ${m===c?"selected":""}`,href:Ps({view:"project",id:t,section:"repositories",repository:c,tool:"code"}),children:[e("strong",{children:be(c)}),e("code",{children:c}),e("span",{children:"Open repository tools \u2192"})]}))}):e("p",{class:"help",children:["No repositories yet. Add a repository from ",Qt()," to use its files and tools."]}),m?e(Ir,{projectId:t,initialFolder:m,initialTool:a,onNavigate:(c,u)=>{Z.value={view:"project",id:t,section:"repositories",repository:c,tool:u}}},`${t}:${m}`):i.repos.length?e("p",{class:"help",children:"Choose a repository to inspect its files, checks, services and history."}):null]}):e(j,{children:[e("section",{class:"pp-card project-start",children:[e("h2",{children:"Project settings"}),e("p",{children:"Manage the project's name and repository membership."}),e("button",{class:"btn",onClick:()=>ga(t),children:"Edit project"})]}),e(dr,{project:t}),i.repos.map(c=>e(Nl,{repository:c},c)),e("a",{class:"btn",href:Ps({view:"project",id:t,section:"automation",kind:"missions"}),children:"Manage project missions"})]}):e(j,{children:[e("section",{class:"project-start pp-card","aria-label":"Start work",children:[e("h2",{children:Ct.value===t&&Pe.value.trim()?"Continue your draft":"What would you like to work on?"}),e("p",{children:i.repos.length?"Describe the outcome, choose your agents, and review the result here.":"Add a repository to start a run in this project."}),Ct.value===t&&Pe.value.trim()?e("p",{class:"draft-preview",children:Pe.value.slice(0,240)}):null,e("button",{class:"btn primary",disabled:!qt.value||dt.value,onClick:()=>i.repos.length?void st(t):Gs(t),children:i.repos.length?Ct.value===t&&Pe.value.trim()?"Continue draft":"Describe a task":"Add repository"})]}),e(gr,{projectId:t}),e(Gh,{id:t},t),e("a",{class:"btn",href:d("runs"),children:"View run history"})]})]})}function Gh({id:t}){let[s,n]=h(null),[a,r]=h(""),[o,i]=h({waiting:100,running:100,results:8}),[d,l]=h(!1);Ee(async c=>{l(!0);try{let u=await U(`/api/projects/${J(t)}/summary`);for(let p of["waiting","running","results"]){let f=u.sections[p];for(;c()&&f.nextCursor&&f.runs.length<o[p];){let v=await U(`/api/runs?limit=${Math.min(100,o[p]-f.runs.length)}&project=${J(t)}&section=${p}&cursor=${J(f.nextCursor)}`);f={...v,runs:[...f.runs,...v.runs]}}u.sections[p]=f}c()&&(n(u),r(""))}catch(u){c()&&r(u.message)}finally{c()&&l(!1)}},15e3,[t,o.waiting,o.running,o.results]);let m=c=>i(u=>({...u,[c]:u[c]+100}));return e(j,{children:[e("div",{class:"ins-cards pp-numbers",children:[e(Ci,{label:"Runs this week",value:s?String(s.week.runs):"\u2013"}),e(Ci,{label:"Checks passed",value:s?.week.runs?`${s.week.passed} of ${s.week.runs}`:"\u2013"}),e(Ci,{label:"API-equivalent",value:s?.week.costUsd?ht(s.week.costUsd):"\u2013",hint:"Claude's cost, as a measure of size"})]}),a?e("p",{class:"msg err",role:"alert",children:a}):null,s?["waiting","running","results"].map(c=>{let u=s.sections[c];return c!=="results"&&!u.total?null:e($u,{title:{waiting:"Needs you",running:"Running",results:"Recent results"}[c],count:u.total,runs:u.runs,attention:c==="waiting",empty:"No results yet. Start a run above.",more:u.nextCursor?()=>m(c):void 0,moreCount:Math.max(0,u.total-u.runs.length),loading:d},c)}):e("p",{class:"help",children:"Loading project history\u2026"})]})}function Ci({label:t,value:s,hint:n}){return e("div",{class:"ins-card",title:n,children:[e("div",{class:"ic-label",children:t}),e("div",{class:"ic-value",children:s})]})}function Yh({projectId:t}){let[s,n]=h(""),[a,r]=h(!1),[o,i]=h([]),[d,l]=h(null),[m,c]=h(null),[u,p]=h(!1),[f,v]=h(""),g=Q(0),w=async T=>{let $=++g.current;p(!0),v("");try{let x=new URLSearchParams({project:t,limit:"100",q:s.trim()});T&&x.set("cursor",T);let E=await U(`/api/runs?${x}`);if($!==g.current)return;i(A=>T?[...A,...E.runs]:E.runs),c(s.trim()),l(E.nextCursor??null)}catch(x){$===g.current&&v(x.message)}finally{$===g.current&&p(!1)}};_(()=>{let T=setTimeout(()=>void w(),150);return()=>{clearTimeout(T),g.current++}},[t,s]);let C=new Map(o.map(T=>[T.id,Ne.value.get(T.id)??T]));for(let T of Ne.value.values())Xe(T)?.id===t&&C.set(T.id,T);let k=s.trim().toLowerCase().split(/\s+/).filter(Boolean),y=new Set(m===s.trim()?o.map(T=>T.id):[]),b=[...C.values()].filter(T=>Xe(T)?.id===t&&!T.deleted&&(a||!T.archived)&&(T.cold&&y.has(T.id)||k.every($=>uu(T).includes($)))).sort((T,$)=>$.createdAt-T.createdAt);return e("section",{"aria-label":"Project run history",children:[e("div",{class:"project-history-controls",children:[e("label",{children:["Search this project's runs",e("input",{class:"field",type:"search",value:s,onInput:T=>n(T.currentTarget.value)})]}),e("label",{class:"check",children:[e("input",{type:"checkbox",checked:a,onChange:T=>r(T.currentTarget.checked)}),"Include archived runs"]})]}),f?e("p",{class:"msg err",role:"alert",children:[f," ",e("button",{class:"btn small",onClick:()=>void w(),children:"Retry"})]}):null,e($u,{title:"Run history",count:b.length,runs:b,empty:u?"Loading runs\u2026":"No runs match this view."}),d?e("button",{class:"btn",disabled:u,onClick:()=>void w(d),children:u?"Loading\u2026":"Load older runs"}):null]})}function $u({title:t,runs:s,count:n,empty:a,more:r,moreCount:o=0,attention:i=!1,loading:d=!1}){return e("section",{class:`pp-card ${i?"attention":""}`,"aria-label":t,children:[e("div",{class:"pp-card-head",children:[e("h2",{children:t}),n?e("span",{class:`pp-count ${i?"warn":""}`,children:n}):null]}),s.length?e("div",{class:"pp-list",children:s.map(l=>e(Qh,{run:l},l.id))}):a?e("p",{class:"pp-empty",children:a}):null,r?e("button",{type:"button",class:"pp-more",disabled:d,onClick:r,children:["Show ",Math.min(100,o)," more"]}):null]})}function Qh({run:t}){let s=ft(t),n=ve.value.find(d=>d.id===t.pattern)?.name??t.pattern,a=t.merges.length>0,r=Object.keys(t.prs).length>0,o=(d,l)=>e("span",{class:`status-pill ${d}`,children:l}),i=t.awaiting?o("awaiting","Waiting for you"):s==="failing"?o("failing","Check fails"):s==="done"?o("done","Check passes"):t.status!=="done"?o(t.status,ot[t.status]??t.status):o(s,it(t));return e("a",{class:"pp-row",href:`#/run/${encodeURIComponent(t.id)}`,title:t.task,children:[e("span",{class:`dot ${s}`,"aria-hidden":"true"}),e("span",{class:"t",children:t.task.split(`
114
+ `)[0]||"(no task)"}),e("span",{class:"pills",children:[i,t.archived?o("","Archived"):null,a?o("","Merged"):r?o("","PR open"):null]}),e("span",{class:"m",children:[n," \xB7 ",Wt(t.createdAt)]})]})}function Iu(){let[t,s]=h(null),[n,a]=h(""),r=JSON.stringify(fe.value.map(o=>[o.id,o.name,o.repos]));return _(()=>{if(at.value.kind==="host")return;let o=!0,i=!1,l=Je(async()=>{if(!(i||document.hidden)){i=!0;try{let m=await mt("/api/workspace-projects");o&&(s({...m,currentComputerId:cs??"local"}),a(""))}catch{o&&(s(null),a("Connected projects unavailable"))}finally{i=!1}}},15e3);return()=>{o=!1,l()}},[r,at.value.kind]),{directory:t,error:n}}function Si({directory:t,error:s,query:n,children:a}){return t?t.computers.length===1?e(j,{children:a}):e(j,{children:t.computers.map(r=>{let o=r.id===t.currentComputerId,i=r.projects.filter(d=>`${r.name} ${d.name}`.toLocaleLowerCase().includes(n.trim().toLocaleLowerCase())).sort((d,l)=>d.name.localeCompare(l.name)||d.id.localeCompare(l.id));return!o&&n.trim()&&!i.length?null:e("details",{class:"computer-projects",open:!0,"data-computer-id":r.id,children:[e("summary",{class:"rail-title",children:[r.name,e("span",{class:"computer-project-count",children:o?"Current":r.projects.length})]}),e("div",{role:"group","aria-label":`${r.name} projects`,children:o?a:r.error?e("p",{class:"rail-empty",role:"status",children:r.error}):i.length?i.map(d=>{let l=Fa(r.id,`#/project/${encodeURIComponent(d.id)}`);return e("a",{class:"connected-project-link",href:l,title:`Open ${d.name} on ${r.name}`,children:e("span",{children:d.name})},d.id)}):e("p",{class:"rail-empty",children:"No projects yet"})})]},r.id)})}):s||at.value.kind==="host"?e(j,{children:[a,s?e("p",{class:"rail-empty",role:"status",children:s}):null]}):e("p",{class:"rail-empty",role:"status",children:"Loading projects\u2026"})}var Xh=[["all","All"],["attention","Needs you"],["running","Running"],["passed","Passed"],["failing","Failing"],["flagged","Tests changed"]],Zh=5,Au=t=>t.awaiting||Et(t)?"Waiting for you":Kt(t)?"Unresolved work":t.triage?.state==="pending"?"In your inbox":ft(t)==="failing"?"Check failing":ft(t)==="unchecked"?"Check can't run":ft(t)==="unverified"?"Finished \xB7 not verified":ot[t.status]??t.status,ef=t=>Wt(t).replace(" ago","").replace("just now","now");function Eu(){let t=Iu(),s=t.directory,n=s&&s.computers.length>1?s.computers.find(I=>I.id===s.currentComputerId):void 0,[a,r]=h(!1),[o,i]=h(!1),[d,l]=h(null),[m,c]=h(!1),[u,p]=h(new Set),[f,v]=h(null),[g,w]=h(!1),[C,k]=h(""),[y,b]=h(new Set),T=yl.value,$=gl.value,x=vl.value,E=Z.value,A=E.view==="run"||E.view==="review"?E.id:void 0,P=E.view==="project"?E.id:void 0,D=[...Ne.value.values()].sort((I,re)=>re.createdAt-I.createdAt),S=D.filter(I=>bl(I)&&(!I.archived||T.archived)),R=D.filter(I=>I.archived).length,M=S.filter(I=>I.status!=="running"),O=M.map(I=>I.id).join(","),B=M.filter(I=>u.has(I.id));_(()=>{let I=new Set(O.split(","));p(re=>new Set([...re].filter(oe=>I.has(oe))))},[O]);let ee=I=>p(re=>{let oe=new Set(re);return oe.delete(I),oe}),se=I=>p(re=>{let oe=new Set(re);return oe.has(I)?oe.delete(I):oe.add(I),oe}),te=async I=>{w(!0),k("");let re=[],oe=0;for(let he of B)try{await q(`/api/runs/${he.id}/archive`,{archived:I,cleanup:!1}),ee(he.id),oe++}catch(le){re.push(`${he.task.split(`
115
+ `)[0]}: ${le.message}`)}oe&&V(`${oe} ${oe===1?"run":"runs"} ${I?"archived":"unarchived"}`),k(re.join(`
116
+ `)),w(!1)},G=S.filter(Ms),L=xi().length,Y=rs.value,X=Wa.value,N=Be.value.filter(I=>!I.available||Ss.value?.find(re=>re.id===I.id)?.signedIn===!1).length,ae=I=>{Z.value=I,Pt.value=!1},ie=I=>{st(I.id)},pe=I=>Fn({collapsed:T.collapsed.includes(I)?T.collapsed.filter(re=>re!==I):[...T.collapsed,I]}),ge=(I,re)=>{let oe=(I.usage?.inputTokens??0)+(I.usage?.outputTokens??0),he=Xe(I),le=[Au(I),co(I)?"tests changed in ways that could hide failures":"",ve.value.find(ce=>ce.id===I.pattern)?.name??I.pattern,he?he.repos.length>1?`${he.name} \xB7 ${be(I.repo)}`:he.name:be(I.repo),Wt(I.createdAt),oe?`${It(oe)} tok`:"",I.usage?.costUsd?ht(I.usage.costUsd):""].filter(Boolean);return e("div",{class:`rail-run-row ${m?"selecting":""}`,role:"group","aria-label":I.task.split(`
117
+ `)[0]||"Untitled run",children:[m?e("input",{type:"checkbox",class:"rail-run-check","aria-label":`Select ${I.task.split(`
118
+ `)[0]||"Untitled run"}`,checked:u.has(I.id),disabled:g||!!f||I.status==="running",onChange:()=>se(I.id)}):null,e("button",{type:"button",class:`run-item ${A===I.id?"active":""} ${Ms(I)?"unseen":""} ${I.archived?"archived":""}`,title:`${I.task.split(`
119
+ `)[0]}
120
+ ${le.join(" \xB7 ")}`,"aria-current":A===I.id?"page":void 0,disabled:m&&(g||!!f||I.status==="running"),onClick:()=>m?se(I.id):ae({view:"run",id:I.id}),children:[e("span",{class:`dot ${ft(I)}`,"aria-hidden":"true"}),e("span",{class:"t",children:[I.trigger?e(z,{name:I.trigger.via==="sweep"?"layers":I.trigger.via==="webhook"?"globe":"clock",class:"inline-icon"}):null,I.group?e(z,{name:"compare",class:"inline-icon"}):null,I.task.split(`
121
+ `)[0]||"(no task)"]}),e("span",{class:"m",children:[co(I)?e("span",{class:"flag",children:e(z,{name:"alert"})}):null,re]}),e("span",{class:"sr-only",children:[" ","\xB7 ",Au(I),I.archived?" \xB7 archived":""]})]},I.id),m?null:e(nt,{above:!0,class:"chat-choice rail-run-menu",label:"Run actions",icon:"more",children:ce=>e(j,{children:[e(me,{disabled:I.status==="running",onClick:()=>{ce(),q(`/api/runs/${I.id}/archive`,{archived:!I.archived,cleanup:!1}).then(()=>V(I.archived?"Run unarchived":"Run archived"),H=>V(H.message))},children:I.archived?"Unarchive":"Archive"}),e(me,{disabled:I.status==="running"||!!I.projectTeam,sub:I.projectTeam?"Project mission history is retained. Archive instead.":void 0,onClick:()=>{ce(),l(I)},children:"Delete\u2026"})]})})]},I.id)},Ie=I=>e("span",{class:"proj-actions",children:[e("button",{type:"button",class:"icon-btn",disabled:!qt.value||dt.value,"aria-label":`New run in ${I.name}`,title:`New run in ${I.name}`,onClick:()=>ie(I),children:e(z,{name:"plus"})}),e("button",{type:"button",class:"icon-btn","aria-label":`Edit ${I.name}`,title:"Rename, repositories, delete",onClick:()=>ga(I.id),children:e(z,{name:"more"})})]}),xe=I=>{if(!I.runs.length)return e("div",{class:"proj quiet",role:"group","aria-label":I.name,children:e("div",{class:`proj-head ${P&&P===I.project?.id?"here":""}`,children:[I.project?e("button",{type:"button",class:"proj-name",title:`Open ${I.name}: ${I.project.repos.join(", ")}`,"aria-current":P===I.project.id?"page":void 0,onClick:()=>ae({view:"project",id:I.project.id}),children:[e("span",{class:"pn",children:I.name}),I.archived?e("span",{class:"pc",children:[I.archived," archived"]}):null]}):e("span",{class:"proj-name",children:e("span",{class:"pn",children:I.name})}),I.project?Ie(I.project):null]})},I.key);let re=T.collapsed.includes(I.key),oe=y.has(I.key)||x,he=re?I.runs.filter(ce=>ce.id===A):oe?I.runs:I.runs.slice(0,Zh),le=re?0:I.runs.length-he.length;return e("div",{class:"proj",role:"group","aria-label":I.name,children:[e("div",{class:`proj-head ${P&&P===I.project?.id?"here":""}`,children:[e("button",{type:"button",class:"proj-fold","aria-expanded":!re,"aria-label":`${re?"Show":"Hide"} the runs in ${I.name}`,title:re?"Show its runs":"Hide its runs",onClick:()=>pe(I.key),children:e(z,{name:"chevron",class:"caret"})}),e("button",{type:"button",class:"proj-toggle","aria-current":I.project&&P===I.project.id?"page":void 0,title:I.project?`Open ${I.name}: ${I.project.repos.join(", ")}`:"Runs whose project was deleted",onClick:()=>I.project?ae({view:"project",id:I.project.id}):pe(I.key),children:[e("span",{class:"pn",children:I.name}),re&&I.runs.length?e("span",{class:"pc",children:I.runs.length}):null]}),I.project?Ie(I.project):null]}),he.map(ce=>ge(ce,ef(ce.createdAt))),le>0?e("button",{type:"button",class:"rail-more",onClick:()=>b(new Set([...y,I.key])),children:["Show ",le," more"]}):null]},I.key)},We;if(T.group==="status"){let I=[["Needs you",G],["Running",S.filter(oe=>oe.status==="running"&&!Ms(oe))],["Recent",S.filter(oe=>!oe.archived&&oe.status!=="running"&&!Ms(oe))],["Archived",S.filter(oe=>oe.archived)]],re=oe=>Xe(oe)?.name??be(oe.repo);We=I.map(([oe,he])=>he.length?e("section",{"aria-label":oe,children:[e("div",{class:"rail-title rail-section",children:[oe,oe==="Needs you"?e("span",{class:"count",children:he.length}):null]}),he.map(le=>ge(le,re(le)))]},oe):null)}else{let I=new Map(fe.value.map(ce=>[ce.id,{key:ce.id,project:ce,name:ce.name,runs:[],last:0,archived:0}])),re=ce=>{let H=Xe(ce)?.id??Bt;return I.has(H)||I.set(H,{key:H,name:"No project",runs:[],last:0,archived:0}),I.get(H)};for(let ce of D){let H=re(ce);H.last=Math.max(H.last,ce.createdAt),ce.archived&&H.archived++}for(let ce of S)Ms(ce)||re(ce).runs.push(ce);let oe=[...I.values()].sort((ce,H)=>H.last-ce.last||ce.name.localeCompare(H.name)),he=oe.filter(ce=>ce.runs.length),le=x?[]:oe.filter(ce=>!ce.runs.length&&ce.project);We=e(j,{children:[G.length?e("section",{"aria-label":"Needs you",children:[e("div",{class:"rail-title rail-section",children:["Needs you ",e("span",{class:"count",children:G.length})]}),G.map(ce=>ge(ce,Xe(ce)?.name??be(ce.repo)))]}):null,e("section",{"aria-label":"Projects",children:[e("div",{class:"rail-title rail-section",children:["Projects",e("button",{type:"button",class:"icon-btn","aria-label":"New project",title:"New project",onClick:()=>{ws.value="new",zt.value=!0},children:e(z,{name:"plus"})})]}),e(Si,{directory:s,error:t.error,query:$.q,children:[n?oe.filter(ce=>ce.runs.length||!x&&ce.project).sort((ce,H)=>ce.name.localeCompare(H.name)||ce.key.localeCompare(H.key)).map(xe):he.map(xe),!n&&le.length?e(j,{children:[e("button",{type:"button",class:"rail-more quiet","aria-expanded":o,onClick:()=>i(!o),children:[e(z,{name:"chevron",class:"caret"}),le.length," more project",le.length===1?"":"s"]}),o?le.map(xe):null]}):null]})]})]})}let Ve=!S.length;return e("nav",{class:`rail ${Pt.value?"open":""}`,"aria-label":"Runs",children:[e("div",{class:"rail-head",children:[e("a",{class:"brand",href:"#/","aria-label":"code-flow: new run",onClick:()=>Pt.value=!1,children:e("span",{class:"brand-name",children:["code",e("span",{children:"-flow"})]})}),e("button",{type:"button",class:"icon-btn rail-toggle","aria-label":X?"Expand sidebar":"Collapse sidebar",title:X?"Expand sidebar":"Collapse sidebar","aria-expanded":!X,"aria-controls":"run-navigation",onClick:()=>Pn(!X),children:e(z,{name:"sidebar"})}),e("button",{type:"button",class:"icon-btn rail-close","aria-label":"Close menu",onClick:()=>Pt.value=!1,children:e(z,{name:"close"})})]}),e("button",{class:"btn primary new-run",disabled:!qt.value||dt.value,"aria-label":"New run",title:"New run (n)",onClick:()=>void st(),children:[e(z,{name:"plus"})," ",e("span",{children:"New run"})]}),e("div",{class:"rail-destinations",role:"group","aria-label":"Work navigation",children:[e("a",{class:"nav-item",href:"#/inbox","aria-label":`Inbox${L?`, ${L} need attention`:""}`,title:"Inbox","aria-current":E.view==="inbox"?"page":void 0,children:[e(z,{name:"bell"}),e("span",{children:"Inbox"}),L?e("span",{class:"count",children:L}):null]}),e("a",{class:"nav-item",href:"#/automations",title:"Scheduling","aria-label":"Scheduling","aria-current":E.view==="automations"?"page":void 0,children:[e(z,{name:"clock"}),e("span",{children:"Scheduling"})]})]}),X?e("button",{type:"button",class:"icon-btn rail-search-button","aria-label":"Search runs",title:"Search runs (/)",onClick:()=>{Pn(!1),requestAnimationFrame(()=>document.getElementById("run-search")?.focus())},children:e(z,{name:"search"})}):null,e("div",{class:"rail-search",children:[e(z,{name:"search"}),e("input",{id:"run-search",class:"field",type:"search",placeholder:"Search runs","aria-label":"Search runs (press / to focus)",value:$.q,onInput:I=>zs({q:I.currentTarget.value}),onKeyDown:I=>{I.key==="Escape"?(zs({q:""}),I.currentTarget.blur()):(I.key==="ArrowDown"||I.key==="Enter")&&(I.preventDefault(),document.querySelector(".rail .run-item")?.[I.key==="Enter"?"click":"focus"]())}})]}),!X&&(D.length>0||m)?e("div",{class:"rail-selection",children:[e("div",{class:"rail-selection-head",children:[e("button",{type:"button",class:"btn small ghost",disabled:g||!!f,"aria-pressed":m,onClick:()=>{c(!m),p(new Set),k("")},children:m?"Done selecting":"Select runs"}),m?e("span",{role:"status",children:[B.length," selected"]}):null]}),m?e(j,{children:[e("div",{class:"rail-bulk-actions",children:[e("button",{type:"button",class:"btn small",disabled:g||!!f||!M.length,onClick:()=>p(B.length===M.length?new Set:new Set(M.map(I=>I.id))),children:B.length&&B.length===M.length?"Clear selection":"Select loaded"}),e("button",{type:"button",class:"btn small",disabled:g||!B.length,onClick:()=>void te(!0),children:"Archive"}),B.some(I=>I.archived)?e("button",{type:"button",class:"btn small",disabled:g,onClick:()=>void te(!1),children:"Unarchive"}):null,e("button",{type:"button",class:"btn small danger",disabled:g||!B.length||B.some(I=>!!I.projectTeam),onClick:()=>v(B),children:"Delete\u2026"})]}),e("span",{class:"help",children:g?"Updating runs\u2026":"Only stopped runs on this computer. Select loaded includes matching runs in folded projects."}),B.some(I=>!!I.projectTeam)?e("span",{class:"help",children:"Project mission history is retained for recovery and approvals. Archive these runs instead."}):null,C?e("div",{class:"err",role:"alert",children:C}):null]}):null]}):null,R||T.archived?e("button",{type:"button",class:"rail-archive-toggle","aria-label":T.archived?"Hide archived runs":"Show archived runs","aria-pressed":T.archived,onClick:()=>Fn({archived:!T.archived}),children:[e(z,{name:"archive"}),T.archived?"Hide archived runs":"Show archived runs",e("span",{children:R})]}):null,a?e("div",{class:"rail-filters",id:"rail-filters",children:[e("div",{class:"rf-row",children:[e("span",{class:"rf-label",children:"View and filter runs"}),e("button",{type:"button",class:"icon-btn","aria-label":"Close filters",onClick:()=>{r(!1),document.getElementById("run-search")?.focus()},children:e(z,{name:"close"})})]}),e("div",{class:"rf-row",children:[e("span",{class:"rf-label",children:"Group by"}),e("div",{class:"segmented small",role:"group","aria-label":"Group by",children:["project","status"].map(I=>e("button",{type:"button",class:T.group===I?"on":"","aria-pressed":T.group===I,onClick:()=>Fn({group:I}),children:I==="project"?"Project":"Status"},I))})]}),e("div",{class:"chips",role:"group","aria-label":"Status",children:Xh.map(([I,re])=>e("button",{type:"button",class:"chip-tpl","aria-pressed":$.status===I,onClick:()=>zs({status:I}),children:re},I))}),e("select",{class:"field","aria-label":"Pattern",value:$.pattern,onChange:I=>zs({pattern:I.currentTarget.value}),children:[e("option",{value:"",children:"Any pattern"}),ve.value.map(I=>e("option",{value:I.id,children:I.name},I.id))]}),e("select",{class:"field","aria-label":"Agent",value:$.agent,onChange:I=>zs({agent:I.currentTarget.value}),children:[e("option",{value:"",children:"Any agent"}),Be.value.map(I=>e("option",{value:I.id,children:I.displayName},I.id))]}),e("label",{class:"check",children:[e("input",{type:"checkbox",checked:$.thisRepo,onChange:I=>zs({thisRepo:I.currentTarget.checked})})," ",ne.value?`Only ${be(ne.value)}`:"Only the selected repository"]}),e("label",{class:"check",children:[e("input",{type:"checkbox",checked:T.archived,onChange:I=>Fn({archived:I.currentTarget.checked})})," Show archived runs"]})]}):null,x?e("div",{class:"rail-hint",children:[S.length," of ",D.length," runs",e("button",{type:"button",onClick:()=>zs({q:"",status:"all",pattern:"",agent:"",thisRepo:!1}),children:"Clear"})]}):null,e("div",{class:"rail-list",id:"run-navigation",children:[T.group==="status"?e(Si,{directory:s,error:t.error,query:$.q,children:We}):We,Ve?e("div",{class:"rail-empty",children:x?"No runs match":n?"No runs in this workspace yet":"No runs yet \u2014 start one on the right"}):null]}),e("div",{class:"rail-history",role:"region","aria-label":"Run history pages",children:[e("span",{class:"help",role:"status",children:bo.value?"Searching history\u2026":Bn.value===null?"Loading history\u2026":x?`${S.length} loaded matches \xB7 ${Bn.value} in history`:Ne.value.size>Bn.value?`${Ne.value.size} loaded \xB7 ${Bn.value} at last refresh`:`${Ne.value.size} of ${Bn.value} runs loaded`}),vo.value?e("button",{type:"button",class:"btn small",disabled:bo.value||yo.value,onClick:()=>void fl(),children:yo.value?"Loading\u2026":"Load older runs"}):null,hl.value?e("span",{class:"help",role:"status",children:[ml.value," running or attention items at last refresh. Older attention is paged; use Load older runs to include more."]}):null,ko.value?e("div",{class:"help",role:"alert",children:[ko.value,e("button",{class:"btn small",onClick:()=>void Un(),children:"Retry history"})]}):null,x&&!$.q.trim()&&vo.value?e("span",{class:"help",children:"Filters apply to loaded pages. Load older runs to include more history."}):null]}),e("div",{class:"rail-foot",children:e(nt,{class:"rail-menu",label:"Application menu",icon:"more",trigger:e(j,{children:[e("span",{class:"rail-menu-avatar",children:e(z,{name:"layers"})}),e("span",{class:"rail-menu-label",children:e("strong",{children:"Code Flow"})}),Y+L?e("span",{class:"rail-menu-count","aria-label":`${Y+L} items need attention`,children:Y+L>99?"99+":Y+L}):null,e(z,{name:"more"})]}),children:I=>e(j,{children:[xo.value||$n.value||Y?e(me,{on:E.view==="team"||E.view==="team-task"||E.view==="team-people",onClick:()=>{I(),ae({view:"team"})},children:[e(z,{name:"people"}),e("span",{children:"Board"}),Y?e("span",{class:"rail-menu-meta","aria-label":`${Y} unread`,children:Y}):null]}):null,e(me,{on:E.view==="settings",onClick:()=>{I(),ae({view:"settings"})},children:[e(z,{name:"sliders"}),e("span",{children:"Settings"}),e("kbd",{class:"rail-menu-meta",children:"\u2318,"})]}),e(me,{sub:`${Be.value.length} providers${N?` \xB7 ${N} need setup`:""}`,onClick:()=>{I(),Pt.value=!1,ms.value=!0},children:[e(z,{name:"sparkle"}),e("span",{children:"Agents & usage"})]}),e(me,{onClick:()=>{I(),ae({view:"workspace"})},children:[e(z,{name:"files"}),e("span",{children:"Repository tools"})]}),e(me,{onClick:()=>{I(),ae({view:"insights"})},children:[e(z,{name:"chart"}),e("span",{children:"Insights"})]}),e(me,{onClick:()=>{I(),ae({view:"automations"})},children:[e(z,{name:"clock"}),e("span",{children:"Scheduling"}),L?e("span",{class:"rail-menu-meta","aria-label":`${L} runs need attention`,children:L}):null]}),e(me,{onClick:()=>{I(),ae({view:"settings",section:"notifications"})},children:[e(z,{name:"bell"}),e("span",{children:"Notifications"})]}),e("div",{class:"rail-menu-divider",role:"separator"}),e(me,{on:a,onClick:()=>{I(),Pn(!1),r(!a),a||requestAnimationFrame(()=>document.querySelector("#rail-filters button")?.focus())},children:[e(z,{name:"sliders"}),e("span",{children:"View and filter runs"})]}),e(me,{on:T.archived,onClick:()=>{I(),Fn({archived:!T.archived})},children:[e(z,{name:"archive"}),e("span",{children:T.archived?"Hide archived runs":"Show archived runs"}),e("span",{class:"rail-menu-meta",children:R})]}),e(me,{onClick:()=>{I(),Pt.value=!1,rn.value=!0},children:[e(z,{name:"keyboard"}),e("span",{children:"Keyboard shortcuts"}),e("kbd",{class:"rail-menu-meta",children:"?"})]}),e("a",{class:"pop-item",role:"menuitem",href:"/docs/",target:"_blank",rel:"noreferrer",onClick:I,children:e("span",{class:"pi-main",children:[e(z,{name:"help"}),e("span",{children:"Help & documentation"}),e(z,{name:"external",class:"rail-menu-meta"})]})})]})})}),d?e(Mr,{run:d,onClose:()=>l(null)}):null,f?e(Wo,{runs:f,onDeleted:ee,onClose:()=>v(null)}):null]})}var tf=Ys(()=>import("./settings-QJZVW22Y.js").then(t=>t.SettingsView));function c0(){return e(j,{children:[Z.value.view==="side"?e(sf,{tab:Z.value.tab}):e(nf,{}),e(Sc,{})]})}function sf({tab:t}){return _(()=>(Os.value=t,Gt.value=!0,document.addEventListener("click",Pu),()=>document.removeEventListener("click",Pu)),[]),_(()=>{document.title=`code-flow \xB7 ${t}`},[t]),e("div",{class:"popped",children:[e(mi,{popped:!0}),e("div",{class:"sr-only",role:"status","aria-live":"polite",children:za.value}),sn.value?e("div",{class:"toast",role:"status",children:sn.value.text},sn.value.id):null]})}function Pu(t){if(t.defaultPrevented||t.button!==0||t.metaKey||t.ctrlKey||t.shiftKey||t.altKey)return;let s=t.target?.closest?.("a[href^='#/']");!s||s.getAttribute("target")||(t.preventDefault(),_e(ol(s.getAttribute("href"))))}function nf(){return _(()=>{let t=at.value;document.title=`${er.value?`(${er.value}) `:""}code-flow${t.kind==="ssh"?` \xB7 SSH ${t.name}`:""}`},[er.value,at.value]),_(()=>(window.addEventListener("keydown",Mu),()=>window.removeEventListener("keydown",Mu)),[]),_(()=>{Jc()},[]),_(()=>{Pt.value=!1},[Z.value]),e(j,{children:[e("a",{class:"skip-link",href:"#main-content",onClick:t=>{t.preventDefault(),document.getElementById("main-content")?.focus()},children:"Skip to main content"}),e(Bc,{}),e("div",{class:`app ${Gt.value?"with-side":""} ${Wa.value?"rail-collapsed":""}`,style:`--side-w:${jn.value}px`,children:[e(Eu,{}),Pt.value?e("div",{class:"rail-scrim","aria-hidden":"true",onClick:()=>Pt.value=!1}):null,e("div",{class:"main-col",children:[e(af,{}),e("main",{id:"main-content",tabIndex:-1,children:Z.value.view==="run"?e(Bd,{id:Z.value.id},Z.value.id):Z.value.view==="review"?e(ou,{id:Z.value.id,branch:Z.value.branch},`${Z.value.id}:${Z.value.branch}`):Z.value.view==="project"?e(Ti,{...Z.value},Z.value.id):Z.value.view==="workspace"&&Z.value.project?e(Ti,{id:Z.value.project,section:"repositories"},Z.value.project):["inbox","automations","workspace","insights"].includes(Z.value.view)?e(Tc,{current:Z.value},Z.value.view==="workspace"?`workspace:${Z.value.project??""}`:Z.value.view):Z.value.view==="settings"?e(tf,{section:Z.value.section,group:Z.value.group}):Z.value.view==="team"?e(oa,{project:Z.value.project,navigate:_e},"team"):Z.value.view==="team-people"?e(ia,{project:Z.value.project,navigate:_e},Z.value.project??"all"):Z.value.view==="team-task"?e(no,{id:Z.value.id,navigate:_e},Z.value.id):Z.value.view==="invalid"?e("div",{class:"composer",role:"alert",children:[e("h1",{children:"This link is invalid"}),e("p",{class:"lede",children:"The address contains an invalid or unsupported destination. Your saved work is available from the project and run lists."}),e("button",{class:"btn primary",onClick:()=>Z.value={view:"composer"},children:"Open new run"})]}):!qt.value||dt.value||Z.value.view==="composer"&&Z.value.project!==void 0&&Z.value.project!==Ct.value?e("div",{class:"composer",role:"status",children:ha.value||"Restoring your project draft\u2026"}):e(Lu,{},Ct.value)})]}),Gt.value?e("div",{class:"side-scrim","aria-hidden":"true",onClick:an}):null,e(mi,{})]}),e(df,{}),e(iu,{}),e(du,{}),zt.value?e(Wl,{}):null,ks.value?e(zl,{},ks.value.repository):null,ms.value?e(cf,{}):null,rn.value?e(lf,{}):null,on.value?e(qc,{}):null,e("div",{class:"sr-only",role:"status","aria-live":"polite",children:za.value}),sn.value?e("div",{class:"toast",role:"status",children:sn.value.text},sn.value.id):null]})}var ju=typeof navigator<"u"&&/Mac|iPhone|iPad|iPod/.test(navigator.platform||navigator.userAgent)?"\u2318":"Ctrl ";function af(){let t=Fi.value==="dark";return e("header",{class:"topbar",children:[e("button",{class:"icon-btn menu-btn","aria-label":"Show runs","aria-expanded":Pt.value,onClick:()=>Pt.value=!Pt.value,children:e(z,{name:"menu"})}),e(ir,{}),e(rf,{}),e("span",{class:`connection-status ${qn.value.state}`,role:"status",title:qn.value.state==="connected"?"Live updates are connected":"Live updates are unavailable; displayed run information may be out of date",children:[e("span",{class:"cs-dot","aria-hidden":"true"}),e("span",{class:"cs-label",children:qn.value.state==="connected"?"Connected":qn.value.state==="offline"?"Offline":qn.value.state==="reconnecting"?"Reconnecting\u2026":"Connecting\u2026"})]}),e("button",{class:"btn ghost command-btn","aria-label":"Open command palette",title:`Commands and navigation (${ju}K)`,onClick:()=>on.value=!0,children:[e(z,{name:"search"}),e("kbd",{class:"kbd-key","aria-hidden":"true",children:[ju,"K"]})]}),e("button",{class:"icon-btn","aria-label":t?"Use the light theme":"Use the dark theme",title:t?"Light theme":"Dark theme",onClick:Hi,children:e(z,{name:t?"sun":"moon"})}),e("button",{class:"icon-btn side-btn","aria-pressed":Gt.value,"aria-label":"Side panel",title:"Side panel: chat, files, terminal, browser, notes (\\\\)",onClick:()=>Gt.value?an():gt(),children:e(z,{name:"panel"})})]})}function rf(){let t=Z.value,s=t.view==="run"||t.view==="review"?Ne.value.get(t.id):void 0,n=e("span",{class:"sep","aria-hidden":"true",children:"/"}),a;if(s){let r=Xe(s);a=e(j,{children:[r?e("a",{class:"crumb",href:`#/project/${encodeURIComponent(r.id)}`,title:s.repo,children:r.name}):e("span",{class:"crumb",title:s.repo,children:"No project"}),n,e("span",{class:`crumb title ${t.view==="run"?"here":""}`,title:s.task,"aria-current":t.view==="run"?"page":void 0,children:s.task.split(`
122
+ `)[0]||"(no task)"}),t.view==="review"?e(j,{children:[n,e("span",{class:"crumb here","aria-current":"page",children:"Review"})]}):null]})}else if(t.view==="project")a=e(j,{children:[e("a",{class:"crumb",href:`#/project/${encodeURIComponent(t.id)}`,"aria-current":t.section?void 0:"page",children:fe.value.find(r=>r.id===t.id)?.name??"Project"}),t.section?e(j,{children:[n,e("span",{class:"crumb here","aria-current":"page",children:{runs:"Runs",repositories:"Repositories",settings:"Project settings",board:"Board",people:"People",automation:"Automation"}[t.section]})]}):null]});else if(t.view==="team"||t.view==="team-task"||t.view==="team-people"){let r=t.view==="team-task"?os.value?.id===t.id?os.value.title:Dt.value?.tasks.find(i=>i.id===t.id)?.title??"Task":void 0,o=t.view==="team"&&t.project?Dt.value?.projects.find(i=>i.id===t.project)?.name:void 0;a=r!==void 0?e(j,{children:[e("a",{class:"crumb",href:"#/team",children:"Board"}),n,e("span",{class:"crumb title here",title:r,"aria-current":"page",children:r})]}):o?e(j,{children:[e("a",{class:"crumb",href:"#/team",children:"Board"}),n,e("span",{class:"crumb here","aria-current":"page",children:o})]}):e("span",{class:"crumb here","aria-current":"page",children:t.view==="team-people"?"People":"Board"})}else if(t.view==="inbox"||t.view==="automations"||t.view==="workspace"||t.view==="insights")a=e(j,{children:[t.view==="workspace"&&t.project?e(j,{children:[e("a",{class:"crumb",href:`#/project/${encodeURIComponent(t.project)}`,children:fe.value.find(r=>r.id===t.project)?.name??"Project"}),n]}):null,e("span",{class:"crumb here","aria-current":"page",children:{inbox:"Inbox",automations:"Scheduling",workspace:"Repositories",insights:"Insights"}[t.view]})]});else if(t.view==="settings"){let r=t.section?Ua.find(o=>o.id===t.section):void 0;a=r?e(j,{children:[e("a",{class:"crumb",href:"#/settings",children:"Settings"}),n,e("span",{class:"crumb here","aria-current":"page",children:r.label})]}):e("span",{class:"crumb here","aria-current":"page",children:"Settings"})}else{let r=t.view==="composer"?"New run":"";a=r?e("span",{class:"crumb here","aria-current":"page",children:r}):null}return e("nav",{class:"crumbs-bar","aria-label":"Where you are",children:a})}function d0(t){if(Z.value.view==="side")return;let s=(Z.value.view==="run"||Z.value.view==="review")&&Z.value.id===t.id,n={done:it(t)==="Failed"?"finished, but its check fails":it(t)==="Blocked"?"finished, but its check couldn't run":it(t)==="Passed"?"finished, with passing checks":"finished, without passing verification",failed:"failed",stopped:Kt(t)?"has unresolved work":"stopped at a limit",interrupted:"was interrupted"},a=t.status!=="running"&&!t.awaiting?kl(t):void 0,r=t.awaiting?`code-flow: ${t.awaiting.title.toLowerCase()}`:Et(t)?"code-flow: your team needs an answer":a?`code-flow: PR needs you \u2014 ${a.detail}`:`code-flow: run ${n[t.status]??t.status}`;if(za.value=`${r.replace(/^code-flow: /,"")}: ${t.task.split(`
123
+ `)[0].slice(0,120)}`,!xl()||s&&!document.hidden)return;let o;try{o=new Notification(r,{body:t.task.split(`
124
+ `)[0],tag:t.id})}catch{return V(r.replace(/^code-flow: /,""),5e3)}o.onclick=()=>{window.focus(),_e({view:"run",id:t.id}),o.close()}}var of=[["\u2318, / Ctrl+,","Settings"],["\u2318K / Ctrl+K","Commands, projects and runs"],["/","Search runs"],["j / k","Next / previous run in the list"],["[ / ]","Previous / next step of the open run"],["n","New run"],["p","Pick the project for new runs, Insights and Scheduling"],["i","Insights"],["a","Scheduling"],["\u2318\u21B5","Start the run, or send what you typed"],["Esc","Close a dialog, or leave the search box"],["\\","Show or hide the side panel"],["?","This list"]];function Mu(t){if((t.metaKey||t.ctrlKey)&&!t.altKey&&t.key===","&&!t.defaultPrevented&&!document.querySelector("dialog[open]")){t.preventDefault(),_e({view:"settings"});return}if((t.metaKey||t.ctrlKey)&&!t.altKey&&t.key.toLowerCase()==="k"){t.preventDefault(),on.value=!on.value;return}if(t.metaKey||t.ctrlKey||t.altKey||t.defaultPrevented||t.target?.closest("input, textarea, select, [contenteditable=true], dialog"))return;let n=a=>{t.preventDefault(),_e(a)};switch(t.key){case"/":{t.preventDefault(),Pn(!1),Pt.value=!0;let a=()=>document.getElementById("run-search");a()?.focus(),document.activeElement!==a()&&requestAnimationFrame(()=>a()?.focus());return}case"n":t.preventDefault(),st();return;case"p":t.preventDefault(),ts.value=Z.value.view==="composer"?"composer":"filter",zt.value=!0;return;case"i":return n({view:"insights"});case"a":return n({view:"automations"});case"?":t.preventDefault(),rn.value=!0;return;case"\\":t.preventDefault(),Gt.value?an():gt();return;case"j":case"k":{let a=[...document.querySelectorAll(".rail .run-item")];if(!a.length)return;t.preventDefault();let r=a.findIndex(i=>i.classList.contains("active")),o=a[r<0?0:Math.min(a.length-1,Math.max(0,r+(t.key==="j"?1:-1)))];o.click(),o.scrollIntoView({block:"nearest"});return}}}function lf(){let t=we(!0,()=>rn.value=!1);return e("dialog",{class:"picker small-dialog",ref:t,"aria-labelledby":"shortcuts-title",children:e("div",{class:"picker-inner",children:[e("div",{class:"picker-head",children:e("h3",{id:"shortcuts-title",children:"Keyboard shortcuts"})}),e("div",{class:"dialog-body",children:e("table",{class:"shortcuts",children:e("tbody",{children:of.map(([s,n])=>e("tr",{children:[e("td",{children:e("kbd",{children:s})}),e("td",{children:n})]},s))})})}),e("div",{class:"picker-foot",children:[e("span",{class:"ps"}),e("button",{class:"btn primary",onClick:()=>rn.value=!1,children:"Done"})]})]})})}function cf(){let t=we(!0,()=>ms.value=!1);_(()=>{fo()},[]);let s=a=>a===void 0?"?":`${Math.round(a*100)}%`,n=a=>a?new Date(a).toLocaleString([],{weekday:"short",hour:"2-digit",minute:"2-digit"}):"";return e("dialog",{class:"picker small-dialog health",ref:t,"aria-labelledby":"health-title",children:e("div",{class:"picker-inner",children:[e("div",{class:"picker-head",children:[e("h3",{id:"health-title",children:"Health"}),e("div",{class:"help",children:"What code-flow can see about each CLI \u2014 it uses the CLIs' own commands and never reads their credentials."})]}),e("div",{class:"dialog-body",children:[Ss.value?null:e("div",{class:"help",children:"Checking\u2026"}),Ss.value?.map(a=>e("div",{class:"health-row",children:[e("div",{class:"hr-title",children:[e("span",{class:`agent ${a.id}`,children:a.name}),e("span",{class:`badge ${a.installed&&a.signedIn!==!1?"ok":""}`,children:a.installed?a.signedIn===!1?"Signed out":a.signedIn?`Signed in \xB7 ${a.account??""}`:"Installed":"Not installed"}),e("span",{class:"help",children:a.version})]}),a.quota&&Object.keys(a.quota.windows).length?e("div",{class:"quota",children:Object.entries(a.quota.windows).map(([r,o])=>e("div",{class:"q",children:[e("span",{children:[r.replace("_","-")," window"]}),e("span",{class:"bar",children:e("span",{style:`width:${Math.min(100,Math.round((o.utilization??0)*100))}%`})}),e("span",{children:[s(o.utilization)," used",o.resetsAt?` \xB7 resets ${n(o.resetsAt)}`:""]})]},r))}):a.quota?.status==="limited"?e("div",{class:"msg warn",children:"Hit a usage limit recently."}):a.installed?e("div",{class:"help",children:a.id==="claude"?"Quota shows after the next Claude step.":"This CLI doesn't report remaining quota."}):null,a.warnings?.map(r=>e("div",{class:"msg warn",children:r},r)),a.fix?e("div",{class:"msg warn",children:a.fix}):null]},a.id)),Ws.value?e("div",{class:"health-row",children:[e("div",{class:"hr-title",children:[e("span",{class:"agent",children:"git"}),e("span",{class:`badge ${Ws.value.ok?"ok":""}`,children:Ws.value.ok?"OK":Ws.value.installed?"Too old":"Not found"}),e("span",{class:"help",children:Ws.value.version})]}),Ws.value.warning?e("div",{class:"msg warn",children:Ws.value.warning}):null]}):null]}),e("div",{class:"picker-foot",children:[e("span",{class:"ps"}),e("button",{class:"btn",onClick:()=>fo(),children:"Check again"}),e("button",{class:"btn primary",onClick:()=>ms.value=!1,children:"Done"})]})]})})}function df(){let[t,s]=h(null),[n,a]=h(""),[r,o]=h(""),[i,d]=h(!1),l=Q(null),m=Q(!1),c=()=>{m.current=!1,f.current++,wt.value=!1,Ln.value=null},u=we(wt.value,c),p=Ln.value,f=Q(0),v=Q(!1),g=async(b,T=i)=>{if(!wt.value)return;m.current=!0;let $=++f.current;v.current=!1,o("Loading\u2026");let x=new URLSearchParams;b&&x.set("path",b),T&&x.set("hidden","1");try{let E=await U(`/api/fs?${x}`);if($!==f.current||!wt.value)return;s(E),!v.current&&document.activeElement!==l.current&&a(E.path),o(E.isRepo?"\u2713 This folder is a git repository":"Open a folder marked Git, or type a path")}catch(E){if($!==f.current||!wt.value)return;o(E.message),!t&&b&&g(void 0,T)}};Qe(()=>{wt.value&&!m.current&&g(ne.value||void 0),wt.value||(m.current=!1)},[wt.value]);let w=b=>{c(),p?p.choose(b):Ka(b)},C=t?t.path.split("/").filter(Boolean):[],k=t&&t.path===t.home?ll():[],y=(b,T,$,x)=>e("div",{class:"dir",title:$,children:[e("button",{type:"button",class:"dir-browse","aria-label":`Open folder ${T}`,onClick:()=>g($),children:[e("span",{class:"di",children:b}),e("span",{class:"dn",children:T}),x?e("span",{class:"git-badge",children:"Git"}):null]}),x?e("button",{class:"btn small",type:"button",onClick:E=>{E.stopPropagation(),w($)},children:"Use"}):null]},$);return e("dialog",{class:"picker",ref:u,"aria-labelledby":"folder-picker-title",children:e("div",{class:"picker-inner",children:[e("div",{class:"picker-head",children:[e("h3",{id:"folder-picker-title",children:p?p.title:"Choose a repository"}),e("div",{class:"row",children:[e("button",{class:"btn",type:"button",title:"Parent folder","aria-label":"Parent folder",disabled:!t?.parent,onClick:()=>t?.parent&&g(t.parent),children:"\u2191"}),e("button",{class:"btn",type:"button",title:"Home folder","aria-label":"Home folder",onClick:()=>g(t?.home),children:"~"}),e("input",{class:"field",type:"text",spellcheck:!1,"aria-label":"Folder path",ref:l,value:n,onInput:b=>{m.current=!0,v.current=!0,a(b.currentTarget.value)},onKeyDown:b=>{b.key==="Enter"&&(b.preventDefault(),g(b.currentTarget.value.trim()))}}),e("button",{class:"btn",type:"button",onClick:()=>g((l.current?.value??n).trim()),children:"Go"})]}),e("nav",{class:"crumbs","aria-label":"Folder breadcrumbs",children:[e("button",{type:"button","aria-label":"The root folder",onClick:()=>g("/"),children:"/"}),C.map((b,T)=>e("span",{children:[e("button",{type:"button","aria-current":T===C.length-1?"location":void 0,onClick:()=>g("/"+C.slice(0,T+1).join("/")),children:b}),T<C.length-1?"/":""]},T))]})]}),e("div",{class:"picker-list",children:[k.length?e("div",{class:"picker-section",children:"Recent"}):null,k.map(b=>y("\u2605",t?b.replace(t.home,"~"):b,b,!0)),k.length?e("div",{class:"picker-section",children:"Folders"}):null,t?.entries.map(b=>y(b.isRepo?"\u25C6":"\u25B8",b.name,b.path,b.isRepo)),t&&!t.entries.length?e("div",{class:"picker-section",children:"No subfolders"}):null,t?.truncated?e("div",{class:"picker-section",children:"Showing the first 500 \u2014 type a path above"}):null]}),e("div",{class:"picker-foot",children:[e("span",{class:"ps",children:r}),e("label",{children:[e("input",{type:"checkbox",checked:i,onChange:b=>{d(b.currentTarget.checked),g(t?.path,b.currentTarget.checked)}})," ","Hidden folders"]}),e("button",{class:"btn",type:"button",onClick:c,children:"Cancel"}),e("button",{class:"btn primary",type:"button",disabled:!t||n.trim()!==t.path||r==="Loading\u2026",onClick:()=>{let b=(l.current?.value??n).trim();t&&b===t.path&&r!=="Loading\u2026"&&w(t.path)},children:p?.title==="Open repository"?"Open this repository":p?"Add this folder":"Use this folder"})]})]})})}function we(t,s){let[n,a]=h(null),r=Q(new WeakMap);return _(()=>{if(!n)return;t&&!n.open&&n.showModal(),!t&&n.open&&(r.current.set(n,(r.current.get(n)??0)+1),n.close());let o=()=>{let i=r.current.get(n)??0;if(i){r.current.set(n,i-1);return}s()};return n.addEventListener("close",o),()=>n.removeEventListener("close",o)},[n,t]),a}function la(t){let s=t.status==="running"&&!!t.team?.awaitingRequestId;if(!(t.archived||t.projectTeam&&!t.awaiting&&!s)){if(t.awaiting||s)return"answer";if(t.team?.status==="blocked")return"blocked";if(!t.seen&&(t.status==="failed"||t.status==="interrupted"))return"failed";if(!t.seen&&t.status!=="running"){if(it(t)==="Blocked"||t.status==="stopped")return"blocked";if(it(t)==="Failed")return"failed"}if(t.triage?.state==="pending"||!t.seen&&t.status==="done"&&t.artifacts?.some(n=>n.stat?.trim()))return"review"}}var ao={answer:"Waiting for your answer",blocked:"Blocked work",failed:"Failed checks or execution",review:"Results to review"},Du={answer:0,blocked:1,failed:2,review:3};function Ri(t,s={}){let n=(s.query??"").trim().toLowerCase().split(/\s+/).filter(Boolean);return t.filter(a=>{let r=la(a);return r&&(!s.reason||r===s.reason)&&n.every(o=>[a.task,a.repo,a.id,a.trigger?.name??"",a.source?.title??""].join(`
125
+ `).toLowerCase().includes(o))}).sort((a,r)=>(r.priority??0)-(a.priority??0)||Du[la(a)]-Du[la(r)]||a.createdAt-r.createdAt||a.id.localeCompare(r.id))}function Nu(t,s){let n=new Map;for(let a of t){let r=s(a);n.has(r.id)||n.set(r.id,{...r,runs:[]}),n.get(r.id).runs.push(a)}return[...n.values()]}var Ii=t=>t.project?fe.value.find(s=>s.id===t.project):fe.value.filter(s=>s.repos.includes(t.repo)).length===1?fe.value.find(s=>s.repos.includes(t.repo)):void 0,uf=(t,s=Ye.value)=>{if(s===qs)return!0;let n=Ii(t.run);return s===Bt?!n:n?.id===s},_u=ke([]);async function ca(){try{_u.value=await zi("/api/automations")}catch{}}var xi=()=>Ri([...Ne.value.values()]),pf=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],$i=()=>Intl.DateTimeFormat().resolvedOptions().timeZone||"UTC";function vr({schedule:t}){let[s,n]=h([]),[a,r]=h(""),o=JSON.stringify(t);_(()=>{let l=!0;if(!t){n([]),r("");return}let m=setTimeout(()=>void q("/api/automations/schedule-preview",{schedule:t,after:Date.now(),count:5}).then(c=>{l&&(n(c.times),r(""))},c=>{l&&(n([]),r(c.message))}),200);return()=>{l=!1,clearTimeout(m)}},[o]);let i=t&&"at"in t?t.timezone:void 0,d=l=>{try{return new Date(l).toLocaleString([],{timeZone:i,weekday:"short",year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit",timeZoneName:"short"})}catch{return"Choose a valid time zone"}};return e("div",{role:"group","aria-label":"Next scheduled times",children:[e("p",{class:"help",children:["Next runs",i?` in ${i}`:"",":"]}),s.length?e("ol",{class:"help",children:s.map(l=>e("li",{children:d(l)},l))}):e("p",{class:"help",children:t?"Calculating\u2026":"No schedule"}),i?e("p",{class:"help",children:"Runs once per local day. A skipped daylight-saving time moves forward; a repeated time uses its first occurrence."}):null,a?e("p",{class:"msg err",role:"alert",children:a}):null]})}function br({automation:t,save:s}){let n=t.schedule,[a,r]=h(n?"every"in n?"every":"daily":"off"),[o,i]=h(n&&"at"in n?n.at:"07:00"),[d,l]=h(n&&"at"in n?n.timezone??$i():$i()),[m,c]=h(n&&"at"in n?n.days??[0,1,2,3,4,5,6]:[0,1,2,3,4,5,6]),[u,p]=h(n&&"every"in n?n.every:60),f=a==="off"?void 0:a==="every"?{every:u}:{at:o,timezone:d,days:m.length===7?void 0:m};return e("details",{children:[e("summary",{children:"Schedule and next times"}),e("label",{children:["Schedule",e("select",{class:"field","aria-label":`Schedule for ${t.name}`,value:a,onChange:v=>r(v.currentTarget.value),children:[e("option",{value:"off",children:"Only when triggered"}),e("option",{value:"daily",children:"At a time"}),e("option",{value:"every",children:"Every N minutes"})]})]}),a==="daily"?e(j,{children:[e("label",{children:["Time",e("input",{class:"field",type:"time",value:o,onInput:v=>i(v.currentTarget.value)})]}),e("label",{children:["Time zone",e("input",{class:"field",placeholder:"Europe/Stockholm",value:d,onInput:v=>l(v.currentTarget.value)})]})]}):a==="every"?e("label",{children:["Minutes",e("input",{class:"field",type:"number",min:5,max:10080,value:u,onInput:v=>p(Number(v.currentTarget.value))})]}):null,a==="daily"&&e("fieldset",{children:[e("legend",{children:"Days"}),["Sun","Mon","Tue","Wed","Thu","Fri","Sat"].map((v,g)=>e("label",{children:[e("input",{type:"checkbox",checked:m.includes(g),onChange:w=>c(w.currentTarget.checked?[...m,g].sort():m.filter(C=>C!==g))})," ",v]},v))]}),e(vr,{schedule:f}),e("button",{type:"button",class:"btn small",onClick:()=>s({schedule:f??null}),children:"Save schedule"})]})}function Sa({mode:t="all",category:s,projectId:n,showScope:a=!0}){_(()=>Je(ca,15e3),[]);let r=n??Ye.value,o=r!==qs,[i,d]=h("project"),[l,m]=h(""),[c,u]=h(""),p=xi(),f=p.filter(b=>Ja(b)),v=Ri(f,{query:c,reason:l||void 0}),g=Nu(v,b=>{if(i==="reason"){let $=la(b);return{id:$,label:ao[$]}}if(i==="repo")return{id:b.repo,label:b.repo};if(i==="none")return{id:"all",label:"All attention items"};let T=Xe(b);return{id:T?.id??"unassigned",label:T?.name??"Without a project"}}),w=_u.value.filter(b=>!s||!b.target&&(s==="backlog"?!!b.sweep:!b.sweep)),C=w.filter(b=>uf(b,r)),k=fe.value.find(b=>b.id===r),y=k?` in ${k.name}`:o?" without a project":"";return e("div",{class:"automations",children:[t!=="automations"?e(gr,{projectId:Ye.value!==qs&&Ye.value!==Bt?Ye.value:void 0}):null,a?e("div",{class:"page-head",children:[e("div",{class:"ph-text page-head-text",children:[e("h3",{children:"Project scope"}),e("p",{class:"lede",children:t==="inbox"?"Questions, blocked work, failed checks and results waiting for your review.":"Schedule work and manage triggers. Results wait in your Inbox; nothing is merged automatically."})]}),n?e("span",{children:k?.name}):e(Ks,{})]}):null,t!=="automations"?e("section",{class:"section auto-card","aria-labelledby":"inbox-title",children:[e("h2",{class:"section-title",id:"inbox-title",children:["Review inbox ",f.length?e("span",{class:"count",children:f.length}):null]}),e(Ou,{count:p.length-f.length,what:b=>`${b} in other projects need${b===1?"s":""} you`}),e("p",{class:"help inbox-note",children:"Higher run priorities come first, then questions, blocked work, failures and results. Older items come first within each priority. Open a run to answer approvals, resume work or review its evidence."}),e("div",{class:"wb-row inbox-filters",children:[e("label",{children:["Group by",e("select",{class:"field","aria-label":"Group review inbox",value:i,onChange:b=>d(b.currentTarget.value),children:[e("option",{value:"project",children:"Project"}),e("option",{value:"repo",children:"Repository"}),e("option",{value:"reason",children:"Attention needed"}),e("option",{value:"none",children:"No grouping"})]})]}),e("label",{children:["Show",e("select",{class:"field","aria-label":"Filter review inbox",value:l,onChange:b=>m(b.currentTarget.value),children:[e("option",{value:"",children:"All attention items"}),Object.entries(ao).map(([b,T])=>e("option",{value:b,children:T}))]})]}),e("label",{children:["Search",e("input",{class:"field","aria-label":"Search review inbox",value:c,onInput:b=>u(b.currentTarget.value),placeholder:"Task, repository or run ID"})]})]}),v.length?g.map(b=>e("section",{class:"inbox-group","aria-label":`Review group ${b.label}`,children:[e("h3",{children:[b.label," ",e("span",{class:"count",children:b.runs.length})]}),b.runs.map(T=>e(mf,{run:T,scoped:o},T.id))]},b.id)):e("p",{class:"help empty",children:f.length?"No attention items match these filters.":`Nothing to review${y}. Runs that changed nothing are archived on their own.`})]}):null,t!=="inbox"?e("section",{class:"section auto-card","aria-labelledby":"automations-title",children:[e("h2",{class:"section-title",id:"automations-title",children:[s==="backlog"?"Scheduled backlog work":"Repeating tasks and webhooks"," ",C.length?e("span",{class:"n",children:C.length}):null]}),n?null:e(Ou,{count:w.length-C.length,what:b=>`${b} more in other projects`}),C.length?C.map(b=>e(hf,{a:b,scoped:o},b.id)):e("p",{class:"help empty",children:["None",y," yet. Set up a run in the composer \u2014 task, team, check \u2014 and choose ",e("b",{children:"Schedule \u2192 Repeat"})," next to Start run."]})]}):null,e("p",{class:"help",children:["To access this computer from another device, open ",e("a",{href:"#/settings/connections/sharing",children:"Connections \u2192 Share access"}),"."]})]})}var Bu=(t,s,n)=>!n&&t&&t.name!==be(s)?t:void 0;function Ou({count:t,what:s}){return t<=0?null:e("div",{class:"rail-hint elsewhere",children:[s(t),e("button",{type:"button",onClick:()=>va(qs),children:"Show all"})]})}function mf({run:t,scoped:s}){let n=t.artifacts.filter(r=>r.stat?.trim()),a=Bu(Xe(t),t.repo,s);return e("div",{class:"inbox-item",children:[e("div",{class:"ih",children:[e("span",{class:"badge",children:ao[la(t)]}),t.priority?e("span",{class:"badge",children:["Priority ",t.priority>0?"+":"",t.priority]}):null,e("span",{class:`dot ${ft(t)}`}),e("a",{href:`#/run/${t.id}`,class:"t",children:[t.task.split(`
126
+ `)[0],t.source?.title&&!t.task.includes(t.source.title)?` \u2014 ${t.source.title}`:null]}),e("span",{class:"help",children:[t.trigger?e(j,{children:[e(z,{name:t.trigger.via==="sweep"?"layers":t.trigger.via==="webhook"?"globe":"clock",class:"inline-icon"})," ",t.trigger.name," \xB7 "]}):null,ot[t.status]??t.status,` \xB7 checks: ${it(t).toLowerCase()}`," \xB7 ",be(t.repo),a?e(j,{children:[" \xB7 ",e(z,{name:"project",class:"inline-icon"})," ",a.name]}):null," \xB7 ",Wt(t.createdAt)]})]}),t.awaiting?e("a",{class:"btn small primary",href:`#/run/${t.id}`,children:"Open pending approval"}):null,t.checkCantRun?e(Cr,{cantRun:t.checkCantRun}):null,t.team?e("div",{class:"help",children:["Team: ",t.team.members.length," members \xB7 ",t.team.tasks.filter(r=>r.status==="completed").length,"/",t.team.tasks.length," tasks completed \xB7 ",t.team.metrics.invocations," calls"]}):null,Et(t)?e("div",{class:"at-notice",children:[e("b",{children:"The team needs your answer"}),e("p",{children:t.team?.messages.find(r=>r.id===t.team.awaitingRequestId)?.body}),e("a",{class:"btn small primary",href:`#/run/${t.id}`,children:"Answer team question"})]}):t.team?.status==="blocked"?e("div",{class:"at-notice",children:[e("p",{children:t.team.gaps.join(" ")}),e("a",{class:"btn small",href:`#/run/${t.id}`,children:"Continue team work"})]}):null,t.review?e("div",{class:"help",children:["Review: ",t.review.verdict==="approve"?"approve":`${t.review.findings.length} findings`]}):null,n.map(r=>e("pre",{class:"stat",tabIndex:0,"aria-label":`Changed files on ${r.branch}`,children:[r.label," \xB7 ",r.branch,`
127
+ `,r.stat]},r.branch)),t.error?e("div",{class:"msg err",children:t.error}):null,t.triage?.state==="pending"?e(ri,{run:t}):null]})}function ri({run:t}){let[s,n]=h(""),[a,r]=h(""),[o,i]=h(t.loop.maxInvocations??t.loop.maxSteps),[d,l]=h(t.loop.maxMinutes),m=async(f,v={})=>{if(!(f==="reject"&&!await Ce("Reject this result? Its worktrees and branches are deleted.",{title:"Reject this result?",confirmLabel:"Reject result",danger:!0}))){r(f);try{await q(`/api/runs/${t.id}/triage`,{decision:f,note:s,...f==="revise"?{budget:{maxSteps:o,maxInvocations:o,maxMinutes:d}}:{},...v}),V(f==="approve"?v.pushPr?`Approved \u2014 pushed to PR #${t.source?.number}`:v.openPr?"Approved \u2014 pull request opened":"Approved":f==="revise"?"Sent \u2014 the agent is revising it":"Rejected and cleaned up"),n("")}catch(g){V(g.message,5e3)}finally{r("")}}},c=t.artifacts.some(f=>f.stat?.trim()),u=t.status==="running",p=t.source?.kind==="pr"&&!t.source.isCrossRepository?t.source:void 0;return e("div",{class:"triage",children:[e("input",{class:"field",placeholder:"What should change? (for Revise)",value:s,onInput:f=>n(f.currentTarget.value),disabled:u}),s.trim()?e("details",{class:"followup-budget",children:[e("summary",{children:["Revision budget \xB7 ",o," calls \xB7 ",d," min"]}),e("label",{children:["Maximum calls",e("input",{class:"field","aria-label":"Revision maximum calls",type:"number",min:1,max:200,value:o,onInput:f=>i(Number(f.currentTarget.value))})]}),e("label",{children:["Maximum minutes",e("input",{class:"field","aria-label":"Revision maximum minutes",type:"number",min:1,max:720,value:d,onInput:f=>l(Number(f.currentTarget.value))})]})]}):null,e("button",{class:"btn small",disabled:u||!!a||!s.trim(),onClick:()=>m("revise"),children:a==="revise"?"Sending\u2026":"Revise"}),e("button",{class:"btn small primary",disabled:u||!!a,onClick:()=>m("approve"),children:"\u2713 Approve"}),c&&p?e("button",{class:"btn small",disabled:u||!!a,title:`Approve and push the fix to ${p.headRefName}, updating PR #${p.number} (never forced)`,onClick:()=>m("approve",{pushPr:!0}),children:a==="approve"?"\u2026":`Approve & push to PR #${p.number}`}):c?e("button",{class:"btn small",disabled:u||!!a,title:"Approve, push the branch and open a pull request into the base branch",onClick:()=>m("approve",{openPr:!0}),children:a==="approve"?"\u2026":"Approve & open PR"}):null,e("button",{class:"btn small danger",disabled:u||!!a,onClick:()=>m("reject"),children:"Reject"})]})}function hf({a:t,scoped:s}){let[n,a]=h(!1),[r,o]=h(!1),i=t.lastRunId?Ne.value.get(t.lastRunId):void 0,d=Bu(Ii(t.run),t.run.repo,s),l=c=>q(`/api/automations/${t.id}`,c).then(ca,u=>V(u.message,5e3)),m=`${location.origin}${t.hookPath}`;return t.target?e("div",{class:"auto-row",children:[e("b",{children:t.name}),e("p",{class:"help",children:["Project mission \xB7 ",t.enabled?"active":"paused"," \xB7 ",t.scheduleText]}),e("button",{class:"btn small",onClick:()=>{let c=t.run.project;c&&(Z.value={view:"project",id:c})},children:"Mission, cycles and opportunities"})]}):e("div",{class:`auto-row ${t.enabled?"":"off"}`,children:[e("div",{class:"ar-head",children:[e("label",{class:"switch",title:t.enabled?"Turn off":"Turn on",children:e("input",{type:"checkbox",role:"switch","aria-label":`${t.name}: on`,checked:t.enabled,onChange:c=>l({enabled:c.currentTarget.checked})})}),e("b",{children:t.name}),e("span",{class:"help",children:[t.sweep?`Sweep: up to ${t.sweep.max} new ${t.sweep.kind==="issues"?"issues":t.sweep.kind==="dependabot"?"Dependabot PRs":"alerts"} \xB7 `:"",t.scheduleText,t.webhook?" \xB7 webhook":"",t.isolate?` \xB7 checks in ${t.image||"node:22"}`:""]}),e("span",{class:"spacer"}),e("button",{class:"btn small","aria-expanded":r,onClick:()=>o(!r),children:"Preview and events"}),e("button",{class:"btn small",onClick:()=>q(`/api/automations/${t.id}/run`).then(({id:c,ids:u})=>{ca(),u&&u.length!==1?V(`Started ${u.length} runs \u2014 their results will wait in the inbox`):c&&(Z.value={view:"run",id:c})},c=>V(c.message,5e3)),children:"Run now"}),t.webhook?e("button",{class:"btn small","aria-pressed":n,onClick:()=>a(!n),children:"Webhook"}):null,e("button",{class:"btn small danger",onClick:async()=>await Ce(`Delete \u201C${t.name}\u201D? Its past runs are kept.`,{title:"Delete automation?",confirmLabel:"Delete automation",danger:!0})&&U(`/api/automations/${t.id}`,{method:"DELETE"}).then(ca,c=>V(c.message)),children:"Delete"})]}),e("div",{class:"ar-meta help",children:[ve.value.find(c=>c.id===t.run.pattern)?.name??t.run.pattern," in ",be(t.run.repo),d?e(j,{children:[" \xB7 ",e(z,{name:"project",class:"inline-icon"})," ",d.name]}):null,": \u201C",t.run.task.split(`
128
+ `)[0],"\u201D",t.sweep&&t.handled?.length?` \xB7 ${t.handled.length} handled so far`:"",Object.values(t.run.roles).flat().filter((c,u,p)=>p.indexOf(c)===u).map(c=>c==="auto"?e("span",{children:" \xB7 Auto"},c):e("span",{children:[" \xB7 ",e($e,{id:c})]},c))]}),e("div",{class:"ar-meta help",children:[t.enabled&&t.nextAt?`Next: ${new Date(t.nextAt).toLocaleString([],{weekday:"short",hour:"2-digit",minute:"2-digit"})}`:t.enabled?"Runs when triggered":"Off",t.lastFiredAt?e(j,{children:[" \xB7 Last: ",i?e("a",{href:`#/run/${i.id}`,children:[Wt(t.lastFiredAt)," (",i.triage?.state==="empty"?"no changes":ot[i.status]??i.status,")"]}):Wt(t.lastFiredAt)]}):null,t.queued?.length?` \xB7 ${t.queued.length} webhook event${t.queued.length===1?"":"s"} waiting for the run to end`:null,t.lastError?e("span",{class:"msg err inline",children:[" \xB7 couldn't start: ",t.lastError]}):null]}),e(br,{automation:t,save:l}),r?e(ff,{automation:t}):null,n?e("div",{class:"hook",children:[e("div",{children:[e("span",{class:"lbl",children:"URL"})," ",e("code",{children:m})]}),e("div",{children:[e("span",{class:"lbl",children:"Secret"})," ",e("code",{children:[t.token.slice(0,6),"\u2026"]})," ",e("button",{class:"btn small",onClick:()=>Ot(t.token,"Secret copied"),children:"Copy"}),e("button",{class:"btn small",onClick:async()=>await Ce("Make a new secret? The old one stops working.",{title:"Replace webhook secret?",confirmLabel:"Replace secret",danger:!0})&&l({rotateToken:!0}),children:"New secret"})]}),e("pre",{children:`curl -X POST ${m} \\
129
+ -H "Authorization: Bearer <secret>" \\
130
+ -H "Content-Type: application/json" \\
131
+ -d '{"details": "what happened", "source": {"kind": "pr", "number": 12}}'`}),e("div",{class:"help",children:["For a GitHub webhook, use this URL through a tunnel, content type ",e("code",{children:"application/json"}),", and the secret above. Opened issues and pull requests, and failed workflow runs (with their logs), start a run; other events are ignored."]})]}):null]})}function ff({automation:t}){let[s,n]=h([]),[a,r]=h(null),[o,i]=h(""),[d,l]=h(""),m=()=>U(`/api/automations/${t.id}/events`).then(n),c=()=>q(`/api/automations/${t.id}/preview`,{via:"manual"}).then(r);_(()=>{let p=!0;q(`/api/automations/${t.id}/preview`,{via:"manual"}).then(g=>{p&&(r(g),i(""))},g=>{p&&i(g.message)});let v=Je(()=>U(`/api/automations/${t.id}/events`).then(g=>{p&&n(g)},()=>{}),15e3);return()=>{p=!1,v()}},[t.id]);let u=async p=>{l(p.id);try{await q(`/api/automations/${t.id}/events/${p.id}/retry`),await Promise.all([m(),ca()]),V("Event retry requested")}catch(f){i(f.message)}finally{l("")}};return e("section",{class:"hook automation-inspector","aria-label":`Preview and events for ${t.name}`,children:[e("b",{children:"Dry run"}),e("p",{class:"help",children:"Preview current selections and settings before running."}),a?e(j,{children:[e("p",{children:[a.ready?"Ready to start":"Cannot start immediately",a.busy?` \xB7 ${a.busy}`:"",a.wouldQueue?" \xB7 event would wait in the queue":""]}),e("p",{class:"help",children:["Permissions: ",a.permissions.trust," \xB7 ",a.permissions.isolate?`commands in ${a.permissions.image}`:"commands on this machine"," \xB7 ",a.limits.maxInvocations??a.limits.maxSteps??"default"," calls \xB7 ",a.limits.maxMinutes??"default"," minutes \xB7 webhooks ",a.limits.startsUsed,"/",a.limits.startsPerHour," this hour"]}),a.commands.setup?e("div",{class:"help",children:["Setup: ",e("code",{children:a.commands.setup})]}):null,a.commands.check?e("div",{class:"help",children:["Check: ",e("code",{children:a.commands.check})]}):null,a.warnings.map(p=>e("p",{class:"msg warn",children:p},p)),a.selected.length?e("ul",{children:a.selected.map(p=>e("li",{children:[e("b",{children:p.key}),": ",p.task.split(`
132
+ `)[0]]},p.key))}):e("p",{class:"help",children:"No work selected."}),a.skipped.length?e("details",{children:[e("summary",{children:[a.skipped.length," items outside this run"]}),e("ul",{children:a.skipped.map(p=>e("li",{children:[p.key,": ",p.reason]},p.key))})]}):null,e("button",{class:"btn small",onClick:()=>c().catch(p=>i(p.message)),children:"Refresh preview"})]}):e("p",{class:"help",children:"Loading preview\u2026"}),e("p",{children:e("b",{children:"Event history"})}),e("p",{class:"help",children:"Keeps the latest 100 events, including queued, deduplicated, failed and dropped deliveries. Retrying uses the original validated event and current limits."}),s.length?e("div",{class:"table-wrap",children:e("table",{class:"ins-table",children:[e("thead",{children:e("tr",{children:[e("th",{children:"Received"}),e("th",{children:"Origin"}),e("th",{children:"State"}),e("th",{children:"Details"}),e("th",{children:"Action"})]})}),e("tbody",{children:s.map(p=>e("tr",{children:[e("td",{children:new Date(p.at).toLocaleString()}),e("td",{children:p.via}),e("td",{children:[p.state,p.retries?` (${p.retries} ${p.retries===1?"retry":"retries"})`:""]}),e("td",{children:[p.input.source?`${p.input.source.kind} #${p.input.source.number}`:p.input.details?.slice(0,160)||"Saved task",p.reason?e("div",{class:"help",children:p.reason}):null,p.runIds?.map(f=>e("a",{href:`#/run/${f}`,children:"Open run "},f))]}),e("td",{children:p.state==="failed"||p.state==="dropped"?e("button",{class:"btn small",disabled:!t.enabled||!!d,onClick:()=>u(p),children:d===p.id?"Retrying\u2026":"Retry event"}):"\u2013"})]},p.id))})]})}):e("p",{class:"help",children:"No events recorded yet."}),o?e("p",{class:"msg err",role:"alert",children:o}):null]})}function qu({body:t,onClose:s}){let n=we(!0,s),[a,r]=h(String(t.task??"").split(`
133
+ `)[0].slice(0,50)),[o,i]=h("daily"),[d,l]=h(60),[m,c]=h("07:00"),[u,p]=h($i()),[f,v]=h([1,2,3,4,5]),[g,w]=h(!1),[C,k]=h(!1),[y,b]=h("node:22"),[T,$]=h(""),[x,E]=h(!1),A=async()=>{E(!0),$("");try{let{attachments:P,approvals:D,branchPrefix:S,...R}=t;R.context={paths:t.context?.paths??[]};let M=await q("/api/automations",{name:a,run:R,schedule:o==="every"?{every:d}:o==="daily"?{at:m,days:f,timezone:u}:void 0,webhook:o==="webhook"||g,isolate:C,image:y});await ca(),V("Automation saved"),s();let O=Ii(M.run);Ye.value!==qs&&O&&O.id!==Ye.value&&va(O.id,{defaults:!1,repo:!1}),Z.value={view:"automations"}}catch(P){$(P.message)}finally{E(!1)}};return e("dialog",{class:"picker small-dialog save-auto",ref:n,"aria-labelledby":"save-automation-title",children:e("div",{class:"picker-inner",children:[e("div",{class:"picker-head",children:[e("h3",{id:"save-automation-title",children:"Save as automation"}),e("div",{class:"help",children:"Runs this task with this team and these settings, unattended. Results wait in your inbox; nothing merges by itself."})]}),e("div",{class:"dialog-body",children:[e("div",{class:"fg",children:[e("label",{class:"lbl",for:"auto-name",children:"Name"}),e("input",{id:"auto-name",class:"field",value:a,onInput:P=>r(P.currentTarget.value)})]}),e("div",{class:"fg",children:[e("span",{class:"lbl",id:"auto-when",children:"When"}),e("div",{class:"segmented",role:"radiogroup","aria-labelledby":"auto-when",children:[["daily","At a time"],["every","Repeatedly"],["webhook","Only from a webhook"]].map(([P,D])=>e("button",{type:"button",role:"radio","aria-checked":o===P,class:o===P?"on":"",onClick:()=>i(P),children:D},P))}),o==="daily"?e("div",{class:"row-inline",children:[e("input",{class:"field inline",type:"time","aria-label":"Time of day",value:m,onInput:P=>c(P.currentTarget.value)}),e("span",{class:"days",role:"group","aria-label":"Days",children:pf.map((P,D)=>e("button",{type:"button",class:"day","aria-pressed":f.includes(D),onClick:()=>v(f.includes(D)?f.filter(S=>S!==D):[...f,D].sort()),children:P},P))})]}):o==="every"?e("div",{class:"row-inline",children:["Every ",e("input",{class:"field inline num",type:"number",min:5,"aria-label":"Minutes between runs",value:d,onInput:P=>l(Number(P.currentTarget.value)||60)})," minutes"]}):null,o==="daily"?e("label",{class:"lbl tz",children:["Time zone",e("input",{class:"field","aria-label":"Automation time zone",placeholder:"Europe/Stockholm",value:u,onInput:P=>p(P.currentTarget.value)})]}):null,o!=="webhook"?e(vr,{schedule:o==="every"?{every:d}:{at:m,days:f,timezone:u}}):null]}),e("div",{class:"fg checks",children:[o!=="webhook"?e("label",{class:"check",children:[e("input",{type:"checkbox",checked:g,onChange:P=>w(P.currentTarget.checked)})," Also start it from a webhook"]}):null,e("label",{class:"check",children:[e("input",{type:"checkbox",checked:C,onChange:P=>k(P.currentTarget.checked)})," Run checks and setup in a Docker container"]}),C?e("div",{class:"row-inline image",children:["Image ",e("input",{class:"field inline mono","aria-label":"Docker image",value:y,onInput:P=>b(P.currentTarget.value)}),e("span",{class:"help",children:"Only the worktree is mounted; none of your environment or home folder."})]}):null]}),T?e("div",{class:"msg err",children:T}):null]}),e("div",{class:"picker-foot",children:[e("span",{class:"ps"}),e("button",{class:"btn",onClick:s,children:"Cancel"}),e("button",{class:"btn primary",disabled:x||!a.trim()||o==="daily"&&!f.length,onClick:A,children:x?"Saving\u2026":"Save automation"})]})]})})}var Uu={queued:"Queued","waiting-time":"Waiting for start time","waiting-provider":"Waiting for provider capacity",claimed:"Starting",started:"Run started",failed:"Start rejected",unknown:"Launch outcome unknown",cancelled:"Cancelled"},Ei=new Set(["queued","waiting-time","waiting-provider","claimed","unknown"]),Ai=t=>new Date(t).toLocaleString(),gf=t=>{let s=new Date(t);return new Date(t-s.getTimezoneOffset()*6e4).toISOString().slice(0,16)};function ro({runRequest:t,project:s,repo:n,unassigned:a=!1}){let[r,o]=h([]),[i,d]=h(""),[l,m]=h(""),[c,u]=h("ready"),[p,f]=h(gf(Date.now()+60*6e4)),[v,g]=h([]),[w,C]=h(!1),[k,y]=h(0),b=Q(),T=async E=>{let A=await U("/api/deferred-runs",E?{signal:E}:void 0);o(A),d("")};_(()=>{let E=!0,A=!1,P=new AbortController,S=Je(async()=>{if(!A){A=!0;try{let R=await U("/api/deferred-runs",{signal:P.signal});E&&(o(R),d(""))}catch(R){E&&d(R.message)}finally{A=!1}}},5e3);return()=>{E=!1,P.abort(),S()}},[k]);let $=async()=>{if(!t||w)return;let E=c==="at"?new Date(p).getTime():void 0;if(c==="at"&&(!Number.isFinite(E)||E<=Date.now())){d("Choose a future local start time.");return}let A={name:l.trim()||void 0,run:t,notBefore:E,waitForProviders:v},P=JSON.stringify(A);b.current?.key!==P&&(b.current={key:P,id:crypto.randomUUID()}),C(!0),d("");try{await q("/api/deferred-runs",{...A,operationId:b.current.id}),b.current=void 0,V("Deferred run saved. It starts when this application is open and its conditions are ready."),await T()}catch(D){d(D.message)}finally{C(!1)}},x=r.filter(E=>(!s||E.run.project===s)&&(!a||!E.run.project)&&(!n||E.run.repo===n));return e("section",{class:"section deferred-runs","aria-label":"Deferred runs",children:[e("div",{class:"section-title",children:["Deferred runs ",e("span",{class:"count",children:x.filter(E=>Ei.has(E.status)).length})]}),e("p",{class:"help",children:"Save a run for later, or wait for provider capacity. The queue survives restarts and runs while this application is open. Provider reset times come from reported usage; unknown reset times are rechecked."}),t?e("details",{children:[e("summary",{children:"Queue this run configuration"}),e("p",{class:"help",children:"Deferred runs use Safe mode, suppress copied ignored files and disable approval waits. Files and source references are revalidated when launching; attachments cannot be deferred."}),e("p",{class:"help",children:"Task and command text is saved locally with this request. Reference environment variable names for credentials instead of putting their values in commands."}),e("div",{class:"wb-fields",children:[e("label",{children:["Queue label (optional)",e("input",{class:"field",maxLength:120,"aria-label":"Deferred run label",value:l,onInput:E=>m(E.currentTarget.value)})]}),e("label",{children:["Start condition",e("select",{class:"field","aria-label":"Deferred start condition",value:c,onChange:E=>u(E.currentTarget.value),children:[e("option",{value:"ready",children:"As soon as conditions are ready"}),e("option",{value:"at",children:"At or after a chosen time"})]})]}),c==="at"?e("label",{children:["Earliest start \xB7 local time",e("input",{class:"field",type:"datetime-local","aria-label":"Deferred earliest start",value:p,onInput:E=>f(E.currentTarget.value)})]}):null]}),e("fieldset",{class:"deferred-providers",children:[e("legend",{children:"Wait for selected providers to have capacity"}),["claude","codex","agy"].map(E=>e("label",{children:[e("input",{type:"checkbox",checked:v.includes(E),onChange:A=>g(P=>A.currentTarget.checked?[...P,E]:P.filter(D=>D!==E))})," ",E==="agy"?"Antigravity":E==="claude"?"Claude":"Codex"]},E))]}),e("details",{children:[e("summary",{children:"Review saved run request"}),e("pre",{children:JSON.stringify(t,null,2)})]}),e("div",{class:"wb-actions",children:e("button",{class:"btn primary",disabled:w,onClick:$,children:w?"Saving\u2026":"Save deferred run"})})]}):null,e("div",{class:"wb-actions",children:e("button",{class:"btn small",onClick:()=>y(E=>E+1),children:"Refresh queue"})}),i?e("p",{class:"msg err",role:"alert",children:i}):null,x.length?e("div",{class:"wb-list",children:x.map(E=>e(vf,{job:E,refresh:T},E.id))}):e("p",{class:"help",children:"No deferred runs in this scope."})]})}function vf({job:t,refresh:s}){let[n,a]=h(!1),[r,o]=h(""),[i,d]=h(""),[l,m]=h(!1),c=async(u,p={})=>{a(!0),o("");try{await q(`/api/deferred-runs/${encodeURIComponent(t.id)}/${u}`,{expectedRevision:t.revision,...p}),await s()}catch(f){o(f.message)}finally{a(!1)}};return e("article",{class:"wb-item deferred-run","aria-label":`Deferred run ${t.name}`,children:[e("div",{class:"wb-item-head",children:[e("b",{children:t.name}),e("span",{class:`badge ${t.status==="started"?"ok":t.status==="failed"?"err":t.status==="unknown"||t.status==="waiting-provider"?"warn":t.status==="claimed"?"run":""}`,children:Uu[t.status]})]}),e("p",{class:"help",children:[t.run.pattern," \xB7 ",t.run.repo," \xB7 earliest ",Ai(t.notBefore)," \xB7 launch attempts ",t.attempts,"/",t.maxAttempts]}),t.waitForProviders.length?e("p",{class:"help",children:["Provider conditions: ",t.waitForProviders.join(", "),t.nextCheckAt?` \xB7 check again at ${Ai(t.nextCheckAt)}`:""]}):null,t.reason?e("p",{class:"help",children:t.reason}):null,t.runId||Ei.has(t.status)||t.status==="failed"&&t.attempts<t.maxAttempts?e("div",{class:"wb-actions",children:[t.runId?e("a",{class:"btn small",href:`#/run/${encodeURIComponent(t.runId)}`,children:["Open run ",t.runId]}):null,Ei.has(t.status)?e("button",{class:"btn small",disabled:n,onClick:()=>c("cancel"),children:t.status==="unknown"?"Cancel queue recovery":t.status==="claimed"?"Request launch cancellation":"Cancel deferred run"}):null,t.status==="failed"&&t.attempts<t.maxAttempts?e("button",{class:"btn small",disabled:n,onClick:()=>c("retry"),children:"Retry after reviewing the failure"}):null]}):null,t.status==="unknown"?e("div",{class:"deferred-recovery","aria-label":"Recover unknown deferred launch",children:[e("p",{class:"help",children:"A run may have started before its receipt was saved. Inspect existing runs and the claim below before linking one or retrying. Cancelling queue recovery does not stop an unknown existing run."}),e("p",{class:"help",children:["Job ",e("code",{children:t.id})," \xB7 launch claim ",e("code",{children:t.claimId})]}),e("div",{class:"wb-row",children:[e("label",{children:["Existing run ID",e("input",{class:"field","aria-label":`Existing run for ${t.id}`,maxLength:240,value:i,onInput:u=>d(u.currentTarget.value)})]}),e("button",{class:"btn small",disabled:n||!i.trim(),onClick:()=>c("attach",{runId:i.trim()}),children:"Link matching existing run"})]}),t.attempts<t.maxAttempts?e("div",{class:"wb-row",children:[e("label",{children:[e("input",{type:"checkbox",checked:l,onChange:u=>m(u.currentTarget.checked)})," I inspected existing runs and understand that another attempt can duplicate work."]}),e("button",{class:"btn small",disabled:n||!l,onClick:()=>c("retry",{acknowledgeUnknown:!0}),children:"Retry unknown launch"})]}):null]}):null,e("details",{children:[e("summary",{children:"Saved request and launch history"}),e("pre",{children:JSON.stringify(t.run,null,2)}),e("ol",{class:"help",children:t.history.map(u=>e("li",{children:[Ai(u.at)," \xB7 ",Uu[u.status]," \xB7 ",u.detail,u.claimId?e(j,{children:[" \xB7 claim ",e("code",{children:u.claimId})]}):null,u.runId?e(j,{children:[" \xB7 ",e("a",{href:`#/run/${encodeURIComponent(u.runId)}`,children:u.runId})]}):null]},u.id))})]}),r?e("p",{class:"msg err",role:"alert",children:r}):null]})}var Da=[{id:"once",label:"Run once later",description:"Start a task at a chosen time or when its providers have capacity."},{id:"repeat",label:"Repeat",description:"Run a configured task on a schedule or from a webhook."},{id:"backlog",label:"Process a backlog",description:"Choose issues, dependency updates or security alerts, with one run per item."},{id:"missions",label:"Pursue a mission",description:"Give agents an ongoing goal and review their proposals and verified drafts."}];function Ar({kind:t="repeat",projectId:s}){let n=Da.find(m=>m.id===t)??Da[1],a=s?fe.value.find(m=>m.id===s):Dn.value,[r,o]=h(""),i=a?.repos.includes(r)?r:a?.repos.length===1?a.repos[0]:"",d=s??a?.id,l=()=>st(d??(Ye.value===Bt?"":void 0),i?{repository:i}:{});return s&&!a?e("p",{role:"alert",children:"This project is unavailable. Choose an existing project to manage automation."}):e("div",{class:"scheduling-hub",children:[e("nav",{class:"purpose-nav","aria-label":"Scheduling purpose",children:Da.map(m=>e("a",{class:`btn ${n.id===m.id?"primary":""}`,href:Ps(s?{view:"project",id:s,section:"automation",kind:m.id}:{view:"automations",kind:m.id}),"aria-current":n.id===m.id?"page":void 0,children:m.label}))}),e("p",{children:n.description}),e("p",{class:"help",children:[a?`${a.name} \xB7 `:"Across projects \xB7 ","Computer: ",Qt(),". The host must be running. Results return to the Inbox for review."]}),s?null:e(Ks,{}),a&&n.id!=="missions"?e("label",{children:["Automation repository",e("select",{class:"field",value:i,onChange:m=>o(m.currentTarget.value),children:[e("option",{value:"",disabled:!0,children:"Choose a repository"}),a.repos.map(m=>e("option",{value:m,children:m},m))]})]}):null,n.id==="once"?e(j,{children:[e("p",{class:"help",children:"Configure a task in New run, then choose Schedule \u2192 Run once later."}),e("button",{class:"btn",disabled:!qt.value||dt.value||!!a&&!i,onClick:()=>void l(),children:"Configure a task"}),e(ro,{project:d,unassigned:!s&&Ye.value===Bt})]}):null,n.id==="repeat"?e(j,{children:[e("button",{class:"btn",disabled:!qt.value||dt.value||!!a&&!i,onClick:()=>void l(),children:"Configure a repeating task"}),e(Sa,{mode:"automations",category:"repeat",projectId:s,showScope:!1})]}):null,n.id==="backlog"?e(j,{children:[a&&i?e(j,{children:[e("p",{class:"help",children:["Next backlog: ",a.name," \xB7 ",e("code",{children:i}),". Uses this project's saved agent workflow."]}),e(Qr,{only:"backlog",disabled:!qt.value||dt.value,prepare:()=>st(a.id,{repository:i,stay:!0})})]}):e("p",{class:"help",children:"Choose a project and repository here to select backlog items."}),e(Sa,{mode:"automations",category:"backlog",projectId:s,showScope:!1})]}):null,n.id==="missions"?e(j,{children:a?e(Bl,{projectId:a.id,repos:a.repos},a.id):e("p",{class:"help",children:"Choose a project to create or manage its missions."})}):null]})}var Fu=["claude","codex","agy"],Hu={auto:"Auto",claude:"Claude Code",codex:"Codex",agy:"Antigravity"};function K0(t,s){return t==="claude"?{model:s==="quick"?"haiku":"sonnet",effort:s==="quick"?void 0:"low"}:{effort:"low"}}function G0(t,s,n){return t==="claude"&&/haiku/i.test(s??"")?[]:n?.models.find(a=>a.id===(s||n.defaultModel))?.efforts??n?.efforts??[]}function Pi(t){let s=t;if(!s||typeof s!="object"||Array.isArray(s))throw new Error("Invalid prompt improvement settings");if(s.agent!=="auto"&&!Fu.includes(s.agent))throw new Error("Choose Auto, Claude Code, Codex or Antigravity for prompt improvement");if(s.defaultMode!=="quick"&&s.defaultMode!=="repo")throw new Error("Choose Quick or Repo as the default improvement mode");let n={};if(s.providers!==void 0&&(!s.providers||typeof s.providers!="object"||Array.isArray(s.providers)))throw new Error("Invalid prompt improvement provider settings");for(let a of Fu)for(let r of["quick","repo"]){let o=s.providers?.[a]?.[r];if(o===void 0)continue;if(!o||typeof o!="object"||Array.isArray(o))throw new Error("Invalid prompt improvement model settings");let i={};for(let d of["model","effort"]){let l=o[d];if(l!==void 0){if(typeof l!="string"||l.length>200||/[\x00-\x1f\x7f]/.test(l))throw new Error(`Invalid prompt improvement ${d}`);i[d]=l.trim()}}(n[a]??={})[r]=i}return{agent:s.agent,defaultMode:s.defaultMode,providers:n}}function bf(){try{let t=de.get("improveSettings");if(t)return Pi(JSON.parse(t))}catch{}return{agent:"auto",defaultMode:de.get("improveMode")==="repo"?"repo":"quick",providers:{}}}var As=ke(bf());function eR(t){As.value=Pi(t),de.set("improveSettings",JSON.stringify(As.value))}var Ft=t=>!!t&&typeof t=="object"&&!Array.isArray(t),Wu=t=>typeof t=="string"&&/^[a-zA-Z0-9_-]{1,100}$/.test(t),ls=(t,s)=>typeof t=="string"&&t.length<=s,zu=t=>typeof t=="string"&&(["claude","codex","agy"].includes(t)||/^acp:[a-z][a-z0-9-]{0,40}$/.test(t)||/^plugin:[a-z][a-z0-9-]{0,40}\/[a-z][a-z0-9-]{0,40}$/.test(t)),Tn=(t,s,n)=>typeof t=="number"&&Number.isInteger(t)&&t>=s&&t<=n,He=t=>{throw new Error(t)};function Vu(t){if(!Ft(t))return He("Model settings must be an object.");let s={};for(let[n,a]of Object.entries(t)){if(!zu(n)||!Ft(a)||a.model!==void 0&&!ls(a.model,256)||a.effort!==void 0&&!ls(a.effort,64))return He("A preset contains invalid provider model settings.");if(a.variants!==void 0&&(!Array.isArray(a.variants)||a.variants.length>128||a.variants.some(r=>!Ft(r)||!ls(r.model,256)||!r.model.trim()||r.effort!==void 0&&!ls(r.effort,64))))return He("Invalid model variants.");s[n]={...a.model!==void 0?{model:a.model}:{},...a.effort!==void 0?{effort:a.effort}:{},...Array.isArray(a.variants)?{variants:a.variants.map(r=>({model:r.model,...r.effort!==void 0?{effort:r.effort}:{}}))}:{}}}return s}function ji(t,s){if(!Ft(t))return He("A preset is missing its configuration.");let n=s.find(l=>l.id===t.pattern);if(!n)return He(`Unknown workflow: ${String(t.pattern)}.`);if(!Ft(t.roles)||!Ft(t.options)||!Ft(t.roleSettings))return He("A preset must contain roles, options and role settings.");let a={};for(let[l,m]of Object.entries(t.roles)){let c=n.roles.find(u=>u.id===l);if(!c||!Array.isArray(m)||m.length>(c.multiple?4:1)||m.some(u=>u!=="auto"&&!zu(u))||new Set(m).size!==m.length)return He(`Invalid assignments for role ${l}.`);a[l]=[...m]}for(let l of n.roles)if(!l.optional&&!a[l.id]?.length)return He(`A preset needs an assignment for ${l.label}.`);let r={};for(let[l,m]of Object.entries(t.options)){let c=n.options.find(u=>u.id===l);if(!c||(c.type==="boolean"?typeof m!="boolean":typeof m!="number"||!Number.isFinite(m)||m<(c.min??0)||m>(c.max??1e4)))return He(`Invalid workflow option ${l}.`);r[l]=m}let o={};for(let[l,m]of Object.entries(t.roleSettings)){if(!n.roles.some(c=>c.id===l))return He(`Unknown role settings: ${l}.`);o[l]=Vu(m)}if(!["safe","standard","trusted","full"].includes(String(t.trust))||typeof t.approvePlan!="boolean"||!Ft(t.limits)||!Tn(t.limits.maxMinutes,1,720)||!Tn(t.limits.maxSteps,1,200))return He("Invalid permissions, approval choice or execution limits.");if(t.limits.maxTokens!==void 0&&!Tn(t.limits.maxTokens,1,1e9)||t.limits.maxCostUsd!==void 0&&(typeof t.limits.maxCostUsd!="number"||!Number.isFinite(t.limits.maxCostUsd)||t.limits.maxCostUsd<=0||t.limits.maxCostUsd>1e6)||t.toolApprovals!==void 0&&typeof t.toolApprovals!="boolean")return He("Invalid reported usage ceilings or tool approval preference.");for(let l of["check","setup","baseRef"])if(t[l]!==void 0&&!ls(t[l],1e4))return He(`Invalid ${l} setting.`);let i=Object.fromEntries(["check","setup","baseRef"].filter(l=>t[l]!==void 0).map(l=>[l,t[l]])),d=Qi(t.contextBudget);return{...i,pattern:n.id,roles:a,options:r,agentSettings:Vu(t.agentSettings),roleSettings:o,trust:t.trust,limits:{maxMinutes:t.limits.maxMinutes,maxSteps:t.limits.maxSteps,...t.limits.maxTokens!==void 0?{maxTokens:t.limits.maxTokens}:{},...t.limits.maxCostUsd!==void 0?{maxCostUsd:t.limits.maxCostUsd}:{}},approvePlan:t.approvePlan,...t.toolApprovals!==void 0?{toolApprovals:t.toolApprovals}:{},...d?{contextBudget:d}:{}}}function da(t){return[...new Set([...[t.task,...t.criteria].join(`
134
+ `).matchAll(/\{\{([a-zA-Z][a-zA-Z0-9_]{0,39})\}\}/g)].map(s=>s[1]))]}function oo(t,s){for(let a of da(t))if(!s[a]?.trim())return He(`Enter a value for ${a}.`);let n=a=>a.replace(/\{\{([a-zA-Z][a-zA-Z0-9_]{0,39})\}\}/g,(r,o)=>s[o].trim());return{task:n(t.task),criteria:t.criteria.map(n)}}function Es(t,s){if(!Ft(t)||t.schemaVersion!==1||!Array.isArray(t.presets)||!Array.isArray(t.templates)||t.presets.length>100||t.templates.length>100)return He("Expected a version 1 code-flow library with at most 100 presets and 100 templates.");let n=t.presets.map(r=>{if(!Ft(r)||!Wu(r.id)||!ls(r.name,80)||!r.name.trim()||!Tn(r.revision,1,1e6)||!Tn(r.updatedAt,0,Number.MAX_SAFE_INTEGER)||!Array.isArray(r.history)||r.history.length>10)return He("Invalid team preset metadata.");let o=r.history.map(i=>!Ft(i)||!Tn(i.revision,1,r.revision-1)||!Tn(i.updatedAt,0,Number.MAX_SAFE_INTEGER)?He("Invalid preset revision history."):{revision:i.revision,updatedAt:i.updatedAt,config:ji(i.config,s)});return new Set(o.map(i=>i.revision)).size!==o.length?He("Duplicate preset revision."):{id:r.id,name:r.name.trim(),revision:r.revision,updatedAt:r.updatedAt,config:ji(r.config,s),history:o}}),a=t.templates.map(r=>{if(!Ft(r)||!Wu(r.id)||!ls(r.name,80)||!r.name.trim()||!s.some(l=>l.id===r.pattern)||!ls(r.task,1e5)||!r.task.trim()||!Array.isArray(r.criteria)||r.criteria.length>100||r.criteria.some(l=>!ls(l,2e3)))return He("Invalid task template.");if(r.intent!==void 0&&!["bug","feature","review","explore"].includes(String(r.intent)))return He("Invalid template task intent.");let o={...r.intent?{intent:r.intent}:{},id:r.id,name:r.name.trim(),pattern:r.pattern,task:r.task,criteria:r.criteria};if(da(o).length>24)return He("A template can have at most 24 parameters.");let i=r.config===void 0?void 0:ji(r.config,s);if(i&&i.pattern!==o.pattern)return He("Template workflow and agent configuration must match.");let d;if(r.runOptions!==void 0){let l=r.runOptions;if(!Ft(l)||!["","lightweight","standard","thorough"].includes(String(l.verification))||!Ft(l.container)||typeof l.container.enabled!="boolean"||!ls(l.container.image,500)||!ls(l.container.authVolume,500))return He("Invalid template execution settings.");d={verification:l.verification,container:{enabled:l.container.enabled,image:l.container.image,authVolume:l.container.authVolume}}}return{...o,...i?{config:i}:{},...d?{runOptions:d}:{}}});return new Set(n.map(r=>r.id)).size!==n.length||new Set(a.map(r=>r.id)).size!==a.length?He("Duplicate library identifiers."):{schemaVersion:1,presets:n,templates:a}}function Na(t,s){let n=s.map(a=>a.trim()).filter(Boolean);return n.length?`${t.trim()}
135
+
136
+ Acceptance criteria:
137
+ ${n.map((a,r)=>`${r+1}. ${a}`).join(`
138
+ `)}`:t}function Ju(){let t=es.value,[s,n]=h(""),a=r=>{try{En(r),n("")}catch(o){n(o.message)}};return e("fieldset",{class:"context-budget",children:[e("legend",{children:"Invocation context budget"}),e("label",{class:"check",children:[e("input",{type:"checkbox",checked:!!t,onChange:r=>a(r.currentTarget.checked?{maxPromptBytes:65536,policy:"warn"}:void 0)}),"Set an explicit input budget for each provider launch"]}),e("p",{class:"help",children:"Measured immediately before dispatch from the assembled prompt and JSON schema. Earlier CLI conversations, provider system instructions, file reads and image tokens are excluded. Reference file sizes below are separate estimates."}),t?e(j,{children:[e("label",{class:"lbl",for:"context-max-bytes",children:"Maximum explicit input bytes"}),e("input",{class:"field",id:"context-max-bytes",type:"number",min:1,max:67108864,value:t.maxPromptBytes??"",placeholder:"No byte ceiling",onInput:r=>a({...t,maxPromptBytes:r.currentTarget.value?Number(r.currentTarget.value):void 0})}),e("label",{class:"lbl",for:"context-max-tokens",children:"Maximum approximate input tokens"}),e("input",{class:"field",id:"context-max-tokens",type:"number",min:1,max:16777216,value:t.maxApproximateTokens??"",placeholder:"No estimated token ceiling",onInput:r=>a({...t,maxApproximateTokens:r.currentTarget.value?Number(r.currentTarget.value):void 0})}),e("label",{class:"lbl",for:"context-budget-policy",children:"When the explicit input exceeds this budget"}),e("select",{class:"field",id:"context-budget-policy",value:t.policy,onChange:r=>a({...t,policy:r.currentTarget.value}),children:[e("option",{value:"warn",children:"Record a warning and continue"}),e("option",{value:"block",children:"Block the provider launch"})]}),e("p",{class:"help",children:["Active budget: ",t.maxPromptBytes?`${t.maxPromptBytes.toLocaleString()} bytes`:"no byte ceiling"," \xB7 ",t.maxApproximateTokens?`${t.maxApproximateTokens.toLocaleString()} estimated tokens`:"no estimated token ceiling"," \xB7 ",t.policy,". Token ceilings are approximate guards, not a guarantee about a provider\u2019s context window."]})]}):null,s?e("p",{class:"msg err",role:"alert",children:s}):null]})}var Sn={schemaVersion:1,presets:[],templates:[]};function Di(){let t=Ss.value;return!t||t.some(s=>s.installed&&s.signedIn!==!1&&s.compatible!==!1)?null:e("div",{class:"banner provider-setup",role:"status",children:[e("p",{children:"Connect a provider to start a conversation or run a team."}),e("a",{class:"btn",href:"#/settings/agents",children:"Connect a provider"})]})}function Ku(){return e("details",{class:"settings acceptance-editor",children:[e("summary",{children:[e("span",{class:"st",children:"Acceptance criteria"}),e("span",{class:"ss",children:[Ts.value.filter(t=>t.trim()).length||"Optional"," \xB7 explicit requirements for the team"]})]}),e("div",{class:"settings-body",children:[e("label",{class:"lbl",for:"acceptance-criteria",children:"One requirement per line"}),e("textarea",{id:"acceptance-criteria",class:"field",rows:4,placeholder:`The new behavior has automated tests.
139
+ Existing API clients continue to work.`,value:Ts.value.join(`
140
+ `),onInput:t=>ps(t.currentTarget.value.split(`
141
+ `))}),e("p",{class:"help",children:"These requirements are included in the run's task and in saved automations. Review them before starting."})]})]})}function Gu({repository:t=ne.value,setup:s=Yt.value,check:n=jt.value,base:a=Fe.value,loading:r=cn.value,pattern:o,roles:i,providers:d}={}){let[l,m]=h(null),[c,u]=h(!1),[p,f]=h(""),[v,g]=h(!1),w=JSON.stringify([t,a,s,n,o,i,d]),C=Q(w);C.current=w;let k=Q(0);_(()=>{++k.current,u(!1),m(null),f(""),g(!1)},[w]);let y=async b=>{let T=++k.current,$=w;u(!0),f(""),m(null);try{let x=await q("/api/readiness",{repo:t,baseRef:a,setup:s,check:n,execute:b,pattern:o,roles:i,providers:d});if(T!==k.current||C.current!==$)return;m(x),g(b)}catch(x){T===k.current&&C.current===$&&f(x.message)}finally{T===k.current&&C.current===$&&u(!1)}};return e("details",{class:"settings readiness",children:[e("summary",{children:[e("span",{class:"st",children:"Repository readiness"}),e("span",{class:"ss",children:c?"Checking\u2026":l?`${v?"Commands validated":"Inspection complete"} \xB7 ${l.ok?"ready":"needs attention"}`:"Check the repository and provider setup"})]}),e("div",{class:"settings-body",children:[e("p",{class:"help",children:"Inspect readiness checks configuration and installed tools. Validate commands runs setup and checks in a temporary worktree; this executes repository code."}),e("div",{class:"onboarding-actions",children:[e("button",{class:"btn",disabled:!t||c||r,onClick:()=>y(!1),children:"Inspect readiness"}),e("button",{class:"btn",disabled:!t||c||r||!s.trim()&&!n.trim(),onClick:()=>y(!0),children:"Validate commands"})]}),c?e("p",{role:"status",children:"Checking repository readiness\u2026"}):null,p?e("p",{class:"msg err",role:"alert",children:p}):null,l?e("ul",{class:"readiness-results",children:l.items.map(b=>e("li",{children:[e("span",{class:`badge ${{passed:"ok",failed:"err",warning:"warn",skipped:""}[b.status]??""}`,children:b.status.charAt(0).toUpperCase()+b.status.slice(1)}),e("span",{children:[e("b",{children:b.label}),b.detail?e("span",{class:"help",children:b.detail}):null]})]},b.id))}):null]})]})}function Mi(t){return structuredClone({pattern:t.id,roles:ns(t),options:as(t),agentSettings:Ue.value,roleSettings:lt.value[t.id]??{},trust:Tt.value,limits:Se.value,approvePlan:hn(t.id),toolApprovals:de.get("interactiveApprovals")==="1",contextBudget:es.value,check:jt.value,setup:Yt.value,baseRef:Fe.value})}function Li(t,s){let n=ve.value.find(a=>a.id===t.pattern);if(!n)throw new Error("This workflow is no longer available.");bt(t.pattern);for(let a of n.roles)Lt(n.id,a.id,t.roles[a.id]??[]);for(let a of n.options)fn(n,a.id,t.options[a.id]??a.default);Ue.value={},de.set("agentSettings","{}"),lt.value={...lt.value,[n.id]:{}},de.set("roleModels",JSON.stringify(lt.value));for(let[a,r]of Object.entries(t.agentSettings))Vs(a,r);for(let[a,r]of Object.entries(t.roleSettings))for(let[o,i]of Object.entries(r))Mt(n.id,a,o,i);En(t.contextBudget,s),t.check!==void 0&&Qa(t.check),t.setup!==void 0&&Xa(t.setup),t.baseRef!==void 0&&(Fe.value=t.baseRef),On.value={...On.value,pattern:s,roles:s,models:s}}function kR({p:t,onToolApprovalsChange:s,libraryKey:n="composerLibrary"}){let[a]=h(()=>{try{return{library:Es(de.json(n,Sn),ve.value),error:""}}catch(D){return{library:structuredClone(Sn),error:`Saved library could not be loaded: ${D.message}. Import a valid backup to recover it.`}}}),[r,o]=h(a.library),i=Q(r);i.current=r;let[d,l]=h(a.error),[m,c]=h(""),[u,p]=h(""),[f,v]=h(""),[g,w]=h(""),[C,k]=h(""),[y,b]=h(null),T=Q(null),$=r.presets.find(D=>D.id===m),x=D=>{try{let S=Es(D,ve.value);return de.set(n,JSON.stringify(S)),i.current=S,o(S),l(""),!0}catch(S){return l(S.message),!1}},E=()=>{let D=$,S=D?.id??crypto.randomUUID(),R={id:S,name:u.trim(),revision:(D?.revision??0)+1,updatedAt:Date.now(),config:Mi(t),history:D?[...D.history,{revision:D.revision,updatedAt:D.updatedAt,config:D.config}].slice(-10):[]};x({...r,presets:[...r.presets.filter(M=>M.id!==S),R]})&&(c(S),v(""),V(`Saved ${R.name}, revision ${R.revision}`))},A=(D,S)=>{let R=oo(D,S);D.config?Li(D.config,`Template ${D.name}`):bt(D.pattern),At.value=D.intent,St(R.task),ps(R.criteria),b(null)},P=()=>{let D=URL.createObjectURL(new Blob([JSON.stringify(r,null,2)],{type:"application/json"})),S=document.createElement("a");S.href=D,S.download="code-flow-library.json",S.click(),setTimeout(()=>URL.revokeObjectURL(D),1e3)};return e("details",{class:"settings composer-library",children:[e("summary",{children:[e("span",{class:"st",children:"Advanced library management"}),e("span",{class:"ss",children:[r.presets.length," teams \xB7 ",r.templates.length," templates"]})]}),e("div",{class:"settings-body",children:[e("p",{class:"help",children:"Saved in this browser for the selected library. Export a backup to share or move them. Saving captures the current run draft. Teams include permissions, models, workflow options and limits; saved workflow commands are restored when applied."}),e("div",{class:"settings-grid",children:[e("div",{children:[e("label",{class:"lbl",for:"saved-preset",children:"Saved workflow"}),e("select",{class:"field",id:"saved-preset",value:m,onChange:D=>{let S=r.presets.find(R=>R.id===D.currentTarget.value);c(S?.id??""),p(S?.name??""),v("")},children:[e("option",{value:"",children:"New saved workflow\u2026"}),r.presets.map(D=>e("option",{value:D.id,children:[D.name," \xB7 r",D.revision]},D.id))]})]}),e("div",{children:[e("label",{class:"lbl",for:"preset-name",children:"Workflow name"}),e("input",{id:"preset-name",class:"field",maxLength:80,value:u,onInput:D=>p(D.currentTarget.value)})]})]}),$?e("div",{children:[e("label",{class:"lbl",for:"preset-revision",children:"Revision to apply"}),e("select",{id:"preset-revision",class:"field",value:f,onChange:D=>v(D.currentTarget.value),children:[e("option",{value:"",children:["Current \xB7 r",$.revision]}),[...$.history].reverse().map(D=>e("option",{value:D.revision,children:["r",D.revision," \xB7 ",new Date(D.updatedAt).toLocaleString()]},D.revision))]}),e("p",{class:"help",children:["Permissions: ",(f?$.history.find(D=>String(D.revision)===f)?.config:$.config)?.trust,". Up to 10 previous revisions are kept."]})]}):null,e("div",{class:"onboarding-actions",children:[e("button",{class:"btn",disabled:!u.trim(),onClick:E,children:$?"Save new revision":"Save current workflow"}),e("button",{class:"btn",disabled:!$||cn.value||ys.value,onClick:()=>{if($){let D=f?$.history.find(S=>String(S.revision)===f).config:$.config;Li(D,`Preset ${$.name} r${f||$.revision}`)}},children:"Apply workflow"}),$?e("button",{class:"btn ghost",onClick:()=>{x({...r,presets:r.presets.filter(D=>D.id!==m)})&&(c(""),p(""))},children:"Delete workflow"}):null]}),e("div",{class:"settings-grid",children:[e("div",{children:[e("label",{class:"lbl",for:"saved-template",children:"Task template"}),e("select",{class:"field",id:"saved-template",value:g,onChange:D=>{let S=r.templates.find(R=>R.id===D.currentTarget.value);w(S?.id??""),k(S?.name??"")},children:[e("option",{value:"",children:"New task template\u2026"}),r.templates.map(D=>e("option",{value:D.id,children:D.name},D.id))]})]}),e("div",{children:[e("label",{class:"lbl",for:"template-name",children:"Template name"}),e("input",{class:"field",id:"template-name",maxLength:80,value:C,onInput:D=>k(D.currentTarget.value)})]})]}),e("p",{class:"help",children:["Save the current task, workflow and acceptance criteria. Write parameters such as ",e("code",{children:"{{component}}"})," or ",e("code",{children:"{{issue}}"})," in the task or criteria; you'll be asked to fill each one when applying."]}),e("div",{class:"onboarding-actions",children:[e("button",{class:"btn",disabled:!C.trim()||!Pe.value.trim(),onClick:()=>{let D=g||crypto.randomUUID();x({...r,templates:[...r.templates.filter(S=>S.id!==D),{id:D,name:C,pattern:t.id,task:Pe.value,intent:At.value,criteria:Ts.value,config:Mi(t)}]})&&w(D)},children:"Save current task as template"}),e("button",{class:"btn",disabled:!g||cn.value||ys.value,onClick:()=>{let D=r.templates.find(S=>S.id===g);da(D).length?b(D):A(D,{})},children:"Apply template"}),g?e("button",{class:"btn ghost",onClick:()=>{x({...r,templates:r.templates.filter(D=>D.id!==g)})&&(w(""),k(""))},children:"Delete template"}):null]}),e("div",{class:"onboarding-actions",children:[e("button",{class:"btn",onClick:P,children:"Export library"}),e("button",{class:"btn",onClick:()=>T.current?.click(),children:"Import library"})]}),e("input",{ref:T,type:"file",hidden:!0,accept:".json,application/json",onChange:async D=>{let S=D.currentTarget.files?.[0];if(D.currentTarget.value="",!!S)try{if(S.size>1024*1024)throw new Error("Library files must be under 1 MB.");let R=Es(JSON.parse(await S.text()),ve.value),M=i.current,O=(B,ee)=>[...B,...ee.map(se=>B.some(te=>te.id===se.id)?{...se,id:crypto.randomUUID()}:se)];x({schemaVersion:1,presets:O(M.presets,R.presets),templates:O(M.templates,R.templates)})&&V("Library imported. Existing entries were preserved.")}catch(R){l(R.message)}}}),d?e("p",{class:"msg err",role:"alert",children:d}):null]}),y?e(kf,{template:y,onClose:()=>b(null),onApply:D=>A(y,D)}):null]})}var yf=[{id:"starter-bug",intent:"bug",name:"Fix a bug",pattern:"pipeline",task:`Fix the following bug:
142
+
143
+ Expected behavior:
144
+ Actual behavior:
145
+ Steps to reproduce:`,criteria:[]},{id:"starter-feature",intent:"feature",name:"Build a feature",pattern:"pipeline",task:`Build the following feature:
146
+
147
+ Who it helps:
148
+ Expected behavior:
149
+ Acceptance criteria:`,criteria:[]},{id:"starter-review",intent:"review",name:"Review code",pattern:"council",task:`Review the code for correctness and regressions.
150
+
151
+ Scope or branch to review:
152
+ Areas of concern:`,criteria:[]},{id:"starter-explore",intent:"explore",name:"Explore an idea",pattern:"debate",task:`Explore approaches to the following idea without implementing changes:
153
+
154
+ Goal:
155
+ Constraints:
156
+ Trade-offs to consider:`,criteria:[]}];function Yu({initialScope:t,onClose:s,onUsed:n,onConfigured:a}){let r=we(!0,s),[o]=h(()=>Ze.value.project),[i,d]=h(o&&t==="project"?"project":"personal"),[l,m]=h(""),[c,u]=h({}),[p,f]=h(null),v=Q(null),[g,w]=h(!1),[C,k]=h(""),[y,b]=h(()=>{let O=B=>{try{let ee=de.get(B);return{...Es(ee===null?Sn:JSON.parse(ee),ve.value),error:""}}catch(ee){return{...Sn,error:`Could not load templates: ${ee.message}`}}};return{project:o?O(`composerLibrary:${o.id}`):{...Sn,error:""},personal:O("composerLibrary")}}),T=i==="project"?y.project:y.personal,$=yf.filter(O=>ve.value.some(B=>B.id===O.pattern)),x=l.startsWith("saved:")?T.templates.find(O=>`saved:${O.id}`===l):void 0,E=l.startsWith("workflow:")?T.presets.find(O=>`workflow:${O.id}`===l):void 0,A=x??(E?{id:E.id,name:E.name,pattern:E.config.pattern,task:Pe.value.trim()||"{{task}}",criteria:[...Ts.value],config:E.config}:$.find(O=>O.id===l)),P=!!x;_(()=>{p&&v.current?.focus()},[p?.id]);let D=O=>{if(A)try{let B=i==="project"&&o?`composerLibrary:${o.id}`:"composerLibrary",ee=de.get(B),se=Es(ee===null?Sn:JSON.parse(ee),ve.value),te=se.templates.find(Y=>Y.id===A.id);if(!te||JSON.stringify(te)!==JSON.stringify(A))throw new Error("This template changed elsewhere. Close and reopen the picker to load the latest version.");let G=Es({...se,templates:O?se.templates.map(Y=>Y.id===A.id?O:Y):se.templates.filter(Y=>Y.id!==A.id)},ve.value),L=JSON.stringify(G);if(de.set(B,L),de.get(B)!==L)throw new Error("The change could not be saved. Check that browser storage is available.");b({...y,[i]:{...G,error:""}}),f(null),w(!1),u({}),k(""),O||m(""),V(O?"Template updated.":"Template deleted.")}catch(B){k(B.message)}},S=A?da(A):[],R;if(A)try{R=oo(A,c)}catch{}let M=()=>{!A||!R||p||g||(A.config?Li(A.config,`Template ${A.name}`):bt(A.pattern),A.id==="starter-explore"&&(Lt("debate","builder",[]),Lt("debate","reviewer",[])),At.value=E?At.value:A.intent,St(R.task),ps(R.criteria),a?.(A),n(i))};return e("dialog",{class:"picker",ref:r,"aria-labelledby":"use-task-template-title",children:e("form",{class:"picker-inner",onSubmit:O=>{O.preventDefault(),p?D({...p,name:p.name.trim(),criteria:p.criteria.map(B=>B.trim()).filter(Boolean)}):M()},children:[e("div",{class:"picker-head",children:e("h3",{id:"use-task-template-title",children:"Template library"})}),e("div",{class:"dialog-body",children:[e("label",{class:"lbl",for:"quick-use-library",children:"Library"}),e("select",{id:"quick-use-library",class:"field",disabled:!!p||g,value:i,onChange:O=>{d(O.currentTarget.value),m(""),u({}),k("")},children:[o?e("option",{value:"project",children:["This project \xB7 ",o.name]}):null,e("option",{value:"personal",children:"Personal library \xB7 all projects"})]}),T.error?e("p",{class:"msg err",role:"alert",children:T.error}):$.length||T.templates.length||T.presets.length?e(j,{children:[e("label",{class:"lbl",for:"quick-use-template",children:"Template"}),e("select",{id:"quick-use-template",class:"field",disabled:!!p||g,value:l,onChange:O=>{m(O.currentTarget.value),u({}),k("")},children:[e("option",{value:"",children:"Choose a template\u2026"}),e("optgroup",{label:"Built-in templates",children:$.map(O=>e("option",{value:O.id,children:O.name},O.id))}),e("optgroup",{label:"Saved templates",children:T.templates.map(O=>e("option",{value:`saved:${O.id}`,children:O.name},O.id))}),T.presets.length?e("optgroup",{label:"Saved workflows (keep your task)",children:T.presets.map(O=>e("option",{value:`workflow:${O.id}`,children:O.name},O.id))}):null]}),p?e(j,{children:[e("label",{class:"lbl",for:"edit-template-name",children:["Template name",e("input",{ref:v,id:"edit-template-name",class:"field",required:!0,maxLength:80,value:p.name,onInput:O=>f({...p,name:O.currentTarget.value})})]}),e("label",{class:"lbl",for:"edit-template-workflow",children:["Workflow",e("select",{id:"edit-template-workflow","aria-label":"Workflow",class:"field",value:p.pattern,onChange:O=>f({...p,pattern:O.currentTarget.value,config:O.currentTarget.value===p.pattern?p.config:void 0}),children:ve.value.map(O=>e("option",{value:O.id,children:O.name},O.id))})]}),e("label",{class:"lbl",for:"edit-template-task",children:["Template task",e("textarea",{id:"edit-template-task","aria-label":"Template task",class:"field",required:!0,rows:5,maxLength:1e5,value:p.task,onInput:O=>f({...p,task:O.currentTarget.value})})]}),e("label",{class:"lbl",for:"edit-template-criteria",children:["Acceptance criteria",e("textarea",{id:"edit-template-criteria","aria-label":"Acceptance criteria",class:"field",rows:3,value:p.criteria.join(`
157
+ `),onInput:O=>f({...p,criteria:O.currentTarget.value.split(`
158
+ `)})})]}),e("p",{class:"help",children:["One acceptance criterion per line. Keep placeholders such as ",e("code",{children:"{{component}}"})," for reusable prompts."]})]}):g&&A?e("div",{role:"group","aria-label":"Delete template confirmation",children:[e("p",{children:["Delete \u201C",A.name,"\u201D from ",i==="project"?"this project\u2019s library":"your personal library","?"]}),e("div",{class:"settings-actions",children:[e("button",{type:"button",class:"btn",onClick:()=>{w(!1),k("")},children:"Keep template"}),e("button",{type:"button",class:"btn danger",onClick:()=>D(null),children:"Delete template"})]})]}):e(j,{children:[A&&P?e("div",{class:"settings-actions",children:[e("button",{type:"button",class:"btn",onClick:()=>{f({...A,criteria:[...A.criteria]}),k("")},children:"Edit template"}),e("button",{type:"button",class:"btn danger",onClick:()=>{w(!0),k("")},children:"Delete template\u2026"})]}):null,S.map(O=>e("label",{class:"lbl",for:`quick-use-${O}`,children:[O,e("input",{class:"field",id:`quick-use-${O}`,required:!0,maxLength:4e3,value:c[O]??"",onInput:B=>u({...c,[O]:B.currentTarget.value})})]},O)),R?e("details",{children:[e("summary",{children:"Preview task"}),e("pre",{class:"template-preview",tabIndex:0,children:Na(R.task,R.criteria)})]}):null,e("p",{class:"help",children:[A?.config?`Restores task, workflow, agents, models, checks and permissions (${A.config.trust}).`:"Replaces the task, workflow and acceptance criteria; current agent settings are retained."," Review the settings before choosing Start run."]})]})]}):e("p",{class:"help",role:"status",children:"No templates in this library yet. Choose \u201CSave as template\u2026\u201D from the chat box menu to create one."}),ne.value&&!p&&!g?e(Qr,{only:"sources",onChoose:s}):null,C?e("p",{class:"msg err",role:"alert",children:C}):null]}),e("div",{class:"picker-foot",children:p?e(j,{children:[e("button",{type:"button",class:"btn",onClick:()=>{f(null),k("")},children:"Cancel editing"}),e("button",{type:"submit",class:"btn primary",disabled:!p.name.trim()||!p.task.trim(),children:"Save changes"})]}):e(j,{children:[e("button",{type:"button",class:"btn",onClick:s,children:"Cancel"}),e("button",{type:"submit",class:"btn primary",disabled:!R||g||cn.value||ys.value,children:"Use template"})]})})]})})}function Qu({p:t,initialScope:s,onClose:n,onSaved:a,runOptions:r}){let o=we(!0,n),[i,d]=h(""),[l]=h(()=>Ze.value.project),[m,c]=h(l&&s==="project"?"project":"personal"),[u]=h(()=>({task:Pe.value,intent:At.value,pattern:t.id,criteria:[...Ts.value],config:Mi(t),...r?{runOptions:structuredClone(r)}:{}})),[p,f]=h(""),v=()=>{if(!(!i.trim()||!u.task.trim()))try{let g=m==="project"&&l?`composerLibrary:${l.id}`:"composerLibrary",w=de.get(g),C=Es(w===null?Sn:JSON.parse(w),ve.value),k=Es({...C,templates:[...C.templates,{id:crypto.randomUUID(),name:i.trim(),...u}]},ve.value),y=JSON.stringify(k);if(de.set(g,y),de.get(g)!==y)throw new Error("The template could not be saved. Check that browser storage is available.");a(m),V(`Template \u201C${i.trim()}\u201D saved.`)}catch(g){f(g.message)}};return e("dialog",{class:"picker",ref:o,"aria-labelledby":"save-task-template-title",children:e("form",{class:"picker-inner",onSubmit:g=>{g.preventDefault(),v()},children:[e("div",{class:"picker-head",children:e("h3",{id:"save-task-template-title",children:"Save as template"})}),e("div",{class:"dialog-body",children:[e("label",{class:"lbl",for:"quick-template-name",children:"Template name"}),e("input",{id:"quick-template-name",class:"field",maxLength:80,required:!0,value:i,onInput:g=>d(g.currentTarget.value),placeholder:"e.g. Review a component"}),e("label",{class:"lbl",for:"quick-template-library",children:"Save to"}),e("select",{id:"quick-template-library",class:"field",value:m,onChange:g=>c(g.currentTarget.value),children:[l?e("option",{value:"project",children:["This project \xB7 ",l.name]}):null,e("option",{value:"personal",children:"Personal library \xB7 all projects"})]}),e("p",{class:"help",children:["Saves the task, acceptance criteria, workflow, agents, models, permissions, checks and run settings in this browser. Repository selection, remote worker assignments and attached files remain specific to each run. Use placeholders such as ",e("code",{children:"{{component}}"})," for reusable prompts."]}),p?e("p",{class:"msg err",role:"alert",children:p}):null]}),e("div",{class:"picker-foot",children:[e("button",{type:"button",class:"btn",onClick:n,children:"Cancel"}),e("button",{type:"submit",class:"btn primary",disabled:!i.trim()||!u.task.trim(),children:"Save template"})]})]})})}function kf({template:t,onClose:s,onApply:n}){let a=we(!0,s),[r,o]=h({}),i=da(t),d="";try{let l=oo(t,r);d=Na(l.task,l.criteria)}catch{}return e("dialog",{class:"picker",ref:a,"aria-labelledby":"fill-template-title",children:e("div",{class:"picker-inner",children:[e("div",{class:"picker-head",children:e("h3",{id:"fill-template-title",children:["Apply ",t.name]})}),e("div",{class:"dialog-body",children:[i.map(l=>e("div",{children:[e("label",{class:"lbl",for:`parameter-${l}`,children:l}),e("input",{class:"field",id:`parameter-${l}`,value:r[l]??"",maxLength:4e3,onInput:m=>o({...r,[l]:m.currentTarget.value})})]},l)),d?e("details",{children:[e("summary",{children:"Preview task"}),e("pre",{class:"template-preview",tabIndex:0,children:d})]}):null]}),e("div",{class:"picker-foot",children:[e("span",{class:"ps"}),e("button",{class:"btn",onClick:s,children:"Cancel"}),e("button",{class:"btn primary",disabled:!d,onClick:()=>n(r),children:"Use template"})]})]})})}function Xu({p:t,verificationProfile:s,container:n}){let a=ne.value,r=ss.value?.config??{},o=a?de.get(`check:${a}`):null,i=a?de.get(`setup:${a}`):null,d=[["Repository",a||"Not chosen","Repository picker"],["Project",Ze.value.project?.name??"Created from repository on start","Project selection / repository membership"],["Workflow",t.name,On.value.pattern??"Workflow default"],["Team",Object.entries(ns(t)).map(([l,m])=>`${l}: ${m.join(", ")||"skipped"}`).join(" \xB7 "),On.value.roles??"Workflow defaults"],["Verification command",jt.value||"No automated command",ya.value==="Override for this run."?"This run override":o!==null?"Project Settings (this browser)":r.check?".codeflow/config.json":ya.value||"Not configured"],["Worktree setup",Yt.value||"None",i!==null?"Repository preference (this browser)":r.setup?".codeflow/config.json":Yt.value?"Repository detection":"Not configured"],["Permissions",Tt.value,de.get("trust")!==null?"Explicit browser preference":r.trust?".codeflow/config.json":"Application default"],["Plan approval",hn(t.id)?"Required":"Automatic","Per-workflow browser preference / workflow default"],["Tool permissions",de.get("interactiveApprovals")==="1"?"Ask for supported native requests":"Decline requests requiring interaction",de.get("interactiveApprovals")!==null?"Explicit browser preference / selected preset":"Application default"],["Verification gates",s?`${s.name}: ${s.checks.map(l=>`${l.id} (${l.required?"required":"optional"}) \xB7 ${l.command}`).join("; ")||"No runnable gates"}`:"Single configured check",s?`Detected profile${s.source?` from ${s.source}`:""}; selected for this run`:"Verification command above"],["Agent container",n?.enabled?`${n.image||"Image not configured"}${n.authVolume?` \xB7 authentication volume ${n.authVolume}`:" \xB7 no authentication volume"}`:"Host CLI execution",n?.enabled?`Explicit choice for this run; network ${n.network===!1?"disabled":"enabled"}`:"Application default"],["Start branch",Fe.value||"Current HEAD",Fe.value?"Selected branch (remembered)":"Repository HEAD"],["Limits",`${Se.value.maxMinutes} minutes \xB7 ${Se.value.maxSteps} steps${Se.value.maxTokens?` \xB7 ${Se.value.maxTokens.toLocaleString()} reported tokens`:""}${Se.value.maxCostUsd?` \xB7 $${Se.value.maxCostUsd} reported API equivalent`:""}`,de.get("limits")?"Browser preferences / selected preset":"Application defaults"],["Explicit input context budget",es.value?`${es.value.maxPromptBytes??"No"} byte ceiling \xB7 ${es.value.maxApproximateTokens??"no"} estimated token ceiling \xB7 ${es.value.policy}`:"No configured ceiling",Xi.value]];for(let[l,m]of Object.entries(ns(t)))for(let c of m){if(c==="auto"){d.push([`${l} model`,"Selected at dispatch from available providers","Auto selection"]);continue}let u=lt.value[t.id]?.[l]?.[c],p=Ue.value[c],f=Ns.value[c],v=u?.model||p?.model||(f&&!("error"in f)?f.defaultModel:void 0),g=u?.effort||p?.effort||(f&&!("error"in f)?f.models.find(w=>w.id===v)?.defaultEffort||f.defaultEffort:void 0);d.push([`${l} \xB7 ${c}`,`${v||"CLI default"} \xB7 ${g||"default effort"}`,u?.model||u?.effort?"Per-role override":p?.model||p?.effort?On.value.models??"Provider settings":"CLI defaults"])}return e("details",{class:"settings effective-settings",children:[e("summary",{children:[e("span",{class:"st",children:"Run details"}),e("span",{class:"ss",children:"Values and where they came from"})]}),e("div",{class:"settings-body",children:e("div",{class:"settings-table-scroll",children:e("table",{children:[e("thead",{children:e("tr",{children:[e("th",{children:"Setting"}),e("th",{children:"Value"}),e("th",{children:"Source"})]})}),e("tbody",{children:d.map(([l,m,c],u)=>e("tr",{children:[e("th",{scope:"row",children:l}),e("td",{children:m}),e("td",{children:c})]},`${l}-${u}`))})]})})})]})}function Zu(){let t=[...vt.value.values()],s=et.value,[n,a]=h(null),[r,o]=h(!1),[i,d]=h(""),l=JSON.stringify([ne.value,Fe.value,t,s.map(({name:p,size:f})=>({name:p,size:f}))]),m=Q(l);m.current=l;let c=Q(0);_(()=>{++c.current,a(null),o(!1),d("")},[l]);let u=async()=>{let p=++c.current;o(!0),d("");try{let f=await q("/api/workspace/context",{repo:ne.value,baseRef:Fe.value||void 0,paths:t.map(v=>v.path),attachments:s.map(({name:v,size:g})=>({name:v,size:g}))});p===c.current&&l===m.current&&a(f)}catch(f){p===c.current&&l===m.current&&d(f.message)}finally{p===c.current&&l===m.current&&o(!1)}};return e("details",{class:"settings context-inspector",children:[e("summary",{children:[e("span",{class:"st",children:"Context inspector"}),e("span",{class:"ss",children:[t.length," repository paths \xB7 ",s.length," attachments"]})]}),e("div",{class:"settings-body",children:[e("p",{class:"help",children:"Preview selected files and expand folders from the chosen committed base. Explicit files show your current copy. Credential paths and symbolic selections are refused during actual context preparation; preview redaction does not remove secrets from other repository files."}),e("ul",{children:[t.map(p=>e("li",{children:[e("code",{children:[p.path,p.type==="dir"?"/":""]})," \xB7 selected repository path"]},p.path)),s.map((p,f)=>e("li",{children:[p.name," \xB7 ",p.size.toLocaleString()," bytes \xB7 uploaded file"]},f))]}),!t.length&&!s.length?e("p",{class:"help",children:"No explicit context selected. Agents can inspect their worktree."}):null,e("button",{class:"btn",disabled:!ne.value||!t.length&&!s.length||r,onClick:u,children:r?"Reading context\u2026":"Preview selected context"}),n?e("div",{class:"context-inspection-results",children:[e("p",{class:"help",children:[n.fileBytes.toLocaleString()," inspected text bytes \xB7 ",n.omittedBytes.toLocaleString()," known omitted-file bytes \xB7 ",n.attachmentBytes.toLocaleString()," attachment bytes \xB7 approximately ",n.approximateTokens.toLocaleString()," known text tokens. ",n.note]}),n.truncated?e("p",{class:"msg warn",children:"Inspection reached its file or byte limit. Narrow the selection to review the remaining context."}):null,n.files.map((p,f)=>e("details",{children:[e("summary",{children:[p.path," \xB7 ",p.source==="base-ref"?"committed base":"current copy",p.truncated?" \xB7 preview truncated":""]}),p.omitted?e("p",{class:"help",children:[p.bytes!==void 0?`${p.bytes.toLocaleString()} known bytes \xB7 `:"",p.omitted]}):e(j,{children:[e("p",{class:"help",children:[p.bytes?.toLocaleString()," bytes \xB7 approximately ",p.approximateTokens?.toLocaleString()," tokens",p.redacted?" \xB7 possible secret material redacted in this preview only":""]}),e("pre",{class:"template-preview",tabIndex:0,children:p.preview})]})]},`${p.path}-${f}`)),n.attachments.map((p,f)=>e("p",{class:"help",children:[p.name,": ",p.bytes.toLocaleString()," bytes \xB7 ",p.omitted??(p.approximateTokens===void 0?"token footprint unknown (image, binary or unrecognized format)":`approximately ${p.approximateTokens.toLocaleString()} text tokens from byte size`)]},f))]}):null,i?e("p",{class:"msg err",role:"alert",children:i}):null,e(Ju,{})]})]})}var Ni=ke(0);function ep(t){let s=de.json(`runDefaults:${t}`,{})??{};return{verification:["lightweight","standard","thorough"].includes(s.verification??"")?s.verification:"",container:{enabled:s.container?.enabled===!0,image:s.container?.image??"",authVolume:s.container?.authVolume??""}}}function xR(t,s){de.set(`runDefaults:${t}`,JSON.stringify(s)),Ni.value++}var Oi="application/x-codeflow-path",wf=10*1024*1024,Cf=25*1024*1024;function Lu(){let t=Ls.value?.repo===ne.value?Ls.value:null,s=Q(fa.value),[n,a]=h(s.current.remoteWorker),[r,o]=h(),[i,d]=h("");_(()=>{let W=!0;return o(void 0),d(""),n&&q(`/api/remote-workers/${encodeURIComponent(n.workerId)}/probe`,{repoMapping:n.repoMapping}).then(({capabilities:ue})=>{W&&o(Be.value.map(ze=>({...ze,available:ue.providers.some(qe=>qe.id===ze.id&&qe.available)})))},ue=>{W&&d(ue.message)}),()=>{W=!1}},[n?.workerId,n?.repoMapping,Be.value]);let[l,m]=h(s.current.container?.enabled??!1),[c,u]=h(s.current.container?.image??""),[p,f]=h(s.current.container?.authVolume??""),[v,g]=h(s.current.verificationProfile??null),[w,C]=h(s.current.verification??""),[k,y]=h(!1),b=Q(0),[T,$]=h(s.current.antigravityExecution==="native"),[x,E]=h(s.current.permissionRequirements??[]),[A,P]=h(s.current.toolApprovals??de.get("interactiveApprovals")==="1"),D=Rf(n?"Improve uses a local provider. Choose This computer to rewrite this task.":l?"Improve uses a local provider. Turn off Docker isolation to rewrite this task.":""),S=un.value,R=S?.id==="solo",[M,O]=h(!1),[B,ee]=h(()=>de.get("composerAdvanced")==="1"),se=async W=>{let ue=++b.current,ze=ne.value;if(G(!1),Y(""),C(W),g(null),y(!!W),!!W)try{let qe=await U(`/api/verification/profile?repo=${J(ze)}&preset=${W}`);ne.value===ze&&ue===b.current&&g(qe)}catch(qe){ue===b.current&&(Y(qe.message),G(!0))}finally{ue===b.current&&y(!1)}},[te,G]=h(!1);Qe(()=>{let W=ep(ne.value),ue=s.current.container??W.container;return m(ue.enabled),u(ue.image),f(ue.authVolume),a(s.current.remoteWorker),P(s.current.toolApprovals??de.get("interactiveApprovals")==="1"),G(!1),s.current.verification==="restored"?(++b.current,y(!1),C("restored"),g(s.current.verificationProfile??null)):se(s.current.verification??W.verification),()=>{++b.current}},[ne.value,Ni.value,t]),Qe(()=>{dt.value||(fa.value={remoteWorker:n,container:{enabled:l,image:c,authVolume:p},verification:w,verificationProfile:v,toolApprovals:A,antigravityExecution:T?"native":"isolated",permissionRequirements:x})},[n,l,c,p,w,v,A,T,x]);let[L,Y]=h(""),[X,N]=h(!1);_(()=>{let W=Mn("composer");W.length&&(St([Pe.value.trim(),...W.map(ue=>ue.text)].filter(Boolean).join(`
159
+
160
+ `)),et.value=[...et.value,...W.flatMap(ue=>ue.images)])},[_s.value]);let ae=ns(S),ie=ae.agent?.[0],pe=ie&&ie!=="auto"?{...Ue.value[ie],...lt.value[S.id]?.agent?.[ie]}:{},ge=(S?.id==="auto-team"&&ma.value?.enabled===!1?"Auto is disabled on this server. Choose Solo or a template in Advanced.":"")||(n?i||(r?vn(S,ae,!0,r):"Checking remote worker\u2026"):vn(S,ae))||(k?"Loading verification profile\u2026":te?"Verification profile unavailable. Choose another profile in Run options.":""),[Ie,xe]=h(!1),[We,Ve]=h(!1),[I,re]=h(!1),[oe,he]=h("project"),le=W=>({intent:_t.value?.repo===ne.value?"bug":At.value,journeyId:_t.value?.repo===ne.value?_t.value.id:void 0,repo:ne.value,project:Ct.value||void 0,projectSelection:"explicit",parentRunId:t?.id,task:Na(Pe.value,Ts.value),pattern:W.id,templateRef:ds.value?{id:ds.value.template.id,version:ds.value.template.version,inputs:ds.value.inputs}:void 0,roles:ae,options:as(W),baseRef:Fe.value,source:Yi(tt.value,t?.source),branchPrefix:pn.value.trim(),externalSourceId:yt.value?.id,context:{paths:[...vt.value.values()].map(ue=>({path:ue.path})),attachments:et.value.map(ue=>({name:ue.name,data:ue.data}))},agentSettings:R&&ie&&ie!=="auto"?{...Ue.value,[ie]:pe}:Ue.value,approvals:{plan:!!_n[W.id]&&hn(W.id),tools:n?!1:A},trust:Tt.value,permissionRequirements:x,antigravityExecution:T?"native":"isolated",roleSettings:lt.value[W.id]??{},loop:{...t?.loop,check:jt.value.trim(),setup:Yt.value.trim(),maxMinutes:Se.value.maxMinutes,maxSteps:Se.value.maxSteps,maxTokens:Se.value.maxTokens,maxCostUsd:Se.value.maxCostUsd,contextBudget:es.value,verification:v,remoteWorker:n,agentContainer:l&&!n?{...t?.loop.agentContainer,image:c.trim(),authVolume:p.trim()||void 0,network:t?.loop.agentContainer?.network??!0}:void 0,copy:n?[]:t?t.loop.copy??[]:ss.value?.config.copy}}),ce=S?le(S):null;Qe(()=>{pr.value=ce},[ce]);let[H,Ae]=h(null),Re=async()=>{if(!(ge||!S||X||k)){if(l&&!n&&!c.trim()){Y("Choose a prebuilt agent image");return}D.stop(),N(!0),Y("");try{let{id:W,project:ue}=await sp("/api/runs",{...le(S),remember:!0});Z.value={view:"run",id:W},F(),Promise.allSettled([Co(),Ga(ue),Un()])}catch(W){Y(W.message)}finally{N(!1)}}},F=()=>{Ls.value=null,de.set("baseRef",Fe.value),St(""),pl(),Se.value=de.json("limits",{maxMinutes:60,maxSteps:40}),ps([]),pn.value="",tt.value=null,yt.value=null,vt.value=new Map,et.value=[],_t.value=void 0,At.value=void 0};return!fe.value.length&&!ne.value&&!Pe.value.trim()?e("div",{class:"composer project-welcome",children:[e("div",{class:"eyebrow",children:"Your first project"}),e("h1",{children:"What would you like to work on?"}),e("p",{class:"lede",children:"Open a repository to start a project, describe a task, and review your agents\u2019 work."}),e("div",{class:"project-welcome-actions",children:[e("button",{class:"btn primary",onClick:()=>Gs(),children:"Open repository"}),e("a",{class:"btn",href:"#/settings/connections/sharing",children:"Join shared project"})]}),e("p",{class:"help",children:["Computer: ",Qt()," \xB7 ",e("a",{href:"#/settings/connections/workspace",children:"On another computer"})]}),e(Di,{})]}):e("div",{class:`composer ${R?"composer-single":""}`,children:[e("div",{class:"eyebrow",children:"New run"}),e("h1",{children:R?"What would you like to work on?":"What should the agents build?"}),e("p",{class:"lede",children:R?"Choose a provider, describe your task, and start the conversation.":"Describe the task, add the files that matter, and pick how your agents work together."}),e("div",{class:"where",role:"group","aria-label":"Where the run works",children:[e(Ks,{composer:!0}),Ze.value.project?.repos.length===1&&Ze.value.project.repos[0]===ne.value?e("span",{class:"repo-btn",title:ne.value,children:[e(z,{name:"folder"}),e("span",{class:"name",children:be(ne.value)})]}):Ze.value.project&&Ze.value.project.repos.length>1?e("label",{class:"composer-repository",children:["Repository",e("select",{class:"field","aria-label":"Run repository",value:ne.value,onChange:W=>void nr(W.currentTarget.value),children:[Ze.value.project.repos.includes(ne.value)?null:e("option",{value:"",children:"Choose repository"}),Ze.value.project.repos.map(W=>e("option",{value:W,children:[be(W)," \xB7 ",W]}))]})]}):e(xf,{}),e("button",{class:"btn small ghost",onClick:()=>Gs(Ct.value),children:"Open another repository"})]}),ha.value?e("p",{class:"msg warn",role:"alert",children:[ha.value," ",e("button",{class:"btn small",onClick:()=>void Co(),children:"Retry saving"})]}):null,ne.value&&Ze.value.problem?e("div",{class:"banner",children:[e("p",{children:Ze.value.problem}),e("button",{class:"btn",onClick:()=>{ks.value={repository:ne.value,project:Ze.value.project?.id}},children:"Choose destination"})]}):null,e(Di,{}),ln.value?null:e("div",{class:`banner ${Bs.value?"bad":""}`,children:[e("p",{children:Bs.value?/isn't a git repository$/.test(Bs.value)?`${Bs.value}. Pick the folder that contains your project's .git.`:Bs.value:"Choose the repository the agents should work in."}),e("button",{class:"btn primary",onClick:()=>wt.value=!0,children:"Choose repository"})]}),ss.value?.found?e("div",{class:`config-note ${ss.value.error?"bad":""}`,children:ss.value.error?e(j,{children:["\u26A0 ",ss.value.error]}):e(j,{children:[e(z,{name:"sliders"}),"Using ",e("code",{children:".codeflow/config.json"}),Mf(ss.value.config)]})}):null,yt.value?e("div",{class:"banner",children:[e("p",{children:["External context: ",yt.value.provider," ",yt.value.kind," ",yt.value.key," \xB7 ",yt.value.title]}),e("p",{class:"help",children:"This source remains untrusted. The run uses Safe permissions and isolated checks."}),e("button",{class:"btn small",onClick:()=>{yt.value=null},children:"Remove source"})]}):null,S?.id==="auto-team"?e(Oo,{}):null,_t.value?.repo===ne.value?e("p",{class:"help",children:["Recorded scenario: ",_t.value.title," ",e("button",{class:"btn ghost small",onClick:()=>{_t.value=void 0},children:"Detach scenario"})]}):null,e(Af,{onStart:Re,improve:D,controls:e(j,{children:[e("div",{class:"team-toggle",role:"group","aria-label":"Execution mode",children:[e("button",{type:"button",class:`btn ${S?.id==="auto-team"?"on":"ghost"}`,"aria-pressed":S?.id==="auto-team",onClick:()=>bt("auto-team"),children:"Auto"}),e("button",{type:"button",class:`btn ${R?"on":"ghost"}`,"aria-pressed":R,onClick:()=>bt("solo"),children:"Solo"})]}),R?e(j,{children:ie&&ie!=="auto"?e(Qs,{agent:ie,providers:r,onAgent:W=>Lt(S.id,"agent",[W]),settings:pe,onSettings:W=>Mt(S.id,"agent",ie,W),permissions:{trust:yt.value?"safe":Tt.value,tools:!n&&!l&&!yt.value&&A},onPermissions:W=>{mn(W.trust),P(W.tools),de.set("interactiveApprovals",W.tools?"1":"0")},restricted:!!yt.value,approvalsAvailable:!n&&!l}):e(nt,{above:!0,label:"Provider",icon:"layers",class:"chat-choice",trigger:e(j,{children:[e("span",{children:ie==="auto"?"Auto provider":"Choose provider"}),e(z,{name:"chevron"})]}),children:W=>e(j,{children:(r??Be.value).map(ue=>e(me,{disabled:!ue.available||!nn(ue.id),onClick:()=>{Lt(S.id,"agent",[ue.id]),W()},children:ue.displayName},ue.id))})})}):e("span",{class:"help",children:ds.value?`Template: ${ds.value.template.name} v${ds.value.template.version}`:S?.id==="auto-team"?"Plans and delegates dynamically":`Template: ${S?.name}`}),R?null:e(j,{children:[e("button",{type:"button",class:"btn ghost",onClick:()=>{O(!0),ee(!0),de.set("composerAdvanced","1")},children:"Advanced"}),e(Ho,{permissions:{trust:yt.value?"safe":Tt.value,tools:!n&&!l&&!yt.value&&A},onPermissions:W=>{mn(W.trust),P(W.tools),de.set("interactiveApprovals",W.tools?"1":"0")},restricted:!!yt.value,approvalsAvailable:!n&&!l&&Object.values(ae).flat().some(W=>W==="codex"||W.startsWith("acp:")),agent:Object.values(ae).flat().find(W=>W.startsWith("acp:"))})]}),e("button",{class:"btn primary task-start",disabled:!!ge||X,onClick:Re,title:ge||"Start run (\u2318\u21B5)",children:[X?"Starting\u2026":"Start run",e(z,{name:"send"})]}),e(nt,{above:!0,label:"Run actions",icon:"more",class:"chat-choice",children:W=>e(j,{children:[e(me,{disabled:!S||!Us.value,onClick:()=>{W(),re(!0)},children:[e(z,{name:"files"}),"Use template\u2026"]}),e(me,{disabled:!S||!Us.value||!Pe.value.trim()||w==="restored",sub:w==="restored"?"Choose a verification preset before saving a template":void 0,onClick:()=>{W(),Ve(!0)},children:[e(z,{name:"files"}),"Save as template\u2026"]}),e(me,{disabled:!!ge,onClick:()=>{W(),Ae(null),xe(!0)},children:[e(z,{name:"clock"}),"Schedule\u2026"]})]})})]})}),e("div",{class:"composer-summary","aria-label":"Run configuration summary",children:[e("span",{children:[e("b",{children:"Computer"})," ",Qt(),n?` \xB7 Agent worker: ${n.workerId}`:""]}),e("span",{children:[e("b",{children:"Project"})," ",Ze.value.project?.name??"Choose project"]}),e("span",{children:[e("b",{children:"Repository"})," ",ne.value?be(ne.value):"Choose repository"," \xB7 ",Fe.value||ln.value?.current||"HEAD"]}),e("span",{children:[e("b",{children:R?"Solo":S?.id==="auto-team"?"Auto":"Template"})," ",S?aa(S,ae):"Choose workflow"]}),e("span",{children:[e("b",{children:"Checks"})," ",k?"Detecting checks\u2026":v?v.checks.map(W=>W.command).join(" \xB7 ")||"No runnable gates":jt.value.trim()||"Not configured"]}),e("span",{children:[e("b",{children:"Limit"})," ",t?.loop.maxInvocations??Se.value.maxSteps," calls \xB7 ",Se.value.maxMinutes," minutes"]}),ge?e("span",{class:"composer-problem",role:"status",children:ge}):null,Tt.value==="full"?e("span",{class:"warn",children:"Full access \xB7 no provider sandbox"}):null,e("button",{class:"btn small ghost",onClick:()=>O(!M),"aria-expanded":M,children:"Edit run options"})]}),e(El,{repository:ne.value,intent:_t.value?.repo===ne.value?"bug":At.value}),dn.value?e("div",{class:"msg err",children:dn.value}):null,e("details",{class:"composer-options compact",open:M,onToggle:W=>O(W.currentTarget.open),children:[e("summary",{children:["Run options ",e("span",{children:"Agents, context, checks and limits for this task"})]}),e(Ku,{}),e("div",{class:"section",children:[S&&!R?e("p",{class:"pattern-why",children:aa(S,ae)}):null,Tt.value==="full"?e("p",{class:"full-warn",role:"alert",children:[e("b",{children:"Full access: no sandbox."})," Agents can run commands and change files outside their worktree with your credentials. Review permissions in Advanced agent settings."]}):null,S&&_n[S.id]&&(S.id!=="debate"||ae.builder?.length)?e("label",{class:"checkpoint",children:[e("input",{type:"checkbox",checked:hn(S.id),onChange:W=>Ya(W.currentTarget.checked,S.id)}),e("span",{children:[e("b",{children:["Let me approve ",_n[S.id]]})," before agents build."]})]}):null,e("div",{class:`donewhen ${S?.requiresCheck&&!jt.value.trim()?"required":""}`,children:[e("label",{class:"lbl",for:"checkCmd",children:"Done when this passes"}),e("div",{class:"dw-row",children:[e("span",{class:"dw-prompt",children:"$"}),e("input",{class:"field",id:"checkCmd",disabled:ys.value,placeholder:"e.g. npm test",spellcheck:!1,autocomplete:"off",value:jt.value,onInput:W=>{Qa(W.currentTarget.value),ya.value="Override for this run."}})]}),e("div",{class:"help",children:"Override the project check for this run. A run without a passing automated check is unchecked."})]}),e("div",{class:"donewhen",children:[e("label",{class:"lbl",for:"setupCmd",children:"Worktree setup command"}),e("div",{class:"dw-row",children:[e("span",{class:"dw-prompt",children:"$"}),e("input",{class:"field",id:"setupCmd",disabled:ys.value,placeholder:"e.g. npm ci",spellcheck:!1,autocomplete:"off",value:Yt.value,onInput:W=>Xa(W.currentTarget.value)})]}),e("div",{class:"help",children:"Runs once in each new worktree before agent work and checks. Override for this run; save reusable defaults in Settings \u2192 Projects."})]}),!n&&!l&&!v?e(Gu,{pattern:S?.id,roles:ae}):null]}),e("div",{class:"composer-more",children:[e("details",{class:"settings advanced-controls",open:B,onToggle:W=>{ee(W.currentTarget.open),de.set("composerAdvanced",W.currentTarget.open?"1":"0")},children:[e("summary",{children:[e("span",{class:"st",children:["Advanced",T?" \xB7 Unrestricted Antigravity":""]}),e("span",{class:"ss",children:"Templates, roles, models, permissions and limits"})]}),e("div",{class:"settings-body",children:[e("label",{class:"lbl",for:"workflow-select",children:"Built-in workflow templates"}),e("select",{class:"field",id:"workflow-select","aria-label":"Workflow",value:S?.id??"auto-team",onChange:W=>bt(W.currentTarget.value),children:[e("option",{value:"auto-team",children:"Auto \u2014 dynamic plan"}),e("option",{value:"solo",children:"Solo \u2014 one agent"}),ve.value.filter(W=>!["solo","auto-team"].includes(W.id)).map(W=>e("option",{value:W.id,children:W.name},W.id))]}),e(ur,{}),S?.id==="auto-team"?e(Ol,{remote:!!n||l,nativeAntigravity:T}):null,e("fieldset",{class:"section",children:[e("legend",{children:"Antigravity execution"}),e("label",{class:"checkpoint",children:[e("input",{type:"checkbox",checked:T,onChange:W=>$(W.currentTarget.checked)}),e("span",{children:"Use unrestricted Antigravity with my existing login"})]}),e("p",{class:"help",children:"Opt-in for this run. Antigravity uses your normal profile without Code Flow's sandbox. Terminal, browser, MCP, hooks and native agents follow provider settings. Read-only requests are advisory and native child usage is outside the worker budget. Claude and Codex keep their run permissions. Requires a valid saved login, local attended execution, and no mandatory boundaries, Safe mode or tool approvals."})]}),e("fieldset",{class:"section",children:[e("legend",{children:"Required permission enforcement"}),[["workspace-writes","Require an agent workspace write boundary"],["no-command-network","Block network access from agent commands"],["no-external-tools","Disable external browser and MCP tools"]].map(([W,ue])=>e("label",{class:"checkpoint",children:[e("input",{type:"checkbox",checked:x.includes(W),onChange:ze=>E(ze.currentTarget.checked?[...x,W]:x.filter(qe=>qe!==W))}),e("span",{children:ue})]},W)),e("p",{class:"help",children:"Only providers that enforce these requirements can run. Command network restrictions do not cover provider inference or external tools. With none selected, the existing provider-specific permission profile applies."})]}),e("div",{class:"section",children:[e("button",{class:"btn",disabled:!S||!Us.value,onClick:()=>re(!0),children:"Browser task library"})," ",e("button",{class:"btn",disabled:!S||!Pe.value.trim(),onClick:()=>Ve(!0),children:"Save task preset"}),e("p",{class:"help",children:"Existing browser presets remain available. Applying a preset keeps this run's permissions and isolation."})]}),e($d,{value:n,onChange:W=>{D.stop(),a(W)},disabled:X}),n?e("p",{class:"help",children:"Provider availability comes from this worker. Checks and setup run on the application server. Copied workspace files and native interactive approvals are unavailable; use explicitly staged references."}):null,S&&!R?e(jf,{p:S,roles:ae,providers:r,remote:!!n}):null,e("div",{class:"section",children:[e("label",{class:"lbl",for:"verification-profile",children:"Verification gates"}),e("select",{class:"field",id:"verification-profile",value:w,disabled:!ne.value,onChange:W=>void se(W.currentTarget.value),children:[e("option",{value:"",children:"Single configured check"}),w==="restored"?e("option",{value:"restored",children:["From original run \xB7 ",v?.name]}):null,e("option",{value:"lightweight",children:"Lightweight profile"}),e("option",{value:"standard",children:"Standard profile"}),e("option",{value:"thorough",children:"Thorough profile"})]}),v?e("p",{class:"help",children:["Required gates: ",v.checks.map(W=>W.command).join(" \xB7 ")||"No runnable gates detected",". Each gate appears in the run's evidence."]}):null]}),S?e(Df,{p:S,roles:ae}):null]})]}),S?e(Xu,{p:S,verificationProfile:v,container:{enabled:l,image:c,authVolume:p,network:t?.loop.agentContainer?.network}}):null,e(Zu,{}),e("details",{class:"settings agent-isolation",children:[e("summary",{children:[e("span",{class:"st",children:"Agent isolation"}),e("span",{class:"ss",children:l&&!n?`Prebuilt Docker image${c.trim()?` \xB7 ${c.trim()}`:""}`:"Off \xB7 agents use this computer's CLIs"})]}),e("div",{class:"settings-body",children:[e("label",{class:"checkpoint",children:[e("input",{type:"checkbox",checked:l,disabled:!!n,onChange:W=>{D.stop(),m(W.currentTarget.checked)}}),e("span",{children:"Run agents in a prebuilt Docker image"})]}),l?e(j,{children:[e("label",{class:"iso-field",children:["Image",e("input",{class:"field mono",placeholder:"Your prepared image:tag",spellcheck:!1,value:c,onInput:W=>u(W.currentTarget.value)})]}),e("label",{class:"iso-field",children:["Authentication volume",e("input",{class:"field mono",spellcheck:!1,placeholder:"Optional explicitly named Docker volume",value:p,onInput:W=>f(W.currentTarget.value)})]}),e("p",{class:"help",children:["The image must contain compatible official CLIs and be authenticated inside the image or selected volume. Host credential folders are never mounted. Agents receive their worktree and read-only Git metadata; network access is ",t?.loop.agentContainer?.network===!1?"disabled by the original run":"enabled for inference",". Live team bridges use structured turn-boundary replies in containers."]})]}):null]})]})]})]}),L?e("div",{class:"msg err",children:L}):null,I?e(Yu,{initialScope:oe,onConfigured:W=>{W.runOptions?.verification&&se(W.runOptions.verification)},onClose:()=>re(!1),onUsed:W=>{he(W),re(!1)}}):null,We&&S?e(Qu,{p:S,runOptions:{verification:w,container:{enabled:l,image:c,authVolume:p}},initialScope:oe,onClose:()=>Ve(!1),onSaved:W=>{he(W),Ve(!1)}}):null,Ie&&S&&!H?e(Tf,{onClose:()=>xe(!1),onChoose:W=>{W==="backlog"||W==="missions"?(xe(!1),Z.value={view:"automations",kind:W}):Ae(W)}}):null,Ie&&S&&H==="once"?e(Sf,{body:le(S),onClose:()=>xe(!1)}):null,Ie&&S&&H==="repeat"?e(qu,{body:le(S),onClose:()=>xe(!1)}):null]})}function Tf({onClose:t,onChoose:s}){let n=we(!0,t);return e("dialog",{ref:n,class:"picker","aria-labelledby":"schedule-choice-title",children:e("div",{class:"picker-inner",children:[e("div",{class:"picker-head",children:e("h3",{id:"schedule-choice-title",children:"Schedule work"})}),e("div",{class:"dialog-body purpose-choices",children:Da.map(a=>e("button",{class:"settings-result",onClick:()=>s(a.id),children:e("span",{children:[e("strong",{children:a.label}),e("span",{children:a.description})]})}))}),e("div",{class:"picker-foot",children:e("button",{class:"btn",onClick:t,children:"Cancel"})})]})})}function Sf({body:t,onClose:s}){let n=we(!0,s);return e("dialog",{ref:n,class:"picker","aria-labelledby":"schedule-run-title",children:e("div",{class:"picker-inner",children:[e("div",{class:"picker-head",children:e("h3",{id:"schedule-run-title",children:"Start later"})}),e("div",{class:"dialog-body",children:e(ro,{runRequest:t,project:t.project,repo:t.repo})}),e("div",{class:"picker-foot",children:e("button",{class:"btn",onClick:s,children:"Close"})})]})})}function xf(){let t=ln.value;return e("button",{type:"button",class:`repo-btn ${t?"":"empty"} ${Bs.value?"bad":""}`,title:t?t.repo:"Choose repository",onClick:()=>wt.value=!0,children:[e(z,{name:"folder"}),e("span",{class:"name",children:t?be(t.repo):ys.value?"Checking\u2026":Bs.value||"Choose repository\u2026"}),e(z,{name:"chevron",class:"caret"})]})}async function sp(t,s){try{return await q(t,s)}catch(n){if(!(n instanceof Ge)||n.confirm!=="allowUntrusted")throw n;if(!await Ce(`${n.message}
161
+
162
+ Run its checks on this machine anyway?`,{title:"Run checks locally?",confirmLabel:"Run checks",danger:!0}))throw new Error("Not started: the source isn't trusted and Docker isn't available.");return q(t,{...s,allowUntrusted:!0})}}function uc({base:t,onClose:s,onStarted:n}){let a=we(!0,s),r=un.value?.id,[o,i]=h(new Set(r?[r]:[])),[d,l]=h(1),[m,c]=h(!1),[u,p]=h(""),f=ve.value.map(w=>{let C=ns(w);return{p:w,roles:C,problem:vn(w,C)}}),v=o.size*d,g=async()=>{c(!0),p("");try{let w=f.filter(k=>o.has(k.p.id)).map(k=>({label:k.p.name,pattern:k.p.id,roles:k.roles,options:as(k.p),roleSettings:lt.value[k.p.id]??{}})),{group:C}=await sp("/api/compare",{run:t,variants:w,repeat:d});s(),n(C)}catch(w){p(w.message)}finally{c(!1)}};return e("dialog",{class:"picker",ref:a,"aria-labelledby":"compare-title",children:e("div",{class:"picker-inner",children:[e("div",{class:"picker-head",children:[e("h3",{id:"compare-title",children:"Compare setups"}),e("div",{class:"help",children:"Runs this task once per setup, at the same time, and shows the results side by side in Insights: did it pass, how long, how many steps and tokens, did it touch the tests. Each pattern uses the team you last picked for it \u2014 select a pattern in the composer to change its team."})]}),e("div",{class:"dialog-body",children:[f.map(({p:w,roles:C,problem:k})=>e("label",{class:`compare-choice ${k?"off":""}`,children:[e("input",{type:"checkbox",checked:o.has(w.id),disabled:!!k,onChange:y=>{let b=new Set(o);y.currentTarget.checked?b.add(w.id):b.delete(w.id),i(b)}}),e("span",{children:[e("b",{children:w.name}),e("span",{class:"help",children:k||aa(w,C)})]})]},w.id)),e("label",{class:"check",children:["Run each",e("select",{class:"field inline",value:d,onChange:w=>l(Number(w.currentTarget.value)),children:[e("option",{value:1,children:"once"}),e("option",{value:2,children:"twice"}),e("option",{value:3,children:"3 times"})]}),"(repeats show how consistent a setup is)"]}),u?e("div",{class:"msg err",children:u}):null]}),e("div",{class:"picker-foot",children:[e("span",{class:"ps",children:[v," run",v===1?"":"s",v>9?" \u2014 at most 9":"","; they share code-flow's agent slots, so some may wait their turn."]}),e("button",{class:"btn",onClick:s,children:"Cancel"}),e("button",{class:"btn primary",disabled:m||o.size<2||v>9,onClick:g,title:o.size<2?"Pick at least two setups":"",children:m?"Starting\u2026":`Start ${v} run${v===1?"":"s"}`})]})]})})}function vn(t,s,n=!0,a){if(t?.id==="auto-team"&&ma.value?.enabled===!1)return"New Auto teams are disabled. Existing teams can still be resumed.";if(dt.value)return"Restoring project draft\u2026";if(ys.value)return"Checking repository\u2026";if(!ne.value)return"Choose a repository first";if(Ze.value.problem)return Ze.value.problem;if(cn.value)return"Loading repository configuration\u2026";if(n&&!Pe.value.trim())return"Describe the task to start";if(!t)return"Pick how the agents work together";let r=(t.id==="auto-team"?s.coordinator??[]:Object.values(s).flat()).find(d=>d!=="auto"&&!nn(d));if(r)return`${r} cannot enforce managed run permissions yet. Choose Claude or Codex.`;for(let d of t.roles)if(!d.optional&&!s[d.id]?.length)return`Pick an agent for ${d.label}`;if(t.id==="race"&&Oa(t.id,"contestants",s.contestants??[])<2)return"A race needs at least two contestants";if(t.id==="debate"&&Oa(t.id,"debaters",s.debaters??[])<2)return"A debate needs at least two debaters";if(t.id==="auto-team"&&!s.pool?.some(nn))return"Keep at least one compatible provider in the pool (Claude or Codex)";if(t.id==="auto-team"&&Se.value.maxSteps<4)return"An Auto team needs at least 4 steps: planning, work, review and recovery";if(t.requiresCheck&&!jt.value.trim())return`${t.name} needs a \u201CDone when\u201D command, e.g. npm test`;let o=new Set(t.id==="auto-team"?s.coordinator??[]:Object.values(s).flat());if(a){let d=new Set(a.filter(l=>l.available).map(l=>l.id));for(let l of o)if(l!=="auto"&&!d.has(l))return`${De[l]} is unavailable on the selected remote worker`;return o.has("auto")&&!d.size?"No configured provider CLI is available on this remote worker":""}let i=Ss.value?.find(d=>o.has(d.id)&&d.installed&&d.signedIn===!1);return i?`${i.name} isn't signed in \u2014 open Settings \u2192 Agents & models`:""}function Rf(t){let[s,n]=h(null),[a,r]=h(null),[o,i]=h(null),[d,l]=h(As.value.defaultMode),m=Q(t);m.current=t;let c=()=>[Pe.value,ne.value,ln.value,Ye.value,Ze.value.project?.id,Fe.value,vt.value,et.value,tt.value,yt.value,Ts.value,es.value,m.current,As.value],u=($,x)=>$.every((E,A)=>Object.is(E,x[A])),p=Q(c()),f=Q(0),v=Q(!0),g=Q(null),w=Q(null),C=()=>{let $=g.current;g.current=null,$?.stop.abort(),w.current=null,n(null),r(null),i(null)},k=()=>{let $=c();u(p.current,$)||(p.current=$,f.current++,C())};Qe(()=>{let $=Ui(k);return()=>{v.current=!1,g.current?.stop.abort(),g.current=null,$()}},[]),Qe(k,[t]),_(()=>l(As.value.defaultMode),[As.value.defaultMode]);let y=async($=d)=>{if(g.current){C();return}k();let x=Pe.value;if(!v.current||m.current||!x.trim()||!ne.value)return;let E={stop:new AbortController,revision:f.current,snapshot:c()};g.current=E,w.current=null,n({mode:$}),i(null),r(null);let A=()=>v.current&&g.current===E&&!E.stop.signal.aborted&&f.current===E.revision&&u(E.snapshot,c());try{let P=await U("/api/improve-prompt",{method:"POST",signal:E.stop.signal,body:JSON.stringify({text:x,repo:ne.value,mode:$,execution:"local",settings:As.value,context:[...vt.value.values()].map(R=>R.path).concat(et.value.map(R=>R.name)),source:tt.value?{kind:tt.value.kind,number:tt.value.number,title:tt.value.title}:void 0})});if(!A())return;g.current=null,n(null),St(P.prompt);let D=Be.value.find(R=>R.id===P.agent)?.displayName??P.agent,S={before:x,note:`${D}: ${P.summary}`,revision:f.current,snapshot:c()};w.current=S,r(S)}catch(P){A()&&i({message:P.message,revision:f.current,snapshot:c()})}finally{v.current&&g.current===E&&(g.current=null,n(null))}};return{busy:s,mode:d,run:y,pick:$=>{l($),y($)},undo:()=>{let $=w.current;if(!$||$.revision!==f.current||!u($.snapshot,c())){C();return}C(),St($.before)},stop:C,disabledReason:t,agentName:Hu[As.value.agent],error:o&&o.revision===f.current&&u(o.snapshot,c())?o.message:"",done:a&&a.revision===f.current&&u(a.snapshot,c())?a:null}}function $f({improve:t,disabled:s}){let[n,a]=h(!1),r=Q(null),o=Q(null),i=Q(!1),d=(l=!1)=>{a(!1),l&&o.current?.focus()};return Qe(()=>{if(!n)return;let l=r.current?.querySelectorAll('[role="menuitemradio"]');l?.[i.current?l.length-1:0]?.focus()},[n]),_(()=>{if(!n)return;let l=m=>{r.current?.contains(m.target)||d()};return document.addEventListener("pointerdown",l),()=>document.removeEventListener("pointerdown",l)},[n]),Qe(()=>{s&&a(!1)},[s]),e("div",{class:"pop-wrap",ref:r,onBlur:l=>{l.currentTarget.contains(l.relatedTarget)||d()},onKeyDown:l=>{if(l.key==="Escape"&&n){l.preventDefault(),l.stopPropagation(),d(!0);return}if(!["ArrowDown","ArrowUp","Home","End"].includes(l.key))return;if(l.preventDefault(),!n){s||(i.current=l.key==="ArrowUp"||l.key==="End",a(!0));return}let m=[...r.current?.querySelectorAll('[role="menuitemradio"]')??[]],c=m.findIndex(u=>u===document.activeElement);m[l.key==="Home"?0:l.key==="End"?m.length-1:(c+(l.key==="ArrowUp"?-1:1)+m.length)%m.length]?.focus()},children:[e("button",{ref:o,type:"button",class:`icon-btn ${n?"on":""}`,"aria-label":"How Improve works","aria-haspopup":"menu","aria-expanded":n,"aria-controls":n?"improve-mode-menu":void 0,disabled:s,title:"How Improve works",onClick:()=>{i.current=!1,a(!n)},children:e(z,{name:"chevron"})}),n?e("div",{class:"pop-menu",role:"menu",id:"improve-mode-menu","aria-label":"Improve mode",children:[e(Rt,{children:"Improve the task"}),[{mode:"quick",title:"Quick rewrite",description:"From your text alone, using your configured model"},{mode:"repo",title:"Use the repository",description:"Reads a committed repository snapshot. Skips local edits."}].map(l=>e("button",{type:"button",role:"menuitemradio",tabIndex:-1,"aria-checked":t.mode===l.mode,class:`pop-item ${t.mode===l.mode?"on":""}`,onClick:()=>{d(),t.pick(l.mode),r.current?.previousElementSibling?.focus()},children:[e("span",{class:"pi-main",children:l.title}),e("span",{class:"pi-sub",children:l.description})]},l.mode))]}):null]})}function If(){let t=ln.value,s=tt.value?.kind==="pr"?tt.value:null;if(!t)return null;let n=s?"__pr":Fe.value;return e("div",{class:"task-branch",children:[e("label",{for:"baseRef",children:"Start from branch"}),e("select",{id:"baseRef",class:"field",value:n,disabled:!!s,title:s?`The worktree starts from PR #${s.number}: ${s.headRefName}`:"Create the new worktree from this Git branch",onChange:a=>{Fe.value=a.currentTarget.value},children:s?e("option",{value:"__pr",children:["PR #",s.number," \xB7 ",s.headRefName]}):e(j,{children:[e("option",{value:"",children:t.current?`Current branch \xB7 ${t.current}`:"Current HEAD"}),Fe.value&&!t.branches.some(a=>a.name===Fe.value)?e("option",{value:Fe.value,children:Fe.value}):null,[["local","Local branches"],["remote","Remote branches"],["run","Previous run branches"]].map(([a,r])=>e("optgroup",{label:r,children:t.branches.filter(o=>o.kind===a).map(o=>e("option",{value:o.name,children:o.name},o.name))},a))]})}),e("span",{class:"help",children:"New worktree"})]})}function Af({onStart:t,improve:s,controls:n}){let[a,r]=h(!1),o=Q(null),i=Q(null),d=!!Pe.value.trim()&&!!ne.value&&!s.disabledReason;_(()=>{let f=o.current;f&&(f.style.height="auto",f.style.height=`${Math.min(420,Math.max(120,f.scrollHeight))}px`)},[Pe.value]),_(()=>{let f=v=>{!v.target?.closest?.(".taskbox")&&v.dataTransfer?.types.includes("Files")&&v.preventDefault()};return window.addEventListener("dragover",f),window.addEventListener("drop",f),()=>{window.removeEventListener("dragover",f),window.removeEventListener("drop",f)}},[]);let m=vt.value.size+et.value.length,c=`${m} item${m===1?"":"s"} of context`,u=m?`${c} \u2014 agents read these first`:"Drag files here to give the agents context",p=m?`${c} \u2014 agents read these before starting`:"Drag files here from the file list or Finder to give the agents context";return e("div",{class:`taskbox ${a?"over":""}`,onDragOver:f=>{let v=[...f.dataTransfer?.types??[]];!v.includes(Oi)&&!v.includes("Files")||(f.preventDefault(),f.dataTransfer.dropEffect="copy",r(!0))},onDragLeave:f=>{f.currentTarget.contains(f.relatedTarget)||r(!1)},onDrop:f=>{r(!1);let v=f.dataTransfer?.getData(Oi);if(v){f.preventDefault(),Rr(JSON.parse(v));return}if(!f.dataTransfer?.files.length)return;f.preventDefault();let g=[...f.dataTransfer.items].filter(k=>k.kind==="file"),w=[],C=[];[...f.dataTransfer.files].forEach((k,y)=>{g[y]?.webkitGetAsEntry?.()?.isDirectory?C.push(k.name):w.push(k)}),tp(w,C)},children:[e(If,{}),e("textarea",{ref:o,"aria-label":"Task",placeholder:"e.g. Add rate limiting to the /login endpoint, with tests\u2026",value:Pe.value,"aria-busy":!!s.busy,onInput:f=>St(f.currentTarget.value),onKeyDown:f=>{f.key==="Enter"&&(f.metaKey||f.ctrlKey)&&(f.preventDefault(),t())}}),e(Ef,{}),e("div",{class:"bar",children:[e("button",{class:"btn ghost small",title:"Attach files from your computer",onClick:()=>i.current?.click(),children:[e(z,{name:"attach"})," Attach"]}),e("button",{class:"btn ghost small",title:"Start from a GitHub issue or pull request",onClick:()=>Js.value={kind:tt.value?.kind==="pr"?"pr":"issue"},children:[e(z,{name:"pull"})," GitHub"]}),e("button",{class:"btn ghost small",title:"Show the repository's files in the side panel",onClick:()=>gt("files"),children:[e(z,{name:"files"})," Files"]}),s.busy?e("span",{class:"hint status",role:"status",children:s.busy.mode==="repo"?"Reading the committed repository snapshot and rewriting the task\u2026":"Rewriting the task\u2026"}):s.error?e("span",{class:"hint status bad",role:"alert",title:s.error,children:s.error}):s.done?e("span",{class:"hint status",role:"status",title:s.done.note,children:s.done.note}):s.disabledReason?e("span",{class:"hint status",id:"improve-execution-note",children:s.disabledReason}):e("span",{class:"hint",title:p,children:u}),s.done?e("button",{class:"btn ghost small improve-undo",title:"Put back the task as you wrote it",onClick:s.undo,children:"Undo"}):null,e("div",{class:"improve",children:[e("button",{class:"btn ghost small",disabled:!s.busy&&!d,"aria-label":s.busy?"Stop":"Improve","aria-description":`Prompt improvement agent: ${s.agentName}. Mode: ${s.mode}. Configure in Settings, Agents & models.`,"aria-describedby":s.disabledReason?"improve-execution-note":void 0,title:s.busy?"Stop rewriting":s.disabledReason||(ne.value?s.mode==="repo"?"Rewrite the task using a committed repository snapshot":"Rewrite the task so agents can act on it":"Choose a repository first"),onClick:()=>void s.run(),children:[s.busy?e("span",{class:"spin"}):e(z,{name:"sparkle"})," ",s.busy?"Stop":e(j,{children:["Improve ",e("span",{class:"improve-agent","aria-hidden":"true",children:["\xB7 ",s.agentName]})]})]}),e($f,{improve:s,disabled:!!s.busy||!d})]})]}),n?e("div",{class:"task-controls",children:n}):null,e("div",{class:"overlay",children:"Drop to add as context"}),e("input",{ref:i,type:"file",multiple:!0,hidden:!0,onChange:f=>{tp([...f.currentTarget.files??[]]),f.currentTarget.value=""}})]})}function Ef(){let t=s=>{let n=new Map(vt.value);n.delete(s),vt.value=n};return e("div",{class:"chips",children:[e(lu,{}),[...vt.value.values()].map(s=>e("span",{class:"chip-ctx",title:s.path,children:[e(z,{name:s.type==="dir"?"folder":"note"}),e("span",{class:"n",children:[s.path,s.type==="dir"?"/":""]}),e("button",{type:"button",title:"Remove","aria-label":`Remove ${s.path}`,onClick:()=>t(s.path),children:"\xD7"})]},s.path)),et.value.map((s,n)=>e("span",{class:"chip-ctx",title:s.name,children:[e(z,{name:"attach"}),e("span",{class:"n",children:[s.name," \xB7 ",Ht(s.size)]}),e("button",{type:"button",title:"Remove","aria-label":`Remove ${s.name}`,onClick:()=>et.value=et.value.filter(a=>a!==s),children:"\xD7"})]},`a${n}`))]})}function Rr(t){let s=new Map(vt.value);s.set(t.path,{path:t.path,type:t.type}),vt.value=s}function Pf(t){let s=new Map(vt.value);s.has(t.path)?s.delete(t.path):s.set(t.path,{path:t.path,type:t.type}),vt.value=s}async function tp(t,s=[]){dn.value=s.length?`${s.join(", ")} ${s.length===1?"is a folder":"are folders"}. From outside the repo, add individual files.`:"";let n=et.value.reduce((r,o)=>r+o.size,0),a=[];for(let r of t){if(r.size>wf){dn.value=`"${r.name}" is over 10 MB.`;continue}if(n+r.size>Cf){dn.value="Attached files must total under 25 MB.";break}try{a.push({name:r.name,size:r.size,data:await Gi(r)}),n+=r.size}catch{dn.value=`Couldn't read "${r.name}".`}}et.value=[...et.value,...a]}function Oa(t,s,n){return n.reduce((a,r)=>a+1+(r==="auto"?0:lt.value[t]?.[s]?.[r]?.variants?.length??0),0)}function jf({p:t,roles:s,providers:n,remote:a}){return e("div",{class:"team",children:[t.roles.map(r=>{let o=s[r.id]??[],i=r.multiple,d=a?[]:(n??Be.value).filter(l=>l.available&&nn(l.id)).flatMap(l=>{let m=t.id==="auto-team"?ka.value[l.id]:Ns.value[l.id],c=m&&!("error"in m)?m.models.filter(yn):[];return c.length?[{agent:l.id,models:c}]:[]});return e("div",{class:"role",children:[e("div",{class:"role-heading",children:[e("div",{class:"role-description",children:[e("div",{class:"rl",children:[r.label,e("span",{class:"role-count",children:[Oa(t.id,r.id,o)," ",t.id==="auto-team"&&r.id==="pool"?"choices":"selected"]})]}),e("div",{class:"rd",children:r.description})]}),d.length?e("button",{type:"button",class:"btn small role-free-action",onClick:()=>{let l=i?d:[d.find(m=>o.includes(m.agent))??d[0]];for(let m of l)Mt(t.id,r.id,m.agent,{model:m.models[0].id,effort:"",variants:i?m.models.slice(1).map(c=>({model:c.id})):[]});Lt(t.id,r.id,l.map(m=>m.agent))},children:i?"Select all free":"Use free model"}):null]}),e("div",{class:"role-pick",children:[e("div",{class:"pills",role:"group","aria-label":`${r.label} providers`,children:[(n??Be.value).map(l=>{let m=o.includes(l.id);return e("button",{type:"button",class:"pill","aria-pressed":m,disabled:(!l.available||!nn(l.id))&&!m,title:nn(l.id)?l.available?`${r.multiple?"Toggle":"Choose"} ${l.displayName}`:`${l.displayName} isn't installed`:"Managed run permissions are not supported by this adapter yet",onClick:()=>Lt(t.id,r.id,r.multiple?m?o.filter(c=>c!==l.id):[...o,l.id]:[l.id]),children:[e("span",{class:"provider-check","aria-hidden":"true",children:m?"\u2713":"+"}),e("span",{children:l.displayName})]},l.id)}),t.id!=="auto-team"||r.id!=="pool"?e("button",{type:"button",class:"pill auto","aria-pressed":o.includes("auto"),title:"code-flow picks an installed agent when the run starts, skipping plans that are near their usage limit",onClick:()=>{let l=o.includes("auto");Lt(t.id,r.id,r.multiple?l?o.filter(m=>m!=="auto"):[...o,"auto"]:["auto"])},children:"Auto"}):null,r.optional?e("button",{type:"button",class:"pill none","aria-pressed":!o.length,onClick:()=>Lt(t.id,r.id,[]),children:"Skip"}):null]}),i&&Oa(t.id,r.id,o)>o.length?e("span",{class:"help",children:[Oa(t.id,r.id,o)," ",t.id==="auto-team"?"model choices \xB7 coordinator selects within the member limit":"agents \xB7 each model runs separately"]}):null,o.some(l=>l!=="auto")?e(Lf,{p:t,roleId:r.id,roleLabel:r.label.toLowerCase(),agents:o.filter(l=>l!=="auto"),remote:a}):null]})]},r.id)}),e("div",{class:"team-summary",children:[e(z,{name:"chevron"}),e("span",{children:aa(t,s)})]})]})}var La={safe:{label:"Safe",help:"Edit files only. Claude can't run commands; Codex stays sandboxed."},standard:{label:"Standard",help:"Edit files and run common build/test commands (npm, node, pytest, uv, poetry, cargo, go, make\u2026)."},trusted:{label:"Trusted",help:"Any command for Claude; network access inside Codex's sandbox. Use on repos you trust."},full:{label:"Full access",help:"Every agent can run any command, use the network and change files outside its worktree, with your credentials. Only for repos and tasks you trust completely."}};function aa(t,s,n=!0){let a=l=>s[l]?.[0]?De[s[l][0]]:"\u2014",r=l=>{let m=(s[l]??[]).map(c=>{let u=c==="auto"?1:1+(lt.value[t.id]?.[l]?.[c]?.variants?.length??0);return`${De[c]}${u>1?` \xD7 ${u}`:""}`});return m.length?m.length===1?m[0]:`${m.slice(0,-1).join(", ")} and ${m.at(-1)}`:"\u2014"},o=as(t),i=jt.value.trim(),d=(i?` \xB7 done when \u201C${i}\u201D passes`:"")+(n&&_n[t.id]&&hn(t.id)&&(t.id!=="debate"||s.builder?.length)?` \xB7 you approve ${_n[t.id]} first`:"");switch(t.id){case"auto-team":return`${a("coordinator")} assembles up to ${o.maxMembers??4} members from ${r("pool")} \u2192 the team works through dependencies \u2192 an independent member verifies the result${d}`;case"pipeline":return`${a("planner")} plans \u2192 ${a("builder")} builds \u2192 ${a("reviewer")} reviews (up to ${o.maxRounds} rounds of fixes)${d}`;case"race":return`${r("contestants")} each solve it separately \u2192 ${r("judge")} ${(s.judge?.length??0)>1?"vote":"picks"} the best, blind${d}`;case"debate":return`${r("debaters")} propose and debate \u2192 ${a("synthesizer")} writes the final plan${s.builder?.length?` \u2192 ${a("builder")} builds it${s.reviewer?.length?` \u2192 ${a("reviewer")} reviews it`:""}`:" (design only)"}${d}`;case"supervisor":return`${a("supervisor")} splits the work and sets the contracts \u2192 ${r("workers")} build the parts in parallel \u2192 ${a("supervisor")} merges${s.reviewer?.length?` \u2192 ${a("reviewer")} reviews`:" and reviews its own work"}${d}`;case"tdd":return`${a("tester")} writes tests \u2192 ${a("builder")} makes them pass \u2192 ${a("tester")} tries to break it${d}`;case"council":return`${r("reviewers")} review on their own, read-only \u2192 ${a("chair")} merges what they found \xB7 nothing is changed or posted without you`;case"solo":return`${a("agent")} works on it in its own branch; reply to keep going, like a chat${i?` \xB7 code-flow runs \u201C${i}\u201D after every turn`:""}`;case"loop":{let l=s.workers??[],m=l.length>1?`, handing over to ${l.slice(1).map(c=>De[c]).join(", then ")} if stuck`:"";return`${l.length?De[l[0]]:"\u2014"} fixes and code-flow re-runs \u201C${i||"your check"}\u201D until it passes${m} (max ${o.maxRounds} rounds)`}default:return t.summary}}function Mf(t){let s=[t.check&&`check \u201C${t.check}\u201D`,t.setup&&`setup \u201C${t.setup}\u201D`,t.copy?.length&&`copies ${t.copy.join(", ")}`,t.run?.command&&`runs the app with \u201C${t.run.command}\u201D`,t.trust&&`${t.trust} permissions`].filter(Boolean);return s.length?`: ${s.join(" \xB7 ")}`:""}function Lf({p:t,roleId:s,roleLabel:n,agents:a,remote:r}){let o=lt.value[t.id]?.[s]??{};return e("div",{class:"role-models",children:a.map(i=>{let d=o[i]??{},l=t.id==="auto-team"?ka.value[i]:Ns.value[i];if(r)return e("div",{class:"provider-models",children:[e("div",{class:"provider-model-heading",children:e($e,{id:i})}),e("div",{class:"team-model-row",children:[e("label",{children:["Model",e("input",{class:"field","aria-label":`${De[i]} model for the ${n}`,placeholder:"Worker CLI default model",value:d.model??"",onChange:g=>Mt(t.id,s,i,{model:g.currentTarget.value})})]}),e("label",{children:["Effort",e("input",{class:"field","aria-label":`${De[i]} effort for the ${n}`,placeholder:"Default effort",value:d.effort??"",onChange:g=>Mt(t.id,s,i,{effort:g.currentTarget.value})})]})]})]},i);if(!l||"error"in l)return e("div",{class:"provider-models",children:e("div",{class:"provider-model-heading",children:[e($e,{id:i}),e("span",{class:"help",children:l?"Using CLI defaults \xB7 model list unavailable":"Loading models\u2026"})]})},i);let m=l,c=t.id==="auto-team"&&s==="pool"?{}:Ue.value[i]??{},u=c.model||m.defaultModel,p=t.roles.find(g=>g.id===s)?.multiple,f=[{model:d.model??"",effort:d.effort??""},...p?d.variants??[]:[]],v=zn(m.models).filter(g=>g.id!==(d.model||u)&&!d.variants?.some(w=>w.model===g.id));return e("div",{class:"provider-models",children:[e("div",{class:"provider-model-heading",children:[e("div",{class:"provider-model-name",children:[e($e,{id:i}),f.length>1?e("span",{class:"role-count",children:[f.length," models"]}):null]}),p?e(Jn,{class:"add-model",label:`Add ${De[i]} model for the ${n}`,value:"",placeholder:"+ Add model",options:v,disabled:!v.length||f.length>=129,onChange:g=>Mt(t.id,s,i,{variants:[...d.variants??[],{model:g}]})}):null]}),f.map((g,w)=>{let C=w===0,k=m.models.find(x=>x.id===(g.model||u)),y=k?.efforts??m.efforts,b=C?c.effort||k?.defaultEffort||m.defaultEffort:k?.defaultEffort||m.defaultEffort,T=x=>C?`${De[i]} ${x} for the ${n}`:`${De[i]} additional ${x} ${w} for the ${n}`,$=zn(m.models).filter(x=>C||x.id===g.model||x.id!==(d.model||u)&&!d.variants?.some(E=>E.model===x.id));return e("div",{class:`team-model-row ${C?"primary":"additional"}`,children:[e("div",{class:"model-field",children:[e("span",{children:["Model",f.length>1?` ${w+1}`:""]}),e(Jn,{label:T("model"),value:g.model,options:[...C?[{id:"",label:t.id==="auto-team"&&s==="pool"?"Automatic \xB7 coordinator chooses":u?`Default \xB7 ${m.models.find(x=>x.id===u)?.label??u}`:"Default model"}]:[],...$,...g.model&&!m.models.some(x=>x.id===g.model)?[{id:g.model,label:g.model}]:[]],onChange:x=>{if(C){let A=m.models.find(P=>P.id===(x||u))?.efforts??m.efforts;Mt(t.id,s,i,{model:x,effort:g.effort&&A.includes(g.effort)?g.effort:"",variants:d.variants?.filter(P=>P.model!==(x||u))})}else Mt(t.id,s,i,{variants:d.variants.map((E,A)=>A===w-1?{model:x}:E)})}})]}),e("label",{children:["Effort",e("select",{class:"field","aria-label":T("effort"),value:g.effort??"",onChange:x=>{let E=x.currentTarget.value;C?Mt(t.id,s,i,{effort:E}):Mt(t.id,s,i,{variants:d.variants.map((A,P)=>P===w-1?{...A,effort:E}:A)})},children:[e("option",{value:"",children:b?`Default \xB7 ${b}`:"Default effort"}),y.map(x=>e("option",{value:x,children:x},x))]})]}),C?e("span",{class:"model-remove-space","aria-hidden":"true"}):e("button",{type:"button",class:"icon-btn remove-model",title:"Remove model","aria-label":`Remove ${De[i]} model ${g.model}`,onClick:()=>Mt(t.id,s,i,{variants:d.variants.filter((x,E)=>E!==w-1)}),children:e(z,{name:"close"})})]},w)})]},i)})})}function Df({p:t,roles:s}){let n=ln.value,r=[...new Set(Object.values(s).flat().filter(m=>m!=="auto"))].map(m=>{let c=Ue.value[m];return c?.model||c?.effort?`${De[m]}: ${[c.model,c.effort].filter(Boolean).join(" ")}`:null}).filter(Boolean),o=tt.value?.kind==="pr"?tt.value:null,i=o?`PR #${o.number}'s branch`:Fe.value||(n?.current?`HEAD (${n.current})`:"HEAD"),d=as(t),l=m=>{Se.value={...Se.value,...m}};return e("details",{class:"settings",children:[e("summary",{children:[e("span",{class:"st",children:"Branches and limits"}),e("span",{class:"ss",children:["from ",i," \xB7 ",r.length?r.join(", "):"default models"," \xB7 stops after ",Se.value.maxMinutes," min or ",Se.value.maxSteps," steps",Tt.value==="full"?e("span",{class:"full-access",children:" \xB7 \u26A0 full access"}):null]})]}),e("div",{class:"settings-body",children:[e("div",{class:"settings-grid",children:[e("div",{children:[e("label",{class:"lbl",for:"branchPrefix",children:"Result branch name"}),e("input",{class:"field",id:"branchPrefix",placeholder:"codeflow/<run-id>",spellcheck:!1,autocomplete:"off",value:pn.value,onInput:m=>pn.value=m.currentTarget.value}),e("div",{class:"help",children:["Results land on ",e("code",{children:"name/build"}),", ",e("code",{children:"name/candidate-a"}),"\u2026"]})]}),t.options.map(m=>e("div",{children:[e("label",{class:"lbl",for:`opt-${m.id}`,children:m.label}),m.type==="boolean"?e("input",{type:"checkbox",id:`opt-${m.id}`,checked:!!d[m.id],onChange:c=>fn(t,m.id,c.currentTarget.checked)}):e("input",{class:"field",type:"number",id:`opt-${m.id}`,min:m.min,max:m.max,value:String(d[m.id]),onInput:c=>fn(t,m.id,Number(c.currentTarget.value))})]},m.id))]}),e("div",{children:[e("span",{class:"lbl",children:"Limits \u2014 the run stops when it reaches either"}),e("div",{class:"settings-grid",children:[e("div",{children:[e("label",{class:"lbl",for:"maxMinutes",children:"Minutes"}),e("input",{class:"field",type:"number",id:"maxMinutes",min:1,max:720,value:String(Se.value.maxMinutes),onInput:m=>l({maxMinutes:Number(m.currentTarget.value)||60})})]}),e("div",{children:[e("label",{class:"lbl",for:"maxSteps",children:"Agent steps"}),e("input",{class:"field",type:"number",id:"maxSteps",min:1,max:200,value:String(Se.value.maxSteps),onInput:m=>l({maxSteps:Number(m.currentTarget.value)||40})})]}),e("div",{children:[e("label",{class:"lbl",for:"maxTokens",children:"Reported token ceiling"}),e("input",{class:"field",id:"maxTokens",type:"number",min:1,placeholder:"Optional",value:Se.value.maxTokens??"",onInput:m=>l({maxTokens:Number(m.currentTarget.value)||void 0})})]}),e("div",{children:[e("label",{class:"lbl",for:"maxCostUsd",children:"Reported API-equivalent ceiling ($)"}),e("input",{class:"field",id:"maxCostUsd",type:"number",min:.001,step:.01,placeholder:"Optional",value:Se.value.maxCostUsd??"",onInput:m=>l({maxCostUsd:Number(m.currentTarget.value)||void 0})})]})]}),e("div",{class:"help",children:"Ceilings use reported usage; they cannot count missing provider data and are checked between operations. API-equivalent cost is not your subscription bill. Work done before a limit is kept on its branch."}),Ls.value?.loop.maxInvocations!==void 0?e("p",{class:"help",children:["Original invocation ceiling: ",Ls.value.loop.maxInvocations," CLI calls. This ceiling is retained separately from the agent-step limit."]}):null]}),n?e("div",{class:"help",children:["Each run works in git worktrees under ",n.worktreeRoot,"/ \u2014 your checkout is never touched."]}):null]})]})}function fr({agent:t,used:s,settings:n,onChange:a}){let r=Ns.value[t.id],o=n??Ue.value[t.id]??{},i=g=>a?a(g):Vs(t.id,g),[d,l]=h(null);if(!r||"error"in r)return e("div",{class:`model-row ${s?"":"unused"}`,children:[e($e,{id:t.id}),e("div",{class:"err",children:"Uses the CLI's defaults (couldn't list models)"})]});let m=r,c=m.models.some(g=>g.id===o.model),u=d??(!!o.model&&!c),p=m.models.find(g=>g.id===o.model),f=p?.efforts?.length?p.efforts:m.efforts,v=p?.defaultEffort||m.defaultEffort;return e("div",{class:`model-row ${s?"":"unused"}`,title:s?"":"Not used by this team",children:[e($e,{id:t.id}),e(Jn,{label:`${t.displayName} model`,value:u?"__custom":o.model??"",options:[{id:"",label:m.defaultModel?`Default (${m.defaultModel})`:"Default model"},...zn(m.models),...m.allowCustom?[{id:"__custom",label:"Other\u2026"}]:[]],onChange:g=>{l(g==="__custom");let w=g==="__custom"?"":g,C=m.models.find(y=>y.id===w),k=C?.efforts?.length?C.efforts:m.efforts;i({model:w,effort:o.effort&&k.includes(o.effort)?o.effort:""})}}),e("select",{class:"field","aria-label":`${t.displayName} effort`,value:o.effort??"",onChange:g=>i({effort:g.currentTarget.value}),children:[e("option",{value:"",children:v?`Default (${v})`:"Default effort"}),f.map(g=>e("option",{value:g,children:g},g))]}),u?e("input",{class:"field custom",type:"text",placeholder:"model id or alias","aria-label":`${t.displayName} custom model`,value:o.model??"",onInput:g=>i({model:g.currentTarget.value.trim()})}):null]})}function wc({root:t,onOpen:s}){let[n,a]=h(null),[r,o]=h(!1),[i,d]=h(""),[l,m]=h(""),[c,u]=h(null),p=An(),f=An();_(()=>{let g=p();if(m(""),u(null),!t){a(null),d("Choose a repository to see its files.");return}d("Loading\u2026"),U(`/api/tree?repo=${J(t)}&path=`).then(w=>{g()&&(a(w.entries),o(w.truncated),d(""))}).catch(w=>g()&&d(w.message))},[t]),_(()=>{let g=f(),w=l.trim();if(!w||!t)return u(null);let C=setTimeout(async()=>{try{let k=await U(`/api/search?repo=${J(t)}&q=${J(w)}`);g()&&u(k)}catch(k){g()&&d(k.message)}},180);return()=>clearTimeout(C)},[l,t]);let v=Z.value.view==="composer"&&t===ne.value;return e(j,{children:[e("input",{type:"search",class:"field files-search",placeholder:"Search files\u2026","aria-label":"Search files",autocomplete:"off",spellcheck:!1,value:l,onInput:g=>m(g.currentTarget.value)}),e("div",{class:"tree",children:[i?e("div",{class:"tree-empty",children:i}):null,(c??n)?.length?e("div",{role:"tree","aria-label":c?"Matching files":"Files",children:c?c.map(g=>e(_i,{entry:g,depth:0,sub:g.path.includes("/")?g.path.slice(0,g.path.lastIndexOf("/")):"",root:t,onOpen:s,context:v},`s:${g.path}`)):n?.map(g=>e(_i,{entry:g,depth:0,root:t,onOpen:s,context:v},g.path))}):null,c&&!c.length?e("div",{class:"tree-empty",children:"No matching files"}):null,!c&&r?e("div",{class:"tree-empty",children:"Showing the first 1000 \u2014 use search"}):null]}),v?e("div",{class:"files-foot",children:["Click a file to read it; ",e("b",{children:"+"})," or drag adds it to the task. ",e("b",{class:"mark-m",children:"M"})," changed \xB7 ",e("b",{class:"mark-u",children:"U"})," new"]}):null]})}function _i({entry:t,depth:s,sub:n,root:a,onOpen:r,context:o}){let[i,d]=h(null),[l,m]=h(!1),[c,u]=h(""),p=An(),f=o&&vt.value.has(t.path),v=t.status?{M:"changed",U:"new, not committed",A:"added"}[t.status]:"",g=t.type==="dir",w=async()=>{if(m(!0),i)return;let y=p();u("Loading\u2026");try{let b=await U(`/api/tree?repo=${J(a)}&path=${J(t.path)}`);if(!y())return;d(b.entries),u(b.entries.length?"":"Empty folder")}catch(b){y()&&u(b.message)}},C=()=>{if(!g)return r(t.path);if(l)return m(!1);w()},k=y=>{if(y.target!==y.currentTarget)return;let b=y.currentTarget;if(y.key==="Enter"||y.key===" ")C();else if(y.key==="ArrowRight"&&g&&!l)w();else if(y.key==="ArrowLeft"&&g&&l)m(!1);else if(y.key==="ArrowDown"||y.key==="ArrowUp"){let T=[...b.closest('[role="tree"]')?.querySelectorAll('[role="treeitem"]')??[]];T[T.indexOf(b)+(y.key==="ArrowDown"?1:-1)]?.focus()}else return;y.preventDefault()};return e("div",{children:[e("div",{class:`node ${f?"added":""}`,role:"treeitem",tabIndex:0,"aria-level":s+1,"aria-expanded":g?l:void 0,"aria-label":`${t.name}${n?`, in ${n}`:""}${v?`, ${v}`:""}`,draggable:o,title:`${t.path}${v?` \u2014 ${v}`:""}${o?`
163
+ Drag into the task, or click +`:""}`,style:`padding-left:${2+s*14}px`,onClick:C,onKeyDown:k,onDblClick:()=>o&&t.type==="file"&&Rr(t),onDragStart:y=>{y.dataTransfer.setData(Oi,JSON.stringify({path:t.path,type:t.type})),y.dataTransfer.setData("text/plain",t.path),y.dataTransfer.effectAllowed="copy",y.currentTarget.classList.add("dragging")},onDragEnd:y=>y.currentTarget.classList.remove("dragging"),children:[e("span",{class:"tw",children:t.type==="dir"?e(z,{name:"chevron",class:l?"":"shut"}):null}),e("span",{class:`lb ${t.type}`,children:[e(z,{name:t.type==="dir"?"folder":"file",class:"fi"})," ",t.name]}),n?e("span",{class:"sub",children:n}):null,e("span",{class:`st ${t.status??""}`,children:t.status??""}),o?e("button",{type:"button",class:"add",title:`Add ${t.path} to the task`,"aria-label":`Add ${t.path} to the task`,onClick:y=>{y.stopPropagation(),Pf(t)},children:"+"}):null]}),l?e("div",{role:"group",children:[c?e("div",{class:"tree-empty",style:`padding-left:${22+s*14}px`,children:c}):null,i?.map(y=>e(_i,{entry:y,depth:s+1,root:a,onOpen:r,context:o},y.path))]}):null]})}export{So as a,xl as b,_f as c,ap as d,xo as e,Bf as f,at as g,Jf as h,Kf as i,Gf as j,Rs as k,$g as l,Ig as m,Fu as n,Hu as o,K0 as p,G0 as q,As as r,eR as s,Gu as t,kR as u,Bk as v,ep as w,xR as x,La as y,fr as z,xi as A,Ar as B,pc as C,Ta as D,Ir as E,Sc as F,ld as G,Gr as H,pi as I,au as J,vh as K,hi as L,bh as M,yh as N,kh as O,VT as P,ku as Q,zT as R,rS as S,PS as T,c0 as U,d0 as V};