@opencode/codemode 0.0.0-dev-1180 → 0.0.0-dev-1216

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 (91) hide show
  1. package/README.md +6 -12
  2. package/dist/codemode.d.ts +7 -21
  3. package/dist/codemode.js +17 -38
  4. package/dist/extension.d.ts +1 -1
  5. package/dist/index.d.ts +1 -1
  6. package/dist/scan.js +2 -2
  7. package/dist/tool-runtime.d.ts +8 -11
  8. package/dist/tool-runtime.js +13 -11
  9. package/dist/tool.d.ts +18 -9
  10. package/dist/tool.js +15 -23
  11. package/dist/vm/data.d.ts +1 -1
  12. package/dist/vm/runtime/execute.d.ts +16 -6
  13. package/dist/vm/runtime/execute.js +10 -7
  14. package/dist/vm/snapshot/codec.d.ts +3 -2
  15. package/dist/vm/snapshot/codec.js +3 -2
  16. package/dist/vm/snapshot/snapshot.d.ts +6 -3
  17. package/dist/vm/snapshot/snapshot.js +13 -2
  18. package/dist/vm/vm.d.ts +2 -2
  19. package/package.json +3 -5
  20. package/dist/data.d.ts +0 -21
  21. package/dist/data.js +0 -93
  22. package/dist/interpreter/callback.d.ts +0 -35
  23. package/dist/interpreter/callback.js +0 -98
  24. package/dist/interpreter/errors.d.ts +0 -23
  25. package/dist/interpreter/errors.js +0 -173
  26. package/dist/interpreter/execute.d.ts +0 -14
  27. package/dist/interpreter/execute.js +0 -207
  28. package/dist/interpreter/extensions.d.ts +0 -9
  29. package/dist/interpreter/extensions.js +0 -248
  30. package/dist/interpreter/generators.d.ts +0 -3
  31. package/dist/interpreter/generators.js +0 -168
  32. package/dist/interpreter/globals.d.ts +0 -6
  33. package/dist/interpreter/globals.js +0 -144
  34. package/dist/interpreter/interpreter.d.ts +0 -48
  35. package/dist/interpreter/interpreter.js +0 -2253
  36. package/dist/interpreter/intrinsics.d.ts +0 -15
  37. package/dist/interpreter/intrinsics.js +0 -105
  38. package/dist/interpreter/limits.d.ts +0 -10
  39. package/dist/interpreter/limits.js +0 -19
  40. package/dist/interpreter/model.d.ts +0 -68
  41. package/dist/interpreter/model.js +0 -54
  42. package/dist/interpreter/modules.d.ts +0 -4
  43. package/dist/interpreter/modules.js +0 -33
  44. package/dist/interpreter/native.d.ts +0 -17
  45. package/dist/interpreter/native.js +0 -35
  46. package/dist/interpreter/objects.d.ts +0 -301
  47. package/dist/interpreter/objects.js +0 -592
  48. package/dist/interpreter/promises.d.ts +0 -18
  49. package/dist/interpreter/promises.js +0 -292
  50. package/dist/interpreter/references.d.ts +0 -8
  51. package/dist/interpreter/references.js +0 -51
  52. package/dist/interpreter/runner.d.ts +0 -178
  53. package/dist/interpreter/runner.js +0 -480
  54. package/dist/interpreter/scope.d.ts +0 -16
  55. package/dist/interpreter/scope.js +0 -79
  56. package/dist/stdlib/array.d.ts +0 -11
  57. package/dist/stdlib/array.js +0 -498
  58. package/dist/stdlib/bytes.d.ts +0 -10
  59. package/dist/stdlib/bytes.js +0 -253
  60. package/dist/stdlib/collections.d.ts +0 -7
  61. package/dist/stdlib/collections.js +0 -497
  62. package/dist/stdlib/console.d.ts +0 -6
  63. package/dist/stdlib/console.js +0 -93
  64. package/dist/stdlib/date.d.ts +0 -2
  65. package/dist/stdlib/date.js +0 -132
  66. package/dist/stdlib/headers.d.ts +0 -2
  67. package/dist/stdlib/headers.js +0 -110
  68. package/dist/stdlib/iterator.d.ts +0 -2
  69. package/dist/stdlib/iterator.js +0 -322
  70. package/dist/stdlib/json.d.ts +0 -3
  71. package/dist/stdlib/json.js +0 -58
  72. package/dist/stdlib/math.d.ts +0 -8
  73. package/dist/stdlib/math.js +0 -97
  74. package/dist/stdlib/number.d.ts +0 -3
  75. package/dist/stdlib/number.js +0 -72
  76. package/dist/stdlib/object.d.ts +0 -6
  77. package/dist/stdlib/object.js +0 -219
  78. package/dist/stdlib/regexp.d.ts +0 -7
  79. package/dist/stdlib/regexp.js +0 -114
  80. package/dist/stdlib/string.d.ts +0 -2
  81. package/dist/stdlib/string.js +0 -272
  82. package/dist/stdlib/url.d.ts +0 -13
  83. package/dist/stdlib/url.js +0 -255
  84. package/dist/stdlib/value.d.ts +0 -7
  85. package/dist/stdlib/value.js +0 -33
  86. package/dist/stdlib/web.d.ts +0 -5
  87. package/dist/stdlib/web.js +0 -97
  88. package/dist/suspend-error.d.ts +0 -24
  89. package/dist/suspend-error.js +0 -25
  90. package/dist/vm/index.d.ts +0 -6
  91. package/dist/vm/index.js +0 -6
@@ -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
- }