@nanobpm/urban-pr-review-codefirst 1.0.0 → 1.1.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ # [1.1.0](https://github.com/jwulf/urban-pr-review-codefirst/compare/v1.0.0...v1.1.0) (2026-07-31)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **ci:** sync package-lock to @nanobpm/workflow@0.4.0 ([57aa919](https://github.com/jwulf/urban-pr-review-codefirst/commit/57aa919e4f5f1dbc2e9022cda19b2aa1594dff50)), closes [#1](https://github.com/jwulf/urban-pr-review-codefirst/issues/1)
7
+
8
+
9
+ ### Features
10
+
11
+ * emit senior:pr-review so one reviewer serves both apps ([#1](https://github.com/jwulf/urban-pr-review-codefirst/issues/1)) ([0d3e39b](https://github.com/jwulf/urban-pr-review-codefirst/commit/0d3e39b112ce6cfb9d56874247f7d34d85e3e4fd))
12
+
1
13
  # 1.0.0 (2026-07-31)
2
14
 
3
15
 
package/README.md CHANGED
@@ -17,6 +17,152 @@ them (`convergence-loop.bpmn` + `workers/*/worker.ts`), code-first writes them
17
17
  (`workflows/convergence-loop.ts`, with the record steps hosted in-process). See
18
18
  [Persistence](#persistence) and [Frontend](#frontend) below.
19
19
 
20
+ ## HOWTO: run agents that converge PRs for you, all day
21
+
22
+ ### The problem this solves
23
+
24
+ Driving a PR to convergence is mostly *waiting*: open a review, wait 5–15 min for
25
+ the reviewer, address the comments, re-request, wait again — often ten rounds
26
+ deep, escalating to a human only when the reviewer is stuck. If a single agent
27
+ babysits one PR, it spends almost all of its time **idle-polling** a review that
28
+ hasn't landed yet. That is wasted wall-clock and a wasted worker slot.
29
+
30
+ This app inverts that. **The BPMN process the SDK derives owns the durable wait**
31
+ between rounds (a real `w.signal` message-catch event), so no agent is ever parked
32
+ holding a job slot while a review is pending. Instead you **hire a couple of agent
33
+ workers once**, and they pull `senior:pr-review` jobs from *whatever PR is ready
34
+ right now* — alternating across all in-flight reviews. Two agents can keep a dozen
35
+ PRs converging in parallel, and they only run when there is actual work to do.
36
+
37
+ Because the `review-round` task overrides its job type to **`senior:pr-review`**
38
+ (via `w.task("review-round", { jobType: "senior:pr-review" })`), the *same* hired
39
+ reviewer services both this code-first app and the model-first
40
+ [urban-pr-review](../urban-pr-review). Set it up by: **(1)** running this app,
41
+ **(2)** submitting PRs, and **(3)** hiring agent workers with
42
+ [`c8ctl nano`](https://github.com/jwulf/c8ctl-plugin-nano).
43
+
44
+ ### 0. Prerequisites
45
+
46
+ - A running **Nano gateway/engine** (default `http://localhost:8080`). This is
47
+ what the app deploys to and what agents pull jobs from.
48
+ - **[Deno](https://deno.land/)** (to run this app) and the **c8ctl CLI with the
49
+ `nano` plugin** installed (to hire/run agents).
50
+ - On each machine that will *host an agent*: the **GitHub CLI** logged in
51
+ (`gh auth login`) or a `GITHUB_TOKEN`/`GH_TOKEN` in the environment, and the
52
+ agent harness itself — e.g. the **[Copilot CLI](https://github.com/github/copilot-cli)**
53
+ (`copilot`).
54
+
55
+ ### 1. Install the app into your Nano IDE
56
+
57
+ Open the Nano console and **Projects → Import by reference**, pointing at this
58
+ app's folder (ADR 0041), or drop a `*.project-ref.json` next to your other
59
+ projects. `nano-ide.ext.json` marks it as an example. You can also just run it
60
+ standalone (next step) — the IDE import is only needed to launch/manage it from
61
+ the console.
62
+
63
+ ### 2. Start the app
64
+
65
+ ```sh
66
+ deno task start # → http://localhost:3000
67
+ ```
68
+
69
+ That applies the DB migrations, deploys the derived flow, hosts the in-process
70
+ `w.run` record steps, serves the web UI at **<http://localhost:3000>**, and runs
71
+ the review-ready poller (which needs `GITHUB_TOKEN` to watch GitHub — without it,
72
+ re-reviews come only from the UI/CLI). Point it at a non-default gateway with
73
+ `NANOBPMN_BASE_URL`; change the port with `PR_REVIEW_PORT`.
74
+
75
+ ### 3. Submit a PR
76
+
77
+ From the web UI, or from the CLI:
78
+
79
+ ```sh
80
+ deno task submit https://github.com/owner/repo/pull/42 5 # 5 = maxRounds
81
+ ```
82
+
83
+ Each submitted PR starts one durable `convergence-loop` instance that parks until
84
+ an agent services its `senior:pr-review` round.
85
+
86
+ ### 4. Hire an agent worker
87
+
88
+ An agent is a CLI harness (Copilot CLI here) turned into a Nano job worker. Hire a
89
+ profile whose **rank + capability** produce the `senior:pr-review` token this
90
+ flow's task emits:
91
+
92
+ ```sh
93
+ c8ctl nano hire \
94
+ --name reviewer \
95
+ --rank senior \
96
+ --capabilities pr-review \
97
+ --command 'copilot -p - --allow-all-tools' \
98
+ --model <your-model>
99
+ ```
100
+
101
+ - `--rank senior` + `--capabilities pr-review` makes the worker subscribe to the
102
+ `senior:pr-review` job type — exactly the token this flow's `review-round` task
103
+ emits (thanks to the SDK job-type override), so **one profile serves both apps.**
104
+ - `--command 'copilot -p - --allow-all-tools'` starts the Copilot CLI reading its
105
+ prompt from **stdin** (`-p -`). The harness pipes the whole job JSON (prompt +
106
+ `job.variables`: `prUrl`, `repo`, `prNumber`, `round`, `answer?`) to stdin; the
107
+ review-round instructions tell the agent how to read it and where to write its
108
+ result.
109
+ - **`--allow-all-tools` is the crucial flag.** Without it, Copilot pauses to ask
110
+ permission before each tool call — and an unattended worker has no human to
111
+ answer, so the job stalls. `--allow-all-tools` lets it run the whole round
112
+ non-interactively. (Pair with `--deny-tool` to blocklist specific tools.)
113
+
114
+ > ⚠️ **Only enable `--allow-all-tools` for code and hosts you trust.** It grants
115
+ > the agent unattended, broad permissions (shell, file writes, network). Each
116
+ > job runs in a throwaway per-job workspace (see below), but the worker still
117
+ > runs as your user on the host — don't point it at untrusted PRs on a shared
118
+ > machine. Use `--deny-tool` to narrow it, or a container sandbox for stronger
119
+ > isolation.
120
+
121
+ > If you'd rather not override the job type in the flow, you can instead leave the
122
+ > derived `convergence-loop:review-round` type and point a worker at it explicitly
123
+ > with `c8ctl nano work reviewer --job-type convergence-loop:review-round`. This
124
+ > app ships with the `senior:pr-review` override so it shares a reviewer with the
125
+ > model-first app out of the box.
126
+
127
+ ### 5. Put the agent to work
128
+
129
+ ```sh
130
+ c8ctl nano work reviewer # polls for senior:pr-review jobs until Ctrl-C
131
+ ```
132
+
133
+ Now every PR you submit gets picked up automatically. Start a **second** worker
134
+ (same command, another terminal or another machine) and the two alternate across
135
+ whichever PRs are ready — that is the idle-time you reclaim. Run more than one job
136
+ at once per worker with `--max-parallel 2`.
137
+
138
+ ### Isolation — each job gets its own clean workspace
139
+
140
+ In the default **host mode** (`--sandbox none`), the worker provisions a
141
+ **throwaway, per-job workspace**: a fresh clone under `<state>/agent-runs/run-*`
142
+ checked out on the PR's head branch, exposed to the agent as `AGENT_WORKSPACE` /
143
+ `REPO_URL` / `REPO_BRANCH` / `REPO_REF`, and **reaped after the job**. So multiple
144
+ agents on one host don't step on each other. Host workers inherit *your*
145
+ `gh`/`GITHUB_TOKEN` login, so no extra auth is needed. Docker/podman sandboxes
146
+ exist (`--sandbox docker --image …`) for stronger isolation, but container-side
147
+ git provisioning is a later increment — container jobs don't clone yet, and don't
148
+ inherit your host login (pass credentials via `--secret-resolver host` /
149
+ `secretRefs`). For the review loop, **host mode is the recommended setup.**
150
+
151
+ ### Run it across spare hardware (incl. a Raspberry Pi)
152
+
153
+ Nano ships ARM binaries (arm64/armv7/armv6), so the whole thing scales down nicely:
154
+
155
+ - **All-in-one:** run the gateway, this app, and one or two workers on your laptop.
156
+ - **Distributed:** run the **Nano gateway on a Raspberry Pi** (always-on, low
157
+ power), run this app anywhere, and put **agent workers on spare machines** — each
158
+ worker just needs the c8ctl CLI, the Copilot CLI logged in, and
159
+ `NANOBPMN_BASE_URL` pointed at the Pi. Add or remove workers at will; the BPMN
160
+ process holds all durable state, so workers are stateless and disposable.
161
+
162
+ The payoff: instead of one agent burning wall-clock polling a single PR, a small
163
+ pool of always-available workers keeps every open review converging — and idles to
164
+ zero cost when there's nothing to do.
165
+
20
166
  ## The flow
21
167
 
22
168
  `workflows/convergence-loop.ts`:
@@ -35,8 +181,10 @@ loop:
35
181
  ```
36
182
 
37
183
  - **`review-round`** is a `w.task` — an **external** worker. Point a coding-agent
38
- harness at the job type `convergence-loop:review-round` (e.g. `c8ctl nano hire`).
39
- The app never hosts or names it; it only owns the durable orchestration around it.
184
+ harness at the job type `senior:pr-review` (e.g. a `c8ctl nano hire`d rank
185
+ `senior` + capability `pr-review` profile — the same one that services the
186
+ model-first app). The app never hosts or names it; it only owns the durable
187
+ orchestration around it.
40
188
  - **`persist-*`** and **`persist-converged`** are `w.run` — app-hosted handlers.
41
189
  `persist-round` returns `{ round: round + 1 }`; that return value (not an
42
190
  ioMapping) is the loop's only state mutation.
@@ -55,7 +203,7 @@ the generated BPMN as `nano:shape` + `io.nanobpm.dataEnvelope` properties.
55
203
 
56
204
  | Step | Derived job type / message |
57
205
  | --- | --- |
58
- | `review-round` (external) | `convergence-loop:review-round` |
206
+ | `review-round` (external) | `senior:pr-review` (overridden via `w.task("review-round", { jobType: "senior:pr-review" })`) |
59
207
  | `persist-round` | `convergence-loop:persist-round` |
60
208
  | `persist-escalation` | `convergence-loop:persist-escalation` |
61
209
  | `persist-escalation-maxrounds` | `convergence-loop:persist-escalation-maxrounds` |
@@ -95,8 +243,8 @@ deno task purge
95
243
  ```
96
244
 
97
245
  The reviewer itself is not started by `deno task start` — it is the external
98
- `convergence-loop:review-round` job. Host it with a coding-agent harness so the
99
- automated review is fully decoupled from the durable orchestration.
246
+ `senior:pr-review` job. Host it with a coding-agent harness so the automated
247
+ review is fully decoupled from the durable orchestration.
100
248
 
101
249
  Environment overrides: `PR_REVIEW_PORT` (default `3000`), `NANOBPMN_BASE_URL`
102
250
  (gateway), `NANO_APP_DB_URL` (default `file:./app.db`), `NANO_PR_POLL_MS`
@@ -2,13 +2,13 @@
2
2
  "$schema": "https://unpkg.com/@camunda/zeebe-element-templates-json-schema@0.44.0/resources/schema.json",
3
3
  "id": "io.nanobpm.urban.pr-review-round-codefirst",
4
4
  "name": "PR Review Round (agent, code-first)",
5
- "description": "One decoupled review round serviced by an external agent (e.g. a Copilot instance via `c8ctl nano work`). The agent reads the latest review, addresses it, pushes, re-requests review, and returns a structured status. Mirrors the model-first template, bound to the code-first derived job type.",
5
+ "description": "One decoupled review round serviced by an external agent (e.g. a Copilot instance via `c8ctl nano work`). The agent reads the latest review, addresses it, pushes, re-requests review, and returns a structured status. Mirrors the model-first template, bound to the shared `senior:pr-review` reviewer job type the flow now emits.",
6
6
  "appliesTo": ["bpmn:Task"],
7
7
  "elementType": { "value": "bpmn:ServiceTask" },
8
8
  "properties": [
9
9
  {
10
10
  "type": "Hidden",
11
- "value": "convergence-loop:review-round",
11
+ "value": "senior:pr-review",
12
12
  "binding": { "type": "zeebe:taskDefinition:type" }
13
13
  },
14
14
  {
package/deno.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "exclude": [".deno-cache/", "nano-generated/"]
7
7
  },
8
8
  "imports": {
9
- "@nanobpm/workflow": "npm:@nanobpm/workflow@^0.3.0",
9
+ "@nanobpm/workflow": "npm:@nanobpm/workflow@^0.4.0",
10
10
  "@nanobpm/domain": "./nano-generated/domain.ts",
11
11
  "@nanobpm/data": "./nano-generated/data-sdk.ts",
12
12
  "@nanobpm/app": "./nano-generated/app-pages.ts",