footprintjs 14.1.0 → 14.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 (171) hide show
  1. package/AGENTS.md +1 -0
  2. package/README.md +2 -0
  3. package/dist/declared-attempts.js +34 -0
  4. package/dist/esm/declared-attempts.d.ts +4 -0
  5. package/dist/esm/declared-attempts.js +30 -0
  6. package/dist/esm/index.d.ts +4 -0
  7. package/dist/esm/index.js +3 -1
  8. package/dist/esm/lib/attempt/declared.d.ts +9 -0
  9. package/dist/esm/lib/attempt/declared.js +153 -0
  10. package/dist/esm/lib/attempt/evidence.d.ts +2 -0
  11. package/dist/esm/lib/attempt/evidence.js +11 -1
  12. package/dist/esm/lib/attempt/outsideInputNames.d.ts +4 -0
  13. package/dist/esm/lib/attempt/outsideInputNames.js +54 -0
  14. package/dist/esm/lib/attempt/types.d.ts +36 -0
  15. package/dist/esm/lib/attempt/types.js +1 -1
  16. package/dist/esm/lib/builder/FlowChartBuilder.d.ts +27 -42
  17. package/dist/esm/lib/builder/FlowChartBuilder.js +45 -60
  18. package/dist/esm/lib/builder/namedDeclarations.d.ts +22 -0
  19. package/dist/esm/lib/builder/namedDeclarations.js +69 -0
  20. package/dist/esm/lib/builder/types.d.ts +8 -0
  21. package/dist/esm/lib/builder/types.js +1 -1
  22. package/dist/esm/lib/engine/executionResults.d.ts +21 -0
  23. package/dist/esm/lib/engine/executionResults.js +2 -0
  24. package/dist/esm/lib/engine/graph/StageNode.d.ts +4 -0
  25. package/dist/esm/lib/engine/graph/StageNode.js +26 -1
  26. package/dist/esm/lib/engine/graph/prefixNodeTree.d.ts +1 -1
  27. package/dist/esm/lib/engine/graph/prefixNodeTree.js +3 -2
  28. package/dist/esm/lib/engine/handlers/NodeResolver.d.ts +1 -1
  29. package/dist/esm/lib/engine/handlers/NodeResolver.js +9 -9
  30. package/dist/esm/lib/engine/handlers/ParallelForEachHandler.d.ts +1 -1
  31. package/dist/esm/lib/engine/handlers/ParallelForEachHandler.js +6 -6
  32. package/dist/esm/lib/engine/handlers/ResumeEntry.d.ts +1 -1
  33. package/dist/esm/lib/engine/handlers/ResumeEntry.js +7 -3
  34. package/dist/esm/lib/engine/handlers/RuntimeStructureManager.js +5 -1
  35. package/dist/esm/lib/engine/handlers/StageRunner.js +3 -1
  36. package/dist/esm/lib/engine/handlers/SubflowExecutor.d.ts +1 -1
  37. package/dist/esm/lib/engine/handlers/SubflowExecutor.js +4 -5
  38. package/dist/esm/lib/engine/narrative/CombinedNarrativeRecorder.d.ts +1 -1
  39. package/dist/esm/lib/engine/traversal/FlowchartTraverser.js +7 -12
  40. package/dist/esm/lib/engine/traversal/continuationHop.d.ts +41 -0
  41. package/dist/esm/lib/engine/traversal/continuationHop.js +10 -0
  42. package/dist/esm/lib/engine/types.d.ts +7 -21
  43. package/dist/esm/lib/engine/types.js +2 -2
  44. package/dist/esm/lib/memory/StageContext.d.ts +12 -13
  45. package/dist/esm/lib/memory/StageContext.js +82 -129
  46. package/dist/esm/lib/memory/stageCallLifetime.d.ts +8 -0
  47. package/dist/esm/lib/memory/stageCallLifetime.js +26 -0
  48. package/dist/esm/lib/memory/stageOutsideInputs.d.ts +9 -0
  49. package/dist/esm/lib/memory/stageOutsideInputs.js +54 -0
  50. package/dist/esm/lib/memory/stageSnapshot.d.ts +49 -0
  51. package/dist/esm/lib/memory/stageSnapshot.js +100 -0
  52. package/dist/esm/lib/recorder/AttemptRecorder.d.ts +82 -0
  53. package/dist/esm/lib/recorder/AttemptRecorder.js +24 -7
  54. package/dist/esm/lib/recorder/attemptMetricRows.js +22 -1
  55. package/dist/esm/lib/recorder/attemptMetrics.d.ts +4 -1
  56. package/dist/esm/lib/recorder/attemptMetrics.js +19 -6
  57. package/dist/esm/lib/recorder/attemptMetricsTypes.d.ts +5 -0
  58. package/dist/esm/lib/recorder/attemptMetricsTypes.js +1 -1
  59. package/dist/esm/lib/recorder/attemptOTel.js +22 -12
  60. package/dist/esm/lib/runner/RunnableChart.d.ts +2 -1
  61. package/dist/esm/lib/runner/RunnableChart.js +29 -20
  62. package/dist/esm/lib/runner/describeChart.d.ts +25 -0
  63. package/dist/esm/lib/runner/describeChart.js +145 -0
  64. package/dist/esm/lib/runner/resume.js +4 -2
  65. package/dist/esm/lib/scope/ScopeFacade.d.ts +8 -2
  66. package/dist/esm/lib/scope/ScopeFacade.js +30 -15
  67. package/dist/esm/lib/sinks/fileSink.d.ts +17 -1
  68. package/dist/esm/lib/sinks/fileSink.js +136 -67
  69. package/dist/esm/lib/sinks/indexedAdmission.d.ts +6 -1
  70. package/dist/esm/lib/sinks/indexedAdmission.js +30 -7
  71. package/dist/esm/lib/sinks/indexedIO.js +4 -2
  72. package/dist/esm/lib/sinks/indexedRecordFile.js +29 -108
  73. package/dist/esm/lib/sinks/indexedScan.js +3 -9
  74. package/dist/esm/lib/sinks/indexedSession.d.ts +29 -0
  75. package/dist/esm/lib/sinks/indexedSession.js +105 -0
  76. package/dist/esm/lib/sinks/publishedRecordFile.d.ts +40 -0
  77. package/dist/esm/lib/sinks/publishedRecordFile.js +106 -0
  78. package/dist/esm/lib/sinks/publishedRecordIndex.d.ts +8 -0
  79. package/dist/esm/lib/sinks/publishedRecordIndex.js +98 -0
  80. package/dist/esm/lib/sinks/publishedRecordRows.d.ts +13 -0
  81. package/dist/esm/lib/sinks/publishedRecordRows.js +188 -0
  82. package/dist/esm/lib/sinks/publishedRecordSelection.d.ts +21 -0
  83. package/dist/esm/lib/sinks/publishedRecordSelection.js +69 -0
  84. package/dist/esm/lib/sinks/publishedRecordWriter.d.ts +49 -0
  85. package/dist/esm/lib/sinks/publishedRecordWriter.js +237 -0
  86. package/dist/esm/sinks.d.ts +5 -0
  87. package/dist/esm/sinks.js +3 -1
  88. package/dist/index.js +7 -3
  89. package/dist/lib/attempt/declared.js +158 -0
  90. package/dist/lib/attempt/evidence.js +13 -2
  91. package/dist/lib/attempt/outsideInputNames.js +59 -0
  92. package/dist/lib/attempt/types.js +1 -1
  93. package/dist/lib/builder/FlowChartBuilder.js +59 -74
  94. package/dist/lib/builder/namedDeclarations.js +74 -0
  95. package/dist/lib/builder/types.js +1 -1
  96. package/dist/lib/engine/executionResults.js +3 -0
  97. package/dist/lib/engine/graph/StageNode.js +28 -2
  98. package/dist/lib/engine/graph/prefixNodeTree.js +3 -2
  99. package/dist/lib/engine/handlers/NodeResolver.js +9 -9
  100. package/dist/lib/engine/handlers/ParallelForEachHandler.js +6 -6
  101. package/dist/lib/engine/handlers/ResumeEntry.js +7 -3
  102. package/dist/lib/engine/handlers/RuntimeStructureManager.js +5 -1
  103. package/dist/lib/engine/handlers/StageRunner.js +3 -1
  104. package/dist/lib/engine/handlers/SubflowExecutor.js +4 -5
  105. package/dist/lib/engine/traversal/FlowchartTraverser.js +10 -15
  106. package/dist/lib/engine/traversal/continuationHop.js +14 -0
  107. package/dist/lib/engine/types.js +2 -2
  108. package/dist/lib/memory/StageContext.js +97 -144
  109. package/dist/lib/memory/stageCallLifetime.js +31 -0
  110. package/dist/lib/memory/stageOutsideInputs.js +62 -0
  111. package/dist/lib/memory/stageSnapshot.js +105 -0
  112. package/dist/lib/recorder/AttemptRecorder.js +23 -6
  113. package/dist/lib/recorder/attemptMetricRows.js +22 -1
  114. package/dist/lib/recorder/attemptMetrics.js +22 -7
  115. package/dist/lib/recorder/attemptMetricsTypes.js +1 -1
  116. package/dist/lib/recorder/attemptOTel.js +21 -11
  117. package/dist/lib/runner/RunnableChart.js +29 -20
  118. package/dist/lib/runner/describeChart.js +150 -0
  119. package/dist/lib/runner/resume.js +4 -2
  120. package/dist/lib/scope/ScopeFacade.js +29 -14
  121. package/dist/lib/sinks/fileSink.js +140 -68
  122. package/dist/lib/sinks/indexedAdmission.js +34 -8
  123. package/dist/lib/sinks/indexedIO.js +4 -2
  124. package/dist/lib/sinks/indexedRecordFile.js +28 -107
  125. package/dist/lib/sinks/indexedScan.js +2 -8
  126. package/dist/lib/sinks/indexedSession.js +109 -0
  127. package/dist/lib/sinks/publishedRecordFile.js +110 -0
  128. package/dist/lib/sinks/publishedRecordIndex.js +103 -0
  129. package/dist/lib/sinks/publishedRecordRows.js +192 -0
  130. package/dist/lib/sinks/publishedRecordSelection.js +75 -0
  131. package/dist/lib/sinks/publishedRecordWriter.js +241 -0
  132. package/dist/sinks.js +6 -2
  133. package/dist/types/declared-attempts.d.ts +4 -0
  134. package/dist/types/index.d.ts +4 -0
  135. package/dist/types/lib/attempt/declared.d.ts +9 -0
  136. package/dist/types/lib/attempt/evidence.d.ts +2 -0
  137. package/dist/types/lib/attempt/outsideInputNames.d.ts +4 -0
  138. package/dist/types/lib/attempt/types.d.ts +36 -0
  139. package/dist/types/lib/builder/FlowChartBuilder.d.ts +27 -42
  140. package/dist/types/lib/builder/namedDeclarations.d.ts +22 -0
  141. package/dist/types/lib/builder/types.d.ts +8 -0
  142. package/dist/types/lib/engine/executionResults.d.ts +21 -0
  143. package/dist/types/lib/engine/graph/StageNode.d.ts +4 -0
  144. package/dist/types/lib/engine/graph/prefixNodeTree.d.ts +1 -1
  145. package/dist/types/lib/engine/handlers/NodeResolver.d.ts +1 -1
  146. package/dist/types/lib/engine/handlers/ParallelForEachHandler.d.ts +1 -1
  147. package/dist/types/lib/engine/handlers/ResumeEntry.d.ts +1 -1
  148. package/dist/types/lib/engine/handlers/SubflowExecutor.d.ts +1 -1
  149. package/dist/types/lib/engine/narrative/CombinedNarrativeRecorder.d.ts +1 -1
  150. package/dist/types/lib/engine/traversal/continuationHop.d.ts +41 -0
  151. package/dist/types/lib/engine/types.d.ts +7 -21
  152. package/dist/types/lib/memory/StageContext.d.ts +12 -13
  153. package/dist/types/lib/memory/stageCallLifetime.d.ts +8 -0
  154. package/dist/types/lib/memory/stageOutsideInputs.d.ts +9 -0
  155. package/dist/types/lib/memory/stageSnapshot.d.ts +49 -0
  156. package/dist/types/lib/recorder/AttemptRecorder.d.ts +82 -0
  157. package/dist/types/lib/recorder/attemptMetrics.d.ts +4 -1
  158. package/dist/types/lib/recorder/attemptMetricsTypes.d.ts +5 -0
  159. package/dist/types/lib/runner/RunnableChart.d.ts +2 -1
  160. package/dist/types/lib/runner/describeChart.d.ts +25 -0
  161. package/dist/types/lib/scope/ScopeFacade.d.ts +8 -2
  162. package/dist/types/lib/sinks/fileSink.d.ts +17 -1
  163. package/dist/types/lib/sinks/indexedAdmission.d.ts +6 -1
  164. package/dist/types/lib/sinks/indexedSession.d.ts +29 -0
  165. package/dist/types/lib/sinks/publishedRecordFile.d.ts +40 -0
  166. package/dist/types/lib/sinks/publishedRecordIndex.d.ts +8 -0
  167. package/dist/types/lib/sinks/publishedRecordRows.d.ts +13 -0
  168. package/dist/types/lib/sinks/publishedRecordSelection.d.ts +21 -0
  169. package/dist/types/lib/sinks/publishedRecordWriter.d.ts +49 -0
  170. package/dist/types/sinks.d.ts +5 -0
  171. package/package.json +17 -3
@@ -101,6 +101,8 @@ export interface SerializedPipelineStructure {
101
101
  * `retryAttempts`: `.tag()` is chained AFTER `onStageAdded` fires.
102
102
  */
103
103
  tags?: readonly string[];
104
+ /** Public names of outside inputs this stage declares, absent when undeclared. */
105
+ outsideInputs?: readonly string[];
104
106
  /**
105
107
  * STRUCTURE-ONLY: for a fork/selector/decider branch, the downstream stage
106
108
  * id its convergence `next` edge points to, instead of the shared next-stage
@@ -147,6 +149,8 @@ export interface FlowChartSpec {
147
149
  touches?: string;
148
150
  /** Declared tags on this stage, as-is (see `SerializedPipelineStructure.tags`). */
149
151
  tags?: readonly string[];
152
+ /** Public names of outside inputs declared on this stage. */
153
+ outsideInputs?: readonly string[];
150
154
  }
151
155
  /**
152
156
  * Options-bag argument shape for the `flowChart()` factory.
@@ -195,6 +199,8 @@ export interface FlowChartOptions {
195
199
  * recording carries its own milestones. See `FlowChartBuilder.tag`.
196
200
  */
197
201
  tags?: readonly string[];
202
+ /** Public names of outside inputs the chart's first stage takes. */
203
+ outsideInputs?: readonly string[];
198
204
  }
199
205
  export type FlowChart<TOut = any, TScope = any> = {
200
206
  root: StageNode<TOut, TScope>;
@@ -227,6 +233,8 @@ export type SimplifiedParallelSpec<TOut = any, TScope = any> = {
227
233
  touches?: StageTouches;
228
234
  /** Declared tags for this fork child — each child's bundle carries its own. */
229
235
  tags?: readonly string[];
236
+ /** Public names of outside inputs this fork child takes. */
237
+ outsideInputs?: readonly string[];
230
238
  };
231
239
  export type ExecOptions = {
232
240
  defaults?: unknown;
@@ -0,0 +1,21 @@
1
+ import type { FlowchartCheckpoint } from '../pause/types.js';
2
+ export type NodeResultType = {
3
+ id: string;
4
+ result: unknown;
5
+ isError?: boolean;
6
+ };
7
+ export type BranchResult = {
8
+ result: string | Error;
9
+ isError: boolean;
10
+ };
11
+ export type BranchResults = {
12
+ [branchId: string]: BranchResult;
13
+ };
14
+ export type TraversalResult = BranchResults | string | Error;
15
+ /** Returned by run()/resume() when execution pauses. */
16
+ export type PausedResult = {
17
+ readonly paused: true;
18
+ readonly checkpoint: FlowchartCheckpoint;
19
+ };
20
+ /** Full return type of FlowChartExecutor.run() and resume(). */
21
+ export type ExecutorResult = TraversalResult | PausedResult;
@@ -108,6 +108,8 @@ export type StageNode<TOut = any, TScope = any> = {
108
108
  * branch-segment marker. See `FlowChartBuilder.tag`.
109
109
  */
110
110
  tags?: readonly string[];
111
+ /** Public names declared by the author for this stage's outside inputs. */
112
+ outsideInputs?: readonly string[];
111
113
  /** When true, this stage can pause execution (PausableHandler pattern). */
112
114
  isPausable?: boolean;
113
115
  /** Resume function — called instead of fn when resuming a paused stage. */
@@ -150,3 +152,5 @@ export type StageNode<TOut = any, TScope = any> = {
150
152
  * Safely handles proxy objects (e.g., Zod scope) that may throw on property access.
151
153
  */
152
154
  export declare function isStageNodeReturn(output: unknown): output is StageNode;
155
+ /** Shallow spread semantics, with outside-input evidence taken only from an own data slot. */
156
+ export declare function copyStageNode<N extends StageNode>(node: N): N;
@@ -22,5 +22,5 @@
22
22
  * `child.branchId ?? child.id`. The input is never mutated (each node is a
23
23
  * shallow clone).
24
24
  */
25
- import type { StageNode } from './StageNode.js';
25
+ import { type StageNode } from './StageNode.js';
26
26
  export declare function prefixNodeTree<N extends StageNode<any, any>>(node: N, prefix: string): N;
@@ -5,7 +5,7 @@
5
5
  * - Find nodes by ID via recursive depth-first search (for back-edge/loop support)
6
6
  * - Resolve subflow reference nodes to actual subflow structures
7
7
  */
8
- import type { StageNode } from '../graph/StageNode.js';
8
+ import { type StageNode } from '../graph/StageNode.js';
9
9
  import type { HandlerDeps } from '../types.js';
10
10
  export declare class NodeResolver<TOut = any, TScope = any> {
11
11
  private deps;
@@ -1,5 +1,5 @@
1
1
  import type { StageContext } from '../../memory/StageContext.js';
2
- import type { StageNode } from '../graph/StageNode.js';
2
+ import { type StageNode } from '../graph/StageNode.js';
3
3
  import type { TraversalContext } from '../narrative/types.js';
4
4
  import type { BranchChart, HandlerDeps } from '../types.js';
5
5
  import type { ChildrenExecutor } from './ChildrenExecutor.js';
@@ -63,7 +63,7 @@
63
63
  */
64
64
  import type { PendingPause } from '../../pause/types.js';
65
65
  import { PauseSignal } from '../../pause/types.js';
66
- import type { StageNode } from '../graph/StageNode.js';
66
+ import { type StageNode } from '../graph/StageNode.js';
67
67
  /**
68
68
  * A parallel sibling's pause, queued at the level of its fan-out: raised
69
69
  * again there once the resumed child's chain ends (see {@link raiseQueuedPause}).
@@ -1,5 +1,5 @@
1
1
  import type { StageContext } from '../../memory/StageContext.js';
2
- import type { StageNode } from '../graph/StageNode.js';
2
+ import { type StageNode } from '../graph/StageNode.js';
3
3
  import type { TraversalContext } from '../narrative/types.js';
4
4
  import type { HandlerDeps, ReturnedSubflowDefinition, SubflowResult, SubflowTraverserFactory } from '../types.js';
5
5
  import type { BreakFlag } from './types.js';
@@ -183,7 +183,7 @@ export declare class CombinedNarrativeRecorder implements CombinedRecorder {
183
183
  runtimeStageId?: string | undefined;
184
184
  stepNumber?: number | undefined;
185
185
  subflowId?: string | undefined;
186
- direction?: "exit" | "entry" | undefined;
186
+ direction?: "entry" | "exit" | undefined;
187
187
  key?: string | undefined;
188
188
  }[];
189
189
  };
@@ -0,0 +1,41 @@
1
+ import type { StageContext } from '../../memory/StageContext.js';
2
+ import type { StageNode } from '../types.js';
3
+ /**
4
+ * Trampoline brand — marks a continuation hop returned by `executeNodeStep`
5
+ * to the driver loop in `executeNode`. Internal engine symbol so a stage's own
6
+ * return value (which can be any object) can never be mistaken for a hop.
7
+ */
8
+ export declare const CONTINUE_HOP: unique symbol;
9
+ /**
10
+ * A flat continuation — "execute this node next, in this context" — returned
11
+ * by `executeNodeStep` for every TAIL continuation (linear `next`, loop
12
+ * edges, dynamic next, dynamic-subflow re-entry, no-continuation decider
13
+ * dispatch). The driver loop in `executeNode` consumes hops iteratively:
14
+ * `current = hop; continue;` — so neither the call stack nor the retained
15
+ * promise chain grows with chain length or loop iterations.
16
+ */
17
+ export interface ContinuationHop<TOut = any, TScope = any> {
18
+ readonly [CONTINUE_HOP]: true;
19
+ readonly node: StageNode<TOut, TScope>;
20
+ readonly context: StageContext;
21
+ readonly branchPath: string | undefined;
22
+ /**
23
+ * Present when the hop is a decider's branch dispatch (decider without its
24
+ * own `next`). The driver records it so a PauseSignal thrown anywhere in
25
+ * the continued chain still gets the decider stamped as its invoker —
26
+ * exactly what the recursive dispatch's catch used to do.
27
+ */
28
+ readonly invokerStamp?: InvokerStamp;
29
+ /**
30
+ * Present when the hop follows a LOOP edge (a back-reference resolved by
31
+ * `ContinuationResolver`). A decider's branch frame hands such a hop back
32
+ * to its decider when the target is not a node the frame ran, so the loop
33
+ * re-enters at the target's own level — flat, never one frame per pass.
34
+ */
35
+ readonly loop?: true;
36
+ }
37
+ /** Pause-invoker context recorded by the driver for flat decider dispatches. */
38
+ export interface InvokerStamp {
39
+ readonly invokerStageId: string;
40
+ }
41
+ export declare function isContinuationHop<TOut, TScope>(value: unknown): value is ContinuationHop<TOut, TScope>;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * types.ts — All type definitions for the engine library.
2
+ * types.ts — Type definitions and re-exports for the engine library.
3
3
  *
4
4
  * Centralizes type definitions to avoid circular dependencies.
5
5
  * Every handler receives HandlerDeps (the DI bag) instead of importing the traverser.
@@ -10,6 +10,7 @@ import type { FlowControlType, FlowMessage } from '../memory/frameTypes.js';
10
10
  import type { NativeMappingBinding } from '../memory/RunFrame.js';
11
11
  import type { StageContext } from '../memory/StageContext.js';
12
12
  import type { ScopeProtectionMode } from '../scope/protection/types.js';
13
+ import type { TraversalResult } from './executionResults.js';
13
14
  import type { StageNode } from './graph/StageNode.js';
14
15
  import type { QueuedPause, ResumeEntry } from './handlers/ResumeEntry.js';
15
16
  import type { IControlFlowNarrative } from './narrative/types.js';
@@ -248,6 +249,8 @@ export interface SubflowMountOptions<TParentScope = any, TSubflowInput = any, TS
248
249
  * ```
249
250
  */
250
251
  tags?: readonly string[];
252
+ /** Public names of outside inputs the mount itself takes. Inner stages declare their own. */
253
+ outsideInputs?: readonly string[];
251
254
  }
252
255
  export interface SubflowResult {
253
256
  subflowId: string;
@@ -581,26 +584,7 @@ export interface RuntimeStructureMetadata {
581
584
  isLoopReference?: boolean;
582
585
  streamId?: string;
583
586
  }
584
- export type NodeResultType = {
585
- id: string;
586
- result: unknown;
587
- isError?: boolean;
588
- };
589
- export type BranchResult = {
590
- result: string | Error;
591
- isError: boolean;
592
- };
593
- export type BranchResults = {
594
- [branchId: string]: BranchResult;
595
- };
596
- export type TraversalResult = BranchResults | string | Error;
597
- /** Returned by run()/resume() when execution pauses. */
598
- export type PausedResult = {
599
- readonly paused: true;
600
- readonly checkpoint: import('../pause/types.js').FlowchartCheckpoint;
601
- };
602
- /** Full return type of FlowChartExecutor.run() and resume(). */
603
- export type ExecutorResult = TraversalResult | PausedResult;
587
+ export type { BranchResult, BranchResults, ExecutorResult, NodeResultType, PausedResult, TraversalResult, } from './executionResults.js';
604
588
  export interface SerializedPipelineNode {
605
589
  name: string;
606
590
  id: string;
@@ -644,6 +628,8 @@ export interface SerializedPipelineNode {
644
628
  * Absent when the stage declares none.
645
629
  */
646
630
  tags?: readonly string[];
631
+ /** Public names of outside inputs declared on this stage. */
632
+ outsideInputs?: readonly string[];
647
633
  }
648
634
  /** Alias for SerializedPipelineNode used as full structure */
649
635
  export type SerializedPipelineStructure = SerializedPipelineNode & {
@@ -13,7 +13,7 @@
13
13
  */
14
14
  import type { CommitPhase, EmitSourcePosition, UntrackedSource } from 'foottrace';
15
15
  import type { EventLog, SharedMemory } from 'foottrace/write';
16
- import type { AttemptContext, AttemptRecord, AttemptSummary, LateWrite } from '../attempt/types.js';
16
+ import type { AttemptContext, AttemptRecord, AttemptSummary, DeclaredWrite, DeclaredWriteObserver, LateWrite } from '../attempt/types.js';
17
17
  import type { NativeCapture } from '../capture/nativeCoverage.js';
18
18
  import type { NativeExtent } from '../capture/nativeExtent/collector.js';
19
19
  import type { EngineReadSourceCapture } from '../capture/readSources.js';
@@ -220,6 +220,10 @@ export declare class StageContext {
220
220
  /** Value-free, execution-local observation of successfully staged write addresses. */
221
221
  private _stagedWriteObserver?;
222
222
  private _writeBoundaryObserver?;
223
+ /** Only the active native stage body may start or stage a dispatch. */
224
+ get declaredInvocationOpen(): boolean;
225
+ endDeclaredAttemptInvocation(): void;
226
+ useDeclaredWrites(observer: DeclaredWriteObserver): void;
223
227
  /** @internal Observe one mapper's writes without changing the record's encoding or reads. */
224
228
  observeStagedWrites(observer: (path: readonly string[]) => void, boundary?: (phase: 'committing' | 'landed') => void): () => void;
225
229
  constructor(runId: string, name: string, stageId: string, sharedMemory: SharedMemory, branchId?: string, eventLog?: EventLog, isDecider?: boolean);
@@ -361,7 +365,7 @@ export declare class StageContext {
361
365
  patch(path: string[], key: string, value: unknown, shouldRedact?: boolean): RedactionVerdict;
362
366
  set(path: string[], key: string, value: unknown): void;
363
367
  merge(path: string[], key: string, value: unknown, shouldRedact?: boolean): RedactionVerdict;
364
- setObject(path: string[], key: string, value: unknown, shouldRedact?: boolean, description?: string, operationOverride?: 'set' | 'delete'): RedactionVerdict;
368
+ setObject(path: string[], key: string, value: unknown, shouldRedact?: boolean, description?: string, operationOverride?: 'set' | 'delete', declared?: readonly DeclaredWrite[]): RedactionVerdict;
365
369
  updateObject(path: string[], key: string, value: unknown, description?: string, shouldRedact?: boolean): RedactionVerdict;
366
370
  setRoot(key: string, value: unknown): void;
367
371
  /** Root-level (un-namespaced) write — the subflow seed and merge-back path. */
@@ -582,9 +586,9 @@ export declare class StageContext {
582
586
  * context via `leaf.createNext`) never re-use a committed context.
583
587
  * - A USER handle held past its stage is a different matter: its writes
584
588
  * would land in a buffer nothing ever commits. That refusal lives on the
585
- * scope tier (`ScopeFacade`, sealed by the commit observer — 9.22.0),
586
- * because the frame's re-usability is exactly what the engine paths
587
- * above need.
589
+ * scope tier (`ScopeFacade`, sealed at the commit stamp for declared
590
+ * writes, otherwise by the commit observer). The engine paths above
591
+ * still need a reusable frame.
588
592
  * - `_stageWrites` / `_stageReads` are NOT released — `snapshotSelf()`
589
593
  * reads them post-run for the execution-tree snapshot.
590
594
  */
@@ -696,13 +700,7 @@ export declare class StageContext {
696
700
  get hasKeylessEffect(): boolean;
697
701
  /** Where this execution's call records are reported — the engine sets it before the stage runs. */
698
702
  useAttemptReporter(report: ((record: AttemptRecord, structuredError: StructuredErrorInfo | undefined) => void) | undefined): void;
699
- /**
700
- * The signal the calls of stage attempt `stageAttempt` run under besides its own (P2): aborted when that attempt is
701
- * over — however it ended — and when the frame commits, so no call outlives the attempt that made it (no
702
- * background retry, no wait, no listener left on the run's signal). Already aborted after the commit.
703
- */
704
703
  callsEndedSignal(stageAttempt: number): AbortSignal;
705
- /** End the calls of `stageAttempt` (every attempt's when `undefined`) — `reason` when the attempt's signal gave one. */
706
704
  private endCalls;
707
705
  /** The next call's ordinal within stage attempt `stageAttempt`, 1-based (`attempt/call.ts · callSeries`). */
708
706
  nextCallOrdinal(stageAttempt: number): number;
@@ -710,8 +708,9 @@ export declare class StageContext {
710
708
  * A call's (or an observed) attempt record: kept beside the stage's own attempts — the first
711
709
  * {@link MAX_CALL_RECORDS}, the rest counted — and reported to the run's `onAttempt` either way. Like the stage's
712
710
  * records, NOT cleared by {@link discardStaged}: a failed attempt's calls are evidence too.
711
+ * Only the native reporter can pair a retained row with the attempt whose callback began.
713
712
  */
714
- reportCallAttempt(record: AttemptRecord, structuredError: StructuredErrorInfo | undefined, evidence?: Readonly<Record<string, unknown>>): void;
713
+ reportCallAttempt(record: AttemptRecord, structuredError: StructuredErrorInfo | undefined, evidence?: Readonly<Record<string, unknown>>, nativeCallStarted?: boolean): void;
715
714
  /**
716
715
  * Create (or return) this context's linked successor.
717
716
  *
@@ -744,7 +743,7 @@ export declare class StageContext {
744
743
  }): void;
745
744
  getStageId(): string;
746
745
  getSnapshot(redaction?: RedactionRule | undefined): StageSnapshot;
747
- /** This frame's fields, before the execution walk links its successors. */
746
+ /** Keep the existing prototype slot pinned by the read-authority key checks. */
748
747
  private snapshotSelf;
749
748
  }
750
749
  export declare const observeOwnedContext: (owner: unknown) => boolean | undefined;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * The signal the calls of stage attempt `stageAttempt` run under besides its own (P2): aborted when that attempt is
3
+ * over — however it ended — and when the frame commits, so no call outlives the attempt that made it (no
4
+ * background retry, no wait, no listener left on the run's signal). Already aborted after the commit.
5
+ */
6
+ export declare function callEndSignal(ended: Map<number, AbortController>, stageAttempt: number, committed: boolean): AbortSignal;
7
+ /** End the calls of `stageAttempt` (every attempt's when `undefined`) — `reason` when the attempt's signal gave one. */
8
+ export declare function endCallsFor(ended: Map<number, AbortController>, stageAttempt: number | undefined, reason?: unknown): void;
@@ -0,0 +1,9 @@
1
+ import type { OutsideInputs } from 'foottrace';
2
+ import type { StageContext } from './StageContext.js';
3
+ export declare function setDeclaredOutsideInputs(frame: StageContext, declared: readonly string[] | undefined): void;
4
+ /** Called before each native attempt invokes host work. A stage retry does not erase the earlier starts. */
5
+ export declare function noteNativeCallStarted(frame: StageContext): void;
6
+ /** Only a native callback's own row in the existing attempt budget can supply a target. */
7
+ export declare function recordNativeCallTarget(frame: StageContext, target: string): void;
8
+ export declare function outsideInputStamp(frame: StageContext): OutsideInputs | undefined;
9
+ export declare function clearOutsideInputs(frame: StageContext): void;
@@ -0,0 +1,49 @@
1
+ import type { AttemptRecord, AttemptSummary, LateWrite } from '../attempt/types.js';
2
+ import { type SourceReadCounter } from '../capture/sourceReadCounts.js';
3
+ import type { StageAttention } from './attention.js';
4
+ import type { DiagnosticCollector } from './DiagnosticCollector.js';
5
+ import type { StageSnapshot } from './frameTypes.js';
6
+ import type { RedactionRule } from './redaction.js';
7
+ type SnapshotFrame = {
8
+ readonly stageId: string;
9
+ readonly runtimeStageId: string;
10
+ readonly stageName: string;
11
+ readonly isDecider: boolean;
12
+ readonly isFork: boolean;
13
+ readonly description?: string;
14
+ readonly subflowId?: string;
15
+ readonly debug: Pick<DiagnosticCollector, 'logContext' | 'errorContext' | 'metricContext' | 'evalContext' | 'flowMessages'>;
16
+ readonly readSources?: {
17
+ readonly observing: boolean;
18
+ };
19
+ readonly captureClosureTracking?: boolean;
20
+ };
21
+ type SnapshotLinks<Frame> = {
22
+ readonly next?: Frame;
23
+ readonly children?: readonly Frame[];
24
+ };
25
+ /** Read retained frame data at the point it is used, including through pending-write projection. */
26
+ export type StageSnapshotInputs<Frame> = {
27
+ sourceReadCounter(frame: Frame): Pick<SourceReadCounter, 'snapshot'> | undefined;
28
+ sourceInvocations(frame: Frame): number;
29
+ closureInvocations(frame: Frame): {
30
+ readonly count: number;
31
+ } | undefined;
32
+ retainedWrites(frame: Frame): Readonly<Record<string, {
33
+ readonly value: unknown;
34
+ }>>;
35
+ stageReads(frame: Frame): Readonly<Record<string, unknown>>;
36
+ unsetNestedReads(frame: Frame): ReadonlyMap<string, {
37
+ readonly path: readonly string[];
38
+ readonly key: string;
39
+ }> | undefined;
40
+ attempts(frame: Frame): readonly AttemptRecord[] | undefined;
41
+ attemptSummary(frame: Frame): AttemptSummary | undefined;
42
+ lateWrites(frame: Frame): readonly LateWrite[] | undefined;
43
+ attemptsDropped(frame: Frame): number;
44
+ attention(frame: Frame): Pick<StageAttention, 'snapshot'> | undefined;
45
+ };
46
+ export declare function buildStageSnapshotTree<Frame extends SnapshotLinks<Frame>>(rootFrame: Frame, redaction: RedactionRule | undefined, project: (frame: Frame, rule: RedactionRule | undefined) => StageSnapshot): StageSnapshot;
47
+ /** This frame's fields, before the execution walk links its successors. */
48
+ export declare function buildStageSnapshot<Frame extends SnapshotFrame>(frame: Frame, inputs: StageSnapshotInputs<Frame>, rule: RedactionRule | undefined): StageSnapshot;
49
+ export {};
@@ -34,6 +34,7 @@ export declare class AttemptRecorder implements FlowRecorder {
34
34
  decisions: AttemptDecisionRow[];
35
35
  };
36
36
  aggregate(supplied?: AttemptQuery): Promise<AttemptAggregate>;
37
+ private readAggregate;
37
38
  private readStored;
38
39
  toSnapshot(): {
39
40
  name: string;
@@ -127,6 +128,87 @@ export declare class AttemptRecorder implements FlowRecorder {
127
128
  }[];
128
129
  }[];
129
130
  };
131
+ /** Export admitted OTLP metrics and their storage accounting after reload. */
132
+ toStoredOTel(supplied?: AttemptQuery): Promise<{
133
+ metrics: {
134
+ resourceMetrics: {
135
+ resource: {
136
+ attributes: never[];
137
+ };
138
+ scopeMetrics: {
139
+ scope: {
140
+ name: string;
141
+ };
142
+ metrics: ({
143
+ name: string;
144
+ unit: string;
145
+ description: string;
146
+ histogram: {
147
+ aggregationTemporality: number;
148
+ dataPoints: {
149
+ attributes: {
150
+ key: string;
151
+ value: {
152
+ stringValue: string;
153
+ };
154
+ }[];
155
+ startTimeUnixNano: string;
156
+ timeUnixNano: string;
157
+ count: string;
158
+ sum: number;
159
+ explicitBounds: number[];
160
+ bucketCounts: string[];
161
+ exemplars: {
162
+ traceId?: string | undefined;
163
+ asDouble: number;
164
+ timeUnixNano: string;
165
+ filteredAttributes: {
166
+ key: string;
167
+ value: {
168
+ stringValue: string;
169
+ };
170
+ }[];
171
+ }[];
172
+ }[];
173
+ };
174
+ sum?: undefined;
175
+ } | {
176
+ name: string;
177
+ unit: string;
178
+ sum: {
179
+ aggregationTemporality: number;
180
+ isMonotonic: boolean;
181
+ dataPoints: {
182
+ attributes: {
183
+ key: string;
184
+ value: {
185
+ stringValue: string;
186
+ };
187
+ }[];
188
+ startTimeUnixNano: string;
189
+ timeUnixNano: string;
190
+ asDouble: number;
191
+ exemplars: {
192
+ asDouble: number;
193
+ traceId?: string | undefined;
194
+ timeUnixNano: string;
195
+ filteredAttributes: {
196
+ key: string;
197
+ value: {
198
+ stringValue: string;
199
+ };
200
+ }[];
201
+ }[];
202
+ }[];
203
+ };
204
+ description?: undefined;
205
+ histogram?: undefined;
206
+ })[];
207
+ }[];
208
+ }[];
209
+ };
210
+ storage: AttemptStorageStats;
211
+ }>;
130
212
  /** Clear completed local projections; active/paused evidence and bounded ownership survive executor auto-clear. */
131
213
  clear(): void;
132
214
  }
@@ -1,7 +1,10 @@
1
- import type { AttemptAggregate, AttemptMetricRef, AttemptRow, AttemptStorageStats, PhysicalAttemptRow } from './attemptMetricsTypes.js';
1
+ import type { AttemptAggregate, AttemptFailureProvenance, AttemptMetricRef, AttemptRow, AttemptStorageStats, PhysicalAttemptRow } from './attemptMetricsTypes.js';
2
2
  export declare const attemptRowKey: (row: AttemptRow) => string;
3
3
  export declare const logicalKey: (runId: string, series: string, attempt: number) => string;
4
4
  export declare const seriesKey: (runId: string, series: string) => string;
5
+ export declare const latestAttemptRows: (rows: readonly AttemptRow[]) => AttemptRow[];
6
+ /** A legacy category is usable, but its origin was never recorded. */
7
+ export declare function failureProvenance(row: PhysicalAttemptRow): AttemptFailureProvenance | undefined;
5
8
  export declare function reference(row: PhysicalAttemptRow): AttemptMetricRef;
6
9
  export declare function worst(rows: readonly PhysicalAttemptRow[], limit: number): AttemptMetricRef[];
7
10
  export declare function aggregateAttempts(rows: readonly AttemptRow[], exemplars: number, storage: AttemptStorageStats): AttemptAggregate;
@@ -2,6 +2,8 @@
2
2
  import type { AttemptId } from 'foottrace';
3
3
  import type { RetryLoopCall, RetryLoopDecision } from '../attempt/retryLoopTypes.js';
4
4
  import type { AttemptCategory, AttemptEffect, AttemptKind, AttemptNext, AttemptOutcome, AttemptReason } from '../attempt/types.js';
5
+ /** How the recorded failure category was obtained. Older rows may lack this fact. */
6
+ export type AttemptFailureProvenance = 'declared' | 'classified' | 'unknown';
5
7
  export interface AttemptMetricRef {
6
8
  readonly id: AttemptId;
7
9
  readonly series: string;
@@ -15,6 +17,7 @@ export interface AttemptMetricRef {
15
17
  readonly durationMs: number;
16
18
  readonly outcome: AttemptOutcome;
17
19
  readonly category?: AttemptCategory;
20
+ readonly provenance?: AttemptFailureProvenance;
18
21
  readonly next: AttemptNext;
19
22
  readonly reason: AttemptReason;
20
23
  }
@@ -69,6 +72,8 @@ export interface AttemptStats {
69
72
  readonly byKind: Record<AttemptKind, number>;
70
73
  readonly byOutcome: Record<AttemptOutcome, number>;
71
74
  readonly byCategory: Record<AttemptCategory, number>;
75
+ /** A breakdown for each category present in the result. */
76
+ readonly byCategoryProvenance: Readonly<Partial<Record<AttemptCategory, Readonly<Record<AttemptFailureProvenance, number>>>>>;
72
77
  readonly retries: number;
73
78
  readonly seriesRetried: number;
74
79
  readonly gaveUp: number;
@@ -63,7 +63,8 @@ export interface RunnableFlowChart<TOut = any, TScope = any> extends FlowChart<T
63
63
  }
64
64
  /**
65
65
  * Draw the default `flowchart TD` from a chart root. Declare each node once and draw every edge.
66
- * A loop-reference stub supplies only its back-edge. Labels escape quotes as `#quot;`.
66
+ * A loop-reference stub points to the first placement of its target ID, as the engine's loop lookup does.
67
+ * Labels escape quotes as `#quot;`.
67
68
  * IDs use `[A-Za-z0-9_]`; collisions get `_2`, `_3`, and so on in encounter order.
68
69
  */
69
70
  export declare function chartToMermaid(root: StageNode): string;
@@ -0,0 +1,25 @@
1
+ import type { FlowChart } from '../builder/types.js';
2
+ import type { RunnableFlowChart } from './RunnableChart.js';
3
+ /** One declared subflow placement, with a chart-local path suitable for a documentation index. */
4
+ export interface ChartMount {
5
+ readonly subflowId: string;
6
+ readonly subflowName: string;
7
+ /** Slash-separated mount IDs from the chart being described. */
8
+ readonly subflowPath: string;
9
+ readonly isLazy: boolean;
10
+ /** Entry stage of an eagerly mounted chart, when its structure is present. */
11
+ readonly entryStageId?: string;
12
+ /** Description declared on the mount or its eager entry stage. */
13
+ readonly description?: string;
14
+ }
15
+ /**
16
+ * List mount placements in graph order, descending into each eager mount.
17
+ * Lazy mounts appear without resolving them. Runtime fan-out creates its branches during a run.
18
+ */
19
+ export declare function listMounts(chart: Pick<FlowChart, 'buildTimeStructure'>): readonly ChartMount[];
20
+ /**
21
+ * Generate a Markdown README for one built chart. The drawing uses the chart's
22
+ * default Mermaid export. Stage and loop details describe this chart, with eager
23
+ * child charts represented by their mounts. No stage or lazy resolver is called.
24
+ */
25
+ export declare function describeChart(chart: Pick<RunnableFlowChart, 'buildTimeStructure' | 'description' | 'toMermaid'>): string;
@@ -1,4 +1,5 @@
1
- import type { AttemptContext, AttemptError, CallOptions, RetryPolicy, RunCorrelation } from '../attempt/types.js';
1
+ import type { DeclaredFailureOwner } from '../attempt/declared.js';
2
+ import type { AttemptContext, AttemptError, CallOptions, DeclaredWrite, RetryPolicy, RunCorrelation } from '../attempt/types.js';
2
3
  import type { FlowChart } from '../builder/types.js';
3
4
  import type { DetachDriver, DetachHandle } from '../detach/types.js';
4
5
  import type { ExecutionEnv } from '../engine/types.js';
@@ -163,6 +164,11 @@ export declare class ScopeFacade {
163
164
  * ```
164
165
  */
165
166
  getAttempt(): AttemptContext;
167
+ /** @internal For the optional declared-attempts entry point. */
168
+ declaredFailureOwner(): DeclaredFailureOwner & {
169
+ readonly context: StageContext;
170
+ sealScope(): void;
171
+ };
166
172
  /**
167
173
  * A call to an outside system, made inside this stage — `scope.$call(target, fn, policy?)` (design §3.6, P2).
168
174
  * `fn` runs on the attempt runner under `policy` (none = ONE attempt, still recorded: a single call is evidence
@@ -335,7 +341,7 @@ export declare class ScopeFacade {
335
341
  getValueAt(path: string[], key?: string): unknown;
336
342
  setValue(key: string, value: unknown, shouldRedact?: boolean, description?: string): void;
337
343
  /** Path-aware writes share recording, redaction and lifetime policy with flat writes. */
338
- setValueAt(path: string[], key: string, value: unknown, shouldRedact?: boolean, description?: string): void;
344
+ setValueAt(path: string[], key: string, value: unknown, shouldRedact?: boolean, description?: string, declared?: readonly DeclaredWrite[]): void;
339
345
  updateValue(key: string, value: unknown, description?: string): void;
340
346
  /** Path-aware merges use the same write funnel as replacements. */
341
347
  updateValueAt(path: string[], key: string, value: unknown, description?: string): void;
@@ -41,7 +41,7 @@
41
41
  * empty object, `undefined` disappears. A record of plain JSON values reads back exactly (`readRecordFile` →
42
42
  * `readStoredRecord`); for richer values, bring an adapter with a richer encoding.
43
43
  */
44
- import type { RecordSink } from 'foottrace/write';
44
+ import type { RecordEntry, RecordSink } from 'foottrace/write';
45
45
  import type { CaptureHistoryOptions } from '../capture/historyTypes.js';
46
46
  /** The default cap on a record file: 64 MiB. */
47
47
  export declare const DEFAULT_FILE_SINK_MAX_BYTES: number;
@@ -51,6 +51,8 @@ export declare const DEFAULT_FILE_SINK_MAX_ENTRY_BYTES: number;
51
51
  export declare const DEFAULT_FILE_SINK_MAX_QUEUED_BYTES: number;
52
52
  /** The default bound on `flush()`: 10 s. */
53
53
  export declare const DEFAULT_FILE_SINK_FLUSH_TIMEOUT_MS = 10000;
54
+ /** How far past `maxBytes` a CLOSING entry may still go, so a full file can say how the run ended: 64 KiB. */
55
+ export declare const CLOSE_RESERVE_BYTES: number;
54
56
  /** `fileSink`'s options — every resource the sink can spend, bounded. */
55
57
  export interface FileSinkOptions {
56
58
  /**
@@ -114,6 +116,20 @@ export interface FileSink extends RecordSink, Pick<CaptureHistoryOptions, 'ackno
114
116
  * ```
115
117
  */
116
118
  export declare function fileSink(path: string, options?: FileSinkOptions): FileSink;
119
+ /** @internal Index observation never owns the writer's descriptor. */
120
+ export interface FileSinkIndex {
121
+ write(entry: RecordEntry, offset: number, bytes: Uint8Array): () => void;
122
+ omit(entry: RecordEntry, reason: 'too-large' | 'unavailable'): void;
123
+ }
124
+ /** @internal An indexed writer creates a fresh file and seals it on this descriptor. */
125
+ export declare function createFileSink(path: string, options?: FileSinkOptions, index?: FileSinkIndex): {
126
+ sink: FileSink;
127
+ finalize: <T>(inspect: (descriptor: number) => Promise<T>) => Promise<T>;
128
+ };
129
+ /** Write all of `buffer` at `position` (asynchronously, as many writes as it takes); `wrote` is how much went out. */
130
+ export declare function writeAt(fd: number, buffer: Uint8Array, position: number, done: (error: Error | null, wrote: number) => void): void;
131
+ /** `work`, or a rejection naming the bound once `ms` passed — the work goes on, nobody waits for it. */
132
+ export declare function withTimeout<T>(work: Promise<T>, ms: number, message: string, abort?: () => void): Promise<T>;
117
133
  /** A record file read back: every parsed line, and every line that could not be. */
118
134
  export interface RecordFile {
119
135
  /** The parsed entries, in file order — untrusted input for `readStoredRecord` (`foottrace`). */
@@ -3,11 +3,16 @@ export declare class IndexedRefusal extends Error {
3
3
  readonly reason: IndexedRecordFileReason;
4
4
  constructor(reason: IndexedRecordFileReason);
5
5
  }
6
+ export declare function invalidIndexedData(): never;
7
+ export declare function validIndexedAudience(value: unknown): value is string;
8
+ export declare const MAX_PUBLISHED_VIEW_BYTES: number;
6
9
  /** A stored line's text. Bytes that are not UTF-8 are corrupt data (`'invalid-data'`), never an I/O problem. */
7
10
  export declare function indexedText(bytes: Uint8Array): string;
11
+ /** JSON syntax is an admission failure once the bytes have been read. */
12
+ export declare function indexedJson(text: string): unknown;
8
13
  /** An index key, not a source-ID or record codec. Canonical record admission remains in Foottrace. */
9
14
  export declare function indexedAddress(value: unknown): string;
10
- export declare function indexedLimits(options: IndexedRecordFileOptions): IndexedLimits;
15
+ export declare function indexedLimits(options: IndexedRecordFileOptions, published?: boolean): IndexedLimits;
11
16
  export declare function refused(error: unknown): {
12
17
  readonly status: 'unknown';
13
18
  readonly reason: IndexedRecordFileReason;