@beyondwork/wb-cli 0.1.21 → 0.1.23

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 CHANGED
@@ -47,21 +47,24 @@ const path = __importStar(require("path"));
47
47
  const yaml_1 = require("yaml");
48
48
  const markdown_it_1 = __importDefault(require("markdown-it"));
49
49
  const lib_1 = require("./lib");
50
+ const connection_feedback_1 = require("./connection_feedback");
50
51
  const clientsByHost = {};
51
52
  let diagnosticCollection;
52
53
  let outputChannel;
53
54
  let streamsByDir;
54
55
  let hostsByStream;
56
+ let branchKeysByStream;
57
+ let streamsByBranchKey;
55
58
  let syncStreams;
56
- let streamsByHost;
57
59
  let latestWorkblocks;
60
+ let currentUsersByHost;
58
61
  let outputLogger;
59
- async function onWorkblockChange(streamId, workblock, treeDataProvider, host) {
60
- console.log("onWorkblockChange", streamId, workblock?.state);
62
+ async function onWorkblockChange(key, workblock, treeDataProvider) {
63
+ console.log("onWorkblockChange", key, workblock?.state);
61
64
  if (!workblock) {
62
65
  return;
63
66
  }
64
- const dir = streamsByDir[streamId];
67
+ const dir = streamsByDir[key];
65
68
  if (!dir) {
66
69
  return;
67
70
  }
@@ -71,7 +74,101 @@ async function onWorkblockChange(streamId, workblock, treeDataProvider, host) {
71
74
  }
72
75
  const uWb = (0, lib_1.trimWorkblock)(workblock);
73
76
  const uLocalWb = (0, lib_1.trimWorkblock)(localWb);
74
- treeDataProvider.setSyncStatus(host, streamId, JSON.stringify(uWb) !== JSON.stringify(uLocalWb));
77
+ treeDataProvider.setSyncStatus(key, JSON.stringify(uWb) !== JSON.stringify(uLocalWb));
78
+ }
79
+ function parseBranchKey(key) {
80
+ const [host, workblockId, branch] = key.split("|").map(decodeURIComponent);
81
+ if (!host || !workblockId || !branch) {
82
+ throw new Error(`Invalid branch binding key: ${key}`);
83
+ }
84
+ return { host, workblockId, branch };
85
+ }
86
+ async function refreshWorkblocksForHost(host, client, treeDataProvider, currentUserId) {
87
+ const workblocks = await client.listWorkblockDefinitions();
88
+ const branchesByWorkblock = {};
89
+ for (const workblock of workblocks) {
90
+ branchesByWorkblock[workblock.id] = workblock.branches ?? [];
91
+ }
92
+ const involvedWorkblocks = workblocks.filter((workblock) => {
93
+ if (workblock.user_id === currentUserId || workblock.branch_user === currentUserId) {
94
+ return true;
95
+ }
96
+ return userBranchesFor(branchesByWorkblock[workblock.id] ?? [], currentUserId).length > 0;
97
+ });
98
+ treeDataProvider.setWorkblocksForHost(host, involvedWorkblocks);
99
+ for (const workblock of involvedWorkblocks) {
100
+ const ownsWorkblock = workblock.user_id === currentUserId || workblock.branch_user === currentUserId;
101
+ const branches = filterBranchesForUser(branchesByWorkblock[workblock.id] ?? [], currentUserId, ownsWorkblock);
102
+ treeDataProvider.setBranchesForWorkblock(host, workblock.id, branches, false, false);
103
+ }
104
+ treeDataProvider.refresh();
105
+ }
106
+ function filterBranchesForUser(branches, currentUserId, ownsWorkblock) {
107
+ const visibleBranches = (0, tree_data_provider_1.filterVisibleBranches)(branches);
108
+ const userBranches = neuiUserBranchesFor(branches, currentUserId);
109
+ if (userBranches.length > 0) {
110
+ return userBranches;
111
+ }
112
+ return ownsWorkblock ? visibleBranches.filter((branch) => branch.name === "main") : [];
113
+ }
114
+ function userBranchesFor(branches, currentUserId) {
115
+ return branches
116
+ .filter((branch) => branch.name.startsWith("features/") || branch.name.startsWith("users/"))
117
+ .filter((branch) => !branch.name.includes("@thread/"))
118
+ .filter((branch) => branchOwnerId(branch) === currentUserId);
119
+ }
120
+ function neuiUserBranchesFor(branches, currentUserId) {
121
+ const featureBranches = new Set(branches
122
+ .filter((branch) => branch.name.startsWith("features/"))
123
+ .filter((branch) => !branch.name.includes("@thread/"))
124
+ .filter((branch) => !branchOwnerId(branch))
125
+ .map((branch) => getFeatureRef(branch.name)));
126
+ return branches
127
+ .filter((branch) => branch.name.startsWith("features/"))
128
+ .filter((branch) => !branch.name.includes("@thread/"))
129
+ .filter((branch) => branchOwnerId(branch) === currentUserId)
130
+ .filter((branch) => featureBranches.has(getFeatureRef(branch.name)));
131
+ }
132
+ function getFeatureRef(branchName) {
133
+ const withoutThread = branchName.replace(/@thread\/[0-9a-f-]+$/, "");
134
+ const userBranchIdx = withoutThread.lastIndexOf("@users/");
135
+ if (userBranchIdx !== -1) {
136
+ return withoutThread.slice(0, userBranchIdx);
137
+ }
138
+ return withoutThread;
139
+ }
140
+ function branchOwnerId(branch) {
141
+ const withoutThread = branch.name.replace(/@thread\/[0-9a-f-]+$/, "");
142
+ const userBranchIdx = withoutThread.lastIndexOf("@users/");
143
+ if (userBranchIdx !== -1) {
144
+ return withoutThread.slice(userBranchIdx + "@users/".length);
145
+ }
146
+ if (withoutThread.startsWith("users/")) {
147
+ return withoutThread.slice("users/".length);
148
+ }
149
+ if (branch.owner_id && branch.owner_id !== "00000000-0000-0000-0000-000000000000") {
150
+ return branch.owner_id;
151
+ }
152
+ return undefined;
153
+ }
154
+ async function resolveBranchStream(host, workblockId, branch, title) {
155
+ const key = (0, tree_data_provider_1.branchKey)(host, workblockId, branch);
156
+ const existingStreamId = streamsByBranchKey[key];
157
+ if (existingStreamId) {
158
+ return { id: existingStreamId };
159
+ }
160
+ const client = clientsByHost[host];
161
+ if (!client) {
162
+ throw new Error(`Not connected to ${host}`);
163
+ }
164
+ const stream = await client.createStudioWorkspace(workblockId, branch, title);
165
+ hostsByStream[stream.id] = host;
166
+ branchKeysByStream[stream.id] = key;
167
+ streamsByBranchKey[key] = stream.id;
168
+ return stream;
169
+ }
170
+ async function resolveBranchItemStream(item) {
171
+ return resolveBranchStream(item.connection.host, item.workblock.id, item.branch.name, `${item.workblock.name} (${item.branch.name})`);
75
172
  }
76
173
  async function connectToHost(host, context, treeDataProvider) {
77
174
  if (clientsByHost[host]) {
@@ -80,66 +177,81 @@ async function connectToHost(host, context, treeDataProvider) {
80
177
  }
81
178
  const token = await (0, auth_1.getApiToken)(context, host);
82
179
  if (!token) {
83
- throw new Error(`Failed to retrieve token for ${host}.`);
180
+ const msg = `Failed to retrieve token for ${host}.`;
181
+ treeDataProvider.updateConnectionStatus(host, "disconnected");
182
+ outputChannel.appendLine(`[connection] ${msg}`);
183
+ vscode.window.showErrorMessage(`Beyond Work: ${msg}`);
184
+ throw new Error(msg);
84
185
  }
85
186
  const newClient = new client_1.BeyondWorkClient();
187
+ newClient.addCurrentUserHandler((user) => {
188
+ currentUsersByHost[host] = user;
189
+ refreshWorkblocksForHost(host, newClient, treeDataProvider, user.id)
190
+ .then(() => autoBindBranches(host, context, treeDataProvider))
191
+ .catch((e) => {
192
+ outputChannel.appendLine(`${e}`);
193
+ vscode.window.showErrorMessage(`Beyond Work: ${e}`);
194
+ });
195
+ });
86
196
  newClient.addStreamHandler(async (message) => {
87
- treeDataProvider.setStreamsForHost(host, message);
88
197
  treeDataProvider.updateConnectionStatus(host, "connected");
89
- streamsByHost[host] = message;
90
- hostsByStream = {};
91
198
  for (const stream of message) {
92
199
  hostsByStream[stream.id] = host;
93
200
  }
94
201
  try {
95
- // Attempt automatic binding of streams to directories based on manifest.yaml id matches
96
- await autoBindStreams(message, context, treeDataProvider);
202
+ const currentUser = currentUsersByHost[host];
203
+ if (!currentUser) {
204
+ return;
205
+ }
206
+ await refreshWorkblocksForHost(host, newClient, treeDataProvider, currentUser.id);
207
+ await autoBindBranches(host, context, treeDataProvider);
97
208
  }
98
209
  catch (e) {
99
210
  outputChannel.appendLine(`${e}`);
100
211
  vscode.window.showErrorMessage(`Beyond Work: ${e}`);
101
212
  }
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
213
  });
119
214
  newClient.addEventHandler(async (message) => {
120
215
  for (const msg of message) {
121
216
  if (msg.type == "workblock") {
122
- if (syncStreams[msg.stream_id] !== undefined &&
123
- msg.work_block?.work_block) {
124
- await (0, lib_1.storeWorkblockFiles)(syncStreams[msg.stream_id], msg.work_block?.work_block, newClient);
217
+ const streamId = msg.stream_id;
218
+ let key = streamId ? branchKeysByStream[streamId] : undefined;
219
+ if (!key && msg.work_block?.workblock_id && msg.work_block?.branch) {
220
+ key = (0, tree_data_provider_1.branchKey)(host, msg.work_block.workblock_id, msg.work_block.branch);
221
+ }
222
+ if (!key) {
223
+ continue;
224
+ }
225
+ let workblock = msg.work_block?.work_block;
226
+ if (!workblock &&
227
+ streamId &&
228
+ msg.work_block?.workblock_id &&
229
+ msg.work_block?.commit_ref) {
230
+ try {
231
+ workblock = await newClient.getWorkblock(streamId);
232
+ }
233
+ catch (e) {
234
+ const err = e?.message ?? String(e);
235
+ outputChannel.appendLine(`[events] Failed to resolve workblock for ${streamId}: ${err}`);
236
+ }
237
+ }
238
+ if (syncStreams[key] !== undefined && workblock) {
239
+ await (0, lib_1.storeWorkblockFiles)(syncStreams[key], workblock, newClient);
240
+ }
241
+ await onWorkblockChange(key, workblock, treeDataProvider);
242
+ if (workblock) {
243
+ latestWorkblocks[key] = workblock;
125
244
  }
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
245
  }
129
246
  if (msg.type == "stream") {
130
- if (msg.stream?.stream?.editing) {
131
- hostsByStream[msg.stream?.stream?.id] = host;
132
- streamsByHost[host].push({
133
- id: msg.stream?.stream?.id,
134
- editing: msg.stream?.stream?.editing,
135
- title: msg.stream?.stream?.title,
136
- });
247
+ const stream = msg.stream?.stream;
248
+ if (stream?.id) {
249
+ hostsByStream[stream.id] = host;
137
250
  }
138
- else {
139
- streamsByHost[host] = streamsByHost[host].filter((s) => s.id !== msg.stream?.stream?.id);
251
+ const currentUser = currentUsersByHost[host];
252
+ if (currentUser) {
253
+ await refreshWorkblocksForHost(host, newClient, treeDataProvider, currentUser.id);
140
254
  }
141
- streamsByHost[host] = streamsByHost[host].sort((a, b) => a.title.localeCompare(b.title));
142
- treeDataProvider.setStreamsForHost(host, streamsByHost[host]);
143
255
  }
144
256
  }
145
257
  });
@@ -150,8 +262,20 @@ async function connectToHost(host, context, treeDataProvider) {
150
262
  outputChannel.appendLine(`[ws] ${msg}`);
151
263
  vscode.window.showErrorMessage(`Beyond Work: ${msg}`);
152
264
  });
153
- newClient.connect(host, token, context);
154
- clientsByHost[host] = newClient;
265
+ newClient.addConnectionErrorHandler((err) => {
266
+ (0, connection_feedback_1.showConnectionError)(host, treeDataProvider, outputChannel, err);
267
+ });
268
+ try {
269
+ newClient.connect(host, token, context);
270
+ clientsByHost[host] = newClient;
271
+ }
272
+ catch (e) {
273
+ treeDataProvider.updateConnectionStatus(host, "disconnected");
274
+ const msg = e?.message ?? String(e);
275
+ outputChannel.appendLine(`[connection] Failed to connect to ${host}: ${msg}`);
276
+ vscode.window.showErrorMessage(`Beyond Work: Failed to connect to ${host}: ${msg}`);
277
+ throw e;
278
+ }
155
279
  context.globalState.update("bw_current_connection", host);
156
280
  return newClient;
157
281
  }
@@ -163,8 +287,10 @@ function activate(context) {
163
287
  streamsByDir = context.globalState.get("bw_streams_dir") ?? {};
164
288
  syncStreams = context.globalState.get("bw_sync_streams") ?? {};
165
289
  hostsByStream = {};
166
- streamsByHost = {};
290
+ branchKeysByStream = {};
291
+ streamsByBranchKey = {};
167
292
  latestWorkblocks = {};
293
+ currentUsersByHost = {};
168
294
  const treeDataProvider = new tree_data_provider_1.BeyondWorkTreeDataProvider(context, streamsByDir, syncStreams);
169
295
  const treeView = vscode.window.createTreeView("beyondworkConnections", {
170
296
  treeDataProvider: treeDataProvider,
@@ -178,19 +304,26 @@ function activate(context) {
178
304
  if (ignorePatterns.some((pattern) => uri.path.includes(pattern))) {
179
305
  return;
180
306
  }
181
- for (const [streamId, dir] of Object.entries(streamsByDir)) {
307
+ for (const [key, dir] of Object.entries(streamsByDir)) {
308
+ if (!key.includes("|")) {
309
+ continue;
310
+ }
182
311
  if (uri.fsPath.startsWith(dir)) {
183
- const host = hostsByStream[streamId];
184
- if (host) {
185
- if (syncStreams[streamId] !== undefined && sync) {
186
- await setWorkblock(dir, host, streamId).then(() => {
187
- treeDataProvider.setSyncStatus(host, streamId, false);
312
+ try {
313
+ const { host, workblockId, branch } = parseBranchKey(key);
314
+ if (syncStreams[key] !== undefined && sync) {
315
+ const stream = await resolveBranchStream(host, workblockId, branch);
316
+ await setWorkblock(dir, host, stream.id).then(() => {
317
+ treeDataProvider.setSyncStatus(key, false);
188
318
  });
189
319
  }
190
320
  else {
191
- await onWorkblockChange(streamId, latestWorkblocks[host + streamId], treeDataProvider, host);
321
+ await onWorkblockChange(key, latestWorkblocks[key], treeDataProvider);
192
322
  }
193
323
  }
324
+ catch (e) {
325
+ outputChannel.appendLine(`[sync] ${e?.message ?? e}`);
326
+ }
194
327
  }
195
328
  }
196
329
  };
@@ -298,29 +431,22 @@ function activate(context) {
298
431
  try {
299
432
  const stream = await client.storeWorkblock(wb);
300
433
  outputChannel.appendLine(`Created stream ${stream.id} (${stream.title})`);
301
- // Ensure host mapping structures exist
302
- if (!streamsByHost[host]) {
303
- streamsByHost[host] = [];
304
- }
305
434
  hostsByStream[stream.id] = host;
306
- // Insert new stream into list if not present
307
- if (!streamsByHost[host].some((s) => s.id === stream.id)) {
308
- streamsByHost[host].push({
309
- id: stream.id,
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
- }
435
+ const branch = stream.branch ?? "main";
436
+ const key = (0, tree_data_provider_1.branchKey)(host, wb.id, branch);
437
+ branchKeysByStream[stream.id] = key;
438
+ streamsByBranchKey[key] = stream.id;
315
439
  // Bind directory to stream
316
- streamsByDir[stream.id] = baseDir[0].fsPath;
440
+ streamsByDir[key] = baseDir[0].fsPath;
317
441
  context.globalState.update("bw_streams_dir", streamsByDir);
318
442
  // Store latest workblock for change tracking
319
- latestWorkblocks[host + stream.id] = wb;
443
+ latestWorkblocks[key] = wb;
320
444
  // Update tree view
321
- treeDataProvider.setStreamsForHost(host, streamsByHost[host]);
322
- treeDataProvider.refresh();
323
- vscode.window.showInformationMessage(`Created and bound new stream '${stream.title}'`);
445
+ const currentUser = currentUsersByHost[host];
446
+ if (currentUser) {
447
+ await refreshWorkblocksForHost(host, client, treeDataProvider, currentUser.id);
448
+ }
449
+ vscode.window.showInformationMessage(`Created and bound '${wb.name}' on ${branch}`);
324
450
  }
325
451
  catch (e) {
326
452
  const msg = e?.message ?? String(e);
@@ -328,50 +454,47 @@ function activate(context) {
328
454
  vscode.window.showErrorMessage(`Failed to create stream: ${msg}`);
329
455
  }
330
456
  });
331
- const bindStream = vscode.commands.registerCommand("beyondwork.beyondwork.bindStream", async (stream, dir) => {
332
- outputChannel.appendLine(`Binding stream ${stream.id} ${dir}`);
457
+ const bindStream = vscode.commands.registerCommand("beyondwork.beyondwork.bindStream", async (item) => {
458
+ outputChannel.appendLine(`Binding ${item.workblock.name} ${item.branch.name} ${item.dir}`);
333
459
  const opts = {
334
460
  canSelectFolders: true,
335
461
  canSelectFiles: false,
336
462
  canSelectMany: false,
337
463
  openLabel: "Select folder for the workblock",
338
464
  };
339
- if (dir) {
340
- opts.defaultUri = vscode.Uri.file(dir);
465
+ if (item.dir) {
466
+ opts.defaultUri = vscode.Uri.file(item.dir);
341
467
  }
342
468
  const baseDir = await vscode.window.showOpenDialog(opts);
343
469
  if (!baseDir?.length) {
344
470
  return;
345
471
  }
346
- streamsByDir[stream.id] = baseDir[0].fsPath;
472
+ streamsByDir[item.key] = baseDir[0].fsPath;
347
473
  context.globalState.update("bw_streams_dir", streamsByDir);
348
474
  treeDataProvider.refresh();
349
- // Immediately fetch remote workblock into selected directory (enhanced behavior)
350
475
  try {
351
- const host = hostsByStream[stream.id];
352
- if (host) {
353
- const client = clientsByHost[host];
354
- const wb = await client.getWorkblock(stream.id);
355
- if (wb) {
356
- await (0, lib_1.storeWorkblockFiles)(baseDir[0].fsPath, wb, client);
357
- latestWorkblocks[host + stream.id] = wb;
358
- await onWorkblockChange(stream.id, wb, treeDataProvider, host);
359
- outputChannel.appendLine(`Fetched remote workblock for ${stream.id} into ${baseDir[0].fsPath}`);
360
- }
361
- else {
362
- outputChannel.appendLine(`No remote workblock present for ${stream.id}`);
363
- }
476
+ const stream = await resolveBranchItemStream(item);
477
+ const client = clientsByHost[item.connection.host];
478
+ const wb = await client.getWorkblock(stream.id);
479
+ if (wb) {
480
+ await (0, lib_1.storeWorkblockFiles)(baseDir[0].fsPath, wb, client);
481
+ latestWorkblocks[item.key] = wb;
482
+ await onWorkblockChange(item.key, wb, treeDataProvider);
483
+ outputChannel.appendLine(`Fetched ${item.workblock.name} (${item.branch.name}) into ${baseDir[0].fsPath}`);
484
+ }
485
+ else {
486
+ outputChannel.appendLine(`No remote workblock present for ${item.workblock.name} (${item.branch.name})`);
364
487
  }
365
488
  }
366
489
  catch (e) {
367
- outputChannel.appendLine(`Failed to fetch remote workblock for ${stream.id}: ${e?.message ?? e}`);
490
+ outputChannel.appendLine(`Failed to fetch remote workblock for ${item.workblock.name}: ${e?.message ?? e}`);
368
491
  }
369
492
  });
370
493
  const getWB = vscode.commands.registerCommand("beyondwork.beyondwork.get", async (item) => {
371
494
  outputChannel.show(true);
372
- outputChannel.appendLine(`Getting workblock streamId=${item.stream.id} host=${item.connection.host}`);
495
+ outputChannel.appendLine(`Getting workblock workblockId=${item.workblock.id} branch=${item.branch.name} host=${item.connection.host}`);
373
496
  if (!item.dir) {
374
- vscode.window.showErrorMessage("Please bind a directory to the stream first");
497
+ vscode.window.showErrorMessage("Please bind a directory to the branch first");
375
498
  return;
376
499
  }
377
500
  const dir = item.dir;
@@ -383,7 +506,7 @@ function activate(context) {
383
506
  try {
384
507
  await vscode.window.withProgress({
385
508
  location: vscode.ProgressLocation.Notification,
386
- title: `Beyond Work: Getting workblock (${item.stream.title})`,
509
+ title: `Beyond Work: Getting ${item.workblock.name} (${item.branch.name})`,
387
510
  cancellable: true,
388
511
  }, async (_progress, token) => {
389
512
  let cancellationSub;
@@ -391,16 +514,19 @@ function activate(context) {
391
514
  cancellationSub = token.onCancellationRequested(() => reject(new Error("Cancelled")));
392
515
  });
393
516
  try {
517
+ const stream = await resolveBranchItemStream(item);
394
518
  const wb = await Promise.race([
395
- client.getWorkblock(item.stream.id),
519
+ client.getWorkblock(stream.id),
396
520
  cancellation,
397
521
  ]);
398
- outputChannel.appendLine(`Got workblock streamId=${item.stream.id}: ${wb ? wb.id : "none"}`);
522
+ outputChannel.appendLine(`Got workblock ${item.workblock.id} (${item.branch.name}): ${wb ? wb.id : "none"}`);
399
523
  if (!wb) {
400
524
  vscode.window.showErrorMessage("No workblock in workspace");
401
525
  return;
402
526
  }
403
527
  await (0, lib_1.storeWorkblockFiles)(dir, wb, client);
528
+ latestWorkblocks[item.key] = wb;
529
+ await onWorkblockChange(item.key, wb, treeDataProvider);
404
530
  }
405
531
  finally {
406
532
  cancellationSub?.dispose();
@@ -409,21 +535,24 @@ function activate(context) {
409
535
  }
410
536
  catch (e) {
411
537
  const msg = e?.message ?? String(e);
412
- outputChannel.appendLine(`Failed to get workblock streamId=${item.stream.id}: ${msg}`);
538
+ outputChannel.appendLine(`Failed to get workblock ${item.workblock.id} (${item.branch.name}): ${msg}`);
413
539
  vscode.window.showErrorMessage(`Failed to get workblock: ${msg}`);
414
540
  }
415
541
  });
416
542
  const setWB = vscode.commands.registerCommand("beyondwork.beyondwork.set", async (item) => {
417
- outputChannel.appendLine(`Setting workblock ${item.stream}`);
543
+ outputChannel.appendLine(`Setting workblock ${item.workblock.id} (${item.branch.name})`);
418
544
  if (!item.dir) {
419
- vscode.window.showErrorMessage("Please bind a directory to the stream first");
545
+ vscode.window.showErrorMessage("Please bind a directory to the branch first");
420
546
  return;
421
547
  }
422
- await setWorkblock(item.dir, item.connection.host, item.stream.id);
548
+ const stream = await resolveBranchItemStream(item);
549
+ await setWorkblock(item.dir, item.connection.host, stream.id);
550
+ treeDataProvider.setSyncStatus(item.key, false);
423
551
  });
424
552
  const compareChanges = async (item) => {
425
553
  const wb = await (0, lib_1.assembleWorkblock)(item.dir, outputLogger);
426
- const stored = await clientsByHost[item.connection.host].getWorkblock(item.stream.id);
554
+ const stream = await resolveBranchItemStream(item);
555
+ const stored = await clientsByHost[item.connection.host].getWorkblock(stream.id);
427
556
  const file1 = vscode.Uri.parse("bw-manifest:local.yaml");
428
557
  const file2 = vscode.Uri.parse("bw-manifest:stored.yaml");
429
558
  if (wb) {
@@ -435,16 +564,16 @@ function activate(context) {
435
564
  vscode.commands.executeCommand("vscode.diff", file1, file2, "Local vs stored workblock");
436
565
  };
437
566
  const streamOptions = vscode.commands.registerCommand("beyondwork.beyondwork.showStreamOptions", async (item) => {
438
- outputChannel.appendLine(`Stream options ${item}`);
567
+ outputChannel.appendLine(`Branch options ${item.workblock.id} (${item.branch.name})`);
439
568
  const dirOpt = item.dir
440
569
  ? `Change directory from ${item.dir}`
441
- : "Choose a directory for the workspace";
570
+ : "Choose a directory for the branch";
442
571
  const options = [dirOpt];
443
572
  if (item.dir) {
444
573
  options.push("Remove directory binding");
445
- options.push("Get workblock from workspace");
446
- options.push("Store workblock to workspace");
447
- if (syncStreams[item.stream.id] === undefined) {
574
+ options.push("Get workblock branch");
575
+ options.push("Store workblock branch");
576
+ if (syncStreams[item.key] === undefined) {
448
577
  options.push("Enable sync");
449
578
  }
450
579
  else {
@@ -462,21 +591,21 @@ function activate(context) {
462
591
  if (selection) {
463
592
  switch (selection) {
464
593
  case dirOpt:
465
- vscode.commands.executeCommand("beyondwork.beyondwork.bindStream", item.stream, item.dir);
594
+ vscode.commands.executeCommand("beyondwork.beyondwork.bindStream", item);
466
595
  break;
467
- case "Get workblock from workspace":
596
+ case "Get workblock branch":
468
597
  vscode.commands.executeCommand("beyondwork.beyondwork.get", item);
469
598
  break;
470
- case "Store workblock to workspace":
599
+ case "Store workblock branch":
471
600
  vscode.commands.executeCommand("beyondwork.beyondwork.set", item);
472
601
  break;
473
602
  case "Enable sync":
474
- syncStreams[item.stream.id] = item.dir;
603
+ syncStreams[item.key] = item.dir;
475
604
  context.globalState.update("bw_sync_streams", syncStreams);
476
605
  treeDataProvider.refresh();
477
606
  break;
478
607
  case "Disable sync":
479
- delete syncStreams[item.stream.id];
608
+ delete syncStreams[item.key];
480
609
  context.globalState.update("bw_sync_streams", syncStreams);
481
610
  treeDataProvider.refresh();
482
611
  break;
@@ -484,8 +613,8 @@ function activate(context) {
484
613
  compareChanges(item);
485
614
  break;
486
615
  case "Remove directory binding":
487
- delete streamsByDir[item.stream.id];
488
- delete syncStreams[item.stream.id];
616
+ delete streamsByDir[item.key];
617
+ delete syncStreams[item.key];
489
618
  context.globalState.update("bw_streams_dir", streamsByDir);
490
619
  treeDataProvider.refresh();
491
620
  break;
@@ -494,11 +623,12 @@ function activate(context) {
494
623
  });
495
624
  });
496
625
  const syncSelected = vscode.commands.registerCommand("beyondwork.beyondwork.storeSelected", async () => {
497
- const items = treeView.selection.filter((item) => item.contextValue === "beyondwork.stream");
626
+ const items = treeView.selection.filter((item) => item.contextValue === "beyondwork.branch");
498
627
  for (const item of items) {
499
- const si = item;
500
- if (si.dir) {
501
- await setWorkblock(si.dir, si.connection.host, si.stream.id);
628
+ const branch = item;
629
+ if (branch.dir) {
630
+ const stream = await resolveBranchItemStream(branch);
631
+ await setWorkblock(branch.dir, branch.connection.host, stream.id);
502
632
  }
503
633
  }
504
634
  });
@@ -571,7 +701,9 @@ Base dir/
571
701
  let prevHost = context.globalState.get("bw_current_connection", "");
572
702
  if (prevHost) {
573
703
  treeDataProvider.updateConnectionStatus(prevHost, "connecting");
574
- connectToHost(prevHost, context, treeDataProvider).then(() => { });
704
+ connectToHost(prevHost, context, treeDataProvider).catch((e) => {
705
+ outputChannel.appendLine(`[connection] ${e?.message ?? e}`);
706
+ });
575
707
  }
576
708
  const watcher = vscode.workspace.createFileSystemWatcher("**/*");
577
709
  watcher.onDidChange(async (uri) => {
@@ -667,9 +799,7 @@ async function setWorkblock(dir, host, streamId) {
667
799
  outputChannel.appendLine(`Set workblock ${streamId}`);
668
800
  }
669
801
  }
670
- // Automatically bind streams to directories by scanning for manifest.yaml files containing matching id
671
- async function autoBindStreams(streams, context, treeDataProvider) {
672
- // Collect all manifest.yaml files in open workspace folders
802
+ async function autoBindBranches(host, context, treeDataProvider) {
673
803
  const manifestUris = await vscode.workspace.findFiles("**/manifest.yaml", "**/{node_modules,.git}/**");
674
804
  if (!manifestUris.length) {
675
805
  return;
@@ -695,17 +825,23 @@ async function autoBindStreams(streams, context, treeDataProvider) {
695
825
  // ignore individual read errors
696
826
  }
697
827
  }
828
+ const workblocksByHost = context.globalState.get("bw_workblocks", {});
829
+ const branchesByWorkblock = context.globalState.get("bw_workblock_branches", {});
830
+ const workblocks = workblocksByHost[host] ?? [];
698
831
  let updated = false;
699
832
  const existingDirs = new Set(Object.values(streamsByDir));
700
- for (const s of streams) {
701
- if (!s.editing || !s.current_work_block) {
702
- continue;
703
- }
704
- if (!streamsByDir[s.id] && manifestById[s.id]) {
705
- const candidateDir = manifestById[s.current_work_block];
706
- // Skip if directory already bound to a different stream to avoid accidental collisions
833
+ for (const workblock of workblocks) {
834
+ if (manifestById[workblock.id]) {
835
+ const candidateDir = manifestById[workblock.id];
836
+ const workblockBranchKey = (0, tree_data_provider_1.branchKey)(host, workblock.id, "");
837
+ const branches = branchesByWorkblock[workblockBranchKey] ?? workblock.branches ?? [];
838
+ const branch = branches.find((candidate) => candidate.name === "main") ?? branches[0];
839
+ if (!branch) {
840
+ continue;
841
+ }
842
+ const key = (0, tree_data_provider_1.branchKey)(host, workblock.id, branch.name);
707
843
  if (!existingDirs.has(candidateDir)) {
708
- streamsByDir[s.id] = candidateDir;
844
+ streamsByDir[key] = candidateDir;
709
845
  existingDirs.add(candidateDir);
710
846
  updated = true;
711
847
  }
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["CreateStudioWorkspace"] = "create_studio_workspace";
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.21",
6
+ "version": "0.1.23",
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",