ravensight-playtest 0.11.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +89 -21
- package/addons/mobile/Host/AppDelegate.swift +11 -0
- package/addons/mobile/RavensightMobile.xcodeproj/project.pbxproj +398 -0
- package/addons/mobile/RavensightMobile.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
- package/addons/mobile/RavensightMobile.xcodeproj/xcshareddata/xcschemes/RavensightMobile.xcscheme +116 -0
- package/addons/mobile/UITests/MobileInputTests.swift +152 -0
- package/addons/mobile/project.yml +45 -0
- package/docs/ADAPTERS.md +5 -4
- package/docs/MOBILE.md +107 -0
- package/docs/NATIVE_RUNNER.md +7 -3
- package/docs/godot-driver.md +1 -1
- package/package.json +7 -5
- package/src/api/README.md +3 -3
- package/src/cli.js +36 -6
- package/src/commands/check.js +17 -3
- package/src/commands/device.js +64 -0
- package/src/commands/fakeCore.js +1 -1
- package/src/commands/hosted.js +16 -13
- package/src/commands/login.js +1 -1
- package/src/commands/run.js +39 -11
- package/src/dashboard.js +2 -3
- package/src/detect.js +17 -0
- package/src/fsutil.js +1 -1
- package/src/hosted/archivePreflight.js +3 -3
- package/src/hosted/buildUpload.js +8 -7
- package/src/hosted/recordedRun.js +19 -3
- package/src/run/anygame/index.js +9 -3
- package/src/run/args.js +6 -0
- package/src/run/budgetReserve.js +29 -9
- package/src/run/claimProtocol.js +27 -0
- package/src/run/completion.js +86 -0
- package/src/run/context.js +2 -2
- package/src/run/drivers/android.js +3 -0
- package/src/run/drivers/godot.js +1 -1
- package/src/run/drivers/index.js +4 -0
- package/src/run/drivers/ios.js +3 -0
- package/src/run/drivers/mobile/adb.js +91 -0
- package/src/run/drivers/mobile/attempt.js +18 -0
- package/src/run/drivers/mobile/crash.js +115 -0
- package/src/run/drivers/mobile/frame.js +64 -0
- package/src/run/drivers/mobile/ios-helper.js +102 -0
- package/src/run/drivers/mobile/lock.js +32 -0
- package/src/run/drivers/mobile/native.js +227 -0
- package/src/run/drivers/mobile/preflight.js +80 -0
- package/src/run/drivers/mobile/process.js +57 -0
- package/src/run/drivers/mobile/recording.js +88 -0
- package/src/run/drivers/mobile/screenshot.js +34 -0
- package/src/run/drivers/mobile/simctl.js +60 -0
- package/src/run/drivers/mobile/target.js +53 -0
- package/src/run/honesty.js +66 -26
- package/src/run/inputMeasurement.js +49 -0
- package/src/run/model.js +24 -31
- package/src/run/paths.js +1 -1
- package/src/run/personaLoop.js +282 -74
- package/src/run/proxyClient.js +173 -0
- package/src/run/repoTools.js +1 -1
- package/src/run/report.js +19 -0
- package/src/run/resume.js +33 -4
- package/src/run/screenshots.js +3 -1
- package/src/run/tools.js +31 -5
- package/src/run/usage.js +2 -2
- package/src/upload/allowlist.js +2 -2
- package/src/upload/index.js +9 -9
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one HTTP client for Ravensight's model proxy.
|
|
3
|
+
*
|
|
4
|
+
* Every model call goes to the proxy (./model.js), never to a model provider,
|
|
5
|
+
* so this needs exactly one endpoint: POST `<base>/v1/messages` with
|
|
6
|
+
* `stream: true`, read back as the Server-Sent Events the proxy re-emits.
|
|
7
|
+
* It keeps the shape the loops already call, `client.messages.create(body,
|
|
8
|
+
* { headers, signal }).withResponse()`, answering `{ data, response }` where
|
|
9
|
+
* `data` is an async iterable of the stream's JSON events.
|
|
10
|
+
*
|
|
11
|
+
* What it sends: the caller's body as JSON, `Authorization: Bearer <gt_cli_
|
|
12
|
+
* token>`, and the caller's `X-Playtest-*` headers. No provider key and no
|
|
13
|
+
* library headers, whatever is in the environment.
|
|
14
|
+
*
|
|
15
|
+
* How it fails, in the fields ./model.js reads (`toProxyError`):
|
|
16
|
+
* - a refusal before the stream: `status`, `error` (the body, parsed when it
|
|
17
|
+
* is JSON), `headers` (a Headers object, for `retry-after`);
|
|
18
|
+
* - an `event: error` frame after the first byte: no status, and `error` is
|
|
19
|
+
* the frame's JSON, so the caller treats it as a failed upstream (502);
|
|
20
|
+
* - no answer at all: name `APIConnectionError`, or `APIConnectionTimeoutError`
|
|
21
|
+
* when nothing arrived within the timeout, both with no status;
|
|
22
|
+
* - the caller's own signal: name `APIUserAbortError`, before the answer
|
|
23
|
+
* starts. An abort once the stream is open ends it quietly, as before.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/** An error in the fields ./model.js reads off a failed call. */
|
|
27
|
+
export class ProxyClientError extends Error {
|
|
28
|
+
constructor(message, { name = 'APIError', status, error, headers, cause } = {}) {
|
|
29
|
+
super(message, cause ? { cause } : undefined);
|
|
30
|
+
this.name = name;
|
|
31
|
+
this.status = status;
|
|
32
|
+
this.error = error;
|
|
33
|
+
this.headers = headers;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** The message a refusal reads as: its own message, else its body. */
|
|
38
|
+
function refusalMessage(status, error) {
|
|
39
|
+
const inner = error && typeof error === 'object' ? (error.error && typeof error.error === 'object' ? error.error.message : error.message) : null;
|
|
40
|
+
const text = typeof inner === 'string' && inner ? inner : error === undefined || error === '' ? '' : typeof error === 'string' ? error : JSON.stringify(error);
|
|
41
|
+
if (status && text) return `${status} ${text}`;
|
|
42
|
+
if (status) return `${status} status code (no body)`;
|
|
43
|
+
return text || '(no status code or body)';
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function parsed(text) {
|
|
47
|
+
try { return JSON.parse(text); } catch { return undefined; }
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The stream's events, one JSON object each. `ping` and comments are dropped;
|
|
52
|
+
* an `error` frame throws. Lines end in LF, CRLF or CR, and a frame may be split
|
|
53
|
+
* across any number of network reads.
|
|
54
|
+
*/
|
|
55
|
+
async function* events(response, signal) {
|
|
56
|
+
const decoder = new TextDecoder();
|
|
57
|
+
let buffer = '';
|
|
58
|
+
let event = null;
|
|
59
|
+
let data = [];
|
|
60
|
+
const dispatch = function* () {
|
|
61
|
+
const name = event;
|
|
62
|
+
const payload = data.join('\n');
|
|
63
|
+
event = null;
|
|
64
|
+
data = [];
|
|
65
|
+
if (!name && !payload) return;
|
|
66
|
+
if (name === 'ping') return;
|
|
67
|
+
if (name === 'error') {
|
|
68
|
+
const error = parsed(payload) ?? payload;
|
|
69
|
+
throw new ProxyClientError(refusalMessage(undefined, error), { error, headers: response.headers });
|
|
70
|
+
}
|
|
71
|
+
yield JSON.parse(payload);
|
|
72
|
+
};
|
|
73
|
+
const lines = function* (final) {
|
|
74
|
+
let at;
|
|
75
|
+
while ((at = buffer.search(/\r\n|\r|\n/)) >= 0) {
|
|
76
|
+
// A lone CR at the very end may be the first half of a CRLF still to come.
|
|
77
|
+
if (!final && buffer[at] === '\r' && at === buffer.length - 1) return;
|
|
78
|
+
const line = buffer.slice(0, at);
|
|
79
|
+
buffer = buffer.slice(at + (buffer.startsWith('\r\n', at) ? 2 : 1));
|
|
80
|
+
yield line;
|
|
81
|
+
}
|
|
82
|
+
if (final && buffer) { const line = buffer; buffer = ''; yield line; }
|
|
83
|
+
};
|
|
84
|
+
const handle = function* (line) {
|
|
85
|
+
if (line === '') { yield* dispatch(); return; }
|
|
86
|
+
if (line.startsWith(':')) return;
|
|
87
|
+
const colon = line.indexOf(':');
|
|
88
|
+
const field = colon < 0 ? line : line.slice(0, colon);
|
|
89
|
+
let value = colon < 0 ? '' : line.slice(colon + 1);
|
|
90
|
+
if (value.startsWith(' ')) value = value.slice(1);
|
|
91
|
+
if (field === 'event') event = value;
|
|
92
|
+
else if (field === 'data') data.push(value);
|
|
93
|
+
};
|
|
94
|
+
const reader = response.body.getReader();
|
|
95
|
+
try {
|
|
96
|
+
for (;;) {
|
|
97
|
+
let chunk;
|
|
98
|
+
try {
|
|
99
|
+
chunk = await reader.read();
|
|
100
|
+
} catch (error) {
|
|
101
|
+
if (signal?.aborted || error?.name === 'AbortError') return;
|
|
102
|
+
throw new ProxyClientError('Connection error.', { name: 'APIConnectionError', cause: error });
|
|
103
|
+
}
|
|
104
|
+
if (chunk.done) break;
|
|
105
|
+
buffer += decoder.decode(chunk.value, { stream: true });
|
|
106
|
+
for (const line of lines(false)) yield* handle(line);
|
|
107
|
+
}
|
|
108
|
+
buffer += decoder.decode();
|
|
109
|
+
for (const line of lines(true)) yield* handle(line);
|
|
110
|
+
yield* dispatch();
|
|
111
|
+
} finally {
|
|
112
|
+
reader.releaseLock?.();
|
|
113
|
+
response.body.cancel?.().catch?.(() => {});
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* @param {Object} opts
|
|
119
|
+
* @param {string} opts.baseURL the proxy's base, e.g. https://api.ravensight.io/api/v1/playtest/model
|
|
120
|
+
* @param {string} opts.authToken the gt_cli_ token
|
|
121
|
+
* @param {number} [opts.timeoutMs] how long to wait for the answer to start
|
|
122
|
+
* @param {Function} [opts.fetch] test seam
|
|
123
|
+
*/
|
|
124
|
+
export function createProxyClient({ baseURL, authToken, timeoutMs = 300000, fetch: fetchImpl = globalThis.fetch }) {
|
|
125
|
+
const url = `${String(baseURL).replace(/\/+$/, '')}/v1/messages`;
|
|
126
|
+
|
|
127
|
+
async function send(body, { headers = {}, signal } = {}) {
|
|
128
|
+
const aborted = () => new ProxyClientError('Request was aborted.', { name: 'APIUserAbortError' });
|
|
129
|
+
if (signal?.aborted) throw aborted();
|
|
130
|
+
const controller = new AbortController();
|
|
131
|
+
const forward = () => controller.abort();
|
|
132
|
+
signal?.addEventListener('abort', forward, { once: true });
|
|
133
|
+
let timedOut = false;
|
|
134
|
+
// The timeout covers the answer starting; a long stream is not cut off.
|
|
135
|
+
const timer = setTimeout(() => { timedOut = true; controller.abort(); }, timeoutMs);
|
|
136
|
+
let response;
|
|
137
|
+
try {
|
|
138
|
+
response = await fetchImpl(url, {
|
|
139
|
+
method: 'POST',
|
|
140
|
+
headers: { 'Content-Type': 'application/json', Accept: 'text/event-stream', Authorization: `Bearer ${authToken}`, ...headers },
|
|
141
|
+
body: JSON.stringify(body),
|
|
142
|
+
signal: controller.signal
|
|
143
|
+
});
|
|
144
|
+
} catch (error) {
|
|
145
|
+
signal?.removeEventListener('abort', forward);
|
|
146
|
+
if (signal?.aborted) throw aborted();
|
|
147
|
+
if (timedOut) throw new ProxyClientError('Request timed out.', { name: 'APIConnectionTimeoutError', cause: error });
|
|
148
|
+
throw new ProxyClientError('Connection error.', { name: 'APIConnectionError', cause: error });
|
|
149
|
+
} finally {
|
|
150
|
+
clearTimeout(timer);
|
|
151
|
+
}
|
|
152
|
+
if (!response.ok) {
|
|
153
|
+
signal?.removeEventListener('abort', forward);
|
|
154
|
+
const text = await response.text().catch(() => '');
|
|
155
|
+
const error = parsed(text) ?? (text || undefined);
|
|
156
|
+
throw new ProxyClientError(refusalMessage(response.status, error), { status: response.status, error, headers: response.headers });
|
|
157
|
+
}
|
|
158
|
+
const data = (async function* stream() {
|
|
159
|
+
try { yield* events(response, signal); } finally { signal?.removeEventListener('abort', forward); }
|
|
160
|
+
})();
|
|
161
|
+
return { data, response };
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return {
|
|
165
|
+
messages: {
|
|
166
|
+
create(body, options) {
|
|
167
|
+
return { withResponse: () => send(body, options) };
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export default createProxyClient;
|
package/src/run/repoTools.js
CHANGED
|
@@ -9,7 +9,7 @@ import { MAX_SCAN_BYTES, scanForSecrets } from './secretScan.js';
|
|
|
9
9
|
/**
|
|
10
10
|
* The read-only source tools for `game_profile`: `read_file`, `glob` and
|
|
11
11
|
* `grep`, which are exactly the three names
|
|
12
|
-
*
|
|
12
|
+
* the server routing table's `game_profile.triage` allows (and `read_file` alone on
|
|
13
13
|
* `game_profile.synthesis` and `aggregate.synthesis`).
|
|
14
14
|
*
|
|
15
15
|
* `fix.apply` is the one step that also gets `write_file`, and it gets it
|
package/src/run/report.js
CHANGED
|
@@ -438,6 +438,23 @@ export function normaliseEnums(report, schema) {
|
|
|
438
438
|
return { report: changes.length > 0 ? root : report, changes };
|
|
439
439
|
}
|
|
440
440
|
|
|
441
|
+
/**
|
|
442
|
+
* Preserve a textual reproduction as one step when the pack requires a
|
|
443
|
+
* string array. No splitting, trimming, inferred steps or claim changes.
|
|
444
|
+
* Other invalid shapes remain the validator's responsibility.
|
|
445
|
+
*/
|
|
446
|
+
export function normaliseReproSteps(report, schema) {
|
|
447
|
+
const spec = schema?.properties?.findings?.items?.properties?.repro_steps;
|
|
448
|
+
if (!Array.isArray(report?.findings) || spec?.type !== 'array' || spec.items?.type !== 'string') return { report, changes: [] };
|
|
449
|
+
const changes = [];
|
|
450
|
+
const findings = report.findings.map(finding => {
|
|
451
|
+
if (!finding || typeof finding !== 'object' || Array.isArray(finding) || typeof finding.repro_steps !== 'string' || !finding.repro_steps.trim()) return finding;
|
|
452
|
+
changes.push({ id: typeof finding.id === 'string' ? finding.id : null, field: 'repro_steps', fromType: 'string', toType: 'array', note: 'repro_steps was wrapped in a one-element array without changing its text' });
|
|
453
|
+
return { ...finding, repro_steps: [finding.repro_steps] };
|
|
454
|
+
});
|
|
455
|
+
return { report: changes.length ? { ...report, findings } : report, changes };
|
|
456
|
+
}
|
|
457
|
+
|
|
441
458
|
/** How report.md lists what the runner normalised. */
|
|
442
459
|
export const NORMALISED_HEADING = '## Normalised by the runner (values the report schema does not allow)';
|
|
443
460
|
|
|
@@ -553,12 +570,14 @@ export function repairInstruction(details, evidenceProblems, missingSections = [
|
|
|
553
570
|
lines.push(`report.md is missing the required section heading "${section}". Add it with real content under it.`);
|
|
554
571
|
}
|
|
555
572
|
lines.push('Change nothing else. Do not add findings, and do not remove a finding you can still evidence.');
|
|
573
|
+
lines.push('Keep the supplied report.json schema. If narrative text is under a JSON field that schema forbids, preserve that text in the corresponding report.md section instead of discarding it. Supply missing required finding fields from that finding\'s existing account, without inventing new claims.');
|
|
556
574
|
return lines.join('\n');
|
|
557
575
|
}
|
|
558
576
|
|
|
559
577
|
export default {
|
|
560
578
|
createReportValidator,
|
|
561
579
|
normaliseEnums,
|
|
580
|
+
normaliseReproSteps,
|
|
562
581
|
appendNormalisedMarkdown,
|
|
563
582
|
stampReport,
|
|
564
583
|
checkEvidence,
|
package/src/run/resume.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { MOBILE_DRIVERS, buildDigest } from './drivers/mobile/target.js';
|
|
2
|
+
import { lockDevice } from './drivers/mobile/lock.js';
|
|
3
|
+
import { archiveNativeAttempt } from './drivers/mobile/attempt.js';
|
|
1
4
|
import { optionsFrom } from './args.js';
|
|
2
5
|
import { finishJob } from './settle.js';
|
|
3
6
|
import { getDeps } from './deps.js';
|
|
@@ -69,6 +72,9 @@ export async function resumeJob({ api, gameId, jobId, job, runs, state, repoRoot
|
|
|
69
72
|
log(`${jobId} is a validation. Carry on with "ravensight-playtest validate --resume ${jobId}".`);
|
|
70
73
|
return EXIT.ENVIRONMENT;
|
|
71
74
|
}
|
|
75
|
+
if (journal.options?.nativePlan && ['nativeBuild', 'device', 'package', 'bundleId', 'portrait', 'landscape', 'driverConfig'].some(key => options[key] !== undefined)) {
|
|
76
|
+
log('A native resume uses the saved build and device. Start a new job to change them.'); return EXIT.ENVIRONMENT;
|
|
77
|
+
}
|
|
72
78
|
const controllers = job.controllers?.length ? job.controllers : null;
|
|
73
79
|
if (journal.job_id !== jobId || journal.game_id !== gameId ||
|
|
74
80
|
JSON.stringify(journal.options?.controllers || null) !== JSON.stringify(controllers) ||
|
|
@@ -185,7 +191,7 @@ export async function resumeJob({ api, gameId, jobId, job, runs, state, repoRoot
|
|
|
185
191
|
driver: driverName,
|
|
186
192
|
cli_version: deps.cliVersion || api.cliVersion,
|
|
187
193
|
confirm_price_cents: Number.isInteger(journal.price_cents) ? journal.price_cents : 0,
|
|
188
|
-
build: { kind: driverName === 'playwright_web' ? 'url' : 'godot_project', ref: target },
|
|
194
|
+
build: { kind: journal.options?.nativePlan ? 'native_build' : driverName === 'playwright_web' ? 'url' : MOBILE_DRIVERS.includes(driverName) ? 'driver_config' : 'godot_project', ref: target },
|
|
189
195
|
repo: { commit: '', dirty: false },
|
|
190
196
|
max_actions: (journal.options && journal.options.maxActions) ?? null,
|
|
191
197
|
// The same body as the first register, so a long job replays as long.
|
|
@@ -203,6 +209,9 @@ export async function resumeJob({ api, gameId, jobId, job, runs, state, repoRoot
|
|
|
203
209
|
|
|
204
210
|
const resumeOptions = {
|
|
205
211
|
...options,
|
|
212
|
+
driverMode: journal.options?.driverMode || (MOBILE_DRIVERS.includes(driverName) ? 'webdriver' : undefined),
|
|
213
|
+
nativePlan: journal.options?.nativePlan || null,
|
|
214
|
+
realtime: journal.options?.realtime, phone: journal.options?.phone,
|
|
206
215
|
controller: journal.options?.controller || options.controller || 'standard',
|
|
207
216
|
controllers,
|
|
208
217
|
recordVideo: options.recordVideo ?? journal.options?.recordVideo,
|
|
@@ -216,7 +225,27 @@ export async function resumeJob({ api, gameId, jobId, job, runs, state, repoRoot
|
|
|
216
225
|
uploadTranscript: options.uploadTranscript ?? (journal.options && journal.options.uploadTranscript)
|
|
217
226
|
};
|
|
218
227
|
|
|
219
|
-
|
|
228
|
+
let nativeLease = null;
|
|
229
|
+
if (resumeOptions.nativePlan) {
|
|
230
|
+
try {
|
|
231
|
+
const native = resumeOptions.nativePlan;
|
|
232
|
+
if (!native.resolvedDevice) throw new Error('The native journal has no pinned device. Start a new job.');
|
|
233
|
+
if (native.buildHash && await buildDigest(native.build || target) !== native.buildHash) throw new Error('The saved native build changed. Start a new job for the changed build.');
|
|
234
|
+
const key = `${driverName === 'android_driver' ? 'android' : 'ios'}:${native.resolvedDevice}`;
|
|
235
|
+
const release = await (injected.lockDevice || lockDevice)(key);
|
|
236
|
+
nativeLease = { release, lock: async requested => { if (requested !== key) throw new Error('The resumed device does not match its lease.'); return async () => {}; } };
|
|
237
|
+
for (const row of outstanding.filter(row => row.module === 'persona_playtest')) {
|
|
238
|
+
const archived = await archiveNativeAttempt(runDirFor(repoRoot, jobId, row.run_id));
|
|
239
|
+
if (archived) {
|
|
240
|
+
const entry = journal.runs[row.run_id];
|
|
241
|
+
entry.native_attempts = [...(entry.native_attempts || []), archived];
|
|
242
|
+
log(`run ${row.run_id}: preserved the previous native attempt at ${archived}.`);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
await stateFile.save(repoRoot, journal);
|
|
246
|
+
} catch (error) { await nativeLease?.release(); log(`Native resume could not prepare a fresh attempt: ${error.message}`); return EXIT.ENVIRONMENT; }
|
|
247
|
+
}
|
|
248
|
+
try { return await playJob({
|
|
220
249
|
deps,
|
|
221
250
|
api,
|
|
222
251
|
apiUrl: api.apiUrl,
|
|
@@ -232,12 +261,12 @@ export async function resumeJob({ api, gameId, jobId, job, runs, state, repoRoot
|
|
|
232
261
|
journal,
|
|
233
262
|
config: null,
|
|
234
263
|
brief,
|
|
235
|
-
injected,
|
|
264
|
+
injected: nativeLease ? { ...injected, nativeLease } : injected,
|
|
236
265
|
log,
|
|
237
266
|
// A job that is already terminal must not be settled twice: `finish` is
|
|
238
267
|
// the one writer of a terminal state and the one issuer of a refund.
|
|
239
268
|
finish: !isTerminalJob(job)
|
|
240
|
-
});
|
|
269
|
+
}); } finally { await nativeLease?.release(); }
|
|
241
270
|
}
|
|
242
271
|
|
|
243
272
|
/**
|
package/src/run/screenshots.js
CHANGED
|
@@ -136,7 +136,9 @@ export function createScreenshotKeeper({ read = readFile, remove = unlink } = {}
|
|
|
136
136
|
last = null;
|
|
137
137
|
return { shot, duplicate: false, seen: false };
|
|
138
138
|
}
|
|
139
|
-
|
|
139
|
+
// Native timers and dialog fades can differ in a small part of the
|
|
140
|
+
// screen. Only identical native pixels may reuse an older artifact.
|
|
141
|
+
if (last && (driver.exactScreenshots ? last.bytes.equals(bytes) : sameScreen(last.bytes, bytes))) {
|
|
140
142
|
await remove(shot.path).catch(() => {});
|
|
141
143
|
return { shot: last.shot, duplicate: true, seen: last.seen };
|
|
142
144
|
}
|
package/src/run/tools.js
CHANGED
|
@@ -12,7 +12,7 @@ export { STALE_REF_MESSAGE };
|
|
|
12
12
|
/**
|
|
13
13
|
* The client tool set for `persona_playtest.act`.
|
|
14
14
|
*
|
|
15
|
-
* **The names are not ours to choose.**
|
|
15
|
+
* **The names are not ours to choose.** The server routing table's
|
|
16
16
|
* `persona_playtest.act` lists `allowed_client_tools: ["snapshot", "click",
|
|
17
17
|
* "type", "key", "navigate", "wait", "screenshot"]`, and the proxy answers
|
|
18
18
|
* 400 `tool_not_allowed` for anything else. Two consequences worth knowing
|
|
@@ -275,7 +275,27 @@ export function toolsFor(driver, { newTools = true, newestTools = newTools } = {
|
|
|
275
275
|
}
|
|
276
276
|
// A driver without the pointer extras is offered the plain click it had.
|
|
277
277
|
const tools = pointer.length > 0 ? base : base.map(tool => (tool.name === 'click' || tool.name === 'key' ? plainTool(tool) : tool));
|
|
278
|
-
|
|
278
|
+
const combined = [...tools, ...extra];
|
|
279
|
+
// A mobile drag is exposed through the same name and old-server alias.
|
|
280
|
+
// Do not offer the older duplicate swipe definition when drag is present.
|
|
281
|
+
const unique = combined.filter((tool, i) => combined.findLastIndex(other => other.name === tool.name) === i);
|
|
282
|
+
return driver?.inputProfile === 'native-mobile' ? unique.map(tool => nativeMobileTool(tool, driver.name)) : unique;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/** Describe only the coordinate and keyboard inputs the native runner sends. */
|
|
286
|
+
function nativeMobileTool(tool, driverName) {
|
|
287
|
+
const drop = {
|
|
288
|
+
click: ['ref', 'target', 'button'], key: ['sequence', 'with_keys', 'hold_ms'],
|
|
289
|
+
type: ['ref', 'target', 'replace'], drag: ['from', 'to', 'steps', 'via', 'hold_ms', 'button'], swipe: ['from', 'to', 'steps', 'via', 'hold_ms', 'button']
|
|
290
|
+
}[tool.name] || [];
|
|
291
|
+
const properties = Object.fromEntries(Object.entries(tool.input_schema.properties || {}).filter(([key]) => !drop.includes(key)).map(([key, value]) => [key, { ...value }]));
|
|
292
|
+
let required = tool.input_schema.required, description = tool.description;
|
|
293
|
+
if (tool.name === 'click') { required = ['x', 'y']; description = 'Tap visible screenshot coordinates x,y. double taps twice; hold_ms holds one finger for up to 5000 milliseconds. Spends one action.'; }
|
|
294
|
+
if (tool.name === 'key') { required = ['key']; properties.key = { type: 'string', enum: driverName === 'ios_driver' ? ['Enter', 'Backspace'] : ['Back', 'Escape', 'Enter', 'Backspace', 'Tab', 'Space', 'ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight'] }; description = 'Send one supported mobile keyboard key. On Android Back leaves the current screen. No held keys or chords. Spends one action.'; }
|
|
295
|
+
if (tool.name === 'type') { properties.text = { ...properties.text, minLength: 1, maxLength: 2000 }; description = `Type into the already focused field. Tap it first. ${driverName === 'android_driver' ? 'Android accepts printable ASCII without percent signs. ' : ''}No field replacement. Spends one action.`; }
|
|
296
|
+
if (['drag', 'swipe'].includes(tool.name)) { required = ['x', 'y', 'toX', 'toY']; description = 'Move one finger in a straight line from screenshot coordinates x,y to toX,toY, then release. No waypoints or held pickup. Spends one action.'; }
|
|
297
|
+
for (const key of ['hold_ms', 'duration_ms', 'durationMs', 'ms']) if (properties[key]) properties[key] = { ...properties[key], minimum: 0, maximum: 5000 };
|
|
298
|
+
return { ...tool, description, input_schema: { ...tool.input_schema, properties, ...(required ? { required } : {}) } };
|
|
279
299
|
}
|
|
280
300
|
|
|
281
301
|
/** A click or key tool without the fields only a pointer driver can honour. */
|
|
@@ -633,7 +653,12 @@ export async function executeTool({ driver, toolUse, onNote, onScreenshot, stale
|
|
|
633
653
|
// The picture goes back with the answer: a persona that asks for a
|
|
634
654
|
// screenshot is asking to see the screen, and "Saved <path>" showed it
|
|
635
655
|
// nothing. The same screen it was already shown is not sent twice.
|
|
636
|
-
|
|
656
|
+
// A live native screen may have returned to an earlier saved picture
|
|
657
|
+
// after a different action observation. An explicit look must show it
|
|
658
|
+
// again, using the saved capture rather than taking a second picture.
|
|
659
|
+
const frame = taken.duplicate && taken.seen && !driver.exactScreenshots
|
|
660
|
+
? null
|
|
661
|
+
: await modelFrameOf(driver, driver.exactScreenshots ? { screenshot: shot } : undefined);
|
|
637
662
|
if (frame && keeper) keeper.markSeen();
|
|
638
663
|
const said = taken.duplicate
|
|
639
664
|
? `The screen has not changed since ${shot.relativePath} was saved, so no new file was saved. Cite ${shot.relativePath}.`
|
|
@@ -787,12 +812,13 @@ export const NO_PICTURE_NOTE = 'This runner cannot show you the picture here; th
|
|
|
787
812
|
* request by), or null when the driver has none.
|
|
788
813
|
*
|
|
789
814
|
* @param {Object} driver
|
|
815
|
+
* @param {Object} [options] native retained screenshot, when the caller just saved one
|
|
790
816
|
* @returns {Promise<{data: string, mediaType: string, note?: string}|null>}
|
|
791
817
|
*/
|
|
792
|
-
export async function modelFrameOf(driver) {
|
|
818
|
+
export async function modelFrameOf(driver, options) {
|
|
793
819
|
if (!driver || typeof driver.modelFrame !== 'function') return null;
|
|
794
820
|
try {
|
|
795
|
-
const frame = await driver.modelFrame();
|
|
821
|
+
const frame = await driver.modelFrame(options);
|
|
796
822
|
return frame && frame.data ? frame : null;
|
|
797
823
|
} catch {
|
|
798
824
|
return null;
|
package/src/run/usage.js
CHANGED
|
@@ -10,8 +10,8 @@ import { assertNoSecrets } from './secretScan.js';
|
|
|
10
10
|
* `message_delta` carry them, and the proxy re-emits both verbatim.
|
|
11
11
|
*
|
|
12
12
|
* **Dollars are not counted locally, and cannot be.** Per-token prices live
|
|
13
|
-
* in
|
|
14
|
-
* or price
|
|
13
|
+
* in the server's routing table, which is server-only by design (no model id
|
|
14
|
+
* or price is ever sent to a client, and the client subset
|
|
15
15
|
* `clientRouting()` deliberately carries neither). So `total_usd` is taken
|
|
16
16
|
* from the server, which prices every call as it makes it: the run's
|
|
17
17
|
* `usage.total_usd` comes back on every heartbeat answer
|
package/src/upload/allowlist.js
CHANGED
|
@@ -45,8 +45,8 @@ export const VIDEO_PATHS = Object.freeze(['session.webm', 'session.mp4']);
|
|
|
45
45
|
export const TRACE_PATH = 'trace.jsonl';
|
|
46
46
|
|
|
47
47
|
/**
|
|
48
|
-
* The paths whose objects carry the `retention=90d`
|
|
49
|
-
* `RETENTION_TAGGED_PATHS`. The CLI never computes the tag value itself: the
|
|
48
|
+
* The paths whose objects carry the `retention=90d` storage tag, mirroring the
|
|
49
|
+
* server's `RETENTION_TAGGED_PATHS`. The CLI never computes the tag value itself: the
|
|
50
50
|
* presign response hands back the exact string that was signed. This list is
|
|
51
51
|
* only used to explain, in `--dry-upload` output, which files expire.
|
|
52
52
|
*/
|
package/src/upload/index.js
CHANGED
|
@@ -119,14 +119,14 @@ export async function planRunDir(runDir, opts = {}) {
|
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
/**
|
|
122
|
-
* The verbatim
|
|
122
|
+
* The verbatim storage tagging header value for a presigned entry.
|
|
123
123
|
*
|
|
124
124
|
* The presign response is the authority: it carries back exactly what was
|
|
125
125
|
* signed, so the CLI never computes the tag itself. Two shapes are accepted
|
|
126
|
-
* because
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
126
|
+
* because server versions spell it differently: one returns the encoded
|
|
127
|
+
* string, another passes the tag object through. Either is normalized to the
|
|
128
|
+
* string storage wants; a mismatch would be a signature mismatch rather than
|
|
129
|
+
* an untagged object,
|
|
130
130
|
* so guessing is not an option and accepting both is.
|
|
131
131
|
*
|
|
132
132
|
* @param {unknown} tagging
|
|
@@ -148,13 +148,13 @@ export function taggingHeader(tagging) {
|
|
|
148
148
|
* PUT one file at a presigned URL.
|
|
149
149
|
*
|
|
150
150
|
* The headers are exactly the ones the URL was signed with: the content type,
|
|
151
|
-
*
|
|
151
|
+
* the tagging header when the presign said so, and the checksum header with
|
|
152
152
|
* the base64 digest the presign echoed back. The checksum header is what
|
|
153
|
-
* makes
|
|
153
|
+
* makes storage hash the body it receives and refuse one that differs, and what
|
|
154
154
|
* lets the server's `complete` read the checksum back; a presign that names
|
|
155
155
|
* none is an older server, and the header is simply not sent. An extra
|
|
156
156
|
* signed header that is missing, or a value that differs by one character,
|
|
157
|
-
* is a
|
|
157
|
+
* is a signature mismatch from storage and not a retryable failure, so nothing
|
|
158
158
|
* is added here on a guess.
|
|
159
159
|
*
|
|
160
160
|
* @param {Object} options
|
|
@@ -206,7 +206,7 @@ export async function putFile(options) {
|
|
|
206
206
|
const text = await response.text().catch(() => '');
|
|
207
207
|
lastError = new ApiError({
|
|
208
208
|
status: response.status,
|
|
209
|
-
code: response.status === 403 ? 'presign_expired' : `
|
|
209
|
+
code: response.status === 403 ? 'presign_expired' : `storage_${response.status}`,
|
|
210
210
|
message: `PUT ${entry.path} answered ${response.status}: ${text.slice(0, 300)}`,
|
|
211
211
|
method: 'PUT',
|
|
212
212
|
path: entry.path
|