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,13 +1,57 @@
1
+ import { hookSpecificContext, nestedHookEntry, secretRefs } from "./formats.js";
2
+ /**
3
+ * Codex forwards variables by name (`env_vars`, `env_http_headers`) instead of
4
+ * interpolating references, so secrets stay out of `config.toml`. It can't give
5
+ * a stdio server a variable under another name; BarnDog's launcher does that.
6
+ */
7
+ function mcpServer(definition, launcher) {
8
+ const refs = secretRefs(definition);
9
+ const variables = Object.values(refs).map((ref) => ref.secretRef);
10
+ if (definition.transport === "http") {
11
+ return {
12
+ url: definition.url,
13
+ ...(variables.length
14
+ ? {
15
+ env_http_headers: Object.fromEntries(Object.entries(refs).map(([name, ref]) => [name, ref.secretRef])),
16
+ }
17
+ : {}),
18
+ };
19
+ }
20
+ const renamed = Object.entries(refs).some(([name, ref]) => name !== ref.secretRef);
21
+ if (renamed) {
22
+ return {
23
+ command: process.execPath,
24
+ args: [
25
+ launcher,
26
+ Buffer.from(JSON.stringify(definition)).toString("base64url"),
27
+ ],
28
+ env_vars: variables,
29
+ };
30
+ }
31
+ return {
32
+ command: definition.command,
33
+ args: definition.args,
34
+ env_vars: variables,
35
+ };
36
+ }
1
37
  const toolMatcher = "Tool name, such as Bash or Edit|Write. Leave empty for all";
2
38
  export const codex = {
3
39
  id: "codex",
4
40
  name: "Codex",
5
41
  skillRoot: ".agents/skills",
6
42
  commands: ["codex"],
7
- macApp: "Codex.app",
43
+ desktopApp: { name: "Codex" },
8
44
  hooks: {
9
45
  settings: [/(^|\/)\.codex\/hooks\.json$/, /(^|\/)\.codex\/config\.toml$/],
46
+ // Recent Codex runs hooks in the session shell, PowerShell on Windows;
47
+ // older releases (such as 0.142) used cmd.exe, where these lines fail.
48
+ windowsShell: "powershell",
10
49
  rootVariables: ["PLUGIN_ROOT"],
50
+ file: ".codex/hooks.json",
51
+ sessionStart: "SessionStart",
52
+ entry: nestedHookEntry,
53
+ sessionContext: hookSpecificContext,
54
+ trustNote: "Codex skips new Hooks until you trust them with /hooks.",
11
55
  events: [
12
56
  {
13
57
  name: "SessionStart",
@@ -43,4 +87,16 @@ export const codex = {
43
87
  { name: "SessionEnd" },
44
88
  ],
45
89
  },
90
+ mcp: {
91
+ file: ".codex/config.toml",
92
+ files: [".codex/config.toml"],
93
+ path: ["mcp_servers"],
94
+ server: mcpServer,
95
+ login: { command: ["codex", "mcp", "login"] },
96
+ },
97
+ configHome: {
98
+ variable: "CODEX_HOME",
99
+ directory: ".codex",
100
+ defaultIsSupported: true,
101
+ },
46
102
  };
@@ -1,16 +1,27 @@
1
+ import { jsonMcpServer } from "./formats.js";
1
2
  const toolMatcher = "Tool type, such as Shell, Read or Write";
2
3
  export const cursor = {
3
4
  id: "cursor",
4
5
  name: "Cursor",
5
6
  skillRoot: ".cursor/skills",
6
7
  commands: ["cursor", "cursor-agent"],
7
- macApp: "Cursor.app",
8
+ desktopApp: { name: "Cursor" },
8
9
  hooks: {
9
10
  settings: [
10
11
  /(^|\/)\.cursor\/hooks\.json$/,
11
12
  /(^|\/)hooks\/hooks-cursor\.json$/,
12
13
  ],
14
+ // Cursor's desktop app runs hook commands through PowerShell.
15
+ windowsShell: "powershell",
13
16
  rootVariables: ["CURSOR_PLUGIN_ROOT"],
17
+ file: ".cursor/hooks.json",
18
+ fileVersion: 1,
19
+ sessionStart: "sessionStart",
20
+ entry: (command, matcher) => ({
21
+ command,
22
+ ...(matcher ? { matcher } : {}),
23
+ }),
24
+ sessionContext: (text) => ({ additional_context: text }),
14
25
  events: [
15
26
  { name: "sessionStart" },
16
27
  { name: "sessionEnd" },
@@ -41,4 +52,14 @@ export const cursor = {
41
52
  { name: "stop" },
42
53
  ],
43
54
  },
55
+ mcp: {
56
+ file: ".cursor/mcp.json",
57
+ files: [".cursor/mcp.json"],
58
+ path: ["mcpServers"],
59
+ server: (definition) => jsonMcpServer(definition, {
60
+ reference: (variable) => `\${env:${variable}}`,
61
+ typed: false,
62
+ }),
63
+ login: { settings: "Settings → MCP" },
64
+ },
44
65
  };
@@ -1,61 +1,17 @@
1
- import { access, stat } from "node:fs/promises";
2
- import { constants } from "node:fs";
3
- import { homedir } from "node:os";
4
- import { delimiter, join } from "node:path";
5
1
  import { harnesses, adapters } from "./registry.js";
6
- async function exists(path, directory = false) {
7
- try {
8
- const info = await stat(path);
9
- if (directory)
10
- return info.isDirectory();
11
- await access(path, constants.X_OK);
12
- return info.isFile();
13
- }
14
- catch (error) {
15
- if (["ENOENT", "ENOTDIR", "EACCES"].includes(error.code ?? ""))
16
- return false;
17
- throw error;
18
- }
19
- }
2
+ import { findExecutable, installedApplication } from "../platform.js";
20
3
  /** Inspect installation evidence; never execute harnesses or infer installation from skill directories. */
21
- export async function detectHarnesses(options = {}) {
22
- const home = options.home ?? homedir();
23
- const platform = options.platform ?? process.platform;
24
- const directories = (options.path ?? process.env.PATH ?? "")
25
- .split(delimiter)
26
- .filter(Boolean);
27
- const appDirectories = options.appDirectories ?? [
28
- "/Applications",
29
- join(home, "Applications"),
30
- ];
31
- const extensions = platform === "win32" ? ["", ".exe", ".cmd", ".bat"] : [""];
4
+ export async function detectHarnesses(runtime, options = {}) {
32
5
  return Promise.all(harnesses.map(async (id) => {
33
6
  const installation = adapters[id];
34
7
  let evidence = null;
35
- for (const directory of directories) {
36
- for (const command of installation.commands) {
37
- for (const extension of extensions) {
38
- const candidate = join(directory, `${command}${extension}`);
39
- if (await exists(candidate)) {
40
- evidence = candidate;
41
- break;
42
- }
43
- }
44
- if (evidence)
45
- break;
46
- }
47
- if (evidence)
8
+ for (const command of installation.commands) {
9
+ evidence = await findExecutable(command, runtime);
10
+ if (evidence) {
48
11
  break;
49
- }
50
- if (!evidence && platform === "darwin") {
51
- for (const directory of appDirectories) {
52
- const candidate = join(directory, installation.macApp);
53
- if (await exists(join(candidate, "Contents", "MacOS"), true)) {
54
- evidence = candidate;
55
- break;
56
- }
57
12
  }
58
13
  }
14
+ evidence ??= await installedApplication(installation.desktopApp, runtime, options.appDirectories);
59
15
  return { id, name: installation.name, evidence };
60
16
  }));
61
17
  }
@@ -0,0 +1,45 @@
1
+ /** The secret references of a definition: environment for stdio, headers for HTTP. */
2
+ export const secretRefs = (definition) => definition.transport === "stdio"
3
+ ? definition.environment
4
+ : definition.headers;
5
+ /**
6
+ * A server entry for a tool that keeps `mcpServers` in JSON, as Claude Code and
7
+ * Cursor do. They differ in how a value refers to a local environment variable
8
+ * and in whether an entry must name its transport in `type`.
9
+ */
10
+ export function jsonMcpServer(definition, format) {
11
+ const references = Object.fromEntries(Object.entries(secretRefs(definition)).map(([name, ref]) => [
12
+ name,
13
+ format.reference(ref.secretRef),
14
+ ]));
15
+ const type = format.typed ? { type: definition.transport } : {};
16
+ const some = Object.keys(references).length > 0;
17
+ if (definition.transport === "http") {
18
+ return {
19
+ ...type,
20
+ url: definition.url,
21
+ ...(some ? { headers: references } : {}),
22
+ };
23
+ }
24
+ return {
25
+ ...type,
26
+ command: definition.command,
27
+ args: definition.args,
28
+ ...(some ? { env: references } : {}),
29
+ };
30
+ }
31
+ /**
32
+ * A command handler nested under a matcher group, the shape Claude Code and
33
+ * Codex share: `{ matcher, hooks: [{ type: "command", command }] }`.
34
+ */
35
+ export const nestedHookEntry = (command, matcher) => ({
36
+ ...(matcher ? { matcher } : {}),
37
+ hooks: [{ type: "command", command }],
38
+ });
39
+ /** The session-start output Claude Code and Codex read added context from. */
40
+ export const hookSpecificContext = (text) => ({
41
+ hookSpecificOutput: {
42
+ hookEventName: "SessionStart",
43
+ additionalContext: text,
44
+ },
45
+ });
@@ -0,0 +1,111 @@
1
+ import { VARIABLE_NAME } from "../shared/patterns.js";
2
+ import { asRecord, asStrings } from "../shared/values.js";
3
+ import { secretRefs } from "./formats.js";
4
+ /**
5
+ * OpenCode's server entry (`mcp.servers.<name>` in opencode.jsonc): a stdio
6
+ * server is `local` with the program and its arguments in one `command` list,
7
+ * an HTTP server is `remote`. Values refer to a local variable as `{env:NAME}`.
8
+ */
9
+ function mcpServer(definition) {
10
+ const references = Object.fromEntries(Object.entries(secretRefs(definition)).map(([name, ref]) => [
11
+ name,
12
+ `{env:${ref.secretRef}}`,
13
+ ]));
14
+ const some = Object.keys(references).length > 0;
15
+ if (definition.transport === "http") {
16
+ return {
17
+ type: "remote",
18
+ url: definition.url,
19
+ ...(some ? { headers: references } : {}),
20
+ };
21
+ }
22
+ return {
23
+ type: "local",
24
+ command: [definition.command, ...definition.args],
25
+ ...(some ? { environment: references } : {}),
26
+ };
27
+ }
28
+ /** OpenCode's reference to a local variable inside a value: `Bearer {env:TOKEN}`. */
29
+ const OPENCODE_REFERENCE = new RegExp(String.raw `\{env:(${VARIABLE_NAME.source})\}`, "g");
30
+ /**
31
+ * A value with OpenCode's `{env:NAME}` references spelled `${NAME}`, as
32
+ * Claude Code writes them: `Bearer {env:TOKEN}` → `Bearer ${TOKEN}`.
33
+ *
34
+ * @internal Exported for its table test in `src/tests/patterns.test.ts`.
35
+ */
36
+ export const bracedReferences = (value) => value.replaceAll(OPENCODE_REFERENCE, (_, name) => `\${${name}}`);
37
+ /** Every string value of a map, with its references respelled. */
38
+ const respelled = (values) => Object.fromEntries(Object.entries(asRecord(values)).map(([key, value]) => [
39
+ key,
40
+ typeof value === "string" ? bracedReferences(value) : value,
41
+ ]));
42
+ /**
43
+ * An OpenCode entry in Claude Code's shape. A remote server with an `oauth`
44
+ * object signs in; `oauth: false` or none leaves that to its headers.
45
+ */
46
+ function importedServer(entry) {
47
+ if (entry.type === "remote") {
48
+ return {
49
+ url: entry.url,
50
+ headers: respelled(entry.headers),
51
+ ...(entry.oauth ? { oauth: true } : {}),
52
+ };
53
+ }
54
+ const [command, ...args] = asStrings(entry.command);
55
+ return { command, args, env: respelled(entry.environment) };
56
+ }
57
+ /**
58
+ * OpenCode keeps its user settings in `~/.config/opencode` on every platform
59
+ * (or under `XDG_CONFIG_HOME`). It has no command hooks: BarnDog's
60
+ * session-start work runs from a plugin module OpenCode loads from
61
+ * `plugins/`, and Hook assets don't apply to it.
62
+ */
63
+ export const opencode = {
64
+ id: "opencode",
65
+ name: "OpenCode",
66
+ skillRoot: ".config/opencode/skills",
67
+ commands: ["opencode"],
68
+ // OpenCode Desktop's electron-builder build: OpenCode.app; a per-user NSIS
69
+ // install, whose folder is the package name `@opencode-ai/desktop` with the
70
+ // slash dropped; and deb/rpm packages whose entry is named after the app ID.
71
+ desktopApp: {
72
+ name: "OpenCode",
73
+ windowsFolder: "@opencode-aidesktop",
74
+ linuxEntry: "ai.opencode.desktop",
75
+ },
76
+ plugin: {
77
+ file: ".config/opencode/plugins/barndog.js",
78
+ entryScript: "opencode-plugin",
79
+ // OpenCode's plugin loader takes a default export of `{ id, server }`.
80
+ module: (entry, options) => [
81
+ "// Written by barndog sync, which rewrites or removes it. Sync stops if this file is edited by hand.",
82
+ `import { barndog } from ${JSON.stringify(entry)};`,
83
+ "",
84
+ `export default { id: "barndog", server: barndog(${JSON.stringify(options)}) };`,
85
+ "",
86
+ ].join("\n"),
87
+ },
88
+ mcp: {
89
+ // The file OpenCode creates on first run and reads last, so it wins.
90
+ file: ".config/opencode/opencode.jsonc",
91
+ // Known limitation: BarnDog supports only the latest OpenCode, so it reads
92
+ // and writes `mcp.servers` alone. OpenCode still accepts a server written
93
+ // straight under `mcp` (the older shape), and BarnDog neither imports those
94
+ // nor notices one with the same name as a server it installs.
95
+ path: ["mcp", "servers"],
96
+ // OpenCode merges these in this order, a later file winning.
97
+ files: [
98
+ ".config/opencode/config.json",
99
+ ".config/opencode/opencode.json",
100
+ ".config/opencode/opencode.jsonc",
101
+ ],
102
+ server: mcpServer,
103
+ imported: importedServer,
104
+ login: { command: ["opencode", "mcp", "auth"] },
105
+ },
106
+ configHome: {
107
+ variable: "XDG_CONFIG_HOME",
108
+ directory: ".config",
109
+ defaultIsSupported: true,
110
+ },
111
+ };
@@ -1,16 +1,49 @@
1
- import { resolve } from "node:path";
2
1
  import { claude } from "./claude.js";
3
2
  import { codex } from "./codex.js";
4
3
  import { cursor } from "./cursor.js";
5
- export const harnesses = ["claude", "codex", "cursor"];
4
+ import { opencode } from "./opencode.js";
5
+ import { join, resolve } from "node:path";
6
+ export const harnesses = ["claude", "codex", "cursor", "opencode"];
7
+ /** The tools with command hooks, in the order `harnesses` lists them. */
8
+ export const hookHarnesses = ["claude", "codex", "cursor"];
6
9
  export const adapters = {
7
10
  claude,
8
11
  codex,
9
12
  cursor,
13
+ opencode,
10
14
  };
11
15
  export function isHarness(value) {
12
16
  return (typeof value === "string" && harnesses.some((harness) => harness === value));
13
17
  }
18
+ export function isHookHarness(value) {
19
+ return (typeof value === "string" &&
20
+ hookHarnesses.some((harness) => harness === value));
21
+ }
22
+ /**
23
+ * The harness whose hook settings live at a repository path, such as
24
+ * `.claude/settings.json` (Claude Code) or `.codex/config.toml` (Codex);
25
+ * undefined for any other file.
26
+ */
27
+ export function hookSettingsOwner(path) {
28
+ return hookHarnesses.find((harness) => adapters[harness].hooks.settings.some((pattern) => pattern.test(path)));
29
+ }
14
30
  export function skillDirectory(harness, home) {
15
31
  return resolve(home, adapters[harness].skillRoot);
16
32
  }
33
+ /**
34
+ * What BarnDog writes into a coding tool's own settings files: MCP servers,
35
+ * Hooks, the knowledge index and the sync reminder.
36
+ */
37
+ export const nativeKinds = ["mcp", "hook", "knowledge", "sync"];
38
+ /**
39
+ * Resolves the native settings file under the supplied home. MCP entries go to
40
+ * the tool's MCP file; the rest to its hook settings, or for a tool without
41
+ * command hooks, to BarnDog's plugin module.
42
+ */
43
+ export function nativeFile(harness, kind, home) {
44
+ const adapter = adapters[harness];
45
+ if (kind === "mcp") {
46
+ return join(home, adapter.mcp.file);
47
+ }
48
+ return join(home, adapter.hooks ? adapter.hooks.file : adapter.plugin.file);
49
+ }