barndog 0.1.1 → 0.2.0
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 +8 -7
- package/dist/cli.js +11 -7
- package/dist/commands/add.js +33 -21
- package/dist/commands/arguments.js +12 -0
- package/dist/commands/asset-install.js +160 -0
- package/dist/commands/asset-list.js +121 -0
- package/dist/commands/asset-share.js +94 -0
- package/dist/commands/auth.js +4 -0
- package/dist/commands/availability.js +54 -26
- package/dist/commands/capabilities.js +71 -415
- package/dist/commands/collaboration.js +194 -110
- package/dist/commands/environment.js +18 -411
- package/dist/commands/github.js +200 -0
- package/dist/commands/helpers.js +39 -0
- package/dist/commands/hooks.js +87 -0
- package/dist/commands/init.js +4 -2
- package/dist/commands/knowledge.js +73 -0
- package/dist/commands/mcp.js +62 -0
- package/dist/commands/origin.js +21 -23
- package/dist/commands/people.js +51 -0
- package/dist/commands/sets.js +141 -0
- package/dist/commands/status.js +34 -24
- package/dist/commands/sync.js +11 -4
- package/dist/commands/workspace.js +33 -19
- package/dist/config/environment.js +13 -27
- package/dist/config/paths.js +62 -0
- package/dist/config/selection.js +30 -0
- package/dist/config/settings.js +97 -108
- package/dist/config/state.js +57 -57
- package/dist/entry/knowledge-startup.js +32 -0
- package/dist/entry/mcp-launch.js +71 -0
- package/dist/entry/opencode-plugin.js +62 -0
- package/dist/{features/git-workspace/startup.js → entry/workspace-startup.js} +7 -2
- package/dist/errors.js +198 -55
- package/dist/features/asset-kinds/index.js +120 -0
- package/dist/features/asset-selection/index.js +51 -19
- package/dist/features/auth/credentials.js +80 -47
- package/dist/features/auth/session.js +80 -45
- package/dist/features/auth/transport.js +66 -15
- package/dist/features/catalog/index.js +32 -61
- package/dist/features/collaboration/api.js +160 -0
- package/dist/features/collaboration/index.js +321 -233
- package/dist/features/collaboration/remote.js +35 -115
- package/dist/features/collaboration/results.js +2 -0
- package/dist/features/collaboration/workspace-git.js +233 -149
- package/dist/features/collaboration/workspace-github.js +117 -54
- package/dist/features/collaboration/workspace-store.js +140 -100
- package/dist/features/collaboration/workspace.js +257 -172
- package/dist/features/discovery/index.js +68 -57
- package/dist/features/doctor/index.js +32 -24
- package/dist/features/environment/auto-sync.js +28 -27
- package/dist/features/environment/names.js +67 -47
- package/dist/features/environment/operations.js +321 -228
- package/dist/features/environment/own-entries.js +89 -0
- package/dist/features/environment/settle-names.js +91 -0
- package/dist/features/environment/stage.js +178 -0
- package/dist/features/environment/sync.js +113 -484
- package/dist/features/environment/transaction.js +179 -147
- package/dist/features/environment/writes.js +196 -0
- package/dist/features/github/account.js +25 -0
- package/dist/features/github/connections.js +119 -0
- package/dist/features/github/pulls.js +118 -0
- package/dist/features/hooks/adapt.js +32 -25
- package/dist/features/hooks/catalog.js +28 -0
- package/dist/features/hooks/compatibility.js +49 -0
- package/dist/features/hooks/divergence.js +9 -6
- package/dist/features/hooks/test.js +74 -49
- package/dist/features/hooks/types.js +1 -0
- package/dist/features/imports/discover.js +134 -61
- package/dist/features/imports/folder.js +48 -14
- package/dist/features/imports/local.js +113 -134
- package/dist/features/imports/remote.js +44 -25
- package/dist/features/inspection/index.js +17 -17
- package/dist/features/inventory/index.js +99 -110
- package/dist/features/knowledge/index.js +69 -49
- package/dist/features/mcps/catalog.js +31 -0
- package/dist/features/mcps/import.js +316 -0
- package/dist/features/mcps/index.js +98 -49
- package/dist/features/migration/migrate.js +263 -0
- package/dist/features/{git-workspace → migration}/move.js +165 -109
- package/dist/features/migration/promote.js +24 -0
- package/dist/features/native/adapters.js +53 -94
- package/dist/features/native/configuration.js +128 -82
- package/dist/features/native/hook-shell.js +55 -0
- package/dist/features/native/plugin-module.js +56 -0
- package/dist/features/onboarding/environment.js +67 -34
- package/dist/features/onboarding/setup.js +43 -40
- package/dist/features/repositories/context.js +30 -13
- package/dist/features/server/catalog.js +58 -0
- package/dist/features/server/client.js +13 -0
- package/dist/features/server/connection.js +37 -0
- package/dist/features/server/origin.js +74 -0
- package/dist/features/server/pages.js +24 -0
- package/dist/features/skills/catalog.js +42 -0
- package/dist/features/workspace/assets.js +57 -0
- package/dist/features/workspace/cloud-source.js +34 -0
- package/dist/features/workspace/directory.js +38 -0
- package/dist/features/{git-workspace → workspace}/format.js +114 -51
- package/dist/features/workspace/git.js +214 -0
- package/dist/features/workspace/installed.js +92 -0
- package/dist/features/{git-workspace → workspace}/overlay.js +43 -23
- package/dist/features/workspace/packages.js +160 -0
- package/dist/features/{git-workspace → workspace}/publish.js +120 -64
- package/dist/features/workspace/repo-source.js +192 -0
- package/dist/features/{git-workspace → workspace}/setup.js +60 -42
- package/dist/features/{git-workspace → workspace}/snapshot.js +53 -18
- package/dist/features/workspace/source.js +1 -0
- package/dist/features/workspace/tree.js +52 -0
- package/dist/features/workspace/workspace-source.js +27 -0
- package/dist/harnesses/claude.js +23 -1
- package/dist/harnesses/codex.js +57 -1
- package/dist/harnesses/cursor.js +22 -1
- package/dist/harnesses/detect.js +6 -50
- package/dist/harnesses/formats.js +45 -0
- package/dist/harnesses/opencode.js +111 -0
- package/dist/harnesses/registry.js +35 -2
- package/dist/platform.js +375 -0
- package/dist/program.js +225 -54
- package/dist/runtime.js +1 -0
- package/dist/shared/cli-error.js +22 -0
- package/dist/shared/constants.js +32 -0
- package/dist/shared/files.js +72 -0
- package/dist/shared/lock.js +49 -0
- package/dist/shared/lookup.js +11 -0
- package/dist/shared/patterns.js +94 -0
- package/dist/shared/shell.js +22 -0
- package/dist/shared/values.js +26 -0
- package/dist/ui/add-asset.js +41 -400
- package/dist/ui/add-hook.js +213 -0
- package/dist/ui/add-mcp.js +107 -0
- package/dist/ui/add-prompts.js +47 -0
- package/dist/ui/add-skills.js +115 -0
- package/dist/ui/asset-list.js +31 -13
- package/dist/ui/assets.js +33 -44
- package/dist/ui/auth.js +43 -33
- package/dist/ui/clash.js +11 -6
- package/dist/ui/collaboration.js +116 -44
- package/dist/ui/connection.js +10 -4
- package/dist/ui/decision-error.js +24 -0
- package/dist/ui/environment-onboarding.js +35 -13
- package/dist/ui/format.js +66 -18
- package/dist/ui/hook-compatibility.js +14 -6
- package/dist/ui/mcp.js +28 -3
- package/dist/ui/move.js +10 -5
- package/dist/ui/onboarding.js +113 -73
- package/dist/ui/options.js +9 -0
- package/dist/ui/output.js +106 -43
- package/dist/ui/pick.js +45 -33
- package/dist/ui/scope-install.js +15 -7
- package/dist/ui/selection.js +15 -11
- package/dist/ui/theme.js +37 -14
- package/dist/version.js +6 -3
- package/package.json +13 -3
- package/dist/features/capabilities/index.js +0 -106
- package/dist/features/collaboration/domain.js +0 -90
- package/dist/features/environment/cloud-source.js +0 -27
- package/dist/features/environment/installed.js +0 -124
- package/dist/features/environment/packages.js +0 -120
- package/dist/features/environment/remote.js +0 -71
- package/dist/features/environment/workspace-source.js +0 -19
- package/dist/features/git-hosts/index.js +0 -148
- package/dist/features/git-workspace/assets.js +0 -71
- package/dist/features/git-workspace/git.js +0 -135
- package/dist/features/git-workspace/migrate.js +0 -188
- package/dist/features/git-workspace/source.js +0 -159
- package/dist/features/imports/mcp.js +0 -219
- package/dist/features/knowledge/startup.js +0 -25
- package/dist/features/native/mcp-launch.js +0 -57
- package/dist/features/skills/install.js +0 -25
- package/dist/features/skills/remote.js +0 -177
- package/dist/features/skills/sync.js +0 -121
- package/dist/features/skills/validation.js +0 -34
- /package/dist/features/environment/{source.js → events.js} +0 -0
|
@@ -1,416 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
import { runSetInstall } from "../ui/scope-install.js";
|
|
11
|
-
import { runSelection } from "../ui/selection.js";
|
|
12
|
-
import { pickMany, pickOne } from "../ui/pick.js";
|
|
13
|
-
import { promptTheme } from "../ui/theme.js";
|
|
14
|
-
import { bold, clean, dim, hint, json, ok, ORIGIN_HELP, originLabel, section, table, } from "../ui/format.js";
|
|
15
|
-
export { runSelection } from "../ui/selection.js";
|
|
16
|
-
/** Asks for a value in a terminal, or explains the flag to pass. */
|
|
17
|
-
export async function ask(context, value, message, flag, fallback) {
|
|
18
|
-
if (value)
|
|
19
|
-
return value;
|
|
20
|
-
if (!context.mode.interactive)
|
|
21
|
-
throw new CliError(`Add ${flag} <value> to this command, or run it in a terminal to be asked.`);
|
|
22
|
-
return (await input({ message, default: fallback, theme: promptTheme })).trim();
|
|
23
|
-
}
|
|
24
|
-
function requireArguments(context, usage) {
|
|
25
|
-
if (!context.mode.interactive)
|
|
26
|
-
throw new CliError("Name the asset to act on, or run this in a terminal to choose from a list.", usage);
|
|
27
|
-
}
|
|
28
|
-
/** Installed assets eligible for an action on this machine. */
|
|
29
|
-
function localCandidates(items, kind, action) {
|
|
30
|
-
return items.filter((item) => item.kind === kind &&
|
|
31
|
-
!item.via.includes("config") &&
|
|
32
|
-
item.origin !== "—" &&
|
|
33
|
-
(action === "enable"
|
|
34
|
-
? item.state === "disabled"
|
|
35
|
-
: action === "disable"
|
|
36
|
-
? item.state !== "disabled"
|
|
37
|
-
: true));
|
|
38
|
-
}
|
|
39
|
-
const localChoice = (item) => ({
|
|
40
|
-
value: item,
|
|
41
|
-
name: item.installedName,
|
|
42
|
-
hint: `${item.origin} · ${item.state}`,
|
|
43
|
-
});
|
|
1
|
+
import { assetKindList, assetKinds } from "../features/asset-kinds/index.js";
|
|
2
|
+
import { registerList, registerSearch } from "./asset-list.js";
|
|
3
|
+
import { registerInstall, registerRename, registerToggles, } from "./asset-install.js";
|
|
4
|
+
import { registerSharing } from "./asset-share.js";
|
|
5
|
+
import { registerSets } from "./sets.js";
|
|
6
|
+
/**
|
|
7
|
+
* Registers environment selection and subscription commands using the supplied
|
|
8
|
+
* services.
|
|
9
|
+
*/
|
|
44
10
|
export function registerEnvironment(program, context) {
|
|
45
|
-
for (const kind of
|
|
46
|
-
const labels = kindLabels[kind];
|
|
47
|
-
const group = labels.group;
|
|
48
|
-
const addCommand = `barndog ${group} add${kind === "mcp" ? "" : kind === "skill" ? " <source>" : " <url>"}`;
|
|
11
|
+
for (const kind of assetKindList) {
|
|
49
12
|
const command = program
|
|
50
|
-
.command(
|
|
51
|
-
.description(
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
.description(`List installed, disabled and available ${labels.many}`);
|
|
59
|
-
pageOptions(listCommand)
|
|
60
|
-
.option("--installed", `Only ${labels.many} installed on this machine`)
|
|
61
|
-
.option("--disabled", `Only ${labels.many} you've disabled`)
|
|
62
|
-
.option("--available", `Only ${labels.many} you can install`)
|
|
63
|
-
.option("--paths", "Show installed folders and configuration files")
|
|
64
|
-
.action(async (options) => {
|
|
65
|
-
const narrowed = options.installed || options.disabled;
|
|
66
|
-
const onlyAvailable = options.available && !narrowed;
|
|
67
|
-
let catalogProblem;
|
|
68
|
-
const [inventory, rows] = await Promise.all([
|
|
69
|
-
context.inventory(),
|
|
70
|
-
options.available || !narrowed
|
|
71
|
-
? context.searchCatalog(kind).catch((error) => {
|
|
72
|
-
if (onlyAvailable)
|
|
73
|
-
throw error;
|
|
74
|
-
catalogProblem = friendlyMessage(error);
|
|
75
|
-
return [];
|
|
76
|
-
})
|
|
77
|
-
: [],
|
|
78
|
-
]);
|
|
79
|
-
const items = inventory.items.filter((item) => item.kind === kind);
|
|
80
|
-
const listing = assetListing(items, rows, options);
|
|
81
|
-
if (context.mode.json)
|
|
82
|
-
return context.write(json(listing));
|
|
83
|
-
if (inventory.offline)
|
|
84
|
-
context.write(dim(`Showing local state only: ${inventory.offline}`));
|
|
85
|
-
else if (catalogProblem)
|
|
86
|
-
context.write(dim(`Couldn't load available ${labels.many}: ${catalogProblem}`));
|
|
87
|
-
if (!listing.length) {
|
|
88
|
-
if (narrowed) {
|
|
89
|
-
context.write(`No ${labels.many} match that filter.`);
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
if (catalogProblem || inventory.offline) {
|
|
93
|
-
context.write(`No ${labels.many} on this machine yet.`);
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
context.write(`No ${labels.many} yet.`);
|
|
97
|
-
context.write(hint(addCommand, "Next"));
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
const start = (options.page - 1) * options.limit;
|
|
101
|
-
const page = listing.slice(start, start + options.limit);
|
|
102
|
-
if (!page.length) {
|
|
103
|
-
context.write(`Page ${options.page} is empty. Choose a page from 1 to ${Math.ceil(listing.length / options.limit)}.`);
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
for (const line of renderInventory(page, options))
|
|
107
|
-
context.write(line);
|
|
108
|
-
if (listing.length > options.limit) {
|
|
109
|
-
const flags = ["installed", "disabled", "available"]
|
|
110
|
-
.filter((flag) => options[flag])
|
|
111
|
-
.map((flag) => ` --${flag}`)
|
|
112
|
-
.join("");
|
|
113
|
-
context.write("\n" +
|
|
114
|
-
dim(`Showing ${start + 1}–${start + page.length} of ${listing.length}`));
|
|
115
|
-
if (start + page.length < listing.length)
|
|
116
|
-
context.write(hint(`barndog ${group} list${flags} --page ${options.page + 1}`, "Next"));
|
|
117
|
-
}
|
|
118
|
-
const onThisMachine = page.filter((item) => item.state !== "available");
|
|
119
|
-
const hints = inventoryHints(onThisMachine);
|
|
120
|
-
if (hints.length)
|
|
121
|
-
context.write(["", ...hints].join("\n"));
|
|
122
|
-
else if (!options.paths && onThisMachine.length)
|
|
123
|
-
context.write("\n" +
|
|
124
|
-
hint(`barndog ${group} list --paths`, "Tip") +
|
|
125
|
-
dim(" to see where each one lives"));
|
|
126
|
-
});
|
|
127
|
-
const search = async (assetKind, query, options) => {
|
|
128
|
-
const [rows, inventory] = await Promise.all([
|
|
129
|
-
context.searchCatalog(assetKind),
|
|
130
|
-
context.inventory().catch(() => undefined),
|
|
131
|
-
]);
|
|
132
|
-
const selected = new Set(inventory?.items
|
|
133
|
-
.filter((item) => item.state !== "removing")
|
|
134
|
-
.map((item) => item.id) ?? []);
|
|
135
|
-
// JSON gets the same matches the table shows, all pages at once.
|
|
136
|
-
if (context.mode.json)
|
|
137
|
-
return context.write(json(filterAssets(rows, { ...options, search: query }).map((row) => ({
|
|
138
|
-
...row,
|
|
139
|
-
selected: selected.has(row.id),
|
|
140
|
-
}))));
|
|
141
|
-
for (const line of renderCatalog(rows, { ...options, search: query }, `barndog ${group} search`, selected))
|
|
142
|
-
context.write(line);
|
|
143
|
-
};
|
|
144
|
-
assetListOptions(command
|
|
145
|
-
.command("search [query]")
|
|
146
|
-
.description(`Browse ${labels.many} published in your workspace`), false).action((query, options) => search(kind, query ?? options.search, options));
|
|
147
|
-
command
|
|
148
|
-
.command("install [name]")
|
|
149
|
-
.description(`Install ${labels.many} on this machine; choose from a list when no name is given`)
|
|
150
|
-
.option("--origin <origin>", ORIGIN_HELP)
|
|
151
|
-
.addOption(new Option("--overrides <choice>", "Keep or clear your existing exclusions").choices(["preserve", "clear"]))
|
|
152
|
-
.option("--decisions <file>", "JSON per-asset override choices")
|
|
153
|
-
.action(async (name, options) => {
|
|
154
|
-
if (name)
|
|
155
|
-
return runSelection(context, "install", { ...options, name, kind });
|
|
156
|
-
requireArguments(context, `barndog ${group} install <name> --origin <origin>`);
|
|
157
|
-
const [rows, inventory] = await Promise.all([
|
|
158
|
-
context.searchCatalog(kind),
|
|
159
|
-
context.inventory(),
|
|
160
|
-
]);
|
|
161
|
-
const selected = new Set(inventory.items
|
|
162
|
-
.filter((item) => item.state !== "removing")
|
|
163
|
-
.map((item) => item.id));
|
|
164
|
-
const inOrigin = rows.filter((row) => !options.origin ||
|
|
165
|
-
originLabel(row.origin) === options.origin.replace(":", "/"));
|
|
166
|
-
const ids = await pickMany(`Choose ${labels.many} to install`, inOrigin
|
|
167
|
-
.filter((row) => !selected.has(row.id))
|
|
168
|
-
.sort((a, b) => a.name.localeCompare(b.name))
|
|
169
|
-
.map((row) => ({
|
|
170
|
-
value: row.id,
|
|
171
|
-
name: row.name,
|
|
172
|
-
hint: `${originLabel(row.origin)} · ${clean(row.version.description)}`,
|
|
173
|
-
})), {
|
|
174
|
-
empty: inOrigin.length
|
|
175
|
-
? `Every available ${labels.one} is already on this machine.`
|
|
176
|
-
: `No ${labels.many} available to install. Add one with ${addCommand}.`,
|
|
177
|
-
});
|
|
178
|
-
await runSelection(context, "install", {
|
|
179
|
-
kind,
|
|
180
|
-
ids,
|
|
181
|
-
overrides: options.overrides,
|
|
182
|
-
decisions: options.decisions,
|
|
183
|
-
});
|
|
184
|
-
});
|
|
185
|
-
for (const action of ["remove", "enable", "disable"])
|
|
186
|
-
command
|
|
187
|
-
.command(`${action} [name]`)
|
|
188
|
-
.description(action === "remove"
|
|
189
|
-
? `Remove ${labels.many} from this machine, even when a set includes them`
|
|
190
|
-
: action === "enable"
|
|
191
|
-
? `Turn disabled ${labels.many} back on`
|
|
192
|
-
: `Turn ${labels.many} off without removing them from your selection`)
|
|
193
|
-
.option("--origin <origin>", ORIGIN_HELP)
|
|
194
|
-
.action(async (name, options) => {
|
|
195
|
-
if (name)
|
|
196
|
-
return runSelection(context, action, { ...options, name, kind });
|
|
197
|
-
requireArguments(context, `barndog ${group} ${action} <name>`);
|
|
198
|
-
const items = localCandidates((await context.inventory()).items, kind, action);
|
|
199
|
-
const chosen = await pickMany(`Choose ${labels.many} to ${action}`, items.map(localChoice), {
|
|
200
|
-
empty: action === "enable"
|
|
201
|
-
? `No ${labels.many} are disabled.`
|
|
202
|
-
: `No ${labels.many} to ${action} on this machine.`,
|
|
203
|
-
});
|
|
204
|
-
await runSelection(context, action, {
|
|
205
|
-
kind,
|
|
206
|
-
ids: chosen.map((item) => item.id),
|
|
207
|
-
});
|
|
208
|
-
});
|
|
209
|
-
command
|
|
210
|
-
.command("rename [name]")
|
|
211
|
-
.description(`Install ${labels.a} under a different local name`)
|
|
212
|
-
.option("--origin <origin>", ORIGIN_HELP)
|
|
213
|
-
.option("--as <name>", "New local name: lowercase letters, numbers and hyphens")
|
|
214
|
-
.option("--reset", "Go back to the published name")
|
|
215
|
-
.action(async (name, options) => {
|
|
216
|
-
let target = name;
|
|
217
|
-
let suggestion;
|
|
218
|
-
if (!target) {
|
|
219
|
-
requireArguments(context, `barndog ${group} rename <name> --as <new-name>`);
|
|
220
|
-
const item = await pickOne(`Choose ${labels.a} to rename`, localCandidates((await context.inventory()).items, kind, "rename").map(localChoice), { empty: `No ${labels.many} to rename on this machine.` });
|
|
221
|
-
target = item.id;
|
|
222
|
-
const [type, slug] = item.origin.split("/");
|
|
223
|
-
suggestion = prefixedName({
|
|
224
|
-
name: item.name,
|
|
225
|
-
origin: { type: type, slug: slug ?? "" },
|
|
226
|
-
});
|
|
227
|
-
}
|
|
228
|
-
const as = options.reset
|
|
229
|
-
? undefined
|
|
230
|
-
: await ask(context, options.as, "New local name", "--as", suggestion);
|
|
231
|
-
await runSelection(context, "rename", {
|
|
232
|
-
kind,
|
|
233
|
-
name: target,
|
|
234
|
-
origin: options.origin,
|
|
235
|
-
as,
|
|
236
|
-
reset: options.reset,
|
|
237
|
-
});
|
|
238
|
-
// A clash prompt during the sync may have chosen a different name.
|
|
239
|
-
const item = (await context.inventory()).items.find((entry) => entry.kind === kind &&
|
|
240
|
-
[entry.id, entry.name, entry.installedName].includes(target) &&
|
|
241
|
-
(!options.origin || entry.origin === options.origin));
|
|
242
|
-
if (item && !context.mode.json)
|
|
243
|
-
context.write(item.installedName === item.name
|
|
244
|
-
? `${ok("✔")} ${bold(item.name)} uses its published name.`
|
|
245
|
-
: `${ok("✔")} ${bold(item.name)} from ${item.origin} is installed as ${bold(item.installedName)}.`);
|
|
246
|
-
});
|
|
247
|
-
for (const action of ["fork", "promote"])
|
|
248
|
-
command
|
|
249
|
-
.command(`${action} [name]`)
|
|
250
|
-
.description(action === "fork"
|
|
251
|
-
? `Copy ${labels.a} into a scope you own, such as your personal space`
|
|
252
|
-
: `Propose ${labels.a} for a team, repository or the organization`)
|
|
253
|
-
.option("--origin <origin>", ORIGIN_HELP)
|
|
254
|
-
.option("--target <origin>", "Destination scope, such as me, team/engineering or org")
|
|
255
|
-
.option("--name <newName>", "Name of the new asset")
|
|
256
|
-
.option("--key <key>", "Stable key for exact retries")
|
|
257
|
-
.action(async (name, options) => {
|
|
258
|
-
let origin = options.origin;
|
|
259
|
-
if (!name) {
|
|
260
|
-
requireArguments(context, `barndog ${group} ${action} <name> --origin <origin> --target <origin> --name <new-name>`);
|
|
261
|
-
const row = await pickOne(`Choose ${labels.a} to ${action}`, (await context.searchCatalog(kind)).map((row) => ({
|
|
262
|
-
value: row,
|
|
263
|
-
name: row.name,
|
|
264
|
-
hint: `${originLabel(row.origin)} · ${clean(row.version.description)}`,
|
|
265
|
-
})));
|
|
266
|
-
name = row.name;
|
|
267
|
-
origin = originLabel(row.origin);
|
|
268
|
-
}
|
|
269
|
-
origin = await ask(context, origin, "Current scope", "--origin");
|
|
270
|
-
const target = await ask(context, options.target, "Destination scope (me, team/<slug>, repo/<slug> or org)", "--target", action === "fork" ? "me" : undefined);
|
|
271
|
-
const newName = await ask(context, options.name, "New name", "--name", name);
|
|
272
|
-
const outcome = await context.capability(action, {
|
|
273
|
-
kind,
|
|
274
|
-
name,
|
|
275
|
-
origin,
|
|
276
|
-
target,
|
|
277
|
-
newName,
|
|
278
|
-
key: options.key,
|
|
279
|
-
});
|
|
280
|
-
if (origin === LOCAL_ORIGIN) {
|
|
281
|
-
if (context.mode.json)
|
|
282
|
-
return context.write(json(outcome));
|
|
283
|
-
for (const line of renderMove(outcome))
|
|
284
|
-
context.write(line);
|
|
285
|
-
return;
|
|
286
|
-
}
|
|
287
|
-
const result = z
|
|
288
|
-
.object({
|
|
289
|
-
kind: z.string(),
|
|
290
|
-
id: z.string(),
|
|
291
|
-
changeId: z.string().optional(),
|
|
292
|
-
})
|
|
293
|
-
.parse(outcome);
|
|
294
|
-
if (context.mode.json)
|
|
295
|
-
return context.write(json(result));
|
|
296
|
-
context.write(result.changeId
|
|
297
|
-
? `${ok("✔")} Proposed ${bold(newName)} for ${target}. A reviewer must merge the Suggested Change.`
|
|
298
|
-
: `${ok("✔")} Created ${bold(newName)} in ${target}.`);
|
|
299
|
-
context.write(result.changeId
|
|
300
|
-
? hint(`barndog changes show ${result.changeId}`)
|
|
301
|
-
: hint(`barndog ${group} install ${newName} --origin ${target === "me" ? "me" : target}`));
|
|
302
|
-
});
|
|
13
|
+
.command(assetKinds[kind].command)
|
|
14
|
+
.description(`Install, browse and manage ${assetKinds[kind].many}`);
|
|
15
|
+
registerList(command, kind, context);
|
|
16
|
+
registerSearch(command, kind, context);
|
|
17
|
+
registerInstall(command, kind, context);
|
|
18
|
+
registerToggles(command, kind, context);
|
|
19
|
+
registerRename(command, kind, context);
|
|
20
|
+
registerSharing(command, kind, context);
|
|
303
21
|
}
|
|
304
22
|
registerSets(program, context);
|
|
305
23
|
}
|
|
306
|
-
function registerSets(program, context) {
|
|
307
|
-
const sets = program
|
|
308
|
-
.command("sets")
|
|
309
|
-
.description("Subscribe to everything a team, repository or the organization shares");
|
|
310
|
-
const load = async () => (await context.environment("sets-list", {}));
|
|
311
|
-
const label = (scope) => originLabel(scope);
|
|
312
|
-
assetListOptions(sets
|
|
313
|
-
.command("list")
|
|
314
|
-
.description("Show your subscriptions and the scopes you can subscribe to")).action(async (options) => {
|
|
315
|
-
const result = await load();
|
|
316
|
-
if (context.mode.json)
|
|
317
|
-
return context.write(json(result));
|
|
318
|
-
const subscribed = result.subscriptions.map((subscription) => ({
|
|
319
|
-
subscription,
|
|
320
|
-
scope: result.available.find((s) => s.id === subscription.scope.id && s.type === subscription.scope.type),
|
|
321
|
-
}));
|
|
322
|
-
context.write(`${section("Subscribed")} ${dim(`(${subscribed.length})`)}`);
|
|
323
|
-
context.write(subscribed.length
|
|
324
|
-
? table(subscribed.map(({ subscription, scope }) => [
|
|
325
|
-
bold(scope
|
|
326
|
-
? label(scope)
|
|
327
|
-
: `${subscription.scope.type}/${subscription.scope.id}`),
|
|
328
|
-
scope?.name ?? dim("unavailable"),
|
|
329
|
-
subscription.mode,
|
|
330
|
-
subscription.enabled ? ok("enabled") : dim("disabled"),
|
|
331
|
-
]), { header: ["Scope", "Name", "Mode", "State"] }).join("\n")
|
|
332
|
-
: dim(" None yet."));
|
|
333
|
-
const terms = options.search?.toLowerCase().split(/\s+/).filter(Boolean) ?? [];
|
|
334
|
-
const available = result.available
|
|
335
|
-
.filter((scope) => !result.subscriptions.some((s) => s.scope.id === scope.id && s.scope.type === scope.type))
|
|
336
|
-
.filter((scope) => (!options.origin ||
|
|
337
|
-
scope.type === options.origin ||
|
|
338
|
-
label(scope) === options.origin.replace(":", "/")) &&
|
|
339
|
-
terms.every((term) => `${label(scope)} ${scope.name ?? ""}`.toLowerCase().includes(term)))
|
|
340
|
-
.sort((a, b) => label(a).localeCompare(label(b)));
|
|
341
|
-
const start = (options.page - 1) * options.limit;
|
|
342
|
-
const page = available.slice(start, start + options.limit);
|
|
343
|
-
context.write("");
|
|
344
|
-
context.write(`${section("Available")} ${dim(`(${available.length})`)}`);
|
|
345
|
-
context.write(page.length
|
|
346
|
-
? table(page.map((scope) => [bold(label(scope)), scope.name ?? ""]), { header: ["Scope", "Name"] }).join("\n")
|
|
347
|
-
: dim(" Nothing else to subscribe to."));
|
|
348
|
-
if (start + options.limit < available.length)
|
|
349
|
-
context.write(hint(`barndog sets list --page ${options.page + 1}`));
|
|
350
|
-
context.write("");
|
|
351
|
-
context.write(hint("barndog sets install", "Tip") + dim(" to subscribe"));
|
|
352
|
-
});
|
|
353
|
-
const chooseScope = async (message, filter, empty) => {
|
|
354
|
-
const result = await load();
|
|
355
|
-
return pickOne(message, result.available
|
|
356
|
-
.filter((scope) => filter(scope, result.subscriptions.some((s) => s.scope.id === scope.id && s.scope.type === scope.type)))
|
|
357
|
-
.sort((a, b) => label(a).localeCompare(label(b)))
|
|
358
|
-
.map((scope) => ({
|
|
359
|
-
value: label(scope),
|
|
360
|
-
name: label(scope),
|
|
361
|
-
hint: scope.name,
|
|
362
|
-
})), { empty });
|
|
363
|
-
};
|
|
364
|
-
for (const action of ["install", "remove", "enable", "disable"]) {
|
|
365
|
-
const command = sets
|
|
366
|
-
.command(`${action} [scope]`)
|
|
367
|
-
.description(action === "install"
|
|
368
|
-
? "Subscribe to a scope's shared assets"
|
|
369
|
-
: action === "remove"
|
|
370
|
-
? "Unsubscribe from a scope"
|
|
371
|
-
: action === "enable"
|
|
372
|
-
? "Turn a paused subscription back on"
|
|
373
|
-
: "Pause a subscription without removing it")
|
|
374
|
-
.option("--origin <origin>", "Scope, such as org, team/engineering or repo/web-app");
|
|
375
|
-
if (action === "install")
|
|
376
|
-
command
|
|
377
|
-
.addOption(new Option("--mode <mode>", "Which assets to include; asks when omitted").choices(["recommended", "optional", "all"]))
|
|
378
|
-
.addOption(new Option("--overrides <choice>", "Keep or clear your existing exclusions").choices(["preserve", "clear"]))
|
|
379
|
-
.option("--decisions <file>", "JSON per-asset override choices");
|
|
380
|
-
command.action(async (scope, options) => {
|
|
381
|
-
let origin = scope ?? options.origin;
|
|
382
|
-
if (!origin) {
|
|
383
|
-
requireArguments(context, `barndog sets ${action} <scope>`);
|
|
384
|
-
origin = await chooseScope(action === "install"
|
|
385
|
-
? "Choose a scope to subscribe to"
|
|
386
|
-
: `Choose a subscription to ${action}`, (_, subscribed) => (action === "install" ? !subscribed : subscribed), action === "install"
|
|
387
|
-
? "You're already subscribed to every scope."
|
|
388
|
-
: "You have no subscriptions yet.");
|
|
389
|
-
}
|
|
390
|
-
return action === "install"
|
|
391
|
-
? runSetInstall(context, { ...options, origin })
|
|
392
|
-
: runSelection(context, `sets-${action}`, { ...options, origin });
|
|
393
|
-
});
|
|
394
|
-
}
|
|
395
|
-
const switchCommand = (name, hidden) => sets
|
|
396
|
-
.command(`${name} [scope]`, { hidden })
|
|
397
|
-
.description("Switch to another team or repository, replacing your current one of that type")
|
|
398
|
-
.addOption(new Option("--mode <mode>", "Which assets to include")
|
|
399
|
-
.choices(["recommended", "optional", "all"])
|
|
400
|
-
.default("recommended"))
|
|
401
|
-
.addOption(new Option("--overrides <choice>", "Keep or clear your existing exclusions").choices(["preserve", "clear"]))
|
|
402
|
-
.option("--decisions <file>", "JSON per-asset override choices")
|
|
403
|
-
.action(async (scope, options) => {
|
|
404
|
-
let origin = scope && name === "switch-team" && !scope.includes("/")
|
|
405
|
-
? `team/${scope}`
|
|
406
|
-
: scope;
|
|
407
|
-
if (!origin) {
|
|
408
|
-
requireArguments(context, "barndog sets switch <team/slug|repo/slug>");
|
|
409
|
-
origin = await chooseScope("Switch to", (candidate, subscribed) => !subscribed &&
|
|
410
|
-
(candidate.type === "team" || candidate.type === "repo"), "There is no other team or repository to switch to.");
|
|
411
|
-
}
|
|
412
|
-
await runSelection(context, "switch", { ...options, origin });
|
|
413
|
-
});
|
|
414
|
-
switchCommand("switch", false);
|
|
415
|
-
switchCommand("switch-team", true);
|
|
416
|
-
}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { openBrowser } from "../ui/auth.js";
|
|
2
|
+
import { ORIGIN_HELP } from "../ui/format.js";
|
|
3
|
+
import { Option } from "commander";
|
|
4
|
+
import { packageKindList } from "../config/selection.js";
|
|
5
|
+
import { positiveInteger } from "../ui/options.js";
|
|
6
|
+
import { CliError } from "../errors.js";
|
|
7
|
+
import { commandHelpers } from "./helpers.js";
|
|
8
|
+
/** `barndog github`: the GitHub App, connections, mirrors and pull requests. */
|
|
9
|
+
export function registerGithub(program, context) {
|
|
10
|
+
const { print } = commandHelpers(context);
|
|
11
|
+
const github = program
|
|
12
|
+
.command("github")
|
|
13
|
+
.description("Manage GitHub App connections, contributions and mirrors");
|
|
14
|
+
for (const [name, step, page] of [
|
|
15
|
+
["auth", "authorization", context.githubAuth],
|
|
16
|
+
["install", "App installation", context.githubInstall],
|
|
17
|
+
]) {
|
|
18
|
+
github
|
|
19
|
+
.command(name)
|
|
20
|
+
.option("--no-browser", "Print the URL without opening it")
|
|
21
|
+
.action(async (options) => {
|
|
22
|
+
const { url } = await page();
|
|
23
|
+
if (options.browser) {
|
|
24
|
+
// The message below still gives the URL when no browser opens.
|
|
25
|
+
await openBrowser(url).catch(() => undefined);
|
|
26
|
+
}
|
|
27
|
+
print({ message: `Complete GitHub ${step} in your browser: ${url}` });
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
for (const [name, read] of [
|
|
31
|
+
["status", context.githubStatus],
|
|
32
|
+
["installations", context.githubInstallations],
|
|
33
|
+
["list", context.githubList],
|
|
34
|
+
]) {
|
|
35
|
+
github.command(name).action(async () => print(await read()));
|
|
36
|
+
}
|
|
37
|
+
/** A command that names an asset and the GitHub repository it pairs with. */
|
|
38
|
+
const repositoryCommand = (name) => github
|
|
39
|
+
.command(`${name} <name>`)
|
|
40
|
+
.addOption(new Option("--kind <kind>", "Git-backed asset kind")
|
|
41
|
+
.choices(packageKindList)
|
|
42
|
+
.default("skill"))
|
|
43
|
+
.requiredOption("--origin <origin>", ORIGIN_HELP)
|
|
44
|
+
.requiredOption("--installation <id>", "BarnDog installation binding UUID")
|
|
45
|
+
.requiredOption("--repository <owner/name>", "Customer-selected GitHub repository");
|
|
46
|
+
repositoryCommand("connect")
|
|
47
|
+
.addOption(new Option("--mode <mode>", "mirror keeps BarnDog authoritative")
|
|
48
|
+
.choices(["connect", "transfer", "mirror"])
|
|
49
|
+
.default("connect"))
|
|
50
|
+
.option("--expected-version <id>", "Inspected BarnDog version ID")
|
|
51
|
+
.action(async (name, options) => print(await context.githubConnect({ ...options, name })));
|
|
52
|
+
repositoryCommand("import")
|
|
53
|
+
.addOption(new Option("--authority <authority>", "Copy into BarnDog or keep GitHub authoritative")
|
|
54
|
+
.choices(["barndog", "github"])
|
|
55
|
+
.default("github"))
|
|
56
|
+
.option("--key <key>", "Required for BarnDog-owned copies; retain for exact retries")
|
|
57
|
+
.action(async (name, { authority, key, ...target }) => {
|
|
58
|
+
if (authority === "github") {
|
|
59
|
+
return print(await context.githubImport({ ...target, name }));
|
|
60
|
+
}
|
|
61
|
+
if (!key) {
|
|
62
|
+
throw new CliError("Add --key <key>, and reuse the same key to retry exactly.");
|
|
63
|
+
}
|
|
64
|
+
print(await context.githubImportCopy({ ...target, name, key }));
|
|
65
|
+
});
|
|
66
|
+
github
|
|
67
|
+
.command("create-repository <name>")
|
|
68
|
+
.description("Create a GitHub repository and export published history")
|
|
69
|
+
.addOption(new Option("--kind <kind>", "Asset kind")
|
|
70
|
+
.choices(packageKindList)
|
|
71
|
+
.default("skill"))
|
|
72
|
+
.requiredOption("--origin <origin>", ORIGIN_HELP)
|
|
73
|
+
.requiredOption("--installation <id>", "BarnDog installation binding UUID")
|
|
74
|
+
.requiredOption("--repository <owner/name>", "New repository to create")
|
|
75
|
+
.requiredOption("--key <key>", "Stable key; retain for exact retries")
|
|
76
|
+
.requiredOption("--expected-version <id>", "Inspected BarnDog version")
|
|
77
|
+
.addOption(new Option("--mode <mode>", "Content authority after export")
|
|
78
|
+
.choices(["mirror", "transfer"])
|
|
79
|
+
.default("mirror"))
|
|
80
|
+
.addOption(new Option("--visibility <visibility>", "New repository visibility")
|
|
81
|
+
.choices(["private", "public"])
|
|
82
|
+
.default("private"))
|
|
83
|
+
.action(async (name, options) => print(await context.githubCreateRepository({ ...options, name })));
|
|
84
|
+
for (const [name, read] of [
|
|
85
|
+
["show", context.githubShow],
|
|
86
|
+
["sync", context.githubSync],
|
|
87
|
+
["remote-head", context.githubRemoteHead],
|
|
88
|
+
]) {
|
|
89
|
+
github
|
|
90
|
+
.command(`${name} <id>`)
|
|
91
|
+
.action(async (id) => print(await read(id)));
|
|
92
|
+
}
|
|
93
|
+
github
|
|
94
|
+
.command("resolve-mirror <id>")
|
|
95
|
+
.addOption(new Option("--action <action>", "Explicit divergence resolution")
|
|
96
|
+
.choices(["use-barndog", "use-mirror", "disconnect"])
|
|
97
|
+
.makeOptionMandatory())
|
|
98
|
+
.requiredOption("--expected-version <id>", "Inspected BarnDog version")
|
|
99
|
+
.requiredOption("--expected-remote <sha|absent>", "Inspected remote main SHA or absent")
|
|
100
|
+
.option("--key <key>", "Stable key for exact retries")
|
|
101
|
+
.action(async (id, { expectedRemote, ...options }) => print(await context.githubResolveMirror({
|
|
102
|
+
...options,
|
|
103
|
+
connectionId: id,
|
|
104
|
+
expectedRemoteCommit: expectedRemote === "absent" ? null : expectedRemote,
|
|
105
|
+
})));
|
|
106
|
+
const pulls = github
|
|
107
|
+
.command("pulls")
|
|
108
|
+
.description("Inspect and contribute to externally authoritative assets");
|
|
109
|
+
pulls
|
|
110
|
+
.command("list <id>")
|
|
111
|
+
.action(async (id) => print(await context.githubPullsList(id)));
|
|
112
|
+
pulls
|
|
113
|
+
.command("show <id> <number>")
|
|
114
|
+
.action(async (id, number) => print(await context.githubPullsShow(id, positiveInteger(number))));
|
|
115
|
+
pulls
|
|
116
|
+
.command("create <id>")
|
|
117
|
+
.requiredOption("--expected-commit <sha>", "Inspected canonical commit")
|
|
118
|
+
.requiredOption("--title <title>", "Pull request title")
|
|
119
|
+
.option("--directory <path>", "Complete editable package directory")
|
|
120
|
+
.option("--body <text>", "Pull request body")
|
|
121
|
+
.option("--body-file <path>", "Pull request body file")
|
|
122
|
+
.option("--key <key>", "Stable key for exact retries")
|
|
123
|
+
.action(async (id, options) => print(await context.githubPullsCreate({ ...options, connectionId: id })));
|
|
124
|
+
pulls
|
|
125
|
+
.command("revise <id> <number>")
|
|
126
|
+
.requiredOption("--expected-commit <sha>", "Inspected pull head commit")
|
|
127
|
+
.option("--title <title>", "Updated title")
|
|
128
|
+
.option("--directory <path>", "Complete package directory")
|
|
129
|
+
.option("--body <text>", "Updated body")
|
|
130
|
+
.option("--body-file <file>", "Updated body file")
|
|
131
|
+
.option("--key <key>", "Stable key for exact retries")
|
|
132
|
+
.action(async (id, number, options) => print(await context.githubPullsRevise({
|
|
133
|
+
...options,
|
|
134
|
+
connectionId: id,
|
|
135
|
+
number: positiveInteger(number),
|
|
136
|
+
})));
|
|
137
|
+
/** A command on one pull request, pinned to the commit that was inspected. */
|
|
138
|
+
const pullCommand = (name) => pulls
|
|
139
|
+
.command(`${name} <id> <number>`)
|
|
140
|
+
.requiredOption("--expected-commit <sha>", "Inspected pull head commit");
|
|
141
|
+
const bodyOptions = (command) => command
|
|
142
|
+
.option("--body <text>", "Review or comment")
|
|
143
|
+
.option("--body-file <file>", "Review or comment file");
|
|
144
|
+
bodyOptions(pullCommand("review"))
|
|
145
|
+
.addOption(new Option("--event <event>", "Review decision")
|
|
146
|
+
.choices(["APPROVE", "REQUEST_CHANGES", "COMMENT"])
|
|
147
|
+
.makeOptionMandatory())
|
|
148
|
+
.action(async (id, number, options) => print(await context.githubPullsReview({
|
|
149
|
+
...options,
|
|
150
|
+
connectionId: id,
|
|
151
|
+
number: positiveInteger(number),
|
|
152
|
+
})));
|
|
153
|
+
bodyOptions(pullCommand("comment"))
|
|
154
|
+
.option("--path <file>", "Inline file")
|
|
155
|
+
.option("--line <number>", "Inline line", positiveInteger)
|
|
156
|
+
.addOption(new Option("--side <side>", "Inline diff side").choices([
|
|
157
|
+
"LEFT",
|
|
158
|
+
"RIGHT",
|
|
159
|
+
]))
|
|
160
|
+
.action(async (id, number, options) => print(await context.githubPullsComment({
|
|
161
|
+
...options,
|
|
162
|
+
connectionId: id,
|
|
163
|
+
number: positiveInteger(number),
|
|
164
|
+
})));
|
|
165
|
+
pullCommand("merge").action(async (id, number, options) => print(await context.githubPullsMerge({
|
|
166
|
+
...options,
|
|
167
|
+
connectionId: id,
|
|
168
|
+
number: positiveInteger(number),
|
|
169
|
+
})));
|
|
170
|
+
const describe = (parent, descriptions) => {
|
|
171
|
+
for (const command of parent.commands) {
|
|
172
|
+
const description = descriptions[command.name()];
|
|
173
|
+
if (!command.description() && description) {
|
|
174
|
+
command.description(description);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
describe(github, {
|
|
179
|
+
auth: "Link your GitHub account to BarnDog",
|
|
180
|
+
install: "Install the BarnDog GitHub App on an account or organization",
|
|
181
|
+
status: "Show your GitHub account and App connection",
|
|
182
|
+
installations: "List GitHub App installations you can use",
|
|
183
|
+
list: "List Skills and Hooks connected to GitHub repositories",
|
|
184
|
+
connect: "Connect a Skill or Hook to a GitHub repository",
|
|
185
|
+
import: "Import a Skill or Hook from a GitHub repository",
|
|
186
|
+
show: "Show a GitHub connection",
|
|
187
|
+
sync: "Sync a connection with its repository now",
|
|
188
|
+
"remote-head": "Show the repository's current main commit",
|
|
189
|
+
"resolve-mirror": "Resolve a mirror that diverged from BarnDog",
|
|
190
|
+
});
|
|
191
|
+
describe(pulls, {
|
|
192
|
+
list: "List pull requests for a connected asset",
|
|
193
|
+
show: "Show a pull request",
|
|
194
|
+
create: "Open a pull request with your edits",
|
|
195
|
+
revise: "Update an open pull request",
|
|
196
|
+
review: "Approve or request changes on a pull request",
|
|
197
|
+
comment: "Comment on a pull request",
|
|
198
|
+
merge: "Merge a pull request",
|
|
199
|
+
});
|
|
200
|
+
}
|