Skip to content

Commit fe03849

Browse files
Merge remote-tracking branch 'origin/main' into codex/fix-android-language-switch
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2 parents d525204 + d63b9c4 commit fe03849

253 files changed

Lines changed: 7795 additions & 10882 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.agents/skills/launch-video/SKILL.md‎

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,25 @@ There are two ways to build one:
3737
- Agent turns: pass `claude: [turns]` to `prepareHome` and the real Claude provider runs
3838
`scripts/fake-claude.mjs` as its CLI, so the video shows Claude's logo, models, thinking
3939
and tool rows. Each turn is `{ match, steps }`: `think`, `text`, `bash` (+ `output`, `ms`),
40-
`wait`, and `tool` (+ `input`), which calls that T3 MCP tool for real, e.g.
41-
`delegate_task`. Match generated titles with a `{ match: "title", repeat: true }` turn.
42-
`<var:name>` is filled from the JSON file at `FAKE_CLAUDE_VARS`, for ids that change
43-
every run. `fake-claude.log` in the home records the protocol, for debugging.
40+
`wait`, `edit` (+ `old`, `new`) and `write` (+ `content`), which change the file for real
41+
so diffs and checkpoints show them, and `tool` (+ `input`), which calls that T3 MCP tool
42+
for real, e.g. `delegate_task`; with `server` and `output` it plays another MCP server's
43+
tool instead. `<var:name>` is filled from the JSON file at `FAKE_CLAUDE_VARS`, for ids
44+
that change every run. `bash` with `run: true` executes the command in the session's cwd
45+
(to push a branch or open a pull request with a forge CLI); `as: "name"` keeps its output,
46+
or the `pick` regex match in it, as `<var:name>` for the turn's later steps. A workflow
47+
`agent` step with `returns` finishes on `submit: { ... }`, which hands it that value
48+
through `t3_submit_output`. `fake-claude.log` in the home records the protocol, for debugging.
49+
- Titles, commit messages and branch names come from `claude -p --json-schema`: answer them
50+
with `{ match, json }` turns, where `match` is tested against the schema plus the prompt
51+
(`'"title"'`, `'"subject"[\\s\\S]*products\\.ts'`). Unanswered ones fail in the app.
52+
- An MCP server that needs a sign-in: pass `claude: { turns, servers: [{ name, authUrl }] }`.
53+
The fake answers Claude's `mcp_status`, `mcp_authenticate` and `mcp_oauth_callback_url`,
54+
and remembers the sign-in across processes like the real CLI.
55+
- `createProject(env, title, files, { repos: ["api", "web"] })` makes a plain folder of
56+
several repositories. Staged repos commit as a fictional author. Keep staging homes
57+
outside this checkout (e.g. `<out>/home`): a project folder inside it shows this
58+
checkout's branch.
4459
- Data a real flow can't produce cheaply goes into the app's own stores, never into pixels.
4560
`insertPeerLinks` writes link rows into a stopped server; `serveDescriptors` makes fake
4661
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.
8297
only on tailnet names. `serve.mjs` links to this machine's tailnet DNS name.
8398
- **Leaks.** Grep the beats for the real hostname, username and tailnet name before
8499
rendering. `snapshot.mjs` drops hidden inputs' values (they hold local paths).
100+
- **Timeline rows** (`[data-timeline-row-id]`) are placed by a transform; `rise`/`pop` on one
101+
replaces it and the row vanishes. Animate an element inside the row.
102+
- **The app's own animations** (a running tool's shine) are frozen into the beat and seeked
103+
with the story, which can leave text invisible. Cancel them in `setup()`:
104+
`iframe.contentDocument.getAnimations().forEach((a) => a.cancel())`.
85105
- **Timing.** A replayed turn streams in real time (each frame delay caps at 2 s). Make a
86106
recording long enough for the drive to catch the state you need, and freeze beats on a
87107
timer when the UI summarises (a running command shows only "Running pnpm").

‎.agents/skills/launch-video/assets/kit.js‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,9 @@ window.Kit = (() => {
160160
const visible = (target, from, to = Infinity, fade = 0) => {
161161
const shown = from + fade;
162162
const open = !Number.isFinite(to);
163-
const end = open ? shown + 1 : to;
163+
// A closed window stays shown through `to`: when the next beat starts exactly on a frame,
164+
// its first keyframe is still 0 there, and both hiding would flash black.
165+
const end = open ? shown + 1 : to + 0.002;
164166
const keys = [
165167
{ offset: 0, opacity: 0 },
166168
{ offset: from / end, opacity: 0 },
@@ -169,7 +171,7 @@ window.Kit = (() => {
169171
...(open
170172
? [{ offset: 1, opacity: 1 }]
171173
: [
172-
{ offset: Math.max(shown, to - 0.001) / end, opacity: 1 },
174+
{ offset: Math.max(shown, to) / end, opacity: 1 },
173175
{ offset: 1, opacity: 0 },
174176
]),
175177
];

‎.agents/skills/launch-video/scripts/fake-claude.mjs‎

Lines changed: 197 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
// A stand-in `claude` CLI for staged launch videos: T3's real Claude provider runs it, and it
33
// plays the scripted turns in FAKE_CLAUDE_SCRIPT over the Agent SDK's stream-json protocol.
44
// Script format: see the launch-video SKILL.md. FAKE_CLAUDE_LOG records every line.
5+
import * as NodeChildProcess from "node:child_process";
56
import * as NodeCrypto from "node:crypto";
67
import * as NodeFS from "node:fs";
8+
import * as NodePath from "node:path";
79
import * as NodeReadline from "node:readline";
810

911
const VERSION = "2.1.329";
@@ -28,10 +30,22 @@ const readJson = (file, fallback) => {
2830
return fallback;
2931
}
3032
};
31-
const script = readJson(process.env.FAKE_CLAUDE_SCRIPT ?? "", []);
33+
// An array of turns, or { turns, servers } where servers are MCP servers that need a sign-in:
34+
// [{ name, authUrl }]. Sign-in follows the SDK's mcp_authenticate / mcp_oauth_callback_url.
35+
const loaded = readJson(process.env.FAKE_CLAUDE_SCRIPT ?? "", []);
36+
const script = Array.isArray(loaded) ? loaded : (loaded.turns ?? []);
37+
// Sign-ins outlive the process, like the real CLI's stored credentials.
38+
const signedInFile = `${process.env.FAKE_CLAUDE_SCRIPT}.signed-in.json`;
39+
const signedIn = new Set(readJson(signedInFile, []));
40+
const signInServers = new Map(
41+
(Array.isArray(loaded) ? [] : (loaded.servers ?? [])).map((server) => [
42+
server.name,
43+
{ ...server, status: signedIn.has(server.name) ? "connected" : "needs-auth" },
44+
]),
45+
);
3246
const played = new Set();
33-
const fill = (value) => {
34-
const vars = readJson(process.env.FAKE_CLAUDE_VARS ?? "", {});
47+
const fill = (value, local = {}) => {
48+
const vars = { ...readJson(process.env.FAKE_CLAUDE_VARS ?? "", {}), ...local };
3549
const walk = (v) =>
3650
typeof v === "string"
3751
? v.replace(/<var:([\w-]+)>/g, (m, name) => vars[name] ?? m)
@@ -47,6 +61,33 @@ const argValue = (name) => {
4761
const i = process.argv.indexOf(name);
4862
return i === -1 ? undefined : process.argv[i + 1];
4963
};
64+
65+
// `-p --json-schema` is T3's text generation (titles, commit messages, branch names). It answers
66+
// with the first `{ match, json }` turn whose regex matches the schema plus the prompt.
67+
if (process.argv.includes("-p")) {
68+
const schema = argValue("--json-schema") ?? "";
69+
let prompt = "";
70+
for await (const chunk of process.stdin) prompt += chunk;
71+
log("print", { schema, prompt: prompt.slice(0, 2000) });
72+
const turn = script.find(
73+
(t) => t.json && new RegExp(t.match ?? "", "i").test(`${schema}\n${prompt}`),
74+
);
75+
if (!turn) {
76+
console.error(`fake-claude: no json turn matches ${schema}`);
77+
process.exit(1);
78+
}
79+
console.log(
80+
JSON.stringify({
81+
type: "result",
82+
subtype: "success",
83+
is_error: false,
84+
result: "",
85+
structured_output: fill(turn.json),
86+
session_id: NodeCrypto.randomUUID(),
87+
}),
88+
);
89+
process.exit(0);
90+
}
5091
const sessionId = argValue("--session-id") ?? argValue("--resume") ?? NodeCrypto.randomUUID();
5192
let model = argValue("--model") ?? "claude-opus-5-5";
5293
const cwd = process.cwd();
@@ -82,12 +123,12 @@ const assistant = (content, id = `msg_${uuid().replaceAll("-", "").slice(0, 24)}
82123
session_id: sessionId,
83124
uuid: uuid(),
84125
});
85-
const toolResult = (toolUseId, content, extra = {}) =>
126+
const toolResult = (toolUseId, content, extra = {}, isError = false) =>
86127
send({
87128
type: "user",
88129
message: {
89130
role: "user",
90-
content: [{ tool_use_id: toolUseId, type: "tool_result", content, is_error: false }],
131+
content: [{ tool_use_id: toolUseId, type: "tool_result", content, is_error: isError }],
91132
},
92133
parent_tool_use_id: null,
93134
session_id: sessionId,
@@ -164,6 +205,11 @@ const streamText = async (text, type = "text") => {
164205
});
165206
};
166207

208+
const serverStatuses = () => [
209+
...Object.keys(mcpServers).map((name) => ({ name, status: "connected", scope: "dynamic" })),
210+
...[...signInServers.values()].map(({ name, status }) => ({ name, status, scope: "user" })),
211+
];
212+
167213
// One MCP tools/call over streamable HTTP against the server T3 registered.
168214
async function callTool(name, args) {
169215
const [serverName, server] = Object.entries(mcpServers).find(([, s]) => s.url) ?? [];
@@ -205,9 +251,11 @@ async function callTool(name, args) {
205251

206252
async function playTurn(prompt) {
207253
let index = script.findIndex(
208-
(turn, i) => !played.has(i) && turn.match && new RegExp(turn.match, "i").test(prompt),
254+
(turn, i) =>
255+
!played.has(i) && !turn.json && turn.match && new RegExp(turn.match, "i").test(prompt),
209256
);
210-
if (index === -1) index = script.findIndex((turn, i) => !played.has(i) && !turn.match);
257+
if (index === -1)
258+
index = script.findIndex((turn, i) => !played.has(i) && !turn.json && !turn.match);
211259
const turn = index === -1 ? { steps: [{ text: "Done." }] } : script[index];
212260
if (index !== -1 && !turn.repeat) played.add(index);
213261
send({
@@ -217,7 +265,7 @@ async function playTurn(prompt) {
217265
claude_code_version: VERSION,
218266
cwd,
219267
tools: ["Bash", "Read", "Edit"],
220-
mcp_servers: Object.keys(mcpServers).map((name) => ({ name, status: "connected" })),
268+
mcp_servers: serverStatuses().map(({ name, status }) => ({ name, status })),
221269
model,
222270
permissionMode: "bypassPermissions",
223271
slash_commands: [],
@@ -229,44 +277,121 @@ async function playTurn(prompt) {
229277
session_id: sessionId,
230278
});
231279
let last = "";
232-
for (const step of fill(turn.steps)) {
233-
if (step.wait) await sleep(step.wait);
234-
if (step.think) await streamText(step.think, "thinking");
235-
if (step.text) {
236-
await streamText(step.text);
237-
last = step.text;
238-
}
239-
if (step.bash) {
240-
const id = `toolu_${uuid().replaceAll("-", "").slice(0, 24)}`;
241-
assistant([
242-
{
280+
// `as` keeps a step's real output for later steps of the turn, as <var:name>.
281+
const local = {};
282+
// The tool call awaiting its result, so a failing step can still answer it.
283+
let pending;
284+
const toolUse = (block) => {
285+
pending = block.id;
286+
assistant([block]);
287+
};
288+
const answer = (...args) => {
289+
toolResult(...args);
290+
pending = undefined;
291+
};
292+
try {
293+
for (const raw of turn.steps) {
294+
const filled = fill(raw, local);
295+
// `submit` hands a workflow agent step its typed result through T3's own MCP.
296+
const step = filled.submit
297+
? { ...filled, tool: "t3_submit_output", input: { json: JSON.stringify(filled.submit) } }
298+
: filled;
299+
if (step.wait) await sleep(step.wait);
300+
if (step.think) await streamText(step.think, "thinking");
301+
if (step.text) {
302+
await streamText(step.text);
303+
last = step.text;
304+
}
305+
if (step.bash) {
306+
const id = `toolu_${uuid().replaceAll("-", "").slice(0, 24)}`;
307+
toolUse({
243308
type: "tool_use",
244309
id,
245310
name: "Bash",
246311
input: { command: step.bash, description: step.description ?? step.bash },
247-
},
248-
]);
249-
await sleep(step.ms ?? 1200);
250-
toolResult(id, step.output ?? "", {
251-
tool_use_result: {
252-
stdout: step.output ?? "",
253-
stderr: "",
254-
interrupted: false,
255-
isImage: false,
256-
},
257-
});
258-
}
259-
if (step.tool) {
260-
const id = `toolu_${uuid().replaceAll("-", "").slice(0, 24)}`;
261-
const serverName = Object.keys(mcpServers)[0] ?? "t3-code";
262-
assistant([
263-
{ type: "tool_use", id, name: `mcp__${serverName}__${step.tool}`, input: step.input ?? {} },
264-
]);
265-
const { text } = await callTool(step.tool, step.input ?? {}).catch((error) => ({
266-
text: String(error),
267-
}));
268-
toolResult(id, [{ type: "text", text }]);
312+
});
313+
// `run` executes the command for real in the session's cwd, e.g. to push and open a PR.
314+
let output = step.output ?? "";
315+
if (step.run) {
316+
const started = Date.now();
317+
output = NodeChildProcess.execSync(step.bash, {
318+
cwd,
319+
encoding: "utf8",
320+
stdio: ["ignore", "pipe", "pipe"],
321+
}).trim();
322+
await sleep(Math.max(0, (step.ms ?? 1200) - (Date.now() - started)));
323+
} else await sleep(step.ms ?? 1200);
324+
if (step.as)
325+
local[step.as] = step.pick ? (new RegExp(step.pick).exec(output)?.[0] ?? output) : output;
326+
answer(id, output, {
327+
tool_use_result: {
328+
stdout: output,
329+
stderr: "",
330+
interrupted: false,
331+
isImage: false,
332+
},
333+
});
334+
}
335+
if (step.tool) {
336+
const id = `toolu_${uuid().replaceAll("-", "").slice(0, 24)}`;
337+
// `server` names a scripted server whose answer is `output`; otherwise T3's own MCP runs it.
338+
const serverName = step.server ?? Object.keys(mcpServers)[0] ?? "t3-code";
339+
toolUse({
340+
type: "tool_use",
341+
id,
342+
name: `mcp__${serverName}__${step.tool}`,
343+
input: step.input ?? {},
344+
});
345+
if (step.server) await sleep(step.ms ?? 900);
346+
const { text, isError = false } = step.server
347+
? { text: step.output ?? "" }
348+
: await callTool(step.tool, step.input ?? {}).catch((error) => ({
349+
text: String(error),
350+
isError: true,
351+
}));
352+
answer(id, [{ type: "text", text }], {}, isError);
353+
}
354+
// Real edits, so checkpoints and diffs show them. Paths are relative to the session's cwd.
355+
if (step.edit || step.write) {
356+
const id = `toolu_${uuid().replaceAll("-", "").slice(0, 24)}`;
357+
const file = NodePath.resolve(cwd, step.edit ?? step.write);
358+
const input = step.edit
359+
? { file_path: file, old_string: step.old, new_string: step.new }
360+
: { file_path: file, content: step.content };
361+
toolUse({ type: "tool_use", id, name: step.edit ? "Edit" : "Write", input });
362+
await sleep(step.ms ?? 700);
363+
if (step.edit) {
364+
const before = NodeFS.readFileSync(file, "utf8");
365+
if (!before.includes(step.old)) throw new Error(`${step.edit}: old text not found`);
366+
NodeFS.writeFileSync(file, before.replace(step.old, step.new));
367+
} else {
368+
NodeFS.mkdirSync(NodePath.dirname(file), { recursive: true });
369+
NodeFS.writeFileSync(file, step.content);
370+
}
371+
answer(id, `The file ${file} has been updated successfully.`);
372+
}
269373
}
374+
} catch (error) {
375+
// A scripted step that fails (an edit whose text is gone, a command that exits non-zero)
376+
// still ends the turn, as a failed one, so the app does not wait forever.
377+
log("step failed", String(error));
378+
if (pending) answer(pending, String(error.message ?? error), {}, true);
379+
send({
380+
type: "result",
381+
subtype: "error_during_execution",
382+
is_error: true,
383+
duration_ms: 4000,
384+
duration_api_ms: 3500,
385+
num_turns: 1,
386+
result: String(error.message ?? error),
387+
session_id: sessionId,
388+
total_cost_usd: 0,
389+
usage,
390+
modelUsage: {},
391+
permission_denials: [],
392+
uuid: uuid(),
393+
});
394+
return;
270395
}
271396
send({
272397
type: "result",
@@ -304,6 +429,29 @@ const controlResponse = (request) => {
304429
return {};
305430
case "get_usage":
306431
return { rate_limits_available: false, rate_limits: [] };
432+
case "mcp_status":
433+
return { mcpServers: serverStatuses() };
434+
case "mcp_authenticate": {
435+
const server = signInServers.get(request.serverName);
436+
if (!server) throw new Error(`no MCP server ${request.serverName}`);
437+
if (server.status === "connected") return { requiresUserAction: false };
438+
server.state = uuid();
439+
const url = new URL(server.authUrl);
440+
url.searchParams.set("state", server.state);
441+
return { authUrl: url.toString(), requiresUserAction: true };
442+
}
443+
case "mcp_oauth_callback_url": {
444+
const server = signInServers.get(request.serverName);
445+
const state = new URL(request.callbackUrl).searchParams.get("state");
446+
if (!server || !server.state || state !== server.state)
447+
throw new Error("callback is not from this sign-in");
448+
server.status = "connected";
449+
signedIn.add(server.name);
450+
NodeFS.writeFileSync(signedInFile, JSON.stringify([...signedIn]));
451+
return {};
452+
}
453+
case "mcp_reconnect":
454+
return {};
307455
default:
308456
return {};
309457
}
@@ -321,14 +469,17 @@ input.on("line", (line) => {
321469
}
322470
log("in", message);
323471
if (message.type === "control_request") {
324-
send({
325-
type: "control_response",
326-
response: {
472+
let response;
473+
try {
474+
response = {
327475
subtype: "success",
328476
request_id: message.request_id,
329477
response: controlResponse(message.request ?? {}),
330-
},
331-
});
478+
};
479+
} catch (error) {
480+
response = { subtype: "error", request_id: message.request_id, error: String(error) };
481+
}
482+
send({ type: "control_response", response });
332483
return;
333484
}
334485
if (message.type === "user") {

0 commit comments

Comments
 (0)