barndog 0.2.1 → 0.2.3

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 (92) hide show
  1. package/README.md +21 -0
  2. package/dist/cli.js +29 -3
  3. package/dist/commands/add.js +4 -2
  4. package/dist/commands/asset-install.js +7 -3
  5. package/dist/commands/asset-list.js +5 -1
  6. package/dist/commands/asset-share.js +15 -3
  7. package/dist/commands/capabilities.js +23 -5
  8. package/dist/commands/collaboration.js +9 -3
  9. package/dist/commands/harnesses.js +33 -3
  10. package/dist/commands/hooks.js +16 -1
  11. package/dist/commands/mcp-env.js +159 -43
  12. package/dist/commands/mcp.js +13 -3
  13. package/dist/commands/origin.js +7 -4
  14. package/dist/commands/sets.js +16 -5
  15. package/dist/commands/status.js +3 -1
  16. package/dist/commands/sync.js +1 -1
  17. package/dist/commands/uninstall.js +64 -0
  18. package/dist/commands/workspace.js +19 -0
  19. package/dist/config/paths.js +2 -0
  20. package/dist/config/state.js +19 -0
  21. package/dist/entry/update-check.js +15 -0
  22. package/dist/errors.js +4 -0
  23. package/dist/features/adoption/adopt.js +47 -29
  24. package/dist/features/adoption/scan.js +5 -0
  25. package/dist/features/asset-kinds/url-query.js +26 -0
  26. package/dist/features/auth/session.js +22 -0
  27. package/dist/features/collaboration/workspace-store.js +2 -1
  28. package/dist/features/doctor/check.js +1 -0
  29. package/dist/features/doctor/grouped.js +127 -0
  30. package/dist/features/doctor/index.js +29 -27
  31. package/dist/features/environment/events.js +18 -1
  32. package/dist/features/environment/kept-value-events.js +40 -0
  33. package/dist/features/environment/kept-values.js +68 -0
  34. package/dist/features/environment/mcp-records.js +57 -0
  35. package/dist/features/environment/moves.js +17 -1
  36. package/dist/features/environment/stage.js +32 -28
  37. package/dist/features/environment/sync.js +13 -3
  38. package/dist/features/environment/writes.js +25 -27
  39. package/dist/features/hooks/compatibility.js +37 -17
  40. package/dist/features/hooks/test.js +2 -2
  41. package/dist/features/inventory/hook-matrix.js +14 -0
  42. package/dist/features/inventory/hook-readiness.js +47 -0
  43. package/dist/features/inventory/index.js +54 -3
  44. package/dist/features/inventory/show.js +10 -2
  45. package/dist/features/mcps/import.js +74 -21
  46. package/dist/features/mcps/index.js +28 -5
  47. package/dist/features/mcps/values.js +161 -23
  48. package/dist/features/migration/migrate.js +15 -0
  49. package/dist/features/migration/move.js +38 -9
  50. package/dist/features/migration/promote.js +1 -0
  51. package/dist/features/native/adapters.js +5 -46
  52. package/dist/features/native/hook-shell.js +11 -0
  53. package/dist/features/native/requirements.js +98 -0
  54. package/dist/features/secrets/index.js +95 -29
  55. package/dist/features/uninstall/index.js +126 -0
  56. package/dist/features/uninstall/leave.js +152 -0
  57. package/dist/features/uninstall/survey.js +103 -0
  58. package/dist/features/update-check/index.js +108 -0
  59. package/dist/features/workspace/cloud-source.js +38 -4
  60. package/dist/features/workspace/format.js +6 -1
  61. package/dist/harnesses/claude.js +1 -1
  62. package/dist/harnesses/codex.js +46 -22
  63. package/dist/harnesses/cursor.js +1 -1
  64. package/dist/harnesses/opencode.js +1 -1
  65. package/dist/harnesses/read-renamed-variables.js +141 -0
  66. package/dist/harnesses/renamed-variables.js +99 -0
  67. package/dist/platform.js +12 -1
  68. package/dist/program.js +24 -9
  69. package/dist/ui/add-hook.js +2 -2
  70. package/dist/ui/add-mcp.js +54 -16
  71. package/dist/ui/add-skills.js +2 -2
  72. package/dist/ui/adopt.js +90 -19
  73. package/dist/ui/assets.js +15 -2
  74. package/dist/ui/collaboration.js +5 -3
  75. package/dist/ui/connection.js +2 -0
  76. package/dist/ui/format.js +81 -2
  77. package/dist/ui/harness-picker.js +7 -2
  78. package/dist/ui/hook-compatibility.js +176 -22
  79. package/dist/ui/mcp.js +169 -24
  80. package/dist/ui/move.js +3 -2
  81. package/dist/ui/onboarding.js +11 -2
  82. package/dist/ui/output.js +116 -37
  83. package/dist/ui/package-details.js +7 -2
  84. package/dist/ui/pick.js +20 -6
  85. package/dist/ui/secret-input.js +9 -0
  86. package/dist/ui/selection.js +1 -1
  87. package/dist/ui/uninstall.js +186 -0
  88. package/dist/ui/update.js +10 -0
  89. package/dist/ui/variable-problems.js +23 -0
  90. package/dist/version.js +2 -2
  91. package/package.json +2 -2
  92. package/dist/entry/mcp-launch.js +0 -71
@@ -6,6 +6,7 @@ import { assetKinds } from "../asset-kinds/index.js";
6
6
  import { patchNative } from "../native/configuration.js";
7
7
  import { recordedVariables, redacted, sameValue, } from "../native/secret-values.js";
8
8
  import { inPluginModule, pluginModule } from "../native/plugin-module.js";
9
+ import { keptValueEvents } from "./kept-value-events.js";
9
10
  import { linkTarget } from "./transaction.js";
10
11
  function changeType(change) {
11
12
  if (!change.sameAsset) {
@@ -116,38 +117,30 @@ const sameEntry = (left, right) => left.id === right.id &&
116
117
  left.file === right.file &&
117
118
  left.key === right.key &&
118
119
  sameValue(left.value, right.value);
119
- /** A notice for kept values a changed entry no longer holds. */
120
- function removedSecrets(entry, still) {
120
+ /** The kept values a changed entry no longer holds. */
121
+ function removedKeptValues(entry, still, nameOf) {
121
122
  const gone = recordedVariables(entry.value).filter((variable) => !still.includes(variable));
122
- return gone.length
123
- ? [
124
- {
125
- type: "notice",
126
- message: `Removed the kept ${plural(gone)} ${gone.join(", ")} from ${entry.file}.`,
127
- },
128
- ]
129
- : [];
123
+ return {
124
+ action: "removed",
125
+ server: nameOf(entry),
126
+ file: entry.file,
127
+ variables: gone,
128
+ };
130
129
  }
131
- /** Says where kept values were written, and where they were taken out. */
132
- function secretNotices(entry, old, changed, nameOf) {
133
- if (!changed) {
134
- return [];
135
- }
130
+ /** Where a changed entry's kept values were written, and where they were taken out. */
131
+ function keptValueWrites(entry, old, nameOf) {
136
132
  const written = (entry.secrets ?? []).map((secret) => secret.variable);
137
133
  const before = old.find((e) => e.id === entry.id && e.harness === entry.harness);
138
134
  return [
139
- ...(written.length
140
- ? [
141
- {
142
- type: "notice",
143
- message: `Wrote the kept ${plural(written)} ${written.join(", ")} into ${entry.file} for ${nameOf(entry)}. ${written.length === 1 ? "It stays" : "They stay"} on this machine.`,
144
- },
145
- ]
146
- : []),
147
- ...(before ? removedSecrets(before, written) : []),
135
+ {
136
+ action: "wrote",
137
+ server: nameOf(entry),
138
+ file: entry.file,
139
+ variables: written,
140
+ },
141
+ ...(before ? [removedKeptValues(before, written, nameOf)] : []),
148
142
  ];
149
143
  }
150
- const plural = (variables) => variables.length === 1 ? "value of" : "values of";
151
144
  /**
152
145
  * One write per native settings file that holds, or will hold, an entry of
153
146
  * BarnDog's. `nameOf` gives the name an entry is reported under.
@@ -156,6 +149,7 @@ export async function nativeWrites(previous, desired, context) {
156
149
  const { trees, updated, nameOf, platform } = context;
157
150
  const writes = [];
158
151
  const events = [];
152
+ const keptValues = [];
159
153
  for (const file of new Set([
160
154
  ...previous.map((e) => e.file),
161
155
  ...desired.map((e) => e.file),
@@ -185,7 +179,9 @@ export async function nativeWrites(previous, desired, context) {
185
179
  harness: entry.harness,
186
180
  name: nameOf(entry),
187
181
  });
188
- events.push(...secretNotices(entry, old, action !== "unchanged", nameOf));
182
+ if (action !== "unchanged") {
183
+ keptValues.push(...keptValueWrites(entry, old, nameOf));
184
+ }
189
185
  }
190
186
  for (const entry of old) {
191
187
  if (!next.some((e) => sameEntry(e, entry) ||
@@ -197,10 +193,11 @@ export async function nativeWrites(previous, desired, context) {
197
193
  harness: entry.harness,
198
194
  name: nameOf(entry),
199
195
  });
200
- events.push(...removedSecrets(entry, []));
196
+ keptValues.push(removedKeptValues(entry, [], nameOf));
201
197
  }
202
198
  }
203
199
  }
200
+ events.push(...keptValueEvents(keptValues));
204
201
  return { writes, events };
205
202
  }
206
203
  /**
@@ -239,5 +236,6 @@ export function stateText(plan) {
239
236
  fingerprint,
240
237
  versionId,
241
238
  })),
239
+ mcpServers: plan.mcpServers,
242
240
  }, null, 2) + "\n");
243
241
  }
@@ -2,7 +2,7 @@ import { hookSchema } from "@barndog-ai/api-contract";
2
2
  import { readSettings } from "../../config/settings.js";
3
3
  import { selectAsset } from "../server/catalog.js";
4
4
  import { repoForOrigin, selectRepoAsset } from "../workspace/assets.js";
5
- import { runtimeRequirements } from "../native/adapters.js";
5
+ import { missingRequirements, skipReason, } from "../native/requirements.js";
6
6
  import { hookHarnesses } from "../../harnesses/registry.js";
7
7
  import { hookMetadata } from "@barndog-ai/api-contract/package";
8
8
  /**
@@ -12,32 +12,37 @@ import { hookMetadata } from "@barndog-ai/api-contract/package";
12
12
  export async function hookCompatibility(name, origin, runtime) {
13
13
  const { home } = runtime;
14
14
  const settings = await readSettings(home);
15
- const managed = (result) => settings
15
+ const repo = settings && repoForOrigin(settings, runtime, origin);
16
+ if (repo) {
17
+ return repoHookCompatibility(selectRepoAsset(await repo.model(), "hook", name, origin), runtime);
18
+ }
19
+ const selected = await selectAsset("hook", name, origin, runtime);
20
+ return cloudHookCompatibility(hookSchema.parse(selected.asset), runtime);
21
+ }
22
+ /** Only the tools this machine has BarnDog manage, once it is set up. */
23
+ async function managed(result, runtime) {
24
+ const settings = await readSettings(runtime.home);
25
+ return settings
16
26
  ? {
17
27
  ...result,
18
28
  compatibility: result.compatibility.filter((row) => settings.harnesses.includes(row.harness)),
19
29
  }
20
30
  : result;
21
- const repo = settings && repoForOrigin(settings, runtime, origin);
22
- if (repo) {
23
- return managed(await repoHookCompatibility(selectRepoAsset(await repo.model(), "hook", name, origin), runtime));
24
- }
25
- const selected = await selectAsset("hook", name, origin, runtime);
26
- const asset = hookSchema.parse(selected.asset);
31
+ }
32
+ /** What a Cloud Hook declares for each coding tool, and what this machine lacks. */
33
+ export async function cloudHookCompatibility(asset, runtime) {
27
34
  return managed({
28
35
  version: asset.version.number,
29
36
  compatibility: await Promise.all(asset.compatibility.map(async (row) => ({
30
37
  ...row,
31
- runtimeIssue: row.implementation
32
- ? await runtimeRequirements(row.harness, row.implementation.requirements, runtime)
33
- : "No implementation for this harness",
38
+ ...(await readiness(row.harness, row.implementation, runtime)),
34
39
  }))),
35
- });
40
+ }, runtime);
36
41
  }
37
42
  /** What a Git or local workspace Hook declares for each coding tool, and what this machine lacks. */
38
- async function repoHookCompatibility(asset, runtime) {
43
+ export async function repoHookCompatibility(asset, runtime) {
39
44
  const manifest = hookMetadata(asset.entries);
40
- return {
45
+ return managed({
41
46
  version: asset.publishedVersion,
42
47
  compatibility: await Promise.all(hookHarnesses.map(async (harness) => {
43
48
  const implementation = manifest.implementations[harness] ?? null;
@@ -46,10 +51,25 @@ async function repoHookCompatibility(asset, runtime) {
46
51
  status: implementation?.compatibility ?? "unsupported",
47
52
  declared: true,
48
53
  implementation,
49
- runtimeIssue: implementation
50
- ? await runtimeRequirements(harness, implementation.requirements, runtime)
51
- : "No implementation for this harness",
54
+ ...(await readiness(harness, implementation, runtime)),
52
55
  };
53
56
  })),
57
+ }, runtime);
58
+ }
59
+ /** What an implementation lacks on this machine, typed and in words. */
60
+ async function readiness(harness, implementation, runtime) {
61
+ if (!implementation) {
62
+ return {
63
+ missingRequirements: [],
64
+ runtimeIssue: skipReason(harness, { type: "no-implementation" }),
65
+ };
66
+ }
67
+ const missing = await missingRequirements(harness, implementation.requirements, runtime);
68
+ const [first] = missing;
69
+ return {
70
+ missingRequirements: missing,
71
+ runtimeIssue: first
72
+ ? skipReason(harness, { type: "missing-requirement", requirement: first })
73
+ : null,
54
74
  };
55
75
  }
@@ -7,7 +7,7 @@ import { parse } from "yaml";
7
7
  import { hookManifestSchema, hookSchema } from "@barndog-ai/api-contract";
8
8
  import { selectAsset } from "../server/catalog.js";
9
9
  import { cachedPackage } from "../workspace/packages.js";
10
- import { runtimeRequirements } from "../native/adapters.js";
10
+ import { requirementFix, requirementMessage, runtimeRequirements, } from "../native/requirements.js";
11
11
  import { hookInvocation } from "../native/hook-shell.js";
12
12
  import { readSettings } from "../../config/settings.js";
13
13
  import { repoForOrigin, selectRepoAsset } from "../workspace/assets.js";
@@ -45,7 +45,7 @@ export async function testHook(name, origin, options, runtime) {
45
45
  }
46
46
  const unmet = await runtimeRequirements(options.harness, implementation.requirements, runtime);
47
47
  if (unmet) {
48
- throw new CliError(unmet);
48
+ throw new CliError(`${name} ${requirementMessage(options.harness, unmet)}.`, requirementFix(options.harness, unmet));
49
49
  }
50
50
  const event = options.event ??
51
51
  (Object.keys(implementation.events).length === 1
@@ -0,0 +1,14 @@
1
+ import { hookCompatibility } from "../hooks/compatibility.js";
2
+ import { inventory } from "./index.js";
3
+ /** Every selected Hook's support and readiness per tool, in the inventory's order. */
4
+ export async function allHookCompatibility(runtime) {
5
+ const { items } = await inventory(runtime);
6
+ // Leftovers have no origin to look them up by: they are no longer selected.
7
+ const hooks = items.filter((item) => item.kind === "hook" && item.origin !== "—");
8
+ return Promise.all(hooks.map(async (item) => ({
9
+ name: item.installedName,
10
+ origin: item.origin,
11
+ compatibility: (await hookCompatibility(item.name, item.origin, runtime))
12
+ .compatibility,
13
+ })));
14
+ }
@@ -0,0 +1,47 @@
1
+ import { join } from "node:path";
2
+ import { parseDocument } from "yaml";
3
+ import { hookManifestSchema } from "@barndog-ai/api-contract";
4
+ import { readIfExists } from "../../shared/files.js";
5
+ import { isHookHarness } from "../../harnesses/registry.js";
6
+ import { hookIssue } from "../native/adapters.js";
7
+ /**
8
+ * Why sync installs a selected Hook in none of the selected tools, read from
9
+ * its materialized package: `no-version` when it has no implementation for any
10
+ * of them, `cant-run` when it has one but this machine lacks what it needs.
11
+ * Null for anything else: another kind, a disabled or installed Hook, one some
12
+ * tool can run, or a package that isn't there or can't be read.
13
+ */
14
+ export async function hookBlocked(asset, harnesses, runtime) {
15
+ if (asset.kind !== "hook" ||
16
+ !asset.enabled ||
17
+ asset.present ||
18
+ !asset.installed) {
19
+ return null;
20
+ }
21
+ const text = await readIfExists(join(asset.installed.path, "hook.yaml"));
22
+ if (text === null) {
23
+ return null;
24
+ }
25
+ // A hand-edited package is doctor's to report; here it only can't be judged.
26
+ const document = parseDocument(text);
27
+ const parsed = hookManifestSchema.safeParse(document.errors.length ? null : document.toJS());
28
+ if (!parsed.success) {
29
+ return null;
30
+ }
31
+ const skips = [];
32
+ for (const harness of harnesses) {
33
+ const skip = isHookHarness(harness)
34
+ ? await hookIssue(harness, parsed.data, runtime)
35
+ : { type: "no-command-hooks" };
36
+ if (!skip) {
37
+ return null;
38
+ }
39
+ skips.push(skip);
40
+ }
41
+ if (!skips.length) {
42
+ return null;
43
+ }
44
+ return skips.some((skip) => skip.type === "missing-requirement")
45
+ ? "cant-run"
46
+ : "no-version";
47
+ }
@@ -6,12 +6,17 @@ import { treeFingerprint } from "../workspace/tree.js";
6
6
  import { linkTarget } from "../environment/transaction.js";
7
7
  import { environmentCatalog } from "../server/catalog.js";
8
8
  import { openRepoSource } from "../workspace/workspace-source.js";
9
- import { localOverlay, mergeLocalCatalog, moveDestination, readMoved, } from "../workspace/overlay.js";
9
+ import { localOverlay, mergeLocalCatalog, moveDestination, readMoved, withOverlay, } from "../workspace/overlay.js";
10
+ import { cloudSource } from "../workspace/cloud-source.js";
11
+ import { secretRefs } from "../../harnesses/formats.js";
12
+ import { missingValues } from "../secrets/index.js";
13
+ import { keptValues } from "../environment/kept-values.js";
10
14
  import { resolveAssets } from "../asset-selection/index.js";
11
15
  import { installedName, resolveClashes } from "../environment/names.js";
12
16
  import { originLabel, scopes } from "../server/origin.js";
13
17
  import { isAssetKind } from "../asset-kinds/index.js";
14
18
  import { isHarness } from "../../harnesses/registry.js";
19
+ import { hookBlocked } from "./hook-readiness.js";
15
20
  /** Local assets still moving to the shared workspace; none without a local folder. */
16
21
  async function pendingMoves(settings) {
17
22
  const folder = settings.localWorkspace?.path;
@@ -35,7 +40,7 @@ function inventoryState(asset) {
35
40
  return "modified";
36
41
  }
37
42
  if (!asset.present) {
38
- return "pending";
43
+ return asset.blocked ?? "pending";
39
44
  }
40
45
  return asset.outdated ? "outdated" : "installed";
41
46
  }
@@ -46,11 +51,42 @@ function leftoverState(modified, offline) {
46
51
  }
47
52
  return offline ? "installed" : "removing";
48
53
  }
54
+ /**
55
+ * Finds an MCP server's variables with no value here, reading its definition
56
+ * from the same sources the inventory's catalog came from.
57
+ */
58
+ function variableCheck(input) {
59
+ const { settings, repo, overlay, runtime } = input;
60
+ const conn = settings.connection;
61
+ const primary = repo ?? (conn ? cloudSource(conn, runtime) : undefined);
62
+ const source = primary && overlay ? withOverlay(primary, overlay) : primary;
63
+ let kept;
64
+ return async ({ asset, enabled }) => {
65
+ if (!input.wanted || !source || asset.kind !== "mcp") {
66
+ return {};
67
+ }
68
+ // Read once, and only when some server needs checking.
69
+ kept ??= keptValues(runtime);
70
+ const values = (await kept).servers[asset.id] ?? {};
71
+ const definition = await source.mcpDefinition(asset);
72
+ const variables = [
73
+ ...new Set(Object.values(secretRefs(definition)).map((ref) => ref.secretRef)),
74
+ ];
75
+ return {
76
+ variables,
77
+ ...(enabled
78
+ ? {
79
+ unsetVariables: missingValues(definition, values, runtime.env).map((missing) => missing.variable),
80
+ }
81
+ : {}),
82
+ };
83
+ };
84
+ }
49
85
  /**
50
86
  * Compares configured selections, catalog and installed files to report status;
51
87
  * unreachable sources fall back to local state.
52
88
  */
53
- export async function inventory(runtime) {
89
+ export async function inventory(runtime, options = {}) {
54
90
  const { home } = runtime;
55
91
  const settings = await readSettings(home);
56
92
  if (!settings) {
@@ -101,6 +137,13 @@ export async function inventory(runtime) {
101
137
  const catalog = overlay
102
138
  ? await mergeLocalCatalog(primaryCatalog, overlay)
103
139
  : primaryCatalog;
140
+ const variablesOf = variableCheck({
141
+ wanted: Boolean(options.checkVariables),
142
+ settings,
143
+ repo,
144
+ overlay,
145
+ runtime,
146
+ });
104
147
  const selection = selectionState(settings);
105
148
  const effective = resolveAssets(catalog, selection);
106
149
  const outcome = await resolveClashes(effective.assets.flatMap(({ asset, enabled }) => {
@@ -126,6 +169,12 @@ export async function inventory(runtime) {
126
169
  const entries = nativeOf(asset.id);
127
170
  const tree = installed.find((t) => t.id === asset.id);
128
171
  const present = links.length > 0 || entries.length > 0;
172
+ const blocked = await hookBlocked({
173
+ kind: asset.kind,
174
+ enabled: entry.enabled,
175
+ present,
176
+ installed: tree,
177
+ }, settings.harnesses, runtime);
129
178
  const harnesses = [
130
179
  ...new Set([
131
180
  ...links.map((l) => l.harness),
@@ -147,6 +196,7 @@ export async function inventory(runtime) {
147
196
  modified: modified.has(asset.id),
148
197
  present,
149
198
  outdated: Boolean(tree?.versionId && tree.versionId !== asset.publishedVersion),
199
+ blocked,
150
200
  }),
151
201
  harnesses,
152
202
  paths: [
@@ -154,6 +204,7 @@ export async function inventory(runtime) {
154
204
  ...links.map((l) => l.target),
155
205
  ...new Set(entries.map((n) => `${n.file} (${n.key})`)),
156
206
  ],
207
+ ...(await variablesOf(entry)),
157
208
  });
158
209
  }
159
210
  const visible = await loadScopes();
@@ -5,13 +5,14 @@ import { selectAsset } from "../server/catalog.js";
5
5
  import { originLabel } from "../server/origin.js";
6
6
  import { repoForOrigin, selectRepoAsset, showRepoAsset, } from "../workspace/assets.js";
7
7
  import { inventory } from "./index.js";
8
+ import { cloudHookCompatibility, repoHookCompatibility, } from "../hooks/compatibility.js";
8
9
  /** What a Skill or Hook is, where it comes from, and where this machine has it. */
9
10
  export async function showPackage(kind, name, origin, runtime) {
10
11
  const { home } = runtime;
11
12
  const settings = await readSettings(home);
12
13
  const repo = settings && repoForOrigin(settings, runtime, origin);
13
14
  const described = repo
14
- ? repoDetails(selectRepoAsset(await repo.model(), kind, name, origin), kind)
15
+ ? await repoDetails(selectRepoAsset(await repo.model(), kind, name, origin), kind, runtime)
15
16
  : await cloudDetails(kind, name, origin, runtime);
16
17
  const item = (await inventory(runtime)).items.find((entry) => entry.id === described.id);
17
18
  return {
@@ -21,7 +22,7 @@ export async function showPackage(kind, name, origin, runtime) {
21
22
  : null,
22
23
  };
23
24
  }
24
- function repoDetails(asset, kind) {
25
+ async function repoDetails(asset, kind, runtime) {
25
26
  const view = showRepoAsset(asset);
26
27
  const events = view.manifest
27
28
  ? eventsByTool((harness) => view.manifest?.implementations[harness]?.events)
@@ -34,6 +35,12 @@ function repoDetails(asset, kind) {
34
35
  version: view.version,
35
36
  description: view.description,
36
37
  ...(events ? { events } : {}),
38
+ ...(kind === "hook"
39
+ ? {
40
+ compatibility: (await repoHookCompatibility(asset, runtime))
41
+ .compatibility,
42
+ }
43
+ : {}),
37
44
  };
38
45
  }
39
46
  async function cloudDetails(kind, name, origin, runtime) {
@@ -59,6 +66,7 @@ async function cloudDetails(kind, name, origin, runtime) {
59
66
  description: hook.version.description,
60
67
  events: eventsByTool((harness) => hook.compatibility.find((row) => row.harness === harness)
61
68
  ?.implementation?.events),
69
+ compatibility: (await cloudHookCompatibility(hook, runtime)).compatibility,
62
70
  };
63
71
  }
64
72
  /** Event names per tool, leaving out tools the Hook has no implementation for. */
@@ -16,9 +16,11 @@ import { synchronize } from "../environment/sync.js";
16
16
  import { patchNative } from "../native/configuration.js";
17
17
  import { validMcpName, VARIABLE_NAME } from "../../shared/patterns.js";
18
18
  import { assetKinds } from "../asset-kinds/index.js";
19
- import { LOCAL_ORIGIN } from "../workspace/overlay.js";
19
+ import { queryParameters } from "../asset-kinds/url-query.js";
20
20
  import { ensureLocalWorkspace } from "../imports/local.js";
21
- import { updateSecrets } from "../secrets/index.js";
21
+ import { keptValues, updateKeptValues, withServerValues, } from "../environment/kept-values.js";
22
+ import { localRepoSource } from "../workspace/repo-source.js";
23
+ import { defined } from "../../shared/lookup.js";
22
24
  import { asRecord, asStrings, isRecord } from "../../shared/values.js";
23
25
  import { barndogPaths } from "../../config/paths.js";
24
26
  /** Random characters that keep two backups of one file taken in the same millisecond apart. */
@@ -89,14 +91,33 @@ const SECRET_WORD = /api[-_]?key|token|secret|password/i;
89
91
  * @internal Exported for its table test in `src/tests/patterns.test.ts`.
90
92
  */
91
93
  export const looksSecret = (arg) => SECRET_WORD.test(arg) || arg.startsWith("sk-");
94
+ const isKept = (keep, server, variable) => keep.some((choice) => choice.server === server && choice.variable === variable);
95
+ /** Each literal of one server, and whether BarnDog keeps it. */
96
+ export function literalValues(server, literals, keep) {
97
+ return literals.map((literal) => ({
98
+ server,
99
+ variable: literal.variable,
100
+ kept: isKept(keep, server, literal.variable),
101
+ }));
102
+ }
92
103
  /**
93
- * What to tell the developer about each literal: where BarnDog keeps it, or
94
- * which variable to set. `kept` holds the variables BarnDog keeps.
104
+ * Keeps the chosen literal values for the server each came from, by its asset
105
+ * ID, and returns how to put back the values those servers had before.
95
106
  */
96
- export function literalNotes(literals, kept) {
97
- return literals.map((literal) => kept.includes(literal.variable)
98
- ? `BarnDog keeps the value of ${literal.variable} in ~/.barndog/secrets.json on this machine, never uploaded, and writes it into your coding tools.`
99
- : `${literal.key} held a literal value, which BarnDog doesn't keep. Set ${literal.variable} in your environment, or keep it with barndog mcp env set ${literal.variable}.`);
107
+ export async function keepLiteralValues(servers, keep, runtime) {
108
+ const chosen = servers.flatMap((server) => server.literals
109
+ .filter((literal) => isKept(keep, server.name, literal.variable))
110
+ .map((literal) => ({ id: server.id, ...literal })));
111
+ if (!chosen.length) {
112
+ return async () => { };
113
+ }
114
+ const before = await keptValues(runtime);
115
+ await updateKeptValues((secrets) => chosen.reduce((next, { id, variable, value }) => withServerValues(next, id, { [variable]: { value } }), secrets), runtime);
116
+ return async () => {
117
+ await updateKeptValues((secrets) => chosen.reduce((next, { id, variable }) => withServerValues(next, id, {
118
+ [variable]: before.servers[id]?.[variable] ?? null,
119
+ }), secrets), runtime);
120
+ };
100
121
  }
101
122
  /** Secrets are named, never shared: every literal becomes a variable the definition refers to. */
102
123
  function reference(key, value, fallback, found) {
@@ -158,9 +179,6 @@ export function convertServer({ name, server }, description, oauth) {
158
179
  }
159
180
  // Claude Code writes `oauth` and Cursor writes `auth` for servers that sign in natively.
160
181
  const signsIn = oauth || !!server.oauth || !!server.auth;
161
- if (signsIn) {
162
- notes.push(`Sign in once it's added: barndog mcp auth ${name} --origin ${LOCAL_ORIGIN} --harness <tool>`);
163
- }
164
182
  candidate = {
165
183
  ...common,
166
184
  transport: "http",
@@ -198,7 +216,21 @@ export function convertServer({ name, server }, description, oauth) {
198
216
  if (!parsed.success) {
199
217
  throw new CliError(`${name} can't be added: ${parsed.error.issues.map((issue) => `${issue.path.join(".") || "server"}: ${issue.message}`).join("; ")}`);
200
218
  }
201
- return { name, definition: parsed.data, notes, literals };
219
+ return {
220
+ name,
221
+ definition: parsed.data,
222
+ notes: [...notes, ...urlQueryNotes(parsed.data)],
223
+ literals,
224
+ };
225
+ }
226
+ /** What to check before sharing a server whose URL has a query string. */
227
+ function urlQueryNotes(definition) {
228
+ const parameters = queryParameters(definition);
229
+ return parameters.length
230
+ ? [
231
+ `Its URL keeps the query parameters ${parameters.join(", ")} as written. Check none of them holds a secret before you share it.`,
232
+ ]
233
+ : [];
202
234
  }
203
235
  /** How an imported HTTP server authenticates. */
204
236
  function httpAuthentication(signsIn, headers) {
@@ -295,6 +327,25 @@ export async function localMcpNamed(name, runtime) {
295
327
  .map((file) => file.slice(0, -".yaml".length));
296
328
  return (names.find((other) => other.toLowerCase() === name.toLowerCase()) ?? null);
297
329
  }
330
+ const toolList = new Intl.ListFormat("en", { type: "conjunction" });
331
+ /**
332
+ * The servers that sign in through each coding tool, which `mcp auth` starts
333
+ * once per tool. Read by asset ID from `state.json` after the sync, since a
334
+ * clash rename changes the name a tool has the server under.
335
+ */
336
+ export async function signInTools(servers, runtime) {
337
+ const { native } = await readState(runtime.home);
338
+ return servers
339
+ .filter(({ definition }) => definition.authentication === "native-oauth")
340
+ .map(({ id, name }) => ({
341
+ server: name,
342
+ harnesses: [
343
+ ...new Set(native
344
+ .filter((entry) => entry.kind === "mcp" && entry.id === id)
345
+ .map((entry) => entry.harness)),
346
+ ],
347
+ }));
348
+ }
298
349
  /**
299
350
  * Writes converted MCP servers and synchronizes them. Existing local workspace
300
351
  * names are always rejected; replace permits backing up and removing
@@ -317,7 +368,7 @@ export async function addMcpServers(servers, options, runtime) {
317
368
  }
318
369
  const conflicts = await conflictingEntries(name, runtime);
319
370
  if (conflicts.length && !options.replace) {
320
- throw new CliError(`${name} is already configured in ${conflicts.map((c) => c.file).join(" and ")}. Replacing it is required for BarnDog to manage it.`, `barndog mcp add ${name} --replace`);
371
+ throw new CliError(`${name} is already configured in ${toolList.format(conflicts.map((c) => adapters[c.harness].name))}. Replacing it is required for BarnDog to manage it.`, `barndog mcp add ${name} --replace`);
321
372
  }
322
373
  }
323
374
  // One backup per settings file, taken before its first change, so a file
@@ -349,20 +400,22 @@ export async function addMcpServers(servers, options, runtime) {
349
400
  await writeAtomic(join(workspace.path, "org/mcp", `${name}.yaml`), stringify(definition), { mode: POSIX_MODE.regularFile });
350
401
  }
351
402
  // Saved before the sync, which writes them into the tools' settings.
352
- const kept = servers.flatMap((s) => s.literals.filter((literal) => options.keep.includes(literal.variable)));
353
- if (kept.length) {
354
- await updateSecrets(Object.fromEntries(kept.map((l) => [l.variable, l.value])), runtime);
355
- }
403
+ const model = await localRepoSource(workspace, runtime).model();
404
+ const saved = servers.map((server) => ({
405
+ ...server,
406
+ id: defined(model.assets.find((asset) => asset.kind === "mcp" &&
407
+ asset.path === `org/mcp/${server.name}.yaml`)?.id, `The local folder has no ${server.name} after writing it`),
408
+ }));
409
+ await keepLiteralValues(saved, options.keep, runtime);
356
410
  const events = await synchronize(undefined, runtime, undefined, {
357
411
  prompt: false,
358
412
  });
359
413
  return {
360
414
  added: servers.map((s) => s.name),
361
- notes: servers.flatMap((s) => [...s.notes, ...literalNotes(s.literals, options.keep)].map((text) => ({
362
- server: s.name,
363
- text,
364
- }))),
415
+ notes: servers.flatMap((s) => s.notes.map((text) => ({ server: s.name, text }))),
416
+ values: servers.flatMap((s) => literalValues(s.name, s.literals, options.keep)),
365
417
  backups,
418
+ signIn: await signInTools(saved, runtime),
366
419
  events,
367
420
  };
368
421
  });
@@ -14,24 +14,32 @@ import { readSettings } from "../../config/settings.js";
14
14
  import { repoForOrigin, selectRepoAsset, showRepoAsset, } from "../workspace/assets.js";
15
15
  import { gitVersions } from "../collaboration/workspace-git.js";
16
16
  import { adapters } from "../../harnesses/registry.js";
17
+ import { missingValues, readsFrom } from "../secrets/index.js";
18
+ import { keptValues } from "../environment/kept-values.js";
17
19
  import { patchNative } from "../native/configuration.js";
18
20
  import { fileText, inputJson } from "../../shared/files.js";
21
+ import { mayShareUrlQueries, } from "../asset-kinds/url-query.js";
19
22
  import { defined } from "../../shared/lookup.js";
20
23
  import { CliError, friendlyMessage } from "../../errors.js";
21
24
  import { barndogPaths } from "../../config/paths.js";
22
25
  import { apiClient } from "../auth/transport.js";
23
- async function readDefinition(file, runtime) {
26
+ /** The definition in `input.file`, once the developer agrees to share any URL query it has. */
27
+ async function readDefinition(input, runtime) {
28
+ const { file } = input;
24
29
  const result = mcpDefinitionSchema.safeParse(await inputJson(localPath(file, runtime)));
25
30
  if (!result.success) {
26
31
  throw new CliError(`${file} isn't an MCP definition: ${friendlyMessage(result.error)}.`, "Check the fields against the MCP definition format at barndog.dev/docs", { cause: result.error });
27
32
  }
33
+ if (!(await mayShareUrlQueries([{ name: input.name, definition: result.data }], input.confirmUrlQuery))) {
34
+ throw new CliError("Nothing was published.");
35
+ }
28
36
  return result.data;
29
37
  }
30
38
  /** Publishes a new MCP configuration in a scope. */
31
39
  export async function createMcp(input, runtime) {
32
40
  const conn = await connection(runtime);
33
41
  const scope = await selectOrigin(input.origin, conn, runtime);
34
- const definition = await readDefinition(input.file, runtime);
42
+ const definition = await readDefinition(input, runtime);
35
43
  return parsed(mcpSchema, apiClient(conn.server, runtime).POST("/v1/mcps", {
36
44
  body: {
37
45
  name: input.name,
@@ -45,7 +53,7 @@ export async function createMcp(input, runtime) {
45
53
  export async function updateMcp(input, runtime) {
46
54
  const conn = await connection(runtime);
47
55
  await selectOrigin(input.origin, conn, runtime);
48
- const definition = await readDefinition(input.file, runtime);
56
+ const definition = await readDefinition(input, runtime);
49
57
  const selected = await selectAsset("mcp", input.name, input.origin, runtime);
50
58
  return parsed(mcpSchema, apiClient(conn.server, runtime).POST("/v1/mcps/{id}/versions", {
51
59
  params: { path: { id: selected.reference.id } },
@@ -61,10 +69,25 @@ export async function showMcp(name, origin, runtime) {
61
69
  const { home } = runtime;
62
70
  const settings = await readSettings(home);
63
71
  const repo = settings && repoForOrigin(settings, runtime, origin);
72
+ const withUnset = async (asset, definition) => {
73
+ const values = (await keptValues(runtime)).servers[asset.id] ?? {};
74
+ return {
75
+ ...asset,
76
+ keptVariables: Object.entries(values).map(([variable, kept]) => {
77
+ const from = readsFrom(kept);
78
+ return from ? { variable, from } : { variable };
79
+ }),
80
+ unsetVariables: definition
81
+ ? missingValues(definition, values, runtime.env).map((missing) => missing.variable)
82
+ : [],
83
+ };
84
+ };
64
85
  if (repo) {
65
- return showRepoAsset(selectRepoAsset(await repo.model(), "mcp", name, origin));
86
+ const view = showRepoAsset(selectRepoAsset(await repo.model(), "mcp", name, origin));
87
+ return withUnset(view, view.definition);
66
88
  }
67
- return (await selectAsset("mcp", name, origin, runtime)).asset;
89
+ const { asset } = await selectAsset("mcp", name, origin, runtime);
90
+ return withUnset(asset, mcpSchema.parse(asset).version.definition);
68
91
  }
69
92
  export async function mcpVersions(name, origin, runtime) {
70
93
  const { home } = runtime;