crysk 0.0.0 → 0.3.1
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 +611 -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/SKILL-y8rv8msh.md +134 -0
- package/dist/SKILL-ygka1bs0.md +515 -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/ci-admission-qk9r9taq.md +124 -0
- package/dist/cli.js +42501 -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 +124 -0
- package/skills/crysk-ci-setup/references/opencode-ci.md +141 -0
- package/skills/crysk-loop/SKILL.md +515 -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 +945 -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 +910 -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 +984 -0
- package/src/pr/answered-findings.ts +169 -0
- package/src/pr/ci-admission-gate.ts +743 -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 +845 -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,845 @@
|
|
|
1
|
+
// The pure builder behind `pr-hero status` (ROADMAP S9): what a skill needs to drive
|
|
2
|
+
// review -> reply -> fix -> wait, read from the PR's own GitHub facts. Raw inputs in, the
|
|
3
|
+
// status object out, no I/O: src/commands/status.ts reads GitHub and hands the results here.
|
|
4
|
+
//
|
|
5
|
+
// Every reader is one the engine already uses: the gate (preflight.ts latestStatusInContext,
|
|
6
|
+
// isInFlightCommitStatus), the summary and its state block (findMarkedCommentId,
|
|
7
|
+
// parsePrCommentMarker, parseStateBlock), each finding (parseFindingMarker, and the header
|
|
8
|
+
// badge of report.ts), the triage a finding was answered with (parseTriageMarker, bound by
|
|
9
|
+
// the review thread, or by the link an outside-channel reply carries), and the newest outcome
|
|
10
|
+
// (parseOutcomeCode). Nothing here re-parses a
|
|
11
|
+
// format another module owns, so a drift in one of them moves this command with it.
|
|
12
|
+
|
|
13
|
+
import { OUTCOME_MARKER_PREFIX, parseOutcomeCode } from "#ci/outcome";
|
|
14
|
+
import { isOverrideStatus, overrideActorOf } from "#ci/override";
|
|
15
|
+
import {
|
|
16
|
+
OVERRIDE_COMMAND,
|
|
17
|
+
RECHECK_COMMAND,
|
|
18
|
+
REVIEW_COMMAND,
|
|
19
|
+
REVIEW_FULL_COMMAND,
|
|
20
|
+
} from "#ci/trigger";
|
|
21
|
+
import {
|
|
22
|
+
COMMIT_STATUS_CONTEXT,
|
|
23
|
+
type CommitStatusFact,
|
|
24
|
+
findMarkedCommentId,
|
|
25
|
+
IN_FLIGHT_TTL_MS,
|
|
26
|
+
isInFlightCommitStatus,
|
|
27
|
+
latestStatusInContext,
|
|
28
|
+
type ParsedFindingMarker,
|
|
29
|
+
parseFindingMarker,
|
|
30
|
+
} from "#pr/preflight";
|
|
31
|
+
import {
|
|
32
|
+
type RecoveredTier,
|
|
33
|
+
SEVERITY_UNRECOVERABLE,
|
|
34
|
+
TIER_UNRECOVERABLE,
|
|
35
|
+
} from "#rereview/classify";
|
|
36
|
+
import { parseProofRefLocs } from "#rereview/identity";
|
|
37
|
+
import { bindPriorsToPosted } from "#rereview/prepare";
|
|
38
|
+
import { parseStateBlock, type StateFinding } from "#rereview/state";
|
|
39
|
+
import { parseFindingCommentBadge } from "#review/report";
|
|
40
|
+
import {
|
|
41
|
+
CI_ADJUDICATOR_LOGIN,
|
|
42
|
+
parseAdjudicationMarker,
|
|
43
|
+
} from "#triage/adjudication";
|
|
44
|
+
import {
|
|
45
|
+
type ParsedTriageMarker,
|
|
46
|
+
parseTriageMarker,
|
|
47
|
+
type TriageActor,
|
|
48
|
+
type TriageTag,
|
|
49
|
+
type TriageVerdict,
|
|
50
|
+
} from "#triage/triage";
|
|
51
|
+
import { parsePrCommentMarker } from "#watch/preflight";
|
|
52
|
+
import {
|
|
53
|
+
canonicalStatusText,
|
|
54
|
+
commandHint,
|
|
55
|
+
isCommand,
|
|
56
|
+
matchMarkerPrefix,
|
|
57
|
+
} from "../brand";
|
|
58
|
+
|
|
59
|
+
export const PR_STATUS_SCHEMA = "pr-hero.status/v1" as const;
|
|
60
|
+
|
|
61
|
+
export type PrGateState = "success" | "failure" | "error" | "pending" | "none";
|
|
62
|
+
export type PrNextAction =
|
|
63
|
+
| "wait"
|
|
64
|
+
| "review"
|
|
65
|
+
| "triage"
|
|
66
|
+
| "fix"
|
|
67
|
+
| "override-or-fix"
|
|
68
|
+
| "recheck"
|
|
69
|
+
| "done";
|
|
70
|
+
|
|
71
|
+
export interface PrStatusGate {
|
|
72
|
+
state: PrGateState;
|
|
73
|
+
description: string | null;
|
|
74
|
+
target_url: string | null;
|
|
75
|
+
created_at: string | null;
|
|
76
|
+
pending_in_flight: boolean;
|
|
77
|
+
override: { active: boolean; by: string | null };
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export interface PrStatusReport {
|
|
81
|
+
head: string | null;
|
|
82
|
+
complete: boolean | null;
|
|
83
|
+
reviews: number | null;
|
|
84
|
+
outcome_code: string | null;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export interface PrStatusTriage {
|
|
88
|
+
tag: TriageTag;
|
|
89
|
+
verdict: TriageVerdict | null;
|
|
90
|
+
actor: TriageActor;
|
|
91
|
+
head: string;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export interface PrStatusFinding {
|
|
95
|
+
id: string | null;
|
|
96
|
+
path: string;
|
|
97
|
+
line: number;
|
|
98
|
+
// The head the finding was posted on. Null for a state row no comment carries: the row has no
|
|
99
|
+
// head of its own, and nothing was posted here.
|
|
100
|
+
head: string | null;
|
|
101
|
+
// Null for a finding with no comment thread (a state row no comment bound: summary-only, or
|
|
102
|
+
// never posted inline). Such a finding cannot be answered with a triage reply.
|
|
103
|
+
comment_id: number | null;
|
|
104
|
+
channel: "inline" | "outside";
|
|
105
|
+
severity: string | null;
|
|
106
|
+
// The tier the badge or the state row reports: "blocking" or "advisory". "unrecoverable" (the
|
|
107
|
+
// engine's sentinel, rereview/classify.ts) when neither can give one. Never null.
|
|
108
|
+
// `blocking` is the field every blocking decision reads.
|
|
109
|
+
tier: RecoveredTier;
|
|
110
|
+
// True for every tier but advisory. An unrecoverable tier counts as blocking because the gate
|
|
111
|
+
// counts it that way (rereview/state.ts unresolvedBlockingCount): fail closed, so a finding
|
|
112
|
+
// that cannot be read as advisory is never waved through.
|
|
113
|
+
blocking: boolean;
|
|
114
|
+
live_on_head: boolean;
|
|
115
|
+
triage: PrStatusTriage | null;
|
|
116
|
+
// The CI adjudicator's ruling on the newest triage reply, counted only when github-actions[bot] posted it on the head being read (src/triage/adjudication.ts). Null when there is none.
|
|
117
|
+
ci_verdict: "upheld" | "rejected" | "inconclusive" | null;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export interface PrStatusJson {
|
|
121
|
+
schema: typeof PR_STATUS_SCHEMA;
|
|
122
|
+
pr: number;
|
|
123
|
+
head: string;
|
|
124
|
+
gate: PrStatusGate;
|
|
125
|
+
report: PrStatusReport;
|
|
126
|
+
findings: PrStatusFinding[];
|
|
127
|
+
unresolved_blocking: number;
|
|
128
|
+
next_action: PrNextAction;
|
|
129
|
+
reason: string;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// A GitHub comment as the shell reads it. Review comments also carry the thread link a
|
|
133
|
+
// triage reply is bound by (in_reply_to_id); issue comments have none.
|
|
134
|
+
export interface PrStatusComment {
|
|
135
|
+
id: number;
|
|
136
|
+
body: string;
|
|
137
|
+
created_at?: string;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export const STATUS_WAIT_POLL_INTERVAL_MS = 15_000;
|
|
141
|
+
export const STATUS_WAIT_STARTUP_GRACE_MS = 180_000;
|
|
142
|
+
export const STATUS_WAIT_MAX_MS = IN_FLIGHT_TTL_MS;
|
|
143
|
+
|
|
144
|
+
const TRIGGER_COMMANDS = [REVIEW_COMMAND, REVIEW_FULL_COMMAND, RECHECK_COMMAND];
|
|
145
|
+
|
|
146
|
+
// A review comment's live projection (pr/pr.ts PrReviewComment) carries the path and line
|
|
147
|
+
// GitHub shows now, which follow a rename or a re-anchor. Optional, as the engine's own posted
|
|
148
|
+
// shape has them (rereview/prepare.ts PostedForPrior): without them the marker's anchor stands.
|
|
149
|
+
export interface PrStatusReviewComment extends PrStatusComment {
|
|
150
|
+
in_reply_to_id: number | null;
|
|
151
|
+
// The GitHub login that posted it. The CI adjudicator's ruling is trusted only from CI_ADJUDICATOR_LOGIN.
|
|
152
|
+
user?: string;
|
|
153
|
+
path?: string;
|
|
154
|
+
line?: number | null;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export interface PrStatusInput {
|
|
158
|
+
pr: number;
|
|
159
|
+
head: string;
|
|
160
|
+
nowMs: number;
|
|
161
|
+
statuses: CommitStatusFact[];
|
|
162
|
+
issueComments: PrStatusComment[];
|
|
163
|
+
reviewComments: PrStatusReviewComment[];
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// The window a pending status is trusted for, named from the constant that defines it, so
|
|
167
|
+
// the reason a stale pending reads as "review" never drifts from the watcher's own rule.
|
|
168
|
+
const IN_FLIGHT_WINDOW_MINUTES = Math.round(IN_FLIGHT_TTL_MS / 60_000);
|
|
169
|
+
|
|
170
|
+
// A finding as the decision needs it: the output row, plus whether a triage reply sits at
|
|
171
|
+
// the head the finding was posted on (a reply at another head does not answer it).
|
|
172
|
+
interface AnalyzedFinding {
|
|
173
|
+
finding: PrStatusFinding;
|
|
174
|
+
triagedAtPostedHead: boolean;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export function buildPrStatus(input: PrStatusInput): PrStatusJson {
|
|
178
|
+
const gate = readGate(input);
|
|
179
|
+
const summary = readSummary(input.issueComments);
|
|
180
|
+
const analyzed = readFindings(input, summary.rows);
|
|
181
|
+
const liveBlocking = analyzed.filter(
|
|
182
|
+
(a) => a.finding.blocking && a.finding.live_on_head,
|
|
183
|
+
);
|
|
184
|
+
const decision = decideNext(gate, analyzed, input.head, summary);
|
|
185
|
+
return {
|
|
186
|
+
schema: PR_STATUS_SCHEMA,
|
|
187
|
+
pr: input.pr,
|
|
188
|
+
head: input.head,
|
|
189
|
+
gate,
|
|
190
|
+
report: {
|
|
191
|
+
head: summary.head,
|
|
192
|
+
complete: summary.complete,
|
|
193
|
+
reviews: summary.reviews,
|
|
194
|
+
outcome_code: outcomeCodeOf(input.issueComments),
|
|
195
|
+
},
|
|
196
|
+
findings: analyzed.map((a) => a.finding),
|
|
197
|
+
// A dismissal the CI adjudicator upheld on this head leaves the gate's count (review #348
|
|
198
|
+
// F001), so the fallback count leaves it out too.
|
|
199
|
+
unresolved_blocking: unresolvedBlocking(
|
|
200
|
+
gate,
|
|
201
|
+
liveBlocking.filter((a) => !upheldDismissal(a)).length,
|
|
202
|
+
),
|
|
203
|
+
next_action: decision.next_action,
|
|
204
|
+
reason: decision.reason,
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// The gate is crysk's own commit status on the head, read by its context alone (the legacy
|
|
209
|
+
// pr-hero name counts as the same context), so a local run's crysk/local status never
|
|
210
|
+
// answers for the gate.
|
|
211
|
+
function readGate(input: PrStatusInput): PrStatusGate {
|
|
212
|
+
const latest = latestStatusInContext(input.statuses, COMMIT_STATUS_CONTEXT);
|
|
213
|
+
if (latest === null) {
|
|
214
|
+
return {
|
|
215
|
+
state: "none",
|
|
216
|
+
description: null,
|
|
217
|
+
target_url: null,
|
|
218
|
+
created_at: null,
|
|
219
|
+
pending_in_flight: false,
|
|
220
|
+
override: { active: false, by: null },
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
const active = isOverrideStatus(latest);
|
|
224
|
+
const description = latest.description ?? null;
|
|
225
|
+
return {
|
|
226
|
+
state: gateStateOf(latest.state),
|
|
227
|
+
description,
|
|
228
|
+
target_url: latest.target_url ?? null,
|
|
229
|
+
created_at: latest.created_at,
|
|
230
|
+
pending_in_flight: isInFlightCommitStatus(input.statuses, input.nowMs),
|
|
231
|
+
override: {
|
|
232
|
+
active,
|
|
233
|
+
by: active && description !== null ? overrideActorOf(description) : null,
|
|
234
|
+
},
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// A state the reader does not know is read as error, which sends a review out. It never
|
|
239
|
+
// reads as success, so an unrecognised gate cannot pass a PR.
|
|
240
|
+
function gateStateOf(state: string): PrGateState {
|
|
241
|
+
if (
|
|
242
|
+
state === "success" ||
|
|
243
|
+
state === "failure" ||
|
|
244
|
+
state === "error" ||
|
|
245
|
+
state === "pending"
|
|
246
|
+
) {
|
|
247
|
+
return state;
|
|
248
|
+
}
|
|
249
|
+
return "error";
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// The live blocking findings at input.head, each with its newest triage reply and CI ruling, read exactly as
|
|
253
|
+
// buildPrStatus reads them. The admission gate reads them for the reviewed head (pr/answered-findings.ts).
|
|
254
|
+
export function liveBlockingFindings(input: PrStatusInput): PrStatusFinding[] {
|
|
255
|
+
const summary = readSummary(input.issueComments);
|
|
256
|
+
return readFindings(input, summary.rows)
|
|
257
|
+
.filter((a) => a.finding.blocking && a.finding.live_on_head)
|
|
258
|
+
.map((a) => a.finding);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// The summary is the newest comment carrying the report marker (findMarkedCommentId picks
|
|
262
|
+
// the newest). Its head and completeness come from the marker; its reviews count and its
|
|
263
|
+
// live rows come from the state block that the summary carries.
|
|
264
|
+
function readSummary(comments: PrStatusComment[]): {
|
|
265
|
+
head: string | null;
|
|
266
|
+
complete: boolean | null;
|
|
267
|
+
reviews: number | null;
|
|
268
|
+
rows: StateFinding[];
|
|
269
|
+
} {
|
|
270
|
+
const id = findMarkedCommentId(comments);
|
|
271
|
+
const body = comments.find((c) => c.id === id)?.body ?? null;
|
|
272
|
+
if (id === null || body === null) {
|
|
273
|
+
return { head: null, complete: null, reviews: null, rows: [] };
|
|
274
|
+
}
|
|
275
|
+
const marker = parsePrCommentMarker(body);
|
|
276
|
+
const state = parseStateBlock(body);
|
|
277
|
+
return {
|
|
278
|
+
head: marker?.head ?? null,
|
|
279
|
+
complete: marker?.complete ?? null,
|
|
280
|
+
reviews: state?.reviews ?? null,
|
|
281
|
+
rows: state?.findings ?? [],
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// The newest outcome comment's code. Only the newest is read: an older run's code says
|
|
286
|
+
// nothing about the run the gate now reflects. Null when the newest has no catalogued code.
|
|
287
|
+
function outcomeCodeOf(comments: PrStatusComment[]): string | null {
|
|
288
|
+
let newest: PrStatusComment | null = null;
|
|
289
|
+
for (const comment of comments) {
|
|
290
|
+
if (matchMarkerPrefix(comment.body, OUTCOME_MARKER_PREFIX) === undefined) {
|
|
291
|
+
continue;
|
|
292
|
+
}
|
|
293
|
+
if (newest === null || comment.id > newest.id) newest = comment;
|
|
294
|
+
}
|
|
295
|
+
return newest === null ? null : parseOutcomeCode(newest.body);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// Every posted finding, from both streams, in comment order. Only a comment that parses
|
|
299
|
+
// as a finding marker is a finding, so the summary and a human's reply drop out here.
|
|
300
|
+
function readFindings(
|
|
301
|
+
input: PrStatusInput,
|
|
302
|
+
rows: StateFinding[],
|
|
303
|
+
): AnalyzedFinding[] {
|
|
304
|
+
const sources: {
|
|
305
|
+
id: number;
|
|
306
|
+
body: string;
|
|
307
|
+
channel: "inline" | "outside";
|
|
308
|
+
// A review comment's live path and line, as pr/discovery.ts reads them. An outside comment
|
|
309
|
+
// has no live projection, so its marker's anchor is the only one.
|
|
310
|
+
livePath?: string;
|
|
311
|
+
liveLine?: number;
|
|
312
|
+
}[] = [
|
|
313
|
+
...input.reviewComments.map((c) => ({
|
|
314
|
+
id: c.id,
|
|
315
|
+
body: c.body,
|
|
316
|
+
channel: "inline" as const,
|
|
317
|
+
livePath: c.path,
|
|
318
|
+
liveLine: c.line ?? undefined,
|
|
319
|
+
})),
|
|
320
|
+
...input.issueComments.map((c) => ({
|
|
321
|
+
id: c.id,
|
|
322
|
+
body: c.body,
|
|
323
|
+
channel: "outside" as const,
|
|
324
|
+
})),
|
|
325
|
+
].sort((a, b) => a.id - b.id);
|
|
326
|
+
const posted: {
|
|
327
|
+
source: (typeof sources)[number];
|
|
328
|
+
marker: ParsedFindingMarker;
|
|
329
|
+
}[] = [];
|
|
330
|
+
for (const source of sources) {
|
|
331
|
+
const marker = parseFindingMarker(source.body);
|
|
332
|
+
if (marker !== null) posted.push({ source, marker });
|
|
333
|
+
}
|
|
334
|
+
// The join is the engine's own prior-to-comment binding (bindPriorsToPosted, rereview/
|
|
335
|
+
// prepare.ts): a row binds a posted finding only when the comment's anchor lands within one
|
|
336
|
+
// of the row's locs on the same path, and the claim fingerprint `c` breaks a tie and nothing
|
|
337
|
+
// else. Keying on `c` alone let two findings with the same claim on different paths share one
|
|
338
|
+
// row. The binding is one-to-one, so it runs once over every posted finding.
|
|
339
|
+
const bound = bindPriorsToPosted(
|
|
340
|
+
rows,
|
|
341
|
+
posted.map(({ source, marker }) => ({
|
|
342
|
+
id: source.id,
|
|
343
|
+
marker,
|
|
344
|
+
livePath: source.livePath,
|
|
345
|
+
liveLine: source.liveLine,
|
|
346
|
+
})),
|
|
347
|
+
);
|
|
348
|
+
const rowByComment = new Map<number, StateFinding>();
|
|
349
|
+
for (const row of rows) {
|
|
350
|
+
const comment = bound.get(row.id);
|
|
351
|
+
if (comment !== undefined) rowByComment.set(comment.id, row);
|
|
352
|
+
}
|
|
353
|
+
const out: AnalyzedFinding[] = [];
|
|
354
|
+
for (const { source, marker } of posted) {
|
|
355
|
+
const row = rowByComment.get(source.id);
|
|
356
|
+
const badge = parseFindingCommentBadge(source.body);
|
|
357
|
+
const replies = repliesTo(source, input);
|
|
358
|
+
const newest = newestReply(replies);
|
|
359
|
+
const triage = newest?.marker ?? null;
|
|
360
|
+
// The badge's tier, else the row's, else the engine's unrecoverable sentinel: the same fallback
|
|
361
|
+
// priorsFromPostedMarkers (rereview/prepare.ts) applies to a comment it cannot read.
|
|
362
|
+
const tier: RecoveredTier = badge?.tier ?? row?.tier ?? TIER_UNRECOVERABLE;
|
|
363
|
+
out.push({
|
|
364
|
+
finding: {
|
|
365
|
+
id: row?.id ?? null,
|
|
366
|
+
path: marker.path,
|
|
367
|
+
line: marker.line,
|
|
368
|
+
head: marker.headSha,
|
|
369
|
+
comment_id: source.id,
|
|
370
|
+
channel: source.channel,
|
|
371
|
+
severity:
|
|
372
|
+
badge?.sev ??
|
|
373
|
+
(row !== undefined && row.sev !== SEVERITY_UNRECOVERABLE
|
|
374
|
+
? row.sev
|
|
375
|
+
: null),
|
|
376
|
+
tier,
|
|
377
|
+
// Fail closed: only an advisory tier clears a finding, so an unrecoverable one blocks.
|
|
378
|
+
blocking: tier !== "advisory",
|
|
379
|
+
// A finding is live when the summary's state block still carries its row, or when
|
|
380
|
+
// it was posted on the head being read. A row is the gate's own memory of a live
|
|
381
|
+
// finding, so a carried finding from an older head stays live.
|
|
382
|
+
live_on_head: row !== undefined || marker.headSha === input.head,
|
|
383
|
+
triage:
|
|
384
|
+
triage === null
|
|
385
|
+
? null
|
|
386
|
+
: {
|
|
387
|
+
tag: triage.tag,
|
|
388
|
+
verdict: triage.verdict ?? null,
|
|
389
|
+
actor: triage.actor,
|
|
390
|
+
head: triage.headSha,
|
|
391
|
+
},
|
|
392
|
+
ci_verdict:
|
|
393
|
+
source.channel === "inline"
|
|
394
|
+
? ciVerdictOf(source.id, newest?.id ?? null, input)
|
|
395
|
+
: null,
|
|
396
|
+
},
|
|
397
|
+
// A reply at another head does not answer the finding, so only a reply carrying the
|
|
398
|
+
// posted head counts.
|
|
399
|
+
triagedAtPostedHead: replies.some(
|
|
400
|
+
(r) => r.marker.headSha === marker.headSha,
|
|
401
|
+
),
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
// A live row no comment bound to (summary-only, or never posted inline) is still a finding the
|
|
405
|
+
// gate counts. Without this row the status could not see a blocking finding the gate names.
|
|
406
|
+
for (const row of rows) {
|
|
407
|
+
if (bound.has(row.id)) continue;
|
|
408
|
+
out.push({ finding: unthreadedFinding(row), triagedAtPostedHead: false });
|
|
409
|
+
}
|
|
410
|
+
return out;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
// A state row with no comment: its anchor is the first of its locs (path:line or path:a-b, the
|
|
414
|
+
// start line), read with the same parser the binder uses. A row with no parseable loc keeps its raw
|
|
415
|
+
// text and line 0, so it still blocks and still reports.
|
|
416
|
+
function unthreadedFinding(row: StateFinding): PrStatusFinding {
|
|
417
|
+
const first = row.locs[0];
|
|
418
|
+
const span = first === undefined ? undefined : parseProofRefLocs(first)[0];
|
|
419
|
+
// Fail closed: only an advisory tier clears a row, as for a comment.
|
|
420
|
+
const tier: RecoveredTier = row.tier;
|
|
421
|
+
return {
|
|
422
|
+
id: row.id,
|
|
423
|
+
path: span?.path ?? first ?? "",
|
|
424
|
+
line: span?.span.start ?? 0,
|
|
425
|
+
head: null,
|
|
426
|
+
comment_id: null,
|
|
427
|
+
channel: row.channel,
|
|
428
|
+
severity: row.sev !== SEVERITY_UNRECOVERABLE ? row.sev : null,
|
|
429
|
+
tier,
|
|
430
|
+
blocking: tier !== "advisory",
|
|
431
|
+
live_on_head: true,
|
|
432
|
+
triage: null,
|
|
433
|
+
ci_verdict: null,
|
|
434
|
+
};
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
// The CI adjudicator's ruling on the newest triage reply of one inline finding. Only a reply
|
|
438
|
+
// github-actions[bot] posted, on the head under review, that names this newest reply counts; the
|
|
439
|
+
// highest comment id wins. Null when there is no such ruling.
|
|
440
|
+
function ciVerdictOf(
|
|
441
|
+
threadId: number,
|
|
442
|
+
newestTriageId: number | null,
|
|
443
|
+
input: PrStatusInput,
|
|
444
|
+
): "upheld" | "rejected" | "inconclusive" | null {
|
|
445
|
+
if (newestTriageId === null) return null;
|
|
446
|
+
let best: {
|
|
447
|
+
id: number;
|
|
448
|
+
verdict: "upheld" | "rejected" | "inconclusive";
|
|
449
|
+
} | null = null;
|
|
450
|
+
for (const comment of input.reviewComments) {
|
|
451
|
+
if (comment.in_reply_to_id !== threadId) continue;
|
|
452
|
+
if (comment.user !== CI_ADJUDICATOR_LOGIN) continue;
|
|
453
|
+
const marker = parseAdjudicationMarker(comment.body);
|
|
454
|
+
if (marker === null) continue;
|
|
455
|
+
if (marker.reply !== newestTriageId || marker.head !== input.head) continue;
|
|
456
|
+
if (best === null || comment.id > best.id) {
|
|
457
|
+
best = { id: comment.id, verdict: marker.verdict };
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
return best?.verdict ?? null;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
interface TriageReplyRow {
|
|
464
|
+
id: number;
|
|
465
|
+
marker: ParsedTriageMarker;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
// Every triage reply that answers one posted finding. An inline finding's replies sit in its
|
|
469
|
+
// review thread (in_reply_to_id). An outside-channel finding has no thread: its replies are
|
|
470
|
+
// top-level issue comments, and the link triage/reply writes binds one to its finding
|
|
471
|
+
// (`In reply to: <url>#issuecomment-<id>`). A comment that does not parse as a triage marker
|
|
472
|
+
// is not a reply, whatever it links.
|
|
473
|
+
function repliesTo(
|
|
474
|
+
source: { id: number; channel: "inline" | "outside" },
|
|
475
|
+
input: PrStatusInput,
|
|
476
|
+
): TriageReplyRow[] {
|
|
477
|
+
const out: TriageReplyRow[] = [];
|
|
478
|
+
if (source.channel === "inline") {
|
|
479
|
+
for (const reply of input.reviewComments) {
|
|
480
|
+
if (reply.in_reply_to_id !== source.id) continue;
|
|
481
|
+
const marker = parseTriageMarker(reply.body);
|
|
482
|
+
if (marker !== null) out.push({ id: reply.id, marker });
|
|
483
|
+
}
|
|
484
|
+
return out;
|
|
485
|
+
}
|
|
486
|
+
const link = new RegExp(`#issuecomment-${source.id}(?!\\d)`);
|
|
487
|
+
for (const comment of input.issueComments) {
|
|
488
|
+
const marker = parseTriageMarker(comment.body);
|
|
489
|
+
if (marker === null || !link.test(comment.body)) continue;
|
|
490
|
+
out.push({ id: comment.id, marker });
|
|
491
|
+
}
|
|
492
|
+
return out;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
// The newest reply by comment id (the API's own order is not relied on).
|
|
496
|
+
function newestReply(
|
|
497
|
+
replies: readonly TriageReplyRow[],
|
|
498
|
+
): TriageReplyRow | null {
|
|
499
|
+
let newest: TriageReplyRow | null = null;
|
|
500
|
+
for (const reply of replies) {
|
|
501
|
+
if (newest === null || reply.id > newest.id) newest = reply;
|
|
502
|
+
}
|
|
503
|
+
return newest;
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
// The red partial-review verdict (preflight.ts partialReviewDescription) and its carried form
|
|
507
|
+
// (admission.ts carriedPartialDescription). The prefix is what this reader needs: the full text is
|
|
508
|
+
// written by those builders, and the gate's own state already says the review is red.
|
|
509
|
+
const PARTIAL_REVIEW_GATE =
|
|
510
|
+
/^crysk: review partial \(\d+ of \d+ hunters failed(?:, set [0-9a-f]{6})?\)/;
|
|
511
|
+
|
|
512
|
+
// W3-PARTIAL F004: the repeat form, the same N of M failure set as the head's previous partial verdict.
|
|
513
|
+
// A retry already failed that way, so the unlock is a route fix or an override, never review again.
|
|
514
|
+
const PARTIAL_REVIEW_AGAIN_GATE =
|
|
515
|
+
/^crysk: review partial again \(\d+ of \d+ hunters failed(?:, set [0-9a-f]{6})?\)/;
|
|
516
|
+
|
|
517
|
+
// unresolved_blocking has two sources, and the description wins when it has one. A red
|
|
518
|
+
// gate's description names the count its own rule counted (rereview/state.ts
|
|
519
|
+
// unresolvedBlockingCount), which can include a carried row that no comment in this read
|
|
520
|
+
// shows. Every other state has no such count, so it is the live blocking findings this read
|
|
521
|
+
// can see. Nothing else is counted.
|
|
522
|
+
function unresolvedBlocking(
|
|
523
|
+
gate: PrStatusGate,
|
|
524
|
+
liveBlockingCount: number,
|
|
525
|
+
): number {
|
|
526
|
+
return gateBlockingCount(gate) ?? liveBlockingCount;
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
// The count a red gate's own description names, or null when it names none.
|
|
530
|
+
function gateBlockingCount(gate: PrStatusGate): number | null {
|
|
531
|
+
if (gate.state !== "failure" || gate.description === null) return null;
|
|
532
|
+
const counted = /^crysk: (\d+) blocking finding\(s\)/.exec(
|
|
533
|
+
canonicalStatusText(gate.description),
|
|
534
|
+
);
|
|
535
|
+
return counted?.[1] === undefined ? null : Number(counted[1]);
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
// The gate descriptions that name no review of this head: the automatic budget is used up, or the
|
|
539
|
+
// policy is manual. A gate stopped writing them on 2026-10-30 (budget-exhausted-carry S2: both carry the
|
|
540
|
+
// last verdict now), so only a head statused before that still carries one. Their text is the gate's own,
|
|
541
|
+
// so no count is read.
|
|
542
|
+
const REVIEW_TRIGGER_GATE =
|
|
543
|
+
/^crysk: review (budget for this PR is used up|needs a manual trigger)/;
|
|
544
|
+
|
|
545
|
+
// A blocking red a skip carried from an earlier commit (admission.ts carriedBlockingDescription).
|
|
546
|
+
const CARRIED_BLOCKING_GATE = /^crysk: \d+ blocking finding\(s\) carried from /;
|
|
547
|
+
|
|
548
|
+
// The green a skip writes over answered findings no review verified (admission.ts unverifiedFixesDescription).
|
|
549
|
+
const UNVERIFIED_FIXES_GATE =
|
|
550
|
+
/^crysk: \d+ answered finding\(s\), fixes unverified \(/;
|
|
551
|
+
|
|
552
|
+
// A blocking finding whose newest reply is a dismissal the CI adjudicator upheld on this head.
|
|
553
|
+
function upheldDismissal(a: AnalyzedFinding): boolean {
|
|
554
|
+
return (
|
|
555
|
+
a.finding.triage?.tag === "dismissed" && a.finding.ci_verdict === "upheld"
|
|
556
|
+
);
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
// The next action, first match wins. The branches are in the order the skill must act on
|
|
560
|
+
// them, and each carries its own reason sentence so the human reads the same decision the
|
|
561
|
+
// skill made.
|
|
562
|
+
function decideNext(
|
|
563
|
+
gate: PrStatusGate,
|
|
564
|
+
analyzed: AnalyzedFinding[],
|
|
565
|
+
head: string,
|
|
566
|
+
summary: { head: string | null; complete: boolean | null },
|
|
567
|
+
): { next_action: PrNextAction; reason: string } {
|
|
568
|
+
const liveBlocking = analyzed.filter(
|
|
569
|
+
(a) => a.finding.blocking && a.finding.live_on_head,
|
|
570
|
+
);
|
|
571
|
+
if (gate.state === "pending") {
|
|
572
|
+
if (gate.pending_in_flight) {
|
|
573
|
+
return {
|
|
574
|
+
next_action: "wait",
|
|
575
|
+
reason: `A crysk review is in flight on this head (pending since ${gate.created_at}); wait for it to finish.`,
|
|
576
|
+
};
|
|
577
|
+
}
|
|
578
|
+
// A pending past the in-flight window is not held by any run. The watcher's own rule
|
|
579
|
+
// lets the next tick start a review then, so the skill starts one too.
|
|
580
|
+
return {
|
|
581
|
+
next_action: "review",
|
|
582
|
+
reason: `The pending crysk status on this head is older than the ${IN_FLIGHT_WINDOW_MINUTES}-minute in-flight window and no run holds it; start a review.`,
|
|
583
|
+
};
|
|
584
|
+
}
|
|
585
|
+
if (gate.state === "none") {
|
|
586
|
+
return {
|
|
587
|
+
next_action: "review",
|
|
588
|
+
reason:
|
|
589
|
+
"No crysk gate status is on this head, so no review has run here yet; start one.",
|
|
590
|
+
};
|
|
591
|
+
}
|
|
592
|
+
if (gate.state === "error") {
|
|
593
|
+
return {
|
|
594
|
+
next_action: "review",
|
|
595
|
+
reason: `The last crysk review on this head did not finish (${gate.description ?? "no description"}); start a review.`,
|
|
596
|
+
};
|
|
597
|
+
}
|
|
598
|
+
if (gate.state === "success") {
|
|
599
|
+
// An override is a human's unlock of the head, so it stays done whatever the findings say.
|
|
600
|
+
if (gate.override.active) {
|
|
601
|
+
return {
|
|
602
|
+
next_action: "done",
|
|
603
|
+
reason: `The gate is green through an override by @${gate.override.by ?? "an unknown login"}; nothing is owed on this head.`,
|
|
604
|
+
};
|
|
605
|
+
}
|
|
606
|
+
// A partial review of this head (some reviewers failed) is not a finished review, and the
|
|
607
|
+
// engine's own admission runs the same head again (partialSameHead, ci/review-admission.ts).
|
|
608
|
+
// A green gate over it is therefore review. The same marker on an older head is history.
|
|
609
|
+
if (summary.head === head && summary.complete === false) {
|
|
610
|
+
return {
|
|
611
|
+
next_action: "review",
|
|
612
|
+
reason: `The last review of this head was partial (some reviewers failed); run ${commandHint(REVIEW_COMMAND, "")}.`,
|
|
613
|
+
};
|
|
614
|
+
}
|
|
615
|
+
// The triage skill answers every finding, advisory included, so a green gate is not the
|
|
616
|
+
// end while a finding posted on this head has no reply at that head. A finding posted on an
|
|
617
|
+
// older head is not this head's to answer.
|
|
618
|
+
const owed = analyzed.filter(
|
|
619
|
+
(a) => a.finding.head === head && !a.triagedAtPostedHead,
|
|
620
|
+
);
|
|
621
|
+
if (owed.length > 0) {
|
|
622
|
+
return {
|
|
623
|
+
next_action: "triage",
|
|
624
|
+
reason: `The gate is green, but ${owed.length} finding(s) on this head have no reply yet; triage them.`,
|
|
625
|
+
};
|
|
626
|
+
}
|
|
627
|
+
// budget-exhausted-carry S6: a green no review verified. Nothing is owed, and the reason says why
|
|
628
|
+
// it is green, so the skill reports the fixes as unverified rather than reviewed.
|
|
629
|
+
if (
|
|
630
|
+
UNVERIFIED_FIXES_GATE.test(canonicalStatusText(gate.description ?? ""))
|
|
631
|
+
) {
|
|
632
|
+
return {
|
|
633
|
+
next_action: "done",
|
|
634
|
+
reason: `The gate is green on answered findings no review verified (${gate.description}); the PR is ready to merge, or comment ${commandHint(REVIEW_COMMAND, "")} for another review.`,
|
|
635
|
+
};
|
|
636
|
+
}
|
|
637
|
+
return {
|
|
638
|
+
next_action: "done",
|
|
639
|
+
reason:
|
|
640
|
+
"The review on this head passed the gate, and every finding on this head has a reply.",
|
|
641
|
+
};
|
|
642
|
+
}
|
|
643
|
+
// failure: the blocking findings on this head decide between triage, fix, and override.
|
|
644
|
+
// G12, first: the gate is red because no review may run on this head (the automatic budget is
|
|
645
|
+
// used up, or the policy is manual_only). No push gets an automatic review there, so a fix cannot
|
|
646
|
+
// clear anything; the review the human asks for is the only unlock, whatever the summary's rows
|
|
647
|
+
// (from an older head) say (review #348 R006).
|
|
648
|
+
if (REVIEW_TRIGGER_GATE.test(canonicalStatusText(gate.description ?? ""))) {
|
|
649
|
+
return {
|
|
650
|
+
next_action: "review",
|
|
651
|
+
reason: `The automatic review budget for this PR is used up, or the review policy is manual (ci_review_policy is manual_only); comment ${commandHint(REVIEW_COMMAND, "")} to review this head.`,
|
|
652
|
+
};
|
|
653
|
+
}
|
|
654
|
+
// A row with no comment has no thread a triage reply could land in, so it is never "untriaged".
|
|
655
|
+
const untriaged = liveBlocking.filter(
|
|
656
|
+
(a) => a.finding.comment_id !== null && !a.triagedAtPostedHead,
|
|
657
|
+
);
|
|
658
|
+
if (untriaged.length > 0) {
|
|
659
|
+
return {
|
|
660
|
+
next_action: "triage",
|
|
661
|
+
reason: `${untriaged.length} live blocking finding(s) on this head have no triage reply at the head they were posted on; triage them first.`,
|
|
662
|
+
};
|
|
663
|
+
}
|
|
664
|
+
// WHY this precedes the upheld-dismissal review branch: a blocking row with no thread cannot be
|
|
665
|
+
// answered, and only a fix clears it. Answering review here would re-run a gate that still counts
|
|
666
|
+
// it, and the review never stops counting it (review #348 R001/R003).
|
|
667
|
+
// Only a gate that states a blocking count is the verdict of a review the summary's rows belong
|
|
668
|
+
// to. A skipped or partial gate reviewed nothing, and its rows may be an older head's, so it falls
|
|
669
|
+
// through to its own branches below (review #348 R006).
|
|
670
|
+
const unthreaded = liveBlocking.filter((a) => a.finding.comment_id === null);
|
|
671
|
+
if (unthreaded.length > 0 && gateBlockingCount(gate) !== null) {
|
|
672
|
+
const ids = unthreaded.map((a) => a.finding.id ?? "unnamed").join(", ");
|
|
673
|
+
return {
|
|
674
|
+
next_action: "fix",
|
|
675
|
+
reason: `${unthreaded.length} live blocking finding(s) (${ids}) have no comment thread to answer (summary-only or never posted inline); fix them and push, or ${commandHint(OVERRIDE_COMMAND, "")}.`,
|
|
676
|
+
};
|
|
677
|
+
}
|
|
678
|
+
const applied = liveBlocking.filter(
|
|
679
|
+
(a) => a.finding.triage?.tag === "applied",
|
|
680
|
+
);
|
|
681
|
+
if (applied.length > 0) {
|
|
682
|
+
// budget-exhausted-carry S3: a carried blocking red means a review rule skipped this head. The next push
|
|
683
|
+
// may be skipped too, and then the gate reads the replies instead of a review, but only every blocking
|
|
684
|
+
// finding answered unlocks it (answered-findings.ts), so the reason promises that only when it holds.
|
|
685
|
+
// A carried partial red is never unlocked by replies, so it keeps the plain reason.
|
|
686
|
+
if (
|
|
687
|
+
CARRIED_BLOCKING_GATE.test(canonicalStatusText(gate.description ?? ""))
|
|
688
|
+
) {
|
|
689
|
+
// The gate's own rules (admission.ts admissionSkipDecision, answered-findings.ts): a finding is
|
|
690
|
+
// answered only by its newest reply at the head it was posted on, and the gate must see at least as
|
|
691
|
+
// many blocking findings as the red counts. The stale-reply cutoff needs the carried verdict's time,
|
|
692
|
+
// which this read does not have, so the reason says the push can turn green, never that it will.
|
|
693
|
+
const open = liveBlocking.filter(
|
|
694
|
+
(a) =>
|
|
695
|
+
!(
|
|
696
|
+
(a.finding.triage?.tag === "applied" &&
|
|
697
|
+
a.finding.triage.head === a.finding.head) ||
|
|
698
|
+
upheldDismissal(a)
|
|
699
|
+
),
|
|
700
|
+
).length;
|
|
701
|
+
const counted = gateBlockingCount(gate);
|
|
702
|
+
const unseen =
|
|
703
|
+
counted === null ? 0 : Math.max(0, counted - liveBlocking.length);
|
|
704
|
+
return {
|
|
705
|
+
next_action: "fix",
|
|
706
|
+
reason:
|
|
707
|
+
open === 0 && unseen === 0
|
|
708
|
+
? "Every live blocking finding is answered and a review rule skipped this head; push the fix. If a rule skips that push too, the gate reads the replies on it and can turn green, marked unverified; otherwise the review verifies it."
|
|
709
|
+
: `A live blocking finding is tagged applied, but ${open + unseen} blocking finding(s) are still open (deferred, misclassified, a dismissal not upheld, a reply at another head, or one this read cannot see), so replies alone will not unlock the carried red; push the fix, and answer or fix the rest.`,
|
|
710
|
+
};
|
|
711
|
+
}
|
|
712
|
+
return {
|
|
713
|
+
next_action: "fix",
|
|
714
|
+
reason:
|
|
715
|
+
"A live blocking finding is tagged applied; push the fix, and the next review verifies it.",
|
|
716
|
+
};
|
|
717
|
+
}
|
|
718
|
+
// A dismissal leaves the count only on a CI ruling of "upheld" (src/triage/adjudication.ts). A
|
|
719
|
+
// dismissal with no ruling on this head, or an inconclusive one, is pending: recheck rules on it.
|
|
720
|
+
const dismissed = liveBlocking.filter(
|
|
721
|
+
(a) => a.finding.triage?.tag === "dismissed",
|
|
722
|
+
);
|
|
723
|
+
// Only an inline finding can get a CI ruling: the adjudicator answers on the finding's own review
|
|
724
|
+
// thread, and an outside-diff finding has none, so recheck would never settle it.
|
|
725
|
+
const pendingRulings = dismissed.filter(
|
|
726
|
+
(a) =>
|
|
727
|
+
a.finding.channel === "inline" &&
|
|
728
|
+
(a.finding.ci_verdict === null ||
|
|
729
|
+
a.finding.ci_verdict === "inconclusive"),
|
|
730
|
+
);
|
|
731
|
+
if (pendingRulings.length > 0) {
|
|
732
|
+
return {
|
|
733
|
+
next_action: "recheck",
|
|
734
|
+
reason: `${pendingRulings.length} live blocking finding(s) are answered dismissed with no CI ruling on this head (or an inconclusive one); comment ${commandHint(RECHECK_COMMAND, "")} so the CI adjudicator rules on them.`,
|
|
735
|
+
};
|
|
736
|
+
}
|
|
737
|
+
// WHY the gate's own count is checked too (review #348 F002): the gate can count a blocking
|
|
738
|
+
// finding this read cannot see (one rendered only in the summary). A review that already
|
|
739
|
+
// consumed the rulings leaves that one counted, and answering review again would loop.
|
|
740
|
+
const gateCount = gateBlockingCount(gate);
|
|
741
|
+
if (
|
|
742
|
+
dismissed.length > 0 &&
|
|
743
|
+
dismissed.length === liveBlocking.length &&
|
|
744
|
+
dismissed.every(upheldDismissal) &&
|
|
745
|
+
(gateCount === null || gateCount <= dismissed.length)
|
|
746
|
+
) {
|
|
747
|
+
return {
|
|
748
|
+
next_action: "review",
|
|
749
|
+
reason: `The CI adjudicator upheld every dismissal on this head; run ${commandHint(REVIEW_COMMAND, "")}, and that review no longer counts them.`,
|
|
750
|
+
};
|
|
751
|
+
}
|
|
752
|
+
if (
|
|
753
|
+
canonicalStatusText(gate.description ?? "").startsWith(
|
|
754
|
+
"crysk skipped the review",
|
|
755
|
+
)
|
|
756
|
+
) {
|
|
757
|
+
return {
|
|
758
|
+
next_action: "override-or-fix",
|
|
759
|
+
reason: `The review on this head was skipped (${gate.description}); run ${commandHint(REVIEW_COMMAND, "")} to review it anyway, or override the gate.`,
|
|
760
|
+
};
|
|
761
|
+
}
|
|
762
|
+
// S6: a red gate that is a partial review (its own text, or the carried form) is not a finding to fix.
|
|
763
|
+
// Nothing blocking was found, so the retry is the unlock. Its text is the gate's own, so no count is read.
|
|
764
|
+
if (
|
|
765
|
+
PARTIAL_REVIEW_AGAIN_GATE.test(canonicalStatusText(gate.description ?? ""))
|
|
766
|
+
) {
|
|
767
|
+
return {
|
|
768
|
+
next_action: "override-or-fix",
|
|
769
|
+
reason: `The review is partial again with the same hunters failing: a retry already failed the same way; fix the failing hunter's route (model or provider) or run ${commandHint(OVERRIDE_COMMAND, "")}.`,
|
|
770
|
+
};
|
|
771
|
+
}
|
|
772
|
+
if (PARTIAL_REVIEW_GATE.test(canonicalStatusText(gate.description ?? ""))) {
|
|
773
|
+
return {
|
|
774
|
+
next_action: "review",
|
|
775
|
+
reason: `The last review of this head was partial (some reviewers failed); run ${commandHint(REVIEW_COMMAND, "")}, which retries it. If the same reviewers fail every time (an unavailable model, a broken route), fix that route or override the gate.`,
|
|
776
|
+
};
|
|
777
|
+
}
|
|
778
|
+
if (liveBlocking.length > 0) {
|
|
779
|
+
return {
|
|
780
|
+
next_action: "override-or-fix",
|
|
781
|
+
reason: `The gate is red with ${liveBlocking.length} live blocking finding(s), all triaged and none applied or pending a CI ruling (a rejected dismissal, or a deferred or misclassified tag, never leaves the count): fix and push, or override the gate.`,
|
|
782
|
+
};
|
|
783
|
+
}
|
|
784
|
+
return {
|
|
785
|
+
next_action: "override-or-fix",
|
|
786
|
+
reason: `The gate is red and names no live blocking finding on this head (${gate.description ?? "no description"}); read the gate description.`,
|
|
787
|
+
};
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
// Pure predicate for `pr-hero status --pr <n> --wait`: whether the caller should keep polling
|
|
791
|
+
// for a review to start or finish before emitting the settled status.
|
|
792
|
+
export function shouldWaitPrStatus(input: {
|
|
793
|
+
status: PrStatusJson;
|
|
794
|
+
issueComments: PrStatusComment[];
|
|
795
|
+
nowMs: number;
|
|
796
|
+
elapsedMs: number;
|
|
797
|
+
startupGraceMs?: number;
|
|
798
|
+
}): boolean {
|
|
799
|
+
const { status, issueComments, nowMs, elapsedMs } = input;
|
|
800
|
+
const startupGraceMs = input.startupGraceMs ?? STATUS_WAIT_STARTUP_GRACE_MS;
|
|
801
|
+
|
|
802
|
+
if (status.next_action === "wait") return true;
|
|
803
|
+
|
|
804
|
+
// Fresh push: no status on this head yet, within the initial startup grace window.
|
|
805
|
+
if (status.gate.state === "none" && elapsedMs < startupGraceMs) {
|
|
806
|
+
return true;
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
// Fresh `/crysk review` or `/crysk recheck` comment: posted within the startup grace
|
|
810
|
+
// window, and no pr-hero commit status has been posted since that comment.
|
|
811
|
+
const gateMs =
|
|
812
|
+
status.gate.created_at !== null
|
|
813
|
+
? Date.parse(status.gate.created_at)
|
|
814
|
+
: Number.NEGATIVE_INFINITY;
|
|
815
|
+
|
|
816
|
+
for (const comment of issueComments) {
|
|
817
|
+
if (!TRIGGER_COMMANDS.some((command) => isCommand(comment.body, command))) {
|
|
818
|
+
continue;
|
|
819
|
+
}
|
|
820
|
+
if (comment.created_at === undefined) continue;
|
|
821
|
+
const commentMs = Date.parse(comment.created_at);
|
|
822
|
+
if (!Number.isFinite(commentMs)) continue;
|
|
823
|
+
const ageMs = nowMs - commentMs;
|
|
824
|
+
if (ageMs >= 0 && ageMs < startupGraceMs && commentMs > gateMs) {
|
|
825
|
+
return true;
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
return false;
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
// The human lines `pr-hero status` prints on stderr without --json. A renderer: it returns
|
|
833
|
+
// lines, never writes them, and carries no escape bytes (the caller styles nothing here).
|
|
834
|
+
export function renderPrStatusLines(status: PrStatusJson): string[] {
|
|
835
|
+
const gate =
|
|
836
|
+
status.gate.description === null
|
|
837
|
+
? status.gate.state
|
|
838
|
+
: `${status.gate.state} (${status.gate.description})`;
|
|
839
|
+
return [
|
|
840
|
+
`crysk status: PR #${status.pr} at ${status.head.slice(0, 7)}`,
|
|
841
|
+
`gate: ${gate}`,
|
|
842
|
+
`findings: ${status.findings.length} posted, ${status.unresolved_blocking} unresolved blocking`,
|
|
843
|
+
`next: ${status.next_action} — ${status.reason}`,
|
|
844
|
+
];
|
|
845
|
+
}
|