Skip to content

Commit 33e52c7

Browse files
committed
feat: add scale-only screenshot sizing
1 parent 127e2be commit 33e52c7

58 files changed

Lines changed: 376 additions & 784 deletions

Some content is hidden

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

apple-runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+CommandExecution.swift

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -422,24 +422,18 @@ extension RunnerTests {
422422
if let requestedFps = command.fps, (requestedFps < minRecordingFps || requestedFps > maxRecordingFps) {
423423
return Response(ok: false, error: ErrorPayload(message: "recordStart fps must be between \(minRecordingFps) and \(maxRecordingFps)"))
424424
}
425-
if let requestedMaxSize = command.maxSize, requestedMaxSize < 1 {
426-
return Response(ok: false, error: ErrorPayload(message: "recordStart maxSize must be a positive integer"))
427-
}
428425
do {
429426
let resolvedOutPath = resolveRecordingOutPath(requestedOutPath)
430427
let fpsLabel = command.fps.map(String.init) ?? String(RunnerTests.defaultRecordingFps)
431-
let maxSizeLabel = command.maxSize.map(String.init) ?? "native"
432428
NSLog(
433-
"AGENT_DEVICE_RUNNER_RECORD_START requestedOutPath=%@ resolvedOutPath=%@ fps=%@ maxSize=%@",
429+
"AGENT_DEVICE_RUNNER_RECORD_START requestedOutPath=%@ resolvedOutPath=%@ fps=%@",
434430
requestedOutPath,
435431
resolvedOutPath,
436-
fpsLabel,
437-
maxSizeLabel
432+
fpsLabel
438433
)
439434
let recorder = ScreenRecorder(
440435
outputPath: resolvedOutPath,
441-
fps: command.fps.map { Int32($0) },
442-
maxSize: command.maxSize
436+
fps: command.fps.map { Int32($0) }
443437
)
444438
try recorder.start { [weak self] in
445439
return self?.captureRunnerFrame()

apple-runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Models.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ struct Command: Codable {
138138
let velocity: Double?
139139
let outPath: String?
140140
let fps: Int?
141-
let maxSize: Int?
142141
let interactiveOnly: Bool?
143142
let depth: Int?
144143
let scope: String?

apple-runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+ScreenRecorder.swift

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ extension RunnerTests {
77
final class ScreenRecorder {
88
private let outputPath: String
99
private let fps: Int32?
10-
private let maxSize: Int?
1110
private var effectiveFps: Int32 {
1211
max(1, fps ?? RunnerTests.defaultRecordingFps)
1312
}
@@ -26,10 +25,9 @@ extension RunnerTests {
2625
private var startedSession = false
2726
private var startError: Error?
2827

29-
init(outputPath: String, fps: Int32?, maxSize: Int?) {
28+
init(outputPath: String, fps: Int32?) {
3029
self.outputPath = outputPath
3130
self.fps = fps
32-
self.maxSize = maxSize
3331
}
3432

3533
func start(captureFrame: @escaping () -> RunnerImage?) throws {
@@ -50,7 +48,7 @@ extension RunnerTests {
5048
while Date() < bootstrapDeadline {
5149
if let image = captureFrame(), let cgImage = runnerCGImage(from: image) {
5250
bootstrapImage = image
53-
dimensions = scaledDimensions(width: cgImage.width, height: cgImage.height)
51+
dimensions = CGSize(width: cgImage.width, height: cgImage.height)
5452
break
5553
}
5654
Thread.sleep(forTimeInterval: 0.05)
@@ -261,23 +259,5 @@ extension RunnerTests {
261259
return pixelBuffer
262260
}
263261

264-
private func scaledDimensions(width: Int, height: Int) -> CGSize {
265-
guard let maxSize, maxSize > 0 else {
266-
return CGSize(width: width, height: height)
267-
}
268-
let longest = max(width, height)
269-
guard longest > maxSize else {
270-
return CGSize(width: width, height: height)
271-
}
272-
let scale = Double(maxSize) / Double(longest)
273-
return CGSize(
274-
width: scaledEvenDimension(width, scale: scale),
275-
height: scaledEvenDimension(height, scale: scale)
276-
)
277-
}
278-
279-
private func scaledEvenDimension(_ value: Int, scale: Double) -> Int {
280-
max(2, Int((Double(value) * scale / 2.0).rounded()) * 2)
281-
}
282262
}
283263
}

apple-runner/AgentDeviceRunner/RecordingScripts/recording-resize.swift

Lines changed: 0 additions & 225 deletions
This file was deleted.

apple-runner/RUNNER_PROTOCOL.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Examples:
3232
```
3333

3434
```json
35-
{ "command": "recordStart", "outPath": "/tmp/demo.mp4", "fps": 30, "maxSize": 720 }
35+
{ "command": "recordStart", "outPath": "/tmp/demo.mp4", "fps": 30 }
3636
```
3737

3838
```json

src/__tests__/cli-client-commands.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ test('screenshot forwards --overlay-refs to the client capture API', async () =>
384384
| {
385385
path?: string;
386386
overlayRefs?: boolean;
387-
maxSize?: number;
387+
scale?: number;
388388
stabilize?: boolean;
389389
}
390390
| undefined;
@@ -409,7 +409,7 @@ test('screenshot forwards --overlay-refs to the client capture API', async () =>
409409
help: false,
410410
version: false,
411411
overlayRefs: true,
412-
screenshotMaxSize: 1024,
412+
screenshotScale: 0.3,
413413
screenshotNoStabilize: true,
414414
},
415415
client,
@@ -419,7 +419,7 @@ test('screenshot forwards --overlay-refs to the client capture API', async () =>
419419
assert.deepEqual(observed, {
420420
path: '/tmp/screenshot.png',
421421
overlayRefs: true,
422-
maxSize: 1024,
422+
scale: 0.3,
423423
stabilize: false,
424424
});
425425
});

src/__tests__/cli-config.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,30 @@ test('CLI merges config defaults with precedence user < project < env < CLI', as
5151
fs.rmSync(root, { recursive: true, force: true });
5252
});
5353

54+
test('screenshot scale supports env defaults with CLI precedence', async () => {
55+
const { root, home, project } = makeTempWorkspace();
56+
57+
const fromEnv = await runCliCapture(['screenshot', 'env.png', '--json'], {
58+
cwd: project,
59+
env: { HOME: home, AGENT_DEVICE_SCREENSHOT_SCALE: '0.3' },
60+
defaultResponse: { ok: true, data: { path: 'env.png' } },
61+
});
62+
63+
assert.equal(fromEnv.code, null);
64+
assert.equal(fromEnv.calls[0]?.flags?.screenshotScale, 0.3);
65+
66+
const fromCli = await runCliCapture(['screenshot', 'cli.png', '--scale', '0.5', '--json'], {
67+
cwd: project,
68+
env: { HOME: home, AGENT_DEVICE_SCREENSHOT_SCALE: '0.3' },
69+
defaultResponse: { ok: true, data: { path: 'cli.png' } },
70+
});
71+
72+
assert.equal(fromCli.code, null);
73+
assert.equal(fromCli.calls[0]?.flags?.screenshotScale, 0.5);
74+
75+
fs.rmSync(root, { recursive: true, force: true });
76+
});
77+
5478
test('config can set appsFilter through canonical enum values', async () => {
5579
const { root, home, project } = makeTempWorkspace();
5680
fs.mkdirSync(path.join(home, '.agent-device'), { recursive: true });

0 commit comments

Comments
 (0)