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,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,202 @@
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 { secretRefs } from "../../harnesses/formats.js";
9
+ import { isInside } from "../../shared/files.js";
10
+ import { defined } from "../../shared/lookup.js";
11
+ import { hookEntries, hookIssue, mcpEntry } from "../native/adapters.js";
12
+ import { desiredEntries, installedPath } from "../workspace/installed.js";
13
+ import { hookFolders, installedName } from "./names.js";
14
+ /**
15
+ * One event per variable that installed MCP servers refer to but that has no
16
+ * value here: BarnDog doesn't keep it and this environment doesn't set it.
17
+ */
18
+ function unsetVariables(servers, kept, env) {
19
+ const unset = new Map();
20
+ for (const { name, definition } of servers) {
21
+ for (const { secretRef } of Object.values(secretRefs(definition))) {
22
+ if (kept[secretRef] === undefined && !env[secretRef]) {
23
+ unset.set(secretRef, [...(unset.get(secretRef) ?? []), name]);
24
+ }
25
+ }
26
+ }
27
+ return [...unset].map(([variable, names]) => ({
28
+ type: "unset-variable",
29
+ variable,
30
+ servers: names,
31
+ }));
32
+ }
33
+ export async function stageAssets(input) {
34
+ const { invalid, vanished, skipped, localNames, source, harnesses, runtime } = input;
35
+ const { home } = runtime;
36
+ const effective = { assets: input.assets };
37
+ const { links, native: previousNative, installed } = input.state;
38
+ const desired = [];
39
+ const native = [];
40
+ const trees = [];
41
+ const events = [];
42
+ const names = new Set();
43
+ const ids = new Set();
44
+ /** Installed MCP servers, to report the variables they find no value for. */
45
+ const servers = [];
46
+ const addSkill = (id, source, name) => {
47
+ if (names.has(name)) {
48
+ throw new CliError(`Two enabled Skills are named ${name}`, "barndog doctor");
49
+ }
50
+ names.add(name);
51
+ for (const harness of harnesses) {
52
+ const target = resolve(skillDirectory(harness, home), name);
53
+ if (isInside(source, target) || isInside(target, source)) {
54
+ throw new CliError(`${source} is inside a folder BarnDog installs into. Keep your workspace somewhere else.`);
55
+ }
56
+ desired.push({ id, harness, source, target });
57
+ }
58
+ };
59
+ const stage = async ({ id, kind, name, source, rename, versionId, }) => {
60
+ const path = installedPath(runtime, kind, name);
61
+ trees.push({
62
+ id,
63
+ kind,
64
+ path,
65
+ source,
66
+ rename,
67
+ versionId,
68
+ fingerprint: packageFingerprint(await desiredEntries(source, rename, input.runtime)),
69
+ });
70
+ return path;
71
+ };
72
+ const folders = hookFolders(effective.assets
73
+ .filter(({ asset, enabled }) => enabled &&
74
+ asset.kind === "hook" &&
75
+ !vanished.has(asset.id) &&
76
+ (!invalid.has(asset.id) ||
77
+ installed.some((tree) => tree.id === asset.id)))
78
+ .map(({ asset }) => {
79
+ const tree = installed.find((entry) => entry.id === asset.id);
80
+ const folder = tree && basename(tree.path);
81
+ if (!folder) {
82
+ return asset;
83
+ }
84
+ return invalid.has(asset.id)
85
+ ? { ...asset, kept: folder }
86
+ : { ...asset, current: folder };
87
+ }), localNames);
88
+ for (const chosen of effective.assets) {
89
+ const ref = chosen.asset;
90
+ if (ids.has(ref.id)) {
91
+ throw new Error("A catalog asset has the same ID as a local one");
92
+ }
93
+ ids.add(ref.id);
94
+ if (!chosen.enabled) {
95
+ events.push({ type: "disabled", id: ref.id });
96
+ continue;
97
+ }
98
+ if (skipped.has(ref.id)) {
99
+ continue;
100
+ }
101
+ const reason = invalid.get(ref.id);
102
+ if (reason) {
103
+ // Nothing validates a repo before merge, so a bad change must not uninstall what works.
104
+ events.push({
105
+ type: "invalid",
106
+ kind: ref.kind,
107
+ name: ref.name,
108
+ reason,
109
+ });
110
+ if (vanished.has(ref.id)) {
111
+ continue;
112
+ }
113
+ for (const link of links.filter((l) => l.id === ref.id)) {
114
+ desired.push(link);
115
+ names.add(basename(link.target));
116
+ }
117
+ native.push(...previousNative.filter((entry) => entry.id === ref.id));
118
+ const tree = installed.find((entry) => entry.id === ref.id);
119
+ if (tree) {
120
+ trees.push({
121
+ id: tree.id,
122
+ kind: tree.kind,
123
+ path: tree.path,
124
+ source: tree.path,
125
+ rename: null,
126
+ fingerprint: tree.fingerprint,
127
+ versionId: tree.versionId,
128
+ });
129
+ }
130
+ continue;
131
+ }
132
+ // Without a source the catalog is empty, so this never runs.
133
+ if (!source) {
134
+ throw new Error("Catalog assets need a workspace source");
135
+ }
136
+ const name = installedName(ref, localNames);
137
+ if (ref.kind === "skill") {
138
+ const cache = await source.packageFolder("skill", ref);
139
+ addSkill(ref.id, await stage({
140
+ id: ref.id,
141
+ kind: "skill",
142
+ name,
143
+ source: cache,
144
+ rename: name === ref.name ? null : name,
145
+ versionId: ref.publishedVersion,
146
+ }), name);
147
+ }
148
+ else if (ref.kind === "mcp") {
149
+ const definition = await source.mcpDefinition(ref);
150
+ servers.push({ name, definition });
151
+ for (const harness of harnesses) {
152
+ native.push(mcpEntry(harness, { id: ref.id, name, definition }, input.kept, runtime));
153
+ }
154
+ }
155
+ else {
156
+ const cache = await source.packageFolder("hook", ref);
157
+ const manifest = hookManifestSchema.parse(parse(await readFile(join(cache, "hook.yaml"), "utf8")));
158
+ // Hook folders are internal, so collisions are settled without prompting.
159
+ const root = await stage({
160
+ id: ref.id,
161
+ kind: "hook",
162
+ name: defined(folders.get(ref.id), `No Hook folder chosen for ${ref.id}`),
163
+ source: cache,
164
+ rename: null,
165
+ versionId: ref.publishedVersion,
166
+ });
167
+ const registered = await hookRegistrations(harnesses, { id: ref.id, name: ref.name, root, manifest }, runtime);
168
+ native.push(...registered.native);
169
+ events.push(...registered.events);
170
+ }
171
+ }
172
+ events.push(...unsetVariables(servers, input.kept, input.runtime.env));
173
+ return { links: desired, native, trees, events };
174
+ }
175
+ /**
176
+ * A Hook's registrations for each selected tool, and an `unsupported` event
177
+ * for each tool it can't run in.
178
+ */
179
+ async function hookRegistrations(harnesses, hook, runtime) {
180
+ const native = [];
181
+ const events = [];
182
+ const unsupported = (harness, reason) => events.push({
183
+ type: "unsupported",
184
+ kind: "hook",
185
+ harness,
186
+ name: hook.name,
187
+ reason,
188
+ });
189
+ for (const harness of harnesses) {
190
+ if (!isHookHarness(harness)) {
191
+ unsupported(harness, `${adapters[harness].name} has no command hooks`);
192
+ continue;
193
+ }
194
+ const reason = await hookIssue(harness, hook.manifest, runtime);
195
+ if (reason !== null) {
196
+ unsupported(harness, reason);
197
+ continue;
198
+ }
199
+ native.push(...hookEntries(harness, hook, runtime));
200
+ }
201
+ return { native, events };
202
+ }