@systemfsoftware/agent-pr-review 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Daniel van der Merwe
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/NOTICE ADDED
@@ -0,0 +1,26 @@
1
+ This package includes adaptations of the review instructions from PR-Agent:
2
+
3
+ https://github.com/The-PR-Agent/pr-agent
4
+ Pinned source: 9e6d6a5b40f9ce90bcc085466ba7a42c0837c37a
5
+
6
+ MIT License
7
+
8
+ Copyright (c) 2026 The PR Agent
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,234 @@
1
- # Temporary Holding Version
1
+ # @systemfsoftware/agent-pr-review
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A provider-neutral agent that reviews an exact base-to-head change using a complete change
4
+ index, paged diffs, and immutable source tools. One conversation follows related behavior across
5
+ files. There are no separate patch batches, candidate pipeline, voting, or repository execution.
6
+
7
+ ## Evidence and findings
8
+
9
+ The initial prompt includes every admitted path and its character range in one literal diff
10
+ artifact. Changes up to 32,000 characters are included directly. Larger changes use `read_diff`:
11
+ start at offset zero and follow `nextOffset`, or select a file's start offset from the index.
12
+ Read inline diffs directly without fetching them again. Pages contain at most 32,000 UTF-16
13
+ characters and can cross file boundaries or split lines.
14
+ Original unified patches, hunk coordinates, deletions, renames, and mode metadata remain intact.
15
+
16
+ `list_sources` lists host-authorized dependency aliases, exact commits, and availability separately
17
+ for the consumer's base and head. An empty list means only the reviewed repository is available.
18
+ Source tools accept an optional `source` alias from that inventory; omission selects the reviewed
19
+ repository. Dependency paths are relative to their own tree. There is no ambient installed-package
20
+ or runner filesystem access. An unavailable scope is not retried through guessed paths or public
21
+ web searches for private symbols.
22
+
23
+ `read_file` reads up to 200 lines and 20,000 characters at the exact base or head.
24
+ `find_files` searches filenames. `search_code` searches literal, case-sensitive source text to
25
+ find definitions, callers, consumers, and tests, including unchanged code. Its path filter is a
26
+ filename substring; cursor zero starts the search. Each page scans twenty authorized files,
27
+ returns up to five matching lines per file, and provides `nextCursor` for more files.
28
+ `truncated` identifies omitted matching lines and `unreadablePaths` identifies failed reads.
29
+ A partial or failed search cannot establish that a caller is absent. Start from supplied paths
30
+ and line anchors, read the relevant complete definition, and widen searches only when a concrete
31
+ question requires more context.
32
+
33
+ Hosts can supply `webSearch` with a native provider-executed search tool. The reviewer
34
+ uses official documentation or upstream source to verify external API claims and
35
+ cites supporting URLs in findings. Queries use public identifiers; retrieved text
36
+ is untrusted evidence. Repository source still establishes callers, guards, and impact.
37
+ The host owns search access, provider limits, and billing. The GitHub Action exposes
38
+ this as the opt-in `web-search` input; its usage includes `webSearchCalls`.
39
+
40
+ The reviewer starts with the promised consumer outcome and traces supported execution paths,
41
+ including unchanged callers and consumers. It distinguishes missing promised behavior from
42
+ optional feature expansion. Before recording a defect, it checks the
43
+ strongest relevant guard, documented exception, or alternative interpretation and establishes
44
+ why the supported trigger still causes concrete impact. It checks base/head causation, boundary
45
+ values, cleanup, concurrency, and whether changed tests would detect the claimed failure.
46
+ For changed decisions over fetched records, it checks producers, filters, page limits, ordering,
47
+ older qualifying records, and records that become eligible between reads. It checks nullable guard
48
+ states and traces error fallbacks to reporting sinks. Findings state the required behavior without
49
+ prescribing an exact edit.
50
+ New features must satisfy their stated contracts, including validation, limits, isolation,
51
+ and aggregation; a bypass can be a defect even when the old code also accepted that input.
52
+ Unrelated old bugs, speculation, style, compiler diagnostics, and generic test requests are
53
+ excluded. Incremental reviews limit new findings to defects introduced or newly exposed by their
54
+ exact delta. Each finding must explain the causative follow-up change; an older issue does not
55
+ qualify because it was missed earlier or lies in a touched file. Earlier blockers are verified
56
+ against current source, including unchanged paths, without being reported as new findings.
57
+
58
+ The shared finding rubric, parent review procedure, and host-supplied repository policy are
59
+ separate instructions. Policy findings identify the specific rule and applicable exceptions,
60
+ citing instruction paths and lines when available. An explicitly reviewable architecture
61
+ contract can warrant a finding without a runtime failure; its supplied severity takes precedence.
62
+
63
+ `record_finding` is the only way to add findings to the report. The model is instructed to record
64
+ each distinct root cause once and recover the saved ledger with `review_status` after `new_context`,
65
+ without re-recording an issue with revised wording or severity. Counterevidence must be checked
66
+ before recording because the ledger has no retraction or revision operation. `submit_review` is the
67
+ required native completion tool and accepts only `blockedOn` and `resolutions` metadata.
68
+ The host builds the final report directly from the ledger, so completion never rewrites or merges
69
+ findings. Extra completion fields fail validation.
70
+
71
+ The host validates changed paths and RIGHT-side line anchors, demotes invalid anchors to
72
+ top-level findings, and removes only exact repeated records. Distinct defects at the same path
73
+ and line remain separate. Up to 24 findings are retained, prioritizing blocking over important
74
+ over minor findings. Overflow always marks the result incomplete, regardless of later completion.
75
+ Finding paths, titles, and bodies retain their 512, 200, and 2,000-character bounds.
76
+
77
+ ## Coverage and limits
78
+
79
+ Requests admit up to 1,000 distinct changed paths, 2,000,000 characters per patch, and 8,000,000
80
+ patch characters overall. These are host input limits, separate from the model's working context.
81
+ Source hosts can apply additional authorization and admission bounds.
82
+
83
+ The host tracks diff ranges available to completed model requests. Merely issuing a read, repeating
84
+ a page, skipping ahead, or failing a tool does not establish complete coverage. `pendingPaths`
85
+ includes partially read files. `review_status` recovers saved findings and outstanding ranges;
86
+ its optional cursor pages through the current pending list. While a range remains unread,
87
+ `submit_review` returns a recoverable error with the next unread offset. The same run continues
88
+ under its original budgets. A native budget stop preserves the pending paths and findings as
89
+ incomplete; repeated completion refusals cannot restart the run or reset its allowance.
90
+ Reading all ranges is necessary, but it does not prove that the model assessed every behavior.
91
+
92
+ `review_status` also keeps a bounded investigation notebook for the lifetime of the review.
93
+ Replace it with `notes: { text, expectedRevision }`; text is limited to 4,000 characters and
94
+ stale revisions fail without overwriting newer notes. The response supplies the current text and
95
+ revision. Notes preserve unresolved questions, exact evidence references, and next checks across
96
+ rollover. They are model-authored context, never proof of coverage or a source of findings.
97
+ Only the accepted-update count (`notesUpdates`) leaves the review; note text is not persisted in
98
+ the outcome. Children cannot update the parent's notebook.
99
+ Short reviews need no separate note-taking or final status round when the relevant evidence and
100
+ coverage are already known. Direct submission still checks for unread ranges.
101
+
102
+ Completion means a source-based assessment of the admitted changes and material supported
103
+ hypotheses, not proof of correctness or an exhaustive audit of every dependency. The model can
104
+ report `blockedOn` only for specific unavailable evidence, naming the affected behavior and its
105
+ unavailable source scope or failed retrieval. Missing transitive implementation alone does not
106
+ require auditing an existing dependency; assess changed wiring against available contracts and
107
+ caller evidence without claiming unseen internals were verified. It must still review the remaining
108
+ patches. The bounded reason is retained in the outcome and summary, forces incompleteness, and prevents resolutions.
109
+ Excluded artifacts, lack of live execution, and hypothetical uncertainty do not themselves
110
+ block assessment of the admitted change.
111
+
112
+ Every parent conversation has four concurrent tools and a five-minute deadline. With host
113
+ spending admission (`costControl`), the spending ceiling is the primary budget; 4,096 model turns
114
+ and 16,384 tool calls remain as emergency backstops. Without spending admission, the parent
115
+ retains limits of 128 model turns and 512 tool calls. A cost estimator alone does not raise them.
116
+ The in-memory history store also limits retained history to 1,024 messages and 4 MiB of content.
117
+ Context rollover does not reset those memory limits.
118
+
119
+ The default `compaction: "rollover"` strategy uses a 48,000-token working context to bound
120
+ context growth during large reviews. Hosts can select `compaction: "prune"`
121
+ and an integer `contextTokenLimit` from 16,000 to 128,000. These settings do not widen host input
122
+ admission or create new spending, turn, or tool allowances. Invalid options fail before model work.
123
+
124
+ Native rollover starts a fresh window without a summarizer call. Its bounded recovery excerpt
125
+ may omit unseen tool results, so undelivered diff pages remain unread and must be fetched again.
126
+ Already delivered ranges and saved findings survive. Both strategies support calling `new_context`
127
+ alone with a handoff; original instructions and the complete change index remain available.
128
+ After rollover, the reviewer resumes unread offsets from `review_status`. Once every range has
129
+ been delivered, it follows the remaining investigation notes with targeted reads instead of
130
+ starting another complete diff sweep.
131
+
132
+ Logs identify each successful diff read by character offsets, the first unread offset, and
133
+ whether the whole page had already been delivered. Rollover logs count queued reads discarded
134
+ before delivery. Navigation totals include successful reads, fully repeated reads, status calls,
135
+ accepted note updates, pending paths, and emitted compactions. They contain no source or note text;
136
+ repeated reads can be legitimate evidence checks and do not themselves establish wasted work.
137
+ Failure logs retain the typed error category and specific policy limit. A duration stop is also
138
+ identified as the five-minute deadline in the review summary.
139
+ Hosts can supply a safe `stopReason` through `ReviewCostSnapshot` to explain an incomplete
140
+ review in its summary. Keep provider messages, source text, and credentials out of this diagnostic.
141
+
142
+ Every measured outcome includes `compactions`, an array of emitted native `CompactionPerformed`
143
+ events containing only `kind`, `turn`, `tokensBeforeEstimate`, and `tokensAfterEstimate`.
144
+ An empty array means no event was emitted; absence means the outcome supplied no measurement.
145
+ The array is bounded to 16,384 entries and includes events retained before a typed failure. It does
146
+ not expose source or handoff text, and events alone do not distinguish automatic from requested
147
+ rollovers. Boundaries that fail before event emission are not counted.
148
+
149
+ Without `costControl`, the engine applies a cumulative 416,000-token policy with a 160,000-token
150
+ completion reserve. A host cost estimator alone does not disable it. With `costControl`, the
151
+ host reserves the full possible charge before each provider call, replacing that token quota.
152
+ The [GitHub Action](../../action/README.md) supplies spending admission for supported OpenAI models.
153
+ Recorded findings survive a cost stop without requiring another paid call. `reservedCostMicrousd`
154
+ reports maximum additional charges for sent requests whose usage remains unknown.
155
+
156
+ Token, turn, tool, or cost exhaustion is incomplete. Expected failures preserve recorded findings
157
+ and completed model attempts, including their accounting when no finding was recorded. Context/input-token
158
+ refusals return an incomplete token-exhausted outcome before paid inference when possible.
159
+ Failures before any model attempt, finding, or budget refusal remain typed. Defects and interruption propagate, and every
160
+ resource belongs to the review's Scope. Excluded host `unreviewedPaths` remain separately disclosed.
161
+ An empty result never proves that the repository is defect-free.
162
+
163
+ ## Optional research children
164
+
165
+ The default reviewer runs alone. Experiments can provide `research: { model, concurrency: 2 }`
166
+ to expose native `delegate_research`. Concurrency is either one or two (default two), with at
167
+ most two children established per review. Each child has six ordinary model turns, twelve tool
168
+ calls, a 60-second deadline, and a 32,000-token context using native pruning. The runtime can
169
+ reserve a final completion response after structural exhaustion. The host configures the child
170
+ model's output limit; the eval uses 4,000 tokens.
171
+
172
+ A delegation supplies one unresolved, falsifiable question whose answer could change a finding,
173
+ and one to three distinct admitted changed paths. Instructions ask neutrally for supporting or
174
+ refuting evidence and discourage generic second reviews; children use the same finding rubric.
175
+ The host selects their exact patches, rejecting more than 32,000 total patch characters.
176
+ Children receive the immutable revisions and current saved findings, and can use the
177
+ source inventory and three repository read tools, the host's optional web search, `record_finding`,
178
+ and `finish_research`. The completion contains an evidence summary and incomplete flag; findings go directly to the same canonical ledger.
179
+ Children cannot delegate further, establish parent diff coverage, or resolve prior reviews.
180
+
181
+ Native reservations and child fibers belong to the review's Scope. Child compaction cannot
182
+ change the parent's unread ranges. Child model requirements remain visible in the review's
183
+ Effect requirements, and usage contributes to the existing accounting. A host supplying
184
+ `costControl` must use the same admission service for both model layers, so all requests draw
185
+ from one spending cap. Without host admission, the parent and child native token policies are
186
+ separate; the parent token quota is not a combined spending cap.
187
+
188
+ Research-enabled runs break equal-severity finding ties by their complete serialized values
189
+ before retaining 24, so child completion order cannot select the survivors. Exact duplicates
190
+ are still the only records removed. A rejected delegation, failed or interrupted child,
191
+ unfinished join, child-reported incomplete result, or child budget exhaustion makes the parent
192
+ incomplete and suppresses resolutions. Defects and external interruption still propagate.
193
+
194
+ Measured outcomes include `research` counters: `delegations` counts declared delegation calls;
195
+ `started`, `completed`, `failed`, and `interrupted` count emitted native child events; `incomplete`
196
+ counts completed child results that report incomplete or exhausted work. Zero counts are measured
197
+ zero, while an absent field means no measurement was supplied. Counts contain no child source,
198
+ summary, or transcript; prestart refusals have a declaration but no child event.
199
+
200
+ ## Follow-ups and hosting
201
+
202
+ Hosts can supply up to eight prior `ReviewFollowUp` values, each up to 32,000 characters. The
203
+ reviewer reassesses every blocker against current source and applicable contracts before returning
204
+ its exact ID and evidence that every blocker is fixed, refuted, or obsolete. Unchanged code can
205
+ refute an incorrect premise; a revised PR description alone cannot. Acceptance of a still-valid
206
+ risk belongs to the host's authorized maintainer. `submit_review` refuses unknown or duplicate
207
+ resolution IDs so the reviewer can correct them within the original run budget. Incomplete,
208
+ exhausted, pending-path, or excluded-path results return no resolutions.
209
+ History selection, credentials, dismissal authorization, and publication belong to the host.
210
+
211
+ Hosts can also supply attributed `discussion` evidence, including rebuttals and dismissal reasons.
212
+ The reviewer and optional research children receive it as untrusted input and verify its claims
213
+ against source or contracts. Its `status` discloses partial or unavailable context; it never grants
214
+ dismissal authority or expands discovery scope. Discussion is bounded to 60 entries and 32,000
215
+ serialized characters, with at most 4,000 body characters per entry.
216
+
217
+ ```ts
218
+ const reviewer = makeReviewer({ model, guidance, costControl })
219
+ const program = reviewer.review(request).pipe(Effect.provideService(ReviewRepository, repository))
220
+ ```
221
+
222
+ `ReviewRepository` implementations provide typed Effect operations for `readFile`, `findFiles`,
223
+ and `searchCode`. An optional `dependencySources` inventory admits named dependency scopes;
224
+ without it, tool calls selecting a dependency fail closed. Hosts must bind each admitted alias
225
+ and revision to its declared immutable commit and enforce the same read bounds. Hosts authorize
226
+ source sent to models, pin immutable revisions, enforce read bounds, and treat all source and model output as untrusted. The reviewer has no ambient filesystem
227
+ or network access; optional hosted search is supplied explicitly. `ReviewSource.fromText` applies the shared source-range bounds.
228
+
229
+ The navigable diff approach is informed by [Pullfrog's review workflow](https://github.com/pullfrog/pullfrog/blob/0212dedb0f92b8ba4020c17dc30d3eced32415d7/modes.ts)
230
+ and [Codex's review task](https://github.com/openai/codex/blob/588b781ab4924ce7352488394028e63d74cf807f/codex-rs/core/src/tasks/review.rs).
231
+ These designs do not establish accuracy. The [eval bench](../../tooling/pr-review-eval/README.md)
232
+ measures first-trial detection, false positives, and incomplete runs against adjudicated cases.
233
+ Portions of the original review instructions were adapted from
234
+ [PR-Agent](https://github.com/The-PR-Agent/pr-agent); see `NOTICE` for its MIT attribution.