@beyondwork/wb-cli 0.1.29 → 0.1.31

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.31",
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,29 @@ 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. Drive what a person sees, from Start
45
+ through each task UI to the result, in a browser as `references/browser-validation.md` next to
46
+ this file describes. That needs a browser tool that acts where the user is signed in to the
47
+ tenant, or a monorepo checkout and a tenant on the dev-eu1 cluster. What you did not see run,
48
+ report as not checked.
46
49
  8. **Report** the Studio workspace URL, the version, the files changed, the validate, test, run and
47
50
  browser results or why there were none, and what is left for the user in Studio.
48
51
 
49
52
  ## Credentials
50
53
 
51
- `bin/wb-cli login <host>` checks the tenant's token in `~/.config/beyondwork/credentials.json` and
54
+ `wb-cli login <host>` checks the tenant's token in `~/.config/beyondwork/credentials.json` and
52
55
  prints the user it belongs to; when there is none, it says what to ask the user for. You never
53
56
  handle the token: do not open the credentials file, source an environment file that holds one, ask
54
57
  for it, or put it in a command, because your transcript and the shell history are kept.
@@ -58,9 +61,15 @@ for it, or put it in a command, because your transcript and the shell history ar
58
61
  `main` is what is deployed; the CLI never writes it, and it is empty until the first deploy. A
59
62
  version `features/<name>` holds what was published with Update; each Studio workspace saves to its
60
63
  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
64
+ workspace URL (`wb-cli branches <studio-url>` lists them); cloning `features/<name>` gives only
62
65
  the published state. When the CLI refuses a push or a pull (exit 3), its message names the remedy.
63
66
 
67
+ ## Other platform requests
68
+
69
+ `wb-cli api <verb> '<json>'` sends one request of the platform's WebSocket API as your user, for
70
+ what has no verb of its own: schedules, triggers, permissions, spaces, run data, the LLM calls of a
71
+ run. `wb-cli api --list <word>` finds the verb; `wb-cli api <verb> --describe` shows its arguments.
72
+
64
73
  ## Row store
65
74
 
66
75
  Workblock-scoped rows are shared by `main`, every version and every workspace of the workblock, so a
@@ -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
@@ -1,10 +1,16 @@
1
- # Browser validation from Start to the result (optional, dev tenants only)
1
+ # Browser validation from Start to the result
2
2
 
3
- `bin/wb-cli run` proves Python tasks by their outputs. It never passes through Studio's Start and it
3
+ `wb-cli run` proves Python tasks by their outputs. It never passes through Studio's Start and it
4
4
  parks at a task UI, so what a person sees, from Start through every UI to the result, is proven only
5
- in a browser. This check is optional. It works only on a tenant on the dev-eu1 cluster whose
6
- namespace secrets you can read, because it mints the session cookie with `testcookies`; on any
7
- other tenant, report the UI as not checked and hand over the workspace URL.
5
+ in a browser. Two routes drive one, and the checks are the same:
6
+
7
+ - **Your browser tool**, when your harness gives you one that acts in a browser where the user is
8
+ signed in to the tenant, such as Claude in Chrome in Claude Code or the ChatGPT browser extension
9
+ in the Codex desktop app. It works on any tenant.
10
+ - **The Playwright script** next to this file, from a monorepo checkout on a tenant on the dev-eu1
11
+ cluster whose namespace secrets you can read. It mints its own session cookie with `testcookies`.
12
+
13
+ With neither, report the UI as not checked and hand over the workspace URL.
8
14
 
9
15
  ## When
10
16
 
@@ -13,12 +19,44 @@ or first task, a change to a task UI (the component, its `render_ui` call, the d
13
19
  outputs it returns), and a run of the module you changed that reports `waiting`. "Should work" from
14
20
  the code or the type check is a guess: say what you saw and what you did not.
15
21
 
22
+ ## With your browser tool
23
+
24
+ The browser acts as the user with all of the user's rights, not only the token's scopes. Open only
25
+ this checkout's workspace, the URL that `wb-cli status` prints. Press only Start, the controls of the
26
+ task UIs, Submit and the details of a toast. Never press Deploy, never change sharing, permissions
27
+ or settings, and never delete anything. On a login page, stop and ask the user to sign in in that
28
+ browser; never type credentials. When your tool connects more than one browser, use the one that is
29
+ signed in to the tenant.
30
+
31
+ 1. Push, then run `wb-cli cancel`: while a run waits at a task UI, as `wb-cli run` leaves it,
32
+ Studio shows Stop instead of Start. Then open the workspace. The task UI runs in a sandboxed
33
+ iframe in a process of its own. While the tab is hidden, the clicks and keys that you send into
34
+ it are lost without an error, and screenshots still look right. So check that
35
+ `document.visibilityState` is `visible`, and when it is not, or a click into a task UI has no
36
+ effect, ask the user to bring the browser window to the front and keep it visible until you
37
+ finish.
38
+ 2. Press `Start <module>` or `Try changes` in the toolbar, or pick the module under `Start specific
39
+ module`. When Start opens the "Configure & Run module" form instead of a task UI, stop: the
40
+ module has inputs, which is a finding against step 3 of the skill, not a form to fill in.
41
+ 3. Use each task UI as a person would. Page reading (the accessibility tree, element search, form
42
+ input) may see nothing inside the iframe. Then take a screenshot, click by coordinates, type, and
43
+ zoom in to confirm that the text arrived. Submit and the other run controls are outside the
44
+ iframe, below it.
45
+ 4. A rejected Submit shows a "Submission rejected" toast for a few seconds. Its "View error details"
46
+ button opens the data that the component rejected, with the reason it threw.
47
+ 5. Look at a screenshot of every screen: a red-on-red label or a hidden button is in the picture and
48
+ nowhere else.
49
+ 6. When the run ends, `wb-cli run --wait-for latest` from the checkout prints the state and the
50
+ outputs of every task. Compare the outputs with what the request asked for. When no task UI
51
+ shows the result, a person sees the outputs only as raw data behind the module's output node in
52
+ Studio, and not at all in a Space (`.skills/workblock-architecture`).
53
+
54
+ ## With the Playwright script
55
+
16
56
  When the script stops for the tenant or the access, report the UI as not checked and hand over the
17
57
  workspace URL. Do not probe the access with `kubectl` yourself: a call against another context says
18
58
  `Forbidden` for reasons of its own.
19
59
 
20
- ## How
21
-
22
60
  `browser-run.sh` next to this file does every step in one shell; `validate-ui.mjs` is the Playwright
23
61
  script it runs. Copy both next to your checkout (not into it: the checkout lists files it does not
24
62
  claim).
@@ -36,9 +74,14 @@ claim).
36
74
  final states and outputs.
37
75
  Every stop prints what to do.
38
76
  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.
40
- 4. When something is wrong, fix it in the checkout, push, and run the script again. After three
41
- rounds on the same problem, stop and report what still fails and what you tried.
77
+ and nowhere else. The `result-*` screenshots show the end of the run in Studio, where module
78
+ outputs are raw data; a Space does not show them at all (`.skills/workblock-architecture`).
79
+ Compare the outputs with what the request asked for.
80
+
81
+ ## Fix and report
82
+
83
+ When something is wrong, fix it in the checkout, push, and run the check again. After three rounds
84
+ on the same problem, stop and report what still fails and what you tried.
42
85
 
43
86
  Report what you did in the browser, which screenshots you looked at, the outputs set against the
44
87
  request, and anything you could not check and why.
@@ -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();