duo-agents 0.0.0-stage → 1.19.4

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 (230) hide show
  1. package/CORE_VERSION +1 -0
  2. package/LICENSE +21 -0
  3. package/README.md +138 -2
  4. package/VERSION +1 -0
  5. package/bin/__pycache__/duocpython-310.pyc +0 -0
  6. package/bin/__pycache__/duocpython-313.pyc +0 -0
  7. package/bin/duo +486 -0
  8. package/engine/__init__.py +1 -0
  9. package/engine/__main__.py +8 -0
  10. package/engine/__pycache__/__init__.cpython-310.pyc +0 -0
  11. package/engine/__pycache__/__init__.cpython-313.pyc +0 -0
  12. package/engine/__pycache__/__main__.cpython-310.pyc +0 -0
  13. package/engine/__pycache__/__main__.cpython-313.pyc +0 -0
  14. package/engine/__pycache__/active_runtime.cpython-313.pyc +0 -0
  15. package/engine/__pycache__/agent_failures.cpython-313.pyc +0 -0
  16. package/engine/__pycache__/agents.cpython-310.pyc +0 -0
  17. package/engine/__pycache__/agents.cpython-313.pyc +0 -0
  18. package/engine/__pycache__/antigravity_models.cpython-313.pyc +0 -0
  19. package/engine/__pycache__/bounds.cpython-310.pyc +0 -0
  20. package/engine/__pycache__/bounds.cpython-313.pyc +0 -0
  21. package/engine/__pycache__/broker.cpython-313.pyc +0 -0
  22. package/engine/__pycache__/build_workflow.cpython-313.pyc +0 -0
  23. package/engine/__pycache__/check_policy.cpython-313.pyc +0 -0
  24. package/engine/__pycache__/cli_adapters.cpython-313.pyc +0 -0
  25. package/engine/__pycache__/clone_agent.cpython-310.pyc +0 -0
  26. package/engine/__pycache__/clone_agent.cpython-313.pyc +0 -0
  27. package/engine/__pycache__/codex_config.cpython-313.pyc +0 -0
  28. package/engine/__pycache__/codex_guard.cpython-313.pyc +0 -0
  29. package/engine/__pycache__/codex_worker.cpython-313.pyc +0 -0
  30. package/engine/__pycache__/command_policy.cpython-313.pyc +0 -0
  31. package/engine/__pycache__/completion_summary.cpython-313.pyc +0 -0
  32. package/engine/__pycache__/components.cpython-310.pyc +0 -0
  33. package/engine/__pycache__/components.cpython-313.pyc +0 -0
  34. package/engine/__pycache__/config.cpython-310.pyc +0 -0
  35. package/engine/__pycache__/config.cpython-313.pyc +0 -0
  36. package/engine/__pycache__/coreapi.cpython-310.pyc +0 -0
  37. package/engine/__pycache__/coreapi.cpython-313.pyc +0 -0
  38. package/engine/__pycache__/coremgr.cpython-310.pyc +0 -0
  39. package/engine/__pycache__/coremgr.cpython-313.pyc +0 -0
  40. package/engine/__pycache__/decide.cpython-310.pyc +0 -0
  41. package/engine/__pycache__/decide.cpython-313.pyc +0 -0
  42. package/engine/__pycache__/delivery.cpython-313.pyc +0 -0
  43. package/engine/__pycache__/extensions.cpython-313.pyc +0 -0
  44. package/engine/__pycache__/features.cpython-310.pyc +0 -0
  45. package/engine/__pycache__/features.cpython-313.pyc +0 -0
  46. package/engine/__pycache__/feedback.cpython-310.pyc +0 -0
  47. package/engine/__pycache__/feedback.cpython-313.pyc +0 -0
  48. package/engine/__pycache__/goal_loop.cpython-313.pyc +0 -0
  49. package/engine/__pycache__/guard_hook.cpython-313.pyc +0 -0
  50. package/engine/__pycache__/handoff.cpython-313.pyc +0 -0
  51. package/engine/__pycache__/harness.cpython-310.pyc +0 -0
  52. package/engine/__pycache__/harness.cpython-313.pyc +0 -0
  53. package/engine/__pycache__/helper.cpython-310.pyc +0 -0
  54. package/engine/__pycache__/helper.cpython-313.pyc +0 -0
  55. package/engine/__pycache__/history.cpython-310.pyc +0 -0
  56. package/engine/__pycache__/history.cpython-313.pyc +0 -0
  57. package/engine/__pycache__/insights.cpython-310.pyc +0 -0
  58. package/engine/__pycache__/insights.cpython-313.pyc +0 -0
  59. package/engine/__pycache__/jobs.cpython-313.pyc +0 -0
  60. package/engine/__pycache__/memory.cpython-310.pyc +0 -0
  61. package/engine/__pycache__/memory.cpython-313.pyc +0 -0
  62. package/engine/__pycache__/model_catalog.cpython-313.pyc +0 -0
  63. package/engine/__pycache__/model_discovery.cpython-313.pyc +0 -0
  64. package/engine/__pycache__/model_policy.cpython-313.pyc +0 -0
  65. package/engine/__pycache__/models.cpython-310.pyc +0 -0
  66. package/engine/__pycache__/models.cpython-313.pyc +0 -0
  67. package/engine/__pycache__/network_policy.cpython-313.pyc +0 -0
  68. package/engine/__pycache__/notify.cpython-310.pyc +0 -0
  69. package/engine/__pycache__/notify.cpython-313.pyc +0 -0
  70. package/engine/__pycache__/orchestration.cpython-313.pyc +0 -0
  71. package/engine/__pycache__/pane.cpython-313.pyc +0 -0
  72. package/engine/__pycache__/panes.cpython-313.pyc +0 -0
  73. package/engine/__pycache__/personal.cpython-310.pyc +0 -0
  74. package/engine/__pycache__/personal.cpython-313.pyc +0 -0
  75. package/engine/__pycache__/phases.cpython-310.pyc +0 -0
  76. package/engine/__pycache__/phases.cpython-313.pyc +0 -0
  77. package/engine/__pycache__/plan_discussion.cpython-313.pyc +0 -0
  78. package/engine/__pycache__/project_handoff.cpython-313.pyc +0 -0
  79. package/engine/__pycache__/protocol.cpython-310.pyc +0 -0
  80. package/engine/__pycache__/protocol.cpython-313.pyc +0 -0
  81. package/engine/__pycache__/readiness.cpython-313.pyc +0 -0
  82. package/engine/__pycache__/references.cpython-310.pyc +0 -0
  83. package/engine/__pycache__/references.cpython-313.pyc +0 -0
  84. package/engine/__pycache__/relay.cpython-313.pyc +0 -0
  85. package/engine/__pycache__/reply_examples.cpython-313.pyc +0 -0
  86. package/engine/__pycache__/research_workflow.cpython-313.pyc +0 -0
  87. package/engine/__pycache__/review.cpython-310.pyc +0 -0
  88. package/engine/__pycache__/review.cpython-313.pyc +0 -0
  89. package/engine/__pycache__/roleflow.cpython-313.pyc +0 -0
  90. package/engine/__pycache__/routing.cpython-310.pyc +0 -0
  91. package/engine/__pycache__/routing.cpython-313.pyc +0 -0
  92. package/engine/__pycache__/rubrics.cpython-310.pyc +0 -0
  93. package/engine/__pycache__/rubrics.cpython-313.pyc +0 -0
  94. package/engine/__pycache__/run_chat.cpython-313.pyc +0 -0
  95. package/engine/__pycache__/run_pool.cpython-313.pyc +0 -0
  96. package/engine/__pycache__/sandbox.cpython-310.pyc +0 -0
  97. package/engine/__pycache__/sandbox.cpython-313.pyc +0 -0
  98. package/engine/__pycache__/security.cpython-310.pyc +0 -0
  99. package/engine/__pycache__/security.cpython-313.pyc +0 -0
  100. package/engine/__pycache__/selfdev.cpython-310.pyc +0 -0
  101. package/engine/__pycache__/selfdev.cpython-313.pyc +0 -0
  102. package/engine/__pycache__/server.cpython-310.pyc +0 -0
  103. package/engine/__pycache__/server.cpython-313.pyc +0 -0
  104. package/engine/__pycache__/session.cpython-310.pyc +0 -0
  105. package/engine/__pycache__/session.cpython-313.pyc +0 -0
  106. package/engine/__pycache__/session_index.cpython-313.pyc +0 -0
  107. package/engine/__pycache__/sessionlog.cpython-310.pyc +0 -0
  108. package/engine/__pycache__/sessionlog.cpython-313.pyc +0 -0
  109. package/engine/__pycache__/settings.cpython-310.pyc +0 -0
  110. package/engine/__pycache__/settings.cpython-313.pyc +0 -0
  111. package/engine/__pycache__/shots.cpython-310.pyc +0 -0
  112. package/engine/__pycache__/shots.cpython-313.pyc +0 -0
  113. package/engine/__pycache__/skill_inventory.cpython-313.pyc +0 -0
  114. package/engine/__pycache__/ste.cpython-310.pyc +0 -0
  115. package/engine/__pycache__/ste.cpython-313.pyc +0 -0
  116. package/engine/__pycache__/store.cpython-310.pyc +0 -0
  117. package/engine/__pycache__/store.cpython-313.pyc +0 -0
  118. package/engine/__pycache__/summary_agent.cpython-313.pyc +0 -0
  119. package/engine/__pycache__/task_context.cpython-313.pyc +0 -0
  120. package/engine/__pycache__/task_output.cpython-313.pyc +0 -0
  121. package/engine/__pycache__/tmux.cpython-310.pyc +0 -0
  122. package/engine/__pycache__/tmux.cpython-313.pyc +0 -0
  123. package/engine/__pycache__/token_ledger.cpython-313.pyc +0 -0
  124. package/engine/__pycache__/triage.cpython-313.pyc +0 -0
  125. package/engine/__pycache__/trust.cpython-310.pyc +0 -0
  126. package/engine/__pycache__/trust.cpython-313.pyc +0 -0
  127. package/engine/__pycache__/userspace.cpython-310.pyc +0 -0
  128. package/engine/__pycache__/userspace.cpython-313.pyc +0 -0
  129. package/engine/__pycache__/vshots.cpython-310.pyc +0 -0
  130. package/engine/__pycache__/vshots.cpython-313.pyc +0 -0
  131. package/engine/__pycache__/workers.cpython-313.pyc +0 -0
  132. package/engine/active_runtime.py +33 -0
  133. package/engine/agent_failures.py +134 -0
  134. package/engine/agents.py +252 -0
  135. package/engine/antigravity_models.py +43 -0
  136. package/engine/bounds.py +69 -0
  137. package/engine/broker.py +772 -0
  138. package/engine/build_workflow.py +281 -0
  139. package/engine/check_policy.py +3 -0
  140. package/engine/cli_adapters.py +164 -0
  141. package/engine/clone_agent.py +413 -0
  142. package/engine/codex_config.py +84 -0
  143. package/engine/codex_guard.py +49 -0
  144. package/engine/codex_worker.py +220 -0
  145. package/engine/command_policy.py +381 -0
  146. package/engine/completion_summary.py +228 -0
  147. package/engine/components.py +108 -0
  148. package/engine/config.py +124 -0
  149. package/engine/coreapi.py +264 -0
  150. package/engine/coremgr.py +395 -0
  151. package/engine/delivery.py +68 -0
  152. package/engine/extensions.py +128 -0
  153. package/engine/features.py +378 -0
  154. package/engine/feedback.py +156 -0
  155. package/engine/goal_loop.py +473 -0
  156. package/engine/guard_hook.py +28 -0
  157. package/engine/handoff.py +168 -0
  158. package/engine/harness.py +209 -0
  159. package/engine/helper.py +144 -0
  160. package/engine/history.py +35 -0
  161. package/engine/insights.py +102 -0
  162. package/engine/jobs.py +346 -0
  163. package/engine/memory.py +17 -0
  164. package/engine/migrations/__init__.py +1 -0
  165. package/engine/migrations/__pycache__/__init__.cpython-313.pyc +0 -0
  166. package/engine/model_catalog.py +79 -0
  167. package/engine/model_discovery.py +261 -0
  168. package/engine/model_policy.py +40 -0
  169. package/engine/models.py +43 -0
  170. package/engine/network_policy.py +16 -0
  171. package/engine/notify.py +20 -0
  172. package/engine/orchestration.py +189 -0
  173. package/engine/pane.py +109 -0
  174. package/engine/panes.py +153 -0
  175. package/engine/personal.py +283 -0
  176. package/engine/phases.py +181 -0
  177. package/engine/project_handoff.py +96 -0
  178. package/engine/protocol.py +107 -0
  179. package/engine/readiness.py +41 -0
  180. package/engine/relay.py +34 -0
  181. package/engine/research_workflow.py +464 -0
  182. package/engine/review.py +80 -0
  183. package/engine/roleflow.py +144 -0
  184. package/engine/run_chat.py +134 -0
  185. package/engine/run_pool.py +147 -0
  186. package/engine/sandbox.py +174 -0
  187. package/engine/security.py +360 -0
  188. package/engine/selfdev.py +194 -0
  189. package/engine/server.py +771 -0
  190. package/engine/session.py +2550 -0
  191. package/engine/session_index.py +77 -0
  192. package/engine/sessionlog.py +119 -0
  193. package/engine/settings.py +89 -0
  194. package/engine/shots.py +51 -0
  195. package/engine/skill_inventory.py +93 -0
  196. package/engine/ste.py +81 -0
  197. package/engine/store.py +213 -0
  198. package/engine/summary_agent.py +180 -0
  199. package/engine/task_context.py +139 -0
  200. package/engine/task_output.py +340 -0
  201. package/engine/tmux.py +63 -0
  202. package/engine/token_ledger.py +57 -0
  203. package/engine/triage.py +33 -0
  204. package/engine/trust.py +140 -0
  205. package/engine/userspace.py +290 -0
  206. package/engine/vshots.py +87 -0
  207. package/engine/workers.py +49 -0
  208. package/install.sh +78 -0
  209. package/npm/cli.js +94 -0
  210. package/package.json +35 -3
  211. package/rubrics/agent-roles.json +46 -0
  212. package/rubrics/command-policy.json +3511 -0
  213. package/rubrics/security.json +131 -0
  214. package/scripts/desktop_launcher.py +25 -0
  215. package/scripts/install_core.py +37 -0
  216. package/scripts/update_desktop_launcher.py +43 -0
  217. package/skills/duo/SKILL.md +27 -0
  218. package/tests/__init__.py +29 -0
  219. package/tests/contract/__init__.py +0 -0
  220. package/tests/contract/__pycache__/__init__.cpython-310.pyc +0 -0
  221. package/tests/contract/__pycache__/__init__.cpython-313.pyc +0 -0
  222. package/tests/contract/__pycache__/test_contract.cpython-310.pyc +0 -0
  223. package/tests/contract/__pycache__/test_contract.cpython-313.pyc +0 -0
  224. package/tests/contract/test_contract.py +106 -0
  225. package/web/features.js +108 -0
  226. package/web/index.html +1753 -0
  227. package/web/notifications.js +80 -0
  228. package/web/research-evidence.js +44 -0
  229. package/web/task-map.css +38 -0
  230. package/web/task-map.js +273 -0
package/CORE_VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.19.4
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Duo contributors
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,139 @@
1
- # Temporary Holding Version
1
+ # Duo
2
2
 
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.
3
+ Duo makes the AI coding CLIs you already have check each other's work.
4
+
5
+ Give it one task. A large model writes a plan, a second large model critiques the plan, a smaller model
6
+ builds it, and a third pass reviews the code. Each step is a fresh session, so no model grades its own
7
+ work. Small asks skip all of that and run on one agent, the way the CLI would on its own.
8
+
9
+ Duo works with **Claude Code**, **Codex** and **Google Antigravity**. It uses the CLIs you have installed
10
+ and signed in to. It never installs them and never asks for API keys.
11
+
12
+ ## Install
13
+
14
+ ```bash
15
+ npx duo-agents
16
+ ```
17
+
18
+ You need:
19
+
20
+ | | macOS | Linux | Windows |
21
+ |---|---|---|---|
22
+ | Node 18+ | yes | yes | inside WSL |
23
+ | Python 3.13+ | `brew install python@3.13` | `sudo apt install python3.13` (or `uv python install 3.13`) | inside WSL |
24
+ | tmux | `brew install tmux` | `sudo apt install tmux` | inside WSL |
25
+ | At least one agent CLI, signed in | `claude`, `codex` or `agy` | same | inside WSL |
26
+
27
+ Windows runs Duo inside WSL (Ubuntu): `wsl --install -d Ubuntu`, open Ubuntu, then run `npx duo-agents`.
28
+ If something is missing, the installer says which command to run.
29
+
30
+ The installer puts Duo in `~/Duo`, adds a `duo` command, starts the engine and opens
31
+ http://127.0.0.1:8787 in your browser. From a source checkout, run `sh install.sh` instead.
32
+
33
+ ## Use
34
+
35
+ ```bash
36
+ duo # start Duo and open it in the browser
37
+ duo "add a dark mode toggle to settings"
38
+ duo doctor # show what Duo can find and what is missing
39
+ duo models # show the models each CLI reports
40
+ duo quit # stop the engine and close all agents
41
+ ```
42
+
43
+ On a Mac, `duo setup` can also build an optional desktop app (needs Xcode tools and Rust).
44
+
45
+ **From inside an agent.** Install the skill, then say "run this through Duo":
46
+
47
+ ```bash
48
+ npx skills add kkkarthik6/duo@duo
49
+ ```
50
+
51
+ ## How a task runs
52
+
53
+ Duo first sizes the task.
54
+
55
+ - **Quick path.** A short, single-part ask (about 90 words or fewer, no words like "architecture",
56
+ "migrate" or "refactor") goes to one agent using the CLI's default model. There is no plan or review
57
+ step. If it is not finished after two rounds or it stalls, Duo escalates to the full pipeline on its own.
58
+ - **Full pipeline.**
59
+ 1. A large model inspects the project and writes a plan with checks you can observe.
60
+ 2. A fresh large model critiques the plan and lists every required fix in one pass.
61
+ 3. A smaller model builds the approved plan and records real check results.
62
+ 4. A fresh medium model reviews the changes. Required fixes go back to the builder.
63
+
64
+ A reviewer is never a weaker tier than the author. When you have two CLIs, Duo reviews across providers,
65
+ which is what catches an author's blind spots. With one CLI it works, and tells you reviews share a provider.
66
+
67
+ Models are matched to roles by tier (large, medium, small) from what your CLIs report. If a model has no
68
+ tier, Duo uses the nearest tier, then the CLI's own default. Failures are tracked, so a model that is out of
69
+ quota or signed out is skipped and the work moves to another one. Saved work is kept.
70
+
71
+ Each handoff is a short brief generated from the run's state: the ask, constraints, open defects, changed
72
+ files and who does what next. Older turns collapse to counts, so context stays small without losing work.
73
+
74
+ Up to four runs can work at once, in different projects. Runs in the same project wait their turn.
75
+ The Insights panel shows time and estimated tokens for each turn.
76
+
77
+ ## Safety
78
+
79
+ **By default Duo's agents run with their CLIs' automatic-approval modes, so they can edit files and run
80
+ commands in the project without asking you.** Use it on projects under version control and keep backups.
81
+ Each run works in its own project folder, but Duo is not a sandbox. Native CLI safeguards stay on, and
82
+ agents ask you when they are missing information. See the [approval policy](docs/duo-approval-policy.md)
83
+ and [command policy](docs/duo-command-policy.md).
84
+
85
+ Duo runs Codex with `exec --ephemeral`, so its runs do not appear in your Codex history.
86
+ See [session privacy](docs/duo-session-privacy.md).
87
+
88
+ ## Settings
89
+
90
+ Duo reads `~/Duo/config.json`. Useful keys:
91
+
92
+ ```json
93
+ {"triage": "auto", "max_rounds": 100, "max_active_runs": 4, "quick_review": false, "fast_close": true}
94
+ ```
95
+
96
+ - `triage`: `auto` sizes each task; `full` always runs the whole pipeline.
97
+ - `quick_review`: add one independent review to quick tasks.
98
+ - `fast_close`: end approved, verified work without extra summary turns.
99
+
100
+ The app's Defaults and Features screens expose the rest. Assign a role to a specific model with
101
+ `role_models`; see [generic agents](docs/duo-generic-agents.md) and
102
+ [model discovery](docs/dynamic-model-catalog.md).
103
+
104
+ ## Updating and recovery
105
+
106
+ Duo installs as sealed, versioned cores in `~/Duo/core`.
107
+
108
+ ```bash
109
+ npx duo-agents setup # install the newest published version
110
+ duo update --from <folder|file.tgz> # test a new core, check your features, then switch
111
+ duo core go-back # return to the previous core
112
+ ```
113
+
114
+ Your features and settings live outside the core and survive updates.
115
+
116
+ ## Troubleshooting
117
+
118
+ - `duo doctor` lists what Duo can find: Python, tmux, each agent CLI and the engine.
119
+ - A CLI shows as signed out: open it once in a normal terminal and sign in, then rescan in Duo.
120
+ - Codex will not start after a crash: `duo repair-codex` shows the problem; add `--apply` to fix it.
121
+ - The page does not load: run `duo` again. Quitting the app or closing the terminal that started the
122
+ engine stops it.
123
+ - tmux must be 3.2 or newer.
124
+
125
+ ## Develop
126
+
127
+ ```bash
128
+ python3.13 -m unittest discover -s tests -t . # unit tests, about 25 seconds
129
+ python3.13 -m unittest discover -s tests/integration -t . # real tmux with fake agents
130
+ ```
131
+
132
+ The engine uses only the Python standard library. More detail: [multiple runs](docs/duo-multiple-runs.md),
133
+ [goal loop](docs/duo-goal-loop.md), [job monitoring](docs/duo-job-monitoring.md),
134
+ [delivery recovery](docs/duo-delivery-recovery.md), [UI extensions](docs/duo-ui-extensions.md),
135
+ [network access](docs/duo-network-access.md), [native worker setup](docs/duo-native-worker-setup.md).
136
+
137
+ ## License
138
+
139
+ MIT. See [LICENSE](LICENSE).
package/VERSION ADDED
@@ -0,0 +1 @@
1
+ r8
package/bin/duo ADDED
@@ -0,0 +1,486 @@
1
+ #!/usr/bin/env python3
2
+ """duo: open the Duo app, start a task, or set things up.
3
+
4
+ duo open Duo
5
+ duo "task text" start a task and open Duo
6
+ duo setup [--yes] install what is missing (tmux, Rust, Docker) and build the Mac app
7
+ duo doctor show what Duo can find
8
+ duo repair-codex fix a Codex config that does not load (shows what it would change; add --apply to do it)
9
+ duo models refresh installed CLIs and show their reported model choices
10
+ duo version show your Duo version and the core version
11
+ duo update --from <folder|file.tgz>
12
+ install a new Duo core safely: test it, check your features, then switch
13
+ duo core show the core version and check that its files are unchanged
14
+ duo core go-back switch back to the previous core
15
+ duo serve run the engine in this terminal
16
+ duo serve-bg start the engine in the background (used by the app)
17
+ duo quit stop the engine and close all agents (the app does this when you quit it)
18
+ """
19
+ import json
20
+ import os
21
+ import shutil
22
+ import subprocess
23
+ import sys
24
+ import time
25
+ import urllib.request
26
+ from pathlib import Path
27
+
28
+ REQUIRED_PYTHON = (3, 13)
29
+ # Where a Python 3.13 install usually lives on a Mac (Homebrew, python.org, or the PATH).
30
+ PYTHON_CANDIDATES = ["/opt/homebrew/bin/python3.13", "/usr/local/bin/python3.13",
31
+ "/Library/Frameworks/Python.framework/Versions/3.13/bin/python3.13"]
32
+
33
+ # Duo needs Python 3.13. When this runs under an older Python (the Xcode copy on macOS is 3.9),
34
+ # hand over to a 3.13 install. This code must stay valid for older Pythons until this check runs.
35
+ if sys.version_info < REQUIRED_PYTHON:
36
+ found = next((c for c in PYTHON_CANDIDATES if os.path.exists(c)), None) or shutil.which("python3.13")
37
+ if found:
38
+ os.execv(found, [found, os.path.realpath(__file__)] + sys.argv[1:])
39
+ how = ("brew install python@3.13" if sys.platform == "darwin" else
40
+ "sudo apt install python3.13 (or: uv python install 3.13)")
41
+ sys.exit("Duo needs Python %d.%d or newer. This is Python %s. Install it (%s) and run duo again."
42
+ % (REQUIRED_PYTHON + (sys.version.split()[0], how)))
43
+
44
+ BUNDLED = Path(os.path.realpath(__file__)).parent.parent # the source that came with this install
45
+ DUO_HOME = Path(os.environ.get("DUO_HOME") or Path.home() / "Duo")
46
+
47
+
48
+ def _active_dir():
49
+ """The code to run: the current sealed core in ~/Duo/core. Falls back to this copy (a checkout or an
50
+ unpacked archive) when no core is installed yet."""
51
+ sys.path.insert(0, str(BUNDLED))
52
+ try:
53
+ from engine import coremgr
54
+ cur = coremgr.current_dir(DUO_HOME)
55
+ return cur if cur and (cur / "bin" / "duo").exists() else BUNDLED
56
+ except Exception as ex:
57
+ print("Duo could not read its core state (%s). Running this copy." % ex, file=sys.stderr)
58
+ return BUNDLED
59
+ finally:
60
+ sys.path.pop(0)
61
+
62
+
63
+ APP_DIR = _active_dir() # .../_duo, or the version being run
64
+ PORT = 8787
65
+ HOME = Path.home()
66
+ APP_PATHS = [HOME / "Applications" / "Duo.app", Path("/Applications/Duo.app")]
67
+ # The pattern must not start with "-": pkill would read it as an option and stop nothing.
68
+ PKILL_ENGINE = ["pkill", "-f", "[-]m engine serve"]
69
+ TOOL_DIRS = ["/opt/homebrew/bin", "/usr/local/bin", "{h}/.local/bin", "{h}/.npm-global/bin", "{h}/.cargo/bin",
70
+ "/usr/bin", "/bin", "/usr/sbin", "/sbin"]
71
+
72
+
73
+ def say(msg):
74
+ print(msg, flush=True)
75
+
76
+
77
+ # ------------------------------------------------------------------ engine
78
+ def code_id():
79
+ sys.path.insert(0, str(APP_DIR))
80
+ from engine.config import code_id as cid
81
+ return cid()
82
+
83
+
84
+ def engine_code(port=PORT):
85
+ """The running engine's code fingerprint, or None when no engine answers."""
86
+ try:
87
+ with urllib.request.urlopen("http://127.0.0.1:%d/api/health" % port, timeout=1) as r:
88
+ body = json.loads(r.read())
89
+ return body.get("code", "") if body.get("ok") is True else None
90
+ except Exception:
91
+ return None
92
+
93
+
94
+ def health(port=PORT):
95
+ return engine_code(port) is not None
96
+
97
+
98
+ def stop_engine(port=PORT, run=subprocess.run):
99
+ try:
100
+ post_json(port, "/api/shutdown", {})
101
+ except Exception:
102
+ pass
103
+ for _ in range(40):
104
+ if engine_code(port) is None:
105
+ return
106
+ time.sleep(0.25)
107
+ run(PKILL_ENGINE, capture_output=True) # engines from before /api/shutdown existed
108
+ for _ in range(20):
109
+ if engine_code(port) is None:
110
+ return
111
+ time.sleep(0.25)
112
+
113
+
114
+ def login_path():
115
+ """PATH from the user's shell. Apps opened from Finder get a bare PATH without Homebrew or npm."""
116
+ shell = os.environ.get("SHELL", "/bin/zsh")
117
+ try:
118
+ r = subprocess.run([shell, "-lic", 'printf "\\n%s" "$PATH"'], capture_output=True, text=True, timeout=5)
119
+ return r.stdout.strip().splitlines()[-1] if r.stdout.strip() else ""
120
+ except Exception:
121
+ return ""
122
+
123
+
124
+ def engine_env():
125
+ env = dict(os.environ)
126
+ h = env.get("HOME", str(HOME))
127
+ parts = [p for p in login_path().split(":") if p] + [d.format(h=h) for d in TOOL_DIRS] + env.get("PATH", "").split(":")
128
+ env["PATH"] = ":".join(dict.fromkeys(p for p in parts if p))
129
+ return env
130
+
131
+
132
+ def spawn_engine(port=PORT):
133
+ log = HOME / "Duo Workouts" / ".duo-engine.log"
134
+ log.parent.mkdir(parents=True, exist_ok=True)
135
+ subprocess.Popen([sys.executable, "-m", "engine", "serve", str(port)], cwd=str(APP_DIR), env=engine_env(),
136
+ stdout=log.open("a"), stderr=subprocess.STDOUT, stdin=subprocess.DEVNULL, start_new_session=True)
137
+
138
+
139
+ def ensure_engine(port=PORT, spawn=None, wait=10):
140
+ want, running = code_id(), engine_code(port)
141
+ if running == want:
142
+ return True
143
+ if running is not None: # an older engine is running: replace it (agents in tmux keep going)
144
+ stop_engine(port)
145
+ (spawn or spawn_engine)(port)
146
+ for _ in range(int(wait / 0.25)):
147
+ if engine_code(port) == want:
148
+ return True
149
+ time.sleep(0.25)
150
+ return False
151
+
152
+
153
+ def post_json(port, path, body):
154
+ req = urllib.request.Request("http://127.0.0.1:%d%s" % (port, path), data=json.dumps(body).encode(),
155
+ headers={"Content-Type": "application/json"})
156
+ with urllib.request.urlopen(req, timeout=10) as r:
157
+ return json.loads(r.read())
158
+
159
+
160
+ def tmux_name():
161
+ sys.path.insert(0, str(APP_DIR))
162
+ from engine.config import CFG
163
+ return CFG["tmux_session"]
164
+
165
+
166
+ def quit_all(port=PORT, run=subprocess.run):
167
+ """Quitting Duo forgets everything: stop the engine and close every agent."""
168
+ try:
169
+ post_json(port, "/api/quit", {})
170
+ for _ in range(20):
171
+ if engine_code(port) is None:
172
+ break
173
+ time.sleep(0.25)
174
+ except Exception:
175
+ stop_engine(port)
176
+ run(["tmux", "kill-session", "-t", tmux_name()], capture_output=True)
177
+
178
+
179
+ def open_ui(port=PORT, run=subprocess.run, app_paths=None):
180
+ app = next((p for p in (app_paths or APP_PATHS) if p.exists()), None)
181
+ url = "http://127.0.0.1:%d" % port
182
+ if sys.platform == "darwin":
183
+ run(["open", str(app)] if app else ["open", url])
184
+ return
185
+ opener = next((c for c in ("wslview", "xdg-open") if shutil.which(c)), None)
186
+ if opener:
187
+ run([opener, url], capture_output=True)
188
+ else:
189
+ say("Open %s in your browser." % url)
190
+
191
+
192
+ # ------------------------------------------------------------------- setup
193
+ def have(cmd):
194
+ return shutil.which(cmd, path=engine_env()["PATH"])
195
+
196
+
197
+ def run(cmd, **kw):
198
+ say(" $ " + (cmd if isinstance(cmd, str) else " ".join(cmd)))
199
+ return subprocess.run(cmd, shell=isinstance(cmd, str), env=engine_env(), **kw)
200
+
201
+
202
+ def write_icon(path, size=1024):
203
+ """Two overlapping discs, the Duo mark, written as a PNG with the standard library."""
204
+ import struct
205
+ import zlib
206
+ claude, codex, bg = (168, 106, 18), (14, 116, 104), (237, 240, 243)
207
+ r, cy, c1, c2 = size * 0.25, size / 2, size * 0.39, size * 0.61
208
+ m, rad = size * 0.09, size * 0.2 # macOS-style margin and corner radius
209
+ rows = []
210
+ for y in range(size):
211
+ row = bytearray([0])
212
+ for x in range(size):
213
+ qx, qy = max(m + rad - x, 0, x - (size - m - rad)), max(m + rad - y, 0, y - (size - m - rad))
214
+ if x < m or y < m or x > size - m or y > size - m or qx * qx + qy * qy > rad * rad:
215
+ row += b"\x00\x00\x00\x00"
216
+ continue
217
+ in1 = (x - c1) ** 2 + (y - cy) ** 2 <= r * r
218
+ in2 = (x - c2) ** 2 + (y - cy) ** 2 <= r * r
219
+ if in1 and in2:
220
+ px = tuple((a + b) // 2 for a, b in zip(claude, codex))
221
+ else:
222
+ px = claude if in1 else codex if in2 else bg
223
+ row += bytes(px) + b"\xff"
224
+ rows.append(bytes(row))
225
+
226
+ def chunk(tag, data):
227
+ return struct.pack(">I", len(data)) + tag + data + struct.pack(">I", zlib.crc32(tag + data) & 0xFFFFFFFF)
228
+
229
+ png = b"\x89PNG\r\n\x1a\n" + chunk(b"IHDR", struct.pack(">IIBBBBB", size, size, 8, 6, 0, 0, 0)) \
230
+ + chunk(b"IDAT", zlib.compress(b"".join(rows), 9)) + chunk(b"IEND", b"")
231
+ Path(path).write_bytes(png)
232
+
233
+
234
+ def setup():
235
+ if sys.platform != "darwin":
236
+ say("The Duo app is built on macOS only. On Linux and WSL, Duo runs in your browser:")
237
+ say(" duo (starts Duo and opens http://127.0.0.1:%d)" % PORT)
238
+ return doctor()
239
+ missing = []
240
+ if subprocess.run(["xcode-select", "-p"], capture_output=True).returncode != 0:
241
+ missing.append("Xcode Command Line Tools")
242
+ if not have("tmux"):
243
+ missing.append("tmux")
244
+ if not have("cargo"):
245
+ missing.append("Rust (rustup)")
246
+ say("Duo setup")
247
+ if missing:
248
+ say("Missing: " + ", ".join(missing))
249
+ if "--yes" not in sys.argv and input("Install missing tools? [y/N] ").strip().lower() != "y":
250
+ say("Nothing installed.")
251
+ return 1
252
+ if "Xcode Command Line Tools" in missing:
253
+ run(["xcode-select", "--install"])
254
+ say("Finish the Apple installer window. Duo waits for it.")
255
+ while subprocess.run(["xcode-select", "-p"], capture_output=True).returncode != 0:
256
+ time.sleep(10)
257
+ if "tmux" in missing:
258
+ if not have("brew"):
259
+ say("Install Homebrew first (https://brew.sh), then run duo setup again:")
260
+ say(' /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"')
261
+ return 1
262
+ run(["brew", "install", "tmux"], check=True)
263
+ if "Rust (rustup)" in missing:
264
+ run("curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y", check=True)
265
+
266
+ if not have("docker") and have("brew"):
267
+ say("Docker is not installed. Duo uses it to install each project's tools safely.")
268
+ if "--yes" in sys.argv or input("Install Docker Desktop? [y/N] ").strip().lower() == "y":
269
+ run(["brew", "install", "--cask", "docker"])
270
+ run(["open", "-a", "Docker"])
271
+ say("Docker Desktop is starting. Accept its prompts once. Duo works without it, but installs then need your approval.")
272
+ say("Building the Duo app. The first build takes a few minutes.")
273
+ app = APP_DIR / "app"
274
+ icons = app / "src-tauri" / "icons"
275
+ icons.mkdir(parents=True, exist_ok=True)
276
+ src_png = icons / "source.png"
277
+ if not src_png.exists():
278
+ write_icon(src_png)
279
+ # ponytail: npx uses the prebuilt Tauri CLI (seconds); cargo install compiles it (minutes). Fallback only.
280
+ tauri = ["npx", "--yes", "@tauri-apps/cli@^2"] if have("npx") else ["cargo", "tauri"]
281
+ if tauri[0] == "cargo" and run(["cargo", "tauri", "--version"], capture_output=True).returncode != 0:
282
+ run(["cargo", "install", "tauri-cli", "--version", "^2", "--locked"], check=True)
283
+ run(tauri + ["icon", str(src_png)], cwd=str(app / "src-tauri"), check=True)
284
+ run(tauri + ["build", "--bundles", "app"], cwd=str(app), check=True)
285
+ built = next((app / "src-tauri" / "target" / "release" / "bundle" / "macos").glob("*.app"), None)
286
+ if not built:
287
+ say("The build finished but Duo.app was not found.")
288
+ return 1
289
+ dest = HOME / "Applications" / "Duo.app"
290
+ dest.parent.mkdir(exist_ok=True)
291
+ shutil.rmtree(dest, ignore_errors=True)
292
+ shutil.copytree(built, dest, symlinks=True)
293
+ say("Duo.app installed in %s" % dest.parent)
294
+
295
+ shim = HOME / ".local" / "bin" / "duo"
296
+ shim.parent.mkdir(parents=True, exist_ok=True)
297
+ if shim.is_symlink() or shim.exists():
298
+ shim.unlink()
299
+ shim.symlink_to(Path(os.path.realpath(__file__)))
300
+ zshrc = HOME / ".zshrc"
301
+ line = 'export PATH="$HOME/.local/bin:$PATH"'
302
+ if line not in (zshrc.read_text() if zshrc.exists() else ""):
303
+ with zshrc.open("a") as f:
304
+ f.write("\n# Duo\n%s\n" % line)
305
+ say("Added ~/.local/bin to your PATH in ~/.zshrc. Open a new Terminal window to use 'duo'.")
306
+ return doctor()
307
+
308
+
309
+ def doctor():
310
+ sys.path.insert(0, str(APP_DIR))
311
+ os.environ["PATH"] = engine_env()["PATH"]
312
+ from engine import agents
313
+ say("Python %s" % sys.version.split()[0])
314
+ say("tmux %s" % (have("tmux") or "missing: " + ("brew install tmux" if sys.platform == "darwin" else "sudo apt install tmux")))
315
+ found = agents.detect()
316
+ from engine import cli_adapters
317
+ specs = dict(agents.AGENT_SPECS)
318
+ for aid, adapter in cli_adapters.registry().items():
319
+ specs.setdefault(aid, {'label': adapter.label})
320
+ for aid, spec in specs.items():
321
+ a = next((x for x in found if x.id == aid), None)
322
+ say("%-11s %s" % (spec["label"], a.version if a else "not found"))
323
+ if a and a.capability_check:
324
+ say(' role worker: ' + ('ready' if a.capability_check['ready'] else 'required CLI flags missing'))
325
+ if not found:
326
+ say("No agent CLIs found. Install Claude Code, Codex or Antigravity, then sign in once in Terminal.")
327
+ from engine import sandbox
328
+ ok, msg = sandbox.available()
329
+ say("Docker %s" % ("running" if ok else msg))
330
+ from engine import codex_config
331
+ problem = codex_config.check()
332
+ if problem:
333
+ say("Codex config PROBLEM: " + problem)
334
+ say("Engine %s" % ("running on port %d" % PORT if health() else "not running"))
335
+ if sys.platform == "darwin":
336
+ app = next((p for p in APP_PATHS if p.exists()), None)
337
+ say("App %s" % (app or "not built: run duo setup"))
338
+ return 0 if found and have("tmux") else 1
339
+
340
+
341
+ # -------------------------------------------------------------------- main
342
+ def _engine_mods():
343
+ sys.path.insert(0, str(APP_DIR))
344
+ from engine import coremgr, userspace
345
+ return coremgr, userspace
346
+
347
+
348
+ def version():
349
+ """Your Duo's number and the core's number, for example: 3.0.0 · core 1.0.0."""
350
+ try:
351
+ coremgr, userspace = _engine_mods()
352
+ core = coremgr.info(DUO_HOME).get("version")
353
+ if not (DUO_HOME / "user-versions.json").exists():
354
+ return "not set up yet (run install.sh)"
355
+ return "%s · core %s" % (userspace.load(DUO_HOME)["number"], core or "not installed")
356
+ except Exception:
357
+ p = APP_DIR / "VERSION"
358
+ return p.read_text().strip() if p.exists() else "unknown"
359
+
360
+
361
+ def _source(arg):
362
+ """A folder, or a .tgz unpacked into a new temporary folder. Returns the folder that holds CORE_VERSION."""
363
+ p = Path(os.path.expanduser(arg)).resolve()
364
+ if p.is_dir():
365
+ return p
366
+ if p.is_file() and p.name.endswith((".tgz", ".tar.gz")):
367
+ import tarfile
368
+ import tempfile
369
+ dest = Path(tempfile.mkdtemp(prefix="duo-update-"))
370
+ with tarfile.open(p) as t:
371
+ t.extractall(dest, filter="data")
372
+ hits = [c.parent for c in dest.rglob("CORE_VERSION")]
373
+ if hits:
374
+ return min(hits, key=lambda h: len(h.parts))
375
+ raise SystemExit("Duo cannot read %s. Give a Duo folder or a .tgz file." % arg)
376
+
377
+
378
+ def update(argv=()):
379
+ """Install a new core beside the current one. Its core tests and your features' tests run first."""
380
+ args = list(argv)
381
+ if "--from" not in args or args.index("--from") + 1 >= len(args):
382
+ say("Tell Duo where the new version is: duo update --from <folder or file.tgz>")
383
+ say("Or run install.sh from the new Duo folder. Both keep your features and runs.")
384
+ return 1
385
+ src = _source(args[args.index("--from") + 1])
386
+ coremgr, _ = _engine_mods()
387
+ say("Checking the new core. This runs its core tests and your features' tests.")
388
+ r = coremgr.update(src, DUO_HOME)
389
+ say(r["detail"])
390
+ if r["status"] == "updated":
391
+ say("Run `duo quit`, then `duo`, to load it.")
392
+ for n in r["disabled"]:
393
+ say("Feature %s is off for now. Duo is fixing it in a copy and turns it on when the fix passes." % n)
394
+ return 3 if r["status"] == "core_failed" else 0
395
+
396
+
397
+ def core_cmd(argv):
398
+ coremgr, _ = _engine_mods()
399
+ if argv[:1] == ["go-back"]:
400
+ say("Switched to core %s. Run `duo quit`, then `duo`, to load it." % coremgr.go_back(DUO_HOME))
401
+ return 0
402
+ i = coremgr.info(DUO_HOME)
403
+ if not i.get("version"):
404
+ say("No sealed core is installed. Run install.sh from the Duo folder.")
405
+ return 1
406
+ say("Core %s in %s" % (i["version"], i["dir"]))
407
+ say("Contract %s. Earlier core: %s." % (i["contract"], i.get("previous") or "none"))
408
+ changed = coremgr.verify(DUO_HOME)
409
+ if changed:
410
+ say("These core files were changed by hand: %s" % ", ".join(changed[:10]))
411
+ say("Run duo update --from <the Duo folder> to put them back.")
412
+ return 2
413
+ say("All core files are unchanged.")
414
+ return 0
415
+
416
+
417
+ def repair_codex(argv):
418
+ sys.path.insert(0, str(APP_DIR))
419
+ from engine import codex_config
420
+ if not codex_config.check() and "--apply" not in argv:
421
+ say("Your Codex config loads fine.")
422
+ report = codex_config.repair(apply="--apply" in argv)
423
+ say("%s: %d throwaway test folders and %d broken fragments %s; %d real project entries kept."
424
+ % (report["file"], report["removed_test_folders"], len(report["removed_fragments"]),
425
+ "removed" if report["applied"] else "would be removed", report["projects_kept"]))
426
+ if report["applied"]:
427
+ say("Backup of the old file: " + report["backup"])
428
+ elif report["removed_test_folders"] or report["removed_fragments"]:
429
+ say("Nothing was changed. Run `duo repair-codex --apply` to make the change (a backup is kept).")
430
+ return 0
431
+
432
+
433
+ def main(argv):
434
+ cmd = argv[0] if argv else ""
435
+ if cmd in ("-h", "--help", "help"):
436
+ say(__doc__.strip())
437
+ return 0
438
+ if cmd == "version":
439
+ say("Duo " + version())
440
+ return 0
441
+ if cmd == "update":
442
+ return update(argv[1:])
443
+ if cmd == "core":
444
+ return core_cmd(argv[1:])
445
+ if cmd == "setup":
446
+ return setup()
447
+ if cmd == "doctor":
448
+ return doctor()
449
+ if cmd == "repair-codex":
450
+ return repair_codex(argv[1:])
451
+ if cmd == 'models':
452
+ os.environ['PATH'] = engine_env()['PATH']
453
+ sys.path.insert(0, str(APP_DIR))
454
+ from engine import model_discovery, model_catalog
455
+ snapshot = model_discovery.refresh(force=True)
456
+ rows = model_discovery.catalog(snapshot, model_catalog.entries())
457
+ say('Checked: ' + time.strftime('%Y-%m-%d %H:%M %Z (%z)', time.localtime(snapshot['checked_at'])))
458
+ for cli in snapshot['clis']:
459
+ say(cli['id'] + ': ' + cli['status'])
460
+ for row in (r for r in rows if r['cli'] == cli['id']):
461
+ say(' %-32s %s' % (row['id'], row['tier'] or 'needs tier'))
462
+ say('CLI-reported choices; quota and inference access are checked when used.')
463
+ return 0 if any(c['status'] == 'ready' for c in snapshot['clis']) else 1
464
+ if cmd == "serve":
465
+ os.chdir(APP_DIR)
466
+ os.environ["PATH"] = engine_env()["PATH"]
467
+ sys.path.insert(0, str(APP_DIR))
468
+ from engine.server import serve
469
+ serve(PORT)
470
+ return 0
471
+ if cmd == "quit":
472
+ quit_all(PORT)
473
+ return 0
474
+ if cmd == "serve-bg":
475
+ return 0 if ensure_engine(PORT) else 1
476
+ if not ensure_engine(PORT):
477
+ say("Duo could not start its engine. See ~/Duo Workouts/.duo-engine.log")
478
+ return 1
479
+ if argv:
480
+ post_json(PORT, "/api/start", {"task": " ".join(argv)})
481
+ open_ui(PORT)
482
+ return 0
483
+
484
+
485
+ if __name__ == "__main__":
486
+ sys.exit(main(sys.argv[1:]))
@@ -0,0 +1 @@
1
+ """Duo engine."""
@@ -0,0 +1,8 @@
1
+ import sys
2
+ from .server import serve
3
+
4
+ if __name__ == "__main__":
5
+ if sys.argv[1:2] == ["serve"]:
6
+ serve(int(sys.argv[2]) if len(sys.argv) > 2 else None)
7
+ else:
8
+ print("usage: python3 -m engine serve [port]")