From b0f16de5d029ca029ba22b8110a3f33071cf8f46 Mon Sep 17 00:00:00 2001 From: Julius Marminge <51714798+juliusmarminge@users.noreply.github.com> Date: Fri, 20 Nov 2026 23:39:14 -0800 Subject: [PATCH] feat(skills): launch videos can stage file edits, commits and MCP sign-in The fake Claude now edits real files, answers T3's title and commit-message generation, plays other MCP servers' tools, and reports a server that needs a sign-in through the SDK's sign-in control requests. createProject can make a folder of several repositories with a fictional author. Beats keep open shadow roots (the diff viewer), and a hard cut no longer flashes black for one frame. Co-Authored-By: Claude Opus 5.5 --- .agents/skills/launch-video/SKILL.md | 24 +++- .agents/skills/launch-video/assets/kit.js | 6 +- .../launch-video/scripts/fake-claude.mjs | 120 ++++++++++++++++-- .../skills/launch-video/scripts/snapshot.mjs | 20 +++ .../skills/launch-video/scripts/stage-env.mjs | 36 +++--- .../stagings/linked-environments/serve.mjs | 7 +- 6 files changed, 177 insertions(+), 36 deletions(-) diff --git a/.agents/skills/launch-video/SKILL.md b/.agents/skills/launch-video/SKILL.md index 37d67577b9a26..842386c1df7f9 100644 --- a/.agents/skills/launch-video/SKILL.md +++ b/.agents/skills/launch-video/SKILL.md @@ -37,10 +37,21 @@ There are two ways to build one: - Agent turns: pass `claude: [turns]` to `prepareHome` and the real Claude provider runs `scripts/fake-claude.mjs` as its CLI, so the video shows Claude's logo, models, thinking and tool rows. Each turn is `{ match, steps }`: `think`, `text`, `bash` (+ `output`, `ms`), - `wait`, and `tool` (+ `input`), which calls that T3 MCP tool for real, e.g. - `delegate_task`. Match generated titles with a `{ match: "title", repeat: true }` turn. - `` is filled from the JSON file at `FAKE_CLAUDE_VARS`, for ids that change - every run. `fake-claude.log` in the home records the protocol, for debugging. + `wait`, `edit` (+ `old`, `new`) and `write` (+ `content`), which change the file for real + so diffs and checkpoints show them, and `tool` (+ `input`), which calls that T3 MCP tool + for real, e.g. `delegate_task`; with `server` and `output` it plays another MCP server's + tool instead. `` is filled from the JSON file at `FAKE_CLAUDE_VARS`, for ids + that change every run. `fake-claude.log` in the home records the protocol, for debugging. + - Titles, commit messages and branch names come from `claude -p --json-schema`: answer them + with `{ match, json }` turns, where `match` is tested against the schema plus the prompt + (`'"title"'`, `'"subject"[\\s\\S]*products\\.ts'`). Unanswered ones fail in the app. + - An MCP server that needs a sign-in: pass `claude: { turns, servers: [{ name, authUrl }] }`. + The fake answers Claude's `mcp_status`, `mcp_authenticate` and `mcp_oauth_callback_url`, + and remembers the sign-in across processes like the real CLI. + - `createProject(env, title, files, { repos: ["api", "web"] })` makes a plain folder of + several repositories. Staged repos commit as a fictional author. Keep staging homes + outside this checkout (e.g. `/home`): a project folder inside it shows this + checkout's branch. - Data a real flow can't produce cheaply goes into the app's own stores, never into pixels. `insertPeerLinks` writes link rows into a stopped server; `serveDescriptors` makes fake machines answer the reachability probe. The client's saved environments and routes live @@ -82,6 +93,11 @@ harness's task stop; it ends its servers' process groups. only on tailnet names. `serve.mjs` links to this machine's tailnet DNS name. - **Leaks.** Grep the beats for the real hostname, username and tailnet name before rendering. `snapshot.mjs` drops hidden inputs' values (they hold local paths). +- **Timeline rows** (`[data-timeline-row-id]`) are placed by a transform; `rise`/`pop` on one + replaces it and the row vanishes. Animate an element inside the row. +- **The app's own animations** (a running tool's shine) are frozen into the beat and seeked + with the story, which can leave text invisible. Cancel them in `setup()`: + `iframe.contentDocument.getAnimations().forEach((a) => a.cancel())`. - **Timing.** A replayed turn streams in real time (each frame delay caps at 2 s). Make a recording long enough for the drive to catch the state you need, and freeze beats on a timer when the UI summarises (a running command shows only "Running pnpm"). diff --git a/.agents/skills/launch-video/assets/kit.js b/.agents/skills/launch-video/assets/kit.js index 0f682543415a5..3be85be01aac7 100644 --- a/.agents/skills/launch-video/assets/kit.js +++ b/.agents/skills/launch-video/assets/kit.js @@ -160,7 +160,9 @@ window.Kit = (() => { const visible = (target, from, to = Infinity, fade = 0) => { const shown = from + fade; const open = !Number.isFinite(to); - const end = open ? shown + 1 : to; + // A closed window stays shown through `to`: when the next beat starts exactly on a frame, + // its first keyframe is still 0 there, and both hiding would flash black. + const end = open ? shown + 1 : to + 0.002; const keys = [ { offset: 0, opacity: 0 }, { offset: from / end, opacity: 0 }, @@ -169,7 +171,7 @@ window.Kit = (() => { ...(open ? [{ offset: 1, opacity: 1 }] : [ - { offset: Math.max(shown, to - 0.001) / end, opacity: 1 }, + { offset: Math.max(shown, to) / end, opacity: 1 }, { offset: 1, opacity: 0 }, ]), ]; diff --git a/.agents/skills/launch-video/scripts/fake-claude.mjs b/.agents/skills/launch-video/scripts/fake-claude.mjs index 4d1a83dacb8d6..de596f48ddd8e 100755 --- a/.agents/skills/launch-video/scripts/fake-claude.mjs +++ b/.agents/skills/launch-video/scripts/fake-claude.mjs @@ -4,6 +4,7 @@ // Script format: see the launch-video SKILL.md. FAKE_CLAUDE_LOG records every line. import * as NodeCrypto from "node:crypto"; import * as NodeFS from "node:fs"; +import * as NodePath from "node:path"; import * as NodeReadline from "node:readline"; const VERSION = "2.1.329"; @@ -28,7 +29,19 @@ const readJson = (file, fallback) => { return fallback; } }; -const script = readJson(process.env.FAKE_CLAUDE_SCRIPT ?? "", []); +// An array of turns, or { turns, servers } where servers are MCP servers that need a sign-in: +// [{ name, authUrl }]. Sign-in follows the SDK's mcp_authenticate / mcp_oauth_callback_url. +const loaded = readJson(process.env.FAKE_CLAUDE_SCRIPT ?? "", []); +const script = Array.isArray(loaded) ? loaded : (loaded.turns ?? []); +// Sign-ins outlive the process, like the real CLI's stored credentials. +const signedInFile = `${process.env.FAKE_CLAUDE_SCRIPT}.signed-in.json`; +const signedIn = new Set(readJson(signedInFile, [])); +const signInServers = new Map( + (Array.isArray(loaded) ? [] : (loaded.servers ?? [])).map((server) => [ + server.name, + { ...server, status: signedIn.has(server.name) ? "connected" : "needs-auth" }, + ]), +); const played = new Set(); const fill = (value) => { const vars = readJson(process.env.FAKE_CLAUDE_VARS ?? "", {}); @@ -47,6 +60,33 @@ const argValue = (name) => { const i = process.argv.indexOf(name); return i === -1 ? undefined : process.argv[i + 1]; }; + +// `-p --json-schema` is T3's text generation (titles, commit messages, branch names). It answers +// with the first `{ match, json }` turn whose regex matches the schema plus the prompt. +if (process.argv.includes("-p")) { + const schema = argValue("--json-schema") ?? ""; + let prompt = ""; + for await (const chunk of process.stdin) prompt += chunk; + log("print", { schema, prompt: prompt.slice(0, 2000) }); + const turn = script.find( + (t) => t.json && new RegExp(t.match ?? "", "i").test(`${schema}\n${prompt}`), + ); + if (!turn) { + console.error(`fake-claude: no json turn matches ${schema}`); + process.exit(1); + } + console.log( + JSON.stringify({ + type: "result", + subtype: "success", + is_error: false, + result: "", + structured_output: fill(turn.json), + session_id: NodeCrypto.randomUUID(), + }), + ); + process.exit(0); +} const sessionId = argValue("--session-id") ?? argValue("--resume") ?? NodeCrypto.randomUUID(); let model = argValue("--model") ?? "claude-opus-5-5"; const cwd = process.cwd(); @@ -164,6 +204,11 @@ const streamText = async (text, type = "text") => { }); }; +const serverStatuses = () => [ + ...Object.keys(mcpServers).map((name) => ({ name, status: "connected", scope: "dynamic" })), + ...[...signInServers.values()].map(({ name, status }) => ({ name, status, scope: "user" })), +]; + // One MCP tools/call over streamable HTTP against the server T3 registered. async function callTool(name, args) { const [serverName, server] = Object.entries(mcpServers).find(([, s]) => s.url) ?? []; @@ -205,9 +250,11 @@ async function callTool(name, args) { async function playTurn(prompt) { let index = script.findIndex( - (turn, i) => !played.has(i) && turn.match && new RegExp(turn.match, "i").test(prompt), + (turn, i) => + !played.has(i) && !turn.json && turn.match && new RegExp(turn.match, "i").test(prompt), ); - if (index === -1) index = script.findIndex((turn, i) => !played.has(i) && !turn.match); + if (index === -1) + index = script.findIndex((turn, i) => !played.has(i) && !turn.json && !turn.match); const turn = index === -1 ? { steps: [{ text: "Done." }] } : script[index]; if (index !== -1 && !turn.repeat) played.add(index); send({ @@ -217,7 +264,7 @@ async function playTurn(prompt) { claude_code_version: VERSION, cwd, tools: ["Bash", "Read", "Edit"], - mcp_servers: Object.keys(mcpServers).map((name) => ({ name, status: "connected" })), + mcp_servers: serverStatuses().map(({ name, status }) => ({ name, status })), model, permissionMode: "bypassPermissions", slash_commands: [], @@ -258,15 +305,36 @@ async function playTurn(prompt) { } if (step.tool) { const id = `toolu_${uuid().replaceAll("-", "").slice(0, 24)}`; - const serverName = Object.keys(mcpServers)[0] ?? "t3-code"; + // `server` names a scripted server whose answer is `output`; otherwise T3's own MCP runs it. + const serverName = step.server ?? Object.keys(mcpServers)[0] ?? "t3-code"; assistant([ { type: "tool_use", id, name: `mcp__${serverName}__${step.tool}`, input: step.input ?? {} }, ]); - const { text } = await callTool(step.tool, step.input ?? {}).catch((error) => ({ - text: String(error), - })); + if (step.server) await sleep(step.ms ?? 900); + const { text } = step.server + ? { text: step.output ?? "" } + : await callTool(step.tool, step.input ?? {}).catch((error) => ({ text: String(error) })); toolResult(id, [{ type: "text", text }]); } + // Real edits, so checkpoints and diffs show them. Paths are relative to the session's cwd. + if (step.edit || step.write) { + const id = `toolu_${uuid().replaceAll("-", "").slice(0, 24)}`; + const file = NodePath.resolve(cwd, step.edit ?? step.write); + const input = step.edit + ? { file_path: file, old_string: step.old, new_string: step.new } + : { file_path: file, content: step.content }; + assistant([{ type: "tool_use", id, name: step.edit ? "Edit" : "Write", input }]); + await sleep(step.ms ?? 700); + if (step.edit) { + const before = NodeFS.readFileSync(file, "utf8"); + if (!before.includes(step.old)) throw new Error(`${step.edit}: old text not found`); + NodeFS.writeFileSync(file, before.replace(step.old, step.new)); + } else { + NodeFS.mkdirSync(NodePath.dirname(file), { recursive: true }); + NodeFS.writeFileSync(file, step.content); + } + toolResult(id, `The file ${file} has been updated successfully.`); + } } send({ type: "result", @@ -304,6 +372,29 @@ const controlResponse = (request) => { return {}; case "get_usage": return { rate_limits_available: false, rate_limits: [] }; + case "mcp_status": + return { mcpServers: serverStatuses() }; + case "mcp_authenticate": { + const server = signInServers.get(request.serverName); + if (!server) throw new Error(`no MCP server ${request.serverName}`); + if (server.status === "connected") return { requiresUserAction: false }; + server.state = uuid(); + const url = new URL(server.authUrl); + url.searchParams.set("state", server.state); + return { authUrl: url.toString(), requiresUserAction: true }; + } + case "mcp_oauth_callback_url": { + const server = signInServers.get(request.serverName); + const state = new URL(request.callbackUrl).searchParams.get("state"); + if (!server || !server.state || state !== server.state) + throw new Error("callback is not from this sign-in"); + server.status = "connected"; + signedIn.add(server.name); + NodeFS.writeFileSync(signedInFile, JSON.stringify([...signedIn])); + return {}; + } + case "mcp_reconnect": + return {}; default: return {}; } @@ -321,14 +412,17 @@ input.on("line", (line) => { } log("in", message); if (message.type === "control_request") { - send({ - type: "control_response", - response: { + let response; + try { + response = { subtype: "success", request_id: message.request_id, response: controlResponse(message.request ?? {}), - }, - }); + }; + } catch (error) { + response = { subtype: "error", request_id: message.request_id, error: String(error) }; + } + send({ type: "control_response", response }); return; } if (message.type === "user") { diff --git a/.agents/skills/launch-video/scripts/snapshot.mjs b/.agents/skills/launch-video/scripts/snapshot.mjs index 8bef33d3622d5..bdf144afa2805 100644 --- a/.agents/skills/launch-video/scripts/snapshot.mjs +++ b/.agents/skills/launch-video/scripts/snapshot.mjs @@ -82,6 +82,26 @@ async function freeze(known) { }); for (const el of clone.querySelectorAll("script, noscript, style, link, base")) el.remove(); + // Open shadow roots (the diff viewer draws inside one) become declarative shadow DOM. + const shadowHtml = (root) => { + const sheets = [...root.adoptedStyleSheets] + .map((sheet) => { + try { + return [...sheet.cssRules].map((r) => r.cssText).join("\n"); + } catch { + return ""; + } + }) + .join("\n"); + const nested = [...root.querySelectorAll("*")].filter((el) => el.shadowRoot); + let inner = root.getHTML({ shadowRoots: nested.map((el) => el.shadowRoot) }); + return ``; + }; + source.forEach((el, i) => { + if (!el.shadowRoot) return; + copies[i].insertAdjacentHTML("afterbegin", shadowHtml(el.shadowRoot)); + }); + const head = clone.querySelector("head"); const styleEl = document.createElement("style"); styleEl.textContent = css; diff --git a/.agents/skills/launch-video/scripts/stage-env.mjs b/.agents/skills/launch-video/scripts/stage-env.mjs index daa9911656f43..0f7866b0819c5 100644 --- a/.agents/skills/launch-video/scripts/stage-env.mjs +++ b/.agents/skills/launch-video/scripts/stage-env.mjs @@ -223,26 +223,32 @@ export function cli(home, args) { ); } -/** A git repository under `home` registered as a project. Returns { projectId, workspace }. */ -export async function createProject(environment, title, files = { "README.md": "" }) { +/** + * A folder under `home` registered as a project. Returns { projectId, workspace }. The folder is + * one git repository, or with `repos` (folders relative to it) a plain folder holding those. + */ +export async function createProject( + environment, + title, + files = { "README.md": "" }, + { repos = ["."] } = {}, +) { const workspace = NodePath.join(environment.home, "workspaces", title); for (const [file, content] of Object.entries(files)) { NodeFS.mkdirSync(NodePath.dirname(NodePath.join(workspace, file)), { recursive: true }); NodeFS.writeFileSync(NodePath.join(workspace, file), content); } - const git = (...args) => NodeChildProcess.execFileSync("git", args, { cwd: workspace }); - git("init", "--quiet", "--initial-branch=main"); - git("add", "--all"); - git( - "-c", - "user.name=Staging", - "-c", - "user.email=staging@example.invalid", - "commit", - "--quiet", - "-m", - "Initial commit", - ); + for (const repo of repos) { + const cwd = NodePath.join(workspace, repo); + NodeFS.mkdirSync(cwd, { recursive: true }); + const git = (...args) => NodeChildProcess.execFileSync("git", args, { cwd }); + git("init", "--quiet", "--initial-branch=main"); + // A fictional author, so commits made on camera work and never carry a real name. + git("config", "user.name", "Dana Reyes"); + git("config", "user.email", "dana@example.com"); + git("add", "--all"); + git("commit", "--quiet", "-m", "Initial commit"); + } const bearer = cli(environment.home, [ "auth", "session", diff --git a/.agents/skills/launch-video/stagings/linked-environments/serve.mjs b/.agents/skills/launch-video/stagings/linked-environments/serve.mjs index 6398daf2f24b5..8a26574044ed0 100644 --- a/.agents/skills/launch-video/stagings/linked-environments/serve.mjs +++ b/.agents/skills/launch-video/stagings/linked-environments/serve.mjs @@ -26,8 +26,11 @@ const tailnetName = JSON.parse( ).Self.DNSName.replace(/\.$/, ""); const linked = { linkedEnvironmentsEnabled: true }; -// Generated thread titles go through Claude too; answer them before any scripted turn can. -const title = (text) => ({ match: "title", repeat: true, steps: [{ text }] }); +// Generated thread titles; text generation runs the CLI with --json-schema. +const title = (text, match = "") => ({ + match: `"title"[\\s\\S]*${match}`, + json: { title: text, needsRefinement: false }, +}); const E2E_OUTPUT = `Running 144 tests using 8 workers ✘ checkout.spec.ts:42 › applies a coupon