crysk 0.3.3 → 0.4.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/dist/SKILL-dsnffnfp.md +140 -0
- package/dist/SKILL-gnrbph72.md +140 -0
- package/dist/SKILL-kq0xejn3.md +553 -0
- package/dist/SKILL-qaqsbygw.md +66 -0
- package/dist/SKILL-vws0aqb8.md +553 -0
- package/dist/ci-admission-t0f5qwth.md +128 -0
- package/dist/cli.js +408 -155
- package/dist/index.js +151 -20
- package/package.json +2 -2
- package/skills/crysk-ci-setup/SKILL.md +1 -1
- package/skills/crysk-ci-setup/references/ci-admission.md +1 -1
- package/skills/crysk-loop/SKILL.md +19 -8
- package/skills/crysk-pr/SKILL.md +1 -1
- package/src/assets.ts +2 -2
- package/src/ci/gates.ts +9 -6
- package/src/ci/platform-config.ts +127 -0
- package/src/ci/platform-report.ts +702 -0
- package/src/ci/platform.ts +449 -0
- package/src/ci/reporter.ts +9 -7
- package/src/ci/review-admission.ts +8 -4
- package/src/ci/setup.ts +112 -9
- package/src/compare/loop.ts +9 -1
- package/src/compare/martian-adapter.ts +1 -1
- package/src/index.ts +1 -1
- package/src/pr/admission.ts +53 -11
- package/src/pr/ci-admission-gate.ts +2 -1
- package/src/pr/finding-state-record.ts +58 -0
- package/src/pr/gate-record.ts +22 -0
- package/src/pr/inline.ts +3 -0
- package/src/pr/posting.ts +4 -0
- package/src/pr/pr-status.ts +27 -7
- package/src/pr/pr.ts +39 -8
- package/src/pr/preflight.ts +43 -1
- package/src/pr/publish-outcome.ts +10 -2
- package/src/pr/review-pr.ts +5 -3
- package/src/rereview/classify.ts +4 -0
- package/src/rereview/prepare.ts +47 -22
- package/src/rereview/state.ts +34 -8
- package/src/review/report.ts +34 -14
- package/src/security/published-text.ts +161 -0
- package/src/triage/triage.ts +2 -1
- package/src/updater.ts +1 -1
package/src/pr/pr.ts
CHANGED
|
@@ -74,6 +74,7 @@ import {
|
|
|
74
74
|
WORKFLOW_FILE_NAME,
|
|
75
75
|
} from "../brand";
|
|
76
76
|
import { CliError } from "../errors";
|
|
77
|
+
import { buildFindingStateRecord } from "./finding-state-record";
|
|
77
78
|
import {
|
|
78
79
|
buildPostPlan,
|
|
79
80
|
computeDroppedFindingIds,
|
|
@@ -1310,7 +1311,7 @@ const PR_ISSUE_COMMENTS_QUERY =
|
|
|
1310
1311
|
"repository(owner:$repoOwner,name:$repoName){pullRequest(number:$number){" +
|
|
1311
1312
|
"comments(first:100,after:$cursor){" +
|
|
1312
1313
|
"pageInfo{endCursor hasNextPage}" +
|
|
1313
|
-
"nodes{databaseId body createdAt updatedAt author{login}}}}}}";
|
|
1314
|
+
"nodes{databaseId body createdAt updatedAt author{login __typename}}}}}}";
|
|
1314
1315
|
|
|
1315
1316
|
const PR_REVIEW_COMMENTS_QUERY =
|
|
1316
1317
|
"query($repoOwner:String!,$repoName:String!,$number:Int!,$cursor:String){" +
|
|
@@ -1609,7 +1610,7 @@ function issueCommentsFromNodes(nodes: unknown[]): {
|
|
|
1609
1610
|
if (id === null) continue;
|
|
1610
1611
|
comments.push({
|
|
1611
1612
|
id,
|
|
1612
|
-
user:
|
|
1613
|
+
user: graphqlReviewLogin(record.author),
|
|
1613
1614
|
body: typeof record.body === "string" ? record.body : "",
|
|
1614
1615
|
...(typeof record.createdAt === "string"
|
|
1615
1616
|
? { created_at: record.createdAt }
|
|
@@ -3133,31 +3134,48 @@ export async function postInlineFindings(input: {
|
|
|
3133
3134
|
// WHY one merge function for both writes: the S1 re-merge reruns it with a
|
|
3134
3135
|
// PATCH-sized budget and the SAME inputs, so the kept ids and hw cannot
|
|
3135
3136
|
// drift between the POST and the PATCH.
|
|
3137
|
+
// WHY a first review writes the block too: an outside-diff finding has no
|
|
3138
|
+
// comment of its own, so the block is its only machine-readable copy. A
|
|
3139
|
+
// first review without one left `crysk status` blind to those findings
|
|
3140
|
+
// (PR #472: four advisories, status read none).
|
|
3141
|
+
// WHY not every post without framing (PR #475 R001): over another head's
|
|
3142
|
+
// summary, a block holding only this run's findings would replace the
|
|
3143
|
+
// marker recovery the next review relies on, so still-open findings of
|
|
3144
|
+
// older heads would stop being priors. Such a post writes the block only
|
|
3145
|
+
// as a same-head re-post, which carries the previous rows. A re-review
|
|
3146
|
+
// whose prior summary vanished has its framing dropped and stays
|
|
3147
|
+
// state-less: that framing names threads that no longer exist.
|
|
3148
|
+
const stateFramed =
|
|
3149
|
+
framing !== undefined ||
|
|
3150
|
+
(input.rereview === undefined &&
|
|
3151
|
+
(existingSummaryId === null || previousState?.headSha === doc.head_sha));
|
|
3136
3152
|
const mergeStateWithBudget = (
|
|
3137
3153
|
stateBudget: number,
|
|
3138
3154
|
): MergedState | undefined =>
|
|
3139
|
-
|
|
3155
|
+
!stateFramed
|
|
3140
3156
|
? undefined
|
|
3141
3157
|
: mergeStateFindings({
|
|
3142
3158
|
headSha: doc.head_sha,
|
|
3143
3159
|
reviews: postedReviewCount,
|
|
3144
|
-
live: framing
|
|
3160
|
+
live: framing?.live ?? [],
|
|
3145
3161
|
previous: previousState,
|
|
3146
3162
|
previousHead: previousState?.headSha ?? null,
|
|
3147
3163
|
retiredIds: [
|
|
3148
|
-
...(framing
|
|
3149
|
-
...(framing
|
|
3164
|
+
...(framing?.resolved_ids ?? []),
|
|
3165
|
+
...(framing?.worsened ?? []).map((w) => w.priorId),
|
|
3150
3166
|
],
|
|
3151
3167
|
// The priors this run's gate count released through a materiality
|
|
3152
3168
|
// demotion, recorded on the rereview block by the pipeline, so the
|
|
3153
3169
|
// state the next run reads agrees with this run's count.
|
|
3154
|
-
...(
|
|
3170
|
+
...(framing?.materiality_released_ids === undefined
|
|
3155
3171
|
? {}
|
|
3156
|
-
: { releasedIds:
|
|
3172
|
+
: { releasedIds: framing.materiality_released_ids }),
|
|
3157
3173
|
fresh: freshFindings,
|
|
3158
3174
|
stateBudget,
|
|
3159
3175
|
});
|
|
3160
3176
|
const merged = mergeStateWithBudget(stateBlockBudget(referenceBody.length));
|
|
3177
|
+
// What was finally written, for the record the platform reads: a re-merge below may drop rows.
|
|
3178
|
+
let writtenState = merged;
|
|
3161
3179
|
|
|
3162
3180
|
const renderWithState = (
|
|
3163
3181
|
delta: PrCommentDelta,
|
|
@@ -3361,6 +3379,7 @@ export async function postInlineFindings(input: {
|
|
|
3361
3379
|
stateBlockBudget(bodyWithoutState.length),
|
|
3362
3380
|
);
|
|
3363
3381
|
patchBody = renderPatch(reMerged, 0);
|
|
3382
|
+
writtenState = reMerged;
|
|
3364
3383
|
}
|
|
3365
3384
|
if (patchBody.length > GITHUB_ISSUE_COMMENT_MAX) {
|
|
3366
3385
|
process.stdout.write(
|
|
@@ -3515,6 +3534,18 @@ export async function postInlineFindings(input: {
|
|
|
3515
3534
|
commentUrls: commentUrlByFindingId,
|
|
3516
3535
|
movedHeadSha,
|
|
3517
3536
|
...(closingCommentId === undefined ? {} : { closingCommentId }),
|
|
3537
|
+
...(writtenState === undefined
|
|
3538
|
+
? {}
|
|
3539
|
+
: {
|
|
3540
|
+
findingState: buildFindingStateRecord({
|
|
3541
|
+
rows: writtenState.rows,
|
|
3542
|
+
freshFindingIds: postedDoc.findings.map((f) => f.id),
|
|
3543
|
+
freshIds: writtenState.freshIds,
|
|
3544
|
+
resolvedIds: framing?.resolved_ids ?? [],
|
|
3545
|
+
supersededIds: (framing?.worsened ?? []).map((w) => w.priorId),
|
|
3546
|
+
dropped: writtenState.dropped,
|
|
3547
|
+
}),
|
|
3548
|
+
}),
|
|
3518
3549
|
};
|
|
3519
3550
|
}
|
|
3520
3551
|
|
package/src/pr/preflight.ts
CHANGED
|
@@ -1007,10 +1007,51 @@ export function latestStatusInContext(
|
|
|
1007
1007
|
return latest;
|
|
1008
1008
|
}
|
|
1009
1009
|
|
|
1010
|
+
// The pending a gate skip writes when a rule that caps automatic reviews (the budget is used up, or the
|
|
1011
|
+
// policy is manual_only) would otherwise carry a green no review saw (ROADMAP Stage 2 #12). It holds the
|
|
1012
|
+
// head until a human asks for a review or an override. `label` is the rule (ciReviewSkipLabel); `sha` is
|
|
1013
|
+
// the commit whose verdict it held, so the next skip's walk can jump there (heldVerdictSha).
|
|
1014
|
+
export function manualReviewHoldDescription(
|
|
1015
|
+
label: string,
|
|
1016
|
+
sha: string,
|
|
1017
|
+
): string {
|
|
1018
|
+
return clipStatusDescription(
|
|
1019
|
+
`${STATUS_CONTEXT}: waiting for a manual review (${label}); carried from ${sha.slice(0, 7)} — /pr-hero review or /pr-hero override`,
|
|
1020
|
+
);
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
const MANUAL_REVIEW_HOLD = /^crysk: waiting for a manual review \(/;
|
|
1024
|
+
const HELD_VERDICT =
|
|
1025
|
+
/^crysk: waiting for a manual review \((.+)\); carried from ([0-9a-f]{7}) — /;
|
|
1026
|
+
|
|
1027
|
+
// Whether a pending status is the gate's hold, not a running review. No run holds it, so no in-flight
|
|
1028
|
+
// reader may wait on it: it lasts until a human acts, not until a run ends.
|
|
1029
|
+
export function isManualReviewHold(
|
|
1030
|
+
status: Pick<CommitStatusFact, "state" | "description">,
|
|
1031
|
+
): boolean {
|
|
1032
|
+
return (
|
|
1033
|
+
status.state === "pending" &&
|
|
1034
|
+
MANUAL_REVIEW_HOLD.test(status.description ?? "")
|
|
1035
|
+
);
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1038
|
+
// The short sha a hold names, or null. WHY the text is rebuilt: the builder above is the only authority on
|
|
1039
|
+
// a hold's exact text, so a description that only resembles one never redirects the carry's walk.
|
|
1040
|
+
export function heldVerdictSha(
|
|
1041
|
+
status: Pick<CommitStatusFact, "state" | "description">,
|
|
1042
|
+
): string | null {
|
|
1043
|
+
if (!isManualReviewHold(status)) return null;
|
|
1044
|
+
const description = status.description ?? "";
|
|
1045
|
+
const match = HELD_VERDICT.exec(description);
|
|
1046
|
+
if (match === null) return null;
|
|
1047
|
+
const [, label, sha] = match as unknown as [string, string, string];
|
|
1048
|
+
return manualReviewHoldDescription(label, sha) === description ? sha : null;
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1010
1051
|
// Latest status for our context, by created_at — GitHub's list is usually
|
|
1011
1052
|
// newest-first, but the watcher must not depend on that. A pending older
|
|
1012
1053
|
// than the TTL is NOT in-flight: the process likely died, and the next tick
|
|
1013
|
-
// must be allowed to launch.
|
|
1054
|
+
// must be allowed to launch. A manual-review hold is never in flight.
|
|
1014
1055
|
// In-flight in ANY of the given contexts: each context's own latest status is
|
|
1015
1056
|
// judged, so a fresh pending on one never hides behind a settled one on another.
|
|
1016
1057
|
// The default reads the gate alone, which is a `--ci` run's yield. A non-CI run
|
|
@@ -1024,6 +1065,7 @@ export function isInFlightCommitStatus(
|
|
|
1024
1065
|
return contexts.some((context) => {
|
|
1025
1066
|
const latest = latestStatusInContext(statuses, context);
|
|
1026
1067
|
if (latest === null || latest.state !== "pending") return false;
|
|
1068
|
+
if (isManualReviewHold(latest)) return false;
|
|
1027
1069
|
const createdMs = Date.parse(latest.created_at);
|
|
1028
1070
|
if (Number.isNaN(createdMs)) return false;
|
|
1029
1071
|
return nowMs - createdMs < ttlMs;
|
|
@@ -105,7 +105,9 @@ export interface PublishRunOutcomeInput {
|
|
|
105
105
|
// (settleCommitStatusAndLedger) reads this count in reviewPr()'s finally,
|
|
106
106
|
// and a throw later in this tail must not leave it unknown. The count is the
|
|
107
107
|
// gate's UNRESOLVED blocking count (rereview/state.ts), not this run's survivors.
|
|
108
|
-
|
|
108
|
+
// `conclusive` is false for a zero the gate itself ignores (commitStatusCompletion),
|
|
109
|
+
// because a reviewer that never ran or failed might have been the one to block.
|
|
110
|
+
onBlockingCount: (count: number, conclusive: boolean) => void;
|
|
109
111
|
// Test-only seam (default: the real postFindingsIfEnabled). The posting stage
|
|
110
112
|
// reaches gh with no offline seam of its own, so the suite passes a fake that
|
|
111
113
|
// rejects or resolves, the way it drives the throw and the delivery point.
|
|
@@ -153,7 +155,13 @@ export async function publishRunOutcome(
|
|
|
153
155
|
doc.findings,
|
|
154
156
|
result.gatePriors ?? [],
|
|
155
157
|
);
|
|
156
|
-
input.onBlockingCount(
|
|
158
|
+
input.onBlockingCount(
|
|
159
|
+
blockingCount,
|
|
160
|
+
blockingCount > 0 ||
|
|
161
|
+
(result.sessionFailed !== true &&
|
|
162
|
+
result.noReviewerRan !== true &&
|
|
163
|
+
(result.hunterFailures?.length ?? 0) === 0),
|
|
164
|
+
);
|
|
157
165
|
const reportPath = await writeRunReport({
|
|
158
166
|
runDir: input.runDir,
|
|
159
167
|
doc,
|
package/src/pr/review-pr.ts
CHANGED
|
@@ -92,7 +92,7 @@ import {
|
|
|
92
92
|
resolveMaxConcurrentSteps,
|
|
93
93
|
resolveSharedPrefix,
|
|
94
94
|
} from "#review/preflight";
|
|
95
|
-
import { estimateCost } from "#review/report";
|
|
95
|
+
import { code, estimateCost } from "#review/report";
|
|
96
96
|
import {
|
|
97
97
|
pipelineConsolidateInput,
|
|
98
98
|
pipelineMaterialityInput,
|
|
@@ -121,6 +121,7 @@ import { acquirePidLock } from "../home";
|
|
|
121
121
|
import { worktreeLockPath } from "../home-preflight";
|
|
122
122
|
import { readLocalIgnoreRules } from "../ignore-read";
|
|
123
123
|
import type { ProductionRuntime } from "../production-runtime";
|
|
124
|
+
import { writeGateRecord } from "./gate-record";
|
|
124
125
|
|
|
125
126
|
// The CLI's record for a pipeline whose every hunter failed (cli.json,
|
|
126
127
|
// odd/tasks/agent-first-ci.md, T2c). reviewPr writes it right after the pipeline's
|
|
@@ -228,7 +229,7 @@ export async function postAdjudicationReplies(input: {
|
|
|
228
229
|
});
|
|
229
230
|
const evidence =
|
|
230
231
|
entry.evidence.length > 0
|
|
231
|
-
? `\n\nEvidence:\n${entry.evidence.map((e) => `-
|
|
232
|
+
? `\n\nEvidence:\n${entry.evidence.map((e) => `- ${code(e)}`).join("\n")}`
|
|
232
233
|
: "";
|
|
233
234
|
const body = `${marker}\n\n${ADJUDICATION_BADGES[entry.verdict]}${evidence}`;
|
|
234
235
|
let commentId: number | undefined;
|
|
@@ -916,8 +917,9 @@ export async function reviewPr(
|
|
|
916
917
|
onPosted: (outcome) => {
|
|
917
918
|
posted = outcome;
|
|
918
919
|
},
|
|
919
|
-
onBlockingCount: (count) => {
|
|
920
|
+
onBlockingCount: (count, conclusive) => {
|
|
920
921
|
blockingCount = count;
|
|
922
|
+
if (conclusive) writeGateRecord(runDir, count);
|
|
921
923
|
},
|
|
922
924
|
});
|
|
923
925
|
// T5b: the verdicts are posted only after the review itself published.
|
package/src/rereview/classify.ts
CHANGED
|
@@ -107,6 +107,10 @@ export interface PriorRecord {
|
|
|
107
107
|
channel: FindingChannel;
|
|
108
108
|
locs: readonly string[];
|
|
109
109
|
claim: string;
|
|
110
|
+
// The fingerprint of the claim as first written, which is what the posted
|
|
111
|
+
// marker carries. `claim` here may be its published form, so hashing it would
|
|
112
|
+
// not match. Absent when the prior has no claim to fingerprint.
|
|
113
|
+
c?: string;
|
|
110
114
|
triage: PriorTriage | null;
|
|
111
115
|
// Case B rule 7b: any new reply on the prior thread, including tags
|
|
112
116
|
// other than a newly-applied `applied` (that one is rule 7).
|
package/src/rereview/prepare.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// The case machine itself stays in rereview/plan.ts.
|
|
5
5
|
|
|
6
6
|
import { normalizePath } from "#compare/compare";
|
|
7
|
-
import { claimFingerprint } from "#pr/preflight";
|
|
7
|
+
import { claimFingerprint, parseFindingMarker } from "#pr/preflight";
|
|
8
8
|
import type { Severity } from "#review/findings";
|
|
9
9
|
import { parseFindingCommentBadge } from "#review/report";
|
|
10
10
|
import {
|
|
@@ -617,20 +617,20 @@ export function priorsFromStateFindings(
|
|
|
617
617
|
channel: finding.channel,
|
|
618
618
|
locs: finding.locs,
|
|
619
619
|
claim: finding.claim,
|
|
620
|
+
c: finding.c,
|
|
620
621
|
triage: null,
|
|
621
622
|
newThreadReply: false,
|
|
622
623
|
}));
|
|
623
624
|
}
|
|
624
625
|
|
|
625
626
|
// #206's fix: the fallback that runs whenever the previous summary's
|
|
626
|
-
// `pr-hero-state` block cannot supply priors — missing
|
|
627
|
-
//
|
|
628
|
-
//
|
|
629
|
-
//
|
|
630
|
-
//
|
|
631
|
-
//
|
|
632
|
-
//
|
|
633
|
-
// `claimFingerprint("")`'s shared constant.
|
|
627
|
+
// `pr-hero-state` block cannot supply priors — missing or unparseable. Before
|
|
628
|
+
// 2026-11-04 a FIRST review never wrote a state block, so this was the
|
|
629
|
+
// routine path of every second review; summaries posted before then still
|
|
630
|
+
// reach it. It used to hardcode `sev: "WARNING"` / `tier: "advisory"` /
|
|
631
|
+
// `claim: ""` for EVERY prior here — silently downgrading a live BLOCKER to a
|
|
632
|
+
// warning on every second review of every PR, and collapsing every claim-less
|
|
633
|
+
// row onto `claimFingerprint("")`'s shared constant.
|
|
634
634
|
//
|
|
635
635
|
// `body` is the posted comment's raw text (the marker line alone carries no
|
|
636
636
|
// sev/tier/claim — `findingMarker` signs only the claim's fingerprint, never
|
|
@@ -651,6 +651,7 @@ export function priorsFromPostedMarkers(
|
|
|
651
651
|
): PriorRecord[] {
|
|
652
652
|
return posted.map((item, i) => {
|
|
653
653
|
const recovered = parseFindingCommentBadge(item.body);
|
|
654
|
+
const c = recovered === null ? undefined : parseFindingMarker(item.body)?.c;
|
|
654
655
|
return {
|
|
655
656
|
id: `R${String(i + 1).padStart(3, "0")}`,
|
|
656
657
|
sev: recovered?.sev ?? SEVERITY_UNRECOVERABLE,
|
|
@@ -658,6 +659,7 @@ export function priorsFromPostedMarkers(
|
|
|
658
659
|
channel: item.channel,
|
|
659
660
|
locs: [`${item.path}:${item.line}`],
|
|
660
661
|
claim: recovered?.claim ?? "",
|
|
662
|
+
...(c === undefined ? {} : { c }),
|
|
661
663
|
triage: null,
|
|
662
664
|
newThreadReply: false,
|
|
663
665
|
};
|
|
@@ -750,13 +752,18 @@ export interface PostedForPrior {
|
|
|
750
752
|
// triage tag or a thread left open; an over-match puts a "✅ RESOLVED ·
|
|
751
753
|
// verified gone" reply on a still-live finding.
|
|
752
754
|
export function bindPriorsToPosted<T extends PostedForPrior>(
|
|
753
|
-
priors: readonly {
|
|
755
|
+
priors: readonly {
|
|
756
|
+
id: string;
|
|
757
|
+
locs: readonly string[];
|
|
758
|
+
claim: string;
|
|
759
|
+
c?: string;
|
|
760
|
+
}[],
|
|
754
761
|
posted: readonly T[],
|
|
755
762
|
window: number = IDENTITY_LINE_WINDOW,
|
|
756
763
|
): Map<string, T> {
|
|
757
764
|
interface Pair {
|
|
758
765
|
priorId: string;
|
|
759
|
-
|
|
766
|
+
fingerprint: string | undefined;
|
|
760
767
|
row: T;
|
|
761
768
|
distance: number;
|
|
762
769
|
}
|
|
@@ -767,7 +774,12 @@ export function bindPriorsToPosted<T extends PostedForPrior>(
|
|
|
767
774
|
for (const row of posted) {
|
|
768
775
|
const distance = anchorDistance(identity, row, window);
|
|
769
776
|
if (distance === null) continue;
|
|
770
|
-
pairs.push({
|
|
777
|
+
pairs.push({
|
|
778
|
+
priorId: prior.id,
|
|
779
|
+
fingerprint: priorFingerprint(prior),
|
|
780
|
+
row,
|
|
781
|
+
distance,
|
|
782
|
+
});
|
|
771
783
|
}
|
|
772
784
|
}
|
|
773
785
|
|
|
@@ -804,7 +816,7 @@ export function bindPriorsToPosted<T extends PostedForPrior>(
|
|
|
804
816
|
let changed = false;
|
|
805
817
|
const proposals: Pair[] = [];
|
|
806
818
|
for (const [priorId, group] of byPrior) {
|
|
807
|
-
const winner = resolvePriorTie(group, group[0]?.
|
|
819
|
+
const winner = resolvePriorTie(group, group[0]?.fingerprint);
|
|
808
820
|
if (winner === undefined) {
|
|
809
821
|
disqualified.add(priorId);
|
|
810
822
|
changed = true;
|
|
@@ -869,16 +881,25 @@ function anchorDistance(
|
|
|
869
881
|
return best;
|
|
870
882
|
}
|
|
871
883
|
|
|
884
|
+
// What a prior's marker should carry. No claim, no fingerprint:
|
|
885
|
+
// `claimFingerprint("")` is a real constant hash (`e3b0c44298fc`) that every
|
|
886
|
+
// empty-claim prior shares, so consulting it would hand a whole tied set to
|
|
887
|
+
// whichever row came first. A stored `c` wins because the stored claim may be
|
|
888
|
+
// its published form, which the posted marker never hashed.
|
|
889
|
+
function priorFingerprint(prior: {
|
|
890
|
+
claim: string;
|
|
891
|
+
c?: string;
|
|
892
|
+
}): string | undefined {
|
|
893
|
+
if (prior.claim.trim().length === 0) return undefined;
|
|
894
|
+
return prior.c ?? claimFingerprint(prior.claim);
|
|
895
|
+
}
|
|
896
|
+
|
|
872
897
|
function resolvePriorTie<T extends PostedForPrior>(
|
|
873
898
|
tied: readonly { row: T; distance: number }[],
|
|
874
|
-
|
|
899
|
+
fingerprint: string | undefined,
|
|
875
900
|
): T | undefined {
|
|
876
901
|
if (tied.length === 1) return tied[0]?.row;
|
|
877
|
-
|
|
878
|
-
// (`e3b0c44298fc`) that every empty-claim prior shares, so consulting it
|
|
879
|
-
// here would hand the whole tied set to whichever row came first.
|
|
880
|
-
if (claim.trim().length === 0) return undefined;
|
|
881
|
-
const fingerprint = claimFingerprint(claim);
|
|
902
|
+
if (fingerprint === undefined) return undefined;
|
|
882
903
|
const matching = tied.filter((c) => c.row.marker.c === fingerprint);
|
|
883
904
|
return matching.length === 1 ? matching[0]?.row : undefined;
|
|
884
905
|
}
|
|
@@ -890,13 +911,17 @@ function resolvePriorTie<T extends PostedForPrior>(
|
|
|
890
911
|
// claim-less prior shares), and anything short of exactly one match leaves the
|
|
891
912
|
// comment to nobody.
|
|
892
913
|
function resolveRowTie<T extends PostedForPrior>(
|
|
893
|
-
contenders: readonly {
|
|
914
|
+
contenders: readonly {
|
|
915
|
+
priorId: string;
|
|
916
|
+
fingerprint: string | undefined;
|
|
917
|
+
row: T;
|
|
918
|
+
}[],
|
|
894
919
|
): { priorId: string; row: T } | undefined {
|
|
895
920
|
if (contenders.length === 1) return contenders[0];
|
|
896
921
|
const matching = contenders.filter(
|
|
897
922
|
(contender) =>
|
|
898
|
-
contender.
|
|
899
|
-
contender.row.marker.c ===
|
|
923
|
+
contender.fingerprint !== undefined &&
|
|
924
|
+
contender.row.marker.c === contender.fingerprint,
|
|
900
925
|
);
|
|
901
926
|
return matching.length === 1 ? matching[0] : undefined;
|
|
902
927
|
}
|
package/src/rereview/state.ts
CHANGED
|
@@ -27,6 +27,7 @@ import {
|
|
|
27
27
|
} from "#review/findings";
|
|
28
28
|
import { isSafetyProtected } from "#review/materiality-gate";
|
|
29
29
|
import { findMarker, MARKER_BRAND_PATTERN, MARKER_OPEN } from "../brand";
|
|
30
|
+
import { redactSecrets, wasRedacted } from "../security/published-text";
|
|
30
31
|
import {
|
|
31
32
|
type FindingChannel,
|
|
32
33
|
type GateStatus,
|
|
@@ -125,9 +126,14 @@ export function renderStateBlock(
|
|
|
125
126
|
sev: f.sev,
|
|
126
127
|
tier: f.tier,
|
|
127
128
|
channel: f.channel,
|
|
129
|
+
// Stays as written, unlike the claim below. A location is the identity the
|
|
130
|
+
// engine compares, and a redacted one never pairs with its finding again,
|
|
131
|
+
// so a blocking row could never be released.
|
|
128
132
|
locs: f.locs,
|
|
129
133
|
c: f.c,
|
|
130
|
-
|
|
134
|
+
// The block sits in the comment's raw source, so a secret here is still
|
|
135
|
+
// public. `c` keeps the fingerprint of the original claim.
|
|
136
|
+
claim: redactSecrets(f.claim),
|
|
131
137
|
})),
|
|
132
138
|
};
|
|
133
139
|
if (reviews !== undefined && Number.isInteger(reviews) && reviews >= 1) {
|
|
@@ -270,10 +276,16 @@ function lastEvictableIndex(
|
|
|
270
276
|
}
|
|
271
277
|
|
|
272
278
|
function encodeStateJson(value: unknown): string {
|
|
273
|
-
return
|
|
274
|
-
.
|
|
275
|
-
|
|
276
|
-
|
|
279
|
+
return (
|
|
280
|
+
JSON.stringify(value)
|
|
281
|
+
.replaceAll("\u2028", "\\u2028")
|
|
282
|
+
.replaceAll("\u2029", "\\u2029")
|
|
283
|
+
// No angle bracket at all: a claim or path must not spell a marker that a
|
|
284
|
+
// parser finds first, and GitHub also ends a comment at `--!>`, not only
|
|
285
|
+
// at `-->`. JSON.parse reads the escapes back to the same text.
|
|
286
|
+
.replaceAll("<", "\\u003c")
|
|
287
|
+
.replaceAll(">", "\\u003e")
|
|
288
|
+
);
|
|
277
289
|
}
|
|
278
290
|
|
|
279
291
|
function asStateFindings(parsed: unknown): StateFinding[] | null {
|
|
@@ -447,7 +459,9 @@ export function assembleLive(input: {
|
|
|
447
459
|
tier: gatePrior.tier,
|
|
448
460
|
channel: gatePrior.channel,
|
|
449
461
|
locs: row.locs,
|
|
450
|
-
|
|
462
|
+
// The stored fingerprint when there is one: the stored claim may be
|
|
463
|
+
// sanitized, and the posted marker hashed the original.
|
|
464
|
+
c: gatePrior.c ?? liveFingerprint(gatePrior.id, gatePrior.claim),
|
|
451
465
|
claim: gatePrior.claim,
|
|
452
466
|
status: persisted,
|
|
453
467
|
});
|
|
@@ -718,10 +732,16 @@ function gatePairing(
|
|
|
718
732
|
// would turn the gate green on a finding the guard exists to keep blocking.
|
|
719
733
|
// A blank claim counts as unknown: the badge reader writes an unrecovered
|
|
720
734
|
// claim as "" (rereview/prepare.ts), and the guard cannot read safety content
|
|
721
|
-
// that is not there.
|
|
735
|
+
// that is not there. A redacted claim counts the same way, since the word that
|
|
736
|
+
// made it a safety finding may be the part that was removed.
|
|
722
737
|
function isReleasable(row: GateRow | undefined): boolean {
|
|
723
738
|
const claim = row?.claim;
|
|
724
|
-
if (
|
|
739
|
+
if (
|
|
740
|
+
row === undefined ||
|
|
741
|
+
claim === undefined ||
|
|
742
|
+
claim.trim().length === 0 ||
|
|
743
|
+
wasRedacted(claim)
|
|
744
|
+
) {
|
|
725
745
|
return false;
|
|
726
746
|
}
|
|
727
747
|
const paths = [...identityFromLocs(row.locs).keys()];
|
|
@@ -807,6 +827,8 @@ export interface MergedState {
|
|
|
807
827
|
rows: LiveFinding[];
|
|
808
828
|
hw: number;
|
|
809
829
|
dropped: number;
|
|
830
|
+
// The stable id each `fresh` finding ended up with, by index.
|
|
831
|
+
freshIds: (string | undefined)[];
|
|
810
832
|
}
|
|
811
833
|
|
|
812
834
|
// Visible body the state block must leave room for. The PATCH body is longer
|
|
@@ -857,6 +879,7 @@ export function mergeStateFindings(input: MergeStateInput): MergedState {
|
|
|
857
879
|
}
|
|
858
880
|
}
|
|
859
881
|
const touched = new Set<string>();
|
|
882
|
+
const freshIds: (string | undefined)[] = input.fresh.map(() => undefined);
|
|
860
883
|
|
|
861
884
|
const pairs = pairBlockingSurvivors(
|
|
862
885
|
input.fresh,
|
|
@@ -905,6 +928,7 @@ export function mergeStateFindings(input: MergeStateInput): MergedState {
|
|
|
905
928
|
status: prior.status,
|
|
906
929
|
};
|
|
907
930
|
touched.add(prior.id);
|
|
931
|
+
freshIds[s] = prior.id;
|
|
908
932
|
continue;
|
|
909
933
|
}
|
|
910
934
|
// WHY an unpaired survivor appends: a blocking survivor with no matching row
|
|
@@ -925,6 +949,7 @@ export function mergeStateFindings(input: MergeStateInput): MergedState {
|
|
|
925
949
|
status: "unconfirmed",
|
|
926
950
|
});
|
|
927
951
|
touched.add(id);
|
|
952
|
+
freshIds[s] = id;
|
|
928
953
|
}
|
|
929
954
|
|
|
930
955
|
const capped = capLiveFindings(rows, "", input.headSha, input.stateBudget, {
|
|
@@ -936,6 +961,7 @@ export function mergeStateFindings(input: MergeStateInput): MergedState {
|
|
|
936
961
|
rows: capped.kept,
|
|
937
962
|
hw,
|
|
938
963
|
dropped: capped.droppedUnconfirmed + capped.droppedCarried,
|
|
964
|
+
freshIds,
|
|
939
965
|
};
|
|
940
966
|
}
|
|
941
967
|
|
package/src/review/report.ts
CHANGED
|
@@ -42,6 +42,7 @@ import {
|
|
|
42
42
|
LEGACY_BIN_NAME,
|
|
43
43
|
matchMarkerPrefix,
|
|
44
44
|
} from "../brand";
|
|
45
|
+
import { publishedText, redactSecrets } from "../security/published-text";
|
|
45
46
|
|
|
46
47
|
export interface DiffStat {
|
|
47
48
|
files: number;
|
|
@@ -961,7 +962,7 @@ function liveFindingLines(rereview: RereviewDelta | undefined): string[] {
|
|
|
961
962
|
? "⚠️ severity unavailable"
|
|
962
963
|
: severityEmoji(row.sev);
|
|
963
964
|
out.push(
|
|
964
|
-
`- \`${row.status}\` ${badge}
|
|
965
|
+
`- \`${row.status}\` ${badge} ${code(loc)} — ${liveClaimText(row.claim)} (${row.id})`,
|
|
965
966
|
);
|
|
966
967
|
}
|
|
967
968
|
out.push("");
|
|
@@ -1257,7 +1258,7 @@ function findingLocationLine(
|
|
|
1257
1258
|
): string {
|
|
1258
1259
|
const loc = code(`${finding.path}:${finding.line}`);
|
|
1259
1260
|
const linked =
|
|
1260
|
-
linkLocation && webUrl !== undefined
|
|
1261
|
+
linkLocation && webUrl !== undefined && isLinkablePath(finding.path)
|
|
1261
1262
|
? `[${loc}](${blobUrl(webUrl, headSha, finding.path, `L${finding.line}`)})`
|
|
1262
1263
|
: loc;
|
|
1263
1264
|
// A POSITIVE type test, not `=== undefined`. Defence in depth: the draft and
|
|
@@ -1326,16 +1327,11 @@ function tierExplanationLines(finding: Finding): string[] {
|
|
|
1326
1327
|
|
|
1327
1328
|
// The judge's reason is model text written about author-controlled input,
|
|
1328
1329
|
// and it is posted. One line (a newline would end the list item and could
|
|
1329
|
-
// start a forged header line)
|
|
1330
|
-
// it can never open or close a marker the comment parsers read, and `@`
|
|
1331
|
-
// defused so it cannot notify anyone.
|
|
1330
|
+
// start a forged header line) and capped; oneLine makes it safe to publish.
|
|
1332
1331
|
const MATERIALITY_REASON_MAX = 280;
|
|
1333
1332
|
|
|
1334
1333
|
function materialityReason(reason: string): string {
|
|
1335
|
-
const flat = oneLine(reason)
|
|
1336
|
-
.replaceAll("<!--", "<!‐‐")
|
|
1337
|
-
.replaceAll("-->", "‐‐>")
|
|
1338
|
-
.replaceAll("@", "@\u200b");
|
|
1334
|
+
const flat = oneLine(reason);
|
|
1339
1335
|
return flat.length <= MATERIALITY_REASON_MAX
|
|
1340
1336
|
? flat
|
|
1341
1337
|
: `${flat.slice(0, MATERIALITY_REASON_MAX - 1).trimEnd()}…`;
|
|
@@ -1351,7 +1347,7 @@ function promptToFixBlock(finding: Finding): string[] {
|
|
|
1351
1347
|
"<details><summary>Prompt to fix with AI</summary>",
|
|
1352
1348
|
"",
|
|
1353
1349
|
"```",
|
|
1354
|
-
`Fix this issue in ${finding.path} at line ${finding.line}:`,
|
|
1350
|
+
`Fix this issue in ${oneLine(finding.path)} at line ${finding.line}:`,
|
|
1355
1351
|
"",
|
|
1356
1352
|
oneLine(finding.claim),
|
|
1357
1353
|
"```",
|
|
@@ -1520,7 +1516,7 @@ function renderRef(
|
|
|
1520
1516
|
): string {
|
|
1521
1517
|
if (webUrl === undefined) return code(ref);
|
|
1522
1518
|
const parsed = parseRefAnchor(ref);
|
|
1523
|
-
if (parsed === null) return code(ref);
|
|
1519
|
+
if (parsed === null || !isLinkablePath(parsed.path)) return code(ref);
|
|
1524
1520
|
const fragment =
|
|
1525
1521
|
parsed.end === undefined
|
|
1526
1522
|
? `L${parsed.start}`
|
|
@@ -1559,6 +1555,27 @@ function parseRefAnchor(ref: string): {
|
|
|
1559
1555
|
};
|
|
1560
1556
|
}
|
|
1561
1557
|
|
|
1558
|
+
// A finding's path is whatever the model wrote; nothing checks that the file
|
|
1559
|
+
// exists. A span redacts it, but a link's href needs the original, so a path
|
|
1560
|
+
// carrying a secret gets no link.
|
|
1561
|
+
export function isLinkablePath(path: string): boolean {
|
|
1562
|
+
return redactSecrets(path) === path;
|
|
1563
|
+
}
|
|
1564
|
+
|
|
1565
|
+
// A path is author-controlled and lands in a Markdown link. `)` would end the
|
|
1566
|
+
// link and leave what follows as text, where `@name` is a real mention. Parens are
|
|
1567
|
+
// encoded by hand because encodeURIComponent leaves them. An unpaired surrogate
|
|
1568
|
+
// would make it throw, and a post that was paid for must not be lost to a path.
|
|
1569
|
+
function encodeBlobPath(path: string): string {
|
|
1570
|
+
return path
|
|
1571
|
+
.toWellFormed()
|
|
1572
|
+
.split("/")
|
|
1573
|
+
.map(encodeURIComponent)
|
|
1574
|
+
.join("/")
|
|
1575
|
+
.replaceAll("(", "%28")
|
|
1576
|
+
.replaceAll(")", "%29");
|
|
1577
|
+
}
|
|
1578
|
+
|
|
1562
1579
|
// Exported for ui/result.ts, the second surface that links a finding to its
|
|
1563
1580
|
// source. Deliberately SHARED rather than re-derived: the markdown report and
|
|
1564
1581
|
// the terminal block must point a reader at the same bytes, and two copies of
|
|
@@ -1570,7 +1587,7 @@ export function blobUrl(
|
|
|
1570
1587
|
path: string,
|
|
1571
1588
|
fragment: string,
|
|
1572
1589
|
): string {
|
|
1573
|
-
return `${webUrl}/blob/${sha}/${path}#${fragment}`;
|
|
1590
|
+
return `${webUrl}/blob/${sha}/${encodeBlobPath(path)}#${fragment}`;
|
|
1574
1591
|
}
|
|
1575
1592
|
|
|
1576
1593
|
function runLines(doc: FindingsDocument, meta: ReportMeta): string[] {
|
|
@@ -1809,9 +1826,12 @@ export function code(text: string): string {
|
|
|
1809
1826
|
}
|
|
1810
1827
|
|
|
1811
1828
|
// Claims arrive as free prose and sometimes carry newlines; a raw newline
|
|
1812
|
-
// inside a list item silently ends the item.
|
|
1829
|
+
// inside a list item silently ends the item. Every piece of model text and every
|
|
1830
|
+
// span in this file passes through here, which makes this the one place it is
|
|
1831
|
+
// made safe to publish. The finding marker fingerprints the raw claim instead, so
|
|
1832
|
+
// a comment posted before this existed still matches its finding.
|
|
1813
1833
|
function oneLine(text: string): string {
|
|
1814
|
-
return text.replace(/\s+/g, " ").trim();
|
|
1834
|
+
return publishedText(text.replace(/\s+/g, " ").trim());
|
|
1815
1835
|
}
|
|
1816
1836
|
|
|
1817
1837
|
function usd(amount: number): string {
|