@aftertext/runtime 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +31 -2
- package/dist/create-runtime-state.d.ts +14 -0
- package/dist/create-runtime-state.d.ts.map +1 -0
- package/dist/create-runtime-state.js +18 -0
- package/dist/create-runtime-state.js.map +1 -0
- package/dist/execution/advance.d.ts +37 -0
- package/dist/execution/advance.d.ts.map +1 -0
- package/dist/execution/advance.js +196 -0
- package/dist/execution/advance.js.map +1 -0
- package/dist/execution/choice.d.ts +30 -0
- package/dist/execution/choice.d.ts.map +1 -0
- package/dist/execution/choice.js +58 -0
- package/dist/execution/choice.js.map +1 -0
- package/dist/execution/cursor.d.ts +78 -0
- package/dist/execution/cursor.d.ts.map +1 -0
- package/dist/execution/cursor.js +59 -0
- package/dist/execution/cursor.js.map +1 -0
- package/dist/execution/errors.d.ts +27 -0
- package/dist/execution/errors.d.ts.map +1 -0
- package/dist/execution/errors.js +36 -0
- package/dist/execution/errors.js.map +1 -0
- package/dist/execution/expression.d.ts +50 -0
- package/dist/execution/expression.d.ts.map +1 -0
- package/dist/execution/expression.js +159 -0
- package/dist/execution/expression.js.map +1 -0
- package/dist/execution/memory-queries.d.ts +20 -0
- package/dist/execution/memory-queries.d.ts.map +1 -0
- package/dist/execution/memory-queries.js +83 -0
- package/dist/execution/memory-queries.js.map +1 -0
- package/dist/execution/navigate.d.ts +23 -0
- package/dist/execution/navigate.d.ts.map +1 -0
- package/dist/execution/navigate.js +32 -0
- package/dist/execution/navigate.js.map +1 -0
- package/dist/execution/result.d.ts +50 -0
- package/dist/execution/result.d.ts.map +1 -0
- package/dist/execution/result.js +2 -0
- package/dist/execution/result.js.map +1 -0
- package/dist/execution/variant.d.ts +33 -0
- package/dist/execution/variant.d.ts.map +1 -0
- package/dist/execution/variant.js +34 -0
- package/dist/execution/variant.js.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/reader/scene-memory.d.ts +15 -0
- package/dist/reader/scene-memory.d.ts.map +1 -0
- package/dist/reader/scene-memory.js +23 -0
- package/dist/reader/scene-memory.js.map +1 -0
- package/dist/reader/variant-memory.d.ts +42 -0
- package/dist/reader/variant-memory.d.ts.map +1 -0
- package/dist/reader/variant-memory.js +48 -0
- package/dist/reader/variant-memory.js.map +1 -0
- package/dist/state/navigation-state.d.ts +9 -0
- package/dist/state/navigation-state.d.ts.map +1 -0
- package/dist/state/navigation-state.js +2 -0
- package/dist/state/navigation-state.js.map +1 -0
- package/dist/state/reader-state.d.ts +15 -0
- package/dist/state/reader-state.d.ts.map +1 -0
- package/dist/state/reader-state.js +2 -0
- package/dist/state/reader-state.js.map +1 -0
- package/dist/state/runtime-state.d.ts +16 -0
- package/dist/state/runtime-state.d.ts.map +1 -0
- package/dist/state/runtime-state.js +2 -0
- package/dist/state/runtime-state.js.map +1 -0
- package/dist/state/story-state.d.ts +14 -0
- package/dist/state/story-state.d.ts.map +1 -0
- package/dist/state/story-state.js +2 -0
- package/dist/state/story-state.js.map +1 -0
- package/package.json +38 -4
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
function error(kind, message, span) {
|
|
2
|
+
return span ? { kind, message, span } : { kind, message };
|
|
3
|
+
}
|
|
4
|
+
export const RuntimeErrors = {
|
|
5
|
+
unknownIdentifier(name, span) {
|
|
6
|
+
return error("unknown-identifier", `Unknown identifier "${name}".`, span);
|
|
7
|
+
},
|
|
8
|
+
typeMismatch(message, span) {
|
|
9
|
+
return error("type-mismatch", message, span);
|
|
10
|
+
},
|
|
11
|
+
divisionByZero(span) {
|
|
12
|
+
return error("division-by-zero", "Division or modulo by zero.", span);
|
|
13
|
+
},
|
|
14
|
+
invalidArithmeticResult(span) {
|
|
15
|
+
return error("invalid-arithmetic-result", "Arithmetic result is not a finite, JSON-representable number.", span);
|
|
16
|
+
},
|
|
17
|
+
emptyChoice(span) {
|
|
18
|
+
return error("empty-choice", "No choice items are available.", span);
|
|
19
|
+
},
|
|
20
|
+
invalidChoiceSelection(message) {
|
|
21
|
+
return error("invalid-choice-selection", message);
|
|
22
|
+
},
|
|
23
|
+
invalidSceneTarget(target, span) {
|
|
24
|
+
return error("invalid-scene-target", `Target scene "${target}" does not exist.`, span);
|
|
25
|
+
},
|
|
26
|
+
stepLimitExceeded() {
|
|
27
|
+
return error("step-limit-exceeded", "Execution step budget exceeded before reaching a suspension point.");
|
|
28
|
+
},
|
|
29
|
+
unknownBuiltin(name, span) {
|
|
30
|
+
return error("unknown-builtin", `Unknown builtin call "${name}".`, span);
|
|
31
|
+
},
|
|
32
|
+
invalidVariantReference(variantId, span) {
|
|
33
|
+
return error("invalid-variant-reference", `Reference to unknown Variant "${variantId}".`, span);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/execution/errors.ts"],"names":[],"mappings":"AA2BA,SAAS,KAAK,CAAC,IAA+B,EAAE,OAAe,EAAE,IAAiB;IAChF,OAAO,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;AAC5D,CAAC;AAED,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,iBAAiB,CAAC,IAAY,EAAE,IAAiB;QAC/C,OAAO,KAAK,CAAC,oBAAoB,EAAE,uBAAuB,IAAI,IAAI,EAAE,IAAI,CAAC,CAAC;IAC5E,CAAC;IACD,YAAY,CAAC,OAAe,EAAE,IAAiB;QAC7C,OAAO,KAAK,CAAC,eAAe,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;IAC/C,CAAC;IACD,cAAc,CAAC,IAAiB;QAC9B,OAAO,KAAK,CAAC,kBAAkB,EAAE,6BAA6B,EAAE,IAAI,CAAC,CAAC;IACxE,CAAC;IACD,uBAAuB,CAAC,IAAiB;QACvC,OAAO,KAAK,CACV,2BAA2B,EAC3B,+DAA+D,EAC/D,IAAI,CACL,CAAC;IACJ,CAAC;IACD,WAAW,CAAC,IAAiB;QAC3B,OAAO,KAAK,CAAC,cAAc,EAAE,gCAAgC,EAAE,IAAI,CAAC,CAAC;IACvE,CAAC;IACD,sBAAsB,CAAC,OAAe;QACpC,OAAO,KAAK,CAAC,0BAA0B,EAAE,OAAO,CAAC,CAAC;IACpD,CAAC;IACD,kBAAkB,CAAC,MAAc,EAAE,IAAiB;QAClD,OAAO,KAAK,CAAC,sBAAsB,EAAE,iBAAiB,MAAM,mBAAmB,EAAE,IAAI,CAAC,CAAC;IACzF,CAAC;IACD,iBAAiB;QACf,OAAO,KAAK,CAAC,qBAAqB,EAAE,oEAAoE,CAAC,CAAC;IAC5G,CAAC;IACD,cAAc,CAAC,IAAY,EAAE,IAAiB;QAC5C,OAAO,KAAK,CAAC,iBAAiB,EAAE,yBAAyB,IAAI,IAAI,EAAE,IAAI,CAAC,CAAC;IAC3E,CAAC;IACD,uBAAuB,CAAC,SAAiB,EAAE,IAAiB;QAC1D,OAAO,KAAK,CAAC,2BAA2B,EAAE,iCAAiC,SAAS,IAAI,EAAE,IAAI,CAAC,CAAC;IAClG,CAAC;CACO,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { ExpressionNode, StoryDocument } from "@aftertext/compiler";
|
|
2
|
+
import type { ReaderState } from "../state/reader-state.js";
|
|
3
|
+
import type { StoryState, StoryValue } from "../state/story-state.js";
|
|
4
|
+
import type { RuntimeExecutionError } from "./errors.js";
|
|
5
|
+
/**
|
|
6
|
+
* Everything expression evaluation may read (docs/PROJECT_SPEC.md Section
|
|
7
|
+
* 17.17). Responsibilities are strictly partitioned: `story` backs
|
|
8
|
+
* `Identifier` resolution (unchanged since before Reader Memory queries
|
|
9
|
+
* existed); `reader` backs Reader Memory builtin values, reachable only
|
|
10
|
+
* through `Call` dispatch, never as an ordinary identifier; `document`
|
|
11
|
+
* backs the defensive Scene/Variant existence checks a best-effort/
|
|
12
|
+
* malformed document's Reader Memory call might still need. Pure and
|
|
13
|
+
* immutable — evaluation never mutates any of these, and no module-global
|
|
14
|
+
* or "current runtime" state exists anywhere in this module.
|
|
15
|
+
*/
|
|
16
|
+
export interface EvaluationContext {
|
|
17
|
+
readonly document: StoryDocument;
|
|
18
|
+
readonly story: StoryState;
|
|
19
|
+
readonly reader: ReaderState;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Pure evaluator for the compiler's existing `ExpressionNode` against an
|
|
23
|
+
* `EvaluationContext`. Implements docs/PROJECT_SPEC.md Section 17.8 exactly:
|
|
24
|
+
* explicit, deterministic rules, never implicit JavaScript truthiness or
|
|
25
|
+
* coercion. Result-typed rather than throwing, matching this package's
|
|
26
|
+
* existing no-throw, pure-function style. `Call` (Reader Memory queries)
|
|
27
|
+
* is defined separately in Sections 17.14–17.16.
|
|
28
|
+
*/
|
|
29
|
+
export type ExpressionOutcome = {
|
|
30
|
+
readonly ok: true;
|
|
31
|
+
readonly value: StoryValue;
|
|
32
|
+
} | {
|
|
33
|
+
readonly ok: false;
|
|
34
|
+
readonly error: RuntimeExecutionError;
|
|
35
|
+
};
|
|
36
|
+
export type ConditionOutcome = {
|
|
37
|
+
readonly ok: true;
|
|
38
|
+
readonly value: boolean;
|
|
39
|
+
} | {
|
|
40
|
+
readonly ok: false;
|
|
41
|
+
readonly error: RuntimeExecutionError;
|
|
42
|
+
};
|
|
43
|
+
export declare function evaluateExpression(expression: ExpressionNode, context: EvaluationContext): ExpressionOutcome;
|
|
44
|
+
/**
|
|
45
|
+
* Evaluates `expression` and requires the result to be an actual boolean —
|
|
46
|
+
* no truthiness of any kind. Used for `@if`/`@elseif`/`@when`/choice `if`
|
|
47
|
+
* conditions, and reused below to give `!`/`&&`/`||` the same strict rule.
|
|
48
|
+
*/
|
|
49
|
+
export declare function evaluateCondition(expression: ExpressionNode, context: EvaluationContext): ConditionOutcome;
|
|
50
|
+
//# sourceMappingURL=expression.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expression.d.ts","sourceRoot":"","sources":["../../src/execution/expression.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,cAAc,EAEd,aAAa,EAEd,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAEtE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAGzD;;;;;;;;;;GAUG;AACH,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,QAAQ,EAAE,aAAa,CAAC;IACjC,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;IAC3B,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;CAC9B;AAED;;;;;;;GAOG;AACH,MAAM,MAAM,iBAAiB,GACzB;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAA;CAAE,GACjD;IAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,qBAAqB,CAAA;CAAE,CAAC;AAElE,MAAM,MAAM,gBAAgB,GACxB;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAA;CAAE,GAC9C;IAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,qBAAqB,CAAA;CAAE,CAAC;AAWlE,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,cAAc,EAAE,OAAO,EAAE,iBAAiB,GAAG,iBAAiB,CAqB5G;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,cAAc,EAAE,OAAO,EAAE,iBAAiB,GAAG,gBAAgB,CAa1G"}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { RuntimeErrors } from "./errors.js";
|
|
2
|
+
import { evaluateMemoryQuery } from "./memory-queries.js";
|
|
3
|
+
function describeType(value) {
|
|
4
|
+
return value === null ? "null" : typeof value;
|
|
5
|
+
}
|
|
6
|
+
function sameType(a, b) {
|
|
7
|
+
if (a === null || b === null)
|
|
8
|
+
return a === null && b === null;
|
|
9
|
+
return typeof a === typeof b;
|
|
10
|
+
}
|
|
11
|
+
export function evaluateExpression(expression, context) {
|
|
12
|
+
switch (expression.type) {
|
|
13
|
+
case "Literal":
|
|
14
|
+
return { ok: true, value: expression.value };
|
|
15
|
+
case "Identifier": {
|
|
16
|
+
if (!Object.prototype.hasOwnProperty.call(context.story, expression.name)) {
|
|
17
|
+
return { ok: false, error: RuntimeErrors.unknownIdentifier(expression.name, expression.span) };
|
|
18
|
+
}
|
|
19
|
+
return { ok: true, value: context.story[expression.name] };
|
|
20
|
+
}
|
|
21
|
+
case "Unary":
|
|
22
|
+
return evaluateUnary(expression, context);
|
|
23
|
+
case "Binary":
|
|
24
|
+
return evaluateBinary(expression, context);
|
|
25
|
+
case "Call":
|
|
26
|
+
return evaluateMemoryQuery(expression, context.document, context.reader);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Evaluates `expression` and requires the result to be an actual boolean —
|
|
31
|
+
* no truthiness of any kind. Used for `@if`/`@elseif`/`@when`/choice `if`
|
|
32
|
+
* conditions, and reused below to give `!`/`&&`/`||` the same strict rule.
|
|
33
|
+
*/
|
|
34
|
+
export function evaluateCondition(expression, context) {
|
|
35
|
+
const result = evaluateExpression(expression, context);
|
|
36
|
+
if (!result.ok)
|
|
37
|
+
return result;
|
|
38
|
+
if (typeof result.value !== "boolean") {
|
|
39
|
+
return {
|
|
40
|
+
ok: false,
|
|
41
|
+
error: RuntimeErrors.typeMismatch(`Expected a boolean condition, got ${describeType(result.value)}.`, expression.span)
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
return { ok: true, value: result.value };
|
|
45
|
+
}
|
|
46
|
+
function evaluateUnary(expression, context) {
|
|
47
|
+
if (expression.operator === "!") {
|
|
48
|
+
const argument = evaluateCondition(expression.argument, context);
|
|
49
|
+
if (!argument.ok)
|
|
50
|
+
return argument;
|
|
51
|
+
return { ok: true, value: !argument.value };
|
|
52
|
+
}
|
|
53
|
+
// operator === "-"
|
|
54
|
+
const argument = evaluateExpression(expression.argument, context);
|
|
55
|
+
if (!argument.ok)
|
|
56
|
+
return argument;
|
|
57
|
+
if (typeof argument.value !== "number") {
|
|
58
|
+
return {
|
|
59
|
+
ok: false,
|
|
60
|
+
error: RuntimeErrors.typeMismatch(`Unary "-" requires a number operand, got ${describeType(argument.value)}.`, expression.span)
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
return { ok: true, value: -argument.value };
|
|
64
|
+
}
|
|
65
|
+
function isArithmeticOperator(operator) {
|
|
66
|
+
return operator === "+" || operator === "-" || operator === "*" || operator === "/" || operator === "%";
|
|
67
|
+
}
|
|
68
|
+
function isComparisonOperator(operator) {
|
|
69
|
+
return operator === "<" || operator === "<=" || operator === ">" || operator === ">=";
|
|
70
|
+
}
|
|
71
|
+
function evaluateBinary(expression, context) {
|
|
72
|
+
const { operator } = expression;
|
|
73
|
+
if (operator === "&&" || operator === "||") {
|
|
74
|
+
const left = evaluateCondition(expression.left, context);
|
|
75
|
+
if (!left.ok)
|
|
76
|
+
return left;
|
|
77
|
+
// Short-circuit: the right operand is not evaluated once the left
|
|
78
|
+
// already determines the result, so an unevaluated branch (including
|
|
79
|
+
// one containing a Reader Memory query) can never surface an error or
|
|
80
|
+
// execute at all.
|
|
81
|
+
if (operator === "&&" && left.value === false)
|
|
82
|
+
return { ok: true, value: false };
|
|
83
|
+
if (operator === "||" && left.value === true)
|
|
84
|
+
return { ok: true, value: true };
|
|
85
|
+
return evaluateCondition(expression.right, context);
|
|
86
|
+
}
|
|
87
|
+
const left = evaluateExpression(expression.left, context);
|
|
88
|
+
if (!left.ok)
|
|
89
|
+
return left;
|
|
90
|
+
const right = evaluateExpression(expression.right, context);
|
|
91
|
+
if (!right.ok)
|
|
92
|
+
return right;
|
|
93
|
+
if (operator === "==" || operator === "!=") {
|
|
94
|
+
const equal = sameType(left.value, right.value) && left.value === right.value;
|
|
95
|
+
return { ok: true, value: operator === "==" ? equal : !equal };
|
|
96
|
+
}
|
|
97
|
+
if (isArithmeticOperator(operator)) {
|
|
98
|
+
return evaluateArithmetic(operator, left.value, right.value, expression.span);
|
|
99
|
+
}
|
|
100
|
+
if (isComparisonOperator(operator)) {
|
|
101
|
+
return evaluateComparison(operator, left.value, right.value, expression.span);
|
|
102
|
+
}
|
|
103
|
+
return { ok: true, value: false }; // unreachable — all BinaryOperator members are handled above
|
|
104
|
+
}
|
|
105
|
+
function evaluateArithmetic(operator, left, right, span) {
|
|
106
|
+
if (typeof left !== "number" || typeof right !== "number") {
|
|
107
|
+
return {
|
|
108
|
+
ok: false,
|
|
109
|
+
error: RuntimeErrors.typeMismatch(`"${operator}" requires two number operands, got ${describeType(left)} and ${describeType(right)}.`, span)
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
if ((operator === "/" || operator === "%") && right === 0) {
|
|
113
|
+
return { ok: false, error: RuntimeErrors.divisionByZero(span) };
|
|
114
|
+
}
|
|
115
|
+
let result;
|
|
116
|
+
switch (operator) {
|
|
117
|
+
case "+":
|
|
118
|
+
result = left + right;
|
|
119
|
+
break;
|
|
120
|
+
case "-":
|
|
121
|
+
result = left - right;
|
|
122
|
+
break;
|
|
123
|
+
case "*":
|
|
124
|
+
result = left * right;
|
|
125
|
+
break;
|
|
126
|
+
case "/":
|
|
127
|
+
result = left / right;
|
|
128
|
+
break;
|
|
129
|
+
case "%":
|
|
130
|
+
result = left % right;
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
133
|
+
// General rule (17.8): any arithmetic result must remain a valid JSON
|
|
134
|
+
// number. Division/modulo by zero is the common case (already caught
|
|
135
|
+
// above); this also catches the rare overflow-to-Infinity case.
|
|
136
|
+
if (!Number.isFinite(result)) {
|
|
137
|
+
return { ok: false, error: RuntimeErrors.invalidArithmeticResult(span) };
|
|
138
|
+
}
|
|
139
|
+
return { ok: true, value: result };
|
|
140
|
+
}
|
|
141
|
+
function evaluateComparison(operator, left, right, span) {
|
|
142
|
+
if (typeof left !== "number" || typeof right !== "number") {
|
|
143
|
+
return {
|
|
144
|
+
ok: false,
|
|
145
|
+
error: RuntimeErrors.typeMismatch(`"${operator}" requires two number operands, got ${describeType(left)} and ${describeType(right)}.`, span)
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
switch (operator) {
|
|
149
|
+
case "<":
|
|
150
|
+
return { ok: true, value: left < right };
|
|
151
|
+
case "<=":
|
|
152
|
+
return { ok: true, value: left <= right };
|
|
153
|
+
case ">":
|
|
154
|
+
return { ok: true, value: left > right };
|
|
155
|
+
case ">=":
|
|
156
|
+
return { ok: true, value: left >= right };
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
//# sourceMappingURL=expression.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expression.js","sourceRoot":"","sources":["../../src/execution/expression.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAmC1D,SAAS,YAAY,CAAC,KAAiB;IACrC,OAAO,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,KAAK,CAAC;AAChD,CAAC;AAED,SAAS,QAAQ,CAAC,CAAa,EAAE,CAAa;IAC5C,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,IAAI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AAuC,YAAY,CAAC,IAAI,CAAC,QAAQ,YAAY,CAAC,KAAK,CAAC,GAAG,EACnG,IAAI,CACL;SACF,CAAC;IACJ,CAAC;IACD,QAAQ,QAAQ,EAAE,CAAC;QACjB,KAAK,GAAG;YACN,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,GAAG,KAAK,EAAE,CAAC;QAC3C,KAAK,IAAI;YACP,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,IAAI,KAAK,EAAE,CAAC;QAC5C,KAAK,GAAG;YACN,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,GAAG,KAAK,EAAE,CAAC;QAC3C,KAAK,IAAI;YACP,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,IAAI,KAAK,EAAE,CAAC;IAC9C,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { CallExpression, StoryDocument } from "@aftertext/compiler";
|
|
2
|
+
import type { ReaderState } from "../state/reader-state.js";
|
|
3
|
+
import type { StoryValue } from "../state/story-state.js";
|
|
4
|
+
import type { RuntimeExecutionError } from "./errors.js";
|
|
5
|
+
export type MemoryQueryOutcome = {
|
|
6
|
+
readonly ok: true;
|
|
7
|
+
readonly value: StoryValue;
|
|
8
|
+
} | {
|
|
9
|
+
readonly ok: false;
|
|
10
|
+
readonly error: RuntimeExecutionError;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Evaluates a Reader Memory builtin call (docs/PROJECT_SPEC.md Sections
|
|
14
|
+
* 17.14–17.16). Defensive: the compiler is expected to have already
|
|
15
|
+
* rejected an unknown callee, wrong arity, a non-literal argument, or an
|
|
16
|
+
* unknown Scene/Variant reference — this still re-checks each, exactly as
|
|
17
|
+
* `navigateTo` defensively re-checks a Goto/Choice target (17.11).
|
|
18
|
+
*/
|
|
19
|
+
export declare function evaluateMemoryQuery(call: CallExpression, document: StoryDocument, reader: ReaderState): MemoryQueryOutcome;
|
|
20
|
+
//# sourceMappingURL=memory-queries.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-queries.d.ts","sourceRoot":"","sources":["../../src/execution/memory-queries.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAc,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACrF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAI1D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAEzD,MAAM,MAAM,kBAAkB,GAC1B;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAA;CAAE,GACjD;IAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,qBAAqB,CAAA;CAAE,CAAC;AAiDlE;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,cAAc,EACpB,QAAQ,EAAE,aAAa,EACvB,MAAM,EAAE,WAAW,GAClB,kBAAkB,CA0BpB"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { hasVisitedScene, getSceneVisitCount } from "../reader/scene-memory.js";
|
|
2
|
+
import { hasSeenVariant, getLastSeenVariantBranch } from "../reader/variant-memory.js";
|
|
3
|
+
import { RuntimeErrors } from "./errors.js";
|
|
4
|
+
/**
|
|
5
|
+
* The fixed Reader Memory query builtin registry (docs/PROJECT_SPEC.md
|
|
6
|
+
* Section 17.15) — exactly four entries, not author-extensible. This is
|
|
7
|
+
* implementation code, not a dynamic function-lookup mechanism: adding a
|
|
8
|
+
* builtin means adding an entry here, never resolving a JS function by an
|
|
9
|
+
* author-supplied name.
|
|
10
|
+
*/
|
|
11
|
+
const MEMORY_QUERIES = {
|
|
12
|
+
visited: { kind: "scene", read: (reader, id) => hasVisitedScene(reader, id) },
|
|
13
|
+
visit_count: { kind: "scene", read: (reader, id) => getSceneVisitCount(reader, id) },
|
|
14
|
+
seen_variant: { kind: "variant", read: (reader, id) => hasSeenVariant(reader, id) },
|
|
15
|
+
last_seen_variant_branch: { kind: "variant", read: (reader, id) => getLastSeenVariantBranch(reader, id) }
|
|
16
|
+
};
|
|
17
|
+
function sceneExists(document, sceneId) {
|
|
18
|
+
return document.scenes.some((scene) => scene.id === sceneId);
|
|
19
|
+
}
|
|
20
|
+
/** Depth-first search for a Variant with id `variantId`, descending into Conditional/Variant branch bodies. */
|
|
21
|
+
function containsVariant(blocks, variantId) {
|
|
22
|
+
for (const block of blocks) {
|
|
23
|
+
if (block.type === "Variant") {
|
|
24
|
+
if (block.id === variantId)
|
|
25
|
+
return true;
|
|
26
|
+
for (const branch of block.branches) {
|
|
27
|
+
if (containsVariant(branch.blocks, variantId))
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
else if (block.type === "Conditional") {
|
|
32
|
+
for (const branch of block.branches) {
|
|
33
|
+
if (containsVariant(branch.blocks, variantId))
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Whether `variantId` is declared anywhere in `document`. `StoryDocument`
|
|
42
|
+
* has no direct Variant index, so this is the smallest deterministic
|
|
43
|
+
* substitute: a bounded recursive scan, used only on the defensive
|
|
44
|
+
* fallback path for a best-effort/malformed document (the compiler's own
|
|
45
|
+
* validation, Section 17.16, is the normal path and already rejects an
|
|
46
|
+
* unknown Variant reference before this would ever run).
|
|
47
|
+
*/
|
|
48
|
+
function variantExists(document, variantId) {
|
|
49
|
+
return document.scenes.some((scene) => containsVariant(scene.blocks, variantId));
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Evaluates a Reader Memory builtin call (docs/PROJECT_SPEC.md Sections
|
|
53
|
+
* 17.14–17.16). Defensive: the compiler is expected to have already
|
|
54
|
+
* rejected an unknown callee, wrong arity, a non-literal argument, or an
|
|
55
|
+
* unknown Scene/Variant reference — this still re-checks each, exactly as
|
|
56
|
+
* `navigateTo` defensively re-checks a Goto/Choice target (17.11).
|
|
57
|
+
*/
|
|
58
|
+
export function evaluateMemoryQuery(call, document, reader) {
|
|
59
|
+
const query = MEMORY_QUERIES[call.callee];
|
|
60
|
+
if (!query) {
|
|
61
|
+
return { ok: false, error: RuntimeErrors.unknownBuiltin(call.callee, call.span) };
|
|
62
|
+
}
|
|
63
|
+
const arg = call.args[0];
|
|
64
|
+
if (call.args.length !== 1 || !arg || arg.type !== "Literal" || typeof arg.value !== "string") {
|
|
65
|
+
return {
|
|
66
|
+
ok: false,
|
|
67
|
+
error: RuntimeErrors.typeMismatch(`"${call.callee}" requires exactly one string-literal argument.`, call.span)
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
const id = arg.value;
|
|
71
|
+
if (query.kind === "scene") {
|
|
72
|
+
if (!sceneExists(document, id)) {
|
|
73
|
+
return { ok: false, error: RuntimeErrors.invalidSceneTarget(id, call.span) };
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
if (!variantExists(document, id)) {
|
|
78
|
+
return { ok: false, error: RuntimeErrors.invalidVariantReference(id, call.span) };
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return { ok: true, value: query.read(reader, id) };
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=memory-queries.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-queries.js","sourceRoot":"","sources":["../../src/execution/memory-queries.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAChF,OAAO,EAAE,cAAc,EAAE,wBAAwB,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,IAAI,CAAC,IAAI,CAAC;SAC/G,CAAC;IACJ,CAAC;IAED,MAAM,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC;IACrB,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;QAC3B,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE,EAAE,CAAC,EAAE,CAAC;YAC/B,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,aAAa,CAAC,kBAAkB,CAAC,EAAE,EAAE,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QAC/E,CAAC;IACH,CAAC;SAAM,CAAC;QACN,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE,EAAE,CAAC,EAAE,CAAC;YACjC,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,aAAa,CAAC,uBAAuB,CAAC,EAAE,EAAE,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QACpF,CAAC;IACH,CAAC;IAED,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE,CAAC;AACrD,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { StoryDocument } from "@aftertext/compiler";
|
|
2
|
+
import type { RuntimeState } from "../state/runtime-state.js";
|
|
3
|
+
import { type ExecutionCursor } from "./cursor.js";
|
|
4
|
+
import type { ExecutionStep } from "./result.js";
|
|
5
|
+
/**
|
|
6
|
+
* Shared internal navigation operation used identically by `GotoNode`
|
|
7
|
+
* handling and by a resolved Choice selection (docs/PROJECT_SPEC.md
|
|
8
|
+
* Section 17.7: "share one navigation rule"). Not part of the public
|
|
9
|
+
* barrel.
|
|
10
|
+
*
|
|
11
|
+
* The returned `RuntimeState` already reflects the target scene; the
|
|
12
|
+
* target scene's own blocks are not walked here — execution suspends
|
|
13
|
+
* immediately with a `navigation` result, and the next `advance()` begins
|
|
14
|
+
* the walk. Never touches `ReaderState.visitedScenes`
|
|
15
|
+
* (`navigated != experienced`).
|
|
16
|
+
*
|
|
17
|
+
* On an invalid target, `runtimeState`/`cursor` are echoed back exactly as
|
|
18
|
+
* given — execution is progressive, not transactional (17.11): any
|
|
19
|
+
* automatic work already completed earlier in the same call is preserved
|
|
20
|
+
* in what the caller passes in here.
|
|
21
|
+
*/
|
|
22
|
+
export declare function navigateTo(document: StoryDocument, runtimeState: RuntimeState, cursor: ExecutionCursor, target: string): ExecutionStep;
|
|
23
|
+
//# sourceMappingURL=navigate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"navigate.d.ts","sourceRoot":"","sources":["../../src/execution/navigate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAkB,KAAK,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,UAAU,CACxB,QAAQ,EAAE,aAAa,EACvB,YAAY,EAAE,YAAY,EAC1B,MAAM,EAAE,eAAe,EACvB,MAAM,EAAE,MAAM,GACb,aAAa,CAYf"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { INITIAL_CURSOR } from "./cursor.js";
|
|
2
|
+
import { RuntimeErrors } from "./errors.js";
|
|
3
|
+
/**
|
|
4
|
+
* Shared internal navigation operation used identically by `GotoNode`
|
|
5
|
+
* handling and by a resolved Choice selection (docs/PROJECT_SPEC.md
|
|
6
|
+
* Section 17.7: "share one navigation rule"). Not part of the public
|
|
7
|
+
* barrel.
|
|
8
|
+
*
|
|
9
|
+
* The returned `RuntimeState` already reflects the target scene; the
|
|
10
|
+
* target scene's own blocks are not walked here — execution suspends
|
|
11
|
+
* immediately with a `navigation` result, and the next `advance()` begins
|
|
12
|
+
* the walk. Never touches `ReaderState.visitedScenes`
|
|
13
|
+
* (`navigated != experienced`).
|
|
14
|
+
*
|
|
15
|
+
* On an invalid target, `runtimeState`/`cursor` are echoed back exactly as
|
|
16
|
+
* given — execution is progressive, not transactional (17.11): any
|
|
17
|
+
* automatic work already completed earlier in the same call is preserved
|
|
18
|
+
* in what the caller passes in here.
|
|
19
|
+
*/
|
|
20
|
+
export function navigateTo(document, runtimeState, cursor, target) {
|
|
21
|
+
const targetScene = document.scenes.find((scene) => scene.id === target);
|
|
22
|
+
if (!targetScene) {
|
|
23
|
+
return { runtimeState, cursor, result: { type: "error", error: RuntimeErrors.invalidSceneTarget(target) } };
|
|
24
|
+
}
|
|
25
|
+
const from = runtimeState.navigation.sceneId;
|
|
26
|
+
return {
|
|
27
|
+
runtimeState: { ...runtimeState, navigation: { sceneId: target } },
|
|
28
|
+
cursor: INITIAL_CURSOR,
|
|
29
|
+
result: { type: "navigation", from, to: target }
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=navigate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"navigate.js","sourceRoot":"","sources":["../../src/execution/navigate.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAwB,MAAM,aAAa,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAG5C;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,UAAU,CACxB,QAAuB,EACvB,YAA0B,EAC1B,MAAuB,EACvB,MAAc;IAEd,MAAM,WAAW,GAAG,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,MAAM,CAAC,CAAC;IACzE,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,aAAa,CAAC,kBAAkB,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC;IAC9G,CAAC;IAED,MAAM,IAAI,GAAG,YAAY,CAAC,UAAU,CAAC,OAAO,CAAC;IAC7C,OAAO;QACL,YAAY,EAAE,EAAE,GAAG,YAAY,EAAE,UAAU,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE;QAClE,MAAM,EAAE,cAAc;QACtB,MAAM,EAAE,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,EAAE;KACjD,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { HeadingNode, ParagraphNode, PresentationCommand } from "@aftertext/compiler";
|
|
2
|
+
import type { RuntimeState } from "../state/runtime-state.js";
|
|
3
|
+
import type { ExecutionCursor } from "./cursor.js";
|
|
4
|
+
import type { RuntimeExecutionError } from "./errors.js";
|
|
5
|
+
/**
|
|
6
|
+
* One item offered by a Choice suspension. `index` is a transient
|
|
7
|
+
* request/response correlator scoped to that one suspension — never a
|
|
8
|
+
* stable identity, never persisted (docs/PROJECT_SPEC.md Section 17.7).
|
|
9
|
+
*/
|
|
10
|
+
export interface AvailableChoiceItem {
|
|
11
|
+
readonly index: number;
|
|
12
|
+
readonly text: string;
|
|
13
|
+
readonly target: string;
|
|
14
|
+
}
|
|
15
|
+
export interface ContentResult {
|
|
16
|
+
readonly type: "content";
|
|
17
|
+
readonly block: ParagraphNode | HeadingNode;
|
|
18
|
+
}
|
|
19
|
+
export interface PresentationResult {
|
|
20
|
+
readonly type: "presentation";
|
|
21
|
+
readonly command: PresentationCommand;
|
|
22
|
+
}
|
|
23
|
+
export interface ChoiceResult {
|
|
24
|
+
readonly type: "choice";
|
|
25
|
+
readonly items: readonly AvailableChoiceItem[];
|
|
26
|
+
}
|
|
27
|
+
export interface NavigationResult {
|
|
28
|
+
readonly type: "navigation";
|
|
29
|
+
readonly from: string;
|
|
30
|
+
readonly to: string;
|
|
31
|
+
}
|
|
32
|
+
export interface CompletedResult {
|
|
33
|
+
readonly type: "completed";
|
|
34
|
+
}
|
|
35
|
+
export interface ErrorResult {
|
|
36
|
+
readonly type: "error";
|
|
37
|
+
readonly error: RuntimeExecutionError;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Exhaustive suspension/terminal outcomes of one `advance`/`selectChoice`
|
|
41
|
+
* call. Runtime errors are their own variant (`ErrorResult`) — always
|
|
42
|
+
* distinguishable from a valid suspension via `result.type`.
|
|
43
|
+
*/
|
|
44
|
+
export type ExecutionResult = ContentResult | PresentationResult | ChoiceResult | NavigationResult | CompletedResult | ErrorResult;
|
|
45
|
+
export interface ExecutionStep {
|
|
46
|
+
readonly runtimeState: RuntimeState;
|
|
47
|
+
readonly cursor: ExecutionCursor;
|
|
48
|
+
readonly result: ExecutionResult;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=result.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"result.d.ts","sourceRoot":"","sources":["../../src/execution/result.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC3F,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAEzD;;;;GAIG;AACH,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,KAAK,EAAE,aAAa,GAAG,WAAW,CAAC;CAC7C;AAED,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC;IAC9B,QAAQ,CAAC,OAAO,EAAE,mBAAmB,CAAC;CACvC;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,SAAS,mBAAmB,EAAE,CAAC;CAChD;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;CAC5B;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,qBAAqB,CAAC;CACvC;AAED;;;;GAIG;AACH,MAAM,MAAM,eAAe,GACvB,aAAa,GACb,kBAAkB,GAClB,YAAY,GACZ,gBAAgB,GAChB,eAAe,GACf,WAAW,CAAC;AAEhB,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,YAAY,EAAE,YAAY,CAAC;IACpC,QAAQ,CAAC,MAAM,EAAE,eAAe,CAAC;IACjC,QAAQ,CAAC,MAAM,EAAE,eAAe,CAAC;CAClC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"result.js","sourceRoot":"","sources":["../../src/execution/result.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { StoryBlock, VariantNode } from "@aftertext/compiler";
|
|
2
|
+
import { type EvaluationContext } from "./expression.js";
|
|
3
|
+
import type { RuntimeExecutionError } from "./errors.js";
|
|
4
|
+
export interface ResolvedVariant {
|
|
5
|
+
readonly variantId: string;
|
|
6
|
+
readonly branchId: string;
|
|
7
|
+
readonly blocks: readonly StoryBlock[];
|
|
8
|
+
}
|
|
9
|
+
export type VariantResolution = {
|
|
10
|
+
readonly ok: true;
|
|
11
|
+
readonly resolved: ResolvedVariant | undefined;
|
|
12
|
+
} | {
|
|
13
|
+
readonly ok: false;
|
|
14
|
+
readonly error: RuntimeExecutionError;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Pure Variant resolution (docs/PROJECT_SPEC.md Section 17.7): `@when`
|
|
18
|
+
* conditions evaluated in source order, first match wins, `@otherwise` is
|
|
19
|
+
* the fallback. If nothing matches and there is no `@otherwise`,
|
|
20
|
+
* `resolved` is `undefined` — a graceful "no match," not an error. Never
|
|
21
|
+
* calls `recordVariantSeen` — `resolve != seen` (Decision C / 17.9).
|
|
22
|
+
*
|
|
23
|
+
* Takes the full `EvaluationContext` (Section 17.17), not a bare
|
|
24
|
+
* `StoryState`, because a `@when` condition may now contain a Reader
|
|
25
|
+
* Memory query (Section 17.15). This is an intentional, approved public
|
|
26
|
+
* API evolution — see Section 17.17 for the rejected alternatives (an
|
|
27
|
+
* implicit empty `ReaderState`, overload-shape sniffing, module-global
|
|
28
|
+
* state). `resolveVariant` itself remains pure, deterministic, and
|
|
29
|
+
* first-match-wins; only the information available to its condition
|
|
30
|
+
* evaluator changed.
|
|
31
|
+
*/
|
|
32
|
+
export declare function resolveVariant(node: VariantNode, context: EvaluationContext): VariantResolution;
|
|
33
|
+
//# sourceMappingURL=variant.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"variant.d.ts","sourceRoot":"","sources":["../../src/execution/variant.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACnE,OAAO,EAAqB,KAAK,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAC5E,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAEzD,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,SAAS,UAAU,EAAE,CAAC;CACxC;AAED,MAAM,MAAM,iBAAiB,GACzB;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,eAAe,GAAG,SAAS,CAAA;CAAE,GACrE;IAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,qBAAqB,CAAA;CAAE,CAAC;AAElE;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,iBAAiB,GAAG,iBAAiB,CAe/F"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { evaluateCondition } from "./expression.js";
|
|
2
|
+
/**
|
|
3
|
+
* Pure Variant resolution (docs/PROJECT_SPEC.md Section 17.7): `@when`
|
|
4
|
+
* conditions evaluated in source order, first match wins, `@otherwise` is
|
|
5
|
+
* the fallback. If nothing matches and there is no `@otherwise`,
|
|
6
|
+
* `resolved` is `undefined` — a graceful "no match," not an error. Never
|
|
7
|
+
* calls `recordVariantSeen` — `resolve != seen` (Decision C / 17.9).
|
|
8
|
+
*
|
|
9
|
+
* Takes the full `EvaluationContext` (Section 17.17), not a bare
|
|
10
|
+
* `StoryState`, because a `@when` condition may now contain a Reader
|
|
11
|
+
* Memory query (Section 17.15). This is an intentional, approved public
|
|
12
|
+
* API evolution — see Section 17.17 for the rejected alternatives (an
|
|
13
|
+
* implicit empty `ReaderState`, overload-shape sniffing, module-global
|
|
14
|
+
* state). `resolveVariant` itself remains pure, deterministic, and
|
|
15
|
+
* first-match-wins; only the information available to its condition
|
|
16
|
+
* evaluator changed.
|
|
17
|
+
*/
|
|
18
|
+
export function resolveVariant(node, context) {
|
|
19
|
+
for (const branch of node.branches) {
|
|
20
|
+
if (branch.kind === "otherwise") {
|
|
21
|
+
return { ok: true, resolved: { variantId: node.id, branchId: branch.branchId, blocks: branch.blocks } };
|
|
22
|
+
}
|
|
23
|
+
if (!branch.condition)
|
|
24
|
+
continue; // defensive: "when" branches always carry a condition per the compiler grammar
|
|
25
|
+
const condition = evaluateCondition(branch.condition, context);
|
|
26
|
+
if (!condition.ok)
|
|
27
|
+
return { ok: false, error: condition.error };
|
|
28
|
+
if (condition.value) {
|
|
29
|
+
return { ok: true, resolved: { variantId: node.id, branchId: branch.branchId, blocks: branch.blocks } };
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return { ok: true, resolved: undefined };
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=variant.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"variant.js","sourceRoot":"","sources":["../../src/execution/variant.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAA0B,MAAM,iBAAiB,CAAC;AAa5E;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,cAAc,CAAC,IAAiB,EAAE,OAA0B;IAC1E,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;QACnC,IAAI,MAAM,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;YAChC,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,SAAS,EAAE,IAAI,CAAC,EAAE,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC;QAC1G,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,SAAS;YAAE,SAAS,CAAC,+EAA+E;QAEhH,MAAM,SAAS,GAAG,iBAAiB,CAAC,MAAM,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;QAC/D,IAAI,CAAC,SAAS,CAAC,EAAE;YAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,CAAC,KAAK,EAAE,CAAC;QAChE,IAAI,SAAS,CAAC,KAAK,EAAE,CAAC;YACpB,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,SAAS,EAAE,IAAI,CAAC,EAAE,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC;QAC1G,CAAC;IACH,CAAC;IACD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC;AAC3C,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export type { StoryValue, StoryState } from "./state/story-state.js";
|
|
2
|
+
export type { ReaderState } from "./state/reader-state.js";
|
|
3
|
+
export type { NavigationState } from "./state/navigation-state.js";
|
|
4
|
+
export type { RuntimeState } from "./state/runtime-state.js";
|
|
5
|
+
export type { SceneVisitMemory } from "./reader/scene-memory.js";
|
|
6
|
+
export { recordSceneVisit, hasVisitedScene, getSceneVisitCount } from "./reader/scene-memory.js";
|
|
7
|
+
export type { VariantMemory } from "./reader/variant-memory.js";
|
|
8
|
+
export { recordVariantSeen, hasVariantChangedSinceRead, hasSeenVariant, getLastSeenVariantBranch } from "./reader/variant-memory.js";
|
|
9
|
+
export { createRuntimeState } from "./create-runtime-state.js";
|
|
10
|
+
export type { ExecutionCursor } from "./execution/cursor.js";
|
|
11
|
+
export { INITIAL_CURSOR } from "./execution/cursor.js";
|
|
12
|
+
export type { AvailableChoiceItem, ContentResult, PresentationResult, ChoiceResult, NavigationResult, CompletedResult, ErrorResult, ExecutionResult, ExecutionStep } from "./execution/result.js";
|
|
13
|
+
export type { RuntimeExecutionErrorKind, RuntimeExecutionError } from "./execution/errors.js";
|
|
14
|
+
export { RuntimeErrors } from "./execution/errors.js";
|
|
15
|
+
export type { EvaluationContext } from "./execution/expression.js";
|
|
16
|
+
export type { ResolvedVariant, VariantResolution } from "./execution/variant.js";
|
|
17
|
+
export { resolveVariant } from "./execution/variant.js";
|
|
18
|
+
export type { AdvanceOptions } from "./execution/advance.js";
|
|
19
|
+
export { advance } from "./execution/advance.js";
|
|
20
|
+
export { selectChoice } from "./execution/choice.js";
|
|
21
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACrE,YAAY,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAC3D,YAAY,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AACnE,YAAY,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAE7D,YAAY,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAEjG,YAAY,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EACL,iBAAiB,EACjB,0BAA0B,EAC1B,cAAc,EACd,wBAAwB,EACzB,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAK/D,YAAY,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD,YAAY,EACV,mBAAmB,EACnB,aAAa,EACb,kBAAkB,EAClB,YAAY,EACZ,gBAAgB,EAChB,eAAe,EACf,WAAW,EACX,eAAe,EACf,aAAa,EACd,MAAM,uBAAuB,CAAC;AAE/B,YAAY,EAAE,yBAAyB,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAC9F,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAetD,YAAY,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAEnE,YAAY,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AACjF,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAExD,YAAY,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAEjD,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// Public API surface. Only runtime-owned domain types and the small set of
|
|
2
|
+
// pure functions that operate on them are exported — no internal helpers,
|
|
3
|
+
// no mutable module-level state, and nothing from `@aftertext/compiler`
|
|
4
|
+
// re-exported here (consumers that need compiler types import them from
|
|
5
|
+
// `@aftertext/compiler` directly).
|
|
6
|
+
export { recordSceneVisit, hasVisitedScene, getSceneVisitCount } from "./reader/scene-memory.js";
|
|
7
|
+
export { recordVariantSeen, hasVariantChangedSinceRead, hasSeenVariant, getLastSeenVariantBranch } from "./reader/variant-memory.js";
|
|
8
|
+
export { createRuntimeState } from "./create-runtime-state.js";
|
|
9
|
+
export { INITIAL_CURSOR } from "./execution/cursor.js";
|
|
10
|
+
export { RuntimeErrors } from "./execution/errors.js";
|
|
11
|
+
export { resolveVariant } from "./execution/variant.js";
|
|
12
|
+
export { advance } from "./execution/advance.js";
|
|
13
|
+
export { selectChoice } from "./execution/choice.js";
|
|
14
|
+
//# sourceMappingURL=index.js.map
|