barndog 0.1.1 → 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 +31 -28
- package/dist/cli.js +11 -7
- package/dist/commands/add.js +34 -21
- package/dist/commands/adopt.js +91 -0
- package/dist/commands/arguments.js +12 -0
- package/dist/commands/asset-install.js +161 -0
- package/dist/commands/asset-list.js +126 -0
- package/dist/commands/asset-share.js +94 -0
- package/dist/commands/auth.js +4 -0
- package/dist/commands/availability.js +72 -27
- package/dist/commands/capabilities.js +79 -417
- package/dist/commands/collaboration.js +212 -108
- package/dist/commands/environment.js +18 -411
- package/dist/commands/github.js +200 -0
- package/dist/commands/harnesses.js +74 -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-env.js +78 -0
- package/dist/commands/mcp.js +64 -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 +36 -25
- package/dist/commands/sync.js +13 -5
- package/dist/commands/workspace.js +75 -23
- package/dist/config/environment.js +13 -27
- package/dist/config/paths.js +81 -0
- package/dist/config/selection.js +30 -0
- package/dist/config/settings.js +99 -108
- package/dist/config/state.js +67 -55
- 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/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 +129 -0
- package/dist/features/asset-selection/index.js +51 -19
- package/dist/features/auth/credentials.js +80 -54
- package/dist/features/auth/session.js +83 -49
- package/dist/features/auth/transport.js +69 -17
- 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 +242 -152
- package/dist/features/collaboration/workspace-github.js +118 -54
- package/dist/features/collaboration/workspace-store.js +157 -97
- package/dist/features/collaboration/workspace.js +278 -173
- package/dist/features/discovery/index.js +68 -57
- package/dist/features/doctor/index.js +56 -26
- package/dist/features/environment/auto-sync.js +28 -27
- package/dist/features/environment/harnesses.js +36 -0
- package/dist/features/environment/moves.js +171 -0
- package/dist/features/environment/names.js +73 -49
- package/dist/features/environment/operations.js +322 -229
- package/dist/features/environment/own-entries.js +89 -0
- package/dist/features/environment/settle-names.js +91 -0
- package/dist/features/environment/stage.js +202 -0
- package/dist/features/environment/sync.js +127 -487
- package/dist/features/environment/transaction.js +179 -147
- package/dist/features/environment/writes.js +243 -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 +55 -0
- package/dist/features/hooks/divergence.js +36 -12
- package/dist/features/hooks/test.js +91 -66
- package/dist/features/hooks/types.js +1 -0
- package/dist/features/imports/discover.js +133 -60
- package/dist/features/imports/folder.js +48 -14
- package/dist/features/imports/local.js +127 -135
- package/dist/features/imports/remote.js +46 -26
- package/dist/features/inspection/index.js +17 -17
- package/dist/features/inventory/index.js +111 -111
- package/dist/features/inventory/show.js +74 -0
- package/dist/features/knowledge/index.js +69 -49
- package/dist/features/mcps/catalog.js +31 -0
- package/dist/features/mcps/import.js +369 -0
- package/dist/features/mcps/index.js +104 -50
- package/dist/features/mcps/values.js +33 -0
- package/dist/features/migration/migrate.js +263 -0
- package/dist/features/migration/move.js +448 -0
- package/dist/features/migration/promote.js +26 -0
- package/dist/features/native/adapters.js +69 -96
- package/dist/features/native/configuration.js +134 -84
- package/dist/features/native/hook-shell.js +55 -0
- package/dist/features/native/plugin-module.js +56 -0
- package/dist/features/native/secret-values.js +74 -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/secrets/index.js +77 -0
- 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 +121 -54
- package/dist/features/workspace/git.js +221 -0
- package/dist/features/workspace/installed.js +92 -0
- package/dist/features/{git-workspace → workspace}/overlay.js +53 -46
- package/dist/features/workspace/packages.js +173 -0
- package/dist/features/{git-workspace → workspace}/publish.js +120 -64
- package/dist/features/workspace/repo-source.js +193 -0
- package/dist/features/{git-workspace → workspace}/setup.js +72 -45
- package/dist/features/{git-workspace → workspace}/snapshot.js +60 -19
- 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 +67 -1
- package/dist/harnesses/cursor.js +22 -1
- package/dist/harnesses/detect.js +6 -50
- package/dist/harnesses/formats.js +52 -0
- package/dist/harnesses/opencode.js +108 -0
- package/dist/harnesses/registry.js +35 -2
- package/dist/platform.js +403 -0
- package/dist/program.js +275 -56
- 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 +107 -0
- package/dist/shared/lock.js +113 -0
- package/dist/shared/lookup.js +11 -0
- package/dist/shared/patterns.js +102 -0
- package/dist/shared/shell.js +20 -0
- package/dist/shared/values.js +26 -0
- package/dist/ui/add-asset.js +41 -400
- package/dist/ui/add-hook.js +219 -0
- package/dist/ui/add-mcp.js +170 -0
- package/dist/ui/add-prompts.js +47 -0
- package/dist/ui/add-skills.js +117 -0
- package/dist/ui/adopt.js +197 -0
- package/dist/ui/asset-list.js +31 -13
- package/dist/ui/assets.js +38 -47
- package/dist/ui/auth.js +45 -34
- package/dist/ui/clash.js +10 -6
- package/dist/ui/collaboration.js +116 -44
- package/dist/ui/connection.js +17 -6
- 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/harness-picker.js +18 -0
- package/dist/ui/hook-compatibility.js +14 -6
- package/dist/ui/mcp.js +28 -3
- package/dist/ui/move.js +57 -6
- package/dist/ui/onboarding.js +148 -95
- package/dist/ui/options.js +9 -0
- package/dist/ui/output.js +108 -43
- package/dist/ui/package-details.js +34 -0
- package/dist/ui/pick.js +45 -33
- package/dist/ui/scope-install.js +18 -7
- package/dist/ui/secret-input.js +19 -0
- package/dist/ui/selection.js +17 -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/move.js +0 -337
- 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
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { friendlyMessage } from "../errors.js";
|
|
2
|
+
import { assetListOptions, pageOptions, filterAssets, } from "../ui/asset-list.js";
|
|
3
|
+
import { assetListing, inventoryHints, renderCatalog, renderInventory, } from "../ui/assets.js";
|
|
4
|
+
import { dim, hint, json } from "../ui/format.js";
|
|
5
|
+
import { assetKinds } from "../features/asset-kinds/index.js";
|
|
6
|
+
import { addArguments } from "./arguments.js";
|
|
7
|
+
/** `list`: installed, disabled and available assets of one kind. */
|
|
8
|
+
export function registerList(command, kind, context) {
|
|
9
|
+
const labels = assetKinds[kind];
|
|
10
|
+
const group = assetKinds[kind].command;
|
|
11
|
+
const addCommand = `barndog ${assetKinds[kind].command} add${addArguments[kind]}`;
|
|
12
|
+
const listCommand = command
|
|
13
|
+
.command("list")
|
|
14
|
+
.description(`List installed, disabled and available ${labels.many}`);
|
|
15
|
+
pageOptions(listCommand)
|
|
16
|
+
.option("--installed", `Only ${labels.many} installed on this machine`)
|
|
17
|
+
.option("--disabled", `Only ${labels.many} you've disabled`)
|
|
18
|
+
.option("--available", `Only ${labels.many} you can install`)
|
|
19
|
+
.option("--paths", "Show installed folders and configuration files")
|
|
20
|
+
.action(async (options) => {
|
|
21
|
+
const narrowed = options.installed || options.disabled;
|
|
22
|
+
const onlyAvailable = options.available && !narrowed;
|
|
23
|
+
let catalogProblem;
|
|
24
|
+
const [inventory, rows] = await Promise.all([
|
|
25
|
+
context.inventory(),
|
|
26
|
+
options.available || !narrowed
|
|
27
|
+
? context.searchCatalog(kind).catch((error) => {
|
|
28
|
+
// JSON has nowhere to say the list is partial, so it fails;
|
|
29
|
+
// --installed and --disabled don't need the catalog.
|
|
30
|
+
if (onlyAvailable || context.mode.json) {
|
|
31
|
+
throw error;
|
|
32
|
+
}
|
|
33
|
+
catalogProblem = friendlyMessage(error);
|
|
34
|
+
return [];
|
|
35
|
+
})
|
|
36
|
+
: [],
|
|
37
|
+
]);
|
|
38
|
+
const items = inventory.items.filter((item) => item.kind === kind);
|
|
39
|
+
const listing = assetListing(items, rows, options);
|
|
40
|
+
if (context.mode.json) {
|
|
41
|
+
return context.write(json(listing));
|
|
42
|
+
}
|
|
43
|
+
if (inventory.offline) {
|
|
44
|
+
context.write(dim(`Showing local state only: ${inventory.offline}`));
|
|
45
|
+
}
|
|
46
|
+
else if (catalogProblem) {
|
|
47
|
+
context.write(dim(`Couldn't load available ${labels.many}: ${catalogProblem}`));
|
|
48
|
+
}
|
|
49
|
+
if (!listing.length) {
|
|
50
|
+
if (narrowed) {
|
|
51
|
+
context.write(`No ${labels.many} match that filter.`);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (catalogProblem || inventory.offline) {
|
|
55
|
+
context.write(`No ${labels.many} on this machine yet.`);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
context.write(`No ${labels.many} yet.`);
|
|
59
|
+
context.write(hint(addCommand, "Next"));
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const start = (options.page - 1) * options.limit;
|
|
63
|
+
const page = listing.slice(start, start + options.limit);
|
|
64
|
+
if (!page.length) {
|
|
65
|
+
context.write(`Page ${options.page} is empty. Choose a page from 1 to ${Math.ceil(listing.length / options.limit)}.`);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
for (const line of renderInventory(page, {
|
|
69
|
+
...options,
|
|
70
|
+
runtime: context.runtime,
|
|
71
|
+
})) {
|
|
72
|
+
context.write(line);
|
|
73
|
+
}
|
|
74
|
+
if (listing.length > options.limit) {
|
|
75
|
+
const flags = ["installed", "disabled", "available"]
|
|
76
|
+
.filter((flag) => options[flag])
|
|
77
|
+
.map((flag) => ` --${flag}`)
|
|
78
|
+
.join("");
|
|
79
|
+
context.write("\n" +
|
|
80
|
+
dim(`Showing ${start + 1}–${start + page.length} of ${listing.length}`));
|
|
81
|
+
if (start + page.length < listing.length) {
|
|
82
|
+
context.write(hint(`barndog ${group} list${flags} --page ${options.page + 1}`, "Next"));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
const onThisMachine = page.filter((item) => item.state !== "available");
|
|
86
|
+
const hints = inventoryHints(onThisMachine);
|
|
87
|
+
if (hints.length) {
|
|
88
|
+
context.write(["", ...hints].join("\n"));
|
|
89
|
+
}
|
|
90
|
+
else if (!options.paths && onThisMachine.length) {
|
|
91
|
+
context.write("\n" +
|
|
92
|
+
hint(`barndog ${group} list --paths`, "Tip") +
|
|
93
|
+
dim(" to see where each one lives"));
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
/** `search`: the kind's published catalog, filtered locally. */
|
|
98
|
+
export function registerSearch(command, kind, context) {
|
|
99
|
+
const labels = assetKinds[kind];
|
|
100
|
+
const group = assetKinds[kind].command;
|
|
101
|
+
const search = async (assetKind, query, options) => {
|
|
102
|
+
const [rows, inventory] = await Promise.all([
|
|
103
|
+
context.searchCatalog(assetKind),
|
|
104
|
+
context.inventory().catch(() => undefined),
|
|
105
|
+
]);
|
|
106
|
+
const selected = new Set(inventory?.items
|
|
107
|
+
.filter((item) => item.state !== "removing")
|
|
108
|
+
.map((item) => item.id) ?? []);
|
|
109
|
+
// JSON gets the same matches the table shows, all pages at once.
|
|
110
|
+
if (context.mode.json) {
|
|
111
|
+
return context.write(json(filterAssets(rows, { ...options, search: query }).map((row) => ({
|
|
112
|
+
...row,
|
|
113
|
+
selected: selected.has(row.id),
|
|
114
|
+
}))));
|
|
115
|
+
}
|
|
116
|
+
for (const line of renderCatalog(rows, { ...options, search: query }, {
|
|
117
|
+
command: `barndog ${group} search`,
|
|
118
|
+
platform: context.runtime.platform,
|
|
119
|
+
}, selected)) {
|
|
120
|
+
context.write(line);
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
assetListOptions(command
|
|
124
|
+
.command("search [query]")
|
|
125
|
+
.description(`Browse ${labels.many} published in your workspace`), false).action((query, options) => search(kind, query ?? options.search, options));
|
|
126
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { renderMove } from "../ui/move.js";
|
|
2
|
+
import input from "@inquirer/input";
|
|
3
|
+
import { CliError } from "../errors.js";
|
|
4
|
+
import { pickOne } from "../ui/pick.js";
|
|
5
|
+
import { promptTheme } from "../ui/theme.js";
|
|
6
|
+
import { bold, clean, hint, json, ok, ORIGIN_HELP, originLabel, } from "../ui/format.js";
|
|
7
|
+
import { assetKinds } from "../features/asset-kinds/index.js";
|
|
8
|
+
import { requireArguments } from "./arguments.js";
|
|
9
|
+
/** Asks for a value in a terminal, or explains the flag to pass. */
|
|
10
|
+
export async function ask(context, value, { message, flag, fallback, }) {
|
|
11
|
+
if (value) {
|
|
12
|
+
return value;
|
|
13
|
+
}
|
|
14
|
+
if (!context.mode.interactive) {
|
|
15
|
+
throw new CliError(`Add ${flag} <value> to this command, or run it in a terminal to be asked.`);
|
|
16
|
+
}
|
|
17
|
+
return (await input({ message, default: fallback, theme: promptTheme })).trim();
|
|
18
|
+
}
|
|
19
|
+
/** `fork` and `promote`: copies an asset into another scope. */
|
|
20
|
+
export function registerSharing(command, kind, context) {
|
|
21
|
+
const labels = assetKinds[kind];
|
|
22
|
+
const group = assetKinds[kind].command;
|
|
23
|
+
for (const action of ["fork", "promote"]) {
|
|
24
|
+
command
|
|
25
|
+
.command(`${action} [name]`)
|
|
26
|
+
.description(action === "fork"
|
|
27
|
+
? `Copy ${labels.a} into a scope you own, such as your personal space`
|
|
28
|
+
: `Propose ${labels.a} for a team, repository or the organization`)
|
|
29
|
+
.option("--origin <origin>", ORIGIN_HELP)
|
|
30
|
+
.option("--target <origin>", "Destination scope, such as me, team/engineering or org")
|
|
31
|
+
.option("--name <newName>", "Name of the new asset")
|
|
32
|
+
.option("--key <key>", "Stable key for exact retries")
|
|
33
|
+
.action(async (name, options) => {
|
|
34
|
+
let origin = options.origin;
|
|
35
|
+
if (!name) {
|
|
36
|
+
requireArguments(context, `barndog ${group} ${action} <name> --origin <origin> --target <origin> --name <new-name>`);
|
|
37
|
+
const row = await pickOne(`Choose ${labels.a} to ${action}`, (await context.searchCatalog(kind)).map((row) => ({
|
|
38
|
+
value: row,
|
|
39
|
+
name: row.name,
|
|
40
|
+
hint: `${originLabel(row.origin)} · ${clean(row.version.description)}`,
|
|
41
|
+
})));
|
|
42
|
+
name = row.name;
|
|
43
|
+
origin = originLabel(row.origin);
|
|
44
|
+
}
|
|
45
|
+
origin = await ask(context, origin, {
|
|
46
|
+
message: "Current scope",
|
|
47
|
+
flag: "--origin",
|
|
48
|
+
});
|
|
49
|
+
const target = await ask(context, options.target, {
|
|
50
|
+
message: "Destination scope (me, team/<slug>, repo/<slug> or org)",
|
|
51
|
+
flag: "--target",
|
|
52
|
+
fallback: action === "fork" ? "me" : undefined,
|
|
53
|
+
});
|
|
54
|
+
const newName = await ask(context, options.name, {
|
|
55
|
+
message: "New name",
|
|
56
|
+
flag: "--name",
|
|
57
|
+
fallback: name,
|
|
58
|
+
});
|
|
59
|
+
const input = {
|
|
60
|
+
kind,
|
|
61
|
+
name,
|
|
62
|
+
origin,
|
|
63
|
+
target,
|
|
64
|
+
newName,
|
|
65
|
+
key: options.key,
|
|
66
|
+
};
|
|
67
|
+
const outcome = action === "fork"
|
|
68
|
+
? {
|
|
69
|
+
outcome: "promoted",
|
|
70
|
+
promotion: await context.fork(input),
|
|
71
|
+
}
|
|
72
|
+
: await context.promote(input);
|
|
73
|
+
if (outcome.outcome === "moved") {
|
|
74
|
+
if (context.mode.json) {
|
|
75
|
+
return context.write(json(outcome.move));
|
|
76
|
+
}
|
|
77
|
+
for (const line of renderMove(outcome.move)) {
|
|
78
|
+
context.write(line);
|
|
79
|
+
}
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const result = outcome.promotion;
|
|
83
|
+
if (context.mode.json) {
|
|
84
|
+
return context.write(json(result));
|
|
85
|
+
}
|
|
86
|
+
context.write(result.changeId
|
|
87
|
+
? `${ok("✔")} Proposed ${bold(newName)} for ${target}. A reviewer must merge the Suggested Change.`
|
|
88
|
+
: `${ok("✔")} Created ${bold(newName)} in ${target}.`);
|
|
89
|
+
context.write(result.changeId
|
|
90
|
+
? hint(`barndog ${group} changes show ${result.changeId}`)
|
|
91
|
+
: hint(`barndog ${group} install ${newName} --origin ${target === "me" ? "me" : target}`));
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
}
|
package/dist/commands/auth.js
CHANGED
|
@@ -1,41 +1,74 @@
|
|
|
1
|
-
import { homedir } from "node:os";
|
|
2
1
|
import { readSettings } from "../config/settings.js";
|
|
3
2
|
import { CliError } from "../errors.js";
|
|
4
3
|
import { readCredentials } from "../features/auth/credentials.js";
|
|
5
|
-
import { LOCAL_ORIGIN } from "../features/
|
|
6
|
-
|
|
4
|
+
import { LOCAL_ORIGIN } from "../features/workspace/overlay.js";
|
|
5
|
+
/** Every `skills changes …` and `hooks changes …` command. */
|
|
6
|
+
const CHANGES_COMMANDS = /^(?:skills|hooks) changes(?: |$)/;
|
|
7
|
+
/**
|
|
8
|
+
* Commands that need a BarnDog server, matched against the command's words
|
|
9
|
+
* without the program name: `auth status`, `skills fork`, `github pulls list`.
|
|
10
|
+
* `src/tests/patterns.test.ts` checks that each still matches a real command.
|
|
11
|
+
*
|
|
12
|
+
* @internal Exported for its table test in `src/tests/patterns.test.ts`.
|
|
13
|
+
*/
|
|
14
|
+
export const cloudOnlyCommands = [
|
|
7
15
|
/^login$/,
|
|
8
16
|
/^auth status$/,
|
|
9
17
|
/^whoami$/,
|
|
10
18
|
/^open$/,
|
|
11
|
-
/^people( |$)/,
|
|
12
|
-
/^github( |$)/,
|
|
13
|
-
|
|
14
|
-
/^(skills|mcp|hooks) (fork|promote)$/,
|
|
15
|
-
/^mcp (create|update)$/,
|
|
19
|
+
/^people(?: |$)/,
|
|
20
|
+
/^github(?: |$)/,
|
|
21
|
+
CHANGES_COMMANDS,
|
|
22
|
+
/^(?:skills|mcp|hooks) (?:fork|promote)$/,
|
|
23
|
+
/^mcp (?:create|update)$/,
|
|
16
24
|
];
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
/^(
|
|
25
|
+
/** Commands that need published versions and reviews, which a local folder lacks. */
|
|
26
|
+
const reviewCommands = [
|
|
27
|
+
/^(?:pull|push|resolve)$/,
|
|
28
|
+
/^(?:skills|hooks) (?:pull|push|create|versions|diff)$/,
|
|
20
29
|
/^mcp versions$/,
|
|
21
30
|
];
|
|
31
|
+
/** Every `knowledge …` command. */
|
|
32
|
+
const KNOWLEDGE_COMMANDS = /^knowledge(?: |$)/;
|
|
33
|
+
/**
|
|
34
|
+
* Commands a local folder can't serve yet: nothing adds knowledge documents to
|
|
35
|
+
* it, so they need a Git repo or Cloud Workspace.
|
|
36
|
+
*
|
|
37
|
+
* @internal Exported for its table test in `src/tests/patterns.test.ts`.
|
|
38
|
+
*/
|
|
39
|
+
export const sharedSourceCommands = [...reviewCommands, KNOWLEDGE_COMMANDS];
|
|
22
40
|
/** The setup this machine runs on, when that setup limits what commands can do. */
|
|
23
|
-
export async function currentSetupMode(
|
|
41
|
+
export async function currentSetupMode(runtime) {
|
|
42
|
+
const { home } = runtime;
|
|
24
43
|
const settings = await readSettings(home).catch(() => null);
|
|
25
|
-
if (settings
|
|
44
|
+
if (!settings || settings.connection) {
|
|
26
45
|
return undefined;
|
|
27
|
-
|
|
46
|
+
}
|
|
47
|
+
if (settings.gitWorkspace) {
|
|
28
48
|
return "git";
|
|
49
|
+
}
|
|
29
50
|
return settings.localWorkspace ? "local" : undefined;
|
|
30
51
|
}
|
|
31
52
|
/** What a command needs that this setup lacks; undefined when it can run. */
|
|
32
53
|
export function commandNeeds(command, mode) {
|
|
33
|
-
if (
|
|
54
|
+
if (cloudOnlyCommands.some((pattern) => pattern.test(command))) {
|
|
34
55
|
return "cloud";
|
|
35
|
-
|
|
56
|
+
}
|
|
57
|
+
if (mode === "local" &&
|
|
58
|
+
sharedSourceCommands.some((pattern) => pattern.test(command))) {
|
|
36
59
|
return "shared";
|
|
60
|
+
}
|
|
37
61
|
return undefined;
|
|
38
62
|
}
|
|
63
|
+
/** Like `commandNeeds()`, for a command line whose options can change what it needs. */
|
|
64
|
+
function setupNeeds(command, options, mode) {
|
|
65
|
+
// `show` describes any asset; only a published version's files need shared versions.
|
|
66
|
+
const showsFiles = ["skills show", "hooks show"].includes(command) &&
|
|
67
|
+
(options.files === true || options.version !== undefined);
|
|
68
|
+
return mode === "local" && showsFiles
|
|
69
|
+
? "shared"
|
|
70
|
+
: commandNeeds(command, mode);
|
|
71
|
+
}
|
|
39
72
|
export const needText = (need) => need === "cloud" ? "a Cloud Workspace" : "a Git repo or Cloud Workspace";
|
|
40
73
|
export const modeName = (mode) => mode === "local" ? "local" : "Git";
|
|
41
74
|
/** Help's note beside a command this setup can't run. */
|
|
@@ -47,41 +80,53 @@ const why = {
|
|
|
47
80
|
open: "opens the BarnDog Cloud Workspace in your browser",
|
|
48
81
|
};
|
|
49
82
|
/** Stops commands the current setup can't run, before they prompt or reach a server. */
|
|
50
|
-
export async function assertCommandAvailable(path, options
|
|
83
|
+
export async function assertCommandAvailable(path, options, runtime) {
|
|
84
|
+
const { home } = runtime;
|
|
51
85
|
const settings = await readSettings(home).catch(() => null);
|
|
52
86
|
if (path.join(" ") === "logout" && !settings) {
|
|
53
|
-
if (!(await readCredentials(
|
|
87
|
+
if (!(await readCredentials(runtime)).selectedServer) {
|
|
54
88
|
throw new CliError("You aren't signed in.");
|
|
89
|
+
}
|
|
55
90
|
return;
|
|
56
91
|
}
|
|
57
|
-
if (settings
|
|
92
|
+
if (!settings || settings.connection) {
|
|
58
93
|
return;
|
|
94
|
+
}
|
|
59
95
|
const git = settings.gitWorkspace;
|
|
60
96
|
const folder = settings.localWorkspace?.path;
|
|
61
|
-
if (!git && !folder)
|
|
97
|
+
if (!git && !folder) {
|
|
62
98
|
return;
|
|
99
|
+
}
|
|
63
100
|
const command = path.join(" ");
|
|
64
101
|
const where = git
|
|
65
102
|
? `a Git repo (${git.url})`
|
|
66
103
|
: `a folder on this machine (${folder})`;
|
|
67
104
|
if (command === "logout") {
|
|
68
|
-
const { selectedServer } = await readCredentials(
|
|
69
|
-
if (!selectedServer)
|
|
105
|
+
const { selectedServer } = await readCredentials(runtime);
|
|
106
|
+
if (!selectedServer) {
|
|
70
107
|
throw new CliError(`You aren't signed in. This machine keeps its assets in ${where}, so it doesn't need a sign-in.`);
|
|
108
|
+
}
|
|
71
109
|
return;
|
|
72
110
|
}
|
|
73
|
-
if (git &&
|
|
111
|
+
if (git && CHANGES_COMMANDS.test(command)) {
|
|
74
112
|
throw new CliError(`Reviews happen as pull requests on your Git host, because this machine keeps its assets in ${where}.`, "barndog status");
|
|
113
|
+
}
|
|
75
114
|
// An explicit server is how local assets get promoted without switching.
|
|
76
|
-
if (command === "login" && options.server)
|
|
115
|
+
if (command === "login" && options.server) {
|
|
77
116
|
return;
|
|
78
|
-
|
|
117
|
+
}
|
|
118
|
+
if (command.endsWith(" promote") && options.origin === LOCAL_ORIGIN) {
|
|
79
119
|
return;
|
|
80
|
-
|
|
120
|
+
}
|
|
121
|
+
const needs = setupNeeds(command, options, git ? "git" : "local");
|
|
81
122
|
if (needs === "cloud") {
|
|
82
123
|
const action = why[command] ?? "needs a BarnDog Cloud Workspace";
|
|
83
124
|
throw new CliError(`\`barndog ${command}\` ${action}, but this machine keeps its assets in ${where}.${git ? "" : " Your local assets stay active if you switch."}`, "barndog init --server <url>");
|
|
84
125
|
}
|
|
85
|
-
if (needs === "shared")
|
|
126
|
+
if (needs === "shared" && KNOWLEDGE_COMMANDS.test(command)) {
|
|
127
|
+
throw new CliError(`\`barndog ${command}\` reads shared knowledge documents, which a local folder can't hold yet.`, "barndog init");
|
|
128
|
+
}
|
|
129
|
+
if (needs === "shared") {
|
|
86
130
|
throw new CliError(`\`barndog ${command}\` works with shared versions and reviews, which assets in a local folder don't have. Edit them directly in ${folder}, then sync.`, "barndog sync");
|
|
131
|
+
}
|
|
87
132
|
}
|