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,141 @@
1
+ import { Option } from "commander";
2
+ import { assetListOptions } from "../ui/asset-list.js";
3
+ import { runSetInstall } from "../ui/scope-install.js";
4
+ import { runSelection } from "../ui/selection.js";
5
+ import { pickOne } from "../ui/pick.js";
6
+ import { bold, dim, hint, json, ok, originLabel, section, table, } from "../ui/format.js";
7
+ import { requireArguments } from "./arguments.js";
8
+ const setDescriptions = {
9
+ install: "Subscribe to a scope's shared assets",
10
+ remove: "Unsubscribe from a scope",
11
+ enable: "Turn a paused subscription back on",
12
+ disable: "Pause a subscription without removing it",
13
+ };
14
+ /** What the picker offers when a `sets` command is run without a scope. */
15
+ const setPickers = {
16
+ install: {
17
+ message: "Choose a scope to subscribe to",
18
+ offers: (subscription) => !subscription,
19
+ empty: "You're already subscribed to every scope.",
20
+ },
21
+ remove: {
22
+ message: "Choose a subscription to remove",
23
+ offers: (subscription) => Boolean(subscription),
24
+ empty: "You have no subscriptions yet.",
25
+ },
26
+ enable: {
27
+ message: "Choose a paused subscription to turn back on",
28
+ offers: (subscription) => subscription?.enabled === false,
29
+ empty: "None of your subscriptions are paused.",
30
+ },
31
+ disable: {
32
+ message: "Choose a subscription to pause",
33
+ offers: (subscription) => subscription?.enabled === true,
34
+ empty: "None of your subscriptions are active.",
35
+ },
36
+ };
37
+ export function registerSets(program, context) {
38
+ const sets = program
39
+ .command("sets")
40
+ .description("Subscribe to everything a team, repository or the organization shares");
41
+ const load = () => context.listSets();
42
+ const label = (scope) => originLabel(scope);
43
+ assetListOptions(sets
44
+ .command("list")
45
+ .description("Show your subscriptions and the scopes you can subscribe to")).action(async (options) => {
46
+ const result = await load();
47
+ if (context.mode.json) {
48
+ return context.write(json(result));
49
+ }
50
+ const subscribed = result.subscriptions.map((subscription) => ({
51
+ subscription,
52
+ scope: result.available.find((s) => s.id === subscription.scope.id && s.type === subscription.scope.type),
53
+ }));
54
+ context.write(`${section("Subscribed")} ${dim(`(${subscribed.length})`)}`);
55
+ context.write(subscribed.length
56
+ ? table(subscribed.map(({ subscription, scope }) => [
57
+ bold(scope
58
+ ? label(scope)
59
+ : `${subscription.scope.type}/${subscription.scope.id}`),
60
+ scope?.name ?? dim("unavailable"),
61
+ subscription.mode,
62
+ subscription.enabled ? ok("enabled") : dim("disabled"),
63
+ ]), { header: ["Scope", "Name", "Mode", "State"] }).join("\n")
64
+ : dim(" None yet."));
65
+ const terms = options.search?.toLowerCase().split(/\s+/).filter(Boolean) ?? [];
66
+ const available = result.available
67
+ .filter((scope) => !result.subscriptions.some((s) => s.scope.id === scope.id && s.scope.type === scope.type))
68
+ .filter((scope) => (!options.origin ||
69
+ scope.type === options.origin ||
70
+ label(scope) === options.origin.replace(":", "/")) &&
71
+ terms.every((term) => `${label(scope)} ${scope.name ?? ""}`.toLowerCase().includes(term)))
72
+ .sort((a, b) => label(a).localeCompare(label(b)));
73
+ const start = (options.page - 1) * options.limit;
74
+ const page = available.slice(start, start + options.limit);
75
+ context.write("");
76
+ context.write(`${section("Available")} ${dim(`(${available.length})`)}`);
77
+ context.write(page.length
78
+ ? table(page.map((scope) => [bold(label(scope)), scope.name ?? ""]), { header: ["Scope", "Name"] }).join("\n")
79
+ : dim(" Nothing else to subscribe to."));
80
+ if (start + options.limit < available.length) {
81
+ context.write(hint(`barndog sets list --page ${options.page + 1}`));
82
+ }
83
+ context.write("");
84
+ context.write(hint("barndog sets install", "Tip") + dim(" to subscribe"));
85
+ });
86
+ const chooseScope = async (message, filter, empty) => {
87
+ const result = await load();
88
+ return pickOne(message, result.available
89
+ .filter((scope) => filter(scope, result.subscriptions.find((s) => s.scope.id === scope.id && s.scope.type === scope.type)))
90
+ .sort((a, b) => label(a).localeCompare(label(b)))
91
+ .map((scope) => ({
92
+ value: label(scope),
93
+ name: label(scope),
94
+ hint: scope.name,
95
+ })), { empty });
96
+ };
97
+ for (const action of ["install", "remove", "enable", "disable"]) {
98
+ const command = sets
99
+ .command(`${action} [scope]`)
100
+ .description(setDescriptions[action])
101
+ .option("--origin <origin>", "Scope, such as org, team/engineering or repo/web-app");
102
+ if (action === "install") {
103
+ command
104
+ .addOption(new Option("--mode <mode>", "Which assets to include; asks when omitted").choices(["recommended", "optional", "all"]))
105
+ .addOption(new Option("--overrides <choice>", "Keep or clear your existing exclusions").choices(["preserve", "clear"]))
106
+ .option("--decisions <file>", "JSON per-asset override choices");
107
+ }
108
+ command.action(async (scope, options) => {
109
+ let origin = scope ?? options.origin;
110
+ if (!origin) {
111
+ requireArguments(context, `barndog sets ${action} <scope>`);
112
+ const { message, offers, empty } = setPickers[action];
113
+ origin = await chooseScope(message, (_, s) => offers(s), empty);
114
+ }
115
+ return action === "install"
116
+ ? runSetInstall(context, { ...options, origin })
117
+ : runSelection(context, (resolution) => context.changeSet(action, { ...options, origin, resolution }));
118
+ });
119
+ }
120
+ const switchCommand = (name, hidden) => sets
121
+ .command(`${name} [scope]`, { hidden })
122
+ .description("Switch to another team or repository, replacing your current one of that type")
123
+ .addOption(new Option("--mode <mode>", "Which assets to include")
124
+ .choices(["recommended", "optional", "all"])
125
+ .default("recommended"))
126
+ .addOption(new Option("--overrides <choice>", "Keep or clear your existing exclusions").choices(["preserve", "clear"]))
127
+ .option("--decisions <file>", "JSON per-asset override choices")
128
+ .action(async (scope, options) => {
129
+ let origin = scope && name === "switch-team" && !scope.includes("/")
130
+ ? `team/${scope}`
131
+ : scope;
132
+ if (!origin) {
133
+ requireArguments(context, "barndog sets switch <team/slug|repo/slug>");
134
+ origin = await chooseScope("Switch to", (candidate, subscription) => !subscription &&
135
+ (candidate.type === "team" || candidate.type === "repo"), "There is no other team or repository to switch to.");
136
+ }
137
+ await runSelection(context, (resolution) => context.switchSet({ ...options, origin, resolution }));
138
+ });
139
+ switchCommand("switch", false);
140
+ switchCommand("switch-team", true);
141
+ }
@@ -1,21 +1,27 @@
1
- import { harnessNames, inventoryHints, kindLabels, renderInventory, } from "../ui/assets.js";
1
+ import { harnessNames, inventoryHints, renderInventory } from "../ui/assets.js";
2
2
  import { renderCollaboration } from "../ui/collaboration.js";
3
- import { dim, fields, heading, hint, json, ok, plural } from "../ui/format.js";
3
+ import { dim, fields, heading, hint, json, ok, plural, warn, } from "../ui/format.js";
4
+ import { assetKindList, assetKinds } from "../features/asset-kinds/index.js";
5
+ function knowledgeState(enabled) {
6
+ return enabled ? ok("listed at session start") : dim("off");
7
+ }
4
8
  export function registerStatus(program, context) {
5
9
  program
6
10
  .command("status")
7
11
  .description("Show what's installed on this machine and where (inside a working copy, its edits first)")
8
12
  .option("--paths", "Show installed folders and configuration files")
9
13
  .action(async (options) => {
10
- const working = (await context.collaborate("status", {}));
14
+ const working = await context.workingStatus();
11
15
  const inventory = await context.inventory();
12
- if (context.mode.json)
13
- return context.write(json(working.mode === "environment"
14
- ? inventory
15
- : { workingCopy: working, ...inventory }));
16
- if (working.mode !== "environment") {
17
- for (const line of renderCollaboration("status", working))
16
+ if (context.mode.json) {
17
+ return context.write(json("changes" in working
18
+ ? { workingCopy: working, ...inventory }
19
+ : inventory));
20
+ }
21
+ if ("changes" in working) {
22
+ for (const line of renderCollaboration(working)) {
18
23
  context.write(line);
24
+ }
19
25
  context.write("");
20
26
  }
21
27
  context.write(`${heading("status")}\n`);
@@ -27,40 +33,45 @@ export function registerStatus(program, context) {
27
33
  ],
28
34
  [
29
35
  "Knowledge",
30
- inventory.server
31
- ? inventory.knowledge
32
- ? ok("listed at session start")
33
- : dim("off")
34
- : undefined,
36
+ inventory.server ? knowledgeState(inventory.knowledge) : undefined,
35
37
  ],
36
- ]))
38
+ ])) {
37
39
  context.write(line);
38
- if (inventory.offline)
40
+ }
41
+ if (inventory.offline) {
39
42
  context.write(dim(`\nShowing local state only: ${inventory.offline}`));
40
- for (const kind of ["skill", "mcp", "hook"]) {
43
+ }
44
+ inventory.moving.forEach((move) => context.write(`\n${warn("!")} ${move.name} is moving to ${move.to}. Your local copy stays in use until that merges.`));
45
+ for (const kind of assetKindList) {
41
46
  const items = inventory.items.filter((item) => item.kind === kind);
42
47
  context.write("");
43
48
  if (!items.length) {
44
- context.write(`${kindLabels[kind].title} ${dim("(0)")}`);
45
- context.write(dim(` None. ${`barndog ${kindLabels[kind].group} install`} to add some.`));
49
+ context.write(`${assetKinds[kind].many} ${dim("(0)")}`);
50
+ context.write(dim(` None. ${`barndog ${assetKinds[kind].command} install`} to add some.`));
46
51
  continue;
47
52
  }
48
53
  for (const line of renderInventory(items, {
49
- heading: kindLabels[kind].title,
54
+ heading: assetKinds[kind].many,
50
55
  paths: options.paths,
51
- }))
56
+ runtime: context.runtime,
57
+ })) {
52
58
  context.write(line);
59
+ }
53
60
  }
54
61
  const hints = inventoryHints(inventory.items);
55
62
  context.write("");
56
- if (hints.length)
57
- for (const line of hints)
63
+ if (hints.length) {
64
+ for (const line of hints) {
58
65
  context.write(line);
66
+ }
67
+ }
59
68
  // Without the workspace, BarnDog only knows what is installed, not whether it's current.
60
- else if (inventory.offline)
69
+ else if (inventory.offline) {
61
70
  context.write(`${plural(inventory.items.length, "asset")} installed. ${dim("Couldn't check for updates; run barndog sync once the workspace is reachable.")}`);
62
- else
71
+ }
72
+ else {
63
73
  context.write(`${ok("✔")} ${plural(inventory.items.length, "asset")} up to date.` +
64
74
  (options.paths ? "" : ` ${hint("barndog status --paths", "Tip")}`));
75
+ }
65
76
  });
66
77
  }
@@ -1,3 +1,4 @@
1
+ import { Option } from "commander";
1
2
  import { resolve } from "node:path";
2
3
  import { renderSyncOutput } from "../ui/output.js";
3
4
  import { json } from "../ui/format.js";
@@ -9,22 +10,29 @@ export function registerSync(program, context) {
9
10
  .option("--dry-run", "Show what would change without changing anything")
10
11
  .option("-v, --verbose", "Also list what is already up to date, including BarnDog's own entries")
11
12
  .option("--config <path>", "Use an explicit configuration file once")
12
- .option("--auto", "Quiet background sync used at session start")
13
+ .addOption(new Option("--auto", "Quiet background sync used at session start").conflicts(["dryRun", "verbose", "config"]))
13
14
  .action(async (options) => {
14
15
  // Runs detached at session start: nobody is watching, so it never reports.
15
16
  if (options.auto) {
16
- await autoSync(() => context.synchronize(undefined, { refresh: "auto", prompt: false })).catch(() => undefined);
17
+ await autoSync(() => context.synchronize(undefined, {
18
+ refresh: "auto",
19
+ prompt: false,
20
+ }), context.runtime).catch(() => undefined);
17
21
  return;
18
22
  }
19
- const configPath = options.config === undefined ? undefined : resolve(options.config);
23
+ const configPath = options.config === undefined
24
+ ? undefined
25
+ : resolve(context.runtime.cwd, options.config);
20
26
  const events = await context.synchronize(configPath, options.dryRun ? { dryRun: true } : undefined);
21
- if (context.mode.json)
27
+ if (context.mode.json) {
22
28
  return context.write(json(events));
29
+ }
23
30
  for (const line of renderSyncOutput(events, {
24
31
  title: options.dryRun ? "sync --dry-run" : "sync",
25
32
  preview: options.dryRun,
26
33
  verbose: options.verbose,
27
- }))
34
+ })) {
28
35
  context.write(line);
36
+ }
29
37
  });
30
38
  }
@@ -1,13 +1,25 @@
1
1
  import { bold, dim, heading, json, ok, plural, table, warn, } from "../ui/format.js";
2
- import { renderMove } from "../ui/move.js";
2
+ import { chooseKeepLocal, pickLocalAssets, renderMove } from "../ui/move.js";
3
+ import { CliError } from "../errors.js";
4
+ const migrationActionStyles = {
5
+ publish: ok,
6
+ exists: dim,
7
+ invalid: warn,
8
+ "missing-scope": warn,
9
+ };
10
+ /**
11
+ * Registers workspace validation, local asset movement and migration commands
12
+ * using the supplied services.
13
+ */
3
14
  export function registerWorkspace(program, context) {
4
15
  program
5
16
  .command("validate [directory]")
6
17
  .description("Check a BarnDog workspace folder, for example in a repo's CI")
7
18
  .action(async (directory) => {
8
- const result = (await context.capability("validate", { directory }));
9
- if (context.mode.json)
19
+ const result = await context.validateFolder(directory ?? ".");
20
+ if (context.mode.json) {
10
21
  return context.write(json(result));
22
+ }
11
23
  context.write(`${ok("✔")} ${bold(result.workspace)} is valid · ${plural(result.assets, "asset")}, ${plural(result.knowledge, "knowledge document")}`);
12
24
  });
13
25
  const local = program
@@ -15,67 +27,107 @@ export function registerWorkspace(program, context) {
15
27
  .description("See and share the assets kept in this machine's folder");
16
28
  local
17
29
  .command("list")
18
- .description("List local assets and whether they've been moved")
30
+ .description("List the assets kept in this machine's folder")
19
31
  .action(async () => {
20
- const result = (await context.capability("local-list", {}));
21
- if (context.mode.json)
32
+ const result = await context.listLocalAssets();
33
+ if (context.mode.json) {
22
34
  return context.write(json(result));
35
+ }
23
36
  context.write(dim(result.folder));
24
- if (!result.assets.length)
37
+ if (!result.assets.length) {
25
38
  return context.write(dim("No local assets."));
39
+ }
26
40
  for (const line of table(result.assets.map((asset) => [
27
41
  bold(asset.name),
28
42
  dim(asset.kind),
29
43
  asset.state === "invalid" ? warn(asset.state) : asset.state,
30
44
  dim(asset.path),
31
- ]), { header: ["Name", "Kind", "State", "Path"] }))
45
+ asset.movingTo ? dim(`to ${asset.movingTo}`) : "",
46
+ ]), { header: ["Name", "Kind", "State", "Path", ""] })) {
32
47
  context.write(line);
48
+ }
33
49
  });
34
50
  local
35
51
  .command("move [names...]")
36
- .description("Copy local assets into your Git or Cloud workspace")
52
+ .description("Move local assets into your Git or Cloud workspace")
53
+ .option("--all", "Move every local asset that isn't already moving")
54
+ .option("--keep-local", "Share a copy and keep the local assets as separate ones")
55
+ .option("--no-keep-local", "Make the shared copy the only one; the local copy is removed once it exists")
37
56
  .option("--to <origin>", "Destination, such as me, org or team/web. Defaults to me in cloud, org in Git")
38
57
  .option("--as <name>", "New name, for moving one asset whose name is taken")
39
58
  .option("--repo <url>", "Send to this Git repo; this machine stays as it is")
40
59
  .option("--server <url>", "Send to this Cloud Workspace; this machine stays as it is")
60
+ .addHelpText("after", `
61
+ Without names, a terminal lists your local assets to pick from; elsewhere, name them or pass --all.
62
+
63
+ It then asks whether to move them or keep separate local copies; --keep-local or --no-keep-local answers without asking.
64
+ Move: the shared copy becomes the only one. Once it exists, the next sync installs it and removes the local copy.
65
+ A move into a Git repo with assets in it waits for its pull request: until it merges, local list shows
66
+ the asset as moving and the local copy stays in use. A local copy edited before then stays as a separate asset.
67
+ Keep: a copy is shared and the local asset stays. When both have the same name, sync asks which to rename.
68
+ With --repo or --server this machine stays as it is, so the assets are always copied.`)
41
69
  .action(async (names, options) => {
42
- const result = (await context.capability("local-move", {
43
- names,
70
+ const chosen = await chooseNames(names, options.all);
71
+ // --repo and --server send a copy and leave this machine as it is.
72
+ const oneOff = Boolean(options.repo || options.server);
73
+ const keepLocal = options.keepLocal ?? (oneOff || (await askKeepLocal(chosen?.length)));
74
+ const result = await context.moveLocalAssets({
75
+ names: chosen,
76
+ keepLocal,
44
77
  to: options.to,
45
78
  as: options.as,
46
79
  repo: options.repo,
47
80
  server: options.server,
48
- }));
49
- if (context.mode.json)
81
+ });
82
+ if (context.mode.json) {
50
83
  return context.write(json(result));
51
- for (const line of renderMove(result))
84
+ }
85
+ for (const line of renderMove(result)) {
52
86
  context.write(line);
87
+ }
53
88
  });
89
+ /** The names to move; undefined means every local asset not already moving. */
90
+ async function chooseNames(names, all) {
91
+ if (all && names.length) {
92
+ throw new CliError("Name the assets to move or pass --all, not both.", "barndog local move --help");
93
+ }
94
+ if (all || names.length) {
95
+ return all ? undefined : names;
96
+ }
97
+ if (!context.mode.interactive) {
98
+ throw new CliError("Name the local assets to move, or pass --all.", "barndog local move <names...> --keep-local, or barndog local move --all --no-keep-local");
99
+ }
100
+ return pickLocalAssets(await context.listLocalAssets());
101
+ }
102
+ async function askKeepLocal(count) {
103
+ if (!context.mode.interactive) {
104
+ throw new CliError("Say whether to keep separate local copies: --keep-local keeps them, --no-keep-local makes the shared copy the only one.", "barndog local move --help");
105
+ }
106
+ return chooseKeepLocal(count ?? 2);
107
+ }
54
108
  program
55
109
  .command("migrate")
56
110
  .description("Move a Git repo or local workspace to a BarnDog Cloud Workspace")
57
111
  .requiredOption("--to <server>", "Cloud or self-hosted server URL")
58
112
  .option("--dry-run", "Show what would move without changing anything")
59
113
  .action(async (options) => {
60
- const result = (await context.capability("migrate", {
114
+ const result = await context.migrate({
61
115
  server: options.to,
62
116
  dryRun: options.dryRun,
63
- }));
64
- if (context.mode.json)
117
+ });
118
+ if (context.mode.json) {
65
119
  return context.write(json(result));
120
+ }
66
121
  context.write(`\n${heading(options.dryRun ? "migrate --dry-run" : "migrate")}\n`);
67
122
  for (const line of table(result.rows.map((row) => [
68
- row.action === "publish"
69
- ? ok(row.action)
70
- : row.action === "exists"
71
- ? dim(row.action)
72
- : warn(row.action),
123
+ migrationActionStyles[row.action](row.action),
73
124
  dim(row.kind),
74
125
  bold(row.name),
75
126
  row.origin,
76
127
  dim(row.detail ?? ""),
77
- ]), { header: ["Action", "Kind", "Name", "Origin", ""] }))
128
+ ]), { header: ["Action", "Kind", "Name", "Origin", ""] })) {
78
129
  context.write(line);
130
+ }
79
131
  context.write("");
80
132
  context.write(result.migrated
81
133
  ? `${ok("✔")} This machine now uses ${result.server}. Only current content moved; older versions stay in your repo.`
@@ -1,40 +1,26 @@
1
- import { z } from "zod";
2
- import { upgradeSettings } from "./settings.js";
3
- const id = z.uuidv4().transform((value) => value.toLowerCase());
4
- export const selectionStateSchema = z
5
- .object({
6
- subscriptions: z.array(z
7
- .object({
8
- scope: z.object({ type: z.enum(["org", "team", "repo"]), id }),
9
- mode: z.enum(["recommended", "optional", "all"]),
10
- enabled: z.boolean(),
11
- })
12
- .strict()),
13
- individualAssetIds: z.array(id),
14
- excludedAssetIds: z.array(id),
15
- disabledAssetIds: z.array(id),
16
- })
17
- .strict();
1
+ import { selectionStateSchema } from "./selection.js";
2
+ /**
3
+ * Reads selections from settings, returning empty lists when no environment has
4
+ * been saved.
5
+ */
18
6
  export function selectionState(settings) {
19
- const next = upgradeSettings(settings);
20
- return (next.environment ?? {
7
+ return (settings.environment ?? {
21
8
  subscriptions: [],
22
- individualAssetIds: next.skills
23
- .filter((s) => s.kind === "api")
24
- .map((s) => s.id),
9
+ individualAssetIds: [],
25
10
  excludedAssetIds: [],
26
- disabledAssetIds: next.skills
27
- .filter((s) => s.kind === "api" && !s.enabled)
28
- .map((s) => s.id),
11
+ disabledAssetIds: [],
29
12
  });
30
13
  }
31
14
  export function withSelection(settings, environment) {
32
15
  return {
33
- ...upgradeSettings(settings),
34
- skills: upgradeSettings(settings).skills.filter((s) => s.kind === "local"),
16
+ ...settings,
35
17
  environment: selectionStateSchema.parse(environment),
36
18
  };
37
19
  }
20
+ /**
21
+ * Checks whether settings contain subscriptions or individually selected
22
+ * assets, including disabled selections.
23
+ */
38
24
  export function hasRemoteSelections(settings) {
39
25
  const state = selectionState(settings);
40
26
  return !!(state.subscriptions.length || state.individualAssetIds.length);
@@ -0,0 +1,81 @@
1
+ import { join } from "node:path";
2
+ import { assetFolders } from "./selection.js";
3
+ /**
4
+ * Every path BarnDog keeps under `~/.barndog/`. These files are part of the
5
+ * public surface: older and newer CLI versions, and the end-to-end tests, read
6
+ * them. A new one gets a path here, a Zod schema, one reader, and writes
7
+ * through `writeAtomic()`.
8
+ */
9
+ export function barndogPaths(home) {
10
+ const root = join(home, ".barndog");
11
+ const git = join(root, "git");
12
+ const workingCopies = join(root, "workspaces");
13
+ return {
14
+ root,
15
+ /** Settings: harnesses, the workspace source and the asset selection. */
16
+ settings: join(root, "config.yaml"),
17
+ /** What BarnDog installed: harness links, native entries, package folders. */
18
+ state: join(root, "state.json"),
19
+ /** The writes of a sync in progress, rolled forward after a crash. */
20
+ pendingSync: join(root, "pending-sync.json"),
21
+ syncLock: join(root, "sync.lock"),
22
+ /** Backups of config.yaml and native files taken before BarnDog changes them. */
23
+ migrations: join(root, "migrations"),
24
+ /** One folder per `barndog adopt`: its record and the originals it moved aside. */
25
+ adoptions: join(root, "adoptions"),
26
+ adoption: (id) => {
27
+ const folder = join(root, "adoptions", id);
28
+ return {
29
+ folder,
30
+ record: join(folder, "record.json"),
31
+ /** Each tool settings file as it was before the adoption changed it. */
32
+ settings: join(folder, "settings"),
33
+ /** Skill folders taken out of the tools: `<harness>/<name>`. */
34
+ skills: join(folder, "skills"),
35
+ };
36
+ },
37
+ /** The last Cloud catalog revision a background sync delivered. */
38
+ cloudCheck: join(root, "cloud-check.json"),
39
+ /** Saved sessions, per server. */
40
+ credentials: join(root, "credentials.json"),
41
+ credentialsLock: join(root, "credentials.lock"),
42
+ /**
43
+ * MCP variable values kept on this machine only, by variable name. Never
44
+ * uploaded; sync writes them into the coding tools' settings.
45
+ */
46
+ secrets: join(root, "secrets.json"),
47
+ secretsLock: join(root, "secrets.lock"),
48
+ /** Where `claude mcp login` and `codex mcp login` run. */
49
+ nativeAuth: join(root, "native-auth"),
50
+ /** The default local workspace folder. */
51
+ localWorkspace: join(root, "workspace"),
52
+ /** Bare clones of Git workspaces. */
53
+ git,
54
+ /** The bare clone a Git workspace is read from; nothing is checked out. */
55
+ bareClone: (workspaceId) => join(git, `${workspaceId}.git`),
56
+ /** The commit last accepted from a Git workspace's host, and when. */
57
+ fetchState: (workspaceId) => join(git, `${workspaceId}.json`),
58
+ /** A clone that `barndog init --repo` checks before keeping it. */
59
+ setupClone: (id) => join(git, `.setup-${id}.git`),
60
+ /** Working-copy records, keyed by folder, with their lock and snapshots. */
61
+ workingCopies,
62
+ workingCopiesLock: join(workingCopies, "lock"),
63
+ /** What a working copy held before an update, for recovery. */
64
+ workingCopySnapshots: join(workingCopies, "snapshots"),
65
+ /** The commit-pinned package cache of one source: `<skills|hooks>/<asset ID>/<commit>/`. */
66
+ packageCache: (key) => join(root, "packages", key),
67
+ /** Readable folders that harness links point at. */
68
+ installed: (kind) => join(root, "installed", assetFolders[kind]),
69
+ };
70
+ }
71
+ /** Files BarnDog keeps inside a local workspace folder. */
72
+ export function localWorkspaceFiles(folder) {
73
+ return {
74
+ /** Assets imported from repositories, and how each one updates. */
75
+ sources: join(folder, ".barndog-sources.json"),
76
+ /** Assets moved to a shared workspace, so sync stops installing the local copy. */
77
+ moved: join(folder, ".barndog-moved.json"),
78
+ };
79
+ }
80
+ /** Beside each cached package: the fingerprint it was stored with. */
81
+ export const packageManifest = (revisionFolder) => join(revisionFolder, "manifest.json");
@@ -0,0 +1,30 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * Asset kinds delivered as file packages; MCP definitions use separate
4
+ * configuration handling.
5
+ */
6
+ export const packageKindList = [
7
+ "skill",
8
+ "hook",
9
+ ];
10
+ /** The folder each kind lives in, in a workspace and under ~/.barndog/installed/. */
11
+ export const assetFolders = {
12
+ skill: "skills",
13
+ mcp: "mcp",
14
+ hook: "hooks",
15
+ };
16
+ const id = z.uuidv4().transform((value) => value.toLowerCase());
17
+ export const selectionStateSchema = z
18
+ .object({
19
+ subscriptions: z.array(z
20
+ .object({
21
+ scope: z.object({ type: z.enum(["org", "team", "repo"]), id }),
22
+ mode: z.enum(["recommended", "optional", "all"]),
23
+ enabled: z.boolean(),
24
+ })
25
+ .strict()),
26
+ individualAssetIds: z.array(id),
27
+ excludedAssetIds: z.array(id),
28
+ disabledAssetIds: z.array(id),
29
+ })
30
+ .strict();