barndog 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +117 -2
- package/dist/cli.js +40 -0
- package/dist/commands/add.js +99 -0
- package/dist/commands/auth.js +25 -0
- package/dist/commands/availability.js +87 -0
- package/dist/commands/capabilities.js +488 -0
- package/dist/commands/collaboration.js +203 -0
- package/dist/commands/context.js +1 -0
- package/dist/commands/environment.js +416 -0
- package/dist/commands/init.js +20 -0
- package/dist/commands/origin.js +48 -0
- package/dist/commands/status.js +66 -0
- package/dist/commands/sync.js +30 -0
- package/dist/commands/workspace.js +84 -0
- package/dist/config/build.js +2 -0
- package/dist/config/environment.js +41 -0
- package/dist/config/settings.js +127 -0
- package/dist/config/state.js +70 -0
- package/dist/errors.js +154 -0
- package/dist/features/asset-selection/index.js +212 -0
- package/dist/features/asset-selection/types.js +1 -0
- package/dist/features/auth/credentials.js +62 -0
- package/dist/features/auth/session.js +120 -0
- package/dist/features/auth/transport.js +44 -0
- package/dist/features/capabilities/index.js +106 -0
- package/dist/features/catalog/index.js +102 -0
- package/dist/features/collaboration/domain.js +90 -0
- package/dist/features/collaboration/index.js +254 -0
- package/dist/features/collaboration/remote.js +121 -0
- package/dist/features/collaboration/workspace-git.js +362 -0
- package/dist/features/collaboration/workspace-github.js +130 -0
- package/dist/features/collaboration/workspace-store.js +256 -0
- package/dist/features/collaboration/workspace.js +391 -0
- package/dist/features/discovery/index.js +66 -0
- package/dist/features/doctor/index.js +154 -0
- package/dist/features/environment/auto-sync.js +96 -0
- package/dist/features/environment/cloud-source.js +27 -0
- package/dist/features/environment/installed.js +124 -0
- package/dist/features/environment/names.js +153 -0
- package/dist/features/environment/operations.js +277 -0
- package/dist/features/environment/packages.js +120 -0
- package/dist/features/environment/remote.js +71 -0
- package/dist/features/environment/source.js +1 -0
- package/dist/features/environment/sync.js +547 -0
- package/dist/features/environment/transaction.js +284 -0
- package/dist/features/environment/workspace-source.js +19 -0
- package/dist/features/git-hosts/index.js +148 -0
- package/dist/features/git-workspace/assets.js +71 -0
- package/dist/features/git-workspace/format.js +310 -0
- package/dist/features/git-workspace/git.js +135 -0
- package/dist/features/git-workspace/migrate.js +188 -0
- package/dist/features/git-workspace/move.js +337 -0
- package/dist/features/git-workspace/overlay.js +131 -0
- package/dist/features/git-workspace/publish.js +172 -0
- package/dist/features/git-workspace/setup.js +135 -0
- package/dist/features/git-workspace/snapshot.js +105 -0
- package/dist/features/git-workspace/source.js +159 -0
- package/dist/features/git-workspace/startup.js +16 -0
- package/dist/features/hooks/adapt.js +103 -0
- package/dist/features/hooks/divergence.js +38 -0
- package/dist/features/hooks/test.js +114 -0
- package/dist/features/imports/discover.js +249 -0
- package/dist/features/imports/folder.js +52 -0
- package/dist/features/imports/local.js +242 -0
- package/dist/features/imports/mcp.js +219 -0
- package/dist/features/imports/remote.js +85 -0
- package/dist/features/inspection/index.js +42 -0
- package/dist/features/inventory/index.js +224 -0
- package/dist/features/knowledge/index.js +118 -0
- package/dist/features/knowledge/startup.js +25 -0
- package/dist/features/mcps/index.js +102 -0
- package/dist/features/native/adapters.js +143 -0
- package/dist/features/native/configuration.js +196 -0
- package/dist/features/native/mcp-launch.js +57 -0
- package/dist/features/onboarding/environment.js +160 -0
- package/dist/features/onboarding/setup.js +123 -0
- package/dist/features/repositories/context.js +55 -0
- package/dist/features/skills/install.js +25 -0
- package/dist/features/skills/remote.js +177 -0
- package/dist/features/skills/sync.js +121 -0
- package/dist/features/skills/validation.js +34 -0
- package/dist/harnesses/claude.js +57 -0
- package/dist/harnesses/codex.js +46 -0
- package/dist/harnesses/cursor.js +44 -0
- package/dist/harnesses/detect.js +61 -0
- package/dist/harnesses/registry.js +16 -0
- package/dist/harnesses/types.js +1 -0
- package/dist/program.js +272 -0
- package/dist/ui/add-asset.js +440 -0
- package/dist/ui/asset-list.js +50 -0
- package/dist/ui/assets.js +142 -0
- package/dist/ui/auth.js +138 -0
- package/dist/ui/clash.js +43 -0
- package/dist/ui/collaboration.js +142 -0
- package/dist/ui/connection.js +102 -0
- package/dist/ui/environment-onboarding.js +125 -0
- package/dist/ui/format.js +154 -0
- package/dist/ui/hook-compatibility.js +33 -0
- package/dist/ui/mcp.js +40 -0
- package/dist/ui/move.js +22 -0
- package/dist/ui/onboarding.js +293 -0
- package/dist/ui/output.js +155 -0
- package/dist/ui/pick.js +153 -0
- package/dist/ui/scope-install.js +47 -0
- package/dist/ui/selection.js +51 -0
- package/dist/ui/theme.js +37 -0
- package/dist/version.js +12 -0
- package/package.json +76 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 BarnDog.ai
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,118 @@
|
|
|
1
|
-
#
|
|
1
|
+
# BarnDog CLI
|
|
2
2
|
|
|
3
|
-
|
|
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.
|
|
4
|
+
|
|
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
|
+
|
|
7
|
+
Currently supported harnesses:
|
|
8
|
+
|
|
9
|
+
- Claude Code
|
|
10
|
+
- Codex
|
|
11
|
+
- Cursor
|
|
12
|
+
|
|
13
|
+
## Why
|
|
14
|
+
|
|
15
|
+
Every coding agent has its own place for skills, its own MCP config format, and its own hook settings. Keeping a team's setup consistent across them usually means copying files around and hoping nobody's copy is stale.
|
|
16
|
+
|
|
17
|
+
BarnDog keeps one shared setup and writes it into each tool in that tool's own format. Developers keep working in the agent they prefer.
|
|
18
|
+
|
|
19
|
+
## How it works
|
|
20
|
+
|
|
21
|
+
```mermaid
|
|
22
|
+
flowchart LR
|
|
23
|
+
W["Your workspace<br/>BarnDog server, a Git repo,<br/>or a local folder"] -->|barndog sync| C["barndog CLI"]
|
|
24
|
+
C --> CC[Claude Code]
|
|
25
|
+
C --> CX[Codex]
|
|
26
|
+
C --> CU[Other harnesses]
|
|
27
|
+
```
|
|
28
|
+
|
|
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
|
+
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
|
+
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
|
+
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.
|
|
33
|
+
|
|
34
|
+
## What it manages
|
|
35
|
+
|
|
36
|
+
| Asset | What it is |
|
|
37
|
+
| -------------- | ------------------------------------------------------------------------------------------- |
|
|
38
|
+
| **Skill** | A folder with a `SKILL.md` and supporting files that agents load when relevant. |
|
|
39
|
+
| **MCP server** | A connection to an MCP server. It names the secrets it needs but never stores their values. |
|
|
40
|
+
| **Hook** | A command that runs on an agent lifecycle event, such as after a file edit. |
|
|
41
|
+
| **Knowledge** | Company policies and context that agents can look up when a task needs it. |
|
|
42
|
+
|
|
43
|
+
## Install
|
|
44
|
+
|
|
45
|
+
Requires [Node.js](https://nodejs.org) 24 or newer.
|
|
46
|
+
|
|
47
|
+
```sh
|
|
48
|
+
npm install -g barndog
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Quick start
|
|
52
|
+
|
|
53
|
+
```sh
|
|
54
|
+
barndog init # connect, sign in, choose tools and sets
|
|
55
|
+
barndog status # what's installed on this machine, and where
|
|
56
|
+
barndog skills search review # browse the shared catalog
|
|
57
|
+
barndog skills install code-review # add one asset on top of your sets
|
|
58
|
+
barndog sync # apply changes now
|
|
59
|
+
barndog doctor # check everything and print a fix for each problem
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Run `barndog` on its own to see every command, or `barndog <command> --help` for its options.
|
|
63
|
+
|
|
64
|
+
### No BarnDog server? Use Git
|
|
65
|
+
|
|
66
|
+
You can share assets through any Git repository, using your own Git credentials. This requires the [GitHub CLI](https://cli.github.com) (`gh`) to be installed:
|
|
67
|
+
|
|
68
|
+
```sh
|
|
69
|
+
barndog init --repo git@github.com:acme/ai-setup.git
|
|
70
|
+
```
|
|
71
|
+
|
|
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
|
+
|
|
74
|
+
### Suggest a change
|
|
75
|
+
|
|
76
|
+
```sh
|
|
77
|
+
barndog skills pull code-review --origin team/engineering
|
|
78
|
+
cd code-review
|
|
79
|
+
# edit SKILL.md
|
|
80
|
+
barndog diff
|
|
81
|
+
barndog push --title "Add a security checklist"
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Reviewers use `barndog changes list`, `changes diff`, and `changes approve` from the terminal, or the BarnDog web workspace.
|
|
85
|
+
|
|
86
|
+
## What it changes on your machine
|
|
87
|
+
|
|
88
|
+
BarnDog is careful with your existing setup:
|
|
89
|
+
|
|
90
|
+
- It only touches what it installed itself. It never takes over a skill, MCP entry, or hook you added by hand, and it stops before overwriting anything it doesn't own.
|
|
91
|
+
- Comments and unrelated settings in your tools' config files are left alone.
|
|
92
|
+
- Its own files live in `~/.barndog/`. Skills appear as links in each tool's skills folder, such as `~/.claude/skills/`.
|
|
93
|
+
- Changes are journaled before they're applied, so an interrupted sync is finished safely on the next run.
|
|
94
|
+
- Hook scripts run only inside your coding tools, after their own trust checks. Installing or syncing never runs them.
|
|
95
|
+
|
|
96
|
+
## Documentation
|
|
97
|
+
|
|
98
|
+
- [What is BarnDog?](https://barndog.dev/docs)
|
|
99
|
+
- [Quickstart](https://barndog.dev/docs/quickstart)
|
|
100
|
+
- [Core concepts](https://barndog.dev/docs/concepts)
|
|
101
|
+
- [CLI reference](https://barndog.dev/docs/cli)
|
|
102
|
+
|
|
103
|
+
## Contributing
|
|
104
|
+
|
|
105
|
+
Issues and pull requests are welcome. To work on the CLI:
|
|
106
|
+
|
|
107
|
+
```sh
|
|
108
|
+
pnpm install
|
|
109
|
+
pnpm build
|
|
110
|
+
npm link # use your local build as `barndog`
|
|
111
|
+
pnpm test
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
[AGENTS.md](AGENTS.md) describes how the code is organized and how each part is expected to behave. It's written for coding agents, and it's the best technical reference for people too.
|
|
115
|
+
|
|
116
|
+
## License
|
|
117
|
+
|
|
118
|
+
[MIT](LICENSE)
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { CommanderError, InvalidArgumentError } from "commander";
|
|
3
|
+
import { assertCommandAvailable, currentSetupMode, } from "./commands/availability.js";
|
|
4
|
+
import { createProgram } from "./program.js";
|
|
5
|
+
import { renderError, renderJsonError } from "./ui/output.js";
|
|
6
|
+
import { json } from "./ui/format.js";
|
|
7
|
+
import { NothingToDoError } from "./errors.js";
|
|
8
|
+
// Parsing errors happen before any action runs, so read the flag directly.
|
|
9
|
+
const words = process.argv.slice(2);
|
|
10
|
+
const end = words.indexOf("--");
|
|
11
|
+
const asJson = (end < 0 ? words : words.slice(0, end)).includes("--json");
|
|
12
|
+
try {
|
|
13
|
+
await createProgram({
|
|
14
|
+
guard: assertCommandAvailable,
|
|
15
|
+
setupMode: await currentSetupMode(),
|
|
16
|
+
...(asJson ? { writeError: () => undefined } : {}),
|
|
17
|
+
}).parseAsync(process.argv);
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
if (error instanceof CommanderError &&
|
|
21
|
+
!(error instanceof InvalidArgumentError)) {
|
|
22
|
+
// Commander already printed help or the parsing error, unless it was silenced for --json.
|
|
23
|
+
process.exitCode = error.exitCode;
|
|
24
|
+
if (asJson && error.exitCode)
|
|
25
|
+
console.error(renderJsonError(new Error(error.code === "commander.help"
|
|
26
|
+
? "Choose a subcommand. Add --help to see them."
|
|
27
|
+
: error.message.replace(/^error: /, ""))));
|
|
28
|
+
}
|
|
29
|
+
else if (error instanceof Error && error.name === "ExitPromptError") {
|
|
30
|
+
console.log("Cancelled. Nothing was changed.");
|
|
31
|
+
process.exitCode = 130;
|
|
32
|
+
}
|
|
33
|
+
else if (error instanceof NothingToDoError) {
|
|
34
|
+
console.log(asJson ? json({ message: error.message }) : error.message);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
console.error(asJson ? renderJsonError(error) : renderError(error));
|
|
38
|
+
process.exitCode = 1;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { Option } from "commander";
|
|
2
|
+
import { stripVTControlCharacters } from "node:util";
|
|
3
|
+
import { addHook, addMcp, addSkills, terminalPrompts, } from "../ui/add-asset.js";
|
|
4
|
+
import { renderCollaboration } from "../ui/collaboration.js";
|
|
5
|
+
import { dim, json, ok } from "../ui/format.js";
|
|
6
|
+
import { renderSyncOutput } from "../ui/output.js";
|
|
7
|
+
const updates = () => new Option("--updates <mode>", "Stay current: fork, manual or auto").choices([
|
|
8
|
+
"fork",
|
|
9
|
+
"manual",
|
|
10
|
+
"auto",
|
|
11
|
+
]);
|
|
12
|
+
export function registerAdd(program, context) {
|
|
13
|
+
const group = (name) => program.commands.find((c) => c.name() === name);
|
|
14
|
+
const add = () => ({
|
|
15
|
+
interactive: context.mode.interactive,
|
|
16
|
+
write: context.write,
|
|
17
|
+
prompts: terminalPrompts(context.write),
|
|
18
|
+
});
|
|
19
|
+
/** Adding narrates as it goes; `--json` callers get those lines as one object. */
|
|
20
|
+
const reporting = async (run) => {
|
|
21
|
+
if (!context.mode.json)
|
|
22
|
+
return run(add());
|
|
23
|
+
const messages = [];
|
|
24
|
+
await run({
|
|
25
|
+
...add(),
|
|
26
|
+
write: (line) => messages.push(stripVTControlCharacters(line)),
|
|
27
|
+
});
|
|
28
|
+
context.write(json({ messages }));
|
|
29
|
+
};
|
|
30
|
+
group("skills")
|
|
31
|
+
.command("add <source>")
|
|
32
|
+
.description("Add Skills from a folder, GitHub or Git repository")
|
|
33
|
+
.addOption(updates())
|
|
34
|
+
.addOption(new Option("--copy", "From a folder: leave the original in place").conflicts("move"))
|
|
35
|
+
.option("--move", "From a folder: remove the original once it's added")
|
|
36
|
+
.option("--as <name>", "Add one Skill under a different name")
|
|
37
|
+
.option("--only <names...>", "Choose Skills by name or folder")
|
|
38
|
+
.option("--all", "Add every Skill in the repository")
|
|
39
|
+
.action((url, options) => reporting((context) => addSkills(url, options, context)));
|
|
40
|
+
group("hooks")
|
|
41
|
+
.command("add <url>")
|
|
42
|
+
.description("Add a Hook from a repository, for the coding tools it was written for")
|
|
43
|
+
.addOption(updates())
|
|
44
|
+
.option("--as <name>", "Add it under a different name")
|
|
45
|
+
.option("--only <names...>", "Choose a Hook by name")
|
|
46
|
+
.option("--description <text>", "What the Hook does")
|
|
47
|
+
.action((url, options) => reporting((context) => addHook(url, options, context)));
|
|
48
|
+
group("mcp")
|
|
49
|
+
.command("add [name]")
|
|
50
|
+
.description("Add an MCP server from JSON or from one of your coding tools")
|
|
51
|
+
.option("--config <json>", "Server configuration as JSON text")
|
|
52
|
+
.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
|
+
]))
|
|
58
|
+
.option("--replace", "Replace an existing entry in your coding tools")
|
|
59
|
+
.option("--oauth", "The server signs in through your coding tool (OAuth)")
|
|
60
|
+
.option("--description <text>", "What the server does")
|
|
61
|
+
.action((name, options) => reporting((context) => addMcp(name, options, context)));
|
|
62
|
+
for (const [name, kind] of [
|
|
63
|
+
["skills", "skill"],
|
|
64
|
+
["hooks", "hook"],
|
|
65
|
+
])
|
|
66
|
+
group(name)
|
|
67
|
+
.command("update [name]")
|
|
68
|
+
.description("Bring assets added from a repository up to date, showing what changed")
|
|
69
|
+
.option("--force", "Overwrite local edits")
|
|
70
|
+
.option("--dry-run", "Show what would change without changing anything")
|
|
71
|
+
.action(async (asset, options) => {
|
|
72
|
+
const results = (await context.capability("imports-update", {
|
|
73
|
+
kind,
|
|
74
|
+
name: asset,
|
|
75
|
+
force: options.force,
|
|
76
|
+
dryRun: options.dryRun,
|
|
77
|
+
}));
|
|
78
|
+
// New files only reach coding tools through the installed copies.
|
|
79
|
+
const applied = !options.dryRun && results.some((r) => r.changes.length > 0);
|
|
80
|
+
const events = applied
|
|
81
|
+
? await context.synchronize(undefined, { prompt: false })
|
|
82
|
+
: [];
|
|
83
|
+
if (context.mode.json)
|
|
84
|
+
return context.write(json(results));
|
|
85
|
+
if (!results.length)
|
|
86
|
+
return context.write(dim("Nothing was added from a repository."));
|
|
87
|
+
for (const result of results) {
|
|
88
|
+
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("diff", result.changes))
|
|
91
|
+
context.write(line);
|
|
92
|
+
}
|
|
93
|
+
if (applied) {
|
|
94
|
+
for (const line of renderSyncOutput(events))
|
|
95
|
+
context.write(line);
|
|
96
|
+
context.write(`${ok("✔")} Update installed.`);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export function registerAuth(program, context) {
|
|
2
|
+
program
|
|
3
|
+
.command("login")
|
|
4
|
+
.description("Sign in to your BarnDog workspace in the browser")
|
|
5
|
+
.option("--server <url>", "Workspace URL, such as https://barndog.example.com")
|
|
6
|
+
.option("--no-browser", "Print the sign-in URL instead of opening it")
|
|
7
|
+
.option("--force", "Sign in again even if you're already signed in")
|
|
8
|
+
.action(async (options) => {
|
|
9
|
+
await context.login(options);
|
|
10
|
+
});
|
|
11
|
+
program
|
|
12
|
+
.command("logout")
|
|
13
|
+
.description("Sign out and revoke this machine's session")
|
|
14
|
+
.action(async () => {
|
|
15
|
+
await context.logout();
|
|
16
|
+
});
|
|
17
|
+
program
|
|
18
|
+
.command("auth")
|
|
19
|
+
.description("Check your sign-in")
|
|
20
|
+
.command("status", { isDefault: true })
|
|
21
|
+
.description("Show who you're signed in as, your organization and role")
|
|
22
|
+
.action(async () => {
|
|
23
|
+
await context.authStatus();
|
|
24
|
+
});
|
|
25
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { homedir } from "node:os";
|
|
2
|
+
import { readSettings } from "../config/settings.js";
|
|
3
|
+
import { CliError } from "../errors.js";
|
|
4
|
+
import { readCredentials } from "../features/auth/credentials.js";
|
|
5
|
+
import { LOCAL_ORIGIN } from "../features/git-workspace/overlay.js";
|
|
6
|
+
const cloudOnly = [
|
|
7
|
+
/^login$/,
|
|
8
|
+
/^auth status$/,
|
|
9
|
+
/^whoami$/,
|
|
10
|
+
/^open$/,
|
|
11
|
+
/^people( |$)/,
|
|
12
|
+
/^github( |$)/,
|
|
13
|
+
/^(skills |hooks )?changes( |$)/,
|
|
14
|
+
/^(skills|mcp|hooks) (fork|promote)$/,
|
|
15
|
+
/^mcp (create|update)$/,
|
|
16
|
+
];
|
|
17
|
+
const needsReview = [
|
|
18
|
+
/^(pull|push|resolve)$/,
|
|
19
|
+
/^(skills|hooks) (pull|push|create|versions|show|diff)$/,
|
|
20
|
+
/^mcp versions$/,
|
|
21
|
+
];
|
|
22
|
+
/** The setup this machine runs on, when that setup limits what commands can do. */
|
|
23
|
+
export async function currentSetupMode(home = homedir()) {
|
|
24
|
+
const settings = await readSettings(home).catch(() => null);
|
|
25
|
+
if (settings?.version !== 2 || settings.connection)
|
|
26
|
+
return undefined;
|
|
27
|
+
if (settings.gitWorkspace)
|
|
28
|
+
return "git";
|
|
29
|
+
return settings.localWorkspace ? "local" : undefined;
|
|
30
|
+
}
|
|
31
|
+
/** What a command needs that this setup lacks; undefined when it can run. */
|
|
32
|
+
export function commandNeeds(command, mode) {
|
|
33
|
+
if (cloudOnly.some((pattern) => pattern.test(command)))
|
|
34
|
+
return "cloud";
|
|
35
|
+
if (mode === "local" && needsReview.some((pattern) => pattern.test(command)))
|
|
36
|
+
return "shared";
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
export const needText = (need) => need === "cloud" ? "a Cloud Workspace" : "a Git repo or Cloud Workspace";
|
|
40
|
+
export const modeName = (mode) => mode === "local" ? "local" : "Git";
|
|
41
|
+
/** Help's note beside a command this setup can't run. */
|
|
42
|
+
export const unavailableNote = (need, mode) => `Not available in ${modeName(mode)} mode. Needs ${needText(need)}.`;
|
|
43
|
+
const why = {
|
|
44
|
+
login: "signs in to a BarnDog Cloud Workspace",
|
|
45
|
+
"auth status": "shows your BarnDog Cloud Workspace sign-in",
|
|
46
|
+
whoami: "shows your BarnDog Cloud Workspace sign-in",
|
|
47
|
+
open: "opens the BarnDog Cloud Workspace in your browser",
|
|
48
|
+
};
|
|
49
|
+
/** Stops commands the current setup can't run, before they prompt or reach a server. */
|
|
50
|
+
export async function assertCommandAvailable(path, options = {}, home = homedir()) {
|
|
51
|
+
const settings = await readSettings(home).catch(() => null);
|
|
52
|
+
if (path.join(" ") === "logout" && !settings) {
|
|
53
|
+
if (!(await readCredentials(home)).selectedServer)
|
|
54
|
+
throw new CliError("You aren't signed in.");
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
if (settings?.version !== 2 || settings.connection)
|
|
58
|
+
return;
|
|
59
|
+
const git = settings.gitWorkspace;
|
|
60
|
+
const folder = settings.localWorkspace?.path;
|
|
61
|
+
if (!git && !folder)
|
|
62
|
+
return;
|
|
63
|
+
const command = path.join(" ");
|
|
64
|
+
const where = git
|
|
65
|
+
? `a Git repo (${git.url})`
|
|
66
|
+
: `a folder on this machine (${folder})`;
|
|
67
|
+
if (command === "logout") {
|
|
68
|
+
const { selectedServer } = await readCredentials(home);
|
|
69
|
+
if (!selectedServer)
|
|
70
|
+
throw new CliError(`You aren't signed in. This machine keeps its assets in ${where}, so it doesn't need a sign-in.`);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (git && /^(skills |hooks )?changes( |$)/.test(command))
|
|
74
|
+
throw new CliError(`Reviews happen as pull requests on your Git host, because this machine keeps its assets in ${where}.`, "barndog status");
|
|
75
|
+
// An explicit server is how local assets get promoted without switching.
|
|
76
|
+
if (command === "login" && options.server)
|
|
77
|
+
return;
|
|
78
|
+
if (/ promote$/.test(command) && options.origin === LOCAL_ORIGIN)
|
|
79
|
+
return;
|
|
80
|
+
const needs = commandNeeds(command, git ? "git" : "local");
|
|
81
|
+
if (needs === "cloud") {
|
|
82
|
+
const action = why[command] ?? "needs a BarnDog Cloud Workspace";
|
|
83
|
+
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
|
+
}
|
|
85
|
+
if (needs === "shared")
|
|
86
|
+
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");
|
|
87
|
+
}
|