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.
Files changed (66) hide show
  1. package/README.md +280 -66
  2. package/addons/ravensight_driver/driver.gd +666 -21
  3. package/docs/ADAPTERS.md +11 -7
  4. package/docs/NATIVE_RUNNER.md +3 -1
  5. package/docs/godot-driver.md +127 -13
  6. package/package.json +8 -6
  7. package/src/api/client.js +4 -3
  8. package/src/cli.js +84 -25
  9. package/src/commands/check.js +30 -4
  10. package/src/commands/fakeCore.js +1 -0
  11. package/src/commands/hosted.js +41 -12
  12. package/src/commands/init.js +17 -1
  13. package/src/commands/run.js +209 -14
  14. package/src/commands/upload.js +6 -2
  15. package/src/commands/validate.js +1 -1
  16. package/src/commands/validateHosted.js +50 -5
  17. package/src/config.js +33 -2
  18. package/src/hosted/archivePreflight.js +7 -7
  19. package/src/hosted/buildUpload.js +89 -8
  20. package/src/hosted/recordedRun.js +141 -26
  21. package/src/hosted/status.js +19 -10
  22. package/src/run/actionSelector.js +14 -3
  23. package/src/run/aggregate.js +57 -3
  24. package/src/run/anygame/controlbook.js +179 -0
  25. package/src/run/anygame/genre.js +179 -0
  26. package/src/run/anygame/index.js +258 -0
  27. package/src/run/anygame/language.js +336 -0
  28. package/src/run/anygame/memory.js +330 -0
  29. package/src/run/anygame/shared-hashes.json +10 -0
  30. package/src/run/anygame/shared.js +24 -0
  31. package/src/run/anygame/sound.js +342 -0
  32. package/src/run/args.js +75 -8
  33. package/src/run/choiceCheck.js +312 -0
  34. package/src/run/context.js +254 -13
  35. package/src/run/drivers/godot-observation.js +93 -6
  36. package/src/run/drivers/godot.js +769 -46
  37. package/src/run/drivers/recording.js +24 -4
  38. package/src/run/drivers/web.js +1242 -77
  39. package/src/run/edgePass.js +731 -0
  40. package/src/run/fixLoop.js +5 -4
  41. package/src/run/focus.js +65 -0
  42. package/src/run/gamepad.js +108 -0
  43. package/src/run/godotEdgePass.js +235 -0
  44. package/src/run/godotTesterProbes.js +192 -0
  45. package/src/run/headings.js +21 -0
  46. package/src/run/honesty.js +544 -0
  47. package/src/run/inputs.js +256 -0
  48. package/src/run/marks.js +142 -0
  49. package/src/run/personaLoop.js +1000 -79
  50. package/src/run/phone.js +7 -0
  51. package/src/run/pixels.js +215 -0
  52. package/src/run/playClock.js +162 -0
  53. package/src/run/readiness.js +585 -0
  54. package/src/run/refusal.js +67 -0
  55. package/src/run/regions.js +119 -0
  56. package/src/run/report.js +14 -2
  57. package/src/run/reportChecks.js +472 -0
  58. package/src/run/resume.js +3 -2
  59. package/src/run/screenshots.js +161 -0
  60. package/src/run/strip.js +114 -0
  61. package/src/run/testerLedger.js +312 -0
  62. package/src/run/testerProbes.js +584 -0
  63. package/src/run/thinRun.js +102 -0
  64. package/src/run/timeFreeze.js +79 -0
  65. package/src/run/tools.js +454 -29
  66. package/src/runDefaults.js +24 -2
@@ -0,0 +1,330 @@
1
+ // The run's memory: what a long playtest has learned, kept by the runner and
2
+ // carried into every plan (BR-19 in docs/playtest/PLAYTESTER_EDGE_CASES.md).
3
+ //
4
+ // The planner is asked afresh on every look and remembers nothing itself: the
5
+ // loop gave it the last 8 inputs and the goal list, so by minute 60 it no
6
+ // longer knew what minute 2 taught it and tried the same locked door again.
7
+ // The memory holds:
8
+ //
9
+ // - what the game is, in the planner's own words;
10
+ // - what the planner said it learned (a rule, a dead end, where things are,
11
+ // what a tutorial told it, what beat it, a choice it made on this pass);
12
+ // - the titles of what it already reported, so it is not reported again;
13
+ // - dead ends the runner measured: an input that changed nothing on a named
14
+ // screen, counted, whoever chose it;
15
+ // - the places seen and how each was reached;
16
+ // - levels finished, losses, wins and endings reached, as counters, and
17
+ // what was chosen for the brief.
18
+ //
19
+ // It is rendered as one block of at most `maxChars` characters, whatever the
20
+ // run's length. When the notes outgrow that, they are summarised by rule, with
21
+ // no model call: repeats are merged and counted, dead ends are grouped by
22
+ // place, and of the rest the oldest confirmed notes and the newest are kept,
23
+ // with a count of what was left out. So a plan's prompt has a fixed ceiling
24
+ // and the memory costs no call of its own.
25
+ //
26
+ // Pure: no I/O, no page, no model. The same file is carried by the hosted runner
27
+ // (the platform repo, infrastructure/hosted-playtest/direct-runner/lib/anygame/memory.mjs).
28
+
29
+ export const MEMORY_MAX_CHARS = 1200;
30
+ export const FACT_MAX_CHARS = 90;
31
+ export const ABOUT_MAX_CHARS = 120;
32
+ // Kinds of note the planner may hand in.
33
+ export const FACT_KINDS = ['rule', 'dead_end', 'place', 'control', 'tutorial', 'death', 'choice'];
34
+ // How each kind is headed in the block, in the order shown. Dead ends have their own line.
35
+ const KIND_HEADS = [['tutorial', 'The game told you'], ['rule', 'Learned'], ['control', 'Learned'], ['place', 'Learned'], ['death', 'What beat you'], ['choice', 'Choices you made']];
36
+ // An input must change nothing this many times on a place before it is called a dead end there.
37
+ export const DEAD_END_AFTER = 2;
38
+ // Notes held at most; past it the least confirmed, oldest-seen note gives way.
39
+ export const MAX_FACTS = 120;
40
+ export const MAX_PLACES = 80;
41
+ export const MAX_FAILS = 200;
42
+ // How alike two notes must be to be one note (share of their words in common).
43
+ export const SAME_NOTE = 0.7;
44
+
45
+ const norm = s => String(s ?? '').normalize('NFKC');
46
+ /** A note's text made safe to carry: one line, no braces or quotes that could be read as structure. */
47
+ export function cleanNote(text, max = FACT_MAX_CHARS) {
48
+ return norm(text).replace(/[\u0000-\u001f\u007f]+/g, ' ').replace(/[{}[\]<>`"\\]/g, '').replace(/[\u2013\u2014]/g, ', ').replace(/\s+/g, ' ').trim().slice(0, max).trim();
49
+ }
50
+
51
+ const STOP = new Set(['the', 'a', 'an', 'of', 'to', 'is', 'it', 'and', 'in', 'on', 'at', 'this', 'that']);
52
+ /** What two notes are compared by: words, or pairs of letters where the script has no spaces. */
53
+ export function noteTokens(text) {
54
+ const t = norm(text).toLowerCase();
55
+ const out = new Set();
56
+ for (const w of t.match(/[\p{L}\p{N}]+/gu) || []) {
57
+ if (/[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}]/u.test(w)) { const c = [...w]; if (c.length === 1) out.add(w); for (let i = 0; i + 1 < c.length; i++) out.add(c[i] + c[i + 1]); }
58
+ else if (!STOP.has(w)) out.add(w);
59
+ }
60
+ return out;
61
+ }
62
+
63
+ /** The share of two notes' words they have in common (0 to 1). */
64
+ export function alike(a, b) {
65
+ const A = a instanceof Set ? a : noteTokens(a), B = b instanceof Set ? b : noteTokens(b);
66
+ if (!A.size || !B.size) return 0;
67
+ let shared = 0;
68
+ for (const x of A) if (B.has(x)) shared++;
69
+ return shared / (A.size + B.size - shared);
70
+ }
71
+
72
+ /** A place's key: its label without case, articles or punctuation, so "The Title Menu" and "title menu" are one place. */
73
+ export function placeKey(label) {
74
+ return [...noteTokens(cleanNote(label, 60))].join(' ').slice(0, 60) || 'unnamed';
75
+ }
76
+
77
+ const plural = (n, one, many = `${one}s`) => `${n} ${n === 1 ? one : many}`;
78
+ /** A note shortened to `n` characters at a word's end, never in the middle of one (scripts without spaces are cut where they are). */
79
+ export function shorten(text, n) {
80
+ const t = String(text);
81
+ if (t.length <= n) return t;
82
+ const cut = t.slice(0, n), at = cut.lastIndexOf(' ');
83
+ return (at >= n * 0.6 ? cut.slice(0, at) : cut).trim();
84
+ }
85
+
86
+ export function createMemory({ maxChars = MEMORY_MAX_CHARS } = {}) {
87
+ let about = null;
88
+ const facts = [];
89
+ const fails = new Map();
90
+ const places = new Map();
91
+ const edges = [];
92
+ const events = { level_done: [], game_over: [], won: [], ended: [] };
93
+ const notices = [];
94
+ const choices = [];
95
+ let now = null;
96
+ const stats = { renders: 0, compactions: 0, maxRendered: 0, leftOut: 0, factsDropped: 0, learned: 0, repeats: 0 };
97
+
98
+ /** What the game is, as the planner put it. The first account stands until a later one says more. */
99
+ function setAbout(text, step = 0) {
100
+ const t = cleanNote(text, ABOUT_MAX_CHARS);
101
+ if (t.length < 4) return false;
102
+ if (about && t.length <= about.text.length && alike(t, about.text) >= 0.5) return false;
103
+ about = { text: t, step, first: about ? about.first : step };
104
+ return true;
105
+ }
106
+
107
+ /** One note from the planner. A note already held is confirmed, not added. Returns true when it was new. */
108
+ function learn(fact, { step = 0, place = now } = {}) {
109
+ const kind = FACT_KINDS.includes(fact?.t) ? fact.t : 'rule';
110
+ const text = cleanNote(fact?.s ?? fact?.text);
111
+ if ([...text].length < 3) return false;
112
+ const tokens = noteTokens(text);
113
+ const same = facts.find(f => f.kind === kind && alike(f.tokens, tokens) >= SAME_NOTE);
114
+ if (same) {
115
+ same.seen++; same.lastStep = step; stats.repeats++;
116
+ return false;
117
+ }
118
+ facts.push({ kind, text, tokens, firstStep: step, lastStep: step, seen: 1, place: place || null });
119
+ stats.learned++;
120
+ if (facts.length > MAX_FACTS) {
121
+ // The least confirmed note that was not seen lately gives way; the first notes of the run stay.
122
+ const order = facts.map((f, i) => ({ f, i })).filter(x => x.i >= 8).sort((a, b) => (a.f.seen - b.f.seen) || (a.f.lastStep - b.f.lastStep));
123
+ facts.splice(order[0].i, 1);
124
+ stats.factsDropped++;
125
+ }
126
+ return true;
127
+ }
128
+
129
+ /** An input that changed nothing on a place (measured by the runner). */
130
+ function failed(place, input, step = 0) {
131
+ const label = cleanNote(input, 60);
132
+ if (!label) return;
133
+ const pk = placeKey(place || now || 'unnamed');
134
+ const k = `${pk}|${label.toLowerCase()}`;
135
+ const f = fails.get(k) || { place: pk, label: places.get(pk)?.label || cleanNote(place || 'this screen', 40), input: label, n: 0, firstStep: step, lastStep: step };
136
+ f.n++; f.lastStep = step;
137
+ fails.set(k, f);
138
+ if (fails.size > MAX_FAILS) {
139
+ const oldest = [...fails.entries()].sort((a, b) => (a[1].n - b[1].n) || (a[1].lastStep - b[1].lastStep))[0];
140
+ fails.delete(oldest[0]);
141
+ }
142
+ }
143
+
144
+ /** An input that changed something on a place: it is no dead end there any more. */
145
+ function worked(place, input) {
146
+ const label = cleanNote(input, 60);
147
+ fails.delete(`${placeKey(place || now || 'unnamed')}|${label.toLowerCase()}`);
148
+ }
149
+
150
+ /** The planner named the screen it is on. `via` is the input that brought it there, when one did. */
151
+ function arrive(label, step = 0, { via = null } = {}) {
152
+ const text = cleanNote(label, 40);
153
+ if (!text) return now;
154
+ const k = placeKey(text);
155
+ const p = places.get(k) || { label: text, firstStep: step, lastStep: step, visits: 0 };
156
+ if (now !== k) {
157
+ p.visits++;
158
+ if (now && !edges.some(e => e.from === now && e.to === k)) {
159
+ edges.push({ from: now, to: k, via: via ? cleanNote(via, 50) : null, step });
160
+ if (edges.length > MAX_PLACES * 2) edges.shift();
161
+ }
162
+ }
163
+ p.lastStep = step;
164
+ places.set(k, p);
165
+ if (places.size > MAX_PLACES) {
166
+ const oldest = [...places.entries()].filter(([key]) => key !== k).sort((a, b) => a[1].lastStep - b[1].lastStep)[0];
167
+ places.delete(oldest[0]);
168
+ }
169
+ now = k;
170
+ return k;
171
+ }
172
+
173
+ /** A level finished, a loss or a win, read off the screen by the planner. */
174
+ function event(kind, step = 0) {
175
+ if (!events[kind]) return;
176
+ const last = events[kind].at(-1);
177
+ // One reading of one screen is one event, however many plans read it.
178
+ if (last && last.place === now && step - last.step < 3) return;
179
+ events[kind].push({ step, place: now });
180
+ }
181
+
182
+ /** A thing the planner reported about the game: its title is kept so the same thing is not reported twice. */
183
+ function noticed(title, step = 0) {
184
+ const t = cleanNote(title, FACT_MAX_CHARS);
185
+ if (!t) return false;
186
+ const tokens = noteTokens(t);
187
+ if (notices.some(n => alike(n.tokens, tokens) >= SAME_NOTE)) return false;
188
+ notices.push({ title: t, tokens, step });
189
+ if (notices.length > 60) notices.shift();
190
+ return true;
191
+ }
192
+
193
+ /** Whether a title says what an earlier report already said. */
194
+ const reported = title => { const tokens = noteTokens(cleanNote(title, FACT_MAX_CHARS)); return notices.some(n => alike(n.tokens, tokens) >= SAME_NOTE); };
195
+
196
+ /** What the playtester picked for something the brief named. */
197
+ function chose({ brief, screen, step = 0, seen = null }) {
198
+ const b = cleanNote(brief, 60), s = cleanNote(screen, 60);
199
+ if (!b || !s) return false;
200
+ const held = choices.find(c => c.brief.toLowerCase() === b.toLowerCase());
201
+ if (held) { held.screen = s; held.step = step; held.seen = seen; return false; }
202
+ choices.push({ brief: b, screen: s, step, seen });
203
+ if (choices.length > 12) choices.shift();
204
+ return true;
205
+ }
206
+
207
+ const placeLabel = k => places.get(k)?.label || k;
208
+
209
+ // Notes to show under a cap: a third of the room to the first ones learned, a third to the most confirmed, the rest to the newest.
210
+ // What the first minutes taught (the controls, the rules) stays in view however long the run goes on.
211
+ function pick(list, cap) {
212
+ if (list.length <= cap) return { kept: list, left: 0 };
213
+ const third = Math.max(1, Math.floor(cap / 3));
214
+ const first = [...list].sort((a, b) => a.firstStep - b.firstStep).slice(0, third);
215
+ const sure = [...list].filter(f => !first.includes(f) && f.seen > 1).sort((a, b) => (b.seen - a.seen) || (a.firstStep - b.firstStep)).slice(0, Math.min(third, cap - first.length));
216
+ const fresh = [...list].filter(f => !first.includes(f) && !sure.includes(f)).sort((a, b) => b.lastStep - a.lastStep).slice(0, cap - first.length - sure.length);
217
+ const kept = [...first, ...sure, ...fresh].sort((a, b) => a.firstStep - b.firstStep);
218
+ return { kept, left: list.length - kept.length };
219
+ }
220
+
221
+ // Room at each level of summary: notes a heading, dead ends, inputs a place, places, reports, and characters a note.
222
+ const LEVELS = [
223
+ { rules: 10, dead: 8, perPlace: 4, places: 8, notices: 8, about: ABOUT_MAX_CHARS, fact: FACT_MAX_CHARS },
224
+ { rules: 8, dead: 6, perPlace: 3, places: 6, notices: 6, about: 100, fact: 80 },
225
+ { rules: 6, dead: 5, perPlace: 3, places: 4, notices: 4, about: 90, fact: 70 },
226
+ { rules: 5, dead: 4, perPlace: 2, places: 3, notices: 3, about: 80, fact: 64 },
227
+ { rules: 4, dead: 4, perPlace: 2, places: 3, notices: 2, about: 70, fact: 60 },
228
+ { rules: 3, dead: 3, perPlace: 2, places: 2, notices: 2, about: 60, fact: 60 },
229
+ { rules: 2, dead: 2, perPlace: 1, places: 1, notices: 1, about: 60, fact: 60 }
230
+ ];
231
+
232
+
233
+ // The lines in the order of what a plan can least afford to lose: if whole lines must go, they go from the end.
234
+ function lines(level) {
235
+ const caps = LEVELS[level];
236
+ const out = [];
237
+ let left = 0;
238
+ if (about) out.push(`The game: ${shorten(about.text, caps.about)}`);
239
+ // Dead ends the planner named, then the ones the runner measured, the current place's first.
240
+ const dead = [];
241
+ const named = pick(facts.filter(f => f.kind === 'dead_end'), Math.ceil(caps.dead / 2));
242
+ left += named.left;
243
+ for (const f of named.kept) dead.push(`${shorten(f.text, caps.fact)} (step ${f.firstStep}${f.lastStep > f.firstStep ? `, again at ${f.lastStep}` : ''})`);
244
+ const byPlace = new Map();
245
+ for (const f of fails.values()) if (f.n >= DEAD_END_AFTER) byPlace.set(f.place, [...(byPlace.get(f.place) || []), f]);
246
+ const order = [...byPlace.entries()].sort((a, b) => (b[0] === now) - (a[0] === now) || Math.max(...b[1].map(f => f.lastStep)) - Math.max(...a[1].map(f => f.lastStep)));
247
+ const room = Math.max(1, caps.dead - dead.length);
248
+ for (const [k, list] of order.slice(0, room)) {
249
+ const shown = [...list].sort((a, b) => b.n - a.n).slice(0, caps.perPlace);
250
+ dead.push(`on ${placeLabel(k)}${k === now ? ' (where you are)' : ''}: ${shown.map(f => `${f.input} did nothing ${f.n} times`).join(', ')}${list.length > shown.length ? ` and ${list.length - shown.length} more` : ''}`);
251
+ }
252
+ left += Math.max(0, order.length - room);
253
+ if (dead.length) out.push(`Dead ends, do not repeat them unless something has changed that would make them work: ${dead.join('; ')}`);
254
+ // One line per heading; the kinds that share a heading share its room.
255
+ for (const head of [...new Set(KIND_HEADS.map(([, h]) => h))]) {
256
+ const kinds = KIND_HEADS.filter(([, h]) => h === head).map(([k]) => k);
257
+ const r = pick(facts.filter(f => kinds.includes(f.kind)), head === 'Learned' ? caps.rules : Math.max(1, Math.ceil(caps.rules / 2)));
258
+ left += r.left;
259
+ if (r.kept.length) out.push(`${head}: ${r.kept.map(f => `${shorten(f.text, caps.fact)} (step ${f.firstStep}${f.seen > 1 ? `, confirmed ${f.seen} times` : ''})`).join('; ')}`);
260
+ }
261
+ if (choices.length) out.push(`Chosen for the brief: ${choices.slice(-4).map(c => `${c.brief} = ${c.screen}`).join('; ')}`);
262
+ const ev = [events.level_done.length ? `${plural(events.level_done.length, 'level')} finished (last at step ${events.level_done.at(-1).step})` : '', events.won.length ? `${plural(events.won.length, 'win')} (last at step ${events.won.at(-1).step})` : '', events.game_over.length ? `${plural(events.game_over.length, 'loss', 'losses')} (last at step ${events.game_over.at(-1).step}${events.game_over.at(-1).place ? ` on ${placeLabel(events.game_over.at(-1).place)}` : ''})` : ''].filter(Boolean);
263
+ if (events.ended.length) ev.push(`the game's end reached ${plural(events.ended.length, 'time')} (last at step ${events.ended.at(-1).step})`);
264
+ if (ev.length) out.push(`So far: ${ev.join(', ')}`);
265
+ if (places.size) {
266
+ const all = [...places.entries()].sort((a, b) => b[1].lastStep - a[1].lastStep);
267
+ const shown = all.slice(0, caps.places);
268
+ const how = k => { const e = edges.filter(x => x.to === k).at(-1); return e && e.via ? ` (reached by ${e.via})` : ''; };
269
+ out.push(`Places seen, newest first: ${shown.map(([k, p]) => `${p.label}${k === now ? ' (now)' : how(k)}`).join('; ')}${all.length > shown.length ? `; and ${all.length - shown.length} more` : ''}`);
270
+ }
271
+ if (notices.length) out.push(`Already reported, do not report these again: ${notices.slice(-caps.notices).map(n => shorten(n.title, caps.fact)).join('; ')}${notices.length > caps.notices ? `; and ${notices.length - caps.notices} more` : ''}`);
272
+ if (left > 0) out.push(`(${plural(left, 'older note')} left out for room)`);
273
+ return { out, left };
274
+ }
275
+
276
+ /** Whether the memory holds anything worth a block in the prompt. */
277
+ const empty = () => !about && !facts.length && !places.size && ![...fails.values()].some(f => f.n >= DEAD_END_AFTER) && !choices.length && !notices.length && !Object.values(events).some(e => e.length);
278
+
279
+ /**
280
+ * The memory as lines for a plan, at most `maxChars` characters in all (the
281
+ * `budget` may ask for fewer). '' while there is nothing to say.
282
+ */
283
+ function render({ budget = maxChars } = {}) {
284
+ if (empty()) return '';
285
+ const cap = Math.max(120, Math.min(maxChars, budget));
286
+ stats.renders++;
287
+ let text = '', level = 0, left = 0;
288
+ for (; level < LEVELS.length; level++) {
289
+ const l = lines(level);
290
+ text = l.out.map(x => `- ${x}`).join('\n');
291
+ left = l.left;
292
+ if (text.length <= cap) break;
293
+ }
294
+ if (text.length > cap) {
295
+ // The last resort: whole lines are dropped from the end, never a note cut in half.
296
+ const kept = [];
297
+ let size = 0;
298
+ for (const line of text.split('\n')) { if (size + line.length + 1 > cap - 40) break; kept.push(line); size += line.length + 1; }
299
+ const dropped = text.split('\n').length - kept.length;
300
+ text = [...kept, `- (${plural(dropped, 'more line')} of notes left out for room)`].join('\n').slice(0, cap);
301
+ left += dropped;
302
+ level = LEVELS.length;
303
+ }
304
+ // Summarised: shown at less than full room, or with notes left out.
305
+ if (level > 0 || left > 0) stats.compactions++;
306
+ stats.leftOut = Math.max(stats.leftOut, left);
307
+ stats.maxRendered = Math.max(stats.maxRendered, text.length);
308
+ return text;
309
+ }
310
+
311
+ /** Everything held, for the report: counts and the notes themselves (bounded). */
312
+ function digest() {
313
+ return {
314
+ about: about ? about.text : null,
315
+ learned: facts.filter(f => f.kind !== 'dead_end').slice(0, 40).map(f => ({ kind: f.kind, text: f.text, firstStep: f.firstStep, lastStep: f.lastStep, seen: f.seen })),
316
+ deadEnds: [
317
+ ...facts.filter(f => f.kind === 'dead_end').slice(0, 20).map(f => ({ source: 'playtester', text: f.text, firstStep: f.firstStep, lastStep: f.lastStep, seen: f.seen })),
318
+ ...[...fails.values()].filter(f => f.n >= DEAD_END_AFTER).sort((a, b) => b.n - a.n).slice(0, 20).map(f => ({ source: 'measured', place: f.label, input: f.input, times: f.n, firstStep: f.firstStep, lastStep: f.lastStep }))
319
+ ],
320
+ places: [...places.values()].sort((a, b) => a.firstStep - b.firstStep).slice(0, 40).map(p => ({ label: p.label, firstStep: p.firstStep, visits: p.visits })),
321
+ routes: edges.slice(0, 40).map(e => ({ from: placeLabel(e.from), to: placeLabel(e.to), via: e.via, step: e.step })),
322
+ choices: choices.map(c => ({ ...c })),
323
+ events: { levelsFinished: events.level_done.length, losses: events.game_over.length, wins: events.won.length, endings: events.ended.length },
324
+ reported: notices.map(n => ({ title: n.title, step: n.step })),
325
+ stats: { ...stats, maxChars, notes: facts.length, places: places.size }
326
+ };
327
+ }
328
+
329
+ return { setAbout, learn, failed, worked, arrive, event, chose, noticed, reported, render, digest, empty, counters: () => ({ levels: events.level_done.length, losses: events.game_over.length, wins: events.won.length, endings: events.ended.length }), get place() { return now ? placeLabel(now) : null; }, get stats() { return { ...stats }; } };
330
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "comment": "Hashes of the files shared by the hosted runner (lib/anygame/*.mjs) and the local CLI (src/run/anygame/*.js), taken over the code both carry (see shared.mjs or shared.js). The same file in both repos: update it in both, after copying the change.",
3
+ "files": {
4
+ "language": "5a1152170efe91337a717823c23ed073fdd4beb1ecb515ab4e58c56806b349db",
5
+ "memory": "d33df58ba2747597156f427ba456b3e98f074e659ddb3a0fb9d5c3626a6d0846",
6
+ "controlbook": "1b388c0dd0c60f332131a095cf89eb4ee181671c60a2b4e45750a0a918c6ea9e",
7
+ "genre": "a52359537d277a59976bc6ce77fbc1e21303f10861ff77226164a9884d2b543b",
8
+ "sound": "8be235bda7903856cd9b1cdb5aad1c327c10af8d86c3b0dbb575f2d323999bb3"
9
+ }
10
+ }
@@ -0,0 +1,24 @@
1
+ // The files this folder shares with the hosted runner (the platform repo,
2
+ // infrastructure/hosted-playtest/direct-runner/lib/anygame): language, memory, controlbook, genre and sound are
3
+ // the same code in both repos. Each repo checks its own copies against one
4
+ // table of hashes (shared-hashes.json, the same file in both), so a change to
5
+ // one copy fails that repo's test until the table is updated, and the table
6
+ // in the other repo then fails until the copy there is updated too.
7
+ //
8
+ // The hash is taken over the code, not over what differs by design: the
9
+ // module extension in imports (.mjs here, .js there), the comment lines that
10
+ // name the other repo, and how each gets its `noDashes`.
11
+ import crypto from 'node:crypto';
12
+
13
+ export const SHARED = ['language', 'memory', 'controlbook', 'genre', 'sound'];
14
+
15
+ /** A shared file's text with what differs by design taken out. */
16
+ export function normalizeShared(text) {
17
+ return String(text).replace(/\r\n/g, '\n').split('\n')
18
+ .filter(line => !/hosted runner|platform repo|local CLI|ravensight-playtest, src|PLAYTESTER_EDGE_CASES/.test(line))
19
+ .filter(line => !/^import \{ noDashes \}|^const noDashes = /.test(line))
20
+ .map(line => line.replace(/(from '\.\/[a-z]+)\.mjs'/g, "$1.js'"))
21
+ .join('\n').trim();
22
+ }
23
+
24
+ export const sharedHash = text => crypto.createHash('sha256').update(normalizeShared(text)).digest('hex');