co-maintainer 0.7.10-beta.2 → 0.7.11-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/package.json +1 -1
- package/dist/src/cli/commands/registry.js +12 -0
- package/dist/src/cli/commands/set.js +60 -4
- package/dist/src/config.d.ts +7 -0
- package/dist/src/local/review_local.js +8 -2
- package/dist/src/pr/review_tools.d.ts +26 -4
- package/dist/src/pr/review_tools.js +45 -5
- package/dist/src/pr/reviewer.d.ts +7 -2
- package/dist/src/pr/reviewer.js +79 -15
- package/dist/src/review/private_text.d.ts +26 -0
- package/dist/src/review/private_text.js +131 -0
- package/dist/src/services/remote_review.js +4 -1
- package/dist/src/services/review.d.ts +8 -0
- package/dist/src/services/review.js +13 -2
- package/dist/src/tools/mcp_client.d.ts +81 -0
- package/dist/src/tools/mcp_client.js +259 -0
- package/dist/src/tools/mcp_config.d.ts +26 -0
- package/dist/src/tools/mcp_config.js +111 -0
- package/dist/src/tools/mcp_tools.d.ts +39 -0
- package/dist/src/tools/mcp_tools.js +150 -0
- package/dist/src/tools/search_non_code.d.ts +8 -0
- package/dist/src/tools/search_non_code.js +17 -7
- package/dist/src/util/runtime.d.ts +11 -1
- package/dist/src/util/runtime.js +34 -5
- package/package.json +1 -1
package/dist/package.json
CHANGED
|
@@ -935,6 +935,17 @@ export const COMMANDS = [
|
|
|
935
935
|
default: "3",
|
|
936
936
|
description: "The most lines search-non-code returns around a match. Needs --repo. 0 or -1 means no limit.",
|
|
937
937
|
},
|
|
938
|
+
{
|
|
939
|
+
name: "mcp-config",
|
|
940
|
+
value: "PATH",
|
|
941
|
+
description: "Read the repository's MCP servers from this JSON file and store them. Reviews offer their listed read-only tools to the model. Needs --repo. Refused when CM_MCP_DISABLED=1.",
|
|
942
|
+
},
|
|
943
|
+
{
|
|
944
|
+
name: "mcp-allow-forks",
|
|
945
|
+
value: "true|false",
|
|
946
|
+
default: "false",
|
|
947
|
+
description: "Offer MCP tools in serve reviews of pull requests from forks. Needs --repo.",
|
|
948
|
+
},
|
|
938
949
|
{
|
|
939
950
|
name: "guide-full-every",
|
|
940
951
|
value: "N",
|
|
@@ -990,6 +1001,7 @@ export const COMMANDS = [
|
|
|
990
1001
|
"co-maintainer set --remote-host=https://review.example.com --remote-token=...",
|
|
991
1002
|
"co-maintainer set --repo=owner/repo --review-system-prompt='Focus on the parser.'",
|
|
992
1003
|
"co-maintainer set --repo=owner/repo --diagram-runtime=plantuml-server",
|
|
1004
|
+
"co-maintainer set --repo=owner/repo --mcp-config=./mcp.json",
|
|
993
1005
|
"co-maintainer set --unset=token",
|
|
994
1006
|
],
|
|
995
1007
|
},
|
|
@@ -10,6 +10,7 @@ import { verifyOpenCode } from "../../ai/opencode.js";
|
|
|
10
10
|
import { die } from "../error.js";
|
|
11
11
|
import { parsePolicy } from "../../services/review_policy.js";
|
|
12
12
|
import { isCodegraphVersion } from "../../tools/codegraph.js";
|
|
13
|
+
import { MCP_DISABLED_MESSAGE, McpConfigError, mcpDisabled, mcpServersSummary, parseMcpConfig, } from "../../tools/mcp_config.js";
|
|
13
14
|
import { AI_PROVIDERS, rejectRetiredProvider } from "../../ai/provider.js";
|
|
14
15
|
import { MAX_CONCURRENCY, MIN_CONCURRENCY, } from "../../services/concurrency.js";
|
|
15
16
|
import { renderCommandHelp, renderGlobalHelp } from "./registry.js";
|
|
@@ -86,6 +87,8 @@ export async function runSet(args) {
|
|
|
86
87
|
...DIAGRAM_FLAGS,
|
|
87
88
|
"review-read-diff-max-chars",
|
|
88
89
|
...TOOL_LIMIT_FLAGS.map(([flag]) => flag),
|
|
90
|
+
"mcp-config",
|
|
91
|
+
"mcp-allow-forks",
|
|
89
92
|
"guide-full-every",
|
|
90
93
|
"password",
|
|
91
94
|
"extension-rerun-on-restart",
|
|
@@ -107,7 +110,12 @@ export async function runSet(args) {
|
|
|
107
110
|
await runSetRepo(repoArg, args);
|
|
108
111
|
return;
|
|
109
112
|
}
|
|
110
|
-
for (const name of [
|
|
113
|
+
for (const name of [
|
|
114
|
+
...DIAGRAM_FLAGS,
|
|
115
|
+
"review-references",
|
|
116
|
+
"mcp-config",
|
|
117
|
+
"mcp-allow-forks",
|
|
118
|
+
]) {
|
|
111
119
|
if (text(args, name) !== undefined)
|
|
112
120
|
die(`--${name} needs --repo`);
|
|
113
121
|
}
|
|
@@ -410,6 +418,8 @@ const REPO_SCOPED_FLAGS = new Set([
|
|
|
410
418
|
...DIAGRAM_FLAGS,
|
|
411
419
|
"review-read-diff-max-chars",
|
|
412
420
|
...TOOL_LIMIT_FLAGS.map(([flag]) => flag),
|
|
421
|
+
"mcp-config",
|
|
422
|
+
"mcp-allow-forks",
|
|
413
423
|
"guide-full-every",
|
|
414
424
|
"review-references",
|
|
415
425
|
"gh-concurrent",
|
|
@@ -430,6 +440,10 @@ const REPO_SCOPED_UNSET = new Set([
|
|
|
430
440
|
"review-read-diff-max-chars",
|
|
431
441
|
"reviewReadDiffMaxChars",
|
|
432
442
|
...TOOL_LIMIT_FLAGS.flat(),
|
|
443
|
+
"mcp-config",
|
|
444
|
+
"mcpServers",
|
|
445
|
+
"mcp-allow-forks",
|
|
446
|
+
"mcpAllowForks",
|
|
433
447
|
"guide-full-every",
|
|
434
448
|
"guideFullEvery",
|
|
435
449
|
"gh-concurrent",
|
|
@@ -439,7 +453,7 @@ const REPO_SCOPED_UNSET = new Set([
|
|
|
439
453
|
"review-references",
|
|
440
454
|
"reviewReferences",
|
|
441
455
|
]);
|
|
442
|
-
/** `set --repo=owner/repo [--review-system-prompt=... | --review-system-prompt-max-chars=N | --review-read-diff-max-chars=N | --review-tool-result-max-chars=N | --review-tool-budget-chars=N | --review-search-max-context-lines=N | --unset=name]`
|
|
456
|
+
/** `set --repo=owner/repo [--review-system-prompt=... | --review-system-prompt-max-chars=N | --review-read-diff-max-chars=N | --review-tool-result-max-chars=N | --review-tool-budget-chars=N | --review-search-max-context-lines=N | --mcp-config=PATH | --mcp-allow-forks=true|false | --unset=name]`
|
|
443
457
|
* writes the repository-scoped settings to `repos[owner/repo]` in config.json
|
|
444
458
|
* instead of the global config. */
|
|
445
459
|
async function runSetRepo(typed, args) {
|
|
@@ -554,6 +568,42 @@ async function runSetRepo(typed, args) {
|
|
|
554
568
|
}
|
|
555
569
|
patch[field] = value;
|
|
556
570
|
}
|
|
571
|
+
if (unset.has("mcp-config") || unset.has("mcpServers")) {
|
|
572
|
+
patch.mcpServers = undefined;
|
|
573
|
+
}
|
|
574
|
+
const mcpFile = text(args, "mcp-config");
|
|
575
|
+
if (mcpFile !== undefined) {
|
|
576
|
+
// The cloud sets the switch from outside the container, so a stored
|
|
577
|
+
// config can never turn MCP back on there.
|
|
578
|
+
if (mcpDisabled())
|
|
579
|
+
die(MCP_DISABLED_MESSAGE);
|
|
580
|
+
let raw;
|
|
581
|
+
try {
|
|
582
|
+
raw = await readTextFile(mcpFile);
|
|
583
|
+
}
|
|
584
|
+
catch (error) {
|
|
585
|
+
die(`Could not read the MCP config ${mcpFile}: ${String(error)}`);
|
|
586
|
+
}
|
|
587
|
+
try {
|
|
588
|
+
patch.mcpServers = parseMcpConfig(raw);
|
|
589
|
+
}
|
|
590
|
+
catch (error) {
|
|
591
|
+
if (error instanceof McpConfigError) {
|
|
592
|
+
die(`--mcp-config: ${error.message}`);
|
|
593
|
+
}
|
|
594
|
+
throw error;
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
if (unset.has("mcp-allow-forks") || unset.has("mcpAllowForks")) {
|
|
598
|
+
patch.mcpAllowForks = undefined;
|
|
599
|
+
}
|
|
600
|
+
const allowForks = text(args, "mcp-allow-forks");
|
|
601
|
+
if (allowForks !== undefined) {
|
|
602
|
+
if (!["true", "false"].includes(allowForks)) {
|
|
603
|
+
die("--mcp-allow-forks must be true or false");
|
|
604
|
+
}
|
|
605
|
+
patch.mcpAllowForks = allowForks === "true";
|
|
606
|
+
}
|
|
557
607
|
if (unset.has("guide-full-every") || unset.has("guideFullEvery")) {
|
|
558
608
|
patch.guideFullEvery = undefined;
|
|
559
609
|
}
|
|
@@ -588,7 +638,7 @@ async function runSetRepo(typed, args) {
|
|
|
588
638
|
patch.reviewSystemPrompt = prompt.trim() === "" ? undefined : prompt;
|
|
589
639
|
}
|
|
590
640
|
if (Object.keys(patch).length === 0) {
|
|
591
|
-
die("Nothing to set. Pass --review-system-prompt=, --review-system-prompt-max-chars=N, --diagram-runtime=, --plantuml-server=, --plantuml-output-format=, --review-read-diff-max-chars=N, --review-tool-result-max-chars=N, --review-tool-budget-chars=N, --review-search-max-context-lines=N, --guide-full-every=N, --review-references=on|off, or --unset=name with --repo.");
|
|
641
|
+
die("Nothing to set. Pass --review-system-prompt=, --review-system-prompt-max-chars=N, --diagram-runtime=, --plantuml-server=, --plantuml-output-format=, --review-read-diff-max-chars=N, --review-tool-result-max-chars=N, --review-tool-budget-chars=N, --review-search-max-context-lines=N, --mcp-config=PATH, --mcp-allow-forks=true|false, --guide-full-every=N, --review-references=on|off, or --unset=name with --repo.");
|
|
592
642
|
}
|
|
593
643
|
// The values after this write are the ones given here, or the stored ones.
|
|
594
644
|
// Lowering the cap re-checks the stored prompt too, so it cannot end up over
|
|
@@ -605,7 +655,13 @@ async function runSetRepo(typed, args) {
|
|
|
605
655
|
die(`--review-system-prompt: ${problem}`);
|
|
606
656
|
}
|
|
607
657
|
await writeRepoConfig(repo, patch);
|
|
608
|
-
|
|
658
|
+
// MCP servers print by name and tool: their command and env may hold
|
|
659
|
+
// secrets.
|
|
660
|
+
const summary = Object.entries(patch).map(([key, value]) => value === undefined
|
|
661
|
+
? `${key} (unset)`
|
|
662
|
+
: key === "mcpServers"
|
|
663
|
+
? `${key}=${mcpServersSummary(patch.mcpServers)}`
|
|
664
|
+
: `${key}=${value}`);
|
|
609
665
|
console.log(`[set] updated ${repo}: ${summary.join(", ")}`);
|
|
610
666
|
console.log(`Saved to ${configPath()}`);
|
|
611
667
|
}
|
package/dist/src/config.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type Platform } from "./util/runtime.ts";
|
|
2
2
|
import type { ExtensionRegistration } from "./extensions/registry.ts";
|
|
3
|
+
import type { McpServerConfig } from "./tools/mcp_config.ts";
|
|
3
4
|
/** Everything init/remake resolved for one repo, except secrets, an API
|
|
4
5
|
* token is never written to config.json, only ever taken from --token or
|
|
5
6
|
* an env file. Remembering this lets `remake owner/repo` run with no
|
|
@@ -75,6 +76,12 @@ export type RepoConfig = {
|
|
|
75
76
|
/** Most context lines `search-non-code` returns around a match. Unset means
|
|
76
77
|
* the default, `0` or a negative number means no limit. */
|
|
77
78
|
reviewSearchMaxContextLines?: number;
|
|
79
|
+
/** The repository's MCP servers, read from the file `set --mcp-config`
|
|
80
|
+
* names. Their `env` values are never printed. */
|
|
81
|
+
mcpServers?: Record<string, McpServerConfig>;
|
|
82
|
+
/** `serve` offers MCP tools to a pull request from a fork only when this
|
|
83
|
+
* is true. */
|
|
84
|
+
mcpAllowForks?: boolean;
|
|
78
85
|
/** Every N-th `sync` whose guide input changed rewrites the review guide
|
|
79
86
|
* in full, the others edit it. Unset means 10, `1` always rewrites, `0`
|
|
80
87
|
* never rewrites after `init`. */
|
|
@@ -213,8 +213,14 @@ export async function runLocalReview(cli) {
|
|
|
213
213
|
// model call. The handler has released the lock.
|
|
214
214
|
if (interrupted())
|
|
215
215
|
return;
|
|
216
|
-
// Search and codegraph read the working tree at the git root.
|
|
217
|
-
|
|
216
|
+
// Search and codegraph read the working tree at the git root. The
|
|
217
|
+
// repository's MCP servers run here too.
|
|
218
|
+
extras.tools = {
|
|
219
|
+
kind: "tree",
|
|
220
|
+
root,
|
|
221
|
+
codegraph: codegraphPrep.tools,
|
|
222
|
+
mcp: true,
|
|
223
|
+
};
|
|
218
224
|
const stopHeartbeat = startHeartbeat("reviewing local changes");
|
|
219
225
|
const started = performance.now();
|
|
220
226
|
const aiMetrics = emptyAiMetrics();
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
/** The tools a review offers the model, prepared in one place for every mode
|
|
2
2
|
* (issue 79): codegraph when it is on, `search-non-code` where a checkout is
|
|
3
|
-
* there to search,
|
|
4
|
-
*
|
|
3
|
+
* there to search, `read-full-diff` from the diff plan, and the tools of the
|
|
4
|
+
* repository's MCP servers where the mode runs them. */
|
|
5
5
|
import type { ToolHandler } from "../ai/mermaid_loop.ts";
|
|
6
|
-
import type { Options } from "../types.ts";
|
|
6
|
+
import type { Json, Options } from "../types.ts";
|
|
7
|
+
import { type McpServerConfig } from "../tools/mcp_config.ts";
|
|
8
|
+
import { type McpSession } from "../tools/mcp_tools.ts";
|
|
7
9
|
import { type Run } from "./checkout.ts";
|
|
8
10
|
import { type SearchOptions } from "../tools/search_non_code.ts";
|
|
9
11
|
/** Where a review's tools run. */
|
|
@@ -17,6 +19,8 @@ export type ReviewToolSource =
|
|
|
17
19
|
commit: string;
|
|
18
20
|
search: boolean;
|
|
19
21
|
allowInstall?: boolean;
|
|
22
|
+
/** Start the repository's MCP servers. */
|
|
23
|
+
mcp?: boolean;
|
|
20
24
|
}
|
|
21
25
|
/** A tree already on disk with its codegraph tools ready: local review at
|
|
22
26
|
* the git root. */
|
|
@@ -24,18 +28,24 @@ export type ReviewToolSource =
|
|
|
24
28
|
kind: "tree";
|
|
25
29
|
root: string;
|
|
26
30
|
codegraph: ToolHandler[];
|
|
31
|
+
mcp?: boolean;
|
|
27
32
|
}
|
|
28
33
|
/** Tools another process runs: a remote review, where the client runs
|
|
29
|
-
* codegraph and search in its own checkout.
|
|
34
|
+
* codegraph and search in its own checkout. The server runs the MCP
|
|
35
|
+
* servers it has for the repository itself. */
|
|
30
36
|
| {
|
|
31
37
|
kind: "bridge";
|
|
32
38
|
tools: ToolHandler[];
|
|
39
|
+
mcp?: boolean;
|
|
33
40
|
};
|
|
34
41
|
export type ReviewTools = {
|
|
35
42
|
/** Every tool to offer, codegraph first. */
|
|
36
43
|
tools: ToolHandler[];
|
|
37
44
|
/** The codegraph tools alone, which decide `codegraphState`. */
|
|
38
45
|
codegraph: ToolHandler[];
|
|
46
|
+
/** The review's MCP servers, empty when it runs none. The review stops
|
|
47
|
+
* them however it ends. */
|
|
48
|
+
mcp: McpSession;
|
|
39
49
|
};
|
|
40
50
|
export type ReviewToolsDeps = {
|
|
41
51
|
run?: Run;
|
|
@@ -43,6 +53,8 @@ export type ReviewToolsDeps = {
|
|
|
43
53
|
codegraph?: (worktree: () => Promise<string>) => Promise<ToolHandler[]>;
|
|
44
54
|
/** Overrides the repository's search settings, for tests. */
|
|
45
55
|
search?: SearchOptions;
|
|
56
|
+
/** Overrides the MCP start, for tests. */
|
|
57
|
+
mcp?: (servers: Record<string, McpServerConfig>) => Promise<McpSession>;
|
|
46
58
|
};
|
|
47
59
|
export declare function isCodegraphTool(name: string): boolean;
|
|
48
60
|
/** The review's tools. `diffTools` is the diff plan's own tools
|
|
@@ -50,6 +62,16 @@ export declare function isCodegraphTool(name: string): boolean;
|
|
|
50
62
|
* prepared at the same time. A setup that fails leaves its tools out and the
|
|
51
63
|
* review goes on with the rest. */
|
|
52
64
|
export declare function prepareReviewTools(source: ReviewToolSource, options: Pick<Options, "repo" | "useCodegraph">, diffTools: ToolHandler[] | Promise<ToolHandler[]>, deps?: ReviewToolsDeps): Promise<ReviewTools>;
|
|
65
|
+
/** The repository's MCP servers, started when this mode runs them, none is
|
|
66
|
+
* turned off by `CM_MCP_DISABLED=1`, and the repository has some. */
|
|
67
|
+
export declare function startMcp(source: ReviewToolSource, repo: string, deps?: Pick<ReviewToolsDeps, "mcp">): Promise<McpSession>;
|
|
68
|
+
/** True when the pull request's head lives in another repository, or in
|
|
69
|
+
* none because the fork was deleted. The same rule as the review policy's
|
|
70
|
+
* `fork`. */
|
|
71
|
+
export declare function pullFromFork(pr: Json, repo: string): boolean;
|
|
72
|
+
/** Whether a `serve` review of this pull request may start the repository's
|
|
73
|
+
* MCP servers: a pull request from a fork only with `--mcp-allow-forks=true`. */
|
|
74
|
+
export declare function mcpAllowedForPull(pr: Json, repo: string): boolean;
|
|
53
75
|
/** `codegraphState` from the codegraph tools alone, never from the length of
|
|
54
76
|
* the whole tool list. */
|
|
55
77
|
export declare function codegraphState(useCodegraph: boolean | undefined, codegraph: ToolHandler[]): "used" | "disabled" | "unavailable";
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { log } from "../util/log.js";
|
|
2
|
+
import { readConfig } from "../config.js";
|
|
3
|
+
import { mcpDisabled } from "../tools/mcp_config.js";
|
|
4
|
+
import { emptyMcpSession, startMcpSession, } from "../tools/mcp_tools.js";
|
|
2
5
|
import { ensureWorktree, runCommand } from "./checkout.js";
|
|
3
6
|
import { prepareCodegraphTools } from "./codegraph_tools.js";
|
|
4
7
|
import { searchNonCodeTool, searchOptionsFor, } from "../tools/search_non_code.js";
|
|
@@ -10,11 +13,32 @@ export function isCodegraphTool(name) {
|
|
|
10
13
|
* prepared at the same time. A setup that fails leaves its tools out and the
|
|
11
14
|
* review goes on with the rest. */
|
|
12
15
|
export async function prepareReviewTools(source, options, diffTools, deps = {}) {
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
const starting = startMcp(source, options.repo, deps);
|
|
17
|
+
try {
|
|
18
|
+
const [own, diff, mcp] = await Promise.all([
|
|
19
|
+
prepareOwnTools(source, options, deps),
|
|
20
|
+
diffTools,
|
|
21
|
+
starting,
|
|
22
|
+
]);
|
|
23
|
+
return { ...own, tools: [...own.tools, ...diff, ...mcp.tools], mcp };
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
// Servers that started while another part failed are stopped here, as
|
|
27
|
+
// the review that would stop them never gets them.
|
|
28
|
+
void starting.then((mcp) => mcp.stop(), () => { });
|
|
29
|
+
throw error;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/** The repository's MCP servers, started when this mode runs them, none is
|
|
33
|
+
* turned off by `CM_MCP_DISABLED=1`, and the repository has some. */
|
|
34
|
+
export async function startMcp(source, repo, deps = {}) {
|
|
35
|
+
if (!source.mcp || mcpDisabled())
|
|
36
|
+
return emptyMcpSession();
|
|
37
|
+
const servers = readConfig().repos?.[repo]?.mcpServers;
|
|
38
|
+
if (!servers || Object.keys(servers).length === 0) {
|
|
39
|
+
return emptyMcpSession();
|
|
40
|
+
}
|
|
41
|
+
return (deps.mcp ?? startMcpSession)(servers);
|
|
18
42
|
}
|
|
19
43
|
async function prepareOwnTools(source, options, deps) {
|
|
20
44
|
const search = (root) => searchNonCodeTool(root, deps.search ?? searchOptionsFor(options.repo));
|
|
@@ -60,6 +84,22 @@ async function prepareOwnTools(source, options, deps) {
|
|
|
60
84
|
codegraph,
|
|
61
85
|
};
|
|
62
86
|
}
|
|
87
|
+
/** True when the pull request's head lives in another repository, or in
|
|
88
|
+
* none because the fork was deleted. The same rule as the review policy's
|
|
89
|
+
* `fork`. */
|
|
90
|
+
export function pullFromFork(pr, repo) {
|
|
91
|
+
const head = pr.head;
|
|
92
|
+
const headRepo = head?.repo?.full_name;
|
|
93
|
+
return (typeof headRepo !== "string" ||
|
|
94
|
+
headRepo.toLowerCase() !== repo.toLowerCase());
|
|
95
|
+
}
|
|
96
|
+
/** Whether a `serve` review of this pull request may start the repository's
|
|
97
|
+
* MCP servers: a pull request from a fork only with `--mcp-allow-forks=true`. */
|
|
98
|
+
export function mcpAllowedForPull(pr, repo) {
|
|
99
|
+
if (!pullFromFork(pr, repo))
|
|
100
|
+
return true;
|
|
101
|
+
return readConfig().repos?.[repo]?.mcpAllowForks === true;
|
|
102
|
+
}
|
|
63
103
|
/** `codegraphState` from the codegraph tools alone, never from the length of
|
|
64
104
|
* the whole tool list. */
|
|
65
105
|
export function codegraphState(useCodegraph, codegraph) {
|
|
@@ -40,6 +40,9 @@ export type ReviewExtras = {
|
|
|
40
40
|
/** Stop from the dashboard. An AI call that already started finishes, and
|
|
41
41
|
* no new one starts: no further tool round, retry or improvement pass. */
|
|
42
42
|
signal?: AbortSignal;
|
|
43
|
+
/** True in `serve`: a pull request from a fork gets no MCP tools unless
|
|
44
|
+
* the repository sets `mcpAllowForks`. */
|
|
45
|
+
mcpForkRule?: boolean;
|
|
43
46
|
};
|
|
44
47
|
/** What a review run returns to every flow. */
|
|
45
48
|
export type ReviewOutcome = AiResponse & {
|
|
@@ -53,11 +56,13 @@ export type ReviewOutcome = AiResponse & {
|
|
|
53
56
|
referenceContext: ReferenceContext;
|
|
54
57
|
codegraphState: "used" | "disabled" | "unavailable";
|
|
55
58
|
coverage: Coverage;
|
|
56
|
-
/** `diff_dropped`, `diff_withheld`, `summary_failed
|
|
57
|
-
* `tool_budget_spent`. */
|
|
59
|
+
/** `diff_dropped`, `diff_withheld`, `summary_failed`,
|
|
60
|
+
* `tool_budget_spent`, the MCP warnings and `private_text_removed`. */
|
|
58
61
|
warnings: CoverageWarning[];
|
|
59
62
|
/** What the review's tools did, for `usage.tools`. */
|
|
60
63
|
tools: ToolUsage;
|
|
64
|
+
/** The MCP servers that started for this review, by name. */
|
|
65
|
+
mcpServers: string[];
|
|
61
66
|
/** Every changed file of the subject, for the result's `revision` block. */
|
|
62
67
|
diffStats: {
|
|
63
68
|
files: number;
|
package/dist/src/pr/reviewer.js
CHANGED
|
@@ -4,7 +4,9 @@ import { completeWithMermaidTools, } from "../ai/mermaid_loop.js";
|
|
|
4
4
|
import { loadGuides } from "../review/guides.js";
|
|
5
5
|
import { notInitializedError } from "../review/not_initialized.js";
|
|
6
6
|
import { computeScope } from "./scope.js";
|
|
7
|
-
import { codegraphState, prepareReviewTools, } from "./review_tools.js";
|
|
7
|
+
import { codegraphState, mcpAllowedForPull, prepareReviewTools, } from "./review_tools.js";
|
|
8
|
+
import { emptyMcpSession, isMcpTool } from "../tools/mcp_tools.js";
|
|
9
|
+
import { MCP_PRIVATE_GUIDANCE, privateTextWarning, removePrivateText, } from "../review/private_text.js";
|
|
8
10
|
import { ToolGate, toolBudgetChars, toolResultMaxChars, } from "../ai/tool_gate.js";
|
|
9
11
|
import { SEARCH_NON_CODE } from "../tools/search_non_code.js";
|
|
10
12
|
import { severitySection } from "./review_copy.js";
|
|
@@ -161,12 +163,37 @@ identifying the concrete input or code path that misbehaves when you can.`;
|
|
|
161
163
|
/** Said next to the codegraph instructions when the review offers search. */
|
|
162
164
|
export const SEARCH_NON_CODE_GUIDANCE = `Use search-non-code for docs, configuration and other files codegraph does not index. Use codegraph for code.`;
|
|
163
165
|
/** The codegraph instructions, with the search sentence when search is one
|
|
164
|
-
* of the tools the model can call
|
|
165
|
-
* none, so it is passed no
|
|
166
|
+
* of the tools the model can call, and the private results sentence when an
|
|
167
|
+
* MCP tool is. A provider without tool support gets none, so it is passed no
|
|
168
|
+
* tools. */
|
|
166
169
|
function toolGuidance(tools) {
|
|
167
|
-
return
|
|
168
|
-
|
|
169
|
-
|
|
170
|
+
return [
|
|
171
|
+
CODEGRAPH_DIFF_VERIFICATION,
|
|
172
|
+
...(tools.some((tool) => tool.name === SEARCH_NON_CODE)
|
|
173
|
+
? [SEARCH_NON_CODE_GUIDANCE]
|
|
174
|
+
: []),
|
|
175
|
+
...(tools.some((tool) => isMcpTool(tool.name))
|
|
176
|
+
? [MCP_PRIVATE_GUIDANCE]
|
|
177
|
+
: []),
|
|
178
|
+
].join("\n");
|
|
179
|
+
}
|
|
180
|
+
/** Stops the MCP servers of every tool preparation a review started,
|
|
181
|
+
* however the review ended. A preparation that failed stopped its own. */
|
|
182
|
+
async function stopMcp(opened) {
|
|
183
|
+
await Promise.all(opened.map((tools) => tools.then((ready) => ready.mcp.stop(), () => { })));
|
|
184
|
+
}
|
|
185
|
+
/** The rendered review with every passage copied from a private MCP result
|
|
186
|
+
* removed, and the review's MCP warnings. It runs before the text is
|
|
187
|
+
* printed, posted or stored, in every mode. */
|
|
188
|
+
function withoutPrivateText(reviewText, reviewTools) {
|
|
189
|
+
const privacy = removePrivateText(reviewText, reviewTools.mcp.privateResults());
|
|
190
|
+
return {
|
|
191
|
+
text: privacy.text,
|
|
192
|
+
warnings: [
|
|
193
|
+
...reviewTools.mcp.warnings(),
|
|
194
|
+
...privateTextWarning(privacy.removed),
|
|
195
|
+
],
|
|
196
|
+
};
|
|
170
197
|
}
|
|
171
198
|
/** One review's tool gate, from the repository's settings. */
|
|
172
199
|
function reviewGate(repo) {
|
|
@@ -253,6 +280,15 @@ async function allInOrder(values) {
|
|
|
253
280
|
return settled.map((item) => item.value);
|
|
254
281
|
}
|
|
255
282
|
export async function reviewPullRequest(client, options, usage, snapshot, ai, progress, extras) {
|
|
283
|
+
const opened = [];
|
|
284
|
+
try {
|
|
285
|
+
return await pullRequestReview(client, options, usage, snapshot, ai, progress, extras, opened);
|
|
286
|
+
}
|
|
287
|
+
finally {
|
|
288
|
+
await stopMcp(opened);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
async function pullRequestReview(client, options, usage, snapshot, ai, progress, extras, opened) {
|
|
256
292
|
if (!options.prNumber)
|
|
257
293
|
throw new Error("review requires a PR number");
|
|
258
294
|
const number = options.prNumber;
|
|
@@ -333,7 +369,12 @@ export async function reviewPullRequest(client, options, usage, snapshot, ai, pr
|
|
|
333
369
|
report,
|
|
334
370
|
});
|
|
335
371
|
// The pull request's checkout serves codegraph and search alike, and is
|
|
336
|
-
// made while the diff is prepared.
|
|
372
|
+
// made while the diff is prepared. In serve, a pull request from a fork
|
|
373
|
+
// starts no MCP server unless the repository allows it.
|
|
374
|
+
const mcp = !extras?.mcpForkRule || mcpAllowedForPull(pr, options.repo);
|
|
375
|
+
if (!mcp && readConfig().repos?.[options.repo]?.mcpServers) {
|
|
376
|
+
report("MCP servers · off for a pull request from a fork");
|
|
377
|
+
}
|
|
337
378
|
const source = extras?.tools ??
|
|
338
379
|
(headSha
|
|
339
380
|
? {
|
|
@@ -342,13 +383,20 @@ export async function reviewPullRequest(client, options, usage, snapshot, ai, pr
|
|
|
342
383
|
commit: headSha,
|
|
343
384
|
search: true,
|
|
344
385
|
allowInstall: options.allowToolInstall,
|
|
386
|
+
mcp,
|
|
345
387
|
}
|
|
346
388
|
: undefined);
|
|
389
|
+
const preparingTools = source
|
|
390
|
+
? prepareReviewTools(source, options, preparing.then((plan) => plan.tools))
|
|
391
|
+
: preparing.then((plan) => ({
|
|
392
|
+
tools: plan.tools,
|
|
393
|
+
codegraph: [],
|
|
394
|
+
mcp: emptyMcpSession(),
|
|
395
|
+
}));
|
|
396
|
+
opened.push(preparingTools);
|
|
347
397
|
const [prepared, reviewTools] = await Promise.all([
|
|
348
398
|
preparing,
|
|
349
|
-
|
|
350
|
-
? prepareReviewTools(source, options, preparing.then((plan) => plan.tools))
|
|
351
|
-
: preparing.then((plan) => ({ tools: plan.tools, codegraph: [] })),
|
|
399
|
+
preparingTools,
|
|
352
400
|
]);
|
|
353
401
|
if (options.useCodegraph) {
|
|
354
402
|
report(`codegraph tools · ${reviewTools.codegraph.length > 0 ? "ready" : "unavailable"}`);
|
|
@@ -495,21 +543,32 @@ ${reviewText}`,
|
|
|
495
543
|
console.log(`\n----- IMPROVED REVIEW ${pass - 1} -----\n${reviewText}\n`);
|
|
496
544
|
}
|
|
497
545
|
}
|
|
546
|
+
const kept = withoutPrivateText(reviewText, reviewTools);
|
|
498
547
|
return {
|
|
499
548
|
...response,
|
|
500
|
-
text: `${severitySection()}\n${renderDiagrams(
|
|
549
|
+
text: `${severitySection()}\n${renderDiagrams(kept.text, options)}`,
|
|
501
550
|
visiblePaths: prepared.seenPaths,
|
|
502
551
|
guideBuiltAt: guides.guideBuiltAt,
|
|
503
552
|
referenceContext: { rules: guides.rules, codebase: guides.codebase },
|
|
504
553
|
codegraphState: codegraphState(options.useCodegraph, reviewTools.codegraph),
|
|
505
554
|
coverage: prepared.coverage,
|
|
506
|
-
warnings: [...prepared.warnings, ...gate.warnings()],
|
|
555
|
+
warnings: [...prepared.warnings, ...gate.warnings(), ...kept.warnings],
|
|
507
556
|
tools: gate.usage(),
|
|
557
|
+
mcpServers: reviewTools.mcp.servers,
|
|
508
558
|
diffStats: diffStats(named.map(({ file }) => diffFileFromGithub(file))),
|
|
509
559
|
};
|
|
510
560
|
}
|
|
511
561
|
/** Local workspace review, same prompt loop as PR review without GitHub. */
|
|
512
562
|
export async function reviewWorkspaceRevision(revision, options, headSha, usage, ai, progress, extras) {
|
|
563
|
+
const opened = [];
|
|
564
|
+
try {
|
|
565
|
+
return await workspaceReview(revision, options, headSha, usage, ai, progress, extras, opened);
|
|
566
|
+
}
|
|
567
|
+
finally {
|
|
568
|
+
await stopMcp(opened);
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
async function workspaceReview(revision, options, headSha, usage, ai, progress, extras, opened) {
|
|
513
572
|
const report = progress ?? (() => { });
|
|
514
573
|
const signal = extras?.signal;
|
|
515
574
|
report(modelSummary(options));
|
|
@@ -535,12 +594,15 @@ export async function reviewWorkspaceRevision(revision, options, headSha, usage,
|
|
|
535
594
|
usage,
|
|
536
595
|
report,
|
|
537
596
|
});
|
|
538
|
-
|
|
597
|
+
// Left out, this is a push review, which runs no MCP server.
|
|
598
|
+
const preparingTools = prepareReviewTools(extras?.tools ?? {
|
|
539
599
|
kind: "checkout",
|
|
540
600
|
pr: 0,
|
|
541
601
|
commit: headSha,
|
|
542
602
|
search: false,
|
|
543
603
|
}, options, prepared.tools);
|
|
604
|
+
opened.push(preparingTools);
|
|
605
|
+
const reviewTools = await preparingTools;
|
|
544
606
|
const extraTools = reviewTools.tools;
|
|
545
607
|
const gate = reviewGate(options.repo);
|
|
546
608
|
const totalDiffLines = ownFiles.reduce((sum, file) => sum + file.changes, 0);
|
|
@@ -615,16 +677,18 @@ ${reviewText}`,
|
|
|
615
677
|
await usage(response);
|
|
616
678
|
reviewText = await normalizeReviewResponse(provider, improvementRequest, response, extraTools, maxToolRounds, usage, report, options, gate, signal);
|
|
617
679
|
}
|
|
680
|
+
const kept = withoutPrivateText(reviewText, reviewTools);
|
|
618
681
|
return {
|
|
619
682
|
...response,
|
|
620
|
-
text: `${severitySection()}\n${renderDiagrams(
|
|
683
|
+
text: `${severitySection()}\n${renderDiagrams(kept.text, options)}`,
|
|
621
684
|
visiblePaths: prepared.seenPaths,
|
|
622
685
|
guideBuiltAt: guides.guideBuiltAt,
|
|
623
686
|
referenceContext: { rules: guides.rules, codebase: guides.codebase },
|
|
624
687
|
codegraphState: codegraphState(options.useCodegraph, reviewTools.codegraph),
|
|
625
688
|
coverage: prepared.coverage,
|
|
626
|
-
warnings: [...prepared.warnings, ...gate.warnings()],
|
|
689
|
+
warnings: [...prepared.warnings, ...gate.warnings(), ...kept.warnings],
|
|
627
690
|
tools: gate.usage(),
|
|
691
|
+
mcpServers: reviewTools.mcp.servers,
|
|
628
692
|
diffStats: diffStats(files),
|
|
629
693
|
};
|
|
630
694
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** The copied-passage check for private MCP results (issue 79).
|
|
2
|
+
*
|
|
3
|
+
* The prompt asks the model never to quote a private result. This is the
|
|
4
|
+
* check in code: before a review is printed, posted or stored, any run of 8
|
|
5
|
+
* or more consecutive words of its text that also appears in a private
|
|
6
|
+
* result, ignoring case and punctuation, is replaced. It catches copied
|
|
7
|
+
* passages. A single word, such as a customer's name, or a paraphrase passes
|
|
8
|
+
* it. */
|
|
9
|
+
import type { CoverageWarning } from "./coverage.ts";
|
|
10
|
+
/** Said in the review prompt when the model is offered an MCP tool. */
|
|
11
|
+
export declare const MCP_PRIVATE_GUIDANCE = "Results from mcp- tools are private. Base a finding on them when they show the change is wrong, and say only that a private source of this repository requires it. Never quote, paraphrase or summarize their text in a finding.";
|
|
12
|
+
/** What a removed passage becomes. */
|
|
13
|
+
export declare const PRIVATE_TEXT_REMOVED = "[private context removed]";
|
|
14
|
+
/** The shortest run of words that counts as a copied passage. */
|
|
15
|
+
export declare const PRIVATE_RUN_WORDS = 8;
|
|
16
|
+
/** The review's Markdown with every copied passage replaced, and how many
|
|
17
|
+
* were. A paragraph is checked as one piece, so a passage that wraps a line
|
|
18
|
+
* is still found. A suggestion block is the author's code with a fix and is
|
|
19
|
+
* left as it is. Inside any other fenced block each line is checked on its
|
|
20
|
+
* own, so the block keeps its lines. */
|
|
21
|
+
export declare function removePrivateText(markdown: string, privateResults: string[]): {
|
|
22
|
+
text: string;
|
|
23
|
+
removed: number;
|
|
24
|
+
};
|
|
25
|
+
/** `private_text_removed`, or nothing when no passage was removed. */
|
|
26
|
+
export declare function privateTextWarning(removed: number): CoverageWarning[];
|