Skip to content

Commit 2708fc8

Browse files
saravmajesticclaude
andcommitted
fix: resolve install ownership from the manager; refuse destructive actions when unresolved (#1305)
Three-model review (round 3) returned blocker-grade findings that all traced to the same root cause: identity was being inferred from the path string. A path cannot distinguish a top-level global install from a transitive dependency, and it cannot say which of our two published wrappers owns a platform package. Ownership is now a filesystem fact obtained from the package manager. `ownerOf(root, execPath)` asks which of `@altimateai/altimate-code` / `altimate-code` actually contains the running binary, and covers both real shapes: (a) the binary inside the wrapper — postinstall hard-links it to `<wrapper>/bin/.altimate-code` and the shims run that first; (b) the binary as one of our platform packages stored BESIDE the wrapper — pnpm's isolated store, hoisting, every Windows install (postinstall exits early there), and any install run with `--ignore-scripts`. (b) is bounded to that manager's own tree so a project-local binary cannot borrow a global wrapper's identity, and it refuses when BOTH wrappers are installed rather than guessing. `Installation.method()` returns a package-manager identity only when ownership is confirmed; otherwise `unknown`. That made `unknown` much more common, which exposed the consumer that had never been re-examined: **`uninstall` now refuses before removing anything when ownership is unresolved.** It was deleting data, config, cache and state unconditionally while skipping both the binary and the package removal — so an unverifiable install lost everything the user cared about and stayed installed, silently. It now stops and prints per-manager removal instructions. **The CLI upgrade dead end is gone.** "Install anyways?" passed `unknown` straight to `Installation.upgrade()`, which refuses it, so both answers ended in `UpgradeFailedError`. Replaced with actionable instructions. `UNSUPPORTED_UPGRADE_METHODS` is shared so the CLI and both HTTP routes reject the same set — the v2 handler had drifted to `unknown` only. `upgrade()` refuses yarn/scoop/choco at the choke point and the scoop/choco branches are deleted; they installed upstream's `opencode` package, not ours. Diagnostics are redacted before reaching any sink — the logger fans out to stderr under OPENCODE_PRINT_LOGS and to an OTLP collector when one is configured, so "it stays local" was never true. Masks now cover `Basic` blobs, quoted JSON keys and bare URL userinfo, and the post-upgrade `running:` field is redacted like every other subprocess-derived value. KNOWN OUTSTANDING — deliberately not fixed here, tracked for a follow-up: * `owningPackageOrScoped()` still falls back to the scoped name when a second manager query disagrees with the one `method()` already made. An unscoped install could then be upgraded under the scoped name, installing a duplicate. The fix is to resolve one identity and thread it through rather than re-deriving it per call site. * `resolveInstall()` picks a single candidate manager from path shape and only that one is queried, so a custom bun/pnpm directory without the expected segment resolves to npm, finds no owner, and degrades to `unknown`. Path shape should order which managers to ask, not decide the answer. * The standalone upgrade path still writes `$HOME/.altimate/bin` regardless of where the running binary lives. * Coverage is unit-level; there is no test across detection → upgrade → uninstall. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
1 parent 6ee55b6 commit 2708fc8

8 files changed

Lines changed: 412 additions & 118 deletions

File tree

‎packages/opencode/src/cli/cmd/uninstall.ts‎

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,34 @@ export const UninstallCommand = {
6262
const method = await Installation.method()
6363
prompts.log.info(`Installation method: ${method}`)
6464

65+
// altimate_change start — #1305: refuse BEFORE removing anything when we cannot tell what
66+
// installed this binary.
67+
//
68+
// `unknown` means detection could not confirm an owner. The removal targets below always
69+
// include data, config, cache and state, while the binary and the package-manager entry
70+
// are only removed for a known method — so proceeding here wiped everything the user
71+
// cares about and left the installation running, with no indication that had happened.
72+
// Data loss with nothing uninstalled is strictly worse than declining.
73+
if (method === "unknown") {
74+
prompts.log.error(`Cannot determine how altimate was installed (running from ${process.execPath}).`)
75+
prompts.log.info("Uninstalling now would delete your data and config while leaving the program installed.")
76+
prompts.log.info("Remove it with the tool you installed it with, then re-run to clean up data:")
77+
prompts.log.info(" npm/pnpm/bun/yarn: <manager> uninstall -g @altimateai/altimate-code (or altimate-code)")
78+
prompts.log.info(" Homebrew: brew uninstall altimate-code")
79+
prompts.log.info(" install script: rm the binary from ~/.altimate/bin")
80+
prompts.outro("Nothing was removed")
81+
return
82+
}
83+
// altimate_change end
84+
6585
const targets = await collectRemovalTargets(args, method)
6686

67-
await showRemovalSummary(targets, method)
87+
// altimate_change start — #1305: the package the MANAGER confirms owns this binary.
88+
// publish.ts ships both a scoped and an unscoped wrapper; removing the wrong one removes
89+
// nothing while uninstall goes on to delete config and cache.
90+
const pkg = (await Installation.packageName()) ?? "@altimateai/altimate-code"
91+
// altimate_change end
92+
await showRemovalSummary(targets, method, pkg)
6893

6994
if (!args.force && !args.dryRun) {
7095
const confirm = await prompts.confirm({
@@ -83,7 +108,7 @@ export const UninstallCommand = {
83108
return
84109
}
85110

86-
await executeUninstall(method, targets)
111+
await executeUninstall(method, targets, pkg)
87112

88113
prompts.outro("Done")
89114
},
@@ -103,7 +128,7 @@ async function collectRemovalTargets(args: UninstallArgs, method: Installation.M
103128
return { directories, shellConfig, binary }
104129
}
105130

106-
async function showRemovalSummary(targets: RemovalTargets, method: Installation.Method) {
131+
async function showRemovalSummary(targets: RemovalTargets, method: Installation.Method, pkg: string) {
107132
prompts.log.message("The following will be removed:")
108133

109134
for (const dir of targets.directories) {
@@ -135,18 +160,18 @@ async function showRemovalSummary(targets: RemovalTargets, method: Installation.
135160
// installed. scoop/choco are omitted: Installation.method() no longer returns them
136161
// (their commands still reference upstream identities), so they are unreachable here.
137162
const cmds: Record<string, string> = {
138-
npm: "npm uninstall -g @altimateai/altimate-code",
139-
pnpm: "pnpm uninstall -g @altimateai/altimate-code",
140-
bun: "bun remove -g @altimateai/altimate-code",
141-
yarn: "yarn global remove @altimateai/altimate-code",
163+
npm: `npm uninstall -g ${pkg}`,
164+
pnpm: `pnpm uninstall -g ${pkg}`,
165+
bun: `bun remove -g ${pkg}`,
166+
yarn: `yarn global remove ${pkg}`,
142167
brew: "brew uninstall altimate-code",
143168
}
144169
// altimate_change end
145170
prompts.log.info(` ✓ Package: ${cmds[method] || method}`)
146171
}
147172
}
148173

149-
async function executeUninstall(method: Installation.Method, targets: RemovalTargets) {
174+
async function executeUninstall(method: Installation.Method, targets: RemovalTargets, pkg: string) {
150175
const spinner = prompts.spinner()
151176
const errors: string[] = []
152177

@@ -186,10 +211,10 @@ async function executeUninstall(method: Installation.Method, targets: RemovalTar
186211
if (method !== "curl" && method !== "unknown") {
187212
// altimate_change start — #1305: Altimate package identities, not upstream's.
188213
const cmds: Record<string, string[]> = {
189-
npm: ["npm", "uninstall", "-g", "@altimateai/altimate-code"],
190-
pnpm: ["pnpm", "uninstall", "-g", "@altimateai/altimate-code"],
191-
bun: ["bun", "remove", "-g", "@altimateai/altimate-code"],
192-
yarn: ["yarn", "global", "remove", "@altimateai/altimate-code"],
214+
npm: ["npm", "uninstall", "-g", pkg],
215+
pnpm: ["pnpm", "uninstall", "-g", pkg],
216+
bun: ["bun", "remove", "-g", pkg],
217+
yarn: ["yarn", "global", "remove", pkg],
193218
brew: ["brew", "uninstall", "altimate-code"],
194219
}
195220
// altimate_change end

‎packages/opencode/src/cli/cmd/upgrade.ts‎

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -46,27 +46,26 @@ export const UpgradeCommand = {
4646
// altimate_change end
4747
const detectedMethod = await Installation.method()
4848
const method = (args.method as Installation.Method) ?? detectedMethod
49-
// altimate_change start — #1305: Installation.upgrade()'s switch has no `yarn` case, so
50-
// yarn reaches `default` and dies with "Unknown installation method: yarn". cli/upgrade.ts
51-
// already routes yarn to notify for the same reason; this is the explicit-command path.
52-
if (method === "unknown" || method === "yarn") {
53-
// altimate_change end
54-
// altimate_change start — branding
55-
prompts.log.error(`altimate is installed to ${process.execPath} and may be managed by a package manager`)
56-
// altimate_change end
57-
const install = await prompts.select({
58-
message: "Install anyways?",
59-
options: [
60-
{ label: "Yes", value: true },
61-
{ label: "No", value: false },
62-
],
63-
initialValue: false,
64-
})
65-
if (!install) {
66-
prompts.outro("Done")
67-
return
68-
}
49+
// altimate_change start — #1305: stop instead of offering a choice that cannot work.
50+
// `Installation.upgrade()` refuses every method in UNSUPPORTED_UPGRADE_METHODS, so the
51+
// old "Install anyways?" prompt ended in `UpgradeFailedError: Unknown installation
52+
// method` whichever way the user answered — and detection now returns `unknown` for
53+
// anything it cannot verify, which made that dead end much more common.
54+
if (Installation.UNSUPPORTED_UPGRADE_METHODS.includes(method)) {
55+
prompts.log.error(
56+
method === "unknown"
57+
? `Cannot determine how altimate was installed (running from ${process.execPath}).`
58+
: `Upgrading a ${method} installation is not supported.`,
59+
)
60+
prompts.log.info("Upgrade with the tool you installed it with:")
61+
prompts.log.info(" npm/pnpm/bun: <manager> install -g @altimateai/altimate-code@latest (or altimate-code)")
62+
prompts.log.info(" Homebrew: brew upgrade altimate-code")
63+
prompts.log.info(" install script: curl -fsSL https://www.altimate.sh/install | bash")
64+
prompts.log.info("Or force a specific manager with --method <npm|pnpm|bun|brew|curl>.")
65+
prompts.outro("Done")
66+
return
6967
}
68+
// altimate_change end
7069
prompts.log.info("Using method: " + method)
7170
const target = args.target ? args.target.replace(/^v/, "") : await Installation.latest()
7271

0 commit comments

Comments
 (0)