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

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 (319) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +141 -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/changes-62ZIEQSN.js +1 -0
  17. package/public/assets/chunk-2PZVOKID.js +1 -0
  18. package/public/assets/chunk-4D5IENEB.js +1 -0
  19. package/public/assets/chunk-5SARP5MU.js +1 -0
  20. package/public/assets/chunk-63YLZ3PR.js +1 -0
  21. package/public/assets/chunk-7FUHKF2M.js +1 -0
  22. package/public/assets/chunk-APQEVJ2K.js +1 -0
  23. package/public/assets/chunk-CGOZQMEZ.js +2 -0
  24. package/public/assets/chunk-J4VYS3KV.js +2 -0
  25. package/public/assets/chunk-L7TUCIYF.js +1 -0
  26. package/public/assets/chunk-SIHDWM2Y.js +154 -0
  27. package/public/assets/chunk-TEJVYIKC.js +1 -0
  28. package/public/assets/code-browser-VB2HGZSG.js +4 -0
  29. package/public/assets/filtered-tasks-ES5CP4KV.js +1 -0
  30. package/public/assets/interactive-browser-7F5ZXRUV.js +7 -0
  31. package/public/assets/join-project-6RTFHNCA.js +1 -0
  32. package/public/assets/main-65EW73SB.js +1 -0
  33. package/public/assets/project-invitations-view-GMPWGWYM.js +1 -0
  34. package/public/assets/settings-UB5Q4AQM.js +9 -0
  35. package/public/assets/styles-18792BB4.css +32 -0
  36. package/public/assets/team-server-wizard-2GLDWS6D.js +8 -0
  37. package/public/assets/terminal-IWAIM4DE.js +62 -0
  38. package/public/assets.json +1 -0
  39. package/public/bundle-meta.json +1 -0
  40. package/public/docs/.nojekyll +0 -0
  41. package/public/docs/accessibility.html +19 -0
  42. package/public/docs/acp-agents.html +117 -0
  43. package/public/docs/agent-containers.html +79 -0
  44. package/public/docs/api.html +1130 -0
  45. package/public/docs/app.js +342 -0
  46. package/public/docs/application-improvements.html +275 -0
  47. package/public/docs/architecture-explorer.html +19 -0
  48. package/public/docs/architecture.html +149 -0
  49. package/public/docs/auto-team.html +148 -0
  50. package/public/docs/automations.html +109 -0
  51. package/public/docs/checkpoint-review.html +37 -0
  52. package/public/docs/code-hosts.html +35 -0
  53. package/public/docs/code-intelligence.html +35 -0
  54. package/public/docs/configuration.html +346 -0
  55. package/public/docs/context-inspection.html +23 -0
  56. package/public/docs/coordinated-changes.html +28 -0
  57. package/public/docs/deferred-runs.html +25 -0
  58. package/public/docs/dependency-discovery.html +19 -0
  59. package/public/docs/documentation.html +84 -0
  60. package/public/docs/dynamic-teams-evaluation.html +174 -0
  61. package/public/docs/dynamic-teams-implementation-plan.html +882 -0
  62. package/public/docs/dynamic-teams-implementation-review-1.html +141 -0
  63. package/public/docs/dynamic-teams-plan-review-0.html +204 -0
  64. package/public/docs/extensions.html +42 -0
  65. package/public/docs/external-sources.html +96 -0
  66. package/public/docs/filesystem-policy.html +26 -0
  67. package/public/docs/filtered-tasks.html +44 -0
  68. package/public/docs/font-license.txt +92 -0
  69. package/public/docs/getting-started.html +143 -0
  70. package/public/docs/github-review-threads.html +26 -0
  71. package/public/docs/github.html +157 -0
  72. package/public/docs/help.html +69 -0
  73. package/public/docs/index.html +88 -0
  74. package/public/docs/installation.html +80 -0
  75. package/public/docs/launch-profiles.html +48 -0
  76. package/public/docs/maintenance.html +60 -0
  77. package/public/docs/memory-claims.html +31 -0
  78. package/public/docs/memory-storage.html +58 -0
  79. package/public/docs/notifications.html +39 -0
  80. package/public/docs/patterns.html +195 -0
  81. package/public/docs/performance-results.html +210 -0
  82. package/public/docs/performance.html +166 -0
  83. package/public/docs/project-conventions.html +22 -0
  84. package/public/docs/project-first-navigation-plan.html +587 -0
  85. package/public/docs/project-teams-implementation-plan.html +772 -0
  86. package/public/docs/project-teams.html +129 -0
  87. package/public/docs/provider-compatibility.html +20 -0
  88. package/public/docs/releasing.html +65 -0
  89. package/public/docs/remote-workers.html +64 -0
  90. package/public/docs/review-inbox.html +26 -0
  91. package/public/docs/run-storage.html +23 -0
  92. package/public/docs/runs.html +141 -0
  93. package/public/docs/search.json +1 -0
  94. package/public/docs/security.html +133 -0
  95. package/public/docs/shared-projects.html +31 -0
  96. package/public/docs/ssh-projects.html +60 -0
  97. package/public/docs/style.css +768 -0
  98. package/public/docs/task-reruns.html +30 -0
  99. package/public/docs/team-collaboration.html +412 -0
  100. package/public/docs/verification.html +22 -0
  101. package/public/docs/vscode.html +53 -0
  102. package/public/docs/worker-permission-verification.html +131 -0
  103. package/public/index.html +17 -0
  104. package/scripts/check-node.mjs +7 -0
  105. package/scripts/codeflow.mjs +55 -0
  106. package/scripts/computer-use.swift +64 -0
  107. package/scripts/pty.py +273 -0
  108. package/src/acp-connections.js +110 -0
  109. package/src/adapters/acp-presets.js +37 -0
  110. package/src/adapters/acp-types.js +0 -0
  111. package/src/adapters/acp.js +328 -0
  112. package/src/adapters/agent-tools.js +28 -0
  113. package/src/adapters/agy-auth.js +67 -0
  114. package/src/adapters/agy-isolation.js +242 -0
  115. package/src/adapters/agy-tools.js +45 -0
  116. package/src/adapters/agy.js +326 -0
  117. package/src/adapters/claude-stream.js +58 -0
  118. package/src/adapters/claude.js +282 -0
  119. package/src/adapters/codex-app-server.js +555 -0
  120. package/src/adapters/codex.js +311 -0
  121. package/src/adapters/errors.js +57 -0
  122. package/src/adapters/index.js +91 -0
  123. package/src/adapters/managed-permissions.js +37 -0
  124. package/src/adapters/model-discovery.js +100 -0
  125. package/src/adapters/process.js +433 -0
  126. package/src/adapters/team-tools.js +103 -0
  127. package/src/adapters/types.js +0 -0
  128. package/src/agent-browser.js +688 -0
  129. package/src/agent-computer.js +88 -0
  130. package/src/agent-container.js +155 -0
  131. package/src/agent-team-definitions.js +131 -0
  132. package/src/agent-tool-client.mjs +79 -0
  133. package/src/agent-tools.js +296 -0
  134. package/src/approvals.js +134 -0
  135. package/src/architecture.js +456 -0
  136. package/src/assets.js +44 -0
  137. package/src/automation.js +901 -0
  138. package/src/browser-files.js +293 -0
  139. package/src/browser-ownership.js +150 -0
  140. package/src/certificate-renewal.js +75 -0
  141. package/src/chat-family.js +25 -0
  142. package/src/chat-handoff.js +87 -0
  143. package/src/checkpoint-review.js +72 -0
  144. package/src/checks.js +303 -0
  145. package/src/code-host-git.js +102 -0
  146. package/src/code-hosts-api.js +99 -0
  147. package/src/code-hosts.js +482 -0
  148. package/src/code-intelligence-worker.mjs +452 -0
  149. package/src/code-intelligence.js +141 -0
  150. package/src/collab/api.js +365 -0
  151. package/src/collab/checkpoints.js +198 -0
  152. package/src/collab/connections.js +139 -0
  153. package/src/collab/host-execution.js +347 -0
  154. package/src/collab/hub-client.js +210 -0
  155. package/src/collab/link-api.js +229 -0
  156. package/src/collab/link.js +595 -0
  157. package/src/collab/model.js +496 -0
  158. package/src/collab/runner.js +1014 -0
  159. package/src/collab/store.js +1452 -0
  160. package/src/collab/terminals.js +361 -0
  161. package/src/collaboration-reviews.js +116 -0
  162. package/src/config.js +48 -0
  163. package/src/context-budget.js +14 -0
  164. package/src/context-inspection.js +204 -0
  165. package/src/context.js +154 -0
  166. package/src/conventions.js +283 -0
  167. package/src/coordinated-api.js +247 -0
  168. package/src/deferred-launch.js +82 -0
  169. package/src/deferred-runs.js +515 -0
  170. package/src/dependency-health.js +35 -0
  171. package/src/diff.js +43 -0
  172. package/src/docs-help.js +316 -0
  173. package/src/doctor.js +232 -0
  174. package/src/documentation-changes.js +20 -0
  175. package/src/engine.js +5258 -0
  176. package/src/env.js +44 -0
  177. package/src/execution-budget.js +8 -0
  178. package/src/experience.js +50 -0
  179. package/src/extensions.js +144 -0
  180. package/src/filesystem-access.js +107 -0
  181. package/src/filesystem-policy.js +238 -0
  182. package/src/filtered-task-limits.js +93 -0
  183. package/src/filtered-tasks-api.js +53 -0
  184. package/src/filtered-tasks.js +576 -0
  185. package/src/frame-policy.js +66 -0
  186. package/src/fs.js +57 -0
  187. package/src/git.js +626 -0
  188. package/src/github-review-threads.js +181 -0
  189. package/src/github.js +538 -0
  190. package/src/http.js +69 -0
  191. package/src/improve-settings.js +38 -0
  192. package/src/improve.js +187 -0
  193. package/src/integrations.js +373 -0
  194. package/src/integrity.js +259 -0
  195. package/src/journey-api.js +77 -0
  196. package/src/journey-replay.js +65 -0
  197. package/src/journey-store.js +97 -0
  198. package/src/journeys.js +60 -0
  199. package/src/json.js +81 -0
  200. package/src/launch-profiles.js +292 -0
  201. package/src/learnings.js +80 -0
  202. package/src/local-app-url.js +19 -0
  203. package/src/log.js +39 -0
  204. package/src/maintenance.js +335 -0
  205. package/src/memory-analysis.js +182 -0
  206. package/src/memory-claims.js +153 -0
  207. package/src/memory-sqlite.js +236 -0
  208. package/src/memory.js +552 -0
  209. package/src/merge-validation.js +58 -0
  210. package/src/model-catalog.js +239 -0
  211. package/src/model-research.js +91 -0
  212. package/src/notes.js +176 -0
  213. package/src/notifications.js +413 -0
  214. package/src/patterns/auto-team-model.js +230 -0
  215. package/src/patterns/auto-team.js +816 -0
  216. package/src/patterns/council.js +199 -0
  217. package/src/patterns/debate.js +188 -0
  218. package/src/patterns/findings.js +141 -0
  219. package/src/patterns/index.js +21 -0
  220. package/src/patterns/loop.js +158 -0
  221. package/src/patterns/pipeline.js +125 -0
  222. package/src/patterns/prompts.js +181 -0
  223. package/src/patterns/race.js +147 -0
  224. package/src/patterns/schemas.js +40 -0
  225. package/src/patterns/solo.js +46 -0
  226. package/src/patterns/supervisor.js +235 -0
  227. package/src/patterns/task-draft.js +29 -0
  228. package/src/patterns/task-review.js +45 -0
  229. package/src/patterns/tdd.js +231 -0
  230. package/src/patterns/team-strategies.js +67 -0
  231. package/src/performance.js +43 -0
  232. package/src/persistence-status.js +35 -0
  233. package/src/phone-sessions.js +96 -0
  234. package/src/preview-overlay.js +392 -0
  235. package/src/preview.js +230 -0
  236. package/src/privacy.js +23 -0
  237. package/src/project-report.js +22 -0
  238. package/src/project-team-budget.js +22 -0
  239. package/src/project-team-model.js +225 -0
  240. package/src/project-team-policy.js +42 -0
  241. package/src/project-team-store.js +234 -0
  242. package/src/project-team-usage.js +24 -0
  243. package/src/project-teams-api.js +43 -0
  244. package/src/project-teams.js +644 -0
  245. package/src/projects.js +290 -0
  246. package/src/provider-eligibility.js +9 -0
  247. package/src/readiness.js +98 -0
  248. package/src/remote-tls.js +66 -0
  249. package/src/remote-workers/bundles.js +198 -0
  250. package/src/remote-workers/client.js +332 -0
  251. package/src/remote-workers/durability.js +37 -0
  252. package/src/remote-workers/protocol.js +68 -0
  253. package/src/remote-workers/stdio.js +138 -0
  254. package/src/remote-workers/worker.js +304 -0
  255. package/src/remote.js +204 -0
  256. package/src/repo-config.js +201 -0
  257. package/src/repo-coordination.js +725 -0
  258. package/src/repo-tree.js +106 -0
  259. package/src/repository-identity.js +13 -0
  260. package/src/retention-policy.js +466 -0
  261. package/src/review-inbox.js +38 -0
  262. package/src/routing.js +49 -0
  263. package/src/run-analysis.js +111 -0
  264. package/src/run-cold-store.js +231 -0
  265. package/src/run-environment.js +15 -0
  266. package/src/run-history.js +91 -0
  267. package/src/run-log.js +160 -0
  268. package/src/run-permissions.js +111 -0
  269. package/src/run-projection.js +77 -0
  270. package/src/run-recovery.js +53 -0
  271. package/src/run-status.js +56 -0
  272. package/src/serve.js +138 -0
  273. package/src/server.js +2871 -0
  274. package/src/shared-access.js +103 -0
  275. package/src/shared-accounts.js +381 -0
  276. package/src/shared-api.js +239 -0
  277. package/src/shell.js +346 -0
  278. package/src/ship.js +344 -0
  279. package/src/slots.js +74 -0
  280. package/src/snapshot.js +388 -0
  281. package/src/source-context.js +17 -0
  282. package/src/sse-writer.js +70 -0
  283. package/src/ssh-projects/bootstrap.mjs +95 -0
  284. package/src/ssh-projects/config.js +45 -0
  285. package/src/ssh-projects/gateway.js +143 -0
  286. package/src/ssh-projects/manager.js +320 -0
  287. package/src/ssh-projects/team-autostart.mjs +93 -0
  288. package/src/ssh-projects/team-remove.mjs +69 -0
  289. package/src/ssh-projects/team-status.mjs +39 -0
  290. package/src/ssh-projects/transport.js +133 -0
  291. package/src/stats.js +139 -0
  292. package/src/store.js +544 -0
  293. package/src/stream.js +91 -0
  294. package/src/sweeps.js +241 -0
  295. package/src/tailscale.js +101 -0
  296. package/src/task-draft.js +23 -0
  297. package/src/task-team.js +164 -0
  298. package/src/team-evaluation.js +243 -0
  299. package/src/team-mailbox.js +160 -0
  300. package/src/team-memory.js +84 -0
  301. package/src/team-rerun-graph.js +15 -0
  302. package/src/team-reruns.js +130 -0
  303. package/src/team-scheduler.js +121 -0
  304. package/src/team-steering.js +21 -0
  305. package/src/team-template-store.js +98 -0
  306. package/src/team-templates.js +117 -0
  307. package/src/team-tool-client.mjs +79 -0
  308. package/src/team-tools.js +235 -0
  309. package/src/teams.js +0 -0
  310. package/src/templates.js +62 -0
  311. package/src/transcript.js +134 -0
  312. package/src/verification-integrity.js +27 -0
  313. package/src/verification.js +183 -0
  314. package/src/watch.js +195 -0
  315. package/src/work-queue.js +47 -0
  316. package/src/workflow-control.js +83 -0
  317. package/src/workspace-api.js +207 -0
  318. package/src/workspace-changes.js +61 -0
  319. package/src/workspace.js +146 -0
@@ -0,0 +1,8 @@
1
+ import{b as Ne}from"./chunk-7FUHKF2M.js";import{b as Ie,d as se}from"./chunk-5SARP5MU.js";import{Ga as Re,ma as Pe,tc as Ee}from"./chunk-J4VYS3KV.js";import{y as Ae}from"./chunk-CGOZQMEZ.js";import"./chunk-4D5IENEB.js";import"./chunk-TEJVYIKC.js";import{G as $,ba as je,d as j,da as e,h as r,i as G,k as te,x as ae,y as Te}from"./chunk-63YLZ3PR.js";function $e(y,b){let x=y.replace(/[\\/]+$/,"").split(/[\\/]/).pop()||"Repository",n=x.toLowerCase().replace(/[^a-z0-9-]+/g,"-").replace(/^-+|-+$/g,"")||"repo";/^[a-z]/.test(n)||(n=`repo-${n}`),n=n.slice(0,64).replace(/-+$/,"");let P=n;for(let i=2;b.includes(P);i++){let c=`-${i}`;P=n.slice(0,64-c.length).replace(/-+$/,"")+c}return{key:P,label:x.slice(0,80)}}var xe=["Project","Repositories","Secure access","Teammates","Share"],oe=()=>({key:"app",label:"App",defaultBranch:"main"}),Be=y=>y==="contributor"||y==="maintainer";function Qe({onClose:y}){let[b,x]=r([]),[n,P]=r(Te??"local"),[i,c]=r("local"),[d,l]=r(!1),[g,z]=r(!1),[H,v]=r(""),[S,k]=r("4318"),[B,R]=r(!1),[h,f]=r(null),[E,u]=r(""),[U,m]=r(""),A=b.find(a=>a.id===n)?.name??"Remote server",I=`/api/ssh-hosts/${n}/team-server`,M=async()=>{try{x((await $("/api/ssh-hosts")).hosts),v("")}catch(a){v(a.message)}};G(()=>{M()},[]);let L=async(a="status")=>{u("");try{f(await $(I+"/autostart",a==="status"?{}:{method:"POST",body:JSON.stringify({action:a})}))}catch(w){f(null),u(w.message)}},q=async a=>{if(!(d||g)){l(!0);try{await L(a)}finally{l(!1)}}},Y=async()=>{if(!d){l(!0),v("");try{b.find(w=>w.id===n)?.state!=="connected"&&(await $(`/api/ssh-hosts/${n}/connect`,{method:"POST",body:"{}"}),await M());let a=await $(I,{method:"POST",body:JSON.stringify({remotePort:Number(S)})});k(String(a.remotePort)),R(!0),m(a.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."),c(n),await L()}catch(a){v(a.message)}finally{l(!1)}}},_=async()=>{if(!(d||!await Ee(`Stop the team server on ${A}? 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),v("");try{await $(I,{method:"DELETE"}),c(""),R(!1)}catch(a){v(a.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||g,value:n,onChange:a=>{P(a.currentTarget.value),c("local"),R(!1),f(null),u(""),k("4318"),v("")},children:[e("option",{value:"local",children:"This computer"}),b.map(a=>e("option",{value:a.id,children:[a.name,a.state!=="connected"?" \xB7 disconnected":""]},a.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||g,onClick:()=>void M(),children:"Refresh servers"}),n!=="local"?e(j,{children:[e("p",{children:["Host the team on ",A,". 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."}),i!==n?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:S,onInput:a=>k(a.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||!b.some(a=>a.id===n)||!Number.isInteger(Number(S))||Number(S)<1||Number(S)>65535,onClick:()=>void Y(),children:d?"Setting up server\u2026":b.find(a=>a.id===n)?.state==="connected"?"Open or start team server":"Connect and set up on this server"}),e("button",{class:"btn",disabled:d,onClick:y,children:"Close setup"})]}):e("p",{role:"status",children:["Connected to the team server on ",A," \xB7 port ",S]}),B?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:h?.message??(E?"Automatic startup could not be checked.":"Checking automatic startup\u2026")}),h?.command?e("p",{children:e("code",{children:h.command})}):null,E?e("p",{class:"msg err",role:"alert",children:E}):null,e("div",{class:"settings-actions",children:[e("button",{class:"btn",disabled:d||g,onClick:()=>void q("status"),children:"Check startup status"}),h?.supported&&h.unitEnabled&&!h.enabled?e("button",{class:"btn",disabled:d||g,onClick:()=>void q("disable"),children:"Disable automatic startup"}):null,h?.supported?e("button",{class:"btn",disabled:d||g,onClick:()=>void q(h.enabled?"disable":"enable"),children:h.enabled?"Disable automatic startup":"Enable automatic startup"}):null]})]}):null,B?e("button",{class:"btn small",disabled:d||g,onClick:()=>void _(),children:"Stop team server"}):null]}):null,H?e("p",{class:"msg err",role:"alert",children:H}):null]}),U&&B?e("p",{class:"help",role:"status",children:U}):null,i===n?e(De,{onClose:y,prefix:n==="local"?"":I,workspacePrefix:n==="local"?"":`/computer/${encodeURIComponent(n)}`,hostName:n==="local"?"this computer":A,onBusy:z},n):null]})}function De({onClose:y,prefix:b,workspacePrefix:x,hostName:n,onBusy:P}){let i=(t,s,o="POST")=>$(b+(t.startsWith("/api/team/")?`${t}${t.includes("?")?"&":"?"}teamConnection=local`:t),s?{method:o,body:JSON.stringify(s)}:{}),[c,d]=r(0),[l,g]=r(!1),[z,H]=r(""),v=te(!1),S=te(null),[k,B]=r([]),[R,h]=r(null),[f,E]=r(null),[u,U]=r(null),[m,A]=r(""),[I,M]=r(""),[L,q]=r(b?"":Pe.value),[Y,_]=r(""),[a,w]=r([oe()]),[J,re]=r(""),[ne,le]=r(""),[ie,ce]=r(""),[ue,Q]=r(""),[X,pe]=r("contributor"),[de,me]=r(""),[N,be]=r("tailscale"),C=k.find(t=>t.id===m),O=f?.users.filter(t=>t.enabled&&t.roles[m])??[],T=u?.enabled&&u.lan&&!u.lanError?Ae(u):void 0,F=R?.projects.find(t=>t.id===m)?.repositories??[],[Ue,He]=r([]),[he,fe]=r(""),[ve,ye]=r(!1),ge=[...new Set([...k,...Ue].flatMap(t=>t.repos))],we=async()=>{ye(!0),fe("");try{He(await $(`${x}/api/projects`))}catch(t){fe(`Could not load repositories from ${n}: ${t.message}`)}finally{ye(!1)}};G(()=>{we()},[]);let Le=(t,s)=>{w(o=>o.map((p,D)=>D!==t?p:s?{...p,...$e(s,o.filter((K,Fe)=>Fe!==t).map(K=>K.key)),sourcePath:s,remote:void 0}:{...p,sourcePath:void 0}))},Z=!!C&&F.length>0&&!!T,ee=Z&&O.some(t=>Be(t.roles[m])),V=async t=>{if(v.current)return!1;v.current=!0,g(!0),P(!0),H("");try{return await t(),!0}catch(s){return H(s.message),!1}finally{v.current=!1,g(!1),P(!1)}},Se=()=>V(async()=>{let[t,s,o,p]=await Promise.all([i("/api/projects"),i("/api/team/board"),i("/api/accounts"),i("/api/remote")]);B(t),h(s),E(o),U(p),_(s.me.displayName),be(p.enabled&&p.lan?p.transport:"tailscale"),!m&&t.length&&A(t[0].id)});G(()=>{Se()},[]),G(()=>{S.current?.focus(),me("")},[c]);let W=async()=>{await V(async()=>{if(c===0){if(!Y.trim())throw new Error("Enter your name as teammates should see it.");let t=C;if(!t){if(!I.trim())throw new Error("Enter a project name.");t=await i("/api/projects",{name:I.trim(),repos:L.trim()?[L.trim()]:[]}),B(p=>[...p,t]),A(t.id),b||Re()}await i("/api/team/profile",{displayName:Y.trim()},"PUT");let s=await i("/api/team/board");h(s);let o=s.projects.find(p=>p.id===t.id)?.repositories;w(o?.length?o.map(p=>({...p})):[oe()])}if(c===1){if(!a.length||a.some(t=>!/^[a-z][a-z0-9-]{0,63}$/.test(t.key.trim()))||new Set(a.map(t=>t.key.trim())).size!==a.length)throw new Error("Add at least one repository, with a unique key using lowercase letters, numbers and dashes.");try{await i(`/api/team/projects/${encodeURIComponent(m)}/repositories`,{revision:R.revision,repositories:a.map(t=>({key:t.key.trim(),label:t.label.trim()||t.key.trim(),...t.remote?.trim()?{remote:t.remote.trim()}:{},...t.defaultBranch?.trim()?{defaultBranch:t.defaultBranch.trim()}:{}}))},"PUT")}catch(t){throw t instanceof ae&&t.status===409&&h(await i("/api/team/board")),t}h(await i("/api/team/board"))}if(c>=2){let[t,s,o,p]=await Promise.all([i("/api/remote?refresh=1"),i("/api/accounts"),i("/api/team/board"),i("/api/projects")]);U(t),E(s),h(o),B(p)}d(Math.min(c+1,4))})},ke=(t,s="/api/remote")=>V(async()=>{U(await i(s,t))}),Oe=async()=>{await V(async()=>{if(f)try{let t=f.users.find(o=>o.id===J);if(J&&(!t||!t.enabled))throw new Error("Choose an enabled account.");let s=t?await i(`/api/accounts/${encodeURIComponent(t.id)}`,{revision:f.revision,roles:{...t.roles,[m]:X}},"PUT"):await i("/api/accounts",{revision:f.revision,username:ne.trim(),displayName:ie.trim(),password:ue,roles:{[m]:X}});E(s),re(""),le(""),ce(""),me(t?"Project access saved. Existing credentials still apply.":"Teammate saved. Share their initial password privately.")}catch(t){throw t instanceof ae&&t.status===409&&E(await i("/api/accounts")),t}finally{Q("")}})},Ce=T&&C?`Join ${C.name} in Code Flow
2
+ Team server: ${T}
3
+
4
+ 1. ${u?.transport==="tailscale"?"Connect your computer to our Tailscale network.":"Make sure your computer can reach the team server over HTTPS."}
5
+ 2. Open your own Code Flow \u2192 Settings \u2192 Connections \u2192 Share access \u2192 Join a team.
6
+ 3. Enter the server address and the account credentials shared with you separately.
7
+ 4. Map these repository keys to your local clones: ${F.map(t=>t.key).join(", ")}.
8
+ 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:y,children:"Close setup"})]}),e("p",{class:"help",children:["Edit the team server on ",n,". Choose a section below. Saved settings stay in place when you close setup."]}),e("ol",{class:"team-setup-steps","aria-label":"Setup progress",children:xe.map((t,s)=>e("li",{"aria-current":c===s?"step":void 0,children:e("button",{type:"button",disabled:l||!R||s>0&&!C,"aria-current":c===s?"step":void 0,onClick:()=>{s===1&&c!==1&&w(F.length?F.map(o=>({...o})):[oe()]),d(s)},children:[e("span",{children:s+1}),t]})},t))}),e("h4",{ref:S,tabIndex:-1,children:["Step ",c+1," of 5: ",xe[c]]}),!R||!f||!u?e("p",{class:"help",children:[z?"Setup could not load your current settings.":"Loading your current settings\u2026",e("button",{class:"btn small",disabled:l,onClick:()=>void Se(),children:"Retry loading settings"})]}):e(j,{children:[c===0?e("form",{onSubmit:t=>{t.preventDefault(),W()},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:Y,onInput:t=>_(t.currentTarget.value)})]}),e("label",{children:["Project",e("select",{"aria-label":"Project",class:"field",value:m,onChange:t=>A(t.currentTarget.value),children:[e("option",{value:"",children:"Create a new project\u2026"}),k.map(t=>e("option",{value:t.id,children:t.name},t.id))]})]}),C?e("p",{class:"help",children:["Use ",C.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:I,onInput:t=>M(t.currentTarget.value)})]}),e("label",{children:["Local repository folder (optional)",e("input",{class:"field mono",value:L,placeholder:"/path/to/repository",onInput:t=>q(t.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,c===1?e("form",{onSubmit:t=>{t.preventDefault(),W()},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:ve,onClick:()=>void we(),children:ve?"Loading repositories\u2026":"Refresh repositories"})}),he?e("p",{class:"msg err",role:"alert",children:he}):null,a.map((t,s)=>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 ${s+1}`,value:t.sourcePath??"",onChange:o=>Le(s,o.currentTarget.value),children:[e("option",{value:"",children:"Enter repository details manually"}),ge.map(o=>e("option",{value:o,disabled:a.some((p,D)=>D!==s&&p.sourcePath===o),children:o},o))]})]}),e("p",{class:"help team-setup-repo-source",children:[ge.length?`Choose a repository from the existing projects on ${n}${x?", 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 ${n}. 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(o=>e("label",{children:[{key:"Repository key",label:"Repository label",remote:"Git URL (optional)",defaultBranch:"Default branch"}[o],e("input",{class:"field",required:o==="key",maxLength:o==="key"?64:o==="label"?80:o==="remote"?300:100,pattern:o==="key"?"[a-z][a-z0-9-]{0,63}":void 0,value:t[o]??"",onInput:p=>w(a.map((D,K)=>K===s?{...D,[o]:p.currentTarget.value}:D))})]},o)),e("button",{class:"btn small",type:"button",onClick:()=>w(a.filter((o,p)=>p!==s)),children:["Remove repository ",s+1]})]},s)),e("div",{class:"settings-actions",children:[e("button",{class:"btn",type:"button",disabled:a.length>=50,onClick:()=>w([...a,{key:"",label:"",defaultBranch:"main"}]),children:"Add repository"}),e("button",{class:"btn primary",type:"submit",children:"Save repositories and continue"})]})]})]}):null,c===2?e("div",{class:"team-setup-fields",children:[e("p",{children:["Teammates need an encrypted address they can reach. Keep ",n," running with Code Flow active."]}),e("label",{children:["Connection method",e("select",{class:"field","aria-label":"Connection method",disabled:l,value:N,onChange:t=>be(t.currentTarget.value),children:[e("option",{value:"tailscale",children:"Tailscale \xB7 recommended"}),e("option",{value:"lan",children:"Other HTTPS network"})]})]}),N==="tailscale"?e(j,{children:[e("p",{class:"help",children:[u.tailscale.message," ",u.tailscale.dnsName??""]}),u.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 V(async()=>U(await i("/api/remote?refresh=1"))),children:"Check connection"}),!u.enabled||!u.lan||u.transport!==N?e("button",{class:"btn primary",disabled:l||N==="tailscale"&&u.tailscale.state!=="connected",onClick:()=>void ke({enabled:!0,lan:!0,transport:N}),children:N==="tailscale"?"Enable team access over Tailscale":"Enable team access on network"}):null]}),u.enabled&&u.lan&&u.transport===N?e(Ne,{info:u,busy:l,save:t=>ke(t,"/api/remote/tls")},N):null,u.lanError?e("p",{class:"msg err",role:"alert",children:u.lanError}):null,T?e("p",{role:"status",children:["Secure team address: ",e("code",{children:T})]}):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 W(),children:T?"Continue to teammates":"Set up access later"})]}):null,c===3?e("div",{children:[e(se,{projects:k,projectId:m,prefix:b,address:T}),e("h4",{children:"Or manage accounts directly"}),e("p",{children:["Add accounts for people working on ",C?.name,". Contributor lets them run tasks on their computers; Maintainer also lets them manage the project board."]}),O.length?e("ul",{children:O.map(t=>e("li",{children:[t.displayName," (",t.username,") \xB7 ",t.roles[m]]},t.id))}):e("p",{class:"help",children:"No teammates have access to this project yet."}),e("form",{onSubmit:t=>{t.preventDefault(),Oe()},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:J,onChange:t=>{let s=t.currentTarget.value;re(s),Q(""),pe(f.users.find(o=>o.id===s)?.roles[m]??"contributor")},children:[e("option",{value:"",children:"Create a new account\u2026"}),f.users.filter(t=>t.enabled).map(t=>e("option",{value:t.id,children:[t.displayName," (",t.username,")"]},t.id))]})]}),J?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:ne,autoComplete:"off",onInput:t=>le(t.currentTarget.value)})]}),e("label",{children:["Display name",e("input",{class:"field",required:!0,maxLength:120,value:ie,onInput:t=>ce(t.currentTarget.value)})]}),e("label",{children:["Initial password",e("input",{class:"field",type:"password",required:!0,minLength:15,autoComplete:"new-password",value:ue,onInput:t=>Q(t.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:X,onChange:t=>pe(t.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:J?"Save project access":"Add teammate"})]})}),de?e("p",{role:"status",children:de}):null,e("button",{class:"btn primary",disabled:l,onClick:()=>void W(),children:O.length?"Review setup":"Add teammates later"})]}):null,c===4?e("div",{class:"team-setup-fields",children:[e("h4",{children:ee?"Ready to share with your team":Z?"Ready to invite your team":"Your setup is saved, with steps still to finish"}),e("ul",{children:[e("li",{children:["Project: ",C?.name??"Unavailable \u2014 choose a project"]}),e("li",{children:["Repositories: ",F.length?F.map(t=>t.key).join(", "):"Add a repository key"]}),e("li",{children:["Secure access: ",T??"Finish secure access setup"]}),e("li",{children:["Teammates: ",O.length," with access",O.some(t=>Be(t.roles[m]))?" \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"})]}),Z?e(se,{projects:k,projectId:m,prefix:b,address:T}):null,ee?e(j,{children:[e("label",{children:["Connection instructions",e("textarea",{class:"field",readOnly:!0,rows:8,value:Ce})]}),e("button",{class:"btn primary",onClick:()=>void je(Ce,"Connection instructions copied"),children:"Copy connection instructions"}),e("p",{class:"help",children:"New teammates can use an invitation above to choose their own password. Existing accounts can use these connection instructions. 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 W(),children:"Check setup again"}),e("button",{class:"btn primary",disabled:l,onClick:()=>{if(b)return y();let t=new URL(location.href);t.hash="#/team",history.replaceState(history.state,"",t.href),Ie("local")},children:b?"Finish setup":ee?"Open team board":"Finish for now"})]})]}):null,c>0&&c<4?e("button",{class:"btn ghost",disabled:l,onClick:()=>{H(""),d(c-1)},children:"Back"}):null]}),z?e("p",{class:"msg err",role:"alert",children:z}):null]})}export{Qe as TeamServerWizard};