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/ui/output.js CHANGED
@@ -1,23 +1,29 @@
1
+ import { pathsFor } from "../platform.js";
2
+ import { HTTP_STATUS } from "../shared/constants.js";
1
3
  import { LoginRequiredError } from "../features/auth/transport.js";
2
4
  import { styleText } from "node:util";
3
- import { homedir } from "node:os";
4
- import { basename, isAbsolute, relative, sep } from "node:path";
5
+ import { basename } from "node:path";
6
+ import { isInside } from "../shared/files.js";
5
7
  import { SetupRequiredError } from "../config/settings.js";
6
- import { adapters } from "../harnesses/registry.js";
8
+ import { adapters, isHarness } from "../harnesses/registry.js";
7
9
  import { primary, danger } from "./theme.js";
8
10
  import { bad, bold, dim, heading, hint, json, ok, table, warn, } from "./format.js";
9
11
  import { ApiError } from "@barndog-ai/api-contract";
10
12
  import { CliError, friendlyHint, friendlyMessage } from "../errors.js";
11
- export function displayPath(path) {
12
- const homeRelative = relative(homedir(), path);
13
- if (!homeRelative)
14
- return "~";
15
- if (homeRelative !== ".." &&
16
- !homeRelative.startsWith(`..${sep}`) &&
17
- !isAbsolute(homeRelative)) {
18
- return `~${sep}${homeRelative}`;
13
+ import { assetKinds } from "../features/asset-kinds/index.js";
14
+ import { DecisionRequiredError } from "./decision-error.js";
15
+ /**
16
+ * Abbreviates paths inside the current user's home with ~, preserving platform
17
+ * separators.
18
+ */
19
+ export function displayPath(path, runtime) {
20
+ const { home } = runtime;
21
+ const paths = pathsFor(runtime.platform);
22
+ if (!isInside(home, path, paths)) {
23
+ return path;
19
24
  }
20
- return path;
25
+ const homeRelative = paths.relative(home, path);
26
+ return homeRelative ? `~${paths.sep}${homeRelative}` : "~";
21
27
  }
22
28
  const marks = {
23
29
  installed: (text) => ok(`+ ${text}`),
@@ -31,7 +37,7 @@ const marks = {
31
37
  const internalKinds = new Set(["knowledge", "sync"]);
32
38
  function rows(events) {
33
39
  const byKey = new Map();
34
- const add = (action, kind, name, harness, note) => {
40
+ const add = ({ action, kind, name, harness, note, }) => {
35
41
  const key = `${action}\0${kind}\0${name}\0${note ?? ""}`;
36
42
  const row = byKey.get(key) ?? {
37
43
  action,
@@ -40,23 +46,58 @@ function rows(events) {
40
46
  harnesses: new Set(),
41
47
  note,
42
48
  };
43
- if (harness)
49
+ if (isHarness(harness)) {
44
50
  row.harnesses.add(adapters[harness].name);
51
+ }
45
52
  byKey.set(key, row);
46
53
  };
47
54
  for (const event of events) {
48
- if (event.type === "disabled" || event.type === "notice")
55
+ if (event.type === "disabled" ||
56
+ event.type === "notice" ||
57
+ event.type === "unset-variable") {
49
58
  continue;
50
- if (event.type === "invalid")
51
- add("skipped", event.kind, event.name, undefined, event.reason);
52
- else if (event.type === "clash")
53
- add("skipped", event.kind, event.skipped.name, undefined, `${event.skipped.origin} · name taken by ${event.installed.origin}`);
54
- else if (event.type === "unsupported")
55
- add("unsupported", event.kind, event.name, event.harness, event.reason);
56
- else if (event.type === "native")
57
- add(event.action, event.kind, event.name, event.harness);
58
- else
59
- add(event.type, "skill", basename(event.link.target), event.link.harness);
59
+ }
60
+ if (event.type === "invalid") {
61
+ add({
62
+ action: "skipped",
63
+ kind: event.kind,
64
+ name: event.name,
65
+ note: event.reason,
66
+ });
67
+ }
68
+ else if (event.type === "clash") {
69
+ add({
70
+ action: "skipped",
71
+ kind: event.kind,
72
+ name: event.skipped.name,
73
+ note: `${event.skipped.origin} · name taken by ${event.installed.origin}`,
74
+ });
75
+ }
76
+ else if (event.type === "unsupported") {
77
+ add({
78
+ action: "unsupported",
79
+ kind: event.kind,
80
+ name: event.name,
81
+ harness: event.harness,
82
+ note: event.reason,
83
+ });
84
+ }
85
+ else if (event.type === "native") {
86
+ add({
87
+ action: event.action,
88
+ kind: event.kind,
89
+ name: event.name,
90
+ harness: event.harness,
91
+ });
92
+ }
93
+ else {
94
+ add({
95
+ action: event.type,
96
+ kind: "skill",
97
+ name: basename(event.link.target),
98
+ harness: event.link.harness,
99
+ });
100
+ }
60
101
  }
61
102
  const order = [
62
103
  "installed",
@@ -70,6 +111,10 @@ function rows(events) {
70
111
  a.kind.localeCompare(b.kind) ||
71
112
  a.name.localeCompare(b.name));
72
113
  }
114
+ /**
115
+ * Returns terminal lines for synchronization events, with optional verbose
116
+ * detail or preview wording.
117
+ */
73
118
  export function renderSyncOutput(events, options = {}) {
74
119
  const all = rows(events);
75
120
  const assets = all.filter((row) => !internalKinds.has(row.kind));
@@ -101,55 +146,75 @@ export function renderSyncOutput(events, options = {}) {
101
146
  ])), "");
102
147
  }
103
148
  output.push(`${incomplete ? warn("!") : ok("✔")} ${options.preview ? "Preview" : "Sync complete"}${summary ? ` · ${summary}` : ""}`);
104
- if (options.preview)
149
+ if (options.preview) {
105
150
  output.push(changed
106
151
  ? hint("barndog sync", "Next") + dim(" to apply these changes")
107
152
  : quiet);
108
- else
153
+ }
154
+ else {
109
155
  output.push(changed
110
156
  ? dim("Restart your coding tools to pick up the changes.")
111
157
  : quiet);
112
- for (const event of events)
113
- if (event.type === "notice")
158
+ }
159
+ for (const event of events) {
160
+ if (event.type === "notice") {
114
161
  output.push("", `${warn("!")} ${event.message}`);
115
- else if (event.type === "clash")
116
- output.push("", `${warn("!")} ${event.kind === "skill" ? "Skill" : "MCP server"} ${bold(event.skipped.name)} from ${event.skipped.origin} was skipped: ${event.installed.origin} already installs one with that name.`, ` ${hint(`barndog ${event.kind === "skill" ? "skills" : "mcp"} rename ${event.skipped.name} --origin ${event.skipped.origin} --as ${event.skipped.rename}`, "Fix")}`);
162
+ }
163
+ else if (event.type === "clash") {
164
+ output.push("", `${warn("!")} ${assetKinds[event.kind].one} ${bold(event.skipped.name)} from ${event.skipped.origin} was skipped: ${event.installed.origin} already installs one with that name.`, ` ${hint(`barndog ${assetKinds[event.kind].command} rename ${event.skipped.name} --origin ${event.skipped.origin} --as ${event.skipped.rename}`, "Fix")}`);
165
+ }
166
+ }
117
167
  output.push("");
118
168
  return output;
119
169
  }
120
170
  function describeError(error) {
121
- if (error instanceof LoginRequiredError)
171
+ if (error instanceof LoginRequiredError) {
122
172
  return { message: "You're not signed in.", fix: "barndog login" };
123
- if (error instanceof SetupRequiredError)
173
+ }
174
+ if (error instanceof SetupRequiredError) {
124
175
  return {
125
176
  message: "BarnDog isn't set up on this machine yet.",
126
177
  fix: "barndog init",
127
178
  };
128
- if (error instanceof CliError)
129
- return { message: error.message, fix: error.hint };
130
- if (error instanceof ApiError && error.status === 500)
179
+ }
180
+ if (error instanceof CliError) {
181
+ return { message: error.message, fix: error.hint, command: error.command };
182
+ }
183
+ if (error instanceof ApiError &&
184
+ error.status === HTTP_STATUS.internalServerError) {
131
185
  return {
132
186
  message: `The BarnDog server had a problem and couldn't finish this (${error.status}). If you run it yourself, check that it and its database are up.`,
133
187
  };
134
- if (error instanceof TypeError && error.message === "fetch failed")
135
- return {
136
- message: "Can't reach the BarnDog server. Check your connection and that the server is running.",
137
- };
188
+ }
138
189
  return { message: friendlyMessage(error), fix: friendlyHint(error) };
139
190
  }
191
+ /**
192
+ * Formats an error and optional repair command using stderr color support; does
193
+ * not write to the stream.
194
+ */
140
195
  export function renderError(error) {
141
196
  const stream = process.stderr;
142
- const { message, fix } = describeError(error);
143
- return `${danger("✖", stream)} ${message}${fix ? `\n ${styleText("dim", "Fix:", { stream })} ${styleText("bold", fix, { stream })}` : ""}`;
197
+ const { message, fix, command } = describeError(error);
198
+ const line = (label, text, style) => `\n ${styleText("dim", label, { stream })} ${styleText(style, text, { stream })}`;
199
+ // A fix in words reads as plain text; a fix that is itself a command is bold.
200
+ return [
201
+ `${danger("✖", stream)} ${message}`,
202
+ fix ? line("Fix:", fix, command ? "reset" : "bold") : "",
203
+ command ? line("Command:", command, "bold") : "",
204
+ ].join("");
144
205
  }
145
206
  /** The same failure for `--json` callers, who parse rather than read. */
146
207
  export function renderJsonError(error) {
147
- const { message, fix } = describeError(error);
208
+ const { message, fix, command } = describeError(error);
148
209
  return json({
149
210
  error: {
150
211
  message,
151
212
  ...(fix ? { fix } : {}),
213
+ ...(command ? { command } : {}),
152
214
  ...(error instanceof ApiError ? { status: error.status } : {}),
215
+ ...(error instanceof DecisionRequiredError
216
+ ? { decisions: error.decisions }
217
+ : {}),
153
218
  },
154
219
  });
155
220
  }
@@ -0,0 +1,34 @@
1
+ import { adapters, hookHarnesses } from "../harnesses/registry.js";
2
+ import { SHORT_COMMIT_LENGTH } from "../shared/constants.js";
3
+ import { bold, clean, dim, fields } from "./format.js";
4
+ /** `skills show` and `hooks show`: what the asset is and where this machine has it. */
5
+ export function renderPackageDetails(details) {
6
+ const { installed } = details;
7
+ const events = hookHarnesses.flatMap((harness) => {
8
+ const names = details.events?.[harness];
9
+ return names ? [`${adapters[harness].name}: ${names.join(", ")}`] : [];
10
+ });
11
+ const output = fields([
12
+ ["Name", bold(clean(details.name))],
13
+ ["Origin", details.origin],
14
+ [
15
+ "Version",
16
+ typeof details.version === "number"
17
+ ? `v${details.version}`
18
+ : details.version.slice(0, SHORT_COMMIT_LENGTH),
19
+ ],
20
+ ["Description", clean(details.description)],
21
+ ["State", installed?.state ?? dim("not installed")],
22
+ [
23
+ "Installed in",
24
+ installed?.harnesses.map((harness) => adapters[harness].name).join(", "),
25
+ ],
26
+ ]);
27
+ if (details.kind === "hook") {
28
+ output.push("", dim("Events"), ...(events.length ? events : [dim("No coding tool runs it.")]).map((line) => ` ${line}`));
29
+ }
30
+ if (installed?.paths.length) {
31
+ output.push("", dim("Paths"), ...installed.paths.map((path) => ` ${path}`));
32
+ }
33
+ return output;
34
+ }
package/dist/ui/pick.js CHANGED
@@ -3,6 +3,17 @@ import { cursorHide } from "@inquirer/ansi";
3
3
  import { styleText } from "node:util";
4
4
  import { NothingToDoError } from "../errors.js";
5
5
  import { promptTheme, selected } from "./theme.js";
6
+ import { defined } from "../shared/lookup.js";
7
+ /** Cap names to leave room for hints in the picker. */
8
+ const MAX_CHOICE_NAME_WIDTH = 40;
9
+ /** Show ten choices before scrolling by default. */
10
+ const DEFAULT_PICKER_PAGE_SIZE = 10;
11
+ /** Assume one hundred columns when the output has no terminal dimensions. */
12
+ const FALLBACK_TERMINAL_COLUMNS = 100;
13
+ /** Reserve four columns for picker indentation and cursor spacing. */
14
+ const PICKER_ROW_CHROME_WIDTH = 4;
15
+ /** Only show a hint when at least four columns remain. */
16
+ const MIN_HINT_ROOM = 3;
6
17
  const matches = (choice, search) => {
7
18
  const text = `${choice.name} ${choice.hint ?? ""}`.toLowerCase();
8
19
  return search
@@ -19,23 +30,26 @@ const prompt = createPrompt((config, done) => {
19
30
  const [checked, setChecked] = useState(new Set(config.choices.flatMap((choice, index) => choice.checked ? [index] : [])));
20
31
  const [active, setActive] = useState(0);
21
32
  const [error, setError] = useState();
22
- const nameWidth = useMemo(() => Math.min(40, Math.max(0, ...config.choices.map((choice) => choice.name.length))), []);
33
+ const nameWidth = useMemo(() => Math.min(MAX_CHOICE_NAME_WIDTH, Math.max(0, ...config.choices.map((choice) => choice.name.length))), []);
23
34
  const visible = useMemo(() => config.choices
24
35
  .map((choice, index) => ({ choice, index }))
25
36
  .filter(({ choice }) => matches(choice, search)), [search]);
26
37
  useKeypress((key, rl) => {
27
- if (status !== "idle")
38
+ if (status !== "idle") {
28
39
  return;
40
+ }
29
41
  const restore = () => {
30
42
  rl.clearLine(0);
31
43
  rl.write(search);
32
44
  };
33
45
  if (isEnterKey(key)) {
46
+ const current = visible[active];
47
+ const single = current ? [current.choice] : [];
34
48
  const values = config.multiple
35
- ? [...checked].sort((a, b) => a - b).map((i) => config.choices[i])
36
- : visible[active]
37
- ? [visible[active].choice]
38
- : [];
49
+ ? [...checked]
50
+ .sort((a, b) => a - b)
51
+ .flatMap((i) => config.choices[i] ?? [])
52
+ : single;
39
53
  if (!values.length) {
40
54
  setError(config.multiple
41
55
  ? "Select at least one item with space."
@@ -48,8 +62,9 @@ const prompt = createPrompt((config, done) => {
48
62
  }
49
63
  else if (isUpKey(key) || isDownKey(key)) {
50
64
  restore();
51
- if (!visible.length)
65
+ if (!visible.length) {
52
66
  return;
67
+ }
53
68
  const offset = isUpKey(key) ? -1 : 1;
54
69
  // The list stops at both ends instead of wrapping around.
55
70
  setActive(Math.min(visible.length - 1, Math.max(0, active + offset)));
@@ -57,13 +72,16 @@ const prompt = createPrompt((config, done) => {
57
72
  else if (config.multiple && (isSpaceKey(key) || isTabKey(key))) {
58
73
  restore();
59
74
  const item = visible[active];
60
- if (!item)
75
+ if (!item) {
61
76
  return;
77
+ }
62
78
  const next = new Set(checked);
63
- if (next.has(item.index))
79
+ if (next.has(item.index)) {
64
80
  next.delete(item.index);
65
- else
81
+ }
82
+ else {
66
83
  next.add(item.index);
84
+ }
67
85
  setChecked(next);
68
86
  setError(undefined);
69
87
  }
@@ -76,7 +94,7 @@ const prompt = createPrompt((config, done) => {
76
94
  const message = theme.style.message(config.message, status);
77
95
  if (status === "done") {
78
96
  const names = config.multiple
79
- ? [...checked].map((i) => config.choices[i].name).join(", ")
97
+ ? [...checked].map((i) => config.choices[i]?.name).join(", ")
80
98
  : (visible[active]?.choice.name ?? "");
81
99
  return `${prefix} ${message} ${promptTheme.style.answer(names)}`;
82
100
  }
@@ -84,28 +102,25 @@ const prompt = createPrompt((config, done) => {
84
102
  ? usePagination({
85
103
  items: visible,
86
104
  active,
87
- pageSize: config.pageSize ?? 10,
105
+ pageSize: config.pageSize ?? DEFAULT_PICKER_PAGE_SIZE,
88
106
  loop: false,
89
107
  renderItem({ item, isActive }) {
90
108
  const cursor = isActive ? promptTheme.icon.cursor : " ";
91
- const box = config.multiple
92
- ? checked.has(item.index)
93
- ? selected("◉ ")
94
- : "◯ "
95
- : "";
109
+ const mark = checked.has(item.index) ? selected("◉ ") : "◯ ";
110
+ const box = config.multiple ? mark : "";
96
111
  const padded = item.choice.name.padEnd(nameWidth);
97
112
  const name = isActive
98
113
  ? promptTheme.style.highlight(padded)
99
114
  : padded;
100
115
  // Leave a column spare so the terminal never wraps a row.
101
- const room = (process.stdout.columns || 100) -
116
+ const room = (process.stdout.columns || FALLBACK_TERMINAL_COLUMNS) -
102
117
  1 -
103
- 4 -
118
+ PICKER_ROW_CHROME_WIDTH -
104
119
  box.length -
105
120
  nameWidth -
106
121
  2;
107
122
  const text = item.choice.hint ?? "";
108
- const hint = text && room > 3
123
+ const hint = text && room > MIN_HINT_ROOM
109
124
  ? ` ${styleText("dim", text.length > room ? `${text.slice(0, room - 1)}…` : text)}`
110
125
  : "";
111
126
  return `${cursor} ${box}${name}${hint}`;
@@ -133,21 +148,18 @@ export function interactiveTerminal() {
133
148
  }
134
149
  /** A searchable list: type to filter, space to select, enter to confirm. */
135
150
  export async function pickMany(message, choices, options = {}) {
136
- if (!choices.length)
151
+ if (!choices.length) {
137
152
  throw new NothingToDoError(options.empty ?? "Nothing to choose from.");
138
- return (await prompt({
139
- message,
140
- choices,
141
- multiple: true,
142
- }));
153
+ }
154
+ return prompt({ message, choices, multiple: true });
143
155
  }
156
+ /**
157
+ * Prompts for exactly one typed choice; an empty list throws NothingToDoError.
158
+ */
144
159
  export async function pickOne(message, choices, options = {}) {
145
- if (!choices.length)
160
+ if (!choices.length) {
146
161
  throw new NothingToDoError(options.empty ?? "Nothing to choose from.");
147
- const [value] = (await prompt({
148
- message,
149
- choices,
150
- multiple: false,
151
- }));
152
- return value;
162
+ }
163
+ const [value] = await prompt({ message, choices, multiple: false });
164
+ return defined(value, "Nothing was chosen");
153
165
  }
@@ -3,11 +3,21 @@ import select from "@inquirer/select";
3
3
  import { CliError } from "../errors.js";
4
4
  import { runSelection } from "./selection.js";
5
5
  import { checkboxTheme, promptTheme } from "./theme.js";
6
+ import { interactiveTerminal } from "./pick.js";
7
+ /**
8
+ * Installs a scope using an explicit mode or interactive asset selection, then
9
+ * renders the selection result.
10
+ */
6
11
  export async function runSetInstall(context, options, prompts = {}) {
7
- if (options.mode)
8
- return runSelection(context, "sets-install", options);
9
- if (!(prompts.interactive ?? Boolean(process.stdin.isTTY && process.stdout.isTTY)))
12
+ const install = (mode) => runSelection(context, (resolution) => context.installSet({ ...options, mode, resolution }));
13
+ if (options.mode) {
14
+ return install(options.mode);
15
+ }
16
+ if (!(prompts.interactive ??
17
+ context.mode?.interactive ??
18
+ interactiveTerminal())) {
10
19
  throw new CliError("Choose which assets to include with --mode, or run this in a terminal to pick.", `barndog sets install ${options.origin} --mode recommended`);
20
+ }
11
21
  const mode = await (prompts.mode ??
12
22
  (() => select({
13
23
  loop: false,
@@ -20,9 +30,10 @@ export async function runSetInstall(context, options, prompts = {}) {
20
30
  default: "recommended",
21
31
  theme: promptTheme,
22
32
  })))();
23
- if (mode !== "custom")
24
- return runSelection(context, "sets-install", { ...options, mode });
25
- const preview = (await context.environment("sets-preview", options));
33
+ if (mode !== "custom") {
34
+ return install(mode);
35
+ }
36
+ const preview = await context.previewSet(options.origin);
26
37
  if (!preview.assets.length) {
27
38
  context.write("No published assets in this source yet.");
28
39
  return;
@@ -43,5 +54,5 @@ export async function runSetInstall(context, options, prompts = {}) {
43
54
  context.write("No assets selected. Nothing changed.");
44
55
  return;
45
56
  }
46
- await runSelection(context, "sets-install-custom", { ...options, assetIds });
57
+ await runSelection(context, () => context.installSetAssets({ origin: options.origin, assetIds }));
47
58
  }
@@ -0,0 +1,19 @@
1
+ /** Reads an MCP variable's value without showing it or putting it in shell history. */
2
+ import input from "@inquirer/input";
3
+ import { promptTheme } from "./theme.js";
4
+ /** Asks in the terminal, echoing one `*` per character. */
5
+ export function askSecret(variable) {
6
+ return input({
7
+ message: `Value for ${variable}`,
8
+ transformer: (value) => "*".repeat(value.length),
9
+ theme: promptTheme,
10
+ });
11
+ }
12
+ /** Everything piped in, without the final line break a file or `echo` adds. */
13
+ export async function readStdin(stream = process.stdin) {
14
+ let text = "";
15
+ for await (const chunk of stream) {
16
+ text += chunk.toString();
17
+ }
18
+ return text.replace(/\r?\n$/, "");
19
+ }
@@ -1,23 +1,29 @@
1
1
  import select from "@inquirer/select";
2
2
  import confirm from "@inquirer/confirm";
3
- import { CliError } from "../errors.js";
3
+ import { DecisionRequiredError } from "./decision-error.js";
4
4
  import { json } from "./format.js";
5
5
  import { renderSyncOutput } from "./output.js";
6
6
  import { promptTheme } from "./theme.js";
7
- export async function runSelection(context, action, options) {
7
+ import { interactiveTerminal } from "./pick.js";
8
+ /** A change that would undo exclusions or disabled assets runs again with the answer. */
9
+ export async function runSelection(context, change) {
10
+ let resolution;
8
11
  while (true) {
9
- const result = (await context.environment(action, options));
12
+ const result = await change(resolution);
10
13
  if (result.status !== "decision-required") {
11
14
  if (context.mode?.json) {
12
15
  context.write(json(result));
13
16
  return;
14
17
  }
15
- for (const line of renderSyncOutput(result.events ?? []))
18
+ for (const line of renderSyncOutput(result.events)) {
16
19
  context.write(line);
20
+ }
17
21
  return;
18
22
  }
19
- if (context.mode?.json || !process.stdin.isTTY || !process.stdout.isTTY)
20
- throw new CliError("Existing exclusions or disable overrides need a decision.", "add --overrides preserve, --overrides clear or --decisions <file>");
23
+ if (context.mode?.json ||
24
+ !(context.mode?.interactive ?? interactiveTerminal())) {
25
+ throw new DecisionRequiredError(result.conflicts);
26
+ }
21
27
  const type = await select({
22
28
  loop: false,
23
29
  message: "Existing exclusions or disabled assets",
@@ -28,10 +34,9 @@ export async function runSelection(context, action, options) {
28
34
  { value: "per-asset", name: "Choose for each asset" },
29
35
  ],
30
36
  });
31
- let resolution;
32
37
  if (type === "per-asset") {
33
38
  const decisions = [];
34
- for (const conflict of result.conflicts ?? [])
39
+ for (const conflict of result.conflicts) {
35
40
  decisions.push({
36
41
  assetId: conflict.asset.id,
37
42
  choice: (await confirm({
@@ -42,10 +47,11 @@ export async function runSelection(context, action, options) {
42
47
  ? "clear"
43
48
  : "preserve",
44
49
  });
50
+ }
45
51
  resolution = { type: "per-asset", decisions };
46
52
  }
47
- else
48
- resolution = { type: type };
49
- options = { ...options, resolution };
53
+ else {
54
+ resolution = { type };
55
+ }
50
56
  }
51
57
  }
package/dist/ui/theme.js CHANGED
@@ -1,28 +1,47 @@
1
1
  import { styleText } from "node:util";
2
- export const PRIMARY_COLOR = "#C54836";
3
- export const SELECTION_COLOR = "green";
2
+ /** Node terminal color depth for 24-bit RGB. */
3
+ const TRUE_COLOR_DEPTH = 24;
4
+ /** Node terminal color depth for the 256-color palette. */
5
+ const PALETTE_COLOR_DEPTH = 8;
6
+ /** Node terminal color depth for the sixteen ANSI colors. */
7
+ const BASIC_COLOR_DEPTH = 4;
8
+ /** CSS #RRGGBB green channel starts at character three. */
9
+ const GREEN_HEX_OFFSET = 3;
10
+ /** CSS #RRGGBB blue channel starts at character five. */
11
+ const BLUE_HEX_OFFSET = 5;
12
+ /**
13
+ * BarnDog brand accent, applied through `primary()` to headings, highlighted
14
+ * output and prompt accents.
15
+ */
16
+ const PRIMARY_COLOR = "#C54836";
17
+ const SELECTION_COLOR = "green";
18
+ /**
19
+ * Applies the selection color using Node's color policy for the supplied stream
20
+ * (stdout by default).
21
+ */
4
22
  export function selected(text, stream = process.stdout) {
5
23
  return styleText(SELECTION_COLOR, text, { stream });
6
24
  }
25
+ /** The SGR foreground code for the brand color at a color depth: exact, nearest of 256, or red. */
26
+ function primaryColorCode(depth, rgb) {
27
+ if (depth >= TRUE_COLOR_DEPTH) {
28
+ return `38;2;${rgb.join(";")}`;
29
+ }
30
+ return depth >= PALETTE_COLOR_DEPTH ? "38;5;131" : "31";
31
+ }
7
32
  /** Exact brand color on true-color terminals, with palette and plain-text fallbacks. */
8
33
  export function primary(text, stream = process.stdout) {
9
34
  // Let Node handle NO_COLOR, NODE_DISABLE_COLORS, FORCE_COLOR, and terminal detection.
10
- if (styleText("bold", "x", { stream }) === "x")
35
+ if (styleText("bold", "x", { stream }) === "x") {
11
36
  return text;
12
- const forcedDepth = process.env.FORCE_COLOR === "3"
13
- ? 24
14
- : process.env.FORCE_COLOR === "2"
15
- ? 8
16
- : 4;
17
- const depth = stream.getColorDepth?.() ?? forcedDepth;
18
- const rgb = PRIMARY_COLOR.slice(1)
19
- .match(/../g)
20
- .map((value) => parseInt(value, 16));
21
- const color = depth >= 24 ? `38;2;${rgb.join(";")}` : depth >= 8 ? "38;5;131" : "31";
37
+ }
38
+ const depth = stream.getColorDepth?.() ?? BASIC_COLOR_DEPTH;
39
+ const rgb = [1, GREEN_HEX_OFFSET, BLUE_HEX_OFFSET].map((start) => parseInt(PRIMARY_COLOR.slice(start, start + 2), 16));
40
+ const color = primaryColorCode(depth, rgb);
22
41
  const start = `\u001b[${color}m`;
23
42
  return `${start}${text.replaceAll("\u001b[39m", start)}\u001b[39m`;
24
43
  }
25
- export const DANGER_COLOR = "red";
44
+ const DANGER_COLOR = "red";
26
45
  export function danger(text, stream = process.stdout) {
27
46
  return styleText(DANGER_COLOR, text, { stream });
28
47
  }
@@ -31,6 +50,10 @@ export const promptTheme = {
31
50
  icon: { cursor: primary("❯") },
32
51
  style: { answer: primary, highlight: primary, description: primary },
33
52
  };
53
+ /**
54
+ * `promptTheme` with BarnDog's checked and unchecked circles, for multi-select
55
+ * prompts.
56
+ */
34
57
  export const checkboxTheme = {
35
58
  ...promptTheme,
36
59
  icon: { ...promptTheme.icon, checked: selected(" ◉"), unchecked: " ◯" },
package/dist/version.js CHANGED
@@ -1,12 +1,15 @@
1
1
  import { readFileSync } from "node:fs";
2
+ import { z } from "zod";
2
3
  import { defaultServer } from "./config/build.js";
3
4
  /** The package version, read from package.json beside dist/ so it can't drift. */
4
- export const version = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")).version;
5
+ const version = z
6
+ .object({ version: z.string() })
7
+ .parse(JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"))).version;
5
8
  /** What `barndog --version` prints: enough to tell builds apart in a support report. */
6
- export function versionReport() {
9
+ export function versionReport(platform) {
7
10
  return [
8
11
  `barndog ${version}`,
9
- `Node.js ${process.version} on ${process.platform} ${process.arch}`,
12
+ `Node.js ${process.version} on ${platform} ${process.arch}`,
10
13
  `Default server ${defaultServer}`,
11
14
  ].join("\n");
12
15
  }