@yaks/code-mode 0.0.0-stage → 0.2.36

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 ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2026 Jeff Peterson
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,87 @@
1
- # Temporary Holding Version
1
+ # @yaks/code-mode
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
+ Short JS/TS executions over a scoped tool registry. `catalog()` preserves each
4
+ provider and tool name as an object path; `declarations()` generates TypeScript
5
+ from the registry's input and output schemas. `execute()` records nested calls
6
+ through the supplied runner with the outer call's actor, instrument and source.
7
+ Its `refused` option hears what the bridge refuses before any runner does (a
8
+ tool outside the scope, a limit, a malformed argument or `results.read`, a call
9
+ after the execution ended) as a runner's `refused` hears its own, each with the
10
+ nested call it refused: the id a call keeps from the bridge to the runner, so a
11
+ host deduping by call hears each call once. When a tool or the host's
12
+ `strangerWrote` option marks a nested answer `heard`, both the nested call's
13
+ receipt and the execution's answer carry `heard`.
14
+
15
+ The host supplies an isolated evaluator, and a `Strip` that reads a script's
16
+ TypeScript as JavaScript: yaks.app strips through its compiler Worker, which
17
+ carries sucrase so the kernel need not. The yaks.app connector exposes
18
+ `code_mode`; omit `script` to read declarations, with `search`, `offset` and
19
+ `limit` for discovery. A script is an async function body with `tools` and
20
+ `results` in scope. For example, to publish your HTML in an app:
21
+
22
+ ```ts ignore
23
+ await tools.yaks.app_new({ slug, title, access: 'public' })
24
+ await tools.yaks.app_files({
25
+ app: slug,
26
+ files: [{ path: 'index.html', content: html }],
27
+ })
28
+ return await tools.yaks.app_deploy({ app: slug })
29
+ ```
30
+
31
+ Each function answers the MCP result: `content`, `structuredContent`, and
32
+ `isError` for a tool's refusal. Check `isError` before depending on a tool's
33
+ success. The execution answers `{value, calls, error?}`: `value` is what the
34
+ script returned, and each call is a receipt of its id and exact path, with
35
+ `isError` and the first KiB of its words when it failed. Inner results stay in
36
+ the isolate: a script reads, filters and joins there, and returns only what the
37
+ model needs. `code_mode` itself is excluded from nested discovery and execution.
38
+
39
+ The host supplies `Kept` so a script can read results the harness saved in the
40
+ caller's graph through `await results.read(id)`. Nested tool calls and script
41
+ return values remain complete for programs. The agent harness keeps oversized
42
+ answers and gives the model a summary after execution.
43
+
44
+ ```ts ignore
45
+ let rows = await results.read('result-id')
46
+ return rows.filter((row) => row.status === 'open').map((row) => row.id)
47
+ ```
48
+
49
+ `results.read` reads the saved value exactly, within the caller's scope. Its
50
+ capability is revoked when the execution ends. yaks.app's `result_query` tool
51
+ runs jq against the same snapshots. Ordinary graph answers have rows at
52
+ `.result`; custom tool answers keep data under `.structuredContent`, with
53
+ accompanying text in `.content`.
54
+
55
+ On yaks.app, a fresh dynamic Worker runs each script with 30 seconds of CPU, 40
56
+ seconds of elapsed time, 128 MiB of memory and 64 tool calls. Its tool bridge is
57
+ revoked when the execution ends. A script and its ordinary tool arguments each
58
+ have a 64 KiB limit. A serialized result, kept result read or script answer has
59
+ a 32 MiB limit. A script's failure leaves started writes in flight. A receipt
60
+ with `pending: true` means the outcome is still unknown.
61
+
62
+ The hosted adapter supplies `fs` with a request-local `/tmp` and `/apps/<app>`
63
+ for draft files. App file operations use the ordinary `app_files` tool with its
64
+ draft selection, permissions and receipts. The host gives the isolate an egress
65
+ binding for HTTP requests. Pass `app` to use that app's connection sentinels.
66
+ Egress holds the credentials and sends them to destinations the connection
67
+ permits.
68
+
69
+ A host that passes `browser`, puppeteer's module, gives a script that names
70
+ `browser` a `browser.launch()`: puppeteer launches on the Worker's
71
+ `env.BROWSER`, which the host lends, and every browser the script launched is
72
+ closed when the run ends. A script that does not name it loads no puppeteer.
73
+
74
+ A host that passes `repl` runs the script as a cell of that REPL
75
+ (`@yaks/code-mode/repl`). The cell's Worker exports `Cell`, a Durable Object
76
+ class the host runs as one facet for every cell, so `storage.sql` and
77
+ `storage.kv` are one database across cells. When a cell ends, its top-level
78
+ values that structured clone can copy are kept there, and the host keeps their
79
+ names and each function and class declaration's source (`cells`), so the next
80
+ cell declares them again before its own code (`carry`). `declared` (./scan.ts)
81
+ reads what a cell declares from its tokens.
82
+
83
+ The runtime contract follows Cloudflare's
84
+ [Worker Loader API](https://developers.cloudflare.com/dynamic-workers/api-reference/),
85
+ [egress control](https://developers.cloudflare.com/dynamic-workers/usage/egress-control/)
86
+ and
87
+ [custom resource limits](https://developers.cloudflare.com/dynamic-workers/usage/limits/).
@@ -0,0 +1,7 @@
1
+ export declare const FILE_BYTES: any;
2
+ export type FileScope = {
3
+ space?: string;
4
+ app?: string;
5
+ draft?: string;
6
+ };
7
+ //# sourceMappingURL=files.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"files.d.ts","sources":["../files.ts"],"names":[],"mappings":"AAGA,OAAO,cAAM,gBAAwB;AAErC,YAAY;EAAc,QAAQ,MAAM;EAAE,MAAM,MAAM;EAAE,QAAQ,MAAM"}
package/_dist/mod.d.ts ADDED
@@ -0,0 +1,107 @@
1
+ /** Short, isolated code executions over a caller's scoped registry. The host
2
+ * supplies an evaluator and reads a script's TypeScript as JavaScript; this
3
+ * package owns discovery, limits and the bridge. */ import { type Bundle, type Tool } from "@yaks/graph";
4
+ import { type Opts, type Provider, type Registry, type Runner } from "@yaks/tools";
5
+ import { type FileScope } from "./files.js";
6
+ export { catalog, declarations, type Entry } from "./types.js";
7
+ export { TOO } from "./source.js";
8
+ export { FILE_BYTES } from "./files.js";
9
+ export declare let LIMITS: {
10
+ readonly wallMs: number;
11
+ readonly cpuMs: number;
12
+ readonly memoryMiB: number;
13
+ readonly calls: number;
14
+ readonly systemBytes: number;
15
+ readonly scriptBytes: number;
16
+ };
17
+ export declare let HOSTED_LIMITS: {
18
+ readonly wallMs: number;
19
+ readonly cpuMs: number;
20
+ readonly calls: number;
21
+ };
22
+ export type Result = {
23
+ content: {
24
+ type: 'text';
25
+ text: string;
26
+ }[];
27
+ structuredContent?: Record<string, unknown>;
28
+ isError?: boolean;
29
+ };
30
+ /** One nested call as the answer reports it: the script holds its result,
31
+ * and only a failure's words come back, so the model reads what the script
32
+ * returns rather than every row a read handed the sandbox. */ export type Receipt = {
33
+ id: string;
34
+ path: [string, string];
35
+ isError?: boolean;
36
+ error?: string;
37
+ pending?: boolean;
38
+ /** the tool or `Options.hears` marked the answer `heard` */ heard?: true;
39
+ };
40
+ export type Answer = {
41
+ value: unknown;
42
+ calls: Receipt[];
43
+ error?: string;
44
+ /** the REPL the cell ran in */ repl?: string;
45
+ /** the cell's top-level names whose values could not be kept */ dropped?: string[];
46
+ };
47
+ /** A nested call as an execution's `timed` hears it: its id, its tool, and
48
+ * when its tool's run began and how long it took, on the execution's clock. */ export type Called = {
49
+ id: string;
50
+ name: string;
51
+ at: number;
52
+ ms: number;
53
+ };
54
+ /** Hears where an execution's time went. */ export type Timed = {
55
+ /** A stage of the execution, in milliseconds: `compile` (its script read
56
+ * into modules), `reach` (finding the runner each nested call reaches),
57
+ * `calls` (the time at least one nested call was running) and, for a
58
+ * script given `browser`, `browser` (the rest of its run, which drives the
59
+ * pages it opens). */ stage(name: string, ms: number): void;
60
+ /** Each nested call that reached its tool, once its run ends. */ call(call: Called): void;
61
+ };
62
+ /** The host admits reads of results kept by its model-facing harness. */ export type Kept = {
63
+ keep(value: unknown, source: Bundle): Promise<unknown>;
64
+ read(id: string): Promise<unknown>;
65
+ };
66
+ export type Evaluate = (modules: Record<string, string>, bridge: {
67
+ call(set: string, name: string, args: string): Promise<Result>;
68
+ read(id: string): Promise<unknown>;
69
+ file?(app: string, args: string): Promise<Result>;
70
+ }, signal: AbortSignal) => Promise<string>;
71
+ /** How the host reads a module's TypeScript as JavaScript, by its path.
72
+ * Throws a SyntaxError where the source does not parse. */ export type Strip = (path: string, source: string) => string | Promise<string>;
73
+ /** What an execution is given beside its script, tools and evaluator. A
74
+ * runner's `clock`, `report` and `refused` mean here what they mean to it:
75
+ * what the bridge refuses itself (a tool outside the scope, a limit,
76
+ * arguments that are not an object, a call after the execution ended) is
77
+ * heard by `refused` with the nested call it refused, as a runner hears its
78
+ * own refusals. */ export type Options = Pick<Opts, 'clock' | 'report' | 'refused'> & {
79
+ /** The app mount's tool arguments, scoped by the host. */ files?: FileScope;
80
+ /** puppeteer's module, read only for a script that names `browser`, which
81
+ * launches a browser on the evaluator's `env.BROWSER` */ browser?: () => Promise<string>;
82
+ /** the REPL this execution is a cell of: its top-level values and its
83
+ * `storage` last from cell to cell (./repl.ts) */ repl?: string;
84
+ /** Execution limits advertised by this host. */ limits?: typeof LIMITS;
85
+ /** the runner each nested call reaches, asked once for each file app and
86
+ * again after a call that may write, since a write can change what the
87
+ * caller reaches (default: the execution's `run`) */ current?: (fileApp?: string) => Promise<Pick<Runner, 'admit'>>;
88
+ /** Record a nested call's possible effects before dispatching it. */ beforeCall?: (set: string, tool: Tool) => Promise<void> | undefined;
89
+ /** the results the host's harness kept, read by `results.read` */ kept?: Kept;
90
+ /** whether the caller hears in a nested call's answer words it cannot
91
+ * vouch for, by the rule its direct calls take: its receipt says `heard`,
92
+ * and so does the execution's answer, as a direct call's result would */ hears?: (tool: Tool, answer: Bundle[]) => Promise<boolean>;
93
+ /** hears where the execution's time went */ timed?: Timed;
94
+ };
95
+ /** All nested calls use admitted registry implementations, the outer caller's
96
+ * stamps and the ordinary runner. Arguments cannot select an actor or session. */ export declare let execute: (script: string, registry: Registry, run: Runner, asked: Bundle, evaluate: Evaluate, strip: Strip, opts?: Options) => Promise<Answer>;
97
+ /** How a script names a tool, by the sets it will see. */ export declare let sets: (registry: Registry) => string;
98
+ type Definition = Omit<Tool, 'run' | 'inputSchema'> & {
99
+ inputSchema: NonNullable<Tool['inputSchema']> & {
100
+ properties: Record<string, unknown>;
101
+ };
102
+ };
103
+ /** The code tool's public declaration from its providers, without building
104
+ * their registry or publishing any of the nested tools' schemas. */ export declare let definition: (providers: readonly Provider[], opts?: Pick<Options, 'files' | 'limits' | 'browser'>) => Definition;
105
+ /** One connector tool: omit script to discover generated declarations; supply
106
+ * a JS/TS function body to execute it with the same tool objects. */ export declare let tool: (registry: Registry, run: Runner, evaluate: Evaluate, strip: Strip, opts?: Options) => Tool;
107
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sources":["../mod.ts"],"names":[],"mappings":"AAAA;;kDAEkD,GAClD,SAAiB,KAAK,MAAM,EAAQ,KAAK,IAAI,2BAAqC;AAGlF,SAKE,KAAK,IAAI,EACT,KAAK,QAAQ,EAEb,KAAK,QAAQ,EACb,KAAK,MAAM,2BAKkB;AAI/B,SAIE,KAAK,SAAS,qBACG;AACnB,SAAS,OAAO,EAAE,YAAY,EAAE,KAAK,KAAK,qBAAoB;AAC9D,SAAS,GAAG,sBAAqB;AACjC,SAAS,UAAU,qBAAoB;AAEvC,OAAO,YAAI;WACT;WACA;WACA;WACA;WACA;WACA;EACD;AACD,OAAO,YAAI;WAET;WACA;WACA;EACD;AACD,YAAY;EACV;IAAW,MAAM;IAAQ,MAAM,MAAM;;EACrC,oBAAoB,OAAO,MAAM,EAAE,OAAO;EAC1C,UAAU,OAAO;;AAEnB;;4DAE4D,GAC5D,YAAY;EACV,IAAI,MAAM;EACV,OAAO,MAAM,EAAE,MAAM;EACrB,UAAU,OAAO;EACjB,QAAQ,MAAM;EACd,UAAU,OAAO;EACjB,0DAA0D,GAC1D,QAAQ,IAAI;;AAEd,YAAY;EACV,OAAO,OAAO;EACd,OAAO;EACP,QAAQ,MAAM;EACd,6BAA6B,GAC7B,OAAO,MAAM;EACb,8DAA8D,GAC9D,UAAU,MAAM;;AAElB;6EAC6E,GAC7E,YAAY;EAAW,IAAI,MAAM;EAAE,MAAM,MAAM;EAAE,IAAI,MAAM;EAAE,IAAI,MAAM;;AACvE,0CAA0C,GAC1C,YAAY;EACV;;;;sBAIoB,GACpB,MAAM,MAAM,MAAM,EAAE,IAAI,MAAM,GAAG,IAAI;EACrC,+DAA+D,GAC/D,KAAK,MAAM,SAAS,IAAI;;AAE1B,uEAAuE,GACvE,YAAY;EACV,KAAK,OAAO,OAAO,EAAE,QAAQ,SAAS,QAAQ,OAAO;EACrD,KAAK,IAAI,MAAM,GAAG,QAAQ,OAAO;;AAEnC,YAAY,YACV,SAAS,OAAO,MAAM,EAAE,MAAM,GAC9B;EACE,KAAK,KAAK,MAAM,EAAE,MAAM,MAAM,EAAE,MAAM,MAAM,GAAG,QAAQ;EACvD,KAAK,IAAI,MAAM,GAAG,QAAQ,OAAO;EACjC,MAAM,KAAK,MAAM,EAAE,MAAM,MAAM,GAAG,QAAQ;GAE5C,QAAQ,gBACL,QAAQ,MAAM;AACnB;yDACyD,GACzD,YAAY,SAAS,MAAM,MAAM,EAAE,QAAQ,MAAM,KAAK,MAAM,GAAG,QAAQ,MAAM;AAqB7E;;;;;iBAKiB,GACjB,YAAY,UAAU,KAAK,MAAM,UAAU,WAAW;EACpD,wDAAwD,GACxD,QAAQ;EACR;yDACuD,GACvD,gBAAgB,QAAQ,MAAM;EAC9B;kDACgD,GAChD,OAAO,MAAM;EACb,8CAA8C,GAC9C,gBAAgB;EAChB;;qDAEmD,GACnD,WAAW,UAAU,MAAM,KAAK,QAAQ,KAAK,QAAQ;EACrD,mEAAmE,GACnE,cAAc,KAAK,MAAM,EAAE,MAAM,SAAS,QAAQ,IAAI,IAAI,SAAS;EACnE,gEAAgE,GAChE,OAAO;EACP;;yEAEuE,GACvE,SAAS,MAAM,MAAM,QAAQ,aAAa,QAAQ,OAAO;EACzD,0CAA0C,GAC1C,QAAQ;;AAIV;gFACgF,GAChF,OAAO,YAAI,UACT,QAAQ,MAAM,EACd,UAAU,UACV,KAAK,QACL,OAAO,QACP,UAAU,UACV,OAAO,OACP,OAAM,YACL,QAAQ,QAmRV;AAYD,wDAAwD,GACxD,OAAO,YAAI,OAAQ,UAAU,aAAW,MAAM,CAAiC;KAqC1E,aAAa,KAAK,MAAM,QAAQ;EACnC,aAAa,YAAY,KAAK;IAC5B,YAAY,OAAO,MAAM,EAAE,OAAO;;;AAItC;kEACkE,GAClE,OAAO,YAAI,aACT,oBAAoB,YACpB,OAAM,KAAK,SAAS,UAAU,WAAW,eACxC,WAiBD;AAEF;mEACmE,GACnE,OAAO,YAAI,OACT,UAAU,UACV,KAAK,QACL,UAAU,UACV,OAAO,OACP,OAAM,YACL,KA2CD"}
@@ -0,0 +1,25 @@
1
+ import { type Declared } from "./scan.js";
2
+ /** What a REPL carries from one cell to the next, kept by its host. */ export type Carried = {
3
+ /** the names whose values the facet's storage holds */ values: string[];
4
+ /** each function and class declared, by name */ declarations: Record<string, string>;
5
+ };
6
+ export declare let EMPTY: Carried;
7
+ /** What a cell's own code declares, kept beside it for `carry` and `settle`. */ export declare let cellOf: (modules: Record<string, string>) => Declared;
8
+ /** The cell's modules with `declared`'s reading of its code beside them. */ export declare let described: (modules: Record<string, string>) => Record<string, string>;
9
+ /** The cell's modules as its Worker loads them, declaring first what the
10
+ * REPL carries and the cell does not declare again: each kept value by its name, then each earlier
11
+ * function and class. Its own names and the carried ones are read back when
12
+ * it ends, whichever were bound. */ export declare let carry: (modules: Record<string, string>, carried: Carried) => Record<string, string>;
13
+ /** What the REPL carries after a cell, and the cell's answer without its
14
+ * bookkeeping. A name the cell bound again as a value is no longer a
15
+ * declaration, and one it declared is no longer a value. */ export declare let settle: (carried: Carried, modules: Record<string, string>, text: string) => {
16
+ carried: Carried;
17
+ text: string;
18
+ };
19
+ /** Where a host keeps what its REPL carries. */ export type Keeping = {
20
+ read(): Carried | undefined;
21
+ write(carried: Carried): void;
22
+ };
23
+ /** How a REPL's host runs each cell: declared with what the REPL carries,
24
+ * run by `run` as the REPL's facet, and settled into what it carries next. */ export declare let cells: (kept: Keeping, run: (modules: Record<string, string>) => Promise<string>) => any;
25
+ //# sourceMappingURL=repl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repl.d.ts","sources":["../repl.ts"],"names":[],"mappings":"AAOA,SAAS,KAAK,QAAQ,oBAA6B;AAGnD,qEAAqE,GACrE,YAAY;EACV,qDAAqD,GACrD,QAAQ,MAAM;EACd,8CAA8C,GAC9C,cAAc,OAAO,MAAM,EAAE,MAAM;;AAGrC,OAAO,YAAI,OAAO,QAA0C;AAK5D,8EAA8E,GAC9E,OAAO,YAAI,SAAU,SAAS,OAAO,MAAM,EAAE,MAAM,MAAI,SACQ;AAE/D,0EAA0E,GAC1E,OAAO,YAAI,YACT,SAAS,OAAO,MAAM,EAAE,MAAM,MAC7B,OAAO,MAAM,EAAE,MAAM,EAIvB;AAED;;;kCAGkC,GAClC,OAAO,YAAI,QACT,SAAS,OAAO,MAAM,EAAE,MAAM,GAC9B,SAAS,YACR,OAAO,MAAM,EAAE,MAAM,EAsBvB;AAED;;0DAE0D,GAC1D,OAAO,YAAI,SACT,SAAS,SACT,SAAS,OAAO,MAAM,EAAE,MAAM,GAC9B,MAAM,MAAM;EACT,SAAS;EAAS,MAAM,MAAM;EAiBlC;AAED,8CAA8C,GAC9C,YAAY;EACV,QAAQ,UAAU,SAAS;EAC3B,MAAM,SAAS,UAAU,IAAI;;AAG/B;4EAC4E,GAC5E,OAAO,YAAI,QACT,MAAM,SACN,MAAM,SAAS,OAAO,MAAM,EAAE,MAAM,MAAM,QAAQ,MAAM,UAQzD"}
@@ -0,0 +1,5 @@
1
+ export type Declared = {
2
+ /** names bound by `let`, `const` and `var` */ names: string[];
3
+ /** each `function` and `class` declaration's source, by its name */ declarations: Record<string, string>;
4
+ };
5
+ //# sourceMappingURL=scan.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scan.d.ts","sources":["../scan.ts"],"names":[],"mappings":"AAUA,YAAY;EACV,4CAA4C,GAC5C,OAAO,MAAM;EACb,kEAAkE,GAClE,cAAc,OAAO,MAAM,EAAE,MAAM"}
@@ -0,0 +1,25 @@
1
+ import type { Strip } from "./mod.js";
2
+ import type { Entry } from "./types.js";
3
+ export declare let timedOut: (wallMs: number) => string;
4
+ /** What each limit says, with what to do instead. */ export declare let TOO: {
5
+ readonly script: any;
6
+ readonly args: string;
7
+ readonly calls: any;
8
+ readonly system: any;
9
+ };
10
+ /** What a script is given beside its tools. */ export type Given = {
11
+ wallMs?: number;
12
+ /** `fs`, over /tmp and the app mount */ files?: boolean;
13
+ /** puppeteer's module, as `puppeteer.js`, for a script given `browser`: it
14
+ * launches on the evaluator's `env.BROWSER`, and every browser it launched
15
+ * is closed when the run ends */ browser?: string;
16
+ /** a REPL's cell: the Worker exports `Cell`, a Durable Object class whose
17
+ * storage is the REPL's, and keeps the cell's top-level values there
18
+ * (./repl.ts) */ cell?: boolean;
19
+ };
20
+ /** Where a cell keeps its top-level values, in its storage's kv. */ export declare let VALUES: string;
21
+ /** Where ./repl.ts `carry` declares what a cell carries, before its code. */ export declare let CARRIED: string;
22
+ /** User code lives in its own module, its TypeScript read as JavaScript by
23
+ * the host's `strip`. The trusted entrypoint loads it inside its catch, with
24
+ * no bindings and no lexical access to the bridge. */ export declare let source: (script: string, entries: Entry[], most: number, strip: Strip, _dts_1: never) => Promise<Record<string, string>>;
25
+ //# sourceMappingURL=source.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"source.d.ts","sources":["../source.ts"],"names":[],"mappings":"AAAA,cAAc,KAAK,mBAAkB;AACrC,cAAc,KAAK,qBAAoB;AAGvC,OAAO,YAAI,WAAY,QAAQ,MAAM,YACU;AAE/C,mDAAmD,GACnD,OAAO,YAAI;WACT;WAEA;WACA;WAEA;EAED;AAED,6CAA6C,GAC7C,YAAY;EACV,SAAS,MAAM;EACf,sCAAsC,GACtC,QAAQ,OAAO;EACf;;iCAE+B,GAC/B,UAAU,MAAM;EAChB;;iBAEe,GACf,OAAO,OAAO;;AAGhB,kEAAkE,GAClE,OAAO,YAAI,eAAuB;AAQlC,2EAA2E,GAC3E,OAAO,YAAI,gBAAuB;AAElC;;oDAEoD,GACpD,OAAO,YAAI,SACT,QAAQ,MAAM,EACd,SAAS,SACT,MAAM,MAAM,EACZ,OAAO,OACP,kBACC,QAAQ,OAAO,MAAM,EAAE,MAAM,GAgG9B"}
@@ -0,0 +1,8 @@
1
+ import type { Description, Registry } from "@yaks/tools";
2
+ export type Entry = Description & {
3
+ path: [string, string];
4
+ };
5
+ /** Names are preserved as object keys, including punctuation; bracket notation
6
+ * gives every registry name one unambiguous path without alias collisions. */ export declare let catalog: (registry: Registry) => Entry[];
7
+ /** Declarations are generated from the same schemas that discovery serves. */ export declare let declarations: (entries: Entry[]) => string;
8
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sources":["../types.ts"],"names":[],"mappings":"AACA,cAAc,WAAW,EAAE,QAAQ,2BAAgC;AA8DnE,YAAY,QAAQ;EAAgB,OAAO,MAAM,EAAE,MAAM;;AACzD;4EAC4E,GAC5E,OAAO,YAAI,UAAW,UAAU,aAAW,QAGY;AAEvD,4EAA4E,GAC5E,OAAO,YAAI,eAAgB,SAAS,YAAU,MAAM,CAYnD"}
@@ -0,0 +1,5 @@
1
+ import type { VocabDoc } from "@yaks/vocab";
2
+ /** The code mode vocabulary, in the form `loadVocab` accepts. */ export declare let codeModeDoc: VocabDoc;
3
+ /** What this package is: its manifest's description. */ export declare let description: string;
4
+ /** Every document this plugin declares. */ export declare let docs: VocabDoc[];
5
+ //# sourceMappingURL=vocab.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vocab.d.ts","sources":["../vocab.ts"],"names":[],"mappings":"AAEA,cAAc,QAAQ,2BAAgC;AAItD,+DAA+D,GAC/D,OAAO,YAAI,aAAa,SAA0B;AAElD,sDAAsD,GACtD,OAAO,YAAI,aAAa,MAAM,CAAuB;AAErD,yCAAyC,GACzC,OAAO,YAAI,MAAM,WAA0B"}
package/deno.json ADDED
@@ -0,0 +1 @@
1
+ {"publish":{"exclude":["**/*_test.ts","testing.ts"]},"name":"@yaks/code-mode","version":"0.2.36","license":"Apache-2.0","description":"Typed tool objects from a scoped registry, bounded short script execution and recorded nested calls through an isolated evaluator.","exports":{".":"./mod.ts","./source":"./source.ts","./repl":"./repl.ts","./vocab":"./vocab.ts"},"imports":{"@yaks/code-mode":"./mod.ts","@yaks/code-mode/source":"./source.ts","@yaks/code-mode/repl":"./repl.ts","@yaks/code-mode/vocab":"./vocab.ts"}}
package/files.js ADDED
@@ -0,0 +1,88 @@
1
+ // The script's two mounts, and its browser. Workerd owns the request-local
2
+ // /tmp filesystem; the app mount sees its draft through the caller's recorded
3
+ // tool calls.
4
+ export const FILE_BYTES = 1024 * 1024;
5
+ export let fileDeclarations = `
6
+ declare const fs: {
7
+ readFile(path: string): Promise<Uint8Array>
8
+ readFile(path: string, encoding: 'utf8' | { encoding: 'utf8' }): Promise<string>
9
+ writeFile(path: string, data: string | Uint8Array): Promise<void>
10
+ readdir(path: string): Promise<string[]>
11
+ unlink(path: string): Promise<void>
12
+ mkdir(path: string, options?: { recursive?: boolean }): Promise<void>
13
+ }`;
14
+ export let browserDeclarations = `
15
+ /** A puppeteer Browser (@cloudflare/puppeteer) on Cloudflare's headless Chrome. */
16
+ declare const browser: {
17
+ launch(options?: { keep_alive?: number }): Promise<import('@cloudflare/puppeteer').Browser>
18
+ }`;
19
+ export let fileModule = `import * as tmp from 'node:fs/promises';
20
+ import { Buffer } from 'node:buffer';
21
+
22
+ function locate(path) {
23
+ if (typeof path !== 'string' || path.includes('\\0') || path.includes('\\\\')) {
24
+ throw new TypeError('fs takes an absolute /tmp or /apps/<app> path');
25
+ }
26
+ let parts = path.split('/');
27
+ let [, mount, app, ...file] = parts;
28
+ if (parts[0] || !['tmp', 'apps'].includes(mount) || parts.includes('..') ||
29
+ (mount === 'apps' && !/^[a-z0-9][a-z0-9-]*$/.test(app ?? ''))) {
30
+ throw new TypeError('fs takes an absolute /tmp or /apps/<app> path without ..');
31
+ }
32
+ return mount === 'tmp' ? null : {app, path: file.filter(p => p && p !== '.').join('/')};
33
+ }
34
+
35
+ export function filesystem(call) {
36
+ async function appFile(at, op, args) {
37
+ let result = await call(at.app, JSON.stringify({op, path: at.path || undefined, ...args}));
38
+ if (result.isError) throw new Error(result.content.map(c => c.text).join('\\n'));
39
+ return result.structuredContent;
40
+ }
41
+ function file(at, path) {
42
+ if (!at.path) throw new Error('EISDIR: ' + path);
43
+ return at;
44
+ }
45
+ return {
46
+ async readFile(path, options) {
47
+ let at = locate(path);
48
+ if (!at) return tmp.readFile(path, options);
49
+ let encoding = typeof options === 'string' ? options : options?.encoding;
50
+ let result = await appFile(file(at, path), 'read', {encoding: 'base64'});
51
+ let data = Buffer.from(result.base64, 'base64');
52
+ return encoding == null ? data : data.toString(encoding);
53
+ },
54
+ async writeFile(path, data) {
55
+ let at = locate(path);
56
+ if (!at) return tmp.writeFile(path, data);
57
+ if (typeof data !== 'string' && !ArrayBuffer.isView(data)) {
58
+ throw new TypeError('fs.writeFile takes a string or bytes');
59
+ }
60
+ let bytes = Buffer.from(data);
61
+ if (bytes.length > ${FILE_BYTES}) throw new Error('app files are limited to 1 MiB per fs write');
62
+ await appFile(file(at, path), 'write', {base64: bytes.toString('base64')});
63
+ },
64
+ async readdir(path) {
65
+ let at = locate(path);
66
+ if (!at) return tmp.readdir(path);
67
+ let {files} = await appFile(at, 'list', {path: undefined});
68
+ let prefix = at.path ? at.path + '/' : '';
69
+ let entries = files.filter(f => f.path.startsWith(prefix))
70
+ .map(f => f.path.slice(prefix.length).split('/')[0]);
71
+ if (at.path && !entries.length) {
72
+ let code = files.some(f => f.path === at.path) ? 'ENOTDIR' : 'ENOENT';
73
+ throw new Error(code + ': ' + path);
74
+ }
75
+ return [...new Set(entries)].sort();
76
+ },
77
+ async unlink(path) {
78
+ let at = locate(path);
79
+ if (!at) return tmp.unlink(path);
80
+ await appFile(file(at, path), 'delete');
81
+ },
82
+ async mkdir(path, options) {
83
+ if (locate(path)) throw new Error('app directories are created by writing a file in them');
84
+ return tmp.mkdir(path, options);
85
+ },
86
+ };
87
+ }`;
88
+ //# sourceMappingURL=files.js.map
package/files.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"files.js","sources":["./files.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,8EAA8E;AAC9E,cAAc;AACd,OAAO,MAAM,aAAa,OAAO,KAAI;AAIrC,OAAO,IAAI,mBAAmB,CAAC;;;;;;;;CAQ9B,CAAC,CAAA;AAEF,OAAO,IAAI,sBAAsB,CAAC;;;;CAIjC,CAAC,CAAA;AAEF,OAAO,IAAI,aAAa,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;yBA0CA,EAAE,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;CA0BrC,CAAC,CAAA"}