Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
199 changes: 114 additions & 85 deletions demo-site/DEMO-SCRIPT.md

Large diffs are not rendered by default.

68 changes: 35 additions & 33 deletions demo-site/record/rehearse-act3.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
// A rehearsal of the demo's act 3 on a copy of demo-site/snowday-before: a fresh genclass.dev project (/start), its real
// Connect prompt plus the script's static-site line, then the script's three-change prompt (3c), both through Claude
// Code on Opus exactly as the recording does; then what Claude wrote is checked, and the five bugs are played on the
// result in guard (verify-snowday.mjs --src). No deploy: the copy stays in out/rehearsal-snowday.
// A rehearsal of the demo's act 3 on a copy of demo-site/snowday-before: a fresh genclass.dev project (/start), its
// Connect dialog with the act's choices ticked (Guard, Eager, Badge on the live site, Connect my coding agent to
// production; never Deploy), the prompt its Copy button holds, given to Claude Code on Opus exactly as the recording
// pastes it; then what Claude wrote is checked, and the five bugs are played on it in guard (verify-snowday.mjs --src,
// on port 8791 so the demo's dev server on 8788 keeps running). No deploy: the copy stays in out/rehearsal-snowday, and
// the MCP entry Claude adds for the agent link is removed at the end.
// Usage: node demo-site/record/rehearse-act3.mjs
import { spawnSync } from "node:child_process";
import { readFileSync, rmSync, writeFileSync } from "node:fs";
import { copyFileSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";
import { chromium } from "playwright";
Expand All @@ -13,10 +15,6 @@ const REC = dirname(fileURLToPath(import.meta.url));
const ROOT = join(REC, "..", "..");
const WORK = join(REC, "out", "rehearsal-snowday");
const sh = (cmd, cwd = ROOT) => spawnSync("bash", ["-lc", cmd], { cwd, encoding: "utf8", stdio: ["ignore", "pipe", "pipe"], maxBuffer: 50 * 1024 * 1024 });
const SCRIPT = readFileSync(join(ROOT, "demo-site", "DEMO-SCRIPT.md"), "utf8");
const block = (after) => { const i = SCRIPT.indexOf(after); const a = SCRIPT.indexOf("```text\n", i) + 8; return SCRIPT.slice(a, SCRIPT.indexOf("\n ```", a)).trim(); };
const STATIC_LINE = block("- **3a.**");
const PROMPT_3C = block("- **3c.**");

// ---------------------------------------------------------------------------------------------------- the project and its prompt
const browser = await chromium.launch({ headless: true });
Expand All @@ -27,41 +25,45 @@ await page.click("#go");
await page.waitForSelector("#dash", { state: "visible", timeout: 30000 });
const link = (await page.$eval("#dash", (a) => a.textContent)).trim();
await page.goto(`${link}#connect`, { waitUntil: "domcontentloaded" });
await page.waitForTimeout(3000);
const copied = (await page.locator('button:has-text("Copy the prompt for your coding agent")').first().getAttribute("data-copy")) ?? "";
await page.waitForSelector("#cchoices", { state: "visible", timeout: 15000 });
for (const k of ["guard", "eager", "badge", "agent"]) await page.check(`#cchoices [data-choice="${k}"]`);
const copied = (await page.getAttribute("#cpinstall", "data-copy")) ?? "";
await browser.close();
const token = (copied.match(/gc_[A-Za-z0-9]{22}/) ?? [""])[0];
console.log(`project: key ${token ? "found" : "MISSING"}, prompt ${copied.length} chars, overlay line ${copied.includes("mountDevtools") ? "yes" : "no"}`);
console.log(`project: key ${token ? "found" : "MISSING"}, prompt ${copied.length} chars, guard ${copied.includes('data-mode="guard"') ? "yes" : "no"}, agent link ${copied.includes("GENCLASS_DASHBOARD=") ? "yes" : "no"}, deploy ${copied.includes("Deploy it") ? "YES (should not be)" : "no"}`);

// ---------------------------------------------------------------------------------------------------- Claude, twice
// ---------------------------------------------------------------------------------------------------- Claude, once, with the copied prompt
rmSync(WORK, { recursive: true, force: true });
sh(`rsync -a --exclude .wrangler --exclude node_modules "${join(ROOT, "demo-site", "snowday-before")}/" "${WORK}/"`);
const claude = (prompt, cont) => {
const t0 = Date.now();
const r = sh(`export PATH="$HOME/.local/bin:$PATH"; claude -p ${JSON.stringify(prompt)} ${cont ? "--continue" : ""} --model opus --output-format json --permission-mode acceptEdits --allowedTools "Bash,Edit,Write,Read,Glob,Grep,WebFetch,mcp__genclass__*"`, WORK);
let out = ""; try { out = JSON.parse(r.stdout).result ?? r.stdout; } catch { out = r.stdout || r.stderr; }
console.log(`\n--- Claude (${Math.round((Date.now() - t0) / 1000)} s):\n${out.slice(0, 1800)}`);
};
claude(`${copied}\n\n${STATIC_LINE}`, false);
claude(PROMPT_3C, true);
for (const p of [8788, 8787, 5173]) sh(`lsof -nP -iTCP:${p} -sTCP:LISTEN -t | xargs -r kill 2>/dev/null; true`);
mkdirSync(WORK, { recursive: true });
sh(`git archive HEAD demo-site/snowday-before | tar -x -C "${WORK}" --strip-components=2`);
copyFileSync(join(ROOT, "demo-site", "snowday-before", "package.json"), join(WORK, "package.json"));
const t0 = Date.now();
const r = sh(`export PATH="$HOME/.local/bin:$PATH"; claude -p ${JSON.stringify(copied)} --model opus --output-format json --permission-mode acceptEdits --allowedTools "Bash,Edit,Write,Read,Glob,Grep,WebFetch"`, WORK);
let out = "";
try { out = JSON.parse(r.stdout).result ?? r.stdout; } catch { out = r.stdout || r.stderr; }
console.log(`\n--- Claude (${Math.round((Date.now() - t0) / 1000)} s):\n${out.slice(0, 1800)}`);
// leave nothing behind: the MCP entry with the agent link, servers started from the copy
// Claude saves it for this folder (under the repository's root) or, seeing that, for every project: remove both
sh(`export PATH="$HOME/.local/bin:$PATH"; claude mcp remove genclass -s local; claude mcp remove genclass -s user`, WORK);
for (const pid of sh("lsof -nP -iTCP -sTCP:LISTEN -Fp | tr -d p").stdout.split("\n").filter(Boolean)) {
if (sh(`lsof -a -p ${pid} -d cwd -Fn | grep ^n | cut -c2-`).stdout.trim().startsWith(WORK)) sh(`kill ${pid}`);
}

// ---------------------------------------------------------------------------------------------------- what Claude wrote
const html = readFileSync(join(WORK, "index.html"), "utf8");
const has = (name, ok) => console.log(` ${ok ? "ok " : "MISSING"} ${name}`);
console.log("\nindex.html:");
has("the project key", html.includes(token));
has("the project key", !!token && html.includes(token));
has("the GenClass runtime from the CDN", /cdn\.jsdelivr\.net\/npm\/@genclass\/runtime@/.test(html));
has("guard mode", /guard/.test(html));
has("guard mode", /data-mode="guard"|mode:\s*["']guard/.test(html));
has("eager", /eager/.test(html));
has("visual fixes", /fix:\s*true|data-visual|visual/.test(html));
has("the devtools overlay", /devtools/.test(html));
has("the boards atom", /atom\(\s*["']boards["']/.test(html));
has("the agent link for localhost", /connectAgent/.test(html));
has(".mcp.json", (() => { try { return readFileSync(join(WORK, ".mcp.json"), "utf8").includes("@genclass/mcp"); } catch { return false; } })());
writeFileSync(join(REC, "out", "rehearsal-head.txt"), html.slice(0, html.indexOf("</head>")));
has("visual fixes", /data-visual="fix"|fix:\s*true/.test(html));
has("the overlay on every host", /data-devtools(?!="local")|mountDevtools|devtools:\s*true/.test(html));
has("the board search as one value (no separate boards.query key; an atom or one guarded key)", /\b(atom|guard)\(/.test(html) && !/boards\.query/.test(html));
has("the agent link for local hosts", /connectAgent/.test(html));
writeFileSync(join(REC, "out", "rehearsal-head.txt"), html.slice(0, html.indexOf('<meta name="viewport"')));

// ---------------------------------------------------------------------------------------------------- the five bugs on Claude's integration
console.log("\nthe five bugs on Claude's integration (its own mode: guard):");
const v = spawnSync(process.execPath, [join(REC, "verify-snowday.mjs"), "--src", WORK, "--keep"], { encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] });
console.log(v.stdout.split("\n").filter((l) => /^==|fixed|BROKEN|raw/.test(l)).join("\n"));
const v = spawnSync(process.execPath, [join(REC, "verify-snowday.mjs"), "--src", WORK, "--keep", "--port", "8791"], { encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] });
console.log(v.stdout.split("\n").filter((l) => /^==|fixed|BROKEN|guard:/.test(l)).join("\n"));
7 changes: 4 additions & 3 deletions demo-site/record/verify-snowday.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
// five bugs in observe (they must show) and in guard (they must not):
// 1 stale board search (the first letter's answer lands last) 2 double vote 3 white text on white
// 4 click block Predict leaves after a mistyped postal code 5 scroll lock the notice leaves behind
// Usage: node demo-site/record/verify-snowday.mjs [--keep] [--src <dir>] (--src: an already integrated copy, e.g.
// after the agent's fixes; the bugs are then expected fixed in observe too). Build the runtime first.
// Usage: node demo-site/record/verify-snowday.mjs [--keep] [--src <dir>] [--port <n>] (--src: an already integrated copy, e.g.
// after the agent's fixes; the bugs are then expected fixed in observe too; --port: not 8788, while the demo's dev server
// runs there). Build the runtime first.
import { spawn, spawnSync } from "node:child_process";
import { copyFileSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
import { dirname, join } from "node:path";
Expand All @@ -18,7 +19,7 @@ const args = process.argv.slice(2);
const SRC = args.includes("--src") ? args[args.indexOf("--src") + 1] : join(ROOT, "demo-site", "snowday-before");
const integrated = args.includes("--src");
const WORK = join(REC, "out", "verify-snowday");
const PORT = 8788;
const PORT = args.includes("--port") ? Number(args[args.indexOf("--port") + 1]) : 8788;
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
const sh = (cmd, cwd = ROOT) => spawnSync("bash", ["-lc", cmd], { cwd, encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] });

Expand Down
1 change: 1 addition & 0 deletions demo-site/snowday-before/.assetsignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ test
.mcp.json
.genclass
.vscode
.claude
15 changes: 15 additions & 0 deletions demo-site/snowday-before/.claude/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"model": "opus",
"permissions": {
"defaultMode": "acceptEdits",
"allow": [
"Bash(npx --yes wrangler@4 dev:*)",
"Bash(npx wrangler dev:*)",
"Bash(curl:*)",
"Bash(claude mcp add:*)",
"Bash(claude mcp get:*)",
"Bash(claude mcp list:*)",
"Bash(sleep:*)"
]
}
}
5 changes: 5 additions & 0 deletions demo-site/snowday-before/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
// The demo: the Claude logo at the top right of the editor opens Claude Code in a new terminal, a new conversation
// that loads the MCP servers added since (DEMO-SCRIPT.md, acts 3 and 6).
"claudeCode.useTerminal": true
}
1 change: 1 addition & 0 deletions demo-site/snowday-before/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "Predict whether there is going to be a snow day at Halton District School Board or not? This is for complete school closure. I want the community to come together and build this the best snow day predictor ever! If you want to add more data you can go here: https://toronto.weatherstats.ca/metrics/snow.html",
"main": "index.js",
"scripts": {
"deploy": "XDG_CONFIG_HOME=$HOME/.config-dizon CLOUDFLARE_ACCOUNT_ID=4daefdf7440d182204be114a9c9f5074 npx --yes wrangler@4 deploy",
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion demo-site/snowday-before/wrangler.jsonc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// The live Worker behind snowday-predictor.ca (Dizon account): same name, compatibility date and ASSETS binding.
// Deploy with XDG_CONFIG_HOME=~/.config-dizon CLOUDFLARE_ACCOUNT_ID=4daefdf7440d182204be114a9c9f5074 npx wrangler@4 deploy
// Deploy with npm run deploy (package.json: wrangler with the Dizon login, XDG_CONFIG_HOME=~/.config-dizon).
{
"name": "snowday-predictor",
"main": "worker.js",
Expand Down
Loading