@plasius/learning-runtime 0.0.0-stage → 0.1.2
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/LICENSE +203 -0
- package/README.md +169 -2
- package/dist/chunk-2YWUDCGJ.js +189 -0
- package/dist/chunk-2YWUDCGJ.js.map +1 -0
- package/dist/chunk-XDTWUCFP.js +213 -0
- package/dist/chunk-XDTWUCFP.js.map +1 -0
- package/dist/cpp.cjs +563 -0
- package/dist/cpp.cjs.map +1 -0
- package/dist/cpp.d.cts +33 -0
- package/dist/cpp.d.ts +33 -0
- package/dist/cpp.js +535 -0
- package/dist/cpp.js.map +1 -0
- package/dist/index.cjs +244 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/javascript.cjs +226 -0
- package/dist/javascript.cjs.map +1 -0
- package/dist/javascript.d.cts +45 -0
- package/dist/javascript.d.ts +45 -0
- package/dist/javascript.js +13 -0
- package/dist/javascript.js.map +1 -0
- package/dist/javascript.worker.cjs +252 -0
- package/dist/javascript.worker.cjs.map +1 -0
- package/dist/javascript.worker.d.cts +2 -0
- package/dist/javascript.worker.d.ts +2 -0
- package/dist/javascript.worker.js +50 -0
- package/dist/javascript.worker.js.map +1 -0
- package/dist/maze.cjs +242 -0
- package/dist/maze.cjs.map +1 -0
- package/dist/maze.d.cts +85 -0
- package/dist/maze.d.ts +85 -0
- package/dist/maze.js +17 -0
- package/dist/maze.js.map +1 -0
- package/dist/server.cjs +232 -0
- package/dist/server.cjs.map +1 -0
- package/dist/server.d.cts +25 -0
- package/dist/server.d.ts +25 -0
- package/dist/server.js +149 -0
- package/dist/server.js.map +1 -0
- package/dist/web.cjs +600 -0
- package/dist/web.cjs.map +1 -0
- package/dist/web.d.cts +80 -0
- package/dist/web.d.ts +80 -0
- package/dist/web.js +513 -0
- package/dist/web.js.map +1 -0
- package/package.json +115 -4
package/dist/maze.cjs
ADDED
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key2 of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key2) && key2 !== except)
|
|
14
|
+
__defProp(to, key2, { get: () => from[key2], enumerable: !(desc = __getOwnPropDesc(from, key2)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/maze.ts
|
|
21
|
+
var maze_exports = {};
|
|
22
|
+
__export(maze_exports, {
|
|
23
|
+
LearningRuntimeInputError: () => LearningRuntimeInputError,
|
|
24
|
+
MAZE_LIMITS: () => MAZE_LIMITS,
|
|
25
|
+
parseMazeProject: () => parseMazeProject,
|
|
26
|
+
parseMazeScene: () => parseMazeScene,
|
|
27
|
+
projectMazeLanguages: () => projectMazeLanguages,
|
|
28
|
+
runMazeProject: () => runMazeProject
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(maze_exports);
|
|
31
|
+
var MAZE_LIMITS = Object.freeze({
|
|
32
|
+
sourceCharacters: 16e3,
|
|
33
|
+
instructions: 256,
|
|
34
|
+
nesting: 12,
|
|
35
|
+
routines: 16,
|
|
36
|
+
sequenceLength: 64,
|
|
37
|
+
repeat: 20,
|
|
38
|
+
steps: 512,
|
|
39
|
+
callDepth: 16,
|
|
40
|
+
dimension: 20,
|
|
41
|
+
explorers: 64
|
|
42
|
+
});
|
|
43
|
+
var LearningRuntimeInputError = class extends Error {
|
|
44
|
+
constructor() {
|
|
45
|
+
super("The learning project or scenario is invalid.");
|
|
46
|
+
this.name = "LearningRuntimeInputError";
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var invalid = () => {
|
|
50
|
+
throw new LearningRuntimeInputError();
|
|
51
|
+
};
|
|
52
|
+
var record = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
53
|
+
var exact = (value, keys) => Object.keys(value).length === keys.length && keys.every((key2) => Object.hasOwn(value, key2));
|
|
54
|
+
var integer = (value, min, max) => typeof value === "number" && Number.isInteger(value) && value >= min && value <= max;
|
|
55
|
+
var routineName = (value) => typeof value === "string" && /^[a-z][a-z0-9-]{0,31}$/u.test(value);
|
|
56
|
+
var DIRECTIONS = ["north", "east", "south", "west"];
|
|
57
|
+
var DELTAS = [{ x: 0, y: -1 }, { x: 1, y: 0 }, { x: 0, y: 1 }, { x: -1, y: 0 }];
|
|
58
|
+
var key = (point) => `${point.x},${point.y}`;
|
|
59
|
+
function parseMazeProject(source) {
|
|
60
|
+
if (typeof source !== "string" || source.length > MAZE_LIMITS.sourceCharacters) return invalid();
|
|
61
|
+
let value;
|
|
62
|
+
try {
|
|
63
|
+
value = JSON.parse(source);
|
|
64
|
+
} catch {
|
|
65
|
+
return invalid();
|
|
66
|
+
}
|
|
67
|
+
if (!record(value) || !exact(value, ["program", "routines"]) || !record(value.routines)) return invalid();
|
|
68
|
+
const routines = value.routines;
|
|
69
|
+
const names = Object.keys(routines);
|
|
70
|
+
if (names.length > MAZE_LIMITS.routines || names.some((name) => !routineName(name))) return invalid();
|
|
71
|
+
let nodes = 0;
|
|
72
|
+
function sequence(value2, depth) {
|
|
73
|
+
if (!Array.isArray(value2) || value2.length > MAZE_LIMITS.sequenceLength || depth > MAZE_LIMITS.nesting) return invalid();
|
|
74
|
+
return value2.map((node) => {
|
|
75
|
+
if (++nodes > MAZE_LIMITS.instructions || !record(node)) return invalid();
|
|
76
|
+
switch (node.do) {
|
|
77
|
+
case "forward":
|
|
78
|
+
case "left":
|
|
79
|
+
case "right":
|
|
80
|
+
case "collect":
|
|
81
|
+
if (!exact(node, ["do"])) return invalid();
|
|
82
|
+
return { do: node.do };
|
|
83
|
+
case "repeat":
|
|
84
|
+
if (!exact(node, ["do", "times", "body"]) || !integer(node.times, 1, MAZE_LIMITS.repeat)) return invalid();
|
|
85
|
+
return { do: "repeat", times: node.times, body: sequence(node.body, depth + 1) };
|
|
86
|
+
case "if-clear":
|
|
87
|
+
if (!exact(node, ["do", "then", "else"])) return invalid();
|
|
88
|
+
return { do: "if-clear", then: sequence(node.then, depth + 1), else: sequence(node.else, depth + 1) };
|
|
89
|
+
case "call":
|
|
90
|
+
if (!exact(node, ["do", "name"]) || !routineName(node.name) || !names.includes(node.name)) return invalid();
|
|
91
|
+
return { do: "call", name: node.name };
|
|
92
|
+
default:
|
|
93
|
+
return invalid();
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
return { program: sequence(value.program, 0), routines: Object.fromEntries(names.map((name) => [name, sequence(routines[name], 0)])) };
|
|
98
|
+
}
|
|
99
|
+
function parseMazeScene(value) {
|
|
100
|
+
if (!record(value) || !exact(value, ["columns", "rows", "start", "goal", "walls", "explorers"]) || !integer(value.columns, 3, MAZE_LIMITS.dimension) || !integer(value.rows, 3, MAZE_LIMITS.dimension)) return invalid();
|
|
101
|
+
const columns = value.columns;
|
|
102
|
+
const rows = value.rows;
|
|
103
|
+
function point(input, start2 = false) {
|
|
104
|
+
if (!record(input) || !exact(input, start2 ? ["x", "y", "direction"] : ["x", "y"]) || !integer(input.x, 0, columns - 1) || !integer(input.y, 0, rows - 1)) return invalid();
|
|
105
|
+
return { x: input.x, y: input.y };
|
|
106
|
+
}
|
|
107
|
+
const start = point(value.start, true);
|
|
108
|
+
if (!record(value.start) || !DIRECTIONS.includes(value.start.direction)) return invalid();
|
|
109
|
+
const goal = point(value.goal);
|
|
110
|
+
function points(input, max) {
|
|
111
|
+
if (!Array.isArray(input) || input.length > max) return invalid();
|
|
112
|
+
const result = input.map((item) => point(item));
|
|
113
|
+
if (new Set(result.map(key)).size !== result.length) return invalid();
|
|
114
|
+
return result;
|
|
115
|
+
}
|
|
116
|
+
const walls = points(value.walls, columns * rows);
|
|
117
|
+
const explorers = points(value.explorers, MAZE_LIMITS.explorers);
|
|
118
|
+
const blocked = new Set(walls.map(key));
|
|
119
|
+
if ([start, goal, ...explorers].some((position) => blocked.has(key(position)))) return invalid();
|
|
120
|
+
return { columns, rows, start: { ...start, direction: value.start.direction }, goal, walls, explorers };
|
|
121
|
+
}
|
|
122
|
+
function runMazeProject(source, world, options = {}) {
|
|
123
|
+
options.signal?.throwIfAborted();
|
|
124
|
+
const maximumSteps = options.maximumSteps ?? MAZE_LIMITS.steps;
|
|
125
|
+
if (!integer(maximumSteps, 1, MAZE_LIMITS.steps)) return invalid();
|
|
126
|
+
const project = parseMazeProject(source);
|
|
127
|
+
const scene = parseMazeScene(world);
|
|
128
|
+
let position = { x: scene.start.x, y: scene.start.y };
|
|
129
|
+
let direction = DIRECTIONS.indexOf(scene.start.direction);
|
|
130
|
+
let steps = 0;
|
|
131
|
+
let outcome = "program-ended";
|
|
132
|
+
const walls = new Set(scene.walls.map(key));
|
|
133
|
+
const remaining = new Set(scene.explorers.map(key));
|
|
134
|
+
const trace = [];
|
|
135
|
+
const blocked = (point) => point.x < 0 || point.x >= scene.columns || point.y < 0 || point.y >= scene.rows || walls.has(key(point));
|
|
136
|
+
const ahead = () => ({ x: position.x + DELTAS[direction].x, y: position.y + DELTAS[direction].y });
|
|
137
|
+
const snapshot = (kind, clear) => {
|
|
138
|
+
trace.push({
|
|
139
|
+
step: steps,
|
|
140
|
+
kind,
|
|
141
|
+
position: { ...position },
|
|
142
|
+
direction: DIRECTIONS[direction],
|
|
143
|
+
rescued: scene.explorers.length - remaining.size,
|
|
144
|
+
remaining: remaining.size,
|
|
145
|
+
...clear === void 0 ? {} : { clear }
|
|
146
|
+
});
|
|
147
|
+
};
|
|
148
|
+
const victory = () => {
|
|
149
|
+
if (key(position) === key(scene.goal) && remaining.size === 0) outcome = "rescued";
|
|
150
|
+
};
|
|
151
|
+
snapshot("start");
|
|
152
|
+
victory();
|
|
153
|
+
function execute(sequence, callDepth) {
|
|
154
|
+
for (const node of sequence) {
|
|
155
|
+
options.signal?.throwIfAborted();
|
|
156
|
+
if (outcome !== "program-ended") return;
|
|
157
|
+
if (steps >= maximumSteps) {
|
|
158
|
+
outcome = "step-limit";
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
steps++;
|
|
162
|
+
if (node.do === "repeat") {
|
|
163
|
+
snapshot("repeat");
|
|
164
|
+
for (let i = 0; i < node.times && outcome === "program-ended"; i++) execute(node.body, callDepth);
|
|
165
|
+
} else if (node.do === "if-clear") {
|
|
166
|
+
const clear = !blocked(ahead());
|
|
167
|
+
snapshot("if-clear", clear);
|
|
168
|
+
execute(clear ? node.then : node.else, callDepth);
|
|
169
|
+
} else if (node.do === "call") {
|
|
170
|
+
snapshot("call");
|
|
171
|
+
if (callDepth >= MAZE_LIMITS.callDepth) {
|
|
172
|
+
outcome = "call-depth";
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
execute(project.routines[node.name], callDepth + 1);
|
|
176
|
+
} else {
|
|
177
|
+
if (node.do === "left") direction = (direction + 3) % 4;
|
|
178
|
+
else if (node.do === "right") direction = (direction + 1) % 4;
|
|
179
|
+
else if (node.do === "collect") remaining.delete(key(position));
|
|
180
|
+
else {
|
|
181
|
+
const next = ahead();
|
|
182
|
+
if (blocked(next)) outcome = "blocked";
|
|
183
|
+
else position = next;
|
|
184
|
+
}
|
|
185
|
+
snapshot(node.do);
|
|
186
|
+
if (outcome !== "blocked") victory();
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
execute(project.program, 0);
|
|
191
|
+
return {
|
|
192
|
+
outcome,
|
|
193
|
+
position: { ...position },
|
|
194
|
+
direction: DIRECTIONS[direction],
|
|
195
|
+
rescued: scene.explorers.length - remaining.size,
|
|
196
|
+
remaining: remaining.size,
|
|
197
|
+
steps,
|
|
198
|
+
trace
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
function projectMazeLanguages(source) {
|
|
202
|
+
const project = parseMazeProject(source);
|
|
203
|
+
const name = (value) => `route_${value.replace(/-/gu, "_")}`;
|
|
204
|
+
function render(language) {
|
|
205
|
+
const python = language === "python";
|
|
206
|
+
const pad = (depth) => " ".repeat(depth * (python ? 4 : 2));
|
|
207
|
+
const commands = {
|
|
208
|
+
forward: python ? "move_forward()" : "moveForward();",
|
|
209
|
+
left: python ? "turn_left()" : "turnLeft();",
|
|
210
|
+
right: python ? "turn_right()" : "turnRight();",
|
|
211
|
+
collect: python ? "collect_explorer()" : "collectExplorer();"
|
|
212
|
+
};
|
|
213
|
+
function sequence(nodes, depth) {
|
|
214
|
+
if (!nodes.length && python) return [pad(depth) + "pass"];
|
|
215
|
+
return nodes.flatMap((node) => {
|
|
216
|
+
const line = (value) => pad(depth) + value;
|
|
217
|
+
if (node.do === "call") return [line(`${name(node.name)}()${python ? "" : ";"}`)];
|
|
218
|
+
if (node.do === "repeat") {
|
|
219
|
+
const counter = `count${depth}`;
|
|
220
|
+
return python ? [line(`for ${counter} in range(${node.times}):`), ...sequence(node.body, depth + 1)] : [line(`for (${language === "cpp" ? "int" : "let"} ${counter} = 0; ${counter} < ${node.times}; ${counter}++) {`), ...sequence(node.body, depth + 1), line("}")];
|
|
221
|
+
}
|
|
222
|
+
if (node.do === "if-clear") return python ? [line("if is_clear():"), ...sequence(node.then, depth + 1), line("else:"), ...sequence(node.else, depth + 1)] : [line("if (isClear()) {"), ...sequence(node.then, depth + 1), line("} else {"), ...sequence(node.else, depth + 1), line("}")];
|
|
223
|
+
return [line(commands[node.do])];
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
const definitions = Object.entries(project.routines).flatMap(([id, body]) => python ? [`def ${name(id)}():`, ...sequence(body, 1), ""] : [`${language === "cpp" ? "void" : "function"} ${name(id)}() {`, ...sequence(body, 1), "}", ""]);
|
|
227
|
+
const declarations = language === "cpp" ? Object.keys(project.routines).map((id) => `void ${name(id)}();`) : [];
|
|
228
|
+
const main = language === "cpp" ? ["void runMaze() {", ...sequence(project.program, 1), "}"] : sequence(project.program, 0);
|
|
229
|
+
return [...declarations, ...definitions, ...main].join("\n");
|
|
230
|
+
}
|
|
231
|
+
return { javascript: render("javascript"), python: render("python"), cpp: render("cpp") };
|
|
232
|
+
}
|
|
233
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
234
|
+
0 && (module.exports = {
|
|
235
|
+
LearningRuntimeInputError,
|
|
236
|
+
MAZE_LIMITS,
|
|
237
|
+
parseMazeProject,
|
|
238
|
+
parseMazeScene,
|
|
239
|
+
projectMazeLanguages,
|
|
240
|
+
runMazeProject
|
|
241
|
+
});
|
|
242
|
+
//# sourceMappingURL=maze.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/maze.ts"],"sourcesContent":["/** Closed visual instructions; source is data and is never evaluated as host code. */\nexport type MazeInstruction =\n | { do: \"forward\" | \"left\" | \"right\" | \"collect\" }\n | { do: \"repeat\"; times: number; body: MazeInstruction[] }\n | { do: \"if-clear\"; then: MazeInstruction[]; else: MazeInstruction[] }\n | { do: \"call\"; name: string };\nexport interface MazeProject { program: MazeInstruction[]; routines: Record<string, MazeInstruction[]> }\nexport interface MazePoint { x: number; y: number }\nexport type MazeDirection = \"north\" | \"east\" | \"south\" | \"west\";\nexport interface MazeScene {\n columns: number; rows: number;\n start: MazePoint & { direction: MazeDirection };\n goal: MazePoint;\n walls: MazePoint[];\n explorers: MazePoint[];\n}\nexport interface MazeFrame {\n step: number;\n kind: MazeInstruction[\"do\"] | \"start\";\n position: MazePoint;\n direction: MazeDirection;\n rescued: number;\n remaining: number;\n clear?: boolean;\n}\nexport interface MazeRunResult {\n outcome: \"rescued\" | \"program-ended\" | \"blocked\" | \"step-limit\" | \"call-depth\";\n position: MazePoint;\n direction: MazeDirection;\n rescued: number;\n remaining: number;\n steps: number;\n trace: MazeFrame[];\n}\nexport const MAZE_LIMITS = Object.freeze({ sourceCharacters: 16000, instructions: 256, nesting: 12,\n routines: 16, sequenceLength: 64, repeat: 20, steps: 512, callDepth: 16, dimension: 20, explorers: 64 });\nexport class LearningRuntimeInputError extends Error {\n constructor() { super(\"The learning project or scenario is invalid.\"); this.name = \"LearningRuntimeInputError\"; }\n}\nconst invalid = (): never => { throw new LearningRuntimeInputError(); };\nconst record = (value: unknown): value is Record<string, unknown> => typeof value === \"object\" && value !== null && !Array.isArray(value);\nconst exact = (value: Record<string, unknown>, keys: string[]) => Object.keys(value).length === keys.length && keys.every(key => Object.hasOwn(value, key));\nconst integer = (value: unknown, min: number, max: number): value is number => typeof value === \"number\" && Number.isInteger(value) && value >= min && value <= max;\nconst routineName = (value: unknown): value is string => typeof value === \"string\" && /^[a-z][a-z0-9-]{0,31}$/u.test(value);\nconst DIRECTIONS: MazeDirection[] = [\"north\", \"east\", \"south\", \"west\"];\nconst DELTAS = [{ x: 0, y: -1 }, { x: 1, y: 0 }, { x: 0, y: 1 }, { x: -1, y: 0 }];\nconst key = (point: MazePoint) => `${point.x},${point.y}`;\n\n/** Validate the entire source before executing any instruction; return detached data. */\nexport function parseMazeProject(source: string): MazeProject {\n if (typeof source !== \"string\" || source.length > MAZE_LIMITS.sourceCharacters) return invalid();\n let value: unknown;\n try { value = JSON.parse(source); } catch { return invalid(); }\n if (!record(value) || !exact(value, [\"program\", \"routines\"]) || !record(value.routines)) return invalid();\n const routines = value.routines;\n const names = Object.keys(routines);\n if (names.length > MAZE_LIMITS.routines || names.some(name => !routineName(name))) return invalid();\n let nodes = 0;\n function sequence(value: unknown, depth: number): MazeInstruction[] {\n if (!Array.isArray(value) || value.length > MAZE_LIMITS.sequenceLength || depth > MAZE_LIMITS.nesting) return invalid();\n return value.map((node: unknown): MazeInstruction => {\n if (++nodes > MAZE_LIMITS.instructions || !record(node)) return invalid();\n switch (node.do) {\n case \"forward\": case \"left\": case \"right\": case \"collect\":\n if (!exact(node, [\"do\"])) return invalid();\n return { do: node.do };\n case \"repeat\":\n if (!exact(node, [\"do\", \"times\", \"body\"]) || !integer(node.times, 1, MAZE_LIMITS.repeat)) return invalid();\n return { do: \"repeat\", times: node.times, body: sequence(node.body, depth + 1) };\n case \"if-clear\":\n if (!exact(node, [\"do\", \"then\", \"else\"])) return invalid();\n return { do: \"if-clear\", then: sequence(node.then, depth + 1), else: sequence(node.else, depth + 1) };\n case \"call\":\n if (!exact(node, [\"do\", \"name\"]) || !routineName(node.name) || !names.includes(node.name)) return invalid();\n return { do: \"call\", name: node.name };\n default: return invalid();\n }\n });\n }\n return { program: sequence(value.program, 0), routines: Object.fromEntries(names.map(name => [name, sequence(routines[name], 0)])) };\n}\n\n/** Hosts supply trusted scenarios, but malformed or shared mutable worlds still fail closed. */\nexport function parseMazeScene(value: unknown): MazeScene {\n if (!record(value) || !exact(value, [\"columns\", \"rows\", \"start\", \"goal\", \"walls\", \"explorers\"])\n || !integer(value.columns, 3, MAZE_LIMITS.dimension) || !integer(value.rows, 3, MAZE_LIMITS.dimension)) return invalid();\n const columns = value.columns;\n const rows = value.rows;\n function point(input: unknown, start = false): MazePoint {\n if (!record(input) || !exact(input, start ? [\"x\", \"y\", \"direction\"] : [\"x\", \"y\"])\n || !integer(input.x, 0, columns - 1) || !integer(input.y, 0, rows - 1)) return invalid();\n return { x: input.x, y: input.y };\n }\n const start = point(value.start, true);\n if (!record(value.start) || !DIRECTIONS.includes(value.start.direction as MazeDirection)) return invalid();\n const goal = point(value.goal);\n function points(input: unknown, max: number): MazePoint[] {\n if (!Array.isArray(input) || input.length > max) return invalid();\n const result = input.map(item => point(item));\n if (new Set(result.map(key)).size !== result.length) return invalid();\n return result;\n }\n const walls = points(value.walls, columns * rows);\n const explorers = points(value.explorers, MAZE_LIMITS.explorers);\n const blocked = new Set(walls.map(key));\n if ([start, goal, ...explorers].some(position => blocked.has(key(position)))) return invalid();\n return { columns, rows, start: { ...start, direction: value.start.direction as MazeDirection }, goal, walls, explorers };\n}\n\n/** Deterministic bounded rescue simulation. Victory is an explicit world rule. */\nexport function runMazeProject(source: string, world: unknown, options: { maximumSteps?: number; signal?: AbortSignal } = {}): MazeRunResult {\n options.signal?.throwIfAborted();\n const maximumSteps = options.maximumSteps ?? MAZE_LIMITS.steps;\n if (!integer(maximumSteps, 1, MAZE_LIMITS.steps)) return invalid();\n const project = parseMazeProject(source);\n const scene = parseMazeScene(world);\n let position = { x: scene.start.x, y: scene.start.y };\n let direction = DIRECTIONS.indexOf(scene.start.direction);\n let steps = 0;\n let outcome: MazeRunResult[\"outcome\"] = \"program-ended\";\n const walls = new Set(scene.walls.map(key));\n const remaining = new Set(scene.explorers.map(key));\n const trace: MazeFrame[] = [];\n const blocked = (point: MazePoint) => point.x < 0 || point.x >= scene.columns || point.y < 0 || point.y >= scene.rows || walls.has(key(point));\n const ahead = () => ({ x: position.x + DELTAS[direction]!.x, y: position.y + DELTAS[direction]!.y });\n const snapshot = (kind: MazeFrame[\"kind\"], clear?: boolean) => {\n trace.push({ step: steps, kind, position: { ...position }, direction: DIRECTIONS[direction]!,\n rescued: scene.explorers.length - remaining.size, remaining: remaining.size, ...(clear === undefined ? {} : { clear }) });\n };\n const victory = () => { if (key(position) === key(scene.goal) && remaining.size === 0) outcome = \"rescued\"; };\n snapshot(\"start\");\n victory();\n function execute(sequence: MazeInstruction[], callDepth: number): void {\n for (const node of sequence) {\n options.signal?.throwIfAborted();\n if (outcome !== \"program-ended\") return;\n if (steps >= maximumSteps) { outcome = \"step-limit\"; return; }\n steps++;\n if (node.do === \"repeat\") {\n snapshot(\"repeat\");\n for (let i = 0; i < node.times && outcome === \"program-ended\"; i++) execute(node.body, callDepth);\n } else if (node.do === \"if-clear\") {\n const clear = !blocked(ahead()); snapshot(\"if-clear\", clear);\n execute(clear ? node.then : node.else, callDepth);\n } else if (node.do === \"call\") {\n snapshot(\"call\");\n if (callDepth >= MAZE_LIMITS.callDepth) { outcome = \"call-depth\"; return; }\n execute(project.routines[node.name]!, callDepth + 1);\n } else {\n if (node.do === \"left\") direction = (direction + 3) % 4;\n else if (node.do === \"right\") direction = (direction + 1) % 4;\n else if (node.do === \"collect\") remaining.delete(key(position));\n else {\n const next = ahead();\n if (blocked(next)) outcome = \"blocked\";\n else position = next;\n }\n snapshot(node.do);\n if (outcome !== \"blocked\") victory();\n }\n }\n }\n execute(project.program, 0);\n return { outcome, position: { ...position }, direction: DIRECTIONS[direction]!, rescued: scene.explorers.length - remaining.size,\n remaining: remaining.size, steps, trace };\n}\n\n/** Display-only language equivalents. The validated visual project remains the source of truth. */\nexport function projectMazeLanguages(source: string): { javascript: string; python: string; cpp: string } {\n const project = parseMazeProject(source);\n const name = (value: string) => `route_${value.replace(/-/gu, \"_\")}`;\n function render(language: \"javascript\" | \"python\" | \"cpp\"): string {\n const python = language === \"python\";\n const pad = (depth: number) => \" \".repeat(depth * (python ? 4 : 2));\n const commands = { forward: python ? \"move_forward()\" : \"moveForward();\", left: python ? \"turn_left()\" : \"turnLeft();\",\n right: python ? \"turn_right()\" : \"turnRight();\", collect: python ? \"collect_explorer()\" : \"collectExplorer();\" };\n function sequence(nodes: MazeInstruction[], depth: number): string[] {\n if (!nodes.length && python) return [pad(depth) + \"pass\"];\n return nodes.flatMap(node => {\n const line = (value: string) => pad(depth) + value;\n if (node.do === \"call\") return [line(`${name(node.name)}()${python ? \"\" : \";\"}`)];\n if (node.do === \"repeat\") {\n const counter = `count${depth}`;\n return python\n ? [line(`for ${counter} in range(${node.times}):`), ...sequence(node.body, depth + 1)]\n : [line(`for (${language === \"cpp\" ? \"int\" : \"let\"} ${counter} = 0; ${counter} < ${node.times}; ${counter}++) {`), ...sequence(node.body, depth + 1), line(\"}\")];\n }\n if (node.do === \"if-clear\") return python\n ? [line(\"if is_clear():\"), ...sequence(node.then, depth + 1), line(\"else:\"), ...sequence(node.else, depth + 1)]\n : [line(\"if (isClear()) {\"), ...sequence(node.then, depth + 1), line(\"} else {\"), ...sequence(node.else, depth + 1), line(\"}\")];\n return [line(commands[node.do])];\n });\n }\n const definitions = Object.entries(project.routines).flatMap(([id, body]) => python\n ? [`def ${name(id)}():`, ...sequence(body, 1), \"\"]\n : [`${language === \"cpp\" ? \"void\" : \"function\"} ${name(id)}() {`, ...sequence(body, 1), \"}\", \"\"]);\n const declarations = language === \"cpp\" ? Object.keys(project.routines).map(id => `void ${name(id)}();`) : [];\n const main = language === \"cpp\" ? [\"void runMaze() {\", ...sequence(project.program, 1), \"}\"] : sequence(project.program, 0);\n return [...declarations, ...definitions, ...main].join(\"\\n\");\n }\n return { javascript: render(\"javascript\"), python: render(\"python\"), cpp: render(\"cpp\") };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAkCO,IAAM,cAAc,OAAO,OAAO;AAAA,EAAE,kBAAkB;AAAA,EAAO,cAAc;AAAA,EAAK,SAAS;AAAA,EAC9F,UAAU;AAAA,EAAI,gBAAgB;AAAA,EAAI,QAAQ;AAAA,EAAI,OAAO;AAAA,EAAK,WAAW;AAAA,EAAI,WAAW;AAAA,EAAI,WAAW;AAAG,CAAC;AAClG,IAAM,4BAAN,cAAwC,MAAM;AAAA,EACnD,cAAc;AAAE,UAAM,8CAA8C;AAAG,SAAK,OAAO;AAAA,EAA6B;AAClH;AACA,IAAM,UAAU,MAAa;AAAE,QAAM,IAAI,0BAA0B;AAAG;AACtE,IAAM,SAAS,CAAC,UAAqD,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AACxI,IAAM,QAAQ,CAAC,OAAgC,SAAmB,OA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,OAAO,KAAK,EAAE;AAC1F;","names":["key","value","start"]}
|
package/dist/maze.d.cts
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/** Closed visual instructions; source is data and is never evaluated as host code. */
|
|
2
|
+
type MazeInstruction = {
|
|
3
|
+
do: "forward" | "left" | "right" | "collect";
|
|
4
|
+
} | {
|
|
5
|
+
do: "repeat";
|
|
6
|
+
times: number;
|
|
7
|
+
body: MazeInstruction[];
|
|
8
|
+
} | {
|
|
9
|
+
do: "if-clear";
|
|
10
|
+
then: MazeInstruction[];
|
|
11
|
+
else: MazeInstruction[];
|
|
12
|
+
} | {
|
|
13
|
+
do: "call";
|
|
14
|
+
name: string;
|
|
15
|
+
};
|
|
16
|
+
interface MazeProject {
|
|
17
|
+
program: MazeInstruction[];
|
|
18
|
+
routines: Record<string, MazeInstruction[]>;
|
|
19
|
+
}
|
|
20
|
+
interface MazePoint {
|
|
21
|
+
x: number;
|
|
22
|
+
y: number;
|
|
23
|
+
}
|
|
24
|
+
type MazeDirection = "north" | "east" | "south" | "west";
|
|
25
|
+
interface MazeScene {
|
|
26
|
+
columns: number;
|
|
27
|
+
rows: number;
|
|
28
|
+
start: MazePoint & {
|
|
29
|
+
direction: MazeDirection;
|
|
30
|
+
};
|
|
31
|
+
goal: MazePoint;
|
|
32
|
+
walls: MazePoint[];
|
|
33
|
+
explorers: MazePoint[];
|
|
34
|
+
}
|
|
35
|
+
interface MazeFrame {
|
|
36
|
+
step: number;
|
|
37
|
+
kind: MazeInstruction["do"] | "start";
|
|
38
|
+
position: MazePoint;
|
|
39
|
+
direction: MazeDirection;
|
|
40
|
+
rescued: number;
|
|
41
|
+
remaining: number;
|
|
42
|
+
clear?: boolean;
|
|
43
|
+
}
|
|
44
|
+
interface MazeRunResult {
|
|
45
|
+
outcome: "rescued" | "program-ended" | "blocked" | "step-limit" | "call-depth";
|
|
46
|
+
position: MazePoint;
|
|
47
|
+
direction: MazeDirection;
|
|
48
|
+
rescued: number;
|
|
49
|
+
remaining: number;
|
|
50
|
+
steps: number;
|
|
51
|
+
trace: MazeFrame[];
|
|
52
|
+
}
|
|
53
|
+
declare const MAZE_LIMITS: Readonly<{
|
|
54
|
+
sourceCharacters: 16000;
|
|
55
|
+
instructions: 256;
|
|
56
|
+
nesting: 12;
|
|
57
|
+
routines: 16;
|
|
58
|
+
sequenceLength: 64;
|
|
59
|
+
repeat: 20;
|
|
60
|
+
steps: 512;
|
|
61
|
+
callDepth: 16;
|
|
62
|
+
dimension: 20;
|
|
63
|
+
explorers: 64;
|
|
64
|
+
}>;
|
|
65
|
+
declare class LearningRuntimeInputError extends Error {
|
|
66
|
+
constructor();
|
|
67
|
+
}
|
|
68
|
+
/** Validate the entire source before executing any instruction; return detached data. */
|
|
69
|
+
declare function parseMazeProject(source: string): MazeProject;
|
|
70
|
+
/** Hosts supply trusted scenarios, but malformed or shared mutable worlds still fail closed. */
|
|
71
|
+
declare function parseMazeScene(value: unknown): MazeScene;
|
|
72
|
+
/** Deterministic bounded rescue simulation. Victory is an explicit world rule. */
|
|
73
|
+
declare function runMazeProject(source: string, world: unknown, options?: {
|
|
74
|
+
maximumSteps?: number;
|
|
75
|
+
signal?: AbortSignal;
|
|
76
|
+
}): MazeRunResult;
|
|
77
|
+
/** Display-only language equivalents. The validated visual project remains the source of truth. */
|
|
78
|
+
declare function projectMazeLanguages(source: string): {
|
|
79
|
+
javascript: string;
|
|
80
|
+
python: string;
|
|
81
|
+
cpp: string;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export { LearningRuntimeInputError, MAZE_LIMITS, parseMazeProject, parseMazeScene, projectMazeLanguages, runMazeProject };
|
|
85
|
+
export type { MazeDirection, MazeFrame, MazeInstruction, MazePoint, MazeProject, MazeRunResult, MazeScene };
|
package/dist/maze.d.ts
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/** Closed visual instructions; source is data and is never evaluated as host code. */
|
|
2
|
+
type MazeInstruction = {
|
|
3
|
+
do: "forward" | "left" | "right" | "collect";
|
|
4
|
+
} | {
|
|
5
|
+
do: "repeat";
|
|
6
|
+
times: number;
|
|
7
|
+
body: MazeInstruction[];
|
|
8
|
+
} | {
|
|
9
|
+
do: "if-clear";
|
|
10
|
+
then: MazeInstruction[];
|
|
11
|
+
else: MazeInstruction[];
|
|
12
|
+
} | {
|
|
13
|
+
do: "call";
|
|
14
|
+
name: string;
|
|
15
|
+
};
|
|
16
|
+
interface MazeProject {
|
|
17
|
+
program: MazeInstruction[];
|
|
18
|
+
routines: Record<string, MazeInstruction[]>;
|
|
19
|
+
}
|
|
20
|
+
interface MazePoint {
|
|
21
|
+
x: number;
|
|
22
|
+
y: number;
|
|
23
|
+
}
|
|
24
|
+
type MazeDirection = "north" | "east" | "south" | "west";
|
|
25
|
+
interface MazeScene {
|
|
26
|
+
columns: number;
|
|
27
|
+
rows: number;
|
|
28
|
+
start: MazePoint & {
|
|
29
|
+
direction: MazeDirection;
|
|
30
|
+
};
|
|
31
|
+
goal: MazePoint;
|
|
32
|
+
walls: MazePoint[];
|
|
33
|
+
explorers: MazePoint[];
|
|
34
|
+
}
|
|
35
|
+
interface MazeFrame {
|
|
36
|
+
step: number;
|
|
37
|
+
kind: MazeInstruction["do"] | "start";
|
|
38
|
+
position: MazePoint;
|
|
39
|
+
direction: MazeDirection;
|
|
40
|
+
rescued: number;
|
|
41
|
+
remaining: number;
|
|
42
|
+
clear?: boolean;
|
|
43
|
+
}
|
|
44
|
+
interface MazeRunResult {
|
|
45
|
+
outcome: "rescued" | "program-ended" | "blocked" | "step-limit" | "call-depth";
|
|
46
|
+
position: MazePoint;
|
|
47
|
+
direction: MazeDirection;
|
|
48
|
+
rescued: number;
|
|
49
|
+
remaining: number;
|
|
50
|
+
steps: number;
|
|
51
|
+
trace: MazeFrame[];
|
|
52
|
+
}
|
|
53
|
+
declare const MAZE_LIMITS: Readonly<{
|
|
54
|
+
sourceCharacters: 16000;
|
|
55
|
+
instructions: 256;
|
|
56
|
+
nesting: 12;
|
|
57
|
+
routines: 16;
|
|
58
|
+
sequenceLength: 64;
|
|
59
|
+
repeat: 20;
|
|
60
|
+
steps: 512;
|
|
61
|
+
callDepth: 16;
|
|
62
|
+
dimension: 20;
|
|
63
|
+
explorers: 64;
|
|
64
|
+
}>;
|
|
65
|
+
declare class LearningRuntimeInputError extends Error {
|
|
66
|
+
constructor();
|
|
67
|
+
}
|
|
68
|
+
/** Validate the entire source before executing any instruction; return detached data. */
|
|
69
|
+
declare function parseMazeProject(source: string): MazeProject;
|
|
70
|
+
/** Hosts supply trusted scenarios, but malformed or shared mutable worlds still fail closed. */
|
|
71
|
+
declare function parseMazeScene(value: unknown): MazeScene;
|
|
72
|
+
/** Deterministic bounded rescue simulation. Victory is an explicit world rule. */
|
|
73
|
+
declare function runMazeProject(source: string, world: unknown, options?: {
|
|
74
|
+
maximumSteps?: number;
|
|
75
|
+
signal?: AbortSignal;
|
|
76
|
+
}): MazeRunResult;
|
|
77
|
+
/** Display-only language equivalents. The validated visual project remains the source of truth. */
|
|
78
|
+
declare function projectMazeLanguages(source: string): {
|
|
79
|
+
javascript: string;
|
|
80
|
+
python: string;
|
|
81
|
+
cpp: string;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export { LearningRuntimeInputError, MAZE_LIMITS, parseMazeProject, parseMazeScene, projectMazeLanguages, runMazeProject };
|
|
85
|
+
export type { MazeDirection, MazeFrame, MazeInstruction, MazePoint, MazeProject, MazeRunResult, MazeScene };
|
package/dist/maze.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import {
|
|
2
|
+
LearningRuntimeInputError,
|
|
3
|
+
MAZE_LIMITS,
|
|
4
|
+
parseMazeProject,
|
|
5
|
+
parseMazeScene,
|
|
6
|
+
projectMazeLanguages,
|
|
7
|
+
runMazeProject
|
|
8
|
+
} from "./chunk-XDTWUCFP.js";
|
|
9
|
+
export {
|
|
10
|
+
LearningRuntimeInputError,
|
|
11
|
+
MAZE_LIMITS,
|
|
12
|
+
parseMazeProject,
|
|
13
|
+
parseMazeScene,
|
|
14
|
+
projectMazeLanguages,
|
|
15
|
+
runMazeProject
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=maze.js.map
|
package/dist/maze.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|