barndog 0.2.0 → 0.2.2

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.
Files changed (112) hide show
  1. package/README.md +45 -24
  2. package/dist/cli.js +27 -1
  3. package/dist/commands/add.js +1 -0
  4. package/dist/commands/adopt.js +91 -0
  5. package/dist/commands/asset-install.js +1 -0
  6. package/dist/commands/asset-list.js +12 -3
  7. package/dist/commands/availability.js +25 -8
  8. package/dist/commands/capabilities.js +8 -2
  9. package/dist/commands/collaboration.js +22 -2
  10. package/dist/commands/harnesses.js +104 -0
  11. package/dist/commands/mcp-env.js +167 -0
  12. package/dist/commands/mcp.js +4 -2
  13. package/dist/commands/sets.js +13 -2
  14. package/dist/commands/status.js +2 -1
  15. package/dist/commands/sync.js +2 -1
  16. package/dist/commands/uninstall.js +62 -0
  17. package/dist/commands/workspace.js +43 -5
  18. package/dist/config/paths.js +21 -0
  19. package/dist/config/settings.js +5 -3
  20. package/dist/config/state.js +18 -6
  21. package/dist/entry/update-check.js +15 -0
  22. package/dist/features/adoption/adopt.js +235 -0
  23. package/dist/features/adoption/copies.js +29 -0
  24. package/dist/features/adoption/originals.js +116 -0
  25. package/dist/features/adoption/record.js +120 -0
  26. package/dist/features/adoption/restore.js +28 -0
  27. package/dist/features/adoption/scan.js +482 -0
  28. package/dist/features/adoption/undo.js +42 -0
  29. package/dist/features/asset-kinds/index.js +9 -0
  30. package/dist/features/auth/credentials.js +7 -14
  31. package/dist/features/auth/session.js +26 -5
  32. package/dist/features/auth/transport.js +3 -2
  33. package/dist/features/collaboration/workspace-git.js +13 -7
  34. package/dist/features/collaboration/workspace-github.js +2 -1
  35. package/dist/features/collaboration/workspace-store.js +25 -4
  36. package/dist/features/collaboration/workspace.js +22 -2
  37. package/dist/features/doctor/index.js +46 -7
  38. package/dist/features/environment/events.js +8 -1
  39. package/dist/features/environment/harnesses.js +36 -0
  40. package/dist/features/environment/kept-values.js +68 -0
  41. package/dist/features/environment/moves.js +187 -0
  42. package/dist/features/environment/names.js +10 -6
  43. package/dist/features/environment/operations.js +7 -7
  44. package/dist/features/environment/stage.js +25 -1
  45. package/dist/features/environment/sync.js +17 -6
  46. package/dist/features/environment/writes.js +55 -8
  47. package/dist/features/hooks/compatibility.js +11 -5
  48. package/dist/features/hooks/divergence.js +30 -9
  49. package/dist/features/hooks/test.js +25 -25
  50. package/dist/features/imports/discover.js +1 -1
  51. package/dist/features/imports/local.js +15 -2
  52. package/dist/features/imports/remote.js +2 -1
  53. package/dist/features/inventory/index.js +57 -3
  54. package/dist/features/inventory/show.js +74 -0
  55. package/dist/features/mcps/import.js +95 -21
  56. package/dist/features/mcps/index.js +24 -9
  57. package/dist/features/mcps/values.js +121 -0
  58. package/dist/features/migration/migrate.js +15 -0
  59. package/dist/features/migration/move.js +105 -25
  60. package/dist/features/migration/promote.js +2 -0
  61. package/dist/features/native/adapters.js +20 -7
  62. package/dist/features/native/configuration.js +8 -4
  63. package/dist/features/native/hook-shell.js +11 -0
  64. package/dist/features/native/secret-values.js +74 -0
  65. package/dist/features/secrets/index.js +142 -0
  66. package/dist/features/uninstall/index.js +126 -0
  67. package/dist/features/uninstall/leave.js +152 -0
  68. package/dist/features/uninstall/survey.js +103 -0
  69. package/dist/features/update-check/index.js +108 -0
  70. package/dist/features/workspace/format.js +19 -10
  71. package/dist/features/workspace/git.js +11 -4
  72. package/dist/features/workspace/overlay.js +23 -36
  73. package/dist/features/workspace/packages.js +16 -3
  74. package/dist/features/workspace/publish.js +1 -1
  75. package/dist/features/workspace/repo-source.js +4 -3
  76. package/dist/features/workspace/setup.js +12 -3
  77. package/dist/features/workspace/snapshot.js +7 -1
  78. package/dist/harnesses/claude.js +2 -2
  79. package/dist/harnesses/codex.js +54 -20
  80. package/dist/harnesses/cursor.js +2 -2
  81. package/dist/harnesses/formats.js +12 -5
  82. package/dist/harnesses/opencode.js +3 -6
  83. package/dist/harnesses/read-renamed-variables.js +141 -0
  84. package/dist/harnesses/renamed-variables.js +99 -0
  85. package/dist/platform.js +51 -12
  86. package/dist/program.js +68 -8
  87. package/dist/shared/files.js +35 -0
  88. package/dist/shared/lock.js +87 -23
  89. package/dist/shared/patterns.js +8 -0
  90. package/dist/shared/shell.js +0 -2
  91. package/dist/ui/add-hook.js +8 -2
  92. package/dist/ui/add-mcp.js +82 -13
  93. package/dist/ui/add-skills.js +7 -5
  94. package/dist/ui/adopt.js +202 -0
  95. package/dist/ui/assets.js +5 -3
  96. package/dist/ui/auth.js +2 -1
  97. package/dist/ui/clash.js +2 -3
  98. package/dist/ui/connection.js +9 -2
  99. package/dist/ui/harness-picker.js +23 -0
  100. package/dist/ui/mcp.js +89 -23
  101. package/dist/ui/move.js +49 -2
  102. package/dist/ui/onboarding.js +40 -27
  103. package/dist/ui/output.js +35 -8
  104. package/dist/ui/package-details.js +34 -0
  105. package/dist/ui/scope-install.js +4 -1
  106. package/dist/ui/secret-input.js +28 -0
  107. package/dist/ui/selection.js +3 -1
  108. package/dist/ui/uninstall.js +174 -0
  109. package/dist/ui/update.js +10 -0
  110. package/dist/version.js +2 -2
  111. package/package.json +1 -1
  112. package/dist/entry/mcp-launch.js +0 -71
package/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # BarnDog CLI
2
2
 
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.
3
+ Set up your AI coding environment once, and have it show up in Claude Code, Codex, or any other harness you love.
4
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.
5
+ `barndog` is the command-line tool for [BarnDog](https://barndog.dev). It installs Skills, MCP servers, Hooks, and knowledge into the coding agents you already use, keeps them up to date, and lets you improve them like code. It works the same whether it's just you, a small team, or a whole organization; only where the assets live changes.
6
6
 
7
7
  Currently supported harnesses:
8
8
 
@@ -13,24 +13,36 @@ Currently supported harnesses:
13
13
 
14
14
  ## Why
15
15
 
16
- 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
+ Every coding agent has its own place for skills, its own MCP config format, and its own hook settings. Keeping one setup consistent across them, or across a team, usually means copying files around and hoping nobody's copy is stale.
17
17
 
18
- 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
+ BarnDog keeps one setup and writes it into each tool in that tool's own format. You keep working in the agent you prefer.
19
+
20
+ ## Pick your setup
21
+
22
+ | Workspace | Run | Best for | What you get |
23
+ | ------------------ | --------------------------- | -------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
24
+ | **Local folder** | `barndog init --local` | Just you | One copy of your assets in every tool. No account, nothing shared. |
25
+ | **Git repository** | `barndog init --repo <url>` | Teams that want full control over their data | BarnDog stores nothing. You edit `barndog.yaml` and the folders by hand, and the repository's permissions decide who can change what. |
26
+ | **BarnDog Cloud** | `barndog init` | Teams of any size | A web catalog to manage, distribute, and discover assets, teams and people; per-team approval rules, and review in the terminal or the browser. |
27
+
28
+ Git trades discoverability for governance: there are no per-team approval rules, people management or web catalog, and a growing setup can get heavy to maintain by hand. BarnDog Cloud is free during the beta, and will stay free for teams of up to 5 people.
29
+
30
+ Installing and syncing work the same everywhere. Knowledge needs Git or Cloud. Switch later with `barndog local move` or `barndog migrate --to <server>`.
19
31
 
20
32
  ## How it works
21
33
 
22
34
  ```mermaid
23
35
  flowchart LR
24
- W["Your workspace<br/>BarnDog Cloud, a Git repo,<br/>or a local folder"] -->|barndog sync| C["barndog CLI"]
36
+ W["Your workspace<br/>a local folder, a Git repo,<br/>or BarnDog Cloud"] -->|barndog sync| C["barndog CLI"]
25
37
  C --> CC[Claude Code]
26
38
  C --> CX[Codex]
27
39
  C --> CU[Other harnesses]
28
40
  ```
29
41
 
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.
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.
42
+ 1. **Connect to a workspace.** `barndog init` points at a local folder, a Git repository, or a BarnDog server.
43
+ 2. **Choose what you want.** Pick your coding tools, then what to install. On BarnDog Cloud that means sets (the organization, your team, the repositories you work in) plus any individual assets.
32
44
  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.
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.
45
+ 4. **Improve.** Edit a local asset directly, or, in a Git or Cloud workspace, pull it into a folder, edit it, and `barndog push` it for review. Once merged, everyone gets the new version on their next sync.
34
46
 
35
47
  ## What it manages
36
48
 
@@ -39,7 +51,7 @@ flowchart LR
39
51
  | **Skill** | A folder with a `SKILL.md` and supporting files that agents load when relevant. |
40
52
  | **MCP server** | A connection to an MCP server. It names the secrets it needs but never stores their values. |
41
53
  | **Hook** | A command that runs on an agent lifecycle event, such as after a file edit. |
42
- | **Knowledge** | Company policies and context that agents can look up when a task needs it. |
54
+ | **Knowledge** | Policies and context that agents can look up when a task needs it (Git and Cloud). |
43
55
 
44
56
  ## Install
45
57
 
@@ -49,30 +61,30 @@ Runs on **macOS, Linux, and Windows** with [Node.js](https://nodejs.org) 24 or n
49
61
  npm install -g barndog
50
62
  ```
51
63
 
52
- ## Quick start
64
+ ### Update
53
65
 
54
66
  ```sh
55
- barndog init # connect, optionally sign in, choose tools and sets
56
- barndog status # what's installed on this machine, and where
57
- barndog skills search review # browse the shared catalog
58
- barndog skills install code-review # add one asset on top of your sets
59
- barndog sync # apply changes now
60
- barndog doctor # check everything and print a fix for each problem
67
+ npm install -g barndog@latest
68
+ barndog sync
69
+ barndog --version
61
70
  ```
62
71
 
63
- Run `barndog` on its own to see every command, or `barndog <command> --help` for its options.
64
-
65
- ### No BarnDog server? Use Git
72
+ Run `barndog sync` after every update: it brings the session-start and Hook registrations in your coding tools in line with the new version.
66
73
 
67
- 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:
74
+ ## Quick start
68
75
 
69
76
  ```sh
70
- barndog init --repo git@github.com:acme/ai-setup.git
77
+ barndog init # choose a workspace and your coding tools
78
+ barndog status # what's installed on this machine, and where
79
+ barndog skills add https://github.com/... # add a Skill from a repository
80
+ barndog skills search review # browse what the workspace offers
81
+ barndog sync # apply changes now
82
+ barndog doctor # check everything and print a fix for each problem
71
83
  ```
72
84
 
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.
85
+ Run `barndog` on its own to see every command, or `barndog <command> --help` for its options.
74
86
 
75
- ### Suggest a change
87
+ ### Suggest a change (Git and Cloud)
76
88
 
77
89
  ```sh
78
90
  barndog skills pull code-review --origin team/engineering
@@ -82,7 +94,7 @@ barndog diff
82
94
  barndog push --title "Add a security checklist"
83
95
  ```
84
96
 
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.
97
+ In a Git workspace this opens a pull request on your Git host. In BarnDog Cloud it creates a Suggested Change that reviewers handle with `barndog skills changes list`, `changes diff`, and `changes approve` (or the same under `barndog hooks`), or in the web workspace.
86
98
 
87
99
  ## What it changes on your machine
88
100
 
@@ -94,6 +106,15 @@ BarnDog is careful with your existing setup:
94
106
  - Changes are journaled before they're applied, so an interrupted sync is finished safely on the next run.
95
107
  - Hook scripts run only inside your coding tools, after their own trust checks. Installing or syncing never runs them.
96
108
 
109
+ ## Uninstall
110
+
111
+ ```sh
112
+ barndog uninstall
113
+ npm uninstall -g barndog
114
+ ```
115
+
116
+ Run `barndog uninstall` first. It asks whether to leave your Skills, MCP servers, and Hooks in your coding tools or remove them.
117
+
97
118
  ## Documentation
98
119
 
99
120
  - [What is BarnDog?](https://barndog.dev/docs)
package/dist/cli.js CHANGED
@@ -1,16 +1,21 @@
1
1
  #!/usr/bin/env node
2
+ import { spawn } from "node:child_process";
3
+ import { fileURLToPath } from "node:url";
2
4
  import { CommanderError, InvalidArgumentError } from "commander";
3
5
  import { assertCommandAvailable, currentSetupMode, } from "./commands/availability.js";
4
6
  import { captureRuntime, createProgram } from "./program.js";
5
7
  import { renderError, renderJsonError } from "./ui/output.js";
6
8
  import { json } from "./ui/format.js";
7
9
  import { CliError, NothingToDoError } from "./errors.js";
10
+ import { updateCheck } from "./features/update-check/index.js";
11
+ import { renderUpdateNotice } from "./ui/update.js";
12
+ import { cliVersion } from "./version.js";
8
13
  // Parsing errors happen before any action runs, so read the flag directly.
9
14
  const words = process.argv.slice(2);
10
15
  const end = words.indexOf("--");
11
16
  const asJson = (end < 0 ? words : words.slice(0, end)).includes("--json");
17
+ const runtime = captureRuntime();
12
18
  try {
13
- const runtime = captureRuntime();
14
19
  await createProgram({
15
20
  runtime,
16
21
  guard: (path, options) => assertCommandAvailable(path, options, runtime),
@@ -42,3 +47,24 @@ catch (error) {
42
47
  process.exitCode = 1;
43
48
  }
44
49
  }
50
+ // After the command, on stderr, so it never changes what a script reads; and
51
+ // it can never fail the command.
52
+ if (!asJson && process.stderr.isTTY) {
53
+ try {
54
+ const check = await updateCheck(cliVersion, runtime);
55
+ if (check?.update) {
56
+ console.error(renderUpdateNotice(check.update).join("\n"));
57
+ }
58
+ if (check?.due) {
59
+ spawn(process.execPath, [
60
+ fileURLToPath(new URL("entry/update-check.js", import.meta.url)),
61
+ runtime.home,
62
+ ], { detached: true, windowsHide: true, stdio: "ignore" })
63
+ .on("error", () => { })
64
+ .unref();
65
+ }
66
+ }
67
+ catch {
68
+ // The next command checks again.
69
+ }
70
+ }
@@ -63,6 +63,7 @@ export function registerAdd(program, context) {
63
63
  .option("--config <json>", "Server configuration as JSON text")
64
64
  .option("--file <path>", "Read the configuration from a file")
65
65
  .addOption(new Option("--from <harness>", "Import from a coding tool").choices(harnesses))
66
+ .option("--as <name>", "Add one MCP server under a different name")
66
67
  .option("--replace", "Replace an existing entry in your coding tools")
67
68
  .option("--oauth", "The server signs in through your coding tool (OAuth)")
68
69
  .option("--description <text>", "What the server does")
@@ -0,0 +1,91 @@
1
+ import { CliError } from "../errors.js";
2
+ import { offerAdoption, renderAdoption, renderAdoptions, renderScan, renderUndo, } from "../ui/adopt.js";
3
+ import { dim, json } from "../ui/format.js";
4
+ /** Registers `adopt`, `adopt list` and `adopt undo`. */
5
+ export function registerAdopt(program, context) {
6
+ const adopt = program
7
+ .command("adopt")
8
+ .description("Let BarnDog manage the Skills, MCP servers and Hooks your coding tools already have")
9
+ .option("--dry-run", "Show what can be adopted without changing anything")
10
+ .option("--all", "Adopt everything that can be adopted")
11
+ .option("--only <assets...>", "Adopt these, named tool/kind/name as --dry-run lists them")
12
+ .action(async (options) => {
13
+ if (options.all && options.only) {
14
+ throw new CliError("--all and --only can't be combined. Choose one.", "barndog adopt --help");
15
+ }
16
+ const scan = await context.scanNative();
17
+ if (options.dryRun) {
18
+ if (context.mode.json) {
19
+ return context.write(json(scan));
20
+ }
21
+ for (const line of renderScan(scan, context.runtime)) {
22
+ context.write(line);
23
+ }
24
+ return;
25
+ }
26
+ const keys = options.all
27
+ ? scan.assets.map((asset) => asset.key)
28
+ : options.only;
29
+ if (!keys) {
30
+ if (!context.mode.interactive) {
31
+ throw new CliError("Choose what to adopt with --only <tool/kind/name...> or --all; --dry-run lists the names.", "barndog adopt --dry-run");
32
+ }
33
+ if (!scan.assets.length) {
34
+ for (const line of renderScan(scan, context.runtime)) {
35
+ context.write(line);
36
+ }
37
+ return;
38
+ }
39
+ await offerAdoption(scan, {
40
+ adoptNative: context.adoptNative,
41
+ write: context.write,
42
+ runtime: context.runtime,
43
+ });
44
+ return;
45
+ }
46
+ if (!keys.length) {
47
+ return context.write(context.mode.json ? json({ adopted: [] }) : dim("Nothing to adopt."));
48
+ }
49
+ // Without a terminal nothing is kept; the notes say which variables to set.
50
+ const result = await context.adoptNative(keys, []);
51
+ if (context.mode.json) {
52
+ return context.write(json(result));
53
+ }
54
+ for (const line of renderAdoption(result, context.runtime)) {
55
+ context.write(line);
56
+ }
57
+ });
58
+ adopt
59
+ .command("list")
60
+ .description("List adoptions on this machine and what each took over")
61
+ .action(async () => {
62
+ const list = await context.listAdoptions();
63
+ if (context.mode.json) {
64
+ return context.write(json(list));
65
+ }
66
+ for (const line of renderAdoptions(list)) {
67
+ context.write(line);
68
+ }
69
+ });
70
+ adopt
71
+ .command("undo [id]")
72
+ .description("Put adopted assets back in their coding tools (the newest adoption by default)")
73
+ .option("--only <assets...>", "Put back only these, named tool/kind/name as adopt list shows them")
74
+ .option("--force", "Undo even if BarnDog's copy was edited since")
75
+ .action(async (id, _, command) => {
76
+ // Commander gives `--only` to `adopt`, which declares it too, wherever
77
+ // it appears; positional options would change how every command parses.
78
+ const options = command.optsWithGlobals();
79
+ const result = await context.undoAdoption({
80
+ id,
81
+ only: options.only,
82
+ force: options.force,
83
+ });
84
+ if (context.mode.json) {
85
+ return context.write(json(result));
86
+ }
87
+ for (const line of renderUndo(result, context.runtime)) {
88
+ context.write(line);
89
+ }
90
+ });
91
+ }
@@ -127,6 +127,7 @@ export function registerRename(command, kind, context) {
127
127
  target = item.id;
128
128
  const [type = "", slug = ""] = item.origin.split("/");
129
129
  suggestion = prefixedName({
130
+ kind: item.kind,
130
131
  name: item.name,
131
132
  origin: { type, slug },
132
133
  });
@@ -4,6 +4,7 @@ import { assetListing, inventoryHints, renderCatalog, renderInventory, } from ".
4
4
  import { dim, hint, json } from "../ui/format.js";
5
5
  import { assetKinds } from "../features/asset-kinds/index.js";
6
6
  import { addArguments } from "./arguments.js";
7
+ import { unsetVariableNotes } from "../ui/mcp.js";
7
8
  /** `list`: installed, disabled and available assets of one kind. */
8
9
  export function registerList(command, kind, context) {
9
10
  const labels = assetKinds[kind];
@@ -22,10 +23,12 @@ export function registerList(command, kind, context) {
22
23
  const onlyAvailable = options.available && !narrowed;
23
24
  let catalogProblem;
24
25
  const [inventory, rows] = await Promise.all([
25
- context.inventory(),
26
+ context.inventory({ checkVariables: kind === "mcp" }),
26
27
  options.available || !narrowed
27
28
  ? context.searchCatalog(kind).catch((error) => {
28
- if (onlyAvailable) {
29
+ // JSON has nowhere to say the list is partial, so it fails;
30
+ // --installed and --disabled don't need the catalog.
31
+ if (onlyAvailable || context.mode.json) {
29
32
  throw error;
30
33
  }
31
34
  catalogProblem = friendlyMessage(error);
@@ -81,6 +84,9 @@ export function registerList(command, kind, context) {
81
84
  }
82
85
  }
83
86
  const onThisMachine = page.filter((item) => item.state !== "available");
87
+ for (const line of unsetVariableNotes(onThisMachine)) {
88
+ context.write(line);
89
+ }
84
90
  const hints = inventoryHints(onThisMachine);
85
91
  if (hints.length) {
86
92
  context.write(["", ...hints].join("\n"));
@@ -111,7 +117,10 @@ export function registerSearch(command, kind, context) {
111
117
  selected: selected.has(row.id),
112
118
  }))));
113
119
  }
114
- for (const line of renderCatalog(rows, { ...options, search: query }, `barndog ${group} search`, selected)) {
120
+ for (const line of renderCatalog(rows, { ...options, search: query }, {
121
+ command: `barndog ${group} search`,
122
+ platform: context.runtime.platform,
123
+ }, selected)) {
115
124
  context.write(line);
116
125
  }
117
126
  };
@@ -22,16 +22,21 @@ export const cloudOnlyCommands = [
22
22
  /^(?:skills|mcp|hooks) (?:fork|promote)$/,
23
23
  /^mcp (?:create|update)$/,
24
24
  ];
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)$/,
29
+ /^mcp versions$/,
30
+ ];
31
+ /** Every `knowledge …` command. */
32
+ const KNOWLEDGE_COMMANDS = /^knowledge(?: |$)/;
25
33
  /**
26
- * Commands that need published versions and reviews, which a local folder lacks.
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.
27
36
  *
28
37
  * @internal Exported for its table test in `src/tests/patterns.test.ts`.
29
38
  */
30
- export const reviewCommands = [
31
- /^(?:pull|push|resolve)$/,
32
- /^(?:skills|hooks) (?:pull|push|create|versions|show|diff)$/,
33
- /^mcp versions$/,
34
- ];
39
+ export const sharedSourceCommands = [...reviewCommands, KNOWLEDGE_COMMANDS];
35
40
  /** The setup this machine runs on, when that setup limits what commands can do. */
36
41
  export async function currentSetupMode(runtime) {
37
42
  const { home } = runtime;
@@ -50,11 +55,20 @@ export function commandNeeds(command, mode) {
50
55
  return "cloud";
51
56
  }
52
57
  if (mode === "local" &&
53
- reviewCommands.some((pattern) => pattern.test(command))) {
58
+ sharedSourceCommands.some((pattern) => pattern.test(command))) {
54
59
  return "shared";
55
60
  }
56
61
  return undefined;
57
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
+ }
58
72
  export const needText = (need) => need === "cloud" ? "a Cloud Workspace" : "a Git repo or Cloud Workspace";
59
73
  export const modeName = (mode) => mode === "local" ? "local" : "Git";
60
74
  /** Help's note beside a command this setup can't run. */
@@ -104,11 +118,14 @@ export async function assertCommandAvailable(path, options, runtime) {
104
118
  if (command.endsWith(" promote") && options.origin === LOCAL_ORIGIN) {
105
119
  return;
106
120
  }
107
- const needs = commandNeeds(command, git ? "git" : "local");
121
+ const needs = setupNeeds(command, options, git ? "git" : "local");
108
122
  if (needs === "cloud") {
109
123
  const action = why[command] ?? "needs a BarnDog Cloud Workspace";
110
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>");
111
125
  }
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
+ }
112
129
  if (needs === "shared") {
113
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");
114
131
  }
@@ -71,7 +71,7 @@ function registerGeneral(program, context) {
71
71
  }
72
72
  if (!result.root) {
73
73
  context.write("Not inside a Git repository.");
74
- context.write(hint("cd <your-repository> && barndog repo status", "Tip"));
74
+ context.write(`${dim("Tip:")} run ${bold("barndog repo status")} from inside your repository.`);
75
75
  return;
76
76
  }
77
77
  const repositoryId = result.repository?.id;
@@ -118,7 +118,13 @@ function registerGeneral(program, context) {
118
118
  const mark = checkMarks[check.status];
119
119
  context.write(`${mark} ${check.name.padEnd(width)} ${check.status === "ok" ? dim(check.detail) : check.detail}`);
120
120
  if (check.fix) {
121
- context.write(` ${" ".repeat(width)} ${hint(check.fix, "Fix")}`);
121
+ // A fix in words reads as plain text when a command follows it.
122
+ context.write(check.command
123
+ ? ` ${" ".repeat(width)} ${dim("Fix:")} ${check.fix}`
124
+ : ` ${" ".repeat(width)} ${hint(check.fix, "Fix")}`);
125
+ }
126
+ if (check.command) {
127
+ context.write(` ${" ".repeat(width)} ${dim("Command:")} ${bold(check.command)}`);
122
128
  }
123
129
  }
124
130
  const failed = checks.filter((c) => c.status === "fail").length;
@@ -9,6 +9,7 @@ import { ApiError } from "@barndog-ai/api-contract";
9
9
  import { assetKinds } from "../features/asset-kinds/index.js";
10
10
  import { packageKindList } from "../config/selection.js";
11
11
  import { pickOne } from "../ui/pick.js";
12
+ import { renderPackageDetails } from "../ui/package-details.js";
12
13
  import { resolveOrigin } from "./origin.js";
13
14
  import { clean, json, ORIGIN_HELP, originLabel, warn } from "../ui/format.js";
14
15
  import { defined } from "../shared/lookup.js";
@@ -108,6 +109,15 @@ export function registerCollaboration(program, context, kind) {
108
109
  const noun = assetKinds[kind].one;
109
110
  const group = assetKinds[kind].command;
110
111
  const kindCommand = defined(program.commands.find((c) => c.name() === group), `Command group ${group} isn't registered`);
112
+ const describe = async (name, origin) => {
113
+ const details = await context.showPackage(kind, name, origin);
114
+ if (context.mode.json) {
115
+ return context.write(json(details));
116
+ }
117
+ for (const line of renderPackageDetails(details)) {
118
+ context.write(line);
119
+ }
120
+ };
111
121
  /** Fills a missing name and origin from a searchable catalog list. */
112
122
  const choose = async (name, origin, usage) => {
113
123
  if (name) {
@@ -152,7 +162,10 @@ export function registerCollaboration(program, context, kind) {
152
162
  "versions",
153
163
  `List ${noun === "Skill" ? "a Skill's" : "a Hook's"} published versions`,
154
164
  ],
155
- ["show", "Print the files of a published version"],
165
+ [
166
+ "show",
167
+ `Describe ${noun === "Skill" ? "a Skill" : "a Hook"}: origin, version, where it's installed`,
168
+ ],
156
169
  ["diff", "Compare two published versions"],
157
170
  ]) {
158
171
  const command = kindCommand
@@ -160,7 +173,9 @@ export function registerCollaboration(program, context, kind) {
160
173
  .description(description)
161
174
  .option("--origin <origin>", ORIGIN_HELP);
162
175
  if (name === "show") {
163
- command.option("--version <number>", "Published version", positiveInteger);
176
+ command
177
+ .option("--files", "Print the files of the published version")
178
+ .option("--version <number>", "Print the files of this published version", positiveInteger);
164
179
  }
165
180
  if (name === "diff") {
166
181
  command
@@ -175,6 +190,11 @@ export function registerCollaboration(program, context, kind) {
175
190
  if (name === "versions") {
176
191
  await run(context.packageVersions(target));
177
192
  }
193
+ else if (name === "show" &&
194
+ !options.files &&
195
+ options.version === undefined) {
196
+ await describe(target.name, target.origin);
197
+ }
178
198
  else if (name === "show") {
179
199
  await run(context.versionFiles(target));
180
200
  }
@@ -0,0 +1,104 @@
1
+ import { Argument } from "commander";
2
+ import { styleText } from "node:util";
3
+ import { CliError } from "../errors.js";
4
+ import { harnesses } from "../harnesses/registry.js";
5
+ import { toolNames } from "../features/hooks/adapt.js";
6
+ import { bold, dim, json, ok, table } from "../ui/format.js";
7
+ import { chooseHarnesses } from "../ui/harness-picker.js";
8
+ import { renderSyncOutput } from "../ui/output.js";
9
+ function managedLine(managed) {
10
+ return managed.length
11
+ ? `${ok("✔")} BarnDog now manages ${toolNames(managed)}.`
12
+ : `${ok("✔")} BarnDog no longer manages any coding tool. Add one with ${styleText("bold", "barndog harnesses enable <harness>")}.`;
13
+ }
14
+ const pickMessage = {
15
+ enable: "Which coding tools should BarnDog start managing?",
16
+ disable: "Which coding tools should BarnDog stop managing?",
17
+ };
18
+ const nothingTo = {
19
+ enable: "BarnDog already manages every coding tool it supports.",
20
+ disable: "BarnDog doesn't manage any coding tool.",
21
+ };
22
+ const nothingToHint = {
23
+ enable: "barndog harnesses list",
24
+ disable: "barndog harnesses enable <harness>",
25
+ };
26
+ function harnessTable(rows) {
27
+ return table(rows.map((row) => [
28
+ bold(row.id),
29
+ row.name,
30
+ row.enabled ? ok("managed") : dim("off"),
31
+ row.evidence ? dim(row.evidence) : dim("not found"),
32
+ ]), { header: ["Harness", "Tool", "State", "Detected"] });
33
+ }
34
+ export function registerHarnesses(program, context) {
35
+ const group = program
36
+ .command("harnesses")
37
+ .description("Choose which coding tools BarnDog manages; a tool turned off loses everything BarnDog installed there");
38
+ group
39
+ .command("list", { isDefault: true })
40
+ .description("List supported coding tools and whether BarnDog manages them")
41
+ .action(async () => {
42
+ const rows = await context.listHarnesses();
43
+ if (context.mode.json) {
44
+ return context.write(json(rows));
45
+ }
46
+ for (const line of harnessTable(rows)) {
47
+ context.write(line);
48
+ }
49
+ });
50
+ const report = (result) => {
51
+ if (context.mode.json) {
52
+ return context.write(json(result));
53
+ }
54
+ for (const line of renderSyncOutput(result.events)) {
55
+ context.write(line);
56
+ }
57
+ context.write(managedLine(result.harnesses));
58
+ };
59
+ // With no tools named, a terminal picks from the ones the change applies to.
60
+ const pickTargets = async (change) => {
61
+ const usage = `barndog harnesses ${change} <harness>`;
62
+ if (!context.mode.interactive) {
63
+ throw new CliError(`Name the coding tools to ${change}.`, usage);
64
+ }
65
+ const offered = (await context.listHarnesses()).filter((row) => row.enabled === (change === "disable"));
66
+ if (offered.length === 0) {
67
+ throw new CliError(nothingTo[change], nothingToHint[change]);
68
+ }
69
+ return chooseHarnesses(offered.map((row) => ({
70
+ value: row.id,
71
+ name: row.name,
72
+ evidence: row.evidence,
73
+ checked: false,
74
+ })), { message: pickMessage[change], required: true });
75
+ };
76
+ for (const change of ["enable", "disable"]) {
77
+ group
78
+ .command(change)
79
+ .description(change === "enable"
80
+ ? "Start installing your selection into these coding tools"
81
+ : "Remove everything BarnDog installed in these coding tools and stop installing there")
82
+ .addArgument(new Argument("[harnesses...]", "Coding tools").choices(harnesses))
83
+ .action(async (named) => {
84
+ const targets = named.length ? named : await pickTargets(change);
85
+ report(await context.changeHarnesses(change, targets));
86
+ });
87
+ }
88
+ group
89
+ .command("select")
90
+ .description("Choose from a list exactly which coding tools BarnDog manages")
91
+ .action(async () => {
92
+ if (!context.mode.interactive) {
93
+ throw new CliError("Choosing coding tools from a list needs a terminal.", "barndog harnesses enable <harness>");
94
+ }
95
+ const rows = await context.listHarnesses();
96
+ const chosen = await chooseHarnesses(rows.map((row) => ({
97
+ value: row.id,
98
+ name: row.name,
99
+ evidence: row.evidence,
100
+ checked: row.enabled,
101
+ })));
102
+ report(await context.selectHarnesses(chosen));
103
+ });
104
+ }