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,106 +0,0 @@
|
|
|
1
|
-
import { inspect } from "../inspection/index.js";
|
|
2
|
-
import { doctor } from "../doctor/index.js";
|
|
3
|
-
import { environmentOperation } from "../environment/operations.js";
|
|
4
|
-
import { hookSchema } from "@barndog-ai/api-contract";
|
|
5
|
-
import { runtimeRequirements } from "../native/adapters.js";
|
|
6
|
-
import { homedir } from "node:os";
|
|
7
|
-
import { knowledgeGet, knowledgeList, knowledgeProblems, } from "../knowledge/index.js";
|
|
8
|
-
import { writeMcp, authenticateMcp, mcpVersions } from "../mcps/index.js";
|
|
9
|
-
import { developerAssets, developers, promote } from "../discovery/index.js";
|
|
10
|
-
import { selectAsset } from "../environment/remote.js";
|
|
11
|
-
import { testHook } from "../hooks/test.js";
|
|
12
|
-
import { gitOperation } from "../git-hosts/index.js";
|
|
13
|
-
import { readSettings } from "../../config/settings.js";
|
|
14
|
-
import { repoForOrigin, repoHookCompatibility, selectRepoAsset, showRepoAsset, validateFolder, } from "../git-workspace/assets.js";
|
|
15
|
-
import { migrate } from "../git-workspace/migrate.js";
|
|
16
|
-
import { listLocalAssets, moveLocalAssets } from "../git-workspace/move.js";
|
|
17
|
-
import { LOCAL_ORIGIN } from "../git-workspace/overlay.js";
|
|
18
|
-
import { updateImported } from "../imports/local.js";
|
|
19
|
-
import { adaptHook } from "../hooks/adapt.js";
|
|
20
|
-
export async function capability(action, options = {}, home = homedir()) {
|
|
21
|
-
if (action === "validate")
|
|
22
|
-
return validateFolder(options.directory ?? ".");
|
|
23
|
-
if (action === "local-list")
|
|
24
|
-
return listLocalAssets(home);
|
|
25
|
-
if (action === "local-move")
|
|
26
|
-
return moveLocalAssets({
|
|
27
|
-
names: options.names,
|
|
28
|
-
to: options.to,
|
|
29
|
-
as: options.as,
|
|
30
|
-
repo: options.repo,
|
|
31
|
-
server: options.server,
|
|
32
|
-
}, home);
|
|
33
|
-
if (action === "imports-update")
|
|
34
|
-
return updateImported(options.kind, options.name, { force: options.force, dryRun: options.dryRun }, home);
|
|
35
|
-
if (action === "promote" && options.origin === LOCAL_ORIGIN)
|
|
36
|
-
return moveLocalAssets({
|
|
37
|
-
names: [options.name],
|
|
38
|
-
kind: options.kind,
|
|
39
|
-
to: options.target,
|
|
40
|
-
as: options.newName === options.name ? undefined : options.newName,
|
|
41
|
-
}, home);
|
|
42
|
-
if (action === "migrate")
|
|
43
|
-
return migrate({ server: options.server, dryRun: options.dryRun }, home);
|
|
44
|
-
if (action === "show" || action === "hooks-compatibility") {
|
|
45
|
-
const settings = await readSettings(home);
|
|
46
|
-
const repo = settings && repoForOrigin(settings, home, options.origin);
|
|
47
|
-
if (repo) {
|
|
48
|
-
const asset = selectRepoAsset(await repo.model(), action === "show" ? options.kind : "hook", options.name, options.origin);
|
|
49
|
-
return action === "show"
|
|
50
|
-
? showRepoAsset(asset)
|
|
51
|
-
: repoHookCompatibility(asset);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
if (["whoami", "open", "repo-status"].includes(action))
|
|
55
|
-
return inspect(action, home);
|
|
56
|
-
if (action === "doctor")
|
|
57
|
-
return doctor(home);
|
|
58
|
-
if (action.startsWith("github-"))
|
|
59
|
-
return gitOperation(action.slice(7), options, home);
|
|
60
|
-
if (action === "knowledge-enable" || action === "knowledge-disable")
|
|
61
|
-
return environmentOperation(action, {}, home);
|
|
62
|
-
if (action === "knowledge-list")
|
|
63
|
-
return knowledgeList(home, options.always);
|
|
64
|
-
if (action === "knowledge-problems")
|
|
65
|
-
return knowledgeProblems(home);
|
|
66
|
-
if (action === "knowledge-get")
|
|
67
|
-
return knowledgeGet(options.name, home);
|
|
68
|
-
if (action === "mcp-create" || action === "mcp-update")
|
|
69
|
-
return writeMcp(options.name, options.origin, options.file, home, options.key, action === "mcp-update" ? options.expectedVersion : undefined);
|
|
70
|
-
if (action === "mcp-auth")
|
|
71
|
-
return authenticateMcp(options.name, options.origin, options.harness, home);
|
|
72
|
-
if (action === "mcp-versions")
|
|
73
|
-
return mcpVersions(options.name, options.origin, home);
|
|
74
|
-
if (action === "show")
|
|
75
|
-
return (await selectAsset(options.kind, options.name, options.origin, home)).asset;
|
|
76
|
-
if (action === "hooks-compatibility") {
|
|
77
|
-
const selected = await selectAsset("hook", options.name, options.origin, home);
|
|
78
|
-
const asset = hookSchema.parse(selected.asset);
|
|
79
|
-
return {
|
|
80
|
-
version: asset.version.number,
|
|
81
|
-
compatibility: await Promise.all(asset.compatibility.map(async (row) => ({
|
|
82
|
-
...row,
|
|
83
|
-
runtimeIssue: row.implementation
|
|
84
|
-
? await runtimeRequirements(row.harness, row.implementation.requirements)
|
|
85
|
-
: "No implementation for this harness",
|
|
86
|
-
}))),
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
if (action === "hooks-adapt")
|
|
90
|
-
return adaptHook(options.name, options.origin, options.targets, home);
|
|
91
|
-
if (action === "hooks-test")
|
|
92
|
-
return testHook(options.name, options.origin, {
|
|
93
|
-
harness: options.harness,
|
|
94
|
-
input: options.input,
|
|
95
|
-
event: options.event,
|
|
96
|
-
handler: options.handler,
|
|
97
|
-
timeout: options.timeout,
|
|
98
|
-
}, home);
|
|
99
|
-
if (action === "developers-list")
|
|
100
|
-
return developers(options.search, home);
|
|
101
|
-
if (action === "developers-assets")
|
|
102
|
-
return developerAssets(options.name, options.search, home);
|
|
103
|
-
if (action === "promote" || action === "fork")
|
|
104
|
-
return promote(options.kind, options.name, options.origin, options.target, options.newName, home, action === "fork", options.key);
|
|
105
|
-
throw new Error(`Unknown capability: ${action}`);
|
|
106
|
-
}
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { createApiClient, hookManifestSchema } from "@barndog-ai/api-contract";
|
|
2
|
-
import { packageMetadata, } from "@barndog-ai/api-contract/package";
|
|
3
|
-
import { parse } from "yaml";
|
|
4
|
-
import { serverFetch, normalizeServer } from "../auth/transport.js";
|
|
5
|
-
import { homedir } from "node:os";
|
|
6
|
-
export function packagePath(path, kind) {
|
|
7
|
-
return kind === "skill"
|
|
8
|
-
? path
|
|
9
|
-
: path
|
|
10
|
-
.replace(/^\/v1\/skills(?=\/|$)/, "/v1/hooks")
|
|
11
|
-
.replace(/^\/v1\/skill-changes(?=\/|$)/, "/v1/hook-changes");
|
|
12
|
-
}
|
|
13
|
-
function fields(value, from, to) {
|
|
14
|
-
if (Array.isArray(value))
|
|
15
|
-
return value.map((v) => fields(v, from, to));
|
|
16
|
-
if (value && typeof value === "object")
|
|
17
|
-
return Object.fromEntries(Object.entries(value).map(([key, val]) => [
|
|
18
|
-
key === from
|
|
19
|
-
? to
|
|
20
|
-
: key === `published${from[0].toUpperCase()}${from.slice(1)}`
|
|
21
|
-
? `published${to[0].toUpperCase()}${to.slice(1)}`
|
|
22
|
-
: key,
|
|
23
|
-
fields(val, from, to),
|
|
24
|
-
]));
|
|
25
|
-
return value;
|
|
26
|
-
}
|
|
27
|
-
/** Transport adapter for the proven working-copy algorithm. Distinct public Hook
|
|
28
|
-
* contracts and manifests remain separate; legacy Skill field aliases stay local. */
|
|
29
|
-
export function collaborationClient(server, home = homedir(), kind = "skill") {
|
|
30
|
-
const transport = serverFetch(server, home);
|
|
31
|
-
return createApiClient({
|
|
32
|
-
baseUrl: normalizeServer(server),
|
|
33
|
-
fetch: async (input, init) => {
|
|
34
|
-
let request = new Request(input, init);
|
|
35
|
-
if (kind === "hook") {
|
|
36
|
-
const url = new URL(request.url);
|
|
37
|
-
url.pathname = packagePath(url.pathname, kind);
|
|
38
|
-
const headers = new Headers(request.headers);
|
|
39
|
-
let body;
|
|
40
|
-
if (request.method !== "GET" && request.method !== "HEAD") {
|
|
41
|
-
if (headers.get("content-type")?.includes("multipart/form-data")) {
|
|
42
|
-
const form = await request.formData();
|
|
43
|
-
const metadata = form.get("metadata");
|
|
44
|
-
if (typeof metadata === "string")
|
|
45
|
-
form.set("metadata", JSON.stringify(fields(JSON.parse(metadata), "skillId", "hookId")));
|
|
46
|
-
headers.delete("content-type");
|
|
47
|
-
headers.delete("content-length");
|
|
48
|
-
body = form;
|
|
49
|
-
}
|
|
50
|
-
else
|
|
51
|
-
body = await request.text();
|
|
52
|
-
}
|
|
53
|
-
request = new Request(url, {
|
|
54
|
-
method: request.method,
|
|
55
|
-
headers,
|
|
56
|
-
body,
|
|
57
|
-
signal: request.signal,
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
const response = await transport(request);
|
|
61
|
-
if (kind !== "hook" ||
|
|
62
|
-
!response.headers.get("content-type")?.includes("application/json"))
|
|
63
|
-
return response;
|
|
64
|
-
let data = fields(await response.json(), "hookId", "skillId");
|
|
65
|
-
if (data && "nextCursor" in data && Array.isArray(data.hooks)) {
|
|
66
|
-
const { hooks, ...rest } = data;
|
|
67
|
-
data = { ...rest, skills: hooks };
|
|
68
|
-
}
|
|
69
|
-
const headers = new Headers(response.headers);
|
|
70
|
-
headers.delete("content-length");
|
|
71
|
-
return new Response(JSON.stringify(data), {
|
|
72
|
-
status: response.status,
|
|
73
|
-
headers,
|
|
74
|
-
});
|
|
75
|
-
},
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
export function metadata(entries, kind = "skill") {
|
|
79
|
-
if (kind === "skill")
|
|
80
|
-
return packageMetadata(entries);
|
|
81
|
-
if (!entries.some((e) => e.path === "hook.yaml"))
|
|
82
|
-
throw new Error("MISSING_PACKAGE_MANIFEST: hook.yaml");
|
|
83
|
-
const manifest = hookManifestSchema.parse(parse(entries.find((e) => e.path === "hook.yaml")?.data.toString("utf8") ?? ""));
|
|
84
|
-
for (const implementation of Object.values(manifest.implementations))
|
|
85
|
-
if (implementation)
|
|
86
|
-
for (const script of implementation.scripts)
|
|
87
|
-
if (!entries.some((e) => e.path === script))
|
|
88
|
-
throw new Error(`Missing Hook script: ${script}`);
|
|
89
|
-
return manifest;
|
|
90
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { hookSchema, mcpSchema, skillSchema } from "@barndog-ai/api-contract";
|
|
2
|
-
import { cacheKey, cachedPackage } from "./packages.js";
|
|
3
|
-
import { environmentCatalog, getAsset } from "./remote.js";
|
|
4
|
-
async function currentAsset(kind, reference, conn, home) {
|
|
5
|
-
const data = await getAsset(kind, reference.id, conn, home);
|
|
6
|
-
if (data.id !== reference.id ||
|
|
7
|
-
data.version.id !== reference.publishedVersion ||
|
|
8
|
-
data.name !== reference.name ||
|
|
9
|
-
data.organizationId !== conn.organizationId)
|
|
10
|
-
throw new Error("Catalog changed during staging; retry sync");
|
|
11
|
-
return data;
|
|
12
|
-
}
|
|
13
|
-
export function cloudSource(conn, home) {
|
|
14
|
-
return {
|
|
15
|
-
cacheKey: cacheKey(conn),
|
|
16
|
-
journal: conn,
|
|
17
|
-
catalog: async () => (await environmentCatalog(home, conn)).catalog,
|
|
18
|
-
skillOrHookPackage: async (kind, reference) => {
|
|
19
|
-
const data = await currentAsset(kind, reference, conn, home);
|
|
20
|
-
return cachedPackage(kind, kind === "skill" ? skillSchema.parse(data) : hookSchema.parse(data), conn, home);
|
|
21
|
-
},
|
|
22
|
-
mcpDefinition: async (reference) => mcpSchema.parse(await currentAsset("mcp", reference, conn, home)).version
|
|
23
|
-
.definition,
|
|
24
|
-
invalidAssets: async () => new Map(),
|
|
25
|
-
notices: () => [],
|
|
26
|
-
};
|
|
27
|
-
}
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import { chmod, lstat, mkdir, readdir, readFile, rename, rm, rmdir, writeFile, } from "node:fs/promises";
|
|
2
|
-
import { randomUUID } from "node:crypto";
|
|
3
|
-
import { dirname, join } from "node:path";
|
|
4
|
-
import { packageFingerprint, } from "@barndog-ai/api-contract/package";
|
|
5
|
-
/** Readable, stable folders that harnesses resolve; the commit-pinned cache stays internal. */
|
|
6
|
-
export function installedRoot(home, kind) {
|
|
7
|
-
return join(home, ".barndog", "installed", kind === "skill" ? "skills" : "hooks");
|
|
8
|
-
}
|
|
9
|
-
export function installedPath(home, kind, name) {
|
|
10
|
-
return join(installedRoot(home, kind), name);
|
|
11
|
-
}
|
|
12
|
-
export async function readTree(directory) {
|
|
13
|
-
const entries = [];
|
|
14
|
-
async function visit(base) {
|
|
15
|
-
for (const child of (await readdir(join(directory, base))).sort()) {
|
|
16
|
-
const path = base ? `${base}/${child}` : child;
|
|
17
|
-
const info = await lstat(join(directory, path));
|
|
18
|
-
if (info.isDirectory())
|
|
19
|
-
await visit(path);
|
|
20
|
-
else if (info.isFile())
|
|
21
|
-
entries.push({
|
|
22
|
-
path,
|
|
23
|
-
data: await readFile(join(directory, path)),
|
|
24
|
-
executable: !!(info.mode & 0o111),
|
|
25
|
-
});
|
|
26
|
-
else
|
|
27
|
-
throw new Error(`Unexpected file type in ${join(directory, path)}`);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
await visit("");
|
|
31
|
-
return entries;
|
|
32
|
-
}
|
|
33
|
-
/** Fingerprint of an installed folder, or null when it does not exist. */
|
|
34
|
-
export async function treeFingerprint(directory) {
|
|
35
|
-
try {
|
|
36
|
-
const info = await lstat(directory);
|
|
37
|
-
if (!info.isDirectory())
|
|
38
|
-
return `not-a-directory:${info.mode}`;
|
|
39
|
-
}
|
|
40
|
-
catch (error) {
|
|
41
|
-
if (error.code === "ENOENT")
|
|
42
|
-
return null;
|
|
43
|
-
throw error;
|
|
44
|
-
}
|
|
45
|
-
try {
|
|
46
|
-
return packageFingerprint(await readTree(directory));
|
|
47
|
-
}
|
|
48
|
-
catch {
|
|
49
|
-
return "unreadable";
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
const frontmatter = /^(\uFEFF?---\r?\n)([\s\S]*?)(\r?\n---(?:\r?\n|$))/;
|
|
53
|
-
/** Points SKILL.md's name at the installed folder name; harnesses require them to match. */
|
|
54
|
-
export function renameSkillEntries(entries, name) {
|
|
55
|
-
return entries.map((entry) => {
|
|
56
|
-
if (entry.path !== "SKILL.md")
|
|
57
|
-
return entry;
|
|
58
|
-
const text = entry.data.toString("utf8");
|
|
59
|
-
const match = frontmatter.exec(text);
|
|
60
|
-
if (!match)
|
|
61
|
-
return entry;
|
|
62
|
-
const body = /^name\s*:.*$/m.test(match[2])
|
|
63
|
-
? match[2].replace(/^name\s*:.*$/m, `name: ${name}`)
|
|
64
|
-
: `name: ${name}\n${match[2]}`;
|
|
65
|
-
return {
|
|
66
|
-
...entry,
|
|
67
|
-
data: Buffer.from(`${match[1]}${body}${match[3]}${text.slice(match[0].length)}`),
|
|
68
|
-
};
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
export async function desiredEntries(source, rename) {
|
|
72
|
-
const entries = await readTree(source);
|
|
73
|
-
return rename ? renameSkillEntries(entries, rename) : entries;
|
|
74
|
-
}
|
|
75
|
-
async function removeEmptyDirectories(directory) {
|
|
76
|
-
for (const child of await readdir(directory)) {
|
|
77
|
-
const path = join(directory, child);
|
|
78
|
-
if ((await lstat(path)).isDirectory()) {
|
|
79
|
-
await removeEmptyDirectories(path);
|
|
80
|
-
if (!(await readdir(path)).length)
|
|
81
|
-
await rmdir(path);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Mirrors entries into an existing folder file by file. The folder itself is never
|
|
87
|
-
* replaced, so harness file watchers observe edits instead of a vanished directory.
|
|
88
|
-
*/
|
|
89
|
-
export async function mirrorTree(directory, entries) {
|
|
90
|
-
await mkdir(directory, { recursive: true, mode: 0o755 });
|
|
91
|
-
const wanted = new Map(entries.map((entry) => [entry.path, entry]));
|
|
92
|
-
let current = [];
|
|
93
|
-
try {
|
|
94
|
-
current = await readTree(directory);
|
|
95
|
-
}
|
|
96
|
-
catch {
|
|
97
|
-
await rm(directory, { recursive: true, force: true });
|
|
98
|
-
await mkdir(directory, { recursive: true, mode: 0o755 });
|
|
99
|
-
}
|
|
100
|
-
for (const existing of current)
|
|
101
|
-
if (!wanted.has(existing.path))
|
|
102
|
-
await rm(join(directory, existing.path), { force: true });
|
|
103
|
-
// Emptied folders must go first: a new file may take one's exact path.
|
|
104
|
-
await removeEmptyDirectories(directory);
|
|
105
|
-
for (const entry of entries) {
|
|
106
|
-
const path = join(directory, entry.path);
|
|
107
|
-
const existing = current.find((item) => item.path === entry.path);
|
|
108
|
-
const mode = entry.executable ? 0o755 : 0o644;
|
|
109
|
-
if (existing?.data.equals(entry.data)) {
|
|
110
|
-
if (existing.executable !== entry.executable)
|
|
111
|
-
await chmod(path, mode);
|
|
112
|
-
continue;
|
|
113
|
-
}
|
|
114
|
-
await mkdir(dirname(path), { recursive: true, mode: 0o755 });
|
|
115
|
-
const temp = `${path}.${randomUUID()}.tmp`;
|
|
116
|
-
try {
|
|
117
|
-
await writeFile(temp, entry.data, { mode, flag: "wx" });
|
|
118
|
-
await rename(temp, path);
|
|
119
|
-
}
|
|
120
|
-
finally {
|
|
121
|
-
await rm(temp, { force: true });
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import { createHash, randomUUID } from "node:crypto";
|
|
2
|
-
import { mkdir, readdir, readFile, rename, rm, lstat, writeFile, } from "node:fs/promises";
|
|
3
|
-
import { join } from "node:path";
|
|
4
|
-
import { parse } from "yaml";
|
|
5
|
-
import { hookManifestSchema } from "@barndog-ai/api-contract";
|
|
6
|
-
import { defaultLimits, parsePackage, packageFingerprint, packageMetadata, directoryFingerprint, writePackage, } from "@barndog-ai/api-contract/package";
|
|
7
|
-
import { serverFetch } from "../auth/transport.js";
|
|
8
|
-
/** One identity's cache partition: server, organization and developer never mix. */
|
|
9
|
-
export function cacheKey(conn) {
|
|
10
|
-
const server = createHash("sha256").update(conn.server).digest("hex");
|
|
11
|
-
return join(server, conn.organizationId, conn.developerId);
|
|
12
|
-
}
|
|
13
|
-
export const cacheRoot = (key, home) => join(home, ".barndog", "packages", key);
|
|
14
|
-
/**
|
|
15
|
-
* Deletes cached versions nothing installs any more. Every cached version was
|
|
16
|
-
* downloaded from the workspace, so an older one can always be fetched again.
|
|
17
|
-
* Other identities' caches are left alone.
|
|
18
|
-
*/
|
|
19
|
-
export async function pruneCache(key, home, keep) {
|
|
20
|
-
const root = cacheRoot(key, home);
|
|
21
|
-
let removed = 0;
|
|
22
|
-
const children = async (path) => {
|
|
23
|
-
try {
|
|
24
|
-
return await readdir(path);
|
|
25
|
-
}
|
|
26
|
-
catch (error) {
|
|
27
|
-
if (error.code === "ENOENT")
|
|
28
|
-
return [];
|
|
29
|
-
throw error;
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
for (const parent of [root, join(root, "hooks")])
|
|
33
|
-
for (const asset of await children(parent)) {
|
|
34
|
-
if (!/^[0-9a-f-]{36}$/i.test(asset))
|
|
35
|
-
continue;
|
|
36
|
-
const directory = join(parent, asset);
|
|
37
|
-
for (const revision of await children(directory)) {
|
|
38
|
-
const path = join(directory, revision);
|
|
39
|
-
if (keep.has(path))
|
|
40
|
-
continue;
|
|
41
|
-
if (!/^[0-9a-f]{40}$/.test(revision) && !revision.startsWith(".stage-"))
|
|
42
|
-
continue;
|
|
43
|
-
await rm(path, { recursive: true, force: true });
|
|
44
|
-
removed++;
|
|
45
|
-
}
|
|
46
|
-
if (!(await children(directory)).length)
|
|
47
|
-
await rm(directory, { recursive: true, force: true });
|
|
48
|
-
}
|
|
49
|
-
return removed;
|
|
50
|
-
}
|
|
51
|
-
/** Returns the immutable cached folder for a revision, loading it only when absent. */
|
|
52
|
-
export async function storePackage(kind, asset, key, home, load) {
|
|
53
|
-
const parent = join(cacheRoot(key, home), ...(kind === "hook" ? ["hooks"] : []), asset.id);
|
|
54
|
-
await mkdir(parent, { recursive: true, mode: 0o700 });
|
|
55
|
-
const check = async (root) => {
|
|
56
|
-
const saved = JSON.parse(await readFile(join(root, "manifest.json"), "utf8"));
|
|
57
|
-
if (typeof saved.fingerprint !== "string" ||
|
|
58
|
-
(await directoryFingerprint(join(root, asset.name))) !== saved.fingerprint)
|
|
59
|
-
throw new Error(`Cached ${kind} was modified locally: ${asset.name}`);
|
|
60
|
-
};
|
|
61
|
-
for (const revision of await readdir(parent))
|
|
62
|
-
if (/^[0-9a-f]{40}$/.test(revision))
|
|
63
|
-
await check(join(parent, revision));
|
|
64
|
-
const target = join(parent, asset.revision);
|
|
65
|
-
try {
|
|
66
|
-
await lstat(target);
|
|
67
|
-
await check(target);
|
|
68
|
-
return join(target, asset.name);
|
|
69
|
-
}
|
|
70
|
-
catch (error) {
|
|
71
|
-
if (error.code !== "ENOENT")
|
|
72
|
-
throw error;
|
|
73
|
-
}
|
|
74
|
-
const entries = await load();
|
|
75
|
-
const stage = join(parent, `.stage-${randomUUID()}`);
|
|
76
|
-
try {
|
|
77
|
-
await writePackage(join(stage, asset.name), entries);
|
|
78
|
-
await writeFile(join(stage, "manifest.json"), JSON.stringify({ fingerprint: packageFingerprint(entries) }), { mode: 0o600 });
|
|
79
|
-
await rename(stage, target);
|
|
80
|
-
}
|
|
81
|
-
finally {
|
|
82
|
-
await rm(stage, { recursive: true, force: true });
|
|
83
|
-
}
|
|
84
|
-
return join(target, asset.name);
|
|
85
|
-
}
|
|
86
|
-
export async function cachedPackage(kind, asset, conn, home) {
|
|
87
|
-
return storePackage(kind, { id: asset.id, name: asset.name, revision: asset.version.commit }, cacheKey(conn), home, async () => {
|
|
88
|
-
const response = await serverFetch(conn.server, home)(`${conn.server}/v1/${kind === "skill" ? "skills" : "hooks"}/${asset.id}/versions/${asset.version.number}/package`);
|
|
89
|
-
if (!response.ok)
|
|
90
|
-
throw new Error(`Package download failed (${response.status}): ${asset.name}`);
|
|
91
|
-
if (response.headers.get("etag") !== `"${asset.version.commit}"`)
|
|
92
|
-
throw new Error("Package revision does not match catalog");
|
|
93
|
-
if (!response.body)
|
|
94
|
-
throw new Error("Missing package body");
|
|
95
|
-
let size = 0;
|
|
96
|
-
const chunks = [];
|
|
97
|
-
for await (const chunk of response.body) {
|
|
98
|
-
size += chunk.length;
|
|
99
|
-
if (size > defaultLimits.compressed)
|
|
100
|
-
throw new Error("PACKAGE_TOO_LARGE");
|
|
101
|
-
chunks.push(chunk);
|
|
102
|
-
}
|
|
103
|
-
const entries = await parsePackage(Buffer.concat(chunks), defaultLimits, kind === "hook" ? "hook.yaml" : "SKILL.md");
|
|
104
|
-
const metadata = kind === "skill"
|
|
105
|
-
? packageMetadata(entries)
|
|
106
|
-
: hookManifestSchema.parse(parse(entries
|
|
107
|
-
.find((e) => e.path === "hook.yaml")
|
|
108
|
-
.data.toString("utf8")));
|
|
109
|
-
if (metadata.name !== asset.name)
|
|
110
|
-
throw new Error("Package name does not match catalog");
|
|
111
|
-
if (kind === "hook")
|
|
112
|
-
for (const implementation of Object.values(hookManifestSchema.parse(metadata).implementations)) {
|
|
113
|
-
if (implementation)
|
|
114
|
-
for (const script of implementation.scripts)
|
|
115
|
-
if (!entries.some((e) => e.path === script))
|
|
116
|
-
throw new Error(`Missing Hook script: ${script}`);
|
|
117
|
-
}
|
|
118
|
-
return entries;
|
|
119
|
-
});
|
|
120
|
-
}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
import { environmentCatalogSchema, hookSchema, mcpSchema, skillSchema, ApiError, } from "@barndog-ai/api-contract";
|
|
3
|
-
import { serverFetch } from "../auth/transport.js";
|
|
4
|
-
import { connection } from "../collaboration/remote.js";
|
|
5
|
-
import { connectionContext } from "../skills/remote.js";
|
|
6
|
-
import { homedir } from "node:os";
|
|
7
|
-
import { CliError } from "../../errors.js";
|
|
8
|
-
export async function request(conn, path, schema, home = homedir(), method = "GET", body) {
|
|
9
|
-
if (!path.startsWith("/v1/") || path.includes(".."))
|
|
10
|
-
throw new Error("Invalid API path");
|
|
11
|
-
const response = await serverFetch(conn.server, home)(`${conn.server}${path}`, {
|
|
12
|
-
method,
|
|
13
|
-
headers: body instanceof FormData
|
|
14
|
-
? undefined
|
|
15
|
-
: body === undefined
|
|
16
|
-
? undefined
|
|
17
|
-
: { "Content-Type": "application/json" },
|
|
18
|
-
body: body instanceof FormData
|
|
19
|
-
? body
|
|
20
|
-
: body === undefined
|
|
21
|
-
? undefined
|
|
22
|
-
: JSON.stringify(body),
|
|
23
|
-
});
|
|
24
|
-
if (!response.ok) {
|
|
25
|
-
const error = z
|
|
26
|
-
.object({ code: z.string(), message: z.string() })
|
|
27
|
-
.safeParse(await response.json().catch(() => null));
|
|
28
|
-
throw new ApiError(response.status, error.success ? error.data.code : "REQUEST_FAILED", error.success
|
|
29
|
-
? error.data.message
|
|
30
|
-
: `Request failed (${response.status})`);
|
|
31
|
-
}
|
|
32
|
-
return schema.parse(await response.json());
|
|
33
|
-
}
|
|
34
|
-
export async function environmentCatalog(home = homedir(), expected) {
|
|
35
|
-
const conn = expected
|
|
36
|
-
? await connectionContext(expected.server, home)
|
|
37
|
-
: await connection(home);
|
|
38
|
-
if (expected &&
|
|
39
|
-
(conn.organizationId !== expected.organizationId ||
|
|
40
|
-
conn.developerId !== expected.developerId))
|
|
41
|
-
throw new Error("Authenticated identity does not match the selected environment");
|
|
42
|
-
return {
|
|
43
|
-
connection: conn,
|
|
44
|
-
catalog: await request(conn, "/v1/environment/catalog", environmentCatalogSchema, home),
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
export const assetRoute = (kind) => kind === "skill" ? "skills" : kind === "hook" ? "hooks" : "mcps";
|
|
48
|
-
export const assetSchema = (kind) => kind === "skill" ? skillSchema : kind === "hook" ? hookSchema : mcpSchema;
|
|
49
|
-
export async function getAsset(kind, id, conn, home = homedir()) {
|
|
50
|
-
// Parse in each domain rather than defining a generic content schema.
|
|
51
|
-
const path = `/v1/${assetRoute(kind)}/${z.uuidv4().parse(id)}`;
|
|
52
|
-
if (kind === "skill")
|
|
53
|
-
return request(conn, path, skillSchema, home);
|
|
54
|
-
if (kind === "hook")
|
|
55
|
-
return request(conn, path, hookSchema, home);
|
|
56
|
-
return request(conn, path, mcpSchema, home);
|
|
57
|
-
}
|
|
58
|
-
export async function selectAsset(kind, name, origin, home = homedir()) {
|
|
59
|
-
const { connection: conn, catalog } = await environmentCatalog(home);
|
|
60
|
-
const { matchesOrigin } = await import("../collaboration/remote.js");
|
|
61
|
-
const matches = catalog.assets.filter((a) => a.kind === kind &&
|
|
62
|
-
(a.id === name || a.name === name) &&
|
|
63
|
-
matchesOrigin(a.origin, origin, conn));
|
|
64
|
-
if (matches.length !== 1)
|
|
65
|
-
throw new CliError(`No ${kind === "mcp" ? "MCP server" : kind} named ${name} in ${origin}.`, `barndog ${kind === "skill" ? "skills" : kind === "hook" ? "hooks" : "mcp"} search ${name}`);
|
|
66
|
-
return {
|
|
67
|
-
connection: conn,
|
|
68
|
-
reference: matches[0],
|
|
69
|
-
asset: await getAsset(kind, matches[0].id, conn, home),
|
|
70
|
-
};
|
|
71
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { cloudSource } from "./cloud-source.js";
|
|
2
|
-
import { localOverlay, withOverlay } from "../git-workspace/overlay.js";
|
|
3
|
-
import { gitRepoSource, localRepoSource, } from "../git-workspace/source.js";
|
|
4
|
-
export function openRepoSource(settings, home, options = {}) {
|
|
5
|
-
if (settings.version !== 2)
|
|
6
|
-
return undefined;
|
|
7
|
-
if (settings.gitWorkspace)
|
|
8
|
-
return gitRepoSource(settings.gitWorkspace, home, options);
|
|
9
|
-
if (settings.localWorkspace && !settings.connection)
|
|
10
|
-
return localRepoSource(settings.localWorkspace, home);
|
|
11
|
-
return undefined;
|
|
12
|
-
}
|
|
13
|
-
export function openWorkspaceSource(settings, home, options = {}) {
|
|
14
|
-
const primary = settings.version === 2 && settings.connection
|
|
15
|
-
? cloudSource(settings.connection, home)
|
|
16
|
-
: openRepoSource(settings, home, options);
|
|
17
|
-
const overlay = localOverlay(settings, home);
|
|
18
|
-
return primary && overlay ? withOverlay(primary, overlay) : primary;
|
|
19
|
-
}
|