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
|
@@ -1,31 +1,53 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { localPath } from "../../platform.js";
|
|
2
2
|
import { readFile } from "node:fs/promises";
|
|
3
3
|
import { z } from "zod";
|
|
4
|
-
import { scopeSchema } from "@barndog-ai/api-contract";
|
|
5
4
|
import { readSettings, SetupRequiredError, } from "../../config/settings.js";
|
|
6
5
|
import { selectionState, withSelection } from "../../config/environment.js";
|
|
7
|
-
import { applySelectionAction, resolveAssets, } from "../asset-selection/index.js";
|
|
8
|
-
import { environmentCatalog
|
|
9
|
-
import { matchesOrigin } from "../
|
|
6
|
+
import { applySelectionAction, resolveAssets, ScopeNotSelectedError, } from "../asset-selection/index.js";
|
|
7
|
+
import { environmentCatalog } from "../server/catalog.js";
|
|
8
|
+
import { matchesOrigin, scopes } from "../server/origin.js";
|
|
10
9
|
import { locked } from "./transaction.js";
|
|
11
10
|
import { installedNames, synchronize } from "./sync.js";
|
|
12
|
-
import { openRepoSource } from "
|
|
13
|
-
import { localOverlay, mergeLocalCatalog, withOverlay, } from "../
|
|
14
|
-
import { CliError } from "../../errors.js";
|
|
15
|
-
import { originLabel
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
import { openRepoSource } from "../workspace/workspace-source.js";
|
|
12
|
+
import { localOverlay, mergeLocalCatalog, withOverlay, } from "../workspace/overlay.js";
|
|
13
|
+
import { CliError, friendlyMessage } from "../../errors.js";
|
|
14
|
+
import { originLabel } from "../server/origin.js";
|
|
15
|
+
import { assetKinds } from "../asset-kinds/index.js";
|
|
16
|
+
import { only } from "../../shared/lookup.js";
|
|
17
|
+
import { splitOrigin, validAssetName } from "../../shared/patterns.js";
|
|
18
|
+
const decisionsSchema = z.array(z
|
|
19
|
+
.object({
|
|
20
|
+
assetId: z.uuidv4(),
|
|
21
|
+
choice: z.enum(["preserve", "clear"]),
|
|
22
|
+
})
|
|
23
|
+
.strict());
|
|
24
|
+
/** A `--decisions` file: `[{"assetId":"<uuid>","choice":"preserve"}]`. */
|
|
25
|
+
async function readDecisions(file, runtime) {
|
|
26
|
+
const text = await readFile(localPath(file, runtime), "utf8");
|
|
27
|
+
let value;
|
|
28
|
+
try {
|
|
29
|
+
value = JSON.parse(text);
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
throw new CliError(`${file} isn't valid JSON.`, DECISIONS_FORMAT, {
|
|
33
|
+
cause: error,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
const result = decisionsSchema.safeParse(value);
|
|
37
|
+
if (!result.success) {
|
|
38
|
+
throw new CliError(`${file} isn't a decisions file: ${friendlyMessage(result.error)}.`, DECISIONS_FORMAT, { cause: result.error });
|
|
39
|
+
}
|
|
40
|
+
return result.data;
|
|
41
|
+
}
|
|
42
|
+
/** What a `--decisions` file holds, as the fix for one that doesn't. */
|
|
43
|
+
const DECISIONS_FORMAT = 'Write a list such as [{"assetId": "<uuid>", "choice": "preserve"}], with "preserve" or "clear" for each asset';
|
|
44
|
+
async function overrideResolution(options, runtime) {
|
|
45
|
+
if (options.decisions) {
|
|
18
46
|
return {
|
|
19
47
|
type: "per-asset",
|
|
20
|
-
decisions:
|
|
21
|
-
.array(z
|
|
22
|
-
.object({
|
|
23
|
-
assetId: z.uuidv4(),
|
|
24
|
-
choice: z.enum(["preserve", "clear"]),
|
|
25
|
-
})
|
|
26
|
-
.strict())
|
|
27
|
-
.parse(JSON.parse(await readFile(options.decisions, "utf8"))),
|
|
48
|
+
decisions: await readDecisions(options.decisions, runtime),
|
|
28
49
|
};
|
|
50
|
+
}
|
|
29
51
|
return (options.resolution ??
|
|
30
52
|
(options.overrides
|
|
31
53
|
? {
|
|
@@ -35,243 +57,314 @@ async function overrideResolution(options) {
|
|
|
35
57
|
}
|
|
36
58
|
: undefined));
|
|
37
59
|
}
|
|
38
|
-
function assetChange(
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
60
|
+
function assetChange(change, assetId) {
|
|
61
|
+
switch (change) {
|
|
62
|
+
case "install":
|
|
63
|
+
return { type: "install-asset", assetId };
|
|
64
|
+
case "remove":
|
|
65
|
+
return { type: "remove-asset", assetId };
|
|
66
|
+
case "enable":
|
|
67
|
+
case "disable":
|
|
68
|
+
return {
|
|
69
|
+
type: "set-asset-enabled",
|
|
70
|
+
assetId,
|
|
71
|
+
enabled: change === "enable",
|
|
72
|
+
};
|
|
73
|
+
}
|
|
50
74
|
}
|
|
51
75
|
/** Cloud answers these through its API; repo workspaces answer them from files. */
|
|
52
|
-
async function workspaceAccess(settings,
|
|
53
|
-
const overlay = localOverlay(settings,
|
|
76
|
+
async function workspaceAccess(settings, runtime) {
|
|
77
|
+
const overlay = localOverlay(settings, runtime);
|
|
54
78
|
const merge = (catalog) => overlay ? mergeLocalCatalog(catalog, overlay) : catalog;
|
|
55
|
-
const source = openRepoSource(settings,
|
|
79
|
+
const source = openRepoSource(settings, runtime);
|
|
56
80
|
if (source) {
|
|
57
81
|
const model = await source.model();
|
|
58
82
|
return {
|
|
59
83
|
identity: model,
|
|
60
84
|
catalog: await merge(model.catalog),
|
|
61
85
|
source: overlay ? withOverlay(source, overlay) : source,
|
|
62
|
-
scopes:
|
|
86
|
+
scopes: () => Promise.resolve(model.scopes),
|
|
63
87
|
};
|
|
64
88
|
}
|
|
65
|
-
const { connection: conn, catalog } = await environmentCatalog(
|
|
89
|
+
const { connection: conn, catalog } = await environmentCatalog(runtime);
|
|
66
90
|
return {
|
|
67
91
|
identity: conn,
|
|
68
92
|
catalog: await merge(catalog),
|
|
69
|
-
scopes: () =>
|
|
93
|
+
scopes: () => scopes(conn, runtime),
|
|
70
94
|
};
|
|
71
95
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
96
|
+
async function readRequiredSettings(runtime) {
|
|
97
|
+
const { home } = runtime;
|
|
98
|
+
const settings = await readSettings(home);
|
|
99
|
+
if (!settings) {
|
|
100
|
+
throw new SetupRequiredError();
|
|
101
|
+
}
|
|
102
|
+
return settings;
|
|
103
|
+
}
|
|
104
|
+
function withLockedWorkspace(runtime, operation) {
|
|
105
|
+
return locked(runtime, async () => {
|
|
106
|
+
const settings = await readRequiredSettings(runtime);
|
|
107
|
+
const access = await workspaceAccess(settings, runtime);
|
|
108
|
+
return operation({
|
|
109
|
+
...access,
|
|
110
|
+
runtime,
|
|
111
|
+
settings,
|
|
112
|
+
current: selectionState(settings),
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
async function syncSelection(workspace, state, next = withSelection(workspace.settings, state)) {
|
|
117
|
+
return {
|
|
118
|
+
status: "applied",
|
|
119
|
+
events: await synchronize(undefined, workspace.runtime, next, {
|
|
120
|
+
catalog: workspace.catalog,
|
|
121
|
+
source: workspace.source,
|
|
122
|
+
}),
|
|
123
|
+
state,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
async function applyChange(workspace, change, overrides, origin) {
|
|
127
|
+
const resolution = await overrideResolution(overrides, workspace.runtime);
|
|
128
|
+
const result = (() => {
|
|
129
|
+
try {
|
|
130
|
+
return applySelectionAction(workspace.catalog, workspace.current, change, resolution);
|
|
90
131
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
const current = selectionState(settings);
|
|
95
|
-
if (action === "list")
|
|
96
|
-
return catalog.assets.filter((a) => !options.kind || a.kind === options.kind);
|
|
97
|
-
if (action === "status")
|
|
98
|
-
return resolveAssets(catalog, current);
|
|
99
|
-
// Picker selections arrive as IDs and apply in one synchronization.
|
|
100
|
-
if (options.ids?.length &&
|
|
101
|
-
["install", "remove", "enable", "disable"].includes(action)) {
|
|
102
|
-
const resolution = await overrideResolution(options);
|
|
103
|
-
let state = current;
|
|
104
|
-
for (const assetId of options.ids) {
|
|
105
|
-
const result = applySelectionAction(catalog, state, assetChange(action, assetId), resolution);
|
|
106
|
-
if (result.status === "decision-required")
|
|
107
|
-
return result;
|
|
108
|
-
state = result.state;
|
|
132
|
+
catch (error) {
|
|
133
|
+
if (error instanceof ScopeNotSelectedError) {
|
|
134
|
+
throw new CliError(`${origin} isn't in your sets yet.`, `barndog sets install ${origin}`, { cause: error });
|
|
109
135
|
}
|
|
110
|
-
|
|
111
|
-
status: "applied",
|
|
112
|
-
events: await synchronize(undefined, home, withSelection(settings, state), known),
|
|
113
|
-
state,
|
|
114
|
-
};
|
|
136
|
+
throw error;
|
|
115
137
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
state,
|
|
173
|
-
};
|
|
138
|
+
})();
|
|
139
|
+
if (result.status === "decision-required") {
|
|
140
|
+
return result;
|
|
141
|
+
}
|
|
142
|
+
return syncSelection(workspace, result.state);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* The asset `target` names for `change`. Anything but install also accepts the
|
|
146
|
+
* UUID of an asset that's no longer in the catalog, so it can still be cleaned up.
|
|
147
|
+
*/
|
|
148
|
+
function assetId(workspace, target, change) {
|
|
149
|
+
const { settings, catalog, identity } = workspace;
|
|
150
|
+
const command = `barndog ${assetKinds[target.kind].command} ${change}`;
|
|
151
|
+
const localNames = settings.localNames ?? {};
|
|
152
|
+
const named = catalog.assets.filter((a) => a.kind === target.kind &&
|
|
153
|
+
(a.id === target.name ||
|
|
154
|
+
a.name === target.name ||
|
|
155
|
+
localNames[a.id] === target.name));
|
|
156
|
+
const { origin } = target;
|
|
157
|
+
const matches = origin
|
|
158
|
+
? named.filter((a) => matchesOrigin(a.origin, origin, identity))
|
|
159
|
+
: named;
|
|
160
|
+
const staleId = change !== "install" && z.uuidv4().safeParse(target.name).success
|
|
161
|
+
? target.name
|
|
162
|
+
: undefined;
|
|
163
|
+
const id = only(matches)?.id ?? staleId;
|
|
164
|
+
const [first] = matches;
|
|
165
|
+
if (!id && first && matches.length > 1) {
|
|
166
|
+
throw new CliError(`${target.name} exists in several scopes: ${matches.map((a) => originLabel(a.origin)).join(", ")}. Choose one with --origin.`, `${command} ${target.name} --origin ${originLabel(first.origin)}`);
|
|
167
|
+
}
|
|
168
|
+
if (!id) {
|
|
169
|
+
throw new CliError(`No ${assetKinds[target.kind].one} named ${target.name}${target.origin ? ` in ${target.origin}` : ""} is available to you.`, `barndog ${assetKinds[target.kind].command} search ${target.name}`);
|
|
170
|
+
}
|
|
171
|
+
return id;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Installs, removes, enables or disables one asset, then syncs. Removing an
|
|
175
|
+
* asset a subscribed set still supplies also excludes it. Takes the sync lock.
|
|
176
|
+
*/
|
|
177
|
+
export function changeAsset(change, target, runtime) {
|
|
178
|
+
return withLockedWorkspace(runtime, async (workspace) => {
|
|
179
|
+
const id = assetId(workspace, target, change);
|
|
180
|
+
return applyChange(workspace, assetChange(change, id), target, target.origin);
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
export function changeAssets(change, target, runtime) {
|
|
184
|
+
return withLockedWorkspace(runtime, async (workspace) => {
|
|
185
|
+
if (!target.ids.length) {
|
|
186
|
+
return { status: "applied", events: [] };
|
|
187
|
+
}
|
|
188
|
+
const resolution = await overrideResolution(target, workspace.runtime);
|
|
189
|
+
let state = workspace.current;
|
|
190
|
+
for (const id of target.ids) {
|
|
191
|
+
const result = applySelectionAction(workspace.catalog, state, assetChange(change, id), resolution);
|
|
192
|
+
if (result.status === "decision-required") {
|
|
193
|
+
return result;
|
|
174
194
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
195
|
+
state = result.state;
|
|
196
|
+
}
|
|
197
|
+
return syncSelection(workspace, state);
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
/** `reset`, or `as` set to the published name, drops the local name. */
|
|
201
|
+
export async function renameAsset(target, runtime) {
|
|
202
|
+
if (!target.reset && target.as === undefined) {
|
|
203
|
+
const { command } = assetKinds[target.kind];
|
|
204
|
+
throw new CliError(`Say what to rename ${target.name} to.`, `barndog ${command} rename ${target.name} --as <new-name>, or --reset for its published name`);
|
|
205
|
+
}
|
|
206
|
+
return withLockedWorkspace(runtime, async (workspace) => {
|
|
207
|
+
const { settings, catalog, current } = workspace;
|
|
208
|
+
const id = assetId(workspace, target, "rename");
|
|
209
|
+
const asset = catalog.assets.find((a) => a.id === id);
|
|
210
|
+
const names = {
|
|
211
|
+
...(settings.localNames ?? {}),
|
|
212
|
+
};
|
|
213
|
+
if (target.reset || target.as === asset?.name) {
|
|
214
|
+
delete names[id];
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
const name = target.as ?? "";
|
|
218
|
+
if (!validAssetName(name)) {
|
|
219
|
+
throw new CliError("Use lowercase letters, numbers and single hyphens (at most 64 characters).");
|
|
183
220
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
};
|
|
221
|
+
const held = await installedNames(runtime);
|
|
222
|
+
const taken = catalog.assets.find((a) => a.id !== id &&
|
|
223
|
+
a.kind === target.kind &&
|
|
224
|
+
((names[a.id] ?? a.name) === name || held(a.id) === name) &&
|
|
225
|
+
resolveAssets(catalog, current).assets.some((entry) => entry.asset.id === a.id && entry.enabled));
|
|
226
|
+
if (taken) {
|
|
227
|
+
throw new CliError(`${name} is already used by ${originLabel(taken.origin)}.`);
|
|
192
228
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
};
|
|
199
|
-
else if (action === "sets-remove")
|
|
200
|
-
change = { type: "remove-scope", scope };
|
|
201
|
-
else
|
|
202
|
-
change = {
|
|
203
|
-
type: "set-scope-enabled",
|
|
204
|
-
scope,
|
|
205
|
-
enabled: action === "sets-enable",
|
|
206
|
-
};
|
|
229
|
+
names[id] = name;
|
|
230
|
+
}
|
|
231
|
+
const next = withSelection(settings, current);
|
|
232
|
+
if (Object.keys(names).length) {
|
|
233
|
+
next.localNames = names;
|
|
207
234
|
}
|
|
208
235
|
else {
|
|
209
|
-
|
|
210
|
-
const named = catalog.assets.filter((a) => a.kind === options.kind &&
|
|
211
|
-
(a.id === options.name ||
|
|
212
|
-
a.name === options.name ||
|
|
213
|
-
localNames[a.id] === options.name));
|
|
214
|
-
const matches = options.origin
|
|
215
|
-
? named.filter((a) => matchesOrigin(a.origin, options.origin, conn))
|
|
216
|
-
: named;
|
|
217
|
-
const staleId = action !== "install" && z.uuidv4().safeParse(options.name).success
|
|
218
|
-
? options.name
|
|
219
|
-
: undefined;
|
|
220
|
-
const id = matches.length === 1 ? matches[0].id : staleId;
|
|
221
|
-
const command = `barndog ${options.kind === "skill" ? "skills" : options.kind === "mcp" ? "mcp" : "hooks"} ${action}`;
|
|
222
|
-
if (!id && matches.length > 1)
|
|
223
|
-
throw new CliError(`${options.name} exists in several scopes: ${matches.map((a) => originLabel(a.origin)).join(", ")}. Choose one with --origin.`, `${command} ${options.name} --origin ${originLabel(matches[0].origin)}`);
|
|
224
|
-
if (!id)
|
|
225
|
-
throw new CliError(`No ${options.kind === "mcp" ? "MCP server" : options.kind} named ${options.name}${options.origin ? ` in ${options.origin}` : ""} is available to you.`, `barndog ${options.kind === "skill" ? "skills" : options.kind === "mcp" ? "mcp" : "hooks"} search ${options.name}`);
|
|
226
|
-
if (action === "rename") {
|
|
227
|
-
const asset = catalog.assets.find((a) => a.id === id);
|
|
228
|
-
const names = { ...localNames };
|
|
229
|
-
if (options.reset || options.as === asset?.name)
|
|
230
|
-
delete names[id];
|
|
231
|
-
else {
|
|
232
|
-
const name = options.as ?? "";
|
|
233
|
-
if (!validInstalledName(name))
|
|
234
|
-
throw new CliError("Use lowercase letters, numbers and single hyphens (at most 64 characters).");
|
|
235
|
-
const held = await installedNames(home);
|
|
236
|
-
const taken = catalog.assets.find((a) => a.id !== id &&
|
|
237
|
-
a.kind === options.kind &&
|
|
238
|
-
((names[a.id] ?? a.name) === name || held(a.id) === name) &&
|
|
239
|
-
resolveAssets(catalog, current).assets.some((entry) => entry.asset.id === a.id && entry.enabled));
|
|
240
|
-
if (taken)
|
|
241
|
-
throw new CliError(`${name} is already used by ${originLabel(taken.origin)}.`);
|
|
242
|
-
names[id] = name;
|
|
243
|
-
}
|
|
244
|
-
const next = withSelection(settings, current);
|
|
245
|
-
if (Object.keys(names).length)
|
|
246
|
-
next.localNames = names;
|
|
247
|
-
else
|
|
248
|
-
delete next.localNames;
|
|
249
|
-
return {
|
|
250
|
-
status: "applied",
|
|
251
|
-
events: await synchronize(undefined, home, next, known),
|
|
252
|
-
state: current,
|
|
253
|
-
};
|
|
254
|
-
}
|
|
255
|
-
change = assetChange(action, id);
|
|
236
|
+
delete next.localNames;
|
|
256
237
|
}
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
238
|
+
return syncSelection(workspace, current, next);
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
export function listSets(runtime) {
|
|
242
|
+
return withLockedWorkspace(runtime, async ({ scopes, current, catalog }) => ({
|
|
243
|
+
available: (await scopes()).filter((s) => s.type !== "dev"),
|
|
244
|
+
subscriptions: current.subscriptions,
|
|
245
|
+
diagnostics: resolveAssets(catalog, current).diagnostics,
|
|
246
|
+
}));
|
|
247
|
+
}
|
|
248
|
+
/** Removal also accepts the UUID of a scope you can no longer see, such as `team/<uuid>`. */
|
|
249
|
+
async function findScope(workspace, selector, { forRemoval = false } = {}) {
|
|
250
|
+
const matches = (await workspace.scopes()).filter((s) => s.type !== "dev" && matchesOrigin(s, selector, workspace.identity));
|
|
251
|
+
const [match] = matches;
|
|
252
|
+
if (matches.length === 1 && match && match.type !== "dev") {
|
|
253
|
+
return { type: match.type, id: match.id };
|
|
254
|
+
}
|
|
255
|
+
const { type, value: id } = splitOrigin(selector);
|
|
256
|
+
if (!forRemoval ||
|
|
257
|
+
(type !== "org" && type !== "team" && type !== "repo") ||
|
|
258
|
+
id === undefined ||
|
|
259
|
+
!z.uuidv4().safeParse(id).success) {
|
|
260
|
+
throw new CliError(`No scope named ${selector} is available to you. To remove an unavailable subscription, pass its UUID, such as team/<uuid>.`, "barndog sets list");
|
|
261
|
+
}
|
|
262
|
+
return { type, id };
|
|
263
|
+
}
|
|
264
|
+
function scopeAssets(workspace, scope) {
|
|
265
|
+
const distribution = workspace.catalog.distributions.find((d) => d.scope.type === scope.type && d.scope.id === scope.id);
|
|
266
|
+
if (!distribution) {
|
|
267
|
+
throw new Error("Scope distribution unavailable");
|
|
268
|
+
}
|
|
269
|
+
return workspace.catalog.assets.filter((asset) => distribution.assets.some((entry) => entry.assetId === asset.id));
|
|
270
|
+
}
|
|
271
|
+
export function previewSet(origin, runtime) {
|
|
272
|
+
return withLockedWorkspace(runtime, async (workspace) => ({
|
|
273
|
+
assets: scopeAssets(workspace, await findScope(workspace, origin)),
|
|
274
|
+
selectedAssetIds: resolveAssets(workspace.catalog, workspace.current).assets.map((entry) => entry.asset.id),
|
|
275
|
+
}));
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Subscribes to a set in recommended, optional or all mode, then syncs. Returns
|
|
279
|
+
* a decision-required outcome when existing overrides need an explicit choice.
|
|
280
|
+
*/
|
|
281
|
+
export function installSet(options, runtime) {
|
|
282
|
+
return withLockedWorkspace(runtime, async (workspace) => applyChange(workspace, {
|
|
283
|
+
type: "install-scope",
|
|
284
|
+
scope: await findScope(workspace, options.origin),
|
|
285
|
+
mode: options.mode ?? "recommended",
|
|
286
|
+
}, options, options.origin));
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Selects some of a scope's assets individually instead of subscribing, so the
|
|
290
|
+
* selection doesn't follow later additions to the scope.
|
|
291
|
+
*/
|
|
292
|
+
export function installSetAssets(options, runtime) {
|
|
293
|
+
return withLockedWorkspace(runtime, async (workspace) => {
|
|
294
|
+
const scope = await findScope(workspace, options.origin);
|
|
295
|
+
const available = scopeAssets(workspace, scope);
|
|
296
|
+
const ids = z.array(z.uuidv4()).parse(options.assetIds);
|
|
297
|
+
const repeated = ids.filter((id, index) => ids.indexOf(id) !== index);
|
|
298
|
+
if (repeated.length) {
|
|
299
|
+
throw new CliError(`Each asset can be chosen once, but ${[...new Set(repeated)].join(", ")} is listed more than once.`);
|
|
300
|
+
}
|
|
301
|
+
const outside = ids.filter((id) => !available.some((asset) => asset.id === id));
|
|
302
|
+
if (outside.length) {
|
|
303
|
+
throw new CliError(`${outside.join(", ")} isn't one of ${options.origin}'s assets.`, `barndog sets show ${options.origin}`);
|
|
304
|
+
}
|
|
305
|
+
if (!ids.length) {
|
|
306
|
+
return { status: "applied", events: [] };
|
|
307
|
+
}
|
|
308
|
+
let state = {
|
|
309
|
+
...workspace.current,
|
|
310
|
+
subscriptions: workspace.current.subscriptions.filter((s) => s.scope.type !== scope.type || s.scope.id !== scope.id),
|
|
311
|
+
};
|
|
312
|
+
for (const assetId of ids) {
|
|
313
|
+
const result = applySelectionAction(workspace.catalog, state, {
|
|
314
|
+
type: "install-asset",
|
|
315
|
+
assetId,
|
|
316
|
+
});
|
|
317
|
+
if (result.status !== "applied") {
|
|
318
|
+
throw new Error("Installing a set's assets one by one asked for a decision");
|
|
266
319
|
}
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
320
|
+
state = result.state;
|
|
321
|
+
}
|
|
322
|
+
return syncSelection(workspace, state);
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Removes, enables or disables a subscription, then syncs. A removed set's
|
|
327
|
+
* assets go unless something else selects them.
|
|
328
|
+
*/
|
|
329
|
+
export function changeSet(change, options, runtime) {
|
|
330
|
+
return withLockedWorkspace(runtime, async (workspace) => {
|
|
331
|
+
const scope = await findScope(workspace, options.origin, {
|
|
332
|
+
forRemoval: change === "remove",
|
|
333
|
+
});
|
|
334
|
+
return applyChange(workspace, change === "remove"
|
|
335
|
+
? { type: "remove-scope", scope }
|
|
336
|
+
: { type: "set-scope-enabled", scope, enabled: change === "enable" }, options, options.origin);
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
/** Replaces the subscriptions of the same type (team or repository). */
|
|
340
|
+
export function switchSet(options, runtime) {
|
|
341
|
+
return withLockedWorkspace(runtime, async (workspace) => {
|
|
342
|
+
const scope = await findScope(workspace, options.origin);
|
|
343
|
+
if (scope.type !== "team" && scope.type !== "repo") {
|
|
344
|
+
throw new CliError("Switch between teams or repositories, such as team/engineering or repo/web-app.");
|
|
345
|
+
}
|
|
346
|
+
return applyChange(workspace, {
|
|
347
|
+
type: "switch-scope",
|
|
348
|
+
scope: { type: scope.type, id: scope.id },
|
|
349
|
+
mode: options.mode ?? "recommended",
|
|
350
|
+
}, options, options.origin);
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
/** Whether coding tools are told at session start which knowledge documents exist. */
|
|
354
|
+
export function setKnowledge(enabled, runtime) {
|
|
355
|
+
return locked(runtime, async () => {
|
|
356
|
+
const settings = await readRequiredSettings(runtime);
|
|
357
|
+
if (!settings.connection &&
|
|
358
|
+
!settings.gitWorkspace &&
|
|
359
|
+
!settings.localWorkspace) {
|
|
360
|
+
throw new CliError("Set up a workspace first.", "barndog init");
|
|
361
|
+
}
|
|
271
362
|
return {
|
|
272
363
|
status: "applied",
|
|
273
|
-
events: await synchronize(undefined,
|
|
274
|
-
|
|
364
|
+
events: await synchronize(undefined, runtime, {
|
|
365
|
+
...settings,
|
|
366
|
+
knowledge: enabled,
|
|
367
|
+
}),
|
|
275
368
|
};
|
|
276
369
|
});
|
|
277
370
|
}
|