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
@@ -0,0 +1,197 @@
1
+ import checkbox, { Separator } from "@inquirer/checkbox";
2
+ import confirm from "@inquirer/confirm";
3
+ import { adoptNative, adoptionPlan, } from "../features/adoption/adopt.js";
4
+ import { scanNative, } from "../features/adoption/scan.js";
5
+ import { friendlyMessage } from "../errors.js";
6
+ import { harnesses, adapters } from "../harnesses/registry.js";
7
+ import { bold, dim, heading, hint, ok, plural, table, warn } from "./format.js";
8
+ import { displayPath } from "./output.js";
9
+ import { checkboxTheme, promptTheme } from "./theme.js";
10
+ const kindLabels = {
11
+ skill: "Skill",
12
+ mcp: "MCP",
13
+ hook: "Hook",
14
+ };
15
+ const kindWidth = Math.max(...Object.values(kindLabels).map((label) => label.length));
16
+ /** How the asset relates to other tools' assets of the same name, when it does. */
17
+ function sharing(asset) {
18
+ if (!asset.sameName.length) {
19
+ return "";
20
+ }
21
+ const tools = asset.sameName
22
+ .map((other) => adapters[other.harness].name)
23
+ .join(", ");
24
+ return asset.identical ? `same as ${tools}` : `differs from ${tools}`;
25
+ }
26
+ const byTool = (items) => harnesses.flatMap((harness) => {
27
+ const mine = items.filter((item) => item.harness === harness);
28
+ return mine.length ? [{ harness, items: mine }] : [];
29
+ });
30
+ /** What a scan found, one section per coding tool. */
31
+ 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
+ const output = [];
38
+ for (const { harness, items } of byTool(scan.assets)) {
39
+ output.push(bold(adapters[harness].name));
40
+ output.push(...table(items.map((asset) => [
41
+ dim(kindLabels[asset.kind]),
42
+ bold(asset.name),
43
+ asset.identical ? dim(sharing(asset)) : warn(sharing(asset)),
44
+ dim(asset.key),
45
+ ])));
46
+ output.push("");
47
+ }
48
+ if (scan.skipped.length) {
49
+ output.push(bold("Can't be adopted"));
50
+ for (const skipped of scan.skipped) {
51
+ output.push(` ${dim(`${adapters[skipped.harness].name} ${kindLabels[skipped.kind]}`)} ${bold(skipped.name)} ${dim(displayPath(skipped.location, runtime))}`, ` ${dim(skipped.reason)}`);
52
+ }
53
+ output.push("");
54
+ }
55
+ return output;
56
+ }
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) => ({
63
+ value: asset.key,
64
+ checked: false,
65
+ short: asset.key,
66
+ name: `${kindLabels[asset.kind].padEnd(kindWidth)} ${asset.name}${sharing(asset) ? dim(` ${sharing(asset)}`) : ""}`,
67
+ description: asset.description,
68
+ })),
69
+ ]),
70
+ theme: checkboxTheme,
71
+ });
72
+ /** What an adoption will take over, including other tools' copies BarnDog's one replaces. */
73
+ function renderPlan(plan) {
74
+ const output = [bold("BarnDog will adopt")];
75
+ output.push(...table(plan.map((asset) => [
76
+ adapters[asset.harness].name,
77
+ dim(kindLabels[asset.kind]),
78
+ bold(asset.name),
79
+ asset.source.key !== asset.key && !asset.identical
80
+ ? warn(`replaced by ${adapters[asset.source.harness].name}'s`)
81
+ : "",
82
+ ])));
83
+ 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."));
84
+ return output;
85
+ }
86
+ const confirmAdoption = (plan) => confirm({
87
+ message: `Adopt ${plural(plan.length, "asset")}?`,
88
+ default: true,
89
+ theme: promptTheme,
90
+ });
91
+ export function renderAdoption(result, runtime) {
92
+ const output = [
93
+ `${ok("✔")} Adopted ${plural(result.adopted.length, "asset")} into your local folder.`,
94
+ dim(`Originals are saved in ${displayPath(result.backup, runtime)}`),
95
+ ];
96
+ for (const note of result.notes) {
97
+ output.push(`${warn("!")} ${kindLabels[note.kind]} ${bold(note.name)}: ${note.text}`);
98
+ }
99
+ output.push("", result.canShare
100
+ ? hint("barndog local move", "Tip") +
101
+ dim(" share them through your workspace")
102
+ : hint("barndog local list", "Tip") +
103
+ dim(" see everything in your local workspace"));
104
+ return output;
105
+ }
106
+ export function renderUndo(result, runtime) {
107
+ const output = [
108
+ `${ok("✔")} Put back ${plural(result.restored.length, "asset")}.`,
109
+ ...result.restored.map((item) => ` ${adapters[item.harness].name} ${dim(kindLabels[item.kind])} ${bold(item.name)} ${dim(displayPath(item.location, runtime))}`),
110
+ ];
111
+ if (result.remaining.length) {
112
+ output.push("", dim(`${plural(result.remaining.length, "asset")} of this adoption ${result.remaining.length === 1 ? "is" : "are"} still managed by BarnDog.`));
113
+ }
114
+ return output;
115
+ }
116
+ export function renderAdoptions(list) {
117
+ if (!list.length) {
118
+ return [dim("Nothing has been adopted on this machine.")];
119
+ }
120
+ return table(list.map((record) => [
121
+ record.id,
122
+ dim(record.createdAt.slice(0, "YYYY-MM-DD".length)),
123
+ record.status === "applied" ? ok(record.status) : warn(record.status),
124
+ record.items
125
+ .map((item) => (item.undone ? dim(item.key) : item.key))
126
+ .join(", "),
127
+ ]), { header: ["ID", "Date", "Status", "Assets"] });
128
+ }
129
+ const chooseKeptValues = (values) => checkbox({
130
+ message: "Which values should BarnDog keep on this machine?",
131
+ choices: values.map((value) => ({
132
+ name: `${value.variable} ${dim(`${value.server}: ${value.key}`)}`,
133
+ short: value.variable,
134
+ value: value.variable,
135
+ checked: true,
136
+ })),
137
+ theme: checkboxTheme,
138
+ });
139
+ /** Shows what a scan found, asks which assets to adopt, and adopts them. */
140
+ export async function offerAdoption(scan, prompt) {
141
+ const { write } = prompt;
142
+ write(`\n${heading("adopt")}\n`);
143
+ write("These are set up in your coding tools without BarnDog:");
144
+ write("");
145
+ for (const line of renderScan(scan, prompt.runtime)) {
146
+ write(line);
147
+ }
148
+ const keys = await (prompt.choose ?? chooseAdoption)(scan);
149
+ if (!keys.length) {
150
+ write(`${dim("Nothing adopted. Run")} ${bold("barndog adopt")} ${dim("any time.")}`);
151
+ return;
152
+ }
153
+ const plan = adoptionPlan(scan, keys);
154
+ write("");
155
+ for (const line of renderPlan(plan)) {
156
+ write(line);
157
+ }
158
+ write("");
159
+ if (!(await (prompt.confirm ?? confirmAdoption)(plan))) {
160
+ write(dim("Nothing adopted."));
161
+ return;
162
+ }
163
+ // Same-named copies share one source, so each value is asked about once.
164
+ const values = plan
165
+ .filter((asset) => asset.key === asset.source.key)
166
+ .flatMap((asset) => asset.values.map((value) => ({ server: asset.name, ...value })));
167
+ let keep = [];
168
+ if (values.length) {
169
+ write("");
170
+ write(dim("These MCP values were written into the tools' settings. BarnDog can keep them in ~/.barndog/secrets.json, which only you can read and which is never uploaded, and write them into each tool it manages. Leave one unticked to set it yourself."));
171
+ keep = await (prompt.keepValues ?? chooseKeptValues)(values);
172
+ }
173
+ const result = await prompt.adoptNative(keys, keep);
174
+ for (const line of renderAdoption(result, prompt.runtime)) {
175
+ write(line);
176
+ }
177
+ }
178
+ /**
179
+ * First-time setup offers to adopt what the tools already have. Setup is saved
180
+ * by then, so a failure here is reported rather than failing setup.
181
+ */
182
+ export async function offerAdoptionAtSetup(runtime, prompt) {
183
+ try {
184
+ const scan = await scanNative(runtime);
185
+ if (scan.assets.length) {
186
+ await offerAdoption(scan, {
187
+ ...prompt,
188
+ adoptNative: (keys, keep) => adoptNative(keys, keep, runtime),
189
+ runtime,
190
+ });
191
+ }
192
+ }
193
+ catch (error) {
194
+ prompt.write(`${warn("!")} Nothing was adopted: ${friendlyMessage(error)}`);
195
+ prompt.write(hint("barndog adopt", "Tip") + dim(" try again later"));
196
+ }
197
+ }
@@ -1,22 +1,35 @@
1
1
  import { InvalidArgumentError } from "commander";
2
- import { originLabel } from "../features/environment/names.js";
3
- function positive(value) {
4
- if (!/^[1-9]\d*$/.test(value) || !Number.isSafeInteger(Number(value)))
5
- throw new InvalidArgumentError("Use a positive integer");
6
- return Number(value);
7
- }
2
+ import { originLabel } from "../features/server/origin.js";
3
+ import { positiveInteger } from "./options.js";
4
+ import { CliError } from "../errors.js";
5
+ /** BarnDog catalog pagination permits at most one hundred results. */
6
+ const MAX_PAGE_SIZE = 100;
7
+ /** Show twenty catalog results per page by default. */
8
+ const DEFAULT_PAGE_SIZE = 20;
9
+ /**
10
+ * Adds origin, paging and optional search flags to a Commander command,
11
+ * mutating and returning it.
12
+ */
8
13
  export function assetListOptions(command, withSearch = true) {
9
- if (withSearch)
14
+ if (withSearch) {
10
15
  command.option("--search <keywords>", "Search names, descriptions and origins");
16
+ }
11
17
  return pageOptions(command.option("--origin <origin>", "Filter by scope, such as org, team/engineering, repo/web-app or dev/john"));
12
18
  }
19
+ /**
20
+ * Adds positive page and limit flags to a command; defaults are page 1 and 20
21
+ * rows, with a 100-row maximum.
22
+ */
13
23
  export function pageOptions(command) {
14
- return command.option("--page <number>", "Results page", positive, 1).option("--limit <number>", "Results per page (maximum 100)", (value) => {
15
- const count = positive(value);
16
- if (count > 100)
24
+ return command
25
+ .option("--page <number>", "Results page", positiveInteger, 1)
26
+ .option("--limit <number>", "Results per page (maximum 100)", (value) => {
27
+ const count = positiveInteger(value);
28
+ if (count > MAX_PAGE_SIZE) {
17
29
  throw new InvalidArgumentError("Use at most 100 results per page");
30
+ }
18
31
  return count;
19
- }, 20);
32
+ }, DEFAULT_PAGE_SIZE);
20
33
  }
21
34
  /** Rows that match the search words and origin, in display order. */
22
35
  export function filterAssets(rows, options) {
@@ -36,11 +49,16 @@ export function filterAssets(rows, options) {
36
49
  (a.origin.slug ?? "").localeCompare(b.origin.slug ?? "") ||
37
50
  a.id.localeCompare(b.id));
38
51
  }
52
+ /**
53
+ * Filters and slices rows using one-based paging, returning totals and at least
54
+ * one page even for empty results.
55
+ */
39
56
  export function assetPage(rows, options) {
40
57
  const filtered = filterAssets(rows, options);
41
58
  const start = (options.page - 1) * options.limit;
42
- if (!Number.isSafeInteger(start))
43
- throw new Error("Page number is too large");
59
+ if (!Number.isSafeInteger(start)) {
60
+ throw new CliError("That --page number is too large. Use a smaller one.");
61
+ }
44
62
  return {
45
63
  rows: filtered.slice(start, start + options.limit),
46
64
  total: filtered.length,
package/dist/ui/assets.js CHANGED
@@ -1,36 +1,17 @@
1
+ import { shellWord } from "../platform.js";
1
2
  import { adapters } from "../harnesses/registry.js";
2
3
  import { assetPage } from "./asset-list.js";
3
4
  import { displayPath } from "./output.js";
4
5
  import { badge, bold, clean, dim, hint, ok, originLabel, plural, section, table, } from "./format.js";
5
- export const kindLabels = {
6
- skill: {
7
- group: "skills",
8
- one: "Skill",
9
- a: "a Skill",
10
- many: "Skills",
11
- title: "Skills",
12
- },
13
- mcp: {
14
- group: "mcp",
15
- one: "MCP server",
16
- a: "an MCP server",
17
- many: "MCP servers",
18
- title: "MCP servers",
19
- },
20
- hook: {
21
- group: "hooks",
22
- one: "Hook",
23
- a: "a Hook",
24
- many: "Hooks",
25
- title: "Hooks",
26
- },
27
- };
28
6
  export const harnessNames = (harnesses) => harnesses.map((h) => adapters[h].name).join(", ");
29
- const listGroup = (state) => state === "available"
30
- ? "available"
31
- : state === "disabled"
32
- ? "disabled"
33
- : "installed";
7
+ const listGroup = (state) => state === "available" || state === "disabled" ? state : "installed";
8
+ /** Outdated assets look pending and modified ones look clashed. */
9
+ function badgeState(state) {
10
+ if (state === "outdated") {
11
+ return "pending";
12
+ }
13
+ return state === "modified" ? "clash" : state;
14
+ }
34
15
  /** Installed first, then disabled, then available; no filter means all three. */
35
16
  export function assetListing(items, rows, filter) {
36
17
  const onMachine = new Set(items.map((item) => item.id));
@@ -65,10 +46,11 @@ const stateLabel = {
65
46
  removing: "pending removal",
66
47
  };
67
48
  /** One table of what is selected and installed, with an optional path listing. */
68
- export function renderInventory(items, options = {}) {
49
+ export function renderInventory(items, options) {
69
50
  const output = [];
70
- if (options.heading)
51
+ if (options.heading) {
71
52
  output.push(`${section(options.heading)} ${dim(`(${items.length})`)}`);
53
+ }
72
54
  output.push(...table(items.map((item) => [
73
55
  bold(item.installedName) +
74
56
  (item.installedName !== item.name ? dim(" (renamed)") : ""),
@@ -77,45 +59,53 @@ export function renderInventory(items, options = {}) {
77
59
  dim(item.harnesses.length
78
60
  ? item.harnesses.map((h) => adapters[h].name).join(", ")
79
61
  : "—"),
80
- badge(item.state === "outdated"
81
- ? "pending"
82
- : item.state === "modified"
83
- ? "clash"
84
- : item.state, stateLabel[item.state]),
62
+ badge(badgeState(item.state), stateLabel[item.state]),
85
63
  ]), { header: ["Name", "Origin", "Via", "Installed in", "State"], flex: 2 }));
86
- if (options.paths)
64
+ if (options.paths) {
87
65
  for (const item of items) {
88
- if (!item.paths.length)
66
+ if (!item.paths.length) {
89
67
  continue;
68
+ }
90
69
  output.push("", ` ${bold(item.installedName)}${item.installedName !== item.name ? dim(` · published as ${item.name}`) : ""}`);
91
- for (const path of item.paths)
92
- output.push(dim(` ${displayPath(path)}`));
70
+ for (const path of item.paths) {
71
+ output.push(dim(` ${displayPath(path, options.runtime)}`));
72
+ }
93
73
  }
74
+ }
94
75
  return output;
95
76
  }
96
77
  /** Follow-up advice for states that need action. */
97
78
  export function inventoryHints(items) {
98
79
  const output = [];
99
80
  const count = (state) => items.filter((item) => item.state === state).length;
100
- if (count("pending") || count("outdated") || count("removing"))
81
+ if (count("pending") || count("outdated") || count("removing")) {
101
82
  output.push(hint("barndog sync", "Next") +
102
83
  dim(` to apply ${plural(count("pending") + count("outdated") + count("removing"), "pending change")}`));
103
- if (count("modified"))
84
+ }
85
+ if (count("modified")) {
104
86
  output.push(hint("barndog doctor", "Fix") +
105
87
  dim(` to restore ${plural(count("modified"), "hand-edited asset")}`));
106
- if (count("clash"))
88
+ }
89
+ if (count("clash")) {
107
90
  output.push(hint("barndog sync", "Fix") +
108
91
  dim(" in a terminal to choose how to resolve name clashes"));
92
+ }
109
93
  return output;
110
94
  }
111
- export function renderCatalog(rows, options, command, installedIds) {
95
+ /**
96
+ * Returns a filtered catalog table and paging hints, marking selected IDs; does
97
+ * not write output.
98
+ */
99
+ export function renderCatalog(rows, options, next, installedIds) {
112
100
  const page = assetPage(rows, options);
113
- if (!page.total)
101
+ if (!page.total) {
114
102
  return [dim("No matching assets.")];
115
- if (!page.rows.length)
103
+ }
104
+ if (!page.rows.length) {
116
105
  return [
117
106
  `Page ${options.page} is empty. Choose a page from 1 to ${page.pages}.`,
118
107
  ];
108
+ }
119
109
  // Only Cloud has version numbers; local and Git assets are identified by a hash.
120
110
  const versioned = page.rows.some((row) => row.version.label === undefined);
121
111
  const output = table(page.rows.map((row) => [
@@ -135,8 +125,9 @@ export function renderCatalog(rows, options, command, installedIds) {
135
125
  });
136
126
  output.push("", dim(`Showing ${page.start + 1}–${page.start + page.rows.length} of ${page.total}${page.pages > 1 ? ` · page ${options.page}/${page.pages}` : ""}${installedIds.size ? " · ✔ selected on this machine" : ""}`));
137
127
  if (options.page < page.pages) {
138
- const filters = `${options.search ? ` ${JSON.stringify(options.search)}` : ""}${options.origin ? ` --origin ${options.origin}` : ""}`;
139
- output.push(hint(`${command}${filters} --page ${options.page + 1}`, "Next"));
128
+ const word = (value) => shellWord(value, next.platform);
129
+ const filters = `${options.search ? ` ${word(options.search)}` : ""}${options.origin ? ` --origin ${word(options.origin)}` : ""}`;
130
+ output.push(hint(`${next.command}${filters} --page ${options.page + 1}`, "Next"));
140
131
  }
141
132
  return output;
142
133
  }
package/dist/ui/auth.js CHANGED
@@ -1,38 +1,33 @@
1
- import { spawn } from "node:child_process";
2
- import { homedir } from "node:os";
3
- import { login, logout, authStatus } from "../features/auth/session.js";
4
- import { configuredServer } from "../features/auth/session.js";
1
+ import open from "open";
2
+ import { login, logout, authStatus, configuredServer, } from "../features/auth/session.js";
5
3
  import { readCredentials } from "../features/auth/credentials.js";
6
4
  import { LoginRequiredError } from "../features/auth/transport.js";
7
5
  import { CliError } from "../errors.js";
8
6
  import { promptServer } from "./connection.js";
7
+ import { interactiveTerminal } from "./pick.js";
9
8
  import { bad, bold, dim, fields, heading, hint, humanize, json, ok, warn, } from "./format.js";
9
+ /** Opens `url` in the default browser; rejects when no browser could be started. */
10
10
  export async function openBrowser(url) {
11
- const command = process.platform === "darwin"
12
- ? "open"
13
- : process.platform === "win32"
14
- ? "rundll32"
15
- : "xdg-open";
16
- const args = process.platform === "win32" ? ["url.dll,FileProtocolHandler", url] : [url];
17
- await new Promise((resolve, reject) => {
18
- const child = spawn(command, args, { stdio: "ignore" });
19
- child.once("error", reject);
20
- child.once("exit", (code) => code === 0 ? resolve() : reject(new Error("Unable to open browser")));
21
- });
11
+ await open(url);
22
12
  }
23
13
  function describeIdentity(context) {
24
14
  return `${bold(context.developer.name)} ${dim(`@${context.developer.slug}`)} · ${context.organization.name}`;
25
15
  }
16
+ /**
17
+ * Runs interactive device login, optionally opens a browser and saves
18
+ * credentials; reports an existing session unless forced.
19
+ */
26
20
  export async function runLogin(options, write) {
27
21
  const server = options.server ??
28
- (await configuredServer(options.home)) ??
29
- (process.stdin.isTTY && process.stdout.isTTY
22
+ (await configuredServer(options.runtime)) ??
23
+ ((options.interactive ?? interactiveTerminal())
30
24
  ? await promptServer()
31
25
  : undefined);
32
26
  if (server && !options.force) {
33
- const current = await authStatus(options.home, server).catch((error) => {
34
- if (error instanceof LoginRequiredError)
27
+ const current = await authStatus(options.runtime, server).catch((error) => {
28
+ if (error instanceof LoginRequiredError) {
35
29
  return undefined;
30
+ }
36
31
  throw error;
37
32
  });
38
33
  if (current) {
@@ -50,14 +45,15 @@ export async function runLogin(options, write) {
50
45
  try {
51
46
  const result = await login({
52
47
  server,
53
- home: options.home,
48
+ runtime: options.runtime,
54
49
  signal: controller.signal,
55
50
  verification: async (details) => {
56
51
  write(`\n${heading("sign-in")}\n`);
57
52
  write(`Verification code: ${bold(details.userCode)}`);
58
53
  write(`Open ${details.url} and confirm this code.`);
59
- if (options.browser)
54
+ if (options.browser) {
60
55
  await openBrowser(details.browserUrl).catch(() => write("Open the verification URL above to continue."));
56
+ }
61
57
  },
62
58
  });
63
59
  write("");
@@ -65,37 +61,51 @@ export async function runLogin(options, write) {
65
61
  write(hint("barndog init"));
66
62
  }
67
63
  catch (error) {
68
- if (controller.signal.aborted)
69
- throw new Error("Sign-in cancelled", { cause: error });
70
- if (error.name === "AbortError" ||
71
- error.name === "TimeoutError")
64
+ if (controller.signal.aborted) {
65
+ throw new CliError("Sign-in cancelled.", "barndog login", {
66
+ cause: error,
67
+ });
68
+ }
69
+ if (error instanceof Error &&
70
+ (error.name === "AbortError" || error.name === "TimeoutError")) {
72
71
  throw new CliError("Sign-in expired before it was confirmed.", "barndog login", {
73
72
  cause: error,
74
73
  });
74
+ }
75
75
  throw error;
76
76
  }
77
77
  finally {
78
78
  process.removeListener("SIGINT", cancel);
79
79
  }
80
80
  }
81
- export async function runLogout(write) {
82
- const result = await logout();
81
+ /**
82
+ * Revokes the current session and removes local credentials, reporting whether
83
+ * remote revocation was confirmed.
84
+ */
85
+ export async function runLogout(write, runtime) {
86
+ const result = await logout(runtime);
83
87
  write(result.revoked
84
88
  ? `${ok("✔")} Signed out of ${result.server}.`
85
89
  : `${warn("!")} Removed the local credential, but ${result.server} did not confirm the session was revoked.`);
86
90
  }
87
- export async function showAuthStatus(output, home = homedir()) {
91
+ /**
92
+ * Fetches and writes authentication status in JSON or terminal form; signed-out
93
+ * status sets process.exitCode to 1.
94
+ */
95
+ export async function showAuthStatus(output, runtime) {
88
96
  const { write } = output;
89
97
  let result;
90
98
  try {
91
- result = await authStatus(home);
99
+ result = await authStatus(runtime);
92
100
  }
93
101
  catch (error) {
94
- if (!(error instanceof LoginRequiredError))
102
+ if (!(error instanceof LoginRequiredError)) {
95
103
  throw error;
96
- const server = await configuredServer(home).catch(() => undefined);
97
- if (output.json)
104
+ }
105
+ const server = await configuredServer(runtime).catch(() => undefined);
106
+ if (output.json) {
98
107
  write(json({ signedIn: false, server: server ?? null }));
108
+ }
99
109
  else {
100
110
  write(`${bad("✖")} Not signed in${server ? ` to ${server}` : ""}.`);
101
111
  write(` ${hint(server ? "barndog login" : "barndog init", "Fix")}`);
@@ -103,7 +113,7 @@ export async function showAuthStatus(output, home = homedir()) {
103
113
  process.exitCode = 1;
104
114
  return;
105
115
  }
106
- const credential = (await readCredentials(home)).servers[result.server];
116
+ const credential = (await readCredentials(runtime)).servers[result.server];
107
117
  if (output.json) {
108
118
  write(json({
109
119
  signedIn: true,
@@ -133,6 +143,7 @@ export async function showAuthStatus(output, home = homedir()) {
133
143
  ? `expires ${new Date(credential.expiresAt).toLocaleString()}`
134
144
  : undefined,
135
145
  ],
136
- ]))
146
+ ])) {
137
147
  write(line);
148
+ }
138
149
  }
package/dist/ui/clash.js CHANGED
@@ -1,31 +1,35 @@
1
1
  import select from "@inquirer/select";
2
- import { originLabel, validInstalledName, } from "../features/environment/names.js";
2
+ import { originLabel } from "../features/server/origin.js";
3
3
  import { bold, dim, fields, warn } from "./format.js";
4
4
  import { promptTheme } from "./theme.js";
5
+ import { assetKinds } from "../features/asset-kinds/index.js";
5
6
  /** Asks once per clash; the sync persists the answer. */
6
7
  export async function promptClash(clash) {
7
- const noun = clash.kind === "skill" ? "Skills" : "MCP servers";
8
+ const noun = assetKinds[clash.kind].many;
8
9
  console.log("");
9
10
  console.log(`${warn("!")} Two ${noun} want the name ${bold(clash.name)}`);
10
11
  for (const line of fields([
11
12
  ["Installed", originLabel(clash.installed.origin)],
12
13
  ["New", originLabel(clash.incoming.origin)],
13
- ], 2))
14
+ ], 2)) {
14
15
  console.log(line);
16
+ }
15
17
  console.log("");
16
18
  const choices = [];
17
19
  if (clash.incoming.renamable !== false &&
18
- validInstalledName(clash.incomingRename))
20
+ assetKinds[clash.kind].validName(clash.incomingRename)) {
19
21
  choices.push({
20
22
  name: `Rename the new one to ${clash.incomingRename}`,
21
23
  value: "rename-incoming",
22
24
  });
25
+ }
23
26
  if (clash.installed.renamable !== false &&
24
- validInstalledName(clash.installedRename))
27
+ assetKinds[clash.kind].validName(clash.installedRename)) {
25
28
  choices.push({
26
29
  name: `Rename the installed one to ${clash.installedRename}`,
27
30
  value: "rename-installed",
28
31
  });
32
+ }
29
33
  choices.push({ name: "Don't install the new one", value: "skip-incoming" }, {
30
34
  name: "Replace the installed one with the new one",
31
35
  value: "replace-installed",
@@ -37,7 +41,7 @@ export async function promptClash(clash) {
37
41
  theme: promptTheme,
38
42
  });
39
43
  console.log(dim(" Saved. Change it later with barndog " +
40
- (clash.kind === "skill" ? "skills" : "mcp") +
44
+ assetKinds[clash.kind].command +
41
45
  " rename, enable or disable."));
42
46
  return choice;
43
47
  }