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