@geonosis/review 1.0.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 +202 -0
- package/README.md +106 -0
- package/bin/geonosis-review.mjs +4 -0
- package/dist/chunk-PJWPFJAP.js +168 -0
- package/dist/index.d.ts +131 -0
- package/dist/index.js +26 -0
- package/dist/review-cli.js +94 -0
- package/package.json +49 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# @geonosis/review
|
|
2
|
+
|
|
3
|
+
The decision-only reviewer contract. A review's sole output is one JSON decision; a deterministic
|
|
4
|
+
step validates it and records it. The step comments nowhere, labels nothing, approves nothing, and
|
|
5
|
+
has no forge client and no network client in it — by construction, and there is a test that reads
|
|
6
|
+
the shipped bundle to keep it that way.
|
|
7
|
+
|
|
8
|
+
Ported from Medusa's `reviewing-prs` skill, which runs this in production: read-only tools, one
|
|
9
|
+
`review-decision.json`, and the mutation scripts *deliberately unavailable in this job*.
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm i -D @geonosis/review zod
|
|
13
|
+
|
|
14
|
+
geonosis-review apply decision.json [--to ledger|stdout] [--slug <name>]
|
|
15
|
+
geonosis-review check decision.json --criteria plans/022-1.0.0-everything.md
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
| exit | what it means |
|
|
19
|
+
|---|---|
|
|
20
|
+
| `0` | applied |
|
|
21
|
+
| `1` | the review was READ and REFUSED — prose, a bad shape, a contradiction, a criterion never checked |
|
|
22
|
+
| `2` | the command could not run — no file, no verb, an unknown flag, an option with no value, a plan with no criteria |
|
|
23
|
+
|
|
24
|
+
Only `1` is an answer about a review. Everything the command line itself gets wrong is `2`, on one
|
|
25
|
+
line and with no stack trace, so a caller that branches on the code never reads a typo as a refusal.
|
|
26
|
+
|
|
27
|
+
## The decision
|
|
28
|
+
|
|
29
|
+
```json
|
|
30
|
+
{
|
|
31
|
+
"decision": "request-changes",
|
|
32
|
+
"summary": "The ops-leakage probe reads its patterns twice and defaults them in one of the two.",
|
|
33
|
+
"findings": [
|
|
34
|
+
{
|
|
35
|
+
"file": "packages/walk/src/probes/ops-leakage.ts",
|
|
36
|
+
"line": 21,
|
|
37
|
+
"severity": "blocking",
|
|
38
|
+
"criterion": "When a probe is enabled without its list, the run shall refuse",
|
|
39
|
+
"text": "needs() requires patterns but run() falls back to an empty list, so a walk that skipped needs() reports a clean page."
|
|
40
|
+
}
|
|
41
|
+
],
|
|
42
|
+
"criteriaChecked": [
|
|
43
|
+
"When a probe is enabled without its list, the run shall refuse"
|
|
44
|
+
]
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
`decision` is `approve`, `request-changes` or `comment` — the three outcomes a review has anywhere.
|
|
49
|
+
Medusa's two closing templates are not here: closing is a forge action, and this applier takes none.
|
|
50
|
+
`severity` is `blocking`, `major` or `minor`. `file` and `text` are required on every finding,
|
|
51
|
+
because "being vague about required changes" is on Medusa's own list of mistakes and a finding that
|
|
52
|
+
names neither is exactly that. `criterion` is the field Medusa has no analogue for: it binds a
|
|
53
|
+
finding to the plan's EARS criterion.
|
|
54
|
+
|
|
55
|
+
## What is refused
|
|
56
|
+
|
|
57
|
+
Beyond the schema — which is strict, so an unknown key is refused rather than dropped:
|
|
58
|
+
|
|
59
|
+
- **a prose review**, in the first clause of the message rather than after a schema dump;
|
|
60
|
+
- **an approval that lists a blocking finding** — Medusa's "Common Mistakes", made mechanical;
|
|
61
|
+
- **a `request-changes` with nothing blocking or major in it** — the same failure from the other
|
|
62
|
+
side: a decision the author cannot act on, and how a review loop reaches round three having said
|
|
63
|
+
nothing;
|
|
64
|
+
- **a decision that never looked at a criterion the plan states** (`check`), naming which.
|
|
65
|
+
|
|
66
|
+
## `check --criteria`
|
|
67
|
+
|
|
68
|
+
Every EARS criterion under the plan's acceptance heading must appear in `criteriaChecked`, matched
|
|
69
|
+
on the whole criterion with whitespace normalised — a criterion an editor reflowed is the same
|
|
70
|
+
criterion; a criterion half-quoted is not, or `criteriaChecked: ["When"]` would cover a plan.
|
|
71
|
+
|
|
72
|
+
The heading and the criterion pattern are configuration, because a heading is a repo's vocabulary:
|
|
73
|
+
|
|
74
|
+
```json
|
|
75
|
+
{
|
|
76
|
+
"review": {
|
|
77
|
+
"criteriaHeading": "^#{2,3} +Acceptance criteria\\b",
|
|
78
|
+
"criteria": "^- When .+ shall .+",
|
|
79
|
+
"proofs": "proofs",
|
|
80
|
+
"runner": "peer-session"
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## `runner`
|
|
86
|
+
|
|
87
|
+
`peer-session` or `agent:<model>` (C13). D-009 said the reviewer runs on a different model; D-016
|
|
88
|
+
said the cross-context check is the peer session that owns the other repo. Both are *not the
|
|
89
|
+
author*, which is the property that matters — so the kit ships the contract and leaves the runner to
|
|
90
|
+
configuration. **Nothing in this package acts on the field**; the agent text reads it, because a
|
|
91
|
+
library that picked a runner would have picked for every consumer.
|
|
92
|
+
|
|
93
|
+
## Why it does not use `@geonosis/ledger`
|
|
94
|
+
|
|
95
|
+
`apply --to ledger` writes `<proofs>/<slug>.md` itself, and this package imports nothing of the kit.
|
|
96
|
+
Three measured reasons:
|
|
97
|
+
|
|
98
|
+
1. the ledger's only proof API is `captureProof`, which **runs a command** and captures its output —
|
|
99
|
+
a decision that already exists is not a command, and an applier that shells out is not
|
|
100
|
+
deterministic;
|
|
101
|
+
2. `captureProof` writes `NNN-slug.md`, one past the highest number on disk, so the same decision
|
|
102
|
+
lands at a different path on a different tree — the opposite of a deterministic apply;
|
|
103
|
+
3. a reviewer that can reach the ledger is one call away from writing the tick it just judged. The
|
|
104
|
+
scored agent never writes the scoreboard.
|
|
105
|
+
|
|
106
|
+
Running `apply` twice on the same decision rewrites the same bytes at the same path.
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
// src/config.ts
|
|
2
|
+
import { existsSync, readFileSync } from "fs";
|
|
3
|
+
import { resolve } from "path";
|
|
4
|
+
var ReviewError = class extends Error {
|
|
5
|
+
constructor(message) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = "ReviewError";
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
var REVIEW_DEFAULT = {
|
|
11
|
+
criteria: "^- When .+ shall .+",
|
|
12
|
+
criteriaHeading: "^#{2,3} +Acceptance criteria\\b",
|
|
13
|
+
proofs: "proofs",
|
|
14
|
+
runner: "peer-session"
|
|
15
|
+
};
|
|
16
|
+
var KNOWN = new Set(Object.keys(REVIEW_DEFAULT));
|
|
17
|
+
var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
18
|
+
var loadReviewConfig = (root) => {
|
|
19
|
+
const file = resolve(root, "geonosis.json");
|
|
20
|
+
if (!existsSync(file)) return REVIEW_DEFAULT;
|
|
21
|
+
let parsed;
|
|
22
|
+
try {
|
|
23
|
+
parsed = JSON.parse(readFileSync(file, "utf8"));
|
|
24
|
+
} catch (error) {
|
|
25
|
+
throw new ReviewError(`geonosis.json is not valid JSON: ${error.message}`);
|
|
26
|
+
}
|
|
27
|
+
if (!isRecord(parsed)) throw new ReviewError("geonosis.json must hold an object");
|
|
28
|
+
const block = parsed.review;
|
|
29
|
+
if (block === void 0) return REVIEW_DEFAULT;
|
|
30
|
+
if (!isRecord(block)) throw new ReviewError("review must be an object");
|
|
31
|
+
const config = { ...REVIEW_DEFAULT };
|
|
32
|
+
for (const [key, value] of Object.entries(block)) {
|
|
33
|
+
if (!KNOWN.has(key)) throw new ReviewError(`review.${key} is not a key of the review block`);
|
|
34
|
+
if (typeof value !== "string") throw new ReviewError(`review.${key} must be a string`);
|
|
35
|
+
config[key] = value;
|
|
36
|
+
}
|
|
37
|
+
for (const key of ["criteria", "criteriaHeading"]) {
|
|
38
|
+
try {
|
|
39
|
+
RegExp(config[key]);
|
|
40
|
+
} catch {
|
|
41
|
+
throw new ReviewError(`review.${key}: "${config[key]}" is not a regular expression`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return config;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// src/criteria.ts
|
|
48
|
+
var HEADING = /^(#{1,6}) +(.*)$/;
|
|
49
|
+
var sectionUnder = (lines, pattern) => {
|
|
50
|
+
const test = new RegExp(pattern);
|
|
51
|
+
const headings = [];
|
|
52
|
+
let fenced = false;
|
|
53
|
+
for (const [index, line] of lines.entries()) {
|
|
54
|
+
if (line.startsWith("```") || line.startsWith("~~~")) fenced = !fenced;
|
|
55
|
+
if (fenced) continue;
|
|
56
|
+
const match = HEADING.exec(line);
|
|
57
|
+
if (match?.[1] !== void 0) headings.push({ depth: match[1].length, index });
|
|
58
|
+
}
|
|
59
|
+
const at = headings.find((heading) => test.test(lines[heading.index] ?? ""));
|
|
60
|
+
if (at === void 0) return void 0;
|
|
61
|
+
const next = headings.find((heading) => heading.index > at.index && heading.depth <= at.depth);
|
|
62
|
+
return lines.slice(at.index + 1, next?.index ?? lines.length);
|
|
63
|
+
};
|
|
64
|
+
var normalise = (text) => text.trim().replaceAll(/\s+/g, " ");
|
|
65
|
+
var criteriaOf = (plan, config) => {
|
|
66
|
+
const section = sectionUnder(plan.split("\n"), config.criteriaHeading);
|
|
67
|
+
if (section === void 0) return [];
|
|
68
|
+
const test = new RegExp(config.criteria);
|
|
69
|
+
return section.filter((line) => test.test(line)).map((line) => normalise(line.replace(/^\s*[-*]\s+/, "")));
|
|
70
|
+
};
|
|
71
|
+
var uncovered = (stated, checked) => {
|
|
72
|
+
const seen = new Set(checked.map(normalise));
|
|
73
|
+
return stated.filter((one) => !seen.has(normalise(one)));
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
// src/decision.ts
|
|
77
|
+
import { z } from "zod";
|
|
78
|
+
var DECISIONS = ["approve", "comment", "request-changes"];
|
|
79
|
+
var SEVERITIES = ["blocking", "major", "minor"];
|
|
80
|
+
var finding = z.strictObject({
|
|
81
|
+
criterion: z.string().min(1).optional(),
|
|
82
|
+
file: z.string().min(1),
|
|
83
|
+
line: z.number().int().positive().optional(),
|
|
84
|
+
severity: z.enum(SEVERITIES),
|
|
85
|
+
text: z.string().min(1)
|
|
86
|
+
});
|
|
87
|
+
var decisionSchema = z.strictObject({
|
|
88
|
+
criteriaChecked: z.array(z.string().min(1)),
|
|
89
|
+
decision: z.enum(DECISIONS),
|
|
90
|
+
findings: z.array(finding),
|
|
91
|
+
summary: z.string().min(1)
|
|
92
|
+
});
|
|
93
|
+
var issues = (error) => error.issues.map((issue) => `${issue.path.join(".") || "(root)"}: ${issue.message}`).join("; ");
|
|
94
|
+
var contradictions = (decision) => {
|
|
95
|
+
const blocking = decision.findings.filter((one) => one.severity === "blocking");
|
|
96
|
+
if (decision.decision === "approve" && blocking.length > 0) {
|
|
97
|
+
return `an approve cannot carry ${blocking.length} blocking finding(s) \u2014 ${blocking[0]?.file}: ${blocking[0]?.text}`;
|
|
98
|
+
}
|
|
99
|
+
if (decision.decision !== "request-changes") return null;
|
|
100
|
+
const actionable = decision.findings.filter((one) => one.severity !== "minor");
|
|
101
|
+
return actionable.length > 0 ? null : "a request-changes must carry at least one blocking or major finding saying what to change";
|
|
102
|
+
};
|
|
103
|
+
var readDecision = (source) => {
|
|
104
|
+
let parsed;
|
|
105
|
+
try {
|
|
106
|
+
parsed = JSON.parse(source);
|
|
107
|
+
} catch (error) {
|
|
108
|
+
return {
|
|
109
|
+
ok: false,
|
|
110
|
+
reason: `the review is not JSON, so no step can apply it: ${error.message}`
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
const read = decisionSchema.safeParse(parsed);
|
|
114
|
+
if (!read.success) return { ok: false, reason: issues(read.error) };
|
|
115
|
+
const contradiction = contradictions(read.data);
|
|
116
|
+
return contradiction === null ? { decision: read.data, ok: true } : { ok: false, reason: contradiction };
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
// src/apply.ts
|
|
120
|
+
import { mkdirSync, writeFileSync } from "fs";
|
|
121
|
+
import { dirname, resolve as resolve2 } from "path";
|
|
122
|
+
var render = (decision) => {
|
|
123
|
+
const findings = decision.findings.length === 0 ? ["_No findings._"] : decision.findings.map(
|
|
124
|
+
(one) => `- **${one.severity}** \`${one.file}${one.line === void 0 ? "" : `:${one.line}`}\`${one.criterion === void 0 ? "" : ` \u2014 _${one.criterion}_`}
|
|
125
|
+
${one.text}`
|
|
126
|
+
);
|
|
127
|
+
const criteria = decision.criteriaChecked.length === 0 ? ["_None stated._"] : decision.criteriaChecked.map((one) => `- ${one}`);
|
|
128
|
+
return [
|
|
129
|
+
`# review \u2014 ${decision.decision}`,
|
|
130
|
+
"",
|
|
131
|
+
decision.summary,
|
|
132
|
+
"",
|
|
133
|
+
"## Findings",
|
|
134
|
+
"",
|
|
135
|
+
...findings,
|
|
136
|
+
"",
|
|
137
|
+
"## Criteria checked",
|
|
138
|
+
"",
|
|
139
|
+
...criteria,
|
|
140
|
+
"",
|
|
141
|
+
"## The decision, verbatim",
|
|
142
|
+
"",
|
|
143
|
+
"```json",
|
|
144
|
+
JSON.stringify(decision, null, 2),
|
|
145
|
+
"```",
|
|
146
|
+
""
|
|
147
|
+
].join("\n");
|
|
148
|
+
};
|
|
149
|
+
var applyDecision = (decision, root, proofs, slug) => {
|
|
150
|
+
const at = resolve2(root, proofs, `${slug}.md`);
|
|
151
|
+
mkdirSync(dirname(at), { recursive: true });
|
|
152
|
+
writeFileSync(at, render(decision));
|
|
153
|
+
return at;
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
export {
|
|
157
|
+
ReviewError,
|
|
158
|
+
REVIEW_DEFAULT,
|
|
159
|
+
loadReviewConfig,
|
|
160
|
+
criteriaOf,
|
|
161
|
+
uncovered,
|
|
162
|
+
DECISIONS,
|
|
163
|
+
SEVERITIES,
|
|
164
|
+
decisionSchema,
|
|
165
|
+
readDecision,
|
|
166
|
+
render,
|
|
167
|
+
applyDecision
|
|
168
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Where the reviewer's runner comes from (C13).
|
|
5
|
+
*
|
|
6
|
+
* D-009 said "a different model"; D-016 said the cross-context check is the PEER SESSION that owns
|
|
7
|
+
* the other repo. Both are "not the author", which is the property that matters, so the kit ships
|
|
8
|
+
* the CONTRACT and leaves the runner to configuration. The agent text reads this field; nothing in
|
|
9
|
+
* this package acts on it, because a library that chose a model would have chosen for both.
|
|
10
|
+
*/
|
|
11
|
+
type ReviewConfig = {
|
|
12
|
+
criteria: string;
|
|
13
|
+
criteriaHeading: string;
|
|
14
|
+
proofs: string;
|
|
15
|
+
runner: string;
|
|
16
|
+
};
|
|
17
|
+
declare class ReviewError extends Error {
|
|
18
|
+
constructor(message: string);
|
|
19
|
+
}
|
|
20
|
+
/** The same two patterns the ledger's plan contract uses, and for the same reason: a heading is a repo's vocabulary. */
|
|
21
|
+
declare const REVIEW_DEFAULT: ReviewConfig;
|
|
22
|
+
/** The `review` block of `geonosis.json`, every key optional, every default a contract. */
|
|
23
|
+
declare const loadReviewConfig: (root: string) => ReviewConfig;
|
|
24
|
+
|
|
25
|
+
/** Every EARS criterion the plan states, in order, with the list marker taken off. */
|
|
26
|
+
declare const criteriaOf: (plan: string, config: ReviewConfig) => string[];
|
|
27
|
+
/**
|
|
28
|
+
* The criteria the decision never looked at.
|
|
29
|
+
*
|
|
30
|
+
* Equality of the whole normalised criterion, never a prefix: a review that quoted the first six
|
|
31
|
+
* words of a criterion has not stated that it checked it, and accepting a prefix would let
|
|
32
|
+
* `criteriaChecked: ["When"]` cover a whole plan.
|
|
33
|
+
*/
|
|
34
|
+
declare const uncovered: (stated: string[], checked: string[]) => string[];
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The three outcomes a review has anywhere.
|
|
38
|
+
*
|
|
39
|
+
* Medusa's contract has five `review_template` values, two of which close the pull request. Closing
|
|
40
|
+
* is a forge action, and this applier takes none — so `close-spam` and `close-malicious` are a
|
|
41
|
+
* decision to describe in the summary, not an outcome the kit can carry out.
|
|
42
|
+
*/
|
|
43
|
+
declare const DECISIONS: readonly ["approve", "comment", "request-changes"];
|
|
44
|
+
declare const SEVERITIES: readonly ["blocking", "major", "minor"];
|
|
45
|
+
/**
|
|
46
|
+
* `file` is required and `text` is required, because Medusa's own list of mistakes has "being vague
|
|
47
|
+
* about required changes — always state exactly what needs to change and where", and a finding that
|
|
48
|
+
* names neither is exactly that. `criterion` is the field Medusa has no analogue for: it binds a
|
|
49
|
+
* finding to the plan's EARS criterion, so `check` can say which criterion is unmet rather than
|
|
50
|
+
* only which file.
|
|
51
|
+
*/
|
|
52
|
+
declare const finding: z.ZodObject<{
|
|
53
|
+
criterion: z.ZodOptional<z.ZodString>;
|
|
54
|
+
file: z.ZodString;
|
|
55
|
+
line: z.ZodOptional<z.ZodNumber>;
|
|
56
|
+
severity: z.ZodEnum<{
|
|
57
|
+
blocking: "blocking";
|
|
58
|
+
major: "major";
|
|
59
|
+
minor: "minor";
|
|
60
|
+
}>;
|
|
61
|
+
text: z.ZodString;
|
|
62
|
+
}, z.core.$strict>;
|
|
63
|
+
/**
|
|
64
|
+
* `strictObject`, not `object`: an unknown key is refused rather than dropped.
|
|
65
|
+
*
|
|
66
|
+
* Medusa's schema note is that a value outside the allowlist makes the downstream apply job FAIL,
|
|
67
|
+
* surfacing in the logs. A KEY outside it is the same mistake one step earlier — silently ignoring
|
|
68
|
+
* `labels_to_add` would apply a decision the reviewer did not make and tell nobody.
|
|
69
|
+
*/
|
|
70
|
+
declare const decisionSchema: z.ZodObject<{
|
|
71
|
+
criteriaChecked: z.ZodArray<z.ZodString>;
|
|
72
|
+
decision: z.ZodEnum<{
|
|
73
|
+
approve: "approve";
|
|
74
|
+
comment: "comment";
|
|
75
|
+
"request-changes": "request-changes";
|
|
76
|
+
}>;
|
|
77
|
+
findings: z.ZodArray<z.ZodObject<{
|
|
78
|
+
criterion: z.ZodOptional<z.ZodString>;
|
|
79
|
+
file: z.ZodString;
|
|
80
|
+
line: z.ZodOptional<z.ZodNumber>;
|
|
81
|
+
severity: z.ZodEnum<{
|
|
82
|
+
blocking: "blocking";
|
|
83
|
+
major: "major";
|
|
84
|
+
minor: "minor";
|
|
85
|
+
}>;
|
|
86
|
+
text: z.ZodString;
|
|
87
|
+
}, z.core.$strict>>;
|
|
88
|
+
summary: z.ZodString;
|
|
89
|
+
}, z.core.$strict>;
|
|
90
|
+
type ReviewDecision = z.infer<typeof decisionSchema>;
|
|
91
|
+
type ReviewFinding = z.infer<typeof finding>;
|
|
92
|
+
type ReadDecision = {
|
|
93
|
+
decision: ReviewDecision;
|
|
94
|
+
ok: true;
|
|
95
|
+
} | {
|
|
96
|
+
ok: false;
|
|
97
|
+
reason: string;
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* The whole gate, in one function: a review is either this object or it is refused.
|
|
101
|
+
*
|
|
102
|
+
* A reviewer that wrote three paragraphs has produced something no deterministic step can apply,
|
|
103
|
+
* and the refusal says so in the first clause rather than after a schema dump — "not JSON" is the
|
|
104
|
+
* sentence that tells the author what went wrong.
|
|
105
|
+
*/
|
|
106
|
+
declare const readDecision: (source: string) => ReadDecision;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* The decision, rendered.
|
|
110
|
+
*
|
|
111
|
+
* Deterministic to the byte: no timestamp, no git HEAD, no directory scan. Running the applier
|
|
112
|
+
* twice on the same decision rewrites the same file, which is what "applies deterministically"
|
|
113
|
+
* means and is why this is not `@geonosis/ledger`'s `captureProof` — that numbers a proof one past
|
|
114
|
+
* the highest on disk, so the same input lands somewhere else on a different tree.
|
|
115
|
+
*
|
|
116
|
+
* The decision is embedded verbatim as well as rendered, so nothing a reader needs is lost to the
|
|
117
|
+
* rendering and a later tool can read the record back.
|
|
118
|
+
*/
|
|
119
|
+
declare const render: (decision: ReviewDecision) => string;
|
|
120
|
+
/**
|
|
121
|
+
* Writes the record, and NOTHING else.
|
|
122
|
+
*
|
|
123
|
+
* There is no comment to post, no label to set, no approval to give and no forge to reach — by
|
|
124
|
+
* construction, not by policy: this package has no network client and no forge client in it, and a
|
|
125
|
+
* test reads the shipped bundle to keep it that way. 2ndm1nd's rail is that the scored agent never
|
|
126
|
+
* writes the scoreboard; an applier that held a token would be a reviewer that could approve
|
|
127
|
+
* itself.
|
|
128
|
+
*/
|
|
129
|
+
declare const applyDecision: (decision: ReviewDecision, root: string, proofs: string, slug: string) => string;
|
|
130
|
+
|
|
131
|
+
export { DECISIONS, REVIEW_DEFAULT, type ReadDecision, type ReviewConfig, type ReviewDecision, ReviewError, type ReviewFinding, SEVERITIES, applyDecision, criteriaOf, decisionSchema, loadReviewConfig, readDecision, render, uncovered };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DECISIONS,
|
|
3
|
+
REVIEW_DEFAULT,
|
|
4
|
+
ReviewError,
|
|
5
|
+
SEVERITIES,
|
|
6
|
+
applyDecision,
|
|
7
|
+
criteriaOf,
|
|
8
|
+
decisionSchema,
|
|
9
|
+
loadReviewConfig,
|
|
10
|
+
readDecision,
|
|
11
|
+
render,
|
|
12
|
+
uncovered
|
|
13
|
+
} from "./chunk-PJWPFJAP.js";
|
|
14
|
+
export {
|
|
15
|
+
DECISIONS,
|
|
16
|
+
REVIEW_DEFAULT,
|
|
17
|
+
ReviewError,
|
|
18
|
+
SEVERITIES,
|
|
19
|
+
applyDecision,
|
|
20
|
+
criteriaOf,
|
|
21
|
+
decisionSchema,
|
|
22
|
+
loadReviewConfig,
|
|
23
|
+
readDecision,
|
|
24
|
+
render,
|
|
25
|
+
uncovered
|
|
26
|
+
};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ReviewError,
|
|
3
|
+
applyDecision,
|
|
4
|
+
criteriaOf,
|
|
5
|
+
loadReviewConfig,
|
|
6
|
+
readDecision,
|
|
7
|
+
render,
|
|
8
|
+
uncovered
|
|
9
|
+
} from "./chunk-PJWPFJAP.js";
|
|
10
|
+
|
|
11
|
+
// src/review-cli.ts
|
|
12
|
+
import { existsSync, readFileSync } from "fs";
|
|
13
|
+
import { basename, resolve } from "path";
|
|
14
|
+
var parse = (argv) => {
|
|
15
|
+
const out = {};
|
|
16
|
+
for (let at = 0; at < argv.length; at += 1) {
|
|
17
|
+
const arg = argv[at];
|
|
18
|
+
if (arg === void 0) continue;
|
|
19
|
+
const takes = (name) => {
|
|
20
|
+
const value = argv[at + 1];
|
|
21
|
+
if (value === void 0) throw new ReviewError(`${name} needs a value`);
|
|
22
|
+
at += 1;
|
|
23
|
+
return value;
|
|
24
|
+
};
|
|
25
|
+
if (arg === "--to") out.to = takes("--to");
|
|
26
|
+
else if (arg === "--slug") out.slug = takes("--slug");
|
|
27
|
+
else if (arg === "--criteria") out.criteria = takes("--criteria");
|
|
28
|
+
else if (arg.startsWith("-")) throw new ReviewError(`unknown option ${arg}`);
|
|
29
|
+
else if (out.verb === void 0) out.verb = arg;
|
|
30
|
+
else if (out.file === void 0) out.file = arg;
|
|
31
|
+
else throw new ReviewError(`unexpected argument ${arg}`);
|
|
32
|
+
}
|
|
33
|
+
return out;
|
|
34
|
+
};
|
|
35
|
+
var readFile = (root, relative, what) => {
|
|
36
|
+
if (relative === void 0) throw new ReviewError(`geonosis-review needs ${what}`);
|
|
37
|
+
const at = resolve(root, relative);
|
|
38
|
+
if (!existsSync(at)) throw new ReviewError(`${relative}: no such file`);
|
|
39
|
+
return readFileSync(at, "utf8");
|
|
40
|
+
};
|
|
41
|
+
var Refused = class extends Error {
|
|
42
|
+
};
|
|
43
|
+
var apply = (argv, root) => {
|
|
44
|
+
const config = loadReviewConfig(root);
|
|
45
|
+
const source = readFile(root, argv.file, "a decision file to apply");
|
|
46
|
+
const read = readDecision(source);
|
|
47
|
+
if (!read.ok) throw new Refused(read.reason);
|
|
48
|
+
if (argv.to === void 0 || argv.to === "stdout") {
|
|
49
|
+
process.stdout.write(render(read.decision));
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (argv.to !== "ledger")
|
|
53
|
+
throw new ReviewError(`--to takes "ledger" or "stdout", not "${argv.to}"`);
|
|
54
|
+
const slug = argv.slug ?? basename(argv.file ?? "review").replace(/\.[^.]+$/, "");
|
|
55
|
+
process.stdout.write(`${applyDecision(read.decision, root, config.proofs, slug)}
|
|
56
|
+
`);
|
|
57
|
+
};
|
|
58
|
+
var check = (argv, root) => {
|
|
59
|
+
const config = loadReviewConfig(root);
|
|
60
|
+
const read = readDecision(readFile(root, argv.file, "a decision file to check"));
|
|
61
|
+
if (!read.ok) throw new Refused(read.reason);
|
|
62
|
+
const plan = readFile(root, argv.criteria, "--criteria <plan.md>");
|
|
63
|
+
const stated = criteriaOf(plan, config);
|
|
64
|
+
if (stated.length === 0) {
|
|
65
|
+
throw new ReviewError(
|
|
66
|
+
`${argv.criteria ?? ""} states no acceptance criteria \u2014 there is nothing to review it against`
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
const missed = uncovered(stated, read.decision.criteriaChecked);
|
|
70
|
+
if (missed.length > 0) {
|
|
71
|
+
throw new Refused(
|
|
72
|
+
[`the review did not check ${missed.length} of ${stated.length} criteria:`, ...missed].join(
|
|
73
|
+
"\n "
|
|
74
|
+
)
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
process.stdout.write(`all ${stated.length} criteria checked
|
|
78
|
+
`);
|
|
79
|
+
};
|
|
80
|
+
var main = () => {
|
|
81
|
+
const root = process.cwd();
|
|
82
|
+
try {
|
|
83
|
+
const argv = parse(process.argv.slice(2));
|
|
84
|
+
if (argv.verb === "apply") apply(argv, root);
|
|
85
|
+
else if (argv.verb === "check") check(argv, root);
|
|
86
|
+
else throw new ReviewError(`geonosis-review takes "apply" or "check", not "${argv.verb ?? ""}"`);
|
|
87
|
+
} catch (error) {
|
|
88
|
+
process.stderr.write(`${error.message}
|
|
89
|
+
`);
|
|
90
|
+
return error instanceof Refused ? 1 : 2;
|
|
91
|
+
}
|
|
92
|
+
return 0;
|
|
93
|
+
};
|
|
94
|
+
process.exitCode = main();
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@geonosis/review",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "The decision-only reviewer contract: a review's sole output is one JSON decision, validated and applied by a step that comments nowhere, approves nothing and cannot reach a forge.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"code-review",
|
|
7
|
+
"pull-request",
|
|
8
|
+
"agent",
|
|
9
|
+
"zod",
|
|
10
|
+
"gate",
|
|
11
|
+
"ci",
|
|
12
|
+
"ears"
|
|
13
|
+
],
|
|
14
|
+
"homepage": "https://github.com/microcompanies/geonosis/tree/main/packages/review",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/microcompanies/geonosis.git",
|
|
18
|
+
"directory": "packages/review"
|
|
19
|
+
},
|
|
20
|
+
"license": "Apache-2.0",
|
|
21
|
+
"type": "module",
|
|
22
|
+
"main": "dist/index.js",
|
|
23
|
+
"bin": {
|
|
24
|
+
"geonosis-review": "bin/geonosis-review.mjs"
|
|
25
|
+
},
|
|
26
|
+
"exports": {
|
|
27
|
+
".": "./dist/index.js"
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"bin",
|
|
31
|
+
"dist"
|
|
32
|
+
],
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"zod": "^4.0.0"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"zod": "^4.0.0"
|
|
38
|
+
},
|
|
39
|
+
"engines": {
|
|
40
|
+
"node": ">=22"
|
|
41
|
+
},
|
|
42
|
+
"publishConfig": {
|
|
43
|
+
"access": "public"
|
|
44
|
+
},
|
|
45
|
+
"scripts": {
|
|
46
|
+
"build": "tsup",
|
|
47
|
+
"typecheck": "tsc --noEmit"
|
|
48
|
+
}
|
|
49
|
+
}
|