@beyondwork/wb-cli 0.1.21 → 0.1.22
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/out/extension.js +239 -125
- package/out/types.js +3 -0
- package/package.json +15 -1
package/out/extension.js
CHANGED
|
@@ -52,16 +52,18 @@ let diagnosticCollection;
|
|
|
52
52
|
let outputChannel;
|
|
53
53
|
let streamsByDir;
|
|
54
54
|
let hostsByStream;
|
|
55
|
+
let branchKeysByStream;
|
|
56
|
+
let streamsByBranchKey;
|
|
55
57
|
let syncStreams;
|
|
56
|
-
let streamsByHost;
|
|
57
58
|
let latestWorkblocks;
|
|
59
|
+
let currentUsersByHost;
|
|
58
60
|
let outputLogger;
|
|
59
|
-
async function onWorkblockChange(
|
|
60
|
-
console.log("onWorkblockChange",
|
|
61
|
+
async function onWorkblockChange(key, workblock, treeDataProvider) {
|
|
62
|
+
console.log("onWorkblockChange", key, workblock?.state);
|
|
61
63
|
if (!workblock) {
|
|
62
64
|
return;
|
|
63
65
|
}
|
|
64
|
-
const dir = streamsByDir[
|
|
66
|
+
const dir = streamsByDir[key];
|
|
65
67
|
if (!dir) {
|
|
66
68
|
return;
|
|
67
69
|
}
|
|
@@ -71,7 +73,98 @@ async function onWorkblockChange(streamId, workblock, treeDataProvider, host) {
|
|
|
71
73
|
}
|
|
72
74
|
const uWb = (0, lib_1.trimWorkblock)(workblock);
|
|
73
75
|
const uLocalWb = (0, lib_1.trimWorkblock)(localWb);
|
|
74
|
-
treeDataProvider.setSyncStatus(
|
|
76
|
+
treeDataProvider.setSyncStatus(key, JSON.stringify(uWb) !== JSON.stringify(uLocalWb));
|
|
77
|
+
}
|
|
78
|
+
function parseBranchKey(key) {
|
|
79
|
+
const [host, workblockId, branch] = key.split("|").map(decodeURIComponent);
|
|
80
|
+
if (!host || !workblockId || !branch) {
|
|
81
|
+
throw new Error(`Invalid branch binding key: ${key}`);
|
|
82
|
+
}
|
|
83
|
+
return { host, workblockId, branch };
|
|
84
|
+
}
|
|
85
|
+
async function refreshWorkblocksForHost(host, client, treeDataProvider, currentUserId) {
|
|
86
|
+
const workblocks = await client.listWorkblockDefinitions();
|
|
87
|
+
const branchesByWorkblock = {};
|
|
88
|
+
for (const workblock of workblocks) {
|
|
89
|
+
branchesByWorkblock[workblock.id] = workblock.branches ?? [];
|
|
90
|
+
}
|
|
91
|
+
const involvedWorkblocks = workblocks.filter((workblock) => {
|
|
92
|
+
if (workblock.user_id === currentUserId || workblock.branch_user === currentUserId) {
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
return userBranchesFor(branchesByWorkblock[workblock.id] ?? [], currentUserId).length > 0;
|
|
96
|
+
});
|
|
97
|
+
treeDataProvider.setWorkblocksForHost(host, involvedWorkblocks);
|
|
98
|
+
for (const workblock of involvedWorkblocks) {
|
|
99
|
+
const ownsWorkblock = workblock.user_id === currentUserId || workblock.branch_user === currentUserId;
|
|
100
|
+
const branches = filterBranchesForUser(branchesByWorkblock[workblock.id] ?? [], currentUserId, ownsWorkblock);
|
|
101
|
+
treeDataProvider.setBranchesForWorkblock(host, workblock.id, branches, false, false);
|
|
102
|
+
}
|
|
103
|
+
treeDataProvider.refresh();
|
|
104
|
+
}
|
|
105
|
+
function filterBranchesForUser(branches, currentUserId, ownsWorkblock) {
|
|
106
|
+
const visibleBranches = (0, tree_data_provider_1.filterVisibleBranches)(branches);
|
|
107
|
+
const userBranches = neuiUserBranchesFor(branches, currentUserId);
|
|
108
|
+
if (userBranches.length > 0) {
|
|
109
|
+
return userBranches;
|
|
110
|
+
}
|
|
111
|
+
return ownsWorkblock ? visibleBranches.filter((branch) => branch.name === "main") : [];
|
|
112
|
+
}
|
|
113
|
+
function userBranchesFor(branches, currentUserId) {
|
|
114
|
+
return branches
|
|
115
|
+
.filter((branch) => branch.name.startsWith("features/") || branch.name.startsWith("users/"))
|
|
116
|
+
.filter((branch) => !branch.name.includes("@thread/"))
|
|
117
|
+
.filter((branch) => branchOwnerId(branch) === currentUserId);
|
|
118
|
+
}
|
|
119
|
+
function neuiUserBranchesFor(branches, currentUserId) {
|
|
120
|
+
const featureBranches = new Set(branches
|
|
121
|
+
.filter((branch) => branch.name.startsWith("features/"))
|
|
122
|
+
.filter((branch) => !branch.name.includes("@thread/"))
|
|
123
|
+
.filter((branch) => !branchOwnerId(branch))
|
|
124
|
+
.map((branch) => getFeatureRef(branch.name)));
|
|
125
|
+
return branches
|
|
126
|
+
.filter((branch) => branch.name.startsWith("features/"))
|
|
127
|
+
.filter((branch) => !branch.name.includes("@thread/"))
|
|
128
|
+
.filter((branch) => branchOwnerId(branch) === currentUserId)
|
|
129
|
+
.filter((branch) => featureBranches.has(getFeatureRef(branch.name)));
|
|
130
|
+
}
|
|
131
|
+
function getFeatureRef(branchName) {
|
|
132
|
+
const withoutThread = branchName.replace(/@thread\/[0-9a-f-]+$/, "");
|
|
133
|
+
const userBranchIdx = withoutThread.lastIndexOf("@users/");
|
|
134
|
+
if (userBranchIdx !== -1) {
|
|
135
|
+
return withoutThread.slice(0, userBranchIdx);
|
|
136
|
+
}
|
|
137
|
+
return withoutThread;
|
|
138
|
+
}
|
|
139
|
+
function branchOwnerId(branch) {
|
|
140
|
+
const withoutThread = branch.name.replace(/@thread\/[0-9a-f-]+$/, "");
|
|
141
|
+
const userBranchIdx = withoutThread.lastIndexOf("@users/");
|
|
142
|
+
if (userBranchIdx !== -1) {
|
|
143
|
+
return withoutThread.slice(userBranchIdx + "@users/".length);
|
|
144
|
+
}
|
|
145
|
+
if (withoutThread.startsWith("users/")) {
|
|
146
|
+
return withoutThread.slice("users/".length);
|
|
147
|
+
}
|
|
148
|
+
if (branch.owner_id && branch.owner_id !== "00000000-0000-0000-0000-000000000000") {
|
|
149
|
+
return branch.owner_id;
|
|
150
|
+
}
|
|
151
|
+
return undefined;
|
|
152
|
+
}
|
|
153
|
+
async function resolveBranchStream(host, workblockId, branch) {
|
|
154
|
+
const client = clientsByHost[host];
|
|
155
|
+
if (!client) {
|
|
156
|
+
throw new Error(`Not connected to ${host}`);
|
|
157
|
+
}
|
|
158
|
+
const stream = await client.getEditStream(workblockId);
|
|
159
|
+
await client.switchStreamBranch(stream.id, branch);
|
|
160
|
+
const key = (0, tree_data_provider_1.branchKey)(host, workblockId, branch);
|
|
161
|
+
hostsByStream[stream.id] = host;
|
|
162
|
+
branchKeysByStream[stream.id] = key;
|
|
163
|
+
streamsByBranchKey[key] = stream.id;
|
|
164
|
+
return stream;
|
|
165
|
+
}
|
|
166
|
+
async function resolveBranchItemStream(item) {
|
|
167
|
+
return resolveBranchStream(item.connection.host, item.workblock.id, item.branch.name);
|
|
75
168
|
}
|
|
76
169
|
async function connectToHost(host, context, treeDataProvider) {
|
|
77
170
|
if (clientsByHost[host]) {
|
|
@@ -83,63 +176,74 @@ async function connectToHost(host, context, treeDataProvider) {
|
|
|
83
176
|
throw new Error(`Failed to retrieve token for ${host}.`);
|
|
84
177
|
}
|
|
85
178
|
const newClient = new client_1.BeyondWorkClient();
|
|
179
|
+
newClient.addCurrentUserHandler((user) => {
|
|
180
|
+
currentUsersByHost[host] = user;
|
|
181
|
+
refreshWorkblocksForHost(host, newClient, treeDataProvider, user.id)
|
|
182
|
+
.then(() => autoBindBranches(host, context, treeDataProvider))
|
|
183
|
+
.catch((e) => {
|
|
184
|
+
outputChannel.appendLine(`${e}`);
|
|
185
|
+
vscode.window.showErrorMessage(`Beyond Work: ${e}`);
|
|
186
|
+
});
|
|
187
|
+
});
|
|
86
188
|
newClient.addStreamHandler(async (message) => {
|
|
87
|
-
treeDataProvider.setStreamsForHost(host, message);
|
|
88
189
|
treeDataProvider.updateConnectionStatus(host, "connected");
|
|
89
|
-
streamsByHost[host] = message;
|
|
90
|
-
hostsByStream = {};
|
|
91
190
|
for (const stream of message) {
|
|
92
191
|
hostsByStream[stream.id] = host;
|
|
93
192
|
}
|
|
94
193
|
try {
|
|
95
|
-
|
|
96
|
-
|
|
194
|
+
const currentUser = currentUsersByHost[host];
|
|
195
|
+
if (!currentUser) {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
await refreshWorkblocksForHost(host, newClient, treeDataProvider, currentUser.id);
|
|
199
|
+
await autoBindBranches(host, context, treeDataProvider);
|
|
97
200
|
}
|
|
98
201
|
catch (e) {
|
|
99
202
|
outputChannel.appendLine(`${e}`);
|
|
100
203
|
vscode.window.showErrorMessage(`Beyond Work: ${e}`);
|
|
101
204
|
}
|
|
102
|
-
Promise.all(message.map(async (stream) => {
|
|
103
|
-
return await newClient.getWorkblock(stream.id);
|
|
104
|
-
}))
|
|
105
|
-
.then((workblocks) => {
|
|
106
|
-
workblocks.map((wb, idx) => {
|
|
107
|
-
onWorkblockChange(message[idx].id, wb, treeDataProvider, host);
|
|
108
|
-
if (wb) {
|
|
109
|
-
latestWorkblocks[host + message[idx].id] = wb;
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
console.log("got workblocks", workblocks);
|
|
113
|
-
})
|
|
114
|
-
.catch((e) => {
|
|
115
|
-
const msg = e?.message ?? String(e);
|
|
116
|
-
outputChannel.appendLine(`[connect] Failed to prefetch workblocks: ${msg}`);
|
|
117
|
-
});
|
|
118
205
|
});
|
|
119
206
|
newClient.addEventHandler(async (message) => {
|
|
120
207
|
for (const msg of message) {
|
|
121
208
|
if (msg.type == "workblock") {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
209
|
+
const streamId = msg.stream_id;
|
|
210
|
+
let key = streamId ? branchKeysByStream[streamId] : undefined;
|
|
211
|
+
if (!key && msg.work_block?.workblock_id && msg.work_block?.branch) {
|
|
212
|
+
key = (0, tree_data_provider_1.branchKey)(host, msg.work_block.workblock_id, msg.work_block.branch);
|
|
213
|
+
}
|
|
214
|
+
if (!key) {
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
let workblock = msg.work_block?.work_block;
|
|
218
|
+
if (!workblock &&
|
|
219
|
+
streamId &&
|
|
220
|
+
msg.work_block?.workblock_id &&
|
|
221
|
+
msg.work_block?.commit_ref) {
|
|
222
|
+
try {
|
|
223
|
+
workblock = await newClient.getWorkblock(streamId);
|
|
224
|
+
}
|
|
225
|
+
catch (e) {
|
|
226
|
+
const err = e?.message ?? String(e);
|
|
227
|
+
outputChannel.appendLine(`[events] Failed to resolve workblock for ${streamId}: ${err}`);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
if (syncStreams[key] !== undefined && workblock) {
|
|
231
|
+
await (0, lib_1.storeWorkblockFiles)(syncStreams[key], workblock, newClient);
|
|
232
|
+
}
|
|
233
|
+
await onWorkblockChange(key, workblock, treeDataProvider);
|
|
234
|
+
if (workblock) {
|
|
235
|
+
latestWorkblocks[key] = workblock;
|
|
125
236
|
}
|
|
126
|
-
await onWorkblockChange(msg.stream_id, msg.work_block?.work_block, treeDataProvider, host);
|
|
127
|
-
latestWorkblocks[host + msg.stream_id] = msg.work_block?.work_block;
|
|
128
237
|
}
|
|
129
238
|
if (msg.type == "stream") {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
id: msg.stream?.stream?.id,
|
|
134
|
-
editing: msg.stream?.stream?.editing,
|
|
135
|
-
title: msg.stream?.stream?.title,
|
|
136
|
-
});
|
|
239
|
+
const stream = msg.stream?.stream;
|
|
240
|
+
if (stream?.id) {
|
|
241
|
+
hostsByStream[stream.id] = host;
|
|
137
242
|
}
|
|
138
|
-
|
|
139
|
-
|
|
243
|
+
const currentUser = currentUsersByHost[host];
|
|
244
|
+
if (currentUser) {
|
|
245
|
+
await refreshWorkblocksForHost(host, newClient, treeDataProvider, currentUser.id);
|
|
140
246
|
}
|
|
141
|
-
streamsByHost[host] = streamsByHost[host].sort((a, b) => a.title.localeCompare(b.title));
|
|
142
|
-
treeDataProvider.setStreamsForHost(host, streamsByHost[host]);
|
|
143
247
|
}
|
|
144
248
|
}
|
|
145
249
|
});
|
|
@@ -163,8 +267,10 @@ function activate(context) {
|
|
|
163
267
|
streamsByDir = context.globalState.get("bw_streams_dir") ?? {};
|
|
164
268
|
syncStreams = context.globalState.get("bw_sync_streams") ?? {};
|
|
165
269
|
hostsByStream = {};
|
|
166
|
-
|
|
270
|
+
branchKeysByStream = {};
|
|
271
|
+
streamsByBranchKey = {};
|
|
167
272
|
latestWorkblocks = {};
|
|
273
|
+
currentUsersByHost = {};
|
|
168
274
|
const treeDataProvider = new tree_data_provider_1.BeyondWorkTreeDataProvider(context, streamsByDir, syncStreams);
|
|
169
275
|
const treeView = vscode.window.createTreeView("beyondworkConnections", {
|
|
170
276
|
treeDataProvider: treeDataProvider,
|
|
@@ -178,19 +284,26 @@ function activate(context) {
|
|
|
178
284
|
if (ignorePatterns.some((pattern) => uri.path.includes(pattern))) {
|
|
179
285
|
return;
|
|
180
286
|
}
|
|
181
|
-
for (const [
|
|
287
|
+
for (const [key, dir] of Object.entries(streamsByDir)) {
|
|
288
|
+
if (!key.includes("|")) {
|
|
289
|
+
continue;
|
|
290
|
+
}
|
|
182
291
|
if (uri.fsPath.startsWith(dir)) {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
if (syncStreams[
|
|
186
|
-
await
|
|
187
|
-
|
|
292
|
+
try {
|
|
293
|
+
const { host, workblockId, branch } = parseBranchKey(key);
|
|
294
|
+
if (syncStreams[key] !== undefined && sync) {
|
|
295
|
+
const stream = await resolveBranchStream(host, workblockId, branch);
|
|
296
|
+
await setWorkblock(dir, host, stream.id).then(() => {
|
|
297
|
+
treeDataProvider.setSyncStatus(key, false);
|
|
188
298
|
});
|
|
189
299
|
}
|
|
190
300
|
else {
|
|
191
|
-
await onWorkblockChange(
|
|
301
|
+
await onWorkblockChange(key, latestWorkblocks[key], treeDataProvider);
|
|
192
302
|
}
|
|
193
303
|
}
|
|
304
|
+
catch (e) {
|
|
305
|
+
outputChannel.appendLine(`[sync] ${e?.message ?? e}`);
|
|
306
|
+
}
|
|
194
307
|
}
|
|
195
308
|
}
|
|
196
309
|
};
|
|
@@ -298,29 +411,22 @@ function activate(context) {
|
|
|
298
411
|
try {
|
|
299
412
|
const stream = await client.storeWorkblock(wb);
|
|
300
413
|
outputChannel.appendLine(`Created stream ${stream.id} (${stream.title})`);
|
|
301
|
-
// Ensure host mapping structures exist
|
|
302
|
-
if (!streamsByHost[host]) {
|
|
303
|
-
streamsByHost[host] = [];
|
|
304
|
-
}
|
|
305
414
|
hostsByStream[stream.id] = host;
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
editing: stream.editing ?? true,
|
|
311
|
-
title: stream.title ?? wb.name,
|
|
312
|
-
});
|
|
313
|
-
streamsByHost[host] = streamsByHost[host].sort((a, b) => a.title.localeCompare(b.title));
|
|
314
|
-
}
|
|
415
|
+
const branch = stream.branch ?? "main";
|
|
416
|
+
const key = (0, tree_data_provider_1.branchKey)(host, wb.id, branch);
|
|
417
|
+
branchKeysByStream[stream.id] = key;
|
|
418
|
+
streamsByBranchKey[key] = stream.id;
|
|
315
419
|
// Bind directory to stream
|
|
316
|
-
streamsByDir[
|
|
420
|
+
streamsByDir[key] = baseDir[0].fsPath;
|
|
317
421
|
context.globalState.update("bw_streams_dir", streamsByDir);
|
|
318
422
|
// Store latest workblock for change tracking
|
|
319
|
-
latestWorkblocks[
|
|
423
|
+
latestWorkblocks[key] = wb;
|
|
320
424
|
// Update tree view
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
425
|
+
const currentUser = currentUsersByHost[host];
|
|
426
|
+
if (currentUser) {
|
|
427
|
+
await refreshWorkblocksForHost(host, client, treeDataProvider, currentUser.id);
|
|
428
|
+
}
|
|
429
|
+
vscode.window.showInformationMessage(`Created and bound '${wb.name}' on ${branch}`);
|
|
324
430
|
}
|
|
325
431
|
catch (e) {
|
|
326
432
|
const msg = e?.message ?? String(e);
|
|
@@ -328,50 +434,47 @@ function activate(context) {
|
|
|
328
434
|
vscode.window.showErrorMessage(`Failed to create stream: ${msg}`);
|
|
329
435
|
}
|
|
330
436
|
});
|
|
331
|
-
const bindStream = vscode.commands.registerCommand("beyondwork.beyondwork.bindStream", async (
|
|
332
|
-
outputChannel.appendLine(`Binding
|
|
437
|
+
const bindStream = vscode.commands.registerCommand("beyondwork.beyondwork.bindStream", async (item) => {
|
|
438
|
+
outputChannel.appendLine(`Binding ${item.workblock.name} ${item.branch.name} ${item.dir}`);
|
|
333
439
|
const opts = {
|
|
334
440
|
canSelectFolders: true,
|
|
335
441
|
canSelectFiles: false,
|
|
336
442
|
canSelectMany: false,
|
|
337
443
|
openLabel: "Select folder for the workblock",
|
|
338
444
|
};
|
|
339
|
-
if (dir) {
|
|
340
|
-
opts.defaultUri = vscode.Uri.file(dir);
|
|
445
|
+
if (item.dir) {
|
|
446
|
+
opts.defaultUri = vscode.Uri.file(item.dir);
|
|
341
447
|
}
|
|
342
448
|
const baseDir = await vscode.window.showOpenDialog(opts);
|
|
343
449
|
if (!baseDir?.length) {
|
|
344
450
|
return;
|
|
345
451
|
}
|
|
346
|
-
streamsByDir[
|
|
452
|
+
streamsByDir[item.key] = baseDir[0].fsPath;
|
|
347
453
|
context.globalState.update("bw_streams_dir", streamsByDir);
|
|
348
454
|
treeDataProvider.refresh();
|
|
349
|
-
// Immediately fetch remote workblock into selected directory (enhanced behavior)
|
|
350
455
|
try {
|
|
351
|
-
const
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
outputChannel.appendLine(`No remote workblock present for ${stream.id}`);
|
|
363
|
-
}
|
|
456
|
+
const stream = await resolveBranchItemStream(item);
|
|
457
|
+
const client = clientsByHost[item.connection.host];
|
|
458
|
+
const wb = await client.getWorkblock(stream.id);
|
|
459
|
+
if (wb) {
|
|
460
|
+
await (0, lib_1.storeWorkblockFiles)(baseDir[0].fsPath, wb, client);
|
|
461
|
+
latestWorkblocks[item.key] = wb;
|
|
462
|
+
await onWorkblockChange(item.key, wb, treeDataProvider);
|
|
463
|
+
outputChannel.appendLine(`Fetched ${item.workblock.name} (${item.branch.name}) into ${baseDir[0].fsPath}`);
|
|
464
|
+
}
|
|
465
|
+
else {
|
|
466
|
+
outputChannel.appendLine(`No remote workblock present for ${item.workblock.name} (${item.branch.name})`);
|
|
364
467
|
}
|
|
365
468
|
}
|
|
366
469
|
catch (e) {
|
|
367
|
-
outputChannel.appendLine(`Failed to fetch remote workblock for ${
|
|
470
|
+
outputChannel.appendLine(`Failed to fetch remote workblock for ${item.workblock.name}: ${e?.message ?? e}`);
|
|
368
471
|
}
|
|
369
472
|
});
|
|
370
473
|
const getWB = vscode.commands.registerCommand("beyondwork.beyondwork.get", async (item) => {
|
|
371
474
|
outputChannel.show(true);
|
|
372
|
-
outputChannel.appendLine(`Getting workblock
|
|
475
|
+
outputChannel.appendLine(`Getting workblock workblockId=${item.workblock.id} branch=${item.branch.name} host=${item.connection.host}`);
|
|
373
476
|
if (!item.dir) {
|
|
374
|
-
vscode.window.showErrorMessage("Please bind a directory to the
|
|
477
|
+
vscode.window.showErrorMessage("Please bind a directory to the branch first");
|
|
375
478
|
return;
|
|
376
479
|
}
|
|
377
480
|
const dir = item.dir;
|
|
@@ -383,7 +486,7 @@ function activate(context) {
|
|
|
383
486
|
try {
|
|
384
487
|
await vscode.window.withProgress({
|
|
385
488
|
location: vscode.ProgressLocation.Notification,
|
|
386
|
-
title: `Beyond Work: Getting workblock (${item.
|
|
489
|
+
title: `Beyond Work: Getting ${item.workblock.name} (${item.branch.name})`,
|
|
387
490
|
cancellable: true,
|
|
388
491
|
}, async (_progress, token) => {
|
|
389
492
|
let cancellationSub;
|
|
@@ -391,16 +494,19 @@ function activate(context) {
|
|
|
391
494
|
cancellationSub = token.onCancellationRequested(() => reject(new Error("Cancelled")));
|
|
392
495
|
});
|
|
393
496
|
try {
|
|
497
|
+
const stream = await resolveBranchItemStream(item);
|
|
394
498
|
const wb = await Promise.race([
|
|
395
|
-
client.getWorkblock(
|
|
499
|
+
client.getWorkblock(stream.id),
|
|
396
500
|
cancellation,
|
|
397
501
|
]);
|
|
398
|
-
outputChannel.appendLine(`Got workblock
|
|
502
|
+
outputChannel.appendLine(`Got workblock ${item.workblock.id} (${item.branch.name}): ${wb ? wb.id : "none"}`);
|
|
399
503
|
if (!wb) {
|
|
400
504
|
vscode.window.showErrorMessage("No workblock in workspace");
|
|
401
505
|
return;
|
|
402
506
|
}
|
|
403
507
|
await (0, lib_1.storeWorkblockFiles)(dir, wb, client);
|
|
508
|
+
latestWorkblocks[item.key] = wb;
|
|
509
|
+
await onWorkblockChange(item.key, wb, treeDataProvider);
|
|
404
510
|
}
|
|
405
511
|
finally {
|
|
406
512
|
cancellationSub?.dispose();
|
|
@@ -409,21 +515,24 @@ function activate(context) {
|
|
|
409
515
|
}
|
|
410
516
|
catch (e) {
|
|
411
517
|
const msg = e?.message ?? String(e);
|
|
412
|
-
outputChannel.appendLine(`Failed to get workblock
|
|
518
|
+
outputChannel.appendLine(`Failed to get workblock ${item.workblock.id} (${item.branch.name}): ${msg}`);
|
|
413
519
|
vscode.window.showErrorMessage(`Failed to get workblock: ${msg}`);
|
|
414
520
|
}
|
|
415
521
|
});
|
|
416
522
|
const setWB = vscode.commands.registerCommand("beyondwork.beyondwork.set", async (item) => {
|
|
417
|
-
outputChannel.appendLine(`Setting workblock ${item.
|
|
523
|
+
outputChannel.appendLine(`Setting workblock ${item.workblock.id} (${item.branch.name})`);
|
|
418
524
|
if (!item.dir) {
|
|
419
|
-
vscode.window.showErrorMessage("Please bind a directory to the
|
|
525
|
+
vscode.window.showErrorMessage("Please bind a directory to the branch first");
|
|
420
526
|
return;
|
|
421
527
|
}
|
|
422
|
-
await
|
|
528
|
+
const stream = await resolveBranchItemStream(item);
|
|
529
|
+
await setWorkblock(item.dir, item.connection.host, stream.id);
|
|
530
|
+
treeDataProvider.setSyncStatus(item.key, false);
|
|
423
531
|
});
|
|
424
532
|
const compareChanges = async (item) => {
|
|
425
533
|
const wb = await (0, lib_1.assembleWorkblock)(item.dir, outputLogger);
|
|
426
|
-
const
|
|
534
|
+
const stream = await resolveBranchItemStream(item);
|
|
535
|
+
const stored = await clientsByHost[item.connection.host].getWorkblock(stream.id);
|
|
427
536
|
const file1 = vscode.Uri.parse("bw-manifest:local.yaml");
|
|
428
537
|
const file2 = vscode.Uri.parse("bw-manifest:stored.yaml");
|
|
429
538
|
if (wb) {
|
|
@@ -435,16 +544,16 @@ function activate(context) {
|
|
|
435
544
|
vscode.commands.executeCommand("vscode.diff", file1, file2, "Local vs stored workblock");
|
|
436
545
|
};
|
|
437
546
|
const streamOptions = vscode.commands.registerCommand("beyondwork.beyondwork.showStreamOptions", async (item) => {
|
|
438
|
-
outputChannel.appendLine(`
|
|
547
|
+
outputChannel.appendLine(`Branch options ${item.workblock.id} (${item.branch.name})`);
|
|
439
548
|
const dirOpt = item.dir
|
|
440
549
|
? `Change directory from ${item.dir}`
|
|
441
|
-
: "Choose a directory for the
|
|
550
|
+
: "Choose a directory for the branch";
|
|
442
551
|
const options = [dirOpt];
|
|
443
552
|
if (item.dir) {
|
|
444
553
|
options.push("Remove directory binding");
|
|
445
|
-
options.push("Get workblock
|
|
446
|
-
options.push("Store workblock
|
|
447
|
-
if (syncStreams[item.
|
|
554
|
+
options.push("Get workblock branch");
|
|
555
|
+
options.push("Store workblock branch");
|
|
556
|
+
if (syncStreams[item.key] === undefined) {
|
|
448
557
|
options.push("Enable sync");
|
|
449
558
|
}
|
|
450
559
|
else {
|
|
@@ -462,21 +571,21 @@ function activate(context) {
|
|
|
462
571
|
if (selection) {
|
|
463
572
|
switch (selection) {
|
|
464
573
|
case dirOpt:
|
|
465
|
-
vscode.commands.executeCommand("beyondwork.beyondwork.bindStream", item
|
|
574
|
+
vscode.commands.executeCommand("beyondwork.beyondwork.bindStream", item);
|
|
466
575
|
break;
|
|
467
|
-
case "Get workblock
|
|
576
|
+
case "Get workblock branch":
|
|
468
577
|
vscode.commands.executeCommand("beyondwork.beyondwork.get", item);
|
|
469
578
|
break;
|
|
470
|
-
case "Store workblock
|
|
579
|
+
case "Store workblock branch":
|
|
471
580
|
vscode.commands.executeCommand("beyondwork.beyondwork.set", item);
|
|
472
581
|
break;
|
|
473
582
|
case "Enable sync":
|
|
474
|
-
syncStreams[item.
|
|
583
|
+
syncStreams[item.key] = item.dir;
|
|
475
584
|
context.globalState.update("bw_sync_streams", syncStreams);
|
|
476
585
|
treeDataProvider.refresh();
|
|
477
586
|
break;
|
|
478
587
|
case "Disable sync":
|
|
479
|
-
delete syncStreams[item.
|
|
588
|
+
delete syncStreams[item.key];
|
|
480
589
|
context.globalState.update("bw_sync_streams", syncStreams);
|
|
481
590
|
treeDataProvider.refresh();
|
|
482
591
|
break;
|
|
@@ -484,8 +593,8 @@ function activate(context) {
|
|
|
484
593
|
compareChanges(item);
|
|
485
594
|
break;
|
|
486
595
|
case "Remove directory binding":
|
|
487
|
-
delete streamsByDir[item.
|
|
488
|
-
delete syncStreams[item.
|
|
596
|
+
delete streamsByDir[item.key];
|
|
597
|
+
delete syncStreams[item.key];
|
|
489
598
|
context.globalState.update("bw_streams_dir", streamsByDir);
|
|
490
599
|
treeDataProvider.refresh();
|
|
491
600
|
break;
|
|
@@ -494,11 +603,12 @@ function activate(context) {
|
|
|
494
603
|
});
|
|
495
604
|
});
|
|
496
605
|
const syncSelected = vscode.commands.registerCommand("beyondwork.beyondwork.storeSelected", async () => {
|
|
497
|
-
const items = treeView.selection.filter((item) => item.contextValue === "beyondwork.
|
|
606
|
+
const items = treeView.selection.filter((item) => item.contextValue === "beyondwork.branch");
|
|
498
607
|
for (const item of items) {
|
|
499
|
-
const
|
|
500
|
-
if (
|
|
501
|
-
await
|
|
608
|
+
const branch = item;
|
|
609
|
+
if (branch.dir) {
|
|
610
|
+
const stream = await resolveBranchItemStream(branch);
|
|
611
|
+
await setWorkblock(branch.dir, branch.connection.host, stream.id);
|
|
502
612
|
}
|
|
503
613
|
}
|
|
504
614
|
});
|
|
@@ -667,9 +777,7 @@ async function setWorkblock(dir, host, streamId) {
|
|
|
667
777
|
outputChannel.appendLine(`Set workblock ${streamId}`);
|
|
668
778
|
}
|
|
669
779
|
}
|
|
670
|
-
|
|
671
|
-
async function autoBindStreams(streams, context, treeDataProvider) {
|
|
672
|
-
// Collect all manifest.yaml files in open workspace folders
|
|
780
|
+
async function autoBindBranches(host, context, treeDataProvider) {
|
|
673
781
|
const manifestUris = await vscode.workspace.findFiles("**/manifest.yaml", "**/{node_modules,.git}/**");
|
|
674
782
|
if (!manifestUris.length) {
|
|
675
783
|
return;
|
|
@@ -695,17 +803,23 @@ async function autoBindStreams(streams, context, treeDataProvider) {
|
|
|
695
803
|
// ignore individual read errors
|
|
696
804
|
}
|
|
697
805
|
}
|
|
806
|
+
const workblocksByHost = context.globalState.get("bw_workblocks", {});
|
|
807
|
+
const branchesByWorkblock = context.globalState.get("bw_workblock_branches", {});
|
|
808
|
+
const workblocks = workblocksByHost[host] ?? [];
|
|
698
809
|
let updated = false;
|
|
699
810
|
const existingDirs = new Set(Object.values(streamsByDir));
|
|
700
|
-
for (const
|
|
701
|
-
if (
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
const
|
|
706
|
-
|
|
811
|
+
for (const workblock of workblocks) {
|
|
812
|
+
if (manifestById[workblock.id]) {
|
|
813
|
+
const candidateDir = manifestById[workblock.id];
|
|
814
|
+
const workblockBranchKey = (0, tree_data_provider_1.branchKey)(host, workblock.id, "");
|
|
815
|
+
const branches = branchesByWorkblock[workblockBranchKey] ?? workblock.branches ?? [];
|
|
816
|
+
const branch = branches.find((candidate) => candidate.name === "main") ?? branches[0];
|
|
817
|
+
if (!branch) {
|
|
818
|
+
continue;
|
|
819
|
+
}
|
|
820
|
+
const key = (0, tree_data_provider_1.branchKey)(host, workblock.id, branch.name);
|
|
707
821
|
if (!existingDirs.has(candidateDir)) {
|
|
708
|
-
streamsByDir[
|
|
822
|
+
streamsByDir[key] = candidateDir;
|
|
709
823
|
existingDirs.add(candidateDir);
|
|
710
824
|
updated = true;
|
|
711
825
|
}
|
package/out/types.js
CHANGED
|
@@ -7,10 +7,12 @@ var EventType;
|
|
|
7
7
|
EventType["StoreWorkblock"] = "store_work_block";
|
|
8
8
|
EventType["PublishWorkblock"] = "publish_workblock";
|
|
9
9
|
EventType["SetWorkblock"] = "set_work_block";
|
|
10
|
+
EventType["SetWorkblockV2"] = "set_work_block_v2";
|
|
10
11
|
EventType["BatchGetEvents"] = "batch_get_events";
|
|
11
12
|
EventType["GetEvents"] = "get_events";
|
|
12
13
|
EventType["GetWorkblock"] = "get_workblock";
|
|
13
14
|
EventType["ListWorkblockDefinitions"] = "list_workblock_definitions";
|
|
15
|
+
EventType["ListWorkblockBranches"] = "list_workblock_branches";
|
|
14
16
|
EventType["Events"] = "events";
|
|
15
17
|
EventType["SendMessage"] = "send_message";
|
|
16
18
|
EventType["Typing"] = "typing";
|
|
@@ -18,6 +20,7 @@ var EventType;
|
|
|
18
20
|
EventType["CreateStream"] = "create_stream";
|
|
19
21
|
EventType["CloseStream"] = "close_stream";
|
|
20
22
|
EventType["GetEditStream"] = "get_edit_stream";
|
|
23
|
+
EventType["SwitchStreamBranch"] = "switch_stream_branch";
|
|
21
24
|
})(EventType || (exports.EventType = EventType = {}));
|
|
22
25
|
var ActionType;
|
|
23
26
|
(function (ActionType) {
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publisher": "beyondwork",
|
|
4
4
|
"displayName": "Beyond Work",
|
|
5
5
|
"description": "Tool for interacting with Beyond Work workblocks from VS Code and CLI.",
|
|
6
|
-
"version": "0.1.
|
|
6
|
+
"version": "0.1.22",
|
|
7
7
|
"icon": "media/icon.png",
|
|
8
8
|
"engines": {
|
|
9
9
|
"vscode": "^1.94.0",
|
|
@@ -15,6 +15,20 @@
|
|
|
15
15
|
"bin": {
|
|
16
16
|
"beyondwork": "./out/cli.js"
|
|
17
17
|
},
|
|
18
|
+
"activationEvents": [
|
|
19
|
+
"onView:beyondworkConnections",
|
|
20
|
+
"onCommand:beyondwork.beyondwork.addConnection",
|
|
21
|
+
"onCommand:beyondwork.beyondwork.clearConnections",
|
|
22
|
+
"onCommand:beyondwork.beyondwork.removeConnection",
|
|
23
|
+
"onCommand:beyondwork.beyondwork.storeWorkblock",
|
|
24
|
+
"onCommand:beyondwork.beyondwork.help",
|
|
25
|
+
"onCommand:beyondwork.beyondwork.storeSelected",
|
|
26
|
+
"onCommand:beyondwork.beyondwork.connectToTenant",
|
|
27
|
+
"onCommand:beyondwork.beyondwork.bindStream",
|
|
28
|
+
"onCommand:beyondwork.beyondwork.get",
|
|
29
|
+
"onCommand:beyondwork.beyondwork.set",
|
|
30
|
+
"onCommand:beyondwork.beyondwork.showStreamOptions"
|
|
31
|
+
],
|
|
18
32
|
"files": [
|
|
19
33
|
"out/lib/**/*",
|
|
20
34
|
"out/cli.js",
|