crysk 0.0.0 → 0.3.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.
- package/LICENSE +176 -0
- package/README.md +611 -3
- package/bin/pr-hero.js +166 -0
- package/config/models/anthropic.json +5 -0
- package/dist/SKILL-7e3725zn.md +496 -0
- package/dist/SKILL-7q35wcaz.md +66 -0
- package/dist/SKILL-9at22381.md +74 -0
- package/dist/SKILL-ex2hxxh3.md +134 -0
- package/dist/SKILL-y8rv8msh.md +134 -0
- package/dist/SKILL-ygka1bs0.md +515 -0
- package/dist/adjudicator-dtg2axnh.md +86 -0
- package/dist/admission-config.example-a9vqmmad.json +9 -0
- package/dist/ci-admission-camfbx2b.md +122 -0
- package/dist/ci-admission-qk9r9taq.md +124 -0
- package/dist/cli.js +42501 -0
- package/dist/consolidate-ac0mnfyj.md +24 -0
- package/dist/deep-review-lifecycle-m698ybjp.md +362 -0
- package/dist/deep-review-logic-a6b1gczf.md +156 -0
- package/dist/deep-review-parity-0ec904db.md +120 -0
- package/dist/deep-review-reliability-qyakbjb9.md +125 -0
- package/dist/deep-review-resilience-3tz8y26e.md +118 -0
- package/dist/index.js +20190 -0
- package/dist/opencode-ci-7b0be64p.md +141 -0
- package/dist/review-refuter-j4e9gezy.md +71 -0
- package/dist/scout-yvp153q7.md +140 -0
- package/dist/summarizer-zca44nxa.md +18 -0
- package/dist/workflow-w1g9szna.yml +151 -0
- package/package.json +81 -4
- package/prompts/consolidate.md +24 -0
- package/prompts/default/PROVENANCE.md +18 -0
- package/prompts/default/deep-review-lifecycle.md +362 -0
- package/prompts/default/deep-review-logic.md +156 -0
- package/prompts/default/deep-review-parity.md +120 -0
- package/prompts/default/deep-review-reliability.md +125 -0
- package/prompts/default/deep-review-resilience.md +118 -0
- package/prompts/default/review-refuter.md +71 -0
- package/prompts/scout.md +140 -0
- package/prompts/summarizer.md +18 -0
- package/skills/crysk/SKILL.md +74 -0
- package/skills/crysk-ci-setup/SKILL.md +134 -0
- package/skills/crysk-ci-setup/assets/admission-config.example.json +9 -0
- package/skills/crysk-ci-setup/assets/workflow.yml +151 -0
- package/skills/crysk-ci-setup/references/ci-admission.md +124 -0
- package/skills/crysk-ci-setup/references/opencode-ci.md +141 -0
- package/skills/crysk-loop/SKILL.md +515 -0
- package/skills/crysk-loop/adjudicator.md +86 -0
- package/skills/crysk-pr/SKILL.md +66 -0
- package/src/agent-env.ts +1084 -0
- package/src/asset-manifest.ts +83 -0
- package/src/assets.d.ts +6 -0
- package/src/assets.ts +183 -0
- package/src/brand-paths.ts +155 -0
- package/src/brand.ts +255 -0
- package/src/ci/admission-ledger.ts +350 -0
- package/src/ci/classify-error.ts +73 -0
- package/src/ci/cli-record.ts +271 -0
- package/src/ci/force-comment.ts +39 -0
- package/src/ci/gates.ts +945 -0
- package/src/ci/outcome.ts +2181 -0
- package/src/ci/override.ts +187 -0
- package/src/ci/publish.ts +1639 -0
- package/src/ci/reporter.ts +626 -0
- package/src/ci/review-admission.ts +910 -0
- package/src/ci/review-levels.ts +310 -0
- package/src/ci/review-policy.ts +18 -0
- package/src/ci/review-risk.ts +184 -0
- package/src/ci/setup.ts +844 -0
- package/src/ci/trigger.ts +1353 -0
- package/src/cli.ts +348 -0
- package/src/commands/activity.ts +67 -0
- package/src/commands/ci-setup-questions.ts +397 -0
- package/src/commands/ci-setup.ts +381 -0
- package/src/commands/config.ts +99 -0
- package/src/commands/doctor.ts +108 -0
- package/src/commands/init.ts +139 -0
- package/src/commands/mcp.ts +10 -0
- package/src/commands/menu.ts +129 -0
- package/src/commands/post.ts +302 -0
- package/src/commands/skills.ts +83 -0
- package/src/commands/status.ts +173 -0
- package/src/commands/triage.ts +342 -0
- package/src/commands/uninstall.ts +37 -0
- package/src/commands/upgrade.ts +214 -0
- package/src/commands/usage.ts +98 -0
- package/src/compare/compare.ts +28 -0
- package/src/compare/floor-test.ts +471 -0
- package/src/compare/martian-adapter.ts +80 -0
- package/src/config/config.ts +267 -0
- package/src/corpus/corpus.ts +1094 -0
- package/src/corpus/preflight.ts +1789 -0
- package/src/diversity/accounting.ts +90 -0
- package/src/diversity/adjudication.ts +145 -0
- package/src/diversity/admission.ts +60 -0
- package/src/diversity/benchmark.ts +195 -0
- package/src/diversity/clustering.ts +285 -0
- package/src/diversity/errors.ts +7 -0
- package/src/diversity/identity.ts +285 -0
- package/src/diversity/index.ts +11 -0
- package/src/diversity/pipeline-integration.ts +448 -0
- package/src/diversity/projection.ts +57 -0
- package/src/diversity/self-contained.ts +68 -0
- package/src/diversity/target-validation.ts +179 -0
- package/src/doctor-migration.ts +209 -0
- package/src/doctor.ts +723 -0
- package/src/errors.ts +83 -0
- package/src/execution/admission.ts +75 -0
- package/src/execution/atomic-write.ts +35 -0
- package/src/execution/attempt-evidence.ts +415 -0
- package/src/execution/bucket-id.ts +136 -0
- package/src/execution/concurrency-limiter.ts +175 -0
- package/src/execution/contracts.ts +443 -0
- package/src/execution/failure-classification.ts +42 -0
- package/src/execution/failure-policy.ts +240 -0
- package/src/execution/harness.ts +2548 -0
- package/src/execution/settlement.ts +348 -0
- package/src/execution/spawned-process.ts +66 -0
- package/src/execution/spend-limiter.ts +424 -0
- package/src/execution/step-artifacts.ts +55 -0
- package/src/execution/usage-normalized.ts +469 -0
- package/src/git/git.ts +396 -0
- package/src/git/identity.ts +64 -0
- package/src/git/refs.ts +140 -0
- package/src/home-preflight.ts +443 -0
- package/src/home.ts +243 -0
- package/src/ignore-file.ts +336 -0
- package/src/ignore-read.ts +118 -0
- package/src/index.ts +34 -0
- package/src/legacy-launchd.ts +29 -0
- package/src/mcp/mcp.ts +150 -0
- package/src/mcp/preflight.ts +407 -0
- package/src/menu-context.ts +192 -0
- package/src/model/catalog.ts +251 -0
- package/src/model/exec-snapshots.ts +390 -0
- package/src/model/free-discovery.ts +302 -0
- package/src/model/provider-capabilities.ts +814 -0
- package/src/model/routing.ts +600 -0
- package/src/pr/admission.ts +984 -0
- package/src/pr/answered-findings.ts +169 -0
- package/src/pr/ci-admission-gate.ts +743 -0
- package/src/pr/ci-publish.ts +76 -0
- package/src/pr/discovery.ts +432 -0
- package/src/pr/inline.ts +507 -0
- package/src/pr/plan.ts +366 -0
- package/src/pr/posting.ts +115 -0
- package/src/pr/pr-status.ts +845 -0
- package/src/pr/pr.ts +3642 -0
- package/src/pr/preflight.ts +1031 -0
- package/src/pr/publish-outcome.ts +361 -0
- package/src/pr/range.ts +119 -0
- package/src/pr/reverts-preflight.ts +606 -0
- package/src/pr/reverts.ts +377 -0
- package/src/pr/review-pr.ts +927 -0
- package/src/pr/status.ts +154 -0
- package/src/pr/target.ts +388 -0
- package/src/pr/teardown.ts +437 -0
- package/src/pr/worktree-setup.ts +60 -0
- package/src/production-runtime.ts +1877 -0
- package/src/progress.ts +487 -0
- package/src/rereview/adjudicate.ts +89 -0
- package/src/rereview/classify.ts +362 -0
- package/src/rereview/identity.ts +211 -0
- package/src/rereview/plan.ts +308 -0
- package/src/rereview/prepare.ts +1025 -0
- package/src/rereview/state.ts +767 -0
- package/src/rereview/verify.ts +241 -0
- package/src/review/boundary.ts +105 -0
- package/src/review/consolidate.ts +246 -0
- package/src/review/dedupe.ts +368 -0
- package/src/review/drafts.ts +448 -0
- package/src/review/findings-conformance.ts +120 -0
- package/src/review/findings.ts +714 -0
- package/src/review/pipeline.ts +3977 -0
- package/src/review/preflight.ts +3575 -0
- package/src/review/prompt-set.ts +177 -0
- package/src/review/proof-refs.ts +187 -0
- package/src/review/report.ts +1821 -0
- package/src/review/review.ts +490 -0
- package/src/review/root-cause.ts +120 -0
- package/src/review/route-preflight.ts +289 -0
- package/src/review/run.ts +601 -0
- package/src/review/scout.ts +323 -0
- package/src/review/size-gate.ts +595 -0
- package/src/review/spec.ts +235 -0
- package/src/review/step-runner.ts +233 -0
- package/src/runner-authority.ts +596 -0
- package/src/security/binding-policy.ts +115 -0
- package/src/security/credential-broker.ts +773 -0
- package/src/security/evidence-redaction.ts +62 -0
- package/src/security/execution-authority.ts +27 -0
- package/src/security/redact.ts +71 -0
- package/src/security/workspace-read-broker.ts +466 -0
- package/src/server/client.ts +190 -0
- package/src/server/preflight.ts +217 -0
- package/src/server/server.ts +327 -0
- package/src/signal-handler.ts +50 -0
- package/src/store/activity.ts +413 -0
- package/src/store/backfill-preflight.ts +49 -0
- package/src/store/backfill.ts +141 -0
- package/src/store/gc-preflight.ts +206 -0
- package/src/store/gc.ts +424 -0
- package/src/store/metrics-preflight.ts +229 -0
- package/src/store/metrics.ts +236 -0
- package/src/store/preflight.ts +748 -0
- package/src/store/store.ts +693 -0
- package/src/system-tools.ts +355 -0
- package/src/transport-registry.ts +1124 -0
- package/src/transports/claude-code-cli.ts +1348 -0
- package/src/transports/opencode-admission.ts +515 -0
- package/src/transports/opencode-client.ts +3328 -0
- package/src/transports/opencode-evidence.ts +557 -0
- package/src/transports/opencode-mcp.ts +248 -0
- package/src/transports/opencode-sdk.ts +2294 -0
- package/src/transports/opencode-server.ts +535 -0
- package/src/triage/adjudication.ts +113 -0
- package/src/triage/reply.ts +125 -0
- package/src/triage/triage.ts +255 -0
- package/src/ui/activity.ts +173 -0
- package/src/ui/config-edit.ts +816 -0
- package/src/ui/config.ts +462 -0
- package/src/ui/menu.ts +1325 -0
- package/src/ui/plan.ts +1039 -0
- package/src/ui/primitives.ts +300 -0
- package/src/ui/progress.ts +298 -0
- package/src/ui/result.ts +552 -0
- package/src/ui/review-menu.ts +312 -0
- package/src/ui/select.ts +528 -0
- package/src/ui/tree.ts +178 -0
- package/src/uninstaller.ts +479 -0
- package/src/updater.ts +836 -0
- package/src/usage.ts +77 -0
- package/src/watch/preflight.ts +1389 -0
- package/src/watch/watch.ts +1235 -0
- package/src/wizard.ts +877 -0
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import {
|
|
4
|
+
budgetInput,
|
|
5
|
+
type CiSetupChoices,
|
|
6
|
+
type CurrentSettings,
|
|
7
|
+
configPlan,
|
|
8
|
+
defaultChoices,
|
|
9
|
+
parseWorkflowChoices,
|
|
10
|
+
renderChoicesSummary,
|
|
11
|
+
} from "#ci/review-levels";
|
|
12
|
+
import {
|
|
13
|
+
appendIgnorePatterns,
|
|
14
|
+
ignorePatternsError,
|
|
15
|
+
runCiSetup,
|
|
16
|
+
writeRepoReviewConfig,
|
|
17
|
+
} from "#ci/setup";
|
|
18
|
+
import { resolveOptionalRepoRoot } from "#config/config";
|
|
19
|
+
import {
|
|
20
|
+
type CliOptions,
|
|
21
|
+
GOTCHAS_PLACEHOLDER_MARKER,
|
|
22
|
+
gotchasUnusableReason,
|
|
23
|
+
} from "#review/preflight";
|
|
24
|
+
import { log } from "#ui/primitives";
|
|
25
|
+
import {
|
|
26
|
+
duplicateWorkflowProblem,
|
|
27
|
+
resolveIgnoreFileName,
|
|
28
|
+
resolveRepoDir,
|
|
29
|
+
resolveWorkflowRelativePath,
|
|
30
|
+
} from "../brand-paths";
|
|
31
|
+
import { CliError } from "../errors";
|
|
32
|
+
import {
|
|
33
|
+
checkGhStatus,
|
|
34
|
+
type InstallResult,
|
|
35
|
+
installSystemTool,
|
|
36
|
+
type SystemToolStatus,
|
|
37
|
+
} from "../system-tools";
|
|
38
|
+
import {
|
|
39
|
+
askChoices,
|
|
40
|
+
choicesFromFlags,
|
|
41
|
+
type SetupPrompter,
|
|
42
|
+
terminalPrompter,
|
|
43
|
+
} from "./ci-setup-questions";
|
|
44
|
+
|
|
45
|
+
// What the gh check talks to, injectable so its every branch runs offline.
|
|
46
|
+
export interface GhPreflightDeps {
|
|
47
|
+
check: () => Promise<SystemToolStatus>;
|
|
48
|
+
// A human at a terminal. Agents run `setup --ci` with no TTY and must never
|
|
49
|
+
// be left waiting on a prompt, so they only get the printed instructions.
|
|
50
|
+
interactive: boolean;
|
|
51
|
+
ask: (question: string) => Promise<boolean>;
|
|
52
|
+
install: () => Promise<InstallResult>;
|
|
53
|
+
login: () => Promise<number>;
|
|
54
|
+
installCommand: string;
|
|
55
|
+
// Only where installSystemTool can actually install it (macOS with brew).
|
|
56
|
+
// Elsewhere it would just hand back a manual command, so nothing is offered.
|
|
57
|
+
canAutoInstall: boolean;
|
|
58
|
+
log: (line?: string) => void;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const GH_WHY =
|
|
62
|
+
"Crysk's CI loop needs it on this machine: to add the repository secret (gh secret set), and after a pull request opens, to wait for its review (crysk status) and answer the findings (crysk triage reply).";
|
|
63
|
+
|
|
64
|
+
// Never blocks and never changes the exit code: the workflow file does not
|
|
65
|
+
// need gh, and a user may add the secret in GitHub's web UI instead.
|
|
66
|
+
export async function ghPreflight(deps: GhPreflightDeps): Promise<void> {
|
|
67
|
+
let status = await deps.check();
|
|
68
|
+
if (status.installed && status.authOk) return;
|
|
69
|
+
const say = deps.log;
|
|
70
|
+
say();
|
|
71
|
+
say(
|
|
72
|
+
`GitHub CLI (gh) is ${status.installed ? "not logged in" : "not installed"}. ${GH_WHY}`,
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
if (!status.installed) {
|
|
76
|
+
let installCommand = deps.installCommand;
|
|
77
|
+
if (
|
|
78
|
+
deps.interactive &&
|
|
79
|
+
deps.canAutoInstall &&
|
|
80
|
+
(await deps.ask(`Install it now with \`${deps.installCommand}\`?`))
|
|
81
|
+
) {
|
|
82
|
+
const result = await deps.install();
|
|
83
|
+
installCommand = result.manualCommand ?? installCommand;
|
|
84
|
+
if (!result.ok) {
|
|
85
|
+
say(
|
|
86
|
+
`The install failed${result.error ? `: ${result.error.trim()}` : "."}`,
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
status = await deps.check();
|
|
90
|
+
}
|
|
91
|
+
if (!status.installed) {
|
|
92
|
+
say(` Install it: ${installCommand}`);
|
|
93
|
+
say(" Then log in: gh auth login");
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (!status.authOk) {
|
|
99
|
+
if (deps.interactive && (await deps.ask("Run `gh auth login` now?"))) {
|
|
100
|
+
await deps.login();
|
|
101
|
+
status = await deps.check();
|
|
102
|
+
}
|
|
103
|
+
if (!status.authOk) {
|
|
104
|
+
say(" Log in: gh auth login");
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
say("gh is installed and logged in.");
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
async function askYesNo(question: string): Promise<boolean> {
|
|
112
|
+
const { createInterface } = await import("node:readline/promises");
|
|
113
|
+
const rl = createInterface({ input: process.stdin, output: process.stderr });
|
|
114
|
+
try {
|
|
115
|
+
const answer = await rl.question(`${question} [Y/n] `);
|
|
116
|
+
return /^\s*(y|yes)?\s*$/i.test(answer);
|
|
117
|
+
} finally {
|
|
118
|
+
rl.close();
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function defaultGhPreflightDeps(): GhPreflightDeps {
|
|
123
|
+
const canAutoInstall =
|
|
124
|
+
process.platform === "darwin" && Bun.which("brew") !== null;
|
|
125
|
+
return {
|
|
126
|
+
check: () => checkGhStatus(),
|
|
127
|
+
interactive: Boolean(process.stdin.isTTY && process.stderr.isTTY),
|
|
128
|
+
ask: askYesNo,
|
|
129
|
+
install: () => installSystemTool("gh"),
|
|
130
|
+
login: async () => {
|
|
131
|
+
// gh's own interactive login, on this terminal.
|
|
132
|
+
const proc = Bun.spawn([Bun.which("gh") ?? "gh", "auth", "login"], {
|
|
133
|
+
stdio: ["inherit", "inherit", "inherit"],
|
|
134
|
+
});
|
|
135
|
+
return await proc.exited;
|
|
136
|
+
},
|
|
137
|
+
installCommand: canAutoInstall
|
|
138
|
+
? "brew install gh"
|
|
139
|
+
: "see https://github.com/cli/cli#installation",
|
|
140
|
+
canAutoInstall,
|
|
141
|
+
log,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Shared shell for `pr-hero setup --ci` and `pr-hero ci init` — both are the
|
|
146
|
+
// same scaffolding action (runCiSetup), reached by two different command
|
|
147
|
+
// spellings. The refusal-without-force branch is a safety property (see
|
|
148
|
+
// spec.md §4.1 / ci/setup.ts's header comment), not a usage error, so it
|
|
149
|
+
// returns 1 rather than throwing CliUsageError: the invocation was valid,
|
|
150
|
+
// the outcome is just "nothing was written".
|
|
151
|
+
export interface CiSetupDeps {
|
|
152
|
+
gh: GhPreflightDeps;
|
|
153
|
+
// A person at a terminal gets the questions; anyone else gets flags or defaults.
|
|
154
|
+
interactive: boolean;
|
|
155
|
+
prompter: SetupPrompter;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function defaultCiSetupDeps(): CiSetupDeps {
|
|
159
|
+
const gh = defaultGhPreflightDeps();
|
|
160
|
+
return { gh, interactive: gh.interactive, prompter: terminalPrompter() };
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// Flags win (an agent already asked the person), then a terminal's answers,
|
|
164
|
+
// then the defaults, which the summary reports as nobody's choice.
|
|
165
|
+
async function resolveChoices(
|
|
166
|
+
options: CliOptions,
|
|
167
|
+
deps: CiSetupDeps,
|
|
168
|
+
current: CurrentSettings,
|
|
169
|
+
): Promise<CiSetupChoices> {
|
|
170
|
+
const fromFlags = choicesFromFlags(options);
|
|
171
|
+
const choices =
|
|
172
|
+
fromFlags ??
|
|
173
|
+
(deps.interactive
|
|
174
|
+
? await askChoices(deps.prompter, log, current)
|
|
175
|
+
: defaultChoices());
|
|
176
|
+
// A --force refresh rewrites the workflow; what nobody chose this run keeps
|
|
177
|
+
// what the old workflow said, the same rule the config follows.
|
|
178
|
+
if (!choices.chosen.mode && current.workflow.mode !== undefined) {
|
|
179
|
+
choices.mode = current.workflow.mode;
|
|
180
|
+
}
|
|
181
|
+
const oldBudget = Number(current.workflow.budgetUsd);
|
|
182
|
+
if (
|
|
183
|
+
!choices.chosen.billing &&
|
|
184
|
+
current.workflow.budgetUsd !== undefined &&
|
|
185
|
+
Number.isFinite(oldBudget)
|
|
186
|
+
) {
|
|
187
|
+
choices.billing = "api";
|
|
188
|
+
choices.budgetUsd = oldBudget;
|
|
189
|
+
}
|
|
190
|
+
return choices;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// What the repository says now. A config that is not valid JSON reads as
|
|
194
|
+
// empty here; writeRepoReviewConfig refuses it before anything is written.
|
|
195
|
+
async function readCurrentSettings(
|
|
196
|
+
repoRoot: string,
|
|
197
|
+
workflowPath: string,
|
|
198
|
+
): Promise<CurrentSettings> {
|
|
199
|
+
let config: Record<string, unknown> = {};
|
|
200
|
+
const configFile = Bun.file(
|
|
201
|
+
path.join(resolveRepoDir(repoRoot), "config.json"),
|
|
202
|
+
);
|
|
203
|
+
if (await configFile.exists()) {
|
|
204
|
+
try {
|
|
205
|
+
const parsed: unknown = JSON.parse(await configFile.text());
|
|
206
|
+
if (
|
|
207
|
+
parsed !== null &&
|
|
208
|
+
typeof parsed === "object" &&
|
|
209
|
+
!Array.isArray(parsed)
|
|
210
|
+
) {
|
|
211
|
+
config = parsed as Record<string, unknown>;
|
|
212
|
+
}
|
|
213
|
+
} catch {
|
|
214
|
+
// refused later, by the writer
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
const workflowFile = Bun.file(workflowPath);
|
|
218
|
+
const workflow = (await workflowFile.exists())
|
|
219
|
+
? parseWorkflowChoices(await workflowFile.text())
|
|
220
|
+
: {};
|
|
221
|
+
return { config, workflow };
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export async function ciSetupCommand(
|
|
225
|
+
options: CliOptions,
|
|
226
|
+
overrides: Partial<CiSetupDeps> = {},
|
|
227
|
+
): Promise<number> {
|
|
228
|
+
const deps = { ...defaultCiSetupDeps(), ...overrides };
|
|
229
|
+
const repoRoot = (await resolveOptionalRepoRoot(options)) ?? process.cwd();
|
|
230
|
+
|
|
231
|
+
// Before any question: an existing workflow without --force writes nothing,
|
|
232
|
+
// so asking first would collect answers that are then thrown away.
|
|
233
|
+
const duplicate = duplicateWorkflowProblem(repoRoot);
|
|
234
|
+
if (duplicate !== undefined) {
|
|
235
|
+
log(duplicate);
|
|
236
|
+
return 1;
|
|
237
|
+
}
|
|
238
|
+
// The file the repo already has (a pre-rename pr-hero.yml stays where it is),
|
|
239
|
+
// else the new name.
|
|
240
|
+
const workflowRelative = resolveWorkflowRelativePath(repoRoot);
|
|
241
|
+
const target = path.join(repoRoot, workflowRelative);
|
|
242
|
+
if (existsSync(target) && !options.force) {
|
|
243
|
+
log(`${target} already exists.`);
|
|
244
|
+
log(`${workflowRelative} already exists; pass --force to overwrite it`);
|
|
245
|
+
return 1;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
const current = await readCurrentSettings(repoRoot, target);
|
|
249
|
+
const choices = await resolveChoices(options, deps, current);
|
|
250
|
+
const budget = budgetInput(choices);
|
|
251
|
+
// The config first: it is the write that can refuse (an invalid existing
|
|
252
|
+
// file, a value the review parser rejects), and refusing before the workflow
|
|
253
|
+
// is written leaves the repository as it was.
|
|
254
|
+
const patterns = choices.advanced.ignorePatterns ?? [];
|
|
255
|
+
// An existing .prheroignore keeps being extended in place; a fresh repo gets
|
|
256
|
+
// .cryskignore.
|
|
257
|
+
const ignoreFile = Bun.file(
|
|
258
|
+
path.join(repoRoot, resolveIgnoreFileName(repoRoot)),
|
|
259
|
+
);
|
|
260
|
+
const patternProblem = ignorePatternsError(
|
|
261
|
+
patterns,
|
|
262
|
+
(await ignoreFile.exists()) ? await ignoreFile.text() : "",
|
|
263
|
+
);
|
|
264
|
+
if (patternProblem !== undefined) throw new CliError(patternProblem);
|
|
265
|
+
const config = await writeRepoReviewConfig(repoRoot, configPlan(choices));
|
|
266
|
+
// After the write, so a fresh repo reports the .crysk/ it just got.
|
|
267
|
+
const repoDirName = path.basename(resolveRepoDir(repoRoot));
|
|
268
|
+
const result = await runCiSetup({
|
|
269
|
+
cwd: repoRoot,
|
|
270
|
+
force: options.force,
|
|
271
|
+
template: {
|
|
272
|
+
mode: choices.mode,
|
|
273
|
+
...(budget === undefined ? {} : { budgetUsd: budget }),
|
|
274
|
+
// Size inputs a person set by hand in the old workflow. setup never
|
|
275
|
+
// writes them (it writes the config keys), so a refresh carries them
|
|
276
|
+
// over; the action gives a workflow input precedence over the config.
|
|
277
|
+
...(current.workflow.maxChangedLines === undefined
|
|
278
|
+
? {}
|
|
279
|
+
: { maxChangedLines: current.workflow.maxChangedLines }),
|
|
280
|
+
...(current.workflow.maxChangedFiles === undefined
|
|
281
|
+
? {}
|
|
282
|
+
: { maxChangedFiles: current.workflow.maxChangedFiles }),
|
|
283
|
+
},
|
|
284
|
+
});
|
|
285
|
+
if (result.status === "refused-duplicate") {
|
|
286
|
+
log(result.hint);
|
|
287
|
+
return 1;
|
|
288
|
+
}
|
|
289
|
+
if (result.status === "skipped-existing") {
|
|
290
|
+
log(`${result.path} already exists.`);
|
|
291
|
+
log(result.hint);
|
|
292
|
+
return 1;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
log();
|
|
296
|
+
log(
|
|
297
|
+
result.status === "overwritten"
|
|
298
|
+
? `Overwrote ${result.path}`
|
|
299
|
+
: `Created ${result.path}`,
|
|
300
|
+
);
|
|
301
|
+
log(`Updated ${config.file}`);
|
|
302
|
+
if (patterns.length > 0) {
|
|
303
|
+
log(`Updated ${await appendIgnorePatterns(repoRoot, patterns)}`);
|
|
304
|
+
}
|
|
305
|
+
log();
|
|
306
|
+
for (const line of renderChoicesSummary(choices, config.kept, config.config))
|
|
307
|
+
log(line);
|
|
308
|
+
// The summary describes the choices; these lines say where the file differs.
|
|
309
|
+
for (const c of config.changed) {
|
|
310
|
+
log(
|
|
311
|
+
`Changed ${c.key}: ${JSON.stringify(c.from)} -> ${JSON.stringify(c.to)}`,
|
|
312
|
+
);
|
|
313
|
+
}
|
|
314
|
+
for (const [input, value] of [
|
|
315
|
+
["max-changed-lines", current.workflow.maxChangedLines],
|
|
316
|
+
["max-changed-files", current.workflow.maxChangedFiles],
|
|
317
|
+
] as const) {
|
|
318
|
+
if (value !== undefined) {
|
|
319
|
+
log(
|
|
320
|
+
`Kept the workflow's ${input}: ${value}; it takes precedence over ${repoDirName}/config.json`,
|
|
321
|
+
);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
const keptKeys = Object.keys(config.kept);
|
|
325
|
+
if (keptKeys.length > 0) {
|
|
326
|
+
log(
|
|
327
|
+
`Kept existing ${keptKeys.map((key) => `${key} ${JSON.stringify(config.kept[key])}`).join(", ")} in ${repoDirName}/config.json: nobody chose them this run (pass --level or --max-changed-lines, or answer in a terminal, to change them)`,
|
|
328
|
+
);
|
|
329
|
+
}
|
|
330
|
+
log();
|
|
331
|
+
log("Next steps:");
|
|
332
|
+
let step = 0;
|
|
333
|
+
const next = () => ` ${++step}.`;
|
|
334
|
+
log(`${next()} Commit ${workflowRelative} and ${repoDirName}/config.json`);
|
|
335
|
+
log(
|
|
336
|
+
`${next()} Add a repository secret: ${
|
|
337
|
+
choices.billing === "subscription"
|
|
338
|
+
? "CLAUDE_CODE_OAUTH_TOKEN (create it with `claude setup-token`)"
|
|
339
|
+
: choices.billing === "api"
|
|
340
|
+
? "ANTHROPIC_API_KEY (or OPENCODE_AUTH_JSON for an OpenCode provider)"
|
|
341
|
+
: "ANTHROPIC_API_KEY (or CLAUDE_CODE_OAUTH_TOKEN)"
|
|
342
|
+
}`,
|
|
343
|
+
);
|
|
344
|
+
// The first PR of a new repository goes red without gotchas: every hunter's
|
|
345
|
+
// prompt carries them, and PRH-GOTCHAS-MISSING refuses the review while the
|
|
346
|
+
// file is absent or still the scaffold. So the init steps print only then;
|
|
347
|
+
// a repo that already wrote real gotchas is not told to write them again.
|
|
348
|
+
// Asked through gotchasUnusableReason, the one gate the review itself uses,
|
|
349
|
+
// so a scaffold with no marker line gets the steps it will need.
|
|
350
|
+
const gotchasPath = path.join(resolveRepoDir(repoRoot), "gotchas.md");
|
|
351
|
+
const gotchas = (await Bun.file(gotchasPath).exists())
|
|
352
|
+
? await Bun.file(gotchasPath).text()
|
|
353
|
+
: undefined;
|
|
354
|
+
if (gotchas === undefined || gotchasUnusableReason(gotchas) !== undefined) {
|
|
355
|
+
log(
|
|
356
|
+
`${next()} Run \`npx -y crysk init\` in a clone of the repository (it creates ${repoDirName}/gotchas.md; the config.json written above is kept as it is)`,
|
|
357
|
+
);
|
|
358
|
+
log(
|
|
359
|
+
`${next()} Replace the placeholder lines in ${repoDirName}/gotchas.md with real facts about this repository, and delete the ${GOTCHAS_PLACEHOLDER_MARKER} marker line if it is there: Crysk refuses to review the scaffold`,
|
|
360
|
+
);
|
|
361
|
+
log(
|
|
362
|
+
`${next()} Commit ${repoDirName}/ to the default branch (comment-triggered runs read the base branch)`,
|
|
363
|
+
);
|
|
364
|
+
}
|
|
365
|
+
// The check to require is `crysk` (the commit status, the gate), not the
|
|
366
|
+
// `review` job, which stays green even when it finds blocking issues.
|
|
367
|
+
log(
|
|
368
|
+
`${next()} In branch protection, require the \`crysk\` status check (not the \`review\` job; the legacy \`pr-hero\` status is still posted for one version, so an existing rule on \`pr-hero\` keeps working); a private repository on GitHub Free cannot require status checks`,
|
|
369
|
+
);
|
|
370
|
+
log(`${next()} Open a pull request to trigger the workflow`);
|
|
371
|
+
// GitHub reads a comment-triggered workflow from the DEFAULT branch, so a
|
|
372
|
+
// `/crysk review` on a pull request that only ADDS this file starts
|
|
373
|
+
// nothing, with no error anywhere. Said here because this is where a new
|
|
374
|
+
// user first reads how to force a review.
|
|
375
|
+
log(
|
|
376
|
+
`${next()} Comment /crysk review on a pull request to force a review; it works once this file is on the default branch`,
|
|
377
|
+
);
|
|
378
|
+
// Last, so a prompt it may show comes after everything above is printed.
|
|
379
|
+
await ghPreflight(deps.gh);
|
|
380
|
+
return 0;
|
|
381
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { loadEffectiveConfig, resolveOptionalRepoRoot } from "#config/config";
|
|
5
|
+
import type { CliOptions } from "#review/preflight";
|
|
6
|
+
import { renderConfig } from "#ui/config";
|
|
7
|
+
import {
|
|
8
|
+
runConfigEditor,
|
|
9
|
+
setConfigValue,
|
|
10
|
+
unsetConfigValue,
|
|
11
|
+
} from "#ui/config-edit";
|
|
12
|
+
import { log, styleEnabled, terminalWidth } from "#ui/primitives";
|
|
13
|
+
import { resolveRepoDir } from "../brand-paths";
|
|
14
|
+
import { CliError } from "../errors";
|
|
15
|
+
|
|
16
|
+
// `pr-hero config` (C5 O-12 / D10 / §3.10) — read-only, $0, and deliberately
|
|
17
|
+
// the thinnest shell in this file: resolve the two layers through the SAME
|
|
18
|
+
// loadEffectiveConfig a review takes, hand the result to a pure renderer,
|
|
19
|
+
// print. Every decision it could get wrong lives in mergeConfig, which is
|
|
20
|
+
// already the engine's; re-deriving anything here is how the command that
|
|
21
|
+
// explains the config starts disagreeing with the config.
|
|
22
|
+
//
|
|
23
|
+
// It never writes either file. Editing config from menus is distribution
|
|
24
|
+
// pillar 2 (§3.10, "Not in scope"), and a command an operator runs to
|
|
25
|
+
// UNDERSTAND their setup must be safe to run without reading its flags first.
|
|
26
|
+
//
|
|
27
|
+
// stdout, like `ledger` and `usage`: the listing IS this command's product,
|
|
28
|
+
// so it stays pipeable. Everything human-facing elsewhere in this CLI goes to
|
|
29
|
+
// stderr via log(), which is what reserves the channel — and the style flag is
|
|
30
|
+
// therefore sniffed off stdout, the stream actually being written.
|
|
31
|
+
export async function configCommand(options: CliOptions): Promise<number> {
|
|
32
|
+
const repoRoot = await resolveOptionalRepoRoot(options);
|
|
33
|
+
|
|
34
|
+
if (options.configSubcommand === "edit") {
|
|
35
|
+
return await runConfigEditor({
|
|
36
|
+
home: os.homedir(),
|
|
37
|
+
repoRoot,
|
|
38
|
+
styles: styleEnabled(process.stderr),
|
|
39
|
+
width: terminalWidth(),
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (options.configSubcommand === "set") {
|
|
44
|
+
if (!options.configKey || !options.configValue) {
|
|
45
|
+
throw new CliError("config set requires a key and value");
|
|
46
|
+
}
|
|
47
|
+
const layer = options.configLayer ?? "person";
|
|
48
|
+
const res = await setConfigValue({
|
|
49
|
+
layer,
|
|
50
|
+
key: options.configKey,
|
|
51
|
+
value: options.configValue,
|
|
52
|
+
home: os.homedir(),
|
|
53
|
+
repoRoot,
|
|
54
|
+
});
|
|
55
|
+
if (res.annotation) {
|
|
56
|
+
log(res.annotation);
|
|
57
|
+
} else {
|
|
58
|
+
log(`✓ Updated ${layer} configuration (${options.configKey}).`);
|
|
59
|
+
}
|
|
60
|
+
return 0;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (options.configSubcommand === "unset") {
|
|
64
|
+
if (!options.configKey) {
|
|
65
|
+
throw new CliError("config unset requires a key");
|
|
66
|
+
}
|
|
67
|
+
const layer = options.configLayer ?? "person";
|
|
68
|
+
await unsetConfigValue({
|
|
69
|
+
layer,
|
|
70
|
+
key: options.configKey,
|
|
71
|
+
home: os.homedir(),
|
|
72
|
+
repoRoot,
|
|
73
|
+
});
|
|
74
|
+
log(`✓ Removed ${options.configKey} from ${layer} configuration.`);
|
|
75
|
+
return 0;
|
|
76
|
+
}
|
|
77
|
+
const loaded = await loadEffectiveConfig({
|
|
78
|
+
root: repoRoot,
|
|
79
|
+
home: os.homedir(),
|
|
80
|
+
configFlag: options.config,
|
|
81
|
+
});
|
|
82
|
+
const lines = renderConfig({
|
|
83
|
+
effective: loaded.effective,
|
|
84
|
+
sources: loaded.sources,
|
|
85
|
+
repoConfigPath: repoRoot
|
|
86
|
+
? loaded.repoConfigPath
|
|
87
|
+
: path.join(resolveRepoDir(process.cwd()), "config.json"),
|
|
88
|
+
// Not carried on EffectiveConfig: the review path has no use for it (an
|
|
89
|
+
// absent repo file is simply an absent layer), and widening a type six
|
|
90
|
+
// callers share to serve one renderer is how shared shapes rot.
|
|
91
|
+
repoPresent: repoRoot ? existsSync(loaded.repoConfigPath) : false,
|
|
92
|
+
globalConfigPath: loaded.globalConfigPath,
|
|
93
|
+
globalPresent: loaded.globalPresent,
|
|
94
|
+
styles: styleEnabled(process.stdout),
|
|
95
|
+
width: terminalWidth(),
|
|
96
|
+
});
|
|
97
|
+
process.stdout.write(`${lines.join("\n")}\n`);
|
|
98
|
+
return 0;
|
|
99
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import os from "node:os";
|
|
2
|
+
import { loadEffectiveConfig, resolveOptionalRepoRoot } from "#config/config";
|
|
3
|
+
import { type RoutingConfig, routingNeedsOpenCodeSdk } from "#model/routing";
|
|
4
|
+
import type { CliOptions } from "#review/preflight";
|
|
5
|
+
import { styleEnabled, terminalWidth } from "#ui/primitives";
|
|
6
|
+
import {
|
|
7
|
+
type DoctorCheckItem,
|
|
8
|
+
type DoctorReport,
|
|
9
|
+
evaluateDoctorReport,
|
|
10
|
+
openCodeRoutingSdkCheck,
|
|
11
|
+
renderDoctorReport,
|
|
12
|
+
runDoctor,
|
|
13
|
+
} from "../doctor";
|
|
14
|
+
import { prheroLayout } from "../home-preflight";
|
|
15
|
+
import { collectDoctorExactBindingReports } from "../production-runtime";
|
|
16
|
+
import { readInstalledOpenCodeSdkVersion } from "../transport-registry";
|
|
17
|
+
|
|
18
|
+
// W3 remediation (opencode-production-runtime PR3 verify #4997): doctor
|
|
19
|
+
// exists to diagnose a broken setup, so it must not die on the very
|
|
20
|
+
// misconfiguration it is asked to report. loadEffectiveConfig throws a
|
|
21
|
+
// CliError on a missing --config file, and delegates to parseLocalConfig,
|
|
22
|
+
// which throws on malformed repo config.json — either used to abort
|
|
23
|
+
// doctorCommand before a single check ran. A config-load failure is now one
|
|
24
|
+
// blocking DoctorCheckItem prepended to the report; every other diagnostic
|
|
25
|
+
// still runs and still renders, and the exit code stays nonzero.
|
|
26
|
+
export async function runDoctorCommand(input: {
|
|
27
|
+
repoRoot?: string | undefined;
|
|
28
|
+
workspaceRoot: string;
|
|
29
|
+
home: string;
|
|
30
|
+
configFlag?: string | undefined;
|
|
31
|
+
styles: boolean;
|
|
32
|
+
width: number;
|
|
33
|
+
// Injectable for tests: production always uses the real runDoctor, which
|
|
34
|
+
// shells out to git/claude/gh/codegraph. Tests stub this to prove the
|
|
35
|
+
// config-failure wiring without depending on host tool availability.
|
|
36
|
+
runDoctorFn?: typeof runDoctor;
|
|
37
|
+
// Same seam for the SDK reader: production reads the install doctor and
|
|
38
|
+
// the loader share. Tests pass a version without resolving a package.
|
|
39
|
+
readSdkVersion?: () => Promise<string | undefined>;
|
|
40
|
+
}): Promise<{ report: DoctorReport; lines: string[] }> {
|
|
41
|
+
let routingConfig: RoutingConfig | undefined;
|
|
42
|
+
let configCheck: DoctorCheckItem | undefined;
|
|
43
|
+
try {
|
|
44
|
+
const loaded = await loadEffectiveConfig({
|
|
45
|
+
root: input.repoRoot,
|
|
46
|
+
home: input.home,
|
|
47
|
+
configFlag: input.configFlag,
|
|
48
|
+
});
|
|
49
|
+
routingConfig = loaded.effective.routing;
|
|
50
|
+
} catch (error) {
|
|
51
|
+
configCheck = {
|
|
52
|
+
name: "config",
|
|
53
|
+
severity: "blocking",
|
|
54
|
+
message: `configuration failed to load: ${
|
|
55
|
+
error instanceof Error ? error.message : String(error)
|
|
56
|
+
}`,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
const runDoctorFn = input.runDoctorFn ?? runDoctor;
|
|
60
|
+
const doctorReport = await runDoctorFn({
|
|
61
|
+
repoRoot: input.repoRoot,
|
|
62
|
+
cwd: input.repoRoot,
|
|
63
|
+
probeExactBindings: () =>
|
|
64
|
+
collectDoctorExactBindingReports({
|
|
65
|
+
workspaceRoot: input.workspaceRoot,
|
|
66
|
+
routingConfig,
|
|
67
|
+
}),
|
|
68
|
+
});
|
|
69
|
+
// Same home the command was given. The no-arg reader uses os.homedir().
|
|
70
|
+
const readSdkVersion =
|
|
71
|
+
input.readSdkVersion ??
|
|
72
|
+
(() =>
|
|
73
|
+
readInstalledOpenCodeSdkVersion({
|
|
74
|
+
nodeModulesDir: prheroLayout(input.home).nodeModulesDir,
|
|
75
|
+
}));
|
|
76
|
+
const sdkCheck = routingNeedsOpenCodeSdk(routingConfig)
|
|
77
|
+
? openCodeRoutingSdkCheck({
|
|
78
|
+
routing: routingConfig,
|
|
79
|
+
sdkVersion: await readSdkVersion(),
|
|
80
|
+
})
|
|
81
|
+
: undefined;
|
|
82
|
+
const prefix: DoctorCheckItem[] = [];
|
|
83
|
+
if (configCheck !== undefined) prefix.push(configCheck);
|
|
84
|
+
if (sdkCheck !== undefined) prefix.push(sdkCheck);
|
|
85
|
+
const report =
|
|
86
|
+
prefix.length === 0
|
|
87
|
+
? doctorReport
|
|
88
|
+
: evaluateDoctorReport([...prefix, ...doctorReport.checks]);
|
|
89
|
+
const lines = renderDoctorReport(report, {
|
|
90
|
+
styles: input.styles,
|
|
91
|
+
width: input.width,
|
|
92
|
+
});
|
|
93
|
+
return { report, lines };
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export async function doctorCommand(options: CliOptions): Promise<number> {
|
|
97
|
+
const repoRoot = await resolveOptionalRepoRoot(options);
|
|
98
|
+
const { report, lines } = await runDoctorCommand({
|
|
99
|
+
repoRoot: repoRoot ?? undefined,
|
|
100
|
+
workspaceRoot: repoRoot ?? process.cwd(),
|
|
101
|
+
home: os.homedir(),
|
|
102
|
+
configFlag: options.config,
|
|
103
|
+
styles: styleEnabled(process.stdout),
|
|
104
|
+
width: terminalWidth(),
|
|
105
|
+
});
|
|
106
|
+
process.stdout.write(`${lines.join("\n")}\n`);
|
|
107
|
+
return report.exitCode;
|
|
108
|
+
}
|