magus-cli 7.7.0 → 7.9.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.
Files changed (140) hide show
  1. package/README.md +1 -1
  2. package/package.json +4 -4
  3. package/src/__tests__/blackbox-parity.test.ts +45 -26
  4. package/src/__tests__/blackbox-plugin-state.test.ts +25 -6
  5. package/src/__tests__/blind/plugin-deps/doctor.test.ts +622 -0
  6. package/src/__tests__/blind/plugin-deps/helpers.ts +340 -0
  7. package/src/__tests__/blind/plugin-deps/hook.test.ts +328 -0
  8. package/src/__tests__/blind/plugin-deps/probe.test.ts +694 -0
  9. package/src/__tests__/blind/plugin-deps/read-only.test.ts +96 -0
  10. package/src/__tests__/blind/plugin-deps/schema.test.ts +390 -0
  11. package/src/__tests__/blind-780-cli-tools.test.ts +796 -0
  12. package/src/__tests__/blind-780-deprecated.test.ts +631 -0
  13. package/src/__tests__/blind-780-failure-reasons.test.ts +1004 -0
  14. package/src/__tests__/blind-780-plugin-resolution.test.ts +431 -0
  15. package/src/__tests__/blind-780-review2.test.ts +1178 -0
  16. package/src/__tests__/cli-apply-seams.test.ts +2 -67
  17. package/src/__tests__/cli-tool-commands.test.ts +131 -6
  18. package/src/__tests__/cli-tools-adapter.test.ts +52 -2
  19. package/src/__tests__/cli-tools-plugin-managed.test.tsx +83 -0
  20. package/src/__tests__/cli-update-view.test.ts +3 -3
  21. package/src/__tests__/deprecated-remove.test.ts +827 -0
  22. package/src/__tests__/deps-adapter.test.ts +191 -0
  23. package/src/__tests__/deps-check-hook.test.ts +220 -0
  24. package/src/__tests__/deps-plan.test.ts +896 -0
  25. package/src/__tests__/deps-report.test.ts +197 -0
  26. package/src/__tests__/doctor-bins.test.ts +134 -36
  27. package/src/__tests__/doctor-json.test.ts +261 -0
  28. package/src/__tests__/doctor.test.ts +159 -1
  29. package/src/__tests__/failure-popup-review2.test.tsx +896 -0
  30. package/src/__tests__/failure-popup.test.tsx +419 -0
  31. package/src/__tests__/final-fixes-780.test.tsx +740 -0
  32. package/src/__tests__/fixtures/bins.ts +55 -0
  33. package/src/__tests__/format-update-outcome.test.ts +6 -32
  34. package/src/__tests__/gitignore-profile.test.ts +1 -9
  35. package/src/__tests__/install-plan.test.ts +15 -1
  36. package/src/__tests__/marketplace-refresh.test.ts +9 -3
  37. package/src/__tests__/models-screen-state.test.ts +18 -40
  38. package/src/__tests__/no-shell-spawn.test.ts +77 -0
  39. package/src/__tests__/npm-package-name.test.ts +6 -9
  40. package/src/__tests__/plugin-requires.test.ts +138 -153
  41. package/src/__tests__/plugin-resolution.test.ts +52 -13
  42. package/src/__tests__/plugin-row-text.test.ts +30 -37
  43. package/src/__tests__/profile-dependencies.test.ts +7 -0
  44. package/src/__tests__/profile-startup-old-format.test.ts +0 -3
  45. package/src/__tests__/profile-startup.test.ts +40 -12
  46. package/src/__tests__/requires-probe.test.ts +858 -0
  47. package/src/__tests__/resolver.test.ts +129 -52
  48. package/src/__tests__/run.test.ts +108 -0
  49. package/src/__tests__/stale-load-repair.test.ts +31 -23
  50. package/src/__tests__/tool-probe.test.ts +1 -1
  51. package/src/__tests__/toolchain.test.ts +123 -52
  52. package/src/__tests__/update-apply.test.ts +13 -29
  53. package/src/__tests__/update-plan.test.ts +24 -18
  54. package/src/__tests__/useStaleLoadModal.test.ts +1 -57
  55. package/src/__tests__/version-unknown-state.test.ts +15 -17
  56. package/src/cli/ansi.ts +2 -7
  57. package/src/cli/deps-view.ts +213 -0
  58. package/src/cli/doctor.ts +320 -54
  59. package/src/cli/install.ts +55 -71
  60. package/src/cli/profile.ts +20 -2
  61. package/src/cli/router.ts +6 -2
  62. package/src/cli/update-view.ts +58 -15
  63. package/src/cli/update.ts +55 -12
  64. package/src/data/cli-tools.ts +24 -9
  65. package/src/services/active-closure.ts +3 -3
  66. package/src/services/catalog-cache-store.ts +8 -6
  67. package/src/services/claude-cli.ts +106 -19
  68. package/src/services/claude-settings.ts +88 -384
  69. package/src/services/cli-tool-commands.ts +104 -3
  70. package/src/services/deps-plan.ts +962 -0
  71. package/src/services/deps-report.ts +265 -0
  72. package/src/services/doctor-bins.ts +115 -43
  73. package/src/services/install-plan.ts +11 -1
  74. package/src/services/local-marketplace.ts +12 -206
  75. package/src/services/marketplace-refresh.ts +4 -4
  76. package/src/services/plugin-env-needs.ts +69 -0
  77. package/src/services/plugin-manager.ts +35 -37
  78. package/src/services/plugin-requires.ts +93 -162
  79. package/src/services/plugin-resolution.ts +34 -42
  80. package/src/services/profile-activate.ts +1 -2
  81. package/src/services/profile-startup.ts +18 -43
  82. package/src/services/profile-state.ts +72 -2
  83. package/src/services/resolver.ts +263 -59
  84. package/src/services/tool-probe.ts +18 -25
  85. package/src/services/toolchain.ts +117 -111
  86. package/src/services/update-engine.ts +345 -45
  87. package/src/services/update-plan.ts +296 -36
  88. package/src/shared/plugin/hooks/bun-missing.sh +39 -0
  89. package/src/shared/plugin/hooks/deps-check.ts +224 -0
  90. package/src/shared/plugin/hooks/lib/requires-probe.ts +1183 -0
  91. package/src/types/index.ts +60 -16
  92. package/src/ui/App.tsx +81 -171
  93. package/src/ui/adapters/cliToolsAdapter.ts +252 -12
  94. package/src/ui/adapters/depsAdapter.ts +129 -0
  95. package/src/ui/adapters/failureReport.ts +137 -0
  96. package/src/ui/adapters/pluginsAdapter.ts +297 -45
  97. package/src/ui/adapters/startupReports.ts +260 -0
  98. package/src/ui/components/modals/FailureListModal.tsx +231 -0
  99. package/src/ui/components/modals/MessageModal.tsx +7 -12
  100. package/src/ui/components/modals/ModalContainer.tsx +10 -5
  101. package/src/ui/components/modals/index.ts +1 -0
  102. package/src/ui/hooks/startupQueue.ts +56 -0
  103. package/src/ui/hooks/useGitignoreModal.ts +30 -52
  104. package/src/ui/hooks/useProfileStartupModal.ts +119 -142
  105. package/src/ui/hooks/useStaleLoadModal.ts +35 -65
  106. package/src/ui/keymap.ts +14 -1
  107. package/src/ui/renderers/cliToolRenderers.tsx +135 -2
  108. package/src/ui/renderers/mcpRenderers.tsx +110 -3
  109. package/src/ui/renderers/pluginRenderers.tsx +77 -6
  110. package/src/ui/renderers/pluginRowText.ts +25 -25
  111. package/src/ui/renderers/pluginStatusText.ts +18 -1
  112. package/src/ui/screens/AliasScreen.tsx +38 -45
  113. package/src/ui/screens/CliToolsScreen.tsx +199 -98
  114. package/src/ui/screens/EnvVarsScreen.tsx +17 -5
  115. package/src/ui/screens/GitignoreScreen.tsx +48 -67
  116. package/src/ui/screens/McpRegistryScreen.tsx +67 -38
  117. package/src/ui/screens/McpScreen.tsx +46 -19
  118. package/src/ui/screens/ModelsScreen.tsx +46 -86
  119. package/src/ui/screens/PluginsScreen.tsx +315 -259
  120. package/src/ui/screens/ProfilesScreen.tsx +79 -40
  121. package/src/ui/screens/SkillsScreen.tsx +83 -80
  122. package/src/ui/screens/StylesScreen.tsx +211 -275
  123. package/src/ui/state/AppContext.tsx +66 -44
  124. package/src/ui/state/DimensionsContext.tsx +3 -22
  125. package/src/ui/state/reducer.ts +12 -100
  126. package/src/ui/state/types.ts +48 -69
  127. package/src/utils/command-utils.ts +4 -5
  128. package/src/utils/run.ts +123 -52
  129. package/src/utils/string-utils.ts +9 -0
  130. package/src/utils/user-path.ts +60 -0
  131. package/src/__tests__/go-module.test.ts +0 -43
  132. package/src/__tests__/notices-rules.test.ts +0 -476
  133. package/src/__tests__/notices.test.tsx +0 -604
  134. package/src/__tests__/plugin-setup.test.ts +0 -1016
  135. package/src/__tests__/shell-script-callers.test.ts +0 -92
  136. package/src/__tests__/styles-status-line.test.ts +0 -72
  137. package/src/__tests__/version-snapshot.test.ts +0 -212
  138. package/src/services/plugin-setup.ts +0 -965
  139. package/src/services/version-snapshot.ts +0 -189
  140. package/src/utils/go-module.ts +0 -36
@@ -1,16 +1,28 @@
1
1
  /**
2
- * Toolchain detection + bootstrap for the package managers a profile's binary
3
- * deps need (bun, brew, npm, pip, go).
2
+ * The commands that install, upgrade, pin and remove a version-managed tool
3
+ * (bun, brew, npm, pip, go), and the bridge between a requirement and that
4
+ * version-managed view.
4
5
  *
5
- * `magus install` requires whatever installers the resolved closure uses. In
6
- * source form bun is already guaranteed (bin/magus.js hard-exits without it),
7
- * but once magus ships as a compiled binary an end user may lack bun — so bun
8
- * is treated as a bootstrappable toolchain exactly like brew.
6
+ * Installing a requirement goes through requires-probe's `renderInstall` and
7
+ * the deps executor (`services/deps-plan.ts`); this module builds only what
8
+ * `magus update` and the CLI Tools screen run beyond a first install.
9
9
  */
10
10
 
11
- import type { BinInstaller, ResolvedBin } from "../types/index.js";
11
+ import {
12
+ type InstallOption,
13
+ assertNever,
14
+ currentPlatform,
15
+ renderInstall,
16
+ } from "../shared/plugin/hooks/lib/requires-probe.js";
17
+ import type {
18
+ BinInstaller,
19
+ ManagedBin,
20
+ ManagedTool,
21
+ ResolvedBin,
22
+ SelectedBin,
23
+ } from "../types/index.js";
12
24
  import type { Command } from "../utils/command-utils.js";
13
- import { which, whichSync } from "../utils/command-utils.js";
25
+ import { whichSync } from "../utils/command-utils.js";
14
26
 
15
27
  // -- Python CLI applications -------------------------------------------------
16
28
 
@@ -160,125 +172,119 @@ export function resetPythonCliInstallerMemo(): void {
160
172
  }
161
173
 
162
174
  // ----------------------------------------------------------------------------
175
+ //
176
+ // The version-managed view of a requirement.
177
+ //
178
+ // A requirement (plugin `requires`, or a profile cliTool mapped onto the
179
+ // profile-only kinds) is installed by requires-probe's `renderInstall` and the
180
+ // deps executor. `magus update` and the CLI Tools screen additionally track
181
+ // the installed VERSION of the kinds that have one — bun, brew, npm, pip, go —
182
+ // and they work in the {@link ManagedTool} shape. These functions are the one
183
+ // bridge between the two, in both directions.
163
184
 
164
- /**
165
- * The executable that proves a toolchain is installed.
166
- *
167
- * `pip` is deliberately absent: which executable proves it depends on the
168
- * machine, so it is resolved by {@link resolvePythonCliInstaller} instead.
169
- */
170
- const TOOLCHAIN_PROBE: Record<Exclude<BinInstaller, "pip">, string> = {
171
- bun: "bun",
172
- brew: "brew",
173
- npm: "npm",
174
- go: "go",
175
- };
176
-
177
- /** The executable whose presence proves `name` is usable. */
178
- function toolchainProbe(name: BinInstaller): string {
179
- return name === "pip"
180
- ? resolvePythonCliInstaller().probe
181
- : TOOLCHAIN_PROBE[name];
182
- }
183
-
184
- /** Official one-line bootstrap for the toolchains magus will install. */
185
- export const TOOLCHAIN_BOOTSTRAP: Partial<Record<BinInstaller, string>> = {
186
- bun: "curl -fsSL https://bun.sh/install | bash",
187
- brew: '/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"',
188
- };
189
-
190
- export interface ToolchainStatus {
191
- name: BinInstaller;
192
- present: boolean;
193
- /** Binary names in the closure that need this toolchain. */
194
- requiredBy: string[];
195
- /** Bootstrap command, when magus can install this toolchain itself. */
196
- bootstrap?: string;
197
- }
198
-
199
- /** Is a given toolchain available on PATH? */
200
- export async function isToolchainPresent(name: BinInstaller): Promise<boolean> {
201
- return (await which(toolchainProbe(name))) !== null;
202
- }
185
+ const pinned = (version: string | undefined) => (version ? { version } : {});
203
186
 
204
187
  /**
205
- * Determine which toolchains a resolved closure's binary deps require, and
206
- * whether each is present. Only toolchains actually needed are returned.
188
+ * The version-managed view of a selected requirement, or null when its chosen
189
+ * option is not one of the {@link BinInstaller} kinds (apt, release,
190
+ * bootstrap, uv-script, uv-module: their version is the declaration's, and
191
+ * `magus doctor --fix` installs them).
207
192
  */
208
- export async function detectToolchains(
209
- bins: ResolvedBin[],
210
- ): Promise<ToolchainStatus[]> {
211
- const requiredBy = new Map<BinInstaller, string[]>();
212
- for (const bin of bins) {
213
- const list = requiredBy.get(bin.via) ?? [];
214
- list.push(bin.name);
215
- requiredBy.set(bin.via, list);
193
+ export function managedTool(bin: SelectedBin): ManagedTool | null {
194
+ const option = bin.chosen;
195
+ if (!option) return null;
196
+ const check = bin.check.join(" ");
197
+ switch (option.via) {
198
+ case "bun":
199
+ case "npm":
200
+ case "pip":
201
+ return {
202
+ name: bin.name,
203
+ via: option.via,
204
+ package: option.package,
205
+ check,
206
+ ...pinned(option.version),
207
+ };
208
+ case "go":
209
+ return {
210
+ name: bin.name,
211
+ via: "go",
212
+ module: option.package,
213
+ check,
214
+ ...pinned(option.version),
215
+ };
216
+ case "brew":
217
+ // A cask is installed, upgraded and removed with `--cask`, which the
218
+ // version-managed view does not speak: its declaration manages it.
219
+ return option.cask !== undefined
220
+ ? null
221
+ : { name: bin.name, via: "brew", formula: option.formula, check };
222
+ case "apt":
223
+ case "release":
224
+ case "bootstrap":
225
+ case "uv-script":
226
+ case "uv-module":
227
+ return null;
228
+ default:
229
+ return assertNever(option);
216
230
  }
231
+ }
217
232
 
218
- const statuses: ToolchainStatus[] = [];
219
- for (const [name, names] of requiredBy) {
220
- statuses.push({
221
- name,
222
- present: await isToolchainPresent(name),
223
- requiredBy: names,
224
- bootstrap: TOOLCHAIN_BOOTSTRAP[name],
225
- });
233
+ /** {@link managedTool} over a closure's bins, keeping each one's provenance. */
234
+ export function managedBins(bins: readonly ResolvedBin[]): ManagedBin[] {
235
+ const out: ManagedBin[] = [];
236
+ for (const bin of bins) {
237
+ const tool = managedTool(bin);
238
+ if (tool) out.push({ ...tool, sources: [...bin.sources] });
226
239
  }
227
- // Stable order: bun, brew, npm, pip, go.
228
- const order: BinInstaller[] = ["bun", "brew", "npm", "pip", "go"];
229
- statuses.sort((a, b) => order.indexOf(a.name) - order.indexOf(b.name));
230
- return statuses;
240
+ return out;
231
241
  }
232
242
 
233
- /**
234
- * The install command for a single binary requirement.
235
- *
236
- * `python` is injectable so tests can pin one and stay machine-independent —
237
- * the default depends on what is on PATH, so an assertion against a literal
238
- * `uv tool …` would pass here and fail on a runner without uv.
239
- *
240
- * `pkg@version` and `pkg==version` are each ONE argv token. That join is
241
- * precisely where a string was dangerous: `bin.package` is hand-authored
242
- * profile/marketplace data, and under a shell a space or a `;` in it would have
243
- * become extra words. Here it cannot.
244
- */
245
- export function binInstallCommand(
246
- bin: {
247
- name: string;
248
- via: BinInstaller;
249
- package?: string;
250
- formula?: string;
251
- module?: string;
252
- version?: string;
253
- },
254
- python: PythonCliInstaller = resolvePythonCliInstaller(),
255
- ): Command {
256
- const pkg = bin.package ?? bin.name;
257
- const at = bin.version ? `@${bin.version}` : "";
258
- switch (bin.via) {
243
+ /** The install option a {@link ManagedTool} stands for. */
244
+ export function managedOption(t: ManagedTool): InstallOption {
245
+ switch (t.via) {
246
+ case "brew":
247
+ return { via: "brew", formula: t.formula ?? t.name };
248
+ case "go":
249
+ return { via: "go", package: t.module ?? t.name, ...pinned(t.version) };
259
250
  case "bun":
260
- return { cmd: "bun", args: ["install", "-g", `${pkg}${at}`] };
261
251
  case "npm":
262
- return { cmd: "npm", args: ["install", "-g", `${pkg}${at}`] };
263
252
  case "pip":
264
- return python.install(pkg, bin.version);
265
- case "brew":
266
- return { cmd: "brew", args: ["install", bin.formula ?? bin.name] };
267
- case "go":
268
253
  return {
269
- cmd: "go",
270
- args: [
271
- "install",
272
- `${bin.module ?? bin.name}@${bin.version ?? "latest"}`,
273
- ],
254
+ via: t.via,
255
+ package: t.package ?? t.name,
256
+ ...pinned(t.version),
274
257
  };
258
+ default:
259
+ return assertNever(t.via);
260
+ }
261
+ }
262
+
263
+ /**
264
+ * The command that installs a {@link ManagedTool}, rendered by requires-probe's
265
+ * `renderInstall` — the one renderer every install goes through — so the pin
266
+ * travels in the same token (`pkg@version`, `pkg==version`) it does there.
267
+ */
268
+ export function managedInstallCommand(t: ManagedTool): Command {
269
+ const step = renderInstall(
270
+ { name: t.name, check: [], install: [] },
271
+ managedOption(t),
272
+ {
273
+ ...(currentPlatform() ?? { os: "linux", arch: "amd64" }),
274
+ pluginRoot: "",
275
+ },
276
+ );
277
+ if (step.kind !== "argv") {
278
+ throw new Error(`${t.via} renders a ${step.kind} step, not a command`);
275
279
  }
280
+ const [cmd = "", ...args] = step.argv;
281
+ return { cmd, args };
276
282
  }
277
283
 
278
284
  /**
279
285
  * The command that advances an ALREADY-INSTALLED binary to the newest version.
280
286
  *
281
- * Distinct from {@link binInstallCommand} because two of the five installers
287
+ * Distinct from {@link managedInstallCommand} because two of the five installers
282
288
  * treat "install" as a no-op once the package is present: `brew install` on an
283
289
  * installed formula prints "already installed" and changes nothing, and `pip
284
290
  * install` without `--upgrade` does the same. Reusing the install command for
@@ -363,7 +369,7 @@ export function claudeNativeUpgradeCommand(pin?: string): Command {
363
369
  * {@link binUpgradeCommand} goes to the newest version, past the pin, and a
364
370
  * plain `uv tool install pkg==v` is a no-op once any version is installed.
365
371
  *
366
- * bun, npm and go take the version in the same token `binInstallCommand` builds
372
+ * bun, npm and go take the version in the same token `managedInstallCommand` builds
367
373
  * (`pkg@v`), and each replaces an installed version with it. pip goes through
368
374
  * the resolved installer's own `pin`. brew installs only its newest version, so
369
375
  * there is nothing to return — the planner never asks for it (a brew pin below
@@ -387,7 +393,7 @@ export function binPinCommand(
387
393
  case "bun":
388
394
  case "npm":
389
395
  case "go":
390
- return binInstallCommand(bin, python);
396
+ return managedInstallCommand(bin);
391
397
  case "pip":
392
398
  return python.pin(bin.package ?? bin.name, bin.version);
393
399
  case "brew":
@@ -405,7 +411,7 @@ export function binPinCommand(
405
411
  * `bun install -g pkg@latest` and left the tool permanently ahead of its pin,
406
412
  * a state magus cannot leave. Both now come through here.
407
413
  *
408
- * `install` → {@link binInstallCommand} (which appends the pin, when there is
414
+ * `install` → {@link managedInstallCommand} (which appends the pin, when there is
409
415
  * one). An upgrade whose target IS the pin → {@link binPinCommand}, because
410
416
  * {@link binUpgradeCommand} would overshoot it. Any other upgrade → the newest
411
417
  * version.
@@ -426,7 +432,7 @@ export function binCommandForState(
426
432
  },
427
433
  python: PythonCliInstaller = resolvePythonCliInstaller(),
428
434
  ): Command | null {
429
- if (state === "install") return binInstallCommand(bin, python);
435
+ if (state === "install") return managedInstallCommand(bin);
430
436
  if (bin.version && target === bin.version) return binPinCommand(bin, python);
431
437
  return binUpgradeCommand(bin, python);
432
438
  }