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
package/dist/program.js CHANGED
@@ -1,21 +1,45 @@
1
+ import { resolve } from "node:path";
1
2
  import { Command, Help, Option } from "commander";
3
+ import { homedir } from "node:os";
2
4
  import { styleText } from "node:util";
3
- import { registerCollaboration } from "./commands/collaboration.js";
4
- import { collaborate } from "./features/collaboration/index.js";
5
+ import { registerCollaboration, registerWorkingCopy, } from "./commands/collaboration.js";
6
+ import { applySuggestion, changeDiff, commentOnChange, createPackage, diffVersions, listChanges, mergeChange, packageVersions, pullPackage, pushWorkingCopy, rejectChange, resolveFile, reviewChange, setDiscussionResolved, showChange, updateWorkingCopy, versionFiles, workingDiff, workingStatus, } from "./features/collaboration/index.js";
5
7
  import { registerAuth } from "./commands/auth.js";
6
8
  import { runLogin, runLogout, showAuthStatus } from "./ui/auth.js";
7
9
  import { registerInit } from "./commands/init.js";
8
10
  import { registerSync } from "./commands/sync.js";
11
+ import { registerHarnesses } from "./commands/harnesses.js";
9
12
  import { registerStatus } from "./commands/status.js";
10
- import { settingsPath } from "./config/settings.js";
11
13
  import { clashPrompt, synchronize } from "./features/environment/sync.js";
12
- import { environmentOperation } from "./features/environment/operations.js";
13
- import { capability } from "./features/capabilities/index.js";
14
+ import { changeAsset, changeAssets, changeSet, installSet, installSetAssets, listSets, previewSet, renameAsset, setKnowledge, switchSet, } from "./features/environment/operations.js";
15
+ import { changeHarnesses, listHarnesses, selectHarnesses, } from "./features/environment/harnesses.js";
16
+ import { doctor } from "./features/doctor/index.js";
17
+ import { repoStatus, workspaceUrl } from "./features/inspection/index.js";
18
+ import { validateFolder } from "./features/workspace/assets.js";
19
+ import { migrate } from "./features/migration/migrate.js";
20
+ import { listLocalAssets, moveLocalAssets } from "./features/migration/move.js";
21
+ import { adoptNative } from "./features/adoption/adopt.js";
22
+ import { undoAdoption } from "./features/adoption/undo.js";
23
+ import { listAdoptions } from "./features/adoption/record.js";
24
+ import { scanNative } from "./features/adoption/scan.js";
25
+ import { updateImported } from "./features/imports/local.js";
26
+ import { authenticateMcp, createMcp, mcpVersions, showMcp, updateMcp, } from "./features/mcps/index.js";
27
+ import { adaptHook, toolNames } from "./features/hooks/adapt.js";
28
+ import { harnesses } from "./harnesses/registry.js";
29
+ import { hookCompatibility } from "./features/hooks/compatibility.js";
30
+ import { testHook } from "./features/hooks/test.js";
31
+ import { knowledgeGet, knowledgeList, knowledgeProblems, } from "./features/knowledge/index.js";
32
+ import { developerAssets, developers, fork, } from "./features/discovery/index.js";
33
+ import { promote } from "./features/migration/promote.js";
34
+ import { githubAuth, githubInstall, githubInstallations, githubStatus, } from "./features/github/account.js";
35
+ import { githubConnect, githubCreateRepository, githubImport, githubImportCopy, githubList, githubRemoteHead, githubResolveMirror, githubShow, githubSync, } from "./features/github/connections.js";
36
+ import { githubPullsComment, githubPullsCreate, githubPullsList, githubPullsMerge, githubPullsReview, githubPullsRevise, githubPullsShow, } from "./features/github/pulls.js";
14
37
  import { inventory } from "./features/inventory/index.js";
15
38
  import { searchCatalog } from "./features/catalog/index.js";
16
39
  import { registerEnvironment } from "./commands/environment.js";
17
40
  import { registerCapabilities } from "./commands/capabilities.js";
18
41
  import { registerWorkspace } from "./commands/workspace.js";
42
+ import { registerAdopt } from "./commands/adopt.js";
19
43
  import { registerAdd } from "./commands/add.js";
20
44
  import { commandNeeds, modeName, needText, unavailableNote, } from "./commands/availability.js";
21
45
  import { runSetup } from "./ui/onboarding.js";
@@ -23,16 +47,34 @@ import { interactiveTerminal } from "./ui/pick.js";
23
47
  import { promptClash } from "./ui/clash.js";
24
48
  import { primary } from "./ui/theme.js";
25
49
  import { versionReport } from "./version.js";
50
+ import { defined } from "./shared/lookup.js";
51
+ import { barndogPaths } from "./config/paths.js";
52
+ import { showPackage } from "./features/inventory/show.js";
53
+ import { forgetMcpValue, keepMcpValue, listKeptValues, } from "./features/mcps/values.js";
54
+ import { readSettings } from "./config/settings.js";
55
+ /** Keep command help readable at the conventional eighty-column terminal width. */
56
+ const HELP_WIDTH = 80;
26
57
  /** Help sections, in order; every top-level command belongs to one. */
27
58
  const groups = [
28
59
  [
29
60
  "Get started:",
30
- ["init", "login", "logout", "auth", "whoami", "sync", "status", "doctor"],
61
+ [
62
+ "init",
63
+ "login",
64
+ "logout",
65
+ "auth",
66
+ "whoami",
67
+ "sync",
68
+ "status",
69
+ "doctor",
70
+ "harnesses",
71
+ "adopt",
72
+ ],
31
73
  ],
32
74
  ["Assets:", ["skills", "mcp", "hooks", "sets", "knowledge"]],
33
75
  [
34
76
  "Working copy & review (run inside a folder from `skills pull`, `hooks pull` or `create`):",
35
- ["pull", "diff", "push", "resolve", "changes"],
77
+ ["pull", "diff", "push", "resolve"],
36
78
  ],
37
79
  [
38
80
  "Workspace:",
@@ -63,26 +105,41 @@ const assetGroups = [
63
105
  ["Test and adapt:", ["test", "compatibility", "adapt"]],
64
106
  ];
65
107
  /** The command's words without the program name, as availability rules name them. */
108
+ /** The help section of a command in an asset group. */
109
+ function helpGroup(group, command, heading) {
110
+ // MCP create/show/versions publish or inspect definitions directly.
111
+ if (group === "mcp" && ["create", "show", "versions"].includes(command)) {
112
+ return "Publish directly:";
113
+ }
114
+ if (group !== "mcp" && command === "update") {
115
+ return "On this machine:";
116
+ }
117
+ return heading;
118
+ }
66
119
  function commandPath(command) {
67
120
  const path = [];
68
- for (let c = command; c?.parent; c = c.parent)
121
+ for (let c = command; c?.parent; c = c.parent) {
69
122
  path.unshift(c.name());
123
+ }
70
124
  return path.join(" ");
71
125
  }
72
126
  /** A group is unavailable only when nothing inside it can run. */
73
127
  function helpNeed(command, mode) {
74
128
  const children = command.commands.filter((c) => c.name() !== "help");
75
- if (!children.length)
129
+ if (!children.length) {
76
130
  return commandNeeds(commandPath(command), mode);
131
+ }
77
132
  const needs = children.map((child) => helpNeed(child, mode));
78
- if (!needs.every(Boolean))
133
+ if (!needs.every(Boolean)) {
79
134
  return undefined;
135
+ }
80
136
  return needs.includes("shared") ? "shared" : "cloud";
81
137
  }
82
138
  function listsUnavailable(command) {
83
139
  let root = command;
84
- while (root.parent)
140
+ while (root.parent) {
85
141
  root = root.parent;
142
+ }
86
143
  return root.opts().listUnavailable === true;
87
144
  }
88
145
  /** Hides what this setup can't run, unless asked for or already looking at one. */
@@ -101,8 +158,9 @@ function limitedHelp(mode) {
101
158
  },
102
159
  subcommandTerm(command) {
103
160
  const term = Help.prototype.subcommandTerm.call(this, command);
104
- if (note(command))
161
+ if (note(command)) {
105
162
  dimmed.add(term);
163
+ }
106
164
  return term;
107
165
  },
108
166
  subcommandDescription(command) {
@@ -120,21 +178,24 @@ function limitedHelp(mode) {
120
178
  /** The closing lines of help: what was left out, why, and how to see it. */
121
179
  function unavailableHint(command, mode) {
122
180
  const own = helpNeed(command, mode);
123
- if (own)
181
+ if (own) {
124
182
  return `\n${styleText("dim", unavailableNote(own, mode))}`;
125
- if (listsUnavailable(command))
183
+ }
184
+ if (listsUnavailable(command)) {
126
185
  return "";
186
+ }
127
187
  const hidden = new Help().visibleCommands(command).flatMap((child) => {
128
188
  const need = helpNeed(child, mode);
129
189
  return need ? [{ name: child.name(), need }] : [];
130
190
  });
131
- if (!hidden.length)
191
+ if (!hidden.length) {
132
192
  return "";
193
+ }
133
194
  const need = hidden.some((c) => c.need === "shared") ? "shared" : "cloud";
134
195
  const one = hidden.length === 1;
135
196
  const path = commandPath(command);
136
197
  const help = new Help();
137
- const width = Math.min(process.stdout.columns || 80, 80);
198
+ const width = Math.min(process.stdout.columns || HELP_WIDTH, HELP_WIDTH);
138
199
  const lines = [
139
200
  `${one ? "One command is" : "Some commands are"} hidden in ${modeName(mode)} mode because ${one ? "it needs" : "they need"} ${needText(need)}: ${hidden.map((c) => c.name).join(", ")}.`,
140
201
  `Run barndog ${path ? `${path} ` : ""}--help --list-unavailable to see ${one ? "it" : "them"}.`,
@@ -146,48 +207,194 @@ function unavailableHint(command, mode) {
146
207
  * here before complaining about its flags. Help stays available either way.
147
208
  */
148
209
  function guardRequiredOptions(parent, guard) {
149
- for (const child of parent.commands)
210
+ for (const child of parent.commands) {
150
211
  guardRequiredOptions(child, guard);
151
- if (!parent.commands.length)
212
+ }
213
+ if (!parent.commands.length) {
152
214
  return;
215
+ }
153
216
  parent.hook("preSubcommand", async (_, command) => {
154
- if (command.commands.length || !command.options.some((o) => o.mandatory))
217
+ if (command.commands.length || !command.options.some((o) => o.mandatory)) {
155
218
  return;
219
+ }
156
220
  let root = parent;
157
- while (root.parent)
221
+ while (root.parent) {
158
222
  root = root.parent;
223
+ }
159
224
  const { rawArgs = [] } = root;
160
- if (rawArgs.includes("--help") || rawArgs.includes("-h"))
225
+ if (rawArgs.includes("--help") || rawArgs.includes("-h")) {
161
226
  return;
227
+ }
162
228
  await guard(commandPath(command).split(" "), {});
163
229
  });
164
230
  }
231
+ /** Process entry points capture ambient inputs here; downstream code receives this object. */
232
+ export function captureRuntime(options = {}) {
233
+ const cwd = resolve(options.cwd ?? process.cwd());
234
+ return {
235
+ home: resolve(cwd, options.home ?? homedir()),
236
+ cwd,
237
+ env: { ...(options.env ?? process.env) },
238
+ platform: options.platform ?? process.platform,
239
+ };
240
+ }
165
241
  /** Construct a fresh parser for every invocation or test; command behavior is independently injectable. */
166
242
  export function createProgram(options = {}) {
167
243
  const write = options.write ?? console.log;
244
+ // The one place the real home directory is read; everything below takes it.
245
+ const runtime = options.runtime ?? captureRuntime(options);
246
+ const { home } = runtime;
168
247
  const mode = {
169
248
  json: false,
170
249
  interactive: options.interactive ?? interactiveTerminal(),
171
250
  };
172
251
  const context = {
173
- collaborate: options.collaborate ?? collaborate,
174
- login: options.login ?? ((login) => runLogin(login, write)),
175
- logout: options.logout ?? (() => runLogout(write)),
176
- authStatus: options.authStatus ?? (() => showAuthStatus({ write, json: mode.json })),
252
+ applySuggestion: options.applySuggestion ?? ((target) => applySuggestion(target, runtime)),
253
+ changeDiff: options.changeDiff ?? ((target) => changeDiff(target, runtime)),
254
+ commentOnChange: options.commentOnChange ??
255
+ ((options) => commentOnChange(options, runtime)),
256
+ createPackage: options.createPackage ?? ((target) => createPackage(target, runtime)),
257
+ diffVersions: options.diffVersions ?? ((target) => diffVersions(target, runtime)),
258
+ listChanges: options.listChanges ?? ((options) => listChanges(options, runtime)),
259
+ mergeChange: options.mergeChange ?? ((target) => mergeChange(target, runtime)),
260
+ packageVersions: options.packageVersions ?? ((target) => packageVersions(target, runtime)),
261
+ pullPackage: options.pullPackage ?? ((target) => pullPackage(target, runtime)),
262
+ pushWorkingCopy: options.pushWorkingCopy ??
263
+ ((options) => pushWorkingCopy(options, runtime)),
264
+ rejectChange: options.rejectChange ?? ((target) => rejectChange(target, runtime)),
265
+ resolveFile: options.resolveFile ?? ((path) => resolveFile(path, runtime)),
266
+ reviewChange: options.reviewChange ??
267
+ ((decision, target) => reviewChange(decision, target, runtime)),
268
+ setDiscussionResolved: options.setDiscussionResolved ??
269
+ ((target) => setDiscussionResolved(target, runtime)),
270
+ showChange: options.showChange ?? ((target) => showChange(target, runtime)),
271
+ updateWorkingCopy: options.updateWorkingCopy ?? (() => updateWorkingCopy(runtime)),
272
+ versionFiles: options.versionFiles ?? ((target) => versionFiles(target, runtime)),
273
+ workingDiff: options.workingDiff ?? (() => workingDiff(runtime)),
274
+ workingStatus: options.workingStatus ?? (() => workingStatus(runtime)),
275
+ login: options.login ??
276
+ ((login) => runLogin({ ...login, runtime, interactive: mode.interactive }, write)),
277
+ logout: options.logout ?? (() => runLogout(write, runtime)),
278
+ authStatus: options.authStatus ??
279
+ (() => showAuthStatus({ write, json: mode.json }, runtime)),
280
+ isSetUp: options.isSetUp ??
281
+ // A damaged file counts as set up: the command that reads it explains what's wrong.
282
+ (async () => (await readSettings(home).catch(() => true)) !== null),
177
283
  setup: options.setup ??
178
- ((restart, server, setupOptions) => runSetup({ restart, server, ...setupOptions, write: options.write })),
179
- environment: options.environment ?? environmentOperation,
180
- capability: options.capability ?? capability,
284
+ ((restart, server, setupOptions) => runSetup({
285
+ restart,
286
+ server,
287
+ ...setupOptions,
288
+ interactive: mode.interactive,
289
+ write: options.write,
290
+ runtime,
291
+ })),
292
+ changeAsset: options.changeAsset ??
293
+ ((change, target) => changeAsset(change, target, runtime)),
294
+ changeAssets: options.changeAssets ??
295
+ ((change, target) => changeAssets(change, target, runtime)),
296
+ renameAsset: options.renameAsset ?? ((target) => renameAsset(target, runtime)),
297
+ listSets: options.listSets ?? (() => listSets(runtime)),
298
+ previewSet: options.previewSet ?? ((origin) => previewSet(origin, runtime)),
299
+ installSet: options.installSet ?? ((options) => installSet(options, runtime)),
300
+ installSetAssets: options.installSetAssets ??
301
+ ((options) => installSetAssets(options, runtime)),
302
+ changeSet: options.changeSet ??
303
+ ((change, options) => changeSet(change, options, runtime)),
304
+ switchSet: options.switchSet ?? ((options) => switchSet(options, runtime)),
305
+ setKnowledge: options.setKnowledge ?? ((enabled) => setKnowledge(enabled, runtime)),
306
+ listHarnesses: options.listHarnesses ?? (() => listHarnesses(runtime)),
307
+ changeHarnesses: options.changeHarnesses ??
308
+ ((change, targets) => changeHarnesses(change, targets, runtime)),
309
+ selectHarnesses: options.selectHarnesses ??
310
+ ((selected) => selectHarnesses(selected, runtime)),
311
+ doctor: options.doctor ?? (() => doctor(runtime)),
312
+ workspaceUrl: options.workspaceUrl ?? (() => workspaceUrl(runtime)),
313
+ repoStatus: options.repoStatus ?? (() => repoStatus(runtime)),
314
+ scanNative: options.scanNative ?? (() => scanNative(runtime)),
315
+ adoptNative: options.adoptNative ?? ((keys, keep) => adoptNative(keys, keep, runtime)),
316
+ listAdoptions: options.listAdoptions ?? (() => listAdoptions(home)),
317
+ undoAdoption: options.undoAdoption ?? ((target) => undoAdoption(target, runtime)),
318
+ listLocalAssets: options.listLocalAssets ?? (() => listLocalAssets(runtime)),
319
+ knowledgeProblems: options.knowledgeProblems ?? (() => knowledgeProblems(runtime)),
320
+ githubStatus: options.githubStatus ?? (() => githubStatus(runtime)),
321
+ githubInstallations: options.githubInstallations ?? (() => githubInstallations(runtime)),
322
+ githubList: options.githubList ?? (() => githubList(runtime)),
323
+ validateFolder: options.validateFolder ??
324
+ ((directory) => validateFolder(directory, runtime)),
325
+ migrate: options.migrate ?? ((options) => migrate(options, runtime)),
326
+ moveLocalAssets: options.moveLocalAssets ??
327
+ ((options) => moveLocalAssets(options, runtime)),
328
+ updateImported: options.updateImported ??
329
+ ((kind, name, options) => updateImported(kind, name, options, runtime)),
330
+ keepMcpValue: options.keepMcpValue ??
331
+ ((variable, value) => keepMcpValue(variable, value, runtime)),
332
+ forgetMcpValue: options.forgetMcpValue ??
333
+ ((variable) => forgetMcpValue(variable, runtime)),
334
+ listKeptValues: options.listKeptValues ?? (() => listKeptValues(runtime)),
335
+ showPackage: options.showPackage ??
336
+ ((kind, name, origin) => showPackage(kind, name, origin, runtime)),
337
+ showMcp: options.showMcp ?? ((name, origin) => showMcp(name, origin, runtime)),
338
+ createMcp: options.createMcp ?? ((input) => createMcp(input, runtime)),
339
+ updateMcp: options.updateMcp ?? ((input) => updateMcp(input, runtime)),
340
+ mcpVersions: options.mcpVersions ??
341
+ ((name, origin) => mcpVersions(name, origin, runtime)),
342
+ authenticateMcp: options.authenticateMcp ??
343
+ ((name, origin, harness) => authenticateMcp(name, origin, harness, runtime)),
344
+ testHook: options.testHook ??
345
+ ((name, origin, testOptions) => testHook(name, origin, testOptions, runtime)),
346
+ hookCompatibility: options.hookCompatibility ??
347
+ ((name, origin) => hookCompatibility(name, origin, runtime)),
348
+ adaptHook: options.adaptHook ??
349
+ ((name, origin, targets) => adaptHook(name, origin, targets, runtime)),
350
+ knowledgeGet: options.knowledgeGet ?? ((name) => knowledgeGet(name, runtime)),
351
+ developers: options.developers ?? ((search) => developers(search, runtime)),
352
+ developerAssets: options.developerAssets ??
353
+ ((selector, search) => developerAssets(selector, search, runtime)),
354
+ promote: options.promote ?? ((input) => promote(input, runtime)),
355
+ fork: options.fork ?? ((input) => fork(input, runtime)),
356
+ githubAuth: options.githubAuth ?? (() => githubAuth(runtime)),
357
+ githubInstall: options.githubInstall ?? (() => githubInstall(runtime)),
358
+ githubConnect: options.githubConnect ?? ((options) => githubConnect(options, runtime)),
359
+ githubImport: options.githubImport ?? ((options) => githubImport(options, runtime)),
360
+ githubImportCopy: options.githubImportCopy ??
361
+ ((options) => githubImportCopy(options, runtime)),
362
+ githubCreateRepository: options.githubCreateRepository ??
363
+ ((options) => githubCreateRepository(options, runtime)),
364
+ githubShow: options.githubShow ??
365
+ ((connectionId) => githubShow(connectionId, runtime)),
366
+ githubSync: options.githubSync ??
367
+ ((connectionId) => githubSync(connectionId, runtime)),
368
+ githubRemoteHead: options.githubRemoteHead ??
369
+ ((connectionId) => githubRemoteHead(connectionId, runtime)),
370
+ githubResolveMirror: options.githubResolveMirror ??
371
+ ((options) => githubResolveMirror(options, runtime)),
372
+ githubPullsList: options.githubPullsList ??
373
+ ((connectionId) => githubPullsList(connectionId, runtime)),
374
+ githubPullsShow: options.githubPullsShow ??
375
+ ((connectionId, number) => githubPullsShow(connectionId, number, runtime)),
376
+ githubPullsCreate: options.githubPullsCreate ??
377
+ ((options) => githubPullsCreate(options, runtime)),
378
+ githubPullsRevise: options.githubPullsRevise ??
379
+ ((options) => githubPullsRevise(options, runtime)),
380
+ githubPullsReview: options.githubPullsReview ??
381
+ ((options) => githubPullsReview(options, runtime)),
382
+ githubPullsComment: options.githubPullsComment ??
383
+ ((options) => githubPullsComment(options, runtime)),
384
+ githubPullsMerge: options.githubPullsMerge ??
385
+ ((options) => githubPullsMerge(options, runtime)),
386
+ knowledgeList: options.knowledgeList ?? ((always) => knowledgeList(always, runtime)),
181
387
  synchronize: options.synchronize ??
182
- ((path, syncOptions) => synchronize(path, undefined, undefined, syncOptions)),
183
- inventory: options.inventory ?? (() => inventory()),
184
- searchCatalog: options.searchCatalog ?? ((kind) => searchCatalog(kind)),
388
+ ((path, syncOptions) => synchronize(path, runtime, undefined, syncOptions)),
389
+ inventory: options.inventory ?? (() => inventory(runtime)),
390
+ searchCatalog: options.searchCatalog ?? ((kind) => searchCatalog(kind, runtime)),
185
391
  write,
186
392
  mode,
393
+ runtime,
187
394
  };
188
395
  const program = new Command()
189
396
  .name("barndog")
190
- .description(`${primary(styleText("bold", "BarnDog"))} keeps your team's Skills, MCP servers and Hooks in sync across Claude Code, Codex and Cursor.`)
397
+ .description(`${primary(styleText("bold", "BarnDog"))} keeps your team's Skills, MCP servers and Hooks in sync across ${toolNames(harnesses)}.`)
191
398
  .exitOverride()
192
399
  .configureOutput({
193
400
  writeOut: (text) => context.write(text.trimEnd()),
@@ -204,16 +411,21 @@ export function createProgram(options = {}) {
204
411
  styleOptionDescription: (text) => styleText("dim", text),
205
412
  ...(options.setupMode ? limitedHelp(options.setupMode) : {}),
206
413
  })
207
- .version(versionReport(), "-V, --version", "Show the version and build")
414
+ .version(versionReport(runtime.platform), "-V, --version", "Show the version and build")
208
415
  .option("--json", "Print machine-readable JSON")
209
416
  .option("--no-interactive", "Never prompt; fail with a hint instead")
210
417
  .addOption(new Option("--list-unavailable", "With --help, include commands this setup can't run").hideHelp(!options.setupMode))
211
418
  .showHelpAfterError(styleText("dim", "Add --help to any command to see its usage."))
212
- .addHelpText("after", `\nRun ${styleText("bold", "barndog <command> --help")} for details. Configuration: ${settingsPath()}`)
419
+ .addHelpText("after", `\nRun ${styleText("bold", "barndog <command> --help")} for details. Configuration: ${barndogPaths(home).settings}`)
213
420
  .addHelpText("afterAll", ({ command }) => options.setupMode ? unavailableHint(command, options.setupMode) : "")
214
- .action((_, command) => {
215
- if (command.args.length)
421
+ .action(async (_, command) => {
422
+ if (command.args.length) {
216
423
  program.error(`error: unknown command '${command.args[0]}'`);
424
+ }
425
+ // Setup needs a terminal; without one, help says to run `barndog init`.
426
+ if (mode.interactive && !(await context.isSetUp())) {
427
+ return context.setup(true);
428
+ }
217
429
  program.help();
218
430
  });
219
431
  program.hook("preAction", async (_, action) => {
@@ -223,49 +435,56 @@ export function createProgram(options = {}) {
223
435
  mode.interactive &&
224
436
  flags.interactive !== false &&
225
437
  !mode.json &&
226
- !process.env.CI;
227
- if (!options.synchronize && mode.interactive)
438
+ !runtime.env.CI;
439
+ if (!options.synchronize && mode.interactive) {
228
440
  clashPrompt.resolver = promptClash;
229
- else if (!mode.interactive)
441
+ }
442
+ else if (!mode.interactive) {
230
443
  clashPrompt.resolver = undefined;
444
+ }
231
445
  const path = [];
232
- for (let c = action; c?.parent; c = c.parent)
446
+ for (let c = action; c?.parent; c = c.parent) {
233
447
  path.unshift(c.name());
448
+ }
234
449
  await options.guard?.(path, action.opts());
235
450
  });
236
451
  registerAuth(program, context);
237
452
  registerInit(program, context);
238
453
  registerSync(program, context);
454
+ registerHarnesses(program, context);
455
+ registerAdopt(program, context);
239
456
  registerStatus(program, context);
240
457
  registerEnvironment(program, context);
241
458
  registerCapabilities(program, context);
242
459
  registerWorkspace(program, context);
243
- registerCollaboration(program, context);
460
+ registerWorkingCopy(program, context);
461
+ registerCollaboration(program, context, "skill");
244
462
  registerCollaboration(program, context, "hook");
245
463
  registerAdd(program, context);
246
464
  const order = groups.flatMap(([, names]) => names);
247
- for (const [heading, names] of groups)
248
- for (const name of names)
465
+ for (const [heading, names] of groups) {
466
+ for (const name of names) {
249
467
  program.commands.find((c) => c.name() === name)?.helpGroup(heading);
468
+ }
469
+ }
250
470
  // Commander lists groups in command order, so sort commands into section order.
471
+ // Commander types `commands` as readonly but offers no other way to reorder them.
472
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
251
473
  program.commands.sort((a, b) => order.indexOf(a.name()) - order.indexOf(b.name()));
252
474
  program.commandsGroup("Get started:").helpCommand(true);
253
475
  for (const name of ["skills", "mcp", "hooks"]) {
254
- const group = program.commands.find((c) => c.name() === name);
255
- for (const [heading, names] of assetGroups)
256
- for (const command of group.commands)
257
- if (names.includes(command.name()))
258
- command.helpGroup(
259
- // MCP create/show/versions publish or inspect definitions directly.
260
- name === "mcp" &&
261
- ["create", "show", "versions"].includes(command.name())
262
- ? "Publish directly:"
263
- : name !== "mcp" && command.name() === "update"
264
- ? "On this machine:"
265
- : heading);
476
+ const group = defined(program.commands.find((c) => c.name() === name), `Command group ${name} isn't registered`);
477
+ for (const [heading, names] of assetGroups) {
478
+ for (const command of group.commands) {
479
+ if (names.includes(command.name())) {
480
+ command.helpGroup(helpGroup(name, command.name(), heading));
481
+ }
482
+ }
483
+ }
266
484
  }
267
- if (options.guard)
485
+ if (options.guard) {
268
486
  guardRequiredOptions(program, options.guard);
487
+ }
269
488
  // Only the root accepts stray words, to report them as unknown commands.
270
489
  program.allowExcessArguments(true);
271
490
  return program;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,22 @@
1
+ /**
2
+ * A failure the person running the CLI can act on: bad input, missing setup,
3
+ * an unreachable server, a permission or a conflict. The message says what
4
+ * happened in a sentence; `hint` is the command (or short instruction) that
5
+ * fixes it, printed after `Fix:`. When the fix is a command that deletes or
6
+ * changes something, `hint` says in words what it does and `command` holds the
7
+ * command itself, printed after `Command:`. Anything else thrown as a plain `Error` is an
8
+ * internal invariant or a broken server contract, not something to fix here.
9
+ *
10
+ * It lives in `src/shared/` so the shared helpers can throw it too;
11
+ * `src/errors.ts` re-exports it.
12
+ */
13
+ export class CliError extends Error {
14
+ hint;
15
+ command;
16
+ constructor(message, hint, options) {
17
+ super(message, options);
18
+ this.name = "CliError";
19
+ this.hint = hint;
20
+ this.command = options?.command;
21
+ }
22
+ }
@@ -0,0 +1,32 @@
1
+ /** HTTP response status codes registered by IANA (RFC 9110). */
2
+ export const HTTP_STATUS = {
3
+ badRequest: 400,
4
+ unauthorized: 401,
5
+ forbidden: 403,
6
+ notFound: 404,
7
+ conflict: 409,
8
+ payloadTooLarge: 413,
9
+ internalServerError: 500,
10
+ };
11
+ /** POSIX permission bits: execute for any user, group/other access, and creation modes. */
12
+ export const POSIX_MODE = {
13
+ executableBits: 0o111,
14
+ groupAndOtherBits: 0o077,
15
+ privateDirectory: 0o700,
16
+ executableFile: 0o755,
17
+ regularFile: 0o644,
18
+ };
19
+ /** JavaScript timers and Date use milliseconds; Git and OAuth timestamps use seconds. */
20
+ export const MILLISECONDS_PER_SECOND = 1000;
21
+ /** Date timestamps expressed as one minute in milliseconds. */
22
+ export const MILLISECONDS_PER_MINUTE = 60000;
23
+ /** Time conversion for human-readable ages. */
24
+ export const MINUTES_PER_HOUR = 60;
25
+ /** Time conversion for human-readable ages. */
26
+ export const HOURS_PER_DAY = 24;
27
+ /** Git conventional abbreviated object ID length used in CLI labels. */
28
+ export const SHORT_COMMIT_LENGTH = 7;
29
+ /** BarnDog asset slug and local-name limit, shared with the API contract. */
30
+ export const MAX_ASSET_NAME_LENGTH = 64;
31
+ /** Hexadecimal encoding uses sixteen digits. */
32
+ export const HEX_RADIX = 16;
@@ -0,0 +1,107 @@
1
+ import { POSIX_MODE } from "./constants.js";
2
+ import { randomUUID } from "node:crypto";
3
+ import { lstat, mkdir, readFile, rename, rm, writeFile, } from "node:fs/promises";
4
+ import { dirname, relative, isAbsolute, sep } from "node:path";
5
+ import { errorCode } from "./values.js";
6
+ import { CliError } from "./cli-error.js";
7
+ /**
8
+ * Writes a temporary file beside `path` and renames it over `path`, so a reader
9
+ * sees the old file or the new one, never half of one. Creates missing parent
10
+ * folders.
11
+ */
12
+ export async function writeAtomic(path, data, { mode = 0o600, directoryMode = POSIX_MODE.privateDirectory, } = {}) {
13
+ await mkdir(dirname(path), { recursive: true, mode: directoryMode });
14
+ const temporary = `${path}.${randomUUID()}.tmp`;
15
+ try {
16
+ await writeFile(temporary, data, { mode, flag: "wx" });
17
+ await rename(temporary, path);
18
+ }
19
+ finally {
20
+ await rm(temporary, { force: true });
21
+ }
22
+ }
23
+ /**
24
+ * What `operation` returns, or null when the file or folder it touches doesn't
25
+ * exist (`ENOENT`). Any other failure is thrown.
26
+ */
27
+ export async function ifExists(operation) {
28
+ try {
29
+ return await operation;
30
+ }
31
+ catch (error) {
32
+ if (errorCode(error) === "ENOENT") {
33
+ return null;
34
+ }
35
+ throw error;
36
+ }
37
+ }
38
+ /** Why a file named on the command line can't be read, by Node error code. */
39
+ const inputProblems = {
40
+ ENOENT: "doesn't exist",
41
+ EISDIR: "is a folder, not a file",
42
+ EACCES: "can't be read: permission denied",
43
+ EPERM: "can't be read: permission denied",
44
+ };
45
+ /**
46
+ * A file the person running the CLI named, such as `--file` or `--input`. A
47
+ * missing or unreadable one is a mistake they can fix, so it says which file.
48
+ */
49
+ export async function inputFile(path) {
50
+ try {
51
+ return await readFile(path);
52
+ }
53
+ catch (error) {
54
+ const problem = inputProblems[errorCode(error) ?? ""];
55
+ if (problem) {
56
+ throw new CliError(`${path} ${problem}.`, undefined, { cause: error });
57
+ }
58
+ throw error;
59
+ }
60
+ }
61
+ /** `inputFile()` parsed as JSON; invalid JSON says which file. */
62
+ export async function inputJson(path) {
63
+ const text = (await inputFile(path)).toString("utf8");
64
+ try {
65
+ return JSON.parse(text);
66
+ }
67
+ catch (error) {
68
+ throw new CliError(`${path} isn't valid JSON.`, undefined, {
69
+ cause: error,
70
+ });
71
+ }
72
+ }
73
+ /** A file's text, or null when it doesn't exist. */
74
+ export function readIfExists(path) {
75
+ return ifExists(readFile(path, "utf8"));
76
+ }
77
+ /** A JSON file checked against `schema`, or null when it doesn't exist. */
78
+ export async function readJsonIfExists(path, schema) {
79
+ const text = await readIfExists(path);
80
+ return text === null ? null : schema.parse(JSON.parse(text));
81
+ }
82
+ /**
83
+ * A regular file's text, or null when it doesn't exist. Refuses symlinks and
84
+ * anything else that isn't a plain file, so a write can't be redirected.
85
+ */
86
+ export async function fileText(path) {
87
+ const info = await ifExists(lstat(path));
88
+ if (!info) {
89
+ return null;
90
+ }
91
+ if (!info.isFile() || info.isSymbolicLink()) {
92
+ throw new CliError(`${path} is a link or not a regular file, so BarnDog won't edit it.`);
93
+ }
94
+ return readIfExists(path);
95
+ }
96
+ /** Whether `child` is `parent` or somewhere below it; compares paths, not links. */
97
+ export function isInside(parent, child, paths = {
98
+ relative,
99
+ isAbsolute,
100
+ sep,
101
+ }) {
102
+ const path = paths.relative(parent, child);
103
+ return (!path ||
104
+ (path !== ".." &&
105
+ !path.startsWith(`..${paths.sep}`) &&
106
+ !paths.isAbsolute(path)));
107
+ }