@plasius/learning-runtime 0.0.0-stage → 0.1.3

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 (49) hide show
  1. package/LICENSE +203 -0
  2. package/README.md +170 -2
  3. package/dist/chunk-2YWUDCGJ.js +189 -0
  4. package/dist/chunk-2YWUDCGJ.js.map +1 -0
  5. package/dist/chunk-XDTWUCFP.js +213 -0
  6. package/dist/chunk-XDTWUCFP.js.map +1 -0
  7. package/dist/cpp.cjs +563 -0
  8. package/dist/cpp.cjs.map +1 -0
  9. package/dist/cpp.d.cts +33 -0
  10. package/dist/cpp.d.ts +33 -0
  11. package/dist/cpp.js +535 -0
  12. package/dist/cpp.js.map +1 -0
  13. package/dist/index.cjs +244 -0
  14. package/dist/index.cjs.map +1 -0
  15. package/dist/index.d.cts +1 -0
  16. package/dist/index.d.ts +1 -0
  17. package/dist/index.js +17 -0
  18. package/dist/index.js.map +1 -0
  19. package/dist/javascript.cjs +226 -0
  20. package/dist/javascript.cjs.map +1 -0
  21. package/dist/javascript.d.cts +45 -0
  22. package/dist/javascript.d.ts +45 -0
  23. package/dist/javascript.js +13 -0
  24. package/dist/javascript.js.map +1 -0
  25. package/dist/javascript.worker.cjs +252 -0
  26. package/dist/javascript.worker.cjs.map +1 -0
  27. package/dist/javascript.worker.d.cts +2 -0
  28. package/dist/javascript.worker.d.ts +2 -0
  29. package/dist/javascript.worker.js +50 -0
  30. package/dist/javascript.worker.js.map +1 -0
  31. package/dist/maze.cjs +242 -0
  32. package/dist/maze.cjs.map +1 -0
  33. package/dist/maze.d.cts +85 -0
  34. package/dist/maze.d.ts +85 -0
  35. package/dist/maze.js +17 -0
  36. package/dist/maze.js.map +1 -0
  37. package/dist/server.cjs +232 -0
  38. package/dist/server.cjs.map +1 -0
  39. package/dist/server.d.cts +25 -0
  40. package/dist/server.d.ts +25 -0
  41. package/dist/server.js +149 -0
  42. package/dist/server.js.map +1 -0
  43. package/dist/web.cjs +600 -0
  44. package/dist/web.cjs.map +1 -0
  45. package/dist/web.d.cts +80 -0
  46. package/dist/web.d.ts +80 -0
  47. package/dist/web.js +513 -0
  48. package/dist/web.js.map +1 -0
  49. package/package.json +115 -4
package/LICENSE ADDED
@@ -0,0 +1,203 @@
1
+ Copyright 2025 Plasius LTD
2
+
3
+ Apache License
4
+ Version 2.0, January 2004
5
+ http://www.apache.org/licenses/
6
+
7
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
8
+
9
+ 1. Definitions.
10
+
11
+ "License" shall mean the terms and conditions for use, reproduction,
12
+ and distribution as defined by Sections 1 through 9 of this document.
13
+
14
+ "Licensor" shall mean the copyright owner or entity authorized by
15
+ the copyright owner that is granting the License.
16
+
17
+ "Legal Entity" shall mean the union of the acting entity and all
18
+ other entities that control, are controlled by, or are under common
19
+ control with that entity. For the purposes of this definition,
20
+ "control" means (i) the power, direct or indirect, to cause the
21
+ direction or management of such entity, whether by contract or
22
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
23
+ outstanding shares, or (iii) beneficial ownership of such entity.
24
+
25
+ "You" (or "Your") shall mean an individual or Legal Entity
26
+ exercising permissions granted by this License.
27
+
28
+ "Source" form shall mean the preferred form for making modifications,
29
+ including but not limited to software source code, documentation
30
+ source, and configuration files.
31
+
32
+ "Object" form shall mean any form resulting from mechanical
33
+ transformation or translation of a Source form, including but
34
+ not limited to compiled object code, generated documentation,
35
+ and conversions to other media types.
36
+
37
+ "Work" shall mean the work of authorship, whether in Source or
38
+ Object form, made available under the License, as indicated by a
39
+ copyright notice that is included in or attached to the work
40
+ (an example is provided in the Appendix below).
41
+
42
+ "Derivative Works" shall mean any work, whether in Source or Object
43
+ form, that is based on (or derived from) the Work and for which the
44
+ editorial revisions, annotations, elaborations, or other modifications
45
+ represent, as a whole, an original work of authorship. For the purposes
46
+ of this License, Derivative Works shall not include works that remain
47
+ separable from, or merely link (or bind by name) to the interfaces of,
48
+ the Work and Derivative Works thereof.
49
+
50
+ "Contribution" shall mean any work of authorship, including
51
+ the original version of the Work and any modifications or additions
52
+ to that Work or Derivative Works thereof, that is intentionally
53
+ submitted to Licensor for inclusion in the Work by the copyright owner
54
+ or by an individual or Legal Entity authorized to submit on behalf of
55
+ the copyright owner. For the purposes of this definition, "submitted"
56
+ means any form of electronic, verbal, or written communication sent
57
+ to the Licensor or its representatives, including but not limited to
58
+ communication on electronic mailing lists, source code control systems,
59
+ and issue tracking systems that are managed by, or on behalf of, the
60
+ Licensor for the purpose of discussing and improving the Work, but
61
+ excluding communication that is conspicuously marked or otherwise
62
+ designated in writing by the copyright owner as "Not a Contribution."
63
+
64
+ "Contributor" shall mean Licensor and any individual or Legal Entity
65
+ on behalf of whom a Contribution has been received by Licensor and
66
+ subsequently incorporated within the Work.
67
+
68
+ 2. Grant of Copyright License. Subject to the terms and conditions of
69
+ this License, each Contributor hereby grants to You a perpetual,
70
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
71
+ copyright license to reproduce, prepare Derivative Works of,
72
+ publicly display, publicly perform, sublicense, and distribute the
73
+ Work and such Derivative Works in Source or Object form.
74
+
75
+ 3. Grant of Patent License. Subject to the terms and conditions of
76
+ this License, each Contributor hereby grants to You a perpetual,
77
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
78
+ (except as stated in this section) patent license to make, have made,
79
+ use, offer to sell, sell, import, and otherwise transfer the Work,
80
+ where such license applies only to those patent claims licensable
81
+ by such Contributor that are necessarily infringed by their
82
+ Contribution(s) alone or by combination of their Contribution(s)
83
+ with the Work to which such Contribution(s) was submitted. If You
84
+ institute patent litigation against any entity (including a
85
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
86
+ or a Contribution incorporated within the Work constitutes direct
87
+ or contributory patent infringement, then any patent licenses
88
+ granted to You under this License for that Work shall terminate
89
+ as of the date such litigation is filed.
90
+
91
+ 4. Redistribution. You may reproduce and distribute copies of the
92
+ Work or Derivative Works thereof in any medium, with or without
93
+ modifications, and in Source or Object form, provided that You
94
+ meet the following conditions:
95
+
96
+ (a) You must give any other recipients of the Work or
97
+ Derivative Works a copy of this License; and
98
+
99
+ (b) You must cause any modified files to carry prominent notices
100
+ stating that You changed the files; and
101
+
102
+ (c) You must retain, in the Source form of any Derivative Works
103
+ that You distribute, all copyright, patent, trademark, and
104
+ attribution notices from the Source form of the Work,
105
+ excluding those notices that do not pertain to any part of
106
+ the Derivative Works; and
107
+
108
+ (d) If the Work includes a "NOTICE" text file as part of its
109
+ distribution, then any Derivative Works that You distribute must
110
+ include a readable copy of the attribution notices contained
111
+ within such NOTICE file, excluding those notices that do not
112
+ pertain to any part of the Derivative Works, in at least one
113
+ of the following places: within a NOTICE text file distributed
114
+ as part of the Derivative Works; within the Source form or
115
+ documentation, if provided along with the Derivative Works; or,
116
+ within a display generated by the Derivative Works, if and
117
+ wherever such third-party notices normally appear. The contents
118
+ of the NOTICE file are for informational purposes only and
119
+ do not modify the License. You may add Your own attribution
120
+ notices within Derivative Works that You distribute, alongside
121
+ or as an addendum to the NOTICE text from the Work, provided
122
+ that such additional attribution notices cannot be construed
123
+ as modifying the License.
124
+
125
+ You may add Your own copyright statement to Your modifications and
126
+ may provide additional or different license terms and conditions
127
+ for use, reproduction, or distribution of Your modifications, or
128
+ for any such Derivative Works as a whole, provided Your use,
129
+ reproduction, and distribution of the Work otherwise complies with
130
+ the conditions stated in this License.
131
+
132
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
133
+ any Contribution intentionally submitted for inclusion in the Work
134
+ by You to the Licensor shall be under the terms and conditions of
135
+ this License, without any additional terms or conditions.
136
+ Notwithstanding the above, nothing herein shall supersede or modify
137
+ the terms of any separate license agreement you may have executed
138
+ with Licensor regarding such Contributions.
139
+
140
+ 6. Trademarks. This License does not grant permission to use the trade
141
+ names, trademarks, service marks, or product names of the Licensor,
142
+ except as required for reasonable and customary use in describing the
143
+ origin of the Work and reproducing the content of the NOTICE file.
144
+
145
+ 7. Disclaimer of Warranty. Unless required by applicable law or
146
+ agreed to in writing, Licensor provides the Work (and each
147
+ Contributor provides its Contributions) on an "AS IS" BASIS,
148
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
149
+ implied, including, without limitation, any warranties or conditions
150
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
151
+ PARTICULAR PURPOSE. You are solely responsible for determining the
152
+ appropriateness of using or redistributing the Work and assume any
153
+ risks associated with Your exercise of permissions under this License.
154
+
155
+ 8. Limitation of Liability. In no event and under no legal theory,
156
+ whether in tort (including negligence), contract, or otherwise,
157
+ unless required by applicable law (such as deliberate and grossly
158
+ negligent acts) or agreed to in writing, shall any Contributor be
159
+ liable to You for damages, including any direct, indirect, special,
160
+ incidental, or consequential damages of any character arising as a
161
+ result of this License or out of the use or inability to use the
162
+ Work (including but not limited to damages for loss of goodwill,
163
+ work stoppage, computer failure or malfunction, or any and all
164
+ other commercial damages or losses), even if such Contributor
165
+ has been advised of the possibility of such damages.
166
+
167
+ 9. Accepting Warranty or Additional Liability. While redistributing
168
+ the Work or Derivative Works thereof, You may choose to offer,
169
+ and charge a fee for, acceptance of support, warranty, indemnity,
170
+ or other liability obligations and/or rights consistent with this
171
+ License. However, in accepting such obligations, You may act only
172
+ on Your own behalf and on Your sole responsibility, not on behalf
173
+ of any other Contributor, and only if You agree to indemnify,
174
+ defend, and hold each Contributor harmless for any liability
175
+ incurred by, or claims asserted against, such Contributor by reason
176
+ of your accepting any such warranty or additional liability.
177
+
178
+ END OF TERMS AND CONDITIONS
179
+
180
+ APPENDIX: How to apply the Apache License to your work.
181
+
182
+ To apply the Apache License to your work, attach the following
183
+ boilerplate notice, with the fields enclosed by brackets "[]"
184
+ replaced with your own identifying information. (Don't include
185
+ the brackets!) The text should be enclosed in the appropriate
186
+ comment syntax for the file format. We also recommend that a
187
+ file or class name and description of purpose be included on the
188
+ same "printed page" as the copyright notice for easier
189
+ identification within third-party archives.
190
+
191
+ Copyright [yyyy] [name of copyright owner]
192
+
193
+ Licensed under the Apache License, Version 2.0 (the "License");
194
+ you may not use this file except in compliance with the License.
195
+ You may obtain a copy of the License at
196
+
197
+ http://www.apache.org/licenses/LICENSE-2.0
198
+
199
+ Unless required by applicable law or agreed to in writing, software
200
+ distributed under the License is distributed on an "AS IS" BASIS,
201
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
202
+ See the License for the specific language governing permissions and
203
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,171 @@
1
- # Temporary Holding Version
1
+ # @plasius/learning-runtime
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Bounded project execution and deterministic simulation for learning course hosts.
4
+ This package is under development; no released runtime is available yet.
5
+
6
+ ## Runtime entry points
7
+
8
+ `@plasius/learning-runtime/maze` parses the closed visual project and runs bounded
9
+ world scenarios. `runMazeProject(source, scene)` returns position, heading, rescue
10
+ counts and a step trace. Reaching the pad with no explorers remaining ends the
11
+ rescue. `projectMazeLanguages(source)` produces explanatory JavaScript, Python and
12
+ C++ views from that same visual program; the views are not executed.
13
+
14
+ `@plasius/learning-runtime/javascript` lazily loads QuickJS. Call
15
+ `createJavaScriptProjectSession(source, { signal })`, then
16
+ `session.call("update", [state, input])` using JSON data, and always
17
+ `session.dispose()` in a finally block. A session has isolated global state, a
18
+ 16 MiB memory limit, a 256 KiB stack and a 100 ms deadline per call (host adjustable
19
+ up to 500 ms, enforced cooperatively by the engine). Source and JSON transport are limited to 64,000 characters; input
20
+ has depth/node limits. Runtime failure closes the session. No host functions or
21
+ module loader are installed. Calls are synchronous: the browser must use a worker
22
+ and impose its own hard deadline and cancellation. Server assessors also run it
23
+ inside a worker they can terminate: a native engine operation cannot always be
24
+ interrupted immediately. Hosts validate the returned
25
+ game-specific state before rendering or assessing it.
26
+ `Math.random()` uses a host-selected reproducible seed (default 1); ambient Date
27
+ and Intl clocks are absent. Supply simulated time explicitly through project input.
28
+
29
+ Server consumers use `createServerProjectSession` from
30
+ `@plasius/learning-runtime/server`. Its asynchronous `call` API runs the same core
31
+ inside a private Node worker with an empty environment. Startup is limited to
32
+ 1.5 seconds and calls to 500 ms by default; timeout, cancellation or failure
33
+ terminates the worker. There is one in-flight request per session and at most four
34
+ workers per process, with immediate `BUSY` responses instead of an unbounded queue.
35
+ Always `await session.dispose()`; error codes carry no source or worker stack.
36
+ Both ESM and CommonJS entry points are exercised using their actual compiled
37
+ workers. The native-allocation regression also checks that the host stays responsive.
38
+
39
+ All project/state data stays in the caller's process and must be handled as
40
+ private learner content. Runtime errors contain fixed codes, never learner text.
41
+
42
+ `@plasius/learning-runtime/cpp` supplies `createCppProjectSession(source, options)`
43
+ for the documented C++ robot simulator subset. Declare output signatures such as
44
+ `{ outputs: { setServoAngle: ["number"] } }`; each `run({ timeMs, sensors })`
45
+ returns structured `commands` and a detached primitive `globals` snapshot.
46
+ The host validates command names, ranges and simulation safety before applying
47
+ them. No host callback is accepted and no hardware action is performed.
48
+
49
+ Programs require `void loop()` and may include a one-time `void setup()`, globals,
50
+ typed helper functions, block-local variables, assignments, if/else, for/while,
51
+ return, break and continue. Supported primitive types are int, double, bool and
52
+ string; constants require initial values. Integer division truncates toward zero;
53
+ mixed numeric arithmetic uses double. Conditions require bool and sensor readers
54
+ require the matching primitive type. There are no implicit number/bool conversions,
55
+ arrays, pointers, classes, includes, imports or arbitrary member access. This is a
56
+ teaching simulator, not a full C++ compiler or an Arduino firmware toolchain.
57
+
58
+ The built-ins are `millis()`, `numberSensor(name)`, `boolSensor(name)`,
59
+ `textSensor(name)`, `min(a,b)`, `max(a,b)` and `abs(value)`. Time is supplied by
60
+ the host, never read from a wall clock. Use elapsed-time conditions instead of
61
+ blocking sleeps. Sensor observations are freshly snapshotted on each tick.
62
+ Globals persist only inside that session; create a new session to restart.
63
+
64
+ Limits: 32,768 source characters, 4,096 tokens, parse depth 64, 64 top-level names,
65
+ 32 functions, eight arguments, 64 variables per scope, 2,000 execution operations
66
+ and call depth 16 per tick. A tick accepts at most 32 primitive sensors and emits
67
+ at most 64 commands from at most 16 declared signatures. Strings are at most 256
68
+ characters; numbers are finite and at most one billion in magnitude. Simulated
69
+ milliseconds are nonnegative integers and cannot run backwards. Accessor inputs
70
+ are rejected without invoking them. Failure or cancellation closes the session,
71
+ discards that tick's commands and releases state; error messages contain no source.
72
+ Use `dispose()` after successful use as well. Browser hosts still run learners'
73
+ programs in their cancellable worker, keeping the interface responsive.
74
+
75
+ ### Web project templates
76
+
77
+ `@plasius/learning-runtime/web` supplies `createWebProject({ html, css }, { signal })`.
78
+ It parses a documented HTML/CSS subset without creating DOM nodes, executing
79
+ JavaScript or loading resources. Call `project.render(view)` with bounded JSON
80
+ returned from the separately isolated learner `view` function. The result contains
81
+ inert `nodes` and approved `css`; `project.template` returns a detached structural
82
+ snapshot. Dispose on navigation/cancellation. Invalid view data may be corrected
83
+ and rendered again; cancellation closes the project permanently.
84
+
85
+ Use semantic sections, headings, text, lists, tables, forms and native controls.
86
+ Scripts, metadata, URLs, embeds, SVG/MathML, custom elements, event attributes and
87
+ inline styles are rejected, including unsupported tokens an HTML parser would
88
+ otherwise discard. The parser uses HTML's own tokenization and tree construction;
89
+ it does not implement an approximate HTML regex parser.
90
+
91
+ Bindings read own JSON fields through paths such as `draft.title`, at most four
92
+ segments; expressions, array indexing and prototype paths are unsupported:
93
+
94
+ | Attribute | Meaning |
95
+ | --- | --- |
96
+ | `data-text` | Replace children with a scalar text value. |
97
+ | `data-value` | Project a control, output, progress or meter value. |
98
+ | `data-checked`, `data-disabled`, `data-pressed` | Project boolean checked/disabled/ARIA-pressed state. |
99
+ | `data-invalid` | Project boolean ARIA-invalid state on a form field. |
100
+ | `data-label` | Project a nonempty accessible label. |
101
+ | `data-if` | Include the element only when the bound boolean is true. |
102
+ | `data-repeat` | Repeat this element for up to 50 records with unique string `id` values; descendant bindings read that record. |
103
+ | `data-action` | Emit action metadata for a form or a `type="button"` button. |
104
+ | `data-id` | Bind an optional action item ID. |
105
+
106
+ Static element IDs are forbidden within repeat subtrees. Named text, number,
107
+ range, checkbox, textarea and select controls expose `field` metadata. Hosts
108
+ translate changes to `{ type: "field", name, value }`, with bounded strings or
109
+ checkbox booleans; action controls produce `{ type, id? }`. No event object,
110
+ DOM reference, callback or implicit JavaScript expression reaches learner code.
111
+ Forms use their own submit action; their submit buttons have no separate action.
112
+ Forms may use `novalidate` for custom reducer validation, with `aria-required`,
113
+ `data-invalid`, described errors and persistent alert/status regions providing
114
+ equivalent accessible feedback instead of relying on native validation popups.
115
+
116
+ Styles use a bounded allowlist of layout, typography, colour, box and focus
117
+ properties. Custom properties are parsed and checked too. Supported media rules
118
+ are min/max width, reduced motion and colour scheme. URLs, imports, font loading,
119
+ unparsed values, `!important`, fixed positioning, pseudo-elements and unsupported
120
+ functions/selectors are rejected. Attribute selectors are limited to exact native
121
+ input-type and boolean ARIA-pressed/expanded/invalid/required comparisons. Transition durations are
122
+ at most two seconds; explicit grid repetitions are at most twelve.
123
+
124
+ Budgets: HTML 24,000 characters; CSS 16,000; 256 template nodes at depth 20;
125
+ 16 attributes per element, each at most 240 characters; CSS 2,048 syntax nodes
126
+ at depth 16; 768 projected nodes; serialized projection at most 64,000 characters.
127
+ Bound control values are at most 2,000 characters and accessible labels 240.
128
+ JSON views reuse the existing transport's node/depth/value limits and reject
129
+ accessors without invoking them. Errors contain fixed codes, never source text.
130
+
131
+ The host must run compilation/projection in its disposable worker and render only
132
+ this closed representation using element, text and known attribute/property APIs.
133
+ Never concatenate it into executable HTML. Isolate the preview with a restrictive
134
+ sandbox and CSP prohibiting scripts, resource loads, navigation and outgoing forms;
135
+ install approved CSS with `textContent`. Preserve focus and native field input,
136
+ validate translated actions, expose useful failure feedback and keep editor/account
137
+ controls outside the preview. Parser success is neither an accessibility pass nor
138
+ course assessment evidence. See [ADR 0004](docs/adrs/adr-0004-bounded-web-projects.md).
139
+
140
+ The browser worker and the server assessor use the same runtime. Learner source
141
+ never receives browser, network, storage, account or physical hardware access.
142
+ The host owns authentication, saves, protected test scenarios and final scoring.
143
+ Runtime success alone grants no progress, badge or entitlement.
144
+
145
+ ## Development
146
+
147
+ Use the Node version in `.nvmrc`, then `npm ci`, `npm test`, `npm run typecheck`,
148
+ `npm run lint` and `npm run build`. `npm run test:coverage` enforces 80% coverage;
149
+ every changed source must appear in LCOV. `npm run pack:check` checks publication
150
+ contents. Source and project data must never enter logs or test snapshots.
151
+
152
+ Repository setup follows the schema package template. Publication is exclusively
153
+ through `.github/workflows/cd.yml` on `main` and the GitHub `production` environment.
154
+ Consumer adoption requires verified CI, the exact package release and registry
155
+ integrity. Never publish directly from a workstation.
156
+
157
+ See [the runtime boundary decision](docs/adrs/adr-0001-bounded-course-runtime.md)
158
+ and [delivery design](docs/design/complete-course-runtime.md). The robot language
159
+ boundary is recorded in [ADR 0003](docs/adrs/adr-0003-bounded-robot-programs.md).
160
+
161
+ ## Package registration and trusted publishing
162
+
163
+ The release workflow follows the shared `@plasius/schema` template. Initial
164
+ registration of `@plasius/learning-runtime@0.1.2` is verified and its enrollment
165
+ descriptor is retired. Releases use main `cd.yml`, the `production` environment
166
+ and npm Trusted Publishing through OIDC. Ordinary releases do not use `NPM_TOKEN`;
167
+ an explicit first-registration request now fails before registry access. See the
168
+ [registration design](docs/design/shared-first-registration.md) and
169
+ [ADR 0005](docs/adrs/adr-0005-shared-schema-registration.md) for exact admission, credential cleanup
170
+ and the OIDC handover checks. Each release remains incomplete until CD and npm
171
+ registry integrity are verified.
@@ -0,0 +1,189 @@
1
+ // src/javascript.ts
2
+ var JAVASCRIPT_PROJECT_LIMITS = Object.freeze({
3
+ sourceCharacters: 64e3,
4
+ jsonCharacters: 64e3,
5
+ memoryBytes: 16 * 1024 * 1024,
6
+ stackBytes: 256 * 1024,
7
+ executionMs: 100,
8
+ maximumExecutionMs: 500,
9
+ calls: 1e4,
10
+ arguments: 8,
11
+ jsonDepth: 20,
12
+ jsonNodes: 4096
13
+ });
14
+ var JavaScriptProjectRuntimeError = class extends Error {
15
+ constructor(code) {
16
+ super(`Learning project: ${code}`);
17
+ this.code = code;
18
+ this.name = "JavaScriptProjectRuntimeError";
19
+ }
20
+ code;
21
+ };
22
+ var invalid = () => {
23
+ throw new JavaScriptProjectRuntimeError("INVALID_INPUT");
24
+ };
25
+ function serializeProjectJson(value) {
26
+ const seen = /* @__PURE__ */ new Set();
27
+ let nodes = 0;
28
+ function visit(value2, depth) {
29
+ if (++nodes > JAVASCRIPT_PROJECT_LIMITS.jsonNodes || depth > JAVASCRIPT_PROJECT_LIMITS.jsonDepth) return invalid();
30
+ if (value2 === null || typeof value2 === "boolean") return;
31
+ if (typeof value2 === "string") {
32
+ if (value2.length > JAVASCRIPT_PROJECT_LIMITS.jsonCharacters) return invalid();
33
+ return;
34
+ }
35
+ if (typeof value2 === "number") {
36
+ if (!Number.isFinite(value2)) return invalid();
37
+ return;
38
+ }
39
+ if (typeof value2 !== "object" || seen.has(value2)) return invalid();
40
+ const array = Array.isArray(value2);
41
+ const prototype = Object.getPrototypeOf(value2);
42
+ if (prototype !== (array ? Array.prototype : Object.prototype) && prototype !== null) return invalid();
43
+ seen.add(value2);
44
+ const descriptors = Object.getOwnPropertyDescriptors(value2);
45
+ const keys = Object.keys(descriptors);
46
+ if (Object.getOwnPropertySymbols(value2).length || keys.length > JAVASCRIPT_PROJECT_LIMITS.jsonNodes) return invalid();
47
+ if (array && (value2.length > JAVASCRIPT_PROJECT_LIMITS.jsonNodes || keys.length !== value2.length + 1)) return invalid();
48
+ for (const key of keys) {
49
+ if (array && key === "length") continue;
50
+ const descriptor = descriptors[key];
51
+ if (key.length > 160 || descriptor.get || descriptor.set || !descriptor.enumerable) return invalid();
52
+ if (array && !/^(0|[1-9][0-9]*)$/u.test(key)) return invalid();
53
+ visit(descriptor.value, depth + 1);
54
+ }
55
+ seen.delete(value2);
56
+ }
57
+ visit(value, 0);
58
+ const json = JSON.stringify(value);
59
+ if (json.length > JAVASCRIPT_PROJECT_LIMITS.jsonCharacters) return invalid();
60
+ return json;
61
+ }
62
+ async function createJavaScriptProjectSession(source, options = {}) {
63
+ const executionMs = options.executionMs ?? JAVASCRIPT_PROJECT_LIMITS.executionMs;
64
+ const maximumCalls = options.maximumCalls ?? JAVASCRIPT_PROJECT_LIMITS.calls;
65
+ const seed = options.seed ?? 1;
66
+ if (typeof source !== "string" || source.length > JAVASCRIPT_PROJECT_LIMITS.sourceCharacters || !Number.isInteger(executionMs) || executionMs < 1 || executionMs > JAVASCRIPT_PROJECT_LIMITS.maximumExecutionMs || !Number.isInteger(maximumCalls) || maximumCalls < 1 || maximumCalls > JAVASCRIPT_PROJECT_LIMITS.calls || !Number.isInteger(seed) || seed < 1 || seed > 4294967295) return invalid();
67
+ options.signal?.throwIfAborted();
68
+ const { getQuickJS } = await import("quickjs-emscripten");
69
+ const engine = await getQuickJS();
70
+ options.signal?.throwIfAborted();
71
+ let runtime;
72
+ let context;
73
+ const retained = [];
74
+ let closed = false;
75
+ let deadline = Date.now() + executionMs;
76
+ let calls = 0;
77
+ const dispose = () => {
78
+ if (closed) return;
79
+ closed = true;
80
+ options.signal?.removeEventListener("abort", dispose);
81
+ for (const handle of retained.reverse()) if (handle.alive) handle.dispose();
82
+ if (context?.alive) context.dispose();
83
+ if (runtime?.alive) runtime.dispose();
84
+ };
85
+ try {
86
+ runtime = engine.newRuntime();
87
+ runtime.setMemoryLimit(JAVASCRIPT_PROJECT_LIMITS.memoryBytes);
88
+ runtime.setMaxStackSize(JAVASCRIPT_PROJECT_LIMITS.stackBytes);
89
+ runtime.setInterruptHandler(() => Date.now() >= deadline || options.signal?.aborted === true);
90
+ context = runtime.newContext();
91
+ const vm = context;
92
+ const take = (result, handles) => {
93
+ if (result.error) {
94
+ result.error.dispose();
95
+ throw new JavaScriptProjectRuntimeError("EXECUTION_FAILED");
96
+ }
97
+ handles.push(result.value);
98
+ return result.value;
99
+ };
100
+ const transport = take(vm.evalCode(`((parse, stringify, finite) => ({
101
+ parse,
102
+ serialize: value => stringify(value, (_key, item) => {
103
+ const kind = typeof item;
104
+ if (kind === 'undefined' || kind === 'function' || kind === 'symbol' || kind === 'bigint'
105
+ || (kind === 'number' && !finite(item))) throw new Error('not-json');
106
+ return item;
107
+ })
108
+ }))(JSON.parse, JSON.stringify, Number.isFinite)`), retained);
109
+ const parse = vm.getProp(transport, "parse");
110
+ retained.push(parse);
111
+ const serialize = vm.getProp(transport, "serialize");
112
+ retained.push(serialize);
113
+ const deterministic = vm.evalCode(`(() => {
114
+ let state = ${seed};
115
+ Object.defineProperty(Math, 'random', { value: () => {
116
+ state ^= state << 13; state ^= state >>> 17; state ^= state << 5;
117
+ return (state >>> 0) / 4294967296;
118
+ }, writable: false, configurable: false });
119
+ for (const name of ['Date', 'Intl']) Object.defineProperty(globalThis, name, {
120
+ value: undefined, writable: false, configurable: false
121
+ });
122
+ })()`);
123
+ if (deterministic.error) {
124
+ deterministic.error.dispose();
125
+ throw new JavaScriptProjectRuntimeError("EXECUTION_FAILED");
126
+ }
127
+ deterministic.value.dispose();
128
+ const initialization = vm.evalCode(source, "project.js", { type: "global", strict: true });
129
+ if (initialization.error) {
130
+ initialization.error.dispose();
131
+ throw new JavaScriptProjectRuntimeError("EXECUTION_FAILED");
132
+ }
133
+ initialization.value.dispose();
134
+ options.signal?.addEventListener("abort", dispose, { once: true });
135
+ return {
136
+ get closed() {
137
+ return closed;
138
+ },
139
+ dispose,
140
+ call(entry, args) {
141
+ if (closed) throw new JavaScriptProjectRuntimeError("CLOSED");
142
+ if (typeof entry !== "string" || !/^[A-Za-z][A-Za-z0-9_]{0,63}$/u.test(entry) || !Array.isArray(args) || args.length > JAVASCRIPT_PROJECT_LIMITS.arguments) return invalid();
143
+ const json = serializeProjectJson(args);
144
+ if (++calls > maximumCalls) {
145
+ dispose();
146
+ throw new JavaScriptProjectRuntimeError("CALL_LIMIT");
147
+ }
148
+ deadline = Date.now() + executionMs;
149
+ const handles = [];
150
+ let failed = false;
151
+ try {
152
+ const encoded = vm.newString(json);
153
+ handles.push(encoded);
154
+ const parsed = take(vm.callFunction(parse, vm.undefined, encoded), handles);
155
+ const parameters = args.map((_, index) => {
156
+ const handle = vm.getProp(parsed, index);
157
+ handles.push(handle);
158
+ return handle;
159
+ });
160
+ const fn = take(vm.evalCode(entry, "entry.js", { type: "global", strict: true }), handles);
161
+ const result = take(vm.callFunction(fn, vm.undefined, parameters), handles);
162
+ const serialized = take(vm.callFunction(serialize, vm.undefined, result), handles);
163
+ const output = vm.getString(serialized);
164
+ if (output.length > JAVASCRIPT_PROJECT_LIMITS.jsonCharacters) throw new JavaScriptProjectRuntimeError("OUTPUT_LIMIT");
165
+ const value = JSON.parse(output);
166
+ serializeProjectJson(value);
167
+ return value;
168
+ } catch (error) {
169
+ failed = true;
170
+ throw error instanceof JavaScriptProjectRuntimeError ? error : new JavaScriptProjectRuntimeError("EXECUTION_FAILED");
171
+ } finally {
172
+ for (const handle of handles.reverse()) if (handle.alive) handle.dispose();
173
+ if (failed) dispose();
174
+ }
175
+ }
176
+ };
177
+ } catch {
178
+ dispose();
179
+ throw new JavaScriptProjectRuntimeError("EXECUTION_FAILED");
180
+ }
181
+ }
182
+
183
+ export {
184
+ JAVASCRIPT_PROJECT_LIMITS,
185
+ JavaScriptProjectRuntimeError,
186
+ serializeProjectJson,
187
+ createJavaScriptProjectSession
188
+ };
189
+ //# sourceMappingURL=chunk-2YWUDCGJ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/javascript.ts"],"sourcesContent":["import type { QuickJSContext, QuickJSHandle, QuickJSRuntime } from \"quickjs-emscripten\";\n\nexport type ProjectJsonValue = null | boolean | number | string | ProjectJsonValue[] | { [key: string]: ProjectJsonValue };\nexport const JAVASCRIPT_PROJECT_LIMITS = Object.freeze({ sourceCharacters: 64000, jsonCharacters: 64000,\n memoryBytes: 16 * 1024 * 1024, stackBytes: 256 * 1024, executionMs: 100, maximumExecutionMs: 500,\n calls: 10000, arguments: 8, jsonDepth: 20, jsonNodes: 4096 });\nexport class JavaScriptProjectRuntimeError extends Error {\n constructor(readonly code: \"INVALID_INPUT\" | \"EXECUTION_FAILED\" | \"OUTPUT_LIMIT\" | \"CALL_LIMIT\" | \"CLOSED\") {\n super(`Learning project: ${code}`); this.name = \"JavaScriptProjectRuntimeError\";\n }\n}\nexport interface JavaScriptProjectSession {\n readonly closed: boolean;\n /** Invoke a declared learner function with detached, bounded JSON data. */\n call(entry: string, args: ProjectJsonValue[]): ProjectJsonValue;\n /** Idempotent. Hosts must dispose on navigation, worker shutdown or cancellation. */\n dispose(): void;\n}\nexport interface JavaScriptProjectSessionOptions {\n executionMs?: number;\n maximumCalls?: number;\n signal?: AbortSignal;\n /** Same source, inputs and seed reproduce the same pseudo-random sequence. */\n seed?: number;\n}\nconst invalid = (): never => { throw new JavaScriptProjectRuntimeError(\"INVALID_INPUT\"); };\n\n/** Reject accessors, cycles and non-JSON values before host serialization. */\nexport function serializeProjectJson(value: unknown): string {\n const seen = new Set<object>();\n let nodes = 0;\n function visit(value: unknown, depth: number): void {\n if (++nodes > JAVASCRIPT_PROJECT_LIMITS.jsonNodes || depth > JAVASCRIPT_PROJECT_LIMITS.jsonDepth) return invalid();\n if (value === null || typeof value === \"boolean\") return;\n if (typeof value === \"string\") { if (value.length > JAVASCRIPT_PROJECT_LIMITS.jsonCharacters) return invalid(); return; }\n if (typeof value === \"number\") { if (!Number.isFinite(value)) return invalid(); return; }\n if (typeof value !== \"object\" || seen.has(value)) return invalid();\n const array = Array.isArray(value);\n const prototype = Object.getPrototypeOf(value);\n if (prototype !== (array ? Array.prototype : Object.prototype) && prototype !== null) return invalid();\n seen.add(value);\n const descriptors = Object.getOwnPropertyDescriptors(value);\n const keys = Object.keys(descriptors);\n if (Object.getOwnPropertySymbols(value).length || keys.length > JAVASCRIPT_PROJECT_LIMITS.jsonNodes) return invalid();\n if (array && (value.length > JAVASCRIPT_PROJECT_LIMITS.jsonNodes || keys.length !== value.length + 1)) return invalid();\n for (const key of keys) {\n if (array && key === \"length\") continue;\n const descriptor = descriptors[key]!;\n if (key.length > 160 || descriptor.get || descriptor.set || !descriptor.enumerable) return invalid();\n if (array && !/^(0|[1-9][0-9]*)$/u.test(key)) return invalid();\n visit(descriptor.value, depth + 1);\n }\n seen.delete(value);\n }\n visit(value, 0);\n const json = JSON.stringify(value);\n if (json.length > JAVASCRIPT_PROJECT_LIMITS.jsonCharacters) return invalid();\n return json;\n}\n\n/**\n * Create a capability-free QuickJS session. Run this inside a disposable browser\n * worker on both browser and server, never on the browser UI or server event loop.\n * Each call gets a fresh cooperative deadline; the host must enforce its hard\n * deadline by terminating the worker. Runtime failures permanently close sessions.\n */\nexport async function createJavaScriptProjectSession(source: string, options: JavaScriptProjectSessionOptions = {}): Promise<JavaScriptProjectSession> {\n const executionMs = options.executionMs ?? JAVASCRIPT_PROJECT_LIMITS.executionMs;\n const maximumCalls = options.maximumCalls ?? JAVASCRIPT_PROJECT_LIMITS.calls;\n const seed = options.seed ?? 1;\n if (typeof source !== \"string\" || source.length > JAVASCRIPT_PROJECT_LIMITS.sourceCharacters\n || !Number.isInteger(executionMs) || executionMs < 1 || executionMs > JAVASCRIPT_PROJECT_LIMITS.maximumExecutionMs\n || !Number.isInteger(maximumCalls) || maximumCalls < 1 || maximumCalls > JAVASCRIPT_PROJECT_LIMITS.calls\n || !Number.isInteger(seed) || seed < 1 || seed > 0xffffffff) return invalid();\n options.signal?.throwIfAborted();\n const { getQuickJS } = await import(\"quickjs-emscripten\");\n const engine = await getQuickJS();\n options.signal?.throwIfAborted();\n let runtime: QuickJSRuntime | undefined;\n let context: QuickJSContext | undefined;\n const retained: QuickJSHandle[] = [];\n let closed = false;\n let deadline = Date.now() + executionMs;\n let calls = 0;\n const dispose = () => {\n if (closed) return;\n closed = true;\n options.signal?.removeEventListener(\"abort\", dispose);\n for (const handle of retained.reverse()) if (handle.alive) handle.dispose();\n if (context?.alive) context.dispose();\n if (runtime?.alive) runtime.dispose();\n };\n try {\n runtime = engine.newRuntime();\n runtime.setMemoryLimit(JAVASCRIPT_PROJECT_LIMITS.memoryBytes);\n runtime.setMaxStackSize(JAVASCRIPT_PROJECT_LIMITS.stackBytes);\n runtime.setInterruptHandler(() => Date.now() >= deadline || options.signal?.aborted === true);\n context = runtime.newContext();\n const vm = context;\n const take = (result: ReturnType<QuickJSContext[\"evalCode\"]>, handles: QuickJSHandle[]): QuickJSHandle => {\n if (result.error) { result.error.dispose(); throw new JavaScriptProjectRuntimeError(\"EXECUTION_FAILED\"); }\n handles.push(result.value); return result.value;\n };\n // Captured before learner code; later replacement of global JSON/Number cannot\n // forge the transport. No handle or host callback is exposed in the realm.\n const transport = take(vm.evalCode(`((parse, stringify, finite) => ({\n parse,\n serialize: value => stringify(value, (_key, item) => {\n const kind = typeof item;\n if (kind === 'undefined' || kind === 'function' || kind === 'symbol' || kind === 'bigint'\n || (kind === 'number' && !finite(item))) throw new Error('not-json');\n return item;\n })\n }))(JSON.parse, JSON.stringify, Number.isFinite)`), retained);\n const parse = vm.getProp(transport, \"parse\"); retained.push(parse);\n const serialize = vm.getProp(transport, \"serialize\"); retained.push(serialize);\n const deterministic = vm.evalCode(`(() => {\n let state = ${seed};\n Object.defineProperty(Math, 'random', { value: () => {\n state ^= state << 13; state ^= state >>> 17; state ^= state << 5;\n return (state >>> 0) / 4294967296;\n }, writable: false, configurable: false });\n for (const name of ['Date', 'Intl']) Object.defineProperty(globalThis, name, {\n value: undefined, writable: false, configurable: false\n });\n })()`);\n if (deterministic.error) { deterministic.error.dispose(); throw new JavaScriptProjectRuntimeError(\"EXECUTION_FAILED\"); }\n deterministic.value.dispose();\n const initialization = vm.evalCode(source, \"project.js\", { type: \"global\", strict: true });\n if (initialization.error) { initialization.error.dispose(); throw new JavaScriptProjectRuntimeError(\"EXECUTION_FAILED\"); }\n initialization.value.dispose();\n options.signal?.addEventListener(\"abort\", dispose, { once: true });\n return {\n get closed() { return closed; },\n dispose,\n call(entry, args) {\n if (closed) throw new JavaScriptProjectRuntimeError(\"CLOSED\");\n if (typeof entry !== \"string\" || !/^[A-Za-z][A-Za-z0-9_]{0,63}$/u.test(entry)\n || !Array.isArray(args) || args.length > JAVASCRIPT_PROJECT_LIMITS.arguments) return invalid();\n const json = serializeProjectJson(args);\n if (++calls > maximumCalls) { dispose(); throw new JavaScriptProjectRuntimeError(\"CALL_LIMIT\"); }\n deadline = Date.now() + executionMs;\n const handles: QuickJSHandle[] = [];\n let failed = false;\n try {\n const encoded = vm.newString(json); handles.push(encoded);\n const parsed = take(vm.callFunction(parse, vm.undefined, encoded), handles);\n const parameters = args.map((_, index) => { const handle = vm.getProp(parsed, index); handles.push(handle); return handle; });\n const fn = take(vm.evalCode(entry, \"entry.js\", { type: \"global\", strict: true }), handles);\n const result = take(vm.callFunction(fn, vm.undefined, parameters), handles);\n const serialized = take(vm.callFunction(serialize, vm.undefined, result), handles);\n const output = vm.getString(serialized);\n if (output.length > JAVASCRIPT_PROJECT_LIMITS.jsonCharacters) throw new JavaScriptProjectRuntimeError(\"OUTPUT_LIMIT\");\n const value: unknown = JSON.parse(output);\n serializeProjectJson(value);\n return value as ProjectJsonValue;\n } catch (error) {\n failed = true;\n throw error instanceof JavaScriptProjectRuntimeError ? error : new JavaScriptProjectRuntimeError(\"EXECUTION_FAILED\");\n } finally {\n for (const handle of handles.reverse()) if (handle.alive) handle.dispose();\n if (failed) dispose();\n }\n },\n };\n } catch {\n dispose();\n throw new JavaScriptProjectRuntimeError(\"EXECUTION_FAILED\");\n }\n}\n"],"mappings":";AAGO,IAAM,4BAA4B,OAAO,OAAO;AAAA,EAAE,kBAAkB;AAAA,EAAO,gBAAgB;AAAA,EAChG,aAAa,KAAK,OAAO;AAAA,EAAM,YAAY,MAAM;AAAA,EAAM,aAAa;AAAA,EAAK,oBAAoB;AAAA,EAC7F,OAAO;AAAA,EAAO,WAAW;AAAA,EAAG,WAAW;AAAA,EAAI,WAAW;AAAK,CAAC;AACvD,IAAM,gCAAN,cAA4C,MAAM;AAAA,EACvD,YAAqB,MAAuF;AAC1G,UAAM,qBAAqB,IA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