barndog 0.1.1 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -28
- package/dist/cli.js +11 -7
- package/dist/commands/add.js +34 -21
- package/dist/commands/adopt.js +91 -0
- package/dist/commands/arguments.js +12 -0
- package/dist/commands/asset-install.js +161 -0
- package/dist/commands/asset-list.js +126 -0
- package/dist/commands/asset-share.js +94 -0
- package/dist/commands/auth.js +4 -0
- package/dist/commands/availability.js +72 -27
- package/dist/commands/capabilities.js +79 -417
- package/dist/commands/collaboration.js +212 -108
- package/dist/commands/environment.js +18 -411
- package/dist/commands/github.js +200 -0
- package/dist/commands/harnesses.js +74 -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-env.js +78 -0
- package/dist/commands/mcp.js +64 -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 +36 -25
- package/dist/commands/sync.js +13 -5
- package/dist/commands/workspace.js +75 -23
- package/dist/config/environment.js +13 -27
- package/dist/config/paths.js +81 -0
- package/dist/config/selection.js +30 -0
- package/dist/config/settings.js +99 -108
- package/dist/config/state.js +67 -55
- 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/adoption/adopt.js +234 -0
- package/dist/features/adoption/copies.js +29 -0
- package/dist/features/adoption/originals.js +116 -0
- package/dist/features/adoption/record.js +120 -0
- package/dist/features/adoption/restore.js +28 -0
- package/dist/features/adoption/scan.js +482 -0
- package/dist/features/adoption/undo.js +42 -0
- package/dist/features/asset-kinds/index.js +129 -0
- package/dist/features/asset-selection/index.js +51 -19
- package/dist/features/auth/credentials.js +80 -54
- package/dist/features/auth/session.js +83 -49
- package/dist/features/auth/transport.js +69 -17
- 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 +242 -152
- package/dist/features/collaboration/workspace-github.js +118 -54
- package/dist/features/collaboration/workspace-store.js +157 -97
- package/dist/features/collaboration/workspace.js +278 -173
- package/dist/features/discovery/index.js +68 -57
- package/dist/features/doctor/index.js +56 -26
- package/dist/features/environment/auto-sync.js +28 -27
- package/dist/features/environment/harnesses.js +36 -0
- package/dist/features/environment/moves.js +171 -0
- package/dist/features/environment/names.js +73 -49
- package/dist/features/environment/operations.js +322 -229
- package/dist/features/environment/own-entries.js +89 -0
- package/dist/features/environment/settle-names.js +91 -0
- package/dist/features/environment/stage.js +202 -0
- package/dist/features/environment/sync.js +127 -487
- package/dist/features/environment/transaction.js +179 -147
- package/dist/features/environment/writes.js +243 -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 +55 -0
- package/dist/features/hooks/divergence.js +36 -12
- package/dist/features/hooks/test.js +91 -66
- package/dist/features/hooks/types.js +1 -0
- package/dist/features/imports/discover.js +133 -60
- package/dist/features/imports/folder.js +48 -14
- package/dist/features/imports/local.js +127 -135
- package/dist/features/imports/remote.js +46 -26
- package/dist/features/inspection/index.js +17 -17
- package/dist/features/inventory/index.js +111 -111
- package/dist/features/inventory/show.js +74 -0
- package/dist/features/knowledge/index.js +69 -49
- package/dist/features/mcps/catalog.js +31 -0
- package/dist/features/mcps/import.js +369 -0
- package/dist/features/mcps/index.js +104 -50
- package/dist/features/mcps/values.js +33 -0
- package/dist/features/migration/migrate.js +263 -0
- package/dist/features/migration/move.js +448 -0
- package/dist/features/migration/promote.js +26 -0
- package/dist/features/native/adapters.js +69 -96
- package/dist/features/native/configuration.js +134 -84
- package/dist/features/native/hook-shell.js +55 -0
- package/dist/features/native/plugin-module.js +56 -0
- package/dist/features/native/secret-values.js +74 -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/secrets/index.js +77 -0
- 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 +121 -54
- package/dist/features/workspace/git.js +221 -0
- package/dist/features/workspace/installed.js +92 -0
- package/dist/features/{git-workspace → workspace}/overlay.js +53 -46
- package/dist/features/workspace/packages.js +173 -0
- package/dist/features/{git-workspace → workspace}/publish.js +120 -64
- package/dist/features/workspace/repo-source.js +193 -0
- package/dist/features/{git-workspace → workspace}/setup.js +72 -45
- package/dist/features/{git-workspace → workspace}/snapshot.js +60 -19
- 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 +67 -1
- package/dist/harnesses/cursor.js +22 -1
- package/dist/harnesses/detect.js +6 -50
- package/dist/harnesses/formats.js +52 -0
- package/dist/harnesses/opencode.js +108 -0
- package/dist/harnesses/registry.js +35 -2
- package/dist/platform.js +403 -0
- package/dist/program.js +275 -56
- 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 +107 -0
- package/dist/shared/lock.js +113 -0
- package/dist/shared/lookup.js +11 -0
- package/dist/shared/patterns.js +102 -0
- package/dist/shared/shell.js +20 -0
- package/dist/shared/values.js +26 -0
- package/dist/ui/add-asset.js +41 -400
- package/dist/ui/add-hook.js +219 -0
- package/dist/ui/add-mcp.js +170 -0
- package/dist/ui/add-prompts.js +47 -0
- package/dist/ui/add-skills.js +117 -0
- package/dist/ui/adopt.js +197 -0
- package/dist/ui/asset-list.js +31 -13
- package/dist/ui/assets.js +38 -47
- package/dist/ui/auth.js +45 -34
- package/dist/ui/clash.js +10 -6
- package/dist/ui/collaboration.js +116 -44
- package/dist/ui/connection.js +17 -6
- 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/harness-picker.js +18 -0
- package/dist/ui/hook-compatibility.js +14 -6
- package/dist/ui/mcp.js +28 -3
- package/dist/ui/move.js +57 -6
- package/dist/ui/onboarding.js +148 -95
- package/dist/ui/options.js +9 -0
- package/dist/ui/output.js +108 -43
- package/dist/ui/package-details.js +34 -0
- package/dist/ui/pick.js +45 -33
- package/dist/ui/scope-install.js +18 -7
- package/dist/ui/secret-input.js +19 -0
- package/dist/ui/selection.js +17 -11
- package/dist/ui/theme.js +37 -14
- package/dist/version.js +6 -3
- package/package.json +13 -3
- package/dist/features/capabilities/index.js +0 -106
- package/dist/features/collaboration/domain.js +0 -90
- package/dist/features/environment/cloud-source.js +0 -27
- package/dist/features/environment/installed.js +0 -124
- package/dist/features/environment/packages.js +0 -120
- package/dist/features/environment/remote.js +0 -71
- package/dist/features/environment/workspace-source.js +0 -19
- package/dist/features/git-hosts/index.js +0 -148
- package/dist/features/git-workspace/assets.js +0 -71
- package/dist/features/git-workspace/git.js +0 -135
- package/dist/features/git-workspace/migrate.js +0 -188
- package/dist/features/git-workspace/move.js +0 -337
- 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
|
@@ -0,0 +1,448 @@
|
|
|
1
|
+
import { randomBytes } from "node:crypto";
|
|
2
|
+
import { basename, join } from "node:path";
|
|
3
|
+
import { rm } from "node:fs/promises";
|
|
4
|
+
import { knowledgeIndexSchema, } from "@barndog-ai/api-contract";
|
|
5
|
+
import { stringify } from "yaml";
|
|
6
|
+
import { readSettings, SetupRequiredError, } from "../../config/settings.js";
|
|
7
|
+
import { CliError, friendlyMessage } from "../../errors.js";
|
|
8
|
+
import { matchesOrigin, selectOrigin, scopes } from "../server/origin.js";
|
|
9
|
+
import { connection } from "../server/connection.js";
|
|
10
|
+
import { selectScope } from "../collaboration/workspace-git.js";
|
|
11
|
+
import { renameSkillEntries } from "../workspace/installed.js";
|
|
12
|
+
import { originLabel } from "../server/origin.js";
|
|
13
|
+
import { environmentCatalog } from "../server/catalog.js";
|
|
14
|
+
import { parsed } from "../server/client.js";
|
|
15
|
+
import { synchronize } from "../environment/sync.js";
|
|
16
|
+
import { locked } from "../environment/transaction.js";
|
|
17
|
+
import { assetPath, stableId } from "../workspace/format.js";
|
|
18
|
+
import { checkRepositoryUrl, cloneOrigin, git } from "../workspace/git.js";
|
|
19
|
+
import { connectGitWorkspace, createGitWorkspace, inspectRepository, } from "../workspace/setup.js";
|
|
20
|
+
import { LoginRequiredError, normalizeServer, apiClient, } from "../auth/transport.js";
|
|
21
|
+
import { connectionContext } from "../auth/session.js";
|
|
22
|
+
import { publishKnowledge, publishMcp, publishPackage } from "./migrate.js";
|
|
23
|
+
import { moveDestination, readMoved, recordMoved, } from "../workspace/overlay.js";
|
|
24
|
+
import { commitFiles, openPullRequest, pushCommit, } from "../workspace/publish.js";
|
|
25
|
+
import { acceptedCommit, gitRepoSource, localRepoSource, recordFetch, trackingRef, } from "../workspace/repo-source.js";
|
|
26
|
+
import { defined } from "../../shared/lookup.js";
|
|
27
|
+
import { setYamlName } from "../../shared/patterns.js";
|
|
28
|
+
import { barndogPaths } from "../../config/paths.js";
|
|
29
|
+
import { PAGE_SIZE } from "../server/pages.js";
|
|
30
|
+
/** Three random bytes distinguish temporary move branches. */
|
|
31
|
+
const MOVE_BRANCH_RANDOM_BYTES = 3;
|
|
32
|
+
const knowledgeOf = (item) => defined(item.content, `${item.name} has no knowledge content`);
|
|
33
|
+
/** A one-off destination: nothing about this machine's own setup changes. */
|
|
34
|
+
async function repoDestination(value, runtime) {
|
|
35
|
+
const url = checkRepositoryUrl(await cloneOrigin(value, runtime));
|
|
36
|
+
const head = await inspectRepository(url, runtime);
|
|
37
|
+
return head
|
|
38
|
+
? connectGitWorkspace(url, head.branch, runtime)
|
|
39
|
+
: createGitWorkspace(url, basename(url).replace(/\.git$/, "") || "Workspace", runtime);
|
|
40
|
+
}
|
|
41
|
+
async function serverDestination(value, runtime) {
|
|
42
|
+
const server = normalizeServer(value);
|
|
43
|
+
try {
|
|
44
|
+
return await connectionContext(server, runtime);
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
if (error instanceof LoginRequiredError) {
|
|
48
|
+
throw new CliError(`Sign in to ${server} first. This machine stays local.`, `barndog login --server ${server}`, { cause: error });
|
|
49
|
+
}
|
|
50
|
+
throw error;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function renamed(asset, name) {
|
|
54
|
+
if (asset.name === name) {
|
|
55
|
+
return asset.entries;
|
|
56
|
+
}
|
|
57
|
+
if (asset.kind === "skill") {
|
|
58
|
+
return renameSkillEntries(asset.entries, name);
|
|
59
|
+
}
|
|
60
|
+
return asset.entries.map((entry) => entry.path === "hook.yaml"
|
|
61
|
+
? {
|
|
62
|
+
...entry,
|
|
63
|
+
data: Buffer.from(setYamlName(entry.data.toString("utf8"), name)),
|
|
64
|
+
}
|
|
65
|
+
: entry);
|
|
66
|
+
}
|
|
67
|
+
async function candidates(overlay, names, as, kind) {
|
|
68
|
+
const model = await overlay.model();
|
|
69
|
+
const moved = await readMoved(overlay.label);
|
|
70
|
+
const pending = (path) => names?.length ? true : !moved.some((entry) => entry.path === path);
|
|
71
|
+
const items = [];
|
|
72
|
+
const invalid = [];
|
|
73
|
+
// Requested names, as the local workspace spells them, that matched an asset.
|
|
74
|
+
const found = new Set();
|
|
75
|
+
for (const asset of model.assets) {
|
|
76
|
+
if (!pending(asset.path) ||
|
|
77
|
+
(names?.length && !names.includes(asset.name)) ||
|
|
78
|
+
(kind && asset.kind !== kind)) {
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
if (asset.invalid) {
|
|
82
|
+
invalid.push({
|
|
83
|
+
kind: asset.kind,
|
|
84
|
+
name: asset.name,
|
|
85
|
+
status: "skipped",
|
|
86
|
+
detail: asset.invalid,
|
|
87
|
+
});
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
found.add(asset.name);
|
|
91
|
+
const name = as ?? asset.name;
|
|
92
|
+
items.push({
|
|
93
|
+
kind: asset.kind,
|
|
94
|
+
name,
|
|
95
|
+
path: asset.path,
|
|
96
|
+
version: asset.publishedVersion,
|
|
97
|
+
id: asset.id,
|
|
98
|
+
entries: renamed(asset, name),
|
|
99
|
+
definition: asset.definition,
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
for (const doc of model.knowledge) {
|
|
103
|
+
if (!pending(doc.path) ||
|
|
104
|
+
(names?.length && !names.includes(doc.content.name))) {
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
found.add(doc.content.name);
|
|
108
|
+
const name = as ?? doc.content.name;
|
|
109
|
+
items.push({
|
|
110
|
+
kind: "knowledge",
|
|
111
|
+
name,
|
|
112
|
+
path: doc.path,
|
|
113
|
+
version: doc.version,
|
|
114
|
+
id: doc.id,
|
|
115
|
+
entries: [],
|
|
116
|
+
content: { ...doc.content, name },
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
for (const name of names ?? []) {
|
|
120
|
+
if (!found.has(name) && !invalid.some((row) => row.name === name)) {
|
|
121
|
+
throw new CliError(`No local asset named ${name}.`, "barndog local list");
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return { items, invalid };
|
|
125
|
+
}
|
|
126
|
+
function knowledgeFile(content) {
|
|
127
|
+
const { description, tags, accessMode, markdown } = content;
|
|
128
|
+
return `---\n${stringify({ description, tags, accessMode })}---\n${markdown}`;
|
|
129
|
+
}
|
|
130
|
+
/** The files a candidate becomes in a Git workspace, under `path`. */
|
|
131
|
+
function candidateFiles(item, path) {
|
|
132
|
+
if (item.kind === "knowledge") {
|
|
133
|
+
return [
|
|
134
|
+
{
|
|
135
|
+
path,
|
|
136
|
+
data: Buffer.from(knowledgeFile(knowledgeOf(item))),
|
|
137
|
+
executable: false,
|
|
138
|
+
},
|
|
139
|
+
];
|
|
140
|
+
}
|
|
141
|
+
if (item.kind === "mcp") {
|
|
142
|
+
return [
|
|
143
|
+
{
|
|
144
|
+
path,
|
|
145
|
+
data: Buffer.from(stringify(item.definition)),
|
|
146
|
+
executable: false,
|
|
147
|
+
},
|
|
148
|
+
];
|
|
149
|
+
}
|
|
150
|
+
return item.entries.map((entry) => ({
|
|
151
|
+
...entry,
|
|
152
|
+
path: `${path}/${entry.path}`,
|
|
153
|
+
}));
|
|
154
|
+
}
|
|
155
|
+
async function moveToGit(workspace, items, to, runtime) {
|
|
156
|
+
const { home } = runtime;
|
|
157
|
+
const shared = await gitRepoSource(workspace, runtime).model();
|
|
158
|
+
const tip = defined(await acceptedCommit(workspace.workspaceId, runtime), "This Git workspace hasn't been fetched yet");
|
|
159
|
+
const scope = selectScope(shared, to ?? "org");
|
|
160
|
+
const repo = barndogPaths(home).bareClone(workspace.workspaceId);
|
|
161
|
+
const rows = [];
|
|
162
|
+
const moving = [];
|
|
163
|
+
for (const item of items) {
|
|
164
|
+
const path = item.kind === "knowledge"
|
|
165
|
+
? `org/knowledge/${item.name}.md`
|
|
166
|
+
: assetPath(scope.path, item.kind, item.name);
|
|
167
|
+
if (shared.assets.some((asset) => asset.path === path) ||
|
|
168
|
+
shared.knowledge.some((doc) => doc.path === path)) {
|
|
169
|
+
rows.push({
|
|
170
|
+
kind: item.kind,
|
|
171
|
+
name: item.name,
|
|
172
|
+
status: "clash",
|
|
173
|
+
detail: `${path} already exists`,
|
|
174
|
+
});
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
moving.push({
|
|
178
|
+
item,
|
|
179
|
+
files: candidateFiles(item, path),
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
const result = {
|
|
183
|
+
target: workspace.url,
|
|
184
|
+
keepLocal: true,
|
|
185
|
+
removed: [],
|
|
186
|
+
rows,
|
|
187
|
+
originId: stableId(workspace.workspaceId, "scope", scope.type, ...(scope.type === "org" ? [] : [scope.slug])),
|
|
188
|
+
};
|
|
189
|
+
if (!moving.length) {
|
|
190
|
+
return result;
|
|
191
|
+
}
|
|
192
|
+
const title = `Move ${moving.length} local asset${moving.length === 1 ? "" : "s"} into the workspace`;
|
|
193
|
+
const commit = await commitFiles(repo, tip, {
|
|
194
|
+
files: moving.flatMap((entry) => entry.files),
|
|
195
|
+
message: title,
|
|
196
|
+
}, { ...{}, runtime });
|
|
197
|
+
// A workspace with nothing in it has nothing to review against.
|
|
198
|
+
if (!shared.assets.length && !shared.knowledge.length) {
|
|
199
|
+
await pushCommit(repo, commit, workspace.branch, {
|
|
200
|
+
runtime,
|
|
201
|
+
allowPrompt: false,
|
|
202
|
+
});
|
|
203
|
+
await git(["update-ref", trackingRef(workspace.branch), commit], runtime, {
|
|
204
|
+
repo,
|
|
205
|
+
});
|
|
206
|
+
await recordFetch(workspace, commit, runtime);
|
|
207
|
+
result.direct = true;
|
|
208
|
+
result.branch = workspace.branch;
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
const branch = `barndog/local-move-${randomBytes(MOVE_BRANCH_RANDOM_BYTES).toString("hex")}`;
|
|
212
|
+
await pushCommit(repo, commit, branch, {
|
|
213
|
+
runtime,
|
|
214
|
+
allowPrompt: false,
|
|
215
|
+
});
|
|
216
|
+
const opened = await openPullRequest({
|
|
217
|
+
url: workspace.url,
|
|
218
|
+
base: workspace.branch,
|
|
219
|
+
branch,
|
|
220
|
+
title,
|
|
221
|
+
}, runtime);
|
|
222
|
+
result.branch = branch;
|
|
223
|
+
result.url = opened.url ?? null;
|
|
224
|
+
}
|
|
225
|
+
rows.push(...moving.map(({ item }) => ({
|
|
226
|
+
kind: item.kind,
|
|
227
|
+
name: item.name,
|
|
228
|
+
status: "moved",
|
|
229
|
+
})));
|
|
230
|
+
return result;
|
|
231
|
+
}
|
|
232
|
+
async function moveToCloud(conn, items, to, runtime) {
|
|
233
|
+
const scope = await selectOrigin(to ?? "me", conn, runtime);
|
|
234
|
+
if (!scope.canPublish) {
|
|
235
|
+
throw new CliError(`You can't publish to ${originLabel(scope)}.`, "barndog local move --to me");
|
|
236
|
+
}
|
|
237
|
+
const { catalog } = await environmentCatalog(runtime, conn);
|
|
238
|
+
const docs = (await parsed(knowledgeIndexSchema, apiClient(conn.server, runtime).GET("/v1/knowledge", {
|
|
239
|
+
params: { query: { limit: PAGE_SIZE } },
|
|
240
|
+
}))).documents;
|
|
241
|
+
const visible = await scopes(conn, runtime);
|
|
242
|
+
const org = visible.find((s) => s.type === "org");
|
|
243
|
+
const rows = [];
|
|
244
|
+
for (const item of items) {
|
|
245
|
+
const base = { kind: item.kind, name: item.name };
|
|
246
|
+
try {
|
|
247
|
+
if (item.kind === "knowledge") {
|
|
248
|
+
if (docs.some((doc) => doc.name === item.name)) {
|
|
249
|
+
rows.push({ ...base, status: "clash", detail: "Name already used" });
|
|
250
|
+
}
|
|
251
|
+
else if (!org?.canPublish) {
|
|
252
|
+
rows.push({
|
|
253
|
+
...base,
|
|
254
|
+
status: "skipped",
|
|
255
|
+
detail: "Knowledge is organization-wide, and you can't publish there",
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
else {
|
|
259
|
+
await publishKnowledge({
|
|
260
|
+
id: item.id,
|
|
261
|
+
version: item.version,
|
|
262
|
+
content: knowledgeOf(item),
|
|
263
|
+
}, conn, runtime);
|
|
264
|
+
rows.push({ ...base, status: "moved" });
|
|
265
|
+
}
|
|
266
|
+
continue;
|
|
267
|
+
}
|
|
268
|
+
if (catalog.assets.some((asset) => asset.kind === item.kind &&
|
|
269
|
+
asset.name === item.name &&
|
|
270
|
+
asset.origin.id === scope.id)) {
|
|
271
|
+
rows.push({
|
|
272
|
+
...base,
|
|
273
|
+
status: "clash",
|
|
274
|
+
detail: `Already in ${originLabel(scope)}`,
|
|
275
|
+
});
|
|
276
|
+
continue;
|
|
277
|
+
}
|
|
278
|
+
const asset = {
|
|
279
|
+
id: item.id,
|
|
280
|
+
kind: item.kind,
|
|
281
|
+
name: item.name,
|
|
282
|
+
publishedVersion: item.version,
|
|
283
|
+
entries: item.entries,
|
|
284
|
+
definition: item.definition,
|
|
285
|
+
};
|
|
286
|
+
if (asset.kind === "mcp") {
|
|
287
|
+
await publishMcp(asset, scope, conn, runtime);
|
|
288
|
+
}
|
|
289
|
+
else {
|
|
290
|
+
await publishPackage({ ...asset, kind: asset.kind }, scope, conn, runtime);
|
|
291
|
+
}
|
|
292
|
+
rows.push({ ...base, status: "moved" });
|
|
293
|
+
}
|
|
294
|
+
catch (error) {
|
|
295
|
+
rows.push({
|
|
296
|
+
...base,
|
|
297
|
+
status: "failed",
|
|
298
|
+
detail: friendlyMessage(error),
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
return {
|
|
303
|
+
target: originLabel(scope),
|
|
304
|
+
keepLocal: true,
|
|
305
|
+
removed: [],
|
|
306
|
+
rows,
|
|
307
|
+
originId: scope.id,
|
|
308
|
+
direct: true,
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
/** A one-off destination (`--repo`, `--server`) leaves this machine as it is, so it only copies. */
|
|
312
|
+
const keepsLocal = (options) => options.keepLocal || Boolean(options.repo ?? options.server);
|
|
313
|
+
/**
|
|
314
|
+
* Records full moves so sync can replace each local copy with the shared one
|
|
315
|
+
* once it exists. Knowledge that is already published needs no selection, so
|
|
316
|
+
* its local file goes at once; the rest waits for the next sync.
|
|
317
|
+
*/
|
|
318
|
+
async function finishMove(folder, result, moved, items) {
|
|
319
|
+
const removed = [];
|
|
320
|
+
const records = [];
|
|
321
|
+
for (const row of moved) {
|
|
322
|
+
const item = defined(items.find((i) => i.kind === row.kind && i.name === row.name), `${row.name} isn't among the moved items`);
|
|
323
|
+
if (row.kind === "knowledge" && result.direct) {
|
|
324
|
+
const path = join(folder, item.path);
|
|
325
|
+
await rm(path, { force: true });
|
|
326
|
+
removed.push(path);
|
|
327
|
+
continue;
|
|
328
|
+
}
|
|
329
|
+
records.push({
|
|
330
|
+
kind: row.kind,
|
|
331
|
+
name: row.name,
|
|
332
|
+
path: item.path,
|
|
333
|
+
version: item.version,
|
|
334
|
+
target: result.target,
|
|
335
|
+
...(row.kind !== "knowledge" ? { originId: result.originId } : {}),
|
|
336
|
+
...(result.url ? { url: result.url } : {}),
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
await recordMoved(folder, records);
|
|
340
|
+
return removed;
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Copies local assets into the shared workspace. With `keepLocal` false the
|
|
344
|
+
* shared copy becomes the only one: sync removes each local copy once its
|
|
345
|
+
* shared copy exists.
|
|
346
|
+
*/
|
|
347
|
+
export function moveLocalAssets(options, runtime) {
|
|
348
|
+
const { home } = runtime;
|
|
349
|
+
return locked(runtime, async () => {
|
|
350
|
+
const settings = await readSettings(home);
|
|
351
|
+
if (!settings) {
|
|
352
|
+
throw new SetupRequiredError();
|
|
353
|
+
}
|
|
354
|
+
if (!settings.localWorkspace) {
|
|
355
|
+
throw new CliError("This machine has no local assets to move.");
|
|
356
|
+
}
|
|
357
|
+
const overlay = localRepoSource(settings.localWorkspace, runtime);
|
|
358
|
+
const shared = options.repo || options.server
|
|
359
|
+
? null
|
|
360
|
+
: (settings.gitWorkspace ?? settings.connection);
|
|
361
|
+
if (!options.repo && !options.server && !shared) {
|
|
362
|
+
throw new CliError("This machine only has its local folder, so there's nowhere to move assets yet. Name a Git repo or a Cloud Workspace as the destination; this machine stays local.", "barndog local move --repo <url> or barndog local move --server <url>");
|
|
363
|
+
}
|
|
364
|
+
if (options.as && options.names?.length !== 1) {
|
|
365
|
+
throw new CliError("--as renames one asset, so name exactly one.", "barndog local move <name> --as <new-name>");
|
|
366
|
+
}
|
|
367
|
+
const { items, invalid } = await candidates(overlay, options.names, options.as, options.kind);
|
|
368
|
+
const moveItems = async () => {
|
|
369
|
+
if (options.repo) {
|
|
370
|
+
return moveToGit(await repoDestination(options.repo, runtime), items, options.to, runtime);
|
|
371
|
+
}
|
|
372
|
+
if (options.server) {
|
|
373
|
+
return moveToCloud(await serverDestination(options.server, runtime), items, options.to, runtime);
|
|
374
|
+
}
|
|
375
|
+
if (settings.gitWorkspace) {
|
|
376
|
+
return moveToGit(settings.gitWorkspace, items, options.to, runtime);
|
|
377
|
+
}
|
|
378
|
+
return moveToCloud(await connection(runtime), items, options.to, runtime);
|
|
379
|
+
};
|
|
380
|
+
const result = await moveItems();
|
|
381
|
+
result.rows.unshift(...invalid);
|
|
382
|
+
result.keepLocal = keepsLocal(options);
|
|
383
|
+
const moved = result.rows.filter((row) => row.status === "moved");
|
|
384
|
+
if (!result.keepLocal) {
|
|
385
|
+
result.removed = await finishMove(overlay.label, result, moved, items);
|
|
386
|
+
}
|
|
387
|
+
if (moved.length) {
|
|
388
|
+
await synchronize(undefined, runtime, undefined, { prompt: false });
|
|
389
|
+
}
|
|
390
|
+
return result;
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
export async function listLocalAssets(runtime) {
|
|
394
|
+
const { home } = runtime;
|
|
395
|
+
const settings = await readSettings(home);
|
|
396
|
+
if (!settings || !settings.localWorkspace) {
|
|
397
|
+
throw new CliError("This machine has no local assets.", "barndog init --local");
|
|
398
|
+
}
|
|
399
|
+
const source = localRepoSource(settings.localWorkspace, runtime);
|
|
400
|
+
const model = await source.model();
|
|
401
|
+
// A move can only be under way while the workspace it goes to is in use.
|
|
402
|
+
const moving = settings.connection || settings.gitWorkspace
|
|
403
|
+
? await readMoved(source.label)
|
|
404
|
+
: [];
|
|
405
|
+
const state = (path, invalid) => {
|
|
406
|
+
if (invalid) {
|
|
407
|
+
return { state: "invalid" };
|
|
408
|
+
}
|
|
409
|
+
const entry = moving.find((m) => m.path === path);
|
|
410
|
+
return entry
|
|
411
|
+
? {
|
|
412
|
+
state: "moving",
|
|
413
|
+
movingTo: moveDestination(entry),
|
|
414
|
+
}
|
|
415
|
+
: { state: "active" };
|
|
416
|
+
};
|
|
417
|
+
return {
|
|
418
|
+
folder: settings.localWorkspace.path,
|
|
419
|
+
assets: [
|
|
420
|
+
...model.assets.map((asset) => ({
|
|
421
|
+
kind: asset.kind,
|
|
422
|
+
name: asset.name,
|
|
423
|
+
path: asset.path,
|
|
424
|
+
...state(asset.path, asset.invalid),
|
|
425
|
+
})),
|
|
426
|
+
...model.knowledge.map((doc) => ({
|
|
427
|
+
kind: "knowledge",
|
|
428
|
+
name: doc.content.name,
|
|
429
|
+
path: doc.path,
|
|
430
|
+
...state(doc.path),
|
|
431
|
+
})),
|
|
432
|
+
],
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
/** Where setup can offer to send local assets in a Cloud Workspace; personal first. */
|
|
436
|
+
export async function cloudMoveTargets(runtime) {
|
|
437
|
+
const conn = await connection(runtime);
|
|
438
|
+
const visible = await scopes(conn, runtime);
|
|
439
|
+
return visible
|
|
440
|
+
.filter((s) => s.canPublish && (s.type !== "dev" || matchesOrigin(s, "me", conn)))
|
|
441
|
+
.sort((a, b) => Number(b.type === "dev") - Number(a.type === "dev"))
|
|
442
|
+
.map((s) => ({
|
|
443
|
+
value: s.type === "dev" ? "me" : originLabel(s),
|
|
444
|
+
name: s.type === "dev"
|
|
445
|
+
? "Your personal assets"
|
|
446
|
+
: `${s.name} (${originLabel(s)})`,
|
|
447
|
+
}));
|
|
448
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { copyToScope, } from "../discovery/index.js";
|
|
2
|
+
import { LOCAL_ORIGIN } from "../workspace/overlay.js";
|
|
3
|
+
import { moveLocalAssets } from "./move.js";
|
|
4
|
+
/**
|
|
5
|
+
* Proposes an asset for another scope. A local asset has no server copy to
|
|
6
|
+
* propose from, so it is moved there instead and the result is that move.
|
|
7
|
+
*/
|
|
8
|
+
export async function promote(input, runtime) {
|
|
9
|
+
if (input.origin === LOCAL_ORIGIN) {
|
|
10
|
+
return {
|
|
11
|
+
outcome: "moved",
|
|
12
|
+
move: await moveLocalAssets({
|
|
13
|
+
names: [input.name],
|
|
14
|
+
kind: input.kind,
|
|
15
|
+
// Promoting shares a copy; the original stays, as on the server.
|
|
16
|
+
keepLocal: true,
|
|
17
|
+
to: input.target,
|
|
18
|
+
as: input.newName === input.name ? undefined : input.newName,
|
|
19
|
+
}, runtime),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
outcome: "promoted",
|
|
24
|
+
promotion: await copyToScope("promote", input, runtime),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
@@ -1,52 +1,42 @@
|
|
|
1
|
-
import { access } from "node:fs/promises";
|
|
2
|
-
import { constants } from "node:fs";
|
|
3
|
-
import { delimiter, join } from "node:path";
|
|
4
|
-
import { execFile } from "node:child_process";
|
|
5
|
-
import { promisify } from "node:util";
|
|
6
1
|
import { fileURLToPath } from "node:url";
|
|
7
2
|
import { coerce, satisfies, validRange } from "semver";
|
|
8
|
-
import {
|
|
9
|
-
import { nativeFile } from "
|
|
10
|
-
|
|
11
|
-
|
|
3
|
+
import { programOutput, findExecutable, runtimeExecutable, } from "../../platform.js";
|
|
4
|
+
import { adapters, nativeFile } from "../../harnesses/registry.js";
|
|
5
|
+
import { secretRefs } from "../../harnesses/formats.js";
|
|
6
|
+
import { hookCommand } from "./hook-shell.js";
|
|
7
|
+
/** A `--version` answer is one short line; anything slower or longer is broken. */
|
|
8
|
+
const VERSION_TIMEOUT_MS = 5000;
|
|
9
|
+
const VERSION_OUTPUT_LIMIT_BYTES = 4096;
|
|
12
10
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
11
|
+
* Checks required executables and optionally runs the harness version command;
|
|
12
|
+
* returns the first issue or null.
|
|
15
13
|
*/
|
|
16
|
-
export
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
: path.split(delimiter)) {
|
|
21
|
-
const candidate = directory ? join(directory, command) : command;
|
|
22
|
-
try {
|
|
23
|
-
await access(candidate, constants.X_OK);
|
|
24
|
-
return candidate;
|
|
25
|
-
}
|
|
26
|
-
catch {
|
|
27
|
-
/* next PATH entry */
|
|
14
|
+
export async function runtimeRequirements(harness, requirements, runtime) {
|
|
15
|
+
for (const command of requirements.commands) {
|
|
16
|
+
if (!(await runtimeExecutable(command, runtime))) {
|
|
17
|
+
return `Missing runtime: ${command}`;
|
|
28
18
|
}
|
|
29
19
|
}
|
|
30
|
-
return null;
|
|
31
|
-
}
|
|
32
|
-
export async function runtimeRequirements(harness, requirements) {
|
|
33
|
-
for (const command of requirements.commands)
|
|
34
|
-
if (!(await executable(command)))
|
|
35
|
-
return `Missing runtime: ${command}`;
|
|
36
20
|
if (requirements.harnessVersion) {
|
|
37
|
-
if (!validRange(requirements.harnessVersion))
|
|
21
|
+
if (!validRange(requirements.harnessVersion)) {
|
|
38
22
|
return `Invalid declared harness version requirement: ${requirements.harnessVersion}`;
|
|
39
|
-
|
|
40
|
-
|
|
23
|
+
}
|
|
24
|
+
const command = (await Promise.all(adapters[harness].commands.map((c) => findExecutable(c, runtime)))).find(Boolean);
|
|
25
|
+
if (!command) {
|
|
41
26
|
return `Cannot verify ${harness} version: harness command is missing`;
|
|
27
|
+
}
|
|
42
28
|
try {
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
29
|
+
const stdout = await programOutput(command, ["--version"], runtime, {
|
|
30
|
+
timeoutMs: VERSION_TIMEOUT_MS,
|
|
31
|
+
maxBytes: VERSION_OUTPUT_LIMIT_BYTES,
|
|
46
32
|
});
|
|
47
33
|
const version = coerce(stdout);
|
|
48
|
-
if (!version
|
|
49
|
-
return
|
|
34
|
+
if (!version) {
|
|
35
|
+
return `Cannot verify ${harness} version: ${command} --version printed no version`;
|
|
36
|
+
}
|
|
37
|
+
if (!satisfies(version, requirements.harnessVersion)) {
|
|
38
|
+
return `${harness} ${version.version} does not meet ${requirements.harnessVersion}`;
|
|
39
|
+
}
|
|
50
40
|
}
|
|
51
41
|
catch {
|
|
52
42
|
return `Cannot verify ${harness} version`;
|
|
@@ -54,72 +44,55 @@ export async function runtimeRequirements(harness, requirements) {
|
|
|
54
44
|
}
|
|
55
45
|
return null;
|
|
56
46
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
: `\${${ref.secretRef}}`,
|
|
66
|
-
]));
|
|
67
|
-
let value;
|
|
68
|
-
if (definition.transport === "http")
|
|
69
|
-
value =
|
|
70
|
-
harness === "codex"
|
|
71
|
-
? {
|
|
72
|
-
url: definition.url,
|
|
73
|
-
...(Object.keys(refs).length
|
|
74
|
-
? {
|
|
75
|
-
env_http_headers: Object.fromEntries(Object.entries(refs).map(([k, v]) => [k, v.secretRef])),
|
|
76
|
-
}
|
|
77
|
-
: {}),
|
|
78
|
-
}
|
|
79
|
-
: {
|
|
80
|
-
...(harness === "claude" ? { type: "http" } : {}),
|
|
81
|
-
url: definition.url,
|
|
82
|
-
...(Object.keys(env).length ? { headers: env } : {}),
|
|
83
|
-
};
|
|
84
|
-
else if (harness === "codex") {
|
|
85
|
-
// Native forwarding preserves reference-only storage. Renamed variables are
|
|
86
|
-
// bound by a tiny local launcher, without writing their values to disk.
|
|
87
|
-
const renamed = Object.entries(refs).some(([key, ref]) => key !== ref.secretRef);
|
|
88
|
-
value = renamed
|
|
89
|
-
? {
|
|
90
|
-
command: process.execPath,
|
|
91
|
-
args: [
|
|
92
|
-
fileURLToPath(new URL("./mcp-launch.js", import.meta.url)),
|
|
93
|
-
Buffer.from(JSON.stringify(definition)).toString("base64url"),
|
|
94
|
-
],
|
|
95
|
-
env_vars: Object.values(refs).map((v) => v.secretRef),
|
|
96
|
-
}
|
|
97
|
-
: {
|
|
98
|
-
command: definition.command,
|
|
99
|
-
args: definition.args,
|
|
100
|
-
env_vars: Object.values(refs).map((v) => v.secretRef),
|
|
101
|
-
};
|
|
47
|
+
/**
|
|
48
|
+
* Why a Hook can't be installed for a tool: no implementation for it, or
|
|
49
|
+
* something its implementation needs is missing here. Null when it can.
|
|
50
|
+
*/
|
|
51
|
+
export async function hookIssue(harness, manifest, runtime) {
|
|
52
|
+
const implementation = manifest.implementations[harness];
|
|
53
|
+
if (!implementation) {
|
|
54
|
+
return "No implementation for this harness";
|
|
102
55
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
56
|
+
return runtimeRequirements(harness, implementation.requirements, runtime);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Builds a harness-specific MCP configuration entry; does not write native
|
|
60
|
+
* settings. Variables in `kept` are written as their values, the rest as
|
|
61
|
+
* references to local environment variables.
|
|
62
|
+
*/
|
|
63
|
+
export function mcpEntry(harness, server, kept, runtime) {
|
|
64
|
+
const { home } = runtime;
|
|
65
|
+
const used = Object.fromEntries(Object.values(secretRefs(server.definition)).flatMap((ref) => {
|
|
66
|
+
const value = kept[ref.secretRef];
|
|
67
|
+
return value === undefined ? [] : [[ref.secretRef, value]];
|
|
68
|
+
}));
|
|
110
69
|
return {
|
|
111
|
-
id:
|
|
70
|
+
id: server.id,
|
|
112
71
|
kind: "mcp",
|
|
113
72
|
harness,
|
|
114
73
|
file: nativeFile(harness, "mcp", home),
|
|
115
|
-
key:
|
|
116
|
-
value,
|
|
74
|
+
key: server.name,
|
|
75
|
+
value: adapters[harness].mcp.server(server.definition, fileURLToPath(new URL("../../entry/mcp-launch.js", import.meta.url)), used),
|
|
76
|
+
...(Object.keys(used).length
|
|
77
|
+
? {
|
|
78
|
+
secrets: Object.entries(used).map(([variable, value]) => ({
|
|
79
|
+
variable,
|
|
80
|
+
value,
|
|
81
|
+
})),
|
|
82
|
+
}
|
|
83
|
+
: {}),
|
|
117
84
|
};
|
|
118
85
|
}
|
|
119
|
-
|
|
86
|
+
/**
|
|
87
|
+
* Builds native Hook entries with commands rooted at the installed package;
|
|
88
|
+
* missing implementations yield no entries.
|
|
89
|
+
*/
|
|
90
|
+
export function hookEntries(harness, { id, root, manifest }, runtime) {
|
|
91
|
+
const { home } = runtime;
|
|
120
92
|
const implementation = manifest.implementations[harness];
|
|
121
|
-
if (!implementation)
|
|
93
|
+
if (!implementation) {
|
|
122
94
|
return [];
|
|
95
|
+
}
|
|
123
96
|
return Object.entries(implementation.events).flatMap(([key, handlers]) => handlers.map((handler) => ({
|
|
124
97
|
id,
|
|
125
98
|
kind: "hook",
|
|
@@ -132,12 +105,12 @@ export function hookEntries(harness, id, root, manifest, home) {
|
|
|
132
105
|
hooks: handler.hooks.map((command) => ({
|
|
133
106
|
...command,
|
|
134
107
|
type: "command",
|
|
135
|
-
command: hookCommand(root, command.command, harness),
|
|
108
|
+
command: hookCommand(root, command.command, harness, runtime.platform),
|
|
136
109
|
})),
|
|
137
110
|
}
|
|
138
111
|
: {
|
|
139
112
|
...handler,
|
|
140
|
-
command: hookCommand(root, handler.command, harness),
|
|
113
|
+
command: hookCommand(root, handler.command, harness, runtime.platform),
|
|
141
114
|
},
|
|
142
115
|
})));
|
|
143
116
|
}
|