barndog 0.1.1 → 0.2.1

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 (194) hide show
  1. package/README.md +31 -28
  2. package/dist/cli.js +11 -7
  3. package/dist/commands/add.js +34 -21
  4. package/dist/commands/adopt.js +91 -0
  5. package/dist/commands/arguments.js +12 -0
  6. package/dist/commands/asset-install.js +161 -0
  7. package/dist/commands/asset-list.js +126 -0
  8. package/dist/commands/asset-share.js +94 -0
  9. package/dist/commands/auth.js +4 -0
  10. package/dist/commands/availability.js +72 -27
  11. package/dist/commands/capabilities.js +79 -417
  12. package/dist/commands/collaboration.js +212 -108
  13. package/dist/commands/environment.js +18 -411
  14. package/dist/commands/github.js +200 -0
  15. package/dist/commands/harnesses.js +74 -0
  16. package/dist/commands/helpers.js +39 -0
  17. package/dist/commands/hooks.js +87 -0
  18. package/dist/commands/init.js +4 -2
  19. package/dist/commands/knowledge.js +73 -0
  20. package/dist/commands/mcp-env.js +78 -0
  21. package/dist/commands/mcp.js +64 -0
  22. package/dist/commands/origin.js +21 -23
  23. package/dist/commands/people.js +51 -0
  24. package/dist/commands/sets.js +141 -0
  25. package/dist/commands/status.js +36 -25
  26. package/dist/commands/sync.js +13 -5
  27. package/dist/commands/workspace.js +75 -23
  28. package/dist/config/environment.js +13 -27
  29. package/dist/config/paths.js +81 -0
  30. package/dist/config/selection.js +30 -0
  31. package/dist/config/settings.js +99 -108
  32. package/dist/config/state.js +67 -55
  33. package/dist/entry/knowledge-startup.js +32 -0
  34. package/dist/entry/mcp-launch.js +71 -0
  35. package/dist/entry/opencode-plugin.js +62 -0
  36. package/dist/{features/git-workspace/startup.js → entry/workspace-startup.js} +7 -2
  37. package/dist/errors.js +198 -55
  38. package/dist/features/adoption/adopt.js +234 -0
  39. package/dist/features/adoption/copies.js +29 -0
  40. package/dist/features/adoption/originals.js +116 -0
  41. package/dist/features/adoption/record.js +120 -0
  42. package/dist/features/adoption/restore.js +28 -0
  43. package/dist/features/adoption/scan.js +482 -0
  44. package/dist/features/adoption/undo.js +42 -0
  45. package/dist/features/asset-kinds/index.js +129 -0
  46. package/dist/features/asset-selection/index.js +51 -19
  47. package/dist/features/auth/credentials.js +80 -54
  48. package/dist/features/auth/session.js +83 -49
  49. package/dist/features/auth/transport.js +69 -17
  50. package/dist/features/catalog/index.js +32 -61
  51. package/dist/features/collaboration/api.js +160 -0
  52. package/dist/features/collaboration/index.js +321 -233
  53. package/dist/features/collaboration/remote.js +35 -115
  54. package/dist/features/collaboration/results.js +2 -0
  55. package/dist/features/collaboration/workspace-git.js +242 -152
  56. package/dist/features/collaboration/workspace-github.js +118 -54
  57. package/dist/features/collaboration/workspace-store.js +157 -97
  58. package/dist/features/collaboration/workspace.js +278 -173
  59. package/dist/features/discovery/index.js +68 -57
  60. package/dist/features/doctor/index.js +56 -26
  61. package/dist/features/environment/auto-sync.js +28 -27
  62. package/dist/features/environment/harnesses.js +36 -0
  63. package/dist/features/environment/moves.js +171 -0
  64. package/dist/features/environment/names.js +73 -49
  65. package/dist/features/environment/operations.js +322 -229
  66. package/dist/features/environment/own-entries.js +89 -0
  67. package/dist/features/environment/settle-names.js +91 -0
  68. package/dist/features/environment/stage.js +202 -0
  69. package/dist/features/environment/sync.js +127 -487
  70. package/dist/features/environment/transaction.js +179 -147
  71. package/dist/features/environment/writes.js +243 -0
  72. package/dist/features/github/account.js +25 -0
  73. package/dist/features/github/connections.js +119 -0
  74. package/dist/features/github/pulls.js +118 -0
  75. package/dist/features/hooks/adapt.js +32 -25
  76. package/dist/features/hooks/catalog.js +28 -0
  77. package/dist/features/hooks/compatibility.js +55 -0
  78. package/dist/features/hooks/divergence.js +36 -12
  79. package/dist/features/hooks/test.js +91 -66
  80. package/dist/features/hooks/types.js +1 -0
  81. package/dist/features/imports/discover.js +133 -60
  82. package/dist/features/imports/folder.js +48 -14
  83. package/dist/features/imports/local.js +127 -135
  84. package/dist/features/imports/remote.js +46 -26
  85. package/dist/features/inspection/index.js +17 -17
  86. package/dist/features/inventory/index.js +111 -111
  87. package/dist/features/inventory/show.js +74 -0
  88. package/dist/features/knowledge/index.js +69 -49
  89. package/dist/features/mcps/catalog.js +31 -0
  90. package/dist/features/mcps/import.js +369 -0
  91. package/dist/features/mcps/index.js +104 -50
  92. package/dist/features/mcps/values.js +33 -0
  93. package/dist/features/migration/migrate.js +263 -0
  94. package/dist/features/migration/move.js +448 -0
  95. package/dist/features/migration/promote.js +26 -0
  96. package/dist/features/native/adapters.js +69 -96
  97. package/dist/features/native/configuration.js +134 -84
  98. package/dist/features/native/hook-shell.js +55 -0
  99. package/dist/features/native/plugin-module.js +56 -0
  100. package/dist/features/native/secret-values.js +74 -0
  101. package/dist/features/onboarding/environment.js +67 -34
  102. package/dist/features/onboarding/setup.js +43 -40
  103. package/dist/features/repositories/context.js +30 -13
  104. package/dist/features/secrets/index.js +77 -0
  105. package/dist/features/server/catalog.js +58 -0
  106. package/dist/features/server/client.js +13 -0
  107. package/dist/features/server/connection.js +37 -0
  108. package/dist/features/server/origin.js +74 -0
  109. package/dist/features/server/pages.js +24 -0
  110. package/dist/features/skills/catalog.js +42 -0
  111. package/dist/features/workspace/assets.js +57 -0
  112. package/dist/features/workspace/cloud-source.js +34 -0
  113. package/dist/features/workspace/directory.js +38 -0
  114. package/dist/features/{git-workspace → workspace}/format.js +121 -54
  115. package/dist/features/workspace/git.js +221 -0
  116. package/dist/features/workspace/installed.js +92 -0
  117. package/dist/features/{git-workspace → workspace}/overlay.js +53 -46
  118. package/dist/features/workspace/packages.js +173 -0
  119. package/dist/features/{git-workspace → workspace}/publish.js +120 -64
  120. package/dist/features/workspace/repo-source.js +193 -0
  121. package/dist/features/{git-workspace → workspace}/setup.js +72 -45
  122. package/dist/features/{git-workspace → workspace}/snapshot.js +60 -19
  123. package/dist/features/workspace/source.js +1 -0
  124. package/dist/features/workspace/tree.js +52 -0
  125. package/dist/features/workspace/workspace-source.js +27 -0
  126. package/dist/harnesses/claude.js +23 -1
  127. package/dist/harnesses/codex.js +67 -1
  128. package/dist/harnesses/cursor.js +22 -1
  129. package/dist/harnesses/detect.js +6 -50
  130. package/dist/harnesses/formats.js +52 -0
  131. package/dist/harnesses/opencode.js +108 -0
  132. package/dist/harnesses/registry.js +35 -2
  133. package/dist/platform.js +403 -0
  134. package/dist/program.js +275 -56
  135. package/dist/runtime.js +1 -0
  136. package/dist/shared/cli-error.js +22 -0
  137. package/dist/shared/constants.js +32 -0
  138. package/dist/shared/files.js +107 -0
  139. package/dist/shared/lock.js +113 -0
  140. package/dist/shared/lookup.js +11 -0
  141. package/dist/shared/patterns.js +102 -0
  142. package/dist/shared/shell.js +20 -0
  143. package/dist/shared/values.js +26 -0
  144. package/dist/ui/add-asset.js +41 -400
  145. package/dist/ui/add-hook.js +219 -0
  146. package/dist/ui/add-mcp.js +170 -0
  147. package/dist/ui/add-prompts.js +47 -0
  148. package/dist/ui/add-skills.js +117 -0
  149. package/dist/ui/adopt.js +197 -0
  150. package/dist/ui/asset-list.js +31 -13
  151. package/dist/ui/assets.js +38 -47
  152. package/dist/ui/auth.js +45 -34
  153. package/dist/ui/clash.js +10 -6
  154. package/dist/ui/collaboration.js +116 -44
  155. package/dist/ui/connection.js +17 -6
  156. package/dist/ui/decision-error.js +24 -0
  157. package/dist/ui/environment-onboarding.js +35 -13
  158. package/dist/ui/format.js +66 -18
  159. package/dist/ui/harness-picker.js +18 -0
  160. package/dist/ui/hook-compatibility.js +14 -6
  161. package/dist/ui/mcp.js +28 -3
  162. package/dist/ui/move.js +57 -6
  163. package/dist/ui/onboarding.js +148 -95
  164. package/dist/ui/options.js +9 -0
  165. package/dist/ui/output.js +108 -43
  166. package/dist/ui/package-details.js +34 -0
  167. package/dist/ui/pick.js +45 -33
  168. package/dist/ui/scope-install.js +18 -7
  169. package/dist/ui/secret-input.js +19 -0
  170. package/dist/ui/selection.js +17 -11
  171. package/dist/ui/theme.js +37 -14
  172. package/dist/version.js +6 -3
  173. package/package.json +13 -3
  174. package/dist/features/capabilities/index.js +0 -106
  175. package/dist/features/collaboration/domain.js +0 -90
  176. package/dist/features/environment/cloud-source.js +0 -27
  177. package/dist/features/environment/installed.js +0 -124
  178. package/dist/features/environment/packages.js +0 -120
  179. package/dist/features/environment/remote.js +0 -71
  180. package/dist/features/environment/workspace-source.js +0 -19
  181. package/dist/features/git-hosts/index.js +0 -148
  182. package/dist/features/git-workspace/assets.js +0 -71
  183. package/dist/features/git-workspace/git.js +0 -135
  184. package/dist/features/git-workspace/migrate.js +0 -188
  185. package/dist/features/git-workspace/move.js +0 -337
  186. package/dist/features/git-workspace/source.js +0 -159
  187. package/dist/features/imports/mcp.js +0 -219
  188. package/dist/features/knowledge/startup.js +0 -25
  189. package/dist/features/native/mcp-launch.js +0 -57
  190. package/dist/features/skills/install.js +0 -25
  191. package/dist/features/skills/remote.js +0 -177
  192. package/dist/features/skills/sync.js +0 -121
  193. package/dist/features/skills/validation.js +0 -34
  194. /package/dist/features/environment/{source.js → events.js} +0 -0
@@ -0,0 +1,74 @@
1
+ import { Argument } from "commander";
2
+ import { styleText } from "node:util";
3
+ import { CliError } from "../errors.js";
4
+ import { harnesses } from "../harnesses/registry.js";
5
+ import { toolNames } from "../features/hooks/adapt.js";
6
+ import { bold, dim, json, ok, table } from "../ui/format.js";
7
+ import { chooseHarnesses } from "../ui/harness-picker.js";
8
+ import { renderSyncOutput } from "../ui/output.js";
9
+ function managedLine(managed) {
10
+ return managed.length
11
+ ? `${ok("✔")} BarnDog now manages ${toolNames(managed)}.`
12
+ : `${ok("✔")} BarnDog no longer manages any coding tool. Add one with ${styleText("bold", "barndog harnesses enable <harness>")}.`;
13
+ }
14
+ function harnessTable(rows) {
15
+ return table(rows.map((row) => [
16
+ bold(row.id),
17
+ row.name,
18
+ row.enabled ? ok("managed") : dim("off"),
19
+ row.evidence ? dim(row.evidence) : dim("not found"),
20
+ ]), { header: ["Harness", "Tool", "State", "Detected"] });
21
+ }
22
+ export function registerHarnesses(program, context) {
23
+ const group = program
24
+ .command("harnesses")
25
+ .description("Choose which coding tools BarnDog manages; a tool turned off loses everything BarnDog installed there");
26
+ group
27
+ .command("list", { isDefault: true })
28
+ .description("List supported coding tools and whether BarnDog manages them")
29
+ .action(async () => {
30
+ const rows = await context.listHarnesses();
31
+ if (context.mode.json) {
32
+ return context.write(json(rows));
33
+ }
34
+ for (const line of harnessTable(rows)) {
35
+ context.write(line);
36
+ }
37
+ });
38
+ const report = (result) => {
39
+ if (context.mode.json) {
40
+ return context.write(json(result));
41
+ }
42
+ for (const line of renderSyncOutput(result.events)) {
43
+ context.write(line);
44
+ }
45
+ context.write(managedLine(result.harnesses));
46
+ };
47
+ for (const change of ["enable", "disable"]) {
48
+ group
49
+ .command(change)
50
+ .description(change === "enable"
51
+ ? "Start installing your selection into these coding tools"
52
+ : "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) => {
55
+ report(await context.changeHarnesses(change, targets));
56
+ });
57
+ }
58
+ group
59
+ .command("select")
60
+ .description("Choose from a list exactly which coding tools BarnDog manages")
61
+ .action(async () => {
62
+ if (!context.mode.interactive) {
63
+ throw new CliError("Choosing coding tools from a list needs a terminal.", "barndog harnesses enable <harness>");
64
+ }
65
+ const rows = await context.listHarnesses();
66
+ const chosen = await chooseHarnesses(rows.map((row) => ({
67
+ value: row.id,
68
+ name: row.name,
69
+ evidence: row.evidence,
70
+ checked: row.enabled,
71
+ })));
72
+ report(await context.selectHarnesses(chosen));
73
+ });
74
+ }
@@ -0,0 +1,39 @@
1
+ import { safe, json, renderValue } from "../ui/format.js";
2
+ import { renderMcp } from "../ui/mcp.js";
3
+ import { pickInstalled, resolveOrigin } from "./origin.js";
4
+ /** What every command group prints with and how it finds the asset a command names. */
5
+ export function commandHelpers(context) {
6
+ const write = (value) => context.write(safe(value));
7
+ const print = (result) => {
8
+ if (context.mode.json) {
9
+ context.write(json(result));
10
+ }
11
+ else if (typeof result === "object" && result && "message" in result) {
12
+ write(String(result.message));
13
+ }
14
+ else {
15
+ for (const line of renderValue(result)) {
16
+ context.write(line);
17
+ }
18
+ }
19
+ };
20
+ const printMcp = (result) => {
21
+ for (const line of renderMcp(result)) {
22
+ context.write(line);
23
+ }
24
+ };
25
+ /** Adds the owning scope, asking only when several scopes share the name. */
26
+ const locate = async (kind, name, options, usage) => name
27
+ ? {
28
+ ...options,
29
+ name,
30
+ origin: await resolveOrigin(context, {
31
+ kind,
32
+ name,
33
+ origin: options.origin,
34
+ usage: usage.replace("<name>", name),
35
+ }),
36
+ }
37
+ : { ...options, ...(await pickInstalled(context, kind, usage)) };
38
+ return { write, print, printMcp, locate };
39
+ }
@@ -0,0 +1,87 @@
1
+ import { bad, dim, json, ok, ORIGIN_HELP } from "../ui/format.js";
2
+ import { Option } from "commander";
3
+ import { renderHookCompatibility } from "../ui/hook-compatibility.js";
4
+ import { hookHarnesses } from "../harnesses/registry.js";
5
+ import { defined } from "../shared/lookup.js";
6
+ import { positiveInteger } from "../ui/options.js";
7
+ import { commandHelpers } from "./helpers.js";
8
+ /** Shell timeout utility convention for a timed-out command. */
9
+ const TIMEOUT_EXIT_CODE = 124;
10
+ function hookTestSummary(timedOut, exitCode) {
11
+ if (timedOut) {
12
+ return `${bad("✖")} Hook test timed out.`;
13
+ }
14
+ if (exitCode) {
15
+ return `${bad("✖")} Hook test exited ${exitCode}.`;
16
+ }
17
+ return `${ok("✔")} Hook test exited 0.`;
18
+ }
19
+ /** `barndog hooks` commands that test a Hook and report or widen its tool coverage. */
20
+ export function registerHooks(program, context) {
21
+ const { write, locate } = commandHelpers(context);
22
+ const hooks = defined(program.commands.find((c) => c.name() === "hooks"), "Command group hooks isn't registered");
23
+ hooks
24
+ .command("test [name]")
25
+ .option("--origin <origin>", ORIGIN_HELP)
26
+ .addOption(new Option("--harness <harness>", "Chosen implementation")
27
+ .choices(hookHarnesses)
28
+ .makeOptionMandatory())
29
+ .requiredOption("--input <file>", "Native JSON test input")
30
+ .option("--event <event>", "Native event name")
31
+ .option("--handler <number>", "One-based command index", positiveInteger)
32
+ .option("--timeout <seconds>", "Maximum test duration", positiveInteger)
33
+ .description("Explicitly run one published command Hook with test input")
34
+ .action(async (name, options) => {
35
+ const located = await locate("hook", name, options, `barndog hooks test <name> --harness ${options.harness} --input ${options.input}`);
36
+ const test = await context.testHook(located.name, located.origin, {
37
+ harness: options.harness,
38
+ input: options.input,
39
+ event: options.event,
40
+ handler: options.handler,
41
+ timeout: options.timeout,
42
+ });
43
+ // The Hook's own result is the command's result, however it is printed.
44
+ if (test.exitCode || test.timedOut) {
45
+ process.exitCode = test.timedOut ? TIMEOUT_EXIT_CODE : test.exitCode;
46
+ }
47
+ if (context.mode.json) {
48
+ return context.write(json(test));
49
+ }
50
+ if (test.stdout) {
51
+ write(test.stdout.trimEnd());
52
+ }
53
+ if (test.stderr) {
54
+ write(test.stderr.trimEnd());
55
+ }
56
+ write(hookTestSummary(test.timedOut, test.exitCode));
57
+ });
58
+ hooks
59
+ .command("compatibility [name]")
60
+ .option("--origin <origin>", ORIGIN_HELP)
61
+ .description("Inspect version-specific declarations and local runtime requirements")
62
+ .action(async (name, options) => {
63
+ const located = await locate("hook", name, options, "barndog hooks compatibility <name>");
64
+ const result = await context.hookCompatibility(located.name, located.origin);
65
+ if (context.mode.json) {
66
+ return context.write(json(result));
67
+ }
68
+ for (const line of renderHookCompatibility(located.name, result)) {
69
+ context.write(line);
70
+ }
71
+ });
72
+ hooks
73
+ .command("adapt [name]")
74
+ .option("--origin <origin>", ORIGIN_HELP)
75
+ .addOption(new Option("--for <tools...>", "Coding tools to adapt it for (default: the ones this machine uses that it doesn't cover)").choices(hookHarnesses))
76
+ .description("Print a prompt for an AI agent to adapt a Hook to coding tools it wasn't written for")
77
+ .action(async (name, options) => {
78
+ const located = await locate("hook", name, options, "barndog hooks adapt <name>");
79
+ const result = await context.adaptHook(located.name, located.origin, options.for);
80
+ if (context.mode.json) {
81
+ return context.write(json(result));
82
+ }
83
+ // Printed bare, so it can be piped to the clipboard or an agent.
84
+ context.write(result.prompt ??
85
+ dim(`${result.name} already has settings for every coding tool this machine uses.`));
86
+ });
87
+ }
@@ -7,10 +7,12 @@ export function registerInit(program, context) {
7
7
  .option("--repo <url>", "Share assets through one Git repository")
8
8
  .option("--no-browser", "Display the sign-in URL without opening it")
9
9
  .action(async (options) => {
10
- if (options.local && options.server)
10
+ if (options.local && options.server) {
11
11
  program.error("--local cannot be combined with --server");
12
- if (options.repo && (options.local || options.server))
12
+ }
13
+ if (options.repo && (options.local || options.server)) {
13
14
  program.error("--repo cannot be combined with --local or --server");
15
+ }
14
16
  await context.setup(true, options.server, {
15
17
  local: options.local,
16
18
  browser: options.browser,
@@ -0,0 +1,73 @@
1
+ import { bold, clean, dim, hint, json, ok, table, warn } from "../ui/format.js";
2
+ import { runSelection } from "../ui/selection.js";
3
+ import { commandHelpers } from "./helpers.js";
4
+ /** When coding tools see a knowledge document. */
5
+ function knowledgeListing(listedAtStart, accessMode) {
6
+ if (listedAtStart) {
7
+ return ok("every session");
8
+ }
9
+ return accessMode === "always" ? dim("off") : dim("on demand");
10
+ }
11
+ /** `barndog knowledge`: reading shared knowledge and its session-start listing. */
12
+ export function registerKnowledge(program, context) {
13
+ const { write } = commandHelpers(context);
14
+ const knowledge = program
15
+ .command("knowledge")
16
+ .description("Read your organization's shared knowledge documents");
17
+ knowledge
18
+ .command("list")
19
+ .description("List knowledge documents and when coding tools see them")
20
+ .option("--always", "Only documents listed at every session start")
21
+ .action(async (options) => {
22
+ const docs = await context.knowledgeList(options.always);
23
+ if (context.mode.json) {
24
+ return context.write(json(docs));
25
+ }
26
+ const problems = await context.knowledgeProblems().catch(() => []);
27
+ for (const problem of problems) {
28
+ context.write(`${warn("!")} ${problem.path}: ${problem.reason}`);
29
+ }
30
+ if (!docs.length) {
31
+ return context.write(dim("No knowledge documents yet."));
32
+ }
33
+ for (const line of table(docs.map((doc) => [
34
+ bold(clean(doc.name)),
35
+ knowledgeListing(doc.listedAtStart, doc.accessMode),
36
+ dim(clean(doc.description)),
37
+ ]), { header: ["Name", "Listed", "Description"] })) {
38
+ context.write(line);
39
+ }
40
+ context.write("");
41
+ if (docs.some((d) => d.accessMode === "always" && !d.listedAtStart)) {
42
+ context.write(hint("barndog knowledge enable", "Tip") +
43
+ dim(" to list these at session start again"));
44
+ }
45
+ context.write(hint("barndog knowledge get <name>", "Tip") + dim(" to read one"));
46
+ });
47
+ knowledge
48
+ .command("get <name>")
49
+ .description("Print a knowledge document")
50
+ .action(async (name) => {
51
+ const result = await context.knowledgeGet(name);
52
+ if (context.mode.json) {
53
+ return context.write(json(result));
54
+ }
55
+ write(result.version.content.markdown);
56
+ });
57
+ for (const action of ["enable", "disable"]) {
58
+ knowledge
59
+ .command(action)
60
+ .description(action === "enable"
61
+ ? "Tell coding tools at session start which knowledge documents exist"
62
+ : "Stop listing knowledge documents at session start")
63
+ .action(async () => {
64
+ await runSelection(context, () => context.setKnowledge(action === "enable"));
65
+ if (context.mode.json) {
66
+ return;
67
+ }
68
+ context.write(action === "enable"
69
+ ? `${ok("✔")} Coding tools now see the list of knowledge documents when a session starts.`
70
+ : `${ok("✔")} Knowledge documents are no longer listed at session start.`);
71
+ });
72
+ }
73
+ }
@@ -0,0 +1,78 @@
1
+ import { CliError } from "../errors.js";
2
+ import { bold, dim, json, ok, table } from "../ui/format.js";
3
+ import { displayPath, renderSyncOutput } from "../ui/output.js";
4
+ import { askSecret, readStdin } from "../ui/secret-input.js";
5
+ /**
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.
8
+ */
9
+ export function registerMcpEnv(mcp, context) {
10
+ const env = mcp
11
+ .command("env")
12
+ .description("Keep MCP variable values on this machine, never uploaded, and write them into your coding tools");
13
+ const where = (file) => displayPath(file, context.runtime);
14
+ env
15
+ .command("set <variable>")
16
+ .description("Keep a value for a variable MCP servers refer to")
17
+ .option("--stdin", "Read the value from standard input")
18
+ .addHelpText("after", `
19
+ 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 }));
27
+ }
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);
31
+ }
32
+ });
33
+ 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);
44
+ }
45
+ });
46
+ env
47
+ .command("list")
48
+ .description("List kept variables and where their values are written")
49
+ .action(async () => {
50
+ const kept = await context.listKeptValues();
51
+ if (context.mode.json) {
52
+ return context.write(json(kept));
53
+ }
54
+ 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"] })) {
66
+ context.write(line);
67
+ }
68
+ });
69
+ async function readValue(variable, stdin) {
70
+ if (stdin) {
71
+ return readStdin();
72
+ }
73
+ 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`);
75
+ }
76
+ return askSecret(variable);
77
+ }
78
+ }
@@ -0,0 +1,64 @@
1
+ import { json, ok, ORIGIN_HELP } from "../ui/format.js";
2
+ import { Option } from "commander";
3
+ import { harnesses } from "../harnesses/registry.js";
4
+ import { defined } from "../shared/lookup.js";
5
+ import { commandHelpers } from "./helpers.js";
6
+ import { registerMcpEnv } from "./mcp-env.js";
7
+ /** `barndog mcp` commands that publish, inspect and authenticate MCP configurations. */
8
+ export function registerMcp(program, context) {
9
+ const { write, print, printMcp, locate } = commandHelpers(context);
10
+ const mcp = defined(program.commands.find((c) => c.name() === "mcp"), "Command group mcp isn't registered");
11
+ for (const action of ["create", "update"]) {
12
+ const command = mcp
13
+ .command(`${action} <name>`)
14
+ .description(`${action === "create" ? "Create" : "Publish a new revision of"} an MCP configuration directly`)
15
+ .requiredOption("--origin <origin>", ORIGIN_HELP)
16
+ .requiredOption("--file <file>", "JSON connection definition with secret references")
17
+ .option("--key <key>", "Stable key for exact retries");
18
+ if (action === "update") {
19
+ command.requiredOption("--expected-version <id>", "Inspected configuration version ID");
20
+ }
21
+ command.action(async (name, options) => {
22
+ const result = action === "create"
23
+ ? await context.createMcp({ ...options, name })
24
+ : await context.updateMcp({ ...options, name });
25
+ if (context.mode.json) {
26
+ return context.write(json(result));
27
+ }
28
+ write(`${ok("✔")} Published ${name}.`);
29
+ printMcp(result);
30
+ });
31
+ }
32
+ mcp
33
+ .command("show [name]")
34
+ .option("--origin <origin>", ORIGIN_HELP)
35
+ .description("Inspect a connection definition")
36
+ .action(async (name, options) => {
37
+ const located = await locate("mcp", name, options, "barndog mcp show <name>");
38
+ const result = await context.showMcp(located.name, located.origin);
39
+ if (context.mode.json) {
40
+ return context.write(json(result));
41
+ }
42
+ printMcp(result);
43
+ });
44
+ mcp
45
+ .command("versions <name>")
46
+ .option("--origin <origin>", ORIGIN_HELP)
47
+ .description("Inspect immutable configuration history")
48
+ .action(async (name, options) => {
49
+ const located = await locate("mcp", name, options, `barndog mcp versions ${name}`);
50
+ print(await context.mcpVersions(located.name, located.origin));
51
+ });
52
+ mcp
53
+ .command("auth <name>")
54
+ .option("--origin <origin>", ORIGIN_HELP)
55
+ .addOption(new Option("--harness <harness>", "Native login owner")
56
+ .choices(harnesses)
57
+ .makeOptionMandatory())
58
+ .description("Enter native authentication without sharing credentials")
59
+ .action(async (name, options) => {
60
+ const located = await locate("mcp", name, options, `barndog mcp auth ${name} --harness ${options.harness}`);
61
+ print(await context.authenticateMcp(located.name, located.origin, options.harness));
62
+ });
63
+ registerMcpEnv(mcp, context);
64
+ }
@@ -1,48 +1,46 @@
1
+ import { assetKinds } from "../features/asset-kinds/index.js";
1
2
  import { CliError } from "../errors.js";
2
3
  import { pickOne } from "../ui/pick.js";
3
4
  import { clean, originLabel } from "../ui/format.js";
4
- const nouns = {
5
- skill: "Skill",
6
- hook: "Hook",
7
- mcp: "MCP server",
8
- };
9
- const groups = {
10
- skill: "skills",
11
- hook: "hooks",
12
- mcp: "mcp",
13
- };
5
+ import { only } from "../shared/lookup.js";
14
6
  /**
15
7
  * Names are unique only within a scope, so `--origin` picks between scopes
16
8
  * that share one. When only one scope has the name, as in a local folder
17
9
  * with its single scope, the name alone identifies the asset.
18
10
  */
19
- export async function resolveOrigin(context, kind, name, origin, usage) {
20
- if (origin)
11
+ export async function resolveOrigin(context, { kind, name, origin, usage, }) {
12
+ if (origin) {
21
13
  return origin;
14
+ }
22
15
  const rows = (await context.searchCatalog(kind)).filter((row) => row.name === name || row.id === name);
23
- if (!rows.length)
24
- throw new CliError(`No ${nouns[kind]} named ${name} is available to you.`, `barndog ${groups[kind]} search ${name}`);
16
+ if (!rows.length) {
17
+ throw new CliError(`No ${assetKinds[kind].one} named ${name} is available to you.`, `barndog ${assetKinds[kind].command} search ${name}`);
18
+ }
25
19
  const labels = [...new Set(rows.map((row) => originLabel(row.origin)))];
26
- if (labels.length === 1)
27
- return labels[0];
28
- if (!context.mode.interactive)
20
+ const single = only(labels);
21
+ if (single) {
22
+ return single;
23
+ }
24
+ if (!context.mode.interactive) {
29
25
  throw new CliError(`${name} exists in several scopes: ${labels.join(", ")}. Choose one with --origin.`, `${usage} --origin ${labels[0]}`);
26
+ }
30
27
  return pickOne(`${name} exists in several scopes. Which one?`, labels.map((label) => ({
31
28
  value: label,
32
29
  name: label,
33
- hint: clean(rows.find((row) => originLabel(row.origin) === label).version
34
- .description),
30
+ hint: clean(rows.find((row) => originLabel(row.origin) === label)?.version
31
+ .description ?? ""),
35
32
  })));
36
33
  }
37
34
  /** Lets the person choose an installed asset when the command was given no name. */
38
35
  export async function pickInstalled(context, kind, usage) {
39
- if (!context.mode.interactive)
40
- throw new CliError(`Name the ${nouns[kind]} to use, or run this in a terminal to choose from a list.`, usage);
36
+ if (!context.mode.interactive) {
37
+ throw new CliError(`Name the ${assetKinds[kind].one} to use, or run this in a terminal to choose from a list.`, usage);
38
+ }
41
39
  const items = (await context.inventory()).items.filter((item) => item.kind === kind && item.origin !== "—");
42
- const item = await pickOne(`Choose a ${nouns[kind]}`, items.map((item) => ({
40
+ const item = await pickOne(`Choose a ${assetKinds[kind].one}`, items.map((item) => ({
43
41
  value: item,
44
42
  name: item.installedName,
45
43
  hint: `${item.origin} · ${item.state}`,
46
- })), { empty: `No ${nouns[kind]}s are installed on this machine.` });
44
+ })), { empty: `No ${assetKinds[kind].one}s are installed on this machine.` });
47
45
  return { name: item.name, origin: item.origin };
48
46
  }
@@ -0,0 +1,51 @@
1
+ import { bold, clean, dim, hint, json, originLabel, table, } from "../ui/format.js";
2
+ /** `barndog people`: coworkers and the personal assets they share. */
3
+ export function registerPeople(program, context) {
4
+ const people = program
5
+ .command("people")
6
+ .description("Find coworkers and the personal assets they share");
7
+ people
8
+ .command("list")
9
+ .description("List people in your organization")
10
+ .option("--search <query>", "Search names or handles")
11
+ .action(async (options) => {
12
+ const rows = await context.developers(options.search);
13
+ if (context.mode.json) {
14
+ return context.write(json(rows));
15
+ }
16
+ if (!rows.length) {
17
+ return context.write(dim("No matching people."));
18
+ }
19
+ for (const line of table(rows.map((person) => [
20
+ bold(clean(person.name)),
21
+ dim(`@${clean(person.slug)}`),
22
+ ]), { header: ["Name", "Handle"] })) {
23
+ context.write(line);
24
+ }
25
+ context.write("");
26
+ context.write(hint("barndog people show <handle>", "Tip") +
27
+ dim(" to see what someone shares"));
28
+ });
29
+ people
30
+ .command("show <handle>")
31
+ .description("List a person's shared assets")
32
+ .option("--search <query>", "Filter asset names")
33
+ .action(async (handle, options) => {
34
+ const result = await context.developerAssets(handle, options.search);
35
+ if (context.mode.json) {
36
+ return context.write(json(result));
37
+ }
38
+ context.write(`${bold(clean(result.developer.name))} ${dim(`@${result.developer.slug}`)}`);
39
+ context.write("");
40
+ if (!result.assets.length) {
41
+ return context.write(dim(" Nothing shared yet."));
42
+ }
43
+ for (const line of table(result.assets.map((asset) => [
44
+ dim(asset.kind),
45
+ bold(clean(asset.name)),
46
+ originLabel(asset.origin),
47
+ ]), { header: ["Kind", "Name", "Origin"] })) {
48
+ context.write(line);
49
+ }
50
+ });
51
+ }