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
@@ -1,4 +1,5 @@
1
1
  import { json, ok, ORIGIN_HELP } from "../ui/format.js";
2
+ import { confirmSharingUrlQuery } from "../ui/mcp.js";
2
3
  import { Option } from "commander";
3
4
  import { harnesses } from "../harnesses/registry.js";
4
5
  import { defined } from "../shared/lookup.js";
@@ -14,14 +15,23 @@ export function registerMcp(program, context) {
14
15
  .description(`${action === "create" ? "Create" : "Publish a new revision of"} an MCP configuration directly`)
15
16
  .requiredOption("--origin <origin>", ORIGIN_HELP)
16
17
  .requiredOption("--file <file>", "JSON connection definition with secret references")
17
- .option("--key <key>", "Stable key for exact retries");
18
+ .option("--key <key>", "Stable key for exact retries")
19
+ .option("--allow-url-query", "Publish a URL with query parameters without asking");
18
20
  if (action === "update") {
19
21
  command.requiredOption("--expected-version <id>", "Inspected configuration version ID");
20
22
  }
21
23
  command.action(async (name, options) => {
24
+ const { allowUrlQuery, ...rest } = options;
25
+ const confirmUrlQuery = confirmSharingUrlQuery({
26
+ interactive: context.mode.interactive,
27
+ allowed: allowUrlQuery,
28
+ write: context.write,
29
+ fix: `barndog mcp ${action} ${name} --origin ${options.origin} --file ${options.file}${action === "update" ? ` --expected-version ${options.expectedVersion}` : ""} --allow-url-query`,
30
+ });
31
+ const input = { ...rest, name, confirmUrlQuery };
22
32
  const result = action === "create"
23
- ? await context.createMcp({ ...options, name })
24
- : await context.updateMcp({ ...options, name });
33
+ ? await context.createMcp(input)
34
+ : await context.updateMcp(input);
25
35
  if (context.mode.json) {
26
36
  return context.write(json(result));
27
37
  }
@@ -1,7 +1,8 @@
1
1
  import { assetKinds } from "../features/asset-kinds/index.js";
2
2
  import { CliError } from "../errors.js";
3
3
  import { pickOne } from "../ui/pick.js";
4
- import { clean, originLabel } from "../ui/format.js";
4
+ import { clean, dim, originLabel } from "../ui/format.js";
5
+ import { stateBadge } from "../ui/assets.js";
5
6
  import { only } from "../shared/lookup.js";
6
7
  /**
7
8
  * Names are unique only within a scope, so `--origin` picks between scopes
@@ -27,8 +28,10 @@ export async function resolveOrigin(context, { kind, name, origin, usage, }) {
27
28
  return pickOne(`${name} exists in several scopes. Which one?`, labels.map((label) => ({
28
29
  value: label,
29
30
  name: label,
30
- hint: clean(rows.find((row) => originLabel(row.origin) === label)?.version
31
- .description ?? ""),
31
+ columns: [
32
+ dim(clean(rows.find((row) => originLabel(row.origin) === label)?.version
33
+ .description ?? "")),
34
+ ],
32
35
  })));
33
36
  }
34
37
  /** Lets the person choose an installed asset when the command was given no name. */
@@ -40,7 +43,7 @@ export async function pickInstalled(context, kind, usage) {
40
43
  const item = await pickOne(`Choose a ${assetKinds[kind].one}`, items.map((item) => ({
41
44
  value: item,
42
45
  name: item.installedName,
43
- hint: `${item.origin} · ${item.state}`,
46
+ columns: [dim(item.origin), stateBadge(item.state)],
44
47
  })), { empty: `No ${assetKinds[kind].one}s are installed on this machine.` });
45
48
  return { name: item.name, origin: item.origin };
46
49
  }
@@ -1,9 +1,10 @@
1
1
  import { Option } from "commander";
2
2
  import { assetListOptions } from "../ui/asset-list.js";
3
3
  import { runSetInstall } from "../ui/scope-install.js";
4
+ import { LOCAL_ORIGIN } from "../features/workspace/overlay.js";
4
5
  import { runSelection } from "../ui/selection.js";
5
6
  import { pickOne } from "../ui/pick.js";
6
- import { bold, dim, hint, json, ok, originLabel, section, table, } from "../ui/format.js";
7
+ import { bold, dim, off, hint, json, ok, originLabel, section, table, } from "../ui/format.js";
7
8
  import { requireArguments } from "./arguments.js";
8
9
  const setDescriptions = {
9
10
  install: "Subscribe to a scope's shared assets",
@@ -59,7 +60,7 @@ export function registerSets(program, context) {
59
60
  : `${subscription.scope.type}/${subscription.scope.id}`),
60
61
  scope?.name ?? dim("unavailable"),
61
62
  subscription.mode,
62
- subscription.enabled ? ok("enabled") : dim("disabled"),
63
+ subscription.enabled ? ok("enabled") : off("disabled"),
63
64
  ]), { header: ["Scope", "Name", "Mode", "State"] }).join("\n")
64
65
  : dim(" None yet."));
65
66
  const terms = options.search?.toLowerCase().split(/\s+/).filter(Boolean) ?? [];
@@ -70,6 +71,14 @@ export function registerSets(program, context) {
70
71
  label(scope) === options.origin.replace(":", "/")) &&
71
72
  terms.every((term) => `${label(scope)} ${scope.name ?? ""}`.toLowerCase().includes(term)))
72
73
  .sort((a, b) => label(a).localeCompare(label(b)));
74
+ // A local folder is one set of its own; others come from Git or a server.
75
+ if (result.available.every((scope) => label(scope) === LOCAL_ORIGIN)) {
76
+ context.write("");
77
+ context.write("Your local folder is the only set a local workspace has, so there's nothing else to subscribe to.");
78
+ context.write(hint("barndog init", "Tip") +
79
+ dim(" connect a Git repository or BarnDog server to subscribe to what your organization and teams share"));
80
+ return;
81
+ }
73
82
  const start = (options.page - 1) * options.limit;
74
83
  const page = available.slice(start, start + options.limit);
75
84
  context.write("");
@@ -80,8 +89,10 @@ export function registerSets(program, context) {
80
89
  if (start + options.limit < available.length) {
81
90
  context.write(hint(`barndog sets list --page ${options.page + 1}`));
82
91
  }
83
- context.write("");
84
- context.write(hint("barndog sets install", "Tip") + dim(" to subscribe"));
92
+ if (available.length) {
93
+ context.write("");
94
+ context.write(hint("barndog sets install", "Tip") + dim(" to subscribe"));
95
+ }
85
96
  });
86
97
  const chooseScope = async (message, filter, empty) => {
87
98
  const result = await load();
@@ -91,7 +102,7 @@ export function registerSets(program, context) {
91
102
  .map((scope) => ({
92
103
  value: label(scope),
93
104
  name: label(scope),
94
- hint: scope.name,
105
+ columns: [dim(scope.name)],
95
106
  })), { empty });
96
107
  };
97
108
  for (const action of ["install", "remove", "enable", "disable"]) {
@@ -19,7 +19,9 @@ export function registerStatus(program, context) {
19
19
  : inventory));
20
20
  }
21
21
  if ("changes" in working) {
22
- for (const line of renderCollaboration(working)) {
22
+ for (const line of renderCollaboration(working, {
23
+ runtime: context.runtime,
24
+ })) {
23
25
  context.write(line);
24
26
  }
25
27
  context.write("");
@@ -27,7 +27,7 @@ export function registerSync(program, context) {
27
27
  if (context.mode.json) {
28
28
  return context.write(json(events));
29
29
  }
30
- for (const line of renderSyncOutput(events, {
30
+ for (const line of renderSyncOutput(events, context.runtime, {
31
31
  title: options.dryRun ? "sync --dry-run" : "sync",
32
32
  preview: options.dryRun,
33
33
  verbose: options.verbose,
@@ -0,0 +1,64 @@
1
+ import { Option } from "commander";
2
+ import { CliError } from "../errors.js";
3
+ import { json } from "../ui/format.js";
4
+ import { askUninstall, confirmUninstall, hasAssets, renderUninstall, renderUninstallPlan, uninstallOptions, } from "../ui/uninstall.js";
5
+ /** Registers `uninstall`. */
6
+ export function registerUninstall(program, context) {
7
+ program
8
+ .command("uninstall")
9
+ .description("Remove BarnDog from this machine, leaving your Skills, MCP servers and Hooks in your coding tools or removing them too")
10
+ .addOption(new Option("--keep-setup", "Leave Skills, MCP servers and Hooks in your coding tools as plain files").conflicts("removeAll"))
11
+ .option("--remove-all", "Remove every Skill, MCP server and Hook BarnDog installed")
12
+ .option("--drop-adopted", "With --remove-all, delete adopted assets instead of putting them back")
13
+ .option("--remove-workspace", "Delete the local workspace folder too, when it is inside ~/.barndog")
14
+ .option("--force", "Put adopted assets back even if BarnDog's copy was edited since")
15
+ .option("--dry-run", "Show what would happen without changing anything")
16
+ .action(async (flags) => {
17
+ const survey = await context.uninstallSurvey();
18
+ const choices = {
19
+ // With nothing of the developer's installed, there is nothing to choose.
20
+ keepSetup: (flags.keepSetup || (flags.removeAll ? false : undefined)) ??
21
+ (hasAssets(survey) ? undefined : true),
22
+ dropAdopted: flags.dropAdopted,
23
+ removeWorkspace: flags.removeWorkspace,
24
+ force: flags.force,
25
+ };
26
+ let options;
27
+ if (context.mode.interactive) {
28
+ options = await askUninstall(survey, choices, context.runtime);
29
+ }
30
+ else if (choices.keepSetup === undefined) {
31
+ throw new CliError("Choose whether to keep your Skills, MCP servers and Hooks: --keep-setup leaves them in your coding tools, --remove-all removes them.", "barndog uninstall --keep-setup");
32
+ }
33
+ else {
34
+ options = uninstallOptions(survey, {
35
+ ...choices,
36
+ keepSetup: choices.keepSetup,
37
+ });
38
+ }
39
+ if (flags.dryRun) {
40
+ if (context.mode.json) {
41
+ return context.write(json({ survey, options }));
42
+ }
43
+ for (const line of renderUninstallPlan(survey, options, context.runtime)) {
44
+ context.write(line);
45
+ }
46
+ return;
47
+ }
48
+ if (context.mode.interactive) {
49
+ for (const line of renderUninstallPlan(survey, options, context.runtime)) {
50
+ context.write(line);
51
+ }
52
+ if (!(await confirmUninstall())) {
53
+ return context.write("Nothing was changed.");
54
+ }
55
+ }
56
+ const result = await context.uninstall(options);
57
+ if (context.mode.json) {
58
+ return context.write(json(result));
59
+ }
60
+ for (const line of renderUninstall(result, context.runtime)) {
61
+ context.write(line);
62
+ }
63
+ });
64
+ }
@@ -1,5 +1,6 @@
1
1
  import { bold, dim, heading, json, ok, plural, table, warn, } from "../ui/format.js";
2
2
  import { chooseKeepLocal, pickLocalAssets, renderMove } from "../ui/move.js";
3
+ import { confirmSharingUrlQuery } from "../ui/mcp.js";
3
4
  import { CliError } from "../errors.js";
4
5
  const migrationActionStyles = {
5
6
  publish: ok,
@@ -57,6 +58,7 @@ export function registerWorkspace(program, context) {
57
58
  .option("--as <name>", "New name, for moving one asset whose name is taken")
58
59
  .option("--repo <url>", "Send to this Git repo; this machine stays as it is")
59
60
  .option("--server <url>", "Send to this Cloud Workspace; this machine stays as it is")
61
+ .option("--allow-url-query", "Share MCP servers whose URL has query parameters without asking")
60
62
  .addHelpText("after", `
61
63
  Without names, a terminal lists your local assets to pick from; elsewhere, name them or pass --all.
62
64
 
@@ -78,6 +80,23 @@ With --repo or --server this machine stays as it is, so the assets are always co
78
80
  as: options.as,
79
81
  repo: options.repo,
80
82
  server: options.server,
83
+ confirmUrlQuery: confirmSharingUrlQuery({
84
+ interactive: context.mode.interactive,
85
+ allowed: options.allowUrlQuery,
86
+ write: context.write,
87
+ fix: [
88
+ "barndog local move",
89
+ chosen?.join(" ") ?? "--all",
90
+ keepLocal ? "--keep-local" : "--no-keep-local",
91
+ ...Object.entries({
92
+ to: options.to,
93
+ as: options.as,
94
+ repo: options.repo,
95
+ server: options.server,
96
+ }).flatMap(([flag, value]) => value ? [`--${flag} ${value}`] : []),
97
+ "--allow-url-query",
98
+ ].join(" "),
99
+ }),
81
100
  });
82
101
  if (context.mode.json) {
83
102
  return context.write(json(result));
@@ -36,6 +36,8 @@ export function barndogPaths(home) {
36
36
  },
37
37
  /** The last Cloud catalog revision a background sync delivered. */
38
38
  cloudCheck: join(root, "cloud-check.json"),
39
+ /** The CLI versions last published on npm, and when they were checked. */
40
+ updateCheck: join(root, "update-check.json"),
39
41
  /** Saved sessions, per server. */
40
42
  credentials: join(root, "credentials.json"),
41
43
  credentialsLock: join(root, "credentials.lock"),
@@ -12,6 +12,23 @@ const linkSchema = z.object({
12
12
  source: z.string().refine(isAbsolute),
13
13
  target: z.string(),
14
14
  });
15
+ /**
16
+ * One selected MCP server, enabled or not, as the last sync saw it. Disabling a
17
+ * server removes its native entries, so this is what lets `mcp env` name it and
18
+ * check its variables without asking the workspace.
19
+ */
20
+ const mcpServerSchema = z.strictObject({
21
+ id: z.string(),
22
+ /** The workspace's name for it. */
23
+ name: z.string(),
24
+ /** The name its coding-tool entries use, after any clash rename. */
25
+ installedName: z.string(),
26
+ /** The published version `variables` were read from. */
27
+ versionId: z.string(),
28
+ /** Every variable its definition refers to. */
29
+ variables: z.array(z.string()),
30
+ enabled: z.boolean(),
31
+ });
15
32
  /** The complete persisted installation ownership journal. */
16
33
  const stateSchema = z.looseObject({
17
34
  version: z.literal(1),
@@ -31,6 +48,8 @@ const stateSchema = z.looseObject({
31
48
  fingerprint: z.string(),
32
49
  versionId: z.string(),
33
50
  })),
51
+ /** Absent until a sync by a CLI that records MCP servers. */
52
+ mcpServers: z.array(mcpServerSchema).optional(),
34
53
  });
35
54
  /**
36
55
  * Reads installation ownership and checks targets against the supplied home;
@@ -0,0 +1,15 @@
1
+ import { homedir } from "node:os";
2
+ import { refreshUpdateCheck } from "../features/update-check/index.js";
3
+ // Started detached after a command, with the home that command used. It can
4
+ // never fail that command: a missed check is retried after the next one.
5
+ try {
6
+ await refreshUpdateCheck({
7
+ home: process.argv[2] ?? homedir(),
8
+ cwd: process.cwd(),
9
+ env: { ...process.env },
10
+ platform: process.platform,
11
+ });
12
+ }
13
+ catch {
14
+ // Nothing to report to; the cached answer stays as it was.
15
+ }
package/dist/errors.js CHANGED
@@ -251,6 +251,10 @@ export function friendlyHint(error) {
251
251
  const code = serverProblemCode(error);
252
252
  return code ? serverProblems[code].fix : undefined;
253
253
  }
254
+ /** Inquirer's error name when the person presses Ctrl+C at a prompt. */
255
+ const PROMPT_CLOSED = "ExitPromptError";
256
+ /** Whether the person cancelled a prompt (Ctrl+C), which is a choice, not a failure. */
257
+ export const promptCancelled = (error) => error instanceof Error && error.name === PROMPT_CLOSED;
254
258
  /** Turns internal codes and validation errors into something a person can act on. */
255
259
  export function friendlyMessage(error) {
256
260
  if (!(error instanceof Error)) {
@@ -18,8 +18,7 @@ import { assetKinds } from "../asset-kinds/index.js";
18
18
  import { synchronize } from "../environment/sync.js";
19
19
  import { locked } from "../environment/transaction.js";
20
20
  import { ensureLocalWorkspace } from "../imports/local.js";
21
- import { literalNotes } from "../mcps/import.js";
22
- import { readSecrets, updateSecrets } from "../secrets/index.js";
21
+ import { keepLiteralValues, literalValues, signInTools, } from "../mcps/import.js";
23
22
  import { writePackage } from "../workspace/directory.js";
24
23
  import { localRepoSource } from "../workspace/repo-source.js";
25
24
  import { copyFingerprint, installed } from "./copies.js";
@@ -67,30 +66,37 @@ async function hasSharedWorkspace(home) {
67
66
  }
68
67
  /** Same-named copies share one source, so each source's notes appear once. */
69
68
  function adoptionNotes(plan, sourceOf, keep) {
70
- const sources = new Map(plan.map((asset) => [asset.source.key, asset]));
71
- return [...sources.values()].flatMap((asset) => {
72
- const source = sourceOf(asset);
73
- return [...source.notes, ...literalNotes(source.literals, keep)].map((text) => ({ kind: asset.kind, name: asset.name, text }));
74
- });
69
+ const sources = [
70
+ ...new Map(plan.map((asset) => [asset.source.key, asset])).values(),
71
+ ];
72
+ return {
73
+ notes: sources.flatMap((asset) => sourceOf(asset).notes.map((text) => ({
74
+ kind: asset.kind,
75
+ name: asset.name,
76
+ text,
77
+ }))),
78
+ values: sources.flatMap((asset) => literalValues(asset.name, sourceOf(asset).literals, keep)),
79
+ };
75
80
  }
76
- /**
77
- * Keeps the chosen values before the sync that writes them into the tools,
78
- * and returns how to put the file back as it was if adopting fails.
79
- */
80
- async function keepValues(literals, keep, runtime) {
81
- const chosen = literals.filter((l) => keep.includes(l.variable));
82
- if (!chosen.length) {
83
- return async () => { };
81
+ /** The adopted MCP servers, once each, under the asset ID their copy got. */
82
+ function adoptedServers(plan, record, sourceOf) {
83
+ const servers = new Map();
84
+ for (const [index, asset] of plan.entries()) {
85
+ const { content } = sourceOf(asset);
86
+ if (content.kind === "mcp") {
87
+ servers.set(asset.source.key, {
88
+ id: defined(record.items[index], "Each planned asset has an item")
89
+ .assetId,
90
+ name: asset.name,
91
+ definition: content.definition,
92
+ });
93
+ }
84
94
  }
85
- const before = await readSecrets(runtime);
86
- await updateSecrets(Object.fromEntries(chosen.map((l) => [l.variable, l.value])), runtime);
87
- return async () => {
88
- await updateSecrets(Object.fromEntries(chosen.map((l) => [l.variable, before[l.variable] ?? null])), runtime);
89
- };
95
+ return [...servers.values()];
90
96
  }
91
97
  /** Takes over the chosen assets; on any failure, puts back what it changed. */
92
98
  export async function adoptNative(keys,
93
- /** Variables whose values BarnDog keeps on this machine (see `mcp env`). */
99
+ /** The MCP values BarnDog keeps on this machine (see `mcp env`). */
94
100
  keep, runtime) {
95
101
  const { home } = runtime;
96
102
  return locked(runtime, async () => {
@@ -141,18 +147,15 @@ keep, runtime) {
141
147
  }
142
148
  // Written before anything changes, so undo can always find what moved.
143
149
  await writeAdoption(record, home);
144
- const sources = [
145
- ...new Map(plan.map((asset) => [asset.source.key, asset])).values(),
146
- ].map(sourceOf);
147
- let forgetValues = async () => { };
150
+ const values = { forget: async () => { } };
148
151
  try {
149
- forgetValues = await keepValues(sources.flatMap((source) => source.literals), keep, runtime);
150
- const events = await apply({ record, plan, sourceOf, workspace }, runtime);
152
+ const events = await apply({ record, plan, sourceOf, workspace, keep, values }, runtime);
151
153
  return {
152
154
  id,
153
155
  adopted: plan,
154
156
  backup: paths.folder,
155
- notes: adoptionNotes(plan, sourceOf, keep),
157
+ ...adoptionNotes(plan, sourceOf, keep),
158
+ signIn: await signInTools(adoptedServers(plan, record, sourceOf), runtime),
156
159
  events,
157
160
  canShare: await hasSharedWorkspace(home),
158
161
  };
@@ -161,7 +164,7 @@ keep, runtime) {
161
164
  await restore(record, record.items, runtime).catch((undoError) => {
162
165
  throw new CliError(`Adopting failed (${friendlyMessage(error)}), and putting things back failed too: ${friendlyMessage(undoError)}`, `barndog adopt undo ${id}`, { cause: error });
163
166
  });
164
- await forgetValues();
167
+ await values.forget();
165
168
  throw error;
166
169
  }
167
170
  });
@@ -187,6 +190,21 @@ async function apply(input, runtime) {
187
190
  }
188
191
  item.assetId = asset.id;
189
192
  }
193
+ // Kept by asset ID, which exists only now; saved before the sync writes them.
194
+ // One source per name, and every item of it shares one copy and asset ID.
195
+ const servers = new Map(plan.flatMap((asset, index) => asset.kind === "mcp"
196
+ ? [
197
+ [
198
+ asset.source.key,
199
+ {
200
+ id: defined(record.items[index], "Each planned asset has an item").assetId,
201
+ name: asset.name,
202
+ literals: sourceOf(asset).literals,
203
+ },
204
+ ],
205
+ ]
206
+ : []));
207
+ input.values.forget = await keepLiteralValues([...servers.values()], input.keep, runtime);
190
208
  // A settings file is saved as the user left it, before BarnDog's first change.
191
209
  for (const item of record.items) {
192
210
  const { original } = item;
@@ -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
+ }
@@ -125,6 +125,28 @@ export async function logout(runtime) {
125
125
  });
126
126
  return { server, revoked };
127
127
  }
128
+ /**
129
+ * Ends every saved session: revokes each on its server where it can, and
130
+ * removes every local credential even where revocation failed.
131
+ */
132
+ export async function signOutEverywhere(runtime) {
133
+ const { servers } = await readCredentials(runtime);
134
+ const results = [];
135
+ for (const [server, credential] of Object.entries(servers)) {
136
+ try {
137
+ await revokeSession(signInClient(server, runtime), credential.token);
138
+ results.push({ server, revoked: true });
139
+ }
140
+ catch {
141
+ results.push({ server, revoked: false });
142
+ }
143
+ }
144
+ await updateCredentials(runtime, (credentials) => {
145
+ credentials.servers = {};
146
+ delete credentials.selectedServer;
147
+ });
148
+ return results;
149
+ }
128
150
  /**
129
151
  * Fetches the authenticated server context; missing or expired credentials
130
152
  * require login.
@@ -246,7 +246,6 @@ async function findRecord(runtime, parse) {
246
246
  throw new NoWorkingCopyError("This folder isn't an editable Skill or Hook. Working-copy commands run inside a folder made by barndog skills pull, barndog hooks pull or barndog skills create.", "barndog skills pull <name>");
247
247
  }
248
248
  async function replaceFiles(root, entries, runtime) {
249
- assertPackagePaths(entries, runtime.platform);
250
249
  // Validate paths and directory topology before touching local files.
251
250
  const paths = new Set(entries.map((e) => e.path));
252
251
  for (const path of paths) {
@@ -267,6 +266,8 @@ async function replaceFiles(root, entries, runtime) {
267
266
  }
268
267
  }
269
268
  }
269
+ // After the safety check, so an unsafe path is reported as unsafe.
270
+ assertPackagePaths(entries, runtime.platform);
270
271
  const old = await readDirectory(root, runtime);
271
272
  for (const entry of old) {
272
273
  await rm(join(root, entry.path));
@@ -0,0 +1 @@
1
+ export {};