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,76 @@
|
|
|
1
|
+
// PR mode's CI headless publishing (ROADMAP Pillar 3): the step summary +
|
|
2
|
+
// $GITHUB_OUTPUT, built from the SAME findings doc renderResult already
|
|
3
|
+
// printed, so nothing here can disagree with what the terminal (and the PR
|
|
4
|
+
// comments, via the posting stage's outcome) already reported. Relocated out
|
|
5
|
+
// of reviewPr() (src/pr/review-pr.ts): the `shouldPublishCiReview` branch
|
|
6
|
+
// became an early return and identifiers moved onto explicit parameters,
|
|
7
|
+
// control flow otherwise unchanged. The WHY comments below move with the
|
|
8
|
+
// code they explain.
|
|
9
|
+
//
|
|
10
|
+
// The gate is shouldPublishCiReview, never a bare `isCi`: design D6's "a
|
|
11
|
+
// failed session publishes nothing" binds this channel exactly as it binds
|
|
12
|
+
// postInlineIfEligible in posting.ts.
|
|
13
|
+
|
|
14
|
+
import {
|
|
15
|
+
planCiReview,
|
|
16
|
+
shouldPublishCiReview,
|
|
17
|
+
shouldWriteCiOutputs,
|
|
18
|
+
shouldWriteStepSummary,
|
|
19
|
+
} from "#ci/gates";
|
|
20
|
+
import {
|
|
21
|
+
appendCiOutputs,
|
|
22
|
+
appendStepSummary,
|
|
23
|
+
formatWorkflowCommand,
|
|
24
|
+
} from "#ci/reporter";
|
|
25
|
+
import type { CiMode } from "#pr/preflight";
|
|
26
|
+
import type { Finding } from "#review/findings";
|
|
27
|
+
import type { PrCommentDelta } from "#review/report";
|
|
28
|
+
import { log } from "#ui/primitives";
|
|
29
|
+
|
|
30
|
+
export async function publishCiReviewIfEligible(input: {
|
|
31
|
+
isCi: boolean;
|
|
32
|
+
sessionFailed: boolean;
|
|
33
|
+
prNumber: number;
|
|
34
|
+
headSha: string;
|
|
35
|
+
findings: readonly Finding[];
|
|
36
|
+
costUsdEst: number;
|
|
37
|
+
wallMs: number;
|
|
38
|
+
model: string;
|
|
39
|
+
webUrl: string | undefined;
|
|
40
|
+
delta: PrCommentDelta | undefined;
|
|
41
|
+
runDir: string;
|
|
42
|
+
stepSummaryFlag: boolean | undefined;
|
|
43
|
+
// S4: the mode this run resolved (resolveCiMode, reviewPr). It names the
|
|
44
|
+
// step summary's footer, and nothing else in this function reads it.
|
|
45
|
+
ciMode: CiMode;
|
|
46
|
+
}): Promise<void> {
|
|
47
|
+
if (!shouldPublishCiReview(input.isCi, input.sessionFailed)) return;
|
|
48
|
+
|
|
49
|
+
const ciPlan = planCiReview({
|
|
50
|
+
prNumber: input.prNumber,
|
|
51
|
+
headSha: input.headSha,
|
|
52
|
+
findings: input.findings,
|
|
53
|
+
costUsdEst: input.costUsdEst,
|
|
54
|
+
wallMs: input.wallMs,
|
|
55
|
+
model: input.model,
|
|
56
|
+
...(input.webUrl === undefined ? {} : { repoWebUrl: input.webUrl }),
|
|
57
|
+
...(input.delta === undefined ? {} : { delta: input.delta }),
|
|
58
|
+
runDir: input.runDir,
|
|
59
|
+
ciMode: input.ciMode,
|
|
60
|
+
});
|
|
61
|
+
const summaryPath = process.env.GITHUB_STEP_SUMMARY;
|
|
62
|
+
if (shouldWriteStepSummary(input.isCi, input.stepSummaryFlag, summaryPath)) {
|
|
63
|
+
await appendStepSummary(summaryPath as string, ciPlan.summaryMarkdown);
|
|
64
|
+
}
|
|
65
|
+
const outputPath = process.env.GITHUB_OUTPUT;
|
|
66
|
+
if (shouldWriteCiOutputs(input.isCi, outputPath)) {
|
|
67
|
+
await appendCiOutputs(outputPath as string, ciPlan.outputs);
|
|
68
|
+
}
|
|
69
|
+
log(
|
|
70
|
+
formatWorkflowCommand(
|
|
71
|
+
"notice",
|
|
72
|
+
`crysk review complete — ${ciPlan.outputs.findings_count} ` +
|
|
73
|
+
`finding(s) (${ciPlan.outputs.blocking_count} blocking)`,
|
|
74
|
+
),
|
|
75
|
+
);
|
|
76
|
+
}
|
|
@@ -0,0 +1,432 @@
|
|
|
1
|
+
// PR mode's re-review/delta-detection step (ROADMAP D9, rereview-coverage
|
|
2
|
+
// fix): step 5 of reviewPr() — last-reviewed head, the two deltas, Phase B
|
|
3
|
+
// classification, and the size gate over the discovery range. Relocated out
|
|
4
|
+
// of reviewPr() (src/pr/review-pr.ts): identifiers moved onto explicit
|
|
5
|
+
// parameters, control flow and WHY comments unchanged.
|
|
6
|
+
//
|
|
7
|
+
// The three `gh`-backed comment fetches (issueComments/postedFindings/
|
|
8
|
+
// reviewComments) stay a Promise.all in reviewPr() itself, on purpose: they
|
|
9
|
+
// are the one genuine system boundary in this step, and reviewPr() already
|
|
10
|
+
// has no injectable seam for them (same limitation as ci-admission-gate.ts's
|
|
11
|
+
// own fetches). Handing this module the ALREADY-FETCHED arrays as data,
|
|
12
|
+
// plus a small git adapter for the object-db reads, is what makes the
|
|
13
|
+
// re-review MACHINE itself — case classification, discovery widening, and
|
|
14
|
+
// Phase B queuing — testable with fakes, even though the fetches around it
|
|
15
|
+
// are not.
|
|
16
|
+
|
|
17
|
+
import { formatWorkflowCommand } from "#ci/reporter";
|
|
18
|
+
import type {
|
|
19
|
+
fetchPostedFindingComments,
|
|
20
|
+
fetchPrComments,
|
|
21
|
+
fetchPrReviewComments,
|
|
22
|
+
} from "#pr/pr";
|
|
23
|
+
import { findMarkedCommentId } from "#pr/preflight";
|
|
24
|
+
import {
|
|
25
|
+
adjudicationQueue,
|
|
26
|
+
buildPhaseBQueue,
|
|
27
|
+
decideLastHeadDelta,
|
|
28
|
+
enrichPriorsFromThreads,
|
|
29
|
+
incompleteLastReviewMessage,
|
|
30
|
+
type PreparedDiscovery,
|
|
31
|
+
parseNameStatus,
|
|
32
|
+
prepareDiscovery,
|
|
33
|
+
priorsFromPostedMarkers,
|
|
34
|
+
priorsFromStateFindings,
|
|
35
|
+
type RereviewProvenance,
|
|
36
|
+
shouldAbortEmptyDiscovery,
|
|
37
|
+
skippedDiscoveryMessage,
|
|
38
|
+
toRereviewProvenance,
|
|
39
|
+
unreachableLastHeadMessage,
|
|
40
|
+
} from "#rereview/prepare";
|
|
41
|
+
import { parseStateBlock } from "#rereview/state";
|
|
42
|
+
import type { VerifyQueueEntry } from "#rereview/verify";
|
|
43
|
+
import {
|
|
44
|
+
allExcludedMessage,
|
|
45
|
+
emptyDiffMessage,
|
|
46
|
+
resolveMaxVerificationSteps,
|
|
47
|
+
} from "#review/preflight";
|
|
48
|
+
import type { DiffStat } from "#review/report";
|
|
49
|
+
import {
|
|
50
|
+
computeDiffStatAndSizeGate,
|
|
51
|
+
type LoadedRunConfig,
|
|
52
|
+
selectActiveHunters,
|
|
53
|
+
} from "#review/run";
|
|
54
|
+
import {
|
|
55
|
+
type ExcludedPath,
|
|
56
|
+
evaluateSizeGate,
|
|
57
|
+
filterDiffByIgnoreRules,
|
|
58
|
+
type SizeGateVerdict,
|
|
59
|
+
sizeGateConfigFor,
|
|
60
|
+
} from "#review/size-gate";
|
|
61
|
+
import type { AgentSpec } from "#review/spec";
|
|
62
|
+
import type { AdjudicationSubject } from "#triage/adjudication";
|
|
63
|
+
import { parsePrCommentMarker, summaryMarkerFields } from "#watch/preflight";
|
|
64
|
+
import { CliError } from "../errors";
|
|
65
|
+
import type { IgnoreFileReadResult } from "../ignore-read";
|
|
66
|
+
|
|
67
|
+
// Invariant 1 (rereview-coverage fix): the ONLY input that may gate which
|
|
68
|
+
// hunters run for a re-review is `skipDiscovery` — never a hardcoded
|
|
69
|
+
// `case === "B"` special-case, which would defeat the fix by silently
|
|
70
|
+
// skipping discovery for every case-B re-review regardless of whether this
|
|
71
|
+
// particular one actually has nothing to discover. `agents`/`parityFires`
|
|
72
|
+
// flow through unchanged to `selectActiveHunters` (#review/run), shared with
|
|
73
|
+
// review()'s own copy.
|
|
74
|
+
export function discoveryHunters(params: {
|
|
75
|
+
skipDiscovery: boolean;
|
|
76
|
+
agents: readonly AgentSpec[];
|
|
77
|
+
parityFires: boolean;
|
|
78
|
+
}): AgentSpec[] {
|
|
79
|
+
return params.skipDiscovery
|
|
80
|
+
? []
|
|
81
|
+
: selectActiveHunters(params.agents, params.parityFires);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface PrDiscoveryGit {
|
|
85
|
+
commitExists(sha: string): Promise<boolean>;
|
|
86
|
+
isAncestor(ancestor: string, descendant: string): Promise<boolean>;
|
|
87
|
+
nameOnly(from: string, to: string): Promise<string[]>;
|
|
88
|
+
nameStatus(from: string, to: string): Promise<string>;
|
|
89
|
+
// The raw `git diff` primitive, repo already bound by the caller — used
|
|
90
|
+
// for the discovery-range diff itself and (via computeDiffStatAndSizeGate)
|
|
91
|
+
// its numstat variants. Matches computeDiffStatAndSizeGate's own `runGit`
|
|
92
|
+
// shape (#review/run) so both share one fake in tests.
|
|
93
|
+
runGit(
|
|
94
|
+
args: string[],
|
|
95
|
+
): Promise<{ ok: boolean; stdout: string; stderr: string }>;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export interface PrDiscoveryResult {
|
|
99
|
+
prepared: PreparedDiscovery;
|
|
100
|
+
skipDiscovery: boolean;
|
|
101
|
+
rawDiff: string;
|
|
102
|
+
effectiveDiff: {
|
|
103
|
+
patch: string;
|
|
104
|
+
droppedPaths: string[];
|
|
105
|
+
exclusions: ExcludedPath[];
|
|
106
|
+
};
|
|
107
|
+
// The diff inline comments are anchored against: the FULL PR range
|
|
108
|
+
// (diffFromSha..headSha), ignore-filtered like the discovery diff. On an
|
|
109
|
+
// incremental re-review the discovery diff covers only the push delta, so a
|
|
110
|
+
// finding on an untouched line of the PR would have no anchor and be posted
|
|
111
|
+
// as an outside-diff comment. Equal to effectiveDiff.patch whenever
|
|
112
|
+
// discovery already covers the whole PR range.
|
|
113
|
+
anchorPatch: string;
|
|
114
|
+
gateConfig: ReturnType<typeof sizeGateConfigFor>;
|
|
115
|
+
rereview: RereviewProvenance | undefined;
|
|
116
|
+
verifyQueue: VerifyQueueEntry[];
|
|
117
|
+
overlapCandidates: VerifyQueueEntry[];
|
|
118
|
+
// T5b: the pending dismissals the CI adjudicator rules on. Empty unless
|
|
119
|
+
// `adjudicate` was set.
|
|
120
|
+
adjudicationQueue: AdjudicationSubject[];
|
|
121
|
+
phaseB:
|
|
122
|
+
| {
|
|
123
|
+
settled: ReturnType<typeof buildPhaseBQueue>["settled"];
|
|
124
|
+
priors: ReturnType<typeof priorsFromStateFindings>;
|
|
125
|
+
}
|
|
126
|
+
| undefined;
|
|
127
|
+
diffStat: DiffStat;
|
|
128
|
+
sizeGate: SizeGateVerdict;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export async function resolvePrDiscovery(params: {
|
|
132
|
+
diffFromSha: string;
|
|
133
|
+
headSha: string;
|
|
134
|
+
full: boolean;
|
|
135
|
+
// T5b: `--adjudicate`. Absent or false queues no adjudication.
|
|
136
|
+
adjudicate?: boolean;
|
|
137
|
+
baseRef: string;
|
|
138
|
+
headLabel: string;
|
|
139
|
+
isCi: boolean;
|
|
140
|
+
sizeGateOverrides: { maxChangedLines?: number; maxChangedFiles?: number };
|
|
141
|
+
config: LoadedRunConfig["config"];
|
|
142
|
+
prIgnore: IgnoreFileReadResult;
|
|
143
|
+
issueComments: Awaited<ReturnType<typeof fetchPrComments>>;
|
|
144
|
+
postedFindings: Awaited<ReturnType<typeof fetchPostedFindingComments>>;
|
|
145
|
+
reviewComments: Awaited<ReturnType<typeof fetchPrReviewComments>>;
|
|
146
|
+
git: PrDiscoveryGit;
|
|
147
|
+
log: (line?: string) => void;
|
|
148
|
+
}): Promise<PrDiscoveryResult> {
|
|
149
|
+
const {
|
|
150
|
+
diffFromSha,
|
|
151
|
+
headSha,
|
|
152
|
+
full,
|
|
153
|
+
adjudicate,
|
|
154
|
+
baseRef,
|
|
155
|
+
headLabel,
|
|
156
|
+
isCi,
|
|
157
|
+
sizeGateOverrides,
|
|
158
|
+
config,
|
|
159
|
+
prIgnore,
|
|
160
|
+
issueComments,
|
|
161
|
+
postedFindings,
|
|
162
|
+
reviewComments,
|
|
163
|
+
git,
|
|
164
|
+
log,
|
|
165
|
+
} = params;
|
|
166
|
+
|
|
167
|
+
// parsePrCommentMarker, not parseMarkerHead: this is the ONE call site
|
|
168
|
+
// that decides whether the L this run is about to trust actually
|
|
169
|
+
// finished (rereview-coverage fix). A missing or unparseable
|
|
170
|
+
// marker means "nothing to distrust" — summaryMarkerFields defaults
|
|
171
|
+
// summaryComplete true and it is then ignored anyway, since
|
|
172
|
+
// resolveLastReviewedHead only consults it when summaryHead itself is
|
|
173
|
+
// non-null.
|
|
174
|
+
const existingSummaryId = findMarkedCommentId(issueComments);
|
|
175
|
+
const summaryMarker =
|
|
176
|
+
existingSummaryId === null
|
|
177
|
+
? null
|
|
178
|
+
: parsePrCommentMarker(
|
|
179
|
+
issueComments.find((c) => c.id === existingSummaryId)?.body ?? "",
|
|
180
|
+
);
|
|
181
|
+
const { summaryHead, summaryComplete } = summaryMarkerFields(summaryMarker);
|
|
182
|
+
const prepared = await prepareDiscovery({
|
|
183
|
+
B: diffFromSha,
|
|
184
|
+
H: headSha,
|
|
185
|
+
full,
|
|
186
|
+
summaryHead,
|
|
187
|
+
summaryComplete,
|
|
188
|
+
findingMarkers: postedFindings.map((p) => ({
|
|
189
|
+
headSha: p.marker.headSha,
|
|
190
|
+
createdAt: p.created_at ?? "",
|
|
191
|
+
})),
|
|
192
|
+
git: {
|
|
193
|
+
commitExists: git.commitExists,
|
|
194
|
+
isAncestor: git.isAncestor,
|
|
195
|
+
nameOnly: git.nameOnly,
|
|
196
|
+
},
|
|
197
|
+
});
|
|
198
|
+
const discoveryRange = `${prepared.discoveryFrom}..${prepared.discoveryTo}`;
|
|
199
|
+
const pathArgs =
|
|
200
|
+
prepared.discoveryPaths !== null && prepared.discoveryPaths.length > 0
|
|
201
|
+
? ["--", ...prepared.discoveryPaths]
|
|
202
|
+
: [];
|
|
203
|
+
const skipPlannedDiscovery =
|
|
204
|
+
prepared.plan.skipDiscovery || prepared.discoverySkippedEmptyDelta;
|
|
205
|
+
|
|
206
|
+
let rawDiff = "";
|
|
207
|
+
if (!skipPlannedDiscovery) {
|
|
208
|
+
const diff = await git.runGit(["diff", discoveryRange, ...pathArgs]);
|
|
209
|
+
if (!diff.ok) throw new CliError(`git diff failed: ${diff.stderr}`);
|
|
210
|
+
rawDiff = diff.stdout;
|
|
211
|
+
}
|
|
212
|
+
if (shouldAbortEmptyDiscovery(prepared.plan, rawDiff)) {
|
|
213
|
+
throw new CliError(emptyDiffMessage(baseRef, headLabel, false));
|
|
214
|
+
}
|
|
215
|
+
const gateConfig = sizeGateConfigFor(sizeGateOverrides, config, prIgnore);
|
|
216
|
+
const effectiveDiff = skipPlannedDiscovery
|
|
217
|
+
? {
|
|
218
|
+
patch: "",
|
|
219
|
+
droppedPaths: [] as string[],
|
|
220
|
+
exclusions: [] as ExcludedPath[],
|
|
221
|
+
}
|
|
222
|
+
: filterDiffByIgnoreRules(rawDiff, gateConfig.excludeRules);
|
|
223
|
+
if (
|
|
224
|
+
prepared.plan.emptyDeltaIsError &&
|
|
225
|
+
effectiveDiff.patch.trim().length === 0
|
|
226
|
+
) {
|
|
227
|
+
throw new CliError(
|
|
228
|
+
effectiveDiff.droppedPaths.length > 0
|
|
229
|
+
? allExcludedMessage(effectiveDiff.droppedPaths)
|
|
230
|
+
: emptyDiffMessage(baseRef, headLabel, false),
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
const skipDiscovery =
|
|
234
|
+
skipPlannedDiscovery || effectiveDiff.patch.trim().length === 0;
|
|
235
|
+
// WHY a second git call and not the discovery diff: GitHub anchors a review
|
|
236
|
+
// comment against the PR's merge-base..head diff, so the anchor set must
|
|
237
|
+
// cover that range even when discovery read only the delta or nothing.
|
|
238
|
+
const discoveryIsPrRange =
|
|
239
|
+
!skipPlannedDiscovery &&
|
|
240
|
+
prepared.discoveryFrom === diffFromSha &&
|
|
241
|
+
pathArgs.length === 0;
|
|
242
|
+
let anchorPatch = effectiveDiff.patch;
|
|
243
|
+
if (!discoveryIsPrRange) {
|
|
244
|
+
const prRange = await git.runGit(["diff", `${diffFromSha}..${headSha}`]);
|
|
245
|
+
if (!prRange.ok) throw new CliError(`git diff failed: ${prRange.stderr}`);
|
|
246
|
+
anchorPatch = filterDiffByIgnoreRules(
|
|
247
|
+
prRange.stdout,
|
|
248
|
+
gateConfig.excludeRules,
|
|
249
|
+
).patch;
|
|
250
|
+
}
|
|
251
|
+
const rereview = toRereviewProvenance(prepared, postedFindings.length);
|
|
252
|
+
if (rereview !== undefined && skipDiscovery) {
|
|
253
|
+
rereview.discovery_skipped_empty_delta = true;
|
|
254
|
+
// pr-hero review #286 finding: this flag alone cannot tell a reader WHY
|
|
255
|
+
// discovery is empty, and the two reasons need different wording — see
|
|
256
|
+
// `RereviewProvenance.discovery_skip_reason`'s own WHY. `skipPlannedDiscovery`
|
|
257
|
+
// is the (a) branch (case B / case C's empty restricted intersection,
|
|
258
|
+
// decided before any diff was even read); anything reaching here with
|
|
259
|
+
// `skipPlannedDiscovery` false got a REAL diff that `filterDiffByIgnoreRules`
|
|
260
|
+
// then emptied out — but ONLY when it actually dropped something. A
|
|
261
|
+
// `git diff` that came back empty on its own (no exclusions recorded)
|
|
262
|
+
// is still "nothing to discover", not "everything was excluded".
|
|
263
|
+
rereview.discovery_skip_reason =
|
|
264
|
+
!skipPlannedDiscovery && effectiveDiff.droppedPaths.length > 0
|
|
265
|
+
? "all_excluded"
|
|
266
|
+
: "no_delta";
|
|
267
|
+
if (rereview.discovery_skip_reason === "all_excluded") {
|
|
268
|
+
rereview.discovery_excluded_paths = effectiveDiff.droppedPaths;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
let verifyQueue: ReturnType<typeof buildPhaseBQueue>["queued"] = [];
|
|
273
|
+
let overlapCandidates: ReturnType<
|
|
274
|
+
typeof buildPhaseBQueue
|
|
275
|
+
>["overlapCandidates"] = [];
|
|
276
|
+
let phaseB: PrDiscoveryResult["phaseB"];
|
|
277
|
+
let adjudicationSubjects: AdjudicationSubject[] = [];
|
|
278
|
+
const lastHeadDelta = decideLastHeadDelta({
|
|
279
|
+
case: prepared.case,
|
|
280
|
+
L: prepared.last.L,
|
|
281
|
+
});
|
|
282
|
+
if (lastHeadDelta.kind !== "none") {
|
|
283
|
+
// A force-pushed L is gone from this clone, so there is no L..H delta to
|
|
284
|
+
// read and asking git for one is the crash this branch exists to avoid.
|
|
285
|
+
// Case E already planned a FULL review; an empty name-status keeps Phase
|
|
286
|
+
// B running over it, and classifyPrior's D/E branch queues every prior
|
|
287
|
+
// for verification before it would ever consult `touched`. Losing the
|
|
288
|
+
// deletion/rename settling that a real name-status buys therefore costs
|
|
289
|
+
// a verify spawn, never a dropped prior.
|
|
290
|
+
if (lastHeadDelta.kind === "unreachable") {
|
|
291
|
+
const degraded = unreachableLastHeadMessage(lastHeadDelta.sha);
|
|
292
|
+
log(isCi ? formatWorkflowCommand("notice", degraded) : degraded);
|
|
293
|
+
} else if (lastHeadDelta.kind === "diff" && !prepared.last.lastComplete) {
|
|
294
|
+
// The incomplete-review notice, same mechanism and "said once, in CI
|
|
295
|
+
// and out" rule as the unreachable one above — case E's unreachable
|
|
296
|
+
// message already explains "full review, re-verify everything" for
|
|
297
|
+
// that case, so this covers exactly the cases the unreachable branch
|
|
298
|
+
// does not: a forced-full B/C re-review because the LAST review (not
|
|
299
|
+
// this one) never finished.
|
|
300
|
+
const incomplete = incompleteLastReviewMessage(lastHeadDelta.from);
|
|
301
|
+
log(isCi ? formatWorkflowCommand("notice", incomplete) : incomplete);
|
|
302
|
+
}
|
|
303
|
+
const nameStatus = parseNameStatus(
|
|
304
|
+
lastHeadDelta.kind === "diff"
|
|
305
|
+
? await git.nameStatus(lastHeadDelta.from, headSha)
|
|
306
|
+
: "",
|
|
307
|
+
);
|
|
308
|
+
const summaryComment =
|
|
309
|
+
existingSummaryId === null
|
|
310
|
+
? undefined
|
|
311
|
+
: issueComments.find((c) => c.id === existingSummaryId);
|
|
312
|
+
const summaryUpdatedAt = summaryComment?.updated_at ?? null;
|
|
313
|
+
const state = parseStateBlock(summaryComment?.body ?? "");
|
|
314
|
+
// #206: `postedFindings` (PostedFindingComment[]) never carries the raw
|
|
315
|
+
// comment body — only the parsed marker fields (findingMarker signs the
|
|
316
|
+
// claim's fingerprint, never the claim text) — so recovering a fallback
|
|
317
|
+
// prior's real sev/tier/claim needs the body looked up from whichever
|
|
318
|
+
// fetch actually produced this comment. Built once, not per-item.
|
|
319
|
+
//
|
|
320
|
+
// Two maps, never one: review comments and issue comments are different
|
|
321
|
+
// GitHub resources from different endpoints, and nothing documents that
|
|
322
|
+
// their numeric ids share a namespace. A single map keyed by id alone
|
|
323
|
+
// would let a colliding issue comment silently hand this prior ANOTHER
|
|
324
|
+
// finding's sev/tier/claim — a plausible wrong value, which is worse than
|
|
325
|
+
// the UNRECOVERABLE sentinel this recovery exists to fall back on.
|
|
326
|
+
// `p.channel` already says which endpoint produced each posted finding.
|
|
327
|
+
const reviewBodyById = new Map<number, string>(
|
|
328
|
+
reviewComments.map((c) => [c.id, c.body] as const),
|
|
329
|
+
);
|
|
330
|
+
const issueBodyById = new Map<number, string>(
|
|
331
|
+
issueComments.map((c) => [c.id, c.body] as const),
|
|
332
|
+
);
|
|
333
|
+
const rawPriors =
|
|
334
|
+
state === null
|
|
335
|
+
? priorsFromPostedMarkers(
|
|
336
|
+
postedFindings.map((p) => ({
|
|
337
|
+
path: p.livePath ?? p.marker.path,
|
|
338
|
+
line: p.liveLine ?? p.marker.line,
|
|
339
|
+
channel: p.channel === "issue" ? "outside" : "inline",
|
|
340
|
+
body:
|
|
341
|
+
(p.channel === "issue"
|
|
342
|
+
? issueBodyById.get(p.id)
|
|
343
|
+
: reviewBodyById.get(p.id)) ?? "",
|
|
344
|
+
})),
|
|
345
|
+
)
|
|
346
|
+
: priorsFromStateFindings(state.findings);
|
|
347
|
+
const priors = enrichPriorsFromThreads({
|
|
348
|
+
priors: rawPriors,
|
|
349
|
+
posted: postedFindings,
|
|
350
|
+
replies: reviewComments,
|
|
351
|
+
summaryUpdatedAt,
|
|
352
|
+
headSha,
|
|
353
|
+
});
|
|
354
|
+
const classified = buildPhaseBQueue({
|
|
355
|
+
case: prepared.case,
|
|
356
|
+
priors,
|
|
357
|
+
nameStatus,
|
|
358
|
+
summaryUpdatedAt,
|
|
359
|
+
// Rereview-coverage wiring fix: `plan.verifyAll` was computed but
|
|
360
|
+
// never read anywhere in production — classifyPrior only ever forced
|
|
361
|
+
// verify_all off `case === "D" || "E"`, and decideRereviewCase stays
|
|
362
|
+
// UNCHANGED by this fix (the case stays B/C, only discovery widens,
|
|
363
|
+
// per R2-C5). Without this, `verifyAll: true` on a forced-full case
|
|
364
|
+
// B/C would be a silent no-op and the refuter-failed prior would
|
|
365
|
+
// never be re-verified.
|
|
366
|
+
verifyAll: prepared.plan.verifyAll,
|
|
367
|
+
});
|
|
368
|
+
verifyQueue = classified.queued;
|
|
369
|
+
overlapCandidates = classified.overlapCandidates;
|
|
370
|
+
phaseB = { settled: classified.settled, priors };
|
|
371
|
+
// T5b: only a `--adjudicate` run pays for adjudicator calls. The priors
|
|
372
|
+
// here are the enriched ones, so a dismissal's thread and CI verdict are
|
|
373
|
+
// already bound.
|
|
374
|
+
adjudicationSubjects = adjudicate === true ? adjudicationQueue(priors) : [];
|
|
375
|
+
if (rereview !== undefined) {
|
|
376
|
+
rereview.prior_findings = priors.length;
|
|
377
|
+
rereview.settled_deterministically = classified.settled.filter(
|
|
378
|
+
(s) => s.status !== "queued",
|
|
379
|
+
).length;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
// pr-hero review #286 finding: the discovery-skip notice used to print
|
|
384
|
+
// BEFORE this block ran, when `verifyQueue` did not exist yet — an empty
|
|
385
|
+
// notice claiming "not re-verified now" while case B's `applied`/
|
|
386
|
+
// `case_b_reply` triggers or case C's `touched()` (rereview/classify.ts)
|
|
387
|
+
// may have just queued priors for the SAME pass's verifier. Printed here,
|
|
388
|
+
// after the queue is a real, final number, the same "said once, in CI and
|
|
389
|
+
// out" rule as the unreachable/incomplete notices above.
|
|
390
|
+
if (rereview !== undefined && skipDiscovery) {
|
|
391
|
+
const skipped = skippedDiscoveryMessage({
|
|
392
|
+
headSha,
|
|
393
|
+
reason: rereview.discovery_skip_reason ?? "no_delta",
|
|
394
|
+
excludedPaths: rereview.discovery_excluded_paths ?? [],
|
|
395
|
+
queuedForVerification: verifyQueue.length,
|
|
396
|
+
maxVerificationSteps: resolveMaxVerificationSteps(config),
|
|
397
|
+
});
|
|
398
|
+
log(isCi ? formatWorkflowCommand("notice", skipped) : skipped);
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
let diffStat: DiffStat;
|
|
402
|
+
let sizeGate: SizeGateVerdict;
|
|
403
|
+
if (skipDiscovery) {
|
|
404
|
+
diffStat = { files: 0, insertions: 0, deletions: 0 };
|
|
405
|
+
sizeGate = evaluateSizeGate([], gateConfig);
|
|
406
|
+
} else {
|
|
407
|
+
// See computeDiffStatAndSizeGate (src/review/run.ts) for the full
|
|
408
|
+
// rationale.
|
|
409
|
+
({ diffStat, sizeGate } = await computeDiffStatAndSizeGate({
|
|
410
|
+
runGit: git.runGit,
|
|
411
|
+
range: discoveryRange,
|
|
412
|
+
pathArgs,
|
|
413
|
+
gateConfig,
|
|
414
|
+
}));
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
return {
|
|
418
|
+
prepared,
|
|
419
|
+
skipDiscovery,
|
|
420
|
+
rawDiff,
|
|
421
|
+
effectiveDiff,
|
|
422
|
+
anchorPatch,
|
|
423
|
+
gateConfig,
|
|
424
|
+
rereview,
|
|
425
|
+
verifyQueue,
|
|
426
|
+
overlapCandidates,
|
|
427
|
+
adjudicationQueue: adjudicationSubjects,
|
|
428
|
+
phaseB,
|
|
429
|
+
diffStat,
|
|
430
|
+
sizeGate,
|
|
431
|
+
};
|
|
432
|
+
}
|