crysk 0.3.3 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -17
- package/config/models/anthropic.json +1 -1
- package/dist/SKILL-dsnffnfp.md +140 -0
- package/dist/SKILL-gnrbph72.md +140 -0
- package/dist/SKILL-k4k0zn1w.md +143 -0
- package/dist/SKILL-kq0xejn3.md +553 -0
- package/dist/SKILL-qaqsbygw.md +66 -0
- package/dist/SKILL-vhb4c3vv.md +553 -0
- package/dist/SKILL-vws0aqb8.md +553 -0
- package/dist/SKILL-xpf6kmdw.md +74 -0
- package/dist/ci-admission-0ken6ehx.md +128 -0
- package/dist/ci-admission-t0f5qwth.md +128 -0
- package/dist/cli.js +3366 -1680
- package/dist/index.js +1884 -947
- package/dist/opencode-ci-ac5zksdn.md +106 -0
- package/dist/workflow-4pkyck01.yml +160 -0
- package/package.json +2 -2
- package/prompts/default/PROVENANCE.md +1 -0
- package/skills/crysk/SKILL.md +16 -16
- package/skills/crysk-ci-setup/SKILL.md +42 -39
- package/skills/crysk-ci-setup/assets/workflow.yml +31 -22
- package/skills/crysk-ci-setup/references/ci-admission.md +2 -2
- package/skills/crysk-ci-setup/references/opencode-ci.md +53 -88
- package/skills/crysk-loop/SKILL.md +20 -9
- package/skills/crysk-pr/SKILL.md +1 -1
- package/src/asset-manifest.ts +0 -4
- package/src/assets.ts +2 -2
- package/src/ci/admission-ledger.ts +4 -0
- package/src/ci/classify-error.ts +21 -24
- package/src/ci/cli-record.ts +53 -1
- package/src/ci/crysk-secrets.ts +409 -0
- package/src/ci/gates.ts +31 -42
- package/src/ci/outcome.ts +421 -330
- package/src/ci/platform-config.ts +127 -0
- package/src/ci/platform-report.ts +935 -0
- package/src/ci/platform-trace.ts +551 -0
- package/src/ci/platform.ts +465 -0
- package/src/ci/publish.ts +19 -6
- package/src/ci/reporter.ts +9 -7
- package/src/ci/review-admission.ts +8 -4
- package/src/ci/review-levels.ts +8 -7
- package/src/ci/run.ts +88 -0
- package/src/ci/setup.ts +547 -109
- package/src/ci/trace-bundle.ts +1282 -0
- package/src/ci/trace-transcripts.ts +415 -0
- package/src/ci/trigger.ts +176 -33
- package/src/cli.ts +11 -3
- package/src/commands/ci-setup-questions.ts +3 -3
- package/src/commands/ci-setup.ts +152 -6
- package/src/commands/config.ts +3 -0
- package/src/commands/doctor.ts +15 -6
- package/src/compare/loop.ts +9 -1
- package/src/compare/martian-adapter.ts +1 -1
- package/src/config/config.ts +16 -3
- package/src/diversity/clustering.ts +0 -1
- package/src/diversity/identity.ts +4 -5
- package/src/diversity/pipeline-integration.ts +1 -9
- package/src/doctor.ts +3 -3
- package/src/execution/attempt-evidence.ts +10 -5
- package/src/execution/claude-session-trace.ts +480 -0
- package/src/execution/contracts.ts +21 -4
- package/src/execution/harness.ts +105 -8
- package/src/execution/model-fallback.ts +239 -0
- package/src/execution/usage-normalized.ts +6 -4
- package/src/home-preflight.ts +1 -1
- package/src/index.ts +1 -1
- package/src/model/catalog.ts +13 -37
- package/src/model/free-discovery.ts +117 -8
- package/src/model/model-name.ts +404 -0
- package/src/model/provider-capabilities.ts +22 -7
- package/src/model/routing.ts +346 -467
- package/src/pr/admission.ts +71 -11
- package/src/pr/ci-admission-gate.ts +2 -1
- package/src/pr/finding-state-record.ts +58 -0
- package/src/pr/gate-record.ts +22 -0
- package/src/pr/inline.ts +3 -0
- package/src/pr/plan.ts +20 -4
- package/src/pr/posting.ts +4 -0
- package/src/pr/pr-status.ts +27 -7
- package/src/pr/pr.ts +39 -8
- package/src/pr/preflight.ts +44 -2
- package/src/pr/publish-outcome.ts +11 -3
- package/src/pr/review-pr.ts +20 -4
- package/src/pr/target.ts +12 -3
- package/src/production-runtime.ts +760 -331
- package/src/rereview/classify.ts +4 -0
- package/src/rereview/prepare.ts +47 -22
- package/src/rereview/state.ts +34 -8
- package/src/review/pipeline.ts +277 -101
- package/src/review/preflight.ts +201 -294
- package/src/review/report.ts +60 -40
- package/src/review/review.ts +20 -3
- package/src/review/route-preflight.ts +79 -11
- package/src/review/run.ts +28 -6
- package/src/review/scout.ts +1 -1
- package/src/review/spec.ts +3 -3
- package/src/review/step-runner.ts +70 -1
- package/src/runner-authority.ts +127 -9
- package/src/security/binding-policy.ts +1 -2
- package/src/security/claude-credential.ts +355 -0
- package/src/security/credential-broker.ts +56 -40
- package/src/security/evidence-redaction.ts +179 -4
- package/src/security/opencode-secret-manifest.ts +114 -0
- package/src/security/published-text.ts +161 -0
- package/src/security/redact.ts +45 -0
- package/src/system-tools.ts +48 -21
- package/src/transport-registry.ts +12 -2
- package/src/transports/claude-code-cli.ts +21 -2
- package/src/transports/opencode-sdk.ts +11 -9
- package/src/transports/opencode-server.ts +7 -10
- package/src/triage/triage.ts +2 -1
- package/src/ui/config-edit.ts +9 -20
- package/src/ui/config.ts +32 -27
- package/src/ui/plan.ts +76 -47
- package/src/updater.ts +10 -7
- package/prompts/default/deep-review-lifecycle.md +0 -362
package/src/ci/trigger.ts
CHANGED
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
// ignored comment costs seconds instead of a dependency install. A package
|
|
20
20
|
// import has no node_modules to resolve against yet, and a `#...` alias is no
|
|
21
21
|
// better: it resolves to a src module whose own imports reach packages. Keep
|
|
22
|
-
// every import here `node:` or `bun
|
|
22
|
+
// every import here `node:` or `bun`, plus the import-free ../brand and
|
|
23
|
+
// ./crysk-secrets (the CRYSK_* grammar, kept import-free for this step).
|
|
23
24
|
|
|
24
25
|
import { randomBytes } from "node:crypto";
|
|
25
26
|
import {
|
|
@@ -32,6 +33,14 @@ import {
|
|
|
32
33
|
} from "node:fs";
|
|
33
34
|
import path from "node:path";
|
|
34
35
|
import { commandHint, isCommand, startsWithCommand } from "../brand";
|
|
36
|
+
import {
|
|
37
|
+
type CryskSecretsParse,
|
|
38
|
+
cryskSecretsCarryCredential,
|
|
39
|
+
inheritedOpenCodeSecretNames,
|
|
40
|
+
inheritedOpenCodeSecretWarning,
|
|
41
|
+
LEGACY_SECRET_REPLACEMENT,
|
|
42
|
+
parseCryskSecrets,
|
|
43
|
+
} from "./crysk-secrets";
|
|
35
44
|
|
|
36
45
|
// Commands are written in the new `/crysk` form. The matchers in ../brand
|
|
37
46
|
// also accept the legacy `/pr-hero` spelling for one version.
|
|
@@ -66,11 +75,39 @@ const GITHUB_LOGIN = /^(?=.{1,91}$)[A-Za-z0-9][A-Za-z0-9_-]{0,90}(\[bot\])?$/;
|
|
|
66
75
|
// so this is the whole set of "can push to the repository".
|
|
67
76
|
const TRIGGER_PERMISSIONS: ReadonlySet<string> = new Set(["admin", "write"]);
|
|
68
77
|
|
|
69
|
-
const CREDENTIAL_INPUTS = [
|
|
78
|
+
const CREDENTIAL_INPUTS = ["crysk-secrets"] as const;
|
|
79
|
+
|
|
80
|
+
// The inputs the clean break removed (odd/tasks/role-model-routing.md, S2, S8, U5).
|
|
81
|
+
// They stay declared in action.yml only so a workflow still passing one stops here,
|
|
82
|
+
// before any install or spend, with the replacement named. The action binds each as
|
|
83
|
+
// a presence boolean (`inputs.<name> != ''`), never its value.
|
|
84
|
+
export const REMOVED_INPUTS = [
|
|
70
85
|
"anthropic-api-key",
|
|
71
86
|
"claude-token",
|
|
72
87
|
"opencode-auth",
|
|
88
|
+
"routing",
|
|
73
89
|
] as const;
|
|
90
|
+
export type RemovedInput = (typeof REMOVED_INPUTS)[number];
|
|
91
|
+
|
|
92
|
+
// What replaces each removed input, for the cause the trigger prints. The secret
|
|
93
|
+
// names are the crysk-secrets grammar's own (LEGACY_SECRET_REPLACEMENT), so the
|
|
94
|
+
// trigger, the setup step and the old-name warnings cannot name different secrets.
|
|
95
|
+
export const REMOVED_INPUT_REPLACEMENT: Readonly<Record<RemovedInput, string>> =
|
|
96
|
+
{
|
|
97
|
+
"claude-token": `pass ${LEGACY_SECRET_REPLACEMENT.CLAUDE_CODE_OAUTH_TOKEN} in the crysk-secrets input`,
|
|
98
|
+
"anthropic-api-key": `pass ${LEGACY_SECRET_REPLACEMENT.ANTHROPIC_API_KEY} in the crysk-secrets input`,
|
|
99
|
+
"opencode-auth": `pass ${LEGACY_SECRET_REPLACEMENT.OPENCODE_AUTH_JSON} in the crysk-secrets input`,
|
|
100
|
+
routing:
|
|
101
|
+
"pass the models per role in the `models` input, from `vars.CRYSK_MODELS`",
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
// The env flag action.yml binds for each removed input.
|
|
105
|
+
const REMOVED_INPUT_FLAG: Readonly<Record<RemovedInput, string>> = {
|
|
106
|
+
"anthropic-api-key": "HAS_ANTHROPIC_API_KEY",
|
|
107
|
+
"claude-token": "HAS_CLAUDE_TOKEN",
|
|
108
|
+
"opencode-auth": "HAS_OPENCODE_AUTH",
|
|
109
|
+
routing: "HAS_ROUTING",
|
|
110
|
+
};
|
|
74
111
|
|
|
75
112
|
// What the artifact is named after when the head cannot be resolved. The head
|
|
76
113
|
// sha only disambiguates the artifact name; a review must not fail over it.
|
|
@@ -95,26 +132,25 @@ export type CommenterPermission =
|
|
|
95
132
|
rateLimited?: boolean;
|
|
96
133
|
};
|
|
97
134
|
|
|
98
|
-
// Presence only. The
|
|
99
|
-
//
|
|
135
|
+
// Presence only. The `crysk-secrets` input's lines are one input, so presence
|
|
136
|
+
// needs the parse, and the step hands it over on stdin (runCiTrigger's
|
|
137
|
+
// `cryskSecrets`). Only this boolean leaves the parse. The old credential inputs
|
|
138
|
+
// are no credential any more: they are REMOVED_INPUTS, which stop the run.
|
|
100
139
|
export interface CiCredentialPresence {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
opencodeAuth: boolean;
|
|
140
|
+
// A CRYSK_* credential in the crysk-secrets input (cryskSecretsCarryCredential).
|
|
141
|
+
cryskSecrets: boolean;
|
|
104
142
|
// A Claude session file or the OpenCode auth store already on the runner
|
|
105
143
|
// (see runnerCredentialPaths). The engine authenticates with either.
|
|
106
144
|
runnerFile: boolean;
|
|
107
145
|
}
|
|
108
146
|
|
|
109
|
-
// The engine's Claude
|
|
110
|
-
// auth-store rule. Copied rather than imported, because this module may
|
|
147
|
+
// The engine's Claude login file, relative to HOME (U2: `~/.claude.json` and
|
|
148
|
+
// `~/.claude/session.json` are no credential), and its OpenCode auth-store rule. Copied rather than imported, because this module may
|
|
111
149
|
// import only builtins (see the header): the originals are
|
|
112
150
|
// CLAUDE_SESSION_FILES in src/model/provider-capabilities.ts and
|
|
113
151
|
// resolveOpenCodeAuthPath in src/security/credential-broker.ts, and a drift
|
|
114
152
|
// test in test/ci/trigger.test.ts pins this copy to both.
|
|
115
153
|
const CLAUDE_SESSION_FILES: readonly string[] = [
|
|
116
|
-
".claude.json",
|
|
117
|
-
path.join(".claude", "session.json"),
|
|
118
154
|
path.join(".claude", ".credentials.json"),
|
|
119
155
|
];
|
|
120
156
|
|
|
@@ -152,6 +188,9 @@ export interface CiTriggerInput {
|
|
|
152
188
|
// Absent means nobody looked it up, which is denied like a failed lookup.
|
|
153
189
|
commenterPermission?: CommenterPermission;
|
|
154
190
|
credentials: CiCredentialPresence;
|
|
191
|
+
// The removed inputs the workflow still passes with a value, in REMOVED_INPUTS
|
|
192
|
+
// order. Any of them stops the run (`removed-inputs`).
|
|
193
|
+
removedInputs: readonly RemovedInput[];
|
|
155
194
|
// RUNNER_ENVIRONMENT is `self-hosted`.
|
|
156
195
|
selfHostedRunner: boolean;
|
|
157
196
|
forceInput: boolean;
|
|
@@ -178,7 +217,10 @@ export type CiTriggerDecision =
|
|
|
178
217
|
status?: number;
|
|
179
218
|
rateLimited?: boolean;
|
|
180
219
|
}
|
|
181
|
-
| { kind: "no-credentials"; inputs: readonly string[] }
|
|
220
|
+
| { kind: "no-credentials"; inputs: readonly string[] }
|
|
221
|
+
// The workflow still passes an input the clean break removed (U5). Red, before
|
|
222
|
+
// any install, whatever else the workflow passes.
|
|
223
|
+
| { kind: "removed-inputs"; inputs: readonly RemovedInput[] };
|
|
182
224
|
|
|
183
225
|
// Exact match after trimming, and nothing else: no case folding, no inner
|
|
184
226
|
// whitespace tolerance, no trailing words. A loose match is how "/crysk
|
|
@@ -395,6 +437,15 @@ export function decideCiTrigger(input: CiTriggerInput): CiTriggerDecision {
|
|
|
395
437
|
if (event.command.kind === "override") return overrideDecision(input);
|
|
396
438
|
}
|
|
397
439
|
|
|
440
|
+
// WHY after the override and before the credential check: an override spends
|
|
441
|
+
// nothing and reads no input, so it still unlocks a gate; a review must not run
|
|
442
|
+
// on a workflow that passes an input nothing reads any more, even when another
|
|
443
|
+
// credential would let it, because that workflow's owner believes the old input
|
|
444
|
+
// is the one in use.
|
|
445
|
+
if (input.removedInputs.length > 0) {
|
|
446
|
+
return { kind: "removed-inputs", inputs: input.removedInputs };
|
|
447
|
+
}
|
|
448
|
+
|
|
398
449
|
// `no-credentials` is red, so it fires only when nothing the engine can
|
|
399
450
|
// authenticate with is within reach: no credential input, no Claude
|
|
400
451
|
// session file and no OpenCode auth store on the runner, and a runner that
|
|
@@ -403,19 +454,13 @@ export function decideCiTrigger(input: CiTriggerInput): CiTriggerDecision {
|
|
|
403
454
|
// capability gate decides.
|
|
404
455
|
//
|
|
405
456
|
// ANTHROPIC_API_KEY / CLAUDE_CODE_OAUTH_TOKEN in the JOB's environment do
|
|
406
|
-
// not count, and nothing here reads them.
|
|
407
|
-
//
|
|
408
|
-
//
|
|
409
|
-
//
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
if (
|
|
413
|
-
!anthropicApiKey &&
|
|
414
|
-
!claudeToken &&
|
|
415
|
-
!opencodeAuth &&
|
|
416
|
-
!runnerFile &&
|
|
417
|
-
!input.selfHostedRunner
|
|
418
|
-
) {
|
|
457
|
+
// not count, and nothing here reads them. The Run Crysk step's entry
|
|
458
|
+
// (src/ci/run.ts) hands the review only the crysk-secrets input's Claude
|
|
459
|
+
// values and drops every other Claude variable from what it reads, so a
|
|
460
|
+
// job-level value never reaches the engine: counting it would trade this
|
|
461
|
+
// clear red for a confusing auth failure later.
|
|
462
|
+
const { cryskSecrets, runnerFile } = input.credentials;
|
|
463
|
+
if (!cryskSecrets && !runnerFile && !input.selfHostedRunner) {
|
|
419
464
|
return { kind: "no-credentials", inputs: CREDENTIAL_INPUTS };
|
|
420
465
|
}
|
|
421
466
|
|
|
@@ -554,6 +599,9 @@ export interface CiTriggerDeps {
|
|
|
554
599
|
stdout: (text: string) => void;
|
|
555
600
|
appendOutput: (text: string) => void;
|
|
556
601
|
appendSummary: (text: string) => void;
|
|
602
|
+
// The `crysk-secrets` input, read from stdin by the entry point below (never
|
|
603
|
+
// from `env`). Absent or empty: no CRYSK_* secret.
|
|
604
|
+
cryskSecrets?: string;
|
|
557
605
|
// The record's file writes. The default is node:fs; a test injects a failing
|
|
558
606
|
// one to prove the write is atomic.
|
|
559
607
|
fs?: OutcomeFs;
|
|
@@ -685,6 +733,9 @@ const CLI_RECORD = "cli.json";
|
|
|
685
733
|
// The CLI's pending identity (src/ci/outcome.ts PENDING_AT_FILE, pinned equal by a test). A
|
|
686
734
|
// stale one would let the cancel settle trust an older run's pending.
|
|
687
735
|
const PENDING_AT = "pending-at";
|
|
736
|
+
// The CLI's run directory (src/ci/outcome.ts RUN_DIR_FILE, pinned equal by a test).
|
|
737
|
+
// A stale one would hand the trace step an older run's files.
|
|
738
|
+
const RUN_DIR = "run-dir";
|
|
688
739
|
|
|
689
740
|
function clearStaleMarkers(dir: string, fs: OutcomeFs): void {
|
|
690
741
|
// The markers the publisher reads stay strict: a stale one would mislead it.
|
|
@@ -695,6 +746,7 @@ function clearStaleMarkers(dir: string, fs: OutcomeFs): void {
|
|
|
695
746
|
SETUP_RECORD,
|
|
696
747
|
CLI_RECORD,
|
|
697
748
|
PENDING_AT,
|
|
749
|
+
RUN_DIR,
|
|
698
750
|
]) {
|
|
699
751
|
fs.remove(path.join(dir, name));
|
|
700
752
|
}
|
|
@@ -773,7 +825,33 @@ function printCauseUnlessRecorded(
|
|
|
773
825
|
// The cause of a run with no credential. It names the decision's own input
|
|
774
826
|
// list, so the text cannot drift from the check that produced it.
|
|
775
827
|
function noCredentialCause(inputs: readonly string[]): string {
|
|
776
|
-
return `Crysk has no credential for this review: pass
|
|
828
|
+
return `Crysk has no credential for this review: pass a CRYSK_* secret in the ${inputs.join(", ")} input.`;
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
// The cause of a run stopped for a removed input: each input with what replaces it.
|
|
832
|
+
// Names only, never a value (the trigger never receives one).
|
|
833
|
+
export function removedInputsCause(inputs: readonly RemovedInput[]): string {
|
|
834
|
+
const each = inputs.map(
|
|
835
|
+
(name) => `the ${name} input is gone: ${REMOVED_INPUT_REPLACEMENT[name]}`,
|
|
836
|
+
);
|
|
837
|
+
return `Crysk stopped before reviewing: ${each.join("; ")}. Remove the old input${inputs.length === 1 ? "" : "s"} from the workflow.`;
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
// The old names (CLAUDE_CODE_OAUTH_TOKEN, ...) written inside the crysk-secrets
|
|
841
|
+
// input. They are recorded by presence only and read by no step, so a workflow
|
|
842
|
+
// that copied them there would otherwise lose its credential without a word.
|
|
843
|
+
function warnLegacySecretNames(
|
|
844
|
+
deps: CiTriggerDeps,
|
|
845
|
+
secrets: CryskSecretsParse,
|
|
846
|
+
): void {
|
|
847
|
+
for (const name of secrets.legacy) {
|
|
848
|
+
deps.stdout(
|
|
849
|
+
workflowCommand(
|
|
850
|
+
"warning",
|
|
851
|
+
`${name} in the crysk-secrets input is an old secret name, and Crysk does not read it: set ${LEGACY_SECRET_REPLACEMENT[name]} instead.`,
|
|
852
|
+
),
|
|
853
|
+
);
|
|
854
|
+
}
|
|
777
855
|
}
|
|
778
856
|
|
|
779
857
|
// The lookup's class: only when gh printed an HTTP status. A 403 is a rate
|
|
@@ -788,8 +866,9 @@ function lookupClass(decision: {
|
|
|
788
866
|
: { kind: "github", status: decision.status };
|
|
789
867
|
}
|
|
790
868
|
|
|
791
|
-
// The route the run would have used. The trigger has no
|
|
792
|
-
// whether
|
|
869
|
+
// The route the run would have used. The trigger has no models text, only
|
|
870
|
+
// whether the models in effect name OpenCode: the platform's, or else the
|
|
871
|
+
// `models` input's (action.yml's HAS_OPENCODE_ROUTING, D1).
|
|
793
872
|
function backendOf(deps: CiTriggerDeps): string {
|
|
794
873
|
return deps.env.HAS_OPENCODE_ROUTING === "true" ? "opencode" : "claude";
|
|
795
874
|
}
|
|
@@ -827,6 +906,7 @@ function validSha(value: string): string | undefined {
|
|
|
827
906
|
// HOME and XDG_DATA_HOME, which every step inherits from the runner.
|
|
828
907
|
function readTriggerInput(
|
|
829
908
|
deps: CiTriggerDeps,
|
|
909
|
+
secrets: CryskSecretsParse,
|
|
830
910
|
): Omit<CiTriggerInput, "commenterPermission"> {
|
|
831
911
|
const { env } = deps;
|
|
832
912
|
const text = (name: string): string => env[name] ?? "";
|
|
@@ -845,11 +925,12 @@ function readTriggerInput(
|
|
|
845
925
|
commentOnPullRequest: text("EVENT_ISSUE_PR_URL") !== "",
|
|
846
926
|
commenterLogin: text("COMMENTER_LOGIN"),
|
|
847
927
|
credentials: {
|
|
848
|
-
|
|
849
|
-
claudeToken: flag("HAS_CLAUDE_TOKEN"),
|
|
850
|
-
opencodeAuth: flag("HAS_OPENCODE_AUTH"),
|
|
928
|
+
cryskSecrets: cryskSecretsCarryCredential(secrets),
|
|
851
929
|
runnerFile: runnerCredentialPaths(env).some((file) => exists(file)),
|
|
852
930
|
},
|
|
931
|
+
removedInputs: REMOVED_INPUTS.filter((name) =>
|
|
932
|
+
flag(REMOVED_INPUT_FLAG[name]),
|
|
933
|
+
),
|
|
853
934
|
selfHostedRunner: text("RUNNER_ENVIRONMENT") === "self-hosted",
|
|
854
935
|
forceInput: flag("FORCE_INPUT"),
|
|
855
936
|
fullInput: flag("FULL_INPUT"),
|
|
@@ -1129,7 +1210,14 @@ function lookupNoCredentialsHead(
|
|
|
1129
1210
|
}
|
|
1130
1211
|
|
|
1131
1212
|
export function runCiTrigger(deps: CiTriggerDeps): number {
|
|
1132
|
-
|
|
1213
|
+
// E-f F5: first, on every event, so the warning shows whatever is decided.
|
|
1214
|
+
for (const name of inheritedOpenCodeSecretNames(deps.env)) {
|
|
1215
|
+
deps.stdout(
|
|
1216
|
+
workflowCommand("warning", inheritedOpenCodeSecretWarning(name)),
|
|
1217
|
+
);
|
|
1218
|
+
}
|
|
1219
|
+
const secrets = parseCryskSecrets(deps.cryskSecrets ?? "");
|
|
1220
|
+
const base = readTriggerInput(deps, secrets);
|
|
1133
1221
|
const input: CiTriggerInput = commenterPermissionNeeded(base)
|
|
1134
1222
|
? {
|
|
1135
1223
|
...base,
|
|
@@ -1176,6 +1264,43 @@ export function runCiTrigger(deps: CiTriggerDeps): number {
|
|
|
1176
1264
|
return 1;
|
|
1177
1265
|
}
|
|
1178
1266
|
|
|
1267
|
+
// A run that reached the credential check (an override never does): an old
|
|
1268
|
+
// secret name inside the input is named with its CRYSK_* replacement, whether
|
|
1269
|
+
// or not another credential lets the review run, since nothing reads it.
|
|
1270
|
+
if (
|
|
1271
|
+
decision.kind === "review" ||
|
|
1272
|
+
decision.kind === "no-credentials" ||
|
|
1273
|
+
decision.kind === "removed-inputs"
|
|
1274
|
+
) {
|
|
1275
|
+
warnLegacySecretNames(deps, secrets);
|
|
1276
|
+
}
|
|
1277
|
+
|
|
1278
|
+
if (decision.kind === "removed-inputs") {
|
|
1279
|
+
// Like a missing credential: the command is accepted, the run is red, and the
|
|
1280
|
+
// PR's comment and status name the inputs to remove (CRYSK-INPUT-REMOVED).
|
|
1281
|
+
react(deps, base, "eyes");
|
|
1282
|
+
const head =
|
|
1283
|
+
pr === undefined
|
|
1284
|
+
? UNKNOWN_HEAD_SHA
|
|
1285
|
+
: lookupNoCredentialsHead(deps, base, pr);
|
|
1286
|
+
const write = writeRecord(deps, run, {
|
|
1287
|
+
decision: "removed-inputs",
|
|
1288
|
+
params: { detail: decision.inputs.join(", ") },
|
|
1289
|
+
pr,
|
|
1290
|
+
headSha: validSha(head),
|
|
1291
|
+
});
|
|
1292
|
+
printCauseUnlessRecorded(deps, write, removedInputsCause(decision.inputs));
|
|
1293
|
+
deps.appendOutput(
|
|
1294
|
+
formatTriggerOutputs({
|
|
1295
|
+
...NO_RUN,
|
|
1296
|
+
pr: pr ?? "",
|
|
1297
|
+
head_sha: validSha(head) ?? "",
|
|
1298
|
+
publish: publishes(write),
|
|
1299
|
+
}),
|
|
1300
|
+
);
|
|
1301
|
+
return 1;
|
|
1302
|
+
}
|
|
1303
|
+
|
|
1179
1304
|
if (decision.kind === "no-credentials") {
|
|
1180
1305
|
// An authorised commenter's command is accepted; the run is red for the missing
|
|
1181
1306
|
// credential, and its comment says why.
|
|
@@ -1203,7 +1328,7 @@ export function runCiTrigger(deps: CiTriggerDeps): number {
|
|
|
1203
1328
|
}
|
|
1204
1329
|
|
|
1205
1330
|
if (!resolution.ok) {
|
|
1206
|
-
// The publisher renders the class (
|
|
1331
|
+
// The publisher renders the class (CRYSK-PR-UNRESOLVED). The review never
|
|
1207
1332
|
// started, so the install step's marker is absent by design. A malformed
|
|
1208
1333
|
// input carries its fixed detail, so the fix names the input to correct.
|
|
1209
1334
|
const write = writeRecord(deps, run, {
|
|
@@ -1325,10 +1450,28 @@ function appendTo(filePath: string | undefined): (text: string) => void {
|
|
|
1325
1450
|
};
|
|
1326
1451
|
}
|
|
1327
1452
|
|
|
1453
|
+
// The env variable action.yml binds the `crysk-secrets` input to in this step.
|
|
1454
|
+
// The shell pipes it on stdin (the flag below) and runs bun with it emptied, the
|
|
1455
|
+
// way setup.ts takes it: Bun hands a child the environment it STARTED with, so a
|
|
1456
|
+
// variable bun received would reach every `gh` call. A non-empty one here means
|
|
1457
|
+
// the step was wired wrongly, and the trigger refuses to run.
|
|
1458
|
+
const CRYSK_SECRETS_ENV = "CRYSK_SECRETS_INPUT";
|
|
1459
|
+
const CRYSK_SECRETS_STDIN_FLAG = "--crysk-secrets-stdin";
|
|
1460
|
+
|
|
1328
1461
|
if (import.meta.main) {
|
|
1462
|
+
if ((process.env[CRYSK_SECRETS_ENV] ?? "") !== "") {
|
|
1463
|
+
process.stderr.write(
|
|
1464
|
+
`crysk: the crysk-secrets input reached trigger.ts through its environment, which every child it spawns would inherit; pipe it on stdin with ${CRYSK_SECRETS_STDIN_FLAG} and run bun with ${CRYSK_SECRETS_ENV} empty.\n`,
|
|
1465
|
+
);
|
|
1466
|
+
process.exit(1);
|
|
1467
|
+
}
|
|
1468
|
+
const cryskSecrets = process.argv.includes(CRYSK_SECRETS_STDIN_FLAG)
|
|
1469
|
+
? await Bun.stdin.text()
|
|
1470
|
+
: "";
|
|
1329
1471
|
process.exit(
|
|
1330
1472
|
runCiTrigger({
|
|
1331
1473
|
env: process.env,
|
|
1474
|
+
cryskSecrets,
|
|
1332
1475
|
gh: (args) => {
|
|
1333
1476
|
const result = Bun.spawnSync(["gh", ...args], {
|
|
1334
1477
|
stdout: "pipe",
|
package/src/cli.ts
CHANGED
|
@@ -59,7 +59,7 @@ export {
|
|
|
59
59
|
settleHeldCommitStatusOnSignal,
|
|
60
60
|
};
|
|
61
61
|
|
|
62
|
-
import { classifyCliError } from "#ci/classify-error";
|
|
62
|
+
import { classifyCliError, cliErrorParams } from "#ci/classify-error";
|
|
63
63
|
import { writeFatalCliRecord } from "#ci/cli-record";
|
|
64
64
|
import {
|
|
65
65
|
reportFatalCiError,
|
|
@@ -258,7 +258,11 @@ export async function main(argv: string[]): Promise<number> {
|
|
|
258
258
|
: await review(parsed.options);
|
|
259
259
|
} catch (error) {
|
|
260
260
|
if (error instanceof CliError || error instanceof CliUsageError) {
|
|
261
|
-
writeFatalCliRecord(
|
|
261
|
+
writeFatalCliRecord(
|
|
262
|
+
classifyCliError(error),
|
|
263
|
+
process.env,
|
|
264
|
+
cliErrorParams(error),
|
|
265
|
+
);
|
|
262
266
|
log(`error: ${error.message}`);
|
|
263
267
|
await reportFatalCiErrorIfInJobStep(error);
|
|
264
268
|
return 1;
|
|
@@ -326,7 +330,11 @@ export async function runCli(
|
|
|
326
330
|
// Before the rethrow below, and whatever GITHUB_OUTPUT says: a crash in
|
|
327
331
|
// action mode is the record's to name, unless this job already recorded its
|
|
328
332
|
// terminal outcome (writeFatalCliRecord keeps that one).
|
|
329
|
-
writeFatalCliRecord(
|
|
333
|
+
writeFatalCliRecord(
|
|
334
|
+
classifyCliError(error),
|
|
335
|
+
process.env,
|
|
336
|
+
cliErrorParams(error),
|
|
337
|
+
);
|
|
330
338
|
const outputPath = process.env.GITHUB_OUTPUT;
|
|
331
339
|
if (outputPath === undefined || outputPath.length === 0) {
|
|
332
340
|
// Not a real GitHub Actions job step — preserve the original
|
|
@@ -193,20 +193,20 @@ export async function askChoices(
|
|
|
193
193
|
value: "subscription",
|
|
194
194
|
label: "Claude subscription",
|
|
195
195
|
description:
|
|
196
|
-
"
|
|
196
|
+
"CRYSK_CLAUDE_OAUTH_TOKEN. Reviews spend quota, not dollars.",
|
|
197
197
|
},
|
|
198
198
|
{
|
|
199
199
|
value: "api",
|
|
200
200
|
label: "API key",
|
|
201
201
|
description:
|
|
202
|
-
"
|
|
202
|
+
"CRYSK_CLAUDE_API_KEY or an OpenCode provider's CRYSK_OPENCODE_* key. Reviews are billed per token.",
|
|
203
203
|
},
|
|
204
204
|
],
|
|
205
205
|
current.workflow.budgetUsd === undefined ? "subscription" : "api",
|
|
206
206
|
);
|
|
207
207
|
if (choices.billing === "subscription") {
|
|
208
208
|
say(
|
|
209
|
-
" No spend ceiling, and nothing to write: a subscription review spends quota, not dollars, and CI applies no ceiling while the
|
|
209
|
+
" No spend ceiling, and nothing to write: a subscription review spends quota, not dollars, and CI applies no ceiling while the run uses CRYSK_CLAUDE_OAUTH_TOKEN and no OpenCode model with its CRYSK_OPENCODE_* secret. A run on CRYSK_CLAUDE_API_KEY (no subscription set, or api_key first in credentials.claude) or an OpenCode model with its CRYSK_OPENCODE_* secret brings back the $10 ceiling.",
|
|
210
210
|
);
|
|
211
211
|
} else {
|
|
212
212
|
choices.budgetUsd = await askValue(
|
package/src/commands/ci-setup.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
|
+
import { homedir } from "node:os";
|
|
2
3
|
import path from "node:path";
|
|
4
|
+
import {
|
|
5
|
+
MAX_OPENCODE_PROVIDER_SLOTS,
|
|
6
|
+
OPENCODE_OAUTH_SECRET_PROVIDER,
|
|
7
|
+
opencodeSecretToken,
|
|
8
|
+
} from "#ci/crysk-secrets";
|
|
3
9
|
import {
|
|
4
10
|
budgetInput,
|
|
5
11
|
type CiSetupChoices,
|
|
@@ -12,10 +18,12 @@ import {
|
|
|
12
18
|
import {
|
|
13
19
|
appendIgnorePatterns,
|
|
14
20
|
ignorePatternsError,
|
|
21
|
+
OPENCODE_PROVIDERS_VARIABLE,
|
|
22
|
+
openCodeProvidersOfModels,
|
|
15
23
|
runCiSetup,
|
|
16
24
|
writeRepoReviewConfig,
|
|
17
25
|
} from "#ci/setup";
|
|
18
|
-
import { resolveOptionalRepoRoot } from "#config/config";
|
|
26
|
+
import { loadGlobalConfigLayer, resolveOptionalRepoRoot } from "#config/config";
|
|
19
27
|
import {
|
|
20
28
|
type CliOptions,
|
|
21
29
|
GOTCHAS_PLACEHOLDER_MARKER,
|
|
@@ -154,11 +162,117 @@ export interface CiSetupDeps {
|
|
|
154
162
|
// A person at a terminal gets the questions; anyone else gets flags or defaults.
|
|
155
163
|
interactive: boolean;
|
|
156
164
|
prompter: SetupPrompter;
|
|
165
|
+
// Whose personal config (~/.crysk/config.json) supplies the models and
|
|
166
|
+
// credentials the printed variable commands carry. Tests pass a scratch home.
|
|
167
|
+
home: string;
|
|
157
168
|
}
|
|
158
169
|
|
|
159
170
|
function defaultCiSetupDeps(): CiSetupDeps {
|
|
160
171
|
const gh = defaultGhPreflightDeps();
|
|
161
|
-
return {
|
|
172
|
+
return {
|
|
173
|
+
gh,
|
|
174
|
+
interactive: gh.interactive,
|
|
175
|
+
prompter: terminalPrompter(),
|
|
176
|
+
home: homedir(),
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// E-f F4 (odd/tasks/role-model-routing.md, D1, D2): what the scaffolded workflow
|
|
181
|
+
// reads from repository variables, taken from the person's own config, so the
|
|
182
|
+
// review in CI runs the models it runs locally. Only commands are printed: setting
|
|
183
|
+
// a variable or a secret is the person's call, on their repository.
|
|
184
|
+
interface WorkflowVariables {
|
|
185
|
+
// The personal config file, as the commands print it (`~/.crysk/config.json`).
|
|
186
|
+
readonly configLabel: string;
|
|
187
|
+
readonly hasModels: boolean;
|
|
188
|
+
readonly hasCredentials: boolean;
|
|
189
|
+
// The OpenCode providers the models name, as secret tokens (DEEPSEEK), sorted.
|
|
190
|
+
readonly openCodeTokens: readonly string[];
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
type WorkflowVariablesRead =
|
|
194
|
+
| { readonly ok: true; readonly variables: WorkflowVariables }
|
|
195
|
+
| { readonly ok: false; readonly problem: string };
|
|
196
|
+
|
|
197
|
+
async function readWorkflowVariables(
|
|
198
|
+
home: string,
|
|
199
|
+
): Promise<WorkflowVariablesRead> {
|
|
200
|
+
const { filePath, layer } = await loadGlobalConfigLayer(home);
|
|
201
|
+
const configLabel = filePath.startsWith(`${home}${path.sep}`)
|
|
202
|
+
? `~/${path.relative(home, filePath)}`
|
|
203
|
+
: filePath;
|
|
204
|
+
// The judge is skipped and every fallback counts, the providers the setup step
|
|
205
|
+
// builds the auth file for (openCodeProvidersOfModels).
|
|
206
|
+
const providers = openCodeProvidersOfModels(layer?.models);
|
|
207
|
+
const unnamed = providers.filter(
|
|
208
|
+
(provider) => opencodeSecretToken(provider) === undefined,
|
|
209
|
+
);
|
|
210
|
+
if (unnamed.length > 0) {
|
|
211
|
+
return {
|
|
212
|
+
ok: false,
|
|
213
|
+
problem: `The models in ${configLabel} name the OpenCode provider ${unnamed.map((p) => JSON.stringify(p)).join(", ")}, which no CRYSK_OPENCODE_* secret name can carry. Nothing was written.`,
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
const openCodeTokens = [
|
|
217
|
+
...new Set(
|
|
218
|
+
providers.map((provider) => opencodeSecretToken(provider) as string),
|
|
219
|
+
),
|
|
220
|
+
].sort();
|
|
221
|
+
if (openCodeTokens.length > MAX_OPENCODE_PROVIDER_SLOTS) {
|
|
222
|
+
return {
|
|
223
|
+
ok: false,
|
|
224
|
+
problem: `The models in ${configLabel} name ${openCodeTokens.length} OpenCode providers (${providers.join(", ")}), but the workflow forwards the keys of at most ${MAX_OPENCODE_PROVIDER_SLOTS}. Use at most ${MAX_OPENCODE_PROVIDER_SLOTS} OpenCode providers across your models, then run this again. Nothing was written.`,
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
return {
|
|
228
|
+
ok: true,
|
|
229
|
+
variables: {
|
|
230
|
+
configLabel,
|
|
231
|
+
hasModels: layer?.models !== undefined,
|
|
232
|
+
hasCredentials: layer?.credentials !== undefined,
|
|
233
|
+
openCodeTokens,
|
|
234
|
+
},
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// The commands that put a person's models, credential order and OpenCode
|
|
239
|
+
// providers where the scaffolded workflow reads them. Empty when the personal
|
|
240
|
+
// config sets none of them: the workflow then runs the default Claude model.
|
|
241
|
+
export function workflowVariableCommands(
|
|
242
|
+
variables: WorkflowVariables,
|
|
243
|
+
): string[] {
|
|
244
|
+
const commands: string[] = [];
|
|
245
|
+
if (variables.hasModels) {
|
|
246
|
+
commands.push(
|
|
247
|
+
`$ gh variable set CRYSK_MODELS --body "$(jq -c .models ${variables.configLabel})"`,
|
|
248
|
+
);
|
|
249
|
+
}
|
|
250
|
+
if (variables.hasCredentials) {
|
|
251
|
+
commands.push(
|
|
252
|
+
`$ gh variable set CRYSK_CREDENTIALS --body "$(jq -c .credentials ${variables.configLabel})"`,
|
|
253
|
+
);
|
|
254
|
+
}
|
|
255
|
+
if (variables.openCodeTokens.length > 0) {
|
|
256
|
+
commands.push(
|
|
257
|
+
`$ gh variable set ${OPENCODE_PROVIDERS_VARIABLE} --body '${JSON.stringify(variables.openCodeTokens)}'`,
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
return commands;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
const OPENAI_TOKEN = opencodeSecretToken(OPENCODE_OAUTH_SECRET_PROVIDER);
|
|
264
|
+
|
|
265
|
+
// One secret per OpenCode provider the models name. OpenAI may be a ChatGPT
|
|
266
|
+
// subscription instead of a key: its OpenCode login record, base64 on one line.
|
|
267
|
+
export function openCodeSecretCommands(tokens: readonly string[]): string[] {
|
|
268
|
+
return tokens.flatMap((token) =>
|
|
269
|
+
token === OPENAI_TOKEN
|
|
270
|
+
? [
|
|
271
|
+
`$ gh secret set CRYSK_OPENCODE_${token}_API_KEY`,
|
|
272
|
+
` or, for a ChatGPT subscription (on macOS, drop -w0): jq -c .openai ~/.local/share/opencode/auth.json | base64 -w0 | gh secret set CRYSK_OPENCODE_${token}_OAUTH`,
|
|
273
|
+
]
|
|
274
|
+
: [`$ gh secret set CRYSK_OPENCODE_${token}_API_KEY`],
|
|
275
|
+
);
|
|
162
276
|
}
|
|
163
277
|
|
|
164
278
|
// Flags win (an agent already asked the person), then a terminal's answers,
|
|
@@ -246,6 +360,15 @@ export async function ciSetupCommand(
|
|
|
246
360
|
return 1;
|
|
247
361
|
}
|
|
248
362
|
|
|
363
|
+
// Before any question and any write: models naming more OpenCode providers than
|
|
364
|
+
// the workflow has slots for would scaffold a workflow that drops some keys.
|
|
365
|
+
const variablesRead = await readWorkflowVariables(deps.home);
|
|
366
|
+
if (!variablesRead.ok) {
|
|
367
|
+
log(variablesRead.problem);
|
|
368
|
+
return 1;
|
|
369
|
+
}
|
|
370
|
+
const variables = variablesRead.variables;
|
|
371
|
+
|
|
249
372
|
const current = await readCurrentSettings(repoRoot, target);
|
|
250
373
|
const choices = await resolveChoices(options, deps, current);
|
|
251
374
|
const budget = budgetInput(choices);
|
|
@@ -333,19 +456,42 @@ export async function ciSetupCommand(
|
|
|
333
456
|
let step = 0;
|
|
334
457
|
const next = () => ` ${++step}.`;
|
|
335
458
|
log(`${next()} Commit ${workflowRelative} and ${repoDirName}/config.json`);
|
|
459
|
+
// The CRYSK_* names the scaffolded workflow reads (S8); gh asks for the value.
|
|
336
460
|
log(
|
|
337
461
|
`${next()} Add a repository secret: ${
|
|
338
462
|
choices.billing === "subscription"
|
|
339
|
-
? "
|
|
463
|
+
? "CRYSK_CLAUDE_OAUTH_TOKEN (create the value with `claude setup-token`)"
|
|
340
464
|
: choices.billing === "api"
|
|
341
|
-
? "
|
|
342
|
-
: "
|
|
465
|
+
? "CRYSK_CLAUDE_API_KEY (or the CRYSK_OPENCODE_* key of the OpenCode provider your models use)"
|
|
466
|
+
: "CRYSK_CLAUDE_OAUTH_TOKEN (create the value with `claude setup-token`) or CRYSK_CLAUDE_API_KEY"
|
|
343
467
|
}`,
|
|
344
468
|
);
|
|
469
|
+
log(
|
|
470
|
+
` $ gh secret set ${
|
|
471
|
+
choices.billing === "api"
|
|
472
|
+
? "CRYSK_CLAUDE_API_KEY"
|
|
473
|
+
: "CRYSK_CLAUDE_OAUTH_TOKEN"
|
|
474
|
+
}`,
|
|
475
|
+
);
|
|
476
|
+
if (variables.openCodeTokens.length > 0) {
|
|
477
|
+
log(
|
|
478
|
+
`${next()} Add the API key of each OpenCode provider your models in ${variables.configLabel} use:`,
|
|
479
|
+
);
|
|
480
|
+
for (const line of openCodeSecretCommands(variables.openCodeTokens)) {
|
|
481
|
+
log(` ${line}`);
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
const variableCommands = workflowVariableCommands(variables);
|
|
485
|
+
if (variableCommands.length > 0) {
|
|
486
|
+
log(
|
|
487
|
+
`${next()} Set the repository variables the workflow reads your models from (${variables.configLabel}):`,
|
|
488
|
+
);
|
|
489
|
+
for (const line of variableCommands) log(` ${line}`);
|
|
490
|
+
}
|
|
345
491
|
// Review instructions are optional (odd/tasks/review-md.md S3): with none
|
|
346
492
|
// the review runs on the default guidance, so a repo without a file gets a
|
|
347
493
|
// recommendation, not a required step. A file that exists but is empty or
|
|
348
|
-
// still the scaffold turns the first PR red (
|
|
494
|
+
// still the scaffold turns the first PR red (CRYSK-GOTCHAS-MISSING), so that
|
|
349
495
|
// one gets the fix steps. Asked through the resolver and the gate the review
|
|
350
496
|
// itself uses, so this advice cannot disagree with the run.
|
|
351
497
|
const instructions = resolveReviewInstructions(undefined, repoRoot);
|
package/src/commands/config.ts
CHANGED
|
@@ -95,5 +95,8 @@ export async function configCommand(options: CliOptions): Promise<number> {
|
|
|
95
95
|
width: terminalWidth(),
|
|
96
96
|
});
|
|
97
97
|
process.stdout.write(`${lines.join("\n")}\n`);
|
|
98
|
+
for (const warning of loaded.warnings) {
|
|
99
|
+
process.stderr.write(`warning: ${warning}\n`);
|
|
100
|
+
}
|
|
98
101
|
return 0;
|
|
99
102
|
}
|