footprintjs 14.1.0 → 14.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +1 -0
- package/README.md +2 -0
- package/dist/declared-attempts.js +34 -0
- package/dist/esm/declared-attempts.d.ts +4 -0
- package/dist/esm/declared-attempts.js +30 -0
- package/dist/esm/index.d.ts +14 -0
- package/dist/esm/index.js +5 -1
- package/dist/esm/lib/attempt/decision.d.ts +4 -4
- package/dist/esm/lib/attempt/decision.js +8 -86
- package/dist/esm/lib/attempt/declared.d.ts +9 -0
- package/dist/esm/lib/attempt/declared.js +153 -0
- package/dist/esm/lib/attempt/evidence.d.ts +2 -0
- package/dist/esm/lib/attempt/evidence.js +11 -1
- package/dist/esm/lib/attempt/outsideInputNames.d.ts +4 -0
- package/dist/esm/lib/attempt/outsideInputNames.js +54 -0
- package/dist/esm/lib/attempt/runner.js +5 -5
- package/dist/esm/lib/attempt/types.d.ts +36 -0
- package/dist/esm/lib/attempt/types.js +1 -1
- package/dist/esm/lib/builder/FlowChartBuilder.d.ts +27 -42
- package/dist/esm/lib/builder/FlowChartBuilder.js +45 -60
- package/dist/esm/lib/builder/namedDeclarations.d.ts +22 -0
- package/dist/esm/lib/builder/namedDeclarations.js +69 -0
- package/dist/esm/lib/builder/types.d.ts +8 -0
- package/dist/esm/lib/builder/types.js +1 -1
- package/dist/esm/lib/decide/decide.js +12 -73
- package/dist/esm/lib/decide/fromFacts.d.ts +75 -0
- package/dist/esm/lib/decide/fromFacts.js +114 -0
- package/dist/esm/lib/decide/index.d.ts +6 -1
- package/dist/esm/lib/decide/index.js +5 -2
- package/dist/esm/lib/decide/record.d.ts +81 -0
- package/dist/esm/lib/decide/record.js +83 -0
- package/dist/esm/lib/engine/executionResults.d.ts +21 -0
- package/dist/esm/lib/engine/executionResults.js +2 -0
- package/dist/esm/lib/engine/graph/StageNode.d.ts +4 -0
- package/dist/esm/lib/engine/graph/StageNode.js +26 -1
- package/dist/esm/lib/engine/graph/prefixNodeTree.d.ts +1 -1
- package/dist/esm/lib/engine/graph/prefixNodeTree.js +3 -2
- package/dist/esm/lib/engine/handlers/NodeResolver.d.ts +1 -1
- package/dist/esm/lib/engine/handlers/NodeResolver.js +9 -9
- package/dist/esm/lib/engine/handlers/ParallelForEachHandler.d.ts +1 -1
- package/dist/esm/lib/engine/handlers/ParallelForEachHandler.js +6 -6
- package/dist/esm/lib/engine/handlers/ResumeEntry.d.ts +1 -1
- package/dist/esm/lib/engine/handlers/ResumeEntry.js +7 -3
- package/dist/esm/lib/engine/handlers/RuntimeStructureManager.js +5 -1
- package/dist/esm/lib/engine/handlers/StageRunner.js +3 -1
- package/dist/esm/lib/engine/handlers/SubflowExecutor.d.ts +1 -1
- package/dist/esm/lib/engine/handlers/SubflowExecutor.js +4 -5
- package/dist/esm/lib/engine/narrative/CombinedNarrativeRecorder.d.ts +1 -1
- package/dist/esm/lib/engine/traversal/FlowchartTraverser.js +7 -12
- package/dist/esm/lib/engine/traversal/continuationHop.d.ts +41 -0
- package/dist/esm/lib/engine/traversal/continuationHop.js +10 -0
- package/dist/esm/lib/engine/types.d.ts +7 -21
- package/dist/esm/lib/engine/types.js +2 -2
- package/dist/esm/lib/filter/firstMatch.d.ts +98 -0
- package/dist/esm/lib/filter/firstMatch.js +174 -0
- package/dist/esm/lib/memory/StageContext.d.ts +12 -13
- package/dist/esm/lib/memory/StageContext.js +82 -129
- package/dist/esm/lib/memory/stageCallLifetime.d.ts +8 -0
- package/dist/esm/lib/memory/stageCallLifetime.js +26 -0
- package/dist/esm/lib/memory/stageOutsideInputs.d.ts +9 -0
- package/dist/esm/lib/memory/stageOutsideInputs.js +54 -0
- package/dist/esm/lib/memory/stageSnapshot.d.ts +49 -0
- package/dist/esm/lib/memory/stageSnapshot.js +100 -0
- package/dist/esm/lib/recorder/AttemptRecorder.d.ts +82 -0
- package/dist/esm/lib/recorder/AttemptRecorder.js +24 -7
- package/dist/esm/lib/recorder/attemptMetricRows.js +22 -1
- package/dist/esm/lib/recorder/attemptMetrics.d.ts +4 -1
- package/dist/esm/lib/recorder/attemptMetrics.js +19 -6
- package/dist/esm/lib/recorder/attemptMetricsTypes.d.ts +5 -0
- package/dist/esm/lib/recorder/attemptMetricsTypes.js +1 -1
- package/dist/esm/lib/recorder/attemptOTel.js +22 -12
- package/dist/esm/lib/runner/RunnableChart.d.ts +2 -1
- package/dist/esm/lib/runner/RunnableChart.js +29 -20
- package/dist/esm/lib/runner/describeChart.d.ts +25 -0
- package/dist/esm/lib/runner/describeChart.js +145 -0
- package/dist/esm/lib/runner/resume.js +4 -2
- package/dist/esm/lib/scope/ScopeFacade.d.ts +8 -2
- package/dist/esm/lib/scope/ScopeFacade.js +30 -15
- package/dist/esm/lib/sinks/fileSink.d.ts +17 -1
- package/dist/esm/lib/sinks/fileSink.js +136 -67
- package/dist/esm/lib/sinks/indexedAdmission.d.ts +6 -1
- package/dist/esm/lib/sinks/indexedAdmission.js +30 -7
- package/dist/esm/lib/sinks/indexedIO.js +4 -2
- package/dist/esm/lib/sinks/indexedRecordFile.js +29 -108
- package/dist/esm/lib/sinks/indexedScan.js +3 -9
- package/dist/esm/lib/sinks/indexedSession.d.ts +29 -0
- package/dist/esm/lib/sinks/indexedSession.js +105 -0
- package/dist/esm/lib/sinks/publishedRecordFile.d.ts +40 -0
- package/dist/esm/lib/sinks/publishedRecordFile.js +106 -0
- package/dist/esm/lib/sinks/publishedRecordIndex.d.ts +8 -0
- package/dist/esm/lib/sinks/publishedRecordIndex.js +98 -0
- package/dist/esm/lib/sinks/publishedRecordRows.d.ts +13 -0
- package/dist/esm/lib/sinks/publishedRecordRows.js +188 -0
- package/dist/esm/lib/sinks/publishedRecordSelection.d.ts +21 -0
- package/dist/esm/lib/sinks/publishedRecordSelection.js +69 -0
- package/dist/esm/lib/sinks/publishedRecordWriter.d.ts +49 -0
- package/dist/esm/lib/sinks/publishedRecordWriter.js +237 -0
- package/dist/esm/sinks.d.ts +5 -0
- package/dist/esm/sinks.js +3 -1
- package/dist/index.js +72 -63
- package/dist/lib/attempt/decision.js +8 -86
- package/dist/lib/attempt/declared.js +158 -0
- package/dist/lib/attempt/evidence.js +13 -2
- package/dist/lib/attempt/outsideInputNames.js +59 -0
- package/dist/lib/attempt/runner.js +5 -5
- package/dist/lib/attempt/types.js +1 -1
- package/dist/lib/builder/FlowChartBuilder.js +59 -74
- package/dist/lib/builder/namedDeclarations.js +74 -0
- package/dist/lib/builder/types.js +1 -1
- package/dist/lib/decide/decide.js +12 -73
- package/dist/lib/decide/fromFacts.js +118 -0
- package/dist/lib/decide/index.js +9 -3
- package/dist/lib/decide/record.js +88 -0
- package/dist/lib/engine/executionResults.js +3 -0
- package/dist/lib/engine/graph/StageNode.js +28 -2
- package/dist/lib/engine/graph/prefixNodeTree.js +3 -2
- package/dist/lib/engine/handlers/NodeResolver.js +9 -9
- package/dist/lib/engine/handlers/ParallelForEachHandler.js +6 -6
- package/dist/lib/engine/handlers/ResumeEntry.js +7 -3
- package/dist/lib/engine/handlers/RuntimeStructureManager.js +5 -1
- package/dist/lib/engine/handlers/StageRunner.js +3 -1
- package/dist/lib/engine/handlers/SubflowExecutor.js +4 -5
- package/dist/lib/engine/traversal/FlowchartTraverser.js +10 -15
- package/dist/lib/engine/traversal/continuationHop.js +14 -0
- package/dist/lib/engine/types.js +2 -2
- package/dist/lib/filter/firstMatch.js +182 -0
- package/dist/lib/memory/StageContext.js +97 -144
- package/dist/lib/memory/stageCallLifetime.js +31 -0
- package/dist/lib/memory/stageOutsideInputs.js +62 -0
- package/dist/lib/memory/stageSnapshot.js +105 -0
- package/dist/lib/recorder/AttemptRecorder.js +23 -6
- package/dist/lib/recorder/attemptMetricRows.js +22 -1
- package/dist/lib/recorder/attemptMetrics.js +22 -7
- package/dist/lib/recorder/attemptMetricsTypes.js +1 -1
- package/dist/lib/recorder/attemptOTel.js +21 -11
- package/dist/lib/runner/RunnableChart.js +29 -20
- package/dist/lib/runner/describeChart.js +150 -0
- package/dist/lib/runner/resume.js +4 -2
- package/dist/lib/scope/ScopeFacade.js +29 -14
- package/dist/lib/sinks/fileSink.js +140 -68
- package/dist/lib/sinks/indexedAdmission.js +34 -8
- package/dist/lib/sinks/indexedIO.js +4 -2
- package/dist/lib/sinks/indexedRecordFile.js +28 -107
- package/dist/lib/sinks/indexedScan.js +2 -8
- package/dist/lib/sinks/indexedSession.js +109 -0
- package/dist/lib/sinks/publishedRecordFile.js +110 -0
- package/dist/lib/sinks/publishedRecordIndex.js +103 -0
- package/dist/lib/sinks/publishedRecordRows.js +192 -0
- package/dist/lib/sinks/publishedRecordSelection.js +75 -0
- package/dist/lib/sinks/publishedRecordWriter.js +241 -0
- package/dist/sinks.js +6 -2
- package/dist/types/declared-attempts.d.ts +4 -0
- package/dist/types/index.d.ts +14 -0
- package/dist/types/lib/attempt/decision.d.ts +4 -4
- package/dist/types/lib/attempt/declared.d.ts +9 -0
- package/dist/types/lib/attempt/evidence.d.ts +2 -0
- package/dist/types/lib/attempt/outsideInputNames.d.ts +4 -0
- package/dist/types/lib/attempt/types.d.ts +36 -0
- package/dist/types/lib/builder/FlowChartBuilder.d.ts +27 -42
- package/dist/types/lib/builder/namedDeclarations.d.ts +22 -0
- package/dist/types/lib/builder/types.d.ts +8 -0
- package/dist/types/lib/decide/fromFacts.d.ts +75 -0
- package/dist/types/lib/decide/index.d.ts +6 -1
- package/dist/types/lib/decide/record.d.ts +81 -0
- package/dist/types/lib/engine/executionResults.d.ts +21 -0
- package/dist/types/lib/engine/graph/StageNode.d.ts +4 -0
- package/dist/types/lib/engine/graph/prefixNodeTree.d.ts +1 -1
- package/dist/types/lib/engine/handlers/NodeResolver.d.ts +1 -1
- package/dist/types/lib/engine/handlers/ParallelForEachHandler.d.ts +1 -1
- package/dist/types/lib/engine/handlers/ResumeEntry.d.ts +1 -1
- package/dist/types/lib/engine/handlers/SubflowExecutor.d.ts +1 -1
- package/dist/types/lib/engine/narrative/CombinedNarrativeRecorder.d.ts +1 -1
- package/dist/types/lib/engine/traversal/continuationHop.d.ts +41 -0
- package/dist/types/lib/engine/types.d.ts +7 -21
- package/dist/types/lib/filter/firstMatch.d.ts +98 -0
- package/dist/types/lib/memory/StageContext.d.ts +12 -13
- package/dist/types/lib/memory/stageCallLifetime.d.ts +8 -0
- package/dist/types/lib/memory/stageOutsideInputs.d.ts +9 -0
- package/dist/types/lib/memory/stageSnapshot.d.ts +49 -0
- package/dist/types/lib/recorder/AttemptRecorder.d.ts +82 -0
- package/dist/types/lib/recorder/attemptMetrics.d.ts +4 -1
- package/dist/types/lib/recorder/attemptMetricsTypes.d.ts +5 -0
- package/dist/types/lib/runner/RunnableChart.d.ts +2 -1
- package/dist/types/lib/runner/describeChart.d.ts +25 -0
- package/dist/types/lib/scope/ScopeFacade.d.ts +8 -2
- package/dist/types/lib/sinks/fileSink.d.ts +17 -1
- package/dist/types/lib/sinks/indexedAdmission.d.ts +6 -1
- package/dist/types/lib/sinks/indexedSession.d.ts +29 -0
- package/dist/types/lib/sinks/publishedRecordFile.d.ts +40 -0
- package/dist/types/lib/sinks/publishedRecordIndex.d.ts +8 -0
- package/dist/types/lib/sinks/publishedRecordRows.d.ts +13 -0
- package/dist/types/lib/sinks/publishedRecordSelection.d.ts +21 -0
- package/dist/types/lib/sinks/publishedRecordWriter.d.ts +49 -0
- package/dist/types/sinks.d.ts +5 -0
- package/package.json +17 -3
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { SerializedPipelineStructure, StageNode } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Attach declared tags to a stage node + its spec node.
|
|
4
|
+
*
|
|
5
|
+
* The ONE place tags land on a node — the twin of {@link applyRetryPolicy} —
|
|
6
|
+
* shared by the `.tag()` cursor modifier and every `options.tags` declaration
|
|
7
|
+
* site, so the refusals and the spec's mirror can never drift between them.
|
|
8
|
+
*
|
|
9
|
+
* A tag is a NAME declared at build time, never a value, so every refusal is
|
|
10
|
+
* about the name's shape: an empty string names nothing; a non-string is a
|
|
11
|
+
* value, and a value on a stage would ride the commit log past every
|
|
12
|
+
* redaction point; the branch-segment marker is the runtimeStageId grammar's
|
|
13
|
+
* one reserved byte, and a consumer that puts a tag into a path (a URL, a
|
|
14
|
+
* store key) would inherit exactly the ambiguity the reservation exists to
|
|
15
|
+
* prevent; a name declared twice is the typo it usually is. Refused at BUILD
|
|
16
|
+
* time, like `retry.attempts`, so the mistake fails while the chart is being
|
|
17
|
+
* written. An EMPTY list lands nothing: "absent when empty" is the law the
|
|
18
|
+
* commit bundle keeps, and the spec keeps it too.
|
|
19
|
+
*/
|
|
20
|
+
export declare function applyTags(node: StageNode<any, any>, spec: SerializedPipelineStructure, tags: readonly string[] | undefined, where: string): void;
|
|
21
|
+
/** Keep the stage and its spec on the same validated, public source names. */
|
|
22
|
+
export declare function applyOutsideInputs(node: StageNode, spec: SerializedPipelineStructure, names: readonly string[] | undefined, where: string): void;
|
|
@@ -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,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* decide/fromFacts -- `decide()`'s evaluation without a scope: a rule table over a plain record of named facts.
|
|
3
|
+
*
|
|
4
|
+
* One law, two doors. `decide()` evaluates a table over a stage's scope; `decideFromFacts` evaluates the same table
|
|
5
|
+
* over a record a caller built, on the same first-match core and the same row assembler (`filter/firstMatch.ts`), and
|
|
6
|
+
* returns the same `DecisionEvidence` shape. A property test pins that its evidence equals what `decide()` records in a
|
|
7
|
+
* run whose redaction policy selects every key, apart from a thrown rule's text, which this door never quotes
|
|
8
|
+
* (test/lib/decide/property/decide-from-facts.property.test.ts).
|
|
9
|
+
*
|
|
10
|
+
* A scope brings its run's redaction rule; a record brings none. So this door keeps no value, ever: names and operators
|
|
11
|
+
* only. There is no option that keeps values here. A caller inside a run that wants the run's own evidence calls
|
|
12
|
+
* `decide()` with its scope.
|
|
13
|
+
*/
|
|
14
|
+
import type { DecideRule, DecisionEvidence, DefaultBranch } from './types.js';
|
|
15
|
+
/**
|
|
16
|
+
* What {@link decideFromFacts} returns. Not a decider's return value: inside a decider stage, use `decide()`.
|
|
17
|
+
*
|
|
18
|
+
* @category Decision Branching
|
|
19
|
+
*/
|
|
20
|
+
export interface DecisionFromFacts {
|
|
21
|
+
/** The branch chosen: the first matching rule's `then`, or the default. */
|
|
22
|
+
readonly branch: string;
|
|
23
|
+
/** The `DecisionEvidence` of the decision, names and operators only. {@link decisionRecord} projects it to a record. */
|
|
24
|
+
readonly evidence: DecisionEvidence;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Evaluates `rules` in order over `facts` — first match wins — exactly as `decide()` evaluates them over a scope,
|
|
28
|
+
* and returns the branch and its `DecisionEvidence`. For a "which strategy, and why" chosen outside a stage.
|
|
29
|
+
*
|
|
30
|
+
* - `rules` take `decide()`'s shapes: a filter (`{ express: { eq: true } }`, every key ANDed) or a function
|
|
31
|
+
* (`(f) => f.weightKg > 30`). A rule's `label` is its reason. A filter with no evaluable condition never matches: the
|
|
32
|
+
* catch-all is `defaultBranch`.
|
|
33
|
+
* - `facts` is a plain record of FLAT names. A rule key is a name, never a path. Every own string-keyed DATA property
|
|
34
|
+
* is read once, up front, before any rule runs; class instances, frozen and null-prototype objects and arrays work.
|
|
35
|
+
* Inherited and symbol-keyed properties are not facts: a rule reads them as missing. A `Proxy` as facts is asked
|
|
36
|
+
* `ownKeys` once and `getOwnPropertyDescriptor` once per string key, and nothing else.
|
|
37
|
+
* - `defaultBranch` is `decide()`'s: `'rejected'`, or `{ branch: 'rejected', label: 'No rule fired' }`.
|
|
38
|
+
*
|
|
39
|
+
* **The evidence keeps names and operators only.** Every `actualSummary`, `valueSummary` and `threshold` is the
|
|
40
|
+
* placeholder `'[REDACTED]'` with `redacted: true` (a threshold also says `thresholdRedacted: true`), a function rule's
|
|
41
|
+
* `matched` is `true` or `false` whatever the rule returned, and a rule that threw says `matchError: '[REDACTED]'`: the
|
|
42
|
+
* thrown value is never turned into text. The rules still decide on the real values. One limit no door can close: a
|
|
43
|
+
* NAME is recorded as written, so a value a rule uses as a property key (`(f) => f[f.token]`), or a key that is itself
|
|
44
|
+
* the secret, is recorded as a fact name.
|
|
45
|
+
*
|
|
46
|
+
* A function rule reads facts by property access (`f.weightKg`); each string-keyed read is recorded by name. Its view
|
|
47
|
+
* closes when the rule returns: a view the rule kept reads nothing afterwards.
|
|
48
|
+
*
|
|
49
|
+
* A rule that throws does not match and does not throw out: its row says `matched: false` and carries `matchError`, as
|
|
50
|
+
* in `decide()`. Unlike `decide()`, and like the retry table's own evaluation, this door prints no dev-mode warning for
|
|
51
|
+
* a rule that threw: the row is the report.
|
|
52
|
+
*
|
|
53
|
+
* **Refused, up front, with a `TypeError` whose message names no value** (a fact that cannot be read as data would
|
|
54
|
+
* otherwise read as missing, and decide a different branch than `decide()` would):
|
|
55
|
+
* - facts that are not an object;
|
|
56
|
+
* - an own ACCESSOR property: the message names its key; its getter never runs;
|
|
57
|
+
* - a registered stage scope: inside a stage, use `decide(scope, …)`;
|
|
58
|
+
* - a `Map` or a `Set` (told by its own brand, so a `Proxy` around one is not).
|
|
59
|
+
*
|
|
60
|
+
* `rules` that are not an array of rules fail with the language's own `TypeError`.
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```ts
|
|
64
|
+
* const { branch, evidence } = decideFromFacts(
|
|
65
|
+
* [{ when: { express: { eq: true } }, then: 'courier', label: 'Express delivery was asked for' }],
|
|
66
|
+
* { express: true },
|
|
67
|
+
* { branch: 'post', label: 'No rule fired' },
|
|
68
|
+
* );
|
|
69
|
+
* // branch === 'courier'; decisionRecord(evidence) →
|
|
70
|
+
* // { strategy: 'courier', by: 'rule', rule: 0, label: 'Express delivery was asked for', reads: ['express'] }
|
|
71
|
+
* ```
|
|
72
|
+
*
|
|
73
|
+
* @category Decision Branching
|
|
74
|
+
*/
|
|
75
|
+
export declare function decideFromFacts<F extends object>(rules: readonly DecideRule<F>[], facts: F, defaultBranch: DefaultBranch): DecisionFromFacts;
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* decide/ -- Decision reasoning capture for footprintjs.
|
|
3
3
|
*
|
|
4
|
-
* decide() and select() auto-capture evidence from decider/selector functions
|
|
4
|
+
* decide() and select() auto-capture evidence from decider/selector functions; decideFromFacts() evaluates the
|
|
5
|
+
* same rules over a plain record, and decisionRecord() / fixedRecord() give the record of a decision:
|
|
5
6
|
* - Function when: (s) => s.creditScore > 700 (auto-captures reads)
|
|
6
7
|
* - Filter when: { creditScore: { gt: 700 } } (captures reads + operators + thresholds)
|
|
7
8
|
*/
|
|
8
9
|
export type { DecideRule, DecisionEvidence, DecisionResult, DefaultBranch, FilterCondition, FilterOps, FilterRuleEvidence, FunctionRuleEvidence, ReadInput, RuleEvidence, SelectionEvidence, SelectionResult, WhenClause, WhereFilter, } from './types.js';
|
|
9
10
|
export { DECISION_RESULT } from './types.js';
|
|
10
11
|
export { decide, select } from './decide.js';
|
|
12
|
+
export type { DecisionFromFacts } from './fromFacts.js';
|
|
13
|
+
export { decideFromFacts } from './fromFacts.js';
|
|
14
|
+
export type { DecisionRecord, DecisionVoucher } from './record.js';
|
|
15
|
+
export { decisionRecord, fixedRecord } from './record.js';
|
|
11
16
|
export { evaluateFilter } from '../filter/evaluator.js';
|
|
12
17
|
export { EvidenceCollector } from './evidence.js';
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* decide/record -- the decision record: which strategy was picked, by what, for what reason, from which facts.
|
|
3
|
+
*
|
|
4
|
+
* A projection, not a second structure: `decisionRecord(evidence)` derives the record from a `DecisionEvidence`
|
|
5
|
+
* (`decide()`'s or `decideFromFacts`'s), so nothing is stored twice. `fixedRecord` makes the one record no evidence
|
|
6
|
+
* can give: a choice no table made, because someone stated it.
|
|
7
|
+
*/
|
|
8
|
+
import type { DecisionEvidence } from './types.js';
|
|
9
|
+
/**
|
|
10
|
+
* Who stated a fixed choice: the application (its configuration), or a provider (an adapter's own setting).
|
|
11
|
+
*
|
|
12
|
+
* @category Decision Branching
|
|
13
|
+
*/
|
|
14
|
+
export type DecisionVoucher = 'app' | 'provider';
|
|
15
|
+
/**
|
|
16
|
+
* One "which strategy, and why". A user may add its own fields beside these; it does not rename them or change what
|
|
17
|
+
* they mean. `strategy`, `by` and `reads` are always present; `rule` only for `by: 'rule'`, `label` only when the table
|
|
18
|
+
* or the caller gave a reason, `voucher` only on a fixed choice whose caller said who stated it.
|
|
19
|
+
*
|
|
20
|
+
* @category Decision Branching
|
|
21
|
+
*/
|
|
22
|
+
export interface DecisionRecord {
|
|
23
|
+
/** The branch chosen. */
|
|
24
|
+
readonly strategy: string;
|
|
25
|
+
/**
|
|
26
|
+
* What chose it: `'rule'`, a rule of the table; `'default'`, the table's default, because no rule matched;
|
|
27
|
+
* `'fixed'`, no table — someone stated the choice ({@link fixedRecord}).
|
|
28
|
+
*/
|
|
29
|
+
readonly by: 'rule' | 'default' | 'fixed';
|
|
30
|
+
/** The winning rule's index in its table (`ruleIndex`, counted from 0). Present only when `by` is `'rule'`. */
|
|
31
|
+
readonly rule?: number;
|
|
32
|
+
/** The reason, in the table author's words: the winning rule's `label`, or the default's. Absent when none was given. */
|
|
33
|
+
readonly label?: string;
|
|
34
|
+
/**
|
|
35
|
+
* The names of the facts that decided it, de-duplicated in first-read order: names, never values. A name is recorded
|
|
36
|
+
* as written, so a value a rule used as a property key (`(f) => f[f.token]`) is recorded as a name.
|
|
37
|
+
*/
|
|
38
|
+
readonly reads: readonly string[];
|
|
39
|
+
/** Who stated a fixed choice, when the caller says. Only on `by: 'fixed'`. */
|
|
40
|
+
readonly voucher?: DecisionVoucher;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The decision record of `evidence`, derived from the evidence alone.
|
|
44
|
+
*
|
|
45
|
+
* - **The winner.** The winning rule is the last entry of `evidence.rules` when its `matched` is true (first match
|
|
46
|
+
* wins, so evaluation stopped there): `by: 'rule'`, `rule` its `ruleIndex`, `label` its label. `by` is never
|
|
47
|
+
* inferred from `chosen === default`: a rule whose `then` equals the default branch is still `by: 'rule'`.
|
|
48
|
+
* - **The default.** Otherwise `by: 'default'` and `label` is `evidence.defaultLabel`.
|
|
49
|
+
* - **`reads`.** For a rule, the names its row read: a filter's condition keys, a function's input keys. For the
|
|
50
|
+
* default, the de-duplicated union, in first-read order, of every row's condition and input keys: what was looked
|
|
51
|
+
* at, since no rule won.
|
|
52
|
+
*
|
|
53
|
+
* A name the rows do not hold cannot be in the record, and the record says nothing more about it. The rows lose a name
|
|
54
|
+
* that was read, or meant to be read, in these cases:
|
|
55
|
+
* - a filter rule that THREW (for example an `in` list over 1000 entries) records no conditions, so none of its names;
|
|
56
|
+
* - a key the filter refuses (the prototype denylist: `__proto__`, `constructor`, `toString`, …) records no condition;
|
|
57
|
+
* - a key whose operators are an empty object (`{ a: {} }`) is read but records no condition, and a key whose operators
|
|
58
|
+
* are not an object (`{ a: 5 }`) is not read at all;
|
|
59
|
+
* - a function rule's symbol-keyed reads are not recorded, and in `decide()` neither is a read with no key (the whole
|
|
60
|
+
* state at once);
|
|
61
|
+
* - a read a function rule makes after it returned (`decideFromFacts`, the retry table) is not recorded.
|
|
62
|
+
*
|
|
63
|
+
* A function rule that threw keeps the names it read before the throw.
|
|
64
|
+
*
|
|
65
|
+
* @category Decision Branching
|
|
66
|
+
*/
|
|
67
|
+
export declare function decisionRecord(evidence: DecisionEvidence): DecisionRecord;
|
|
68
|
+
/**
|
|
69
|
+
* The record of a choice no table made: `by: 'fixed'`, no rule, no reads. A bare string in a configuration
|
|
70
|
+
* (`delivery: 'courier'`) is `fixedRecord('courier', undefined, 'app')`. It is not a rule: an empty filter never
|
|
71
|
+
* matches, so no table can express "always".
|
|
72
|
+
*
|
|
73
|
+
* @param strategy - the branch someone stated.
|
|
74
|
+
* @param label - the reason, when there is one.
|
|
75
|
+
* @param voucher - who stated it, `'app'` or `'provider'`, when the caller knows.
|
|
76
|
+
* @throws TypeError when `strategy` is not a string, `label` is given and not a string, or `voucher` is given and is
|
|
77
|
+
* not one of the two.
|
|
78
|
+
*
|
|
79
|
+
* @category Decision Branching
|
|
80
|
+
*/
|
|
81
|
+
export declare function fixedRecord(strategy: string, label?: string, voucher?: DecisionVoucher): DecisionRecord;
|
|
@@ -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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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?: "
|
|
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 —
|
|
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 & {
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* filter/firstMatch -- the ONE first-match law over a `decide()` rule table, the ONE row assembler, and one rule's
|
|
3
|
+
* evaluation without a scope.
|
|
4
|
+
*
|
|
5
|
+
* `firstMatch(rules, evaluate, defaultBranch)` asks `evaluate` for each rule in order until one matches, and builds the
|
|
6
|
+
* `DecisionEvidence`: the rows evaluated so far, the branch chosen, the default and its label, in that key order.
|
|
7
|
+
* Three doors call it, each with its own way of evaluating one rule:
|
|
8
|
+
*
|
|
9
|
+
* | Door | One rule is evaluated over |
|
|
10
|
+
* |---|---|
|
|
11
|
+
* | `decide()` (decide/decide.ts) | the stage's scope: its recorders, its run's redaction rule |
|
|
12
|
+
* | `decideAttempt` (attempt/decision.ts) | an attempt's inputs, every value kept (`ruleOver(read)`) |
|
|
13
|
+
* | `decideFromFacts` (decide/fromFacts.ts) | a plain record of facts, no value kept (`ruleOver(read, KEEP_NO_VALUE)`) |
|
|
14
|
+
*
|
|
15
|
+
* `functionRow` and `filterRow` build every row, for these three and for `select()`. A function rule's `matched` is
|
|
16
|
+
* whether its return was truthy, which is what routes the decision, and never the return itself: a rule over `any`
|
|
17
|
+
* facts can return a value (`(f) => f.token`), and the row must not carry it.
|
|
18
|
+
*
|
|
19
|
+
* `ruleOver(read, keeping?)` is one rule as `decide()` evaluates it, minus the scope: a filter rule's rows come from
|
|
20
|
+
* `evaluateFilter`, a function rule reads through a view that records each read and closes when the rule returns.
|
|
21
|
+
* `keeping` is what a row keeps of a value it read: every value (`KEEP_EVERY_VALUE`, the default), or none
|
|
22
|
+
* (`KEEP_NO_VALUE`: names and operators only, the placeholder for every value and threshold and for a thrown rule's
|
|
23
|
+
* text).
|
|
24
|
+
*
|
|
25
|
+
* A leaf beside `evaluator.ts`, not in decide/: attempt/ calls it, and decide/decide.ts imports the scope runtime, so an
|
|
26
|
+
* attempt → decide edge would close the attempt ⇄ decide ⇄ scope module cycle that moved the evaluator here (P2).
|
|
27
|
+
*/
|
|
28
|
+
import type { DecideRule, DecisionEvidence, DefaultBranch, FilterCondition, FilterRuleEvidence, FunctionRuleEvidence, ReadInput, RuleEvidence } from '../decide/types.js';
|
|
29
|
+
/** One rule's evaluation, as the first-match loop asks for it. */
|
|
30
|
+
export type RuleEvaluator<R> = (rule: R, index: number) => RuleEvidence;
|
|
31
|
+
/** A first-match pass: the branch, the label of what chose it (the rule's, or the default's), and the evidence. */
|
|
32
|
+
export interface FirstMatch {
|
|
33
|
+
readonly branch: string;
|
|
34
|
+
readonly label: string | undefined;
|
|
35
|
+
readonly evidence: DecisionEvidence;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Collapses both {@link DefaultBranch} forms to one shape, once. A bare string yields `label: undefined`, which the
|
|
39
|
+
* evidence then omits — so the string call site produces exactly the evidence it produced before the parameter was
|
|
40
|
+
* widened.
|
|
41
|
+
*
|
|
42
|
+
* ONLY the object form is unwrapped; every other value passes through as the branch, untouched. That is deliberate:
|
|
43
|
+
* JavaScript callers reach `decide()` with the third argument MISSING (a rule set that covers every case never consults
|
|
44
|
+
* a default), and before the parameter widened that `undefined` simply landed on `evidence.default`. It still does — a
|
|
45
|
+
* normalization that only understood strings would turn those call sites into a TypeError.
|
|
46
|
+
*/
|
|
47
|
+
export declare function normalizeDefaultBranch(defaultBranch: DefaultBranch): {
|
|
48
|
+
branch: string;
|
|
49
|
+
label?: string;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Evaluates `rules` in order — first match wins — and builds the evidence. A rule whose `then` equals the default is
|
|
53
|
+
* still a rule's choice: what chose a branch is read from the rows, never from the branch.
|
|
54
|
+
*/
|
|
55
|
+
export declare function firstMatch<R extends {
|
|
56
|
+
readonly then: string;
|
|
57
|
+
readonly label?: string;
|
|
58
|
+
}>(rules: readonly R[], evaluate: RuleEvaluator<R>, defaultBranch: {
|
|
59
|
+
readonly branch: string;
|
|
60
|
+
readonly label?: string;
|
|
61
|
+
}): FirstMatch;
|
|
62
|
+
/** What a rule's row needs of the rule: its branch and its label. */
|
|
63
|
+
interface RuleHead {
|
|
64
|
+
readonly then: string;
|
|
65
|
+
readonly label?: string;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* A function rule's row. `matched` is `!!returned`: whether the rule's return was truthy, which is all that routes a
|
|
69
|
+
* decision. The return itself is never stored, so a rule that returns a value (`(f) => f.token`) leaves no value here.
|
|
70
|
+
*/
|
|
71
|
+
export declare function functionRow(rule: RuleHead, index: number, returned: unknown, inputs: ReadInput[], matchError: string | undefined): FunctionRuleEvidence;
|
|
72
|
+
/** A filter rule's row. */
|
|
73
|
+
export declare function filterRow(rule: RuleHead, index: number, matched: boolean, conditions: FilterCondition[], matchError: string | undefined): FilterRuleEvidence;
|
|
74
|
+
/** What a row keeps of the values a rule read. */
|
|
75
|
+
export interface ValueKeeping {
|
|
76
|
+
/** Is the value under `key` masked? What `redacted` says on a row. */
|
|
77
|
+
readonly masked: (key: string) => boolean;
|
|
78
|
+
/** A thrown rule's text, as the row keeps it. */
|
|
79
|
+
readonly matchError: (error: unknown) => string;
|
|
80
|
+
}
|
|
81
|
+
/** No mask: every value, threshold and thrown text as it is. What `decideAttempt` keeps. */
|
|
82
|
+
export declare const KEEP_EVERY_VALUE: ValueKeeping;
|
|
83
|
+
/**
|
|
84
|
+
* No value: names and operators only. Every value and threshold is the placeholder (`evaluateFilter`'s own hole for a
|
|
85
|
+
* masked key), and a thrown rule's text is the placeholder: the thrown value is never turned into text, so none of its
|
|
86
|
+
* code runs. What `decideFromFacts` keeps.
|
|
87
|
+
*/
|
|
88
|
+
export declare const KEEP_NO_VALUE: ValueKeeping;
|
|
89
|
+
/**
|
|
90
|
+
* One rule's evaluation over `read`, without a scope: `read(key)` returns one value and is called only for the keys
|
|
91
|
+
* the rule touches, in the order it touches them. `keeping` is what each row keeps of a value (default: every value).
|
|
92
|
+
*
|
|
93
|
+
* As in `decide()`: a rule that throws does not match, and its row says why (`matchError`); a filter rule that throws
|
|
94
|
+
* records no conditions; a function rule that throws keeps the reads it made before the throw. A function rule's view
|
|
95
|
+
* closes when the rule returns or throws: a view it kept reads nothing afterwards and adds nothing to its row.
|
|
96
|
+
*/
|
|
97
|
+
export declare function ruleOver<S extends object>(read: (key: string) => unknown, keeping?: ValueKeeping): RuleEvaluator<DecideRule<S>>;
|
|
98
|
+
export {};
|
|
@@ -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
|
|
586
|
-
*
|
|
587
|
-
*
|
|
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
|
|
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
|
-
/**
|
|
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;
|