barndog 0.1.1 → 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 +8 -7
  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 +13 -3
  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
@@ -0,0 +1,89 @@
1
+ import { fileURLToPath, pathToFileURL } from "node:url";
2
+ import { CliError } from "../../errors.js";
3
+ import { adapters, nativeFile } from "../../harnesses/registry.js";
4
+ import { environmentValue, pathsFor, unsetCommand } from "../../platform.js";
5
+ import { programLine } from "../native/hook-shell.js";
6
+ /**
7
+ * Refuses to sync while a selected coding tool is told to keep its settings
8
+ * somewhere other than the folder BarnDog writes to.
9
+ */
10
+ export function assertSupportedConfigHomes(harnesses, runtime) {
11
+ const { home } = runtime;
12
+ for (const harness of harnesses) {
13
+ const { configHome } = adapters[harness];
14
+ const custom = configHome && environmentValue(runtime, configHome.variable);
15
+ if (!configHome || !custom) {
16
+ continue;
17
+ }
18
+ const paths = pathsFor(runtime.platform);
19
+ const isDefault = paths.relative(paths.resolve(runtime.cwd, custom), paths.join(home, configHome.directory)) === "";
20
+ if (!isDefault || !configHome.defaultIsSupported) {
21
+ throw new CliError(`BarnDog can't install into a custom ${configHome.variable} yet; it uses ~/${configHome.directory}.`, `Stop setting ${configHome.variable}, including in your shell profile, then sync again.`, { command: unsetCommand(configHome.variable, runtime.platform) });
22
+ }
23
+ }
24
+ }
25
+ /** A built entry script a coding tool runs. */
26
+ const entryScript = (name) => fileURLToPath(new URL(`../../entry/${name}.js`, import.meta.url));
27
+ /**
28
+ * One session-start registration that runs `program` (an entry script and its
29
+ * arguments, run by Node): a command hook in the tool's hook settings, or for
30
+ * a tool without command hooks, a line of options in BarnDog's plugin module,
31
+ * keyed by `kind`.
32
+ */
33
+ function startupEntry(harness, registration, runtime) {
34
+ const { id, kind, program } = registration;
35
+ const adapter = adapters[harness];
36
+ const file = nativeFile(harness, kind, runtime.home);
37
+ const command = [process.execPath, ...program];
38
+ if (!adapter.hooks) {
39
+ return {
40
+ id,
41
+ kind,
42
+ harness,
43
+ file,
44
+ key: kind,
45
+ value: {
46
+ entry: pathToFileURL(entryScript(adapter.plugin.entryScript)).href,
47
+ command,
48
+ },
49
+ };
50
+ }
51
+ return {
52
+ id,
53
+ kind,
54
+ harness,
55
+ file,
56
+ key: adapter.hooks.sessionStart,
57
+ value: adapter.hooks.entry(programLine(adapter.id, command, runtime.platform)),
58
+ };
59
+ }
60
+ /**
61
+ * BarnDog's own session-start registrations for every selected coding tool.
62
+ * The knowledge index needs a workspace to read from (`knowledge`) and the
63
+ * setting left on; the workspace sync is registered for every workspace type.
64
+ */
65
+ export function startupEntries(settings, runtime, available) {
66
+ const { home } = runtime;
67
+ const entries = [];
68
+ if (available.knowledge && settings.knowledge !== false) {
69
+ const script = entryScript("knowledge-startup");
70
+ for (const harness of settings.harnesses) {
71
+ entries.push(startupEntry(harness, {
72
+ id: "barndog-knowledge-index",
73
+ kind: "knowledge",
74
+ program: [script, harness, home],
75
+ }, runtime));
76
+ }
77
+ }
78
+ if (settings.connection || settings.gitWorkspace || settings.localWorkspace) {
79
+ const script = entryScript("workspace-startup");
80
+ for (const harness of settings.harnesses) {
81
+ entries.push(startupEntry(harness, {
82
+ id: "barndog-workspace-sync",
83
+ kind: "sync",
84
+ program: [script, home],
85
+ }, runtime));
86
+ }
87
+ }
88
+ return entries;
89
+ }
@@ -0,0 +1,91 @@
1
+ import { basename } from "node:path";
2
+ import { treeFingerprint } from "../workspace/tree.js";
3
+ import { originLabel } from "../server/origin.js";
4
+ import { resolveClashes } from "./names.js";
5
+ /** The name an asset is installed under right now, whatever settings say it should be. */
6
+ export function heldName(id, links, native) {
7
+ const held = links.find((link) => link.id === id)?.target ??
8
+ native.find((entry) => entry.id === id && entry.kind === "mcp")?.key;
9
+ return held ? basename(held) : undefined;
10
+ }
11
+ export async function settleNames(input, runtime) {
12
+ const { assets, invalid, state, savedNames, resolver } = input;
13
+ const { links, native, installed } = state;
14
+ // Installed names share one namespace per kind; resolve clashes before staging.
15
+ const owned = (id) => links.some((link) => link.id === id) ||
16
+ native.some((entry) => entry.id === id && entry.kind === "mcp");
17
+ // An invalid asset can only stay installed while its own folder is still there.
18
+ const vanished = new Set();
19
+ for (const entry of installed) {
20
+ if (!invalid.has(entry.id)) {
21
+ continue;
22
+ }
23
+ const actual = await treeFingerprint(entry.path, runtime);
24
+ const shared = installed.some((other) => other.id !== entry.id && other.path === entry.path);
25
+ if (actual === null || (shared && actual !== entry.fingerprint)) {
26
+ vanished.add(entry.id);
27
+ }
28
+ }
29
+ // An invalid asset stays under the name it's installed at, whatever it was renamed to since.
30
+ const heldNames = new Map();
31
+ for (const { asset, enabled } of assets) {
32
+ if (!enabled || !invalid.has(asset.id) || vanished.has(asset.id)) {
33
+ continue;
34
+ }
35
+ const held = heldName(asset.id, links, native);
36
+ if (held) {
37
+ heldNames.set(asset.id, held);
38
+ }
39
+ }
40
+ const outcome = await resolveClashes([
41
+ ...assets.flatMap(({ asset, enabled }) => {
42
+ const { kind } = asset;
43
+ if (!enabled ||
44
+ kind === "hook" ||
45
+ (invalid.has(asset.id) &&
46
+ (!owned(asset.id) || vanished.has(asset.id)))) {
47
+ return [];
48
+ }
49
+ return [
50
+ {
51
+ id: asset.id,
52
+ kind,
53
+ name: asset.name,
54
+ origin: asset.origin,
55
+ installed: owned(asset.id),
56
+ renamable: !invalid.has(asset.id),
57
+ },
58
+ ];
59
+ }),
60
+ ], { ...savedNames, ...Object.fromEntries(heldNames) }, resolver);
61
+ // A held name is for this run; settings keep whatever the developer saved.
62
+ const localNames = { ...outcome.localNames };
63
+ for (const id of heldNames.keys()) {
64
+ if (savedNames[id] === undefined) {
65
+ delete localNames[id];
66
+ }
67
+ else {
68
+ localNames[id] = savedNames[id];
69
+ }
70
+ }
71
+ return {
72
+ vanished,
73
+ localNames,
74
+ disabledAssetIds: outcome.disabledAssetIds,
75
+ skipped: new Set(outcome.skipped.map((clash) => clash.incoming.id)),
76
+ events: outcome.skipped.map((clash) => ({
77
+ type: "clash",
78
+ kind: clash.kind,
79
+ name: clash.name,
80
+ installed: {
81
+ name: clash.installed.name,
82
+ origin: originLabel(clash.installed.origin),
83
+ },
84
+ skipped: {
85
+ name: clash.incoming.name,
86
+ origin: originLabel(clash.incoming.origin),
87
+ rename: clash.incomingRename,
88
+ },
89
+ })),
90
+ };
91
+ }
@@ -0,0 +1,178 @@
1
+ import { readFile } from "node:fs/promises";
2
+ import { basename, join, resolve } from "node:path";
3
+ import { parse } from "yaml";
4
+ import { hookManifestSchema, } from "@barndog-ai/api-contract";
5
+ import { packageFingerprint } from "@barndog-ai/api-contract/package";
6
+ import { CliError } from "../../errors.js";
7
+ import { adapters, isHookHarness, skillDirectory, } from "../../harnesses/registry.js";
8
+ import { isInside } from "../../shared/files.js";
9
+ import { defined } from "../../shared/lookup.js";
10
+ import { hookEntries, hookIssue, mcpEntry } from "../native/adapters.js";
11
+ import { desiredEntries, installedPath } from "../workspace/installed.js";
12
+ import { hookFolders, installedName } from "./names.js";
13
+ export async function stageAssets(input) {
14
+ const { invalid, vanished, skipped, localNames, source, harnesses, runtime } = input;
15
+ const { home } = runtime;
16
+ const effective = { assets: input.assets };
17
+ const { links, native: previousNative, installed } = input.state;
18
+ const desired = [];
19
+ const native = [];
20
+ const trees = [];
21
+ const events = [];
22
+ const names = new Set();
23
+ const ids = new Set();
24
+ const addSkill = (id, source, name) => {
25
+ if (names.has(name)) {
26
+ throw new CliError(`Two enabled Skills are named ${name}`, "barndog doctor");
27
+ }
28
+ names.add(name);
29
+ for (const harness of harnesses) {
30
+ const target = resolve(skillDirectory(harness, home), name);
31
+ if (isInside(source, target) || isInside(target, source)) {
32
+ throw new CliError(`${source} is inside a folder BarnDog installs into. Keep your workspace somewhere else.`);
33
+ }
34
+ desired.push({ id, harness, source, target });
35
+ }
36
+ };
37
+ const stage = async ({ id, kind, name, source, rename, versionId, }) => {
38
+ const path = installedPath(runtime, kind, name);
39
+ trees.push({
40
+ id,
41
+ kind,
42
+ path,
43
+ source,
44
+ rename,
45
+ versionId,
46
+ fingerprint: packageFingerprint(await desiredEntries(source, rename, input.runtime)),
47
+ });
48
+ return path;
49
+ };
50
+ const folders = hookFolders(effective.assets
51
+ .filter(({ asset, enabled }) => enabled &&
52
+ asset.kind === "hook" &&
53
+ !vanished.has(asset.id) &&
54
+ (!invalid.has(asset.id) ||
55
+ installed.some((tree) => tree.id === asset.id)))
56
+ .map(({ asset }) => {
57
+ const tree = installed.find((entry) => entry.id === asset.id);
58
+ const folder = tree && basename(tree.path);
59
+ if (!folder) {
60
+ return asset;
61
+ }
62
+ return invalid.has(asset.id)
63
+ ? { ...asset, kept: folder }
64
+ : { ...asset, current: folder };
65
+ }), localNames);
66
+ for (const chosen of effective.assets) {
67
+ const ref = chosen.asset;
68
+ if (ids.has(ref.id)) {
69
+ throw new Error("A catalog asset has the same ID as a local one");
70
+ }
71
+ ids.add(ref.id);
72
+ if (!chosen.enabled) {
73
+ events.push({ type: "disabled", id: ref.id });
74
+ continue;
75
+ }
76
+ if (skipped.has(ref.id)) {
77
+ continue;
78
+ }
79
+ const reason = invalid.get(ref.id);
80
+ if (reason) {
81
+ // Nothing validates a repo before merge, so a bad change must not uninstall what works.
82
+ events.push({
83
+ type: "invalid",
84
+ kind: ref.kind,
85
+ name: ref.name,
86
+ reason,
87
+ });
88
+ if (vanished.has(ref.id)) {
89
+ continue;
90
+ }
91
+ for (const link of links.filter((l) => l.id === ref.id)) {
92
+ desired.push(link);
93
+ names.add(basename(link.target));
94
+ }
95
+ native.push(...previousNative.filter((entry) => entry.id === ref.id));
96
+ const tree = installed.find((entry) => entry.id === ref.id);
97
+ if (tree) {
98
+ trees.push({
99
+ id: tree.id,
100
+ kind: tree.kind,
101
+ path: tree.path,
102
+ source: tree.path,
103
+ rename: null,
104
+ fingerprint: tree.fingerprint,
105
+ versionId: tree.versionId,
106
+ });
107
+ }
108
+ continue;
109
+ }
110
+ // Without a source the catalog is empty, so this never runs.
111
+ if (!source) {
112
+ throw new Error("Catalog assets need a workspace source");
113
+ }
114
+ const name = installedName(ref, localNames);
115
+ if (ref.kind === "skill") {
116
+ const cache = await source.packageFolder("skill", ref);
117
+ addSkill(ref.id, await stage({
118
+ id: ref.id,
119
+ kind: "skill",
120
+ name,
121
+ source: cache,
122
+ rename: name === ref.name ? null : name,
123
+ versionId: ref.publishedVersion,
124
+ }), name);
125
+ }
126
+ else if (ref.kind === "mcp") {
127
+ const definition = await source.mcpDefinition(ref);
128
+ for (const harness of harnesses) {
129
+ native.push(mcpEntry(harness, { id: ref.id, name }, definition, runtime));
130
+ }
131
+ }
132
+ else {
133
+ const cache = await source.packageFolder("hook", ref);
134
+ const manifest = hookManifestSchema.parse(parse(await readFile(join(cache, "hook.yaml"), "utf8")));
135
+ // Hook folders are internal, so collisions are settled without prompting.
136
+ const root = await stage({
137
+ id: ref.id,
138
+ kind: "hook",
139
+ name: defined(folders.get(ref.id), `No Hook folder chosen for ${ref.id}`),
140
+ source: cache,
141
+ rename: null,
142
+ versionId: ref.publishedVersion,
143
+ });
144
+ const registered = await hookRegistrations(harnesses, { id: ref.id, name: ref.name, root, manifest }, runtime);
145
+ native.push(...registered.native);
146
+ events.push(...registered.events);
147
+ }
148
+ }
149
+ return { links: desired, native, trees, events };
150
+ }
151
+ /**
152
+ * A Hook's registrations for each selected tool, and an `unsupported` event
153
+ * for each tool it can't run in.
154
+ */
155
+ async function hookRegistrations(harnesses, hook, runtime) {
156
+ const native = [];
157
+ const events = [];
158
+ const unsupported = (harness, reason) => events.push({
159
+ type: "unsupported",
160
+ kind: "hook",
161
+ harness,
162
+ name: hook.name,
163
+ reason,
164
+ });
165
+ for (const harness of harnesses) {
166
+ if (!isHookHarness(harness)) {
167
+ unsupported(harness, `${adapters[harness].name} has no command hooks`);
168
+ continue;
169
+ }
170
+ const reason = await hookIssue(harness, hook.manifest, runtime);
171
+ if (reason !== null) {
172
+ unsupported(harness, reason);
173
+ continue;
174
+ }
175
+ native.push(...hookEntries(harness, hook, runtime));
176
+ }
177
+ return { native, events };
178
+ }