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