barndog 0.2.0 → 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 +29 -27
- package/dist/commands/add.js +1 -0
- package/dist/commands/adopt.js +91 -0
- package/dist/commands/asset-install.js +1 -0
- package/dist/commands/asset-list.js +7 -2
- package/dist/commands/availability.js +25 -8
- package/dist/commands/capabilities.js +8 -2
- package/dist/commands/collaboration.js +22 -2
- package/dist/commands/harnesses.js +74 -0
- package/dist/commands/mcp-env.js +78 -0
- package/dist/commands/mcp.js +4 -2
- package/dist/commands/status.js +2 -1
- package/dist/commands/sync.js +2 -1
- package/dist/commands/workspace.js +43 -5
- package/dist/config/paths.js +19 -0
- package/dist/config/settings.js +5 -3
- package/dist/config/state.js +18 -6
- 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 +9 -0
- package/dist/features/auth/credentials.js +7 -14
- package/dist/features/auth/session.js +4 -5
- package/dist/features/auth/transport.js +3 -2
- package/dist/features/collaboration/workspace-git.js +13 -7
- package/dist/features/collaboration/workspace-github.js +2 -1
- package/dist/features/collaboration/workspace-store.js +23 -3
- package/dist/features/collaboration/workspace.js +22 -2
- package/dist/features/doctor/index.js +24 -2
- package/dist/features/environment/harnesses.js +36 -0
- package/dist/features/environment/moves.js +171 -0
- package/dist/features/environment/names.js +10 -6
- package/dist/features/environment/operations.js +7 -7
- package/dist/features/environment/stage.js +25 -1
- package/dist/features/environment/sync.js +17 -6
- package/dist/features/environment/writes.js +55 -8
- package/dist/features/hooks/compatibility.js +11 -5
- package/dist/features/hooks/divergence.js +30 -9
- package/dist/features/hooks/test.js +25 -25
- package/dist/features/imports/discover.js +1 -1
- package/dist/features/imports/local.js +15 -2
- package/dist/features/imports/remote.js +2 -1
- package/dist/features/inventory/index.js +13 -2
- package/dist/features/inventory/show.js +74 -0
- package/dist/features/mcps/import.js +74 -21
- package/dist/features/mcps/index.js +12 -7
- package/dist/features/mcps/values.js +33 -0
- package/dist/features/migration/move.js +72 -17
- package/dist/features/migration/promote.js +2 -0
- package/dist/features/native/adapters.js +20 -6
- package/dist/features/native/configuration.js +8 -4
- package/dist/features/native/secret-values.js +74 -0
- package/dist/features/secrets/index.js +77 -0
- package/dist/features/workspace/format.js +13 -9
- package/dist/features/workspace/git.js +11 -4
- package/dist/features/workspace/overlay.js +23 -36
- package/dist/features/workspace/packages.js +16 -3
- package/dist/features/workspace/publish.js +1 -1
- package/dist/features/workspace/repo-source.js +4 -3
- package/dist/features/workspace/setup.js +12 -3
- package/dist/features/workspace/snapshot.js +7 -1
- package/dist/harnesses/claude.js +2 -2
- package/dist/harnesses/codex.js +19 -9
- package/dist/harnesses/cursor.js +2 -2
- package/dist/harnesses/formats.js +12 -5
- package/dist/harnesses/opencode.js +3 -6
- package/dist/platform.js +39 -11
- package/dist/program.js +51 -3
- package/dist/shared/files.js +35 -0
- package/dist/shared/lock.js +87 -23
- package/dist/shared/patterns.js +8 -0
- package/dist/shared/shell.js +0 -2
- package/dist/ui/add-hook.js +8 -2
- package/dist/ui/add-mcp.js +69 -6
- package/dist/ui/add-skills.js +7 -5
- package/dist/ui/adopt.js +197 -0
- package/dist/ui/assets.js +5 -3
- package/dist/ui/auth.js +2 -1
- package/dist/ui/clash.js +2 -3
- package/dist/ui/connection.js +7 -2
- package/dist/ui/harness-picker.js +18 -0
- package/dist/ui/move.js +48 -2
- package/dist/ui/onboarding.js +40 -27
- package/dist/ui/output.js +3 -1
- package/dist/ui/package-details.js +34 -0
- package/dist/ui/scope-install.js +4 -1
- package/dist/ui/secret-input.js +19 -0
- package/dist/ui/selection.js +3 -1
- package/package.json +1 -1
|
@@ -4,6 +4,7 @@ import { parse } from "yaml";
|
|
|
4
4
|
import { assetFolders, packageKindList, } from "../../config/selection.js";
|
|
5
5
|
import { CliError, PackageError } from "../../errors.js";
|
|
6
6
|
import { only } from "../../shared/lookup.js";
|
|
7
|
+
import { validAssetName, validMcpName } from "../../shared/patterns.js";
|
|
7
8
|
/** In the order commands list them. */
|
|
8
9
|
export const assetKindList = [
|
|
9
10
|
"skill",
|
|
@@ -30,6 +31,8 @@ implementations:
|
|
|
30
31
|
- type: command
|
|
31
32
|
command: '\${BARNDOG_HOOK_ROOT}/scripts/hook.sh'
|
|
32
33
|
`;
|
|
34
|
+
/** Skill and Hook names, which become folder names: the `NAME` shape. */
|
|
35
|
+
const ASSET_NAME_RULE = "Names use lowercase letters, numbers and single hyphens, at most 64 characters";
|
|
33
36
|
/**
|
|
34
37
|
* What differs between asset kinds. Code that needs a kind's word, route, folder
|
|
35
38
|
* or schema reads it here instead of comparing `kind`.
|
|
@@ -46,6 +49,8 @@ export const assetKinds = {
|
|
|
46
49
|
/** Inside a workspace scope and `~/.barndog/installed/`. */
|
|
47
50
|
folder: assetFolders.skill,
|
|
48
51
|
schema: skillSchema,
|
|
52
|
+
validName: validAssetName,
|
|
53
|
+
nameRule: ASSET_NAME_RULE,
|
|
49
54
|
manifest: "SKILL.md",
|
|
50
55
|
scaffold: (name) => [
|
|
51
56
|
file("SKILL.md", `---\nname: ${name}\ndescription: Describe this Skill\n---\n\nAdd instructions here.\n`),
|
|
@@ -59,6 +64,8 @@ export const assetKinds = {
|
|
|
59
64
|
route: "mcps",
|
|
60
65
|
folder: assetFolders.mcp,
|
|
61
66
|
schema: mcpSchema,
|
|
67
|
+
validName: validMcpName,
|
|
68
|
+
nameRule: "MCP server names use letters, numbers, underscores and hyphens, at most 64 characters",
|
|
62
69
|
},
|
|
63
70
|
hook: {
|
|
64
71
|
one: "Hook",
|
|
@@ -68,6 +75,8 @@ export const assetKinds = {
|
|
|
68
75
|
route: "hooks",
|
|
69
76
|
folder: assetFolders.hook,
|
|
70
77
|
schema: hookSchema,
|
|
78
|
+
validName: validAssetName,
|
|
79
|
+
nameRule: ASSET_NAME_RULE,
|
|
71
80
|
manifest: "hook.yaml",
|
|
72
81
|
scaffold: (name) => [
|
|
73
82
|
file("hook.yaml", hookManifest(name)),
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { fixSteps, privatePermissions, protectPrivate, removeCommand, } from "../../platform.js";
|
|
2
2
|
import { posixQuote } from "../../shared/shell.js";
|
|
3
3
|
import { POSIX_MODE } from "../../shared/constants.js";
|
|
4
|
-
import { chmod, lstat, mkdir, readFile
|
|
4
|
+
import { chmod, lstat, mkdir, readFile } from "node:fs/promises";
|
|
5
5
|
import { contextSchema } from "@barndog-ai/api-contract";
|
|
6
6
|
import { z } from "zod";
|
|
7
|
-
import { errorCode } from "../../shared/values.js";
|
|
8
7
|
import { ifExists, writeAtomic } from "../../shared/files.js";
|
|
9
8
|
import { CliError } from "../../errors.js";
|
|
10
9
|
import { barndogPaths } from "../../config/paths.js";
|
|
10
|
+
import { withPidLock } from "../../shared/lock.js";
|
|
11
11
|
/**
|
|
12
12
|
* A BarnDog session token: 32 random bytes in unpadded base64url, 43 characters.
|
|
13
13
|
*
|
|
@@ -76,20 +76,13 @@ export async function updateCredentials(runtime, update) {
|
|
|
76
76
|
}
|
|
77
77
|
await chmod(root, POSIX_MODE.privateDirectory);
|
|
78
78
|
await protectPrivate(root, runtime);
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
throw error;
|
|
85
|
-
});
|
|
86
|
-
try {
|
|
79
|
+
await withPidLock(barndogPaths(home).credentialsLock, {
|
|
80
|
+
starting: "Another sign-in or sign-out is starting. Wait for it to finish, then try again.",
|
|
81
|
+
running: "Another sign-in or sign-out is running. Wait for it to finish, then try again.",
|
|
82
|
+
}, async () => {
|
|
87
83
|
const credentials = await readCredentials(runtime);
|
|
88
84
|
update(credentials);
|
|
89
85
|
await writeAtomic(barndogPaths(home).credentials, JSON.stringify(credentials, null, 2) + "\n");
|
|
90
86
|
await protectPrivate(barndogPaths(home).credentials, runtime);
|
|
91
|
-
}
|
|
92
|
-
finally {
|
|
93
|
-
await rm(lock, { recursive: true });
|
|
94
|
-
}
|
|
87
|
+
});
|
|
95
88
|
}
|
|
@@ -130,13 +130,12 @@ export async function logout(runtime) {
|
|
|
130
130
|
* require login.
|
|
131
131
|
*/
|
|
132
132
|
export async function authStatus(runtime, explicitServer) {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
}
|
|
137
|
-
catch {
|
|
133
|
+
// No server yet means never signed in; a bad URL or settings file says so itself.
|
|
134
|
+
const configured = explicitServer ?? (await configuredServer(runtime));
|
|
135
|
+
if (!configured) {
|
|
138
136
|
throw new LoginRequiredError();
|
|
139
137
|
}
|
|
138
|
+
const server = normalizeServer(configured);
|
|
140
139
|
const context = contextSchema.parse((await apiClient(server, runtime).GET("/v1/context")).data);
|
|
141
140
|
return { server, context };
|
|
142
141
|
}
|
|
@@ -25,8 +25,9 @@ export class LoginRequiredError extends Error {
|
|
|
25
25
|
* credentials or URL suffixes are rejected.
|
|
26
26
|
*/
|
|
27
27
|
export function normalizeServer(value) {
|
|
28
|
-
const url =
|
|
29
|
-
if (!
|
|
28
|
+
const url = URL.parse(value);
|
|
29
|
+
if (!url ||
|
|
30
|
+
!["http:", "https:"].includes(url.protocol) ||
|
|
30
31
|
url.username ||
|
|
31
32
|
url.password ||
|
|
32
33
|
url.search ||
|
|
@@ -14,7 +14,7 @@ import { acceptedCommit, gitRepoSource, recordFetch, trackingRef, } from "../wor
|
|
|
14
14
|
import { metadata as packageMetadataFor, packageKindOf, assetKinds, assetNotFound, } from "../asset-kinds/index.js";
|
|
15
15
|
import { matchesOrigin } from "../server/origin.js";
|
|
16
16
|
import { markResolved } from "./workspace.js";
|
|
17
|
-
import { applyFiles, decodeFiles, encodeFiles, findGit, locked, save, readWorkingCopy, } from "./workspace-store.js";
|
|
17
|
+
import { applyFiles, decodeFiles, encodeFiles, findGit, NoWorkingCopyError, locked, save, readWorkingCopy, } from "./workspace-store.js";
|
|
18
18
|
import { defined, only } from "../../shared/lookup.js";
|
|
19
19
|
import { NAME, splitOrigin } from "../../shared/patterns.js";
|
|
20
20
|
import { barndogPaths } from "../../config/paths.js";
|
|
@@ -22,10 +22,11 @@ import { barndogPaths } from "../../config/paths.js";
|
|
|
22
22
|
const BRANCH_RANDOM_BYTES = 3;
|
|
23
23
|
async function latest(workspace, runtime) {
|
|
24
24
|
const model = await gitRepoSource(workspace, runtime).model();
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
25
|
+
const commit = await acceptedCommit(workspace.workspaceId, runtime);
|
|
26
|
+
if (!commit) {
|
|
27
|
+
throw new CliError("This machine hasn't fetched the Git workspace yet.", "barndog sync");
|
|
28
|
+
}
|
|
29
|
+
return { model, commit };
|
|
29
30
|
}
|
|
30
31
|
function selectAsset(model, kind, name, origin) {
|
|
31
32
|
const matches = model.assets.filter((asset) => asset.kind === kind &&
|
|
@@ -251,11 +252,12 @@ export function pushGitWorkingCopy(workspace, options, runtime) {
|
|
|
251
252
|
return locked(runtime, async () => {
|
|
252
253
|
const { model, commit: tip } = await latest(workspace, runtime);
|
|
253
254
|
let work;
|
|
255
|
+
let unregistered = false;
|
|
254
256
|
try {
|
|
255
257
|
work = await findGit(runtime);
|
|
256
258
|
}
|
|
257
259
|
catch (error) {
|
|
258
|
-
if (!options.origin || !(error instanceof
|
|
260
|
+
if (!options.origin || !(error instanceof NoWorkingCopyError)) {
|
|
259
261
|
throw error;
|
|
260
262
|
}
|
|
261
263
|
const root = await realpath(cwd);
|
|
@@ -271,7 +273,7 @@ export function pushGitWorkingCopy(workspace, options, runtime) {
|
|
|
271
273
|
base: [],
|
|
272
274
|
conflicts: [],
|
|
273
275
|
};
|
|
274
|
-
|
|
276
|
+
unregistered = true;
|
|
275
277
|
}
|
|
276
278
|
if (options.kind && work.kind !== options.kind) {
|
|
277
279
|
throw new CliError(`This working copy holds a ${work.kind}, not a ${options.kind}.`, "barndog status");
|
|
@@ -282,6 +284,10 @@ export function pushGitWorkingCopy(workspace, options, runtime) {
|
|
|
282
284
|
if (work.git.workspaceId !== workspace.workspaceId) {
|
|
283
285
|
throw new CliError("This working copy belongs to a different Git workspace.");
|
|
284
286
|
}
|
|
287
|
+
// Registered only once the folder passed the checks above.
|
|
288
|
+
if (unregistered) {
|
|
289
|
+
await save(work, runtime);
|
|
290
|
+
}
|
|
285
291
|
if (work.conflicts.length) {
|
|
286
292
|
throw new CliError("Resolve the conflicts before pushing.", "barndog resolve <path>");
|
|
287
293
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { fixSteps } from "../../platform.js";
|
|
1
2
|
import { HTTP_STATUS } from "../../shared/constants.js";
|
|
2
3
|
import { randomUUID } from "node:crypto";
|
|
3
4
|
import { z } from "zod";
|
|
@@ -116,7 +117,7 @@ export async function pushExternal(work, source, options, runtime) {
|
|
|
116
117
|
}))).pull
|
|
117
118
|
: undefined;
|
|
118
119
|
if (pull?.state === "closed" && !options.new) {
|
|
119
|
-
throw new CliError("The pull request is closed. Pull, then push a new one.", "barndog pull
|
|
120
|
+
throw new CliError("The pull request is closed. Pull, then push a new one.", fixSteps(["barndog pull", "barndog push --new"], runtime.platform));
|
|
120
121
|
}
|
|
121
122
|
if (pull && pull.head !== external.pull?.head) {
|
|
122
123
|
throw new CliError("The pull request changed on GitHub since your last pull.", "barndog pull");
|
|
@@ -9,7 +9,7 @@ import { changeUploadSchema } from "@barndog-ai/api-contract";
|
|
|
9
9
|
import { packageFingerprint, } from "@barndog-ai/api-contract/package";
|
|
10
10
|
import { packageKindList } from "../../config/selection.js";
|
|
11
11
|
import { GIT_OBJECT_ID } from "../../shared/patterns.js";
|
|
12
|
-
import { readIfExists, writeAtomic } from "../../shared/files.js";
|
|
12
|
+
import { isInside, readIfExists, writeAtomic } from "../../shared/files.js";
|
|
13
13
|
import { withPidLock } from "../../shared/lock.js";
|
|
14
14
|
import { barndogPaths } from "../../config/paths.js";
|
|
15
15
|
const filesSchema = z.array(z.object({ path: z.string(), content: z.string(), executable: z.boolean() }));
|
|
@@ -134,7 +134,8 @@ async function recoverySnapshot(work, runtime) {
|
|
|
134
134
|
command: removeCommand(recordPath(work.root, runtime), runtime.platform),
|
|
135
135
|
});
|
|
136
136
|
const path = work.pendingSnapshot;
|
|
137
|
-
|
|
137
|
+
const snapshots = barndogPaths(runtime.home).workingCopySnapshots;
|
|
138
|
+
if (!path || path === snapshots || !isInside(snapshots, path)) {
|
|
138
139
|
throw damaged("its record doesn't point at a recovery snapshot");
|
|
139
140
|
}
|
|
140
141
|
const text = await readIfExists(path);
|
|
@@ -189,12 +190,31 @@ export const findGit = (runtime) => {
|
|
|
189
190
|
return gitWorkspaceSchema.parse(value);
|
|
190
191
|
});
|
|
191
192
|
};
|
|
193
|
+
/**
|
|
194
|
+
* A working-copy record read from disk. A record that isn't JSON or doesn't
|
|
195
|
+
* match its schema was damaged, so it says how to start the folder over; the
|
|
196
|
+
* errors `parse` raises itself pass through.
|
|
197
|
+
*/
|
|
198
|
+
function parseRecord(text, root, runtime, parse) {
|
|
199
|
+
try {
|
|
200
|
+
return parse(JSON.parse(text));
|
|
201
|
+
}
|
|
202
|
+
catch (error) {
|
|
203
|
+
if (error instanceof CliError) {
|
|
204
|
+
throw error;
|
|
205
|
+
}
|
|
206
|
+
throw new CliError(`The working-copy record for ${root} is damaged.`, "Save any edits in the folder elsewhere, then remove its working-copy record and pull it again", {
|
|
207
|
+
cause: error,
|
|
208
|
+
command: removeCommand(recordPath(root, runtime), runtime.platform),
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
}
|
|
192
212
|
async function findRecord(runtime, parse) {
|
|
193
213
|
let path = await realpath(runtime.cwd);
|
|
194
214
|
while (true) {
|
|
195
215
|
const text = await readIfExists(recordPath(path, runtime));
|
|
196
216
|
if (text !== null) {
|
|
197
|
-
const work =
|
|
217
|
+
const work = parseRecord(text, path, runtime, parse);
|
|
198
218
|
if (work.root !== path) {
|
|
199
219
|
throw new Error(`The working-copy record for ${path} names a different folder`);
|
|
200
220
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isWindows } from "../../platform.js";
|
|
1
2
|
import { writePackage, readDirectory } from "../workspace/directory.js";
|
|
2
3
|
import { HTTP_STATUS } from "../../shared/constants.js";
|
|
3
4
|
import { randomUUID } from "node:crypto";
|
|
@@ -214,10 +215,24 @@ const CONFLICT_MARKER = /^(?:<{7}|\|{7}|={7}|>{7})(?: |$)/m;
|
|
|
214
215
|
*/
|
|
215
216
|
export const hasConflictMarkers = (text) => CONFLICT_MARKER.test(text);
|
|
216
217
|
/** Clears one conflict once its markers are gone; shared by cloud and Git working copies. */
|
|
218
|
+
/**
|
|
219
|
+
* The conflict `absolute` names. macOS and Windows folders usually ignore
|
|
220
|
+
* case, so there a path that differs only in case still matches, as long as
|
|
221
|
+
* it matches one conflict.
|
|
222
|
+
*/
|
|
223
|
+
function conflictAt(work, absolute, platform) {
|
|
224
|
+
const exact = work.conflicts.find((p) => join(work.root, p) === absolute);
|
|
225
|
+
if (exact || (platform !== "darwin" && !isWindows(platform))) {
|
|
226
|
+
return exact;
|
|
227
|
+
}
|
|
228
|
+
const folded = absolute.toLowerCase();
|
|
229
|
+
const matches = work.conflicts.filter((p) => join(work.root, p).toLowerCase() === folded);
|
|
230
|
+
return matches.length === 1 ? matches[0] : undefined;
|
|
231
|
+
}
|
|
217
232
|
export async function markResolved(work, path, runtime) {
|
|
218
233
|
const { cwd } = runtime;
|
|
219
234
|
const absolute = resolve(await realpath(cwd), path);
|
|
220
|
-
const conflict =
|
|
235
|
+
const conflict = conflictAt(work, absolute, runtime.platform);
|
|
221
236
|
if (!conflict) {
|
|
222
237
|
throw new CliError(`${path} isn't an unresolved conflict.`, "barndog status");
|
|
223
238
|
}
|
|
@@ -272,6 +287,7 @@ export async function pushWorkspace(options = {}, runtime) {
|
|
|
272
287
|
const { cwd } = runtime;
|
|
273
288
|
return locked(runtime, async () => {
|
|
274
289
|
let work;
|
|
290
|
+
let unregistered = false;
|
|
275
291
|
try {
|
|
276
292
|
work = await find(runtime);
|
|
277
293
|
}
|
|
@@ -296,7 +312,7 @@ export async function pushWorkspace(options = {}, runtime) {
|
|
|
296
312
|
base: [],
|
|
297
313
|
conflicts: [],
|
|
298
314
|
};
|
|
299
|
-
|
|
315
|
+
unregistered = true;
|
|
300
316
|
}
|
|
301
317
|
if (options.kind && work.kind !== options.kind) {
|
|
302
318
|
throw new CliError(`This working copy holds a ${work.kind}, not a ${options.kind}.`, "barndog status");
|
|
@@ -304,6 +320,10 @@ export async function pushWorkspace(options = {}, runtime) {
|
|
|
304
320
|
if (options.name && work.name !== options.name) {
|
|
305
321
|
throw new CliError(`This working copy is ${work.name}, not ${options.name}.`, "barndog status");
|
|
306
322
|
}
|
|
323
|
+
// Registered only once the folder passed the checks above.
|
|
324
|
+
if (unregistered) {
|
|
325
|
+
await save(work, runtime);
|
|
326
|
+
}
|
|
307
327
|
await connection(runtime, work.connection);
|
|
308
328
|
if (options.origin) {
|
|
309
329
|
const selected = await selectOrigin(options.origin, work.connection, runtime);
|
|
@@ -10,9 +10,24 @@ import { LoginRequiredError } from "../auth/transport.js";
|
|
|
10
10
|
import { synchronize } from "../environment/sync.js";
|
|
11
11
|
import { assetKinds } from "../asset-kinds/index.js";
|
|
12
12
|
import { barndogPaths } from "../../config/paths.js";
|
|
13
|
+
/** An MCP variable installed servers refer to that has no value on this machine. */
|
|
14
|
+
function variableCheck(event) {
|
|
15
|
+
if (event.type !== "unset-variable") {
|
|
16
|
+
return [];
|
|
17
|
+
}
|
|
18
|
+
return [
|
|
19
|
+
{
|
|
20
|
+
name: "MCP variable",
|
|
21
|
+
status: "warn",
|
|
22
|
+
detail: `${event.variable} has no value here, so ${event.servers.join(", ")} can't use it: BarnDog doesn't keep it and it isn't set in this shell. Coding tools opened outside a terminal may not see your shell's variables either.`,
|
|
23
|
+
fix: `barndog mcp env set ${event.variable}`,
|
|
24
|
+
},
|
|
25
|
+
];
|
|
26
|
+
}
|
|
13
27
|
const failure = (error) => ({
|
|
14
28
|
detail: error instanceof Error ? error.message : String(error),
|
|
15
29
|
fix: error instanceof CliError ? error.hint : undefined,
|
|
30
|
+
command: error instanceof CliError ? error.command : undefined,
|
|
16
31
|
});
|
|
17
32
|
async function gitChecks(workspace, runtime) {
|
|
18
33
|
const checks = [];
|
|
@@ -26,8 +41,8 @@ async function gitChecks(workspace, runtime) {
|
|
|
26
41
|
}
|
|
27
42
|
catch (error) {
|
|
28
43
|
checks.push({ name: "Git access", status: "fail", ...failure(error) });
|
|
29
|
-
return checks;
|
|
30
44
|
}
|
|
45
|
+
// Read locally, so it still helps when the remote can't be reached.
|
|
31
46
|
const state = await readFetchState(workspace.workspaceId, runtime);
|
|
32
47
|
checks.push({
|
|
33
48
|
name: "Last fetch",
|
|
@@ -37,6 +52,9 @@ async function gitChecks(workspace, runtime) {
|
|
|
37
52
|
: "Never fetched.",
|
|
38
53
|
fix: state.fetchedAt ? undefined : "barndog sync",
|
|
39
54
|
});
|
|
55
|
+
if (checks.some((check) => check.status === "fail")) {
|
|
56
|
+
return checks;
|
|
57
|
+
}
|
|
40
58
|
const protectedBranch = await branchProtected(workspace.url, workspace.branch, runtime);
|
|
41
59
|
if (protectedBranch !== true) {
|
|
42
60
|
checks.push({
|
|
@@ -49,7 +67,10 @@ async function gitChecks(workspace, runtime) {
|
|
|
49
67
|
}
|
|
50
68
|
return checks;
|
|
51
69
|
}
|
|
52
|
-
/**
|
|
70
|
+
/**
|
|
71
|
+
* Runs every check that can run: a failure hides only the checks that need
|
|
72
|
+
* what failed (a readable configuration, a session).
|
|
73
|
+
*/
|
|
53
74
|
export async function doctor(runtime) {
|
|
54
75
|
const { home } = runtime;
|
|
55
76
|
const checks = [];
|
|
@@ -127,6 +148,7 @@ export async function doctor(runtime) {
|
|
|
127
148
|
: "Everything selected is installed and up to date.",
|
|
128
149
|
fix: pending ? "barndog sync" : undefined,
|
|
129
150
|
});
|
|
151
|
+
checks.push(...events.flatMap(variableCheck));
|
|
130
152
|
for (const event of events) {
|
|
131
153
|
if (event.type === "notice") {
|
|
132
154
|
checks.push({ name: "Notice", status: "warn", detail: event.message });
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { detectHarnesses } from "../../harnesses/detect.js";
|
|
2
|
+
import { harnesses } from "../../harnesses/registry.js";
|
|
3
|
+
import { locked } from "./transaction.js";
|
|
4
|
+
import { synchronize } from "./sync.js";
|
|
5
|
+
import { readRequiredSettings } from "./operations.js";
|
|
6
|
+
/** Every coding tool BarnDog supports, in registry order. */
|
|
7
|
+
export async function listHarnesses(runtime) {
|
|
8
|
+
const settings = await readRequiredSettings(runtime);
|
|
9
|
+
const detected = await detectHarnesses(runtime);
|
|
10
|
+
return detected.map((harness) => ({
|
|
11
|
+
...harness,
|
|
12
|
+
enabled: settings.harnesses.includes(harness.id),
|
|
13
|
+
}));
|
|
14
|
+
}
|
|
15
|
+
/** Leaves the tools not named as they are. */
|
|
16
|
+
export function changeHarnesses(change, targets, runtime) {
|
|
17
|
+
return applyHarnesses(runtime, (current) => change === "enable"
|
|
18
|
+
? [...current, ...targets]
|
|
19
|
+
: current.filter((harness) => !targets.includes(harness)));
|
|
20
|
+
}
|
|
21
|
+
export function selectHarnesses(selected, runtime) {
|
|
22
|
+
return applyHarnesses(runtime, () => selected);
|
|
23
|
+
}
|
|
24
|
+
function applyHarnesses(runtime, next) {
|
|
25
|
+
return locked(runtime, async () => {
|
|
26
|
+
const settings = await readRequiredSettings(runtime);
|
|
27
|
+
const chosen = new Set(next(settings.harnesses));
|
|
28
|
+
// Registry order, so the saved list doesn't depend on the order typed.
|
|
29
|
+
const managed = harnesses.filter((harness) => chosen.has(harness));
|
|
30
|
+
const events = await synchronize(undefined, runtime, {
|
|
31
|
+
...settings,
|
|
32
|
+
harnesses: managed,
|
|
33
|
+
});
|
|
34
|
+
return { status: "applied", events, harnesses: managed };
|
|
35
|
+
});
|
|
36
|
+
}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { rm } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { isDeepStrictEqual } from "node:util";
|
|
4
|
+
import { resolveAssets } from "../asset-selection/index.js";
|
|
5
|
+
import { forgetImport } from "../imports/local.js";
|
|
6
|
+
import { saveSettings } from "../../config/settings.js";
|
|
7
|
+
import { withSelection } from "../../config/environment.js";
|
|
8
|
+
import { localOverlay, moveDestination, readMoved, recordMoved, } from "../workspace/overlay.js";
|
|
9
|
+
import { openRepoSource, openWorkspaceSource, } from "../workspace/workspace-source.js";
|
|
10
|
+
import { treeFingerprint } from "../workspace/tree.js";
|
|
11
|
+
const targetOf = (entry) => entry.target ?? "the shared workspace";
|
|
12
|
+
const waiting = (entry) => `${entry.name} is still moving to ${moveDestination(entry)}. Your local copy stays in use until that merges.`;
|
|
13
|
+
/** Whether the local copy still holds exactly what was moved. */
|
|
14
|
+
async function unchanged(entry, local, shared, input) {
|
|
15
|
+
if (entry.version) {
|
|
16
|
+
return local.publishedVersion === entry.version;
|
|
17
|
+
}
|
|
18
|
+
// Moves recorded before versions were kept: compare with the shared copy.
|
|
19
|
+
if (local.kind === "mcp") {
|
|
20
|
+
return isDeepStrictEqual(await input.source.mcpDefinition(shared), local.definition);
|
|
21
|
+
}
|
|
22
|
+
const folder = await input.source.packageFolder(local.kind, shared);
|
|
23
|
+
return ((await treeFingerprint(folder, input.runtime)) ===
|
|
24
|
+
(await treeFingerprint(join(input.overlay.label, local.path), input.runtime)));
|
|
25
|
+
}
|
|
26
|
+
/** Where a knowledge move stands; Cloud knowledge is published at once, so only Git waits. */
|
|
27
|
+
async function knowledgeOutcome(entry, model, input) {
|
|
28
|
+
const doc = model.knowledge.find((d) => d.path === entry.path);
|
|
29
|
+
if (!doc) {
|
|
30
|
+
return "gone";
|
|
31
|
+
}
|
|
32
|
+
// Recorded before versions were kept, and Cloud knowledge can't be compared here.
|
|
33
|
+
if (!entry.version) {
|
|
34
|
+
return "changed";
|
|
35
|
+
}
|
|
36
|
+
if (!(await input.sharedKnowledge())?.includes(entry.name)) {
|
|
37
|
+
return "waiting";
|
|
38
|
+
}
|
|
39
|
+
return doc.version === entry.version ? "unchanged" : "changed";
|
|
40
|
+
}
|
|
41
|
+
/** Only paths the local workspace's own model lists get here, so they stay inside it. */
|
|
42
|
+
async function removeLocal(entry, input) {
|
|
43
|
+
await rm(join(input.overlay.label, entry.path), {
|
|
44
|
+
recursive: true,
|
|
45
|
+
force: true,
|
|
46
|
+
});
|
|
47
|
+
await forgetImport(input.overlay.label, entry.kind, entry.name);
|
|
48
|
+
}
|
|
49
|
+
async function settleMoves(input) {
|
|
50
|
+
const records = await readMoved(input.overlay.label);
|
|
51
|
+
if (!records.length) {
|
|
52
|
+
return { selection: input.selection, notices: [], removedLocal: false };
|
|
53
|
+
}
|
|
54
|
+
const model = await input.overlay.model();
|
|
55
|
+
const selected = new Set(resolveAssets(input.catalog, input.selection).assets.map((entry) => entry.asset.id));
|
|
56
|
+
const ids = [...input.selection.individualAssetIds];
|
|
57
|
+
const notices = [];
|
|
58
|
+
const finished = [];
|
|
59
|
+
const removals = [];
|
|
60
|
+
const finish = (entry, keep) => {
|
|
61
|
+
finished.push(entry.path);
|
|
62
|
+
if (keep) {
|
|
63
|
+
notices.push(`${entry.name} changed after it was moved to ${targetOf(entry)}, so your local copy stays as a separate asset.`);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
removals.push(entry);
|
|
67
|
+
notices.push(`${entry.name} moved to ${targetOf(entry)}. Removed the local copy at ${join(input.overlay.label, entry.path)}.`);
|
|
68
|
+
};
|
|
69
|
+
for (const entry of records) {
|
|
70
|
+
if (entry.kind === "knowledge") {
|
|
71
|
+
const outcome = await knowledgeOutcome(entry, model, input);
|
|
72
|
+
if (outcome === "waiting") {
|
|
73
|
+
notices.push(waiting(entry));
|
|
74
|
+
}
|
|
75
|
+
else if (outcome === "gone") {
|
|
76
|
+
finished.push(entry.path);
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
finish(entry, outcome === "changed");
|
|
80
|
+
}
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
const shared = input.catalog.assets.find((asset) => !asset.origin.localOnly &&
|
|
84
|
+
asset.kind === entry.kind &&
|
|
85
|
+
asset.name === entry.name &&
|
|
86
|
+
asset.origin.id === entry.originId);
|
|
87
|
+
if (!shared) {
|
|
88
|
+
notices.push(waiting(entry));
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
if (!selected.has(shared.id) && !ids.includes(shared.id)) {
|
|
92
|
+
ids.push(shared.id);
|
|
93
|
+
}
|
|
94
|
+
const local = model.assets.find((asset) => asset.path === entry.path);
|
|
95
|
+
if (!local) {
|
|
96
|
+
finished.push(entry.path);
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
finish(entry, !(await unchanged(entry, local, shared, input)));
|
|
100
|
+
}
|
|
101
|
+
const selection = ids.length === input.selection.individualAssetIds.length
|
|
102
|
+
? input.selection
|
|
103
|
+
: { ...input.selection, individualAssetIds: ids };
|
|
104
|
+
if (input.persist && finished.length) {
|
|
105
|
+
// Saved first, so an interrupted sync can't leave an asset with neither copy.
|
|
106
|
+
await input.saveSelection(selection);
|
|
107
|
+
for (const entry of removals) {
|
|
108
|
+
await removeLocal(entry, input);
|
|
109
|
+
}
|
|
110
|
+
await recordMoved(input.overlay.label, [], finished);
|
|
111
|
+
}
|
|
112
|
+
return {
|
|
113
|
+
selection,
|
|
114
|
+
notices,
|
|
115
|
+
removedLocal: input.persist && removals.length > 0,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* A machine that stopped using a Git or Cloud workspace can't finish moves
|
|
120
|
+
* into it, so they end here and the local copies stay as they are.
|
|
121
|
+
*/
|
|
122
|
+
async function dropUnreachable(settings, persist) {
|
|
123
|
+
const folder = settings.localWorkspace?.path;
|
|
124
|
+
const records = folder ? await readMoved(folder) : [];
|
|
125
|
+
if (!folder || !records.length || !persist) {
|
|
126
|
+
return [];
|
|
127
|
+
}
|
|
128
|
+
await recordMoved(folder, [], records.map((entry) => entry.path));
|
|
129
|
+
return [
|
|
130
|
+
`This machine no longer uses the workspace ${records.map((entry) => entry.name).join(", ")} ${records.length === 1 ? "was" : "were"} moving to, so ${records.length === 1 ? "its local copy stays" : "their local copies stay"} as ${records.length === 1 ? "it is" : "they are"}.`,
|
|
131
|
+
];
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Finishes the moves whose shared copy exists. When a local copy was deleted,
|
|
135
|
+
* the catalog read before it still lists that copy, so it is read again
|
|
136
|
+
* unless the caller supplied it (`reread` false).
|
|
137
|
+
*/
|
|
138
|
+
export async function finishMoves(input) {
|
|
139
|
+
const { settings, source, options, runtime } = input;
|
|
140
|
+
// A one-off --config delivery never changes what this machine keeps.
|
|
141
|
+
const persist = !options.dryRun && !input.configPath;
|
|
142
|
+
const reread = !options.source && !options.catalog;
|
|
143
|
+
const overlay = localOverlay(settings, runtime);
|
|
144
|
+
if (!overlay || !source) {
|
|
145
|
+
return {
|
|
146
|
+
source,
|
|
147
|
+
catalog: input.catalog,
|
|
148
|
+
selection: input.selection,
|
|
149
|
+
notices: await dropUnreachable(settings, persist),
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
const moves = await settleMoves({
|
|
153
|
+
overlay,
|
|
154
|
+
source,
|
|
155
|
+
catalog: input.catalog,
|
|
156
|
+
selection: input.selection,
|
|
157
|
+
sharedKnowledge: async () => settings.gitWorkspace
|
|
158
|
+
? ((await openRepoSource(settings, runtime, {
|
|
159
|
+
refresh: "none",
|
|
160
|
+
})?.model())?.knowledge.map((doc) => doc.content.name) ?? null)
|
|
161
|
+
: null,
|
|
162
|
+
persist,
|
|
163
|
+
saveSelection: (next) => saveSettings(withSelection(settings, next), runtime.home),
|
|
164
|
+
runtime,
|
|
165
|
+
});
|
|
166
|
+
if (!moves.removedLocal || !reread) {
|
|
167
|
+
return { source, catalog: input.catalog, ...moves };
|
|
168
|
+
}
|
|
169
|
+
const fresh = openWorkspaceSource(settings, runtime, { refresh: "none" }) ?? source;
|
|
170
|
+
return { source: fresh, catalog: await fresh.catalog(), ...moves };
|
|
171
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { slugify
|
|
1
|
+
import { slugify } from "../../shared/patterns.js";
|
|
2
|
+
import { assetKinds } from "../asset-kinds/index.js";
|
|
2
3
|
/** Eight ID characters distinguish hooks with the same display name. */
|
|
3
4
|
const HOOK_ID_SUFFIX_LENGTH = 8;
|
|
4
5
|
/** Unknown origins sort after all explicitly ranked origins. */
|
|
@@ -14,11 +15,14 @@ const rank = {
|
|
|
14
15
|
};
|
|
15
16
|
/** `<origin-type>-<origin-slug>-<name>` with single hyphens, e.g. team-super-team-review. */
|
|
16
17
|
export function prefixedName(asset) {
|
|
17
|
-
|
|
18
|
+
const prefix = [
|
|
18
19
|
asset.origin.type,
|
|
19
20
|
asset.origin.slug ?? asset.origin.id ?? "",
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
].join("-");
|
|
22
|
+
// An MCP server keeps its own spelling, such as my_server; only the prefix is a slug.
|
|
23
|
+
return asset.kind === "mcp"
|
|
24
|
+
? `${slugify(prefix)}-${asset.name}`
|
|
25
|
+
: slugify(`${prefix}-${asset.name}`);
|
|
22
26
|
}
|
|
23
27
|
/**
|
|
24
28
|
* The name an asset installs under: its saved rename from `localNames`, else
|
|
@@ -45,7 +49,7 @@ export function hookFolders(hooks, localNames) {
|
|
|
45
49
|
folders.set(hook.id, folder);
|
|
46
50
|
used.add(folder);
|
|
47
51
|
};
|
|
48
|
-
const plain = (hook) => localNames[hook.id] ?? prefixedName(hook);
|
|
52
|
+
const plain = (hook) => localNames[hook.id] ?? prefixedName({ ...hook, kind: "hook" });
|
|
49
53
|
const idText = (hook) => hook.id.replace(/[^a-z0-9]/gi, "").toLowerCase();
|
|
50
54
|
const suffixed = (hook) => `${plain(hook)}-${idText(hook).slice(0, HOOK_ID_SUFFIX_LENGTH)}`;
|
|
51
55
|
const whole = (hook) => `${plain(hook)}-${idText(hook)}`;
|
|
@@ -149,7 +153,7 @@ export async function resolveClashes(assets, localNames, resolver) {
|
|
|
149
153
|
if (rename) {
|
|
150
154
|
const name = prefixedName(rename);
|
|
151
155
|
if (rename.renamable === false ||
|
|
152
|
-
!
|
|
156
|
+
!assetKinds[rename.kind].validName(name) ||
|
|
153
157
|
active.some((other) => other.id !== rename.id &&
|
|
154
158
|
other.kind === rename.kind &&
|
|
155
159
|
installedName(other, names) === name)) {
|