@sharpee/engine 1.1.0 → 1.1.1
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sharpee/engine",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "Runtime engine for Sharpee IF Platform - game loop, command execution, and turn management",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"types": "./index.d.ts",
|
|
@@ -12,17 +12,17 @@
|
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@sharpee/channel-service": "^1.1.
|
|
16
|
-
"@sharpee/core": "^1.1.
|
|
17
|
-
"@sharpee/event-processor": "^1.1.
|
|
18
|
-
"@sharpee/plugins": "^1.1.
|
|
19
|
-
"@sharpee/if-domain": "^1.1.
|
|
20
|
-
"@sharpee/if-services": "^1.1.
|
|
21
|
-
"@sharpee/lang-en-us": "^1.1.
|
|
22
|
-
"@sharpee/parser-en-us": "^1.1.
|
|
23
|
-
"@sharpee/stdlib": "^1.1.
|
|
24
|
-
"@sharpee/text-blocks": "^1.1.
|
|
25
|
-
"@sharpee/world-model": "^1.1.
|
|
15
|
+
"@sharpee/channel-service": "^1.1.1",
|
|
16
|
+
"@sharpee/core": "^1.1.1",
|
|
17
|
+
"@sharpee/event-processor": "^1.1.1",
|
|
18
|
+
"@sharpee/plugins": "^1.1.1",
|
|
19
|
+
"@sharpee/if-domain": "^1.1.1",
|
|
20
|
+
"@sharpee/if-services": "^1.1.1",
|
|
21
|
+
"@sharpee/lang-en-us": "^1.1.1",
|
|
22
|
+
"@sharpee/parser-en-us": "^1.1.1",
|
|
23
|
+
"@sharpee/stdlib": "^1.1.1",
|
|
24
|
+
"@sharpee/text-blocks": "^1.1.1",
|
|
25
|
+
"@sharpee/world-model": "^1.1.1",
|
|
26
26
|
"fflate": "^0.8.2"
|
|
27
27
|
},
|
|
28
28
|
"keywords": [
|
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Scene evaluation turn plugin (ADR-149).
|
|
2
|
+
* Scene evaluation turn plugin (ADR-149, ADR-186).
|
|
3
3
|
*
|
|
4
4
|
* Evaluates scene begin/end conditions each turn. Runs after NPC turns
|
|
5
5
|
* and state machines, before daemons/fuses (priority 60).
|
|
6
6
|
*
|
|
7
7
|
* For each registered scene:
|
|
8
|
-
* - If state='waiting' and begin() returns true → activate, emit scene_began
|
|
9
|
-
*
|
|
8
|
+
* - If state='waiting' and begin() returns true → activate, emit scene_began,
|
|
9
|
+
* then invoke the scene's onBegin reaction (ADR-186)
|
|
10
|
+
* - If state='active' and end() returns true → end (or reset if recurring),
|
|
11
|
+
* emit scene_ended, then invoke the scene's onEnd reaction (ADR-186)
|
|
10
12
|
* - If state='active' → increment activeTurns
|
|
11
13
|
*
|
|
14
|
+
* scene_began / scene_ended are emitted as observable facts (perception,
|
|
15
|
+
* tooling, transcripts). Author-visible reactions come from the typed
|
|
16
|
+
* onBegin/onEnd callbacks, translated here into game.message events — the
|
|
17
|
+
* event the prose pipeline renders — so reactions are visible by construction
|
|
18
|
+
* (ADR-186).
|
|
19
|
+
*
|
|
12
20
|
* Public interface: SceneEvaluationPlugin (TurnPlugin implementation).
|
|
13
21
|
* Owner context: @sharpee/engine — turn cycle
|
|
14
22
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scene-evaluation-plugin.d.ts","sourceRoot":"","sources":["../../../../../../repos/sharpee/packages/engine/src/scene-evaluation-plugin.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"scene-evaluation-plugin.d.ts","sourceRoot":"","sources":["../../../../../../repos/sharpee/packages/engine/src/scene-evaluation-plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAQ/C,OAAO,KAAK,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AA2DtE,qBAAa,qBAAsB,YAAW,UAAU;IACtD,EAAE,SAA8B;IAChC,QAAQ,SAAM;IAEd;;OAEG;IACH,aAAa,CAAC,OAAO,EAAE,iBAAiB,GAAG,cAAc,EAAE;CAqF5D"}
|
|
@@ -1,15 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* Scene evaluation turn plugin (ADR-149).
|
|
3
|
+
* Scene evaluation turn plugin (ADR-149, ADR-186).
|
|
4
4
|
*
|
|
5
5
|
* Evaluates scene begin/end conditions each turn. Runs after NPC turns
|
|
6
6
|
* and state machines, before daemons/fuses (priority 60).
|
|
7
7
|
*
|
|
8
8
|
* For each registered scene:
|
|
9
|
-
* - If state='waiting' and begin() returns true → activate, emit scene_began
|
|
10
|
-
*
|
|
9
|
+
* - If state='waiting' and begin() returns true → activate, emit scene_began,
|
|
10
|
+
* then invoke the scene's onBegin reaction (ADR-186)
|
|
11
|
+
* - If state='active' and end() returns true → end (or reset if recurring),
|
|
12
|
+
* emit scene_ended, then invoke the scene's onEnd reaction (ADR-186)
|
|
11
13
|
* - If state='active' → increment activeTurns
|
|
12
14
|
*
|
|
15
|
+
* scene_began / scene_ended are emitted as observable facts (perception,
|
|
16
|
+
* tooling, transcripts). Author-visible reactions come from the typed
|
|
17
|
+
* onBegin/onEnd callbacks, translated here into game.message events — the
|
|
18
|
+
* event the prose pipeline renders — so reactions are visible by construction
|
|
19
|
+
* (ADR-186).
|
|
20
|
+
*
|
|
13
21
|
* Public interface: SceneEvaluationPlugin (TurnPlugin implementation).
|
|
14
22
|
* Owner context: @sharpee/engine — turn cycle
|
|
15
23
|
*/
|
|
@@ -19,16 +27,54 @@ const world_model_1 = require("@sharpee/world-model");
|
|
|
19
27
|
let eventCounter = 0;
|
|
20
28
|
/**
|
|
21
29
|
* Creates a minimal ISemanticEvent with the given type and data.
|
|
30
|
+
*
|
|
31
|
+
* The id is made unique by a monotonic counter — no wall-clock is stamped in
|
|
32
|
+
* (deterministic replay, ADR-186). timestamp is left as a 0 sentinel; the
|
|
33
|
+
* engine's turn-event-processor backfills it at the single normalization point
|
|
34
|
+
* (`event.timestamp || Date.now()`).
|
|
22
35
|
*/
|
|
23
36
|
function sceneEvent(type, data) {
|
|
24
37
|
return {
|
|
25
|
-
id: `scene-${++eventCounter}
|
|
38
|
+
id: `scene-${++eventCounter}`,
|
|
26
39
|
type,
|
|
27
|
-
timestamp:
|
|
40
|
+
timestamp: 0,
|
|
28
41
|
entities: {},
|
|
29
42
|
data,
|
|
30
43
|
};
|
|
31
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* Translates the return of a scene reaction callback into game.message events.
|
|
47
|
+
*
|
|
48
|
+
* Invokes the callback under try/catch (parity with the begin/end condition
|
|
49
|
+
* guards): a throwing callback is swallowed and produces no events, the
|
|
50
|
+
* transition having already completed. Normalizes the return (undefined → none,
|
|
51
|
+
* a single reaction → one event) and maps each SceneReaction to a game.message
|
|
52
|
+
* carrying either direct text or a messageId + params.
|
|
53
|
+
*/
|
|
54
|
+
function reactionEvents(callback, ctx) {
|
|
55
|
+
if (!callback)
|
|
56
|
+
return [];
|
|
57
|
+
let result;
|
|
58
|
+
try {
|
|
59
|
+
result = callback(ctx);
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
// Callback threw — transition already happened; emit no reaction events.
|
|
63
|
+
return [];
|
|
64
|
+
}
|
|
65
|
+
if (!result)
|
|
66
|
+
return [];
|
|
67
|
+
const reactions = Array.isArray(result) ? result : [result];
|
|
68
|
+
return reactions.map((reaction) => {
|
|
69
|
+
if ('text' in reaction) {
|
|
70
|
+
return sceneEvent('game.message', { text: reaction.text });
|
|
71
|
+
}
|
|
72
|
+
return sceneEvent('game.message', {
|
|
73
|
+
messageId: reaction.messageId,
|
|
74
|
+
params: reaction.params,
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
}
|
|
32
78
|
class SceneEvaluationPlugin {
|
|
33
79
|
id = 'sharpee.scene-evaluation';
|
|
34
80
|
priority = 60;
|
|
@@ -60,6 +106,13 @@ class SceneEvaluationPlugin {
|
|
|
60
106
|
sceneName: trait.name,
|
|
61
107
|
turn,
|
|
62
108
|
}));
|
|
109
|
+
// Author-visible reaction (ADR-186)
|
|
110
|
+
events.push(...reactionEvents(conds.onBegin, {
|
|
111
|
+
world,
|
|
112
|
+
sceneId,
|
|
113
|
+
sceneName: trait.name,
|
|
114
|
+
turn,
|
|
115
|
+
}));
|
|
63
116
|
}
|
|
64
117
|
}
|
|
65
118
|
catch {
|
|
@@ -91,6 +144,15 @@ class SceneEvaluationPlugin {
|
|
|
91
144
|
turn,
|
|
92
145
|
totalTurns,
|
|
93
146
|
}));
|
|
147
|
+
// Author-visible reaction (ADR-186). totalTurns is captured before
|
|
148
|
+
// the activeTurns reset above.
|
|
149
|
+
events.push(...reactionEvents(conds.onEnd, {
|
|
150
|
+
world,
|
|
151
|
+
sceneId,
|
|
152
|
+
sceneName: trait.name,
|
|
153
|
+
turn,
|
|
154
|
+
totalTurns,
|
|
155
|
+
}));
|
|
94
156
|
}
|
|
95
157
|
else {
|
|
96
158
|
// Scene still active — increment turn counter
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scene-evaluation-plugin.js","sourceRoot":"","sources":["../../../../../../repos/sharpee/packages/engine/src/scene-evaluation-plugin.ts"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"scene-evaluation-plugin.js","sourceRoot":"","sources":["../../../../../../repos/sharpee/packages/engine/src/scene-evaluation-plugin.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;;;AAGH,sDAM8B;AAG9B,IAAI,YAAY,GAAG,CAAC,CAAC;AAErB;;;;;;;GAOG;AACH,SAAS,UAAU,CAAC,IAAY,EAAE,IAA6B;IAC7D,OAAO;QACL,EA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