crysk 0.0.0-stage → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (229) hide show
  1. package/LICENSE +176 -0
  2. package/README.md +610 -2
  3. package/bin/pr-hero.js +166 -0
  4. package/config/models/anthropic.json +5 -0
  5. package/dist/SKILL-7e3725zn.md +496 -0
  6. package/dist/SKILL-7q35wcaz.md +66 -0
  7. package/dist/SKILL-9at22381.md +74 -0
  8. package/dist/SKILL-ex2hxxh3.md +134 -0
  9. package/dist/adjudicator-dtg2axnh.md +86 -0
  10. package/dist/admission-config.example-a9vqmmad.json +9 -0
  11. package/dist/ci-admission-camfbx2b.md +122 -0
  12. package/dist/cli.js +42292 -0
  13. package/dist/consolidate-ac0mnfyj.md +24 -0
  14. package/dist/deep-review-lifecycle-m698ybjp.md +362 -0
  15. package/dist/deep-review-logic-a6b1gczf.md +156 -0
  16. package/dist/deep-review-parity-0ec904db.md +120 -0
  17. package/dist/deep-review-reliability-qyakbjb9.md +125 -0
  18. package/dist/deep-review-resilience-3tz8y26e.md +118 -0
  19. package/dist/index.js +20190 -0
  20. package/dist/opencode-ci-7b0be64p.md +141 -0
  21. package/dist/review-refuter-j4e9gezy.md +71 -0
  22. package/dist/scout-yvp153q7.md +140 -0
  23. package/dist/summarizer-zca44nxa.md +18 -0
  24. package/dist/workflow-w1g9szna.yml +151 -0
  25. package/package.json +82 -4
  26. package/prompts/consolidate.md +24 -0
  27. package/prompts/default/PROVENANCE.md +18 -0
  28. package/prompts/default/deep-review-lifecycle.md +362 -0
  29. package/prompts/default/deep-review-logic.md +156 -0
  30. package/prompts/default/deep-review-parity.md +120 -0
  31. package/prompts/default/deep-review-reliability.md +125 -0
  32. package/prompts/default/deep-review-resilience.md +118 -0
  33. package/prompts/default/review-refuter.md +71 -0
  34. package/prompts/scout.md +140 -0
  35. package/prompts/summarizer.md +18 -0
  36. package/skills/crysk/SKILL.md +74 -0
  37. package/skills/crysk-ci-setup/SKILL.md +134 -0
  38. package/skills/crysk-ci-setup/assets/admission-config.example.json +9 -0
  39. package/skills/crysk-ci-setup/assets/workflow.yml +151 -0
  40. package/skills/crysk-ci-setup/references/ci-admission.md +122 -0
  41. package/skills/crysk-ci-setup/references/opencode-ci.md +141 -0
  42. package/skills/crysk-loop/SKILL.md +496 -0
  43. package/skills/crysk-loop/adjudicator.md +86 -0
  44. package/skills/crysk-pr/SKILL.md +66 -0
  45. package/src/agent-env.ts +1084 -0
  46. package/src/asset-manifest.ts +83 -0
  47. package/src/assets.d.ts +6 -0
  48. package/src/assets.ts +183 -0
  49. package/src/brand-paths.ts +155 -0
  50. package/src/brand.ts +255 -0
  51. package/src/ci/admission-ledger.ts +350 -0
  52. package/src/ci/classify-error.ts +73 -0
  53. package/src/ci/cli-record.ts +271 -0
  54. package/src/ci/force-comment.ts +39 -0
  55. package/src/ci/gates.ts +923 -0
  56. package/src/ci/outcome.ts +2181 -0
  57. package/src/ci/override.ts +187 -0
  58. package/src/ci/publish.ts +1639 -0
  59. package/src/ci/reporter.ts +626 -0
  60. package/src/ci/review-admission.ts +901 -0
  61. package/src/ci/review-levels.ts +310 -0
  62. package/src/ci/review-policy.ts +18 -0
  63. package/src/ci/review-risk.ts +184 -0
  64. package/src/ci/setup.ts +844 -0
  65. package/src/ci/trigger.ts +1353 -0
  66. package/src/cli.ts +348 -0
  67. package/src/commands/activity.ts +67 -0
  68. package/src/commands/ci-setup-questions.ts +397 -0
  69. package/src/commands/ci-setup.ts +381 -0
  70. package/src/commands/config.ts +99 -0
  71. package/src/commands/doctor.ts +108 -0
  72. package/src/commands/init.ts +139 -0
  73. package/src/commands/mcp.ts +10 -0
  74. package/src/commands/menu.ts +129 -0
  75. package/src/commands/post.ts +302 -0
  76. package/src/commands/skills.ts +83 -0
  77. package/src/commands/status.ts +173 -0
  78. package/src/commands/triage.ts +342 -0
  79. package/src/commands/uninstall.ts +37 -0
  80. package/src/commands/upgrade.ts +214 -0
  81. package/src/commands/usage.ts +98 -0
  82. package/src/compare/compare.ts +28 -0
  83. package/src/compare/floor-test.ts +471 -0
  84. package/src/compare/martian-adapter.ts +80 -0
  85. package/src/config/config.ts +267 -0
  86. package/src/corpus/corpus.ts +1094 -0
  87. package/src/corpus/preflight.ts +1789 -0
  88. package/src/diversity/accounting.ts +90 -0
  89. package/src/diversity/adjudication.ts +145 -0
  90. package/src/diversity/admission.ts +60 -0
  91. package/src/diversity/benchmark.ts +195 -0
  92. package/src/diversity/clustering.ts +285 -0
  93. package/src/diversity/errors.ts +7 -0
  94. package/src/diversity/identity.ts +285 -0
  95. package/src/diversity/index.ts +11 -0
  96. package/src/diversity/pipeline-integration.ts +448 -0
  97. package/src/diversity/projection.ts +57 -0
  98. package/src/diversity/self-contained.ts +68 -0
  99. package/src/diversity/target-validation.ts +179 -0
  100. package/src/doctor-migration.ts +209 -0
  101. package/src/doctor.ts +723 -0
  102. package/src/errors.ts +83 -0
  103. package/src/execution/admission.ts +75 -0
  104. package/src/execution/atomic-write.ts +35 -0
  105. package/src/execution/attempt-evidence.ts +415 -0
  106. package/src/execution/bucket-id.ts +136 -0
  107. package/src/execution/concurrency-limiter.ts +175 -0
  108. package/src/execution/contracts.ts +443 -0
  109. package/src/execution/failure-classification.ts +42 -0
  110. package/src/execution/failure-policy.ts +240 -0
  111. package/src/execution/harness.ts +2548 -0
  112. package/src/execution/settlement.ts +348 -0
  113. package/src/execution/spawned-process.ts +66 -0
  114. package/src/execution/spend-limiter.ts +424 -0
  115. package/src/execution/step-artifacts.ts +55 -0
  116. package/src/execution/usage-normalized.ts +469 -0
  117. package/src/git/git.ts +396 -0
  118. package/src/git/identity.ts +64 -0
  119. package/src/git/refs.ts +140 -0
  120. package/src/home-preflight.ts +443 -0
  121. package/src/home.ts +243 -0
  122. package/src/ignore-file.ts +336 -0
  123. package/src/ignore-read.ts +118 -0
  124. package/src/index.ts +34 -0
  125. package/src/legacy-launchd.ts +29 -0
  126. package/src/mcp/mcp.ts +150 -0
  127. package/src/mcp/preflight.ts +407 -0
  128. package/src/menu-context.ts +192 -0
  129. package/src/model/catalog.ts +251 -0
  130. package/src/model/exec-snapshots.ts +390 -0
  131. package/src/model/free-discovery.ts +302 -0
  132. package/src/model/provider-capabilities.ts +814 -0
  133. package/src/model/routing.ts +600 -0
  134. package/src/pr/admission.ts +847 -0
  135. package/src/pr/ci-admission-gate.ts +665 -0
  136. package/src/pr/ci-publish.ts +76 -0
  137. package/src/pr/discovery.ts +432 -0
  138. package/src/pr/inline.ts +507 -0
  139. package/src/pr/plan.ts +366 -0
  140. package/src/pr/posting.ts +115 -0
  141. package/src/pr/pr-status.ts +787 -0
  142. package/src/pr/pr.ts +3642 -0
  143. package/src/pr/preflight.ts +1031 -0
  144. package/src/pr/publish-outcome.ts +361 -0
  145. package/src/pr/range.ts +119 -0
  146. package/src/pr/reverts-preflight.ts +606 -0
  147. package/src/pr/reverts.ts +377 -0
  148. package/src/pr/review-pr.ts +927 -0
  149. package/src/pr/status.ts +154 -0
  150. package/src/pr/target.ts +388 -0
  151. package/src/pr/teardown.ts +437 -0
  152. package/src/pr/worktree-setup.ts +60 -0
  153. package/src/production-runtime.ts +1877 -0
  154. package/src/progress.ts +487 -0
  155. package/src/rereview/adjudicate.ts +89 -0
  156. package/src/rereview/classify.ts +362 -0
  157. package/src/rereview/identity.ts +211 -0
  158. package/src/rereview/plan.ts +308 -0
  159. package/src/rereview/prepare.ts +1025 -0
  160. package/src/rereview/state.ts +767 -0
  161. package/src/rereview/verify.ts +241 -0
  162. package/src/review/boundary.ts +105 -0
  163. package/src/review/consolidate.ts +246 -0
  164. package/src/review/dedupe.ts +368 -0
  165. package/src/review/drafts.ts +448 -0
  166. package/src/review/findings-conformance.ts +120 -0
  167. package/src/review/findings.ts +714 -0
  168. package/src/review/pipeline.ts +3977 -0
  169. package/src/review/preflight.ts +3575 -0
  170. package/src/review/prompt-set.ts +177 -0
  171. package/src/review/proof-refs.ts +187 -0
  172. package/src/review/report.ts +1821 -0
  173. package/src/review/review.ts +490 -0
  174. package/src/review/root-cause.ts +120 -0
  175. package/src/review/route-preflight.ts +289 -0
  176. package/src/review/run.ts +601 -0
  177. package/src/review/scout.ts +323 -0
  178. package/src/review/size-gate.ts +595 -0
  179. package/src/review/spec.ts +235 -0
  180. package/src/review/step-runner.ts +233 -0
  181. package/src/runner-authority.ts +596 -0
  182. package/src/security/binding-policy.ts +115 -0
  183. package/src/security/credential-broker.ts +773 -0
  184. package/src/security/evidence-redaction.ts +62 -0
  185. package/src/security/execution-authority.ts +27 -0
  186. package/src/security/redact.ts +71 -0
  187. package/src/security/workspace-read-broker.ts +466 -0
  188. package/src/server/client.ts +190 -0
  189. package/src/server/preflight.ts +217 -0
  190. package/src/server/server.ts +327 -0
  191. package/src/signal-handler.ts +50 -0
  192. package/src/store/activity.ts +413 -0
  193. package/src/store/backfill-preflight.ts +49 -0
  194. package/src/store/backfill.ts +141 -0
  195. package/src/store/gc-preflight.ts +206 -0
  196. package/src/store/gc.ts +424 -0
  197. package/src/store/metrics-preflight.ts +229 -0
  198. package/src/store/metrics.ts +236 -0
  199. package/src/store/preflight.ts +748 -0
  200. package/src/store/store.ts +693 -0
  201. package/src/system-tools.ts +355 -0
  202. package/src/transport-registry.ts +1124 -0
  203. package/src/transports/claude-code-cli.ts +1348 -0
  204. package/src/transports/opencode-admission.ts +515 -0
  205. package/src/transports/opencode-client.ts +3328 -0
  206. package/src/transports/opencode-evidence.ts +557 -0
  207. package/src/transports/opencode-mcp.ts +248 -0
  208. package/src/transports/opencode-sdk.ts +2294 -0
  209. package/src/transports/opencode-server.ts +535 -0
  210. package/src/triage/adjudication.ts +113 -0
  211. package/src/triage/reply.ts +125 -0
  212. package/src/triage/triage.ts +255 -0
  213. package/src/ui/activity.ts +173 -0
  214. package/src/ui/config-edit.ts +816 -0
  215. package/src/ui/config.ts +462 -0
  216. package/src/ui/menu.ts +1325 -0
  217. package/src/ui/plan.ts +1039 -0
  218. package/src/ui/primitives.ts +300 -0
  219. package/src/ui/progress.ts +298 -0
  220. package/src/ui/result.ts +552 -0
  221. package/src/ui/review-menu.ts +312 -0
  222. package/src/ui/select.ts +528 -0
  223. package/src/ui/tree.ts +178 -0
  224. package/src/uninstaller.ts +479 -0
  225. package/src/updater.ts +836 -0
  226. package/src/usage.ts +77 -0
  227. package/src/watch/preflight.ts +1389 -0
  228. package/src/watch/watch.ts +1235 -0
  229. package/src/wizard.ts +877 -0
@@ -0,0 +1,310 @@
1
+ // The choices `setup --ci` asks for, as data: the re-review level presets, the
2
+ // gate mode, the spend ceiling, and the advanced keys. Pure, so every choice
3
+ // and every line of the summary is testable offline; the prompts live in the
4
+ // command shell (src/commands/ci-setup.ts).
5
+ //
6
+ // WHY presets at all: before this, CI admission ran on defaults nobody was
7
+ // shown (risk_aware, 2 passes). A preset names the behaviour in words, and the
8
+ // keys it sets are always written to .crysk/config.json, so what a repo does
9
+ // is visible in the file it versions, never inherited silently.
10
+
11
+ import { DEFAULT_SIZE_GATE } from "#review/size-gate";
12
+ import { CI_DEFAULT_METERED_BUDGET_USD } from "./gates";
13
+ import {
14
+ DEFAULT_CI_ADVISORY_WEIGHT,
15
+ DEFAULT_CI_BLOCKING_WEIGHT,
16
+ } from "./review-admission";
17
+ import type { CiReviewPolicyMode } from "./review-policy";
18
+
19
+ export type ReviewLevel = "minimal" | "balanced" | "thorough" | "manual";
20
+
21
+ export interface ReviewLevelPreset {
22
+ label: string;
23
+ description: string;
24
+ config: {
25
+ ci_review_policy: CiReviewPolicyMode;
26
+ ci_max_attempts: number;
27
+ // Read only by risk_aware and thresholded, so the other presets leave it out.
28
+ ci_rereview_min_score?: number;
29
+ max_verification_steps: number;
30
+ };
31
+ }
32
+
33
+ // Every preset verifies prior findings (8): even `minimal` and `manual` can be
34
+ // re-reviewed by hand with /crysk review, and a forced pass that confirms
35
+ // nothing it fixed would be worse than useless.
36
+ export const REVIEW_LEVELS: Record<ReviewLevel, ReviewLevelPreset> = {
37
+ minimal: {
38
+ label: "Minimal",
39
+ description:
40
+ "One automatic review per PR. Later pushes are reviewed only when you comment /crysk review.",
41
+ config: {
42
+ ci_review_policy: "once_per_pr",
43
+ ci_max_attempts: 1,
44
+ max_verification_steps: 8,
45
+ },
46
+ },
47
+ balanced: {
48
+ label: "Balanced (recommended)",
49
+ description:
50
+ "Re-review a push when it touches risky files or the previous pass found enough (score >= 4). At most 2 automatic passes per PR.",
51
+ config: {
52
+ ci_review_policy: "risk_aware",
53
+ ci_max_attempts: 2,
54
+ ci_rereview_min_score: 4,
55
+ max_verification_steps: 8,
56
+ },
57
+ },
58
+ thorough: {
59
+ label: "Thorough",
60
+ description:
61
+ "Review every push, up to 4 automatic passes per PR. Most coverage, most cost.",
62
+ config: {
63
+ ci_review_policy: "every_push",
64
+ ci_max_attempts: 4,
65
+ max_verification_steps: 8,
66
+ },
67
+ },
68
+ manual: {
69
+ label: "Manual",
70
+ description:
71
+ "No automatic reviews after the first. Every re-review starts with a /crysk review comment.",
72
+ config: {
73
+ ci_review_policy: "manual_only",
74
+ ci_max_attempts: 1,
75
+ max_verification_steps: 8,
76
+ },
77
+ },
78
+ };
79
+
80
+ export const REVIEW_LEVEL_ORDER: readonly ReviewLevel[] = [
81
+ "minimal",
82
+ "balanced",
83
+ "thorough",
84
+ "manual",
85
+ ];
86
+
87
+ export const DEFAULT_REVIEW_LEVEL: ReviewLevel = "balanced";
88
+
89
+ export function isReviewLevel(value: string): value is ReviewLevel {
90
+ return (REVIEW_LEVEL_ORDER as readonly string[]).includes(value);
91
+ }
92
+
93
+ export type Billing = "subscription" | "api";
94
+
95
+ export interface AdvancedChoices {
96
+ ci_blocking_weight?: number;
97
+ ci_advisory_weight?: number;
98
+ ci_admission_observe_only?: boolean;
99
+ ci_trusted_actors?: string[];
100
+ max_changed_files?: number;
101
+ // Lines appended to .cryskignore; exclusions have no config key.
102
+ ignorePatterns?: string[];
103
+ }
104
+
105
+ export interface CiSetupChoices {
106
+ level: ReviewLevel;
107
+ mode: "gate" | "advisory";
108
+ // Undefined: nobody said how the review is paid, so no ceiling is written
109
+ // and the action resolves it from the route's billing mode.
110
+ billing?: Billing;
111
+ // Only with billing "api"; undefined there means the $10 default.
112
+ budgetUsd?: number;
113
+ // Always written. Unlike the budget, a size threshold matters on any route:
114
+ // left unset, a subscription route resolves to NO limit, so a huge PR would
115
+ // run a review nobody asked for. 0 is the explicit, chosen "no limit".
116
+ maxChangedLines: number;
117
+ advanced: AdvancedChoices;
118
+ // True when no human or agent chose: the summary must say so.
119
+ defaulted: boolean;
120
+ // Which groups someone chose this run. A chosen group overrides the file; an
121
+ // unchosen one only fills a group the file does not have yet, so re-running
122
+ // setup (say `--force` to refresh an old workflow) never resets tuned keys.
123
+ // `mode` and `billing` guard the workflow the same way: on a --force refresh
124
+ // an unchosen one keeps what the old workflow said.
125
+ chosen: {
126
+ level: boolean;
127
+ maxChangedLines: boolean;
128
+ mode: boolean;
129
+ billing: boolean;
130
+ };
131
+ }
132
+
133
+ // What the repository already says, read before asking: the defaults a
134
+ // re-run should start from, so pressing Enter changes nothing.
135
+ export interface CurrentSettings {
136
+ config: Record<string, unknown>;
137
+ workflow: {
138
+ mode?: "gate" | "advisory";
139
+ budgetUsd?: string;
140
+ maxChangedLines?: string;
141
+ maxChangedFiles?: string;
142
+ };
143
+ }
144
+
145
+ export const NO_CURRENT_SETTINGS: CurrentSettings = {
146
+ config: {},
147
+ workflow: {},
148
+ };
149
+
150
+ const LEVEL_KEYS = [
151
+ "ci_review_policy",
152
+ "ci_max_attempts",
153
+ "ci_rereview_min_score",
154
+ "max_verification_steps",
155
+ ] as const;
156
+
157
+ // The preset the file's level keys spell exactly, "custom" when they are set
158
+ // but match none, undefined when the file sets none of them.
159
+ export function presetMatching(
160
+ config: Record<string, unknown>,
161
+ ): ReviewLevel | "custom" | undefined {
162
+ if (!LEVEL_KEYS.some((key) => key in config)) return undefined;
163
+ for (const level of REVIEW_LEVEL_ORDER) {
164
+ const preset = REVIEW_LEVELS[level].config as Record<string, unknown>;
165
+ if (LEVEL_KEYS.every((key) => config[key] === preset[key])) return level;
166
+ }
167
+ return "custom";
168
+ }
169
+
170
+ // The two inputs setup writes into the workflow, read back from an existing one.
171
+ export function parseWorkflowChoices(
172
+ text: string,
173
+ ): CurrentSettings["workflow"] {
174
+ // One input per line, quoted or not, with an optional trailing comment. A
175
+ // number must be a whole number (sizes) or a plain decimal (budget): a value
176
+ // like `1.2.3` reads as absent rather than becoming NaN in the new file.
177
+ const input = (name: string, value: string): string | undefined =>
178
+ new RegExp(`^\\s+${name}:\\s*["']?(${value})["']?\\s*(?:#.*)?$`, "m").exec(
179
+ text,
180
+ )?.[1];
181
+ const mode = input("mode", "gate|advisory") as
182
+ | "gate"
183
+ | "advisory"
184
+ | undefined;
185
+ const budgetUsd = input("budget-usd", "-?\\d+(?:\\.\\d+)?");
186
+ const maxChangedLines = input("max-changed-lines", "\\d+");
187
+ const maxChangedFiles = input("max-changed-files", "\\d+");
188
+ return {
189
+ ...(mode === undefined ? {} : { mode }),
190
+ ...(budgetUsd === undefined ? {} : { budgetUsd }),
191
+ ...(maxChangedLines === undefined ? {} : { maxChangedLines }),
192
+ ...(maxChangedFiles === undefined ? {} : { maxChangedFiles }),
193
+ };
194
+ }
195
+
196
+ // The engine's own default threshold, so a chosen default and an inherited one agree.
197
+ export const DEFAULT_MAX_CHANGED_LINES = DEFAULT_SIZE_GATE.maxChangedLines;
198
+
199
+ export function defaultChoices(): CiSetupChoices {
200
+ return {
201
+ level: DEFAULT_REVIEW_LEVEL,
202
+ mode: "gate",
203
+ maxChangedLines: DEFAULT_MAX_CHANGED_LINES,
204
+ advanced: {},
205
+ defaulted: true,
206
+ chosen: {
207
+ level: false,
208
+ maxChangedLines: false,
209
+ mode: false,
210
+ billing: false,
211
+ },
212
+ };
213
+ }
214
+
215
+ // The `budget-usd` workflow input for these choices, or undefined to write none.
216
+ // A subscription writes none. CI bills as metered only when a non-empty
217
+ // ANTHROPIC_API_KEY (or ANTHROPIC_AUTH_TOKEN) is present (envBillsMetered), so
218
+ // a subscription-only repo already gets no ceiling. An explicit 0 would print
219
+ // the disabled-ceiling warning on every run and, worse, stay an operator
220
+ // override if an API key is added later, defeating the $10 fail-safe that the
221
+ // key's mere presence is meant to bring back (gates.ts, CiBillingMode).
222
+ export function budgetInput(choices: CiSetupChoices): string | undefined {
223
+ if (choices.billing === "api") {
224
+ return String(choices.budgetUsd ?? CI_DEFAULT_METERED_BUDGET_USD);
225
+ }
226
+ return undefined;
227
+ }
228
+
229
+ // How the choices land in .crysk/config.json. `set` overrides; each group in
230
+ // `fillIfAbsent` is written only when the file has none of its keys, and kept
231
+ // whole otherwise, so a tuned policy is never half-replaced by a preset.
232
+ export interface ConfigPlan {
233
+ set: Record<string, unknown>;
234
+ fillIfAbsent: Record<string, unknown>[];
235
+ // Keys a chosen preset removes from the file.
236
+ remove: string[];
237
+ }
238
+
239
+ export function configPlan(choices: CiSetupChoices): ConfigPlan {
240
+ const { ignorePatterns: _ignored, ...advanced } = choices.advanced;
241
+ const set: Record<string, unknown> = {};
242
+ const fillIfAbsent: Record<string, unknown>[] = [];
243
+ const remove: string[] = [];
244
+ const levelKeys = { ...REVIEW_LEVELS[choices.level].config };
245
+ const lineKeys = { max_changed_lines: choices.maxChangedLines };
246
+ if (choices.chosen.level) {
247
+ Object.assign(set, levelKeys);
248
+ for (const key of [...LEVEL_KEYS, "ci_max_reviews"]) {
249
+ if (!(key in levelKeys)) remove.push(key);
250
+ }
251
+ } else fillIfAbsent.push(levelKeys);
252
+ if (choices.chosen.maxChangedLines) Object.assign(set, lineKeys);
253
+ else fillIfAbsent.push(lineKeys);
254
+ // An advanced key is present only because someone gave it.
255
+ for (const [key, value] of Object.entries(advanced)) {
256
+ if (value !== undefined) set[key] = value;
257
+ }
258
+ return { set, fillIfAbsent, remove };
259
+ }
260
+
261
+ // One line per choice, plus how to change it. Returned, never logged.
262
+ // `kept` holds the file's values for keys nobody chose this run; where a group
263
+ // was kept the summary shows those values, never the preset it did not write.
264
+ // `effective` is the config file as written: the advanced lines report it, so
265
+ // a tuned value nobody touched this run is shown as it stands.
266
+ export function renderChoicesSummary(
267
+ choices: CiSetupChoices,
268
+ kept: Record<string, unknown> = {},
269
+ effective: Record<string, unknown> = {},
270
+ ): string[] {
271
+ const preset = REVIEW_LEVELS[choices.level];
272
+ const levelKept = LEVEL_KEYS.filter((key) => key in kept);
273
+ const c = preset.config;
274
+ const a: AdvancedChoices = {
275
+ ...(effective as AdvancedChoices),
276
+ ...choices.advanced,
277
+ };
278
+ const budget = budgetInput(choices);
279
+ const lines = [
280
+ choices.defaulted
281
+ ? "Review settings (defaults: nobody chose them; pass --level, --ci-mode and --billing, or run setup --ci in a terminal, to choose):"
282
+ : "Review settings:",
283
+ ...(levelKept.length > 0
284
+ ? [
285
+ ` level kept the existing settings: ${levelKept.map((key) => `${key} ${JSON.stringify(kept[key])}`).join(", ")}`,
286
+ ]
287
+ : [
288
+ ` level ${choices.level}: ${preset.description}`,
289
+ ` policy ${c.ci_review_policy}, at most ${c.ci_max_attempts} automatic pass${c.ci_max_attempts === 1 ? "" : "es"} per PR${c.ci_rereview_min_score === undefined ? "" : `, score floor ${c.ci_rereview_min_score}`}`,
290
+ ` verification up to ${c.max_verification_steps} prior findings checked per re-review`,
291
+ ]),
292
+ ` gate ${choices.mode === "gate" ? "gate: blocking findings turn the crysk check red" : "advisory: the crysk check stays green"}`,
293
+ ` budget ${
294
+ budget === undefined
295
+ ? choices.billing === "subscription"
296
+ ? "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"
297
+ : "not set: resolved from how the review is paid (no ceiling on a subscription, $10 on an API key)"
298
+ : Number(budget) <= 0
299
+ ? `none (budget-usd: ${budget}; 0 or less disables the ceiling)`
300
+ : `$${budget} per review (budget-usd)`
301
+ }`,
302
+ ` score weights blocking ${a.ci_blocking_weight ?? DEFAULT_CI_BLOCKING_WEIGHT}, advisory ${a.ci_advisory_weight ?? DEFAULT_CI_ADVISORY_WEIGHT}`,
303
+ ` observe only ${a.ci_admission_observe_only === true ? "yes: skip decisions are logged, every push is reviewed" : "no"}`,
304
+ ` trusted actors ${a.ci_trusted_actors && a.ci_trusted_actors.length > 0 ? a.ci_trusted_actors.join(", ") : "none beyond the workflow actor"}`,
305
+ ` size limit ${"max_changed_lines" in kept ? `${JSON.stringify(kept.max_changed_lines)} changed lines (kept)` : choices.maxChangedLines === 0 ? "no changed-lines limit (0)" : `${choices.maxChangedLines} changed lines`}, ${a.max_changed_files === undefined ? "files resolved from how the review is paid" : `${a.max_changed_files} files`}`,
306
+ ` exclusions ${a.ignorePatterns && a.ignorePatterns.length > 0 ? `${a.ignorePatterns.join(", ")} (.cryskignore)` : "none added (.cryskignore)"}`,
307
+ "Change them later in the repo config (.crysk/config.json, or .prhero/config.json in a repo set up before the rename) and the review workflow (.github/workflows/crysk.yml, or pr-hero.yml in a repo set up before the rename) (`npx -y crysk config` shows the effective values).",
308
+ ];
309
+ return lines;
310
+ }
@@ -0,0 +1,18 @@
1
+ // The CI review-policy mode enum. Split out of ci/review-admission.ts
2
+ // (architecture guard C2): review/preflight.ts validates config's
3
+ // `ci_review_policy` field against this list, and ci/review-admission.ts
4
+ // imports `parseFindingMarker`/`PR_FINDING_MARKER_PREFIX` (value) from
5
+ // pr/preflight.ts, which in turn imports `assertOutsideRepo` (value) from
6
+ // review/preflight.ts — so review/preflight.ts importing this enum FROM
7
+ // ci/review-admission.ts closed a 3-file value-import cycle. This file has
8
+ // no imports of its own — a true leaf every side can depend on one-way.
9
+
10
+ export const CI_REVIEW_POLICY_MODES = [
11
+ "once_per_pr",
12
+ "thresholded",
13
+ "risk_aware",
14
+ "every_push",
15
+ "manual_only",
16
+ ] as const;
17
+
18
+ export type CiReviewPolicyMode = (typeof CI_REVIEW_POLICY_MODES)[number];
@@ -0,0 +1,184 @@
1
+ // Current-head delta risk classification for CI admission (WU-04). Pure — no I/O.
2
+ // Unknown never qualifies as safe; only an explicit all-low allowlist may skip.
3
+
4
+ import { normalizePath } from "#compare/compare";
5
+
6
+ export const CI_RISK_POLICY_VERSION = 1;
7
+
8
+ export type RiskClass = "high" | "low" | "unknown";
9
+
10
+ export interface DeltaRiskAssessment {
11
+ version: typeof CI_RISK_POLICY_VERSION;
12
+ class: RiskClass;
13
+ reason: string;
14
+ changedPaths: readonly string[];
15
+ highRiskPaths: readonly string[];
16
+ lowRiskPaths: readonly string[];
17
+ }
18
+
19
+ export type CompareFileStatus = "added" | "modified" | "removed" | "renamed";
20
+
21
+ export interface ComparePathStatus {
22
+ path: string;
23
+ status: CompareFileStatus;
24
+ }
25
+
26
+ const HIGH_RISK_GLOBS = [
27
+ "src/**",
28
+ "scripts/**",
29
+ ".github/**",
30
+ "action.yml",
31
+ "package.json",
32
+ "bun.lock",
33
+ "bun.lockb",
34
+ "pnpm-lock.yaml",
35
+ "package-lock.json",
36
+ "yarn.lock",
37
+ "npm-shrinkwrap.json",
38
+ "deno.lock",
39
+ "poetry.lock",
40
+ "Pipfile.lock",
41
+ "Gemfile.lock",
42
+ "**/auth/**",
43
+ "**/*secret*",
44
+ "**/*credential*",
45
+ "**/*password*",
46
+ "**/.env",
47
+ "**/.env.*",
48
+ ] as const;
49
+
50
+ const LOW_RISK_GLOBS = [
51
+ "docs/**",
52
+ "**/*.md",
53
+ "test/**",
54
+ "**/*.test.ts",
55
+ "**/*.spec.ts",
56
+ "fixtures/**",
57
+ ] as const;
58
+
59
+ function escapeRegexChar(char: string): string {
60
+ return char.replace(/[|\\{}()[\]^$+?.]/g, "\\$&");
61
+ }
62
+
63
+ function globToRegExp(pattern: string): RegExp {
64
+ let regex = "^";
65
+ for (let i = 0; i < pattern.length; i++) {
66
+ const char = pattern[i];
67
+ if (char === "*") {
68
+ if (pattern[i + 1] === "*") {
69
+ if (pattern[i + 2] === "/") {
70
+ regex += "(?:.*/)?";
71
+ i += 2;
72
+ } else {
73
+ regex += ".*";
74
+ i += 1;
75
+ }
76
+ } else {
77
+ regex += "[^/]*";
78
+ }
79
+ continue;
80
+ }
81
+ regex += escapeRegexChar(char);
82
+ }
83
+ regex += "$";
84
+ return new RegExp(regex);
85
+ }
86
+
87
+ const HIGH_RISK_REGEXES = HIGH_RISK_GLOBS.map(globToRegExp);
88
+ const LOW_RISK_REGEXES = LOW_RISK_GLOBS.map(globToRegExp);
89
+
90
+ function matchesAnyGlob(path: string, regexes: readonly RegExp[]): boolean {
91
+ return regexes.some((regex) => regex.test(path));
92
+ }
93
+
94
+ function statusByPath(
95
+ compareStatuses: readonly ComparePathStatus[] | undefined,
96
+ ): Map<string, CompareFileStatus> {
97
+ const out = new Map<string, CompareFileStatus>();
98
+ if (compareStatuses === undefined) return out;
99
+ for (const entry of compareStatuses) {
100
+ out.set(normalizePath(entry.path), entry.status);
101
+ }
102
+ return out;
103
+ }
104
+
105
+ function classifyPath(
106
+ path: string,
107
+ status: CompareFileStatus | undefined,
108
+ ): "high" | "low" {
109
+ if (status === "removed" || status === "renamed") {
110
+ return "high";
111
+ }
112
+ if (matchesAnyGlob(path, HIGH_RISK_REGEXES)) {
113
+ return "high";
114
+ }
115
+ if (matchesAnyGlob(path, LOW_RISK_REGEXES)) {
116
+ return "low";
117
+ }
118
+ return "high";
119
+ }
120
+
121
+ export function classifyChangedPaths(
122
+ paths: readonly string[],
123
+ compareStatuses?: readonly ComparePathStatus[],
124
+ ): DeltaRiskAssessment {
125
+ const changedPaths = [...new Set(paths.map(normalizePath))].sort();
126
+ if (changedPaths.length === 0) {
127
+ return {
128
+ version: CI_RISK_POLICY_VERSION,
129
+ class: "unknown",
130
+ reason: "no changed paths in delta metadata",
131
+ changedPaths,
132
+ highRiskPaths: [],
133
+ lowRiskPaths: [],
134
+ };
135
+ }
136
+
137
+ const statuses = statusByPath(compareStatuses);
138
+ const highRiskPaths: string[] = [];
139
+ const lowRiskPaths: string[] = [];
140
+
141
+ for (const path of changedPaths) {
142
+ const bucket = classifyPath(path, statuses.get(path));
143
+ if (bucket === "high") {
144
+ highRiskPaths.push(path);
145
+ } else {
146
+ lowRiskPaths.push(path);
147
+ }
148
+ }
149
+
150
+ if (highRiskPaths.length === 0) {
151
+ return {
152
+ version: CI_RISK_POLICY_VERSION,
153
+ class: "low",
154
+ reason: "all changed paths match the low-risk allowlist",
155
+ changedPaths,
156
+ highRiskPaths,
157
+ lowRiskPaths,
158
+ };
159
+ }
160
+ if (lowRiskPaths.length === 0) {
161
+ return {
162
+ version: CI_RISK_POLICY_VERSION,
163
+ class: "high",
164
+ reason: "delta touches high-risk paths",
165
+ changedPaths,
166
+ highRiskPaths,
167
+ lowRiskPaths,
168
+ };
169
+ }
170
+ return {
171
+ version: CI_RISK_POLICY_VERSION,
172
+ class: "unknown",
173
+ reason: "delta mixes high-risk and low-risk paths",
174
+ changedPaths,
175
+ highRiskPaths,
176
+ lowRiskPaths,
177
+ };
178
+ }
179
+
180
+ export function deltaRiskTriggersReview(
181
+ assessment: DeltaRiskAssessment,
182
+ ): boolean {
183
+ return assessment.class === "high" || assessment.class === "unknown";
184
+ }