@beyondwork/wb-cli 0.1.11 → 0.1.14
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/CHANGELOG.md +18 -0
- package/README.md +113 -0
- package/media/icon.png +0 -0
- package/out/extension.js +239 -87
- package/package.json +17 -3
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## v0.1.14
|
|
4
|
+
|
|
5
|
+
- Documentation updates.
|
|
6
|
+
|
|
7
|
+
## v0.1.13
|
|
8
|
+
|
|
9
|
+
- Make it easier to import a workblock that only exists on the filesystem. Right-click on a connection, select `Store new workblock`. This will import the workblock and bind it to the local dir.
|
|
10
|
+
|
|
11
|
+
## v0.1.12
|
|
12
|
+
|
|
13
|
+
- Automatically map local directories to remote workspaces.
|
|
14
|
+
|
|
15
|
+
## v0.1.11
|
|
16
|
+
|
|
17
|
+
- Better error handling and display.
|
|
18
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# Beyond Work
|
|
2
|
+
|
|
3
|
+
This extension and cli is for interacting with the Beyond Work platform. This package provides both a VS Code extension and a command-line interface (CLI) for working with Beyond Work workblocks.
|
|
4
|
+
|
|
5
|
+
# VS Code Extension
|
|
6
|
+
|
|
7
|
+
The Beyond Work VS Code extension enables developers to write, test, and manage Workblocks directly within Visual Studio Code. Using a remote file system, it provides direct access to your Beyond Work Workblocks, making it the ideal tool for developers who want a full-featured editor for creating and updating Workblocks.
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
Use this to edit workblocks via VSCode. The extension allows you to connect to Beyond Work and bind workblocks to directories on your local machine.
|
|
12
|
+
The workblocks in those workspaces can then be stored as files on your local machine.
|
|
13
|
+
|
|
14
|
+
The extension has 3 features:
|
|
15
|
+
|
|
16
|
+
- Get a work block from an existing workspace to local filesystem
|
|
17
|
+
- Set a work block on a workspace from local files
|
|
18
|
+
- Live sync work blocks between open workspaces and local filesystem
|
|
19
|
+
|
|
20
|
+
Work blocks are expected to be placed in a directory that contains nothing but work blocks. When starting from scratch simply create a new directory somewhere.
|
|
21
|
+
|
|
22
|
+
### Getting started
|
|
23
|
+
|
|
24
|
+
First step is to create a new connection. Click the `+` button in the BEYOND WORK sidebar, or use CMD-SHIFT-P and type `Beyond Work: Add Connection`.
|
|
25
|
+
Then, enter the hostname of the Beyond Work instance you want to connect to. This is the same hostname you use to access the web UI.
|
|
26
|
+
|
|
27
|
+
Then, click on the connection in the BEYOND WORK sidebar. This will prompt for an API key. You can get this by creating a new token under the account settings.
|
|
28
|
+
|
|
29
|
+
The connection should now have a blue checkmark. Under it, workspaces with an open editor will be shown. Each of them can be bound to a directory by clicking on them
|
|
30
|
+
and choosing `Choose a directory`.
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
### Getting a work block
|
|
34
|
+
|
|
35
|
+
Click a workspace in the menu and choose \`Get workblock from workspace\`. This takes the work block that's in the workspace provided and downloads it to the directory associated with the workspace.
|
|
36
|
+
|
|
37
|
+
### Setting a work block
|
|
38
|
+
|
|
39
|
+
Click a workspace in the menu and choose \`Store workblock to workspace\`. This takes the work block files in the associated directory and combines them into a work block definition and sets it in the workspace provided.
|
|
40
|
+
|
|
41
|
+
Note that this does not actually store the work block outside the workspace. In order to do that open the work block editor in the workspace and click store.
|
|
42
|
+
|
|
43
|
+
### Syncing work blocks
|
|
44
|
+
|
|
45
|
+
Click a workspace in the menu and choose \`Enable sync\`.
|
|
46
|
+
|
|
47
|
+
If a workblock is changed in the UI, either via the editor or by an agent, that change will be reflected in the local files. If local files are changed they are automatically set on the workspace. It's possible to have the UI editor open while editing files locally, the editor will update live as files are saved.
|
|
48
|
+
|
|
49
|
+
Notice that workblocks are validated before they are set on a workspace. If a workblock is not valid, errors will be shown in the files.
|
|
50
|
+
|
|
51
|
+
### Directory structure
|
|
52
|
+
|
|
53
|
+
The work block directory structure is like this:
|
|
54
|
+
|
|
55
|
+
<pre>
|
|
56
|
+
Base dir/
|
|
57
|
+
work_block_1/
|
|
58
|
+
task_1/
|
|
59
|
+
assets/
|
|
60
|
+
asset1.txt
|
|
61
|
+
task_1.py
|
|
62
|
+
manifest.yaml
|
|
63
|
+
</pre>
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
## CLI Tool
|
|
67
|
+
|
|
68
|
+
In addition to the VS Code extension, this package provides a command-line interface (CLI) for working with Beyond Work workblocks.
|
|
69
|
+
|
|
70
|
+
### Installation as a CLI tool
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
npm install -g beyondwork
|
|
74
|
+
# or
|
|
75
|
+
yarn global add beyondwork
|
|
76
|
+
# or
|
|
77
|
+
pnpm add -g beyondwork
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### CLI Usage
|
|
81
|
+
|
|
82
|
+
#### Assemble a workblock from a directory
|
|
83
|
+
```bash
|
|
84
|
+
beyondwork assemble /path/to/workblock/dir [--output output.json]
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
This command takes a directory containing workblock files and assembles them into a complete workblock JSON object. The structure follows the Beyond Work format:
|
|
88
|
+
|
|
89
|
+
```
|
|
90
|
+
Base dir/
|
|
91
|
+
work_block_1/
|
|
92
|
+
task_1/
|
|
93
|
+
assets/
|
|
94
|
+
asset1.txt
|
|
95
|
+
task_1.py
|
|
96
|
+
manifest.yaml
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Programmatic Usage
|
|
100
|
+
|
|
101
|
+
You can also use the library programmatically:
|
|
102
|
+
|
|
103
|
+
```typescript
|
|
104
|
+
import { assembleWorkblock, storeWorkblockFiles } from 'beyondwork/lib/utils';
|
|
105
|
+
|
|
106
|
+
// Assemble a workblock from files
|
|
107
|
+
const workblock = await assembleWorkblock('/path/to/workblock');
|
|
108
|
+
|
|
109
|
+
// Store a workblock as files
|
|
110
|
+
await storeWorkblockFiles('/output/path', workblockObject);
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
|
package/media/icon.png
ADDED
|
Binary file
|
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,
|
|
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 &&
|
|
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,
|
|
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(
|
|
152
|
+
context.globalState.update("bw_current_connection", host);
|
|
144
153
|
return newClient;
|
|
145
154
|
}
|
|
146
155
|
function activate(context) {
|
|
147
|
-
diagnosticCollection =
|
|
148
|
-
|
|
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(
|
|
151
|
-
syncStreams = context.globalState.get(
|
|
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(
|
|
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 = [
|
|
165
|
-
if (ignorePatterns.some((pattern) => uri.
|
|
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(
|
|
194
|
+
const addConnectionCmd = vscode.commands.registerCommand("beyondwork.beyondwork.addConnection", async () => {
|
|
186
195
|
let host = await vscode.window.showInputBox({
|
|
187
|
-
prompt:
|
|
188
|
-
placeHolder:
|
|
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(
|
|
200
|
+
new URL(`${value.startsWith("https://") ? "" : "https://"}${value}`);
|
|
192
201
|
return undefined; // valid
|
|
193
202
|
}
|
|
194
203
|
catch {
|
|
195
|
-
return
|
|
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:
|
|
213
|
+
status: "disconnected",
|
|
205
214
|
});
|
|
206
215
|
});
|
|
207
|
-
const connectToTenantCmd = vscode.commands.registerCommand(
|
|
208
|
-
tenant.status =
|
|
209
|
-
treeDataProvider.updateConnectionStatus(tenant.host,
|
|
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(
|
|
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(
|
|
230
|
+
vscode.window.showInformationMessage("All connections cleared.");
|
|
222
231
|
});
|
|
223
|
-
const removeConnectionCmd = vscode.commands.registerCommand(
|
|
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(
|
|
240
|
+
vscode.window.showInformationMessage("No connections to remove.");
|
|
232
241
|
return;
|
|
233
242
|
}
|
|
234
|
-
const picked = await vscode.window.showQuickPick(all.map(c => ({
|
|
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}?`,
|
|
240
|
-
if (yesNo ===
|
|
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,79 @@ function activate(context) {
|
|
|
246
259
|
treeDataProvider.removeConnection(connection);
|
|
247
260
|
}
|
|
248
261
|
});
|
|
249
|
-
const
|
|
262
|
+
const storeNewWorkblock = vscode.commands.registerCommand("beyondwork.beyondwork.storeWorkblock", async (item) => {
|
|
263
|
+
outputChannel.appendLine(`Store new workblock`);
|
|
264
|
+
const opts = {
|
|
265
|
+
canSelectFolders: true,
|
|
266
|
+
canSelectFiles: false,
|
|
267
|
+
canSelectMany: false,
|
|
268
|
+
openLabel: "Select folder for the workblock",
|
|
269
|
+
};
|
|
270
|
+
const baseDir = await vscode.window.showOpenDialog(opts);
|
|
271
|
+
if (!baseDir?.length) {
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
const manifestDir = await (0, lib_1.locateManifest)(baseDir[0].fsPath);
|
|
275
|
+
if (!manifestDir) {
|
|
276
|
+
vscode.window.showErrorMessage(`No manifest.yaml found in selected directory`);
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
// Assemble workblock from selected directory
|
|
280
|
+
const wb = await (0, lib_1.assembleWorkblock)(baseDir[0].fsPath, outputLogger);
|
|
281
|
+
if (!wb) {
|
|
282
|
+
vscode.window.showErrorMessage("Failed to assemble workblock from directory");
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
const host = item?.connection?.host;
|
|
286
|
+
if (!host) {
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
const client = clientsByHost[host];
|
|
290
|
+
if (!client) {
|
|
291
|
+
vscode.window.showErrorMessage(`Not connected to ${host}`);
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
outputChannel.appendLine(`Creating new stream for workblock '${wb.name}' on host ${host}`);
|
|
295
|
+
try {
|
|
296
|
+
const stream = await client.storeWorkblock(wb);
|
|
297
|
+
outputChannel.appendLine(`Created stream ${stream.id} (${stream.title})`);
|
|
298
|
+
// Ensure host mapping structures exist
|
|
299
|
+
if (!streamsByHost[host]) {
|
|
300
|
+
streamsByHost[host] = [];
|
|
301
|
+
}
|
|
302
|
+
hostsByStream[stream.id] = host;
|
|
303
|
+
// Insert new stream into list if not present
|
|
304
|
+
if (!streamsByHost[host].some((s) => s.id === stream.id)) {
|
|
305
|
+
streamsByHost[host].push({
|
|
306
|
+
id: stream.id,
|
|
307
|
+
editing: stream.editing ?? true,
|
|
308
|
+
title: stream.title ?? wb.name,
|
|
309
|
+
});
|
|
310
|
+
streamsByHost[host] = streamsByHost[host].sort((a, b) => a.title.localeCompare(b.title));
|
|
311
|
+
}
|
|
312
|
+
// Bind directory to stream
|
|
313
|
+
streamsByDir[stream.id] = baseDir[0].fsPath;
|
|
314
|
+
context.globalState.update("bw_streams_dir", streamsByDir);
|
|
315
|
+
// Store latest workblock for change tracking
|
|
316
|
+
latestWorkblocks[host + stream.id] = wb;
|
|
317
|
+
// Update tree view
|
|
318
|
+
treeDataProvider.setStreamsForHost(host, streamsByHost[host]);
|
|
319
|
+
treeDataProvider.refresh();
|
|
320
|
+
vscode.window.showInformationMessage(`Created and bound new stream '${stream.title}'`);
|
|
321
|
+
}
|
|
322
|
+
catch (e) {
|
|
323
|
+
const msg = e?.message ?? String(e);
|
|
324
|
+
outputChannel.appendLine(`Failed to create stream: ${msg}`);
|
|
325
|
+
vscode.window.showErrorMessage(`Failed to create stream: ${msg}`);
|
|
326
|
+
}
|
|
327
|
+
});
|
|
328
|
+
const bindStream = vscode.commands.registerCommand("beyondwork.beyondwork.bindStream", async (stream, dir) => {
|
|
250
329
|
outputChannel.appendLine(`Binding stream ${stream.id} ${dir}`);
|
|
251
330
|
const opts = {
|
|
252
331
|
canSelectFolders: true,
|
|
253
332
|
canSelectFiles: false,
|
|
254
333
|
canSelectMany: false,
|
|
255
|
-
openLabel:
|
|
334
|
+
openLabel: "Select folder for the workblock",
|
|
256
335
|
};
|
|
257
336
|
if (dir) {
|
|
258
337
|
opts.defaultUri = vscode.Uri.file(dir);
|
|
@@ -262,104 +341,126 @@ function activate(context) {
|
|
|
262
341
|
return;
|
|
263
342
|
}
|
|
264
343
|
streamsByDir[stream.id] = baseDir[0].fsPath;
|
|
265
|
-
context.globalState.update(
|
|
344
|
+
context.globalState.update("bw_streams_dir", streamsByDir);
|
|
266
345
|
treeDataProvider.refresh();
|
|
346
|
+
// Immediately fetch remote workblock into selected directory (enhanced behavior)
|
|
347
|
+
try {
|
|
348
|
+
const host = hostsByStream[stream.id];
|
|
349
|
+
if (host) {
|
|
350
|
+
const client = clientsByHost[host];
|
|
351
|
+
const wb = await client.getWorkblock(stream.id);
|
|
352
|
+
if (wb) {
|
|
353
|
+
await storeWorkblockFiles(baseDir[0].fsPath, wb, client);
|
|
354
|
+
latestWorkblocks[host + stream.id] = wb;
|
|
355
|
+
await onWorkblockChange(stream.id, wb, treeDataProvider, host);
|
|
356
|
+
outputChannel.appendLine(`Fetched remote workblock for ${stream.id} into ${baseDir[0].fsPath}`);
|
|
357
|
+
}
|
|
358
|
+
else {
|
|
359
|
+
outputChannel.appendLine(`No remote workblock present for ${stream.id}`);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
catch (e) {
|
|
364
|
+
outputChannel.appendLine(`Failed to fetch remote workblock for ${stream.id}: ${e?.message ?? e}`);
|
|
365
|
+
}
|
|
267
366
|
});
|
|
268
|
-
const getWB = vscode.commands.registerCommand(
|
|
367
|
+
const getWB = vscode.commands.registerCommand("beyondwork.beyondwork.get", async (item) => {
|
|
269
368
|
outputChannel.appendLine(`Getting workblock ${item.stream}`);
|
|
270
369
|
if (!item.dir) {
|
|
271
|
-
vscode.window.showErrorMessage(
|
|
370
|
+
vscode.window.showErrorMessage("Please bind a directory to the stream first");
|
|
272
371
|
return;
|
|
273
372
|
}
|
|
274
373
|
const client = clientsByHost[item.connection.host];
|
|
275
374
|
const wb = await client.getWorkblock(item.stream.id);
|
|
276
375
|
outputChannel.appendLine(`Got workblock ${wb}`);
|
|
277
376
|
if (!wb) {
|
|
278
|
-
vscode.window.showErrorMessage(
|
|
377
|
+
vscode.window.showErrorMessage("No workblock in workspace");
|
|
279
378
|
return;
|
|
280
379
|
}
|
|
281
|
-
storeWorkblockFiles(item.dir, wb, client);
|
|
380
|
+
await storeWorkblockFiles(item.dir, wb, client);
|
|
282
381
|
});
|
|
283
|
-
const setWB = vscode.commands.registerCommand(
|
|
382
|
+
const setWB = vscode.commands.registerCommand("beyondwork.beyondwork.set", async (item) => {
|
|
284
383
|
outputChannel.appendLine(`Setting workblock ${item.stream}`);
|
|
285
384
|
if (!item.dir) {
|
|
286
|
-
vscode.window.showErrorMessage(
|
|
385
|
+
vscode.window.showErrorMessage("Please bind a directory to the stream first");
|
|
287
386
|
return;
|
|
288
387
|
}
|
|
289
|
-
setWorkblock(item.dir, item.connection.host, item.stream.id);
|
|
388
|
+
await setWorkblock(item.dir, item.connection.host, item.stream.id);
|
|
290
389
|
});
|
|
291
390
|
const compareChanges = async (item) => {
|
|
292
391
|
const wb = await (0, lib_1.assembleWorkblock)(item.dir, outputLogger);
|
|
293
392
|
const stored = await clientsByHost[item.connection.host].getWorkblock(item.stream.id);
|
|
294
|
-
const file1 = vscode.Uri.parse(
|
|
295
|
-
const file2 = vscode.Uri.parse(
|
|
393
|
+
const file1 = vscode.Uri.parse("bw-manifest:local.yaml");
|
|
394
|
+
const file2 = vscode.Uri.parse("bw-manifest:stored.yaml");
|
|
296
395
|
if (wb) {
|
|
297
396
|
stringContentProvider.setContent(file1, (0, yaml_1.stringify)((0, lib_1.trimWorkblock)(wb)));
|
|
298
397
|
}
|
|
299
398
|
if (stored) {
|
|
300
399
|
stringContentProvider.setContent(file2, (0, yaml_1.stringify)((0, lib_1.trimWorkblock)(stored)));
|
|
301
400
|
}
|
|
302
|
-
vscode.commands.executeCommand(
|
|
401
|
+
vscode.commands.executeCommand("vscode.diff", file1, file2, "Local vs stored workblock");
|
|
303
402
|
};
|
|
304
|
-
const streamOptions = vscode.commands.registerCommand(
|
|
403
|
+
const streamOptions = vscode.commands.registerCommand("beyondwork.beyondwork.showStreamOptions", async (item) => {
|
|
305
404
|
outputChannel.appendLine(`Stream options ${item}`);
|
|
306
|
-
const dirOpt = item.dir
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
];
|
|
405
|
+
const dirOpt = item.dir
|
|
406
|
+
? `Change directory from ${item.dir}`
|
|
407
|
+
: "Choose a directory for the workspace";
|
|
408
|
+
const options = [dirOpt];
|
|
310
409
|
if (item.dir) {
|
|
311
|
-
options.push(
|
|
312
|
-
options.push(
|
|
313
|
-
options.push(
|
|
410
|
+
options.push("Remove directory binding");
|
|
411
|
+
options.push("Get workblock from workspace");
|
|
412
|
+
options.push("Store workblock to workspace");
|
|
314
413
|
if (syncStreams[item.stream.id] === undefined) {
|
|
315
|
-
options.push(
|
|
414
|
+
options.push("Enable sync");
|
|
316
415
|
}
|
|
317
416
|
else {
|
|
318
|
-
options.push(
|
|
417
|
+
options.push("Disable sync");
|
|
319
418
|
}
|
|
320
419
|
if (item.modified) {
|
|
321
|
-
options.push(
|
|
420
|
+
options.push("Compare changes");
|
|
322
421
|
}
|
|
323
422
|
}
|
|
324
|
-
vscode.window
|
|
325
|
-
|
|
326
|
-
|
|
423
|
+
vscode.window
|
|
424
|
+
.showQuickPick(options, {
|
|
425
|
+
placeHolder: "Select an action",
|
|
426
|
+
})
|
|
427
|
+
.then((selection) => {
|
|
327
428
|
if (selection) {
|
|
328
429
|
switch (selection) {
|
|
329
430
|
case dirOpt:
|
|
330
|
-
vscode.commands.executeCommand(
|
|
431
|
+
vscode.commands.executeCommand("beyondwork.beyondwork.bindStream", item.stream, item.dir);
|
|
331
432
|
break;
|
|
332
|
-
case
|
|
333
|
-
vscode.commands.executeCommand(
|
|
433
|
+
case "Get workblock from workspace":
|
|
434
|
+
vscode.commands.executeCommand("beyondwork.beyondwork.get", item);
|
|
334
435
|
break;
|
|
335
|
-
case
|
|
336
|
-
vscode.commands.executeCommand(
|
|
436
|
+
case "Store workblock to workspace":
|
|
437
|
+
vscode.commands.executeCommand("beyondwork.beyondwork.set", item);
|
|
337
438
|
break;
|
|
338
|
-
case
|
|
439
|
+
case "Enable sync":
|
|
339
440
|
syncStreams[item.stream.id] = item.dir;
|
|
340
|
-
context.globalState.update(
|
|
441
|
+
context.globalState.update("bw_sync_streams", syncStreams);
|
|
341
442
|
treeDataProvider.refresh();
|
|
342
443
|
break;
|
|
343
|
-
case
|
|
444
|
+
case "Disable sync":
|
|
344
445
|
delete syncStreams[item.stream.id];
|
|
345
|
-
context.globalState.update(
|
|
446
|
+
context.globalState.update("bw_sync_streams", syncStreams);
|
|
346
447
|
treeDataProvider.refresh();
|
|
347
448
|
break;
|
|
348
|
-
case
|
|
449
|
+
case "Compare changes":
|
|
349
450
|
compareChanges(item);
|
|
350
451
|
break;
|
|
351
|
-
case
|
|
452
|
+
case "Remove directory binding":
|
|
352
453
|
delete streamsByDir[item.stream.id];
|
|
353
454
|
delete syncStreams[item.stream.id];
|
|
354
|
-
context.globalState.update(
|
|
455
|
+
context.globalState.update("bw_streams_dir", streamsByDir);
|
|
355
456
|
treeDataProvider.refresh();
|
|
356
457
|
break;
|
|
357
458
|
}
|
|
358
459
|
}
|
|
359
460
|
});
|
|
360
461
|
});
|
|
361
|
-
const syncSelected = vscode.commands.registerCommand(
|
|
362
|
-
const items = treeView.selection.filter((item) => item.contextValue ===
|
|
462
|
+
const syncSelected = vscode.commands.registerCommand("beyondwork.beyondwork.storeSelected", async () => {
|
|
463
|
+
const items = treeView.selection.filter((item) => item.contextValue === "beyondwork.stream");
|
|
363
464
|
for (const item of items) {
|
|
364
465
|
const si = item;
|
|
365
466
|
if (si.dir) {
|
|
@@ -367,8 +468,8 @@ function activate(context) {
|
|
|
367
468
|
}
|
|
368
469
|
}
|
|
369
470
|
});
|
|
370
|
-
const help = vscode.commands.registerCommand(
|
|
371
|
-
const panel = vscode.window.createWebviewPanel(
|
|
471
|
+
const help = vscode.commands.registerCommand("beyondwork.beyondwork.help", async () => {
|
|
472
|
+
const panel = vscode.window.createWebviewPanel("help", "Beyond Work Help", vscode.ViewColumn.One, {
|
|
372
473
|
enableCommandUris: true,
|
|
373
474
|
});
|
|
374
475
|
const md = new markdown_it_1.default({
|
|
@@ -433,13 +534,12 @@ Base dir/
|
|
|
433
534
|
</pre>
|
|
434
535
|
`);
|
|
435
536
|
});
|
|
436
|
-
let prevHost = context.globalState.get(
|
|
537
|
+
let prevHost = context.globalState.get("bw_current_connection", "");
|
|
437
538
|
if (prevHost) {
|
|
438
|
-
treeDataProvider.updateConnectionStatus(prevHost,
|
|
439
|
-
connectToHost(prevHost, context, treeDataProvider).then(() => {
|
|
440
|
-
});
|
|
539
|
+
treeDataProvider.updateConnectionStatus(prevHost, "connecting");
|
|
540
|
+
connectToHost(prevHost, context, treeDataProvider).then(() => { });
|
|
441
541
|
}
|
|
442
|
-
const watcher = vscode.workspace.createFileSystemWatcher(
|
|
542
|
+
const watcher = vscode.workspace.createFileSystemWatcher("**/*");
|
|
443
543
|
watcher.onDidChange(async (uri) => {
|
|
444
544
|
await onFileChange(uri, false);
|
|
445
545
|
});
|
|
@@ -452,7 +552,7 @@ Base dir/
|
|
|
452
552
|
const saveListener = vscode.workspace.onDidSaveTextDocument((doc) => {
|
|
453
553
|
onFileChange(doc.uri, true);
|
|
454
554
|
});
|
|
455
|
-
context.subscriptions.push(providerReg, addConnectionCmd, connectToTenantCmd, clearConnectionsCmd, removeConnectionCmd, bindStream, getWB, setWB, streamOptions, syncSelected, help, watcher, treeView, outputChannel, diagnosticCollection, saveListener);
|
|
555
|
+
context.subscriptions.push(providerReg, addConnectionCmd, connectToTenantCmd, clearConnectionsCmd, removeConnectionCmd, storeNewWorkblock, bindStream, getWB, setWB, streamOptions, syncSelected, help, watcher, treeView, outputChannel, diagnosticCollection, saveListener);
|
|
456
556
|
}
|
|
457
557
|
function deactivate() {
|
|
458
558
|
for (const [key, cl] of Object.entries(clientsByHost)) {
|
|
@@ -461,7 +561,7 @@ function deactivate() {
|
|
|
461
561
|
}
|
|
462
562
|
}
|
|
463
563
|
async function setWorkblock(dir, host, streamId) {
|
|
464
|
-
console.log(
|
|
564
|
+
console.log("Setting workblock", dir, host, streamId);
|
|
465
565
|
const client = clientsByHost[host];
|
|
466
566
|
if (!client) {
|
|
467
567
|
vscode.window.showErrorMessage(`Not connected to ${host}`);
|
|
@@ -482,7 +582,10 @@ async function setWorkblock(dir, host, streamId) {
|
|
|
482
582
|
outputChannel.appendLine(`[set_work_block] Backend error: ${message}`);
|
|
483
583
|
const diagnostics = [];
|
|
484
584
|
const range = new vscode.Range(0, 0, 0, 0);
|
|
485
|
-
diagnostics.push([
|
|
585
|
+
diagnostics.push([
|
|
586
|
+
vscode.Uri.file(mf),
|
|
587
|
+
[new vscode.Diagnostic(range, message, vscode.DiagnosticSeverity.Error)],
|
|
588
|
+
]);
|
|
486
589
|
diagnosticCollection.set(diagnostics);
|
|
487
590
|
vscode.window.showErrorMessage('Backend error while setting workblock. See "Beyond Work" output for details.');
|
|
488
591
|
return;
|
|
@@ -492,7 +595,7 @@ async function setWorkblock(dir, host, streamId) {
|
|
|
492
595
|
const diagnostics = [];
|
|
493
596
|
for (const err of validation) {
|
|
494
597
|
if (err.library) {
|
|
495
|
-
const uri = vscode.Uri.file(path.join(dir,
|
|
598
|
+
const uri = vscode.Uri.file(path.join(dir, "library.py"));
|
|
496
599
|
const range = new vscode.Range(0, 0, 0, 0);
|
|
497
600
|
const diag = new vscode.Diagnostic(range, err.library.error, vscode.DiagnosticSeverity.Error);
|
|
498
601
|
diagnostics.push([uri, [diag]]);
|
|
@@ -554,7 +657,7 @@ async function storeWorkblockFiles(dir, wb, client) {
|
|
|
554
657
|
const name = (0, lib_1.normalizedFilename)(task.name);
|
|
555
658
|
fs.mkdirSync(path.join(moduleDir, name), { recursive: true });
|
|
556
659
|
const taskDir = path.join(moduleDir, name);
|
|
557
|
-
const taskPath = await (0, lib_1.locateFile)(taskDir,
|
|
660
|
+
const taskPath = await (0, lib_1.locateFile)(taskDir, ".py", `${name}.py`);
|
|
558
661
|
promises.push(resolve(taskPath, task.action.value));
|
|
559
662
|
if (task.assets) {
|
|
560
663
|
fs.mkdirSync(path.join(moduleDir, name, "assets"), { recursive: true });
|
|
@@ -577,16 +680,16 @@ async function storeWorkblockFiles(dir, wb, client) {
|
|
|
577
680
|
}
|
|
578
681
|
}
|
|
579
682
|
if (wb.library) {
|
|
580
|
-
const libPath = path.join(dir,
|
|
683
|
+
const libPath = path.join(dir, "library.py");
|
|
581
684
|
promises.push(resolve(libPath, wb.library));
|
|
582
685
|
}
|
|
583
686
|
if (wb.logo) {
|
|
584
|
-
const logoPath = path.join(dir,
|
|
687
|
+
const logoPath = path.join(dir, "logo.svg");
|
|
585
688
|
promises.push(resolve(logoPath, wb.logo));
|
|
586
689
|
}
|
|
587
690
|
if (wb.react_components) {
|
|
588
691
|
for (const [key, asset] of Object.entries(wb.react_components)) {
|
|
589
|
-
const assetPath = path.join(dir,
|
|
692
|
+
const assetPath = path.join(dir, "react_components", key);
|
|
590
693
|
if (asset.data) {
|
|
591
694
|
promises.push(resolve(assetPath, asset.data));
|
|
592
695
|
delete asset.data;
|
|
@@ -610,6 +713,55 @@ async function storeWorkblockFiles(dir, wb, client) {
|
|
|
610
713
|
delete out.react_components;
|
|
611
714
|
fs.writeFileSync(mf, (0, yaml_1.stringify)(out));
|
|
612
715
|
}
|
|
716
|
+
// Automatically bind streams to directories by scanning for manifest.yaml files containing matching id
|
|
717
|
+
async function autoBindStreams(streams, context, treeDataProvider) {
|
|
718
|
+
// Collect all manifest.yaml files in open workspace folders
|
|
719
|
+
const manifestUris = await vscode.workspace.findFiles("**/manifest.yaml", "**/{node_modules,.git}/**");
|
|
720
|
+
if (!manifestUris.length) {
|
|
721
|
+
return;
|
|
722
|
+
}
|
|
723
|
+
const manifestById = {};
|
|
724
|
+
for (const uri of manifestUris) {
|
|
725
|
+
try {
|
|
726
|
+
const doc = await vscode.workspace.openTextDocument(uri);
|
|
727
|
+
const text = doc.getText();
|
|
728
|
+
let parsed;
|
|
729
|
+
try {
|
|
730
|
+
parsed = (0, yaml_1.parse)(text);
|
|
731
|
+
}
|
|
732
|
+
catch {
|
|
733
|
+
continue; // skip invalid yaml
|
|
734
|
+
}
|
|
735
|
+
const id = parsed?.id;
|
|
736
|
+
if (id && typeof id === "string") {
|
|
737
|
+
manifestById[id] = path.dirname(uri.fsPath);
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
catch (e) {
|
|
741
|
+
// ignore individual read errors
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
let updated = false;
|
|
745
|
+
const existingDirs = new Set(Object.values(streamsByDir));
|
|
746
|
+
for (const s of streams) {
|
|
747
|
+
if (!s.editing || !s.current_work_block) {
|
|
748
|
+
continue;
|
|
749
|
+
}
|
|
750
|
+
if (!streamsByDir[s.id] && manifestById[s.id]) {
|
|
751
|
+
const candidateDir = manifestById[s.current_work_block];
|
|
752
|
+
// Skip if directory already bound to a different stream to avoid accidental collisions
|
|
753
|
+
if (!existingDirs.has(candidateDir)) {
|
|
754
|
+
streamsByDir[s.id] = candidateDir;
|
|
755
|
+
existingDirs.add(candidateDir);
|
|
756
|
+
updated = true;
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
if (updated) {
|
|
761
|
+
context.globalState.update("bw_streams_dir", streamsByDir);
|
|
762
|
+
treeDataProvider.refresh();
|
|
763
|
+
}
|
|
764
|
+
}
|
|
613
765
|
class StringDocumentContentProvider {
|
|
614
766
|
_onDidChange = new vscode.EventEmitter();
|
|
615
767
|
_content = "";
|
package/package.json
CHANGED
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
"name": "@beyondwork/wb-cli",
|
|
3
3
|
"publisher": "beyondwork",
|
|
4
4
|
"displayName": "Beyond Work",
|
|
5
|
-
"description": "
|
|
6
|
-
"version": "0.1.
|
|
5
|
+
"description": "Tool for interacting with Beyond Work workblocks from VS Code and CLI.",
|
|
6
|
+
"version": "0.1.14",
|
|
7
|
+
"icon": "media/icon.png",
|
|
7
8
|
"engines": {
|
|
8
9
|
"vscode": "^1.94.0",
|
|
9
10
|
"node": ">=16.0.0"
|
|
@@ -17,7 +18,11 @@
|
|
|
17
18
|
"files": [
|
|
18
19
|
"out/lib/**/*",
|
|
19
20
|
"out/cli.js",
|
|
20
|
-
"out/extension.js"
|
|
21
|
+
"out/extension.js",
|
|
22
|
+
"media/icon.png",
|
|
23
|
+
"CHANGELOG.md",
|
|
24
|
+
"README.md",
|
|
25
|
+
"LICENSE.txt"
|
|
21
26
|
],
|
|
22
27
|
"main": "./out/extension.js",
|
|
23
28
|
"private": false,
|
|
@@ -42,6 +47,10 @@
|
|
|
42
47
|
"title": "Beyond Work: Remove Connection",
|
|
43
48
|
"icon": "$(trash)"
|
|
44
49
|
},
|
|
50
|
+
{
|
|
51
|
+
"command": "beyondwork.beyondwork.storeWorkblock",
|
|
52
|
+
"title": "Beyond Work: Store new workblock"
|
|
53
|
+
},
|
|
45
54
|
{
|
|
46
55
|
"command": "beyondwork.beyondwork.help",
|
|
47
56
|
"title": "Beyond Work: Help",
|
|
@@ -71,6 +80,11 @@
|
|
|
71
80
|
"command": "beyondwork.beyondwork.removeConnection",
|
|
72
81
|
"when": "view == beyondworkConnections",
|
|
73
82
|
"group": "navigation"
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
"command": "beyondwork.beyondwork.storeWorkblock",
|
|
86
|
+
"when": "view == beyondworkConnections",
|
|
87
|
+
"group": "navigation"
|
|
74
88
|
}
|
|
75
89
|
]
|
|
76
90
|
},
|