@rulvar/planner 1.1.0 → 1.3.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.
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ScriptRejected } from "@rulvar/core";
|
|
2
2
|
//#region src/compile.ts
|
|
3
3
|
/**
|
|
4
|
-
* The exact curated sandbox global set, in
|
|
4
|
+
* The exact curated sandbox global set, in canonical order.
|
|
5
5
|
* The worker binds the ctx methods as bare globals under these names and
|
|
6
6
|
* the API card teaches exactly this list.
|
|
7
7
|
*/
|
|
@@ -165,11 +165,11 @@ function scanImports(source, blanked, allowImports) {
|
|
|
165
165
|
return diagnostics;
|
|
166
166
|
}
|
|
167
167
|
/**
|
|
168
|
-
* Validates and compiles planner-generated source into a CompiledWorkflow
|
|
169
|
-
*
|
|
168
|
+
* Validates and compiles planner-generated source into a CompiledWorkflow.
|
|
169
|
+
* The source is an async function body over the sandbox
|
|
170
170
|
* globals; its `return` value is the workflow result. The compiled form is
|
|
171
171
|
* pure data (the source is evaluated only inside the worker sandbox);
|
|
172
|
-
* machine scripts run under errorPolicy 'lenient'
|
|
172
|
+
* machine scripts run under errorPolicy 'lenient'.
|
|
173
173
|
*/
|
|
174
174
|
function compileScript(source, o) {
|
|
175
175
|
const allowImports = o?.allowImports ?? [];
|
package/dist/index.d.ts
CHANGED
|
@@ -2,12 +2,12 @@ import { CompiledWorkflow, Ctx, Engine, InMemoryStore, JournalEntry, Json, Model
|
|
|
2
2
|
|
|
3
3
|
//#region src/compile.d.ts
|
|
4
4
|
/**
|
|
5
|
-
* The exact curated sandbox global set, in
|
|
5
|
+
* The exact curated sandbox global set, in canonical order.
|
|
6
6
|
* The worker binds the ctx methods as bare globals under these names and
|
|
7
7
|
* the API card teaches exactly this list.
|
|
8
8
|
*/
|
|
9
9
|
declare const SANDBOX_GLOBALS: readonly string[];
|
|
10
|
-
/** One machine-readable compileScript diagnostic (
|
|
10
|
+
/** One machine-readable compileScript diagnostic (carried by ScriptRejected). */
|
|
11
11
|
interface ScriptDiagnostic {
|
|
12
12
|
ruleId: string;
|
|
13
13
|
message: string;
|
|
@@ -19,11 +19,11 @@ interface CompileScriptOptions {
|
|
|
19
19
|
allowImports?: string[];
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
|
-
* Validates and compiles planner-generated source into a CompiledWorkflow
|
|
23
|
-
*
|
|
22
|
+
* Validates and compiles planner-generated source into a CompiledWorkflow.
|
|
23
|
+
* The source is an async function body over the sandbox
|
|
24
24
|
* globals; its `return` value is the workflow result. The compiled form is
|
|
25
25
|
* pure data (the source is evaluated only inside the worker sandbox);
|
|
26
|
-
* machine scripts run under errorPolicy 'lenient'
|
|
26
|
+
* machine scripts run under errorPolicy 'lenient'.
|
|
27
27
|
*/
|
|
28
28
|
declare function compileScript(source: string, o?: CompileScriptOptions): CompiledWorkflow;
|
|
29
29
|
/** Typed accessor for the diagnostics carried on a ScriptRejected. */
|
|
@@ -56,7 +56,7 @@ interface PlanResult {
|
|
|
56
56
|
/** Diagnostics of the ACCEPTED draft: advisories only, never errors. */
|
|
57
57
|
lint: PlanDiagnostic[];
|
|
58
58
|
}
|
|
59
|
-
/** The deterministic planner runId: one goal, one journal
|
|
59
|
+
/** The deterministic planner runId: one goal, one journal. */
|
|
60
60
|
declare function planRunIdOf(goal: string): string;
|
|
61
61
|
/**
|
|
62
62
|
* The model may fence the script; the extractor takes the first fenced
|
|
@@ -76,7 +76,7 @@ declare function lintScript(source: string): {
|
|
|
76
76
|
};
|
|
77
77
|
declare function plan(engine: Engine, goal: string, o?: PlanOptions): Promise<PlanResult>;
|
|
78
78
|
/**
|
|
79
|
-
* plan-then-run in one call (
|
|
79
|
+
* plan-then-run in one call (amended during M6-T05:
|
|
80
80
|
* the composition is async because planning itself is a run).
|
|
81
81
|
*/
|
|
82
82
|
declare function runPlanned(engine: Engine, goal: string, args?: Json): Promise<RunHandle<unknown>>;
|
|
@@ -141,7 +141,7 @@ interface WorkerSandboxRunnerOptions {
|
|
|
141
141
|
*/
|
|
142
142
|
workerUrl?: URL;
|
|
143
143
|
}
|
|
144
|
-
/** Accepts CompiledWorkflow ONLY: feeding a closure is a type error
|
|
144
|
+
/** Accepts CompiledWorkflow ONLY: feeding a closure is a type error. */
|
|
145
145
|
declare class WorkerSandboxRunner implements ScriptRunner {
|
|
146
146
|
private readonly timeoutMs;
|
|
147
147
|
private readonly memoryMb;
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as compileScript, r as scriptDiagnosticsOf, t as SANDBOX_GLOBALS } from "./compile-
|
|
1
|
+
import { n as compileScript, r as scriptDiagnosticsOf, t as SANDBOX_GLOBALS } from "./compile-BtCY9wfO.js";
|
|
2
2
|
import { ConfigError, InMemoryStore, SandboxError, ScriptRejected, createEngine, createSandboxBridge, defineWorkflow, toJournalValue } from "@rulvar/core";
|
|
3
3
|
import { createHash } from "node:crypto";
|
|
4
4
|
import { Linter } from "eslint";
|
|
@@ -7,7 +7,7 @@ import { MessageChannel, Worker } from "node:worker_threads";
|
|
|
7
7
|
//#region src/api-card.ts
|
|
8
8
|
/**
|
|
9
9
|
* The API card (M6-T04): teaches the planner model EXACTLY the sandbox
|
|
10
|
-
* dialect and global set
|
|
10
|
+
* dialect and global set. The card is a
|
|
11
11
|
* pure constant, byte-stable across runs; plan() (M6-T05) composes it
|
|
12
12
|
* with profileCard(registry) and the goal. The usage examples are
|
|
13
13
|
* distilled from the runnable examples/ corpus (M5-T09).
|
|
@@ -61,7 +61,7 @@ function apiCard() {
|
|
|
61
61
|
//#region src/plan.ts
|
|
62
62
|
/**
|
|
63
63
|
* The plan agent and the self-repair loop (M6-T05): mode (b), the
|
|
64
|
-
* flagship hybrid
|
|
64
|
+
* flagship hybrid. plan() asks a planner model
|
|
65
65
|
* (role 'plan') to write a script against the API card and the profile
|
|
66
66
|
* card, lints it with eslint-plugin-rulvar, self-repairs up to
|
|
67
67
|
* repairRounds rounds from the JSON diagnostics, and compiles the
|
|
@@ -72,7 +72,7 @@ function apiCard() {
|
|
|
72
72
|
* against the same store REPLAYS the unchanged prefix for free
|
|
73
73
|
* (invariant I1; the M6-T05 acceptance).
|
|
74
74
|
*/
|
|
75
|
-
/** The deterministic planner runId: one goal, one journal
|
|
75
|
+
/** The deterministic planner runId: one goal, one journal. */
|
|
76
76
|
function planRunIdOf(goal) {
|
|
77
77
|
return `plan-${createHash("sha256").update(goal, "utf8").digest("hex").slice(0, 24)}`;
|
|
78
78
|
}
|
|
@@ -205,7 +205,7 @@ async function plan(engine, goal, o) {
|
|
|
205
205
|
};
|
|
206
206
|
}
|
|
207
207
|
/**
|
|
208
|
-
* plan-then-run in one call (
|
|
208
|
+
* plan-then-run in one call (amended during M6-T05:
|
|
209
209
|
* the composition is async because planning itself is a run).
|
|
210
210
|
*/
|
|
211
211
|
async function runPlanned(engine, goal, args) {
|
|
@@ -218,19 +218,19 @@ async function runPlanned(engine, goal, args) {
|
|
|
218
218
|
* WorkerSandboxRunner (M6-T02): the mandatory runner for machine-generated
|
|
219
219
|
* scripts, mode (b). Owns the worker lifecycle and the dedicated
|
|
220
220
|
* MessageChannel; every primitive call is served by the core sandbox
|
|
221
|
-
* bridge against the canonical run ctx
|
|
221
|
+
* bridge against the canonical run ctx.
|
|
222
222
|
*
|
|
223
223
|
* Port lifecycle: one channel per run; the worker end rides the init
|
|
224
224
|
* transfer list; the host end is referenced while the worker computes and
|
|
225
225
|
* unreferenced while every worker frame is blocked on a host call, so a
|
|
226
|
-
* suspended run lets the process exit
|
|
226
|
+
* suspended run lets the process exit and a computing
|
|
227
227
|
* worker keeps it alive. Breaching timeoutMs or memoryMb terminates the
|
|
228
228
|
* worker and the run completes with outcome 'error' carrying the typed
|
|
229
|
-
* SandboxError
|
|
229
|
+
* SandboxError.
|
|
230
230
|
*/
|
|
231
231
|
const DEFAULT_SANDBOX_TIMEOUT_MS = 3e5;
|
|
232
232
|
const DEFAULT_SANDBOX_MEMORY_MB = 512;
|
|
233
|
-
/** Accepts CompiledWorkflow ONLY: feeding a closure is a type error
|
|
233
|
+
/** Accepts CompiledWorkflow ONLY: feeding a closure is a type error. */
|
|
234
234
|
var WorkerSandboxRunner = class {
|
|
235
235
|
timeoutMs;
|
|
236
236
|
memoryMb;
|
package/dist/sandbox-worker.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as SANDBOX_GLOBALS } from "./compile-
|
|
1
|
+
import { t as SANDBOX_GLOBALS } from "./compile-BtCY9wfO.js";
|
|
2
2
|
import { NonSerializableValueError, toJournalValue } from "@rulvar/core";
|
|
3
3
|
import { createHash } from "node:crypto";
|
|
4
4
|
import { parentPort } from "node:worker_threads";
|
|
@@ -8,7 +8,7 @@ import { AsyncLocalStorage } from "node:async_hooks";
|
|
|
8
8
|
* The worker half of the sandbox contract (M6-T02): evaluates a
|
|
9
9
|
* CompiledWorkflow source inside a worker_threads realm with the curated
|
|
10
10
|
* global scope and proxies every primitive call as JSON-RPC over the
|
|
11
|
-
* dedicated MessagePort to the host bridge
|
|
11
|
+
* dedicated MessagePort to the host bridge.
|
|
12
12
|
*
|
|
13
13
|
* Determinism: now, random, uuid, and the Date.now/Math.random realm
|
|
14
14
|
* replacements all draw from ONE seeded stream (seed = sha256(runId)), so
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rulvar/planner",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "rulvar flagship hybrid mode: plan agent, compileScript, WorkerSandboxRunner, self-repair loop.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -23,14 +23,14 @@
|
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"eslint": "^9.39.4",
|
|
26
|
-
"@rulvar/core": "1.
|
|
27
|
-
"eslint-plugin-rulvar": "1.
|
|
26
|
+
"@rulvar/core": "1.3.0",
|
|
27
|
+
"eslint-plugin-rulvar": "1.3.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@types/node": "^22.20.0",
|
|
31
31
|
"tsdown": "^0.22.3",
|
|
32
32
|
"typescript": "~6.0.3",
|
|
33
|
-
"@rulvar/testing": "1.
|
|
33
|
+
"@rulvar/testing": "1.3.0"
|
|
34
34
|
},
|
|
35
35
|
"repository": {
|
|
36
36
|
"type": "git",
|