MCPcopy
hub / github.com/callstack/agent-device / diffCommand

Function diffCommand

src/cli/commands/screenshot.ts:40–87  ·  view source on GitHub ↗
({ positionals, flags, client })

Source from the content-addressed store, hash-verified

38};
39
40export const diffCommand: ClientCommandHandler = async ({ positionals, flags, client }) => {
41 if (positionals[0] === 'snapshot') {
42 const result = await runCliCommand({ client, command: 'diff', positionals, flags });
43 writeCommandOutput(flags, result, () => formatSnapshotDiffText(result));
44 return true;
45 }
46
47 if (positionals[0] !== 'screenshot') return false;
48
49 const baselineRaw = flags.baseline;
50 if (!baselineRaw || typeof baselineRaw !== 'string') {
51 throw new AppError('INVALID_ARGS', 'diff screenshot requires --baseline <path>');
52 }
53
54 const baselinePath = resolveUserPath(baselineRaw);
55 const outputPath = typeof flags.out === 'string' ? resolveUserPath(flags.out) : undefined;
56 const currentRaw = positionals[1];
57 if (positionals.length > 2) {
58 throw new AppError(
59 'INVALID_ARGS',
60 'diff screenshot accepts at most one current screenshot path',
61 );
62 }
63
64 const runtime = createAgentDevice({
65 backend: createClientScreenshotBackend(client, flags),
66 artifacts: createLocalArtifactAdapter(),
67 sessions: {
68 get: (name) => ({ name }),
69 set: () => {},
70 },
71 policy: localCommandPolicy(),
72 });
73
74 const result = await runtime.capture.diffScreenshot({
75 session: flags.session,
76 baseline: { kind: 'path', path: baselinePath },
77 current: currentRaw ? { kind: 'path', path: resolveUserPath(currentRaw) } : { kind: 'live' },
78 ...(outputPath ? { out: { kind: 'path', path: outputPath } } : {}),
79 threshold: parseCliThreshold(flags.threshold),
80 overlayRefs: flags.overlayRefs,
81 normalizeStatusBar: flags.screenshotNormalizeStatusBar,
82 surface: flags.surface,
83 });
84
85 writeCommandOutput(flags, result, () => formatScreenshotDiffText(result));
86 return true;
87};
88
89function createClientScreenshotBackend(
90 client: AgentDeviceClient,

Callers

nothing calls this directly

Calls 10

runCliCommandFunction · 0.90
writeCommandOutputFunction · 0.90
formatSnapshotDiffTextFunction · 0.90
resolveUserPathFunction · 0.90
createAgentDeviceFunction · 0.90
localCommandPolicyFunction · 0.90
formatScreenshotDiffTextFunction · 0.90
parseCliThresholdFunction · 0.85

Tested by

no test coverage detected