@opencode/codemode 0.0.0-dev-177 → 0.0.0-dev-189
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/README.md
CHANGED
|
@@ -198,7 +198,8 @@ every visible tool. Hosts render their own model-facing instructions from these
|
|
|
198
198
|
and `CodeMode.toolExpression(path)` supply the exact callable forms.
|
|
199
199
|
|
|
200
200
|
The synchronous `search(...)` built-in is always available. It supports exact-path lookup, namespace-scoped search,
|
|
201
|
-
empty-query browsing, and pagination, and returns callable paths with full signatures.
|
|
201
|
+
empty-query browsing, and pagination, and returns callable paths with full signatures. Its result can be used directly,
|
|
202
|
+
awaited, or chained with `then`, `catch`, and `finally`, so programs work whichever way they treat it. Search counts toward
|
|
202
203
|
`maxToolCalls`. Search also matches descriptions from enclosing `Namespace` values.
|
|
203
204
|
|
|
204
205
|
## Execution Limits
|
|
@@ -83,7 +83,7 @@ const symbolGlobal = (ctx) => {
|
|
|
83
83
|
// A table rather than a list so the names are known before any runtime exists.
|
|
84
84
|
const table = {
|
|
85
85
|
tools: () => new ToolReference([]),
|
|
86
|
-
search: (ctx) => native(ctx.builtins, { name: "search", call: (_, args) => ctx.
|
|
86
|
+
search: (ctx) => native(ctx.builtins, { name: "search", call: (_, args) => ctx.search(args), callback: false }),
|
|
87
87
|
undefined: () => undefined,
|
|
88
88
|
NaN: () => NaN,
|
|
89
89
|
Infinity: () => Infinity,
|
|
@@ -33,4 +33,6 @@ export declare class Interpreter<R> {
|
|
|
33
33
|
iterateDirect(value: Value): Cursor;
|
|
34
34
|
/** Runs one host call to completion before any other job: arguments cross as JSON, the result comes back as values. */
|
|
35
35
|
tool(run: ToolRuntime<R>["search"], args: Array<Value>): Generator<import("./runner.js").Signal, Value, import("effect/Schema").Json | undefined>;
|
|
36
|
+
/** The built-in search: its result is usable directly, and can also be awaited or chained like a Promise. */
|
|
37
|
+
search(args: Array<Value>): Generator<import("./runner.js").Signal, Value, import("effect/Schema").Json | undefined>;
|
|
36
38
|
}
|
|
@@ -10,7 +10,7 @@ import { preserveConsumerError, toPrimitive } from "./callback.js";
|
|
|
10
10
|
import { AsyncBoundary, Await, Call, Interruption, isEval, MAX_CALL_DEPTH, Runner, Slice, Task, Yield, normal, } from "./runner.js";
|
|
11
11
|
import { describeValue, isOpaque, rejectCircularInsertion, typeofValue } from "./references.js";
|
|
12
12
|
import { fn } from "./native.js";
|
|
13
|
-
import { capability } from "./promises.js";
|
|
13
|
+
import { capability, promiseLike } from "./promises.js";
|
|
14
14
|
import { ScopeStack } from "./scope.js";
|
|
15
15
|
import { constructRegExp } from "../stdlib/regexp.js";
|
|
16
16
|
import { enumerableSource } from "../stdlib/object.js";
|
|
@@ -290,6 +290,10 @@ export class Interpreter {
|
|
|
290
290
|
json.push(yield* toBoundary(this, arg));
|
|
291
291
|
return fromJson(this, (yield this.runner.blocking(run(json))));
|
|
292
292
|
}
|
|
293
|
+
/** The built-in search: its result is usable directly, and can also be awaited or chained like a Promise. */
|
|
294
|
+
*search(args) {
|
|
295
|
+
return promiseLike(this, yield* this.tool(this.tools.search, args));
|
|
296
|
+
}
|
|
293
297
|
}
|
|
294
298
|
/** One activation: the top-level program or a single function call, evaluating against its own scope chain. */
|
|
295
299
|
class Frame {
|
|
@@ -10,4 +10,9 @@ export declare const capability: <R>(ctx: Interpreter<R>, site: AstNode | undefi
|
|
|
10
10
|
reject: (reason: unknown) => void;
|
|
11
11
|
promise: PromiseObj;
|
|
12
12
|
};
|
|
13
|
+
/**
|
|
14
|
+
* Lets a synchronous object result also be awaited or chained like a Promise. It inherits non-enumerable
|
|
15
|
+
* then/catch/finally that settle with a plain copy, so data views never show them and awaiting does not recurse.
|
|
16
|
+
*/
|
|
17
|
+
export declare const promiseLike: <R>(ctx: Interpreter<R>, value: Value) => Value;
|
|
13
18
|
export declare const promiseGlobal: <R>(ctx: Interpreter<R>) => import("./objects.js").Native;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Throw, typeError } from "./model.js";
|
|
2
|
-
import { Callable, define, get, hidden, Arr, Fn, PromiseObj, record } from "./objects.js";
|
|
2
|
+
import { Callable, define, get, hidden, Arr, Fn, Obj, PromiseObj, record } from "./objects.js";
|
|
3
3
|
import { constructor, fn, methods, native, receiver, requiresNew } from "./native.js";
|
|
4
4
|
import { createAggregateErrorValue, materialize } from "./errors.js";
|
|
5
5
|
import { describeValue, typeofValue } from "./references.js";
|
|
@@ -231,6 +231,37 @@ function* constructPromise(ctx, executor, site) {
|
|
|
231
231
|
}
|
|
232
232
|
return made.promise;
|
|
233
233
|
}
|
|
234
|
+
const promiseLikePrototypes = new WeakMap();
|
|
235
|
+
/**
|
|
236
|
+
* Lets a synchronous object result also be awaited or chained like a Promise. It inherits non-enumerable
|
|
237
|
+
* then/catch/finally that settle with a plain copy, so data views never show them and awaiting does not recurse.
|
|
238
|
+
*/
|
|
239
|
+
export const promiseLike = (ctx, value) => {
|
|
240
|
+
if (!(value instanceof Obj) || value.proto !== ctx.builtins.Object)
|
|
241
|
+
return value;
|
|
242
|
+
value.proto = promiseLikePrototype(ctx);
|
|
243
|
+
return value;
|
|
244
|
+
};
|
|
245
|
+
const promiseLikePrototype = (ctx) => {
|
|
246
|
+
const cached = promiseLikePrototypes.get(ctx);
|
|
247
|
+
if (cached !== undefined)
|
|
248
|
+
return cached;
|
|
249
|
+
const proto = new Obj(ctx.builtins.Object);
|
|
250
|
+
const settled = (thisValue, name) => {
|
|
251
|
+
const source = receiver(Obj, thisValue, name);
|
|
252
|
+
const copy = new Obj(ctx.builtins.Object);
|
|
253
|
+
for (const [key, slot] of source.props)
|
|
254
|
+
copy.props.set(key, { ...slot });
|
|
255
|
+
return ctx.runner.promiseResolve(copy);
|
|
256
|
+
};
|
|
257
|
+
methods(ctx.builtins, proto, ["then", "catch", "finally"].map((name) => [
|
|
258
|
+
name,
|
|
259
|
+
name === "then" ? 2 : 1,
|
|
260
|
+
(thisValue, args, site) => instanceMethod(ctx, name, settled(thisValue, name), args, site),
|
|
261
|
+
]));
|
|
262
|
+
promiseLikePrototypes.set(ctx, proto);
|
|
263
|
+
return proto;
|
|
264
|
+
};
|
|
234
265
|
export const promiseGlobal = (ctx) => {
|
|
235
266
|
const builtins = ctx.builtins;
|
|
236
267
|
const proto = builtins.Promise;
|
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-189",
|
|
5
5
|
"description": "Effect-native confined code execution over schema-described tools",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"license": "MIT",
|