@nanobpm/urban-pr-review-codefirst 1.2.0 → 1.3.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,17 @@
1
+ # [1.3.0](https://github.com/jwulf/urban-pr-review-codefirst/compare/v1.2.1...v1.3.0) (2026-08-03)
2
+
3
+
4
+ ### Features
5
+
6
+ * GET /app/status + cancel-by-prKey affordances ([#8](https://github.com/jwulf/urban-pr-review-codefirst/issues/8)) ([3df7fb3](https://github.com/jwulf/urban-pr-review-codefirst/commit/3df7fb3416625cf3e0170c5612f3671deb4d9563)), closes [#12](https://github.com/jwulf/urban-pr-review-codefirst/issues/12)
7
+
8
+ ## [1.2.1](https://github.com/jwulf/urban-pr-review-codefirst/compare/v1.2.0...v1.2.1) (2026-08-03)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * **deps:** bump @nanobpm/urban to ^0.17.1 ([#7](https://github.com/jwulf/urban-pr-review-codefirst/issues/7)) ([18b866e](https://github.com/jwulf/urban-pr-review-codefirst/commit/18b866e287b018c2dbbbee52a280daf69354851c))
14
+
1
15
  # [1.2.0](https://github.com/jwulf/urban-pr-review-codefirst/compare/v1.1.0...v1.2.0) (2026-08-03)
2
16
 
3
17
 
package/actions/cancel.ts CHANGED
@@ -1,16 +1,30 @@
1
1
  // POST /app/actions/cancel — override the generic row-cancel action. Terminating the engine
2
2
  // instance emits no completion event, so reconcile the app row (status='abandoned', clear the
3
- // open escalation) here.
3
+ // open escalation) here. Accepts either `processInstanceKey` or the `prKey` the status endpoint
4
+ // reports, so a caller can cancel a run it discovered via GET /app/status.
4
5
  import type { ActionHandler } from "@nanobpm/urban";
5
6
  import { cancelRun } from "../app/service.ts";
6
7
 
8
+ const str = (v: unknown): string | undefined => {
9
+ if (v == null) return undefined;
10
+ const s = String(v).trim();
11
+ return s === "" ? undefined : s;
12
+ };
13
+
7
14
  const handler: ActionHandler = async ({ body }, app) => {
8
- const key = (body as { processInstanceKey?: unknown })?.processInstanceKey;
9
- if (key == null || String(key) === "") {
10
- return { status: 400, body: { error: "processInstanceKey is required" } };
15
+ const b = (body ?? {}) as { processInstanceKey?: unknown; prKey?: unknown };
16
+ const processInstanceKey = str(b.processInstanceKey);
17
+ const prKey = str(b.prKey);
18
+ if (!processInstanceKey && !prKey) {
19
+ return { status: 400, body: { error: "processInstanceKey or prKey is required" } };
11
20
  }
12
- const r = await cancelRun(app.data, app.engine, String(key));
13
- return { status: r.ok ? 200 : 404, body: r };
21
+ if (processInstanceKey && prKey) {
22
+ return { status: 400, body: { error: "provide exactly one of processInstanceKey or prKey" } };
23
+ }
24
+ const r = await cancelRun(app.data, app.engine, { processInstanceKey, prKey });
25
+ if (r.ok) return { status: 200, body: r };
26
+ return { status: r.kind === "terminal" ? 409 : 404, body: r };
14
27
  };
15
28
 
16
29
  export default handler;
30
+
@@ -0,0 +1,22 @@
1
+ // GET /app/status — list the PRs currently in flight (every tracked PR not converged/abandoned).
2
+ // A read-only projection over the app datasource so an operator or an external automation
3
+ // harness can see active work — and grab a prKey to cancel — without opening the DB or the UI.
4
+ //
5
+ // Optional shared-secret guard, mirroring /hooks/submit: when NANO_PR_WEBHOOK_SECRET is set,
6
+ // callers must present it via the x-hook-secret header. Unset → open (unchanged default). The
7
+ // pages UI does not call this endpoint (its grid reads the datasource directly), so the guard
8
+ // never affects the UI.
9
+ import type { ActionHandler } from "@nanobpm/urban";
10
+ import { activePrs } from "../app/service.ts";
11
+
12
+ const SECRET = process.env.NANO_PR_WEBHOOK_SECRET ?? "";
13
+
14
+ const handler: ActionHandler = async ({ req }, app) => {
15
+ if (SECRET && req.headers.get("x-hook-secret") !== SECRET) {
16
+ return { status: 401, body: { error: "unauthorized" } };
17
+ }
18
+ const prs = await activePrs(app.data);
19
+ return { status: 200, body: { count: prs.length, prs } };
20
+ };
21
+
22
+ export default handler;
package/app/service.ts CHANGED
@@ -19,6 +19,10 @@ export interface ParsedPr {
19
19
 
20
20
  const now = (): string => new Date().toISOString();
21
21
 
22
+ /** A PR is "done" in exactly these two states; everything else (converging, waiting_review,
23
+ * escalated) is in flight. The status endpoint and the cancel guard both key off this. */
24
+ export const TERMINAL_STATUSES: readonly string[] = ["converged", "abandoned"];
25
+
22
26
  const prs = (data: DataLayer) => data.table<PullRequests>("pull_requests", "pr_key");
23
27
  const rounds = (data: DataLayer) => data.table<Rounds>("rounds", "id");
24
28
  const escalations = (data: DataLayer) => data.table<Escalations>("escalations", "id");
@@ -64,7 +68,7 @@ export async function submitPr(data: DataLayer, parsed: ParsedPr) {
64
68
  const { repo, number, url, prKey } = parsed;
65
69
  const table = prs(data);
66
70
  const existing = await table.get(prKey);
67
- if (existing && !["converged", "abandoned"].includes(existing.status)) {
71
+ if (existing && !TERMINAL_STATUSES.includes(existing.status)) {
68
72
  return { prKey, alreadyRunning: true };
69
73
  }
70
74
  const ts = now();
@@ -109,26 +113,85 @@ export async function answerEscalation(data: DataLayer, prKey: string, answer: s
109
113
  return { ok: true, escalationId };
110
114
  }
111
115
 
112
- /** Cancel a PR's running convergence instance and mark it abandoned. Terminating
113
- * the engine instance emits no completion event (no worker runs), so the app-tier
114
- * flips the PR's status here. */
115
- export async function cancelRun(data: DataLayer, engine: EngineClient, processInstanceKey: string) {
116
- const [pr] = await prs(data).find({ process_key: processInstanceKey });
117
- try {
118
- await engine.cancelInstance({ processInstanceKey });
119
- } catch (err) {
120
- // The instance may already be gone (converged/cancelled) — still reconcile the
121
- // app row so a stale "converging" PR can't linger in the UI.
122
- console.warn(`[cancel] engine cancel for ${processInstanceKey}: ${err}`);
116
+ /** How a caller identifies the run to cancel: by its engine `processInstanceKey` or, more
117
+ * ergonomically, by the `prKey` the status endpoint reports. The cancel action rejects a
118
+ * request that supplies both, so exactly one selector reaches here. */
119
+ export interface CancelSelector {
120
+ processInstanceKey?: string;
121
+ prKey?: string;
122
+ }
123
+
124
+ /** Cancel a PR's running convergence instance and mark it abandoned. Terminating the engine
125
+ * instance emits no completion event (no worker runs), so the app-tier flips the PR's status
126
+ * here. Accepts either selector; a PR already in a terminal state is left untouched so a stale
127
+ * cancel can't overwrite a `converged` outcome with `abandoned`. */
128
+ export async function cancelRun(data: DataLayer, engine: EngineClient, selector: CancelSelector) {
129
+ const { processInstanceKey, prKey } = selector;
130
+ const table = prs(data);
131
+ const pr = prKey
132
+ ? await table.get(prKey)
133
+ : processInstanceKey
134
+ ? (await table.find({ process_key: processInstanceKey }))[0]
135
+ : undefined;
136
+ if (pr && TERMINAL_STATUSES.includes(pr.status)) {
137
+ return { ok: false, kind: "terminal", reason: `PR already ${pr.status}`, prKey: pr.pr_key };
138
+ }
139
+ const instanceKey = pr?.process_key ?? processInstanceKey ?? null;
140
+ if (instanceKey) {
141
+ try {
142
+ await engine.cancelInstance({ processInstanceKey: instanceKey });
143
+ } catch (err) {
144
+ // The instance may already be gone (converged/cancelled) — still reconcile the app row so
145
+ // a stale "converging" PR can't linger in the UI.
146
+ console.warn(`[cancel] engine cancel for ${instanceKey}: ${err}`);
147
+ }
123
148
  }
124
149
  if (pr) {
125
- await prs(data).update(String(pr.pr_key), {
150
+ await table.update(String(pr.pr_key), {
126
151
  status: "abandoned", updated_at: now(),
127
152
  open_escalation_id: null, open_escalation_question: null,
128
153
  });
129
154
  return { ok: true, prKey: pr.pr_key };
130
155
  }
131
- return { ok: false, reason: "no PR for that instance" };
156
+ return { ok: false, kind: "not_found", reason: "no PR for that selector" };
157
+ }
158
+
159
+ /** A PR currently in flight, as reported by the status endpoint. */
160
+ export interface ActivePr {
161
+ prKey: string;
162
+ repo: string;
163
+ number: number;
164
+ url: string;
165
+ title: string | null;
166
+ status: string;
167
+ round: number;
168
+ processKey: string | null;
169
+ waitingSince: string | null;
170
+ openEscalation: string | null;
171
+ updatedAt: string;
172
+ }
173
+
174
+ /** Every tracked PR not in a terminal state (converged/abandoned), newest-updated first. Backs
175
+ * the GET status endpoint so an operator or an external harness can see what is in flight
176
+ * without reading the datasource directly. */
177
+ export async function activePrs(data: DataLayer): Promise<ActivePr[]> {
178
+ const all = await prs(data).all();
179
+ return all
180
+ .filter((p) => !TERMINAL_STATUSES.includes(p.status))
181
+ .sort((a, b) => (a.updated_at < b.updated_at ? 1 : a.updated_at > b.updated_at ? -1 : 0))
182
+ .map((p) => ({
183
+ prKey: p.pr_key,
184
+ repo: p.repo,
185
+ number: p.number,
186
+ url: p.url,
187
+ title: p.title ?? null,
188
+ status: p.status,
189
+ round: p.current_round,
190
+ processKey: p.process_key ?? null,
191
+ waitingSince: p.waiting_since ?? null,
192
+ openEscalation: p.open_escalation_question ?? null,
193
+ updatedAt: p.updated_at,
194
+ }));
132
195
  }
133
196
 
134
197
  /** One poll pass: for each PR waiting on review, fetch fresh GitHub reviews (via the host
package/deno.json CHANGED
@@ -6,15 +6,15 @@
6
6
  "exclude": [".deno-cache/", "nano-generated/"]
7
7
  },
8
8
  "imports": {
9
- "@nanobpm/urban": "npm:@nanobpm/urban@^0.16.1"
9
+ "@nanobpm/urban": "npm:@nanobpm/urban@^0.17.1"
10
10
  },
11
11
  "tasks": {
12
12
  "start": "deno run --allow-net --allow-read --allow-write --allow-run=gh --allow-env main.ts",
13
13
  "purge": "deno run --allow-read --allow-write --allow-env scripts/purge-db.ts",
14
- "check": "deno run -A npm:@nanobpm/urban@^0.16.1 check",
15
- "gen": "deno run -A npm:@nanobpm/urban@^0.16.1 gen",
16
- "gen:check": "deno run -A npm:@nanobpm/urban@^0.16.1 gen --check",
17
- "dev": "deno run -A npm:@nanobpm/urban@^0.16.1 dev",
14
+ "check": "deno run -A @nanobpm/urban check",
15
+ "gen": "deno run -A @nanobpm/urban gen",
16
+ "gen:check": "deno run -A @nanobpm/urban gen --check",
17
+ "dev": "deno run -A @nanobpm/urban dev",
18
18
  "submit": "deno run --allow-net --allow-read --allow-env scripts/submit.ts",
19
19
  "review-ready": "deno run --allow-net --allow-read --allow-env scripts/review-ready.ts",
20
20
  "answer": "deno run --allow-net --allow-read --allow-env scripts/answer.ts",
package/deno.lock CHANGED
@@ -1686,11 +1686,11 @@
1686
1686
  },
1687
1687
  "workspace": {
1688
1688
  "dependencies": [
1689
- "npm:@nanobpm/urban@~0.16.1"
1689
+ "npm:@nanobpm/urban@~0.17.1"
1690
1690
  ],
1691
1691
  "packageJson": {
1692
1692
  "dependencies": [
1693
- "npm:@nanobpm/urban@~0.16.1",
1693
+ "npm:@nanobpm/urban@~0.17.1",
1694
1694
  "npm:@semantic-release/changelog@^6.0.3",
1695
1695
  "npm:@semantic-release/git@^10.0.1",
1696
1696
  "npm:@semantic-release/npm@^13.1.5",
package/nano.app.json CHANGED
@@ -31,6 +31,11 @@
31
31
  "path": "/app/actions/cancel",
32
32
  "module": "actions/cancel.ts"
33
33
  },
34
+ {
35
+ "path": "/app/status",
36
+ "module": "actions/status.ts",
37
+ "method": "GET"
38
+ },
34
39
  {
35
40
  "path": "/app/actions/message",
36
41
  "module": "actions/message.ts"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nanobpm/urban-pr-review-codefirst",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "Code-first (defineFlow) expression of the Nano Urban PR-review convergence app: one durable multi-round loop per PR, BPMN model derived from TypeScript.",
5
5
  "type": "module",
6
6
  "engines": {
@@ -38,7 +38,7 @@
38
38
  "compile": "deno task compile"
39
39
  },
40
40
  "dependencies": {
41
- "@nanobpm/urban": "^0.16.1"
41
+ "@nanobpm/urban": "^0.17.1"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@semantic-release/changelog": "^6.0.3",