crysk 0.0.0-stage → 0.3.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 +176 -0
- package/README.md +610 -2
- package/bin/pr-hero.js +166 -0
- package/config/models/anthropic.json +5 -0
- package/dist/SKILL-7e3725zn.md +496 -0
- package/dist/SKILL-7q35wcaz.md +66 -0
- package/dist/SKILL-9at22381.md +74 -0
- package/dist/SKILL-ex2hxxh3.md +134 -0
- package/dist/adjudicator-dtg2axnh.md +86 -0
- package/dist/admission-config.example-a9vqmmad.json +9 -0
- package/dist/ci-admission-camfbx2b.md +122 -0
- package/dist/cli.js +42292 -0
- package/dist/consolidate-ac0mnfyj.md +24 -0
- package/dist/deep-review-lifecycle-m698ybjp.md +362 -0
- package/dist/deep-review-logic-a6b1gczf.md +156 -0
- package/dist/deep-review-parity-0ec904db.md +120 -0
- package/dist/deep-review-reliability-qyakbjb9.md +125 -0
- package/dist/deep-review-resilience-3tz8y26e.md +118 -0
- package/dist/index.js +20190 -0
- package/dist/opencode-ci-7b0be64p.md +141 -0
- package/dist/review-refuter-j4e9gezy.md +71 -0
- package/dist/scout-yvp153q7.md +140 -0
- package/dist/summarizer-zca44nxa.md +18 -0
- package/dist/workflow-w1g9szna.yml +151 -0
- package/package.json +82 -4
- package/prompts/consolidate.md +24 -0
- package/prompts/default/PROVENANCE.md +18 -0
- package/prompts/default/deep-review-lifecycle.md +362 -0
- package/prompts/default/deep-review-logic.md +156 -0
- package/prompts/default/deep-review-parity.md +120 -0
- package/prompts/default/deep-review-reliability.md +125 -0
- package/prompts/default/deep-review-resilience.md +118 -0
- package/prompts/default/review-refuter.md +71 -0
- package/prompts/scout.md +140 -0
- package/prompts/summarizer.md +18 -0
- package/skills/crysk/SKILL.md +74 -0
- package/skills/crysk-ci-setup/SKILL.md +134 -0
- package/skills/crysk-ci-setup/assets/admission-config.example.json +9 -0
- package/skills/crysk-ci-setup/assets/workflow.yml +151 -0
- package/skills/crysk-ci-setup/references/ci-admission.md +122 -0
- package/skills/crysk-ci-setup/references/opencode-ci.md +141 -0
- package/skills/crysk-loop/SKILL.md +496 -0
- package/skills/crysk-loop/adjudicator.md +86 -0
- package/skills/crysk-pr/SKILL.md +66 -0
- package/src/agent-env.ts +1084 -0
- package/src/asset-manifest.ts +83 -0
- package/src/assets.d.ts +6 -0
- package/src/assets.ts +183 -0
- package/src/brand-paths.ts +155 -0
- package/src/brand.ts +255 -0
- package/src/ci/admission-ledger.ts +350 -0
- package/src/ci/classify-error.ts +73 -0
- package/src/ci/cli-record.ts +271 -0
- package/src/ci/force-comment.ts +39 -0
- package/src/ci/gates.ts +923 -0
- package/src/ci/outcome.ts +2181 -0
- package/src/ci/override.ts +187 -0
- package/src/ci/publish.ts +1639 -0
- package/src/ci/reporter.ts +626 -0
- package/src/ci/review-admission.ts +901 -0
- package/src/ci/review-levels.ts +310 -0
- package/src/ci/review-policy.ts +18 -0
- package/src/ci/review-risk.ts +184 -0
- package/src/ci/setup.ts +844 -0
- package/src/ci/trigger.ts +1353 -0
- package/src/cli.ts +348 -0
- package/src/commands/activity.ts +67 -0
- package/src/commands/ci-setup-questions.ts +397 -0
- package/src/commands/ci-setup.ts +381 -0
- package/src/commands/config.ts +99 -0
- package/src/commands/doctor.ts +108 -0
- package/src/commands/init.ts +139 -0
- package/src/commands/mcp.ts +10 -0
- package/src/commands/menu.ts +129 -0
- package/src/commands/post.ts +302 -0
- package/src/commands/skills.ts +83 -0
- package/src/commands/status.ts +173 -0
- package/src/commands/triage.ts +342 -0
- package/src/commands/uninstall.ts +37 -0
- package/src/commands/upgrade.ts +214 -0
- package/src/commands/usage.ts +98 -0
- package/src/compare/compare.ts +28 -0
- package/src/compare/floor-test.ts +471 -0
- package/src/compare/martian-adapter.ts +80 -0
- package/src/config/config.ts +267 -0
- package/src/corpus/corpus.ts +1094 -0
- package/src/corpus/preflight.ts +1789 -0
- package/src/diversity/accounting.ts +90 -0
- package/src/diversity/adjudication.ts +145 -0
- package/src/diversity/admission.ts +60 -0
- package/src/diversity/benchmark.ts +195 -0
- package/src/diversity/clustering.ts +285 -0
- package/src/diversity/errors.ts +7 -0
- package/src/diversity/identity.ts +285 -0
- package/src/diversity/index.ts +11 -0
- package/src/diversity/pipeline-integration.ts +448 -0
- package/src/diversity/projection.ts +57 -0
- package/src/diversity/self-contained.ts +68 -0
- package/src/diversity/target-validation.ts +179 -0
- package/src/doctor-migration.ts +209 -0
- package/src/doctor.ts +723 -0
- package/src/errors.ts +83 -0
- package/src/execution/admission.ts +75 -0
- package/src/execution/atomic-write.ts +35 -0
- package/src/execution/attempt-evidence.ts +415 -0
- package/src/execution/bucket-id.ts +136 -0
- package/src/execution/concurrency-limiter.ts +175 -0
- package/src/execution/contracts.ts +443 -0
- package/src/execution/failure-classification.ts +42 -0
- package/src/execution/failure-policy.ts +240 -0
- package/src/execution/harness.ts +2548 -0
- package/src/execution/settlement.ts +348 -0
- package/src/execution/spawned-process.ts +66 -0
- package/src/execution/spend-limiter.ts +424 -0
- package/src/execution/step-artifacts.ts +55 -0
- package/src/execution/usage-normalized.ts +469 -0
- package/src/git/git.ts +396 -0
- package/src/git/identity.ts +64 -0
- package/src/git/refs.ts +140 -0
- package/src/home-preflight.ts +443 -0
- package/src/home.ts +243 -0
- package/src/ignore-file.ts +336 -0
- package/src/ignore-read.ts +118 -0
- package/src/index.ts +34 -0
- package/src/legacy-launchd.ts +29 -0
- package/src/mcp/mcp.ts +150 -0
- package/src/mcp/preflight.ts +407 -0
- package/src/menu-context.ts +192 -0
- package/src/model/catalog.ts +251 -0
- package/src/model/exec-snapshots.ts +390 -0
- package/src/model/free-discovery.ts +302 -0
- package/src/model/provider-capabilities.ts +814 -0
- package/src/model/routing.ts +600 -0
- package/src/pr/admission.ts +847 -0
- package/src/pr/ci-admission-gate.ts +665 -0
- package/src/pr/ci-publish.ts +76 -0
- package/src/pr/discovery.ts +432 -0
- package/src/pr/inline.ts +507 -0
- package/src/pr/plan.ts +366 -0
- package/src/pr/posting.ts +115 -0
- package/src/pr/pr-status.ts +787 -0
- package/src/pr/pr.ts +3642 -0
- package/src/pr/preflight.ts +1031 -0
- package/src/pr/publish-outcome.ts +361 -0
- package/src/pr/range.ts +119 -0
- package/src/pr/reverts-preflight.ts +606 -0
- package/src/pr/reverts.ts +377 -0
- package/src/pr/review-pr.ts +927 -0
- package/src/pr/status.ts +154 -0
- package/src/pr/target.ts +388 -0
- package/src/pr/teardown.ts +437 -0
- package/src/pr/worktree-setup.ts +60 -0
- package/src/production-runtime.ts +1877 -0
- package/src/progress.ts +487 -0
- package/src/rereview/adjudicate.ts +89 -0
- package/src/rereview/classify.ts +362 -0
- package/src/rereview/identity.ts +211 -0
- package/src/rereview/plan.ts +308 -0
- package/src/rereview/prepare.ts +1025 -0
- package/src/rereview/state.ts +767 -0
- package/src/rereview/verify.ts +241 -0
- package/src/review/boundary.ts +105 -0
- package/src/review/consolidate.ts +246 -0
- package/src/review/dedupe.ts +368 -0
- package/src/review/drafts.ts +448 -0
- package/src/review/findings-conformance.ts +120 -0
- package/src/review/findings.ts +714 -0
- package/src/review/pipeline.ts +3977 -0
- package/src/review/preflight.ts +3575 -0
- package/src/review/prompt-set.ts +177 -0
- package/src/review/proof-refs.ts +187 -0
- package/src/review/report.ts +1821 -0
- package/src/review/review.ts +490 -0
- package/src/review/root-cause.ts +120 -0
- package/src/review/route-preflight.ts +289 -0
- package/src/review/run.ts +601 -0
- package/src/review/scout.ts +323 -0
- package/src/review/size-gate.ts +595 -0
- package/src/review/spec.ts +235 -0
- package/src/review/step-runner.ts +233 -0
- package/src/runner-authority.ts +596 -0
- package/src/security/binding-policy.ts +115 -0
- package/src/security/credential-broker.ts +773 -0
- package/src/security/evidence-redaction.ts +62 -0
- package/src/security/execution-authority.ts +27 -0
- package/src/security/redact.ts +71 -0
- package/src/security/workspace-read-broker.ts +466 -0
- package/src/server/client.ts +190 -0
- package/src/server/preflight.ts +217 -0
- package/src/server/server.ts +327 -0
- package/src/signal-handler.ts +50 -0
- package/src/store/activity.ts +413 -0
- package/src/store/backfill-preflight.ts +49 -0
- package/src/store/backfill.ts +141 -0
- package/src/store/gc-preflight.ts +206 -0
- package/src/store/gc.ts +424 -0
- package/src/store/metrics-preflight.ts +229 -0
- package/src/store/metrics.ts +236 -0
- package/src/store/preflight.ts +748 -0
- package/src/store/store.ts +693 -0
- package/src/system-tools.ts +355 -0
- package/src/transport-registry.ts +1124 -0
- package/src/transports/claude-code-cli.ts +1348 -0
- package/src/transports/opencode-admission.ts +515 -0
- package/src/transports/opencode-client.ts +3328 -0
- package/src/transports/opencode-evidence.ts +557 -0
- package/src/transports/opencode-mcp.ts +248 -0
- package/src/transports/opencode-sdk.ts +2294 -0
- package/src/transports/opencode-server.ts +535 -0
- package/src/triage/adjudication.ts +113 -0
- package/src/triage/reply.ts +125 -0
- package/src/triage/triage.ts +255 -0
- package/src/ui/activity.ts +173 -0
- package/src/ui/config-edit.ts +816 -0
- package/src/ui/config.ts +462 -0
- package/src/ui/menu.ts +1325 -0
- package/src/ui/plan.ts +1039 -0
- package/src/ui/primitives.ts +300 -0
- package/src/ui/progress.ts +298 -0
- package/src/ui/result.ts +552 -0
- package/src/ui/review-menu.ts +312 -0
- package/src/ui/select.ts +528 -0
- package/src/ui/tree.ts +178 -0
- package/src/uninstaller.ts +479 -0
- package/src/updater.ts +836 -0
- package/src/usage.ts +77 -0
- package/src/watch/preflight.ts +1389 -0
- package/src/watch/watch.ts +1235 -0
- package/src/wizard.ts +877 -0
|
@@ -0,0 +1,407 @@
|
|
|
1
|
+
// Read-only MCP server (Fundamentals #6 / observability-canonical-store.md),
|
|
2
|
+
// pure half: tool definitions, request schemas, dispatch routing, and JSON-RPC
|
|
3
|
+
// serialization contracts.
|
|
4
|
+
//
|
|
5
|
+
// 100% pure and offline-testable: no network, no stdio handles, no filesystem.
|
|
6
|
+
|
|
7
|
+
import type { Tier } from "#review/findings";
|
|
8
|
+
import type { ProductStoreClient } from "#server/client";
|
|
9
|
+
import { currentMcpToolName } from "../brand";
|
|
10
|
+
|
|
11
|
+
export const MCP_PROTOCOL_VERSION = "2024-11-05";
|
|
12
|
+
const MCP_SERVER_NAME = "crysk-store";
|
|
13
|
+
export const MCP_SERVER_VERSION = "1.0.0";
|
|
14
|
+
|
|
15
|
+
export interface McpToolDefinition {
|
|
16
|
+
name: string;
|
|
17
|
+
description: string;
|
|
18
|
+
inputSchema: {
|
|
19
|
+
type: "object";
|
|
20
|
+
properties: Record<string, unknown>;
|
|
21
|
+
required?: string[];
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const MCP_TOOLS: McpToolDefinition[] = [
|
|
26
|
+
{
|
|
27
|
+
name: "crysk_health",
|
|
28
|
+
description:
|
|
29
|
+
"Check the health, schema version, and run count of the Crysk canonical product store.",
|
|
30
|
+
inputSchema: {
|
|
31
|
+
type: "object",
|
|
32
|
+
properties: {},
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
name: "crysk_list_runs",
|
|
37
|
+
description:
|
|
38
|
+
"List review runs from the canonical store, optionally filtered by repository ID, PR number, and limit.",
|
|
39
|
+
inputSchema: {
|
|
40
|
+
type: "object",
|
|
41
|
+
properties: {
|
|
42
|
+
repo_id: {
|
|
43
|
+
type: "string",
|
|
44
|
+
description: "Repository identifier (e.g. github.com/owner/repo)",
|
|
45
|
+
},
|
|
46
|
+
pr: {
|
|
47
|
+
type: "number",
|
|
48
|
+
description: "Pull request number",
|
|
49
|
+
},
|
|
50
|
+
limit: {
|
|
51
|
+
type: "number",
|
|
52
|
+
description: "Maximum number of runs to return (default: 50)",
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
name: "crysk_get_run",
|
|
59
|
+
description:
|
|
60
|
+
"Retrieve full telemetry, timing, summary score, and cost breakdown of a single review run.",
|
|
61
|
+
inputSchema: {
|
|
62
|
+
type: "object",
|
|
63
|
+
properties: {
|
|
64
|
+
run_id: {
|
|
65
|
+
type: "number",
|
|
66
|
+
description: "Canonical run ID",
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
required: ["run_id"],
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
name: "crysk_get_findings",
|
|
74
|
+
description:
|
|
75
|
+
"Retrieve the complete FindingsDocument of a run, including all findings, hop trails, and proof refs.",
|
|
76
|
+
inputSchema: {
|
|
77
|
+
type: "object",
|
|
78
|
+
properties: {
|
|
79
|
+
run_id: {
|
|
80
|
+
type: "number",
|
|
81
|
+
description: "Canonical run ID",
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
required: ["run_id"],
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
name: "crysk_search_findings",
|
|
89
|
+
description:
|
|
90
|
+
"Search findings across historical runs by file path, tier (blocking/advisory), repository, or specific run ID.",
|
|
91
|
+
inputSchema: {
|
|
92
|
+
type: "object",
|
|
93
|
+
properties: {
|
|
94
|
+
repo_id: {
|
|
95
|
+
type: "string",
|
|
96
|
+
description: "Repository identifier",
|
|
97
|
+
},
|
|
98
|
+
run_id: {
|
|
99
|
+
type: "number",
|
|
100
|
+
description: "Canonical run ID to filter findings within",
|
|
101
|
+
},
|
|
102
|
+
path: {
|
|
103
|
+
type: "string",
|
|
104
|
+
description: "Relative file path",
|
|
105
|
+
},
|
|
106
|
+
tier: {
|
|
107
|
+
type: "string",
|
|
108
|
+
enum: ["blocking", "advisory"],
|
|
109
|
+
description: "Tier filter",
|
|
110
|
+
},
|
|
111
|
+
limit: {
|
|
112
|
+
type: "number",
|
|
113
|
+
description: "Maximum number of findings to return",
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
name: "crysk_get_usage",
|
|
120
|
+
description:
|
|
121
|
+
"Retrieve aggregated token usage, cost breakdown, and run counts (global or scoped to a repository).",
|
|
122
|
+
inputSchema: {
|
|
123
|
+
type: "object",
|
|
124
|
+
properties: {
|
|
125
|
+
repo_id: {
|
|
126
|
+
type: "string",
|
|
127
|
+
description:
|
|
128
|
+
"Repository identifier (optional; omit for global usage)",
|
|
129
|
+
},
|
|
130
|
+
all: {
|
|
131
|
+
type: "boolean",
|
|
132
|
+
description: "Include all repos (default: true if repo_id omitted)",
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
name: "crysk_get_triage",
|
|
139
|
+
description:
|
|
140
|
+
"Retrieve recorded triage decisions (applied, dismissed, deferred, misclassified) for a review run.",
|
|
141
|
+
inputSchema: {
|
|
142
|
+
type: "object",
|
|
143
|
+
properties: {
|
|
144
|
+
run_id: {
|
|
145
|
+
type: "number",
|
|
146
|
+
description: "Canonical run ID",
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
required: ["run_id"],
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
];
|
|
153
|
+
|
|
154
|
+
export interface JsonRpcRequest {
|
|
155
|
+
jsonrpc: "2.0";
|
|
156
|
+
id?: number | string | null;
|
|
157
|
+
method: string;
|
|
158
|
+
params?: Record<string, unknown>;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export interface JsonRpcSuccessResponse {
|
|
162
|
+
jsonrpc: "2.0";
|
|
163
|
+
id: number | string | null;
|
|
164
|
+
result: unknown;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export interface JsonRpcErrorResponse {
|
|
168
|
+
jsonrpc: "2.0";
|
|
169
|
+
id: number | string | null;
|
|
170
|
+
error: {
|
|
171
|
+
code: number;
|
|
172
|
+
message: string;
|
|
173
|
+
data?: unknown;
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export type JsonRpcResponse = JsonRpcSuccessResponse | JsonRpcErrorResponse;
|
|
178
|
+
|
|
179
|
+
export interface ToolCallResult {
|
|
180
|
+
content: Array<{ type: "text"; text: string }>;
|
|
181
|
+
isError?: boolean;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export function formatToolSuccess(data: unknown): ToolCallResult {
|
|
185
|
+
return {
|
|
186
|
+
content: [
|
|
187
|
+
{
|
|
188
|
+
type: "text",
|
|
189
|
+
text: JSON.stringify(data, null, 2),
|
|
190
|
+
},
|
|
191
|
+
],
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export function formatToolError(message: string): ToolCallResult {
|
|
196
|
+
return {
|
|
197
|
+
content: [
|
|
198
|
+
{
|
|
199
|
+
type: "text",
|
|
200
|
+
text: message,
|
|
201
|
+
},
|
|
202
|
+
],
|
|
203
|
+
isError: true,
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export function parseOptionalInteger(
|
|
208
|
+
val: unknown,
|
|
209
|
+
paramName?: string,
|
|
210
|
+
min = 0,
|
|
211
|
+
): number | undefined {
|
|
212
|
+
if (val === undefined || val === null || val === "") return undefined;
|
|
213
|
+
const n = typeof val === "number" ? val : Number(val);
|
|
214
|
+
if (!Number.isInteger(n) || Number.isNaN(n) || n < min) {
|
|
215
|
+
throw new Error(
|
|
216
|
+
`Invalid ${paramName ?? "parameter"}: must be ${min === 1 ? "a positive integer" : `an integer >= ${min}`}`,
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
return n;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export function parseRequiredInteger(val: unknown, paramName: string): number {
|
|
223
|
+
if (val === undefined || val === null || val === "") {
|
|
224
|
+
throw new Error(`Missing required parameter: ${paramName}`);
|
|
225
|
+
}
|
|
226
|
+
const n = typeof val === "number" ? val : Number(val);
|
|
227
|
+
if (!Number.isInteger(n) || Number.isNaN(n) || n < 1) {
|
|
228
|
+
throw new Error(`Invalid ${paramName}: must be a positive integer`);
|
|
229
|
+
}
|
|
230
|
+
return n;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
export async function handleMcpToolCall(
|
|
234
|
+
client: ProductStoreClient,
|
|
235
|
+
name: string,
|
|
236
|
+
args: Record<string, unknown> = {},
|
|
237
|
+
): Promise<ToolCallResult> {
|
|
238
|
+
try {
|
|
239
|
+
// A pre-rename name reaches the same handler; the default branch still
|
|
240
|
+
// reports the name the caller sent.
|
|
241
|
+
switch (currentMcpToolName(name)) {
|
|
242
|
+
case "crysk_health": {
|
|
243
|
+
const health = await client.health();
|
|
244
|
+
return formatToolSuccess(health);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
case "crysk_list_runs": {
|
|
248
|
+
const repo_id =
|
|
249
|
+
typeof args.repo_id === "string" && args.repo_id.trim() !== ""
|
|
250
|
+
? args.repo_id.trim()
|
|
251
|
+
: undefined;
|
|
252
|
+
const pr = parseOptionalInteger(args.pr, "pr", 0);
|
|
253
|
+
const limit = parseOptionalInteger(args.limit, "limit", 1);
|
|
254
|
+
const runs = await client.listRuns({ repo_id, pr, limit });
|
|
255
|
+
return formatToolSuccess(runs);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
case "crysk_get_run": {
|
|
259
|
+
const run_id = parseRequiredInteger(args.run_id, "run_id");
|
|
260
|
+
const run = await client.getRun(run_id);
|
|
261
|
+
if (!run) {
|
|
262
|
+
return formatToolError(`Run #${run_id} not found`);
|
|
263
|
+
}
|
|
264
|
+
return formatToolSuccess(run);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
case "crysk_get_findings": {
|
|
268
|
+
const run_id = parseRequiredInteger(args.run_id, "run_id");
|
|
269
|
+
const doc = await client.getFindingsDocument(run_id);
|
|
270
|
+
if (!doc) {
|
|
271
|
+
return formatToolError(
|
|
272
|
+
`Findings document for run #${run_id} not found`,
|
|
273
|
+
);
|
|
274
|
+
}
|
|
275
|
+
return formatToolSuccess(doc);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
case "crysk_search_findings": {
|
|
279
|
+
const repo_id =
|
|
280
|
+
typeof args.repo_id === "string" && args.repo_id.trim() !== ""
|
|
281
|
+
? args.repo_id.trim()
|
|
282
|
+
: undefined;
|
|
283
|
+
const run_id = parseOptionalInteger(args.run_id, "run_id", 1);
|
|
284
|
+
const path =
|
|
285
|
+
typeof args.path === "string" && args.path.trim() !== ""
|
|
286
|
+
? args.path.trim()
|
|
287
|
+
: undefined;
|
|
288
|
+
const tier =
|
|
289
|
+
typeof args.tier === "string" &&
|
|
290
|
+
(args.tier === "blocking" || args.tier === "advisory")
|
|
291
|
+
? (args.tier as Tier)
|
|
292
|
+
: undefined;
|
|
293
|
+
const limit = parseOptionalInteger(args.limit, "limit", 1);
|
|
294
|
+
const findings = await client.searchFindings({
|
|
295
|
+
repo_id,
|
|
296
|
+
run_id,
|
|
297
|
+
path,
|
|
298
|
+
tier,
|
|
299
|
+
limit,
|
|
300
|
+
});
|
|
301
|
+
return formatToolSuccess(findings);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
case "crysk_get_usage": {
|
|
305
|
+
const repo_id =
|
|
306
|
+
typeof args.repo_id === "string" && args.repo_id.trim() !== ""
|
|
307
|
+
? args.repo_id.trim()
|
|
308
|
+
: undefined;
|
|
309
|
+
const all =
|
|
310
|
+
typeof args.all === "boolean" ? args.all : repo_id === undefined;
|
|
311
|
+
const usage = await client.getUsage({ repo_id, all });
|
|
312
|
+
return formatToolSuccess(usage);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
case "crysk_get_triage": {
|
|
316
|
+
const run_id = parseRequiredInteger(args.run_id, "run_id");
|
|
317
|
+
const triage = await client.getTriage(run_id);
|
|
318
|
+
return formatToolSuccess(triage);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
default:
|
|
322
|
+
return formatToolError(`Unknown tool: ${name}`);
|
|
323
|
+
}
|
|
324
|
+
} catch (err) {
|
|
325
|
+
return formatToolError(`Tool execution failed: ${(err as Error).message}`);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
export async function processMcpMessage(
|
|
330
|
+
client: ProductStoreClient,
|
|
331
|
+
request: JsonRpcRequest,
|
|
332
|
+
): Promise<JsonRpcResponse | null> {
|
|
333
|
+
// JSON-RPC 2.0 §4.1: If the request is a notification, the server MUST NOT reply
|
|
334
|
+
if (request.id === undefined || request.id === null) {
|
|
335
|
+
return null;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
const id = request.id;
|
|
339
|
+
const { method, params } = request;
|
|
340
|
+
|
|
341
|
+
switch (method) {
|
|
342
|
+
case "initialize": {
|
|
343
|
+
return {
|
|
344
|
+
jsonrpc: "2.0",
|
|
345
|
+
id,
|
|
346
|
+
result: {
|
|
347
|
+
protocolVersion: MCP_PROTOCOL_VERSION,
|
|
348
|
+
capabilities: {
|
|
349
|
+
tools: {},
|
|
350
|
+
},
|
|
351
|
+
serverInfo: {
|
|
352
|
+
name: MCP_SERVER_NAME,
|
|
353
|
+
version: MCP_SERVER_VERSION,
|
|
354
|
+
},
|
|
355
|
+
},
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
case "notifications/initialized": {
|
|
360
|
+
return null;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
case "ping": {
|
|
364
|
+
return {
|
|
365
|
+
jsonrpc: "2.0",
|
|
366
|
+
id,
|
|
367
|
+
result: {},
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
case "tools/list": {
|
|
372
|
+
return {
|
|
373
|
+
jsonrpc: "2.0",
|
|
374
|
+
id,
|
|
375
|
+
result: {
|
|
376
|
+
tools: MCP_TOOLS,
|
|
377
|
+
},
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
case "tools/call": {
|
|
382
|
+
const toolName = typeof params?.name === "string" ? params.name : "";
|
|
383
|
+
const toolArgs =
|
|
384
|
+
typeof params?.arguments === "object" && params.arguments !== null
|
|
385
|
+
? (params.arguments as Record<string, unknown>)
|
|
386
|
+
: {};
|
|
387
|
+
|
|
388
|
+
const toolResult = await handleMcpToolCall(client, toolName, toolArgs);
|
|
389
|
+
return {
|
|
390
|
+
jsonrpc: "2.0",
|
|
391
|
+
id,
|
|
392
|
+
result: toolResult,
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
default: {
|
|
397
|
+
return {
|
|
398
|
+
jsonrpc: "2.0",
|
|
399
|
+
id,
|
|
400
|
+
error: {
|
|
401
|
+
code: -32601,
|
|
402
|
+
message: `Method not found: ${method}`,
|
|
403
|
+
},
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { resolveRepoDir } from "./brand-paths";
|
|
4
|
+
|
|
5
|
+
export type RepoContext =
|
|
6
|
+
| { kind: "not-a-repo"; cwd: string }
|
|
7
|
+
| { kind: "unconfigured-repo"; root: string; name: string }
|
|
8
|
+
| {
|
|
9
|
+
kind: "configured-repo";
|
|
10
|
+
root: string;
|
|
11
|
+
name: string;
|
|
12
|
+
defaultBase?: string;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export interface MenuStatusInfo {
|
|
16
|
+
activeReviewsCount?: number;
|
|
17
|
+
upgradeAvailable?: boolean;
|
|
18
|
+
watcherStatus?: "running" | "stopped" | "uninstalled";
|
|
19
|
+
doctorStatus?: "healthy" | "degraded" | "blocking";
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type MenuAction =
|
|
23
|
+
| "review"
|
|
24
|
+
| "init"
|
|
25
|
+
| "activity"
|
|
26
|
+
| "watcher"
|
|
27
|
+
| "config"
|
|
28
|
+
| "doctor"
|
|
29
|
+
| "lifecycle"
|
|
30
|
+
| "quit";
|
|
31
|
+
|
|
32
|
+
export interface MenuItem {
|
|
33
|
+
id: MenuAction;
|
|
34
|
+
label: string;
|
|
35
|
+
desc: string;
|
|
36
|
+
cliHint: string;
|
|
37
|
+
badge?: string;
|
|
38
|
+
isSubmenu?: boolean;
|
|
39
|
+
action: MenuAction;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface ResolveMenuContextDeps {
|
|
43
|
+
resolveRoot?: (dir: string) => Promise<string | null>;
|
|
44
|
+
exists?: (p: string) => boolean;
|
|
45
|
+
readConfig?: (p: string) => Record<string, unknown>;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async function findGitRoot(dir: string): Promise<string | null> {
|
|
49
|
+
try {
|
|
50
|
+
const proc = Bun.spawn(["git", "-C", dir, "rev-parse", "--show-toplevel"], {
|
|
51
|
+
stdout: "pipe",
|
|
52
|
+
stderr: "pipe",
|
|
53
|
+
});
|
|
54
|
+
const exitCode = await proc.exited;
|
|
55
|
+
if (exitCode !== 0) return null;
|
|
56
|
+
const stdout = await new Response(proc.stdout).text();
|
|
57
|
+
const root = stdout.trim();
|
|
58
|
+
return root.length > 0 ? root : null;
|
|
59
|
+
} catch {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export async function resolveMenuContext(
|
|
65
|
+
cwd: string = process.cwd(),
|
|
66
|
+
deps: ResolveMenuContextDeps = {},
|
|
67
|
+
): Promise<RepoContext> {
|
|
68
|
+
const resolveRoot = deps.resolveRoot ?? findGitRoot;
|
|
69
|
+
const exists = deps.exists ?? existsSync;
|
|
70
|
+
const readConfig =
|
|
71
|
+
deps.readConfig ??
|
|
72
|
+
((p) => {
|
|
73
|
+
try {
|
|
74
|
+
return JSON.parse(readFileSync(p, "utf-8"));
|
|
75
|
+
} catch {
|
|
76
|
+
return {};
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
const root = await resolveRoot(cwd);
|
|
81
|
+
if (!root) {
|
|
82
|
+
return { kind: "not-a-repo", cwd };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const name = path.basename(root) || "repository";
|
|
86
|
+
const configPath = path.join(resolveRepoDir(root), "config.json");
|
|
87
|
+
|
|
88
|
+
if (!exists(configPath)) {
|
|
89
|
+
return { kind: "unconfigured-repo", root, name };
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const config = readConfig(configPath);
|
|
93
|
+
const defaultBase =
|
|
94
|
+
typeof config.default_base === "string" ? config.default_base : undefined;
|
|
95
|
+
|
|
96
|
+
return {
|
|
97
|
+
kind: "configured-repo",
|
|
98
|
+
root,
|
|
99
|
+
name,
|
|
100
|
+
defaultBase,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function getMenuOptions(
|
|
105
|
+
context: RepoContext,
|
|
106
|
+
status: MenuStatusInfo = {},
|
|
107
|
+
): MenuItem[] {
|
|
108
|
+
const items: MenuItem[] = [];
|
|
109
|
+
|
|
110
|
+
if (context.kind === "configured-repo") {
|
|
111
|
+
items.push({
|
|
112
|
+
id: "review",
|
|
113
|
+
label: "Review PR",
|
|
114
|
+
desc: "Run multi-agent review on branch or PR",
|
|
115
|
+
cliHint: "review",
|
|
116
|
+
isSubmenu: true,
|
|
117
|
+
action: "review",
|
|
118
|
+
});
|
|
119
|
+
} else if (context.kind === "unconfigured-repo") {
|
|
120
|
+
items.push({
|
|
121
|
+
id: "init",
|
|
122
|
+
label: "Initialize repo",
|
|
123
|
+
desc: "Scaffold <repo>/.crysk/ config & gotchas",
|
|
124
|
+
cliHint: "init",
|
|
125
|
+
action: "init",
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// Activity is present in all contexts
|
|
130
|
+
const activeBadge =
|
|
131
|
+
(status.activeReviewsCount ?? 0) > 0
|
|
132
|
+
? `${status.activeReviewsCount} running`
|
|
133
|
+
: undefined;
|
|
134
|
+
|
|
135
|
+
items.push({
|
|
136
|
+
id: "activity",
|
|
137
|
+
label: "Activity & runs",
|
|
138
|
+
desc: "View active reviews and completed history",
|
|
139
|
+
cliHint: "activity",
|
|
140
|
+
badge: activeBadge,
|
|
141
|
+
action: "activity",
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
items.push({
|
|
145
|
+
id: "watcher",
|
|
146
|
+
label: "Watcher daemon",
|
|
147
|
+
desc: "Background branch and PR monitoring daemon",
|
|
148
|
+
cliHint: "watch",
|
|
149
|
+
isSubmenu: true,
|
|
150
|
+
action: "watcher",
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
items.push({
|
|
154
|
+
id: "config",
|
|
155
|
+
label: "Configuration",
|
|
156
|
+
desc: "Inspect or edit global and repo settings",
|
|
157
|
+
cliHint: "config",
|
|
158
|
+
isSubmenu: true,
|
|
159
|
+
action: "config",
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
items.push({
|
|
163
|
+
id: "doctor",
|
|
164
|
+
label: "Doctor diagnostics",
|
|
165
|
+
desc: "Check system tools, auth & environment readiness",
|
|
166
|
+
cliHint: "doctor",
|
|
167
|
+
action: "doctor",
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
const lifecycleBadge = status.upgradeAvailable
|
|
171
|
+
? "update available"
|
|
172
|
+
: undefined;
|
|
173
|
+
items.push({
|
|
174
|
+
id: "lifecycle",
|
|
175
|
+
label: "Lifecycle & updates",
|
|
176
|
+
desc: "Upgrade, sync skills & managed uninstall",
|
|
177
|
+
cliHint: "upgrade",
|
|
178
|
+
badge: lifecycleBadge,
|
|
179
|
+
isSubmenu: true,
|
|
180
|
+
action: "lifecycle",
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
items.push({
|
|
184
|
+
id: "quit",
|
|
185
|
+
label: "Quit",
|
|
186
|
+
desc: "Exit crysk TUI",
|
|
187
|
+
cliHint: "exit",
|
|
188
|
+
action: "quit",
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
return items;
|
|
192
|
+
}
|