opencode-azure-devops-pr-review 0.3.0 → 0.3.2

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 (53) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/README.md +189 -109
  3. package/package.json +2 -11
  4. package/src/attribution.mjs +2 -2
  5. package/src/azure.mjs +18 -3
  6. package/src/config.mjs +5 -0
  7. package/src/host.mjs +44 -0
  8. package/src/plugin.js +2 -1
  9. package/src/runtime.mjs +27 -5
  10. package/src/setup.mjs +49 -21
  11. package/AGENTS.md +0 -164
  12. package/CODE_OF_CONDUCT.md +0 -83
  13. package/CONTRIBUTING.md +0 -84
  14. package/SECURITY.md +0 -38
  15. package/config/settings.example.json +0 -55
  16. package/config/settings.schema.json +0 -316
  17. package/docs/ARCHITECTURE.md +0 -408
  18. package/docs/AZURE_DEVOPS.md +0 -214
  19. package/docs/COMMENTING.md +0 -399
  20. package/docs/DEBUGGING.md +0 -144
  21. package/docs/DEMO.md +0 -195
  22. package/docs/ENTERPRISE.md +0 -205
  23. package/docs/QUICKSTART.md +0 -219
  24. package/docs/RELEASING.md +0 -95
  25. package/docs/ROADMAP.md +0 -241
  26. package/docs/VALIDATION.md +0 -2066
  27. package/docs/VALIDATION_HISTORY.md +0 -1845
  28. package/docs/VERIFICATION.md +0 -42
  29. package/docs/assets/RECORDING.md +0 -131
  30. package/docs/assets/adjust-findings-teaser.gif +0 -0
  31. package/docs/assets/adjust-preview.png +0 -0
  32. package/docs/assets/adjust-publication.png +0 -0
  33. package/docs/assets/example-comments.md +0 -38
  34. package/docs/assets/generate-demo-gif.py +0 -25
  35. package/docs/assets/generate-demo.mjs +0 -141
  36. package/docs/assets/live-azure-readback.png +0 -0
  37. package/docs/assets/live-preview.png +0 -0
  38. package/docs/assets/live-review-teaser.gif +0 -0
  39. package/docs/assets/live-review.png +0 -0
  40. package/docs/assets/quick-review-demo.gif +0 -0
  41. package/docs/assets/record-terminal.py +0 -124
  42. package/docs/assets/render-terminal-demo.py +0 -168
  43. package/docs/assets/review-example.svg +0 -1
  44. package/docs/assets/walkthrough.svg +0 -1
  45. package/docs/releases/v0.1.0.md +0 -74
  46. package/docs/releases/v0.2.0.md +0 -107
  47. package/docs/releases/v0.2.1.md +0 -65
  48. package/docs/releases/v0.2.2.md +0 -76
  49. package/docs/releases/v0.2.3.md +0 -93
  50. package/docs/releases/v0.3.0.md +0 -125
  51. package/install.sh +0 -171
  52. package/scripts/merge-settings.py +0 -120
  53. package/uninstall.sh +0 -50
@@ -1,408 +0,0 @@
1
- # Architecture
2
-
3
- AZPR is an OpenCode V2 plugin distributed as an npm package, a native Git
4
- package or a source archive. Model work runs in private,
5
- role-bound child sessions; deterministic facts and every Azure DevOps write are
6
- runtime code that calls the Azure DevOps Services REST API (api-version 7.1)
7
- with the organization and PAT from AZPR's own settings (or the owner-only file
8
- named by `azure.patFile`). Reviewers read the
9
- repository through AZPR's own read-only tools, which use the same client.
10
-
11
- ## Components
12
-
13
- | File | Responsibility |
14
- | --- | --- |
15
- | `src/plugin.js` | V2 plugin definition and setup entry. |
16
- | `src/setup.mjs` | Native package bootstrap, external settings selection and the deterministic `/pr-setup` command. |
17
- | `src/runtime.mjs` | Registration, hooks, grants, workflows, stage attempts (repair turns and retries), notices, cancellation and lifecycle. |
18
- | `src/host.mjs` | OpenCode compatibility layer: response-shape normalization, capability detection and host constants. |
19
- | `src/config.mjs` | Settings validation, roles, native tool rules, shared prompt policies, prompt variants per mode and agent compilation. |
20
- | `src/session.mjs` | Session create/admit/wait/correlate, host stream continuations, failure classification, interrupt and synthetic notices. |
21
- | `src/tool-queue.mjs` | Bounded Azure DevOps concurrency with per-call timeouts that abort the request, shared by reviewer tools and runtime calls. |
22
- | `src/azure.mjs` | PR URL parsing, the REST client (PR, iterations, changes, items, threads, thread creation), error classification, retries, the per-run file cache and snapshot construction. The only place with REST paths and the api-version. |
23
- | `src/review-tools.mjs` | The reviewers' read-only tools (`azpr_read_diff`, `azpr_read_file`, `azpr_search_code`, `azpr_find_files`, `azpr_list_files`, `azpr_pr_threads`): definitions, argument validation and bounded output. |
24
- | `src/diff.mjs` | Line diffs (Myers) with both line numbers, more context before a change than after, the enclosing block's start, and folding of repeated changes. |
25
- | `src/search.mjs` | Content search: reads the repository zip of one commit once per run (stored or deflated entries; bounded inflation; ZIP64 and encrypted archives refused), keeps its text files in memory and finds literal text, bounded per file and in total. |
26
- | `src/review-work.mjs` | Sharded initial reviews, overflow splitting, sharded verification, the same-file duplicate check, merge and the final version recheck; the quick review and its location and source checks. |
27
- | `src/output.mjs` | Strict model JSON extraction, review acceptance with per-item degradation, and repair prompts. |
28
- | `src/comments.mjs` | Publishable findings per mode, comment-plan validation, title/anchor normalization, stable markers, plan assembly and the safeguards of automatic publication. |
29
- | `src/comment-work.mjs` | Comment planning pages and deterministic, idempotent publication. |
30
- | `src/comment-data.mjs` | Private content-addressed data files for large inputs and observed source. |
31
- | `src/store.mjs` | Persistent reviews, data cleanup, fallback receipt files and the reviewer sessions kept from unfinished runs (released for deletion beyond the review limit). |
32
- | `src/attribution.mjs` | Deterministic reports, provenance, receipts and ledgers. |
33
- | `src/diagnostics.mjs` | Optional private diagnostic files (bounded by `debug.keepRuns`) and stage timing. |
34
- | `src/prompts/` | Shared review rules, role prompts and comment policy. |
35
-
36
- ## Commands and workflows
37
-
38
- The package's `server.js` exports the plugin definition. Native installations
39
- keep configuration outside the package cache, at an explicit absolute
40
- `options.settingsFile` or `${XDG_CONFIG_HOME:-~/.config}/azpr/settings.json`.
41
- Source installations retain their adjacent settings file. `/pr-setup` provides
42
- guidance before settings exist, validates one model and an existing private PAT
43
- file, and writes settings only on the explicit setup command. It makes no model
44
- or Azure request. Changes take effect after a restart; the loaded runtime and
45
- its active grants do not change in place. While settings are missing or
46
- unusable, the review commands answer `SETUP REQUIRED` and name the problem
47
- found at load (no file yet, an unreadable file's error code, invalid JSON, a
48
- validation error or an unusable PAT file), never a setting value; an unknown
49
- key is named only when it looks like a setting name.
50
-
51
- `ctx.command.transform` registers `/pr-check`, `/pr-review`, `/pr-deep`,
52
- `/pr-quick`, `/pr-stop` and `/pr-comment`. A command validates its arguments, registers a run
53
- with its origin lock (and a PR lock for comments), queues a `STARTED` notice and
54
- returns; the workflow continues in the background. The final receipt is queued
55
- to the invoking conversation with up to three attempts and is written to
56
- `receipts/` in the state directory if the conversation cannot be reached.
57
- `PROGRESS` notices report phases (snapshot, shard counts, verification,
58
- planning pages, posting). Notices never start a model response.
59
-
60
- A review command takes at most one flag right after the PR URL (`--preview`,
61
- `--publish`, `--no-comment`); it sets `afterReview` for that run, and other
62
- option-like text there is refused before any request. When the resulting step
63
- is `preview` or `publish`, a COMPLETE review hands on after its receipt is
64
- queued: without publishable findings one notice says so and nothing is planned;
65
- otherwise the runtime starts the comment workflow of `/pr-comment` as a new run
66
- with its own run ID, `STARTED` notice and receipt, under the same origin and
67
- PR locks (a held lock skips the step with a notice naming the command to run).
68
- A stop, timeout or unload while a finished review's report is delivered keeps
69
- the review COMPLETE but hands on nothing.
70
- Automatic publication posts the items no safeguard holds back (`publishPlan`
71
- with `only`): an item whose saved text has an `@<…>` mention, a `javascript:`,
72
- `vbscript:`, `data:` or `file://` link (both also checked after decoding
73
- backslash escapes and character references, script links also without tabs and
74
- line breaks, which a browser drops from a URL), an image, or HTML that embeds
75
- content, runs a script (attributes read from every `<` the way a browser reads
76
- a tag, `hasActiveAttribute`) or hides text waits in the saved plan, and the
77
- receipt names it. Only mentions are checked inside literal code (`withoutCode`
78
- blanks fenced code and code spans where every CommonMark reading agrees, and
79
- leaves the rest of the text checked). A plan without inline comments whose
80
- findings the planner all skipped as `existing-thread` with threads read live
81
- before planning posts nothing (`NOTHING_TO_POST`; only a repeated summary would
82
- be posted). A comment run hands on nothing; non-COMPLETE reviews and an
83
- unloading plugin start nothing.
84
-
85
- Each workflow first runs one **preflight**: `settings.json`, and the PAT file
86
- when `azure.patFile` is set, must be unchanged since load, reserved commands must still be ours, the private agents of the
87
- command's profile are pinned and the models the command uses must exist and
88
- support tools (and offer the variant when a model is set as
89
- `provider/model#variant`). Pinning and the model check are per profile, so a
90
- problem with the quick (or deep) roles or models blocks only the commands that
91
- use them; `/pr-check` reports configured quick and deep models as warnings and says
92
- when the deep models are unset or repeat the review models. Review commands refuse a PR
93
- URL whose organization differs from `azure.organization` before any request.
94
- After preflight, hooks never re-read settings or catalogs.
95
-
96
- ### Review
97
-
98
- 1. **Snapshot** — the PR (identity, status, title, description, repository and
99
- project IDs), its iterations and every page of the latest iteration's
100
- changes (2,000 per request). Head is the latest iteration's source commit;
101
- base is its common commit (merge base), the comparison Azure DevOps shows,
102
- falling back to the target tip with a warning when Azure reports none. A
103
- lagging merge or multiple merge bases are reported as warnings. The PR's
104
- commit messages (newest 100, each shortened to 600 characters) go to the
105
- reviewers as the author's claims about each change; the comment planner
106
- does not get them. A complete change list without files ends the command
107
- before any session (INCOMPLETE, nothing to review); a partial one asks the
108
- reviewers to find the remaining paths.
109
- 2. **Initial reviews** — changed files are sorted and cut into shards of
110
- `workflow.shardFiles`. For each role and shard a private session reviews the
111
- assigned files with a finding-ID range (`F-1…`, `F-1001…`) so IDs never
112
- collide. Up to `workflow.parallelSessions` sessions run at once. Each
113
- reviewer files every concrete defect it finds as a finding: a role's focus
114
- orders its attention and is not a filter, and `report` carries exclusions,
115
- advice and limitations only.
116
- 3. **Overflow** — private sessions may not compact. A compaction the host
117
- attempts in a reviewer's turn opens its message first and is refused, which
118
- ends the turn; that message (or a 413) marks the stage as `overflow`, and the
119
- runtime splits that shard in half and runs both halves (labels
120
- `shard 1/5a`, `1/5b`). OpenCode's opt-in `experimental.background_compaction`
121
- (2.1.4) asks for a summary through the same request before the context is
122
- full and publishes nothing; it is refused before anything is sent and the
123
- turn goes on, so a later failure is classified by its own cause.
124
- 4. **Verification** — findings are grouped by file into shards of at most
125
- `workflow.shardFindings`; shards end only between files, so every finding on
126
- a file reaches the same verifier (a file is split only when it alone has
127
- more findings than a shard holds). Each verifier decides its assigned IDs and may
128
- merge into any original ID; merging is the only place duplicates are
129
- resolved. A decision row is judged by its own fields (an explicit status,
130
- or a merge target on a row without a finding) even when it sits in another
131
- list. A confirmation that moves its finding to another file must say so
132
- with `movedFrom`; otherwise the verifier is asked to confirm or undo the
133
- move, and an unconfirmed move is kept with a warning. The report shows a
134
- moved finding's initial location. Missing or invalid decisions trigger a
135
- repair turn asking only for those IDs; leftovers become UNREVIEWED (or
136
- NEEDS_INFO for incomplete confirmations). A merge whose chain ends at a
137
- finding the same answer rejected or marked NEEDS_INFO gets a repair turn
138
- for the pair; left unresolved, the merged finding is UNREVIEWED. After the
139
- shards are combined the same rule settles merges into findings another
140
- verifier did not confirm, with a warning.
141
- Without candidate findings one verifier still runs: it checks the initial
142
- reports and condenses them into the report's checks and limitations, which
143
- comment planning also uses for the PR summary.
144
- 5. **Duplicate check** — the runtime groups confirmed findings by their final
145
- file. A file whose findings different verifiers confirmed (a verifier moved
146
- one there, or a crowded file was split) lost the one-verifier-per-file
147
- guarantee, so one `dedupe` session per such file, using the verifier model,
148
- compares them and may only merge a finding into another of that file (same
149
- root cause and same correction). Invalid merges get a correction turn and are
150
- otherwise ignored; chains end at the finding that stays; a failed check keeps
151
- every finding and adds a warning. Usually no file qualifies and nothing runs.
152
- 6. **Recheck** — a fresh PR and iteration read compares versions. A changed
153
- head is STALE; a changed base only adds a warning. A failed recheck is a
154
- warning because publication rechecks the head anyway.
155
-
156
- COMPLETE reviews are cached (newest 20) and persisted with the source the
157
- reviewers read, so `/pr-comment` works after a restart in the same conversation.
158
-
159
- ### Quick review
160
-
161
- `/pr-quick` uses the same snapshot, file shards, overflow splitting, stage
162
- retries, watchdog and final version recheck, with one role,
163
- `azpr-quick-reviewer`, per shard (IDs `Q-1`, `Q-1001`, …) and no verifier,
164
- duplicate check or summary session. The reviewer covers the functional and
165
- the risk focus and checks each finding against source it read in its own
166
- session. A defect its files lead it to in another changed file is filed at
167
- that file's defective lines (never at a line that only uses the code), so two
168
- shards can report one defect; comment planning may combine such repeats. The runtime then checks only form and source, never whether a defect
169
- is real:
170
-
171
- - the answer contract of an initial review with a required `location`; a
172
- parsed answer is a usable result only with a `findings` array and at least
173
- one reviewed file or accepted finding;
174
- - the location (`head:` by default, `base:` for content that exists only in
175
- BASE) must exist at that commit with the lines in range, in a file whose
176
- content this session's own `azpr_read_diff` or `azpr_read_file` calls showed
177
- (not the run's cache, another shard's reads or the runtime's own checks).
178
- Only answers that show source count: a binary or oversized side, an empty
179
- file, identical versions or a line, column or hunk past the end show none;
180
- a diff reads a version only through the rows it shows after paging and byte
181
- cuts ("-" BASE, "+" HEAD, a blank mark both; folded repeats none), and an
182
- answer cut to the tool-output limit is no read;
183
- - problems the reviewer can fix get the normal correction turns, with hints
184
- for deleted and renamed files; what is still wrong afterwards becomes
185
- NEEDS_INFO. Passing findings are REPORTED; only records identical in every
186
- field are merged (findings on the same lines stay separate);
187
- - a usable answer that is PARTIAL and names unfinished work (coverage gaps or
188
- assigned files it did not list as reviewed), with nothing left to correct,
189
- gets one **follow-up** turn in the same session within the
190
- `workflow.repairAttempts` budget: continue where the source is readable,
191
- keep a gap only for a limit it cannot close, and return the whole answer
192
- again. A second PARTIAL stands. When the follow-up, or a correction turn
193
- after it, fails or gives no usable answer, the answer it followed stands;
194
- cancellation and context overflow keep their usual handling (overflow
195
- splits the shard). The stage record keeps the outcome (`followUp`). Review
196
- and deep shards have two reviewers and get no follow-up.
197
-
198
- A location on a changed HEAD file may carry an inline comment; a BASE location
199
- or unchanged code stays in the summary index. Shard reports are joined by the
200
- runtime. The review records `verification: "none"` and a coverage summary
201
- (complete, or the number of unreviewed files when it is known and fixed
202
- reasons: a failed shard, a partial change list, reviewer-reported gaps).
203
- COMPLETE needs at least one usable shard; without one the review is PARTIAL
204
- and cannot be commented on.
205
-
206
- Shared prompts mark the passages about where findings come from with
207
- `<!-- azpr:verified -->` and `<!-- azpr:quick -->` blocks. Review and deep
208
- agents get the verified text, so their system prompts are byte-identical to
209
- the files without markers; quick agents get the quick text, which never claims
210
- that findings were verified, confirmed or de-duplicated. A deep agent's system
211
- prompt is the review agent's; only its model (from `models.deep`) differs.
212
-
213
- ### Stage attempts
214
-
215
- A stage attempt creates a fresh role-bound session, admits the JSON payload as
216
- the only prompt, waits for idle and correlates the turn. The handler evaluates
217
- the answer; if it lists issues and a repair prompt, the runtime sends up to
218
- `workflow.repairAttempts` correction prompts in the **same** session (each is a
219
- newly authorized prompt with its own nonce). A transient failure (provider
220
- 408/409/425/429/5xx, missing idle, an unexpected message in the turn) retries
221
- the stage once in a new session (`workflow.stageRetries`). Permanent failures
222
- and cancellations are not retried. Before that, OpenCode itself retries a
223
- failed provider request in the same session (backoff from 2 s, `Retry-After`
224
- up to 15 minutes); it prepares every resend again, so the resend passes the
225
- `context` and `model.request` hooks like any request.
226
-
227
- A **stage inactivity watchdog** (`workflow.stageIdleSeconds`, default 600, 0
228
- turns it off) covers a model stream, a tool or the host that stops responding.
229
- While a stage waits on OpenCode, prompt admissions, model requests, streamed
230
- output, tool starts and ends, approval requests and announced host retries are
231
- activity (an announced retry wait is added to the window), and a running AZPR
232
- tool counts until it returns because its Azure calls have their own timeouts.
233
- Streamed output reaches no hook, so while a stage is watched AZPR follows
234
- OpenCode's session events (`event.subscribe`), which carry one event per
235
- streamed chunk of answer text, reasoning or tool-call input; a host without
236
- them leaves only the hooks. A stage with
237
- no activity for the whole window is stopped: its grant is revoked, its session
238
- interrupted, and it fails with `failure=idle` and an error that names the last
239
- activity, such as `Stage inactivity watchdog stopped this stage: no activity
240
- for 600 s after model request 3 was sent`; the receipt adds an inactivity
241
- notice. It is retried in a new session like a transient failure. Any activity
242
- restarts the window, so this is not the whole-run timeout or step cap the
243
- [roadmap](ROADMAP.md#deferred) defers: a stage that keeps working is never
244
- stopped. The longest quiet stretch in 1,097 normal live stages was 151 s.
245
-
246
- Host stream continuations are accepted for any provider: an errored text-only
247
- assistant message that the host marked for retry, followed by the host's
248
- continuation notice and a successful final text, is joined literally. When the
249
- model starts its answer over instead of continuing (a later fragment opens like
250
- the first), only the restarted text is used.
251
-
252
- Before asking for a correction, a narrow local repair escapes unescaped double
253
- quotes inside closed single-line `code` spans. Corrections for syntax errors ask
254
- for the same content unchanged; answers without JSON are asked for the full
255
- object.
256
-
257
- ### Comments
258
-
259
- `publishableFindings` supplies the findings: CONFIRMED ones and verifier
260
- additions for review and deep, REPORTED ones for a quick review. A saved
261
- review without a verification field is trusted only when its profile is review
262
- or deep. `commentFindings` hands them to planning as a person adjusted them
263
- after a preview (see below); without adjustments they are exactly the
264
- publishable findings. Planning (model) uses pages of at most four findings plus report segments
265
- (on a large PR each page carries the changed files and dispositions of its own
266
- findings and references to the complete lists), with
267
- CONTINUE checkpoints when a page needs more reading: at most three continuation
268
- sessions per page, and a checkpoint without progress or a fourth unfinished
269
- session ends the page, keeping its finished comments and skipping what is open.
270
- Two pages run at a time (`PLANNING_PARALLEL_PAGES`, never more than
271
- `workflow.parallelSessions`), each continuing in its own lane, and nothing a page
272
- sees depends on which page finishes first: only the first page may write the
273
- summary note (the runtime drops a note from any other page without a correction
274
- turn); a page's anchor checks see the HEAD source the runtime fetched for its own
275
- and earlier pages' findings; a checkpoint counts only the page's own details and
276
- the planner tool results the runtime tagged with its page; and pages are
277
- assembled in page order, so markers and their ordinals match planning one page
278
- at a time. After a page fails, no page or continuation session starts, stages
279
- already running finish (with their repairs and retries), and the failure of the
280
- lowest failed page ends the command as before; `/pr-stop` cancels every running
281
- page.
282
- Each page is validated per item: titles, severity labels, path slashes and
283
- HTML comment markers are normalized; anchors are restored against source text
284
- observed during the review; real problems get a repair turn; what remains is
285
- skipped with a reason. A planner skip names one cause, and the runtime checks
286
- the facts it states against the finding, the page's source excerpts and the
287
- live threads it read (a `cannot-anchor` skip whose lines the page showed goes
288
- back for correction). For a quick review an inline comment also needs a
289
- finding located on a changed HEAD file and an anchor found in the observed HEAD
290
- source; otherwise the finding stays in the summary index. The disclosure line
291
- of a quick review's comments names its method (and, in the summary, incomplete
292
- coverage). For a quick review the runtime also groups findings of different
293
- sessions with the same severity on overlapping lines of one HEAD file into
294
- `mergeCandidates`, keeps each group on one page, and accepts a planner's
295
- combined comment (`findingIds`, `mergeReason`) only when its members are in one
296
- group, come from different sessions, share a severity and a line, and the
297
- anchor lies on the shared lines; a refused combination falls back to the valid
298
- single comments and reasoned skips. The summary index gives an accepted
299
- combination one row. The assembled plan stores exact content, offsets and markers.
300
-
301
- The runtime gives each page what it normally needs: the HEAD source around
302
- each finding (the whole file when small) and a digest of every live thread, both
303
- read deterministically; findings are inline. A page usually
304
- finishes in one model request without tools.
305
-
306
- Publication (runtime) rechecks that the PR is active and the head unchanged,
307
- lists every thread, skips items whose marker exists, creates the rest with
308
- `POST …/threads` (right-side `threadContext` for inline items; Azure DevOps adds
309
- the iteration context itself), records each result immediately, and reads all
310
- markers back (`VERIFIED`). Creation results are `POSTED`, `ALREADY_PRESENT`,
311
- `FAILED`, `UNCERTAIN` (resolved by read-back), `UNVERIFIED` or `DELETED` (a
312
- recorded thread whose comment someone deleted on the PR; it is not posted
313
- again). Re-running publication is safe.
314
-
315
- A person's adjustments (`/pr-comment <review-id> --exclude`, `--severity`,
316
- `--reset`) are stored apart from the review, as `review.adjustments`; the
317
- review record, its findings and its report never change. `commentFindings`
318
- leaves excluded findings out and applies changed severities, so the existing
319
- page checks decide titles and inline eligibility, and the planner input gains
320
- an `adjustments` field only while some are active. Two states matter:
321
-
322
- - **Active adjustments** shape planning and the summary index. Published text
323
- must not name an excluded finding: the page checks repair or drop the
324
- planner's own text, and `excludedReferences` checks the assembled preview,
325
- including the summary rows rendered from the review's finding summaries,
326
- and holds publication when one still names an excluded ID.
327
- - **Ever adjusted** (also after `--reset`) keeps the stricter publication
328
- rules. An adjustment is saved together with dropping the earlier preview
329
- before anything else, and a failed save changes nothing; the new preview is
330
- saved strictly as well and dropped when that fails. Such a review is posted
331
- only from a preview planned after its latest adjustment, never planned and
332
- posted in one `--publish`, and once its publication has started it is
333
- neither adjusted nor planned again. Its publication compares the text of
334
- items already on the PR (from the first thread list and from the read-back)
335
- and names in the receipt those that keep their earlier text; nothing posted
336
- is changed.
337
-
338
- ## Authorization and isolation
339
-
340
- Private roles (`azpr-<mode>-functional|risk|verifier|dedupe|comment-plan`, and
341
- `azpr-quick-reviewer|comment-plan`) are hidden
342
- primary agents with explicit models (and variants, when configured). Every
343
- private session gets a grant with the run, role, model and a pending prompt
344
- (text + nonce); a request on another model or variant is refused. Hooks enforce it:
345
-
346
- - `prompt`: only the exact pending runtime prompt is admitted; private agents
347
- cannot be mentioned or delegated.
348
- - `context`: private requests keep only the role's allowlist — AZPR's five
349
- tools, native read/glob/grep and shell when the `shell` setting allows it;
350
- every other tool (other MCP servers, edits, web, delegation, CodeMode) is
351
- removed. Ordinary sessions lose only AZPR's tools. Comment pages that read too
352
- much get their tools removed to force a checkpoint.
353
- - `model.request`: only primary requests after an authorized context; compaction,
354
- generation and title requests are refused (a compaction the host attempts
355
- in the turn ends it as overflow).
356
- - `retry`: host retries continue only while the grant is active; the announced
357
- wait does not count as inactivity. OpenCode prepares the resend again
358
- (`context`, then `model.request`), so it passes the primary-request check.
359
- - `permission` `evaluate`: enforces the `shell` setting for private roles,
360
- allows reads of AZPR's own private data directory and refuses at once any
361
- other request that would wait for an approval (private sessions run
362
- unattended); only shell under `shell: "ask"` or `"inherit"` may wait. A
363
- native read, glob or grep on a repository path is refused with a pointer to
364
- the azpr tools.
365
- - `tool.execute.before`: refuses any tool outside the allowlist and delegation.
366
- - `tool.execute.after`: records tool outcomes and pages large comment-tool
367
- results into private files.
368
- - `prompt`, `model.request`, `retry`, the tool hooks and a pending approval in
369
- `permission` also record the stage's last activity for the inactivity
370
- watchdog, and so do OpenCode's session events for streamed output, followed
371
- only while a stage is watched.
372
-
373
- AZPR registers its tools with `codemode: false` (OpenCode offers only such
374
- tools directly). A tool runs only for an active grant and always on the run's
375
- snapshot repository; it returns numbered, bounded text and, for file reads,
376
- saves the full observed source for comment anchor checks. Failures come back as
377
- visible tool errors so the model can report the gap.
378
-
379
- Every Azure DevOps call — runtime or tool — goes through one queue
380
- (`azure.concurrency`) with a per-call timeout that aborts the HTTP request.
381
- Reads retry network errors, timeouts, throttling (honouring `Retry-After`) and
382
- 5xx twice with backoff; authentication (HTTP 203 sign-in page or 401),
383
- permission, validation and not-found errors and every write fail at once. Files
384
- are cached per run. With debug enabled each call is logged to
385
- `azure-calls.jsonl` (method, call, path or range, attempt, status, duration,
386
- outcome; never comment bodies or credentials). Slots are released in
387
- `finally`, never by a hook. Every request carries the `azure.proxy`,
388
- `azure.caFile` and `azure.verifyTls` transport (Bun's per-request `proxy` and
389
- `tls` options; extra CA certificates are added to the built-in roots). A
390
- rejected certificate fails at once, and an error answer without Azure DevOps'
391
- `X-TFS-ProcessId` header is reported as a proxy's or gateway's answer rather
392
- than as a PAT or permission problem.
393
-
394
- Shell is denied by default. With `shell: "ask"` or `"inherit"` reviewers may run
395
- commands under host permissions; that is real host authority, not a sandbox.
396
- Reviewers have no Azure DevOps write tool at all; only the runtime writes.
397
-
398
- ## Compatibility
399
-
400
- `host.mjs` normalizes list/record response shapes, detects optional capabilities
401
- (`permission.hook`, `tool.transform`) and holds the host continuation text.
402
- Without `permission.hook` the project boundary for native read tools is left to
403
- the host's own permission rules; `/pr-check` shows a WARNING row and reviews
404
- still run.
405
- Receipts note when the detected OpenCode version differs from the tested one
406
- (`TESTED_HOST_VERSION`, 2.1.4).
407
- REST paths and the pinned api-version live only in `azure.mjs`; see
408
- [Azure DevOps access](AZURE_DEVOPS.md) for the API list and version policy.
@@ -1,214 +0,0 @@
1
- # Azure DevOps access
2
-
3
- AZPR calls the Azure DevOps Services REST API itself, with a personal access
4
- token (PAT) from its own settings: alone in a file named by `azure.patFile`
5
- (recommended) or in `azure.pat`. No MCP server is involved and AZPR reads no
6
- other component's configuration.
7
-
8
- ## Configure
9
-
10
- 1. Create a PAT in Azure DevOps (User settings → Personal access tokens) for
11
- **one organization** with these scopes:
12
- - **Code: Read** — PR metadata, iterations, changes and file content;
13
- - **Pull Request Threads: Read & write** — reading discussions and posting
14
- comments.
15
-
16
- Global PATs ("All accessible organizations") stop working on 2026-12-01; use
17
- an organization-scoped token. `Code: Read & write` also works but allows
18
- pushing code, which AZPR never needs.
19
- 2. Put the PAT alone in a file only you can read, set the organization and
20
- that file's absolute path in the installed `plugins/azpr-v2/settings.json`,
21
- and restart OpenCode:
22
-
23
- ```sh
24
- umask 077 && mkdir -p ~/.config/azpr
25
- read -rs -p 'Azure DevOps PAT: ' AZPR_PAT && printf '%s' "$AZPR_PAT" > ~/.config/azpr/pat; unset AZPR_PAT; echo
26
- ```
27
-
28
- ```json
29
- { "azure": { "organization": "YOUR_ORGANIZATION", "patFile": "/home/YOU/.config/azpr/pat" } }
30
- ```
31
-
32
- `"pat": "YOUR_PAT"` in place of `patFile` also works but keeps the secret in
33
- `settings.json`; set one of the two, not both.
34
-
35
- 3. Run `/pr-check <PR URL>`; it reads the PR, its changes, one HEAD and one BASE
36
- file and the discussions without any model request.
37
-
38
- The PAT is sent only to `https://dev.azure.com/<organization>` as
39
- `Authorization: Basic base64(":" + PAT)`, inside a `CONNECT` tunnel when
40
- `azure.proxy` is set. It never appears in receipts, reports,
41
- diagnostics or error messages. AZPR opens `azure.patFile` without following
42
- symbolic links and refuses it unless it is a regular file owned by the OpenCode
43
- user with no group or other access (mode 600) holding one token; it reads the
44
- file at start and again before each command, and a file that changed blocks new
45
- commands until OpenCode restarts. The installer keeps `settings.json` at mode 600
46
- and preserves it on `--replace`; keep it out of repositories and shared profiles.
47
- PR URLs whose organization differs from `azure.organization` are refused before
48
- any request.
49
-
50
- ## Proxies and TLS inspection
51
-
52
- When dev.azure.com is reachable only through a proxy, a direct connection fails
53
- and `/pr-check` reports `network error (ConnectionRefused)` (or a timeout, or
54
- `ENOTFOUND`) under PR metadata. Point AZPR at the proxy in `settings.json` and
55
- restart OpenCode:
56
-
57
- ```json
58
- { "azure": { "proxy": "http://proxy.example.com:8080" } }
59
- ```
60
-
61
- - `azure.proxy` applies only to AZPR's Azure DevOps calls, not to model
62
- providers or other plugins. Credentials go in the URL as
63
- `http://user:password@host:port`, percent-encoded (`@` is `%40`); they are
64
- never shown in reports or diagnostics. Only Basic proxy authentication is
65
- supported; for an NTLM or Kerberos proxy run a local forwarder (such as Px or
66
- Cntlm) and point `azure.proxy` at it. HTTPS requests are tunnelled with
67
- `CONNECT`, so the proxy sees `dev.azure.com:443` but not the PAT, unless it
68
- inspects TLS.
69
- - Many corporate proxies inspect TLS: they present certificates signed by a
70
- company root CA, and requests fail with `the server's TLS certificate was not
71
- accepted (UNABLE_TO_GET_ISSUER_CERT_LOCALLY)` or a similar code. Save that root
72
- CA certificate as a PEM file and set `azure.caFile` to its absolute path; AZPR
73
- trusts it in addition to the built-in roots. On Windows (also for WSL) the
74
- certificate is in the certificate store (certmgr.msc → Trusted Root
75
- Certification Authorities); export it as "Base-64 encoded X.509 (.CER)".
76
- `openssl s_client -proxy host:port -connect dev.azure.com:443 -showcerts`
77
- shows the chain the proxy presents.
78
- - `azure.verifyTls: false` turns certificate checks off for these calls, the
79
- equivalent of `curl -k` or `NODE_TLS_REJECT_UNAUTHORIZED=0`. Anyone who can
80
- intercept the connection can then read the PAT, so use it only when the CA
81
- certificate cannot be obtained. `/pr-check` shows a WARNING row while it is
82
- off.
83
- - Settings and the CA file are read when OpenCode loads AZPR; restart OpenCode
84
- after changing either. `/pr-check` lists the proxy (without credentials) and
85
- the number of extra CA certificates.
86
- - Without `azure.proxy`, OpenCode's runtime (Bun) still honours `HTTPS_PROXY`
87
- and `NO_PROXY` in the OpenCode process environment, and `NODE_EXTRA_CA_CERTS`
88
- for extra CA certificates. Those apply to every connection OpenCode makes,
89
- including model providers; `azure.proxy` and `azure.caFile` limit the change
90
- to AZPR.
91
- - The three settings rely on the per-request proxy and TLS options of Bun's
92
- `fetch`. A runtime whose `fetch` would ignore them makes AZPR refuse to load
93
- instead of connecting directly.
94
-
95
- ## REST API and versions
96
-
97
- Every request pins `api-version=7.1`, the latest **released** version of each
98
- resource below. The service reports, per resource, a minimum of 1.0 or 3.0, a
99
- released version of 7.1 and a maximum of 7.2 (preview). Released versions stay
100
- supported; preview versions may be deactivated 12 weeks after their release,
101
- which is why AZPR does not use 7.2-preview (the MCP 2.9.0 client did). The
102
- fields AZPR reads were compared on 5.0, 5.1, 6.0, 7.0, 7.1 and 7.2-preview
103
- against a live organization and were identical.
104
-
105
- Paths are relative to
106
- `https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repository}/`.
107
-
108
- | Use | Request | Scope |
109
- | --- | --- | --- |
110
- | PR identity, status, title, description, refs | `GET pullRequests/{id}` | Code (Read) |
111
- | Iterations: latest source commit and merge base (`commonRefCommit`) | `GET pullRequests/{id}/iterations` | Code (Read) |
112
- | Changed files of the latest iteration against the merge base | `GET pullRequests/{id}/iterations/{n}/changes?$top=2000&$skip=` | Code (Read) |
113
- | The PR's commit messages (newest 100), reviewer context | `GET pullRequests/{id}/commits?$top=100` | Code (Read) |
114
- | Discussions, existing markers and read-back | `GET pullRequests/{id}/threads` | Code (Read) or Pull Request Threads |
115
- | Summary and inline comments | `POST pullRequests/{id}/threads` | Pull Request Threads (Read & write) or Code (Read & write) |
116
- | File content and folder listings at a commit | `GET items?path=…` / `GET items?scopePath=…&recursionLevel=…` with `versionDescriptor.versionType=commit` | Code (Read) |
117
- | The whole repository at a commit as a zip, for content search | `GET items?scopePath=/&recursionLevel=Full&$format=zip` with `versionDescriptor.versionType=commit` | Code (Read) |
118
-
119
- Azure DevOps Server (on-premises) supports 7.1 from Azure DevOps Server 2022.1,
120
- but AZPR accepts only Azure DevOps Services URLs (`dev.azure.com/<org>` and
121
- `<org>.visualstudio.com`).
122
-
123
- ## Who calls what
124
-
125
- - **Runtime** (deterministic code): the snapshot (PR, iterations, all change
126
- pages, commit messages), the final version recheck and the pre-publication recheck (PR and
127
- iterations), `/pr-check` reads, the discussion digest for comment planning,
128
- HEAD source excerpts for planning, thread creation and marker read-back.
129
- - **Reviewers** (models) use six read-only AZPR tools, visible only in AZPR's
130
- private sessions and always bound to the run's repository. Every answer
131
- stays below 48,000 UTF-8 bytes: OpenCode keeps only a preview of a tool
132
- output over its default limit of 51,200 bytes, and private reviewers cannot
133
- read the rest it saves:
134
- - `azpr_read_diff` — what the PR changed in one file: BASE → HEAD hunks with
135
- both line numbers, 5 unchanged lines before and 3 after each change
136
- (extended to the start of the enclosing block when it is near). A change
137
- repeated at least three times in a file with only different strings or
138
- numbers is folded to one line per repeat listing the values that differ.
139
- The diff is computed locally from the two file reads below;
140
- - `azpr_read_file` — one file at `head`, `base` or a full commit SHA as
141
- numbered lines, at most 1,000 lines (45,000 bytes) per call; a line longer
142
- than one read is returned in parts with `startColumn`, keeping its line
143
- number, so no source is out of reach;
144
- - `azpr_search_code` — literal text in the contents of every text file at
145
- `head`, `base` or a commit, changed or not, as `path:line: text` matches
146
- (at most 100, 20 per file), optionally limited to a folder or a name glob.
147
- The runtime downloads the repository once per run and commit as a zip
148
- (at most `azure.archiveMegabytes`, 100 MB by default) and searches it in memory; files over 2 MB, binary files
149
- and anything beyond 256 MB of text are not searched, and ZIP64 or
150
- encrypted archives make the tool answer that search is unavailable. Azure
151
- DevOps Code Search is not used: it searches
152
- [indexed branches](https://learn.microsoft.com/en-us/azure/devops/project/search/functional-code-search?view=azure-devops)
153
- rather than an arbitrary commit; AZPR searches the repository snapshot at
154
- the selected commit;
155
- - `azpr_find_files` — repository paths by name or glob, from one recursive
156
- listing per commit and folder (read once per run); names only;
157
- - `azpr_list_files` — one folder's entries (optionally recursive), at most
158
- 1,000 entries;
159
- - `azpr_pr_threads` — live discussion threads, filterable by path or thread ID.
160
-
161
- Ordinary OpenCode sessions do not see these tools, and private sessions see no
162
- other tools except native read/glob/grep (and shell when the `shell` setting
163
- allows it). There are no write tools for models.
164
-
165
- ## Snapshot semantics
166
-
167
- - **head** is the latest iteration's source commit (the code under review).
168
- - **base** is that iteration's common commit with the target branch (the merge
169
- base), the comparison Azure DevOps shows in the PR's Files view. When Azure
170
- reports no merge base, base is the target branch tip and the report says so.
171
- - **files** are the latest iteration's changes against the merge base, read in
172
- pages of 2,000 until Azure reports no further page.
173
- - Only a changed head makes a review STALE; a moved base is a warning.
174
-
175
- ## Reliability
176
-
177
- - All calls share one queue (`azure.concurrency`) with a per-call timeout
178
- (`azure.callTimeoutSeconds`) that aborts the HTTP request and frees the slot.
179
- AZPR switches off the runtime's own idle limit for these requests (Bun's
180
- fetch would end a call that receives nothing for five to six minutes), so a
181
- longer timeout takes effect.
182
- - Reads retry network errors, timeouts, throttling (429, honouring
183
- `Retry-After` up to 60 seconds) and 5xx responses twice with backoff.
184
- - Writes are never retried. A write whose outcome is unknown (timeout, a lost
185
- connection after sending, or a 5xx from a proxy or gateway that may have
186
- forwarded it) is recorded as uncertain and resolved by reading the markers
187
- back; publishing again is always safe.
188
- - A certificate that is not trusted fails at once: the handshake failed, so
189
- nothing was sent. An error answer without Azure DevOps' `X-TFS-ProcessId`
190
- response header (which Azure DevOps puts on every answer) is reported as the
191
- answer of a proxy or gateway, not as a PAT or permission problem.
192
- - Files are read once per run and cached; binary files (a NUL byte in the first
193
- 8,000 bytes) and files over 10 MB are reported, not shown.
194
-
195
- ## Troubleshooting
196
-
197
- | Message | Meaning |
198
- | --- | --- |
199
- | `Azure DevOps rejected the PAT for organization "x" (HTTP 203)` (or 401) | The PAT is invalid, expired, revoked or not valid for this organization. Azure answers with a sign-in page (HTTP 203) instead of 401. |
200
- | `Azure DevOps refused … (HTTP 403 …)` | The PAT lacks a scope or the user lacks access to the project or repository. |
201
- | `azure.patFile could not be used (…)` | The file is missing, a symbolic link, not a regular file, owned by another user, accessible by group or others (`chmod 600` it) or larger than 4 KB. |
202
- | `azure.patFile must hold only the Azure DevOps PAT (…)` | The file is empty, holds more than one token or still a placeholder. |
203
- | `azure.patFile changed since OpenCode loaded it` | Restart OpenCode to use the new PAT; running commands keep the old one. |
204
- | `Azure DevOps could not find … (HTTP 404 TF…)` | Wrong project, repository, PR ID or path; Azure's error code is shown. |
205
- | `The PR belongs to organization "x", but azure.organization is "y"` | Configure the PAT and organization of that PR. |
206
- | `… did not finish within the per-call timeout` | Azure DevOps or the network did not answer; reads were retried. |
207
- | `network error (ConnectionRefused)` (or `ETIMEDOUT`, `ENOTFOUND`) | OpenCode cannot reach dev.azure.com; behind a corporate proxy set `azure.proxy`. With a proxy set, the proxy itself is unreachable. |
208
- | `the server's TLS certificate was not accepted (…)` | A proxy inspects HTTPS with its own CA (or the clock is wrong); set `azure.caFile`. Not retried. |
209
- | `A proxy refused … it requires authentication (HTTP 407)` | Put the proxy credentials in `azure.proxy`. |
210
- | `A proxy or gateway answered … instead of Azure DevOps` | A proxy or firewall answered (no Azure DevOps response headers), for example for a blocked destination; check its policy for dev.azure.com. |
211
- | `The PR has no source/base commit yet` | Azure DevOps has not finished evaluating the PR; retry shortly. |
212
-
213
- Exact-host fixtures set `AZPR_TEST_AZURE_BASE_URL` to a loopback fake service;
214
- any other host is refused, so the PAT can only reach `dev.azure.com`.