barndog 0.2.2 → 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 (66) hide show
  1. package/README.md +2 -0
  2. package/dist/cli.js +2 -2
  3. package/dist/commands/add.js +4 -2
  4. package/dist/commands/asset-install.js +7 -3
  5. package/dist/commands/asset-share.js +15 -3
  6. package/dist/commands/capabilities.js +23 -5
  7. package/dist/commands/collaboration.js +9 -3
  8. package/dist/commands/harnesses.js +1 -1
  9. package/dist/commands/hooks.js +16 -1
  10. package/dist/commands/mcp-env.js +39 -12
  11. package/dist/commands/mcp.js +13 -3
  12. package/dist/commands/origin.js +7 -4
  13. package/dist/commands/sets.js +3 -3
  14. package/dist/commands/status.js +3 -1
  15. package/dist/commands/sync.js +1 -1
  16. package/dist/commands/uninstall.js +4 -2
  17. package/dist/commands/workspace.js +19 -0
  18. package/dist/config/state.js +19 -0
  19. package/dist/errors.js +4 -0
  20. package/dist/features/adoption/adopt.js +18 -1
  21. package/dist/features/adoption/scan.js +5 -0
  22. package/dist/features/asset-kinds/url-query.js +26 -0
  23. package/dist/features/doctor/check.js +1 -0
  24. package/dist/features/doctor/grouped.js +127 -0
  25. package/dist/features/doctor/index.js +18 -33
  26. package/dist/features/environment/events.js +10 -0
  27. package/dist/features/environment/kept-value-events.js +40 -0
  28. package/dist/features/environment/mcp-records.js +57 -0
  29. package/dist/features/environment/stage.js +12 -8
  30. package/dist/features/environment/sync.js +11 -1
  31. package/dist/features/environment/writes.js +25 -27
  32. package/dist/features/hooks/compatibility.js +37 -17
  33. package/dist/features/hooks/test.js +2 -2
  34. package/dist/features/inventory/hook-matrix.js +14 -0
  35. package/dist/features/inventory/hook-readiness.js +47 -0
  36. package/dist/features/inventory/index.js +9 -1
  37. package/dist/features/inventory/show.js +10 -2
  38. package/dist/features/mcps/import.js +40 -8
  39. package/dist/features/mcps/index.js +23 -10
  40. package/dist/features/mcps/values.js +71 -21
  41. package/dist/features/migration/move.js +4 -0
  42. package/dist/features/migration/promote.js +1 -0
  43. package/dist/features/native/adapters.js +4 -44
  44. package/dist/features/native/requirements.js +98 -0
  45. package/dist/features/secrets/index.js +4 -3
  46. package/dist/features/uninstall/index.js +1 -1
  47. package/dist/features/workspace/cloud-source.js +38 -4
  48. package/dist/program.js +4 -1
  49. package/dist/ui/add-hook.js +2 -2
  50. package/dist/ui/add-mcp.js +37 -5
  51. package/dist/ui/add-skills.js +2 -2
  52. package/dist/ui/adopt.js +80 -14
  53. package/dist/ui/assets.js +15 -2
  54. package/dist/ui/collaboration.js +5 -3
  55. package/dist/ui/format.js +81 -2
  56. package/dist/ui/hook-compatibility.js +176 -22
  57. package/dist/ui/mcp.js +98 -19
  58. package/dist/ui/move.js +1 -1
  59. package/dist/ui/onboarding.js +11 -2
  60. package/dist/ui/output.js +96 -42
  61. package/dist/ui/package-details.js +7 -2
  62. package/dist/ui/pick.js +20 -6
  63. package/dist/ui/selection.js +1 -1
  64. package/dist/ui/uninstall.js +14 -2
  65. package/dist/ui/variable-problems.js +23 -0
  66. package/package.json +2 -2
@@ -22,6 +22,7 @@ import { discoverSkills, ROOT_TOKEN } from "../imports/discover.js";
22
22
  import { readFolder } from "../imports/folder.js";
23
23
  import { renamedSkill } from "../imports/local.js";
24
24
  import { convertServer, harnessServers } from "../mcps/import.js";
25
+ import { queryParameters } from "../asset-kinds/url-query.js";
25
26
  import { assetKinds } from "../asset-kinds/index.js";
26
27
  import { assetPath, NAME_RULE } from "../workspace/format.js";
27
28
  import { localMcpNamed } from "../mcps/import.js";
@@ -41,6 +42,7 @@ const publicAsset = (asset) => ({
41
42
  identical: asset.identical,
42
43
  notes: asset.notes,
43
44
  values: asset.values,
45
+ queryParameters: asset.queryParameters,
44
46
  });
45
47
  /** Every adoptable asset in the selected tools, with its contents. */
46
48
  export async function findNativeAssets(runtime) {
@@ -217,6 +219,7 @@ async function readSkill(entry, runtime) {
217
219
  notes: [],
218
220
  literals: [],
219
221
  values: [],
222
+ queryParameters: [],
220
223
  content: { kind: "skill", entries: renamedSkill(skill, name) },
221
224
  original: link === null
222
225
  ? { type: "folder", path }
@@ -265,6 +268,7 @@ async function toolServers(selected, runtime) {
265
268
  key,
266
269
  variable,
267
270
  })),
271
+ queryParameters: queryParameters(converted.definition),
268
272
  content: { kind: "mcp", definition: converted.definition },
269
273
  original: {
270
274
  type: "entry",
@@ -319,6 +323,7 @@ async function toolHooks(harness, state, runtime) {
319
323
  notes: hook.notes,
320
324
  literals: [],
321
325
  values: [],
326
+ queryParameters: [],
322
327
  content: { kind: "hook", entries: hook.entries },
323
328
  original: {
324
329
  type: "entry",
@@ -0,0 +1,26 @@
1
+ /**
2
+ * The names of an HTTP server's query parameters, never their values, which may
3
+ * be secret. Empty for a stdio server or a URL without a query string.
4
+ */
5
+ export function queryParameters(definition) {
6
+ if (definition.transport !== "http") {
7
+ return [];
8
+ }
9
+ return [...new Set(new URL(definition.url).searchParams.keys())];
10
+ }
11
+ /**
12
+ * Whether to share the servers whose URLs have a query string: true when there
13
+ * are none, else what `confirm` answers. Without `confirm`, nobody was asked,
14
+ * so they are not shared.
15
+ */
16
+ export async function mayShareUrlQueries(servers, confirm) {
17
+ const queries = urlQueries(servers);
18
+ return !queries.length || ((await confirm?.(queries)) ?? false);
19
+ }
20
+ /** The servers among `servers` whose URLs have a query string. */
21
+ export function urlQueries(servers) {
22
+ return servers.flatMap(({ name, definition }) => {
23
+ const parameters = definition ? queryParameters(definition) : [];
24
+ return parameters.length ? [{ name, parameters }] : [];
25
+ });
26
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -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,33 +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
- import { unassignedValueMessage, unsetValueMessage, } from "../environment/events.js";
14
- /** An MCP variable with no value on this machine, or a kept value no server has. */
15
- function variableCheck(event) {
16
- if (event.type === "unassigned-value") {
17
- return [
18
- {
19
- name: "MCP variable",
20
- status: "warn",
21
- detail: unassignedValueMessage(event.variable),
22
- fix: `barndog mcp env set <server> ${event.variable}`,
23
- },
24
- ];
25
- }
26
- if (event.type !== "unset-variable") {
27
- return [];
28
- }
29
- return [
30
- {
31
- name: "MCP variable",
32
- status: "warn",
33
- detail: `${unsetValueMessage(event)} 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.`,
34
- fix: `barndog mcp env set ${event.server} ${event.variable}`,
35
- },
36
- ];
37
- }
14
+ import { cantRunChecks, hooksMissingTools, variableChecks } from "./grouped.js";
38
15
  const failure = (error) => ({
39
16
  detail: error instanceof Error ? error.message : String(error),
40
17
  fix: error instanceof CliError ? error.hint : undefined,
@@ -83,6 +60,12 @@ async function gitChecks(workspace, runtime) {
83
60
  * what failed (a readable configuration, a session).
84
61
  */
85
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) {
86
69
  const { home } = runtime;
87
70
  const checks = [];
88
71
  let settings;
@@ -165,11 +148,18 @@ export async function doctor(runtime) {
165
148
  : "Everything selected is installed and up to date.",
166
149
  fix: pending ? "barndog sync" : undefined,
167
150
  });
168
- checks.push(...events.flatMap(variableCheck));
151
+ checks.push(...variableChecks(events));
169
152
  for (const event of events) {
170
153
  if (event.type === "notice") {
171
154
  checks.push({ name: "Notice", status: "warn", detail: event.message });
172
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
+ }
173
163
  if (event.type === "clash") {
174
164
  checks.push({
175
165
  name: "Name clash",
@@ -185,14 +175,9 @@ export async function doctor(runtime) {
185
175
  detail: `${event.kind} ${event.name}: ${event.reason}. The installed version stays in place.`,
186
176
  });
187
177
  }
188
- if (event.type === "unsupported") {
189
- checks.push({
190
- name: "Unsupported",
191
- status: "warn",
192
- detail: `${event.kind} ${event.name} on ${adapters[event.harness].name}: ${event.reason}`,
193
- });
194
- }
195
178
  }
179
+ checks.push(...cantRunChecks(events));
180
+ found.hooksMissingTools = hooksMissingTools(events);
196
181
  }
197
182
  catch (error) {
198
183
  checks.push({ name: "Installation", status: "fail", ...failure(error) });
@@ -4,5 +4,15 @@ export function unsetValueMessage(event) {
4
4
  ? `${event.from} has no value here, so ${event.server} can't read ${event.variable} from it.`
5
5
  : `${event.variable} has no value here, so ${event.server} can't use it.`;
6
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
+ }
7
17
  /** What an `unassigned-value` event means, as one sentence. */
8
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,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
+ }
@@ -4,10 +4,11 @@ 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";
7
+ import { isHookHarness, skillDirectory } from "../../harnesses/registry.js";
8
8
  import { isInside } from "../../shared/files.js";
9
9
  import { defined } from "../../shared/lookup.js";
10
10
  import { hookEntries, hookIssue, mcpEntry } from "../native/adapters.js";
11
+ import { skipReason } from "../native/requirements.js";
11
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";
@@ -37,6 +38,7 @@ export async function stageAssets(input) {
37
38
  const native = [];
38
39
  const trees = [];
39
40
  const events = [];
41
+ const definitions = new Map();
40
42
  const names = new Set();
41
43
  const ids = new Set();
42
44
  /** Installed MCP servers, to report the variables they find no value for. */
@@ -145,6 +147,7 @@ export async function stageAssets(input) {
145
147
  }
146
148
  else if (ref.kind === "mcp") {
147
149
  const definition = await source.mcpDefinition(ref);
150
+ definitions.set(ref.id, definition);
148
151
  const values = input.kept.servers[ref.id] ?? {};
149
152
  const applied = applyKeptValues(definition, values);
150
153
  servers.push({ name, definition, values });
@@ -170,7 +173,7 @@ export async function stageAssets(input) {
170
173
  }
171
174
  }
172
175
  events.push(...valueEvents(servers, input.kept, input.runtime.env));
173
- return { links: desired, native, trees, events };
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";
@@ -125,6 +126,15 @@ export async function synchronize(configPath, runtime, override, options = {}) {
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.
@@ -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
  }