crysk 0.4.0 → 0.5.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.
Files changed (98) hide show
  1. package/README.md +26 -17
  2. package/config/models/anthropic.json +1 -1
  3. package/dist/SKILL-k4k0zn1w.md +143 -0
  4. package/dist/SKILL-vhb4c3vv.md +553 -0
  5. package/dist/SKILL-xpf6kmdw.md +74 -0
  6. package/dist/ci-admission-0ken6ehx.md +128 -0
  7. package/dist/cli.js +3056 -1623
  8. package/dist/index.js +1744 -938
  9. package/dist/opencode-ci-ac5zksdn.md +106 -0
  10. package/dist/workflow-4pkyck01.yml +160 -0
  11. package/package.json +1 -1
  12. package/prompts/default/PROVENANCE.md +1 -0
  13. package/skills/crysk/SKILL.md +16 -16
  14. package/skills/crysk-ci-setup/SKILL.md +41 -38
  15. package/skills/crysk-ci-setup/assets/workflow.yml +31 -22
  16. package/skills/crysk-ci-setup/references/ci-admission.md +1 -1
  17. package/skills/crysk-ci-setup/references/opencode-ci.md +53 -88
  18. package/skills/crysk-loop/SKILL.md +1 -1
  19. package/src/asset-manifest.ts +0 -4
  20. package/src/assets.ts +1 -1
  21. package/src/ci/admission-ledger.ts +4 -0
  22. package/src/ci/classify-error.ts +21 -24
  23. package/src/ci/cli-record.ts +53 -1
  24. package/src/ci/crysk-secrets.ts +409 -0
  25. package/src/ci/force-comment.ts +14 -1
  26. package/src/ci/gates.ts +86 -57
  27. package/src/ci/outcome.ts +421 -330
  28. package/src/ci/platform-config.ts +2 -2
  29. package/src/ci/platform-estimate.ts +111 -0
  30. package/src/ci/platform-report.ts +274 -41
  31. package/src/ci/platform-trace.ts +581 -0
  32. package/src/ci/platform.ts +58 -12
  33. package/src/ci/publish.ts +19 -6
  34. package/src/ci/reporter.ts +14 -4
  35. package/src/ci/review-levels.ts +8 -7
  36. package/src/ci/run.ts +88 -0
  37. package/src/ci/setup.ts +485 -118
  38. package/src/ci/trace-bundle.ts +1486 -0
  39. package/src/ci/trace-transcripts.ts +480 -0
  40. package/src/ci/trigger.ts +176 -33
  41. package/src/cli.ts +11 -3
  42. package/src/commands/ci-setup-questions.ts +3 -3
  43. package/src/commands/ci-setup.ts +152 -6
  44. package/src/commands/config.ts +3 -0
  45. package/src/commands/doctor.ts +15 -6
  46. package/src/config/config.ts +16 -3
  47. package/src/diversity/clustering.ts +0 -1
  48. package/src/diversity/identity.ts +4 -5
  49. package/src/diversity/pipeline-integration.ts +1 -9
  50. package/src/doctor.ts +3 -3
  51. package/src/execution/attempt-evidence.ts +10 -5
  52. package/src/execution/claude-session-trace.ts +480 -0
  53. package/src/execution/contracts.ts +21 -4
  54. package/src/execution/harness.ts +105 -8
  55. package/src/execution/model-fallback.ts +239 -0
  56. package/src/execution/usage-normalized.ts +6 -4
  57. package/src/home-preflight.ts +1 -1
  58. package/src/index.ts +1 -1
  59. package/src/model/catalog.ts +13 -37
  60. package/src/model/free-discovery.ts +117 -8
  61. package/src/model/model-name.ts +404 -0
  62. package/src/model/provider-capabilities.ts +22 -7
  63. package/src/model/routing.ts +346 -467
  64. package/src/pr/admission.ts +18 -0
  65. package/src/pr/ci-admission-gate.ts +2 -0
  66. package/src/pr/discovery.ts +18 -0
  67. package/src/pr/plan.ts +55 -5
  68. package/src/pr/preflight.ts +1 -1
  69. package/src/pr/publish-outcome.ts +1 -1
  70. package/src/pr/review-pr.ts +26 -1
  71. package/src/pr/target.ts +63 -11
  72. package/src/production-runtime.ts +760 -331
  73. package/src/review/pipeline.ts +277 -101
  74. package/src/review/preflight.ts +201 -294
  75. package/src/review/report.ts +30 -26
  76. package/src/review/review.ts +20 -3
  77. package/src/review/route-preflight.ts +79 -11
  78. package/src/review/run.ts +44 -6
  79. package/src/review/scout.ts +1 -1
  80. package/src/review/spec.ts +3 -3
  81. package/src/review/step-runner.ts +70 -1
  82. package/src/runner-authority.ts +127 -9
  83. package/src/security/binding-policy.ts +1 -2
  84. package/src/security/claude-credential.ts +355 -0
  85. package/src/security/credential-broker.ts +56 -40
  86. package/src/security/evidence-redaction.ts +179 -4
  87. package/src/security/opencode-secret-manifest.ts +114 -0
  88. package/src/security/redact.ts +45 -0
  89. package/src/system-tools.ts +48 -21
  90. package/src/transport-registry.ts +12 -2
  91. package/src/transports/claude-code-cli.ts +21 -2
  92. package/src/transports/opencode-sdk.ts +11 -9
  93. package/src/transports/opencode-server.ts +7 -10
  94. package/src/ui/config-edit.ts +9 -20
  95. package/src/ui/config.ts +32 -27
  96. package/src/ui/plan.ts +84 -50
  97. package/src/updater.ts +10 -7
  98. package/prompts/default/deep-review-lifecycle.md +0 -362
package/src/ci/gates.ts CHANGED
@@ -190,7 +190,10 @@ function sizeLimitsText(maxLines: number, maxFiles: number): string {
190
190
  return `${lines} / ${files}`;
191
191
  }
192
192
 
193
- function buildSizeSkipComment(data: SkipSizeSummary): string {
193
+ function buildSizeSkipComment(
194
+ data: SkipSizeSummary,
195
+ platformConnected: boolean,
196
+ ): string {
194
197
  const lines = [
195
198
  SKIP_SIZE_COMMENT_MARKER,
196
199
  "## Crysk review skipped",
@@ -199,16 +202,28 @@ function buildSizeSkipComment(data: SkipSizeSummary): string {
199
202
  `${data.changedFiles} file(s), exceeding the configured size gate ` +
200
203
  `(${sizeLimitsText(data.maxChangedLines, data.maxChangedFiles)}).`,
201
204
  "",
202
- "Crysk did not run to avoid reviewing an unbounded diff. Split the " +
203
- "PR or raise `max-changed-lines` / `max-changed-files` to change the " +
204
- "limit for later pushes.",
205
+ // A platform repository sets its limits in the dashboard, not as inputs.
206
+ platformConnected
207
+ ? "Crysk did not run to avoid reviewing an unbounded diff. Split the " +
208
+ "PR or raise the size limits in the Crysk dashboard to change them " +
209
+ "for later pushes."
210
+ : "Crysk did not run to avoid reviewing an unbounded diff. Split the " +
211
+ "PR or raise `max-changed-lines` / `max-changed-files` to change the " +
212
+ "limit for later pushes.",
205
213
  "",
206
- ciForceReviewHintLine(data.prNumber),
214
+ ciForceReviewHintLine(data.prNumber, platformConnected),
207
215
  ];
208
216
  return `${lines.join("\n")}\n`;
209
217
  }
210
218
 
219
+ // What a platform repository can do about a budget skip (cryskai/platform#12):
220
+ // it has no `budget-usd` input to raise, and what a review costs is the model
221
+ // setup chosen in the dashboard.
222
+ const PLATFORM_BUDGET_SKIP_HINT =
223
+ "To change what reviews cost, change the model setup in the Crysk dashboard.";
224
+
211
225
  function buildBudgetSkipComment(data: SkipBudgetSummary): string {
226
+ const platformConnected = data.platformConnected === true;
212
227
  const lines = [
213
228
  SKIP_BUDGET_COMMENT_MARKER,
214
229
  "## Crysk review skipped",
@@ -216,10 +231,12 @@ function buildBudgetSkipComment(data: SkipBudgetSummary): string {
216
231
  `⚠️ The estimated review cost (${usd(data.estimatedCostUsd)}) exceeds ` +
217
232
  `the configured CI budget ceiling (${usd(data.budgetUsd)}).`,
218
233
  "",
219
- "Crysk did not run to stay within the configured `--budget-usd` " +
220
- "ceiling.",
234
+ platformConnected
235
+ ? PLATFORM_BUDGET_SKIP_HINT
236
+ : "Crysk did not run to stay within the configured `--budget-usd` " +
237
+ "ceiling.",
221
238
  "",
222
- ciForceReviewHintLine(data.prNumber),
239
+ ciForceReviewHintLine(data.prNumber, platformConnected),
223
240
  ];
224
241
  return `${lines.join("\n")}\n`;
225
242
  }
@@ -240,6 +257,9 @@ export interface CiSizeGateSkipInput {
240
257
  // failed (size-gate.ts), but the summary/comment show both metrics.
241
258
  maxChangedLines: number;
242
259
  maxChangedFiles: number;
260
+ // The run came through the Crysk platform (CRYSK_PLATFORM_CONNECTED): the
261
+ // comment names only what applies to a platform repository.
262
+ platformConnected?: boolean;
243
263
  }
244
264
 
245
265
  // `null` means "nothing to publish": either this isn't a CI run, or the
@@ -254,8 +274,12 @@ export function ciSizeGateSkip(input: CiSizeGateSkipInput): CiGateSkip | null {
254
274
  changedFiles: input.verdict.effectiveFiles,
255
275
  maxChangedLines: input.maxChangedLines,
256
276
  maxChangedFiles: input.maxChangedFiles,
277
+ ...(input.platformConnected === true ? { platformConnected: true } : {}),
278
+ };
279
+ return {
280
+ comment: buildSizeSkipComment(summary, input.platformConnected === true),
281
+ summary,
257
282
  };
258
- return { comment: buildSizeSkipComment(summary), summary };
259
283
  }
260
284
 
261
285
  export interface CiBudgetGateSkipInput {
@@ -263,6 +287,9 @@ export interface CiBudgetGateSkipInput {
263
287
  estimatedCostUsd: number;
264
288
  budgetUsd: number;
265
289
  prNumber: number;
290
+ // The run came through the Crysk platform (CRYSK_PLATFORM_CONNECTED): the
291
+ // skip names only what applies to a platform repository.
292
+ platformConnected?: boolean;
266
293
  }
267
294
 
268
295
  export function ciBudgetGateSkip(
@@ -275,6 +302,7 @@ export function ciBudgetGateSkip(
275
302
  prNumber: input.prNumber,
276
303
  estimatedCostUsd: input.estimatedCostUsd,
277
304
  budgetUsd: input.budgetUsd,
305
+ ...(input.platformConnected === true ? { platformConnected: true } : {}),
278
306
  };
279
307
  return { comment: buildBudgetSkipComment(summary), summary };
280
308
  }
@@ -330,44 +358,30 @@ export type CiBillingMode = "subscription" | "metered";
330
358
  // ANTHROPIC_AUTH_TOKEN joined the signal in the same move. It was never
331
359
  // excluded by a decision — the doctrine below never mentions it — and
332
360
  // `ENV_PASSTHROUGH` (harness.ts) projects it into the child immediately beside
333
- // ANTHROPIC_API_KEY as the same per-token credential class, so the rule stated
334
- // two paragraphs down ("the mere PRESENCE of a key keeps the ceiling") already
335
- // covered it. Nil-delta for the shipped action: action.yml binds only
336
- // ANTHROPIC_API_KEY and CLAUDE_CODE_OAUTH_TOKEN, so no generated workflow can
337
- // newly acquire a ceiling from it.
361
+ // ANTHROPIC_API_KEY as the same per-token credential class, so the presence rule
362
+ // that stood below (retired by S5) already covered it. It cannot reach a run's
363
+ // ceiling any more: the action takes Claude credentials only from the CRYSK_CLAUDE_*
364
+ // secrets in its crysk-secrets input (S8, U5) and empties the CLI's own variables,
365
+ // and the run env (claudeRunEnv) removes ANTHROPIC_AUTH_TOKEN whatever its source.
338
366
  //
339
- // Which credential bills when BOTH CLAUDE_CODE_OAUTH_TOKEN and ANTHROPIC_API_KEY are
340
- // present was settled by observation after this rule was written: CLI 2.1.312 prints
341
- // "claude.ai connectors are disabled because ANTHROPIC_API_KEY or another auth source is
342
- // set and takes precedence over your claude.ai login", and on this repo's CI with both
343
- // secrets bound every request used the API key (see credentialOf in
344
- // transports/claude-code-cli.ts). The rule below still does not depend on that answer,
345
- // and the gap it describes was real when it was written:
346
- // action.yml:111-112 binds both into the child env unconditionally,
347
- // test/harness/env-projection.test.ts:48-56 deliberately asserts both survive
348
- // the projection with no precedence between them, and `defaultClaudeAuthProbe`
349
- // (model/provider-capabilities.ts:402-405) ORs them into a single boolean. Whichever
350
- // one the Claude CLI itself prefers wins, and that fact is recorded nowhere in
351
- // this codebase.
367
+ // S5 (2026-11-06) retired the rule that stood here: "the mere PRESENCE of a key keeps
368
+ // the ceiling", written while nobody chose which credential billed when both were set
369
+ // (the CLI preferred the key, observed on CLI 2.1.312). Now the run chooses: the first
370
+ // credential in `credentials.claude` (default subscription, then api_key) that is
371
+ // present, once at run start (security/claude-credential.ts). The env this function
372
+ // receives is that run's env, which holds the chosen Claude credential and no other,
373
+ // so `metered` here means the run uses the API key, and a repo holding both secrets
374
+ // with the default order runs on the subscription with no ceiling. A caller that
375
+ // passes the raw process env instead gets the old presence answer.
352
376
  //
353
- // This rule does not need that answer, because the two errors are not
354
- // symmetric. Guess "unlimited" wrongly and a real invoice arrives that nobody
355
- // authorized. Guess "ceiling" wrongly and one review is skipped, which the
356
- // operator clears with a single line of YAML (`budget-usd: 0`). So the mere
357
- // PRESENCE of a key keeps the ceiling: we cannot rule out that it bills.
358
- // README.md:38-45 already states the user-facing half of the same rule —
359
- // sourcing ANTHROPIC_API_KEY into the shell "is what moves a run from quota to
360
- // invoice".
361
- //
362
- // Trimming is load-bearing. 2026-09-02, #177 corrects the overstatement this
363
- // paragraph used to carry ("without the trim, no route would ever resolve as
364
- // a subscription in Actions"): action.yml:111 binds the input UNCONDITIONALLY
365
- // and GitHub renders an unset input as the empty string, so every
366
- // subscription-route CI run carries `ANTHROPIC_API_KEY=""` — and `""` is
367
- // already falsy, so that case never needed the trim. What the trim catches is
368
- // a WHITESPACE-ONLY value, which is truthy and would otherwise impose a
369
- // ceiling on a subscription route. `test/ci/gates.test.ts` asserts both cases
370
- // separately, and only the whitespace ones flip when the trim is removed.
377
+ // Trimming is load-bearing. An empty value never needed it: `""` is already
378
+ // falsy, and it is what the action binds the CLI's Claude variables to and how
379
+ // GitHub renders a secret the repository does not have. What the trim catches is
380
+ // a WHITESPACE-ONLY value, which is truthy and would otherwise impose a ceiling
381
+ // on a subscription route, for a caller that passes a raw env (the run env never
382
+ // holds one: claudeCredentialPresence trims the same way and drops it).
383
+ // `test/ci/gates.test.ts` asserts both cases separately, and only the
384
+ // whitespace ones flip when the trim is removed.
371
385
  //
372
386
  // This is deliberately NOT `model/provider-capabilities.ts`'s
373
387
  // `CLAUDE_CAPABILITY_STATICS.billingMode`, and the two must not be "unified"
@@ -396,19 +410,19 @@ export type CiBillingMode = "subscription" | "metered";
396
410
  // through that one decision — this CI gate is not that caller, and never
397
411
  // should be.
398
412
  //
399
- // Optional `openCodeAuthPresent` is the OpenCode half of the same ceiling
413
+ // Optional `openCodeBillsMetered` is the OpenCode half of the same ceiling
400
414
  // question — "could this run invoice?" — ORed beside the Anthropic env
401
415
  // predicate, never folded into it. `envBillsMetered` stamps Claude CLI
402
416
  // usage and must stay Anthropic-env-only. Omit the option (or leave it
403
- // undefined/false) and this function stays env-only. Presence of the 0600
404
- // auth.json is enough: we cannot rule out an invoice, same conservative
405
- // doctrine as Anthropic keys. The instance is the file, not a parsed
406
- // provider name.
417
+ // undefined/false) and this function stays env-only. The caller derives it
418
+ // from the routes the run resolves (openCodeRoutesBillMetered, ci/setup.ts):
419
+ // an OpenCode provider bound to an API key can invoice; an auth file that only
420
+ // holds providers no model uses cannot (cryskai/platform#12).
407
421
  export function deriveCiBillingMode(
408
422
  env: Record<string, string | undefined>,
409
- opts?: { openCodeAuthPresent?: boolean },
423
+ opts?: { openCodeBillsMetered?: boolean },
410
424
  ): CiBillingMode {
411
- return envBillsMetered(env) || opts?.openCodeAuthPresent === true
425
+ return envBillsMetered(env) || opts?.openCodeBillsMetered === true
412
426
  ? "metered"
413
427
  : "subscription";
414
428
  }
@@ -669,6 +683,7 @@ const COVERAGE_REASON_LABEL: Record<
669
683
  function buildCoverageSkipComment(
670
684
  data: SkipCoverageSummary,
671
685
  reason: CiReviewSkipReason,
686
+ platformConnected: boolean,
672
687
  ): string {
673
688
  // A stop is a maintainer's decision, not a score: the score line would
674
689
  // blame the push for a skip it did not cause.
@@ -691,7 +706,7 @@ function buildCoverageSkipComment(
691
706
  "The existing review comment still describes the last head Crysk " +
692
707
  "reviewed.",
693
708
  "",
694
- ciForceReviewHintLine(data.prNumber),
709
+ ciForceReviewHintLine(data.prNumber, platformConnected),
695
710
  ];
696
711
  return `${lines.join("\n")}\n`;
697
712
  }
@@ -700,7 +715,10 @@ function buildCoverageSkipComment(
700
715
  // it by the repository's own rules, says what the gate does with the next pushes, and how to ask for more.
701
716
  // Stage 2 #12: no review reads those pushes, so the gate holds a green instead of carrying it, and the
702
717
  // override is how a human merges a head no review verified.
703
- function buildManualRequiredComment(data: ManualRequiredSummary): string {
718
+ function buildManualRequiredComment(
719
+ data: ManualRequiredSummary,
720
+ platformConnected: boolean,
721
+ ): string {
704
722
  const manualOnly = data.admissionReason === "manual-only-policy";
705
723
  const rules = [
706
724
  ...(data.policyMode === undefined
@@ -734,7 +752,7 @@ function buildManualRequiredComment(data: ManualRequiredSummary): string {
734
752
  "",
735
753
  "The existing review comment still describes the last head Crysk reviewed.",
736
754
  "",
737
- `Want more review rounds? ${ciForceReviewHintLine(data.prNumber)}`,
755
+ `Want more review rounds? ${ciForceReviewHintLine(data.prNumber, platformConnected)}`,
738
756
  ];
739
757
  return `${lines.join("\n")}\n`;
740
758
  }
@@ -794,6 +812,8 @@ export function planCiReviewSkip(input: {
794
812
  verdict: Extract<CiReviewAdmissionVerdict, { action: "skip" }>;
795
813
  admission?: AdmissionContext;
796
814
  ciMode: CiMode;
815
+ // The run came through the Crysk platform: the hint names only `/crysk review`.
816
+ platformConnected?: boolean;
797
817
  }): CiGateSkipPlan {
798
818
  const detail = ciReviewSkipDetail(input.verdict);
799
819
  const summary: SkipCoverageSummary = {
@@ -808,7 +828,11 @@ export function planCiReviewSkip(input: {
808
828
  ...skipAdmissionSummaryFields(input.verdict, input.admission),
809
829
  };
810
830
  return {
811
- comment: buildCoverageSkipComment(summary, input.verdict.reason),
831
+ comment: buildCoverageSkipComment(
832
+ summary,
833
+ input.verdict.reason,
834
+ input.platformConnected === true,
835
+ ),
812
836
  markerPrefix: SKIP_COVERAGE_COMMENT_MARKER,
813
837
  summaryMarkdown: renderStepSummary(summary, input.ciMode),
814
838
  outputs: ciGateSkipOutputs("skipped-coverage", 0),
@@ -820,6 +844,8 @@ export function planCiReviewManualRequired(input: {
820
844
  verdict: Extract<CiReviewAdmissionVerdict, { action: "manual-required" }>;
821
845
  admission?: AdmissionContext;
822
846
  ciMode: CiMode;
847
+ // The run came through the Crysk platform: the hint names only `/crysk review`.
848
+ platformConnected?: boolean;
823
849
  }): CiGateSkipPlan {
824
850
  const detail = ciReviewManualRequiredDetail(input.verdict);
825
851
  const summary: ManualRequiredSummary = {
@@ -836,7 +862,10 @@ export function planCiReviewManualRequired(input: {
836
862
  ...manualAdmissionSummaryFields(input.verdict, input.admission),
837
863
  };
838
864
  return {
839
- comment: buildManualRequiredComment(summary),
865
+ comment: buildManualRequiredComment(
866
+ summary,
867
+ input.platformConnected === true,
868
+ ),
840
869
  markerPrefix: MANUAL_REQUIRED_COMMENT_MARKER,
841
870
  summaryMarkdown: renderStepSummary(summary, input.ciMode),
842
871
  outputs: ciGateSkipOutputs("manual-required", 0),