barndog 0.2.1 → 0.2.2

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 (53) hide show
  1. package/README.md +19 -0
  2. package/dist/cli.js +27 -1
  3. package/dist/commands/asset-list.js +5 -1
  4. package/dist/commands/harnesses.js +32 -2
  5. package/dist/commands/mcp-env.js +130 -41
  6. package/dist/commands/sets.js +13 -2
  7. package/dist/commands/uninstall.js +62 -0
  8. package/dist/config/paths.js +2 -0
  9. package/dist/entry/update-check.js +15 -0
  10. package/dist/features/adoption/adopt.js +31 -30
  11. package/dist/features/auth/session.js +22 -0
  12. package/dist/features/collaboration/workspace-store.js +2 -1
  13. package/dist/features/doctor/index.js +25 -8
  14. package/dist/features/environment/events.js +8 -1
  15. package/dist/features/environment/kept-values.js +68 -0
  16. package/dist/features/environment/moves.js +17 -1
  17. package/dist/features/environment/stage.js +20 -20
  18. package/dist/features/environment/sync.js +2 -2
  19. package/dist/features/inventory/index.js +45 -2
  20. package/dist/features/mcps/import.js +36 -15
  21. package/dist/features/mcps/index.js +12 -2
  22. package/dist/features/mcps/values.js +108 -20
  23. package/dist/features/migration/migrate.js +15 -0
  24. package/dist/features/migration/move.js +34 -9
  25. package/dist/features/native/adapters.js +1 -2
  26. package/dist/features/native/hook-shell.js +11 -0
  27. package/dist/features/secrets/index.js +94 -29
  28. package/dist/features/uninstall/index.js +126 -0
  29. package/dist/features/uninstall/leave.js +152 -0
  30. package/dist/features/uninstall/survey.js +103 -0
  31. package/dist/features/update-check/index.js +108 -0
  32. package/dist/features/workspace/format.js +6 -1
  33. package/dist/harnesses/claude.js +1 -1
  34. package/dist/harnesses/codex.js +46 -22
  35. package/dist/harnesses/cursor.js +1 -1
  36. package/dist/harnesses/opencode.js +1 -1
  37. package/dist/harnesses/read-renamed-variables.js +141 -0
  38. package/dist/harnesses/renamed-variables.js +99 -0
  39. package/dist/platform.js +12 -1
  40. package/dist/program.js +21 -9
  41. package/dist/ui/add-mcp.js +22 -16
  42. package/dist/ui/adopt.js +11 -6
  43. package/dist/ui/connection.js +2 -0
  44. package/dist/ui/harness-picker.js +7 -2
  45. package/dist/ui/mcp.js +89 -23
  46. package/dist/ui/move.js +2 -1
  47. package/dist/ui/output.js +33 -8
  48. package/dist/ui/secret-input.js +9 -0
  49. package/dist/ui/uninstall.js +174 -0
  50. package/dist/ui/update.js +10 -0
  51. package/dist/version.js +2 -2
  52. package/package.json +1 -1
  53. package/dist/entry/mcp-launch.js +0 -71
package/README.md CHANGED
@@ -61,6 +61,16 @@ Runs on **macOS, Linux, and Windows** with [Node.js](https://nodejs.org) 24 or n
61
61
  npm install -g barndog
62
62
  ```
63
63
 
64
+ ### Update
65
+
66
+ ```sh
67
+ npm install -g barndog@latest
68
+ barndog sync
69
+ barndog --version
70
+ ```
71
+
72
+ Run `barndog sync` after every update: it brings the session-start and Hook registrations in your coding tools in line with the new version.
73
+
64
74
  ## Quick start
65
75
 
66
76
  ```sh
@@ -96,6 +106,15 @@ BarnDog is careful with your existing setup:
96
106
  - Changes are journaled before they're applied, so an interrupted sync is finished safely on the next run.
97
107
  - Hook scripts run only inside your coding tools, after their own trust checks. Installing or syncing never runs them.
98
108
 
109
+ ## Uninstall
110
+
111
+ ```sh
112
+ barndog uninstall
113
+ npm uninstall -g barndog
114
+ ```
115
+
116
+ Run `barndog uninstall` first. It asks whether to leave your Skills, MCP servers, and Hooks in your coding tools or remove them.
117
+
99
118
  ## Documentation
100
119
 
101
120
  - [What is BarnDog?](https://barndog.dev/docs)
package/dist/cli.js CHANGED
@@ -1,16 +1,21 @@
1
1
  #!/usr/bin/env node
2
+ import { spawn } from "node:child_process";
3
+ import { fileURLToPath } from "node:url";
2
4
  import { CommanderError, InvalidArgumentError } from "commander";
3
5
  import { assertCommandAvailable, currentSetupMode, } from "./commands/availability.js";
4
6
  import { captureRuntime, createProgram } from "./program.js";
5
7
  import { renderError, renderJsonError } from "./ui/output.js";
6
8
  import { json } from "./ui/format.js";
7
9
  import { CliError, NothingToDoError } from "./errors.js";
10
+ import { updateCheck } from "./features/update-check/index.js";
11
+ import { renderUpdateNotice } from "./ui/update.js";
12
+ import { cliVersion } from "./version.js";
8
13
  // Parsing errors happen before any action runs, so read the flag directly.
9
14
  const words = process.argv.slice(2);
10
15
  const end = words.indexOf("--");
11
16
  const asJson = (end < 0 ? words : words.slice(0, end)).includes("--json");
17
+ const runtime = captureRuntime();
12
18
  try {
13
- const runtime = captureRuntime();
14
19
  await createProgram({
15
20
  runtime,
16
21
  guard: (path, options) => assertCommandAvailable(path, options, runtime),
@@ -42,3 +47,24 @@ catch (error) {
42
47
  process.exitCode = 1;
43
48
  }
44
49
  }
50
+ // After the command, on stderr, so it never changes what a script reads; and
51
+ // it can never fail the command.
52
+ if (!asJson && process.stderr.isTTY) {
53
+ try {
54
+ const check = await updateCheck(cliVersion, runtime);
55
+ if (check?.update) {
56
+ console.error(renderUpdateNotice(check.update).join("\n"));
57
+ }
58
+ if (check?.due) {
59
+ spawn(process.execPath, [
60
+ fileURLToPath(new URL("entry/update-check.js", import.meta.url)),
61
+ runtime.home,
62
+ ], { detached: true, windowsHide: true, stdio: "ignore" })
63
+ .on("error", () => { })
64
+ .unref();
65
+ }
66
+ }
67
+ catch {
68
+ // The next command checks again.
69
+ }
70
+ }
@@ -4,6 +4,7 @@ import { assetListing, inventoryHints, renderCatalog, renderInventory, } from ".
4
4
  import { dim, hint, json } from "../ui/format.js";
5
5
  import { assetKinds } from "../features/asset-kinds/index.js";
6
6
  import { addArguments } from "./arguments.js";
7
+ import { unsetVariableNotes } from "../ui/mcp.js";
7
8
  /** `list`: installed, disabled and available assets of one kind. */
8
9
  export function registerList(command, kind, context) {
9
10
  const labels = assetKinds[kind];
@@ -22,7 +23,7 @@ export function registerList(command, kind, context) {
22
23
  const onlyAvailable = options.available && !narrowed;
23
24
  let catalogProblem;
24
25
  const [inventory, rows] = await Promise.all([
25
- context.inventory(),
26
+ context.inventory({ checkVariables: kind === "mcp" }),
26
27
  options.available || !narrowed
27
28
  ? context.searchCatalog(kind).catch((error) => {
28
29
  // JSON has nowhere to say the list is partial, so it fails;
@@ -83,6 +84,9 @@ export function registerList(command, kind, context) {
83
84
  }
84
85
  }
85
86
  const onThisMachine = page.filter((item) => item.state !== "available");
87
+ for (const line of unsetVariableNotes(onThisMachine)) {
88
+ context.write(line);
89
+ }
86
90
  const hints = inventoryHints(onThisMachine);
87
91
  if (hints.length) {
88
92
  context.write(["", ...hints].join("\n"));
@@ -11,6 +11,18 @@ function managedLine(managed) {
11
11
  ? `${ok("✔")} BarnDog now manages ${toolNames(managed)}.`
12
12
  : `${ok("✔")} BarnDog no longer manages any coding tool. Add one with ${styleText("bold", "barndog harnesses enable <harness>")}.`;
13
13
  }
14
+ const pickMessage = {
15
+ enable: "Which coding tools should BarnDog start managing?",
16
+ disable: "Which coding tools should BarnDog stop managing?",
17
+ };
18
+ const nothingTo = {
19
+ enable: "BarnDog already manages every coding tool it supports.",
20
+ disable: "BarnDog doesn't manage any coding tool.",
21
+ };
22
+ const nothingToHint = {
23
+ enable: "barndog harnesses list",
24
+ disable: "barndog harnesses enable <harness>",
25
+ };
14
26
  function harnessTable(rows) {
15
27
  return table(rows.map((row) => [
16
28
  bold(row.id),
@@ -44,14 +56,32 @@ export function registerHarnesses(program, context) {
44
56
  }
45
57
  context.write(managedLine(result.harnesses));
46
58
  };
59
+ // With no tools named, a terminal picks from the ones the change applies to.
60
+ const pickTargets = async (change) => {
61
+ const usage = `barndog harnesses ${change} <harness>`;
62
+ if (!context.mode.interactive) {
63
+ throw new CliError(`Name the coding tools to ${change}.`, usage);
64
+ }
65
+ const offered = (await context.listHarnesses()).filter((row) => row.enabled === (change === "disable"));
66
+ if (offered.length === 0) {
67
+ throw new CliError(nothingTo[change], nothingToHint[change]);
68
+ }
69
+ return chooseHarnesses(offered.map((row) => ({
70
+ value: row.id,
71
+ name: row.name,
72
+ evidence: row.evidence,
73
+ checked: false,
74
+ })), { message: pickMessage[change], required: true });
75
+ };
47
76
  for (const change of ["enable", "disable"]) {
48
77
  group
49
78
  .command(change)
50
79
  .description(change === "enable"
51
80
  ? "Start installing your selection into these coding tools"
52
81
  : "Remove everything BarnDog installed in these coding tools and stop installing there")
53
- .addArgument(new Argument("<harnesses...>", "Coding tools").choices(harnesses))
54
- .action(async (targets) => {
82
+ .addArgument(new Argument("[harnesses...]", "Coding tools").choices(harnesses))
83
+ .action(async (named) => {
84
+ const targets = named.length ? named : await pickTargets(change);
55
85
  report(await context.changeHarnesses(change, targets));
56
86
  });
57
87
  }
@@ -1,78 +1,167 @@
1
+ import { barndogPaths } from "../config/paths.js";
1
2
  import { CliError } from "../errors.js";
3
+ import { readsFrom } from "../features/secrets/index.js";
2
4
  import { bold, dim, json, ok, table } from "../ui/format.js";
3
5
  import { displayPath, renderSyncOutput } from "../ui/output.js";
4
- import { askSecret, readStdin } from "../ui/secret-input.js";
6
+ import { pickOne } from "../ui/pick.js";
7
+ import { askSecret, askUseUnassigned, readStdin } from "../ui/secret-input.js";
8
+ import { requireArguments } from "./arguments.js";
9
+ const SET_USAGE = "barndog mcp env set <server> <variable>";
10
+ const UNSET_USAGE = "barndog mcp env unset <server> <variable>";
11
+ /** How a kept value reads in a list; never the value itself. */
12
+ const describe = (row) => row.from ? `reads $${row.from}` : "kept";
5
13
  /**
6
- * `barndog mcp env`: MCP variable values BarnDog keeps on this machine. Every
7
- * command says where a value is kept and where it was written; none prints one.
14
+ * `barndog mcp env`: MCP variable values BarnDog keeps on this machine, each
15
+ * for one MCP server. Every command says where a value is kept and where it
16
+ * was written; none prints one.
8
17
  */
9
18
  export function registerMcpEnv(mcp, context) {
10
19
  const env = mcp
11
20
  .command("env")
12
21
  .description("Keep MCP variable values on this machine, never uploaded, and write them into your coding tools");
13
22
  const where = (file) => displayPath(file, context.runtime);
23
+ const report = (message, result, data) => {
24
+ if (context.mode.json) {
25
+ return context.write(json({ ...data, file: result.file }));
26
+ }
27
+ context.write(`${ok("✔")} ${message}`);
28
+ for (const line of renderSyncOutput(result.events)) {
29
+ context.write(line);
30
+ }
31
+ };
14
32
  env
15
- .command("set <variable>")
16
- .description("Keep a value for a variable MCP servers refer to")
33
+ .command("set [server] [variable]")
34
+ .description("Keep a value for a variable one MCP server refers to")
35
+ .option("--from <variable>", "Read another environment variable instead")
17
36
  .option("--stdin", "Read the value from standard input")
18
37
  .addHelpText("after", `
19
38
  The value is saved in ~/.barndog/secrets.json, which only you can read, and never leaves this machine.
20
- Sync then writes it into the settings of each coding tool whose MCP servers use the variable, as the
21
- tools store values they're given; shared definitions keep only the variable's name.`)
22
- .action(async (variable, options) => {
23
- const value = await readValue(variable, options.stdin);
24
- const result = await context.keepMcpValue(variable, value);
25
- if (context.mode.json) {
26
- return context.write(json({ variable, file: result.file }));
39
+ Sync then writes it into that server's entry in each coding tool's settings, as the tools store values
40
+ they're given; shared definitions keep only the variable's name. With --from, the server reads another
41
+ variable from your environment instead, such as GITHUB_TOKEN for GITHUB_PERSONAL_ACCESS_TOKEN.`)
42
+ .action(async (server, variable, options) => {
43
+ if (options.from && options.stdin) {
44
+ throw new CliError("Pass either --from or --stdin, not both.", SET_USAGE);
27
45
  }
28
- context.write(`${ok("✔")} Saved ${bold(variable)} in ${where(result.file)}, readable only by you. It stays on this machine and is never uploaded.`);
29
- for (const line of renderSyncOutput(result.events)) {
30
- context.write(line);
46
+ const target = await chooseTarget(server, variable);
47
+ const kept = await valueFor(target, options);
48
+ const file = where(barndogPaths(context.runtime.home).secrets);
49
+ if (kept === "unassigned") {
50
+ return report(`${bold(target.server)} now uses the value BarnDog kept for ${bold(target.variable)}, in ${file}.`, await context.assignKeptValue(target), target);
51
+ }
52
+ const result = await context.keepMcpValue(target, kept);
53
+ const from = readsFrom(kept);
54
+ if (from) {
55
+ return report(`${bold(target.server)} reads ${bold(target.variable)} from ${bold(`$${from}`)}. Saved in ${file}.`, result, { ...target, from });
31
56
  }
57
+ report(`Saved ${bold(target.variable)} for ${bold(target.server)} in ${file}, readable only by you. It stays on this machine and is never uploaded.`, result, target);
32
58
  });
33
59
  env
34
- .command("unset <variable>")
35
- .description("Forget a kept value; the tools read the variable again")
36
- .action(async (variable) => {
37
- const result = await context.forgetMcpValue(variable);
38
- if (context.mode.json) {
39
- return context.write(json({ variable, file: result.file }));
40
- }
41
- context.write(`${ok("✔")} Removed ${bold(variable)} from ${where(result.file)}.`);
42
- for (const line of renderSyncOutput(result.events)) {
43
- context.write(line);
60
+ .command("unset [server] [variable]")
61
+ .description("Forget a kept value; the server reads the variable again")
62
+ .option("--unassigned", "Forget a value kept from before values belonged to servers; name only the variable")
63
+ .action(async (server, variable, options) => {
64
+ const kept = await context.listKeptValues();
65
+ const file = where(barndogPaths(context.runtime.home).secrets);
66
+ if (options.unassigned) {
67
+ const named = variable ?? server;
68
+ const name = named ??
69
+ (await pickRow(kept.filter((row) => !row.server), "Choose a value to forget", "barndog mcp env unset --unassigned <variable>")).variable;
70
+ return report(`Removed the unassigned value of ${bold(name)} from ${file}.`, await context.forgetUnassignedValue(name), { variable: name });
44
71
  }
72
+ const assigned = kept.filter((row) => row.server !== null);
73
+ const serverRow = server === undefined
74
+ ? await pickRow([
75
+ ...new Map(assigned.map((row) => [row.assetId, row])).values(),
76
+ ], "Choose an MCP server", UNSET_USAGE, (row) => row.server ?? "")
77
+ : undefined;
78
+ const target = serverRow?.server ?? server ?? "";
79
+ const ofServer = assigned.filter((row) => [row.server, row.assetId].includes(target));
80
+ const name = variable ??
81
+ (ofServer.length === 1 && ofServer[0]
82
+ ? ofServer[0].variable
83
+ : (await pickRow(ofServer, `Choose a value of ${target} to forget`, UNSET_USAGE)).variable);
84
+ report(`Removed ${bold(name)} for ${bold(target)} from ${file}.`, await context.forgetMcpValue({ server: target, variable: name }), { server: target, variable: name });
45
85
  });
46
86
  env
47
87
  .command("list")
48
- .description("List kept variables and where their values are written")
88
+ .description("List kept values, by MCP server, and where they're written")
49
89
  .action(async () => {
50
90
  const kept = await context.listKeptValues();
51
91
  if (context.mode.json) {
52
92
  return context.write(json(kept));
53
93
  }
54
94
  if (!kept.length) {
55
- return context.write(`${dim("BarnDog keeps no MCP values. Add one with")} ${bold("barndog mcp env set <variable>")}${dim(".")}`);
56
- }
57
- context.write(dim("Kept in ~/.barndog/secrets.json on this machine only. Values aren't shown."));
58
- for (const line of table(kept.map((item) => [
59
- bold(item.variable),
60
- item.writtenTo.length
61
- ? item.writtenTo
62
- .map((place) => `${where(place.file)} (${place.server})`)
63
- .join(", ")
95
+ return context.write(`${dim("BarnDog keeps no MCP values. Add one with")} ${bold(SET_USAGE)}${dim(".")}`);
96
+ }
97
+ context.write(dim(`Kept in ${where(barndogPaths(context.runtime.home).secrets)} on this machine only. Values aren't shown.`));
98
+ for (const line of table(kept.map((row) => [
99
+ row.server ? bold(row.server) : dim("not assigned"),
100
+ bold(row.variable),
101
+ describe(row),
102
+ row.writtenTo.length
103
+ ? row.writtenTo.map(where).join(", ")
64
104
  : dim("not written anywhere yet"),
65
- ]), { header: ["Variable", "Written into"] })) {
105
+ ]), { header: ["Server", "Variable", "Value", "Written into"] })) {
66
106
  context.write(line);
67
107
  }
68
108
  });
69
- async function readValue(variable, stdin) {
70
- if (stdin) {
71
- return readStdin();
109
+ async function pickRow(rows, message, usage, name = (row) => row.variable) {
110
+ requireArguments(context, usage);
111
+ return pickOne(message, rows.map((row) => ({ value: row, name: name(row) })), { empty: "BarnDog keeps no such MCP values." });
112
+ }
113
+ /** The server and variable named, or chosen from lists in a terminal. */
114
+ async function chooseTarget(server, variable) {
115
+ if (server && variable) {
116
+ return { server, variable };
117
+ }
118
+ requireArguments(context, SET_USAGE);
119
+ const servers = (await context.inventory({ checkVariables: true })).items.filter((item) => item.kind === "mcp");
120
+ const item = server
121
+ ? servers.find((candidate) => [candidate.installedName, candidate.name, candidate.id].includes(server))
122
+ : await pickOne("Choose an MCP server", servers.map((candidate) => ({
123
+ value: candidate,
124
+ name: candidate.installedName,
125
+ hint: `${candidate.origin} · ${candidate.state}`,
126
+ })), { empty: "No MCP servers on this machine." });
127
+ if (!item) {
128
+ throw new CliError(`There's no MCP server called ${server} on this machine.`, "barndog mcp list");
129
+ }
130
+ if (variable) {
131
+ return { server: item.installedName, variable };
132
+ }
133
+ const kept = (await context.listKeptValues()).filter((row) => row.assetId === item.id);
134
+ const chosen = await pickOne(`Choose a variable of ${item.installedName}`, (item.variables ?? []).map((name) => {
135
+ const row = kept.find((candidate) => candidate.variable === name);
136
+ return { value: name, name, hint: row ? describe(row) : undefined };
137
+ }), {
138
+ empty: `BarnDog couldn't find any variables ${item.installedName} uses. Name one: ${SET_USAGE}`,
139
+ });
140
+ return { server: item.installedName, variable: chosen };
141
+ }
142
+ /**
143
+ * The value to keep: another variable to read, standard input, the value a
144
+ * version 1 file kept with no server, or a masked prompt, in that order.
145
+ */
146
+ async function valueFor(target, options) {
147
+ if (options.from) {
148
+ return { from: options.from };
149
+ }
150
+ if (options.stdin) {
151
+ return { value: await readStdin() };
152
+ }
153
+ const unassigned = (await context.listKeptValues()).some((row) => !row.server && row.variable === target.variable);
154
+ if (unassigned) {
155
+ if (!context.mode.interactive) {
156
+ return "unassigned";
157
+ }
158
+ if (await askUseUnassigned(target.variable)) {
159
+ return "unassigned";
160
+ }
72
161
  }
73
162
  if (!context.mode.interactive) {
74
- throw new CliError("Pass the value on standard input, so it stays out of your shell history.", `barndog mcp env set ${variable} --stdin`);
163
+ throw new CliError("Pass the value on standard input, so it stays out of your shell history.", `barndog mcp env set ${target.server} ${target.variable} --stdin`);
75
164
  }
76
- return askSecret(variable);
165
+ return { value: await askSecret(target.variable) };
77
166
  }
78
167
  }
@@ -1,6 +1,7 @@
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
7
  import { bold, dim, hint, json, ok, originLabel, section, table, } from "../ui/format.js";
@@ -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();
@@ -0,0 +1,62 @@
1
+ import { Option } from "commander";
2
+ import { CliError } from "../errors.js";
3
+ import { json } from "../ui/format.js";
4
+ import { askUninstall, confirmUninstall, 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
+ keepSetup: flags.keepSetup || (flags.removeAll ? false : undefined),
20
+ dropAdopted: flags.dropAdopted,
21
+ removeWorkspace: flags.removeWorkspace,
22
+ force: flags.force,
23
+ };
24
+ let options;
25
+ if (context.mode.interactive) {
26
+ options = await askUninstall(survey, choices, context.runtime);
27
+ }
28
+ else if (choices.keepSetup === undefined) {
29
+ 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");
30
+ }
31
+ else {
32
+ options = uninstallOptions(survey, {
33
+ ...choices,
34
+ keepSetup: choices.keepSetup,
35
+ });
36
+ }
37
+ if (flags.dryRun) {
38
+ if (context.mode.json) {
39
+ return context.write(json({ survey, options }));
40
+ }
41
+ for (const line of renderUninstallPlan(survey, options, context.runtime)) {
42
+ context.write(line);
43
+ }
44
+ return;
45
+ }
46
+ if (context.mode.interactive) {
47
+ for (const line of renderUninstallPlan(survey, options, context.runtime)) {
48
+ context.write(line);
49
+ }
50
+ if (!(await confirmUninstall())) {
51
+ return context.write("Nothing was changed.");
52
+ }
53
+ }
54
+ const result = await context.uninstall(options);
55
+ if (context.mode.json) {
56
+ return context.write(json(result));
57
+ }
58
+ for (const line of renderUninstall(result, context.runtime)) {
59
+ context.write(line);
60
+ }
61
+ });
62
+ }
@@ -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"),
@@ -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
+ }
@@ -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, } 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,21 @@ 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
- });
75
- }
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 () => { };
84
- }
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);
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)),
89
79
  };
90
80
  }
91
81
  /** Takes over the chosen assets; on any failure, puts back what it changed. */
92
82
  export async function adoptNative(keys,
93
- /** Variables whose values BarnDog keeps on this machine (see `mcp env`). */
83
+ /** The MCP values BarnDog keeps on this machine (see `mcp env`). */
94
84
  keep, runtime) {
95
85
  const { home } = runtime;
96
86
  return locked(runtime, async () => {
@@ -141,18 +131,14 @@ keep, runtime) {
141
131
  }
142
132
  // Written before anything changes, so undo can always find what moved.
143
133
  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 () => { };
134
+ const values = { forget: async () => { } };
148
135
  try {
149
- forgetValues = await keepValues(sources.flatMap((source) => source.literals), keep, runtime);
150
- const events = await apply({ record, plan, sourceOf, workspace }, runtime);
136
+ const events = await apply({ record, plan, sourceOf, workspace, keep, values }, runtime);
151
137
  return {
152
138
  id,
153
139
  adopted: plan,
154
140
  backup: paths.folder,
155
- notes: adoptionNotes(plan, sourceOf, keep),
141
+ ...adoptionNotes(plan, sourceOf, keep),
156
142
  events,
157
143
  canShare: await hasSharedWorkspace(home),
158
144
  };
@@ -161,7 +147,7 @@ keep, runtime) {
161
147
  await restore(record, record.items, runtime).catch((undoError) => {
162
148
  throw new CliError(`Adopting failed (${friendlyMessage(error)}), and putting things back failed too: ${friendlyMessage(undoError)}`, `barndog adopt undo ${id}`, { cause: error });
163
149
  });
164
- await forgetValues();
150
+ await values.forget();
165
151
  throw error;
166
152
  }
167
153
  });
@@ -187,6 +173,21 @@ async function apply(input, runtime) {
187
173
  }
188
174
  item.assetId = asset.id;
189
175
  }
176
+ // Kept by asset ID, which exists only now; saved before the sync writes them.
177
+ // One source per name, and every item of it shares one copy and asset ID.
178
+ const servers = new Map(plan.flatMap((asset, index) => asset.kind === "mcp"
179
+ ? [
180
+ [
181
+ asset.source.key,
182
+ {
183
+ id: defined(record.items[index], "Each planned asset has an item").assetId,
184
+ name: asset.name,
185
+ literals: sourceOf(asset).literals,
186
+ },
187
+ ],
188
+ ]
189
+ : []));
190
+ input.values.forget = await keepLiteralValues([...servers.values()], input.keep, runtime);
190
191
  // A settings file is saved as the user left it, before BarnDog's first change.
191
192
  for (const item of record.items) {
192
193
  const { original } = item;
@@ -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));