@cotal-ai/lang 0.0.0 → 0.15.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/LICENSE +202 -0
- package/dist/dryrun.d.ts +106 -0
- package/dist/dryrun.d.ts.map +1 -0
- package/dist/dryrun.js +172 -0
- package/dist/dryrun.js.map +1 -0
- package/dist/duration.d.ts +12 -0
- package/dist/duration.d.ts.map +1 -0
- package/dist/duration.js +34 -0
- package/dist/duration.js.map +1 -0
- package/dist/effects.d.ts +231 -0
- package/dist/effects.d.ts.map +1 -0
- package/dist/effects.js +64 -0
- package/dist/effects.js.map +1 -0
- package/dist/errors.d.ts +141 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +163 -0
- package/dist/errors.js.map +1 -0
- package/dist/grammar.d.ts +28 -0
- package/dist/grammar.d.ts.map +1 -0
- package/dist/grammar.js +793 -0
- package/dist/grammar.js.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/interpret.d.ts +89 -0
- package/dist/interpret.d.ts.map +1 -0
- package/dist/interpret.js +1117 -0
- package/dist/interpret.js.map +1 -0
- package/dist/journal.d.ts +177 -0
- package/dist/journal.d.ts.map +1 -0
- package/dist/journal.js +198 -0
- package/dist/journal.js.map +1 -0
- package/dist/keys.d.ts +87 -0
- package/dist/keys.d.ts.map +1 -0
- package/dist/keys.js +105 -0
- package/dist/keys.js.map +1 -0
- package/dist/primitives.d.ts +84 -0
- package/dist/primitives.d.ts.map +1 -0
- package/dist/primitives.js +265 -0
- package/dist/primitives.js.map +1 -0
- package/dist/sim.d.ts +101 -0
- package/dist/sim.d.ts.map +1 -0
- package/dist/sim.js +192 -0
- package/dist/sim.js.map +1 -0
- package/dist/values.d.ts +35 -0
- package/dist/values.d.ts.map +1 -0
- package/dist/values.js +0 -0
- package/dist/values.js.map +1 -0
- package/package.json +27 -7
- package/README.md +0 -10
package/dist/sim.js
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The simulation handler: the same interpreter, a different handler.
|
|
3
|
+
*
|
|
4
|
+
* That is the whole design, and it is why simulation is v1 scope rather than a later nicety. It
|
|
5
|
+
* costs one implementation of an interface the runtime needed anyway, and it is the test harness
|
|
6
|
+
* for everything else: scripted turns, instant sleeps, injected checkpoint answers, and injected
|
|
7
|
+
* faults, with no broker, no agents, and no wall-clock waiting.
|
|
8
|
+
*
|
|
9
|
+
* The rule that makes it worth trusting: **an unscripted effect is an error, never a default**. A
|
|
10
|
+
* simulator that invents a plausible turn result is a simulator that green-lights broken programs,
|
|
11
|
+
* which is worse than having no simulator at all.
|
|
12
|
+
*/
|
|
13
|
+
import { EffectError } from "./effects.js";
|
|
14
|
+
import { parseDuration } from "./duration.js";
|
|
15
|
+
import { stepKeyString } from "./keys.js";
|
|
16
|
+
export class SimUnscriptedError extends Error {
|
|
17
|
+
code;
|
|
18
|
+
stepKey;
|
|
19
|
+
constructor(code, stepKey, message) {
|
|
20
|
+
super(message);
|
|
21
|
+
this.code = code;
|
|
22
|
+
this.stepKey = stepKey;
|
|
23
|
+
this.name = "SimUnscriptedError";
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The simulation handler.
|
|
28
|
+
*
|
|
29
|
+
* Every effect resolves from the script or fails loudly. Sleeps are instant and advance the
|
|
30
|
+
* virtual clock by the duration the program asked for, so a program that waits four hours is
|
|
31
|
+
* tested in microseconds without pretending the wait did not happen.
|
|
32
|
+
*/
|
|
33
|
+
export class SimHandler {
|
|
34
|
+
script;
|
|
35
|
+
virtualNow;
|
|
36
|
+
occurrences = new Map();
|
|
37
|
+
consumed = [];
|
|
38
|
+
agents = new Map();
|
|
39
|
+
constructor(script = {}) {
|
|
40
|
+
this.script = script;
|
|
41
|
+
this.virtualNow = script.clock?.start ?? 0;
|
|
42
|
+
}
|
|
43
|
+
now() {
|
|
44
|
+
return this.virtualNow;
|
|
45
|
+
}
|
|
46
|
+
/** Advance virtual time. Sleeps do this by their full duration; turns by a scripted default. */
|
|
47
|
+
advance(ms) {
|
|
48
|
+
this.virtualNow += ms;
|
|
49
|
+
}
|
|
50
|
+
advanceBy(spec, fallback) {
|
|
51
|
+
this.advance(parseDuration(spec ?? fallback));
|
|
52
|
+
}
|
|
53
|
+
/** Which occurrence of this (table, name) we are on, counted per simulated run. */
|
|
54
|
+
nextOccurrence(table, name) {
|
|
55
|
+
const tag = `${table}:${name}`;
|
|
56
|
+
const n = this.occurrences.get(tag) ?? 0;
|
|
57
|
+
this.occurrences.set(tag, n + 1);
|
|
58
|
+
return n;
|
|
59
|
+
}
|
|
60
|
+
checkFault(ctx) {
|
|
61
|
+
const full = stepKeyString(ctx.key);
|
|
62
|
+
const short = full.slice(full.lastIndexOf("/") + 1);
|
|
63
|
+
const fault = this.script.faults?.find((f) => f.at === full || f.at === short);
|
|
64
|
+
if (fault === undefined)
|
|
65
|
+
return;
|
|
66
|
+
throw new EffectError(fault.code ?? "L4002", fault.kind, fault.message ?? `simulated ${fault.kind} at ${full}`);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Resolve one scripted outcome, or fail. `name` falls back to the effect kind for unnamed
|
|
70
|
+
* steps, which is the same fallback the journal key uses, so a script and a real trace read
|
|
71
|
+
* against each other without translation.
|
|
72
|
+
*/
|
|
73
|
+
resolve(table, scripted, ctx) {
|
|
74
|
+
this.checkFault(ctx);
|
|
75
|
+
const name = ctx.key.name === "" ? ctx.key.kind : ctx.key.name;
|
|
76
|
+
const entry = scripted?.[name];
|
|
77
|
+
const stepKey = stepKeyString(ctx.key);
|
|
78
|
+
if (entry === undefined) {
|
|
79
|
+
throw new SimUnscriptedError("L6001", stepKey, `L6001 Unscripted effect in simulation\n\nThe script has no ${table} entry for "${name}" (step ${stepKey}).\n\nFix: add one, for example { ${table}: { "${name}": <result> } }. The simulator never invents a result, because a simulator that guesses is a simulator that green-lights broken programs.`);
|
|
80
|
+
}
|
|
81
|
+
const occurrence = this.nextOccurrence(table, name);
|
|
82
|
+
this.consumed.push({ table, name, occurrence });
|
|
83
|
+
if (!Array.isArray(entry))
|
|
84
|
+
return entry;
|
|
85
|
+
const list = entry;
|
|
86
|
+
const value = list[occurrence];
|
|
87
|
+
if (value === undefined) {
|
|
88
|
+
throw new SimUnscriptedError("L6001", stepKey, `L6001 Unscripted effect in simulation\n\nThe script gives ${list.length} ${table} result${list.length === 1 ? "" : "s"} for "${name}", and this is occurrence ${occurrence} (step ${stepKey}).\n\nFix: add another entry to the list, or use a single value to script every occurrence the same way.`);
|
|
89
|
+
}
|
|
90
|
+
return value;
|
|
91
|
+
}
|
|
92
|
+
// ---- the handler ----------------------------------------------------------------------------
|
|
93
|
+
async spawn(req, ctx) {
|
|
94
|
+
this.checkFault(ctx);
|
|
95
|
+
const n = this.nextOccurrence("spawn", req.persona);
|
|
96
|
+
const handle = {
|
|
97
|
+
agent: `sim.${req.persona}${n === 0 ? "" : `-${n + 1}`}`,
|
|
98
|
+
persona: req.persona,
|
|
99
|
+
...(req.worktree !== undefined ? { worktree: req.worktree } : {}),
|
|
100
|
+
...(req.role !== undefined ? { role: req.role } : {}),
|
|
101
|
+
};
|
|
102
|
+
this.agents.set(handle.agent, handle);
|
|
103
|
+
await ctx.bind({ simAgent: handle.agent });
|
|
104
|
+
return handle;
|
|
105
|
+
}
|
|
106
|
+
async turn(_req, ctx) {
|
|
107
|
+
const scripted = this.resolve("turns", this.script.turns, ctx);
|
|
108
|
+
await ctx.bind({ simGoal: stepKeyString(ctx.key) });
|
|
109
|
+
this.advanceBy(this.script.clock?.turn, "5m");
|
|
110
|
+
return { ...scripted, at: this.virtualNow };
|
|
111
|
+
}
|
|
112
|
+
async ask(_req, ctx) {
|
|
113
|
+
const value = this.resolve("asks", this.script.asks, ctx);
|
|
114
|
+
await ctx.bind({ simGoal: stepKeyString(ctx.key) });
|
|
115
|
+
this.advanceBy(this.script.clock?.ask, "1m");
|
|
116
|
+
return value;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Reports WHAT HAPPENED and never whether it throws. A script says `resolved` or `expired`; the
|
|
120
|
+
* interpreter journals that and applies today's `onExpiry` afterwards. A simulator that decided
|
|
121
|
+
* the disposition would bake it into the record exactly as a production handler would.
|
|
122
|
+
*/
|
|
123
|
+
async checkpoint(_req, ctx) {
|
|
124
|
+
const scripted = this.resolve("checkpoints", this.script.checkpoints, ctx);
|
|
125
|
+
await ctx.bind({ simCheckpoint: stepKeyString(ctx.key) });
|
|
126
|
+
this.advanceBy(this.script.clock?.checkpoint, "1m");
|
|
127
|
+
if (scripted.status === "expired")
|
|
128
|
+
return { outcome: "expired", at: this.virtualNow };
|
|
129
|
+
return {
|
|
130
|
+
outcome: "resolved",
|
|
131
|
+
...(scripted.value !== undefined ? { value: scripted.value } : {}),
|
|
132
|
+
...(scripted.by !== undefined ? { by: scripted.by } : {}),
|
|
133
|
+
...(scripted.artifact !== undefined ? { artifact: scripted.artifact } : {}),
|
|
134
|
+
at: this.virtualNow,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
/** Instant, and honest: the clock moves by exactly what the program asked to wait. */
|
|
138
|
+
async sleep(req, ctx) {
|
|
139
|
+
this.checkFault(ctx);
|
|
140
|
+
this.advance(parseDuration(req.duration));
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
async wait(req, ctx) {
|
|
144
|
+
const value = this.resolve("events", this.script.events, ctx);
|
|
145
|
+
// A scripted null is a timeout, and a timeout consumes the whole timeout budget.
|
|
146
|
+
if (value === null && req.timeout !== undefined)
|
|
147
|
+
this.advance(parseDuration(req.timeout));
|
|
148
|
+
else
|
|
149
|
+
this.advanceBy(this.script.clock?.wait, "1m");
|
|
150
|
+
return value;
|
|
151
|
+
}
|
|
152
|
+
async notify(_req, ctx) {
|
|
153
|
+
this.checkFault(ctx);
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
async monitor(_req, ctx) {
|
|
157
|
+
this.checkFault(ctx);
|
|
158
|
+
return null;
|
|
159
|
+
}
|
|
160
|
+
async openConclave(req, ctx) {
|
|
161
|
+
this.checkFault(ctx);
|
|
162
|
+
return { channel: req.channel ?? `sim-conclave-${stepKeyString(ctx.key)}` };
|
|
163
|
+
}
|
|
164
|
+
async closeConclave(_req, ctx) {
|
|
165
|
+
this.checkFault(ctx);
|
|
166
|
+
return null;
|
|
167
|
+
}
|
|
168
|
+
// ---- the report ------------------------------------------------------------------------------
|
|
169
|
+
/**
|
|
170
|
+
* Script entries the run never reached. Usually a renamed step, which is worth saying out loud:
|
|
171
|
+
* a script that silently stops matching is a test that silently stops testing.
|
|
172
|
+
*/
|
|
173
|
+
unusedScript() {
|
|
174
|
+
const used = new Set(this.consumed.map((c) => `${c.table}:${c.name}`));
|
|
175
|
+
const out = [];
|
|
176
|
+
for (const table of ["turns", "asks", "checkpoints", "events"]) {
|
|
177
|
+
const t = this.script[table];
|
|
178
|
+
if (t === undefined)
|
|
179
|
+
continue;
|
|
180
|
+
for (const name of Object.keys(t)) {
|
|
181
|
+
if (!used.has(`${table}:${name}`))
|
|
182
|
+
out.push(`${table}.${name}`);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return out;
|
|
186
|
+
}
|
|
187
|
+
/** Every effect the run performed, in order, for the dry-run report. */
|
|
188
|
+
performed() {
|
|
189
|
+
return this.consumed;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
//# sourceMappingURL=sim.js.map
|
package/dist/sim.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sim.js","sourceRoot":"","sources":["../src/sim.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAoBH,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,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AK,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;QACvE,MAAM,GAAG,GAAa,EAAE,CAAC;QACzB,KAAK,MAAM,KAAK,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,QAAQ,CAAU,EAAE,CAAC;YACxE,MAAM,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAC7B,IAAI,CAAC,KAAK,SAAS;gBAAE,SAAS;YAC9B,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;gBAClC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,KAAK,IAAI,IAAI,EAAE,CAAC;oBAAE,GAAG,CAAC,IAAI,CAAC,GAAG,KAAK,IAAI,IAAI,EAAE,CAAC,CAAC;YAClE,CAAC;QACH,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC;IAED,wEAAwE;IACxE,SAAS;QACP,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;CACF"}
|
package/dist/values.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Values, freezing, and the tamed nondeterminism.
|
|
3
|
+
*
|
|
4
|
+
* Jessie asks the author to call `harden()` before a value may be aliased or escape. An explicit
|
|
5
|
+
* call whose omission produces silent aliasing is the wrong shape for an author who is a language
|
|
6
|
+
* model, so we do it for them: every value crossing an effect boundary, in either direction, is
|
|
7
|
+
* deep-frozen by the interpreter. The rule the design states as "freeze on share" is therefore a
|
|
8
|
+
* property of the runtime rather than a discipline anyone has to remember.
|
|
9
|
+
*/
|
|
10
|
+
import type { ScopeFrame } from "./keys.js";
|
|
11
|
+
/** Deep-freeze a value on its way across an effect boundary. Cycles are not reachable here: a
|
|
12
|
+
* value that crosses a boundary has to canonicalize, and a cycle does not. */
|
|
13
|
+
export declare function deepFreeze<T>(value: T): T;
|
|
14
|
+
/**
|
|
15
|
+
* A value that cannot canonicalize cannot be journalled, and a value that cannot be journalled
|
|
16
|
+
* cannot be replayed. Catching it at the boundary is strictly better than discovering it at
|
|
17
|
+
* digest time, because here we still know which argument it was.
|
|
18
|
+
*/
|
|
19
|
+
export declare function assertCrossable(value: unknown, path?: string): void;
|
|
20
|
+
/**
|
|
21
|
+
* The seeded PRNG.
|
|
22
|
+
*
|
|
23
|
+
* Derived per scope rather than as one stream over the run: `H(seed, scopePath, draw)`. A single
|
|
24
|
+
* global counter would mean that inserting a draw anywhere shifts every later draw, so an
|
|
25
|
+
* unrelated edit elsewhere in the program would change the randomness a given scope sees. Per
|
|
26
|
+
* scope, an edit only disturbs the scope it is in, which is what makes randomness survive a
|
|
27
|
+
* migration. Draws are never journalled: they are a pure function of journalled state.
|
|
28
|
+
*/
|
|
29
|
+
export declare class Prng {
|
|
30
|
+
readonly seed: string;
|
|
31
|
+
private readonly draws;
|
|
32
|
+
constructor(seed: string);
|
|
33
|
+
next(scope: readonly ScopeFrame[]): number;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=values.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"values.d.ts","sourceRoot":"","sources":["../src/values.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAG5C;+EAC+E;AAC/E,wBAAgB,UAAU,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAMzC;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,SAAU,GAAG,IAAI,CAsCpE;AAED;;;;;;;;GAQG;AACH,qBAAa,IAAI;IAGH,QAAQ,CAAC,IAAI,EAAE,MAAM;IAFjC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAA6B;gBAE9B,IAAI,EAAE,MAAM;IAEjC,IAAI,CAAC,KAAK,EAAE,SAAS,UAAU,EAAE,G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QAAQ,CAAC,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,IAAI,IAAI,IAAI,IAAI,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC,MAAM,EAAE,CAAC;QACpF,4EAA4E;QAC5E,IAAI,CAAC,GAAG,CAAC,CAAC;QACV,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC;YAAE,CAAC,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;QACzD,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;IACrB,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,15 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cotal-ai/lang",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
3
|
+
"description": "cotal-lang: the restricted-JS workflow language. Parser and validator, the effect interface, the step journal, the interpreter, and the simulation handler. Depends on nothing else in the repo.",
|
|
4
|
+
"version": "0.15.0",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "https://github.com/Cotal-AI/Cotal.git",
|
|
9
9
|
"directory": "packages/lang"
|
|
10
10
|
},
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
|
|
11
|
+
"type": "module",
|
|
12
|
+
"main": "./dist/index.js",
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"import": "./dist/index.js"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"acorn": "^8.15.0",
|
|
22
|
+
"json-canonicalize": "^2.0.0"
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"dist"
|
|
26
|
+
],
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
32
|
+
"build": "tsc -p tsconfig.json",
|
|
33
|
+
"test": "tsx smoke/grammar.smoke.ts && tsx smoke/keys.smoke.ts && tsx smoke/journal.smoke.ts && tsx smoke/sim.smoke.ts && tsx smoke/interpret.smoke.ts && tsx smoke/fuel.smoke.ts && tsx smoke/dryrun.smoke.ts && tsx smoke/examples.smoke.ts && tsx smoke/options.smoke.ts"
|
|
34
|
+
}
|
|
35
|
+
}
|
package/README.md
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
# @cotal-ai/lang
|
|
2
|
-
|
|
3
|
-
Placeholder release reserving this package name.
|
|
4
|
-
|
|
5
|
-
`cotal-lang` is the restricted-JS workflow language used by [Cotal](https://github.com/Cotal-AI/Cotal):
|
|
6
|
-
the parser and validator, the effect interface, the step journal, the interpreter, and the
|
|
7
|
-
simulation handler.
|
|
8
|
-
|
|
9
|
-
The real package is published from the Cotal repository. See
|
|
10
|
-
[packages/lang](https://github.com/Cotal-AI/Cotal/tree/main/packages/lang).
|