diff --git a/.agents/skills/launch-video/SKILL.md b/.agents/skills/launch-video/SKILL.md index 37d67577b9a26..ec1e8a84daa60 100644 --- a/.agents/skills/launch-video/SKILL.md +++ b/.agents/skills/launch-video/SKILL.md @@ -37,10 +37,25 @@ 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. `bash` with `run: true` executes the command in the session's cwd + (to push a branch or open a pull request with a forge CLI); `as: "name"` keeps its output, + or the `pick` regex match in it, as `` for the turn's later steps. A workflow + `agent` step with `returns` finishes on `submit: { ... }`, which hands it that value + through `t3_submit_output`. `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 +97,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..02312bac813ba 100755 --- a/.agents/skills/launch-video/scripts/fake-claude.mjs +++ b/.agents/skills/launch-video/scripts/fake-claude.mjs @@ -2,8 +2,10 @@ // A stand-in `claude` CLI for staged launch videos: T3's real Claude provider runs it, and it // plays the scripted turns in FAKE_CLAUDE_SCRIPT over the Agent SDK's stream-json protocol. // Script format: see the launch-video SKILL.md. FAKE_CLAUDE_LOG records every line. +import * as NodeChildProcess from "node:child_process"; 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,10 +30,22 @@ 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 ?? "", {}); +const fill = (value, local = {}) => { + const vars = { ...readJson(process.env.FAKE_CLAUDE_VARS ?? "", {}), ...local }; const walk = (v) => typeof v === "string" ? v.replace(//g, (m, name) => vars[name] ?? m) @@ -47,6 +61,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(); @@ -82,12 +123,12 @@ const assistant = (content, id = `msg_${uuid().replaceAll("-", "").slice(0, 24)} session_id: sessionId, uuid: uuid(), }); -const toolResult = (toolUseId, content, extra = {}) => +const toolResult = (toolUseId, content, extra = {}, isError = false) => send({ type: "user", message: { role: "user", - content: [{ tool_use_id: toolUseId, type: "tool_result", content, is_error: false }], + content: [{ tool_use_id: toolUseId, type: "tool_result", content, is_error: isError }], }, parent_tool_use_id: null, session_id: sessionId, @@ -164,6 +205,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 +251,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 +265,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: [], @@ -229,44 +277,121 @@ async function playTurn(prompt) { session_id: sessionId, }); let last = ""; - for (const step of fill(turn.steps)) { - if (step.wait) await sleep(step.wait); - if (step.think) await streamText(step.think, "thinking"); - if (step.text) { - await streamText(step.text); - last = step.text; - } - if (step.bash) { - const id = `toolu_${uuid().replaceAll("-", "").slice(0, 24)}`; - assistant([ - { + // `as` keeps a step's real output for later steps of the turn, as . + const local = {}; + // The tool call awaiting its result, so a failing step can still answer it. + let pending; + const toolUse = (block) => { + pending = block.id; + assistant([block]); + }; + const answer = (...args) => { + toolResult(...args); + pending = undefined; + }; + try { + for (const raw of turn.steps) { + const filled = fill(raw, local); + // `submit` hands a workflow agent step its typed result through T3's own MCP. + const step = filled.submit + ? { ...filled, tool: "t3_submit_output", input: { json: JSON.stringify(filled.submit) } } + : filled; + if (step.wait) await sleep(step.wait); + if (step.think) await streamText(step.think, "thinking"); + if (step.text) { + await streamText(step.text); + last = step.text; + } + if (step.bash) { + const id = `toolu_${uuid().replaceAll("-", "").slice(0, 24)}`; + toolUse({ type: "tool_use", id, name: "Bash", input: { command: step.bash, description: step.description ?? step.bash }, - }, - ]); - await sleep(step.ms ?? 1200); - toolResult(id, step.output ?? "", { - tool_use_result: { - stdout: step.output ?? "", - stderr: "", - interrupted: false, - isImage: false, - }, - }); - } - if (step.tool) { - const id = `toolu_${uuid().replaceAll("-", "").slice(0, 24)}`; - const serverName = 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), - })); - toolResult(id, [{ type: "text", text }]); + }); + // `run` executes the command for real in the session's cwd, e.g. to push and open a PR. + let output = step.output ?? ""; + if (step.run) { + const started = Date.now(); + output = NodeChildProcess.execSync(step.bash, { + cwd, + encoding: "utf8", + stdio: ["ignore", "pipe", "pipe"], + }).trim(); + await sleep(Math.max(0, (step.ms ?? 1200) - (Date.now() - started))); + } else await sleep(step.ms ?? 1200); + if (step.as) + local[step.as] = step.pick ? (new RegExp(step.pick).exec(output)?.[0] ?? output) : output; + answer(id, output, { + tool_use_result: { + stdout: output, + stderr: "", + interrupted: false, + isImage: false, + }, + }); + } + if (step.tool) { + const id = `toolu_${uuid().replaceAll("-", "").slice(0, 24)}`; + // `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"; + toolUse({ + type: "tool_use", + id, + name: `mcp__${serverName}__${step.tool}`, + input: step.input ?? {}, + }); + if (step.server) await sleep(step.ms ?? 900); + const { text, isError = false } = step.server + ? { text: step.output ?? "" } + : await callTool(step.tool, step.input ?? {}).catch((error) => ({ + text: String(error), + isError: true, + })); + answer(id, [{ type: "text", text }], {}, isError); + } + // 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 }; + toolUse({ 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); + } + answer(id, `The file ${file} has been updated successfully.`); + } } + } catch (error) { + // A scripted step that fails (an edit whose text is gone, a command that exits non-zero) + // still ends the turn, as a failed one, so the app does not wait forever. + log("step failed", String(error)); + if (pending) answer(pending, String(error.message ?? error), {}, true); + send({ + type: "result", + subtype: "error_during_execution", + is_error: true, + duration_ms: 4000, + duration_api_ms: 3500, + num_turns: 1, + result: String(error.message ?? error), + session_id: sessionId, + total_cost_usd: 0, + usage, + modelUsage: {}, + permission_denials: [], + uuid: uuid(), + }); + return; } send({ type: "result", @@ -304,6 +429,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 +469,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..3f055927ebf7c 100644 --- a/.agents/skills/launch-video/scripts/snapshot.mjs +++ b/.agents/skills/launch-video/scripts/snapshot.mjs @@ -82,6 +82,49 @@ 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 sheetText = (root) => + [...root.adoptedStyleSheets] + .map((sheet) => { + try { + return [...sheet.cssRules].map((r) => r.cssText).join("\n"); + } catch { + return ""; + } + }) + .join("\n"); + const rootsIn = (root) => + [...root.querySelectorAll("*")] + .filter((el) => el.shadowRoot) + .flatMap((el) => [el.shadowRoot, ...rootsIn(el.shadowRoot)]); + const shadowHtml = (root) => { + const nested = rootsIn(root); + // Adopted sheets do not serialize. Each root gets them as its last