barndog 0.2.2 → 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 (66) hide show
  1. package/README.md +2 -0
  2. package/dist/cli.js +2 -2
  3. package/dist/commands/add.js +4 -2
  4. package/dist/commands/asset-install.js +7 -3
  5. package/dist/commands/asset-share.js +15 -3
  6. package/dist/commands/capabilities.js +23 -5
  7. package/dist/commands/collaboration.js +9 -3
  8. package/dist/commands/harnesses.js +1 -1
  9. package/dist/commands/hooks.js +16 -1
  10. package/dist/commands/mcp-env.js +39 -12
  11. package/dist/commands/mcp.js +13 -3
  12. package/dist/commands/origin.js +7 -4
  13. package/dist/commands/sets.js +3 -3
  14. package/dist/commands/status.js +3 -1
  15. package/dist/commands/sync.js +1 -1
  16. package/dist/commands/uninstall.js +4 -2
  17. package/dist/commands/workspace.js +19 -0
  18. package/dist/config/state.js +19 -0
  19. package/dist/errors.js +4 -0
  20. package/dist/features/adoption/adopt.js +18 -1
  21. package/dist/features/adoption/scan.js +5 -0
  22. package/dist/features/asset-kinds/url-query.js +26 -0
  23. package/dist/features/doctor/check.js +1 -0
  24. package/dist/features/doctor/grouped.js +127 -0
  25. package/dist/features/doctor/index.js +18 -33
  26. package/dist/features/environment/events.js +10 -0
  27. package/dist/features/environment/kept-value-events.js +40 -0
  28. package/dist/features/environment/mcp-records.js +57 -0
  29. package/dist/features/environment/stage.js +12 -8
  30. package/dist/features/environment/sync.js +11 -1
  31. package/dist/features/environment/writes.js +25 -27
  32. package/dist/features/hooks/compatibility.js +37 -17
  33. package/dist/features/hooks/test.js +2 -2
  34. package/dist/features/inventory/hook-matrix.js +14 -0
  35. package/dist/features/inventory/hook-readiness.js +47 -0
  36. package/dist/features/inventory/index.js +9 -1
  37. package/dist/features/inventory/show.js +10 -2
  38. package/dist/features/mcps/import.js +40 -8
  39. package/dist/features/mcps/index.js +23 -10
  40. package/dist/features/mcps/values.js +71 -21
  41. package/dist/features/migration/move.js +4 -0
  42. package/dist/features/migration/promote.js +1 -0
  43. package/dist/features/native/adapters.js +4 -44
  44. package/dist/features/native/requirements.js +98 -0
  45. package/dist/features/secrets/index.js +4 -3
  46. package/dist/features/uninstall/index.js +1 -1
  47. package/dist/features/workspace/cloud-source.js +38 -4
  48. package/dist/program.js +4 -1
  49. package/dist/ui/add-hook.js +2 -2
  50. package/dist/ui/add-mcp.js +37 -5
  51. package/dist/ui/add-skills.js +2 -2
  52. package/dist/ui/adopt.js +80 -14
  53. package/dist/ui/assets.js +15 -2
  54. package/dist/ui/collaboration.js +5 -3
  55. package/dist/ui/format.js +81 -2
  56. package/dist/ui/hook-compatibility.js +176 -22
  57. package/dist/ui/mcp.js +98 -19
  58. package/dist/ui/move.js +1 -1
  59. package/dist/ui/onboarding.js +11 -2
  60. package/dist/ui/output.js +96 -42
  61. package/dist/ui/package-details.js +7 -2
  62. package/dist/ui/pick.js +20 -6
  63. package/dist/ui/selection.js +1 -1
  64. package/dist/ui/uninstall.js +14 -2
  65. package/dist/ui/variable-problems.js +23 -0
  66. package/package.json +2 -2
@@ -1,48 +1,7 @@
1
- import { coerce, satisfies, validRange } from "semver";
2
- import { programOutput, findExecutable, runtimeExecutable, } from "../../platform.js";
3
1
  import { adapters, nativeFile } from "../../harnesses/registry.js";
4
2
  import { secretRefs } from "../../harnesses/formats.js";
5
3
  import { hookCommand } from "./hook-shell.js";
6
- /** A `--version` answer is one short line; anything slower or longer is broken. */
7
- const VERSION_TIMEOUT_MS = 5000;
8
- const VERSION_OUTPUT_LIMIT_BYTES = 4096;
9
- /**
10
- * Checks required executables and optionally runs the harness version command;
11
- * returns the first issue or null.
12
- */
13
- export async function runtimeRequirements(harness, requirements, runtime) {
14
- for (const command of requirements.commands) {
15
- if (!(await runtimeExecutable(command, runtime))) {
16
- return `Missing runtime: ${command}`;
17
- }
18
- }
19
- if (requirements.harnessVersion) {
20
- if (!validRange(requirements.harnessVersion)) {
21
- return `Invalid declared harness version requirement: ${requirements.harnessVersion}`;
22
- }
23
- const command = (await Promise.all(adapters[harness].commands.map((c) => findExecutable(c, runtime)))).find(Boolean);
24
- if (!command) {
25
- return `Cannot verify ${harness} version: harness command is missing`;
26
- }
27
- try {
28
- const stdout = await programOutput(command, ["--version"], runtime, {
29
- timeoutMs: VERSION_TIMEOUT_MS,
30
- maxBytes: VERSION_OUTPUT_LIMIT_BYTES,
31
- });
32
- const version = coerce(stdout);
33
- if (!version) {
34
- return `Cannot verify ${harness} version: ${command} --version printed no version`;
35
- }
36
- if (!satisfies(version, requirements.harnessVersion)) {
37
- return `${harness} ${version.version} does not meet ${requirements.harnessVersion}`;
38
- }
39
- }
40
- catch {
41
- return `Cannot verify ${harness} version`;
42
- }
43
- }
44
- return null;
45
- }
4
+ import { runtimeRequirements } from "./requirements.js";
46
5
  /**
47
6
  * Why a Hook can't be installed for a tool: no implementation for it, or
48
7
  * something its implementation needs is missing here. Null when it can.
@@ -50,9 +9,10 @@ export async function runtimeRequirements(harness, requirements, runtime) {
50
9
  export async function hookIssue(harness, manifest, runtime) {
51
10
  const implementation = manifest.implementations[harness];
52
11
  if (!implementation) {
53
- return "No implementation for this harness";
12
+ return { type: "no-implementation" };
54
13
  }
55
- return runtimeRequirements(harness, implementation.requirements, runtime);
14
+ const requirement = await runtimeRequirements(harness, implementation.requirements, runtime);
15
+ return requirement && { type: "missing-requirement", requirement };
56
16
  }
57
17
  /**
58
18
  * Builds a harness-specific MCP configuration entry; does not write native
@@ -0,0 +1,98 @@
1
+ import { coerce, satisfies, validRange } from "semver";
2
+ import { programOutput, findExecutable, runtimeExecutable, } from "../../platform.js";
3
+ import { adapters } from "../../harnesses/registry.js";
4
+ /** A `--version` answer is one short line; anything slower or longer is broken. */
5
+ const VERSION_TIMEOUT_MS = 5000;
6
+ const VERSION_OUTPUT_LIMIT_BYTES = 4096;
7
+ /** The tool's own version, or why it couldn't be read. */
8
+ async function toolVersion(harness, range, runtime) {
9
+ const command = (await Promise.all(adapters[harness].commands.map((c) => findExecutable(c, runtime)))).find(Boolean);
10
+ if (!command) {
11
+ return { type: "tool-missing", range };
12
+ }
13
+ try {
14
+ const stdout = await programOutput(command, ["--version"], runtime, {
15
+ timeoutMs: VERSION_TIMEOUT_MS,
16
+ maxBytes: VERSION_OUTPUT_LIMIT_BYTES,
17
+ });
18
+ return coerce(stdout)?.version ?? { type: "version-unknown", range };
19
+ }
20
+ catch {
21
+ return { type: "version-unknown", range };
22
+ }
23
+ }
24
+ /**
25
+ * Checks required executables and optionally runs the harness version command;
26
+ * returns every requirement this machine misses, in the order declared.
27
+ */
28
+ export async function missingRequirements(harness, requirements, runtime) {
29
+ const missing = [];
30
+ for (const command of requirements.commands) {
31
+ if (!(await runtimeExecutable(command, runtime))) {
32
+ missing.push({ type: "command", command });
33
+ }
34
+ }
35
+ const range = requirements.harnessVersion;
36
+ if (!range) {
37
+ return missing;
38
+ }
39
+ if (!validRange(range)) {
40
+ return [...missing, { type: "invalid-range", range }];
41
+ }
42
+ const installed = await toolVersion(harness, range, runtime);
43
+ if (typeof installed !== "string") {
44
+ return [...missing, installed];
45
+ }
46
+ return satisfies(installed, range)
47
+ ? missing
48
+ : [...missing, { type: "version", range, installed }];
49
+ }
50
+ /** The first requirement this machine misses, or null when it has them all. */
51
+ export async function runtimeRequirements(harness, requirements, runtime) {
52
+ const [first] = await missingRequirements(harness, requirements, runtime);
53
+ return first ?? null;
54
+ }
55
+ /**
56
+ * What is missing, as the end of a sentence about the Hook:
57
+ * `lint-on-save` + ` needs the deno command, which isn't installed here or isn't on your PATH`.
58
+ */
59
+ export function requirementMessage(harness, missing) {
60
+ const tool = adapters[harness].name;
61
+ switch (missing.type) {
62
+ case "command":
63
+ return `needs the ${missing.command} command, which isn't installed here or isn't on your PATH`;
64
+ case "invalid-range":
65
+ return `declares a ${tool} version BarnDog can't read: ${missing.range}`;
66
+ case "tool-missing":
67
+ return `needs ${tool} ${missing.range}, but BarnDog can't find ${tool} to check its version`;
68
+ case "version-unknown":
69
+ return `needs ${tool} ${missing.range}, but BarnDog couldn't read ${tool}'s version`;
70
+ case "version":
71
+ return `needs ${tool} ${missing.range}; this machine has ${missing.installed}`;
72
+ }
73
+ }
74
+ /** What the developer can do about it, in words. */
75
+ export function requirementFix(harness, missing) {
76
+ const tool = adapters[harness].name;
77
+ switch (missing.type) {
78
+ case "command":
79
+ return `Install ${missing.command}`;
80
+ case "invalid-range":
81
+ return "Ask the Hook's author to fix requirements.harnessVersion in hook.yaml";
82
+ case "tool-missing":
83
+ case "version-unknown":
84
+ case "version":
85
+ return `Install or update ${tool}`;
86
+ }
87
+ }
88
+ /** A skip as one sentence fragment, such as `No implementation for this harness`. */
89
+ export function skipReason(harness, skip) {
90
+ switch (skip.type) {
91
+ case "no-implementation":
92
+ return "No implementation for this harness";
93
+ case "no-command-hooks":
94
+ return `${adapters[harness].name} has no command hooks`;
95
+ case "missing-requirement":
96
+ return requirementMessage(harness, skip.requirement);
97
+ }
98
+ }
@@ -119,8 +119,8 @@ export function applyKeptValues(definition, values = {}) {
119
119
  }
120
120
  /**
121
121
  * The variables a definition names that have no value on this machine:
122
- * BarnDog keeps none for this server and `env` doesn't set the variable read.
123
- * Each once, in the order the definition names them.
122
+ * BarnDog keeps none for this server and `env` doesn't set the variable read,
123
+ * even to an empty string. Each once, in the order the definition names them.
124
124
  */
125
125
  export function missingValues(definition, values, env) {
126
126
  const missing = new Map();
@@ -131,7 +131,8 @@ export function missingValues(definition, values, env) {
131
131
  const found = literalOf(kept) ??
132
132
  literalOf(from ? values[from] : undefined) ??
133
133
  env[read];
134
- if (!found) {
134
+ // An empty value is still a value: a tool passes it as it is.
135
+ if (found === undefined) {
135
136
  missing.set(secretRef, {
136
137
  variable: secretRef,
137
138
  ...(from ? { from } : {}),
@@ -76,7 +76,7 @@ async function removeEntries(keepSetup, runtime) {
76
76
  kind: "file",
77
77
  path: stateFile,
78
78
  before: await fileText(stateFile),
79
- after: stateText({ links: [], native: [], trees: [] }),
79
+ after: stateText({ links: [], native: [], trees: [], mcpServers: [] }),
80
80
  },
81
81
  ];
82
82
  await transact(runtime, writes);
@@ -1,7 +1,7 @@
1
1
  import { mcpSchema } from "@barndog-ai/api-contract";
2
2
  import { assetKinds } from "../asset-kinds/index.js";
3
3
  import { cacheKey, cachedPackage } from "./packages.js";
4
- import { environmentCatalog, getAsset } from "../server/catalog.js";
4
+ import { environmentCatalog, getAsset, } from "../server/catalog.js";
5
5
  import { CliError } from "../../errors.js";
6
6
  async function currentAsset(kind, reference, conn, runtime) {
7
7
  const data = await getAsset(kind, reference.id, conn, runtime);
@@ -16,18 +16,52 @@ async function currentAsset(kind, reference, conn, runtime) {
16
16
  /**
17
17
  * Adapts an authenticated cloud connection to lazy catalog, package-cache and
18
18
  * MCP reads for synchronization.
19
+ *
20
+ * Servers that include each asset's version and MCP definition in the catalog
21
+ * need no further request per asset. Entries from older servers lack them, so
22
+ * those assets are fetched one by one and checked against the catalog.
19
23
  */
20
24
  export function cloudSource(conn, runtime) {
25
+ const entries = new Map();
26
+ // The entry this reference was read from, if the reference still matches it.
27
+ const entry = (reference) => {
28
+ const found = entries.get(reference.id);
29
+ return found?.publishedVersion === reference.publishedVersion &&
30
+ found.name === reference.name
31
+ ? found
32
+ : undefined;
33
+ };
21
34
  return {
22
35
  cacheKey: cacheKey(conn),
23
36
  journal: conn,
24
- catalog: async () => (await environmentCatalog(runtime, conn)).catalog,
37
+ catalog: async () => {
38
+ const { catalog } = await environmentCatalog(runtime, conn);
39
+ entries.clear();
40
+ for (const asset of catalog.assets) {
41
+ entries.set(asset.id, asset);
42
+ }
43
+ return catalog;
44
+ },
25
45
  packageFolder: async (kind, reference) => {
46
+ const listed = entry(reference);
47
+ const commit = listed?.version?.commit;
48
+ if (listed?.version && commit) {
49
+ return cachedPackage(kind, {
50
+ id: listed.id,
51
+ name: listed.name,
52
+ version: { commit, number: listed.version.number },
53
+ }, conn, runtime);
54
+ }
26
55
  const data = await currentAsset(kind, reference, conn, runtime);
27
56
  return cachedPackage(kind, assetKinds[kind].schema.parse(data), conn, runtime);
28
57
  },
29
- mcpDefinition: async (reference) => mcpSchema.parse(await currentAsset("mcp", reference, conn, runtime))
30
- .version.definition,
58
+ mcpDefinition: async (reference) => {
59
+ const definition = entry(reference)?.definition;
60
+ if (definition) {
61
+ return definition;
62
+ }
63
+ return mcpSchema.parse(await currentAsset("mcp", reference, conn, runtime)).version.definition;
64
+ },
31
65
  invalidAssets: () => Promise.resolve(new Map()),
32
66
  notices: () => [],
33
67
  };
package/dist/program.js CHANGED
@@ -27,6 +27,7 @@ import { authenticateMcp, createMcp, mcpVersions, showMcp, updateMcp, } from "./
27
27
  import { adaptHook, toolNames } from "./features/hooks/adapt.js";
28
28
  import { harnesses } from "./harnesses/registry.js";
29
29
  import { hookCompatibility } from "./features/hooks/compatibility.js";
30
+ import { allHookCompatibility } from "./features/inventory/hook-matrix.js";
30
31
  import { testHook } from "./features/hooks/test.js";
31
32
  import { knowledgeGet, knowledgeList, knowledgeProblems, } from "./features/knowledge/index.js";
32
33
  import { developerAssets, developers, fork, } from "./features/discovery/index.js";
@@ -53,7 +54,7 @@ import { versionReport } from "./version.js";
53
54
  import { defined } from "./shared/lookup.js";
54
55
  import { barndogPaths } from "./config/paths.js";
55
56
  import { showPackage } from "./features/inventory/show.js";
56
- import { assignKeptValue, forgetMcpValue, forgetUnassignedValue, keepMcpValue, listKeptValues, } from "./features/mcps/values.js";
57
+ import { assignKeptValue, forgetMcpValue, forgetUnassignedValue, keepMcpValue, listKeptValues, recordedMcpServers, } from "./features/mcps/values.js";
57
58
  import { readSettings } from "./config/settings.js";
58
59
  /** Keep command help readable at the conventional eighty-column terminal width. */
59
60
  const HELP_WIDTH = 80;
@@ -343,6 +344,7 @@ export function createProgram(options = {}) {
343
344
  forgetUnassignedValue: options.forgetUnassignedValue ??
344
345
  ((variable) => forgetUnassignedValue(variable, runtime)),
345
346
  listKeptValues: options.listKeptValues ?? (() => listKeptValues(runtime)),
347
+ recordedMcpServers: options.recordedMcpServers ?? (() => recordedMcpServers(runtime)),
346
348
  showPackage: options.showPackage ??
347
349
  ((kind, name, origin) => showPackage(kind, name, origin, runtime)),
348
350
  showMcp: options.showMcp ?? ((name, origin) => showMcp(name, origin, runtime)),
@@ -356,6 +358,7 @@ export function createProgram(options = {}) {
356
358
  ((name, origin, testOptions) => testHook(name, origin, testOptions, runtime)),
357
359
  hookCompatibility: options.hookCompatibility ??
358
360
  ((name, origin) => hookCompatibility(name, origin, runtime)),
361
+ allHookCompatibility: options.allHookCompatibility ?? (() => allHookCompatibility(runtime)),
359
362
  adaptHook: options.adaptHook ??
360
363
  ((name, origin, targets) => adaptHook(name, origin, targets, runtime)),
361
364
  knowledgeGet: options.knowledgeGet ?? ((name) => knowledgeGet(name, runtime)),
@@ -11,7 +11,7 @@ import { LOCAL_ORIGIN } from "../features/workspace/overlay.js";
11
11
  import { saveImported } from "../features/imports/local.js";
12
12
  import { assertSourceExists, plainFolder } from "../features/imports/folder.js";
13
13
  import { fetchRemote, parseLocation } from "../features/imports/remote.js";
14
- import { bold, dim, ok, warn } from "./format.js";
14
+ import { bold, choiceDescription, dim, ok, warn } from "./format.js";
15
15
  import { setYamlName, slugify } from "../shared/patterns.js";
16
16
  import { only } from "../shared/lookup.js";
17
17
  import { assertDistinctNames, finish, folderLabel, notFound, onlyChosen, updateMode, } from "./add-asset.js";
@@ -72,7 +72,7 @@ async function choosePackages(packages, url, options, context) {
72
72
  name: `${p.name} ${dim(folderLabel(p.root))}`,
73
73
  value: p.root,
74
74
  short: p.name,
75
- description: `Description: ${p.description}`,
75
+ description: choiceDescription(`Description: ${p.description}`),
76
76
  })));
77
77
  chosen = packages.filter((p) => picked.includes(p.root));
78
78
  }
@@ -7,7 +7,11 @@ 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
+ import { displayPath, keptValueFiles } from "./output.js";
11
+ import { variableProblemLines } from "./variable-problems.js";
12
+ import { keptValuesMessage } from "../features/environment/events.js";
13
+ import { urlQueries } from "../features/asset-kinds/url-query.js";
14
+ import { LOCAL_URL_QUERY, renderMcpValues, renderSignIn, renderUrlQueries, } from "./mcp.js";
11
15
  async function serversToAdd(name, options, context) {
12
16
  if (options.config) {
13
17
  return parseMcpText(options.config, name);
@@ -118,6 +122,23 @@ async function namedServers(servers, as, context) {
118
122
  }
119
123
  return result;
120
124
  }
125
+ /**
126
+ * Warns about URLs with a query string, which BarnDog keeps as written, and in
127
+ * a terminal asks whether to add them; elsewhere the added servers' notes say so.
128
+ */
129
+ async function confirmUrlQueries(servers, context) {
130
+ const queries = urlQueries(servers);
131
+ if (!queries.length || !context.interactive) {
132
+ return;
133
+ }
134
+ for (const line of renderUrlQueries(queries)) {
135
+ context.write(line);
136
+ }
137
+ context.write(dim(LOCAL_URL_QUERY));
138
+ if (!(await context.prompts.yes(`Add ${queries.length === 1 ? "it" : "them"}?`))) {
139
+ throw new CliError("Nothing was added.");
140
+ }
141
+ }
121
142
  /**
122
143
  * `mcp add`: imports MCP servers from a harness's configuration or pasted JSON
123
144
  * into the local workspace.
@@ -145,6 +166,7 @@ export async function addMcp(name, options, context) {
145
166
  if (!servers.length) {
146
167
  throw new CliError("No MCP servers were chosen, so nothing was added.");
147
168
  }
169
+ await confirmUrlQueries(servers, context);
148
170
  let replace = options.replace;
149
171
  const conflicts = (await Promise.all(servers.map((s) => conflictingEntries(s.name, context.runtime)))).flat();
150
172
  if (conflicts.length && !replace && context.interactive) {
@@ -159,18 +181,28 @@ export async function addMcp(name, options, context) {
159
181
  }
160
182
  const keep = await chooseKept(servers.flatMap((server) => server.literals.map((literal) => ({ server: server.name, literal }))), context);
161
183
  const result = await addMcpServers(servers, { replace, keep }, context.runtime);
162
- for (const line of renderAddedServers(result)) {
184
+ for (const line of renderAddedServers(result, context.runtime)) {
163
185
  context.write(line);
164
186
  }
165
187
  }
166
188
  /** What `mcp add` added, what's left to do, and where it backed up settings. */
167
- function renderAddedServers(result) {
189
+ function renderAddedServers(result, runtime) {
168
190
  return [
169
191
  ...result.added.map((added) => `${ok("✔")} Added ${bold(added)}`),
170
192
  ...result.notes.map((note) => `${warn("!")} ${bold(note.server)}: ${note.text}`),
193
+ ...renderSignIn(result.signIn),
171
194
  ...renderMcpValues(result.values),
172
195
  // 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}`)),
196
+ ...result.events.flatMap((event) => {
197
+ if (event.type === "kept-values") {
198
+ return [
199
+ dim(keptValuesMessage(event)),
200
+ ...keptValueFiles(event, runtime),
201
+ ];
202
+ }
203
+ return event.type === "notice" ? [dim(event.message)] : [];
204
+ }),
205
+ ...result.backups.map((backup) => dim(`Backup: ${displayPath(backup, runtime)}`)),
206
+ ...variableProblemLines(result.events, result.values),
175
207
  ];
176
208
  }
@@ -4,7 +4,7 @@ import { discoverSkills, } from "../features/imports/discover.js";
4
4
  import { renamedSkill, saveImported } from "../features/imports/local.js";
5
5
  import { assertSourceExists, plainFolder, readFolder, removeImported, } from "../features/imports/folder.js";
6
6
  import { fetchRemote, parseLocation, } from "../features/imports/remote.js";
7
- import { bold, dim, ok, warn } from "./format.js";
7
+ import { bold, choiceDescription, dim, ok, warn } from "./format.js";
8
8
  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. */
@@ -76,7 +76,7 @@ export async function addSkills(url, options, context) {
76
76
  name: `${s.name} ${dim(folderLabel(s.root))}`,
77
77
  value: s.root,
78
78
  short: distinctName(s),
79
- description: `Description: ${s.description}`,
79
+ description: choiceDescription(`Description: ${s.description}`),
80
80
  })));
81
81
  chosen = skills.filter((s) => picked.includes(s.root));
82
82
  }
package/dist/ui/adopt.js CHANGED
@@ -2,11 +2,12 @@ import checkbox, { Separator } from "@inquirer/checkbox";
2
2
  import confirm from "@inquirer/confirm";
3
3
  import { adoptNative, adoptionPlan, } from "../features/adoption/adopt.js";
4
4
  import { scanNative, } from "../features/adoption/scan.js";
5
- import { friendlyMessage } from "../errors.js";
5
+ import { friendlyMessage, promptCancelled } from "../errors.js";
6
6
  import { harnesses, adapters } from "../harnesses/registry.js";
7
- import { bold, dim, heading, hint, ok, plural, table, warn } from "./format.js";
7
+ import { bold, checklistPageSize, choiceDescription, dim, heading, hint, ok, plural, table, warn, } from "./format.js";
8
8
  import { displayPath } from "./output.js";
9
- import { renderMcpValues } from "./mcp.js";
9
+ import { variableProblemLines } from "./variable-problems.js";
10
+ import { LOCAL_URL_QUERY, renderMcpValues, renderSignIn, renderUrlQueries, } from "./mcp.js";
10
11
  import { checkboxTheme, promptTheme } from "./theme.js";
11
12
  const kindLabels = {
12
13
  skill: "Skill",
@@ -57,21 +58,72 @@ export function renderScan(scan, runtime) {
57
58
  }
58
59
  return output;
59
60
  }
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) => ({
61
+ /**
62
+ * Columns Inquirer draws before a choice's name (cursor, then a circle such as
63
+ * ` ◯`, then a space); a text row is indented to match.
64
+ */
65
+ const CHOICE_PREFIX_WIDTH = 4;
66
+ /** What a same-named copy picked in an earlier tool's checklist does to this one, if one was picked. */
67
+ function broughtAlong(asset, picked) {
68
+ const twin = asset.sameName.find((other) => picked.includes(other.key));
69
+ if (!twin) {
70
+ return undefined;
71
+ }
72
+ const tool = adapters[twin.harness].name;
73
+ return asset.identical
74
+ ? `already comes with ${tool}`
75
+ : warn(`replaced by ${tool}'s copy`);
76
+ }
77
+ /**
78
+ * One tool's checklist: the assets still to choose, then, as text the cursor
79
+ * skips, those an earlier pick already brings along. Returns no choices when
80
+ * nothing is left to pick.
81
+ */
82
+ function adoptionChoices(items, picked) {
83
+ const nameWidth = Math.max(...items.map((asset) => asset.name.length));
84
+ const label = (asset) => `${kindLabels[asset.kind].padEnd(kindWidth)} ${asset.name.padEnd(nameWidth)}`;
85
+ const open = items.filter((asset) => !broughtAlong(asset, picked));
86
+ const along = items.flatMap((asset) => {
87
+ const note = broughtAlong(asset, picked);
88
+ return note
89
+ ? [
90
+ new Separator(`${" ".repeat(CHOICE_PREFIX_WIDTH - 1)}${dim(label(asset))} ${note}`),
91
+ ]
92
+ : [];
93
+ });
94
+ if (!open.length) {
95
+ return [];
96
+ }
97
+ return [
98
+ ...open.map((asset) => ({
66
99
  value: asset.key,
67
100
  checked: false,
68
101
  short: asset.key,
69
- name: `${kindLabels[asset.kind].padEnd(kindWidth)} ${asset.name}${sharing(asset) ? dim(` ${sharing(asset)}`) : ""}`,
70
- description: asset.description,
102
+ name: `${label(asset)}${sharing(asset) ? dim(` ${sharing(asset)}`) : ""}`,
103
+ description: choiceDescription(asset.description),
71
104
  })),
72
- ]),
73
- theme: checkboxTheme,
74
- });
105
+ ...along,
106
+ ];
107
+ }
108
+ /** Asks tool by tool, so each checklist names the tool its assets are in. */
109
+ const chooseAdoption = async (scan) => {
110
+ const picked = [];
111
+ for (const { harness, items } of byTool(scan.assets)) {
112
+ const choices = adoptionChoices(items, picked);
113
+ // Inquirer refuses a checklist with nothing left to pick.
114
+ if (!choices.length) {
115
+ continue;
116
+ }
117
+ picked.push(...(await checkbox({
118
+ loop: false,
119
+ message: `Which ${bold(adapters[harness].name)} assets should BarnDog adopt?`,
120
+ choices,
121
+ pageSize: checklistPageSize(items.length),
122
+ theme: checkboxTheme,
123
+ })));
124
+ }
125
+ return picked;
126
+ };
75
127
  /** What an adoption will take over, including other tools' copies BarnDog's one replaces. */
76
128
  function renderPlan(plan) {
77
129
  const output = [bold("BarnDog will adopt")];
@@ -84,6 +136,13 @@ function renderPlan(plan) {
84
136
  : "",
85
137
  ])));
86
138
  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."));
139
+ // Same-named copies share one source, so each server is named once.
140
+ const queries = plan
141
+ .filter((asset) => asset.key === asset.source.key)
142
+ .flatMap(({ name, queryParameters: parameters }) => parameters.length ? [{ name, parameters }] : []);
143
+ if (queries.length) {
144
+ output.push("", ...renderUrlQueries(queries), dim(LOCAL_URL_QUERY));
145
+ }
87
146
  return output;
88
147
  }
89
148
  const confirmAdoption = (plan) => confirm({
@@ -99,7 +158,9 @@ export function renderAdoption(result, runtime) {
99
158
  for (const note of result.notes) {
100
159
  output.push(`${warn("!")} ${kindLabels[note.kind]} ${bold(note.name)}: ${note.text}`);
101
160
  }
161
+ output.push(...renderSignIn(result.signIn));
102
162
  output.push(...renderMcpValues(result.values));
163
+ output.push(...variableProblemLines(result.events, result.values));
103
164
  output.push("", result.canShare
104
165
  ? hint("barndog local move", "Tip") +
105
166
  dim(" share them through your workspace")
@@ -133,6 +194,7 @@ export function renderAdoptions(list) {
133
194
  const chooseKeptValues = (values) => checkbox({
134
195
  loop: false,
135
196
  message: "Which values should BarnDog keep on this machine?",
197
+ pageSize: checklistPageSize(values.length),
136
198
  choices: values.map((value) => ({
137
199
  name: `${value.variable} ${dim(`${value.server}: ${value.key}`)}`,
138
200
  short: value.variable,
@@ -196,6 +258,10 @@ export async function offerAdoptionAtSetup(runtime, prompt) {
196
258
  }
197
259
  }
198
260
  catch (error) {
261
+ if (promptCancelled(error)) {
262
+ prompt.write(`${dim("Adoption cancelled; nothing was adopted. Run")} ${bold("barndog adopt")} ${dim("any time.")}`);
263
+ return;
264
+ }
199
265
  prompt.write(`${warn("!")} Nothing was adopted: ${friendlyMessage(error)}`);
200
266
  prompt.write(hint("barndog adopt", "Tip") + dim(" try again later"));
201
267
  }
package/dist/ui/assets.js CHANGED
@@ -5,11 +5,14 @@ import { displayPath } from "./output.js";
5
5
  import { badge, bold, clean, dim, hint, ok, originLabel, plural, section, table, } from "./format.js";
6
6
  export const harnessNames = (harnesses) => harnesses.map((h) => adapters[h].name).join(", ");
7
7
  const listGroup = (state) => state === "available" || state === "disabled" ? state : "installed";
8
- /** Outdated assets look pending and modified ones look clashed. */
8
+ /** Outdated assets look pending, modified ones look clashed, Hooks that can't run look skipped. */
9
9
  function badgeState(state) {
10
10
  if (state === "outdated") {
11
11
  return "pending";
12
12
  }
13
+ if (state === "cant-run") {
14
+ return "skipped";
15
+ }
13
16
  return state === "modified" ? "clash" : state;
14
17
  }
15
18
  /** Installed first, then disabled, then available; no filter means all three. */
@@ -40,11 +43,17 @@ const stateLabel = {
40
43
  installed: "installed",
41
44
  disabled: "disabled",
42
45
  pending: "pending",
46
+ "cant-run": "can't run",
47
+ "no-version": "no version for your tools",
43
48
  outdated: "update available",
44
49
  clash: "clash",
45
50
  modified: "edited by hand",
46
51
  removing: "pending removal",
47
52
  };
53
+ /** A state as a table or picker shows it: colored by how much it needs attention. */
54
+ export function stateBadge(state) {
55
+ return badge(badgeState(state), stateLabel[state]);
56
+ }
48
57
  /** One table of what is selected and installed, with an optional path listing. */
49
58
  export function renderInventory(items, options) {
50
59
  const output = [];
@@ -59,7 +68,7 @@ export function renderInventory(items, options) {
59
68
  dim(item.harnesses.length
60
69
  ? item.harnesses.map((h) => adapters[h].name).join(", ")
61
70
  : "—"),
62
- badge(badgeState(item.state), stateLabel[item.state]),
71
+ stateBadge(item.state),
63
72
  ]), { header: ["Name", "Origin", "Via", "Installed in", "State"], flex: 2 }));
64
73
  if (options.paths) {
65
74
  for (const item of items) {
@@ -90,6 +99,10 @@ export function inventoryHints(items) {
90
99
  output.push(hint("barndog sync", "Fix") +
91
100
  dim(" in a terminal to choose how to resolve name clashes"));
92
101
  }
102
+ if (count("cant-run")) {
103
+ output.push(hint("barndog doctor", "Fix") +
104
+ dim(` to see what ${plural(count("cant-run"), "Hook")} ${count("cant-run") === 1 ? "needs" : "need"} to run`));
105
+ }
93
106
  return output;
94
107
  }
95
108
  /**
@@ -82,7 +82,7 @@ function executableNote(previous, next) {
82
82
  return ` executable: ${safe(previous)} → ${safe(next)}`;
83
83
  }
84
84
  /** Results are told apart by their shape, not by the command that produced them. */
85
- export function renderCollaboration(value, options = {}) {
85
+ export function renderCollaboration(value, options) {
86
86
  if (Array.isArray(value)) {
87
87
  if (!value.length) {
88
88
  return ["No changes."];
@@ -142,7 +142,7 @@ export function renderCollaboration(value, options = {}) {
142
142
  }
143
143
  if (value && typeof value === "object") {
144
144
  if (isEnvironmentPreview(value)) {
145
- return renderSyncOutput(value.events, {
145
+ return renderSyncOutput(value.events, options.runtime, {
146
146
  title: "preview",
147
147
  preview: true,
148
148
  });
@@ -191,7 +191,9 @@ export function renderCollaboration(value, options = {}) {
191
191
  ? ["Submission awaiting confirmation; retry barndog push."]
192
192
  : []),
193
193
  ...status.conflicts.map((path) => `Conflict: ${safe(path)}`),
194
- ...renderCollaboration(status.changes).filter((line) => !line.startsWith("@@") && !line.startsWith("+")),
194
+ ...renderCollaboration(status.changes, {
195
+ runtime: options.runtime,
196
+ }).filter((line) => !line.startsWith("@@") && !line.startsWith("+")),
195
197
  ];
196
198
  }
197
199
  const workingCopy = workingCopySchema.safeParse(value);