@opencode/codemode 2.2.6 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (197) hide show
  1. package/README.md +115 -29
  2. package/dist/{vm/async.d.ts → async.d.ts} +1 -1
  3. package/dist/codemode.d.ts +13 -22
  4. package/dist/codemode.js +18 -39
  5. package/dist/data.d.ts +4 -19
  6. package/dist/data.js +1 -82
  7. package/dist/extension.d.ts +20 -1
  8. package/dist/extension.js +14 -1
  9. package/dist/{vm/host.d.ts → host.d.ts} +5 -2
  10. package/dist/{vm/host.js → host.js} +9 -4
  11. package/dist/index.d.ts +1 -1
  12. package/dist/{vm/opcodes.d.ts → opcodes.d.ts} +1 -1
  13. package/dist/{vm/prelude → prelude}/helpers.js +1 -1
  14. package/dist/{vm/runtime → runtime}/driver.d.ts +18 -8
  15. package/dist/{vm/runtime → runtime}/driver.js +90 -20
  16. package/dist/{vm/runtime → runtime}/errors.js +2 -2
  17. package/dist/{vm/runtime → runtime}/execute.d.ts +18 -9
  18. package/dist/{vm/runtime → runtime}/execute.js +45 -15
  19. package/dist/{vm/runtime → runtime}/extensions.d.ts +2 -2
  20. package/dist/{vm/runtime → runtime}/extensions.js +121 -19
  21. package/dist/{vm/runtime → runtime}/globals.js +1 -1
  22. package/dist/{vm/runtime → runtime}/interpreter.d.ts +4 -1
  23. package/dist/{vm/runtime → runtime}/interpreter.js +2 -0
  24. package/dist/{vm/runtime → runtime}/model.d.ts +1 -1
  25. package/dist/{vm/runtime → runtime}/objects.d.ts +1 -1
  26. package/dist/{vm/runtime → runtime}/objects.js +1 -1
  27. package/dist/{vm/runtime → runtime}/operations.d.ts +1 -1
  28. package/dist/{vm/runtime → runtime}/operations.js +1 -1
  29. package/dist/scan.js +2 -2
  30. package/dist/{vm/scheduler.d.ts → scheduler.d.ts} +16 -4
  31. package/dist/{vm/scheduler.js → scheduler.js} +13 -2
  32. package/dist/{vm/snapshot → snapshot}/codec.d.ts +37 -6
  33. package/dist/{vm/snapshot → snapshot}/codec.js +112 -8
  34. package/dist/{vm/snapshot → snapshot}/snapshot.d.ts +13 -6
  35. package/dist/{vm/snapshot → snapshot}/snapshot.js +19 -4
  36. package/dist/{vm/snapshot.js → snapshot.js} +5 -2
  37. package/dist/stdlib/array.d.ts +14 -9
  38. package/dist/stdlib/array.js +89 -276
  39. package/dist/stdlib/bytes.d.ts +11 -7
  40. package/dist/stdlib/bytes.js +112 -79
  41. package/dist/stdlib/collections.d.ts +7 -7
  42. package/dist/stdlib/collections.js +30 -339
  43. package/dist/stdlib/console.d.ts +2 -2
  44. package/dist/stdlib/console.js +3 -3
  45. package/dist/stdlib/date.d.ts +2 -2
  46. package/dist/stdlib/date.js +21 -30
  47. package/dist/stdlib/headers.d.ts +2 -2
  48. package/dist/stdlib/headers.js +15 -33
  49. package/dist/stdlib/iterator.d.ts +2 -2
  50. package/dist/stdlib/iterator.js +10 -303
  51. package/dist/stdlib/json.d.ts +2 -2
  52. package/dist/stdlib/json.js +15 -31
  53. package/dist/stdlib/math.d.ts +2 -7
  54. package/dist/stdlib/math.js +6 -30
  55. package/dist/stdlib/number.d.ts +3 -3
  56. package/dist/stdlib/number.js +8 -8
  57. package/dist/stdlib/object.d.ts +4 -4
  58. package/dist/stdlib/object.js +12 -30
  59. package/dist/stdlib/regexp.d.ts +6 -5
  60. package/dist/stdlib/regexp.js +18 -13
  61. package/dist/stdlib/string.d.ts +2 -2
  62. package/dist/stdlib/string.js +53 -53
  63. package/dist/stdlib/url.d.ts +21 -9
  64. package/dist/stdlib/url.js +55 -55
  65. package/dist/stdlib/value.d.ts +3 -4
  66. package/dist/stdlib/value.js +5 -6
  67. package/dist/stdlib/web.d.ts +4 -4
  68. package/dist/stdlib/web.js +7 -7
  69. package/dist/tool-runtime.d.ts +34 -12
  70. package/dist/tool-runtime.js +350 -68
  71. package/dist/tool-schema.d.ts +5 -0
  72. package/dist/tool-schema.js +36 -16
  73. package/dist/tool.d.ts +60 -2
  74. package/dist/tool.js +17 -1
  75. package/dist/{vm/vm.d.ts → vm.d.ts} +4 -3
  76. package/dist/{vm/vm.js → vm.js} +1 -1
  77. package/package.json +5 -7
  78. package/dist/interpreter/callback.d.ts +0 -24
  79. package/dist/interpreter/callback.js +0 -86
  80. package/dist/interpreter/errors.js +0 -173
  81. package/dist/interpreter/execute.d.ts +0 -14
  82. package/dist/interpreter/execute.js +0 -207
  83. package/dist/interpreter/extensions.d.ts +0 -9
  84. package/dist/interpreter/extensions.js +0 -248
  85. package/dist/interpreter/generators.d.ts +0 -3
  86. package/dist/interpreter/generators.js +0 -168
  87. package/dist/interpreter/globals.js +0 -144
  88. package/dist/interpreter/interpreter.d.ts +0 -48
  89. package/dist/interpreter/interpreter.js +0 -2253
  90. package/dist/interpreter/intrinsics.d.ts +0 -15
  91. package/dist/interpreter/intrinsics.js +0 -105
  92. package/dist/interpreter/model.d.ts +0 -68
  93. package/dist/interpreter/model.js +0 -54
  94. package/dist/interpreter/native.d.ts +0 -17
  95. package/dist/interpreter/native.js +0 -35
  96. package/dist/interpreter/objects.d.ts +0 -301
  97. package/dist/interpreter/objects.js +0 -592
  98. package/dist/interpreter/promises.d.ts +0 -18
  99. package/dist/interpreter/promises.js +0 -292
  100. package/dist/interpreter/runner.d.ts +0 -188
  101. package/dist/interpreter/runner.js +0 -492
  102. package/dist/interpreter/scope.d.ts +0 -16
  103. package/dist/interpreter/scope.js +0 -79
  104. package/dist/suspend-error.d.ts +0 -23
  105. package/dist/suspend-error.js +0 -25
  106. package/dist/vm/data.d.ts +0 -7
  107. package/dist/vm/data.js +0 -13
  108. package/dist/vm/index.d.ts +0 -6
  109. package/dist/vm/index.js +0 -6
  110. package/dist/vm/runtime/errors.d.ts +0 -23
  111. package/dist/vm/runtime/globals.d.ts +0 -6
  112. package/dist/vm/runtime/limits.d.ts +0 -10
  113. package/dist/vm/runtime/limits.js +0 -19
  114. package/dist/vm/runtime/modules.d.ts +0 -4
  115. package/dist/vm/runtime/modules.js +0 -33
  116. package/dist/vm/runtime/references.d.ts +0 -8
  117. package/dist/vm/runtime/references.js +0 -51
  118. package/dist/vm/stdlib/array.d.ts +0 -16
  119. package/dist/vm/stdlib/array.js +0 -311
  120. package/dist/vm/stdlib/bytes.d.ts +0 -11
  121. package/dist/vm/stdlib/bytes.js +0 -222
  122. package/dist/vm/stdlib/collections.d.ts +0 -7
  123. package/dist/vm/stdlib/collections.js +0 -188
  124. package/dist/vm/stdlib/console.d.ts +0 -6
  125. package/dist/vm/stdlib/console.js +0 -93
  126. package/dist/vm/stdlib/date.d.ts +0 -2
  127. package/dist/vm/stdlib/date.js +0 -123
  128. package/dist/vm/stdlib/headers.d.ts +0 -2
  129. package/dist/vm/stdlib/headers.js +0 -92
  130. package/dist/vm/stdlib/iterator.d.ts +0 -2
  131. package/dist/vm/stdlib/iterator.js +0 -30
  132. package/dist/vm/stdlib/json.d.ts +0 -3
  133. package/dist/vm/stdlib/json.js +0 -42
  134. package/dist/vm/stdlib/math.d.ts +0 -3
  135. package/dist/vm/stdlib/math.js +0 -73
  136. package/dist/vm/stdlib/number.d.ts +0 -3
  137. package/dist/vm/stdlib/number.js +0 -72
  138. package/dist/vm/stdlib/object.d.ts +0 -6
  139. package/dist/vm/stdlib/object.js +0 -201
  140. package/dist/vm/stdlib/regexp.d.ts +0 -8
  141. package/dist/vm/stdlib/regexp.js +0 -119
  142. package/dist/vm/stdlib/string.d.ts +0 -2
  143. package/dist/vm/stdlib/string.js +0 -272
  144. package/dist/vm/stdlib/url.d.ts +0 -25
  145. package/dist/vm/stdlib/url.js +0 -255
  146. package/dist/vm/stdlib/value.d.ts +0 -6
  147. package/dist/vm/stdlib/value.js +0 -32
  148. package/dist/vm/stdlib/web.d.ts +0 -5
  149. package/dist/vm/stdlib/web.js +0 -97
  150. /package/dist/{vm/async.js → async.js} +0 -0
  151. /package/dist/{vm/code.d.ts → code.d.ts} +0 -0
  152. /package/dist/{vm/code.js → code.js} +0 -0
  153. /package/dist/{vm/compiler → compiler}/compile.d.ts +0 -0
  154. /package/dist/{vm/compiler → compiler}/compile.js +0 -0
  155. /package/dist/{vm/compiler → compiler}/scope.d.ts +0 -0
  156. /package/dist/{vm/compiler → compiler}/scope.js +0 -0
  157. /package/dist/{vm/generators.d.ts → generators.d.ts} +0 -0
  158. /package/dist/{vm/generators.js → generators.js} +0 -0
  159. /package/dist/{vm/internal-prelude.d.ts → internal-prelude.d.ts} +0 -0
  160. /package/dist/{vm/internal-prelude.js → internal-prelude.js} +0 -0
  161. /package/dist/{vm/opcodes.js → opcodes.js} +0 -0
  162. /package/dist/{vm/prelude → prelude}/bytecode.d.ts +0 -0
  163. /package/dist/{vm/prelude → prelude}/bytecode.js +0 -0
  164. /package/dist/{vm/prelude → prelude}/bytecode.json +0 -0
  165. /package/dist/{vm/prelude → prelude}/helpers.d.ts +0 -0
  166. /package/dist/{vm/prelude → prelude}/prelude.d.ts +0 -0
  167. /package/dist/{vm/prelude → prelude}/prelude.js +0 -0
  168. /package/dist/{vm/prelude → prelude}/source.d.ts +0 -0
  169. /package/dist/{vm/prelude → prelude}/source.js +0 -0
  170. /package/dist/{vm/runtime → runtime}/callback.d.ts +0 -0
  171. /package/dist/{vm/runtime → runtime}/callback.js +0 -0
  172. /package/dist/{interpreter → runtime}/errors.d.ts +0 -0
  173. /package/dist/{vm/runtime → runtime}/generators.d.ts +0 -0
  174. /package/dist/{vm/runtime → runtime}/generators.js +0 -0
  175. /package/dist/{interpreter → runtime}/globals.d.ts +0 -0
  176. /package/dist/{vm/runtime → runtime}/intrinsic-names.d.ts +0 -0
  177. /package/dist/{vm/runtime → runtime}/intrinsic-names.js +0 -0
  178. /package/dist/{vm/runtime → runtime}/intrinsics.d.ts +0 -0
  179. /package/dist/{vm/runtime → runtime}/intrinsics.js +0 -0
  180. /package/dist/{interpreter → runtime}/limits.d.ts +0 -0
  181. /package/dist/{interpreter → runtime}/limits.js +0 -0
  182. /package/dist/{vm/runtime → runtime}/model.js +0 -0
  183. /package/dist/{interpreter → runtime}/modules.d.ts +0 -0
  184. /package/dist/{interpreter → runtime}/modules.js +0 -0
  185. /package/dist/{vm/runtime → runtime}/native.d.ts +0 -0
  186. /package/dist/{vm/runtime → runtime}/native.js +0 -0
  187. /package/dist/{vm/runtime → runtime}/promises.d.ts +0 -0
  188. /package/dist/{vm/runtime → runtime}/promises.js +0 -0
  189. /package/dist/{interpreter → runtime}/references.d.ts +0 -0
  190. /package/dist/{interpreter → runtime}/references.js +0 -0
  191. /package/dist/{vm/runtime → runtime}/signals.d.ts +0 -0
  192. /package/dist/{vm/runtime → runtime}/signals.js +0 -0
  193. /package/dist/{vm/runtime → runtime}/source.d.ts +0 -0
  194. /package/dist/{vm/runtime → runtime}/source.js +0 -0
  195. /package/dist/{vm/runtime → runtime}/table.d.ts +0 -0
  196. /package/dist/{vm/runtime → runtime}/table.js +0 -0
  197. /package/dist/{vm/snapshot.d.ts → snapshot.d.ts} +0 -0
@@ -1,144 +0,0 @@
1
- import { Arr, Callable, coerceToInteger, coerceToString, get, Obj } from "./objects.js";
2
- import { arrayGlobal } from "../stdlib/array.js";
3
- import { textDecoderGlobal, textEncoderGlobal, uint8ArrayGlobal } from "../stdlib/bytes.js";
4
- import { mapGlobal, setGlobal, weakMapGlobal, weakSetGlobal } from "../stdlib/collections.js";
5
- import { consoleGlobal } from "../stdlib/console.js";
6
- import { dateGlobal } from "../stdlib/date.js";
7
- import { jsonGlobal } from "../stdlib/json.js";
8
- import { mathGlobal } from "../stdlib/math.js";
9
- import { booleanGlobal, numberGlobal } from "../stdlib/number.js";
10
- import { objectGlobal } from "../stdlib/object.js";
11
- import { regexpGlobal } from "../stdlib/regexp.js";
12
- import { stringGlobal } from "../stdlib/string.js";
13
- import { uriGlobal, urlGlobal, urlSearchParamsGlobal } from "../stdlib/url.js";
14
- import { headersGlobal } from "../stdlib/headers.js";
15
- import { iteratorGlobals } from "../stdlib/iterator.js";
16
- import { coercion } from "../stdlib/value.js";
17
- import { base64Global, cryptoGlobal, structuredCloneGlobal } from "../stdlib/web.js";
18
- import { ToolReference } from "../tool-runtime.js";
19
- import { errorGlobal } from "./errors.js";
20
- import { errorTypes } from "./intrinsics.js";
21
- import { constants, constructor, methods, native, receiver } from "./native.js";
22
- import { AsyncIteratorSymbol, IteratorSymbol, typeError } from "./model.js";
23
- import { checkArrayLength } from "./limits.js";
24
- import { generatorGlobals } from "./generators.js";
25
- import { promiseGlobal } from "./promises.js";
26
- // Function.prototype.constructor exists so `fn.constructor === Function` holds; dynamic code is unsupported.
27
- const functionGlobal = (ctx) => {
28
- const reject = () => {
29
- throw typeError("The Function constructor is not supported; write the function inline.");
30
- };
31
- const target = (thisValue, method) => receiver(Callable, thisValue, `Function.prototype.${method}`);
32
- methods(ctx.builtins, ctx.builtins.Function, [
33
- ["call", 1, (thisValue, args, site) => ctx.call(target(thisValue, "call"), args[0], args.slice(1), site)],
34
- [
35
- "apply",
36
- 2,
37
- (thisValue, args, site) => ctx.call(target(thisValue, "apply"), args[0], listFromArrayLike(args[1]), site),
38
- ],
39
- [
40
- "bind",
41
- 1,
42
- (thisValue, args) => {
43
- const fn = target(thisValue, "bind");
44
- const bound = args.slice(1);
45
- return native(ctx.builtins, {
46
- name: `bound ${coerceToString(get(fn, "name"))}`,
47
- length: Math.max(0, fn.length - bound.length),
48
- call: (_, rest, site) => ctx.call(fn, args[0], [...bound, ...rest], site),
49
- });
50
- },
51
- ],
52
- ]);
53
- return constructor(ctx.builtins, ctx.builtins.Function, {
54
- name: "Function",
55
- length: 1,
56
- call: reject,
57
- construct: reject,
58
- });
59
- };
60
- // CreateListFromArrayLike: `apply` reads `length` and the indexed properties of any object.
61
- const listFromArrayLike = (value) => {
62
- if (value === undefined || value === null)
63
- return [];
64
- if (value instanceof Arr)
65
- return [...value.items];
66
- if (!(value instanceof Obj))
67
- throw typeError("Function.prototype.apply expects an array-like argument list.");
68
- const length = Math.max(0, coerceToInteger(get(value, "length")));
69
- checkArrayLength(length);
70
- return Array.from({ length }, (_, index) => get(value, String(index)));
71
- };
72
- const symbolGlobal = (ctx) => {
73
- const symbol = native(ctx.builtins, {
74
- name: "Symbol",
75
- call: () => {
76
- throw typeError("Symbol is not callable; only Symbol.asyncIterator and Symbol.iterator are available.");
77
- },
78
- callback: false,
79
- });
80
- constants(symbol, { asyncIterator: AsyncIteratorSymbol, iterator: IteratorSymbol });
81
- return symbol;
82
- };
83
- // A table rather than a list so the names are known before any runtime exists.
84
- const table = {
85
- tools: () => new ToolReference([]),
86
- search: (ctx) => native(ctx.builtins, { name: "search", call: (_, args) => ctx.search(args), callback: false }),
87
- require: (ctx) => native(ctx.builtins, {
88
- name: "require",
89
- length: 1,
90
- call: (_, args, site) => {
91
- const specifier = args[0];
92
- if (typeof specifier !== "string")
93
- throw typeError("require expects a module name string.");
94
- return ctx.module(specifier, site);
95
- },
96
- }),
97
- undefined: () => undefined,
98
- NaN: () => NaN,
99
- Infinity: () => Infinity,
100
- Object: (ctx) => objectGlobal(ctx),
101
- Function: (ctx) => functionGlobal(ctx),
102
- Array: (ctx) => arrayGlobal(ctx),
103
- Math: (ctx) => mathGlobal(ctx),
104
- JSON: (ctx) => jsonGlobal(ctx),
105
- console: (ctx) => consoleGlobal(ctx),
106
- Promise: (ctx) => promiseGlobal(ctx),
107
- Symbol: (ctx) => symbolGlobal(ctx),
108
- Iterator: (ctx) => iteratorGlobals(ctx),
109
- Number: (ctx) => numberGlobal(ctx),
110
- String: (ctx) => stringGlobal(ctx),
111
- Boolean: (ctx) => booleanGlobal(ctx),
112
- parseInt: (ctx) => coercion(ctx, "parseInt", 2),
113
- parseFloat: (ctx) => coercion(ctx, "parseFloat"),
114
- isFinite: (ctx) => coercion(ctx, "isFinite"),
115
- isNaN: (ctx) => coercion(ctx, "isNaN"),
116
- Date: (ctx) => dateGlobal(ctx),
117
- RegExp: (ctx) => regexpGlobal(ctx),
118
- Map: (ctx) => mapGlobal(ctx),
119
- Set: (ctx) => setGlobal(ctx),
120
- WeakMap: (ctx) => weakMapGlobal(ctx),
121
- WeakSet: (ctx) => weakSetGlobal(ctx),
122
- URL: (ctx) => urlGlobal(ctx),
123
- URLSearchParams: (ctx) => urlSearchParamsGlobal(ctx),
124
- Headers: (ctx) => headersGlobal(ctx),
125
- Uint8Array: (ctx) => uint8ArrayGlobal(ctx),
126
- TextEncoder: (ctx) => textEncoderGlobal(ctx),
127
- TextDecoder: (ctx) => textDecoderGlobal(ctx),
128
- encodeURI: (ctx) => uriGlobal(ctx, "encodeURI"),
129
- encodeURIComponent: (ctx) => uriGlobal(ctx, "encodeURIComponent"),
130
- decodeURI: (ctx) => uriGlobal(ctx, "decodeURI"),
131
- decodeURIComponent: (ctx) => uriGlobal(ctx, "decodeURIComponent"),
132
- atob: (ctx) => base64Global(ctx, "atob"),
133
- btoa: (ctx) => base64Global(ctx, "btoa"),
134
- crypto: (ctx) => cryptoGlobal(ctx),
135
- structuredClone: (ctx) => structuredCloneGlobal(ctx),
136
- ...Object.fromEntries(errorTypes.map((type) => [type, (ctx) => errorGlobal(type, ctx)])),
137
- };
138
- /** Names bound in every program before extensions apply. */
139
- export const globalNames = new Set(Object.keys(table));
140
- /** The immutable global bindings of every program, in declaration order. */
141
- export const globals = (ctx) => {
142
- generatorGlobals(ctx);
143
- return Object.entries(table).map(([name, factory]) => [name, factory(ctx)]);
144
- };
@@ -1,48 +0,0 @@
1
- import type { Program, TaggedTemplateExpression } from "acorn";
2
- import type { Context } from "effect";
3
- import { type Json } from "../data.js";
4
- import { type ToolRuntime } from "../tool-runtime.js";
5
- import { type AstNode } from "./model.js";
6
- import { type Builtins } from "./intrinsics.js";
7
- import { type Cursor, Arr, Obj, type Value } from "./objects.js";
8
- import { type Eval, Runner } from "./runner.js";
9
- /** One program execution: the tool bridge, job queue, captured logs, and the global scope built once. */
10
- export declare class Interpreter<R> {
11
- readonly tools: ToolRuntime<R>;
12
- readonly runner: Runner<R>;
13
- readonly builtins: Builtins;
14
- readonly logs: Array<string>;
15
- /** Template objects by site: a tag sees the same `strings` array every time its literal is evaluated, as in JS. */
16
- readonly templates: WeakMap<TaggedTemplateExpression, Arr>;
17
- private readonly root;
18
- private readonly globalScope;
19
- private readonly modules;
20
- private readonly namespaces;
21
- constructor(options: {
22
- readonly tools: ToolRuntime<R>;
23
- /** The caller's services, which host work runs with. */
24
- readonly services: Context.Context<R>;
25
- readonly builtins: Builtins;
26
- readonly logs?: Array<string>;
27
- readonly globals?: (ctx: Interpreter<R>) => ReadonlyArray<readonly [string, Value]>;
28
- });
29
- /** A module, as `require` returns it and a default import binds it: a global, by its Node module name. */
30
- module(specifier: string, site?: AstNode): Value;
31
- /**
32
- * What `import * as` and `import()` see: the module's own properties, and the module itself as `default`, the way
33
- * Node presents a CommonJS module.
34
- */
35
- namespace(specifier: string, site?: AstNode): Obj;
36
- /** The program's body, as the first job: its completion value, copied out for the host. */
37
- main(program: Program): Eval<Json | undefined>;
38
- /** Calls into the program; a built-in passes its own call site so failures inside are located there. */
39
- call(callable: Value, thisValue: Value, args: Array<Value>, site?: AstNode): Eval<Value>;
40
- /** Await: suspends the innermost async body until `value` settles. */
41
- awaitValue(value: Value, node?: AstNode): Eval<Value>;
42
- iterate(value: Value): Eval<Cursor | undefined>;
43
- iterateDirect(value: Value): Cursor;
44
- /** Runs one host call to completion before any other job: arguments cross as JSON, the result comes back as values. */
45
- tool(run: ToolRuntime<R>["search"], args: Array<Value>): Generator<import("./runner.js").Signal, Value, import("effect/Schema").Json | undefined>;
46
- /** The built-in search: its result is usable directly, and can also be awaited or chained like a Promise. */
47
- search(args: Array<Value>): Generator<import("./runner.js").Signal, Value, import("effect/Schema").Json | undefined>;
48
- }