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
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import { CliError } from "../../errors.js";
|
|
2
|
+
import { fileText } from "../../shared/files.js";
|
|
3
|
+
import { fixSteps, removeCommand } from "../../platform.js";
|
|
4
|
+
import { treeFingerprint } from "../workspace/tree.js";
|
|
5
|
+
import { assetKinds } from "../asset-kinds/index.js";
|
|
6
|
+
import { patchNative } from "../native/configuration.js";
|
|
7
|
+
import { recordedVariables, redacted, sameValue, } from "../native/secret-values.js";
|
|
8
|
+
import { inPluginModule, pluginModule } from "../native/plugin-module.js";
|
|
9
|
+
import { linkTarget } from "./transaction.js";
|
|
10
|
+
function changeType(change) {
|
|
11
|
+
if (!change.sameAsset) {
|
|
12
|
+
return "installed";
|
|
13
|
+
}
|
|
14
|
+
if (change.current && !change.contentChanged) {
|
|
15
|
+
return "unchanged";
|
|
16
|
+
}
|
|
17
|
+
return "updated";
|
|
18
|
+
}
|
|
19
|
+
/** Stops a sync that would overwrite an installed folder someone edited by hand. */
|
|
20
|
+
export async function assertInstalledUntouched(installed, settings, runtime) {
|
|
21
|
+
for (const entry of installed) {
|
|
22
|
+
const actual = await treeFingerprint(entry.path, runtime);
|
|
23
|
+
if (actual !== null && actual !== entry.fingerprint) {
|
|
24
|
+
throw new CliError(`The installed copy at ${entry.path} was edited by hand. Syncing would overwrite those edits. ${settings.localWorkspace &&
|
|
25
|
+
!settings.connection &&
|
|
26
|
+
!settings.gitWorkspace
|
|
27
|
+
? "To keep them, copy that folder somewhere else first."
|
|
28
|
+
: `To keep them, make an editable copy with barndog ${assetKinds[entry.kind].command} pull first.`}`, "Delete the installed copy; the next sync installs it again.", {
|
|
29
|
+
command: fixSteps([removeCommand(entry.path, runtime.platform), "barndog sync"], runtime.platform),
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* One write per installed folder, old or new, and the paths of the folders
|
|
36
|
+
* whose content changes (`updated`), which is what makes a link or Hook
|
|
37
|
+
* registration count as updated.
|
|
38
|
+
*/
|
|
39
|
+
export async function treeWrites(installed, trees, runtime) {
|
|
40
|
+
const writes = [];
|
|
41
|
+
const updated = new Set();
|
|
42
|
+
for (const treePath of new Set([
|
|
43
|
+
...installed.map((entry) => entry.path),
|
|
44
|
+
...trees.map((tree) => tree.path),
|
|
45
|
+
])) {
|
|
46
|
+
const next = trees.find((tree) => tree.path === treePath);
|
|
47
|
+
const before = await treeFingerprint(treePath, runtime);
|
|
48
|
+
const after = next?.fingerprint ?? null;
|
|
49
|
+
if (before !== null && after !== null && before !== after) {
|
|
50
|
+
updated.add(treePath);
|
|
51
|
+
}
|
|
52
|
+
writes.push({
|
|
53
|
+
kind: "tree",
|
|
54
|
+
path: treePath,
|
|
55
|
+
before,
|
|
56
|
+
after,
|
|
57
|
+
source: next?.source ?? null,
|
|
58
|
+
rename: next?.rename ?? null,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
return { writes, updated };
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* One write per Skill link, old or new. Refuses a link changed outside BarnDog
|
|
65
|
+
* and a destination holding a Skill BarnDog didn't install.
|
|
66
|
+
*/
|
|
67
|
+
export async function linkWrites(previous, desired, updated) {
|
|
68
|
+
for (const link of previous) {
|
|
69
|
+
const actual = await linkTarget(link.target);
|
|
70
|
+
if (actual !== null && actual !== link.source) {
|
|
71
|
+
throw new CliError(`${link.target} was changed outside BarnDog. Restore or remove it, then sync again.`, "barndog sync");
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
for (const link of desired) {
|
|
75
|
+
const actual = await linkTarget(link.target);
|
|
76
|
+
const old = previous.find((l) => l.target === link.target);
|
|
77
|
+
if (actual !== null && !old) {
|
|
78
|
+
throw new CliError(`${link.target} is a Skill BarnDog didn't install, so it won't replace it. Move or rename it, then sync again.`, "barndog sync");
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
const writes = [];
|
|
82
|
+
const events = [];
|
|
83
|
+
for (const target of new Set([
|
|
84
|
+
...previous.map((l) => l.target),
|
|
85
|
+
...desired.map((l) => l.target),
|
|
86
|
+
])) {
|
|
87
|
+
const old = previous.find((l) => l.target === target);
|
|
88
|
+
const next = desired.find((l) => l.target === target);
|
|
89
|
+
const actual = await linkTarget(target);
|
|
90
|
+
if (old && (!next || next.id !== old.id)) {
|
|
91
|
+
events.push({ type: "removed", link: old });
|
|
92
|
+
}
|
|
93
|
+
if (next) {
|
|
94
|
+
events.push({
|
|
95
|
+
type: changeType({
|
|
96
|
+
sameAsset: old?.id === next.id,
|
|
97
|
+
current: actual === next.source,
|
|
98
|
+
contentChanged: updated.has(next.source),
|
|
99
|
+
}),
|
|
100
|
+
link: next,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
writes.push({
|
|
104
|
+
kind: "link",
|
|
105
|
+
path: target,
|
|
106
|
+
before: actual,
|
|
107
|
+
after: next?.source ?? null,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
return { writes, events };
|
|
111
|
+
}
|
|
112
|
+
/** The same entry, comparing kept values with the hashes `state.json` records. */
|
|
113
|
+
const sameEntry = (left, right) => left.id === right.id &&
|
|
114
|
+
left.kind === right.kind &&
|
|
115
|
+
left.harness === right.harness &&
|
|
116
|
+
left.file === right.file &&
|
|
117
|
+
left.key === right.key &&
|
|
118
|
+
sameValue(left.value, right.value);
|
|
119
|
+
/** A notice for kept values a changed entry no longer holds. */
|
|
120
|
+
function removedSecrets(entry, still) {
|
|
121
|
+
const gone = recordedVariables(entry.value).filter((variable) => !still.includes(variable));
|
|
122
|
+
return gone.length
|
|
123
|
+
? [
|
|
124
|
+
{
|
|
125
|
+
type: "notice",
|
|
126
|
+
message: `Removed the kept ${plural(gone)} ${gone.join(", ")} from ${entry.file}.`,
|
|
127
|
+
},
|
|
128
|
+
]
|
|
129
|
+
: [];
|
|
130
|
+
}
|
|
131
|
+
/** Says where kept values were written, and where they were taken out. */
|
|
132
|
+
function secretNotices(entry, old, changed, nameOf) {
|
|
133
|
+
if (!changed) {
|
|
134
|
+
return [];
|
|
135
|
+
}
|
|
136
|
+
const written = (entry.secrets ?? []).map((secret) => secret.variable);
|
|
137
|
+
const before = old.find((e) => e.id === entry.id && e.harness === entry.harness);
|
|
138
|
+
return [
|
|
139
|
+
...(written.length
|
|
140
|
+
? [
|
|
141
|
+
{
|
|
142
|
+
type: "notice",
|
|
143
|
+
message: `Wrote the kept ${plural(written)} ${written.join(", ")} into ${entry.file} for ${nameOf(entry)}. ${written.length === 1 ? "It stays" : "They stay"} on this machine.`,
|
|
144
|
+
},
|
|
145
|
+
]
|
|
146
|
+
: []),
|
|
147
|
+
...(before ? removedSecrets(before, written) : []),
|
|
148
|
+
];
|
|
149
|
+
}
|
|
150
|
+
const plural = (variables) => variables.length === 1 ? "value of" : "values of";
|
|
151
|
+
/**
|
|
152
|
+
* One write per native settings file that holds, or will hold, an entry of
|
|
153
|
+
* BarnDog's. `nameOf` gives the name an entry is reported under.
|
|
154
|
+
*/
|
|
155
|
+
export async function nativeWrites(previous, desired, context) {
|
|
156
|
+
const { trees, updated, nameOf, platform } = context;
|
|
157
|
+
const writes = [];
|
|
158
|
+
const events = [];
|
|
159
|
+
for (const file of new Set([
|
|
160
|
+
...previous.map((e) => e.file),
|
|
161
|
+
...desired.map((e) => e.file),
|
|
162
|
+
])) {
|
|
163
|
+
const old = previous.filter((e) => e.file === file);
|
|
164
|
+
const next = desired.filter((e) => e.file === file);
|
|
165
|
+
const text = await fileText(file);
|
|
166
|
+
writes.push({
|
|
167
|
+
kind: "file",
|
|
168
|
+
path: file,
|
|
169
|
+
before: text,
|
|
170
|
+
after: inPluginModule([...old, ...next])
|
|
171
|
+
? pluginModule(text, { before: old, after: next }, platform)
|
|
172
|
+
: patchNative(text, old, next),
|
|
173
|
+
});
|
|
174
|
+
for (const entry of next) {
|
|
175
|
+
const action = changeType({
|
|
176
|
+
sameAsset: old.some((e) => e.id === entry.id && e.harness === entry.harness),
|
|
177
|
+
current: old.some((e) => sameEntry(e, entry)),
|
|
178
|
+
contentChanged: entry.kind === "hook" &&
|
|
179
|
+
trees.some((t) => t.id === entry.id && updated.has(t.path)),
|
|
180
|
+
});
|
|
181
|
+
events.push({
|
|
182
|
+
type: "native",
|
|
183
|
+
action,
|
|
184
|
+
kind: entry.kind,
|
|
185
|
+
harness: entry.harness,
|
|
186
|
+
name: nameOf(entry),
|
|
187
|
+
});
|
|
188
|
+
events.push(...secretNotices(entry, old, action !== "unchanged", nameOf));
|
|
189
|
+
}
|
|
190
|
+
for (const entry of old) {
|
|
191
|
+
if (!next.some((e) => sameEntry(e, entry) ||
|
|
192
|
+
(e.id === entry.id && e.harness === entry.harness))) {
|
|
193
|
+
events.push({
|
|
194
|
+
type: "native",
|
|
195
|
+
action: "removed",
|
|
196
|
+
kind: entry.kind,
|
|
197
|
+
harness: entry.harness,
|
|
198
|
+
name: nameOf(entry),
|
|
199
|
+
});
|
|
200
|
+
events.push(...removedSecrets(entry, []));
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return { writes, events };
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* How a native entry is named in reports. Hook registrations carry IDs, so
|
|
208
|
+
* `known` maps an asset ID to its name or installed folder; a later pair wins.
|
|
209
|
+
*/
|
|
210
|
+
export function entryNames(known) {
|
|
211
|
+
const names = new Map(known);
|
|
212
|
+
return (entry) => {
|
|
213
|
+
if (entry.kind === "mcp") {
|
|
214
|
+
return entry.key;
|
|
215
|
+
}
|
|
216
|
+
if (entry.kind === "knowledge") {
|
|
217
|
+
return "knowledge index";
|
|
218
|
+
}
|
|
219
|
+
if (entry.kind === "sync") {
|
|
220
|
+
return "workspace sync";
|
|
221
|
+
}
|
|
222
|
+
return names.get(entry.id) ?? entry.id;
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
/** The text of `~/.barndog/state.json` once the plan is applied. */
|
|
226
|
+
export function stateText(plan) {
|
|
227
|
+
return (JSON.stringify({
|
|
228
|
+
version: 1,
|
|
229
|
+
links: plan.links,
|
|
230
|
+
// Kept MCP values are recorded only as hashes; see secret-values.ts.
|
|
231
|
+
native: plan.native.map(({ secrets, ...entry }) => ({
|
|
232
|
+
...entry,
|
|
233
|
+
value: redacted(entry.value, secrets ?? []),
|
|
234
|
+
})),
|
|
235
|
+
installed: plan.trees.map(({ id, kind, path, fingerprint, versionId }) => ({
|
|
236
|
+
id,
|
|
237
|
+
kind,
|
|
238
|
+
path,
|
|
239
|
+
fingerprint,
|
|
240
|
+
versionId,
|
|
241
|
+
})),
|
|
242
|
+
}, null, 2) + "\n");
|
|
243
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { githubStatusSchema, gitAuthorizationSchema, gitInstallationSchema, } from "@barndog-ai/api-contract";
|
|
3
|
+
import { connection } from "../server/connection.js";
|
|
4
|
+
import { parsed } from "../server/client.js";
|
|
5
|
+
import { apiClient } from "../auth/transport.js";
|
|
6
|
+
export async function githubStatus(runtime) {
|
|
7
|
+
const conn = await connection(runtime);
|
|
8
|
+
return parsed(githubStatusSchema, apiClient(conn.server, runtime).GET("/v1/github/status"));
|
|
9
|
+
}
|
|
10
|
+
/** The page that links the developer's GitHub account to BarnDog. */
|
|
11
|
+
export async function githubAuth(runtime) {
|
|
12
|
+
const conn = await connection(runtime);
|
|
13
|
+
const { url } = await parsed(gitAuthorizationSchema, apiClient(conn.server, runtime).POST("/v1/github/authorize"));
|
|
14
|
+
return { url };
|
|
15
|
+
}
|
|
16
|
+
/** The page that installs the BarnDog GitHub App on an account or organization. */
|
|
17
|
+
export async function githubInstall(runtime) {
|
|
18
|
+
const conn = await connection(runtime);
|
|
19
|
+
const { url } = await parsed(gitAuthorizationSchema, apiClient(conn.server, runtime).POST("/v1/github/install"));
|
|
20
|
+
return { url };
|
|
21
|
+
}
|
|
22
|
+
export async function githubInstallations(runtime) {
|
|
23
|
+
const conn = await connection(runtime);
|
|
24
|
+
return parsed(z.array(gitInstallationSchema), apiClient(conn.server, runtime).GET("/v1/github/installations"));
|
|
25
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { gitCopyImportSchema, gitCopyImportResultSchema, gitCreateRepositorySchema, gitRemoteHeadSchema, gitConnectionSchema, gitConnectSchema, gitImportSchema, gitMirrorResolutionSchema, okSchema, } from "@barndog-ai/api-contract";
|
|
4
|
+
import { selectOrigin } from "../server/origin.js";
|
|
5
|
+
import { connection } from "../server/connection.js";
|
|
6
|
+
import { selectAsset } from "../server/catalog.js";
|
|
7
|
+
import { parsed } from "../server/client.js";
|
|
8
|
+
import { CliError } from "../../errors.js";
|
|
9
|
+
import { apiClient } from "../auth/transport.js";
|
|
10
|
+
/** The path parameters of one connection's routes; only a UUID may reach the URL. */
|
|
11
|
+
export const connectionParams = (connectionId) => ({
|
|
12
|
+
path: { id: z.uuidv4().parse(connectionId) },
|
|
13
|
+
});
|
|
14
|
+
function repositoryTarget(options) {
|
|
15
|
+
const [owner, repository, ...rest] = options.repository.split("/");
|
|
16
|
+
if (!owner || !repository || rest.length) {
|
|
17
|
+
throw new CliError("Choose the repository with --repository <owner/name>.");
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
kind: options.kind,
|
|
21
|
+
installationId: options.installation,
|
|
22
|
+
owner,
|
|
23
|
+
repository,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export async function githubList(runtime) {
|
|
27
|
+
const conn = await connection(runtime);
|
|
28
|
+
return parsed(z.array(gitConnectionSchema), apiClient(conn.server, runtime).GET("/v1/git-connections"));
|
|
29
|
+
}
|
|
30
|
+
/** Connects a published Skill or Hook to an existing GitHub repository. */
|
|
31
|
+
export async function githubConnect(options, runtime) {
|
|
32
|
+
const conn = await connection(runtime);
|
|
33
|
+
const target = repositoryTarget(options);
|
|
34
|
+
const selected = await selectAsset(target.kind, options.name, options.origin, runtime);
|
|
35
|
+
const body = gitConnectSchema.parse({
|
|
36
|
+
...target,
|
|
37
|
+
assetId: selected.reference.id,
|
|
38
|
+
expectedVersionId: options.expectedVersion ?? selected.asset.version.id,
|
|
39
|
+
mode: options.mode ?? "connect",
|
|
40
|
+
});
|
|
41
|
+
return parsed(gitConnectionSchema, apiClient(conn.server, runtime).POST("/v1/git-connections", { body }));
|
|
42
|
+
}
|
|
43
|
+
/** Creates a Skill or Hook from a GitHub repository, which stays authoritative. */
|
|
44
|
+
export async function githubImport(options, runtime) {
|
|
45
|
+
const conn = await connection(runtime);
|
|
46
|
+
const target = repositoryTarget(options);
|
|
47
|
+
const scope = await selectOrigin(options.origin, conn, runtime);
|
|
48
|
+
const body = gitImportSchema.parse({
|
|
49
|
+
...target,
|
|
50
|
+
name: options.name,
|
|
51
|
+
origin: { type: scope.type, id: scope.id },
|
|
52
|
+
});
|
|
53
|
+
return parsed(gitConnectionSchema, apiClient(conn.server, runtime).POST("/v1/git-connections/import", {
|
|
54
|
+
body,
|
|
55
|
+
}));
|
|
56
|
+
}
|
|
57
|
+
/** Copies a GitHub repository into a BarnDog-owned asset with no connection left behind. */
|
|
58
|
+
export async function githubImportCopy(options, runtime) {
|
|
59
|
+
const conn = await connection(runtime);
|
|
60
|
+
const target = repositoryTarget(options);
|
|
61
|
+
const scope = await selectOrigin(options.origin, conn, runtime);
|
|
62
|
+
const body = gitCopyImportSchema.parse({
|
|
63
|
+
...target,
|
|
64
|
+
name: options.name,
|
|
65
|
+
origin: { type: scope.type, id: scope.id },
|
|
66
|
+
idempotencyKey: options.key,
|
|
67
|
+
});
|
|
68
|
+
return parsed(gitCopyImportResultSchema, apiClient(conn.server, runtime).POST("/v1/git-connections/import-copy", {
|
|
69
|
+
body,
|
|
70
|
+
}));
|
|
71
|
+
}
|
|
72
|
+
/** Creates a GitHub repository for a published asset and exports its history. */
|
|
73
|
+
export async function githubCreateRepository(options, runtime) {
|
|
74
|
+
const conn = await connection(runtime);
|
|
75
|
+
const target = repositoryTarget(options);
|
|
76
|
+
const selected = await selectAsset(target.kind, options.name, options.origin, runtime);
|
|
77
|
+
const body = gitCreateRepositorySchema.parse({
|
|
78
|
+
...target,
|
|
79
|
+
assetId: selected.reference.id,
|
|
80
|
+
expectedVersionId: options.expectedVersion ?? selected.asset.version.id,
|
|
81
|
+
mode: options.mode ?? "mirror",
|
|
82
|
+
visibility: options.visibility ?? "private",
|
|
83
|
+
idempotencyKey: options.key,
|
|
84
|
+
});
|
|
85
|
+
return parsed(gitConnectionSchema, apiClient(conn.server, runtime).POST("/v1/git-connections/create-repository", {
|
|
86
|
+
body,
|
|
87
|
+
}));
|
|
88
|
+
}
|
|
89
|
+
export async function githubShow(connectionId, runtime) {
|
|
90
|
+
const conn = await connection(runtime);
|
|
91
|
+
return parsed(gitConnectionSchema, apiClient(conn.server, runtime).GET("/v1/git-connections/{id}", {
|
|
92
|
+
params: connectionParams(connectionId),
|
|
93
|
+
}));
|
|
94
|
+
}
|
|
95
|
+
/** Syncs now instead of waiting for the server's next scheduled sync. */
|
|
96
|
+
export async function githubSync(connectionId, runtime) {
|
|
97
|
+
const conn = await connection(runtime);
|
|
98
|
+
return parsed(gitConnectionSchema, apiClient(conn.server, runtime).POST("/v1/git-connections/{id}/sync", {
|
|
99
|
+
params: connectionParams(connectionId),
|
|
100
|
+
}));
|
|
101
|
+
}
|
|
102
|
+
/** The repository's main commit as GitHub reports it now, not as last synced. */
|
|
103
|
+
export async function githubRemoteHead(connectionId, runtime) {
|
|
104
|
+
const conn = await connection(runtime);
|
|
105
|
+
return parsed(gitRemoteHeadSchema, apiClient(conn.server, runtime).GET("/v1/git-connections/{id}/remote-head", {
|
|
106
|
+
params: connectionParams(connectionId),
|
|
107
|
+
}));
|
|
108
|
+
}
|
|
109
|
+
/** Settles a mirror that diverged from BarnDog; refused if either side moved since it was inspected. */
|
|
110
|
+
export async function githubResolveMirror(options, runtime) {
|
|
111
|
+
const conn = await connection(runtime);
|
|
112
|
+
const body = gitMirrorResolutionSchema.parse({
|
|
113
|
+
action: options.action,
|
|
114
|
+
expectedVersionId: options.expectedVersion,
|
|
115
|
+
expectedRemoteCommit: options.expectedRemoteCommit,
|
|
116
|
+
idempotencyKey: options.key ?? randomUUID(),
|
|
117
|
+
});
|
|
118
|
+
return parsed(okSchema, apiClient(conn.server, runtime).POST("/v1/git-connections/{id}/mirror-resolution", { params: connectionParams(options.connectionId), body }));
|
|
119
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pull requests on the GitHub repository behind a connection, for assets
|
|
3
|
+
* GitHub is authoritative for. Every call goes to the BarnDog server, never
|
|
4
|
+
* to GitHub itself.
|
|
5
|
+
*/
|
|
6
|
+
import { localPath } from "../../platform.js";
|
|
7
|
+
import { readDirectory } from "../workspace/directory.js";
|
|
8
|
+
import { readFile } from "node:fs/promises";
|
|
9
|
+
import { randomUUID } from "node:crypto";
|
|
10
|
+
import { z } from "zod";
|
|
11
|
+
import { gitConnectionSchema, gitPullSchema, gitPullDetailsSchema, gitProposalSchema, gitRevisionSchema, gitReviewSchema, gitCommentSchema, gitMergeSchema, } from "@barndog-ai/api-contract";
|
|
12
|
+
import { connection } from "../server/connection.js";
|
|
13
|
+
import { parsed } from "../server/client.js";
|
|
14
|
+
import { connectionParams } from "./connections.js";
|
|
15
|
+
import { apiClient } from "../auth/transport.js";
|
|
16
|
+
const bodyText = async (options, runtime) => options.bodyFile
|
|
17
|
+
? await readFile(localPath(options.bodyFile, runtime), "utf8")
|
|
18
|
+
: (options.body ?? "");
|
|
19
|
+
/** The path parameters of one pull request's routes. */
|
|
20
|
+
const pullParams = (connectionId, number) => ({
|
|
21
|
+
path: {
|
|
22
|
+
...connectionParams(connectionId).path,
|
|
23
|
+
number: z.number().int().positive().parse(number),
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
/** Every file of the package, as the server's proposal routes take them. */
|
|
27
|
+
async function packageFiles(directory, runtime) {
|
|
28
|
+
const entries = await readDirectory(localPath(directory ?? ".", runtime), runtime);
|
|
29
|
+
return entries.map((entry) => ({
|
|
30
|
+
path: entry.path,
|
|
31
|
+
content: entry.data.toString("base64"),
|
|
32
|
+
executable: entry.executable,
|
|
33
|
+
}));
|
|
34
|
+
}
|
|
35
|
+
export async function githubPullsList(connectionId, runtime) {
|
|
36
|
+
const conn = await connection(runtime);
|
|
37
|
+
return parsed(z.array(gitPullSchema), apiClient(conn.server, runtime).GET("/v1/git-connections/{id}/pulls", {
|
|
38
|
+
params: connectionParams(connectionId),
|
|
39
|
+
}));
|
|
40
|
+
}
|
|
41
|
+
/** One pull request with its reviews and comments. */
|
|
42
|
+
export async function githubPullsShow(connectionId, number, runtime) {
|
|
43
|
+
const conn = await connection(runtime);
|
|
44
|
+
return parsed(gitPullDetailsSchema, apiClient(conn.server, runtime).GET("/v1/git-connections/{id}/pulls/{number}", {
|
|
45
|
+
params: pullParams(connectionId, number),
|
|
46
|
+
}));
|
|
47
|
+
}
|
|
48
|
+
/** Opens a pull request whose content is the complete package, not a patch. */
|
|
49
|
+
export async function githubPullsCreate(options, runtime) {
|
|
50
|
+
const conn = await connection(runtime);
|
|
51
|
+
const body = await bodyText(options, runtime);
|
|
52
|
+
const proposal = gitProposalSchema.parse({
|
|
53
|
+
expectedCommit: options.expectedCommit,
|
|
54
|
+
files: await packageFiles(options.directory, runtime),
|
|
55
|
+
title: options.title,
|
|
56
|
+
body,
|
|
57
|
+
idempotencyKey: options.key ?? randomUUID(),
|
|
58
|
+
});
|
|
59
|
+
return parsed(gitPullSchema, apiClient(conn.server, runtime).POST("/v1/git-connections/{id}/pulls", {
|
|
60
|
+
params: connectionParams(options.connectionId),
|
|
61
|
+
body: proposal,
|
|
62
|
+
}));
|
|
63
|
+
}
|
|
64
|
+
/** Replaces an open pull request's content with the complete package. */
|
|
65
|
+
export async function githubPullsRevise(options, runtime) {
|
|
66
|
+
const conn = await connection(runtime);
|
|
67
|
+
const body = await bodyText(options, runtime);
|
|
68
|
+
const revision = gitRevisionSchema.parse({
|
|
69
|
+
expectedCommit: options.expectedCommit,
|
|
70
|
+
files: await packageFiles(options.directory, runtime),
|
|
71
|
+
title: options.title,
|
|
72
|
+
body,
|
|
73
|
+
idempotencyKey: options.key ?? randomUUID(),
|
|
74
|
+
});
|
|
75
|
+
return parsed(gitPullSchema, apiClient(conn.server, runtime).PUT("/v1/git-connections/{id}/pulls/{number}/revisions", {
|
|
76
|
+
params: pullParams(options.connectionId, options.number),
|
|
77
|
+
body: revision,
|
|
78
|
+
}));
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Approves, requests changes or comments on a pull request at the inspected
|
|
82
|
+
* head commit. Reads `bodyFile` when given.
|
|
83
|
+
*/
|
|
84
|
+
export async function githubPullsReview(options, runtime) {
|
|
85
|
+
const conn = await connection(runtime);
|
|
86
|
+
const body = await bodyText(options, runtime);
|
|
87
|
+
return parsed(gitPullDetailsSchema, apiClient(conn.server, runtime).POST("/v1/git-connections/{id}/pulls/{number}/reviews", {
|
|
88
|
+
params: pullParams(options.connectionId, options.number),
|
|
89
|
+
body: gitReviewSchema.parse({
|
|
90
|
+
expectedCommit: options.expectedCommit,
|
|
91
|
+
event: options.event,
|
|
92
|
+
body,
|
|
93
|
+
}),
|
|
94
|
+
}));
|
|
95
|
+
}
|
|
96
|
+
/** A general comment, or an inline one when `path`, `line` and `side` are given. */
|
|
97
|
+
export async function githubPullsComment(options, runtime) {
|
|
98
|
+
const conn = await connection(runtime);
|
|
99
|
+
const body = await bodyText(options, runtime);
|
|
100
|
+
return parsed(gitPullDetailsSchema, apiClient(conn.server, runtime).POST("/v1/git-connections/{id}/pulls/{number}/comments", {
|
|
101
|
+
params: pullParams(options.connectionId, options.number),
|
|
102
|
+
body: gitCommentSchema.parse({
|
|
103
|
+
expectedCommit: options.expectedCommit,
|
|
104
|
+
body,
|
|
105
|
+
path: options.path,
|
|
106
|
+
line: options.line,
|
|
107
|
+
side: options.side,
|
|
108
|
+
}),
|
|
109
|
+
}));
|
|
110
|
+
}
|
|
111
|
+
/** Returns the connection, now at the merged commit, rather than the pull request. */
|
|
112
|
+
export async function githubPullsMerge(options, runtime) {
|
|
113
|
+
const conn = await connection(runtime);
|
|
114
|
+
return parsed(gitConnectionSchema, apiClient(conn.server, runtime).PUT("/v1/git-connections/{id}/pulls/{number}/merge", {
|
|
115
|
+
params: pullParams(options.connectionId, options.number),
|
|
116
|
+
body: gitMergeSchema.parse({ expectedCommit: options.expectedCommit }),
|
|
117
|
+
}));
|
|
118
|
+
}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { homedir } from "node:os";
|
|
2
1
|
import { join } from "node:path";
|
|
3
2
|
import { hookAdaptPrompt, hookSchema, } from "@barndog-ai/api-contract";
|
|
4
3
|
import { hookMetadata } from "@barndog-ai/api-contract/package";
|
|
5
4
|
import { readSettings, SetupRequiredError } from "../../config/settings.js";
|
|
6
5
|
import { CliError } from "../../errors.js";
|
|
7
|
-
import { adapters,
|
|
8
|
-
import { selectAsset } from "../
|
|
9
|
-
import { repoForOrigin, selectRepoAsset } from "../
|
|
10
|
-
import { LOCAL_ORIGIN } from "../
|
|
6
|
+
import { adapters, hookHarnesses, isHookHarness, } from "../../harnesses/registry.js";
|
|
7
|
+
import { selectAsset } from "../server/catalog.js";
|
|
8
|
+
import { repoForOrigin, selectRepoAsset } from "../workspace/assets.js";
|
|
9
|
+
import { LOCAL_ORIGIN } from "../workspace/overlay.js";
|
|
11
10
|
import { importedFrom } from "../imports/local.js";
|
|
12
11
|
/** "Codex", "Codex and Cursor", "Claude Code, Codex or Cursor". */
|
|
13
12
|
export function toolNames(tools, joiner = "and") {
|
|
@@ -17,34 +16,40 @@ export function toolNames(tools, joiner = "and") {
|
|
|
17
16
|
: `${names.slice(0, -1).join(", ")} ${joiner} ${names.at(-1)}`;
|
|
18
17
|
}
|
|
19
18
|
/** The shared prompt, with this machine's names for coding tools and the local folder. */
|
|
20
|
-
|
|
19
|
+
function adaptPrompt(input) {
|
|
21
20
|
return hookAdaptPrompt({
|
|
22
21
|
...input,
|
|
23
|
-
|
|
22
|
+
// Object.fromEntries types its keys as string; the map covers every harness.
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
|
24
|
+
tools: Object.fromEntries(hookHarnesses.map((harness) => [harness, adapters[harness].name])),
|
|
24
25
|
place: input.place.type === "folder"
|
|
25
26
|
? { ...input.place, origin: LOCAL_ORIGIN }
|
|
26
27
|
: input.place,
|
|
27
28
|
});
|
|
28
29
|
}
|
|
29
|
-
async function resolveHook(name, origin,
|
|
30
|
+
async function resolveHook(name, origin, runtime) {
|
|
31
|
+
const { home } = runtime;
|
|
30
32
|
const settings = await readSettings(home);
|
|
31
|
-
if (!settings)
|
|
33
|
+
if (!settings) {
|
|
32
34
|
throw new SetupRequiredError();
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
const
|
|
36
|
-
const
|
|
35
|
+
}
|
|
36
|
+
const local = settings.localWorkspace;
|
|
37
|
+
const git = settings.gitWorkspace;
|
|
38
|
+
const shared = Boolean(git || settings.connection);
|
|
39
|
+
const repo = repoForOrigin(settings, runtime, origin);
|
|
37
40
|
if (!repo) {
|
|
38
|
-
const selected = await selectAsset("hook", name, origin,
|
|
41
|
+
const selected = await selectAsset("hook", name, origin, runtime);
|
|
39
42
|
const asset = hookSchema.parse(selected.asset);
|
|
40
43
|
const implementations = {};
|
|
41
|
-
for (const row of asset.compatibility)
|
|
42
|
-
if (row.implementation)
|
|
44
|
+
for (const row of asset.compatibility) {
|
|
45
|
+
if (row.implementation) {
|
|
43
46
|
implementations[row.harness] = row.implementation;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
44
49
|
return {
|
|
45
50
|
name: asset.name,
|
|
46
51
|
implementations,
|
|
47
|
-
machine: settings.harnesses,
|
|
52
|
+
machine: settings.harnesses.filter(isHookHarness),
|
|
48
53
|
place: {
|
|
49
54
|
type: "workspace",
|
|
50
55
|
origin,
|
|
@@ -58,7 +63,7 @@ async function resolveHook(name, origin, home) {
|
|
|
58
63
|
return {
|
|
59
64
|
name: asset.name,
|
|
60
65
|
implementations,
|
|
61
|
-
machine: settings.harnesses,
|
|
66
|
+
machine: settings.harnesses.filter(isHookHarness),
|
|
62
67
|
place: inFolder
|
|
63
68
|
? {
|
|
64
69
|
type: "folder",
|
|
@@ -76,17 +81,19 @@ async function resolveHook(name, origin, home) {
|
|
|
76
81
|
* Works out which coding tools a Hook doesn't cover and writes the prompt for
|
|
77
82
|
* them. Without `targets`, those are the tools set up on this machine.
|
|
78
83
|
*/
|
|
79
|
-
export async function adaptHook(name, origin, targets,
|
|
80
|
-
const hook = await resolveHook(name, origin,
|
|
81
|
-
const written =
|
|
84
|
+
export async function adaptHook(name, origin, targets, runtime) {
|
|
85
|
+
const hook = await resolveHook(name, origin, runtime);
|
|
86
|
+
const written = hookHarnesses.filter((h) => hook.implementations[h]);
|
|
82
87
|
const covered = targets?.filter((h) => written.includes(h)) ?? [];
|
|
83
|
-
if (covered.length)
|
|
88
|
+
if (covered.length) {
|
|
84
89
|
throw new CliError(`${hook.name} already has settings for ${toolNames(covered)}.`);
|
|
85
|
-
|
|
86
|
-
|
|
90
|
+
}
|
|
91
|
+
const missing = hookHarnesses.filter((h) => (targets ?? hook.machine).includes(h) && !written.includes(h));
|
|
92
|
+
if (!missing.length) {
|
|
87
93
|
return { name: hook.name, written, targets: [], prompt: null };
|
|
94
|
+
}
|
|
88
95
|
const record = hook.place.type === "folder"
|
|
89
|
-
? await importedFrom("hook", hook.name,
|
|
96
|
+
? await importedFrom("hook", hook.name, runtime)
|
|
90
97
|
: null;
|
|
91
98
|
return {
|
|
92
99
|
name: hook.name,
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { hookListSchema } from "@barndog-ai/api-contract";
|
|
2
|
+
import { apiClient } from "../auth/transport.js";
|
|
3
|
+
import { allPages } from "../server/pages.js";
|
|
4
|
+
/** Every published Hook you can see, as the server describes it. */
|
|
5
|
+
export async function publishedHooks(conn, runtime) {
|
|
6
|
+
const client = apiClient(conn.server, runtime);
|
|
7
|
+
return allPages(async (cursor) => {
|
|
8
|
+
const page = hookListSchema.parse((await client.GET("/v1/hooks", {
|
|
9
|
+
params: { query: { limit: 100, cursor } },
|
|
10
|
+
})).data);
|
|
11
|
+
if (page.hooks.some((hook) => hook.organizationId !== conn.organizationId)) {
|
|
12
|
+
throw new Error("The server sent a catalog page for another organization");
|
|
13
|
+
}
|
|
14
|
+
return { items: page.hooks, nextCursor: page.nextCursor };
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
export async function hookCatalog(conn, runtime) {
|
|
18
|
+
return (await publishedHooks(conn, runtime)).map((hook) => ({
|
|
19
|
+
id: hook.id,
|
|
20
|
+
kind: "hook",
|
|
21
|
+
name: hook.name,
|
|
22
|
+
origin: hook.origin,
|
|
23
|
+
version: {
|
|
24
|
+
number: hook.version.number,
|
|
25
|
+
description: hook.version.description,
|
|
26
|
+
},
|
|
27
|
+
}));
|
|
28
|
+
}
|