crysk 0.3.3 → 0.5.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.
Files changed (116) hide show
  1. package/README.md +26 -17
  2. package/config/models/anthropic.json +1 -1
  3. package/dist/SKILL-dsnffnfp.md +140 -0
  4. package/dist/SKILL-gnrbph72.md +140 -0
  5. package/dist/SKILL-k4k0zn1w.md +143 -0
  6. package/dist/SKILL-kq0xejn3.md +553 -0
  7. package/dist/SKILL-qaqsbygw.md +66 -0
  8. package/dist/SKILL-vhb4c3vv.md +553 -0
  9. package/dist/SKILL-vws0aqb8.md +553 -0
  10. package/dist/SKILL-xpf6kmdw.md +74 -0
  11. package/dist/ci-admission-0ken6ehx.md +128 -0
  12. package/dist/ci-admission-t0f5qwth.md +128 -0
  13. package/dist/cli.js +3366 -1680
  14. package/dist/index.js +1884 -947
  15. package/dist/opencode-ci-ac5zksdn.md +106 -0
  16. package/dist/workflow-4pkyck01.yml +160 -0
  17. package/package.json +2 -2
  18. package/prompts/default/PROVENANCE.md +1 -0
  19. package/skills/crysk/SKILL.md +16 -16
  20. package/skills/crysk-ci-setup/SKILL.md +42 -39
  21. package/skills/crysk-ci-setup/assets/workflow.yml +31 -22
  22. package/skills/crysk-ci-setup/references/ci-admission.md +2 -2
  23. package/skills/crysk-ci-setup/references/opencode-ci.md +53 -88
  24. package/skills/crysk-loop/SKILL.md +20 -9
  25. package/skills/crysk-pr/SKILL.md +1 -1
  26. package/src/asset-manifest.ts +0 -4
  27. package/src/assets.ts +2 -2
  28. package/src/ci/admission-ledger.ts +4 -0
  29. package/src/ci/classify-error.ts +21 -24
  30. package/src/ci/cli-record.ts +53 -1
  31. package/src/ci/crysk-secrets.ts +409 -0
  32. package/src/ci/gates.ts +31 -42
  33. package/src/ci/outcome.ts +421 -330
  34. package/src/ci/platform-config.ts +127 -0
  35. package/src/ci/platform-report.ts +935 -0
  36. package/src/ci/platform-trace.ts +551 -0
  37. package/src/ci/platform.ts +465 -0
  38. package/src/ci/publish.ts +19 -6
  39. package/src/ci/reporter.ts +9 -7
  40. package/src/ci/review-admission.ts +8 -4
  41. package/src/ci/review-levels.ts +8 -7
  42. package/src/ci/run.ts +88 -0
  43. package/src/ci/setup.ts +547 -109
  44. package/src/ci/trace-bundle.ts +1282 -0
  45. package/src/ci/trace-transcripts.ts +415 -0
  46. package/src/ci/trigger.ts +176 -33
  47. package/src/cli.ts +11 -3
  48. package/src/commands/ci-setup-questions.ts +3 -3
  49. package/src/commands/ci-setup.ts +152 -6
  50. package/src/commands/config.ts +3 -0
  51. package/src/commands/doctor.ts +15 -6
  52. package/src/compare/loop.ts +9 -1
  53. package/src/compare/martian-adapter.ts +1 -1
  54. package/src/config/config.ts +16 -3
  55. package/src/diversity/clustering.ts +0 -1
  56. package/src/diversity/identity.ts +4 -5
  57. package/src/diversity/pipeline-integration.ts +1 -9
  58. package/src/doctor.ts +3 -3
  59. package/src/execution/attempt-evidence.ts +10 -5
  60. package/src/execution/claude-session-trace.ts +480 -0
  61. package/src/execution/contracts.ts +21 -4
  62. package/src/execution/harness.ts +105 -8
  63. package/src/execution/model-fallback.ts +239 -0
  64. package/src/execution/usage-normalized.ts +6 -4
  65. package/src/home-preflight.ts +1 -1
  66. package/src/index.ts +1 -1
  67. package/src/model/catalog.ts +13 -37
  68. package/src/model/free-discovery.ts +117 -8
  69. package/src/model/model-name.ts +404 -0
  70. package/src/model/provider-capabilities.ts +22 -7
  71. package/src/model/routing.ts +346 -467
  72. package/src/pr/admission.ts +71 -11
  73. package/src/pr/ci-admission-gate.ts +2 -1
  74. package/src/pr/finding-state-record.ts +58 -0
  75. package/src/pr/gate-record.ts +22 -0
  76. package/src/pr/inline.ts +3 -0
  77. package/src/pr/plan.ts +20 -4
  78. package/src/pr/posting.ts +4 -0
  79. package/src/pr/pr-status.ts +27 -7
  80. package/src/pr/pr.ts +39 -8
  81. package/src/pr/preflight.ts +44 -2
  82. package/src/pr/publish-outcome.ts +11 -3
  83. package/src/pr/review-pr.ts +20 -4
  84. package/src/pr/target.ts +12 -3
  85. package/src/production-runtime.ts +760 -331
  86. package/src/rereview/classify.ts +4 -0
  87. package/src/rereview/prepare.ts +47 -22
  88. package/src/rereview/state.ts +34 -8
  89. package/src/review/pipeline.ts +277 -101
  90. package/src/review/preflight.ts +201 -294
  91. package/src/review/report.ts +60 -40
  92. package/src/review/review.ts +20 -3
  93. package/src/review/route-preflight.ts +79 -11
  94. package/src/review/run.ts +28 -6
  95. package/src/review/scout.ts +1 -1
  96. package/src/review/spec.ts +3 -3
  97. package/src/review/step-runner.ts +70 -1
  98. package/src/runner-authority.ts +127 -9
  99. package/src/security/binding-policy.ts +1 -2
  100. package/src/security/claude-credential.ts +355 -0
  101. package/src/security/credential-broker.ts +56 -40
  102. package/src/security/evidence-redaction.ts +179 -4
  103. package/src/security/opencode-secret-manifest.ts +114 -0
  104. package/src/security/published-text.ts +161 -0
  105. package/src/security/redact.ts +45 -0
  106. package/src/system-tools.ts +48 -21
  107. package/src/transport-registry.ts +12 -2
  108. package/src/transports/claude-code-cli.ts +21 -2
  109. package/src/transports/opencode-sdk.ts +11 -9
  110. package/src/transports/opencode-server.ts +7 -10
  111. package/src/triage/triage.ts +2 -1
  112. package/src/ui/config-edit.ts +9 -20
  113. package/src/ui/config.ts +32 -27
  114. package/src/ui/plan.ts +76 -47
  115. package/src/updater.ts +10 -7
  116. package/prompts/default/deep-review-lifecycle.md +0 -362
@@ -0,0 +1,465 @@
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
+ // `traceContent` is present, and true, only when the platform sent exactly
108
+ // `true`; the connect step reads absence as false.
109
+ | {
110
+ ok: true;
111
+ githubToken: string;
112
+ runToken: string;
113
+ githubActor?: string;
114
+ dataMode?: PlatformDataMode;
115
+ traceContent?: true;
116
+ config?: PlatformConfig;
117
+ }
118
+ // `message` names the HTTP status and the API's own `message` when there was
119
+ // one. It never carries a token.
120
+ | { ok: false; message: string };
121
+
122
+ export interface PlatformTokenDeps {
123
+ fetch: typeof fetch;
124
+ env: Readonly<Record<string, string | undefined>>;
125
+ baseUrl: string;
126
+ // Called with each secret as soon as it is known, before it is used or
127
+ // returned, so the caller can emit `::add-mask::` ahead of any other write.
128
+ mask: (secret: string) => void;
129
+ // Waits between OIDC attempts; tests inject a no-op.
130
+ sleep?: (ms: number) => Promise<void>;
131
+ // The refresh steps never use the configuration in their response, so they
132
+ // set this and a config of the wrong shape cannot turn a finished job red.
133
+ ignoreConfig?: boolean;
134
+ }
135
+
136
+ // The OIDC GET is idempotent, so a blip (a thrown fetch, a timeout, a 5xx) is
137
+ // retried; the platform POST below is NOT: the platform refuses a second
138
+ // exchange of the same OIDC token (HTTP 409, keyed on its jti). Every run of
139
+ // this script asks GitHub for a NEW OIDC token, so a later step can exchange
140
+ // again for a fresh installation token; a retry of the POST could not.
141
+ const OIDC_ATTEMPTS = 3;
142
+ const OIDC_BACKOFF_MS = 1_000;
143
+
144
+ async function fetchOidc(
145
+ deps: PlatformTokenDeps,
146
+ url: string,
147
+ requestToken: string,
148
+ ): Promise<Response> {
149
+ const sleep =
150
+ deps.sleep ??
151
+ ((ms: number) => {
152
+ const { promise, resolve } = Promise.withResolvers<void>();
153
+ setTimeout(resolve, ms);
154
+ return promise;
155
+ });
156
+ for (let attempt = 1; ; attempt++) {
157
+ try {
158
+ const response = await deps.fetch(url, {
159
+ headers: { Authorization: `bearer ${requestToken}` },
160
+ signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),
161
+ });
162
+ if (response.status < 500 || attempt === OIDC_ATTEMPTS) return response;
163
+ } catch (error) {
164
+ if (attempt === OIDC_ATTEMPTS) throw error;
165
+ }
166
+ await sleep(OIDC_BACKOFF_MS * attempt);
167
+ }
168
+ }
169
+
170
+ // A token is written to $GITHUB_OUTPUT as `name=value`, so one that holds a
171
+ // line break or any other whitespace could plant a second output. Installation
172
+ // and run tokens are printable ASCII; refuse anything else.
173
+ const SAFE_TOKEN = /^[\x21-\x7e]+$/;
174
+
175
+ function failure(
176
+ message: string,
177
+ secrets: readonly string[],
178
+ ): PlatformTokenResult {
179
+ let safe = message;
180
+ for (const secret of secrets) {
181
+ if (secret !== "") safe = safe.split(secret).join("***");
182
+ }
183
+ return { ok: false, message: safe };
184
+ }
185
+
186
+ // The API's `{ message }`, when the body is JSON and has one.
187
+ async function apiMessage(response: Response): Promise<string | undefined> {
188
+ try {
189
+ const body: unknown = await response.json();
190
+ if (typeof body === "object" && body !== null && "message" in body) {
191
+ const { message } = body as { message: unknown };
192
+ if (typeof message === "string" && message !== "") return message;
193
+ }
194
+ } catch {
195
+ // Not JSON: the status alone names the failure.
196
+ }
197
+ return undefined;
198
+ }
199
+
200
+ export async function exchangePlatformToken(
201
+ deps: PlatformTokenDeps,
202
+ ): Promise<PlatformTokenResult> {
203
+ const requestUrl = deps.env.ACTIONS_ID_TOKEN_REQUEST_URL ?? "";
204
+ const requestToken = deps.env.ACTIONS_ID_TOKEN_REQUEST_TOKEN ?? "";
205
+ const dispatchId = deps.env.CRYSK_DISPATCH_ID ?? "";
206
+ if (requestUrl === "" || requestToken === "") {
207
+ return { ok: false, message: MISSING_OIDC };
208
+ }
209
+ // The runner already masks its own request token, and the secrets list keeps
210
+ // it out of any message a failure builds.
211
+ const secrets: string[] = [requestToken];
212
+
213
+ try {
214
+ const oidcResponse = await fetchOidc(
215
+ deps,
216
+ `${requestUrl}${requestUrl.includes("?") ? "&" : "?"}audience=${OIDC_AUDIENCE}`,
217
+ requestToken,
218
+ );
219
+ if (!oidcResponse.ok) {
220
+ return failure(
221
+ `GitHub's OIDC endpoint answered HTTP ${oidcResponse.status}; the run could not obtain an identity token.`,
222
+ secrets,
223
+ );
224
+ }
225
+ const oidcBody = (await oidcResponse.json()) as { value?: unknown };
226
+ const oidc = oidcBody.value;
227
+ if (typeof oidc !== "string" || oidc === "") {
228
+ return failure("GitHub's OIDC endpoint returned no token.", secrets);
229
+ }
230
+ deps.mask(oidc);
231
+ secrets.push(oidc);
232
+
233
+ const response = await deps.fetch(`${deps.baseUrl}/runs/token`, {
234
+ method: "POST",
235
+ headers: {
236
+ Authorization: `Bearer ${oidc}`,
237
+ "X-Crysk-Dispatch-Id": dispatchId,
238
+ },
239
+ signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),
240
+ });
241
+ if (!response.ok) {
242
+ const message = await apiMessage(response);
243
+ return failure(
244
+ `The Crysk platform refused the token exchange: HTTP ${response.status}${message === undefined ? "" : ` — ${message}`}`,
245
+ secrets,
246
+ );
247
+ }
248
+ const body = (await response.json()) as {
249
+ github_token?: unknown;
250
+ run_token?: unknown;
251
+ github_actor?: unknown;
252
+ data_mode?: unknown;
253
+ trace_content?: unknown;
254
+ config?: unknown;
255
+ };
256
+ const {
257
+ github_token: githubToken,
258
+ run_token: runToken,
259
+ github_actor: actor,
260
+ data_mode: dataMode,
261
+ } = body;
262
+ // Mask whatever string arrived before judging it, so a malformed reply
263
+ // still cannot leak a token into the log.
264
+ for (const value of [githubToken, runToken]) {
265
+ if (typeof value === "string" && value !== "") deps.mask(value);
266
+ }
267
+ if (
268
+ typeof githubToken !== "string" ||
269
+ typeof runToken !== "string" ||
270
+ !SAFE_TOKEN.test(githubToken) ||
271
+ !SAFE_TOKEN.test(runToken)
272
+ ) {
273
+ return failure(
274
+ "The Crysk platform answered HTTP 200 without a usable github_token and run_token.",
275
+ [...secrets, String(githubToken), String(runToken)],
276
+ );
277
+ }
278
+ const config: ReturnType<typeof parsePlatformConfig> =
279
+ deps.ignoreConfig === true
280
+ ? { ok: true }
281
+ : parsePlatformConfig(body.config);
282
+ if (!config.ok) {
283
+ return failure(
284
+ `The Crysk platform answered HTTP 200 with a malformed config: ${config.message}`,
285
+ [...secrets, githubToken, runToken],
286
+ );
287
+ }
288
+ return {
289
+ ok: true,
290
+ githubToken,
291
+ runToken,
292
+ ...(typeof actor === "string" && SAFE_LOGIN.test(actor)
293
+ ? { githubActor: actor }
294
+ : {}),
295
+ ...(dataMode === "full" || dataMode === "metadata_only"
296
+ ? { dataMode }
297
+ : {}),
298
+ // WHY fail closed: whether a review trace may carry the customer's code
299
+ // is the platform's decision (`trace_content`, today its data mode), so
300
+ // an absent or malformed value sends metadata only.
301
+ ...(body.trace_content === true ? { traceContent: true as const } : {}),
302
+ ...(config.config === undefined ? {} : { config: config.config }),
303
+ };
304
+ } catch (error) {
305
+ const detail = error instanceof Error ? error.message : String(error);
306
+ return failure(
307
+ `The Crysk platform token exchange could not complete: ${detail}`,
308
+ secrets,
309
+ );
310
+ }
311
+ }
312
+
313
+ // Workflow-command data escaping, as the runner's own toolkit does it.
314
+ function escapeCommandData(text: string): string {
315
+ return text.replace(/%/g, "%25").replace(/\r/g, "%0D").replace(/\n/g, "%0A");
316
+ }
317
+
318
+ export interface PlatformConnectDeps extends Omit<PlatformTokenDeps, "mask"> {
319
+ stdout: (text: string) => void;
320
+ appendOutput: (text: string) => void;
321
+ // Where the review configuration is left for the setup step. Set by the first
322
+ // connect step only: the refresh steps run after the review and must not touch
323
+ // it, so they leave this unset and the config in their response is ignored.
324
+ configDir?: string;
325
+ }
326
+
327
+ // Hands the platform's review configuration to the setup step as a 0600 file
328
+ // under the runner's temp directory (never the workspace). Returns the path.
329
+ function writePlatformConfig(dir: string, config: PlatformConfig): string {
330
+ const file = path.join(dir, PLATFORM_CONFIG_FILE_NAME);
331
+ mkdirSync(dir, { recursive: true, mode: 0o700 });
332
+ writeFileSync(file, `${JSON.stringify(config)}\n`, { mode: 0o600 });
333
+ return file;
334
+ }
335
+
336
+ // The step's shell. Every token is masked BEFORE the output is written, and a
337
+ // failure writes no output at all: the later steps see no platform token and the
338
+ // job is red, never silently on `github.token`.
339
+ export async function runPlatformConnect(
340
+ deps: PlatformConnectDeps,
341
+ ): Promise<number> {
342
+ const result = await exchangePlatformToken({
343
+ ...deps,
344
+ // Only the first connect step (it binds the config directory) uses it.
345
+ ignoreConfig: deps.configDir === undefined,
346
+ mask: (secret) => deps.stdout(`::add-mask::${escapeCommandData(secret)}\n`),
347
+ });
348
+ if (!result.ok) {
349
+ deps.stdout(
350
+ `::error title=crysk::${escapeCommandData(`Crysk platform mode failed: ${result.message}`)}\n`,
351
+ );
352
+ return 1;
353
+ }
354
+ // WHY the config file is written before any output: a failure writes no
355
+ // output at all, so a run whose configuration could not be applied never
356
+ // looks connected. The failure names the file, never a value.
357
+ let configFile: string | undefined;
358
+ if (result.config !== undefined && deps.configDir !== undefined) {
359
+ try {
360
+ configFile = writePlatformConfig(deps.configDir, result.config);
361
+ } catch (error) {
362
+ const detail = error instanceof Error ? error.message : String(error);
363
+ deps.stdout(
364
+ `::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`,
365
+ );
366
+ return 1;
367
+ }
368
+ }
369
+ // WHY a throw is an error and not a green step: the later steps read this
370
+ // output with `|| inputs.github-token`, so a token that was never written
371
+ // would silently post as github-actions[bot].
372
+ try {
373
+ // WHY fail closed: `data-mode` decides whether the report step may send
374
+ // finding text at all (src/ci/platform-report.ts), and a repository in
375
+ // metadata-only mode must never have its code leave the runner. A missing
376
+ // or unrecognised value therefore reads as metadata_only, with a notice.
377
+ // Written by EVERY exchange, refresh steps included: the report step reads
378
+ // the freshest one (the publish refresh, minted after the run), because the
379
+ // first token can be 75 minutes old and the repository's mode may have
380
+ // been switched to metadata_only since.
381
+ // WHY first: the report step pairs this exchange's run token with this
382
+ // exchange's data mode. Appends are not atomic, so if one throws the step
383
+ // fails; with the mode written before the tokens, a refresh that left a
384
+ // run token always left its mode, and the report never pairs a fresh
385
+ // token with the stale first-exchange mode.
386
+ deps.appendOutput(`data-mode=${result.dataMode ?? "metadata_only"}\n`);
387
+ // The trace step (src/ci/platform-trace.ts) pairs it with this exchange's
388
+ // run token, like the report step does data-mode, so it is written before
389
+ // the tokens for the same reason.
390
+ deps.appendOutput(`trace-content=${result.traceContent === true}\n`);
391
+ if (result.dataMode === undefined) {
392
+ deps.stdout(
393
+ "::notice title=crysk::The Crysk platform sent no recognised data_mode; treating this repository as metadata_only, so no finding text is uploaded.\n",
394
+ );
395
+ }
396
+ deps.appendOutput(`github-token=${result.githubToken}\n`);
397
+ // The run token authenticates the report step (src/ci/platform-report.ts).
398
+ // Already masked by the exchange above, like the installation token.
399
+ deps.appendOutput(`run-token=${result.runToken}\n`);
400
+ // Not a secret. Only a login the platform returned, so the engine's trust
401
+ // set never learns one from anywhere else (see CRYSK_PLATFORM_ACTOR).
402
+ if (result.githubActor !== undefined) {
403
+ deps.appendOutput(`github-actor=${result.githubActor}\n`);
404
+ }
405
+ // Present only when there is configuration to apply: the setup step and the
406
+ // run step are gated on it, so a standalone run (no platform step, no
407
+ // output) and an empty config both skip everything.
408
+ if (configFile !== undefined) {
409
+ deps.appendOutput(`config-file=${configFile}\n`);
410
+ // Whether the models in effect name OpenCode (S1): an `opencode:` model
411
+ // needs the CLI installed. Present whenever the platform sent a non-empty
412
+ // person layer, `false` included, because that layer wins whole over the
413
+ // `models` and `credentials` inputs (D1; the setup step ignores them),
414
+ // so a layer with no models leaves the default models in effect. The
415
+ // trigger's backend flag in action.yml reads an empty output as "use the
416
+ // input's" (`contains(inputs.models, 'opencode:')`) and any value as the
417
+ // platform's answer. The OpenCode install step also reads the setup
418
+ // step's `opencode-models`, its own reading of the models in effect. A
419
+ // platform `routing` is refused by the setup step's person parser.
420
+ const person = result.config?.person ?? {};
421
+ if (Object.keys(person).length > 0) {
422
+ const models = person.models;
423
+ const opencode =
424
+ models !== undefined && JSON.stringify(models).includes('"opencode:');
425
+ deps.appendOutput(`routing-opencode=${opencode}\n`);
426
+ }
427
+ }
428
+ } catch (error) {
429
+ const detail = error instanceof Error ? error.message : String(error);
430
+ deps.stdout(
431
+ `::error title=crysk::${escapeCommandData(`Crysk platform mode failed: the installation token could not be handed to the later steps: ${detail}`)}\n`,
432
+ );
433
+ return 1;
434
+ }
435
+ return 0;
436
+ }
437
+
438
+ // Appends to the file the runner named in GITHUB_OUTPUT. Unset or empty is an
439
+ // error, not a no-op: see runPlatformConnect.
440
+ export function appendGithubOutput(
441
+ outputPath: string | undefined,
442
+ text: string,
443
+ ): void {
444
+ if (outputPath === undefined || outputPath === "") {
445
+ throw new Error("GITHUB_OUTPUT is not set");
446
+ }
447
+ appendFileSync(outputPath, text);
448
+ }
449
+
450
+ if (import.meta.main) {
451
+ process.exit(
452
+ await runPlatformConnect({
453
+ fetch,
454
+ env: process.env,
455
+ baseUrl: PLATFORM_API_URL,
456
+ stdout: (text) => process.stdout.write(text),
457
+ appendOutput: (text) =>
458
+ appendGithubOutput(process.env.GITHUB_OUTPUT, text),
459
+ // Bound by the connect step only (action.yml), never by a refresh step.
460
+ ...(process.env.CRYSK_PLATFORM_CONFIG_DIR
461
+ ? { configDir: process.env.CRYSK_PLATFORM_CONFIG_DIR }
462
+ : {}),
463
+ }),
464
+ );
465
+ }
package/src/ci/publish.ts CHANGED
@@ -215,7 +215,7 @@ export function decidePublication(input: {
215
215
  return { kind: "none" };
216
216
  }
217
217
  // WHY before the outcome fallthrough below: an override is not an error, and
218
- // rendering it as one would publish a false PRH-INSTALL-FAILED.
218
+ // rendering it as one would publish a false CRYSK-INSTALL-FAILED.
219
219
  if (record.decision === "override") return decideOverride(record);
220
220
  if (record.decision === "review" && input.cliStarted) {
221
221
  return decideCliOutcome(record, input.cliRecord, input.latestStatusState);
@@ -412,7 +412,7 @@ function huntersFailedRendering(
412
412
  if (rendered !== undefined) return rendered;
413
413
  }
414
414
  return renderCode(
415
- "PRH-HUNTERS-FAILED",
415
+ "CRYSK-HUNTERS-FAILED",
416
416
  { ...runParams, step: REVIEW_STEP, detail: sharedDetail ?? HUNTERS_DETAIL },
417
417
  "action",
418
418
  // Every hunter was refused for the size of the request: the fix is a smaller review.
@@ -474,6 +474,15 @@ function renderRecordOutcome(
474
474
  "action",
475
475
  );
476
476
  }
477
+ // The record's detail names the removed inputs; the class is the publisher's own,
478
+ // like a missing credential's.
479
+ if (record.decision === "removed-inputs") {
480
+ return renderError(
481
+ { kind: "trigger", check: "removed-input" },
482
+ params,
483
+ "action",
484
+ );
485
+ }
477
486
  if (record.decision === "unverifiable") {
478
487
  // WHY the step name: a lookup with no captured status has no class to
479
488
  // render, and "stopped at this step" needs a step to name.
@@ -516,7 +525,7 @@ function clipStatusDescription(text: string): string {
516
525
  // before its signal settle lands, so the publisher writes this instead of leaving the head
517
526
  // pending. It names the cancel and the way to review the head again.
518
527
  export const CANCELLED_STATUS_DESCRIPTION =
519
- "PRH-CANCELLED: not reviewed — /pr-hero review reviews this head";
528
+ "CRYSK-CANCELLED: not reviewed — /crysk review reviews this head";
520
529
 
521
530
  // The run URL identifies the pending (SB3 follow-up). A pending the CLI posted in Actions carries
522
531
  // its run's attempt URL (actionsRunUrl, src/ci/cli-record.ts), and the settle is this run's only
@@ -662,7 +671,7 @@ function statusWriteFailure(
662
671
  ? "server"
663
672
  : undefined;
664
673
  return renderCode(
665
- "PRH-STATUS-WRITE-FAILED",
674
+ "CRYSK-STATUS-WRITE-FAILED",
666
675
  {
667
676
  detail:
668
677
  httpStatus === undefined
@@ -1313,7 +1322,11 @@ export function runPublish(deps: PublishDeps): number {
1313
1322
  if (cliStarted) return 0;
1314
1323
  report(
1315
1324
  deps,
1316
- renderCode("PRH-UNCLASSIFIED", { step: "the outcome record" }, "action"),
1325
+ renderCode(
1326
+ "CRYSK-UNCLASSIFIED",
1327
+ { step: "the outcome record" },
1328
+ "action",
1329
+ ),
1317
1330
  );
1318
1331
  return 1;
1319
1332
  }
@@ -1525,7 +1538,7 @@ export function runCancelSettle(deps: PublishDeps): number {
1525
1538
  deps.stdout(
1526
1539
  workflowCommand(
1527
1540
  "notice",
1528
- "the review was cancelled; the crysk status is now PRH-CANCELLED",
1541
+ "the review was cancelled; the crysk status is now CRYSK-CANCELLED",
1529
1542
  ),
1530
1543
  );
1531
1544
  } else {
@@ -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
- ? `\`${loc}\``
277
- : `[\`${loc}\`](${blobUrl(webUrl, headSha, finding.path, `L${finding.line}`)})`;
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 the last verdict.",
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(`**\`${filePath}\`**`);
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 plus optional repo-config extras. Undefined when no
171
- // actor is known — callers treat that as "do not filter by author".
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
- if (input.githubActor !== undefined && input.githubActor.length > 0) {
178
- actors.add(input.githubActor);
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);
@@ -214,12 +214,13 @@ export function defaultChoices(): CiSetupChoices {
214
214
  }
215
215
 
216
216
  // The `budget-usd` workflow input for these choices, or undefined to write none.
217
- // A subscription writes none. CI bills as metered only when a non-empty
218
- // ANTHROPIC_API_KEY (or ANTHROPIC_AUTH_TOKEN) is present (envBillsMetered), so
219
- // a subscription-only repo already gets no ceiling. An explicit 0 would print
220
- // the disabled-ceiling warning on every run and, worse, stay an operator
221
- // override if an API key is added later, defeating the $10 fail-safe that the
222
- // key's mere presence is meant to bring back (gates.ts, CiBillingMode).
217
+ // A subscription writes none. CI bills as metered only when the run's chosen
218
+ // Claude credential is the API key (S5: the first of `credentials.claude` that is
219
+ // present, default subscription then api_key; gates.ts, CiBillingMode), so a
220
+ // subscription run already gets no ceiling. An explicit 0 would print the
221
+ // disabled-ceiling warning on every run and, worse, stay an operator override if
222
+ // the run later moves to an API key, defeating the $10 fail-safe a metered run
223
+ // brings back.
223
224
  export function budgetInput(choices: CiSetupChoices): string | undefined {
224
225
  if (choices.billing === "api") {
225
226
  return String(choices.budgetUsd ?? CI_DEFAULT_METERED_BUDGET_USD);
@@ -301,7 +302,7 @@ export function renderChoicesSummary(
301
302
  ` budget ${
302
303
  budget === undefined
303
304
  ? choices.billing === "subscription"
304
- ? "not set: no ceiling while the repo has no ANTHROPIC_API_KEY or OPENCODE_AUTH_JSON secret (a subscription spends quota, not dollars); adding either brings back the $10 ceiling"
305
+ ? "not set: no ceiling while the review runs on CRYSK_CLAUDE_OAUTH_TOKEN and no OpenCode model (a subscription spends quota, not dollars); CRYSK_CLAUDE_API_KEY chosen in its place, or an OpenCode model with its CRYSK_OPENCODE_* secret, brings back the $10 ceiling"
305
306
  : "not set: resolved from how the review is paid (no ceiling on a subscription, $10 on an API key)"
306
307
  : Number(budget) <= 0
307
308
  ? `none (budget-usd: ${budget}; 0 or less disables the ceiling)`