@beyondwork/wb-cli 0.1.29 → 0.1.30

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/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.29",
6
+ "version": "0.1.30",
7
7
  "vsce": {
8
8
  "baseContentUrl": "https://github.com/bwllaming/code/blob/HEAD/src/vscode/beyondwork",
9
9
  "baseImagesUrl": "https://github.com/bwllaming/code/raw/HEAD/src/vscode/beyondwork"
@@ -1,24 +1,25 @@
1
1
  ---
2
2
  name: bw-workblock
3
- description: Create or edit a Beyond Work workblock that lives on a tenant, from a coding agent session in the Beyond Work monorepo, with `bin/wb-cli`. Use whenever the user asks to create, change, fix, extend, inspect, run or validate a workblock on a tenant, names a Studio URL (https://<tenant>/w/studio/detail/<id> or /w/studio/s/<id>) or a workblock id, or wants a change pushed to a workblock version. Covers credentials, create/clone/pull/push, validation, unit tests, runs, versions, and where the authoring knowledge (skills, docs) lands in the checkout.
3
+ description: Create or edit a Beyond Work workblock that lives on a tenant, from a coding agent session, with `wb-cli`. Use whenever the user asks to create, change, fix, extend, inspect, run or validate a workblock on a tenant, names a Studio URL (https://<tenant>/w/studio/detail/<id> or /w/studio/s/<id>) or a workblock id, or wants a change pushed to a workblock version. Covers credentials, create/clone/pull/push, validation, unit tests, runs, versions, and where the authoring knowledge (skills, docs) lands in the checkout.
4
4
  ---
5
5
 
6
6
  # bw-workblock
7
7
 
8
- `bin/wb-cli` in the monorepo turns a workblock on a tenant into local files and saves them back the
9
- way Studio's Save and Update do. `clone` and `create` write the checkout to the directory you give
10
- them: put it outside the monorepo. Every other verb acts on the checkout that holds the current
11
- directory, so run it from there and call the wrapper by its path, `<monorepo>/bin/wb-cli validate`
12
- (written `bin/wb-cli` below). The request is the whole job, push and publish included: do not stop
13
- to ask. Deploying a version to `main` is not part of it: the user does that in Studio, because it
14
- changes what every user of the tenant runs.
8
+ `wb-cli` (the npm package `@beyondwork/wb-cli`) turns a workblock on a tenant into local files and
9
+ saves them back the way Studio's Save and Update do. In the Beyond Work monorepo, call the wrapper by
10
+ its path, `<monorepo>/bin/wb-cli`, wherever this skill says `wb-cli`, and put checkouts outside the
11
+ monorepo. `clone` and `create` write the checkout to the directory you give them. Every other verb
12
+ acts on the checkout that holds the current directory, so run it from there. The request is the whole
13
+ job, push and publish included: do not stop to ask. Deploying a workblock version to `main` must be
14
+ done from Studio.
15
15
 
16
16
  ## The loop
17
17
 
18
- 1. **Get the files.** `bin/wb-cli clone <studio-url> <dir>`, or `bin/wb-cli create <tenant-host>
18
+ 1. **Get the files.** `wb-cli clone <studio-url> <dir>`, or `wb-cli create <tenant-host>
19
19
  "<name>" <dir>` for a new workblock. The checkout is a git repository that wb-cli commits to:
20
- HEAD is the server's state after the last clone, pull or push, so `git diff` shows your unpushed
21
- edits. `.bw/workblock.json` binds it to the platform; do not edit it.
20
+ HEAD is the server's state after the last clone, pull or push, so `git status` lists your
21
+ unpushed edits, new files included, and `git diff HEAD` shows the edits to files the server
22
+ already had. `.bw/workblock.json` binds it to the platform; do not edit it.
22
23
  2. **Read before writing.** `AGENTS.md`, then the `.skills/` entries for the area you touch, then
23
24
  `.docs/docs.md` for each platform API you call. The platform changes faster than your memory of
24
25
  it, and validation catches only part of what the docs would have told you.
@@ -28,27 +29,28 @@ changes what every user of the tenant runs.
28
29
  starts begins with a task that shows a UI and has no module inputs: for a module with inputs,
29
30
  Studio's Start opens a generic "Configure & Run module" form with one raw field per input.
30
31
  4. **Edit.** A test is an entry under the module's `tests:` (`name`, `type: pytest`) plus
31
- `<module>/tests/<name>.py`, which imports a task's function as `from <package> import <function>`,
32
- the package being the task name in lower case with spaces replaced by underscores. A file no
33
- manifest entry claims is not pushed. Change only what the request asks for: no fixes to nearby
32
+ `<module>/tests/<name>.py`. A task's code reaches a test as a pytest fixture, not as a module to
33
+ import: `def test_x(flag_gaps): assert flag_gaps.flag(...)` gets task "Flag Gaps", the parameter
34
+ being the task name in lower case with spaces replaced by underscores. A file no manifest entry
35
+ claims is not pushed. Change only what the request asks for: no fixes to nearby
34
36
  tasks, no tidying of files you did not need to touch, and no tasks beyond the request and the
35
37
  experience of step 3.
36
- 5. **Validate** with `bin/wb-cli validate` until it reports no errors. Warnings are advisory.
37
- 6. **Publish** with `bin/wb-cli push --update` (`push --new-version <name> --update` from a `main`
38
+ 5. **Validate** with `wb-cli validate` until it reports no errors. Warnings are advisory.
39
+ 6. **Publish** with `wb-cli push --update` (`push --new-version <name> --update` from a `main`
38
40
  checkout). Without `--update`, or when the CLI reports the push as not published, the version
39
41
  stays behind, and a deploy in Studio would ship it without your change.
40
- 7. **Prove it.** Run `bin/wb-cli test [<module>]` when the module has tests, then `bin/wb-cli run
41
- <module>`, or `bin/wb-cli run <module>/<task> --inputs '{...}'`, for what you changed. A run never
42
- passes through Studio's Start and stops at a task UI. On a tenant on the dev-eu1 cluster you can
43
- also drive a UI in a browser from Start to the result, as `references/browser-validation.md` next
44
- to this file describes; it is optional, and on any other tenant it is not possible. What you did
45
- not see run, report as not checked.
42
+ 7. **Prove it.** Run `wb-cli test [<module>]` when the module has tests, then `wb-cli run
43
+ <module>`, or `wb-cli run <module>/<task> --inputs '{...}'`, for what you changed. A run never
44
+ passes through Studio's Start and stops at a task UI. From a monorepo checkout, on a tenant on the
45
+ dev-eu1 cluster, you can also drive a UI in a browser from Start to the result, as
46
+ `references/browser-validation.md` next to this file describes; it is optional, and anywhere else
47
+ it is not possible. What you did not see run, report as not checked.
46
48
  8. **Report** the Studio workspace URL, the version, the files changed, the validate, test, run and
47
49
  browser results or why there were none, and what is left for the user in Studio.
48
50
 
49
51
  ## Credentials
50
52
 
51
- `bin/wb-cli login <host>` checks the tenant's token in `~/.config/beyondwork/credentials.json` and
53
+ `wb-cli login <host>` checks the tenant's token in `~/.config/beyondwork/credentials.json` and
52
54
  prints the user it belongs to; when there is none, it says what to ask the user for. You never
53
55
  handle the token: do not open the credentials file, source an environment file that holds one, ask
54
56
  for it, or put it in a command, because your transcript and the shell history are kept.
@@ -58,7 +60,7 @@ for it, or put it in a command, because your transcript and the shell history ar
58
60
  `main` is what is deployed; the CLI never writes it, and it is empty until the first deploy. A
59
61
  version `features/<name>` holds what was published with Update; each Studio workspace saves to its
60
62
  own `features/<name>@stream/<workspace-id>`. To continue work someone left in a workspace, clone the
61
- workspace URL (`bin/wb-cli branches <studio-url>` lists them); cloning `features/<name>` gives only
63
+ workspace URL (`wb-cli branches <studio-url>` lists them); cloning `features/<name>` gives only
62
64
  the published state. When the CLI refuses a push or a pull (exit 3), its message names the remedy.
63
65
 
64
66
  ## Row store
@@ -93,3 +93,11 @@ if [ -z "$OPEN" ] && [ "$("$W" run --wait-for "$RUN_ID" --json | jq -r .status)"
93
93
  echo "The run still waits for a person that no UI step drove: the recipe did not reach the result." >&2
94
94
  exit 3
95
95
  fi
96
+
97
+ # 7. The end of the run as Studio shows it: the graph, and the module's outputs behind its output
98
+ # node. A failure here leaves the proof of step 6 standing, so it does not fail the recipe.
99
+ if [ -z "$OPEN" ]; then
100
+ WB_WORKSPACE_URL="$WORKSPACE_URL" BW_SAML_COOKIE_FILE="$COOKIE_FILE" SHOTS_DIR="$SHOTS_DIR" BW_REPO="$REPO" \
101
+ WB_RESULT="$MODULE" WORKSPACE_ROOT="$REPO" "$REPO/bin/node" "$SCRIPT" ||
102
+ echo "No screenshot of the end of the run. Report the result view as not checked." >&2
103
+ fi
@@ -36,7 +36,9 @@ claim).
36
36
  final states and outputs.
37
37
  Every stop prints what to do.
38
38
  3. Look at every screenshot in `SHOTS_DIR`: a red-on-red label or a hidden button is in the picture
39
- and nowhere else. Compare the outputs with what the request asked for.
39
+ and nowhere else. The `result-*` screenshots show the end of the run in Studio, where module
40
+ outputs are raw data; a Space does not show them at all (`.skills/workblock-architecture`).
41
+ Compare the outputs with what the request asked for.
40
42
  4. When something is wrong, fix it in the checkout, push, and run the script again. After three
41
43
  rounds on the same problem, stop and report what still fails and what you tried.
42
44
 
@@ -13,16 +13,31 @@
13
13
  // WB_START_MODULE the module to start with Studio's Start button, the way a person does;
14
14
  // leave it unset when a run already waits at the UI (`bin/wb-cli run`)
15
15
  // WB_UI_STEP which UI of the run this is, 1 for the first; useTheUi gets it
16
+ // WB_RESULT the module that ran, after the run has ended: drive no UI, and screenshot
17
+ // the end of the run as Studio shows it, that module's graph and outputs.
18
+ // Run it from the checkout, whose manifest.yaml gives the module's id.
16
19
  //
17
20
  // Exit codes: 0 submitted or closed, 5 left open (a UI with its own actions and no Submit),
18
21
  // 2 login or page problem, 3 submit rejected or Start opened the generic input form, 4 no task
19
- // UI appeared, 1 anything else.
22
+ // UI appeared (with WB_RESULT: no graph appeared), 1 anything else.
20
23
  // After exit 0, read the outputs: from the checkout, `bin/wb-cli run --wait-for latest`.
21
24
 
22
25
  import { createRequire } from 'node:module';
23
26
  import fs from 'node:fs';
24
27
  import path from 'node:path';
25
28
 
29
+ const resultModule = process.env.WB_RESULT;
30
+ const resultMode = Boolean(resultModule);
31
+ const shotsDir = path.resolve(process.env.SHOTS_DIR ?? 'shots');
32
+ fs.mkdirSync(shotsDir, { recursive: true });
33
+ // The result screenshots have fixed names: remove an earlier run's before anything can fail, so
34
+ // none of them passes for this run's.
35
+ if (resultMode) {
36
+ for (const file of fs.readdirSync(shotsDir)) {
37
+ if (/^result-.*\.png$/.test(file)) fs.rmSync(path.join(shotsDir, file));
38
+ }
39
+ }
40
+
26
41
  // NODE_PATH does not apply to ESM `import`, so load Playwright through require from neui.
27
42
  const repo = process.env.BW_REPO ?? process.env.WORKSPACE_ROOT;
28
43
  if (!repo) throw new Error('Set BW_REPO (or WORKSPACE_ROOT) to the monorepo checkout.');
@@ -41,16 +56,18 @@ const url = process.env.WB_WORKSPACE_URL;
41
56
  const cookieFile = process.env.BW_SAML_COOKIE_FILE;
42
57
  const startModule = process.env.WB_START_MODULE;
43
58
  const uiStep = Number(process.env.WB_UI_STEP ?? '1');
44
- const shotsDir = path.resolve(process.env.SHOTS_DIR ?? 'shots');
45
59
  if (!url || !cookieFile) throw new Error('Set WB_WORKSPACE_URL and BW_SAML_COOKIE_FILE.');
46
60
  const host = new URL(url).hostname;
61
+ // Studio opens a workspace on the entrypoint module's graph. The result pass opens the graph of
62
+ // the module that ran instead, found in the checkout's manifest by its name.
63
+ const pageUrl = resultMode ? moduleGraphUrl(resultModule) : url;
47
64
  const cookie = fs.readFileSync(cookieFile, 'utf8').trim();
48
65
  if (!cookie) throw new Error(`${cookieFile} is empty: mint the cookie again with testcookies.`);
49
- fs.mkdirSync(shotsDir, { recursive: true });
50
66
 
51
67
  let shots = 0;
52
68
  async function shot(page, name) {
53
- const file = path.join(shotsDir, `ui${uiStep}-${String(++shots).padStart(2, '0')}-${name}.png`);
69
+ const prefix = resultMode ? 'result' : `ui${uiStep}`;
70
+ const file = path.join(shotsDir, `${prefix}-${String(++shots).padStart(2, '0')}-${name}.png`);
54
71
  await page.screenshot({ path: file });
55
72
  console.log(`screenshot ${file}`);
56
73
  }
@@ -109,6 +126,56 @@ async function pressStart(page, moduleName) {
109
126
  return 0;
110
127
  }
111
128
 
129
+ // A module matches as `wb-cli run` matches it: by its id, its name, or the directory name that the
130
+ // checkout gives it.
131
+ function moduleGraphUrl(selector) {
132
+ const lower = (name) => name.trim().toLowerCase();
133
+ const dir = (name) =>
134
+ path.basename(name).toLowerCase().replace(/[^a-z0-9.-]+/g, '_').replace(/^_+|_+$/g, '').replace(/^\.+/, '');
135
+ const { modules = [] } = require('yaml').parse(fs.readFileSync('manifest.yaml', 'utf8'));
136
+ const module = modules.find(
137
+ (m) => m.id === selector || lower(m.name) === lower(selector) || dir(m.name) === dir(selector),
138
+ );
139
+ if (!module) throw new Error(`No module "${selector}" in ./manifest.yaml. Run this from the checkout.`);
140
+ const graph = new URL(url);
141
+ graph.searchParams.set('v', 'graph');
142
+ graph.searchParams.set('m', module.id);
143
+ return graph.href;
144
+ }
145
+
146
+ // Screenshots the end of the run as Studio shows it: the graph, then the dialog that the module's
147
+ // output node opens, which lists every module output as raw data. A Space shows neither; there a
148
+ // person sees only the task UIs.
149
+ async function showResult(page) {
150
+ try {
151
+ await page.locator('.react-flow__node').first().waitFor({ timeout: 60_000 });
152
+ } catch {
153
+ await shot(page, 'no-graph');
154
+ console.error('No graph 60 s after the page loaded. Report the result view as not checked.');
155
+ return 4;
156
+ }
157
+ // Fit the whole graph, output node included, into the screenshot.
158
+ await page.getByRole('button', { name: 'fit view' }).click({ timeout: 5_000 }).catch(() => {});
159
+ await page.waitForTimeout(1_000);
160
+ await shot(page, 'graph');
161
+ const outputNode = page.locator('.react-flow__node-moduleOutput').first();
162
+ if ((await outputNode.count()) === 0) {
163
+ console.log('The module has no outputs: a person sees only its task UIs.');
164
+ return 0;
165
+ }
166
+ // The node's title button, pressed from the keyboard: Studio's floating graph toolbar can cover
167
+ // the node and take a mouse click.
168
+ await outputNode.getByRole('button').first().press('Enter');
169
+ const dialog = page.getByRole('dialog');
170
+ await dialog.waitFor();
171
+ // The values render in an editor that loads after the dialog opens; an output without a value
172
+ // shows none, so a timeout here still takes the screenshot.
173
+ await dialog.locator('.monaco-editor .view-lines').first().waitFor({ timeout: 15_000 }).catch(() => {});
174
+ await page.waitForTimeout(1_000);
175
+ await shot(page, 'outputs');
176
+ return 0;
177
+ }
178
+
112
179
  let browser;
113
180
  try {
114
181
  browser = await chromium.launch();
@@ -133,13 +200,15 @@ try {
133
200
  });
134
201
  page.on('pageerror', (e) => consoleLines.push(`pageerror: ${e.message}`));
135
202
 
136
- const response = await page.goto(url);
203
+ const response = await page.goto(pageUrl);
137
204
  if (response?.status() === 403) {
138
205
  console.error('403 Forbidden: the cookie email is not a user of this tenant. Use the email that `bin/wb-cli login <host>` prints.');
139
206
  exitCode = 2;
140
207
  } else if (new URL(page.url()).hostname !== host) {
141
208
  console.error(`Redirected to ${new URL(page.url()).hostname}: the cookie was rejected or expired. Mint a new one.`);
142
209
  exitCode = 2;
210
+ } else if (resultMode) {
211
+ exitCode = await showResult(page);
143
212
  } else {
144
213
  const started = startModule ? await pressStart(page, startModule) : 0;
145
214
  if (started !== 0) {
@@ -159,11 +228,13 @@ try {
159
228
  }
160
229
  if (exitCode !== 4) {
161
230
  await shot(page, 'ui-loaded');
231
+ // Taken while the iframe is still attached: a continue action pressed in useTheUi removes
232
+ // it, and looking it up afterwards would wait out the page timeout and fail.
233
+ const frameHandle = await frame.elementHandle();
162
234
  await useTheUi(page, ui, uiStep);
163
235
 
164
236
  // Studio shows Submit unless the UI set its own actions (bw.setActions). Then a continue
165
237
  // action pressed in useTheUi closes the UI, and anything else leaves it open.
166
- const frameHandle = await frame.elementHandle();
167
238
  const submit = page.getByRole('button', { name: 'Submit', exact: true });
168
239
  // A submit handler that throws shows "Submission rejected"; a server error "Failed to submit".
169
240
  const rejected = page.getByText('Submission rejected').or(page.getByText('Failed to submit')).first();