@nifrajs/agent-protocol 3.2.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/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # @nifrajs/agent-protocol
2
+
3
+ Small, backend-neutral contracts for local coding-agent sessions.
4
+
5
+ The package contains versioned session snapshots, streamed assistant/tool/approval
6
+ events, bounded live event streams, and backend interfaces. It has no runtime
7
+ dependencies and does not import Nifra framework packages, model SDKs, or UI code.
8
+
9
+ ```ts
10
+ import { createAgentEventStream } from "@nifrajs/agent-protocol"
11
+
12
+ const events = createAgentEventStream(256)
13
+ events.push(/* a versioned AgentEvent */)
14
+ ```
15
+
16
+ Use `@nifrajs/pi` for the Pi backend or implement `AgentBackend` for another
17
+ runtime. The protocol is intentionally small so CLI, desktop, mobile, and CI
18
+ clients can share it without pulling in the Nifra application framework.
19
+
20
+ ## Version 1 compatibility
21
+
22
+ Version 1 is additive. Hosts advertise capabilities and clients use only the negotiated intersection;
23
+ an unsupported command is a stable `feature_unsupported` result. Optional fields are ignored by older
24
+ peers, while a cursor gap returns `resync_required` instead of silently skipping evidence. A future
25
+ major requires a recorded semantic incompatibility, dual decoders, cross-version fixtures, and an
26
+ approved migration plan.
27
+
28
+ Run evidence and lifecycle values are structural only: identifiers, statuses, counters, timestamps,
29
+ digests, and opaque references. Prompts, model output, tool arguments, and filesystem paths do not
30
+ belong in these public contracts.
31
+
32
+ For AI agents, see [`LLM.md`](./LLM.md) and the full corpus
33
+ [`../../llms-full.txt`](../../llms-full.txt).
@@ -0,0 +1,221 @@
1
+ /**
2
+ * Backend-neutral protocol for local coding-agent hosts.
3
+ *
4
+ * This package deliberately has no runtime dependencies. A Pi adapter, a Nifra-native backend,
5
+ * the CLI, and the Workbench can all implement or consume these contracts without pulling any
6
+ * framework, model provider, or UI code into an application.
7
+ */
8
+ export declare const AGENT_PROTOCOL_VERSION: 1;
9
+ export type AgentSessionStatus = "idle" | "running" | "waiting" | "completed" | "failed" | "stopped";
10
+ export type AgentEventType = "session.started" | "session.updated" | "turn.started" | "assistant.delta" | "assistant.message" | "tool.started" | "tool.delta" | "tool.completed" | "approval.required" | "approval.resolved" | "repair.required" | "verification.completed" | "memory.compacted" | "extension.reloaded" | "session.completed" | "session.failed" | "session.stopped";
11
+ export interface AgentSessionSnapshot {
12
+ readonly version: typeof AGENT_PROTOCOL_VERSION;
13
+ readonly id: string;
14
+ readonly backend: string;
15
+ readonly cwd: string;
16
+ readonly status: AgentSessionStatus;
17
+ readonly createdAt: number;
18
+ readonly updatedAt: number;
19
+ readonly lastSeq: number;
20
+ readonly activeTurnId?: string;
21
+ readonly extensionRevision?: string;
22
+ readonly capabilities: readonly string[];
23
+ }
24
+ export interface AgentBackendInfo {
25
+ readonly name: string;
26
+ readonly version?: string;
27
+ readonly capabilities: readonly string[];
28
+ }
29
+ export interface AgentSessionEventBase {
30
+ readonly version: typeof AGENT_PROTOCOL_VERSION;
31
+ readonly sessionId: string;
32
+ readonly seq: number;
33
+ readonly at: number;
34
+ readonly type: AgentEventType;
35
+ }
36
+ export interface AgentSessionStartedEvent extends AgentSessionEventBase {
37
+ readonly type: "session.started";
38
+ readonly snapshot: AgentSessionSnapshot;
39
+ }
40
+ export interface AgentSessionUpdatedEvent extends AgentSessionEventBase {
41
+ readonly type: "session.updated";
42
+ readonly snapshot: AgentSessionSnapshot;
43
+ }
44
+ export interface AgentTurnStartedEvent extends AgentSessionEventBase {
45
+ readonly type: "turn.started";
46
+ readonly turnId: string;
47
+ readonly prompt: string;
48
+ }
49
+ export interface AgentAssistantDeltaEvent extends AgentSessionEventBase {
50
+ readonly type: "assistant.delta";
51
+ readonly turnId: string;
52
+ readonly text: string;
53
+ }
54
+ export interface AgentAssistantMessageEvent extends AgentSessionEventBase {
55
+ readonly type: "assistant.message";
56
+ readonly turnId: string;
57
+ readonly text: string;
58
+ }
59
+ export interface AgentToolStartedEvent extends AgentSessionEventBase {
60
+ readonly type: "tool.started";
61
+ readonly turnId: string;
62
+ readonly callId: string;
63
+ readonly name: string;
64
+ readonly input?: unknown;
65
+ }
66
+ export interface AgentToolDeltaEvent extends AgentSessionEventBase {
67
+ readonly type: "tool.delta";
68
+ readonly turnId: string;
69
+ readonly callId: string;
70
+ readonly text: string;
71
+ }
72
+ export interface AgentToolCompletedEvent extends AgentSessionEventBase {
73
+ readonly type: "tool.completed";
74
+ readonly turnId: string;
75
+ readonly callId: string;
76
+ readonly name: string;
77
+ readonly ok: boolean;
78
+ readonly output?: unknown;
79
+ readonly error?: AgentError;
80
+ }
81
+ export interface AgentApprovalRequiredEvent extends AgentSessionEventBase {
82
+ readonly type: "approval.required";
83
+ readonly turnId: string;
84
+ readonly approvalId: string;
85
+ readonly action: string;
86
+ readonly capability: string;
87
+ readonly reason?: string;
88
+ }
89
+ export interface AgentApprovalResolvedEvent extends AgentSessionEventBase {
90
+ readonly type: "approval.resolved";
91
+ readonly turnId?: string;
92
+ readonly approvalId: string;
93
+ readonly approved: boolean;
94
+ readonly reason?: string;
95
+ }
96
+ export interface AgentRepairTask {
97
+ readonly id: string;
98
+ readonly verification: "check" | "assure" | "test";
99
+ readonly cwd: string;
100
+ readonly reason: string;
101
+ readonly capabilities: readonly string[];
102
+ readonly output?: string;
103
+ readonly report?: unknown;
104
+ }
105
+ export interface AgentRepairRequiredEvent extends AgentSessionEventBase {
106
+ readonly type: "repair.required";
107
+ readonly turnId?: string;
108
+ readonly task: AgentRepairTask;
109
+ }
110
+ export interface AgentVerificationCompletedEvent extends AgentSessionEventBase {
111
+ readonly type: "verification.completed";
112
+ readonly name: string;
113
+ readonly ok: boolean;
114
+ readonly report?: unknown;
115
+ }
116
+ export interface AgentMemoryCompactedEvent extends AgentSessionEventBase {
117
+ readonly type: "memory.compacted";
118
+ readonly before: number;
119
+ readonly after: number;
120
+ readonly reason: "manual" | "threshold" | "overflow" | "workflow";
121
+ }
122
+ export interface AgentExtensionReloadedEvent extends AgentSessionEventBase {
123
+ readonly type: "extension.reloaded";
124
+ readonly revision: string;
125
+ readonly loaded: readonly string[];
126
+ readonly disabled: readonly string[];
127
+ readonly rolledBack: boolean;
128
+ }
129
+ export interface AgentSessionCompletedEvent extends AgentSessionEventBase {
130
+ readonly type: "session.completed";
131
+ readonly snapshot: AgentSessionSnapshot;
132
+ }
133
+ export interface AgentSessionFailedEvent extends AgentSessionEventBase {
134
+ readonly type: "session.failed";
135
+ readonly error: AgentError;
136
+ readonly recoverable: boolean;
137
+ }
138
+ export interface AgentSessionStoppedEvent extends AgentSessionEventBase {
139
+ readonly type: "session.stopped";
140
+ readonly reason?: string;
141
+ }
142
+ export type AgentEvent = AgentSessionStartedEvent | AgentSessionUpdatedEvent | AgentTurnStartedEvent | AgentAssistantDeltaEvent | AgentAssistantMessageEvent | AgentToolStartedEvent | AgentToolDeltaEvent | AgentToolCompletedEvent | AgentApprovalRequiredEvent | AgentApprovalResolvedEvent | AgentRepairRequiredEvent | AgentVerificationCompletedEvent | AgentMemoryCompactedEvent | AgentExtensionReloadedEvent | AgentSessionCompletedEvent | AgentSessionFailedEvent | AgentSessionStoppedEvent;
143
+ /** Event payload before the transport adds protocol version, session id, sequence, and timestamp. */
144
+ export type AgentEventPayload = Omit<AgentSessionStartedEvent, "version" | "sessionId" | "seq" | "at"> | Omit<AgentSessionUpdatedEvent, "version" | "sessionId" | "seq" | "at"> | Omit<AgentTurnStartedEvent, "version" | "sessionId" | "seq" | "at"> | Omit<AgentAssistantDeltaEvent, "version" | "sessionId" | "seq" | "at"> | Omit<AgentAssistantMessageEvent, "version" | "sessionId" | "seq" | "at"> | Omit<AgentToolStartedEvent, "version" | "sessionId" | "seq" | "at"> | Omit<AgentToolDeltaEvent, "version" | "sessionId" | "seq" | "at"> | Omit<AgentToolCompletedEvent, "version" | "sessionId" | "seq" | "at"> | Omit<AgentApprovalRequiredEvent, "version" | "sessionId" | "seq" | "at"> | Omit<AgentApprovalResolvedEvent, "version" | "sessionId" | "seq" | "at"> | Omit<AgentRepairRequiredEvent, "version" | "sessionId" | "seq" | "at"> | Omit<AgentVerificationCompletedEvent, "version" | "sessionId" | "seq" | "at"> | Omit<AgentMemoryCompactedEvent, "version" | "sessionId" | "seq" | "at"> | Omit<AgentExtensionReloadedEvent, "version" | "sessionId" | "seq" | "at"> | Omit<AgentSessionCompletedEvent, "version" | "sessionId" | "seq" | "at"> | Omit<AgentSessionFailedEvent, "version" | "sessionId" | "seq" | "at"> | Omit<AgentSessionStoppedEvent, "version" | "sessionId" | "seq" | "at">;
145
+ export interface AgentError {
146
+ readonly code: string;
147
+ readonly message: string;
148
+ readonly details?: unknown;
149
+ }
150
+ export interface CreateSessionInput {
151
+ readonly cwd: string;
152
+ readonly backend?: string;
153
+ readonly capabilities?: readonly string[];
154
+ readonly sessionId?: string;
155
+ }
156
+ export interface SendMessageInput {
157
+ readonly sessionId: string;
158
+ readonly message: string;
159
+ readonly signal?: AbortSignal;
160
+ }
161
+ export interface ForkSessionInput {
162
+ readonly sessionId: string;
163
+ readonly targetSessionId?: string;
164
+ }
165
+ export interface ForkSessionResult {
166
+ readonly sessionId: string;
167
+ readonly parentSessionId: string;
168
+ }
169
+ export interface AgentSessionCheckpoint {
170
+ readonly version: 1;
171
+ readonly sessionId: string;
172
+ readonly at: number;
173
+ readonly payload?: unknown;
174
+ }
175
+ export interface ReloadResult {
176
+ readonly revision: string;
177
+ readonly loaded: readonly string[];
178
+ readonly disabled: readonly string[];
179
+ readonly rolledBack: boolean;
180
+ readonly error?: AgentError;
181
+ }
182
+ export interface AgentBackend {
183
+ readonly info: AgentBackendInfo;
184
+ createSession(input: CreateSessionInput): Promise<AgentSessionSnapshot>;
185
+ send(input: SendMessageInput): AsyncIterable<AgentEvent>;
186
+ cancel(sessionId: string, reason?: string): Promise<void>;
187
+ snapshot(sessionId: string): Promise<AgentSessionSnapshot>;
188
+ /** Backends may provide native branching; the host can fall back to its session store. */
189
+ fork?(input: ForkSessionInput): Promise<ForkSessionResult>;
190
+ checkpoint?(sessionId: string, payload?: unknown): Promise<AgentSessionCheckpoint>;
191
+ reload(sessionId: string): Promise<ReloadResult>;
192
+ /** Resolve an approval surfaced by a backend UI/tool, when that backend supports interactive approvals. */
193
+ resolveApproval?(sessionId: string, approvalId: string, approved: boolean, reason?: string): Promise<boolean | undefined>;
194
+ close(sessionId: string): Promise<void>;
195
+ }
196
+ export interface AgentEventSink {
197
+ push(event: AgentEvent): void;
198
+ complete(): void;
199
+ fail(error: unknown): void;
200
+ }
201
+ export interface AgentEventStream extends AgentEventSink, AsyncIterableIterator<AgentEvent> {
202
+ readonly dropped: number;
203
+ }
204
+ /**
205
+ * Small bounded event stream for RPC clients and UIs. The authoritative event history belongs to
206
+ * the backend/session store; this live view may drop old transient events if a consumer falls behind.
207
+ */
208
+ export declare function createAgentEventStream(maxQueueSize?: number): AgentEventStream;
209
+ export declare function agentError(code: string, message: string, details?: unknown): AgentError;
210
+ /**
211
+ * Orchestration value contracts (run plans, content-free evidence, artifact refs, effect keys).
212
+ * Additive to the session protocol; carries no behavior and no payload content.
213
+ */
214
+ export * from "./orchestration.js";
215
+ /**
216
+ * Additive run-lifecycle contracts (run snapshots, evidence-event envelopes, handoff snapshots,
217
+ * feature negotiation, cursor resume). Additive to the session protocol; carries no payload content.
218
+ */
219
+ export * from "./run-lifecycle.js";
220
+ export declare function isAgentEvent(value: unknown): value is AgentEvent;
221
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,eAAO,MAAM,sBAAsB,EAAG,CAAU,CAAA;AAEhD,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG,SAAS,GAAG,SAAS,GAAG,WAAW,GAAG,QAAQ,GAAG,SAAS,CAAA;AAEpG,MAAM,MAAM,cAAc,GACtB,iBAAiB,GACjB,iBAAiB,GACjB,cAAc,GACd,iBAAiB,GACjB,mBAAmB,GACnB,cAAc,GACd,YAAY,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 -0,0 +1,112 @@
1
+ /**
2
+ * Backend-neutral protocol for local coding-agent hosts.
3
+ *
4
+ * This package deliberately has no runtime dependencies. A Pi adapter, a Nifra-native backend,
5
+ * the CLI, and the Workbench can all implement or consume these contracts without pulling any
6
+ * framework, model provider, or UI code into an application.
7
+ */
8
+ export const AGENT_PROTOCOL_VERSION = 1;
9
+ /**
10
+ * Small bounded event stream for RPC clients and UIs. The authoritative event history belongs to
11
+ * the backend/session store; this live view may drop old transient events if a consumer falls behind.
12
+ */
13
+ export function createAgentEventStream(maxQueueSize = 256) {
14
+ if (!Number.isSafeInteger(maxQueueSize) || maxQueueSize < 1)
15
+ throw new RangeError("agent event stream: maxQueueSize must be a positive safe integer");
16
+ const queue = [];
17
+ const waiters = [];
18
+ let completed = false;
19
+ let failure;
20
+ let failed = false;
21
+ let dropped = 0;
22
+ const finish = () => {
23
+ if (!completed || queue.length > 0)
24
+ return;
25
+ while (waiters.length > 0) {
26
+ const waiter = waiters.shift();
27
+ if (failed)
28
+ waiter?.reject(failure);
29
+ else
30
+ waiter?.resolve({ done: true, value: undefined });
31
+ }
32
+ };
33
+ const stream = {
34
+ get dropped() {
35
+ return dropped;
36
+ },
37
+ push(event) {
38
+ if (completed)
39
+ return;
40
+ const waiter = waiters.shift();
41
+ if (waiter !== undefined) {
42
+ waiter.resolve({ done: false, value: event });
43
+ return;
44
+ }
45
+ if (queue.length >= maxQueueSize) {
46
+ queue.shift();
47
+ dropped += 1;
48
+ }
49
+ queue.push(event);
50
+ },
51
+ complete() {
52
+ completed = true;
53
+ finish();
54
+ },
55
+ fail(error) {
56
+ if (completed)
57
+ return;
58
+ failure = error;
59
+ failed = true;
60
+ completed = true;
61
+ finish();
62
+ },
63
+ next() {
64
+ const event = queue.shift();
65
+ if (event !== undefined)
66
+ return Promise.resolve({ done: false, value: event });
67
+ if (completed) {
68
+ if (failed)
69
+ return Promise.reject(failure);
70
+ return Promise.resolve({ done: true, value: undefined });
71
+ }
72
+ return new Promise((resolve, reject) => waiters.push({ resolve, reject }));
73
+ },
74
+ return() {
75
+ queue.length = 0;
76
+ completed = true;
77
+ finish();
78
+ return Promise.resolve({ done: true, value: undefined });
79
+ },
80
+ [Symbol.asyncIterator]() {
81
+ return this;
82
+ },
83
+ };
84
+ return stream;
85
+ }
86
+ export function agentError(code, message, details) {
87
+ return details === undefined ? { code, message } : { code, message, details };
88
+ }
89
+ /**
90
+ * Orchestration value contracts (run plans, content-free evidence, artifact refs, effect keys).
91
+ * Additive to the session protocol; carries no behavior and no payload content.
92
+ */
93
+ export * from "./orchestration.js";
94
+ /**
95
+ * Additive run-lifecycle contracts (run snapshots, evidence-event envelopes, handoff snapshots,
96
+ * feature negotiation, cursor resume). Additive to the session protocol; carries no payload content.
97
+ */
98
+ export * from "./run-lifecycle.js";
99
+ export function isAgentEvent(value) {
100
+ if (value === null || typeof value !== "object" || Array.isArray(value))
101
+ return false;
102
+ const record = value;
103
+ return (record.version === AGENT_PROTOCOL_VERSION &&
104
+ typeof record.sessionId === "string" &&
105
+ typeof record.seq === "number" &&
106
+ Number.isSafeInteger(record.seq) &&
107
+ typeof record.at === "number" &&
108
+ Number.isFinite(record.at) &&
109
+ typeof record.type === "string" &&
110
+ record.type.includes("."));
111
+ }
112
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAU,CAAA;AAgShD;;;GAGG;AACH,MAAM,UAAU,sBAAsB,CAAC,YAAY,GAAG,GAAG;IACvD,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,YAAY,CAAC,IAAI,YAAY,GAAG,CAAC;QACzD,MAAM,IAAI,UAAU,CAAC,kEAAkE,CAAC,CAAA;IAE1F,MAAM,KAAK,GAAiB,EAAE,CAAA;IAC9B,MAAM,OAAO,GAGR,EAAE,CAAA;IACP,IAAI,SAAS,GAAG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ACH,cAAc,oBAAoB,CAAA;AAElC;;;GAGG;AACH,cAAc,oBAAoB,CAAA;AAElC,MAAM,UAAU,YAAY,CAAC,KAAc;IACzC,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAA;IACrF,MAAM,MAAM,GAAG,KAAgC,CAAA;IAC/C,OAAO,CACL,MAAM,CAAC,OAAO,KAAK,sBAAsB;QACzC,OAAO,MAAM,CAAC,SAAS,KAAK,QAAQ;QACpC,OAAO,MAAM,CAAC,GAAG,KAAK,QAAQ;QAC9B,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,GAAG,CAAC;QAChC,OAAO,MAAM,CAAC,EAAE,KAAK,QAAQ;QAC7B,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QAC1B,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ;QAC/B,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAC1B,CAAA;AACH,CAAC"}
@@ -0,0 +1,150 @@
1
+ /**
2
+ * Orchestration value contracts: declarative run plans, content-free run evidence, artifact
3
+ * references, and the effect-key identity. Additive to the session protocol; carries no behavior,
4
+ * no runtime dependency, and - by construction - no payload content.
5
+ *
6
+ * The privacy invariant lives in the parsers here: {@link parseRunEvidence} and
7
+ * {@link parseArtifactRef} accept only the declared content-free keys and reject any record over
8
+ * {@link EVIDENCE_MAX_BYTES}. A prompt, model output, or tool payload cannot round-trip through
9
+ * these contracts. Raw payloads travel only through an {@link ArtifactPort} the caller owns.
10
+ */
11
+ /** Orchestration contract version. Additive to the session `AGENT_PROTOCOL_VERSION`. */
12
+ export declare const RUN_PLAN_VERSION: 1;
13
+ /** Hard cap on a single serialized evidence record. A content-free record never approaches this. */
14
+ export declare const EVIDENCE_MAX_BYTES = 4096;
15
+ /**
16
+ * Keys that would carry payload content. They are never valid on evidence or artifact records and
17
+ * are rejected by the strict parsers even if they would otherwise fit the size cap.
18
+ */
19
+ export declare const FORBIDDEN_CONTENT_KEYS: readonly string[];
20
+ /** A content-free pointer to a payload the caller chose to retain out of band. */
21
+ export interface ArtifactRef {
22
+ /** Caller-namespaced id. Opaque to nifra. */
23
+ readonly id: string;
24
+ /** SHA-256 hex of the payload, for integrity and correlation. Content-free. */
25
+ readonly digest: string;
26
+ readonly bytes: number;
27
+ readonly mediaType: string;
28
+ /** Optional caller-opaque locator (e.g. a private URI). nifra never dereferences it. */
29
+ readonly locator?: string;
30
+ }
31
+ /** What a payload is and where it came from, handed to the port at `put` time. */
32
+ export interface ArtifactContext {
33
+ readonly planDigest: string;
34
+ readonly nodeId: string;
35
+ /** e.g. "prompt" | "model_output" | "tool_input" | "tool_output". */
36
+ readonly kind: string;
37
+ }
38
+ /**
39
+ * Caller-owned sink for raw payloads - the ONLY place payload bytes leave transient execution.
40
+ * The public repo ships only a discarding no-op and a disposable in-memory test port. No public
41
+ * implementation persists.
42
+ */
43
+ export interface ArtifactPort {
44
+ put(payload: Uint8Array, ctx: ArtifactContext): ArtifactRef | Promise<ArtifactRef>;
45
+ }
46
+ /** The stable, content-free identity of one side-effecting node attempt-boundary. */
47
+ export interface NodeEffectKey {
48
+ /** SHA-256 hex over the canonical effect material. 64 lowercase hex chars. */
49
+ readonly digest: string;
50
+ /** Non-secret structural coordinates, safe to log. */
51
+ readonly planDigest: string;
52
+ readonly nodeId: string;
53
+ }
54
+ /** Leaf kinds resolve a StepCatalog handler; structural kinds compose child nodes. */
55
+ export type RunLeafKind = "task" | "verify" | "approve" | "checkpoint" | "handoff" | "subagent";
56
+ export type RunStructuralKind = "sequence" | "parallel" | "retry" | "branch";
57
+ /** Declarative node kinds. Each maps to an existing workflow primitive at compile time. */
58
+ export type RunNodeKind = RunLeafKind | RunStructuralKind;
59
+ /** Bounded retry policy for a leaf node. Attempts map to the kernel's retry step. */
60
+ export interface RunRetryPolicy {
61
+ readonly attempts: number;
62
+ readonly backoffMs?: number;
63
+ }
64
+ /** A leaf plan node. `step` names a handler resolved locally through a StepCatalog. */
65
+ export interface RunLeafNode {
66
+ readonly id: string;
67
+ readonly kind: RunLeafKind;
68
+ /** StepCatalog key. The handler is registered locally and never persisted in the plan. */
69
+ readonly step: string;
70
+ /** Only meaningful on top-level nodes; nested children may not declare it. */
71
+ readonly dependsOn?: readonly string[];
72
+ /** Required for `approve`; ignored otherwise. */
73
+ readonly reason?: string;
74
+ /** When set, the compiler asserts the resolved catalog step declares this exact version. */
75
+ readonly stepVersion?: number;
76
+ /** Wraps this leaf's compiled step in a bounded retry. */
77
+ readonly retry?: RunRetryPolicy;
78
+ }
79
+ /** An ordered composite. Children run in declaration order. */
80
+ export interface RunSequenceNode {
81
+ readonly id: string;
82
+ readonly kind: "sequence";
83
+ readonly children: readonly RunNode[];
84
+ readonly dependsOn?: readonly string[];
85
+ }
86
+ /** A bounded fan-out. Effective concurrency is the lower of this, the host, and the child count. */
87
+ export interface RunParallelNode {
88
+ readonly id: string;
89
+ readonly kind: "parallel";
90
+ readonly children: readonly RunNode[];
91
+ readonly maxConcurrency?: number;
92
+ readonly dependsOn?: readonly string[];
93
+ }
94
+ /** A bounded retry wrapping a single child node. */
95
+ export interface RunRetryNode {
96
+ readonly id: string;
97
+ readonly kind: "retry";
98
+ readonly child: RunNode;
99
+ readonly attempts: number;
100
+ readonly backoffMs?: number;
101
+ readonly dependsOn?: readonly string[];
102
+ }
103
+ /** A conditional. `step` names a predicate catalog handler selecting `then` or `otherwise`. */
104
+ export interface RunBranchNode {
105
+ readonly id: string;
106
+ readonly kind: "branch";
107
+ readonly step: string;
108
+ readonly then: RunNode;
109
+ readonly otherwise?: RunNode;
110
+ readonly dependsOn?: readonly string[];
111
+ }
112
+ /** A serializable, closure-free plan node. Structural kinds nest into a tree. */
113
+ export type RunNode = RunLeafNode | RunSequenceNode | RunParallelNode | RunRetryNode | RunBranchNode;
114
+ /** A serializable, closure-free run plan. Top-level nodes form a DAG; each node may nest a tree. */
115
+ export interface RunPlan {
116
+ readonly version: typeof RUN_PLAN_VERSION;
117
+ readonly id: string;
118
+ readonly nodes: readonly RunNode[];
119
+ }
120
+ export type RunEvidenceStatus = "started" | "completed" | "failed";
121
+ /** The content-free projection of one run transition. Every field is id/hash/counter/status/timing. */
122
+ export interface RunEvidence {
123
+ readonly version: typeof RUN_PLAN_VERSION;
124
+ readonly runId: string;
125
+ readonly planDigest: string;
126
+ readonly nodeId: string;
127
+ readonly status: RunEvidenceStatus;
128
+ readonly seq: number;
129
+ /** NodeEffectKey.digest when the node declared an effect selector; absent otherwise. */
130
+ readonly effectKey?: string;
131
+ /** Whether the step declared an idempotency selector. */
132
+ readonly idempotent: boolean;
133
+ readonly artifacts?: readonly ArtifactRef[];
134
+ readonly errorCode?: string;
135
+ readonly durationMs?: number;
136
+ }
137
+ /** Thrown by every parser in this module on malformed or content-bearing input. Fails closed. */
138
+ export declare class RunContractError extends Error {
139
+ readonly reason: string;
140
+ constructor(reason: string);
141
+ }
142
+ /** Parse a content-free artifact reference. Rejects any non-schema or content key. */
143
+ export declare function parseArtifactRef(value: unknown): ArtifactRef;
144
+ /** Parse a declarative run plan. Rejects closures, unknown keys, and structural errors. */
145
+ export declare function parseRunPlan(value: unknown): RunPlan;
146
+ /** Parse a content-free evidence record. Rejects content keys and any record over the size cap. */
147
+ export declare function parseRunEvidence(value: unknown): RunEvidence;
148
+ /** Assert a record serializes within the hard cap. Public reference records are content-free. */
149
+ export declare function assertEvidenceSize(evidence: RunEvidence): void;
150
+ //# sourceMappingURL=orchestration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"orchestration.d.ts","sourceRoot":"","sources":["../src/orchestration.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,wFAAwF;AACxF,eAAO,MAAM,gBAAgB,EAAG,CAAU,CAAA;AAE1C,oGAAoG;AACpG,eAAO,MAAM,kBAAkB,OAAO,CAAA;AAEtC;;;GAGG;AACH,eAA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