@weareikko/code-review 0.0.1 → 0.8.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.
Files changed (66) hide show
  1. package/LICENSE +105 -0
  2. package/README.md +221 -0
  3. package/bin/code-review.js +7 -0
  4. package/dist/cli-w8sz3CYl.js +6375 -0
  5. package/dist/cli-w8sz3CYl.js.map +1 -0
  6. package/dist/cli.d.ts +56 -0
  7. package/dist/cli.d.ts.map +1 -0
  8. package/dist/cli.js +2 -0
  9. package/dist/config.d.ts +205 -0
  10. package/dist/config.d.ts.map +1 -0
  11. package/dist/diagnostics.d.ts +118 -0
  12. package/dist/diagnostics.d.ts.map +1 -0
  13. package/dist/diff-lines.d.ts +48 -0
  14. package/dist/diff-lines.d.ts.map +1 -0
  15. package/dist/errors.d.ts +69 -0
  16. package/dist/errors.d.ts.map +1 -0
  17. package/dist/fingerprints.d.ts +22 -0
  18. package/dist/fingerprints.d.ts.map +1 -0
  19. package/dist/git.d.ts +50 -0
  20. package/dist/git.d.ts.map +1 -0
  21. package/dist/github.d.ts +119 -0
  22. package/dist/github.d.ts.map +1 -0
  23. package/dist/gitlab-review.d.ts +210 -0
  24. package/dist/gitlab-review.d.ts.map +1 -0
  25. package/dist/gitlab.d.ts +98 -0
  26. package/dist/gitlab.d.ts.map +1 -0
  27. package/dist/logger.d.ts +10 -0
  28. package/dist/logger.d.ts.map +1 -0
  29. package/dist/otel.d.ts +111 -0
  30. package/dist/otel.d.ts.map +1 -0
  31. package/dist/parser.d.ts +27 -0
  32. package/dist/parser.d.ts.map +1 -0
  33. package/dist/payloads.d.ts +30 -0
  34. package/dist/payloads.d.ts.map +1 -0
  35. package/dist/platform.d.ts +71 -0
  36. package/dist/platform.d.ts.map +1 -0
  37. package/dist/platforms/github.d.ts +115 -0
  38. package/dist/platforms/github.d.ts.map +1 -0
  39. package/dist/platforms/gitlab.d.ts +26 -0
  40. package/dist/platforms/gitlab.d.ts.map +1 -0
  41. package/dist/posting.d.ts +108 -0
  42. package/dist/posting.d.ts.map +1 -0
  43. package/dist/prior-threads.d.ts +40 -0
  44. package/dist/prior-threads.d.ts.map +1 -0
  45. package/dist/product.d.ts +17 -0
  46. package/dist/product.d.ts.map +1 -0
  47. package/dist/review.d.ts +18 -0
  48. package/dist/review.d.ts.map +1 -0
  49. package/dist/review.js +2 -0
  50. package/dist/skills.d.ts +92 -0
  51. package/dist/skills.d.ts.map +1 -0
  52. package/dist/skipped-retrieval.d.ts +26 -0
  53. package/dist/skipped-retrieval.d.ts.map +1 -0
  54. package/dist/summary-carryover.d.ts +48 -0
  55. package/dist/summary-carryover.d.ts.map +1 -0
  56. package/dist/triage.d.ts +37 -0
  57. package/dist/triage.d.ts.map +1 -0
  58. package/dist/types.d.ts +95 -0
  59. package/dist/types.d.ts.map +1 -0
  60. package/dist/verify.d.ts +74 -0
  61. package/dist/verify.d.ts.map +1 -0
  62. package/package.json +90 -2
  63. package/skills/code-review/SKILL.md +112 -0
  64. package/skills/code-review/references/javascript-typescript.md +50 -0
  65. package/skills/code-review/references/php.md +46 -0
  66. package/skills/test-integrity/SKILL.md +76 -0
package/LICENSE ADDED
@@ -0,0 +1,105 @@
1
+ # Functional Source License, Version 1.1, ALv2 Future License
2
+
3
+ ## Abbreviation
4
+
5
+ FSL-1.1-ALv2
6
+
7
+ ## Notice
8
+
9
+ Copyright 2026 ikko
10
+
11
+ ## Terms and Conditions
12
+
13
+ ### Licensor ("We")
14
+
15
+ The party offering the Software under these Terms and Conditions.
16
+
17
+ ### The Software
18
+
19
+ The "Software" is each version of the software that we make available under
20
+ these Terms and Conditions, as indicated by our inclusion of these Terms and
21
+ Conditions with the Software.
22
+
23
+ ### License Grant
24
+
25
+ Subject to your compliance with this License Grant and the Patents,
26
+ Redistribution and Trademark clauses below, we hereby grant you the right to
27
+ use, copy, modify, create derivative works, publicly perform, publicly display
28
+ and redistribute the Software for any Permitted Purpose identified below.
29
+
30
+ ### Permitted Purpose
31
+
32
+ A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
33
+ means making the Software available to others in a commercial product or
34
+ service that:
35
+
36
+ 1. substitutes for the Software;
37
+
38
+ 2. substitutes for any other product or service we offer using the Software
39
+ that exists as of the date we make the Software available; or
40
+
41
+ 3. offers the same or substantially similar functionality as the Software.
42
+
43
+ Permitted Purposes specifically include using the Software:
44
+
45
+ 1. for your internal use and access;
46
+
47
+ 2. for non-commercial education;
48
+
49
+ 3. for non-commercial research; and
50
+
51
+ 4. in connection with professional services that you provide to a licensee
52
+ using the Software in accordance with these Terms and Conditions.
53
+
54
+ ### Patents
55
+
56
+ To the extent your use for a Permitted Purpose would necessarily infringe our
57
+ patents, the license grant above includes a license under our patents. If you
58
+ make a claim against any party that the Software infringes or contributes to
59
+ the infringement of any patent, then your patent license to the Software ends
60
+ immediately.
61
+
62
+ ### Redistribution
63
+
64
+ The Terms and Conditions apply to all copies, modifications and derivatives of
65
+ the Software.
66
+
67
+ If you redistribute any copies, modifications or derivatives of the Software,
68
+ you must include a copy of or a link to these Terms and Conditions and not
69
+ remove any copyright notices provided in or with the Software.
70
+
71
+ ### Disclaimer
72
+
73
+ THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
74
+ IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
75
+ PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
76
+
77
+ IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
78
+ SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
79
+ EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
80
+
81
+ ### Trademarks
82
+
83
+ Except for displaying the License Details and identifying us as the origin of
84
+ the Software, you have no right under these Terms and Conditions to use our
85
+ trademarks, trade names, service marks or product names.
86
+
87
+ ## Grant of Future License
88
+
89
+ We hereby irrevocably grant you an additional license to use the Software under
90
+ the Apache License, Version 2.0 that is effective on the second anniversary of
91
+ the date we make the Software available. On or after that date, you may use the
92
+ Software under the Apache License, Version 2.0, in which case the following
93
+ will apply:
94
+
95
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
96
+ this file except in compliance with the License.
97
+
98
+ You may obtain a copy of the License at
99
+
100
+ http://www.apache.org/licenses/LICENSE-2.0
101
+
102
+ Unless required by applicable law or agreed to in writing, software distributed
103
+ under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
104
+ CONDITIONS OF ANY KIND, either express or implied. See the License for the
105
+ specific language governing permissions and limitations under the License.
package/README.md ADDED
@@ -0,0 +1,221 @@
1
+ # @weareikko/code-review
2
+
3
+ [![NPM Version](https://img.shields.io/npm/v/@weareikko/code-review.svg?style=flat&colorB=3e63dd&colorA=414853)](https://www.npmjs.com/package/@weareikko/code-review/)
4
+ [![Downloads](https://img.shields.io/npm/dm/@weareikko/code-review?style=flat&colorB=3e63dd&colorA=414853)](https://www.npmjs.com/package/@weareikko/code-review/)
5
+ [![Size](https://img.shields.io/bundlephobia/minzip/@weareikko/code-review?style=flat&colorB=3e63dd&colorA=414853&label=size)](https://bundlephobia.com/package/@weareikko/code-review)
6
+ ![Codecov](https://img.shields.io/codecov/c/github/weareikko/code-review?style=flat&colorB=3e63dd&colorA=414853)
7
+
8
+ Run an agent-driven code review in GitLab CI, parse inline comments, post deduplicated merge request discussions, and report per-run token usage and cost.
9
+
10
+ The reviewer reads the MR **title and description** as the author's declared intent: it checks the diff against the stated purpose and flags code/intent mismatches (the change does something the description never claimed, or omits something it promised) as a first-class finding. A missing or empty description degrades gracefully — the review still runs.
11
+
12
+ ## Requirements
13
+
14
+ - Node.js `>=24`
15
+ - `git` available in the runtime
16
+ - A pipeline running in a merge request context (`CI_PROJECT_ID`, `CI_MERGE_REQUEST_IID`)
17
+
18
+ ## Install / Run
19
+
20
+ Run without installing:
21
+
22
+ ```bash
23
+ npx @weareikko/code-review
24
+ ```
25
+
26
+ Or install in your project:
27
+
28
+ ```bash
29
+ npm i -D @weareikko/code-review
30
+ npx code-review --help
31
+ ```
32
+
33
+ ### Binary entrypoint
34
+
35
+ This package exposes the `code-review` binary through:
36
+
37
+ - `bin/code-review.js` (runtime shim)
38
+ - `dist/cli.js` (compiled CLI)
39
+
40
+ ## Usage
41
+
42
+ ```bash
43
+ code-review [options]
44
+ ```
45
+
46
+ Common local dry-run:
47
+
48
+ ```bash
49
+ code-review \
50
+ --project 123 \
51
+ --mr 42 \
52
+ --gitlab-url https://gitlab.example.com \
53
+ --gitlab-token "$GITLAB_TOKEN" \
54
+ --model anthropic/claude-sonnet-4-5 \
55
+ --api-key "$ANTHROPIC_API_KEY" \
56
+ --dry-run
57
+ ```
58
+
59
+ ## GitLab CI example
60
+
61
+ ```yml
62
+ review:
63
+ image: node:24
64
+ stage: post
65
+ rules:
66
+ - if: $CI_PIPELINE_SOURCE == "merge_request_event"
67
+ variables:
68
+ GIT_DEPTH: '0'
69
+ # A model is required (no default). Provide its provider's key as a masked
70
+ # CI/CD variable, e.g. ANTHROPIC_API_KEY.
71
+ CODE_REVIEW_MODEL: anthropic/claude-sonnet-4-5
72
+ script:
73
+ - npx @weareikko/code-review
74
+ artifacts:
75
+ when: always
76
+ paths:
77
+ - gitlab-review.md
78
+ - review-comments.json
79
+ - review-usage.json
80
+ ```
81
+
82
+ ## GitHub Actions
83
+
84
+ The same reviewer also reviews **GitHub pull requests** — the engine is platform-agnostic and auto-detects GitHub from the Actions environment (`GITHUB_ACTIONS`, `GITHUB_REPOSITORY`, the `pull_request` event). Set `--platform github` to force it.
85
+
86
+ Use the bundled composite action. It needs:
87
+
88
+ - **Permissions:** `pull-requests: write` (to post the review and summary) and `contents: read` (to check out the code). The default `GITHUB_TOKEN` is enough; the action reads it as `${{ github.token }}` by default.
89
+ - **Full git history:** check out with `fetch-depth: 0` so the merge-base diff and commit log resolve.
90
+ - **A model + its key:** pass the model via the `model` input and the provider's key via the `api-key` input (or expose the provider's standard env var, e.g. `ANTHROPIC_API_KEY`, to the step).
91
+
92
+ ```yml
93
+ name: code-review
94
+ on:
95
+ pull_request:
96
+
97
+ permissions:
98
+ contents: read
99
+ pull-requests: write
100
+
101
+ jobs:
102
+ review:
103
+ runs-on: ubuntu-latest
104
+ steps:
105
+ - uses: actions/checkout@v4
106
+ with:
107
+ fetch-depth: 0
108
+ - uses: weareikko/code-review@main # pin to a release tag in production
109
+ with:
110
+ model: anthropic/claude-sonnet-4-5
111
+ api-key: ${{ secrets.ANTHROPIC_API_KEY }}
112
+ # github-token defaults to ${{ github.token }}
113
+ # args: --min-severity warn --dry-run
114
+ ```
115
+
116
+ Inputs: `model` (required), `api-key`, `github-token` (default `${{ github.token }}`), `version` (npm dist-tag/version, default `latest`), `node-version` (default `24`), `working-directory`, and `args` (extra CLI flags forwarded verbatim).
117
+
118
+ Prefer to run the CLI directly (no composite action)? `GITHUB_TOKEN`, `GITHUB_REPOSITORY`, and the PR number are read straight from the Actions environment:
119
+
120
+ ```yml
121
+ - uses: actions/setup-node@v4
122
+ with:
123
+ node-version: 24
124
+ - run: npx @weareikko/code-review
125
+ env:
126
+ GITHUB_TOKEN: ${{ github.token }}
127
+ CODE_REVIEW_MODEL: anthropic/claude-sonnet-4-5
128
+ ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
129
+ ```
130
+
131
+ ## Documentation
132
+
133
+ The README covers getting started. Reference material lives in [`docs/`](https://github.com/weareikko/code-review/tree/main/docs):
134
+
135
+ - [Configuration](https://github.com/weareikko/code-review/blob/main/docs/configuration.md) — full environment-variable and CLI-flag reference, plus the `CODE_REVIEW_` namespacing convention.
136
+ - [Providers](https://github.com/weareikko/code-review/blob/main/docs/providers.md) — Anthropic, OpenRouter, Gemini, Ollama, and OpenAI-compatible endpoints, plus heterogeneous review with a model pool.
137
+ - [Skills](https://github.com/weareikko/code-review/blob/main/docs/skills.md) — built-in, external (`npm:`/`file:`/`git:`), and project auto-discovered review skills.
138
+ - [Multi-stage review](https://github.com/weareikko/code-review/blob/main/docs/multi-stage-review.md) — the staged Find / Verify / Synthesize pipeline behind `--review-depth`.
139
+ - [Observability](https://github.com/weareikko/code-review/blob/main/docs/observability.md) — diagnostics-channel tracing and the opt-in OpenTelemetry bridge (spans, metrics, logs).
140
+ - [Output format](https://github.com/weareikko/code-review/blob/main/docs/output-format.md) — inline-comment shape, MR-level summary note, footer, and duplicate prevention.
141
+
142
+ ## Configuration
143
+
144
+ The CLI auto-resolves most values from GitLab CI variables and provider-standard env vars. The two things you must provide are a model and its provider's API key:
145
+
146
+ ```bash
147
+ code-review --model anthropic/claude-sonnet-4-5 --api-key "$ANTHROPIC_API_KEY"
148
+ ```
149
+
150
+ Equivalently, set `CODE_REVIEW_MODEL` and the provider's key (e.g. `ANTHROPIC_API_KEY`) as CI/CD variables. Common knobs include `--min-severity`, `--thinking`, `--posting-mode draft`, `--no-summary`, and `--dry-run`. See the full [environment-variable and flag reference](https://github.com/weareikko/code-review/blob/main/docs/configuration.md).
151
+
152
+ ## Providers
153
+
154
+ `code-review` uses [`@earendil-works/pi-ai`](https://github.com/earendil-works/pi-ai) for model access. Any registered provider can be selected with `--model provider/modelId` (e.g. `anthropic/claude-sonnet-4-5`, `openrouter/anthropic/claude-3-opus-20240229`, `google/gemini-2.0-flash`, `ollama/qwen2.5-coder:32b`). See [Providers](https://github.com/weareikko/code-review/blob/main/docs/providers.md) for per-provider setup and the model pool.
155
+
156
+ ## Artifacts
157
+
158
+ - `gitlab-review.md`: raw review text returned by the agent
159
+ - `review-comments.json`: generated comment objects including:
160
+ - parsed comment payload
161
+ - computed fingerprints
162
+ - duplicate status
163
+ - final GitLab discussion payload
164
+ - `review-usage.json`: token and cost breakdown for the run (`tokens.{input,output,cacheRead,cacheWrite,total}`, `cost.{input,output,cacheRead,cacheWrite,total}`, `model`)
165
+
166
+ The CLI also prints a one-line summary at the end of the run:
167
+
168
+ ```
169
+ Review usage: 12,345 in / 678 out tokens — $0.0421 (anthropic/claude-sonnet-4-5)
170
+ ```
171
+
172
+ Use these files for CI debugging and auditing.
173
+
174
+ ## Troubleshooting
175
+
176
+ - **`Node.js >=24 is required`**
177
+ - Use `node:24` (or newer) in CI.
178
+ - **`Missing required configuration`**
179
+ - Provide required flags or ensure CI vars are available (`CI_PROJECT_ID`, `CI_MERGE_REQUEST_IID`, token, API key).
180
+ - **`--min-severity must be one of: info, warn, critical`**
181
+ - Fix `--min-severity` or `CODE_REVIEW_MIN_SEVERITY`.
182
+ - **Git history errors / merge-base failures**
183
+ - Set `GIT_DEPTH: 0`.
184
+ - Ensure source and target branches are fetchable from `origin`.
185
+ - **GitLab API 401/403 when posting**
186
+ - Ensure token has rights to read MR metadata/discussions and create MR discussions.
187
+ - If using `CI_JOB_TOKEN`, ensure your GitLab project settings allow required API access.
188
+ - **No comments posted**
189
+ - Check `review-comments.json` for `duplicate: true` or empty parsed comments.
190
+ - Run with `--dry-run` and inspect `gitlab-review.md` formatting (`== Inline Comments ==`).
191
+
192
+ ## Development / release
193
+
194
+ ```bash
195
+ npm run typecheck
196
+ npm test
197
+ npm run build
198
+ npm pack --dry-run
199
+ ```
200
+
201
+ Eval tests call the real LLM and require `ANTHROPIC_API_KEY` (or `CODE_REVIEW_API_KEY`) in a local `.env` file:
202
+
203
+ ```bash
204
+ npm run test:evals
205
+ ```
206
+
207
+ Override the model for cheaper/faster eval runs:
208
+
209
+ ```bash
210
+ CODE_REVIEW_EVAL_MODEL=anthropic/claude-haiku-4-5-20251001 npm run test:evals
211
+ ```
212
+
213
+ The review agent runs against pinned `@earendil-works/pi-agent-core`, `@earendil-works/pi-ai`, and `@earendil-works/pi-coding-agent` versions, so published builds keep a deterministic reviewer runtime.
214
+
215
+ ## Acknowledgements
216
+
217
+ `code-review` builds on ideas and prior work from several projects:
218
+
219
+ - **[pi-reviewer](https://github.com/earendil-works/pi-reviewer)** — the original agent-driven code reviewer that `code-review` grew out of. The agent runtime (`@earendil-works/pi-agent-core`), model abstraction (`@earendil-works/pi-ai`), and read-only coding tools (`@earendil-works/pi-coding-agent`) are all pi-reviewer infrastructure.
220
+ - **[Warden](https://warden.sentry.dev)** by Sentry — the skills architecture (per-skill instruction blocks, reference files loaded on demand by the agent, project-level discovery) takes direct inspiration from Warden's approach to composable, domain-specific review modules.
221
+ - **[agentskills.io](https://agentskills.io)** — the `SKILL.md` frontmatter format and multi-file skill layout (`references/`, `scripts/`, `assets/`) follow the agentskills.io open standard for portable agent skills.
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env node
2
+ import { main } from '../dist/cli.js';
3
+
4
+ main().catch((error) => {
5
+ console.error(error instanceof Error ? error.message : error);
6
+ process.exitCode = 1;
7
+ });