barndog 0.2.1 → 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 (53) hide show
  1. package/README.md +19 -0
  2. package/dist/cli.js +27 -1
  3. package/dist/commands/asset-list.js +5 -1
  4. package/dist/commands/harnesses.js +32 -2
  5. package/dist/commands/mcp-env.js +130 -41
  6. package/dist/commands/sets.js +13 -2
  7. package/dist/commands/uninstall.js +62 -0
  8. package/dist/config/paths.js +2 -0
  9. package/dist/entry/update-check.js +15 -0
  10. package/dist/features/adoption/adopt.js +31 -30
  11. package/dist/features/auth/session.js +22 -0
  12. package/dist/features/collaboration/workspace-store.js +2 -1
  13. package/dist/features/doctor/index.js +25 -8
  14. package/dist/features/environment/events.js +8 -1
  15. package/dist/features/environment/kept-values.js +68 -0
  16. package/dist/features/environment/moves.js +17 -1
  17. package/dist/features/environment/stage.js +20 -20
  18. package/dist/features/environment/sync.js +2 -2
  19. package/dist/features/inventory/index.js +45 -2
  20. package/dist/features/mcps/import.js +36 -15
  21. package/dist/features/mcps/index.js +12 -2
  22. package/dist/features/mcps/values.js +108 -20
  23. package/dist/features/migration/migrate.js +15 -0
  24. package/dist/features/migration/move.js +34 -9
  25. package/dist/features/native/adapters.js +1 -2
  26. package/dist/features/native/hook-shell.js +11 -0
  27. package/dist/features/secrets/index.js +94 -29
  28. package/dist/features/uninstall/index.js +126 -0
  29. package/dist/features/uninstall/leave.js +152 -0
  30. package/dist/features/uninstall/survey.js +103 -0
  31. package/dist/features/update-check/index.js +108 -0
  32. package/dist/features/workspace/format.js +6 -1
  33. package/dist/harnesses/claude.js +1 -1
  34. package/dist/harnesses/codex.js +46 -22
  35. package/dist/harnesses/cursor.js +1 -1
  36. package/dist/harnesses/opencode.js +1 -1
  37. package/dist/harnesses/read-renamed-variables.js +141 -0
  38. package/dist/harnesses/renamed-variables.js +99 -0
  39. package/dist/platform.js +12 -1
  40. package/dist/program.js +21 -9
  41. package/dist/ui/add-mcp.js +22 -16
  42. package/dist/ui/adopt.js +11 -6
  43. package/dist/ui/connection.js +2 -0
  44. package/dist/ui/harness-picker.js +7 -2
  45. package/dist/ui/mcp.js +89 -23
  46. package/dist/ui/move.js +2 -1
  47. package/dist/ui/output.js +33 -8
  48. package/dist/ui/secret-input.js +9 -0
  49. package/dist/ui/uninstall.js +174 -0
  50. package/dist/ui/update.js +10 -0
  51. package/dist/version.js +2 -2
  52. package/package.json +1 -1
  53. package/dist/entry/mcp-launch.js +0 -71
package/dist/program.js CHANGED
@@ -1,6 +1,6 @@
1
- import { resolve } from "node:path";
2
1
  import { Command, Help, Option } from "commander";
3
2
  import { homedir } from "node:os";
3
+ import { pathsFor } from "./platform.js";
4
4
  import { styleText } from "node:util";
5
5
  import { registerCollaboration, registerWorkingCopy, } from "./commands/collaboration.js";
6
6
  import { applySuggestion, changeDiff, commentOnChange, createPackage, diffVersions, listChanges, mergeChange, packageVersions, pullPackage, pushWorkingCopy, rejectChange, resolveFile, reviewChange, setDiscussionResolved, showChange, updateWorkingCopy, versionFiles, workingDiff, workingStatus, } from "./features/collaboration/index.js";
@@ -40,6 +40,9 @@ import { registerEnvironment } from "./commands/environment.js";
40
40
  import { registerCapabilities } from "./commands/capabilities.js";
41
41
  import { registerWorkspace } from "./commands/workspace.js";
42
42
  import { registerAdopt } from "./commands/adopt.js";
43
+ import { registerUninstall } from "./commands/uninstall.js";
44
+ import { uninstall } from "./features/uninstall/index.js";
45
+ import { uninstallSurvey } from "./features/uninstall/survey.js";
43
46
  import { registerAdd } from "./commands/add.js";
44
47
  import { commandNeeds, modeName, needText, unavailableNote, } from "./commands/availability.js";
45
48
  import { runSetup } from "./ui/onboarding.js";
@@ -50,7 +53,7 @@ import { versionReport } from "./version.js";
50
53
  import { defined } from "./shared/lookup.js";
51
54
  import { barndogPaths } from "./config/paths.js";
52
55
  import { showPackage } from "./features/inventory/show.js";
53
- import { forgetMcpValue, keepMcpValue, listKeptValues, } from "./features/mcps/values.js";
56
+ import { assignKeptValue, forgetMcpValue, forgetUnassignedValue, keepMcpValue, listKeptValues, } from "./features/mcps/values.js";
54
57
  import { readSettings } from "./config/settings.js";
55
58
  /** Keep command help readable at the conventional eighty-column terminal width. */
56
59
  const HELP_WIDTH = 80;
@@ -69,6 +72,7 @@ const groups = [
69
72
  "doctor",
70
73
  "harnesses",
71
74
  "adopt",
75
+ "uninstall",
72
76
  ],
73
77
  ],
74
78
  ["Assets:", ["skills", "mcp", "hooks", "sets", "knowledge"]],
@@ -230,12 +234,15 @@ function guardRequiredOptions(parent, guard) {
230
234
  }
231
235
  /** Process entry points capture ambient inputs here; downstream code receives this object. */
232
236
  export function captureRuntime(options = {}) {
233
- const cwd = resolve(options.cwd ?? process.cwd());
237
+ // Resolved by the platform's own rules, so a test can run as another OS.
238
+ const platform = options.platform ?? process.platform;
239
+ const paths = pathsFor(platform);
240
+ const cwd = paths.resolve(options.cwd ?? process.cwd());
234
241
  return {
235
- home: resolve(cwd, options.home ?? homedir()),
242
+ home: paths.resolve(cwd, options.home ?? homedir()),
236
243
  cwd,
237
244
  env: { ...(options.env ?? process.env) },
238
- platform: options.platform ?? process.platform,
245
+ platform,
239
246
  };
240
247
  }
241
248
  /** Construct a fresh parser for every invocation or test; command behavior is independently injectable. */
@@ -312,6 +319,8 @@ export function createProgram(options = {}) {
312
319
  workspaceUrl: options.workspaceUrl ?? (() => workspaceUrl(runtime)),
313
320
  repoStatus: options.repoStatus ?? (() => repoStatus(runtime)),
314
321
  scanNative: options.scanNative ?? (() => scanNative(runtime)),
322
+ uninstallSurvey: options.uninstallSurvey ?? (() => uninstallSurvey(runtime)),
323
+ uninstall: options.uninstall ?? ((choices) => uninstall(choices, runtime)),
315
324
  adoptNative: options.adoptNative ?? ((keys, keep) => adoptNative(keys, keep, runtime)),
316
325
  listAdoptions: options.listAdoptions ?? (() => listAdoptions(home)),
317
326
  undoAdoption: options.undoAdoption ?? ((target) => undoAdoption(target, runtime)),
@@ -328,9 +337,11 @@ export function createProgram(options = {}) {
328
337
  updateImported: options.updateImported ??
329
338
  ((kind, name, options) => updateImported(kind, name, options, runtime)),
330
339
  keepMcpValue: options.keepMcpValue ??
331
- ((variable, value) => keepMcpValue(variable, value, runtime)),
332
- forgetMcpValue: options.forgetMcpValue ??
333
- ((variable) => forgetMcpValue(variable, runtime)),
340
+ ((target, kept) => keepMcpValue(target, kept, runtime)),
341
+ assignKeptValue: options.assignKeptValue ?? ((target) => assignKeptValue(target, runtime)),
342
+ forgetMcpValue: options.forgetMcpValue ?? ((target) => forgetMcpValue(target, runtime)),
343
+ forgetUnassignedValue: options.forgetUnassignedValue ??
344
+ ((variable) => forgetUnassignedValue(variable, runtime)),
334
345
  listKeptValues: options.listKeptValues ?? (() => listKeptValues(runtime)),
335
346
  showPackage: options.showPackage ??
336
347
  ((kind, name, origin) => showPackage(kind, name, origin, runtime)),
@@ -386,7 +397,7 @@ export function createProgram(options = {}) {
386
397
  knowledgeList: options.knowledgeList ?? ((always) => knowledgeList(always, runtime)),
387
398
  synchronize: options.synchronize ??
388
399
  ((path, syncOptions) => synchronize(path, runtime, undefined, syncOptions)),
389
- inventory: options.inventory ?? (() => inventory(runtime)),
400
+ inventory: options.inventory ?? ((choice) => inventory(runtime, choice)),
390
401
  searchCatalog: options.searchCatalog ?? ((kind) => searchCatalog(kind, runtime)),
391
402
  write,
392
403
  mode,
@@ -453,6 +464,7 @@ export function createProgram(options = {}) {
453
464
  registerSync(program, context);
454
465
  registerHarnesses(program, context);
455
466
  registerAdopt(program, context);
467
+ registerUninstall(program, context);
456
468
  registerStatus(program, context);
457
469
  registerEnvironment(program, context);
458
470
  registerCapabilities(program, context);
@@ -7,6 +7,7 @@ import { addMcpServers, conflictingEntries, convertServer, harnessServers, local
7
7
  import { assetKinds } from "../features/asset-kinds/index.js";
8
8
  import { validMcpName } from "../shared/patterns.js";
9
9
  import { bold, dim, ok, warn } from "./format.js";
10
+ import { renderMcpValues } from "./mcp.js";
10
11
  async function serversToAdd(name, options, context) {
11
12
  if (options.config) {
12
13
  return parseMcpText(options.config, name);
@@ -67,12 +68,18 @@ async function chooseKept(found, context) {
67
68
  return [];
68
69
  }
69
70
  context.write(dim("BarnDog can keep these values in ~/.barndog/secrets.json, which only you can read and which is never uploaded, and write them into your coding tools' settings. Leave one unticked to set it yourself."));
70
- return context.prompts.chooseMany("Which values should BarnDog keep on this machine?", found.map(({ server, literal }) => ({
71
+ const picked = await context.prompts.chooseMany("Which values should BarnDog keep on this machine?", found.map(({ server, literal }, index) => ({
71
72
  name: `${literal.variable} ${dim(`${server}: ${literal.key}`)}`,
72
73
  short: literal.variable,
73
- value: literal.variable,
74
+ value: String(index),
74
75
  checked: true,
75
76
  })));
77
+ return picked.flatMap((index) => {
78
+ const choice = found[Number(index)];
79
+ return choice
80
+ ? [{ server: choice.server, variable: choice.literal.variable }]
81
+ : [];
82
+ });
76
83
  }
77
84
  /** Why a server can't be added under `name` here, or null when it can. */
78
85
  async function nameProblem(name, context) {
@@ -152,19 +159,18 @@ export async function addMcp(name, options, context) {
152
159
  }
153
160
  const keep = await chooseKept(servers.flatMap((server) => server.literals.map((literal) => ({ server: server.name, literal }))), context);
154
161
  const result = await addMcpServers(servers, { replace, keep }, context.runtime);
155
- for (const added of result.added) {
156
- context.write(`${ok("✔")} Added ${bold(added)}`);
157
- }
158
- for (const note of result.notes) {
159
- context.write(`${warn("!")} ${bold(note.server)}: ${note.text}`);
160
- }
161
- // Sync says where each kept value was written.
162
- result.events.forEach((event) => {
163
- if (event.type === "notice") {
164
- context.write(dim(event.message));
165
- }
166
- });
167
- for (const backup of result.backups) {
168
- context.write(dim(`Backup: ${backup}`));
162
+ for (const line of renderAddedServers(result)) {
163
+ context.write(line);
169
164
  }
170
165
  }
166
+ /** What `mcp add` added, what's left to do, and where it backed up settings. */
167
+ function renderAddedServers(result) {
168
+ return [
169
+ ...result.added.map((added) => `${ok("✔")} Added ${bold(added)}`),
170
+ ...result.notes.map((note) => `${warn("!")} ${bold(note.server)}: ${note.text}`),
171
+ ...renderMcpValues(result.values),
172
+ // Sync says where each kept value was written.
173
+ ...result.events.flatMap((event) => event.type === "notice" ? [dim(event.message)] : []),
174
+ ...result.backups.map((backup) => dim(`Backup: ${backup}`)),
175
+ ];
176
+ }
package/dist/ui/adopt.js CHANGED
@@ -6,6 +6,7 @@ import { friendlyMessage } from "../errors.js";
6
6
  import { harnesses, adapters } from "../harnesses/registry.js";
7
7
  import { bold, dim, heading, hint, ok, plural, table, warn } from "./format.js";
8
8
  import { displayPath } from "./output.js";
9
+ import { renderMcpValues } from "./mcp.js";
9
10
  import { checkboxTheme, promptTheme } from "./theme.js";
10
11
  const kindLabels = {
11
12
  skill: "Skill",
@@ -29,12 +30,14 @@ const byTool = (items) => harnesses.flatMap((harness) => {
29
30
  });
30
31
  /** What a scan found, one section per coding tool. */
31
32
  export function renderScan(scan, runtime) {
32
- if (!scan.assets.length && !scan.skipped.length) {
33
- return [
34
- dim("Your coding tools have no Skills, MCP servers or Hooks that BarnDog doesn't manage."),
35
- ];
36
- }
37
33
  const output = [];
34
+ if (!scan.assets.length) {
35
+ output.push(`${ok("✔")} Nothing left to adopt: BarnDog manages every Skill, MCP server and Hook it can take over from your coding tools.`);
36
+ if (!scan.skipped.length) {
37
+ return output;
38
+ }
39
+ output.push("");
40
+ }
38
41
  for (const { harness, items } of byTool(scan.assets)) {
39
42
  output.push(bold(adapters[harness].name));
40
43
  output.push(...table(items.map((asset) => [
@@ -96,6 +99,7 @@ export function renderAdoption(result, runtime) {
96
99
  for (const note of result.notes) {
97
100
  output.push(`${warn("!")} ${kindLabels[note.kind]} ${bold(note.name)}: ${note.text}`);
98
101
  }
102
+ output.push(...renderMcpValues(result.values));
99
103
  output.push("", result.canShare
100
104
  ? hint("barndog local move", "Tip") +
101
105
  dim(" share them through your workspace")
@@ -127,11 +131,12 @@ export function renderAdoptions(list) {
127
131
  ]), { header: ["ID", "Date", "Status", "Assets"] });
128
132
  }
129
133
  const chooseKeptValues = (values) => checkbox({
134
+ loop: false,
130
135
  message: "Which values should BarnDog keep on this machine?",
131
136
  choices: values.map((value) => ({
132
137
  name: `${value.variable} ${dim(`${value.server}: ${value.key}`)}`,
133
138
  short: value.variable,
134
- value: value.variable,
139
+ value: { server: value.server, variable: value.variable },
135
140
  checked: true,
136
141
  })),
137
142
  theme: checkboxTheme,
@@ -78,6 +78,7 @@ export async function chooseConnection(current) {
78
78
  }
79
79
  export function chooseLocalAssets(count) {
80
80
  return select({
81
+ loop: false,
81
82
  message: `You have ${count} local asset${count === 1 ? "" : "s"}. What should happen to ${count === 1 ? "it" : "them"}?`,
82
83
  choices: [
83
84
  {
@@ -106,6 +107,7 @@ export function chooseLocalAssets(count) {
106
107
  }
107
108
  export function chooseMoveTarget(targets) {
108
109
  return select({
110
+ loop: false,
109
111
  message: "Where should they go?",
110
112
  choices: targets,
111
113
  theme: promptTheme,
@@ -1,11 +1,16 @@
1
1
  import checkbox from "@inquirer/checkbox";
2
2
  import { checkboxTheme, selected } from "./theme.js";
3
3
  import { dim } from "./format.js";
4
- export const chooseHarnesses = (choices) => {
4
+ const manage = {
5
+ message: "Which coding tools should BarnDog manage?",
6
+ required: false,
7
+ };
8
+ export const chooseHarnesses = (choices, question = manage) => {
5
9
  const width = Math.max(...choices.map((choice) => choice.name.length));
6
10
  return checkbox({
7
11
  loop: false,
8
- message: "Which coding tools should BarnDog manage?",
12
+ message: question.message,
13
+ required: question.required,
9
14
  choices: choices.map((choice) => ({
10
15
  value: choice.value,
11
16
  checked: choice.checked,
package/dist/ui/mcp.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { SHORT_COMMIT_LENGTH } from "../shared/constants.js";
2
2
  import { mcpDefinitionSchema } from "@barndog-ai/api-contract";
3
3
  import { z } from "zod";
4
- import { clean, fields, originLabel, renderValue } from "./format.js";
4
+ import { bold, clean, fields, hint, originLabel, renderValue, table, warn, } from "./format.js";
5
5
  const shownMcpSchema = z.looseObject({
6
6
  name: z.string(),
7
7
  origin: z.union([
@@ -18,12 +18,64 @@ const shownMcpSchema = z.looseObject({
18
18
  z.looseObject({ number: z.number(), definition: mcpDefinitionSchema }),
19
19
  ]),
20
20
  definition: mcpDefinitionSchema.optional(),
21
+ /** Variables it refers to that have no value on this machine. */
22
+ unsetVariables: z.array(z.string()).optional(),
21
23
  });
22
24
  const signIn = {
23
25
  none: "none",
24
26
  environment: "environment variables",
25
27
  "native-oauth": "OAuth, through each coding tool",
26
28
  };
29
+ /**
30
+ * Where each literal MCP value went: one sentence for the values BarnDog keeps
31
+ * and one for those the developer has to set, each over a column of variables
32
+ * grouped by server.
33
+ */
34
+ export function renderMcpValues(values) {
35
+ const column = (kept) => {
36
+ const rows = [];
37
+ let previous;
38
+ for (const value of values.filter((v) => v.kept === kept)) {
39
+ rows.push([
40
+ value.server === previous ? "" : bold(clean(value.server)),
41
+ clean(value.variable),
42
+ ]);
43
+ previous = value.server;
44
+ }
45
+ return rows;
46
+ };
47
+ const kept = column(true);
48
+ const unset = column(false);
49
+ const output = [];
50
+ if (kept.length) {
51
+ output.push("", "BarnDog keeps these values in ~/.barndog/secrets.json, on this machine only and never uploaded, and writes them into your coding tools:", ...table(kept));
52
+ }
53
+ if (unset.length) {
54
+ output.push("", `${warn("!")} BarnDog doesn't keep these values. Set each in your environment, or keep it with ${bold("barndog mcp env set <server> <variable>")}:`, ...table(unset));
55
+ }
56
+ return output;
57
+ }
58
+ /**
59
+ * A note per listed MCP server with variables that have no value here. One
60
+ * variable gets the command that sets it; several point at `mcp show`, which
61
+ * gives one for each.
62
+ */
63
+ export function unsetVariableNotes(items) {
64
+ return items.flatMap(({ installedName: name, unsetVariables: variables }) => {
65
+ if (!variables?.length) {
66
+ return [];
67
+ }
68
+ const [only] = variables;
69
+ const fix = variables.length === 1 && only
70
+ ? `barndog mcp env set ${clean(name)} ${clean(only)}`
71
+ : `barndog mcp show ${clean(name)}`;
72
+ return [
73
+ "",
74
+ `${warn("!")} ${bold(clean(name))} can't use ${variables.map((variable) => bold(clean(variable))).join(", ")}: no value here.`,
75
+ ` ${hint(fix, "Fix")}`,
76
+ ];
77
+ });
78
+ }
27
79
  /** An MCP configuration as a person reads it; secret references print by name. */
28
80
  export function renderMcp(value) {
29
81
  const shown = shownMcpSchema.safeParse(value);
@@ -39,27 +91,41 @@ export function renderMcp(value) {
39
91
  const references = definition.transport === "stdio"
40
92
  ? definition.environment
41
93
  : definition.headers;
42
- const variables = Object.entries(references).map(([key, reference]) => `${clean(key)} from $${reference.secretRef}`);
43
- return fields([
44
- ["Name", clean(mcp.name)],
45
- [
46
- "Origin",
47
- typeof mcp.origin === "string" ? mcp.origin : originLabel(mcp.origin),
48
- ],
49
- [
50
- "Version",
51
- typeof mcp.version === "object"
52
- ? `v${mcp.version.number}`
53
- : mcp.version.slice(0, SHORT_COMMIT_LENGTH),
54
- ],
55
- ["Description", clean(definition.description)],
56
- [
57
- "Connects to",
58
- definition.transport === "http"
59
- ? clean(definition.url)
60
- : clean([definition.command, ...definition.args].join(" ")),
61
- ],
62
- ["Sign-in", signIn[definition.authentication]],
63
- ["Variables", variables.join(", ")],
94
+ const unset = mcp.unsetVariables ?? [];
95
+ const variables = Object.entries(references).map(([key, reference]) => {
96
+ const shown = `${clean(key)} from $${reference.secretRef}`;
97
+ return unset.includes(reference.secretRef)
98
+ ? `${shown} ${warn("(not set)")}`
99
+ : shown;
100
+ });
101
+ const problems = unset.flatMap((variable) => [
102
+ "",
103
+ `${warn("!")} ${bold(clean(variable))} has no value here, so ${clean(mcp.name)} can't use it.`,
104
+ ` ${hint(`barndog mcp env set ${clean(mcp.name)} ${clean(variable)}`, "Fix")}`,
64
105
  ]);
106
+ return [
107
+ ...fields([
108
+ ["Name", clean(mcp.name)],
109
+ [
110
+ "Origin",
111
+ typeof mcp.origin === "string" ? mcp.origin : originLabel(mcp.origin),
112
+ ],
113
+ [
114
+ "Version",
115
+ typeof mcp.version === "object"
116
+ ? `v${mcp.version.number}`
117
+ : mcp.version.slice(0, SHORT_COMMIT_LENGTH),
118
+ ],
119
+ ["Description", clean(definition.description)],
120
+ [
121
+ "Connects to",
122
+ definition.transport === "http"
123
+ ? clean(definition.url)
124
+ : clean([definition.command, ...definition.args].join(" ")),
125
+ ],
126
+ ["Sign-in", signIn[definition.authentication]],
127
+ ["Variables", variables.join(", ")],
128
+ ]),
129
+ ...problems,
130
+ ];
65
131
  }
package/dist/ui/move.js CHANGED
@@ -5,7 +5,7 @@ import { promptTheme } from "./theme.js";
5
5
  /** The local assets `local move` can take: valid, and not already moving. */
6
6
  export function pickLocalAssets(local) {
7
7
  return pickMany("Which local assets should move?", local.assets
8
- .filter((asset) => asset.state === "active")
8
+ .filter((asset) => asset.state === "available")
9
9
  .map((asset) => ({
10
10
  value: asset.name,
11
11
  name: asset.name,
@@ -16,6 +16,7 @@ export function pickLocalAssets(local) {
16
16
  export function chooseKeepLocal(count) {
17
17
  const them = count === 1 ? "it" : "them";
18
18
  return select({
19
+ loop: false,
19
20
  message: `Move ${them}, or share a copy and keep ${them} here too?`,
20
21
  choices: [
21
22
  {
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";
@@ -54,7 +55,8 @@ function rows(events) {
54
55
  for (const event of events) {
55
56
  if (event.type === "disabled" ||
56
57
  event.type === "notice" ||
57
- event.type === "unset-variable") {
58
+ event.type === "unset-variable" ||
59
+ event.type === "unassigned-value") {
58
60
  continue;
59
61
  }
60
62
  if (event.type === "invalid") {
@@ -153,20 +155,43 @@ export function renderSyncOutput(events, options = {}) {
153
155
  }
154
156
  else {
155
157
  output.push(changed
156
- ? 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.")
157
159
  : quiet);
158
160
  }
159
161
  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
- }
162
+ output.push(...problemLines(event));
166
163
  }
167
164
  output.push("");
168
165
  return output;
169
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
+ }
170
195
  function describeError(error) {
171
196
  if (error instanceof LoginRequiredError) {
172
197
  return { message: "You're not signed in.", fix: "barndog login" };
@@ -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
+ }
@@ -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
+ }