The best way to control Claude Code, Codex and more from any computer or phone

main
ts 70 lines 3.53 KB
Raw
1 // @effect-diagnostics nodeBuiltinImport:off - Runs the Claude Code CLI as a reviewer.
2
3 import * as NodeProcess from "node:process";
4
5 import { run } from "./device.ts";
6 import type { Finding, PoseResult } from "./report.ts";
7
8 const 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 */
32 export 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 // Each of these has been confirmed as intended; the review kept reporting them.
45 `These are intended, never report them: content fading or showing through the header as it scrolls under it (the iOS scroll-edge blur); list rows scrolling under the floating glass tab bar; the search and filter buttons on the Settings header (search searches settings, the filter picks which environments settings apply to); Settings groups without a section header; chips or rows cut off at the edge of a list that scrolls; labels and rows wrapping onto more lines at the largest accessibility text size.`,
46 `Use the exact step names above. Severity: high = broken or unusable, medium = clearly wrong, low = polish.`,
47 ].join("\n");
48 const { stdout } = await run(
49 "claude",
50 [
51 "-p",
52 prompt,
53 "--output-format",
54 "json",
55 "--json-schema",
56 JSON.stringify(SCHEMA),
57 "--allowedTools",
58 "Read",
59 "--add-dir",
60 outputDirectory,
61 "--no-session-persistence",
62 ...(NodeProcess.env.T3_E2E_REVIEW_MODEL
63 ? ["--model", NodeProcess.env.T3_E2E_REVIEW_MODEL]
64 : []),
65 ],
66 { cwd: outputDirectory, timeoutMs: 600_000 },
67 );
68 const output = JSON.parse(stdout) as { structured_output?: { findings?: Finding[] } };
69 return output.structured_output?.findings ?? [];
70 }