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
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# BarnDog CLI
|
|
2
2
|
|
|
3
|
-
Set up your team's AI coding environment once, and have it show up in every developer's Claude Code, Codex, or any other coding harness.
|
|
3
|
+
Set up your and your team's AI coding environment once, and have it show up in every developer's Claude Code, Codex, or any other coding harness.
|
|
4
4
|
|
|
5
5
|
`barndog` is the command-line tool for [BarnDog](https://barndog.dev). It installs your organization's shared Skills, MCP servers, Hooks, and knowledge into the coding agents your developers already use, keeps them up to date, and lets the team improve them together with review, like code.
|
|
6
6
|
|
|
@@ -9,6 +9,7 @@ Currently supported harnesses:
|
|
|
9
9
|
- Claude Code
|
|
10
10
|
- Codex
|
|
11
11
|
- Cursor
|
|
12
|
+
- OpenCode (Skills, MCP servers and knowledge; it has no command hooks, so Hooks don't apply)
|
|
12
13
|
|
|
13
14
|
## Why
|
|
14
15
|
|
|
@@ -20,13 +21,13 @@ BarnDog keeps one shared setup and writes it into each tool in that tool's own f
|
|
|
20
21
|
|
|
21
22
|
```mermaid
|
|
22
23
|
flowchart LR
|
|
23
|
-
W["Your workspace<br/>BarnDog
|
|
24
|
+
W["Your workspace<br/>BarnDog Cloud, a Git repo,<br/>or a local folder"] -->|barndog sync| C["barndog CLI"]
|
|
24
25
|
C --> CC[Claude Code]
|
|
25
26
|
C --> CX[Codex]
|
|
26
27
|
C --> CU[Other harnesses]
|
|
27
28
|
```
|
|
28
29
|
|
|
29
|
-
1. **Connect to a workspace.** `barndog init` signs you in to a BarnDog server, or points at a Git repository or local folder that holds your team's assets.
|
|
30
|
+
1. **Connect to a workspace.** `barndog init` signs you in to a BarnDog server, or points at a Git repository or local folder that holds your or your team's assets.
|
|
30
31
|
2. **Choose what you want.** Pick your coding tools, then the sets you need: the whole organization, your team, the repositories you work in, plus any individual assets.
|
|
31
32
|
3. **Sync.** `barndog sync` writes everything into each tool's native location. It runs again automatically when a coding session starts, so updates arrive without anyone thinking about it.
|
|
32
33
|
4. **Improve together.** Pull an asset into a folder, edit it, and `barndog push` a Suggested Change. Teammates review it line by line, and once it's merged everyone gets the new version on their next sync.
|
|
@@ -42,7 +43,7 @@ flowchart LR
|
|
|
42
43
|
|
|
43
44
|
## Install
|
|
44
45
|
|
|
45
|
-
|
|
46
|
+
Runs on **macOS, Linux, and Windows** with [Node.js](https://nodejs.org) 24 or newer.
|
|
46
47
|
|
|
47
48
|
```sh
|
|
48
49
|
npm install -g barndog
|
|
@@ -51,7 +52,7 @@ npm install -g barndog
|
|
|
51
52
|
## Quick start
|
|
52
53
|
|
|
53
54
|
```sh
|
|
54
|
-
barndog init # connect, sign in, choose tools and sets
|
|
55
|
+
barndog init # connect, optionally sign in, choose tools and sets
|
|
55
56
|
barndog status # what's installed on this machine, and where
|
|
56
57
|
barndog skills search review # browse the shared catalog
|
|
57
58
|
barndog skills install code-review # add one asset on top of your sets
|
|
@@ -69,7 +70,7 @@ You can share assets through any Git repository, using your own Git credentials.
|
|
|
69
70
|
barndog init --repo git@github.com:acme/ai-setup.git
|
|
70
71
|
```
|
|
71
72
|
|
|
72
|
-
Or keep them in a folder on your machine with `barndog init --local`. See [Git workspaces](https://barndog.dev/docs/cli/git-workspaces) for the layout.
|
|
73
|
+
Or keep them in a folder on your machine with `barndog init --local`. See [Git workspaces](https://barndog.dev/docs/cli/git-workspaces#local-workspaces) for the layout.
|
|
73
74
|
|
|
74
75
|
### Suggest a change
|
|
75
76
|
|
|
@@ -81,7 +82,7 @@ barndog diff
|
|
|
81
82
|
barndog push --title "Add a security checklist"
|
|
82
83
|
```
|
|
83
84
|
|
|
84
|
-
Reviewers use `barndog changes list`, `changes diff`, and `changes approve` from the terminal, or the BarnDog web workspace.
|
|
85
|
+
Reviewers use `barndog skills changes list`, `changes diff`, and `changes approve` (or the same under `barndog hooks`) from the terminal, or GitHub repo, or the BarnDog web workspace.
|
|
85
86
|
|
|
86
87
|
## What it changes on your machine
|
|
87
88
|
|
package/dist/cli.js
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { CommanderError, InvalidArgumentError } from "commander";
|
|
3
3
|
import { assertCommandAvailable, currentSetupMode, } from "./commands/availability.js";
|
|
4
|
-
import { createProgram } from "./program.js";
|
|
4
|
+
import { captureRuntime, createProgram } from "./program.js";
|
|
5
5
|
import { renderError, renderJsonError } from "./ui/output.js";
|
|
6
6
|
import { json } from "./ui/format.js";
|
|
7
|
-
import { NothingToDoError } from "./errors.js";
|
|
7
|
+
import { CliError, NothingToDoError } from "./errors.js";
|
|
8
8
|
// Parsing errors happen before any action runs, so read the flag directly.
|
|
9
9
|
const words = process.argv.slice(2);
|
|
10
10
|
const end = words.indexOf("--");
|
|
11
11
|
const asJson = (end < 0 ? words : words.slice(0, end)).includes("--json");
|
|
12
12
|
try {
|
|
13
|
+
const runtime = captureRuntime();
|
|
13
14
|
await createProgram({
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
runtime,
|
|
16
|
+
guard: (path, options) => assertCommandAvailable(path, options, runtime),
|
|
17
|
+
setupMode: await currentSetupMode(runtime),
|
|
16
18
|
...(asJson ? { writeError: () => undefined } : {}),
|
|
17
19
|
}).parseAsync(process.argv);
|
|
18
20
|
}
|
|
@@ -21,13 +23,15 @@ catch (error) {
|
|
|
21
23
|
!(error instanceof InvalidArgumentError)) {
|
|
22
24
|
// Commander already printed help or the parsing error, unless it was silenced for --json.
|
|
23
25
|
process.exitCode = error.exitCode;
|
|
24
|
-
if (asJson && error.exitCode)
|
|
25
|
-
console.error(renderJsonError(new
|
|
26
|
+
if (asJson && error.exitCode) {
|
|
27
|
+
console.error(renderJsonError(new CliError(error.code === "commander.help"
|
|
26
28
|
? "Choose a subcommand. Add --help to see them."
|
|
27
29
|
: error.message.replace(/^error: /, ""))));
|
|
30
|
+
}
|
|
28
31
|
}
|
|
29
32
|
else if (error instanceof Error && error.name === "ExitPromptError") {
|
|
30
|
-
|
|
33
|
+
const message = "Cancelled. Nothing was changed.";
|
|
34
|
+
console.log(asJson ? json({ message }) : message);
|
|
31
35
|
process.exitCode = 130;
|
|
32
36
|
}
|
|
33
37
|
else if (error instanceof NothingToDoError) {
|
package/dist/commands/add.js
CHANGED
|
@@ -1,25 +1,36 @@
|
|
|
1
1
|
import { Option } from "commander";
|
|
2
|
+
import { harnesses } from "../harnesses/registry.js";
|
|
2
3
|
import { stripVTControlCharacters } from "node:util";
|
|
3
|
-
import { addHook
|
|
4
|
+
import { addHook } from "../ui/add-hook.js";
|
|
5
|
+
import { addMcp } from "../ui/add-mcp.js";
|
|
6
|
+
import { addSkills } from "../ui/add-skills.js";
|
|
7
|
+
import { terminalPrompts } from "../ui/add-prompts.js";
|
|
4
8
|
import { renderCollaboration } from "../ui/collaboration.js";
|
|
5
9
|
import { dim, json, ok } from "../ui/format.js";
|
|
6
10
|
import { renderSyncOutput } from "../ui/output.js";
|
|
11
|
+
import { defined } from "../shared/lookup.js";
|
|
7
12
|
const updates = () => new Option("--updates <mode>", "Stay current: fork, manual or auto").choices([
|
|
8
13
|
"fork",
|
|
9
14
|
"manual",
|
|
10
15
|
"auto",
|
|
11
16
|
]);
|
|
17
|
+
/**
|
|
18
|
+
* Adds import and update commands to existing asset groups using the supplied
|
|
19
|
+
* command services.
|
|
20
|
+
*/
|
|
12
21
|
export function registerAdd(program, context) {
|
|
13
|
-
const group = (name) => program.commands.find((c) => c.name() === name);
|
|
22
|
+
const group = (name) => defined(program.commands.find((c) => c.name() === name), `Command group ${name} isn't registered`);
|
|
14
23
|
const add = () => ({
|
|
24
|
+
runtime: context.runtime,
|
|
15
25
|
interactive: context.mode.interactive,
|
|
16
26
|
write: context.write,
|
|
17
27
|
prompts: terminalPrompts(context.write),
|
|
18
28
|
});
|
|
19
29
|
/** Adding narrates as it goes; `--json` callers get those lines as one object. */
|
|
20
30
|
const reporting = async (run) => {
|
|
21
|
-
if (!context.mode.json)
|
|
31
|
+
if (!context.mode.json) {
|
|
22
32
|
return run(add());
|
|
33
|
+
}
|
|
23
34
|
const messages = [];
|
|
24
35
|
await run({
|
|
25
36
|
...add(),
|
|
@@ -39,10 +50,11 @@ export function registerAdd(program, context) {
|
|
|
39
50
|
.action((url, options) => reporting((context) => addSkills(url, options, context)));
|
|
40
51
|
group("hooks")
|
|
41
52
|
.command("add <url>")
|
|
42
|
-
.description("Add
|
|
53
|
+
.description("Add Hooks from a repository, for the coding tools they were written for")
|
|
43
54
|
.addOption(updates())
|
|
44
|
-
.option("--as <name>", "Add
|
|
45
|
-
.option("--only <names...>", "Choose
|
|
55
|
+
.option("--as <name>", "Add one Hook under a different name")
|
|
56
|
+
.option("--only <names...>", "Choose Hooks by name or folder")
|
|
57
|
+
.option("--all", "Add every Hook in the repository")
|
|
46
58
|
.option("--description <text>", "What the Hook does")
|
|
47
59
|
.action((url, options) => reporting((context) => addHook(url, options, context)));
|
|
48
60
|
group("mcp")
|
|
@@ -50,11 +62,7 @@ export function registerAdd(program, context) {
|
|
|
50
62
|
.description("Add an MCP server from JSON or from one of your coding tools")
|
|
51
63
|
.option("--config <json>", "Server configuration as JSON text")
|
|
52
64
|
.option("--file <path>", "Read the configuration from a file")
|
|
53
|
-
.addOption(new Option("--from <harness>", "Import from a coding tool").choices(
|
|
54
|
-
"claude",
|
|
55
|
-
"codex",
|
|
56
|
-
"cursor",
|
|
57
|
-
]))
|
|
65
|
+
.addOption(new Option("--from <harness>", "Import from a coding tool").choices(harnesses))
|
|
58
66
|
.option("--replace", "Replace an existing entry in your coding tools")
|
|
59
67
|
.option("--oauth", "The server signs in through your coding tool (OAuth)")
|
|
60
68
|
.option("--description <text>", "What the server does")
|
|
@@ -62,38 +70,42 @@ export function registerAdd(program, context) {
|
|
|
62
70
|
for (const [name, kind] of [
|
|
63
71
|
["skills", "skill"],
|
|
64
72
|
["hooks", "hook"],
|
|
65
|
-
])
|
|
73
|
+
]) {
|
|
66
74
|
group(name)
|
|
67
75
|
.command("update [name]")
|
|
68
76
|
.description("Bring assets added from a repository up to date, showing what changed")
|
|
69
77
|
.option("--force", "Overwrite local edits")
|
|
70
78
|
.option("--dry-run", "Show what would change without changing anything")
|
|
71
79
|
.action(async (asset, options) => {
|
|
72
|
-
const results =
|
|
73
|
-
kind,
|
|
74
|
-
name: asset,
|
|
80
|
+
const results = await context.updateImported(kind, asset, {
|
|
75
81
|
force: options.force,
|
|
76
82
|
dryRun: options.dryRun,
|
|
77
|
-
})
|
|
83
|
+
});
|
|
78
84
|
// New files only reach coding tools through the installed copies.
|
|
79
85
|
const applied = !options.dryRun && results.some((r) => r.changes.length > 0);
|
|
80
86
|
const events = applied
|
|
81
87
|
? await context.synchronize(undefined, { prompt: false })
|
|
82
88
|
: [];
|
|
83
|
-
if (context.mode.json)
|
|
89
|
+
if (context.mode.json) {
|
|
84
90
|
return context.write(json(results));
|
|
85
|
-
|
|
91
|
+
}
|
|
92
|
+
if (!results.length) {
|
|
86
93
|
return context.write(dim("Nothing was added from a repository."));
|
|
94
|
+
}
|
|
87
95
|
for (const result of results) {
|
|
88
96
|
context.write(`${result.name}: ${result.changes.length ? `${result.changes.length} file${result.changes.length === 1 ? "" : "s"} changed` : "up to date"}`);
|
|
89
|
-
if (result.changes.length)
|
|
90
|
-
for (const line of renderCollaboration(
|
|
97
|
+
if (result.changes.length) {
|
|
98
|
+
for (const line of renderCollaboration(result.changes)) {
|
|
91
99
|
context.write(line);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
92
102
|
}
|
|
93
103
|
if (applied) {
|
|
94
|
-
for (const line of renderSyncOutput(events))
|
|
104
|
+
for (const line of renderSyncOutput(events)) {
|
|
95
105
|
context.write(line);
|
|
106
|
+
}
|
|
96
107
|
context.write(`${ok("✔")} Update installed.`);
|
|
97
108
|
}
|
|
98
109
|
});
|
|
110
|
+
}
|
|
99
111
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { CliError } from "../errors.js";
|
|
2
|
+
export function requireArguments(context, usage) {
|
|
3
|
+
if (!context.mode.interactive) {
|
|
4
|
+
throw new CliError("Name the asset to act on, or run this in a terminal to choose from a list.", usage);
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
/** What `add` copies from, as its usage shows it. */
|
|
8
|
+
export const addArguments = {
|
|
9
|
+
skill: " <source>",
|
|
10
|
+
mcp: "",
|
|
11
|
+
hook: " <url>",
|
|
12
|
+
};
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { Option } from "commander";
|
|
2
|
+
import { prefixedName } from "../features/environment/names.js";
|
|
3
|
+
import { runSelection } from "../ui/selection.js";
|
|
4
|
+
import { pickMany, pickOne } from "../ui/pick.js";
|
|
5
|
+
import { bold, clean, ok, ORIGIN_HELP, originLabel } from "../ui/format.js";
|
|
6
|
+
import { assetKinds } from "../features/asset-kinds/index.js";
|
|
7
|
+
import { addArguments, requireArguments } from "./arguments.js";
|
|
8
|
+
import { ask } from "./asset-share.js";
|
|
9
|
+
/** Installed assets eligible for an action on this machine. */
|
|
10
|
+
function localCandidates(items, kind, action, origin) {
|
|
11
|
+
return items.filter((item) => item.kind === kind &&
|
|
12
|
+
!item.via.includes("config") &&
|
|
13
|
+
item.origin !== "—" &&
|
|
14
|
+
(!origin || item.origin === origin.replace(":", "/")) &&
|
|
15
|
+
(action !== "enable" || item.state === "disabled") &&
|
|
16
|
+
(action !== "disable" || item.state !== "disabled"));
|
|
17
|
+
}
|
|
18
|
+
const localChoice = (item) => ({
|
|
19
|
+
value: item,
|
|
20
|
+
name: item.installedName,
|
|
21
|
+
hint: `${item.origin} · ${item.state}`,
|
|
22
|
+
});
|
|
23
|
+
/** `install`: adds assets of one kind to the selection and syncs. */
|
|
24
|
+
export function registerInstall(command, kind, context) {
|
|
25
|
+
const labels = assetKinds[kind];
|
|
26
|
+
const group = assetKinds[kind].command;
|
|
27
|
+
const addCommand = `barndog ${assetKinds[kind].command} add${addArguments[kind]}`;
|
|
28
|
+
command
|
|
29
|
+
.command("install [name]")
|
|
30
|
+
.description(`Install ${labels.many} on this machine; choose from a list when no name is given`)
|
|
31
|
+
.option("--origin <origin>", ORIGIN_HELP)
|
|
32
|
+
.addOption(new Option("--overrides <choice>", "Keep or clear your existing exclusions").choices(["preserve", "clear"]))
|
|
33
|
+
.option("--decisions <file>", "JSON per-asset override choices")
|
|
34
|
+
.action(async (name, options) => {
|
|
35
|
+
if (name) {
|
|
36
|
+
return runSelection(context, (resolution) => context.changeAsset("install", {
|
|
37
|
+
...options,
|
|
38
|
+
name,
|
|
39
|
+
kind,
|
|
40
|
+
resolution,
|
|
41
|
+
}));
|
|
42
|
+
}
|
|
43
|
+
requireArguments(context, `barndog ${group} install <name> --origin <origin>`);
|
|
44
|
+
const [rows, inventory] = await Promise.all([
|
|
45
|
+
context.searchCatalog(kind),
|
|
46
|
+
context.inventory(),
|
|
47
|
+
]);
|
|
48
|
+
const selected = new Set(inventory.items
|
|
49
|
+
.filter((item) => item.state !== "removing")
|
|
50
|
+
.map((item) => item.id));
|
|
51
|
+
const inOrigin = rows.filter((row) => !options.origin ||
|
|
52
|
+
originLabel(row.origin) === options.origin.replace(":", "/"));
|
|
53
|
+
const ids = await pickMany(`Choose ${labels.many} to install`, inOrigin
|
|
54
|
+
.filter((row) => !selected.has(row.id))
|
|
55
|
+
.sort((a, b) => a.name.localeCompare(b.name))
|
|
56
|
+
.map((row) => ({
|
|
57
|
+
value: row.id,
|
|
58
|
+
name: row.name,
|
|
59
|
+
hint: `${originLabel(row.origin)} · ${clean(row.version.description)}`,
|
|
60
|
+
})), {
|
|
61
|
+
empty: inOrigin.length
|
|
62
|
+
? `Every available ${labels.one} is already on this machine.`
|
|
63
|
+
: `No ${labels.many} available to install. Add one with ${addCommand}.`,
|
|
64
|
+
});
|
|
65
|
+
await runSelection(context, (resolution) => context.changeAssets("install", {
|
|
66
|
+
kind,
|
|
67
|
+
ids,
|
|
68
|
+
overrides: options.overrides,
|
|
69
|
+
decisions: options.decisions,
|
|
70
|
+
resolution,
|
|
71
|
+
}));
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
/** `remove`, `enable` and `disable` for assets installed on this machine. */
|
|
75
|
+
export function registerToggles(command, kind, context) {
|
|
76
|
+
const labels = assetKinds[kind];
|
|
77
|
+
const group = assetKinds[kind].command;
|
|
78
|
+
for (const action of ["remove", "enable", "disable"]) {
|
|
79
|
+
command
|
|
80
|
+
.command(`${action} [name]`)
|
|
81
|
+
.description({
|
|
82
|
+
remove: `Remove ${labels.many} from this machine, even when a set includes them`,
|
|
83
|
+
enable: `Turn disabled ${labels.many} back on`,
|
|
84
|
+
disable: `Turn ${labels.many} off without removing them from your selection`,
|
|
85
|
+
}[action])
|
|
86
|
+
.option("--origin <origin>", ORIGIN_HELP)
|
|
87
|
+
.action(async (name, options) => {
|
|
88
|
+
if (name) {
|
|
89
|
+
return runSelection(context, (resolution) => context.changeAsset(action, {
|
|
90
|
+
...options,
|
|
91
|
+
name,
|
|
92
|
+
kind,
|
|
93
|
+
resolution,
|
|
94
|
+
}));
|
|
95
|
+
}
|
|
96
|
+
requireArguments(context, `barndog ${group} ${action} <name>`);
|
|
97
|
+
const items = localCandidates((await context.inventory()).items, kind, action, options.origin);
|
|
98
|
+
const chosen = await pickMany(`Choose ${labels.many} to ${action}`, items.map(localChoice), {
|
|
99
|
+
empty: action === "enable"
|
|
100
|
+
? `No ${labels.many} are disabled.`
|
|
101
|
+
: `No ${labels.many} to ${action} on this machine.`,
|
|
102
|
+
});
|
|
103
|
+
await runSelection(context, (resolution) => context.changeAssets(action, {
|
|
104
|
+
kind,
|
|
105
|
+
ids: chosen.map((item) => item.id),
|
|
106
|
+
resolution,
|
|
107
|
+
}));
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/** `rename`: installs an asset under another local name. */
|
|
112
|
+
export function registerRename(command, kind, context) {
|
|
113
|
+
const labels = assetKinds[kind];
|
|
114
|
+
const group = assetKinds[kind].command;
|
|
115
|
+
command
|
|
116
|
+
.command("rename [name]")
|
|
117
|
+
.description(`Install ${labels.a} under a different local name`)
|
|
118
|
+
.option("--origin <origin>", ORIGIN_HELP)
|
|
119
|
+
.option("--as <name>", "New local name: lowercase letters, numbers and hyphens")
|
|
120
|
+
.option("--reset", "Go back to the published name")
|
|
121
|
+
.action(async (name, options) => {
|
|
122
|
+
let target = name;
|
|
123
|
+
let suggestion;
|
|
124
|
+
if (!target) {
|
|
125
|
+
requireArguments(context, `barndog ${group} rename <name> --as <new-name>`);
|
|
126
|
+
const item = await pickOne(`Choose ${labels.a} to rename`, localCandidates((await context.inventory()).items, kind, "rename", options.origin).map(localChoice), { empty: `No ${labels.many} to rename on this machine.` });
|
|
127
|
+
target = item.id;
|
|
128
|
+
const [type = "", slug = ""] = item.origin.split("/");
|
|
129
|
+
suggestion = prefixedName({
|
|
130
|
+
name: item.name,
|
|
131
|
+
origin: { type, slug },
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
const as = options.reset
|
|
135
|
+
? undefined
|
|
136
|
+
: await ask(context, options.as, {
|
|
137
|
+
message: "New local name",
|
|
138
|
+
flag: "--as",
|
|
139
|
+
fallback: suggestion,
|
|
140
|
+
});
|
|
141
|
+
await runSelection(context, () => context.renameAsset({
|
|
142
|
+
kind,
|
|
143
|
+
name: target,
|
|
144
|
+
origin: options.origin,
|
|
145
|
+
as,
|
|
146
|
+
reset: options.reset,
|
|
147
|
+
}));
|
|
148
|
+
// A clash prompt during the sync may have chosen a different name.
|
|
149
|
+
const renamed = target;
|
|
150
|
+
const item = (await context.inventory()).items.find((entry) => entry.kind === kind &&
|
|
151
|
+
[entry.id, entry.name, entry.installedName].includes(renamed) &&
|
|
152
|
+
(!options.origin ||
|
|
153
|
+
entry.origin === options.origin.replace(":", "/")));
|
|
154
|
+
if (item && !context.mode.json) {
|
|
155
|
+
context.write(item.installedName === item.name
|
|
156
|
+
? `${ok("✔")} ${bold(item.name)} uses its published name.`
|
|
157
|
+
: `${ok("✔")} ${bold(item.name)} from ${item.origin} is installed as ${bold(item.installedName)}.`);
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
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
|
+
if (onlyAvailable) {
|
|
29
|
+
throw error;
|
|
30
|
+
}
|
|
31
|
+
catalogProblem = friendlyMessage(error);
|
|
32
|
+
return [];
|
|
33
|
+
})
|
|
34
|
+
: [],
|
|
35
|
+
]);
|
|
36
|
+
const items = inventory.items.filter((item) => item.kind === kind);
|
|
37
|
+
const listing = assetListing(items, rows, options);
|
|
38
|
+
if (context.mode.json) {
|
|
39
|
+
return context.write(json(listing));
|
|
40
|
+
}
|
|
41
|
+
if (inventory.offline) {
|
|
42
|
+
context.write(dim(`Showing local state only: ${inventory.offline}`));
|
|
43
|
+
}
|
|
44
|
+
else if (catalogProblem) {
|
|
45
|
+
context.write(dim(`Couldn't load available ${labels.many}: ${catalogProblem}`));
|
|
46
|
+
}
|
|
47
|
+
if (!listing.length) {
|
|
48
|
+
if (narrowed) {
|
|
49
|
+
context.write(`No ${labels.many} match that filter.`);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (catalogProblem || inventory.offline) {
|
|
53
|
+
context.write(`No ${labels.many} on this machine yet.`);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
context.write(`No ${labels.many} yet.`);
|
|
57
|
+
context.write(hint(addCommand, "Next"));
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const start = (options.page - 1) * options.limit;
|
|
61
|
+
const page = listing.slice(start, start + options.limit);
|
|
62
|
+
if (!page.length) {
|
|
63
|
+
context.write(`Page ${options.page} is empty. Choose a page from 1 to ${Math.ceil(listing.length / options.limit)}.`);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
for (const line of renderInventory(page, {
|
|
67
|
+
...options,
|
|
68
|
+
runtime: context.runtime,
|
|
69
|
+
})) {
|
|
70
|
+
context.write(line);
|
|
71
|
+
}
|
|
72
|
+
if (listing.length > options.limit) {
|
|
73
|
+
const flags = ["installed", "disabled", "available"]
|
|
74
|
+
.filter((flag) => options[flag])
|
|
75
|
+
.map((flag) => ` --${flag}`)
|
|
76
|
+
.join("");
|
|
77
|
+
context.write("\n" +
|
|
78
|
+
dim(`Showing ${start + 1}–${start + page.length} of ${listing.length}`));
|
|
79
|
+
if (start + page.length < listing.length) {
|
|
80
|
+
context.write(hint(`barndog ${group} list${flags} --page ${options.page + 1}`, "Next"));
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
const onThisMachine = page.filter((item) => item.state !== "available");
|
|
84
|
+
const hints = inventoryHints(onThisMachine);
|
|
85
|
+
if (hints.length) {
|
|
86
|
+
context.write(["", ...hints].join("\n"));
|
|
87
|
+
}
|
|
88
|
+
else if (!options.paths && onThisMachine.length) {
|
|
89
|
+
context.write("\n" +
|
|
90
|
+
hint(`barndog ${group} list --paths`, "Tip") +
|
|
91
|
+
dim(" to see where each one lives"));
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
/** `search`: the kind's published catalog, filtered locally. */
|
|
96
|
+
export function registerSearch(command, kind, context) {
|
|
97
|
+
const labels = assetKinds[kind];
|
|
98
|
+
const group = assetKinds[kind].command;
|
|
99
|
+
const search = async (assetKind, query, options) => {
|
|
100
|
+
const [rows, inventory] = await Promise.all([
|
|
101
|
+
context.searchCatalog(assetKind),
|
|
102
|
+
context.inventory().catch(() => undefined),
|
|
103
|
+
]);
|
|
104
|
+
const selected = new Set(inventory?.items
|
|
105
|
+
.filter((item) => item.state !== "removing")
|
|
106
|
+
.map((item) => item.id) ?? []);
|
|
107
|
+
// JSON gets the same matches the table shows, all pages at once.
|
|
108
|
+
if (context.mode.json) {
|
|
109
|
+
return context.write(json(filterAssets(rows, { ...options, search: query }).map((row) => ({
|
|
110
|
+
...row,
|
|
111
|
+
selected: selected.has(row.id),
|
|
112
|
+
}))));
|
|
113
|
+
}
|
|
114
|
+
for (const line of renderCatalog(rows, { ...options, search: query }, `barndog ${group} search`, selected)) {
|
|
115
|
+
context.write(line);
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
assetListOptions(command
|
|
119
|
+
.command("search [query]")
|
|
120
|
+
.description(`Browse ${labels.many} published in your workspace`), false).action((query, options) => search(kind, query ?? options.search, options));
|
|
121
|
+
}
|
|
@@ -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
|
+
}
|