Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

review.ts

68 lines2.9 KB

1// @effect-diagnostics nodeBuiltinImport:off - Runs the Claude Code CLI as a reviewer.
2​
3import * as NodeProcess from "node:process";
4​
5import { run } from "./device.ts";
6import type { Finding, PoseResult } from "./report.ts";
7​
8const SCHEMA = {
9 type: "object",
10 properties: {
11 findings: {
12 type: "array",
13 items: {
14 type: "object",
15 properties: {
16 step: { type: "string" },
17 issue: { type: "string" },
18 severity: { type: "string", enum: ["high", "medium", "low"] },
19 },
20 required: ["step", "issue", "severity"],
21 },
22 },
23 },
24 required: ["findings"],
25};
26​
27/**
28 * Asks an agent to look at one pose's screenshots for what the generic checks cannot see:
29 * clipped or overlapping text, wrong colours for the appearance, odd gaps, unreadable
30 * contrast. It reads the images itself and returns structured findings.
31 */
32export async function reviewPose(result: PoseResult, outputDirectory: string): Promise<Finding[]> {
33 const shots = result.steps.filter((step) => step.screenshot);
34 if (shots.length === 0) return [];
35 const { pose } = result;
36 const prompt = [
37 `You are reviewing screenshots of the T3 Code mobile app (a client for coding agents) for visual bugs.`,
38 `Device: ${pose.device} (${pose.platform}, ${pose.form}), ${pose.appearance} appearance${pose.landscape ? ", landscape" : ""}${pose.fold ? `, fold ${pose.fold}` : ""}${pose.textSize ? ", largest accessibility text size" : ""}.`,
39 `Read each screenshot below with the Read tool. Each is one step of the same session:`,
40 ...shots.map((step) => `- step "${step.name}": ${step.screenshot}`),
41 ``,
42 `Report only real defects a user would notice: text clipped, truncated mid-word where it should wrap, or overlapping other content; controls overlapping, cut off, or under the status bar, notch, home indicator, or keyboard; content hidden behind navigation chrome; colours wrong for the ${pose.appearance} appearance or unreadable contrast; large unexplained empty areas or misaligned layout; error banners or red error screens.`,
43 `Ignore: the fixture content itself, the status bar clock, a development-build badge, and anything that is plainly a deliberate design choice. Prefer no finding to a speculative one.`,
44 `Use the exact step names above. Severity: high = broken or unusable, medium = clearly wrong, low = polish.`,
45 ].join("\n");
46 const { stdout } = await run(
47 "claude",
48 [
49 "-p",
50 prompt,
51 "--output-format",
52 "json",
53 "--json-schema",
54 JSON.stringify(SCHEMA),
55 "--allowedTools",
56 "Read",
57 "--add-dir",
58 outputDirectory,
59 "--no-session-persistence",
60 ...(NodeProcess.env.T3_E2E_REVIEW_MODEL
61 ? ["--model", NodeProcess.env.T3_E2E_REVIEW_MODEL]
62 : []),
63 ],
64 { cwd: outputDirectory, timeoutMs: 600_000 },
65 );
66 const output = JSON.parse(stdout) as { structured_output?: { findings?: Finding[] } };
67 return output.structured_output?.findings ?? [];