diff --git a/.agents/skills/launch-video/SKILL.md b/.agents/skills/launch-video/SKILL.md new file mode 100644 index 000000000000..82ef0bdd576d --- /dev/null +++ b/.agents/skills/launch-video/SKILL.md @@ -0,0 +1,167 @@ +--- +name: launch-video +description: Make a short launch video (1920x1080 MP4 plus an outro PNG) that demos a T3 Code feature, built from the real app with added motion, for an X/Twitter announcement or release thread. Use when asked for a launch video, demo video, feature teaser or announcement clip, or to add a video to a release tweet. +--- + +# Launch videos + +A launch video is 20–30 seconds: the app goes through one story in two or three beats, +the camera punches in on each, a caption names it, and an outro card closes. Frames are +rendered one by one in headless Chromium, so the result is deterministic. + +There are two ways to build one: + +- **Real app (default).** A staging script runs the real server and web client with fictional + data and the free replay agent, drives the flow in a browser, and freezes the page at each + beat into `beats/.html`. The story stacks those frozen pages and adds the motion: the + camera, cursor, pops, glows, typing and captions. The UI is whatever the app draws today, so + re-staging on main updates the video. `stagings/linked-environments/` is a finished example. +- **Mock.** `template/story.html` is a hand-built HTML copy of the app (the 0.1.11 tunnels + video). Use it only for what a staging can't produce, such as another app on the desktop or + a desktop-only screen. It drifts as the app changes. + +## Workflow (real app) + +1. **Learn the feature.** Read the PRs and the components it touches. Write down the one + thing a user can now do that they couldn't before, in the user's words. +2. **Write the story** before any code: who the user is, what they want, and two or three + beats that get them there. Show it to the maintainer if the angle is a guess. +3. **Stage it.** Copy `stagings/linked-environments/` to `stagings//`. + - `serve.mjs` builds fresh homes under `.t3/launch//` with `scripts/stage-env.mjs`. + Each home gets a fictional machine label, the replay agent, and no paid provider. + It starts the servers, creates projects, writes `/stage.json` and keeps running. + Run it in the background. + - `drive.mjs` opens the web client with `openBrowser()` (1440×720, dark, release + branding) and walks the flow. It calls `beat(name)` at each moment the video needs. + Re-run it as often as you like against the same servers. + - 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 `T3_DEV_REPLAY_VARS`, for ids that change + every run. `fake-claude.log` in the home records the protocol, for debugging. + - The free replay agent (`apps/server/scripts/dev-replay-agent.ts`) still works without + `claude`, but it shows as an ACP provider. +4. **Create the story:** `scripts/new.sh ~/launch-videos/`, then copy the beats in, or + pass that directory as the staging's ``. Add one ` + + + + + + + + + + + +
+ + + +
+ +
+
+ 1Delegate to another machine and it runs there. +
+
+ 2Watch it live without pairing. +
+
+ 3Connect to interact in one click. +
+ +
+
+ +

Linked environments
every machine, one app

+

Available now in T3 Code 0.1.12

+
t3.codes
+
+
+ + + + + diff --git a/.agents/skills/launch-video/template/real.html b/.agents/skills/launch-video/template/real.html new file mode 100644 index 000000000000..99be36d95345 --- /dev/null +++ b/.agents/skills/launch-video/template/real.html @@ -0,0 +1,263 @@ + + + + + + + + +
+
+
+
+ + +
+
+
+ + + +
+
+
+
+ 1Lead phrase and the rest. +
+
+
+
+ +

Feature name
second line

+

Available now in T3 Code 0.0.0

+
t3.codes
+
+
+ + + + + diff --git a/.agents/skills/launch-video/template/story.html b/.agents/skills/launch-video/template/story.html new file mode 100644 index 000000000000..85684dc7dcd2 --- /dev/null +++ b/.agents/skills/launch-video/template/story.html @@ -0,0 +1,2150 @@ + + + + + + + +
+
+
+
+
+
+ + + + +
T3 Code
+ + + + + + + + + +
+
+
+ MSacme/mugshotnow +
+
Spin up the dev stack
+
+ + devbox✳ +
+
+
+
+ MSacme/mugshot2h +
+
Fix avatar upload on Safari
+
+ + + + + fix/safari-avatar+42 + ✳ +
+
+
+
+ MSacme/mugshot5h +
+
Pricing page copy
+
+ + + + + copy/pricing+18 + + + ✳ +
+
+
+
+ INacme/infra1d +
+
Bump Postgres to 17
+
+ + + + + pg-17+7 + ✳ +
+
+
+
+ MSacme/mugshot2d +
+
Onboarding email tweaks
+
+ + + + + main + + + ✳ +
+
+
+
+ + + + + + + + + + + + + + +
+
+ +
+ MSmugshot/Spin up the dev stack +
+
+ + + + + + +
+ +
+
spin up the app and a postgres for it so I can poke at it
+
+
+ Working for 4sWorked for 9s +
+
+
+ + + + +
+ Running docker compose up -d dbRunning pnpm devRan 2 commands +
+
+
+ Both are up. The app is on localhost:3000, seeded from Postgres on + localhost:5432. +
+
+ +
+ Ask anything. @ files, $ skills, / commands +
+ spin up the app and a postgres for it so I can poke at it +
+
+ + + + ✳Opus 5.5 Medium + + + + + + + + +
+
+ +
+
+ + devbox + + + + + +
+
+ Dev + + +
+
+
+ + + + + main +
+
+ + + + + Changes Uncommitted+0 −0 +
+
+
Servers
+
+
+ + + + + +
+
localhost:5432
+
+ Agent · postgresForwarded to :5432 +
+
+
+
+ + + + + + + + + +
+
+
+
Forward to this machine, for any app here
+
+
+
+ + + + + +
+
localhost:3000
+
Agent · next-server
+
+
+
+
+ LimitsUnavailable +
+
+ +
+
+
+ + + + New tab + Mugshot admin✕ +
+
+ + +
+
+
+ + + + + + + + + +
+
+ + + + + + + + +
+ Search or enter a URLhttp://localhost:3000/admin +
+ + + + + + + + + + + +
+
+
+
+ +

Good morning.

+
+
+
Users
+
1,204+37 today
+
+
+
Mugs shot
+
8,911
+
+
+
+
NameEmailJoined
+
Ada Parkada@example.com2m ago
+
Sam Okaforsam@example.com14m ago
+
Lena Ruizlena@example.com1h ago
+
Mira Holtmira@example.com3h ago
+
+
+
+
✓
+
+
Forwarded port 5432
+
+ Apps on this machine reach it at localhost:5432. +
+
+
+
+
+
+ +
+
+
+ mugshot_dev — localhost:5432 + + on your Mac +
+
+
+
Tables
+
+ + + + users +
+
+ + + + mugs +
+
+ + + + sessions +
+
+ + + + _migrations +
+
+
+
+ users1,204 rowsLIMIT 300 +
+
+
+ idnameemailcreated_at +
+
+ 1204Ada Parkada@example.com2026-11-19 09:41 +
+
+ 1203Sam Okaforsam@example.com2026-11-19 09:29 +
+
+ 1202Lena Ruizlena@example.com2026-11-19 08:43 +
+
+ 1201Mira Holtmira@example.com2026-11-19 06:58 +
+
+ 1200Priya Nairpriya@example.com2026-11-18 22:10 +
+
+ 1199Jonas Bergjonas@example.com2026-11-18 19:37 +
+
+
+
+
New connection PostgreSQL
+
+ +
localhost
+
+
+ +
5432
+
+
+ +
app
+
+
+ +
mugshot_dev
+
+
+ TestConnect +
+
+
+
+ +
+ + + +
+
+ +
+
Ask an agent on a remote box to start your stack
+
+ 1Open a server + in the in-app browser. Tunnelled automatically. +
+
+ 2Forward a port and every app on your Mac can use it. +
+
+
+
+ +

Browser tunnels and
port forwarding

+

Available now in T3 Code 0.1.11

+
t3.codes
+
+
+ + + + diff --git a/apps/server/scripts/dev-replay-agent.ts b/apps/server/scripts/dev-replay-agent.ts index 2aa50e353f57..e3bb80f89083 100644 --- a/apps/server/scripts/dev-replay-agent.ts +++ b/apps/server/scripts/dev-replay-agent.ts @@ -1,5 +1,5 @@ #!/usr/bin/env node -// @effect-diagnostics nodeBuiltinImport:off globalTimers:off +// @effect-diagnostics nodeBuiltinImport:off globalTimers:off globalFetch:off /** * A free ACP agent for dev servers. It plays recorded ACP transcripts with simulated * streaming, so the real adapter, orchestration, and UI run without a paid model. @@ -69,6 +69,16 @@ export const SCENARIOS = [ name: "Command output", file: "./dev-replay/command_output_transcript.ndjson", }, + { + id: "delegate-remote", + name: "Delegate to a linked environment", + file: "./dev-replay/delegate_remote_transcript.ndjson", + }, + { + id: "remote-child", + name: "E2E suite run", + file: "./dev-replay/remote_child_transcript.ndjson", + }, ] as const; // Session setup and vendor state stay out: they would replace the replay agent's own models. @@ -84,8 +94,11 @@ const REPLAYED_UPDATES = new Set([ "usage_update", ]); +const MCP_CALL = "t3/mcp_call"; + // Only requests that ask the user. A replayed terminal/create would run a real command. -const REPLAYED_REQUESTS = new Set(["session/request_permission", "elicitation/create"]); +// `t3/mcp_call` is this agent's own: it calls a T3 tool over the session's MCP server. +const REPLAYED_REQUESTS = new Set(["session/request_permission", "elicitation/create", MCP_CALL]); const CHUNK_DELAY_MS = 30; const FRAME_DELAY_MS = 250; @@ -142,12 +155,35 @@ export function streamChunks(text: string): ReadonlyArray { return chunks.length === 0 ? [text] : chunks; } -/** Fills the live session, workspace, and per-prompt tool ids, so repeated turns add rows. */ +/** + * Values a recording can name as ``, read per turn from the JSON file at + * T3_DEV_REPLAY_VARS, for ids that change every run such as another environment's. + */ +function readReplayVars(): Record { + const file = process.env.T3_DEV_REPLAY_VARS; + if (file === undefined || file === "") return {}; + try { + return JSON.parse(NodeFS.readFileSync(file, "utf8")) as Record; + } catch { + return {}; + } +} + +/** Fills the live session, workspace, vars, and per-prompt tool ids, so repeated turns add rows. */ function materialize( value: unknown, - live: { readonly sessionId: string; readonly workspace: string; readonly turnKey: string }, + live: { + readonly sessionId: string; + readonly workspace: string; + readonly turnKey: string; + readonly vars: Record; + }, ): unknown { - if (typeof value === "string") return value.replaceAll("", live.workspace); + if (typeof value === "string") { + return value + .replaceAll("", live.workspace) + .replace(//g, (match, name: string) => live.vars[name] ?? match); + } if (Array.isArray(value)) return value.map((entry) => materialize(entry, live)); if (typeof value !== "object" || value === null) return value; return Object.fromEntries( @@ -176,6 +212,58 @@ function permissionRejectedToolCallId(request: LogicalFrame, answer: unknown): s return rejected ? params.toolCall?.toolCallId : undefined; } +interface McpServer { + readonly endpoint: string; + readonly authorization: string; +} + +/** The T3 MCP server T3 hands the agent in session/new, through the stdio bridge's env. */ +function t3McpServer(servers: unknown): McpServer | undefined { + if (!Array.isArray(servers)) return undefined; + for (const server of servers as ReadonlyArray<{ + env?: ReadonlyArray<{ name: string; value: string }>; + }>) { + const env = new Map((server.env ?? []).map((entry) => [entry.name, entry.value])); + const endpoint = env.get("T3_ACP_MCP_ENDPOINT"); + const authorization = env.get("T3_ACP_MCP_AUTHORIZATION"); + if (endpoint !== undefined && authorization !== undefined) return { endpoint, authorization }; + } + return undefined; +} + +/** One MCP tools/call over streamable HTTP: initialize, initialized, then the call. */ +async function callT3Tool(server: McpServer, name: string, args: unknown): Promise { + let sessionHeader: string | undefined; + const post = async (body: object) => { + const response = await fetch(server.endpoint, { + method: "POST", + headers: { + authorization: server.authorization, + accept: "application/json, text/event-stream", + "content-type": "application/json", + ...(sessionHeader === undefined ? {} : { "mcp-session-id": sessionHeader }), + }, + body: JSON.stringify({ jsonrpc: "2.0", ...body }), + }); + sessionHeader = response.headers.get("mcp-session-id") ?? sessionHeader; + const text = await response.text(); + // A streamed answer carries the JSON-RPC message on a `data:` line. + const data = text.split("\n").find((line) => line.startsWith("data:")); + return text.length === 0 ? undefined : JSON.parse(data === undefined ? text : data.slice(5)); + }; + await post({ + id: 1, + method: "initialize", + params: { + protocolVersion: "2025-06-18", + capabilities: {}, + clientInfo: { name: "t3-dev-replay", version: "1" }, + }, + }); + await post({ method: "notifications/initialized" }); + return post({ id: 2, method: "tools/call", params: { name, arguments: args } }); +} + function runAgent(): void { const turnsByScenario = new Map>(); const loadTurns = (scenarioId: string) => { @@ -191,7 +279,13 @@ function runAgent(): void { const sessions = new Map< string, - { cwd: string; model: string; promptCount: number; cancel: (() => void) | undefined } + { + cwd: string; + model: string; + promptCount: number; + cancel: (() => void) | undefined; + mcp: McpServer | undefined; + } >(); const pendingAgentRequests = new Map void>(); let nextAgentRequestId = 1; @@ -222,9 +316,33 @@ function runAgent(): void { ): Promise<"cancelled" | undefined> => { const session = sessions.get(sessionId)!; // Random, so a session loaded after a restart cannot reuse earlier tool rows. - const live = { sessionId, workspace: session.cwd, turnKey: NodeCrypto.randomUUID() }; + const live = { + sessionId, + workspace: session.cwd, + turnKey: NodeCrypto.randomUUID(), + vars: readReplayVars(), + }; for (const recorded of turn.frames) { const frame = materialize(recorded.frame, live) as LogicalFrame; + if (frame.kind === "request" && frame.method === MCP_CALL) { + await sleep(recorded.afterMs ?? FRAME_DELAY_MS, signal); + if (signal.aborted) return; + const call = frame.params as { name: string; arguments?: unknown }; + if (session.mcp === undefined) { + process.stderr.write(`dev replay agent has no T3 MCP server for ${call.name}\n`); + continue; + } + const result = await callT3Tool(session.mcp, call.name, call.arguments ?? {}).catch( + (error: unknown) => ({ error: String(error) }), + ); + const failed = result as { error?: unknown; result?: { isError?: boolean } } | undefined; + if (failed?.error !== undefined || failed?.result?.isError === true) { + process.stderr.write( + `dev replay agent: ${call.name} failed: ${JSON.stringify(result)}\n`, + ); + } + continue; + } if (frame.kind === "request") { await sleep(recorded.afterMs ?? FRAME_DELAY_MS, signal); if (signal.aborted) return; @@ -296,7 +414,13 @@ function runAgent(): void { const sessionId = message.method === "session/load" ? String(params.sessionId) : NodeCrypto.randomUUID(); const cwd = typeof params.cwd === "string" ? params.cwd : process.cwd(); - sessions.set(sessionId, { cwd, model: SCENARIOS[0].id, promptCount: 0, cancel: undefined }); + sessions.set(sessionId, { + cwd, + model: SCENARIOS[0].id, + promptCount: 0, + cancel: undefined, + mcp: t3McpServer(params.mcpServers), + }); return { ...(message.method === "session/new" ? { sessionId } : {}), models: { diff --git a/apps/server/scripts/dev-replay/delegate_remote_transcript.ndjson b/apps/server/scripts/dev-replay/delegate_remote_transcript.ndjson new file mode 100644 index 000000000000..59903a2421a6 --- /dev/null +++ b/apps/server/scripts/dev-replay/delegate_remote_transcript.ndjson @@ -0,0 +1,9 @@ +{"type": "transcript_start", "provider": "acpRegistry", "protocol": "acp.ndjson-jsonrpc", "version": "1", "scenario": "dev_replay_delegate_remote", "metadata": {"generatedBy": "hand-written for the dev replay agent"}} +{"type": "expect_outbound", "frame": {"kind": "request", "method": "session/prompt", "params": ""}} +{"type": "emit_inbound", "frame": {"kind": "notification", "method": "session/update", "params": {"sessionId": "dev-replay-session", "update": {"sessionUpdate": "agent_message_chunk", "content": {"type": "text", "text": "The full suite takes a while on this laptop, so I'll run it on devbox."}}}}} +{"type": "emit_inbound", "frame": {"kind": "request", "method": "t3/mcp_call", "params": {"name": "delegate_task", "arguments": {"title": "E2E suite", "task": "Run the e2e suite on main and report each failing spec with its error.", "target": {"environmentId": "", "projectId": "", "model": "remote-child"}}}}, "afterMs": 600} +{"type": "emit_inbound", "frame": {"kind": "notification", "method": "session/update", "params": {"sessionId": "dev-replay-session", "update": {"sessionUpdate": "agent_message_chunk", "content": {"type": "text", "text": "\n\nStarted **E2E suite** on devbox. I'll tell you what fails when it finishes."}}}}, "afterMs": 400} +{"type": "emit_inbound", "frame": {"kind": "response", "method": "session/prompt", "result": {"stopReason": "end_turn"}}} +{"type": "expect_outbound", "frame": {"kind": "request", "method": "session/prompt", "params": ""}} +{"type": "emit_inbound", "frame": {"kind": "notification", "method": "session/update", "params": {"sessionId": "dev-replay-session", "update": {"sessionUpdate": "agent_message_chunk", "content": {"type": "text", "text": "The suite finished on devbox: 144 specs ran and 2 failed.\n\n- `checkout.spec.ts` applies a coupon: the 10% coupon is applied after tax, so it charges $20.00 instead of $18.00.\n- `avatar.spec.ts` crops on Safari: times out waiting for the crop preview.\n\nWant me to fix the coupon first?"}}}}, "afterMs": 400} +{"type": "emit_inbound", "frame": {"kind": "response", "method": "session/prompt", "result": {"stopReason": "end_turn"}}} diff --git a/apps/server/scripts/dev-replay/remote_child_transcript.ndjson b/apps/server/scripts/dev-replay/remote_child_transcript.ndjson new file mode 100644 index 000000000000..adae1d4ccee9 --- /dev/null +++ b/apps/server/scripts/dev-replay/remote_child_transcript.ndjson @@ -0,0 +1,17 @@ +{"type": "transcript_start", "provider": "acpRegistry", "protocol": "acp.ndjson-jsonrpc", "version": "1", "scenario": "dev_replay_remote_child", "metadata": {"generatedBy": "hand-written for the dev replay agent"}} +{"type": "expect_outbound", "frame": {"kind": "request", "method": "session/prompt", "params": ""}} +{"type": "emit_inbound", "frame": {"kind": "notification", "method": "session/update", "params": {"sessionId": "dev-replay-session", "update": {"sessionUpdate": "agent_message_chunk", "content": {"type": "text", "text": "Installing dependencies, then running all 144 specs on 8 workers."}}}}, "afterMs": 300} +{"type": "emit_inbound", "frame": {"kind": "notification", "method": "session/update", "params": {"sessionId": "dev-replay-session", "update": {"sessionUpdate": "tool_call", "toolCallId": "install", "kind": "execute", "title": "pnpm install --frozen-lockfile", "status": "in_progress", "rawInput": {"command": "pnpm install --frozen-lockfile"}}}}, "afterMs": 600} +{"type": "emit_inbound", "frame": {"kind": "notification", "method": "session/update", "params": {"sessionId": "dev-replay-session", "update": {"sessionUpdate": "tool_call_update", "toolCallId": "install", "status": "completed", "rawOutput": "Packages: +1243\nDone in 18.4s\n"}}}, "afterMs": 2000} +{"type": "emit_inbound", "frame": {"kind": "notification", "method": "session/update", "params": {"sessionId": "dev-replay-session", "update": {"sessionUpdate": "tool_call", "toolCallId": "build", "kind": "execute", "title": "pnpm build", "status": "in_progress", "rawInput": {"command": "pnpm build"}}}}, "afterMs": 400} +{"type": "emit_inbound", "frame": {"kind": "notification", "method": "session/update", "params": {"sessionId": "dev-replay-session", "update": {"sessionUpdate": "tool_call_update", "toolCallId": "build", "status": "completed", "rawOutput": "✓ built in 6.2s\n"}}}, "afterMs": 2000} +{"type": "emit_inbound", "frame": {"kind": "notification", "method": "session/update", "params": {"sessionId": "dev-replay-session", "update": {"sessionUpdate": "tool_call", "toolCallId": "e2e", "kind": "execute", "title": "pnpm test:e2e", "status": "in_progress", "rawInput": {"command": "pnpm test:e2e"}}}}, "afterMs": 400} +{"type": "emit_inbound", "frame": {"kind": "notification", "method": "session/update", "params": {"sessionId": "dev-replay-session", "update": {"sessionUpdate": "tool_call_update", "toolCallId": "e2e", "status": "in_progress", "rawOutput": "Running 144 tests using 8 workers\n 24/144 done, 0 failed\n"}}}, "afterMs": 2000} +{"type": "emit_inbound", "frame": {"kind": "notification", "method": "session/update", "params": {"sessionId": "dev-replay-session", "update": {"sessionUpdate": "tool_call_update", "toolCallId": "e2e", "status": "in_progress", "rawOutput": "Running 144 tests using 8 workers\n 48/144 done, 1 failed\n"}}}, "afterMs": 2000} +{"type": "emit_inbound", "frame": {"kind": "notification", "method": "session/update", "params": {"sessionId": "dev-replay-session", "update": {"sessionUpdate": "tool_call_update", "toolCallId": "e2e", "status": "in_progress", "rawOutput": "Running 144 tests using 8 workers\n 72/144 done, 1 failed\n"}}}, "afterMs": 2000} +{"type": "emit_inbound", "frame": {"kind": "notification", "method": "session/update", "params": {"sessionId": "dev-replay-session", "update": {"sessionUpdate": "tool_call_update", "toolCallId": "e2e", "status": "in_progress", "rawOutput": "Running 144 tests using 8 workers\n 96/144 done, 1 failed\n"}}}, "afterMs": 2000} +{"type": "emit_inbound", "frame": {"kind": "notification", "method": "session/update", "params": {"sessionId": "dev-replay-session", "update": {"sessionUpdate": "tool_call_update", "toolCallId": "e2e", "status": "in_progress", "rawOutput": "Running 144 tests using 8 workers\n 120/144 done, 2 failed\n"}}}, "afterMs": 2000} +{"type": "emit_inbound", "frame": {"kind": "notification", "method": "session/update", "params": {"sessionId": "dev-replay-session", "update": {"sessionUpdate": "tool_call_update", "toolCallId": "e2e", "status": "in_progress", "rawOutput": "Running 144 tests using 8 workers\n 144/144 done, 2 failed\n"}}}, "afterMs": 2000} +{"type": "emit_inbound", "frame": {"kind": "notification", "method": "session/update", "params": {"sessionId": "dev-replay-session", "update": {"sessionUpdate": "tool_call_update", "toolCallId": "e2e", "status": "completed", "rawOutput": "Running 144 tests using 8 workers\n ✘ checkout.spec.ts:42 › applies a coupon\n Expected: \"$18.00\"\n Received: \"$20.00\"\n ✘ avatar.spec.ts:17 › crops on Safari\n Test timeout of 30000ms exceeded.\n\n 2 failed\n 142 passed (1.9m)\n"}}}, "afterMs": 1500} +{"type": "emit_inbound", "frame": {"kind": "notification", "method": "session/update", "params": {"sessionId": "dev-replay-session", "update": {"sessionUpdate": "agent_message_chunk", "content": {"type": "text", "text": "\n\n144 specs ran and 2 failed:\n\n- `checkout.spec.ts` applies a coupon: expected **$18.00**, got **$20.00**. The 10% coupon is applied after tax instead of before.\n- `avatar.spec.ts` crops on Safari: timed out after 30s waiting for the crop preview.\n\nThe other 142 passed."}}}}, "afterMs": 1200} +{"type": "emit_inbound", "frame": {"kind": "response", "method": "session/prompt", "result": {"stopReason": "end_turn"}}} diff --git a/apps/server/src/environment/ServerEnvironment.test.ts b/apps/server/src/environment/ServerEnvironment.test.ts index 3a9bfafb82ea..2bb7078ad4a2 100644 --- a/apps/server/src/environment/ServerEnvironment.test.ts +++ b/apps/server/src/environment/ServerEnvironment.test.ts @@ -4,6 +4,7 @@ import { ORCHESTRATION_PROTOCOL_VERSION } from "@t3tools/contracts"; import { expect, it } from "@effect/vitest"; import * as SecureRandom from "effect/crypto/SecureRandom"; import * as Deferred from "effect/Deferred"; +import * as ConfigProvider from "effect/ConfigProvider"; import * as Effect from "effect/Effect"; import * as FileSystem from "effect/FileSystem"; import * as Layer from "effect/Layer"; @@ -167,6 +168,35 @@ it.layer(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))("ServerEnvironmen }); }), ); + it.effect("names the environment and its machine from the overrides", () => + Effect.gen(function* () { + const fileSystem = yield* FileSystem.FileSystem; + const baseDir = yield* fileSystem.makeTempDirectoryScoped({ + prefix: "t3-server-environment-override-test-", + }); + const descriptor = yield* Effect.gen(function* () { + const serverEnvironment = yield* ServerEnvironment.ServerEnvironment; + return yield* serverEnvironment.getDescriptor; + }).pipe( + Effect.provide( + layerServerEnvironment(baseDir).pipe( + Layer.provide( + ConfigProvider.layer( + ConfigProvider.fromEnv({ + env: { + T3CODE_ENVIRONMENT_LABEL: " MacBook ", + T3CODE_ENVIRONMENT_MACHINE_KIND: "laptop", + }, + }), + ), + ), + ), + ), + ); + expect(descriptor.label).toBe("MacBook"); + expect(descriptor.platform.machine).toBe("laptop"); + }), + ); it.effect.each([ { platform: "darwin", architecture: "arm64", supported: true }, { platform: "linux", architecture: "x64", supported: true }, diff --git a/apps/server/src/environment/ServerEnvironmentLabel.ts b/apps/server/src/environment/ServerEnvironmentLabel.ts index b56c811d519c..f23321058172 100644 --- a/apps/server/src/environment/ServerEnvironmentLabel.ts +++ b/apps/server/src/environment/ServerEnvironmentLabel.ts @@ -1,4 +1,5 @@ import * as HostProcess from "@t3tools/shared/HostProcess"; +import * as Config from "effect/Config"; import * as Effect from "effect/Effect"; import * as FileSystem from "effect/FileSystem"; import * as Option from "effect/Option"; @@ -192,9 +193,20 @@ const isWsl = Effect.fn("isWsl")(function* () { return kernelRelease.toLowerCase().includes("microsoft"); }); +// Names this environment instead of the machine, e.g. for staged demos and scenario captures. +const labelOverride = Config.String("T3CODE_ENVIRONMENT_LABEL").pipe( + Config.option, + Config.map(Option.flatMap((label) => Option.fromNullishOr(normalizeLabel(label)))), +); + export const resolveServerEnvironmentLabel = Effect.fn("resolveServerEnvironmentLabel")(function* ( input: ResolveServerEnvironmentLabelInput, ) { + const override = yield* labelOverride.pipe(Effect.orElseSucceed(() => Option.none())); + if (Option.isSome(override)) { + return override.value; + } + const friendlyHostLabel = yield* resolveFriendlyHostLabel(); if (friendlyHostLabel) { return friendlyHostLabel; diff --git a/apps/server/src/environment/ServerEnvironmentMachine.ts b/apps/server/src/environment/ServerEnvironmentMachine.ts index 277592a9a48f..95ea0666cb09 100644 --- a/apps/server/src/environment/ServerEnvironmentMachine.ts +++ b/apps/server/src/environment/ServerEnvironmentMachine.ts @@ -1,7 +1,9 @@ -import type { EnvironmentMachineKind } from "@t3tools/contracts"; +import { EnvironmentMachineKind } from "@t3tools/contracts"; import * as HostProcess from "@t3tools/shared/HostProcess"; +import * as Config from "effect/Config"; import * as Effect from "effect/Effect"; import * as FileSystem from "effect/FileSystem"; +import * as Option from "effect/Option"; import * as ProcessRunner from "../processRunner.ts"; @@ -142,8 +144,20 @@ const detectLinuxMachineKind = Effect.fn("detectLinuxMachineKind")(function* () return machineKindFromDmi({ chassisType, sysVendor, productName }); }); +// Overrides detection, e.g. for staged demos on a VM that should read as a laptop. +const machineKindOverride = Config.schema( + EnvironmentMachineKind, + "T3CODE_ENVIRONMENT_MACHINE_KIND", +).pipe(Config.option); + export const detectServerEnvironmentMachineKind = Effect.fn("detectServerEnvironmentMachineKind")( function* () { + const override = yield* machineKindOverride.pipe( + Effect.orElseSucceed(() => Option.none()), + ); + if (Option.isSome(override)) { + return override.value; + } const platform = yield* HostProcess.Platform; switch (platform) { case "darwin": diff --git a/docs/operations/development.md b/docs/operations/development.md index 2e22dd6d3649..0492bab862e6 100644 --- a/docs/operations/development.md +++ b/docs/operations/development.md @@ -96,7 +96,9 @@ Dev servers add it back on start, so turn it off in Settings instead of removing To add a scenario, point a `SCENARIOS` entry at a generic ACP replay fixture (`registry_transcript.ndjson`) or a file in [dev-replay](../../apps/server/scripts/dev-replay). The agent replays session updates, permission requests, and questions. It drops session setup -and vendor frames, so Grok and fx recordings lose their vendor-only behavior. +and vendor frames, so Grok and fx recordings lose their vendor-only behavior. A `t3/mcp_call` +request frame (`{ name, arguments }`) makes the agent call that T3 tool itself over its MCP +session, and `` in any frame is filled from the JSON file at `T3_DEV_REPLAY_VARS`. ### Profiling dev startup diff --git a/scripts/scenarios/machine-switch-keeps-selected-models.e2e.ts b/scripts/scenarios/machine-switch-keeps-selected-models.e2e.ts index e4f96b5ffbf7..9071acc52a10 100644 --- a/scripts/scenarios/machine-switch-keeps-selected-models.e2e.ts +++ b/scripts/scenarios/machine-switch-keeps-selected-models.e2e.ts @@ -54,6 +54,8 @@ test( await dialog.getByPlaceholder("backend.example.com").fill(host); await dialog.getByPlaceholder("PAIRCODE").fill(token); await dialog.getByRole("button", "Add environment").tap(); + // The map is the default view; its rows carry no actions menu. + await screen.getByRole("button", "List", { exact: true }).tap(); await expect(screen.getByRole("button", "More actions for Scenario")).toBeVisible({ timeout: 60_000, }); diff --git a/scripts/scenarios/second-server.ts b/scripts/scenarios/second-server.ts index 190cc800e2bc..f08cf1fd98d2 100644 --- a/scripts/scenarios/second-server.ts +++ b/scripts/scenarios/second-server.ts @@ -12,7 +12,7 @@ import * as Path from "effect/Path"; import { APP_DIR, T3_HOME } from "../e2e.config.ts"; import { ScenarioError } from "./shell.ts"; -import { prepareHome, start } from "./start-app.ts"; +import { prepareHome, SCENARIO_MACHINE_ENV, start } from "./start-app.ts"; export const SECOND_HOME = `${T3_HOME}-second-environment`; @@ -47,6 +47,7 @@ const runSecondServer = Effect.fn("scenario.secondServer")(function* ( PATH: `${path.join(SECOND_HOME, "bin")}:${hostEnvironment.PATH ?? ""}`, HOME: hostEnvironment.HOME, T3CODE_AUTO_BOOTSTRAP_PROJECT_FROM_CWD: "0", + ...SCENARIO_MACHINE_ENV, }, onLine: (line) => { const value = /^Token:\s*(\S+)/.exec(line)?.[1]; diff --git a/scripts/scenarios/start-app.ts b/scripts/scenarios/start-app.ts index c22d6925281f..5dc7de246099 100644 --- a/scripts/scenarios/start-app.ts +++ b/scripts/scenarios/start-app.ts @@ -38,17 +38,11 @@ const REAL_PROVIDERS = [ "antigravity", ]; -// The server labels its environment with the host's name, probed through these commands. -// Captures must not depend on, or show, the machine that made them. -const HOST_LABEL_SHIM = `#!/bin/sh -case "$*" in - "--pretty" | "--get ComputerName") echo "Scenario" ;; - *) for real in /usr/bin /usr/sbin /bin; do - [ -x "$real/$(basename "$0")" ] && exec "$real/$(basename "$0")" "$@" - done - exit 127 ;; -esac -`; +/** Captures must not depend on, or show, the machine that made them. */ +export const SCENARIO_MACHINE_ENV = { + T3CODE_ENVIRONMENT_LABEL: "Scenario", + T3CODE_ENVIRONMENT_MACHINE_KIND: "laptop", +}; const encodeSettings = Schema.encodeEffect(Schema.fromJsonString(Schema.Unknown)); @@ -58,11 +52,6 @@ export const prepareHome = Effect.fn("startApp.prepareHome")(function* (home: st yield* fs.remove(home, { recursive: true, force: true }); yield* fs.makeDirectory(path.join(home, "userdata"), { recursive: true }); yield* fs.makeDirectory(path.join(home, "bin")); - for (const command of ["hostnamectl", "scutil"]) { - const shim = path.join(home, "bin", command); - yield* fs.writeFileString(shim, HOST_LABEL_SHIM); - yield* fs.chmod(shim, 0o755); - } // Editor discovery is cached, so the recording shim must exist before the server starts. const editor = path.join(home, "bin", "cursor"); yield* fs.writeFileString( @@ -137,6 +126,7 @@ const startApp = Effect.fn("startApp")(function* (input: { ...hostEnvironment, PATH: `${path.join(input.home, "bin")}:${hostEnvironment.PATH ?? ""}`, T3CODE_AUTO_BOOTSTRAP_PROJECT_FROM_CWD: "0", + ...SCENARIO_MACHINE_ENV, }; const devRunner = (mode: string, args: ReadonlyArray) => [ "scripts/dev-runner.ts",