barndog 0.2.0 → 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.
- package/README.md +45 -24
- package/dist/cli.js +27 -1
- package/dist/commands/add.js +1 -0
- package/dist/commands/adopt.js +91 -0
- package/dist/commands/asset-install.js +1 -0
- package/dist/commands/asset-list.js +12 -3
- package/dist/commands/availability.js +25 -8
- package/dist/commands/capabilities.js +8 -2
- package/dist/commands/collaboration.js +22 -2
- package/dist/commands/harnesses.js +104 -0
- package/dist/commands/mcp-env.js +167 -0
- package/dist/commands/mcp.js +4 -2
- package/dist/commands/sets.js +13 -2
- package/dist/commands/status.js +2 -1
- package/dist/commands/sync.js +2 -1
- package/dist/commands/uninstall.js +62 -0
- package/dist/commands/workspace.js +43 -5
- package/dist/config/paths.js +21 -0
- package/dist/config/settings.js +5 -3
- package/dist/config/state.js +18 -6
- package/dist/entry/update-check.js +15 -0
- package/dist/features/adoption/adopt.js +235 -0
- package/dist/features/adoption/copies.js +29 -0
- package/dist/features/adoption/originals.js +116 -0
- package/dist/features/adoption/record.js +120 -0
- package/dist/features/adoption/restore.js +28 -0
- package/dist/features/adoption/scan.js +482 -0
- package/dist/features/adoption/undo.js +42 -0
- package/dist/features/asset-kinds/index.js +9 -0
- package/dist/features/auth/credentials.js +7 -14
- package/dist/features/auth/session.js +26 -5
- package/dist/features/auth/transport.js +3 -2
- package/dist/features/collaboration/workspace-git.js +13 -7
- package/dist/features/collaboration/workspace-github.js +2 -1
- package/dist/features/collaboration/workspace-store.js +25 -4
- package/dist/features/collaboration/workspace.js +22 -2
- package/dist/features/doctor/index.js +46 -7
- package/dist/features/environment/events.js +8 -1
- package/dist/features/environment/harnesses.js +36 -0
- package/dist/features/environment/kept-values.js +68 -0
- package/dist/features/environment/moves.js +187 -0
- package/dist/features/environment/names.js +10 -6
- package/dist/features/environment/operations.js +7 -7
- package/dist/features/environment/stage.js +25 -1
- package/dist/features/environment/sync.js +17 -6
- package/dist/features/environment/writes.js +55 -8
- package/dist/features/hooks/compatibility.js +11 -5
- package/dist/features/hooks/divergence.js +30 -9
- package/dist/features/hooks/test.js +25 -25
- package/dist/features/imports/discover.js +1 -1
- package/dist/features/imports/local.js +15 -2
- package/dist/features/imports/remote.js +2 -1
- package/dist/features/inventory/index.js +57 -3
- package/dist/features/inventory/show.js +74 -0
- package/dist/features/mcps/import.js +95 -21
- package/dist/features/mcps/index.js +24 -9
- package/dist/features/mcps/values.js +121 -0
- package/dist/features/migration/migrate.js +15 -0
- package/dist/features/migration/move.js +105 -25
- package/dist/features/migration/promote.js +2 -0
- package/dist/features/native/adapters.js +20 -7
- package/dist/features/native/configuration.js +8 -4
- package/dist/features/native/hook-shell.js +11 -0
- package/dist/features/native/secret-values.js +74 -0
- package/dist/features/secrets/index.js +142 -0
- package/dist/features/uninstall/index.js +126 -0
- package/dist/features/uninstall/leave.js +152 -0
- package/dist/features/uninstall/survey.js +103 -0
- package/dist/features/update-check/index.js +108 -0
- package/dist/features/workspace/format.js +19 -10
- package/dist/features/workspace/git.js +11 -4
- package/dist/features/workspace/overlay.js +23 -36
- package/dist/features/workspace/packages.js +16 -3
- package/dist/features/workspace/publish.js +1 -1
- package/dist/features/workspace/repo-source.js +4 -3
- package/dist/features/workspace/setup.js +12 -3
- package/dist/features/workspace/snapshot.js +7 -1
- package/dist/harnesses/claude.js +2 -2
- package/dist/harnesses/codex.js +54 -20
- package/dist/harnesses/cursor.js +2 -2
- package/dist/harnesses/formats.js +12 -5
- package/dist/harnesses/opencode.js +3 -6
- package/dist/harnesses/read-renamed-variables.js +141 -0
- package/dist/harnesses/renamed-variables.js +99 -0
- package/dist/platform.js +51 -12
- package/dist/program.js +68 -8
- package/dist/shared/files.js +35 -0
- package/dist/shared/lock.js +87 -23
- package/dist/shared/patterns.js +8 -0
- package/dist/shared/shell.js +0 -2
- package/dist/ui/add-hook.js +8 -2
- package/dist/ui/add-mcp.js +82 -13
- package/dist/ui/add-skills.js +7 -5
- package/dist/ui/adopt.js +202 -0
- package/dist/ui/assets.js +5 -3
- package/dist/ui/auth.js +2 -1
- package/dist/ui/clash.js +2 -3
- package/dist/ui/connection.js +9 -2
- package/dist/ui/harness-picker.js +23 -0
- package/dist/ui/mcp.js +89 -23
- package/dist/ui/move.js +49 -2
- package/dist/ui/onboarding.js +40 -27
- package/dist/ui/output.js +35 -8
- package/dist/ui/package-details.js +34 -0
- package/dist/ui/scope-install.js +4 -1
- package/dist/ui/secret-input.js +28 -0
- package/dist/ui/selection.js +3 -1
- package/dist/ui/uninstall.js +174 -0
- package/dist/ui/update.js +10 -0
- package/dist/version.js +2 -2
- package/package.json +1 -1
- package/dist/entry/mcp-launch.js +0 -71
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { barndogPaths } from "../config/paths.js";
|
|
2
|
+
import { CliError } from "../errors.js";
|
|
3
|
+
import { readsFrom } from "../features/secrets/index.js";
|
|
4
|
+
import { bold, dim, json, ok, table } from "../ui/format.js";
|
|
5
|
+
import { displayPath, renderSyncOutput } from "../ui/output.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";
|
|
13
|
+
/**
|
|
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.
|
|
17
|
+
*/
|
|
18
|
+
export function registerMcpEnv(mcp, context) {
|
|
19
|
+
const env = mcp
|
|
20
|
+
.command("env")
|
|
21
|
+
.description("Keep MCP variable values on this machine, never uploaded, and write them into your coding tools");
|
|
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
|
+
};
|
|
32
|
+
env
|
|
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")
|
|
36
|
+
.option("--stdin", "Read the value from standard input")
|
|
37
|
+
.addHelpText("after", `
|
|
38
|
+
The value is saved in ~/.barndog/secrets.json, which only you can read, and never leaves this machine.
|
|
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);
|
|
45
|
+
}
|
|
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 });
|
|
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);
|
|
58
|
+
});
|
|
59
|
+
env
|
|
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 });
|
|
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 });
|
|
85
|
+
});
|
|
86
|
+
env
|
|
87
|
+
.command("list")
|
|
88
|
+
.description("List kept values, by MCP server, and where they're written")
|
|
89
|
+
.action(async () => {
|
|
90
|
+
const kept = await context.listKeptValues();
|
|
91
|
+
if (context.mode.json) {
|
|
92
|
+
return context.write(json(kept));
|
|
93
|
+
}
|
|
94
|
+
if (!kept.length) {
|
|
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(", ")
|
|
104
|
+
: dim("not written anywhere yet"),
|
|
105
|
+
]), { header: ["Server", "Variable", "Value", "Written into"] })) {
|
|
106
|
+
context.write(line);
|
|
107
|
+
}
|
|
108
|
+
});
|
|
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
|
+
}
|
|
161
|
+
}
|
|
162
|
+
if (!context.mode.interactive) {
|
|
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`);
|
|
164
|
+
}
|
|
165
|
+
return { value: await askSecret(target.variable) };
|
|
166
|
+
}
|
|
167
|
+
}
|
package/dist/commands/mcp.js
CHANGED
|
@@ -3,6 +3,7 @@ import { Option } from "commander";
|
|
|
3
3
|
import { harnesses } from "../harnesses/registry.js";
|
|
4
4
|
import { defined } from "../shared/lookup.js";
|
|
5
5
|
import { commandHelpers } from "./helpers.js";
|
|
6
|
+
import { registerMcpEnv } from "./mcp-env.js";
|
|
6
7
|
/** `barndog mcp` commands that publish, inspect and authenticate MCP configurations. */
|
|
7
8
|
export function registerMcp(program, context) {
|
|
8
9
|
const { write, print, printMcp, locate } = commandHelpers(context);
|
|
@@ -29,11 +30,11 @@ export function registerMcp(program, context) {
|
|
|
29
30
|
});
|
|
30
31
|
}
|
|
31
32
|
mcp
|
|
32
|
-
.command("show
|
|
33
|
+
.command("show [name]")
|
|
33
34
|
.option("--origin <origin>", ORIGIN_HELP)
|
|
34
35
|
.description("Inspect a connection definition")
|
|
35
36
|
.action(async (name, options) => {
|
|
36
|
-
const located = await locate("mcp", name, options,
|
|
37
|
+
const located = await locate("mcp", name, options, "barndog mcp show <name>");
|
|
37
38
|
const result = await context.showMcp(located.name, located.origin);
|
|
38
39
|
if (context.mode.json) {
|
|
39
40
|
return context.write(json(result));
|
|
@@ -59,4 +60,5 @@ export function registerMcp(program, context) {
|
|
|
59
60
|
const located = await locate("mcp", name, options, `barndog mcp auth ${name} --harness ${options.harness}`);
|
|
60
61
|
print(await context.authenticateMcp(located.name, located.origin, options.harness));
|
|
61
62
|
});
|
|
63
|
+
registerMcpEnv(mcp, context);
|
|
62
64
|
}
|
package/dist/commands/sets.js
CHANGED
|
@@ -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
|
-
|
|
84
|
-
|
|
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();
|
package/dist/commands/status.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { harnessNames, inventoryHints, renderInventory } from "../ui/assets.js";
|
|
2
2
|
import { renderCollaboration } from "../ui/collaboration.js";
|
|
3
|
-
import { dim, fields, heading, hint, json, ok, plural } from "../ui/format.js";
|
|
3
|
+
import { dim, fields, heading, hint, json, ok, plural, warn, } from "../ui/format.js";
|
|
4
4
|
import { assetKindList, assetKinds } from "../features/asset-kinds/index.js";
|
|
5
5
|
function knowledgeState(enabled) {
|
|
6
6
|
return enabled ? ok("listed at session start") : dim("off");
|
|
@@ -41,6 +41,7 @@ export function registerStatus(program, context) {
|
|
|
41
41
|
if (inventory.offline) {
|
|
42
42
|
context.write(dim(`\nShowing local state only: ${inventory.offline}`));
|
|
43
43
|
}
|
|
44
|
+
inventory.moving.forEach((move) => context.write(`\n${warn("!")} ${move.name} is moving to ${move.to}. Your local copy stays in use until that merges.`));
|
|
44
45
|
for (const kind of assetKindList) {
|
|
45
46
|
const items = inventory.items.filter((item) => item.kind === kind);
|
|
46
47
|
context.write("");
|
package/dist/commands/sync.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Option } from "commander";
|
|
1
2
|
import { resolve } from "node:path";
|
|
2
3
|
import { renderSyncOutput } from "../ui/output.js";
|
|
3
4
|
import { json } from "../ui/format.js";
|
|
@@ -9,7 +10,7 @@ export function registerSync(program, context) {
|
|
|
9
10
|
.option("--dry-run", "Show what would change without changing anything")
|
|
10
11
|
.option("-v, --verbose", "Also list what is already up to date, including BarnDog's own entries")
|
|
11
12
|
.option("--config <path>", "Use an explicit configuration file once")
|
|
12
|
-
.
|
|
13
|
+
.addOption(new Option("--auto", "Quiet background sync used at session start").conflicts(["dryRun", "verbose", "config"]))
|
|
13
14
|
.action(async (options) => {
|
|
14
15
|
// Runs detached at session start: nobody is watching, so it never reports.
|
|
15
16
|
if (options.auto) {
|
|
@@ -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
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { bold, dim, heading, json, ok, plural, table, warn, } from "../ui/format.js";
|
|
2
|
-
import { renderMove } from "../ui/move.js";
|
|
2
|
+
import { chooseKeepLocal, pickLocalAssets, renderMove } from "../ui/move.js";
|
|
3
|
+
import { CliError } from "../errors.js";
|
|
3
4
|
const migrationActionStyles = {
|
|
4
5
|
publish: ok,
|
|
5
6
|
exists: dim,
|
|
@@ -26,7 +27,7 @@ export function registerWorkspace(program, context) {
|
|
|
26
27
|
.description("See and share the assets kept in this machine's folder");
|
|
27
28
|
local
|
|
28
29
|
.command("list")
|
|
29
|
-
.description("List
|
|
30
|
+
.description("List the assets kept in this machine's folder")
|
|
30
31
|
.action(async () => {
|
|
31
32
|
const result = await context.listLocalAssets();
|
|
32
33
|
if (context.mode.json) {
|
|
@@ -41,20 +42,38 @@ export function registerWorkspace(program, context) {
|
|
|
41
42
|
dim(asset.kind),
|
|
42
43
|
asset.state === "invalid" ? warn(asset.state) : asset.state,
|
|
43
44
|
dim(asset.path),
|
|
44
|
-
|
|
45
|
+
asset.movingTo ? dim(`to ${asset.movingTo}`) : "",
|
|
46
|
+
]), { header: ["Name", "Kind", "State", "Path", ""] })) {
|
|
45
47
|
context.write(line);
|
|
46
48
|
}
|
|
47
49
|
});
|
|
48
50
|
local
|
|
49
51
|
.command("move [names...]")
|
|
50
|
-
.description("
|
|
52
|
+
.description("Move local assets into your Git or Cloud workspace")
|
|
53
|
+
.option("--all", "Move every local asset that isn't already moving")
|
|
54
|
+
.option("--keep-local", "Share a copy and keep the local assets as separate ones")
|
|
55
|
+
.option("--no-keep-local", "Make the shared copy the only one; the local copy is removed once it exists")
|
|
51
56
|
.option("--to <origin>", "Destination, such as me, org or team/web. Defaults to me in cloud, org in Git")
|
|
52
57
|
.option("--as <name>", "New name, for moving one asset whose name is taken")
|
|
53
58
|
.option("--repo <url>", "Send to this Git repo; this machine stays as it is")
|
|
54
59
|
.option("--server <url>", "Send to this Cloud Workspace; this machine stays as it is")
|
|
60
|
+
.addHelpText("after", `
|
|
61
|
+
Without names, a terminal lists your local assets to pick from; elsewhere, name them or pass --all.
|
|
62
|
+
|
|
63
|
+
It then asks whether to move them or keep separate local copies; --keep-local or --no-keep-local answers without asking.
|
|
64
|
+
Move: the shared copy becomes the only one. Once it exists, the next sync installs it and removes the local copy.
|
|
65
|
+
A move into a Git repo with assets in it waits for its pull request: until it merges, local list shows
|
|
66
|
+
the asset as moving and the local copy stays in use. A local copy edited before then stays as a separate asset.
|
|
67
|
+
Keep: a copy is shared and the local asset stays. When both have the same name, sync asks which to rename.
|
|
68
|
+
With --repo or --server this machine stays as it is, so the assets are always copied.`)
|
|
55
69
|
.action(async (names, options) => {
|
|
70
|
+
const chosen = await chooseNames(names, options.all);
|
|
71
|
+
// --repo and --server send a copy and leave this machine as it is.
|
|
72
|
+
const oneOff = Boolean(options.repo || options.server);
|
|
73
|
+
const keepLocal = options.keepLocal ?? (oneOff || (await askKeepLocal(chosen?.length)));
|
|
56
74
|
const result = await context.moveLocalAssets({
|
|
57
|
-
names,
|
|
75
|
+
names: chosen,
|
|
76
|
+
keepLocal,
|
|
58
77
|
to: options.to,
|
|
59
78
|
as: options.as,
|
|
60
79
|
repo: options.repo,
|
|
@@ -67,6 +86,25 @@ export function registerWorkspace(program, context) {
|
|
|
67
86
|
context.write(line);
|
|
68
87
|
}
|
|
69
88
|
});
|
|
89
|
+
/** The names to move; undefined means every local asset not already moving. */
|
|
90
|
+
async function chooseNames(names, all) {
|
|
91
|
+
if (all && names.length) {
|
|
92
|
+
throw new CliError("Name the assets to move or pass --all, not both.", "barndog local move --help");
|
|
93
|
+
}
|
|
94
|
+
if (all || names.length) {
|
|
95
|
+
return all ? undefined : names;
|
|
96
|
+
}
|
|
97
|
+
if (!context.mode.interactive) {
|
|
98
|
+
throw new CliError("Name the local assets to move, or pass --all.", "barndog local move <names...> --keep-local, or barndog local move --all --no-keep-local");
|
|
99
|
+
}
|
|
100
|
+
return pickLocalAssets(await context.listLocalAssets());
|
|
101
|
+
}
|
|
102
|
+
async function askKeepLocal(count) {
|
|
103
|
+
if (!context.mode.interactive) {
|
|
104
|
+
throw new CliError("Say whether to keep separate local copies: --keep-local keeps them, --no-keep-local makes the shared copy the only one.", "barndog local move --help");
|
|
105
|
+
}
|
|
106
|
+
return chooseKeepLocal(count ?? 2);
|
|
107
|
+
}
|
|
70
108
|
program
|
|
71
109
|
.command("migrate")
|
|
72
110
|
.description("Move a Git repo or local workspace to a BarnDog Cloud Workspace")
|
package/dist/config/paths.js
CHANGED
|
@@ -21,11 +21,32 @@ export function barndogPaths(home) {
|
|
|
21
21
|
syncLock: join(root, "sync.lock"),
|
|
22
22
|
/** Backups of config.yaml and native files taken before BarnDog changes them. */
|
|
23
23
|
migrations: join(root, "migrations"),
|
|
24
|
+
/** One folder per `barndog adopt`: its record and the originals it moved aside. */
|
|
25
|
+
adoptions: join(root, "adoptions"),
|
|
26
|
+
adoption: (id) => {
|
|
27
|
+
const folder = join(root, "adoptions", id);
|
|
28
|
+
return {
|
|
29
|
+
folder,
|
|
30
|
+
record: join(folder, "record.json"),
|
|
31
|
+
/** Each tool settings file as it was before the adoption changed it. */
|
|
32
|
+
settings: join(folder, "settings"),
|
|
33
|
+
/** Skill folders taken out of the tools: `<harness>/<name>`. */
|
|
34
|
+
skills: join(folder, "skills"),
|
|
35
|
+
};
|
|
36
|
+
},
|
|
24
37
|
/** The last Cloud catalog revision a background sync delivered. */
|
|
25
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"),
|
|
26
41
|
/** Saved sessions, per server. */
|
|
27
42
|
credentials: join(root, "credentials.json"),
|
|
28
43
|
credentialsLock: join(root, "credentials.lock"),
|
|
44
|
+
/**
|
|
45
|
+
* MCP variable values kept on this machine only, by variable name. Never
|
|
46
|
+
* uploaded; sync writes them into the coding tools' settings.
|
|
47
|
+
*/
|
|
48
|
+
secrets: join(root, "secrets.json"),
|
|
49
|
+
secretsLock: join(root, "secrets.lock"),
|
|
29
50
|
/** Where `claude mcp login` and `codex mcp login` run. */
|
|
30
51
|
nativeAuth: join(root, "native-auth"),
|
|
31
52
|
/** The default local workspace folder. */
|
package/dist/config/settings.js
CHANGED
|
@@ -4,7 +4,7 @@ import { parse, stringify } from "yaml";
|
|
|
4
4
|
import { z } from "zod";
|
|
5
5
|
import { selectionStateSchema } from "./selection.js";
|
|
6
6
|
import { isHarness } from "../harnesses/registry.js";
|
|
7
|
-
import {
|
|
7
|
+
import { MCP_NAME, UUID_V4 } from "../shared/patterns.js";
|
|
8
8
|
import { readIfExists, writeAtomic } from "../shared/files.js";
|
|
9
9
|
import { CliError } from "../errors.js";
|
|
10
10
|
import { barndogPaths } from "./paths.js";
|
|
@@ -32,7 +32,9 @@ const localWorkspaceSchema = z.looseObject({
|
|
|
32
32
|
path: z.string().refine(isAbsolute),
|
|
33
33
|
workspaceId: uuid,
|
|
34
34
|
});
|
|
35
|
-
|
|
35
|
+
// An MCP server's name may hold `_` and capitals; every other kind is checked
|
|
36
|
+
// against its own rule when renamed.
|
|
37
|
+
const localNamesSchema = z.record(uuid, z.string().regex(MCP_NAME).max(MAX_ASSET_NAME_LENGTH));
|
|
36
38
|
/** Every part of the file; each optional key is named only here. */
|
|
37
39
|
// Loose objects keep keys this version doesn't know, as the file had them.
|
|
38
40
|
const settingsSchema = z.looseObject({
|
|
@@ -98,7 +100,7 @@ export async function readSettings(home, path = barndogPaths(home).settings) {
|
|
|
98
100
|
}
|
|
99
101
|
catch (error) {
|
|
100
102
|
// Someone edited the file by hand; saving runs the same checks as a guard.
|
|
101
|
-
throw new CliError(`${path} isn't valid: ${error instanceof Error ? error.message : String(error)}. Fix it, or move it aside and set up again.`, `
|
|
103
|
+
throw new CliError(`${path} isn't valid: ${error instanceof Error ? error.message : String(error)}. Fix it, or move it aside and set up again.`, `Fix the file, or move it aside (keep a copy) and run barndog init`, { cause: error });
|
|
102
104
|
}
|
|
103
105
|
}
|
|
104
106
|
/** The file's text, after checking the settings are valid. */
|
package/dist/config/state.js
CHANGED
|
@@ -5,6 +5,7 @@ import { packageKindList } from "./selection.js";
|
|
|
5
5
|
import { NAME, UUID_V4 } from "../shared/patterns.js";
|
|
6
6
|
import { barndogPaths } from "./paths.js";
|
|
7
7
|
import { readIfExists } from "../shared/files.js";
|
|
8
|
+
import { CliError } from "../shared/cli-error.js";
|
|
8
9
|
const linkSchema = z.object({
|
|
9
10
|
id: z.string().regex(UUID_V4),
|
|
10
11
|
harness: z.enum(harnesses),
|
|
@@ -36,23 +37,34 @@ const stateSchema = z.looseObject({
|
|
|
36
37
|
* missing state yields no links.
|
|
37
38
|
*/
|
|
38
39
|
export async function readState(home) {
|
|
39
|
-
const
|
|
40
|
+
const path = barndogPaths(home).state;
|
|
41
|
+
const text = await readIfExists(path);
|
|
40
42
|
if (text === null) {
|
|
41
43
|
return { version: 1, links: [], native: [], installed: [] };
|
|
42
44
|
}
|
|
43
|
-
|
|
45
|
+
// Without this record BarnDog can't tell its own entries from yours, so
|
|
46
|
+
// nothing is changed until it is repaired.
|
|
47
|
+
const damaged = (cause) => new CliError(`${path} is damaged, so BarnDog won't change your tools' files.`, "Undo any edit to that file. If it can't be repaired, move it aside, remove what BarnDog installed in your tools, then run barndog sync", { cause });
|
|
48
|
+
let value;
|
|
49
|
+
try {
|
|
50
|
+
value = JSON.parse(text);
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
throw damaged(error);
|
|
54
|
+
}
|
|
55
|
+
const parsed = stateSchema.safeParse(value);
|
|
44
56
|
if (!parsed.success) {
|
|
45
|
-
throw
|
|
57
|
+
throw damaged(parsed.error);
|
|
46
58
|
}
|
|
47
59
|
const state = parsed.data;
|
|
48
60
|
for (const entry of state.native) {
|
|
49
61
|
if (entry.file !== nativeFile(entry.harness, entry.kind, home)) {
|
|
50
|
-
throw
|
|
62
|
+
throw damaged();
|
|
51
63
|
}
|
|
52
64
|
}
|
|
53
65
|
for (const entry of state.installed) {
|
|
54
66
|
if (dirname(entry.path) !== barndogPaths(home).installed(entry.kind)) {
|
|
55
|
-
throw
|
|
67
|
+
throw damaged();
|
|
56
68
|
}
|
|
57
69
|
}
|
|
58
70
|
const targets = new Set();
|
|
@@ -61,7 +73,7 @@ export async function readState(home) {
|
|
|
61
73
|
if (dirname(link.target) !== skillDirectory(link.harness, home) ||
|
|
62
74
|
!NAME.test(basename(link.target)) ||
|
|
63
75
|
targets.has(link.target)) {
|
|
64
|
-
throw
|
|
76
|
+
throw damaged();
|
|
65
77
|
}
|
|
66
78
|
targets.add(link.target);
|
|
67
79
|
checked.push(link);
|
|
@@ -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
|
+
}
|