@sharpee/story-loader 3.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.
@@ -0,0 +1,57 @@
1
+ /**
2
+ * hatch-context.ts — the narrow staging context handed to text-hatch
3
+ * producers, plus the bind-time `'chord.'` source lint (design.md §5.6,
4
+ * hatch-context proposal 2026-07-12).
5
+ *
6
+ * Enforcement is by construction: chord producers are invoked at phrase
7
+ * staging (runtime.ts `phraseEvent`), and the context they receive is built
8
+ * HERE — a fresh object whose `world` exposes only `RenderWorld`'s read
9
+ * methods. A hatch cannot misuse what it is never given; casting the facade
10
+ * finds nothing (the gateStatus precedent: a producer once cast its way to
11
+ * `getStateValue` and read a loader-private `chord.*` key that a later
12
+ * ratchet deleted, silently).
13
+ *
14
+ * Public interface: HATCH_CONTEXT_VERSION, stagingRenderContext,
15
+ * findChordLiteral.
16
+ * Owner context: @sharpee/story-loader.
17
+ */
18
+ import type { RenderContext } from '@sharpee/if-domain';
19
+ import type { WorldModel } from '@sharpee/world-model';
20
+ /**
21
+ * Version of the surface hatches can see. Bumped only when the narrowed
22
+ * staging surface changes (a `RenderContext`/`RenderWorld` member becomes
23
+ * available to hatches). Re-exported by @sharpee/ide-protocol so the IDE
24
+ * can state exactly what a hatch may touch (the §5.6 IDE contract).
25
+ */
26
+ export declare const HATCH_CONTEXT_VERSION = 1;
27
+ /**
28
+ * Build the narrow, honest `RenderContext` a producer is invoked with at
29
+ * staging time. `world` is a three-method facade over the live world
30
+ * (`nounPhraseFor` is omitted — optional, stdlib-bound, and staging-time
31
+ * producers do not realize noun phrases). The remaining seams are inert by
32
+ * construction because they genuinely do not exist at staging: persistent
33
+ * text state is an assembler-time seam — a producer that needs it returns
34
+ * a `Choice` atom (ADR-196) realized later against the engine's real
35
+ * context. No member exposes mutation or state-key reads.
36
+ *
37
+ * @param world the live world model (read-only access only)
38
+ * @returns a genuine `RenderContext` (no cast) safe to hand author code
39
+ */
40
+ export declare function stagingRenderContext(world: WorldModel): RenderContext;
41
+ /**
42
+ * Bind-time lint (best-effort backstop; the facade is the wall): scan a
43
+ * bound hatch export's source text for a quoted `chord.` literal. For a
44
+ * function export the function's own source is scanned; for an object
45
+ * export (action/behavior hatches) each function-valued own property is.
46
+ *
47
+ * Documented imprecisions (proposal §3.2): minified bundles may evade the
48
+ * scan (the devkit source lint is the authoritative layer), and a QUOTED
49
+ * `chord.` inside a comment in the compiled output trips it — the remedy
50
+ * is rewording the comment.
51
+ *
52
+ * @param bound the module export about to be bound
53
+ * @returns the offending source snippet (trimmed to the match line), or
54
+ * null when clean or unscannable
55
+ */
56
+ export declare function findChordLiteral(bound: unknown): string | null;
57
+ //# sourceMappingURL=hatch-context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hatch-context.d.ts","sourceRoot":"","sources":["../../../../../../repos/sharpee_v2/packages/story-loader/src/hatch-context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,KAAK,EAAE,aAAa,EAAe,MAAM,oBAAoB,CAAC;AACrE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAEvD;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,IAAI,CAAC;AAEvC;;;;;;;;;;;;GAYG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,UAAU,GAAG,aAAa,CA2BrE;AAKD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAkB9D"}
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HATCH_CONTEXT_VERSION = void 0;
4
+ exports.stagingRenderContext = stagingRenderContext;
5
+ exports.findChordLiteral = findChordLiteral;
6
+ /**
7
+ * Version of the surface hatches can see. Bumped only when the narrowed
8
+ * staging surface changes (a `RenderContext`/`RenderWorld` member becomes
9
+ * available to hatches). Re-exported by @sharpee/ide-protocol so the IDE
10
+ * can state exactly what a hatch may touch (the §5.6 IDE contract).
11
+ */
12
+ exports.HATCH_CONTEXT_VERSION = 1;
13
+ /**
14
+ * Build the narrow, honest `RenderContext` a producer is invoked with at
15
+ * staging time. `world` is a three-method facade over the live world
16
+ * (`nounPhraseFor` is omitted — optional, stdlib-bound, and staging-time
17
+ * producers do not realize noun phrases). The remaining seams are inert by
18
+ * construction because they genuinely do not exist at staging: persistent
19
+ * text state is an assembler-time seam — a producer that needs it returns
20
+ * a `Choice` atom (ADR-196) realized later against the engine's real
21
+ * context. No member exposes mutation or state-key reads.
22
+ *
23
+ * @param world the live world model (read-only access only)
24
+ * @returns a genuine `RenderContext` (no cast) safe to hand author code
25
+ */
26
+ function stagingRenderContext(world) {
27
+ const facade = {
28
+ getEntity: (entityId) => world.getEntity(entityId),
29
+ getEntityContents: (entityId) => world.getContents(entityId),
30
+ getContainingRoom: (entityId) => world.getContainingRoom(entityId),
31
+ };
32
+ return {
33
+ world: facade,
34
+ params: {},
35
+ settings: {},
36
+ narrative: { person: 'second' },
37
+ reference: {
38
+ lastMentioned: () => undefined,
39
+ note: () => {
40
+ // Staging has no realization order — nothing to note.
41
+ },
42
+ },
43
+ textState: {
44
+ get: () => undefined,
45
+ set: () => {
46
+ // Inert at staging: persistent choice state belongs to the assembler pass.
47
+ },
48
+ },
49
+ contribute: () => {
50
+ // Slot contributions are a per-turn render seam; staging has no slot store.
51
+ },
52
+ };
53
+ }
54
+ /** Matches a quoted string literal opening with `chord.` — the loader-private namespace. */
55
+ const CHORD_LITERAL = /['"`]chord\./;
56
+ /**
57
+ * Bind-time lint (best-effort backstop; the facade is the wall): scan a
58
+ * bound hatch export's source text for a quoted `chord.` literal. For a
59
+ * function export the function's own source is scanned; for an object
60
+ * export (action/behavior hatches) each function-valued own property is.
61
+ *
62
+ * Documented imprecisions (proposal §3.2): minified bundles may evade the
63
+ * scan (the devkit source lint is the authoritative layer), and a QUOTED
64
+ * `chord.` inside a comment in the compiled output trips it — the remedy
65
+ * is rewording the comment.
66
+ *
67
+ * @param bound the module export about to be bound
68
+ * @returns the offending source snippet (trimmed to the match line), or
69
+ * null when clean or unscannable
70
+ */
71
+ function findChordLiteral(bound) {
72
+ const sources = [];
73
+ if (typeof bound === 'function') {
74
+ sources.push(Function.prototype.toString.call(bound));
75
+ }
76
+ else if (bound !== null && typeof bound === 'object') {
77
+ for (const value of Object.values(bound)) {
78
+ if (typeof value === 'function')
79
+ sources.push(Function.prototype.toString.call(value));
80
+ }
81
+ }
82
+ for (const source of sources) {
83
+ const match = CHORD_LITERAL.exec(source);
84
+ if (match) {
85
+ const start = source.lastIndexOf('\n', match.index) + 1;
86
+ const end = source.indexOf('\n', match.index);
87
+ return source.slice(start, end === -1 ? undefined : end).trim();
88
+ }
89
+ }
90
+ return null;
91
+ }
92
+ //# sourceMappingURL=hatch-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hatch-context.js","sourceRoot":"","sources":["../../../../../../repos/sharpee_v2/packages/story-loader/src/hatch-context.ts"],"names":[],"mappings":";;;AAyCA,oDA2BC;AAoBD,4CAkBC;AAtFD;;;;;GAKG;AACU,QAAA,qBAAqB,GAAG,CAAC,CAAC;AAEvC;;;;;;;;;;;;GAYG;AACH,SAAgB,oBAAoB,CAAC,KAAiB;IACpD,MAAM,MAAM,GAAgB;QAC1B,SAAS,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC,QAAQ,CAAC;QAClD,iBAAiB,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,KAAK,CAAC,WAAW,CAAC,QAAQ,CAAC;QAC5D,iBAAiB,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,KAAK,CAAC,iBAAiB,CAAC,QAAQ,CAAC;KACnE,CAAC;IACF,OAAO;QACL,KAAK,EAAE,MAAM;QACb,MAAM,EAAE,EAAE;QACV,QAAQ,EAAE,EAAE;QACZ,SAAS,EAAE,EAA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AAM,GAAG,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;YAC9C,OAAO,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;QAClE,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
package/index.d.ts ADDED
@@ -0,0 +1,24 @@
1
+ /**
2
+ * @sharpee/story-loader — the Story IR interpreter (ADR-210).
3
+ *
4
+ * Purpose: construct a generic `Story` implementation from compiled Story IR —
5
+ * world building, phrase registration, custom vocabulary, endings, and (Phase 5)
6
+ * event-rule binding, the expression evaluator, occurrence materialization,
7
+ * and seeded RNG.
8
+ *
9
+ * Public interface: createStory(), ChordStory, StoryLoaderOptions, LoadError,
10
+ * CHORD_STATE_PREFIX.
11
+ *
12
+ * Owner context: Chord runtime consumer. Language-neutral by design — it
13
+ * consumes IR and never sees Chord syntax. Depends on the platform
14
+ * (world-model, helpers, engine, if-domain, core); nothing platform depends
15
+ * on it (ADR-210 Direction rule).
16
+ */
17
+ export { LoadError } from './errors';
18
+ export { EVENT_TRIGGERS, EVENT_PAYLOAD_FIELDS } from './event-contract';
19
+ export { HATCH_CONTEXT_VERSION, stagingRenderContext, findChordLiteral } from './hatch-context';
20
+ export { ChordDataTrait, ChordDetailTrait, ChordStory, createStory, StoryLoaderOptions } from './loader';
21
+ export { Evaluator, EvalContext, EntityIdResolver } from './evaluator';
22
+ export { ChordRuntime, ChordBehaviorTrait } from './runtime';
23
+ export { CHORD_OCCURRENCE_PREFIX, CHORD_RNG_KEY, CHORD_STATE_PREFIX, CHORD_TRAIT_PREFIX, } from './state-keys';
24
+ //# sourceMappingURL=index.d.ts.map
package/index.d.ts.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../repos/sharpee_v2/packages/story-loader/src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACxE,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAChG,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,UAAU,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AACzG,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACvE,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAC7D,OAAO,EACL,uBAAuB,EACvB,aAAa,EACb,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,cAAc,CAAC"}
package/index.js ADDED
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ /**
3
+ * @sharpee/story-loader — the Story IR interpreter (ADR-210).
4
+ *
5
+ * Purpose: construct a generic `Story` implementation from compiled Story IR —
6
+ * world building, phrase registration, custom vocabulary, endings, and (Phase 5)
7
+ * event-rule binding, the expression evaluator, occurrence materialization,
8
+ * and seeded RNG.
9
+ *
10
+ * Public interface: createStory(), ChordStory, StoryLoaderOptions, LoadError,
11
+ * CHORD_STATE_PREFIX.
12
+ *
13
+ * Owner context: Chord runtime consumer. Language-neutral by design — it
14
+ * consumes IR and never sees Chord syntax. Depends on the platform
15
+ * (world-model, helpers, engine, if-domain, core); nothing platform depends
16
+ * on it (ADR-210 Direction rule).
17
+ */
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.CHORD_TRAIT_PREFIX = exports.CHORD_STATE_PREFIX = exports.CHORD_RNG_KEY = exports.CHORD_OCCURRENCE_PREFIX = exports.ChordBehaviorTrait = exports.ChordRuntime = exports.Evaluator = exports.createStory = exports.ChordStory = exports.ChordDetailTrait = exports.ChordDataTrait = exports.findChordLiteral = exports.stagingRenderContext = exports.HATCH_CONTEXT_VERSION = exports.EVENT_PAYLOAD_FIELDS = exports.EVENT_TRIGGERS = exports.LoadError = void 0;
20
+ var errors_1 = require("./errors");
21
+ Object.defineProperty(exports, "LoadError", { enumerable: true, get: function () { return errors_1.LoadError; } });
22
+ var event_contract_1 = require("./event-contract");
23
+ Object.defineProperty(exports, "EVENT_TRIGGERS", { enumerable: true, get: function () { return event_contract_1.EVENT_TRIGGERS; } });
24
+ Object.defineProperty(exports, "EVENT_PAYLOAD_FIELDS", { enumerable: true, get: function () { return event_contract_1.EVENT_PAYLOAD_FIELDS; } });
25
+ var hatch_context_1 = require("./hatch-context");
26
+ Object.defineProperty(exports, "HATCH_CONTEXT_VERSION", { enumerable: true, get: function () { return hatch_context_1.HATCH_CONTEXT_VERSION; } });
27
+ Object.defineProperty(exports, "stagingRenderContext", { enumerable: true, get: function () { return hatch_context_1.stagingRenderContext; } });
28
+ Object.defineProperty(exports, "findChordLiteral", { enumerable: true, get: function () { return hatch_context_1.findChordLiteral; } });
29
+ var loader_1 = require("./loader");
30
+ Object.defineProperty(exports, "ChordDataTrait", { enumerable: true, get: function () { return loader_1.ChordDataTrait; } });
31
+ Object.defineProperty(exports, "ChordDetailTrait", { enumerable: true, get: function () { return loader_1.ChordDetailTrait; } });
32
+ Object.defineProperty(exports, "ChordStory", { enumerable: true, get: function () { return loader_1.ChordStory; } });
33
+ Object.defineProperty(exports, "createStory", { enumerable: true, get: function () { return loader_1.createStory; } });
34
+ var evaluator_1 = require("./evaluator");
35
+ Object.defineProperty(exports, "Evaluator", { enumerable: true, get: function () { return evaluator_1.Evaluator; } });
36
+ var runtime_1 = require("./runtime");
37
+ Object.defineProperty(exports, "ChordRuntime", { enumerable: true, get: function () { return runtime_1.ChordRuntime; } });
38
+ Object.defineProperty(exports, "ChordBehaviorTrait", { enumerable: true, get: function () { return runtime_1.ChordBehaviorTrait; } });
39
+ var state_keys_1 = require("./state-keys");
40
+ Object.defineProperty(exports, "CHORD_OCCURRENCE_PREFIX", { enumerable: true, get: function () { return state_keys_1.CHORD_OCCURRENCE_PREFIX; } });
41
+ Object.defineProperty(exports, "CHORD_RNG_KEY", { enumerable: true, get: function () { return state_keys_1.CHORD_RNG_KEY; } });
42
+ Object.defineProperty(exports, "CHORD_STATE_PREFIX", { enumerable: true, get: function () { return state_keys_1.CHORD_STATE_PREFIX; } });
43
+ Object.defineProperty(exports, "CHORD_TRAIT_PREFIX", { enumerable: true, get: function () { return state_keys_1.CHORD_TRAIT_PREFIX; } });
44
+ //# sourceMappingURL=index.js.map
package/index.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../repos/sharpee_v2/packages/story-loader/src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;;AAEH,mCAAqC;AAA5B,mGAAA,SAAS,OAAA;AAClB,mDAAwE;AAA/D,gHAAA,cAAc,OAAA;AAAE,sHAAA,oBAAoB,OAAA;AAC7C,iDAAgG;AAAvF,sHAAA,qBAAqB,OAAA;AAAE,qHAAA,oBAAoB,OAAA;AAAE,iHAAA,gBAAgB,OAAA;AACtE,mCAAyG;AAAhG,wGAAA,cAAc,OAAA;AAAE,0GAAA,gBAAgB,OAAA;AAAE,oGAAA,UAAU,OAAA;AAAE,qGAAA,WAAW,OAAA;AAClE,yCAAuE;AAA9D,sGAAA,SAAS,OAAA;AAClB,qCAA6D;AAApD,uGAAA,YAAY,OAAA;AAAE,6GAAA,kBAAkB,OAAA;AACzC,2CAKsB;AAJpB,qHAAA,uBAAuB,OAAA;AACvB,2GAAA,aAAa,OAAA;AACb,gHAAA,kBAAkB,OAAA;AAClB,gHAAA,kBAAkB,OAAA"}
package/loader.d.ts ADDED
@@ -0,0 +1,241 @@
1
+ /**
2
+ * loader.ts — the generic `Story` constructed from Chord Story IR (ADR-210).
3
+ *
4
+ * Purpose: interpret a compiled IR into the platform's standard story
5
+ * lifecycle: world building (`initializeWorld`), player creation
6
+ * (`createPlayer`), phrase registration (`extendLanguage`), custom verbs
7
+ * (`getCustomVocabulary`), and completion (`isComplete` via the if-domain
8
+ * ending flag). Phase A slice: static world only — when-rules, on-clause
9
+ * interceptors, derived properties, and the evaluator bind in Phase 5.
10
+ *
11
+ * Public interface: createStory(), ChordStory, StoryLoaderOptions.
12
+ * Owner context: @sharpee/story-loader (language-neutral IR consumer; the
13
+ * runtime platform never depends on this package — ADR-210 Direction rule).
14
+ *
15
+ * Invariants:
16
+ * - Atomic load: any defect throws LoadError; no partial registration.
17
+ * - No filesystem access: hatch modules arrive pre-loaded via options
18
+ * (the CLI/devkit owns module resolution and compilation).
19
+ * - Every phrase key in the IR is registered with the Language Provider
20
+ * (given 3); blocked-exit/description text is ALSO written where the
21
+ * platform reads it today (dual-mode, ADR-107).
22
+ */
23
+ import { StoryIR } from '@sharpee/chord';
24
+ import type { Phrase } from '@sharpee/if-domain';
25
+ import type { ISemanticEvent } from '@sharpee/core';
26
+ import type { LanguageProvider, PhraseProducer, StoryEndingKind } from '@sharpee/if-domain';
27
+ import type { CustomVocabulary, Story, StoryConfig } from '@sharpee/engine';
28
+ import { CapabilityBehavior, IFEntity, ITrait, WorldModel } from '@sharpee/world-model';
29
+ import { ChordRuntime } from './runtime';
30
+ /**
31
+ * Marker trait for entities carrying loader-compiled `detail` providers
32
+ * (Z3b): the one state-clause contributor registered per load looks up the
33
+ * owner's gated detail specs through it. Data-free — the specs live on the
34
+ * loader (nothing serialized; re-registered every load).
35
+ */
36
+ export declare class ChordDetailTrait implements ITrait {
37
+ static readonly type = "chord.detail";
38
+ readonly type = "chord.detail";
39
+ }
40
+ /**
41
+ * A `define trait` runtime instance: type `chord.trait.<name>`, data fields
42
+ * as own enumerable properties (world serialization covers them — AC-6).
43
+ */
44
+ export declare class ChordDataTrait implements ITrait {
45
+ readonly type: string;
46
+ [field: string]: unknown;
47
+ constructor(type: string, values: Record<string, unknown>);
48
+ }
49
+ export interface StoryLoaderOptions {
50
+ /**
51
+ * Pre-loaded hatch modules keyed by the `.story` module path
52
+ * (`"./extras.ts"` → its named exports). The host that owns module
53
+ * resolution (CLI/devkit) supplies these; the loader never touches the
54
+ * filesystem, so it stays browser-safe and the pure-IR profile can
55
+ * simply pass none.
56
+ */
57
+ hatchModules?: Record<string, Record<string, unknown>>;
58
+ /**
59
+ * Seed for the story's random stream (`randomly`, `one chance in <n>`).
60
+ * A fixed seed makes repeated runs byte-identical (AC-5); omitted, the
61
+ * stream is time-seeded.
62
+ */
63
+ seed?: number;
64
+ /**
65
+ * Load profile (design.md §5.6, AC-4): 'devkit' (default) binds hatches;
66
+ * 'pure-ir' REFUSES any hatch-bearing story at construction — before any
67
+ * binding, so no author-supplied code is touched. Hatch-free stories load
68
+ * identically under both.
69
+ */
70
+ profile?: 'devkit' | 'pure-ir';
71
+ }
72
+ /**
73
+ * Build a `Story` from compiled IR.
74
+ * @param ir a gate-clean Story IR (`compile().ok` was true)
75
+ * @param options hatch modules and host wiring
76
+ * @throws LoadError on format mismatch or unbindable hatch (atomic load)
77
+ */
78
+ export declare function createStory(ir: StoryIR, options?: StoryLoaderOptions): ChordStory;
79
+ /** The generic Story implementation interpreted from IR. */
80
+ export declare class ChordStory implements Story {
81
+ readonly ir: StoryIR;
82
+ readonly config: StoryConfig;
83
+ /** Bound `define text` producers by hatch name. */
84
+ readonly producers: Map<string, PhraseProducer>;
85
+ /** Bound `define action X from` hatches: four-phase Action objects by name. */
86
+ readonly boundActions: Map<string, unknown>;
87
+ /** Bound `define behavior X from` hatches: CapabilityBehaviors by name. */
88
+ readonly boundBehaviors: Map<string, CapabilityBehavior>;
89
+ /** The turn-by-turn runtime (rules, on-clauses, derived properties). */
90
+ readonly runtime: ChordRuntime;
91
+ /** The condition evaluator — shared with the runtime; Z2 gate thunks close over it. */
92
+ private readonly evaluator;
93
+ /** IR entity ID → world entity ID (populated by initializeWorld/createPlayer). */
94
+ private readonly worldIds;
95
+ /** World entity ID → IR entity ID (state lookups in the evaluator). */
96
+ private readonly irIds;
97
+ private world;
98
+ /** True once initializeWorld has built the world content. */
99
+ private worldBuilt;
100
+ /** True once the player has been placed/equipped (exactly-once guard). */
101
+ private playerFinalized;
102
+ constructor(ir: StoryIR, options: StoryLoaderOptions);
103
+ /** The world entity ID for an IR entity ID (after initializeWorld). */
104
+ entityId(irId: string): string | undefined;
105
+ /** The IR entity ID for a world entity ID. */
106
+ irIdOf(worldId: string): string | undefined;
107
+ /** The player's world id, once createPlayer has run. */
108
+ playerWorldId(): string | undefined;
109
+ private playerId;
110
+ private bindHatches;
111
+ initializeWorld(world: WorldModel): void;
112
+ createPlayer(world: WorldModel): IFEntity;
113
+ /**
114
+ * Place and equip the player, then run the initial derived-property
115
+ * evaluation. Runs exactly once, from whichever lifecycle hook fires
116
+ * second — both the engine order (createPlayer → initializeWorld) and
117
+ * the direct order (initializeWorld → createPlayer) are supported.
118
+ */
119
+ private finalizePlayer;
120
+ extendLanguage(language: LanguageProvider): void;
121
+ getCustomVocabulary(): CustomVocabulary;
122
+ /**
123
+ * Custom actions for engine registration: `define action` dispatch
124
+ * actions (Phase B, §5.4) plus `define action X from` hatch Actions
125
+ * (grammar for hatch actions is the module's own concern).
126
+ */
127
+ getCustomActions(): unknown[];
128
+ /**
129
+ * Register scheduler constructs (`once`/`every`/`define sequence`/
130
+ * every-turn trait clauses) as plugin-scheduler daemons. All progression
131
+ * state is world state — no runner-state plumbing (design.md §6).
132
+ */
133
+ onEngineReady(engine: {
134
+ getPluginRegistry(): {
135
+ register(plugin: unknown): void;
136
+ };
137
+ registerSlotEntry?(entry: ChordSlotEntry): void;
138
+ }): void;
139
+ /**
140
+ * Z3 `present` channel → ADR-212 slot entries. One `registerSlotEntry`
141
+ * call per authoring entity: `slotKey: 'here'`, owner = the entity,
142
+ * content = variants as a `Choice` per the Z5 table (single plain variant
143
+ * → `Literal`), order = declaration order, `counterKey: 'present'` (the
144
+ * §4 owner + channel-key convention — the Choice's own keys match it).
145
+ * An ungated block relies on the platform's `owner-present` default; a
146
+ * `while`-gated block uses the predicate seam, ANDed with the same
147
+ * presence check so the gate narrows the channel rather than replacing
148
+ * its semantics.
149
+ *
150
+ * @param engine the engine surface (structural — absent method is a no-op)
151
+ */
152
+ private registerPresentEntries;
153
+ /**
154
+ * Register `define action` grammar patterns as story grammar (ADR-087).
155
+ * The param is the Story contract's stdlib Parser; typed structurally at
156
+ * the use site to keep story-loader's dependency surface unchanged.
157
+ */
158
+ extendParser(parser: Parameters<NonNullable<Story['extendParser']>>[0]): void;
159
+ isComplete(): boolean;
160
+ /**
161
+ * End the story: set the if-domain ending flag and build the blessed
162
+ * ending event (Prerequisite 3). The caller (rule evaluator) emits it.
163
+ */
164
+ triggerEnding(world: WorldModel, ending: StoryEndingKind, messageId?: string): ISemanticEvent;
165
+ private buildEntity;
166
+ private applyTraitAdjectives;
167
+ /**
168
+ * Initial values for a `define trait` instance: declared `starts`
169
+ * defaults overlaid by the composition's `with` config. Entity-name
170
+ * values (`with food the handful of feed`) resolve to IR entity ids.
171
+ */
172
+ private traitFieldValues;
173
+ private applyContainerConfig;
174
+ private requireWorldId;
175
+ /** Resolved default-locale text for a phrase key (single-variant read). */
176
+ /**
177
+ * Z2 (ADR-211): compile `{key}` strategy-phrase markers in this room's
178
+ * description prose onto ADR-209 storage. ATOMIC per room: every
179
+ * rewrite/entry/gate is computed first and applied only when the whole
180
+ * room compiled clean — a LoadError leaves the room untouched, never
181
+ * partial. Markers rewrite to `{snippet:key}`; variants populate
182
+ * `RoomTrait.snippets[key]` (`nothing` → `''`, strategy → selector via the
183
+ * Z5 table; a single-variant plain phrase compiles to a plain string
184
+ * entry); the phrase's `while` gate compiles — a presence condition on the
185
+ * marker's own room (`is here` / `is in <this room>`, non-negated) becomes
186
+ * `mentions`, anything else registers on the ADR-211 gate seam keyed
187
+ * `(roomId, marker)` (stdlib `registerSnippetGate` — in-memory, nothing
188
+ * serialized, re-registered every story load). Both description texts
189
+ * share one entry per marker (Z1/ADR-211 Q6: shared entries + counters).
190
+ *
191
+ * @param world the world being built (gate thunks close over it)
192
+ * @param irEntity the room's IR entity (presence-gate room identity)
193
+ * @param entity the built room entity
194
+ */
195
+ private compileRoomSnippets;
196
+ /**
197
+ * Z3 (ADR-213 §2): register the one `disappeared` observer, when any
198
+ * entity authors the channel. On a successful removal: skip the player
199
+ * (out of the channel's scope), require an authored block, require the
200
+ * removal to be witnessed (the player's containing room equals the
201
+ * entity's last containing room), then ENQUEUE the phrase through the
202
+ * existing phrase-event path — never rendered inline from the observer.
203
+ * Unwitnessed removals enqueue nothing and consume nothing (D11).
204
+ * Orphaning never reaches here (the seam fires only in `removeEntity`).
205
+ *
206
+ * @param world the world being built (the observer closes over it)
207
+ */
208
+ private registerRemovalObserver;
209
+ /**
210
+ * Z3b: compile each entity's gated `detail` blocks. The two shipped trait
211
+ * shapes bind their fields directly — `while it is on` →
212
+ * `SwitchableTrait.detailWhenOn`, `while it is lit` →
213
+ * `LightSourceTrait.detailWhenLit` (both read by world-model's
214
+ * state-clauses registry). Any other condition joins the loader-owned
215
+ * provider: one marker trait per owner, ONE contributor registered per
216
+ * load (last-wins on the registry — the ADR-211/212 lifecycle), which
217
+ * evaluates the gate live at examine time.
218
+ *
219
+ * @param world the world being built (the provider closes over it)
220
+ */
221
+ private compileDetailChannels;
222
+ private phraseText;
223
+ }
224
+ /**
225
+ * Structural slice of `GameEngine.registerSlotEntry`'s entry (ADR-212 §1) —
226
+ * typed at the use site to keep story-loader's dependency surface unchanged
227
+ * (the `extendParser` precedent).
228
+ */
229
+ interface ChordSlotEntry {
230
+ slotKey: string;
231
+ owner: string;
232
+ content: Phrase;
233
+ order?: number;
234
+ gate?: {
235
+ kind: 'predicate';
236
+ holds: (world: WorldModel) => boolean;
237
+ };
238
+ counterKey?: string;
239
+ }
240
+ export {};
241
+ //# sourceMappingURL=loader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"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