@nanobpm/nano-workforce 0.26.0

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 (115) hide show
  1. package/.github/workflows/ci.yml +60 -0
  2. package/.github/workflows/release.yml +58 -0
  3. package/.releaserc.json +17 -0
  4. package/AGENTS.md +168 -0
  5. package/CHANGELOG.md +231 -0
  6. package/LICENSE +202 -0
  7. package/README.md +303 -0
  8. package/SPEC.md +492 -0
  9. package/actions/abandon.test.ts +93 -0
  10. package/actions/abandon.ts +23 -0
  11. package/actions/blackboard.test.ts +195 -0
  12. package/actions/blackboard.ts +76 -0
  13. package/actions/cancel.ts +29 -0
  14. package/actions/feature-answer-hook.ts +44 -0
  15. package/actions/message.ts +49 -0
  16. package/actions/plan-hook.ts +19 -0
  17. package/actions/plan-start.ts +17 -0
  18. package/actions/start.ts +19 -0
  19. package/actions/status.ts +22 -0
  20. package/actions/webhook-submit.ts +21 -0
  21. package/app/abandon.test.ts +97 -0
  22. package/app/abandon.ts +105 -0
  23. package/app/baseGuard.test.ts +35 -0
  24. package/app/baseGuard.ts +62 -0
  25. package/app/blackboard.test.ts +295 -0
  26. package/app/blackboard.ts +301 -0
  27. package/app/github.test.ts +59 -0
  28. package/app/github.ts +647 -0
  29. package/app/mergeExclusion.test.ts +168 -0
  30. package/app/mergeExclusion.ts +211 -0
  31. package/app/mergeProtocol.test.ts +124 -0
  32. package/app/mergeProtocol.ts +193 -0
  33. package/app/mergeRebaseArm.test.ts +72 -0
  34. package/app/mergeTrain.test.ts +91 -0
  35. package/app/mergeTrain.ts +117 -0
  36. package/app/persist-escalation.test.ts +119 -0
  37. package/app/persist-round.test.ts +65 -0
  38. package/app/plan.test.ts +317 -0
  39. package/app/plan.ts +321 -0
  40. package/app/record-plan-review.test.ts +38 -0
  41. package/app/reviewWait.test.ts +70 -0
  42. package/app/reviewWait.ts +59 -0
  43. package/app/rounds.test.ts +74 -0
  44. package/app/rounds.ts +48 -0
  45. package/app/service.test.ts +101 -0
  46. package/app/service.ts +895 -0
  47. package/app/taskDelta.test.ts +144 -0
  48. package/app/taskDelta.ts +175 -0
  49. package/app/trialMerge.test.ts +15 -0
  50. package/app/trialMerge.ts +102 -0
  51. package/app/waves.test.ts +128 -0
  52. package/app/waves.ts +116 -0
  53. package/assets/icon.svg +13 -0
  54. package/components/review-round.json +69 -0
  55. package/db/migrations/001_init.sql +46 -0
  56. package/db/migrations/002_transcript.sql +7 -0
  57. package/db/migrations/003_open_escalation.sql +8 -0
  58. package/db/migrations/004_merge.sql +36 -0
  59. package/db/migrations/004_planning.sql +37 -0
  60. package/db/migrations/005_job_activation.sql +15 -0
  61. package/db/migrations/005_plan_deps.sql +20 -0
  62. package/db/migrations/006_plan_review.sql +22 -0
  63. package/db/migrations/006_task_escalation.sql +52 -0
  64. package/db/migrations/007_plan_review_job_key.sql +14 -0
  65. package/db/migrations/007_wave_gate.sql +16 -0
  66. package/db/migrations/008_review_nudge.sql +9 -0
  67. package/db/migrations/009_plan_blackboard.sql +46 -0
  68. package/db/migrations/010_plan_task_deltas.sql +27 -0
  69. package/db/migrations/011_plan_merge_exclusions.sql +26 -0
  70. package/db/migrations/012_merge_protocol_attempt.sql +4 -0
  71. package/db/migrations/013_merge_train_waiting_lane.sql +6 -0
  72. package/db/migrations/014_plan_trial_merges.sql +21 -0
  73. package/db/migrations/015_pr_abandon_token.sql +9 -0
  74. package/deno.json +24 -0
  75. package/deno.lock +1776 -0
  76. package/main.ts +71 -0
  77. package/nano-ide.ext.json +7 -0
  78. package/nano.app.json +138 -0
  79. package/nanobpm.project.json +20 -0
  80. package/package.json +56 -0
  81. package/pages/epic.page.json +195 -0
  82. package/pages/home.page.json +296 -0
  83. package/prompts/feature.md +132 -0
  84. package/prompts/fix-ci.md +65 -0
  85. package/prompts/plan-review.md +69 -0
  86. package/prompts/plan.md +183 -0
  87. package/prompts/rebase.md +82 -0
  88. package/prompts/review-round.md +171 -0
  89. package/prompts/trial-merge.md +43 -0
  90. package/renovate.json +21 -0
  91. package/resources/processes/convergence-loop.bpmn +399 -0
  92. package/resources/processes/merge-loop.bpmn +585 -0
  93. package/resources/processes/plan-fanout.bpmn +546 -0
  94. package/scripts/check-agent-prompts.test.ts +84 -0
  95. package/scripts/check-agent-prompts.ts +143 -0
  96. package/scripts/layout-bpmn.ts +99 -0
  97. package/scripts/purge-db.ts +57 -0
  98. package/scripts/upgrade-from-pack.ts +334 -0
  99. package/tsconfig.json +51 -0
  100. package/workers/arm-merge/worker.ts +18 -0
  101. package/workers/finalize/worker.ts +89 -0
  102. package/workers/mark-merged/worker.ts +21 -0
  103. package/workers/merge/worker.ts +119 -0
  104. package/workers/persist-escalation/worker.ts +107 -0
  105. package/workers/persist-round/worker.ts +52 -0
  106. package/workers/persist-task-escalation/worker.ts +112 -0
  107. package/workers/record-plan/worker.ts +135 -0
  108. package/workers/record-plan-review/worker.ts +92 -0
  109. package/workers/record-results/worker.ts +30 -0
  110. package/workers/record-trial-merge/worker.test.ts +104 -0
  111. package/workers/record-trial-merge/worker.ts +88 -0
  112. package/workers/record-wave/worker.test.ts +221 -0
  113. package/workers/record-wave/worker.ts +308 -0
  114. package/workers/select-wave/worker.test.ts +130 -0
  115. package/workers/select-wave/worker.ts +84 -0
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,303 @@
1
+ # Nano Workforce
2
+
3
+ **Agent Graph Orchestration for Agentic SDLC.** Nano Workforce turns a fleet of
4
+ AI coding agents into a durable, self-driving software-delivery workforce: hand it
5
+ an issue and it plans the work, fans a graph of agents out to implement it, drives
6
+ every resulting pull request to **review convergence** against an automated
7
+ reviewer, and **merges** it — escalating to a human only when an agent is stuck or
8
+ a round cap is hit.
9
+
10
+ It is a [Nano](https://github.com/jwulf/nano-ide) **Urban app**: a set of durable
11
+ BPMN processes (`resources/processes/*.bpmn`) executed by the Nano engine, with the
12
+ orchestration graph — planning, implementation, review, and merge — modelled
13
+ explicitly so the whole lifecycle survives restarts, latency, and failure.
14
+
15
+ - **Plan → implement** — a planning agent decomposes an issue into levelized tasks;
16
+ a parallel fan-out drives one implementation agent per task, one PR each.
17
+ - **Review convergence** — each PR runs a durable multi-round loop against an
18
+ automated reviewer until it converges (or escalates).
19
+ - **Merge** — a converged PR flows into a merge loop that clears dependencies,
20
+ auto-fixes failing CI, and merges (queue-aware), escalating conflicts.
21
+
22
+ The agents are external workers you "hire" (any coding-agent CLI harness, e.g. the
23
+ GitHub Copilot CLI). Nano Workforce owns the orchestration; the agents do the work.
24
+
25
+ ---
26
+
27
+ ## Install & run in Nano Studio (recommended)
28
+
29
+ Nano Workforce ships as a Nano Studio **extension**. Studio installs it from the
30
+ marketplace, scaffolds a project from it, runs it as a first-class app in the left
31
+ rail, and keeps it up to date.
32
+
33
+ 1. **Install the Urban toolkit** (once): Studio → **Extensions** → search
34
+ `@nanobpm/nano-ide-app-urban` → **Install**. This provides the `urban` runtime/CLI
35
+ that every Urban app builds on. (Studio installs it automatically the first time
36
+ you create an Urban project.)
37
+
38
+ 2. **Install Nano Workforce**: Studio → **Extensions** → search
39
+ `@nanobpm/nano-workforce` (or browse the **Agentic SDLC** category) → **Install**.
40
+
41
+ 3. **Create a project**: Studio → **New Project** → pick **Nano Workforce** →
42
+ name it → **Create**. Studio copies the app into your workspace and records the
43
+ version it was scaffolded from.
44
+
45
+ 4. **Configure**: in the project's settings, set at least `GITHUB_TOKEN` and, if the
46
+ engine isn't at the default, `NANOBPMN_BASE_URL` (or `CAMUNDA_REST_ADDRESS`). See
47
+ [Configuration](#configuration).
48
+
49
+ 5. **Run**: press **Run**. The app starts, deploys its BPMN, hosts its record
50
+ workers, and appears in the **left rail** as **Nano Workforce** with its embedded
51
+ UI (submit a PR, hand over an issue, answer escalations). Stop/Restart from the
52
+ same pane.
53
+
54
+ 6. **Hire agents**: the orchestration is running, but it needs agents to do the
55
+ engineering. See [Hire your agents](#hire-your-agents).
56
+
57
+ ### Updating an installed project
58
+
59
+ When a new version of the extension is published, Studio flags the project with an
60
+ **"Update available"** badge. Click it to review the change, then **Apply**:
61
+
62
+ - Studio does a **three-way merge** against the version you originally scaffolded
63
+ from — new files are added, files only the app changed are updated, and files you
64
+ and the app both changed are auto-merged where they don't overlap.
65
+ - **Conflicts** (a file you and the new version both edited in the same place) are
66
+ listed and **left for you to resolve** — nothing is clobbered silently.
67
+ - Your **data is never touched**: `app.db` (and its WAL/SHM), `node_modules`,
68
+ `.git`, and generated dirs are always preserved. The runtime re-applies
69
+ `db/migrations` on the next boot, so your PRs/rounds/escalations survive the update.
70
+
71
+ Preview first with a dry-run (Studio shows the plan — created / overwritten /
72
+ merged / conflicting — before writing anything).
73
+
74
+ ---
75
+
76
+ ## Run from the CLI (second-class)
77
+
78
+ You can also run Nano Workforce directly, outside Studio, against a running Nano
79
+ engine. This is the second-class path — no left-rail integration or update UI — but
80
+ it's the same app and the same behaviour.
81
+
82
+ ### Prerequisites
83
+
84
+ - A running **Nano gateway/engine** (default `http://localhost:8080`) — what the app
85
+ deploys to and what agents pull jobs from.
86
+ - **[Node](https://nodejs.org/) >= 22.6** (the app hosts on Node built-ins;
87
+ `@nanobpm/urban` declares `engines.node >=22.6`). **[Deno](https://deno.land/)** is
88
+ optional (only for `npm run compile`).
89
+ - The **c8ctl CLI with the `nano` plugin** (to hire/run agents).
90
+ - On each agent host: the **GitHub CLI** logged in (`gh auth login`) or a
91
+ `GITHUB_TOKEN`/`GH_TOKEN` in the environment, plus the agent harness itself (e.g.
92
+ the [Copilot CLI](https://github.com/github/copilot-cli)).
93
+
94
+ ### Install, configure, run
95
+
96
+ ```sh
97
+ npm install
98
+
99
+ export CAMUNDA_REST_ADDRESS=http://localhost:8080/v2 # or NANOBPMN_BASE_URL=http://localhost:8080
100
+ export GITHUB_TOKEN=ghp_... # for the review poller / merge
101
+ export PR_REVIEW_PORT=3000 # app HTTP port (default 3000)
102
+
103
+ npm start # → http://localhost:3000
104
+ # or, via the urban CLI:
105
+ urban run # `urban gen` then run
106
+ ```
107
+
108
+ That deploys the processes, starts the app-hosted record workers, serves the web UI,
109
+ and runs the review-ready poller.
110
+
111
+ ### Upgrade a CLI install
112
+
113
+ ```sh
114
+ npm run upgrade # dry-run against @latest
115
+ npm run upgrade -- --apply # apply the overlay, preserving app.db
116
+ npm run upgrade -- --version 0.26.0 --apply # pin a specific version
117
+ npm run upgrade -- --from ./pkg.tgz --apply # from a local tarball (offline)
118
+ ```
119
+
120
+ The upgrade overlays the new pack's files, preserves your `app.db`/`node_modules`/
121
+ `.git`/generated dirs, and reports what changed. Reinstall deps if `package.json`
122
+ changed, then restart — migrations re-apply on boot, keeping your data.
123
+
124
+ ---
125
+
126
+ ## Hire your agents
127
+
128
+ An agent is a CLI harness (the Copilot CLI here) turned into a Nano job worker. Hire a
129
+ profile whose **rank + capabilities** subscribe it to the `senior:*` job types the
130
+ app emits, then put it to work:
131
+
132
+ ```sh
133
+ c8ctl nano hire \
134
+ --name fleet \
135
+ --rank senior \
136
+ --capabilities pr-review plan plan-review feature fix-ci \
137
+ --command 'copilot -p - --allow-all-tools' \
138
+ --model <your-model>
139
+
140
+ c8ctl nano work fleet # polls every senior:* agent task below until Ctrl-C
141
+ ```
142
+
143
+ `--rank senior` × those five capabilities subscribes the worker to exactly the agent
144
+ task types the three workflows emit (one `senior:<capability>` job type per
145
+ capability):
146
+
147
+ | Capability | Job type | Workflow | Task |
148
+ | --- | --- | --- | --- |
149
+ | `pr-review` | `senior:pr-review` | `convergence-loop` | Review round (drive a PR to convergence) |
150
+ | `plan` | `senior:plan` | `plan-fanout` | Plan an issue into levelized tasks |
151
+ | `plan-review` | `senior:plan-review` | `plan-fanout` | Review the plan before fan-out |
152
+ | `feature` | `senior:feature` | `plan-fanout` | Implement one planned task → open a PR |
153
+ | `fix-ci` | `senior:fix-ci` | `merge-loop` | Green a `blocked` PR's failing checks |
154
+
155
+ - `--command 'copilot -p - --allow-all-tools'` starts the Copilot CLI reading its
156
+ prompt from **stdin** (`-p -`). The harness pipes the whole job JSON (prompt +
157
+ `job.variables`) to stdin; the relevant `prompts/*.md` template tells the agent how
158
+ to read it and where to write its result.
159
+ - **`--allow-all-tools` is essential** for an unattended worker — without it Copilot
160
+ pauses for permission before each tool call and the job stalls.
161
+
162
+ > ⚠️ **Only enable `--allow-all-tools` for code and hosts you trust.** It grants the
163
+ > agent broad unattended permissions (shell, file writes, network). Each job runs in
164
+ > a throwaway per-job workspace, but the worker still runs as your user on the host.
165
+ > Use `--deny-tool` to narrow it, or a container sandbox for stronger isolation.
166
+
167
+ Run a **second** worker (another terminal or machine) and they alternate across
168
+ whichever PRs/tasks are ready — that is the idle time you reclaim. Run more than one
169
+ job per worker with `--max-parallel 2`. The app-hosted `pr.*` workers (record-plan,
170
+ select-wave, finalize, merge, …) run **inside** the app, not on an agent worker.
171
+
172
+ Already have a narrower worker? Extend it in place instead of re-hiring — `c8ctl nano
173
+ assign <name> plan plan-review feature fix-ci` unions the roles onto the profile,
174
+ then restart its worker.
175
+
176
+ ---
177
+
178
+ ## What it does
179
+
180
+ ### Submit a PR → review convergence
181
+
182
+ Submit a PR (from the UI as `owner/repo#123` or a PR URL, the API, or the webhook) and
183
+ one durable `convergence-loop` starts. Each round dispatches a `senior:pr-review`
184
+ agent; between rounds the process **parks on a durable message-catch event**, so agent
185
+ slots and job timeouts are never held hostage to review latency. The poller watches
186
+ GitHub and publishes `review-ready` when a new review lands (no webhook needed — works
187
+ behind NAT).
188
+
189
+ ```
190
+ submit (UI / webhook) ──► convergence-loop (BPMN)
191
+ │ converged ──► finalize ──► (merge stage)
192
+ Review round (agent) ──────┼ addressed ──► record ──► wait review-ready ─┐
193
+ taskType senior:pr-review └ needs_input/blocked ─► escalate ─► wait ────┤
194
+ ▲ escalation-answered │
195
+ └──────────────────────── loop ─────────────────────────────────── ┘
196
+ ```
197
+
198
+ ### Merge stage
199
+
200
+ With `NANO_PR_AUTO_MERGE` on (default), a converged PR flows into `merge-loop`: it
201
+ parks until any `Depends-on:` PRs have landed, arms the merge, auto-detects a merge
202
+ queue (waits for landing) vs a straight squash/merge/rebase, and — on a `blocked`
203
+ verdict (a required check failed) — dispatches a `senior:fix-ci` agent to green the
204
+ branch before escalating (`NANO_PR_MAX_CI_FIX_ROUNDS`, default 3). Conflicts, an
205
+ exhausted budget, or an agent that can't fix the build escalate to a human; answer in
206
+ the UI and the process re-arms and retries.
207
+
208
+ ### Fleet mode: hand it an issue (plan → implement → converge)
209
+
210
+ ```
211
+ issue (UI / POST /hooks/plan) ─► plan-fanout (BPMN)
212
+ plan (senior:plan) ─► record-plan ─► implement × N (parallel, senior:feature) ─► record-results
213
+
214
+ each opened PR ──► convergence-loop (above)
215
+ ```
216
+
217
+ A planning agent decomposes the issue into tasks; a parallel multi-instance activity
218
+ fans them out over implementation agents (one PR per task); `record-results` enrols
219
+ every opened PR into the convergence loop. Submit from the **"Hand an issue to the
220
+ fleet"** form, or:
221
+
222
+ ```bash
223
+ curl -sS -X POST http://localhost:3000/hooks/plan \
224
+ -H 'content-type: application/json' \
225
+ -H "x-hook-secret: $NANO_PR_WEBHOOK_SECRET" \
226
+ -d '{ "issue": "owner/repo#123" }'
227
+ ```
228
+
229
+ ---
230
+
231
+ ## Configuration
232
+
233
+ | env | default | purpose |
234
+ |---|---|---|
235
+ | `PR_REVIEW_PORT` | `3000` | app HTTP port |
236
+ | `NANO_APP_DB_URL` | `file:./app.db` | sqlite datasource |
237
+ | `NANOBPMN_BASE_URL` | `http://localhost:8080` | engine base URL (or set `CAMUNDA_REST_ADDRESS` to the `/v2` REST address directly) |
238
+ | `GITHUB_TOKEN` | — | token for the review poller / merge (or use the host `gh` CLI) |
239
+ | `NANO_PR_GITHUB_TRANSPORT` | `auto` | how the poller reads GitHub: `gh` (host CLI), `token` (`GITHUB_TOKEN` over HTTP), or `auto` |
240
+ | `NANO_PR_POLL_MS` | `60000` | review-ready poll interval |
241
+ | `NANO_PR_MAX_ROUNDS` | `20` | default cap: escalate after N rounds (per-submit override via the form / webhook `maxRounds`; clamped 1–100) |
242
+ | `NANO_PR_WEBHOOK_SECRET` | — | shared secret for `POST /hooks/submit` (`X-Hook-Secret`) |
243
+ | `NANO_PR_AUTO_MERGE` | `1` | after convergence, run the merge stage; `0` = stop at `converged` (review-only) |
244
+ | `NANO_PR_MERGE_METHOD` | `squash` | merge method: `squash`, `merge`, or `rebase` |
245
+ | `NANO_PR_MERGE_ADMIN` | `0` | pass `--admin` to override failing non-required checks (use with care) |
246
+ | `NANO_PR_MAX_CI_FIX_ROUNDS` | `3` | max `senior:fix-ci` attempts to green a `blocked` PR before escalating; `0` disables (escalate immediately), clamped 0–20 |
247
+ | `NANO_PR_REVIEW_WAIT_TIMEOUT` | `PT20M` | ISO-8601 duration the loop waits for a fresh review before escalating a stalled review (timer arm of the `wait-review` gateway) |
248
+ | `NANO_PR_REVIEW_NUDGE_MINUTES` | `5` | cooldown between the poller's automatic reviewer re-request nudges for one waiting PR (clamped 1–1440) |
249
+
250
+ ### Purge
251
+
252
+ The app keeps its own SQLite state (PRs/rounds/escalations) separate from the engine.
253
+ When you purge and restart the engine, wipe the app db too so they stay consistent:
254
+
255
+ ```sh
256
+ npm run purge # deletes app.db (+ WAL/SHM) and re-applies db/migrations
257
+ ```
258
+
259
+ ---
260
+
261
+ ## The agents (external workers)
262
+
263
+ The `senior:*` tasks are serviced by **external** workers — they are **not** in the
264
+ manifest `workers[]`. Point a `c8ctl nano work` daemon (or any Zeebe-style worker) at
265
+ the task types; each job carries its variables (e.g. `senior:pr-review` gets `{prUrl,
266
+ repo, prNumber, round, answer?}` and returns `{status, summary, question?}`). An
267
+ agent's base prompt is **not** in the job payload — it is delivered via a model
268
+ **template header** (`{{review-round}}`, `{{plan}}`, `{{feature}}`, `{{fix-ci}}`, …)
269
+ substituted at deploy time from `prompts/*.md` (`models.templates` in `nano.app.json`);
270
+ per-instance context (e.g. a human's escalation answer) is appended by the harness.
271
+
272
+ ---
273
+
274
+ ## Compile to a native binary
275
+
276
+ The app is authored on Node built-ins, so **Deno** can cross-compile it into a native
277
+ executable that bundles the runtime, deps, and entry code (the target box needs no
278
+ Node/Deno/`node_modules`):
279
+
280
+ ```sh
281
+ npm run compile # → dist/nano-workforce (via deno compile)
282
+ ```
283
+
284
+ > **Not yet a single self-contained file.** The binary bundles the runtime + deps +
285
+ > entry code, but the Urban runtime loads the app's declarative files
286
+ > (`nano.app.json`, `pages/`, `db/migrations/`, `prompts/`, `resources/`, and the
287
+ > `actions/`/`workers/` modules) from the **working directory at runtime** — so ship
288
+ > the binary alongside those app files and run it from that directory. Add `--target`
289
+ > in the `deno.json` `compile` task to cross-compile for another OS/arch.
290
+
291
+ ---
292
+
293
+ ## Architecture & contributing
294
+
295
+ - **[SPEC.md](SPEC.md)** — the behavioural source of truth for the processes.
296
+ - **[AGENTS.md](AGENTS.md)** — the operational guide for anyone (human or AI) making
297
+ changes: engineering principles, the BPMN authoring rules (author the semantic
298
+ model, **generate** the diagram — CI enforces DI freshness), migration policy, and
299
+ the CI gates.
300
+
301
+ ## License
302
+
303
+ Apache-2.0 — see [LICENSE](LICENSE).