@opencode/codemode 0.0.0-dev-19488 → 0.0.0-dev-19498
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/dist/data.js +4 -1
- package/dist/interpreter/model.d.ts +1 -9
- package/dist/interpreter/model.js +0 -14
- package/dist/interpreter/objects.d.ts +12 -0
- package/dist/interpreter/objects.js +33 -4
- package/dist/interpreter/promises.js +3 -3
- package/dist/interpreter/references.js +4 -4
- package/dist/interpreter/runner.d.ts +4 -3
- package/dist/interpreter/runner.js +3 -3
- package/dist/interpreter/runtime.js +43 -19
- package/dist/tool-runtime.d.ts +1 -1
- package/package.json +1 -1
package/dist/data.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export * as Data from "./data.js";
|
|
2
|
-
import { ownEntries, parseArrayIndex, ProgramArray, ProgramObject, set } from "./interpreter/objects.js";
|
|
2
|
+
import { ownEntries, parseArrayIndex, ProgramArray, ProgramFunction, ProgramObject, set, } from "./interpreter/objects.js";
|
|
3
3
|
import { Values } from "./values.js";
|
|
4
4
|
const MAX_VALUE_DEPTH = 32;
|
|
5
5
|
export class ToolRuntimeError extends Error {
|
|
@@ -46,6 +46,9 @@ const copy = (value, label, mode, depth, seen) => {
|
|
|
46
46
|
if (value instanceof Values.Promise) {
|
|
47
47
|
throw new ToolRuntimeError("InvalidDataValue", `${label} contains an un-awaited Promise; await tool calls (e.g. \`const result = await tools.ns.tool(...)\`) before using their results.`);
|
|
48
48
|
}
|
|
49
|
+
if (value instanceof ProgramFunction && mode !== "program") {
|
|
50
|
+
throw new ToolRuntimeError("InvalidDataValue", `${label} must contain data only.`);
|
|
51
|
+
}
|
|
49
52
|
const plain = mode === "program" || mode === "data";
|
|
50
53
|
if (mode === "program") {
|
|
51
54
|
if (value instanceof ProgramObject || Values.isValue(value))
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Node } from "acorn";
|
|
2
2
|
import type { Effect } from "effect";
|
|
3
3
|
import type { DiagnosticKind } from "../codemode.js";
|
|
4
4
|
import type { ProgramObject } from "./objects.js";
|
|
@@ -26,14 +26,6 @@ export type MemberReference = {
|
|
|
26
26
|
target: ProgramObject | Values.RegExp | Values.URL;
|
|
27
27
|
key: PropertyKey;
|
|
28
28
|
};
|
|
29
|
-
export declare class CodeModeFunction {
|
|
30
|
-
readonly parameters: ReadonlyArray<Pattern>;
|
|
31
|
-
readonly body: BlockStatement | Expression;
|
|
32
|
-
readonly capturedScopes: ReadonlyArray<Map<string, Binding>>;
|
|
33
|
-
readonly async: boolean;
|
|
34
|
-
readonly generator: boolean;
|
|
35
|
-
constructor(parameters: ReadonlyArray<Pattern>, body: BlockStatement | Expression, capturedScopes: ReadonlyArray<Map<string, Binding>>, async: boolean, generator: boolean);
|
|
36
|
-
}
|
|
37
29
|
export type GeneratorRequestKind = "next" | "return" | "throw";
|
|
38
30
|
export declare class CodeModeGenerator {
|
|
39
31
|
readonly asynchronous: boolean;
|
|
@@ -1,17 +1,3 @@
|
|
|
1
|
-
export class CodeModeFunction {
|
|
2
|
-
parameters;
|
|
3
|
-
body;
|
|
4
|
-
capturedScopes;
|
|
5
|
-
async;
|
|
6
|
-
generator;
|
|
7
|
-
constructor(parameters, body, capturedScopes, async, generator) {
|
|
8
|
-
this.parameters = parameters;
|
|
9
|
-
this.body = body;
|
|
10
|
-
this.capturedScopes = capturedScopes;
|
|
11
|
-
this.async = async;
|
|
12
|
-
this.generator = generator;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
1
|
export class CodeModeGenerator {
|
|
16
2
|
asynchronous;
|
|
17
3
|
request;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { BlockStatement, Expression, Pattern } from "acorn";
|
|
2
|
+
import { type Binding } from "./model.js";
|
|
1
3
|
/** An object owned by the program: own properties plus a prototype link. */
|
|
2
4
|
export declare class ProgramObject {
|
|
3
5
|
proto: ProgramObject | null;
|
|
@@ -12,6 +14,16 @@ export declare class ProgramError extends ProgramObject {
|
|
|
12
14
|
readonly errorName: string;
|
|
13
15
|
constructor(errorName: string);
|
|
14
16
|
}
|
|
17
|
+
export declare class ProgramFunction extends ProgramObject {
|
|
18
|
+
readonly name: string;
|
|
19
|
+
readonly parameters: ReadonlyArray<Pattern>;
|
|
20
|
+
readonly body: BlockStatement | Expression;
|
|
21
|
+
readonly capturedScopes: ReadonlyArray<Map<string, Binding>>;
|
|
22
|
+
readonly async: boolean;
|
|
23
|
+
readonly generator: boolean;
|
|
24
|
+
readonly length: number;
|
|
25
|
+
constructor(name: string, parameters: ReadonlyArray<Pattern>, body: BlockStatement | Expression, capturedScopes: ReadonlyArray<Map<string, Binding>>, async: boolean, generator: boolean);
|
|
26
|
+
}
|
|
15
27
|
export declare const parseArrayIndex: (key: string | number) => number | undefined;
|
|
16
28
|
export declare const hasOwn: (target: ProgramObject, key: PropertyKey) => boolean;
|
|
17
29
|
export declare const getOwn: (target: ProgramObject, key: PropertyKey) => unknown;
|
|
@@ -21,6 +21,26 @@ export class ProgramError extends ProgramObject {
|
|
|
21
21
|
this.errorName = errorName;
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
+
export class ProgramFunction extends ProgramObject {
|
|
25
|
+
name;
|
|
26
|
+
parameters;
|
|
27
|
+
body;
|
|
28
|
+
capturedScopes;
|
|
29
|
+
async;
|
|
30
|
+
generator;
|
|
31
|
+
length;
|
|
32
|
+
constructor(name, parameters, body, capturedScopes, async, generator) {
|
|
33
|
+
super();
|
|
34
|
+
this.name = name;
|
|
35
|
+
this.parameters = parameters;
|
|
36
|
+
this.body = body;
|
|
37
|
+
this.capturedScopes = capturedScopes;
|
|
38
|
+
this.async = async;
|
|
39
|
+
this.generator = generator;
|
|
40
|
+
const optional = parameters.findIndex((p) => p.type === "AssignmentPattern" || p.type === "RestElement");
|
|
41
|
+
this.length = optional === -1 ? parameters.length : optional;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
24
44
|
const MAX_ARRAY_LENGTH = 4_294_967_295;
|
|
25
45
|
export const parseArrayIndex = (key) => {
|
|
26
46
|
const property = String(key);
|
|
@@ -31,22 +51,27 @@ export const parseArrayIndex = (key) => {
|
|
|
31
51
|
};
|
|
32
52
|
const canonical = (key) => (typeof key === "symbol" ? key : String(key));
|
|
33
53
|
const index = (target, key) => target instanceof ProgramArray && typeof key === "string" ? parseArrayIndex(key) : undefined;
|
|
54
|
+
// Non-enumerable built-in properties: array length, function name and length.
|
|
55
|
+
const builtin = (target, name) => (name === "length" && target instanceof ProgramArray) ||
|
|
56
|
+
((name === "name" || name === "length") && target instanceof ProgramFunction);
|
|
34
57
|
export const hasOwn = (target, key) => {
|
|
35
58
|
const name = canonical(key);
|
|
36
59
|
const at = index(target, name);
|
|
37
60
|
if (at !== undefined)
|
|
38
61
|
return at in target.items;
|
|
39
|
-
|
|
40
|
-
return true;
|
|
41
|
-
return target.props.has(name);
|
|
62
|
+
return builtin(target, name) || target.props.has(name);
|
|
42
63
|
};
|
|
43
64
|
export const getOwn = (target, key) => {
|
|
44
65
|
const name = canonical(key);
|
|
45
66
|
const at = index(target, name);
|
|
46
67
|
if (at !== undefined)
|
|
47
68
|
return target.items[at];
|
|
48
|
-
if (name === "length"
|
|
69
|
+
if (target instanceof ProgramArray && name === "length")
|
|
49
70
|
return target.items.length;
|
|
71
|
+
if (target instanceof ProgramFunction && name === "name")
|
|
72
|
+
return target.name;
|
|
73
|
+
if (target instanceof ProgramFunction && name === "length")
|
|
74
|
+
return target.length;
|
|
50
75
|
return target.props.get(name);
|
|
51
76
|
};
|
|
52
77
|
export const get = (target, key) => {
|
|
@@ -78,6 +103,8 @@ export const set = (target, key, value) => {
|
|
|
78
103
|
target.items.length = length;
|
|
79
104
|
return true;
|
|
80
105
|
}
|
|
106
|
+
if (builtin(target, name))
|
|
107
|
+
return false;
|
|
81
108
|
target.props.set(name, value);
|
|
82
109
|
return true;
|
|
83
110
|
};
|
|
@@ -88,6 +115,8 @@ export const remove = (target, key) => {
|
|
|
88
115
|
return delete target.items[at];
|
|
89
116
|
if (name === "length" && target instanceof ProgramArray)
|
|
90
117
|
return false;
|
|
118
|
+
if (builtin(target, name))
|
|
119
|
+
return true;
|
|
91
120
|
target.props.delete(name);
|
|
92
121
|
return true;
|
|
93
122
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Cause, Deferred, Effect, Exit, Fiber, Scope } from "effect";
|
|
2
|
-
import {
|
|
3
|
-
import { get, ProgramArray, ProgramObject, record } from "./objects.js";
|
|
2
|
+
import { InterpreterRuntimeError, ProgramThrow, PromiseInstanceMethodReference } from "./model.js";
|
|
3
|
+
import { get, ProgramArray, ProgramFunction, ProgramObject, record } from "./objects.js";
|
|
4
4
|
import { HostFunction, requiresNew, sync } from "./host.js";
|
|
5
5
|
import { caughtErrorValue, normalizeError } from "./errors.js";
|
|
6
6
|
import { typeofValue } from "./references.js";
|
|
@@ -181,7 +181,7 @@ export const invokePromiseInstanceMethod = (runner, promises, ref, args, node) =
|
|
|
181
181
|
return chainReaction(runner, promises, ref.promise, onFulfilled, onRejected, method, node);
|
|
182
182
|
};
|
|
183
183
|
const constructPromise = (runner, promises, executor, node) => {
|
|
184
|
-
if (!(executor instanceof
|
|
184
|
+
if (!(executor instanceof ProgramFunction)) {
|
|
185
185
|
throw new InterpreterRuntimeError("new Promise(...) expects an executor function (e.g. new Promise((resolve, reject) => { ... })).", node).as("TypeError");
|
|
186
186
|
}
|
|
187
187
|
return Effect.gen(function* () {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { ToolReference } from "../tool-runtime.js";
|
|
2
2
|
import { Values } from "../values.js";
|
|
3
3
|
import { HostFunction, HostNamespace } from "./host.js";
|
|
4
|
-
import {
|
|
5
|
-
import { getOwn, ownKeys, ProgramArray, ProgramObject } from "./objects.js";
|
|
4
|
+
import { CodeModeGenerator, GeneratorMethodReference, InterpreterRuntimeError, IntrinsicReference, PromiseInstanceMethodReference, } from "./model.js";
|
|
5
|
+
import { getOwn, ownKeys, ProgramArray, ProgramFunction, ProgramObject } from "./objects.js";
|
|
6
6
|
export const isRuntimeReference = (value) => value instanceof HostFunction ||
|
|
7
7
|
value instanceof HostNamespace ||
|
|
8
|
-
value instanceof
|
|
8
|
+
value instanceof ProgramFunction ||
|
|
9
9
|
value instanceof CodeModeGenerator ||
|
|
10
10
|
value instanceof GeneratorMethodReference ||
|
|
11
11
|
value instanceof ToolReference ||
|
|
@@ -79,7 +79,7 @@ export const describeValue = (value) => {
|
|
|
79
79
|
};
|
|
80
80
|
export const typeofValue = (value) => {
|
|
81
81
|
if (value instanceof HostFunction ||
|
|
82
|
-
value instanceof
|
|
82
|
+
value instanceof ProgramFunction ||
|
|
83
83
|
value instanceof GeneratorMethodReference ||
|
|
84
84
|
value instanceof IntrinsicReference ||
|
|
85
85
|
value instanceof PromiseInstanceMethodReference) {
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
2
|
import { Values } from "../values.js";
|
|
3
3
|
import { HostFunction } from "./host.js";
|
|
4
|
-
import { type AstNode,
|
|
4
|
+
import { type AstNode, IntrinsicReference } from "./model.js";
|
|
5
|
+
import { ProgramFunction } from "./objects.js";
|
|
5
6
|
export type IteratorCursor<R> = {
|
|
6
7
|
readonly next: Effect.Effect<{
|
|
7
8
|
readonly done: boolean;
|
|
@@ -11,13 +12,13 @@ export type IteratorCursor<R> = {
|
|
|
11
12
|
};
|
|
12
13
|
/** Everything a host function needs to call back into the program. */
|
|
13
14
|
export type Runner<R> = {
|
|
14
|
-
readonly invokeFunction: (fn:
|
|
15
|
+
readonly invokeFunction: (fn: ProgramFunction, args: Array<unknown>) => Effect.Effect<unknown, unknown, R>;
|
|
15
16
|
readonly invokeCallable: (callable: unknown, args: Array<unknown>, node: AstNode) => Effect.Effect<unknown, unknown, R>;
|
|
16
17
|
readonly settlePromise: (promise: Values.Promise) => Effect.Effect<unknown, unknown, never>;
|
|
17
18
|
readonly syncIterator: (value: unknown, node: AstNode) => Effect.Effect<IteratorCursor<R> | undefined, unknown, R>;
|
|
18
19
|
};
|
|
19
20
|
export declare const preserveConsumerError: <A, R>(cursor: IteratorCursor<R>, effect: Effect.Effect<A, unknown, R>) => Effect.Effect<A, unknown, R>;
|
|
20
21
|
export declare const toPrimitive: <R>(runner: Runner<R>, value: unknown, hint: "number" | "string", node: AstNode) => Effect.Effect<unknown, unknown, R>;
|
|
21
|
-
export type SupportedCallback =
|
|
22
|
+
export type SupportedCallback = ProgramFunction | HostFunction<unknown> | IntrinsicReference;
|
|
22
23
|
export declare const isSupportedCallback: (value: unknown) => value is SupportedCallback;
|
|
23
24
|
export declare const applyCollectionCallback: <R>(runner: Runner<R>, callback: unknown, name: string, node: AstNode) => ((args: Array<unknown>) => Effect.Effect<unknown, unknown, R>);
|
|
@@ -2,8 +2,8 @@ import { Effect, Exit } from "effect";
|
|
|
2
2
|
import { Values } from "../values.js";
|
|
3
3
|
import { coerceToString } from "../stdlib/value.js";
|
|
4
4
|
import { HostFunction } from "./host.js";
|
|
5
|
-
import {
|
|
6
|
-
import { get, has, ProgramObject } from "./objects.js";
|
|
5
|
+
import { InterpreterRuntimeError, IntrinsicReference } from "./model.js";
|
|
6
|
+
import { get, has, ProgramFunction, ProgramObject } from "./objects.js";
|
|
7
7
|
import { typeofValue } from "./references.js";
|
|
8
8
|
export const preserveConsumerError = (cursor, effect) => Effect.flatMap(Effect.exit(effect), (exit) => Exit.isSuccess(exit)
|
|
9
9
|
? Effect.succeed(exit.value)
|
|
@@ -31,7 +31,7 @@ export const toPrimitive = (runner, value, hint, node) => {
|
|
|
31
31
|
throw new InterpreterRuntimeError("Cannot convert object to primitive value.", node).as("TypeError");
|
|
32
32
|
});
|
|
33
33
|
};
|
|
34
|
-
export const isSupportedCallback = (value) => value instanceof
|
|
34
|
+
export const isSupportedCallback = (value) => value instanceof ProgramFunction ||
|
|
35
35
|
(value instanceof HostFunction && value.callback) ||
|
|
36
36
|
value instanceof IntrinsicReference;
|
|
37
37
|
export const applyCollectionCallback = (runner, callback, name, node) => {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Cause, Deferred, Effect, Exit } from "effect";
|
|
2
2
|
import { ToolRuntimeError, toProgram } from "../data.js";
|
|
3
3
|
import { ToolReference } from "../tool-runtime.js";
|
|
4
|
-
import { AsyncIteratorSymbol,
|
|
4
|
+
import { AsyncIteratorSymbol, CodeModeGenerator, ComputedValue, GeneratorMethodReference, GeneratorReturn, IntrinsicReference, InterpreterRuntimeError, IteratorSymbol, OptionalShortCircuit, PromiseInstanceMethodReference, ProgramThrow, unsupportedSyntax, } from "./model.js";
|
|
5
5
|
import { caughtErrorValue } from "./errors.js";
|
|
6
6
|
import { globals } from "./globals.js";
|
|
7
7
|
import { HostFunction, HostNamespace } from "./host.js";
|
|
8
8
|
import { invokeIntrinsic } from "./methods.js";
|
|
9
|
-
import { assign, get, has, ownKeys, parseArrayIndex, ProgramArray, ProgramObject, record, remove, set, } from "./objects.js";
|
|
9
|
+
import { assign, get, has, ownKeys, parseArrayIndex, ProgramArray, ProgramFunction, ProgramObject, record, remove, set, } from "./objects.js";
|
|
10
10
|
import { preserveConsumerError } from "./runner.js";
|
|
11
11
|
import { invokePromiseInstanceMethod, PromiseRuntime, resolvePromise, resolvePromiseValue } from "./promises.js";
|
|
12
12
|
import { containsOpaqueReference, describeValue, isRuntimeReference, rejectCircularInsertion, typeofValue, } from "./references.js";
|
|
@@ -73,7 +73,7 @@ const constructorName = (value) => {
|
|
|
73
73
|
return "URLSearchParams";
|
|
74
74
|
if (value instanceof Values.Promise)
|
|
75
75
|
return "Promise";
|
|
76
|
-
if (!(value instanceof ProgramObject))
|
|
76
|
+
if (!(value instanceof ProgramObject) || value instanceof ProgramFunction)
|
|
77
77
|
return undefined;
|
|
78
78
|
return errorBrandName(value) ?? "Object";
|
|
79
79
|
};
|
|
@@ -324,8 +324,15 @@ class Frame {
|
|
|
324
324
|
return { kind: "none" };
|
|
325
325
|
}).pipe(Effect.ensuring(Effect.sync(() => self.scopes.pop())));
|
|
326
326
|
}
|
|
327
|
-
createFunction(node) {
|
|
328
|
-
return new
|
|
327
|
+
createFunction(node, name = node.type === "ArrowFunctionExpression" ? "" : (node.id?.name ?? "")) {
|
|
328
|
+
return new ProgramFunction(name, node.params, node.body, this.scopes.capture(), node.async, node.generator);
|
|
329
|
+
}
|
|
330
|
+
// NamedEvaluation: an anonymous function definition takes the name of what it is assigned to.
|
|
331
|
+
evaluateNamed(node, name) {
|
|
332
|
+
if (node.type === "ArrowFunctionExpression" || (node.type === "FunctionExpression" && !node.id)) {
|
|
333
|
+
return Effect.sync(() => this.createFunction(node, name));
|
|
334
|
+
}
|
|
335
|
+
return this.evaluateExpression(node);
|
|
329
336
|
}
|
|
330
337
|
hoistFunctions(statements) {
|
|
331
338
|
for (const node of statements) {
|
|
@@ -826,12 +833,14 @@ class Frame {
|
|
|
826
833
|
}
|
|
827
834
|
const init = declaration.init;
|
|
828
835
|
// `var x` alone is a no-op: the binding was hoisted on function entry.
|
|
836
|
+
const id = declaration.id;
|
|
837
|
+
const evaluate = (init) => id.type === "Identifier" ? self.evaluateNamed(init, id.name) : self.evaluateExpression(init);
|
|
829
838
|
if (kind === "var") {
|
|
830
839
|
if (init)
|
|
831
|
-
yield* self.assignPattern(
|
|
840
|
+
yield* self.assignPattern(id, yield* evaluate(init), declaration);
|
|
832
841
|
continue;
|
|
833
842
|
}
|
|
834
|
-
const value = init ? yield*
|
|
843
|
+
const value = init ? yield* evaluate(init) : undefined;
|
|
835
844
|
yield* self.declarePattern(declaration.id, value, kind !== "const", declaration, true);
|
|
836
845
|
}
|
|
837
846
|
});
|
|
@@ -848,7 +857,7 @@ class Frame {
|
|
|
848
857
|
return;
|
|
849
858
|
}
|
|
850
859
|
if (pattern.type === "AssignmentPattern") {
|
|
851
|
-
const resolved = value === undefined ? yield* self.
|
|
860
|
+
const resolved = value === undefined ? yield* self.evaluateDefault(pattern) : value;
|
|
852
861
|
yield* self.declarePattern(pattern.left, resolved, mutable, node, initialize);
|
|
853
862
|
return;
|
|
854
863
|
}
|
|
@@ -888,7 +897,7 @@ class Frame {
|
|
|
888
897
|
return;
|
|
889
898
|
}
|
|
890
899
|
if (pattern.type === "AssignmentPattern") {
|
|
891
|
-
const resolved = value === undefined ? yield* self.
|
|
900
|
+
const resolved = value === undefined ? yield* self.evaluateDefault(pattern) : value;
|
|
892
901
|
yield* self.assignPattern(pattern.left, resolved, node);
|
|
893
902
|
return;
|
|
894
903
|
}
|
|
@@ -916,6 +925,11 @@ class Frame {
|
|
|
916
925
|
throw new InterpreterRuntimeError(`Unsupported assignment pattern '${pattern.type}'.`, node);
|
|
917
926
|
});
|
|
918
927
|
}
|
|
928
|
+
evaluateDefault(pattern) {
|
|
929
|
+
return pattern.left.type === "Identifier"
|
|
930
|
+
? this.evaluateNamed(pattern.right, pattern.left.name)
|
|
931
|
+
: this.evaluateExpression(pattern.right);
|
|
932
|
+
}
|
|
919
933
|
destructureArrayPattern(pattern, value, consume) {
|
|
920
934
|
const self = this;
|
|
921
935
|
return Effect.gen(function* () {
|
|
@@ -1050,7 +1064,7 @@ class Frame {
|
|
|
1050
1064
|
// unsupported syntax. Built-ins like Number are real constructors in JS, so do not claim
|
|
1051
1065
|
// otherwise; say `new` is unsupported for them and point at the plain call.
|
|
1052
1066
|
const name = calleeDescription(node.callee);
|
|
1053
|
-
const message = callee instanceof
|
|
1067
|
+
const message = callee instanceof ProgramFunction
|
|
1054
1068
|
? `${name} cannot be constructed: user-defined constructors and classes are not supported. Call it as a function that returns a plain object instead.`
|
|
1055
1069
|
: callee instanceof HostFunction
|
|
1056
1070
|
? `new ${name}(...) is not supported; call ${name}(...) without new instead.`
|
|
@@ -1080,6 +1094,9 @@ class Frame {
|
|
|
1080
1094
|
return lhs === rhs;
|
|
1081
1095
|
if (operator === "!==")
|
|
1082
1096
|
return lhs !== rhs;
|
|
1097
|
+
if (operator === "in" && rhs instanceof ProgramObject && !containsOpaqueReference(lhs)) {
|
|
1098
|
+
return has(rhs, lhs !== null && typeof lhs === "object" ? coerceToString(lhs) : lhs);
|
|
1099
|
+
}
|
|
1083
1100
|
if (containsOpaqueReference(lhs) || containsOpaqueReference(rhs)) {
|
|
1084
1101
|
throw new InterpreterRuntimeError("Binary operators require data values.", node, "InvalidDataValue");
|
|
1085
1102
|
}
|
|
@@ -1214,7 +1231,7 @@ class Frame {
|
|
|
1214
1231
|
const next = toProgram(self.applyCompoundAssignment(operator, current, rightValue, node), "Assignment result");
|
|
1215
1232
|
return self.scopes.set(name, next, left);
|
|
1216
1233
|
}
|
|
1217
|
-
const rightValue = yield* self.
|
|
1234
|
+
const rightValue = yield* self.evaluateNamed(node.right, name);
|
|
1218
1235
|
return self.scopes.set(name, rightValue, left);
|
|
1219
1236
|
}
|
|
1220
1237
|
if (left.type === "MemberExpression") {
|
|
@@ -1237,7 +1254,7 @@ class Frame {
|
|
|
1237
1254
|
const current = self.scopes.get(name, left);
|
|
1238
1255
|
if (!shouldAssign(current))
|
|
1239
1256
|
return current;
|
|
1240
|
-
const rightValue = yield* self.
|
|
1257
|
+
const rightValue = yield* self.evaluateNamed(node.right, name);
|
|
1241
1258
|
return self.scopes.set(name, rightValue, left);
|
|
1242
1259
|
});
|
|
1243
1260
|
}
|
|
@@ -1311,7 +1328,7 @@ class Frame {
|
|
|
1311
1328
|
}
|
|
1312
1329
|
return yield* self.createToolCallPromise(callable.path, args);
|
|
1313
1330
|
}
|
|
1314
|
-
if (callable instanceof
|
|
1331
|
+
if (callable instanceof ProgramFunction) {
|
|
1315
1332
|
return yield* self.invokeFunction(callable, args);
|
|
1316
1333
|
}
|
|
1317
1334
|
if (callable instanceof GeneratorMethodReference) {
|
|
@@ -1621,7 +1638,12 @@ class Frame {
|
|
|
1621
1638
|
else {
|
|
1622
1639
|
throw new InterpreterRuntimeError("Unsupported object property key shape.", keyNode);
|
|
1623
1640
|
}
|
|
1624
|
-
|
|
1641
|
+
const name = key === IteratorSymbol
|
|
1642
|
+
? "[Symbol.iterator]"
|
|
1643
|
+
: key === AsyncIteratorSymbol
|
|
1644
|
+
? "[Symbol.asyncIterator]"
|
|
1645
|
+
: String(key);
|
|
1646
|
+
set(objectValue, key, yield* self.evaluateNamed(property.value, name));
|
|
1625
1647
|
}
|
|
1626
1648
|
return objectValue;
|
|
1627
1649
|
});
|
|
@@ -1801,13 +1823,12 @@ class Frame {
|
|
|
1801
1823
|
}
|
|
1802
1824
|
return new ComputedValue(undefined);
|
|
1803
1825
|
}
|
|
1826
|
+
if (objectValue instanceof ProgramObject)
|
|
1827
|
+
return { target: objectValue, key };
|
|
1804
1828
|
if (isRuntimeReference(objectValue)) {
|
|
1805
1829
|
throw new InterpreterRuntimeError(`Cannot read properties of ${describeValue(objectValue)}; only data values expose properties.`, objectNode, "InvalidDataValue");
|
|
1806
1830
|
}
|
|
1807
|
-
|
|
1808
|
-
throw new InterpreterRuntimeError("Cannot access a property on a non-object value.", objectNode);
|
|
1809
|
-
}
|
|
1810
|
-
return { target: objectValue, key };
|
|
1831
|
+
throw new InterpreterRuntimeError("Cannot access a property on a non-object value.", objectNode);
|
|
1811
1832
|
});
|
|
1812
1833
|
}
|
|
1813
1834
|
readMember(node) {
|
|
@@ -1902,8 +1923,11 @@ class Frame {
|
|
|
1902
1923
|
}
|
|
1903
1924
|
const target = reference.target;
|
|
1904
1925
|
rejectCircularInsertion(target, next, target instanceof ProgramArray ? "Array assignment result" : "Object assignment result", node);
|
|
1905
|
-
if (
|
|
1926
|
+
if (set(target, key, next))
|
|
1927
|
+
return;
|
|
1928
|
+
if (target instanceof ProgramArray)
|
|
1906
1929
|
throw new InterpreterRuntimeError("Invalid array length", node).as("RangeError");
|
|
1930
|
+
throw new InterpreterRuntimeError(`Cannot assign to read only property '${String(key)}'.`, node).as("TypeError");
|
|
1907
1931
|
}
|
|
1908
1932
|
toPropertyKey(value, node) {
|
|
1909
1933
|
if (typeof value === "string" || typeof value === "number") {
|
package/dist/tool-runtime.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Effect } from "effect";
|
|
|
2
2
|
import { type Namespace } from "./namespace.js";
|
|
3
3
|
import { type Tool } from "./tool.js";
|
|
4
4
|
import type { Tools } from "./tools.js";
|
|
5
|
-
export declare const compareText: (left: string, right: string) => 1 |
|
|
5
|
+
export declare const compareText: (left: string, right: string) => 1 | -1 | 0;
|
|
6
6
|
export type Services<T> = ServicesOf<T, []>;
|
|
7
7
|
type ServicesOf<T, Depth extends ReadonlyArray<unknown>> = Depth["length"] extends 8 ? never : T extends {
|
|
8
8
|
readonly _tag: "CodeModeTool";
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
3
|
"name": "@opencode/codemode",
|
|
4
|
-
"version": "0.0.0-dev-
|
|
4
|
+
"version": "0.0.0-dev-19498",
|
|
5
5
|
"description": "Effect-native confined code execution over schema-described tools",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"license": "MIT",
|