barndog 0.1.0 → 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 +11 -10
- 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 +24 -11
- 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/dist/program.js
CHANGED
|
@@ -1,16 +1,33 @@
|
|
|
1
|
+
import { resolve } from "node:path";
|
|
1
2
|
import { Command, Help, Option } from "commander";
|
|
3
|
+
import { homedir } from "node:os";
|
|
2
4
|
import { styleText } from "node:util";
|
|
3
|
-
import { registerCollaboration } from "./commands/collaboration.js";
|
|
4
|
-
import {
|
|
5
|
+
import { registerCollaboration, registerWorkingCopy, } from "./commands/collaboration.js";
|
|
6
|
+
import { applySuggestion, changeDiff, commentOnChange, createPackage, diffVersions, listChanges, mergeChange, packageVersions, pullPackage, pushWorkingCopy, rejectChange, resolveFile, reviewChange, setDiscussionResolved, showChange, updateWorkingCopy, versionFiles, workingDiff, workingStatus, } from "./features/collaboration/index.js";
|
|
5
7
|
import { registerAuth } from "./commands/auth.js";
|
|
6
8
|
import { runLogin, runLogout, showAuthStatus } from "./ui/auth.js";
|
|
7
9
|
import { registerInit } from "./commands/init.js";
|
|
8
10
|
import { registerSync } from "./commands/sync.js";
|
|
9
11
|
import { registerStatus } from "./commands/status.js";
|
|
10
|
-
import { settingsPath } from "./config/settings.js";
|
|
11
12
|
import { clashPrompt, synchronize } from "./features/environment/sync.js";
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
13
|
+
import { changeAsset, changeAssets, changeSet, installSet, installSetAssets, listSets, previewSet, renameAsset, setKnowledge, switchSet, } from "./features/environment/operations.js";
|
|
14
|
+
import { doctor } from "./features/doctor/index.js";
|
|
15
|
+
import { repoStatus, workspaceUrl } from "./features/inspection/index.js";
|
|
16
|
+
import { validateFolder } from "./features/workspace/assets.js";
|
|
17
|
+
import { migrate } from "./features/migration/migrate.js";
|
|
18
|
+
import { listLocalAssets, moveLocalAssets } from "./features/migration/move.js";
|
|
19
|
+
import { updateImported } from "./features/imports/local.js";
|
|
20
|
+
import { authenticateMcp, createMcp, mcpVersions, showMcp, updateMcp, } from "./features/mcps/index.js";
|
|
21
|
+
import { adaptHook, toolNames } from "./features/hooks/adapt.js";
|
|
22
|
+
import { harnesses } from "./harnesses/registry.js";
|
|
23
|
+
import { hookCompatibility } from "./features/hooks/compatibility.js";
|
|
24
|
+
import { testHook } from "./features/hooks/test.js";
|
|
25
|
+
import { knowledgeGet, knowledgeList, knowledgeProblems, } from "./features/knowledge/index.js";
|
|
26
|
+
import { developerAssets, developers, fork, } from "./features/discovery/index.js";
|
|
27
|
+
import { promote } from "./features/migration/promote.js";
|
|
28
|
+
import { githubAuth, githubInstall, githubInstallations, githubStatus, } from "./features/github/account.js";
|
|
29
|
+
import { githubConnect, githubCreateRepository, githubImport, githubImportCopy, githubList, githubRemoteHead, githubResolveMirror, githubShow, githubSync, } from "./features/github/connections.js";
|
|
30
|
+
import { githubPullsComment, githubPullsCreate, githubPullsList, githubPullsMerge, githubPullsReview, githubPullsRevise, githubPullsShow, } from "./features/github/pulls.js";
|
|
14
31
|
import { inventory } from "./features/inventory/index.js";
|
|
15
32
|
import { searchCatalog } from "./features/catalog/index.js";
|
|
16
33
|
import { registerEnvironment } from "./commands/environment.js";
|
|
@@ -23,6 +40,10 @@ import { interactiveTerminal } from "./ui/pick.js";
|
|
|
23
40
|
import { promptClash } from "./ui/clash.js";
|
|
24
41
|
import { primary } from "./ui/theme.js";
|
|
25
42
|
import { versionReport } from "./version.js";
|
|
43
|
+
import { defined } from "./shared/lookup.js";
|
|
44
|
+
import { barndogPaths } from "./config/paths.js";
|
|
45
|
+
/** Keep command help readable at the conventional eighty-column terminal width. */
|
|
46
|
+
const HELP_WIDTH = 80;
|
|
26
47
|
/** Help sections, in order; every top-level command belongs to one. */
|
|
27
48
|
const groups = [
|
|
28
49
|
[
|
|
@@ -32,7 +53,7 @@ const groups = [
|
|
|
32
53
|
["Assets:", ["skills", "mcp", "hooks", "sets", "knowledge"]],
|
|
33
54
|
[
|
|
34
55
|
"Working copy & review (run inside a folder from `skills pull`, `hooks pull` or `create`):",
|
|
35
|
-
["pull", "diff", "push", "resolve"
|
|
56
|
+
["pull", "diff", "push", "resolve"],
|
|
36
57
|
],
|
|
37
58
|
[
|
|
38
59
|
"Workspace:",
|
|
@@ -63,26 +84,41 @@ const assetGroups = [
|
|
|
63
84
|
["Test and adapt:", ["test", "compatibility", "adapt"]],
|
|
64
85
|
];
|
|
65
86
|
/** The command's words without the program name, as availability rules name them. */
|
|
87
|
+
/** The help section of a command in an asset group. */
|
|
88
|
+
function helpGroup(group, command, heading) {
|
|
89
|
+
// MCP create/show/versions publish or inspect definitions directly.
|
|
90
|
+
if (group === "mcp" && ["create", "show", "versions"].includes(command)) {
|
|
91
|
+
return "Publish directly:";
|
|
92
|
+
}
|
|
93
|
+
if (group !== "mcp" && command === "update") {
|
|
94
|
+
return "On this machine:";
|
|
95
|
+
}
|
|
96
|
+
return heading;
|
|
97
|
+
}
|
|
66
98
|
function commandPath(command) {
|
|
67
99
|
const path = [];
|
|
68
|
-
for (let c = command; c?.parent; c = c.parent)
|
|
100
|
+
for (let c = command; c?.parent; c = c.parent) {
|
|
69
101
|
path.unshift(c.name());
|
|
102
|
+
}
|
|
70
103
|
return path.join(" ");
|
|
71
104
|
}
|
|
72
105
|
/** A group is unavailable only when nothing inside it can run. */
|
|
73
106
|
function helpNeed(command, mode) {
|
|
74
107
|
const children = command.commands.filter((c) => c.name() !== "help");
|
|
75
|
-
if (!children.length)
|
|
108
|
+
if (!children.length) {
|
|
76
109
|
return commandNeeds(commandPath(command), mode);
|
|
110
|
+
}
|
|
77
111
|
const needs = children.map((child) => helpNeed(child, mode));
|
|
78
|
-
if (!needs.every(Boolean))
|
|
112
|
+
if (!needs.every(Boolean)) {
|
|
79
113
|
return undefined;
|
|
114
|
+
}
|
|
80
115
|
return needs.includes("shared") ? "shared" : "cloud";
|
|
81
116
|
}
|
|
82
117
|
function listsUnavailable(command) {
|
|
83
118
|
let root = command;
|
|
84
|
-
while (root.parent)
|
|
119
|
+
while (root.parent) {
|
|
85
120
|
root = root.parent;
|
|
121
|
+
}
|
|
86
122
|
return root.opts().listUnavailable === true;
|
|
87
123
|
}
|
|
88
124
|
/** Hides what this setup can't run, unless asked for or already looking at one. */
|
|
@@ -101,8 +137,9 @@ function limitedHelp(mode) {
|
|
|
101
137
|
},
|
|
102
138
|
subcommandTerm(command) {
|
|
103
139
|
const term = Help.prototype.subcommandTerm.call(this, command);
|
|
104
|
-
if (note(command))
|
|
140
|
+
if (note(command)) {
|
|
105
141
|
dimmed.add(term);
|
|
142
|
+
}
|
|
106
143
|
return term;
|
|
107
144
|
},
|
|
108
145
|
subcommandDescription(command) {
|
|
@@ -120,21 +157,24 @@ function limitedHelp(mode) {
|
|
|
120
157
|
/** The closing lines of help: what was left out, why, and how to see it. */
|
|
121
158
|
function unavailableHint(command, mode) {
|
|
122
159
|
const own = helpNeed(command, mode);
|
|
123
|
-
if (own)
|
|
160
|
+
if (own) {
|
|
124
161
|
return `\n${styleText("dim", unavailableNote(own, mode))}`;
|
|
125
|
-
|
|
162
|
+
}
|
|
163
|
+
if (listsUnavailable(command)) {
|
|
126
164
|
return "";
|
|
165
|
+
}
|
|
127
166
|
const hidden = new Help().visibleCommands(command).flatMap((child) => {
|
|
128
167
|
const need = helpNeed(child, mode);
|
|
129
168
|
return need ? [{ name: child.name(), need }] : [];
|
|
130
169
|
});
|
|
131
|
-
if (!hidden.length)
|
|
170
|
+
if (!hidden.length) {
|
|
132
171
|
return "";
|
|
172
|
+
}
|
|
133
173
|
const need = hidden.some((c) => c.need === "shared") ? "shared" : "cloud";
|
|
134
174
|
const one = hidden.length === 1;
|
|
135
175
|
const path = commandPath(command);
|
|
136
176
|
const help = new Help();
|
|
137
|
-
const width = Math.min(process.stdout.columns ||
|
|
177
|
+
const width = Math.min(process.stdout.columns || HELP_WIDTH, HELP_WIDTH);
|
|
138
178
|
const lines = [
|
|
139
179
|
`${one ? "One command is" : "Some commands are"} hidden in ${modeName(mode)} mode because ${one ? "it needs" : "they need"} ${needText(need)}: ${hidden.map((c) => c.name).join(", ")}.`,
|
|
140
180
|
`Run barndog ${path ? `${path} ` : ""}--help --list-unavailable to see ${one ? "it" : "them"}.`,
|
|
@@ -146,48 +186,173 @@ function unavailableHint(command, mode) {
|
|
|
146
186
|
* here before complaining about its flags. Help stays available either way.
|
|
147
187
|
*/
|
|
148
188
|
function guardRequiredOptions(parent, guard) {
|
|
149
|
-
for (const child of parent.commands)
|
|
189
|
+
for (const child of parent.commands) {
|
|
150
190
|
guardRequiredOptions(child, guard);
|
|
151
|
-
|
|
191
|
+
}
|
|
192
|
+
if (!parent.commands.length) {
|
|
152
193
|
return;
|
|
194
|
+
}
|
|
153
195
|
parent.hook("preSubcommand", async (_, command) => {
|
|
154
|
-
if (command.commands.length || !command.options.some((o) => o.mandatory))
|
|
196
|
+
if (command.commands.length || !command.options.some((o) => o.mandatory)) {
|
|
155
197
|
return;
|
|
198
|
+
}
|
|
156
199
|
let root = parent;
|
|
157
|
-
while (root.parent)
|
|
200
|
+
while (root.parent) {
|
|
158
201
|
root = root.parent;
|
|
202
|
+
}
|
|
159
203
|
const { rawArgs = [] } = root;
|
|
160
|
-
if (rawArgs.includes("--help") || rawArgs.includes("-h"))
|
|
204
|
+
if (rawArgs.includes("--help") || rawArgs.includes("-h")) {
|
|
161
205
|
return;
|
|
206
|
+
}
|
|
162
207
|
await guard(commandPath(command).split(" "), {});
|
|
163
208
|
});
|
|
164
209
|
}
|
|
210
|
+
/** Process entry points capture ambient inputs here; downstream code receives this object. */
|
|
211
|
+
export function captureRuntime(options = {}) {
|
|
212
|
+
const cwd = resolve(options.cwd ?? process.cwd());
|
|
213
|
+
return {
|
|
214
|
+
home: resolve(cwd, options.home ?? homedir()),
|
|
215
|
+
cwd,
|
|
216
|
+
env: { ...(options.env ?? process.env) },
|
|
217
|
+
platform: options.platform ?? process.platform,
|
|
218
|
+
};
|
|
219
|
+
}
|
|
165
220
|
/** Construct a fresh parser for every invocation or test; command behavior is independently injectable. */
|
|
166
221
|
export function createProgram(options = {}) {
|
|
167
222
|
const write = options.write ?? console.log;
|
|
223
|
+
// The one place the real home directory is read; everything below takes it.
|
|
224
|
+
const runtime = options.runtime ?? captureRuntime(options);
|
|
225
|
+
const { home } = runtime;
|
|
168
226
|
const mode = {
|
|
169
227
|
json: false,
|
|
170
228
|
interactive: options.interactive ?? interactiveTerminal(),
|
|
171
229
|
};
|
|
172
230
|
const context = {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
231
|
+
applySuggestion: options.applySuggestion ?? ((target) => applySuggestion(target, runtime)),
|
|
232
|
+
changeDiff: options.changeDiff ?? ((target) => changeDiff(target, runtime)),
|
|
233
|
+
commentOnChange: options.commentOnChange ??
|
|
234
|
+
((options) => commentOnChange(options, runtime)),
|
|
235
|
+
createPackage: options.createPackage ?? ((target) => createPackage(target, runtime)),
|
|
236
|
+
diffVersions: options.diffVersions ?? ((target) => diffVersions(target, runtime)),
|
|
237
|
+
listChanges: options.listChanges ?? ((options) => listChanges(options, runtime)),
|
|
238
|
+
mergeChange: options.mergeChange ?? ((target) => mergeChange(target, runtime)),
|
|
239
|
+
packageVersions: options.packageVersions ?? ((target) => packageVersions(target, runtime)),
|
|
240
|
+
pullPackage: options.pullPackage ?? ((target) => pullPackage(target, runtime)),
|
|
241
|
+
pushWorkingCopy: options.pushWorkingCopy ??
|
|
242
|
+
((options) => pushWorkingCopy(options, runtime)),
|
|
243
|
+
rejectChange: options.rejectChange ?? ((target) => rejectChange(target, runtime)),
|
|
244
|
+
resolveFile: options.resolveFile ?? ((path) => resolveFile(path, runtime)),
|
|
245
|
+
reviewChange: options.reviewChange ??
|
|
246
|
+
((decision, target) => reviewChange(decision, target, runtime)),
|
|
247
|
+
setDiscussionResolved: options.setDiscussionResolved ??
|
|
248
|
+
((target) => setDiscussionResolved(target, runtime)),
|
|
249
|
+
showChange: options.showChange ?? ((target) => showChange(target, runtime)),
|
|
250
|
+
updateWorkingCopy: options.updateWorkingCopy ?? (() => updateWorkingCopy(runtime)),
|
|
251
|
+
versionFiles: options.versionFiles ?? ((target) => versionFiles(target, runtime)),
|
|
252
|
+
workingDiff: options.workingDiff ?? (() => workingDiff(runtime)),
|
|
253
|
+
workingStatus: options.workingStatus ?? (() => workingStatus(runtime)),
|
|
254
|
+
login: options.login ?? ((login) => runLogin({ ...login, runtime }, write)),
|
|
255
|
+
logout: options.logout ?? (() => runLogout(write, runtime)),
|
|
256
|
+
authStatus: options.authStatus ??
|
|
257
|
+
(() => showAuthStatus({ write, json: mode.json }, runtime)),
|
|
177
258
|
setup: options.setup ??
|
|
178
|
-
((restart, server, setupOptions) => runSetup({
|
|
179
|
-
|
|
180
|
-
|
|
259
|
+
((restart, server, setupOptions) => runSetup({
|
|
260
|
+
restart,
|
|
261
|
+
server,
|
|
262
|
+
...setupOptions,
|
|
263
|
+
write: options.write,
|
|
264
|
+
runtime,
|
|
265
|
+
})),
|
|
266
|
+
changeAsset: options.changeAsset ??
|
|
267
|
+
((change, target) => changeAsset(change, target, runtime)),
|
|
268
|
+
changeAssets: options.changeAssets ??
|
|
269
|
+
((change, target) => changeAssets(change, target, runtime)),
|
|
270
|
+
renameAsset: options.renameAsset ?? ((target) => renameAsset(target, runtime)),
|
|
271
|
+
listSets: options.listSets ?? (() => listSets(runtime)),
|
|
272
|
+
previewSet: options.previewSet ?? ((origin) => previewSet(origin, runtime)),
|
|
273
|
+
installSet: options.installSet ?? ((options) => installSet(options, runtime)),
|
|
274
|
+
installSetAssets: options.installSetAssets ??
|
|
275
|
+
((options) => installSetAssets(options, runtime)),
|
|
276
|
+
changeSet: options.changeSet ??
|
|
277
|
+
((change, options) => changeSet(change, options, runtime)),
|
|
278
|
+
switchSet: options.switchSet ?? ((options) => switchSet(options, runtime)),
|
|
279
|
+
setKnowledge: options.setKnowledge ?? ((enabled) => setKnowledge(enabled, runtime)),
|
|
280
|
+
doctor: options.doctor ?? (() => doctor(runtime)),
|
|
281
|
+
workspaceUrl: options.workspaceUrl ?? (() => workspaceUrl(runtime)),
|
|
282
|
+
repoStatus: options.repoStatus ?? (() => repoStatus(runtime)),
|
|
283
|
+
listLocalAssets: options.listLocalAssets ?? (() => listLocalAssets(runtime)),
|
|
284
|
+
knowledgeProblems: options.knowledgeProblems ?? (() => knowledgeProblems(runtime)),
|
|
285
|
+
githubStatus: options.githubStatus ?? (() => githubStatus(runtime)),
|
|
286
|
+
githubInstallations: options.githubInstallations ?? (() => githubInstallations(runtime)),
|
|
287
|
+
githubList: options.githubList ?? (() => githubList(runtime)),
|
|
288
|
+
validateFolder: options.validateFolder ??
|
|
289
|
+
((directory) => validateFolder(directory, runtime)),
|
|
290
|
+
migrate: options.migrate ?? ((options) => migrate(options, runtime)),
|
|
291
|
+
moveLocalAssets: options.moveLocalAssets ??
|
|
292
|
+
((options) => moveLocalAssets(options, runtime)),
|
|
293
|
+
updateImported: options.updateImported ??
|
|
294
|
+
((kind, name, options) => updateImported(kind, name, options, runtime)),
|
|
295
|
+
showMcp: options.showMcp ?? ((name, origin) => showMcp(name, origin, runtime)),
|
|
296
|
+
createMcp: options.createMcp ?? ((input) => createMcp(input, runtime)),
|
|
297
|
+
updateMcp: options.updateMcp ?? ((input) => updateMcp(input, runtime)),
|
|
298
|
+
mcpVersions: options.mcpVersions ??
|
|
299
|
+
((name, origin) => mcpVersions(name, origin, runtime)),
|
|
300
|
+
authenticateMcp: options.authenticateMcp ??
|
|
301
|
+
((name, origin, harness) => authenticateMcp(name, origin, harness, runtime)),
|
|
302
|
+
testHook: options.testHook ??
|
|
303
|
+
((name, origin, testOptions) => testHook(name, origin, testOptions, runtime)),
|
|
304
|
+
hookCompatibility: options.hookCompatibility ??
|
|
305
|
+
((name, origin) => hookCompatibility(name, origin, runtime)),
|
|
306
|
+
adaptHook: options.adaptHook ??
|
|
307
|
+
((name, origin, targets) => adaptHook(name, origin, targets, runtime)),
|
|
308
|
+
knowledgeGet: options.knowledgeGet ?? ((name) => knowledgeGet(name, runtime)),
|
|
309
|
+
developers: options.developers ?? ((search) => developers(search, runtime)),
|
|
310
|
+
developerAssets: options.developerAssets ??
|
|
311
|
+
((selector, search) => developerAssets(selector, search, runtime)),
|
|
312
|
+
promote: options.promote ?? ((input) => promote(input, runtime)),
|
|
313
|
+
fork: options.fork ?? ((input) => fork(input, runtime)),
|
|
314
|
+
githubAuth: options.githubAuth ?? (() => githubAuth(runtime)),
|
|
315
|
+
githubInstall: options.githubInstall ?? (() => githubInstall(runtime)),
|
|
316
|
+
githubConnect: options.githubConnect ?? ((options) => githubConnect(options, runtime)),
|
|
317
|
+
githubImport: options.githubImport ?? ((options) => githubImport(options, runtime)),
|
|
318
|
+
githubImportCopy: options.githubImportCopy ??
|
|
319
|
+
((options) => githubImportCopy(options, runtime)),
|
|
320
|
+
githubCreateRepository: options.githubCreateRepository ??
|
|
321
|
+
((options) => githubCreateRepository(options, runtime)),
|
|
322
|
+
githubShow: options.githubShow ??
|
|
323
|
+
((connectionId) => githubShow(connectionId, runtime)),
|
|
324
|
+
githubSync: options.githubSync ??
|
|
325
|
+
((connectionId) => githubSync(connectionId, runtime)),
|
|
326
|
+
githubRemoteHead: options.githubRemoteHead ??
|
|
327
|
+
((connectionId) => githubRemoteHead(connectionId, runtime)),
|
|
328
|
+
githubResolveMirror: options.githubResolveMirror ??
|
|
329
|
+
((options) => githubResolveMirror(options, runtime)),
|
|
330
|
+
githubPullsList: options.githubPullsList ??
|
|
331
|
+
((connectionId) => githubPullsList(connectionId, runtime)),
|
|
332
|
+
githubPullsShow: options.githubPullsShow ??
|
|
333
|
+
((connectionId, number) => githubPullsShow(connectionId, number, runtime)),
|
|
334
|
+
githubPullsCreate: options.githubPullsCreate ??
|
|
335
|
+
((options) => githubPullsCreate(options, runtime)),
|
|
336
|
+
githubPullsRevise: options.githubPullsRevise ??
|
|
337
|
+
((options) => githubPullsRevise(options, runtime)),
|
|
338
|
+
githubPullsReview: options.githubPullsReview ??
|
|
339
|
+
((options) => githubPullsReview(options, runtime)),
|
|
340
|
+
githubPullsComment: options.githubPullsComment ??
|
|
341
|
+
((options) => githubPullsComment(options, runtime)),
|
|
342
|
+
githubPullsMerge: options.githubPullsMerge ??
|
|
343
|
+
((options) => githubPullsMerge(options, runtime)),
|
|
344
|
+
knowledgeList: options.knowledgeList ?? ((always) => knowledgeList(always, runtime)),
|
|
181
345
|
synchronize: options.synchronize ??
|
|
182
|
-
((path, syncOptions) => synchronize(path,
|
|
183
|
-
inventory: options.inventory ?? (() => inventory()),
|
|
184
|
-
searchCatalog: options.searchCatalog ?? ((kind) => searchCatalog(kind)),
|
|
346
|
+
((path, syncOptions) => synchronize(path, runtime, undefined, syncOptions)),
|
|
347
|
+
inventory: options.inventory ?? (() => inventory(runtime)),
|
|
348
|
+
searchCatalog: options.searchCatalog ?? ((kind) => searchCatalog(kind, runtime)),
|
|
185
349
|
write,
|
|
186
350
|
mode,
|
|
351
|
+
runtime,
|
|
187
352
|
};
|
|
188
353
|
const program = new Command()
|
|
189
354
|
.name("barndog")
|
|
190
|
-
.description(`${primary(styleText("bold", "BarnDog"))} keeps your team's Skills, MCP servers and Hooks in sync across
|
|
355
|
+
.description(`${primary(styleText("bold", "BarnDog"))} keeps your team's Skills, MCP servers and Hooks in sync across ${toolNames(harnesses)}.`)
|
|
191
356
|
.exitOverride()
|
|
192
357
|
.configureOutput({
|
|
193
358
|
writeOut: (text) => context.write(text.trimEnd()),
|
|
@@ -204,16 +369,17 @@ export function createProgram(options = {}) {
|
|
|
204
369
|
styleOptionDescription: (text) => styleText("dim", text),
|
|
205
370
|
...(options.setupMode ? limitedHelp(options.setupMode) : {}),
|
|
206
371
|
})
|
|
207
|
-
.version(versionReport(), "-V, --version", "Show the version and build")
|
|
372
|
+
.version(versionReport(runtime.platform), "-V, --version", "Show the version and build")
|
|
208
373
|
.option("--json", "Print machine-readable JSON")
|
|
209
374
|
.option("--no-interactive", "Never prompt; fail with a hint instead")
|
|
210
375
|
.addOption(new Option("--list-unavailable", "With --help, include commands this setup can't run").hideHelp(!options.setupMode))
|
|
211
376
|
.showHelpAfterError(styleText("dim", "Add --help to any command to see its usage."))
|
|
212
|
-
.addHelpText("after", `\nRun ${styleText("bold", "barndog <command> --help")} for details. Configuration: ${
|
|
377
|
+
.addHelpText("after", `\nRun ${styleText("bold", "barndog <command> --help")} for details. Configuration: ${barndogPaths(home).settings}`)
|
|
213
378
|
.addHelpText("afterAll", ({ command }) => options.setupMode ? unavailableHint(command, options.setupMode) : "")
|
|
214
379
|
.action((_, command) => {
|
|
215
|
-
if (command.args.length)
|
|
380
|
+
if (command.args.length) {
|
|
216
381
|
program.error(`error: unknown command '${command.args[0]}'`);
|
|
382
|
+
}
|
|
217
383
|
program.help();
|
|
218
384
|
});
|
|
219
385
|
program.hook("preAction", async (_, action) => {
|
|
@@ -223,14 +389,17 @@ export function createProgram(options = {}) {
|
|
|
223
389
|
mode.interactive &&
|
|
224
390
|
flags.interactive !== false &&
|
|
225
391
|
!mode.json &&
|
|
226
|
-
!
|
|
227
|
-
if (!options.synchronize && mode.interactive)
|
|
392
|
+
!runtime.env.CI;
|
|
393
|
+
if (!options.synchronize && mode.interactive) {
|
|
228
394
|
clashPrompt.resolver = promptClash;
|
|
229
|
-
|
|
395
|
+
}
|
|
396
|
+
else if (!mode.interactive) {
|
|
230
397
|
clashPrompt.resolver = undefined;
|
|
398
|
+
}
|
|
231
399
|
const path = [];
|
|
232
|
-
for (let c = action; c?.parent; c = c.parent)
|
|
400
|
+
for (let c = action; c?.parent; c = c.parent) {
|
|
233
401
|
path.unshift(c.name());
|
|
402
|
+
}
|
|
234
403
|
await options.guard?.(path, action.opts());
|
|
235
404
|
});
|
|
236
405
|
registerAuth(program, context);
|
|
@@ -240,32 +409,34 @@ export function createProgram(options = {}) {
|
|
|
240
409
|
registerEnvironment(program, context);
|
|
241
410
|
registerCapabilities(program, context);
|
|
242
411
|
registerWorkspace(program, context);
|
|
243
|
-
|
|
412
|
+
registerWorkingCopy(program, context);
|
|
413
|
+
registerCollaboration(program, context, "skill");
|
|
244
414
|
registerCollaboration(program, context, "hook");
|
|
245
415
|
registerAdd(program, context);
|
|
246
416
|
const order = groups.flatMap(([, names]) => names);
|
|
247
|
-
for (const [heading, names] of groups)
|
|
248
|
-
for (const name of names)
|
|
417
|
+
for (const [heading, names] of groups) {
|
|
418
|
+
for (const name of names) {
|
|
249
419
|
program.commands.find((c) => c.name() === name)?.helpGroup(heading);
|
|
420
|
+
}
|
|
421
|
+
}
|
|
250
422
|
// Commander lists groups in command order, so sort commands into section order.
|
|
423
|
+
// Commander types `commands` as readonly but offers no other way to reorder them.
|
|
424
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
|
251
425
|
program.commands.sort((a, b) => order.indexOf(a.name()) - order.indexOf(b.name()));
|
|
252
426
|
program.commandsGroup("Get started:").helpCommand(true);
|
|
253
427
|
for (const name of ["skills", "mcp", "hooks"]) {
|
|
254
|
-
const group = program.commands.find((c) => c.name() === name);
|
|
255
|
-
for (const [heading, names] of assetGroups)
|
|
256
|
-
for (const command of group.commands)
|
|
257
|
-
if (names.includes(command.name()))
|
|
258
|
-
command.helpGroup(
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
? "Publish directly:"
|
|
263
|
-
: name !== "mcp" && command.name() === "update"
|
|
264
|
-
? "On this machine:"
|
|
265
|
-
: heading);
|
|
428
|
+
const group = defined(program.commands.find((c) => c.name() === name), `Command group ${name} isn't registered`);
|
|
429
|
+
for (const [heading, names] of assetGroups) {
|
|
430
|
+
for (const command of group.commands) {
|
|
431
|
+
if (names.includes(command.name())) {
|
|
432
|
+
command.helpGroup(helpGroup(name, command.name(), heading));
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
}
|
|
266
436
|
}
|
|
267
|
-
if (options.guard)
|
|
437
|
+
if (options.guard) {
|
|
268
438
|
guardRequiredOptions(program, options.guard);
|
|
439
|
+
}
|
|
269
440
|
// Only the root accepts stray words, to report them as unknown commands.
|
|
270
441
|
program.allowExcessArguments(true);
|
|
271
442
|
return program;
|
package/dist/runtime.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A failure the person running the CLI can act on: bad input, missing setup,
|
|
3
|
+
* an unreachable server, a permission or a conflict. The message says what
|
|
4
|
+
* happened in a sentence; `hint` is the command (or short instruction) that
|
|
5
|
+
* fixes it, printed after `Fix:`. When the fix is a command that deletes or
|
|
6
|
+
* changes something, `hint` says in words what it does and `command` holds the
|
|
7
|
+
* command itself, printed after `Command:`. Anything else thrown as a plain `Error` is an
|
|
8
|
+
* internal invariant or a broken server contract, not something to fix here.
|
|
9
|
+
*
|
|
10
|
+
* It lives in `src/shared/` so the shared helpers can throw it too;
|
|
11
|
+
* `src/errors.ts` re-exports it.
|
|
12
|
+
*/
|
|
13
|
+
export class CliError extends Error {
|
|
14
|
+
hint;
|
|
15
|
+
command;
|
|
16
|
+
constructor(message, hint, options) {
|
|
17
|
+
super(message, options);
|
|
18
|
+
this.name = "CliError";
|
|
19
|
+
this.hint = hint;
|
|
20
|
+
this.command = options?.command;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/** HTTP response status codes registered by IANA (RFC 9110). */
|
|
2
|
+
export const HTTP_STATUS = {
|
|
3
|
+
badRequest: 400,
|
|
4
|
+
unauthorized: 401,
|
|
5
|
+
forbidden: 403,
|
|
6
|
+
notFound: 404,
|
|
7
|
+
conflict: 409,
|
|
8
|
+
payloadTooLarge: 413,
|
|
9
|
+
internalServerError: 500,
|
|
10
|
+
};
|
|
11
|
+
/** POSIX permission bits: execute for any user, group/other access, and creation modes. */
|
|
12
|
+
export const POSIX_MODE = {
|
|
13
|
+
executableBits: 0o111,
|
|
14
|
+
groupAndOtherBits: 0o077,
|
|
15
|
+
privateDirectory: 0o700,
|
|
16
|
+
executableFile: 0o755,
|
|
17
|
+
regularFile: 0o644,
|
|
18
|
+
};
|
|
19
|
+
/** JavaScript timers and Date use milliseconds; Git and OAuth timestamps use seconds. */
|
|
20
|
+
export const MILLISECONDS_PER_SECOND = 1000;
|
|
21
|
+
/** Date timestamps expressed as one minute in milliseconds. */
|
|
22
|
+
export const MILLISECONDS_PER_MINUTE = 60000;
|
|
23
|
+
/** Time conversion for human-readable ages. */
|
|
24
|
+
export const MINUTES_PER_HOUR = 60;
|
|
25
|
+
/** Time conversion for human-readable ages. */
|
|
26
|
+
export const HOURS_PER_DAY = 24;
|
|
27
|
+
/** Git conventional abbreviated object ID length used in CLI labels. */
|
|
28
|
+
export const SHORT_COMMIT_LENGTH = 7;
|
|
29
|
+
/** BarnDog asset slug and local-name limit, shared with the API contract. */
|
|
30
|
+
export const MAX_ASSET_NAME_LENGTH = 64;
|
|
31
|
+
/** Hexadecimal encoding uses sixteen digits. */
|
|
32
|
+
export const HEX_RADIX = 16;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { POSIX_MODE } from "./constants.js";
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
3
|
+
import { lstat, mkdir, readFile, rename, rm, writeFile, } from "node:fs/promises";
|
|
4
|
+
import { dirname, relative, isAbsolute, sep } from "node:path";
|
|
5
|
+
import { errorCode } from "./values.js";
|
|
6
|
+
import { CliError } from "./cli-error.js";
|
|
7
|
+
/**
|
|
8
|
+
* Writes a temporary file beside `path` and renames it over `path`, so a reader
|
|
9
|
+
* sees the old file or the new one, never half of one. Creates missing parent
|
|
10
|
+
* folders.
|
|
11
|
+
*/
|
|
12
|
+
export async function writeAtomic(path, data, { mode = 0o600, directoryMode = POSIX_MODE.privateDirectory, } = {}) {
|
|
13
|
+
await mkdir(dirname(path), { recursive: true, mode: directoryMode });
|
|
14
|
+
const temporary = `${path}.${randomUUID()}.tmp`;
|
|
15
|
+
try {
|
|
16
|
+
await writeFile(temporary, data, { mode, flag: "wx" });
|
|
17
|
+
await rename(temporary, path);
|
|
18
|
+
}
|
|
19
|
+
finally {
|
|
20
|
+
await rm(temporary, { force: true });
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* What `operation` returns, or null when the file or folder it touches doesn't
|
|
25
|
+
* exist (`ENOENT`). Any other failure is thrown.
|
|
26
|
+
*/
|
|
27
|
+
export async function ifExists(operation) {
|
|
28
|
+
try {
|
|
29
|
+
return await operation;
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
if (errorCode(error) === "ENOENT") {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
throw error;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/** A file's text, or null when it doesn't exist. */
|
|
39
|
+
export function readIfExists(path) {
|
|
40
|
+
return ifExists(readFile(path, "utf8"));
|
|
41
|
+
}
|
|
42
|
+
/** A JSON file checked against `schema`, or null when it doesn't exist. */
|
|
43
|
+
export async function readJsonIfExists(path, schema) {
|
|
44
|
+
const text = await readIfExists(path);
|
|
45
|
+
return text === null ? null : schema.parse(JSON.parse(text));
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* A regular file's text, or null when it doesn't exist. Refuses symlinks and
|
|
49
|
+
* anything else that isn't a plain file, so a write can't be redirected.
|
|
50
|
+
*/
|
|
51
|
+
export async function fileText(path) {
|
|
52
|
+
const info = await ifExists(lstat(path));
|
|
53
|
+
if (!info) {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
if (!info.isFile() || info.isSymbolicLink()) {
|
|
57
|
+
throw new CliError(`${path} is a link or not a regular file, so BarnDog won't edit it.`);
|
|
58
|
+
}
|
|
59
|
+
return readIfExists(path);
|
|
60
|
+
}
|
|
61
|
+
/** Whether `child` is `parent` or somewhere below it; compares paths, not links. */
|
|
62
|
+
export function isInside(parent, child, paths = {
|
|
63
|
+
relative,
|
|
64
|
+
isAbsolute,
|
|
65
|
+
sep,
|
|
66
|
+
}) {
|
|
67
|
+
const path = paths.relative(parent, child);
|
|
68
|
+
return (!path ||
|
|
69
|
+
(path !== ".." &&
|
|
70
|
+
!path.startsWith(`..${paths.sep}`) &&
|
|
71
|
+
!paths.isAbsolute(path)));
|
|
72
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { POSIX_MODE } from "./constants.js";
|
|
2
|
+
import { mkdir, readFile, rm } from "node:fs/promises";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
import { errorCode } from "./values.js";
|
|
5
|
+
import { CliError } from "./cli-error.js";
|
|
6
|
+
import { writeAtomic } from "./files.js";
|
|
7
|
+
/**
|
|
8
|
+
* Runs `run` while holding a lock across processes: a folder at `path` holding
|
|
9
|
+
* the owner's PID. A lock whose process has died is taken over; liveness comes
|
|
10
|
+
* from the PID, not from the lock's age, so a long operation never loses it.
|
|
11
|
+
*/
|
|
12
|
+
export async function withPidLock(path, messages, run) {
|
|
13
|
+
await mkdir(dirname(path), {
|
|
14
|
+
recursive: true,
|
|
15
|
+
mode: POSIX_MODE.privateDirectory,
|
|
16
|
+
});
|
|
17
|
+
try {
|
|
18
|
+
await mkdir(path);
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
if (errorCode(error) !== "EEXIST") {
|
|
22
|
+
throw error;
|
|
23
|
+
}
|
|
24
|
+
const pid = Number(await readFile(join(path, "pid"), "utf8").catch(() => "0"));
|
|
25
|
+
if (!pid) {
|
|
26
|
+
throw new CliError(messages.starting, undefined, { cause: error });
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
process.kill(pid, 0);
|
|
30
|
+
}
|
|
31
|
+
catch (failure) {
|
|
32
|
+
// EPERM: the owner is alive but belongs to another user, so it still holds the lock.
|
|
33
|
+
if (errorCode(failure) !== "ESRCH") {
|
|
34
|
+
throw new CliError(messages.running, undefined, { cause: failure });
|
|
35
|
+
}
|
|
36
|
+
// Another process may have cleared the same stale lock first.
|
|
37
|
+
await rm(path, { recursive: true, force: true });
|
|
38
|
+
return withPidLock(path, messages, run);
|
|
39
|
+
}
|
|
40
|
+
throw new CliError(messages.running, undefined, { cause: error });
|
|
41
|
+
}
|
|
42
|
+
try {
|
|
43
|
+
await writeAtomic(join(path, "pid"), String(process.pid));
|
|
44
|
+
return await run();
|
|
45
|
+
}
|
|
46
|
+
finally {
|
|
47
|
+
await rm(path, { recursive: true, force: true });
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** `value`, or an Error saying `message` when a lookup the code relies on comes back empty. */
|
|
2
|
+
export function defined(value, message) {
|
|
3
|
+
if (value === undefined || value === null) {
|
|
4
|
+
throw new Error(message);
|
|
5
|
+
}
|
|
6
|
+
return value;
|
|
7
|
+
}
|
|
8
|
+
/** The one element of `items`, or undefined when there are none or several. */
|
|
9
|
+
export function only(items) {
|
|
10
|
+
return items.length === 1 ? items[0] : undefined;
|
|
11
|
+
}
|