crysk 0.4.0 → 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 (93) 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/gates.ts +22 -36
  26. package/src/ci/outcome.ts +421 -330
  27. package/src/ci/platform-config.ts +2 -2
  28. package/src/ci/platform-report.ts +274 -41
  29. package/src/ci/platform-trace.ts +551 -0
  30. package/src/ci/platform.ts +28 -12
  31. package/src/ci/publish.ts +19 -6
  32. package/src/ci/review-levels.ts +8 -7
  33. package/src/ci/run.ts +88 -0
  34. package/src/ci/setup.ts +453 -118
  35. package/src/ci/trace-bundle.ts +1282 -0
  36. package/src/ci/trace-transcripts.ts +415 -0
  37. package/src/ci/trigger.ts +176 -33
  38. package/src/cli.ts +11 -3
  39. package/src/commands/ci-setup-questions.ts +3 -3
  40. package/src/commands/ci-setup.ts +152 -6
  41. package/src/commands/config.ts +3 -0
  42. package/src/commands/doctor.ts +15 -6
  43. package/src/config/config.ts +16 -3
  44. package/src/diversity/clustering.ts +0 -1
  45. package/src/diversity/identity.ts +4 -5
  46. package/src/diversity/pipeline-integration.ts +1 -9
  47. package/src/doctor.ts +3 -3
  48. package/src/execution/attempt-evidence.ts +10 -5
  49. package/src/execution/claude-session-trace.ts +480 -0
  50. package/src/execution/contracts.ts +21 -4
  51. package/src/execution/harness.ts +105 -8
  52. package/src/execution/model-fallback.ts +239 -0
  53. package/src/execution/usage-normalized.ts +6 -4
  54. package/src/home-preflight.ts +1 -1
  55. package/src/index.ts +1 -1
  56. package/src/model/catalog.ts +13 -37
  57. package/src/model/free-discovery.ts +117 -8
  58. package/src/model/model-name.ts +404 -0
  59. package/src/model/provider-capabilities.ts +22 -7
  60. package/src/model/routing.ts +346 -467
  61. package/src/pr/admission.ts +18 -0
  62. package/src/pr/plan.ts +20 -4
  63. package/src/pr/preflight.ts +1 -1
  64. package/src/pr/publish-outcome.ts +1 -1
  65. package/src/pr/review-pr.ts +15 -1
  66. package/src/pr/target.ts +12 -3
  67. package/src/production-runtime.ts +760 -331
  68. package/src/review/pipeline.ts +277 -101
  69. package/src/review/preflight.ts +201 -294
  70. package/src/review/report.ts +26 -26
  71. package/src/review/review.ts +20 -3
  72. package/src/review/route-preflight.ts +79 -11
  73. package/src/review/run.ts +28 -6
  74. package/src/review/scout.ts +1 -1
  75. package/src/review/spec.ts +3 -3
  76. package/src/review/step-runner.ts +70 -1
  77. package/src/runner-authority.ts +127 -9
  78. package/src/security/binding-policy.ts +1 -2
  79. package/src/security/claude-credential.ts +355 -0
  80. package/src/security/credential-broker.ts +56 -40
  81. package/src/security/evidence-redaction.ts +179 -4
  82. package/src/security/opencode-secret-manifest.ts +114 -0
  83. package/src/security/redact.ts +45 -0
  84. package/src/system-tools.ts +48 -21
  85. package/src/transport-registry.ts +12 -2
  86. package/src/transports/claude-code-cli.ts +21 -2
  87. package/src/transports/opencode-sdk.ts +11 -9
  88. package/src/transports/opencode-server.ts +7 -10
  89. package/src/ui/config-edit.ts +9 -20
  90. package/src/ui/config.ts +32 -27
  91. package/src/ui/plan.ts +76 -47
  92. package/src/updater.ts +10 -7
  93. package/prompts/default/deep-review-lifecycle.md +0 -362
@@ -48,6 +48,7 @@ import {
48
48
  import { publishFinalCommitStatus } from "#pr/status";
49
49
  import { log } from "#ui/primitives";
50
50
  import { canonicalStatusText, STATUS_CONTEXT } from "../brand";
51
+ import { CredentialRefusalError } from "../security/claude-credential";
51
52
 
52
53
  // ROADMAP Pillar 3 (GitHub Actions CI). The mechanical glue behind a gate
53
54
  // skip in CI mode: every DECISION (what to say, which marker, what the
@@ -180,6 +181,23 @@ export async function settleCiGateSkip(
180
181
  await settleCiAdmissionLedger(state, "gate-skipped", reason, options);
181
182
  }
182
183
 
184
+ // R003 (#494): a credential refusal at admission (CredentialRefusalError: no Claude
185
+ // credential, or an OpenCode route with no auth record) stops a CI run after the
186
+ // reservation and before any binding or provider call (the OpenCode refusal follows
187
+ // only the token-free free-model probe), so it spent nothing:
188
+ // its row settles as gate-skipped, like the budget gate it follows, with the
189
+ // refusal's own reason. Any other error is left for teardown, which settles it
190
+ // `failed`. The caller rethrows the error unchanged. The name predates the OpenCode
191
+ // refusal and is kept: an architecture test pins its call site.
192
+ export async function settleClaudeCredentialRefusal(
193
+ state: CiAdmissionLedgerState | null,
194
+ error: unknown,
195
+ options?: { spawnFn?: typeof Bun.spawn },
196
+ ): Promise<void> {
197
+ if (!(error instanceof CredentialRefusalError)) return;
198
+ await settleCiGateSkip(state, error.ledgerReason, options);
199
+ }
200
+
183
201
  export async function reserveCiAdmissionLedger(input: {
184
202
  operatorRoot: string;
185
203
  prNumber: number;
package/src/pr/plan.ts CHANGED
@@ -27,11 +27,12 @@ import {
27
27
  countFreeRouteSteps,
28
28
  type FreeRouteBilling,
29
29
  } from "#model/free-discovery";
30
- import type { ResolvedRoutePlan } from "#model/routing";
30
+ import { planRoutes, type ResolvedRoutePlan } from "#model/routing";
31
31
  import {
32
32
  type CiAdmissionLedgerState,
33
33
  publishCiSkip,
34
34
  settleCiGateSkip,
35
+ settleClaudeCredentialRefusal,
35
36
  } from "#pr/admission";
36
37
  import { ghRepoWebUrl } from "#pr/pr";
37
38
  import {
@@ -71,6 +72,7 @@ import {
71
72
  type RunnerAuthorityResolution,
72
73
  resolveRunnerAuthority,
73
74
  } from "../runner-authority";
75
+ import type { RunClaudeCredential } from "../security/claude-credential";
74
76
 
75
77
  export type PrPlanAndConfirmResult =
76
78
  | { exitCode: number }
@@ -128,6 +130,8 @@ export async function resolvePrPlanAndConfirm(params: {
128
130
  // run, pr-hero/local otherwise (resolveCiPosture). Passed down, never re-derived.
129
131
  statusContext: CommitStatusContext;
130
132
  ciBudgetCeiling: { budgetUsd: number | undefined };
133
+ // S5: the run's Claude credential, chosen once at run start (reviewPr).
134
+ claudeRun: RunClaudeCredential;
131
135
  ciAdmissionLedger: CiAdmissionLedgerState | null;
132
136
  skipDiscovery: boolean;
133
137
  hunterCount: number;
@@ -204,12 +208,12 @@ export async function resolvePrPlanAndConfirm(params: {
204
208
  }
205
209
  }
206
210
  const productionRoute = await resolvePipelineRoute({
207
- routingConfigured: params.config.routing !== undefined,
211
+ modelsConfigured: params.config.models !== undefined,
208
212
  workspaceRoot: params.worktreePath,
209
213
  spec: params.spec,
210
214
  options: params.options,
211
215
  agentFiles: params.agentFiles,
212
- routingConfig: params.config.routing,
216
+ models: params.config.models,
213
217
  summary: params.summary,
214
218
  summarizerEnabled: params.summary.enabled && !params.skipDiscovery,
215
219
  scoutEnabled: params.options.scout && !params.skipDiscovery,
@@ -218,6 +222,10 @@ export async function resolvePrPlanAndConfirm(params: {
218
222
  // re-review that hunts nothing new.
219
223
  materialityEnabled:
220
224
  resolveMaterialityGate(params.config) && !params.skipDiscovery,
225
+ claudeRun: params.claudeRun,
226
+ }).catch(async (error: unknown) => {
227
+ await settleClaudeCredentialRefusal(params.ciAdmissionLedger, error);
228
+ throw error;
221
229
  });
222
230
  const routePlan = productionRoute?.routePlan;
223
231
  const productionAdmission = productionRoute?.productionAdmission;
@@ -227,11 +235,19 @@ export async function resolvePrPlanAndConfirm(params: {
227
235
  routePlan === undefined || productionAdmission === undefined
228
236
  ? undefined
229
237
  : await countFreeRouteSteps({
230
- steps: routePlan.steps,
238
+ steps: planRoutes(routePlan),
231
239
  probe: productionAdmission.freeModelProbe,
240
+ // The CRYSK_OPENCODE_* names admission bound each route's kind with,
241
+ // so the card counts free exactly the routes admission probed (U3).
242
+ openCodeSecretNames:
243
+ productionAdmission.authorityOptions.openCodeSecretNames,
232
244
  });
233
245
  const runnerAuthority = await resolveRunnerAuthority({
234
246
  workspaceRoot: params.worktreePath,
247
+ env: params.claudeRun.env,
248
+ ...(params.claudeRun.kind === undefined
249
+ ? {}
250
+ : { claudeCredential: params.claudeRun.kind }),
235
251
  });
236
252
  await enforceCapabilityGate({
237
253
  routePlan,
@@ -828,7 +828,7 @@ export function settleRequestForCancellation(
828
828
  lock: HeldCommitStatusLock | null,
829
829
  ): { operatorRoot: string; sha: string; request: CommitStatusRequest } | null {
830
830
  if (lock === null) return null;
831
- // WHY PRH-CANCELLED and not "review did not finish": a signal is a cancel, and the
831
+ // WHY CRYSK-CANCELLED and not "review did not finish": a signal is a cancel, and the
832
832
  // action's cancel-settle step writes the same text when this settle does not land
833
833
  // first (src/ci/publish.ts runCancelSettle). Either writer leaves one coded status.
834
834
  return {
@@ -339,7 +339,7 @@ export async function publishRunOutcome(
339
339
  findings: doc.findings,
340
340
  costUsdEst: result.usage.cost_usd_est,
341
341
  wallMs,
342
- model: envelopeModel(input.options, input.agentFiles),
342
+ model: envelopeModel(input.options, input.agentFiles, result.routePlan),
343
343
  webUrl,
344
344
  delta: posted?.delta,
345
345
  runDir: input.runDir,
@@ -22,6 +22,7 @@ import path from "node:path";
22
22
  import {
23
23
  cliHeadField,
24
24
  hunterFailureRecords,
25
+ recordRunDir,
25
26
  writeCliRecord,
26
27
  } from "#ci/cli-record";
27
28
  import { planCiExcludedSkip, planCiSizeSkip } from "#ci/gates";
@@ -121,6 +122,7 @@ import { acquirePidLock } from "../home";
121
122
  import { worktreeLockPath } from "../home-preflight";
122
123
  import { readLocalIgnoreRules } from "../ignore-read";
123
124
  import type { ProductionRuntime } from "../production-runtime";
125
+ import { resolveRunClaudeCredential } from "../security/claude-credential";
124
126
  import { writeGateRecord } from "./gate-record";
125
127
 
126
128
  // The CLI's record for a pipeline whose every hunter failed (cli.json,
@@ -142,7 +144,7 @@ export function recordPipelineOutcome(
142
144
  ): void {
143
145
  if (result?.sessionFailed !== true) return;
144
146
  // WHY the causes ride on the record: the publisher names the provider and the model
145
- // when every hunter failed on the provider's side (PRH-MODEL-UNAVAILABLE). A run with
147
+ // when every hunter failed on the provider's side (CRYSK-MODEL-UNAVAILABLE). A run with
146
148
  // no failed hunter list keeps the record as it was before the field existed.
147
149
  const failures = result.hunterFailures ?? [];
148
150
  writeCliRecord(
@@ -279,6 +281,13 @@ export async function reviewPr(
279
281
  const step1 = await resolvePrRunOptions(options, prArg);
280
282
  options = step1.options;
281
283
  const { operatorRoot, prNumber, home, isCi, loaded, config, summary } = step1;
284
+ // S5: the Claude credential this run uses, chosen once, here, from
285
+ // `credentials.claude` and what is set. The CI ceiling, the admission, every
286
+ // runner and binding, and the child read its env, which holds that one
287
+ // credential and no other.
288
+ const claudeRun = resolveRunClaudeCredential({
289
+ credentials: config.credentials,
290
+ });
282
291
  // S4 + T3 S7: the run's one posture. Every gate, skip, status, comment and
283
292
  // summary below takes these values; nothing re-resolves them. Both key on the
284
293
  // explicit --ci flag, never on `isCi` (which also folds in the CI/GITHUB_ACTIONS
@@ -301,6 +310,7 @@ export async function reviewPr(
301
310
  config,
302
311
  isCi,
303
312
  operatorRoot,
313
+ claudeRun,
304
314
  });
305
315
  await validateGotchas(step2.gotchasPath);
306
316
  } catch (error) {
@@ -644,6 +654,9 @@ export async function reviewPr(
644
654
  prNumber,
645
655
  headSha,
646
656
  );
657
+ // Action mode only: the trace step reads the run's files from here when
658
+ // the run step publishes no run_dir (src/ci/cli-record.ts recordRunDir).
659
+ recordRunDir(runDir);
647
660
  // diff.patch is the EFFECTIVE diff — exactly what the hunters read (see
648
661
  // filterDiffByIgnoreRules); diff.raw.patch preserves the unfiltered
649
662
  // bytes, and only when the filter actually dropped something.
@@ -699,6 +712,7 @@ export async function reviewPr(
699
712
  ciMode,
700
713
  statusContext,
701
714
  ciBudgetCeiling,
715
+ claudeRun,
702
716
  ciAdmissionLedger,
703
717
  skipDiscovery,
704
718
  hunterCount,
package/src/pr/target.ts CHANGED
@@ -64,6 +64,7 @@ import {
64
64
  legacyWorktreePath,
65
65
  prWorktreePath,
66
66
  } from "../home-preflight";
67
+ import type { RunClaudeCredential } from "../security/claude-credential";
67
68
  import { resolveOpenCodeAuthPath } from "../security/credential-broker";
68
69
 
69
70
  export interface ResolvedPrRunOptions {
@@ -160,12 +161,20 @@ export async function resolvePrPromptSetAndBudget(params: {
160
161
  config: LoadedRunConfig["config"];
161
162
  isCi: boolean;
162
163
  operatorRoot: string;
164
+ // S5: the run's Claude credential, chosen once at run start (reviewPr). Its env
165
+ // holds only the chosen credential, so the ceiling follows the choice: the
166
+ // subscription has no metered ceiling, the API key keeps it. Absent (tests that
167
+ // pin the older wiring) reads the process env as before.
168
+ claudeRun?: RunClaudeCredential;
163
169
  }): Promise<ResolvedPrPromptSet> {
164
170
  // File presence, not envBillsMetered: that predicate stamps Claude
165
171
  // usage and must stay Anthropic-env-only.
166
- const billingMode = deriveCiBillingMode(process.env, {
167
- openCodeAuthPresent: existsSync(resolveOpenCodeAuthPath()),
168
- });
172
+ const billingMode = deriveCiBillingMode(
173
+ params.claudeRun?.env ?? process.env,
174
+ {
175
+ openCodeAuthPresent: existsSync(resolveOpenCodeAuthPath()),
176
+ },
177
+ );
169
178
  // Issue #156: resolve the ceiling ONCE, here, and use this same value at
170
179
  // the budget gate far below (src/pr/review-pr.ts's plan/confirm stage).
171
180
  // Resolving twice invites the announcement and the gate drifting apart.