footprintjs 10.7.1 → 11.0.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 (170) hide show
  1. package/AGENTS.md +7 -7
  2. package/README.md +9 -0
  3. package/dist/esm/index.d.ts +7 -1
  4. package/dist/esm/index.js +10 -1
  5. package/dist/esm/lib/attempt/call.d.ts +9 -0
  6. package/dist/esm/lib/attempt/call.js +22 -1
  7. package/dist/esm/lib/attempt/decision.d.ts +1 -1
  8. package/dist/esm/lib/attempt/decision.js +3 -3
  9. package/dist/esm/lib/attempt/evidence.d.ts +12 -0
  10. package/dist/esm/lib/attempt/evidence.js +75 -0
  11. package/dist/esm/lib/attempt/index.d.ts +3 -1
  12. package/dist/esm/lib/attempt/index.js +3 -1
  13. package/dist/esm/lib/attempt/observerDiagnostics.d.ts +5 -0
  14. package/dist/esm/lib/attempt/observerDiagnostics.js +41 -0
  15. package/dist/esm/lib/attempt/runner.d.ts +2 -0
  16. package/dist/esm/lib/attempt/runner.js +14 -9
  17. package/dist/esm/lib/attempt/standalone.d.ts +6 -2
  18. package/dist/esm/lib/attempt/standalone.js +15 -14
  19. package/dist/esm/lib/attempt/types.d.ts +23 -2
  20. package/dist/esm/lib/attempt/types.js +1 -1
  21. package/dist/esm/lib/budget/timeBudget.d.ts +1 -1
  22. package/dist/esm/lib/budget/timeBudget.js +3 -3
  23. package/dist/esm/lib/engine/graph/prefixNodeTree.js +3 -1
  24. package/dist/esm/lib/engine/handlers/ParallelForEachHandler.d.ts +0 -52
  25. package/dist/esm/lib/engine/handlers/ParallelForEachHandler.js +4 -1
  26. package/dist/esm/lib/engine/handlers/StageRunner.d.ts +0 -9
  27. package/dist/esm/lib/engine/handlers/StageRunner.js +4 -1
  28. package/dist/esm/lib/engine/handlers/SubflowExecutor.js +376 -327
  29. package/dist/esm/lib/engine/handlers/SubflowInputMapper.d.ts +4 -3
  30. package/dist/esm/lib/engine/handlers/SubflowInputMapper.js +8 -8
  31. package/dist/esm/lib/engine/narrative/CombinedNarrativeRecorder.d.ts +1 -1
  32. package/dist/esm/lib/engine/narrative/CombinedNarrativeRecorder.js +2 -2
  33. package/dist/esm/lib/engine/narrative/FlowRecorderDispatcher.d.ts +9 -2
  34. package/dist/esm/lib/engine/narrative/FlowRecorderDispatcher.js +58 -52
  35. package/dist/esm/lib/engine/narrative/NullControlFlowNarrativeGenerator.d.ts +4 -4
  36. package/dist/esm/lib/engine/narrative/NullControlFlowNarrativeGenerator.js +5 -5
  37. package/dist/esm/lib/engine/narrative/formatting/sentences.d.ts +2 -2
  38. package/dist/esm/lib/engine/narrative/formatting/sentences.js +5 -5
  39. package/dist/esm/lib/engine/narrative/types.d.ts +1 -6
  40. package/dist/esm/lib/engine/narrative/types.js +1 -9
  41. package/dist/esm/lib/engine/traversal/FlowchartTraverser.d.ts +1 -1
  42. package/dist/esm/lib/engine/traversal/FlowchartTraverser.js +20 -8
  43. package/dist/esm/lib/engine/types.d.ts +5 -2
  44. package/dist/esm/lib/engine/types.js +1 -1
  45. package/dist/esm/lib/errors/RunInFlightError.d.ts +7 -0
  46. package/dist/esm/lib/errors/RunInFlightError.js +13 -0
  47. package/dist/esm/lib/memory/RunComponent.d.ts +7 -0
  48. package/dist/esm/lib/memory/RunComponent.js +29 -0
  49. package/dist/esm/lib/memory/RunFrame.d.ts +59 -0
  50. package/dist/esm/lib/memory/RunFrame.js +133 -0
  51. package/dist/esm/lib/memory/StageContext.d.ts +5 -1
  52. package/dist/esm/lib/memory/StageContext.js +14 -5
  53. package/dist/esm/lib/memory/attention.js +2 -2
  54. package/dist/esm/lib/recorder/ComponentRunControl.d.ts +39 -0
  55. package/dist/esm/lib/recorder/ComponentRunControl.js +186 -0
  56. package/dist/esm/lib/recorder/FinalizationBook.d.ts +34 -0
  57. package/dist/esm/lib/recorder/FinalizationBook.js +55 -0
  58. package/dist/esm/lib/recorder/attemptMetricRows.js +13 -4
  59. package/dist/esm/lib/runner/ExecutionRuntime.d.ts +3 -0
  60. package/dist/esm/lib/runner/ExecutionRuntime.js +3 -1
  61. package/dist/esm/lib/runner/FlowChartExecutor.d.ts +3 -3
  62. package/dist/esm/lib/runner/FlowChartExecutor.js +151 -99
  63. package/dist/esm/lib/runner/NativeRunAdapter.d.ts +44 -0
  64. package/dist/esm/lib/runner/NativeRunAdapter.js +89 -0
  65. package/dist/esm/lib/runner/NativeRunLifecycle.d.ts +3 -0
  66. package/dist/esm/lib/runner/NativeRunLifecycle.js +344 -0
  67. package/dist/esm/lib/runner/RunCells.d.ts +10 -0
  68. package/dist/esm/lib/runner/RunCells.js +70 -0
  69. package/dist/esm/lib/runner/RunContext.js +20 -25
  70. package/dist/esm/lib/runner/RunLease.d.ts +12 -0
  71. package/dist/esm/lib/runner/RunLease.js +27 -0
  72. package/dist/esm/lib/runner/RunLifecycle.d.ts +137 -0
  73. package/dist/esm/lib/runner/RunLifecycle.js +2 -0
  74. package/dist/esm/lib/runner/index.d.ts +2 -0
  75. package/dist/esm/lib/runner/index.js +2 -1
  76. package/dist/esm/lib/runner/nativeLegSettlement.d.ts +14 -0
  77. package/dist/esm/lib/runner/nativeLegSettlement.js +8 -0
  78. package/dist/esm/lib/runner/nativeRunBinding.d.ts +19 -0
  79. package/dist/esm/lib/runner/nativeRunBinding.js +43 -0
  80. package/dist/esm/lib/runner/resume.d.ts +4 -20
  81. package/dist/esm/lib/runner/resume.js +11 -10
  82. package/dist/esm/lib/scope/ScopeFacade.d.ts +2 -15
  83. package/dist/esm/lib/scope/ScopeFacade.js +87 -17
  84. package/dist/esm/lib/scope/runtime.d.ts +6 -0
  85. package/dist/esm/lib/scope/runtime.js +28 -3
  86. package/dist/index.js +17 -3
  87. package/dist/lib/attempt/call.js +22 -1
  88. package/dist/lib/attempt/decision.js +3 -3
  89. package/dist/lib/attempt/evidence.js +80 -0
  90. package/dist/lib/attempt/index.js +7 -2
  91. package/dist/lib/attempt/observerDiagnostics.js +46 -0
  92. package/dist/lib/attempt/runner.js +14 -9
  93. package/dist/lib/attempt/standalone.js +15 -14
  94. package/dist/lib/attempt/types.js +1 -1
  95. package/dist/lib/budget/timeBudget.js +3 -3
  96. package/dist/lib/engine/graph/prefixNodeTree.js +3 -1
  97. package/dist/lib/engine/handlers/ParallelForEachHandler.js +6 -3
  98. package/dist/lib/engine/handlers/StageRunner.js +6 -3
  99. package/dist/lib/engine/handlers/SubflowExecutor.js +376 -327
  100. package/dist/lib/engine/handlers/SubflowInputMapper.js +8 -8
  101. package/dist/lib/engine/narrative/CombinedNarrativeRecorder.js +2 -2
  102. package/dist/lib/engine/narrative/FlowRecorderDispatcher.js +58 -52
  103. package/dist/lib/engine/narrative/NullControlFlowNarrativeGenerator.js +5 -5
  104. package/dist/lib/engine/narrative/formatting/sentences.js +5 -5
  105. package/dist/lib/engine/narrative/types.js +1 -9
  106. package/dist/lib/engine/traversal/FlowchartTraverser.js +20 -8
  107. package/dist/lib/engine/types.js +1 -1
  108. package/dist/lib/errors/RunInFlightError.js +17 -0
  109. package/dist/lib/memory/RunComponent.js +36 -0
  110. package/dist/lib/memory/RunFrame.js +142 -0
  111. package/dist/lib/memory/StageContext.js +14 -5
  112. package/dist/lib/memory/attention.js +2 -2
  113. package/dist/lib/recorder/ComponentRunControl.js +197 -0
  114. package/dist/lib/recorder/FinalizationBook.js +60 -0
  115. package/dist/lib/recorder/attemptMetricRows.js +13 -4
  116. package/dist/lib/runner/ExecutionRuntime.js +3 -1
  117. package/dist/lib/runner/FlowChartExecutor.js +151 -99
  118. package/dist/lib/runner/NativeRunAdapter.js +93 -0
  119. package/dist/lib/runner/NativeRunLifecycle.js +348 -0
  120. package/dist/lib/runner/RunCells.js +74 -0
  121. package/dist/lib/runner/RunContext.js +20 -25
  122. package/dist/lib/runner/RunLease.js +31 -0
  123. package/dist/lib/runner/RunLifecycle.js +3 -0
  124. package/dist/lib/runner/index.js +4 -2
  125. package/dist/lib/runner/nativeLegSettlement.js +12 -0
  126. package/dist/lib/runner/nativeRunBinding.js +51 -0
  127. package/dist/lib/runner/resume.js +13 -12
  128. package/dist/lib/scope/ScopeFacade.js +86 -16
  129. package/dist/lib/scope/runtime.js +31 -4
  130. package/dist/types/index.d.ts +7 -1
  131. package/dist/types/lib/attempt/call.d.ts +9 -0
  132. package/dist/types/lib/attempt/decision.d.ts +1 -1
  133. package/dist/types/lib/attempt/evidence.d.ts +12 -0
  134. package/dist/types/lib/attempt/index.d.ts +3 -1
  135. package/dist/types/lib/attempt/observerDiagnostics.d.ts +5 -0
  136. package/dist/types/lib/attempt/runner.d.ts +2 -0
  137. package/dist/types/lib/attempt/standalone.d.ts +6 -2
  138. package/dist/types/lib/attempt/types.d.ts +23 -2
  139. package/dist/types/lib/budget/timeBudget.d.ts +1 -1
  140. package/dist/types/lib/engine/handlers/ParallelForEachHandler.d.ts +0 -52
  141. package/dist/types/lib/engine/handlers/StageRunner.d.ts +0 -9
  142. package/dist/types/lib/engine/handlers/SubflowInputMapper.d.ts +4 -3
  143. package/dist/types/lib/engine/narrative/CombinedNarrativeRecorder.d.ts +1 -1
  144. package/dist/types/lib/engine/narrative/FlowRecorderDispatcher.d.ts +9 -2
  145. package/dist/types/lib/engine/narrative/NullControlFlowNarrativeGenerator.d.ts +4 -4
  146. package/dist/types/lib/engine/narrative/formatting/sentences.d.ts +2 -2
  147. package/dist/types/lib/engine/narrative/types.d.ts +1 -6
  148. package/dist/types/lib/engine/traversal/FlowchartTraverser.d.ts +1 -1
  149. package/dist/types/lib/engine/types.d.ts +5 -2
  150. package/dist/types/lib/errors/RunInFlightError.d.ts +7 -0
  151. package/dist/types/lib/memory/RunComponent.d.ts +7 -0
  152. package/dist/types/lib/memory/RunFrame.d.ts +59 -0
  153. package/dist/types/lib/memory/StageContext.d.ts +5 -1
  154. package/dist/types/lib/recorder/ComponentRunControl.d.ts +39 -0
  155. package/dist/types/lib/recorder/FinalizationBook.d.ts +34 -0
  156. package/dist/types/lib/runner/ExecutionRuntime.d.ts +3 -0
  157. package/dist/types/lib/runner/FlowChartExecutor.d.ts +3 -3
  158. package/dist/types/lib/runner/NativeRunAdapter.d.ts +44 -0
  159. package/dist/types/lib/runner/NativeRunLifecycle.d.ts +3 -0
  160. package/dist/types/lib/runner/RunCells.d.ts +10 -0
  161. package/dist/types/lib/runner/RunLease.d.ts +12 -0
  162. package/dist/types/lib/runner/RunLifecycle.d.ts +137 -0
  163. package/dist/types/lib/runner/index.d.ts +2 -0
  164. package/dist/types/lib/runner/nativeLegSettlement.d.ts +14 -0
  165. package/dist/types/lib/runner/nativeRunBinding.d.ts +19 -0
  166. package/dist/types/lib/runner/resume.d.ts +4 -20
  167. package/dist/types/lib/scope/ScopeFacade.d.ts +2 -15
  168. package/dist/types/lib/scope/runtime.d.ts +6 -0
  169. package/package.json +20 -22
  170. package/CLAUDE.md +0 -156
@@ -521,6 +521,10 @@ export declare class StageContext {
521
521
  * note needs no second redaction pass. Without a sink the log does nothing (`EventLog · note`).
522
522
  */
523
523
  private noteAttempt;
524
+ /** Capture-only invocation note; independent of staged business-state writes. */
525
+ noteCallStart(data: Readonly<Record<string, unknown>>): void;
526
+ /** The answered call may feed subsequent writes in this live owning attempt. */
527
+ noteCallAnswerRead(attemptId: string): void;
524
528
  /** The attempts of this execution so far, in order — its own and its calls'; `undefined` when there are none. */
525
529
  get attempts(): readonly AttemptRecord[] | undefined;
526
530
  /** The ended series' summary; `undefined` while it runs and without a policy. */
@@ -573,7 +577,7 @@ export declare class StageContext {
573
577
  * {@link MAX_CALL_RECORDS}, the rest counted — and reported to the run's `onAttempt` either way. Like the stage's
574
578
  * records, NOT cleared by {@link discardStaged}: a failed attempt's calls are evidence too.
575
579
  */
576
- reportCallAttempt(record: AttemptRecord, structuredError: StructuredErrorInfo | undefined): void;
580
+ reportCallAttempt(record: AttemptRecord, structuredError: StructuredErrorInfo | undefined, evidence?: Readonly<Record<string, unknown>>): void;
577
581
  /**
578
582
  * Create (or return) this context's linked successor.
579
583
  *
@@ -0,0 +1,39 @@
1
+ import type { RunFrame } from '../memory/RunFrame.js';
2
+ import type { CombinedRecorder } from './CombinedRecorder.js';
3
+ import { type ComponentEnd, type FinalizationFailures, FinalizationBook } from './FinalizationBook.js';
4
+ /** Component-local ordinary recorder using the canonical served-event/error boundary.
5
+ * WHY: mid-run consumers need preceding events synchronously, never one beat behind.
6
+ * Absent/inline delivery is admitted; deferred, invalid or accessor delivery refuses
7
+ * with ERR_COMPONENT_RECORDER_DELIVERY rather than being silently overridden.
8
+ */
9
+ export type InlineComponentRecorder = Omit<CombinedRecorder, 'delivery'> & {
10
+ readonly delivery?: 'inline';
11
+ };
12
+ /** Synchronous component wiring, captured before its stages or mappers run.
13
+ * WHY: mounts have no public run wrapper to bind their private integration state.
14
+ */
15
+ export interface ComponentSetup {
16
+ /** Runs on the actual protected scope before stage callbacks, stream start or item selection.
17
+ * Factory construction effects precede this boundary; returned asynchronous work is refused.
18
+ */
19
+ readonly bindScope?: (scope: unknown) => void;
20
+ readonly recorder?: InlineComponentRecorder;
21
+ }
22
+ export interface ComponentPort {
23
+ open(frame: RunFrame, finalizers: FinalizationBook): ComponentSetup;
24
+ }
25
+ /** Called by first component slot issuance; the lifecycle itself strongly owns its port. */
26
+ export declare function registerComponentPort(token: object, namespace: object, port: ComponentPort): void;
27
+ /** Entry captures live ports before any caller can change future chart declarations. */
28
+ export declare function captureComponentControl(frame: RunFrame, finalizers?: FinalizationBook): void;
29
+ export declare function openComponentControl(frame: RunFrame): void;
30
+ export declare function bindComponentScope(frame: RunFrame | undefined, scope: unknown): void;
31
+ export declare function hasComponentRecorders(frame: RunFrame | undefined): boolean;
32
+ /** Native-owned selection only; hooks.fire remains the one callback invocation loop. */
33
+ export declare function componentRecorders(frame: RunFrame | undefined, external: readonly object[]): Iterable<object>;
34
+ /** Drop every leg subscription, including a failFast sibling still in host async work.
35
+ * Already-registered cleanup remains with its actual component settlement owner.
36
+ */
37
+ export declare function retireLegComponentObservations(frame: RunFrame): void;
38
+ /** Native retirement drops observation/setup closures; owned root control settles later. */
39
+ export declare function retireComponentControl(frame: RunFrame, end: ComponentEnd): Promise<FinalizationFailures> | undefined;
@@ -0,0 +1,34 @@
1
+ /** Native component leg terminal, including failed cancellation.
2
+ * WHY: paused cleanup may preserve adapter resources; it must not imply remote closure.
3
+ * SAME and FRESH resumes open new cells/subscriptions and need explicit admitted-data restore.
4
+ */
5
+ export type ComponentEnd = {
6
+ readonly kind: 'completed';
7
+ } | {
8
+ readonly kind: 'paused';
9
+ } | {
10
+ readonly kind: 'failed';
11
+ };
12
+ export type ComponentFinalizer = (end: ComponentEnd) => void | Promise<void>;
13
+ export interface FinalizationFailures {
14
+ readonly count: number;
15
+ readonly first?: {
16
+ readonly reason: unknown;
17
+ };
18
+ }
19
+ /** One once/reverse/awaited implementation; control never runs through recorder hooks. */
20
+ export declare class FinalizationBook {
21
+ private callbacks;
22
+ private closed;
23
+ private result?;
24
+ get hasCallbacks(): boolean;
25
+ register(callback: ComponentFinalizer): void;
26
+ finish(end: ComponentEnd): Promise<FinalizationFailures>;
27
+ }
28
+ /** Value-free diagnostics never await or probe a foreign thenable. */
29
+ export declare function reportFinalizationFailures(logger: {
30
+ warn(message: string, facts: {
31
+ secondaryPhaseFailures: number;
32
+ cleanupFailures: number;
33
+ }): unknown;
34
+ }, secondaryPhaseFailures: number, cleanupFailures: number): void;
@@ -19,6 +19,7 @@ import { NativeCapture } from '../capture/nativeCoverage.js';
19
19
  import type { EngineReadSources, NativeCaptureObservation, SourceLimitation } from '../capture/readSources.js';
20
20
  import { EngineReadSourceCapture } from '../capture/readSources.js';
21
21
  import type { StageSnapshot } from '../memory/frameTypes.js';
22
+ import type { RunFrame } from '../memory/RunFrame.js';
22
23
  import type { RunPolicy } from '../memory/runPolicy.js';
23
24
  import { StageContext } from '../memory/StageContext.js';
24
25
  import type { ObserverStats } from './DeferredObserverTier.js';
@@ -174,6 +175,8 @@ export interface RuntimeRecord {
174
175
  readonly meta?: Meta;
175
176
  }
176
177
  export declare class ExecutionRuntime {
178
+ /** @internal Current native leg's runtime bank; each scope captures its own stage view. */
179
+ runFrame?: RunFrame;
177
180
  readSources?: EngineReadSourceCapture;
178
181
  /** Present only for the current opted-in root leg. Never inherited by a subflow runtime. */
179
182
  capture?: NativeCapture;
@@ -64,7 +64,7 @@ export declare class FlowChartExecutor<TOut = any, TScope = any> {
64
64
  * counters, checkpoint, recorders) — one executor = one in-flight execution.
65
65
  * See docs/guides/execution-model.md.
66
66
  */
67
- private _isExecuting;
67
+ private readonly lease;
68
68
  private captureSignal?;
69
69
  private captureHistoryLease?;
70
70
  private failureState;
@@ -173,6 +173,8 @@ export declare class FlowChartExecutor<TOut = any, TScope = any> {
173
173
  * ```
174
174
  */
175
175
  resume(checkpoint: FlowchartCheckpoint, resumeInput?: unknown, options?: Pick<RunOptions, 'signal' | 'env' | 'maxDepth' | 'maxIterations' | 'deadline' | 'timeoutMs'>): Promise<ExecutorResult>;
176
+ /** The one terminal law for run and resume; no promise or extra await without cleanup. */
177
+ private finishNativeLeg;
176
178
  /**
177
179
  * The settle of a leg that threw: flush the deferred tier (the OUTERMOST
178
180
  * handler — a pause re-throws through subflow traversers without exit
@@ -200,8 +202,6 @@ export declare class FlowChartExecutor<TOut = any, TScope = any> {
200
202
  private openingMeta;
201
203
  /** The closing entry's error: the run's SERVED form of it, its name, message and code only (never `raw`). */
202
204
  private closingError;
203
- /** The re-entrancy guard: one executor = one in-flight execution. */
204
- private assertIdle;
205
205
  /**
206
206
  * Attach a ScopeRecorder to observe data operations (reads, writes, commits)
207
207
  * on every stage scope. Call before run(). **Idempotent by `id`** (replaced,
@@ -0,0 +1,44 @@
1
+ import type { FlowChart } from '../builder/types.js';
2
+ import { type ExecutorResult, type RunOptions } from '../engine/types.js';
3
+ import type { RunBanks, RunFrame } from '../memory/RunFrame.js';
4
+ import type { FlowchartCheckpoint } from '../pause/types.js';
5
+ import type { FinalizationBook } from '../recorder/FinalizationBook.js';
6
+ import type { FlowChartExecutorOptions } from './options.js';
7
+ import type { ResumeOptions, RunSetup } from './RunLifecycle.js';
8
+ export type NativeEntry = {
9
+ readonly kind: 'run';
10
+ readonly options?: RunOptions;
11
+ } | {
12
+ readonly kind: 'resume';
13
+ readonly checkpoint: FlowchartCheckpoint;
14
+ readonly input?: unknown;
15
+ readonly options?: ResumeOptions;
16
+ };
17
+ export interface NativeAdmission {
18
+ readonly legBanks: RunBanks;
19
+ readonly runtimeBanks: RunBanks;
20
+ readonly componentBanks: RunBanks;
21
+ readonly signal: AbortSignal;
22
+ readonly finalizers: FinalizationBook;
23
+ bindOrigin(frame: RunFrame): void;
24
+ initialize(callback: RunSetup['onOrigin']): void;
25
+ cleanup(callback: () => void): void;
26
+ }
27
+ /** The sole production executor adapter. No raw executor crosses this boundary. */
28
+ export declare class NativeRunAdapter {
29
+ private readonly executor;
30
+ constructor(chart: FlowChart, options?: FlowChartExecutorOptions);
31
+ execute(entry: NativeEntry, setup: RunSetup | undefined, admission: NativeAdmission): Promise<ExecutorResult>;
32
+ ready(frame: RunFrame | undefined): boolean;
33
+ snapshot(frame: RunFrame | undefined, options?: {
34
+ redact?: boolean;
35
+ }): import("./ExecutionRuntime.js").RuntimeSnapshot | undefined;
36
+ narrative(frame: RunFrame | undefined): import("../engine/index.js").CombinedNarrativeEntry[];
37
+ commits(frame: RunFrame | undefined): number;
38
+ paused(frame: RunFrame | undefined): boolean;
39
+ drain(frame: RunFrame | undefined, options?: {
40
+ timeoutMs?: number;
41
+ }): Promise<import("../observer-queue/deferredDispatcher.js").DrainResult>;
42
+ liveState(frame: RunFrame | undefined): Record<string, unknown> | undefined;
43
+ checkpoint(frame: RunFrame | undefined): FlowchartCheckpoint | undefined;
44
+ }
@@ -0,0 +1,3 @@
1
+ import type { FlowChart } from '../builder/types.js';
2
+ import type { RunLifecycle, RunLifecycleOptions } from './RunLifecycle.js';
3
+ export declare function createRunLifecycle(chart: FlowChart, options: RunLifecycleOptions): RunLifecycle;
@@ -0,0 +1,10 @@
1
+ import type { CellBank } from '../memory/RunFrame.js';
2
+ import type { RunCells, RunSlot } from './RunLifecycle.js';
3
+ /** Namespace and slot law; the L4 carrier stores only opaque keys and values. */
4
+ export declare class RunSlots {
5
+ private readonly keys;
6
+ private frozen;
7
+ issue<T>(lifetime: 'leg' | 'runtime' | 'component'): RunSlot<T>;
8
+ freeze(): void;
9
+ cells(bankFor: (namespace: object, lifetime: 'leg' | 'runtime' | 'component') => CellBank, allowRead: () => void, allowWrite: () => void): RunCells;
10
+ }
@@ -0,0 +1,12 @@
1
+ /** Internal ownership capability. A stale release can never release another admission. */
2
+ export interface RunAdmission {
3
+ bindRunId(runId: string): void;
4
+ release(): void;
5
+ }
6
+ /** One synchronous admission boundary, reused by executors and logical runners. */
7
+ export declare class RunLease {
8
+ private readonly runnerId;
9
+ private active?;
10
+ constructor(runnerId: string);
11
+ acquire(): RunAdmission;
12
+ }
@@ -0,0 +1,137 @@
1
+ import type { CombinedNarrativeRecorderOptions } from '../engine/narrative/CombinedNarrativeRecorder.js';
2
+ import type { CombinedNarrativeEntry } from '../engine/narrative/narrativeTypes.js';
3
+ import type { ExecutorResult, RunOptions } from '../engine/types.js';
4
+ import type { NativeComponentEntry, NativeRunOrigin } from '../memory/RunFrame.js';
5
+ import type { FlowchartCheckpoint } from '../pause/types.js';
6
+ import type { CombinedRecorder } from '../recorder/CombinedRecorder.js';
7
+ import type { RedactionPolicy } from '../scope/types.js';
8
+ import type { AttachRecorderOptions, ObserverDrainResult } from './DeferredObserverTier.js';
9
+ import type { RuntimeSnapshot } from './ExecutionRuntime.js';
10
+ import type { FlowChartExecutorOptions } from './options.js';
11
+ export type { NativeRunOrigin } from '../memory/RunFrame.js';
12
+ export type { ComponentSetup, InlineComponentRecorder } from '../recorder/ComponentRunControl.js';
13
+ export type { ComponentEnd } from '../recorder/FinalizationBook.js';
14
+ import type { ComponentSetup } from '../recorder/ComponentRunControl.js';
15
+ import type { ComponentEnd } from '../recorder/FinalizationBook.js';
16
+ /** One captured component occurrence: private cells plus joined terminal control.
17
+ * WHY: mounted components have no public run wrapper to own cleanup.
18
+ * entry.ordinal is a native occurrence coordinate, never application identity.
19
+ */
20
+ export interface ComponentRun extends RunCells {
21
+ readonly origin: NativeRunOrigin;
22
+ /** Native occurrence within this leg, not application identity, resume identity or authority. */
23
+ readonly entry: NativeComponentEntry;
24
+ /** Register before resource effects. Native control joins callbacks once in reverse order;
25
+ * owned roots settle after postprocessing, raw roots at native terminal. A failFast sibling
26
+ * mount can settle later than its rejected parent. Cleanup must bound its own time;
27
+ * the run signal/deadline do not cover it. A pause wins over cleanup failure (count logged).
28
+ * Observation has closed before cleanup; a prior body/native failure keeps precedence.
29
+ */
30
+ onFinalize(cleanup: (end: ComponentEnd) => void | Promise<void>): void;
31
+ }
32
+ declare const slotBrand: unique symbol;
33
+ declare const continuationBrand: unique symbol;
34
+ /** Owner-issued key. Neither serialization nor a structural copy creates a valid key. */
35
+ export interface RunSlot<T> {
36
+ readonly [slotBrand]: (value: T) => T;
37
+ }
38
+ export type CellValue<T> = {
39
+ readonly present: false;
40
+ } | {
41
+ readonly present: true;
42
+ readonly value: T;
43
+ };
44
+ export interface RunCells {
45
+ read<T>(slot: RunSlot<T>): CellValue<T>;
46
+ local<T>(slot: RunSlot<T>, initialize: () => T): T;
47
+ set<T>(slot: RunSlot<T>, value: T): void;
48
+ take<T>(slot: RunSlot<T>): CellValue<T>;
49
+ }
50
+ export interface BoundRun extends RunCells {
51
+ readonly origin: NativeRunOrigin;
52
+ readonly retired: boolean;
53
+ }
54
+ export interface PausedContinuation {
55
+ readonly [continuationBrand]: true;
56
+ checkpoint(): FlowchartCheckpoint;
57
+ }
58
+ export type ResumeOptions = Pick<RunOptions, 'signal' | 'env' | 'maxDepth' | 'maxIterations' | 'deadline' | 'timeoutMs'>;
59
+ export type RunEntry = {
60
+ readonly kind: 'run';
61
+ readonly options?: RunOptions;
62
+ } | {
63
+ readonly kind: 'resume';
64
+ readonly mode: 'same';
65
+ readonly continuation: PausedContinuation;
66
+ readonly input?: unknown;
67
+ readonly options?: ResumeOptions;
68
+ } | {
69
+ readonly kind: 'resume';
70
+ readonly mode: 'fresh';
71
+ readonly checkpoint: FlowchartCheckpoint;
72
+ readonly input?: unknown;
73
+ readonly options?: ResumeOptions;
74
+ };
75
+ export interface RunSetup {
76
+ readonly attachments?: readonly {
77
+ readonly recorder: CombinedRecorder;
78
+ readonly options?: AttachRecorderOptions;
79
+ }[];
80
+ readonly redaction?: RedactionPolicy;
81
+ readonly narrative?: CombinedNarrativeRecorderOptions;
82
+ readonly onOrigin?: (cells: RunCells, origin: NativeRunOrigin) => void;
83
+ }
84
+ export interface OwnedRun extends RunCells {
85
+ readonly origin: NativeRunOrigin | undefined;
86
+ execute(entry: RunEntry, setup?: RunSetup): Promise<ExecutorResult>;
87
+ onFinalize(cleanup: () => void | Promise<void>): void;
88
+ snapshot(options?: {
89
+ redact?: boolean;
90
+ }): RuntimeSnapshot | undefined;
91
+ }
92
+ export type RunPhase = 'preparing' | 'executing' | 'postprocessing' | 'settled';
93
+ /** Captures one execution; methods refuse after its executor begins another native leg. */
94
+ export interface RunView {
95
+ readonly phase: RunPhase;
96
+ readonly origin: NativeRunOrigin | undefined;
97
+ snapshot(options?: {
98
+ redact?: boolean;
99
+ }): RuntimeSnapshot | undefined;
100
+ getNarrativeEntries(): readonly CombinedNarrativeEntry[];
101
+ getCommitCount(): number;
102
+ isPaused(): boolean;
103
+ drainObservers(options?: {
104
+ timeoutMs?: number;
105
+ }): Promise<ObserverDrainResult>;
106
+ /** Borrowed internal computation values, never an automatically redacted serving surface. */
107
+ liveState(): Record<string, unknown> | undefined;
108
+ }
109
+ export interface RunLifecycle {
110
+ /**
111
+ * Private per-leg, per-runtime or per-component storage. A component slot
112
+ * declares this chart's entry root: internal unregistered subcharts share
113
+ * it; every separately mounted declared root gets a fresh bank.
114
+ * Declare before entry. An already-captured frame never follows a later
115
+ * declaration, and mismatched component access refuses. Every new leg,
116
+ * including same-executor resume, starts with fresh component values.
117
+ * Keep this lifecycle strongly reachable: a slot alone does not retain its weak component port.
118
+ */
119
+ slot<T>(lifetime: 'leg' | 'runtime' | 'component'): RunSlot<T>;
120
+ withRun<T>(body: (run: OwnedRun) => T | Promise<T>): Promise<T>;
121
+ forScope(scope: unknown): BoundRun;
122
+ view(): RunView | undefined;
123
+ /** One-shot SAME token; setup refusal spends it. Save its checkpoint for FRESH recovery.
124
+ * A failed withRun body withdraws the offered continuation.
125
+ */
126
+ continuation(): PausedContinuation | undefined;
127
+ }
128
+ export interface RunLifecycleOptions {
129
+ readonly runnerId: string;
130
+ readonly executorOptions?: FlowChartExecutorOptions;
131
+ /** Capture wiring only for a declared component slot; retain this lifecycle while the chart runs.
132
+ * Recorders are inline only; registering the same object globally deferred also delivers it there.
133
+ * bindScope runs once per scope/attempt and a throwing binder may be retried by stage policy.
134
+ * WHY: mid-run consumers must see prior events and mounts need joined cleanup.
135
+ */
136
+ readonly componentSetup?: (component: ComponentRun) => ComponentSetup;
137
+ }
@@ -6,9 +6,11 @@ export { ExecutionRuntime } from './ExecutionRuntime.js';
6
6
  export { FlowChartExecutor } from './FlowChartExecutor.js';
7
7
  export type { SubtreeSnapshot } from './getSubtreeSnapshot.js';
8
8
  export { getSubtreeSnapshot, listSubflowPaths } from './getSubtreeSnapshot.js';
9
+ export { createRunLifecycle } from './NativeRunLifecycle.js';
9
10
  export type { FlowChartExecutorOptions } from './options.js';
10
11
  export type { RecordFlushResult, RecordSinkFailureMode, RecordSinkFlushMode, RecordSinkOption, RecordSinkOptions, } from './recordSink.js';
11
12
  export { RecordSinkError } from './recordSink.js';
12
13
  export type { RunResult } from './RunContext.js';
13
14
  export { RunContext } from './RunContext.js';
15
+ export type { BoundRun, CellValue, ComponentEnd, ComponentRun, ComponentSetup, InlineComponentRecorder, NativeRunOrigin, OwnedRun, PausedContinuation, ResumeOptions, RunCells, RunEntry, RunLifecycle, RunLifecycleOptions, RunPhase, RunSetup, RunSlot, RunView, } from './RunLifecycle.js';
14
16
  export type { RunnableFlowChart } from './RunnableChart.js';
@@ -0,0 +1,14 @@
1
+ import type { ExecutorResult } from '../engine/types.js';
2
+ import type { RunFrame } from '../memory/RunFrame.js';
3
+ /** Per-entry terminal data; no additional promise boundary or execution policy. */
4
+ export interface NativeLegSettlement {
5
+ frame?: RunFrame;
6
+ completed: boolean;
7
+ escaped?: {
8
+ readonly reason: unknown;
9
+ };
10
+ cleanupFailure?: {
11
+ readonly reason: unknown;
12
+ };
13
+ }
14
+ export declare function nativeLegResult(terminal: NativeLegSettlement, result: ExecutorResult): ExecutorResult;
@@ -0,0 +1,19 @@
1
+ import { type NativeLegOrigin, type RunBanks, RunFrame } from '../memory/RunFrame.js';
2
+ import type { FinalizationBook } from '../recorder/FinalizationBook.js';
3
+ interface NativeRunBinding {
4
+ readonly legBanks: RunBanks;
5
+ readonly runtimeBanks: RunBanks;
6
+ readonly componentBanks: RunBanks;
7
+ readonly finalizers: FinalizationBook;
8
+ readonly onOrigin: (frame: RunFrame) => void;
9
+ }
10
+ /** Internal one-execution link to the sole native adapter, not an adapter registry. */
11
+ export declare function attachNativeRun(executor: object, binding: NativeRunBinding): () => void;
12
+ /** Called only at the native generated-origin boundary, before traversal callbacks. */
13
+ export declare function beginNativeRun(executor: object, origin: NativeLegOrigin, root: object, capture?: (frame: RunFrame) => void): RunFrame;
14
+ /** Explicit executor relation for captured-view checks, never a process-current run. */
15
+ export declare function nativeRunFrame(executor: object): RunFrame | undefined;
16
+ /** The traverser and sink now belong to this leg; reads before this cannot use an old heap. */
17
+ export declare function readyNativeRun(executor: object): void;
18
+ export declare function nativeRunReady(executor: object, frame: RunFrame): boolean;
19
+ export {};
@@ -1,26 +1,8 @@
1
- /**
2
- * resume — how `FlowChartExecutor.resume()` plans and announces a re-entry (F9).
3
- *
4
- * Three steps, in the order the executor takes them:
5
- *
6
- * 1. {@link planResume} — decode the checkpoint (the ONE codec,
7
- * `pause/record.ts`), find the paused stage in the chart as built, build
8
- * the resume half and the paused stage's stand-in, and plan the one-shot
9
- * re-entry (`ResumeEntry.plan`). Every refusal happens HERE, before any
10
- * executor state is touched.
11
- * 2. {@link seedCounters} — carry the pause-time execution counter and visit
12
- * counts into the run's shared counters (mutated, never replaced).
13
- * 3. {@link announceResume} — fire the executor-made `onResume` on the flow
14
- * and scope channels (and capture it for the deferred tier), BEFORE the
15
- * traversal so it precedes `onRunStart`.
16
- *
17
- * The executor owns the per-run state between the steps (the runId, the
18
- * runtime, the traverser); this module never holds any.
19
- */
20
1
  import type { RunCorrelation } from '../attempt/types.js';
21
2
  import type { FlowChart } from '../builder/types.js';
22
3
  import { ResumeEntry } from '../engine/handlers/ResumeEntry.js';
23
4
  import type { StageNode } from '../engine/types.js';
5
+ import type { RunFrame } from '../memory/RunFrame.js';
24
6
  import type { FlowchartCheckpoint } from '../pause/types.js';
25
7
  import type { RunObservers } from './attach.js';
26
8
  /** Everything a resume decided before any executor state was touched. */
@@ -37,7 +19,7 @@ export interface ResumePlan<TOut, TScope> {
37
19
  * untouched — when the checkpoint is malformed, the paused stage is gone, it
38
20
  * cannot be resumed, or its path does not fit this chart.
39
21
  */
40
- export declare function planResume<TOut, TScope>(fc: FlowChart<TOut, TScope>, stored: FlowchartCheckpoint, resumeInput: unknown): ResumePlan<TOut, TScope>;
22
+ export declare function planResume<TOut, TScope>(fc: FlowChart<TOut, TScope>, root: StageNode<TOut, TScope>, stored: FlowchartCheckpoint, resumeInput: unknown): ResumePlan<TOut, TScope>;
41
23
  /**
42
24
  * Seed the run's shared execution counter + per-stage visit counts from the
43
25
  * checkpoint, so runtimeStageIds stay unique and loopIteration monotonic
@@ -71,6 +53,8 @@ export declare function announceResume<TOut, TScope>(plan: ResumePlan<TOut, TSco
71
53
  readonly runId: string;
72
54
  readonly executionCount: number;
73
55
  readonly observers: RunObservers;
56
+ /** Internal admitted ROOT producer; no predicted child component binding. */
57
+ readonly producer?: RunFrame;
74
58
  /** The RESUMED leg's correlation (from `resume()`'s env) — on both events, like every event of the leg. */
75
59
  readonly correlation?: RunCorrelation;
76
60
  }): void;
@@ -1,18 +1,3 @@
1
- /**
2
- * ScopeFacade — Base class that library consumers extend to create custom scope classes
3
- *
4
- * Wraps StageContext (from memory/) to provide a consumer-friendly API for
5
- * state access, debug logging, metrics, and recorder hooks.
6
- *
7
- * Consumers extend this class to add domain-specific properties:
8
- *
9
- * ```typescript
10
- * class MyScope extends ScopeFacade {
11
- * get userName(): string { return this.getValue('name') as string; }
12
- * set userName(value: string) { this.setValue('name', value); }
13
- * }
14
- * ```
15
- */
16
1
  import type { AttemptContext, AttemptError, CallOptions, RetryPolicy, RunCorrelation } from '../attempt/types.js';
17
2
  import type { FlowChart } from '../builder/types.js';
18
3
  import type { DetachDriver, DetachHandle } from '../detach/types.js';
@@ -48,6 +33,7 @@ export declare class ScopeFacade {
48
33
  */
49
34
  private readonly _trackedReadKeys;
50
35
  private _recorders;
36
+ private readonly _producer;
51
37
  /**
52
38
  * Set by the commit observer: this stage's frame has flushed. A facade is
53
39
  * ONE stage execution's handle — the engine builds a fresh one per stage —
@@ -377,6 +363,7 @@ export declare class ScopeFacade {
377
363
  getEnv(): Readonly<ExecutionEnv>;
378
364
  /** @internal */
379
365
  getPipelineId(): string;
366
+ private _hasRecorders;
380
367
  private _invokeHook;
381
368
  /** The event as fired: unchanged without a correlation, else with the run's correlation as its last key. */
382
369
  private _correlated;
@@ -8,6 +8,7 @@
8
8
  * explicitly supply a smaller port (including `{}` for data-only scopes).
9
9
  */
10
10
  import type { RunCorrelation } from '../attempt/types.js';
11
+ import { type RunFrame } from '../memory/RunFrame.js';
11
12
  import type { RedactionPolicy, ScopeRecorder } from './types.js';
12
13
  /** Engine-facing capabilities. Never use a strict user-field proxy as this port. */
13
14
  export interface ScopeRuntimeTarget {
@@ -37,6 +38,7 @@ export interface ScopeRuntime {
37
38
  * Registration never reads, writes or enumerates properties on `scope`.
38
39
  * Re-registering explicitly replaces its binding. The descriptor is copied
39
40
  * and frozen; the target itself remains live and belongs to its provider.
41
+ * Replacing capabilities never retargets an already captured native producer.
40
42
  *
41
43
  * @example
42
44
  * const facade = new ScopeFacade(context, stageName, input, env);
@@ -50,4 +52,8 @@ export declare function requireScopeRuntime(scope: unknown, message?: string): R
50
52
  /** @internal decide()/select() asked outside a stage: name THEM, not the custom-factory migration. */
51
53
  export declare function requireDecisionScopeRuntime(scope: unknown): Readonly<ScopeRuntime>;
52
54
  export declare function registerNativeCaptureTarget(target: object, context: object): void;
55
+ /** @internal Run identity is independent from opt-in capture observation. */
56
+ export declare function registerNativeRunTarget(target: object, context: object): void;
53
57
  export declare function hasNativeCaptureTarget(target: object, context: object): boolean;
58
+ /** @internal Resolve only explicit scope/native registrations; never inspect a user proxy. */
59
+ export declare function scopeRunFrame(scope: unknown): RunFrame | undefined;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "footprintjs",
3
- "version": "10.7.1",
4
- "description": "Explainable backend flows — automatic causal traces, decision evidence, and MCP tool generation for AI agents",
3
+ "version": "11.0.0",
4
+ "description": "TypeScript workflow engine that records each run's stages, state changes and decision evidence, so AI agents and people can explain and debug what happened.",
5
5
  "license": "MIT",
6
6
  "author": "Sanjay Krishna Anbalagan",
7
7
  "repository": {
@@ -13,26 +13,24 @@
13
13
  "url": "https://github.com/footprintjs/footPrint/issues"
14
14
  },
15
15
  "keywords": [
16
- "explainability",
17
- "xai",
18
- "ai-agent",
19
- "mcp",
20
- "decision-engine",
21
- "rule-engine",
22
- "audit-trail",
23
- "causal-trace",
24
- "flowchart",
25
- "pipeline",
16
+ "typescript",
26
17
  "workflow",
27
- "llm",
28
- "openapi",
29
- "narrative",
30
- "observability",
31
- "tracing",
18
+ "workflow-engine",
19
+ "flowchart",
20
+ "orchestration",
21
+ "execution-trace",
22
+ "execution-provenance",
32
23
  "state-management",
24
+ "decision-evidence",
25
+ "debugging",
26
+ "observability",
27
+ "mcp",
28
+ "ai-agent",
29
+ "llm",
30
+ "explainability",
31
+ "causal-trace",
33
32
  "time-travel-debugging",
34
- "typescript",
35
- "footprint"
33
+ "footprintjs"
36
34
  ],
37
35
  "engines": {
38
36
  "node": ">=22"
@@ -42,8 +40,10 @@
42
40
  "build": "rm -rf dist && tsc && tsc -p tsconfig.esm.json && node scripts/postbuild-esm.mjs",
43
41
  "prepare": "husky",
44
42
  "watch": "tsc -w",
43
+ "pretest": "npm --prefix test/fixtures/published-reference ci --ignore-scripts --strict-peer-deps --registry=https://registry.npmjs.org",
45
44
  "test": "vitest run",
46
45
  "test:watch": "vitest --watch",
46
+ "test:contract:foottrace": "node --test contract/foottrace.test.mjs && node contract/foottrace.types.mjs",
47
47
  "test:examples": "tsc -p examples/tsconfig.json && npm run build && vitest run --config vitest.examples.config.ts",
48
48
  "example": "npx tsx",
49
49
  "release:patch": "bash scripts/release.sh patch",
@@ -80,7 +80,6 @@
80
80
  "!dist/test",
81
81
  "!dist/types/test",
82
82
  "!dist/esm/types/test",
83
- "CLAUDE.md",
84
83
  "AGENTS.md"
85
84
  ],
86
85
  "main": "dist/index.js",
@@ -189,7 +188,7 @@
189
188
  },
190
189
  "sideEffects": false,
191
190
  "dependencies": {
192
- "foottrace": "^1.8.0"
191
+ "foottrace": "^1.11.1"
193
192
  },
194
193
  "peerDependencies": {
195
194
  "zod": "^3.0.0 || ^4.0.0"
@@ -216,7 +215,6 @@
216
215
  "eslint-plugin-simple-import-sort": "^8.0.0",
217
216
  "fast-check": "^4.4.0",
218
217
  "footprintjs-baseline": "npm:footprintjs@9.28.0",
219
- "footprintjs-published": "npm:footprintjs@^10.0.0",
220
218
  "husky": "^9.1.7",
221
219
  "lint-staged": "^16.3.2",
222
220
  "markdown-it": "^14.3.1",