@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
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Midhun Xavier
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,123 @@
1
- # Temporary Holding Version
1
+ <p align="center">
2
+ <img src="ui/brand/vibesboard-mark.png" alt="" width="64" height="64">
3
+ </p>
4
+ <h1 align="center">code-flow</h1>
5
+ <p align="center">Your coding agents. One workspace.</p>
6
+ <p align="center">
7
+ Bring Claude Code, Codex and Antigravity together to plan, build and review.<br>
8
+ Use your installed CLIs and existing logins, with work you can inspect before shipping.
9
+ </p>
10
+ <p align="center">
11
+ <a href="#quickstart">Quickstart</a> ·
12
+ <a href="https://midhunxavier.github.io/code-flow/">Documentation</a> ·
13
+ <a href="docs/patterns.md">Workflows</a> ·
14
+ <a href="docs/security.md">Security</a>
15
+ </p>
2
16
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
17
+ <picture>
18
+ <source media="(prefers-color-scheme: dark)" srcset="docs/images/run-dark.png">
19
+ <img src="docs/images/run-light.png" alt="Code Flow run with the task, agent activity, verification evidence and review actions. Captured from the local app using demo agents." width="100%">
20
+ </picture>
21
+
22
+ *Screenshots show the current local app with deterministic demo agents. They do not represent real provider output or a production verification result.*
23
+
24
+ ## Quickstart
25
+
26
+ The preview adds a one-command launcher: **`npx @midhunxavier/code-flow@preview`**. It starts Code Flow locally and opens your browser. npm and download commands become available when the preview is published; see [installation options](docs/installation.md) for macOS, Linux, Windows through WSL2, npm, Homebrew and the macOS DMG. [Preview downloads](https://github.com/midhunxavier/code-flow/releases).
27
+
28
+ To run from source today:
29
+
30
+ Install **Node.js 22.13+**, **Git 2.38+**, and at least one supported CLI: `claude`, `codex` or `agy`. Sign in through the CLI before starting. Additional [ACP agents](docs/acp-agents.md) can be connected in Settings.
31
+
32
+ ```bash
33
+ git clone https://github.com/midhunxavier/code-flow.git
34
+ cd code-flow
35
+ npm ci
36
+ npm start
37
+ ```
38
+
39
+ Open [localhost:4317](http://localhost:4317), or use the owner link printed in the terminal if sign-in is required.
40
+
41
+ 1. Choose a repository and describe the outcome you want.
42
+ 2. Pick a workflow and its agents. Set a check command such as `npm test`.
43
+ 3. Select **Start run**. Review any plan or question that needs your input.
44
+ 4. Inspect the result and its evidence, then review, merge or open a pull request.
45
+
46
+ Results live on branches such as `codeflow/<run>/build` in separate Git worktrees. The [first-run guide](docs/getting-started.md) explains context, permissions and model settings.
47
+
48
+ **Inbox** and **Scheduling** are in the sidebar. **New run → Template library** groups task starters and saved configurations. Open **Repository tools** from a project; use **Settings → Connections** for remote work and sharing.
49
+
50
+ ## A workspace for the whole task
51
+
52
+ | You want to… | Use… |
53
+ | --- | --- |
54
+ | Build a feature with an independent review | [Plan → Build → Review](docs/patterns.md) |
55
+ | Let a coordinator propose a team and task graph | [Auto team](docs/auto-team.md), with plan approval and bounded execution |
56
+ | Fix failing tests, compare solutions or explore a design | [Loop, race, test-first and debate workflows](docs/patterns.md) |
57
+ | Inspect files, changes, terminals and app previews | The [run workspace and side panel](docs/runs.md) |
58
+ | See what needs a decision across projects | The [review inbox](docs/review-inbox.md) |
59
+ | Run scheduled work or revisit it from another device | [Automations and remote access](docs/automations.md) |
60
+ | Work with teammates or a remote machine | [Team collaboration](docs/team-collaboration.md) and [SSH projects](docs/ssh-projects.md) |
61
+
62
+ Code Flow shows checks, independent review and fail-to-pass evidence separately. Finished work can still be unverified; the [verification guide](docs/verification.md) explains the distinction. Publishing remains an explicit workflow action.
63
+
64
+ ## Choose how the agents work
65
+
66
+ <picture>
67
+ <source media="(prefers-color-scheme: dark)" srcset="docs/images/composer-dark.png">
68
+ <img src="docs/images/composer-light.png" alt="Code Flow composer with a task, workflow selection, agents and run options, using demo data." width="100%">
69
+ </picture>
70
+
71
+ | Workflow | Flow | Good for |
72
+ | --- | --- | --- |
73
+ | **Plan → Build → Review** | Plan, implement, review, repair | Features and bug fixes |
74
+ | **Loop until green** | Change, check, repeat | A failing test or build |
75
+ | **Best-of-N race** | Parallel candidates, blind judging | Exploring alternative implementations |
76
+ | **Debate → Synthesize → Build** | Proposals, critique, synthesis, optional implementation | Design decisions |
77
+ | **Supervisor → Workers** | Subtasks, separate branches, integration | Work that splits cleanly |
78
+ | **Test-first** | Failing tests, implementation, verification | Precisely specified behavior |
79
+ | **Review council** | Independent reviews, evidence, ranked findings | Reviewing a change |
80
+ | **Auto team** | Proposed team, dependency graph, bounded adaptation | Delegating workflow design |
81
+
82
+ Assign providers, models and effort per role. Auto team availability and its default selection follow the current rollout state; see [Auto team](docs/auto-team.md). [Project missions](docs/project-teams.md) are a separate preview for recurring repository work.
83
+
84
+ ## Your CLIs, your machine
85
+
86
+ | Provider | How Code Flow runs it | Authentication |
87
+ | --- | --- | --- |
88
+ | Claude Code | `claude -p` | The CLI's own login |
89
+ | Codex | `codex app-server` or `codex exec` | `codex login` |
90
+ | Antigravity | `agy -p` | The CLI's own login |
91
+ | ACP connections | Saved executable and ACP arguments | The connected CLI's authentication |
92
+
93
+ Code Flow delegates authentication to the CLIs. Provider access, model availability and usage limits depend on your account and CLI configuration. It does not extract or reuse OAuth tokens. Repository checks execute code; choose suitable permissions and isolation for the repository. Read the [security and execution boundaries](docs/security.md).
94
+
95
+ ## Documentation, wherever you work
96
+
97
+ Open **Application menu → Help & documentation** or find it in the command palette. The bundled docs at [localhost:4317/docs/](http://localhost:4317/docs/) include search, page navigation and an **Ask code-flow** chat side panel that answers using your installed CLI and the guides. [How local help works](docs/help.md).
98
+
99
+ The same docs can be hosted on GitHub Pages, with the local app's typography, colors and light/dark themes. The static site provides search and reading with no companion controls. CLI chat runs in the local app, keeping the conversation while you browse guides.
100
+
101
+ ```bash
102
+ npm run docs:preview # build and preview the static site at 127.0.0.1:4319
103
+ npm run build:docs # produces dist/docs for GitHub Pages
104
+ ```
105
+
106
+ See [publishing and maintaining the docs](docs/documentation.md) for repository setup, screenshots and the deployment workflow. The complete [documentation library](docs/README.md) covers configuration, project memory, remote workers, shared accounts, integrations, APIs and maintenance.
107
+
108
+ ## Development
109
+
110
+ ```bash
111
+ npm run dev # localhost:4318, fake agents, no provider quota
112
+ npm run typecheck
113
+ npm test
114
+ npm run test:e2e # browser acceptance tests; requires Chrome
115
+ ```
116
+
117
+ To prepare the npm preview and macOS DMG, see the [release guide](docs/releasing.md).
118
+
119
+ The [development guide](docs/architecture.md) covers the source layout, adapter and workflow contracts, and tests. Engineering plans and evaluation records are grouped separately in the docs library.
120
+
121
+ ## License
122
+
123
+ [MIT](LICENSE). Bundled Inter fonts are distributed under the [SIL Open Font License 1.1](ui/fonts/OFL-1.1.txt).
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env node
2
+ import "../scripts/check-node.mjs";
3
+ import { launch } from "./launcher.mjs";
4
+
5
+ launch().catch((error) => {
6
+ console.error(`Code Flow: ${error.message}`);
7
+ process.exitCode = 1;
8
+ });
@@ -0,0 +1,127 @@
1
+ import { execFile, spawn } from "node:child_process";
2
+ import { readFile, access } from "node:fs/promises";
3
+ import { homedir, release } from "node:os";
4
+ import { resolve } from "node:path";
5
+ import { fileURLToPath } from "node:url";
6
+ import { promisify } from "node:util";
7
+
8
+ const root = new URL("../", import.meta.url);
9
+ const usage = `Code Flow preview — your coding agents, one workspace.
10
+
11
+ Usage: codeflow [start] [--port NUMBER] [--no-open]
12
+ codeflow client <command> [arguments]
13
+ codeflow --version
14
+
15
+ Starts a local server and opens your browser. Keep this terminal open;
16
+ press Ctrl+C to stop. Settings and history live in ~/.codeflow.
17
+
18
+ --port NUMBER Use a different local port (default: PORT or 4317)
19
+ --no-open Print the sign-in link without opening a browser
20
+ -h, --help Show this help
21
+ -v, --version Show the installed version
22
+
23
+ Requires Node.js 22.13+, Git 2.38+, and a signed-in agent CLI.
24
+ Windows: run inside WSL2 with your repository and CLIs installed there.
25
+ Set CODEFLOW_HOME to use a separate data directory.
26
+ `;
27
+
28
+ export function parseOptions(args, env = process.env) {
29
+ const options = { open: true, port: env.PORT || "4317" };
30
+ const rest = args[0] === "start" ? args.slice(1) : [...args];
31
+ for (let i = 0; i < rest.length; i++) {
32
+ if (rest[i] === "--no-open") options.open = false;
33
+ else if (rest[i] === "--port") options.port = rest[++i];
34
+ else throw new Error(`Unknown option: ${rest[i]}. Run codeflow --help.`);
35
+ }
36
+ if (!/^\d+$/.test(options.port ?? "") || Number(options.port) < 1 || Number(options.port) > 65534)
37
+ throw new Error("Choose an integer port from 1 to 65534 with --port.");
38
+ return { ...options, port: String(Number(options.port)) };
39
+ }
40
+
41
+ export function browserCommand(url, platform = process.platform, wsl = /microsoft/i.test(release())) {
42
+ const parsed = new URL(url);
43
+ if (parsed.protocol !== "http:" || parsed.hostname !== "localhost" || parsed.username || parsed.password)
44
+ throw new Error("The browser link must be a local Code Flow HTTP URL.");
45
+ if (platform === "darwin") return ["open", [url]];
46
+ if (platform === "linux" && wsl) {
47
+ // Encoded PowerShell avoids cmd.exe/shell interpretation of the owner link.
48
+ const command = `Start-Process -FilePath '${url.replaceAll("'", "''")}'`;
49
+ return ["powershell.exe", ["-NoProfile", "-NonInteractive", "-EncodedCommand", Buffer.from(command, "utf16le").toString("base64")]];
50
+ }
51
+ return ["xdg-open", [url]];
52
+ }
53
+
54
+ export async function openBrowser(url) {
55
+ const [command, args] = browserCommand(url);
56
+ await promisify(execFile)(command, args, { timeout: 10_000, windowsHide: true });
57
+ }
58
+
59
+ export async function launch(args = process.argv.slice(2)) {
60
+ if (args.length === 1 && ["-h", "--help", "help"].includes(args[0])) {
61
+ console.log(usage);
62
+ return;
63
+ }
64
+ if (args.length === 1 && ["-v", "--version"].includes(args[0])) {
65
+ console.log(JSON.parse(await readFile(new URL("package.json", root), "utf8")).version);
66
+ return;
67
+ }
68
+ if (process.platform === "win32") throw new Error("This preview runs on macOS and Linux. On Windows, use WSL2 and install Node, Git and your agent CLIs inside WSL.");
69
+ if (args[0] === "client") {
70
+ const client = spawn(process.execPath, [fileURLToPath(new URL("scripts/codeflow.mjs", root)), ...args.slice(1)], { stdio: "inherit" });
71
+ await supervise(client);
72
+ return;
73
+ }
74
+ const options = parseOptions(args);
75
+ const server = fileURLToPath(new URL("src/server.js", root));
76
+ await access(server).catch(() => { throw new Error("The release files are missing. From a source checkout, run npm run package:npm, then node dist/npm/bin/codeflow.mjs."); });
77
+ const child = spawn(process.execPath, [server], {
78
+ cwd: homedir(),
79
+ env: { ...process.env, ...(process.env.CODEFLOW_HOME ? { CODEFLOW_HOME: resolve(process.env.CODEFLOW_HOME) } : {}), PORT: options.port, CODEFLOW_LAUNCHER: "1" },
80
+ stdio: ["inherit", "inherit", "inherit", "ipc"],
81
+ });
82
+ let announced = false;
83
+ child.on("message", (message) => {
84
+ if (announced || message?.type !== "codeflow-ready" || typeof message.url !== "string") return;
85
+ announced = true;
86
+ if (process.env.CODEFLOW_DESKTOP === "1") console.log(`CODEFLOW_READY ${JSON.stringify({ url: message.url })}`);
87
+ if (options.open) void openBrowser(message.url).catch(() => {
88
+ console.error("Could not open a browser automatically. Open the sign-in link printed above.");
89
+ });
90
+ });
91
+ console.log("Starting Code Flow preview… Press Ctrl+C to stop.");
92
+ await supervise(child, process.env.CODEFLOW_DESKTOP === "1");
93
+ }
94
+
95
+ async function supervise(child, watchParent = false) {
96
+ const signals = ["SIGINT", "SIGTERM", "SIGHUP"];
97
+ let stopping = false;
98
+ const stop = (signal) => {
99
+ if (stopping) return;
100
+ stopping = true;
101
+ child.kill(signal);
102
+ };
103
+ const handlers = signals.map((signal) => {
104
+ const handler = () => stop(signal);
105
+ process.on(signal, handler);
106
+ return [signal, handler];
107
+ });
108
+ const disconnected = () => stop("SIGTERM");
109
+ process.once("disconnect", disconnected);
110
+ const parentPid = process.ppid;
111
+ const parentWatch = watchParent ? setInterval(() => {
112
+ if (process.ppid !== parentPid) stop("SIGTERM");
113
+ }, 1000).unref() : undefined;
114
+ try {
115
+ await new Promise((resolve, reject) => {
116
+ child.once("error", reject);
117
+ child.once("exit", (code, signal) => {
118
+ process.exitCode = code ?? (stopping ? 0 : signal === "SIGINT" ? 130 : 1);
119
+ resolve();
120
+ });
121
+ });
122
+ } finally {
123
+ clearInterval(parentWatch);
124
+ for (const [signal, handler] of handlers) process.off(signal, handler);
125
+ process.off("disconnect", disconnected);
126
+ }
127
+ }