crysk 0.0.0-stage → 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 +610 -2
- 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 +82 -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,479 @@
|
|
|
1
|
+
import {
|
|
2
|
+
existsSync,
|
|
3
|
+
readFileSync,
|
|
4
|
+
rmSync,
|
|
5
|
+
unlinkSync,
|
|
6
|
+
writeFileSync,
|
|
7
|
+
} from "node:fs";
|
|
8
|
+
import os from "node:os";
|
|
9
|
+
import path from "node:path";
|
|
10
|
+
import {
|
|
11
|
+
allSkillDirNames,
|
|
12
|
+
detectAgentEnvironments,
|
|
13
|
+
removeMcpServerEntries,
|
|
14
|
+
} from "./agent-env";
|
|
15
|
+
import { BIN_NAME, LEGACY_BIN_NAME } from "./brand";
|
|
16
|
+
import {
|
|
17
|
+
HOME_DIR_NAME,
|
|
18
|
+
LEGACY_HOME_DIR_NAME,
|
|
19
|
+
resolveRepoDir,
|
|
20
|
+
} from "./brand-paths";
|
|
21
|
+
import { prheroLayout } from "./home-preflight";
|
|
22
|
+
import {
|
|
23
|
+
LEGACY_GC_LAUNCHD_LABEL,
|
|
24
|
+
LEGACY_WATCH_LAUNCHD_LABEL,
|
|
25
|
+
} from "./legacy-launchd";
|
|
26
|
+
import { GC_LAUNCHD_LABEL } from "./store/gc-preflight";
|
|
27
|
+
import { detectInstallMethod, type InstallMethod } from "./updater";
|
|
28
|
+
import { WATCH_LAUNCHD_LABEL } from "./watch/preflight";
|
|
29
|
+
|
|
30
|
+
export type UninstallStepType =
|
|
31
|
+
| "unload_launchd"
|
|
32
|
+
| "remove_file"
|
|
33
|
+
| "remove_dir"
|
|
34
|
+
| "clean_rc_file"
|
|
35
|
+
| "unregister_mcp"
|
|
36
|
+
| "remove_skills";
|
|
37
|
+
|
|
38
|
+
export interface UninstallStep {
|
|
39
|
+
type: UninstallStepType;
|
|
40
|
+
targetPath?: string;
|
|
41
|
+
label?: string;
|
|
42
|
+
desc: string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface UninstallPlan {
|
|
46
|
+
platform: string;
|
|
47
|
+
purge: boolean;
|
|
48
|
+
launchdServices: string[];
|
|
49
|
+
rcFilesCleaned: string[];
|
|
50
|
+
binariesRemoved: string[];
|
|
51
|
+
agentEnvCleanups: string[];
|
|
52
|
+
programSteps: UninstallStep[];
|
|
53
|
+
dataSteps: UninstallStep[];
|
|
54
|
+
inRepoPrheroDir?: string;
|
|
55
|
+
warnings: string[];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface ActiveRunInfo {
|
|
59
|
+
pid: number;
|
|
60
|
+
repo: string;
|
|
61
|
+
startTime: string;
|
|
62
|
+
trigger: string;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface PlanUninstallationOptions {
|
|
66
|
+
home?: string;
|
|
67
|
+
platform?: string;
|
|
68
|
+
purge?: boolean;
|
|
69
|
+
repoRoot?: string;
|
|
70
|
+
installMethod?: InstallMethod;
|
|
71
|
+
detectActiveRuns?: () => Promise<ActiveRunInfo[]>;
|
|
72
|
+
isWatchLockHeld?: () => Promise<boolean>;
|
|
73
|
+
exists?: (p: string) => boolean;
|
|
74
|
+
readFile?: (p: string) => string | undefined;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// The PATH lines the installer wrote, under either home name.
|
|
78
|
+
const RC_BIN_MARKERS = [".crysk/bin", ".prhero/bin"];
|
|
79
|
+
|
|
80
|
+
export async function planUninstallation(
|
|
81
|
+
options: PlanUninstallationOptions = {},
|
|
82
|
+
): Promise<UninstallPlan> {
|
|
83
|
+
const home = options.home ?? os.homedir();
|
|
84
|
+
const platform = options.platform ?? os.platform();
|
|
85
|
+
const purge = options.purge ?? false;
|
|
86
|
+
const exists = options.exists ?? existsSync;
|
|
87
|
+
const readFile =
|
|
88
|
+
options.readFile ??
|
|
89
|
+
((p: string) => {
|
|
90
|
+
try {
|
|
91
|
+
return readFileSync(p, "utf-8");
|
|
92
|
+
} catch {
|
|
93
|
+
return undefined;
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
const installMethod =
|
|
98
|
+
options.installMethod ??
|
|
99
|
+
detectInstallMethod({
|
|
100
|
+
home,
|
|
101
|
+
execPath: process.execPath,
|
|
102
|
+
exists,
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
// Dual pre-purge gate
|
|
106
|
+
if (purge) {
|
|
107
|
+
const activeRuns = options.detectActiveRuns
|
|
108
|
+
? await options.detectActiveRuns()
|
|
109
|
+
: [];
|
|
110
|
+
if (activeRuns.length > 0) {
|
|
111
|
+
throw new Error(
|
|
112
|
+
`Cannot uninstall with purge: ${activeRuns.length} active reviews are currently running. Stop or cancel them before uninstalling.`,
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const lockHeld = options.isWatchLockHeld
|
|
117
|
+
? await options.isWatchLockHeld()
|
|
118
|
+
: false;
|
|
119
|
+
if (lockHeld) {
|
|
120
|
+
throw new Error(
|
|
121
|
+
"Cannot uninstall with purge: watch.lock is currently held by a running review.",
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const programSteps: UninstallStep[] = [];
|
|
127
|
+
const dataSteps: UninstallStep[] = [];
|
|
128
|
+
const launchdServices: string[] = [];
|
|
129
|
+
const rcFilesCleaned: string[] = [];
|
|
130
|
+
const binariesRemoved: string[] = [];
|
|
131
|
+
const agentEnvCleanups: string[] = [];
|
|
132
|
+
const warnings: string[] = [];
|
|
133
|
+
|
|
134
|
+
// 1. Launchd services (macOS only)
|
|
135
|
+
if (platform === "darwin") {
|
|
136
|
+
const launchAgentsDir = path.join(home, "Library", "LaunchAgents");
|
|
137
|
+
// Both generations: an install set up before the rename still has the
|
|
138
|
+
// io.prhero.* agents, and one set up after has io.crysk.*.
|
|
139
|
+
const services = [
|
|
140
|
+
WATCH_LAUNCHD_LABEL,
|
|
141
|
+
GC_LAUNCHD_LABEL,
|
|
142
|
+
LEGACY_WATCH_LAUNCHD_LABEL,
|
|
143
|
+
LEGACY_GC_LAUNCHD_LABEL,
|
|
144
|
+
].map((label) => ({
|
|
145
|
+
label,
|
|
146
|
+
plist: path.join(launchAgentsDir, `${label}.plist`),
|
|
147
|
+
}));
|
|
148
|
+
|
|
149
|
+
for (const svc of services) {
|
|
150
|
+
launchdServices.push(svc.label);
|
|
151
|
+
if (exists(svc.plist)) {
|
|
152
|
+
programSteps.push({
|
|
153
|
+
type: "unload_launchd",
|
|
154
|
+
label: svc.label,
|
|
155
|
+
targetPath: svc.plist,
|
|
156
|
+
desc: `Unload and remove launchd agent ${svc.label}`,
|
|
157
|
+
});
|
|
158
|
+
programSteps.push({
|
|
159
|
+
type: "remove_file",
|
|
160
|
+
targetPath: svc.plist,
|
|
161
|
+
desc: `Delete ${svc.plist}`,
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// 2. Agent environments (MCP unregistration + skills removal)
|
|
168
|
+
const envs = await detectAgentEnvironments({ home, exists });
|
|
169
|
+
for (const env of envs) {
|
|
170
|
+
if (env.mcpConfigFile && exists(env.mcpConfigFile)) {
|
|
171
|
+
agentEnvCleanups.push(`${env.displayName} MCP`);
|
|
172
|
+
programSteps.push({
|
|
173
|
+
type: "unregister_mcp",
|
|
174
|
+
targetPath: env.mcpConfigFile,
|
|
175
|
+
desc: `Unregister crysk MCP server from ${env.displayName} (${env.mcpConfigFile})`,
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
if (env.skillsDir) {
|
|
179
|
+
for (const skillName of allSkillDirNames()) {
|
|
180
|
+
const skillPath = path.join(env.skillsDir, skillName);
|
|
181
|
+
if (exists(skillPath)) {
|
|
182
|
+
agentEnvCleanups.push(`${env.displayName} Skill: ${skillName}`);
|
|
183
|
+
programSteps.push({
|
|
184
|
+
type: "remove_skills",
|
|
185
|
+
targetPath: skillPath,
|
|
186
|
+
desc: `Remove digest-verified ${skillName} skill from ${env.displayName}`,
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// 3. rc files PATH cleanup
|
|
194
|
+
const rcCandidates = [
|
|
195
|
+
path.join(home, ".zshrc"),
|
|
196
|
+
path.join(home, ".bashrc"),
|
|
197
|
+
path.join(home, ".bash_profile"),
|
|
198
|
+
path.join(home, ".config", "fish", "config.fish"),
|
|
199
|
+
];
|
|
200
|
+
|
|
201
|
+
for (const rcPath of rcCandidates) {
|
|
202
|
+
if (exists(rcPath)) {
|
|
203
|
+
const content = readFile(rcPath);
|
|
204
|
+
if (content && RC_BIN_MARKERS.some((m) => content.includes(m))) {
|
|
205
|
+
rcFilesCleaned.push(rcPath);
|
|
206
|
+
programSteps.push({
|
|
207
|
+
type: "clean_rc_file",
|
|
208
|
+
targetPath: rcPath,
|
|
209
|
+
desc: `Remove ${RC_BIN_MARKERS.filter((m) => content.includes(m)).join(" and ")} from PATH in ${rcPath}`,
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// 4. Standalone binary removal
|
|
216
|
+
if (installMethod.kind === "standalone") {
|
|
217
|
+
// Both names: the installer leaves crysk plus a pr-hero link, so removing
|
|
218
|
+
// only the one that is running would strand the other on PATH. The link
|
|
219
|
+
// goes first: the executor's exists() follows it, and a link whose target
|
|
220
|
+
// is already gone reads as absent.
|
|
221
|
+
const running = installMethod.binaryPath;
|
|
222
|
+
const binDir = path.dirname(running);
|
|
223
|
+
const named = [LEGACY_BIN_NAME, BIN_NAME].map((n) => path.join(binDir, n));
|
|
224
|
+
const binaries = named.includes(running) ? named : [...named, running];
|
|
225
|
+
for (const bin of binaries.filter((b) => b === running || exists(b))) {
|
|
226
|
+
binariesRemoved.push(bin);
|
|
227
|
+
programSteps.push({
|
|
228
|
+
type: "remove_file",
|
|
229
|
+
targetPath: bin,
|
|
230
|
+
desc: `Remove binary ${bin}`,
|
|
231
|
+
});
|
|
232
|
+
const bakFile = `${bin}.bak`;
|
|
233
|
+
if (exists(bakFile)) {
|
|
234
|
+
programSteps.push({
|
|
235
|
+
type: "remove_file",
|
|
236
|
+
targetPath: bakFile,
|
|
237
|
+
desc: `Remove backup binary ${bakFile}`,
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
} else if (installMethod.kind === "package_manager") {
|
|
242
|
+
warnings.push(
|
|
243
|
+
`Crysk was installed via ${installMethod.manager}. Run '${installMethod.manager} uninstall -g crysk' to remove the global package ('${installMethod.manager} uninstall -g pr-hero' for one installed before the rename).`,
|
|
244
|
+
);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// 5. Data steps (Purge)
|
|
248
|
+
if (purge) {
|
|
249
|
+
const layout = prheroLayout(home, exists);
|
|
250
|
+
const dataFiles = [
|
|
251
|
+
layout.prheroDbPath,
|
|
252
|
+
`${layout.prheroDbPath}-wal`,
|
|
253
|
+
`${layout.prheroDbPath}-shm`,
|
|
254
|
+
layout.metricsDbPath,
|
|
255
|
+
layout.storeSocketPath,
|
|
256
|
+
layout.watchConfigPath,
|
|
257
|
+
layout.reviewConfigPath,
|
|
258
|
+
path.join(layout.dir, "setup.json"),
|
|
259
|
+
layout.upgradeCheckPath,
|
|
260
|
+
layout.logPath,
|
|
261
|
+
layout.lockPath,
|
|
262
|
+
layout.launchdLogPath,
|
|
263
|
+
];
|
|
264
|
+
|
|
265
|
+
for (const f of dataFiles) {
|
|
266
|
+
if (exists(f)) {
|
|
267
|
+
dataSteps.push({
|
|
268
|
+
type: "remove_file",
|
|
269
|
+
targetPath: f,
|
|
270
|
+
desc: `Delete ${f}`,
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
const dataDirs = [
|
|
276
|
+
path.join(layout.dir, "active_runs"),
|
|
277
|
+
layout.reposDir,
|
|
278
|
+
path.join(layout.dir, "bin"),
|
|
279
|
+
layout.dir,
|
|
280
|
+
// The home this run is NOT using, if it is still on disk (both exist
|
|
281
|
+
// after a half-finished migration): a purge leaves neither behind.
|
|
282
|
+
...[HOME_DIR_NAME, LEGACY_HOME_DIR_NAME]
|
|
283
|
+
.map((name) => path.join(home, name))
|
|
284
|
+
.filter((dir) => dir !== layout.dir),
|
|
285
|
+
];
|
|
286
|
+
|
|
287
|
+
for (const d of dataDirs) {
|
|
288
|
+
if (exists(d)) {
|
|
289
|
+
dataSteps.push({
|
|
290
|
+
type: "remove_dir",
|
|
291
|
+
targetPath: d,
|
|
292
|
+
desc: `Remove directory ${d}`,
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
let inRepoPrheroDir: string | undefined;
|
|
299
|
+
if (options.repoRoot) {
|
|
300
|
+
const repoPrhero = resolveRepoDir(options.repoRoot, exists);
|
|
301
|
+
if (exists(repoPrhero)) {
|
|
302
|
+
inRepoPrheroDir = repoPrhero;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
return {
|
|
307
|
+
platform,
|
|
308
|
+
purge,
|
|
309
|
+
launchdServices,
|
|
310
|
+
rcFilesCleaned,
|
|
311
|
+
binariesRemoved,
|
|
312
|
+
agentEnvCleanups,
|
|
313
|
+
programSteps,
|
|
314
|
+
dataSteps,
|
|
315
|
+
inRepoPrheroDir,
|
|
316
|
+
warnings,
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
export interface ExecuteUninstallOptions {
|
|
321
|
+
dryRun?: boolean;
|
|
322
|
+
home?: string;
|
|
323
|
+
unlink?: (p: string) => void;
|
|
324
|
+
rmdir?: (p: string, opts?: { recursive?: boolean }) => void;
|
|
325
|
+
writeFile?: (p: string, content: string) => Promise<void> | void;
|
|
326
|
+
readFile?: (p: string) => string | undefined;
|
|
327
|
+
exists?: (p: string) => boolean;
|
|
328
|
+
exec?: (
|
|
329
|
+
cmd: string[],
|
|
330
|
+
options?: { cwd?: string },
|
|
331
|
+
) => Promise<{ exitCode: number; stdout: string; stderr: string }>;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
export interface ExecuteUninstallResult {
|
|
335
|
+
ok: boolean;
|
|
336
|
+
dryRun: boolean;
|
|
337
|
+
executedSteps: string[];
|
|
338
|
+
errors: string[];
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
export async function executeUninstallPlan(
|
|
342
|
+
plan: UninstallPlan,
|
|
343
|
+
options: ExecuteUninstallOptions = {},
|
|
344
|
+
): Promise<ExecuteUninstallResult> {
|
|
345
|
+
const dryRun = options.dryRun ?? false;
|
|
346
|
+
const executedSteps: string[] = [];
|
|
347
|
+
const errors: string[] = [];
|
|
348
|
+
|
|
349
|
+
if (dryRun) {
|
|
350
|
+
return {
|
|
351
|
+
ok: true,
|
|
352
|
+
dryRun: true,
|
|
353
|
+
executedSteps: [],
|
|
354
|
+
errors: [],
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
const unlink = options.unlink ?? unlinkSync;
|
|
359
|
+
const writeFile =
|
|
360
|
+
options.writeFile ??
|
|
361
|
+
((p: string, c: string) => {
|
|
362
|
+
writeFileSync(p, c, "utf-8");
|
|
363
|
+
});
|
|
364
|
+
const readFile =
|
|
365
|
+
options.readFile ??
|
|
366
|
+
((p: string) => {
|
|
367
|
+
try {
|
|
368
|
+
return readFileSync(p, "utf-8");
|
|
369
|
+
} catch {
|
|
370
|
+
return undefined;
|
|
371
|
+
}
|
|
372
|
+
});
|
|
373
|
+
const exists = options.exists ?? existsSync;
|
|
374
|
+
const exec =
|
|
375
|
+
options.exec ??
|
|
376
|
+
(async (cmd: string[]) => {
|
|
377
|
+
const proc = Bun.spawn(cmd, { stdout: "pipe", stderr: "pipe" });
|
|
378
|
+
const exitCode = await proc.exited;
|
|
379
|
+
const stdout = await new Response(proc.stdout).text();
|
|
380
|
+
const stderr = await new Response(proc.stderr).text();
|
|
381
|
+
return { exitCode, stdout, stderr };
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
const allSteps = [...plan.programSteps, ...plan.dataSteps];
|
|
385
|
+
|
|
386
|
+
for (const step of allSteps) {
|
|
387
|
+
try {
|
|
388
|
+
switch (step.type) {
|
|
389
|
+
case "unload_launchd":
|
|
390
|
+
if (step.targetPath && exists(step.targetPath)) {
|
|
391
|
+
await exec(["launchctl", "unload", "-w", step.targetPath]);
|
|
392
|
+
executedSteps.push(step.desc);
|
|
393
|
+
}
|
|
394
|
+
break;
|
|
395
|
+
|
|
396
|
+
case "remove_file":
|
|
397
|
+
if (step.targetPath && exists(step.targetPath)) {
|
|
398
|
+
unlink(step.targetPath);
|
|
399
|
+
executedSteps.push(step.desc);
|
|
400
|
+
}
|
|
401
|
+
break;
|
|
402
|
+
|
|
403
|
+
case "remove_dir":
|
|
404
|
+
if (step.targetPath && exists(step.targetPath)) {
|
|
405
|
+
try {
|
|
406
|
+
if (options.rmdir) {
|
|
407
|
+
options.rmdir(step.targetPath, { recursive: true });
|
|
408
|
+
} else {
|
|
409
|
+
rmSync(step.targetPath, { recursive: true, force: true });
|
|
410
|
+
}
|
|
411
|
+
executedSteps.push(step.desc);
|
|
412
|
+
} catch {
|
|
413
|
+
// Ignore if already deleted
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
break;
|
|
417
|
+
|
|
418
|
+
case "clean_rc_file":
|
|
419
|
+
if (step.targetPath && exists(step.targetPath)) {
|
|
420
|
+
const raw = readFile(step.targetPath);
|
|
421
|
+
if (raw) {
|
|
422
|
+
const lines = raw
|
|
423
|
+
.split("\n")
|
|
424
|
+
.filter((l) => !RC_BIN_MARKERS.some((m) => l.includes(m)));
|
|
425
|
+
await writeFile(step.targetPath, lines.join("\n"));
|
|
426
|
+
executedSteps.push(step.desc);
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
break;
|
|
430
|
+
|
|
431
|
+
case "unregister_mcp":
|
|
432
|
+
if (step.targetPath && exists(step.targetPath)) {
|
|
433
|
+
const raw = readFile(step.targetPath);
|
|
434
|
+
if (raw) {
|
|
435
|
+
try {
|
|
436
|
+
const config = JSON.parse(raw);
|
|
437
|
+
if (removeMcpServerEntries(config)) {
|
|
438
|
+
await writeFile(
|
|
439
|
+
step.targetPath,
|
|
440
|
+
`${JSON.stringify(config, null, 2)}\n`,
|
|
441
|
+
);
|
|
442
|
+
}
|
|
443
|
+
} catch (e) {
|
|
444
|
+
if (!(e instanceof SyntaxError)) {
|
|
445
|
+
throw e;
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
executedSteps.push(step.desc);
|
|
451
|
+
break;
|
|
452
|
+
|
|
453
|
+
case "remove_skills":
|
|
454
|
+
if (step.targetPath && exists(step.targetPath)) {
|
|
455
|
+
// An uninstall the user asked for removes the whole dir, both names, as
|
|
456
|
+
// it always has; only the upgrade sync's legacy cleanup is digest-gated.
|
|
457
|
+
if (options.rmdir) {
|
|
458
|
+
options.rmdir(step.targetPath, { recursive: true });
|
|
459
|
+
} else {
|
|
460
|
+
rmSync(step.targetPath, { recursive: true, force: true });
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
executedSteps.push(step.desc);
|
|
464
|
+
break;
|
|
465
|
+
}
|
|
466
|
+
} catch (err) {
|
|
467
|
+
errors.push(
|
|
468
|
+
`Error executing step (${step.desc}): ${(err as Error).message}`,
|
|
469
|
+
);
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
return {
|
|
474
|
+
ok: errors.length === 0,
|
|
475
|
+
dryRun: false,
|
|
476
|
+
executedSteps,
|
|
477
|
+
errors,
|
|
478
|
+
};
|
|
479
|
+
}
|