@beyondwork/wb-cli 0.1.11 → 0.1.12

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.
Files changed (2) hide show
  1. package/out/extension.js +172 -86
  2. package/package.json +1 -1
package/out/extension.js CHANGED
@@ -85,14 +85,22 @@ async function connectToHost(host, context, treeDataProvider) {
85
85
  throw new Error(`Failed to retrieve token for ${host}.`);
86
86
  }
87
87
  const newClient = new client_1.BeyondWorkClient();
88
- newClient.addStreamHandler((message) => {
88
+ newClient.addStreamHandler(async (message) => {
89
89
  treeDataProvider.setStreamsForHost(host, message);
90
- treeDataProvider.updateConnectionStatus(host, 'connected');
90
+ treeDataProvider.updateConnectionStatus(host, "connected");
91
91
  streamsByHost[host] = message;
92
92
  hostsByStream = {};
93
93
  for (const stream of message) {
94
94
  hostsByStream[stream.id] = host;
95
95
  }
96
+ try {
97
+ // Attempt automatic binding of streams to directories based on manifest.yaml id matches
98
+ await autoBindStreams(message, context, treeDataProvider);
99
+ }
100
+ catch (e) {
101
+ outputChannel.appendLine(`${e}`);
102
+ vscode.window.showErrorMessage(`Beyond Work: ${e}`);
103
+ }
96
104
  Promise.all(message.map(async (stream) => {
97
105
  return await newClient.getWorkblock(stream.id);
98
106
  })).then((workblocks) => {
@@ -108,7 +116,8 @@ async function connectToHost(host, context, treeDataProvider) {
108
116
  newClient.addEventHandler(async (message) => {
109
117
  for (const msg of message) {
110
118
  if (msg.type == "workblock") {
111
- if (syncStreams[msg.stream_id] !== undefined && msg.work_block?.work_block) {
119
+ if (syncStreams[msg.stream_id] !== undefined &&
120
+ msg.work_block?.work_block) {
112
121
  await storeWorkblockFiles(syncStreams[msg.stream_id], msg.work_block?.work_block, newClient);
113
122
  }
114
123
  await onWorkblockChange(msg.stream_id, msg.work_block?.work_block, treeDataProvider, host);
@@ -124,7 +133,7 @@ async function connectToHost(host, context, treeDataProvider) {
124
133
  });
125
134
  }
126
135
  else {
127
- streamsByHost[host] = streamsByHost[host].filter(s => s.id !== msg.stream?.stream?.id);
136
+ streamsByHost[host] = streamsByHost[host].filter((s) => s.id !== msg.stream?.stream?.id);
128
137
  }
129
138
  streamsByHost[host] = streamsByHost[host].sort((a, b) => a.title.localeCompare(b.title));
130
139
  treeDataProvider.setStreamsForHost(host, streamsByHost[host]);
@@ -132,7 +141,7 @@ async function connectToHost(host, context, treeDataProvider) {
132
141
  }
133
142
  });
134
143
  newClient.addOnDisconnect(() => {
135
- treeDataProvider.updateConnectionStatus(host, 'disconnected');
144
+ treeDataProvider.updateConnectionStatus(host, "disconnected");
136
145
  });
137
146
  newClient.addErrorHandler((msg) => {
138
147
  outputChannel.appendLine(`[ws] ${msg}`);
@@ -140,20 +149,21 @@ async function connectToHost(host, context, treeDataProvider) {
140
149
  });
141
150
  newClient.connect(host, token, context);
142
151
  clientsByHost[host] = newClient;
143
- context.globalState.update('bw_current_connection', host);
152
+ context.globalState.update("bw_current_connection", host);
144
153
  return newClient;
145
154
  }
146
155
  function activate(context) {
147
- diagnosticCollection = vscode.languages.createDiagnosticCollection('validation');
148
- outputChannel = vscode.window.createOutputChannel('Beyond Work');
156
+ diagnosticCollection =
157
+ vscode.languages.createDiagnosticCollection("validation");
158
+ outputChannel = vscode.window.createOutputChannel("Beyond Work");
149
159
  outputLogger = new lib_1.VSCodeLogger(outputChannel);
150
- streamsByDir = context.globalState.get('bw_streams_dir') ?? {};
151
- syncStreams = context.globalState.get('bw_sync_streams') ?? {};
160
+ streamsByDir = context.globalState.get("bw_streams_dir") ?? {};
161
+ syncStreams = context.globalState.get("bw_sync_streams") ?? {};
152
162
  hostsByStream = {};
153
163
  streamsByHost = {};
154
164
  latestWorkblocks = {};
155
165
  const treeDataProvider = new tree_data_provider_1.BeyondWorkTreeDataProvider(context, streamsByDir, syncStreams);
156
- const treeView = vscode.window.createTreeView('beyondworkConnections', {
166
+ const treeView = vscode.window.createTreeView("beyondworkConnections", {
157
167
  treeDataProvider: treeDataProvider,
158
168
  showCollapseAll: false,
159
169
  canSelectMany: true,
@@ -161,8 +171,8 @@ function activate(context) {
161
171
  const stringContentProvider = new StringDocumentContentProvider();
162
172
  const providerReg = vscode.workspace.registerTextDocumentContentProvider("bw-manifest", stringContentProvider);
163
173
  const onFileChange = async (uri, sync) => {
164
- const ignorePatterns = ['node_modules/', '.git/'];
165
- if (ignorePatterns.some((pattern) => uri.fsPath.includes(pattern))) {
174
+ const ignorePatterns = ["node_modules/", ".git/"];
175
+ if (ignorePatterns.some((pattern) => uri.path.includes(pattern))) {
166
176
  return;
167
177
  }
168
178
  for (const [streamId, dir] of Object.entries(streamsByDir)) {
@@ -171,7 +181,6 @@ function activate(context) {
171
181
  if (host) {
172
182
  if (syncStreams[streamId] !== undefined && sync) {
173
183
  await setWorkblock(dir, host, streamId).then(() => {
174
- ;
175
184
  treeDataProvider.setSyncStatus(host, streamId, false);
176
185
  });
177
186
  }
@@ -182,34 +191,34 @@ function activate(context) {
182
191
  }
183
192
  }
184
193
  };
185
- const addConnectionCmd = vscode.commands.registerCommand('beyondwork.beyondwork.addConnection', async () => {
194
+ const addConnectionCmd = vscode.commands.registerCommand("beyondwork.beyondwork.addConnection", async () => {
186
195
  let host = await vscode.window.showInputBox({
187
- prompt: 'Enter the hostname you want to connect to',
188
- placeHolder: 'Hostname (eg. acme.prod-eu1.bworker.ai)',
196
+ prompt: "Enter the hostname you want to connect to",
197
+ placeHolder: "Hostname (eg. acme.prod-eu1.bworker.ai)",
189
198
  validateInput: (value) => {
190
199
  try {
191
- new URL(`${value.startsWith('https://') ? '' : 'https://'}${value}`);
200
+ new URL(`${value.startsWith("https://") ? "" : "https://"}${value}`);
192
201
  return undefined; // valid
193
202
  }
194
203
  catch {
195
- return 'Please enter a valid hostname';
204
+ return "Please enter a valid hostname";
196
205
  }
197
- }
206
+ },
198
207
  });
199
208
  if (!host) {
200
209
  return;
201
210
  }
202
211
  treeDataProvider.addConnection({
203
212
  host,
204
- status: 'disconnected'
213
+ status: "disconnected",
205
214
  });
206
215
  });
207
- const connectToTenantCmd = vscode.commands.registerCommand('beyondwork.beyondwork.connectToTenant', async (tenant) => {
208
- tenant.status = 'connecting';
209
- treeDataProvider.updateConnectionStatus(tenant.host, 'connecting');
216
+ const connectToTenantCmd = vscode.commands.registerCommand("beyondwork.beyondwork.connectToTenant", async (tenant) => {
217
+ tenant.status = "connecting";
218
+ treeDataProvider.updateConnectionStatus(tenant.host, "connecting");
210
219
  await connectToHost(tenant.host, context, treeDataProvider);
211
220
  });
212
- const clearConnectionsCmd = vscode.commands.registerCommand('beyondwork.beyondwork.clearConnections', () => {
221
+ const clearConnectionsCmd = vscode.commands.registerCommand("beyondwork.beyondwork.clearConnections", () => {
213
222
  // Clear from tree, and remove all token references
214
223
  (0, auth_1.clearApiTokens)(context);
215
224
  treeDataProvider.clear();
@@ -218,9 +227,9 @@ function activate(context) {
218
227
  clientsByHost[host].disconnect();
219
228
  delete clientsByHost[host];
220
229
  }
221
- vscode.window.showInformationMessage('All connections cleared.');
230
+ vscode.window.showInformationMessage("All connections cleared.");
222
231
  });
223
- const removeConnectionCmd = vscode.commands.registerCommand('beyondwork.beyondwork.removeConnection', async (item) => {
232
+ const removeConnectionCmd = vscode.commands.registerCommand("beyondwork.beyondwork.removeConnection", async (item) => {
224
233
  let connection;
225
234
  if (item) {
226
235
  connection = item.connection;
@@ -228,16 +237,20 @@ function activate(context) {
228
237
  if (!connection) {
229
238
  const all = treeDataProvider.getConnections();
230
239
  if (all.length === 0) {
231
- vscode.window.showInformationMessage('No connections to remove.');
240
+ vscode.window.showInformationMessage("No connections to remove.");
232
241
  return;
233
242
  }
234
- const picked = await vscode.window.showQuickPick(all.map(c => ({ label: c.host, description: c.status, connection: c })), { placeHolder: 'Select a connection to remove' });
243
+ const picked = await vscode.window.showQuickPick(all.map((c) => ({
244
+ label: c.host,
245
+ description: c.status,
246
+ connection: c,
247
+ })), { placeHolder: "Select a connection to remove" });
235
248
  connection = picked?.connection;
236
249
  }
237
250
  if (!connection)
238
251
  return;
239
- const yesNo = await vscode.window.showWarningMessage(`Are you sure you want to remove the connection to ${connection.host}?`, 'Yes', 'No');
240
- if (yesNo === 'Yes') {
252
+ const yesNo = await vscode.window.showWarningMessage(`Are you sure you want to remove the connection to ${connection.host}?`, "Yes", "No");
253
+ if (yesNo === "Yes") {
241
254
  // Disconnect & remove from tree
242
255
  if (clientsByHost[connection.host]) {
243
256
  clientsByHost[connection.host].disconnect();
@@ -246,13 +259,13 @@ function activate(context) {
246
259
  treeDataProvider.removeConnection(connection);
247
260
  }
248
261
  });
249
- const bindStream = vscode.commands.registerCommand('beyondwork.beyondwork.bindStream', async (stream, dir) => {
262
+ const bindStream = vscode.commands.registerCommand("beyondwork.beyondwork.bindStream", async (stream, dir) => {
250
263
  outputChannel.appendLine(`Binding stream ${stream.id} ${dir}`);
251
264
  const opts = {
252
265
  canSelectFolders: true,
253
266
  canSelectFiles: false,
254
267
  canSelectMany: false,
255
- openLabel: 'Select folder for the workblock'
268
+ openLabel: "Select folder for the workblock",
256
269
  };
257
270
  if (dir) {
258
271
  opts.defaultUri = vscode.Uri.file(dir);
@@ -262,104 +275,126 @@ function activate(context) {
262
275
  return;
263
276
  }
264
277
  streamsByDir[stream.id] = baseDir[0].fsPath;
265
- context.globalState.update('bw_streams_dir', streamsByDir);
278
+ context.globalState.update("bw_streams_dir", streamsByDir);
266
279
  treeDataProvider.refresh();
280
+ // Immediately fetch remote workblock into selected directory (enhanced behavior)
281
+ try {
282
+ const host = hostsByStream[stream.id];
283
+ if (host) {
284
+ const client = clientsByHost[host];
285
+ const wb = await client.getWorkblock(stream.id);
286
+ if (wb) {
287
+ await storeWorkblockFiles(baseDir[0].fsPath, wb, client);
288
+ latestWorkblocks[host + stream.id] = wb;
289
+ await onWorkblockChange(stream.id, wb, treeDataProvider, host);
290
+ outputChannel.appendLine(`Fetched remote workblock for ${stream.id} into ${baseDir[0].fsPath}`);
291
+ }
292
+ else {
293
+ outputChannel.appendLine(`No remote workblock present for ${stream.id}`);
294
+ }
295
+ }
296
+ }
297
+ catch (e) {
298
+ outputChannel.appendLine(`Failed to fetch remote workblock for ${stream.id}: ${e?.message ?? e}`);
299
+ }
267
300
  });
268
- const getWB = vscode.commands.registerCommand('beyondwork.beyondwork.get', async (item) => {
301
+ const getWB = vscode.commands.registerCommand("beyondwork.beyondwork.get", async (item) => {
269
302
  outputChannel.appendLine(`Getting workblock ${item.stream}`);
270
303
  if (!item.dir) {
271
- vscode.window.showErrorMessage('Please bind a directory to the stream first');
304
+ vscode.window.showErrorMessage("Please bind a directory to the stream first");
272
305
  return;
273
306
  }
274
307
  const client = clientsByHost[item.connection.host];
275
308
  const wb = await client.getWorkblock(item.stream.id);
276
309
  outputChannel.appendLine(`Got workblock ${wb}`);
277
310
  if (!wb) {
278
- vscode.window.showErrorMessage('No workblock in workspace');
311
+ vscode.window.showErrorMessage("No workblock in workspace");
279
312
  return;
280
313
  }
281
- storeWorkblockFiles(item.dir, wb, client);
314
+ await storeWorkblockFiles(item.dir, wb, client);
282
315
  });
283
- const setWB = vscode.commands.registerCommand('beyondwork.beyondwork.set', async (item) => {
316
+ const setWB = vscode.commands.registerCommand("beyondwork.beyondwork.set", async (item) => {
284
317
  outputChannel.appendLine(`Setting workblock ${item.stream}`);
285
318
  if (!item.dir) {
286
- vscode.window.showErrorMessage('Please bind a directory to the stream first');
319
+ vscode.window.showErrorMessage("Please bind a directory to the stream first");
287
320
  return;
288
321
  }
289
- setWorkblock(item.dir, item.connection.host, item.stream.id);
322
+ await setWorkblock(item.dir, item.connection.host, item.stream.id);
290
323
  });
291
324
  const compareChanges = async (item) => {
292
325
  const wb = await (0, lib_1.assembleWorkblock)(item.dir, outputLogger);
293
326
  const stored = await clientsByHost[item.connection.host].getWorkblock(item.stream.id);
294
- const file1 = vscode.Uri.parse('bw-manifest:local.yaml');
295
- const file2 = vscode.Uri.parse('bw-manifest:stored.yaml');
327
+ const file1 = vscode.Uri.parse("bw-manifest:local.yaml");
328
+ const file2 = vscode.Uri.parse("bw-manifest:stored.yaml");
296
329
  if (wb) {
297
330
  stringContentProvider.setContent(file1, (0, yaml_1.stringify)((0, lib_1.trimWorkblock)(wb)));
298
331
  }
299
332
  if (stored) {
300
333
  stringContentProvider.setContent(file2, (0, yaml_1.stringify)((0, lib_1.trimWorkblock)(stored)));
301
334
  }
302
- vscode.commands.executeCommand('vscode.diff', file1, file2, 'Local vs stored workblock');
335
+ vscode.commands.executeCommand("vscode.diff", file1, file2, "Local vs stored workblock");
303
336
  };
304
- const streamOptions = vscode.commands.registerCommand('beyondwork.beyondwork.showStreamOptions', async (item) => {
337
+ const streamOptions = vscode.commands.registerCommand("beyondwork.beyondwork.showStreamOptions", async (item) => {
305
338
  outputChannel.appendLine(`Stream options ${item}`);
306
- const dirOpt = item.dir ? `Change directory from ${item.dir}` : 'Choose a directory for the workspace';
307
- const options = [
308
- dirOpt,
309
- ];
339
+ const dirOpt = item.dir
340
+ ? `Change directory from ${item.dir}`
341
+ : "Choose a directory for the workspace";
342
+ const options = [dirOpt];
310
343
  if (item.dir) {
311
- options.push('Remove directory binding');
312
- options.push('Get workblock from workspace');
313
- options.push('Store workblock to workspace');
344
+ options.push("Remove directory binding");
345
+ options.push("Get workblock from workspace");
346
+ options.push("Store workblock to workspace");
314
347
  if (syncStreams[item.stream.id] === undefined) {
315
- options.push('Enable sync');
348
+ options.push("Enable sync");
316
349
  }
317
350
  else {
318
- options.push('Disable sync');
351
+ options.push("Disable sync");
319
352
  }
320
353
  if (item.modified) {
321
- options.push('Compare changes');
354
+ options.push("Compare changes");
322
355
  }
323
356
  }
324
- vscode.window.showQuickPick(options, {
325
- placeHolder: 'Select an action'
326
- }).then((selection) => {
357
+ vscode.window
358
+ .showQuickPick(options, {
359
+ placeHolder: "Select an action",
360
+ })
361
+ .then((selection) => {
327
362
  if (selection) {
328
363
  switch (selection) {
329
364
  case dirOpt:
330
- vscode.commands.executeCommand('beyondwork.beyondwork.bindStream', item.stream, item.dir);
365
+ vscode.commands.executeCommand("beyondwork.beyondwork.bindStream", item.stream, item.dir);
331
366
  break;
332
- case 'Get workblock from workspace':
333
- vscode.commands.executeCommand('beyondwork.beyondwork.get', item);
367
+ case "Get workblock from workspace":
368
+ vscode.commands.executeCommand("beyondwork.beyondwork.get", item);
334
369
  break;
335
- case 'Store workblock to workspace':
336
- vscode.commands.executeCommand('beyondwork.beyondwork.set', item);
370
+ case "Store workblock to workspace":
371
+ vscode.commands.executeCommand("beyondwork.beyondwork.set", item);
337
372
  break;
338
- case 'Enable sync':
373
+ case "Enable sync":
339
374
  syncStreams[item.stream.id] = item.dir;
340
- context.globalState.update('bw_sync_streams', syncStreams);
375
+ context.globalState.update("bw_sync_streams", syncStreams);
341
376
  treeDataProvider.refresh();
342
377
  break;
343
- case 'Disable sync':
378
+ case "Disable sync":
344
379
  delete syncStreams[item.stream.id];
345
- context.globalState.update('bw_sync_streams', syncStreams);
380
+ context.globalState.update("bw_sync_streams", syncStreams);
346
381
  treeDataProvider.refresh();
347
382
  break;
348
- case 'Compare changes':
383
+ case "Compare changes":
349
384
  compareChanges(item);
350
385
  break;
351
- case 'Remove directory binding':
386
+ case "Remove directory binding":
352
387
  delete streamsByDir[item.stream.id];
353
388
  delete syncStreams[item.stream.id];
354
- context.globalState.update('bw_streams_dir', streamsByDir);
389
+ context.globalState.update("bw_streams_dir", streamsByDir);
355
390
  treeDataProvider.refresh();
356
391
  break;
357
392
  }
358
393
  }
359
394
  });
360
395
  });
361
- const syncSelected = vscode.commands.registerCommand('beyondwork.beyondwork.storeSelected', async () => {
362
- const items = treeView.selection.filter((item) => item.contextValue === 'beyondwork.stream');
396
+ const syncSelected = vscode.commands.registerCommand("beyondwork.beyondwork.storeSelected", async () => {
397
+ const items = treeView.selection.filter((item) => item.contextValue === "beyondwork.stream");
363
398
  for (const item of items) {
364
399
  const si = item;
365
400
  if (si.dir) {
@@ -367,8 +402,8 @@ function activate(context) {
367
402
  }
368
403
  }
369
404
  });
370
- const help = vscode.commands.registerCommand('beyondwork.beyondwork.help', async () => {
371
- const panel = vscode.window.createWebviewPanel('help', 'Beyond Work Help', vscode.ViewColumn.One, {
405
+ const help = vscode.commands.registerCommand("beyondwork.beyondwork.help", async () => {
406
+ const panel = vscode.window.createWebviewPanel("help", "Beyond Work Help", vscode.ViewColumn.One, {
372
407
  enableCommandUris: true,
373
408
  });
374
409
  const md = new markdown_it_1.default({
@@ -433,13 +468,12 @@ Base dir/
433
468
  </pre>
434
469
  `);
435
470
  });
436
- let prevHost = context.globalState.get('bw_current_connection', '');
471
+ let prevHost = context.globalState.get("bw_current_connection", "");
437
472
  if (prevHost) {
438
- treeDataProvider.updateConnectionStatus(prevHost, 'connecting');
439
- connectToHost(prevHost, context, treeDataProvider).then(() => {
440
- });
473
+ treeDataProvider.updateConnectionStatus(prevHost, "connecting");
474
+ connectToHost(prevHost, context, treeDataProvider).then(() => { });
441
475
  }
442
- const watcher = vscode.workspace.createFileSystemWatcher('**/*');
476
+ const watcher = vscode.workspace.createFileSystemWatcher("**/*");
443
477
  watcher.onDidChange(async (uri) => {
444
478
  await onFileChange(uri, false);
445
479
  });
@@ -461,7 +495,7 @@ function deactivate() {
461
495
  }
462
496
  }
463
497
  async function setWorkblock(dir, host, streamId) {
464
- console.log('Setting workblock', dir, host, streamId);
498
+ console.log("Setting workblock", dir, host, streamId);
465
499
  const client = clientsByHost[host];
466
500
  if (!client) {
467
501
  vscode.window.showErrorMessage(`Not connected to ${host}`);
@@ -482,7 +516,10 @@ async function setWorkblock(dir, host, streamId) {
482
516
  outputChannel.appendLine(`[set_work_block] Backend error: ${message}`);
483
517
  const diagnostics = [];
484
518
  const range = new vscode.Range(0, 0, 0, 0);
485
- diagnostics.push([vscode.Uri.file(mf), [new vscode.Diagnostic(range, message, vscode.DiagnosticSeverity.Error)]]);
519
+ diagnostics.push([
520
+ vscode.Uri.file(mf),
521
+ [new vscode.Diagnostic(range, message, vscode.DiagnosticSeverity.Error)],
522
+ ]);
486
523
  diagnosticCollection.set(diagnostics);
487
524
  vscode.window.showErrorMessage('Backend error while setting workblock. See "Beyond Work" output for details.');
488
525
  return;
@@ -492,7 +529,7 @@ async function setWorkblock(dir, host, streamId) {
492
529
  const diagnostics = [];
493
530
  for (const err of validation) {
494
531
  if (err.library) {
495
- const uri = vscode.Uri.file(path.join(dir, 'library.py'));
532
+ const uri = vscode.Uri.file(path.join(dir, "library.py"));
496
533
  const range = new vscode.Range(0, 0, 0, 0);
497
534
  const diag = new vscode.Diagnostic(range, err.library.error, vscode.DiagnosticSeverity.Error);
498
535
  diagnostics.push([uri, [diag]]);
@@ -554,7 +591,7 @@ async function storeWorkblockFiles(dir, wb, client) {
554
591
  const name = (0, lib_1.normalizedFilename)(task.name);
555
592
  fs.mkdirSync(path.join(moduleDir, name), { recursive: true });
556
593
  const taskDir = path.join(moduleDir, name);
557
- const taskPath = await (0, lib_1.locateFile)(taskDir, '.py', `${name}.py`);
594
+ const taskPath = await (0, lib_1.locateFile)(taskDir, ".py", `${name}.py`);
558
595
  promises.push(resolve(taskPath, task.action.value));
559
596
  if (task.assets) {
560
597
  fs.mkdirSync(path.join(moduleDir, name, "assets"), { recursive: true });
@@ -577,16 +614,16 @@ async function storeWorkblockFiles(dir, wb, client) {
577
614
  }
578
615
  }
579
616
  if (wb.library) {
580
- const libPath = path.join(dir, 'library.py');
617
+ const libPath = path.join(dir, "library.py");
581
618
  promises.push(resolve(libPath, wb.library));
582
619
  }
583
620
  if (wb.logo) {
584
- const logoPath = path.join(dir, 'logo.svg');
621
+ const logoPath = path.join(dir, "logo.svg");
585
622
  promises.push(resolve(logoPath, wb.logo));
586
623
  }
587
624
  if (wb.react_components) {
588
625
  for (const [key, asset] of Object.entries(wb.react_components)) {
589
- const assetPath = path.join(dir, 'react_components', key);
626
+ const assetPath = path.join(dir, "react_components", key);
590
627
  if (asset.data) {
591
628
  promises.push(resolve(assetPath, asset.data));
592
629
  delete asset.data;
@@ -610,6 +647,55 @@ async function storeWorkblockFiles(dir, wb, client) {
610
647
  delete out.react_components;
611
648
  fs.writeFileSync(mf, (0, yaml_1.stringify)(out));
612
649
  }
650
+ // Automatically bind streams to directories by scanning for manifest.yaml files containing matching id
651
+ async function autoBindStreams(streams, context, treeDataProvider) {
652
+ // Collect all manifest.yaml files in open workspace folders
653
+ const manifestUris = await vscode.workspace.findFiles("**/manifest.yaml", "**/{node_modules,.git}/**");
654
+ if (!manifestUris.length) {
655
+ return;
656
+ }
657
+ const manifestById = {};
658
+ for (const uri of manifestUris) {
659
+ try {
660
+ const doc = await vscode.workspace.openTextDocument(uri);
661
+ const text = doc.getText();
662
+ let parsed;
663
+ try {
664
+ parsed = (0, yaml_1.parse)(text);
665
+ }
666
+ catch {
667
+ continue; // skip invalid yaml
668
+ }
669
+ const id = parsed?.id;
670
+ if (id && typeof id === "string") {
671
+ manifestById[id] = path.dirname(uri.fsPath);
672
+ }
673
+ }
674
+ catch (e) {
675
+ // ignore individual read errors
676
+ }
677
+ }
678
+ let updated = false;
679
+ const existingDirs = new Set(Object.values(streamsByDir));
680
+ for (const s of streams) {
681
+ if (!s.editing || !s.current_work_block) {
682
+ continue;
683
+ }
684
+ if (!streamsByDir[s.id] && manifestById[s.id]) {
685
+ const candidateDir = manifestById[s.current_work_block];
686
+ // Skip if directory already bound to a different stream to avoid accidental collisions
687
+ if (!existingDirs.has(candidateDir)) {
688
+ streamsByDir[s.id] = candidateDir;
689
+ existingDirs.add(candidateDir);
690
+ updated = true;
691
+ }
692
+ }
693
+ }
694
+ if (updated) {
695
+ context.globalState.update("bw_streams_dir", streamsByDir);
696
+ treeDataProvider.refresh();
697
+ }
698
+ }
613
699
  class StringDocumentContentProvider {
614
700
  _onDidChange = new vscode.EventEmitter();
615
701
  _content = "";
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publisher": "beyondwork",
4
4
  "displayName": "Beyond Work",
5
5
  "description": "Beyond Work is a tool for managing your work in a way that is easy to use and understand.",
6
- "version": "0.1.11",
6
+ "version": "0.1.12",
7
7
  "engines": {
8
8
  "vscode": "^1.94.0",
9
9
  "node": ">=16.0.0"