barndog 0.2.1 → 0.2.3

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 (92) hide show
  1. package/README.md +21 -0
  2. package/dist/cli.js +29 -3
  3. package/dist/commands/add.js +4 -2
  4. package/dist/commands/asset-install.js +7 -3
  5. package/dist/commands/asset-list.js +5 -1
  6. package/dist/commands/asset-share.js +15 -3
  7. package/dist/commands/capabilities.js +23 -5
  8. package/dist/commands/collaboration.js +9 -3
  9. package/dist/commands/harnesses.js +33 -3
  10. package/dist/commands/hooks.js +16 -1
  11. package/dist/commands/mcp-env.js +159 -43
  12. package/dist/commands/mcp.js +13 -3
  13. package/dist/commands/origin.js +7 -4
  14. package/dist/commands/sets.js +16 -5
  15. package/dist/commands/status.js +3 -1
  16. package/dist/commands/sync.js +1 -1
  17. package/dist/commands/uninstall.js +64 -0
  18. package/dist/commands/workspace.js +19 -0
  19. package/dist/config/paths.js +2 -0
  20. package/dist/config/state.js +19 -0
  21. package/dist/entry/update-check.js +15 -0
  22. package/dist/errors.js +4 -0
  23. package/dist/features/adoption/adopt.js +47 -29
  24. package/dist/features/adoption/scan.js +5 -0
  25. package/dist/features/asset-kinds/url-query.js +26 -0
  26. package/dist/features/auth/session.js +22 -0
  27. package/dist/features/collaboration/workspace-store.js +2 -1
  28. package/dist/features/doctor/check.js +1 -0
  29. package/dist/features/doctor/grouped.js +127 -0
  30. package/dist/features/doctor/index.js +29 -27
  31. package/dist/features/environment/events.js +18 -1
  32. package/dist/features/environment/kept-value-events.js +40 -0
  33. package/dist/features/environment/kept-values.js +68 -0
  34. package/dist/features/environment/mcp-records.js +57 -0
  35. package/dist/features/environment/moves.js +17 -1
  36. package/dist/features/environment/stage.js +32 -28
  37. package/dist/features/environment/sync.js +13 -3
  38. package/dist/features/environment/writes.js +25 -27
  39. package/dist/features/hooks/compatibility.js +37 -17
  40. package/dist/features/hooks/test.js +2 -2
  41. package/dist/features/inventory/hook-matrix.js +14 -0
  42. package/dist/features/inventory/hook-readiness.js +47 -0
  43. package/dist/features/inventory/index.js +54 -3
  44. package/dist/features/inventory/show.js +10 -2
  45. package/dist/features/mcps/import.js +74 -21
  46. package/dist/features/mcps/index.js +28 -5
  47. package/dist/features/mcps/values.js +161 -23
  48. package/dist/features/migration/migrate.js +15 -0
  49. package/dist/features/migration/move.js +38 -9
  50. package/dist/features/migration/promote.js +1 -0
  51. package/dist/features/native/adapters.js +5 -46
  52. package/dist/features/native/hook-shell.js +11 -0
  53. package/dist/features/native/requirements.js +98 -0
  54. package/dist/features/secrets/index.js +95 -29
  55. package/dist/features/uninstall/index.js +126 -0
  56. package/dist/features/uninstall/leave.js +152 -0
  57. package/dist/features/uninstall/survey.js +103 -0
  58. package/dist/features/update-check/index.js +108 -0
  59. package/dist/features/workspace/cloud-source.js +38 -4
  60. package/dist/features/workspace/format.js +6 -1
  61. package/dist/harnesses/claude.js +1 -1
  62. package/dist/harnesses/codex.js +46 -22
  63. package/dist/harnesses/cursor.js +1 -1
  64. package/dist/harnesses/opencode.js +1 -1
  65. package/dist/harnesses/read-renamed-variables.js +141 -0
  66. package/dist/harnesses/renamed-variables.js +99 -0
  67. package/dist/platform.js +12 -1
  68. package/dist/program.js +24 -9
  69. package/dist/ui/add-hook.js +2 -2
  70. package/dist/ui/add-mcp.js +54 -16
  71. package/dist/ui/add-skills.js +2 -2
  72. package/dist/ui/adopt.js +90 -19
  73. package/dist/ui/assets.js +15 -2
  74. package/dist/ui/collaboration.js +5 -3
  75. package/dist/ui/connection.js +2 -0
  76. package/dist/ui/format.js +81 -2
  77. package/dist/ui/harness-picker.js +7 -2
  78. package/dist/ui/hook-compatibility.js +176 -22
  79. package/dist/ui/mcp.js +169 -24
  80. package/dist/ui/move.js +3 -2
  81. package/dist/ui/onboarding.js +11 -2
  82. package/dist/ui/output.js +116 -37
  83. package/dist/ui/package-details.js +7 -2
  84. package/dist/ui/pick.js +20 -6
  85. package/dist/ui/secret-input.js +9 -0
  86. package/dist/ui/selection.js +1 -1
  87. package/dist/ui/uninstall.js +186 -0
  88. package/dist/ui/update.js +10 -0
  89. package/dist/ui/variable-problems.js +23 -0
  90. package/dist/version.js +2 -2
  91. package/package.json +2 -2
  92. package/dist/entry/mcp-launch.js +0 -71
package/dist/ui/output.js CHANGED
@@ -5,9 +5,11 @@ 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 { keptValuesMessage, } from "../features/environment/events.js";
9
+ import { variableProblemLines } from "./variable-problems.js";
8
10
  import { adapters, isHarness } from "../harnesses/registry.js";
9
11
  import { primary, danger } from "./theme.js";
10
- import { bad, bold, dim, heading, hint, json, ok, table, warn, } from "./format.js";
12
+ import { bad, bold, dim, heading, hint, json, ok, plural, table, warn, } from "./format.js";
11
13
  import { ApiError } from "@barndog-ai/api-contract";
12
14
  import { CliError, friendlyHint, friendlyMessage } from "../errors.js";
13
15
  import { assetKinds } from "../features/asset-kinds/index.js";
@@ -30,9 +32,41 @@ const marks = {
30
32
  updated: (text) => primary(`~ ${text}`),
31
33
  removed: (text) => bad(`- ${text}`),
32
34
  unchanged: (text) => dim(` ${text}`),
33
- unsupported: (text) => warn(`! ${text}`),
34
35
  skipped: (text) => warn(`! ${text}`),
35
36
  };
37
+ /** A Hook skipped in one tool, as a Note cell: `Codex: no implementation`. */
38
+ function skipNote(event) {
39
+ const words = {
40
+ "no-implementation": "no implementation",
41
+ "no-command-hooks": "no command hooks",
42
+ "missing-requirement": "missing requirement",
43
+ };
44
+ return `${adapters[event.harness].name}: ${words[event.cause.type]}`;
45
+ }
46
+ /**
47
+ * Where each newly installed Hook isn't, so a developer learns it when the
48
+ * Hook arrives rather than on every sync.
49
+ */
50
+ function installNotes(events, rows) {
51
+ const skipped = events.filter((event) => event.type === "unsupported");
52
+ for (const row of rows) {
53
+ if (row.action !== "installed" || row.kind !== "hook") {
54
+ continue;
55
+ }
56
+ const notes = skipped
57
+ .filter((event) => event.name === row.name)
58
+ .map(skipNote);
59
+ if (notes.length) {
60
+ row.note = `Not in ${notes.join(", ")}`;
61
+ }
62
+ }
63
+ }
64
+ /** Hooks with an implementation for a tool that this machine can't run. */
65
+ function cantRun(events) {
66
+ return new Set(events.flatMap((event) => event.type === "unsupported" && event.cause.type === "missing-requirement"
67
+ ? [event.name]
68
+ : []));
69
+ }
36
70
  /** BarnDog's own entries in each tool's configuration, not assets the user manages. */
37
71
  const internalKinds = new Set(["knowledge", "sync"]);
38
72
  function rows(events) {
@@ -53,8 +87,11 @@ function rows(events) {
53
87
  };
54
88
  for (const event of events) {
55
89
  if (event.type === "disabled" ||
90
+ event.type === "unsupported" ||
56
91
  event.type === "notice" ||
57
- event.type === "unset-variable") {
92
+ event.type === "kept-values" ||
93
+ event.type === "unset-variable" ||
94
+ event.type === "unassigned-value") {
58
95
  continue;
59
96
  }
60
97
  if (event.type === "invalid") {
@@ -70,16 +107,7 @@ function rows(events) {
70
107
  action: "skipped",
71
108
  kind: event.kind,
72
109
  name: event.skipped.name,
73
- note: `${event.skipped.origin} · name taken by ${event.installed.origin}`,
74
- });
75
- }
76
- else if (event.type === "unsupported") {
77
- add({
78
- action: "unsupported",
79
- kind: event.kind,
80
- name: event.name,
81
- harness: event.harness,
82
- note: event.reason,
110
+ note: `${event.skipped.origin}: name taken by ${event.installed.origin}`,
83
111
  });
84
112
  }
85
113
  else if (event.type === "native") {
@@ -104,18 +132,48 @@ function rows(events) {
104
132
  "updated",
105
133
  "removed",
106
134
  "skipped",
107
- "unsupported",
108
135
  "unchanged",
109
136
  ];
110
- return [...byKey.values()].sort((a, b) => order.indexOf(a.action) - order.indexOf(b.action) ||
137
+ const sorted = [...byKey.values()].sort((a, b) => order.indexOf(a.action) - order.indexOf(b.action) ||
111
138
  a.kind.localeCompare(b.kind) ||
112
139
  a.name.localeCompare(b.name));
140
+ installNotes(events, sorted);
141
+ return sorted;
142
+ }
143
+ /** The table of changed assets and a blank line after it; nothing when there are none. */
144
+ function rowLines(shown) {
145
+ if (!shown.length) {
146
+ return [];
147
+ }
148
+ // A clash or invalid asset names no tool; without a Tools cell in any row the column goes.
149
+ const withTools = shown.some((row) => row.harnesses.size > 0);
150
+ return [
151
+ ...table(shown.map((row) => [
152
+ marks[row.action](row.action),
153
+ dim(row.kind),
154
+ bold(row.name),
155
+ ...(withTools ? [dim([...row.harnesses].join(", "))] : []),
156
+ row.action === "installed" ? dim(row.note ?? "") : (row.note ?? ""),
157
+ ])),
158
+ "",
159
+ ];
160
+ }
161
+ /** One warning for every Hook that can't run, with doctor for the details. */
162
+ function cantRunLines(hooks) {
163
+ if (!hooks) {
164
+ return [];
165
+ }
166
+ return [
167
+ "",
168
+ `${warn("!")} ${plural(hooks, "Hook")} can't run in a tool ${hooks === 1 ? "it's" : "they're"} written for.`,
169
+ ` ${hint("barndog doctor", "Tip")}${dim(" to see which and why")}`,
170
+ ];
113
171
  }
114
172
  /**
115
173
  * Returns terminal lines for synchronization events, with optional verbose
116
174
  * detail or preview wording.
117
175
  */
118
- export function renderSyncOutput(events, options = {}) {
176
+ export function renderSyncOutput(events, runtime, options = {}) {
119
177
  const all = rows(events);
120
178
  const assets = all.filter((row) => !internalKinds.has(row.kind));
121
179
  const shown = options.verbose
@@ -124,27 +182,22 @@ export function renderSyncOutput(events, options = {}) {
124
182
  const count = (action) => assets.filter((row) => row.action === action).length;
125
183
  // Internal entries stay out of the counts, but a change to one still needs a restart.
126
184
  const changed = all.some((row) => ["installed", "updated", "removed"].includes(row.action));
127
- // Something was left out or read from an old copy, so "up to date" would be untrue.
128
- const incomplete = count("skipped") > 0 || events.some((event) => event.type === "notice");
185
+ const broken = cantRun(events);
186
+ // Something was left out, read from an old copy or can't run yet, so "up to date" would be untrue.
187
+ const incomplete = count("skipped") > 0 ||
188
+ broken.size > 0 ||
189
+ events.some((event) => problemTypes.has(event.type));
129
190
  const quiet = incomplete
130
191
  ? dim("Nothing else changed.")
131
192
  : dim("Everything is up to date.");
132
193
  const summary = [
133
194
  ...["installed", "updated", "removed", "unchanged"].flatMap((action) => (count(action) ? [`${count(action)} ${action}`] : [])),
134
195
  ...(count("skipped") ? [`${count("skipped")} skipped`] : []),
135
- ...(count("unsupported") ? [`${count("unsupported")} unsupported`] : []),
136
196
  ].join(", ");
137
- const output = [`\n${heading(options.title ?? "sync")}\n`];
138
- if (shown.length) {
139
- output.push(...table(shown.map((row) => [
140
- marks[row.action](row.action),
141
- dim(row.kind),
142
- bold(row.name),
143
- row.note
144
- ? `${[...row.harnesses].join(", ")}${row.harnesses.size ? " · " : ""}${row.note}`
145
- : dim([...row.harnesses].join(", ")),
146
- ])), "");
147
- }
197
+ const output = [
198
+ `\n${heading(options.title ?? "sync")}\n`,
199
+ ...rowLines(shown),
200
+ ];
148
201
  output.push(`${incomplete ? warn("!") : ok("✔")} ${options.preview ? "Preview" : "Sync complete"}${summary ? ` · ${summary}` : ""}`);
149
202
  if (options.preview) {
150
203
  output.push(changed
@@ -153,20 +206,46 @@ export function renderSyncOutput(events, options = {}) {
153
206
  }
154
207
  else {
155
208
  output.push(changed
156
- ? dim("Restart your coding tools to pick up the changes.")
209
+ ? dim("A restart of your coding tools may be required to pick up the changes.")
157
210
  : quiet);
158
211
  }
212
+ output.push(...cantRunLines(broken.size));
159
213
  for (const event of events) {
160
- if (event.type === "notice") {
161
- output.push("", `${warn("!")} ${event.message}`);
162
- }
163
- else if (event.type === "clash") {
164
- 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")}`);
165
- }
214
+ output.push(...problemLines(event, runtime));
166
215
  }
216
+ output.push(...variableProblemLines(events));
167
217
  output.push("");
168
218
  return output;
169
219
  }
220
+ /** The settings files a `kept-values` event names, one per line under its sentence. */
221
+ export const keptValueFiles = (event, runtime) => event.files.map((file) => dim(` ${displayPath(file, runtime)}`));
222
+ /** Events that mean the installation isn't fully working yet. */
223
+ const problemTypes = new Set([
224
+ "notice",
225
+ "unset-variable",
226
+ "unassigned-value",
227
+ ]);
228
+ /** What a sync event asks the developer to look at, after the summary; nothing for the rest. */
229
+ function problemLines(event, runtime) {
230
+ if (event.type === "notice") {
231
+ return ["", `${warn("!")} ${event.message}`];
232
+ }
233
+ if (event.type === "kept-values") {
234
+ return [
235
+ "",
236
+ `${warn("!")} ${keptValuesMessage(event)}`,
237
+ ...keptValueFiles(event, runtime),
238
+ ];
239
+ }
240
+ if (event.type === "clash") {
241
+ return [
242
+ "",
243
+ `${warn("!")} ${assetKinds[event.kind].one} ${bold(event.skipped.name)} from ${event.skipped.origin} was skipped: ${event.installed.origin} already installs one with that name.`,
244
+ ` ${hint(`barndog ${assetKinds[event.kind].command} rename ${event.skipped.name} --origin ${event.skipped.origin} --as ${event.skipped.rename}`, "Fix")}`,
245
+ ];
246
+ }
247
+ return [];
248
+ }
170
249
  function describeError(error) {
171
250
  if (error instanceof LoginRequiredError) {
172
251
  return { message: "You're not signed in.", fix: "barndog login" };
@@ -1,6 +1,8 @@
1
1
  import { adapters, hookHarnesses } from "../harnesses/registry.js";
2
2
  import { SHORT_COMMIT_LENGTH } from "../shared/constants.js";
3
3
  import { bold, clean, dim, fields } from "./format.js";
4
+ import { stateBadge } from "./assets.js";
5
+ import { renderHookTools } from "./hook-compatibility.js";
4
6
  /** `skills show` and `hooks show`: what the asset is and where this machine has it. */
5
7
  export function renderPackageDetails(details) {
6
8
  const { installed } = details;
@@ -18,13 +20,16 @@ export function renderPackageDetails(details) {
18
20
  : details.version.slice(0, SHORT_COMMIT_LENGTH),
19
21
  ],
20
22
  ["Description", clean(details.description)],
21
- ["State", installed?.state ?? dim("not installed")],
23
+ ["State", installed ? stateBadge(installed.state) : dim("not installed")],
22
24
  [
23
25
  "Installed in",
24
26
  installed?.harnesses.map((harness) => adapters[harness].name).join(", "),
25
27
  ],
26
28
  ]);
27
- if (details.kind === "hook") {
29
+ if (details.compatibility) {
30
+ output.push("", ...renderHookTools(details.name, details.compatibility));
31
+ }
32
+ else if (details.kind === "hook") {
28
33
  output.push("", dim("Events"), ...(events.length ? events : [dim("No coding tool runs it.")]).map((line) => ` ${line}`));
29
34
  }
30
35
  if (installed?.paths.length) {
package/dist/ui/pick.js CHANGED
@@ -1,9 +1,10 @@
1
1
  import { createPrompt, isDownKey, isEnterKey, isSpaceKey, isTabKey, isUpKey, makeTheme, useKeypress, useMemo, usePagination, usePrefix, useState, } from "@inquirer/core";
2
2
  import { cursorHide } from "@inquirer/ansi";
3
- import { styleText } from "node:util";
3
+ import { stripVTControlCharacters, styleText } from "node:util";
4
4
  import { NothingToDoError } from "../errors.js";
5
5
  import { promptTheme, selected } from "./theme.js";
6
6
  import { defined } from "../shared/lookup.js";
7
+ import { pad, truncate, visibleWidth } from "./format.js";
7
8
  /** Cap names to leave room for hints in the picker. */
8
9
  const MAX_CHOICE_NAME_WIDTH = 40;
9
10
  /** Show ten choices before scrolling by default. */
@@ -15,7 +16,7 @@ const PICKER_ROW_CHROME_WIDTH = 4;
15
16
  /** Only show a hint when at least four columns remain. */
16
17
  const MIN_HINT_ROOM = 3;
17
18
  const matches = (choice, search) => {
18
- const text = `${choice.name} ${choice.hint ?? ""}`.toLowerCase();
19
+ const text = stripVTControlCharacters([choice.name, ...(choice.columns ?? [])].join(" ")).toLowerCase();
19
20
  return search
20
21
  .toLowerCase()
21
22
  .split(/\s+/)
@@ -31,6 +32,16 @@ const prompt = createPrompt((config, done) => {
31
32
  const [active, setActive] = useState(0);
32
33
  const [error, setError] = useState();
33
34
  const nameWidth = useMemo(() => Math.min(MAX_CHOICE_NAME_WIDTH, Math.max(0, ...config.choices.map((choice) => choice.name.length))), []);
35
+ // Measured over every choice, so columns stay put while the list filters.
36
+ const columnWidths = useMemo(() => {
37
+ const widths = [];
38
+ for (const choice of config.choices) {
39
+ (choice.columns ?? []).forEach((cell, index) => {
40
+ widths[index] = Math.max(widths[index] ?? 0, visibleWidth(cell));
41
+ });
42
+ }
43
+ return widths;
44
+ }, []);
34
45
  const visible = useMemo(() => config.choices
35
46
  .map((choice, index) => ({ choice, index }))
36
47
  .filter(({ choice }) => matches(choice, search)), [search]);
@@ -119,10 +130,13 @@ const prompt = createPrompt((config, done) => {
119
130
  box.length -
120
131
  nameWidth -
121
132
  2;
122
- const text = item.choice.hint ?? "";
123
- const hint = text && room > MIN_HINT_ROOM
124
- ? ` ${styleText("dim", text.length > room ? `${text.slice(0, room - 1)}…` : text)}`
125
- : "";
133
+ const cells = item.choice.columns ?? [];
134
+ const text = cells
135
+ .map((cell, index) => index === cells.length - 1
136
+ ? cell
137
+ : pad(cell, columnWidths[index] ?? 0))
138
+ .join(" ");
139
+ const hint = text && room > MIN_HINT_ROOM ? ` ${truncate(text, room)}` : "";
126
140
  return `${cursor} ${box}${name}${hint}`;
127
141
  },
128
142
  })
@@ -1,4 +1,5 @@
1
1
  /** Reads an MCP variable's value without showing it or putting it in shell history. */
2
+ import confirm from "@inquirer/confirm";
2
3
  import input from "@inquirer/input";
3
4
  import { promptTheme } from "./theme.js";
4
5
  /** Asks in the terminal, echoing one `*` per character. */
@@ -17,3 +18,11 @@ export async function readStdin(stream = process.stdin) {
17
18
  }
18
19
  return text.replace(/\r?\n$/, "");
19
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
+ }
@@ -15,7 +15,7 @@ export async function runSelection(context, change) {
15
15
  context.write(json(result));
16
16
  return;
17
17
  }
18
- for (const line of renderSyncOutput(result.events)) {
18
+ for (const line of renderSyncOutput(result.events, context.runtime)) {
19
19
  context.write(line);
20
20
  }
21
21
  return;
@@ -0,0 +1,186 @@
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, checklistPageSize, 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
+ /**
35
+ * Whether there is anything of the developer's to leave or remove. With none,
36
+ * there's no choice to make: uninstall only removes BarnDog's own files.
37
+ */
38
+ export const hasAssets = (survey) => survey.installed.length > 0 || survey.adopted.length > 0;
39
+ /** Options from the command line alone, for runs that can't prompt. */
40
+ export function uninstallOptions(survey, choices) {
41
+ return {
42
+ keepSetup: choices.keepSetup,
43
+ restore: choices.keepSetup || choices.dropAdopted
44
+ ? []
45
+ : survey.adopted.map((item) => item.key),
46
+ keepWorkspace: !choices.removeWorkspace,
47
+ force: choices.force,
48
+ };
49
+ }
50
+ const chooseRestored = (adopted) => checkbox({
51
+ loop: false,
52
+ message: "Put these adopted assets back where they were? Unchecked ones are deleted.",
53
+ pageSize: checklistPageSize(adopted.length + harnesses.length),
54
+ choices: harnesses.flatMap((harness) => {
55
+ const mine = adopted.filter((item) => item.harness === harness);
56
+ return mine.length
57
+ ? [
58
+ new Separator(bold(adapters[harness].name)),
59
+ ...mine.map((item) => ({
60
+ value: item.key,
61
+ checked: true,
62
+ short: item.key,
63
+ name: `${kindLabels[item.kind].padEnd(kindWidth)} ${item.name}`,
64
+ })),
65
+ ]
66
+ : [];
67
+ }),
68
+ theme: checkboxTheme,
69
+ });
70
+ /** Asks for each choice the command line left open. */
71
+ export async function askUninstall(survey, choices, runtime) {
72
+ const keepSetup = choices.keepSetup ??
73
+ (await select({
74
+ loop: false,
75
+ message: survey.installed.length
76
+ ? `What should happen to the ${counts(survey.installed)} BarnDog installed?`
77
+ : "What should happen to what BarnDog installed?",
78
+ choices: [
79
+ {
80
+ name: "Leave them in my coding tools",
81
+ value: true,
82
+ description: "Skills and Hooks become plain folders in each tool; MCP servers stay as they are.",
83
+ },
84
+ {
85
+ name: "Remove them",
86
+ value: false,
87
+ description: "Adopted assets can go back where they came from.",
88
+ },
89
+ ],
90
+ theme: promptTheme,
91
+ }));
92
+ const restore = keepSetup || choices.dropAdopted || !survey.adopted.length
93
+ ? []
94
+ : await chooseRestored(survey.adopted);
95
+ const workspace = survey.workspace;
96
+ const keepWorkspace = !choices.removeWorkspace &&
97
+ (!workspace ||
98
+ (await confirm({
99
+ message: `Keep your local workspace folder, ${displayPath(workspace, runtime)}?`,
100
+ default: true,
101
+ theme: promptTheme,
102
+ })));
103
+ return { keepSetup, restore, keepWorkspace, force: choices.force };
104
+ }
105
+ /** What uninstalling with `options` will do. */
106
+ export function renderUninstallPlan(survey, options, runtime) {
107
+ const root = displayPath(survey.root, runtime);
108
+ const lines = hasAssets(survey)
109
+ ? []
110
+ : [
111
+ "BarnDog installed no Skills, MCP servers or Hooks in your coding tools, so there's nothing of yours to keep or remove.",
112
+ "",
113
+ ];
114
+ lines.push(bold("BarnDog will"));
115
+ const step = (text) => lines.push(`${STEP}${text}`);
116
+ if (survey.installed.length) {
117
+ step(options.keepSetup
118
+ ? `leave ${counts(survey.installed)} in your coding tools, as plain files of their own`
119
+ : `remove ${counts(survey.installed)} from your coding tools`);
120
+ }
121
+ if (options.keepSetup && survey.variables.length) {
122
+ step(warn("leave it to you to keep these variables set; your MCP servers read them from your environment:"));
123
+ lines.push(...variableRows(survey.variables, STEP.length));
124
+ }
125
+ step("remove its own scripts and registrations from your tools");
126
+ const restored = survey.adopted.filter((item) => options.restore.includes(item.key));
127
+ const dropped = options.keepSetup
128
+ ? []
129
+ : survey.adopted.filter((item) => !options.restore.includes(item.key));
130
+ if (restored.length) {
131
+ step(`put back ${plural(restored.length, "adopted asset")} where ${restored.length === 1 ? "it" : "they"} came from`);
132
+ }
133
+ if (dropped.length) {
134
+ step(warn(`delete ${plural(dropped.length, "adopted asset")} for good: ${dropped.map((item) => item.key).join(", ")}`));
135
+ }
136
+ if (survey.servers.length) {
137
+ step(`sign out of ${survey.servers.join(", ")}`);
138
+ }
139
+ const workspace = survey.workspace;
140
+ step(workspace && options.keepWorkspace
141
+ ? `delete ${root}, except your local workspace in ${displayPath(workspace, runtime)}`
142
+ : `delete ${root}`);
143
+ return lines;
144
+ }
145
+ export function confirmUninstall() {
146
+ return confirm({
147
+ message: "Uninstall BarnDog?",
148
+ default: false,
149
+ theme: promptTheme,
150
+ });
151
+ }
152
+ /** What the uninstall did, and the last step: removing the CLI. */
153
+ export function renderUninstall(result, runtime) {
154
+ const lines = [`${ok("✔")} BarnDog's files are gone from this machine.`, ""];
155
+ if (result.left.length) {
156
+ lines.push(bold("Left in your coding tools"));
157
+ lines.push(...table(result.left.map((asset) => [
158
+ adapters[asset.harness].name,
159
+ dim(kindLabels[asset.kind]),
160
+ bold(asset.name),
161
+ dim(displayPath(asset.path, runtime)),
162
+ ])));
163
+ lines.push("");
164
+ }
165
+ if (result.variables.length) {
166
+ lines.push(warn("Your MCP servers read these variables from your environment. Without BarnDog, keeping them set is up to you:"), ...variableRows(result.variables), "");
167
+ }
168
+ if (result.removed.length) {
169
+ lines.push(result.keptSetup
170
+ ? "Removed BarnDog's own scripts and registrations from your coding tools."
171
+ : "Removed everything BarnDog installed from your coding tools.");
172
+ }
173
+ if (result.restored.length) {
174
+ lines.push(`Put back ${result.restored.map((item) => bold(item.key)).join(", ")}.`);
175
+ }
176
+ for (const { server, revoked } of result.signedOut) {
177
+ lines.push(revoked
178
+ ? `Signed out of ${server}.`
179
+ : warn(`Signed out of ${server} here, but the server couldn't be told; that session ends when it expires.`));
180
+ }
181
+ lines.push(result.keptWorkspace
182
+ ? `Deleted ${displayPath(result.root, runtime)}, except your local workspace in ${displayPath(result.keptWorkspace, runtime)}.`
183
+ : `Deleted ${displayPath(result.root, runtime)}.`);
184
+ lines.push("", hint(REMOVE_CLI, "Next"));
185
+ return lines;
186
+ }
@@ -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
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * The MCP variables a sync found with no value, grouped the way `doctor`
3
+ * groups them: one warning for several variables, listed by server, with one
4
+ * fix, rather than a warning and a fix per variable.
5
+ */
6
+ import { variableChecks } from "../features/doctor/grouped.js";
7
+ import { hint, labelledLists, warn } from "./format.js";
8
+ /** Lines under a warning start where its text does. */
9
+ const UNDER = " ";
10
+ /**
11
+ * `listed` names variables the caller has already shown, such as the literal
12
+ * values `mcp add` and `adopt` left for the developer to set; they're left out.
13
+ */
14
+ export function variableProblemLines(events, listed = []) {
15
+ const unlisted = events.filter((event) => event.type !== "unset-variable" ||
16
+ !listed.some((value) => value.server === event.server && value.variable === event.variable));
17
+ return variableChecks(unlisted).flatMap((check) => [
18
+ "",
19
+ `${warn("!")} ${check.detail}`,
20
+ ...labelledLists(check.rows ?? [], { indent: UNDER.length + 2 }),
21
+ ...(check.fix ? [`${UNDER}${hint(check.fix, "Fix")}`] : []),
22
+ ]);
23
+ }
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.1",
3
+ "version": "0.2.3",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "barndog": "dist/cli.js"
@@ -24,7 +24,7 @@
24
24
  "test:watch": "vitest"
25
25
  },
26
26
  "dependencies": {
27
- "@barndog-ai/api-contract": "^0.1.0",
27
+ "@barndog-ai/api-contract": "^0.3.0",
28
28
  "@inquirer/ansi": "^2.0.10",
29
29
  "@inquirer/checkbox": "^5.2.7",
30
30
  "@inquirer/confirm": "^6.3.4",
@@ -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
- }