@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,42 @@
|
|
|
1
|
+
import { d as ZeroCompilerLike, c as ZeroCompilerConfig, k as ZeroSourceFile, b as ZeroCheckResult, h as ZeroGraphResult, j as ZeroSizeResult, f as ZeroFixResult, Z as ZeroBuildOptions, a as ZeroBuildResult } from './types-Dc-cDRjG.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @moikapy/origen-zero — ZeroCompiler class
|
|
5
|
+
*
|
|
6
|
+
* Wraps the Zero CLI binary, invoking it as a subprocess with --json flags
|
|
7
|
+
* and parsing the structured output into typed results.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/** Temp directory for Zero compilation artifacts. Shared across modules. */
|
|
11
|
+
declare const TEMP_DIR = ".zero-origen/tmp";
|
|
12
|
+
declare class ZeroCompiler implements ZeroCompilerLike {
|
|
13
|
+
private readonly binaryPath;
|
|
14
|
+
private readonly workingDir;
|
|
15
|
+
private readonly timeout;
|
|
16
|
+
constructor(config?: ZeroCompilerConfig);
|
|
17
|
+
/** Check a Zero file or package for errors. Returns structured diagnostics. */
|
|
18
|
+
check(source: string | ZeroSourceFile): Promise<ZeroCheckResult>;
|
|
19
|
+
/** Get the dependency graph for a Zero package. */
|
|
20
|
+
graph(source: string | ZeroSourceFile): Promise<ZeroGraphResult>;
|
|
21
|
+
/** Get size estimates for functions in a Zero file. */
|
|
22
|
+
size(source: string | ZeroSourceFile): Promise<ZeroSizeResult>;
|
|
23
|
+
/** Get repair suggestions for a Zero program. */
|
|
24
|
+
fix(source: string | ZeroSourceFile): Promise<ZeroFixResult>;
|
|
25
|
+
/** Build a Zero file to a native executable. */
|
|
26
|
+
build(source: string | ZeroSourceFile, options?: ZeroBuildOptions): Promise<ZeroBuildResult>;
|
|
27
|
+
/** Get a human-readable explanation for a diagnostic code. */
|
|
28
|
+
explain(diagnosticCode: string): Promise<string>;
|
|
29
|
+
/** Resolve source to a file path. If inline content, write to temp dir. */
|
|
30
|
+
private writeSource;
|
|
31
|
+
/** Clean up temp files (best effort — ignore errors). */
|
|
32
|
+
private cleanup;
|
|
33
|
+
/**
|
|
34
|
+
* Execute the Zero CLI binary with the given arguments.
|
|
35
|
+
* Returns stdout on success (exit code 0).
|
|
36
|
+
* Throws ZeroCompilerNotFoundError if the binary isn't found.
|
|
37
|
+
* Throws ZeroTimeoutError if the invocation exceeds the timeout.
|
|
38
|
+
*/
|
|
39
|
+
private exec;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export { TEMP_DIR, ZeroCompiler };
|
package/dist/compiler.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { d as ZeroCompilerLike, i as ZeroHTTPCompilerConfig, k as ZeroSourceFile, b as ZeroCheckResult, h as ZeroGraphResult, j as ZeroSizeResult, f as ZeroFixResult, Z as ZeroBuildOptions, a as ZeroBuildResult } from './types-Dc-cDRjG.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @moikapy/origen-zero — ZeroHTTPCompiler
|
|
5
|
+
*
|
|
6
|
+
* HTTP-based Zero compiler client that works in Cloudflare Workers
|
|
7
|
+
* (and any environment with fetch). Calls a Zero compiler service
|
|
8
|
+
* instead of spawning a subprocess.
|
|
9
|
+
*
|
|
10
|
+
* The Zero compiler service must implement these endpoints:
|
|
11
|
+
* POST /check { source, path? } → ZeroCheckResult
|
|
12
|
+
* POST /graph { source, path? } → ZeroGraphResult
|
|
13
|
+
* POST /size { source, path? } → ZeroSizeResult
|
|
14
|
+
* POST /fix { source, path? } → ZeroFixResult
|
|
15
|
+
* POST /build { source, path?, options? } → ZeroBuildResult
|
|
16
|
+
* GET /explain/:code → string
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
declare class ZeroHTTPCompiler implements ZeroCompilerLike {
|
|
20
|
+
private readonly endpoint;
|
|
21
|
+
private readonly apiKey;
|
|
22
|
+
private readonly headers;
|
|
23
|
+
private readonly timeout;
|
|
24
|
+
private readonly fetchFn;
|
|
25
|
+
constructor(config: ZeroHTTPCompilerConfig);
|
|
26
|
+
check(source: string | ZeroSourceFile): Promise<ZeroCheckResult>;
|
|
27
|
+
graph(source: string | ZeroSourceFile): Promise<ZeroGraphResult>;
|
|
28
|
+
size(source: string | ZeroSourceFile): Promise<ZeroSizeResult>;
|
|
29
|
+
fix(source: string | ZeroSourceFile): Promise<ZeroFixResult>;
|
|
30
|
+
build(source: string | ZeroSourceFile, options?: ZeroBuildOptions): Promise<ZeroBuildResult>;
|
|
31
|
+
explain(diagnosticCode: string): Promise<string>;
|
|
32
|
+
private sourceToBody;
|
|
33
|
+
private post;
|
|
34
|
+
private postJson;
|
|
35
|
+
private postRaw;
|
|
36
|
+
/** fetch with timeout. */
|
|
37
|
+
private fetchWithTimeout;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export { ZeroHTTPCompiler };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { e as ZeroDiagnostic, b as ZeroCheckResult, f as ZeroFixResult, h as ZeroGraphResult, j as ZeroSizeResult, d as ZeroCompilerLike, c as ZeroCompilerConfig } from './types-Dc-cDRjG.js';
|
|
2
|
+
export { Z as ZeroBuildOptions, a as ZeroBuildResult, g as ZeroFixSuggestion, i as ZeroHTTPCompilerConfig, k as ZeroSourceFile, l as ZeroToolConfig, m as ZeroToolExecution, n as ZeroToolRegistrationFailure, o as ZeroToolRegistrationSuccess } from './types-Dc-cDRjG.js';
|
|
3
|
+
export { ZeroCompiler } from './compiler.js';
|
|
4
|
+
export { ZeroHTTPCompiler } from './http-compiler.js';
|
|
5
|
+
export { createZeroWASMTool, createZeroWASMTools } from './wasm-tool.js';
|
|
6
|
+
export { ZeroWASIRuntime, ZeroWASIRuntimeConfig, createZeroWASIRuntime } from './wasi-runtime.js';
|
|
7
|
+
import { z } from 'zod';
|
|
8
|
+
export { compileAndRegister, createZeroTool, createZeroToolsFromProgram } from './tools.js';
|
|
9
|
+
import { OrigenTool } from '@moikapy/origen';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @moikapy/origen-zero — Error hierarchy
|
|
13
|
+
*
|
|
14
|
+
* All errors extend ZeroError for consistent catch patterns.
|
|
15
|
+
*/
|
|
16
|
+
/** Base error for all origen-zero errors. */
|
|
17
|
+
declare class ZeroError extends Error {
|
|
18
|
+
readonly code: string;
|
|
19
|
+
readonly diagnostics?: ZeroDiagnostic[] | undefined;
|
|
20
|
+
constructor(message: string, code: string, diagnostics?: ZeroDiagnostic[] | undefined);
|
|
21
|
+
}
|
|
22
|
+
/** Thrown when the `zero` binary cannot be found on PATH or configured path. */
|
|
23
|
+
declare class ZeroCompilerNotFoundError extends ZeroError {
|
|
24
|
+
constructor(binaryPath: string);
|
|
25
|
+
}
|
|
26
|
+
/** Thrown when a Zero source file has diagnostic errors/warnings. */
|
|
27
|
+
declare class ZeroCheckFailedError extends ZeroError {
|
|
28
|
+
constructor(diagnostics: ZeroDiagnostic[]);
|
|
29
|
+
}
|
|
30
|
+
/** Thrown when `zero build` fails (produces no output binary). */
|
|
31
|
+
declare class ZeroBuildFailedError extends ZeroError {
|
|
32
|
+
constructor(diagnostics: ZeroDiagnostic[]);
|
|
33
|
+
}
|
|
34
|
+
/** Thrown when a Zero CLI invocation exceeds the configured timeout. */
|
|
35
|
+
declare class ZeroTimeoutError extends ZeroError {
|
|
36
|
+
constructor(command: string, timeout: number);
|
|
37
|
+
}
|
|
38
|
+
/** Thrown when a Zero HTTP compiler request fails. */
|
|
39
|
+
declare class ZeroHTTPError extends ZeroError {
|
|
40
|
+
readonly status: number;
|
|
41
|
+
readonly url: string;
|
|
42
|
+
constructor(status: number, url: string, body: string);
|
|
43
|
+
}
|
|
44
|
+
/** Thrown when a compiled Zero binary returns a non-zero exit code. */
|
|
45
|
+
declare class ZeroExecutionError extends ZeroError {
|
|
46
|
+
readonly exitCode: number;
|
|
47
|
+
readonly stderr: string;
|
|
48
|
+
constructor(exitCode: number, stderr: string);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @moikapy/origen-zero — Zero CLI output parser
|
|
53
|
+
*
|
|
54
|
+
* Parses JSON output from `zero check --json`, `zero graph --json`,
|
|
55
|
+
* `zero size --json`, and `zero fix --plan --json` into typed structures.
|
|
56
|
+
*/
|
|
57
|
+
|
|
58
|
+
declare const ZeroDiagnosticSchema: z.ZodObject<{
|
|
59
|
+
code: z.ZodString;
|
|
60
|
+
severity: z.ZodEnum<{
|
|
61
|
+
error: "error";
|
|
62
|
+
warning: "warning";
|
|
63
|
+
info: "info";
|
|
64
|
+
}>;
|
|
65
|
+
message: z.ZodString;
|
|
66
|
+
line: z.ZodNumber;
|
|
67
|
+
column: z.ZodOptional<z.ZodNumber>;
|
|
68
|
+
repair: z.ZodOptional<z.ZodObject<{
|
|
69
|
+
id: z.ZodString;
|
|
70
|
+
suggestion: z.ZodOptional<z.ZodString>;
|
|
71
|
+
}, z.core.$strip>>;
|
|
72
|
+
}, z.core.$strip>;
|
|
73
|
+
declare const ZeroCheckResultSchema: z.ZodObject<{
|
|
74
|
+
ok: z.ZodBoolean;
|
|
75
|
+
diagnostics: z.ZodArray<z.ZodObject<{
|
|
76
|
+
code: z.ZodString;
|
|
77
|
+
severity: z.ZodEnum<{
|
|
78
|
+
error: "error";
|
|
79
|
+
warning: "warning";
|
|
80
|
+
info: "info";
|
|
81
|
+
}>;
|
|
82
|
+
message: z.ZodString;
|
|
83
|
+
line: z.ZodNumber;
|
|
84
|
+
column: z.ZodOptional<z.ZodNumber>;
|
|
85
|
+
repair: z.ZodOptional<z.ZodObject<{
|
|
86
|
+
id: z.ZodString;
|
|
87
|
+
suggestion: z.ZodOptional<z.ZodString>;
|
|
88
|
+
}, z.core.$strip>>;
|
|
89
|
+
}, z.core.$strip>>;
|
|
90
|
+
raw: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
91
|
+
}, z.core.$strip>;
|
|
92
|
+
declare const ZeroGraphResultSchema: z.ZodObject<{
|
|
93
|
+
ok: z.ZodBoolean;
|
|
94
|
+
graph: z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString>>;
|
|
95
|
+
raw: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
96
|
+
}, z.core.$strip>;
|
|
97
|
+
declare const ZeroSizeResultSchema: z.ZodObject<{
|
|
98
|
+
ok: z.ZodBoolean;
|
|
99
|
+
sizes: z.ZodRecord<z.ZodString, z.ZodNumber>;
|
|
100
|
+
raw: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
101
|
+
}, z.core.$strip>;
|
|
102
|
+
declare const ZeroFixSuggestionSchema: z.ZodObject<{
|
|
103
|
+
id: z.ZodString;
|
|
104
|
+
diagnosticCode: z.ZodString;
|
|
105
|
+
safety: z.ZodString;
|
|
106
|
+
summary: z.ZodString;
|
|
107
|
+
appliesEdits: z.ZodBoolean;
|
|
108
|
+
}, z.core.$strip>;
|
|
109
|
+
declare const ZeroFixResultSchema: z.ZodObject<{
|
|
110
|
+
ok: z.ZodBoolean;
|
|
111
|
+
fixes: z.ZodArray<z.ZodObject<{
|
|
112
|
+
id: z.ZodString;
|
|
113
|
+
diagnosticCode: z.ZodString;
|
|
114
|
+
safety: z.ZodString;
|
|
115
|
+
summary: z.ZodString;
|
|
116
|
+
appliesEdits: z.ZodBoolean;
|
|
117
|
+
}, z.core.$strip>>;
|
|
118
|
+
raw: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
119
|
+
}, z.core.$strip>;
|
|
120
|
+
/** Parse a single diagnostic from raw JSON. */
|
|
121
|
+
declare function parseDiagnostic(d: Record<string, unknown>): ZeroDiagnostic;
|
|
122
|
+
/** Parse `zero check --json` output into a typed ZeroCheckResult. */
|
|
123
|
+
declare function parseCheckOutput(raw: string): ZeroCheckResult;
|
|
124
|
+
/** Parse `zero graph --json` output into a typed ZeroGraphResult. */
|
|
125
|
+
declare function parseGraphOutput(raw: string): ZeroGraphResult;
|
|
126
|
+
/** Parse `zero size --json` output into a typed ZeroSizeResult. */
|
|
127
|
+
declare function parseSizeOutput(raw: string): ZeroSizeResult;
|
|
128
|
+
/** Parse `zero fix --plan --json` output into a typed ZeroFixResult. */
|
|
129
|
+
declare function parseFixOutput(raw: string): ZeroFixResult;
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* @moikapy/origen-zero — Interactive compiler tools
|
|
133
|
+
*
|
|
134
|
+
* Creates four OrigenTools that let the LLM write, check, and fix
|
|
135
|
+
* Zero programs during a conversation:
|
|
136
|
+
* - zero_check: Check a Zero program for errors
|
|
137
|
+
* - zero_graph: Get the dependency graph
|
|
138
|
+
* - zero_size: Get size estimates for functions
|
|
139
|
+
* - zero_fix: Plan repairs for a Zero program
|
|
140
|
+
*/
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Create the set of interactive Zero compiler tools that let the LLM
|
|
144
|
+
* write, check, and fix Zero programs during a conversation.
|
|
145
|
+
*
|
|
146
|
+
* Accepts either a ZeroCompilerLike instance (ZeroCompiler or ZeroHTTPCompiler)
|
|
147
|
+
* or a ZeroCompilerConfig for the local CLI compiler.
|
|
148
|
+
*/
|
|
149
|
+
declare function createZeroCompilerTools(compiler?: ZeroCompilerLike | ZeroCompilerConfig): OrigenTool[];
|
|
150
|
+
|
|
151
|
+
export { ZeroBuildFailedError, ZeroCheckFailedError, ZeroCheckResult, ZeroCheckResultSchema, ZeroCompilerConfig, ZeroCompilerLike, ZeroCompilerNotFoundError, ZeroDiagnostic, ZeroDiagnosticSchema, ZeroError, ZeroExecutionError, ZeroFixResult, ZeroFixResultSchema, ZeroFixSuggestionSchema, ZeroGraphResult, ZeroGraphResultSchema, ZeroHTTPError, ZeroSizeResult, ZeroSizeResultSchema, ZeroTimeoutError, createZeroCompilerTools, parseCheckOutput, parseDiagnostic, parseFixOutput, parseGraphOutput, parseSizeOutput };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import {
|
|
2
|
+
compileAndRegister,
|
|
3
|
+
createZeroTool,
|
|
4
|
+
createZeroToolsFromProgram
|
|
5
|
+
} from "./chunk-SDOZC7ZI.js";
|
|
6
|
+
import {
|
|
7
|
+
ZeroCompiler
|
|
8
|
+
} from "./chunk-DE5JDJKT.js";
|
|
9
|
+
import {
|
|
10
|
+
ZeroHTTPCompiler
|
|
11
|
+
} from "./chunk-J5UPC5XT.js";
|
|
12
|
+
import {
|
|
13
|
+
ZeroBuildFailedError,
|
|
14
|
+
ZeroCheckFailedError,
|
|
15
|
+
ZeroCheckResultSchema,
|
|
16
|
+
ZeroCompilerNotFoundError,
|
|
17
|
+
ZeroDiagnosticSchema,
|
|
18
|
+
ZeroError,
|
|
19
|
+
ZeroExecutionError,
|
|
20
|
+
ZeroFixResultSchema,
|
|
21
|
+
ZeroFixSuggestionSchema,
|
|
22
|
+
ZeroGraphResultSchema,
|
|
23
|
+
ZeroHTTPError,
|
|
24
|
+
ZeroSizeResultSchema,
|
|
25
|
+
ZeroTimeoutError,
|
|
26
|
+
parseCheckOutput,
|
|
27
|
+
parseDiagnostic,
|
|
28
|
+
parseFixOutput,
|
|
29
|
+
parseGraphOutput,
|
|
30
|
+
parseSizeOutput
|
|
31
|
+
} from "./chunk-6RAZN3WM.js";
|
|
32
|
+
import {
|
|
33
|
+
createZeroWASMTool,
|
|
34
|
+
createZeroWASMTools
|
|
35
|
+
} from "./chunk-PJFVSOEI.js";
|
|
36
|
+
import {
|
|
37
|
+
createZeroWASIRuntime
|
|
38
|
+
} from "./chunk-QUQPQFU6.js";
|
|
39
|
+
|
|
40
|
+
// src/compiler-tools.ts
|
|
41
|
+
function createZeroCompilerTools(compiler) {
|
|
42
|
+
const zero = !compiler ? new ZeroCompiler() : "check" in compiler && typeof compiler.check === "function" ? compiler : new ZeroCompiler(compiler);
|
|
43
|
+
const checkTool = {
|
|
44
|
+
name: "zero_check",
|
|
45
|
+
description: `Check a Zero program for errors. Returns structured diagnostics with repair suggestions. Write your Zero source code in the "source" parameter.`,
|
|
46
|
+
parameters: {
|
|
47
|
+
type: "object",
|
|
48
|
+
properties: {
|
|
49
|
+
source: {
|
|
50
|
+
type: "string",
|
|
51
|
+
description: "Zero source code to check"
|
|
52
|
+
},
|
|
53
|
+
path: {
|
|
54
|
+
type: "string",
|
|
55
|
+
description: "File path hint for error reporting (optional)"
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
required: ["source"]
|
|
59
|
+
},
|
|
60
|
+
async execute(args) {
|
|
61
|
+
const source = String(args.source ?? "");
|
|
62
|
+
const path = args.path ? String(args.path) : void 0;
|
|
63
|
+
const result = await zero.check(path ? { path, content: source } : source);
|
|
64
|
+
if (result.ok) {
|
|
65
|
+
return "\u2705 Zero program checks passed with no errors.";
|
|
66
|
+
}
|
|
67
|
+
const lines = result.diagnostics.map((d) => {
|
|
68
|
+
let line = `[${d.code}] ${d.severity}: ${d.message}`;
|
|
69
|
+
if (d.line) line += ` (line ${d.line})`;
|
|
70
|
+
if (d.column) line += `:${d.column}`;
|
|
71
|
+
if (d.repair) line += ` \u2192 Fix: ${d.repair.suggestion ?? d.repair.id}`;
|
|
72
|
+
return line;
|
|
73
|
+
});
|
|
74
|
+
return `\u274C Zero program has ${result.diagnostics.length} diagnostic(s):
|
|
75
|
+
${lines.join("\n")}`;
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
const graphTool = {
|
|
79
|
+
name: "zero_graph",
|
|
80
|
+
description: `Get the dependency graph of a Zero program. Shows which functions depend on which other functions.`,
|
|
81
|
+
parameters: {
|
|
82
|
+
type: "object",
|
|
83
|
+
properties: {
|
|
84
|
+
source: {
|
|
85
|
+
type: "string",
|
|
86
|
+
description: "Zero source code to analyze"
|
|
87
|
+
},
|
|
88
|
+
path: {
|
|
89
|
+
type: "string",
|
|
90
|
+
description: "File path hint (optional)"
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
required: ["source"]
|
|
94
|
+
},
|
|
95
|
+
async execute(args) {
|
|
96
|
+
const source = String(args.source ?? "");
|
|
97
|
+
const path = args.path ? String(args.path) : void 0;
|
|
98
|
+
const result = await zero.graph(path ? { path, content: source } : source);
|
|
99
|
+
return JSON.stringify({ symbols: result.symbols, functions: result.functions }, null, 2);
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
const sizeTool = {
|
|
103
|
+
name: "zero_size",
|
|
104
|
+
description: `Get size estimates for functions in a Zero program. Returns estimated binary size per function.`,
|
|
105
|
+
parameters: {
|
|
106
|
+
type: "object",
|
|
107
|
+
properties: {
|
|
108
|
+
source: {
|
|
109
|
+
type: "string",
|
|
110
|
+
description: "Zero source code to size-report"
|
|
111
|
+
},
|
|
112
|
+
path: {
|
|
113
|
+
type: "string",
|
|
114
|
+
description: "File path hint (optional)"
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
required: ["source"]
|
|
118
|
+
},
|
|
119
|
+
async execute(args) {
|
|
120
|
+
const source = String(args.source ?? "");
|
|
121
|
+
const path = args.path ? String(args.path) : void 0;
|
|
122
|
+
const result = await zero.size(path ? { path, content: source } : source);
|
|
123
|
+
return JSON.stringify(result.portableRuntime ?? result.raw, null, 2);
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
const fixTool = {
|
|
127
|
+
name: "zero_fix",
|
|
128
|
+
description: `Plan repairs for a Zero program. Returns suggested fixes with line numbers and descriptions. Use this after zero_check reports errors.`,
|
|
129
|
+
parameters: {
|
|
130
|
+
type: "object",
|
|
131
|
+
properties: {
|
|
132
|
+
source: {
|
|
133
|
+
type: "string",
|
|
134
|
+
description: "Zero source code to repair"
|
|
135
|
+
},
|
|
136
|
+
path: {
|
|
137
|
+
type: "string",
|
|
138
|
+
description: "File path hint (optional)"
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
required: ["source"]
|
|
142
|
+
},
|
|
143
|
+
async execute(args) {
|
|
144
|
+
const source = String(args.source ?? "");
|
|
145
|
+
const path = args.path ? String(args.path) : void 0;
|
|
146
|
+
const result = await zero.fix(path ? { path, content: source } : source);
|
|
147
|
+
if (result.ok && result.fixes.length === 0) {
|
|
148
|
+
return "\u2705 No fixes needed \u2014 program is clean.";
|
|
149
|
+
}
|
|
150
|
+
const lines = result.fixes.map((f) => {
|
|
151
|
+
let line = `[${f.diagnosticCode}] ${f.summary} (${f.safety})`;
|
|
152
|
+
if (f.appliesEdits) line += ` [auto-fixable]`;
|
|
153
|
+
return line;
|
|
154
|
+
});
|
|
155
|
+
return `\u{1F4DD} ${result.fixes.length} fix suggestion(s):
|
|
156
|
+
${lines.join("\n")}`;
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
return [checkTool, graphTool, sizeTool, fixTool];
|
|
160
|
+
}
|
|
161
|
+
export {
|
|
162
|
+
ZeroBuildFailedError,
|
|
163
|
+
ZeroCheckFailedError,
|
|
164
|
+
ZeroCheckResultSchema,
|
|
165
|
+
ZeroCompiler,
|
|
166
|
+
ZeroCompilerNotFoundError,
|
|
167
|
+
ZeroDiagnosticSchema,
|
|
168
|
+
ZeroError,
|
|
169
|
+
ZeroExecutionError,
|
|
170
|
+
ZeroFixResultSchema,
|
|
171
|
+
ZeroFixSuggestionSchema,
|
|
172
|
+
ZeroGraphResultSchema,
|
|
173
|
+
ZeroHTTPCompiler,
|
|
174
|
+
ZeroHTTPError,
|
|
175
|
+
ZeroSizeResultSchema,
|
|
176
|
+
ZeroTimeoutError,
|
|
177
|
+
compileAndRegister,
|
|
178
|
+
createZeroCompilerTools,
|
|
179
|
+
createZeroTool,
|
|
180
|
+
createZeroToolsFromProgram,
|
|
181
|
+
createZeroWASIRuntime,
|
|
182
|
+
createZeroWASMTool,
|
|
183
|
+
createZeroWASMTools,
|
|
184
|
+
parseCheckOutput,
|
|
185
|
+
parseDiagnostic,
|
|
186
|
+
parseFixOutput,
|
|
187
|
+
parseGraphOutput,
|
|
188
|
+
parseSizeOutput
|
|
189
|
+
};
|
|
190
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/compiler-tools.ts"],"sourcesContent":["/**\n * @moikapy/origen-zero — Interactive compiler tools\n *\n * Creates four OrigenTools that let the LLM write, check, and fix\n * Zero programs during a conversation:\n * - zero_check: Check a Zero program for errors\n * - zero_graph: Get the dependency graph\n * - zero_size: Get size estimates for functions\n * - zero_fix: Plan repairs for a Zero program\n */\n\nimport type { OrigenTool } from \"@moikapy/origen\";\nimport { ZeroCompiler, TEMP_DIR } from \"./compiler.js\";\nimport type { ZeroCompilerLike, ZeroCompilerConfig } from \"./types.js\";\n\n/**\n * Create the set of interactive Zero compiler tools that let the LLM\n * write, check, and fix Zero programs during a conversation.\n *\n * Accepts either a ZeroCompilerLike instance (ZeroCompiler or ZeroHTTPCompiler)\n * or a ZeroCompilerConfig for the local CLI compiler.\n */\nexport function createZeroCompilerTools(\n compiler?: ZeroCompilerLike | ZeroCompilerConfig,\n): OrigenTool[] {\n const zero: ZeroCompilerLike = !compiler\n ? new ZeroCompiler()\n : \"check\" in compiler && typeof compiler.check === \"function\"\n ? (compiler as ZeroCompilerLike)\n : new ZeroCompiler(compiler as ZeroCompilerConfig);\n\n const checkTool: OrigenTool = {\n name: \"zero_check\",\n description: `Check a Zero program for errors. Returns structured diagnostics with repair suggestions. Write your Zero source code in the \"source\" parameter.`,\n parameters: {\n type: \"object\",\n properties: {\n source: {\n type: \"string\",\n description: \"Zero source code to check\",\n },\n path: {\n type: \"string\",\n description: \"File path hint for error reporting (optional)\",\n },\n },\n required: [\"source\"],\n },\n async execute(args: Record<string, unknown>): Promise<string> {\n const source = String(args.source ?? \"\");\n const path = args.path ? String(args.path) : undefined;\n const result = await zero.check(path ? { path, content: source } : source);\n\n if (result.ok) {\n return \"✅ Zero program checks passed with no errors.\";\n }\n\n const lines = result.diagnostics.map((d) => {\n let line = `[${d.code}] ${d.severity}: ${d.message}`;\n if (d.line) line += ` (line ${d.line})`;\n if (d.column) line += `:${d.column}`;\n if (d.repair) line += ` → Fix: ${d.repair.suggestion ?? d.repair.id}`;\n return line;\n });\n\n return `❌ Zero program has ${result.diagnostics.length} diagnostic(s):\\n${lines.join(\"\\n\")}`;\n },\n };\n\n const graphTool: OrigenTool = {\n name: \"zero_graph\",\n description: `Get the dependency graph of a Zero program. Shows which functions depend on which other functions.`,\n parameters: {\n type: \"object\",\n properties: {\n source: {\n type: \"string\",\n description: \"Zero source code to analyze\",\n },\n path: {\n type: \"string\",\n description: \"File path hint (optional)\",\n },\n },\n required: [\"source\"],\n },\n async execute(args: Record<string, unknown>): Promise<string> {\n const source = String(args.source ?? \"\");\n const path = args.path ? String(args.path) : undefined;\n const result = await zero.graph(path ? { path, content: source } : source);\n return JSON.stringify({ symbols: result.symbols, functions: result.functions }, null, 2);\n },\n };\n\n const sizeTool: OrigenTool = {\n name: \"zero_size\",\n description: `Get size estimates for functions in a Zero program. Returns estimated binary size per function.`,\n parameters: {\n type: \"object\",\n properties: {\n source: {\n type: \"string\",\n description: \"Zero source code to size-report\",\n },\n path: {\n type: \"string\",\n description: \"File path hint (optional)\",\n },\n },\n required: [\"source\"],\n },\n async execute(args: Record<string, unknown>): Promise<string> {\n const source = String(args.source ?? \"\");\n const path = args.path ? String(args.path) : undefined;\n const result = await zero.size(path ? { path, content: source } : source);\n return JSON.stringify(result.portableRuntime ?? result.raw, null, 2);\n },\n };\n\n const fixTool: OrigenTool = {\n name: \"zero_fix\",\n description: `Plan repairs for a Zero program. Returns suggested fixes with line numbers and descriptions. Use this after zero_check reports errors.`,\n parameters: {\n type: \"object\",\n properties: {\n source: {\n type: \"string\",\n description: \"Zero source code to repair\",\n },\n path: {\n type: \"string\",\n description: \"File path hint (optional)\",\n },\n },\n required: [\"source\"],\n },\n async execute(args: Record<string, unknown>): Promise<string> {\n const source = String(args.source ?? \"\");\n const path = args.path ? String(args.path) : undefined;\n const result = await zero.fix(path ? { path, content: source } : source);\n\n if (result.ok && result.fixes.length === 0) {\n return \"✅ No fixes needed — program is clean.\";\n }\n\n const lines = result.fixes.map((f) => {\n let line = `[${f.diagnosticCode}] ${f.summary} (${f.safety})`;\n if (f.appliesEdits) line += ` [auto-fixable]`;\n return line;\n });\n\n return `📝 ${result.fixes.length} fix suggestion(s):\\n${lines.join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AAA,MACV,MAAM;AAAA,MACN,YAAY;AAAA,QACV,QAAQ;AAAA,UACN,MAAM;AAAA,UACN,aAAa;AAAA,QACf;AAAA,QACA,MAAM;AAAA,UACJ,MAAM;AAAA,UACN,aAAa;AAAA,QACf;AAAA,MACF;AAAA,MACA,UAAU,CAAC,QAAQ;AAAA,IACrB;AAAA,IACA,MAAM,QAAQ,MAAgD;AAC5D,YAAM,SAAS,OAAO,KAAK,UAAU,EAAE;AACvC,YAAM,OAAO,KAAK,OAAO,OAAO,KAAK,IAAI,IAAI;AAC7C,YAAM,SAAS,MAAM,KAAK,IAAI,OAAO,EAAE,MAAM,SAAS,OAAO,IAAI,MAAM;AAEvE,UAAI,OAAO,MAAM,OAAO,MAAM,WAAW,GAAG;AAC1C,eAAO;AAAA,MACT;AAEA,YAAM,QAAQ,OAAO,MAAM,IAAI,CAAC,MAAM;AACpC,YAAI,OAAO,IAAI,EAAE,cAAc,KAAK,EAAE,OAAO,KAAK,EAAE,MAAM;AAC1D,YAAI,EAAE,aAAc,SAAQ;AAC5B,eAAO;AAAA,MACT,CAAC;AAED,aAAO,aAAM,OAAO,MAAM,MAAM;AAAA,EAAwB,MAAM,KAAK,IAAI,CAAC;AAAA,IAC1E;AAAA,EACF;AAEA,SAAO,CAAC,WAAW,WAAW,UAAU,OAAO;AACjD;","names":[]}
|
package/dist/tools.d.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { OrigenTool } from '@moikapy/origen';
|
|
2
|
+
import { k as ZeroSourceFile, d as ZeroCompilerLike, c as ZeroCompilerConfig, m as ZeroToolExecution, Z as ZeroBuildOptions, o as ZeroToolRegistrationSuccess, n as ZeroToolRegistrationFailure, l as ZeroToolConfig } from './types-Dc-cDRjG.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @moikapy/origen-zero — Tool registration
|
|
6
|
+
*
|
|
7
|
+
* Registers compiled Zero programs as OrigenTools and provides
|
|
8
|
+
* compileAndRegister for write-compile-verify-register in one call.
|
|
9
|
+
*
|
|
10
|
+
* Supports two execution modes:
|
|
11
|
+
* - "subprocess": Spawns compiled binary (Node/Bun only)
|
|
12
|
+
* - "http": Calls a Zero execution service via fetch (Workers-compatible)
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Register a compiled Zero program's function as an OrigenTool.
|
|
17
|
+
*
|
|
18
|
+
* In "subprocess" mode, executes the compiled binary via execFile.
|
|
19
|
+
* In "http" mode, calls a Zero execution service via fetch.
|
|
20
|
+
*/
|
|
21
|
+
declare function createZeroTool(config: ZeroToolConfig): OrigenTool;
|
|
22
|
+
/**
|
|
23
|
+
* Register all exported functions from a Zero program as OrigenTools.
|
|
24
|
+
* Uses the compiler's graph() to discover public functions,
|
|
25
|
+
* then creates one OrigenTool per function.
|
|
26
|
+
*/
|
|
27
|
+
declare function createZeroToolsFromProgram(execution: ZeroToolExecution, options?: {
|
|
28
|
+
compiler?: ZeroCompilerLike | ZeroCompilerConfig;
|
|
29
|
+
verify?: boolean;
|
|
30
|
+
}): Promise<OrigenTool[]>;
|
|
31
|
+
/**
|
|
32
|
+
* Write a Zero source file, compile it, verify it, and register
|
|
33
|
+
* its public functions as OrigenTools — all in one call.
|
|
34
|
+
*
|
|
35
|
+
* If the source has errors, returns them without registering tools.
|
|
36
|
+
*
|
|
37
|
+
* Note: build() only works with ZeroCompiler (subprocess), not ZeroHTTPCompiler.
|
|
38
|
+
* HTTP mode requires pre-compiled binaries or a build service.
|
|
39
|
+
*/
|
|
40
|
+
declare function compileAndRegister(source: ZeroSourceFile, options?: {
|
|
41
|
+
compiler?: ZeroCompilerLike | ZeroCompilerConfig;
|
|
42
|
+
execution?: ZeroToolExecution;
|
|
43
|
+
build?: ZeroBuildOptions;
|
|
44
|
+
}): Promise<ZeroToolRegistrationSuccess | ZeroToolRegistrationFailure>;
|
|
45
|
+
|
|
46
|
+
export { compileAndRegister, createZeroTool, createZeroToolsFromProgram };
|
package/dist/tools.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import {
|
|
2
|
+
compileAndRegister,
|
|
3
|
+
createZeroTool,
|
|
4
|
+
createZeroToolsFromProgram
|
|
5
|
+
} from "./chunk-SDOZC7ZI.js";
|
|
6
|
+
import "./chunk-DE5JDJKT.js";
|
|
7
|
+
import "./chunk-6RAZN3WM.js";
|
|
8
|
+
export {
|
|
9
|
+
compileAndRegister,
|
|
10
|
+
createZeroTool,
|
|
11
|
+
createZeroToolsFromProgram
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|