@moikapy/origen-zero 0.1.0
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 +169 -0
- package/dist/chunk-6RAZN3WM.js +232 -0
- package/dist/chunk-6RAZN3WM.js.map +1 -0
- package/dist/chunk-DE5JDJKT.js +194 -0
- package/dist/chunk-DE5JDJKT.js.map +1 -0
- package/dist/chunk-J5UPC5XT.js +115 -0
- package/dist/chunk-J5UPC5XT.js.map +1 -0
- package/dist/chunk-PJFVSOEI.js +65 -0
- package/dist/chunk-PJFVSOEI.js.map +1 -0
- package/dist/chunk-QUQPQFU6.js +223 -0
- package/dist/chunk-QUQPQFU6.js.map +1 -0
- package/dist/chunk-SDOZC7ZI.js +161 -0
- package/dist/chunk-SDOZC7ZI.js.map +1 -0
- package/dist/compiler.d.ts +42 -0
- package/dist/compiler.js +10 -0
- package/dist/compiler.js.map +1 -0
- package/dist/http-compiler.d.ts +40 -0
- package/dist/http-compiler.js +8 -0
- package/dist/http-compiler.js.map +1 -0
- package/dist/index.d.ts +151 -0
- package/dist/index.js +190 -0
- package/dist/index.js.map +1 -0
- package/dist/tools.d.ts +46 -0
- package/dist/tools.js +13 -0
- package/dist/tools.js.map +1 -0
- package/dist/types-Dc-cDRjG.d.ts +200 -0
- package/dist/wasi-runtime.d.ts +41 -0
- package/dist/wasi-runtime.js +7 -0
- package/dist/wasi-runtime.js.map +1 -0
- package/dist/wasm-tool.d.ts +54 -0
- package/dist/wasm-tool.js +10 -0
- package/dist/wasm-tool.js.map +1 -0
- package/package.json +63 -0
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @moikapy/origen-zero — Type definitions
|
|
3
|
+
*
|
|
4
|
+
* All TypeScript interfaces and types for the ZeroLang → Origen bridge.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* The compiler interface. Both CLI and HTTP implementations satisfy this.
|
|
8
|
+
* Use ZeroCompiler for Node/Bun (subprocess), ZeroHTTPCompiler for
|
|
9
|
+
* Cloudflare Workers (HTTP fetch to a Zero service).
|
|
10
|
+
*/
|
|
11
|
+
interface ZeroCompilerLike {
|
|
12
|
+
check(source: string | ZeroSourceFile): Promise<ZeroCheckResult>;
|
|
13
|
+
graph(source: string | ZeroSourceFile): Promise<ZeroGraphResult>;
|
|
14
|
+
size(source: string | ZeroSourceFile): Promise<ZeroSizeResult>;
|
|
15
|
+
fix(source: string | ZeroSourceFile): Promise<ZeroFixResult>;
|
|
16
|
+
build(source: string | ZeroSourceFile, options?: ZeroBuildOptions): Promise<ZeroBuildResult>;
|
|
17
|
+
explain(diagnosticCode: string): Promise<string>;
|
|
18
|
+
}
|
|
19
|
+
/** Configuration for the local ZeroCompiler (subprocess-based). */
|
|
20
|
+
interface ZeroCompilerConfig {
|
|
21
|
+
/** Path to zero CLI binary. Default: "zero" (must be on PATH) */
|
|
22
|
+
binaryPath?: string;
|
|
23
|
+
/** Working directory for compilation. Default: process.cwd() */
|
|
24
|
+
workingDir?: string;
|
|
25
|
+
/** Timeout for compiler invocations in ms. Default: 30000 */
|
|
26
|
+
timeout?: number;
|
|
27
|
+
}
|
|
28
|
+
/** Configuration for ZeroHTTPCompiler (fetch-based, works in Workers). */
|
|
29
|
+
interface ZeroHTTPCompilerConfig {
|
|
30
|
+
/** Base URL of the Zero compiler service. Required. */
|
|
31
|
+
endpoint: string;
|
|
32
|
+
/** Authorization header value (e.g., "Bearer <token>"). Optional. */
|
|
33
|
+
apiKey?: string;
|
|
34
|
+
/** Custom headers to include in every request. Optional. */
|
|
35
|
+
headers?: Record<string, string>;
|
|
36
|
+
/** Timeout for HTTP requests in ms. Default: 30000 */
|
|
37
|
+
timeout?: number;
|
|
38
|
+
/** Custom fetch function. Defaults to globalThis.fetch. Useful for testing. */
|
|
39
|
+
fetch?: typeof globalThis.fetch;
|
|
40
|
+
}
|
|
41
|
+
/** A Zero source file: either a path on disk or inline content. */
|
|
42
|
+
interface ZeroSourceFile {
|
|
43
|
+
/** File path (relative to workingDir). Used for error reporting. */
|
|
44
|
+
path: string;
|
|
45
|
+
/** Source content. If omitted, reads from disk at path. */
|
|
46
|
+
content?: string;
|
|
47
|
+
}
|
|
48
|
+
/** A single diagnostic from the Zero compiler. */
|
|
49
|
+
interface ZeroDiagnostic {
|
|
50
|
+
/** Machine-readable code, e.g. "NAM003", "TYP001" */
|
|
51
|
+
code: string;
|
|
52
|
+
severity: "error" | "warning" | "info";
|
|
53
|
+
message: string;
|
|
54
|
+
line: number;
|
|
55
|
+
column?: number;
|
|
56
|
+
/** Repair metadata — structured suggestion from the compiler */
|
|
57
|
+
repair?: {
|
|
58
|
+
id: string;
|
|
59
|
+
suggestion?: string;
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/** Result of `zero check --json`. */
|
|
63
|
+
interface ZeroCheckResult {
|
|
64
|
+
ok: boolean;
|
|
65
|
+
diagnostics: ZeroDiagnostic[];
|
|
66
|
+
/** Raw JSON output from zero check --json */
|
|
67
|
+
raw: Record<string, unknown>;
|
|
68
|
+
}
|
|
69
|
+
/** Result of `zero graph --json`. */
|
|
70
|
+
interface ZeroGraphResult {
|
|
71
|
+
ok: boolean;
|
|
72
|
+
/** Parsed symbol list from the graph output. */
|
|
73
|
+
symbols: ZeroGraphSymbol[];
|
|
74
|
+
/** Parsed function list from the graph output. */
|
|
75
|
+
functions: ZeroGraphFunction[];
|
|
76
|
+
/** Raw JSON output from zero graph. */
|
|
77
|
+
raw: Record<string, unknown>;
|
|
78
|
+
}
|
|
79
|
+
interface ZeroGraphSymbol {
|
|
80
|
+
name: string;
|
|
81
|
+
module: string;
|
|
82
|
+
kind: string;
|
|
83
|
+
public: boolean;
|
|
84
|
+
effects: string[];
|
|
85
|
+
}
|
|
86
|
+
interface ZeroGraphFunction {
|
|
87
|
+
name: string;
|
|
88
|
+
kind: string;
|
|
89
|
+
public: boolean;
|
|
90
|
+
params: number;
|
|
91
|
+
returnType: string;
|
|
92
|
+
raises: boolean;
|
|
93
|
+
effects: string[];
|
|
94
|
+
allocationBehavior: string;
|
|
95
|
+
targetSupport: {
|
|
96
|
+
status: string;
|
|
97
|
+
missingCapabilities: string[];
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
/** Result of `zero size --json`. */
|
|
101
|
+
interface ZeroSizeResult {
|
|
102
|
+
ok: boolean;
|
|
103
|
+
/** Structured size/runtime analysis from the real CLI. */
|
|
104
|
+
portableRuntime?: ZeroPortableRuntime;
|
|
105
|
+
/** Raw JSON output from zero size. */
|
|
106
|
+
raw: Record<string, unknown>;
|
|
107
|
+
}
|
|
108
|
+
interface ZeroPortableRuntime {
|
|
109
|
+
target: string;
|
|
110
|
+
runtimeKind: string;
|
|
111
|
+
portable: boolean;
|
|
112
|
+
imports: {
|
|
113
|
+
functionCount: number;
|
|
114
|
+
functions: string[];
|
|
115
|
+
module: string | null;
|
|
116
|
+
};
|
|
117
|
+
memoryFloor?: {
|
|
118
|
+
floorBytes: number;
|
|
119
|
+
minimumPages: number;
|
|
120
|
+
};
|
|
121
|
+
capabilityRestrictions?: {
|
|
122
|
+
filesystem?: string;
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
/** Result of `zero fix --plan --json`. */
|
|
126
|
+
interface ZeroFixResult {
|
|
127
|
+
ok: boolean;
|
|
128
|
+
fixes: ZeroFixSuggestion[];
|
|
129
|
+
raw: Record<string, unknown>;
|
|
130
|
+
}
|
|
131
|
+
/** A single repair suggestion from `zero fix --plan --json`. */
|
|
132
|
+
interface ZeroFixSuggestion {
|
|
133
|
+
/** Fix identifier, e.g. "repair-syntax". */
|
|
134
|
+
id: string;
|
|
135
|
+
/** Associated diagnostic code, e.g. "PAR100". */
|
|
136
|
+
diagnosticCode: string;
|
|
137
|
+
/** Safety level: "safe" | "requires-human-review". */
|
|
138
|
+
safety: string;
|
|
139
|
+
/** Human-readable summary of the fix. */
|
|
140
|
+
summary: string;
|
|
141
|
+
/** Whether the fix can be applied automatically. */
|
|
142
|
+
appliesEdits: boolean;
|
|
143
|
+
}
|
|
144
|
+
/** Result of `zero build`. */
|
|
145
|
+
interface ZeroBuildResult {
|
|
146
|
+
ok: boolean;
|
|
147
|
+
/** Path to compiled output */
|
|
148
|
+
outputPath?: string;
|
|
149
|
+
diagnostics: ZeroDiagnostic[];
|
|
150
|
+
}
|
|
151
|
+
/** Options for `zero build`. */
|
|
152
|
+
interface ZeroBuildOptions {
|
|
153
|
+
/** Output path for compiled binary/wasm. */
|
|
154
|
+
out?: string;
|
|
155
|
+
/** Target triple, e.g., "linux-musl-x64" or "wasm32-web". */
|
|
156
|
+
target?: string;
|
|
157
|
+
/** Emit format: "exe" (default), "object", or "wasm". */
|
|
158
|
+
emit?: "exe" | "object" | "wasm";
|
|
159
|
+
}
|
|
160
|
+
/** Configuration for registering a Zero function as an OrigenTool. */
|
|
161
|
+
interface ZeroToolConfig {
|
|
162
|
+
/** The Zero function to expose as a tool. */
|
|
163
|
+
functionName: string;
|
|
164
|
+
/** Human-readable description for the LLM. Required. */
|
|
165
|
+
description: string;
|
|
166
|
+
/** Execution mode for the compiled Zero program. */
|
|
167
|
+
execution: ZeroToolExecution;
|
|
168
|
+
/** Custom parameter schema for the OrigenTool. */
|
|
169
|
+
parameters?: Record<string, unknown>;
|
|
170
|
+
/** Origen-compatible Zod inputSchema. */
|
|
171
|
+
inputSchema?: unknown;
|
|
172
|
+
/** Zero compiler for verification before registration. Optional. */
|
|
173
|
+
compiler?: ZeroCompilerLike;
|
|
174
|
+
/** Whether to verify the tool compiles cleanly before registering. Default: true */
|
|
175
|
+
verify?: boolean;
|
|
176
|
+
}
|
|
177
|
+
/** How a Zero tool executes. Exactly one mode must be set. */
|
|
178
|
+
type ZeroToolExecution = {
|
|
179
|
+
mode: "subprocess";
|
|
180
|
+
executablePath: string;
|
|
181
|
+
} | {
|
|
182
|
+
mode: "http";
|
|
183
|
+
endpoint: string;
|
|
184
|
+
apiKey?: string;
|
|
185
|
+
headers?: Record<string, string>;
|
|
186
|
+
fetch?: typeof globalThis.fetch;
|
|
187
|
+
} | {
|
|
188
|
+
mode: "wasm";
|
|
189
|
+
wasmBytes: ArrayBuffer | WebAssembly.Module;
|
|
190
|
+
};
|
|
191
|
+
/** Result of compileAndRegister on success. */
|
|
192
|
+
interface ZeroToolRegistrationSuccess {
|
|
193
|
+
tools: unknown[];
|
|
194
|
+
}
|
|
195
|
+
/** Result of compileAndRegister on failure. */
|
|
196
|
+
interface ZeroToolRegistrationFailure {
|
|
197
|
+
errors: ZeroDiagnostic[];
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export type { ZeroBuildOptions as Z, ZeroBuildResult as a, ZeroCheckResult as b, ZeroCompilerConfig as c, ZeroCompilerLike as d, ZeroDiagnostic as e, ZeroFixResult as f, ZeroFixSuggestion as g, ZeroGraphResult as h, ZeroHTTPCompilerConfig as i, ZeroSizeResult as j, ZeroSourceFile as k, ZeroToolConfig as l, ZeroToolExecution as m, ZeroToolRegistrationFailure as n, ZeroToolRegistrationSuccess as o };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @moikapy/origen-zero — WASI runtime for Zero WASM modules
|
|
3
|
+
*
|
|
4
|
+
* Full WASI snapshot preview 1 implementation matching the Zero CLI's
|
|
5
|
+
* wasm-runtime-smoke.mjs. Supports: args, env, fd_read, fd_write,
|
|
6
|
+
* path_open, fd_close, fd_filestat_get, fd_readdir, path_mkdir,
|
|
7
|
+
* path_remove_directory, path_unlink_file, path_rename.
|
|
8
|
+
*
|
|
9
|
+
* Zero programs that use World (stdout/stderr), std.args, std.env,
|
|
10
|
+
* or std.fs (Fs resource) all route through these WASI imports.
|
|
11
|
+
*
|
|
12
|
+
* Uses only Uint8Array/TextEncoder/TextDecoder — no Node.js Buffer.
|
|
13
|
+
* Works in Cloudflare Workers, browsers, and Node.js.
|
|
14
|
+
*/
|
|
15
|
+
interface ZeroWASIRuntimeConfig {
|
|
16
|
+
/** Command-line args (default: ["zero"]). */
|
|
17
|
+
args?: string[];
|
|
18
|
+
/** Environment variables (default: []). Format: "KEY=VALUE". */
|
|
19
|
+
env?: string[];
|
|
20
|
+
/** Pre-populated files: Map<path, Uint8Array>. */
|
|
21
|
+
files?: Map<string, Uint8Array>;
|
|
22
|
+
/** Pre-populated directories. */
|
|
23
|
+
dirs?: Set<string>;
|
|
24
|
+
}
|
|
25
|
+
interface ZeroWASIRuntime {
|
|
26
|
+
/** WASI imports to pass to WebAssembly.instantiate(). */
|
|
27
|
+
imports: Record<string, Record<string, WebAssembly.ImportValue>>;
|
|
28
|
+
/** Get all captured stdout output. */
|
|
29
|
+
getStdout(): string;
|
|
30
|
+
/** Get all captured stderr output. */
|
|
31
|
+
getStderr(): string;
|
|
32
|
+
/** Get the virtual filesystem state. */
|
|
33
|
+
getFiles(): Map<string, Uint8Array>;
|
|
34
|
+
/** Get the virtual directory set. */
|
|
35
|
+
getDirs(): Set<string>;
|
|
36
|
+
/** Set the instance reference (called after instantiation). */
|
|
37
|
+
setInstance(instance: WebAssembly.Instance): void;
|
|
38
|
+
}
|
|
39
|
+
declare function createZeroWASIRuntime(config?: ZeroWASIRuntimeConfig): ZeroWASIRuntime;
|
|
40
|
+
|
|
41
|
+
export { type ZeroWASIRuntime, type ZeroWASIRuntimeConfig, createZeroWASIRuntime };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { OrigenTool } from '@moikapy/origen';
|
|
2
|
+
import { ZeroWASIRuntimeConfig } from './wasi-runtime.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @moikapy/origen-zero — WASM tool execution
|
|
6
|
+
*
|
|
7
|
+
* Executes compiled Zero WASM modules in-process via WebAssembly.instantiate().
|
|
8
|
+
* Works in Cloudflare Workers, browsers, and Node.js — no subprocess needed.
|
|
9
|
+
*
|
|
10
|
+
* WASM modules compiled from Zero export:
|
|
11
|
+
* - `memory`: WebAssembly.Memory (1+ pages, 64KB each)
|
|
12
|
+
* - `main()`: Program entry point (returns i32, 0 = success)
|
|
13
|
+
* They import WASI snapshot preview 1 functions for I/O.
|
|
14
|
+
*
|
|
15
|
+
* For Origen tool invocation, args are passed via WASI (args_get/args_sizes_get)
|
|
16
|
+
* for wasm32-wasi targets, or encoded to memory for wasm32-web targets that
|
|
17
|
+
* read from environ.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
interface ZeroWASMToolConfig {
|
|
21
|
+
/** Tool function name. */
|
|
22
|
+
functionName: string;
|
|
23
|
+
/** Human-readable description for the LLM. */
|
|
24
|
+
description: string;
|
|
25
|
+
/** Compiled WASM module bytes. */
|
|
26
|
+
wasmBytes: ArrayBuffer | WebAssembly.Module;
|
|
27
|
+
/** Optional pre-instantiated module cache (for Workers global scope). */
|
|
28
|
+
module?: WebAssembly.Module;
|
|
29
|
+
/** WASI runtime config (args, env, files, dirs). */
|
|
30
|
+
runtimeConfig?: ZeroWASIRuntimeConfig;
|
|
31
|
+
/** Custom parameter schema for the OrigenTool. */
|
|
32
|
+
parameters?: Record<string, unknown>;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Create an OrigenTool that executes a compiled Zero WASM module in-process.
|
|
36
|
+
*
|
|
37
|
+
* The tool instantiates the WASM module with a full WASI runtime,
|
|
38
|
+
* passes args via WASI args_get, calls the exported main() function,
|
|
39
|
+
* and returns the stdout output.
|
|
40
|
+
*
|
|
41
|
+
* Works in Cloudflare Workers, browsers, and Node.js.
|
|
42
|
+
*/
|
|
43
|
+
declare function createZeroWASMTool(config: ZeroWASMToolConfig): OrigenTool;
|
|
44
|
+
/**
|
|
45
|
+
* Create multiple tools from a single Zero WASM module.
|
|
46
|
+
* If the module exports a single main(), creates one tool.
|
|
47
|
+
* Future: parse module exports to discover multiple functions.
|
|
48
|
+
*/
|
|
49
|
+
declare function createZeroWASMTools(wasmBytes: ArrayBuffer | WebAssembly.Module, options?: {
|
|
50
|
+
descriptions?: Record<string, string>;
|
|
51
|
+
parameters?: Record<string, Record<string, unknown>>;
|
|
52
|
+
}): OrigenTool[];
|
|
53
|
+
|
|
54
|
+
export { type ZeroWASMToolConfig, createZeroWASMTool, createZeroWASMTools };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@moikapy/origen-zero",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Bridge package connecting Origen agents to ZeroLang compiler and runtime",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"./tools": {
|
|
16
|
+
"types": "./dist/tools.d.ts",
|
|
17
|
+
"import": "./dist/tools.js",
|
|
18
|
+
"default": "./dist/tools.js"
|
|
19
|
+
},
|
|
20
|
+
"./compiler": {
|
|
21
|
+
"types": "./dist/compiler.d.ts",
|
|
22
|
+
"import": "./dist/compiler.js",
|
|
23
|
+
"default": "./dist/compiler.js"
|
|
24
|
+
},
|
|
25
|
+
"./http-compiler": {
|
|
26
|
+
"types": "./dist/http-compiler.d.ts",
|
|
27
|
+
"import": "./dist/http-compiler.js",
|
|
28
|
+
"default": "./dist/http-compiler.js"
|
|
29
|
+
},
|
|
30
|
+
"./wasm-tool": {
|
|
31
|
+
"types": "./dist/wasm-tool.d.ts",
|
|
32
|
+
"import": "./dist/wasm-tool.js",
|
|
33
|
+
"default": "./dist/wasm-tool.js"
|
|
34
|
+
},
|
|
35
|
+
"./wasi-runtime": {
|
|
36
|
+
"types": "./dist/wasi-runtime.d.ts",
|
|
37
|
+
"import": "./dist/wasi-runtime.js",
|
|
38
|
+
"default": "./dist/wasi-runtime.js"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"files": [
|
|
42
|
+
"dist/"
|
|
43
|
+
],
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "tsup --no-dts --no-sourcemap",
|
|
46
|
+
"build:release": "tsup",
|
|
47
|
+
"test": "vitest run",
|
|
48
|
+
"typecheck": "tsc --noEmit",
|
|
49
|
+
"prepublishOnly": "bun run build:release"
|
|
50
|
+
},
|
|
51
|
+
"peerDependencies": {
|
|
52
|
+
"@moikapy/origen": "^0.6.0"
|
|
53
|
+
},
|
|
54
|
+
"dependencies": {
|
|
55
|
+
"zod": "^4.4.2"
|
|
56
|
+
},
|
|
57
|
+
"devDependencies": {
|
|
58
|
+
"@moikapy/origen": "^0.6.0",
|
|
59
|
+
"tsup": "^8.5.1",
|
|
60
|
+
"typescript": "^5",
|
|
61
|
+
"vitest": "^3"
|
|
62
|
+
}
|
|
63
|
+
}
|