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
|
@@ -1,41 +1,63 @@
|
|
|
1
|
+
import { writePackage, readDirectory } from "../workspace/directory.js";
|
|
2
|
+
import { HTTP_STATUS } from "../../shared/constants.js";
|
|
1
3
|
import { randomUUID } from "node:crypto";
|
|
2
|
-
import { homedir } from "node:os";
|
|
3
4
|
import { join, resolve, dirname } from "node:path";
|
|
4
5
|
import { mkdir, readFile, realpath, rm } from "node:fs/promises";
|
|
5
6
|
import { c } from "tar";
|
|
6
|
-
import { ApiError
|
|
7
|
-
import { defaultLimits, packageFingerprint,
|
|
8
|
-
import { diffEntries, mergeEntries,
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
7
|
+
import { ApiError } from "@barndog-ai/api-contract";
|
|
8
|
+
import { defaultLimits, packageFingerprint, } from "@barndog-ai/api-contract/package";
|
|
9
|
+
import { diffEntries, mergeEntries, textContent, } from "@barndog-ai/api-contract/collaboration";
|
|
10
|
+
import { packageApi } from "./api.js";
|
|
11
|
+
import { changeAssetId } from "./results.js";
|
|
12
|
+
import { metadata as packageMetadataFor, packageKindOf, assetKinds, } from "../asset-kinds/index.js";
|
|
13
|
+
import { downloadChange, downloadVersion, getChange, selectPackage, } from "./remote.js";
|
|
14
|
+
import { selectOrigin } from "../server/origin.js";
|
|
15
|
+
import { connection } from "../server/connection.js";
|
|
16
|
+
import { encodeFiles, decodeFiles, save, locked, find, applyFiles, NoWorkingCopyError, readWorkingCopy, } from "./workspace-store.js";
|
|
12
17
|
import { externalSource, pullExternal, pushExternal, } from "./workspace-github.js";
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
+
import { defined } from "../../shared/lookup.js";
|
|
19
|
+
import { NAME } from "../../shared/patterns.js";
|
|
20
|
+
import { CliError, PackageError } from "../../errors.js";
|
|
21
|
+
import { barndogPaths } from "../../config/paths.js";
|
|
22
|
+
const publishedId = (work) => defined(work.assetId, "This working copy isn't published yet");
|
|
23
|
+
const linkedProposal = (work) => defined(work.proposal, "This working copy has no linked proposal");
|
|
24
|
+
const publishedVersion = (change) => defined(change.publishedVersion, "The merged change has no published version");
|
|
25
|
+
export { NoWorkingCopyError } from "./workspace-store.js";
|
|
26
|
+
/**
|
|
27
|
+
* `pull <name>` in Cloud: downloads the published Skill or Hook into a new
|
|
28
|
+
* working folder (`target`, default `./<name>`) and registers it under
|
|
29
|
+
* `~/.barndog/workspaces/`. Refuses a folder that already exists.
|
|
30
|
+
*/
|
|
31
|
+
export async function pullCloudPackage({ name, origin, kind }, { target, runtime }) {
|
|
32
|
+
const { cwd } = runtime;
|
|
33
|
+
return locked(runtime, async () => {
|
|
34
|
+
const conn = await connection(runtime);
|
|
35
|
+
const published = await selectPackage({ name, selector: origin, kind }, conn, runtime);
|
|
18
36
|
const path = resolve(cwd, target ?? name);
|
|
19
37
|
await mkdir(dirname(path), { recursive: true });
|
|
20
38
|
// Never overwrite an existing directory, even if it appears empty.
|
|
21
39
|
await mkdir(path);
|
|
22
40
|
const root = await realpath(path);
|
|
23
41
|
try {
|
|
24
|
-
const files = await
|
|
25
|
-
|
|
42
|
+
const files = await downloadVersion({
|
|
43
|
+
id: published.id,
|
|
44
|
+
number: published.version.number,
|
|
45
|
+
commit: published.version.commit,
|
|
46
|
+
}, conn, { runtime, kind });
|
|
47
|
+
await writePackage(root, files, runtime);
|
|
26
48
|
await save({
|
|
27
49
|
root,
|
|
28
50
|
kind,
|
|
29
51
|
connection: conn,
|
|
30
|
-
|
|
31
|
-
name:
|
|
32
|
-
origin: { type:
|
|
33
|
-
baseVersionId:
|
|
34
|
-
baseNumber:
|
|
52
|
+
assetId: published.id,
|
|
53
|
+
name: published.name,
|
|
54
|
+
origin: { type: published.origin.type, id: published.origin.id },
|
|
55
|
+
baseVersionId: published.version.id,
|
|
56
|
+
baseNumber: published.version.number,
|
|
35
57
|
base: encodeFiles(files),
|
|
36
58
|
conflicts: [],
|
|
37
|
-
},
|
|
38
|
-
return { root, version:
|
|
59
|
+
}, runtime);
|
|
60
|
+
return { root, version: published.version.number };
|
|
39
61
|
}
|
|
40
62
|
catch (error) {
|
|
41
63
|
await rm(root, { recursive: true, force: true });
|
|
@@ -43,9 +65,14 @@ export async function pullSkill(name, origin, target, cwd = process.cwd(), home
|
|
|
43
65
|
}
|
|
44
66
|
});
|
|
45
67
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
68
|
+
/**
|
|
69
|
+
* The Cloud working copy containing `cwd`, with its edits as diffs against the
|
|
70
|
+
* version it started from. Throws `NoWorkingCopyError` outside one.
|
|
71
|
+
*/
|
|
72
|
+
export async function workspaceStatus(runtime) {
|
|
73
|
+
return locked(runtime, async () => {
|
|
74
|
+
const work = await find(runtime);
|
|
75
|
+
const local = await readWorkingCopy(work, runtime);
|
|
49
76
|
return {
|
|
50
77
|
root: work.root,
|
|
51
78
|
name: work.name,
|
|
@@ -70,37 +97,52 @@ export async function workspaceStatus(cwd = process.cwd(), home = homedir()) {
|
|
|
70
97
|
};
|
|
71
98
|
});
|
|
72
99
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
100
|
+
/**
|
|
101
|
+
* `pull` in a Cloud working copy: merges edits made to its open proposal, then
|
|
102
|
+
* the newest published version, into the folder. Hands over to GitHub
|
|
103
|
+
* reconciliation when GitHub is authoritative. Refuses while a submission
|
|
104
|
+
* awaits a retry; conflicting text gets markers and is listed in `conflicts`.
|
|
105
|
+
*/
|
|
106
|
+
export async function updateWorkspace(runtime) {
|
|
107
|
+
return locked(runtime, async () => {
|
|
108
|
+
const work = await find(runtime);
|
|
76
109
|
const previous = structuredClone(work);
|
|
77
|
-
await connection(
|
|
78
|
-
if (work.pending || work.external?.pending)
|
|
79
|
-
throw new
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
110
|
+
await connection(runtime, work.connection);
|
|
111
|
+
if (work.pending || work.external?.pending) {
|
|
112
|
+
throw new CliError("Your last push is still waiting for the server to confirm it. Retry it before pulling.", "barndog push");
|
|
113
|
+
}
|
|
114
|
+
if (work.conflicts.length) {
|
|
115
|
+
throw new CliError("Resolve the existing conflicts before pulling again.", "barndog resolve <path>");
|
|
116
|
+
}
|
|
117
|
+
let entries = await readWorkingCopy(work, runtime);
|
|
83
118
|
const conflicts = new Set();
|
|
84
|
-
const source = await externalSource(work,
|
|
85
|
-
if (source)
|
|
86
|
-
return pullExternal(work, source, entries, previous,
|
|
119
|
+
const source = await externalSource(work, runtime);
|
|
120
|
+
if (source) {
|
|
121
|
+
return pullExternal(work, { source, entries, previous }, runtime);
|
|
122
|
+
}
|
|
87
123
|
if (work.proposal) {
|
|
88
|
-
const proposal = await getChange(work.proposal.id, work.connection,
|
|
124
|
+
const proposal = await getChange(work.proposal.id, work.connection, runtime, work.kind);
|
|
89
125
|
if (proposal.revision !== work.proposal.revision) {
|
|
90
|
-
const remote = await
|
|
126
|
+
const remote = await downloadChange(proposal, work.connection, {
|
|
127
|
+
runtime,
|
|
128
|
+
kind: work.kind,
|
|
129
|
+
});
|
|
91
130
|
const merged = await mergeEntries(decodeFiles(work.proposal.files), entries, remote);
|
|
92
131
|
entries = merged.entries;
|
|
93
132
|
merged.conflicts.forEach((p) => conflicts.add(p));
|
|
94
133
|
// The author's remote proposal may already have been rebased by another client.
|
|
95
134
|
if (proposal.baseVersionId !== work.baseVersionId) {
|
|
96
135
|
if (proposal.baseVersionId) {
|
|
97
|
-
const versions =
|
|
98
|
-
params: { path: { id: work.skillId } },
|
|
99
|
-
})).data;
|
|
136
|
+
const versions = await packageApi(work.kind, work.connection, runtime).versions(publishedId(work));
|
|
100
137
|
const version = versions.find((v) => v.id === proposal.baseVersionId);
|
|
101
|
-
if (!version)
|
|
102
|
-
throw new Error("
|
|
103
|
-
|
|
138
|
+
if (!version) {
|
|
139
|
+
throw new Error("The server didn't return the version this Suggested Change is based on");
|
|
140
|
+
}
|
|
141
|
+
work.base = encodeFiles(await downloadVersion({
|
|
142
|
+
id: publishedId(work),
|
|
143
|
+
number: version.number,
|
|
144
|
+
commit: version.commit,
|
|
145
|
+
}, work.connection, { runtime, kind: work.kind }));
|
|
104
146
|
work.baseNumber = version.number;
|
|
105
147
|
}
|
|
106
148
|
else {
|
|
@@ -117,21 +159,23 @@ export async function updateWorkspace(cwd = process.cwd(), home = homedir()) {
|
|
|
117
159
|
}
|
|
118
160
|
}
|
|
119
161
|
if (work.baseVersionId) {
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
162
|
+
const published = await packageApi(work.kind, work.connection, runtime).published(publishedId(work));
|
|
163
|
+
if (published.version.id !== work.baseVersionId) {
|
|
164
|
+
const latest = await downloadVersion({
|
|
165
|
+
id: published.id,
|
|
166
|
+
number: published.version.number,
|
|
167
|
+
commit: published.version.commit,
|
|
168
|
+
}, work.connection, { runtime, kind: work.kind });
|
|
125
169
|
const merged = await mergeEntries(decodeFiles(work.base), entries, latest);
|
|
126
170
|
entries = merged.entries;
|
|
127
171
|
merged.conflicts.forEach((p) => conflicts.add(p));
|
|
128
172
|
work.base = encodeFiles(latest);
|
|
129
|
-
work.baseVersionId =
|
|
130
|
-
work.baseNumber =
|
|
173
|
+
work.baseVersionId = published.version.id;
|
|
174
|
+
work.baseNumber = published.version.number;
|
|
131
175
|
}
|
|
132
176
|
}
|
|
133
177
|
else if (work.proposal) {
|
|
134
|
-
const proposal = await getChange(work.proposal.id, work.connection,
|
|
178
|
+
const proposal = await getChange(work.proposal.id, work.connection, runtime, work.kind);
|
|
135
179
|
if (proposal.publishedVersion) {
|
|
136
180
|
work.baseVersionId = proposal.publishedVersion.id;
|
|
137
181
|
work.baseNumber = proposal.publishedVersion.number;
|
|
@@ -139,7 +183,7 @@ export async function updateWorkspace(cwd = process.cwd(), home = homedir()) {
|
|
|
139
183
|
}
|
|
140
184
|
}
|
|
141
185
|
work.conflicts = [...conflicts];
|
|
142
|
-
await applyFiles(work, entries,
|
|
186
|
+
await applyFiles(work, entries, runtime, previous);
|
|
143
187
|
return {
|
|
144
188
|
root: work.root,
|
|
145
189
|
conflicts: work.conflicts,
|
|
@@ -147,38 +191,67 @@ export async function updateWorkspace(cwd = process.cwd(), home = homedir()) {
|
|
|
147
191
|
};
|
|
148
192
|
});
|
|
149
193
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
194
|
+
/**
|
|
195
|
+
* Marks one conflicted file in a Cloud working copy resolved, after checking
|
|
196
|
+
* its conflict markers are gone.
|
|
197
|
+
*/
|
|
198
|
+
export async function resolveConflict(path, runtime) {
|
|
199
|
+
return locked(runtime, async () => {
|
|
200
|
+
const work = await find(runtime);
|
|
201
|
+
return markResolved(work, path, runtime);
|
|
154
202
|
});
|
|
155
203
|
}
|
|
204
|
+
/**
|
|
205
|
+
* A line a three-way merge writes around conflicting text: `<<<<<<< local`,
|
|
206
|
+
* `||||||| base`, `=======` or `>>>>>>> remote` (seven characters, then a space
|
|
207
|
+
* and a label or the end of the line).
|
|
208
|
+
*/
|
|
209
|
+
const CONFLICT_MARKER = /^(?:<{7}|\|{7}|={7}|>{7})(?: |$)/m;
|
|
210
|
+
/**
|
|
211
|
+
* Whether text still holds a line the three-way merge wrote around a conflict.
|
|
212
|
+
*
|
|
213
|
+
* @internal Exported for its table test in `src/tests/patterns.test.ts`.
|
|
214
|
+
*/
|
|
215
|
+
export const hasConflictMarkers = (text) => CONFLICT_MARKER.test(text);
|
|
156
216
|
/** Clears one conflict once its markers are gone; shared by cloud and Git working copies. */
|
|
157
|
-
export async function markResolved(work, path,
|
|
217
|
+
export async function markResolved(work, path, runtime) {
|
|
218
|
+
const { cwd } = runtime;
|
|
158
219
|
const absolute = resolve(await realpath(cwd), path);
|
|
159
220
|
const conflict = work.conflicts.find((p) => join(work.root, p) === absolute);
|
|
160
|
-
if (!conflict)
|
|
161
|
-
throw new
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
221
|
+
if (!conflict) {
|
|
222
|
+
throw new CliError(`${path} isn't an unresolved conflict.`, "barndog status");
|
|
223
|
+
}
|
|
224
|
+
const files = await readDirectory(work.root, runtime);
|
|
225
|
+
const file = files.find((e) => e.path === conflict);
|
|
226
|
+
if (file && hasConflictMarkers(textContent(file.data) ?? "")) {
|
|
227
|
+
throw new CliError(`${conflict} still has conflict markers. Edit them out, then resolve it again.`, `barndog resolve ${path}`);
|
|
228
|
+
}
|
|
166
229
|
const paths = new Set(files.map((e) => e.path));
|
|
167
|
-
for (const p of paths)
|
|
168
|
-
if ([...paths].some((other) => p.startsWith(other + "/")))
|
|
169
|
-
throw new
|
|
230
|
+
for (const p of paths) {
|
|
231
|
+
if ([...paths].some((other) => p.startsWith(other + "/"))) {
|
|
232
|
+
throw new CliError(`A file and a folder share the path ${p}. Keep one, then resolve again.`, `barndog resolve ${path}`);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
170
235
|
work.conflicts = work.conflicts.filter((p) => p !== conflict);
|
|
171
|
-
await save(work,
|
|
236
|
+
await save(work, runtime);
|
|
172
237
|
return { resolved: conflict, remaining: work.conflicts };
|
|
173
238
|
}
|
|
174
|
-
|
|
175
|
-
|
|
239
|
+
/**
|
|
240
|
+
* Packs base64-encoded files into the gzipped tarball the server's upload
|
|
241
|
+
* routes take. Fails with `PACKAGE_TOO_LARGE` above the compressed size limit;
|
|
242
|
+
* uses a temporary folder under `~/.barndog/workspaces/`.
|
|
243
|
+
*/
|
|
244
|
+
export async function archive(files, runtime) {
|
|
245
|
+
const { home } = runtime;
|
|
246
|
+
const temp = join(barndogPaths(home).workingCopies, `upload-${randomUUID()}`);
|
|
247
|
+
const tar = temp + ".tar.gz";
|
|
176
248
|
try {
|
|
177
|
-
await writePackage(temp, decodeFiles(files));
|
|
249
|
+
await writePackage(temp, decodeFiles(files), runtime);
|
|
178
250
|
await c({ cwd: temp, file: tar, gzip: true, portable: true, noMtime: true }, files.map((e) => e.path));
|
|
179
251
|
const bytes = await readFile(tar);
|
|
180
|
-
if (bytes.length > defaultLimits.compressed)
|
|
181
|
-
throw new
|
|
252
|
+
if (bytes.length > defaultLimits.compressed) {
|
|
253
|
+
throw new PackageError("PACKAGE_TOO_LARGE");
|
|
254
|
+
}
|
|
182
255
|
return new Blob([bytes]);
|
|
183
256
|
}
|
|
184
257
|
finally {
|
|
@@ -186,20 +259,35 @@ export async function archive(files, home) {
|
|
|
186
259
|
await rm(tar, { force: true });
|
|
187
260
|
}
|
|
188
261
|
}
|
|
189
|
-
|
|
190
|
-
|
|
262
|
+
/**
|
|
263
|
+
* `push` in Cloud: creates or revises the working copy's proposal and, with
|
|
264
|
+
* `publish`, merges it at once (scope or organization admins and personal
|
|
265
|
+
* owners only). Inside
|
|
266
|
+
* a folder that isn't a working copy yet, `origin` registers it first. The
|
|
267
|
+
* upload, retry key and payload are saved before sending, so an ambiguous
|
|
268
|
+
* failure can be retried exactly. GitHub-authoritative assets go to a pull
|
|
269
|
+
* request instead.
|
|
270
|
+
*/
|
|
271
|
+
export async function pushWorkspace(options = {}, runtime) {
|
|
272
|
+
const { cwd } = runtime;
|
|
273
|
+
return locked(runtime, async () => {
|
|
191
274
|
let work;
|
|
192
275
|
try {
|
|
193
|
-
work = await find(
|
|
276
|
+
work = await find(runtime);
|
|
194
277
|
}
|
|
195
278
|
catch (error) {
|
|
196
|
-
if (!options.origin || !(error instanceof NoWorkingCopyError))
|
|
279
|
+
if (!options.origin || !(error instanceof NoWorkingCopyError)) {
|
|
197
280
|
throw error;
|
|
198
|
-
|
|
199
|
-
const
|
|
281
|
+
}
|
|
282
|
+
const conn = await connection(runtime);
|
|
283
|
+
const root = await realpath(cwd);
|
|
284
|
+
const files = await readDirectory(root, runtime);
|
|
285
|
+
const kind = packageKindOf(files, options.kind);
|
|
286
|
+
const description = packageMetadataFor(files, kind);
|
|
287
|
+
const origin = await selectOrigin(options.origin, conn, runtime);
|
|
200
288
|
work = {
|
|
201
289
|
root,
|
|
202
|
-
kind
|
|
290
|
+
kind,
|
|
203
291
|
connection: conn,
|
|
204
292
|
name: description.name,
|
|
205
293
|
origin: { type: origin.type, id: origin.id },
|
|
@@ -208,168 +296,165 @@ export async function pushWorkspace(options = {}, cwd = process.cwd(), home = ho
|
|
|
208
296
|
base: [],
|
|
209
297
|
conflicts: [],
|
|
210
298
|
};
|
|
211
|
-
await save(work,
|
|
299
|
+
await save(work, runtime);
|
|
300
|
+
}
|
|
301
|
+
if (options.kind && work.kind !== options.kind) {
|
|
302
|
+
throw new CliError(`This working copy holds a ${work.kind}, not a ${options.kind}.`, "barndog status");
|
|
303
|
+
}
|
|
304
|
+
if (options.name && work.name !== options.name) {
|
|
305
|
+
throw new CliError(`This working copy is ${work.name}, not ${options.name}.`, "barndog status");
|
|
212
306
|
}
|
|
213
|
-
|
|
214
|
-
throw new Error("Working copy belongs to a different asset kind");
|
|
215
|
-
if (options.name && work.name !== options.name)
|
|
216
|
-
throw new Error("Working-copy name does not match the requested asset");
|
|
217
|
-
await connection(home, work.connection);
|
|
307
|
+
await connection(runtime, work.connection);
|
|
218
308
|
if (options.origin) {
|
|
219
|
-
const selected = await selectOrigin(options.origin, work.connection,
|
|
309
|
+
const selected = await selectOrigin(options.origin, work.connection, runtime);
|
|
220
310
|
if (selected.type !== work.origin.type ||
|
|
221
311
|
selected.id !== work.origin.id) {
|
|
222
|
-
if (work.
|
|
223
|
-
throw new
|
|
312
|
+
if (work.assetId || work.proposal || work.pending) {
|
|
313
|
+
throw new CliError("This working copy was already submitted, so its origin can't change. Push without --origin.", "barndog push");
|
|
314
|
+
}
|
|
224
315
|
work.origin = { type: selected.type, id: selected.id };
|
|
225
|
-
await save(work,
|
|
316
|
+
await save(work, runtime);
|
|
226
317
|
}
|
|
227
318
|
}
|
|
228
|
-
if (work.conflicts.length)
|
|
229
|
-
throw new
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
319
|
+
if (work.conflicts.length) {
|
|
320
|
+
throw new CliError("Resolve the conflicts before pushing.", "barndog resolve <path>");
|
|
321
|
+
}
|
|
322
|
+
const source = await externalSource(work, runtime);
|
|
323
|
+
if (source) {
|
|
324
|
+
return pushExternal(work, source, options, runtime);
|
|
325
|
+
}
|
|
326
|
+
const api = packageApi(work.kind, work.connection, runtime);
|
|
234
327
|
if (options.publish) {
|
|
235
|
-
const scope = await selectOrigin(`${work.origin.type}:${work.origin.id}`, work.connection,
|
|
236
|
-
if (!scope.canPublish)
|
|
237
|
-
throw new
|
|
328
|
+
const scope = await selectOrigin(`${work.origin.type}:${work.origin.id}`, work.connection, runtime);
|
|
329
|
+
if (!scope.canPublish) {
|
|
330
|
+
throw new CliError(`Only a scope admin, an organization admin or the personal owner can publish directly. Propose it for review instead, then merge it with barndog ${assetKinds[work.kind].command} changes merge.`, "barndog push");
|
|
331
|
+
}
|
|
238
332
|
}
|
|
239
333
|
let proposal = work.proposal
|
|
240
|
-
? await getChange(work.proposal.id, work.connection,
|
|
334
|
+
? await getChange(work.proposal.id, work.connection, runtime, work.kind)
|
|
241
335
|
: undefined;
|
|
242
336
|
if (!work.pending &&
|
|
243
337
|
options.publish &&
|
|
244
338
|
proposal?.status === "merged" &&
|
|
245
339
|
proposal.publishedVersion &&
|
|
246
|
-
packageFingerprint(await
|
|
247
|
-
packageFingerprint(decodeFiles(work.
|
|
340
|
+
packageFingerprint(await readWorkingCopy(work, runtime)) ===
|
|
341
|
+
packageFingerprint(decodeFiles(linkedProposal(work).files))) {
|
|
248
342
|
work.baseVersionId = proposal.publishedVersion.id;
|
|
249
343
|
work.baseNumber = proposal.publishedVersion.number;
|
|
250
|
-
work.base = work.
|
|
251
|
-
await save(work,
|
|
344
|
+
work.base = linkedProposal(work).files;
|
|
345
|
+
await save(work, runtime);
|
|
252
346
|
return proposal;
|
|
253
347
|
}
|
|
254
348
|
if (!work.pending) {
|
|
255
|
-
if (proposal?.status === "rejected" && !options.new)
|
|
256
|
-
throw new
|
|
349
|
+
if (proposal?.status === "rejected" && !options.new) {
|
|
350
|
+
throw new CliError("This Suggested Change was rejected.", "barndog push --new");
|
|
351
|
+
}
|
|
257
352
|
if (proposal?.status === "merged" &&
|
|
258
|
-
proposal.publishedVersion?.id !== work.baseVersionId)
|
|
259
|
-
throw new
|
|
353
|
+
proposal.publishedVersion?.id !== work.baseVersionId) {
|
|
354
|
+
throw new CliError("Your last Suggested Change was merged. Pull it before starting another.", "barndog pull");
|
|
355
|
+
}
|
|
260
356
|
if (proposal?.status === "open" &&
|
|
261
|
-
proposal.revision !== work.
|
|
262
|
-
throw new
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
357
|
+
proposal.revision !== linkedProposal(work).revision) {
|
|
358
|
+
throw new CliError("The Suggested Change changed on the server since your last pull.", "barndog pull");
|
|
359
|
+
}
|
|
360
|
+
const files = await readWorkingCopy(work, runtime);
|
|
361
|
+
if (packageMetadataFor(files, work.kind).name !== work.name) {
|
|
362
|
+
throw new CliError(`This working copy's name must stay ${work.name}. Change it back, then push again.`);
|
|
363
|
+
}
|
|
266
364
|
const previous = proposal?.status === "open" && !options.new
|
|
267
|
-
? work.
|
|
365
|
+
? linkedProposal(work).files
|
|
268
366
|
: work.base;
|
|
269
367
|
if (packageFingerprint(files) ===
|
|
270
368
|
packageFingerprint(decodeFiles(previous)) &&
|
|
271
369
|
(!proposal || proposal.baseVersionId === work.baseVersionId) &&
|
|
272
370
|
(!options.title || options.title === proposal?.title)) {
|
|
273
371
|
if (options.publish && proposal?.status === "open") {
|
|
274
|
-
const merged =
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
work.
|
|
279
|
-
work.
|
|
280
|
-
work
|
|
281
|
-
await save(work, home);
|
|
372
|
+
const merged = await api.merge(proposal.id, {
|
|
373
|
+
expectedRevision: proposal.revision,
|
|
374
|
+
});
|
|
375
|
+
work.baseVersionId = publishedVersion(merged).id;
|
|
376
|
+
work.baseNumber = publishedVersion(merged).number;
|
|
377
|
+
work.base = linkedProposal(work).files;
|
|
378
|
+
await save(work, runtime);
|
|
282
379
|
return merged;
|
|
283
380
|
}
|
|
284
381
|
return { unchanged: true, proposalId: proposal?.id };
|
|
285
382
|
}
|
|
286
383
|
const changeId = proposal?.status === "open" && !options.new ? proposal.id : undefined;
|
|
287
384
|
const metadata = {
|
|
288
|
-
|
|
385
|
+
assetId: work.assetId,
|
|
289
386
|
name: work.name,
|
|
290
387
|
origin: work.origin,
|
|
291
388
|
baseVersionId: work.baseVersionId,
|
|
292
|
-
expectedRevision: changeId ? work.
|
|
389
|
+
expectedRevision: changeId ? linkedProposal(work).revision : undefined,
|
|
293
390
|
title: options.title ?? proposal?.title ?? `Update ${work.name}`,
|
|
294
391
|
idempotencyKey: randomUUID(),
|
|
295
392
|
};
|
|
296
393
|
work.pending = { metadata, files: encodeFiles(files), changeId };
|
|
297
|
-
await save(work,
|
|
394
|
+
await save(work, runtime);
|
|
298
395
|
}
|
|
299
396
|
const pending = work.pending;
|
|
300
|
-
const
|
|
301
|
-
form.set("metadata", JSON.stringify(pending.metadata));
|
|
302
|
-
form.set("package", await archive(pending.files, home), "skill.tar.gz");
|
|
397
|
+
const upload = await archive(pending.files, runtime);
|
|
303
398
|
try {
|
|
304
|
-
proposal =
|
|
305
|
-
?
|
|
306
|
-
|
|
307
|
-
body: form,
|
|
308
|
-
})).data
|
|
309
|
-
: (await client.POST("/v1/skill-changes", { body: form })).data);
|
|
399
|
+
proposal = pending.changeId
|
|
400
|
+
? await api.revise(pending.changeId, pending.metadata, upload)
|
|
401
|
+
: await api.submit(pending.metadata, upload);
|
|
310
402
|
}
|
|
311
403
|
catch (error) {
|
|
312
404
|
// A definitive rejection did not accept this submission. Keep local edits and
|
|
313
405
|
// permit pull/reconciliation; ambiguous transport failures retain the exact key.
|
|
314
406
|
if (error instanceof ApiError &&
|
|
315
|
-
[
|
|
407
|
+
[
|
|
408
|
+
HTTP_STATUS.badRequest,
|
|
409
|
+
HTTP_STATUS.forbidden,
|
|
410
|
+
HTTP_STATUS.notFound,
|
|
411
|
+
HTTP_STATUS.conflict,
|
|
412
|
+
HTTP_STATUS.payloadTooLarge,
|
|
413
|
+
].includes(error.status)) {
|
|
316
414
|
delete work.pending;
|
|
317
|
-
await save(work,
|
|
415
|
+
await save(work, runtime);
|
|
318
416
|
}
|
|
319
417
|
throw error;
|
|
320
418
|
}
|
|
321
|
-
work.
|
|
419
|
+
work.assetId = changeAssetId(proposal);
|
|
322
420
|
work.proposal = {
|
|
323
421
|
id: proposal.id,
|
|
324
422
|
revision: proposal.submittedRevision,
|
|
325
423
|
files: pending.files,
|
|
326
424
|
};
|
|
327
425
|
delete work.pending;
|
|
328
|
-
await save(work,
|
|
426
|
+
await save(work, runtime);
|
|
329
427
|
if (options.publish) {
|
|
330
|
-
proposal =
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
work.
|
|
335
|
-
work.baseNumber = proposal.publishedVersion.number;
|
|
428
|
+
proposal = await api.merge(proposal.id, {
|
|
429
|
+
expectedRevision: work.proposal.revision,
|
|
430
|
+
});
|
|
431
|
+
work.baseVersionId = publishedVersion(proposal).id;
|
|
432
|
+
work.baseNumber = publishedVersion(proposal).number;
|
|
336
433
|
work.base = work.proposal.files;
|
|
337
|
-
await save(work,
|
|
434
|
+
await save(work, runtime);
|
|
338
435
|
}
|
|
339
436
|
return proposal;
|
|
340
437
|
});
|
|
341
438
|
}
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
439
|
+
/**
|
|
440
|
+
* Starts a Cloud working copy from the kind's scaffold. Contacts the server to
|
|
441
|
+
* validate the connection and origin; asset content is uploaded only on `push`.
|
|
442
|
+
*/
|
|
443
|
+
export async function createWorkspace({ name, origin, kind }, { target, runtime }) {
|
|
444
|
+
const { cwd } = runtime;
|
|
445
|
+
return locked(runtime, async () => {
|
|
446
|
+
if (!NAME.test(name)) {
|
|
447
|
+
throw new CliError(`${name} isn't a valid name. Use lowercase letters, digits and hyphens, such as my-skill.`);
|
|
448
|
+
}
|
|
449
|
+
const conn = await connection(runtime);
|
|
450
|
+
const scope = await selectOrigin(origin, conn, runtime);
|
|
347
451
|
const path = resolve(cwd, target ?? name);
|
|
348
452
|
await mkdir(dirname(path), { recursive: true });
|
|
349
453
|
await mkdir(path);
|
|
350
454
|
const root = await realpath(path);
|
|
351
|
-
const entries = kind
|
|
352
|
-
? [
|
|
353
|
-
{
|
|
354
|
-
path: "SKILL.md",
|
|
355
|
-
data: Buffer.from(`---\nname: ${name}\ndescription: Describe this Skill\n---\n\nAdd instructions here.\n`),
|
|
356
|
-
executable: false,
|
|
357
|
-
},
|
|
358
|
-
]
|
|
359
|
-
: [
|
|
360
|
-
{
|
|
361
|
-
path: "hook.yaml",
|
|
362
|
-
data: Buffer.from(`name: ${name}\ndescription: Describe this Hook\nimplementations:\n claude:\n compatibility: supported\n scripts: [scripts/hook.sh]\n requirements:\n commands: [sh]\n events:\n SessionStart:\n - hooks:\n - type: command\n command: '\${BARNDOG_HOOK_ROOT}/scripts/hook.sh'\n`),
|
|
363
|
-
executable: false,
|
|
364
|
-
},
|
|
365
|
-
{
|
|
366
|
-
path: "scripts/hook.sh",
|
|
367
|
-
data: Buffer.from("#!/bin/sh\n# Read native input; implement the desired behavior here.\ncat >/dev/null\n"),
|
|
368
|
-
executable: true,
|
|
369
|
-
},
|
|
370
|
-
];
|
|
455
|
+
const entries = assetKinds[kind].scaffold(name);
|
|
371
456
|
try {
|
|
372
|
-
await writePackage(root, entries);
|
|
457
|
+
await writePackage(root, entries, runtime);
|
|
373
458
|
await save({
|
|
374
459
|
root,
|
|
375
460
|
kind,
|
|
@@ -380,7 +465,7 @@ export async function createWorkspace(name, origin, target, cwd = process.cwd(),
|
|
|
380
465
|
baseNumber: null,
|
|
381
466
|
base: [],
|
|
382
467
|
conflicts: [],
|
|
383
|
-
},
|
|
468
|
+
}, runtime);
|
|
384
469
|
return { root, kind, name };
|
|
385
470
|
}
|
|
386
471
|
catch (error) {
|