@parcha/agentrun-dsl 0.1.0-beta.2 → 0.1.0-beta.200
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/NOTICE +2 -0
- package/README.md +172 -22
- package/dist/author-references.d.ts +8 -0
- package/dist/author-references.js +8 -0
- package/dist/author.d.ts +97 -0
- package/dist/author.js +329 -0
- package/dist/authoring.js +5 -4
- package/dist/cli.js +19 -13
- package/dist/code-exec.d.ts +25 -0
- package/dist/code-exec.js +180 -5
- package/dist/decision-provider.d.ts +166 -0
- package/dist/decision-provider.js +238 -0
- package/dist/decision-receipts.d.ts +159 -0
- package/dist/decision-receipts.js +93 -0
- package/dist/dry-run.d.ts +45 -2
- package/dist/dry-run.js +159 -27
- package/dist/edit.d.ts +149 -0
- package/dist/edit.js +1415 -0
- package/dist/evidence.d.ts +19 -0
- package/dist/evidence.js +63 -0
- package/dist/graph.d.ts +169 -0
- package/dist/graph.js +433 -0
- package/dist/index.d.ts +20 -7
- package/dist/index.js +17 -7
- package/dist/inspection.d.ts +5 -0
- package/dist/inspection.js +16 -3
- package/dist/job.d.ts +14 -0
- package/dist/job.js +5 -0
- 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/pattern-screen.d.ts +14 -0
- package/dist/pattern-screen.js +451 -0
- package/dist/predicates.d.ts +33 -0
- package/dist/predicates.js +81 -5
- package/dist/record.d.ts +4 -0
- package/dist/record.js +6 -0
- package/dist/recovery/binding.d.ts +10 -0
- package/dist/recovery/binding.js +44 -0
- package/dist/recovery/call-key.d.ts +9 -0
- package/dist/recovery/call-key.js +17 -0
- package/dist/recovery/canonical-hash.d.ts +7 -0
- package/dist/recovery/canonical-hash.js +22 -0
- package/dist/recovery/driver.d.ts +245 -0
- package/dist/recovery/driver.js +1347 -0
- package/dist/recovery/errors.d.ts +31 -0
- package/dist/recovery/errors.js +51 -0
- package/dist/recovery/execution-path.d.ts +53 -0
- package/dist/recovery/execution-path.js +167 -0
- package/dist/recovery/file-store.d.ts +7 -0
- package/dist/recovery/file-store.js +131 -0
- package/dist/recovery/frozen-snapshot.d.ts +274 -0
- package/dist/recovery/frozen-snapshot.js +187 -0
- package/dist/recovery/handoff-receipts.d.ts +7 -0
- package/dist/recovery/handoff-receipts.js +11 -0
- package/dist/recovery/index.d.ts +14 -0
- package/dist/recovery/index.js +13 -0
- package/dist/recovery/item-state.d.ts +48 -0
- package/dist/recovery/item-state.js +89 -0
- package/dist/recovery/journal.d.ts +28 -0
- package/dist/recovery/journal.js +139 -0
- package/dist/recovery/memory-store.d.ts +4 -0
- package/dist/recovery/memory-store.js +20 -0
- package/dist/recovery/store.d.ts +105 -0
- package/dist/recovery/store.js +6 -0
- package/dist/recovery/testing/conformance.d.ts +4 -0
- package/dist/recovery/testing/conformance.js +268 -0
- package/dist/recovery/testing/crash-points.d.ts +18 -0
- package/dist/recovery/testing/crash-points.js +43 -0
- package/dist/recovery/testing/crash-sweep.d.ts +65 -0
- package/dist/recovery/testing/crash-sweep.js +146 -0
- package/dist/recovery/testing/index.d.ts +3 -0
- package/dist/recovery/testing/index.js +4 -0
- package/dist/recovery/testing/preload.d.ts +1 -0
- package/dist/recovery/testing/preload.js +3 -0
- package/dist/recovery/transport-facts.d.ts +23 -0
- package/dist/recovery/transport-facts.js +46 -0
- package/dist/recovery/with-recovery.d.ts +50 -0
- package/dist/recovery/with-recovery.js +144 -0
- package/dist/submit-envelope.d.ts +9 -0
- package/dist/submit-envelope.js +44 -0
- package/dist/system-one.d.ts +37 -2
- package/dist/system-one.js +146 -11
- package/dist/testing/decision-provider.d.ts +32 -0
- package/dist/testing/decision-provider.js +183 -0
- package/dist/testing/index.d.ts +1 -0
- package/dist/testing/index.js +2 -0
- package/dist/vocabulary.d.ts +50 -0
- package/dist/vocabulary.js +84 -0
- package/dist/workflow-shape.d.ts +7 -0
- package/dist/workflow-shape.js +119 -69
- package/dist/workflow.d.ts +309 -29
- package/dist/workflow.js +1664 -487
- package/dist/zod-json-contract.js +6 -8
- package/package.json +33 -5
- package/schema/workflow.schema.json +599 -12
- package/skills/author/SKILL.md +125 -0
- package/skills/author/examples/evidence-gate.input.json +6 -0
- package/skills/author/examples/evidence-gate.json +125 -0
- package/skills/author/examples/read-file.input.json +1 -0
- package/skills/author/examples/read-file.json +44 -0
- package/skills/author/examples/read-source-decision.input.json +4 -0
- package/skills/author/examples/read-source-decision.json +37 -0
- package/skills/author/examples/release-note.txt +10 -0
- package/skills/author/examples/review-release-notes.input.json +6 -0
- package/skills/author/examples/review-release-notes.json +123 -0
- package/skills/author/references/jev-decisions.md +170 -0
- package/skills/author/references/language.md +123 -0
- package/skills/author/references/sdk-authoring.md +11 -0
- package/skills/author/references/workflow-format.md +137 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { DecisionEvidence } from "./decision-provider.js";
|
|
2
|
+
/** The longest title an item keeps, in code points. */
|
|
3
|
+
export declare const EVIDENCE_TITLE_MAX = 300;
|
|
4
|
+
/** The longest passage an item keeps, in code points. */
|
|
5
|
+
export declare const EVIDENCE_EXCERPT_MAX = 4096;
|
|
6
|
+
/** The most passages one item keeps. */
|
|
7
|
+
export declare const EVIDENCE_EXCERPTS_PER_ITEM = 5;
|
|
8
|
+
/** The most items a decision's evidence keeps. */
|
|
9
|
+
export declare const EVIDENCE_ITEMS_MAX = 20;
|
|
10
|
+
/** The most code points of titles and passages a decision's evidence keeps, all items together. */
|
|
11
|
+
export declare const EVIDENCE_TEXT_MAX: number;
|
|
12
|
+
/** What a caller keeps of each citation: `excerpts: false` keeps none of its passages. */
|
|
13
|
+
export type EvidenceOptions = {
|
|
14
|
+
excerpts?: boolean;
|
|
15
|
+
};
|
|
16
|
+
/** Raw citations as a decision's evidence. Items in order, each kept or dropped by its URL, its text plain and cut, until
|
|
17
|
+
* the item count or the code-point budget is reached. With `excerpts: false` no item keeps a passage. Idempotent: clean
|
|
18
|
+
* evidence comes back as it went in. */
|
|
19
|
+
export declare function evidenceOf(raw: unknown, { excerpts: withExcerpts }?: EvidenceOptions): DecisionEvidence[];
|
package/dist/evidence.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { isRecord } from "./record.js";
|
|
2
|
+
/** The longest title an item keeps, in code points. */
|
|
3
|
+
export const EVIDENCE_TITLE_MAX = 300;
|
|
4
|
+
/** The longest passage an item keeps, in code points. */
|
|
5
|
+
export const EVIDENCE_EXCERPT_MAX = 4096;
|
|
6
|
+
/** The most passages one item keeps. */
|
|
7
|
+
export const EVIDENCE_EXCERPTS_PER_ITEM = 5;
|
|
8
|
+
/** The most items a decision's evidence keeps. */
|
|
9
|
+
export const EVIDENCE_ITEMS_MAX = 20;
|
|
10
|
+
/** The most code points of titles and passages a decision's evidence keeps, all items together. */
|
|
11
|
+
export const EVIDENCE_TEXT_MAX = 32 * 1024;
|
|
12
|
+
/** The longest `scope` an item keeps, in code points. */
|
|
13
|
+
const SCOPE_MAX = 64;
|
|
14
|
+
// C0 controls but tab, newline and return; DEL and the C1 controls; the Unicode direction marks, overrides and isolates.
|
|
15
|
+
const CONTROL = /[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f-\u009f--]/g;
|
|
16
|
+
const codePoints = (text) => Array.from(text).length;
|
|
17
|
+
/** `text` with its control characters gone, cut to `max` code points (an ellipsis marking a cut). */
|
|
18
|
+
function plain(text, max) {
|
|
19
|
+
const clean = text.replace(CONTROL, "");
|
|
20
|
+
const chars = Array.from(clean);
|
|
21
|
+
return chars.length <= max ? clean : `${chars.slice(0, Math.max(0, max - 1)).join("")}…`;
|
|
22
|
+
}
|
|
23
|
+
/** The URL as the parser normalizes it, if it is http(s) with no user or password; else undefined, and its item is dropped. */
|
|
24
|
+
function webUrl(url) {
|
|
25
|
+
if (typeof url !== "string")
|
|
26
|
+
return undefined;
|
|
27
|
+
const parsed = URL.parse(url);
|
|
28
|
+
if (!parsed || (parsed.protocol !== "http:" && parsed.protocol !== "https:") || parsed.username || parsed.password)
|
|
29
|
+
return undefined;
|
|
30
|
+
return parsed.href;
|
|
31
|
+
}
|
|
32
|
+
/** Raw citations as a decision's evidence. Items in order, each kept or dropped by its URL, its text plain and cut, until
|
|
33
|
+
* the item count or the code-point budget is reached. With `excerpts: false` no item keeps a passage. Idempotent: clean
|
|
34
|
+
* evidence comes back as it went in. */
|
|
35
|
+
export function evidenceOf(raw, { excerpts: withExcerpts = true } = {}) {
|
|
36
|
+
const kept = [];
|
|
37
|
+
let left = EVIDENCE_TEXT_MAX;
|
|
38
|
+
for (const item of Array.isArray(raw) ? raw : []) {
|
|
39
|
+
if (kept.length >= EVIDENCE_ITEMS_MAX || left <= 0)
|
|
40
|
+
break;
|
|
41
|
+
if (!isRecord(item))
|
|
42
|
+
continue;
|
|
43
|
+
const { url: rawUrl, title: rawTitle, excerpts: rawExcerpts, scope: rawScope } = item;
|
|
44
|
+
const url = webUrl(rawUrl);
|
|
45
|
+
if (!url)
|
|
46
|
+
continue;
|
|
47
|
+
const title = typeof rawTitle === "string" ? plain(rawTitle, Math.min(EVIDENCE_TITLE_MAX, left)) : null;
|
|
48
|
+
left -= title === null ? 0 : codePoints(title);
|
|
49
|
+
const excerpts = [];
|
|
50
|
+
for (const excerpt of withExcerpts && Array.isArray(rawExcerpts) ? rawExcerpts : []) {
|
|
51
|
+
if (excerpts.length >= EVIDENCE_EXCERPTS_PER_ITEM || left <= 0)
|
|
52
|
+
break;
|
|
53
|
+
if (typeof excerpt !== "string")
|
|
54
|
+
continue;
|
|
55
|
+
const text = plain(excerpt, Math.min(EVIDENCE_EXCERPT_MAX, left));
|
|
56
|
+
excerpts.push(text);
|
|
57
|
+
left -= codePoints(text);
|
|
58
|
+
}
|
|
59
|
+
const scope = typeof rawScope === "string" && rawScope ? plain(rawScope, SCOPE_MAX) : "call";
|
|
60
|
+
kept.push({ url, title, excerpts, scope });
|
|
61
|
+
}
|
|
62
|
+
return kept;
|
|
63
|
+
}
|
package/dist/graph.d.ts
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/** One node of the workflow as written. `path` is a JSON Pointer (RFC 6901) into the document: `/root` is the root,
|
|
2
|
+
* `/root/steps/1` a chain's second step, `/root/branches/<name>/body` a route's branch, `/root/body` a map's or a
|
|
3
|
+
* loop's body, `/root/workflow/root` a child workflow's root: the pointers `inspectWorkflow` and a validation issue
|
|
4
|
+
* use for the same node. `label` is the node's label, or its kind when it has none. `via` is a `call` node's transport.
|
|
5
|
+
* `changeCheck` detects a change to the node's own fields from one graph to another: 8 hex digits, the FNV-1a hash of
|
|
6
|
+
* the canonical JSON (keys sorted) of the node with its children left out as the walk leaves them out (a chain's steps,
|
|
7
|
+
* a parallel's branches, a map's or a loop's body, each route branch's body, a child workflow's root). A route's branch
|
|
8
|
+
* names are its own fields, since they decide which branch runs, so a route that gains or loses a branch is rewritten. It
|
|
9
|
+
* is not an identity and not a saved revision's sha256: two nodes with the same check are not the same node, and a check
|
|
10
|
+
* that stayed only means no change was seen. A graph built by hand may leave it out. */
|
|
11
|
+
export type GraphNode = {
|
|
12
|
+
path: string;
|
|
13
|
+
kind: string;
|
|
14
|
+
label: string;
|
|
15
|
+
via?: string;
|
|
16
|
+
changeCheck?: string;
|
|
17
|
+
} & GraphDecision;
|
|
18
|
+
/** One typed question a decision node asks, as a viewer shows it: its id, its type (`unknown` when its schema is not a
|
|
19
|
+
* question the reader recognizes), its instructions, and a choice's options. */
|
|
20
|
+
export type GraphQuestion = {
|
|
21
|
+
id: string;
|
|
22
|
+
type: "noul" | "choice" | "score" | "unknown";
|
|
23
|
+
instructions: string;
|
|
24
|
+
options?: string[];
|
|
25
|
+
};
|
|
26
|
+
/** What a decision node (judge, pick, sift, a judged route, or a loop or escalate whose predicate is `ask`) says about
|
|
27
|
+
* its decision, read from the document: the provider and model it names (absent when it names none), its questions, and
|
|
28
|
+
* the tokens of the images it sends. A graph of another node carries none of these. */
|
|
29
|
+
export type GraphDecision = {
|
|
30
|
+
provider?: string;
|
|
31
|
+
model?: string;
|
|
32
|
+
questions?: GraphQuestion[];
|
|
33
|
+
images?: string[];
|
|
34
|
+
};
|
|
35
|
+
/** How control reaches `to` from `from`.
|
|
36
|
+
* - `next`: a chain enters its first step and each step is followed by the next; a loop enters its body, which runs again
|
|
37
|
+
* until the loop ends.
|
|
38
|
+
* - `branch`: a parallel node starts each of its branches.
|
|
39
|
+
* - `route`: a route node takes one of its branches (the branch's name is the last pointer segment before `/body`).
|
|
40
|
+
* - `item`: a map runs its body once for each item.
|
|
41
|
+
* - `child`: a workflow node runs the child workflow's root. */
|
|
42
|
+
export type GraphEdgeKind = "next" | "branch" | "route" | "item" | "child";
|
|
43
|
+
export type GraphEdge = {
|
|
44
|
+
from: string;
|
|
45
|
+
to: string;
|
|
46
|
+
kind: GraphEdgeKind;
|
|
47
|
+
};
|
|
48
|
+
export type WorkflowGraph = {
|
|
49
|
+
nodes: GraphNode[];
|
|
50
|
+
edges: GraphEdge[];
|
|
51
|
+
};
|
|
52
|
+
/** The graph of `workflow`, computed from its JSON alone: nodes in document order (a node, then its descendants), and the
|
|
53
|
+
* edges between them. A value that is not a workflow, or a node the walk does not know, adds nothing and never throws:
|
|
54
|
+
* validation is `validateWorkflow`'s. */
|
|
55
|
+
export declare function workflowGraph(workflow: unknown): WorkflowGraph;
|
|
56
|
+
/** What a run has done at a node. A node inside a map's or a loop's body stands for every item or iteration, and the record names
|
|
57
|
+
* only those that started, so it is `done` only once the map or loop is: until then it is `working`, and a done node never
|
|
58
|
+
* goes back. A container (chain, parallel, map, loop, route, workflow) is `working` while some of
|
|
59
|
+
* its descendants are, or some are done and it is not; a node a run never reached, a branch a route did not take among
|
|
60
|
+
* them, is `not-run`. `escalated` is where the run ended on an escalation: the escalate node that fired and each container
|
|
61
|
+
* on its path. It is read from the run's terminal result, never from the frame, which holds no mark for that node. */
|
|
62
|
+
export type NodeState = "done" | "working" | "failed" | "not-run" | "escalated";
|
|
63
|
+
type Frame = {
|
|
64
|
+
done?: unknown;
|
|
65
|
+
steps?: unknown;
|
|
66
|
+
inputs?: unknown;
|
|
67
|
+
partial?: unknown;
|
|
68
|
+
};
|
|
69
|
+
/** The part of an `agentrun.items` value the status reads: the map item's `status` and its frame. */
|
|
70
|
+
export type ItemRecordLike = {
|
|
71
|
+
map?: unknown;
|
|
72
|
+
index?: unknown;
|
|
73
|
+
status?: unknown;
|
|
74
|
+
frame?: Frame;
|
|
75
|
+
};
|
|
76
|
+
/** The part of a run's terminal result the status reads: its `status` and, for an escalation, the execution path of the
|
|
77
|
+
* node it stopped at (`escalation.executionPath`, as `runWorkflow` returns it). */
|
|
78
|
+
export type TerminalResultLike = {
|
|
79
|
+
status?: unknown;
|
|
80
|
+
escalation?: {
|
|
81
|
+
executionPath?: unknown;
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
/** What `nodeStatus` reads: a driver frame (the `pin` of a frozen snapshot: `done`, `steps`, `inputs`), a frozen snapshot
|
|
85
|
+
* (its `pin`), or the map items' records, alone or together with the driver's record (`{ pin, items }`), and with it the
|
|
86
|
+
* run's terminal `result` once the run has ended. */
|
|
87
|
+
export type StatusSource = Frame | {
|
|
88
|
+
pin: Frame;
|
|
89
|
+
items?: readonly ItemRecordLike[];
|
|
90
|
+
result?: TerminalResultLike | null;
|
|
91
|
+
} | readonly ItemRecordLike[];
|
|
92
|
+
/** `item`: the source is one map item's (or loop iteration's) record, read on its own, and this is its execution path
|
|
93
|
+
* (`<map path>/items/<index>`, `<loop path>/iterations/<index>`). That item is then the instance, not one of many: its body is done
|
|
94
|
+
* when the item is, whether or not the map is. A map or loop inside the item still stands for all of its own items. */
|
|
95
|
+
export type StatusOptions = {
|
|
96
|
+
item?: string;
|
|
97
|
+
};
|
|
98
|
+
/** For every node of `graph`, the state the record shows. `source` is what the driver kept: its frame and, in the keyed
|
|
99
|
+
* layout, the records of the map items (a run's whole story is the frame and the items together). A source that is not
|
|
100
|
+
* one of those shows no node run. With the run's terminal `result`, an escalation that names a node of the graph marks
|
|
101
|
+
* that node and every container on its path `escalated`, and the maps and loops on that path have ended, so what finished
|
|
102
|
+
* inside them is done; without one, or when it names no node of the graph, nothing else changes. */
|
|
103
|
+
export declare function nodeStatus(graph: WorkflowGraph, source: StatusSource, options?: StatusOptions): Record<string, NodeState>;
|
|
104
|
+
/** Where an execution path is in the graph: the node it ran at (`path`, a node of the graph) and the map items and loop
|
|
105
|
+
* iterations it ran in, outermost first. */
|
|
106
|
+
export type GraphNodeAt = {
|
|
107
|
+
path: string;
|
|
108
|
+
at: {
|
|
109
|
+
kind: "item" | "iteration";
|
|
110
|
+
index: number;
|
|
111
|
+
}[];
|
|
112
|
+
};
|
|
113
|
+
/** The graph node an execution path ran at. An execution path is the node's JSON Pointer with two runtime segments added:
|
|
114
|
+
* a map's item (`items/<i>` before the map's `body`) and a loop's iteration (`iterations/<i>` before the loop's `body`); the
|
|
115
|
+
* graph has `/body` for both, and the indexes are returned in `at`. The path is read by walking the graph from `/root`, by
|
|
116
|
+
* each node's kind, never by matching its text, so a route branch named `items` or `iterations` is a branch. Undefined for
|
|
117
|
+
* a path the graph does not have, or one that is not an execution path (a map's `body` without an item, an item without
|
|
118
|
+
* its `body`). */
|
|
119
|
+
export declare function graphNodeOf(graph: WorkflowGraph, executionPath: string): GraphNodeAt | undefined;
|
|
120
|
+
/** A node as `graphDiff` reports it: its path in the graph it is in, its kind and its label. */
|
|
121
|
+
export type GraphDiffNode = {
|
|
122
|
+
path: string;
|
|
123
|
+
kind: string;
|
|
124
|
+
label: string;
|
|
125
|
+
};
|
|
126
|
+
/** What changed from one graph to the next. `added` holds nodes of `next` only (paths in `next`), `removed` nodes of `prev`
|
|
127
|
+
* only (paths in `prev`); `changed` the same node at the same path with a new kind or label; `moved` the same node at a
|
|
128
|
+
* new path; `rewritten` the same node, its kind and label as they were, with other own fields changed (its `changeCheck`
|
|
129
|
+
* differs: new instructions, a new budget), at its path in each graph; `edges.added` edges of `next` only and
|
|
130
|
+
* `edges.removed` edges of `prev` only, each in its own graph's paths. */
|
|
131
|
+
export type GraphDiff = {
|
|
132
|
+
added: GraphDiffNode[];
|
|
133
|
+
removed: GraphDiffNode[];
|
|
134
|
+
changed: {
|
|
135
|
+
prev: string;
|
|
136
|
+
next: string;
|
|
137
|
+
was: {
|
|
138
|
+
kind: string;
|
|
139
|
+
label: string;
|
|
140
|
+
};
|
|
141
|
+
now: {
|
|
142
|
+
kind: string;
|
|
143
|
+
label: string;
|
|
144
|
+
};
|
|
145
|
+
}[];
|
|
146
|
+
moved: {
|
|
147
|
+
prev: string;
|
|
148
|
+
next: string;
|
|
149
|
+
}[];
|
|
150
|
+
rewritten: {
|
|
151
|
+
prev: string;
|
|
152
|
+
next: string;
|
|
153
|
+
kind: string;
|
|
154
|
+
label: string;
|
|
155
|
+
}[];
|
|
156
|
+
edges: {
|
|
157
|
+
added: GraphEdge[];
|
|
158
|
+
removed: GraphEdge[];
|
|
159
|
+
};
|
|
160
|
+
};
|
|
161
|
+
/** What changed between two graphs of a workflow, such as two saved revisions of one. A node is the same in both when its
|
|
162
|
+
* `(kind, label)` is unique in each graph, wherever it is: a step inserted before others is one `added` node and the rest
|
|
163
|
+
* `moved`, never a run of changes. A node whose `(kind, label)` repeats in either graph, or is in one only, is the same
|
|
164
|
+
* as the other graph's node at its path, unless that node is already matched by its identity; with a new kind or label
|
|
165
|
+
* it is `changed`. A matched node with its kind and label as they were and another `changeCheck` is `rewritten`; a node
|
|
166
|
+
* without a check in either graph is never reported rewritten. An edge is the same when both its ends are the same nodes
|
|
167
|
+
* and its kind is the same. Every list is in its graph's node or edge order. */
|
|
168
|
+
export declare function graphDiff(prev: WorkflowGraph, next: WorkflowGraph): GraphDiff;
|
|
169
|
+
export {};
|