@kradle/challenges-sdk 0.10.0 → 0.11.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 (84) hide show
  1. package/CHANGELOG.md +32 -1
  2. package/LLM_README.md +235 -2333
  3. package/README.md +151 -570
  4. package/dist/index.d.ts +1 -4
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +2 -6
  7. package/dist/index.js.map +1 -1
  8. package/dist/runtime/examples/capture-the-flag.d.ts +33 -0
  9. package/dist/runtime/examples/capture-the-flag.d.ts.map +1 -0
  10. package/dist/runtime/examples/capture-the-flag.js +79 -0
  11. package/dist/runtime/examples/capture-the-flag.js.map +1 -0
  12. package/dist/runtime/examples/climb.d.ts +34 -0
  13. package/dist/runtime/examples/climb.d.ts.map +1 -0
  14. package/dist/runtime/examples/climb.js +54 -0
  15. package/dist/runtime/examples/climb.js.map +1 -0
  16. package/dist/runtime/examples/four-bridges.d.ts +107 -0
  17. package/dist/runtime/examples/four-bridges.d.ts.map +1 -0
  18. package/dist/runtime/examples/four-bridges.js +294 -0
  19. package/dist/runtime/examples/four-bridges.js.map +1 -0
  20. package/dist/runtime/examples/herding.d.ts +59 -0
  21. package/dist/runtime/examples/herding.d.ts.map +1 -0
  22. package/dist/runtime/examples/herding.js +181 -0
  23. package/dist/runtime/examples/herding.js.map +1 -0
  24. package/dist/runtime/examples/skywars.d.ts +116 -0
  25. package/dist/runtime/examples/skywars.d.ts.map +1 -0
  26. package/dist/runtime/examples/skywars.js +253 -0
  27. package/dist/runtime/examples/skywars.js.map +1 -0
  28. package/dist/runtime/harness.d.ts +176 -0
  29. package/dist/runtime/harness.d.ts.map +1 -0
  30. package/dist/runtime/harness.js +441 -0
  31. package/dist/runtime/harness.js.map +1 -0
  32. package/dist/runtime/index.d.ts +2 -0
  33. package/dist/runtime/index.d.ts.map +1 -0
  34. package/dist/runtime/index.js +18 -0
  35. package/dist/runtime/index.js.map +1 -0
  36. package/dist/runtime/sandbox-registry.d.ts +7 -0
  37. package/dist/runtime/sandbox-registry.d.ts.map +1 -0
  38. package/dist/runtime/sandbox-registry.js +16 -0
  39. package/dist/runtime/sandbox-registry.js.map +1 -0
  40. package/dist/runtime/sandbox.d.ts +29 -0
  41. package/dist/runtime/sandbox.d.ts.map +1 -0
  42. package/dist/runtime/sandbox.js +70 -0
  43. package/dist/runtime/sandbox.js.map +1 -0
  44. package/dist/runtime/sdk.d.ts +1038 -0
  45. package/dist/runtime/sdk.d.ts.map +1 -0
  46. package/dist/runtime/sdk.js +1271 -0
  47. package/dist/runtime/sdk.js.map +1 -0
  48. package/dist/runtime/world.d.ts +141 -0
  49. package/dist/runtime/world.d.ts.map +1 -0
  50. package/dist/runtime/world.js +344 -0
  51. package/dist/runtime/world.js.map +1 -0
  52. package/package.json +76 -40
  53. package/dist/actions.d.ts +0 -901
  54. package/dist/actions.d.ts.map +0 -1
  55. package/dist/actions.js +0 -1155
  56. package/dist/actions.js.map +0 -1
  57. package/dist/api_utils.d.ts +0 -25
  58. package/dist/api_utils.d.ts.map +0 -1
  59. package/dist/api_utils.js +0 -48
  60. package/dist/api_utils.js.map +0 -1
  61. package/dist/challenge.d.ts +0 -58
  62. package/dist/challenge.d.ts.map +0 -1
  63. package/dist/challenge.js +0 -582
  64. package/dist/challenge.js.map +0 -1
  65. package/dist/commands.d.ts +0 -57
  66. package/dist/commands.d.ts.map +0 -1
  67. package/dist/commands.js +0 -200
  68. package/dist/commands.js.map +0 -1
  69. package/dist/constants.d.ts +0 -78
  70. package/dist/constants.d.ts.map +0 -1
  71. package/dist/constants.js +0 -109
  72. package/dist/constants.js.map +0 -1
  73. package/dist/testmode.d.ts +0 -3
  74. package/dist/testmode.d.ts.map +0 -1
  75. package/dist/testmode.js +0 -19
  76. package/dist/testmode.js.map +0 -1
  77. package/dist/types.d.ts +0 -195
  78. package/dist/types.d.ts.map +0 -1
  79. package/dist/types.js +0 -38
  80. package/dist/types.js.map +0 -1
  81. package/dist/utils.d.ts +0 -17
  82. package/dist/utils.d.ts.map +0 -1
  83. package/dist/utils.js +0 -22
  84. package/dist/utils.js.map +0 -1
@@ -0,0 +1,441 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Fake = exports.Game = exports.canonical = void 0;
4
+ exports.sandboxed = sandboxed;
5
+ // A stand-in arena for tests. It feeds events, collects actions, keeps the event
6
+ // log, and checks on every reduction that the reducer is pure, deterministic, and
7
+ // that the state survives a JSON round trip. No test framework dependency: it
8
+ // throws plain errors, so it runs under node:test, vitest, bun test or jest.
9
+ const node_fs_1 = require("node:fs");
10
+ const sandbox_registry_js_1 = require("./sandbox-registry.js");
11
+ const sdk_js_1 = require("./sdk.js");
12
+ /** JSON with sorted keys, so key order never counts as a difference. */
13
+ const canonical = (v) => JSON.stringify(v, (_k, x) => x && typeof x === "object" && !Array.isArray(x) ? Object.fromEntries(Object.entries(x).sort()) : x);
14
+ exports.canonical = canonical;
15
+ function assertEqual(actual, expected, what) {
16
+ if (actual !== expected)
17
+ throw new Error(`${what}\n expected: ${expected}\n actual: ${actual}`);
18
+ }
19
+ /**
20
+ * Under `kradle challenge test` (`KRADLE_CHALLENGE_BUNDLE` set), a Game on the
21
+ * imported source would run the rules outside the sandbox and still count as
22
+ * a pass: refused. A Game on the bundle leaves a line in the file named by
23
+ * `KRADLE_CHALLENGE_EVIDENCE`, the command's proof that the bundle ran.
24
+ */
25
+ function requireBundleUnderTheCommand(challenge) {
26
+ const bundle = process.env.KRADLE_CHALLENGE_BUNDLE;
27
+ if (!bundle)
28
+ return;
29
+ const from = (0, sandbox_registry_js_1.sandboxOrigin)(challenge);
30
+ if (!from) {
31
+ throw new Error("KRADLE_CHALLENGE_BUNDLE is set (kradle challenge test), and this Game runs an imported challenge, not the bundle. Write `const challenge = await sandboxed(source)` and pass that to Game.");
32
+ }
33
+ const evidence = process.env.KRADLE_CHALLENGE_EVIDENCE;
34
+ if (evidence) {
35
+ (0, node_fs_1.appendFileSync)(evidence, `${JSON.stringify({ bundle: from.origin, challenge: challenge.manifest?.name })}\n`);
36
+ }
37
+ }
38
+ /**
39
+ * The challenge a test runs against. By default the challenge as imported, in
40
+ * this process: fast, and the rules are the source. When the environment names
41
+ * a built bundle (`KRADLE_CHALLENGE_BUNDLE=<path to kradle-runtime/challenge.js>`,
42
+ * which `kradle challenge test` sets), the bundle is loaded inside the arena's
43
+ * SES sandbox instead: no clock, no random, no timers, and every call gets a
44
+ * fresh compartment. The bundle must be the same challenge as the import.
45
+ * Async because `ses` loads as an ES module: `const c = await sandboxed(source)`.
46
+ */
47
+ async function sandboxed(challenge) {
48
+ const bundle = process.env.KRADLE_CHALLENGE_BUNDLE;
49
+ if (!bundle)
50
+ return challenge;
51
+ // Lazy: `ses` and the lockdown only enter a process that asked for them.
52
+ const { loadBundleFile } = require("./sandbox.js");
53
+ const loaded = await loadBundleFile(bundle);
54
+ const want = challenge.manifest?.name;
55
+ const got = loaded.manifest?.name;
56
+ if (want !== got) {
57
+ throw new Error(`KRADLE_CHALLENGE_BUNDLE holds the challenge "${got}", the test imports "${want}"`);
58
+ }
59
+ return loaded;
60
+ }
61
+ class Game {
62
+ challenge;
63
+ state;
64
+ log = [];
65
+ actions = [];
66
+ last = [];
67
+ /** The harness's tick step, a test setting: server ticks arrive in steps of 4 here (the arena sends every 2 ticks by default). */
68
+ step = 4;
69
+ attempts = 0;
70
+ /** The state this game started from: `init()`, or the checkpoint of `resume`. `replay` starts here. */
71
+ origin;
72
+ /** Inventory slots the fake players used, per player and item, for this game only. */
73
+ slots = new Map();
74
+ constructor(challenge, state) {
75
+ this.challenge = challenge;
76
+ requireBundleUnderTheCommand(challenge);
77
+ this.state = (state ?? challenge.init());
78
+ this.origin = JSON.stringify(this.state);
79
+ }
80
+ dispatch(event) {
81
+ const before = JSON.stringify(this.state);
82
+ const a = this.challenge.reduce(this.state, event);
83
+ assertEqual(JSON.stringify(this.state), before, "reduce() mutated its input state");
84
+ this.state = JSON.parse(JSON.stringify(a.state)); // a checkpoint is a JSON string
85
+ this.log.push(event);
86
+ this.last = a.actions;
87
+ this.actions.push(...a.actions);
88
+ return a.actions;
89
+ }
90
+ /** Ticks in steps of `step`, and lands exactly on `serverTick` (the last step is shorter when needed). */
91
+ tickTo(serverTick) {
92
+ for (let t = this.state.tick + this.step; t <= serverTick; t += this.step)
93
+ this.dispatch({ type: "tick", serverTick: t });
94
+ if (this.state.tick < serverTick)
95
+ this.dispatch({ type: "tick", serverTick });
96
+ }
97
+ tick(n = 1) {
98
+ this.tickTo(this.state.tick + n * this.step);
99
+ }
100
+ /** Advance by a duration: "35s", "2m", or ticks. */
101
+ after(d) {
102
+ this.tickTo(this.state.tick + (0, sdk_js_1.toTicks)(d));
103
+ }
104
+ /** Advance until `d` after game start. */
105
+ at(d) {
106
+ this.tickTo(this.state.startTick + (0, sdk_js_1.toTicks)(d));
107
+ }
108
+ /**
109
+ * run_started, every join, the first tick, and the setup confirmation when the
110
+ * challenge has a setup. A roster entry is a role (`{ alice: "climber" }`), or the
111
+ * role with the player's position and sample fields (`{ alice: { role: "climber",
112
+ * at: { x: 0, y: -60, z: 0 } } }`): the first tick then carries that sample, so
113
+ * `start` and the setup see the position, as they do in the arena. Without `at`
114
+ * the position stays null until the first `moveTo`.
115
+ */
116
+ begin(seed, participants, opts = {}) {
117
+ const entries = Object.entries(participants).map(([name, entry]) => [name, typeof entry === "string" ? { role: entry } : entry]);
118
+ this.dispatch({
119
+ type: "run_started",
120
+ seed,
121
+ participants: entries.map(([name, e]) => ({ name, role: e.role })),
122
+ params: opts.params ?? {},
123
+ capabilities: opts.capabilities ?? sdk_js_1.ALL_CAPABILITIES,
124
+ locations: opts.locations,
125
+ markers: opts.markers,
126
+ });
127
+ for (const [name] of entries)
128
+ this.dispatch({ type: "player_joined", name });
129
+ // Every entry that carries a sample field (a position, a game mode, health...) goes into the first tick.
130
+ const samples = entries
131
+ .filter(([, e]) => Object.keys(e).length > 1)
132
+ .map(([name, { role: _role, at, ...rest }]) => ({ name, participant: true, pos: at, ...rest }));
133
+ if (samples.length > 0)
134
+ this.dispatch({ type: "tick", serverTick: this.state.tick + this.step, players: samples });
135
+ else
136
+ this.tick();
137
+ if (this.of("batch").some((b) => b.id === "setup")) {
138
+ const ok = opts.setupOk ?? true;
139
+ this.dispatch({
140
+ type: "effect_result",
141
+ id: "setup",
142
+ ok,
143
+ detail: ok ? undefined : "fill #3 failed: unknown block",
144
+ });
145
+ }
146
+ return this;
147
+ }
148
+ player(name) {
149
+ return new Fake(this, name);
150
+ }
151
+ custom(name, data, player) {
152
+ return this.dispatch({ type: "custom", name, player, data });
153
+ }
154
+ /** Loads the chunks that cover `box` into the mirror: `block` inside the box, air around it. */
155
+ terrain(box, block, minY = -64, height = 384) {
156
+ const { lo, hi } = (0, sdk_js_1.bounds)(box);
157
+ const out = [];
158
+ for (let cx = lo.x >> 4; cx <= hi.x >> 4; cx++) {
159
+ for (let cz = lo.z >> 4; cz <= hi.z >> 4; cz++) {
160
+ const sections = [];
161
+ for (let base = minY; base < minY + height; base += 16) {
162
+ if (base + 15 < lo.y || base > hi.y)
163
+ continue;
164
+ const whole = lo.x <= cx << 4 &&
165
+ hi.x >= (cx << 4) + 15 &&
166
+ lo.z <= cz << 4 &&
167
+ hi.z >= (cz << 4) + 15 &&
168
+ lo.y <= base &&
169
+ hi.y >= base + 15;
170
+ if (whole) {
171
+ sections.push({ y: base, block });
172
+ continue;
173
+ }
174
+ const data = new Array(4096).fill(0);
175
+ for (let y = 0; y < 16; y++)
176
+ for (let z = 0; z < 16; z++)
177
+ for (let x = 0; x < 16; x++) {
178
+ const wx = (cx << 4) + x;
179
+ const wy = base + y;
180
+ const wz = (cz << 4) + z;
181
+ if (wx >= lo.x && wx <= hi.x && wy >= lo.y && wy <= hi.y && wz >= lo.z && wz <= hi.z) {
182
+ data[(y << 8) | (z << 4) | x] = 1;
183
+ }
184
+ }
185
+ sections.push({ y: base, palette: ["minecraft:air", block], data });
186
+ }
187
+ out.push(...this.dispatch({ type: "chunk", x: cx, z: cz, minY, sections }));
188
+ }
189
+ }
190
+ return out;
191
+ }
192
+ /** Blocks changed on the server, by anyone or anything. */
193
+ setBlocks(changes) {
194
+ return this.dispatch({ type: "blocks_changed", changes });
195
+ }
196
+ spawnEntity(id, type, at, extra = {}) {
197
+ return this.dispatch({ type: "entity_spawned", id, entity: type, at, ...extra });
198
+ }
199
+ /** Entities moved: they arrive with the next tick, so this advances one engine step. */
200
+ moveEntities(moves) {
201
+ return this.dispatch({ type: "tick", serverTick: this.state.tick + this.step, entities: moves });
202
+ }
203
+ /**
204
+ * One engine tick with several samples at once: participants' positions and
205
+ * fields, and entity moves, all in the same tick, as the engine sends them.
206
+ * A handler that reads another player's position sees this tick for everyone.
207
+ */
208
+ sample(players, entities) {
209
+ return this.dispatch({
210
+ type: "tick",
211
+ serverTick: this.state.tick + this.step,
212
+ players: players.map((p) => ({ participant: true, ...p })),
213
+ entities,
214
+ });
215
+ }
216
+ removeEntity(id, cause = "removed", killer) {
217
+ return this.dispatch({ type: "entity_removed", id, cause, killer });
218
+ }
219
+ /**
220
+ * The contents of a declared container, as the engine reports them: `items` is the whole
221
+ * content (item to count), laid out one item per slot. `by` names the player who had it open;
222
+ * `initial` marks the first snapshot (no handler fires for it).
223
+ */
224
+ container(at, items, opts = {}) {
225
+ const key = `${Math.floor(at.x)},${Math.floor(at.y)},${Math.floor(at.z)}`;
226
+ const known = Object.keys(this.state.containers?.[key]?.slots ?? {});
227
+ const slots = [];
228
+ let slot = 0;
229
+ for (const [item, count] of Object.entries(items)) {
230
+ if (count > 0)
231
+ slots.push({ slot, item: item, count });
232
+ else
233
+ slots.push({ slot });
234
+ slot++;
235
+ }
236
+ for (const k of known)
237
+ if (Number(k) >= slot)
238
+ slots.push({ slot: Number(k) });
239
+ return this.dispatch({
240
+ type: "container",
241
+ at: { ...at },
242
+ block: opts.block ?? "minecraft:chest",
243
+ slots,
244
+ by: opts.by,
245
+ initial: opts.initial,
246
+ });
247
+ }
248
+ /** A game mode change reported by the engine (the `gamemode` event). */
249
+ setGamemode(name, gamemode) {
250
+ return this.dispatch({ type: "gamemode", name, gamemode });
251
+ }
252
+ /** A non-participant player's sample (the watcher, a spectator), with the next tick. */
253
+ other(name, sample) {
254
+ return this.dispatch({
255
+ type: "tick",
256
+ serverTick: this.state.tick + this.step,
257
+ players: [{ name, participant: false, ...sample }],
258
+ });
259
+ }
260
+ /**
261
+ * The engine's answer to a walk: the last one requested, or the last one for
262
+ * `player` (or with `id`) when several are in flight. A walk that was already
263
+ * answered is skipped.
264
+ */
265
+ walkResult(ok, detail, which = {}) {
266
+ const answered = new Set();
267
+ for (const e of this.log)
268
+ if (e.type === "effect_result")
269
+ answered.add(e.id);
270
+ const walk = [...this.actions]
271
+ .reverse()
272
+ .find((a) => a.type === "walk" &&
273
+ !answered.has(a.id) &&
274
+ (which.id === undefined || a.id === which.id) &&
275
+ (which.player === undefined || a.player === which.player));
276
+ if (!walk)
277
+ throw new Error(`no pending walk${which.player ? ` for ${which.player}` : ""}${which.id ? ` with id ${which.id}` : ""}`);
278
+ this.dispatch({ type: "effect_result", id: walk.id, ok, detail });
279
+ }
280
+ /** Actions of the last reduction, by type. */
281
+ of(type) {
282
+ return this.last.filter((a) => a.type === type);
283
+ }
284
+ /** Actions of the whole run, by type. */
285
+ all(type) {
286
+ return this.actions.filter((a) => a.type === type);
287
+ }
288
+ /** Effects of the last reduction, including the ones inside a batch. */
289
+ effects(kind) {
290
+ return effectsOf(this.last, kind);
291
+ }
292
+ /** Effects of the whole run, by kind. */
293
+ effectsAll(kind) {
294
+ return effectsOf(this.actions, kind);
295
+ }
296
+ /** Announcements of the last reduction. `to` omitted = the public ones. */
297
+ announcements(to) {
298
+ return this.effects("announce")
299
+ .filter((e) => e.to === to)
300
+ .map((e) => e.message);
301
+ }
302
+ /** Every announcement of the run, public and private. */
303
+ said() {
304
+ return this.effectsAll("announce").map((e) => e.message);
305
+ }
306
+ /**
307
+ * The same log through the same reducer instance, from the state this game
308
+ * started with (`init()`, or the checkpoint of `resume`), gives the same final
309
+ * state and the same actions (determinism). It does not prove the absence of
310
+ * hidden module state: that needs a fresh module, which the arena's worker
311
+ * provides. A test calls it; `dispatch` does not.
312
+ */
313
+ replay() {
314
+ let s = JSON.parse(this.origin);
315
+ const actions = [];
316
+ for (const e of this.log) {
317
+ const r = this.challenge.reduce(s, e);
318
+ s = r.state;
319
+ actions.push(...r.actions);
320
+ }
321
+ assertEqual((0, exports.canonical)(s), (0, exports.canonical)(this.state), "replay: final state differs");
322
+ assertEqual((0, exports.canonical)(actions), (0, exports.canonical)(this.actions), "replay: actions differ");
323
+ }
324
+ checkpoint() {
325
+ return JSON.stringify(this.state);
326
+ }
327
+ static resume(challenge, json) {
328
+ return new Game(challenge, JSON.parse(json));
329
+ }
330
+ nextAttempt() {
331
+ return `attempt:${++this.attempts}`;
332
+ }
333
+ /** The slot a fake player's item occupies: the one the state shows, else the next free one, for this game only. */
334
+ slotFor(name, item) {
335
+ const slots = (this.state.players[name]?.slots ?? {});
336
+ const held = Object.entries(slots).find(([, s]) => s?.item === item);
337
+ if (held)
338
+ return Number(held[0]);
339
+ const mine = this.slots.get(name) ?? new Map();
340
+ this.slots.set(name, mine);
341
+ const known = mine.get(item);
342
+ if (known !== undefined)
343
+ return known;
344
+ const used = new Set([...mine.values(), ...Object.keys(slots).map(Number)]);
345
+ let slot = 0;
346
+ while (used.has(slot))
347
+ slot++;
348
+ mine.set(item, slot);
349
+ return slot;
350
+ }
351
+ }
352
+ exports.Game = Game;
353
+ function effectsOf(actions, kind) {
354
+ return actions
355
+ .flatMap((a) => (a.type === "effect" ? [a.effect] : a.type === "batch" ? a.effects : []))
356
+ .filter((e) => e.kind === kind);
357
+ }
358
+ /** A scripted player. Every method dispatches one engine event; the SDK derives the zone edges from moves. */
359
+ class Fake {
360
+ g;
361
+ name;
362
+ constructor(g, name) {
363
+ this.g = g;
364
+ this.name = name;
365
+ }
366
+ moveTo(to, extrema) {
367
+ const prev = this.g.state.players[this.name]?.pos;
368
+ const pos = { x: prev?.x ?? 0, z: prev?.z ?? 0, ...to };
369
+ return this.g.dispatch({
370
+ type: "player_moved",
371
+ name: this.name,
372
+ to: pos,
373
+ maxY: extrema?.maxY ?? pos.y,
374
+ minY: extrema?.minY ?? pos.y,
375
+ });
376
+ }
377
+ vote(voteId, option) {
378
+ const attemptId = this.g.nextAttempt();
379
+ this.g.dispatch({ type: "vote_attempt", attemptId, name: this.name, voteId, option });
380
+ const d = this.g.of("vote_decision").find((x) => x.attemptId === attemptId);
381
+ if (!d)
382
+ throw new Error(`no vote_decision for ${attemptId}`);
383
+ return { accepted: d.accepted, feedback: d.feedback };
384
+ }
385
+ says(text) {
386
+ return this.g.dispatch({ type: "chat", from: this.name, text });
387
+ }
388
+ swings(animation = "swing") {
389
+ return this.g.dispatch({ type: "animation", name: this.name, animation });
390
+ }
391
+ hurt(amount, cause, attacker) {
392
+ return this.g.dispatch({ type: "player_damaged", name: this.name, amount, cause, attacker });
393
+ }
394
+ dies(cause = "fall", killer) {
395
+ return this.g.dispatch({ type: "player_died", name: this.name, cause, killer });
396
+ }
397
+ respawns() {
398
+ return this.g.dispatch({ type: "player_respawned", name: this.name });
399
+ }
400
+ picksUp(item, count = 1, at = { x: 0, y: 0, z: 0 }) {
401
+ return this.g.dispatch({ type: "item_picked_up", name: this.name, item, count, at });
402
+ }
403
+ /** The player's inventory now holds `count` of `item`: one slot per item name, in this game. */
404
+ has(item, count) {
405
+ const slot = this.g.slotFor(this.name, item);
406
+ return this.g.dispatch({
407
+ type: "inventory",
408
+ name: this.name,
409
+ slots: [count > 0 ? { slot, item, count } : { slot }],
410
+ });
411
+ }
412
+ /** Walks into the declared zone (its first corner); the SDK derives the edge. */
413
+ enters(zone) {
414
+ const box = this.zone(zone);
415
+ return this.moveTo({ x: box.from.x + 0.5, y: box.from.y, z: box.from.z + 0.5 });
416
+ }
417
+ /** Walks 100 blocks under the declared zone's first corner. */
418
+ leaves(zone) {
419
+ const box = this.zone(zone);
420
+ return this.moveTo({ x: box.from.x + 0.5, y: box.from.y - 100, z: box.from.z + 0.5 });
421
+ }
422
+ uses(block, at, item) {
423
+ return this.g.dispatch({ type: "block_used", name: this.name, at, block, item });
424
+ }
425
+ breaks(block, at) {
426
+ return this.g.dispatch({ type: "block_broken", name: this.name, at, block });
427
+ }
428
+ places(block, at) {
429
+ return this.g.dispatch({ type: "block_placed", name: this.name, at, block });
430
+ }
431
+ zone(zone) {
432
+ const zones = this.g.challenge.zones;
433
+ const box = zones[zone];
434
+ if (!box) {
435
+ throw new Error(`"${zone}" is not declared in zones (declared: ${Object.keys(zones).join(", ") || "none"})`);
436
+ }
437
+ return box;
438
+ }
439
+ }
440
+ exports.Fake = Fake;
441
+ //# sourceMappingURL=harness.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"harness.js","sourceRoot":"","sources":["../../src/runtime/harness.ts"],"names":[],"mappings":";;;AAuEA,8BAYC;AAnFD,iFAAiF;AACjF,kFAAkF;AAClF,8EAA8E;AAC9E,6EAA6E;AAC7E,qCAAyC;AAEzC,+DAAsD;AACtD,qCAmBkB;AAKlB,wEAAwE;AACjE,MAAM,SAAS,GAAG,CAAC,CAAU,EAAU,EAAE,CAC/C,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,CAC3B,CAAC,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,CAAW,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAC5G,CAAC;AAHU,QAAA,SAAS,aAGnB;AAEH,SAAS,WAAW,CAAC,MAAc,EAAE,QAAgB,EAAE,IAAY;IAClE,IAAI,MAAM,KAAK,QAAQ;QAAE,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,iBAAiB,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E,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IAClF,CAAC;IACD,MAAM,CAAC,KAA4B,EAAE,EAAQ;QAC5C,OAAO,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,cAAc,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;IAC9E,CAAC;IACD,MAAM,CAAC,KAA4B,EAAE,EAAQ;QAC5C,OAAO,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,cAAc,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;IAC9E,CAAC;IACO,IAAI,CAAC,IAAY;QACxB,MAAM,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC;QACrC,MAAM,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC;QACxB,IAAI,CAAC,GAAG,EAAE,CAAC;YACV,MAAM,IAAI,KAAK,CAAC,IAAI,IAAI,yCAAyC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,MAAM,GAAG,CAAC,CAAC;QAC9G,CAAC;QACD,OAAO,GAAG,CAAC;IACZ,CAAC;CACD;AA7ED,oBA6EC"}
@@ -0,0 +1,2 @@
1
+ export * from "./sdk.js";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/runtime/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC"}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./sdk.js"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/runtime/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB"}
@@ -0,0 +1,7 @@
1
+ /** Records a challenge that came out of a compartment; `origin` is the bundle file, when there is one. */
2
+ export declare function markSandboxed(challenge: object, origin: string | null): void;
3
+ /** The bundle a challenge came from, or `undefined` for an imported source. */
4
+ export declare function sandboxOrigin(challenge: object): {
5
+ origin: string | null;
6
+ } | undefined;
7
+ //# sourceMappingURL=sandbox-registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sandbox-registry.d.ts","sourceRoot":"","sources":["../../src/runtime/sandbox-registry.ts"],"names":[],"mappings":"AAIA,0GAA0G;AAC1G,wBAAgB,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAE5E;AAED,+EAA+E;AAC/E,wBAAgB,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG;IAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,GAAG,SAAS,CAEtF"}
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.markSandboxed = markSandboxed;
4
+ exports.sandboxOrigin = sandboxOrigin;
5
+ // What `loadBundle` handed out, so the harness can tell a bundle from an
6
+ // imported source. No `ses` here: the harness reads this without loading it.
7
+ const origins = new WeakMap();
8
+ /** Records a challenge that came out of a compartment; `origin` is the bundle file, when there is one. */
9
+ function markSandboxed(challenge, origin) {
10
+ origins.set(challenge, { origin });
11
+ }
12
+ /** The bundle a challenge came from, or `undefined` for an imported source. */
13
+ function sandboxOrigin(challenge) {
14
+ return origins.get(challenge);
15
+ }
16
+ //# sourceMappingURL=sandbox-registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sandbox-registry.js","sourceRoot":"","sources":["../../src/runtime/sandbox-registry.ts"],"names":[],"mappings":";;AAKA,sCAEC;AAGD,sCAEC;AAZD,yEAAyE;AACzE,6EAA6E;AAC7E,MAAM,OAAO,GAAG,IAAI,OAAO,EAAqC,CAAC;AAEjE,0GAA0G;AAC1G,SAAgB,aAAa,CAAC,SAAiB,EAAE,MAAqB;IACrE,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;AACpC,CAAC;AAED,+EAA+E;AAC/E,SAAgB,aAAa,CAAC,SAAiB;IAC9C,OAAO,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;AAC/B,CAAC"}
@@ -0,0 +1,29 @@
1
+ import type { AnyChallenge, RuntimeManifest } from "./sdk.js";
2
+ /** The arena's lockdown options (arena-minecraft, src/AgentLib/lockdown.ts). Keep them in step. */
3
+ export declare const LOCKDOWN_OPTIONS: {
4
+ readonly localeTaming: "unsafe";
5
+ readonly consoleTaming: "unsafe";
6
+ readonly errorTaming: "unsafe";
7
+ readonly stackFiltering: "verbose";
8
+ readonly evalTaming: "unsafeEval";
9
+ };
10
+ /** Locks the process down once. A second call is a no-op (SES refuses a second lockdown). */
11
+ export declare function lockdownOnce(): Promise<void>;
12
+ /** A loaded bundle: what the arena's reducer worker holds. */
13
+ export interface LoadedChallenge {
14
+ manifest: RuntimeManifest;
15
+ init(): unknown;
16
+ reduce(state: unknown, event: unknown): {
17
+ state: unknown;
18
+ actions: unknown[];
19
+ };
20
+ }
21
+ /**
22
+ * Evaluates a CommonJS-shaped bundle (the CLI's `kradle-runtime/challenge.js`)
23
+ * inside a fresh compartment and returns its default export, checked to be a
24
+ * runtime challenge. The same wrapper and checks as the arena's worker.
25
+ */
26
+ export declare function loadBundle(source: string, origin?: string | null): Promise<AnyChallenge>;
27
+ /** `loadBundle` on a file; the file is the challenge's origin for the harness. */
28
+ export declare function loadBundleFile(path: string): Promise<AnyChallenge>;
29
+ //# sourceMappingURL=sandbox.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sandbox.d.ts","sourceRoot":"","sources":["../../src/runtime/sandbox.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAE9D,mGAAmG;AACnG,eAAO,MAAM,gBAAgB;;;;;;CAMnB,CAAC;AAcX,6FAA6F;AAC7F,wBAAsB,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC,CAKlD;AAED,8DAA8D;AAC9D,MAAM,WAAW,eAAe;IAC/B,QAAQ,EAAE,eAAe,CAAC;IAC1B,IAAI,IAAI,OAAO,CAAC;IAChB,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,GAAG;QAAE,KAAK,EAAE,OAAO,CAAC;QAAC,OAAO,EAAE,OAAO,EAAE,CAAA;KAAE,CAAC;CAC/E;AAED;;;;GAIG;AACH,wBAAsB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,GAAE,MAAM,GAAG,IAAW,GAAG,OAAO,CAAC,YAAY,CAAC,CAiBpG;AAED,kFAAkF;AAClF,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,CAElE"}
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LOCKDOWN_OPTIONS = void 0;
4
+ exports.lockdownOnce = lockdownOnce;
5
+ exports.loadBundle = loadBundle;
6
+ exports.loadBundleFile = loadBundleFile;
7
+ // The arena's sandbox, for tests: SES lockdown with the arena's options, and a
8
+ // challenge bundle evaluated inside a fresh Compartment with no endowments. What
9
+ // the bundle sees is what it sees in the arena: the tamed intrinsics (Date.now()
10
+ // and a bare Date throw, Math.random() throws), no timers, no process, no
11
+ // network, and the arguments of each reduce call. Nothing else.
12
+ //
13
+ // Only the bundle is sandboxed. The test process itself keeps a working clock
14
+ // after lockdown (SES tames the start compartment's Date and Math only for the
15
+ // other compartments), so a challenge imported as a module is not sandboxed by
16
+ // this file: it has to be the built bundle (`kradle challenge test` builds it).
17
+ //
18
+ // `ses` enters through a dynamic import: Bun runs a required `ses` in sloppy
19
+ // mode and it refuses to initialize (SES_NO_SLOPPY); the ES module loads
20
+ // everywhere. So the loaders are async, and a test awaits `sandboxed()`.
21
+ const node_fs_1 = require("node:fs");
22
+ const sandbox_registry_js_1 = require("./sandbox-registry.js");
23
+ /** The arena's lockdown options (arena-minecraft, src/AgentLib/lockdown.ts). Keep them in step. */
24
+ exports.LOCKDOWN_OPTIONS = {
25
+ localeTaming: "unsafe",
26
+ consoleTaming: "unsafe",
27
+ errorTaming: "unsafe",
28
+ stackFiltering: "verbose",
29
+ evalTaming: "unsafeEval",
30
+ };
31
+ let ses;
32
+ /** Loads `ses` once: `lockdown` and `Compartment` become globals. */
33
+ function loadSes() {
34
+ if (typeof globalThis.lockdown === "function")
35
+ return Promise.resolve();
36
+ ses ??= import("ses").then(() => undefined);
37
+ return ses;
38
+ }
39
+ /** Locks the process down once. A second call is a no-op (SES refuses a second lockdown). */
40
+ async function lockdownOnce() {
41
+ await loadSes();
42
+ if (typeof globalThis.harden === "function")
43
+ return;
44
+ // `reporting`: the list of removed intrinsics is noise in a test report (the arena logs it).
45
+ lockdown({ ...exports.LOCKDOWN_OPTIONS, reporting: "none" });
46
+ }
47
+ /**
48
+ * Evaluates a CommonJS-shaped bundle (the CLI's `kradle-runtime/challenge.js`)
49
+ * inside a fresh compartment and returns its default export, checked to be a
50
+ * runtime challenge. The same wrapper and checks as the arena's worker.
51
+ */
52
+ async function loadBundle(source, origin = null) {
53
+ await lockdownOnce();
54
+ const compartment = new Compartment({});
55
+ const wrapped = `(function () { var module = { exports: {} }; var exports = module.exports;\n${source}\nreturn module.exports; })()`;
56
+ const exported = compartment.evaluate(wrapped);
57
+ const challenge = (exported.default ?? exported);
58
+ if (typeof challenge?.reduce !== "function" ||
59
+ typeof challenge?.init !== "function" ||
60
+ challenge?.manifest?.runtime !== 1) {
61
+ throw new Error("the bundle does not export a runtime challenge (expected default = defineChallenge(config, spec))");
62
+ }
63
+ (0, sandbox_registry_js_1.markSandboxed)(challenge, origin);
64
+ return challenge;
65
+ }
66
+ /** `loadBundle` on a file; the file is the challenge's origin for the harness. */
67
+ function loadBundleFile(path) {
68
+ return loadBundle((0, node_fs_1.readFileSync)(path, "utf8"), path);
69
+ }
70
+ //# sourceMappingURL=sandbox.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sandbox.js","sourceRoot":"","sources":["../../src/runtime/sandbox.ts"],"names":[],"mappings":";;;AAyCA,oCAKC;AAcD,gCAiBC;AAGD,wCAEC;AAlFD,+EAA+E;AAC/E,iFAAiF;AACjF,iFAAiF;AACjF,0EAA0E;AAC1E,gEAAgE;AAChE,EAAE;AACF,8EAA8E;AAC9E,+EAA+E;AAC/E,+EAA+E;AAC/E,gFAAgF;AAChF,EAAE;AACF,6EAA6E;AAC7E,yEAAyE;AACzE,yEAAyE;AACzE,qCAAuC;AAEvC,+DAAsD;AAGtD,mGAAmG;AACtF,QAAA,gBAAgB,GAAG;IAC/B,YAAY,EAAE,QAAQ;IACtB,aAAa,EAAE,QAAQ;IACvB,WAAW,EAAE,QAAQ;IACrB,cAAc,EAAE,SAAS;IACzB,UAAU,EAAE,YAAY;CACf,CAAC;AAKX,IAAI,GAA8B,CAAC;AAEnC,qEAAqE;AACrE,SAAS,OAAO;IACf,IAAI,OAAQ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