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,254 +1,342 @@
|
|
|
1
|
+
import { localPath } from "../../platform.js";
|
|
1
2
|
import { synchronize } from "../environment/sync.js";
|
|
2
3
|
import { readFile } from "node:fs/promises";
|
|
3
|
-
import { homedir } from "node:os";
|
|
4
4
|
import { z } from "zod";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { connection
|
|
5
|
+
import { packageApi } from "./api.js";
|
|
6
|
+
import { downloadChange, selectPackage } from "./remote.js";
|
|
7
|
+
import { connection } from "../server/connection.js";
|
|
8
8
|
import { readSettings } from "../../config/settings.js";
|
|
9
9
|
import { CliError } from "../../errors.js";
|
|
10
10
|
import { developers } from "../discovery/index.js";
|
|
11
|
-
import { LOCAL_ORIGIN } from "../
|
|
12
|
-
import { createGitAsset,
|
|
13
|
-
import { NoWorkingCopyError,
|
|
11
|
+
import { LOCAL_ORIGIN } from "../workspace/overlay.js";
|
|
12
|
+
import { createGitAsset, gitVersionDiff, gitVersionFiles, gitVersions, gitWorkingStatus, pullGitAsset, pushGitWorkingCopy, resolveGitConflict, updateGitWorkingCopy, } from "./workspace-git.js";
|
|
13
|
+
import { NoWorkingCopyError, pullCloudPackage, createWorkspace, workspaceStatus, updateWorkspace, resolveConflict, pushWorkspace, } from "./workspace.js";
|
|
14
|
+
import { allPages } from "../server/pages.js";
|
|
15
|
+
import { changeAssetId } from "./results.js";
|
|
14
16
|
/** Who an ID is, when the server will say; IDs still print if it won't. */
|
|
15
|
-
const developerNames = (
|
|
17
|
+
const developerNames = (runtime) => {
|
|
18
|
+
return developers(undefined, runtime).then((people) => Object.fromEntries(people.map((p) => [p.id, p.name])), () => ({}));
|
|
19
|
+
};
|
|
16
20
|
/**
|
|
17
21
|
* A text file's closing newline isn't part of the selected lines. With a known line
|
|
18
22
|
* count it's kept when it really is content: a range that ends on an empty line.
|
|
19
23
|
*/
|
|
20
|
-
|
|
21
|
-
if (!text.endsWith("\n"))
|
|
24
|
+
function selectedText(text, lines) {
|
|
25
|
+
if (!text.endsWith("\n")) {
|
|
22
26
|
return text;
|
|
27
|
+
}
|
|
23
28
|
return lines === undefined || text.split("\n").length > lines
|
|
24
29
|
? text.slice(0, -1)
|
|
25
30
|
: text;
|
|
26
31
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
: {
|
|
30
|
-
mode: "environment-preview",
|
|
31
|
-
events: await synchronize(undefined, home, undefined, {
|
|
32
|
-
dryRun: true,
|
|
33
|
-
}),
|
|
34
|
-
};
|
|
35
|
-
async function collaborateLocal(path, action, home) {
|
|
36
|
-
if (action === "status" || action === "diff")
|
|
37
|
-
return preview(action, home);
|
|
38
|
-
throw new CliError(`Local assets have no review step. Edit them directly in ${path}, then sync.`, "barndog sync");
|
|
39
|
-
}
|
|
40
|
-
async function collaborateGit(workspace, action, options, cwd, home) {
|
|
41
|
-
const asset = {
|
|
42
|
-
name: options.name,
|
|
43
|
-
origin: options.origin,
|
|
44
|
-
target: options.directory,
|
|
45
|
-
kind: options.kind,
|
|
46
|
-
};
|
|
47
|
-
switch (action) {
|
|
48
|
-
case "create":
|
|
49
|
-
return createGitAsset(workspace, asset, cwd, home);
|
|
50
|
-
case "pull-skill":
|
|
51
|
-
return pullGitAsset(workspace, asset, cwd, home);
|
|
52
|
-
case "pull":
|
|
53
|
-
return updateGitWorkingCopy(cwd, home);
|
|
54
|
-
case "status":
|
|
55
|
-
case "diff":
|
|
56
|
-
try {
|
|
57
|
-
const working = await gitWorkingStatus(cwd, home);
|
|
58
|
-
return action === "status" ? working : working.changes;
|
|
59
|
-
}
|
|
60
|
-
catch (error) {
|
|
61
|
-
if (!(error instanceof NoWorkingCopyError))
|
|
62
|
-
throw error;
|
|
63
|
-
return preview(action, home);
|
|
64
|
-
}
|
|
65
|
-
case "push":
|
|
66
|
-
return pushGitWorkingCopy(workspace, options, cwd, home);
|
|
67
|
-
case "resolve":
|
|
68
|
-
return resolveGitConflict(options.path, cwd, home);
|
|
69
|
-
case "versions":
|
|
70
|
-
case "version-show":
|
|
71
|
-
case "version-diff":
|
|
72
|
-
return gitHistory(workspace, action, { ...options, ...asset }, home);
|
|
73
|
-
default:
|
|
74
|
-
throw new CliError("Reviews happen as pull requests on your Git host in a Git repo workspace.", "barndog status");
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
export async function collaborate(action, options = {}, cwd = process.cwd(), home = homedir()) {
|
|
32
|
+
async function backend(runtime, origin) {
|
|
33
|
+
const { home } = runtime;
|
|
78
34
|
const settings = await readSettings(home);
|
|
79
|
-
if (settings?.
|
|
80
|
-
return
|
|
81
|
-
|
|
82
|
-
if (settings
|
|
35
|
+
if (settings?.gitWorkspace) {
|
|
36
|
+
return { type: "git", workspace: settings.gitWorkspace };
|
|
37
|
+
}
|
|
38
|
+
if (settings &&
|
|
83
39
|
settings.localWorkspace &&
|
|
84
|
-
(!settings.connection ||
|
|
85
|
-
return
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
40
|
+
(!settings.connection || origin === LOCAL_ORIGIN)) {
|
|
41
|
+
return { type: "local", path: settings.localWorkspace.path };
|
|
42
|
+
}
|
|
43
|
+
return { type: "cloud" };
|
|
44
|
+
}
|
|
45
|
+
const noLocalReview = (path) => new CliError(`Local assets have no review step. Edit them directly in ${path}, then sync.`, "barndog sync");
|
|
46
|
+
async function cloudConnection(runtime, origin) {
|
|
47
|
+
const where = await backend(runtime, origin);
|
|
48
|
+
if (where.type === "git") {
|
|
49
|
+
throw new CliError("Reviews happen as pull requests on your Git host in a Git repo workspace.", "barndog status");
|
|
50
|
+
}
|
|
51
|
+
if (where.type === "local") {
|
|
52
|
+
throw noLocalReview(where.path);
|
|
53
|
+
}
|
|
54
|
+
return connection(runtime);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* `create` for a new Skill or Hook: a working copy from the kind's scaffold, in
|
|
58
|
+
* Git or Cloud as the workspace is set up. Local workspaces have no review
|
|
59
|
+
* step, so they are refused with a fix.
|
|
60
|
+
*/
|
|
61
|
+
export async function createPackage(target, runtime) {
|
|
62
|
+
const where = await backend(runtime, target.origin);
|
|
63
|
+
if (where.type === "local") {
|
|
64
|
+
throw noLocalReview(where.path);
|
|
65
|
+
}
|
|
66
|
+
if (where.type === "git") {
|
|
67
|
+
return createGitAsset(where.workspace, { ...target, target: target.directory }, runtime);
|
|
68
|
+
}
|
|
69
|
+
return createWorkspace({ name: target.name, origin: target.origin, kind: target.kind }, { target: target.directory, runtime });
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* `pull <name>`: a new working folder holding the published asset, in Git or
|
|
73
|
+
* Cloud as the workspace is set up. Refused in a local workspace.
|
|
74
|
+
*/
|
|
75
|
+
export async function pullPackage(target, runtime) {
|
|
76
|
+
const where = await backend(runtime, target.origin);
|
|
77
|
+
if (where.type === "local") {
|
|
78
|
+
throw noLocalReview(where.path);
|
|
79
|
+
}
|
|
80
|
+
if (where.type === "git") {
|
|
81
|
+
return pullGitAsset(where.workspace, { ...target, target: target.directory }, runtime);
|
|
82
|
+
}
|
|
83
|
+
return pullCloudPackage({ name: target.name, origin: target.origin, kind: target.kind }, { target: target.directory, runtime });
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* `pull` inside a working copy: merges what changed remotely into the folder.
|
|
87
|
+
* Refused in a local workspace.
|
|
88
|
+
*/
|
|
89
|
+
export async function updateWorkingCopy(runtime) {
|
|
90
|
+
const where = await backend(runtime);
|
|
91
|
+
if (where.type === "local") {
|
|
92
|
+
throw noLocalReview(where.path);
|
|
93
|
+
}
|
|
94
|
+
return where.type === "git"
|
|
95
|
+
? updateGitWorkingCopy(runtime)
|
|
96
|
+
: updateWorkspace(runtime);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* `status` inside a working copy; anywhere else, or in a local workspace, says
|
|
100
|
+
* to describe the machine-wide environment instead.
|
|
101
|
+
*/
|
|
102
|
+
export async function workingStatus(runtime) {
|
|
103
|
+
const where = await backend(runtime);
|
|
104
|
+
if (where.type === "local") {
|
|
105
|
+
return { mode: "environment" };
|
|
106
|
+
}
|
|
107
|
+
try {
|
|
108
|
+
return where.type === "git"
|
|
109
|
+
? await gitWorkingStatus(runtime)
|
|
110
|
+
: await workspaceStatus(runtime);
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
if (!(error instanceof NoWorkingCopyError)) {
|
|
114
|
+
throw error;
|
|
146
115
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
if (action === "show") {
|
|
163
|
-
const change = await getChange(id, conn, home, options.kind);
|
|
164
|
-
const [files, names, versions] = await Promise.all([
|
|
165
|
-
download(`/v1/skill-changes/${id}/package?revision=${change.revision}`, conn, home, change.commit, options.kind),
|
|
166
|
-
developerNames(home),
|
|
167
|
-
change.baseVersionId
|
|
168
|
-
? client
|
|
169
|
-
.GET("/v1/skills/{id}/versions", {
|
|
170
|
-
params: { path: { id: change.skillId } },
|
|
171
|
-
})
|
|
172
|
-
.then((result) => result.data ?? [], () => [])
|
|
173
|
-
: [],
|
|
174
|
-
]);
|
|
175
|
-
return {
|
|
176
|
-
...change,
|
|
177
|
-
names,
|
|
178
|
-
baseVersionNumber: versions.find((v) => v.id === change.baseVersionId)
|
|
179
|
-
?.number,
|
|
180
|
-
files: files.map((e) => ({
|
|
181
|
-
path: e.path,
|
|
182
|
-
content: e.data.toString("base64"),
|
|
183
|
-
executable: e.executable,
|
|
184
|
-
})),
|
|
185
|
-
};
|
|
186
|
-
}
|
|
187
|
-
if (action === "change-diff")
|
|
188
|
-
return (await client.GET("/v1/skill-changes/{id}/diff", {
|
|
189
|
-
params: {
|
|
190
|
-
...params,
|
|
191
|
-
query: {
|
|
192
|
-
revision: options.revision,
|
|
193
|
-
fromRevision: options.fromRevision,
|
|
194
|
-
},
|
|
195
|
-
},
|
|
196
|
-
})).data;
|
|
197
|
-
const expectedRevision = z.number().int().positive().parse(options.revision), body = { expectedRevision };
|
|
198
|
-
if (action === "approve" || action === "request-changes")
|
|
199
|
-
return (await client.POST("/v1/skill-changes/{id}/reviews", {
|
|
200
|
-
params,
|
|
201
|
-
body: {
|
|
202
|
-
...body,
|
|
203
|
-
decision: action === "approve" ? "approve" : "request_changes",
|
|
204
|
-
},
|
|
205
|
-
})).data;
|
|
206
|
-
if (action === "reject")
|
|
207
|
-
return (await client.POST("/v1/skill-changes/{id}/reject", { params, body })).data;
|
|
208
|
-
if (action === "merge")
|
|
209
|
-
return (await client.POST("/v1/skill-changes/{id}/merge", { params, body }))
|
|
210
|
-
.data;
|
|
211
|
-
if (action === "comment") {
|
|
212
|
-
const text = options.bodyFile
|
|
213
|
-
? await readFile(options.bodyFile, "utf8")
|
|
214
|
-
: options.body;
|
|
215
|
-
if (!text?.trim())
|
|
216
|
-
throw new Error("Supply --body <text> or --body-file <path>");
|
|
217
|
-
if (options.thread)
|
|
218
|
-
return (await client.POST("/v1/skill-changes/{id}/discussions/{threadId}/comments", {
|
|
219
|
-
params: { path: { id, threadId: z.uuid().parse(options.thread) } },
|
|
220
|
-
body: { ...body, body: text },
|
|
221
|
-
})).data;
|
|
222
|
-
return (await client.POST("/v1/skill-changes/{id}/discussions", {
|
|
223
|
-
params,
|
|
224
|
-
body: {
|
|
225
|
-
...body,
|
|
226
|
-
body: text,
|
|
227
|
-
path: options.path,
|
|
228
|
-
side: options.side,
|
|
229
|
-
startLine: options.startLine,
|
|
230
|
-
endLine: options.endLine,
|
|
231
|
-
replacement: options.replacementFile
|
|
232
|
-
? selectedText(await readFile(options.replacementFile, "utf8"))
|
|
233
|
-
: undefined,
|
|
234
|
-
expectedContent: options.expectedFile
|
|
235
|
-
? selectedText(await readFile(options.expectedFile, "utf8"), options.startLine && options.endLine
|
|
236
|
-
? options.endLine - options.startLine + 1
|
|
237
|
-
: undefined)
|
|
238
|
-
: undefined,
|
|
239
|
-
},
|
|
240
|
-
})).data;
|
|
241
|
-
}
|
|
242
|
-
const threadParams = {
|
|
243
|
-
path: { id, threadId: z.uuid().parse(options.thread) },
|
|
116
|
+
return { mode: "environment" };
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Returns working-copy edits, or outside a working copy, planned sync events.
|
|
121
|
+
* The dry-run path can still fetch and populate caches.
|
|
122
|
+
*/
|
|
123
|
+
export async function workingDiff(runtime) {
|
|
124
|
+
const status = await workingStatus(runtime);
|
|
125
|
+
if ("changes" in status) {
|
|
126
|
+
return status.changes;
|
|
127
|
+
}
|
|
128
|
+
return {
|
|
129
|
+
mode: "environment-preview",
|
|
130
|
+
events: await synchronize(undefined, runtime, undefined, { dryRun: true }),
|
|
244
131
|
};
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* `push` inside a working copy, to a review branch or proposal as the workspace
|
|
135
|
+
* is set up. Refused in a local workspace.
|
|
136
|
+
*/
|
|
137
|
+
export async function pushWorkingCopy(options, runtime) {
|
|
138
|
+
const where = await backend(runtime, options.origin);
|
|
139
|
+
if (where.type === "local") {
|
|
140
|
+
throw noLocalReview(where.path);
|
|
141
|
+
}
|
|
142
|
+
return where.type === "git"
|
|
143
|
+
? pushGitWorkingCopy(where.workspace, options, runtime)
|
|
144
|
+
: pushWorkspace(options, runtime);
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* `resolve <path>`: marks one conflicted file resolved once its markers are
|
|
148
|
+
* gone. `path` is relative to `cwd`.
|
|
149
|
+
*/
|
|
150
|
+
export async function resolveFile(path, runtime) {
|
|
151
|
+
const where = await backend(runtime);
|
|
152
|
+
if (where.type === "local") {
|
|
153
|
+
throw noLocalReview(where.path);
|
|
154
|
+
}
|
|
155
|
+
return where.type === "git"
|
|
156
|
+
? resolveGitConflict(path, runtime)
|
|
157
|
+
: resolveConflict(path, runtime);
|
|
158
|
+
}
|
|
159
|
+
async function publishedPackage(target, runtime) {
|
|
160
|
+
const where = await backend(runtime, target.origin);
|
|
161
|
+
if (where.type === "local") {
|
|
162
|
+
throw noLocalReview(where.path);
|
|
163
|
+
}
|
|
164
|
+
if (where.type === "git") {
|
|
165
|
+
return where;
|
|
166
|
+
}
|
|
167
|
+
const conn = await connection(runtime);
|
|
168
|
+
return {
|
|
169
|
+
type: "cloud",
|
|
170
|
+
api: packageApi(target.kind, conn, runtime),
|
|
171
|
+
published: await selectPackage({ name: target.name, selector: target.origin, kind: target.kind }, conn, runtime),
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
/** Newest last. */
|
|
175
|
+
export async function packageVersions(target, runtime) {
|
|
176
|
+
const where = await publishedPackage(target, runtime);
|
|
177
|
+
if (where.type === "git") {
|
|
178
|
+
return gitVersions(where.workspace, target, runtime);
|
|
179
|
+
}
|
|
180
|
+
const [rows, names] = await Promise.all([
|
|
181
|
+
where.api.versions(where.published.id),
|
|
182
|
+
developerNames(runtime),
|
|
183
|
+
]);
|
|
184
|
+
return rows.map((row) => ({
|
|
185
|
+
...row,
|
|
186
|
+
publisherName: names[row.publishedBy],
|
|
187
|
+
}));
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* A published version's files, base64-encoded; the newest when `version` is
|
|
191
|
+
* left out.
|
|
192
|
+
*/
|
|
193
|
+
export async function versionFiles(target, runtime) {
|
|
194
|
+
const where = await publishedPackage(target, runtime);
|
|
195
|
+
if (where.type === "git") {
|
|
196
|
+
return gitVersionFiles(where.workspace, target, runtime);
|
|
197
|
+
}
|
|
198
|
+
return where.api.content(where.published.id, target.version ?? where.published.version.number);
|
|
199
|
+
}
|
|
200
|
+
export async function diffVersions(target, runtime) {
|
|
201
|
+
const where = await publishedPackage(target, runtime);
|
|
202
|
+
if (where.type === "git") {
|
|
203
|
+
return gitVersionDiff(where.workspace, target, runtime);
|
|
204
|
+
}
|
|
205
|
+
return where.api.diff(where.published.id, {
|
|
206
|
+
from: target.from,
|
|
207
|
+
to: target.to,
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Every proposal the developer can see, following the server's pages. Cloud
|
|
212
|
+
* only: a Git workspace reviews in pull requests on its host.
|
|
213
|
+
*/
|
|
214
|
+
export async function listChanges({ kind }, runtime) {
|
|
215
|
+
const api = packageApi(kind, await cloudConnection(runtime), runtime);
|
|
216
|
+
return allPages((cursor) => api.changes(cursor));
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* A proposal with its files (base64-encoded), its base version number and
|
|
220
|
+
* developer names by ID. Cloud only.
|
|
221
|
+
*/
|
|
222
|
+
export async function showChange(target, runtime) {
|
|
223
|
+
const conn = await cloudConnection(runtime);
|
|
224
|
+
const id = z.uuid().parse(target.id);
|
|
225
|
+
const { kind } = target;
|
|
226
|
+
const api = packageApi(kind, conn, runtime);
|
|
227
|
+
const change = await api.change(id);
|
|
228
|
+
const [files, names, versions] = await Promise.all([
|
|
229
|
+
downloadChange({ id, revision: change.revision, commit: change.commit }, conn, { runtime, kind }),
|
|
230
|
+
developerNames(runtime),
|
|
231
|
+
// The base number is a nicety; show the change without it if this fails.
|
|
232
|
+
change.baseVersionId
|
|
233
|
+
? api.versions(changeAssetId(change)).catch(() => [])
|
|
234
|
+
: [],
|
|
235
|
+
]);
|
|
236
|
+
return {
|
|
237
|
+
...change,
|
|
238
|
+
names,
|
|
239
|
+
baseVersionNumber: versions.find((v) => v.id === change.baseVersionId)
|
|
240
|
+
?.number,
|
|
241
|
+
files: files.map((e) => ({
|
|
242
|
+
path: e.path,
|
|
243
|
+
content: e.data.toString("base64"),
|
|
244
|
+
executable: e.executable,
|
|
245
|
+
})),
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* A proposal's diff at a revision (the newest by default), against
|
|
250
|
+
* `fromRevision` or the version it started from. Cloud only.
|
|
251
|
+
*/
|
|
252
|
+
export async function changeDiff(target, runtime) {
|
|
253
|
+
const api = packageApi(target.kind, await cloudConnection(runtime), runtime);
|
|
254
|
+
return api.changeDiff(z.uuid().parse(target.id), {
|
|
255
|
+
revision: target.revision,
|
|
256
|
+
fromRevision: target.fromRevision,
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
async function changeAtRevision(target, runtime) {
|
|
260
|
+
return {
|
|
261
|
+
api: packageApi(target.kind, await cloudConnection(runtime), runtime),
|
|
262
|
+
id: z.uuid().parse(target.id),
|
|
263
|
+
body: {
|
|
264
|
+
expectedRevision: z.number().int().positive().parse(target.revision),
|
|
265
|
+
},
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Approves or requests changes on the revision the reviewer inspected. Cloud
|
|
270
|
+
* only.
|
|
271
|
+
*/
|
|
272
|
+
export async function reviewChange(decision, target, runtime) {
|
|
273
|
+
const { api, id, body } = await changeAtRevision(target, runtime);
|
|
274
|
+
return api.review(id, {
|
|
275
|
+
...body,
|
|
276
|
+
decision: decision === "approve" ? "approve" : "request_changes",
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Closes a proposal without publishing it; the author needs `push --new` to
|
|
281
|
+
* propose again. Cloud only.
|
|
282
|
+
*/
|
|
283
|
+
export async function rejectChange(target, runtime) {
|
|
284
|
+
const { api, id, body } = await changeAtRevision(target, runtime);
|
|
285
|
+
return api.reject(id, body);
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Publishes a proposal at the inspected revision, as its scope's review
|
|
289
|
+
* settings allow. Cloud only.
|
|
290
|
+
*/
|
|
291
|
+
export async function mergeChange(target, runtime) {
|
|
292
|
+
const { api, id, body } = await changeAtRevision(target, runtime);
|
|
293
|
+
return api.merge(id, body);
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Adds a comment to a proposal and returns the updated proposal. Reads
|
|
297
|
+
* `bodyFile`, `replacementFile` and `expectedFile` from disk; a file's closing
|
|
298
|
+
* newline isn't part of the selected lines. Cloud only.
|
|
299
|
+
*/
|
|
300
|
+
export async function commentOnChange(options, runtime) {
|
|
301
|
+
const { api, id, body } = await changeAtRevision(options, runtime);
|
|
302
|
+
const text = options.bodyFile
|
|
303
|
+
? await readFile(localPath(options.bodyFile, runtime), "utf8")
|
|
304
|
+
: options.body;
|
|
305
|
+
if (!text?.trim()) {
|
|
306
|
+
throw new CliError("Add the comment with --body <text> or --body-file <path>.");
|
|
307
|
+
}
|
|
308
|
+
if (options.thread) {
|
|
309
|
+
return api.comment(id, z.uuid().parse(options.thread), {
|
|
310
|
+
...body,
|
|
311
|
+
body: text,
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
return api.discuss(id, {
|
|
315
|
+
...body,
|
|
316
|
+
body: text,
|
|
317
|
+
path: options.path,
|
|
318
|
+
side: options.side,
|
|
319
|
+
startLine: options.startLine,
|
|
320
|
+
endLine: options.endLine,
|
|
321
|
+
replacement: options.replacementFile
|
|
322
|
+
? selectedText(await readFile(localPath(options.replacementFile, runtime), "utf8"))
|
|
323
|
+
: undefined,
|
|
324
|
+
expectedContent: options.expectedFile
|
|
325
|
+
? selectedText(await readFile(localPath(options.expectedFile, runtime), "utf8"), options.startLine && options.endLine
|
|
326
|
+
? options.endLine - options.startLine + 1
|
|
327
|
+
: undefined)
|
|
328
|
+
: undefined,
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
/** Creates a new revision; the author runs `barndog pull` to receive it. */
|
|
332
|
+
export async function applySuggestion(target, runtime) {
|
|
333
|
+
const { api, id, body } = await changeAtRevision(target, runtime);
|
|
334
|
+
return api.applySuggestion(id, z.uuid().parse(target.thread), body);
|
|
335
|
+
}
|
|
336
|
+
export async function setDiscussionResolved(target, runtime) {
|
|
337
|
+
const { api, id, body } = await changeAtRevision(target, runtime);
|
|
338
|
+
return api.resolve(id, z.uuid().parse(target.thread), {
|
|
339
|
+
...body,
|
|
340
|
+
resolved: target.resolved,
|
|
341
|
+
});
|
|
254
342
|
}
|