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
@@ -1,17 +1,69 @@
1
+ import { SHORT_COMMIT_LENGTH } from "../shared/constants.js";
1
2
  import { primary } from "./theme.js";
2
3
  import { renderSyncOutput } from "./output.js";
4
+ import { safe } from "./format.js";
3
5
  import { changeSchema } from "@barndog-ai/api-contract";
4
6
  import { textContent } from "@barndog-ai/api-contract/collaboration";
5
- // Remote package text must not be able to emit terminal control sequences.
6
- export function safe(value) {
7
- return String(value).replace(
8
- // eslint-disable-next-line no-control-regex
9
- /[\x00-\x08\x0b-\x1f\x7f-\x9f]/g, (c) => `\\u${c.charCodeAt(0).toString(16).padStart(4, "0")}`);
7
+ import { z } from "zod";
8
+ import { isRecord } from "../shared/values.js";
9
+ // The shapes below list only what this module prints; other fields pass through.
10
+ const filesSchema = z.array(z.looseObject({
11
+ path: z.string(),
12
+ content: z.string(),
13
+ executable: z.boolean().optional(),
14
+ }));
15
+ const detailsSchema = z.looseObject({
16
+ names: z.record(z.string(), z.string()).optional(),
17
+ baseVersionNumber: z.number().optional(),
18
+ });
19
+ const pushedSchema = z.looseObject({
20
+ branch: z.string(),
21
+ commit: z.string(),
22
+ published: z.boolean().optional(),
23
+ url: z.string().nullish(),
24
+ opened: z.boolean().optional(),
25
+ });
26
+ const statusSchema = z.looseObject({
27
+ root: z.string(),
28
+ name: z.string(),
29
+ baseVersion: z.number().nullable(),
30
+ baseCommit: z.string().optional(),
31
+ review: z
32
+ .looseObject({ branch: z.string(), url: z.string().nullable() })
33
+ .nullish(),
34
+ proposal: z.looseObject({ id: z.string(), revision: z.number() }).nullable(),
35
+ external: z
36
+ .looseObject({
37
+ pull: z.looseObject({ number: z.number(), head: z.string() }).nullable(),
38
+ })
39
+ .nullish(),
40
+ conflicts: z.array(z.string()),
41
+ pending: z.boolean(),
42
+ changes: z.array(z.unknown()),
43
+ });
44
+ const workingCopySchema = z.looseObject({
45
+ root: z.string(),
46
+ version: z.number().optional(),
47
+ baseVersion: z.number().nullish(),
48
+ commit: z.string().optional(),
49
+ conflicts: z.array(z.string()).optional(),
50
+ });
51
+ const isEnvironmentPreview = (value) => isRecord(value) &&
52
+ value.mode === "environment-preview" &&
53
+ Array.isArray(value.events);
54
+ /** A short commit hash, else `v<version>`, else nothing. */
55
+ function baseLabel(commit, version) {
56
+ if (commit) {
57
+ return commit.slice(0, SHORT_COMMIT_LENGTH);
58
+ }
59
+ return version ? `v${version}` : undefined;
10
60
  }
11
61
  function files(value) {
12
- if (!Array.isArray(value))
62
+ const parsed = filesSchema.safeParse(value);
63
+ if (!parsed.success) {
13
64
  return [];
14
- return value.flatMap((file) => {
65
+ }
66
+ return parsed.data.flatMap((file) => {
15
67
  const text = textContent(Buffer.from(file.content, "base64"));
16
68
  return [
17
69
  primary(`${safe(file.path)}${file.executable ? " (executable)" : ""}`),
@@ -21,30 +73,40 @@ function files(value) {
21
73
  }
22
74
  /** Mode changes are worth a mention; a new file having no old mode isn't. */
23
75
  function executableNote(previous, next) {
24
- if (previous === next || next === null || next === undefined)
76
+ if (previous === next || next === null || next === undefined) {
25
77
  return "";
26
- if (previous === null || previous === undefined)
78
+ }
79
+ if (previous === null || previous === undefined) {
27
80
  return next ? " executable" : "";
28
- return ` executable: ${previous} → ${next}`;
81
+ }
82
+ return ` executable: ${safe(previous)} → ${safe(next)}`;
29
83
  }
30
- export function renderCollaboration(action, value) {
84
+ /** Results are told apart by their shape, not by the command that produced them. */
85
+ export function renderCollaboration(value, options = {}) {
31
86
  if (Array.isArray(value)) {
32
- if (!value.length)
87
+ if (!value.length) {
33
88
  return ["No changes."];
89
+ }
34
90
  return value.flatMap((row) => {
35
- if (row && "patch" in row)
91
+ if (!isRecord(row)) {
92
+ return [safe(JSON.stringify(row, null, 2))];
93
+ }
94
+ if ("patch" in row) {
36
95
  return [
37
96
  `${safe(row.kind)} ${safe(row.path)}${row.binary ? " (binary)" : ""}${executableNote(row.oldExecutable, row.newExecutable)}`,
38
97
  safe(row.patch),
39
98
  ].filter(Boolean);
40
- if (row && "status" in row)
99
+ }
100
+ if ("status" in row) {
41
101
  return [
42
- `${safe(row.name)} ${safe(row.status)} revision ${row.revision}\n ${safe(row.id)} ${safe(row.title)}`,
102
+ `${safe(row.name)} ${safe(row.status)} revision ${safe(row.revision)}\n ${safe(row.id)} ${safe(row.title)}`,
43
103
  ];
44
- if (row && "number" in row)
104
+ }
105
+ if ("number" in row) {
45
106
  return [
46
- `v${row.number} ${row.commit}\n ${safe(row.description)} published by ${safe(row.publisherName ?? row.publishedBy)}`,
107
+ `v${safe(row.number)} ${safe(row.commit)}\n ${safe(row.description)} published by ${safe(row.publisherName ?? row.publishedBy)}`,
47
108
  ];
109
+ }
48
110
  return [safe(JSON.stringify(row, null, 2))];
49
111
  });
50
112
  }
@@ -55,38 +117,48 @@ export function renderCollaboration(action, value) {
55
117
  primary(`${change.status === "merged" ? "Published" : "Suggested Change"} ${change.id}`),
56
118
  safe(`${change.title} · ${change.status} · revision ${change.revision}`),
57
119
  ];
58
- if (action === "show") {
59
- const details = value;
120
+ if (options.details) {
121
+ const shown = detailsSchema.safeParse(value);
122
+ const details = shown.success ? shown.data : {};
60
123
  const person = (id) => safe(details.names?.[id] ?? id);
61
124
  rows.push(`Author: ${person(change.authorId)}`, `Base: ${details.baseVersionNumber ? `v${details.baseVersionNumber}` : (change.baseVersionId ?? "new package")}`);
62
- for (const review of change.reviews)
125
+ for (const review of change.reviews) {
63
126
  rows.push(`Review: ${review.decision} revision ${review.revision} ${person(review.developerId)}`);
127
+ }
64
128
  for (const thread of change.threads) {
65
129
  rows.push(`\nDiscussion ${thread.id} revision ${thread.revision}${thread.outdated ? " (outdated)" : ""}${thread.resolved ? " (resolved)" : ""}${thread.path ? ` ${safe(thread.path)}:${thread.startLine}-${thread.endLine} (${thread.side})` : ""}`);
66
- for (const comment of thread.comments)
130
+ for (const comment of thread.comments) {
67
131
  rows.push(` ${person(comment.authorId)}: ${safe(comment.body)}`);
68
- if (thread.replacement !== null)
132
+ }
133
+ if (thread.replacement !== null) {
69
134
  rows.push(" Suggested replacement:", safe(thread.replacement));
135
+ }
70
136
  }
71
- if (value && typeof value === "object" && "files" in value)
137
+ if (value && typeof value === "object" && "files" in value) {
72
138
  rows.push("", ...files(value.files));
139
+ }
73
140
  }
74
141
  return rows;
75
142
  }
76
143
  if (value && typeof value === "object") {
77
- if ("mode" in value &&
78
- value.mode === "environment-preview" &&
79
- "events" in value) {
80
- return renderSyncOutput(value.events, { title: "preview", preview: true });
144
+ if (isEnvironmentPreview(value)) {
145
+ return renderSyncOutput(value.events, {
146
+ title: "preview",
147
+ preview: true,
148
+ });
81
149
  }
82
- if ("files" in value)
150
+ if ("files" in value) {
83
151
  return files(value.files);
84
- if ("unchanged" in value)
152
+ }
153
+ if ("unchanged" in value) {
85
154
  return ["Package unchanged."];
86
- if ("branch" in value && "commit" in value) {
87
- const pushed = value;
88
- if (pushed.published)
155
+ }
156
+ const pushedResult = pushedSchema.safeParse(value);
157
+ if (pushedResult.success) {
158
+ const pushed = pushedResult.data;
159
+ if (pushed.published) {
89
160
  return [primary(`Pushed to ${safe(pushed.branch)}`), pushed.commit];
161
+ }
90
162
  return [
91
163
  primary(`Pushed ${safe(pushed.branch)}`),
92
164
  pushed.url
@@ -94,11 +166,12 @@ export function renderCollaboration(action, value) {
94
166
  : "Open a pull request from this branch on your Git host.",
95
167
  ];
96
168
  }
97
- if ("changes" in value && "root" in value) {
98
- const status = value;
169
+ const statusResult = statusSchema.safeParse(value);
170
+ if (statusResult.success) {
171
+ const status = statusResult.data;
99
172
  return [
100
173
  primary(`${safe(status.name)} ${safe(status.root)}`),
101
- `Base: ${status.baseCommit ? status.baseCommit.slice(0, 7) : status.baseVersion ? `v${status.baseVersion}` : "new package"}`,
174
+ `Base: ${baseLabel(status.baseCommit, status.baseVersion) ?? "new package"}`,
102
175
  ...(status.review
103
176
  ? [
104
177
  `Review branch: ${safe(status.review.branch)}${status.review.url ? ` ${safe(status.review.url)}` : ""}`,
@@ -118,25 +191,24 @@ export function renderCollaboration(action, value) {
118
191
  ? ["Submission awaiting confirmation; retry barndog push."]
119
192
  : []),
120
193
  ...status.conflicts.map((path) => `Conflict: ${safe(path)}`),
121
- ...renderCollaboration("diff", status.changes).filter((line) => !line.startsWith("@@") && !line.startsWith("+")),
194
+ ...renderCollaboration(status.changes).filter((line) => !line.startsWith("@@") && !line.startsWith("+")),
122
195
  ];
123
196
  }
124
- if ("root" in value) {
125
- const result = value;
197
+ const workingCopy = workingCopySchema.safeParse(value);
198
+ if (workingCopy.success) {
199
+ const result = workingCopy.data;
200
+ const base = baseLabel(result.commit, result.version || result.baseVersion);
126
201
  return [
127
202
  `Working copy: ${safe(result.root)}`,
128
- ...(result.commit
129
- ? [`Base: ${result.commit.slice(0, 7)}`]
130
- : result.version || result.baseVersion
131
- ? [`Base: v${result.version ?? result.baseVersion}`]
132
- : []),
203
+ ...(base ? [`Base: ${base}`] : []),
133
204
  ...(result.conflicts?.length
134
205
  ? result.conflicts.map((path) => `Conflict: ${safe(path)}; edit and run barndog resolve <path>.`)
135
206
  : []),
136
207
  ];
137
208
  }
138
- if ("resolved" in value)
209
+ if ("resolved" in value) {
139
210
  return [`Resolved: ${safe(value.resolved)}`];
211
+ }
140
212
  }
141
213
  return [safe(JSON.stringify(value, null, 2))];
142
214
  }
@@ -2,8 +2,11 @@ import input from "@inquirer/input";
2
2
  import select from "@inquirer/select";
3
3
  import { defaultServer } from "../config/build.js";
4
4
  import { normalizeServer } from "../features/auth/transport.js";
5
- import { checkRepositoryUrl } from "../features/git-workspace/git.js";
5
+ import { checkRepositoryUrl } from "../features/workspace/git.js";
6
6
  import { promptTheme } from "./theme.js";
7
+ /**
8
+ * Asks for the workspace URL, offering `current` or the build's default server.
9
+ */
7
10
  export async function promptServer(current) {
8
11
  return normalizeServer(await input({
9
12
  message: "BarnDog workspace URL (cloud or self-hosted)",
@@ -21,6 +24,7 @@ export async function promptServer(current) {
21
24
  theme: promptTheme,
22
25
  }).then((value) => value.trim()));
23
26
  }
27
+ /** Asks where to keep assets, defaulting to `current`. */
24
28
  export async function chooseConnection(current) {
25
29
  const kind = await select({
26
30
  loop: false,
@@ -45,13 +49,15 @@ export async function chooseConnection(current) {
45
49
  ],
46
50
  theme: promptTheme,
47
51
  });
48
- if (kind === "local")
52
+ if (kind === "local") {
49
53
  return { kind };
50
- if (kind === "cloud")
54
+ }
55
+ if (kind === "cloud") {
51
56
  return {
52
57
  kind,
53
58
  server: await promptServer(current?.kind === "cloud" ? current.server : undefined),
54
59
  };
60
+ }
55
61
  return {
56
62
  kind,
57
63
  url: (await input({
@@ -63,7 +69,7 @@ export async function chooseConnection(current) {
63
69
  return true;
64
70
  }
65
71
  catch (error) {
66
- return error.message;
72
+ return error instanceof Error ? error.message : String(error);
67
73
  }
68
74
  },
69
75
  theme: promptTheme,
@@ -80,9 +86,14 @@ export function chooseLocalAssets(count) {
80
86
  description: "They keep working next to the shared assets. Move them any time with barndog local move.",
81
87
  },
82
88
  {
83
- name: "Keep active, and move to the new workspace",
89
+ name: "Share a copy, and keep them here too",
90
+ value: "copy",
91
+ description: "The local ones stay as separate assets. Anything whose name is already taken is left out and listed.",
92
+ },
93
+ {
94
+ name: "Move them to the new workspace",
84
95
  value: "move",
85
- description: "Also shares them. Anything whose name is already taken is left out and listed.",
96
+ description: "The shared copies become the only ones; the local ones are removed once they exist. Anything whose name is already taken stays local and is listed.",
86
97
  },
87
98
  {
88
99
  name: "Stop using them",
@@ -0,0 +1,24 @@
1
+ import { CliError } from "../errors.js";
2
+ import { assetKinds } from "../features/asset-kinds/index.js";
3
+ /**
4
+ * A change that would undo exclusions or disables, run where nobody can be
5
+ * asked. It names every asset, so a `--decisions` file can be written for it;
6
+ * `--json` lists them under `decisions`.
7
+ */
8
+ export class DecisionRequiredError extends CliError {
9
+ decisions;
10
+ constructor(conflicts) {
11
+ const decisions = conflicts.map(({ asset }) => ({
12
+ assetId: asset.id,
13
+ kind: asset.kind,
14
+ name: asset.name,
15
+ }));
16
+ super([
17
+ "Existing exclusions or disabled assets need a decision:",
18
+ ...conflicts.map(({ asset }) => ` ${asset.name} (${assetKinds[asset.kind].one}) ${asset.id}`),
19
+ 'A --decisions file lists each one as {"assetId": "<id>", "choice": "preserve"} or "clear".',
20
+ ].join("\n"), "add --overrides preserve, --overrides clear or --decisions <file>");
21
+ this.name = "DecisionRequiredError";
22
+ this.decisions = decisions;
23
+ }
24
+ }
@@ -14,8 +14,15 @@ function sourceLabels(sources, describe) {
14
14
  const rows = sources.map(describe);
15
15
  const width = Math.max(...rows.map((row) => visibleWidth(row.name)));
16
16
  const detailWidth = Math.max(...rows.map((row) => visibleWidth(row.detail)));
17
- return sources.map((source, index) => `${rows[index].name.padEnd(width)} ${dim(rows[index].detail.padEnd(detailWidth))} ${dim(`${source.assets.length} ${source.assets.length === 1 ? "asset" : "assets"}`)}${source.scope.type === "org" ? ` ${dim("· suggested")}` : ""}`);
17
+ return sources.map((source) => {
18
+ const row = describe(source);
19
+ return `${row.name.padEnd(width)} ${dim(row.detail.padEnd(detailWidth))} ${dim(`${source.assets.length} ${source.assets.length === 1 ? "asset" : "assets"}`)}${source.scope.type === "org" ? ` ${dim("· suggested")}` : ""}`;
20
+ });
18
21
  }
22
+ /**
23
+ * Creates the interactive environment picker using the supplied output sink;
24
+ * returns selections without persisting them.
25
+ */
19
26
  export function environmentChooser(write) {
20
27
  return async (choices) => {
21
28
  const sources = onboardingSources(choices);
@@ -31,28 +38,40 @@ export function environmentChooser(write) {
31
38
  }
32
39
  const repoName = sources.find((s) => s.scope.type === "org")?.label ?? "";
33
40
  const folder = (source) => {
34
- if (source.scope.type === "org")
41
+ if (source.scope.type === "org") {
35
42
  return "org/";
43
+ }
36
44
  const slug = choices.scopes.find((s) => s.id === source.scope.id)?.slug;
37
45
  return `${source.scope.type === "team" ? "teams" : "repos"}/${slug}/`;
38
46
  };
39
47
  // A Git repo with only shared assets has nothing to choose between.
40
48
  const single = git && sources.length === 1;
41
- const titled = (source) => !git ? source.label : single ? repoName : folder(source);
42
- if (!git && !choices.catalog.assets.length)
49
+ const titled = (source) => {
50
+ if (!git) {
51
+ return source.label;
52
+ }
53
+ return single ? repoName : folder(source);
54
+ };
55
+ if (!git && !choices.catalog.assets.length) {
43
56
  write("No published assets are available yet. Add assets in the web workspace when you're ready.");
44
- if (!single)
57
+ }
58
+ if (!single) {
45
59
  write("Choose where this machine's Skills, MCP servers and Hooks come from. Anything you leave unchecked is removed.");
60
+ }
46
61
  if (choices.developerId !== null &&
47
62
  choices.firstSetup &&
48
- choices.memberTeamIds.length === 1)
63
+ choices.memberTeamIds.length === 1) {
49
64
  write(dim("Your team is preselected."));
50
- if (choices.developerId !== null && choices.memberTeamIds.length > 1)
65
+ }
66
+ if (choices.developerId !== null && choices.memberTeamIds.length > 1) {
51
67
  write(dim("You belong to several teams; choose the ones you work with."));
52
- if (!single)
68
+ }
69
+ if (!single) {
53
70
  write(dim(`Later: barndog sets switch team/<slug> or repo/<slug>, barndog sets install repo/<slug>.`));
54
- if (!single)
71
+ }
72
+ if (!single) {
55
73
  write("");
74
+ }
56
75
  const labels = sourceLabels(sources, (source) => git
57
76
  ? {
58
77
  name: source.scope.type === "org" ? "Everyone" : source.label,
@@ -67,7 +86,7 @@ export function environmentChooser(write) {
67
86
  ? `What should this machine install from ${repoName}?`
68
87
  : "Which sources would you like to include?",
69
88
  choices: sources.map((source, index) => ({
70
- name: labels[index],
89
+ name: labels[index] ?? titled(source),
71
90
  short: titled(source),
72
91
  value: source,
73
92
  checked: source.checked,
@@ -95,8 +114,9 @@ export function environmentChooser(write) {
95
114
  let assetIds;
96
115
  if (mode === "custom") {
97
116
  const width = Math.max(0, ...source.assets.map((a) => a.name.length));
98
- if (source.assets.length)
117
+ if (source.assets.length) {
99
118
  write("");
119
+ }
100
120
  assetIds = source.assets.length
101
121
  ? await checkbox({
102
122
  loop: false,
@@ -112,12 +132,14 @@ export function environmentChooser(write) {
112
132
  })
113
133
  : [];
114
134
  }
115
- if (!source.assets.length)
135
+ if (!source.assets.length) {
116
136
  write(dim(`No published assets in ${titled(source)} yet.`));
137
+ }
117
138
  if (source.scope.type === "dev" &&
118
139
  mode === "recommended" &&
119
- !source.recommendedIds.length)
140
+ !source.recommendedIds.length) {
120
141
  write(dim("None of your personal assets are marked recommended in an organization or team set."));
142
+ }
121
143
  selections.push({ source, mode, assetIds });
122
144
  }
123
145
  return selectOnboardingSources(selections);
package/dist/ui/format.js CHANGED
@@ -1,7 +1,27 @@
1
1
  import { stripVTControlCharacters, styleText } from "node:util";
2
- import { safe } from "./collaboration.js";
3
2
  import { danger, primary, selected } from "./theme.js";
3
+ import { CONSTANT_CASE } from "../shared/patterns.js";
4
+ import { isRecord } from "../shared/values.js";
5
+ import { HEX_RADIX } from "../shared/constants.js";
6
+ /** Keep the flexible table column readable when shrinking to terminal width. */
7
+ const MIN_FLEX_COLUMN_WIDTH = 8;
8
+ /** JavaScript Unicode escapes encode a UTF-16 code unit with four hex digits. */
9
+ const UNICODE_ESCAPE_DIGITS = 4;
10
+ /** C0 and C1 control characters other than tab and line feed, such as ESC (`\x1b`). */
11
+ // eslint-disable-next-line no-control-regex -- finding control characters is the point
12
+ const CONTROL_CHARACTERS = /[\x00-\x08\x0b-\x1f\x7f-\x9f]/g;
13
+ /**
14
+ * Remote package text must not be able to emit terminal control sequences:
15
+ * `"\x1b[31mred"` → `"\\u001b[31mred"`.
16
+ */
17
+ export function safe(value) {
18
+ return String(value).replace(CONTROL_CHARACTERS, (c) => `\\u${c.charCodeAt(0).toString(HEX_RADIX).padStart(UNICODE_ESCAPE_DIGITS, "0")}`);
19
+ }
4
20
  const paint = (style, text) => styleText(style, text, { stream: process.stdout });
21
+ /**
22
+ * Emphasis for commands, names and values, using Node's stream-aware color
23
+ * policy for stdout.
24
+ */
5
25
  export const bold = (text) => paint("bold", text);
6
26
  export const dim = (text) => paint("dim", text);
7
27
  export const warn = (text) => paint("yellow", text);
@@ -11,20 +31,28 @@ export const bad = (text) => danger(text);
11
31
  export function clean(value) {
12
32
  return safe(value).replace(/\s+/g, " ").trim();
13
33
  }
34
+ /**
35
+ * Counts Unicode code points after stripping terminal control sequences. This
36
+ * is a layout approximation, not the display-cell width of wide characters or
37
+ * emoji.
38
+ */
14
39
  export function visibleWidth(text) {
15
40
  return [...stripVTControlCharacters(text)].length;
16
41
  }
17
42
  function pad(text, width) {
18
43
  return text + " ".repeat(Math.max(0, width - visibleWidth(text)));
19
44
  }
45
+ /** One SGR style code, such as `\u001b[1m` (bold) or `\u001b[38;2;197;72;54m`; captured so `split` keeps it. */
20
46
  // eslint-disable-next-line no-control-regex -- matches terminal style codes
21
- const STYLE_CODE = new RegExp("(\\u001b\\[[0-9;]*m)");
47
+ const STYLE_CODE = /(\u001b\[[\d;]*m)/;
22
48
  function truncate(text, width) {
23
49
  const plain = stripVTControlCharacters(text);
24
- if ([...plain].length <= width)
50
+ if ([...plain].length <= width) {
25
51
  return text;
26
- if (width <= 1)
52
+ }
53
+ if (width <= 1) {
27
54
  return "…";
55
+ }
28
56
  // Every style code is kept, so a cut cell looks like the uncut ones.
29
57
  let room = width - 1;
30
58
  let cut = false;
@@ -34,8 +62,9 @@ function truncate(text, width) {
34
62
  output += part;
35
63
  continue;
36
64
  }
37
- if (cut)
65
+ if (cut) {
38
66
  continue;
67
+ }
39
68
  const characters = [...part];
40
69
  if (characters.length <= room) {
41
70
  output += part;
@@ -47,12 +76,17 @@ function truncate(text, width) {
47
76
  }
48
77
  return output;
49
78
  }
79
+ /**
80
+ * A command's title line: the brand name in the primary color, then `title` in
81
+ * bold.
82
+ */
50
83
  export function heading(title) {
51
84
  return `${primary(bold("BarnDog"))} ${bold(title)}`;
52
85
  }
53
86
  export function section(title) {
54
87
  return bold(title);
55
88
  }
89
+ /** A `Next:`, `Fix:` or `Tip:` line suggesting a command to run. */
56
90
  export function hint(command, label = "Next") {
57
91
  return `${dim(`${label}:`)} ${bold(command)}`;
58
92
  }
@@ -68,8 +102,9 @@ export function table(rows, options = {}) {
68
102
  const all = options.header
69
103
  ? [options.header.map((cell) => dim(cell)), ...rows]
70
104
  : [...rows];
71
- if (!all.length)
105
+ if (!all.length) {
72
106
  return [];
107
+ }
73
108
  const count = Math.max(...all.map((row) => row.length));
74
109
  const widths = Array.from({ length: count }, (_, column) => Math.max(0, ...all.map((row) => visibleWidth(row[column] ?? ""))));
75
110
  const flex = options.flex ?? count - 1;
@@ -77,8 +112,9 @@ export function table(rows, options = {}) {
77
112
  indent.length -
78
113
  (count - 1) * 2;
79
114
  const total = widths.reduce((sum, width) => sum + width, 0);
80
- if (total > available && widths[flex] !== undefined)
81
- widths[flex] = Math.max(8, widths[flex] - (total - available));
115
+ if (total > available && widths[flex] !== undefined) {
116
+ widths[flex] = Math.max(MIN_FLEX_COLUMN_WIDTH, widths[flex] - (total - available));
117
+ }
82
118
  return all.map((row) => (indent +
83
119
  widths
84
120
  .map((width, column) => {
@@ -88,6 +124,7 @@ export function table(rows, options = {}) {
88
124
  })
89
125
  .join(" ")).trimEnd());
90
126
  }
127
+ /** Known states get a color; any other text shows as it is. */
91
128
  export function badge(state, label = state) {
92
129
  switch (state) {
93
130
  case "installed":
@@ -105,14 +142,20 @@ export function badge(state, label = state) {
105
142
  return dim(label);
106
143
  }
107
144
  }
108
- export { originLabel } from "../features/environment/names.js";
145
+ export { originLabel } from "../features/server/origin.js";
146
+ /** `1 skill`, `2 skills`; pass `many` for irregular plurals. */
109
147
  export function plural(count, noun, many = `${noun}s`) {
110
148
  return `${count} ${count === 1 ? noun : many}`;
111
149
  }
150
+ /** `up_to_date` → `Up to date`: a server or state code as a label. */
112
151
  export function humanize(value) {
113
152
  const text = value.replaceAll("_", " ");
114
- return text[0].toUpperCase() + text.slice(1);
153
+ return text.charAt(0).toUpperCase() + text.slice(1);
115
154
  }
155
+ /**
156
+ * The `--json` rendering of a result: two-space indented JSON, without a
157
+ * trailing newline.
158
+ */
116
159
  export function json(value) {
117
160
  return JSON.stringify(value, null, 2);
118
161
  }
@@ -121,27 +164,32 @@ const isPlain = (value) => value === null || ["string", "number", "boolean"].inc
121
164
  const show = (value) => value === null || value === undefined ? dim("—") : clean(value);
122
165
  const label = (key) =>
123
166
  // Environment variable names are data, not field labels.
124
- /^[A-Z][A-Z0-9_]*$/.test(key)
167
+ CONSTANT_CASE.test(key)
125
168
  ? key
126
169
  : humanize(key.replace(/([a-z])([A-Z])/g, "$1 $2").toLowerCase());
127
170
  /** Readable fallback for structured results: key/value blocks and tables. */
128
171
  export function renderValue(value, indent = 0) {
129
- if (isPlain(value))
172
+ if (isPlain(value)) {
130
173
  return [`${" ".repeat(indent)}${show(value)}`];
174
+ }
131
175
  if (Array.isArray(value)) {
132
- if (!value.length)
176
+ if (!value.length) {
133
177
  return [`${" ".repeat(indent)}${dim("None.")}`];
134
- if (value.every((row) => row && typeof row === "object" && !Array.isArray(row))) {
135
- const keys = Object.keys(value[0]).filter((key) => value.every((row) => isPlain(row[key])));
136
- if (keys.length)
137
- return table(value.map((row) => keys.map((key) => show(row[key]))), { header: keys.map(label), indent: indent + 2 });
178
+ }
179
+ const rows = value.filter(isRecord);
180
+ const [first] = rows;
181
+ if (first && rows.length === value.length) {
182
+ const keys = Object.keys(first).filter((key) => rows.every((row) => isPlain(row[key])));
183
+ if (keys.length) {
184
+ return table(rows.map((row) => keys.map((key) => show(row[key]))), { header: keys.map(label), indent: indent + 2 });
185
+ }
138
186
  }
139
187
  return value.flatMap((row, index) => [
140
188
  ...(index ? [""] : []),
141
189
  ...renderValue(row, indent),
142
190
  ]);
143
191
  }
144
- const entries = Object.entries(value);
192
+ const entries = Object.entries(isRecord(value) ? value : {});
145
193
  const simple = entries.filter(([, v]) => isPlain(v));
146
194
  const nested = entries.filter(([, v]) => !isPlain(v) && v !== undefined);
147
195
  return [
@@ -0,0 +1,18 @@
1
+ import checkbox from "@inquirer/checkbox";
2
+ import { checkboxTheme, selected } from "./theme.js";
3
+ import { dim } from "./format.js";
4
+ export const chooseHarnesses = (choices) => {
5
+ const width = Math.max(...choices.map((choice) => choice.name.length));
6
+ return checkbox({
7
+ loop: false,
8
+ message: "Which coding tools should BarnDog manage?",
9
+ choices: choices.map((choice) => ({
10
+ value: choice.value,
11
+ checked: choice.checked,
12
+ short: choice.name,
13
+ name: `${choice.name.padEnd(width)} ${choice.evidence ? selected("detected") : dim("not found")}`,
14
+ description: choice.evidence ?? undefined,
15
+ })),
16
+ theme: checkboxTheme,
17
+ });
18
+ };