barndog 0.2.0 → 0.2.1
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 +29 -27
- 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 +7 -2
- 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 +74 -0
- package/dist/commands/mcp-env.js +78 -0
- package/dist/commands/mcp.js +4 -2
- package/dist/commands/status.js +2 -1
- package/dist/commands/sync.js +2 -1
- package/dist/commands/workspace.js +43 -5
- package/dist/config/paths.js +19 -0
- package/dist/config/settings.js +5 -3
- package/dist/config/state.js +18 -6
- package/dist/features/adoption/adopt.js +234 -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 +4 -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 +23 -3
- package/dist/features/collaboration/workspace.js +22 -2
- package/dist/features/doctor/index.js +24 -2
- package/dist/features/environment/harnesses.js +36 -0
- package/dist/features/environment/moves.js +171 -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 +13 -2
- package/dist/features/inventory/show.js +74 -0
- package/dist/features/mcps/import.js +74 -21
- package/dist/features/mcps/index.js +12 -7
- package/dist/features/mcps/values.js +33 -0
- package/dist/features/migration/move.js +72 -17
- package/dist/features/migration/promote.js +2 -0
- package/dist/features/native/adapters.js +20 -6
- package/dist/features/native/configuration.js +8 -4
- package/dist/features/native/secret-values.js +74 -0
- package/dist/features/secrets/index.js +77 -0
- package/dist/features/workspace/format.js +13 -9
- 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 +19 -9
- package/dist/harnesses/cursor.js +2 -2
- package/dist/harnesses/formats.js +12 -5
- package/dist/harnesses/opencode.js +3 -6
- package/dist/platform.js +39 -11
- package/dist/program.js +51 -3
- 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 +69 -6
- package/dist/ui/add-skills.js +7 -5
- package/dist/ui/adopt.js +197 -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 +7 -2
- package/dist/ui/harness-picker.js +18 -0
- package/dist/ui/move.js +48 -2
- package/dist/ui/onboarding.js +40 -27
- package/dist/ui/output.js +3 -1
- package/dist/ui/package-details.js +34 -0
- package/dist/ui/scope-install.js +4 -1
- package/dist/ui/secret-input.js +19 -0
- package/dist/ui/selection.js +3 -1
- package/package.json +1 -1
package/dist/ui/adopt.js
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import checkbox, { Separator } from "@inquirer/checkbox";
|
|
2
|
+
import confirm from "@inquirer/confirm";
|
|
3
|
+
import { adoptNative, adoptionPlan, } from "../features/adoption/adopt.js";
|
|
4
|
+
import { scanNative, } from "../features/adoption/scan.js";
|
|
5
|
+
import { friendlyMessage } from "../errors.js";
|
|
6
|
+
import { harnesses, adapters } from "../harnesses/registry.js";
|
|
7
|
+
import { bold, dim, heading, hint, ok, plural, table, warn } from "./format.js";
|
|
8
|
+
import { displayPath } from "./output.js";
|
|
9
|
+
import { checkboxTheme, promptTheme } from "./theme.js";
|
|
10
|
+
const kindLabels = {
|
|
11
|
+
skill: "Skill",
|
|
12
|
+
mcp: "MCP",
|
|
13
|
+
hook: "Hook",
|
|
14
|
+
};
|
|
15
|
+
const kindWidth = Math.max(...Object.values(kindLabels).map((label) => label.length));
|
|
16
|
+
/** How the asset relates to other tools' assets of the same name, when it does. */
|
|
17
|
+
function sharing(asset) {
|
|
18
|
+
if (!asset.sameName.length) {
|
|
19
|
+
return "";
|
|
20
|
+
}
|
|
21
|
+
const tools = asset.sameName
|
|
22
|
+
.map((other) => adapters[other.harness].name)
|
|
23
|
+
.join(", ");
|
|
24
|
+
return asset.identical ? `same as ${tools}` : `differs from ${tools}`;
|
|
25
|
+
}
|
|
26
|
+
const byTool = (items) => harnesses.flatMap((harness) => {
|
|
27
|
+
const mine = items.filter((item) => item.harness === harness);
|
|
28
|
+
return mine.length ? [{ harness, items: mine }] : [];
|
|
29
|
+
});
|
|
30
|
+
/** What a scan found, one section per coding tool. */
|
|
31
|
+
export function renderScan(scan, runtime) {
|
|
32
|
+
if (!scan.assets.length && !scan.skipped.length) {
|
|
33
|
+
return [
|
|
34
|
+
dim("Your coding tools have no Skills, MCP servers or Hooks that BarnDog doesn't manage."),
|
|
35
|
+
];
|
|
36
|
+
}
|
|
37
|
+
const output = [];
|
|
38
|
+
for (const { harness, items } of byTool(scan.assets)) {
|
|
39
|
+
output.push(bold(adapters[harness].name));
|
|
40
|
+
output.push(...table(items.map((asset) => [
|
|
41
|
+
dim(kindLabels[asset.kind]),
|
|
42
|
+
bold(asset.name),
|
|
43
|
+
asset.identical ? dim(sharing(asset)) : warn(sharing(asset)),
|
|
44
|
+
dim(asset.key),
|
|
45
|
+
])));
|
|
46
|
+
output.push("");
|
|
47
|
+
}
|
|
48
|
+
if (scan.skipped.length) {
|
|
49
|
+
output.push(bold("Can't be adopted"));
|
|
50
|
+
for (const skipped of scan.skipped) {
|
|
51
|
+
output.push(` ${dim(`${adapters[skipped.harness].name} ${kindLabels[skipped.kind]}`)} ${bold(skipped.name)} ${dim(displayPath(skipped.location, runtime))}`, ` ${dim(skipped.reason)}`);
|
|
52
|
+
}
|
|
53
|
+
output.push("");
|
|
54
|
+
}
|
|
55
|
+
return output;
|
|
56
|
+
}
|
|
57
|
+
const chooseAdoption = (scan) => checkbox({
|
|
58
|
+
loop: false,
|
|
59
|
+
message: "Which assets should BarnDog adopt?",
|
|
60
|
+
choices: byTool(scan.assets).flatMap(({ harness, items }) => [
|
|
61
|
+
new Separator(bold(adapters[harness].name)),
|
|
62
|
+
...items.map((asset) => ({
|
|
63
|
+
value: asset.key,
|
|
64
|
+
checked: false,
|
|
65
|
+
short: asset.key,
|
|
66
|
+
name: `${kindLabels[asset.kind].padEnd(kindWidth)} ${asset.name}${sharing(asset) ? dim(` ${sharing(asset)}`) : ""}`,
|
|
67
|
+
description: asset.description,
|
|
68
|
+
})),
|
|
69
|
+
]),
|
|
70
|
+
theme: checkboxTheme,
|
|
71
|
+
});
|
|
72
|
+
/** What an adoption will take over, including other tools' copies BarnDog's one replaces. */
|
|
73
|
+
function renderPlan(plan) {
|
|
74
|
+
const output = [bold("BarnDog will adopt")];
|
|
75
|
+
output.push(...table(plan.map((asset) => [
|
|
76
|
+
adapters[asset.harness].name,
|
|
77
|
+
dim(kindLabels[asset.kind]),
|
|
78
|
+
bold(asset.name),
|
|
79
|
+
asset.source.key !== asset.key && !asset.identical
|
|
80
|
+
? warn(`replaced by ${adapters[asset.source.harness].name}'s`)
|
|
81
|
+
: "",
|
|
82
|
+
])));
|
|
83
|
+
output.push("", dim("Originals move into ~/.barndog/adoptions/ and BarnDog installs its copies in their place."), dim("Adopted Skills and MCP servers install in every coding tool BarnDog manages."));
|
|
84
|
+
return output;
|
|
85
|
+
}
|
|
86
|
+
const confirmAdoption = (plan) => confirm({
|
|
87
|
+
message: `Adopt ${plural(plan.length, "asset")}?`,
|
|
88
|
+
default: true,
|
|
89
|
+
theme: promptTheme,
|
|
90
|
+
});
|
|
91
|
+
export function renderAdoption(result, runtime) {
|
|
92
|
+
const output = [
|
|
93
|
+
`${ok("✔")} Adopted ${plural(result.adopted.length, "asset")} into your local folder.`,
|
|
94
|
+
dim(`Originals are saved in ${displayPath(result.backup, runtime)}`),
|
|
95
|
+
];
|
|
96
|
+
for (const note of result.notes) {
|
|
97
|
+
output.push(`${warn("!")} ${kindLabels[note.kind]} ${bold(note.name)}: ${note.text}`);
|
|
98
|
+
}
|
|
99
|
+
output.push("", result.canShare
|
|
100
|
+
? hint("barndog local move", "Tip") +
|
|
101
|
+
dim(" share them through your workspace")
|
|
102
|
+
: hint("barndog local list", "Tip") +
|
|
103
|
+
dim(" see everything in your local workspace"));
|
|
104
|
+
return output;
|
|
105
|
+
}
|
|
106
|
+
export function renderUndo(result, runtime) {
|
|
107
|
+
const output = [
|
|
108
|
+
`${ok("✔")} Put back ${plural(result.restored.length, "asset")}.`,
|
|
109
|
+
...result.restored.map((item) => ` ${adapters[item.harness].name} ${dim(kindLabels[item.kind])} ${bold(item.name)} ${dim(displayPath(item.location, runtime))}`),
|
|
110
|
+
];
|
|
111
|
+
if (result.remaining.length) {
|
|
112
|
+
output.push("", dim(`${plural(result.remaining.length, "asset")} of this adoption ${result.remaining.length === 1 ? "is" : "are"} still managed by BarnDog.`));
|
|
113
|
+
}
|
|
114
|
+
return output;
|
|
115
|
+
}
|
|
116
|
+
export function renderAdoptions(list) {
|
|
117
|
+
if (!list.length) {
|
|
118
|
+
return [dim("Nothing has been adopted on this machine.")];
|
|
119
|
+
}
|
|
120
|
+
return table(list.map((record) => [
|
|
121
|
+
record.id,
|
|
122
|
+
dim(record.createdAt.slice(0, "YYYY-MM-DD".length)),
|
|
123
|
+
record.status === "applied" ? ok(record.status) : warn(record.status),
|
|
124
|
+
record.items
|
|
125
|
+
.map((item) => (item.undone ? dim(item.key) : item.key))
|
|
126
|
+
.join(", "),
|
|
127
|
+
]), { header: ["ID", "Date", "Status", "Assets"] });
|
|
128
|
+
}
|
|
129
|
+
const chooseKeptValues = (values) => checkbox({
|
|
130
|
+
message: "Which values should BarnDog keep on this machine?",
|
|
131
|
+
choices: values.map((value) => ({
|
|
132
|
+
name: `${value.variable} ${dim(`${value.server}: ${value.key}`)}`,
|
|
133
|
+
short: value.variable,
|
|
134
|
+
value: value.variable,
|
|
135
|
+
checked: true,
|
|
136
|
+
})),
|
|
137
|
+
theme: checkboxTheme,
|
|
138
|
+
});
|
|
139
|
+
/** Shows what a scan found, asks which assets to adopt, and adopts them. */
|
|
140
|
+
export async function offerAdoption(scan, prompt) {
|
|
141
|
+
const { write } = prompt;
|
|
142
|
+
write(`\n${heading("adopt")}\n`);
|
|
143
|
+
write("These are set up in your coding tools without BarnDog:");
|
|
144
|
+
write("");
|
|
145
|
+
for (const line of renderScan(scan, prompt.runtime)) {
|
|
146
|
+
write(line);
|
|
147
|
+
}
|
|
148
|
+
const keys = await (prompt.choose ?? chooseAdoption)(scan);
|
|
149
|
+
if (!keys.length) {
|
|
150
|
+
write(`${dim("Nothing adopted. Run")} ${bold("barndog adopt")} ${dim("any time.")}`);
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
const plan = adoptionPlan(scan, keys);
|
|
154
|
+
write("");
|
|
155
|
+
for (const line of renderPlan(plan)) {
|
|
156
|
+
write(line);
|
|
157
|
+
}
|
|
158
|
+
write("");
|
|
159
|
+
if (!(await (prompt.confirm ?? confirmAdoption)(plan))) {
|
|
160
|
+
write(dim("Nothing adopted."));
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
// Same-named copies share one source, so each value is asked about once.
|
|
164
|
+
const values = plan
|
|
165
|
+
.filter((asset) => asset.key === asset.source.key)
|
|
166
|
+
.flatMap((asset) => asset.values.map((value) => ({ server: asset.name, ...value })));
|
|
167
|
+
let keep = [];
|
|
168
|
+
if (values.length) {
|
|
169
|
+
write("");
|
|
170
|
+
write(dim("These MCP values were written into the tools' settings. BarnDog can keep them in ~/.barndog/secrets.json, which only you can read and which is never uploaded, and write them into each tool it manages. Leave one unticked to set it yourself."));
|
|
171
|
+
keep = await (prompt.keepValues ?? chooseKeptValues)(values);
|
|
172
|
+
}
|
|
173
|
+
const result = await prompt.adoptNative(keys, keep);
|
|
174
|
+
for (const line of renderAdoption(result, prompt.runtime)) {
|
|
175
|
+
write(line);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* First-time setup offers to adopt what the tools already have. Setup is saved
|
|
180
|
+
* by then, so a failure here is reported rather than failing setup.
|
|
181
|
+
*/
|
|
182
|
+
export async function offerAdoptionAtSetup(runtime, prompt) {
|
|
183
|
+
try {
|
|
184
|
+
const scan = await scanNative(runtime);
|
|
185
|
+
if (scan.assets.length) {
|
|
186
|
+
await offerAdoption(scan, {
|
|
187
|
+
...prompt,
|
|
188
|
+
adoptNative: (keys, keep) => adoptNative(keys, keep, runtime),
|
|
189
|
+
runtime,
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
catch (error) {
|
|
194
|
+
prompt.write(`${warn("!")} Nothing was adopted: ${friendlyMessage(error)}`);
|
|
195
|
+
prompt.write(hint("barndog adopt", "Tip") + dim(" try again later"));
|
|
196
|
+
}
|
|
197
|
+
}
|
package/dist/ui/assets.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { shellWord } from "../platform.js";
|
|
1
2
|
import { adapters } from "../harnesses/registry.js";
|
|
2
3
|
import { assetPage } from "./asset-list.js";
|
|
3
4
|
import { displayPath } from "./output.js";
|
|
@@ -95,7 +96,7 @@ export function inventoryHints(items) {
|
|
|
95
96
|
* Returns a filtered catalog table and paging hints, marking selected IDs; does
|
|
96
97
|
* not write output.
|
|
97
98
|
*/
|
|
98
|
-
export function renderCatalog(rows, options,
|
|
99
|
+
export function renderCatalog(rows, options, next, installedIds) {
|
|
99
100
|
const page = assetPage(rows, options);
|
|
100
101
|
if (!page.total) {
|
|
101
102
|
return [dim("No matching assets.")];
|
|
@@ -124,8 +125,9 @@ export function renderCatalog(rows, options, command, installedIds) {
|
|
|
124
125
|
});
|
|
125
126
|
output.push("", dim(`Showing ${page.start + 1}–${page.start + page.rows.length} of ${page.total}${page.pages > 1 ? ` · page ${options.page}/${page.pages}` : ""}${installedIds.size ? " · ✔ selected on this machine" : ""}`));
|
|
126
127
|
if (options.page < page.pages) {
|
|
127
|
-
const
|
|
128
|
-
|
|
128
|
+
const word = (value) => shellWord(value, next.platform);
|
|
129
|
+
const filters = `${options.search ? ` ${word(options.search)}` : ""}${options.origin ? ` --origin ${word(options.origin)}` : ""}`;
|
|
130
|
+
output.push(hint(`${next.command}${filters} --page ${options.page + 1}`, "Next"));
|
|
129
131
|
}
|
|
130
132
|
return output;
|
|
131
133
|
}
|
package/dist/ui/auth.js
CHANGED
|
@@ -4,6 +4,7 @@ import { readCredentials } from "../features/auth/credentials.js";
|
|
|
4
4
|
import { LoginRequiredError } from "../features/auth/transport.js";
|
|
5
5
|
import { CliError } from "../errors.js";
|
|
6
6
|
import { promptServer } from "./connection.js";
|
|
7
|
+
import { interactiveTerminal } from "./pick.js";
|
|
7
8
|
import { bad, bold, dim, fields, heading, hint, humanize, json, ok, warn, } from "./format.js";
|
|
8
9
|
/** Opens `url` in the default browser; rejects when no browser could be started. */
|
|
9
10
|
export async function openBrowser(url) {
|
|
@@ -19,7 +20,7 @@ function describeIdentity(context) {
|
|
|
19
20
|
export async function runLogin(options, write) {
|
|
20
21
|
const server = options.server ??
|
|
21
22
|
(await configuredServer(options.runtime)) ??
|
|
22
|
-
(
|
|
23
|
+
((options.interactive ?? interactiveTerminal())
|
|
23
24
|
? await promptServer()
|
|
24
25
|
: undefined);
|
|
25
26
|
if (server && !options.force) {
|
package/dist/ui/clash.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import select from "@inquirer/select";
|
|
2
|
-
import { validAssetName } from "../shared/patterns.js";
|
|
3
2
|
import { originLabel } from "../features/server/origin.js";
|
|
4
3
|
import { bold, dim, fields, warn } from "./format.js";
|
|
5
4
|
import { promptTheme } from "./theme.js";
|
|
@@ -18,14 +17,14 @@ export async function promptClash(clash) {
|
|
|
18
17
|
console.log("");
|
|
19
18
|
const choices = [];
|
|
20
19
|
if (clash.incoming.renamable !== false &&
|
|
21
|
-
|
|
20
|
+
assetKinds[clash.kind].validName(clash.incomingRename)) {
|
|
22
21
|
choices.push({
|
|
23
22
|
name: `Rename the new one to ${clash.incomingRename}`,
|
|
24
23
|
value: "rename-incoming",
|
|
25
24
|
});
|
|
26
25
|
}
|
|
27
26
|
if (clash.installed.renamable !== false &&
|
|
28
|
-
|
|
27
|
+
assetKinds[clash.kind].validName(clash.installedRename)) {
|
|
29
28
|
choices.push({
|
|
30
29
|
name: `Rename the installed one to ${clash.installedRename}`,
|
|
31
30
|
value: "rename-installed",
|
package/dist/ui/connection.js
CHANGED
|
@@ -86,9 +86,14 @@ export function chooseLocalAssets(count) {
|
|
|
86
86
|
description: "They keep working next to the shared assets. Move them any time with barndog local move.",
|
|
87
87
|
},
|
|
88
88
|
{
|
|
89
|
-
name: "
|
|
89
|
+
name: "Share a copy, and keep them here too",
|
|
90
|
+
value: "copy",
|
|
91
|
+
description: "The local ones stay as separate assets. Anything whose name is already taken is left out and listed.",
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
name: "Move them to the new workspace",
|
|
90
95
|
value: "move",
|
|
91
|
-
description: "
|
|
96
|
+
description: "The shared copies become the only ones; the local ones are removed once they exist. Anything whose name is already taken stays local and is listed.",
|
|
92
97
|
},
|
|
93
98
|
{
|
|
94
99
|
name: "Stop using them",
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import checkbox from "@inquirer/checkbox";
|
|
2
|
+
import { checkboxTheme, selected } from "./theme.js";
|
|
3
|
+
import { dim } from "./format.js";
|
|
4
|
+
export const chooseHarnesses = (choices) => {
|
|
5
|
+
const width = Math.max(...choices.map((choice) => choice.name.length));
|
|
6
|
+
return checkbox({
|
|
7
|
+
loop: false,
|
|
8
|
+
message: "Which coding tools should BarnDog manage?",
|
|
9
|
+
choices: choices.map((choice) => ({
|
|
10
|
+
value: choice.value,
|
|
11
|
+
checked: choice.checked,
|
|
12
|
+
short: choice.name,
|
|
13
|
+
name: `${choice.name.padEnd(width)} ${choice.evidence ? selected("detected") : dim("not found")}`,
|
|
14
|
+
description: choice.evidence ?? undefined,
|
|
15
|
+
})),
|
|
16
|
+
theme: checkboxTheme,
|
|
17
|
+
});
|
|
18
|
+
};
|
package/dist/ui/move.js
CHANGED
|
@@ -1,4 +1,37 @@
|
|
|
1
|
+
import select from "@inquirer/select";
|
|
1
2
|
import { bold, dim, hint, ok, table, warn } from "./format.js";
|
|
3
|
+
import { pickMany } from "./pick.js";
|
|
4
|
+
import { promptTheme } from "./theme.js";
|
|
5
|
+
/** The local assets `local move` can take: valid, and not already moving. */
|
|
6
|
+
export function pickLocalAssets(local) {
|
|
7
|
+
return pickMany("Which local assets should move?", local.assets
|
|
8
|
+
.filter((asset) => asset.state === "active")
|
|
9
|
+
.map((asset) => ({
|
|
10
|
+
value: asset.name,
|
|
11
|
+
name: asset.name,
|
|
12
|
+
hint: asset.kind,
|
|
13
|
+
})), { empty: "No local assets can be moved." });
|
|
14
|
+
}
|
|
15
|
+
/** True keeps separate local copies; false makes the shared copies the only ones. */
|
|
16
|
+
export function chooseKeepLocal(count) {
|
|
17
|
+
const them = count === 1 ? "it" : "them";
|
|
18
|
+
return select({
|
|
19
|
+
message: `Move ${them}, or share a copy and keep ${them} here too?`,
|
|
20
|
+
choices: [
|
|
21
|
+
{
|
|
22
|
+
name: "Move",
|
|
23
|
+
value: false,
|
|
24
|
+
description: `The shared copy becomes the only one. Once it exists, the next sync installs it and removes the local copy.`,
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
name: "Keep a separate local copy",
|
|
28
|
+
value: true,
|
|
29
|
+
description: `Shares a copy. The local ${count === 1 ? "asset stays" : "assets stay"} on this machine as ${count === 1 ? "its" : "their"} own.`,
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
theme: promptTheme,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
2
35
|
export function renderMove(result) {
|
|
3
36
|
if (!result.rows.length) {
|
|
4
37
|
return [dim("Nothing to move.")];
|
|
@@ -10,13 +43,26 @@ export function renderMove(result) {
|
|
|
10
43
|
dim(row.detail ?? ""),
|
|
11
44
|
]), { header: ["Status", "Kind", "Name", ""] });
|
|
12
45
|
output.push("");
|
|
13
|
-
|
|
46
|
+
const moved = result.rows.some((row) => row.status === "moved");
|
|
47
|
+
if (result.direct && result.branch) {
|
|
14
48
|
output.push(`${ok("✔")} Added to ${result.branch}.`);
|
|
15
49
|
}
|
|
16
50
|
else if (result.branch) {
|
|
17
51
|
output.push(result.url
|
|
18
52
|
? `Open the pull request: ${result.url}`
|
|
19
|
-
: `Open a pull request from ${result.branch} on your Git host
|
|
53
|
+
: `Open a pull request from ${result.branch} on your Git host.`);
|
|
54
|
+
}
|
|
55
|
+
if (moved && result.keepLocal) {
|
|
56
|
+
output.push(dim("Your local copies stay as separate assets. Where one has the same name as its shared copy, sync asks which to rename."));
|
|
57
|
+
}
|
|
58
|
+
else if (moved && result.direct) {
|
|
59
|
+
output.push(dim("The shared copies are installed and the local ones removed."));
|
|
60
|
+
}
|
|
61
|
+
else if (moved) {
|
|
62
|
+
output.push(dim("The move finishes when that merges: your local copies stay in use until then, and the next sync replaces them with the shared ones."));
|
|
63
|
+
}
|
|
64
|
+
for (const path of result.removed) {
|
|
65
|
+
output.push(dim(`Removed ${path}`));
|
|
20
66
|
}
|
|
21
67
|
for (const row of result.rows) {
|
|
22
68
|
if (row.status === "clash") {
|
package/dist/ui/onboarding.js
CHANGED
|
@@ -6,38 +6,25 @@ import { localRepoSource } from "../features/workspace/repo-source.js";
|
|
|
6
6
|
import { renderMove } from "./move.js";
|
|
7
7
|
import { checkRepositoryUrl, cloneOrigin, RepositoryAccessError, } from "../features/workspace/git.js";
|
|
8
8
|
import { cloneGitWorkspace, connectGitWorkspace, createGitWorkspace, inspectRepository, localWorkspace, } from "../features/workspace/setup.js";
|
|
9
|
-
import { CliError } from "../errors.js";
|
|
9
|
+
import { CliError, friendlyMessage } from "../errors.js";
|
|
10
10
|
import { selectionState } from "../config/environment.js";
|
|
11
11
|
import { LoginRequiredError } from "../features/auth/transport.js";
|
|
12
12
|
import { runLogin } from "./auth.js";
|
|
13
|
+
import { interactiveTerminal } from "./pick.js";
|
|
13
14
|
import { synchronize } from "../features/environment/sync.js";
|
|
14
15
|
import { cleanUpIfInterrupted } from "../features/environment/transaction.js";
|
|
15
16
|
import { renderSyncOutput } from "./output.js";
|
|
16
|
-
import checkbox from "@inquirer/checkbox";
|
|
17
17
|
import confirm from "@inquirer/confirm";
|
|
18
18
|
import { existsSync, readdirSync, rmSync } from "node:fs";
|
|
19
19
|
import { basename } from "node:path";
|
|
20
20
|
import { styleText } from "node:util";
|
|
21
21
|
import { readSettings, } from "../config/settings.js";
|
|
22
22
|
import { initialize, } from "../features/onboarding/setup.js";
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
23
|
+
import { promptTheme, selected } from "./theme.js";
|
|
24
|
+
import { chooseHarnesses } from "./harness-picker.js";
|
|
25
|
+
import { offerAdoptionAtSetup, } from "./adopt.js";
|
|
26
|
+
import { bold, dim, fields, heading, originLabel, table, warn, } from "./format.js";
|
|
25
27
|
import { barndogPaths } from "../config/paths.js";
|
|
26
|
-
const chooseHarnesses = (choices) => {
|
|
27
|
-
const width = Math.max(...choices.map((choice) => choice.name.length));
|
|
28
|
-
return checkbox({
|
|
29
|
-
loop: false,
|
|
30
|
-
message: "Which coding tools should BarnDog manage?",
|
|
31
|
-
choices: choices.map((choice) => ({
|
|
32
|
-
value: choice.value,
|
|
33
|
-
checked: choice.checked,
|
|
34
|
-
short: choice.name,
|
|
35
|
-
name: `${choice.name.padEnd(width)} ${choice.evidence ? selected("detected") : dim("not found")}`,
|
|
36
|
-
description: choice.evidence ?? undefined,
|
|
37
|
-
})),
|
|
38
|
-
theme: checkboxTheme,
|
|
39
|
-
});
|
|
40
|
-
};
|
|
41
28
|
/** The source setup was last run with, offered as the default. */
|
|
42
29
|
function savedChoice(previous, server) {
|
|
43
30
|
if (previous.gitWorkspace) {
|
|
@@ -90,10 +77,21 @@ function cloneCleanup(home, before, workspaceId) {
|
|
|
90
77
|
};
|
|
91
78
|
return { discard, keep: cleanUpIfInterrupted(discard) };
|
|
92
79
|
}
|
|
80
|
+
/** The setup choices that send local assets to the new workspace. */
|
|
81
|
+
const sharesLocalAssets = {
|
|
82
|
+
keep: false,
|
|
83
|
+
copy: true,
|
|
84
|
+
move: true,
|
|
85
|
+
leave: false,
|
|
86
|
+
};
|
|
93
87
|
export async function runSetup(options) {
|
|
94
88
|
const { runtime } = options;
|
|
95
89
|
const { home } = runtime;
|
|
96
90
|
const write = options.write ?? console.log;
|
|
91
|
+
// Checked first, so a wrong command line fails before any question.
|
|
92
|
+
if ([options.local, options.server, options.repo].filter(Boolean).length > 1) {
|
|
93
|
+
throw new CliError("--local, --repo and --server can't be combined. Choose one.", "barndog init --help");
|
|
94
|
+
}
|
|
97
95
|
const previous = await readSettings(home);
|
|
98
96
|
if (previous) {
|
|
99
97
|
write(`Configuration already exists at ${barndogPaths(home).settings}.`);
|
|
@@ -103,7 +101,7 @@ export async function runSetup(options) {
|
|
|
103
101
|
return;
|
|
104
102
|
}
|
|
105
103
|
}
|
|
106
|
-
const interactive = options.interactive ??
|
|
104
|
+
const interactive = options.interactive ?? interactiveTerminal();
|
|
107
105
|
if (!interactive) {
|
|
108
106
|
throw new CliError("Setup needs an interactive terminal. Run it in your terminal, not from a script or pipe.", "barndog init");
|
|
109
107
|
}
|
|
@@ -120,9 +118,6 @@ export async function runSetup(options) {
|
|
|
120
118
|
}
|
|
121
119
|
}
|
|
122
120
|
write(`\n${heading("setup")}\n`);
|
|
123
|
-
if ([options.local, options.server, options.repo].filter(Boolean).length > 1) {
|
|
124
|
-
throw new CliError("--local, --repo and --server can't be combined. Choose one.", "barndog init --help");
|
|
125
|
-
}
|
|
126
121
|
const choice = flagChoice(options) ??
|
|
127
122
|
(await chooseSource(previous, options.runtime, options.chooseConnection));
|
|
128
123
|
const server = choice.kind === "cloud" ? choice.server : undefined;
|
|
@@ -197,7 +192,13 @@ export async function runSetup(options) {
|
|
|
197
192
|
if (!(error instanceof LoginRequiredError)) {
|
|
198
193
|
throw error;
|
|
199
194
|
}
|
|
200
|
-
await runLogin({
|
|
195
|
+
await runLogin({
|
|
196
|
+
server,
|
|
197
|
+
browser: options.browser !== false,
|
|
198
|
+
runtime,
|
|
199
|
+
force: true,
|
|
200
|
+
interactive,
|
|
201
|
+
}, write);
|
|
201
202
|
session = await authStatus(options.runtime, server);
|
|
202
203
|
}
|
|
203
204
|
write(`${dim("Signed in")} ${session.context.developer.name} · ${session.context.organization.name}`);
|
|
@@ -207,7 +208,11 @@ export async function runSetup(options) {
|
|
|
207
208
|
? await localRepoSource(keptFolder, options.runtime)
|
|
208
209
|
.model()
|
|
209
210
|
.then((model) => model.assets.length + model.knowledge.length)
|
|
210
|
-
.catch(() =>
|
|
211
|
+
.catch((error) => {
|
|
212
|
+
// Setup goes on and leaves the folder as it is, but says why it didn't ask.
|
|
213
|
+
write(`${warn("!")} Couldn't read the local workspace at ${keptFolder.path}, so it stays as it is: ${friendlyMessage(error)}`);
|
|
214
|
+
return 0;
|
|
215
|
+
})
|
|
211
216
|
: 0;
|
|
212
217
|
const localChoice = localCount
|
|
213
218
|
? await (options.chooseLocalAssets ?? chooseLocalAssets)(localCount)
|
|
@@ -305,15 +310,23 @@ export async function runSetup(options) {
|
|
|
305
310
|
write("Setup cancelled. Configuration and installed assets were not changed. Your sign-in is retained.");
|
|
306
311
|
return;
|
|
307
312
|
}
|
|
308
|
-
if (localChoice
|
|
313
|
+
if (sharesLocalAssets[localChoice] && localCount) {
|
|
309
314
|
const to = choice.kind === "cloud"
|
|
310
315
|
? await (options.chooseMoveTarget ?? chooseMoveTarget)(await cloudMoveTargets(options.runtime))
|
|
311
316
|
: undefined;
|
|
312
317
|
write("");
|
|
313
|
-
for (const line of renderMove(await moveLocalAssets({ to }, options.runtime))) {
|
|
318
|
+
for (const line of renderMove(await moveLocalAssets({ to, keepLocal: localChoice === "copy" }, options.runtime))) {
|
|
314
319
|
write(line);
|
|
315
320
|
}
|
|
316
321
|
}
|
|
322
|
+
// Only a first setup asks: later runs already had the chance, and `barndog adopt` stays available.
|
|
323
|
+
if (!previous) {
|
|
324
|
+
await offerAdoptionAtSetup(runtime, {
|
|
325
|
+
write,
|
|
326
|
+
choose: options.chooseAdoption,
|
|
327
|
+
confirm: options.confirmAdoption,
|
|
328
|
+
});
|
|
329
|
+
}
|
|
317
330
|
write("");
|
|
318
331
|
write(`${selected("✔")} Saved to ${result.configPath}`);
|
|
319
332
|
write("");
|
package/dist/ui/output.js
CHANGED
|
@@ -52,7 +52,9 @@ function rows(events) {
|
|
|
52
52
|
byKey.set(key, row);
|
|
53
53
|
};
|
|
54
54
|
for (const event of events) {
|
|
55
|
-
if (event.type === "disabled" ||
|
|
55
|
+
if (event.type === "disabled" ||
|
|
56
|
+
event.type === "notice" ||
|
|
57
|
+
event.type === "unset-variable") {
|
|
56
58
|
continue;
|
|
57
59
|
}
|
|
58
60
|
if (event.type === "invalid") {
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { adapters, hookHarnesses } from "../harnesses/registry.js";
|
|
2
|
+
import { SHORT_COMMIT_LENGTH } from "../shared/constants.js";
|
|
3
|
+
import { bold, clean, dim, fields } from "./format.js";
|
|
4
|
+
/** `skills show` and `hooks show`: what the asset is and where this machine has it. */
|
|
5
|
+
export function renderPackageDetails(details) {
|
|
6
|
+
const { installed } = details;
|
|
7
|
+
const events = hookHarnesses.flatMap((harness) => {
|
|
8
|
+
const names = details.events?.[harness];
|
|
9
|
+
return names ? [`${adapters[harness].name}: ${names.join(", ")}`] : [];
|
|
10
|
+
});
|
|
11
|
+
const output = fields([
|
|
12
|
+
["Name", bold(clean(details.name))],
|
|
13
|
+
["Origin", details.origin],
|
|
14
|
+
[
|
|
15
|
+
"Version",
|
|
16
|
+
typeof details.version === "number"
|
|
17
|
+
? `v${details.version}`
|
|
18
|
+
: details.version.slice(0, SHORT_COMMIT_LENGTH),
|
|
19
|
+
],
|
|
20
|
+
["Description", clean(details.description)],
|
|
21
|
+
["State", installed?.state ?? dim("not installed")],
|
|
22
|
+
[
|
|
23
|
+
"Installed in",
|
|
24
|
+
installed?.harnesses.map((harness) => adapters[harness].name).join(", "),
|
|
25
|
+
],
|
|
26
|
+
]);
|
|
27
|
+
if (details.kind === "hook") {
|
|
28
|
+
output.push("", dim("Events"), ...(events.length ? events : [dim("No coding tool runs it.")]).map((line) => ` ${line}`));
|
|
29
|
+
}
|
|
30
|
+
if (installed?.paths.length) {
|
|
31
|
+
output.push("", dim("Paths"), ...installed.paths.map((path) => ` ${path}`));
|
|
32
|
+
}
|
|
33
|
+
return output;
|
|
34
|
+
}
|
package/dist/ui/scope-install.js
CHANGED
|
@@ -3,6 +3,7 @@ import select from "@inquirer/select";
|
|
|
3
3
|
import { CliError } from "../errors.js";
|
|
4
4
|
import { runSelection } from "./selection.js";
|
|
5
5
|
import { checkboxTheme, promptTheme } from "./theme.js";
|
|
6
|
+
import { interactiveTerminal } from "./pick.js";
|
|
6
7
|
/**
|
|
7
8
|
* Installs a scope using an explicit mode or interactive asset selection, then
|
|
8
9
|
* renders the selection result.
|
|
@@ -12,7 +13,9 @@ export async function runSetInstall(context, options, prompts = {}) {
|
|
|
12
13
|
if (options.mode) {
|
|
13
14
|
return install(options.mode);
|
|
14
15
|
}
|
|
15
|
-
if (!(prompts.interactive ??
|
|
16
|
+
if (!(prompts.interactive ??
|
|
17
|
+
context.mode?.interactive ??
|
|
18
|
+
interactiveTerminal())) {
|
|
16
19
|
throw new CliError("Choose which assets to include with --mode, or run this in a terminal to pick.", `barndog sets install ${options.origin} --mode recommended`);
|
|
17
20
|
}
|
|
18
21
|
const mode = await (prompts.mode ??
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** Reads an MCP variable's value without showing it or putting it in shell history. */
|
|
2
|
+
import input from "@inquirer/input";
|
|
3
|
+
import { promptTheme } from "./theme.js";
|
|
4
|
+
/** Asks in the terminal, echoing one `*` per character. */
|
|
5
|
+
export function askSecret(variable) {
|
|
6
|
+
return input({
|
|
7
|
+
message: `Value for ${variable}`,
|
|
8
|
+
transformer: (value) => "*".repeat(value.length),
|
|
9
|
+
theme: promptTheme,
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
/** Everything piped in, without the final line break a file or `echo` adds. */
|
|
13
|
+
export async function readStdin(stream = process.stdin) {
|
|
14
|
+
let text = "";
|
|
15
|
+
for await (const chunk of stream) {
|
|
16
|
+
text += chunk.toString();
|
|
17
|
+
}
|
|
18
|
+
return text.replace(/\r?\n$/, "");
|
|
19
|
+
}
|
package/dist/ui/selection.js
CHANGED
|
@@ -4,6 +4,7 @@ import { DecisionRequiredError } from "./decision-error.js";
|
|
|
4
4
|
import { json } from "./format.js";
|
|
5
5
|
import { renderSyncOutput } from "./output.js";
|
|
6
6
|
import { promptTheme } from "./theme.js";
|
|
7
|
+
import { interactiveTerminal } from "./pick.js";
|
|
7
8
|
/** A change that would undo exclusions or disabled assets runs again with the answer. */
|
|
8
9
|
export async function runSelection(context, change) {
|
|
9
10
|
let resolution;
|
|
@@ -19,7 +20,8 @@ export async function runSelection(context, change) {
|
|
|
19
20
|
}
|
|
20
21
|
return;
|
|
21
22
|
}
|
|
22
|
-
if (context.mode?.json ||
|
|
23
|
+
if (context.mode?.json ||
|
|
24
|
+
!(context.mode?.interactive ?? interactiveTerminal())) {
|
|
23
25
|
throw new DecisionRequiredError(result.conflicts);
|
|
24
26
|
}
|
|
25
27
|
const type = await select({
|