crysk 0.0.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +176 -0
- package/README.md +609 -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/adjudicator-dtg2axnh.md +86 -0
- package/dist/admission-config.example-a9vqmmad.json +9 -0
- package/dist/ci-admission-camfbx2b.md +122 -0
- package/dist/cli.js +42292 -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 +122 -0
- package/skills/crysk-ci-setup/references/opencode-ci.md +141 -0
- package/skills/crysk-loop/SKILL.md +496 -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 +923 -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 +901 -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 +847 -0
- package/src/pr/ci-admission-gate.ts +665 -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 +787 -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,397 @@
|
|
|
1
|
+
// The questions `setup --ci` asks a person at a terminal, and how flags stand in
|
|
2
|
+
// for them when an agent runs it. The answers are plain data (CiSetupChoices);
|
|
3
|
+
// src/ci/review-levels.ts turns them into config keys and workflow inputs.
|
|
4
|
+
|
|
5
|
+
import { CI_DEFAULT_METERED_BUDGET_USD } from "#ci/gates";
|
|
6
|
+
import {
|
|
7
|
+
DEFAULT_CI_ADVISORY_WEIGHT,
|
|
8
|
+
DEFAULT_CI_BLOCKING_WEIGHT,
|
|
9
|
+
} from "#ci/review-admission";
|
|
10
|
+
import {
|
|
11
|
+
type AdvancedChoices,
|
|
12
|
+
type Billing,
|
|
13
|
+
type CiSetupChoices,
|
|
14
|
+
type CurrentSettings,
|
|
15
|
+
DEFAULT_MAX_CHANGED_LINES,
|
|
16
|
+
DEFAULT_REVIEW_LEVEL,
|
|
17
|
+
defaultChoices,
|
|
18
|
+
NO_CURRENT_SETTINGS,
|
|
19
|
+
presetMatching,
|
|
20
|
+
REVIEW_LEVEL_ORDER,
|
|
21
|
+
REVIEW_LEVELS,
|
|
22
|
+
type ReviewLevel,
|
|
23
|
+
} from "#ci/review-levels";
|
|
24
|
+
import { ignorePatternsError } from "#ci/setup";
|
|
25
|
+
import type { CliOptions } from "#review/preflight";
|
|
26
|
+
|
|
27
|
+
export interface PromptOption<T extends string> {
|
|
28
|
+
value: T;
|
|
29
|
+
label: string;
|
|
30
|
+
description: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Injectable so every question runs offline.
|
|
34
|
+
export interface SetupPrompter {
|
|
35
|
+
choose<T extends string>(
|
|
36
|
+
question: string,
|
|
37
|
+
options: readonly PromptOption<T>[],
|
|
38
|
+
defaultValue: T,
|
|
39
|
+
): Promise<T>;
|
|
40
|
+
confirm(question: string, defaultYes: boolean): Promise<boolean>;
|
|
41
|
+
text(question: string, defaultValue: string): Promise<string>;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Choices passed as flags, for an agent that already asked the person.
|
|
45
|
+
// Any one of them means someone chose, so nothing is reported as a default.
|
|
46
|
+
export function choicesFromFlags(
|
|
47
|
+
options: Pick<
|
|
48
|
+
CliOptions,
|
|
49
|
+
| "reviewLevel"
|
|
50
|
+
| "ciMode"
|
|
51
|
+
| "billing"
|
|
52
|
+
| "budgetUsd"
|
|
53
|
+
| "maxChangedLines"
|
|
54
|
+
| "maxChangedFiles"
|
|
55
|
+
>,
|
|
56
|
+
): CiSetupChoices | undefined {
|
|
57
|
+
const given =
|
|
58
|
+
options.reviewLevel !== undefined ||
|
|
59
|
+
options.ciMode !== undefined ||
|
|
60
|
+
options.billing !== undefined ||
|
|
61
|
+
options.budgetUsd !== undefined ||
|
|
62
|
+
options.maxChangedLines !== undefined ||
|
|
63
|
+
options.maxChangedFiles !== undefined;
|
|
64
|
+
if (!given) return undefined;
|
|
65
|
+
const billing: Billing | undefined =
|
|
66
|
+
options.billing ?? (options.budgetUsd !== undefined ? "api" : undefined);
|
|
67
|
+
return {
|
|
68
|
+
level: options.reviewLevel ?? DEFAULT_REVIEW_LEVEL,
|
|
69
|
+
mode: options.ciMode ?? "gate",
|
|
70
|
+
...(billing === undefined ? {} : { billing }),
|
|
71
|
+
...(options.budgetUsd === undefined
|
|
72
|
+
? {}
|
|
73
|
+
: { budgetUsd: options.budgetUsd }),
|
|
74
|
+
maxChangedLines: options.maxChangedLines ?? DEFAULT_MAX_CHANGED_LINES,
|
|
75
|
+
advanced:
|
|
76
|
+
options.maxChangedFiles === undefined
|
|
77
|
+
? {}
|
|
78
|
+
: { max_changed_files: options.maxChangedFiles },
|
|
79
|
+
defaulted: false,
|
|
80
|
+
// Only what a flag named overrides the file; the rest fills gaps.
|
|
81
|
+
chosen: {
|
|
82
|
+
level: options.reviewLevel !== undefined,
|
|
83
|
+
maxChangedLines: options.maxChangedLines !== undefined,
|
|
84
|
+
mode: options.ciMode !== undefined,
|
|
85
|
+
billing: billing !== undefined,
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Re-asks until `parse` accepts the answer; an empty answer takes the default.
|
|
91
|
+
async function askValue<T>(
|
|
92
|
+
prompter: SetupPrompter,
|
|
93
|
+
question: string,
|
|
94
|
+
defaultValue: string,
|
|
95
|
+
parse: (raw: string) => T | undefined,
|
|
96
|
+
say: (line?: string) => void,
|
|
97
|
+
hint: string,
|
|
98
|
+
): Promise<T> {
|
|
99
|
+
for (;;) {
|
|
100
|
+
const raw = (await prompter.text(question, defaultValue)).trim();
|
|
101
|
+
const value = parse(raw === "" ? defaultValue : raw);
|
|
102
|
+
if (value !== undefined) return value;
|
|
103
|
+
say(` ${hint}`);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function integerAtLeast(min: number): (raw: string) => number | undefined {
|
|
108
|
+
return (raw) => {
|
|
109
|
+
if (!/^\d+$/.test(raw)) return undefined;
|
|
110
|
+
const n = Number(raw);
|
|
111
|
+
return n >= min ? n : undefined;
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// "" means "leave it to the default resolution".
|
|
116
|
+
function optionalLimit(raw: string): number | null | undefined {
|
|
117
|
+
if (raw === "") return null;
|
|
118
|
+
return integerAtLeast(0)(raw);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function commaList(raw: string): string[] {
|
|
122
|
+
return raw
|
|
123
|
+
.split(",")
|
|
124
|
+
.map((s) => s.trim())
|
|
125
|
+
.filter((s) => s.length > 0);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Every default comes from `current`, so a person re-running setup who presses
|
|
129
|
+
// Enter through it changes nothing.
|
|
130
|
+
export async function askChoices(
|
|
131
|
+
prompter: SetupPrompter,
|
|
132
|
+
say: (line?: string) => void,
|
|
133
|
+
current: CurrentSettings = NO_CURRENT_SETTINGS,
|
|
134
|
+
): Promise<CiSetupChoices> {
|
|
135
|
+
const choices = defaultChoices();
|
|
136
|
+
choices.defaulted = false;
|
|
137
|
+
// A person at a terminal answers every main question.
|
|
138
|
+
choices.chosen = {
|
|
139
|
+
level: true,
|
|
140
|
+
maxChangedLines: true,
|
|
141
|
+
mode: true,
|
|
142
|
+
billing: true,
|
|
143
|
+
};
|
|
144
|
+
const cfg = current.config;
|
|
145
|
+
|
|
146
|
+
say();
|
|
147
|
+
say("How should Crysk re-review a pull request after new pushes?");
|
|
148
|
+
const matching = presetMatching(cfg);
|
|
149
|
+
const levelOptions: PromptOption<ReviewLevel | "keep">[] =
|
|
150
|
+
REVIEW_LEVEL_ORDER.map((value) => ({
|
|
151
|
+
value,
|
|
152
|
+
label: REVIEW_LEVELS[value].label,
|
|
153
|
+
description: REVIEW_LEVELS[value].description,
|
|
154
|
+
}));
|
|
155
|
+
if (matching === "custom") {
|
|
156
|
+
levelOptions.push({
|
|
157
|
+
value: "keep",
|
|
158
|
+
label: "Keep current settings",
|
|
159
|
+
description:
|
|
160
|
+
"The re-review keys in .crysk/config.json match no preset; leave them as they are.",
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
const level = await prompter.choose<ReviewLevel | "keep">(
|
|
164
|
+
"Re-review level",
|
|
165
|
+
levelOptions,
|
|
166
|
+
matching === "custom" ? "keep" : (matching ?? DEFAULT_REVIEW_LEVEL),
|
|
167
|
+
);
|
|
168
|
+
if (level === "keep") choices.chosen.level = false;
|
|
169
|
+
else choices.level = level;
|
|
170
|
+
|
|
171
|
+
choices.mode = await prompter.choose<"gate" | "advisory">(
|
|
172
|
+
"Should blocking findings block the merge?",
|
|
173
|
+
[
|
|
174
|
+
{
|
|
175
|
+
value: "gate",
|
|
176
|
+
label: "Gate",
|
|
177
|
+
description:
|
|
178
|
+
"Blocking findings turn the crysk check red. Require it in branch protection to block merges.",
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
value: "advisory",
|
|
182
|
+
label: "Advisory",
|
|
183
|
+
description: "The crysk check stays green; findings are comments only.",
|
|
184
|
+
},
|
|
185
|
+
],
|
|
186
|
+
current.workflow.mode ?? "gate",
|
|
187
|
+
);
|
|
188
|
+
|
|
189
|
+
choices.billing = await prompter.choose<Billing>(
|
|
190
|
+
"How will CI pay for reviews?",
|
|
191
|
+
[
|
|
192
|
+
{
|
|
193
|
+
value: "subscription",
|
|
194
|
+
label: "Claude subscription",
|
|
195
|
+
description:
|
|
196
|
+
"CLAUDE_CODE_OAUTH_TOKEN. Reviews spend quota, not dollars.",
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
value: "api",
|
|
200
|
+
label: "API key",
|
|
201
|
+
description:
|
|
202
|
+
"ANTHROPIC_API_KEY or an OpenCode provider. Reviews are billed per token.",
|
|
203
|
+
},
|
|
204
|
+
],
|
|
205
|
+
current.workflow.budgetUsd === undefined ? "subscription" : "api",
|
|
206
|
+
);
|
|
207
|
+
if (choices.billing === "subscription") {
|
|
208
|
+
say(
|
|
209
|
+
" No spend ceiling, and nothing to write: a subscription review spends quota, not dollars, and CI applies no ceiling while the repo has no ANTHROPIC_API_KEY or OPENCODE_AUTH_JSON secret. Adding either brings back the $10 ceiling.",
|
|
210
|
+
);
|
|
211
|
+
} else {
|
|
212
|
+
choices.budgetUsd = await askValue(
|
|
213
|
+
prompter,
|
|
214
|
+
"Spend ceiling per review in USD (0 = none)",
|
|
215
|
+
current.workflow.budgetUsd ?? String(CI_DEFAULT_METERED_BUDGET_USD),
|
|
216
|
+
(raw) => {
|
|
217
|
+
const n = Number(raw);
|
|
218
|
+
return raw !== "" && Number.isFinite(n) && n >= 0 ? n : undefined;
|
|
219
|
+
},
|
|
220
|
+
say,
|
|
221
|
+
"Enter a number, 0 or more, for example 10 or 7.5.",
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
say();
|
|
226
|
+
say(
|
|
227
|
+
"Size threshold: a PR with more changed lines than this is skipped, not reviewed. It applies on any billing: without it a subscription reviews any size.",
|
|
228
|
+
);
|
|
229
|
+
choices.maxChangedLines = await askValue(
|
|
230
|
+
prompter,
|
|
231
|
+
"Max changed lines per review (0 = no limit)",
|
|
232
|
+
String(
|
|
233
|
+
typeof cfg.max_changed_lines === "number"
|
|
234
|
+
? cfg.max_changed_lines
|
|
235
|
+
: DEFAULT_MAX_CHANGED_LINES,
|
|
236
|
+
),
|
|
237
|
+
integerAtLeast(0),
|
|
238
|
+
say,
|
|
239
|
+
"Enter a whole number, 0 or more.",
|
|
240
|
+
);
|
|
241
|
+
|
|
242
|
+
say();
|
|
243
|
+
say(
|
|
244
|
+
"Advanced settings: score weights, observe-only mode, trusted actors, the changed-files limit, and exclusions. Each has a default that works.",
|
|
245
|
+
);
|
|
246
|
+
if (await prompter.confirm("Review the advanced settings now?", false)) {
|
|
247
|
+
choices.advanced = await askAdvanced(prompter, say, cfg);
|
|
248
|
+
}
|
|
249
|
+
return choices;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// Every answer is written, the default ones included: a person answered, and
|
|
253
|
+
// an answer equal to the default must still replace a tuned value in the file.
|
|
254
|
+
async function askAdvanced(
|
|
255
|
+
prompter: SetupPrompter,
|
|
256
|
+
say: (line?: string) => void,
|
|
257
|
+
cfg: Record<string, unknown>,
|
|
258
|
+
): Promise<AdvancedChoices> {
|
|
259
|
+
const advanced: AdvancedChoices = {};
|
|
260
|
+
const num = (key: string, fallback: number): string =>
|
|
261
|
+
String(typeof cfg[key] === "number" ? cfg[key] : fallback);
|
|
262
|
+
|
|
263
|
+
say();
|
|
264
|
+
say(
|
|
265
|
+
"Score weights: a re-review runs when blocking x weight + advisory x weight reaches the score floor (risk-aware and thresholded policies only).",
|
|
266
|
+
);
|
|
267
|
+
const blocking = await askValue(
|
|
268
|
+
prompter,
|
|
269
|
+
"Weight of a blocking finding",
|
|
270
|
+
num("ci_blocking_weight", DEFAULT_CI_BLOCKING_WEIGHT),
|
|
271
|
+
integerAtLeast(1),
|
|
272
|
+
say,
|
|
273
|
+
"Enter a whole number, 1 or more.",
|
|
274
|
+
);
|
|
275
|
+
advanced.ci_blocking_weight = blocking;
|
|
276
|
+
const advisory = await askValue(
|
|
277
|
+
prompter,
|
|
278
|
+
"Weight of an advisory finding",
|
|
279
|
+
num("ci_advisory_weight", DEFAULT_CI_ADVISORY_WEIGHT),
|
|
280
|
+
integerAtLeast(1),
|
|
281
|
+
say,
|
|
282
|
+
"Enter a whole number, 1 or more.",
|
|
283
|
+
);
|
|
284
|
+
advanced.ci_advisory_weight = advisory;
|
|
285
|
+
|
|
286
|
+
say();
|
|
287
|
+
say(
|
|
288
|
+
"Observe only: log what the re-review rules would skip, but review every push anyway. Useful for one PR cycle while you tune them.",
|
|
289
|
+
);
|
|
290
|
+
advanced.ci_admission_observe_only = await prompter.confirm(
|
|
291
|
+
"Turn on observe-only mode?",
|
|
292
|
+
cfg.ci_admission_observe_only === true,
|
|
293
|
+
);
|
|
294
|
+
|
|
295
|
+
say();
|
|
296
|
+
say(
|
|
297
|
+
"Trusted actors: extra GitHub logins (bots, other automation) whose crysk markers count, besides the workflow's own actor.",
|
|
298
|
+
);
|
|
299
|
+
const currentActors = Array.isArray(cfg.ci_trusted_actors)
|
|
300
|
+
? (cfg.ci_trusted_actors as string[]).join(", ")
|
|
301
|
+
: "";
|
|
302
|
+
const actorsRaw = (
|
|
303
|
+
await prompter.text(
|
|
304
|
+
"Trusted actors, comma-separated (empty = keep, none = clear)",
|
|
305
|
+
currentActors,
|
|
306
|
+
)
|
|
307
|
+
).trim();
|
|
308
|
+
advanced.ci_trusted_actors =
|
|
309
|
+
actorsRaw.toLowerCase() === "none"
|
|
310
|
+
? []
|
|
311
|
+
: commaList(actorsRaw === "" ? currentActors : actorsRaw);
|
|
312
|
+
|
|
313
|
+
say();
|
|
314
|
+
say(
|
|
315
|
+
"Changed-files limit: a PR touching more files is skipped. Empty keeps the default (none on a subscription, 50 on an API key).",
|
|
316
|
+
);
|
|
317
|
+
const files = await askValue(
|
|
318
|
+
prompter,
|
|
319
|
+
"Max changed files (empty = default, 0 = no limit)",
|
|
320
|
+
typeof cfg.max_changed_files === "number"
|
|
321
|
+
? String(cfg.max_changed_files)
|
|
322
|
+
: "",
|
|
323
|
+
optionalLimit,
|
|
324
|
+
say,
|
|
325
|
+
"Enter a whole number, or leave it empty.",
|
|
326
|
+
);
|
|
327
|
+
if (files !== null) advanced.max_changed_files = files;
|
|
328
|
+
|
|
329
|
+
say();
|
|
330
|
+
say(
|
|
331
|
+
"Exclusions: files the review never reads (generated code, lockfiles, fixtures). They go in .cryskignore, one pattern per line, gitignore syntax.",
|
|
332
|
+
);
|
|
333
|
+
for (;;) {
|
|
334
|
+
const patterns = commaList(
|
|
335
|
+
await prompter.text(
|
|
336
|
+
"Patterns to exclude, comma-separated (empty = none)",
|
|
337
|
+
"",
|
|
338
|
+
),
|
|
339
|
+
);
|
|
340
|
+
const problem = ignorePatternsError(patterns);
|
|
341
|
+
if (problem !== undefined) {
|
|
342
|
+
say(` ${problem}`);
|
|
343
|
+
continue;
|
|
344
|
+
}
|
|
345
|
+
if (patterns.length > 0) advanced.ignorePatterns = patterns;
|
|
346
|
+
break;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
return advanced;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
// The real prompter: numbered options on stderr, answers from stdin.
|
|
353
|
+
export function terminalPrompter(): SetupPrompter {
|
|
354
|
+
async function ask(question: string): Promise<string> {
|
|
355
|
+
const { createInterface } = await import("node:readline/promises");
|
|
356
|
+
const rl = createInterface({
|
|
357
|
+
input: process.stdin,
|
|
358
|
+
output: process.stderr,
|
|
359
|
+
});
|
|
360
|
+
try {
|
|
361
|
+
return await rl.question(question);
|
|
362
|
+
} finally {
|
|
363
|
+
rl.close();
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
return {
|
|
367
|
+
async choose(question, options, defaultValue) {
|
|
368
|
+
const defaultIndex = options.findIndex((o) => o.value === defaultValue);
|
|
369
|
+
process.stderr.write(`${question}\n`);
|
|
370
|
+
options.forEach((o, i) => {
|
|
371
|
+
process.stderr.write(` ${i + 1}. ${o.label}: ${o.description}\n`);
|
|
372
|
+
});
|
|
373
|
+
for (;;) {
|
|
374
|
+
const raw = (
|
|
375
|
+
await ask(`Choose 1-${options.length} [${defaultIndex + 1}]: `)
|
|
376
|
+
).trim();
|
|
377
|
+
if (raw === "") return defaultValue;
|
|
378
|
+
const n = Number(raw);
|
|
379
|
+
const picked = Number.isInteger(n) ? options[n - 1] : undefined;
|
|
380
|
+
if (picked !== undefined) return picked.value;
|
|
381
|
+
}
|
|
382
|
+
},
|
|
383
|
+
async confirm(question, defaultYes) {
|
|
384
|
+
const raw = (await ask(`${question} [${defaultYes ? "Y/n" : "y/N"}] `))
|
|
385
|
+
.trim()
|
|
386
|
+
.toLowerCase();
|
|
387
|
+
if (raw === "") return defaultYes;
|
|
388
|
+
return raw === "y" || raw === "yes";
|
|
389
|
+
},
|
|
390
|
+
async text(question, defaultValue) {
|
|
391
|
+
const raw = await ask(
|
|
392
|
+
`${question}${defaultValue === "" ? "" : ` [${defaultValue}]`}: `,
|
|
393
|
+
);
|
|
394
|
+
return raw;
|
|
395
|
+
},
|
|
396
|
+
};
|
|
397
|
+
}
|