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
@@ -0,0 +1,127 @@
1
+ /**
2
+ * Doctor checks that would repeat one message per variable or per Hook,
3
+ * grouped into one check per message with the names listed under it.
4
+ */
5
+ import { adapters } from "../../harnesses/registry.js";
6
+ import { only } from "../../shared/lookup.js";
7
+ import { requirementFix, requirementMessage } from "../native/requirements.js";
8
+ import { unassignedValueMessage, unsetValueMessage, } from "../environment/events.js";
9
+ const SHELL_NOTE = "Coding tools opened outside a terminal may not see your shell's variables either.";
10
+ /** Names under each label, each once, in the order they first appear. */
11
+ function rowsOf(entries) {
12
+ const rows = new Map();
13
+ for (const { label, item } of entries) {
14
+ const items = rows.get(label) ?? [];
15
+ if (!items.includes(item)) {
16
+ items.push(item);
17
+ }
18
+ rows.set(label, items);
19
+ }
20
+ return [...rows].map(([label, items]) => ({ label, items }));
21
+ }
22
+ /** The `mcp env set` that fixes them: as specific as one server allows. */
23
+ function setFix(events) {
24
+ const server = only([...new Set(events.map((event) => event.server))]);
25
+ if (!server) {
26
+ return "barndog mcp env set <server> <variable>";
27
+ }
28
+ const single = only(events);
29
+ return single
30
+ ? `barndog mcp env set ${server} ${single.variable}`
31
+ : `barndog mcp env set ${server}`;
32
+ }
33
+ /**
34
+ * One variable keeps its own sentence; several share one check that lists
35
+ * them by server.
36
+ */
37
+ function unsetCheck(events, wording) {
38
+ const single = only(events);
39
+ if (single) {
40
+ return [
41
+ {
42
+ name: "MCP variable",
43
+ status: "warn",
44
+ detail: wording.single(single),
45
+ fix: setFix(events),
46
+ },
47
+ ];
48
+ }
49
+ if (!events.length) {
50
+ return [];
51
+ }
52
+ return [
53
+ {
54
+ name: "MCP variables",
55
+ status: "warn",
56
+ detail: wording.many,
57
+ rows: rowsOf(events.map((event) => ({
58
+ label: event.server,
59
+ item: wording.item(event),
60
+ }))),
61
+ fix: setFix(events),
62
+ },
63
+ ];
64
+ }
65
+ /**
66
+ * One check for the variables with no value here, one for those told to read
67
+ * a variable that has none, and one per value kept for no server.
68
+ */
69
+ export function variableChecks(events) {
70
+ const unset = events.filter((event) => event.type === "unset-variable");
71
+ const direct = unset.filter((event) => !event.from);
72
+ const redirected = unset.filter((event) => event.from);
73
+ const checks = [
74
+ ...unsetCheck(direct, {
75
+ single: (event) => `${unsetValueMessage(event)} BarnDog doesn't keep it and it isn't set in this shell. ${SHELL_NOTE}`,
76
+ many: `${direct.length} variables have no value here, so their MCP servers can't use them. BarnDog doesn't keep them and they aren't set in this shell. ${SHELL_NOTE}`,
77
+ item: (event) => event.variable,
78
+ }),
79
+ ...unsetCheck(redirected, {
80
+ single: (event) => `${unsetValueMessage(event)} ${SHELL_NOTE}`,
81
+ many: `${redirected.length} variables read another variable that has no value here. ${SHELL_NOTE}`,
82
+ item: (event) => `${event.variable} from $${event.from}`,
83
+ }),
84
+ ];
85
+ for (const event of events) {
86
+ if (event.type === "unassigned-value") {
87
+ checks.push({
88
+ name: "MCP variable",
89
+ status: "warn",
90
+ detail: unassignedValueMessage(event.variable),
91
+ fix: `barndog mcp env set <server> ${event.variable}`,
92
+ });
93
+ }
94
+ }
95
+ return checks;
96
+ }
97
+ /** Every Hook that has an implementation for a tool but can't run there, in one check. */
98
+ export function cantRunChecks(events) {
99
+ const broken = events.flatMap((event) => event.type === "unsupported" && event.cause.type === "missing-requirement"
100
+ ? [{ event, requirement: event.cause.requirement }]
101
+ : []);
102
+ if (!broken.length) {
103
+ return [];
104
+ }
105
+ const hooks = new Set(broken.map(({ event }) => event.name)).size;
106
+ const fixes = new Set(broken.map(({ event, requirement }) => requirementFix(event.harness, requirement)));
107
+ return [
108
+ {
109
+ name: "Hooks",
110
+ status: "warn",
111
+ detail: `${hooks} ${hooks === 1 ? "Hook can't run in a tool it's" : "Hooks can't run in a tool they're"} written for.`,
112
+ table: broken.map(({ event, requirement }) => [
113
+ event.name,
114
+ adapters[event.harness].name,
115
+ requirementMessage(event.harness, requirement),
116
+ ]),
117
+ fix: `${only([...fixes]) ?? "Install or update what each Hook needs"}, then run the command below`,
118
+ command: "barndog sync",
119
+ },
120
+ ];
121
+ }
122
+ /** How many Hooks aren't written for at least one selected tool: worth a tip, not a warning. */
123
+ export function hooksMissingTools(events) {
124
+ return new Set(events.flatMap((event) => event.type === "unsupported" && event.cause.type !== "missing-requirement"
125
+ ? [event.name]
126
+ : [])).size;
127
+ }
@@ -8,22 +8,10 @@ import { adapters } from "../../harnesses/registry.js";
8
8
  import { authStatus } from "../auth/session.js";
9
9
  import { LoginRequiredError } from "../auth/transport.js";
10
10
  import { synchronize } from "../environment/sync.js";
11
+ import { keptValuesMessage } from "../environment/events.js";
11
12
  import { assetKinds } from "../asset-kinds/index.js";
12
13
  import { barndogPaths } from "../../config/paths.js";
13
- /** An MCP variable installed servers refer to that has no value on this machine. */
14
- function variableCheck(event) {
15
- if (event.type !== "unset-variable") {
16
- return [];
17
- }
18
- return [
19
- {
20
- name: "MCP variable",
21
- status: "warn",
22
- detail: `${event.variable} has no value here, so ${event.servers.join(", ")} can't use it: BarnDog doesn't keep it and it isn't set in this shell. Coding tools opened outside a terminal may not see your shell's variables either.`,
23
- fix: `barndog mcp env set ${event.variable}`,
24
- },
25
- ];
26
- }
14
+ import { cantRunChecks, hooksMissingTools, variableChecks } from "./grouped.js";
27
15
  const failure = (error) => ({
28
16
  detail: error instanceof Error ? error.message : String(error),
29
17
  fix: error instanceof CliError ? error.hint : undefined,
@@ -72,6 +60,12 @@ async function gitChecks(workspace, runtime) {
72
60
  * what failed (a readable configuration, a session).
73
61
  */
74
62
  export async function doctor(runtime) {
63
+ const found = { hooksMissingTools: 0 };
64
+ const checks = await allChecks(runtime, found);
65
+ return { checks, ...found };
66
+ }
67
+ /** The checks; what is only worth a tip goes into `found`. */
68
+ async function allChecks(runtime, found) {
75
69
  const { home } = runtime;
76
70
  const checks = [];
77
71
  let settings;
@@ -98,13 +92,19 @@ export async function doctor(runtime) {
98
92
  });
99
93
  const detected = await detectHarnesses(runtime);
100
94
  for (const harness of settings.harnesses) {
95
+ const { name } = adapters[harness];
101
96
  const found = detected.find((d) => d.id === harness)?.evidence;
97
+ if (found) {
98
+ checks.push({ name, status: "ok", detail: found });
99
+ continue;
100
+ }
101
+ // Disabling removes what BarnDog installed there, so it goes in `command`.
102
102
  checks.push({
103
- name: adapters[harness].name,
104
- status: found ? "ok" : "warn",
105
- detail: found ??
106
- "Not found on this machine; assets are still installed for it.",
107
- fix: found ? undefined : "barndog init",
103
+ name,
104
+ status: "warn",
105
+ detail: "Not found on this machine; assets are still installed for it.",
106
+ fix: `Install ${name}, or stop BarnDog installing for it.`,
107
+ command: `barndog harnesses disable ${harness}`,
108
108
  });
109
109
  }
110
110
  const connected = settings.connection;
@@ -148,11 +148,18 @@ export async function doctor(runtime) {
148
148
  : "Everything selected is installed and up to date.",
149
149
  fix: pending ? "barndog sync" : undefined,
150
150
  });
151
- checks.push(...events.flatMap(variableCheck));
151
+ checks.push(...variableChecks(events));
152
152
  for (const event of events) {
153
153
  if (event.type === "notice") {
154
154
  checks.push({ name: "Notice", status: "warn", detail: event.message });
155
155
  }
156
+ if (event.type === "kept-values") {
157
+ checks.push({
158
+ name: "Kept values",
159
+ status: "warn",
160
+ detail: `${keptValuesMessage(event)} Files: ${event.files.join(", ")}.`,
161
+ });
162
+ }
156
163
  if (event.type === "clash") {
157
164
  checks.push({
158
165
  name: "Name clash",
@@ -168,14 +175,9 @@ export async function doctor(runtime) {
168
175
  detail: `${event.kind} ${event.name}: ${event.reason}. The installed version stays in place.`,
169
176
  });
170
177
  }
171
- if (event.type === "unsupported") {
172
- checks.push({
173
- name: "Unsupported",
174
- status: "warn",
175
- detail: `${event.kind} ${event.name} on ${adapters[event.harness].name}: ${event.reason}`,
176
- });
177
- }
178
178
  }
179
+ checks.push(...cantRunChecks(events));
180
+ found.hooksMissingTools = hooksMissingTools(events);
179
181
  }
180
182
  catch (error) {
181
183
  checks.push({ name: "Installation", status: "fail", ...failure(error) });
@@ -1 +1,18 @@
1
- export {};
1
+ /** What an `unset-variable` event means, as one sentence. */
2
+ export function unsetValueMessage(event) {
3
+ return event.from
4
+ ? `${event.from} has no value here, so ${event.server} can't read ${event.variable} from it.`
5
+ : `${event.variable} has no value here, so ${event.server} can't use it.`;
6
+ }
7
+ /** What a `kept-values` event means, naming no file; its files are listed after it. */
8
+ export function keptValuesMessage(event) {
9
+ const { action, server, variables } = event;
10
+ const listed = `${variables.length === 1 ? "value of" : "values of"} ${variables.join(", ")}`;
11
+ if (action === "removed") {
12
+ return `Removed the kept ${listed} for ${server}.`;
13
+ }
14
+ const stay = variables.length === 1 ? "It stays" : "They stay";
15
+ return `Wrote the kept ${listed} for ${server}. ${stay} on this machine.`;
16
+ }
17
+ /** What an `unassigned-value` event means, as one sentence. */
18
+ export const unassignedValueMessage = (variable) => `BarnDog keeps a value for ${variable} from before each value belonged to one MCP server, and no server has it yet.`;
@@ -0,0 +1,40 @@
1
+ /** The events for `writes`, one per server and action, then one per file for what only it has. */
2
+ export function keptValueEvents(writes) {
3
+ const groups = new Map();
4
+ for (const write of writes.filter((w) => w.variables.length)) {
5
+ const key = JSON.stringify([write.action, write.server]);
6
+ const group = groups.get(key) ?? { ...write, writes: [] };
7
+ group.writes.push(write);
8
+ groups.set(key, group);
9
+ }
10
+ return [...groups.values()].flatMap(({ action, server, writes: group }) => {
11
+ const [first, ...rest] = group;
12
+ const shared = rest.length
13
+ ? (first?.variables ?? []).filter((variable) => rest.every((change) => change.variables.includes(variable)))
14
+ : [];
15
+ const events = shared.length
16
+ ? [
17
+ {
18
+ type: "kept-values",
19
+ action,
20
+ server,
21
+ variables: shared,
22
+ files: group.map((w) => w.file),
23
+ },
24
+ ]
25
+ : [];
26
+ for (const write of group) {
27
+ const own = write.variables.filter((v) => !shared.includes(v));
28
+ if (own.length) {
29
+ events.push({
30
+ type: "kept-values",
31
+ action,
32
+ server,
33
+ variables: own,
34
+ files: [write.file],
35
+ });
36
+ }
37
+ }
38
+ return events;
39
+ });
40
+ }
@@ -0,0 +1,68 @@
1
+ import { readState } from "../../config/state.js";
2
+ import { recordedVariables } from "../native/secret-values.js";
3
+ import { changeSecrets, readStoredSecrets, } from "../secrets/index.js";
4
+ function converted(values, state) {
5
+ const servers = {};
6
+ const assigned = new Set();
7
+ for (const entry of state.native) {
8
+ if (entry.kind !== "mcp") {
9
+ continue;
10
+ }
11
+ for (const variable of recordedVariables(entry.value)) {
12
+ const value = values[variable];
13
+ if (value !== undefined) {
14
+ servers[entry.id] = { ...servers[entry.id], [variable]: { value } };
15
+ assigned.add(variable);
16
+ }
17
+ }
18
+ }
19
+ return {
20
+ servers,
21
+ unassigned: Object.fromEntries(Object.entries(values).filter(([variable]) => !assigned.has(variable))),
22
+ };
23
+ }
24
+ const upgraded = (stored, state) => stored.version === 2 ? stored : converted(stored.values, state);
25
+ /** The kept values, converting a version 1 file first. */
26
+ export async function keptValues(runtime) {
27
+ const stored = await readStoredSecrets(runtime);
28
+ if (stored.version === 2) {
29
+ return stored;
30
+ }
31
+ const state = await readState(runtime.home);
32
+ const { secrets } = await changeSecrets((latest) => upgraded(latest, state), runtime);
33
+ return secrets;
34
+ }
35
+ /** Saves what `change` makes of the kept values; returns the file's path. */
36
+ export async function updateKeptValues(change, runtime) {
37
+ const state = await readState(runtime.home);
38
+ const { file } = await changeSecrets((latest) => change(upgraded(latest, state)), runtime);
39
+ return file;
40
+ }
41
+ /** `secrets` with `values` set for the server with asset ID `id`; null forgets that variable's value. */
42
+ export function withServerValues(secrets, id, values) {
43
+ const server = { ...secrets.servers[id] };
44
+ for (const [variable, value] of Object.entries(values)) {
45
+ if (value === null) {
46
+ delete server[variable];
47
+ }
48
+ else {
49
+ server[variable] = value;
50
+ }
51
+ }
52
+ return { ...secrets, servers: { ...secrets.servers, [id]: server } };
53
+ }
54
+ /** `secrets` with each moved server's values under its new asset ID. */
55
+ export function withMovedServers(secrets, moves) {
56
+ const servers = { ...secrets.servers };
57
+ for (const { from, to, copy } of moves) {
58
+ const values = servers[from];
59
+ if (!values) {
60
+ continue;
61
+ }
62
+ servers[to] = { ...values, ...servers[to] };
63
+ if (!copy) {
64
+ delete servers[from];
65
+ }
66
+ }
67
+ return { ...secrets, servers };
68
+ }
@@ -0,0 +1,57 @@
1
+ import { secretRefs } from "../../harnesses/formats.js";
2
+ import { installedName } from "./names.js";
3
+ /** The variables a definition refers to, each once. */
4
+ const variablesOf = (definition) => [
5
+ ...new Set(Object.values(secretRefs(definition)).map((ref) => ref.secretRef)),
6
+ ];
7
+ /** A server's variables: from this sync's read, the record of the same version, or the workspace. */
8
+ async function currentVariables(input) {
9
+ const { asset, known, staged, source } = input;
10
+ if (staged) {
11
+ return variablesOf(staged);
12
+ }
13
+ if (known?.versionId === asset.publishedVersion) {
14
+ return known.variables;
15
+ }
16
+ // Without a source the catalog is empty, so this never runs.
17
+ if (!source) {
18
+ throw new Error("Catalog assets need a workspace source");
19
+ }
20
+ // Only a server this sync didn't stage, at a version not yet recorded, is read here.
21
+ return variablesOf(await source.mcpDefinition(asset));
22
+ }
23
+ /** Every selected MCP server, for `state.json`. */
24
+ export async function mcpRecords(input) {
25
+ const { definitions, invalid, vanished, localNames, source } = input;
26
+ const previous = input.previous ?? [];
27
+ const records = [];
28
+ for (const { asset, enabled } of input.assets) {
29
+ if (asset.kind !== "mcp" || vanished.has(asset.id)) {
30
+ continue;
31
+ }
32
+ const known = previous.find((record) => record.id === asset.id);
33
+ const name = installedName(asset, localNames);
34
+ // A copy that can't be installed tells nothing new; keep what was known.
35
+ if (invalid.has(asset.id)) {
36
+ if (known) {
37
+ records.push({ ...known, installedName: name, enabled });
38
+ }
39
+ continue;
40
+ }
41
+ const variables = await currentVariables({
42
+ asset,
43
+ known,
44
+ staged: definitions.get(asset.id),
45
+ source,
46
+ });
47
+ records.push({
48
+ id: asset.id,
49
+ name: asset.name,
50
+ installedName: name,
51
+ versionId: asset.publishedVersion,
52
+ variables,
53
+ enabled,
54
+ });
55
+ }
56
+ return records;
57
+ }
@@ -2,6 +2,7 @@ import { rm } from "node:fs/promises";
2
2
  import { join } from "node:path";
3
3
  import { isDeepStrictEqual } from "node:util";
4
4
  import { resolveAssets } from "../asset-selection/index.js";
5
+ import { updateKeptValues, withMovedServers, } from "./kept-values.js";
5
6
  import { forgetImport } from "../imports/local.js";
6
7
  import { saveSettings } from "../../config/settings.js";
7
8
  import { withSelection } from "../../config/environment.js";
@@ -46,6 +47,12 @@ async function removeLocal(entry, input) {
46
47
  });
47
48
  await forgetImport(input.overlay.label, entry.kind, entry.name);
48
49
  }
50
+ /** Kept MCP values follow each moved server to its shared copy. */
51
+ async function carryKeptValues(servers, runtime) {
52
+ if (servers.length) {
53
+ await updateKeptValues((secrets) => withMovedServers(secrets, servers), runtime);
54
+ }
55
+ }
49
56
  async function settleMoves(input) {
50
57
  const records = await readMoved(input.overlay.label);
51
58
  if (!records.length) {
@@ -57,6 +64,7 @@ async function settleMoves(input) {
57
64
  const notices = [];
58
65
  const finished = [];
59
66
  const removals = [];
67
+ const servers = [];
60
68
  const finish = (entry, keep) => {
61
69
  finished.push(entry.path);
62
70
  if (keep) {
@@ -96,7 +104,14 @@ async function settleMoves(input) {
96
104
  finished.push(entry.path);
97
105
  continue;
98
106
  }
99
- finish(entry, !(await unchanged(entry, local, shared, input)));
107
+ const keep = !(await unchanged(entry, local, shared, input));
108
+ servers.push({
109
+ kind: entry.kind,
110
+ from: local.id,
111
+ to: shared.id,
112
+ copy: keep,
113
+ });
114
+ finish(entry, keep);
100
115
  }
101
116
  const selection = ids.length === input.selection.individualAssetIds.length
102
117
  ? input.selection
@@ -104,6 +119,7 @@ async function settleMoves(input) {
104
119
  if (input.persist && finished.length) {
105
120
  // Saved first, so an interrupted sync can't leave an asset with neither copy.
106
121
  await input.saveSelection(selection);
122
+ await carryKeptValues(servers.filter((server) => server.kind === "mcp"), input.runtime);
107
123
  for (const entry of removals) {
108
124
  await removeLocal(entry, input);
109
125
  }
@@ -4,31 +4,30 @@ import { parse } from "yaml";
4
4
  import { hookManifestSchema, } from "@barndog-ai/api-contract";
5
5
  import { packageFingerprint } from "@barndog-ai/api-contract/package";
6
6
  import { CliError } from "../../errors.js";
7
- import { adapters, isHookHarness, skillDirectory, } from "../../harnesses/registry.js";
8
- import { secretRefs } from "../../harnesses/formats.js";
7
+ import { isHookHarness, skillDirectory } from "../../harnesses/registry.js";
9
8
  import { isInside } from "../../shared/files.js";
10
9
  import { defined } from "../../shared/lookup.js";
11
10
  import { hookEntries, hookIssue, mcpEntry } from "../native/adapters.js";
11
+ import { skipReason } from "../native/requirements.js";
12
+ import { applyKeptValues, missingValues, } from "../secrets/index.js";
12
13
  import { desiredEntries, installedPath } from "../workspace/installed.js";
13
14
  import { hookFolders, installedName } from "./names.js";
14
15
  /**
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.
16
+ * One event per variable an installed MCP server refers to that has no value
17
+ * here, and one per value kept from a version 1 file that no server has.
17
18
  */
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
- }));
19
+ function valueEvents(servers, kept, env) {
20
+ return [
21
+ ...servers.flatMap(({ name, definition, values }) => missingValues(definition, values, env).map((missing) => ({
22
+ type: "unset-variable",
23
+ server: name,
24
+ ...missing,
25
+ }))),
26
+ ...Object.keys(kept.unassigned).map((variable) => ({
27
+ type: "unassigned-value",
28
+ variable,
29
+ })),
30
+ ];
32
31
  }
33
32
  export async function stageAssets(input) {
34
33
  const { invalid, vanished, skipped, localNames, source, harnesses, runtime } = input;
@@ -39,6 +38,7 @@ export async function stageAssets(input) {
39
38
  const native = [];
40
39
  const trees = [];
41
40
  const events = [];
41
+ const definitions = new Map();
42
42
  const names = new Set();
43
43
  const ids = new Set();
44
44
  /** Installed MCP servers, to report the variables they find no value for. */
@@ -147,9 +147,12 @@ export async function stageAssets(input) {
147
147
  }
148
148
  else if (ref.kind === "mcp") {
149
149
  const definition = await source.mcpDefinition(ref);
150
- servers.push({ name, definition });
150
+ definitions.set(ref.id, definition);
151
+ const values = input.kept.servers[ref.id] ?? {};
152
+ const applied = applyKeptValues(definition, values);
153
+ servers.push({ name, definition, values });
151
154
  for (const harness of harnesses) {
152
- native.push(mcpEntry(harness, { id: ref.id, name, definition }, input.kept, runtime));
155
+ native.push(mcpEntry(harness, { id: ref.id, name, definition: applied.definition }, applied.kept, runtime));
153
156
  }
154
157
  }
155
158
  else {
@@ -169,8 +172,8 @@ export async function stageAssets(input) {
169
172
  events.push(...registered.events);
170
173
  }
171
174
  }
172
- events.push(...unsetVariables(servers, input.kept, input.runtime.env));
173
- return { links: desired, native, trees, events };
175
+ events.push(...valueEvents(servers, input.kept, input.runtime.env));
176
+ return { links: desired, native, trees, events, definitions };
174
177
  }
175
178
  /**
176
179
  * A Hook's registrations for each selected tool, and an `unsupported` event
@@ -179,21 +182,22 @@ export async function stageAssets(input) {
179
182
  async function hookRegistrations(harnesses, hook, runtime) {
180
183
  const native = [];
181
184
  const events = [];
182
- const unsupported = (harness, reason) => events.push({
185
+ const unsupported = (harness, cause) => events.push({
183
186
  type: "unsupported",
184
187
  kind: "hook",
185
188
  harness,
186
189
  name: hook.name,
187
- reason,
190
+ cause,
191
+ reason: skipReason(harness, cause),
188
192
  });
189
193
  for (const harness of harnesses) {
190
194
  if (!isHookHarness(harness)) {
191
- unsupported(harness, `${adapters[harness].name} has no command hooks`);
195
+ unsupported(harness, { type: "no-command-hooks" });
192
196
  continue;
193
197
  }
194
- const reason = await hookIssue(harness, hook.manifest, runtime);
195
- if (reason !== null) {
196
- unsupported(harness, reason);
198
+ const skip = await hookIssue(harness, hook.manifest, runtime);
199
+ if (skip !== null) {
200
+ unsupported(harness, skip);
197
201
  continue;
198
202
  }
199
203
  native.push(...hookEntries(harness, hook, runtime));
@@ -5,6 +5,7 @@ import { CliError, friendlyMessage } from "../../errors.js";
5
5
  import { selectionState, withSelection } from "../../config/environment.js";
6
6
  import { heldName, settleNames } from "./settle-names.js";
7
7
  import { stageAssets } from "./stage.js";
8
+ import { mcpRecords } from "./mcp-records.js";
8
9
  import { assertSupportedConfigHomes, startupEntries } from "./own-entries.js";
9
10
  import { resolveAssets } from "../asset-selection/index.js";
10
11
  import { pruneCache } from "../workspace/packages.js";
@@ -12,7 +13,7 @@ import { followImports } from "../imports/local.js";
12
13
  import { localOverlay } from "../workspace/overlay.js";
13
14
  import { openWorkspaceSource } from "../workspace/workspace-source.js";
14
15
  import { finishMoves } from "./moves.js";
15
- import { readSecrets } from "../secrets/index.js";
16
+ import { keptValues } from "./kept-values.js";
16
17
  import { locked, transact } from "./transaction.js";
17
18
  import { assertInstalledUntouched, linkWrites, nativeWrites, entryNames, stateText, treeWrites, } from "./writes.js";
18
19
  import { fileText } from "../../shared/files.js";
@@ -121,10 +122,19 @@ export async function synchronize(configPath, runtime, override, options = {}) {
121
122
  state: before,
122
123
  source,
123
124
  harnesses: settings.harnesses,
124
- kept: await readSecrets(runtime),
125
+ kept: await keptValues(runtime),
125
126
  runtime,
126
127
  });
127
128
  const { links: desired, native, trees } = staged;
129
+ const mcpServers = await mcpRecords({
130
+ assets: effective.assets,
131
+ previous: before.mcpServers,
132
+ definitions: staged.definitions,
133
+ invalid,
134
+ vanished,
135
+ localNames,
136
+ source,
137
+ });
128
138
  events.push(...staged.events);
129
139
  native.push(...startupEntries(settings, runtime, { knowledge: !!source }));
130
140
  const nativeName = entryNames([
@@ -151,7 +161,7 @@ export async function synchronize(configPath, runtime, override, options = {}) {
151
161
  kind: "file",
152
162
  path: stateFile,
153
163
  before: rawState,
154
- after: stateText({ links: desired, native, trees }),
164
+ after: stateText({ links: desired, native, trees, mcpServers }),
155
165
  },
156
166
  ];
157
167
  // Explicit overrides are one-shot delivery inputs, never a change to default preferences.