@patterkit/runtime 0.9.0 → 0.11.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/dist/index.d.cts CHANGED
@@ -1,79 +1,11 @@
1
1
  import { ScalarValue } from '@wildwinter/expr';
2
- import { ScopeResolver, ScopeRegistry, ScopeDeclaration, PropertyBag, PropertyRow } from '@wildwinter/scoperegistry';
2
+ import { ScopeResolver, ScopeRegistry, ScopeDeclaration, PropertyBag, LogMount, PropertyRow } from '@wildwinter/scoperegistry';
3
3
  export { PropertyRow } from '@wildwinter/scoperegistry';
4
- import { GameData, Bundle, CompiledGroup, CompiledSnippet, CompiledBlock, PropertyType, ScalarValue as ScalarValue$1, GameDataNodeKind, GameDataField } from '@patterkit/model';
5
- export { Bundle } from '@patterkit/model';
4
+ import { GameData, Bundle, CompiledGroup, CompiledSnippet, CompiledBlock, FlowSnapshot, EngineSave, SaveGame, PropertyType, ScalarValue as ScalarValue$1, GameDataNodeKind, GameDataField } from '@patterkit/model';
5
+ export { Bundle, EngineSave, FlowCursor, FlowSnapshot, SaveEnvelope, SaveGame, SavedChoice, SavedChoiceOption, SavedChoicePrompt, SelectorSnapshot, StackFrame } from '@patterkit/model';
6
6
 
7
7
  type SelectableNode = CompiledGroup | CompiledSnippet;
8
- /** A property-state snapshot: owned scope -> property name -> value. */
9
- type EngineSave = Record<string, Record<string, ScalarValue>>;
10
- /** Serialised `sequence` selector visit state for one group (spec §4 / §7). */
11
- interface SelectorSnapshot {
12
- seq?: number;
13
- bag?: string[];
14
- last?: string;
15
- }
16
- /** One entry on a flow's continuation stack: a position within a container's children. */
17
- interface StackFrame {
18
- sceneId: string;
19
- /** A block id or a run-group id (both are sequential containers). */
20
- containerId: string;
21
- index: number;
22
- /** SNAPSHOT-ONLY (never set on a live frame): the id of the child at `index` when the save was
23
- * taken. On restore the child is re-found by this id, so a save survives siblings being inserted,
24
- * removed, or reordered before the cursor (live bundle refresh / patched-game saves). Absent (an
25
- * older save, or a frame saved at its container's end) falls back to the raw `index`. */
26
- nextId?: string;
27
- }
28
- /** The serialised cursor + scopes + PRNG of a single flow. */
29
- interface FlowSnapshot {
30
- /** This flow's owned-scope values = the NOT-shared `@patter` globals (under token "patter"). */
31
- scopes: EngineSave;
32
- /** Per-scene NOT-shared `@scene` bags (scene id -> name -> value); persist across re-entries (spec §7). */
33
- sceneBags: Record<string, Record<string, ScalarValue>>;
34
- /** This flow's built-in PRNG position (mulberry32 state). */
35
- rngState: number;
36
- /** This flow's per-node entry counts (node id -> times entered by this flow). */
37
- visits: Record<string, number>;
38
- cursor: {
39
- flowEnded: boolean;
40
- currentSceneId: string | null;
41
- /** The continuation stack (call frames + the active block run). */
42
- stack: StackFrame[];
43
- activeSnippetId: string | null;
44
- beatIndex: number;
45
- /** The pending choice's exact option set, REPLAYED on load (schema 9.3). */
46
- pendingChoice: SavedChoice | null;
47
- /** The chosen option owning a prompt still to be replayed (save taken between choose + advance).
48
- * Optional / absent in older saves -> no pending prompt. */
49
- pendingPromptOwnerId?: string | null;
50
- /** This flow's `sequence` selector cursors. */
51
- selectors: Record<string, SelectorSnapshot>;
52
- };
53
- }
54
- /**
55
- * A pending choice as saved: the option set the player was shown, restored
56
- * verbatim - re-deriving on load would re-evaluate conditions (consuming PRNG
57
- * draws a second time) and could mutate the choice under the player.
58
- */
59
- interface SavedChoice {
60
- groupId: string;
61
- options: ChoiceOption[];
62
- }
63
- /** A full resumable save-game: shared `@patter` state + every live flow. */
64
- interface SaveGame {
65
- version: number;
66
- /** Shared `@patter` globals (owned scope "patter"). */
67
- shared: EngineSave;
68
- /** World-wide per-node entry counts (node id -> times entered by any flow). */
69
- sharedVisits: Record<string, number>;
70
- /** Shared selector cursors (node id -> snapshot) for `shared` memoried selectors. */
71
- sharedSelectors: Record<string, SelectorSnapshot>;
72
- /** Shared, scene-namespaced `@scene` bags (scene id -> name -> value) - the shared scene props. */
73
- stageBags: Record<string, Record<string, ScalarValue>>;
74
- /** Each live flow's snapshot, keyed by flow id. */
75
- flows: Record<string, FlowSnapshot>;
76
- }
8
+
77
9
  /** What `Flow.advance()` surfaces to the host at each stop. */
78
10
  type StepResult = {
79
11
  type: "line";
@@ -569,6 +501,18 @@ declare class Engine {
569
501
  getFlow(id: string): Flow | undefined;
570
502
  /** All currently-open flows. */
571
503
  flows(): Flow[];
504
+ /**
505
+ * The SHARED kernel bags with the path each answers to in a log: the `@patter` globals,
506
+ * and one per scene for the shared `@scene` props. Parity with the Storylet Engine's
507
+ * listBags of the same name - it is what a state logger mounts.
508
+ *
509
+ * A stage bag's log path is `@scene:<sceneId>.`, not the bag's own `@scene.`: a property
510
+ * is ADDRESSED relative to a flow's current scene, but a log spans scenes and has to say
511
+ * which one. That is why a mount may override the bag's prefix.
512
+ *
513
+ * loadGame() replaces every bag, so re-enumerate after a load.
514
+ */
515
+ listBags(): LogMount[];
572
516
  /** Close (remove) a flow. The flow object is FINISHED, not merely unregistered, so a host still
573
517
  * holding it cannot keep advancing it into the shared world (see {@link Flow.close}). */
574
518
  closeFlow(id: string): void;
@@ -702,7 +646,12 @@ declare class Flow {
702
646
  * to its caller (call-return) or ends the flow.
703
647
  */
704
648
  private settle;
705
- /** The options of a pending choice (empty when not at a choice point). */
649
+ /**
650
+ * THIS flow's own kernel bags: its not-shared `@patter` half and its per-scene `@scene`
651
+ * props, each prefixed with the flow id so one path space holds every flow. The shared
652
+ * halves are the Engine's listBags.
653
+ */
654
+ listBags(): LogMount[];
706
655
  /** This flow's decisions, in order. Empty unless the run was opened with `log: true`.
707
656
  * The engine's log carries the same events tagged with the flow; this one is what a
708
657
  * single conversation reads as. */
@@ -712,6 +661,7 @@ declare class Flow {
712
661
  /** Record one decision, on this flow's log and the engine's. Cheap to call with logging
713
662
  * off: the entry is never built. */
714
663
  private emit;
664
+ /** The options of a pending choice (empty when not at a choice point). */
715
665
  getChoices(): ChoiceOption[];
716
666
  /** Pick an eligible option by id; the next `advance()` runs it. */
717
667
  choose(id: string): void;
@@ -1000,4 +950,4 @@ declare function effectiveGameData(fields: GameDataField[], node: GameData | und
1000
950
  */
1001
951
  declare function buildTagIndex(bundle: Bundle): Map<string, string[]>;
1002
952
 
1003
- export { type AddressSummary, type AdvanceToStopResult, type BeatInfo, type BundleCounts, type BundleDescription, type BundleIdentity, type ChoiceOption, Engine, type EngineLogEntry, type EngineOptions, type EngineSave, type EngineTraceHandler, type FlatBeat, Flow, type FlowSnapshot, type GameDataFieldSummary, type GameDataSummary, type HostScopeSummary, type LogEntry, type OpenFlowOptions, type OutlineBlock, type OutlineNode, type OutlineScene, type OwnedProperties, type PropertySummary, type SaveGame, type SavedChoice, type SelectorSnapshot, type StackFrame, type StepResult, type TraceEvent, type TraceHandler, type WorldResolver, buildTagIndex, describeBundle, effectiveGameData, gameDataFields, gameDataValue };
953
+ export { type AddressSummary, type AdvanceToStopResult, type BeatInfo, type BundleCounts, type BundleDescription, type BundleIdentity, type ChoiceOption, Engine, type EngineLogEntry, type EngineOptions, type EngineTraceHandler, type FlatBeat, Flow, type GameDataFieldSummary, type GameDataSummary, type HostScopeSummary, type LogEntry, type OpenFlowOptions, type OutlineBlock, type OutlineNode, type OutlineScene, type OwnedProperties, type PropertySummary, type StepResult, type TraceEvent, type TraceHandler, type WorldResolver, buildTagIndex, describeBundle, effectiveGameData, gameDataFields, gameDataValue };
package/dist/index.d.ts CHANGED
@@ -1,79 +1,11 @@
1
1
  import { ScalarValue } from '@wildwinter/expr';
2
- import { ScopeResolver, ScopeRegistry, ScopeDeclaration, PropertyBag, PropertyRow } from '@wildwinter/scoperegistry';
2
+ import { ScopeResolver, ScopeRegistry, ScopeDeclaration, PropertyBag, LogMount, PropertyRow } from '@wildwinter/scoperegistry';
3
3
  export { PropertyRow } from '@wildwinter/scoperegistry';
4
- import { GameData, Bundle, CompiledGroup, CompiledSnippet, CompiledBlock, PropertyType, ScalarValue as ScalarValue$1, GameDataNodeKind, GameDataField } from '@patterkit/model';
5
- export { Bundle } from '@patterkit/model';
4
+ import { GameData, Bundle, CompiledGroup, CompiledSnippet, CompiledBlock, FlowSnapshot, EngineSave, SaveGame, PropertyType, ScalarValue as ScalarValue$1, GameDataNodeKind, GameDataField } from '@patterkit/model';
5
+ export { Bundle, EngineSave, FlowCursor, FlowSnapshot, SaveEnvelope, SaveGame, SavedChoice, SavedChoiceOption, SavedChoicePrompt, SelectorSnapshot, StackFrame } from '@patterkit/model';
6
6
 
7
7
  type SelectableNode = CompiledGroup | CompiledSnippet;
8
- /** A property-state snapshot: owned scope -> property name -> value. */
9
- type EngineSave = Record<string, Record<string, ScalarValue>>;
10
- /** Serialised `sequence` selector visit state for one group (spec §4 / §7). */
11
- interface SelectorSnapshot {
12
- seq?: number;
13
- bag?: string[];
14
- last?: string;
15
- }
16
- /** One entry on a flow's continuation stack: a position within a container's children. */
17
- interface StackFrame {
18
- sceneId: string;
19
- /** A block id or a run-group id (both are sequential containers). */
20
- containerId: string;
21
- index: number;
22
- /** SNAPSHOT-ONLY (never set on a live frame): the id of the child at `index` when the save was
23
- * taken. On restore the child is re-found by this id, so a save survives siblings being inserted,
24
- * removed, or reordered before the cursor (live bundle refresh / patched-game saves). Absent (an
25
- * older save, or a frame saved at its container's end) falls back to the raw `index`. */
26
- nextId?: string;
27
- }
28
- /** The serialised cursor + scopes + PRNG of a single flow. */
29
- interface FlowSnapshot {
30
- /** This flow's owned-scope values = the NOT-shared `@patter` globals (under token "patter"). */
31
- scopes: EngineSave;
32
- /** Per-scene NOT-shared `@scene` bags (scene id -> name -> value); persist across re-entries (spec §7). */
33
- sceneBags: Record<string, Record<string, ScalarValue>>;
34
- /** This flow's built-in PRNG position (mulberry32 state). */
35
- rngState: number;
36
- /** This flow's per-node entry counts (node id -> times entered by this flow). */
37
- visits: Record<string, number>;
38
- cursor: {
39
- flowEnded: boolean;
40
- currentSceneId: string | null;
41
- /** The continuation stack (call frames + the active block run). */
42
- stack: StackFrame[];
43
- activeSnippetId: string | null;
44
- beatIndex: number;
45
- /** The pending choice's exact option set, REPLAYED on load (schema 9.3). */
46
- pendingChoice: SavedChoice | null;
47
- /** The chosen option owning a prompt still to be replayed (save taken between choose + advance).
48
- * Optional / absent in older saves -> no pending prompt. */
49
- pendingPromptOwnerId?: string | null;
50
- /** This flow's `sequence` selector cursors. */
51
- selectors: Record<string, SelectorSnapshot>;
52
- };
53
- }
54
- /**
55
- * A pending choice as saved: the option set the player was shown, restored
56
- * verbatim - re-deriving on load would re-evaluate conditions (consuming PRNG
57
- * draws a second time) and could mutate the choice under the player.
58
- */
59
- interface SavedChoice {
60
- groupId: string;
61
- options: ChoiceOption[];
62
- }
63
- /** A full resumable save-game: shared `@patter` state + every live flow. */
64
- interface SaveGame {
65
- version: number;
66
- /** Shared `@patter` globals (owned scope "patter"). */
67
- shared: EngineSave;
68
- /** World-wide per-node entry counts (node id -> times entered by any flow). */
69
- sharedVisits: Record<string, number>;
70
- /** Shared selector cursors (node id -> snapshot) for `shared` memoried selectors. */
71
- sharedSelectors: Record<string, SelectorSnapshot>;
72
- /** Shared, scene-namespaced `@scene` bags (scene id -> name -> value) - the shared scene props. */
73
- stageBags: Record<string, Record<string, ScalarValue>>;
74
- /** Each live flow's snapshot, keyed by flow id. */
75
- flows: Record<string, FlowSnapshot>;
76
- }
8
+
77
9
  /** What `Flow.advance()` surfaces to the host at each stop. */
78
10
  type StepResult = {
79
11
  type: "line";
@@ -569,6 +501,18 @@ declare class Engine {
569
501
  getFlow(id: string): Flow | undefined;
570
502
  /** All currently-open flows. */
571
503
  flows(): Flow[];
504
+ /**
505
+ * The SHARED kernel bags with the path each answers to in a log: the `@patter` globals,
506
+ * and one per scene for the shared `@scene` props. Parity with the Storylet Engine's
507
+ * listBags of the same name - it is what a state logger mounts.
508
+ *
509
+ * A stage bag's log path is `@scene:<sceneId>.`, not the bag's own `@scene.`: a property
510
+ * is ADDRESSED relative to a flow's current scene, but a log spans scenes and has to say
511
+ * which one. That is why a mount may override the bag's prefix.
512
+ *
513
+ * loadGame() replaces every bag, so re-enumerate after a load.
514
+ */
515
+ listBags(): LogMount[];
572
516
  /** Close (remove) a flow. The flow object is FINISHED, not merely unregistered, so a host still
573
517
  * holding it cannot keep advancing it into the shared world (see {@link Flow.close}). */
574
518
  closeFlow(id: string): void;
@@ -702,7 +646,12 @@ declare class Flow {
702
646
  * to its caller (call-return) or ends the flow.
703
647
  */
704
648
  private settle;
705
- /** The options of a pending choice (empty when not at a choice point). */
649
+ /**
650
+ * THIS flow's own kernel bags: its not-shared `@patter` half and its per-scene `@scene`
651
+ * props, each prefixed with the flow id so one path space holds every flow. The shared
652
+ * halves are the Engine's listBags.
653
+ */
654
+ listBags(): LogMount[];
706
655
  /** This flow's decisions, in order. Empty unless the run was opened with `log: true`.
707
656
  * The engine's log carries the same events tagged with the flow; this one is what a
708
657
  * single conversation reads as. */
@@ -712,6 +661,7 @@ declare class Flow {
712
661
  /** Record one decision, on this flow's log and the engine's. Cheap to call with logging
713
662
  * off: the entry is never built. */
714
663
  private emit;
664
+ /** The options of a pending choice (empty when not at a choice point). */
715
665
  getChoices(): ChoiceOption[];
716
666
  /** Pick an eligible option by id; the next `advance()` runs it. */
717
667
  choose(id: string): void;
@@ -1000,4 +950,4 @@ declare function effectiveGameData(fields: GameDataField[], node: GameData | und
1000
950
  */
1001
951
  declare function buildTagIndex(bundle: Bundle): Map<string, string[]>;
1002
952
 
1003
- export { type AddressSummary, type AdvanceToStopResult, type BeatInfo, type BundleCounts, type BundleDescription, type BundleIdentity, type ChoiceOption, Engine, type EngineLogEntry, type EngineOptions, type EngineSave, type EngineTraceHandler, type FlatBeat, Flow, type FlowSnapshot, type GameDataFieldSummary, type GameDataSummary, type HostScopeSummary, type LogEntry, type OpenFlowOptions, type OutlineBlock, type OutlineNode, type OutlineScene, type OwnedProperties, type PropertySummary, type SaveGame, type SavedChoice, type SelectorSnapshot, type StackFrame, type StepResult, type TraceEvent, type TraceHandler, type WorldResolver, buildTagIndex, describeBundle, effectiveGameData, gameDataFields, gameDataValue };
953
+ export { type AddressSummary, type AdvanceToStopResult, type BeatInfo, type BundleCounts, type BundleDescription, type BundleIdentity, type ChoiceOption, Engine, type EngineLogEntry, type EngineOptions, type EngineTraceHandler, type FlatBeat, Flow, type GameDataFieldSummary, type GameDataSummary, type HostScopeSummary, type LogEntry, type OpenFlowOptions, type OutlineBlock, type OutlineNode, type OutlineScene, type OwnedProperties, type PropertySummary, type StepResult, type TraceEvent, type TraceHandler, type WorldResolver, buildTagIndex, describeBundle, effectiveGameData, gameDataFields, gameDataValue };
package/dist/index.js CHANGED
@@ -463,6 +463,22 @@ var Engine = class _Engine {
463
463
  flows() {
464
464
  return [...this.flowsById.values()];
465
465
  }
466
+ /**
467
+ * The SHARED kernel bags with the path each answers to in a log: the `@patter` globals,
468
+ * and one per scene for the shared `@scene` props. Parity with the Storylet Engine's
469
+ * listBags of the same name - it is what a state logger mounts.
470
+ *
471
+ * A stage bag's log path is `@scene:<sceneId>.`, not the bag's own `@scene.`: a property
472
+ * is ADDRESSED relative to a flow's current scene, but a log spans scenes and has to say
473
+ * which one. That is why a mount may override the bag's prefix.
474
+ *
475
+ * loadGame() replaces every bag, so re-enumerate after a load.
476
+ */
477
+ listBags() {
478
+ const mounts = [{ bag: this.host.shared.ownedBag("patter") }];
479
+ for (const [sceneId, bag] of this.host.stageBags) mounts.push({ bag, pathPrefix: `@scene:${sceneId}.` });
480
+ return mounts;
481
+ }
466
482
  /** Close (remove) a flow. The flow object is FINISHED, not merely unregistered, so a host still
467
483
  * holding it cannot keep advancing it into the shared world (see {@link Flow.close}). */
468
484
  closeFlow(id) {
@@ -902,7 +918,16 @@ var Flow = class {
902
918
  this.enterChild(children[frame.index++]);
903
919
  }
904
920
  }
905
- /** The options of a pending choice (empty when not at a choice point). */
921
+ /**
922
+ * THIS flow's own kernel bags: its not-shared `@patter` half and its per-scene `@scene`
923
+ * props, each prefixed with the flow id so one path space holds every flow. The shared
924
+ * halves are the Engine's listBags.
925
+ */
926
+ listBags() {
927
+ const mounts = [{ bag: this.local.ownedBag("patter"), pathPrefix: `${this.id}/@patter.` }];
928
+ for (const [sceneId, bag] of this.sceneBags) mounts.push({ bag, pathPrefix: `${this.id}/@scene:${sceneId}.` });
929
+ return mounts;
930
+ }
906
931
  /** This flow's decisions, in order. Empty unless the run was opened with `log: true`.
907
932
  * The engine's log carries the same events tagged with the flow; this one is what a
908
933
  * single conversation reads as. */
@@ -921,6 +946,7 @@ var Flow = class {
921
946
  if (!this.host.logEnabled) return;
922
947
  this.flowLog.push({ ...event, seq: this.flowSeq++, ...scene ? { scene } : {} });
923
948
  }
949
+ /** The options of a pending choice (empty when not at a choice point). */
924
950
  getChoices() {
925
951
  return this.pendingChoice?.options ?? [];
926
952
  }