barndog 0.0.0-stage → 0.1.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 (109) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +117 -2
  3. package/dist/cli.js +40 -0
  4. package/dist/commands/add.js +99 -0
  5. package/dist/commands/auth.js +25 -0
  6. package/dist/commands/availability.js +87 -0
  7. package/dist/commands/capabilities.js +488 -0
  8. package/dist/commands/collaboration.js +203 -0
  9. package/dist/commands/context.js +1 -0
  10. package/dist/commands/environment.js +416 -0
  11. package/dist/commands/init.js +20 -0
  12. package/dist/commands/origin.js +48 -0
  13. package/dist/commands/status.js +66 -0
  14. package/dist/commands/sync.js +30 -0
  15. package/dist/commands/workspace.js +84 -0
  16. package/dist/config/build.js +2 -0
  17. package/dist/config/environment.js +41 -0
  18. package/dist/config/settings.js +127 -0
  19. package/dist/config/state.js +70 -0
  20. package/dist/errors.js +154 -0
  21. package/dist/features/asset-selection/index.js +212 -0
  22. package/dist/features/asset-selection/types.js +1 -0
  23. package/dist/features/auth/credentials.js +62 -0
  24. package/dist/features/auth/session.js +120 -0
  25. package/dist/features/auth/transport.js +44 -0
  26. package/dist/features/capabilities/index.js +106 -0
  27. package/dist/features/catalog/index.js +102 -0
  28. package/dist/features/collaboration/domain.js +90 -0
  29. package/dist/features/collaboration/index.js +254 -0
  30. package/dist/features/collaboration/remote.js +121 -0
  31. package/dist/features/collaboration/workspace-git.js +362 -0
  32. package/dist/features/collaboration/workspace-github.js +130 -0
  33. package/dist/features/collaboration/workspace-store.js +256 -0
  34. package/dist/features/collaboration/workspace.js +391 -0
  35. package/dist/features/discovery/index.js +66 -0
  36. package/dist/features/doctor/index.js +154 -0
  37. package/dist/features/environment/auto-sync.js +96 -0
  38. package/dist/features/environment/cloud-source.js +27 -0
  39. package/dist/features/environment/installed.js +124 -0
  40. package/dist/features/environment/names.js +153 -0
  41. package/dist/features/environment/operations.js +277 -0
  42. package/dist/features/environment/packages.js +120 -0
  43. package/dist/features/environment/remote.js +71 -0
  44. package/dist/features/environment/source.js +1 -0
  45. package/dist/features/environment/sync.js +547 -0
  46. package/dist/features/environment/transaction.js +284 -0
  47. package/dist/features/environment/workspace-source.js +19 -0
  48. package/dist/features/git-hosts/index.js +148 -0
  49. package/dist/features/git-workspace/assets.js +71 -0
  50. package/dist/features/git-workspace/format.js +310 -0
  51. package/dist/features/git-workspace/git.js +135 -0
  52. package/dist/features/git-workspace/migrate.js +188 -0
  53. package/dist/features/git-workspace/move.js +337 -0
  54. package/dist/features/git-workspace/overlay.js +131 -0
  55. package/dist/features/git-workspace/publish.js +172 -0
  56. package/dist/features/git-workspace/setup.js +135 -0
  57. package/dist/features/git-workspace/snapshot.js +105 -0
  58. package/dist/features/git-workspace/source.js +159 -0
  59. package/dist/features/git-workspace/startup.js +16 -0
  60. package/dist/features/hooks/adapt.js +103 -0
  61. package/dist/features/hooks/divergence.js +38 -0
  62. package/dist/features/hooks/test.js +114 -0
  63. package/dist/features/imports/discover.js +249 -0
  64. package/dist/features/imports/folder.js +52 -0
  65. package/dist/features/imports/local.js +242 -0
  66. package/dist/features/imports/mcp.js +219 -0
  67. package/dist/features/imports/remote.js +85 -0
  68. package/dist/features/inspection/index.js +42 -0
  69. package/dist/features/inventory/index.js +224 -0
  70. package/dist/features/knowledge/index.js +118 -0
  71. package/dist/features/knowledge/startup.js +25 -0
  72. package/dist/features/mcps/index.js +102 -0
  73. package/dist/features/native/adapters.js +143 -0
  74. package/dist/features/native/configuration.js +196 -0
  75. package/dist/features/native/mcp-launch.js +57 -0
  76. package/dist/features/onboarding/environment.js +160 -0
  77. package/dist/features/onboarding/setup.js +123 -0
  78. package/dist/features/repositories/context.js +55 -0
  79. package/dist/features/skills/install.js +25 -0
  80. package/dist/features/skills/remote.js +177 -0
  81. package/dist/features/skills/sync.js +121 -0
  82. package/dist/features/skills/validation.js +34 -0
  83. package/dist/harnesses/claude.js +57 -0
  84. package/dist/harnesses/codex.js +46 -0
  85. package/dist/harnesses/cursor.js +44 -0
  86. package/dist/harnesses/detect.js +61 -0
  87. package/dist/harnesses/registry.js +16 -0
  88. package/dist/harnesses/types.js +1 -0
  89. package/dist/program.js +272 -0
  90. package/dist/ui/add-asset.js +440 -0
  91. package/dist/ui/asset-list.js +50 -0
  92. package/dist/ui/assets.js +142 -0
  93. package/dist/ui/auth.js +138 -0
  94. package/dist/ui/clash.js +43 -0
  95. package/dist/ui/collaboration.js +142 -0
  96. package/dist/ui/connection.js +102 -0
  97. package/dist/ui/environment-onboarding.js +125 -0
  98. package/dist/ui/format.js +154 -0
  99. package/dist/ui/hook-compatibility.js +33 -0
  100. package/dist/ui/mcp.js +40 -0
  101. package/dist/ui/move.js +22 -0
  102. package/dist/ui/onboarding.js +293 -0
  103. package/dist/ui/output.js +155 -0
  104. package/dist/ui/pick.js +153 -0
  105. package/dist/ui/scope-install.js +47 -0
  106. package/dist/ui/selection.js +51 -0
  107. package/dist/ui/theme.js +37 -0
  108. package/dist/version.js +12 -0
  109. package/package.json +73 -4
@@ -0,0 +1,488 @@
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;
15
+ }
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)) };
70
+ program
71
+ .command("whoami")
72
+ .description("Show who you're signed in as (same as auth status)")
73
+ .action(() => context.authStatus());
74
+ program
75
+ .command("open")
76
+ .description("Open your BarnDog workspace in a browser")
77
+ .option("--no-browser", "Print the URL without opening it")
78
+ .action(async (options) => {
79
+ const { url } = (await context.capability("open", {}));
80
+ if (context.mode.json)
81
+ return context.write(json({ url }));
82
+ if (!options.browser)
83
+ return context.write(url);
84
+ try {
85
+ await openBrowser(url);
86
+ context.write(`${ok("✔")} Opened ${bold(url)} in your browser.`);
87
+ }
88
+ catch {
89
+ context.write(`Couldn't open a browser. Visit ${bold(url)}`);
90
+ }
91
+ });
92
+ program
93
+ .command("repo")
94
+ .description("See how the current Git repository maps to BarnDog")
95
+ .command("status", { isDefault: true })
96
+ .description("Show the repository, its owning team and whether you're subscribed")
97
+ .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)
105
+ return context.write(json(result));
106
+ if (!result.root) {
107
+ context.write("Not inside a Git repository.");
108
+ context.write(hint("cd <your-repository> && barndog repo status", "Tip"));
109
+ return;
110
+ }
111
+ const subscribed = result.repository &&
112
+ sets?.subscriptions.some((s) => s.scope.type === "repo" && s.scope.id === result.repository.id);
113
+ for (const line of fields([
114
+ ["Folder", result.root],
115
+ ["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
+ ],
124
+ [
125
+ "Owning team",
126
+ result.team
127
+ ? `${result.team.name} ${dim(`team/${result.team.slug}`)}`
128
+ : undefined,
129
+ ],
130
+ [
131
+ "Subscribed",
132
+ result.repository ? (subscribed ? ok("yes") : "no") : undefined,
133
+ ],
134
+ ]))
135
+ context.write(line);
136
+ if (result.repository && !subscribed) {
137
+ context.write("");
138
+ context.write(hint(`barndog sets install repo/${result.repository.slug}`) +
139
+ dim(" to use this repository's shared assets"));
140
+ }
141
+ if (!result.repository && !result.ambiguous) {
142
+ context.write("");
143
+ context.write(dim("An admin can register this repository in the BarnDog workspace."));
144
+ }
145
+ });
146
+ program
147
+ .command("doctor")
148
+ .description("Check your setup, session and installed assets, and suggest fixes")
149
+ .action(async () => {
150
+ const checks = (await context.capability("doctor", {}));
151
+ if (context.mode.json)
152
+ return context.write(json(checks));
153
+ context.write(`\n${heading("doctor")}\n`);
154
+ const width = Math.max(...checks.map((c) => c.name.length));
155
+ for (const check of checks) {
156
+ const mark = check.status === "ok"
157
+ ? ok("✔")
158
+ : check.status === "warn"
159
+ ? warn("!")
160
+ : bad("✖");
161
+ context.write(`${mark} ${check.name.padEnd(width)} ${check.status === "ok" ? dim(check.detail) : check.detail}`);
162
+ if (check.fix)
163
+ context.write(` ${" ".repeat(width)} ${hint(check.fix, "Fix")}`);
164
+ }
165
+ const failed = checks.filter((c) => c.status === "fail").length;
166
+ const warned = checks.filter((c) => c.status === "warn").length;
167
+ 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)
174
+ process.exitCode = 1;
175
+ });
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
+ });
488
+ }