barndog 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (173) hide show
  1. package/README.md +11 -10
  2. package/dist/cli.js +11 -7
  3. package/dist/commands/add.js +33 -21
  4. package/dist/commands/arguments.js +12 -0
  5. package/dist/commands/asset-install.js +160 -0
  6. package/dist/commands/asset-list.js +121 -0
  7. package/dist/commands/asset-share.js +94 -0
  8. package/dist/commands/auth.js +4 -0
  9. package/dist/commands/availability.js +54 -26
  10. package/dist/commands/capabilities.js +71 -415
  11. package/dist/commands/collaboration.js +194 -110
  12. package/dist/commands/environment.js +18 -411
  13. package/dist/commands/github.js +200 -0
  14. package/dist/commands/helpers.js +39 -0
  15. package/dist/commands/hooks.js +87 -0
  16. package/dist/commands/init.js +4 -2
  17. package/dist/commands/knowledge.js +73 -0
  18. package/dist/commands/mcp.js +62 -0
  19. package/dist/commands/origin.js +21 -23
  20. package/dist/commands/people.js +51 -0
  21. package/dist/commands/sets.js +141 -0
  22. package/dist/commands/status.js +34 -24
  23. package/dist/commands/sync.js +11 -4
  24. package/dist/commands/workspace.js +33 -19
  25. package/dist/config/environment.js +13 -27
  26. package/dist/config/paths.js +62 -0
  27. package/dist/config/selection.js +30 -0
  28. package/dist/config/settings.js +97 -108
  29. package/dist/config/state.js +57 -57
  30. package/dist/entry/knowledge-startup.js +32 -0
  31. package/dist/entry/mcp-launch.js +71 -0
  32. package/dist/entry/opencode-plugin.js +62 -0
  33. package/dist/{features/git-workspace/startup.js → entry/workspace-startup.js} +7 -2
  34. package/dist/errors.js +198 -55
  35. package/dist/features/asset-kinds/index.js +120 -0
  36. package/dist/features/asset-selection/index.js +51 -19
  37. package/dist/features/auth/credentials.js +80 -47
  38. package/dist/features/auth/session.js +80 -45
  39. package/dist/features/auth/transport.js +66 -15
  40. package/dist/features/catalog/index.js +32 -61
  41. package/dist/features/collaboration/api.js +160 -0
  42. package/dist/features/collaboration/index.js +321 -233
  43. package/dist/features/collaboration/remote.js +35 -115
  44. package/dist/features/collaboration/results.js +2 -0
  45. package/dist/features/collaboration/workspace-git.js +233 -149
  46. package/dist/features/collaboration/workspace-github.js +117 -54
  47. package/dist/features/collaboration/workspace-store.js +140 -100
  48. package/dist/features/collaboration/workspace.js +257 -172
  49. package/dist/features/discovery/index.js +68 -57
  50. package/dist/features/doctor/index.js +32 -24
  51. package/dist/features/environment/auto-sync.js +28 -27
  52. package/dist/features/environment/names.js +67 -47
  53. package/dist/features/environment/operations.js +321 -228
  54. package/dist/features/environment/own-entries.js +89 -0
  55. package/dist/features/environment/settle-names.js +91 -0
  56. package/dist/features/environment/stage.js +178 -0
  57. package/dist/features/environment/sync.js +113 -484
  58. package/dist/features/environment/transaction.js +179 -147
  59. package/dist/features/environment/writes.js +196 -0
  60. package/dist/features/github/account.js +25 -0
  61. package/dist/features/github/connections.js +119 -0
  62. package/dist/features/github/pulls.js +118 -0
  63. package/dist/features/hooks/adapt.js +32 -25
  64. package/dist/features/hooks/catalog.js +28 -0
  65. package/dist/features/hooks/compatibility.js +49 -0
  66. package/dist/features/hooks/divergence.js +9 -6
  67. package/dist/features/hooks/test.js +74 -49
  68. package/dist/features/hooks/types.js +1 -0
  69. package/dist/features/imports/discover.js +134 -61
  70. package/dist/features/imports/folder.js +48 -14
  71. package/dist/features/imports/local.js +113 -134
  72. package/dist/features/imports/remote.js +44 -25
  73. package/dist/features/inspection/index.js +17 -17
  74. package/dist/features/inventory/index.js +99 -110
  75. package/dist/features/knowledge/index.js +69 -49
  76. package/dist/features/mcps/catalog.js +31 -0
  77. package/dist/features/mcps/import.js +316 -0
  78. package/dist/features/mcps/index.js +98 -49
  79. package/dist/features/migration/migrate.js +263 -0
  80. package/dist/features/{git-workspace → migration}/move.js +165 -109
  81. package/dist/features/migration/promote.js +24 -0
  82. package/dist/features/native/adapters.js +53 -94
  83. package/dist/features/native/configuration.js +128 -82
  84. package/dist/features/native/hook-shell.js +55 -0
  85. package/dist/features/native/plugin-module.js +56 -0
  86. package/dist/features/onboarding/environment.js +67 -34
  87. package/dist/features/onboarding/setup.js +43 -40
  88. package/dist/features/repositories/context.js +30 -13
  89. package/dist/features/server/catalog.js +58 -0
  90. package/dist/features/server/client.js +13 -0
  91. package/dist/features/server/connection.js +37 -0
  92. package/dist/features/server/origin.js +74 -0
  93. package/dist/features/server/pages.js +24 -0
  94. package/dist/features/skills/catalog.js +42 -0
  95. package/dist/features/workspace/assets.js +57 -0
  96. package/dist/features/workspace/cloud-source.js +34 -0
  97. package/dist/features/workspace/directory.js +38 -0
  98. package/dist/features/{git-workspace → workspace}/format.js +114 -51
  99. package/dist/features/workspace/git.js +214 -0
  100. package/dist/features/workspace/installed.js +92 -0
  101. package/dist/features/{git-workspace → workspace}/overlay.js +43 -23
  102. package/dist/features/workspace/packages.js +160 -0
  103. package/dist/features/{git-workspace → workspace}/publish.js +120 -64
  104. package/dist/features/workspace/repo-source.js +192 -0
  105. package/dist/features/{git-workspace → workspace}/setup.js +60 -42
  106. package/dist/features/{git-workspace → workspace}/snapshot.js +53 -18
  107. package/dist/features/workspace/source.js +1 -0
  108. package/dist/features/workspace/tree.js +52 -0
  109. package/dist/features/workspace/workspace-source.js +27 -0
  110. package/dist/harnesses/claude.js +23 -1
  111. package/dist/harnesses/codex.js +57 -1
  112. package/dist/harnesses/cursor.js +22 -1
  113. package/dist/harnesses/detect.js +6 -50
  114. package/dist/harnesses/formats.js +45 -0
  115. package/dist/harnesses/opencode.js +111 -0
  116. package/dist/harnesses/registry.js +35 -2
  117. package/dist/platform.js +375 -0
  118. package/dist/program.js +225 -54
  119. package/dist/runtime.js +1 -0
  120. package/dist/shared/cli-error.js +22 -0
  121. package/dist/shared/constants.js +32 -0
  122. package/dist/shared/files.js +72 -0
  123. package/dist/shared/lock.js +49 -0
  124. package/dist/shared/lookup.js +11 -0
  125. package/dist/shared/patterns.js +94 -0
  126. package/dist/shared/shell.js +22 -0
  127. package/dist/shared/values.js +26 -0
  128. package/dist/ui/add-asset.js +41 -400
  129. package/dist/ui/add-hook.js +213 -0
  130. package/dist/ui/add-mcp.js +107 -0
  131. package/dist/ui/add-prompts.js +47 -0
  132. package/dist/ui/add-skills.js +115 -0
  133. package/dist/ui/asset-list.js +31 -13
  134. package/dist/ui/assets.js +33 -44
  135. package/dist/ui/auth.js +43 -33
  136. package/dist/ui/clash.js +11 -6
  137. package/dist/ui/collaboration.js +116 -44
  138. package/dist/ui/connection.js +10 -4
  139. package/dist/ui/decision-error.js +24 -0
  140. package/dist/ui/environment-onboarding.js +35 -13
  141. package/dist/ui/format.js +66 -18
  142. package/dist/ui/hook-compatibility.js +14 -6
  143. package/dist/ui/mcp.js +28 -3
  144. package/dist/ui/move.js +10 -5
  145. package/dist/ui/onboarding.js +113 -73
  146. package/dist/ui/options.js +9 -0
  147. package/dist/ui/output.js +106 -43
  148. package/dist/ui/pick.js +45 -33
  149. package/dist/ui/scope-install.js +15 -7
  150. package/dist/ui/selection.js +15 -11
  151. package/dist/ui/theme.js +37 -14
  152. package/dist/version.js +6 -3
  153. package/package.json +24 -11
  154. package/dist/features/capabilities/index.js +0 -106
  155. package/dist/features/collaboration/domain.js +0 -90
  156. package/dist/features/environment/cloud-source.js +0 -27
  157. package/dist/features/environment/installed.js +0 -124
  158. package/dist/features/environment/packages.js +0 -120
  159. package/dist/features/environment/remote.js +0 -71
  160. package/dist/features/environment/workspace-source.js +0 -19
  161. package/dist/features/git-hosts/index.js +0 -148
  162. package/dist/features/git-workspace/assets.js +0 -71
  163. package/dist/features/git-workspace/git.js +0 -135
  164. package/dist/features/git-workspace/migrate.js +0 -188
  165. package/dist/features/git-workspace/source.js +0 -159
  166. package/dist/features/imports/mcp.js +0 -219
  167. package/dist/features/knowledge/startup.js +0 -25
  168. package/dist/features/native/mcp-launch.js +0 -57
  169. package/dist/features/skills/install.js +0 -25
  170. package/dist/features/skills/remote.js +0 -177
  171. package/dist/features/skills/sync.js +0 -121
  172. package/dist/features/skills/validation.js +0 -34
  173. /package/dist/features/environment/{source.js → events.js} +0 -0
@@ -1,55 +1,65 @@
1
1
  import { randomBytes } from "node:crypto";
2
- import { homedir } from "node:os";
3
2
  import { basename } from "node:path";
4
- import { knowledgeIndexSchema, scopeSchema } from "@barndog-ai/api-contract";
3
+ import { knowledgeIndexSchema, } from "@barndog-ai/api-contract";
5
4
  import { stringify } from "yaml";
6
- import { z } from "zod";
7
5
  import { readSettings, SetupRequiredError, } from "../../config/settings.js";
8
6
  import { CliError, friendlyMessage } from "../../errors.js";
9
- import { connection, matchesOrigin, selectOrigin, } from "../collaboration/remote.js";
7
+ import { matchesOrigin, selectOrigin, scopes } from "../server/origin.js";
8
+ import { connection } from "../server/connection.js";
10
9
  import { selectScope } from "../collaboration/workspace-git.js";
11
- import { renameSkillEntries } from "../environment/installed.js";
12
- import { originLabel } from "../environment/names.js";
13
- import { environmentCatalog, request } from "../environment/remote.js";
10
+ import { renameSkillEntries } from "../workspace/installed.js";
11
+ import { originLabel } from "../server/origin.js";
12
+ import { environmentCatalog } from "../server/catalog.js";
13
+ import { parsed } from "../server/client.js";
14
14
  import { synchronize } from "../environment/sync.js";
15
15
  import { locked } from "../environment/transaction.js";
16
- import { assetFolder, stableId } from "./format.js";
17
- import { checkRepositoryUrl, cloneOrigin, git } from "./git.js";
18
- import { connectGitWorkspace, createGitWorkspace, inspectRepository, } from "./setup.js";
19
- import { LoginRequiredError, normalizeServer } from "../auth/transport.js";
20
- import { connectionContext } from "../skills/remote.js";
16
+ import { assetPath, stableId } from "../workspace/format.js";
17
+ import { checkRepositoryUrl, cloneOrigin, git } from "../workspace/git.js";
18
+ import { connectGitWorkspace, createGitWorkspace, inspectRepository, } from "../workspace/setup.js";
19
+ import { LoginRequiredError, normalizeServer, apiClient, } from "../auth/transport.js";
20
+ import { connectionContext } from "../auth/session.js";
21
21
  import { publishKnowledge, publishMcp, publishPackage } from "./migrate.js";
22
- import { readMoved, recordMoved } from "./overlay.js";
23
- import { commitFiles, openPullRequest, pushCommit } from "./publish.js";
24
- import { acceptedCommit, gitDirectory, gitRepoSource, localRepoSource, recordFetch, trackingRef, } from "./source.js";
22
+ import { readMoved, recordMoved } from "../workspace/overlay.js";
23
+ import { commitFiles, openPullRequest, pushCommit, } from "../workspace/publish.js";
24
+ import { acceptedCommit, gitRepoSource, localRepoSource, recordFetch, trackingRef, } from "../workspace/repo-source.js";
25
+ import { defined } from "../../shared/lookup.js";
26
+ import { setYamlName } from "../../shared/patterns.js";
27
+ import { barndogPaths } from "../../config/paths.js";
28
+ import { PAGE_SIZE } from "../server/pages.js";
29
+ /** Three random bytes distinguish temporary move branches. */
30
+ const MOVE_BRANCH_RANDOM_BYTES = 3;
31
+ const knowledgeOf = (item) => defined(item.content, `${item.name} has no knowledge content`);
25
32
  /** A one-off destination: nothing about this machine's own setup changes. */
26
- async function repoDestination(value, home) {
27
- const url = checkRepositoryUrl(await cloneOrigin(value));
28
- const head = await inspectRepository(url);
33
+ async function repoDestination(value, runtime) {
34
+ const url = checkRepositoryUrl(await cloneOrigin(value, runtime));
35
+ const head = await inspectRepository(url, runtime);
29
36
  return head
30
- ? connectGitWorkspace(url, head.branch, home)
31
- : createGitWorkspace(url, basename(url).replace(/\.git$/, "") || "Workspace", home);
37
+ ? connectGitWorkspace(url, head.branch, runtime)
38
+ : createGitWorkspace(url, basename(url).replace(/\.git$/, "") || "Workspace", runtime);
32
39
  }
33
- async function serverDestination(value, home) {
40
+ async function serverDestination(value, runtime) {
34
41
  const server = normalizeServer(value);
35
42
  try {
36
- return await connectionContext(server, home);
43
+ return await connectionContext(server, runtime);
37
44
  }
38
45
  catch (error) {
39
- if (error instanceof LoginRequiredError)
46
+ if (error instanceof LoginRequiredError) {
40
47
  throw new CliError(`Sign in to ${server} first. This machine stays local.`, `barndog login --server ${server}`, { cause: error });
48
+ }
41
49
  throw error;
42
50
  }
43
51
  }
44
52
  function renamed(asset, name) {
45
- if (asset.name === name)
53
+ if (asset.name === name) {
46
54
  return asset.entries;
47
- if (asset.kind === "skill")
55
+ }
56
+ if (asset.kind === "skill") {
48
57
  return renameSkillEntries(asset.entries, name);
58
+ }
49
59
  return asset.entries.map((entry) => entry.path === "hook.yaml"
50
60
  ? {
51
61
  ...entry,
52
- data: Buffer.from(entry.data.toString("utf8").replace(/^name:.*$/m, `name: ${name}`)),
62
+ data: Buffer.from(setYamlName(entry.data.toString("utf8"), name)),
53
63
  }
54
64
  : entry);
55
65
  }
@@ -62,8 +72,9 @@ async function candidates(overlay, names, as, kind) {
62
72
  for (const asset of model.assets) {
63
73
  if (!pending(asset.path) ||
64
74
  (names?.length && !names.includes(asset.name)) ||
65
- (kind && asset.kind !== kind))
75
+ (kind && asset.kind !== kind)) {
66
76
  continue;
77
+ }
67
78
  if (asset.invalid) {
68
79
  invalid.push({
69
80
  kind: asset.kind,
@@ -86,8 +97,9 @@ async function candidates(overlay, names, as, kind) {
86
97
  }
87
98
  for (const doc of model.knowledge) {
88
99
  if (!pending(doc.path) ||
89
- (names?.length && !names.includes(doc.content.name)))
100
+ (names?.length && !names.includes(doc.content.name))) {
90
101
  continue;
102
+ }
91
103
  const name = as ?? doc.content.name;
92
104
  items.push({
93
105
  kind: "knowledge",
@@ -99,29 +111,55 @@ async function candidates(overlay, names, as, kind) {
99
111
  content: { ...doc.content, name },
100
112
  });
101
113
  }
102
- for (const name of names ?? [])
114
+ for (const name of names ?? []) {
103
115
  if (!items.some((item) => item.path.includes(`/${name}`)) &&
104
- !invalid.some((row) => row.name === name))
116
+ !invalid.some((row) => row.name === name)) {
105
117
  throw new CliError(`No local asset named ${name}.`, "barndog local list");
118
+ }
119
+ }
106
120
  return { items, invalid };
107
121
  }
108
122
  function knowledgeFile(content) {
109
123
  const { description, tags, accessMode, markdown } = content;
110
124
  return `---\n${stringify({ description, tags, accessMode })}---\n${markdown}`;
111
125
  }
112
- async function moveToGit(workspace, items, to, home) {
113
- const shared = await gitRepoSource(workspace, home).model();
114
- const tip = (await acceptedCommit(workspace.workspaceId, home));
126
+ /** The files a candidate becomes in a Git workspace, under `path`. */
127
+ function candidateFiles(item, path) {
128
+ if (item.kind === "knowledge") {
129
+ return [
130
+ {
131
+ path,
132
+ data: Buffer.from(knowledgeFile(knowledgeOf(item))),
133
+ executable: false,
134
+ },
135
+ ];
136
+ }
137
+ if (item.kind === "mcp") {
138
+ return [
139
+ {
140
+ path,
141
+ data: Buffer.from(stringify(item.definition)),
142
+ executable: false,
143
+ },
144
+ ];
145
+ }
146
+ return item.entries.map((entry) => ({
147
+ ...entry,
148
+ path: `${path}/${entry.path}`,
149
+ }));
150
+ }
151
+ async function moveToGit(workspace, items, to, runtime) {
152
+ const { home } = runtime;
153
+ const shared = await gitRepoSource(workspace, runtime).model();
154
+ const tip = defined(await acceptedCommit(workspace.workspaceId, runtime), "This Git workspace hasn't been fetched yet");
115
155
  const scope = selectScope(shared, to ?? "org");
116
- const repo = gitDirectory(workspace.workspaceId, home);
156
+ const repo = barndogPaths(home).bareClone(workspace.workspaceId);
117
157
  const rows = [];
118
158
  const moving = [];
119
159
  for (const item of items) {
120
160
  const path = item.kind === "knowledge"
121
161
  ? `org/knowledge/${item.name}.md`
122
- : item.kind === "mcp"
123
- ? `${scope.path}/mcp/${item.name}.yaml`
124
- : assetFolder(scope.path, item.kind, item.name);
162
+ : assetPath(scope.path, item.kind, item.name);
125
163
  if (shared.assets.some((asset) => asset.path === path) ||
126
164
  shared.knowledge.some((doc) => doc.path === path)) {
127
165
  rows.push({
@@ -134,26 +172,7 @@ async function moveToGit(workspace, items, to, home) {
134
172
  }
135
173
  moving.push({
136
174
  item,
137
- files: item.kind === "knowledge"
138
- ? [
139
- {
140
- path,
141
- data: Buffer.from(knowledgeFile(item.content)),
142
- executable: false,
143
- },
144
- ]
145
- : item.kind === "mcp"
146
- ? [
147
- {
148
- path,
149
- data: Buffer.from(stringify(item.definition)),
150
- executable: false,
151
- },
152
- ]
153
- : item.entries.map((entry) => ({
154
- ...entry,
155
- path: `${path}/${entry.path}`,
156
- })),
175
+ files: candidateFiles(item, path),
157
176
  });
158
177
  }
159
178
  const result = {
@@ -161,27 +180,39 @@ async function moveToGit(workspace, items, to, home) {
161
180
  rows,
162
181
  originId: stableId(workspace.workspaceId, "scope", scope.type, ...(scope.type === "org" ? [] : [scope.slug])),
163
182
  };
164
- if (!moving.length)
183
+ if (!moving.length) {
165
184
  return result;
185
+ }
166
186
  const title = `Move ${moving.length} local asset${moving.length === 1 ? "" : "s"} into the workspace`;
167
- const commit = await commitFiles(repo, tip, { files: moving.flatMap((entry) => entry.files) }, title);
187
+ const commit = await commitFiles(repo, tip, {
188
+ files: moving.flatMap((entry) => entry.files),
189
+ message: title,
190
+ }, { ...{}, runtime });
168
191
  // A workspace with nothing in it has nothing to review against.
169
192
  if (!shared.assets.length && !shared.knowledge.length) {
170
- await pushCommit(repo, commit, workspace.branch);
171
- await git(["update-ref", trackingRef(workspace.branch), commit], { repo });
172
- await recordFetch(workspace, commit, home);
193
+ await pushCommit(repo, commit, workspace.branch, {
194
+ runtime,
195
+ allowPrompt: false,
196
+ });
197
+ await git(["update-ref", trackingRef(workspace.branch), commit], runtime, {
198
+ repo,
199
+ });
200
+ await recordFetch(workspace, commit, runtime);
173
201
  result.direct = true;
174
202
  result.branch = workspace.branch;
175
203
  }
176
204
  else {
177
- const branch = `barndog/local-move-${randomBytes(3).toString("hex")}`;
178
- await pushCommit(repo, commit, branch);
205
+ const branch = `barndog/local-move-${randomBytes(MOVE_BRANCH_RANDOM_BYTES).toString("hex")}`;
206
+ await pushCommit(repo, commit, branch, {
207
+ runtime,
208
+ allowPrompt: false,
209
+ });
179
210
  const opened = await openPullRequest({
180
211
  url: workspace.url,
181
212
  base: workspace.branch,
182
213
  branch,
183
214
  title,
184
- });
215
+ }, runtime);
185
216
  result.branch = branch;
186
217
  result.url = opened.url ?? null;
187
218
  }
@@ -192,29 +223,38 @@ async function moveToGit(workspace, items, to, home) {
192
223
  })));
193
224
  return result;
194
225
  }
195
- async function moveToCloud(conn, items, to, home) {
196
- const scope = await selectOrigin(to ?? "me", conn, home);
197
- if (!scope.canPublish)
226
+ async function moveToCloud(conn, items, to, runtime) {
227
+ const scope = await selectOrigin(to ?? "me", conn, runtime);
228
+ if (!scope.canPublish) {
198
229
  throw new CliError(`You can't publish to ${originLabel(scope)}.`, "barndog local move --to me");
199
- const { catalog } = await environmentCatalog(home, conn);
200
- const docs = (await request(conn, "/v1/knowledge?limit=100", knowledgeIndexSchema, home)).documents;
201
- const scopes = await request(conn, "/v1/scopes", z.array(scopeSchema), home);
202
- const org = scopes.find((s) => s.type === "org");
230
+ }
231
+ const { catalog } = await environmentCatalog(runtime, conn);
232
+ const docs = (await parsed(knowledgeIndexSchema, apiClient(conn.server, runtime).GET("/v1/knowledge", {
233
+ params: { query: { limit: PAGE_SIZE } },
234
+ }))).documents;
235
+ const visible = await scopes(conn, runtime);
236
+ const org = visible.find((s) => s.type === "org");
203
237
  const rows = [];
204
238
  for (const item of items) {
205
239
  const base = { kind: item.kind, name: item.name };
206
240
  try {
207
241
  if (item.kind === "knowledge") {
208
- if (docs.some((doc) => doc.name === item.name))
242
+ if (docs.some((doc) => doc.name === item.name)) {
209
243
  rows.push({ ...base, status: "clash", detail: "Name already used" });
210
- else if (!org?.canPublish)
244
+ }
245
+ else if (!org?.canPublish) {
211
246
  rows.push({
212
247
  ...base,
213
248
  status: "skipped",
214
249
  detail: "Knowledge is organization-wide, and you can't publish there",
215
250
  });
251
+ }
216
252
  else {
217
- await publishKnowledge({ id: item.id, version: item.version, content: item.content }, conn, home);
253
+ await publishKnowledge({
254
+ id: item.id,
255
+ version: item.version,
256
+ content: knowledgeOf(item),
257
+ }, conn, runtime);
218
258
  rows.push({ ...base, status: "moved" });
219
259
  }
220
260
  continue;
@@ -237,10 +277,12 @@ async function moveToCloud(conn, items, to, home) {
237
277
  entries: item.entries,
238
278
  definition: item.definition,
239
279
  };
240
- if (item.kind === "mcp")
241
- await publishMcp(asset, scope, conn, home);
242
- else
243
- await publishPackage(asset, scope, conn, home);
280
+ if (asset.kind === "mcp") {
281
+ await publishMcp(asset, scope, conn, runtime);
282
+ }
283
+ else {
284
+ await publishPackage({ ...asset, kind: asset.kind }, scope, conn, runtime);
285
+ }
244
286
  rows.push({ ...base, status: "moved" });
245
287
  }
246
288
  catch (error) {
@@ -254,55 +296,69 @@ async function moveToCloud(conn, items, to, home) {
254
296
  return { target: originLabel(scope), rows, originId: scope.id };
255
297
  }
256
298
  /** Copies local assets into the shared workspace; the local folder is never deleted. */
257
- export function moveLocalAssets(options, home = homedir()) {
258
- return locked(home, async () => {
299
+ export function moveLocalAssets(options, runtime) {
300
+ const { home } = runtime;
301
+ return locked(runtime, async () => {
259
302
  const settings = await readSettings(home);
260
- if (!settings)
303
+ if (!settings) {
261
304
  throw new SetupRequiredError();
262
- if (settings.version !== 2 || !settings.localWorkspace)
305
+ }
306
+ if (!settings.localWorkspace) {
263
307
  throw new CliError("This machine has no local assets to move.");
264
- const overlay = localRepoSource(settings.localWorkspace, home);
308
+ }
309
+ const overlay = localRepoSource(settings.localWorkspace, runtime);
265
310
  const shared = options.repo || options.server
266
311
  ? null
267
312
  : (settings.gitWorkspace ?? settings.connection);
268
- if (!options.repo && !options.server && !shared)
313
+ if (!options.repo && !options.server && !shared) {
269
314
  throw new CliError("This machine only has its local folder, so there's nowhere to move assets yet. Name a Git repo or a Cloud Workspace as the destination; this machine stays local.", "barndog local move --repo <url> or barndog local move --server <url>");
270
- if (options.as && options.names?.length !== 1)
315
+ }
316
+ if (options.as && options.names?.length !== 1) {
271
317
  throw new CliError("--as renames one asset, so name exactly one.", "barndog local move <name> --as <new-name>");
318
+ }
272
319
  const { items, invalid } = await candidates(overlay, options.names, options.as, options.kind);
273
- const result = options.repo
274
- ? await moveToGit(await repoDestination(options.repo, home), items, options.to, home)
275
- : options.server
276
- ? await moveToCloud(await serverDestination(options.server, home), items, options.to, home)
277
- : settings.gitWorkspace
278
- ? await moveToGit(settings.gitWorkspace, items, options.to, home)
279
- : await moveToCloud(await connection(home), items, options.to, home);
320
+ const moveItems = async () => {
321
+ if (options.repo) {
322
+ return moveToGit(await repoDestination(options.repo, runtime), items, options.to, runtime);
323
+ }
324
+ if (options.server) {
325
+ return moveToCloud(await serverDestination(options.server, runtime), items, options.to, runtime);
326
+ }
327
+ if (settings.gitWorkspace) {
328
+ return moveToGit(settings.gitWorkspace, items, options.to, runtime);
329
+ }
330
+ return moveToCloud(await connection(runtime), items, options.to, runtime);
331
+ };
332
+ const result = await moveItems();
280
333
  result.rows.unshift(...invalid);
281
334
  const moved = result.rows.filter((row) => row.status === "moved");
282
335
  await recordMoved(overlay.label, moved.map((row) => ({
283
336
  kind: row.kind,
284
337
  name: row.name,
285
338
  ...(row.kind !== "knowledge" ? { originId: result.originId } : {}),
286
- path: items.find((i) => i.kind === row.kind && i.name === row.name)
287
- .path,
339
+ path: defined(items.find((i) => i.kind === row.kind && i.name === row.name), `${row.name} isn't among the moved items`).path,
288
340
  })));
289
- if (moved.length)
290
- await synchronize(undefined, home, undefined, { prompt: false });
341
+ if (moved.length) {
342
+ await synchronize(undefined, runtime, undefined, { prompt: false });
343
+ }
291
344
  return result;
292
345
  });
293
346
  }
294
- export async function listLocalAssets(home = homedir()) {
347
+ export async function listLocalAssets(runtime) {
348
+ const { home } = runtime;
295
349
  const settings = await readSettings(home);
296
- if (settings?.version !== 2 || !settings.localWorkspace)
350
+ if (!settings || !settings.localWorkspace) {
297
351
  throw new CliError("This machine has no local assets.", "barndog init --local");
298
- const source = localRepoSource(settings.localWorkspace, home);
352
+ }
353
+ const source = localRepoSource(settings.localWorkspace, runtime);
299
354
  const model = await source.model();
300
355
  const moved = await readMoved(source.label);
301
- const state = (path, invalid) => invalid
302
- ? "invalid"
303
- : moved.some((m) => m.path === path)
304
- ? "moved"
305
- : "active";
356
+ const state = (path, invalid) => {
357
+ if (invalid) {
358
+ return "invalid";
359
+ }
360
+ return moved.some((m) => m.path === path) ? "moved" : "active";
361
+ };
306
362
  return {
307
363
  folder: settings.localWorkspace.path,
308
364
  assets: [
@@ -322,10 +378,10 @@ export async function listLocalAssets(home = homedir()) {
322
378
  };
323
379
  }
324
380
  /** Where setup can offer to send local assets in a Cloud Workspace; personal first. */
325
- export async function cloudMoveTargets(home) {
326
- const conn = await connection(home);
327
- const scopes = await request(conn, "/v1/scopes", z.array(scopeSchema), home);
328
- return scopes
381
+ export async function cloudMoveTargets(runtime) {
382
+ const conn = await connection(runtime);
383
+ const visible = await scopes(conn, runtime);
384
+ return visible
329
385
  .filter((s) => s.canPublish && (s.type !== "dev" || matchesOrigin(s, "me", conn)))
330
386
  .sort((a, b) => Number(b.type === "dev") - Number(a.type === "dev"))
331
387
  .map((s) => ({
@@ -0,0 +1,24 @@
1
+ import { copyToScope, } from "../discovery/index.js";
2
+ import { LOCAL_ORIGIN } from "../workspace/overlay.js";
3
+ import { moveLocalAssets } from "./move.js";
4
+ /**
5
+ * Proposes an asset for another scope. A local asset has no server copy to
6
+ * propose from, so it is moved there instead and the result is that move.
7
+ */
8
+ export async function promote(input, runtime) {
9
+ if (input.origin === LOCAL_ORIGIN) {
10
+ return {
11
+ outcome: "moved",
12
+ move: await moveLocalAssets({
13
+ names: [input.name],
14
+ kind: input.kind,
15
+ to: input.target,
16
+ as: input.newName === input.name ? undefined : input.newName,
17
+ }, runtime),
18
+ };
19
+ }
20
+ return {
21
+ outcome: "promoted",
22
+ promotion: await copyToScope("promote", input, runtime),
23
+ };
24
+ }
@@ -1,52 +1,41 @@
1
- import { access } from "node:fs/promises";
2
- import { constants } from "node:fs";
3
- import { delimiter, join } from "node:path";
4
- import { execFile } from "node:child_process";
5
- import { promisify } from "node:util";
6
1
  import { fileURLToPath } from "node:url";
7
2
  import { coerce, satisfies, validRange } from "semver";
8
- import { adapters } from "../../harnesses/registry.js";
9
- import { nativeFile } from "./configuration.js";
10
- const execute = promisify(execFile);
11
- export const shellQuote = (value) => "'" + value.replaceAll("'", "'\\''") + "'";
3
+ import { programOutput, findExecutable, runtimeExecutable, } from "../../platform.js";
4
+ import { adapters, nativeFile } from "../../harnesses/registry.js";
5
+ import { hookCommand } from "./hook-shell.js";
6
+ /** A `--version` answer is one short line; anything slower or longer is broken. */
7
+ const VERSION_TIMEOUT_MS = 5000;
8
+ const VERSION_OUTPUT_LIMIT_BYTES = 4096;
12
9
  /**
13
- * Also sets the tool's own root variables, so a script written for the tool
14
- * finds its files and recognises where it runs.
10
+ * Checks required executables and optionally runs the harness version command;
11
+ * returns the first issue or null.
15
12
  */
16
- export const hookCommand = (root, command, harness) => `export ${["BARNDOG_HOOK_ROOT", ...(harness ? adapters[harness].hooks.rootVariables : [])].map((name) => `${name}=${shellQuote(root)}`).join(" ")}; ${command}`;
17
- export async function executable(command, path = process.env.PATH ?? "") {
18
- for (const directory of command.includes("/")
19
- ? [""]
20
- : path.split(delimiter)) {
21
- const candidate = directory ? join(directory, command) : command;
22
- try {
23
- await access(candidate, constants.X_OK);
24
- return candidate;
25
- }
26
- catch {
27
- /* next PATH entry */
13
+ export async function runtimeRequirements(harness, requirements, runtime) {
14
+ for (const command of requirements.commands) {
15
+ if (!(await runtimeExecutable(command, runtime))) {
16
+ return `Missing runtime: ${command}`;
28
17
  }
29
18
  }
30
- return null;
31
- }
32
- export async function runtimeRequirements(harness, requirements) {
33
- for (const command of requirements.commands)
34
- if (!(await executable(command)))
35
- return `Missing runtime: ${command}`;
36
19
  if (requirements.harnessVersion) {
37
- if (!validRange(requirements.harnessVersion))
20
+ if (!validRange(requirements.harnessVersion)) {
38
21
  return `Invalid declared harness version requirement: ${requirements.harnessVersion}`;
39
- const command = (await Promise.all(adapters[harness].commands.map((c) => executable(c)))).find(Boolean);
40
- if (!command)
22
+ }
23
+ const command = (await Promise.all(adapters[harness].commands.map((c) => findExecutable(c, runtime)))).find(Boolean);
24
+ if (!command) {
41
25
  return `Cannot verify ${harness} version: harness command is missing`;
26
+ }
42
27
  try {
43
- const { stdout } = await execute(command, ["--version"], {
44
- timeout: 5000,
45
- maxBuffer: 4096,
28
+ const stdout = await programOutput(command, ["--version"], runtime, {
29
+ timeoutMs: VERSION_TIMEOUT_MS,
30
+ maxBytes: VERSION_OUTPUT_LIMIT_BYTES,
46
31
  });
47
32
  const version = coerce(stdout);
48
- if (!version || !satisfies(version, requirements.harnessVersion))
49
- return `${harness} does not meet ${requirements.harnessVersion}`;
33
+ if (!version) {
34
+ return `Cannot verify ${harness} version: ${command} --version printed no version`;
35
+ }
36
+ if (!satisfies(version, requirements.harnessVersion)) {
37
+ return `${harness} ${version.version} does not meet ${requirements.harnessVersion}`;
38
+ }
50
39
  }
51
40
  catch {
52
41
  return `Cannot verify ${harness} version`;
@@ -54,72 +43,42 @@ export async function runtimeRequirements(harness, requirements) {
54
43
  }
55
44
  return null;
56
45
  }
57
- export function mcpEntry(harness, asset, definition, home) {
58
- const refs = definition.transport === "stdio"
59
- ? definition.environment
60
- : definition.headers;
61
- const env = Object.fromEntries(Object.entries(refs).map(([name, ref]) => [
62
- name,
63
- harness === "cursor"
64
- ? `\${env:${ref.secretRef}}`
65
- : `\${${ref.secretRef}}`,
66
- ]));
67
- let value;
68
- if (definition.transport === "http")
69
- value =
70
- harness === "codex"
71
- ? {
72
- url: definition.url,
73
- ...(Object.keys(refs).length
74
- ? {
75
- env_http_headers: Object.fromEntries(Object.entries(refs).map(([k, v]) => [k, v.secretRef])),
76
- }
77
- : {}),
78
- }
79
- : {
80
- ...(harness === "claude" ? { type: "http" } : {}),
81
- url: definition.url,
82
- ...(Object.keys(env).length ? { headers: env } : {}),
83
- };
84
- else if (harness === "codex") {
85
- // Native forwarding preserves reference-only storage. Renamed variables are
86
- // bound by a tiny local launcher, without writing their values to disk.
87
- const renamed = Object.entries(refs).some(([key, ref]) => key !== ref.secretRef);
88
- value = renamed
89
- ? {
90
- command: process.execPath,
91
- args: [
92
- fileURLToPath(new URL("./mcp-launch.js", import.meta.url)),
93
- Buffer.from(JSON.stringify(definition)).toString("base64url"),
94
- ],
95
- env_vars: Object.values(refs).map((v) => v.secretRef),
96
- }
97
- : {
98
- command: definition.command,
99
- args: definition.args,
100
- env_vars: Object.values(refs).map((v) => v.secretRef),
101
- };
46
+ /**
47
+ * Why a Hook can't be installed for a tool: no implementation for it, or
48
+ * something its implementation needs is missing here. Null when it can.
49
+ */
50
+ export async function hookIssue(harness, manifest, runtime) {
51
+ const implementation = manifest.implementations[harness];
52
+ if (!implementation) {
53
+ return "No implementation for this harness";
102
54
  }
103
- else
104
- value = {
105
- ...(harness === "claude" ? { type: "stdio" } : {}),
106
- command: definition.command,
107
- args: definition.args,
108
- ...(Object.keys(env).length ? { env } : {}),
109
- };
55
+ return runtimeRequirements(harness, implementation.requirements, runtime);
56
+ }
57
+ /**
58
+ * Builds a harness-specific MCP configuration entry with secret references;
59
+ * does not write native settings.
60
+ */
61
+ export function mcpEntry(harness, asset, definition, runtime) {
62
+ const { home } = runtime;
110
63
  return {
111
64
  id: asset.id,
112
65
  kind: "mcp",
113
66
  harness,
114
67
  file: nativeFile(harness, "mcp", home),
115
68
  key: asset.name,
116
- value,
69
+ value: adapters[harness].mcp.server(definition, fileURLToPath(new URL("../../entry/mcp-launch.js", import.meta.url))),
117
70
  };
118
71
  }
119
- export function hookEntries(harness, id, root, manifest, home) {
72
+ /**
73
+ * Builds native Hook entries with commands rooted at the installed package;
74
+ * missing implementations yield no entries.
75
+ */
76
+ export function hookEntries(harness, { id, root, manifest }, runtime) {
77
+ const { home } = runtime;
120
78
  const implementation = manifest.implementations[harness];
121
- if (!implementation)
79
+ if (!implementation) {
122
80
  return [];
81
+ }
123
82
  return Object.entries(implementation.events).flatMap(([key, handlers]) => handlers.map((handler) => ({
124
83
  id,
125
84
  kind: "hook",
@@ -132,12 +91,12 @@ export function hookEntries(harness, id, root, manifest, home) {
132
91
  hooks: handler.hooks.map((command) => ({
133
92
  ...command,
134
93
  type: "command",
135
- command: hookCommand(root, command.command, harness),
94
+ command: hookCommand(root, command.command, harness, runtime.platform),
136
95
  })),
137
96
  }
138
97
  : {
139
98
  ...handler,
140
- command: hookCommand(root, handler.command, harness),
99
+ command: hookCommand(root, handler.command, harness, runtime.platform),
141
100
  },
142
101
  })));
143
102
  }