crysk 0.6.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,163 @@
1
+ # Generated by `crysk setup --ci` (or `crysk ci init`).
2
+ # Customize freely — re-running setup will not overwrite this file again
3
+ # unless you pass --force.
4
+ #
5
+ # This one file is the whole install. It reviews every push to a pull
6
+ # request. A pull request comment that is exactly `/crysk review` runs the
7
+ # review again with the skip gates bypassed, and `/crysk review --full`
8
+ # also re-discovers the whole range. A comment that is exactly
9
+ # `/crysk override` turns the gate green on that head with no review and
10
+ # no cost, and records who did it. A comment that is exactly
11
+ # `/crysk recheck` reviews the head and asks the CI adjudicator to rule on
12
+ # pending dismissals of blocking findings. The action parses the comment and
13
+ # refuses a commenter without write access. The older `/pr-hero ...` forms
14
+ # of these commands still work for one version.
15
+ name: Crysk Review
16
+
17
+ on:
18
+ pull_request:
19
+ types: [opened, synchronize, reopened]
20
+ # GitHub runs a comment-triggered workflow from the DEFAULT branch's copy
21
+ # of this file, never the pull request's. The comment trigger works only
22
+ # once this file is merged there; until then a comment starts nothing.
23
+ issue_comment:
24
+ types: [created]
25
+
26
+ # pull-requests: write lets Crysk post inline comments and a step summary.
27
+ # contents: read is enough for actions/checkout. issues: write lets it
28
+ # resolve/reply on review threads (GitHub models PR conversations as issues).
29
+ # checks: write persists the durable CI admission attempt ledger (WU-02).
30
+ # actions: read lets the admission gate list this workflow's past runs; a
31
+ # public repo serves that without the scope, a private one returns HTTP 403.
32
+ permissions:
33
+ actions: read
34
+ contents: read
35
+ pull-requests: write
36
+ issues: write
37
+ statuses: write
38
+ checks: write
39
+
40
+ jobs:
41
+ review:
42
+ # This `if` routes events; it never checks credentials. The secrets
43
+ # context is unreadable in a job-level `if`, so the action detects a
44
+ # missing credential itself and fails the run with the commands that
45
+ # fix it, instead of a skipped job that reads as a clean review.
46
+ #
47
+ # Fork pull_request runs are skipped: GitHub gives them no secrets, so
48
+ # they could never authenticate. A maintainer comments `/crysk review`
49
+ # instead, and that run (base-branch context, with secrets) reviews the
50
+ # fork's head.
51
+ #
52
+ # A comment starts the job only when it BEGINS with `/crysk review`,
53
+ # `/crysk recheck` or `/crysk override` (or the older `/pr-hero` forms
54
+ # of the three). The action then requires an exact match after
55
+ # trimming, so a near-miss such as "/crysk review please" starts a job the
56
+ # action ends without reviewing or overriding.
57
+ if: >-
58
+ (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository) ||
59
+ (github.event_name == 'issue_comment' && github.event.issue.pull_request && startsWith(github.event.comment.body, '/crysk review')) ||
60
+ (github.event_name == 'issue_comment' && github.event.issue.pull_request && startsWith(github.event.comment.body, '/crysk recheck')) ||
61
+ (github.event_name == 'issue_comment' && github.event.issue.pull_request && startsWith(github.event.comment.body, '/crysk override')) ||
62
+ (github.event_name == 'issue_comment' && github.event.issue.pull_request && startsWith(github.event.comment.body, '/pr-hero review')) ||
63
+ (github.event_name == 'issue_comment' && github.event.issue.pull_request && startsWith(github.event.comment.body, '/pr-hero recheck')) ||
64
+ (github.event_name == 'issue_comment' && github.event.issue.pull_request && startsWith(github.event.comment.body, '/pr-hero override'))
65
+ # Job-level and keyed on the pull request number. A workflow-level group
66
+ # on `github.head_ref || github.ref` put every comment on every pull
67
+ # request into ONE group, because head_ref is empty on issue_comment, so
68
+ # any comment anywhere could cancel any in-flight review.
69
+ #
70
+ # Only a new push cancels. The group filter is a prefix, so a near-miss
71
+ # comment can claim the pull request's group too; cancelling there would
72
+ # kill a paid in-flight review before the action ignored the comment. A
73
+ # comment run queues instead. A push never waits: it cancels whatever is
74
+ # running, a forced comment run included, because the head it reviewed
75
+ # is gone (comment again on the new head).
76
+ #
77
+ # GitHub keeps one PENDING run per group, and a newer run replaces it. So
78
+ # a comment enters the pull request's group only when it starts with
79
+ # /crysk review, /crysk recheck or /crysk override (or the older /pr-hero forms), and GitHub associates its author
80
+ # with the repository as OWNER, MEMBER or COLLABORATOR; every other comment
81
+ # gets its own group. Without that, anyone who can comment could replace a
82
+ # maintainer's queued review with a run the action then refuses. The job
83
+ # `if:` above does NOT check the association: a writer GitHub reports
84
+ # under another one (a private org member shown as CONTRIBUTOR) still
85
+ # runs, because the action checks the real permission, just in its own
86
+ # group. KNOWN GAP: an associated author's later comment (a writer's
87
+ # near-miss or second real command, or a read-only member's or
88
+ # collaborator's refused one) still replaces a comment run waiting
89
+ # behind a running review, and `--full` followed by a plain
90
+ # `/crysk review` loses the `--full`; comment again to recover. A
91
+ # writer reported under another association runs unserialized, beside
92
+ # any review already running.
93
+ #
94
+ # A fork's push never enters the pull request's group: its job is skipped
95
+ # above, and if a skipped job still claimed the group, the fork author's
96
+ # push would cancel a maintainer's in-flight review of that fork. Every
97
+ # other event gets a unique per-run group for the same reason, so a
98
+ # skipped job can never cancel or replace a review.
99
+ concurrency:
100
+ group: ${{ ((github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository) || (startsWith(github.event.comment.body, '/crysk review') && contains(fromJSON('["OWNER","MEMBER","COLLABORATOR"]'), github.event.comment.author_association)) || (startsWith(github.event.comment.body, '/crysk recheck') && contains(fromJSON('["OWNER","MEMBER","COLLABORATOR"]'), github.event.comment.author_association)) || (startsWith(github.event.comment.body, '/crysk override') && contains(fromJSON('["OWNER","MEMBER","COLLABORATOR"]'), github.event.comment.author_association)) || (startsWith(github.event.comment.body, '/pr-hero review') && contains(fromJSON('["OWNER","MEMBER","COLLABORATOR"]'), github.event.comment.author_association)) || (startsWith(github.event.comment.body, '/pr-hero recheck') && contains(fromJSON('["OWNER","MEMBER","COLLABORATOR"]'), github.event.comment.author_association)) || (startsWith(github.event.comment.body, '/pr-hero override') && contains(fromJSON('["OWNER","MEMBER","COLLABORATOR"]'), github.event.comment.author_association))) && format('pr-hero-review-{0}', github.event.pull_request.number || github.event.issue.number) || format('pr-hero-noop-{0}', github.run_id) }}
101
+ cancel-in-progress: ${{ github.event_name == 'pull_request' }}
102
+ runs-on: ubuntu-latest
103
+ # Backstop for a HUNG runner, not a second review budget. Crysk already
104
+ # enforces its own 75-minute whole-pipeline ceiling, which closes
105
+ # artifacts and reports before exiting; a CI bound at or below that would
106
+ # kill the job first and throw away the salvage. Above it, this only ever
107
+ # fires when the process is genuinely stuck.
108
+ timeout-minutes: 90
109
+ steps:
110
+ - name: Checkout
111
+ uses: actions/checkout@v4
112
+ with:
113
+ # fetch-depth: 0 is load-bearing, not cosmetic: Crysk computes
114
+ # the pull request's diff range and commit ancestry from full git
115
+ # history. actions/checkout's default is a SHALLOW clone, which
116
+ # cannot produce an accurate diff or blame — trimming this line
117
+ # does not fail loudly, it makes reviews silently miss context.
118
+ fetch-depth: 0
119
+
120
+ - name: Run Crysk
121
+ # The id keeps this step's outputs (`status`, `run-dir`, ...)
122
+ # readable from any step you add below.
123
+ # The action uploads the run directory as an artifact itself, so
124
+ # `crysk triage reply --from` has an input in CI (see action.yml).
125
+ id: pr-hero
126
+ uses: cryskai/crysk@v0
127
+ with:
128
+ github-token: ${{ secrets.GITHUB_TOKEN }}
129
+ # The Crysk credentials: one CRYSK_* secret per line, each named
130
+ # explicitly (never the whole secrets context, which would hand the
131
+ # action every secret of the repository). A secret the repository does not have
132
+ # arrives empty and counts as absent, so every line stays. With
133
+ # both Claude secrets set, credentials.claude picks one (the subscription first).
134
+ # CRYSK_CLAUDE_OAUTH_TOKEN — from `claude setup-token`: a long-lived
135
+ # (~1 year) token that draws on your Claude subscription. The
136
+ # session token `/login` leaves in the keychain expires in hours.
137
+ # CRYSK_CLAUDE_API_KEY — pay-as-you-go key (billed per token).
138
+ # CRYSK_OPENCODE_OPENAI_OAUTH — an OpenAI (ChatGPT) subscription for
139
+ # OpenCode: the openai record of OpenCode's auth.json, base64 on one line.
140
+ # CRYSK_OPENCODE_<PROVIDER>_API_KEY — an OpenCode provider's API key,
141
+ # <PROVIDER> being its id uppercased with - and . as _. The 5
142
+ # lines after the fixed ones forward the providers listed in
143
+ # vars.CRYSK_OPENCODE_PROVIDERS (a JSON array, e.g. ["DEEPSEEK"]);
144
+ # an unused line renders as CRYSK_OPENCODE__API_KEY= and is skipped.
145
+ # `crysk ci init` prints the commands that set these secrets and variables.
146
+ crysk-secrets: |
147
+ CRYSK_CLAUDE_OAUTH_TOKEN=${{ secrets.CRYSK_CLAUDE_OAUTH_TOKEN }}
148
+ CRYSK_CLAUDE_API_KEY=${{ secrets.CRYSK_CLAUDE_API_KEY }}
149
+ CRYSK_OPENCODE_OPENAI_OAUTH=${{ secrets.CRYSK_OPENCODE_OPENAI_OAUTH }}
150
+ CRYSK_OPENCODE_${{ fromJSON(vars.CRYSK_OPENCODE_PROVIDERS || '[]')[0] }}_API_KEY=${{ secrets[format('CRYSK_OPENCODE_{0}_API_KEY', fromJSON(vars.CRYSK_OPENCODE_PROVIDERS || '[]')[0])] }}
151
+ CRYSK_OPENCODE_${{ fromJSON(vars.CRYSK_OPENCODE_PROVIDERS || '[]')[1] }}_API_KEY=${{ secrets[format('CRYSK_OPENCODE_{0}_API_KEY', fromJSON(vars.CRYSK_OPENCODE_PROVIDERS || '[]')[1])] }}
152
+ CRYSK_OPENCODE_${{ fromJSON(vars.CRYSK_OPENCODE_PROVIDERS || '[]')[2] }}_API_KEY=${{ secrets[format('CRYSK_OPENCODE_{0}_API_KEY', fromJSON(vars.CRYSK_OPENCODE_PROVIDERS || '[]')[2])] }}
153
+ CRYSK_OPENCODE_${{ fromJSON(vars.CRYSK_OPENCODE_PROVIDERS || '[]')[3] }}_API_KEY=${{ secrets[format('CRYSK_OPENCODE_{0}_API_KEY', fromJSON(vars.CRYSK_OPENCODE_PROVIDERS || '[]')[3])] }}
154
+ CRYSK_OPENCODE_${{ fromJSON(vars.CRYSK_OPENCODE_PROVIDERS || '[]')[4] }}_API_KEY=${{ secrets[format('CRYSK_OPENCODE_{0}_API_KEY', fromJSON(vars.CRYSK_OPENCODE_PROVIDERS || '[]')[4])] }}
155
+ # The models per role and the Claude credential order, as JSON, from
156
+ # repository variables. Unset, every role runs the default Claude model
157
+ # and the subscription is tried first.
158
+ models: ${{ vars.CRYSK_MODELS }}
159
+ credentials: ${{ vars.CRYSK_CREDENTIALS }}
160
+ # The model profile (claude or openai) from a repository variable.
161
+ # Unset, the claude profile. models still wins role by role.
162
+ profile: ${{ vars.CRYSK_PROFILE }}
163
+ mode: gate
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "crysk",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "private": false,
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -66,7 +66,7 @@ exactly two ways:
66
66
  - **A fix**, pushed to the head and verified gone by the next review.
67
67
  - **A dismissal the CI adjudicator upholds.** You reply `dismissed`, comment `/crysk recheck`, an
68
68
  adjudicator running in CI rules on your argument, and only its `upheld` (posted by
69
- `github-actions[bot]` on that head) lets the next review stop counting the finding. See
69
+ `github-actions[bot]`, or by the Crysk App's bot on a platform-managed repository, on that head) lets the next review stop counting the finding. See
70
70
  "Closing a dismissal" below.
71
71
 
72
72
  **When no review is left, answers unlock the gate.** Every review rule that skips a push (the
@@ -297,7 +297,7 @@ adjudicator. When step 0 says `recheck`:
297
297
  reads your argument and the repository at that head. You may comment it yourself: you only supply
298
298
  the argument, the CI adjudicator rules. (`/crysk override` is the opposite: never yours to post.)
299
299
  2. Wait with `npx -y crysk status --pr <n> --wait --json` until the run settles. Each ruling is a reply on the finding's thread,
300
- from `github-actions[bot]`, whose first line is
300
+ from `github-actions[bot]` (the Crysk App's bot on a platform-managed repository), whose first line is
301
301
  `<!-- crysk-adjudication verdict=<v> reply=<your reply's id> head=<sha> -->`. Step 0's
302
302
  `ci_verdict` reads it for you.
303
303
  3. Act on the verdict:
package/src/assets.ts CHANGED
@@ -74,14 +74,37 @@ function resolveVersion(): string {
74
74
  // Ignore read errors
75
75
  }
76
76
 
77
- return "0.6.0";
77
+ return "0.6.1";
78
+ }
79
+
80
+ // Bun file imports can emit "./name-hash.ext" in bundled npm builds.
81
+ // Resolve those filenames against the emitting module, never the consumer CWD.
82
+ export function resolveBundledFilePath(
83
+ filePath: string,
84
+ moduleDir: string = import.meta.dir,
85
+ ): string {
86
+ return path.isAbsolute(filePath)
87
+ ? filePath
88
+ : path.resolve(moduleDir, filePath);
89
+ }
90
+
91
+ function resolveBundledFileMap(
92
+ files: Record<string, string>,
93
+ ): Record<string, string> {
94
+ return Object.fromEntries(
95
+ Object.entries(files).map(([name, file]) => [
96
+ name,
97
+ resolveBundledFilePath(file),
98
+ ]),
99
+ );
78
100
  }
79
101
 
80
102
  export function resolveEngineAssets(): EngineAssets {
81
103
  const mode = detectAssetMode();
82
104
  const version = resolveVersion();
83
105
 
84
- let defaultAgentsDir = path.dirname(BUNDLED_AGENT_FILES["review-refuter.md"]);
106
+ const bundledAgentFiles = resolveBundledFileMap(BUNDLED_AGENT_FILES);
107
+ let defaultAgentsDir = path.dirname(bundledAgentFiles["review-refuter.md"]);
85
108
  if (mode !== "compiled") {
86
109
  const fsDefaultDir = path.resolve(import.meta.dir, "../prompts/default");
87
110
  if (existsSync(fsDefaultDir)) {
@@ -91,16 +114,16 @@ export function resolveEngineAssets(): EngineAssets {
91
114
 
92
115
  return {
93
116
  mode,
94
- bundledAgentFiles: BUNDLED_AGENT_FILES,
117
+ bundledAgentFiles,
95
118
  defaultAgentsDir,
96
- consolidatePromptPath: CONSOLIDATE_PROMPT_PATH,
97
- materialityPromptPath: MATERIALITY_PROMPT_PATH,
98
- scoutPromptPath: SCOUT_PROMPT_PATH,
99
- summarizerPromptPath: SUMMARIZER_PROMPT_PATH,
100
- triageSkillFiles: TRIAGE_SKILL_FILES,
101
- ciSetupSkillFiles: CI_SETUP_SKILL_FILES,
102
- prSkillFiles: PR_SKILL_FILES,
103
- generalSkillFiles: GENERAL_SKILL_FILES,
119
+ consolidatePromptPath: resolveBundledFilePath(CONSOLIDATE_PROMPT_PATH),
120
+ materialityPromptPath: resolveBundledFilePath(MATERIALITY_PROMPT_PATH),
121
+ scoutPromptPath: resolveBundledFilePath(SCOUT_PROMPT_PATH),
122
+ summarizerPromptPath: resolveBundledFilePath(SUMMARIZER_PROMPT_PATH),
123
+ triageSkillFiles: resolveBundledFileMap(TRIAGE_SKILL_FILES),
124
+ ciSetupSkillFiles: resolveBundledFileMap(CI_SETUP_SKILL_FILES),
125
+ prSkillFiles: resolveBundledFileMap(PR_SKILL_FILES),
126
+ generalSkillFiles: resolveBundledFileMap(GENERAL_SKILL_FILES),
104
127
  version,
105
128
  };
106
129
  }
package/src/ci/gates.ts CHANGED
@@ -8,10 +8,8 @@
8
8
  // comment + marker + step-summary markdown + $GITHUB_OUTPUT, all from the
9
9
  // same numbers, so the shell has no decision left to make beyond "post it /
10
10
  // write it". `budgetDisabledWarningMessage` covers spec 3.1's disabled-
11
- // ceiling `::warning::` requirement. `ciExitCode` pins the assistant-posture
12
- // exit-code contract (spec 2.1): findings, even blocking ones, never fail
13
- // the job — only a fatal session failure or a genuine posting drop (design
14
- // D6) does.
11
+ // ceiling `::warning::` requirement. The exit-code contract (spec 2.1) lives
12
+ // in src/review/exit-code.ts, shared by every mode.
15
13
  //
16
14
  // This module does NOT reimplement the size gate — that gate (deterministic
17
15
  // line/file counting, exclusion globs, the whole cost-predictability
@@ -872,26 +870,6 @@ export function planCiReviewManualRequired(input: {
872
870
  };
873
871
  }
874
872
 
875
- // ---------------------------------------------------------------------------
876
- // Assistant posture — spec 2.1: "The CLI MUST NOT exit with a non-zero code
877
- // merely because findings (even `blocking` ones) were discovered ... exit
878
- // non-zero ONLY on fatal execution failures." `blockingCount` is accepted
879
- // and deliberately NEVER read: its only job is to let a test construct a
880
- // high-blocking-count input and assert the result is still 0, so a future
881
- // change that wires it into this function's logic (the exact regression
882
- // this rule guards against) fails that test rather than shipping silently.
883
- // ---------------------------------------------------------------------------
884
-
885
- export function ciExitCode(input: {
886
- sessionFailed: boolean;
887
- droppedFindingIds: number;
888
- blockingCount: number;
889
- }): 0 | 1 {
890
- if (input.sessionFailed) return 1;
891
- if (input.droppedFindingIds > 0) return 1;
892
- return 0;
893
- }
894
-
895
873
  // ---------------------------------------------------------------------------
896
874
  // CI headless shell's "reviewed" (non-skip) outcome (ROADMAP Pillar 3,
897
875
  // GitHub Actions) — the summary + outputs, and the pure "should I write"
@@ -133,6 +133,39 @@ export function parsePlatformConfig(
133
133
  // says. `full` is the only value that lets the report step send finding text.
134
134
  export type PlatformDataMode = "full" | "metadata_only";
135
135
 
136
+ // The PR comment command the platform dispatched this run for (odd/tasks/platform-commands.md
137
+ // in the platform repo, S2-S4). A platform-managed repository has no issue_comment trigger, so the
138
+ // platform checks the comment and its author, and names the command here; the trigger reads it
139
+ // from this step's outputs. Absent for an ordinary review, and for a name this engine does not know.
140
+ // An override keeps its name when the actor or head is unusable, so the trigger refuses it instead
141
+ // of running a review nobody asked for.
142
+ export type PlatformCommandAnswer =
143
+ | { name: "recheck" }
144
+ | { name: "override"; actor?: string; headSha?: string };
145
+
146
+ const SAFE_SHA = /^[0-9a-f]{40}([0-9a-f]{24})?$/;
147
+ // The override's actor is a commenter, who may be an Enterprise Managed User (`handle_shortcode`):
148
+ // the trigger's own GITHUB_LOGIN grammar (src/ci/trigger.ts), not SAFE_LOGIN, which is the App's.
149
+ const COMMAND_ACTOR = /^(?=.{1,91}$)[A-Za-z0-9][A-Za-z0-9_-]{0,90}(\[bot\])?$/;
150
+
151
+ function parsePlatformCommand(
152
+ value: unknown,
153
+ ): PlatformCommandAnswer | undefined {
154
+ if (typeof value !== "object" || value === null) return undefined;
155
+ const { name, actor, head_sha: headSha } = value as Record<string, unknown>;
156
+ if (name === "recheck") return { name };
157
+ if (name !== "override") return undefined;
158
+ return {
159
+ name,
160
+ ...(typeof actor === "string" && COMMAND_ACTOR.test(actor)
161
+ ? { actor }
162
+ : {}),
163
+ ...(typeof headSha === "string" && SAFE_SHA.test(headSha)
164
+ ? { headSha }
165
+ : {}),
166
+ };
167
+ }
168
+
136
169
  export type PlatformTokenResult =
137
170
  // `githubActor` is the login the platform says posts as the App's bot. It is
138
171
  // absent when the platform sent none or one that is not a plausible login.
@@ -152,6 +185,7 @@ export type PlatformTokenResult =
152
185
  traceContent?: true;
153
186
  config?: PlatformConfig;
154
187
  estimate?: PlatformEstimate;
188
+ command?: PlatformCommandAnswer;
155
189
  }
156
190
  // `message` names the HTTP status and the API's own `message` when there was
157
191
  // one. It never carries a token.
@@ -297,6 +331,7 @@ export async function exchangePlatformToken(
297
331
  trace_content?: unknown;
298
332
  config?: unknown;
299
333
  estimate?: unknown;
334
+ command?: unknown;
300
335
  };
301
336
  const {
302
337
  github_token: githubToken,
@@ -332,6 +367,7 @@ export async function exchangePlatformToken(
332
367
  }
333
368
  // An estimate is advice: one that does not parse is dropped and the
334
369
  // engine's own band decides, never a failed exchange.
370
+ const command = parsePlatformCommand(body.command);
335
371
  const estimate =
336
372
  deps.ignoreConfig === true
337
373
  ? undefined
@@ -352,6 +388,7 @@ export async function exchangePlatformToken(
352
388
  ...(body.trace_content === true ? { traceContent: true as const } : {}),
353
389
  ...(config.config === undefined ? {} : { config: config.config }),
354
390
  ...(estimate === undefined ? {} : { estimate }),
391
+ ...(command === undefined ? {} : { command }),
355
392
  };
356
393
  } catch (error) {
357
394
  const detail = error instanceof Error ? error.message : String(error);
@@ -454,6 +491,19 @@ export async function runPlatformConnect(
454
491
  if (result.githubActor !== undefined) {
455
492
  deps.appendOutput(`github-actor=${result.githubActor}\n`);
456
493
  }
494
+ // Not a secret: a known command name, a validated login and a validated sha. The trigger
495
+ // reads them as PLATFORM_COMMAND* (action.yml), from the first connect step only.
496
+ if (result.command !== undefined) {
497
+ deps.appendOutput(`command=${result.command.name}\n`);
498
+ if (result.command.name === "override") {
499
+ if (result.command.actor !== undefined) {
500
+ deps.appendOutput(`command-actor=${result.command.actor}\n`);
501
+ }
502
+ if (result.command.headSha !== undefined) {
503
+ deps.appendOutput(`command-head=${result.command.headSha}\n`);
504
+ }
505
+ }
506
+ }
457
507
  // Not a secret: two validated numbers and a basis. The run step's budget
458
508
  // gate reads it as CRYSK_PLATFORM_ESTIMATE in place of the engine's band.
459
509
  if (result.estimate !== undefined) {
package/src/ci/trigger.ts CHANGED
@@ -206,8 +206,20 @@ export interface CiTriggerInput {
206
206
  // EVENT_COMMENT_ID when it is all digits: the comment that triggered the run,
207
207
  // which the reaction names. Absent for any other event, or any other value.
208
208
  commentId?: string;
209
+ // The command a Crysk platform dispatched (odd/tasks/platform-commands.md in the platform
210
+ // repo, S2-S4). A platform-managed repository has no issue_comment trigger, so the platform
211
+ // checks the comment and its author's permission and names the command in its token exchange
212
+ // (src/ci/platform.ts). Read only on a workflow_dispatch, and only from the Connect step's
213
+ // outputs, never from a dispatch input, which anyone with write access can set by hand.
214
+ platformCommand?: PlatformCommand;
209
215
  }
210
216
 
217
+ export type PlatformCommand =
218
+ | { kind: "recheck" }
219
+ | { kind: "override"; actor: string; headSha: string }
220
+ // An override the platform named without a usable actor or head: refused, never recorded.
221
+ | { kind: "malformed-override" };
222
+
211
223
  export type CiTriggerDecision =
212
224
  | { kind: "review"; force: boolean; full: boolean; adjudicate: boolean }
213
225
  // A human's override: no CLI run, $0. `actor` is the login that unlocked the gate.
@@ -434,6 +446,21 @@ export function decideCiTrigger(input: CiTriggerInput): CiTriggerDecision {
434
446
  const event = classifyEvent(input);
435
447
  if (event.kind === "ignore") return event;
436
448
 
449
+ // WHY no permission lookup: the platform looked up the commenter's permission before it
450
+ // dispatched, and the dispatch carries no comment to look one up for.
451
+ const platform = event.kind === "event" ? input.platformCommand : undefined;
452
+ if (platform?.kind === "malformed-override") {
453
+ return {
454
+ kind: "denied",
455
+ reason:
456
+ "The Crysk platform asked for an override without a valid login or head, so " +
457
+ "nothing was recorded.",
458
+ };
459
+ }
460
+ if (platform?.kind === "override") {
461
+ return overrideDecision({ ...input, commenterLogin: platform.actor });
462
+ }
463
+
437
464
  if (event.kind === "comment") {
438
465
  const verdict = commenterVerdict(input, event.command);
439
466
  if (verdict !== undefined) return verdict;
@@ -475,12 +502,13 @@ export function decideCiTrigger(input: CiTriggerInput): CiTriggerDecision {
475
502
  event.command.kind === "review" &&
476
503
  event.command.full;
477
504
  const commentAdjudicate =
478
- event.kind === "comment" &&
479
- event.command.kind === "review" &&
480
- event.command.adjudicate;
505
+ (event.kind === "comment" &&
506
+ event.command.kind === "review" &&
507
+ event.command.adjudicate) ||
508
+ platform?.kind === "recheck";
481
509
  return {
482
510
  kind: "review",
483
- force: input.forceInput || fromComment,
511
+ force: input.forceInput || fromComment || platform?.kind === "recheck",
484
512
  full: input.fullInput || commentFull,
485
513
  adjudicate: commentAdjudicate,
486
514
  };
@@ -952,9 +980,27 @@ function readTriggerInput(
952
980
  fullInput: flag("FULL_INPUT"),
953
981
  ...(runAttempt === undefined ? {} : { runAttempt }),
954
982
  ...(commentId === undefined ? {} : { commentId }),
983
+ ...platformCommandOf(text),
955
984
  };
956
985
  }
957
986
 
987
+ // PLATFORM_COMMAND* are bound in action.yml only from the Connect step's outputs, and that step
988
+ // runs only on a workflow_dispatch with a dispatch id. An unknown command is no command.
989
+ function platformCommandOf(text: (name: string) => string): {
990
+ platformCommand?: PlatformCommand;
991
+ } {
992
+ if (text("EVENT_NAME") !== "workflow_dispatch") return {};
993
+ const command = text("PLATFORM_COMMAND");
994
+ if (command === "recheck") return { platformCommand: { kind: "recheck" } };
995
+ if (command !== "override") return {};
996
+ const actor = text("PLATFORM_COMMAND_ACTOR");
997
+ const headSha = validSha(text("PLATFORM_COMMAND_HEAD"));
998
+ if (!GITHUB_LOGIN.test(actor) || headSha === undefined) {
999
+ return { platformCommand: { kind: "malformed-override" } };
1000
+ }
1001
+ return { platformCommand: { kind: "override", actor, headSha } };
1002
+ }
1003
+
958
1004
  // The reaction a comment earns. Best effort: it runs only on an issue_comment with an
959
1005
  // id, and a failure prints one warning. It never changes the decision or the exit code,
960
1006
  // because the reaction is a courtesy and the decision is the product.
@@ -1139,6 +1185,7 @@ const OVERRIDE_UNKNOWN_FORK_REFUSAL = `The override could not confirm whether th
1139
1185
  // with the adjudicator's reason. The unknown answer gets its own text, as the override does.
1140
1186
  const RECHECK_FORK_REFUSAL =
1141
1187
  "A recheck cannot run on a fork pull request: the adjudicator needs this repository's checkout of the head";
1188
+ const OVERRIDE_HEAD_MOVED = `Crysk did not override the gate: the pull request has new commits since the override was asked, and an override applies to the head at the time of the comment; comment ${commandHint(OVERRIDE_COMMAND)} again.`;
1142
1189
  const RECHECK_UNKNOWN_FORK_REFUSAL = `The recheck could not confirm whether this pull request comes from a fork, so it was refused; comment ${commandHint(RECHECK_COMMAND)} again.`;
1143
1190
 
1144
1191
  // What the override's one lookup says. `crossRepository` is undefined when the
@@ -1405,6 +1452,19 @@ export function runCiTrigger(deps: CiTriggerDeps): number {
1405
1452
  react(deps, base, "-1");
1406
1453
  return 0;
1407
1454
  }
1455
+ // WHY refused when the head moved: an override applies to the head at the time of the
1456
+ // comment. On a comment event the job resolves the head moments later; a platform dispatch
1457
+ // can start minutes later, so it carries the head the platform saw and must still match.
1458
+ const asked =
1459
+ input.platformCommand?.kind === "override"
1460
+ ? input.platformCommand.headSha
1461
+ : undefined;
1462
+ if (asked !== undefined && answer.head !== asked) {
1463
+ writeRecord(deps, run, { decision: "denied", params: {} });
1464
+ deps.appendOutput(formatTriggerOutputs(NO_RUN));
1465
+ deps.stdout(workflowCommand("notice", OVERRIDE_HEAD_MOVED));
1466
+ return 0;
1467
+ }
1408
1468
  react(deps, base, "eyes");
1409
1469
  // WHY the no-head path is kept: a same-repository answer with no usable sha
1410
1470
  // still posts, and the publisher's comment says no status could be set.
@@ -125,6 +125,8 @@ export async function runStatusCommand(input: {
125
125
  statuses,
126
126
  issueComments,
127
127
  reviewComments,
128
+ // A developer's machine never learns the platform's login (src/triage/adjudication.ts).
129
+ adjudicatorTrust: { kind: "local" },
128
130
  });
129
131
  consecutivePollErrors = 0;
130
132
  } catch (err) {
package/src/index.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  // Public API surface; the deep-review lab consumes exactly these exports.
3
3
 
4
4
  export const ENGINE_NAME = "pr-hero";
5
- export const ENGINE_VERSION = "0.6.0";
5
+ export const ENGINE_VERSION = "0.6.1";
6
6
 
7
7
  // errors and git/refs used to reach this surface only through re-exports in
8
8
  // review/preflight.ts; they are exported directly now that those re-exports
@@ -121,6 +121,8 @@ export function answeredBlockingFindings(input: {
121
121
  reviewComments: readonly AnswerReviewComment[];
122
122
  trustedActors: ReadonlySet<string> | undefined;
123
123
  writers: ReadonlyMap<string, boolean | null>;
124
+ // In platform mode, the login the platform's token exchange returned (CRYSK_PLATFORM_ACTOR).
125
+ platformActor?: string;
124
126
  // When the carried verdict was written (its commit status's created_at), or null when unknown.
125
127
  verdictAt: string | null;
126
128
  }): AnsweredFindings | null {
@@ -149,6 +151,7 @@ export function answeredBlockingFindings(input: {
149
151
  statuses: [],
150
152
  issueComments,
151
153
  reviewComments,
154
+ adjudicatorTrust: { kind: "ci", platformActor: input.platformActor },
152
155
  });
153
156
  // S5: a finding whose tier could not be read is blocking only by fail-closed default; it cannot be
154
157
  // the evidence that unlocks the gate.
@@ -718,6 +718,7 @@ function answeredReader(input: {
718
718
  trustedActors: input.trustedActors,
719
719
  writers,
720
720
  verdictAt,
721
+ platformActor: process.env.CRYSK_PLATFORM_ACTOR,
721
722
  });
722
723
  };
723
724
  }
@@ -367,6 +367,7 @@ export async function resolvePrDiscovery(params: {
367
367
  replies: reviewComments,
368
368
  summaryUpdatedAt,
369
369
  headSha,
370
+ platformActor: process.env.CRYSK_PLATFORM_ACTOR,
370
371
  });
371
372
  const classified = buildPhaseBQueue({
372
373
  case: prepared.case,
@@ -39,8 +39,10 @@ import { bindPriorsToPosted } from "#rereview/prepare";
39
39
  import { parseStateBlock, type StateFinding } from "#rereview/state";
40
40
  import { parseFindingCommentBadge } from "#review/report";
41
41
  import {
42
- CI_ADJUDICATOR_LOGIN,
42
+ type AdjudicatorTrust,
43
+ CI_ADJUDICATOR_TRUST,
43
44
  parseAdjudicationMarker,
45
+ trustedAdjudicator,
44
46
  } from "#triage/adjudication";
45
47
  import {
46
48
  type ParsedTriageMarker,
@@ -149,7 +151,7 @@ const TRIGGER_COMMANDS = [REVIEW_COMMAND, REVIEW_FULL_COMMAND, RECHECK_COMMAND];
149
151
  // shape has them (rereview/prepare.ts PostedForPrior): without them the marker's anchor stands.
150
152
  export interface PrStatusReviewComment extends PrStatusComment {
151
153
  in_reply_to_id: number | null;
152
- // The GitHub login that posted it. The CI adjudicator's ruling is trusted only from CI_ADJUDICATOR_LOGIN.
154
+ // The GitHub login that posted it. The CI adjudicator's ruling is trusted only from trustedAdjudicator.
153
155
  user?: string;
154
156
  path?: string;
155
157
  line?: number | null;
@@ -162,6 +164,8 @@ export interface PrStatusInput {
162
164
  statuses: CommitStatusFact[];
163
165
  issueComments: PrStatusComment[];
164
166
  reviewComments: PrStatusReviewComment[];
167
+ // Whose CI ruling counts. Absent is a run's standalone read: only github-actions[bot].
168
+ adjudicatorTrust?: AdjudicatorTrust;
165
169
  }
166
170
 
167
171
  // The window a pending status is trusted for, named from the constant that defines it, so
@@ -448,9 +452,20 @@ function ciVerdictOf(
448
452
  id: number;
449
453
  verdict: "upheld" | "rejected" | "inconclusive";
450
454
  } | null = null;
455
+ const findingAuthor = input.reviewComments.find(
456
+ (c) => c.id === threadId,
457
+ )?.user;
451
458
  for (const comment of input.reviewComments) {
452
459
  if (comment.in_reply_to_id !== threadId) continue;
453
- if (comment.user !== CI_ADJUDICATOR_LOGIN) continue;
460
+ if (
461
+ !trustedAdjudicator(
462
+ comment.user,
463
+ findingAuthor,
464
+ input.adjudicatorTrust ?? CI_ADJUDICATOR_TRUST,
465
+ )
466
+ ) {
467
+ continue;
468
+ }
454
469
  const marker = parseAdjudicationMarker(comment.body);
455
470
  if (marker === null) continue;
456
471
  if (marker.reply !== newestTriageId || marker.head !== input.head) continue;