crysk 0.0.0-stage → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +176 -0
- package/README.md +610 -2
- package/bin/pr-hero.js +166 -0
- package/config/models/anthropic.json +5 -0
- package/dist/SKILL-7e3725zn.md +496 -0
- package/dist/SKILL-7q35wcaz.md +66 -0
- package/dist/SKILL-9at22381.md +74 -0
- package/dist/SKILL-ex2hxxh3.md +134 -0
- package/dist/adjudicator-dtg2axnh.md +86 -0
- package/dist/admission-config.example-a9vqmmad.json +9 -0
- package/dist/ci-admission-camfbx2b.md +122 -0
- package/dist/cli.js +42292 -0
- package/dist/consolidate-ac0mnfyj.md +24 -0
- package/dist/deep-review-lifecycle-m698ybjp.md +362 -0
- package/dist/deep-review-logic-a6b1gczf.md +156 -0
- package/dist/deep-review-parity-0ec904db.md +120 -0
- package/dist/deep-review-reliability-qyakbjb9.md +125 -0
- package/dist/deep-review-resilience-3tz8y26e.md +118 -0
- package/dist/index.js +20190 -0
- package/dist/opencode-ci-7b0be64p.md +141 -0
- package/dist/review-refuter-j4e9gezy.md +71 -0
- package/dist/scout-yvp153q7.md +140 -0
- package/dist/summarizer-zca44nxa.md +18 -0
- package/dist/workflow-w1g9szna.yml +151 -0
- package/package.json +82 -4
- package/prompts/consolidate.md +24 -0
- package/prompts/default/PROVENANCE.md +18 -0
- package/prompts/default/deep-review-lifecycle.md +362 -0
- package/prompts/default/deep-review-logic.md +156 -0
- package/prompts/default/deep-review-parity.md +120 -0
- package/prompts/default/deep-review-reliability.md +125 -0
- package/prompts/default/deep-review-resilience.md +118 -0
- package/prompts/default/review-refuter.md +71 -0
- package/prompts/scout.md +140 -0
- package/prompts/summarizer.md +18 -0
- package/skills/crysk/SKILL.md +74 -0
- package/skills/crysk-ci-setup/SKILL.md +134 -0
- package/skills/crysk-ci-setup/assets/admission-config.example.json +9 -0
- package/skills/crysk-ci-setup/assets/workflow.yml +151 -0
- package/skills/crysk-ci-setup/references/ci-admission.md +122 -0
- package/skills/crysk-ci-setup/references/opencode-ci.md +141 -0
- package/skills/crysk-loop/SKILL.md +496 -0
- package/skills/crysk-loop/adjudicator.md +86 -0
- package/skills/crysk-pr/SKILL.md +66 -0
- package/src/agent-env.ts +1084 -0
- package/src/asset-manifest.ts +83 -0
- package/src/assets.d.ts +6 -0
- package/src/assets.ts +183 -0
- package/src/brand-paths.ts +155 -0
- package/src/brand.ts +255 -0
- package/src/ci/admission-ledger.ts +350 -0
- package/src/ci/classify-error.ts +73 -0
- package/src/ci/cli-record.ts +271 -0
- package/src/ci/force-comment.ts +39 -0
- package/src/ci/gates.ts +923 -0
- package/src/ci/outcome.ts +2181 -0
- package/src/ci/override.ts +187 -0
- package/src/ci/publish.ts +1639 -0
- package/src/ci/reporter.ts +626 -0
- package/src/ci/review-admission.ts +901 -0
- package/src/ci/review-levels.ts +310 -0
- package/src/ci/review-policy.ts +18 -0
- package/src/ci/review-risk.ts +184 -0
- package/src/ci/setup.ts +844 -0
- package/src/ci/trigger.ts +1353 -0
- package/src/cli.ts +348 -0
- package/src/commands/activity.ts +67 -0
- package/src/commands/ci-setup-questions.ts +397 -0
- package/src/commands/ci-setup.ts +381 -0
- package/src/commands/config.ts +99 -0
- package/src/commands/doctor.ts +108 -0
- package/src/commands/init.ts +139 -0
- package/src/commands/mcp.ts +10 -0
- package/src/commands/menu.ts +129 -0
- package/src/commands/post.ts +302 -0
- package/src/commands/skills.ts +83 -0
- package/src/commands/status.ts +173 -0
- package/src/commands/triage.ts +342 -0
- package/src/commands/uninstall.ts +37 -0
- package/src/commands/upgrade.ts +214 -0
- package/src/commands/usage.ts +98 -0
- package/src/compare/compare.ts +28 -0
- package/src/compare/floor-test.ts +471 -0
- package/src/compare/martian-adapter.ts +80 -0
- package/src/config/config.ts +267 -0
- package/src/corpus/corpus.ts +1094 -0
- package/src/corpus/preflight.ts +1789 -0
- package/src/diversity/accounting.ts +90 -0
- package/src/diversity/adjudication.ts +145 -0
- package/src/diversity/admission.ts +60 -0
- package/src/diversity/benchmark.ts +195 -0
- package/src/diversity/clustering.ts +285 -0
- package/src/diversity/errors.ts +7 -0
- package/src/diversity/identity.ts +285 -0
- package/src/diversity/index.ts +11 -0
- package/src/diversity/pipeline-integration.ts +448 -0
- package/src/diversity/projection.ts +57 -0
- package/src/diversity/self-contained.ts +68 -0
- package/src/diversity/target-validation.ts +179 -0
- package/src/doctor-migration.ts +209 -0
- package/src/doctor.ts +723 -0
- package/src/errors.ts +83 -0
- package/src/execution/admission.ts +75 -0
- package/src/execution/atomic-write.ts +35 -0
- package/src/execution/attempt-evidence.ts +415 -0
- package/src/execution/bucket-id.ts +136 -0
- package/src/execution/concurrency-limiter.ts +175 -0
- package/src/execution/contracts.ts +443 -0
- package/src/execution/failure-classification.ts +42 -0
- package/src/execution/failure-policy.ts +240 -0
- package/src/execution/harness.ts +2548 -0
- package/src/execution/settlement.ts +348 -0
- package/src/execution/spawned-process.ts +66 -0
- package/src/execution/spend-limiter.ts +424 -0
- package/src/execution/step-artifacts.ts +55 -0
- package/src/execution/usage-normalized.ts +469 -0
- package/src/git/git.ts +396 -0
- package/src/git/identity.ts +64 -0
- package/src/git/refs.ts +140 -0
- package/src/home-preflight.ts +443 -0
- package/src/home.ts +243 -0
- package/src/ignore-file.ts +336 -0
- package/src/ignore-read.ts +118 -0
- package/src/index.ts +34 -0
- package/src/legacy-launchd.ts +29 -0
- package/src/mcp/mcp.ts +150 -0
- package/src/mcp/preflight.ts +407 -0
- package/src/menu-context.ts +192 -0
- package/src/model/catalog.ts +251 -0
- package/src/model/exec-snapshots.ts +390 -0
- package/src/model/free-discovery.ts +302 -0
- package/src/model/provider-capabilities.ts +814 -0
- package/src/model/routing.ts +600 -0
- package/src/pr/admission.ts +847 -0
- package/src/pr/ci-admission-gate.ts +665 -0
- package/src/pr/ci-publish.ts +76 -0
- package/src/pr/discovery.ts +432 -0
- package/src/pr/inline.ts +507 -0
- package/src/pr/plan.ts +366 -0
- package/src/pr/posting.ts +115 -0
- package/src/pr/pr-status.ts +787 -0
- package/src/pr/pr.ts +3642 -0
- package/src/pr/preflight.ts +1031 -0
- package/src/pr/publish-outcome.ts +361 -0
- package/src/pr/range.ts +119 -0
- package/src/pr/reverts-preflight.ts +606 -0
- package/src/pr/reverts.ts +377 -0
- package/src/pr/review-pr.ts +927 -0
- package/src/pr/status.ts +154 -0
- package/src/pr/target.ts +388 -0
- package/src/pr/teardown.ts +437 -0
- package/src/pr/worktree-setup.ts +60 -0
- package/src/production-runtime.ts +1877 -0
- package/src/progress.ts +487 -0
- package/src/rereview/adjudicate.ts +89 -0
- package/src/rereview/classify.ts +362 -0
- package/src/rereview/identity.ts +211 -0
- package/src/rereview/plan.ts +308 -0
- package/src/rereview/prepare.ts +1025 -0
- package/src/rereview/state.ts +767 -0
- package/src/rereview/verify.ts +241 -0
- package/src/review/boundary.ts +105 -0
- package/src/review/consolidate.ts +246 -0
- package/src/review/dedupe.ts +368 -0
- package/src/review/drafts.ts +448 -0
- package/src/review/findings-conformance.ts +120 -0
- package/src/review/findings.ts +714 -0
- package/src/review/pipeline.ts +3977 -0
- package/src/review/preflight.ts +3575 -0
- package/src/review/prompt-set.ts +177 -0
- package/src/review/proof-refs.ts +187 -0
- package/src/review/report.ts +1821 -0
- package/src/review/review.ts +490 -0
- package/src/review/root-cause.ts +120 -0
- package/src/review/route-preflight.ts +289 -0
- package/src/review/run.ts +601 -0
- package/src/review/scout.ts +323 -0
- package/src/review/size-gate.ts +595 -0
- package/src/review/spec.ts +235 -0
- package/src/review/step-runner.ts +233 -0
- package/src/runner-authority.ts +596 -0
- package/src/security/binding-policy.ts +115 -0
- package/src/security/credential-broker.ts +773 -0
- package/src/security/evidence-redaction.ts +62 -0
- package/src/security/execution-authority.ts +27 -0
- package/src/security/redact.ts +71 -0
- package/src/security/workspace-read-broker.ts +466 -0
- package/src/server/client.ts +190 -0
- package/src/server/preflight.ts +217 -0
- package/src/server/server.ts +327 -0
- package/src/signal-handler.ts +50 -0
- package/src/store/activity.ts +413 -0
- package/src/store/backfill-preflight.ts +49 -0
- package/src/store/backfill.ts +141 -0
- package/src/store/gc-preflight.ts +206 -0
- package/src/store/gc.ts +424 -0
- package/src/store/metrics-preflight.ts +229 -0
- package/src/store/metrics.ts +236 -0
- package/src/store/preflight.ts +748 -0
- package/src/store/store.ts +693 -0
- package/src/system-tools.ts +355 -0
- package/src/transport-registry.ts +1124 -0
- package/src/transports/claude-code-cli.ts +1348 -0
- package/src/transports/opencode-admission.ts +515 -0
- package/src/transports/opencode-client.ts +3328 -0
- package/src/transports/opencode-evidence.ts +557 -0
- package/src/transports/opencode-mcp.ts +248 -0
- package/src/transports/opencode-sdk.ts +2294 -0
- package/src/transports/opencode-server.ts +535 -0
- package/src/triage/adjudication.ts +113 -0
- package/src/triage/reply.ts +125 -0
- package/src/triage/triage.ts +255 -0
- package/src/ui/activity.ts +173 -0
- package/src/ui/config-edit.ts +816 -0
- package/src/ui/config.ts +462 -0
- package/src/ui/menu.ts +1325 -0
- package/src/ui/plan.ts +1039 -0
- package/src/ui/primitives.ts +300 -0
- package/src/ui/progress.ts +298 -0
- package/src/ui/result.ts +552 -0
- package/src/ui/review-menu.ts +312 -0
- package/src/ui/select.ts +528 -0
- package/src/ui/tree.ts +178 -0
- package/src/uninstaller.ts +479 -0
- package/src/updater.ts +836 -0
- package/src/usage.ts +77 -0
- package/src/watch/preflight.ts +1389 -0
- package/src/watch/watch.ts +1235 -0
- package/src/wizard.ts +877 -0
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
// Phase B prior classification for item 7 (`docs/item7-rereview-design.md` §3.3).
|
|
2
|
+
// Pure: git facts + recovered triage in, a status or a verify-queue entry out.
|
|
3
|
+
// No LLM, no I/O. Phase E (overlap / worsening) and phase F (verdicts) are
|
|
4
|
+
// separate — this module only settles what the design says settles before
|
|
5
|
+
// hunters run, and queues the rest.
|
|
6
|
+
//
|
|
7
|
+
// Precedence is ordered rules, not first-match-wins rows. Rename rewrites
|
|
8
|
+
// paths and re-enters at rule 1 (R2-C1); triage outranks touched (O-3);
|
|
9
|
+
// `resolved` is never inferred from absence (C1).
|
|
10
|
+
|
|
11
|
+
import type { Severity, Tier } from "#review/findings";
|
|
12
|
+
import type { AdjudicationVerdict } from "#triage/adjudication";
|
|
13
|
+
import type { TriageTag, TriageVerdict } from "#triage/triage";
|
|
14
|
+
import {
|
|
15
|
+
type FindingIdentity,
|
|
16
|
+
formatLocs,
|
|
17
|
+
identitiesMatch,
|
|
18
|
+
identityFromFinding,
|
|
19
|
+
identityFromLocs,
|
|
20
|
+
mapIdentityPaths,
|
|
21
|
+
} from "./identity";
|
|
22
|
+
|
|
23
|
+
// #206: a re-review whose posted priors have no readable `pr-hero-state`
|
|
24
|
+
// block (routine, not rare — a FIRST review never writes one at all, see
|
|
25
|
+
// `postInlineFindings`'s `framing === undefined` branch in src/pr/pr.ts,
|
|
26
|
+
// so EVERY PR's second review takes this path) used to invent
|
|
27
|
+
// `sev: "WARNING"` / `tier: "advisory"` for every carried prior — the exact
|
|
28
|
+
// silent downgrade the headline's severity-not-tier design (report.ts)
|
|
29
|
+
// exists to prevent. These sentinels let a prior say "I could not recover
|
|
30
|
+
// this field" without pretending it is a real Severity/Tier: a consumer
|
|
31
|
+
// that still switches on the 4/2 real values keeps its old exhaustive
|
|
32
|
+
// behavior, and every place this sentinel newly reaches (verify-queue
|
|
33
|
+
// priority, worsening, CI admission scoring, the headline count) fails
|
|
34
|
+
// toward VISIBILITY instead of toward the wrong bucket. Deliberately local
|
|
35
|
+
// sentinels, not a widened `Severity`/`Tier` — those two stay exactly what
|
|
36
|
+
// the lab's `Finding` schema expects (project rule 5, schema compatibility
|
|
37
|
+
// is sacred); this is pr-hero's own internal PR-comment bookkeeping, never
|
|
38
|
+
// read by the lab's scorer.
|
|
39
|
+
export const SEVERITY_UNRECOVERABLE = "UNRECOVERABLE" as const;
|
|
40
|
+
export type RecoveredSeverity = Severity | typeof SEVERITY_UNRECOVERABLE;
|
|
41
|
+
|
|
42
|
+
export const TIER_UNRECOVERABLE = "unrecoverable" as const;
|
|
43
|
+
export type RecoveredTier = Tier | typeof TIER_UNRECOVERABLE;
|
|
44
|
+
|
|
45
|
+
export function isRecoveredSeverity(
|
|
46
|
+
value: unknown,
|
|
47
|
+
): value is RecoveredSeverity {
|
|
48
|
+
return (
|
|
49
|
+
value === "BLOCKER" ||
|
|
50
|
+
value === "CRITICAL" ||
|
|
51
|
+
value === "WARNING" ||
|
|
52
|
+
value === "SUGGESTION" ||
|
|
53
|
+
value === SEVERITY_UNRECOVERABLE
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function isRecoveredTier(value: unknown): value is RecoveredTier {
|
|
58
|
+
return (
|
|
59
|
+
value === "blocking" || value === "advisory" || value === TIER_UNRECOVERABLE
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export type RereviewCase = "A" | "B" | "C" | "D" | "E";
|
|
64
|
+
|
|
65
|
+
export type GateStatus =
|
|
66
|
+
| "carried"
|
|
67
|
+
| "verified-gone"
|
|
68
|
+
| "unconfirmed"
|
|
69
|
+
| "suppressed"
|
|
70
|
+
| "deferred"
|
|
71
|
+
| "returned"
|
|
72
|
+
| "re-tiered"
|
|
73
|
+
| "queued"
|
|
74
|
+
// T5b: the author's latest dismissal, upheld by the CI adjudicator
|
|
75
|
+
// (src/triage/adjudication.ts). The one triage outcome that leaves the gate count.
|
|
76
|
+
| "ci-dismissed";
|
|
77
|
+
|
|
78
|
+
export type VerifyTrigger =
|
|
79
|
+
| "applied"
|
|
80
|
+
| "touched"
|
|
81
|
+
| "overlap"
|
|
82
|
+
| "verify_all"
|
|
83
|
+
| "case_b_reply";
|
|
84
|
+
|
|
85
|
+
export type FindingChannel = "inline" | "outside";
|
|
86
|
+
|
|
87
|
+
export interface PriorTriage {
|
|
88
|
+
tag: TriageTag;
|
|
89
|
+
// `applied` carries no adjudicator verdict (`src/triage/triage.ts` ADJUDICATED_TAGS).
|
|
90
|
+
verdict: TriageVerdict | null;
|
|
91
|
+
// ISO-8601 from GitHub. Null means we cannot prove newness (R2-S9).
|
|
92
|
+
createdAt: string | null;
|
|
93
|
+
// T5b: the reply that carried this marker, the finding's thread it sits on, the
|
|
94
|
+
// author's argument (the reply body below the marker line), and the CI verdict on
|
|
95
|
+
// THIS reply, read only from a CI_ADJUDICATOR_LOGIN reply. Absent on a triage read
|
|
96
|
+
// from anywhere but a thread.
|
|
97
|
+
replyId?: number;
|
|
98
|
+
threadId?: number;
|
|
99
|
+
argument?: string;
|
|
100
|
+
ciVerdict?: AdjudicationVerdict | null;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export interface PriorRecord {
|
|
104
|
+
id: string;
|
|
105
|
+
sev: RecoveredSeverity;
|
|
106
|
+
tier: RecoveredTier;
|
|
107
|
+
channel: FindingChannel;
|
|
108
|
+
locs: readonly string[];
|
|
109
|
+
claim: string;
|
|
110
|
+
triage: PriorTriage | null;
|
|
111
|
+
// Case B rule 7b: any new reply on the prior thread, including tags
|
|
112
|
+
// other than a newly-applied `applied` (that one is rule 7).
|
|
113
|
+
newThreadReply: boolean;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export interface PhaseBContext {
|
|
117
|
+
case: RereviewCase;
|
|
118
|
+
deletedFiles: ReadonlySet<string>;
|
|
119
|
+
renameMap: ReadonlyMap<string, string>;
|
|
120
|
+
touched: (identity: FindingIdentity) => boolean;
|
|
121
|
+
summaryUpdatedAt: string | null;
|
|
122
|
+
// Rereview-coverage fix wiring gap:
|
|
123
|
+
// `DiscoveryPlan.verifyAll` (rereview/plan.ts) was
|
|
124
|
+
// computed for every case but never READ by any production code — this
|
|
125
|
+
// function forced verify_all purely off `case === "D" || "E"`, and
|
|
126
|
+
// buildPhaseBQueue (rereview/prepare.ts) passed it only `case`, never the
|
|
127
|
+
// plan. That made `planDiscovery`'s `verifyAll: true` for a forced-full
|
|
128
|
+
// case B/C (an incomplete prior run) a silent no-op: the refuter-failed
|
|
129
|
+
// prior would stay merely `carried` (case B's empty L===H nameStatus never
|
|
130
|
+
// touches anything) or `queued: touched` at best (case C) — never
|
|
131
|
+
// `verify_all`. This field closes that gap: `true` forces verify_all
|
|
132
|
+
// exactly like case D/E do, for ANY case, so a forced-full re-review
|
|
133
|
+
// actually re-verifies every prior instead of trusting them unexamined.
|
|
134
|
+
verifyAll?: boolean;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// The triage settlements a verification can hold (see `held` below).
|
|
138
|
+
export type HeldStatus = "returned" | "suppressed" | "deferred" | "re-tiered";
|
|
139
|
+
|
|
140
|
+
export interface PhaseBResult {
|
|
141
|
+
id: string;
|
|
142
|
+
status: GateStatus;
|
|
143
|
+
locs: string[];
|
|
144
|
+
renamed: boolean;
|
|
145
|
+
trigger?: VerifyTrigger;
|
|
146
|
+
// WHY `held`: a triage settlement a push that touched the finding's code, or a
|
|
147
|
+
// verify-all case, must not settle on the triage alone. The prior is queued
|
|
148
|
+
// (status `queued`) and this field keeps what the triage would have said. The
|
|
149
|
+
// verifier's verdict then decides: `verified-gone` when the finding is refuted,
|
|
150
|
+
// this status otherwise (assembleLive in rereview/state.ts). Absent on every
|
|
151
|
+
// row that the triage did not decide.
|
|
152
|
+
held?: HeldStatus;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export function classifyPrior(
|
|
156
|
+
prior: PriorRecord,
|
|
157
|
+
ctx: PhaseBContext,
|
|
158
|
+
): PhaseBResult {
|
|
159
|
+
const original = identityFromLocs(prior.locs);
|
|
160
|
+
const rewritten = mapIdentityPaths(
|
|
161
|
+
original,
|
|
162
|
+
(path) => ctx.renameMap.get(path) ?? path,
|
|
163
|
+
);
|
|
164
|
+
const locs = formatLocs(rewritten);
|
|
165
|
+
const renamed = formatLocs(original).join("\0") !== locs.join("\0");
|
|
166
|
+
|
|
167
|
+
if (everyFileDeleted(rewritten, ctx.deletedFiles)) {
|
|
168
|
+
return { id: prior.id, status: "verified-gone", locs, renamed };
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const triage = prior.triage;
|
|
172
|
+
// D5: only a dismissal the CI adjudicator upheld leaves the count.
|
|
173
|
+
if (triage?.tag === "dismissed" && triage.ciVerdict === "upheld") {
|
|
174
|
+
return { id: prior.id, status: "ci-dismissed", locs, renamed };
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// WHY a triage settlement is queued, not returned: the author's dismissal,
|
|
178
|
+
// deferral or misclassification was made against the code as it was. A push
|
|
179
|
+
// that touched the finding's code, or a verify-all case, is the moment the
|
|
180
|
+
// finding can be fixed, and only the verifier can see that. Without this the
|
|
181
|
+
// gate counted a fixed finding forever (its triage row never reached verify).
|
|
182
|
+
// The verifier's answer decides in assembleLive: gone leaves the count, any
|
|
183
|
+
// other answer settles back to the held status.
|
|
184
|
+
const held = triageHeldStatus(triage);
|
|
185
|
+
if (held !== undefined) {
|
|
186
|
+
if (ctx.case === "D" || ctx.case === "E" || ctx.verifyAll === true) {
|
|
187
|
+
return {
|
|
188
|
+
id: prior.id,
|
|
189
|
+
status: "queued",
|
|
190
|
+
locs,
|
|
191
|
+
renamed,
|
|
192
|
+
trigger: "verify_all",
|
|
193
|
+
held,
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
if (ctx.touched(rewritten)) {
|
|
197
|
+
return {
|
|
198
|
+
id: prior.id,
|
|
199
|
+
status: "queued",
|
|
200
|
+
locs,
|
|
201
|
+
renamed,
|
|
202
|
+
trigger: "touched",
|
|
203
|
+
held,
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
return { id: prior.id, status: held, locs, renamed };
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
if (ctx.case === "D" || ctx.case === "E" || ctx.verifyAll === true) {
|
|
210
|
+
return {
|
|
211
|
+
id: prior.id,
|
|
212
|
+
status: "queued",
|
|
213
|
+
locs,
|
|
214
|
+
renamed,
|
|
215
|
+
trigger: "verify_all",
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
if (triage?.tag === "applied" && appliedBuysVerify(triage, ctx)) {
|
|
220
|
+
return {
|
|
221
|
+
id: prior.id,
|
|
222
|
+
status: "queued",
|
|
223
|
+
locs,
|
|
224
|
+
renamed,
|
|
225
|
+
trigger: "applied",
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (ctx.case === "B" && prior.newThreadReply) {
|
|
230
|
+
return {
|
|
231
|
+
id: prior.id,
|
|
232
|
+
status: "queued",
|
|
233
|
+
locs,
|
|
234
|
+
renamed,
|
|
235
|
+
trigger: "case_b_reply",
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
if (ctx.touched(rewritten)) {
|
|
240
|
+
return {
|
|
241
|
+
id: prior.id,
|
|
242
|
+
status: "queued",
|
|
243
|
+
locs,
|
|
244
|
+
renamed,
|
|
245
|
+
trigger: "touched",
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
return { id: prior.id, status: "carried", locs, renamed };
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function triageHeldStatus(triage: PriorTriage | null): HeldStatus | undefined {
|
|
253
|
+
if (triage?.tag === "dismissed" && triage.verdict === "upheld") {
|
|
254
|
+
return "suppressed";
|
|
255
|
+
}
|
|
256
|
+
if (triage?.tag === "dismissed" && triage.verdict === "rejected") {
|
|
257
|
+
return "returned";
|
|
258
|
+
}
|
|
259
|
+
if (triage?.tag === "deferred") return "deferred";
|
|
260
|
+
if (triage?.tag === "misclassified") return "re-tiered";
|
|
261
|
+
return undefined;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
function everyFileDeleted(
|
|
265
|
+
identity: FindingIdentity,
|
|
266
|
+
deletedFiles: ReadonlySet<string>,
|
|
267
|
+
): boolean {
|
|
268
|
+
if (identity.size === 0) return false;
|
|
269
|
+
for (const path of identity.keys()) {
|
|
270
|
+
if (!deletedFiles.has(path)) return false;
|
|
271
|
+
}
|
|
272
|
+
return true;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
function appliedBuysVerify(triage: PriorTriage, ctx: PhaseBContext): boolean {
|
|
276
|
+
if (ctx.case !== "B") return true;
|
|
277
|
+
return isNewReply(triage.createdAt, ctx.summaryUpdatedAt);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
function isNewReply(
|
|
281
|
+
createdAt: string | null,
|
|
282
|
+
summaryUpdatedAt: string | null,
|
|
283
|
+
): boolean {
|
|
284
|
+
if (createdAt === null || summaryUpdatedAt === null) return false;
|
|
285
|
+
return createdAt > summaryUpdatedAt;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
const SEV_RANK: Record<Severity, number> = {
|
|
289
|
+
BLOCKER: 0,
|
|
290
|
+
CRITICAL: 1,
|
|
291
|
+
WARNING: 2,
|
|
292
|
+
SUGGESTION: 3,
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
export function isStrictlyHigherSev(
|
|
296
|
+
discovery: Severity,
|
|
297
|
+
prior: RecoveredSeverity,
|
|
298
|
+
): boolean {
|
|
299
|
+
// An unrecoverable prior severity must not silently rank as "already
|
|
300
|
+
// severe enough to stay suppressed" — #206's whole point is that an
|
|
301
|
+
// unknown severity fails toward being LOOKED AT again, never toward
|
|
302
|
+
// staying quiet. Any real rediscovery counts as strictly higher than
|
|
303
|
+
// "unknown", the same "direction of error stays under-match" bias
|
|
304
|
+
// `bindPriorsToPosted` (rereview/prepare.ts) already documents.
|
|
305
|
+
if (prior === SEVERITY_UNRECOVERABLE) return true;
|
|
306
|
+
return SEV_RANK[discovery] < SEV_RANK[prior];
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
export interface WorseningHit {
|
|
310
|
+
priorId: string;
|
|
311
|
+
priorSev: RecoveredSeverity;
|
|
312
|
+
discoverySev: Severity;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
// Phase E: a suppressed prior stays suppressed against a same-or-lower
|
|
316
|
+
// discovery finding, and RETURNS against a strictly-higher one (W-worse).
|
|
317
|
+
export function applyWorsening(input: {
|
|
318
|
+
settled: readonly PhaseBResult[];
|
|
319
|
+
priors: readonly PriorRecord[];
|
|
320
|
+
survivors: readonly {
|
|
321
|
+
path: string;
|
|
322
|
+
line: number;
|
|
323
|
+
proof_refs: readonly string[];
|
|
324
|
+
severity: Severity;
|
|
325
|
+
}[];
|
|
326
|
+
}): { settled: PhaseBResult[]; hits: WorseningHit[] } {
|
|
327
|
+
const priorById = new Map(input.priors.map((prior) => [prior.id, prior]));
|
|
328
|
+
const hits: WorseningHit[] = [];
|
|
329
|
+
const settled = input.settled.map((row) => {
|
|
330
|
+
// A held suppressed row is queued, so it is worsened in place: it stays
|
|
331
|
+
// queued for its verification and holds `returned` instead.
|
|
332
|
+
const heldSuppressed = row.status === "queued" && row.held === "suppressed";
|
|
333
|
+
if (row.status !== "suppressed" && !heldSuppressed) return row;
|
|
334
|
+
const prior = priorById.get(row.id);
|
|
335
|
+
if (prior === undefined) return row;
|
|
336
|
+
const ident = identityFromLocs(row.locs);
|
|
337
|
+
for (const survivor of input.survivors) {
|
|
338
|
+
if (
|
|
339
|
+
!identitiesMatch(
|
|
340
|
+
ident,
|
|
341
|
+
identityFromFinding({
|
|
342
|
+
path: survivor.path,
|
|
343
|
+
line: survivor.line,
|
|
344
|
+
proof_refs: survivor.proof_refs,
|
|
345
|
+
}),
|
|
346
|
+
)
|
|
347
|
+
) {
|
|
348
|
+
continue;
|
|
349
|
+
}
|
|
350
|
+
if (!isStrictlyHigherSev(survivor.severity, prior.sev)) continue;
|
|
351
|
+
hits.push({
|
|
352
|
+
priorId: row.id,
|
|
353
|
+
priorSev: prior.sev,
|
|
354
|
+
discoverySev: survivor.severity,
|
|
355
|
+
});
|
|
356
|
+
if (heldSuppressed) return { ...row, held: "returned" as const };
|
|
357
|
+
return { ...row, status: "returned" as const };
|
|
358
|
+
}
|
|
359
|
+
return row;
|
|
360
|
+
});
|
|
361
|
+
return { settled, hits };
|
|
362
|
+
}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
// Cross-run finding identity for item 7 (`docs/item7-rereview-design.md` §3.5).
|
|
2
|
+
// Pure: unordered set of normalized proof-ref locations, plus the finding's
|
|
3
|
+
// own path:line as an always-present anchor. Invalid / non-path:line refs
|
|
4
|
+
// are dropped (S10); a finding with nothing left after the drop still has
|
|
5
|
+
// the anchor, so it never becomes the empty set.
|
|
6
|
+
//
|
|
7
|
+
// WHY a new module and not MatchResult / claimFingerprint / root_cause_id:
|
|
8
|
+
// musive PR 1759, two auto-launched runs 16 minutes apart on a byte-identical
|
|
9
|
+
// tree, paired none of those keys and would have reported `Δ 2 resolved`
|
|
10
|
+
// against zero commits (§0.6). The unordered set of locations is what
|
|
11
|
+
// survived the producer/consumer flip.
|
|
12
|
+
//
|
|
13
|
+
// Direction of error is under-match (S1, same posture as review/root-cause.ts:60-70).
|
|
14
|
+
// A missed pairing costs a verification step or a visible duplicate; an
|
|
15
|
+
// over-match can hide a live defect behind `carried`.
|
|
16
|
+
|
|
17
|
+
import { normalizePath } from "#compare/compare";
|
|
18
|
+
import { extractAnchor } from "#review/root-cause";
|
|
19
|
+
|
|
20
|
+
// Same number as `FINDING_LINE_WINDOW` in pr/inline.ts. The posting matcher and
|
|
21
|
+
// this identity layer MUST NOT drift: the design names that constant as the
|
|
22
|
+
// span window (§3.5). A test in test/rereview/identity.test.ts pins the equality.
|
|
23
|
+
// Widening either independently is the size-gate 1500→2500→1500 arc.
|
|
24
|
+
export const IDENTITY_LINE_WINDOW = 5;
|
|
25
|
+
|
|
26
|
+
export interface LineSpan {
|
|
27
|
+
start: number;
|
|
28
|
+
end: number;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface IdentityLoc {
|
|
32
|
+
path: string;
|
|
33
|
+
span: LineSpan;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export type FindingIdentity = ReadonlyMap<string, readonly LineSpan[]>;
|
|
37
|
+
|
|
38
|
+
export interface IdentityInput {
|
|
39
|
+
path: string;
|
|
40
|
+
line: number;
|
|
41
|
+
proof_refs: readonly string[];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const LINE_SPEC = /^(\d+)(?:-(\d+))?$/;
|
|
45
|
+
|
|
46
|
+
// One proof_ref may name several spans on the same path (`path.ts:64,78-90`).
|
|
47
|
+
// `pr/inline.ts`'s parseProofRefLines rejects the comma form; identity cannot,
|
|
48
|
+
// because the PR 1759 pair's defect A is stored that way.
|
|
49
|
+
export function parseProofRefLocs(ref: string): IdentityLoc[] {
|
|
50
|
+
const anchor = extractAnchor([ref]);
|
|
51
|
+
if (anchor === null) return [];
|
|
52
|
+
const colon = anchor.lastIndexOf(":");
|
|
53
|
+
const path = normalizePath(anchor.slice(0, colon));
|
|
54
|
+
if (path.length === 0) return [];
|
|
55
|
+
const specs = anchor.slice(colon + 1).split(",");
|
|
56
|
+
const locs: IdentityLoc[] = [];
|
|
57
|
+
for (const spec of specs) {
|
|
58
|
+
const match = LINE_SPEC.exec(spec);
|
|
59
|
+
if (match?.[1] === undefined) continue;
|
|
60
|
+
const start = Number(match[1]);
|
|
61
|
+
const end = match[2] === undefined ? start : Number(match[2]);
|
|
62
|
+
if (!Number.isInteger(start) || !Number.isInteger(end) || end < start) {
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
locs.push({ path, span: { start, end } });
|
|
66
|
+
}
|
|
67
|
+
return locs;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function identityFromFinding(finding: IdentityInput): FindingIdentity {
|
|
71
|
+
const locs: IdentityLoc[] = [];
|
|
72
|
+
for (const ref of finding.proof_refs) {
|
|
73
|
+
locs.push(...parseProofRefLocs(ref));
|
|
74
|
+
}
|
|
75
|
+
locs.push({
|
|
76
|
+
path: normalizePath(finding.path),
|
|
77
|
+
span: { start: finding.line, end: finding.line },
|
|
78
|
+
});
|
|
79
|
+
return groupByPath(locs);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// State-block `locs` are already `path:line` / `path:start-end` tokens, but
|
|
83
|
+
// a hunter-shaped `path:64,78-90 (prose)` must parse the same way on both
|
|
84
|
+
// sides of a round-trip.
|
|
85
|
+
export function identityFromLocs(locs: readonly string[]): FindingIdentity {
|
|
86
|
+
const parsed: IdentityLoc[] = [];
|
|
87
|
+
for (const loc of locs) parsed.push(...parseProofRefLocs(loc));
|
|
88
|
+
return groupByPath(parsed);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function mapIdentityPaths(
|
|
92
|
+
identity: FindingIdentity,
|
|
93
|
+
rewrite: (path: string) => string,
|
|
94
|
+
): FindingIdentity {
|
|
95
|
+
const locs: IdentityLoc[] = [];
|
|
96
|
+
for (const [path, spans] of identity) {
|
|
97
|
+
const next = rewrite(path);
|
|
98
|
+
for (const span of spans) locs.push({ path: next, span });
|
|
99
|
+
}
|
|
100
|
+
return groupByPath(locs);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function formatLocs(identity: FindingIdentity): string[] {
|
|
104
|
+
const out: string[] = [];
|
|
105
|
+
const paths = [...identity.keys()].sort();
|
|
106
|
+
for (const path of paths) {
|
|
107
|
+
const spans = identity.get(path);
|
|
108
|
+
if (spans === undefined) continue;
|
|
109
|
+
for (const span of spans) {
|
|
110
|
+
out.push(
|
|
111
|
+
span.start === span.end
|
|
112
|
+
? `${path}:${span.start}`
|
|
113
|
+
: `${path}:${span.start}-${span.end}`,
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return out;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export function identitiesMatch(
|
|
121
|
+
a: FindingIdentity,
|
|
122
|
+
b: FindingIdentity,
|
|
123
|
+
window: number = IDENTITY_LINE_WINDOW,
|
|
124
|
+
): boolean {
|
|
125
|
+
const pa = new Set(a.keys());
|
|
126
|
+
const pb = new Set(b.keys());
|
|
127
|
+
const equal = setsEqual(pa, pb);
|
|
128
|
+
const containment =
|
|
129
|
+
pa.size > 1 && pb.size > 1 && (isSubset(pa, pb) || isSubset(pb, pa));
|
|
130
|
+
if (!equal && !containment) return false;
|
|
131
|
+
const shared = equal ? pa : intersect(pa, pb);
|
|
132
|
+
for (const path of shared) {
|
|
133
|
+
const as = a.get(path);
|
|
134
|
+
const bs = b.get(path);
|
|
135
|
+
if (as === undefined || bs === undefined) return false;
|
|
136
|
+
if (!spansOverlapOrNear(as, bs, window)) return false;
|
|
137
|
+
}
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export function findingsMatch(
|
|
142
|
+
a: IdentityInput,
|
|
143
|
+
b: IdentityInput,
|
|
144
|
+
window?: number,
|
|
145
|
+
): boolean {
|
|
146
|
+
return identitiesMatch(
|
|
147
|
+
identityFromFinding(a),
|
|
148
|
+
identityFromFinding(b),
|
|
149
|
+
window,
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function groupByPath(locs: readonly IdentityLoc[]): FindingIdentity {
|
|
154
|
+
const grouped = new Map<string, LineSpan[]>();
|
|
155
|
+
for (const loc of locs) {
|
|
156
|
+
const existing = grouped.get(loc.path);
|
|
157
|
+
if (existing === undefined) {
|
|
158
|
+
grouped.set(loc.path, [loc.span]);
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
if (
|
|
162
|
+
existing.some(
|
|
163
|
+
(span) => span.start === loc.span.start && span.end === loc.span.end,
|
|
164
|
+
)
|
|
165
|
+
) {
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
existing.push(loc.span);
|
|
169
|
+
}
|
|
170
|
+
for (const spans of grouped.values()) {
|
|
171
|
+
spans.sort((x, y) => x.start - y.start || x.end - y.end);
|
|
172
|
+
}
|
|
173
|
+
return grouped;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function spansOverlapOrNear(
|
|
177
|
+
as: readonly LineSpan[],
|
|
178
|
+
bs: readonly LineSpan[],
|
|
179
|
+
window: number,
|
|
180
|
+
): boolean {
|
|
181
|
+
for (const a of as) {
|
|
182
|
+
for (const b of bs) {
|
|
183
|
+
if (spanDistance(a, b) <= window) return true;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function spanDistance(a: LineSpan, b: LineSpan): number {
|
|
190
|
+
if (a.end >= b.start && b.end >= a.start) return 0;
|
|
191
|
+
if (a.end < b.start) return b.start - a.end;
|
|
192
|
+
return a.start - b.end;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function setsEqual(a: Set<string>, b: Set<string>): boolean {
|
|
196
|
+
if (a.size !== b.size) return false;
|
|
197
|
+
for (const v of a) if (!b.has(v)) return false;
|
|
198
|
+
return true;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function isSubset(a: Set<string>, b: Set<string>): boolean {
|
|
202
|
+
if (a.size > b.size) return false;
|
|
203
|
+
for (const v of a) if (!b.has(v)) return false;
|
|
204
|
+
return true;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function intersect(a: Set<string>, b: Set<string>): Set<string> {
|
|
208
|
+
const out = new Set<string>();
|
|
209
|
+
for (const v of a) if (b.has(v)) out.add(v);
|
|
210
|
+
return out;
|
|
211
|
+
}
|