barndog 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (173) hide show
  1. package/README.md +8 -7
  2. package/dist/cli.js +11 -7
  3. package/dist/commands/add.js +33 -21
  4. package/dist/commands/arguments.js +12 -0
  5. package/dist/commands/asset-install.js +160 -0
  6. package/dist/commands/asset-list.js +121 -0
  7. package/dist/commands/asset-share.js +94 -0
  8. package/dist/commands/auth.js +4 -0
  9. package/dist/commands/availability.js +54 -26
  10. package/dist/commands/capabilities.js +71 -415
  11. package/dist/commands/collaboration.js +194 -110
  12. package/dist/commands/environment.js +18 -411
  13. package/dist/commands/github.js +200 -0
  14. package/dist/commands/helpers.js +39 -0
  15. package/dist/commands/hooks.js +87 -0
  16. package/dist/commands/init.js +4 -2
  17. package/dist/commands/knowledge.js +73 -0
  18. package/dist/commands/mcp.js +62 -0
  19. package/dist/commands/origin.js +21 -23
  20. package/dist/commands/people.js +51 -0
  21. package/dist/commands/sets.js +141 -0
  22. package/dist/commands/status.js +34 -24
  23. package/dist/commands/sync.js +11 -4
  24. package/dist/commands/workspace.js +33 -19
  25. package/dist/config/environment.js +13 -27
  26. package/dist/config/paths.js +62 -0
  27. package/dist/config/selection.js +30 -0
  28. package/dist/config/settings.js +97 -108
  29. package/dist/config/state.js +57 -57
  30. package/dist/entry/knowledge-startup.js +32 -0
  31. package/dist/entry/mcp-launch.js +71 -0
  32. package/dist/entry/opencode-plugin.js +62 -0
  33. package/dist/{features/git-workspace/startup.js → entry/workspace-startup.js} +7 -2
  34. package/dist/errors.js +198 -55
  35. package/dist/features/asset-kinds/index.js +120 -0
  36. package/dist/features/asset-selection/index.js +51 -19
  37. package/dist/features/auth/credentials.js +80 -47
  38. package/dist/features/auth/session.js +80 -45
  39. package/dist/features/auth/transport.js +66 -15
  40. package/dist/features/catalog/index.js +32 -61
  41. package/dist/features/collaboration/api.js +160 -0
  42. package/dist/features/collaboration/index.js +321 -233
  43. package/dist/features/collaboration/remote.js +35 -115
  44. package/dist/features/collaboration/results.js +2 -0
  45. package/dist/features/collaboration/workspace-git.js +233 -149
  46. package/dist/features/collaboration/workspace-github.js +117 -54
  47. package/dist/features/collaboration/workspace-store.js +140 -100
  48. package/dist/features/collaboration/workspace.js +257 -172
  49. package/dist/features/discovery/index.js +68 -57
  50. package/dist/features/doctor/index.js +32 -24
  51. package/dist/features/environment/auto-sync.js +28 -27
  52. package/dist/features/environment/names.js +67 -47
  53. package/dist/features/environment/operations.js +321 -228
  54. package/dist/features/environment/own-entries.js +89 -0
  55. package/dist/features/environment/settle-names.js +91 -0
  56. package/dist/features/environment/stage.js +178 -0
  57. package/dist/features/environment/sync.js +113 -484
  58. package/dist/features/environment/transaction.js +179 -147
  59. package/dist/features/environment/writes.js +196 -0
  60. package/dist/features/github/account.js +25 -0
  61. package/dist/features/github/connections.js +119 -0
  62. package/dist/features/github/pulls.js +118 -0
  63. package/dist/features/hooks/adapt.js +32 -25
  64. package/dist/features/hooks/catalog.js +28 -0
  65. package/dist/features/hooks/compatibility.js +49 -0
  66. package/dist/features/hooks/divergence.js +9 -6
  67. package/dist/features/hooks/test.js +74 -49
  68. package/dist/features/hooks/types.js +1 -0
  69. package/dist/features/imports/discover.js +134 -61
  70. package/dist/features/imports/folder.js +48 -14
  71. package/dist/features/imports/local.js +113 -134
  72. package/dist/features/imports/remote.js +44 -25
  73. package/dist/features/inspection/index.js +17 -17
  74. package/dist/features/inventory/index.js +99 -110
  75. package/dist/features/knowledge/index.js +69 -49
  76. package/dist/features/mcps/catalog.js +31 -0
  77. package/dist/features/mcps/import.js +316 -0
  78. package/dist/features/mcps/index.js +98 -49
  79. package/dist/features/migration/migrate.js +263 -0
  80. package/dist/features/{git-workspace → migration}/move.js +165 -109
  81. package/dist/features/migration/promote.js +24 -0
  82. package/dist/features/native/adapters.js +53 -94
  83. package/dist/features/native/configuration.js +128 -82
  84. package/dist/features/native/hook-shell.js +55 -0
  85. package/dist/features/native/plugin-module.js +56 -0
  86. package/dist/features/onboarding/environment.js +67 -34
  87. package/dist/features/onboarding/setup.js +43 -40
  88. package/dist/features/repositories/context.js +30 -13
  89. package/dist/features/server/catalog.js +58 -0
  90. package/dist/features/server/client.js +13 -0
  91. package/dist/features/server/connection.js +37 -0
  92. package/dist/features/server/origin.js +74 -0
  93. package/dist/features/server/pages.js +24 -0
  94. package/dist/features/skills/catalog.js +42 -0
  95. package/dist/features/workspace/assets.js +57 -0
  96. package/dist/features/workspace/cloud-source.js +34 -0
  97. package/dist/features/workspace/directory.js +38 -0
  98. package/dist/features/{git-workspace → workspace}/format.js +114 -51
  99. package/dist/features/workspace/git.js +214 -0
  100. package/dist/features/workspace/installed.js +92 -0
  101. package/dist/features/{git-workspace → workspace}/overlay.js +43 -23
  102. package/dist/features/workspace/packages.js +160 -0
  103. package/dist/features/{git-workspace → workspace}/publish.js +120 -64
  104. package/dist/features/workspace/repo-source.js +192 -0
  105. package/dist/features/{git-workspace → workspace}/setup.js +60 -42
  106. package/dist/features/{git-workspace → workspace}/snapshot.js +53 -18
  107. package/dist/features/workspace/source.js +1 -0
  108. package/dist/features/workspace/tree.js +52 -0
  109. package/dist/features/workspace/workspace-source.js +27 -0
  110. package/dist/harnesses/claude.js +23 -1
  111. package/dist/harnesses/codex.js +57 -1
  112. package/dist/harnesses/cursor.js +22 -1
  113. package/dist/harnesses/detect.js +6 -50
  114. package/dist/harnesses/formats.js +45 -0
  115. package/dist/harnesses/opencode.js +111 -0
  116. package/dist/harnesses/registry.js +35 -2
  117. package/dist/platform.js +375 -0
  118. package/dist/program.js +225 -54
  119. package/dist/runtime.js +1 -0
  120. package/dist/shared/cli-error.js +22 -0
  121. package/dist/shared/constants.js +32 -0
  122. package/dist/shared/files.js +72 -0
  123. package/dist/shared/lock.js +49 -0
  124. package/dist/shared/lookup.js +11 -0
  125. package/dist/shared/patterns.js +94 -0
  126. package/dist/shared/shell.js +22 -0
  127. package/dist/shared/values.js +26 -0
  128. package/dist/ui/add-asset.js +41 -400
  129. package/dist/ui/add-hook.js +213 -0
  130. package/dist/ui/add-mcp.js +107 -0
  131. package/dist/ui/add-prompts.js +47 -0
  132. package/dist/ui/add-skills.js +115 -0
  133. package/dist/ui/asset-list.js +31 -13
  134. package/dist/ui/assets.js +33 -44
  135. package/dist/ui/auth.js +43 -33
  136. package/dist/ui/clash.js +11 -6
  137. package/dist/ui/collaboration.js +116 -44
  138. package/dist/ui/connection.js +10 -4
  139. package/dist/ui/decision-error.js +24 -0
  140. package/dist/ui/environment-onboarding.js +35 -13
  141. package/dist/ui/format.js +66 -18
  142. package/dist/ui/hook-compatibility.js +14 -6
  143. package/dist/ui/mcp.js +28 -3
  144. package/dist/ui/move.js +10 -5
  145. package/dist/ui/onboarding.js +113 -73
  146. package/dist/ui/options.js +9 -0
  147. package/dist/ui/output.js +106 -43
  148. package/dist/ui/pick.js +45 -33
  149. package/dist/ui/scope-install.js +15 -7
  150. package/dist/ui/selection.js +15 -11
  151. package/dist/ui/theme.js +37 -14
  152. package/dist/version.js +6 -3
  153. package/package.json +13 -3
  154. package/dist/features/capabilities/index.js +0 -106
  155. package/dist/features/collaboration/domain.js +0 -90
  156. package/dist/features/environment/cloud-source.js +0 -27
  157. package/dist/features/environment/installed.js +0 -124
  158. package/dist/features/environment/packages.js +0 -120
  159. package/dist/features/environment/remote.js +0 -71
  160. package/dist/features/environment/workspace-source.js +0 -19
  161. package/dist/features/git-hosts/index.js +0 -148
  162. package/dist/features/git-workspace/assets.js +0 -71
  163. package/dist/features/git-workspace/git.js +0 -135
  164. package/dist/features/git-workspace/migrate.js +0 -188
  165. package/dist/features/git-workspace/source.js +0 -159
  166. package/dist/features/imports/mcp.js +0 -219
  167. package/dist/features/knowledge/startup.js +0 -25
  168. package/dist/features/native/mcp-launch.js +0 -57
  169. package/dist/features/skills/install.js +0 -25
  170. package/dist/features/skills/remote.js +0 -177
  171. package/dist/features/skills/sync.js +0 -121
  172. package/dist/features/skills/validation.js +0 -34
  173. /package/dist/features/environment/{source.js → events.js} +0 -0
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,56 @@ 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" || event.type === "notice") {
49
56
  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);
57
+ }
58
+ if (event.type === "invalid") {
59
+ add({
60
+ action: "skipped",
61
+ kind: event.kind,
62
+ name: event.name,
63
+ note: event.reason,
64
+ });
65
+ }
66
+ else if (event.type === "clash") {
67
+ add({
68
+ action: "skipped",
69
+ kind: event.kind,
70
+ name: event.skipped.name,
71
+ note: `${event.skipped.origin} · name taken by ${event.installed.origin}`,
72
+ });
73
+ }
74
+ else if (event.type === "unsupported") {
75
+ add({
76
+ action: "unsupported",
77
+ kind: event.kind,
78
+ name: event.name,
79
+ harness: event.harness,
80
+ note: event.reason,
81
+ });
82
+ }
83
+ else if (event.type === "native") {
84
+ add({
85
+ action: event.action,
86
+ kind: event.kind,
87
+ name: event.name,
88
+ harness: event.harness,
89
+ });
90
+ }
91
+ else {
92
+ add({
93
+ action: event.type,
94
+ kind: "skill",
95
+ name: basename(event.link.target),
96
+ harness: event.link.harness,
97
+ });
98
+ }
60
99
  }
61
100
  const order = [
62
101
  "installed",
@@ -70,6 +109,10 @@ function rows(events) {
70
109
  a.kind.localeCompare(b.kind) ||
71
110
  a.name.localeCompare(b.name));
72
111
  }
112
+ /**
113
+ * Returns terminal lines for synchronization events, with optional verbose
114
+ * detail or preview wording.
115
+ */
73
116
  export function renderSyncOutput(events, options = {}) {
74
117
  const all = rows(events);
75
118
  const assets = all.filter((row) => !internalKinds.has(row.kind));
@@ -101,55 +144,75 @@ export function renderSyncOutput(events, options = {}) {
101
144
  ])), "");
102
145
  }
103
146
  output.push(`${incomplete ? warn("!") : ok("✔")} ${options.preview ? "Preview" : "Sync complete"}${summary ? ` · ${summary}` : ""}`);
104
- if (options.preview)
147
+ if (options.preview) {
105
148
  output.push(changed
106
149
  ? hint("barndog sync", "Next") + dim(" to apply these changes")
107
150
  : quiet);
108
- else
151
+ }
152
+ else {
109
153
  output.push(changed
110
154
  ? dim("Restart your coding tools to pick up the changes.")
111
155
  : quiet);
112
- for (const event of events)
113
- if (event.type === "notice")
156
+ }
157
+ for (const event of events) {
158
+ if (event.type === "notice") {
114
159
  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")}`);
160
+ }
161
+ else if (event.type === "clash") {
162
+ 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")}`);
163
+ }
164
+ }
117
165
  output.push("");
118
166
  return output;
119
167
  }
120
168
  function describeError(error) {
121
- if (error instanceof LoginRequiredError)
169
+ if (error instanceof LoginRequiredError) {
122
170
  return { message: "You're not signed in.", fix: "barndog login" };
123
- if (error instanceof SetupRequiredError)
171
+ }
172
+ if (error instanceof SetupRequiredError) {
124
173
  return {
125
174
  message: "BarnDog isn't set up on this machine yet.",
126
175
  fix: "barndog init",
127
176
  };
128
- if (error instanceof CliError)
129
- return { message: error.message, fix: error.hint };
130
- if (error instanceof ApiError && error.status === 500)
177
+ }
178
+ if (error instanceof CliError) {
179
+ return { message: error.message, fix: error.hint, command: error.command };
180
+ }
181
+ if (error instanceof ApiError &&
182
+ error.status === HTTP_STATUS.internalServerError) {
131
183
  return {
132
184
  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
185
  };
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
- };
186
+ }
138
187
  return { message: friendlyMessage(error), fix: friendlyHint(error) };
139
188
  }
189
+ /**
190
+ * Formats an error and optional repair command using stderr color support; does
191
+ * not write to the stream.
192
+ */
140
193
  export function renderError(error) {
141
194
  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 })}` : ""}`;
195
+ const { message, fix, command } = describeError(error);
196
+ const line = (label, text, style) => `\n ${styleText("dim", label, { stream })} ${styleText(style, text, { stream })}`;
197
+ // A fix in words reads as plain text; a fix that is itself a command is bold.
198
+ return [
199
+ `${danger("✖", stream)} ${message}`,
200
+ fix ? line("Fix:", fix, command ? "reset" : "bold") : "",
201
+ command ? line("Command:", command, "bold") : "",
202
+ ].join("");
144
203
  }
145
204
  /** The same failure for `--json` callers, who parse rather than read. */
146
205
  export function renderJsonError(error) {
147
- const { message, fix } = describeError(error);
206
+ const { message, fix, command } = describeError(error);
148
207
  return json({
149
208
  error: {
150
209
  message,
151
210
  ...(fix ? { fix } : {}),
211
+ ...(command ? { command } : {}),
152
212
  ...(error instanceof ApiError ? { status: error.status } : {}),
213
+ ...(error instanceof DecisionRequiredError
214
+ ? { decisions: error.decisions }
215
+ : {}),
153
216
  },
154
217
  });
155
218
  }
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,18 @@ 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
+ /**
7
+ * Installs a scope using an explicit mode or interactive asset selection, then
8
+ * renders the selection result.
9
+ */
6
10
  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)))
11
+ const install = (mode) => runSelection(context, (resolution) => context.installSet({ ...options, mode, resolution }));
12
+ if (options.mode) {
13
+ return install(options.mode);
14
+ }
15
+ if (!(prompts.interactive ?? Boolean(process.stdin.isTTY && process.stdout.isTTY))) {
10
16
  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`);
17
+ }
11
18
  const mode = await (prompts.mode ??
12
19
  (() => select({
13
20
  loop: false,
@@ -20,9 +27,10 @@ export async function runSetInstall(context, options, prompts = {}) {
20
27
  default: "recommended",
21
28
  theme: promptTheme,
22
29
  })))();
23
- if (mode !== "custom")
24
- return runSelection(context, "sets-install", { ...options, mode });
25
- const preview = (await context.environment("sets-preview", options));
30
+ if (mode !== "custom") {
31
+ return install(mode);
32
+ }
33
+ const preview = await context.previewSet(options.origin);
26
34
  if (!preview.assets.length) {
27
35
  context.write("No published assets in this source yet.");
28
36
  return;
@@ -43,5 +51,5 @@ export async function runSetInstall(context, options, prompts = {}) {
43
51
  context.write("No assets selected. Nothing changed.");
44
52
  return;
45
53
  }
46
- await runSelection(context, "sets-install-custom", { ...options, assetIds });
54
+ await runSelection(context, () => context.installSetAssets({ origin: options.origin, assetIds }));
47
55
  }
@@ -1,23 +1,27 @@
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
+ /** A change that would undo exclusions or disabled assets runs again with the answer. */
8
+ export async function runSelection(context, change) {
9
+ let resolution;
8
10
  while (true) {
9
- const result = (await context.environment(action, options));
11
+ const result = await change(resolution);
10
12
  if (result.status !== "decision-required") {
11
13
  if (context.mode?.json) {
12
14
  context.write(json(result));
13
15
  return;
14
16
  }
15
- for (const line of renderSyncOutput(result.events ?? []))
17
+ for (const line of renderSyncOutput(result.events)) {
16
18
  context.write(line);
19
+ }
17
20
  return;
18
21
  }
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>");
22
+ if (context.mode?.json || !process.stdin.isTTY || !process.stdout.isTTY) {
23
+ throw new DecisionRequiredError(result.conflicts);
24
+ }
21
25
  const type = await select({
22
26
  loop: false,
23
27
  message: "Existing exclusions or disabled assets",
@@ -28,10 +32,9 @@ export async function runSelection(context, action, options) {
28
32
  { value: "per-asset", name: "Choose for each asset" },
29
33
  ],
30
34
  });
31
- let resolution;
32
35
  if (type === "per-asset") {
33
36
  const decisions = [];
34
- for (const conflict of result.conflicts ?? [])
37
+ for (const conflict of result.conflicts) {
35
38
  decisions.push({
36
39
  assetId: conflict.asset.id,
37
40
  choice: (await confirm({
@@ -42,10 +45,11 @@ export async function runSelection(context, action, options) {
42
45
  ? "clear"
43
46
  : "preserve",
44
47
  });
48
+ }
45
49
  resolution = { type: "per-asset", decisions };
46
50
  }
47
- else
48
- resolution = { type: type };
49
- options = { ...options, resolution };
51
+ else {
52
+ resolution = { type };
53
+ }
50
54
  }
51
55
  }
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "barndog",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "barndog": "dist/cli.js"
@@ -9,16 +9,18 @@
9
9
  "node": ">=24"
10
10
  },
11
11
  "scripts": {
12
- "lint": "eslint . --max-warnings=0",
13
- "lint:fix": "eslint . --fix --max-warnings=0",
12
+ "lint": "eslint .",
13
+ "lint:fix": "eslint . --fix",
14
14
  "format": "pnpm lint:fix && prettier --write .",
15
15
  "format:check": "prettier --check .",
16
16
  "clean": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\"",
17
17
  "build": "pnpm clean && tsc -p tsconfig.build.json && node scripts/finish-build.mjs",
18
18
  "barndog": "node dist/cli.js",
19
19
  "test": "vitest run",
20
+ "test:coverage": "vitest run --coverage",
20
21
  "prepack": "pnpm build",
21
22
  "typecheck": "tsc",
23
+ "knip": "knip && knip --production",
22
24
  "test:watch": "vitest"
23
25
  },
24
26
  "dependencies": {
@@ -30,7 +32,9 @@
30
32
  "@inquirer/input": "^5.1.9",
31
33
  "@inquirer/select": "^5.2.8",
32
34
  "commander": "^15.0.0",
35
+ "cross-spawn": "^7.0.6",
33
36
  "jsonc-parser": "^3.3.1",
37
+ "open": "^11.0.4",
34
38
  "semver": "^7.8.5",
35
39
  "smol-toml": "^1.9.1",
36
40
  "tar": "^7.5.22",
@@ -41,11 +45,17 @@
41
45
  "devDependencies": {
42
46
  "@eslint/js": "^10.0.1",
43
47
  "@stylistic/eslint-plugin": "^5.10.0",
48
+ "@types/cross-spawn": "^6.0.6",
44
49
  "@types/node": "^24.0.0",
45
50
  "@types/semver": "^7.8.0",
51
+ "@vitest/coverage-v8": "^5.1.0",
46
52
  "eslint": "^10.13.0",
47
53
  "eslint-config-prettier": "^10.1.8",
54
+ "eslint-import-resolver-typescript": "^4.4.5",
55
+ "eslint-plugin-import-x": "^4.18.1",
56
+ "eslint-plugin-regexp": "^3.3.3",
48
57
  "globals": "^17.13.0",
58
+ "knip": "^6.45.1",
49
59
  "prettier": "^3.9.10",
50
60
  "typescript": "^5.9.0",
51
61
  "typescript-eslint": "^8.72.0",