barndog 0.1.1 → 0.2.0

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 (173) hide show
  1. package/README.md +8 -7
  2. package/dist/cli.js +11 -7
  3. package/dist/commands/add.js +33 -21
  4. package/dist/commands/arguments.js +12 -0
  5. package/dist/commands/asset-install.js +160 -0
  6. package/dist/commands/asset-list.js +121 -0
  7. package/dist/commands/asset-share.js +94 -0
  8. package/dist/commands/auth.js +4 -0
  9. package/dist/commands/availability.js +54 -26
  10. package/dist/commands/capabilities.js +71 -415
  11. package/dist/commands/collaboration.js +194 -110
  12. package/dist/commands/environment.js +18 -411
  13. package/dist/commands/github.js +200 -0
  14. package/dist/commands/helpers.js +39 -0
  15. package/dist/commands/hooks.js +87 -0
  16. package/dist/commands/init.js +4 -2
  17. package/dist/commands/knowledge.js +73 -0
  18. package/dist/commands/mcp.js +62 -0
  19. package/dist/commands/origin.js +21 -23
  20. package/dist/commands/people.js +51 -0
  21. package/dist/commands/sets.js +141 -0
  22. package/dist/commands/status.js +34 -24
  23. package/dist/commands/sync.js +11 -4
  24. package/dist/commands/workspace.js +33 -19
  25. package/dist/config/environment.js +13 -27
  26. package/dist/config/paths.js +62 -0
  27. package/dist/config/selection.js +30 -0
  28. package/dist/config/settings.js +97 -108
  29. package/dist/config/state.js +57 -57
  30. package/dist/entry/knowledge-startup.js +32 -0
  31. package/dist/entry/mcp-launch.js +71 -0
  32. package/dist/entry/opencode-plugin.js +62 -0
  33. package/dist/{features/git-workspace/startup.js → entry/workspace-startup.js} +7 -2
  34. package/dist/errors.js +198 -55
  35. package/dist/features/asset-kinds/index.js +120 -0
  36. package/dist/features/asset-selection/index.js +51 -19
  37. package/dist/features/auth/credentials.js +80 -47
  38. package/dist/features/auth/session.js +80 -45
  39. package/dist/features/auth/transport.js +66 -15
  40. package/dist/features/catalog/index.js +32 -61
  41. package/dist/features/collaboration/api.js +160 -0
  42. package/dist/features/collaboration/index.js +321 -233
  43. package/dist/features/collaboration/remote.js +35 -115
  44. package/dist/features/collaboration/results.js +2 -0
  45. package/dist/features/collaboration/workspace-git.js +233 -149
  46. package/dist/features/collaboration/workspace-github.js +117 -54
  47. package/dist/features/collaboration/workspace-store.js +140 -100
  48. package/dist/features/collaboration/workspace.js +257 -172
  49. package/dist/features/discovery/index.js +68 -57
  50. package/dist/features/doctor/index.js +32 -24
  51. package/dist/features/environment/auto-sync.js +28 -27
  52. package/dist/features/environment/names.js +67 -47
  53. package/dist/features/environment/operations.js +321 -228
  54. package/dist/features/environment/own-entries.js +89 -0
  55. package/dist/features/environment/settle-names.js +91 -0
  56. package/dist/features/environment/stage.js +178 -0
  57. package/dist/features/environment/sync.js +113 -484
  58. package/dist/features/environment/transaction.js +179 -147
  59. package/dist/features/environment/writes.js +196 -0
  60. package/dist/features/github/account.js +25 -0
  61. package/dist/features/github/connections.js +119 -0
  62. package/dist/features/github/pulls.js +118 -0
  63. package/dist/features/hooks/adapt.js +32 -25
  64. package/dist/features/hooks/catalog.js +28 -0
  65. package/dist/features/hooks/compatibility.js +49 -0
  66. package/dist/features/hooks/divergence.js +9 -6
  67. package/dist/features/hooks/test.js +74 -49
  68. package/dist/features/hooks/types.js +1 -0
  69. package/dist/features/imports/discover.js +134 -61
  70. package/dist/features/imports/folder.js +48 -14
  71. package/dist/features/imports/local.js +113 -134
  72. package/dist/features/imports/remote.js +44 -25
  73. package/dist/features/inspection/index.js +17 -17
  74. package/dist/features/inventory/index.js +99 -110
  75. package/dist/features/knowledge/index.js +69 -49
  76. package/dist/features/mcps/catalog.js +31 -0
  77. package/dist/features/mcps/import.js +316 -0
  78. package/dist/features/mcps/index.js +98 -49
  79. package/dist/features/migration/migrate.js +263 -0
  80. package/dist/features/{git-workspace → migration}/move.js +165 -109
  81. package/dist/features/migration/promote.js +24 -0
  82. package/dist/features/native/adapters.js +53 -94
  83. package/dist/features/native/configuration.js +128 -82
  84. package/dist/features/native/hook-shell.js +55 -0
  85. package/dist/features/native/plugin-module.js +56 -0
  86. package/dist/features/onboarding/environment.js +67 -34
  87. package/dist/features/onboarding/setup.js +43 -40
  88. package/dist/features/repositories/context.js +30 -13
  89. package/dist/features/server/catalog.js +58 -0
  90. package/dist/features/server/client.js +13 -0
  91. package/dist/features/server/connection.js +37 -0
  92. package/dist/features/server/origin.js +74 -0
  93. package/dist/features/server/pages.js +24 -0
  94. package/dist/features/skills/catalog.js +42 -0
  95. package/dist/features/workspace/assets.js +57 -0
  96. package/dist/features/workspace/cloud-source.js +34 -0
  97. package/dist/features/workspace/directory.js +38 -0
  98. package/dist/features/{git-workspace → workspace}/format.js +114 -51
  99. package/dist/features/workspace/git.js +214 -0
  100. package/dist/features/workspace/installed.js +92 -0
  101. package/dist/features/{git-workspace → workspace}/overlay.js +43 -23
  102. package/dist/features/workspace/packages.js +160 -0
  103. package/dist/features/{git-workspace → workspace}/publish.js +120 -64
  104. package/dist/features/workspace/repo-source.js +192 -0
  105. package/dist/features/{git-workspace → workspace}/setup.js +60 -42
  106. package/dist/features/{git-workspace → workspace}/snapshot.js +53 -18
  107. package/dist/features/workspace/source.js +1 -0
  108. package/dist/features/workspace/tree.js +52 -0
  109. package/dist/features/workspace/workspace-source.js +27 -0
  110. package/dist/harnesses/claude.js +23 -1
  111. package/dist/harnesses/codex.js +57 -1
  112. package/dist/harnesses/cursor.js +22 -1
  113. package/dist/harnesses/detect.js +6 -50
  114. package/dist/harnesses/formats.js +45 -0
  115. package/dist/harnesses/opencode.js +111 -0
  116. package/dist/harnesses/registry.js +35 -2
  117. package/dist/platform.js +375 -0
  118. package/dist/program.js +225 -54
  119. package/dist/runtime.js +1 -0
  120. package/dist/shared/cli-error.js +22 -0
  121. package/dist/shared/constants.js +32 -0
  122. package/dist/shared/files.js +72 -0
  123. package/dist/shared/lock.js +49 -0
  124. package/dist/shared/lookup.js +11 -0
  125. package/dist/shared/patterns.js +94 -0
  126. package/dist/shared/shell.js +22 -0
  127. package/dist/shared/values.js +26 -0
  128. package/dist/ui/add-asset.js +41 -400
  129. package/dist/ui/add-hook.js +213 -0
  130. package/dist/ui/add-mcp.js +107 -0
  131. package/dist/ui/add-prompts.js +47 -0
  132. package/dist/ui/add-skills.js +115 -0
  133. package/dist/ui/asset-list.js +31 -13
  134. package/dist/ui/assets.js +33 -44
  135. package/dist/ui/auth.js +43 -33
  136. package/dist/ui/clash.js +11 -6
  137. package/dist/ui/collaboration.js +116 -44
  138. package/dist/ui/connection.js +10 -4
  139. package/dist/ui/decision-error.js +24 -0
  140. package/dist/ui/environment-onboarding.js +35 -13
  141. package/dist/ui/format.js +66 -18
  142. package/dist/ui/hook-compatibility.js +14 -6
  143. package/dist/ui/mcp.js +28 -3
  144. package/dist/ui/move.js +10 -5
  145. package/dist/ui/onboarding.js +113 -73
  146. package/dist/ui/options.js +9 -0
  147. package/dist/ui/output.js +106 -43
  148. package/dist/ui/pick.js +45 -33
  149. package/dist/ui/scope-install.js +15 -7
  150. package/dist/ui/selection.js +15 -11
  151. package/dist/ui/theme.js +37 -14
  152. package/dist/version.js +6 -3
  153. package/package.json +13 -3
  154. package/dist/features/capabilities/index.js +0 -106
  155. package/dist/features/collaboration/domain.js +0 -90
  156. package/dist/features/environment/cloud-source.js +0 -27
  157. package/dist/features/environment/installed.js +0 -124
  158. package/dist/features/environment/packages.js +0 -120
  159. package/dist/features/environment/remote.js +0 -71
  160. package/dist/features/environment/workspace-source.js +0 -19
  161. package/dist/features/git-hosts/index.js +0 -148
  162. package/dist/features/git-workspace/assets.js +0 -71
  163. package/dist/features/git-workspace/git.js +0 -135
  164. package/dist/features/git-workspace/migrate.js +0 -188
  165. package/dist/features/git-workspace/source.js +0 -159
  166. package/dist/features/imports/mcp.js +0 -219
  167. package/dist/features/knowledge/startup.js +0 -25
  168. package/dist/features/native/mcp-launch.js +0 -57
  169. package/dist/features/skills/install.js +0 -25
  170. package/dist/features/skills/remote.js +0 -177
  171. package/dist/features/skills/sync.js +0 -121
  172. package/dist/features/skills/validation.js +0 -34
  173. /package/dist/features/environment/{source.js → events.js} +0 -0
@@ -1,72 +1,38 @@
1
1
  import { openBrowser } from "../ui/auth.js";
2
- import { safe } from "../ui/collaboration.js";
3
- import { renderMcp } from "../ui/mcp.js";
4
- import { runSelection } from "../ui/selection.js";
5
- import { bad, bold, clean, dim, fields, heading, hint, json, ok, originLabel, renderValue, table, warn, } from "../ui/format.js";
6
- import { InvalidArgumentError, Option } from "commander";
7
- import { ORIGIN_HELP } from "../ui/format.js";
8
- import { pickInstalled, resolveOrigin } from "./origin.js";
9
- import { renderHookCompatibility, } from "../ui/hook-compatibility.js";
10
- function positive(value) {
11
- const result = Number(value);
12
- if (!Number.isSafeInteger(result) || result < 1)
13
- throw new InvalidArgumentError("Use a positive integer");
14
- return result;
2
+ import { bad, bold, dim, fields, heading, hint, json, ok, warn, } from "../ui/format.js";
3
+ import { registerMcp } from "./mcp.js";
4
+ import { registerHooks } from "./hooks.js";
5
+ import { registerKnowledge } from "./knowledge.js";
6
+ import { registerPeople } from "./people.js";
7
+ import { registerGithub } from "./github.js";
8
+ const checkMarks = {
9
+ ok: ok("✔"),
10
+ warn: warn("!"),
11
+ fail: bad("✖"),
12
+ };
13
+ function repositoryLabel(repository, ambiguous) {
14
+ if (repository) {
15
+ return `${bold(repository.name)} ${dim(`repo/${repository.slug}`)}`;
16
+ }
17
+ if (ambiguous) {
18
+ return warn("matches several BarnDog repositories");
19
+ }
20
+ return dim("not registered in BarnDog");
15
21
  }
16
- export function registerCapabilities(program, context) {
17
- const write = (value) => context.write(safe(value));
18
- const print = (result) => {
19
- if (context.mode.json)
20
- context.write(json(result));
21
- else if (typeof result === "object" && result && "message" in result)
22
- write(String(result.message));
23
- else
24
- for (const line of renderValue(result))
25
- context.write(line);
26
- };
27
- const run = async (action, options = {}) => {
28
- const result = await context.capability(action, options);
29
- if (action === "hooks-test") {
30
- const test = result;
31
- // The Hook's own result is the command's result, however it is printed.
32
- if (test.exitCode || test.timedOut)
33
- process.exitCode = test.timedOut ? 124 : test.exitCode;
34
- if (context.mode.json)
35
- return context.write(json(result));
36
- if (test.stdout)
37
- write(test.stdout.trimEnd());
38
- if (test.stderr)
39
- write(test.stderr.trimEnd());
40
- write(test.timedOut
41
- ? `${bad("✖")} Hook test timed out.`
42
- : test.exitCode
43
- ? `${bad("✖")} Hook test exited ${test.exitCode}.`
44
- : `${ok("✔")} Hook test exited 0.`);
45
- return;
46
- }
47
- if (action === "hooks-compatibility" && !context.mode.json) {
48
- for (const line of renderHookCompatibility(options.name, result))
49
- context.write(line);
50
- return;
51
- }
52
- if (!context.mode.json &&
53
- (action === "show" || action === "mcp-create" || action === "mcp-update")) {
54
- if (action !== "show")
55
- write(`${ok("✔")} Published ${options.name}.`);
56
- for (const line of renderMcp(result))
57
- context.write(line);
58
- return;
59
- }
60
- print(result);
61
- };
62
- /** Adds the owning scope, asking only when several scopes share the name. */
63
- const locate = async (kind, name, options, usage) => name
64
- ? {
65
- ...options,
66
- name,
67
- origin: await resolveOrigin(context, kind, name, options.origin, usage.replace("<name>", name)),
68
- }
69
- : { ...options, ...(await pickInstalled(context, kind, usage)) };
22
+ function yesNo(value) {
23
+ return value ? ok("yes") : "no";
24
+ }
25
+ function doctorSummary(failed, warned) {
26
+ if (failed) {
27
+ return `${bad("✖")} ${failed} ${failed === 1 ? "problem" : "problems"} found.`;
28
+ }
29
+ if (warned) {
30
+ return `${warn("!")} ${warned} ${warned === 1 ? "warning" : "warnings"}.`;
31
+ }
32
+ return `${ok("✔")} Everything looks good.`;
33
+ }
34
+ /** `whoami`, `open`, `repo status` and `doctor`. */
35
+ function registerGeneral(program, context) {
70
36
  program
71
37
  .command("whoami")
72
38
  .description("Show who you're signed in as (same as auth status)")
@@ -76,11 +42,13 @@ export function registerCapabilities(program, context) {
76
42
  .description("Open your BarnDog workspace in a browser")
77
43
  .option("--no-browser", "Print the URL without opening it")
78
44
  .action(async (options) => {
79
- const { url } = (await context.capability("open", {}));
80
- if (context.mode.json)
45
+ const url = await context.workspaceUrl();
46
+ if (context.mode.json) {
81
47
  return context.write(json({ url }));
82
- if (!options.browser)
48
+ }
49
+ if (!options.browser) {
83
50
  return context.write(url);
51
+ }
84
52
  try {
85
53
  await openBrowser(url);
86
54
  context.write(`${ok("✔")} Opened ${bold(url)} in your browser.`);
@@ -95,32 +63,24 @@ export function registerCapabilities(program, context) {
95
63
  .command("status", { isDefault: true })
96
64
  .description("Show the repository, its owning team and whether you're subscribed")
97
65
  .action(async () => {
98
- const result = (await context.capability("repo-status", {}));
99
- const sets = result.repository
100
- ? (await context
101
- .environment("sets-list", {})
102
- .catch(() => undefined))
103
- : undefined;
104
- if (context.mode.json)
66
+ const result = await context.repoStatus();
67
+ // A failed lookup is reported, never shown as "Subscribed: no".
68
+ const sets = result.repository ? await context.listSets() : undefined;
69
+ if (context.mode.json) {
105
70
  return context.write(json(result));
71
+ }
106
72
  if (!result.root) {
107
73
  context.write("Not inside a Git repository.");
108
74
  context.write(hint("cd <your-repository> && barndog repo status", "Tip"));
109
75
  return;
110
76
  }
111
- const subscribed = result.repository &&
112
- sets?.subscriptions.some((s) => s.scope.type === "repo" && s.scope.id === result.repository.id);
77
+ const repositoryId = result.repository?.id;
78
+ const subscribed = repositoryId &&
79
+ sets?.subscriptions.some((s) => s.scope.type === "repo" && s.scope.id === repositoryId);
113
80
  for (const line of fields([
114
81
  ["Folder", result.root],
115
82
  ["Remotes", result.remotes.join(", ") || dim("none")],
116
- [
117
- "Repository",
118
- result.repository
119
- ? `${bold(result.repository.name)} ${dim(`repo/${result.repository.slug}`)}`
120
- : result.ambiguous
121
- ? warn("matches several BarnDog repositories")
122
- : dim("not registered in BarnDog"),
123
- ],
83
+ ["Repository", repositoryLabel(result.repository, result.ambiguous)],
124
84
  [
125
85
  "Owning team",
126
86
  result.team
@@ -129,10 +89,11 @@ export function registerCapabilities(program, context) {
129
89
  ],
130
90
  [
131
91
  "Subscribed",
132
- result.repository ? (subscribed ? ok("yes") : "no") : undefined,
92
+ result.repository ? yesNo(Boolean(subscribed)) : undefined,
133
93
  ],
134
- ]))
94
+ ])) {
135
95
  context.write(line);
96
+ }
136
97
  if (result.repository && !subscribed) {
137
98
  context.write("");
138
99
  context.write(hint(`barndog sets install repo/${result.repository.slug}`) +
@@ -147,342 +108,37 @@ export function registerCapabilities(program, context) {
147
108
  .command("doctor")
148
109
  .description("Check your setup, session and installed assets, and suggest fixes")
149
110
  .action(async () => {
150
- const checks = (await context.capability("doctor", {}));
151
- if (context.mode.json)
111
+ const checks = await context.doctor();
112
+ if (context.mode.json) {
152
113
  return context.write(json(checks));
114
+ }
153
115
  context.write(`\n${heading("doctor")}\n`);
154
116
  const width = Math.max(...checks.map((c) => c.name.length));
155
117
  for (const check of checks) {
156
- const mark = check.status === "ok"
157
- ? ok("✔")
158
- : check.status === "warn"
159
- ? warn("!")
160
- : bad("✖");
118
+ const mark = checkMarks[check.status];
161
119
  context.write(`${mark} ${check.name.padEnd(width)} ${check.status === "ok" ? dim(check.detail) : check.detail}`);
162
- if (check.fix)
120
+ if (check.fix) {
163
121
  context.write(` ${" ".repeat(width)} ${hint(check.fix, "Fix")}`);
122
+ }
164
123
  }
165
124
  const failed = checks.filter((c) => c.status === "fail").length;
166
125
  const warned = checks.filter((c) => c.status === "warn").length;
167
126
  context.write("");
168
- context.write(failed
169
- ? `${bad("✖")} ${failed} ${failed === 1 ? "problem" : "problems"} found.`
170
- : warned
171
- ? `${warn("!")} ${warned} ${warned === 1 ? "warning" : "warnings"}.`
172
- : `${ok("✔")} Everything looks good.`);
173
- if (failed)
127
+ context.write(doctorSummary(failed, warned));
128
+ if (failed) {
174
129
  process.exitCode = 1;
130
+ }
175
131
  });
176
- const mcp = program.commands.find((c) => c.name() === "mcp");
177
- for (const action of ["create", "update"]) {
178
- const command = mcp
179
- .command(`${action} <name>`)
180
- .description(`${action === "create" ? "Create" : "Publish a new revision of"} an MCP configuration directly`)
181
- .requiredOption("--origin <origin>", ORIGIN_HELP)
182
- .requiredOption("--file <file>", "JSON connection definition with secret references")
183
- .option("--key <key>", "Stable key for exact retries");
184
- if (action === "update")
185
- command.requiredOption("--expected-version <id>", "Inspected configuration version ID");
186
- command.action((name, options) => run(`mcp-${action}`, { ...options, name }));
187
- }
188
- mcp
189
- .command("show <name>")
190
- .option("--origin <origin>", ORIGIN_HELP)
191
- .description("Inspect a connection definition")
192
- .action(async (name, options) => run("show", {
193
- ...(await locate("mcp", name, options, `barndog mcp show ${name}`)),
194
- kind: "mcp",
195
- }));
196
- mcp
197
- .command("versions <name>")
198
- .option("--origin <origin>", ORIGIN_HELP)
199
- .description("Inspect immutable configuration history")
200
- .action(async (name, options) => run("mcp-versions", await locate("mcp", name, options, `barndog mcp versions ${name}`)));
201
- mcp
202
- .command("auth <name>")
203
- .option("--origin <origin>", ORIGIN_HELP)
204
- .addOption(new Option("--harness <harness>", "Native login owner")
205
- .choices(["claude", "codex", "cursor"])
206
- .makeOptionMandatory())
207
- .description("Enter native authentication without sharing credentials")
208
- .action(async (name, options) => run("mcp-auth", await locate("mcp", name, options, `barndog mcp auth ${name} --harness ${options.harness}`)));
209
- const hooks = program.commands.find((c) => c.name() === "hooks");
210
- hooks
211
- .command("test [name]")
212
- .option("--origin <origin>", ORIGIN_HELP)
213
- .addOption(new Option("--harness <harness>", "Chosen implementation")
214
- .choices(["claude", "codex", "cursor"])
215
- .makeOptionMandatory())
216
- .requiredOption("--input <file>", "Native JSON test input")
217
- .option("--event <event>", "Native event name")
218
- .option("--handler <number>", "One-based command index", positive)
219
- .option("--timeout <seconds>", "Maximum test duration", positive)
220
- .description("Explicitly run one published command Hook with test input")
221
- .action(async (name, options) => run("hooks-test", await locate("hook", name, options, `barndog hooks test <name> --harness ${options.harness} --input ${options.input}`)));
222
- hooks
223
- .command("compatibility [name]")
224
- .option("--origin <origin>", ORIGIN_HELP)
225
- .description("Inspect version-specific declarations and local runtime requirements")
226
- .action(async (name, options) => run("hooks-compatibility", await locate("hook", name, options, "barndog hooks compatibility <name>")));
227
- hooks
228
- .command("adapt [name]")
229
- .option("--origin <origin>", ORIGIN_HELP)
230
- .addOption(new Option("--for <tools...>", "Coding tools to adapt it for (default: the ones this machine uses that it doesn't cover)").choices(["claude", "codex", "cursor"]))
231
- .description("Print a prompt for an AI agent to adapt a Hook to coding tools it wasn't written for")
232
- .action(async (name, options) => {
233
- const located = await locate("hook", name, options, "barndog hooks adapt <name>");
234
- const result = (await context.capability("hooks-adapt", {
235
- name: located.name,
236
- origin: located.origin,
237
- targets: options.for,
238
- }));
239
- if (context.mode.json)
240
- return context.write(json(result));
241
- // Printed bare, so it can be piped to the clipboard or an agent.
242
- context.write(result.prompt ??
243
- dim(`${result.name} already has settings for every coding tool this machine uses.`));
244
- });
245
- const knowledge = program
246
- .command("knowledge")
247
- .description("Read your organization's shared knowledge documents");
248
- knowledge
249
- .command("list")
250
- .description("List knowledge documents and when coding tools see them")
251
- .option("--always", "Only documents listed at every session start")
252
- .action(async (options) => {
253
- const docs = (await context.capability("knowledge-list", options));
254
- if (context.mode.json)
255
- return context.write(json(docs));
256
- const problems = (await context
257
- .capability("knowledge-problems", {})
258
- .catch(() => []));
259
- for (const problem of problems ?? [])
260
- context.write(`${warn("!")} ${problem.path}: ${problem.reason}`);
261
- if (!docs.length)
262
- return context.write(dim("No knowledge documents yet."));
263
- for (const line of table(docs.map((doc) => [
264
- bold(clean(doc.name)),
265
- doc.listedAtStart
266
- ? ok("every session")
267
- : doc.accessMode === "always"
268
- ? dim("off")
269
- : dim("on demand"),
270
- dim(clean(doc.description)),
271
- ]), { header: ["Name", "Listed", "Description"] }))
272
- context.write(line);
273
- context.write("");
274
- if (docs.some((d) => d.accessMode === "always" && !d.listedAtStart))
275
- context.write(hint("barndog knowledge enable", "Tip") +
276
- dim(" to list these at session start again"));
277
- context.write(hint("barndog knowledge get <name>", "Tip") + dim(" to read one"));
278
- });
279
- knowledge
280
- .command("get <name>")
281
- .description("Print a knowledge document")
282
- .action(async (name) => {
283
- const result = (await context.capability("knowledge-get", { name }));
284
- if (context.mode.json)
285
- return context.write(json(result));
286
- write(result.version.content.markdown);
287
- });
288
- for (const action of ["enable", "disable"])
289
- knowledge
290
- .command(action)
291
- .description(action === "enable"
292
- ? "Tell coding tools at session start which knowledge documents exist"
293
- : "Stop listing knowledge documents at session start")
294
- .action(async () => {
295
- await runSelection(context, `knowledge-${action}`, {});
296
- if (context.mode.json)
297
- return;
298
- context.write(action === "enable"
299
- ? `${ok("✔")} Coding tools now see the list of knowledge documents when a session starts.`
300
- : `${ok("✔")} Knowledge documents are no longer listed at session start.`);
301
- });
302
- const people = program
303
- .command("people")
304
- .description("Find coworkers and the personal assets they share");
305
- people
306
- .command("list")
307
- .description("List people in your organization")
308
- .option("--search <query>", "Search names or handles")
309
- .action(async (options) => {
310
- const rows = (await context.capability("developers-list", options));
311
- if (context.mode.json)
312
- return context.write(json(rows));
313
- if (!rows.length)
314
- return context.write(dim("No matching people."));
315
- for (const line of table(rows.map((person) => [
316
- bold(clean(person.name)),
317
- dim(`@${clean(person.slug)}`),
318
- ]), { header: ["Name", "Handle"] }))
319
- context.write(line);
320
- context.write("");
321
- context.write(hint("barndog people show <handle>", "Tip") +
322
- dim(" to see what someone shares"));
323
- });
324
- people
325
- .command("show <handle>")
326
- .description("List a person's shared assets")
327
- .option("--search <query>", "Filter asset names")
328
- .action(async (name, options) => {
329
- const result = (await context.capability("developers-assets", {
330
- ...options,
331
- name,
332
- }));
333
- if (context.mode.json)
334
- return context.write(json(result));
335
- context.write(`${bold(clean(result.developer.name))} ${dim(`@${result.developer.slug}`)}`);
336
- context.write("");
337
- if (!result.assets.length)
338
- return context.write(dim(" Nothing shared yet."));
339
- for (const line of table(result.assets.map((asset) => [
340
- dim(asset.kind),
341
- bold(clean(asset.name)),
342
- originLabel(asset.origin),
343
- ]), { header: ["Kind", "Name", "Origin"] }))
344
- context.write(line);
345
- });
346
- const github = program
347
- .command("github")
348
- .description("Manage GitHub App connections, contributions and mirrors");
349
- for (const action of ["auth", "install"])
350
- github
351
- .command(action)
352
- .option("--no-browser", "Print the URL without opening it")
353
- .action((options) => run(`github-${action}`, options));
354
- for (const action of ["status", "installations", "list"])
355
- github.command(action).action(() => run(`github-${action}`));
356
- for (const action of ["connect", "import"]) {
357
- const command = github
358
- .command(`${action} <name>`)
359
- .addOption(new Option("--kind <kind>", "Git-backed asset kind")
360
- .choices(["skill", "hook"])
361
- .default("skill"))
362
- .requiredOption("--origin <origin>", ORIGIN_HELP)
363
- .requiredOption("--installation <id>", "BarnDog installation binding UUID")
364
- .requiredOption("--repository <owner/name>", "Customer-selected GitHub repository");
365
- if (action === "connect")
366
- command
367
- .addOption(new Option("--mode <mode>", "mirror keeps BarnDog authoritative")
368
- .choices(["connect", "transfer", "mirror"])
369
- .default("connect"))
370
- .option("--expected-version <id>", "Inspected BarnDog version ID");
371
- if (action === "import")
372
- command
373
- .addOption(new Option("--authority <authority>", "Copy into BarnDog or keep GitHub authoritative")
374
- .choices(["barndog", "github"])
375
- .default("github"))
376
- .option("--key <key>", "Required for BarnDog-owned copies; retain for exact retries");
377
- command.action((name, options) => run(`github-${action}`, { ...options, name }));
378
- }
379
- github
380
- .command("create-repository <name>")
381
- .description("Create a GitHub repository and export published history")
382
- .addOption(new Option("--kind <kind>", "Asset kind")
383
- .choices(["skill", "hook"])
384
- .default("skill"))
385
- .requiredOption("--origin <origin>", ORIGIN_HELP)
386
- .requiredOption("--installation <id>", "BarnDog installation binding UUID")
387
- .requiredOption("--repository <owner/name>", "New repository to create")
388
- .requiredOption("--key <key>", "Stable key; retain for exact retries")
389
- .requiredOption("--expected-version <id>", "Inspected BarnDog version")
390
- .addOption(new Option("--mode <mode>", "Content authority after export")
391
- .choices(["mirror", "transfer"])
392
- .default("mirror"))
393
- .addOption(new Option("--visibility <visibility>", "New repository visibility")
394
- .choices(["private", "public"])
395
- .default("private"))
396
- .action((name, options) => run("github-create-repository", { ...options, name }));
397
- for (const action of ["show", "sync", "remote-head"])
398
- github
399
- .command(`${action} <id>`)
400
- .action((id) => run(`github-${action}`, { id }));
401
- github
402
- .command("resolve-mirror <id>")
403
- .addOption(new Option("--action <action>", "Explicit divergence resolution")
404
- .choices(["use-barndog", "use-mirror", "disconnect"])
405
- .makeOptionMandatory())
406
- .requiredOption("--expected-version <id>", "Inspected BarnDog version")
407
- .requiredOption("--expected-remote <sha|absent>", "Inspected remote main SHA or absent")
408
- .option("--key <key>", "Stable key for exact retries")
409
- .action((id, options) => run("github-mirror-resolve", { ...options, id }));
410
- const pulls = github
411
- .command("pulls")
412
- .description("Inspect and contribute to externally authoritative assets");
413
- pulls.command("list <id>").action((id) => run("github-pulls-list", { id }));
414
- pulls
415
- .command("show <id> <number>")
416
- .action((id, number) => run("github-pulls-show", { id, number: positive(number) }));
417
- pulls
418
- .command("create <id>")
419
- .requiredOption("--expected-commit <sha>", "Inspected canonical commit")
420
- .requiredOption("--title <title>", "Pull request title")
421
- .option("--directory <path>", "Complete editable package directory")
422
- .option("--body <text>", "Pull request body")
423
- .option("--body-file <path>", "Pull request body file")
424
- .option("--key <key>", "Stable key for exact retries")
425
- .action((id, options) => run("github-pulls-create", { ...options, id }));
426
- pulls
427
- .command("revise <id> <number>")
428
- .requiredOption("--expected-commit <sha>", "Inspected pull head commit")
429
- .option("--title <title>", "Updated title")
430
- .option("--directory <path>", "Complete package directory")
431
- .option("--body <text>", "Updated body")
432
- .option("--body-file <file>", "Updated body file")
433
- .option("--key <key>", "Stable key for exact retries")
434
- .action((id, number, options) => run("github-pulls-revise", { ...options, id, number: positive(number) }));
435
- for (const action of ["review", "comment", "merge"]) {
436
- const command = pulls
437
- .command(`${action} <id> <number>`)
438
- .requiredOption("--expected-commit <sha>", "Inspected pull head commit");
439
- if (action !== "merge")
440
- command
441
- .option("--body <text>", "Review or comment")
442
- .option("--body-file <file>", "Review or comment file");
443
- if (action === "review")
444
- command.addOption(new Option("--event <event>", "Review decision")
445
- .choices(["APPROVE", "REQUEST_CHANGES", "COMMENT"])
446
- .makeOptionMandatory());
447
- if (action === "comment")
448
- command
449
- .option("--path <file>", "Inline file")
450
- .option("--line <number>", "Inline line", positive)
451
- .addOption(new Option("--side <side>", "Inline diff side").choices([
452
- "LEFT",
453
- "RIGHT",
454
- ]));
455
- command.action((id, number, options) => run(`github-pulls-${action}`, {
456
- ...options,
457
- id,
458
- number: positive(number),
459
- }));
460
- }
461
- const describe = (parent, descriptions) => {
462
- for (const command of parent.commands)
463
- if (!command.description() && descriptions[command.name()])
464
- command.description(descriptions[command.name()]);
465
- };
466
- describe(github, {
467
- auth: "Link your GitHub account to BarnDog",
468
- install: "Install the BarnDog GitHub App on an account or organization",
469
- status: "Show your GitHub account and App connection",
470
- installations: "List GitHub App installations you can use",
471
- list: "List Skills and Hooks connected to GitHub repositories",
472
- connect: "Connect a Skill or Hook to a GitHub repository",
473
- import: "Import a Skill or Hook from a GitHub repository",
474
- show: "Show a GitHub connection",
475
- sync: "Sync a connection with its repository now",
476
- "remote-head": "Show the repository's current main commit",
477
- "resolve-mirror": "Resolve a mirror that diverged from BarnDog",
478
- });
479
- describe(pulls, {
480
- list: "List pull requests for a connected asset",
481
- show: "Show a pull request",
482
- create: "Open a pull request with your edits",
483
- revise: "Update an open pull request",
484
- review: "Approve or request changes on a pull request",
485
- comment: "Comment on a pull request",
486
- merge: "Merge a pull request",
487
- });
132
+ }
133
+ /**
134
+ * Registers the diagnostic commands and the `mcp`, `hooks`, `knowledge`, `people`
135
+ * and `github` groups.
136
+ */
137
+ export function registerCapabilities(program, context) {
138
+ registerGeneral(program, context);
139
+ registerMcp(program, context);
140
+ registerHooks(program, context);
141
+ registerKnowledge(program, context);
142
+ registerPeople(program, context);
143
+ registerGithub(program, context);
488
144
  }