crysk 0.0.0 → 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 +609 -3
- 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 +81 -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,173 @@
|
|
|
1
|
+
// `pr-hero status --pr <n> [--json]` (ROADMAP S9): the read-only gate, findings and next
|
|
2
|
+
// action of one PR, for the triage skill to drive review -> reply -> fix -> wait. The
|
|
3
|
+
// decisions live in pr/pr-status.ts (pure); this file is the I/O shell: the PR's head, the
|
|
4
|
+
// gate, and both comment streams, all through gh. Nothing is written to GitHub, and no run
|
|
5
|
+
// dir or local store is read.
|
|
6
|
+
//
|
|
7
|
+
// Fail closed: every read here throws on failure (a gh error, a truncated comment list, a
|
|
8
|
+
// head that is not a commit id), so the command exits 1 with nothing on stdout. An empty
|
|
9
|
+
// answer from a failed read would read as "no review yet" and send a review out blind.
|
|
10
|
+
|
|
11
|
+
import { resolveRepoRoot } from "#git/git";
|
|
12
|
+
import {
|
|
13
|
+
CommentsTruncatedError,
|
|
14
|
+
fetchCommitStatuses,
|
|
15
|
+
fetchPrComments,
|
|
16
|
+
fetchPrReviewComments,
|
|
17
|
+
ghPrView,
|
|
18
|
+
POSTING_GH_TIMEOUT_MS,
|
|
19
|
+
} from "#pr/pr";
|
|
20
|
+
import {
|
|
21
|
+
buildPrStatus,
|
|
22
|
+
type PrStatusJson,
|
|
23
|
+
renderPrStatusLines,
|
|
24
|
+
STATUS_WAIT_MAX_MS,
|
|
25
|
+
STATUS_WAIT_POLL_INTERVAL_MS,
|
|
26
|
+
shouldWaitPrStatus,
|
|
27
|
+
} from "#pr/pr-status";
|
|
28
|
+
import { resolvePrTarget } from "#pr/preflight";
|
|
29
|
+
import type { CliOptions } from "#review/preflight";
|
|
30
|
+
import { GH_PR_VIEW_TIMEOUT_MS } from "#store/gc-preflight";
|
|
31
|
+
import { log } from "#ui/primitives";
|
|
32
|
+
import { CliError, CliUsageError } from "../errors";
|
|
33
|
+
|
|
34
|
+
export async function statusCommand(options: CliOptions): Promise<number> {
|
|
35
|
+
// parseArgs already requires a numeric --pr for this command; the check is the type
|
|
36
|
+
// narrowing, and it runs before any repository lookup or read.
|
|
37
|
+
if (typeof options.pr !== "number") {
|
|
38
|
+
throw new CliUsageError("status requires --pr <n> (a PR number)");
|
|
39
|
+
}
|
|
40
|
+
const operatorRoot = await resolveRepoRoot(options.repo);
|
|
41
|
+
return runStatusCommand({
|
|
42
|
+
operatorRoot,
|
|
43
|
+
pr: options.pr,
|
|
44
|
+
json: options.json === true,
|
|
45
|
+
wait: options.wait === true,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Exported with its gh seam (spawnFn), the clock (nowMs) and the stdout writer (out) injectable,
|
|
50
|
+
// so the tests observe exactly what the command reads and what it prints. Without --json the
|
|
51
|
+
// lines go to stderr through log(), and stdout stays empty; with --json stdout carries exactly
|
|
52
|
+
// one JSON object.
|
|
53
|
+
export async function runStatusCommand(input: {
|
|
54
|
+
operatorRoot: string;
|
|
55
|
+
pr: number;
|
|
56
|
+
json: boolean;
|
|
57
|
+
wait?: boolean;
|
|
58
|
+
spawnFn?: typeof Bun.spawn;
|
|
59
|
+
nowMs?: number;
|
|
60
|
+
clock?: () => number;
|
|
61
|
+
sleepFn?: (ms: number) => Promise<void>;
|
|
62
|
+
pollIntervalMs?: number;
|
|
63
|
+
maxWaitMs?: number;
|
|
64
|
+
startupGraceMs?: number;
|
|
65
|
+
// Overrides every bound below. The tests use it to see a timeout without waiting the real one.
|
|
66
|
+
ghTimeoutMs?: number;
|
|
67
|
+
out?: (text: string) => void;
|
|
68
|
+
}): Promise<number> {
|
|
69
|
+
const { operatorRoot, pr, spawnFn } = input;
|
|
70
|
+
// Every gh call here is bounded, so a call that never answers is a timeout CliError and the
|
|
71
|
+
// command exits 1 with nothing on stdout, instead of parking the skill's only gate read. The
|
|
72
|
+
// PR view takes the bound the other PR-view reads take (GH_PR_VIEW_TIMEOUT_MS); the comment
|
|
73
|
+
// reads take the one the posting path's comment lookups take (POSTING_GH_TIMEOUT_MS). The
|
|
74
|
+
// commit statuses carry their own bound (COMMIT_STATUS_TIMEOUT_MS) inside fetchCommitStatuses.
|
|
75
|
+
const viewTimeoutMs = input.ghTimeoutMs ?? GH_PR_VIEW_TIMEOUT_MS;
|
|
76
|
+
const commentTimeoutMs = input.ghTimeoutMs ?? POSTING_GH_TIMEOUT_MS;
|
|
77
|
+
const pollIntervalMs = input.pollIntervalMs ?? STATUS_WAIT_POLL_INTERVAL_MS;
|
|
78
|
+
const maxWaitMs = input.maxWaitMs ?? STATUS_WAIT_MAX_MS;
|
|
79
|
+
const sleep =
|
|
80
|
+
input.sleepFn ??
|
|
81
|
+
((ms: number) => new Promise<void>((resolve) => setTimeout(resolve, ms)));
|
|
82
|
+
let sleptMs = 0;
|
|
83
|
+
const baseNowMs = input.nowMs;
|
|
84
|
+
const readNow =
|
|
85
|
+
input.clock ??
|
|
86
|
+
(baseNowMs !== undefined ? () => baseNowMs + sleptMs : () => Date.now());
|
|
87
|
+
const startMs = readNow();
|
|
88
|
+
let lastHead: string | undefined;
|
|
89
|
+
let headStartMs = startMs;
|
|
90
|
+
let polls = 0;
|
|
91
|
+
let consecutivePollErrors = 0;
|
|
92
|
+
|
|
93
|
+
let status: PrStatusJson;
|
|
94
|
+
while (true) {
|
|
95
|
+
const nowMs = readNow();
|
|
96
|
+
const elapsedMs = nowMs - startMs;
|
|
97
|
+
polls += 1;
|
|
98
|
+
let issueComments: Awaited<ReturnType<typeof fetchPrComments>>;
|
|
99
|
+
try {
|
|
100
|
+
const target = resolvePrTarget(
|
|
101
|
+
await ghPrView(operatorRoot, pr, { spawnFn, timeoutMs: viewTimeoutMs }),
|
|
102
|
+
);
|
|
103
|
+
const head = target.headSha;
|
|
104
|
+
if (head !== lastHead) {
|
|
105
|
+
lastHead = head;
|
|
106
|
+
headStartMs = nowMs;
|
|
107
|
+
}
|
|
108
|
+
// Sequential on purpose: each read names its own failure, and a failed read stops the rest.
|
|
109
|
+
const statuses = await fetchCommitStatuses(operatorRoot, head, {
|
|
110
|
+
spawnFn,
|
|
111
|
+
failClosed: true,
|
|
112
|
+
});
|
|
113
|
+
issueComments = await fetchPrComments(operatorRoot, pr, {
|
|
114
|
+
spawnFn,
|
|
115
|
+
timeoutMs: commentTimeoutMs,
|
|
116
|
+
});
|
|
117
|
+
const reviewComments = await fetchPrReviewComments(operatorRoot, pr, {
|
|
118
|
+
spawnFn,
|
|
119
|
+
timeoutMs: commentTimeoutMs,
|
|
120
|
+
});
|
|
121
|
+
status = buildPrStatus({
|
|
122
|
+
pr,
|
|
123
|
+
head,
|
|
124
|
+
nowMs,
|
|
125
|
+
statuses,
|
|
126
|
+
issueComments,
|
|
127
|
+
reviewComments,
|
|
128
|
+
});
|
|
129
|
+
consecutivePollErrors = 0;
|
|
130
|
+
} catch (err) {
|
|
131
|
+
const retryable =
|
|
132
|
+
input.wait === true &&
|
|
133
|
+
polls > 1 &&
|
|
134
|
+
err instanceof CliError &&
|
|
135
|
+
!(err instanceof CliUsageError) &&
|
|
136
|
+
!(err instanceof CommentsTruncatedError) &&
|
|
137
|
+
consecutivePollErrors < 2 &&
|
|
138
|
+
elapsedMs + pollIntervalMs <= maxWaitMs;
|
|
139
|
+
if (!retryable) throw err;
|
|
140
|
+
consecutivePollErrors += 1;
|
|
141
|
+
await sleep(pollIntervalMs);
|
|
142
|
+
sleptMs += pollIntervalMs;
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
const headElapsedMs = nowMs - headStartMs;
|
|
146
|
+
if (
|
|
147
|
+
!input.wait ||
|
|
148
|
+
!shouldWaitPrStatus({
|
|
149
|
+
status,
|
|
150
|
+
issueComments,
|
|
151
|
+
nowMs,
|
|
152
|
+
elapsedMs: headElapsedMs,
|
|
153
|
+
startupGraceMs: input.startupGraceMs,
|
|
154
|
+
})
|
|
155
|
+
) {
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
if (elapsedMs + pollIntervalMs > maxWaitMs) {
|
|
159
|
+
throw new CliError(
|
|
160
|
+
`Timed out after ${maxWaitMs} ms waiting for crysk status on PR #${pr} to settle.`,
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
await sleep(pollIntervalMs);
|
|
164
|
+
sleptMs += pollIntervalMs;
|
|
165
|
+
}
|
|
166
|
+
if (input.json) {
|
|
167
|
+
const write = input.out ?? ((text: string) => process.stdout.write(text));
|
|
168
|
+
write(`${JSON.stringify(status)}\n`);
|
|
169
|
+
} else {
|
|
170
|
+
for (const line of renderPrStatusLines(status)) log(line);
|
|
171
|
+
}
|
|
172
|
+
return 0;
|
|
173
|
+
}
|
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { assertRunMatchesPr } from "#ci/gates";
|
|
5
|
+
import { resolveRepoRoot } from "#git/git";
|
|
6
|
+
import {
|
|
7
|
+
fetchPostedFindingComments,
|
|
8
|
+
fetchPrReviewComments,
|
|
9
|
+
ghCurrentBranchPr,
|
|
10
|
+
ghPrWebUrl,
|
|
11
|
+
ghRepoNameWithOwner,
|
|
12
|
+
ghRepoWebUrl,
|
|
13
|
+
postIssueTriageComment,
|
|
14
|
+
postReviewCommentReply,
|
|
15
|
+
resolveReviewThreadForComment,
|
|
16
|
+
} from "#pr/pr";
|
|
17
|
+
import { resolveCurrentPrNumber } from "#pr/preflight";
|
|
18
|
+
import { validateFindingsDocument } from "#review/findings";
|
|
19
|
+
import type { CliOptions } from "#review/preflight";
|
|
20
|
+
import { openProductStore, recordFindingTriage } from "#store/store";
|
|
21
|
+
import {
|
|
22
|
+
decideThreadResolve,
|
|
23
|
+
existingTriageAtHead,
|
|
24
|
+
findingIdentityForMarkerMatch,
|
|
25
|
+
matchPostedFindingExact,
|
|
26
|
+
} from "#triage/reply";
|
|
27
|
+
import {
|
|
28
|
+
renderTriageReplyBody,
|
|
29
|
+
TRIAGE_MARKER_PREFIX,
|
|
30
|
+
type TriageMarkerFields,
|
|
31
|
+
type TriageTag,
|
|
32
|
+
type TriageVerdict,
|
|
33
|
+
} from "#triage/triage";
|
|
34
|
+
import { log } from "#ui/primitives";
|
|
35
|
+
import { matchMarkerPrefix } from "../brand";
|
|
36
|
+
import { CliError, CliUsageError } from "../errors";
|
|
37
|
+
import { tryOriginRepoId } from "../home";
|
|
38
|
+
import { prheroLayout } from "../home-preflight";
|
|
39
|
+
|
|
40
|
+
// `pr-hero triage reply --pr <n> --from <run-dir> --finding <id> ...`: the
|
|
41
|
+
// only triage verb. It posts one triage reply, records the verdict in the
|
|
42
|
+
// product store, and resolves the thread. The bare `triage --pr --from` verb
|
|
43
|
+
// that bound verdicts into comparison.json is retired: new
|
|
44
|
+
// verdicts live only in finding_triage. The shell/pure split is unchanged:
|
|
45
|
+
// triage/triage.ts renders the marker, triage/reply.ts decides the binding,
|
|
46
|
+
// and runTriageReplyCommand does the read/fetch/write. It is exported and
|
|
47
|
+
// spawnFn-injectable for the same CRIT-B reason runPostCommand is
|
|
48
|
+
// (verify-report-pr3 #3305): a dry-run branch that could not be proven
|
|
49
|
+
// gh-free is not a $0 gate.
|
|
50
|
+
export async function triageCommand(options: CliOptions): Promise<number> {
|
|
51
|
+
if (options.triage !== "reply") {
|
|
52
|
+
throw new CliUsageError(
|
|
53
|
+
"triage needs a subcommand: use `crysk triage reply` (the bare " +
|
|
54
|
+
"`triage --pr --from` verb was removed with comparison.json)",
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
const operatorRoot = await resolveRepoRoot(options.repo);
|
|
58
|
+
// parseArgs already enforces both of these for the "triage" command; the
|
|
59
|
+
// checks here are the type-narrowing TypeScript needs, not new validation.
|
|
60
|
+
if (options.pr === undefined) {
|
|
61
|
+
throw new CliUsageError("triage requires --pr <n>");
|
|
62
|
+
}
|
|
63
|
+
if (options.from === undefined) {
|
|
64
|
+
throw new CliUsageError("triage requires --from <run-dir>");
|
|
65
|
+
}
|
|
66
|
+
const prNumber =
|
|
67
|
+
options.pr === "current"
|
|
68
|
+
? resolveCurrentPrNumber(await ghCurrentBranchPr(operatorRoot))
|
|
69
|
+
: options.pr;
|
|
70
|
+
if (options.finding === undefined) {
|
|
71
|
+
throw new CliUsageError("triage reply requires --finding <id>");
|
|
72
|
+
}
|
|
73
|
+
if (options.tag === undefined) {
|
|
74
|
+
throw new CliUsageError("triage reply requires --tag <tag>");
|
|
75
|
+
}
|
|
76
|
+
if (options.bodyFile === undefined) {
|
|
77
|
+
throw new CliUsageError("triage reply requires --body-file <path>");
|
|
78
|
+
}
|
|
79
|
+
return runTriageReplyCommand({
|
|
80
|
+
operatorRoot,
|
|
81
|
+
pr: prNumber,
|
|
82
|
+
from: options.from,
|
|
83
|
+
findingId: options.finding,
|
|
84
|
+
tag: options.tag,
|
|
85
|
+
bodyFile: options.bodyFile,
|
|
86
|
+
verdict: options.verdict,
|
|
87
|
+
issue: options.issue,
|
|
88
|
+
dryRun: options.dryRun,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// The PR's web URL, the base an outside-channel reply's `In reply to:` link is built on. The repo's
|
|
93
|
+
// web URL is the first source, as it always was. When that lookup fails, the PR's own URL is
|
|
94
|
+
// asked for, then the repo's nameWithOwner on the GitHub host. Only when none of them is known is
|
|
95
|
+
// the reply posted without the link. The link is what binds a reply to its finding
|
|
96
|
+
// (pr-status.ts repliesTo), so a missing link is the failure this chain exists to avoid.
|
|
97
|
+
async function outsidePullUrl(
|
|
98
|
+
operatorRoot: string,
|
|
99
|
+
prNumber: number,
|
|
100
|
+
spawnFn: typeof Bun.spawn | undefined,
|
|
101
|
+
): Promise<string | undefined> {
|
|
102
|
+
const repoUrl = await ghRepoWebUrl(operatorRoot, { spawnFn });
|
|
103
|
+
if (repoUrl !== undefined) return `${repoUrl}/pull/${prNumber}`;
|
|
104
|
+
const prUrl = await ghPrWebUrl(operatorRoot, prNumber, { spawnFn });
|
|
105
|
+
if (prUrl !== undefined) return prUrl;
|
|
106
|
+
const nameWithOwner = await ghRepoNameWithOwner(operatorRoot, { spawnFn });
|
|
107
|
+
if (nameWithOwner === undefined) return undefined;
|
|
108
|
+
// `||`, not `??`: an empty GITHUB_SERVER_URL counts as unset here (as in ci/trigger.ts),
|
|
109
|
+
// or the link would have no host.
|
|
110
|
+
const host = process.env.GITHUB_SERVER_URL || "https://github.com";
|
|
111
|
+
return `${host}/${nameWithOwner}/pull/${prNumber}`;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export async function runTriageReplyCommand(input: {
|
|
115
|
+
operatorRoot: string;
|
|
116
|
+
pr: number;
|
|
117
|
+
from: string;
|
|
118
|
+
findingId: string;
|
|
119
|
+
tag: TriageTag;
|
|
120
|
+
bodyFile: string;
|
|
121
|
+
verdict?: TriageVerdict;
|
|
122
|
+
issue?: number;
|
|
123
|
+
dryRun: boolean;
|
|
124
|
+
spawnFn?: typeof Bun.spawn;
|
|
125
|
+
}): Promise<number> {
|
|
126
|
+
const { operatorRoot, pr: prNumber, dryRun, spawnFn } = input;
|
|
127
|
+
const runDir = path.resolve(input.from);
|
|
128
|
+
const findingsPath = path.join(runDir, "findings.json");
|
|
129
|
+
if (!existsSync(findingsPath)) {
|
|
130
|
+
throw new CliUsageError(
|
|
131
|
+
`${runDir} is missing findings.json — point --from at a completed ` +
|
|
132
|
+
'PR-mode run directory ("crysk review --pr <n>" writes it)',
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
const doc = validateFindingsDocument(
|
|
136
|
+
JSON.parse(await Bun.file(findingsPath).text()),
|
|
137
|
+
);
|
|
138
|
+
assertRunMatchesPr(doc, prNumber, runDir);
|
|
139
|
+
const finding = doc.findings.find((row) => row.id === input.findingId);
|
|
140
|
+
if (finding === undefined) {
|
|
141
|
+
throw new CliUsageError(
|
|
142
|
+
`${findingsPath} has no finding ${input.findingId}`,
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
const bodyPath = path.resolve(input.bodyFile);
|
|
146
|
+
if (!existsSync(bodyPath)) {
|
|
147
|
+
throw new CliUsageError(`--body-file not found: ${bodyPath}`);
|
|
148
|
+
}
|
|
149
|
+
const reasoning = await Bun.file(bodyPath).text();
|
|
150
|
+
if (matchMarkerPrefix(reasoning, TRIAGE_MARKER_PREFIX) !== undefined) {
|
|
151
|
+
throw new CliUsageError(
|
|
152
|
+
"--body-file must be reasoning prose only — the driver prepends the " +
|
|
153
|
+
"triage marker and badge (do not start the file with " +
|
|
154
|
+
"`<!-- crysk-triage`)",
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
// anchor.patch first, as in post --from: the diff the finding's line is
|
|
158
|
+
// matched against must be the one inline comments anchor on.
|
|
159
|
+
const anchorPath = path.join(runDir, "anchor.patch");
|
|
160
|
+
const diffPath = existsSync(anchorPath)
|
|
161
|
+
? anchorPath
|
|
162
|
+
: path.join(runDir, "diff.patch");
|
|
163
|
+
if (!existsSync(diffPath)) {
|
|
164
|
+
throw new CliUsageError(
|
|
165
|
+
`${runDir} is missing diff.patch — point --from at a completed ` +
|
|
166
|
+
'PR-mode run directory ("crysk review --pr <n>" writes it)',
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
const diffPatch = await Bun.file(diffPath).text();
|
|
170
|
+
const { identity, findingsLine } = findingIdentityForMarkerMatch({
|
|
171
|
+
path: finding.path,
|
|
172
|
+
line: finding.line,
|
|
173
|
+
claim: finding.claim,
|
|
174
|
+
proof_refs: finding.proof_refs,
|
|
175
|
+
diffPatch,
|
|
176
|
+
});
|
|
177
|
+
const fields: TriageMarkerFields = {
|
|
178
|
+
tag: input.tag,
|
|
179
|
+
headSha: doc.head_sha,
|
|
180
|
+
actor: "agent",
|
|
181
|
+
verdict: input.verdict,
|
|
182
|
+
issue: input.issue,
|
|
183
|
+
};
|
|
184
|
+
const body = renderTriageReplyBody(fields, reasoning);
|
|
185
|
+
const posted = await fetchPostedFindingComments(operatorRoot, prNumber, {
|
|
186
|
+
spawnFn,
|
|
187
|
+
});
|
|
188
|
+
const match = matchPostedFindingExact({
|
|
189
|
+
finding: identity,
|
|
190
|
+
headSha: doc.head_sha,
|
|
191
|
+
posted,
|
|
192
|
+
});
|
|
193
|
+
if (match.kind === "none") {
|
|
194
|
+
const lineHint =
|
|
195
|
+
identity.line === findingsLine
|
|
196
|
+
? `${finding.path}:${identity.line}`
|
|
197
|
+
: `${finding.path}: post line ${identity.line} ` +
|
|
198
|
+
`(findings.json:${findingsLine})`;
|
|
199
|
+
throw new CliError(
|
|
200
|
+
`no posted <!-- crysk-finding (or <!-- pr-hero-finding) marker matches ${input.findingId} ` +
|
|
201
|
+
`on PR #${prNumber} (${lineHint}, head ${doc.head_sha.slice(0, 8)}). ` +
|
|
202
|
+
"Bind by marker, never by a GitHub comment id or the nearest line",
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
if (match.kind === "ambiguous") {
|
|
206
|
+
throw new CliError(
|
|
207
|
+
`multiple posted finding comments match ${input.findingId} ` +
|
|
208
|
+
`(ids ${match.ids.join(", ")}) — will not pick by proximity`,
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
const parent = match.posted;
|
|
212
|
+
const reviewComments = await fetchPrReviewComments(operatorRoot, prNumber, {
|
|
213
|
+
spawnFn,
|
|
214
|
+
});
|
|
215
|
+
const already = existingTriageAtHead({
|
|
216
|
+
parentId: parent.id,
|
|
217
|
+
headSha: doc.head_sha,
|
|
218
|
+
replies: reviewComments,
|
|
219
|
+
});
|
|
220
|
+
const resolveDecision = decideThreadResolve({
|
|
221
|
+
channel: parent.channel,
|
|
222
|
+
verdict: input.verdict,
|
|
223
|
+
});
|
|
224
|
+
if (dryRun) {
|
|
225
|
+
log(
|
|
226
|
+
`plan: reply to ${parent.channel} comment ${parent.id} ` +
|
|
227
|
+
`(${input.findingId}, marker match) as ${input.tag}` +
|
|
228
|
+
(already ? " — already triaged at this head, would skip post" : ""),
|
|
229
|
+
);
|
|
230
|
+
if (resolveDecision === "resolve") {
|
|
231
|
+
log("plan: would resolve the review thread after posting");
|
|
232
|
+
} else if (resolveDecision === "skip-inconclusive") {
|
|
233
|
+
log("plan: would leave the thread open (adjudicator inconclusive)");
|
|
234
|
+
} else {
|
|
235
|
+
log("plan: no review thread to resolve (issue-comment finding)");
|
|
236
|
+
}
|
|
237
|
+
log("dry run: nothing was posted.");
|
|
238
|
+
return 0;
|
|
239
|
+
}
|
|
240
|
+
if (!already) {
|
|
241
|
+
if (parent.channel === "review") {
|
|
242
|
+
await postReviewCommentReply({
|
|
243
|
+
operatorRoot,
|
|
244
|
+
pr: prNumber,
|
|
245
|
+
inReplyTo: parent.id,
|
|
246
|
+
body,
|
|
247
|
+
spawnFn,
|
|
248
|
+
});
|
|
249
|
+
} else {
|
|
250
|
+
const pullUrl = await outsidePullUrl(operatorRoot, prNumber, spawnFn);
|
|
251
|
+
const withLink =
|
|
252
|
+
pullUrl === undefined
|
|
253
|
+
? body
|
|
254
|
+
: `${body.trimEnd()}\n\nIn reply to: ${pullUrl}#issuecomment-${parent.id}\n`;
|
|
255
|
+
await postIssueTriageComment({
|
|
256
|
+
operatorRoot,
|
|
257
|
+
pr: prNumber,
|
|
258
|
+
body: withLink,
|
|
259
|
+
spawnFn,
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
log(
|
|
263
|
+
`posted: ${input.tag} on ${input.findingId} ` +
|
|
264
|
+
`(${parent.channel} comment ${parent.id})`,
|
|
265
|
+
);
|
|
266
|
+
} else {
|
|
267
|
+
log(
|
|
268
|
+
`skip post: ${input.findingId} already triaged at this head ` +
|
|
269
|
+
`(${parent.channel} comment ${parent.id})`,
|
|
270
|
+
);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// Persist triage record to canonical product store (idempotent upsert)
|
|
274
|
+
try {
|
|
275
|
+
const layout = prheroLayout(os.homedir());
|
|
276
|
+
if (existsSync(layout.prheroDbPath)) {
|
|
277
|
+
const repoId = await tryOriginRepoId(operatorRoot);
|
|
278
|
+
if (repoId) {
|
|
279
|
+
const db = openProductStore(layout.prheroDbPath);
|
|
280
|
+
try {
|
|
281
|
+
const runDirBasename = path.basename(runDir);
|
|
282
|
+
const runRow = db
|
|
283
|
+
.query(
|
|
284
|
+
"SELECT id FROM runs WHERE repo_id = ? AND run_dir = ? LIMIT 1",
|
|
285
|
+
)
|
|
286
|
+
.get(repoId, runDirBasename) as { id: number } | null;
|
|
287
|
+
if (runRow) {
|
|
288
|
+
recordFindingTriage(db, {
|
|
289
|
+
run_id: runRow.id,
|
|
290
|
+
finding_id: input.findingId,
|
|
291
|
+
comment_id: parent.id,
|
|
292
|
+
tag: input.tag,
|
|
293
|
+
verdict: input.verdict,
|
|
294
|
+
actor: "agent",
|
|
295
|
+
reasoning,
|
|
296
|
+
issue_number: input.issue,
|
|
297
|
+
created_at: new Date().toISOString(),
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
} finally {
|
|
301
|
+
db.close();
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
} catch (err) {
|
|
306
|
+
log(
|
|
307
|
+
`warning: failed to record triage in product store: ${(err as Error).message}`,
|
|
308
|
+
);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
if (resolveDecision !== "resolve") {
|
|
312
|
+
return 0;
|
|
313
|
+
}
|
|
314
|
+
// Live #34: the reply POST succeeded, then GraphQL resolve threw and the
|
|
315
|
+
// process exited 1. The skill's rule is never `gh` — say the reply is
|
|
316
|
+
// already on GitHub and the same command retries resolve only.
|
|
317
|
+
try {
|
|
318
|
+
const resolveOutcome = await resolveReviewThreadForComment({
|
|
319
|
+
operatorRoot,
|
|
320
|
+
pr: prNumber,
|
|
321
|
+
commentId: parent.id,
|
|
322
|
+
spawnFn,
|
|
323
|
+
});
|
|
324
|
+
if (resolveOutcome === "resolved") {
|
|
325
|
+
log(`resolved: review thread for ${input.findingId}`);
|
|
326
|
+
} else if (resolveOutcome === "already-resolved") {
|
|
327
|
+
log(`resolved: thread already closed for ${input.findingId}`);
|
|
328
|
+
} else {
|
|
329
|
+
log(`resolve skipped: no review thread found for comment ${parent.id}`);
|
|
330
|
+
}
|
|
331
|
+
} catch (error) {
|
|
332
|
+
if (error instanceof CliError) {
|
|
333
|
+
throw new CliError(
|
|
334
|
+
`resolve failed after the reply was on GitHub (${error.message}). ` +
|
|
335
|
+
"Re-run the same `crysk triage reply` command to retry resolve " +
|
|
336
|
+
"only — same-head skip will not double-post.",
|
|
337
|
+
);
|
|
338
|
+
}
|
|
339
|
+
throw error;
|
|
340
|
+
}
|
|
341
|
+
return 0;
|
|
342
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import os from "node:os";
|
|
2
|
+
import { resolveRepoRoot } from "#git/git";
|
|
3
|
+
import type { CliOptions } from "#review/preflight";
|
|
4
|
+
import { log } from "#ui/primitives";
|
|
5
|
+
import { executeUninstallPlan, planUninstallation } from "../uninstaller";
|
|
6
|
+
|
|
7
|
+
export async function uninstallCommand(options: CliOptions): Promise<number> {
|
|
8
|
+
const home = os.homedir();
|
|
9
|
+
const repoRoot = options.repo
|
|
10
|
+
? await resolveRepoRoot(options.repo).catch(() => undefined)
|
|
11
|
+
: await resolveRepoRoot(process.cwd()).catch(() => undefined);
|
|
12
|
+
|
|
13
|
+
const plan = await planUninstallation({
|
|
14
|
+
home,
|
|
15
|
+
purge: options.purge,
|
|
16
|
+
repoRoot,
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
if (options.dryRun) {
|
|
20
|
+
log("Planned uninstallation steps (--dry-run):");
|
|
21
|
+
for (const s of [...plan.programSteps, ...plan.dataSteps]) {
|
|
22
|
+
log(` • ${s.desc}`);
|
|
23
|
+
}
|
|
24
|
+
if (plan.warnings.length > 0) {
|
|
25
|
+
for (const w of plan.warnings) log(`warning: ${w}`);
|
|
26
|
+
}
|
|
27
|
+
return 0;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const res = await executeUninstallPlan(plan);
|
|
31
|
+
if (!res.ok) {
|
|
32
|
+
for (const err of res.errors) log(`warning: ${err}`);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
log("✓ crysk uninstallation complete.");
|
|
36
|
+
return 0;
|
|
37
|
+
}
|