ravensight-playtest 0.8.3 → 0.10.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 +280 -66
- package/addons/ravensight_driver/driver.gd +666 -21
- package/docs/ADAPTERS.md +11 -7
- package/docs/NATIVE_RUNNER.md +3 -1
- package/docs/godot-driver.md +127 -13
- package/package.json +8 -6
- package/src/api/client.js +4 -3
- package/src/cli.js +84 -25
- package/src/commands/check.js +30 -4
- package/src/commands/fakeCore.js +1 -0
- package/src/commands/hosted.js +41 -12
- package/src/commands/init.js +17 -1
- package/src/commands/run.js +209 -14
- package/src/commands/upload.js +6 -2
- package/src/commands/validate.js +1 -1
- package/src/commands/validateHosted.js +50 -5
- package/src/config.js +33 -2
- package/src/hosted/archivePreflight.js +7 -7
- package/src/hosted/buildUpload.js +89 -8
- package/src/hosted/recordedRun.js +141 -26
- package/src/hosted/status.js +19 -10
- package/src/run/actionSelector.js +14 -3
- package/src/run/aggregate.js +57 -3
- package/src/run/anygame/controlbook.js +179 -0
- package/src/run/anygame/genre.js +179 -0
- package/src/run/anygame/index.js +258 -0
- package/src/run/anygame/language.js +336 -0
- package/src/run/anygame/memory.js +330 -0
- package/src/run/anygame/shared-hashes.json +10 -0
- package/src/run/anygame/shared.js +24 -0
- package/src/run/anygame/sound.js +342 -0
- package/src/run/args.js +75 -8
- package/src/run/choiceCheck.js +312 -0
- package/src/run/context.js +254 -13
- package/src/run/drivers/godot-observation.js +93 -6
- package/src/run/drivers/godot.js +769 -46
- package/src/run/drivers/recording.js +24 -4
- package/src/run/drivers/web.js +1242 -77
- package/src/run/edgePass.js +731 -0
- package/src/run/fixLoop.js +5 -4
- package/src/run/focus.js +65 -0
- package/src/run/gamepad.js +108 -0
- package/src/run/godotEdgePass.js +235 -0
- package/src/run/godotTesterProbes.js +192 -0
- package/src/run/headings.js +21 -0
- package/src/run/honesty.js +544 -0
- package/src/run/inputs.js +256 -0
- package/src/run/marks.js +142 -0
- package/src/run/personaLoop.js +1000 -79
- package/src/run/phone.js +7 -0
- package/src/run/pixels.js +215 -0
- package/src/run/playClock.js +162 -0
- package/src/run/readiness.js +585 -0
- package/src/run/refusal.js +67 -0
- package/src/run/regions.js +119 -0
- package/src/run/report.js +14 -2
- package/src/run/reportChecks.js +472 -0
- package/src/run/resume.js +3 -2
- package/src/run/screenshots.js +161 -0
- package/src/run/strip.js +114 -0
- package/src/run/testerLedger.js +312 -0
- package/src/run/testerProbes.js +584 -0
- package/src/run/thinRun.js +102 -0
- package/src/run/timeFreeze.js +79 -0
- package/src/run/tools.js +454 -29
- package/src/runDefaults.js +24 -2
|
@@ -0,0 +1,585 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Readiness: what makes a persona run come back thin, found before any charge.
|
|
3
|
+
*
|
|
4
|
+
* A run is thin when the playtester could not read or press something, was not
|
|
5
|
+
* told how to start or what to choose, or was not asked for a video. All of
|
|
6
|
+
* that can be seen on this machine, for free, before a job is registered:
|
|
7
|
+
*
|
|
8
|
+
* - the brief (how to start, the choice to make, controls, success criteria);
|
|
9
|
+
* - a Godot project's scenes and scripts (pressable nodes with no text, screens
|
|
10
|
+
* a script draws itself, no game state hook);
|
|
11
|
+
* - the fonts the project ships against the letters its text and the brief use;
|
|
12
|
+
* - whether a video was asked for.
|
|
13
|
+
*
|
|
14
|
+
* Everything here is a warning with its fix, never a failure: `check` still
|
|
15
|
+
* says Ready, and `run` still runs. Nothing here talks to the network, starts
|
|
16
|
+
* the game or reads outside the project directory.
|
|
17
|
+
*
|
|
18
|
+
* The same module holds the capability note tags the persona skill writes in
|
|
19
|
+
* "What this run didn't cover", with what a developer adds for each, so the
|
|
20
|
+
* line after a run and the row before it name the same fix.
|
|
21
|
+
*/
|
|
22
|
+
import fs from 'node:fs/promises';
|
|
23
|
+
import path from 'node:path';
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The capability note tags of the persona skill (`persona-playtest`, the
|
|
27
|
+
* "Capability notes are never findings" section), each with what to add.
|
|
28
|
+
* `readiness.pinned.test.js` compares the keys with the server's skill.
|
|
29
|
+
*/
|
|
30
|
+
export const CAPABILITY_NOTE_FIXES = Object.freeze({
|
|
31
|
+
no_label: 'give the control text, a tooltip (tooltip_text in Godot, title or aria-label on the web) or an accessible name',
|
|
32
|
+
drawn_screen: 'put a named control over each pressable thing the screen draws, or expose the game state (in Godot, a node in the ravensight_state group with _ravensight_state())',
|
|
33
|
+
no_state: 'show the choice or the result on screen (a name in the HUD), or expose the game state (in Godot, _ravensight_state())',
|
|
34
|
+
font: 'ship a font that covers the language and set it as the project font',
|
|
35
|
+
outline_cut: 'nest the screen less deeply, or give the nodes that matter names of their own',
|
|
36
|
+
no_way_in: 'add a debug start, a level select or a test account, and name it in the brief under how to start',
|
|
37
|
+
input: 'offer a plain key or a button for the same action, or say in the brief that it is out of scope',
|
|
38
|
+
too_fast: 'add a slow or assist mode for testing and name it in the brief',
|
|
39
|
+
brief_gap: 'say in the brief how to start, which choice to make and what each control does',
|
|
40
|
+
budget: 'run again with --long, or give the brief fewer goals'
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
/** The tags, in the order the skill lists them. */
|
|
44
|
+
export const CAPABILITY_NOTE_TAGS = Object.freeze(Object.keys(CAPABILITY_NOTE_FIXES));
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The tagged capability notes of one report.md, each with its fix.
|
|
48
|
+
*
|
|
49
|
+
* @param {string} markdown
|
|
50
|
+
* @returns {Array<{tag: string, text: string, fix: string}>}
|
|
51
|
+
*/
|
|
52
|
+
export function capabilityNotesIn(markdown) {
|
|
53
|
+
const out = [];
|
|
54
|
+
const text = String(markdown || '');
|
|
55
|
+
const start = text.indexOf("## What this run didn't cover");
|
|
56
|
+
if (start < 0) return out;
|
|
57
|
+
const rest = text.slice(start + 1);
|
|
58
|
+
const end = rest.search(/\n## /);
|
|
59
|
+
const section = end < 0 ? rest : rest.slice(0, end);
|
|
60
|
+
for (const match of section.matchAll(/^\s*[-*]\s*`?\[([a-z_]+)\]`?\s*(.+)$/gm)) {
|
|
61
|
+
const fix = CAPABILITY_NOTE_FIXES[match[1]];
|
|
62
|
+
if (fix) out.push({ tag: match[1], text: match[2].trim(), fix });
|
|
63
|
+
}
|
|
64
|
+
return out;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* The lines `run` prints after a job: every tagged capability note the
|
|
69
|
+
* personas wrote, once per tag, with what to add before the next run.
|
|
70
|
+
*
|
|
71
|
+
* @param {Array<{persona?: string, markdown: string}>} reports
|
|
72
|
+
* @returns {Array<string>}
|
|
73
|
+
*/
|
|
74
|
+
export function capabilityNoteLines(reports) {
|
|
75
|
+
const byTag = new Map();
|
|
76
|
+
for (const report of reports || []) {
|
|
77
|
+
for (const note of capabilityNotesIn(report && report.markdown)) {
|
|
78
|
+
if (!byTag.has(note.tag)) byTag.set(note.tag, note);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (byTag.size === 0) return [];
|
|
82
|
+
const lines = ['What this job could not cover, and what to add before the next run:'];
|
|
83
|
+
for (const tag of CAPABILITY_NOTE_TAGS) {
|
|
84
|
+
const note = byTag.get(tag);
|
|
85
|
+
if (note) lines.push(` [${tag}] ${clip(note.text, 160)} To fix: ${note.fix}.`);
|
|
86
|
+
}
|
|
87
|
+
return lines;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/* ------------------------------------------------------------------ brief */
|
|
91
|
+
|
|
92
|
+
/** Fewer characters than this in "how to start" cannot name a menu path and a choice. */
|
|
93
|
+
export const MIN_HOW_TO_START_CHARS = 40;
|
|
94
|
+
/** Fewer characters than this in "controls" cannot say what the inputs do. */
|
|
95
|
+
export const MIN_CONTROLS_CHARS = 20;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Where a complete brief is still too thin to play a full session from.
|
|
99
|
+
*
|
|
100
|
+
* @param {Object} fields the brief's fields
|
|
101
|
+
* @returns {Array<string>} one sentence per thin spot, empty when there is none
|
|
102
|
+
*/
|
|
103
|
+
export function briefGaps(fields = {}) {
|
|
104
|
+
const notes = (fields && fields.build_notes) || {};
|
|
105
|
+
const text = value => (typeof value === 'string' ? value.trim() : '');
|
|
106
|
+
const gaps = [];
|
|
107
|
+
const start = text(notes.how_to_start);
|
|
108
|
+
if (start.length < MIN_HOW_TO_START_CHARS) {
|
|
109
|
+
gaps.push(start
|
|
110
|
+
? `how to start is ${start.length} characters: name the menu path, and any choice to make on the way (a faction, a character, a mode, a difficulty)`
|
|
111
|
+
: 'how to start is empty: name the menu path, and any choice to make on the way');
|
|
112
|
+
}
|
|
113
|
+
const controls = text(notes.controls);
|
|
114
|
+
if (controls.length < MIN_CONTROLS_CHARS) {
|
|
115
|
+
gaps.push(controls ? `controls is ${controls.length} characters: say which inputs the game takes and what each does` : 'controls is empty: say which inputs the game takes and what each does');
|
|
116
|
+
}
|
|
117
|
+
const criteria = text(fields.success_criteria).split(/\n|;|(?<=[.!?])\s+/).map(line => line.trim()).filter(Boolean);
|
|
118
|
+
if (criteria.length < 2) gaps.push('success criteria has fewer than two things to observe: list what a full session reaches, one per line, so the playtester keeps going past the first');
|
|
119
|
+
if (!Array.isArray(fields.goals) || fields.goals.length < 1) gaps.push('goals is empty');
|
|
120
|
+
const known = Array.isArray(fields.known_issues) ? fields.known_issues.length : 0;
|
|
121
|
+
const intent = Array.isArray(fields.design_intent_notes) ? fields.design_intent_notes.length : 0;
|
|
122
|
+
if (known + intent === 0) gaps.push('no known issues or design intent notes: anything you already know is reported back to you as a finding, and costs actions');
|
|
123
|
+
return gaps;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/* ------------------------------------------------------ the Godot project */
|
|
127
|
+
|
|
128
|
+
/** Directories never read. */
|
|
129
|
+
const SKIP_DIRS = new Set(['.godot', '.git', '.ravensight', 'node_modules', '.import', 'ravensight_driver']);
|
|
130
|
+
/** The most files one scan walks, and the most bytes of one text file it reads. */
|
|
131
|
+
export const MAX_SCAN_FILES = 4000;
|
|
132
|
+
export const MAX_TEXT_BYTES = 512 * 1024;
|
|
133
|
+
/** Fonts larger than this are not read; they are counted as unread, not as missing. */
|
|
134
|
+
export const MAX_FONT_BYTES = 64 * 1024 * 1024;
|
|
135
|
+
|
|
136
|
+
/** Node types a click is aimed at, and that show text of their own or need a label. */
|
|
137
|
+
const PRESSABLE_TYPES = ['Button', 'TextureButton', 'LinkButton', 'CheckBox', 'CheckButton', 'MenuButton', 'TouchScreenButton'];
|
|
138
|
+
const PRESSABLE = new RegExp(`^(${PRESSABLE_TYPES.join('|')})$`);
|
|
139
|
+
/** Properties the driver reads as a control's text or label. */
|
|
140
|
+
const LABEL_PROPERTIES = ['text', 'tooltip_text', 'accessibility_name'];
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Every file under a directory, bounded, with the driver's own addon and the
|
|
144
|
+
* engine's caches left out.
|
|
145
|
+
*
|
|
146
|
+
* @param {string} root
|
|
147
|
+
* @returns {Promise<{files: Array<string>, truncated: boolean}>}
|
|
148
|
+
*/
|
|
149
|
+
export async function walk(root) {
|
|
150
|
+
const files = [];
|
|
151
|
+
const queue = [root];
|
|
152
|
+
let truncated = false;
|
|
153
|
+
while (queue.length > 0) {
|
|
154
|
+
const dir = queue.shift();
|
|
155
|
+
let entries = [];
|
|
156
|
+
try {
|
|
157
|
+
entries = await fs.readdir(dir, { withFileTypes: true });
|
|
158
|
+
} catch {
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
for (const entry of entries) {
|
|
162
|
+
if (entry.isSymbolicLink()) continue;
|
|
163
|
+
const full = path.join(dir, entry.name);
|
|
164
|
+
if (entry.isDirectory()) {
|
|
165
|
+
if (!SKIP_DIRS.has(entry.name)) queue.push(full);
|
|
166
|
+
} else if (entry.isFile()) {
|
|
167
|
+
if (files.length >= MAX_SCAN_FILES) {
|
|
168
|
+
truncated = true;
|
|
169
|
+
return { files, truncated };
|
|
170
|
+
}
|
|
171
|
+
files.push(full);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return { files, truncated };
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Pressable nodes of one `.tscn` with no text, tooltip or accessible name, and
|
|
180
|
+
* no labelled node under them.
|
|
181
|
+
*
|
|
182
|
+
* @param {string} source the scene file's text
|
|
183
|
+
* @returns {Array<{node: string, type: string}>}
|
|
184
|
+
*/
|
|
185
|
+
export function silentNodesInScene(source) {
|
|
186
|
+
const nodes = [];
|
|
187
|
+
let current = null;
|
|
188
|
+
for (const line of String(source || '').split(/\r?\n/)) {
|
|
189
|
+
const header = line.match(/^\[node\s+(.*)\]\s*$/);
|
|
190
|
+
if (header) {
|
|
191
|
+
const attribute = name => (header[1].match(new RegExp(`\\b${name}="([^"]*)"`)) || [])[1];
|
|
192
|
+
const name = attribute('name') || '';
|
|
193
|
+
const parent = attribute('parent');
|
|
194
|
+
const nodePath = parent === undefined ? '.' : parent === '.' ? name : `${parent}/${name}`;
|
|
195
|
+
current = { path: nodePath, name, type: attribute('type') || null, instanced: /\binstance=/.test(header[1]), labelled: false };
|
|
196
|
+
nodes.push(current);
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
if (/^\[/.test(line)) {
|
|
200
|
+
current = null;
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
if (!current) continue;
|
|
204
|
+
const property = line.match(/^(\w+)\s*=\s*(.*)$/);
|
|
205
|
+
if (property && LABEL_PROPERTIES.includes(property[1]) && !/^(""|&""|)$/.test(property[2].trim())) current.labelled = true;
|
|
206
|
+
}
|
|
207
|
+
const silent = [];
|
|
208
|
+
for (const node of nodes) {
|
|
209
|
+
if (!node.type || !PRESSABLE.test(node.type) || node.labelled) continue;
|
|
210
|
+
const under = nodes.filter(other => other !== node && (node.path === '.' ? other.path !== '.' : other.path.startsWith(`${node.path}/`)));
|
|
211
|
+
// A labelled node under it reads as its text; an instanced scene under it may hold one.
|
|
212
|
+
if (under.some(other => other.labelled || other.instanced)) continue;
|
|
213
|
+
silent.push({ node: node.path === '.' ? node.name : node.path, type: node.type });
|
|
214
|
+
}
|
|
215
|
+
return silent;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* What one GDScript file says about readability: pressable nodes it builds
|
|
220
|
+
* with no text, whether it draws and reads clicks itself, and whether it
|
|
221
|
+
* exposes the game state.
|
|
222
|
+
*
|
|
223
|
+
* A static read, so it errs on the quiet side: a control given a child, or
|
|
224
|
+
* handed to a helper, is taken as labelled.
|
|
225
|
+
*
|
|
226
|
+
* @param {string} source
|
|
227
|
+
* @returns {{silent: Array<{node: string, type: string, line: number}>, drawsOwnControls: boolean, stateHook: boolean}}
|
|
228
|
+
*/
|
|
229
|
+
export function scanScript(source) {
|
|
230
|
+
const text = String(source || '');
|
|
231
|
+
const lines = text.split(/\r?\n/);
|
|
232
|
+
const silent = [];
|
|
233
|
+
// One function at a time: a variable name means something only inside it.
|
|
234
|
+
let start = 0;
|
|
235
|
+
const bodies = [];
|
|
236
|
+
for (let index = 0; index <= lines.length; index += 1) {
|
|
237
|
+
if (index === lines.length || /^(static\s+)?func\s/.test(lines[index])) {
|
|
238
|
+
if (index > start) bodies.push({ start, lines: lines.slice(start, index) });
|
|
239
|
+
start = index;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
const made = new RegExp(`^\\s*var\\s+(\\w+)\\s*(?::\\s*\\w+\\s*)?:?=\\s*(${PRESSABLE_TYPES.join('|')})\\.new\\(`);
|
|
243
|
+
for (const body of bodies) {
|
|
244
|
+
const code = body.lines.map(line => line.replace(/#.*$/, '')).join('\n');
|
|
245
|
+
body.lines.forEach((line, offset) => {
|
|
246
|
+
const match = line.match(made);
|
|
247
|
+
if (!match) return;
|
|
248
|
+
const name = match[1];
|
|
249
|
+
const labelled = new RegExp(`\\b${name}\\.(${LABEL_PROPERTIES.join('|')})\\s*=`).test(code)
|
|
250
|
+
|| new RegExp(`\\b${name}\\.add_child\\(`).test(code)
|
|
251
|
+
|| new RegExp(`\\b${name}\\.set\\(\\s*["'](${LABEL_PROPERTIES.join('|')})["']`).test(code)
|
|
252
|
+
// Handed to one of the script's own functions (not a method such as
|
|
253
|
+
// add_child or append): it may be labelled there.
|
|
254
|
+
|| [...code.matchAll(new RegExp(`(?<![\\w.])(\\w+)\\([^()\\n]*\\b${name}\\b`, 'g'))].some(call => !['add_child', 'add_sibling', 'move_child', 'remove_child', 'print', 'push_error'].includes(call[1]));
|
|
255
|
+
if (!labelled) silent.push({ node: name, type: match[2], line: body.start + offset + 1 });
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
const code = lines.map(line => line.replace(/#.*$/, '')).join('\n');
|
|
259
|
+
const drawsOwnControls = /^func\s+_draw\s*\(/m.test(code)
|
|
260
|
+
&& /^func\s+(_gui_input|_input|_unhandled_input)\s*\(/m.test(code)
|
|
261
|
+
&& /InputEventMouseButton|InputEventScreenTouch/.test(code);
|
|
262
|
+
const stateHook = /func\s+_ravensight_state\s*\(/.test(code);
|
|
263
|
+
return { silent, drawsOwnControls, stateHook };
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/** Letters outside the scripts Godot's built-in font draws. */
|
|
267
|
+
const OTHER_SCRIPT_LETTER = /\p{L}/u;
|
|
268
|
+
const BUILT_IN_SCRIPTS = /[\p{Script=Latin}\p{Script=Greek}\p{Script=Cyrillic}]/u;
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* The distinct letters of a text that need a font the engine does not bring.
|
|
272
|
+
*
|
|
273
|
+
* @param {string} text
|
|
274
|
+
* @returns {Array<string>}
|
|
275
|
+
*/
|
|
276
|
+
export function lettersNeedingAFont(text) {
|
|
277
|
+
const out = new Set();
|
|
278
|
+
for (const char of String(text || '')) {
|
|
279
|
+
if (OTHER_SCRIPT_LETTER.test(char) && !BUILT_IN_SCRIPTS.test(char)) out.add(char);
|
|
280
|
+
}
|
|
281
|
+
return [...out];
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/** String literals of a GDScript or scene file, joined: the text a player may be shown. */
|
|
285
|
+
export function stringLiterals(source) {
|
|
286
|
+
const out = [];
|
|
287
|
+
for (const match of String(source || '').matchAll(/"((?:[^"\\\n]|\\.)*)"/g)) out.push(match[1]);
|
|
288
|
+
return out.join('\n');
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* The code point ranges a TrueType or OpenType font file maps, read from its
|
|
293
|
+
* `cmap` table (formats 4 and 12, which is what every shipped font uses). A
|
|
294
|
+
* collection (`.ttc`) answers for all its faces together.
|
|
295
|
+
*
|
|
296
|
+
* @param {Buffer} buffer
|
|
297
|
+
* @returns {Array<[number, number]>|null} null when the file is not a font this reads
|
|
298
|
+
*/
|
|
299
|
+
export function fontRanges(buffer) {
|
|
300
|
+
try {
|
|
301
|
+
if (!Buffer.isBuffer(buffer) || buffer.length < 12) return null;
|
|
302
|
+
const tag = buffer.toString('latin1', 0, 4);
|
|
303
|
+
const offsets = [];
|
|
304
|
+
if (tag === 'ttcf') {
|
|
305
|
+
const count = buffer.readUInt32BE(8);
|
|
306
|
+
for (let index = 0; index < Math.min(count, 64); index += 1) offsets.push(buffer.readUInt32BE(12 + index * 4));
|
|
307
|
+
} else if (tag === 'OTTO' || tag === 'true' || buffer.readUInt32BE(0) === 0x00010000) {
|
|
308
|
+
offsets.push(0);
|
|
309
|
+
} else {
|
|
310
|
+
return null;
|
|
311
|
+
}
|
|
312
|
+
const ranges = [];
|
|
313
|
+
for (const offset of offsets) {
|
|
314
|
+
const tables = buffer.readUInt16BE(offset + 4);
|
|
315
|
+
for (let index = 0; index < tables; index += 1) {
|
|
316
|
+
const record = offset + 12 + index * 16;
|
|
317
|
+
if (buffer.toString('latin1', record, record + 4) !== 'cmap') continue;
|
|
318
|
+
ranges.push(...cmapRanges(buffer, buffer.readUInt32BE(record + 8)));
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
return ranges;
|
|
322
|
+
} catch {
|
|
323
|
+
return null;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
function cmapRanges(buffer, cmap) {
|
|
328
|
+
const count = buffer.readUInt16BE(cmap + 2);
|
|
329
|
+
const ranges = [];
|
|
330
|
+
const seen = new Set();
|
|
331
|
+
for (let index = 0; index < count; index += 1) {
|
|
332
|
+
const sub = cmap + buffer.readUInt32BE(cmap + 4 + index * 8 + 4);
|
|
333
|
+
if (seen.has(sub)) continue;
|
|
334
|
+
seen.add(sub);
|
|
335
|
+
const format = buffer.readUInt16BE(sub);
|
|
336
|
+
if (format === 4) {
|
|
337
|
+
const segments = buffer.readUInt16BE(sub + 6) / 2;
|
|
338
|
+
const ends = sub + 14;
|
|
339
|
+
const starts = ends + segments * 2 + 2;
|
|
340
|
+
for (let segment = 0; segment < segments; segment += 1) {
|
|
341
|
+
const end = buffer.readUInt16BE(ends + segment * 2);
|
|
342
|
+
const first = buffer.readUInt16BE(starts + segment * 2);
|
|
343
|
+
if (end !== 0xffff || first !== 0xffff) ranges.push([first, end]);
|
|
344
|
+
}
|
|
345
|
+
} else if (format === 12) {
|
|
346
|
+
const groups = buffer.readUInt32BE(sub + 12);
|
|
347
|
+
for (let group = 0; group < groups; group += 1) {
|
|
348
|
+
const at = sub + 16 + group * 12;
|
|
349
|
+
ranges.push([buffer.readUInt32BE(at), buffer.readUInt32BE(at + 4)]);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
return ranges;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/** True when any range holds the character's code point. */
|
|
357
|
+
export function covers(ranges, char) {
|
|
358
|
+
const point = char.codePointAt(0);
|
|
359
|
+
return ranges.some(([first, last]) => point >= first && point <= last);
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* Read a Godot project for what would leave a playtester unable to read or
|
|
364
|
+
* press something. Reads files only; never starts the engine.
|
|
365
|
+
*
|
|
366
|
+
* @param {string} projectDir
|
|
367
|
+
* @param {{extraText?: string}} [options] `extraText` is the brief, whose
|
|
368
|
+
* language the game is expected to show
|
|
369
|
+
* @returns {Promise<Object|null>} null when the directory is not a Godot project
|
|
370
|
+
*/
|
|
371
|
+
export async function scanGodotProject(projectDir, { extraText = '' } = {}) {
|
|
372
|
+
let project = null;
|
|
373
|
+
try {
|
|
374
|
+
project = await fs.readFile(path.join(projectDir, 'project.godot'), 'utf8');
|
|
375
|
+
} catch {
|
|
376
|
+
return null;
|
|
377
|
+
}
|
|
378
|
+
const { files, truncated } = await walk(projectDir);
|
|
379
|
+
const relative = file => path.relative(projectDir, file).split(path.sep).join('/');
|
|
380
|
+
const silent = [];
|
|
381
|
+
const drawn = [];
|
|
382
|
+
let stateHook = false;
|
|
383
|
+
let scenes = 0;
|
|
384
|
+
let scripts = 0;
|
|
385
|
+
let shown = '';
|
|
386
|
+
const fonts = [];
|
|
387
|
+
const unreadFonts = [];
|
|
388
|
+
for (const file of files) {
|
|
389
|
+
const extension = path.extname(file).toLowerCase();
|
|
390
|
+
if (['.ttf', '.otf', '.ttc'].includes(extension)) {
|
|
391
|
+
let ranges = null;
|
|
392
|
+
try {
|
|
393
|
+
const info = await fs.stat(file);
|
|
394
|
+
if (info.size <= MAX_FONT_BYTES) ranges = fontRanges(await fs.readFile(file));
|
|
395
|
+
} catch {
|
|
396
|
+
ranges = null;
|
|
397
|
+
}
|
|
398
|
+
if (ranges) fonts.push({ file: relative(file), ranges });
|
|
399
|
+
else unreadFonts.push(relative(file));
|
|
400
|
+
continue;
|
|
401
|
+
}
|
|
402
|
+
if (['.woff', '.woff2', '.fnt', '.font'].includes(extension)) {
|
|
403
|
+
unreadFonts.push(relative(file));
|
|
404
|
+
continue;
|
|
405
|
+
}
|
|
406
|
+
if (!['.tscn', '.gd', '.csv', '.po'].includes(extension)) continue;
|
|
407
|
+
let source = '';
|
|
408
|
+
try {
|
|
409
|
+
const info = await fs.stat(file);
|
|
410
|
+
if (info.size > MAX_TEXT_BYTES) continue;
|
|
411
|
+
source = await fs.readFile(file, 'utf8');
|
|
412
|
+
} catch {
|
|
413
|
+
continue;
|
|
414
|
+
}
|
|
415
|
+
if (extension === '.tscn') {
|
|
416
|
+
scenes += 1;
|
|
417
|
+
for (const entry of silentNodesInScene(source)) silent.push({ file: relative(file), ...entry });
|
|
418
|
+
shown += `${stringLiterals(source)}\n`;
|
|
419
|
+
} else if (extension === '.gd') {
|
|
420
|
+
scripts += 1;
|
|
421
|
+
const found = scanScript(source);
|
|
422
|
+
for (const entry of found.silent) silent.push({ file: relative(file), ...entry });
|
|
423
|
+
if (found.drawsOwnControls) drawn.push(relative(file));
|
|
424
|
+
if (found.stateHook) stateHook = true;
|
|
425
|
+
shown += `${stringLiterals(source)}\n`;
|
|
426
|
+
} else {
|
|
427
|
+
shown += `${source}\n`;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
const mainScene = (project.match(/^run\/main_scene\s*=\s*"([^"]*)"/m) || [])[1] || null;
|
|
431
|
+
let rootType = null;
|
|
432
|
+
if (mainScene && mainScene.startsWith('res://')) {
|
|
433
|
+
try {
|
|
434
|
+
const main = await fs.readFile(path.join(projectDir, mainScene.slice('res://'.length)), 'utf8');
|
|
435
|
+
rootType = ((main.match(/^\[node\s+[^\]]*\]/m) || [''])[0].match(/\btype="([^"]*)"/) || [])[1] || null;
|
|
436
|
+
} catch {
|
|
437
|
+
rootType = null;
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
const projectFont = (project.match(/^theme\/custom_font\s*=\s*"([^"]*)"/m) || [])[1] || null;
|
|
441
|
+
const needed = lettersNeedingAFont(`${shown}\n${extraText}`);
|
|
442
|
+
const uncovered = needed.filter(char => !fonts.some(font => covers(font.ranges, char)));
|
|
443
|
+
return {
|
|
444
|
+
scenes,
|
|
445
|
+
scripts,
|
|
446
|
+
truncated,
|
|
447
|
+
silent,
|
|
448
|
+
drawn,
|
|
449
|
+
stateHook,
|
|
450
|
+
mainScene,
|
|
451
|
+
rootType,
|
|
452
|
+
fonts: fonts.map(font => font.file),
|
|
453
|
+
unreadFonts,
|
|
454
|
+
projectFont,
|
|
455
|
+
lettersNeedingAFont: needed.length,
|
|
456
|
+
uncovered
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
/* ------------------------------------------------------------------- rows */
|
|
461
|
+
|
|
462
|
+
const row = (name, status, detail, fix = null) => ({ name, status, detail, fix });
|
|
463
|
+
const clip = (text, max) => (text.length <= max ? text : `${text.slice(0, max - 3).trimEnd()}...`);
|
|
464
|
+
const plural = (count, noun) => `${count} ${noun}${count === 1 ? '' : 's'}`;
|
|
465
|
+
|
|
466
|
+
/** Every string in a brief, for the language it is written in. */
|
|
467
|
+
export function briefText(fields) {
|
|
468
|
+
const out = [];
|
|
469
|
+
const visit = value => {
|
|
470
|
+
if (typeof value === 'string') out.push(value);
|
|
471
|
+
else if (Array.isArray(value)) value.forEach(visit);
|
|
472
|
+
else if (value && typeof value === 'object') Object.values(value).forEach(visit);
|
|
473
|
+
};
|
|
474
|
+
visit(fields);
|
|
475
|
+
return out.join('\n');
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
/**
|
|
479
|
+
* The `full run` rows of `check`: one per thin-run risk, each a warning with
|
|
480
|
+
* its fix, or a pass that says what was read.
|
|
481
|
+
*
|
|
482
|
+
* @param {Object} input
|
|
483
|
+
* @param {Object|null} input.fields the brief's fields, or null when it could not be read
|
|
484
|
+
* @param {string} input.driverName
|
|
485
|
+
* @param {Object|null} input.godot a {@link scanGodotProject} result, or null
|
|
486
|
+
* @param {boolean} input.video whether the run will record a video
|
|
487
|
+
* @returns {Array<{name: string, status: string, detail: string, fix: string|null}>}
|
|
488
|
+
*/
|
|
489
|
+
export function readinessRows({ fields = null, driverName, godot = null, video = false }) {
|
|
490
|
+
const rows = [];
|
|
491
|
+
if (fields) {
|
|
492
|
+
const gaps = briefGaps(fields);
|
|
493
|
+
rows.push(gaps.length === 0
|
|
494
|
+
? row('full run: brief', 'pass', 'says how to start, the controls, what success looks like and what is already known')
|
|
495
|
+
: row('full run: brief', 'warn', gaps.join('; '), 'ravensight-playtest brief (or brief --from <file>): a playtester that has to guess the start or the choice spends its budget guessing'));
|
|
496
|
+
}
|
|
497
|
+
if (godot) {
|
|
498
|
+
const read = `${plural(godot.scenes, 'scene')} and ${plural(godot.scripts, 'script')} read${godot.truncated ? ' (the project is larger than one scan reads)' : ''}`;
|
|
499
|
+
if (godot.silent.length > 0) {
|
|
500
|
+
const sample = godot.silent.slice(0, 5).map(entry => `${entry.file}${entry.line ? `:${entry.line}` : ''} ${entry.node} (${entry.type})`).join(', ');
|
|
501
|
+
rows.push(row(
|
|
502
|
+
'full run: controls',
|
|
503
|
+
'warn',
|
|
504
|
+
`${plural(godot.silent.length, 'pressable node')} with no text, tooltip or labelled child: ${sample}${godot.silent.length > 5 ? `, and ${godot.silent.length - 5} more` : ''}`,
|
|
505
|
+
'set text, or tooltip_text (the driver reads it as the control\'s label), on each: the playtester picks an unlabelled control blind, or pays for a picture on every screen that has one'
|
|
506
|
+
));
|
|
507
|
+
} else {
|
|
508
|
+
rows.push(row('full run: controls', 'pass', `${read}; every pressable node found has text, a tooltip or a labelled child`));
|
|
509
|
+
}
|
|
510
|
+
if (godot.drawn.length > 0 || /3D$/.test(godot.rootType || '')) {
|
|
511
|
+
const why = [
|
|
512
|
+
...(godot.drawn.length > 0 ? [`${godot.drawn.slice(0, 3).join(', ')} ${godot.drawn.length === 1 ? 'draws' : 'draw'} and read${godot.drawn.length === 1 ? 's' : ''} clicks without nodes`] : []),
|
|
513
|
+
...(/3D$/.test(godot.rootType || '') ? [`the main scene is 3D (${godot.rootType})`] : [])
|
|
514
|
+
].join('; ');
|
|
515
|
+
rows.push(row(
|
|
516
|
+
'full run: screens the driver can read',
|
|
517
|
+
'warn',
|
|
518
|
+
`${why}: those screens reach the playtester as a picture only, which costs more of the model budget per turn`,
|
|
519
|
+
godot.stateHook
|
|
520
|
+
? 'put a named Button over each pressable region where you can, and consider run --long'
|
|
521
|
+
: 'expose the game state (a node in the ravensight_state group with _ravensight_state()), put a named Button over each pressable region where you can, and consider run --long'
|
|
522
|
+
));
|
|
523
|
+
}
|
|
524
|
+
rows.push(godot.stateHook
|
|
525
|
+
? row('full run: game state', 'pass', 'a _ravensight_state() hook is defined, so a choice or a result can be confirmed without a picture')
|
|
526
|
+
: row('full run: game state', 'warn', 'no _ravensight_state() hook: whether a choice took effect is read from screen text alone', 'add a node to the ravensight_state group with func _ravensight_state() -> Dictionary that returns what a tester needs (the screen, the chosen faction or character, the turn, the score)'));
|
|
527
|
+
if (godot.lettersNeedingAFont > 0) {
|
|
528
|
+
const sample = godot.uncovered.slice(0, 8).join('');
|
|
529
|
+
if (godot.uncovered.length > 0) {
|
|
530
|
+
rows.push(row(
|
|
531
|
+
'full run: fonts',
|
|
532
|
+
'warn',
|
|
533
|
+
godot.fonts.length === 0
|
|
534
|
+
? `the game's text or the brief uses ${plural(godot.lettersNeedingAFont, 'letter')} the engine's built-in font does not draw (${sample}), and the project ships no font file${godot.unreadFonts.length > 0 ? ` this check can read (not read: ${godot.unreadFonts.slice(0, 3).join(', ')})` : ''}: the text depends on the fonts of whatever machine runs the game`
|
|
535
|
+
: `${plural(godot.uncovered.length, 'letter')} in the game's text or the brief (${sample}) ${godot.uncovered.length === 1 ? 'is' : 'are'} in none of the project's fonts (${godot.fonts.slice(0, 3).join(', ')})`,
|
|
536
|
+
'add a .ttf or .otf that covers the language and set it as the project font (Project Settings, GUI, Theme, Custom Font): boxes on screen are read as a broken game'
|
|
537
|
+
));
|
|
538
|
+
} else {
|
|
539
|
+
rows.push(row('full run: fonts', godot.projectFont ? 'pass' : 'warn',
|
|
540
|
+
`${godot.fonts.slice(0, 3).join(', ')} ${godot.fonts.length === 1 ? 'covers' : 'cover'} the ${plural(godot.lettersNeedingAFont, 'letter')} outside the built-in font${godot.projectFont ? `; the project font is ${godot.projectFont}` : ', but no project font is set'}`,
|
|
541
|
+
godot.projectFont ? null : 'set the font as the project font (Project Settings, GUI, Theme, Custom Font), unless your theme already applies it to every control'));
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
if (driverName !== 'cli_stdio') {
|
|
546
|
+
rows.push(video
|
|
547
|
+
? row('full run: video', 'pass', driverName === 'godot_driver' ? 'the run keeps a video on this machine when ffmpeg is installed' : 'the run keeps a video on this machine')
|
|
548
|
+
: row('full run: video', 'warn', 'no video will be recorded (--no-record-video)', 'leave --no-record-video out: a playwright_web or godot_driver run keeps a video on this machine by default, and --upload-video sends it too'));
|
|
549
|
+
}
|
|
550
|
+
return rows;
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
/**
|
|
554
|
+
* Scan and build the rows in one call, for `check`.
|
|
555
|
+
*
|
|
556
|
+
* @param {Object} input
|
|
557
|
+
* @param {Object|null} input.fields
|
|
558
|
+
* @param {string} input.driverName
|
|
559
|
+
* @param {string|null} input.godotProject a project directory, or null
|
|
560
|
+
* @param {boolean} input.video
|
|
561
|
+
* @returns {Promise<{rows: Array, facts: Object}>}
|
|
562
|
+
*/
|
|
563
|
+
export async function inspectReadiness({ fields = null, driverName, godotProject = null, video = false }) {
|
|
564
|
+
const godot = godotProject ? await scanGodotProject(godotProject, { extraText: fields ? briefText(fields) : '' }) : null;
|
|
565
|
+
const rows = readinessRows({ fields, driverName, godot, video });
|
|
566
|
+
return {
|
|
567
|
+
rows,
|
|
568
|
+
facts: {
|
|
569
|
+
warnings: rows.filter(entry => entry.status === 'warn').map(entry => entry.name),
|
|
570
|
+
brief_gaps: fields ? briefGaps(fields) : null,
|
|
571
|
+
godot: godot && {
|
|
572
|
+
scenes: godot.scenes,
|
|
573
|
+
scripts: godot.scripts,
|
|
574
|
+
silent_controls: godot.silent,
|
|
575
|
+
drawn_screens: godot.drawn,
|
|
576
|
+
state_hook: godot.stateHook,
|
|
577
|
+
fonts: godot.fonts,
|
|
578
|
+
uncovered_letters: godot.uncovered.length
|
|
579
|
+
},
|
|
580
|
+
video
|
|
581
|
+
}
|
|
582
|
+
};
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
export default { CAPABILITY_NOTE_FIXES, CAPABILITY_NOTE_TAGS, capabilityNotesIn, capabilityNoteLines, briefGaps, scanGodotProject, readinessRows, inspectReadiness };
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An answer from the model that is not the persona's.
|
|
3
|
+
*
|
|
4
|
+
* A turn with no tool call is how a persona stops, so the loop used to read
|
|
5
|
+
* every such turn as the persona quitting, and kept its words as the reason.
|
|
6
|
+
* Two kinds of answer are not that:
|
|
7
|
+
*
|
|
8
|
+
* - **A refusal.** The provider stops the answer (`stop_reason: "refusal"`),
|
|
9
|
+
* or the model declines in its own voice ("I can't help with that"). That
|
|
10
|
+
* is the model, not a player giving up on the game.
|
|
11
|
+
* - **An unreadable answer.** No words and no tool call, or an answer cut off
|
|
12
|
+
* at the output limit before any tool call.
|
|
13
|
+
*
|
|
14
|
+
* Either is counted, asked once more with a neutral restatement of the job,
|
|
15
|
+
* and never becomes a finding, a quit in the persona's name, or by itself the
|
|
16
|
+
* end of the session. Two in a row end play as the runner's limit, said so.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The model declining in its own voice. Phrases, and only at the start of the
|
|
21
|
+
* answer: a persona saying "I can't figure out this menu" or "I give up" is
|
|
22
|
+
* the persona, and is left alone.
|
|
23
|
+
*/
|
|
24
|
+
export const REFUSAL_TEXT = new RegExp([
|
|
25
|
+
"^(?:i['’]?m sorry|i am sorry|sorry|i apologi[sz]e|unfortunately)[,.!]?\\s+(?:but\\s+)?i\\s+(?:can(?:['’]t|not)|am (?:not able|unable)|won['’]t|will not|must decline)\\b",
|
|
26
|
+
"^i\\s+(?:can(?:['’]t|not)|am (?:not able|unable) to|won['’]t|will not|must decline to|do not feel comfortable|don['’]t feel comfortable)\\s+(?:help|assist|continue|comply|proceed|do that|engage|participate|take part|role-?play|pretend|provide|generate|fulfil+)\\b",
|
|
27
|
+
"^as an ai\\b",
|
|
28
|
+
"^i['’]?m (?:just )?an ai\\b",
|
|
29
|
+
"\\bi (?:can(?:['’]t|not)|am unable to|won['’]t) (?:help|assist|comply) with (?:that|this)(?: request)?\\b"
|
|
30
|
+
].join('|'), 'i');
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @param {{text?: string, toolUses?: Array, stopReason?: string|null}} answer
|
|
34
|
+
* @returns {'refusal'|'unreadable'|null} null for an answer the loop reads as it always did
|
|
35
|
+
*/
|
|
36
|
+
export function declinedAnswer(answer) {
|
|
37
|
+
if (!answer) return 'unreadable';
|
|
38
|
+
if (answer.stopReason === 'refusal') return 'refusal';
|
|
39
|
+
if (Array.isArray(answer.toolUses) && answer.toolUses.length > 0) return null;
|
|
40
|
+
const text = String(answer.text == null ? '' : answer.text).trim();
|
|
41
|
+
if (text === '') return 'unreadable';
|
|
42
|
+
// Cut off at the output limit with no tool call: whatever it was going to do is lost.
|
|
43
|
+
if (answer.stopReason === 'max_tokens') return 'unreadable';
|
|
44
|
+
return REFUSAL_TEXT.test(text) ? 'refusal' : null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** What the model is asked after an answer that was not the persona's. */
|
|
48
|
+
export const NEUTRAL_RESTATEMENT = 'The last answer could not be used: it held no input for the game. This is a playtest of a video game build, run for its developer, and you are the tester. Look at the screen above and send your next input as a tool call. If you are finished playing, say in one sentence, as the tester, why you stop.';
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Why play ended when the model declined twice in a row.
|
|
52
|
+
*
|
|
53
|
+
* @param {number} actions
|
|
54
|
+
* @param {'refusal'|'unreadable'} how
|
|
55
|
+
* @returns {string}
|
|
56
|
+
*/
|
|
57
|
+
export function declinedStopDetail(actions, how) {
|
|
58
|
+
return `the model ${how === 'refusal' ? 'declined to answer' : 'gave no usable answer'} twice in a row after ${actions} action${actions === 1 ? '' : 's'}; play ended there. This is a limit of the runner, not the persona stopping and not a problem in the game`;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** The report step's instruction when the model declined during play. */
|
|
62
|
+
export function declinedPrompt(count, ended) {
|
|
63
|
+
if (!count) return '';
|
|
64
|
+
return `During play the model ${count === 1 ? 'once gave an answer' : `gave ${count} answers`} that could not be used (a refusal or an empty answer) and was asked again. That is the runner's concern and says nothing about the game or the persona: never write a finding, a quit or a reaction from it.${ended ? ' Play ended on two of them in a row: say in "What this run didn\'t cover" that the session was cut short by the runner, and do not describe it as the persona giving up.' : ''}`;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export default { declinedAnswer, declinedStopDetail, declinedPrompt, NEUTRAL_RESTATEMENT, REFUSAL_TEXT };
|