create-waygraph 0.0.4 → 0.0.6

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/README.md CHANGED
@@ -1,10 +1,16 @@
1
1
  # create-waygraph
2
2
 
3
+ **Deprecated.** This was always the identical scaffold as `npx waygraph init <name>`
4
+ (waygraph >= 0.12.7) - a second package to install and keep in sync for no actual benefit.
5
+ Use `npx waygraph init <name>` instead. This package still works (unpublishing would break
6
+ anyone with it pinned), but gets no further updates and is no longer linked from waygraph's
7
+ own docs/GitHub Pages.
8
+
9
+ ---
10
+
3
11
  Scaffolds a new [waygraph](https://github.com/deviate-dv8/waygraph) **offline** project -
4
12
  one fixed shape, no prompts, no template picker.
5
13
 
6
- This is the scaffold command linked from
7
- [waygraph GitHub Pages](https://deviate-dv8.github.io/waygraph/) (`npx create-waygraph`).
8
14
  Same template as `npx waygraph init` (waygraph >= 0.12.6). For a live saucedemo walkthrough
9
15
  without creating a folder in your cwd, use `npx waygraph try demo` instead.
10
16
 
@@ -3,6 +3,12 @@ import { fileURLToPath } from "node:url";
3
3
  import path from "node:path";
4
4
  import fs from "node:fs";
5
5
 
6
+ console.error(
7
+ "create-waygraph is deprecated - it's the exact same scaffold as `npx waygraph init <name>`\n" +
8
+ "(waygraph >= 0.12.7), just as a second package to install/maintain for no benefit.\n" +
9
+ "Use `npx waygraph init <name>` instead. This still works for now.\n",
10
+ );
11
+
6
12
  const projectName = process.argv[2];
7
13
 
8
14
  if (!projectName) {
@@ -39,7 +45,7 @@ console.log(" npm test");
39
45
  console.log(" npx waygraph list");
40
46
  console.log(" npx waygraph check");
41
47
  console.log(" npx waygraph auto # headed panel");
42
- console.log(" npx waygraph demo src/flows/example.flow.ts");
48
+ console.log(" npx waygraph agent-dive --loop claude");
43
49
  console.log("");
44
- console.log("(Same offline scaffold as: npx waygraph init <name> - waygraph >= 0.10.6.)");
50
+ console.log("(Same offline scaffold as: npx waygraph init <name> - waygraph >= 0.12.7.)");
45
51
  console.log("(Live saucedemo: npx waygraph try auto | try demo - temp dir, not a scaffold.)");
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "create-waygraph",
3
- "version": "0.0.4",
4
- "description": "Scaffold a new waygraph project - package.json, tsconfig, playwright.config, and one working example flow.",
3
+ "version": "0.0.6",
4
+ "description": "Deprecated - identical to `npx waygraph init <name>`. Use that instead.",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "bin": {
@@ -1,10 +1,11 @@
1
1
  # __PROJECT_NAME__
2
2
 
3
- Offline waygraph scaffold (`data:` URL - no network for `npm test`).
3
+ Offline waygraph scaffold - Nav, Page hub, Method, Effect (`instanceOptions` for
4
+ `waygraph auto`), stubs/fixtures/YAP, mem keys.
4
5
 
5
6
  ## Layout
6
7
 
7
- See [STRUCTURE.md](./STRUCTURE.md). Package docs:
8
+ See [STRUCTURE.md](./STRUCTURE.md). Docs:
8
9
  https://deviate-dv8.github.io/waygraph/scaffold.html
9
10
 
10
11
  ## Commands
@@ -13,13 +14,15 @@ https://deviate-dv8.github.io/waygraph/scaffold.html
13
14
  npm install
14
15
  npx playwright install chromium
15
16
  npm test
16
- npm run list
17
- npm run check
18
- npm run demo # headed step (manual Next)
19
- npm run demo:auto-next
20
- npm run auto
17
+ npm run list && npm run check && npm run graph
18
+ npm run demo # exampleFlow (hello + YAP)
19
+ npm run demo:shop # Effect path (needs --data selectedItem)
20
+ npm run auto # headed explore - pick Add Alpha / …
21
21
  npm run auto:cli
22
+ npx waygraph agent-dive --loop claude # coding-agent defs (optional)
22
23
  ```
23
24
 
24
25
  Point `package.json` `waygraph.baseUrl` at your real app when you leave the
25
- `data:` demo. Keep route folders = app URLs (consumer layout).
26
+ fixture (and drop `scripts/with-fixture.mjs` wrappers). Keep route folders =
27
+ app URLs (consumer layout).
28
+ Offline fixture is HTTP `http://127.0.0.1:4177/home.html` (Flatpak-safe).
@@ -1,36 +1,61 @@
1
1
  # Offline scaffold layout (`waygraph init` / `create-waygraph`)
2
2
 
3
3
  Shipped under `templates/scaffold/` in the **waygraph** package.
4
- Same tree is what `npx waygraph init my-app` copies.
5
-
6
- Docs (readable in the package site): [docs/scaffold.html](../../docs/scaffold.html)
4
+ Docs: [docs/scaffold.html](../../docs/scaffold.html)
7
5
 
8
6
  ```text
9
7
  .
10
- ├── package.json # waygraph ^0.12.6, demo/run/auto scripts
11
- ├── playwright.config.ts
12
- ├── tsconfig.json
8
+ ├── package.json
13
9
  ├── STRUCTURE.md # this file
14
10
  ├── README.md
15
11
  ├── src/
16
12
  │ ├── blocks/
17
- │ │ ├── SITE-MAP.md # namespace map (consumer convention)
18
- │ │ └── demo-web/ # synthetic site (data: URL) - mirrors app "/"
13
+ │ │ ├── SITE-MAP.md
14
+ │ │ └── demo-web/ # synthetic "/" (HTTP fixture :4177)
19
15
  │ │ ├── NAV.md
20
- │ │ ├── nav-home.block.ts
16
+ │ │ ├── home.html # offline fixture (catalog + cart)
17
+ │ │ ├── demo-sel.ts
18
+ │ │ ├── nav-home.block.ts # Nav
19
+ │ │ ├── home.page.block.ts # Page hub (methods registry)
21
20
  │ │ └── methods/
22
- │ │ └── assert-hello.method.block.ts
21
+ │ │ ├── assert-hello.method.block.ts # Method + stubs + YAP
22
+ │ │ ├── add-item.effect.block.ts # Effect + instanceOptions (auto)
23
+ │ │ ├── remove-item.effect.block.ts # Effect + instanceOptions
24
+ │ │ └── clear-cart.method.block.ts # Method
23
25
  │ ├── states/
24
- │ │ └── demo.states.ts
26
+ │ │ ├── demo.states.ts
27
+ │ │ └── demo.mem-keys.ts # SelectedItem for Effect / auto
25
28
  │ └── flows/
26
- └── example.flow.ts # withTitle + withHighlightFixtures
29
+ ├── example.flow.ts # nav + assert (smoke)
30
+ │ └── shop.flow.ts # nav + add-item + clear (Effect path)
31
+ ├── scripts/
32
+ │ ├── fixture-server.mjs # serves home.html on :4177
33
+ │ └── with-fixture.mjs # start server + run waygraph auto/demo/run
27
34
  └── tests/
28
35
  └── example.spec.ts
29
36
  ```
30
37
 
31
- **Rule of thumb:** route folders = app URL folders; `/` lives at the namespace
32
- root (`demo-web/`). Methods hang under `methods/`. Chrome/shared UI would be
33
- `shared/chrome/` (not invented for this offline hello).
38
+ ## Features covered
39
+
40
+ | Feature | Where |
41
+ |---------|--------|
42
+ | Nav (`defineNavBlock`) | `nav-home.block.ts` |
43
+ | Page hub (`definePageBlock` + `methods`) | `home.page.block.ts` |
44
+ | Method (`defineMethodBlock`) | `assert-hello`, `clear-cart` |
45
+ | Effect + `instanceOptions` (auto menus) | `add-item`, `remove-item` |
46
+ | Mem (`keyGroup`) | `demo.mem-keys.ts` |
47
+ | `stubBefore` / `stubAfter` / `stubOnError` | all instruction blocks |
48
+ | Flow fixtures + title | `example.flow.ts`, `shop.flow.ts` |
49
+ | YAP slides | `assert-hello` |
50
+ | `withSessionReset` | `shop.flow.ts` |
51
+ | `waygraph auto` / `auto --cli` | `npm run auto` |
52
+ | `demo` / `run` / `list` / `check` / `graph` | `package.json` scripts |
53
+
54
+ ## Auto
55
+
56
+ ```bash
57
+ npm run auto # headed explore - pick Add Alpha / Add Beta from live DOM
58
+ npm run auto:cli # same menus in the terminal
59
+ ```
34
60
 
35
- Grow this into a real app by renaming `demo-web/` to your FE origin namespace
36
- and adding one folder per `page.tsx` URL. See package docs **Consumer layout**.
61
+ After `nav-home`, Effect blocks expose one menu row per visible Add/Remove button.
@@ -6,20 +6,25 @@
6
6
  "scripts": {
7
7
  "typecheck": "tsc --noEmit",
8
8
  "test": "playwright test",
9
+ "fixture": "node scripts/fixture-server.mjs",
9
10
  "list": "waygraph list",
10
11
  "check": "waygraph check",
11
- "auto": "waygraph auto",
12
- "auto:cli": "waygraph auto --cli",
13
- "demo": "waygraph demo --blocks exampleFlow",
14
- "demo:auto-next": "waygraph demo --blocks exampleFlow --auto-next --title \"Scaffold demo\"",
15
- "run": "waygraph run --blocks exampleFlow",
16
- "graph": "waygraph graph"
12
+ "graph": "waygraph graph",
13
+ "graph:mermaid": "waygraph graph --mermaid",
14
+ "auto": "node scripts/with-fixture.mjs waygraph auto",
15
+ "auto:cli": "node scripts/with-fixture.mjs waygraph auto --cli",
16
+ "demo": "node scripts/with-fixture.mjs waygraph demo --blocks exampleFlow",
17
+ "demo:auto-next": "node scripts/with-fixture.mjs waygraph demo --blocks exampleFlow --auto-next --title \"Scaffold hello\"",
18
+ "demo:shop": "node scripts/with-fixture.mjs waygraph demo --blocks shopFlow --data \"{\\\"demo.selectedItem\\\":{\\\"id\\\":\\\"alpha\\\",\\\"name\\\":\\\"Alpha\\\"}}\" --title \"Scaffold shop\"",
19
+ "demo:shop:auto-next": "node scripts/with-fixture.mjs waygraph demo --blocks shopFlow --auto-next --data \"{\\\"demo.selectedItem\\\":{\\\"id\\\":\\\"alpha\\\",\\\"name\\\":\\\"Alpha\\\"}}\"",
20
+ "run": "node scripts/with-fixture.mjs waygraph run --blocks exampleFlow",
21
+ "run:shop": "node scripts/with-fixture.mjs waygraph run --blocks shopFlow --data \"{\\\"demo.selectedItem\\\":{\\\"id\\\":\\\"alpha\\\",\\\"name\\\":\\\"Alpha\\\"}}\""
17
22
  },
18
23
  "waygraph": {
19
- "baseUrl": "about:blank"
24
+ "baseUrl": "http://127.0.0.1:4177"
20
25
  },
21
26
  "dependencies": {
22
- "waygraph": "^0.12.6"
27
+ "waygraph": "^0.12.7"
23
28
  },
24
29
  "devDependencies": {
25
30
  "@playwright/test": "^1.55.0",
@@ -1,12 +1,27 @@
1
1
  import { defineConfig } from "@playwright/test";
2
2
 
3
+ const FIXTURE_PORT = process.env.WAYGRAPH_FIXTURE_PORT || "4177";
4
+ const FIXTURE_HOST = process.env.WAYGRAPH_FIXTURE_HOST || "127.0.0.1";
5
+ const FIXTURE_ORIGIN = `http://${FIXTURE_HOST}:${FIXTURE_PORT}`;
6
+
3
7
  export default defineConfig({
4
8
  testDir: "./tests",
5
9
  fullyParallel: true,
6
10
  reporter: "list",
7
11
  use: {
12
+ baseURL: FIXTURE_ORIGIN,
8
13
  launchOptions: {
9
14
  executablePath: process.env.CHROME_PATH || process.env.CHROMIUM_PATH,
10
15
  },
11
16
  },
17
+ webServer: {
18
+ command: "node scripts/fixture-server.mjs",
19
+ url: `${FIXTURE_ORIGIN}/home.html`,
20
+ reuseExistingServer: !process.env.CI,
21
+ env: {
22
+ WAYGRAPH_FIXTURE_PORT: FIXTURE_PORT,
23
+ WAYGRAPH_FIXTURE_HOST: FIXTURE_HOST,
24
+ WAYGRAPH_FIXTURE_QUIET: "1",
25
+ },
26
+ },
12
27
  });
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Tiny static server for the offline scaffold fixture (home.html).
4
+ * Flatpak Chromium cannot open file:// under /tmp — HTTP localhost works.
5
+ */
6
+ import { createServer } from "node:http";
7
+ import { readFileSync, existsSync } from "node:fs";
8
+ import { join, dirname, extname, normalize } from "node:path";
9
+ import { fileURLToPath } from "node:url";
10
+
11
+ const ROOT = join(dirname(fileURLToPath(import.meta.url)), "../src/blocks/demo-web");
12
+ const PORT = Number(process.env.WAYGRAPH_FIXTURE_PORT || 4177);
13
+ const HOST = process.env.WAYGRAPH_FIXTURE_HOST || "127.0.0.1";
14
+
15
+ const TYPES = {
16
+ ".html": "text/html; charset=utf-8",
17
+ ".css": "text/css; charset=utf-8",
18
+ ".js": "text/javascript; charset=utf-8",
19
+ ".svg": "image/svg+xml",
20
+ ".png": "image/png",
21
+ };
22
+
23
+ const server = createServer((req, res) => {
24
+ const raw = (req.url || "/").split("?")[0] || "/";
25
+ const rel = raw === "/" ? "home.html" : raw.replace(/^\//, "");
26
+ const full = normalize(join(ROOT, rel));
27
+ if (!full.startsWith(ROOT) || !existsSync(full)) {
28
+ res.writeHead(404, { "content-type": "text/plain" });
29
+ res.end("not found");
30
+ return;
31
+ }
32
+ const type = TYPES[extname(full)] || "application/octet-stream";
33
+ res.writeHead(200, { "content-type": type });
34
+ res.end(readFileSync(full));
35
+ });
36
+
37
+ server.listen(PORT, HOST, () => {
38
+ if (process.env.WAYGRAPH_FIXTURE_QUIET !== "1") {
39
+ console.error(`waygraph fixture: http://${HOST}:${PORT}/home.html`);
40
+ }
41
+ });
@@ -0,0 +1,69 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Start fixture-server, run a child command, tear down on exit.
4
+ * Usage: node scripts/with-fixture.mjs [--] <cmd> [args...]
5
+ */
6
+ import { spawn } from "node:child_process";
7
+ import { dirname, join } from "node:path";
8
+ import { fileURLToPath } from "node:url";
9
+
10
+ const HERE = dirname(fileURLToPath(import.meta.url));
11
+ const PORT = process.env.WAYGRAPH_FIXTURE_PORT || "4177";
12
+ const HOST = process.env.WAYGRAPH_FIXTURE_HOST || "127.0.0.1";
13
+
14
+ const argv = process.argv.slice(2).filter((a) => a !== "--");
15
+ if (argv.length === 0) {
16
+ console.error("usage: node scripts/with-fixture.mjs <cmd> [args...]");
17
+ process.exit(1);
18
+ }
19
+
20
+ const env = {
21
+ ...process.env,
22
+ WAYGRAPH_FIXTURE_PORT: PORT,
23
+ WAYGRAPH_FIXTURE_HOST: HOST,
24
+ WAYGRAPH_FIXTURE_QUIET: "1",
25
+ WAYGRAPH_BASE_URL: process.env.WAYGRAPH_BASE_URL || `http://${HOST}:${PORT}`,
26
+ };
27
+
28
+ const server = spawn(process.execPath, [join(HERE, "fixture-server.mjs")], {
29
+ env,
30
+ stdio: ["ignore", "ignore", "inherit"],
31
+ });
32
+
33
+ function killServer() {
34
+ try {
35
+ server.kill("SIGTERM");
36
+ } catch {
37
+ /* ignore */
38
+ }
39
+ }
40
+
41
+ async function waitReady(ms = 5000) {
42
+ const url = `http://${HOST}:${PORT}/home.html`;
43
+ const start = Date.now();
44
+ while (Date.now() - start < ms) {
45
+ try {
46
+ const res = await fetch(url);
47
+ if (res.ok) return;
48
+ } catch {
49
+ /* retry */
50
+ }
51
+ await new Promise((r) => setTimeout(r, 50));
52
+ }
53
+ throw new Error(`fixture server not ready at ${url}`);
54
+ }
55
+
56
+ let code = 1;
57
+ try {
58
+ await waitReady();
59
+ const child = spawn(argv[0], argv.slice(1), { env, stdio: "inherit", shell: false });
60
+ code = await new Promise((resolve) => {
61
+ child.on("exit", (c, signal) => resolve(signal ? 1 : (c ?? 1)));
62
+ });
63
+ } catch (e) {
64
+ console.error(e instanceof Error ? e.message : String(e));
65
+ code = 1;
66
+ } finally {
67
+ killServer();
68
+ }
69
+ process.exit(code);
@@ -1,13 +1,12 @@
1
1
  # Site map (scaffold)
2
2
 
3
- Offline hello uses one synthetic namespace (`demo-web/`) and a `data:` home URL
4
- so `npm test` stays green without the network.
3
+ Offline catalog uses one synthetic namespace (`demo-web/`) and a local
4
+ `home.html` fixture so `npm test` / `waygraph auto` need no network.
5
5
 
6
6
  | Folder | URL | Notes |
7
7
  |--------|-----|-------|
8
- | `demo-web/` | `/` (synthetic) | Nav + methods for the hello page |
9
- | `demo-web/methods/` | same URL | On-page asserts / future form acts |
8
+ | `demo-web/` | `/` (synthetic) | Nav + Page hub + methods/effects |
9
+ | `demo-web/methods/` | same URL | assert, add/remove Effects, clear |
10
10
 
11
11
  When you wire a real app, rename `demo-web/` to your FE origin namespace and
12
- add one folder per real `page.tsx` route. Grouping dirs without a page get no
13
- `NAV.md`. Full contract: waygraph **Consumer layout** docs.
12
+ add one folder per real `page.tsx` route. See **Consumer layout** docs.
@@ -1,20 +1,29 @@
1
1
  # demo-web / (synthetic home)
2
2
 
3
- **URL:** `data:text/html,…` (offline hello - replace with your real `/`)
3
+ **URL:** `http://127.0.0.1:4177/home.html` (offline catalog via `scripts/fixture-server.mjs` - replace with your real `/`)
4
4
 
5
5
  ## Nav-to
6
6
 
7
7
  | From | Block | How |
8
8
  |------|-------|-----|
9
- | start | `nav-home` | `defineNavBlock` `url` → data HTML |
9
+ | start | `nav-home` | `defineNavBlock` `url` → home.html |
10
10
 
11
- ## Methods
11
+ ## Page hub
12
12
 
13
- | Block | Kind | Notes |
14
- |-------|------|-------|
15
- | `assert-hello` | Method | Verify heading; demo stubs + fixtures |
13
+ | Block | Checkpoint | Methods |
14
+ |-------|------------|---------|
15
+ | `page-home` | `Home` | add-item, remove-item, clear-cart, assert-hello |
16
+
17
+ ## Methods / Effects
18
+
19
+ | Block | Kind | Auto |
20
+ |-------|------|------|
21
+ | `assert-hello` | Method | single row |
22
+ | `add-item` | Effect | one row per live Add button (`instanceOptions`) |
23
+ | `remove-item` | Effect | one row per live Remove button |
24
+ | `clear-cart` | Method | single row |
16
25
 
17
26
  ## States / mem-keys
18
27
 
19
- - Checkpoint `Home` after nav
20
- - Checkpoint `HomeVerified` after assert-hello
28
+ - Checkpoints: `Home`, `HomeVerified`, `ItemInCart`, `CartEmpty`
29
+ - Mem: `demo.selectedItem` (`SelectedItem`) - filled by auto or `--data`
@@ -0,0 +1,14 @@
1
+ /** Offline catalog URL — HTTP fixture server (not file://; Flatpak Chromium blocks /tmp file URLs). */
2
+ export const HOME_URL =
3
+ process.env.WAYGRAPH_HOME_URL ??
4
+ `http://${process.env.WAYGRAPH_FIXTURE_HOST || "127.0.0.1"}:${process.env.WAYGRAPH_FIXTURE_PORT || "4177"}/home.html`;
5
+
6
+ export const DemoSel = {
7
+ title: "h1",
8
+ sub: "#sub",
9
+ cartCount: "[data-test=cart-count]",
10
+ catalog: "#catalog",
11
+ clear: "[data-test=clear-cart]",
12
+ addBtn: (id: string) => `[data-test=add-${id}]`,
13
+ removeBtn: (id: string) => `[data-test=remove-${id}]`,
14
+ } as const;
@@ -0,0 +1,65 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <title>Waygraph scaffold demo</title>
6
+ <style>
7
+ body { font-family: system-ui, sans-serif; margin: 2rem; max-width: 32rem; }
8
+ h1 { margin: 0 0 0.5rem; }
9
+ #cart { margin: 1rem 0; font-weight: 600; }
10
+ .item { display: flex; gap: 0.75rem; align-items: center; margin: 0.5rem 0; }
11
+ button { cursor: pointer; }
12
+ </style>
13
+ </head>
14
+ <body>
15
+ <h1>Hello Waygraph</h1>
16
+ <p id="sub">Scaffold demo - Effect / auto / Page hub</p>
17
+ <div id="cart">Cart: <span data-test="cart-count">0</span></div>
18
+ <ul id="catalog">
19
+ <li class="item" data-id="alpha">
20
+ <span class="name">Alpha</span>
21
+ <button type="button" data-test="add-alpha" class="add">Add Alpha</button>
22
+ <button type="button" data-test="remove-alpha" class="remove" hidden>Remove Alpha</button>
23
+ </li>
24
+ <li class="item" data-id="beta">
25
+ <span class="name">Beta</span>
26
+ <button type="button" data-test="add-beta" class="add">Add Beta</button>
27
+ <button type="button" data-test="remove-beta" class="remove" hidden>Remove Beta</button>
28
+ </li>
29
+ <li class="item" data-id="gamma">
30
+ <span class="name">Gamma</span>
31
+ <button type="button" data-test="add-gamma" class="add">Add Gamma</button>
32
+ <button type="button" data-test="remove-gamma" class="remove" hidden>Remove Gamma</button>
33
+ </li>
34
+ </ul>
35
+ <button type="button" data-test="clear-cart" id="clear">Clear cart</button>
36
+ <script>
37
+ const countEl = document.querySelector("[data-test=cart-count]");
38
+ const sync = () => {
39
+ const n = document.querySelectorAll(".remove:not([hidden])").length;
40
+ countEl.textContent = String(n);
41
+ };
42
+ document.querySelectorAll(".item").forEach((row) => {
43
+ const add = row.querySelector(".add");
44
+ const remove = row.querySelector(".remove");
45
+ add.addEventListener("click", () => {
46
+ add.hidden = true;
47
+ remove.hidden = false;
48
+ sync();
49
+ });
50
+ remove.addEventListener("click", () => {
51
+ remove.hidden = true;
52
+ add.hidden = false;
53
+ sync();
54
+ });
55
+ });
56
+ document.getElementById("clear").addEventListener("click", () => {
57
+ document.querySelectorAll(".item").forEach((row) => {
58
+ row.querySelector(".add").hidden = false;
59
+ row.querySelector(".remove").hidden = true;
60
+ });
61
+ sync();
62
+ });
63
+ </script>
64
+ </body>
65
+ </html>
@@ -0,0 +1,29 @@
1
+ import { definePageBlock, Trait } from "waygraph";
2
+ import type { Home } from "../../states/demo.states.js";
3
+ import { DemoSel } from "./demo-sel.js";
4
+ import { AddItemBlock } from "./methods/add-item.effect.block.js";
5
+ import { RemoveItemBlock } from "./methods/remove-item.effect.block.js";
6
+ import { ClearCartBlock } from "./methods/clear-cart.method.block.js";
7
+ import { AssertHelloBlock } from "./methods/assert-hello.method.block.js";
8
+
9
+ /**
10
+ * Kind: Page
11
+ * Helper: definePageBlock
12
+ * Route: demo-web/
13
+ *
14
+ * Hub for the offline home screen. Methods hang here for docs/auto grouping;
15
+ * edges in flows still reference the method Blocks directly.
16
+ * Arrival-only (nav-home already landed on Home).
17
+ */
18
+ export const HomePageBlock = definePageBlock<Home>({
19
+ name: "page-home",
20
+ description: "Offline home hub - add/remove effects, clear, assert-hello.",
21
+ checkpoint: "Home",
22
+ verify: [Trait.visible(DemoSel.catalog)],
23
+ methods: {
24
+ addItem: () => AddItemBlock,
25
+ removeItem: () => RemoveItemBlock,
26
+ clearCart: () => ClearCartBlock,
27
+ assertHello: () => AssertHelloBlock,
28
+ },
29
+ });
@@ -0,0 +1,68 @@
1
+ import {
2
+ defineEffectBlock,
3
+ checkpoint,
4
+ type Checkpoint,
5
+ type WaygraphInstanceOption,
6
+ } from "waygraph";
7
+ import type { ItemInCart } from "../../../states/demo.states.js";
8
+ import { SelectedItem } from "../../../states/demo.mem-keys.js";
9
+ import { DemoSel } from "../demo-sel.js";
10
+
11
+ /**
12
+ * Kind: Effect
13
+ * Helper: defineEffectBlock
14
+ * Route: demo-web/methods/
15
+ *
16
+ * Mutates one catalog row from mem. `waygraph auto` lists one "Add …" row per
17
+ * live Add button via instanceOptions.
18
+ */
19
+ export const AddItemBlock = defineEffectBlock<Checkpoint<string>, ItemInCart>({
20
+ name: "add-item",
21
+ description: "Adds the mem-selected catalog item to the cart.",
22
+ requires: [SelectedItem.key],
23
+ instruction: {
24
+ async act(page, _input, mem) {
25
+ const { id } = mem.get(SelectedItem.key);
26
+ await page.locator(DemoSel.addBtn(id)).click();
27
+ },
28
+ resolve: () => checkpoint("ItemInCart"),
29
+ verify: [
30
+ {
31
+ name: "item-added",
32
+ async check(page, mem) {
33
+ const { id } = mem.get(SelectedItem.key);
34
+ return page.locator(DemoSel.removeBtn(id)).isVisible();
35
+ },
36
+ },
37
+ ],
38
+ stubBefore: {
39
+ add: { selector: DemoSel.catalog, label: "Catalog" },
40
+ },
41
+ stubAfter: {
42
+ cart: { selector: DemoSel.cartCount, label: "Cart count", duration: true },
43
+ },
44
+ stubOnError: {
45
+ cart: { selector: DemoSel.cartCount, label: "Cart at failure", tag: "FAIL" },
46
+ },
47
+ },
48
+ async instanceOptions(page): Promise<readonly WaygraphInstanceOption[]> {
49
+ const buttons = page.locator("button.add:not([hidden])");
50
+ const n = await buttons.count();
51
+ const out: WaygraphInstanceOption[] = [];
52
+ for (let i = 0; i < n; i++) {
53
+ const btn = buttons.nth(i);
54
+ const label = ((await btn.textContent()) || "").trim();
55
+ const testId = await btn.getAttribute("data-test");
56
+ const id = (testId || "").replace(/^add-/, "");
57
+ if (!id) continue;
58
+ out.push({
59
+ id,
60
+ label: label || `Add ${id}`,
61
+ key: SelectedItem.key,
62
+ value: { id, name: id },
63
+ highlight: DemoSel.addBtn(id),
64
+ });
65
+ }
66
+ return out;
67
+ },
68
+ });
@@ -1,48 +1,47 @@
1
1
  import { defineMethodBlock, checkpoint, Trait } from "waygraph";
2
+ import { DemoSel } from "../demo-sel.js";
2
3
 
3
4
  /**
4
5
  * Kind: Method
5
6
  * Helper: defineMethodBlock
6
7
  * Route: demo-web/methods/
7
8
  *
8
- * Same-URL assert after nav - shows stubBefore / stubAfter / stubOnError shape.
9
+ * Same-URL assert after nav - stubs + fixtures + YAP slide.
9
10
  */
10
11
  export const AssertHelloBlock = defineMethodBlock({
11
12
  name: "assert-hello",
12
13
  description: "Confirms the hello heading is still visible after arrival.",
13
14
  instruction: {
14
- async act(_page) {
15
- // No DOM mutation - observe/verify own the proof.
16
- },
15
+ async act(_page) {},
17
16
  async observe(page) {
18
- await page.locator("h1").first().waitFor({ state: "visible", timeout: 5_000 });
17
+ await page.locator(DemoSel.title).first().waitFor({ state: "visible", timeout: 5_000 });
19
18
  return "ok" as const;
20
19
  },
21
20
  resolve: () => checkpoint("HomeVerified"),
22
- verify: [Trait.text("h1", "Hello Waygraph"), Trait.visible("#sub")],
21
+ verify: [Trait.text(DemoSel.title, "Hello Waygraph"), Trait.visible(DemoSel.sub)],
23
22
  stubBefore: {
24
- title: { selector: "h1", label: "Heading about to check" },
23
+ title: { selector: DemoSel.title, label: "Heading about to check" },
25
24
  },
26
25
  stubAfter: {
27
26
  title: {
28
- selector: "h1",
27
+ selector: DemoSel.title,
29
28
  label: "Hello confirmed",
30
29
  detail: "Offline scaffold proof point.",
31
30
  duration: true,
32
31
  },
33
- sub: { selector: "#sub", label: "Subcopy", duration: 1500 },
32
+ sub: { selector: DemoSel.sub, label: "Subcopy", duration: 1500 },
34
33
  },
35
34
  stubOnError: {
36
35
  title: {
37
- selector: "h1",
36
+ selector: DemoSel.title,
38
37
  label: "Heading at failure",
39
38
  tag: "FAIL",
40
39
  },
41
40
  },
42
41
  slides: [
43
42
  {
44
- caption: "Scaffold is route-shaped",
45
- detail: "demo-web/ = synthetic /. Grow folders per real page.tsx.",
43
+ caption: "Scaffold covers auto + narration",
44
+ detail: "Page hub, Effect instanceOptions, stubs, fixtures, YAP.",
46
45
  tag: "YAP",
47
46
  duration: true,
48
47
  },
@@ -0,0 +1,26 @@
1
+ import { defineMethodBlock, checkpoint, Trait } from "waygraph";
2
+ import { DemoSel } from "../demo-sel.js";
3
+
4
+ /**
5
+ * Kind: Method
6
+ * Helper: defineMethodBlock
7
+ * Route: demo-web/methods/
8
+ */
9
+ export const ClearCartBlock = defineMethodBlock({
10
+ name: "clear-cart",
11
+ description: "Clears every item via the Clear cart control.",
12
+ instruction: {
13
+ async act(page) {
14
+ await page.locator(DemoSel.clear).click();
15
+ },
16
+ resolve: () => checkpoint("CartEmpty"),
17
+ verify: [Trait.text(DemoSel.cartCount, "0")],
18
+ stubBefore: {
19
+ clear: { selector: DemoSel.clear, label: "Clear cart" },
20
+ },
21
+ stubAfter: {
22
+ cart: { selector: DemoSel.cartCount, label: "Empty cart", duration: true },
23
+ },
24
+ stubOnError: {},
25
+ },
26
+ });
@@ -0,0 +1,63 @@
1
+ import {
2
+ defineEffectBlock,
3
+ checkpoint,
4
+ type Checkpoint,
5
+ type WaygraphInstanceOption,
6
+ } from "waygraph";
7
+ import type { CartEmpty } from "../../../states/demo.states.js";
8
+ import { SelectedItem } from "../../../states/demo.mem-keys.js";
9
+ import { DemoSel } from "../demo-sel.js";
10
+
11
+ /**
12
+ * Kind: Effect
13
+ * Helper: defineEffectBlock
14
+ * Route: demo-web/methods/
15
+ *
16
+ * Removes one in-cart row. Auto menus one row per visible Remove button.
17
+ */
18
+ export const RemoveItemBlock = defineEffectBlock<Checkpoint<string>, CartEmpty>({
19
+ name: "remove-item",
20
+ description: "Removes the mem-selected catalog item from the cart.",
21
+ requires: [SelectedItem.key],
22
+ instruction: {
23
+ async act(page, _input, mem) {
24
+ const { id } = mem.get(SelectedItem.key);
25
+ await page.locator(DemoSel.removeBtn(id)).click();
26
+ },
27
+ resolve: () => checkpoint("CartEmpty"),
28
+ verify: [
29
+ {
30
+ name: "item-removed",
31
+ async check(page, mem) {
32
+ const { id } = mem.get(SelectedItem.key);
33
+ return page.locator(DemoSel.addBtn(id)).isVisible();
34
+ },
35
+ },
36
+ ],
37
+ stubBefore: {},
38
+ stubAfter: {
39
+ cart: { selector: DemoSel.cartCount, label: "Cart count", duration: true },
40
+ },
41
+ stubOnError: {},
42
+ },
43
+ async instanceOptions(page): Promise<readonly WaygraphInstanceOption[]> {
44
+ const buttons = page.locator("button.remove:not([hidden])");
45
+ const n = await buttons.count();
46
+ const out: WaygraphInstanceOption[] = [];
47
+ for (let i = 0; i < n; i++) {
48
+ const btn = buttons.nth(i);
49
+ const label = ((await btn.textContent()) || "").trim();
50
+ const testId = await btn.getAttribute("data-test");
51
+ const id = (testId || "").replace(/^remove-/, "");
52
+ if (!id) continue;
53
+ out.push({
54
+ id,
55
+ label: label || `Remove ${id}`,
56
+ key: SelectedItem.key,
57
+ value: { id, name: id },
58
+ highlight: DemoSel.removeBtn(id),
59
+ });
60
+ }
61
+ return out;
62
+ },
63
+ });
@@ -1,8 +1,5 @@
1
1
  import { defineNavBlock, Trait } from "waygraph";
2
-
3
- /** Offline hello page - swap `url` for a real app route when you graduate. */
4
- export const HOME_URL =
5
- 'data:text/html,<!doctype html><html><body><h1>Hello Waygraph</h1><p id="sub">Scaffold demo</p></body></html>';
2
+ import { DemoSel, HOME_URL } from "./demo-sel.js";
6
3
 
7
4
  /**
8
5
  * Kind: Nav
@@ -11,15 +8,15 @@ export const HOME_URL =
11
8
  */
12
9
  export const NavHomeBlock = defineNavBlock({
13
10
  name: "nav-home",
14
- description: "Opens the offline hello page (data: URL).",
11
+ description: "Opens the offline catalog page (HTTP fixture :4177).",
15
12
  checkpoint: "Home",
16
13
  url: HOME_URL,
17
- verify: [Trait.text("h1", "Hello Waygraph")],
14
+ verify: [Trait.text(DemoSel.title, "Hello Waygraph"), Trait.visible(DemoSel.catalog)],
18
15
  stubBefore: {},
19
16
  stubAfter: {
20
- title: { selector: "h1", label: "Home heading", duration: true },
17
+ title: { selector: DemoSel.title, label: "Home heading", duration: true },
21
18
  },
22
19
  stubOnError: {
23
- title: { selector: "h1", label: "Home heading at failure" },
20
+ title: { selector: DemoSel.title, label: "Home heading at failure" },
24
21
  },
25
22
  });
@@ -1,13 +1,12 @@
1
1
  import { Engine, start, end, withTitle, withHighlightFixtures } from "waygraph";
2
2
  import { NavHomeBlock } from "../blocks/demo-web/nav-home.block.js";
3
3
  import { AssertHelloBlock } from "../blocks/demo-web/methods/assert-hello.method.block.js";
4
+ // Page hub registered for auto/docs grouping (arrival-only after nav).
5
+ import "../blocks/demo-web/home.page.block.js";
4
6
 
5
7
  const engine = new Engine();
6
8
 
7
- /**
8
- * Offline example: nav to data: hello page, then assert heading.
9
- * Flow fixtures override ticket-style copy on stubs (demo narration).
10
- */
9
+ /** Smoke: nav + assert (no mem). Green offline. */
11
10
  export const exampleFlow = withHighlightFixtures(
12
11
  withTitle(
13
12
  engine.defineFlow([start, NavHomeBlock, AssertHelloBlock, end]),
@@ -0,0 +1,42 @@
1
+ import {
2
+ Engine,
3
+ start,
4
+ end,
5
+ withTitle,
6
+ withHighlightFixtures,
7
+ withSessionReset,
8
+ } from "waygraph";
9
+ import { NavHomeBlock } from "../blocks/demo-web/nav-home.block.js";
10
+ import { AddItemBlock } from "../blocks/demo-web/methods/add-item.effect.block.js";
11
+ import { ClearCartBlock } from "../blocks/demo-web/methods/clear-cart.method.block.js";
12
+ import "../blocks/demo-web/home.page.block.js";
13
+
14
+ const engine = new Engine();
15
+
16
+ /**
17
+ * Effect + Method demo (set mem for add-item, or use `waygraph auto` which
18
+ * fills SelectedItem via instanceOptions).
19
+ *
20
+ * waygraph demo --blocks shopFlow --data '{"demo.selectedItem":{"id":"alpha","name":"Alpha"}}'
21
+ * waygraph auto # after landing on home, pick Add Alpha / Add Beta / …
22
+ */
23
+ export const shopFlow = withHighlightFixtures(
24
+ withTitle(
25
+ withSessionReset(
26
+ engine.defineFlow([start, NavHomeBlock, AddItemBlock, ClearCartBlock, end]),
27
+ ),
28
+ "Scaffold: Shop (Effect + clear)",
29
+ ),
30
+ {
31
+ "add-item": {
32
+ stubAfter: {
33
+ cart: {
34
+ label: "AC · item in cart",
35
+ detail: "Cart count bumped after Add.",
36
+ tag: "AC",
37
+ duration: true,
38
+ },
39
+ },
40
+ },
41
+ },
42
+ );
@@ -0,0 +1,7 @@
1
+ import { keyGroup } from "waygraph";
2
+
3
+ /**
4
+ * Which catalog row `add-item` / `remove-item` act on.
5
+ * `waygraph auto` fills this via Effect `instanceOptions` (one menu row per live button).
6
+ */
7
+ export const SelectedItem = keyGroup<{ id: string; name: string }>("demo.selectedItem");
@@ -2,3 +2,5 @@ import type { Checkpoint } from "waygraph";
2
2
 
3
3
  export type Home = Checkpoint<"Home">;
4
4
  export type HomeVerified = Checkpoint<"HomeVerified">;
5
+ export type ItemInCart = Checkpoint<"ItemInCart">;
6
+ export type CartEmpty = Checkpoint<"CartEmpty">;
@@ -1,8 +1,17 @@
1
1
  import { test, expect } from "@playwright/test";
2
2
  import { MemPage, checkpoint } from "waygraph";
3
3
  import { exampleFlow } from "../src/flows/example.flow.js";
4
+ import { shopFlow } from "../src/flows/shop.flow.js";
5
+ import { SelectedItem } from "../src/states/demo.mem-keys.js";
4
6
 
5
7
  test("example flow reaches HomeVerified", async ({ context }) => {
6
8
  const result = await exampleFlow.run(context, new MemPage());
7
9
  expect(result).toEqual(checkpoint("HomeVerified"));
8
10
  });
11
+
12
+ test("shop flow adds then clears (Effect + Method)", async ({ context }) => {
13
+ const mem = new MemPage();
14
+ mem.set(SelectedItem.key, { id: "alpha", name: "Alpha" });
15
+ const result = await shopFlow.run(context, mem);
16
+ expect(result).toEqual(checkpoint("CartEmpty"));
17
+ });