barndog 0.2.1 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/README.md +21 -0
  2. package/dist/cli.js +29 -3
  3. package/dist/commands/add.js +4 -2
  4. package/dist/commands/asset-install.js +7 -3
  5. package/dist/commands/asset-list.js +5 -1
  6. package/dist/commands/asset-share.js +15 -3
  7. package/dist/commands/capabilities.js +23 -5
  8. package/dist/commands/collaboration.js +9 -3
  9. package/dist/commands/harnesses.js +33 -3
  10. package/dist/commands/hooks.js +16 -1
  11. package/dist/commands/mcp-env.js +159 -43
  12. package/dist/commands/mcp.js +13 -3
  13. package/dist/commands/origin.js +7 -4
  14. package/dist/commands/sets.js +16 -5
  15. package/dist/commands/status.js +3 -1
  16. package/dist/commands/sync.js +1 -1
  17. package/dist/commands/uninstall.js +64 -0
  18. package/dist/commands/workspace.js +19 -0
  19. package/dist/config/paths.js +2 -0
  20. package/dist/config/state.js +19 -0
  21. package/dist/entry/update-check.js +15 -0
  22. package/dist/errors.js +4 -0
  23. package/dist/features/adoption/adopt.js +47 -29
  24. package/dist/features/adoption/scan.js +5 -0
  25. package/dist/features/asset-kinds/url-query.js +26 -0
  26. package/dist/features/auth/session.js +22 -0
  27. package/dist/features/collaboration/workspace-store.js +2 -1
  28. package/dist/features/doctor/check.js +1 -0
  29. package/dist/features/doctor/grouped.js +127 -0
  30. package/dist/features/doctor/index.js +29 -27
  31. package/dist/features/environment/events.js +18 -1
  32. package/dist/features/environment/kept-value-events.js +40 -0
  33. package/dist/features/environment/kept-values.js +68 -0
  34. package/dist/features/environment/mcp-records.js +57 -0
  35. package/dist/features/environment/moves.js +17 -1
  36. package/dist/features/environment/stage.js +32 -28
  37. package/dist/features/environment/sync.js +13 -3
  38. package/dist/features/environment/writes.js +25 -27
  39. package/dist/features/hooks/compatibility.js +37 -17
  40. package/dist/features/hooks/test.js +2 -2
  41. package/dist/features/inventory/hook-matrix.js +14 -0
  42. package/dist/features/inventory/hook-readiness.js +47 -0
  43. package/dist/features/inventory/index.js +54 -3
  44. package/dist/features/inventory/show.js +10 -2
  45. package/dist/features/mcps/import.js +74 -21
  46. package/dist/features/mcps/index.js +28 -5
  47. package/dist/features/mcps/values.js +161 -23
  48. package/dist/features/migration/migrate.js +15 -0
  49. package/dist/features/migration/move.js +38 -9
  50. package/dist/features/migration/promote.js +1 -0
  51. package/dist/features/native/adapters.js +5 -46
  52. package/dist/features/native/hook-shell.js +11 -0
  53. package/dist/features/native/requirements.js +98 -0
  54. package/dist/features/secrets/index.js +95 -29
  55. package/dist/features/uninstall/index.js +126 -0
  56. package/dist/features/uninstall/leave.js +152 -0
  57. package/dist/features/uninstall/survey.js +103 -0
  58. package/dist/features/update-check/index.js +108 -0
  59. package/dist/features/workspace/cloud-source.js +38 -4
  60. package/dist/features/workspace/format.js +6 -1
  61. package/dist/harnesses/claude.js +1 -1
  62. package/dist/harnesses/codex.js +46 -22
  63. package/dist/harnesses/cursor.js +1 -1
  64. package/dist/harnesses/opencode.js +1 -1
  65. package/dist/harnesses/read-renamed-variables.js +141 -0
  66. package/dist/harnesses/renamed-variables.js +99 -0
  67. package/dist/platform.js +12 -1
  68. package/dist/program.js +24 -9
  69. package/dist/ui/add-hook.js +2 -2
  70. package/dist/ui/add-mcp.js +54 -16
  71. package/dist/ui/add-skills.js +2 -2
  72. package/dist/ui/adopt.js +90 -19
  73. package/dist/ui/assets.js +15 -2
  74. package/dist/ui/collaboration.js +5 -3
  75. package/dist/ui/connection.js +2 -0
  76. package/dist/ui/format.js +81 -2
  77. package/dist/ui/harness-picker.js +7 -2
  78. package/dist/ui/hook-compatibility.js +176 -22
  79. package/dist/ui/mcp.js +169 -24
  80. package/dist/ui/move.js +3 -2
  81. package/dist/ui/onboarding.js +11 -2
  82. package/dist/ui/output.js +116 -37
  83. package/dist/ui/package-details.js +7 -2
  84. package/dist/ui/pick.js +20 -6
  85. package/dist/ui/secret-input.js +9 -0
  86. package/dist/ui/selection.js +1 -1
  87. package/dist/ui/uninstall.js +186 -0
  88. package/dist/ui/update.js +10 -0
  89. package/dist/ui/variable-problems.js +23 -0
  90. package/dist/version.js +2 -2
  91. package/package.json +2 -2
  92. package/dist/entry/mcp-launch.js +0 -71
package/README.md CHANGED
@@ -4,6 +4,8 @@ Set up your AI coding environment once, and have it show up in Claude Code, Code
4
4
 
5
5
  `barndog` is the command-line tool for [BarnDog](https://barndog.dev). It installs Skills, MCP servers, Hooks, and knowledge into the coding agents you already use, keeps them up to date, and lets you improve them like code. It works the same whether it's just you, a small team, or a whole organization; only where the assets live changes.
6
6
 
7
+ <img width="1832" height="1080" alt="yurii — -zsh — 139×39 (Window) 2026-11-24 12 03 AM" src="https://github.com/user-attachments/assets/e8454b86-b017-430b-b7dc-caa454bd675c" />
8
+
7
9
  Currently supported harnesses:
8
10
 
9
11
  - Claude Code
@@ -61,6 +63,16 @@ Runs on **macOS, Linux, and Windows** with [Node.js](https://nodejs.org) 24 or n
61
63
  npm install -g barndog
62
64
  ```
63
65
 
66
+ ### Update
67
+
68
+ ```sh
69
+ npm install -g barndog@latest
70
+ barndog sync
71
+ barndog --version
72
+ ```
73
+
74
+ Run `barndog sync` after every update: it brings the session-start and Hook registrations in your coding tools in line with the new version.
75
+
64
76
  ## Quick start
65
77
 
66
78
  ```sh
@@ -96,6 +108,15 @@ BarnDog is careful with your existing setup:
96
108
  - Changes are journaled before they're applied, so an interrupted sync is finished safely on the next run.
97
109
  - Hook scripts run only inside your coding tools, after their own trust checks. Installing or syncing never runs them.
98
110
 
111
+ ## Uninstall
112
+
113
+ ```sh
114
+ barndog uninstall
115
+ npm uninstall -g barndog
116
+ ```
117
+
118
+ Run `barndog uninstall` first. It asks whether to leave your Skills, MCP servers, and Hooks in your coding tools or remove them.
119
+
99
120
  ## Documentation
100
121
 
101
122
  - [What is BarnDog?](https://barndog.dev/docs)
package/dist/cli.js CHANGED
@@ -1,16 +1,21 @@
1
1
  #!/usr/bin/env node
2
+ import { spawn } from "node:child_process";
3
+ import { fileURLToPath } from "node:url";
2
4
  import { CommanderError, InvalidArgumentError } from "commander";
3
5
  import { assertCommandAvailable, currentSetupMode, } from "./commands/availability.js";
4
6
  import { captureRuntime, createProgram } from "./program.js";
5
7
  import { renderError, renderJsonError } from "./ui/output.js";
6
8
  import { json } from "./ui/format.js";
7
- import { CliError, NothingToDoError } from "./errors.js";
9
+ import { CliError, NothingToDoError, promptCancelled } from "./errors.js";
10
+ import { updateCheck } from "./features/update-check/index.js";
11
+ import { renderUpdateNotice } from "./ui/update.js";
12
+ import { cliVersion } from "./version.js";
8
13
  // Parsing errors happen before any action runs, so read the flag directly.
9
14
  const words = process.argv.slice(2);
10
15
  const end = words.indexOf("--");
11
16
  const asJson = (end < 0 ? words : words.slice(0, end)).includes("--json");
17
+ const runtime = captureRuntime();
12
18
  try {
13
- const runtime = captureRuntime();
14
19
  await createProgram({
15
20
  runtime,
16
21
  guard: (path, options) => assertCommandAvailable(path, options, runtime),
@@ -29,7 +34,7 @@ catch (error) {
29
34
  : error.message.replace(/^error: /, ""))));
30
35
  }
31
36
  }
32
- else if (error instanceof Error && error.name === "ExitPromptError") {
37
+ else if (promptCancelled(error)) {
33
38
  const message = "Cancelled. Nothing was changed.";
34
39
  console.log(asJson ? json({ message }) : message);
35
40
  process.exitCode = 130;
@@ -42,3 +47,24 @@ catch (error) {
42
47
  process.exitCode = 1;
43
48
  }
44
49
  }
50
+ // After the command, on stderr, so it never changes what a script reads; and
51
+ // it can never fail the command.
52
+ if (!asJson && process.stderr.isTTY) {
53
+ try {
54
+ const check = await updateCheck(cliVersion, runtime);
55
+ if (check?.update) {
56
+ console.error(renderUpdateNotice(check.update).join("\n"));
57
+ }
58
+ if (check?.due) {
59
+ spawn(process.execPath, [
60
+ fileURLToPath(new URL("entry/update-check.js", import.meta.url)),
61
+ runtime.home,
62
+ ], { detached: true, windowsHide: true, stdio: "ignore" })
63
+ .on("error", () => { })
64
+ .unref();
65
+ }
66
+ }
67
+ catch {
68
+ // The next command checks again.
69
+ }
70
+ }
@@ -96,13 +96,15 @@ export function registerAdd(program, context) {
96
96
  for (const result of results) {
97
97
  context.write(`${result.name}: ${result.changes.length ? `${result.changes.length} file${result.changes.length === 1 ? "" : "s"} changed` : "up to date"}`);
98
98
  if (result.changes.length) {
99
- for (const line of renderCollaboration(result.changes)) {
99
+ for (const line of renderCollaboration(result.changes, {
100
+ runtime: context.runtime,
101
+ })) {
100
102
  context.write(line);
101
103
  }
102
104
  }
103
105
  }
104
106
  if (applied) {
105
- for (const line of renderSyncOutput(events)) {
107
+ for (const line of renderSyncOutput(events, context.runtime)) {
106
108
  context.write(line);
107
109
  }
108
110
  context.write(`${ok("✔")} Update installed.`);
@@ -2,7 +2,8 @@ import { Option } from "commander";
2
2
  import { prefixedName } from "../features/environment/names.js";
3
3
  import { runSelection } from "../ui/selection.js";
4
4
  import { pickMany, pickOne } from "../ui/pick.js";
5
- import { bold, clean, ok, ORIGIN_HELP, originLabel } from "../ui/format.js";
5
+ import { bold, clean, dim, ok, ORIGIN_HELP, originLabel, } from "../ui/format.js";
6
+ import { stateBadge } from "../ui/assets.js";
6
7
  import { assetKinds } from "../features/asset-kinds/index.js";
7
8
  import { addArguments, requireArguments } from "./arguments.js";
8
9
  import { ask } from "./asset-share.js";
@@ -18,7 +19,7 @@ function localCandidates(items, kind, action, origin) {
18
19
  const localChoice = (item) => ({
19
20
  value: item,
20
21
  name: item.installedName,
21
- hint: `${item.origin} · ${item.state}`,
22
+ columns: [dim(item.origin), stateBadge(item.state)],
22
23
  });
23
24
  /** `install`: adds assets of one kind to the selection and syncs. */
24
25
  export function registerInstall(command, kind, context) {
@@ -56,7 +57,10 @@ export function registerInstall(command, kind, context) {
56
57
  .map((row) => ({
57
58
  value: row.id,
58
59
  name: row.name,
59
- hint: `${originLabel(row.origin)} · ${clean(row.version.description)}`,
60
+ columns: [
61
+ dim(originLabel(row.origin)),
62
+ dim(clean(row.version.description)),
63
+ ],
60
64
  })), {
61
65
  empty: inOrigin.length
62
66
  ? `Every available ${labels.one} is already on this machine.`
@@ -4,6 +4,7 @@ import { assetListing, inventoryHints, renderCatalog, renderInventory, } from ".
4
4
  import { dim, hint, json } from "../ui/format.js";
5
5
  import { assetKinds } from "../features/asset-kinds/index.js";
6
6
  import { addArguments } from "./arguments.js";
7
+ import { unsetVariableNotes } from "../ui/mcp.js";
7
8
  /** `list`: installed, disabled and available assets of one kind. */
8
9
  export function registerList(command, kind, context) {
9
10
  const labels = assetKinds[kind];
@@ -22,7 +23,7 @@ export function registerList(command, kind, context) {
22
23
  const onlyAvailable = options.available && !narrowed;
23
24
  let catalogProblem;
24
25
  const [inventory, rows] = await Promise.all([
25
- context.inventory(),
26
+ context.inventory({ checkVariables: kind === "mcp" }),
26
27
  options.available || !narrowed
27
28
  ? context.searchCatalog(kind).catch((error) => {
28
29
  // JSON has nowhere to say the list is partial, so it fails;
@@ -83,6 +84,9 @@ export function registerList(command, kind, context) {
83
84
  }
84
85
  }
85
86
  const onThisMachine = page.filter((item) => item.state !== "available");
87
+ for (const line of unsetVariableNotes(onThisMachine)) {
88
+ context.write(line);
89
+ }
86
90
  const hints = inventoryHints(onThisMachine);
87
91
  if (hints.length) {
88
92
  context.write(["", ...hints].join("\n"));
@@ -1,9 +1,10 @@
1
1
  import { renderMove } from "../ui/move.js";
2
+ import { confirmSharingUrlQuery } from "../ui/mcp.js";
2
3
  import input from "@inquirer/input";
3
4
  import { CliError } from "../errors.js";
4
5
  import { pickOne } from "../ui/pick.js";
5
6
  import { promptTheme } from "../ui/theme.js";
6
- import { bold, clean, hint, json, ok, ORIGIN_HELP, originLabel, } from "../ui/format.js";
7
+ import { bold, clean, dim, hint, json, ok, ORIGIN_HELP, originLabel, } from "../ui/format.js";
7
8
  import { assetKinds } from "../features/asset-kinds/index.js";
8
9
  import { requireArguments } from "./arguments.js";
9
10
  /** Asks for a value in a terminal, or explains the flag to pass. */
@@ -37,7 +38,10 @@ export function registerSharing(command, kind, context) {
37
38
  const row = await pickOne(`Choose ${labels.a} to ${action}`, (await context.searchCatalog(kind)).map((row) => ({
38
39
  value: row,
39
40
  name: row.name,
40
- hint: `${originLabel(row.origin)} · ${clean(row.version.description)}`,
41
+ columns: [
42
+ dim(originLabel(row.origin)),
43
+ dim(clean(row.version.description)),
44
+ ],
41
45
  })));
42
46
  name = row.name;
43
47
  origin = originLabel(row.origin);
@@ -69,7 +73,15 @@ export function registerSharing(command, kind, context) {
69
73
  outcome: "promoted",
70
74
  promotion: await context.fork(input),
71
75
  }
72
- : await context.promote(input);
76
+ : await context.promote({
77
+ ...input,
78
+ confirmUrlQuery: confirmSharingUrlQuery({
79
+ interactive: context.mode.interactive,
80
+ write: context.write,
81
+ // Promoting a local asset shares a copy, as this does.
82
+ fix: `barndog local move ${name} --keep-local --to ${target} --allow-url-query`,
83
+ }),
84
+ });
73
85
  if (outcome.outcome === "moved") {
74
86
  if (context.mode.json) {
75
87
  return context.write(json(outcome.move));
@@ -1,5 +1,5 @@
1
1
  import { openBrowser } from "../ui/auth.js";
2
- import { bad, bold, dim, fields, heading, hint, json, ok, warn, } from "../ui/format.js";
2
+ import { bad, bold, dim, fields, heading, hint, json, labelledLists, ok, plural, table, warn, } from "../ui/format.js";
3
3
  import { registerMcp } from "./mcp.js";
4
4
  import { registerHooks } from "./hooks.js";
5
5
  import { registerKnowledge } from "./knowledge.js";
@@ -108,29 +108,47 @@ function registerGeneral(program, context) {
108
108
  .command("doctor")
109
109
  .description("Check your setup, session and installed assets, and suggest fixes")
110
110
  .action(async () => {
111
- const checks = await context.doctor();
111
+ const { checks, hooksMissingTools } = await context.doctor();
112
112
  if (context.mode.json) {
113
113
  return context.write(json(checks));
114
114
  }
115
115
  context.write(`\n${heading("doctor")}\n`);
116
116
  const width = Math.max(...checks.map((c) => c.name.length));
117
+ // Lines under a check start where its detail does.
118
+ const under = ` ${" ".repeat(width)} `;
117
119
  for (const check of checks) {
118
120
  const mark = checkMarks[check.status];
119
121
  context.write(`${mark} ${check.name.padEnd(width)} ${check.status === "ok" ? dim(check.detail) : check.detail}`);
122
+ for (const line of labelledLists(check.rows ?? [], {
123
+ indent: under.length,
124
+ })) {
125
+ context.write(line);
126
+ }
127
+ if (check.table) {
128
+ context.write("");
129
+ for (const line of table(check.table.map(([first = "", ...rest]) => [bold(first), ...rest]), { indent: under.length })) {
130
+ context.write(line);
131
+ }
132
+ context.write("");
133
+ }
120
134
  if (check.fix) {
121
135
  // A fix in words reads as plain text when a command follows it.
122
136
  context.write(check.command
123
- ? ` ${" ".repeat(width)} ${dim("Fix:")} ${check.fix}`
124
- : ` ${" ".repeat(width)} ${hint(check.fix, "Fix")}`);
137
+ ? `${under}${dim("Fix:")} ${check.fix}`
138
+ : `${under}${hint(check.fix, "Fix")}`);
125
139
  }
126
140
  if (check.command) {
127
- context.write(` ${" ".repeat(width)} ${dim("Command:")} ${bold(check.command)}`);
141
+ context.write(`${under}${dim("Command:")} ${bold(check.command)}`);
128
142
  }
129
143
  }
130
144
  const failed = checks.filter((c) => c.status === "fail").length;
131
145
  const warned = checks.filter((c) => c.status === "warn").length;
132
146
  context.write("");
133
147
  context.write(doctorSummary(failed, warned));
148
+ if (hooksMissingTools) {
149
+ context.write("");
150
+ context.write(`${dim(`Tip: ${plural(hooksMissingTools, "Hook")} ${hooksMissingTools === 1 ? "is" : "are"} written for only some of your tools.`)} ${bold("barndog hooks compatibility --all")}${dim(" to see which")}`);
151
+ }
134
152
  if (failed) {
135
153
  process.exitCode = 1;
136
154
  }
@@ -11,7 +11,7 @@ import { packageKindList } from "../config/selection.js";
11
11
  import { pickOne } from "../ui/pick.js";
12
12
  import { renderPackageDetails } from "../ui/package-details.js";
13
13
  import { resolveOrigin } from "./origin.js";
14
- import { clean, json, ORIGIN_HELP, originLabel, warn } from "../ui/format.js";
14
+ import { clean, dim, json, ORIGIN_HELP, originLabel, warn, } from "../ui/format.js";
15
15
  import { defined } from "../shared/lookup.js";
16
16
  import { positiveInteger } from "../ui/options.js";
17
17
  function side(value) {
@@ -27,7 +27,10 @@ function printer(context) {
27
27
  context.write(json(result));
28
28
  }
29
29
  else {
30
- for (const line of renderCollaboration(result, options)) {
30
+ for (const line of renderCollaboration(result, {
31
+ ...options,
32
+ runtime: context.runtime,
33
+ })) {
31
34
  context.write(line);
32
35
  }
33
36
  }
@@ -138,7 +141,10 @@ export function registerCollaboration(program, context, kind) {
138
141
  const row = await pickOne(`Choose a ${noun}`, rows.map((row) => ({
139
142
  value: row,
140
143
  name: row.name,
141
- hint: `${originLabel(row.origin)} · ${clean(row.version.description)}`,
144
+ columns: [
145
+ dim(originLabel(row.origin)),
146
+ dim(clean(row.version.description)),
147
+ ],
142
148
  })), { empty: `No ${noun}s are published yet.` });
143
149
  return { name: row.name, origin: originLabel(row.origin) };
144
150
  };
@@ -11,6 +11,18 @@ function managedLine(managed) {
11
11
  ? `${ok("✔")} BarnDog now manages ${toolNames(managed)}.`
12
12
  : `${ok("✔")} BarnDog no longer manages any coding tool. Add one with ${styleText("bold", "barndog harnesses enable <harness>")}.`;
13
13
  }
14
+ const pickMessage = {
15
+ enable: "Which coding tools should BarnDog start managing?",
16
+ disable: "Which coding tools should BarnDog stop managing?",
17
+ };
18
+ const nothingTo = {
19
+ enable: "BarnDog already manages every coding tool it supports.",
20
+ disable: "BarnDog doesn't manage any coding tool.",
21
+ };
22
+ const nothingToHint = {
23
+ enable: "barndog harnesses list",
24
+ disable: "barndog harnesses enable <harness>",
25
+ };
14
26
  function harnessTable(rows) {
15
27
  return table(rows.map((row) => [
16
28
  bold(row.id),
@@ -39,19 +51,37 @@ export function registerHarnesses(program, context) {
39
51
  if (context.mode.json) {
40
52
  return context.write(json(result));
41
53
  }
42
- for (const line of renderSyncOutput(result.events)) {
54
+ for (const line of renderSyncOutput(result.events, context.runtime)) {
43
55
  context.write(line);
44
56
  }
45
57
  context.write(managedLine(result.harnesses));
46
58
  };
59
+ // With no tools named, a terminal picks from the ones the change applies to.
60
+ const pickTargets = async (change) => {
61
+ const usage = `barndog harnesses ${change} <harness>`;
62
+ if (!context.mode.interactive) {
63
+ throw new CliError(`Name the coding tools to ${change}.`, usage);
64
+ }
65
+ const offered = (await context.listHarnesses()).filter((row) => row.enabled === (change === "disable"));
66
+ if (offered.length === 0) {
67
+ throw new CliError(nothingTo[change], nothingToHint[change]);
68
+ }
69
+ return chooseHarnesses(offered.map((row) => ({
70
+ value: row.id,
71
+ name: row.name,
72
+ evidence: row.evidence,
73
+ checked: false,
74
+ })), { message: pickMessage[change], required: true });
75
+ };
47
76
  for (const change of ["enable", "disable"]) {
48
77
  group
49
78
  .command(change)
50
79
  .description(change === "enable"
51
80
  ? "Start installing your selection into these coding tools"
52
81
  : "Remove everything BarnDog installed in these coding tools and stop installing there")
53
- .addArgument(new Argument("<harnesses...>", "Coding tools").choices(harnesses))
54
- .action(async (targets) => {
82
+ .addArgument(new Argument("[harnesses...]", "Coding tools").choices(harnesses))
83
+ .action(async (named) => {
84
+ const targets = named.length ? named : await pickTargets(change);
55
85
  report(await context.changeHarnesses(change, targets));
56
86
  });
57
87
  }
@@ -1,6 +1,7 @@
1
1
  import { bad, dim, json, ok, ORIGIN_HELP } from "../ui/format.js";
2
2
  import { Option } from "commander";
3
- import { renderHookCompatibility } from "../ui/hook-compatibility.js";
3
+ import { renderHookCompatibility, renderHookMatrix, } from "../ui/hook-compatibility.js";
4
+ import { CliError } from "../errors.js";
4
5
  import { hookHarnesses } from "../harnesses/registry.js";
5
6
  import { defined } from "../shared/lookup.js";
6
7
  import { positiveInteger } from "../ui/options.js";
@@ -58,8 +59,22 @@ export function registerHooks(program, context) {
58
59
  hooks
59
60
  .command("compatibility [name]")
60
61
  .option("--origin <origin>", ORIGIN_HELP)
62
+ .option("--all", "Show every selected Hook against each coding tool")
61
63
  .description("Inspect version-specific declarations and local runtime requirements")
62
64
  .action(async (name, options) => {
65
+ if (options.all) {
66
+ if (name || options.origin) {
67
+ throw new CliError("--all shows every selected Hook, so it takes no name or --origin.", "barndog hooks compatibility --all");
68
+ }
69
+ const rows = await context.allHookCompatibility();
70
+ if (context.mode.json) {
71
+ return context.write(json(rows));
72
+ }
73
+ for (const line of renderHookMatrix(rows)) {
74
+ context.write(line);
75
+ }
76
+ return;
77
+ }
63
78
  const located = await locate("hook", name, options, "barndog hooks compatibility <name>");
64
79
  const result = await context.hookCompatibility(located.name, located.origin);
65
80
  if (context.mode.json) {
@@ -1,78 +1,194 @@
1
+ import { barndogPaths } from "../config/paths.js";
1
2
  import { CliError } from "../errors.js";
2
- import { bold, dim, json, ok, table } from "../ui/format.js";
3
+ import { readsFrom } from "../features/secrets/index.js";
4
+ import { bold, dim, hint, json, ok, table, warn } from "../ui/format.js";
5
+ import { stateBadge } from "../ui/assets.js";
3
6
  import { displayPath, renderSyncOutput } from "../ui/output.js";
4
- import { askSecret, readStdin } from "../ui/secret-input.js";
7
+ import { pickOne } from "../ui/pick.js";
8
+ import { askSecret, askUseUnassigned, readStdin } from "../ui/secret-input.js";
9
+ import { requireArguments } from "./arguments.js";
10
+ const SET_USAGE = "barndog mcp env set <server> <variable>";
11
+ const UNSET_USAGE = "barndog mcp env unset <server> <variable>";
12
+ /** How a kept value reads in a list; never the value itself. */
13
+ const describe = (row) => row.from ? `reads $${row.from}` : "kept";
5
14
  /**
6
- * `barndog mcp env`: MCP variable values BarnDog keeps on this machine. Every
7
- * command says where a value is kept and where it was written; none prints one.
15
+ * `barndog mcp env`: MCP variable values BarnDog keeps on this machine, each
16
+ * for one MCP server. Every command says where a value is kept and where it
17
+ * was written; none prints one.
8
18
  */
9
19
  export function registerMcpEnv(mcp, context) {
10
20
  const env = mcp
11
21
  .command("env")
12
22
  .description("Keep MCP variable values on this machine, never uploaded, and write them into your coding tools");
13
23
  const where = (file) => displayPath(file, context.runtime);
24
+ const report = (message, result, data) => {
25
+ const { notWritten } = result;
26
+ if (context.mode.json) {
27
+ return context.write(json({
28
+ ...data,
29
+ file: result.file,
30
+ ...(notWritten ? { notWritten } : {}),
31
+ }));
32
+ }
33
+ context.write(`${ok("✔")} ${message}`);
34
+ // Nothing was synced, so there is no sync summary to show.
35
+ if (!notWritten) {
36
+ for (const line of renderSyncOutput(result.events, context.runtime)) {
37
+ context.write(line);
38
+ }
39
+ }
40
+ if (notWritten?.because === "disabled") {
41
+ context.write(dim(`${data.server ?? "This server"} is disabled, so your coding tools get the change when you enable it.`));
42
+ }
43
+ if (notWritten?.because === "sync-failed") {
44
+ context.write(`${warn("Your coding tools weren't updated:")} ${notWritten.message}`);
45
+ context.write(dim(`The change is kept; the next ${bold("barndog sync")} writes it into them.`));
46
+ if (notWritten.fix) {
47
+ context.write(hint(notWritten.fix, "Fix"));
48
+ }
49
+ }
50
+ };
51
+ /** Where a kept value is written, or why it isn't. */
52
+ const writtenInto = (row) => {
53
+ if (row.writtenTo.length) {
54
+ return row.writtenTo.map(where).join(", ");
55
+ }
56
+ return dim(row.enabled === false
57
+ ? "not written (disabled)"
58
+ : "not written anywhere yet");
59
+ };
14
60
  env
15
- .command("set <variable>")
16
- .description("Keep a value for a variable MCP servers refer to")
61
+ .command("set [server] [variable]")
62
+ .description("Keep a value for a variable one MCP server refers to")
63
+ .option("--from <variable>", "Read another environment variable instead")
17
64
  .option("--stdin", "Read the value from standard input")
18
65
  .addHelpText("after", `
19
66
  The value is saved in ~/.barndog/secrets.json, which only you can read, and never leaves this machine.
20
- Sync then writes it into the settings of each coding tool whose MCP servers use the variable, as the
21
- tools store values they're given; shared definitions keep only the variable's name.`)
22
- .action(async (variable, options) => {
23
- const value = await readValue(variable, options.stdin);
24
- const result = await context.keepMcpValue(variable, value);
25
- if (context.mode.json) {
26
- return context.write(json({ variable, file: result.file }));
67
+ Sync then writes it into that server's entry in each coding tool's settings, as the tools store values
68
+ they're given; shared definitions keep only the variable's name. A disabled server gets it when you
69
+ enable it, and a sync that can't run leaves it for the next one. With --from, the server reads another
70
+ variable from your environment instead, such as GITHUB_TOKEN for GITHUB_PERSONAL_ACCESS_TOKEN.`)
71
+ .action(async (server, variable, options) => {
72
+ if (options.from && options.stdin) {
73
+ throw new CliError("Pass either --from or --stdin, not both.", SET_USAGE);
27
74
  }
28
- context.write(`${ok("✔")} Saved ${bold(variable)} in ${where(result.file)}, readable only by you. It stays on this machine and is never uploaded.`);
29
- for (const line of renderSyncOutput(result.events)) {
30
- context.write(line);
75
+ const target = await chooseTarget(server, variable);
76
+ const kept = await valueFor(target, options);
77
+ const file = where(barndogPaths(context.runtime.home).secrets);
78
+ if (kept === "unassigned") {
79
+ return report(`${bold(target.server)} now uses the value BarnDog kept for ${bold(target.variable)}, in ${file}.`, await context.assignKeptValue(target), target);
80
+ }
81
+ const result = await context.keepMcpValue(target, kept);
82
+ const from = readsFrom(kept);
83
+ if (from) {
84
+ return report(`${bold(target.server)} reads ${bold(target.variable)} from ${bold(`$${from}`)}. Saved in ${file}.`, result, { ...target, from });
31
85
  }
86
+ report(`Saved ${bold(target.variable)} for ${bold(target.server)} in ${file}, readable only by you. It stays on this machine and is never uploaded.`, result, target);
32
87
  });
33
88
  env
34
- .command("unset <variable>")
35
- .description("Forget a kept value; the tools read the variable again")
36
- .action(async (variable) => {
37
- const result = await context.forgetMcpValue(variable);
38
- if (context.mode.json) {
39
- return context.write(json({ variable, file: result.file }));
40
- }
41
- context.write(`${ok("✔")} Removed ${bold(variable)} from ${where(result.file)}.`);
42
- for (const line of renderSyncOutput(result.events)) {
43
- context.write(line);
89
+ .command("unset [server] [variable]")
90
+ .description("Forget a kept value; the server reads the variable again")
91
+ .option("--unassigned", "Forget a value kept from before values belonged to servers; name only the variable")
92
+ .action(async (server, variable, options) => {
93
+ const kept = await context.listKeptValues();
94
+ const file = where(barndogPaths(context.runtime.home).secrets);
95
+ if (options.unassigned) {
96
+ const named = variable ?? server;
97
+ const name = named ??
98
+ (await pickRow(kept.filter((row) => !row.server), "Choose a value to forget", "barndog mcp env unset --unassigned <variable>")).variable;
99
+ return report(`Removed the unassigned value of ${bold(name)} from ${file}.`, await context.forgetUnassignedValue(name), { variable: name });
44
100
  }
101
+ const assigned = kept.filter((row) => row.server !== null);
102
+ const serverRow = server === undefined
103
+ ? await pickRow([
104
+ ...new Map(assigned.map((row) => [row.assetId, row])).values(),
105
+ ], "Choose an MCP server", UNSET_USAGE, (row) => row.server ?? "")
106
+ : undefined;
107
+ const target = serverRow?.server ?? server ?? "";
108
+ const ofServer = assigned.filter((row) => [row.server, row.assetId].includes(target));
109
+ const name = variable ??
110
+ (ofServer.length === 1 && ofServer[0]
111
+ ? ofServer[0].variable
112
+ : (await pickRow(ofServer, `Choose a value of ${target} to forget`, UNSET_USAGE)).variable);
113
+ report(`Removed ${bold(name)} for ${bold(target)} from ${file}.`, await context.forgetMcpValue({ server: target, variable: name }), { server: target, variable: name });
45
114
  });
46
115
  env
47
116
  .command("list")
48
- .description("List kept variables and where their values are written")
117
+ .description("List kept values, by MCP server, and where they're written")
49
118
  .action(async () => {
50
119
  const kept = await context.listKeptValues();
51
120
  if (context.mode.json) {
52
121
  return context.write(json(kept));
53
122
  }
54
123
  if (!kept.length) {
55
- return context.write(`${dim("BarnDog keeps no MCP values. Add one with")} ${bold("barndog mcp env set <variable>")}${dim(".")}`);
56
- }
57
- context.write(dim("Kept in ~/.barndog/secrets.json on this machine only. Values aren't shown."));
58
- for (const line of table(kept.map((item) => [
59
- bold(item.variable),
60
- item.writtenTo.length
61
- ? item.writtenTo
62
- .map((place) => `${where(place.file)} (${place.server})`)
63
- .join(", ")
64
- : dim("not written anywhere yet"),
65
- ]), { header: ["Variable", "Written into"] })) {
124
+ return context.write(`${dim("BarnDog keeps no MCP values. Add one with")} ${bold(SET_USAGE)}${dim(".")}`);
125
+ }
126
+ context.write(dim(`Kept in ${where(barndogPaths(context.runtime.home).secrets)} on this machine only. Values aren't shown.`));
127
+ for (const line of table(kept.map((row) => [
128
+ row.server ? bold(row.server) : dim("not assigned"),
129
+ bold(row.variable),
130
+ describe(row),
131
+ writtenInto(row),
132
+ ]), { header: ["Server", "Variable", "Value", "Written into"] })) {
66
133
  context.write(line);
67
134
  }
68
135
  });
69
- async function readValue(variable, stdin) {
70
- if (stdin) {
71
- return readStdin();
136
+ async function pickRow(rows, message, usage, name = (row) => row.variable) {
137
+ requireArguments(context, usage);
138
+ return pickOne(message, rows.map((row) => ({ value: row, name: name(row) })), { empty: "BarnDog keeps no such MCP values." });
139
+ }
140
+ /** The server and variable named, or chosen from lists in a terminal. */
141
+ async function chooseTarget(server, variable) {
142
+ if (server && variable) {
143
+ return { server, variable };
144
+ }
145
+ requireArguments(context, SET_USAGE);
146
+ const servers = await context.recordedMcpServers();
147
+ const item = server
148
+ ? servers.find((candidate) => [candidate.installedName, candidate.name, candidate.id].includes(server))
149
+ : await pickOne("Choose an MCP server", servers.map((candidate) => ({
150
+ value: candidate,
151
+ name: candidate.installedName,
152
+ columns: candidate.enabled ? [] : [stateBadge("disabled")],
153
+ })), { empty: "No MCP servers on this machine." });
154
+ if (!item) {
155
+ throw new CliError(`There's no MCP server called ${server} on this machine.`, "barndog mcp list");
156
+ }
157
+ if (variable) {
158
+ return { server: item.installedName, variable };
159
+ }
160
+ const kept = (await context.listKeptValues()).filter((row) => row.assetId === item.id);
161
+ const chosen = await pickOne(`Choose a variable of ${item.installedName}`, item.variables.map((name) => {
162
+ const row = kept.find((candidate) => candidate.variable === name);
163
+ return { value: name, name, columns: row ? [dim(describe(row))] : [] };
164
+ }), {
165
+ empty: `BarnDog couldn't find any variables ${item.installedName} uses. Name one: ${SET_USAGE}`,
166
+ });
167
+ return { server: item.installedName, variable: chosen };
168
+ }
169
+ /**
170
+ * The value to keep: another variable to read, standard input, the value a
171
+ * version 1 file kept with no server, or a masked prompt, in that order.
172
+ */
173
+ async function valueFor(target, options) {
174
+ if (options.from) {
175
+ return { from: options.from };
176
+ }
177
+ if (options.stdin) {
178
+ return { value: await readStdin() };
179
+ }
180
+ const unassigned = (await context.listKeptValues()).some((row) => !row.server && row.variable === target.variable);
181
+ if (unassigned) {
182
+ if (!context.mode.interactive) {
183
+ return "unassigned";
184
+ }
185
+ if (await askUseUnassigned(target.variable)) {
186
+ return "unassigned";
187
+ }
72
188
  }
73
189
  if (!context.mode.interactive) {
74
- throw new CliError("Pass the value on standard input, so it stays out of your shell history.", `barndog mcp env set ${variable} --stdin`);
190
+ throw new CliError("Pass the value on standard input, so it stays out of your shell history.", `barndog mcp env set ${target.server} ${target.variable} --stdin`);
75
191
  }
76
- return askSecret(variable);
192
+ return { value: await askSecret(target.variable) };
77
193
  }
78
194
  }