barndog 0.2.0 → 0.2.2

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 (112) hide show
  1. package/README.md +45 -24
  2. package/dist/cli.js +27 -1
  3. package/dist/commands/add.js +1 -0
  4. package/dist/commands/adopt.js +91 -0
  5. package/dist/commands/asset-install.js +1 -0
  6. package/dist/commands/asset-list.js +12 -3
  7. package/dist/commands/availability.js +25 -8
  8. package/dist/commands/capabilities.js +8 -2
  9. package/dist/commands/collaboration.js +22 -2
  10. package/dist/commands/harnesses.js +104 -0
  11. package/dist/commands/mcp-env.js +167 -0
  12. package/dist/commands/mcp.js +4 -2
  13. package/dist/commands/sets.js +13 -2
  14. package/dist/commands/status.js +2 -1
  15. package/dist/commands/sync.js +2 -1
  16. package/dist/commands/uninstall.js +62 -0
  17. package/dist/commands/workspace.js +43 -5
  18. package/dist/config/paths.js +21 -0
  19. package/dist/config/settings.js +5 -3
  20. package/dist/config/state.js +18 -6
  21. package/dist/entry/update-check.js +15 -0
  22. package/dist/features/adoption/adopt.js +235 -0
  23. package/dist/features/adoption/copies.js +29 -0
  24. package/dist/features/adoption/originals.js +116 -0
  25. package/dist/features/adoption/record.js +120 -0
  26. package/dist/features/adoption/restore.js +28 -0
  27. package/dist/features/adoption/scan.js +482 -0
  28. package/dist/features/adoption/undo.js +42 -0
  29. package/dist/features/asset-kinds/index.js +9 -0
  30. package/dist/features/auth/credentials.js +7 -14
  31. package/dist/features/auth/session.js +26 -5
  32. package/dist/features/auth/transport.js +3 -2
  33. package/dist/features/collaboration/workspace-git.js +13 -7
  34. package/dist/features/collaboration/workspace-github.js +2 -1
  35. package/dist/features/collaboration/workspace-store.js +25 -4
  36. package/dist/features/collaboration/workspace.js +22 -2
  37. package/dist/features/doctor/index.js +46 -7
  38. package/dist/features/environment/events.js +8 -1
  39. package/dist/features/environment/harnesses.js +36 -0
  40. package/dist/features/environment/kept-values.js +68 -0
  41. package/dist/features/environment/moves.js +187 -0
  42. package/dist/features/environment/names.js +10 -6
  43. package/dist/features/environment/operations.js +7 -7
  44. package/dist/features/environment/stage.js +25 -1
  45. package/dist/features/environment/sync.js +17 -6
  46. package/dist/features/environment/writes.js +55 -8
  47. package/dist/features/hooks/compatibility.js +11 -5
  48. package/dist/features/hooks/divergence.js +30 -9
  49. package/dist/features/hooks/test.js +25 -25
  50. package/dist/features/imports/discover.js +1 -1
  51. package/dist/features/imports/local.js +15 -2
  52. package/dist/features/imports/remote.js +2 -1
  53. package/dist/features/inventory/index.js +57 -3
  54. package/dist/features/inventory/show.js +74 -0
  55. package/dist/features/mcps/import.js +95 -21
  56. package/dist/features/mcps/index.js +24 -9
  57. package/dist/features/mcps/values.js +121 -0
  58. package/dist/features/migration/migrate.js +15 -0
  59. package/dist/features/migration/move.js +105 -25
  60. package/dist/features/migration/promote.js +2 -0
  61. package/dist/features/native/adapters.js +20 -7
  62. package/dist/features/native/configuration.js +8 -4
  63. package/dist/features/native/hook-shell.js +11 -0
  64. package/dist/features/native/secret-values.js +74 -0
  65. package/dist/features/secrets/index.js +142 -0
  66. package/dist/features/uninstall/index.js +126 -0
  67. package/dist/features/uninstall/leave.js +152 -0
  68. package/dist/features/uninstall/survey.js +103 -0
  69. package/dist/features/update-check/index.js +108 -0
  70. package/dist/features/workspace/format.js +19 -10
  71. package/dist/features/workspace/git.js +11 -4
  72. package/dist/features/workspace/overlay.js +23 -36
  73. package/dist/features/workspace/packages.js +16 -3
  74. package/dist/features/workspace/publish.js +1 -1
  75. package/dist/features/workspace/repo-source.js +4 -3
  76. package/dist/features/workspace/setup.js +12 -3
  77. package/dist/features/workspace/snapshot.js +7 -1
  78. package/dist/harnesses/claude.js +2 -2
  79. package/dist/harnesses/codex.js +54 -20
  80. package/dist/harnesses/cursor.js +2 -2
  81. package/dist/harnesses/formats.js +12 -5
  82. package/dist/harnesses/opencode.js +3 -6
  83. package/dist/harnesses/read-renamed-variables.js +141 -0
  84. package/dist/harnesses/renamed-variables.js +99 -0
  85. package/dist/platform.js +51 -12
  86. package/dist/program.js +68 -8
  87. package/dist/shared/files.js +35 -0
  88. package/dist/shared/lock.js +87 -23
  89. package/dist/shared/patterns.js +8 -0
  90. package/dist/shared/shell.js +0 -2
  91. package/dist/ui/add-hook.js +8 -2
  92. package/dist/ui/add-mcp.js +82 -13
  93. package/dist/ui/add-skills.js +7 -5
  94. package/dist/ui/adopt.js +202 -0
  95. package/dist/ui/assets.js +5 -3
  96. package/dist/ui/auth.js +2 -1
  97. package/dist/ui/clash.js +2 -3
  98. package/dist/ui/connection.js +9 -2
  99. package/dist/ui/harness-picker.js +23 -0
  100. package/dist/ui/mcp.js +89 -23
  101. package/dist/ui/move.js +49 -2
  102. package/dist/ui/onboarding.js +40 -27
  103. package/dist/ui/output.js +35 -8
  104. package/dist/ui/package-details.js +34 -0
  105. package/dist/ui/scope-install.js +4 -1
  106. package/dist/ui/secret-input.js +28 -0
  107. package/dist/ui/selection.js +3 -1
  108. package/dist/ui/uninstall.js +174 -0
  109. package/dist/ui/update.js +10 -0
  110. package/dist/version.js +2 -2
  111. package/package.json +1 -1
  112. package/dist/entry/mcp-launch.js +0 -71
package/dist/ui/move.js CHANGED
@@ -1,4 +1,38 @@
1
+ import select from "@inquirer/select";
1
2
  import { bold, dim, hint, ok, table, warn } from "./format.js";
3
+ import { pickMany } from "./pick.js";
4
+ import { promptTheme } from "./theme.js";
5
+ /** The local assets `local move` can take: valid, and not already moving. */
6
+ export function pickLocalAssets(local) {
7
+ return pickMany("Which local assets should move?", local.assets
8
+ .filter((asset) => asset.state === "available")
9
+ .map((asset) => ({
10
+ value: asset.name,
11
+ name: asset.name,
12
+ hint: asset.kind,
13
+ })), { empty: "No local assets can be moved." });
14
+ }
15
+ /** True keeps separate local copies; false makes the shared copies the only ones. */
16
+ export function chooseKeepLocal(count) {
17
+ const them = count === 1 ? "it" : "them";
18
+ return select({
19
+ loop: false,
20
+ message: `Move ${them}, or share a copy and keep ${them} here too?`,
21
+ choices: [
22
+ {
23
+ name: "Move",
24
+ value: false,
25
+ description: `The shared copy becomes the only one. Once it exists, the next sync installs it and removes the local copy.`,
26
+ },
27
+ {
28
+ name: "Keep a separate local copy",
29
+ value: true,
30
+ description: `Shares a copy. The local ${count === 1 ? "asset stays" : "assets stay"} on this machine as ${count === 1 ? "its" : "their"} own.`,
31
+ },
32
+ ],
33
+ theme: promptTheme,
34
+ });
35
+ }
2
36
  export function renderMove(result) {
3
37
  if (!result.rows.length) {
4
38
  return [dim("Nothing to move.")];
@@ -10,13 +44,26 @@ export function renderMove(result) {
10
44
  dim(row.detail ?? ""),
11
45
  ]), { header: ["Status", "Kind", "Name", ""] });
12
46
  output.push("");
13
- if (result.direct) {
47
+ const moved = result.rows.some((row) => row.status === "moved");
48
+ if (result.direct && result.branch) {
14
49
  output.push(`${ok("✔")} Added to ${result.branch}.`);
15
50
  }
16
51
  else if (result.branch) {
17
52
  output.push(result.url
18
53
  ? `Open the pull request: ${result.url}`
19
- : `Open a pull request from ${result.branch} on your Git host.`, dim("Your local copies stay active until it merges."));
54
+ : `Open a pull request from ${result.branch} on your Git host.`);
55
+ }
56
+ if (moved && result.keepLocal) {
57
+ output.push(dim("Your local copies stay as separate assets. Where one has the same name as its shared copy, sync asks which to rename."));
58
+ }
59
+ else if (moved && result.direct) {
60
+ output.push(dim("The shared copies are installed and the local ones removed."));
61
+ }
62
+ else if (moved) {
63
+ output.push(dim("The move finishes when that merges: your local copies stay in use until then, and the next sync replaces them with the shared ones."));
64
+ }
65
+ for (const path of result.removed) {
66
+ output.push(dim(`Removed ${path}`));
20
67
  }
21
68
  for (const row of result.rows) {
22
69
  if (row.status === "clash") {
@@ -6,38 +6,25 @@ import { localRepoSource } from "../features/workspace/repo-source.js";
6
6
  import { renderMove } from "./move.js";
7
7
  import { checkRepositoryUrl, cloneOrigin, RepositoryAccessError, } from "../features/workspace/git.js";
8
8
  import { cloneGitWorkspace, connectGitWorkspace, createGitWorkspace, inspectRepository, localWorkspace, } from "../features/workspace/setup.js";
9
- import { CliError } from "../errors.js";
9
+ import { CliError, friendlyMessage } from "../errors.js";
10
10
  import { selectionState } from "../config/environment.js";
11
11
  import { LoginRequiredError } from "../features/auth/transport.js";
12
12
  import { runLogin } from "./auth.js";
13
+ import { interactiveTerminal } from "./pick.js";
13
14
  import { synchronize } from "../features/environment/sync.js";
14
15
  import { cleanUpIfInterrupted } from "../features/environment/transaction.js";
15
16
  import { renderSyncOutput } from "./output.js";
16
- import checkbox from "@inquirer/checkbox";
17
17
  import confirm from "@inquirer/confirm";
18
18
  import { existsSync, readdirSync, rmSync } from "node:fs";
19
19
  import { basename } from "node:path";
20
20
  import { styleText } from "node:util";
21
21
  import { readSettings, } from "../config/settings.js";
22
22
  import { initialize, } from "../features/onboarding/setup.js";
23
- import { checkboxTheme, promptTheme, selected } from "./theme.js";
24
- import { bold, dim, fields, heading, originLabel, table } from "./format.js";
23
+ import { promptTheme, selected } from "./theme.js";
24
+ import { chooseHarnesses } from "./harness-picker.js";
25
+ import { offerAdoptionAtSetup, } from "./adopt.js";
26
+ import { bold, dim, fields, heading, originLabel, table, warn, } from "./format.js";
25
27
  import { barndogPaths } from "../config/paths.js";
26
- const chooseHarnesses = (choices) => {
27
- const width = Math.max(...choices.map((choice) => choice.name.length));
28
- return checkbox({
29
- loop: false,
30
- message: "Which coding tools should BarnDog manage?",
31
- choices: choices.map((choice) => ({
32
- value: choice.value,
33
- checked: choice.checked,
34
- short: choice.name,
35
- name: `${choice.name.padEnd(width)} ${choice.evidence ? selected("detected") : dim("not found")}`,
36
- description: choice.evidence ?? undefined,
37
- })),
38
- theme: checkboxTheme,
39
- });
40
- };
41
28
  /** The source setup was last run with, offered as the default. */
42
29
  function savedChoice(previous, server) {
43
30
  if (previous.gitWorkspace) {
@@ -90,10 +77,21 @@ function cloneCleanup(home, before, workspaceId) {
90
77
  };
91
78
  return { discard, keep: cleanUpIfInterrupted(discard) };
92
79
  }
80
+ /** The setup choices that send local assets to the new workspace. */
81
+ const sharesLocalAssets = {
82
+ keep: false,
83
+ copy: true,
84
+ move: true,
85
+ leave: false,
86
+ };
93
87
  export async function runSetup(options) {
94
88
  const { runtime } = options;
95
89
  const { home } = runtime;
96
90
  const write = options.write ?? console.log;
91
+ // Checked first, so a wrong command line fails before any question.
92
+ if ([options.local, options.server, options.repo].filter(Boolean).length > 1) {
93
+ throw new CliError("--local, --repo and --server can't be combined. Choose one.", "barndog init --help");
94
+ }
97
95
  const previous = await readSettings(home);
98
96
  if (previous) {
99
97
  write(`Configuration already exists at ${barndogPaths(home).settings}.`);
@@ -103,7 +101,7 @@ export async function runSetup(options) {
103
101
  return;
104
102
  }
105
103
  }
106
- const interactive = options.interactive ?? Boolean(process.stdin.isTTY && process.stdout.isTTY);
104
+ const interactive = options.interactive ?? interactiveTerminal();
107
105
  if (!interactive) {
108
106
  throw new CliError("Setup needs an interactive terminal. Run it in your terminal, not from a script or pipe.", "barndog init");
109
107
  }
@@ -120,9 +118,6 @@ export async function runSetup(options) {
120
118
  }
121
119
  }
122
120
  write(`\n${heading("setup")}\n`);
123
- if ([options.local, options.server, options.repo].filter(Boolean).length > 1) {
124
- throw new CliError("--local, --repo and --server can't be combined. Choose one.", "barndog init --help");
125
- }
126
121
  const choice = flagChoice(options) ??
127
122
  (await chooseSource(previous, options.runtime, options.chooseConnection));
128
123
  const server = choice.kind === "cloud" ? choice.server : undefined;
@@ -197,7 +192,13 @@ export async function runSetup(options) {
197
192
  if (!(error instanceof LoginRequiredError)) {
198
193
  throw error;
199
194
  }
200
- await runLogin({ server, browser: options.browser !== false, runtime, force: true }, write);
195
+ await runLogin({
196
+ server,
197
+ browser: options.browser !== false,
198
+ runtime,
199
+ force: true,
200
+ interactive,
201
+ }, write);
201
202
  session = await authStatus(options.runtime, server);
202
203
  }
203
204
  write(`${dim("Signed in")} ${session.context.developer.name} · ${session.context.organization.name}`);
@@ -207,7 +208,11 @@ export async function runSetup(options) {
207
208
  ? await localRepoSource(keptFolder, options.runtime)
208
209
  .model()
209
210
  .then((model) => model.assets.length + model.knowledge.length)
210
- .catch(() => 0)
211
+ .catch((error) => {
212
+ // Setup goes on and leaves the folder as it is, but says why it didn't ask.
213
+ write(`${warn("!")} Couldn't read the local workspace at ${keptFolder.path}, so it stays as it is: ${friendlyMessage(error)}`);
214
+ return 0;
215
+ })
211
216
  : 0;
212
217
  const localChoice = localCount
213
218
  ? await (options.chooseLocalAssets ?? chooseLocalAssets)(localCount)
@@ -305,15 +310,23 @@ export async function runSetup(options) {
305
310
  write("Setup cancelled. Configuration and installed assets were not changed. Your sign-in is retained.");
306
311
  return;
307
312
  }
308
- if (localChoice === "move" && localCount) {
313
+ if (sharesLocalAssets[localChoice] && localCount) {
309
314
  const to = choice.kind === "cloud"
310
315
  ? await (options.chooseMoveTarget ?? chooseMoveTarget)(await cloudMoveTargets(options.runtime))
311
316
  : undefined;
312
317
  write("");
313
- for (const line of renderMove(await moveLocalAssets({ to }, options.runtime))) {
318
+ for (const line of renderMove(await moveLocalAssets({ to, keepLocal: localChoice === "copy" }, options.runtime))) {
314
319
  write(line);
315
320
  }
316
321
  }
322
+ // Only a first setup asks: later runs already had the chance, and `barndog adopt` stays available.
323
+ if (!previous) {
324
+ await offerAdoptionAtSetup(runtime, {
325
+ write,
326
+ choose: options.chooseAdoption,
327
+ confirm: options.confirmAdoption,
328
+ });
329
+ }
317
330
  write("");
318
331
  write(`${selected("✔")} Saved to ${result.configPath}`);
319
332
  write("");
package/dist/ui/output.js CHANGED
@@ -5,6 +5,7 @@ import { styleText } from "node:util";
5
5
  import { basename } from "node:path";
6
6
  import { isInside } from "../shared/files.js";
7
7
  import { SetupRequiredError } from "../config/settings.js";
8
+ import { unassignedValueMessage, unsetValueMessage, } from "../features/environment/events.js";
8
9
  import { adapters, isHarness } from "../harnesses/registry.js";
9
10
  import { primary, danger } from "./theme.js";
10
11
  import { bad, bold, dim, heading, hint, json, ok, table, warn, } from "./format.js";
@@ -52,7 +53,10 @@ function rows(events) {
52
53
  byKey.set(key, row);
53
54
  };
54
55
  for (const event of events) {
55
- if (event.type === "disabled" || event.type === "notice") {
56
+ if (event.type === "disabled" ||
57
+ event.type === "notice" ||
58
+ event.type === "unset-variable" ||
59
+ event.type === "unassigned-value") {
56
60
  continue;
57
61
  }
58
62
  if (event.type === "invalid") {
@@ -151,20 +155,43 @@ export function renderSyncOutput(events, options = {}) {
151
155
  }
152
156
  else {
153
157
  output.push(changed
154
- ? dim("Restart your coding tools to pick up the changes.")
158
+ ? dim("A restart of your coding tools may be required to pick up the changes.")
155
159
  : quiet);
156
160
  }
157
161
  for (const event of events) {
158
- if (event.type === "notice") {
159
- output.push("", `${warn("!")} ${event.message}`);
160
- }
161
- else if (event.type === "clash") {
162
- output.push("", `${warn("!")} ${assetKinds[event.kind].one} ${bold(event.skipped.name)} from ${event.skipped.origin} was skipped: ${event.installed.origin} already installs one with that name.`, ` ${hint(`barndog ${assetKinds[event.kind].command} rename ${event.skipped.name} --origin ${event.skipped.origin} --as ${event.skipped.rename}`, "Fix")}`);
163
- }
162
+ output.push(...problemLines(event));
164
163
  }
165
164
  output.push("");
166
165
  return output;
167
166
  }
167
+ /** What a sync event asks the developer to look at, after the summary; nothing for the rest. */
168
+ function problemLines(event) {
169
+ if (event.type === "notice") {
170
+ return ["", `${warn("!")} ${event.message}`];
171
+ }
172
+ if (event.type === "unset-variable") {
173
+ return [
174
+ "",
175
+ `${warn("!")} ${unsetValueMessage(event)}`,
176
+ ` ${hint(`barndog mcp env set ${event.server} ${event.variable}`, "Fix")}`,
177
+ ];
178
+ }
179
+ if (event.type === "unassigned-value") {
180
+ return [
181
+ "",
182
+ `${warn("!")} ${unassignedValueMessage(event.variable)}`,
183
+ ` ${hint(`barndog mcp env set <server> ${event.variable}`, "Fix")}`,
184
+ ];
185
+ }
186
+ if (event.type === "clash") {
187
+ return [
188
+ "",
189
+ `${warn("!")} ${assetKinds[event.kind].one} ${bold(event.skipped.name)} from ${event.skipped.origin} was skipped: ${event.installed.origin} already installs one with that name.`,
190
+ ` ${hint(`barndog ${assetKinds[event.kind].command} rename ${event.skipped.name} --origin ${event.skipped.origin} --as ${event.skipped.rename}`, "Fix")}`,
191
+ ];
192
+ }
193
+ return [];
194
+ }
168
195
  function describeError(error) {
169
196
  if (error instanceof LoginRequiredError) {
170
197
  return { message: "You're not signed in.", fix: "barndog login" };
@@ -0,0 +1,34 @@
1
+ import { adapters, hookHarnesses } from "../harnesses/registry.js";
2
+ import { SHORT_COMMIT_LENGTH } from "../shared/constants.js";
3
+ import { bold, clean, dim, fields } from "./format.js";
4
+ /** `skills show` and `hooks show`: what the asset is and where this machine has it. */
5
+ export function renderPackageDetails(details) {
6
+ const { installed } = details;
7
+ const events = hookHarnesses.flatMap((harness) => {
8
+ const names = details.events?.[harness];
9
+ return names ? [`${adapters[harness].name}: ${names.join(", ")}`] : [];
10
+ });
11
+ const output = fields([
12
+ ["Name", bold(clean(details.name))],
13
+ ["Origin", details.origin],
14
+ [
15
+ "Version",
16
+ typeof details.version === "number"
17
+ ? `v${details.version}`
18
+ : details.version.slice(0, SHORT_COMMIT_LENGTH),
19
+ ],
20
+ ["Description", clean(details.description)],
21
+ ["State", installed?.state ?? dim("not installed")],
22
+ [
23
+ "Installed in",
24
+ installed?.harnesses.map((harness) => adapters[harness].name).join(", "),
25
+ ],
26
+ ]);
27
+ if (details.kind === "hook") {
28
+ output.push("", dim("Events"), ...(events.length ? events : [dim("No coding tool runs it.")]).map((line) => ` ${line}`));
29
+ }
30
+ if (installed?.paths.length) {
31
+ output.push("", dim("Paths"), ...installed.paths.map((path) => ` ${path}`));
32
+ }
33
+ return output;
34
+ }
@@ -3,6 +3,7 @@ import select from "@inquirer/select";
3
3
  import { CliError } from "../errors.js";
4
4
  import { runSelection } from "./selection.js";
5
5
  import { checkboxTheme, promptTheme } from "./theme.js";
6
+ import { interactiveTerminal } from "./pick.js";
6
7
  /**
7
8
  * Installs a scope using an explicit mode or interactive asset selection, then
8
9
  * renders the selection result.
@@ -12,7 +13,9 @@ export async function runSetInstall(context, options, prompts = {}) {
12
13
  if (options.mode) {
13
14
  return install(options.mode);
14
15
  }
15
- if (!(prompts.interactive ?? Boolean(process.stdin.isTTY && process.stdout.isTTY))) {
16
+ if (!(prompts.interactive ??
17
+ context.mode?.interactive ??
18
+ interactiveTerminal())) {
16
19
  throw new CliError("Choose which assets to include with --mode, or run this in a terminal to pick.", `barndog sets install ${options.origin} --mode recommended`);
17
20
  }
18
21
  const mode = await (prompts.mode ??
@@ -0,0 +1,28 @@
1
+ /** Reads an MCP variable's value without showing it or putting it in shell history. */
2
+ import confirm from "@inquirer/confirm";
3
+ import input from "@inquirer/input";
4
+ import { promptTheme } from "./theme.js";
5
+ /** Asks in the terminal, echoing one `*` per character. */
6
+ export function askSecret(variable) {
7
+ return input({
8
+ message: `Value for ${variable}`,
9
+ transformer: (value) => "*".repeat(value.length),
10
+ theme: promptTheme,
11
+ });
12
+ }
13
+ /** Everything piped in, without the final line break a file or `echo` adds. */
14
+ export async function readStdin(stream = process.stdin) {
15
+ let text = "";
16
+ for await (const chunk of stream) {
17
+ text += chunk.toString();
18
+ }
19
+ return text.replace(/\r?\n$/, "");
20
+ }
21
+ /** Asks whether a server should use the value BarnDog kept before values belonged to servers. */
22
+ export function askUseUnassigned(variable) {
23
+ return confirm({
24
+ message: `BarnDog already keeps a value for ${variable} that no server has. Use it?`,
25
+ default: true,
26
+ theme: promptTheme,
27
+ });
28
+ }
@@ -4,6 +4,7 @@ import { DecisionRequiredError } from "./decision-error.js";
4
4
  import { json } from "./format.js";
5
5
  import { renderSyncOutput } from "./output.js";
6
6
  import { promptTheme } from "./theme.js";
7
+ import { interactiveTerminal } from "./pick.js";
7
8
  /** A change that would undo exclusions or disabled assets runs again with the answer. */
8
9
  export async function runSelection(context, change) {
9
10
  let resolution;
@@ -19,7 +20,8 @@ export async function runSelection(context, change) {
19
20
  }
20
21
  return;
21
22
  }
22
- if (context.mode?.json || !process.stdin.isTTY || !process.stdout.isTTY) {
23
+ if (context.mode?.json ||
24
+ !(context.mode?.interactive ?? interactiveTerminal())) {
23
25
  throw new DecisionRequiredError(result.conflicts);
24
26
  }
25
27
  const type = await select({
@@ -0,0 +1,174 @@
1
+ /** `barndog uninstall`: the questions it asks, its plan and what it did. */
2
+ import checkbox, { Separator } from "@inquirer/checkbox";
3
+ import confirm from "@inquirer/confirm";
4
+ import select from "@inquirer/select";
5
+ import { adapters, harnesses } from "../harnesses/registry.js";
6
+ import { bold, dim, hint, ok, plural, table, warn } from "./format.js";
7
+ import { displayPath } from "./output.js";
8
+ import { checkboxTheme, promptTheme } from "./theme.js";
9
+ /** The command that removes the CLI itself, once BarnDog's files are gone. */
10
+ const REMOVE_CLI = "npm uninstall -g barndog";
11
+ const kindLabels = {
12
+ skill: "Skill",
13
+ mcp: "MCP server",
14
+ hook: "Hook",
15
+ };
16
+ const kindWidth = Math.max(...Object.values(kindLabels).map((label) => label.length));
17
+ /** `3 Skills, 1 MCP server and 2 Hooks`, leaving out kinds with none. */
18
+ function counts(assets) {
19
+ const parts = ["skill", "mcp", "hook"].flatMap((kind) => {
20
+ const count = assets.filter((asset) => asset.kind === kind).length;
21
+ return count ? [plural(count, kindLabels[kind])] : [];
22
+ });
23
+ return parts.length > 1
24
+ ? `${parts.slice(0, -1).join(", ")} and ${parts.at(-1)}`
25
+ : (parts[0] ?? "nothing");
26
+ }
27
+ /** How each line of the plan starts; details under a line align with its text. */
28
+ const STEP = " • ";
29
+ /** Each variable and the MCP servers that read it, one per row. */
30
+ const variableRows = (variables, indent = 2) => table(variables.map((variable) => [
31
+ bold(variable.name),
32
+ dim(variable.servers.join(", ")),
33
+ ]), { indent, header: ["Variable", "MCP servers"] });
34
+ /** Options from the command line alone, for runs that can't prompt. */
35
+ export function uninstallOptions(survey, choices) {
36
+ return {
37
+ keepSetup: choices.keepSetup,
38
+ restore: choices.keepSetup || choices.dropAdopted
39
+ ? []
40
+ : survey.adopted.map((item) => item.key),
41
+ keepWorkspace: !choices.removeWorkspace,
42
+ force: choices.force,
43
+ };
44
+ }
45
+ const chooseRestored = (adopted) => checkbox({
46
+ loop: false,
47
+ message: "Put these adopted assets back where they were? Unchecked ones are deleted.",
48
+ choices: harnesses.flatMap((harness) => {
49
+ const mine = adopted.filter((item) => item.harness === harness);
50
+ return mine.length
51
+ ? [
52
+ new Separator(bold(adapters[harness].name)),
53
+ ...mine.map((item) => ({
54
+ value: item.key,
55
+ checked: true,
56
+ short: item.key,
57
+ name: `${kindLabels[item.kind].padEnd(kindWidth)} ${item.name}`,
58
+ })),
59
+ ]
60
+ : [];
61
+ }),
62
+ theme: checkboxTheme,
63
+ });
64
+ /** Asks for each choice the command line left open. */
65
+ export async function askUninstall(survey, choices, runtime) {
66
+ const keepSetup = choices.keepSetup ??
67
+ (await select({
68
+ loop: false,
69
+ message: survey.installed.length
70
+ ? `What should happen to the ${counts(survey.installed)} BarnDog installed?`
71
+ : "What should happen to what BarnDog installed?",
72
+ choices: [
73
+ {
74
+ name: "Leave them in my coding tools",
75
+ value: true,
76
+ description: "Skills and Hooks become plain folders in each tool; MCP servers stay as they are.",
77
+ },
78
+ {
79
+ name: "Remove them",
80
+ value: false,
81
+ description: "Adopted assets can go back where they came from.",
82
+ },
83
+ ],
84
+ theme: promptTheme,
85
+ }));
86
+ const restore = keepSetup || choices.dropAdopted || !survey.adopted.length
87
+ ? []
88
+ : await chooseRestored(survey.adopted);
89
+ const workspace = survey.workspace;
90
+ const keepWorkspace = !choices.removeWorkspace &&
91
+ (!workspace ||
92
+ (await confirm({
93
+ message: `Keep your local workspace folder, ${displayPath(workspace, runtime)}?`,
94
+ default: true,
95
+ theme: promptTheme,
96
+ })));
97
+ return { keepSetup, restore, keepWorkspace, force: choices.force };
98
+ }
99
+ /** What uninstalling with `options` will do. */
100
+ export function renderUninstallPlan(survey, options, runtime) {
101
+ const root = displayPath(survey.root, runtime);
102
+ const lines = [bold("BarnDog will")];
103
+ const step = (text) => lines.push(`${STEP}${text}`);
104
+ if (survey.installed.length) {
105
+ step(options.keepSetup
106
+ ? `leave ${counts(survey.installed)} in your coding tools, as plain files of their own`
107
+ : `remove ${counts(survey.installed)} from your coding tools`);
108
+ }
109
+ if (options.keepSetup && survey.variables.length) {
110
+ step(warn("leave it to you to keep these variables set; your MCP servers read them from your environment:"));
111
+ lines.push(...variableRows(survey.variables, STEP.length));
112
+ }
113
+ step("remove its own scripts and registrations from your tools");
114
+ const restored = survey.adopted.filter((item) => options.restore.includes(item.key));
115
+ const dropped = options.keepSetup
116
+ ? []
117
+ : survey.adopted.filter((item) => !options.restore.includes(item.key));
118
+ if (restored.length) {
119
+ step(`put back ${plural(restored.length, "adopted asset")} where ${restored.length === 1 ? "it" : "they"} came from`);
120
+ }
121
+ if (dropped.length) {
122
+ step(warn(`delete ${plural(dropped.length, "adopted asset")} for good: ${dropped.map((item) => item.key).join(", ")}`));
123
+ }
124
+ if (survey.servers.length) {
125
+ step(`sign out of ${survey.servers.join(", ")}`);
126
+ }
127
+ const workspace = survey.workspace;
128
+ step(workspace && options.keepWorkspace
129
+ ? `delete ${root}, except your local workspace in ${displayPath(workspace, runtime)}`
130
+ : `delete ${root}`);
131
+ return lines;
132
+ }
133
+ export function confirmUninstall() {
134
+ return confirm({
135
+ message: "Uninstall BarnDog?",
136
+ default: false,
137
+ theme: promptTheme,
138
+ });
139
+ }
140
+ /** What the uninstall did, and the last step: removing the CLI. */
141
+ export function renderUninstall(result, runtime) {
142
+ const lines = [`${ok("✔")} BarnDog's files are gone from this machine.`, ""];
143
+ if (result.left.length) {
144
+ lines.push(bold("Left in your coding tools"));
145
+ lines.push(...table(result.left.map((asset) => [
146
+ adapters[asset.harness].name,
147
+ dim(kindLabels[asset.kind]),
148
+ bold(asset.name),
149
+ dim(displayPath(asset.path, runtime)),
150
+ ])));
151
+ lines.push("");
152
+ }
153
+ if (result.variables.length) {
154
+ lines.push(warn("Your MCP servers read these variables from your environment. Without BarnDog, keeping them set is up to you:"), ...variableRows(result.variables), "");
155
+ }
156
+ if (result.removed.length) {
157
+ lines.push(result.keptSetup
158
+ ? "Removed BarnDog's own scripts and registrations from your coding tools."
159
+ : "Removed everything BarnDog installed from your coding tools.");
160
+ }
161
+ if (result.restored.length) {
162
+ lines.push(`Put back ${result.restored.map((item) => bold(item.key)).join(", ")}.`);
163
+ }
164
+ for (const { server, revoked } of result.signedOut) {
165
+ lines.push(revoked
166
+ ? `Signed out of ${server}.`
167
+ : warn(`Signed out of ${server} here, but the server couldn't be told; that session ends when it expires.`));
168
+ }
169
+ lines.push(result.keptWorkspace
170
+ ? `Deleted ${displayPath(result.root, runtime)}, except your local workspace in ${displayPath(result.keptWorkspace, runtime)}.`
171
+ : `Deleted ${displayPath(result.root, runtime)}.`);
172
+ lines.push("", hint(REMOVE_CLI, "Next"));
173
+ return lines;
174
+ }
@@ -0,0 +1,10 @@
1
+ import { bold, dim } from "./format.js";
2
+ export function renderUpdateNotice(update) {
3
+ const install = `npm install -g barndog@${update.tag}`;
4
+ return [
5
+ "",
6
+ `A new BarnDog CLI is available: ${update.current} → ${bold(update.version)}`,
7
+ // Sync brings the registrations in each tool in line with the new version.
8
+ `${dim("Next:")} ${bold(install)}, then ${bold("barndog sync")}`,
9
+ ];
10
+ }
package/dist/version.js CHANGED
@@ -2,13 +2,13 @@ import { readFileSync } from "node:fs";
2
2
  import { z } from "zod";
3
3
  import { defaultServer } from "./config/build.js";
4
4
  /** The package version, read from package.json beside dist/ so it can't drift. */
5
- const version = z
5
+ export const cliVersion = z
6
6
  .object({ version: z.string() })
7
7
  .parse(JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"))).version;
8
8
  /** What `barndog --version` prints: enough to tell builds apart in a support report. */
9
9
  export function versionReport(platform) {
10
10
  return [
11
- `barndog ${version}`,
11
+ `barndog ${cliVersion}`,
12
12
  `Node.js ${process.version} on ${platform} ${process.arch}`,
13
13
  `Default server ${defaultServer}`,
14
14
  ].join("\n");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "barndog",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "barndog": "dist/cli.js"
@@ -1,71 +0,0 @@
1
- import { homedir } from "node:os";
2
- import crossSpawn from "cross-spawn";
3
- import { isWindows, stopProcessTree } from "../platform.js";
4
- import { mcpDefinitionSchema } from "@barndog-ai/api-contract";
5
- import { CliError } from "../errors.js";
6
- /** Allow two seconds for the MCP child to exit before forcing shutdown. */
7
- const MCP_SHUTDOWN_GRACE_MS = 2000;
8
- // This process runs only when the native harness starts a selected stdio MCP.
9
- // Definitions contain references, never credential values. No shell is involved.
10
- try {
11
- const definition = mcpDefinitionSchema.parse(JSON.parse(Buffer.from(process.argv[2] ?? "", "base64url").toString("utf8")));
12
- if (definition.transport !== "stdio") {
13
- throw new Error("A stdio configuration is required");
14
- }
15
- const runtime = {
16
- home: homedir(),
17
- cwd: process.cwd(),
18
- env: { ...process.env },
19
- platform: process.platform,
20
- };
21
- const env = { ...runtime.env };
22
- for (const [name, reference] of Object.entries(definition.environment)) {
23
- if (!runtime.env[reference.secretRef]) {
24
- throw new CliError(`${reference.secretRef} isn't set in your environment. Set it, then restart your coding tool.`);
25
- }
26
- env[name] = runtime.env[reference.secretRef];
27
- }
28
- // cross-spawn finds the command on PATH and also starts Windows .cmd shims
29
- // (such as npx) with safely quoted arguments.
30
- const child = crossSpawn(definition.command, definition.args, {
31
- env,
32
- stdio: "inherit",
33
- detached: !isWindows(runtime.platform),
34
- cwd: runtime.cwd,
35
- windowsHide: true,
36
- });
37
- for (const signal of ["SIGINT", "SIGTERM"]) {
38
- process.on(signal, () => {
39
- const { pid } = child;
40
- if (!pid) {
41
- return;
42
- }
43
- try {
44
- stopProcessTree(child, runtime, signal);
45
- const timer = setTimeout(() => {
46
- try {
47
- stopProcessTree(child, runtime);
48
- }
49
- catch {
50
- /* exited */
51
- }
52
- }, MCP_SHUTDOWN_GRACE_MS);
53
- timer.unref();
54
- }
55
- catch {
56
- /* already exited */
57
- }
58
- });
59
- }
60
- child.once("error", () => {
61
- console.error("Unable to start the configured MCP command");
62
- process.exitCode = 1;
63
- });
64
- child.once("exit", (code) => {
65
- process.exitCode = code ?? 1;
66
- });
67
- }
68
- catch (error) {
69
- console.error(error instanceof Error ? error.message : "Invalid MCP configuration.");
70
- process.exitCode = 1;
71
- }