@parcha/agentrun-dsl 0.1.0-beta.41 → 0.1.0-beta.43

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.
@@ -13,22 +13,11 @@ export const DECISION_NODE_FIELDS = ["provider", "model", "evidence", "timeoutMs
13
13
  export const DECISION_TIMEOUT_MAX_MS = 120_000;
14
14
  /** Typed-question kinds: one judge request each, no tools and no session. */
15
15
  export const JUDGMENT_NODE_KINDS = ["judge", "pick", "sift", "route"];
16
- const GENERATIVE_FIELDS = ["node", "label", "state", "instructions", "sopSection", "out", "as", "requires", "tools", "effort", "thinking", "verify", "tier", "guard"];
17
- /** A step guard's signals: `self`, the step's own confidence; `jev`, one Jev question over the step's input and output;
18
- * `both`, the two combined. */
19
- export const GUARD_SIGNALS = ["self", "jev", "both"];
20
- /** The fields a step guard takes. */
21
- export const GUARD_FIELDS = ["signal", "threshold", "question", "fit"];
22
- /** The kinds a guard may sit on: the steps that write a value. */
23
- export const GUARDED_NODE_KINDS = ["agent", "decide", "extract", "code", "call", "workflow", "judge", "pick", "sift"];
24
- /** The kinds that report a confidence of their own, so a guard on one may read `self`: agent and decide nodes submit one
25
- * beside their record, judge, pick and sift nodes take their answers' weakest. The others (extract, code, call,
26
- * workflow) have none: their guard reads jev only. */
27
- export const SELF_CONFIDENCE_KINDS = ["agent", "decide", "judge", "pick", "sift"];
16
+ const GENERATIVE_FIELDS = ["node", "label", "state", "instructions", "sopSection", "out", "as", "requires", "tools", "effort", "thinking", "verify", "tier"];
28
17
  /** The fields each node kind accepts. Any other key is an authoring error. */
29
18
  export const NODE_FIELDS = {
30
19
  chain: ["node", "steps"],
31
- code: ["node", "label", "code", "as", "guard"],
20
+ code: ["node", "label", "code", "as"],
32
21
  agent: [...GENERATIVE_FIELDS, "budget_usd", "max_turns", "context"],
33
22
  decide: GENERATIVE_FIELDS,
34
23
  extract: GENERATIVE_FIELDS,
@@ -38,11 +27,11 @@ export const NODE_FIELDS = {
38
27
  parallel: ["node", "label", "branches"],
39
28
  loop: ["node", "label", "body", "until", "maxIters", "expect_iters"],
40
29
  escalate: ["node", "label", "when", "kind", "stage", "summary"],
41
- call: ["node", "label", "via", "tool", "args", "code", "input", "command", "env", "where", "out", "as", "produces", "deadline_s", "retry", "poll", "requires", "guard"],
42
- workflow: ["node", "label", "workflow", "input", "out", "as", "guard"],
43
- judge: ["node", "label", "state", "out", "as", "requires", ...DECISION_NODE_FIELDS, "guard"],
44
- pick: ["node", "label", "itemsPath", "describe", "instructions", "state", "allowNone", "as", "requires", ...DECISION_NODE_FIELDS, "guard"],
45
- sift: ["node", "label", "itemsPath", "describe", "state", "out", "as", "keep", "requires", ...DECISION_NODE_FIELDS, "guard"],
30
+ call: ["node", "label", "via", "tool", "args", "code", "input", "command", "env", "where", "out", "as", "produces", "deadline_s", "retry", "poll", "requires"],
31
+ workflow: ["node", "label", "workflow", "input", "out", "as"],
32
+ judge: ["node", "label", "state", "out", "as", "requires", ...DECISION_NODE_FIELDS],
33
+ pick: ["node", "label", "itemsPath", "describe", "instructions", "state", "allowNone", "as", "requires", ...DECISION_NODE_FIELDS],
34
+ sift: ["node", "label", "itemsPath", "describe", "state", "out", "as", "keep", "requires", ...DECISION_NODE_FIELDS],
46
35
  route: ["node", "label", "state", "instructions", "branches", "unsure", "valuePath", "otherwise", "as", "requires", ...DECISION_NODE_FIELDS],
47
36
  };
48
37
  /** Fields every node kind accepts in addition to its own. `metadata` is the host's: an optional object of
@@ -1,5 +1,5 @@
1
1
  import { type AcceptPredicate } from "./predicates.js";
2
- import { type GuardSignal, EFFECT_FAILURE_CODES } from "./vocabulary.js";
2
+ import { EFFECT_FAILURE_CODES } from "./vocabulary.js";
3
3
  import { type ConfidenceSource, type SystemOneAnswer, type SystemOneQuestion } from "./system-one.js";
4
4
  import { type CostBasis, type DecisionEvidence, type DecisionProvider } from "./decision-provider.js";
5
5
  import { type DecisionImageDigest, type DecisionReceipt, type DecisionStateSent } from "./decision-receipts.js";
@@ -49,32 +49,6 @@ export type WorkflowThinking = "low" | "medium" | "high";
49
49
  export type NodeMetadata = {
50
50
  [key: string]: unknown;
51
51
  };
52
- /** A step guard as a document holds it (StepGuard once validateWorkflow accepted it): an object the validator reads field
53
- * by field, so a wrong signal or threshold is refused in words an author can act on, never a schema union's. */
54
- export type NodeGuard = {
55
- [key: string]: unknown;
56
- };
57
- /** A logistic fitted on the job's graded runs: p = 1 / (1 + e^-(b + w·x)), x the guard's signals in order ([self], [jev] or
58
- * [self, jev]); `n` the graded runs it was fitted on, `fitted_at` when (ISO 8601). */
59
- export type GuardFit = {
60
- w: number[];
61
- b: number;
62
- n: number;
63
- fitted_at: string;
64
- };
65
- /** The longest question a guard asks Jev, in characters. */
66
- export declare const GUARD_QUESTION_MAX = 2000;
67
- /** A step guard: after the step ran, the probability it is right (`p`, from its signal, through `fit` when one is stored);
68
- * below `threshold` the run hands the job back (escalates, kind `guard`). `self` reads the step's own confidence (agent,
69
- * decide, judge, pick, sift); `jev` one Jev question over the step's input and output (`question`, or the host's default);
70
- * `both` a fitted logistic over [self, jev], or with no fit the lower of the two. The engine reads its shape and the
71
- * step's own confidence; the host's `guardStep` computes p (it asks Jev). */
72
- export type StepGuard = {
73
- signal: GuardSignal;
74
- threshold: number;
75
- question?: string;
76
- fit?: GuardFit;
77
- };
78
52
  export type WorkflowNode = {
79
53
  node: "chain";
80
54
  steps: WorkflowNode[];
@@ -84,7 +58,6 @@ export type WorkflowNode = {
84
58
  label: string;
85
59
  code: string;
86
60
  as?: string;
87
- guard?: NodeGuard;
88
61
  metadata?: NodeMetadata;
89
62
  } | {
90
63
  node: "agent";
@@ -106,7 +79,6 @@ export type WorkflowNode = {
106
79
  * enforces nothing. @minimum 1 @TJS-type integer */
107
80
  max_turns?: number;
108
81
  context?: AgentContext;
109
- guard?: NodeGuard;
110
82
  metadata?: NodeMetadata;
111
83
  } | {
112
84
  node: "decide";
@@ -122,7 +94,6 @@ export type WorkflowNode = {
122
94
  thinking?: WorkflowThinking;
123
95
  verify?: VerifyClause;
124
96
  tier?: ModelTier;
125
- guard?: NodeGuard;
126
97
  metadata?: NodeMetadata;
127
98
  } | {
128
99
  node: "extract";
@@ -138,7 +109,6 @@ export type WorkflowNode = {
138
109
  thinking?: WorkflowThinking;
139
110
  verify?: VerifyClause;
140
111
  tier?: ModelTier;
141
- guard?: NodeGuard;
142
112
  metadata?: NodeMetadata;
143
113
  } | {
144
114
  node: "report";
@@ -204,7 +174,6 @@ export type JudgeNode = {
204
174
  evidence?: DecisionEvidenceMode;
205
175
  timeoutMs?: number;
206
176
  images?: DecisionImages;
207
- guard?: NodeGuard;
208
177
  metadata?: NodeMetadata;
209
178
  };
210
179
  /** One choice whose options are the items of a list. `describe` renders each item as its option
@@ -226,7 +195,6 @@ export type PickNode = {
226
195
  evidence?: DecisionEvidenceMode;
227
196
  timeoutMs?: number;
228
197
  images?: DecisionImages;
229
- guard?: NodeGuard;
230
198
  metadata?: NodeMetadata;
231
199
  };
232
200
  /** The same question set (`out`, a judge schema) asked of every item of a list in ONE request: item i's
@@ -251,7 +219,6 @@ export type SiftNode = {
251
219
  evidence?: DecisionEvidenceMode;
252
220
  timeoutMs?: number;
253
221
  images?: DecisionImages;
254
- guard?: NodeGuard;
255
222
  metadata?: NodeMetadata;
256
223
  };
257
224
  /** Run one of several named branches. Jev chooses it from `instructions` and `state`, or the workflow
@@ -319,7 +286,6 @@ export type WorkflowInvocation = {
319
286
  input: Record<string, unknown>;
320
287
  out: string;
321
288
  as: string;
322
- guard?: NodeGuard;
323
289
  metadata?: NodeMetadata;
324
290
  };
325
291
  /** `exit` is a shell command that ended with a non-zero status: retried only when the author
@@ -403,8 +369,6 @@ export type CallNode = {
403
369
  /** Repeat the call until its result settles (a queued job, an eventually consistent read). */
404
370
  poll?: PollClause;
405
371
  requires?: string[];
406
- /** A step guard (StepGuard): its signal can only be `jev`, a call reports no confidence. */
407
- guard?: NodeGuard;
408
372
  metadata?: NodeMetadata;
409
373
  };
410
374
  export declare const SHELL_RESULT_SCHEMA: Record<string, unknown>;
@@ -627,18 +591,6 @@ export type WorkflowDeps = {
627
591
  * records it, not the state asked. A failed request's DecisionProviderError carries it as `stateSent`. */
628
592
  state_sent?: DecisionStateSent;
629
593
  }>;
630
- /** The host's step guards (StepGuard), asked after each guarded step ran and before its state is committed: what the
631
- * step saw (`input`), what it wrote (`output`), and its own confidence (`self`: an agent or decide node's submitted
632
- * one, a judge, pick or sift node's weakest answer's; null when the guard reads none or the step reported none). It
633
- * answers the probability the step is right (`p`); below the guard's threshold, or with no p, the run hands the job
634
- * back: it escalates (kind `guard`, stage the step's label) with the step's state. A workflow that holds a guard is
635
- * refused before any node runs on a host without it. */
636
- guardStep?: (params: GuardStepParams) => Promise<GuardVerdict>;
637
- /** Escalate nodes the host records instead of obeying, by label (a child workflow's as its events name it,
638
- * `parent/child`): one it says true of evaluates its `when` as any does and says so in its `escalate.evaluated` event
639
- * (`soft: true`), and the run goes on past it whether it fired or not. A replay reads what the workflow would have
640
- * answered past a check it is measuring. Absent: every escalate that fires hands the job back. */
641
- softEscalate?: (label: string) => boolean;
642
594
  /** Records one typed-question request and what its answers decide. It is awaited before the answers
643
595
  * reach state, an event or a branch, so a durable recorder holds every decision the run acted on; a
644
596
  * rejection fails the node. A request the judge could not answer, or one cancelled in flight, is
@@ -695,46 +647,6 @@ export type WorkflowEvent = {
695
647
  detail?: unknown;
696
648
  executionPath?: string;
697
649
  };
698
- /** What a host's `guardStep` is asked with (WorkflowDeps.guardStep). */
699
- export type GuardStepParams = {
700
- label: string;
701
- kind: WorkflowNode["node"];
702
- guard: StepGuard;
703
- /** What the step was asked to do (guardAskOf): without it two steps over the same input that ask for different things
704
- * read the same to Jev. */
705
- task: GuardTask;
706
- /** What the step saw: its interpolated `state` (or a call's `args`, an executor's `input`, a child's `input`), else the
707
- * workflow's state before it. */
708
- input: unknown;
709
- /** What the step wrote: the value under its `as` (or its label), or the keys it changed. */
710
- output: unknown;
711
- /** The step's own confidence in [0, 1], for a guard that reads it; null otherwise or when it reported none. */
712
- self: number | null;
713
- executionPath: string;
714
- item?: MapItem;
715
- signal?: AbortSignal;
716
- };
717
- /** What a guarded step was asked to do, as its guard is asked about it, its instructions first: an agent, decide, extract
718
- * or pick node's `instructions` (a pick's with whether none may fit); a judge or sift's questions (its `out` compiled,
719
- * each question's type and words, as its judge was asked them); the schema its value meets (an agent, decide or extract
720
- * node's `out`, a call's or a child workflow's); a code node's or an executor's code, a tool call's tool, a shell's
721
- * command, a child's workflow name. */
722
- export type GuardTask = {
723
- instructions?: string;
724
- allow_none?: boolean;
725
- questions?: Record<string, unknown>;
726
- schema?: unknown;
727
- code?: string;
728
- tool?: string;
729
- command?: string;
730
- workflow?: string;
731
- };
732
- /** A host's guard verdict: `p`, the probability the step is right. */
733
- export type GuardVerdict = {
734
- p: number;
735
- /** Jev's answer, for a guard that asked it: what the run record keeps beside p. */
736
- jev?: number | null;
737
- };
738
650
  type JudgeRequest = Parameters<NonNullable<WorkflowDeps["runJudge"]>>[0];
739
651
  type JudgeResult = Awaited<ReturnType<NonNullable<WorkflowDeps["runJudge"]>>>;
740
652
  /** What a decision recorder gets beside the receipt: the request as the host's `runJudge` received it,
@@ -802,6 +714,16 @@ export declare function validateWorkflow(workflow: Workflow, opts?: ValidateWork
802
714
  issues: ValidationIssue[];
803
715
  warnings?: string[];
804
716
  };
717
+ /** The value a `{path}` placeholder reads from state, in interpolation's lookup order: the path as written, else, for a
718
+ * `state.` path, the path after `state.` (so `{state.x}` reads a real `state` key first). undefined when neither
719
+ * resolves. Every placeholder the engine fills reads through it; a static check of what a step reads can too. */
720
+ export declare function placeholderValue(state: Record<string, unknown>, path: string): unknown;
721
+ /** The placeholders a state value's string holds, as interpolateValue fills them: a whole string is one, marked optional
722
+ * (`"{draft?}"`) or not; inside a longer string only unmarked ones are. For a host check of what a step reads. */
723
+ export declare function placeholdersOf(text: string): {
724
+ path: string;
725
+ optional: boolean;
726
+ }[];
805
727
  export declare class EscalationSignal extends Error {
806
728
  readonly escalation: Escalation;
807
729
  constructor(escalation: Escalation);
@@ -906,21 +828,6 @@ export declare class WorkflowDecisionRecordError extends Error {
906
828
  }
907
829
  /** The reserved state key host policy writes under. Engine-owned like every `$`-prefixed key: no node may name it. */
908
830
  export declare const HOST_STATE_KEY = "$host";
909
- /** A node's step guard, as the document holds it (validateWorkflow refused any other shape). */
910
- export declare function stepGuardOf(node: WorkflowNode): StepGuard | undefined;
911
- /** The field an agent or decide node whose guard reads `self` submits its confidence in, beside its record. */
912
- export declare const SELF_CONFIDENCE_FIELD = "confidence";
913
- /** The engine-owned state key an agent or decide node's own confidence lands under, beside its value: `<key>$confidence`. */
914
- export declare const confidenceKey: (key: string) => string;
915
- /** The escalate nodes of a workflow document that read a judge's output, by label as a run names its step (a child's
916
- * `parent/child`, as WorkflowDeps.softEscalate is asked): each whose `when` (under any number of `not`s) reads a field a
917
- * judge node wrote (an `ask` predicate: every key its `state` reads, and it reads at least one), the judge being the step that last wrote that path's head on every path a run can take to the
918
- * escalate (a judge an extract overwrites, one in only some of a route's branches, one a code node with no `as` may have
919
- * overwritten, are not). A judge's field is one model's opinion of a draft the workflow already wrote, so a host that
920
- * measures the check may record it instead of obeying it (WorkflowDeps.softEscalate) and read the draft past it. A
921
- * document too deep to walk, or whose loop's writes do not settle, has none. The document is read as it is: no
922
- * validation, and a malformed node writes nothing it cannot name. */
923
- export declare function softEscalates(doc: unknown): Set<string>;
924
831
  export declare class WorkflowVerificationError extends Error {
925
832
  readonly stage: string;
926
833
  readonly candidate: unknown;