@parcha/agentrun-dsl 0.1.0-beta.5 → 0.1.0-beta.9
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 +15 -10
- package/dist/author.js +13 -8
- package/dist/code-exec.d.ts +6 -0
- package/dist/code-exec.js +126 -0
- package/dist/dry-run.d.ts +4 -1
- package/dist/dry-run.js +2 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/long-timer.d.ts +7 -0
- package/dist/long-timer.js +22 -0
- package/dist/observer-snapshot.d.ts +3 -0
- package/dist/observer-snapshot.js +46 -0
- package/dist/system-one.js +28 -2
- package/dist/vocabulary.d.ts +8 -0
- package/dist/vocabulary.js +13 -2
- package/dist/workflow-shape.js +1 -1
- package/dist/workflow.d.ts +60 -11
- package/dist/workflow.js +210 -51
- package/package.json +1 -1
- package/schema/workflow.schema.json +38 -13
- package/skills/author/references/language.md +11 -9
package/README.md
CHANGED
|
@@ -36,11 +36,13 @@ The package root exports a deliberate API. The beta retains agent, structured-ou
|
|
|
36
36
|
| Run and inspect | `runWorkflow`, `validateWorkflow`, `workflowSha256`, `dryRunWorkflow`; core contracts `Workflow`, `WorkflowNode`, `WorkflowDeps`, `WorkflowRunResult`, plus the named node, predicate, effect, effort and result types. |
|
|
37
37
|
| Recognize outcomes | `WorkflowInvalidError`, `WorkflowInputInvalidError`, `WorkflowOutputInvalidError`, `WorkflowVerificationError`, `EffectFailure`, `EffectDeadlineExceededError`, `EffectOutcomeUnknownError`, `EscalationSignal`. A concurrent failure may contain typed outcomes in `AggregateError.errors`; inspect them before deciding whether an effect is safe to retry. |
|
|
38
38
|
| Build judgment adapters | `compileQuestions`, `validateAnswers`, `answersToValue`, `answersSidecar`, `answerConfidence`, `SYSTEM_ONE_LIMITS`, `SystemOneError`; `SystemOneQuestion`, `SystemOneAnswer`, `SystemOneResult`, `SystemOneRetryClass`, `CompiledQuestions`, `AnswersSidecar`. |
|
|
39
|
-
| Integrate a host | `runWorkflowSlice`, `assertWorkflowCapabilities`, `desugarWorkflow`, `resolveSchemaForWorkflow`, `stageSchemaForNode`, `submissionSchemaForNode`, `mergeStageDelta`, `REPORT_SCHEMA`, `SHELL_RESULT_SCHEMA`, `getPath`, `predicateMatches`. |
|
|
39
|
+
| Integrate a host | `runWorkflowSlice`, `assertWorkflowCapabilities`, `desugarWorkflow`, `resolveSchemaForWorkflow`, `stageSchemaForNode`, `submissionSchemaForNode`, `mergeStageDelta`, `REPORT_SCHEMA`, `SHELL_RESULT_SCHEMA`, `getPath`, `predicateMatches`, `deniedGlobalReferences`. |
|
|
40
40
|
| Author workflows | `authorContract`, `renderAuthorContract` (text and sha256), `renderAuthorHostAddendum`, `authorWorkflow`, `candidatePolicyErrors`, `applyHostOutputTypes`, `AUTHOR_SKILL_NAME`, `authorSkillDirectory`, `loadAuthorReference`, `loadAuthorSkillBundle`; `AuthorHostAddendum`, `AuthorWorkflowOptions`, `AuthoredWorkflow`, `CandidatePolicyOptions`. The one author contract and its packaged skill (`skills/author`); a host adds only an addendum. See [the author contract](../../docs/authoring.md#one-author-contract). |
|
|
41
|
-
| Language vocabulary | `WORKFLOW_NODE_KINDS`, `GENERATIVE_NODE_KINDS`, `JUDGMENT_NODE_KINDS`, `NODE_FIELDS`, `IGNORED_NODE_FIELDS`, `WORKFLOW_PREDICATES`, `MECHANICAL_PREDICATES`, `PREDICATE_FIELDS`, `EFFORT_LEVELS`, `THINKING_LEVELS`, `MODEL_TIERS`, `CALL_TRANSPORTS`, `CALL_RETRY_CLASSES`, `PROSE_ARTIFACT_TYPES`; `WorkflowNodeKind`, `WorkflowPredicateName`. The validator and the author contract read these same constants. |
|
|
41
|
+
| Language vocabulary | `WORKFLOW_NODE_KINDS`, `GENERATIVE_NODE_KINDS`, `JUDGMENT_NODE_KINDS`, `NODE_FIELDS`, `IGNORED_NODE_FIELDS`, `WORKFLOW_PREDICATES`, `MECHANICAL_PREDICATES`, `PREDICATE_FIELDS`, `EFFORT_LEVELS`, `THINKING_LEVELS`, `MODEL_TIERS`, `CALL_TRANSPORTS`, `CALL_RETRY_CLASSES`, `EFFECT_FAILURE_CODES`, `PROSE_ARTIFACT_TYPES`; `WorkflowNodeKind`, `WorkflowPredicateName`. The validator and the author contract read these same constants. |
|
|
42
42
|
| Test without a model | `synthesizeInstance`, `synthesizeAnswers`, `DryRunOptions`, `DryRunResult`. Synthetic answers exercise execution mechanics; they do not establish judgment quality. |
|
|
43
43
|
|
|
44
|
+
A `code` node runs in the host process through the package's own executor, which shadows common globals and is not a sandbox. A host that runs code from an untrusted author supplies `deps.runCode`: the interpreter then hands it each code node with the state and the transform's context, merges what it returns under the same patch rules and state checks, and never executes a code body itself, not even as a validation probe. `dryRunWorkflow` takes the same `runCode` option and honors it the same way. `validateWorkflow` is synchronous and cannot call a host executor: a host that has one validates with `executeCode: false`, as `runWorkflow` and `dryRunWorkflow` do for it. `deniedGlobalReferences` names the globals a code body reaches for (a lint, never a boundary), so such a host can refuse the node before it runs. A failed effect carries a closed `code` from `EFFECT_FAILURE_CODES` on its `EffectFailure` and on every `effect.failed` event (null when the failure is not an `EffectFailure` with a listed code; any other typed error's own code rides as `error_code`), and `retry.on` names codes as well as retry classes.
|
|
45
|
+
|
|
44
46
|
`runWorkflowSlice` runs selected root steps against supplied state and optional seed data. It returns the slice state without checking the full workflow's terminal output contract. Use `runWorkflow` for a complete run. `getPath` reads dot-separated record keys and canonical in-bounds array indexes, returning `undefined` when a segment cannot be resolved. `predicateMatches` evaluates mechanical predicates only; use `field_equals` with an explicit path for a stored label.
|
|
45
47
|
|
|
46
48
|
The schema helpers resolve the owning workflow's schema catalog; `stageSchemaForNode` and `submissionSchemaForNode` name the same submission contract. `mergeStageDelta` stores declared submission fields under the node's output key; callers must validate the submission first. Internal traversal, compilation, CSV, reference-file and input-normalization helpers are not package-root APIs.
|
|
@@ -51,23 +53,26 @@ Children can contain maps, loops, routes, parallel branches and other children,
|
|
|
51
53
|
|
|
52
54
|
## Bounds
|
|
53
55
|
|
|
54
|
-
These are the current beta's validation
|
|
56
|
+
These are the current beta's validation rules. The numeric knobs below carry no upper ceiling: the author picks the number, and a host may set its own default, but the validator never caps how high it goes. What remains are lower bounds and structural requirements — a floor a value must sit at or above, a field that must be present — plus the parser's own safety guards, and the System-One question shape (a bounded multiple choice). Hosts may still impose their own budgets as defaults.
|
|
55
57
|
|
|
56
58
|
| Setting | Bound |
|
|
57
59
|
| --- | --- |
|
|
58
60
|
| Document traversal | At most 100,000 visited values and 128 levels of object nesting; cycles, accessors and proxies rejected |
|
|
59
|
-
| `loop.maxIters` | Integer 1
|
|
60
|
-
| `
|
|
61
|
-
| `
|
|
62
|
-
| `call.
|
|
63
|
-
| `call.
|
|
64
|
-
| `call.
|
|
61
|
+
| `loop.maxIters` | Integer >= 1 |
|
|
62
|
+
| `loop.expect_iters` | Integer >= 1, optional (gate prices the loop at this; default the floor) |
|
|
63
|
+
| `verify.maxDrives` | Integer >= 1; default 2 |
|
|
64
|
+
| `call.deadline_s` | Required; a finite number greater than 0 seconds |
|
|
65
|
+
| `call.retry.attempts` | Integer >= 1, including the first attempt |
|
|
66
|
+
| `call.retry.backoff_s` | Finite number >= 0 |
|
|
67
|
+
| `call.poll.interval_s` | Finite number, at least 0.1 seconds (busy-loop guard) |
|
|
68
|
+
| `call.poll.deadline_s` | Finite number, at least the call deadline |
|
|
65
69
|
| Choice options / route branches | At most 240; `pick.allowNone` reserves one option |
|
|
66
70
|
| Score rubric | 2–10 levels, indexed from 0 |
|
|
67
71
|
| Questions per judgment request | Default 256; override with host-owned `WorkflowDeps.maxQuestionsPerRequest` |
|
|
72
|
+
| Judge state bytes per request | No default; host-owned `WorkflowDeps.maxStateBytesPerRequest` (UTF-8 JSON bytes) |
|
|
68
73
|
| Jev context | Selected provider's token limits; an adapter host may configure an additional byte guard |
|
|
69
74
|
|
|
70
|
-
The question-count guard applies after collection expansion, including `sift` items multiplied by their questions. It is a host budget guard, not a claim about a provider's service limit.
|
|
75
|
+
The question-count guard applies after collection expansion, including `sift` items multiplied by their questions. It is a host budget guard, not a claim about a provider's service limit. A `sift` over either limit is split, in item order, into requests that each fit, run up to four at a time. Each request carries the sift's `state` and only its own items.
|
|
71
76
|
|
|
72
77
|
`System One` names TypeSafe's typed-question interface used by the judgment types. A `noul` answer is a truth probability from 0 to 1; `answersToValue` turns values at least 0.5 into `true`. Choice and score confidence comes from the adapter response; Noul confidence is `2 × |probability − 0.5|`. Neither is a calibration guarantee.
|
|
73
78
|
|
package/dist/author.js
CHANGED
|
@@ -5,7 +5,7 @@ import { fileURLToPath } from "node:url";
|
|
|
5
5
|
import { join, resolve } from "node:path";
|
|
6
6
|
import { validateWorkflow } from "./workflow.js";
|
|
7
7
|
import { SYSTEM_ONE_LIMITS } from "./system-one.js";
|
|
8
|
-
import { WORKFLOW_NODE_KINDS, NODE_FIELDS, WORKFLOW_PREDICATES, PREDICATE_FIELDS, MECHANICAL_PREDICATES, EFFORT_LEVELS, THINKING_LEVELS, MODEL_TIERS, CALL_TRANSPORTS, CALL_RETRY_CLASSES, PROSE_ARTIFACT_TYPES, GENERATIVE_NODE_KINDS, JUDGMENT_NODE_KINDS, } from "./vocabulary.js";
|
|
8
|
+
import { WORKFLOW_NODE_KINDS, NODE_FIELDS, WORKFLOW_PREDICATES, PREDICATE_FIELDS, MECHANICAL_PREDICATES, EFFORT_LEVELS, THINKING_LEVELS, MODEL_TIERS, AGENT_CONTEXTS, CALL_TRANSPORTS, CALL_RETRY_CLASSES, EFFECT_FAILURE_CODES, PROSE_ARTIFACT_TYPES, GENERATIVE_NODE_KINDS, JUDGMENT_NODE_KINDS, } from "./vocabulary.js";
|
|
9
9
|
const code = (value) => `\`${value}\``;
|
|
10
10
|
const list = (values) => values.map(code).join(", ");
|
|
11
11
|
const alternatives = (values) => values.join("|");
|
|
@@ -59,9 +59,10 @@ Their fields:
|
|
|
59
59
|
- ${code("out")} names the schema the submission must satisfy; the value lands at ${code("as")}.
|
|
60
60
|
- ${code("requires")} lists state paths that must hold evidence before the node runs, each produced upstream: missing values, null, blank strings, empty arrays and empty objects stop the run; ${code("false")} and ${code("0")} pass.
|
|
61
61
|
- ${code("tools")} names tools the host offers. ${code("[]")} means no tools; omitting ${code("tools")} offers every tool the host allows. Never name a tool the host did not offer.
|
|
62
|
-
- ${code("effort")} is ${alternatives(EFFORT_LEVELS)}; ${code("thinking")} is ${alternatives(THINKING_LEVELS)} (never off); ${code("tier")} is ${alternatives(MODEL_TIERS)}. They are requests to the host: resource ceilings are the host's
|
|
62
|
+
- ${code("effort")} is ${alternatives(EFFORT_LEVELS)}; ${code("thinking")} is ${alternatives(THINKING_LEVELS)} (never off); ${code("tier")} is ${alternatives(MODEL_TIERS)}. They are requests to the host: resource ceilings are the host's.
|
|
63
|
+
- An ${code("agent")} node may carry ${code("budget_usd")}, the most it asks to spend in dollars (above 0), which the host caps by what it has left, and ${code("context")}, ${alternatives(AGENT_CONTEXTS)}: ${code("fresh")} (the default) sees only its instructions and state; ${code("fork")} asks the host to start it from the caller's transcript, which a host refuses where it has none.
|
|
63
64
|
- ${code("sopSection")} names one heading of the host's SOP, or a list of them, as the exact text after "## ". The node receives those sections verbatim.
|
|
64
|
-
- ${code("verify")} reviews a submission before it is accepted: {"out": a question schema with at least one boolean question, "state"?, "maxDrives"?: 1
|
|
65
|
+
- ${code("verify")} reviews a submission before it is accepted: {"out": a question schema with at least one boolean question, "state"?, "maxDrives"?: an integer >= 1 (default 2, no maximum), "override"?: {"below": a number in (0, 1), default 0.3}}. A boolean question named after a submission field doubts that field when its yes-probability is below ${code("override.below")}; any other boolean question is a requirement met at 0.5. A rejected submission returns to the same session with the reasons.
|
|
65
66
|
- When the workflow has a report, no decide or extract ${code("out")} schema carries ${code("report_markdown")}.
|
|
66
67
|
|
|
67
68
|
### Terminal nodes: report and artifact
|
|
@@ -76,7 +77,7 @@ Typed questions answered by the host's judge in one request each: no tools, no s
|
|
|
76
77
|
- A question schema is a flat object. Each property's ${code("description")} is its question. A boolean yields a yes-probability; a string enum (at most ${SYSTEM_ONE_LIMITS.maxChoiceOptions} options, optional per-option ${code("criteria")}) yields a choice; an integer with ${code("criteria")}: [level descriptions] (${SYSTEM_ONE_LIMITS.minScoreLevels} to ${SYSTEM_ONE_LIMITS.maxScoreLevels} levels, minimum 0, maximum the last level index) yields a score. Nothing else is a question.
|
|
77
78
|
- ${code("judge")}: a non-empty ${code("state")} map, ${code("out")} (a question schema) and ${code("as")}. The decoded value lands at ${code("as")}, the raw answers at ${code("<as>$answers")}.
|
|
78
79
|
- ${code("pick")}: ${code("itemsPath")}, ${code("describe")} (the option text per item, such as "{item.name}"), ${code("instructions")} (the one question) and ${code("as")}; ${code("allowNone")} adds a none-of-these option. The result is {index, item, none, option}.
|
|
79
|
-
- ${code("sift")}: ${code("itemsPath")}, ${code("out")} (a question schema asked of every item
|
|
80
|
+
- ${code("sift")}: ${code("itemsPath")}, ${code("out")} (a question schema asked of every item; the host splits the items across requests when they exceed its limits) and ${code("as")}. ${code("keep")} {path: a question id or <id>.confidence, never a choice, gte?} keeps passing items, in order, at ${code("<as>.items")}.
|
|
80
81
|
- ${code("route")}: a non-empty ${code("state")} map, ${code("instructions")} (the one question) and 2 to ${SYSTEM_ONE_LIMITS.maxChoiceOptions} named ${code("branches")}, each {criteria?, body}. ${code("unsure")} {branch: one of the branches, gte: a number in (0, 1]} takes that branch when the choice's confidence is below ${code("gte")}. ${code("as")} records the choice.
|
|
81
82
|
- A decoded boolean is true at yes-probability 0.5. To hold a different threshold, read ${code("<as>$answers.answers.<id>.noul")} in a code node.
|
|
82
83
|
|
|
@@ -85,21 +86,22 @@ Typed questions answered by the host's judge in one request each: no tools, no s
|
|
|
85
86
|
- ${code("chain")}: non-empty ${code("steps")}, run in order.
|
|
86
87
|
- ${code("map")}: ${code("itemsPath")} (an upstream list), ${code("body")} and ${code("as")}. The body sees ${code("item")} and ${code("item_index")}; ${code("maxConcurrency")} is a positive integer (default 4); ${code("resultPath")} selects one path from each completed item's state.
|
|
87
88
|
- ${code("parallel")}: at least two ${code("branches")}, each starting from the state before the parallel node. Branches write disjoint keys and never read a sibling's writes.
|
|
88
|
-
- ${code("loop")}: ${code("body")}, ${code("until")} (a predicate) and an integer ${code("maxIters")}
|
|
89
|
+
- ${code("loop")}: ${code("body")}, ${code("until")} (a predicate) and an integer ${code("maxIters")} of at least 1 (no maximum), optionally an integer ${code("expect_iters")} of at least 1 (priced passes). At the bound the state passes through with ${code("until")} unmet; follow the loop with an escalate or gate on that condition.
|
|
89
90
|
- ${code("escalate")}: ${code("when")} (a predicate), and non-empty ${code("kind")}, ${code("stage")} and ${code("summary")}. When the predicate holds the run stops without output and returns the escalation with its interpolated summary.
|
|
90
91
|
- ${code("workflow")}: ${code("label")}, ${code("workflow")} (a complete inline child), ${code("input")} (an object, interpolated, the child's entire initial state), ${code("out")} (a parent schema checked against the child's output) and ${code("as")}. The child declares ${code("input.schemaId")} in its own schemas and contains no report or artifact.
|
|
91
92
|
- ${code("code")}: ${code("code")} is one synchronous function expression such as "(s) => ({ total: s.items.length })". It receives the full state; return new values and never mutate it. ${code("Date")}, ${code("Promise")}, timers, ${code("fetch")}, ${code("require")}, ${code("process")}, ${code("Function")} and ${code("globalThis")} are unavailable. It is trusted host JavaScript, not a sandbox. Use code for typed-state mechanics, never to read meaning from prose.
|
|
92
|
-
- ${code("call")}: one side effect with no model in the loop. ${code("via")} is ${alternatives(CALL_TRANSPORTS)}; ${code("as")} and ${code("deadline_s")} (greater than 0,
|
|
93
|
+
- ${code("call")}: one side effect with no model in the loop. ${code("via")} is ${alternatives(CALL_TRANSPORTS)}; ${code("as")} and ${code("deadline_s")} (a finite number greater than 0, no maximum) are required — an unbounded effect is how a stalled provider becomes a stalled job.
|
|
93
94
|
- ${code("via: tool")} takes ${code("tool")} (a host tool address), ${code("args")} (an object) and ${code("out")} (the tool's result schema).
|
|
94
95
|
- ${code("via: executor")} takes ${code("code")} (a body that returns its JSON result and uses only ${code("tools")} and ${code("input")}), ${code("input")} and ${code("out")}.
|
|
95
96
|
- ${code("via: shell")} takes ${code("command")} (literal) and ${code("env")} (UPPER_CASE names to strings, interpolated by value; the way long values reach a command). Its result has the fixed shape {code, stdout, stderr, truncated?}: no ${code("out")}. Only a shell call may declare ${code("produces")} (workspace-relative files, checked after the effect).
|
|
96
|
-
- ${code("retry")} {attempts: 1
|
|
97
|
-
- ${code("poll")} {until, fail_when?, interval_s: 0.1
|
|
97
|
+
- ${code("retry")} {attempts: an integer >= 1, backoff_s?: a number >= 0, on?: [${[...CALL_RETRY_CLASSES, ...EFFECT_FAILURE_CODES].join(", ")}]}. ${code("where")} accepts only "sandbox".
|
|
98
|
+
- ${code("poll")} {until, fail_when?, interval_s: >= 0.1 (a busy-loop guard), deadline_s: at least the call's deadline_s (no maximum)} repeats the call until ${code("until")} holds on its own result; ${code("fail_when")} fails it at once. Both are mechanical predicates whose paths are relative to the result and lie in its declared shape.
|
|
98
99
|
- Validation and dry runs never perform effects: they synthesize the declared result, and a shell result's stdout is "{}".
|
|
99
100
|
|
|
100
101
|
## Predicates
|
|
101
102
|
|
|
102
103
|
${code("loop.until")} and ${code("escalate.when")} take one of these; ${code("poll")} takes only the first ${MECHANICAL_PREDICATES.length}. Each path or key reads a state value an input or an earlier node produced.
|
|
104
|
+
A predicate is one JSON object that names itself in its ${code("predicate")} field beside its own fields, for example ${code('{"predicate": "field_true", "path": "review.approved"}')}.
|
|
103
105
|
${predicateLines()}
|
|
104
106
|
|
|
105
107
|
## Authority
|
|
@@ -161,6 +163,9 @@ export function candidatePolicyErrors(candidate, options) {
|
|
|
161
163
|
errors.push(`${String(node.label ?? kind)}: this host does not run ${String(kind)} nodes`);
|
|
162
164
|
if (!options.allowExecutableCandidates && ["code", "call", "artifact"].includes(String(kind)) && !(kind === "call" && node.via === "tool" && typeof node.tool === "string" && options.allowedEffectTools?.includes(node.tool)))
|
|
163
165
|
errors.push(`${kind} requires allowExecutableCandidates`);
|
|
166
|
+
// `budget` on an agent is accepted for older documents and never read: an author writes budget_usd.
|
|
167
|
+
if (kind === "agent" && Object.hasOwn(node, "budget"))
|
|
168
|
+
errors.push(`${String(node.label ?? kind)}: budget is not read; declare budget_usd, the dollars the node asks to spend`);
|
|
164
169
|
if (sections.length && JUDGMENT_NODE_KINDS.includes(String(kind)))
|
|
165
170
|
errors.push(`${String(kind)} cannot carry supplied SOP sections; use an LLM node with sopSection`);
|
|
166
171
|
const llm = GENERATIVE_NODE_KINDS.includes(String(kind));
|
package/dist/code-exec.d.ts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/** The denied globals a transform's source names, in DENIED_GLOBALS order: a lexical scan of the source
|
|
2
|
+
* that skips comments, string and template text and regular-expression literals, and ignores a name
|
|
3
|
+
* read as a property (after `.` or `?.`). A name used as an object key or a local binding is still
|
|
4
|
+
* named: the lint refuses rather than guesses. It is a lint for untrusted authors, never a boundary:
|
|
5
|
+
* a host that runs such code isolates it (deps.runCode). */
|
|
6
|
+
export declare function deniedGlobalReferences(src: string): string[];
|
|
1
7
|
/** Parse the same expression as trusted execution, without evaluating it or calling its body.
|
|
2
8
|
* Syntax validity does not prove that the expression produces a function or a valid patch. */
|
|
3
9
|
export declare function compileTransformSyntax(src: string): void;
|
package/dist/code-exec.js
CHANGED
|
@@ -10,6 +10,132 @@ const DENIED_GLOBALS = [
|
|
|
10
10
|
"fetch", "XMLHttpRequest", "Function", "Buffer",
|
|
11
11
|
"setTimeout", "setInterval", "setImmediate", "queueMicrotask", "Promise", "Date",
|
|
12
12
|
];
|
|
13
|
+
/** Words after which a `/` starts a regular expression rather than a division. */
|
|
14
|
+
const REGEX_AFTER_WORDS = new Set(["return", "typeof", "instanceof", "in", "of", "new", "delete", "void", "throw", "case", "do", "else", "yield", "await"]);
|
|
15
|
+
const IDENTIFIER_START = /[A-Za-z_$\u0080-\uffff]/;
|
|
16
|
+
const IDENTIFIER_PART = /[A-Za-z0-9_$\u0080-\uffff]/;
|
|
17
|
+
/** The denied globals a transform's source names, in DENIED_GLOBALS order: a lexical scan of the source
|
|
18
|
+
* that skips comments, string and template text and regular-expression literals, and ignores a name
|
|
19
|
+
* read as a property (after `.` or `?.`). A name used as an object key or a local binding is still
|
|
20
|
+
* named: the lint refuses rather than guesses. It is a lint for untrusted authors, never a boundary:
|
|
21
|
+
* a host that runs such code isolates it (deps.runCode). */
|
|
22
|
+
export function deniedGlobalReferences(src) {
|
|
23
|
+
const denied = new Set(DENIED_GLOBALS);
|
|
24
|
+
const found = new Set();
|
|
25
|
+
const braces = [];
|
|
26
|
+
const n = typeof src === "string" ? src.length : 0;
|
|
27
|
+
let i = 0;
|
|
28
|
+
// The previous significant token: a word, a value (literal, closing bracket), or punctuation.
|
|
29
|
+
let prev = null;
|
|
30
|
+
/** Template text from i: true when it stopped at `${` (code follows), false at its closing backtick. */
|
|
31
|
+
const templateText = () => {
|
|
32
|
+
while (i < n) {
|
|
33
|
+
if (src[i] === "\\") {
|
|
34
|
+
i += 2;
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
if (src[i] === "`") {
|
|
38
|
+
i += 1;
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
if (src[i] === "$" && src[i + 1] === "{") {
|
|
42
|
+
i += 2;
|
|
43
|
+
braces.push("template");
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
i += 1;
|
|
47
|
+
}
|
|
48
|
+
return false;
|
|
49
|
+
};
|
|
50
|
+
while (i < n) {
|
|
51
|
+
const c = src[i];
|
|
52
|
+
if (/\s/.test(c)) {
|
|
53
|
+
i += 1;
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
if (c === "/" && src[i + 1] === "/") {
|
|
57
|
+
const end = src.indexOf("\n", i);
|
|
58
|
+
i = end < 0 ? n : end;
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
if (c === "/" && src[i + 1] === "*") {
|
|
62
|
+
const end = src.indexOf("*/", i + 2);
|
|
63
|
+
i = end < 0 ? n : end + 2;
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
if (c === "'" || c === '"') {
|
|
67
|
+
i += 1;
|
|
68
|
+
while (i < n && src[i] !== c)
|
|
69
|
+
i += src[i] === "\\" ? 2 : 1;
|
|
70
|
+
i += 1;
|
|
71
|
+
prev = { kind: "value", text: c };
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
if (c === "`" || (c === "}" && braces[braces.length - 1] === "template")) {
|
|
75
|
+
if (c === "}")
|
|
76
|
+
braces.pop();
|
|
77
|
+
i += 1;
|
|
78
|
+
prev = templateText() ? null : { kind: "value", text: "`" };
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
if (c === "/") {
|
|
82
|
+
const regex = prev === null || (prev.kind === "punct" && !")]}".includes(prev.text)) || (prev.kind === "word" && REGEX_AFTER_WORDS.has(prev.text));
|
|
83
|
+
if (regex) {
|
|
84
|
+
i += 1;
|
|
85
|
+
let inClass = false;
|
|
86
|
+
while (i < n && (inClass || src[i] !== "/")) {
|
|
87
|
+
if (src[i] === "\\") {
|
|
88
|
+
i += 2;
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
if (src[i] === "[")
|
|
92
|
+
inClass = true;
|
|
93
|
+
else if (src[i] === "]")
|
|
94
|
+
inClass = false;
|
|
95
|
+
i += 1;
|
|
96
|
+
}
|
|
97
|
+
i += 1;
|
|
98
|
+
while (i < n && IDENTIFIER_PART.test(src[i]))
|
|
99
|
+
i += 1;
|
|
100
|
+
prev = { kind: "value", text: "/" };
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (IDENTIFIER_START.test(c)) {
|
|
105
|
+
const start = i;
|
|
106
|
+
while (i < n && IDENTIFIER_PART.test(src[i]))
|
|
107
|
+
i += 1;
|
|
108
|
+
const word = src.slice(start, i);
|
|
109
|
+
if (denied.has(word) && !(prev?.kind === "punct" && prev.text === "."))
|
|
110
|
+
found.add(word);
|
|
111
|
+
prev = { kind: "word", text: word };
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
if (/[0-9]/.test(c)) {
|
|
115
|
+
while (i < n && IDENTIFIER_PART.test(src[i]))
|
|
116
|
+
i += 1;
|
|
117
|
+
prev = { kind: "value", text: "0" };
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
if (c === "." && src.startsWith("...", i)) {
|
|
121
|
+
i += 3;
|
|
122
|
+
prev = { kind: "punct", text: "..." };
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
if (c === "?" && src[i + 1] === "." && !/[0-9]/.test(src[i + 2] ?? "")) {
|
|
126
|
+
i += 2;
|
|
127
|
+
prev = { kind: "punct", text: "." };
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
if (c === "{")
|
|
131
|
+
braces.push("brace");
|
|
132
|
+
if (c === "}")
|
|
133
|
+
braces.pop();
|
|
134
|
+
i += 1;
|
|
135
|
+
prev = c === ")" || c === "]" || c === "}" ? { kind: "value", text: c } : { kind: "punct", text: c };
|
|
136
|
+
}
|
|
137
|
+
return DENIED_GLOBALS.filter((name) => found.has(name));
|
|
138
|
+
}
|
|
13
139
|
function createTransformFactory(src) {
|
|
14
140
|
if (typeof src !== "string" || !src.trim())
|
|
15
141
|
throw new Error("code transform source must be a non-empty string");
|
package/dist/dry-run.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Workflow } from "./workflow.js";
|
|
1
|
+
import { type Workflow, type WorkflowDeps } from "./workflow.js";
|
|
2
2
|
export type DryRunResult = {
|
|
3
3
|
ok: true;
|
|
4
4
|
skipped?: string[];
|
|
@@ -15,5 +15,8 @@ export type DryRunOptions = {
|
|
|
15
15
|
references_parsed?: Record<string, unknown>;
|
|
16
16
|
};
|
|
17
17
|
input?: Record<string, unknown>;
|
|
18
|
+
/** The host's executor for `code` nodes (WorkflowDeps.runCode). Present, the dry run validates
|
|
19
|
+
* with executeCode:false and hands every code node to it, so no code body runs in this process. */
|
|
20
|
+
runCode?: WorkflowDeps["runCode"];
|
|
18
21
|
};
|
|
19
22
|
export declare function dryRunWorkflow(workflow: Workflow, opts?: DryRunOptions): Promise<DryRunResult>;
|
package/dist/dry-run.js
CHANGED
|
@@ -116,7 +116,7 @@ function unsupportedConstructs(schema, path, found, depth = 0) {
|
|
|
116
116
|
return found;
|
|
117
117
|
}
|
|
118
118
|
export async function dryRunWorkflow(workflow, opts = {}) {
|
|
119
|
-
const valid = validateWorkflow(workflow, opts.input === undefined ?
|
|
119
|
+
const valid = validateWorkflow(workflow, { ...(opts.input === undefined ? {} : { input: opts.input }), ...(opts.runCode ? { executeCode: false } : {}) });
|
|
120
120
|
if (!valid.ok)
|
|
121
121
|
return { ok: false, problems: [new WorkflowInvalidError(String(workflow?.name), valid.errors).message] };
|
|
122
122
|
const skipped = [];
|
|
@@ -159,6 +159,7 @@ export async function dryRunWorkflow(workflow, opts = {}) {
|
|
|
159
159
|
try {
|
|
160
160
|
const result = await runWorkflow(workflow, input, {
|
|
161
161
|
sop: opts.sop,
|
|
162
|
+
...(opts.runCode ? { runCode: opts.runCode } : {}),
|
|
162
163
|
onEvent: (event) => { if (typeof event.label === "string")
|
|
163
164
|
currentLabel = event.label; },
|
|
164
165
|
runNode: async ({ schema, review }) => {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { defineWorkflow, runTypedWorkflow, WorkflowSchemaConversionError } from "./authoring.js";
|
|
2
2
|
export type { StandardJSONSchema, AuthoringSchema, TypedWorkflow, TypedWorkflowRunResult, WorkflowInput, WorkflowOutput, } from "./authoring.js";
|
|
3
3
|
export { runWorkflow, validateWorkflow, workflowSha256, WorkflowInvalidError, WorkflowInputInvalidError, WorkflowOutputInvalidError, WorkflowCodeError, WorkflowStateError, WorkflowVerificationError, EffectFailure, EffectDeadlineExceededError, EffectOutcomeUnknownError, EscalationSignal, } from "./workflow.js";
|
|
4
|
-
export type { Workflow, WorkflowNode, NodeMetadata, WorkflowDeps, WorkflowRunResult, HostPolicy, HostPolicyContext, Escalation, EffectSettlement, MapItem, LlmNode, JudgeNode, PickNode, SiftNode, RouteNode, WorkflowInvocation, ArtifactNode, ArtifactState, CallNode, CallRetryClass, CallPredicate, PollClause, ModelTier, WorkflowEffort, WorkflowThinking, VerifyClause, AskPredicate, MechanicalPredicate, Predicate, } from "./workflow.js";
|
|
4
|
+
export type { Workflow, WorkflowNode, NodeMetadata, WorkflowDeps, WorkflowEvent, WorkflowRunResult, HostPolicy, HostPolicyContext, Escalation, EffectSettlement, MapItem, LlmNode, JudgeNode, PickNode, SiftNode, RouteNode, WorkflowInvocation, ArtifactNode, ArtifactState, CallNode, CodeNode, CallRetryClass, EffectFailureCode, CallPredicate, PollClause, ModelTier, AgentContext, WorkflowEffort, WorkflowThinking, VerifyClause, AskPredicate, MechanicalPredicate, Predicate, } from "./workflow.js";
|
|
5
5
|
export { dryRunWorkflow, synthesizeInstance } from "./dry-run.js";
|
|
6
6
|
export type { DryRunOptions, DryRunResult } from "./dry-run.js";
|
|
7
7
|
export { compileQuestions, validateAnswers, answersToValue, answersSidecar, answerConfidence, synthesizeAnswers, SYSTEM_ONE_LIMITS, SystemOneError, isSystemOneResponseReason, } from "./system-one.js";
|
|
@@ -9,11 +9,11 @@ export type { SystemOneQuestion, SystemOneAnswer, SystemOneResult, SystemOneRetr
|
|
|
9
9
|
export { inspectWorkflow, formatWorkflowTree } from "./inspection.js";
|
|
10
10
|
export type { WorkflowInspection, WorkflowInspectionNode } from "./inspection.js";
|
|
11
11
|
export { runWorkflowSlice, assertWorkflowCapabilities, desugarWorkflow, stageSchemaForNode, submissionSchemaForNode, mergeStageDelta, REPORT_SCHEMA, SHELL_RESULT_SCHEMA, childSteps, declaredWrites, terminalArtifactType, artifactNodeIsProse, schemaProblems, HOST_STATE_KEY, buildReferenceContext, normalizeStringNullsForSchema, parseCsvRows, } from "./workflow.js";
|
|
12
|
-
export { compileTransform, compileTransformSyntax } from "./code-exec.js";
|
|
12
|
+
export { compileTransform, compileTransformSyntax, deniedGlobalReferences } from "./code-exec.js";
|
|
13
13
|
export { resolveSchemaForWorkflow } from "./schema-references.js";
|
|
14
14
|
export { getPath, predicateMatches } from "./predicates.js";
|
|
15
15
|
export type { StopPredicate, AcceptPredicate } from "./predicates.js";
|
|
16
16
|
export { authorContract, renderAuthorContract, renderAuthorHostAddendum, candidatePolicyErrors, applyHostOutputTypes, authorWorkflow, AUTHOR_SKILL_NAME, authorSkillDirectory, loadAuthorReference, loadAuthorSkillBundle, } from "./author.js";
|
|
17
17
|
export type { AuthorHostAddendum, CandidatePolicyOptions, AuthorWorkflowOptions, AuthoredWorkflow } from "./author.js";
|
|
18
|
-
export { WORKFLOW_NODE_KINDS, GENERATIVE_NODE_KINDS, JUDGMENT_NODE_KINDS, NODE_FIELDS, HOST_NODE_FIELDS, IGNORED_NODE_FIELDS, MECHANICAL_PREDICATES, WORKFLOW_PREDICATES, PREDICATE_FIELDS, EFFORT_LEVELS, THINKING_LEVELS, MODEL_TIERS, CALL_TRANSPORTS, CALL_RETRY_CLASSES, PROSE_ARTIFACT_TYPES, } from "./vocabulary.js";
|
|
18
|
+
export { WORKFLOW_NODE_KINDS, GENERATIVE_NODE_KINDS, JUDGMENT_NODE_KINDS, NODE_FIELDS, HOST_NODE_FIELDS, IGNORED_NODE_FIELDS, MECHANICAL_PREDICATES, WORKFLOW_PREDICATES, PREDICATE_FIELDS, EFFORT_LEVELS, THINKING_LEVELS, MODEL_TIERS, AGENT_CONTEXTS, CALL_TRANSPORTS, CALL_RETRY_CLASSES, EFFECT_FAILURE_CODES, PROSE_ARTIFACT_TYPES, } from "./vocabulary.js";
|
|
19
19
|
export type { WorkflowNodeKind, WorkflowPredicateName } from "./vocabulary.js";
|
package/dist/index.js
CHANGED
|
@@ -8,8 +8,8 @@ export { runWorkflowSlice, assertWorkflowCapabilities, desugarWorkflow, stageSch
|
|
|
8
8
|
childSteps, declaredWrites, terminalArtifactType, artifactNodeIsProse, schemaProblems, HOST_STATE_KEY,
|
|
9
9
|
// Host-side data helpers the interpreter itself uses: the same normalization and reference shaping.
|
|
10
10
|
buildReferenceContext, normalizeStringNullsForSchema, parseCsvRows, } from "./workflow.js";
|
|
11
|
-
export { compileTransform, compileTransformSyntax } from "./code-exec.js";
|
|
11
|
+
export { compileTransform, compileTransformSyntax, deniedGlobalReferences } from "./code-exec.js";
|
|
12
12
|
export { resolveSchemaForWorkflow } from "./schema-references.js";
|
|
13
13
|
export { getPath, predicateMatches } from "./predicates.js";
|
|
14
14
|
export { authorContract, renderAuthorContract, renderAuthorHostAddendum, candidatePolicyErrors, applyHostOutputTypes, authorWorkflow, AUTHOR_SKILL_NAME, authorSkillDirectory, loadAuthorReference, loadAuthorSkillBundle, } from "./author.js";
|
|
15
|
-
export { WORKFLOW_NODE_KINDS, GENERATIVE_NODE_KINDS, JUDGMENT_NODE_KINDS, NODE_FIELDS, HOST_NODE_FIELDS, IGNORED_NODE_FIELDS, MECHANICAL_PREDICATES, WORKFLOW_PREDICATES, PREDICATE_FIELDS, EFFORT_LEVELS, THINKING_LEVELS, MODEL_TIERS, CALL_TRANSPORTS, CALL_RETRY_CLASSES, PROSE_ARTIFACT_TYPES, } from "./vocabulary.js";
|
|
15
|
+
export { WORKFLOW_NODE_KINDS, GENERATIVE_NODE_KINDS, JUDGMENT_NODE_KINDS, NODE_FIELDS, HOST_NODE_FIELDS, IGNORED_NODE_FIELDS, MECHANICAL_PREDICATES, WORKFLOW_PREDICATES, PREDICATE_FIELDS, EFFORT_LEVELS, THINKING_LEVELS, MODEL_TIERS, AGENT_CONTEXTS, CALL_TRANSPORTS, CALL_RETRY_CLASSES, EFFECT_FAILURE_CODES, PROSE_ARTIFACT_TYPES, } from "./vocabulary.js";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const MAX_TIMER_DELAY_MS: number;
|
|
2
|
+
export type LongTimer = {
|
|
3
|
+
clear(): void;
|
|
4
|
+
};
|
|
5
|
+
/** Schedule `fn` after `ms`, re-arming in <= MAX_TIMER_DELAY_MS chunks so a delay past Node's timer
|
|
6
|
+
* limit still fires on time instead of overflowing. `clear()` cancels the pending chunk. */
|
|
7
|
+
export declare function setLongTimeout(fn: () => void, ms: number): LongTimer;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// Node's timers accept a delay of at most 2^31-1 ms (~24.8 days); a larger delay silently overflows
|
|
2
|
+
// to a near-immediate fire with a TimeoutOverflowWarning. A workflow's deadline_s, poll.deadline_s,
|
|
3
|
+
// poll.interval_s and retry.backoff_s carry no upper ceiling, so a delay derived from them can exceed
|
|
4
|
+
// that. `setLongTimeout` re-arms in <= MAX_TIMER_DELAY_MS chunks, so the callback fires at the
|
|
5
|
+
// intended time however far out it is, and returns a handle that clears whichever chunk is pending.
|
|
6
|
+
export const MAX_TIMER_DELAY_MS = 2 ** 31 - 1;
|
|
7
|
+
/** Schedule `fn` after `ms`, re-arming in <= MAX_TIMER_DELAY_MS chunks so a delay past Node's timer
|
|
8
|
+
* limit still fires on time instead of overflowing. `clear()` cancels the pending chunk. */
|
|
9
|
+
export function setLongTimeout(fn, ms) {
|
|
10
|
+
let remaining = Number.isFinite(ms) ? Math.max(0, ms) : MAX_TIMER_DELAY_MS;
|
|
11
|
+
let handle;
|
|
12
|
+
const tick = () => {
|
|
13
|
+
if (remaining <= MAX_TIMER_DELAY_MS) {
|
|
14
|
+
handle = setTimeout(fn, remaining);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
remaining -= MAX_TIMER_DELAY_MS;
|
|
18
|
+
handle = setTimeout(tick, MAX_TIMER_DELAY_MS);
|
|
19
|
+
};
|
|
20
|
+
tick();
|
|
21
|
+
return { clear() { clearTimeout(handle); } };
|
|
22
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { isProxy } from "node:util/types";
|
|
2
|
+
/** Copy observation data without reading accessors or sharing mutable data objects.
|
|
3
|
+
* Keep invalid JSON shapes visible so required host trace validation can reject them. */
|
|
4
|
+
export function observerSnapshot(value) {
|
|
5
|
+
const seen = new Map();
|
|
6
|
+
const pending = [];
|
|
7
|
+
const copy = (item) => {
|
|
8
|
+
// A proxy can execute code even when its property descriptors are inspected.
|
|
9
|
+
if (isProxy(item))
|
|
10
|
+
return function unavailable() { };
|
|
11
|
+
if (item === null || typeof item !== "object") {
|
|
12
|
+
// Functions are invalid observation data; an inert function preserves that
|
|
13
|
+
// fact without giving an observer the original callable or its properties.
|
|
14
|
+
return typeof item === "function" ? function unavailable() { } : item;
|
|
15
|
+
}
|
|
16
|
+
const known = seen.get(item);
|
|
17
|
+
if (known)
|
|
18
|
+
return known;
|
|
19
|
+
const prototype = Object.getPrototypeOf(item);
|
|
20
|
+
if (prototype !== Object.prototype && prototype !== Array.prototype && prototype !== null)
|
|
21
|
+
return function unavailable() { };
|
|
22
|
+
const target = Array.isArray(item) ? [] : Object.create(prototype);
|
|
23
|
+
seen.set(item, target);
|
|
24
|
+
pending.push([item, target]);
|
|
25
|
+
return target;
|
|
26
|
+
};
|
|
27
|
+
const result = copy(value);
|
|
28
|
+
while (pending.length) {
|
|
29
|
+
const [source, target] = pending.pop();
|
|
30
|
+
for (const key of Reflect.ownKeys(source)) {
|
|
31
|
+
const descriptor = Object.getOwnPropertyDescriptor(source, key);
|
|
32
|
+
if ("value" in descriptor)
|
|
33
|
+
descriptor.value = copy(descriptor.value);
|
|
34
|
+
else {
|
|
35
|
+
// Never invoke authored getters, including during cloning. Their shape
|
|
36
|
+
// remains an accessor so a JSON-validating host still fails closed.
|
|
37
|
+
if (descriptor.get)
|
|
38
|
+
descriptor.get = () => undefined;
|
|
39
|
+
if (descriptor.set)
|
|
40
|
+
descriptor.set = () => { };
|
|
41
|
+
}
|
|
42
|
+
Object.defineProperty(target, key, descriptor);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return result;
|
|
46
|
+
}
|
package/dist/system-one.js
CHANGED
|
@@ -166,6 +166,33 @@ function roundedFromUnitMass(probabilities) {
|
|
|
166
166
|
}
|
|
167
167
|
return low <= 1 + 1e-5 && high >= 1 - 1e-5;
|
|
168
168
|
}
|
|
169
|
+
// A Score's weighted level drifts the same way. The unrounded probabilities lie within their rounding
|
|
170
|
+
// intervals and sum to 1, so Σ level·p lies between two bounds: start every level at its interval's
|
|
171
|
+
// low end, then give the rest of the unit mass to the lowest levels (the minimum) or the highest (the
|
|
172
|
+
// maximum), each up to its interval's high end. A score on the grid is itself off by up to 0.005. The
|
|
173
|
+
// score is accepted when its interval meets [min, max]; with no grid values this is
|
|
174
|
+
// |score − Σ level·p| ≤ 1e-5. A score that is not a number contradicts nothing here and is left to
|
|
175
|
+
// the range check, as before.
|
|
176
|
+
function scoreContradictsDistribution(score, probabilities) {
|
|
177
|
+
const levels = Object.entries(probabilities).map(([level, p]) => {
|
|
178
|
+
const step = onTwoPlaceGrid(p) ? ROUNDING_HALF_STEP : 0;
|
|
179
|
+
return { level: Number(level), low: Math.max(0, p - step), high: Math.min(1, p + step) };
|
|
180
|
+
}).sort((a, b) => a.level - b.level);
|
|
181
|
+
const floor = levels.reduce((sum, l) => sum + l.level * l.low, 0);
|
|
182
|
+
const spare = Math.max(0, 1 - levels.reduce((sum, l) => sum + l.low, 0));
|
|
183
|
+
const fill = (order) => {
|
|
184
|
+
let rest = spare, weighted = floor;
|
|
185
|
+
for (const l of order) {
|
|
186
|
+
const add = Math.min(rest, l.high - l.low);
|
|
187
|
+
weighted += l.level * add;
|
|
188
|
+
rest -= add;
|
|
189
|
+
}
|
|
190
|
+
return weighted;
|
|
191
|
+
};
|
|
192
|
+
const min = fill(levels), max = fill([...levels].reverse());
|
|
193
|
+
const step = onTwoPlaceGrid(score) ? ROUNDING_HALF_STEP : 0;
|
|
194
|
+
return score - step > max + 1e-5 || score + step < min - 1e-5;
|
|
195
|
+
}
|
|
169
196
|
export function validateAnswers(questions, answers) {
|
|
170
197
|
if (!answers || typeof answers !== "object" || Array.isArray(answers))
|
|
171
198
|
throw new SystemOneError("System One response carries no answers", null, undefined, "answers_shape");
|
|
@@ -196,8 +223,7 @@ export function validateAnswers(questions, answers) {
|
|
|
196
223
|
if (q.type === "score") {
|
|
197
224
|
if (!a.legend || typeof a.legend !== "object" || Array.isArray(a.legend) || Object.keys(a.legend).length !== expectedKeys.length || q.criteria.some((text, index) => a.legend[String(index)] !== text))
|
|
198
225
|
throw new SystemOneError("System One answer: legend must match the score criteria", null, undefined, "score_legend");
|
|
199
|
-
|
|
200
|
-
if (Math.abs(weighted - a.score) > 1e-5)
|
|
226
|
+
if (scoreContradictsDistribution(a.score, a.probabilities))
|
|
201
227
|
throw new SystemOneError("System One answer: score must match its weighted distribution", null, undefined, "score_consistency");
|
|
202
228
|
}
|
|
203
229
|
if (q.type === "choice" && !(typeof a.choice === "string" && Object.prototype.hasOwnProperty.call(q.criteria, a.choice)))
|
package/dist/vocabulary.d.ts
CHANGED
|
@@ -28,7 +28,15 @@ export declare const EFFORT_LEVELS: readonly ["minimal", "low", "medium", "high"
|
|
|
28
28
|
/** There is no "off": every generative node thinks. */
|
|
29
29
|
export declare const THINKING_LEVELS: readonly ["low", "medium", "high"];
|
|
30
30
|
export declare const MODEL_TIERS: readonly ["fast", "default", "strong"];
|
|
31
|
+
/** An `agent` node's context: `fresh` sees its instructions and state only; `fork` asks the host to start
|
|
32
|
+
* the node from the caller's transcript, where the host can (a host refuses it where it cannot). */
|
|
33
|
+
export declare const AGENT_CONTEXTS: readonly ["fresh", "fork"];
|
|
31
34
|
export declare const CALL_TRANSPORTS: readonly ["tool", "executor", "shell"];
|
|
32
35
|
export declare const CALL_RETRY_CLASSES: readonly ["timeout", "http_5xx", "http_429", "connection", "exit"];
|
|
36
|
+
/** The closed codes a failed effect carries: a call's, or a code node's that a host runs out of process.
|
|
37
|
+
* `retry.on` names these or the retry classes above. A retry class implies its code (timeout is
|
|
38
|
+
* effect_timeout, exit is effect_exit, the transient transport classes are effect_transport); a host
|
|
39
|
+
* that types a failure itself names the code. */
|
|
40
|
+
export declare const EFFECT_FAILURE_CODES: readonly ["effect_timeout", "effect_exit", "effect_transport", "effect_not_granted", "effect_produces_missing", "effect_path_escape", "effect_code_unsafe", "output_invalid", "state_invalid", "effect_unknown_transport"];
|
|
33
41
|
/** Artifact types the engine itself treats as prose (the report writer). Every other type names a file. */
|
|
34
42
|
export declare const PROSE_ARTIFACT_TYPES: readonly ["markdown", "report"];
|
package/dist/vocabulary.js
CHANGED
|
@@ -13,14 +13,14 @@ const GENERATIVE_FIELDS = ["node", "label", "state", "instructions", "sopSection
|
|
|
13
13
|
export const NODE_FIELDS = {
|
|
14
14
|
chain: ["node", "steps"],
|
|
15
15
|
code: ["node", "label", "code", "as"],
|
|
16
|
-
agent: GENERATIVE_FIELDS,
|
|
16
|
+
agent: [...GENERATIVE_FIELDS, "budget_usd", "context"],
|
|
17
17
|
decide: GENERATIVE_FIELDS,
|
|
18
18
|
extract: GENERATIVE_FIELDS,
|
|
19
19
|
report: ["node", "label", "state", "instructions", "sopSection", "requires", "tools", "effort", "thinking"],
|
|
20
20
|
artifact: ["node", "label", "state", "type", "path", "instructions", "sopSection", "requires", "tools", "effort", "thinking"],
|
|
21
21
|
map: ["node", "label", "itemsPath", "body", "as", "resultPath", "maxConcurrency"],
|
|
22
22
|
parallel: ["node", "label", "branches"],
|
|
23
|
-
loop: ["node", "label", "body", "until", "maxIters"],
|
|
23
|
+
loop: ["node", "label", "body", "until", "maxIters", "expect_iters"],
|
|
24
24
|
escalate: ["node", "label", "when", "kind", "stage", "summary"],
|
|
25
25
|
call: ["node", "label", "via", "tool", "args", "code", "input", "command", "env", "where", "out", "as", "produces", "deadline_s", "retry", "poll", "requires"],
|
|
26
26
|
workflow: ["node", "label", "workflow", "input", "out", "as"],
|
|
@@ -57,7 +57,18 @@ export const EFFORT_LEVELS = ["minimal", "low", "medium", "high"];
|
|
|
57
57
|
/** There is no "off": every generative node thinks. */
|
|
58
58
|
export const THINKING_LEVELS = ["low", "medium", "high"];
|
|
59
59
|
export const MODEL_TIERS = ["fast", "default", "strong"];
|
|
60
|
+
/** An `agent` node's context: `fresh` sees its instructions and state only; `fork` asks the host to start
|
|
61
|
+
* the node from the caller's transcript, where the host can (a host refuses it where it cannot). */
|
|
62
|
+
export const AGENT_CONTEXTS = ["fresh", "fork"];
|
|
60
63
|
export const CALL_TRANSPORTS = ["tool", "executor", "shell"];
|
|
61
64
|
export const CALL_RETRY_CLASSES = ["timeout", "http_5xx", "http_429", "connection", "exit"];
|
|
65
|
+
/** The closed codes a failed effect carries: a call's, or a code node's that a host runs out of process.
|
|
66
|
+
* `retry.on` names these or the retry classes above. A retry class implies its code (timeout is
|
|
67
|
+
* effect_timeout, exit is effect_exit, the transient transport classes are effect_transport); a host
|
|
68
|
+
* that types a failure itself names the code. */
|
|
69
|
+
export const EFFECT_FAILURE_CODES = [
|
|
70
|
+
"effect_timeout", "effect_exit", "effect_transport", "effect_not_granted", "effect_produces_missing",
|
|
71
|
+
"effect_path_escape", "effect_code_unsafe", "output_invalid", "state_invalid", "effect_unknown_transport",
|
|
72
|
+
];
|
|
62
73
|
/** Artifact types the engine itself treats as prose (the report writer). Every other type names a file. */
|
|
63
74
|
export const PROSE_ARTIFACT_TYPES = ["markdown", "report"];
|
package/dist/workflow-shape.js
CHANGED
|
@@ -117,7 +117,7 @@ export function workflowShapeErrors(value, complete = false) {
|
|
|
117
117
|
if (!record(entry, path))
|
|
118
118
|
return;
|
|
119
119
|
strings(entry, path, ["node", "label", "code", "as", "out", "instructions", "itemsPath", "resultPath", "kind", "stage", "summary", "describe", "type", "path", "tool", "command", "via", "where", "effort", "thinking", "tier"]);
|
|
120
|
-
numeric(entry, path, ["maxConcurrency", "maxIters", "deadline_s"]);
|
|
120
|
+
numeric(entry, path, ["maxConcurrency", "maxIters", "expect_iters", "deadline_s"]);
|
|
121
121
|
for (const key of ["requires", "tools", "produces"])
|
|
122
122
|
stringList(entry[key], `${path}.${key}`);
|
|
123
123
|
if (entry.sopSection !== undefined && typeof entry.sopSection !== "string")
|