barndog 0.2.1 → 0.2.3

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 (92) hide show
  1. package/README.md +21 -0
  2. package/dist/cli.js +29 -3
  3. package/dist/commands/add.js +4 -2
  4. package/dist/commands/asset-install.js +7 -3
  5. package/dist/commands/asset-list.js +5 -1
  6. package/dist/commands/asset-share.js +15 -3
  7. package/dist/commands/capabilities.js +23 -5
  8. package/dist/commands/collaboration.js +9 -3
  9. package/dist/commands/harnesses.js +33 -3
  10. package/dist/commands/hooks.js +16 -1
  11. package/dist/commands/mcp-env.js +159 -43
  12. package/dist/commands/mcp.js +13 -3
  13. package/dist/commands/origin.js +7 -4
  14. package/dist/commands/sets.js +16 -5
  15. package/dist/commands/status.js +3 -1
  16. package/dist/commands/sync.js +1 -1
  17. package/dist/commands/uninstall.js +64 -0
  18. package/dist/commands/workspace.js +19 -0
  19. package/dist/config/paths.js +2 -0
  20. package/dist/config/state.js +19 -0
  21. package/dist/entry/update-check.js +15 -0
  22. package/dist/errors.js +4 -0
  23. package/dist/features/adoption/adopt.js +47 -29
  24. package/dist/features/adoption/scan.js +5 -0
  25. package/dist/features/asset-kinds/url-query.js +26 -0
  26. package/dist/features/auth/session.js +22 -0
  27. package/dist/features/collaboration/workspace-store.js +2 -1
  28. package/dist/features/doctor/check.js +1 -0
  29. package/dist/features/doctor/grouped.js +127 -0
  30. package/dist/features/doctor/index.js +29 -27
  31. package/dist/features/environment/events.js +18 -1
  32. package/dist/features/environment/kept-value-events.js +40 -0
  33. package/dist/features/environment/kept-values.js +68 -0
  34. package/dist/features/environment/mcp-records.js +57 -0
  35. package/dist/features/environment/moves.js +17 -1
  36. package/dist/features/environment/stage.js +32 -28
  37. package/dist/features/environment/sync.js +13 -3
  38. package/dist/features/environment/writes.js +25 -27
  39. package/dist/features/hooks/compatibility.js +37 -17
  40. package/dist/features/hooks/test.js +2 -2
  41. package/dist/features/inventory/hook-matrix.js +14 -0
  42. package/dist/features/inventory/hook-readiness.js +47 -0
  43. package/dist/features/inventory/index.js +54 -3
  44. package/dist/features/inventory/show.js +10 -2
  45. package/dist/features/mcps/import.js +74 -21
  46. package/dist/features/mcps/index.js +28 -5
  47. package/dist/features/mcps/values.js +161 -23
  48. package/dist/features/migration/migrate.js +15 -0
  49. package/dist/features/migration/move.js +38 -9
  50. package/dist/features/migration/promote.js +1 -0
  51. package/dist/features/native/adapters.js +5 -46
  52. package/dist/features/native/hook-shell.js +11 -0
  53. package/dist/features/native/requirements.js +98 -0
  54. package/dist/features/secrets/index.js +95 -29
  55. package/dist/features/uninstall/index.js +126 -0
  56. package/dist/features/uninstall/leave.js +152 -0
  57. package/dist/features/uninstall/survey.js +103 -0
  58. package/dist/features/update-check/index.js +108 -0
  59. package/dist/features/workspace/cloud-source.js +38 -4
  60. package/dist/features/workspace/format.js +6 -1
  61. package/dist/harnesses/claude.js +1 -1
  62. package/dist/harnesses/codex.js +46 -22
  63. package/dist/harnesses/cursor.js +1 -1
  64. package/dist/harnesses/opencode.js +1 -1
  65. package/dist/harnesses/read-renamed-variables.js +141 -0
  66. package/dist/harnesses/renamed-variables.js +99 -0
  67. package/dist/platform.js +12 -1
  68. package/dist/program.js +24 -9
  69. package/dist/ui/add-hook.js +2 -2
  70. package/dist/ui/add-mcp.js +54 -16
  71. package/dist/ui/add-skills.js +2 -2
  72. package/dist/ui/adopt.js +90 -19
  73. package/dist/ui/assets.js +15 -2
  74. package/dist/ui/collaboration.js +5 -3
  75. package/dist/ui/connection.js +2 -0
  76. package/dist/ui/format.js +81 -2
  77. package/dist/ui/harness-picker.js +7 -2
  78. package/dist/ui/hook-compatibility.js +176 -22
  79. package/dist/ui/mcp.js +169 -24
  80. package/dist/ui/move.js +3 -2
  81. package/dist/ui/onboarding.js +11 -2
  82. package/dist/ui/output.js +116 -37
  83. package/dist/ui/package-details.js +7 -2
  84. package/dist/ui/pick.js +20 -6
  85. package/dist/ui/secret-input.js +9 -0
  86. package/dist/ui/selection.js +1 -1
  87. package/dist/ui/uninstall.js +186 -0
  88. package/dist/ui/update.js +10 -0
  89. package/dist/ui/variable-problems.js +23 -0
  90. package/dist/version.js +2 -2
  91. package/package.json +2 -2
  92. package/dist/entry/mcp-launch.js +0 -71
@@ -7,6 +7,11 @@ import { addMcpServers, conflictingEntries, convertServer, harnessServers, local
7
7
  import { assetKinds } from "../features/asset-kinds/index.js";
8
8
  import { validMcpName } from "../shared/patterns.js";
9
9
  import { bold, dim, ok, warn } from "./format.js";
10
+ import { displayPath, keptValueFiles } from "./output.js";
11
+ import { variableProblemLines } from "./variable-problems.js";
12
+ import { keptValuesMessage } from "../features/environment/events.js";
13
+ import { urlQueries } from "../features/asset-kinds/url-query.js";
14
+ import { LOCAL_URL_QUERY, renderMcpValues, renderSignIn, renderUrlQueries, } from "./mcp.js";
10
15
  async function serversToAdd(name, options, context) {
11
16
  if (options.config) {
12
17
  return parseMcpText(options.config, name);
@@ -67,12 +72,18 @@ async function chooseKept(found, context) {
67
72
  return [];
68
73
  }
69
74
  context.write(dim("BarnDog can keep these values in ~/.barndog/secrets.json, which only you can read and which is never uploaded, and write them into your coding tools' settings. Leave one unticked to set it yourself."));
70
- return context.prompts.chooseMany("Which values should BarnDog keep on this machine?", found.map(({ server, literal }) => ({
75
+ const picked = await context.prompts.chooseMany("Which values should BarnDog keep on this machine?", found.map(({ server, literal }, index) => ({
71
76
  name: `${literal.variable} ${dim(`${server}: ${literal.key}`)}`,
72
77
  short: literal.variable,
73
- value: literal.variable,
78
+ value: String(index),
74
79
  checked: true,
75
80
  })));
81
+ return picked.flatMap((index) => {
82
+ const choice = found[Number(index)];
83
+ return choice
84
+ ? [{ server: choice.server, variable: choice.literal.variable }]
85
+ : [];
86
+ });
76
87
  }
77
88
  /** Why a server can't be added under `name` here, or null when it can. */
78
89
  async function nameProblem(name, context) {
@@ -111,6 +122,23 @@ async function namedServers(servers, as, context) {
111
122
  }
112
123
  return result;
113
124
  }
125
+ /**
126
+ * Warns about URLs with a query string, which BarnDog keeps as written, and in
127
+ * a terminal asks whether to add them; elsewhere the added servers' notes say so.
128
+ */
129
+ async function confirmUrlQueries(servers, context) {
130
+ const queries = urlQueries(servers);
131
+ if (!queries.length || !context.interactive) {
132
+ return;
133
+ }
134
+ for (const line of renderUrlQueries(queries)) {
135
+ context.write(line);
136
+ }
137
+ context.write(dim(LOCAL_URL_QUERY));
138
+ if (!(await context.prompts.yes(`Add ${queries.length === 1 ? "it" : "them"}?`))) {
139
+ throw new CliError("Nothing was added.");
140
+ }
141
+ }
114
142
  /**
115
143
  * `mcp add`: imports MCP servers from a harness's configuration or pasted JSON
116
144
  * into the local workspace.
@@ -138,6 +166,7 @@ export async function addMcp(name, options, context) {
138
166
  if (!servers.length) {
139
167
  throw new CliError("No MCP servers were chosen, so nothing was added.");
140
168
  }
169
+ await confirmUrlQueries(servers, context);
141
170
  let replace = options.replace;
142
171
  const conflicts = (await Promise.all(servers.map((s) => conflictingEntries(s.name, context.runtime)))).flat();
143
172
  if (conflicts.length && !replace && context.interactive) {
@@ -152,19 +181,28 @@ export async function addMcp(name, options, context) {
152
181
  }
153
182
  const keep = await chooseKept(servers.flatMap((server) => server.literals.map((literal) => ({ server: server.name, literal }))), context);
154
183
  const result = await addMcpServers(servers, { replace, keep }, context.runtime);
155
- for (const added of result.added) {
156
- context.write(`${ok("✔")} Added ${bold(added)}`);
157
- }
158
- for (const note of result.notes) {
159
- context.write(`${warn("!")} ${bold(note.server)}: ${note.text}`);
160
- }
161
- // Sync says where each kept value was written.
162
- result.events.forEach((event) => {
163
- if (event.type === "notice") {
164
- context.write(dim(event.message));
165
- }
166
- });
167
- for (const backup of result.backups) {
168
- context.write(dim(`Backup: ${backup}`));
184
+ for (const line of renderAddedServers(result, context.runtime)) {
185
+ context.write(line);
169
186
  }
170
187
  }
188
+ /** What `mcp add` added, what's left to do, and where it backed up settings. */
189
+ function renderAddedServers(result, runtime) {
190
+ return [
191
+ ...result.added.map((added) => `${ok("✔")} Added ${bold(added)}`),
192
+ ...result.notes.map((note) => `${warn("!")} ${bold(note.server)}: ${note.text}`),
193
+ ...renderSignIn(result.signIn),
194
+ ...renderMcpValues(result.values),
195
+ // Sync says where each kept value was written.
196
+ ...result.events.flatMap((event) => {
197
+ if (event.type === "kept-values") {
198
+ return [
199
+ dim(keptValuesMessage(event)),
200
+ ...keptValueFiles(event, runtime),
201
+ ];
202
+ }
203
+ return event.type === "notice" ? [dim(event.message)] : [];
204
+ }),
205
+ ...result.backups.map((backup) => dim(`Backup: ${displayPath(backup, runtime)}`)),
206
+ ...variableProblemLines(result.events, result.values),
207
+ ];
208
+ }
@@ -4,7 +4,7 @@ import { discoverSkills, } from "../features/imports/discover.js";
4
4
  import { renamedSkill, saveImported } from "../features/imports/local.js";
5
5
  import { assertSourceExists, plainFolder, readFolder, removeImported, } from "../features/imports/folder.js";
6
6
  import { fetchRemote, parseLocation, } from "../features/imports/remote.js";
7
- import { bold, dim, ok, warn } from "./format.js";
7
+ import { bold, choiceDescription, dim, ok, warn } from "./format.js";
8
8
  import { defined } from "../shared/lookup.js";
9
9
  import { finish, folderLabel, assertDistinctNames, notFound, onlyChosen, updateMode, } from "./add-asset.js";
10
10
  /** Stops two copies of a Skill from claiming the same name, saying which folders hold them. */
@@ -76,7 +76,7 @@ export async function addSkills(url, options, context) {
76
76
  name: `${s.name} ${dim(folderLabel(s.root))}`,
77
77
  value: s.root,
78
78
  short: distinctName(s),
79
- description: `Description: ${s.description}`,
79
+ description: choiceDescription(`Description: ${s.description}`),
80
80
  })));
81
81
  chosen = skills.filter((s) => picked.includes(s.root));
82
82
  }
package/dist/ui/adopt.js CHANGED
@@ -2,10 +2,12 @@ import checkbox, { Separator } from "@inquirer/checkbox";
2
2
  import confirm from "@inquirer/confirm";
3
3
  import { adoptNative, adoptionPlan, } from "../features/adoption/adopt.js";
4
4
  import { scanNative, } from "../features/adoption/scan.js";
5
- import { friendlyMessage } from "../errors.js";
5
+ import { friendlyMessage, promptCancelled } from "../errors.js";
6
6
  import { harnesses, adapters } from "../harnesses/registry.js";
7
- import { bold, dim, heading, hint, ok, plural, table, warn } from "./format.js";
7
+ import { bold, checklistPageSize, choiceDescription, dim, heading, hint, ok, plural, table, warn, } from "./format.js";
8
8
  import { displayPath } from "./output.js";
9
+ import { variableProblemLines } from "./variable-problems.js";
10
+ import { LOCAL_URL_QUERY, renderMcpValues, renderSignIn, renderUrlQueries, } from "./mcp.js";
9
11
  import { checkboxTheme, promptTheme } from "./theme.js";
10
12
  const kindLabels = {
11
13
  skill: "Skill",
@@ -29,12 +31,14 @@ const byTool = (items) => harnesses.flatMap((harness) => {
29
31
  });
30
32
  /** What a scan found, one section per coding tool. */
31
33
  export function renderScan(scan, runtime) {
32
- if (!scan.assets.length && !scan.skipped.length) {
33
- return [
34
- dim("Your coding tools have no Skills, MCP servers or Hooks that BarnDog doesn't manage."),
35
- ];
36
- }
37
34
  const output = [];
35
+ if (!scan.assets.length) {
36
+ output.push(`${ok("✔")} Nothing left to adopt: BarnDog manages every Skill, MCP server and Hook it can take over from your coding tools.`);
37
+ if (!scan.skipped.length) {
38
+ return output;
39
+ }
40
+ output.push("");
41
+ }
38
42
  for (const { harness, items } of byTool(scan.assets)) {
39
43
  output.push(bold(adapters[harness].name));
40
44
  output.push(...table(items.map((asset) => [
@@ -54,21 +58,72 @@ export function renderScan(scan, runtime) {
54
58
  }
55
59
  return output;
56
60
  }
57
- const chooseAdoption = (scan) => checkbox({
58
- loop: false,
59
- message: "Which assets should BarnDog adopt?",
60
- choices: byTool(scan.assets).flatMap(({ harness, items }) => [
61
- new Separator(bold(adapters[harness].name)),
62
- ...items.map((asset) => ({
61
+ /**
62
+ * Columns Inquirer draws before a choice's name (cursor, then a circle such as
63
+ * ` ◯`, then a space); a text row is indented to match.
64
+ */
65
+ const CHOICE_PREFIX_WIDTH = 4;
66
+ /** What a same-named copy picked in an earlier tool's checklist does to this one, if one was picked. */
67
+ function broughtAlong(asset, picked) {
68
+ const twin = asset.sameName.find((other) => picked.includes(other.key));
69
+ if (!twin) {
70
+ return undefined;
71
+ }
72
+ const tool = adapters[twin.harness].name;
73
+ return asset.identical
74
+ ? `already comes with ${tool}`
75
+ : warn(`replaced by ${tool}'s copy`);
76
+ }
77
+ /**
78
+ * One tool's checklist: the assets still to choose, then, as text the cursor
79
+ * skips, those an earlier pick already brings along. Returns no choices when
80
+ * nothing is left to pick.
81
+ */
82
+ function adoptionChoices(items, picked) {
83
+ const nameWidth = Math.max(...items.map((asset) => asset.name.length));
84
+ const label = (asset) => `${kindLabels[asset.kind].padEnd(kindWidth)} ${asset.name.padEnd(nameWidth)}`;
85
+ const open = items.filter((asset) => !broughtAlong(asset, picked));
86
+ const along = items.flatMap((asset) => {
87
+ const note = broughtAlong(asset, picked);
88
+ return note
89
+ ? [
90
+ new Separator(`${" ".repeat(CHOICE_PREFIX_WIDTH - 1)}${dim(label(asset))} ${note}`),
91
+ ]
92
+ : [];
93
+ });
94
+ if (!open.length) {
95
+ return [];
96
+ }
97
+ return [
98
+ ...open.map((asset) => ({
63
99
  value: asset.key,
64
100
  checked: false,
65
101
  short: asset.key,
66
- name: `${kindLabels[asset.kind].padEnd(kindWidth)} ${asset.name}${sharing(asset) ? dim(` ${sharing(asset)}`) : ""}`,
67
- description: asset.description,
102
+ name: `${label(asset)}${sharing(asset) ? dim(` ${sharing(asset)}`) : ""}`,
103
+ description: choiceDescription(asset.description),
68
104
  })),
69
- ]),
70
- theme: checkboxTheme,
71
- });
105
+ ...along,
106
+ ];
107
+ }
108
+ /** Asks tool by tool, so each checklist names the tool its assets are in. */
109
+ const chooseAdoption = async (scan) => {
110
+ const picked = [];
111
+ for (const { harness, items } of byTool(scan.assets)) {
112
+ const choices = adoptionChoices(items, picked);
113
+ // Inquirer refuses a checklist with nothing left to pick.
114
+ if (!choices.length) {
115
+ continue;
116
+ }
117
+ picked.push(...(await checkbox({
118
+ loop: false,
119
+ message: `Which ${bold(adapters[harness].name)} assets should BarnDog adopt?`,
120
+ choices,
121
+ pageSize: checklistPageSize(items.length),
122
+ theme: checkboxTheme,
123
+ })));
124
+ }
125
+ return picked;
126
+ };
72
127
  /** What an adoption will take over, including other tools' copies BarnDog's one replaces. */
73
128
  function renderPlan(plan) {
74
129
  const output = [bold("BarnDog will adopt")];
@@ -81,6 +136,13 @@ function renderPlan(plan) {
81
136
  : "",
82
137
  ])));
83
138
  output.push("", dim("Originals move into ~/.barndog/adoptions/ and BarnDog installs its copies in their place."), dim("Adopted Skills and MCP servers install in every coding tool BarnDog manages."));
139
+ // Same-named copies share one source, so each server is named once.
140
+ const queries = plan
141
+ .filter((asset) => asset.key === asset.source.key)
142
+ .flatMap(({ name, queryParameters: parameters }) => parameters.length ? [{ name, parameters }] : []);
143
+ if (queries.length) {
144
+ output.push("", ...renderUrlQueries(queries), dim(LOCAL_URL_QUERY));
145
+ }
84
146
  return output;
85
147
  }
86
148
  const confirmAdoption = (plan) => confirm({
@@ -96,6 +158,9 @@ export function renderAdoption(result, runtime) {
96
158
  for (const note of result.notes) {
97
159
  output.push(`${warn("!")} ${kindLabels[note.kind]} ${bold(note.name)}: ${note.text}`);
98
160
  }
161
+ output.push(...renderSignIn(result.signIn));
162
+ output.push(...renderMcpValues(result.values));
163
+ output.push(...variableProblemLines(result.events, result.values));
99
164
  output.push("", result.canShare
100
165
  ? hint("barndog local move", "Tip") +
101
166
  dim(" share them through your workspace")
@@ -127,11 +192,13 @@ export function renderAdoptions(list) {
127
192
  ]), { header: ["ID", "Date", "Status", "Assets"] });
128
193
  }
129
194
  const chooseKeptValues = (values) => checkbox({
195
+ loop: false,
130
196
  message: "Which values should BarnDog keep on this machine?",
197
+ pageSize: checklistPageSize(values.length),
131
198
  choices: values.map((value) => ({
132
199
  name: `${value.variable} ${dim(`${value.server}: ${value.key}`)}`,
133
200
  short: value.variable,
134
- value: value.variable,
201
+ value: { server: value.server, variable: value.variable },
135
202
  checked: true,
136
203
  })),
137
204
  theme: checkboxTheme,
@@ -191,6 +258,10 @@ export async function offerAdoptionAtSetup(runtime, prompt) {
191
258
  }
192
259
  }
193
260
  catch (error) {
261
+ if (promptCancelled(error)) {
262
+ prompt.write(`${dim("Adoption cancelled; nothing was adopted. Run")} ${bold("barndog adopt")} ${dim("any time.")}`);
263
+ return;
264
+ }
194
265
  prompt.write(`${warn("!")} Nothing was adopted: ${friendlyMessage(error)}`);
195
266
  prompt.write(hint("barndog adopt", "Tip") + dim(" try again later"));
196
267
  }
package/dist/ui/assets.js CHANGED
@@ -5,11 +5,14 @@ import { displayPath } from "./output.js";
5
5
  import { badge, bold, clean, dim, hint, ok, originLabel, plural, section, table, } from "./format.js";
6
6
  export const harnessNames = (harnesses) => harnesses.map((h) => adapters[h].name).join(", ");
7
7
  const listGroup = (state) => state === "available" || state === "disabled" ? state : "installed";
8
- /** Outdated assets look pending and modified ones look clashed. */
8
+ /** Outdated assets look pending, modified ones look clashed, Hooks that can't run look skipped. */
9
9
  function badgeState(state) {
10
10
  if (state === "outdated") {
11
11
  return "pending";
12
12
  }
13
+ if (state === "cant-run") {
14
+ return "skipped";
15
+ }
13
16
  return state === "modified" ? "clash" : state;
14
17
  }
15
18
  /** Installed first, then disabled, then available; no filter means all three. */
@@ -40,11 +43,17 @@ const stateLabel = {
40
43
  installed: "installed",
41
44
  disabled: "disabled",
42
45
  pending: "pending",
46
+ "cant-run": "can't run",
47
+ "no-version": "no version for your tools",
43
48
  outdated: "update available",
44
49
  clash: "clash",
45
50
  modified: "edited by hand",
46
51
  removing: "pending removal",
47
52
  };
53
+ /** A state as a table or picker shows it: colored by how much it needs attention. */
54
+ export function stateBadge(state) {
55
+ return badge(badgeState(state), stateLabel[state]);
56
+ }
48
57
  /** One table of what is selected and installed, with an optional path listing. */
49
58
  export function renderInventory(items, options) {
50
59
  const output = [];
@@ -59,7 +68,7 @@ export function renderInventory(items, options) {
59
68
  dim(item.harnesses.length
60
69
  ? item.harnesses.map((h) => adapters[h].name).join(", ")
61
70
  : "—"),
62
- badge(badgeState(item.state), stateLabel[item.state]),
71
+ stateBadge(item.state),
63
72
  ]), { header: ["Name", "Origin", "Via", "Installed in", "State"], flex: 2 }));
64
73
  if (options.paths) {
65
74
  for (const item of items) {
@@ -90,6 +99,10 @@ export function inventoryHints(items) {
90
99
  output.push(hint("barndog sync", "Fix") +
91
100
  dim(" in a terminal to choose how to resolve name clashes"));
92
101
  }
102
+ if (count("cant-run")) {
103
+ output.push(hint("barndog doctor", "Fix") +
104
+ dim(` to see what ${plural(count("cant-run"), "Hook")} ${count("cant-run") === 1 ? "needs" : "need"} to run`));
105
+ }
93
106
  return output;
94
107
  }
95
108
  /**
@@ -82,7 +82,7 @@ function executableNote(previous, next) {
82
82
  return ` executable: ${safe(previous)} → ${safe(next)}`;
83
83
  }
84
84
  /** Results are told apart by their shape, not by the command that produced them. */
85
- export function renderCollaboration(value, options = {}) {
85
+ export function renderCollaboration(value, options) {
86
86
  if (Array.isArray(value)) {
87
87
  if (!value.length) {
88
88
  return ["No changes."];
@@ -142,7 +142,7 @@ export function renderCollaboration(value, options = {}) {
142
142
  }
143
143
  if (value && typeof value === "object") {
144
144
  if (isEnvironmentPreview(value)) {
145
- return renderSyncOutput(value.events, {
145
+ return renderSyncOutput(value.events, options.runtime, {
146
146
  title: "preview",
147
147
  preview: true,
148
148
  });
@@ -191,7 +191,9 @@ export function renderCollaboration(value, options = {}) {
191
191
  ? ["Submission awaiting confirmation; retry barndog push."]
192
192
  : []),
193
193
  ...status.conflicts.map((path) => `Conflict: ${safe(path)}`),
194
- ...renderCollaboration(status.changes).filter((line) => !line.startsWith("@@") && !line.startsWith("+")),
194
+ ...renderCollaboration(status.changes, {
195
+ runtime: options.runtime,
196
+ }).filter((line) => !line.startsWith("@@") && !line.startsWith("+")),
195
197
  ];
196
198
  }
197
199
  const workingCopy = workingCopySchema.safeParse(value);
@@ -78,6 +78,7 @@ export async function chooseConnection(current) {
78
78
  }
79
79
  export function chooseLocalAssets(count) {
80
80
  return select({
81
+ loop: false,
81
82
  message: `You have ${count} local asset${count === 1 ? "" : "s"}. What should happen to ${count === 1 ? "it" : "them"}?`,
82
83
  choices: [
83
84
  {
@@ -106,6 +107,7 @@ export function chooseLocalAssets(count) {
106
107
  }
107
108
  export function chooseMoveTarget(targets) {
108
109
  return select({
110
+ loop: false,
109
111
  message: "Where should they go?",
110
112
  choices: targets,
111
113
  theme: promptTheme,
package/dist/ui/format.js CHANGED
@@ -27,6 +27,8 @@ export const dim = (text) => paint("dim", text);
27
27
  export const warn = (text) => paint("yellow", text);
28
28
  export const ok = (text) => selected(text);
29
29
  export const bad = (text) => danger(text);
30
+ /** Dimmed danger, for things the user has turned off. */
31
+ export const off = (text) => dim(danger(text));
30
32
  /** Removes terminal control sequences and folds whitespace in remote text. */
31
33
  export function clean(value) {
32
34
  return safe(value).replace(/\s+/g, " ").trim();
@@ -39,13 +41,15 @@ export function clean(value) {
39
41
  export function visibleWidth(text) {
40
42
  return [...stripVTControlCharacters(text)].length;
41
43
  }
42
- function pad(text, width) {
44
+ /** `text` followed by spaces to `width` visible columns. */
45
+ export function pad(text, width) {
43
46
  return text + " ".repeat(Math.max(0, width - visibleWidth(text)));
44
47
  }
45
48
  /** One SGR style code, such as `\u001b[1m` (bold) or `\u001b[38;2;197;72;54m`; captured so `split` keeps it. */
46
49
  // eslint-disable-next-line no-control-regex -- matches terminal style codes
47
50
  const STYLE_CODE = /(\u001b\[[\d;]*m)/;
48
- function truncate(text, width) {
51
+ /** `text` cut to `width` visible columns with `…`, keeping its style codes. */
52
+ export function truncate(text, width) {
49
53
  const plain = stripVTControlCharacters(text);
50
54
  if ([...plain].length <= width) {
51
55
  return text;
@@ -96,6 +100,79 @@ export function fields(rows, indent = 0) {
96
100
  const width = Math.max(0, ...visible.map(([label]) => label.length));
97
101
  return visible.map(([label, value]) => `${" ".repeat(indent)}${dim(pad(label, width))} ${value}`);
98
102
  }
103
+ /**
104
+ * Lines a choice's description always takes, so a checklist keeps its height
105
+ * as the cursor moves between short and long descriptions.
106
+ */
107
+ const DESCRIPTION_LINES = 5;
108
+ /** Columns assumed when the output has no terminal dimensions. */
109
+ const FALLBACK_COLUMNS = 80;
110
+ /** Inquirer's checklist lines besides choices and description: question, blank line, key help. */
111
+ const CHECKLIST_FIXED_LINES = 3;
112
+ /** Lines a checklist takes besides its choices, with one spare. */
113
+ const CHECKLIST_CHROME_LINES = CHECKLIST_FIXED_LINES + DESCRIPTION_LINES + 1;
114
+ /** Inquirer's own page size, the fewest choices a checklist shows. */
115
+ const MIN_CHECKLIST_PAGE = 7;
116
+ /** How many of `count` choices a checklist shows at once: as many as the terminal's height fits. */
117
+ export function checklistPageSize(count) {
118
+ const rows = process.stdout.rows || 0;
119
+ return Math.max(MIN_CHECKLIST_PAGE, Math.min(count, rows - CHECKLIST_CHROME_LINES));
120
+ }
121
+ /** Words wrapped to lines of at most `width` columns; a longer word is cut. */
122
+ function wrapWords(text, width) {
123
+ const lines = [];
124
+ for (const paragraph of text.split("\n")) {
125
+ let line = "";
126
+ for (const word of paragraph.split(" ").filter(Boolean)) {
127
+ if (!line) {
128
+ line = word;
129
+ }
130
+ else if (visibleWidth(line) + 1 + visibleWidth(word) <= width) {
131
+ line += ` ${word}`;
132
+ }
133
+ else {
134
+ lines.push(line);
135
+ line = word;
136
+ }
137
+ }
138
+ lines.push(line);
139
+ }
140
+ return lines.map((line) => truncate(line, width));
141
+ }
142
+ /**
143
+ * A bold label before each comma-separated list, the lists aligned and
144
+ * wrapped under themselves rather than under the label:
145
+ *
146
+ * node_repl NODE_REPL_INSTRUCTIONS_USE_CASE_CHROME,
147
+ * BROWSER_USE_ACCESS_PIPE_PATH
148
+ */
149
+ export function labelledLists(rows, options) {
150
+ const width = options.width ?? (process.stdout.columns || FALLBACK_COLUMNS);
151
+ const labelWidth = Math.max(0, ...rows.map((row) => visibleWidth(row.label)));
152
+ const lead = options.indent + labelWidth + 2;
153
+ // A spare column keeps the terminal from wrapping a full line itself.
154
+ const room = Math.max(MIN_FLEX_COLUMN_WIDTH, width - lead - 1);
155
+ return rows.flatMap((row) => wrapWords(row.items.map(clean).join(", "), room).map((line, index) => `${" ".repeat(options.indent)}${index ? " ".repeat(labelWidth) : bold(pad(clean(row.label), labelWidth))} ${line}`));
156
+ }
157
+ /**
158
+ * A choice's description as exactly five lines: wrapped to the terminal,
159
+ * padded when shorter and cut with `…` when longer.
160
+ */
161
+ export function choiceDescription(text, width = process.stdout.columns || FALLBACK_COLUMNS) {
162
+ // A spare column keeps the terminal from wrapping a full line itself.
163
+ const room = width - 1;
164
+ const lines = wrapWords(text.trim(), room);
165
+ const shown = lines.length > DESCRIPTION_LINES
166
+ ? [
167
+ ...lines.slice(0, DESCRIPTION_LINES - 1),
168
+ truncate(`${lines[DESCRIPTION_LINES - 1]} ${lines[DESCRIPTION_LINES]}`, room),
169
+ ]
170
+ : lines;
171
+ return [
172
+ ...shown,
173
+ ...Array(DESCRIPTION_LINES - shown.length).fill(""),
174
+ ].join("\n");
175
+ }
99
176
  /** Aligned columns with ANSI-aware widths that fit the terminal. */
100
177
  export function table(rows, options = {}) {
101
178
  const indent = " ".repeat(options.indent ?? 2);
@@ -138,6 +215,8 @@ export function badge(state, label = state) {
138
215
  case "missing":
139
216
  case "unavailable":
140
217
  return bad(label);
218
+ case "disabled":
219
+ return off(label);
141
220
  default:
142
221
  return dim(label);
143
222
  }
@@ -1,11 +1,16 @@
1
1
  import checkbox from "@inquirer/checkbox";
2
2
  import { checkboxTheme, selected } from "./theme.js";
3
3
  import { dim } from "./format.js";
4
- export const chooseHarnesses = (choices) => {
4
+ const manage = {
5
+ message: "Which coding tools should BarnDog manage?",
6
+ required: false,
7
+ };
8
+ export const chooseHarnesses = (choices, question = manage) => {
5
9
  const width = Math.max(...choices.map((choice) => choice.name.length));
6
10
  return checkbox({
7
11
  loop: false,
8
- message: "Which coding tools should BarnDog manage?",
12
+ message: question.message,
13
+ required: question.required,
9
14
  choices: choices.map((choice) => ({
10
15
  value: choice.value,
11
16
  checked: choice.checked,