@opencode-ai/codemode 0.0.0-next-17343 → 0.0.0-next-17352

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,6 +1,8 @@
1
1
  import { parse } from "acorn";
2
2
  import { Cause, Effect, Scope } from "effect";
3
- import { DiagnosticCategory, ModuleKind, ScriptTarget, flattenDiagnosticMessageText, transpileModule } from "typescript";
3
+ // #transpile: conditional import full typescript on node/bun, an identity
4
+ // pass-through on workerd (the compiler is ~11 MiB and can't init there).
5
+ import { transpile } from "#transpile";
4
6
  import { copyIn, copyOut, ToolRuntime } from "../tool-runtime.js";
5
7
  import { normalizeError } from "./errors.js";
6
8
  import { InterpreterRuntimeError, isRecord } from "./model.js";
@@ -81,16 +83,9 @@ export const executeWithLimits = (options, limits, searchIndex) => {
81
83
  });
82
84
  };
83
85
  const parseProgram = (code) => {
84
- const transpiled = transpileModule(`async function __codemode__() {\n${code}\n}`, {
85
- reportDiagnostics: true,
86
- compilerOptions: {
87
- target: ScriptTarget.ESNext,
88
- module: ModuleKind.ESNext,
89
- },
90
- });
91
- const diagnostic = transpiled.diagnostics?.find((item) => item.category === DiagnosticCategory.Error);
92
- if (diagnostic) {
93
- throw new InterpreterRuntimeError(`Failed to parse TypeScript: ${flattenDiagnosticMessageText(diagnostic.messageText, "\n")}`, undefined, "ParseError");
86
+ const transpiled = transpile(`async function __codemode__() {\n${code}\n}`);
87
+ if (transpiled.error !== undefined) {
88
+ throw new InterpreterRuntimeError(`Failed to parse TypeScript: ${transpiled.error}`, undefined, "ParseError");
94
89
  }
95
90
  const bodyStart = transpiled.outputText.indexOf("{") + 1;
96
91
  const bodyEnd = transpiled.outputText.lastIndexOf("}");
@@ -0,0 +1,5 @@
1
+ export interface TranspileResult {
2
+ readonly outputText: string;
3
+ readonly error?: string;
4
+ }
5
+ export declare const transpile: (source: string) => TranspileResult;
@@ -0,0 +1,19 @@
1
+ import { DiagnosticCategory, ModuleKind, ScriptTarget, flattenDiagnosticMessageText, transpileModule } from "typescript";
2
+ // Full TypeScript transpilation on node/bun runtimes.
3
+ export const transpile = (source) => {
4
+ const transpiled = transpileModule(source, {
5
+ reportDiagnostics: true,
6
+ compilerOptions: {
7
+ target: ScriptTarget.ESNext,
8
+ module: ModuleKind.ESNext,
9
+ },
10
+ });
11
+ const diagnostic = transpiled.diagnostics?.find((item) => item.category === DiagnosticCategory.Error);
12
+ if (diagnostic) {
13
+ return {
14
+ outputText: transpiled.outputText,
15
+ error: flattenDiagnosticMessageText(diagnostic.messageText, "\n"),
16
+ };
17
+ }
18
+ return { outputText: transpiled.outputText };
19
+ };
@@ -0,0 +1,5 @@
1
+ export interface TranspileResult {
2
+ readonly outputText: string;
3
+ readonly error?: string;
4
+ }
5
+ export declare const transpile: (source: string) => TranspileResult;
@@ -0,0 +1,6 @@
1
+ // workerd profile: the typescript compiler is ~11 MiB and probes node
2
+ // internals at module init, so codemode programs are passed through
3
+ // untranspiled. Plain-JS programs (the overwhelmingly common case) parse
4
+ // fine downstream via acorn; TypeScript-only syntax surfaces as a parse
5
+ // error from the interpreter instead of a transpile diagnostic.
6
+ export const transpile = (source) => ({ outputText: source });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "@opencode-ai/codemode",
4
- "version": "0.0.0-next-17343",
4
+ "version": "0.0.0-next-17352",
5
5
  "description": "Effect-native confined code execution over schema-described tools",
6
6
  "type": "module",
7
7
  "license": "MIT",
@@ -22,6 +22,12 @@
22
22
  "types": "./dist/index.d.ts"
23
23
  }
24
24
  },
25
+ "imports": {
26
+ "#transpile": {
27
+ "workerd": "./src/interpreter/transpile.workerd.ts",
28
+ "default": "./src/interpreter/transpile.node.ts"
29
+ }
30
+ },
25
31
  "scripts": {
26
32
  "build": "bun run script/build.ts",
27
33
  "typecheck": "tsgo --noEmit",