@opencode/codemode 0.0.0-dev-19474 → 0.0.0-dev-19483

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.
@@ -1,4 +1,5 @@
1
1
  import { Effect } from "effect";
2
2
  import type { ResolvedExecutionLimits, Result } from "../codemode.js";
3
3
  import { ToolRuntime } from "../tool-runtime.js";
4
- export declare const executeProgram: <R>(code: string, prepared: ToolRuntime.Prepared<R>, limits: ResolvedExecutionLimits, hooks: ToolRuntime.ToolCallHooks<R>) => Effect.Effect<Result, never, R>;
4
+ import type { Host } from "./globals.js";
5
+ export declare const executeProgram: <R>(code: string, prepared: ToolRuntime.Prepared<R>, limits: ResolvedExecutionLimits, hooks: ToolRuntime.ToolCallHooks<R>, extraGlobals?: (host: Host<R>) => ReadonlyArray<readonly [string, unknown]>) => Effect.Effect<Result, never, R>;
@@ -9,7 +9,7 @@ import { normalizeError } from "./errors.js";
9
9
  import { InterpreterRuntimeError } from "./model.js";
10
10
  import { PromiseRuntime } from "./promises.js";
11
11
  import { Runtime } from "./runtime.js";
12
- export const executeProgram = (code, prepared, limits, hooks) => {
12
+ export const executeProgram = (code, prepared, limits, hooks, extraGlobals) => {
13
13
  if (code.trim().length === 0) {
14
14
  return Effect.succeed({
15
15
  ok: false,
@@ -27,7 +27,7 @@ export const executeProgram = (code, prepared, limits, hooks) => {
27
27
  const base = Effect.acquireUseRelease(Scope.make("parallel"), (scope) => Effect.gen(function* () {
28
28
  const program = parseProgram(code);
29
29
  const promises = new PromiseRuntime(scope);
30
- const value = yield* new Runtime(tools.execute, tools.search, tools.keys, promises, logs).run(program);
30
+ const value = yield* new Runtime(tools.execute, tools.search, tools.keys, promises, logs, extraGlobals).run(program);
31
31
  const result = toData(value, "Execution result", "result");
32
32
  returned = { value: result, promises };
33
33
  const warnings = yield* promises.interrupt();
@@ -1,5 +1,6 @@
1
1
  import type { Program } from "acorn";
2
2
  import { Effect } from "effect";
3
+ import { type Host } from "./globals.js";
3
4
  import { type Runner } from "./runner.js";
4
5
  import { PromiseRuntime } from "./promises.js";
5
6
  /** One program execution: the tool bridge, promise scheduler, captured logs, and the global scope built once. */
@@ -13,6 +14,6 @@ export declare class Runtime<R> {
13
14
  /** Built-in globals by name, unaffected by program shadowing. */
14
15
  readonly builtins: ReadonlyMap<string, unknown>;
15
16
  private readonly root;
16
- constructor(executeTool: (path: ReadonlyArray<string>, args: Array<unknown>) => Effect.Effect<unknown, unknown, R>, search: (args: Array<unknown>) => Effect.Effect<unknown, unknown, R>, toolKeys: (path: ReadonlyArray<string>) => ReadonlyArray<string>, promises: PromiseRuntime<R>, logs?: Array<string>);
17
+ constructor(executeTool: (path: ReadonlyArray<string>, args: Array<unknown>) => Effect.Effect<unknown, unknown, R>, search: (args: Array<unknown>) => Effect.Effect<unknown, unknown, R>, toolKeys: (path: ReadonlyArray<string>) => ReadonlyArray<string>, promises: PromiseRuntime<R>, logs?: Array<string>, extraGlobals?: (host: Host<R>) => ReadonlyArray<readonly [string, unknown]>);
17
18
  run(program: Program): Effect.Effect<unknown, unknown, R>;
18
19
  }
@@ -192,7 +192,7 @@ export class Runtime {
192
192
  /** Built-in globals by name, unaffected by program shadowing. */
193
193
  builtins;
194
194
  root;
195
- constructor(executeTool, search, toolKeys, promises, logs = []) {
195
+ constructor(executeTool, search, toolKeys, promises, logs = [], extraGlobals = () => []) {
196
196
  this.executeTool = executeTool;
197
197
  this.search = search;
198
198
  this.toolKeys = toolKeys;
@@ -207,7 +207,7 @@ export class Runtime {
207
207
  settlePromise: (promise) => this.root.settlePromise(promise),
208
208
  syncIterator: (value, node) => this.root.syncIterator(value, node),
209
209
  };
210
- this.builtins = new Map(globals(this));
210
+ this.builtins = new Map([...globals(this), ...extraGlobals(this)]);
211
211
  for (const [name, value] of this.builtins)
212
212
  globalScope.set(name, { mutable: false, value });
213
213
  }
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-19474",
4
+ "version": "0.0.0-dev-19483",
5
5
  "description": "Effect-native confined code execution over schema-described tools",
6
6
  "type": "module",
7
7
  "license": "MIT",