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
@@ -1,15 +1,19 @@
1
1
  /** `barndog mcp add`: brings MCP servers from JSON or a coding tool into the local workspace. */
2
2
  import { localPath } from "../platform.js";
3
3
  import { CliError } from "../errors.js";
4
- import { addMcpServers, conflictingEntries, convertServer, harnessServers, parseMcpText, } from "../features/mcps/import.js";
5
- import { readFile } from "node:fs/promises";
4
+ import { only } from "../shared/lookup.js";
5
+ import { inputFile } from "../shared/files.js";
6
+ import { addMcpServers, conflictingEntries, convertServer, harnessServers, localMcpNamed, parseMcpText, } from "../features/mcps/import.js";
7
+ import { assetKinds } from "../features/asset-kinds/index.js";
8
+ import { validMcpName } from "../shared/patterns.js";
6
9
  import { bold, dim, ok, warn } from "./format.js";
10
+ import { renderMcpValues } from "./mcp.js";
7
11
  async function serversToAdd(name, options, context) {
8
12
  if (options.config) {
9
13
  return parseMcpText(options.config, name);
10
14
  }
11
15
  if (options.file) {
12
- return parseMcpText(await readFile(localPath(options.file, context.runtime), "utf8"), name);
16
+ return parseMcpText((await inputFile(localPath(options.file, context.runtime))).toString("utf8"), name);
13
17
  }
14
18
  const fromHarness = async () => {
15
19
  const all = (await harnessServers(context.runtime)).filter((s) => !options.from || s.harness === options.from);
@@ -55,6 +59,65 @@ async function serversToAdd(name, options, context) {
55
59
  ? parseMcpText(await context.prompts.paste(), name)
56
60
  : fromHarness();
57
61
  }
62
+ /**
63
+ * Which literal values BarnDog keeps on this machine. Only asked in a
64
+ * terminal; otherwise none are kept and the notes say which variables to set.
65
+ */
66
+ async function chooseKept(found, context) {
67
+ if (!found.length || !context.interactive) {
68
+ return [];
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."));
71
+ const picked = await context.prompts.chooseMany("Which values should BarnDog keep on this machine?", found.map(({ server, literal }, index) => ({
72
+ name: `${literal.variable} ${dim(`${server}: ${literal.key}`)}`,
73
+ short: literal.variable,
74
+ value: String(index),
75
+ checked: true,
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
+ });
83
+ }
84
+ /** Why a server can't be added under `name` here, or null when it can. */
85
+ async function nameProblem(name, context) {
86
+ if (!validMcpName(name)) {
87
+ return `${name} can't be an MCP server name. ${assetKinds.mcp.nameRule}.`;
88
+ }
89
+ const existing = await localMcpNamed(name, context.runtime);
90
+ if (existing === null) {
91
+ return null;
92
+ }
93
+ return existing === name
94
+ ? `You already have a local MCP server named ${name}.`
95
+ : `${name} differs from your local MCP server ${existing} only in case, and they'd share one file on this disk.`;
96
+ }
97
+ /**
98
+ * Applies `--as`, then asks in a terminal for a new name wherever one is
99
+ * unusable or taken. Without a terminal, adding reports it with the fix.
100
+ */
101
+ async function namedServers(servers, as, context) {
102
+ const one = only(servers);
103
+ if (as !== undefined && !one) {
104
+ throw new CliError("--as renames one MCP server, so add exactly one.", "barndog mcp add <name> --as <new-name>");
105
+ }
106
+ const renamed = one && as !== undefined ? [{ ...one, name: as }] : servers;
107
+ if (!context.interactive) {
108
+ return renamed;
109
+ }
110
+ const result = [];
111
+ for (const server of renamed) {
112
+ let name = server.name;
113
+ for (let problem = await nameProblem(name, context); problem; problem = await nameProblem(name, context)) {
114
+ context.write(`${warn("!")} ${problem}`);
115
+ name = (await context.prompts.text(`New name for ${server.name}`)).trim();
116
+ }
117
+ result.push({ ...server, name });
118
+ }
119
+ return result;
120
+ }
58
121
  /**
59
122
  * `mcp add`: imports MCP servers from a harness's configuration or pasted JSON
60
123
  * into the local workspace.
@@ -64,7 +127,7 @@ export async function addMcp(name, options, context) {
64
127
  if (name?.trimStart().startsWith("{")) {
65
128
  throw new CliError("That looks like the configuration, not a name.", "barndog mcp add <name> --config '<json>'");
66
129
  }
67
- const imported = await serversToAdd(name, options, context);
130
+ const imported = await namedServers(await serversToAdd(name, options, context), options.as, context);
68
131
  const oauth = new Set();
69
132
  for (const { name: server, server: raw } of imported) {
70
133
  if (options.oauth ||
@@ -94,14 +157,20 @@ export async function addMcp(name, options, context) {
94
157
  throw new CliError("Nothing was added.");
95
158
  }
96
159
  }
97
- const result = await addMcpServers(servers, { replace }, context.runtime);
98
- for (const added of result.added) {
99
- context.write(`${ok("✔")} Added ${bold(added)}`);
100
- }
101
- for (const note of result.notes) {
102
- context.write(`${warn("!")} ${note}`);
103
- }
104
- for (const backup of result.backups) {
105
- context.write(dim(`Backup: ${backup}`));
160
+ const keep = await chooseKept(servers.flatMap((server) => server.literals.map((literal) => ({ server: server.name, literal }))), context);
161
+ const result = await addMcpServers(servers, { replace, keep }, context.runtime);
162
+ for (const line of renderAddedServers(result)) {
163
+ context.write(line);
106
164
  }
107
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
+ }
@@ -9,11 +9,12 @@ import { defined } from "../shared/lookup.js";
9
9
  import { finish, folderLabel, assertDistinctNames, notFound, onlyChosen, updateMode, } from "./add-asset.js";
10
10
  /** Stops two copies of a Skill from claiming the same name, saying which folders hold them. */
11
11
  /** A plain folder is read in place; everything else is fetched with Git. */
12
- async function withSkillSource(source, folder, runtime, use) {
13
- if (folder) {
14
- return use(await readFolder(folder, runtime));
12
+ async function withSkillSource(source, runtime, use) {
13
+ if (source.folder) {
14
+ return use(await readFolder(source.folder, runtime));
15
15
  }
16
- return fetchRemote(parseLocation(source), { allowPrompt: true }, use, runtime);
16
+ // Git may ask for credentials only when someone is there to answer.
17
+ return fetchRemote(parseLocation(source.location), { allowPrompt: source.interactive }, use, runtime);
17
18
  }
18
19
  function assertFolderOptions(options, folder) {
19
20
  if (!folder && (options.copy || options.move)) {
@@ -51,7 +52,8 @@ export async function addSkills(url, options, context) {
51
52
  assertSourceExists(url, context.runtime);
52
53
  const folder = await plainFolder(url, context.runtime);
53
54
  assertFolderOptions(options, folder);
54
- await withSkillSource(url, folder, context.runtime, async (remote) => {
55
+ const source = { location: url, folder, interactive: context.interactive };
56
+ await withSkillSource(source, context.runtime, async (remote) => {
55
57
  const { skills, skipped } = discoverSkills(remote);
56
58
  for (const skip of skipped) {
57
59
  context.write(`${warn("!")} ${skip.path}: ${skip.reason}`);
@@ -0,0 +1,202 @@
1
+ import checkbox, { Separator } from "@inquirer/checkbox";
2
+ import confirm from "@inquirer/confirm";
3
+ import { adoptNative, adoptionPlan, } from "../features/adoption/adopt.js";
4
+ import { scanNative, } from "../features/adoption/scan.js";
5
+ import { friendlyMessage } from "../errors.js";
6
+ import { harnesses, adapters } from "../harnesses/registry.js";
7
+ import { bold, dim, heading, hint, ok, plural, table, warn } from "./format.js";
8
+ import { displayPath } from "./output.js";
9
+ import { renderMcpValues } from "./mcp.js";
10
+ import { checkboxTheme, promptTheme } from "./theme.js";
11
+ const kindLabels = {
12
+ skill: "Skill",
13
+ mcp: "MCP",
14
+ hook: "Hook",
15
+ };
16
+ const kindWidth = Math.max(...Object.values(kindLabels).map((label) => label.length));
17
+ /** How the asset relates to other tools' assets of the same name, when it does. */
18
+ function sharing(asset) {
19
+ if (!asset.sameName.length) {
20
+ return "";
21
+ }
22
+ const tools = asset.sameName
23
+ .map((other) => adapters[other.harness].name)
24
+ .join(", ");
25
+ return asset.identical ? `same as ${tools}` : `differs from ${tools}`;
26
+ }
27
+ const byTool = (items) => harnesses.flatMap((harness) => {
28
+ const mine = items.filter((item) => item.harness === harness);
29
+ return mine.length ? [{ harness, items: mine }] : [];
30
+ });
31
+ /** What a scan found, one section per coding tool. */
32
+ export function renderScan(scan, runtime) {
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
+ }
41
+ for (const { harness, items } of byTool(scan.assets)) {
42
+ output.push(bold(adapters[harness].name));
43
+ output.push(...table(items.map((asset) => [
44
+ dim(kindLabels[asset.kind]),
45
+ bold(asset.name),
46
+ asset.identical ? dim(sharing(asset)) : warn(sharing(asset)),
47
+ dim(asset.key),
48
+ ])));
49
+ output.push("");
50
+ }
51
+ if (scan.skipped.length) {
52
+ output.push(bold("Can't be adopted"));
53
+ for (const skipped of scan.skipped) {
54
+ output.push(` ${dim(`${adapters[skipped.harness].name} ${kindLabels[skipped.kind]}`)} ${bold(skipped.name)} ${dim(displayPath(skipped.location, runtime))}`, ` ${dim(skipped.reason)}`);
55
+ }
56
+ output.push("");
57
+ }
58
+ return output;
59
+ }
60
+ const chooseAdoption = (scan) => checkbox({
61
+ loop: false,
62
+ message: "Which assets should BarnDog adopt?",
63
+ choices: byTool(scan.assets).flatMap(({ harness, items }) => [
64
+ new Separator(bold(adapters[harness].name)),
65
+ ...items.map((asset) => ({
66
+ value: asset.key,
67
+ checked: false,
68
+ short: asset.key,
69
+ name: `${kindLabels[asset.kind].padEnd(kindWidth)} ${asset.name}${sharing(asset) ? dim(` ${sharing(asset)}`) : ""}`,
70
+ description: asset.description,
71
+ })),
72
+ ]),
73
+ theme: checkboxTheme,
74
+ });
75
+ /** What an adoption will take over, including other tools' copies BarnDog's one replaces. */
76
+ function renderPlan(plan) {
77
+ const output = [bold("BarnDog will adopt")];
78
+ output.push(...table(plan.map((asset) => [
79
+ adapters[asset.harness].name,
80
+ dim(kindLabels[asset.kind]),
81
+ bold(asset.name),
82
+ asset.source.key !== asset.key && !asset.identical
83
+ ? warn(`replaced by ${adapters[asset.source.harness].name}'s`)
84
+ : "",
85
+ ])));
86
+ output.push("", dim("Originals move into ~/.barndog/adoptions/ and BarnDog installs its copies in their place."), dim("Adopted Skills and MCP servers install in every coding tool BarnDog manages."));
87
+ return output;
88
+ }
89
+ const confirmAdoption = (plan) => confirm({
90
+ message: `Adopt ${plural(plan.length, "asset")}?`,
91
+ default: true,
92
+ theme: promptTheme,
93
+ });
94
+ export function renderAdoption(result, runtime) {
95
+ const output = [
96
+ `${ok("✔")} Adopted ${plural(result.adopted.length, "asset")} into your local folder.`,
97
+ dim(`Originals are saved in ${displayPath(result.backup, runtime)}`),
98
+ ];
99
+ for (const note of result.notes) {
100
+ output.push(`${warn("!")} ${kindLabels[note.kind]} ${bold(note.name)}: ${note.text}`);
101
+ }
102
+ output.push(...renderMcpValues(result.values));
103
+ output.push("", result.canShare
104
+ ? hint("barndog local move", "Tip") +
105
+ dim(" share them through your workspace")
106
+ : hint("barndog local list", "Tip") +
107
+ dim(" see everything in your local workspace"));
108
+ return output;
109
+ }
110
+ export function renderUndo(result, runtime) {
111
+ const output = [
112
+ `${ok("✔")} Put back ${plural(result.restored.length, "asset")}.`,
113
+ ...result.restored.map((item) => ` ${adapters[item.harness].name} ${dim(kindLabels[item.kind])} ${bold(item.name)} ${dim(displayPath(item.location, runtime))}`),
114
+ ];
115
+ if (result.remaining.length) {
116
+ output.push("", dim(`${plural(result.remaining.length, "asset")} of this adoption ${result.remaining.length === 1 ? "is" : "are"} still managed by BarnDog.`));
117
+ }
118
+ return output;
119
+ }
120
+ export function renderAdoptions(list) {
121
+ if (!list.length) {
122
+ return [dim("Nothing has been adopted on this machine.")];
123
+ }
124
+ return table(list.map((record) => [
125
+ record.id,
126
+ dim(record.createdAt.slice(0, "YYYY-MM-DD".length)),
127
+ record.status === "applied" ? ok(record.status) : warn(record.status),
128
+ record.items
129
+ .map((item) => (item.undone ? dim(item.key) : item.key))
130
+ .join(", "),
131
+ ]), { header: ["ID", "Date", "Status", "Assets"] });
132
+ }
133
+ const chooseKeptValues = (values) => checkbox({
134
+ loop: false,
135
+ message: "Which values should BarnDog keep on this machine?",
136
+ choices: values.map((value) => ({
137
+ name: `${value.variable} ${dim(`${value.server}: ${value.key}`)}`,
138
+ short: value.variable,
139
+ value: { server: value.server, variable: value.variable },
140
+ checked: true,
141
+ })),
142
+ theme: checkboxTheme,
143
+ });
144
+ /** Shows what a scan found, asks which assets to adopt, and adopts them. */
145
+ export async function offerAdoption(scan, prompt) {
146
+ const { write } = prompt;
147
+ write(`\n${heading("adopt")}\n`);
148
+ write("These are set up in your coding tools without BarnDog:");
149
+ write("");
150
+ for (const line of renderScan(scan, prompt.runtime)) {
151
+ write(line);
152
+ }
153
+ const keys = await (prompt.choose ?? chooseAdoption)(scan);
154
+ if (!keys.length) {
155
+ write(`${dim("Nothing adopted. Run")} ${bold("barndog adopt")} ${dim("any time.")}`);
156
+ return;
157
+ }
158
+ const plan = adoptionPlan(scan, keys);
159
+ write("");
160
+ for (const line of renderPlan(plan)) {
161
+ write(line);
162
+ }
163
+ write("");
164
+ if (!(await (prompt.confirm ?? confirmAdoption)(plan))) {
165
+ write(dim("Nothing adopted."));
166
+ return;
167
+ }
168
+ // Same-named copies share one source, so each value is asked about once.
169
+ const values = plan
170
+ .filter((asset) => asset.key === asset.source.key)
171
+ .flatMap((asset) => asset.values.map((value) => ({ server: asset.name, ...value })));
172
+ let keep = [];
173
+ if (values.length) {
174
+ write("");
175
+ write(dim("These MCP values were written into the tools' settings. BarnDog can keep them in ~/.barndog/secrets.json, which only you can read and which is never uploaded, and write them into each tool it manages. Leave one unticked to set it yourself."));
176
+ keep = await (prompt.keepValues ?? chooseKeptValues)(values);
177
+ }
178
+ const result = await prompt.adoptNative(keys, keep);
179
+ for (const line of renderAdoption(result, prompt.runtime)) {
180
+ write(line);
181
+ }
182
+ }
183
+ /**
184
+ * First-time setup offers to adopt what the tools already have. Setup is saved
185
+ * by then, so a failure here is reported rather than failing setup.
186
+ */
187
+ export async function offerAdoptionAtSetup(runtime, prompt) {
188
+ try {
189
+ const scan = await scanNative(runtime);
190
+ if (scan.assets.length) {
191
+ await offerAdoption(scan, {
192
+ ...prompt,
193
+ adoptNative: (keys, keep) => adoptNative(keys, keep, runtime),
194
+ runtime,
195
+ });
196
+ }
197
+ }
198
+ catch (error) {
199
+ prompt.write(`${warn("!")} Nothing was adopted: ${friendlyMessage(error)}`);
200
+ prompt.write(hint("barndog adopt", "Tip") + dim(" try again later"));
201
+ }
202
+ }
package/dist/ui/assets.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { shellWord } from "../platform.js";
1
2
  import { adapters } from "../harnesses/registry.js";
2
3
  import { assetPage } from "./asset-list.js";
3
4
  import { displayPath } from "./output.js";
@@ -95,7 +96,7 @@ export function inventoryHints(items) {
95
96
  * Returns a filtered catalog table and paging hints, marking selected IDs; does
96
97
  * not write output.
97
98
  */
98
- export function renderCatalog(rows, options, command, installedIds) {
99
+ export function renderCatalog(rows, options, next, installedIds) {
99
100
  const page = assetPage(rows, options);
100
101
  if (!page.total) {
101
102
  return [dim("No matching assets.")];
@@ -124,8 +125,9 @@ export function renderCatalog(rows, options, command, installedIds) {
124
125
  });
125
126
  output.push("", dim(`Showing ${page.start + 1}–${page.start + page.rows.length} of ${page.total}${page.pages > 1 ? ` · page ${options.page}/${page.pages}` : ""}${installedIds.size ? " · ✔ selected on this machine" : ""}`));
126
127
  if (options.page < page.pages) {
127
- const filters = `${options.search ? ` ${JSON.stringify(options.search)}` : ""}${options.origin ? ` --origin ${options.origin}` : ""}`;
128
- output.push(hint(`${command}${filters} --page ${options.page + 1}`, "Next"));
128
+ const word = (value) => shellWord(value, next.platform);
129
+ const filters = `${options.search ? ` ${word(options.search)}` : ""}${options.origin ? ` --origin ${word(options.origin)}` : ""}`;
130
+ output.push(hint(`${next.command}${filters} --page ${options.page + 1}`, "Next"));
129
131
  }
130
132
  return output;
131
133
  }
package/dist/ui/auth.js CHANGED
@@ -4,6 +4,7 @@ import { readCredentials } from "../features/auth/credentials.js";
4
4
  import { LoginRequiredError } from "../features/auth/transport.js";
5
5
  import { CliError } from "../errors.js";
6
6
  import { promptServer } from "./connection.js";
7
+ import { interactiveTerminal } from "./pick.js";
7
8
  import { bad, bold, dim, fields, heading, hint, humanize, json, ok, warn, } from "./format.js";
8
9
  /** Opens `url` in the default browser; rejects when no browser could be started. */
9
10
  export async function openBrowser(url) {
@@ -19,7 +20,7 @@ function describeIdentity(context) {
19
20
  export async function runLogin(options, write) {
20
21
  const server = options.server ??
21
22
  (await configuredServer(options.runtime)) ??
22
- (process.stdin.isTTY && process.stdout.isTTY
23
+ ((options.interactive ?? interactiveTerminal())
23
24
  ? await promptServer()
24
25
  : undefined);
25
26
  if (server && !options.force) {
package/dist/ui/clash.js CHANGED
@@ -1,5 +1,4 @@
1
1
  import select from "@inquirer/select";
2
- import { validAssetName } from "../shared/patterns.js";
3
2
  import { originLabel } from "../features/server/origin.js";
4
3
  import { bold, dim, fields, warn } from "./format.js";
5
4
  import { promptTheme } from "./theme.js";
@@ -18,14 +17,14 @@ export async function promptClash(clash) {
18
17
  console.log("");
19
18
  const choices = [];
20
19
  if (clash.incoming.renamable !== false &&
21
- validAssetName(clash.incomingRename)) {
20
+ assetKinds[clash.kind].validName(clash.incomingRename)) {
22
21
  choices.push({
23
22
  name: `Rename the new one to ${clash.incomingRename}`,
24
23
  value: "rename-incoming",
25
24
  });
26
25
  }
27
26
  if (clash.installed.renamable !== false &&
28
- validAssetName(clash.installedRename)) {
27
+ assetKinds[clash.kind].validName(clash.installedRename)) {
29
28
  choices.push({
30
29
  name: `Rename the installed one to ${clash.installedRename}`,
31
30
  value: "rename-installed",
@@ -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
  {
@@ -86,9 +87,14 @@ export function chooseLocalAssets(count) {
86
87
  description: "They keep working next to the shared assets. Move them any time with barndog local move.",
87
88
  },
88
89
  {
89
- name: "Keep active, and move to the new workspace",
90
+ name: "Share a copy, and keep them here too",
91
+ value: "copy",
92
+ description: "The local ones stay as separate assets. Anything whose name is already taken is left out and listed.",
93
+ },
94
+ {
95
+ name: "Move them to the new workspace",
90
96
  value: "move",
91
- description: "Also shares them. Anything whose name is already taken is left out and listed.",
97
+ description: "The shared copies become the only ones; the local ones are removed once they exist. Anything whose name is already taken stays local and is listed.",
92
98
  },
93
99
  {
94
100
  name: "Stop using them",
@@ -101,6 +107,7 @@ export function chooseLocalAssets(count) {
101
107
  }
102
108
  export function chooseMoveTarget(targets) {
103
109
  return select({
110
+ loop: false,
104
111
  message: "Where should they go?",
105
112
  choices: targets,
106
113
  theme: promptTheme,
@@ -0,0 +1,23 @@
1
+ import checkbox from "@inquirer/checkbox";
2
+ import { checkboxTheme, selected } from "./theme.js";
3
+ import { dim } from "./format.js";
4
+ const manage = {
5
+ message: "Which coding tools should BarnDog manage?",
6
+ required: false,
7
+ };
8
+ export const chooseHarnesses = (choices, question = manage) => {
9
+ const width = Math.max(...choices.map((choice) => choice.name.length));
10
+ return checkbox({
11
+ loop: false,
12
+ message: question.message,
13
+ required: question.required,
14
+ choices: choices.map((choice) => ({
15
+ value: choice.value,
16
+ checked: choice.checked,
17
+ short: choice.name,
18
+ name: `${choice.name.padEnd(width)} ${choice.evidence ? selected("detected") : dim("not found")}`,
19
+ description: choice.evidence ?? undefined,
20
+ })),
21
+ theme: checkboxTheme,
22
+ });
23
+ };
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
  }