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
|
@@ -0,0 +1,449 @@
|
|
|
1
|
+
// The action's platform step: trade the run's GitHub Actions OIDC token for a
|
|
2
|
+
// repo-scoped installation token, so a review the Crysk platform dispatched
|
|
3
|
+
// posts as the Crysk App's bot instead of github-actions[bot].
|
|
4
|
+
//
|
|
5
|
+
// It runs only in platform mode (action.yml gates the step on
|
|
6
|
+
// `workflow_dispatch` plus a non-empty `dispatch-id`), BEFORE the trigger
|
|
7
|
+
// step, and standalone use never reaches it.
|
|
8
|
+
//
|
|
9
|
+
// WHY the base URL is a constant: anyone with write access can dispatch a
|
|
10
|
+
// workflow with arbitrary inputs, so a URL taken from an input or an env var
|
|
11
|
+
// the workflow controls would let them send the run's OIDC token to a server of
|
|
12
|
+
// their choosing. The tests inject the URL as a parameter; the shell below
|
|
13
|
+
// never reads it from the environment.
|
|
14
|
+
//
|
|
15
|
+
// WHY it fails loudly: in platform mode there is no silent fallback to
|
|
16
|
+
// `github.token`. A review that quietly posted as the wrong identity, or not at
|
|
17
|
+
// all, is worse than a red run that names the cause.
|
|
18
|
+
//
|
|
19
|
+
// WHY ONLY BUILTINS: like the trigger, this runs before `bun install`. Keep
|
|
20
|
+
// every import `node:` or `bun`, and `fetch` is the runtime's own.
|
|
21
|
+
|
|
22
|
+
import { appendFileSync, mkdirSync, writeFileSync } from "node:fs";
|
|
23
|
+
import path from "node:path";
|
|
24
|
+
|
|
25
|
+
export const PLATFORM_API_URL = "https://api.crysk.dev";
|
|
26
|
+
|
|
27
|
+
// The audience the platform verifies. An OIDC token minted for any other
|
|
28
|
+
// audience is refused with a 401.
|
|
29
|
+
const OIDC_AUDIENCE = "crysk";
|
|
30
|
+
|
|
31
|
+
// Long enough for a slow API, short enough that a hung endpoint cannot hold the
|
|
32
|
+
// job: this step runs first, before anything else.
|
|
33
|
+
const REQUEST_TIMEOUT_MS = 30_000;
|
|
34
|
+
|
|
35
|
+
// A GitHub login as the platform returns it (`crysk-dev[bot]`). It lands in a
|
|
36
|
+
// trust set and in $GITHUB_OUTPUT, so nothing else is accepted.
|
|
37
|
+
const SAFE_LOGIN = /^[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?(?:\[bot\])?$/;
|
|
38
|
+
|
|
39
|
+
const MISSING_OIDC =
|
|
40
|
+
"The workflow did not grant `id-token: write`, so GitHub issued no OIDC token to this run. Add `id-token: write` to the workflow's `permissions:` and dispatch again.";
|
|
41
|
+
|
|
42
|
+
// The review configuration the platform holds for this repository, split by the
|
|
43
|
+
// layer each key belongs to (the engine's CONFIG_DIRECTION): `person` is the
|
|
44
|
+
// runner's personal config, `repo` the repository layer. The platform has
|
|
45
|
+
// already validated the values; the engine's parsers stay the authority and
|
|
46
|
+
// re-check them where they are applied (src/ci/platform-config.ts), because this
|
|
47
|
+
// step runs before `bun install` and cannot import them.
|
|
48
|
+
export interface PlatformConfig {
|
|
49
|
+
person: Record<string, unknown>;
|
|
50
|
+
repo: Record<string, unknown>;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// The file the connect step leaves under CRYSK_PLATFORM_CONFIG_DIR, and the
|
|
54
|
+
// setup step reads. Written 0600 under the runner's temp directory, never in the
|
|
55
|
+
// workspace.
|
|
56
|
+
export const PLATFORM_CONFIG_FILE_NAME = "platform-config.json";
|
|
57
|
+
|
|
58
|
+
function isPlainObject(value: unknown): value is Record<string, unknown> {
|
|
59
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// `config` as the token response carries it. Absent (an older platform) or two
|
|
63
|
+
// empty objects is "no configuration": `config` is left out of the result, and
|
|
64
|
+
// nothing downstream runs. A present value of the wrong shape is a failure, not
|
|
65
|
+
// a silent skip: a review with the wrong limits is worse than no review.
|
|
66
|
+
export function parsePlatformConfig(
|
|
67
|
+
value: unknown,
|
|
68
|
+
): { ok: true; config?: PlatformConfig } | { ok: false; message: string } {
|
|
69
|
+
if (value === undefined || value === null) return { ok: true };
|
|
70
|
+
if (!isPlainObject(value)) {
|
|
71
|
+
return { ok: false, message: "`config` must be a JSON object." };
|
|
72
|
+
}
|
|
73
|
+
const layers: Record<"person" | "repo", Record<string, unknown>> = {
|
|
74
|
+
person: {},
|
|
75
|
+
repo: {},
|
|
76
|
+
};
|
|
77
|
+
for (const layer of ["person", "repo"] as const) {
|
|
78
|
+
const body = value[layer];
|
|
79
|
+
if (body === undefined || body === null) continue;
|
|
80
|
+
if (!isPlainObject(body)) {
|
|
81
|
+
return {
|
|
82
|
+
ok: false,
|
|
83
|
+
message: `\`config.${layer}\` must be a JSON object.`,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
layers[layer] = body;
|
|
87
|
+
}
|
|
88
|
+
if (
|
|
89
|
+
Object.keys(layers.person).length === 0 &&
|
|
90
|
+
Object.keys(layers.repo).length === 0
|
|
91
|
+
) {
|
|
92
|
+
return { ok: true };
|
|
93
|
+
}
|
|
94
|
+
return { ok: true, config: layers };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// How much of the run the platform may keep, as /runs/token's `data_mode`
|
|
98
|
+
// says. `full` is the only value that lets the report step send finding text.
|
|
99
|
+
export type PlatformDataMode = "full" | "metadata_only";
|
|
100
|
+
|
|
101
|
+
export type PlatformTokenResult =
|
|
102
|
+
// `githubActor` is the login the platform says posts as the App's bot. It is
|
|
103
|
+
// absent when the platform sent none or one that is not a plausible login.
|
|
104
|
+
// `config` is absent when the platform sent none or only empty objects.
|
|
105
|
+
// `dataMode` is absent when the platform sent none or anything but exactly
|
|
106
|
+
// `full` or `metadata_only`; the connect step reads absence as metadata_only.
|
|
107
|
+
| {
|
|
108
|
+
ok: true;
|
|
109
|
+
githubToken: string;
|
|
110
|
+
runToken: string;
|
|
111
|
+
githubActor?: string;
|
|
112
|
+
dataMode?: PlatformDataMode;
|
|
113
|
+
config?: PlatformConfig;
|
|
114
|
+
}
|
|
115
|
+
// `message` names the HTTP status and the API's own `message` when there was
|
|
116
|
+
// one. It never carries a token.
|
|
117
|
+
| { ok: false; message: string };
|
|
118
|
+
|
|
119
|
+
export interface PlatformTokenDeps {
|
|
120
|
+
fetch: typeof fetch;
|
|
121
|
+
env: Readonly<Record<string, string | undefined>>;
|
|
122
|
+
baseUrl: string;
|
|
123
|
+
// Called with each secret as soon as it is known, before it is used or
|
|
124
|
+
// returned, so the caller can emit `::add-mask::` ahead of any other write.
|
|
125
|
+
mask: (secret: string) => void;
|
|
126
|
+
// Waits between OIDC attempts; tests inject a no-op.
|
|
127
|
+
sleep?: (ms: number) => Promise<void>;
|
|
128
|
+
// The refresh steps never use the configuration in their response, so they
|
|
129
|
+
// set this and a config of the wrong shape cannot turn a finished job red.
|
|
130
|
+
ignoreConfig?: boolean;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// The OIDC GET is idempotent, so a blip (a thrown fetch, a timeout, a 5xx) is
|
|
134
|
+
// retried; the platform POST below is NOT: the platform refuses a second
|
|
135
|
+
// exchange of the same OIDC token (HTTP 409, keyed on its jti). Every run of
|
|
136
|
+
// this script asks GitHub for a NEW OIDC token, so a later step can exchange
|
|
137
|
+
// again for a fresh installation token; a retry of the POST could not.
|
|
138
|
+
const OIDC_ATTEMPTS = 3;
|
|
139
|
+
const OIDC_BACKOFF_MS = 1_000;
|
|
140
|
+
|
|
141
|
+
async function fetchOidc(
|
|
142
|
+
deps: PlatformTokenDeps,
|
|
143
|
+
url: string,
|
|
144
|
+
requestToken: string,
|
|
145
|
+
): Promise<Response> {
|
|
146
|
+
const sleep =
|
|
147
|
+
deps.sleep ??
|
|
148
|
+
((ms: number) => {
|
|
149
|
+
const { promise, resolve } = Promise.withResolvers<void>();
|
|
150
|
+
setTimeout(resolve, ms);
|
|
151
|
+
return promise;
|
|
152
|
+
});
|
|
153
|
+
for (let attempt = 1; ; attempt++) {
|
|
154
|
+
try {
|
|
155
|
+
const response = await deps.fetch(url, {
|
|
156
|
+
headers: { Authorization: `bearer ${requestToken}` },
|
|
157
|
+
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),
|
|
158
|
+
});
|
|
159
|
+
if (response.status < 500 || attempt === OIDC_ATTEMPTS) return response;
|
|
160
|
+
} catch (error) {
|
|
161
|
+
if (attempt === OIDC_ATTEMPTS) throw error;
|
|
162
|
+
}
|
|
163
|
+
await sleep(OIDC_BACKOFF_MS * attempt);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// A token is written to $GITHUB_OUTPUT as `name=value`, so one that holds a
|
|
168
|
+
// line break or any other whitespace could plant a second output. Installation
|
|
169
|
+
// and run tokens are printable ASCII; refuse anything else.
|
|
170
|
+
const SAFE_TOKEN = /^[\x21-\x7e]+$/;
|
|
171
|
+
|
|
172
|
+
function failure(
|
|
173
|
+
message: string,
|
|
174
|
+
secrets: readonly string[],
|
|
175
|
+
): PlatformTokenResult {
|
|
176
|
+
let safe = message;
|
|
177
|
+
for (const secret of secrets) {
|
|
178
|
+
if (secret !== "") safe = safe.split(secret).join("***");
|
|
179
|
+
}
|
|
180
|
+
return { ok: false, message: safe };
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// The API's `{ message }`, when the body is JSON and has one.
|
|
184
|
+
async function apiMessage(response: Response): Promise<string | undefined> {
|
|
185
|
+
try {
|
|
186
|
+
const body: unknown = await response.json();
|
|
187
|
+
if (typeof body === "object" && body !== null && "message" in body) {
|
|
188
|
+
const { message } = body as { message: unknown };
|
|
189
|
+
if (typeof message === "string" && message !== "") return message;
|
|
190
|
+
}
|
|
191
|
+
} catch {
|
|
192
|
+
// Not JSON: the status alone names the failure.
|
|
193
|
+
}
|
|
194
|
+
return undefined;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export async function exchangePlatformToken(
|
|
198
|
+
deps: PlatformTokenDeps,
|
|
199
|
+
): Promise<PlatformTokenResult> {
|
|
200
|
+
const requestUrl = deps.env.ACTIONS_ID_TOKEN_REQUEST_URL ?? "";
|
|
201
|
+
const requestToken = deps.env.ACTIONS_ID_TOKEN_REQUEST_TOKEN ?? "";
|
|
202
|
+
const dispatchId = deps.env.CRYSK_DISPATCH_ID ?? "";
|
|
203
|
+
if (requestUrl === "" || requestToken === "") {
|
|
204
|
+
return { ok: false, message: MISSING_OIDC };
|
|
205
|
+
}
|
|
206
|
+
// The runner already masks its own request token, and the secrets list keeps
|
|
207
|
+
// it out of any message a failure builds.
|
|
208
|
+
const secrets: string[] = [requestToken];
|
|
209
|
+
|
|
210
|
+
try {
|
|
211
|
+
const oidcResponse = await fetchOidc(
|
|
212
|
+
deps,
|
|
213
|
+
`${requestUrl}${requestUrl.includes("?") ? "&" : "?"}audience=${OIDC_AUDIENCE}`,
|
|
214
|
+
requestToken,
|
|
215
|
+
);
|
|
216
|
+
if (!oidcResponse.ok) {
|
|
217
|
+
return failure(
|
|
218
|
+
`GitHub's OIDC endpoint answered HTTP ${oidcResponse.status}; the run could not obtain an identity token.`,
|
|
219
|
+
secrets,
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
const oidcBody = (await oidcResponse.json()) as { value?: unknown };
|
|
223
|
+
const oidc = oidcBody.value;
|
|
224
|
+
if (typeof oidc !== "string" || oidc === "") {
|
|
225
|
+
return failure("GitHub's OIDC endpoint returned no token.", secrets);
|
|
226
|
+
}
|
|
227
|
+
deps.mask(oidc);
|
|
228
|
+
secrets.push(oidc);
|
|
229
|
+
|
|
230
|
+
const response = await deps.fetch(`${deps.baseUrl}/runs/token`, {
|
|
231
|
+
method: "POST",
|
|
232
|
+
headers: {
|
|
233
|
+
Authorization: `Bearer ${oidc}`,
|
|
234
|
+
"X-Crysk-Dispatch-Id": dispatchId,
|
|
235
|
+
},
|
|
236
|
+
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),
|
|
237
|
+
});
|
|
238
|
+
if (!response.ok) {
|
|
239
|
+
const message = await apiMessage(response);
|
|
240
|
+
return failure(
|
|
241
|
+
`The Crysk platform refused the token exchange: HTTP ${response.status}${message === undefined ? "" : ` — ${message}`}`,
|
|
242
|
+
secrets,
|
|
243
|
+
);
|
|
244
|
+
}
|
|
245
|
+
const body = (await response.json()) as {
|
|
246
|
+
github_token?: unknown;
|
|
247
|
+
run_token?: unknown;
|
|
248
|
+
github_actor?: unknown;
|
|
249
|
+
data_mode?: unknown;
|
|
250
|
+
config?: unknown;
|
|
251
|
+
};
|
|
252
|
+
const {
|
|
253
|
+
github_token: githubToken,
|
|
254
|
+
run_token: runToken,
|
|
255
|
+
github_actor: actor,
|
|
256
|
+
data_mode: dataMode,
|
|
257
|
+
} = body;
|
|
258
|
+
// Mask whatever string arrived before judging it, so a malformed reply
|
|
259
|
+
// still cannot leak a token into the log.
|
|
260
|
+
for (const value of [githubToken, runToken]) {
|
|
261
|
+
if (typeof value === "string" && value !== "") deps.mask(value);
|
|
262
|
+
}
|
|
263
|
+
if (
|
|
264
|
+
typeof githubToken !== "string" ||
|
|
265
|
+
typeof runToken !== "string" ||
|
|
266
|
+
!SAFE_TOKEN.test(githubToken) ||
|
|
267
|
+
!SAFE_TOKEN.test(runToken)
|
|
268
|
+
) {
|
|
269
|
+
return failure(
|
|
270
|
+
"The Crysk platform answered HTTP 200 without a usable github_token and run_token.",
|
|
271
|
+
[...secrets, String(githubToken), String(runToken)],
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
const config: ReturnType<typeof parsePlatformConfig> =
|
|
275
|
+
deps.ignoreConfig === true
|
|
276
|
+
? { ok: true }
|
|
277
|
+
: parsePlatformConfig(body.config);
|
|
278
|
+
if (!config.ok) {
|
|
279
|
+
return failure(
|
|
280
|
+
`The Crysk platform answered HTTP 200 with a malformed config: ${config.message}`,
|
|
281
|
+
[...secrets, githubToken, runToken],
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
return {
|
|
285
|
+
ok: true,
|
|
286
|
+
githubToken,
|
|
287
|
+
runToken,
|
|
288
|
+
...(typeof actor === "string" && SAFE_LOGIN.test(actor)
|
|
289
|
+
? { githubActor: actor }
|
|
290
|
+
: {}),
|
|
291
|
+
...(dataMode === "full" || dataMode === "metadata_only"
|
|
292
|
+
? { dataMode }
|
|
293
|
+
: {}),
|
|
294
|
+
...(config.config === undefined ? {} : { config: config.config }),
|
|
295
|
+
};
|
|
296
|
+
} catch (error) {
|
|
297
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
298
|
+
return failure(
|
|
299
|
+
`The Crysk platform token exchange could not complete: ${detail}`,
|
|
300
|
+
secrets,
|
|
301
|
+
);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// Workflow-command data escaping, as the runner's own toolkit does it.
|
|
306
|
+
function escapeCommandData(text: string): string {
|
|
307
|
+
return text.replace(/%/g, "%25").replace(/\r/g, "%0D").replace(/\n/g, "%0A");
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
export interface PlatformConnectDeps extends Omit<PlatformTokenDeps, "mask"> {
|
|
311
|
+
stdout: (text: string) => void;
|
|
312
|
+
appendOutput: (text: string) => void;
|
|
313
|
+
// Where the review configuration is left for the setup step. Set by the first
|
|
314
|
+
// connect step only: the refresh steps run after the review and must not touch
|
|
315
|
+
// it, so they leave this unset and the config in their response is ignored.
|
|
316
|
+
configDir?: string;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// Hands the platform's review configuration to the setup step as a 0600 file
|
|
320
|
+
// under the runner's temp directory (never the workspace). Returns the path.
|
|
321
|
+
function writePlatformConfig(dir: string, config: PlatformConfig): string {
|
|
322
|
+
const file = path.join(dir, PLATFORM_CONFIG_FILE_NAME);
|
|
323
|
+
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
324
|
+
writeFileSync(file, `${JSON.stringify(config)}\n`, { mode: 0o600 });
|
|
325
|
+
return file;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
// The step's shell. Every token is masked BEFORE the output is written, and a
|
|
329
|
+
// failure writes no output at all: the later steps see no platform token and the
|
|
330
|
+
// job is red, never silently on `github.token`.
|
|
331
|
+
export async function runPlatformConnect(
|
|
332
|
+
deps: PlatformConnectDeps,
|
|
333
|
+
): Promise<number> {
|
|
334
|
+
const result = await exchangePlatformToken({
|
|
335
|
+
...deps,
|
|
336
|
+
// Only the first connect step (it binds the config directory) uses it.
|
|
337
|
+
ignoreConfig: deps.configDir === undefined,
|
|
338
|
+
mask: (secret) => deps.stdout(`::add-mask::${escapeCommandData(secret)}\n`),
|
|
339
|
+
});
|
|
340
|
+
if (!result.ok) {
|
|
341
|
+
deps.stdout(
|
|
342
|
+
`::error title=crysk::${escapeCommandData(`Crysk platform mode failed: ${result.message}`)}\n`,
|
|
343
|
+
);
|
|
344
|
+
return 1;
|
|
345
|
+
}
|
|
346
|
+
// WHY the config file is written before any output: a failure writes no
|
|
347
|
+
// output at all, so a run whose configuration could not be applied never
|
|
348
|
+
// looks connected. The failure names the file, never a value.
|
|
349
|
+
let configFile: string | undefined;
|
|
350
|
+
if (result.config !== undefined && deps.configDir !== undefined) {
|
|
351
|
+
try {
|
|
352
|
+
configFile = writePlatformConfig(deps.configDir, result.config);
|
|
353
|
+
} catch (error) {
|
|
354
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
355
|
+
deps.stdout(
|
|
356
|
+
`::error title=crysk::${escapeCommandData(`Crysk platform mode failed: the review configuration could not be written to ${path.join(deps.configDir, PLATFORM_CONFIG_FILE_NAME)}: ${detail}`)}\n`,
|
|
357
|
+
);
|
|
358
|
+
return 1;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
// WHY a throw is an error and not a green step: the later steps read this
|
|
362
|
+
// output with `|| inputs.github-token`, so a token that was never written
|
|
363
|
+
// would silently post as github-actions[bot].
|
|
364
|
+
try {
|
|
365
|
+
// WHY fail closed: `data-mode` decides whether the report step may send
|
|
366
|
+
// finding text at all (src/ci/platform-report.ts), and a repository in
|
|
367
|
+
// metadata-only mode must never have its code leave the runner. A missing
|
|
368
|
+
// or unrecognised value therefore reads as metadata_only, with a notice.
|
|
369
|
+
// Written by EVERY exchange, refresh steps included: the report step reads
|
|
370
|
+
// the freshest one (the publish refresh, minted after the run), because the
|
|
371
|
+
// first token can be 75 minutes old and the repository's mode may have
|
|
372
|
+
// been switched to metadata_only since.
|
|
373
|
+
// WHY first: the report step pairs this exchange's run token with this
|
|
374
|
+
// exchange's data mode. Appends are not atomic, so if one throws the step
|
|
375
|
+
// fails; with the mode written before the tokens, a refresh that left a
|
|
376
|
+
// run token always left its mode, and the report never pairs a fresh
|
|
377
|
+
// token with the stale first-exchange mode.
|
|
378
|
+
deps.appendOutput(`data-mode=${result.dataMode ?? "metadata_only"}\n`);
|
|
379
|
+
if (result.dataMode === undefined) {
|
|
380
|
+
deps.stdout(
|
|
381
|
+
"::notice title=crysk::The Crysk platform sent no recognised data_mode; treating this repository as metadata_only, so no finding text is uploaded.\n",
|
|
382
|
+
);
|
|
383
|
+
}
|
|
384
|
+
deps.appendOutput(`github-token=${result.githubToken}\n`);
|
|
385
|
+
// The run token authenticates the report step (src/ci/platform-report.ts).
|
|
386
|
+
// Already masked by the exchange above, like the installation token.
|
|
387
|
+
deps.appendOutput(`run-token=${result.runToken}\n`);
|
|
388
|
+
// Not a secret. Only a login the platform returned, so the engine's trust
|
|
389
|
+
// set never learns one from anywhere else (see CRYSK_PLATFORM_ACTOR).
|
|
390
|
+
if (result.githubActor !== undefined) {
|
|
391
|
+
deps.appendOutput(`github-actor=${result.githubActor}\n`);
|
|
392
|
+
}
|
|
393
|
+
// Present only when there is configuration to apply: the setup step and the
|
|
394
|
+
// run step are gated on it, so a standalone run (no platform step, no
|
|
395
|
+
// output) and an empty config both skip everything.
|
|
396
|
+
if (configFile !== undefined) {
|
|
397
|
+
deps.appendOutput(`config-file=${configFile}\n`);
|
|
398
|
+
// The same test the OpenCode install step makes of the routing input
|
|
399
|
+
// (`contains(inputs.routing, 'opencode')`): platform routing that names
|
|
400
|
+
// OpenCode needs the CLI installed too. Present whenever the platform
|
|
401
|
+
// sent a routing, `false` included, because platform routing wins over
|
|
402
|
+
// the input: action.yml reads an empty output as "use the input's" and
|
|
403
|
+
// any value as the platform's answer, so a platform routing that does not
|
|
404
|
+
// name OpenCode overrides an input that does.
|
|
405
|
+
const routing = result.config?.person.routing;
|
|
406
|
+
if (routing !== undefined) {
|
|
407
|
+
deps.appendOutput(
|
|
408
|
+
`routing-opencode=${JSON.stringify(routing).toLowerCase().includes("opencode")}\n`,
|
|
409
|
+
);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
} catch (error) {
|
|
413
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
414
|
+
deps.stdout(
|
|
415
|
+
`::error title=crysk::${escapeCommandData(`Crysk platform mode failed: the installation token could not be handed to the later steps: ${detail}`)}\n`,
|
|
416
|
+
);
|
|
417
|
+
return 1;
|
|
418
|
+
}
|
|
419
|
+
return 0;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
// Appends to the file the runner named in GITHUB_OUTPUT. Unset or empty is an
|
|
423
|
+
// error, not a no-op: see runPlatformConnect.
|
|
424
|
+
export function appendGithubOutput(
|
|
425
|
+
outputPath: string | undefined,
|
|
426
|
+
text: string,
|
|
427
|
+
): void {
|
|
428
|
+
if (outputPath === undefined || outputPath === "") {
|
|
429
|
+
throw new Error("GITHUB_OUTPUT is not set");
|
|
430
|
+
}
|
|
431
|
+
appendFileSync(outputPath, text);
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
if (import.meta.main) {
|
|
435
|
+
process.exit(
|
|
436
|
+
await runPlatformConnect({
|
|
437
|
+
fetch,
|
|
438
|
+
env: process.env,
|
|
439
|
+
baseUrl: PLATFORM_API_URL,
|
|
440
|
+
stdout: (text) => process.stdout.write(text),
|
|
441
|
+
appendOutput: (text) =>
|
|
442
|
+
appendGithubOutput(process.env.GITHUB_OUTPUT, text),
|
|
443
|
+
// Bound by the connect step only (action.yml), never by a refresh step.
|
|
444
|
+
...(process.env.CRYSK_PLATFORM_CONFIG_DIR
|
|
445
|
+
? { configDir: process.env.CRYSK_PLATFORM_CONFIG_DIR }
|
|
446
|
+
: {}),
|
|
447
|
+
}),
|
|
448
|
+
);
|
|
449
|
+
}
|
package/src/ci/reporter.ts
CHANGED
|
@@ -38,10 +38,12 @@ import {
|
|
|
38
38
|
blobUrl,
|
|
39
39
|
code,
|
|
40
40
|
formatElapsed,
|
|
41
|
+
isLinkablePath,
|
|
41
42
|
type PrCommentDelta,
|
|
42
43
|
severityEmoji,
|
|
43
44
|
} from "#review/report";
|
|
44
45
|
import { log } from "#ui/primitives";
|
|
46
|
+
import { publishedText } from "../security/published-text";
|
|
45
47
|
|
|
46
48
|
// ---------------------------------------------------------------------------
|
|
47
49
|
// Workflow commands (`::group::`, `::endgroup::`, `::notice::`, `::warning::`,
|
|
@@ -238,7 +240,7 @@ function severityRank(severity: Severity): number {
|
|
|
238
240
|
}
|
|
239
241
|
|
|
240
242
|
function oneLine(text: string): string {
|
|
241
|
-
return text.replace(/\s+/g, " ").trim();
|
|
243
|
+
return publishedText(text.replace(/\s+/g, " ").trim());
|
|
242
244
|
}
|
|
243
245
|
|
|
244
246
|
// Grouped by file (spec 2.1: "grouped by file and severity tier"), sorted
|
|
@@ -270,11 +272,11 @@ function findingLine(
|
|
|
270
272
|
headSha: string,
|
|
271
273
|
webUrl: string | undefined,
|
|
272
274
|
): string {
|
|
273
|
-
const loc = `${finding.path}:${finding.line}
|
|
275
|
+
const loc = code(`${finding.path}:${finding.line}`);
|
|
274
276
|
const linked =
|
|
275
|
-
webUrl === undefined
|
|
276
|
-
?
|
|
277
|
-
: `[
|
|
277
|
+
webUrl === undefined || !isLinkablePath(finding.path)
|
|
278
|
+
? loc
|
|
279
|
+
: `[${loc}](${blobUrl(webUrl, headSha, finding.path, `L${finding.line}`)})`;
|
|
278
280
|
return (
|
|
279
281
|
`- ${severityEmoji(finding.severity)} ${finding.severity} · ` +
|
|
280
282
|
`${finding.tier} — ${linked} — ${oneLine(finding.claim)}`
|
|
@@ -431,7 +433,7 @@ function manualRequiredLines(data: CiManualRequiredSummary): string[] {
|
|
|
431
433
|
return [
|
|
432
434
|
`### ⏹️ Crysk Review — Automatic Reviews Done — PR #${data.prNumber}`,
|
|
433
435
|
"",
|
|
434
|
-
"**Reason:** no automatic review is left for this pull request; the gate keeps
|
|
436
|
+
"**Reason:** no automatic review is left for this pull request; the gate keeps a red verdict and holds a green one `pending` for a manual review (`/crysk review` or `/crysk override`).",
|
|
435
437
|
"",
|
|
436
438
|
"| Metric | Value |",
|
|
437
439
|
"| --- | --- |",
|
|
@@ -464,7 +466,7 @@ function reviewedLines(data: CiReviewSummary): string[] {
|
|
|
464
466
|
} else {
|
|
465
467
|
out.push("#### Findings", "");
|
|
466
468
|
for (const [filePath, group] of groupFindingsByPath(data.findings)) {
|
|
467
|
-
out.push(
|
|
469
|
+
out.push(`**${code(filePath)}**`);
|
|
468
470
|
for (const finding of group) {
|
|
469
471
|
out.push(findingLine(finding, data.headSha, data.repoWebUrl));
|
|
470
472
|
}
|
|
@@ -167,15 +167,19 @@ export function ciReviewPolicyHash(policy: CiReviewPolicy): string {
|
|
|
167
167
|
return createHash("sha256").update(canonical).digest("hex").slice(0, 16);
|
|
168
168
|
}
|
|
169
169
|
|
|
170
|
-
// GITHUB_ACTOR in Actions
|
|
171
|
-
//
|
|
170
|
+
// GITHUB_ACTOR in Actions, the login the Crysk platform returned in platform
|
|
171
|
+
// mode (action.yml sets CRYSK_PLATFORM_ACTOR only from the platform step's
|
|
172
|
+
// output, so it is empty in a standalone run), plus optional repo-config
|
|
173
|
+
// extras. Undefined when no actor is known — callers treat that as "do not
|
|
174
|
+
// filter by author".
|
|
172
175
|
export function resolveCiTrustedActors(input: {
|
|
173
176
|
githubActor?: string;
|
|
177
|
+
platformActor?: string;
|
|
174
178
|
extra?: readonly string[];
|
|
175
179
|
}): ReadonlySet<string> | undefined {
|
|
176
180
|
const actors = new Set<string>();
|
|
177
|
-
|
|
178
|
-
actors.add(
|
|
181
|
+
for (const login of [input.githubActor, input.platformActor]) {
|
|
182
|
+
if (login !== undefined && login.length > 0) actors.add(login);
|
|
179
183
|
}
|
|
180
184
|
for (const login of input.extra ?? []) {
|
|
181
185
|
if (login.length > 0) actors.add(login);
|