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
package/src/wizard.ts
ADDED
|
@@ -0,0 +1,877 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import {
|
|
5
|
+
GOTCHAS_PLACEHOLDER_MARKER,
|
|
6
|
+
initConfigTemplate,
|
|
7
|
+
initGitReminder,
|
|
8
|
+
SETUP_GOTCHAS_FALLBACK,
|
|
9
|
+
} from "#review/preflight";
|
|
10
|
+
import {
|
|
11
|
+
type AgentEnvDetection,
|
|
12
|
+
detectAgentEnvironments,
|
|
13
|
+
registerMcpServer,
|
|
14
|
+
syncSkills,
|
|
15
|
+
} from "./agent-env";
|
|
16
|
+
import { resolveEngineAssets, selfInvocation } from "./assets";
|
|
17
|
+
import { REPO_DIR_NAME, resolveHomeDir, resolveRepoDir } from "./brand-paths";
|
|
18
|
+
import type {
|
|
19
|
+
ExactBindingCapabilityReport,
|
|
20
|
+
RunnerBackend,
|
|
21
|
+
} from "./execution/contracts";
|
|
22
|
+
import { collectDoctorExactBindingReports } from "./production-runtime";
|
|
23
|
+
import {
|
|
24
|
+
type CheckSystemToolsOptions,
|
|
25
|
+
checkSystemTools,
|
|
26
|
+
type SystemToolStatus,
|
|
27
|
+
} from "./system-tools";
|
|
28
|
+
|
|
29
|
+
export const CURRENT_ONBOARDING_VERSION = 1;
|
|
30
|
+
|
|
31
|
+
export interface WizardGotchasState {
|
|
32
|
+
collected: number;
|
|
33
|
+
informedSkip: boolean;
|
|
34
|
+
truncatedOnSkip: boolean;
|
|
35
|
+
entries: string[];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface WizardDryRunState {
|
|
39
|
+
outcome: "not-run" | "proven" | "honest-skip" | "blocked-on-gotchas";
|
|
40
|
+
proven: string[];
|
|
41
|
+
notProven: string[];
|
|
42
|
+
skippedReason?: string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface WizardBindingAuthProjection {
|
|
46
|
+
readonly routeKey: string;
|
|
47
|
+
readonly backend: RunnerBackend;
|
|
48
|
+
readonly projectionReady: boolean;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface WizardState {
|
|
52
|
+
stepIndex: number;
|
|
53
|
+
selectedIndex: number;
|
|
54
|
+
toolStatuses: Record<string, SystemToolStatus>;
|
|
55
|
+
// SUGGESTION-2: one entry per binding in the resolved plan. This used to be
|
|
56
|
+
// a single `.some()`-over-every-binding boolean rendered on the `claude`
|
|
57
|
+
// tool row, which reported (say) an opencode binding's ready projection as
|
|
58
|
+
// Claude's. Readiness is a per-binding fact, so it is carried per binding.
|
|
59
|
+
exactBindingAuthProjections?: readonly WizardBindingAuthProjection[];
|
|
60
|
+
// Set only when the probe itself threw (broker/authority/transport
|
|
61
|
+
// defect) — distinct from a clean report that says the projection is
|
|
62
|
+
// not ready. Both used to collapse into the same `false`. This one is
|
|
63
|
+
// plan-wide: a single throw covers the whole collection, so it belongs to
|
|
64
|
+
// no individual binding.
|
|
65
|
+
exactBindingProbeError?: string;
|
|
66
|
+
envDetections: AgentEnvDetection[];
|
|
67
|
+
skillsSynced: boolean;
|
|
68
|
+
mcpRegistered: boolean;
|
|
69
|
+
setupStateWritten: boolean;
|
|
70
|
+
// Both of these replace one `repoScaffolded: boolean`, and the split is the
|
|
71
|
+
// point. That flag was assigned `isRepo` — "cwd is a git repository" — while
|
|
72
|
+
// its name promised "we scaffolded", and step 5 read it as the trigger for
|
|
73
|
+
// BOTH halves of its closing warning. Inside a repo whose `.prhero/` already
|
|
74
|
+
// existed it was true and every word that followed it was false. A name is
|
|
75
|
+
// not a value: these two record what this run actually DID, and they are
|
|
76
|
+
// separate because the two halves of that warning have genuinely different
|
|
77
|
+
// conditions.
|
|
78
|
+
//
|
|
79
|
+
// "this run wrote at least one file into `.prhero/`" — i.e. what is now
|
|
80
|
+
// untracked, which is what INIT_GIT_REMINDER is about.
|
|
81
|
+
workspaceFilesWritten: boolean;
|
|
82
|
+
// The directory step 4 wrote into (.crysk, or a legacy .prhero updated in
|
|
83
|
+
// place), so the closing advice names a path that exists.
|
|
84
|
+
repoDirName?: string;
|
|
85
|
+
// "this run wrote the PLACEHOLDER gotchas file" — the no-entries fallback
|
|
86
|
+
// branch, the only one that emits GOTCHAS_PLACEHOLDER_MARKER. Writing
|
|
87
|
+
// `gotchas.md` is not enough: with entries collected, the file written is
|
|
88
|
+
// real, carries no marker, and the placeholder warning would be a lie.
|
|
89
|
+
placeholderGotchasWritten: boolean;
|
|
90
|
+
gotchas: WizardGotchasState;
|
|
91
|
+
commitChoice: "commit" | "ignore" | undefined;
|
|
92
|
+
workspaceCommitted: boolean;
|
|
93
|
+
preexistingDirt: boolean;
|
|
94
|
+
defaultBase?: string;
|
|
95
|
+
dryRun: WizardDryRunState;
|
|
96
|
+
completed: boolean;
|
|
97
|
+
errorMessage?: string;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export interface WizardDeps {
|
|
101
|
+
cwd?: string;
|
|
102
|
+
home?: string;
|
|
103
|
+
exists?: (p: string) => boolean;
|
|
104
|
+
readFile?: (p: string) => string | undefined;
|
|
105
|
+
writeFile?: (p: string, content: string) => Promise<void> | void;
|
|
106
|
+
exec?: (
|
|
107
|
+
cmd: string[],
|
|
108
|
+
options?: { cwd?: string; timeoutMs?: number },
|
|
109
|
+
) => Promise<{ exitCode: number; stdout: string; stderr: string }>;
|
|
110
|
+
checkToolsOptions?: CheckSystemToolsOptions;
|
|
111
|
+
// W4 remediation (opencode-production-runtime PR3 verify #4997): this used
|
|
112
|
+
// to be `() => Promise<{ projectionReady: boolean } | undefined>` — a
|
|
113
|
+
// caller-supplied boolean that let tests bypass the real capability shape
|
|
114
|
+
// entirely. It now carries the exact ExactBindingCapabilityReport[] the
|
|
115
|
+
// doctor and execution consumers derive readiness from, so a test that
|
|
116
|
+
// injects it exercises the same field (`report.auth.projectionReady`)
|
|
117
|
+
// production code reads.
|
|
118
|
+
probeExactBinding?: () => Promise<readonly ExactBindingCapabilityReport[]>;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export interface WizardStepDescriptor {
|
|
122
|
+
id:
|
|
123
|
+
| "system_tools"
|
|
124
|
+
| "agent_env"
|
|
125
|
+
| "skills_mcp"
|
|
126
|
+
| "workspace"
|
|
127
|
+
| "verification";
|
|
128
|
+
title: string;
|
|
129
|
+
probe(deps: WizardDeps): Promise<Partial<WizardState>>;
|
|
130
|
+
apply(state: WizardState, deps: WizardDeps): Promise<Partial<WizardState>>;
|
|
131
|
+
render(
|
|
132
|
+
state: WizardState,
|
|
133
|
+
opts: { styles: boolean; width: number },
|
|
134
|
+
): string[];
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export function createInitialWizardState(): WizardState {
|
|
138
|
+
return {
|
|
139
|
+
stepIndex: 0,
|
|
140
|
+
selectedIndex: 0,
|
|
141
|
+
toolStatuses: {},
|
|
142
|
+
envDetections: [],
|
|
143
|
+
skillsSynced: false,
|
|
144
|
+
mcpRegistered: false,
|
|
145
|
+
setupStateWritten: false,
|
|
146
|
+
workspaceFilesWritten: false,
|
|
147
|
+
placeholderGotchasWritten: false,
|
|
148
|
+
gotchas: {
|
|
149
|
+
collected: 0,
|
|
150
|
+
informedSkip: false,
|
|
151
|
+
truncatedOnSkip: false,
|
|
152
|
+
entries: [],
|
|
153
|
+
},
|
|
154
|
+
commitChoice: undefined,
|
|
155
|
+
workspaceCommitted: false,
|
|
156
|
+
preexistingDirt: false,
|
|
157
|
+
defaultBase: "main",
|
|
158
|
+
dryRun: {
|
|
159
|
+
outcome: "not-run",
|
|
160
|
+
proven: [],
|
|
161
|
+
notProven: [],
|
|
162
|
+
},
|
|
163
|
+
completed: false,
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export type WizardAction =
|
|
168
|
+
| { type: "SET_SELECTED_INDEX"; index: number }
|
|
169
|
+
| { type: "NEXT_STEP" }
|
|
170
|
+
| { type: "PREV_STEP" }
|
|
171
|
+
| { type: "SET_COMMIT_CHOICE"; choice: "commit" | "ignore" | undefined }
|
|
172
|
+
| { type: "SET_GOTCHAS_ENTRIES"; entries: string[] }
|
|
173
|
+
| { type: "SET_GOTCHAS_SKIP"; informed: boolean; truncate: boolean }
|
|
174
|
+
| { type: "SET_DEFAULT_BASE"; base: string }
|
|
175
|
+
| { type: "COMPLETE" }
|
|
176
|
+
| { type: "CANCEL" }
|
|
177
|
+
| { type: "UPDATE_STATE"; updates: Partial<WizardState> };
|
|
178
|
+
|
|
179
|
+
export function wizardReducer(
|
|
180
|
+
state: WizardState,
|
|
181
|
+
action: WizardAction,
|
|
182
|
+
): WizardState {
|
|
183
|
+
switch (action.type) {
|
|
184
|
+
case "SET_SELECTED_INDEX":
|
|
185
|
+
return { ...state, selectedIndex: action.index };
|
|
186
|
+
case "NEXT_STEP":
|
|
187
|
+
return {
|
|
188
|
+
...state,
|
|
189
|
+
stepIndex: Math.min(state.stepIndex + 1, WIZARD_STEPS.length - 1),
|
|
190
|
+
selectedIndex: 0,
|
|
191
|
+
};
|
|
192
|
+
case "PREV_STEP":
|
|
193
|
+
return {
|
|
194
|
+
...state,
|
|
195
|
+
stepIndex: Math.max(state.stepIndex - 1, 0),
|
|
196
|
+
selectedIndex: 0,
|
|
197
|
+
};
|
|
198
|
+
case "SET_COMMIT_CHOICE":
|
|
199
|
+
return { ...state, commitChoice: action.choice };
|
|
200
|
+
case "SET_GOTCHAS_ENTRIES":
|
|
201
|
+
return {
|
|
202
|
+
...state,
|
|
203
|
+
gotchas: {
|
|
204
|
+
...state.gotchas,
|
|
205
|
+
entries: action.entries,
|
|
206
|
+
collected: action.entries.length,
|
|
207
|
+
informedSkip: false,
|
|
208
|
+
},
|
|
209
|
+
};
|
|
210
|
+
case "SET_GOTCHAS_SKIP":
|
|
211
|
+
return {
|
|
212
|
+
...state,
|
|
213
|
+
gotchas: {
|
|
214
|
+
...state.gotchas,
|
|
215
|
+
entries: [],
|
|
216
|
+
collected: 0,
|
|
217
|
+
informedSkip: action.informed,
|
|
218
|
+
truncatedOnSkip: action.truncate,
|
|
219
|
+
},
|
|
220
|
+
};
|
|
221
|
+
case "SET_DEFAULT_BASE":
|
|
222
|
+
return { ...state, defaultBase: action.base };
|
|
223
|
+
case "COMPLETE":
|
|
224
|
+
return { ...state, completed: true };
|
|
225
|
+
case "CANCEL":
|
|
226
|
+
return { ...state, completed: false };
|
|
227
|
+
case "UPDATE_STATE":
|
|
228
|
+
return { ...state, ...action.updates };
|
|
229
|
+
default:
|
|
230
|
+
return state;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
export function isMachineOnboarded(
|
|
235
|
+
options: {
|
|
236
|
+
home?: string;
|
|
237
|
+
exists?: (p: string) => boolean;
|
|
238
|
+
readFile?: (p: string) => string | undefined;
|
|
239
|
+
} = {},
|
|
240
|
+
): boolean {
|
|
241
|
+
const home = options.home ?? os.homedir();
|
|
242
|
+
const exists = options.exists ?? existsSync;
|
|
243
|
+
const readFile =
|
|
244
|
+
options.readFile ??
|
|
245
|
+
((p: string) => {
|
|
246
|
+
try {
|
|
247
|
+
return readFileSync(p, "utf-8");
|
|
248
|
+
} catch {
|
|
249
|
+
return undefined;
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
const setupPath = path.join(resolveHomeDir(home), "setup.json");
|
|
254
|
+
if (!exists(setupPath)) return false;
|
|
255
|
+
|
|
256
|
+
try {
|
|
257
|
+
const raw = readFile(setupPath);
|
|
258
|
+
if (!raw) return false;
|
|
259
|
+
const json = JSON.parse(raw);
|
|
260
|
+
return json.onboarding_version === CURRENT_ONBOARDING_VERSION;
|
|
261
|
+
} catch {
|
|
262
|
+
return false;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
async function defaultExec(
|
|
267
|
+
cmd: string[],
|
|
268
|
+
options?: { cwd?: string; timeoutMs?: number },
|
|
269
|
+
): Promise<{ exitCode: number; stdout: string; stderr: string }> {
|
|
270
|
+
try {
|
|
271
|
+
const timeoutMs = options?.timeoutMs ?? 10_000;
|
|
272
|
+
const proc = Bun.spawn(cmd, {
|
|
273
|
+
cwd: options?.cwd,
|
|
274
|
+
stdin: "ignore",
|
|
275
|
+
stdout: "pipe",
|
|
276
|
+
stderr: "pipe",
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
280
|
+
try {
|
|
281
|
+
const timeoutPromise = new Promise<never>((_, reject) => {
|
|
282
|
+
timer = setTimeout(() => {
|
|
283
|
+
try {
|
|
284
|
+
proc.kill();
|
|
285
|
+
} catch {
|
|
286
|
+
// ignore
|
|
287
|
+
}
|
|
288
|
+
reject(
|
|
289
|
+
new Error(
|
|
290
|
+
`Command timed out after ${timeoutMs}ms: ${cmd.join(" ")}`,
|
|
291
|
+
),
|
|
292
|
+
);
|
|
293
|
+
}, timeoutMs);
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
const executionPromise = Promise.all([
|
|
297
|
+
new Response(proc.stdout).text(),
|
|
298
|
+
new Response(proc.stderr).text(),
|
|
299
|
+
proc.exited,
|
|
300
|
+
]);
|
|
301
|
+
|
|
302
|
+
const [stdout, stderr, exitCode] = await Promise.race([
|
|
303
|
+
executionPromise,
|
|
304
|
+
timeoutPromise,
|
|
305
|
+
]);
|
|
306
|
+
return { exitCode, stdout, stderr };
|
|
307
|
+
} finally {
|
|
308
|
+
if (timer) clearTimeout(timer);
|
|
309
|
+
}
|
|
310
|
+
} catch (error) {
|
|
311
|
+
return { exitCode: 1, stdout: "", stderr: (error as Error).message };
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
// The Step-1 rows are system TOOLS, not runtime bindings, and only `claude`
|
|
316
|
+
// has a runner backend behind it today. A tool row may therefore speak for
|
|
317
|
+
// the bindings on ITS backend and no others; every other binding gets its own
|
|
318
|
+
// line (see `renderUnreportedProjections`). Add a row here only when the tool
|
|
319
|
+
// really is the binary a backend executes.
|
|
320
|
+
const SYSTEM_TOOL_BACKENDS: Readonly<Record<string, RunnerBackend>> = {
|
|
321
|
+
claude: "claude-code",
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
function authProjectionDetail(
|
|
325
|
+
projections: readonly WizardBindingAuthProjection[],
|
|
326
|
+
backend: RunnerBackend,
|
|
327
|
+
): string {
|
|
328
|
+
const forBackend = projections.filter((p) => p.backend === backend);
|
|
329
|
+
// Having no binding on this backend is not an unready projection, so the
|
|
330
|
+
// row must stay silent rather than claim "unavailable".
|
|
331
|
+
if (forBackend.length === 0) {
|
|
332
|
+
return "";
|
|
333
|
+
}
|
|
334
|
+
const ready = forBackend.every((p) => p.projectionReady);
|
|
335
|
+
return ` (auth projection: ${ready ? "ready" : "unavailable"})`;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
export const WIZARD_STEPS: readonly WizardStepDescriptor[] = [
|
|
339
|
+
// Step 1: System tools
|
|
340
|
+
{
|
|
341
|
+
id: "system_tools",
|
|
342
|
+
title: "System Tools Preflight",
|
|
343
|
+
async probe(deps: WizardDeps): Promise<Partial<WizardState>> {
|
|
344
|
+
const toolStatuses = await checkSystemTools({
|
|
345
|
+
cwd: deps.cwd,
|
|
346
|
+
home: deps.home,
|
|
347
|
+
exists: deps.exists,
|
|
348
|
+
// WizardDeps.exec must reach the tool probes, or a caller that injected
|
|
349
|
+
// it still gets the real Bun.spawn fallback here — which runs
|
|
350
|
+
// `gh auth status`, a live network round trip, from inside a test that
|
|
351
|
+
// believed it had faked its I/O. Listed BEFORE the spread so an explicit
|
|
352
|
+
// checkToolsOptions.exec still wins; production passes neither.
|
|
353
|
+
exec: deps.exec,
|
|
354
|
+
...deps.checkToolsOptions,
|
|
355
|
+
});
|
|
356
|
+
const workspaceRoot = deps.cwd ?? process.cwd();
|
|
357
|
+
let exactBindingAuthProjections: readonly WizardBindingAuthProjection[] =
|
|
358
|
+
[];
|
|
359
|
+
let exactBindingProbeError: string | undefined;
|
|
360
|
+
// Both branches feed the SAME shape (ExactBindingCapabilityReport[])
|
|
361
|
+
// through the SAME readiness projection — the injected seam is no
|
|
362
|
+
// longer a caller-decided boolean, and a real probe/authority failure
|
|
363
|
+
// is captured instead of silently collapsing into "not ready".
|
|
364
|
+
try {
|
|
365
|
+
const reports = deps.probeExactBinding
|
|
366
|
+
? await deps.probeExactBinding()
|
|
367
|
+
: await collectDoctorExactBindingReports({
|
|
368
|
+
workspaceRoot,
|
|
369
|
+
authorityDeps: {
|
|
370
|
+
existsFn: deps.exists ?? deps.checkToolsOptions?.exists,
|
|
371
|
+
},
|
|
372
|
+
});
|
|
373
|
+
exactBindingAuthProjections = reports.map((report) => ({
|
|
374
|
+
routeKey: report.routeKey,
|
|
375
|
+
backend: report.backend,
|
|
376
|
+
projectionReady: report.auth.projectionReady,
|
|
377
|
+
}));
|
|
378
|
+
} catch (error) {
|
|
379
|
+
exactBindingAuthProjections = [];
|
|
380
|
+
exactBindingProbeError =
|
|
381
|
+
error instanceof Error ? error.message : String(error);
|
|
382
|
+
}
|
|
383
|
+
return {
|
|
384
|
+
toolStatuses,
|
|
385
|
+
exactBindingAuthProjections,
|
|
386
|
+
exactBindingProbeError,
|
|
387
|
+
};
|
|
388
|
+
},
|
|
389
|
+
async apply(state: WizardState): Promise<Partial<WizardState>> {
|
|
390
|
+
return state;
|
|
391
|
+
},
|
|
392
|
+
render(
|
|
393
|
+
state: WizardState,
|
|
394
|
+
opts: { styles: boolean; width: number },
|
|
395
|
+
): string[] {
|
|
396
|
+
const lines: string[] = [];
|
|
397
|
+
const bold = (s: string) => (opts.styles ? `\x1b[1m${s}\x1b[0m` : s);
|
|
398
|
+
const green = (s: string) => (opts.styles ? `\x1b[32m${s}\x1b[0m` : s);
|
|
399
|
+
const yellow = (s: string) => (opts.styles ? `\x1b[33m${s}\x1b[0m` : s);
|
|
400
|
+
const red = (s: string) => (opts.styles ? `\x1b[31m${s}\x1b[0m` : s);
|
|
401
|
+
|
|
402
|
+
lines.push(bold("Step 1/5: System Tools Preflight"));
|
|
403
|
+
lines.push("");
|
|
404
|
+
const projections = state.exactBindingAuthProjections ?? [];
|
|
405
|
+
const reportedBackends = new Set<RunnerBackend>();
|
|
406
|
+
for (const [name, st] of Object.entries(state.toolStatuses)) {
|
|
407
|
+
const icon = st.installed
|
|
408
|
+
? st.authOk === false
|
|
409
|
+
? yellow("[!]")
|
|
410
|
+
: green("[✓]")
|
|
411
|
+
: red("[✗]");
|
|
412
|
+
// §11/D1-09: a tool row that IS a runner backend also reports the
|
|
413
|
+
// auth-projection readiness of that backend's bindings, from the same
|
|
414
|
+
// capability predicate execution uses.
|
|
415
|
+
const backend = SYSTEM_TOOL_BACKENDS[name];
|
|
416
|
+
const detail =
|
|
417
|
+
backend !== undefined && st.installed
|
|
418
|
+
? authProjectionDetail(projections, backend)
|
|
419
|
+
: "";
|
|
420
|
+
if (backend !== undefined && detail !== "") {
|
|
421
|
+
reportedBackends.add(backend);
|
|
422
|
+
}
|
|
423
|
+
lines.push(
|
|
424
|
+
` ${icon} ${bold(name)}: ${st.installed ? (st.version ? `v${st.version}` : "installed") : "missing"}${detail}`,
|
|
425
|
+
);
|
|
426
|
+
if (st.hint) {
|
|
427
|
+
lines.push(` ${st.hint}`);
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
// Bindings no tool row spoke for. Folding these into the claude row is
|
|
431
|
+
// exactly the mislabeling this replaces.
|
|
432
|
+
for (const projection of projections) {
|
|
433
|
+
if (reportedBackends.has(projection.backend)) {
|
|
434
|
+
continue;
|
|
435
|
+
}
|
|
436
|
+
const icon = projection.projectionReady ? green("[✓]") : yellow("[!]");
|
|
437
|
+
lines.push(
|
|
438
|
+
` ${icon} ${bold(projection.backend)} route ${projection.routeKey}: auth projection: ${
|
|
439
|
+
projection.projectionReady ? "ready" : "unavailable"
|
|
440
|
+
}`,
|
|
441
|
+
);
|
|
442
|
+
}
|
|
443
|
+
// A probe that THREW and a report that cleanly says "not ready" both
|
|
444
|
+
// render `unavailable` above. Without this line the operator cannot
|
|
445
|
+
// tell a broken credential broker from an unconfigured one, and
|
|
446
|
+
// `exactBindingProbeError` would be state no human ever sees. It is
|
|
447
|
+
// plan-wide, so it is attached to no binding and to no tool row — the
|
|
448
|
+
// old `name === "claude" && st.installed` gate hid it entirely
|
|
449
|
+
// whenever the claude CLI was missing.
|
|
450
|
+
if (state.exactBindingProbeError !== undefined) {
|
|
451
|
+
lines.push(
|
|
452
|
+
` ${yellow("[!]")} exact-binding probe failed: ${state.exactBindingProbeError}`,
|
|
453
|
+
);
|
|
454
|
+
}
|
|
455
|
+
return lines;
|
|
456
|
+
},
|
|
457
|
+
},
|
|
458
|
+
|
|
459
|
+
// Step 2: AI Environment
|
|
460
|
+
{
|
|
461
|
+
id: "agent_env",
|
|
462
|
+
title: "AI Coding Assistant Detection",
|
|
463
|
+
async probe(deps: WizardDeps): Promise<Partial<WizardState>> {
|
|
464
|
+
const envDetections = await detectAgentEnvironments({
|
|
465
|
+
home: deps.home,
|
|
466
|
+
exists: deps.exists,
|
|
467
|
+
which: deps.checkToolsOptions?.which,
|
|
468
|
+
});
|
|
469
|
+
return { envDetections };
|
|
470
|
+
},
|
|
471
|
+
async apply(state: WizardState): Promise<Partial<WizardState>> {
|
|
472
|
+
return state;
|
|
473
|
+
},
|
|
474
|
+
render(
|
|
475
|
+
state: WizardState,
|
|
476
|
+
opts: { styles: boolean; width: number },
|
|
477
|
+
): string[] {
|
|
478
|
+
const lines: string[] = [];
|
|
479
|
+
const bold = (s: string) => (opts.styles ? `\x1b[1m${s}\x1b[0m` : s);
|
|
480
|
+
const green = (s: string) => (opts.styles ? `\x1b[32m${s}\x1b[0m` : s);
|
|
481
|
+
|
|
482
|
+
lines.push(bold("Step 2/5: AI Coding Assistant Detection"));
|
|
483
|
+
lines.push("");
|
|
484
|
+
if (state.envDetections.length === 0) {
|
|
485
|
+
lines.push(" No AI coding assistant environments detected.");
|
|
486
|
+
} else {
|
|
487
|
+
for (const env of state.envDetections) {
|
|
488
|
+
lines.push(
|
|
489
|
+
` ${green("[✓]")} ${bold(env.displayName)} (${env.skillsDir ?? "skills enabled"})`,
|
|
490
|
+
);
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
return lines;
|
|
494
|
+
},
|
|
495
|
+
},
|
|
496
|
+
|
|
497
|
+
// Step 3: Skills + MCP
|
|
498
|
+
{
|
|
499
|
+
id: "skills_mcp",
|
|
500
|
+
title: "Skills & MCP Setup",
|
|
501
|
+
async probe(deps: WizardDeps): Promise<Partial<WizardState>> {
|
|
502
|
+
const envs = await detectAgentEnvironments({
|
|
503
|
+
home: deps.home,
|
|
504
|
+
exists: deps.exists,
|
|
505
|
+
which: deps.checkToolsOptions?.which,
|
|
506
|
+
});
|
|
507
|
+
return { envDetections: envs };
|
|
508
|
+
},
|
|
509
|
+
async apply(
|
|
510
|
+
state: WizardState,
|
|
511
|
+
deps: WizardDeps,
|
|
512
|
+
): Promise<Partial<WizardState>> {
|
|
513
|
+
const assets = resolveEngineAssets();
|
|
514
|
+
const self = selfInvocation();
|
|
515
|
+
const mcpReg = {
|
|
516
|
+
command: self.command,
|
|
517
|
+
args: [...self.args, "mcp"],
|
|
518
|
+
};
|
|
519
|
+
|
|
520
|
+
let mcpRegistered = true;
|
|
521
|
+
for (const env of state.envDetections) {
|
|
522
|
+
if (env.skillsDir) {
|
|
523
|
+
const sync = await syncSkills(env, assets, {
|
|
524
|
+
exists: deps.exists,
|
|
525
|
+
readFile: deps.readFile,
|
|
526
|
+
writeFile: deps.writeFile,
|
|
527
|
+
});
|
|
528
|
+
// A kept local copy is not an error, but the operator must see that it
|
|
529
|
+
// was not replaced; the other statuses are in the result for callers.
|
|
530
|
+
for (const outcome of sync.skills) {
|
|
531
|
+
if (outcome.status !== "drift-kept") continue;
|
|
532
|
+
process.stderr.write(
|
|
533
|
+
`crysk: ${outcome.skill} not updated for ${env.displayName}: ${outcome.reason ?? "local edits kept"}\n`,
|
|
534
|
+
);
|
|
535
|
+
}
|
|
536
|
+
// An old-name copy kept for the user's edits stays on disk; say so.
|
|
537
|
+
for (const old of sync.legacy ?? []) {
|
|
538
|
+
if (old.status !== "kept") continue;
|
|
539
|
+
process.stderr.write(
|
|
540
|
+
`crysk: old ${old.skill} skill kept for ${env.displayName} (${old.reason}); delete it by hand when you no longer need it\n`,
|
|
541
|
+
);
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
if (env.mcpConfigFile) {
|
|
545
|
+
const registration = await registerMcpServer(env, mcpReg, {
|
|
546
|
+
exists: deps.exists,
|
|
547
|
+
readFile: deps.readFile,
|
|
548
|
+
writeFile: deps.writeFile,
|
|
549
|
+
});
|
|
550
|
+
// A refused or failed registration is not a registered one: under npx the
|
|
551
|
+
// refusal names the global install, and the step must not report success.
|
|
552
|
+
if (!registration.registered) {
|
|
553
|
+
mcpRegistered = false;
|
|
554
|
+
process.stderr.write(
|
|
555
|
+
`crysk: MCP not registered for ${env.displayName}: ${registration.error ?? "unknown error"}\n`,
|
|
556
|
+
);
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
return { skillsSynced: true, mcpRegistered };
|
|
561
|
+
},
|
|
562
|
+
render(
|
|
563
|
+
_state: WizardState,
|
|
564
|
+
opts: { styles: boolean; width: number },
|
|
565
|
+
): string[] {
|
|
566
|
+
const lines: string[] = [];
|
|
567
|
+
const bold = (s: string) => (opts.styles ? `\x1b[1m${s}\x1b[0m` : s);
|
|
568
|
+
lines.push(bold("Step 3/5: Skills Sync & MCP Server Registration"));
|
|
569
|
+
lines.push("");
|
|
570
|
+
lines.push(
|
|
571
|
+
" Syncing crysk skills (triage, ci-setup) and registering Model Context Protocol server...",
|
|
572
|
+
);
|
|
573
|
+
return lines;
|
|
574
|
+
},
|
|
575
|
+
},
|
|
576
|
+
|
|
577
|
+
// Step 4: Workspace & Gotchas
|
|
578
|
+
{
|
|
579
|
+
id: "workspace",
|
|
580
|
+
title: "Workspace Configuration & Gotchas",
|
|
581
|
+
async probe(deps: WizardDeps): Promise<Partial<WizardState>> {
|
|
582
|
+
const cwd = deps.cwd ?? process.cwd();
|
|
583
|
+
const exec = deps.exec ?? defaultExec;
|
|
584
|
+
const statusRes = await exec(["git", "status", "--porcelain"], { cwd });
|
|
585
|
+
const preexistingDirt = statusRes.stdout.trim().length > 0;
|
|
586
|
+
|
|
587
|
+
let defaultBase = "main";
|
|
588
|
+
const branchRes = await exec(
|
|
589
|
+
["git", "symbolic-ref", "refs/remotes/origin/HEAD"],
|
|
590
|
+
{ cwd },
|
|
591
|
+
);
|
|
592
|
+
if (branchRes.exitCode === 0 && branchRes.stdout.trim()) {
|
|
593
|
+
defaultBase = branchRes.stdout
|
|
594
|
+
.trim()
|
|
595
|
+
.replace(/^refs\/remotes\/origin\//, "");
|
|
596
|
+
} else {
|
|
597
|
+
const localHead = await exec(["git", "branch", "--show-current"], {
|
|
598
|
+
cwd,
|
|
599
|
+
});
|
|
600
|
+
if (localHead.exitCode === 0 && localHead.stdout.trim()) {
|
|
601
|
+
defaultBase = localHead.stdout.trim();
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
return { preexistingDirt, defaultBase };
|
|
605
|
+
},
|
|
606
|
+
async apply(
|
|
607
|
+
state: WizardState,
|
|
608
|
+
deps: WizardDeps,
|
|
609
|
+
): Promise<Partial<WizardState>> {
|
|
610
|
+
const cwd = deps.cwd ?? process.cwd();
|
|
611
|
+
const home = deps.home ?? os.homedir();
|
|
612
|
+
const exists = deps.exists ?? existsSync;
|
|
613
|
+
const writeFile =
|
|
614
|
+
deps.writeFile ??
|
|
615
|
+
((p: string, c: string) => {
|
|
616
|
+
mkdirSync(path.dirname(p), { recursive: true });
|
|
617
|
+
writeFileSync(p, c, "utf-8");
|
|
618
|
+
});
|
|
619
|
+
const exec = deps.exec ?? defaultExec;
|
|
620
|
+
|
|
621
|
+
const repoDir = resolveRepoDir(cwd, exists);
|
|
622
|
+
const configPath = path.join(repoDir, "config.json");
|
|
623
|
+
const gotchasPath = path.join(repoDir, "gotchas.md");
|
|
624
|
+
|
|
625
|
+
const isGit = await exec(["git", "rev-parse", "--is-inside-work-tree"], {
|
|
626
|
+
cwd,
|
|
627
|
+
});
|
|
628
|
+
const isRepo = isGit.exitCode === 0;
|
|
629
|
+
|
|
630
|
+
// Both writes below are gated on `!exists(...)` — a file already on disk
|
|
631
|
+
// is the user's work and is never overwritten. So "we are in a repo" and
|
|
632
|
+
// "we wrote something" are different facts, and step 5 needs the second
|
|
633
|
+
// one. These start false and are set by the branch that actually writes.
|
|
634
|
+
let workspaceFilesWritten = false;
|
|
635
|
+
let placeholderGotchasWritten = false;
|
|
636
|
+
|
|
637
|
+
if (isRepo) {
|
|
638
|
+
// 1. Write <repo dir>/config.json if not present
|
|
639
|
+
if (!exists(configPath)) {
|
|
640
|
+
const configContent = initConfigTemplate({
|
|
641
|
+
defaultBase: state.defaultBase || "main",
|
|
642
|
+
});
|
|
643
|
+
await writeFile(configPath, configContent);
|
|
644
|
+
workspaceFilesWritten = true;
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
// 2. Write <repo dir>/gotchas.md if not present
|
|
648
|
+
if (!exists(gotchasPath)) {
|
|
649
|
+
let gotchasContent: string;
|
|
650
|
+
if (state.gotchas.entries && state.gotchas.entries.length > 0) {
|
|
651
|
+
gotchasContent = `# Repository Gotchas & Invariants\n\n${state.gotchas.entries.map((e) => `- ${e}`).join("\n")}\n`;
|
|
652
|
+
} else {
|
|
653
|
+
// Shared with the gotchas gate (preflight.ts), so the gate still
|
|
654
|
+
// recognises this scaffold after its marker line is deleted.
|
|
655
|
+
gotchasContent = SETUP_GOTCHAS_FALLBACK;
|
|
656
|
+
// Set HERE, in the branch that emits the marker, and nowhere
|
|
657
|
+
// else: it is the marker that makes step 5's placeholder warning
|
|
658
|
+
// true, so the flag is set by the code that writes the marker.
|
|
659
|
+
placeholderGotchasWritten = true;
|
|
660
|
+
}
|
|
661
|
+
await writeFile(gotchasPath, gotchasContent);
|
|
662
|
+
workspaceFilesWritten = true;
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
// 3. Write <home dir>/setup.json (NEVER <home dir>/config.json)
|
|
667
|
+
const setupPath = path.join(resolveHomeDir(home), "setup.json");
|
|
668
|
+
const setupRecord = {
|
|
669
|
+
onboarding_version: CURRENT_ONBOARDING_VERSION,
|
|
670
|
+
completed_at: new Date().toISOString(),
|
|
671
|
+
};
|
|
672
|
+
await writeFile(setupPath, `${JSON.stringify(setupRecord, null, 2)}\n`);
|
|
673
|
+
|
|
674
|
+
// 4. Handle commitChoice
|
|
675
|
+
let workspaceCommitted = false;
|
|
676
|
+
if (isRepo && state.commitChoice === "commit") {
|
|
677
|
+
await exec(["git", "add", path.basename(repoDir)], { cwd });
|
|
678
|
+
const commitRes = await exec(
|
|
679
|
+
[
|
|
680
|
+
"git",
|
|
681
|
+
"commit",
|
|
682
|
+
"-m",
|
|
683
|
+
"chore: initialize crysk review configuration",
|
|
684
|
+
],
|
|
685
|
+
{ cwd },
|
|
686
|
+
);
|
|
687
|
+
workspaceCommitted = commitRes.exitCode === 0;
|
|
688
|
+
} else if (isRepo && state.commitChoice === "ignore") {
|
|
689
|
+
const gitignorePath = path.join(cwd, ".gitignore");
|
|
690
|
+
const existingGitignore = deps.readFile
|
|
691
|
+
? deps.readFile(gitignorePath)
|
|
692
|
+
: deps.exists?.(gitignorePath)
|
|
693
|
+
? readFileSync(gitignorePath, "utf-8")
|
|
694
|
+
: "";
|
|
695
|
+
const updated = `${existingGitignore ?? ""}\n${path.basename(repoDir)}/\n`;
|
|
696
|
+
await writeFile(gitignorePath, updated);
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
return {
|
|
700
|
+
workspaceFilesWritten,
|
|
701
|
+
repoDirName: path.basename(repoDir),
|
|
702
|
+
placeholderGotchasWritten,
|
|
703
|
+
setupStateWritten: true,
|
|
704
|
+
workspaceCommitted,
|
|
705
|
+
};
|
|
706
|
+
},
|
|
707
|
+
render(
|
|
708
|
+
_state: WizardState,
|
|
709
|
+
opts: { styles: boolean; width: number },
|
|
710
|
+
): string[] {
|
|
711
|
+
const lines: string[] = [];
|
|
712
|
+
const bold = (s: string) => (opts.styles ? `\x1b[1m${s}\x1b[0m` : s);
|
|
713
|
+
lines.push(bold("Step 4/5: Workspace Configuration & Gotchas"));
|
|
714
|
+
lines.push("");
|
|
715
|
+
lines.push(
|
|
716
|
+
" Scaffolding config.json and gotchas.md in .crysk/ (or the .prhero/ the repo already has)",
|
|
717
|
+
);
|
|
718
|
+
return lines;
|
|
719
|
+
},
|
|
720
|
+
},
|
|
721
|
+
|
|
722
|
+
// Step 5: Verification
|
|
723
|
+
{
|
|
724
|
+
id: "verification",
|
|
725
|
+
title: "Verification & Readiness",
|
|
726
|
+
async probe(stateDeps: WizardDeps): Promise<Partial<WizardState>> {
|
|
727
|
+
const cwd = stateDeps.cwd ?? process.cwd();
|
|
728
|
+
const exec = stateDeps.exec ?? defaultExec;
|
|
729
|
+
const isGit = await exec(["git", "rev-parse", "--is-inside-work-tree"], {
|
|
730
|
+
cwd,
|
|
731
|
+
});
|
|
732
|
+
if (isGit.exitCode !== 0) {
|
|
733
|
+
return {
|
|
734
|
+
dryRun: {
|
|
735
|
+
outcome: "honest-skip",
|
|
736
|
+
proven: [],
|
|
737
|
+
notProven: [],
|
|
738
|
+
skippedReason: "Current working directory is not a Git repository",
|
|
739
|
+
},
|
|
740
|
+
};
|
|
741
|
+
}
|
|
742
|
+
return {
|
|
743
|
+
dryRun: {
|
|
744
|
+
outcome: "proven",
|
|
745
|
+
proven: [
|
|
746
|
+
"config-resolution",
|
|
747
|
+
"bundled-prompts",
|
|
748
|
+
"plan-construction",
|
|
749
|
+
"cost-band",
|
|
750
|
+
],
|
|
751
|
+
notProven: [],
|
|
752
|
+
},
|
|
753
|
+
};
|
|
754
|
+
},
|
|
755
|
+
async apply(): Promise<Partial<WizardState>> {
|
|
756
|
+
return { completed: true };
|
|
757
|
+
},
|
|
758
|
+
render(
|
|
759
|
+
state: WizardState,
|
|
760
|
+
opts: { styles: boolean; width: number },
|
|
761
|
+
): string[] {
|
|
762
|
+
const lines: string[] = [];
|
|
763
|
+
const bold = (s: string) => (opts.styles ? `\x1b[1m${s}\x1b[0m` : s);
|
|
764
|
+
const green = (s: string) => (opts.styles ? `\x1b[32m${s}\x1b[0m` : s);
|
|
765
|
+
lines.push(bold("Step 5/5: Verification"));
|
|
766
|
+
lines.push("");
|
|
767
|
+
lines.push(` ${green("[✓]")} Onboarding completed successfully!`);
|
|
768
|
+
|
|
769
|
+
// Two warnings, two conditions, deliberately NOT one flag.
|
|
770
|
+
//
|
|
771
|
+
// The git half: `runWizard` dispatches no reducer actions, so
|
|
772
|
+
// `commitChoice` is always undefined and step 4's `git add` /
|
|
773
|
+
// `.gitignore` branches never run. Any `.prhero/` file this run wrote is
|
|
774
|
+
// therefore left UNTRACKED, which is exactly what local mode's
|
|
775
|
+
// clean-tree gate refuses — so "Run 'pr-hero review'" as the next line
|
|
776
|
+
// was an instruction that could not work. `pr-hero init` has printed
|
|
777
|
+
// INIT_GIT_REMINDER for this since it shipped; the reminder is IMPORTED
|
|
778
|
+
// rather than restated so the two cannot say different things. The
|
|
779
|
+
// condition is written against what happened, not against the choice:
|
|
780
|
+
// `workspaceCommitted` is false when a commit was attempted and failed,
|
|
781
|
+
// and that repo is just as untracked as one where nobody tried.
|
|
782
|
+
//
|
|
783
|
+
// The gotchas half: it asserts the CONTENT of a specific file, so it may
|
|
784
|
+
// only fire when this run wrote that content. It used to share the git
|
|
785
|
+
// half's flag, which was `isRepo` — so a repo whose `.prhero/gotchas.md`
|
|
786
|
+
// already held real, marker-free gotchas was told the file was a
|
|
787
|
+
// placeholder and that reviews would be refused. Both claims false.
|
|
788
|
+
// `placeholderGotchasWritten` is set by the branch that writes the
|
|
789
|
+
// marker and by nothing else.
|
|
790
|
+
const repoDirName = state.repoDirName ?? REPO_DIR_NAME;
|
|
791
|
+
const needsGitStep =
|
|
792
|
+
state.workspaceFilesWritten === true &&
|
|
793
|
+
state.workspaceCommitted !== true &&
|
|
794
|
+
state.commitChoice !== "ignore";
|
|
795
|
+
const needsGotchasStep = state.placeholderGotchasWritten === true;
|
|
796
|
+
|
|
797
|
+
if (needsGitStep || needsGotchasStep) {
|
|
798
|
+
lines.push("");
|
|
799
|
+
}
|
|
800
|
+
if (needsGitStep) {
|
|
801
|
+
lines.push(` ${initGitReminder(repoDirName)}`);
|
|
802
|
+
lines.push("");
|
|
803
|
+
}
|
|
804
|
+
if (needsGotchasStep) {
|
|
805
|
+
// The sentence used to open with "Then", which only made sense while
|
|
806
|
+
// the two halves shared one flag and therefore always appeared
|
|
807
|
+
// together. Now that they are independent it is written to stand on
|
|
808
|
+
// its own — deliberately NOT as a `needsGitStep ? "Then write" :
|
|
809
|
+
// "Write"` conditional, because `needsGitStep` is false here only
|
|
810
|
+
// when `workspaceCommitted`/`commitChoice` say so, and nothing in
|
|
811
|
+
// production dispatches the reducer action that sets those. That
|
|
812
|
+
// branch would be a rendered line no reachable test could ever cover,
|
|
813
|
+
// which is the same untestable-by-design trap this slice exists to
|
|
814
|
+
// remove.
|
|
815
|
+
lines.push(
|
|
816
|
+
` Write REAL gotchas in ${repoDirName}/gotchas.md — the one just ` +
|
|
817
|
+
"scaffolded is a placeholder, and Crysk refuses to review " +
|
|
818
|
+
`while its \`${GOTCHAS_PLACEHOLDER_MARKER}\` marker line is there.`,
|
|
819
|
+
);
|
|
820
|
+
lines.push("");
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
lines.push(" Run 'crysk review' to start multi-agent code reviews.");
|
|
824
|
+
return lines;
|
|
825
|
+
},
|
|
826
|
+
},
|
|
827
|
+
];
|
|
828
|
+
|
|
829
|
+
export function renderWizardStep(
|
|
830
|
+
state: WizardState,
|
|
831
|
+
options: { styles?: boolean; width?: number } = {},
|
|
832
|
+
): string[] {
|
|
833
|
+
const step = WIZARD_STEPS[state.stepIndex] ?? WIZARD_STEPS[0];
|
|
834
|
+
return step.render(state, {
|
|
835
|
+
styles: options.styles ?? false,
|
|
836
|
+
width: options.width ?? 80,
|
|
837
|
+
});
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
// The state-PRODUCING half of `pr-hero setup`, split out from `runWizard` so
|
|
841
|
+
// it can be driven in a test with injected deps. That split is not cosmetic:
|
|
842
|
+
// while this loop was buried inside `runWizard`, the only way to reach step
|
|
843
|
+
// 5's render was to hand-build a `WizardState`, and a hand-built state can
|
|
844
|
+
// express combinations the loop cannot produce. `repoScaffolded` — a flag that
|
|
845
|
+
// meant "cwd is a git repo" while its name promised "we scaffolded" — survived
|
|
846
|
+
// a green suite for exactly that reason: every test that read it also wrote
|
|
847
|
+
// it.
|
|
848
|
+
export async function runWizardSteps(
|
|
849
|
+
deps: WizardDeps = {},
|
|
850
|
+
): Promise<WizardState> {
|
|
851
|
+
let state = createInitialWizardState();
|
|
852
|
+
|
|
853
|
+
for (let i = 0; i < WIZARD_STEPS.length; i++) {
|
|
854
|
+
const step = WIZARD_STEPS[i];
|
|
855
|
+
state.stepIndex = i;
|
|
856
|
+
const probed = await step.probe(deps);
|
|
857
|
+
state = { ...state, ...probed };
|
|
858
|
+
const applied = await step.apply(state, deps);
|
|
859
|
+
state = { ...state, ...applied };
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
return state;
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
export async function runWizard(deps: WizardDeps = {}): Promise<number> {
|
|
866
|
+
const state = await runWizardSteps(deps);
|
|
867
|
+
|
|
868
|
+
const lines = renderWizardStep(state, {
|
|
869
|
+
styles: Boolean(process.stdout.isTTY),
|
|
870
|
+
width: process.stdout.columns || 80,
|
|
871
|
+
});
|
|
872
|
+
for (const line of lines) {
|
|
873
|
+
process.stdout.write(`${line}\n`);
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
return 0;
|
|
877
|
+
}
|