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