@nifrajs/coding-agent 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.
Files changed (211) hide show
  1. package/EXTENSIONS.md +25 -0
  2. package/PERFORMANCE.md +19 -0
  3. package/README.md +69 -0
  4. package/REGISTRY.md +15 -0
  5. package/SECURITY.md +32 -0
  6. package/dist/approvals.d.ts +70 -0
  7. package/dist/approvals.d.ts.map +1 -0
  8. package/dist/approvals.js +174 -0
  9. package/dist/approvals.js.map +1 -0
  10. package/dist/capabilities.d.ts +20 -0
  11. package/dist/capabilities.d.ts.map +1 -0
  12. package/dist/capabilities.js +49 -0
  13. package/dist/capabilities.js.map +1 -0
  14. package/dist/cli.d.ts +24 -0
  15. package/dist/cli.d.ts.map +1 -0
  16. package/dist/cli.js +380 -0
  17. package/dist/cli.js.map +1 -0
  18. package/dist/context.d.ts +17 -0
  19. package/dist/context.d.ts.map +1 -0
  20. package/dist/context.js +66 -0
  21. package/dist/context.js.map +1 -0
  22. package/dist/deployment-adapters.d.ts +40 -0
  23. package/dist/deployment-adapters.d.ts.map +1 -0
  24. package/dist/deployment-adapters.js +147 -0
  25. package/dist/deployment-adapters.js.map +1 -0
  26. package/dist/diff.d.ts +17 -0
  27. package/dist/diff.d.ts.map +1 -0
  28. package/dist/diff.js +61 -0
  29. package/dist/diff.js.map +1 -0
  30. package/dist/errors.d.ts +9 -0
  31. package/dist/errors.d.ts.map +1 -0
  32. package/dist/errors.js +35 -0
  33. package/dist/errors.js.map +1 -0
  34. package/dist/extensions.d.ts +104 -0
  35. package/dist/extensions.d.ts.map +1 -0
  36. package/dist/extensions.js +284 -0
  37. package/dist/extensions.js.map +1 -0
  38. package/dist/handoffs.d.ts +97 -0
  39. package/dist/handoffs.d.ts.map +1 -0
  40. package/dist/handoffs.js +199 -0
  41. package/dist/handoffs.js.map +1 -0
  42. package/dist/healing.d.ts +56 -0
  43. package/dist/healing.d.ts.map +1 -0
  44. package/dist/healing.js +54 -0
  45. package/dist/healing.js.map +1 -0
  46. package/dist/host.d.ts +61 -0
  47. package/dist/host.d.ts.map +1 -0
  48. package/dist/host.js +369 -0
  49. package/dist/host.js.map +1 -0
  50. package/dist/index.d.ts +26 -0
  51. package/dist/index.d.ts.map +1 -0
  52. package/dist/index.js +26 -0
  53. package/dist/index.js.map +1 -0
  54. package/dist/isolated-worker.d.ts +2 -0
  55. package/dist/isolated-worker.d.ts.map +1 -0
  56. package/dist/isolated-worker.js +155 -0
  57. package/dist/isolated-worker.js.map +1 -0
  58. package/dist/isolated.d.ts +52 -0
  59. package/dist/isolated.d.ts.map +1 -0
  60. package/dist/isolated.js +293 -0
  61. package/dist/isolated.js.map +1 -0
  62. package/dist/native.d.ts +92 -0
  63. package/dist/native.d.ts.map +1 -0
  64. package/dist/native.js +339 -0
  65. package/dist/native.js.map +1 -0
  66. package/dist/orchestration/artifact-port.d.ts +30 -0
  67. package/dist/orchestration/artifact-port.d.ts.map +1 -0
  68. package/dist/orchestration/artifact-port.js +59 -0
  69. package/dist/orchestration/artifact-port.js.map +1 -0
  70. package/dist/orchestration/catalog.d.ts +71 -0
  71. package/dist/orchestration/catalog.d.ts.map +1 -0
  72. package/dist/orchestration/catalog.js +46 -0
  73. package/dist/orchestration/catalog.js.map +1 -0
  74. package/dist/orchestration/compile.d.ts +59 -0
  75. package/dist/orchestration/compile.d.ts.map +1 -0
  76. package/dist/orchestration/compile.js +268 -0
  77. package/dist/orchestration/compile.js.map +1 -0
  78. package/dist/orchestration/dispatch.d.ts +115 -0
  79. package/dist/orchestration/dispatch.d.ts.map +1 -0
  80. package/dist/orchestration/dispatch.js +220 -0
  81. package/dist/orchestration/dispatch.js.map +1 -0
  82. package/dist/orchestration/durable-jobs.d.ts +35 -0
  83. package/dist/orchestration/durable-jobs.d.ts.map +1 -0
  84. package/dist/orchestration/durable-jobs.js +273 -0
  85. package/dist/orchestration/durable-jobs.js.map +1 -0
  86. package/dist/orchestration/effect-key.d.ts +23 -0
  87. package/dist/orchestration/effect-key.d.ts.map +1 -0
  88. package/dist/orchestration/effect-key.js +24 -0
  89. package/dist/orchestration/effect-key.js.map +1 -0
  90. package/dist/orchestration/evidence-store.d.ts +75 -0
  91. package/dist/orchestration/evidence-store.d.ts.map +1 -0
  92. package/dist/orchestration/evidence-store.js +183 -0
  93. package/dist/orchestration/evidence-store.js.map +1 -0
  94. package/dist/orchestration/hash.d.ts +12 -0
  95. package/dist/orchestration/hash.d.ts.map +1 -0
  96. package/dist/orchestration/hash.js +43 -0
  97. package/dist/orchestration/hash.js.map +1 -0
  98. package/dist/orchestration/host.d.ts +121 -0
  99. package/dist/orchestration/host.d.ts.map +1 -0
  100. package/dist/orchestration/host.js +334 -0
  101. package/dist/orchestration/host.js.map +1 -0
  102. package/dist/orchestration/index.d.ts +20 -0
  103. package/dist/orchestration/index.d.ts.map +1 -0
  104. package/dist/orchestration/index.js +19 -0
  105. package/dist/orchestration/index.js.map +1 -0
  106. package/dist/orchestration/policy.d.ts +63 -0
  107. package/dist/orchestration/policy.d.ts.map +1 -0
  108. package/dist/orchestration/policy.js +80 -0
  109. package/dist/orchestration/policy.js.map +1 -0
  110. package/dist/orchestration/recovery.d.ts +87 -0
  111. package/dist/orchestration/recovery.d.ts.map +1 -0
  112. package/dist/orchestration/recovery.js +197 -0
  113. package/dist/orchestration/recovery.js.map +1 -0
  114. package/dist/orchestration/tracer.d.ts +31 -0
  115. package/dist/orchestration/tracer.d.ts.map +1 -0
  116. package/dist/orchestration/tracer.js +141 -0
  117. package/dist/orchestration/tracer.js.map +1 -0
  118. package/dist/plans.d.ts +35 -0
  119. package/dist/plans.d.ts.map +1 -0
  120. package/dist/plans.js +63 -0
  121. package/dist/plans.js.map +1 -0
  122. package/dist/presets.d.ts +10 -0
  123. package/dist/presets.d.ts.map +1 -0
  124. package/dist/presets.js +70 -0
  125. package/dist/presets.js.map +1 -0
  126. package/dist/process.d.ts +6 -0
  127. package/dist/process.d.ts.map +1 -0
  128. package/dist/process.js +42 -0
  129. package/dist/process.js.map +1 -0
  130. package/dist/registry.d.ts +37 -0
  131. package/dist/registry.d.ts.map +1 -0
  132. package/dist/registry.js +51 -0
  133. package/dist/registry.js.map +1 -0
  134. package/dist/replay.d.ts +24 -0
  135. package/dist/replay.d.ts.map +1 -0
  136. package/dist/replay.js +154 -0
  137. package/dist/replay.js.map +1 -0
  138. package/dist/rpc.d.ts +51 -0
  139. package/dist/rpc.d.ts.map +1 -0
  140. package/dist/rpc.js +412 -0
  141. package/dist/rpc.js.map +1 -0
  142. package/dist/session-migration.d.ts +59 -0
  143. package/dist/session-migration.d.ts.map +1 -0
  144. package/dist/session-migration.js +315 -0
  145. package/dist/session-migration.js.map +1 -0
  146. package/dist/sessions.d.ts +74 -0
  147. package/dist/sessions.d.ts.map +1 -0
  148. package/dist/sessions.js +222 -0
  149. package/dist/sessions.js.map +1 -0
  150. package/dist/subagents.d.ts +51 -0
  151. package/dist/subagents.d.ts.map +1 -0
  152. package/dist/subagents.js +141 -0
  153. package/dist/subagents.js.map +1 -0
  154. package/dist/tools.d.ts +13 -0
  155. package/dist/tools.d.ts.map +1 -0
  156. package/dist/tools.js +37 -0
  157. package/dist/tools.js.map +1 -0
  158. package/dist/ui.d.ts +42 -0
  159. package/dist/ui.d.ts.map +1 -0
  160. package/dist/ui.js +93 -0
  161. package/dist/ui.js.map +1 -0
  162. package/dist/verification.d.ts +34 -0
  163. package/dist/verification.d.ts.map +1 -0
  164. package/dist/verification.js +91 -0
  165. package/dist/verification.js.map +1 -0
  166. package/dist/workflows.d.ts +98 -0
  167. package/dist/workflows.d.ts.map +1 -0
  168. package/dist/workflows.js +174 -0
  169. package/dist/workflows.js.map +1 -0
  170. package/package.json +84 -0
  171. package/src/approvals.ts +249 -0
  172. package/src/capabilities.ts +74 -0
  173. package/src/cli.ts +405 -0
  174. package/src/context.ts +81 -0
  175. package/src/deployment-adapters.ts +181 -0
  176. package/src/diff.ts +80 -0
  177. package/src/errors.ts +46 -0
  178. package/src/extensions.ts +402 -0
  179. package/src/handoffs.ts +299 -0
  180. package/src/healing.ts +93 -0
  181. package/src/host.ts +465 -0
  182. package/src/index.ts +165 -0
  183. package/src/isolated-worker.ts +177 -0
  184. package/src/isolated.ts +344 -0
  185. package/src/native.ts +478 -0
  186. package/src/orchestration/artifact-port.ts +75 -0
  187. package/src/orchestration/catalog.ts +102 -0
  188. package/src/orchestration/compile.ts +373 -0
  189. package/src/orchestration/dispatch.ts +383 -0
  190. package/src/orchestration/durable-jobs.ts +374 -0
  191. package/src/orchestration/effect-key.ts +35 -0
  192. package/src/orchestration/evidence-store.ts +233 -0
  193. package/src/orchestration/hash.ts +43 -0
  194. package/src/orchestration/host.ts +445 -0
  195. package/src/orchestration/index.ts +131 -0
  196. package/src/orchestration/policy.ts +116 -0
  197. package/src/orchestration/recovery.ts +271 -0
  198. package/src/orchestration/tracer.ts +177 -0
  199. package/src/plans.ts +105 -0
  200. package/src/presets.ts +90 -0
  201. package/src/process.ts +47 -0
  202. package/src/registry.ts +80 -0
  203. package/src/replay.ts +190 -0
  204. package/src/rpc.ts +598 -0
  205. package/src/session-migration.ts +401 -0
  206. package/src/sessions.ts +303 -0
  207. package/src/subagents.ts +210 -0
  208. package/src/tools.ts +52 -0
  209. package/src/ui.ts +137 -0
  210. package/src/verification.ts +133 -0
  211. package/src/workflows.ts +279 -0
@@ -0,0 +1,334 @@
1
+ /**
2
+ * The OrchestrationHost: the lifecycle owner for a compiled {@link RunPlan}. It does not schedule
3
+ * work itself - each top-level DAG layer is handed to a kernel {@link WorkflowRunner}, exactly as
4
+ * {@link compileRunPlan} would fold them into one `sequence`. Driving layer by layer gives a safe
5
+ * pause boundary (in-flight nodes finish; no new layer starts) and a cancellation seam (the layer's
6
+ * runner and any bounded subagent share the run's abort signal) without a second engine.
7
+ *
8
+ * Every transition is guarded by an explicit state machine: an illegal transition returns a stable
9
+ * code and mutates nothing. A terminal run is frozen - a late completion from an aborted layer
10
+ * cannot change its status, counters, or digest. Terminal results expose status, completed node ids,
11
+ * an order-independent evidence digest, artifact refs, counters, and a failure code only: never a
12
+ * step output, prompt, or payload.
13
+ */
14
+ import { parseRunPlan, RUN_PLAN_VERSION } from "@nifrajs/agent-protocol";
15
+ import { WorkflowRunner } from "../workflows.js";
16
+ import { noopArtifactPort } from "./artifact-port.js";
17
+ import { compileRunPlanLayers, digestRunPlan } from "./compile.js";
18
+ import { MemoryEvidenceStore } from "./evidence-store.js";
19
+ import { admitCapability, ChildVectorTracker } from "./policy.js";
20
+ const TERMINAL = new Set(["succeeded", "failed", "cancelled"]);
21
+ function isTerminal(state) {
22
+ return TERMINAL.has(state);
23
+ }
24
+ /** Thrown on an illegal lifecycle transition or an unknown run. `code` is stable. */
25
+ export class OrchestrationStateError extends Error {
26
+ code;
27
+ constructor(reason, code) {
28
+ super(`orchestration host: ${reason}`);
29
+ this.code = code;
30
+ this.name = "OrchestrationStateError";
31
+ }
32
+ }
33
+ const DEFAULT_MAX_STEPS = 100_000;
34
+ const DEFAULT_MAX_DEPTH = 64;
35
+ /** Owns run lifecycle and evidence projection over the kernel WorkflowRunner. */
36
+ export class OrchestrationHost {
37
+ catalog;
38
+ limits;
39
+ maxSteps;
40
+ maxDepth;
41
+ policy;
42
+ vectors = new ChildVectorTracker();
43
+ runs = new Map();
44
+ counter = 0;
45
+ constructor(options) {
46
+ this.catalog = options.catalog;
47
+ this.limits = options.limits;
48
+ this.maxSteps = options.maxSteps ?? DEFAULT_MAX_STEPS;
49
+ this.maxDepth = options.maxDepth ?? DEFAULT_MAX_DEPTH;
50
+ this.policy = options.policy;
51
+ }
52
+ /**
53
+ * Admit a capability descriptor against the host policy before it can be invoked. Throws
54
+ * {@link OrchestrationStateError} (`E_POLICY_REJECTED`) carrying the admission reason when refused.
55
+ * With no policy configured this is a passthrough - the host admits nothing it is not told to gate.
56
+ */
57
+ admit(descriptor) {
58
+ if (this.policy === undefined)
59
+ return;
60
+ const admission = admitCapability(this.policy, descriptor);
61
+ if (!admission.ok)
62
+ throw new OrchestrationStateError(`capability refused by host policy (${admission.code})`, "E_POLICY_REJECTED");
63
+ }
64
+ /**
65
+ * Allocate the next monotonic child vector for a live run, addressing a decision boundary the run
66
+ * pauses on. Strictly increasing per run, so a decision carrying any other vector is provably stale.
67
+ */
68
+ openBoundaryVector(runId) {
69
+ const run = this.require(runId);
70
+ if (isTerminal(run.state))
71
+ throw new OrchestrationStateError(`run '${runId}' is terminal; no boundary opens`, "E_NOT_TERMINAL");
72
+ return this.vectors.open(runId);
73
+ }
74
+ /**
75
+ * Parse, compile, and register a run in `submitted`. All structural ceilings and capability
76
+ * authority are enforced here (a `CompileError` with a stable code), so an over-limit or
77
+ * unauthorized plan never reaches `running`.
78
+ */
79
+ async submit(source, options = {}) {
80
+ const plan = parseRunPlan(source);
81
+ const planDigest = await digestRunPlan(plan);
82
+ const runId = options.runId ?? `run-${++this.counter}`;
83
+ if (this.runs.has(runId))
84
+ throw new OrchestrationStateError(`run '${runId}' already exists`, "E_DUPLICATE_RUN");
85
+ const artifactPort = options.artifactPort ?? noopArtifactPort();
86
+ const effectKeys = new Map();
87
+ const artifacts = new Map();
88
+ const layers = compileRunPlanLayers(plan, {
89
+ catalog: this.catalog,
90
+ planDigest,
91
+ artifactPort,
92
+ ...(this.limits !== undefined ? { limits: this.limits } : {}),
93
+ onNodeEffect: (nodeId, key) => effectKeys.set(nodeId, key),
94
+ collectArtifact: (nodeId, ref) => {
95
+ const list = artifacts.get(nodeId);
96
+ if (list === undefined)
97
+ artifacts.set(nodeId, [ref]);
98
+ else
99
+ list.push(ref);
100
+ },
101
+ });
102
+ const { kindById, idempotentById, nodeIds } = this.indexPlan(plan);
103
+ let finish;
104
+ const done = new Promise((resolve) => {
105
+ finish = resolve;
106
+ });
107
+ this.runs.set(runId, {
108
+ runId,
109
+ planDigest,
110
+ layers,
111
+ store: options.store ?? new MemoryEvidenceStore(),
112
+ controller: new AbortController(),
113
+ kindById,
114
+ idempotentById,
115
+ nodeIds,
116
+ effectKeys,
117
+ artifacts,
118
+ state: "submitted",
119
+ layerIndex: 0,
120
+ seq: 0,
121
+ cancelRequested: false,
122
+ failureCode: undefined,
123
+ gate: undefined,
124
+ done,
125
+ finish,
126
+ });
127
+ return runId;
128
+ }
129
+ /** Content-free progress view. Throws `E_NOT_FOUND` for an unknown run. */
130
+ inspect(runId) {
131
+ const run = this.require(runId);
132
+ return {
133
+ runId,
134
+ state: run.state,
135
+ planDigest: run.planDigest,
136
+ layerIndex: run.layerIndex,
137
+ layerCount: run.layers.length,
138
+ counters: run.store.counters(),
139
+ };
140
+ }
141
+ /** `submitted` -> `running`. Begins the driver. */
142
+ start(runId) {
143
+ const run = this.require(runId);
144
+ this.transition(run, "start", ["submitted"], "running");
145
+ void this.drive(run);
146
+ }
147
+ /** `running` -> `paused`. Takes effect at the next layer boundary; in-flight nodes finish. */
148
+ pause(runId) {
149
+ const run = this.require(runId);
150
+ this.transition(run, "pause", ["running"], "paused");
151
+ let resolve;
152
+ const promise = new Promise((r) => {
153
+ resolve = r;
154
+ });
155
+ run.gate = { promise, resolve };
156
+ }
157
+ /** `paused` -> `running`. Releases the layer boundary. */
158
+ resume(runId) {
159
+ const run = this.require(runId);
160
+ this.transition(run, "resume", ["paused"], "running");
161
+ run.gate?.resolve();
162
+ run.gate = undefined;
163
+ }
164
+ /**
165
+ * Cancel from any non-terminal state. Aborts the in-flight layer and any bounded subagent, frees a
166
+ * paused gate, and freezes the run in `cancelled`. A late completion cannot revive it.
167
+ */
168
+ cancel(runId) {
169
+ const run = this.require(runId);
170
+ if (isTerminal(run.state))
171
+ throw new OrchestrationStateError(`run '${runId}' cannot cancel from terminal '${run.state}'`, "E_ILLEGAL_TRANSITION");
172
+ run.cancelRequested = true;
173
+ run.state = "cancelled";
174
+ run.failureCode = "E_CANCELLED";
175
+ run.controller.abort();
176
+ run.gate?.resolve();
177
+ run.gate = undefined;
178
+ this.vectors.release(run.runId);
179
+ run.finish();
180
+ }
181
+ /** Terminal result. Throws `E_NOT_TERMINAL` while the run is still live. */
182
+ async result(runId) {
183
+ const run = this.require(runId);
184
+ if (!isTerminal(run.state))
185
+ throw new OrchestrationStateError(`run '${runId}' is '${run.state}', not terminal`, "E_NOT_TERMINAL");
186
+ return this.buildResult(run);
187
+ }
188
+ /** Await the run reaching a terminal state, then return its result. */
189
+ async settled(runId) {
190
+ const run = this.require(runId);
191
+ await run.done;
192
+ return this.buildResult(run);
193
+ }
194
+ require(runId) {
195
+ const run = this.runs.get(runId);
196
+ if (run === undefined)
197
+ throw new OrchestrationStateError(`unknown run '${runId}'`, "E_NOT_FOUND");
198
+ return run;
199
+ }
200
+ transition(run, op, from, to) {
201
+ if (!from.includes(run.state))
202
+ throw new OrchestrationStateError(`cannot ${op} run '${run.runId}' from '${run.state}'`, "E_ILLEGAL_TRANSITION");
203
+ run.state = to;
204
+ }
205
+ async buildResult(run) {
206
+ const status = run.state;
207
+ return {
208
+ runId: run.runId,
209
+ status,
210
+ planDigest: run.planDigest,
211
+ completedNodeIds: run.store.completedNodeIds(),
212
+ evidenceDigest: await run.store.digest(),
213
+ artifacts: run.store.artifacts(),
214
+ counters: run.store.counters(),
215
+ ...(run.failureCode !== undefined ? { failureCode: run.failureCode } : {}),
216
+ };
217
+ }
218
+ async drive(run) {
219
+ try {
220
+ for (; run.layerIndex < run.layers.length; run.layerIndex++) {
221
+ while (run.state === "paused")
222
+ await run.gate?.promise;
223
+ if (isTerminal(run.state))
224
+ return; // cancelled while paused
225
+ const layer = run.layers[run.layerIndex];
226
+ const result = await new WorkflowRunner({
227
+ signal: run.controller.signal,
228
+ maxSteps: this.maxSteps,
229
+ maxDepth: this.maxDepth,
230
+ onEvent: (event) => this.project(run, event),
231
+ }).run(layer);
232
+ if (isTerminal(run.state))
233
+ return; // cancelled mid-layer: ignore the late result
234
+ if (!result.ok) {
235
+ run.state = "failed";
236
+ run.failureCode = run.failureCode ?? "E_STEP_FAILED";
237
+ return;
238
+ }
239
+ }
240
+ if (!isTerminal(run.state))
241
+ run.state = "succeeded";
242
+ }
243
+ finally {
244
+ if (!isTerminal(run.state))
245
+ run.state = "failed";
246
+ this.vectors.release(run.runId);
247
+ run.finish();
248
+ }
249
+ }
250
+ /** Project one kernel event into a content-free evidence record. Frozen once the run is terminal. */
251
+ async project(run, event) {
252
+ if (isTerminal(run.state))
253
+ return; // a late completion cannot mutate a terminal run
254
+ if (!("id" in event) || !run.nodeIds.has(event.id))
255
+ return;
256
+ const base = {
257
+ version: RUN_PLAN_VERSION,
258
+ runId: run.runId,
259
+ planDigest: run.planDigest,
260
+ nodeId: event.id,
261
+ seq: run.seq++,
262
+ idempotent: run.idempotentById.get(event.id) ?? false,
263
+ };
264
+ const key = run.effectKeys.get(event.id);
265
+ const effect = key !== undefined ? { effectKey: key.digest } : {};
266
+ if (event.type === "step.started") {
267
+ await run.store.append({ ...base, status: "started" });
268
+ return;
269
+ }
270
+ if (event.type === "step.completed") {
271
+ if (isGateRejection(run.kindById.get(event.id), event.output)) {
272
+ run.failureCode = "E_GATE_REJECTED";
273
+ await run.store.append({ ...base, status: "failed", errorCode: "GATE_REJECTED", ...effect });
274
+ return;
275
+ }
276
+ const refs = run.artifacts.get(event.id);
277
+ await run.store.append({
278
+ ...base,
279
+ status: "completed",
280
+ ...effect,
281
+ ...(refs !== undefined && refs.length > 0 ? { artifacts: refs } : {}),
282
+ });
283
+ return;
284
+ }
285
+ if (event.type === "step.failed") {
286
+ run.failureCode = "E_STEP_FAILED";
287
+ await run.store.append({ ...base, status: "failed", errorCode: "STEP_FAILED", ...effect });
288
+ }
289
+ }
290
+ /** Walk the plan tree once: node kinds, idempotency flags, and the full id set. */
291
+ indexPlan(plan) {
292
+ const kindById = new Map();
293
+ const idempotentById = new Map();
294
+ const nodeIds = new Set();
295
+ const walk = (node) => {
296
+ nodeIds.add(node.id);
297
+ kindById.set(node.id, node.kind);
298
+ const step = "step" in node ? this.catalog.get(node.step) : undefined;
299
+ idempotentById.set(node.id, step?.selectEffect !== undefined);
300
+ switch (node.kind) {
301
+ case "sequence":
302
+ case "parallel":
303
+ for (const child of node.children)
304
+ walk(child);
305
+ break;
306
+ case "retry":
307
+ walk(node.child);
308
+ break;
309
+ case "branch":
310
+ walk(node.then);
311
+ if (node.otherwise !== undefined)
312
+ walk(node.otherwise);
313
+ break;
314
+ }
315
+ };
316
+ for (const node of plan.nodes)
317
+ walk(node);
318
+ return { kindById, idempotentById, nodeIds };
319
+ }
320
+ }
321
+ /** A verify/approve node whose output is not a pass. Other kinds never gate. */
322
+ function isGateRejection(kind, output) {
323
+ if (kind === "verify") {
324
+ if (output === true)
325
+ return false;
326
+ return !(typeof output === "object" &&
327
+ output !== null &&
328
+ output.ok === true);
329
+ }
330
+ if (kind === "approve")
331
+ return output !== true;
332
+ return false;
333
+ }
334
+ //# sourceMappingURL=host.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host.js","sourceRoot":"","sources":["../../src/orchestration/host.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAWH,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAExE,OAAO,EAAsB,cAAc,EAAE,MAAM,iBAAiB,CAAA;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAErD,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAA4B,MAAM,cAAc,CAAA;AAC5F,OAAO,EAA6C,mBAAmB,EAAE,MAAM,qBAAqB,CAAA;AACpG,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAmB,MAAM,aAAa,CAAA;AAIlF,MAAM,QAAQ,GAA0B,IAAI,GAAG,CAAC,CAAC,WAAW,EAAE,QAAQ,EAAE,WAAW,CAAC,CAAC,CAAA;AAErF,SAAS,UAAU,CAAC,KAAe;IACjC,OAAO,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;AAC5B,CAAC;AAED,qFAAqF;AACrF,MAAM,OAAO,uBAAwB,SAAQ,KAAK;IAGrC;IAFX,YACE,MAAc,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CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,EAAE,YAAY,KAAK,SAAS,CAAC,CAAA;YAC7D,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;gBAClB,KAAK,UAAU,CAAC;gBAChB,KAAK,UAAU;oBACb,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,QAAQ;wBAAE,IAAI,CAAC,KAAK,CAAC,CAAA;oBAC9C,MAAK;gBACP,KAAK,OAAO;oBACV,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;oBAChB,MAAK;gBACP,KAAK,QAAQ;oBACX,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;oBACf,IAAI,IAAI,CAAC,SAAS,KAAK,SAAS;wBAAE,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;oBACtD,MAAK;YACT,CAAC;QACH,CAAC,CAAA;QACD,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,KAAK;YAAE,IAAI,CAAC,IAAI,CAAC,CAAA;QACzC,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,OAAO,EAAE,CAAA;IAC9C,CAAC;CACF;AAED,gFAAgF;AAChF,SAAS,eAAe,CAAC,IAA6B,EAAE,MAAe;IACrE,IAAI,IAAI,KAAK,QAAQ,EAAE,CAAC;QACtB,IAAI,MAAM,KAAK,IAAI;YAAE,OAAO,KAAK,CAAA;QACjC,OAAO,CAAC,CACN,OAAO,MAAM,KAAK,QAAQ;YAC1B,MAAM,KAAK,IAAI;YACd,MAA2B,CAAC,EAAE,KAAK,IAAI,CACzC,CAAA;IACH,CAAC;IACD,IAAI,IAAI,KAAK,SAAS;QAAE,OAAO,MAAM,KAAK,IAAI,CAAA;IAC9C,OAAO,KAAK,CAAA;AACd,CAAC"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * `@nifrajs/coding-agent/orchestration` - declarative RunPlans compiled onto the existing
3
+ * WorkflowRunner, with content-free evidence, a caller-owned artifact seam, and content-free
4
+ * idempotency keys. No second engine; no payload sink. See the P0 addendum for the design lock.
5
+ */
6
+ export type { ArtifactContext, ArtifactPort, ArtifactRef, NodeEffectKey, RunBranchNode, RunEvidence, RunEvidenceStatus, RunLeafKind, RunLeafNode, RunNode, RunNodeKind, RunParallelNode, RunPlan, RunRetryNode, RunRetryPolicy, RunSequenceNode, RunStructuralKind, } from "@nifrajs/agent-protocol";
7
+ export { assertEvidenceSize, EVIDENCE_MAX_BYTES, FORBIDDEN_CONTENT_KEYS, parseArtifactRef, parseRunEvidence, parseRunPlan, RUN_PLAN_VERSION, RunContractError, } from "@nifrajs/agent-protocol";
8
+ export { type MemoryArtifactPort, memoryArtifactPort, noopArtifactPort, } from "./artifact-port.js";
9
+ export { CatalogError, type CatalogStep, createStepCatalog, mergeStepCatalogs, type StepCatalog, type StepEffectContext, type StepRunContext, stepVersion, } from "./catalog.js";
10
+ export { CompileError, type CompileOptions, compileRunPlan, compileRunPlanLayers, digestRunPlan, type OrchestrationLimits, } from "./compile.js";
11
+ export { createRunDispatch, DISPATCH_JOB_NAME, type DispatchBoundary, type DispatchInspection, type DispatchResultCode, type DispatchState, type DispatchWriteResult, type DurableDispatchAdapter, deriveRunIdempotencyKey, type InjectedClock, MAX_DISPATCH_ATTEMPTS, MAX_DISPATCH_STRING, parseRunCheckpoint, parseRunDispatch, parseRunDispatchEvidence, parseRunLease, RUN_DISPATCH_VERSION, type RunCheckpoint, type RunDispatch, type RunDispatchEvidence, type RunDispatchStore, type RunLease, systemClock, } from "./dispatch.js";
12
+ export { createDurableJobsStore, createMemoryRunDispatchStore, type DurableJobsStoreOptions, } from "./durable-jobs.js";
13
+ export { deriveNodeEffectKey, type EffectKeyMaterial } from "./effect-key.js";
14
+ export { type EvidenceCounters, type EvidenceStore, FileEvidenceStore, type FileEvidenceStoreOptions, MemoryEvidenceStore, type MemoryEvidenceStoreOptions, } from "./evidence-store.js";
15
+ export { canonicalJson, sha256Hex, sha256HexOf } from "./hash.js";
16
+ export { OrchestrationHost, type OrchestrationHostOptions, OrchestrationStateError, type RunResult, type RunState, type RunStatus, type SubmitOptions, } from "./host.js";
17
+ export { type Admission, type AdmissionRejection, admitCapability, assertAdmitted, ChildVectorTracker, type HostPolicy, PolicyError, } from "./policy.js";
18
+ export { type CommittedEffect, EffectRejectedError, type IdempotencyProofStore, MemoryIdempotencyProofStore, RecoveryCrashError, type RecoveryMachineOptions, type RecoveryProcessResult, type RunEffect, type RunEffectContext, RunRecoveryMachine, TestClock, } from "./recovery.js";
19
+ export { type RunTraceOptions, type RunTraceResult, runTrace } from "./tracer.js";
20
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/orchestration/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY,EACV,eAAe,EACf,YAAY,EACZ,WAAW,EACX,aAAa,EACb,aAAa,EACb,WAAW,EACX,iBAAiB,EACjB,WAAW,EACX,WAAW,EACX,OAAO,EACP,WAAW,EACX,eAAe,EACf,OAAO,EACP,YAAY,EACZ,cAAc,EACd,eAAe,EACf,iBAAiB,GAClB,MAAM,yBAAyB,CAAA;AAChC,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAClB,sBAAsB,EACtB,gBAAgB,EAChB,gBAAgB,EAChB,YAAY,EACZ,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,yBAAyB,CAAA;AAEhC,OAAO,EACL,KAAK,kBAAkB,EACvB,kBAAkB,EAClB,gBAAgB,GACjB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EACL,YAAY,EACZ,KAAK,WAAW,EAChB,iBAAiB,EACjB,iBAAiB,EACjB,KAAK,WAAW,EAChB,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACnB,WAAW,GACZ,MAAM,cAAc,CAAA;AACrB,OAAO,EACL,YAAY,EACZ,KAAK,cAAc,EACnB,cAAc,EACd,oBAAoB,EACpB,aAAa,EACb,KAAK,mBAAmB,GACzB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B,EAC3B,KAAK,qBAAqB,EAC1B,KAAK,SAAS,EACd,KAAK,gBAAgB,EACrB,kBAAkB,EAClB,SAAS,GACV,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,KAAK,eAAe,EAAE,KAAK,cAAc,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * `@nifrajs/coding-agent/orchestration` - declarative RunPlans compiled onto the existing
3
+ * WorkflowRunner, with content-free evidence, a caller-owned artifact seam, and content-free
4
+ * idempotency keys. No second engine; no payload sink. See the P0 addendum for the design lock.
5
+ */
6
+ export { assertEvidenceSize, EVIDENCE_MAX_BYTES, FORBIDDEN_CONTENT_KEYS, parseArtifactRef, parseRunEvidence, parseRunPlan, RUN_PLAN_VERSION, RunContractError, } from "@nifrajs/agent-protocol";
7
+ export { memoryArtifactPort, noopArtifactPort, } from "./artifact-port.js";
8
+ export { CatalogError, createStepCatalog, mergeStepCatalogs, stepVersion, } from "./catalog.js";
9
+ export { CompileError, compileRunPlan, compileRunPlanLayers, digestRunPlan, } from "./compile.js";
10
+ export { createRunDispatch, DISPATCH_JOB_NAME, deriveRunIdempotencyKey, MAX_DISPATCH_ATTEMPTS, MAX_DISPATCH_STRING, parseRunCheckpoint, parseRunDispatch, parseRunDispatchEvidence, parseRunLease, RUN_DISPATCH_VERSION, systemClock, } from "./dispatch.js";
11
+ export { createDurableJobsStore, createMemoryRunDispatchStore, } from "./durable-jobs.js";
12
+ export { deriveNodeEffectKey } from "./effect-key.js";
13
+ export { FileEvidenceStore, MemoryEvidenceStore, } from "./evidence-store.js";
14
+ export { canonicalJson, sha256Hex, sha256HexOf } from "./hash.js";
15
+ export { OrchestrationHost, OrchestrationStateError, } from "./host.js";
16
+ export { admitCapability, assertAdmitted, ChildVectorTracker, PolicyError, } from "./policy.js";
17
+ export { EffectRejectedError, MemoryIdempotencyProofStore, RecoveryCrashError, RunRecoveryMachine, TestClock, } from "./recovery.js";
18
+ export { runTrace } from "./tracer.js";
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/orchestration/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAqBH,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAClB,sBAAsB,EACtB,gBAAgB,EAChB,gBAAgB,EAChB,YAAY,EACZ,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,yBAAyB,CAAA;AAEhC,OAAO,EAEL,kBAAkB,EAClB,gBAAgB,GACjB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EACL,YAAY,EAEZ,iBAAiB,EACjB,iBAAiB,EAIjB,WAAW,GACZ,MAAM,cAAc,CAAA;AACrB,OAAO,EACL,YAAY,EAEZ,cAAc,EACd,oBAAoB,EACpB,aAAa,GAEd,MAAM,cAAc,CAAA;AACrB,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EAOjB,uBAAuB,EAEvB,qBAAqB,EACrB,mBAAmB,EACnB,kBAAkB,EAClB,gBAAgB,EAChB,wBAAwB,EACxB,aAAa,EACb,oBAAoB,EAMpB,WAAW,GACZ,MAAM,eAAe,CAAA;AACtB,OAAO,EACL,sBAAsB,EACtB,4BAA4B,GAE7B,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,mBAAmB,EAA0B,MAAM,iBAAiB,CAAA;AAC7E,OAAO,EAGL,iBAAiB,EAEjB,mBAAmB,GAEpB,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AACjE,OAAO,EACL,iBAAiB,EAEjB,uBAAuB,GAKxB,MAAM,WAAW,CAAA;AAClB,OAAO,EAGL,eAAe,EACf,cAAc,EACd,kBAAkB,EAElB,WAAW,GACZ,MAAM,aAAa,CAAA;AACpB,OAAO,EAEL,mBAAmB,EAEnB,2BAA2B,EAC3B,kBAAkB,EAKlB,kBAAkB,EAClB,SAAS,GACV,MAAM,eAAe,CAAA;AACtB,OAAO,EAA6C,QAAQ,EAAE,MAAM,aAAa,CAAA"}
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Host policy admission for the orchestration host (REG-06) and the monotonic child-vector allocator
3
+ * (REG-07).
4
+ *
5
+ * A {@link HostPolicy} is the authority: it declares which capability kinds may run, an allowlist of
6
+ * required capabilities, an isolation floor, and whether every capability must be approved. A
7
+ * {@link CapabilityDescriptor} is only a request - {@link admitCapability} lets the descriptor tighten
8
+ * nothing it did not already promise and, crucially, cannot loosen the policy. A descriptor asking for
9
+ * weaker isolation than the floor, declaring a capability outside the allowlist, or offering `none`
10
+ * approval where the host requires approval is refused with a stable code. Descriptors, plans, models,
11
+ * extensions, and clients therefore cannot override host policy.
12
+ *
13
+ * The {@link ChildVectorTracker} hands each newly opened decision boundary a strictly increasing
14
+ * per-run vector. A decision must later carry the exact vector its boundary opened with, so a replayed
15
+ * or superseded decision cannot resume work. The tracker never allocates a non-advancing vector.
16
+ */
17
+ import type { CapabilityDescriptor, CapabilityKind, IsolationClass } from "@nifrajs/agent/registry";
18
+ /** The authoritative admission policy. Empty allowlists deny everything of that kind. */
19
+ export interface HostPolicy {
20
+ /** Capability kinds the host will admit. A descriptor of any other kind is refused. */
21
+ readonly allowedKinds: readonly CapabilityKind[];
22
+ /** Required-capability allowlist. Every `requiredCapabilities` entry must be present. */
23
+ readonly allowedCapabilities: readonly string[];
24
+ /** Isolation floor. A descriptor offering weaker isolation than this is refused. */
25
+ readonly minIsolation: IsolationClass;
26
+ /** When true, a descriptor whose approval class is `none` is refused as a downgrade. */
27
+ readonly requireApproval: boolean;
28
+ }
29
+ /** Stable, content-free reasons the host refuses to admit a capability. */
30
+ export type AdmissionRejection = "kind_not_allowed" | "capability_not_allowed" | "isolation_too_weak" | "approval_downgrade";
31
+ export type Admission = {
32
+ readonly ok: true;
33
+ } | {
34
+ readonly ok: false;
35
+ readonly code: AdmissionRejection;
36
+ };
37
+ /** Thrown when the host refuses admission and the caller wants an exception rather than a result. */
38
+ export declare class PolicyError extends Error {
39
+ readonly code: AdmissionRejection;
40
+ constructor(code: AdmissionRejection);
41
+ }
42
+ /**
43
+ * Admit a capability descriptor against the host policy. The policy is the floor; the descriptor can
44
+ * only meet or exceed it. Returns the first failing reason, or `{ ok: true }` when every gate passes.
45
+ */
46
+ export declare function admitCapability(policy: HostPolicy, descriptor: CapabilityDescriptor): Admission;
47
+ /** Admit or throw {@link PolicyError}. Use at the host boundary where a refusal must stop the run. */
48
+ export declare function assertAdmitted(policy: HostPolicy, descriptor: CapabilityDescriptor): void;
49
+ /**
50
+ * Per-run monotonic child-vector allocator. `open` returns the next strictly increasing vector for a
51
+ * run; `last` reports the high-water mark (`-1` before the first boundary). A vector is never reused,
52
+ * so a decision carrying anything other than its boundary's opened vector is provably stale.
53
+ */
54
+ export declare class ChildVectorTracker {
55
+ private readonly highWater;
56
+ /** Allocate the next vector for a run. Strictly greater than every previously allocated vector. */
57
+ open(runId: string): number;
58
+ /** The last allocated vector for a run, or `-1` when none has opened. */
59
+ last(runId: string): number;
60
+ /** Forget a run's vectors once it is terminal. Idempotent. */
61
+ release(runId: string): void;
62
+ }
63
+ //# sourceMappingURL=policy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"policy.d.ts","sourceRoot":"","sources":["../../src/orchestration/policy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAEV,oBAAoB,EACpB,cAAc,EACd,cAAc,EACf,MAAM,yBAAyB,CAAA;AAEhC,yFAAyF;AACzF,MAAM,WAAW,UAAU;IACzB,uFAAuF;IACvF,QAAQ,CAAC,YAAY,EAAE,SAAS,cAAc,EAAE,CAAA;IAChD,yFAAyF;IACzF,QAAQ,CAAC,mBAAmB,EAAE,SAAS,MAAM,EAAE,CAAA;IAC/C,oFAAoF;IACpF,QAAQ,CAAC,YAAY,EAAE,cAAc,CAAA;IACrC,wFAAwF;IACxF,QAAQ,CAAC,eAAe,EAAE,OAAO,CAAA;CAClC;AAED,2EAA2E;AAC3E,MAAM,MAAM,kBAAkB,GAC1B,kBAAkB,GAClB,wBAAwB,GACxB,oBAAoB,GACpB,oBAAoB,CAAA;AAExB,MAAM,MAAM,SAAS,GACjB;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAA;CAAE,GACrB;IAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,kBAAkB,CAAA;CAAE,CAAA;AAE7D,qGAAqG;AACrG,qBAAa,WAAY,SAAQ,KAAK;IACpC,QAAQ,CAAC,IAAI,EAAE,kBAAkB,CAAA;gBAErB,IAAI,EAAE,kBAAkB;CAKrC;AAaD;;;GAGG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,oBAAoB,GAAG,SAAS,CAU/F;AAED,sGAAsG;AACtG,wBAAgB,cAAc,CAAC,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,oBAAoB,GAAG,IAAI,CAGzF;AAED;;;;GAIG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA4B;IAEtD,mGAAmG;IACnG,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAM3B,yEAAyE;IACzE,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAI3B,8DAA8D;IAC9D,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;CAG7B"}
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Host policy admission for the orchestration host (REG-06) and the monotonic child-vector allocator
3
+ * (REG-07).
4
+ *
5
+ * A {@link HostPolicy} is the authority: it declares which capability kinds may run, an allowlist of
6
+ * required capabilities, an isolation floor, and whether every capability must be approved. A
7
+ * {@link CapabilityDescriptor} is only a request - {@link admitCapability} lets the descriptor tighten
8
+ * nothing it did not already promise and, crucially, cannot loosen the policy. A descriptor asking for
9
+ * weaker isolation than the floor, declaring a capability outside the allowlist, or offering `none`
10
+ * approval where the host requires approval is refused with a stable code. Descriptors, plans, models,
11
+ * extensions, and clients therefore cannot override host policy.
12
+ *
13
+ * The {@link ChildVectorTracker} hands each newly opened decision boundary a strictly increasing
14
+ * per-run vector. A decision must later carry the exact vector its boundary opened with, so a replayed
15
+ * or superseded decision cannot resume work. The tracker never allocates a non-advancing vector.
16
+ */
17
+ /** Thrown when the host refuses admission and the caller wants an exception rather than a result. */
18
+ export class PolicyError extends Error {
19
+ code;
20
+ constructor(code) {
21
+ super(`host policy: ${code}`);
22
+ this.code = code;
23
+ this.name = "PolicyError";
24
+ }
25
+ }
26
+ // Isolation is a total order: a higher rank is stronger and satisfies any lower floor.
27
+ const ISOLATION_RANK = {
28
+ inherit: 0,
29
+ process: 1,
30
+ sandbox: 2,
31
+ };
32
+ function approvalIsNone(approval) {
33
+ return approval.kind === "none";
34
+ }
35
+ /**
36
+ * Admit a capability descriptor against the host policy. The policy is the floor; the descriptor can
37
+ * only meet or exceed it. Returns the first failing reason, or `{ ok: true }` when every gate passes.
38
+ */
39
+ export function admitCapability(policy, descriptor) {
40
+ if (!policy.allowedKinds.includes(descriptor.kind))
41
+ return { ok: false, code: "kind_not_allowed" };
42
+ const allowed = new Set(policy.allowedCapabilities);
43
+ for (const capability of descriptor.requiredCapabilities)
44
+ if (!allowed.has(capability))
45
+ return { ok: false, code: "capability_not_allowed" };
46
+ if (ISOLATION_RANK[descriptor.isolation] < ISOLATION_RANK[policy.minIsolation])
47
+ return { ok: false, code: "isolation_too_weak" };
48
+ if (policy.requireApproval && approvalIsNone(descriptor.approval))
49
+ return { ok: false, code: "approval_downgrade" };
50
+ return { ok: true };
51
+ }
52
+ /** Admit or throw {@link PolicyError}. Use at the host boundary where a refusal must stop the run. */
53
+ export function assertAdmitted(policy, descriptor) {
54
+ const admission = admitCapability(policy, descriptor);
55
+ if (!admission.ok)
56
+ throw new PolicyError(admission.code);
57
+ }
58
+ /**
59
+ * Per-run monotonic child-vector allocator. `open` returns the next strictly increasing vector for a
60
+ * run; `last` reports the high-water mark (`-1` before the first boundary). A vector is never reused,
61
+ * so a decision carrying anything other than its boundary's opened vector is provably stale.
62
+ */
63
+ export class ChildVectorTracker {
64
+ highWater = new Map();
65
+ /** Allocate the next vector for a run. Strictly greater than every previously allocated vector. */
66
+ open(runId) {
67
+ const next = (this.highWater.get(runId) ?? -1) + 1;
68
+ this.highWater.set(runId, next);
69
+ return next;
70
+ }
71
+ /** The last allocated vector for a run, or `-1` when none has opened. */
72
+ last(runId) {
73
+ return this.highWater.get(runId) ?? -1;
74
+ }
75
+ /** Forget a run's vectors once it is terminal. Idempotent. */
76
+ release(runId) {
77
+ this.highWater.delete(runId);
78
+ }
79
+ }
80
+ //# sourceMappingURL=policy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"policy.js","sourceRoot":"","sources":["../../src/orchestration/policy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAgCH,qGAAqG;AACrG,MAAM,OAAO,WAAY,SAAQ,KAAK;IAC3B,IAAI,CAAoB;IAEjC,YAAY,IAAwB;QAClC,KAAK,CAAC,gBAAgB,IAAI,EAAE,CAAC,CAAA;QAC7B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,IAAI,GAAG,aAAa,CAAA;IAC3B,CAAC;CACF;AAED,uFAAuF;AACvF,MAAM,cAAc,GAA6C;IAC/D,OAAO,EAAE,CAAC;IACV,OAAO,EAAE,CAAC;IACV,OAAO,EAAE,CAAC;CACX,CAAA;AAED,SAAS,cAAc,CAAC,QAAuB;IAC7C,OAAO,QAAQ,CAAC,IAAI,KAAK,MAAM,CAAA;AACjC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,MAAkB,EAAE,UAAgC;IAClF,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC;QAAE,OAAO,EAAE,EAA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AAA;QAC/B,OAAO,IAAI,CAAA;IACb,CAAC;IAED,yEAAyE;IACzE,IAAI,CAAC,KAAa;QAChB,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAA;IACxC,CAAC;IAED,8DAA8D;IAC9D,OAAO,CAAC,KAAa;QACnB,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;IAC9B,CAAC;CACF"}
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Recovery state machine for at-least-once node dispatch.
3
+ *
4
+ * The machine treats every effect invocation as potentially side-effecting. A normal retry is
5
+ * allowed only for an explicit pre-effect rejection. Once an effect has been invoked, recovery
6
+ * requires a matching idempotency proof; without one it dead-letters the dispatch instead of
7
+ * guessing that a duplicate is safe. This is deliberately conservative and never claims exactly
8
+ * once delivery or hostile-code isolation.
9
+ */
10
+ import { type DispatchResultCode, type InjectedClock, type RunDispatchStore, type RunLease } from "./dispatch.js";
11
+ export interface IdempotencyProofStore {
12
+ has(key: string): boolean | Promise<boolean>;
13
+ record(key: string): void | Promise<void>;
14
+ }
15
+ /** Disposable proof reference for tests and one-process local runs. */
16
+ export declare class MemoryIdempotencyProofStore implements IdempotencyProofStore {
17
+ private readonly keys;
18
+ has(key: string): boolean;
19
+ record(key: string): void;
20
+ keysSnapshot(): readonly string[];
21
+ }
22
+ /** A side effect must explicitly confirm that its idempotency proof was durably recorded. */
23
+ export interface CommittedEffect {
24
+ readonly committed: true;
25
+ }
26
+ export interface RunEffectContext {
27
+ readonly lease: RunLease;
28
+ readonly signal: AbortSignal;
29
+ /** Persist a content-free safe boundary; a failed write prevents the next unsafe step. */
30
+ readonly checkpoint: (boundary: "before-effect" | "after-effect") => Promise<boolean>;
31
+ }
32
+ export type RunEffect = (context: RunEffectContext) => Promise<CommittedEffect> | CommittedEffect;
33
+ /** Stable pre-effect failure; it may be retried with a new logical attempt. */
34
+ export declare class EffectRejectedError extends Error {
35
+ readonly code: string;
36
+ constructor(code?: string);
37
+ }
38
+ /** Simulates worker loss at a named boundary; the lease is intentionally left unresolved. */
39
+ export declare class RecoveryCrashError extends Error {
40
+ readonly boundary: "before-effect" | "after-effect" | "after-checkpoint";
41
+ constructor(boundary: "before-effect" | "after-effect" | "after-checkpoint");
42
+ }
43
+ export interface RecoveryMachineOptions {
44
+ readonly store: RunDispatchStore;
45
+ readonly clock?: InjectedClock;
46
+ readonly proofStore?: IdempotencyProofStore;
47
+ readonly leaseMs?: number;
48
+ readonly retryBackoff?: (attempt: number) => number;
49
+ readonly signal?: AbortSignal;
50
+ }
51
+ export interface RecoveryProcessResult {
52
+ readonly leased: number;
53
+ readonly completed: number;
54
+ readonly retried: number;
55
+ readonly deadLettered: number;
56
+ readonly cancelled: number;
57
+ }
58
+ /**
59
+ * Drives leases through safe checkpoints and terminal transitions. The caller owns the effect and
60
+ * any real idempotency ledger; this class stores only opaque proof keys in the reference adapter.
61
+ */
62
+ export declare class RunRecoveryMachine {
63
+ private readonly store;
64
+ private readonly clock;
65
+ private readonly proofs;
66
+ private readonly leaseMs;
67
+ private readonly retryBackoff;
68
+ private readonly signal;
69
+ constructor(options: RecoveryMachineOptions);
70
+ /** Cancel all matching run dispatches; every late lease write then fails closed. */
71
+ cancel(runId: string): Promise<number>;
72
+ /** Process one bounded lease batch. No payload is read or emitted by this coordinator. */
73
+ process(effect: RunEffect, options?: {
74
+ readonly limit?: number;
75
+ }): Promise<RecoveryProcessResult>;
76
+ private processLease;
77
+ private storeCheckpoint;
78
+ }
79
+ /** A small deterministic clock useful for recovery schedules and tests. */
80
+ export declare class TestClock implements InjectedClock {
81
+ private current;
82
+ constructor(start?: number);
83
+ now: () => number;
84
+ advance(milliseconds: number): void;
85
+ }
86
+ export type { DispatchResultCode };
87
+ //# sourceMappingURL=recovery.d.ts.map