barndog 0.1.1 → 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 +8 -7
- 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 +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/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,192 @@
|
|
|
1
|
+
import { POSIX_MODE, HOURS_PER_DAY, MILLISECONDS_PER_MINUTE, MINUTES_PER_HOUR, } from "../../shared/constants.js";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import { mkdir } from "node:fs/promises";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { CliError } from "../../errors.js";
|
|
6
|
+
import { storePackage } from "./packages.js";
|
|
7
|
+
import { loadWorkspace, NAME_RULE, } from "./format.js";
|
|
8
|
+
import { git, GitError, gitReason, gitText } from "./git.js";
|
|
9
|
+
import { folderSnapshot, gitSnapshot } from "./snapshot.js";
|
|
10
|
+
import { defined } from "../../shared/lookup.js";
|
|
11
|
+
import { z } from "zod";
|
|
12
|
+
import { readJsonIfExists, writeAtomic } from "../../shared/files.js";
|
|
13
|
+
import { barndogPaths } from "../../config/paths.js";
|
|
14
|
+
/** Display ages of at least two days in days. */
|
|
15
|
+
const AGE_IN_DAYS_THRESHOLD_HOURS = 48;
|
|
16
|
+
function repoSource(backend, runtime) {
|
|
17
|
+
let loading;
|
|
18
|
+
const model = () => (loading ??= backend.open().then((snapshot) => loadWorkspace(snapshot, backend.workspaceId, {
|
|
19
|
+
localOnly: backend.localOnly ?? false,
|
|
20
|
+
})));
|
|
21
|
+
const find = async (reference) => {
|
|
22
|
+
const asset = (await model()).assets.find((a) => a.id === reference.id);
|
|
23
|
+
if (!asset || asset.publishedVersion !== reference.publishedVersion) {
|
|
24
|
+
throw new CliError("The catalog changed while syncing.", "barndog sync");
|
|
25
|
+
}
|
|
26
|
+
if (asset.invalid) {
|
|
27
|
+
throw new CliError(`${asset.path} is invalid: ${asset.invalid}`);
|
|
28
|
+
}
|
|
29
|
+
return asset;
|
|
30
|
+
};
|
|
31
|
+
return {
|
|
32
|
+
cacheKey: backend.cacheKey,
|
|
33
|
+
journal: { workspaceId: backend.workspaceId },
|
|
34
|
+
label: backend.label,
|
|
35
|
+
model,
|
|
36
|
+
catalog: async () => (await model()).catalog,
|
|
37
|
+
invalidAssets: async () => (await model()).invalid,
|
|
38
|
+
notices: () => backend.notices(),
|
|
39
|
+
warnings: async () => {
|
|
40
|
+
const { invalidKnowledge, problems } = await model();
|
|
41
|
+
return [
|
|
42
|
+
...invalidKnowledge.map((problem) => `Knowledge file ${problem.path} was skipped: ${problem.reason}`),
|
|
43
|
+
...problems
|
|
44
|
+
.filter((problem) => problem.reason === NAME_RULE)
|
|
45
|
+
.map((problem) => `${problem.path} was skipped: ${problem.reason}. Rename it to deliver it.`),
|
|
46
|
+
];
|
|
47
|
+
},
|
|
48
|
+
packageFolder: async (kind, reference) => {
|
|
49
|
+
const asset = await find(reference);
|
|
50
|
+
return storePackage(kind, {
|
|
51
|
+
id: asset.id,
|
|
52
|
+
name: asset.name,
|
|
53
|
+
revision: asset.publishedVersion,
|
|
54
|
+
}, { key: backend.cacheKey, runtime }, () => Promise.resolve(asset.entries));
|
|
55
|
+
},
|
|
56
|
+
mcpDefinition: async (reference) => defined((await find(reference)).definition, `${reference.name} has no MCP definition`),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* The local folder workspace (`~/.barndog/workspace` by default) as a workspace
|
|
61
|
+
* source. Reads the folder directly; nothing is fetched.
|
|
62
|
+
*/
|
|
63
|
+
export function localRepoSource(workspace, runtime) {
|
|
64
|
+
return repoSource({
|
|
65
|
+
cacheKey: join("local", workspace.workspaceId),
|
|
66
|
+
workspaceId: workspace.workspaceId,
|
|
67
|
+
label: workspace.path,
|
|
68
|
+
open: () => folderSnapshot(workspace.path, runtime),
|
|
69
|
+
notices: () => [],
|
|
70
|
+
localOnly: true,
|
|
71
|
+
}, runtime);
|
|
72
|
+
}
|
|
73
|
+
/** Background refresh policy: check at most every five minutes (milliseconds). */
|
|
74
|
+
const AUTO_FETCH_INTERVAL_MS = 300000;
|
|
75
|
+
const fetchStateSchema = z.looseObject({
|
|
76
|
+
/** The branch tip this machine last read. */
|
|
77
|
+
accepted: z.string().optional(),
|
|
78
|
+
fetchedAt: z.string().optional(),
|
|
79
|
+
});
|
|
80
|
+
/**
|
|
81
|
+
* The commit this machine last accepted from the Git host and when it fetched;
|
|
82
|
+
* empty before the first fetch.
|
|
83
|
+
*/
|
|
84
|
+
export async function readFetchState(workspaceId, runtime) {
|
|
85
|
+
const { home } = runtime;
|
|
86
|
+
return ((await readJsonIfExists(barndogPaths(home).fetchState(workspaceId), fetchStateSchema)) ?? {});
|
|
87
|
+
}
|
|
88
|
+
async function writeFetchState(workspaceId, runtime, state) {
|
|
89
|
+
const { home } = runtime;
|
|
90
|
+
await writeAtomic(barndogPaths(home).fetchState(workspaceId), JSON.stringify(state));
|
|
91
|
+
}
|
|
92
|
+
/** Creates or repairs the bare clone; nothing is ever checked out of it. */
|
|
93
|
+
export async function ensureBareClone(repo, url, runtime) {
|
|
94
|
+
await mkdir(repo, { recursive: true, mode: POSIX_MODE.privateDirectory });
|
|
95
|
+
await git(["init", "--quiet", "--bare", "."], runtime, { repo });
|
|
96
|
+
await git(["config", "remote.origin.url", url], runtime, { repo });
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Fetches one branch into the bare clone's tracking ref, without tags.
|
|
100
|
+
* Credential prompts stay off unless `allowPrompt`, so a missing login fails
|
|
101
|
+
* instead of hanging.
|
|
102
|
+
*/
|
|
103
|
+
export const fetchBranch = (repo, branch, runtime, allowPrompt = false) => git([
|
|
104
|
+
"fetch",
|
|
105
|
+
"--quiet",
|
|
106
|
+
"--prune",
|
|
107
|
+
"--no-tags",
|
|
108
|
+
"origin",
|
|
109
|
+
`+refs/heads/${branch}:refs/remotes/origin/${branch}`,
|
|
110
|
+
], runtime, { repo, allowPrompt });
|
|
111
|
+
/** The ref the bare clone keeps a fetched branch in. */
|
|
112
|
+
export function trackingRef(branch) {
|
|
113
|
+
return `refs/remotes/origin/${branch}`;
|
|
114
|
+
}
|
|
115
|
+
const age = (fetchedAt) => {
|
|
116
|
+
if (!fetchedAt) {
|
|
117
|
+
return "an unknown time";
|
|
118
|
+
}
|
|
119
|
+
const minutes = Math.round((Date.now() - Date.parse(fetchedAt)) / MILLISECONDS_PER_MINUTE);
|
|
120
|
+
if (minutes < 1) {
|
|
121
|
+
return "less than a minute";
|
|
122
|
+
}
|
|
123
|
+
if (minutes < MINUTES_PER_HOUR) {
|
|
124
|
+
return `${minutes} minute${minutes === 1 ? "" : "s"}`;
|
|
125
|
+
}
|
|
126
|
+
const hours = Math.round(minutes / MINUTES_PER_HOUR);
|
|
127
|
+
return hours < AGE_IN_DAYS_THRESHOLD_HOURS
|
|
128
|
+
? `${hours} hour${hours === 1 ? "" : "s"}`
|
|
129
|
+
: `${Math.round(hours / HOURS_PER_DAY)} days`;
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* Reads a Git workspace, fetching by default. Auto refresh reuses a successful
|
|
133
|
+
* fetch for five minutes; none uses only the accepted commit. A failed branch
|
|
134
|
+
* fetch falls back to that commit when available and adds a notice.
|
|
135
|
+
*/
|
|
136
|
+
export function gitRepoSource(workspace, runtime, options = {}) {
|
|
137
|
+
const { home } = runtime;
|
|
138
|
+
const repo = barndogPaths(home).bareClone(workspace.workspaceId);
|
|
139
|
+
const notices = [];
|
|
140
|
+
async function currentCommit() {
|
|
141
|
+
const state = await readFetchState(workspace.workspaceId, runtime);
|
|
142
|
+
const policy = options.refresh ?? "always";
|
|
143
|
+
const recent = state.fetchedAt &&
|
|
144
|
+
Date.now() - Date.parse(state.fetchedAt) < AUTO_FETCH_INTERVAL_MS;
|
|
145
|
+
if (policy === "none" || (policy === "auto" && recent && state.accepted)) {
|
|
146
|
+
if (!state.accepted) {
|
|
147
|
+
throw new CliError("This Git workspace hasn't been fetched yet.", "barndog sync");
|
|
148
|
+
}
|
|
149
|
+
return state.accepted;
|
|
150
|
+
}
|
|
151
|
+
await ensureBareClone(repo, workspace.url, runtime);
|
|
152
|
+
try {
|
|
153
|
+
await fetchBranch(repo, workspace.branch, runtime);
|
|
154
|
+
}
|
|
155
|
+
catch (error) {
|
|
156
|
+
if (!(error instanceof GitError)) {
|
|
157
|
+
throw error;
|
|
158
|
+
}
|
|
159
|
+
if (!state.accepted) {
|
|
160
|
+
throw new CliError(`Can't fetch ${workspace.url}: ${gitReason(error.stderr)}. Make sure you can clone it on this machine; BarnDog manages it from there.`, `git clone ${workspace.url}`, { cause: error });
|
|
161
|
+
}
|
|
162
|
+
notices.push(`Can't reach ${workspace.url}, so this uses what was fetched ${age(state.fetchedAt)} ago.`);
|
|
163
|
+
return state.accepted;
|
|
164
|
+
}
|
|
165
|
+
const tip = await gitText(["rev-parse", "--verify", trackingRef(workspace.branch)], runtime, { repo });
|
|
166
|
+
await writeFetchState(workspace.workspaceId, runtime, {
|
|
167
|
+
accepted: tip,
|
|
168
|
+
fetchedAt: new Date().toISOString(),
|
|
169
|
+
});
|
|
170
|
+
return tip;
|
|
171
|
+
}
|
|
172
|
+
return repoSource({
|
|
173
|
+
cacheKey: join("git", createHash("sha256").update(workspace.workspaceId).digest("hex")),
|
|
174
|
+
workspaceId: workspace.workspaceId,
|
|
175
|
+
label: workspace.url,
|
|
176
|
+
open: async () => gitSnapshot(repo, await currentCommit(), runtime),
|
|
177
|
+
notices: () => notices,
|
|
178
|
+
}, runtime);
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Records an accepted workspace commit and fetch timestamp after setup or
|
|
182
|
+
* publication. Auto-refresh readers can reuse it without another fetch.
|
|
183
|
+
*/
|
|
184
|
+
export async function recordFetch(workspace, commit, runtime) {
|
|
185
|
+
await writeFetchState(workspace.workspaceId, runtime, {
|
|
186
|
+
accepted: commit,
|
|
187
|
+
fetchedAt: new Date().toISOString(),
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
export const acceptedCommit = async (workspaceId, runtime) => {
|
|
191
|
+
return (await readFetchState(workspaceId, runtime)).accepted;
|
|
192
|
+
};
|
|
@@ -1,38 +1,56 @@
|
|
|
1
|
+
import { POSIX_MODE } from "../../shared/constants.js";
|
|
1
2
|
import { randomUUID } from "node:crypto";
|
|
2
|
-
import { mkdir,
|
|
3
|
+
import { mkdir, rename, rm, writeFile } from "node:fs/promises";
|
|
3
4
|
import { dirname, join } from "node:path";
|
|
4
5
|
import { CliError } from "../../errors.js";
|
|
5
6
|
import { CONFIG_FILE, parseConfig, skeleton } from "./format.js";
|
|
6
7
|
import { git, gitInTerminal, gitText, remoteHead, } from "./git.js";
|
|
7
8
|
import { commitFiles, pushCommit } from "./publish.js";
|
|
8
|
-
import { ensureBareClone, fetchBranch,
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
import { ensureBareClone, fetchBranch, recordFetch, trackingRef, } from "./repo-source.js";
|
|
10
|
+
import { barndogPaths } from "../../config/paths.js";
|
|
11
|
+
import { readIfExists } from "../../shared/files.js";
|
|
12
|
+
/**
|
|
13
|
+
* Branch name used when creating the first commit of an empty Git workspace.
|
|
14
|
+
*/
|
|
15
|
+
const DEFAULT_BRANCH = "main";
|
|
16
|
+
/**
|
|
17
|
+
* Queries a remote repository's default head with credential prompts allowed
|
|
18
|
+
* for interactive setup.
|
|
19
|
+
*/
|
|
20
|
+
export const inspectRepository = (url, runtime) => remoteHead(url, runtime, true);
|
|
21
|
+
const stagingClone = (runtime) => {
|
|
22
|
+
const { home } = runtime;
|
|
23
|
+
return barndogPaths(home).setupClone(randomUUID());
|
|
24
|
+
};
|
|
25
|
+
async function adoptClone(staging, workspaceId, runtime) {
|
|
26
|
+
const { home } = runtime;
|
|
27
|
+
const target = barndogPaths(home).bareClone(workspaceId);
|
|
14
28
|
await rm(target, { recursive: true, force: true });
|
|
15
29
|
await rename(staging, target);
|
|
16
30
|
}
|
|
17
31
|
/** Pushes the first commit of a brand-new workspace to an empty repository. */
|
|
18
|
-
export async function createGitWorkspace(url, name,
|
|
32
|
+
export async function createGitWorkspace(url, name, runtime) {
|
|
19
33
|
const workspaceId = randomUUID();
|
|
20
|
-
const staging = stagingClone(
|
|
34
|
+
const staging = stagingClone(runtime);
|
|
21
35
|
try {
|
|
22
|
-
await ensureBareClone(staging, url);
|
|
36
|
+
await ensureBareClone(staging, url, runtime);
|
|
23
37
|
const commit = await commitFiles(staging, null, {
|
|
24
38
|
files: skeleton({ workspaceId, name }).map((file) => ({
|
|
25
39
|
...file,
|
|
26
40
|
executable: false,
|
|
27
41
|
})),
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
await
|
|
42
|
+
message: "Set up BarnDog workspace",
|
|
43
|
+
}, { allowPrompt: true, runtime });
|
|
44
|
+
await pushCommit(staging, commit, DEFAULT_BRANCH, {
|
|
45
|
+
runtime,
|
|
46
|
+
allowPrompt: true,
|
|
47
|
+
});
|
|
48
|
+
await git(["update-ref", trackingRef(DEFAULT_BRANCH), commit], runtime, {
|
|
31
49
|
repo: staging,
|
|
32
50
|
});
|
|
33
|
-
await adoptClone(staging, workspaceId,
|
|
51
|
+
await adoptClone(staging, workspaceId, runtime);
|
|
34
52
|
const workspace = { url, branch: DEFAULT_BRANCH, workspaceId };
|
|
35
|
-
await recordFetch(workspace, commit,
|
|
53
|
+
await recordFetch(workspace, commit, runtime);
|
|
36
54
|
return workspace;
|
|
37
55
|
}
|
|
38
56
|
finally {
|
|
@@ -40,17 +58,17 @@ export async function createGitWorkspace(url, name, home) {
|
|
|
40
58
|
}
|
|
41
59
|
}
|
|
42
60
|
/** Connects this machine to a repository that already holds a workspace. */
|
|
43
|
-
export async function connectGitWorkspace(url, branch,
|
|
44
|
-
const staging = stagingClone(
|
|
61
|
+
export async function connectGitWorkspace(url, branch, runtime) {
|
|
62
|
+
const staging = stagingClone(runtime);
|
|
45
63
|
try {
|
|
46
|
-
await ensureBareClone(staging, url);
|
|
47
|
-
await fetchBranch(staging, branch, true);
|
|
48
|
-
const commit = await gitText(["rev-parse", trackingRef(branch)], {
|
|
64
|
+
await ensureBareClone(staging, url, runtime);
|
|
65
|
+
await fetchBranch(staging, branch, runtime, true);
|
|
66
|
+
const commit = await gitText(["rev-parse", trackingRef(branch)], runtime, {
|
|
49
67
|
repo: staging,
|
|
50
68
|
});
|
|
51
69
|
let text;
|
|
52
70
|
try {
|
|
53
|
-
text = await gitText(["show", `${commit}:${CONFIG_FILE}`], {
|
|
71
|
+
text = await gitText(["show", `${commit}:${CONFIG_FILE}`], runtime, {
|
|
54
72
|
repo: staging,
|
|
55
73
|
});
|
|
56
74
|
}
|
|
@@ -58,9 +76,9 @@ export async function connectGitWorkspace(url, branch, home) {
|
|
|
58
76
|
throw new CliError(`${url} has commits but no ${CONFIG_FILE}, so it isn't a BarnDog workspace. Use an empty repository to start one.`, undefined, { cause: error });
|
|
59
77
|
}
|
|
60
78
|
const { workspaceId } = parseConfig(text);
|
|
61
|
-
await adoptClone(staging, workspaceId,
|
|
79
|
+
await adoptClone(staging, workspaceId, runtime);
|
|
62
80
|
const workspace = { url, branch, workspaceId };
|
|
63
|
-
await recordFetch(workspace, commit,
|
|
81
|
+
await recordFetch(workspace, commit, runtime);
|
|
64
82
|
return workspace;
|
|
65
83
|
}
|
|
66
84
|
finally {
|
|
@@ -71,12 +89,15 @@ export async function connectGitWorkspace(url, branch, home) {
|
|
|
71
89
|
* Clones through the terminal when Git couldn't read the repository quietly, so
|
|
72
90
|
* credential and host-key prompts work. Null means the repository is empty.
|
|
73
91
|
*/
|
|
74
|
-
export async function cloneGitWorkspace(url,
|
|
75
|
-
const staging = stagingClone(
|
|
76
|
-
await mkdir(dirname(staging), {
|
|
92
|
+
export async function cloneGitWorkspace(url, runtime) {
|
|
93
|
+
const staging = stagingClone(runtime);
|
|
94
|
+
await mkdir(dirname(staging), {
|
|
95
|
+
recursive: true,
|
|
96
|
+
mode: POSIX_MODE.privateDirectory,
|
|
97
|
+
});
|
|
77
98
|
try {
|
|
78
99
|
try {
|
|
79
|
-
await gitInTerminal(["clone", "--bare", "--", url, staging]);
|
|
100
|
+
await gitInTerminal(["clone", "--bare", "--", url, staging], runtime);
|
|
80
101
|
}
|
|
81
102
|
catch (error) {
|
|
82
103
|
throw new CliError(`Git couldn't clone ${url}. Check that you have access, and that this URL is right.`, `git clone ${url}`, { cause: error });
|
|
@@ -84,20 +105,22 @@ export async function cloneGitWorkspace(url, home) {
|
|
|
84
105
|
let commit;
|
|
85
106
|
let branch;
|
|
86
107
|
try {
|
|
87
|
-
commit = await gitText(["rev-parse", "--verify", "HEAD"], {
|
|
108
|
+
commit = await gitText(["rev-parse", "--verify", "HEAD"], runtime, {
|
|
88
109
|
repo: staging,
|
|
89
110
|
});
|
|
90
|
-
branch = await gitText(["symbolic-ref", "--short", "HEAD"], {
|
|
111
|
+
branch = await gitText(["symbolic-ref", "--short", "HEAD"], runtime, {
|
|
91
112
|
repo: staging,
|
|
92
113
|
});
|
|
93
114
|
}
|
|
94
115
|
catch {
|
|
95
116
|
return null;
|
|
96
117
|
}
|
|
97
|
-
await git(["update-ref", trackingRef(branch), commit], {
|
|
118
|
+
await git(["update-ref", trackingRef(branch), commit], runtime, {
|
|
119
|
+
repo: staging,
|
|
120
|
+
});
|
|
98
121
|
let text;
|
|
99
122
|
try {
|
|
100
|
-
text = await gitText(["show", `${commit}:${CONFIG_FILE}`], {
|
|
123
|
+
text = await gitText(["show", `${commit}:${CONFIG_FILE}`], runtime, {
|
|
101
124
|
repo: staging,
|
|
102
125
|
});
|
|
103
126
|
}
|
|
@@ -105,25 +128,20 @@ export async function cloneGitWorkspace(url, home) {
|
|
|
105
128
|
throw new CliError(`${url} has commits but no ${CONFIG_FILE}, so it isn't a BarnDog workspace. Use an empty repository to start one.`, undefined, { cause: error });
|
|
106
129
|
}
|
|
107
130
|
const { workspaceId } = parseConfig(text);
|
|
108
|
-
await adoptClone(staging, workspaceId,
|
|
131
|
+
await adoptClone(staging, workspaceId, runtime);
|
|
109
132
|
const workspace = { url, branch, workspaceId };
|
|
110
|
-
await recordFetch(workspace, commit,
|
|
133
|
+
await recordFetch(workspace, commit, runtime);
|
|
111
134
|
return workspace;
|
|
112
135
|
}
|
|
113
136
|
finally {
|
|
114
137
|
await rm(staging, { recursive: true, force: true });
|
|
115
138
|
}
|
|
116
139
|
}
|
|
117
|
-
export const defaultLocalPath = (home) => join(home, ".barndog", "workspace");
|
|
118
140
|
/** Opens the folder that holds this machine's assets, creating it the first time. */
|
|
119
|
-
export async function localWorkspace(
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
return { path, workspaceId };
|
|
123
|
-
}
|
|
124
|
-
catch (error) {
|
|
125
|
-
if (error.code !== "ENOENT")
|
|
126
|
-
throw error;
|
|
141
|
+
export async function localWorkspace(runtime, path = barndogPaths(runtime.home).localWorkspace) {
|
|
142
|
+
const config = await readIfExists(join(path, CONFIG_FILE));
|
|
143
|
+
if (config !== null) {
|
|
144
|
+
return { path, workspaceId: parseConfig(config).workspaceId };
|
|
127
145
|
}
|
|
128
146
|
const workspaceId = randomUUID();
|
|
129
147
|
for (const file of skeleton({ workspaceId, name: "My workspace" })) {
|
|
@@ -1,17 +1,41 @@
|
|
|
1
|
+
import { fileExecutable } from "../../platform.js";
|
|
1
2
|
import { createHash } from "node:crypto";
|
|
2
3
|
import { lstat, readFile, readdir, readlink } from "node:fs/promises";
|
|
3
4
|
import { join } from "node:path";
|
|
4
5
|
import { git } from "./git.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
import { defined } from "../../shared/lookup.js";
|
|
7
|
+
/** Git cat-file --batch terminates each object header with ASCII LF. */
|
|
8
|
+
const LF_BYTE = 0x0a;
|
|
9
|
+
/**
|
|
10
|
+
* Git index/tree modes are octal strings: regular file, executable, symbolic
|
|
11
|
+
* link, gitlink (submodule), and directory. See gitformat-index and git ls-tree.
|
|
12
|
+
* git update-index --index-info reads <mode> <hash> <path> records; keep these
|
|
13
|
+
* strings intact rather than converting them to decimal permission numbers.
|
|
14
|
+
*/
|
|
15
|
+
export const GIT_MODE = {
|
|
16
|
+
file: "100644",
|
|
17
|
+
executable: "100755",
|
|
18
|
+
symlink: "120000",
|
|
19
|
+
submodule: "160000",
|
|
20
|
+
tree: "040000",
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Recognizes regular-file Git modes, including executables; symlinks and trees
|
|
24
|
+
* are excluded.
|
|
25
|
+
*/
|
|
26
|
+
export const isBlob = (mode) => mode === GIT_MODE.file || mode === GIT_MODE.executable;
|
|
27
|
+
/**
|
|
28
|
+
* Computes the hexadecimal SHA-1 Git object ID from a blob or tree's raw bytes,
|
|
29
|
+
* including its object header.
|
|
30
|
+
*/
|
|
31
|
+
function gitObjectHash(type, content) {
|
|
8
32
|
return createHash("sha1")
|
|
9
33
|
.update(`${type} ${content.length}\0`)
|
|
10
34
|
.update(content)
|
|
11
35
|
.digest("hex");
|
|
12
36
|
}
|
|
13
37
|
function treeObject(children) {
|
|
14
|
-
const key = (child) => Buffer.from(child.mode ===
|
|
38
|
+
const key = (child) => Buffer.from(child.mode === GIT_MODE.tree ? `${child.name}/` : child.name);
|
|
15
39
|
return Buffer.concat([...children]
|
|
16
40
|
.sort((a, b) => Buffer.compare(key(a), key(b)))
|
|
17
41
|
.flatMap((child) => [
|
|
@@ -22,14 +46,15 @@ function treeObject(children) {
|
|
|
22
46
|
// Finder scatters these through any folder a developer browses.
|
|
23
47
|
const ignored = new Set([".git", ".DS_Store"]);
|
|
24
48
|
/** Reads a folder and names it exactly as Git would, without needing Git. */
|
|
25
|
-
export async function folderSnapshot(root) {
|
|
49
|
+
export async function folderSnapshot(root, runtime) {
|
|
26
50
|
const entries = [];
|
|
27
51
|
const paths = new Map();
|
|
28
52
|
async function visit(relative) {
|
|
29
53
|
const children = [];
|
|
30
54
|
for (const name of await readdir(join(root, relative))) {
|
|
31
|
-
if (ignored.has(name))
|
|
55
|
+
if (ignored.has(name)) {
|
|
32
56
|
continue;
|
|
57
|
+
}
|
|
33
58
|
const path = relative ? `${relative}/${name}` : name;
|
|
34
59
|
const absolute = join(root, path);
|
|
35
60
|
const info = await lstat(absolute);
|
|
@@ -37,19 +62,22 @@ export async function folderSnapshot(root) {
|
|
|
37
62
|
let hash;
|
|
38
63
|
if (info.isDirectory()) {
|
|
39
64
|
hash = await visit(path);
|
|
40
|
-
mode =
|
|
65
|
+
mode = GIT_MODE.tree;
|
|
41
66
|
}
|
|
42
67
|
else if (info.isSymbolicLink()) {
|
|
43
68
|
hash = gitObjectHash("blob", Buffer.from(await readlink(absolute)));
|
|
44
|
-
mode =
|
|
69
|
+
mode = GIT_MODE.symlink;
|
|
45
70
|
}
|
|
46
71
|
else if (info.isFile()) {
|
|
47
72
|
hash = gitObjectHash("blob", await readFile(absolute));
|
|
48
|
-
mode = info.mode
|
|
73
|
+
mode = (await fileExecutable(absolute, info.mode, runtime))
|
|
74
|
+
? GIT_MODE.executable
|
|
75
|
+
: GIT_MODE.file;
|
|
49
76
|
paths.set(hash, absolute);
|
|
50
77
|
}
|
|
51
|
-
else
|
|
78
|
+
else {
|
|
52
79
|
continue;
|
|
80
|
+
}
|
|
53
81
|
entries.push({ path, mode, hash });
|
|
54
82
|
children.push({ name, mode, hash });
|
|
55
83
|
}
|
|
@@ -60,15 +88,18 @@ export async function folderSnapshot(root) {
|
|
|
60
88
|
entries,
|
|
61
89
|
readBlobs: async (hashes) => {
|
|
62
90
|
const blobs = new Map();
|
|
63
|
-
for (const hash of new Set(hashes))
|
|
64
|
-
blobs.set(hash, await readFile(paths.get(hash)));
|
|
91
|
+
for (const hash of new Set(hashes)) {
|
|
92
|
+
blobs.set(hash, await readFile(defined(paths.get(hash), `Unknown blob ${hash}`)));
|
|
93
|
+
}
|
|
65
94
|
return blobs;
|
|
66
95
|
},
|
|
67
96
|
};
|
|
68
97
|
}
|
|
69
98
|
/** Reads a commit through Git plumbing, so .gitattributes cannot alter the bytes. */
|
|
70
|
-
export async function gitSnapshot(repo, commit) {
|
|
71
|
-
const listing = await git(["ls-tree", "-r", "-t", "-z", commit], {
|
|
99
|
+
export async function gitSnapshot(repo, commit, runtime) {
|
|
100
|
+
const listing = await git(["ls-tree", "-r", "-t", "-z", commit], runtime, {
|
|
101
|
+
repo,
|
|
102
|
+
});
|
|
72
103
|
const entries = listing
|
|
73
104
|
.toString("utf8")
|
|
74
105
|
.split("\0")
|
|
@@ -79,22 +110,26 @@ export async function gitSnapshot(repo, commit) {
|
|
|
79
110
|
line.slice(line.indexOf("\t") + 1),
|
|
80
111
|
];
|
|
81
112
|
const [mode, , hash] = meta.split(" ");
|
|
82
|
-
|
|
113
|
+
if (!mode || !hash) {
|
|
114
|
+
throw new Error(`Unexpected git ls-tree line: ${line}`);
|
|
115
|
+
}
|
|
116
|
+
return { path, mode, hash };
|
|
83
117
|
});
|
|
84
118
|
return {
|
|
85
119
|
entries,
|
|
86
120
|
readBlobs: async (hashes) => {
|
|
87
121
|
const unique = [...new Set(hashes)];
|
|
88
|
-
if (!unique.length)
|
|
122
|
+
if (!unique.length) {
|
|
89
123
|
return new Map();
|
|
90
|
-
|
|
124
|
+
}
|
|
125
|
+
const output = await git(["cat-file", "--batch"], runtime, {
|
|
91
126
|
repo,
|
|
92
127
|
input: unique.join("\n") + "\n",
|
|
93
128
|
});
|
|
94
129
|
const blobs = new Map();
|
|
95
130
|
let offset = 0;
|
|
96
131
|
for (const hash of unique) {
|
|
97
|
-
const end = output.indexOf(
|
|
132
|
+
const end = output.indexOf(LF_BYTE, offset);
|
|
98
133
|
const size = Number(output.toString("utf8", offset, end).split(" ")[2]);
|
|
99
134
|
blobs.set(hash, output.subarray(end + 1, end + 1 + size));
|
|
100
135
|
offset = end + 1 + size + 1;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { lstat, readdir, readFile } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { packageFingerprint, } from "@barndog-ai/api-contract/package";
|
|
4
|
+
import { CliError } from "../../errors.js";
|
|
5
|
+
import { fileExecutable } from "../../platform.js";
|
|
6
|
+
import { ifExists } from "../../shared/files.js";
|
|
7
|
+
/**
|
|
8
|
+
* Every file in an installed folder. Not `readDirectory()` from the contract
|
|
9
|
+
* package: that one reads a package to submit, so it skips `.git` and stops at
|
|
10
|
+
* package size limits. Here everything counts: a `.git` or large file added by
|
|
11
|
+
* hand must show up as a hand edit and be removed by mirroring.
|
|
12
|
+
*/
|
|
13
|
+
export async function readTree(directory, runtime) {
|
|
14
|
+
const entries = [];
|
|
15
|
+
async function visit(base) {
|
|
16
|
+
for (const child of (await readdir(join(directory, base))).sort()) {
|
|
17
|
+
const path = base ? `${base}/${child}` : child;
|
|
18
|
+
const info = await lstat(join(directory, path));
|
|
19
|
+
if (info.isDirectory()) {
|
|
20
|
+
await visit(path);
|
|
21
|
+
}
|
|
22
|
+
else if (info.isFile()) {
|
|
23
|
+
entries.push({
|
|
24
|
+
path,
|
|
25
|
+
data: await readFile(join(directory, path)),
|
|
26
|
+
executable: await fileExecutable(join(directory, path), info.mode, runtime),
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
throw new CliError(`${join(directory, path)} isn't a regular file or folder, so BarnDog can't read it.`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
await visit("");
|
|
35
|
+
return entries;
|
|
36
|
+
}
|
|
37
|
+
/** Fingerprint of an installed folder, or null when it does not exist. */
|
|
38
|
+
export async function treeFingerprint(directory, runtime) {
|
|
39
|
+
const info = await ifExists(lstat(directory));
|
|
40
|
+
if (!info) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
if (!info.isDirectory()) {
|
|
44
|
+
return `not-a-directory:${info.mode}`;
|
|
45
|
+
}
|
|
46
|
+
try {
|
|
47
|
+
return packageFingerprint(await readTree(directory, runtime));
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
return "unreadable";
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { cloudSource } from "./cloud-source.js";
|
|
2
|
+
import { localOverlay, withOverlay } from "./overlay.js";
|
|
3
|
+
import { gitRepoSource, localRepoSource, } from "./repo-source.js";
|
|
4
|
+
/**
|
|
5
|
+
* Builds a lazy Git or local-folder source from settings; returns undefined for
|
|
6
|
+
* a cloud-only setup.
|
|
7
|
+
*/
|
|
8
|
+
export function openRepoSource(settings, runtime, options = {}) {
|
|
9
|
+
if (settings.gitWorkspace) {
|
|
10
|
+
return gitRepoSource(settings.gitWorkspace, runtime, options);
|
|
11
|
+
}
|
|
12
|
+
if (settings.localWorkspace && !settings.connection) {
|
|
13
|
+
return localRepoSource(settings.localWorkspace, runtime);
|
|
14
|
+
}
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Builds the configured primary source and merges a retained local overlay when
|
|
19
|
+
* present.
|
|
20
|
+
*/
|
|
21
|
+
export function openWorkspaceSource(settings, runtime, options = {}) {
|
|
22
|
+
const primary = settings.connection
|
|
23
|
+
? cloudSource(settings.connection, runtime)
|
|
24
|
+
: openRepoSource(settings, runtime, options);
|
|
25
|
+
const overlay = localOverlay(settings, runtime);
|
|
26
|
+
return primary && overlay ? withOverlay(primary, overlay) : primary;
|
|
27
|
+
}
|
package/dist/harnesses/claude.js
CHANGED
|
@@ -1,16 +1,23 @@
|
|
|
1
|
+
import { hookSpecificContext, jsonMcpServer, nestedHookEntry, } from "./formats.js";
|
|
1
2
|
const toolMatcher = "Tool name, such as Bash or Edit|Write. Leave empty for all";
|
|
2
3
|
export const claude = {
|
|
3
4
|
id: "claude",
|
|
4
5
|
name: "Claude Code",
|
|
5
6
|
skillRoot: ".claude/skills",
|
|
6
7
|
commands: ["claude"],
|
|
7
|
-
|
|
8
|
+
desktopApp: { name: "Claude" },
|
|
8
9
|
hooks: {
|
|
9
10
|
settings: [
|
|
10
11
|
/(^|\/)\.claude\/settings(\.local)?\.json$/,
|
|
11
12
|
/(^|\/)hooks\/hooks\.json$/,
|
|
12
13
|
],
|
|
14
|
+
// Git Bash, as Claude Code's hook reference says (PowerShell only when Git Bash is missing).
|
|
15
|
+
windowsShell: "bash",
|
|
13
16
|
rootVariables: ["CLAUDE_PLUGIN_ROOT"],
|
|
17
|
+
file: ".claude/settings.json",
|
|
18
|
+
sessionStart: "SessionStart",
|
|
19
|
+
entry: nestedHookEntry,
|
|
20
|
+
sessionContext: hookSpecificContext,
|
|
14
21
|
events: [
|
|
15
22
|
{
|
|
16
23
|
name: "SessionStart",
|
|
@@ -54,4 +61,19 @@ export const claude = {
|
|
|
54
61
|
},
|
|
55
62
|
],
|
|
56
63
|
},
|
|
64
|
+
mcp: {
|
|
65
|
+
file: ".claude.json",
|
|
66
|
+
files: [".claude.json"],
|
|
67
|
+
path: ["mcpServers"],
|
|
68
|
+
server: (definition) => jsonMcpServer(definition, {
|
|
69
|
+
reference: (variable) => `\${${variable}}`,
|
|
70
|
+
typed: true,
|
|
71
|
+
}),
|
|
72
|
+
login: { command: ["claude", "mcp", "login"] },
|
|
73
|
+
},
|
|
74
|
+
configHome: {
|
|
75
|
+
variable: "CLAUDE_CONFIG_DIR",
|
|
76
|
+
directory: ".claude",
|
|
77
|
+
defaultIsSupported: false,
|
|
78
|
+
},
|
|
57
79
|
};
|