@weareikko/code-review 0.9.8 → 0.10.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/README.md +21 -1
- package/dist/{cli-CgQF5-WG.js → cli-oQSwCSL0.js} +210 -87
- package/dist/cli-oQSwCSL0.js.map +1 -0
- package/dist/cli.d.ts +16 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +2 -2
- package/dist/config.d.ts +15 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/diagnostics.d.ts +6 -0
- package/dist/diagnostics.d.ts.map +1 -1
- package/dist/github.d.ts +7 -0
- package/dist/github.d.ts.map +1 -1
- package/dist/gitlab.d.ts +6 -0
- package/dist/gitlab.d.ts.map +1 -1
- package/dist/mcp-parse.d.ts +7 -7
- package/dist/mcp-parse.d.ts.map +1 -1
- package/dist/mcp.d.ts +6 -5
- package/dist/mcp.d.ts.map +1 -1
- package/dist/platform.d.ts +5 -0
- package/dist/platform.d.ts.map +1 -1
- package/dist/platforms/github.d.ts +1 -0
- package/dist/platforms/github.d.ts.map +1 -1
- package/dist/platforms/gitlab.d.ts +1 -0
- package/dist/platforms/gitlab.d.ts.map +1 -1
- package/dist/review.js +1 -1
- package/package.json +6 -5
- package/dist/cli-CgQF5-WG.js.map +0 -1
package/README.md
CHANGED
|
@@ -194,7 +194,7 @@ Equivalently, set `CODE_REVIEW_MODEL` and the provider's key (e.g. `ANTHROPIC_AP
|
|
|
194
194
|
|
|
195
195
|
## Providers
|
|
196
196
|
|
|
197
|
-
`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-
|
|
197
|
+
`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-opus-4.5`, `google/gemini-2.5-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.
|
|
198
198
|
|
|
199
199
|
## Artifacts
|
|
200
200
|
|
|
@@ -243,6 +243,26 @@ npm run build
|
|
|
243
243
|
npm pack --dry-run
|
|
244
244
|
```
|
|
245
245
|
|
|
246
|
+
Do not edit `CHANGELOG.md`: each pull request adds a fragment in `.changelog/` (format: [`weareikko/changelog`](https://github.com/weareikko/changelog)), or gets the `no-changelog` label when users do not see the change.
|
|
247
|
+
|
|
248
|
+
Each merge into `main` releases: the `Publish` workflow tests, folds the fragments into `CHANGELOG.md`, bumps the version, tags, publishes to npm and creates the GitHub release. A merge without a fragment (and without a dependency pull request from Renovate) releases nothing. The fragments give the version ([automatic version](https://github.com/weareikko/changelog#automatic-version)):
|
|
249
|
+
|
|
250
|
+
| Entries | From 1.0.0 | On 0.x |
|
|
251
|
+
| ------------------------------------------ | ---------- | ------ |
|
|
252
|
+
| A breaking entry (`**BREAKING**: …`) | major | minor |
|
|
253
|
+
| An entry under `Added`, no breaking entry | minor | patch |
|
|
254
|
+
| Other entries only (fixes, `Dependencies`) | patch | patch |
|
|
255
|
+
|
|
256
|
+
Prereleases follow the file `.changelog/prerelease` ([prereleases](https://github.com/weareikko/changelog#prereleases)): a pull request that adds it with `beta` makes the next merges with fragments release prereleases (from `0.10.0`, a fix gives `0.10.1-beta.0`, then `0.10.1-beta.1`…); a pull request that deletes it releases the stable version, also without a new fragment. A prerelease (a version with a `-`) is published on the `next` npm dist-tag, is a GitHub prerelease and does not move the `@0` / `@0.x` tags; any other version goes to `latest`.
|
|
257
|
+
|
|
258
|
+
A manual run forces a bump, for example a major version without a breaking entry:
|
|
259
|
+
|
|
260
|
+
```bash
|
|
261
|
+
gh workflow run publish.yml -f bump=major # or patch / minor, or prepatch / preminor / premajor / prerelease with -f preid=beta
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
Publishing uses npm trusted publishing (no npm token) and skips a version that npm already has: if the `Publish to npm` job fails, use "Re-run failed jobs".
|
|
265
|
+
|
|
246
266
|
Eval tests call the real LLM and require `ANTHROPIC_API_KEY` (or `CODE_REVIEW_API_KEY`) in a local `.env` file:
|
|
247
267
|
|
|
248
268
|
```bash
|
|
@@ -16,10 +16,7 @@ import { createReadOnlyTools } from "@earendil-works/pi-coding-agent";
|
|
|
16
16
|
import { createTwoFilesPatch } from "diff";
|
|
17
17
|
import * as git from "isomorphic-git";
|
|
18
18
|
import { Type } from "typebox";
|
|
19
|
-
import {
|
|
20
|
-
import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
|
|
21
|
-
import { StdioClientTransport, getDefaultEnvironment } from "@modelcontextprotocol/sdk/client/stdio.js";
|
|
22
|
-
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
19
|
+
import { McpClient, StdioTransport, StreamableHttpTransport } from "@earendil-works/pi-mcp";
|
|
23
20
|
import { SpanKind, SpanStatusCode, context, metrics, trace } from "@opentelemetry/api";
|
|
24
21
|
import { SeverityNumber, logs } from "@opentelemetry/api-logs";
|
|
25
22
|
//#region src/errors.ts
|
|
@@ -310,6 +307,25 @@ var GitHubClient = class {
|
|
|
310
307
|
body: JSON.stringify({ body })
|
|
311
308
|
});
|
|
312
309
|
}
|
|
310
|
+
/** Add labels to an issue or pull request (`POST /issues/{n}/labels`). */
|
|
311
|
+
async addIssueLabels(owner, repo, issue, labels) {
|
|
312
|
+
await this.request(`/repos/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/issues/${issue}/labels`, {
|
|
313
|
+
method: "POST",
|
|
314
|
+
body: JSON.stringify({ labels })
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Remove one label from an issue or pull request. GitHub answers 404 when the
|
|
319
|
+
* label is not on it; that is the desired end state, so it is not an error.
|
|
320
|
+
*/
|
|
321
|
+
async removeIssueLabel(owner, repo, issue, label) {
|
|
322
|
+
try {
|
|
323
|
+
await this.request(`/repos/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/issues/${issue}/labels/${encodeURIComponent(label)}`, { method: "DELETE" });
|
|
324
|
+
} catch (error) {
|
|
325
|
+
if (error instanceof GitHubApiError && error.status === 404) return;
|
|
326
|
+
throw error;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
313
329
|
getCurrentUser() {
|
|
314
330
|
return this.request("/user");
|
|
315
331
|
}
|
|
@@ -397,7 +413,7 @@ var TEMPLATE_PATTERN = /\$\{([A-Za-z_][A-Za-z0-9_]*)(?::-([^}]*))?\}/g;
|
|
|
397
413
|
* timeout, so an unclamped value there is a one-line denial of service.
|
|
398
414
|
*/
|
|
399
415
|
var MAX_MCP_TIMEOUT_MS = 12e4;
|
|
400
|
-
function isRecord(value) {
|
|
416
|
+
function isRecord$1(value) {
|
|
401
417
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
402
418
|
}
|
|
403
419
|
/**
|
|
@@ -448,15 +464,15 @@ function expandMcpTemplate(value, vars) {
|
|
|
448
464
|
* `null` when the document is not an object at all.
|
|
449
465
|
*/
|
|
450
466
|
function extractMcpServerMap(raw) {
|
|
451
|
-
if (!isRecord(raw)) return null;
|
|
452
|
-
if (isRecord(raw.mcpServers)) return raw.mcpServers;
|
|
467
|
+
if (!isRecord$1(raw)) return null;
|
|
468
|
+
if (isRecord$1(raw.mcpServers)) return raw.mcpServers;
|
|
453
469
|
return raw;
|
|
454
470
|
}
|
|
455
471
|
function stringList(value) {
|
|
456
472
|
return Array.isArray(value) ? value.filter((v) => typeof v === "string") : [];
|
|
457
473
|
}
|
|
458
474
|
function stringMap(value) {
|
|
459
|
-
if (!isRecord(value)) return {};
|
|
475
|
+
if (!isRecord$1(value)) return {};
|
|
460
476
|
const out = {};
|
|
461
477
|
for (const [key, entry] of Object.entries(value)) if (typeof entry === "string") out[key] = entry;
|
|
462
478
|
return out;
|
|
@@ -477,7 +493,7 @@ function dropEmptyHeaders(headers) {
|
|
|
477
493
|
}
|
|
478
494
|
/** Read the MCP disable lists from a parsed `.claude/settings.json` document. */
|
|
479
495
|
function parseMcpDisableFilters(raw) {
|
|
480
|
-
if (!isRecord(raw)) return {
|
|
496
|
+
if (!isRecord$1(raw)) return {
|
|
481
497
|
disabledMcpjsonServers: [],
|
|
482
498
|
disabledMcpServers: []
|
|
483
499
|
};
|
|
@@ -504,9 +520,9 @@ function describeSource(source) {
|
|
|
504
520
|
* Normalise one raw server entry. Returns `null` (after warning) when the
|
|
505
521
|
* server is unsupported or incomplete:
|
|
506
522
|
*
|
|
507
|
-
* - `type: ws`, or any `oauth` / `headersHelper` field — unsupported
|
|
508
|
-
* and auth flows
|
|
509
|
-
* - no `command` for stdio, no `url` for http
|
|
523
|
+
* - `type: sse` or `ws`, or any `oauth` / `headersHelper` field — unsupported
|
|
524
|
+
* transports and auth flows
|
|
525
|
+
* - no `command` for stdio, no `url` for http, before or after expansion
|
|
510
526
|
* - a `${VAR}` reference with no value and no default (the warning names the
|
|
511
527
|
* variable, never a value)
|
|
512
528
|
*
|
|
@@ -516,7 +532,7 @@ function describeSource(source) {
|
|
|
516
532
|
function normalizeMcpServer(name, raw, source, options = {}) {
|
|
517
533
|
const warn = options.warn ?? (() => {});
|
|
518
534
|
const where = describeSource(source);
|
|
519
|
-
if (!isRecord(raw)) {
|
|
535
|
+
if (!isRecord$1(raw)) {
|
|
520
536
|
warn(`MCP server "${name}" in ${where} is not an object — skipped.`);
|
|
521
537
|
return null;
|
|
522
538
|
}
|
|
@@ -539,8 +555,8 @@ function normalizeMcpServer(name, raw, source, options = {}) {
|
|
|
539
555
|
warn(`MCP server "${name}" in ${where} has neither "command" nor "url" — skipped.`);
|
|
540
556
|
return null;
|
|
541
557
|
}
|
|
542
|
-
if (type === "ws") {
|
|
543
|
-
warn(`MCP server "${name}" in ${where} uses the
|
|
558
|
+
if (type === "sse" || type === "ws") {
|
|
559
|
+
warn(`MCP server "${name}" in ${where} uses the ${type} transport, which is not supported — skipped.`);
|
|
544
560
|
return null;
|
|
545
561
|
}
|
|
546
562
|
if (type === "stdio" && !hasCommand) {
|
|
@@ -1751,7 +1767,7 @@ function buildSummaryBody(summary, costFooter, options = {}) {
|
|
|
1751
1767
|
return `${withFooter}\n\n${buildSummaryHistoryBlock(historyEntries)}`;
|
|
1752
1768
|
}
|
|
1753
1769
|
function buildReviewedCommitFooter(commitSha) {
|
|
1754
|
-
return `Reviewed by ${PRODUCT_LINK} v0.
|
|
1770
|
+
return `Reviewed by ${PRODUCT_LINK} v0.10.0 for commit ${commitSha}.`;
|
|
1755
1771
|
}
|
|
1756
1772
|
function extractReviewedCommitSha(body) {
|
|
1757
1773
|
return REVIEWED_COMMIT_FOOTER_PATTERN.exec(body)?.[1] ?? null;
|
|
@@ -2095,7 +2111,9 @@ var RESERVED_ENV_SUFFIXES = [
|
|
|
2095
2111
|
"MCP",
|
|
2096
2112
|
"DISABLE_MCP",
|
|
2097
2113
|
"MCP_ENV",
|
|
2098
|
-
"MCP_DISCOVERY"
|
|
2114
|
+
"MCP_DISCOVERY",
|
|
2115
|
+
"LABELS_ON_FINDINGS",
|
|
2116
|
+
"LABELS_ON_CLEAN"
|
|
2099
2117
|
];
|
|
2100
2118
|
var CODE_REVIEW_PREFIX = "CODE_REVIEW_";
|
|
2101
2119
|
var RESERVED_ENV_SUFFIX_SET = new Set(RESERVED_ENV_SUFFIXES);
|
|
@@ -2362,6 +2380,13 @@ function resolveMarketplaces(args, env) {
|
|
|
2362
2380
|
function resolveModelPool(args, env) {
|
|
2363
2381
|
return ((typeof args.modelPool === "string" && args.modelPool.length > 0 ? args.modelPool : env.CODE_REVIEW_MODEL_POOL) ?? "").split(",").map((entry) => entry.trim()).filter(Boolean);
|
|
2364
2382
|
}
|
|
2383
|
+
/**
|
|
2384
|
+
* Resolve a comma-separated label list from its flag (preferred) or env var.
|
|
2385
|
+
* Entries are trimmed and empty entries dropped; `[]` when unset.
|
|
2386
|
+
*/
|
|
2387
|
+
function resolveLabels(flag, envValue) {
|
|
2388
|
+
return ((typeof flag === "string" && flag.length > 0 ? flag : envValue) ?? "").split(",").map((entry) => entry.trim()).filter(Boolean);
|
|
2389
|
+
}
|
|
2365
2390
|
function resolveGitLabToken(args, env) {
|
|
2366
2391
|
if (typeof args.gitlabToken === "string" && args.gitlabToken.length > 0) return {
|
|
2367
2392
|
token: args.gitlabToken,
|
|
@@ -2535,7 +2560,9 @@ function resolveConfig(argv = process.argv.slice(2), env = process.env) {
|
|
|
2535
2560
|
mcp: resolveMcp(args, env),
|
|
2536
2561
|
disableMcp: resolveDisableMcp(args, env),
|
|
2537
2562
|
mcpEnv: resolveMcpEnv(args, env),
|
|
2538
|
-
mcpDiscovery: resolveMcpDiscovery(args, env)
|
|
2563
|
+
mcpDiscovery: resolveMcpDiscovery(args, env),
|
|
2564
|
+
labelsOnFindings: resolveLabels(args.labelsOnFindings, env.CODE_REVIEW_LABELS_ON_FINDINGS),
|
|
2565
|
+
labelsOnClean: resolveLabels(args.labelsOnClean, env.CODE_REVIEW_LABELS_ON_CLEAN)
|
|
2539
2566
|
};
|
|
2540
2567
|
}
|
|
2541
2568
|
function validateConfig(config) {
|
|
@@ -2576,6 +2603,9 @@ function validateConfig(config) {
|
|
|
2576
2603
|
if (!REVIEW_DEPTHS.includes(config.reviewDepth)) throw new ConfigError(`--review-depth must be one of: ${REVIEW_DEPTHS.join(", ")}`);
|
|
2577
2604
|
if (config.inputMode !== void 0 && !REVIEW_INPUT_MODES.includes(config.inputMode)) throw new ConfigError(`--input-mode must be one of: ${REVIEW_INPUT_MODES.join(", ")}`);
|
|
2578
2605
|
if (!POSTING_MODES.includes(config.postingMode)) throw new ConfigError(`--posting-mode must be one of: ${POSTING_MODES.join(", ")}`);
|
|
2606
|
+
const clean = new Set(config.labelsOnClean ?? []);
|
|
2607
|
+
const overlap = (config.labelsOnFindings ?? []).filter((label) => clean.has(label));
|
|
2608
|
+
if (overlap.length > 0) throw new ConfigError(`--labels-on-findings and --labels-on-clean share label(s): ${overlap.join(", ")}.`, { hint: "Each review outcome adds its own labels and removes the other set, so a label cannot belong to both." });
|
|
2579
2609
|
}
|
|
2580
2610
|
//#endregion
|
|
2581
2611
|
//#region src/diagnostics.ts
|
|
@@ -3158,20 +3188,60 @@ function safeSegment(value) {
|
|
|
3158
3188
|
function mcpToolName(server, tool) {
|
|
3159
3189
|
return `mcp__${safeSegment(server)}__${safeSegment(tool)}`;
|
|
3160
3190
|
}
|
|
3191
|
+
/**
|
|
3192
|
+
* Parent environment variables a stdio server inherits: the sudo-style safe
|
|
3193
|
+
* subset the official MCP SDK used. pi-mcp inherits the whole `process.env` by
|
|
3194
|
+
* default, which would hand CI secrets (GitLab token, provider API keys) to a
|
|
3195
|
+
* server the repository under review may have declared.
|
|
3196
|
+
*/
|
|
3197
|
+
var INHERITED_ENV_VARS = process.platform === "win32" ? [
|
|
3198
|
+
"APPDATA",
|
|
3199
|
+
"HOMEDRIVE",
|
|
3200
|
+
"HOMEPATH",
|
|
3201
|
+
"LOCALAPPDATA",
|
|
3202
|
+
"PATH",
|
|
3203
|
+
"PROCESSOR_ARCHITECTURE",
|
|
3204
|
+
"SYSTEMDRIVE",
|
|
3205
|
+
"SYSTEMROOT",
|
|
3206
|
+
"TEMP",
|
|
3207
|
+
"USERNAME",
|
|
3208
|
+
"USERPROFILE",
|
|
3209
|
+
"PROGRAMFILES"
|
|
3210
|
+
] : [
|
|
3211
|
+
"HOME",
|
|
3212
|
+
"LOGNAME",
|
|
3213
|
+
"PATH",
|
|
3214
|
+
"SHELL",
|
|
3215
|
+
"TERM",
|
|
3216
|
+
"USER"
|
|
3217
|
+
];
|
|
3218
|
+
/** The safe subset of `env`, skipping exported shell functions (`() { …`). */
|
|
3219
|
+
function inheritedMcpEnvironment(env = process.env) {
|
|
3220
|
+
const inherited = {};
|
|
3221
|
+
for (const key of INHERITED_ENV_VARS) {
|
|
3222
|
+
const value = env[key];
|
|
3223
|
+
if (value === void 0 || value.startsWith("()")) continue;
|
|
3224
|
+
inherited[key] = value;
|
|
3225
|
+
}
|
|
3226
|
+
return inherited;
|
|
3227
|
+
}
|
|
3161
3228
|
/** Build the real transport for a server config. */
|
|
3162
3229
|
function createMcpTransport(config) {
|
|
3163
3230
|
switch (config.type) {
|
|
3164
|
-
case "stdio": return new
|
|
3231
|
+
case "stdio": return new StdioTransport({
|
|
3165
3232
|
command: config.command,
|
|
3166
3233
|
args: config.args,
|
|
3167
3234
|
env: {
|
|
3168
|
-
...
|
|
3235
|
+
...inheritedMcpEnvironment(),
|
|
3169
3236
|
...config.env
|
|
3170
3237
|
},
|
|
3171
|
-
|
|
3238
|
+
inheritEnv: false
|
|
3239
|
+
});
|
|
3240
|
+
case "http": return new StreamableHttpTransport({
|
|
3241
|
+
url: config.url,
|
|
3242
|
+
headers: config.headers,
|
|
3243
|
+
openGetStream: false
|
|
3172
3244
|
});
|
|
3173
|
-
case "http": return new StreamableHTTPClientTransport(new URL(config.url), { requestInit: { headers: config.headers } });
|
|
3174
|
-
case "sse": return new SSEClientTransport(new URL(config.url), { requestInit: { headers: config.headers } });
|
|
3175
3245
|
default: throw new Error(`Unsupported MCP transport: ${String(config.type)}`);
|
|
3176
3246
|
}
|
|
3177
3247
|
}
|
|
@@ -3200,25 +3270,33 @@ function withMcpTrace(runId, op, server, operation) {
|
|
|
3200
3270
|
function formatMcpToolResult(result, maxChars) {
|
|
3201
3271
|
const texts = [];
|
|
3202
3272
|
const images = [];
|
|
3203
|
-
for (const block of result.content)
|
|
3204
|
-
|
|
3205
|
-
texts.push(
|
|
3206
|
-
|
|
3207
|
-
|
|
3208
|
-
|
|
3209
|
-
|
|
3210
|
-
|
|
3211
|
-
|
|
3212
|
-
|
|
3213
|
-
|
|
3214
|
-
|
|
3215
|
-
|
|
3216
|
-
|
|
3217
|
-
|
|
3218
|
-
|
|
3219
|
-
|
|
3220
|
-
|
|
3221
|
-
|
|
3273
|
+
for (const block of result.content) {
|
|
3274
|
+
if (!isRecord(block)) {
|
|
3275
|
+
texts.push("[invalid content omitted]");
|
|
3276
|
+
continue;
|
|
3277
|
+
}
|
|
3278
|
+
switch (block.type) {
|
|
3279
|
+
case "text":
|
|
3280
|
+
texts.push(typeof block.text === "string" ? block.text : "[invalid text content omitted]");
|
|
3281
|
+
break;
|
|
3282
|
+
case "image":
|
|
3283
|
+
if (typeof block.data === "string" && typeof block.mimeType === "string") images.push({
|
|
3284
|
+
type: "image",
|
|
3285
|
+
data: block.data,
|
|
3286
|
+
mimeType: block.mimeType
|
|
3287
|
+
});
|
|
3288
|
+
else texts.push("[invalid image content omitted]");
|
|
3289
|
+
break;
|
|
3290
|
+
case "resource":
|
|
3291
|
+
if (!isRecord(block.resource)) texts.push("[invalid resource content omitted]");
|
|
3292
|
+
else if (typeof block.resource.text === "string") texts.push(block.resource.text);
|
|
3293
|
+
else texts.push(`[binary resource ${String(block.resource.uri)} omitted]`);
|
|
3294
|
+
break;
|
|
3295
|
+
case "resource_link":
|
|
3296
|
+
texts.push(`[resource link] ${String(block.uri)}${typeof block.description === "string" && block.description ? ` — ${block.description}` : ""}`);
|
|
3297
|
+
break;
|
|
3298
|
+
default: texts.push(`[${String(block.type)} content omitted]`);
|
|
3299
|
+
}
|
|
3222
3300
|
}
|
|
3223
3301
|
if (texts.length === 0 && result.structuredContent !== void 0) texts.push(JSON.stringify(result.structuredContent));
|
|
3224
3302
|
let text = texts.join("\n");
|
|
@@ -3231,11 +3309,12 @@ function formatMcpToolResult(result, maxChars) {
|
|
|
3231
3309
|
const kept = [];
|
|
3232
3310
|
const notes = [];
|
|
3233
3311
|
for (const image of images) {
|
|
3234
|
-
|
|
3312
|
+
const size = image.data.length + image.mimeType.length;
|
|
3313
|
+
if (kept.length >= 4 || size > remaining) {
|
|
3235
3314
|
notes.push(`[image omitted: ${image.data.length} bytes]`);
|
|
3236
3315
|
continue;
|
|
3237
3316
|
}
|
|
3238
|
-
remaining -=
|
|
3317
|
+
remaining -= size;
|
|
3239
3318
|
kept.push(image);
|
|
3240
3319
|
}
|
|
3241
3320
|
if (notes.length > 0) {
|
|
@@ -3250,6 +3329,9 @@ function formatMcpToolResult(result, maxChars) {
|
|
|
3250
3329
|
content.push(...kept);
|
|
3251
3330
|
return content;
|
|
3252
3331
|
}
|
|
3332
|
+
function isRecord(value) {
|
|
3333
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3334
|
+
}
|
|
3253
3335
|
function toParameters(tool) {
|
|
3254
3336
|
const schema = { ...tool.inputSchema };
|
|
3255
3337
|
if (schema.type !== "object") schema.type = "object";
|
|
@@ -3275,11 +3357,8 @@ function bridgeTool(tool, deps) {
|
|
|
3275
3357
|
status.calls += 1;
|
|
3276
3358
|
return withMcpTrace(runId, "mcp.call", status.name, async (context) => {
|
|
3277
3359
|
if (context) context.tool = tool.name;
|
|
3278
|
-
const content = formatMcpToolResult(await client.callTool({
|
|
3279
|
-
|
|
3280
|
-
arguments: params
|
|
3281
|
-
}, void 0, {
|
|
3282
|
-
timeout: timeoutMs,
|
|
3360
|
+
const content = formatMcpToolResult(await client.callTool(tool.name, params, {
|
|
3361
|
+
timeoutMs,
|
|
3283
3362
|
signal
|
|
3284
3363
|
}), maxResultChars);
|
|
3285
3364
|
if (context) context.resultChars = content.reduce((chars, block) => chars + (block.type === "text" ? block.text.length : 0), 0);
|
|
@@ -3291,32 +3370,6 @@ function bridgeTool(tool, deps) {
|
|
|
3291
3370
|
}
|
|
3292
3371
|
};
|
|
3293
3372
|
}
|
|
3294
|
-
/**
|
|
3295
|
-
* `Client.listTools` caches each tool's output-schema validator and task-support
|
|
3296
|
-
* flags, and clears that cache at the start of every call — so after paginating,
|
|
3297
|
-
* the client only holds metadata for the last page and `callTool` silently skips
|
|
3298
|
-
* output validation for every tool listed before it. The SDK exposes no public
|
|
3299
|
-
* re-prime, so re-seed the cache with the full set through its (typed-private,
|
|
3300
|
-
* runtime-public) `cacheToolMetadata`, guarded so a future SDK that drops it
|
|
3301
|
-
* degrades to today's single-page behaviour instead of throwing.
|
|
3302
|
-
*/
|
|
3303
|
-
function recacheToolMetadata(client, tools) {
|
|
3304
|
-
const recache = client.cacheToolMetadata;
|
|
3305
|
-
if (typeof recache === "function") recache.call(client, tools);
|
|
3306
|
-
}
|
|
3307
|
-
async function listAllTools(client, timeoutMs) {
|
|
3308
|
-
const tools = [];
|
|
3309
|
-
let cursor;
|
|
3310
|
-
let pages = 0;
|
|
3311
|
-
do {
|
|
3312
|
-
const page = await client.listTools(cursor ? { cursor } : void 0, { timeout: timeoutMs });
|
|
3313
|
-
tools.push(...page.tools);
|
|
3314
|
-
cursor = page.nextCursor;
|
|
3315
|
-
pages += 1;
|
|
3316
|
-
} while (cursor);
|
|
3317
|
-
if (pages > 1) recacheToolMetadata(client, tools);
|
|
3318
|
-
return tools;
|
|
3319
|
-
}
|
|
3320
3373
|
async function connectOne(config, options) {
|
|
3321
3374
|
const { logger, budget, maxResultChars, runId } = options;
|
|
3322
3375
|
const timeoutMs = config.timeoutMs ?? options.timeoutMs;
|
|
@@ -3327,14 +3380,15 @@ async function connectOne(config, options) {
|
|
|
3327
3380
|
tools: [],
|
|
3328
3381
|
calls: 0
|
|
3329
3382
|
};
|
|
3330
|
-
const client = new
|
|
3383
|
+
const client = new McpClient({
|
|
3331
3384
|
name: PRODUCT_NAME,
|
|
3332
|
-
version: "0.
|
|
3385
|
+
version: "0.10.0",
|
|
3386
|
+
requestTimeoutMs: MCP_CONNECT_TIMEOUT_MS
|
|
3333
3387
|
});
|
|
3334
3388
|
try {
|
|
3335
|
-
await withMcpTrace(runId, "mcp.connect", config.name, () => client.connect(options.createTransport(config)
|
|
3389
|
+
await withMcpTrace(runId, "mcp.connect", config.name, () => client.connect(options.createTransport(config)));
|
|
3336
3390
|
const { exposed, dropped } = await withMcpTrace(runId, "mcp.tools", config.name, async (context) => {
|
|
3337
|
-
const listed = await
|
|
3391
|
+
const listed = await client.listTools({ timeoutMs: MCP_CONNECT_TIMEOUT_MS });
|
|
3338
3392
|
const readOnly = listed.filter(isReadOnlyMcpTool);
|
|
3339
3393
|
const notReadOnly = listed.filter((tool) => !isReadOnlyMcpTool(tool));
|
|
3340
3394
|
if (context) context.toolCount = readOnly.length;
|
|
@@ -7002,7 +7056,7 @@ async function loadDefaultRuntime() {
|
|
|
7002
7056
|
const [sdkNode, resources, semconv] = modules;
|
|
7003
7057
|
const serviceResource = resources.resourceFromAttributes({
|
|
7004
7058
|
[semconv.ATTR_SERVICE_NAME ?? "service.name"]: SERVICE_NAME,
|
|
7005
|
-
[semconv.ATTR_SERVICE_VERSION ?? "service.version"]: "0.
|
|
7059
|
+
[semconv.ATTR_SERVICE_VERSION ?? "service.version"]: "0.10.0"
|
|
7006
7060
|
});
|
|
7007
7061
|
applyOtelExporterDefaults(process.env);
|
|
7008
7062
|
const sdk = new sdkNode.NodeSDK({ resource: resources.defaultResource().merge(serviceResource) });
|
|
@@ -7248,6 +7302,7 @@ var NUMERIC_RESULT_ATTRIBUTES = [
|
|
|
7248
7302
|
];
|
|
7249
7303
|
var STRING_RESULT_ATTRIBUTES = [
|
|
7250
7304
|
["summaryAction", "code_review.summary.action"],
|
|
7305
|
+
["labelsOutcome", "code_review.labels.outcome"],
|
|
7251
7306
|
["httpRequestMethod", "http.request.method"],
|
|
7252
7307
|
["httpUrl", "url.full"],
|
|
7253
7308
|
["serverAddress", "server.address"]
|
|
@@ -7514,7 +7569,7 @@ function boldCommentTitle(body) {
|
|
|
7514
7569
|
*/
|
|
7515
7570
|
function buildCommentBody(body, commitSha, confidence) {
|
|
7516
7571
|
const confidenceLine = `_Confidence: ${confidence}._`;
|
|
7517
|
-
const footer = `<sub>Reviewed by ${PRODUCT_LINK} v0.
|
|
7572
|
+
const footer = `<sub>Reviewed by ${PRODUCT_LINK} v0.10.0 for commit ${commitSha}.</sub>`;
|
|
7518
7573
|
return `${boldCommentTitle(body.trim())}\n\n${confidenceLine}\n\n---\n\n${footer}`;
|
|
7519
7574
|
}
|
|
7520
7575
|
function buildPayload(comment, body, refs, resolved) {
|
|
@@ -7809,6 +7864,10 @@ var GitHubPlatform = class {
|
|
|
7809
7864
|
return { posted };
|
|
7810
7865
|
}
|
|
7811
7866
|
}
|
|
7867
|
+
async updateLabels(add, remove) {
|
|
7868
|
+
for (const label of remove) await this.client.removeIssueLabel(this.owner, this.repo, this.pull, label);
|
|
7869
|
+
if (add.length > 0) await this.client.addIssueLabels(this.owner, this.repo, this.pull, add);
|
|
7870
|
+
}
|
|
7812
7871
|
async upsertSummary(summary, discussions, options) {
|
|
7813
7872
|
const { body, existing } = buildUpsertSummary(summary, discussions, options);
|
|
7814
7873
|
if (existing) {
|
|
@@ -7985,6 +8044,20 @@ var GitLabClient = class {
|
|
|
7985
8044
|
body: JSON.stringify({ body })
|
|
7986
8045
|
});
|
|
7987
8046
|
}
|
|
8047
|
+
/**
|
|
8048
|
+
* Add and remove MR labels in one `PUT`. GitLab applies `add_labels` and
|
|
8049
|
+
* `remove_labels` against the current set, ignores removing an absent label,
|
|
8050
|
+
* and creates a missing project label on add. An empty list is omitted.
|
|
8051
|
+
*/
|
|
8052
|
+
async updateMergeRequestLabels(project, mr, add, remove) {
|
|
8053
|
+
await this.request(`/projects/${encodeURIComponent(project)}/merge_requests/${encodeURIComponent(mr)}`, {
|
|
8054
|
+
method: "PUT",
|
|
8055
|
+
body: JSON.stringify({
|
|
8056
|
+
...add.length > 0 ? { add_labels: add.join(",") } : {},
|
|
8057
|
+
...remove.length > 0 ? { remove_labels: remove.join(",") } : {}
|
|
8058
|
+
})
|
|
8059
|
+
});
|
|
8060
|
+
}
|
|
7988
8061
|
getCurrentUser() {
|
|
7989
8062
|
return this.request("/user");
|
|
7990
8063
|
}
|
|
@@ -8060,6 +8133,9 @@ var GitLabPlatform = class {
|
|
|
8060
8133
|
postComments(generated, mode) {
|
|
8061
8134
|
return postGeneratedComments(this.client, this.project, this.mr, generated, mode);
|
|
8062
8135
|
}
|
|
8136
|
+
updateLabels(add, remove) {
|
|
8137
|
+
return this.client.updateMergeRequestLabels(this.project, this.mr, add, remove);
|
|
8138
|
+
}
|
|
8063
8139
|
upsertSummary(summary, discussions, options) {
|
|
8064
8140
|
return upsertSummaryNote(this.client, this.project, this.mr, summary, discussions, options);
|
|
8065
8141
|
}
|
|
@@ -8145,7 +8221,7 @@ function gitRepoWebUrl(cloneUrl) {
|
|
|
8145
8221
|
*/
|
|
8146
8222
|
function skillSourceUrl(origin, context = {}) {
|
|
8147
8223
|
switch (origin.kind) {
|
|
8148
|
-
case "builtin": return blobUrl(PRODUCT_URL, "0.
|
|
8224
|
+
case "builtin": return blobUrl(PRODUCT_URL, "0.10.0", `skills/${origin.name}/SKILL.md`);
|
|
8149
8225
|
case "project":
|
|
8150
8226
|
if (!context.projectWebUrl || !context.commitSha) return void 0;
|
|
8151
8227
|
return blobUrl(context.projectWebUrl, context.commitSha, `${origin.path}/SKILL.md`);
|
|
@@ -8331,7 +8407,7 @@ Options:
|
|
|
8331
8407
|
provider's standard env var (e.g. ANTHROPIC_API_KEY, OPENAI_API_KEY,
|
|
8332
8408
|
GEMINI_API_KEY, OPENROUTER_API_KEY) or this flag.
|
|
8333
8409
|
--model <provider/id> Model to use. Format: provider/modelId. Multi-slash IDs such as
|
|
8334
|
-
openrouter/anthropic/claude-
|
|
8410
|
+
openrouter/anthropic/claude-opus-4.5 are supported by splitting on the
|
|
8335
8411
|
first slash. Use ollama/<model> for local Ollama models.
|
|
8336
8412
|
(required; env: CODE_REVIEW_MODEL)
|
|
8337
8413
|
--model-pool <list> Comma-separated provider/modelId list for heterogeneous full-depth
|
|
@@ -8377,6 +8453,14 @@ Options:
|
|
|
8377
8453
|
(env: CODE_REVIEW_VERIFY_MODEL)
|
|
8378
8454
|
--posting-mode <mode> direct (sequential discussions) or draft (atomic bulk publish)
|
|
8379
8455
|
(default: direct)
|
|
8456
|
+
--labels-on-findings <labels>
|
|
8457
|
+
Comma-separated labels added to the MR/PR when the review posts at
|
|
8458
|
+
least one new comment; the --labels-on-clean set is removed.
|
|
8459
|
+
(env: CODE_REVIEW_LABELS_ON_FINDINGS)
|
|
8460
|
+
--labels-on-clean <labels>
|
|
8461
|
+
Comma-separated labels added to the MR/PR when the review posts no
|
|
8462
|
+
new comment; the --labels-on-findings set is removed.
|
|
8463
|
+
(env: CODE_REVIEW_LABELS_ON_CLEAN)
|
|
8380
8464
|
--review-file <path> Raw code-review output file (default: code-review.md)
|
|
8381
8465
|
--output <path> Generated payload artifact (default: review-comments.json)
|
|
8382
8466
|
--cwd <path> Working directory (default: process.cwd())
|
|
@@ -8558,6 +8642,8 @@ async function run(config, bridges) {
|
|
|
8558
8642
|
if (config.dryRun || config.noPost) {
|
|
8559
8643
|
console.log(`Generated ${generated.length} comments, ${newCount} new. Posting disabled.`);
|
|
8560
8644
|
if (config.postSummary && parsed.summary) console.log("Summary note generated but not posted (posting disabled).");
|
|
8645
|
+
const dryRunLabels = resolveLabelChange(config, newCount > 0);
|
|
8646
|
+
if (dryRunLabels) console.log(`Would set ${dryRunLabels.outcome} labels: ${formatLabelChange(dryRunLabels)} (posting disabled).`);
|
|
8561
8647
|
runContext.posted = 0;
|
|
8562
8648
|
return {
|
|
8563
8649
|
generated,
|
|
@@ -8621,6 +8707,15 @@ async function run(config, bridges) {
|
|
|
8621
8707
|
runContext.posted = posted;
|
|
8622
8708
|
runContext.draftsPublishFailed = draftsPublishFailed;
|
|
8623
8709
|
if (posted > 0) runContext.postedBySeverity = countPostedBySeverity(generated);
|
|
8710
|
+
const labelChange = resolveLabelChange(config, posted > 0);
|
|
8711
|
+
if (labelChange) try {
|
|
8712
|
+
await platform.updateLabels(labelChange.add, labelChange.remove);
|
|
8713
|
+
runContext.labelsOutcome = labelChange.outcome;
|
|
8714
|
+
console.log(`Set ${labelChange.outcome} labels: ${formatLabelChange(labelChange)}.`);
|
|
8715
|
+
} catch (error) {
|
|
8716
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
8717
|
+
console.warn(`[code-review] Could not set ${labelChange.outcome} labels (${formatLabelChange(labelChange)}) — not failing the review. (${detail})`);
|
|
8718
|
+
}
|
|
8624
8719
|
return {
|
|
8625
8720
|
generated,
|
|
8626
8721
|
posted,
|
|
@@ -8629,6 +8724,34 @@ async function run(config, bridges) {
|
|
|
8629
8724
|
};
|
|
8630
8725
|
});
|
|
8631
8726
|
}
|
|
8727
|
+
/**
|
|
8728
|
+
* Pick the label change for a review outcome: `findings` when the review
|
|
8729
|
+
* published at least one fresh comment, `clean` otherwise. The outcome's labels
|
|
8730
|
+
* are added and the other outcome's labels removed, since GitLab CE does not
|
|
8731
|
+
* enforce scoped-label exclusivity. Returns `null` when neither label set is
|
|
8732
|
+
* configured, so the feature makes no API call unless opted in.
|
|
8733
|
+
*/
|
|
8734
|
+
function resolveLabelChange(config, hasFreshComments) {
|
|
8735
|
+
const onFindings = config.labelsOnFindings ?? [];
|
|
8736
|
+
const onClean = config.labelsOnClean ?? [];
|
|
8737
|
+
if (onFindings.length === 0 && onClean.length === 0) return null;
|
|
8738
|
+
return hasFreshComments ? {
|
|
8739
|
+
outcome: "findings",
|
|
8740
|
+
add: onFindings,
|
|
8741
|
+
remove: onClean
|
|
8742
|
+
} : {
|
|
8743
|
+
outcome: "clean",
|
|
8744
|
+
add: onClean,
|
|
8745
|
+
remove: onFindings
|
|
8746
|
+
};
|
|
8747
|
+
}
|
|
8748
|
+
/** Render a label change for logs, e.g. `add [mr::needs-review]; remove [mr::change-requested]`. */
|
|
8749
|
+
function formatLabelChange(change) {
|
|
8750
|
+
const parts = [];
|
|
8751
|
+
if (change.add.length > 0) parts.push(`add [${change.add.join(", ")}]`);
|
|
8752
|
+
if (change.remove.length > 0) parts.push(`remove [${change.remove.join(", ")}]`);
|
|
8753
|
+
return parts.join("; ");
|
|
8754
|
+
}
|
|
8632
8755
|
function zeroReviewUsage(model, thinkingLevel) {
|
|
8633
8756
|
return {
|
|
8634
8757
|
model,
|
|
@@ -8766,10 +8889,10 @@ async function main(argv = process.argv.slice(2)) {
|
|
|
8766
8889
|
return;
|
|
8767
8890
|
}
|
|
8768
8891
|
if (argv.includes("--version") || argv.includes("-v")) {
|
|
8769
|
-
console.log("0.
|
|
8892
|
+
console.log("0.10.0");
|
|
8770
8893
|
return;
|
|
8771
8894
|
}
|
|
8772
|
-
process.stderr.write(`[code-review] @weareikko/code-review v0.
|
|
8895
|
+
process.stderr.write(`[code-review] @weareikko/code-review v0.10.0\n`);
|
|
8773
8896
|
assertNodeVersion();
|
|
8774
8897
|
applyCodeReviewEnvPrefix();
|
|
8775
8898
|
applyDefaultCacheRetention();
|
|
@@ -8790,6 +8913,6 @@ if (isDirectRun()) main().catch((error) => {
|
|
|
8790
8913
|
process.exitCode = 1;
|
|
8791
8914
|
});
|
|
8792
8915
|
//#endregion
|
|
8793
|
-
export {
|
|
8916
|
+
export { buildSummaryHistoryEntries as $, connectMcpServers as A, traceMcpDiagnostic as B, findSkillForPath as C, readToolPath as D, formatSkillUsageState as E, createDiagnosticRunId as F, SUMMARY_HISTORY_ENTRY_START as G, toGitLabReviewSeverity as H, diagnosticChannels as I, SUMMARY_MARKER as J, SUMMARY_HISTORY_LIMIT as K, mcpDiagnosticChannels as L, DIAGNOSTIC_CHANNEL_PREFIX as M, MCP_DIAGNOSTIC_CHANNEL_NAMES as N, parseReviewMarkdown as O, createDiagnosticContext as P, buildSummaryBody as Q, traceDiagnostic as R, createSkillReadCounter as S, formatReviewUsageSummary as T, SUMMARY_HISTORY_END as U, normalizeSeverity as V, SUMMARY_HISTORY_ENTRY_END as W, buildReviewedCommitFooter as X, buildArchivedSummaryEntry as Y, buildSizeNoticeBlock as Z, buildPayload as _, resolveNpmSkillDir as _t, formatSkillsFooter as a, stripSummaryHistory as at, filterDiff as b, resolveLabelChange as c, appendFingerprintMarkers as ct, blobUrl as d, fingerprints as dt, extractReviewedCommitSha as et, formatSkillLink as f, normalizeBody as ft, buildGeneratedComments as g, parseSkillSpec as gt, skillSourceUrl as h, loadNamedSkill as ht, formatPerModelUsage as i, findExistingSummaryNoteId as it, DIAGNOSTIC_CHANNEL_NAMES as j, parseReviewMarkdownWithWarnings as k, run as l, extractDiffHunkContext as lt, skillDisplayName as m, gitSkillCacheKey as mt, formatLabelChange as n, findExistingReviewedCommitSha as nt, formatUsageLine as o, stripSummaryMarker as ot, gitRepoWebUrl as p, sha256 as pt, SUMMARY_HISTORY_START as q, formatMcpFooter as r, findExistingSummaryNote as rt, main as s, upsertSummaryNote as st, countPostedBySeverity as t, extractSummaryHistoryEntries as tt, withHttpStamping as u, extractExistingFingerprints as ut, isOtelEnabled as v, resolveSkillCacheDir as vt, formatMcpUsageState as w, runReview as x, startOtelBridge as y, traceDiagnosticPhase as z };
|
|
8794
8917
|
|
|
8795
|
-
//# sourceMappingURL=cli-
|
|
8918
|
+
//# sourceMappingURL=cli-oQSwCSL0.js.map
|