@atmin.ai/review 0.1.0-alpha.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.
- package/DEPENDENCIES.md +15 -0
- package/LICENSE +55 -0
- package/NOTICE +6 -0
- package/README.md +144 -0
- package/dist/assessment.d.ts +26 -0
- package/dist/assessment.js +88 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +100 -0
- package/dist/contracts.d.ts +625 -0
- package/dist/contracts.js +86 -0
- package/dist/cost-report.d.ts +40 -0
- package/dist/cost-report.js +42 -0
- package/dist/github/api.d.ts +66 -0
- package/dist/github/api.js +190 -0
- package/dist/github/checks.d.ts +11 -0
- package/dist/github/checks.js +42 -0
- package/dist/github/cli.d.ts +2 -0
- package/dist/github/cli.js +94 -0
- package/dist/github/config.d.ts +16 -0
- package/dist/github/config.js +41 -0
- package/dist/github/runner.d.ts +7 -0
- package/dist/github/runner.js +67 -0
- package/dist/github/store.d.ts +40 -0
- package/dist/github/store.js +134 -0
- package/dist/github/task.d.ts +1 -0
- package/dist/github/task.js +29 -0
- package/dist/github/webhook.d.ts +6 -0
- package/dist/github/webhook.js +119 -0
- package/dist/github/worker.d.ts +19 -0
- package/dist/github/worker.js +209 -0
- package/dist/investigation.d.ts +198 -0
- package/dist/investigation.js +276 -0
- package/dist/openai-model.d.ts +2 -0
- package/dist/openai-model.js +41 -0
- package/dist/openrouter-model.d.ts +2 -0
- package/dist/openrouter-model.js +90 -0
- package/dist/provider-error.d.ts +10 -0
- package/dist/provider-error.js +21 -0
- package/dist/render.d.ts +4 -0
- package/dist/render.js +56 -0
- package/dist/run.d.ts +6 -0
- package/dist/run.js +39 -0
- package/dist/snapshot.d.ts +46 -0
- package/dist/snapshot.js +246 -0
- package/package.json +47 -0
- package/profiles/baseline-deepseek.json +10 -0
- package/profiles/smoke-openai.json +10 -0
- package/profiles/smoke-openrouter-free.json +10 -0
package/DEPENDENCIES.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Dependency inventory
|
|
2
|
+
|
|
3
|
+
Runtime and development dependencies from the lockfile. Each retains its license.
|
|
4
|
+
|
|
5
|
+
| Package | Version | License | Use |
|
|
6
|
+
|---|---|---|---|
|
|
7
|
+
| @types/node | 24.13.3 | MIT | Development |
|
|
8
|
+
| ajv | 8.20.0 | MIT | Runtime |
|
|
9
|
+
| fast-deep-equal | 3.1.3 | MIT | Runtime |
|
|
10
|
+
| fast-uri | 3.1.7 | BSD-3-Clause | Runtime |
|
|
11
|
+
| json-schema-traverse | 1.0.0 | MIT | Runtime |
|
|
12
|
+
| openai | 7.12.1 | Apache-2.0 | Runtime |
|
|
13
|
+
| require-from-string | 2.0.2 | MIT | Runtime |
|
|
14
|
+
| typescript | 5.9.3 | Apache-2.0 | Development |
|
|
15
|
+
| undici-types | 7.18.2 | MIT | Development |
|
package/LICENSE
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
|
|
5
|
+
http://www.apache.org/licenses/
|
|
6
|
+
|
|
7
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
8
|
+
|
|
9
|
+
1. Definitions.
|
|
10
|
+
|
|
11
|
+
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
|
|
16
|
+
|
|
17
|
+
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
|
|
18
|
+
|
|
19
|
+
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
|
|
20
|
+
|
|
21
|
+
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
|
|
22
|
+
|
|
23
|
+
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
|
|
24
|
+
|
|
25
|
+
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
|
|
26
|
+
|
|
27
|
+
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
|
|
28
|
+
|
|
29
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
|
|
30
|
+
|
|
31
|
+
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
|
|
32
|
+
|
|
33
|
+
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
|
|
34
|
+
|
|
35
|
+
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
|
|
36
|
+
|
|
37
|
+
You must give any other recipients of the Work or Derivative Works a copy of this License; and
|
|
38
|
+
|
|
39
|
+
You must cause any modified files to carry prominent notices stating that You changed the files; and
|
|
40
|
+
|
|
41
|
+
You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
|
|
42
|
+
|
|
43
|
+
If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
|
|
44
|
+
|
|
45
|
+
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
|
|
46
|
+
|
|
47
|
+
6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
|
|
48
|
+
|
|
49
|
+
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
|
|
50
|
+
|
|
51
|
+
8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
|
|
52
|
+
|
|
53
|
+
9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
|
|
54
|
+
|
|
55
|
+
END OF TERMS AND CONDITIONS
|
package/NOTICE
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
atmin review
|
|
2
|
+
Copyright 2026 atmin contributors
|
|
3
|
+
|
|
4
|
+
This implementation is independently authored. No source from a private
|
|
5
|
+
reference repository is included. Dependencies retain their own licenses;
|
|
6
|
+
see DEPENDENCIES.md and the licenses installed with each dependency.
|
package/README.md
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
# atmin review
|
|
2
|
+
|
|
3
|
+
Source code review with evidence, clear verdicts, and bounded model spending.
|
|
4
|
+
Run the CLI yourself or operate the included GitHub App worker. Experimental
|
|
5
|
+
alpha: model quality and severity calibration are still being measured.
|
|
6
|
+
|
|
7
|
+
## Install the alpha
|
|
8
|
+
|
|
9
|
+
Requires Node 24 or newer, Git, and an authenticated GitHub CLI (`gh auth login`).
|
|
10
|
+
Install the versioned release in a fresh directory:
|
|
11
|
+
|
|
12
|
+
```sh
|
|
13
|
+
npm install @atmin.ai/review@0.1.0-alpha.2
|
|
14
|
+
npx atmin-review --help
|
|
15
|
+
cp node_modules/@atmin.ai/review/profiles/smoke-openrouter-free.json ./review-profile.json
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Set `OPENROUTER_API_KEY` in your environment, then review a PR:
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
npx atmin-review review https://github.com/OWNER/REPO/pull/123 \
|
|
22
|
+
--profile ./review-profile.json --out ./private-review
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Replace the example URL with a repository you may access and send to the model
|
|
26
|
+
provider. The free profile enforces zero model pricing with no paid fallback;
|
|
27
|
+
availability and rate limits depend on the provider. The bundled paid DeepSeek
|
|
28
|
+
profile caps a run at $2; copying it is an explicit choice to use paid inference.
|
|
29
|
+
Direct OpenAI support uses `OPENAI_API_KEY` and an explicit profile.
|
|
30
|
+
|
|
31
|
+
Each run captures immutable commits, reads changed files and relevant callers,
|
|
32
|
+
records anchored findings, and renders a report. It never executes repository
|
|
33
|
+
scripts. Keep snapshot directories private: they contain repository source.
|
|
34
|
+
Interrupted or partial reviews exit with status 2. Errors exit with status 1.
|
|
35
|
+
|
|
36
|
+
You can also prepare, investigate, render, and inspect costs separately:
|
|
37
|
+
|
|
38
|
+
```sh
|
|
39
|
+
npx atmin-review prepare https://github.com/OWNER/REPO/pull/123 --out ./private-review
|
|
40
|
+
npx atmin-review investigate ./private-review --profile ./review-profile.json
|
|
41
|
+
npx atmin-review render ./private-review --check-current
|
|
42
|
+
npx atmin-review cost ./private-review
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
A directory is investigated once, so previous spending reservations cannot be
|
|
46
|
+
lost by rerunning it. Create a new snapshot for a new review. `--check-current`
|
|
47
|
+
checks live commits; rendering without it explicitly leaves freshness unverified.
|
|
48
|
+
|
|
49
|
+
## Read the verdict
|
|
50
|
+
|
|
51
|
+
**No issues found** means the completed source review reported no visible
|
|
52
|
+
findings. Required validation is separate. It does not mean the code is perfect
|
|
53
|
+
or that tests passed. Incomplete or historical reviews never receive a clean
|
|
54
|
+
headline. A numerical average cannot cancel out a serious defect.
|
|
55
|
+
|
|
56
|
+
| Priority | Meaning | Default check behavior |
|
|
57
|
+
|---|---|---|
|
|
58
|
+
| P0 | Critical, immediate intervention | Changes needed |
|
|
59
|
+
| P1 | High-impact defect needing a prompt fix | Changes needed |
|
|
60
|
+
| P2 | Material defect that should be fixed | Changes needed |
|
|
61
|
+
| P3 | Minor defect with limited impact | Non-blocking suggestion |
|
|
62
|
+
| P4 | Optional improvement | Hidden by default; non-blocking |
|
|
63
|
+
|
|
64
|
+
Priority depends on a concrete trigger, impact, reachability and counterevidence.
|
|
65
|
+
Findings cite immutable source. A model's reasoning is not proof of execution.
|
|
66
|
+
The target commit's `.atmin/review.json` may enable optional suggestions and name
|
|
67
|
+
required validation checks; a PR cannot weaken its own policy:
|
|
68
|
+
|
|
69
|
+
```json
|
|
70
|
+
{"schemaVersion":1,"rubricVersion":"1","includeOptional":false,"requiredChecks":["change-validation"]}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## GitHub App worker
|
|
74
|
+
|
|
75
|
+
The worker receives signed webhooks, stores jobs in SQLite, updates one bot
|
|
76
|
+
summary per PR, and publishes an `atmin review` check. Maintainers can comment
|
|
77
|
+
`/atmin review` to rerun. Use a dedicated host user; the pilot worker is not a
|
|
78
|
+
sandbox for executing repository code or an isolation boundary for many tenants.
|
|
79
|
+
|
|
80
|
+
Register an App with repository Contents read, Pull requests write and Checks
|
|
81
|
+
write. Subscribe to Pull request, Push and Issue comment events. Install it only
|
|
82
|
+
on the intended repository. Set its webhook to your HTTPS proxy's
|
|
83
|
+
`/webhooks/github`, forwarding to the worker on loopback port 8787.
|
|
84
|
+
|
|
85
|
+
Set `GITHUB_APP_ID`, `GITHUB_APP_PRIVATE_KEY_PATH`, `GITHUB_WEBHOOK_SECRET`
|
|
86
|
+
(at least 32 bytes), and the selected model credential. Put actual repository
|
|
87
|
+
and installation IDs in a local configuration:
|
|
88
|
+
|
|
89
|
+
```json
|
|
90
|
+
{
|
|
91
|
+
"repository":"OWNER/REPO",
|
|
92
|
+
"repositoryId":123,
|
|
93
|
+
"installationId":456,
|
|
94
|
+
"profile":"./review-profile.json",
|
|
95
|
+
"stateDirectory":"./private-worker-state",
|
|
96
|
+
"host":"127.0.0.1",
|
|
97
|
+
"port":8787,
|
|
98
|
+
"maxReviewsPerDay":6,
|
|
99
|
+
"trustedChecks":[{"name":"change-validation","appId":15368}]
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
`trustedChecks` is optional. Use the actual check name and producer App ID you
|
|
104
|
+
trust; check names must match the target policy's required checks. App 15368 is
|
|
105
|
+
an illustrative configuration; verify the producer in your repository before
|
|
106
|
+
using it. The worker queries GitHub on the exact reviewed head. Only a unique
|
|
107
|
+
completed success counts as a pass. Missing, skipped, ambiguous, cancelled or
|
|
108
|
+
unavailable checks remain unverified. A check on a different merge commit is
|
|
109
|
+
not automatically treated as evidence for the head.
|
|
110
|
+
|
|
111
|
+
Protect CI workflow changes according to your repository's policy: trusting an
|
|
112
|
+
App and check name is not verification of the workflow's code. This alpha reads
|
|
113
|
+
CI at publication and explicit reconciliation; it does not subscribe to CI
|
|
114
|
+
completion events or poll after publication.
|
|
115
|
+
|
|
116
|
+
```sh
|
|
117
|
+
npx atmin-review-github check ./pilot.json
|
|
118
|
+
npx atmin-review-github serve ./pilot.json
|
|
119
|
+
# In another terminal; a new worker starts paused:
|
|
120
|
+
npx atmin-review-github enable ./pilot.json
|
|
121
|
+
npx atmin-review-github status ./pilot.json
|
|
122
|
+
npx atmin-review-github reconcile ./pilot.json 123
|
|
123
|
+
npx atmin-review-github pause ./pilot.json
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Reconciliation refreshes the saved report and CI without new inference. Pausing
|
|
127
|
+
cancels active work. Failed and cancelled starts count toward the rolling daily
|
|
128
|
+
limit. Stop the service before backups; retain the database and spending receipts.
|
|
129
|
+
Provide snapshot retention and disk limits before widening access. Capture
|
|
130
|
+
fetches repository history, so large repositories can exceed the pilot's capacity.
|
|
131
|
+
No hosted signup, billing, inline comments, or repository execution is included.
|
|
132
|
+
|
|
133
|
+
## Develop
|
|
134
|
+
|
|
135
|
+
```sh
|
|
136
|
+
npm ci
|
|
137
|
+
npm test
|
|
138
|
+
node packaging/verify.mjs
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
Tests use local repositories, fake provider responses and temporary databases;
|
|
142
|
+
they do not consume model credits or establish model quality. Package verification
|
|
143
|
+
installs the actual tarball in a clean directory and exercises both CLI entry
|
|
144
|
+
points and snapshot rendering. Apache-2.0; see LICENSE and NOTICE.
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type Packet, type Result, type Finding } from './contracts.js';
|
|
2
|
+
export type Freshness = {
|
|
3
|
+
status: 'current' | 'superseded' | 'unverified';
|
|
4
|
+
reason: string;
|
|
5
|
+
checkedAt: string | null;
|
|
6
|
+
};
|
|
7
|
+
export declare const unverified: () => Freshness;
|
|
8
|
+
export type ValidationCheck = {
|
|
9
|
+
name: string;
|
|
10
|
+
status: Result['validation'][number]['status'];
|
|
11
|
+
reason: string;
|
|
12
|
+
url?: string;
|
|
13
|
+
};
|
|
14
|
+
export interface Assessment {
|
|
15
|
+
outcome: 'Changes needed' | 'Review incomplete' | 'Validation needed' | 'Superseded' | 'Unverified' | 'Suggestions' | 'No issues found';
|
|
16
|
+
findingsVerdict: 'Changes needed' | 'Review incomplete' | 'Suggestions' | 'No issues found';
|
|
17
|
+
scope: 'complete' | 'partial' | 'unavailable';
|
|
18
|
+
validation: 'passed' | 'failed' | 'missing' | 'not-applicable';
|
|
19
|
+
freshness: Freshness;
|
|
20
|
+
validationChecks: ValidationCheck[];
|
|
21
|
+
findings: Finding[];
|
|
22
|
+
hiddenOptionalCount: number;
|
|
23
|
+
reasons: string[];
|
|
24
|
+
}
|
|
25
|
+
export declare function validateEvidence(packet: Packet, result: Result): void;
|
|
26
|
+
export declare function assess(packet: Packet, result: Result, freshness?: Freshness, ci?: ValidationCheck[]): Assessment;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { parsePacket, parseResult, PRIORITIES } from './contracts.js';
|
|
2
|
+
export const unverified = () => ({ status: 'unverified', reason: 'Live PR state has not been checked for this rendering.', checkedAt: null });
|
|
3
|
+
function unique(values, label) {
|
|
4
|
+
if (new Set(values).size !== values.length)
|
|
5
|
+
throw new Error(`Duplicate ${label}`);
|
|
6
|
+
}
|
|
7
|
+
export function validateEvidence(packet, result) {
|
|
8
|
+
parsePacket(packet);
|
|
9
|
+
parseResult(result);
|
|
10
|
+
if (packet.headSha !== result.headSha || packet.baseSha !== result.baseSha || packet.policyHash !== result.policyHash) {
|
|
11
|
+
throw new Error('Result does not match snapshot commits and policy');
|
|
12
|
+
}
|
|
13
|
+
unique(packet.changedFiles.map(f => f.path), 'changed path');
|
|
14
|
+
unique(result.coverage.map(c => c.path), 'coverage path');
|
|
15
|
+
unique(result.validation.map(c => c.name), 'validation name');
|
|
16
|
+
unique(result.evidence.map(e => e.id), 'evidence ID');
|
|
17
|
+
unique(result.findings.map(f => f.id), 'finding root-cause ID');
|
|
18
|
+
const inventory = new Map(packet.changedFiles.map(f => [f.path, f]));
|
|
19
|
+
if (result.coverage.length !== inventory.size || result.coverage.some(c => !inventory.has(c.path))) {
|
|
20
|
+
throw new Error('Coverage must account for every changed path exactly once');
|
|
21
|
+
}
|
|
22
|
+
const evidence = new Map(result.evidence.map(e => [e.id, e]));
|
|
23
|
+
if (result.status === 'not-started' && (result.findings.length || result.evidence.length
|
|
24
|
+
|| result.coverage.some(c => c.status === 'reviewed') || result.validation.some(c => c.status !== 'not-run'))) {
|
|
25
|
+
throw new Error('A not-started investigation cannot contain claimed review evidence');
|
|
26
|
+
}
|
|
27
|
+
const checkRefs = (refs) => {
|
|
28
|
+
if (refs.some(id => !evidence.has(id)))
|
|
29
|
+
throw new Error('Unknown evidence reference');
|
|
30
|
+
};
|
|
31
|
+
for (const coverage of result.coverage) {
|
|
32
|
+
checkRefs(coverage.evidenceIds);
|
|
33
|
+
if (coverage.status === 'reviewed') {
|
|
34
|
+
if (inventory.get(coverage.path)?.kind !== 'text')
|
|
35
|
+
throw new Error('R01 cannot claim review coverage for non-text paths');
|
|
36
|
+
if (!coverage.evidenceIds.some(id => evidence.get(id)?.anchors.some(a => a.path === coverage.path))) {
|
|
37
|
+
throw new Error('Reviewed coverage needs evidence anchored to that path');
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
for (const check of result.validation) {
|
|
42
|
+
checkRefs(check.evidenceIds);
|
|
43
|
+
if (['pass', 'fail'].includes(check.status) && !check.evidenceIds.some(id => ['reproduction', 'ci'].includes(evidence.get(id).kind))) {
|
|
44
|
+
throw new Error('A passed or failed check needs reproduction or CI evidence');
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
for (const finding of result.findings) {
|
|
48
|
+
checkRefs(finding.evidenceIds);
|
|
49
|
+
if (!inventory.has(finding.anchor.path))
|
|
50
|
+
throw new Error('Finding must anchor to a changed path; callers belong in supporting evidence');
|
|
51
|
+
if ((finding.priority === 'P4') !== (finding.kind === 'improvement'))
|
|
52
|
+
throw new Error('P4 is an optional improvement; P0–P3 are defects');
|
|
53
|
+
if (!finding.evidenceIds.some(id => evidence.get(id)?.anchors.some(a => a.path === finding.anchor.path && a.side === finding.anchor.side))) {
|
|
54
|
+
throw new Error('Finding needs evidence anchored to its changed path and side');
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
export function assess(packet, result, freshness = unverified(), ci = []) {
|
|
59
|
+
validateEvidence(packet, result);
|
|
60
|
+
const scope = result.status === 'not-started' ? 'unavailable'
|
|
61
|
+
: result.status === 'completed' && result.coverage.every(c => c.status === 'reviewed') ? 'complete' : 'partial';
|
|
62
|
+
unique(ci.map(c => c.name), 'CI check name');
|
|
63
|
+
const checks = packet.policy.requiredChecks.map(name => ci.find(c => c.name === name)
|
|
64
|
+
?? result.validation.find(c => c.name === name)
|
|
65
|
+
?? { name, status: 'not-run', reason: 'No evidence supplied.' });
|
|
66
|
+
const validation = checks.some(c => c?.status === 'fail') ? 'failed'
|
|
67
|
+
: checks.some(c => !c || c.status === 'not-run') ? 'missing'
|
|
68
|
+
: checks.some(c => c?.status === 'pass') ? 'passed' : 'not-applicable';
|
|
69
|
+
const findings = result.findings.filter(f => f.priority !== 'P4' || packet.policy.includeOptional)
|
|
70
|
+
.toSorted((a, b) => PRIORITIES.indexOf(a.priority) - PRIORITIES.indexOf(b.priority) || a.id.localeCompare(b.id));
|
|
71
|
+
const blocking = findings.some(f => ['P0', 'P1', 'P2'].includes(f.priority));
|
|
72
|
+
const findingsVerdict = blocking ? 'Changes needed' : findings.length ? 'Suggestions'
|
|
73
|
+
: scope !== 'complete' ? 'Review incomplete' : 'No issues found';
|
|
74
|
+
// These are advisory results, not GitHub approvals or a protected merge check.
|
|
75
|
+
const outcome = freshness.status === 'superseded' ? 'Superseded'
|
|
76
|
+
: blocking ? 'Changes needed'
|
|
77
|
+
: scope !== 'complete' ? 'Review incomplete'
|
|
78
|
+
: ['failed', 'missing'].includes(validation) ? 'Validation needed'
|
|
79
|
+
: freshness.status !== 'current' ? 'Unverified' : findingsVerdict;
|
|
80
|
+
const reasons = [freshness.reason];
|
|
81
|
+
if (blocking)
|
|
82
|
+
reasons.push('At least one substantiated P0–P2 defect needs a change under rubric v1.');
|
|
83
|
+
if (scope !== 'complete')
|
|
84
|
+
reasons.push('Investigation is not complete across the captured changed-file inventory.');
|
|
85
|
+
if (validation === 'failed' || validation === 'missing')
|
|
86
|
+
reasons.push(`Required validation is ${validation}.`);
|
|
87
|
+
return { outcome, findingsVerdict, scope, validation, freshness, validationChecks: checks, findings, hiddenOptionalCount: result.findings.length - findings.length, reasons };
|
|
88
|
+
}
|
package/dist/cli.d.ts
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { parseArgs } from 'node:util';
|
|
3
|
+
import { writeFileSync } from 'node:fs';
|
|
4
|
+
import { resolve } from 'node:path';
|
|
5
|
+
import { assess, unverified } from './assessment.js';
|
|
6
|
+
import { checkCurrent, loadReview, prepare } from './snapshot.js';
|
|
7
|
+
import { renderMarkdown } from './render.js';
|
|
8
|
+
import { readProfile, runReview } from './run.js';
|
|
9
|
+
import { accountedUsd } from './investigation.js';
|
|
10
|
+
import { costReport } from './cost-report.js';
|
|
11
|
+
const help = `atmin review — source investigation and evidence tools
|
|
12
|
+
|
|
13
|
+
atmin-review review <https://github.com/owner/repo/pull/number> --profile <profile.json> [--out <new-directory>]
|
|
14
|
+
atmin-review prepare <https://github.com/owner/repo/pull/number> [--out <new-directory>]
|
|
15
|
+
atmin-review render <directory> [--format markdown|json] [--check-current] [--out <new-file>]
|
|
16
|
+
atmin-review investigate <directory> --profile <profile.json>
|
|
17
|
+
atmin-review cost <directory> [--out <new-json-file>]
|
|
18
|
+
|
|
19
|
+
prepare uses read-only GitHub/Git access and writes a private snapshot.
|
|
20
|
+
render validates all evidence references against captured Git objects.
|
|
21
|
+
--check-current checks live head/target; without it freshness is unverified.
|
|
22
|
+
investigate sends frozen source to the configured API, with bounded reads and usage reservations.
|
|
23
|
+
No repository scripts, GitHub writes or merge approvals. Required execution remains not-run.
|
|
24
|
+
`;
|
|
25
|
+
async function main() {
|
|
26
|
+
const { values, positionals } = parseArgs({ allowPositionals: true, strict: true,
|
|
27
|
+
options: { help: { type: 'boolean', short: 'h' }, out: { type: 'string' }, format: { type: 'string' }, profile: { type: 'string' }, 'check-current': { type: 'boolean' } } });
|
|
28
|
+
if (values.help || !positionals.length) {
|
|
29
|
+
process.stdout.write(help);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const [operation, input] = positionals;
|
|
33
|
+
if (!input || positionals.length !== 2)
|
|
34
|
+
throw new Error('Expected one command and one input; use --help');
|
|
35
|
+
if (operation === 'investigate' || operation === 'review') {
|
|
36
|
+
if (!values.profile || (operation === 'investigate' && values.out) || values.format || values['check-current'])
|
|
37
|
+
throw new Error('review/investigate requires --profile; --out is only valid for review');
|
|
38
|
+
const profile = readProfile(resolve(values.profile));
|
|
39
|
+
const directory = operation === 'review' ? prepare(input, values.out).directory : resolve(input);
|
|
40
|
+
const controller = new AbortController();
|
|
41
|
+
const cancel = () => controller.abort();
|
|
42
|
+
process.once('SIGINT', cancel);
|
|
43
|
+
process.once('SIGTERM', cancel);
|
|
44
|
+
try {
|
|
45
|
+
const { result, receipt } = await runReview(directory, profile, undefined, controller.signal);
|
|
46
|
+
if (operation === 'review') {
|
|
47
|
+
const { packet } = loadReview(directory);
|
|
48
|
+
process.stdout.write(renderMarkdown(packet, result, assess(packet, result, checkCurrent(packet))));
|
|
49
|
+
process.stderr.write(`Private review artifacts: ${directory}\n`);
|
|
50
|
+
}
|
|
51
|
+
else
|
|
52
|
+
process.stdout.write(`${JSON.stringify({ directory, status: result.status, findings: result.findings.length,
|
|
53
|
+
accountedUsd: accountedUsd(receipt), stopReason: receipt.stopReason }, null, 2)}\n`);
|
|
54
|
+
if (receipt.stopReason !== 'finished' || result.status !== 'completed')
|
|
55
|
+
process.exitCode = 2;
|
|
56
|
+
}
|
|
57
|
+
finally {
|
|
58
|
+
process.off('SIGINT', cancel);
|
|
59
|
+
process.off('SIGTERM', cancel);
|
|
60
|
+
}
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (values.profile)
|
|
64
|
+
throw new Error('--profile is only valid for review or investigate');
|
|
65
|
+
if (operation === 'cost') {
|
|
66
|
+
if (values.format || values['check-current'])
|
|
67
|
+
throw new Error('cost accepts only --out');
|
|
68
|
+
const output = `${JSON.stringify(costReport(resolve(input)), null, 2)}\n`;
|
|
69
|
+
if (values.out)
|
|
70
|
+
writeFileSync(resolve(values.out), output, { mode: 0o600, flag: 'wx' });
|
|
71
|
+
else
|
|
72
|
+
process.stdout.write(output);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
if (operation === 'prepare') {
|
|
76
|
+
if (values.format || values['check-current'])
|
|
77
|
+
throw new Error('prepare accepts only --out');
|
|
78
|
+
const { directory, packet } = prepare(input, values.out);
|
|
79
|
+
process.stdout.write(`${JSON.stringify({ directory, headSha: packet.headSha, baseSha: packet.baseSha, changedFiles: packet.changedFiles.length, investigation: 'not-started' }, null, 2)}\n`);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
if (operation !== 'render')
|
|
83
|
+
throw new Error('Unknown command; use prepare, investigate or render.');
|
|
84
|
+
if (values.format && !['markdown', 'json'].includes(values.format))
|
|
85
|
+
throw new Error('Format must be markdown or json');
|
|
86
|
+
const { packet, result } = loadReview(resolve(input));
|
|
87
|
+
const assessment = assess(packet, result, values['check-current'] ? checkCurrent(packet) : unverified());
|
|
88
|
+
const output = values.format === 'json' ? `${JSON.stringify({ packet, result, assessment }, null, 2)}\n` : renderMarkdown(packet, result, assessment);
|
|
89
|
+
if (values.out)
|
|
90
|
+
writeFileSync(resolve(values.out), output, { mode: 0o600, flag: 'wx' });
|
|
91
|
+
else
|
|
92
|
+
process.stdout.write(output);
|
|
93
|
+
}
|
|
94
|
+
try {
|
|
95
|
+
await main();
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
process.stderr.write(`${JSON.stringify({ error: error instanceof Error ? error.message : 'Review operation failed' })}\n`);
|
|
99
|
+
process.exitCode = 1;
|
|
100
|
+
}
|