@sharpee/stdlib 3.0.0 → 3.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.
Files changed (287) hide show
  1. package/actions/base/snapshot-utils.js +2 -2
  2. package/actions/base/snapshot-utils.js.map +1 -1
  3. package/actions/constants.d.ts +2 -0
  4. package/actions/constants.d.ts.map +1 -1
  5. package/actions/constants.js +3 -0
  6. package/actions/constants.js.map +1 -1
  7. package/actions/index.d.ts +2 -0
  8. package/actions/index.d.ts.map +1 -1
  9. package/actions/index.js +6 -0
  10. package/actions/index.js.map +1 -1
  11. package/actions/lifecycle/descriptor.d.ts +111 -0
  12. package/actions/lifecycle/descriptor.d.ts.map +1 -0
  13. package/actions/lifecycle/descriptor.js +22 -0
  14. package/actions/lifecycle/descriptor.js.map +1 -0
  15. package/actions/lifecycle/index.d.ts +14 -0
  16. package/actions/lifecycle/index.d.ts.map +1 -0
  17. package/actions/lifecycle/index.js +27 -0
  18. package/actions/lifecycle/index.js.map +1 -0
  19. package/actions/lifecycle/lifecycle-engine.d.ts +173 -0
  20. package/actions/lifecycle/lifecycle-engine.d.ts.map +1 -0
  21. package/actions/lifecycle/lifecycle-engine.js +247 -0
  22. package/actions/lifecycle/lifecycle-engine.js.map +1 -0
  23. package/actions/lifecycle/multi-object-lifecycle.d.ts +105 -0
  24. package/actions/lifecycle/multi-object-lifecycle.d.ts.map +1 -0
  25. package/actions/lifecycle/multi-object-lifecycle.js +136 -0
  26. package/actions/lifecycle/multi-object-lifecycle.js.map +1 -0
  27. package/actions/lifecycle/registry.d.ts +39 -0
  28. package/actions/lifecycle/registry.d.ts.map +1 -0
  29. package/actions/lifecycle/registry.js +128 -0
  30. package/actions/lifecycle/registry.js.map +1 -0
  31. package/actions/standard/asking/asking.d.ts +25 -0
  32. package/actions/standard/asking/asking.d.ts.map +1 -0
  33. package/actions/standard/asking/asking.js +114 -0
  34. package/actions/standard/asking/asking.js.map +1 -0
  35. package/actions/standard/asking/index.d.ts +5 -0
  36. package/actions/standard/asking/index.d.ts.map +1 -0
  37. package/actions/standard/asking/index.js +10 -0
  38. package/actions/standard/asking/index.js.map +1 -0
  39. package/actions/standard/attacking/attacking.d.ts +14 -0
  40. package/actions/standard/attacking/attacking.d.ts.map +1 -1
  41. package/actions/standard/attacking/attacking.js +138 -94
  42. package/actions/standard/attacking/attacking.js.map +1 -1
  43. package/actions/standard/attacking/index.d.ts +1 -1
  44. package/actions/standard/attacking/index.d.ts.map +1 -1
  45. package/actions/standard/attacking/index.js +2 -1
  46. package/actions/standard/attacking/index.js.map +1 -1
  47. package/actions/standard/climbing/climbing.d.ts +10 -0
  48. package/actions/standard/climbing/climbing.d.ts.map +1 -1
  49. package/actions/standard/climbing/climbing.js +51 -11
  50. package/actions/standard/climbing/climbing.js.map +1 -1
  51. package/actions/standard/closing/closing.d.ts +6 -0
  52. package/actions/standard/closing/closing.d.ts.map +1 -1
  53. package/actions/standard/closing/closing.js +37 -52
  54. package/actions/standard/closing/closing.js.map +1 -1
  55. package/actions/standard/cutting/cutting-messages.d.ts +17 -0
  56. package/actions/standard/cutting/cutting-messages.d.ts.map +1 -0
  57. package/actions/standard/cutting/cutting-messages.js +22 -0
  58. package/actions/standard/cutting/cutting-messages.js.map +1 -0
  59. package/actions/standard/cutting/cutting.d.ts +35 -0
  60. package/actions/standard/cutting/cutting.d.ts.map +1 -0
  61. package/actions/standard/cutting/cutting.js +228 -0
  62. package/actions/standard/cutting/cutting.js.map +1 -0
  63. package/actions/standard/cutting/index.d.ts +7 -0
  64. package/actions/standard/cutting/index.d.ts.map +1 -0
  65. package/actions/standard/cutting/index.js +12 -0
  66. package/actions/standard/cutting/index.js.map +1 -0
  67. package/actions/standard/deadly-room-death/deadly-room-death.d.ts +16 -0
  68. package/actions/standard/deadly-room-death/deadly-room-death.d.ts.map +1 -0
  69. package/actions/standard/deadly-room-death/deadly-room-death.js +44 -0
  70. package/actions/standard/deadly-room-death/deadly-room-death.js.map +1 -0
  71. package/actions/standard/deadly-room-death/index.d.ts +2 -0
  72. package/actions/standard/deadly-room-death/index.d.ts.map +1 -0
  73. package/actions/standard/deadly-room-death/index.js +6 -0
  74. package/actions/standard/deadly-room-death/index.js.map +1 -0
  75. package/actions/standard/digging/digging-messages.d.ts +17 -0
  76. package/actions/standard/digging/digging-messages.d.ts.map +1 -0
  77. package/actions/standard/digging/digging-messages.js +22 -0
  78. package/actions/standard/digging/digging-messages.js.map +1 -0
  79. package/actions/standard/digging/digging.d.ts +35 -0
  80. package/actions/standard/digging/digging.d.ts.map +1 -0
  81. package/actions/standard/digging/digging.js +228 -0
  82. package/actions/standard/digging/digging.js.map +1 -0
  83. package/actions/standard/digging/index.d.ts +7 -0
  84. package/actions/standard/digging/index.d.ts.map +1 -0
  85. package/actions/standard/digging/index.js +12 -0
  86. package/actions/standard/digging/index.js.map +1 -0
  87. package/actions/standard/drinking/drinking.d.ts +9 -0
  88. package/actions/standard/drinking/drinking.d.ts.map +1 -1
  89. package/actions/standard/drinking/drinking.js +40 -2
  90. package/actions/standard/drinking/drinking.js.map +1 -1
  91. package/actions/standard/dropping/dropping-types.d.ts +10 -18
  92. package/actions/standard/dropping/dropping-types.d.ts.map +1 -1
  93. package/actions/standard/dropping/dropping-types.js.map +1 -1
  94. package/actions/standard/dropping/dropping.d.ts +6 -0
  95. package/actions/standard/dropping/dropping.d.ts.map +1 -1
  96. package/actions/standard/dropping/dropping.js +86 -108
  97. package/actions/standard/dropping/dropping.js.map +1 -1
  98. package/actions/standard/eating/eating.d.ts +9 -0
  99. package/actions/standard/eating/eating.d.ts.map +1 -1
  100. package/actions/standard/eating/eating.js +40 -2
  101. package/actions/standard/eating/eating.js.map +1 -1
  102. package/actions/standard/entering/entering.d.ts +14 -5
  103. package/actions/standard/entering/entering.d.ts.map +1 -1
  104. package/actions/standard/entering/entering.js +45 -67
  105. package/actions/standard/entering/entering.js.map +1 -1
  106. package/actions/standard/examining/examining.d.ts +6 -0
  107. package/actions/standard/examining/examining.d.ts.map +1 -1
  108. package/actions/standard/examining/examining.js +35 -48
  109. package/actions/standard/examining/examining.js.map +1 -1
  110. package/actions/standard/exiting/exiting.d.ts +6 -0
  111. package/actions/standard/exiting/exiting.d.ts.map +1 -1
  112. package/actions/standard/exiting/exiting.js +54 -3
  113. package/actions/standard/exiting/exiting.js.map +1 -1
  114. package/actions/standard/giving/giving.d.ts +21 -0
  115. package/actions/standard/giving/giving.d.ts.map +1 -1
  116. package/actions/standard/giving/giving.js +78 -2
  117. package/actions/standard/giving/giving.js.map +1 -1
  118. package/actions/standard/going/going.d.ts +10 -16
  119. package/actions/standard/going/going.d.ts.map +1 -1
  120. package/actions/standard/going/going.js +122 -132
  121. package/actions/standard/going/going.js.map +1 -1
  122. package/actions/standard/hiding/hiding.d.ts +10 -1
  123. package/actions/standard/hiding/hiding.d.ts.map +1 -1
  124. package/actions/standard/hiding/hiding.js +43 -4
  125. package/actions/standard/hiding/hiding.js.map +1 -1
  126. package/actions/standard/index.d.ts +5 -0
  127. package/actions/standard/index.d.ts.map +1 -1
  128. package/actions/standard/index.js +19 -4
  129. package/actions/standard/index.js.map +1 -1
  130. package/actions/standard/inserting/inserting.d.ts +12 -0
  131. package/actions/standard/inserting/inserting.d.ts.map +1 -1
  132. package/actions/standard/inserting/inserting.js +70 -5
  133. package/actions/standard/inserting/inserting.js.map +1 -1
  134. package/actions/standard/listening/listening.d.ts +12 -1
  135. package/actions/standard/listening/listening.d.ts.map +1 -1
  136. package/actions/standard/listening/listening.js +45 -4
  137. package/actions/standard/listening/listening.js.map +1 -1
  138. package/actions/standard/locking/locking.d.ts +9 -0
  139. package/actions/standard/locking/locking.d.ts.map +1 -1
  140. package/actions/standard/locking/locking.js +62 -3
  141. package/actions/standard/locking/locking.js.map +1 -1
  142. package/actions/standard/opening/opening-messages.d.ts +3 -0
  143. package/actions/standard/opening/opening-messages.d.ts.map +1 -1
  144. package/actions/standard/opening/opening-messages.js +4 -0
  145. package/actions/standard/opening/opening-messages.js.map +1 -1
  146. package/actions/standard/opening/opening.d.ts +8 -0
  147. package/actions/standard/opening/opening.d.ts.map +1 -1
  148. package/actions/standard/opening/opening.js +73 -59
  149. package/actions/standard/opening/opening.js.map +1 -1
  150. package/actions/standard/pulling/pulling.d.ts +9 -0
  151. package/actions/standard/pulling/pulling.d.ts.map +1 -1
  152. package/actions/standard/pulling/pulling.js +40 -2
  153. package/actions/standard/pulling/pulling.js.map +1 -1
  154. package/actions/standard/pushing/pushing-types.d.ts +3 -6
  155. package/actions/standard/pushing/pushing-types.d.ts.map +1 -1
  156. package/actions/standard/pushing/pushing-types.js +3 -1
  157. package/actions/standard/pushing/pushing-types.js.map +1 -1
  158. package/actions/standard/pushing/pushing.d.ts +14 -5
  159. package/actions/standard/pushing/pushing.d.ts.map +1 -1
  160. package/actions/standard/pushing/pushing.js +51 -71
  161. package/actions/standard/pushing/pushing.js.map +1 -1
  162. package/actions/standard/putting/putting-types.d.ts +10 -21
  163. package/actions/standard/putting/putting-types.d.ts.map +1 -1
  164. package/actions/standard/putting/putting-types.js +0 -1
  165. package/actions/standard/putting/putting-types.js.map +1 -1
  166. package/actions/standard/putting/putting.d.ts +10 -0
  167. package/actions/standard/putting/putting.d.ts.map +1 -1
  168. package/actions/standard/putting/putting.js +133 -151
  169. package/actions/standard/putting/putting.js.map +1 -1
  170. package/actions/standard/reading/reading.d.ts +6 -0
  171. package/actions/standard/reading/reading.d.ts.map +1 -1
  172. package/actions/standard/reading/reading.js +36 -52
  173. package/actions/standard/reading/reading.js.map +1 -1
  174. package/actions/standard/removing/removing-types.d.ts +10 -16
  175. package/actions/standard/removing/removing-types.d.ts.map +1 -1
  176. package/actions/standard/removing/removing-types.js.map +1 -1
  177. package/actions/standard/removing/removing.d.ts +13 -0
  178. package/actions/standard/removing/removing.d.ts.map +1 -1
  179. package/actions/standard/removing/removing.js +147 -88
  180. package/actions/standard/removing/removing.js.map +1 -1
  181. package/actions/standard/searching/searching.d.ts +10 -0
  182. package/actions/standard/searching/searching.d.ts.map +1 -1
  183. package/actions/standard/searching/searching.js +44 -8
  184. package/actions/standard/searching/searching.js.map +1 -1
  185. package/actions/standard/showing/showing.d.ts +14 -0
  186. package/actions/standard/showing/showing.d.ts.map +1 -1
  187. package/actions/standard/showing/showing.js +62 -2
  188. package/actions/standard/showing/showing.js.map +1 -1
  189. package/actions/standard/smelling/smelling.d.ts +10 -0
  190. package/actions/standard/smelling/smelling.d.ts.map +1 -1
  191. package/actions/standard/smelling/smelling.js +41 -2
  192. package/actions/standard/smelling/smelling.js.map +1 -1
  193. package/actions/standard/switching_off/switching_off.d.ts +11 -1
  194. package/actions/standard/switching_off/switching_off.d.ts.map +1 -1
  195. package/actions/standard/switching_off/switching_off.js +44 -4
  196. package/actions/standard/switching_off/switching_off.js.map +1 -1
  197. package/actions/standard/switching_on/switching_on.d.ts +14 -5
  198. package/actions/standard/switching_on/switching_on.d.ts.map +1 -1
  199. package/actions/standard/switching_on/switching_on.js +45 -57
  200. package/actions/standard/switching_on/switching_on.js.map +1 -1
  201. package/actions/standard/taking/taking-types.d.ts +14 -36
  202. package/actions/standard/taking/taking-types.d.ts.map +1 -1
  203. package/actions/standard/taking/taking-types.js.map +1 -1
  204. package/actions/standard/taking/taking.d.ts +11 -0
  205. package/actions/standard/taking/taking.d.ts.map +1 -1
  206. package/actions/standard/taking/taking.js +102 -148
  207. package/actions/standard/taking/taking.js.map +1 -1
  208. package/actions/standard/taking_off/taking-off.d.ts +6 -0
  209. package/actions/standard/taking_off/taking-off.d.ts.map +1 -1
  210. package/actions/standard/taking_off/taking-off.js +57 -21
  211. package/actions/standard/taking_off/taking-off.js.map +1 -1
  212. package/actions/standard/talking/talking.d.ts +15 -0
  213. package/actions/standard/talking/talking.d.ts.map +1 -1
  214. package/actions/standard/talking/talking.js +52 -3
  215. package/actions/standard/talking/talking.js.map +1 -1
  216. package/actions/standard/telling/index.d.ts +5 -0
  217. package/actions/standard/telling/index.d.ts.map +1 -0
  218. package/actions/standard/telling/index.js +10 -0
  219. package/actions/standard/telling/index.js.map +1 -0
  220. package/actions/standard/telling/telling.d.ts +25 -0
  221. package/actions/standard/telling/telling.d.ts.map +1 -0
  222. package/actions/standard/telling/telling.js +114 -0
  223. package/actions/standard/telling/telling.js.map +1 -0
  224. package/actions/standard/throwing/throwing.d.ts +11 -0
  225. package/actions/standard/throwing/throwing.d.ts.map +1 -1
  226. package/actions/standard/throwing/throwing.js +69 -70
  227. package/actions/standard/throwing/throwing.js.map +1 -1
  228. package/actions/standard/tool-shared.d.ts +38 -0
  229. package/actions/standard/tool-shared.d.ts.map +1 -0
  230. package/actions/standard/tool-shared.js +74 -0
  231. package/actions/standard/tool-shared.js.map +1 -0
  232. package/actions/standard/touching/touching.d.ts +9 -0
  233. package/actions/standard/touching/touching.d.ts.map +1 -1
  234. package/actions/standard/touching/touching.js +40 -4
  235. package/actions/standard/touching/touching.js.map +1 -1
  236. package/actions/standard/turning/index.d.ts +5 -0
  237. package/actions/standard/turning/index.d.ts.map +1 -0
  238. package/actions/standard/turning/index.js +9 -0
  239. package/actions/standard/turning/index.js.map +1 -0
  240. package/actions/standard/turning/turning.d.ts +17 -0
  241. package/actions/standard/turning/turning.d.ts.map +1 -0
  242. package/actions/standard/turning/turning.js +25 -0
  243. package/actions/standard/turning/turning.js.map +1 -0
  244. package/actions/standard/unlocking/unlocking.d.ts +9 -0
  245. package/actions/standard/unlocking/unlocking.d.ts.map +1 -1
  246. package/actions/standard/unlocking/unlocking.js +62 -3
  247. package/actions/standard/unlocking/unlocking.js.map +1 -1
  248. package/actions/standard/wearing/wearing.d.ts +11 -1
  249. package/actions/standard/wearing/wearing.d.ts.map +1 -1
  250. package/actions/standard/wearing/wearing.js +57 -12
  251. package/actions/standard/wearing/wearing.js.map +1 -1
  252. package/channels/standard.d.ts +13 -10
  253. package/channels/standard.d.ts.map +1 -1
  254. package/channels/standard.js +14 -10
  255. package/channels/standard.js.map +1 -1
  256. package/death/deadly-room-transformer.d.ts +37 -0
  257. package/death/deadly-room-transformer.d.ts.map +1 -0
  258. package/death/deadly-room-transformer.js +79 -0
  259. package/death/deadly-room-transformer.js.map +1 -0
  260. package/death/index.d.ts +18 -0
  261. package/death/index.d.ts.map +1 -0
  262. package/death/index.js +28 -0
  263. package/death/index.js.map +1 -0
  264. package/death/kill-player.d.ts +49 -0
  265. package/death/kill-player.d.ts.map +1 -0
  266. package/death/kill-player.js +55 -0
  267. package/death/kill-player.js.map +1 -0
  268. package/death/player-death-events.d.ts +40 -0
  269. package/death/player-death-events.d.ts.map +1 -0
  270. package/death/player-death-events.js +27 -0
  271. package/death/player-death-events.js.map +1 -0
  272. package/death/probabilistic-death.d.ts +23 -0
  273. package/death/probabilistic-death.d.ts.map +1 -0
  274. package/death/probabilistic-death.js +27 -0
  275. package/death/probabilistic-death.js.map +1 -0
  276. package/index.d.ts +1 -0
  277. package/index.d.ts.map +1 -1
  278. package/index.js +1 -0
  279. package/index.js.map +1 -1
  280. package/npc/behaviors.d.ts.map +1 -1
  281. package/npc/behaviors.js +9 -8
  282. package/npc/behaviors.js.map +1 -1
  283. package/npc/npc-service.d.ts +8 -0
  284. package/npc/npc-service.d.ts.map +1 -1
  285. package/npc/npc-service.js +19 -18
  286. package/npc/npc-service.js.map +1 -1
  287. package/package.json +7 -7
@@ -0,0 +1,247 @@
1
+ "use strict";
2
+ /**
3
+ * Interceptor lifecycle engine (ADR-228).
4
+ *
5
+ * The single implementation of the ADR-118 interceptor lifecycle. Actions
6
+ * declare their interceptor surface as an `ActionLifecycleDescriptor` and
7
+ * call the engine at their four phase boundaries; the engine owns the
8
+ * rulings exactly once:
9
+ *
10
+ * - D1 — veto-only guards: a validate hook acts only when it returns
11
+ * `{valid: false}`; any other result (including `{valid: true}`) falls
12
+ * through. No hook can skip standard validation or later consultations.
13
+ * (The explicit force-allow marker is a reserved, unimplemented
14
+ * extension — see ADR-228 D1.)
15
+ * - D2 — structured onBlocked: `{ override?, emit? }` applied against the
16
+ * standard blocked event, which always survives.
17
+ * - D3 — all command entities consulted in the descriptor's published
18
+ * slot order, each consultation with its own sharedData; first veto
19
+ * stops the validate chain; postExecute/postReport run for every
20
+ * consultation once the action proceeds.
21
+ * - Override arbitration: at most one consultation may return an
22
+ * `override` per report/blocked application — a second is a hard error,
23
+ * mirroring ADR-106's "multiple game.message reactions" rule.
24
+ *
25
+ * Multi-object commands (D4) run one lifecycle per item via
26
+ * `multi-object-lifecycle.ts`, built on the same primitives.
27
+ *
28
+ * Public interface: `resolveLifecycle`, `getLifecycleState`,
29
+ * `runPreValidate`, `runPostValidate`, `runPostExecute`, `runPostReport`,
30
+ * `runOnBlocked`, `LifecycleState`, `ResolvedConsultation`.
31
+ * Owner: stdlib standard-action infrastructure (ADR-228).
32
+ */
33
+ Object.defineProperty(exports, "__esModule", { value: true });
34
+ exports.resolveLifecycle = resolveLifecycle;
35
+ exports.getLifecycleState = getLifecycleState;
36
+ exports.runPreValidate = runPreValidate;
37
+ exports.runPostValidate = runPostValidate;
38
+ exports.runPostExecute = runPostExecute;
39
+ exports.runPostReport = runPostReport;
40
+ exports.runOnBlocked = runOnBlocked;
41
+ const world_model_1 = require("@sharpee/world-model");
42
+ /**
43
+ * Reserved sharedData key holding the command's resolved lifecycle state.
44
+ * Actions never read or write this key directly — they hold the state
45
+ * returned by `resolveLifecycle` or fetch it via `getLifecycleState`.
46
+ */
47
+ const LIFECYCLE_KEY = '_lifecycle';
48
+ /**
49
+ * Resolve an action's interceptor consultations for the current command.
50
+ *
51
+ * Iterates the descriptor's slots in published order (D3-B); for each
52
+ * slot that resolves to an entity, consults the world's interceptor
53
+ * registry under each of the slot's action ids (D6 order). Every match
54
+ * becomes a `ResolvedConsultation` with fresh sharedData (seeded via the
55
+ * slot's `seedData`, if any).
56
+ *
57
+ * Stores the state in `context.sharedData` (unless `slotOverride` is
58
+ * used) so later phases can fetch it with `getLifecycleState`.
59
+ *
60
+ * @param context - The action context.
61
+ * @param descriptor - The action's declared interceptor surface.
62
+ * @param options - See `ResolveLifecycleOptions`.
63
+ * @returns The resolved lifecycle state (possibly with zero consultations).
64
+ */
65
+ function resolveLifecycle(context, descriptor, options) {
66
+ const consultations = [];
67
+ for (const slot of descriptor.slots) {
68
+ const isOverrideSlot = options?.slotOverride?.slotId === slot.id;
69
+ const entity = isOverrideSlot
70
+ ? options.slotOverride.entity
71
+ : slot.resolve(context);
72
+ if (!entity)
73
+ continue;
74
+ for (const actionId of slot.actionIds) {
75
+ const lookup = context.world.getInterceptorForAction(entity, actionId);
76
+ if (!lookup)
77
+ continue;
78
+ // In a per-item resolution (D4), non-item slots' seedData receives
79
+ // the current item so shared entities (e.g. the container) can seed
80
+ // per-item context like the item id.
81
+ const multiObjectItem = !isOverrideSlot ? options?.slotOverride?.entity : undefined;
82
+ const data = slot.seedData
83
+ ? { ...slot.seedData(context, entity, multiObjectItem) }
84
+ : {};
85
+ consultations.push({
86
+ slotId: slot.id,
87
+ actionId,
88
+ entity,
89
+ interceptor: lookup.interceptor,
90
+ data
91
+ });
92
+ }
93
+ }
94
+ const state = { descriptor, consultations };
95
+ if (!options?.slotOverride) {
96
+ context.sharedData[LIFECYCLE_KEY] = state;
97
+ }
98
+ return state;
99
+ }
100
+ /**
101
+ * Fetch the lifecycle state stored by `resolveLifecycle` for this command.
102
+ *
103
+ * @param context - The action context.
104
+ * @returns The state, or `undefined` if `resolveLifecycle` has not run.
105
+ */
106
+ function getLifecycleState(context) {
107
+ return context.sharedData[LIFECYCLE_KEY];
108
+ }
109
+ /**
110
+ * D1 veto test: a hook result acts iff it is non-null AND `valid === false`.
111
+ * Everything else — null, `{valid: true}`, any truthy shape — falls through.
112
+ */
113
+ function vetoOf(result) {
114
+ if (result !== null && result.valid === false) {
115
+ return { valid: false, error: result.error, params: result.params };
116
+ }
117
+ return null;
118
+ }
119
+ /**
120
+ * Run every consultation's `preValidate` hook in order (D3-B).
121
+ *
122
+ * First veto wins: returns that veto as a `ValidationResult` and stops
123
+ * consulting. Returns `null` when no hook vetoes (the action continues
124
+ * with standard validation — D1: hooks cannot approve, only object).
125
+ *
126
+ * @param context - The action context.
127
+ * @param state - The resolved lifecycle state.
128
+ */
129
+ function runPreValidate(context, state) {
130
+ for (const c of state.consultations) {
131
+ if (!c.interceptor.preValidate)
132
+ continue;
133
+ const veto = vetoOf(c.interceptor.preValidate(c.entity, context.world, context.player.id, c.data));
134
+ if (veto)
135
+ return veto;
136
+ }
137
+ return null;
138
+ }
139
+ /**
140
+ * Run every consultation's `postValidate` hook in order (D3-B).
141
+ *
142
+ * Canonical placement (ADR-228): after ALL standard validation has
143
+ * passed. First veto wins; returns `null` when no hook vetoes.
144
+ *
145
+ * @param context - The action context.
146
+ * @param state - The resolved lifecycle state.
147
+ */
148
+ function runPostValidate(context, state) {
149
+ for (const c of state.consultations) {
150
+ if (!c.interceptor.postValidate)
151
+ continue;
152
+ const veto = vetoOf(c.interceptor.postValidate(c.entity, context.world, context.player.id, c.data));
153
+ if (veto)
154
+ return veto;
155
+ }
156
+ return null;
157
+ }
158
+ /**
159
+ * Run every consultation's `postExecute` hook in order (D3-B: all
160
+ * consultations survived validation once the action executed).
161
+ *
162
+ * Note the `postExecuteReplacesCore` contract (D7.3) governs whether the
163
+ * ACTION runs its own core logic — the engine always runs the hooks
164
+ * themselves normally.
165
+ *
166
+ * @param context - The action context.
167
+ * @param state - The resolved lifecycle state.
168
+ */
169
+ function runPostExecute(context, state) {
170
+ for (const c of state.consultations) {
171
+ c.interceptor.postExecute?.(c.entity, context.world, context.player.id, c.data);
172
+ }
173
+ }
174
+ /**
175
+ * Run every consultation's `postReport` hook and apply the results to the
176
+ * action's events.
177
+ *
178
+ * At most ONE consultation may return an `override` — a second is a hard
179
+ * error (throws), mirroring the `InterceptorReportResult` contract's
180
+ * ADR-106 rule. `emit` effects append in consultation order.
181
+ *
182
+ * @param context - The action context.
183
+ * @param state - The resolved lifecycle state.
184
+ * @param events - The action's events array; mutated in place.
185
+ * @param primaryEventType - The event type an `override` targets.
186
+ * @param searchFrom - Index in `events` where this report began — override
187
+ * targeting searches from here so per-item applications (D4) land on
188
+ * the item's own event, not an earlier item's.
189
+ */
190
+ function runPostReport(context, state, events, primaryEventType, searchFrom = 0) {
191
+ let overrideSeen = false;
192
+ for (const c of state.consultations) {
193
+ if (!c.interceptor.postReport)
194
+ continue;
195
+ const result = c.interceptor.postReport(c.entity, context.world, context.player.id, c.data);
196
+ if (!result)
197
+ continue;
198
+ if (result.override) {
199
+ if (overrideSeen) {
200
+ throw new Error(`Interceptor lifecycle (${state.descriptor.actionId}): multiple consultations ` +
201
+ `returned a postReport override — at most one interceptor may override the ` +
202
+ `primary message (slot '${c.slotId}', action '${c.actionId}').`);
203
+ }
204
+ overrideSeen = true;
205
+ }
206
+ (0, world_model_1.applyInterceptorReportResult)(events, primaryEventType, result, context, { searchFrom });
207
+ }
208
+ }
209
+ /**
210
+ * Run every consultation's `onBlocked` hook and apply the results to the
211
+ * action's blocked events (D2: the standard blocked event always
212
+ * survives; `override` swaps its message, `emit` appends).
213
+ *
214
+ * All resolved consultations are notified — including ones the validate
215
+ * chain never reached — matching the D3 author model ("a clause on any
216
+ * entity involved in the command fires"). At most one `override` (hard
217
+ * error otherwise).
218
+ *
219
+ * @param context - The action context.
220
+ * @param state - The resolved lifecycle state.
221
+ * @param events - The blocked events array (standard blocked event
222
+ * already pushed); mutated in place.
223
+ * @param blockedEventType - The standard blocked event's type.
224
+ * @param error - The validation error code the action was blocked with.
225
+ * @param searchFrom - Index in `events` where this item's blocked report
226
+ * began (D4 per-item targeting).
227
+ */
228
+ function runOnBlocked(context, state, events, blockedEventType, error, searchFrom = 0) {
229
+ let overrideSeen = false;
230
+ for (const c of state.consultations) {
231
+ if (!c.interceptor.onBlocked)
232
+ continue;
233
+ const result = c.interceptor.onBlocked(c.entity, context.world, context.player.id, error, c.data);
234
+ if (!result)
235
+ continue;
236
+ if (result.override) {
237
+ if (overrideSeen) {
238
+ throw new Error(`Interceptor lifecycle (${state.descriptor.actionId}): multiple consultations ` +
239
+ `returned an onBlocked override — at most one interceptor may override the ` +
240
+ `blocked message (slot '${c.slotId}', action '${c.actionId}').`);
241
+ }
242
+ overrideSeen = true;
243
+ }
244
+ (0, world_model_1.applyInterceptorBlockedResult)(events, blockedEventType, result, context, { searchFrom });
245
+ }
246
+ }
247
+ //# sourceMappingURL=lifecycle-engine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lifecycle-engine.js","sourceRoot":"","sources":["../../../../../../../../repos/sharpee_v2/packages/stdlib/src/actions/lifecycle/lifecycle-engine.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;;AA8EH,4CAwCC;AAQD,8CAEC;AAuBD,wCAYC;AAWD,0CAYC;AAaD,wCAIC;AAkBD,sCAwBC;AAqBD,oCAyBC;AAhSD,sDAK8B;AAK9B;;;;GAIG;AACH,MAAM,aAAa,GAAG,YAAY,CAAC;AA2CnC;;;;;;;;;;;;;;;;GAgBG;AACH,SAAgB,gBAAgB,CAC9B,OAAsB,EACtB,UAAqC,EACrC,OAAiC;IAEjC,MAAM,aAAa,GAA2B,EAAE,CAAC;IAEjD,KAAK,MAAM,IAAI,IAAI,UAAU,CAAC,KAAK,EAAE,CAAC;QACpC,MAAM,cAAc,GAAG,OAAO,EAAE,YAAY,EAAE,MAAM,KAAK,IAAI,CAAC,EAAE,CAAC;QACjE,MAAM,MAAM,GAAG,cAAc;YAC3B,CAAC,CAAC,OAAQ,CAAC,YAAa,CAAC,MAAM;YAC/B,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAC1B,IAAI,CAAC,MAAM;YAAE,SAAS;QAEtB,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACtC,MAAM,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,uBAAuB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;YACvE,IAAI,CAAC,MAAM;gBAAE,SAAS;YAEtB,mEAAmE;YACnE,oEAAoE;YAC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EAAE,EAAE,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC;QAClG,IAAI,CAAC,MAAM;YAAE,SAAS;QACtB,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC;YACpB,IAAI,YAAY,EAAE,CAAC;gBACjB,MAAM,IAAI,KAAK,CACb,0BAA0B,KAAK,CAAC,UAAU,CAAC,QAAQ,4BAA4B;oBAC/E,4EAA4E;oBAC5E,0BAA0B,CAAC,CAAC,MAAM,cAAc,CAAC,CAAC,QAAQ,KAAK,CAChE,CAAC;YACJ,CAAC;YACD,YAAY,GAAG,IAAI,CAAC;QACtB,CAAC;QACD,IAAA,2CAA6B,EAAC,MAAM,EAAE,gBAAgB,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC;IAC3F,CAAC;AACH,CAAC"}
@@ -0,0 +1,105 @@
1
+ /**
2
+ * Multi-object interceptor lifecycle (ADR-228 D4).
3
+ *
4
+ * Runs the FULL interceptor lifecycle per expanded item of a multi-object
5
+ * command ("take all", "put all in case"): resolve → preValidate →
6
+ * standard per-item validation → postValidate per item; postExecute /
7
+ * postReport per successful item; onBlocked per failed item. Actions
8
+ * supply only their standard per-item logic as callbacks — the hook
9
+ * plumbing lives here exactly once, so the bypass class the ADR-118 audit
10
+ * found (putting/dropping multi paths skipping all five hooks; taking
11
+ * skipping onBlocked) cannot silently recur.
12
+ *
13
+ * Aggregated output is preserved: the action's report callbacks push
14
+ * their own events; the engine applies each item's hook results against
15
+ * that item's own events via `searchFrom` targeting.
16
+ *
17
+ * Public interface: `runMultiObjectValidate`, `runMultiObjectExecute`,
18
+ * `runMultiObjectReport`, `getMultiObjectLifecycle`,
19
+ * `MultiObjectItemState`.
20
+ * Owner: stdlib standard-action infrastructure (ADR-228).
21
+ */
22
+ import { ISemanticEvent } from '@sharpee/core';
23
+ import { IFEntity } from '@sharpee/world-model';
24
+ import { ActionContext, ValidationResult } from '../enhanced-types';
25
+ import { ActionLifecycleDescriptor } from './descriptor';
26
+ import { LifecycleState } from './lifecycle-engine';
27
+ /**
28
+ * One item's lifecycle through a multi-object command.
29
+ *
30
+ * `itemData` is the action's per-item scratch space (previous location,
31
+ * implicit-removal flags, ...) — the analogue of single-object
32
+ * sharedData, isolated per item.
33
+ */
34
+ export interface MultiObjectItemState {
35
+ entity: IFEntity;
36
+ /** True when the item passed hooks + standard validation. */
37
+ success: boolean;
38
+ /** Validation error code when `success` is false. */
39
+ error?: string;
40
+ /** Error params when `success` is false. */
41
+ errorParams?: Record<string, unknown>;
42
+ /** The item's resolved interceptor consultations (own sharedData each). */
43
+ state: LifecycleState;
44
+ /** Action-owned per-item scratch data. */
45
+ itemData: Record<string, unknown>;
46
+ }
47
+ /**
48
+ * Validate every expanded item through its full lifecycle (D4).
49
+ *
50
+ * Per item, in order: resolve consultations (the descriptor's
51
+ * `multiObjectSlotId`-designated slot binds to the item) → preValidate
52
+ * hooks (veto fails the item) → `validateItem` (standard validation) →
53
+ * postValidate hooks (veto fails the item). A failed item never blocks
54
+ * the others — per-item success/failure is recorded for the execute and
55
+ * report phases.
56
+ *
57
+ * Stores the resulting array in `context.sharedData` and returns it.
58
+ *
59
+ * @param context - The action context.
60
+ * @param descriptor - The action's declared interceptor surface. Its slot
61
+ * with id `multiObjectSlotId` is bound to each item in turn.
62
+ * @param multiObjectSlotId - Id of the slot that carries each expanded
63
+ * item (usually the direct-object slot).
64
+ * @param items - The expanded entities of the multi-object command.
65
+ * @param validateItem - The action's standard single-item validation.
66
+ * @returns Per-item lifecycle states, in `items` order.
67
+ */
68
+ export declare function runMultiObjectValidate(context: ActionContext, descriptor: ActionLifecycleDescriptor, multiObjectSlotId: string, items: IFEntity[], validateItem: (context: ActionContext, item: IFEntity, itemData: Record<string, unknown>) => ValidationResult): MultiObjectItemState[];
69
+ /**
70
+ * Fetch the per-item states stored by `runMultiObjectValidate`.
71
+ *
72
+ * @param context - The action context.
73
+ * @returns The item states, or `undefined` if the command was not
74
+ * validated as a multi-object command.
75
+ */
76
+ export declare function getMultiObjectLifecycle(context: ActionContext): MultiObjectItemState[] | undefined;
77
+ /**
78
+ * Execute every successful item: the action's `executeItem`, then that
79
+ * item's postExecute hooks (D4 — hooks fire per item, so e.g. a trophy
80
+ * case's postExecute awards score for EVERY deposited treasure).
81
+ *
82
+ * @param context - The action context.
83
+ * @param itemStates - The states from `runMultiObjectValidate`.
84
+ * @param executeItem - The action's standard single-item mutation.
85
+ */
86
+ export declare function runMultiObjectExecute(context: ActionContext, itemStates: MultiObjectItemState[], executeItem: (context: ActionContext, item: IFEntity, itemData: Record<string, unknown>) => void): void;
87
+ /**
88
+ * Report every item: successes via `reportSuccess` + postReport hooks,
89
+ * failures via `reportBlocked` + onBlocked hooks (D4 closes the audit's
90
+ * take-all-loses-onBlocked gap).
91
+ *
92
+ * Each item's hook results are applied with `searchFrom` set to the index
93
+ * where that item's events began, so overrides land on the item's own
94
+ * event even though all items share one events array (aggregated output).
95
+ *
96
+ * @param context - The action context.
97
+ * @param itemStates - The states from `runMultiObjectValidate`.
98
+ * @param events - The action's events array; mutated in place.
99
+ * @param primaryEventType - Event type a success `override` targets.
100
+ * @param blockedEventType - Event type a blocked `override` targets.
101
+ * @param reportSuccess - Pushes the item's standard success event(s).
102
+ * @param reportBlocked - Pushes the item's standard blocked event.
103
+ */
104
+ export declare function runMultiObjectReport(context: ActionContext, itemStates: MultiObjectItemState[], events: ISemanticEvent[], primaryEventType: string, blockedEventType: string, reportSuccess: (context: ActionContext, item: IFEntity, itemData: Record<string, unknown>, events: ISemanticEvent[]) => void, reportBlocked: (context: ActionContext, item: IFEntity, error: string, errorParams: Record<string, unknown> | undefined, events: ISemanticEvent[]) => void): void;
105
+ //# sourceMappingURL=multi-object-lifecycle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"multi-object-lifecycle.d.ts","sourceRoot":"","sources":["../../../../../../../../repos/sharpee_v2/packages/stdlib/src/actions/lifecycle/multi-object-lifecycle.ts"],"names":[],"mappings":"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CAAC,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,GAC/F,IAAI,CAMN;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,aAAa,EACtB,UAAU,EAAE,oBAAoB,EAAE,EAClC,MAAM,EAAE,cAAc,EAAE,EACxB,gBAAgB,EAAE,MAAM,EACxB,gBAAgB,EAAE,MAAM,EACxB,aAAa,EAAE,CAAC,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,cAAc,EAAE,KAAK,IAAI,EAC5H,aAAa,EAAE,CAAC,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,EAAE,MAAM,EAAE,cAAc,EAAE,KAAK,IAAI,GACzJ,IAAI,CAWN"}
@@ -0,0 +1,136 @@
1
+ "use strict";
2
+ /**
3
+ * Multi-object interceptor lifecycle (ADR-228 D4).
4
+ *
5
+ * Runs the FULL interceptor lifecycle per expanded item of a multi-object
6
+ * command ("take all", "put all in case"): resolve → preValidate →
7
+ * standard per-item validation → postValidate per item; postExecute /
8
+ * postReport per successful item; onBlocked per failed item. Actions
9
+ * supply only their standard per-item logic as callbacks — the hook
10
+ * plumbing lives here exactly once, so the bypass class the ADR-118 audit
11
+ * found (putting/dropping multi paths skipping all five hooks; taking
12
+ * skipping onBlocked) cannot silently recur.
13
+ *
14
+ * Aggregated output is preserved: the action's report callbacks push
15
+ * their own events; the engine applies each item's hook results against
16
+ * that item's own events via `searchFrom` targeting.
17
+ *
18
+ * Public interface: `runMultiObjectValidate`, `runMultiObjectExecute`,
19
+ * `runMultiObjectReport`, `getMultiObjectLifecycle`,
20
+ * `MultiObjectItemState`.
21
+ * Owner: stdlib standard-action infrastructure (ADR-228).
22
+ */
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.runMultiObjectValidate = runMultiObjectValidate;
25
+ exports.getMultiObjectLifecycle = getMultiObjectLifecycle;
26
+ exports.runMultiObjectExecute = runMultiObjectExecute;
27
+ exports.runMultiObjectReport = runMultiObjectReport;
28
+ const lifecycle_engine_1 = require("./lifecycle-engine");
29
+ /**
30
+ * Reserved sharedData key holding the command's per-item lifecycle states.
31
+ * Actions never touch this key directly — they hold the array returned by
32
+ * `runMultiObjectValidate` or fetch it via `getMultiObjectLifecycle`.
33
+ */
34
+ const MULTI_LIFECYCLE_KEY = '_lifecycleMulti';
35
+ /**
36
+ * Validate every expanded item through its full lifecycle (D4).
37
+ *
38
+ * Per item, in order: resolve consultations (the descriptor's
39
+ * `multiObjectSlotId`-designated slot binds to the item) → preValidate
40
+ * hooks (veto fails the item) → `validateItem` (standard validation) →
41
+ * postValidate hooks (veto fails the item). A failed item never blocks
42
+ * the others — per-item success/failure is recorded for the execute and
43
+ * report phases.
44
+ *
45
+ * Stores the resulting array in `context.sharedData` and returns it.
46
+ *
47
+ * @param context - The action context.
48
+ * @param descriptor - The action's declared interceptor surface. Its slot
49
+ * with id `multiObjectSlotId` is bound to each item in turn.
50
+ * @param multiObjectSlotId - Id of the slot that carries each expanded
51
+ * item (usually the direct-object slot).
52
+ * @param items - The expanded entities of the multi-object command.
53
+ * @param validateItem - The action's standard single-item validation.
54
+ * @returns Per-item lifecycle states, in `items` order.
55
+ */
56
+ function runMultiObjectValidate(context, descriptor, multiObjectSlotId, items, validateItem) {
57
+ const results = items.map((item) => {
58
+ const state = (0, lifecycle_engine_1.resolveLifecycle)(context, descriptor, {
59
+ slotOverride: { slotId: multiObjectSlotId, entity: item }
60
+ });
61
+ const itemData = {};
62
+ const preVeto = (0, lifecycle_engine_1.runPreValidate)(context, state);
63
+ if (preVeto) {
64
+ return { entity: item, success: false, error: preVeto.error, errorParams: preVeto.params, state, itemData };
65
+ }
66
+ const standard = validateItem(context, item, itemData);
67
+ if (!standard.valid) {
68
+ return { entity: item, success: false, error: standard.error, errorParams: standard.params, state, itemData };
69
+ }
70
+ const postVeto = (0, lifecycle_engine_1.runPostValidate)(context, state);
71
+ if (postVeto) {
72
+ return { entity: item, success: false, error: postVeto.error, errorParams: postVeto.params, state, itemData };
73
+ }
74
+ return { entity: item, success: true, state, itemData };
75
+ });
76
+ context.sharedData[MULTI_LIFECYCLE_KEY] = results;
77
+ return results;
78
+ }
79
+ /**
80
+ * Fetch the per-item states stored by `runMultiObjectValidate`.
81
+ *
82
+ * @param context - The action context.
83
+ * @returns The item states, or `undefined` if the command was not
84
+ * validated as a multi-object command.
85
+ */
86
+ function getMultiObjectLifecycle(context) {
87
+ return context.sharedData[MULTI_LIFECYCLE_KEY];
88
+ }
89
+ /**
90
+ * Execute every successful item: the action's `executeItem`, then that
91
+ * item's postExecute hooks (D4 — hooks fire per item, so e.g. a trophy
92
+ * case's postExecute awards score for EVERY deposited treasure).
93
+ *
94
+ * @param context - The action context.
95
+ * @param itemStates - The states from `runMultiObjectValidate`.
96
+ * @param executeItem - The action's standard single-item mutation.
97
+ */
98
+ function runMultiObjectExecute(context, itemStates, executeItem) {
99
+ for (const itemState of itemStates) {
100
+ if (!itemState.success)
101
+ continue;
102
+ executeItem(context, itemState.entity, itemState.itemData);
103
+ (0, lifecycle_engine_1.runPostExecute)(context, itemState.state);
104
+ }
105
+ }
106
+ /**
107
+ * Report every item: successes via `reportSuccess` + postReport hooks,
108
+ * failures via `reportBlocked` + onBlocked hooks (D4 closes the audit's
109
+ * take-all-loses-onBlocked gap).
110
+ *
111
+ * Each item's hook results are applied with `searchFrom` set to the index
112
+ * where that item's events began, so overrides land on the item's own
113
+ * event even though all items share one events array (aggregated output).
114
+ *
115
+ * @param context - The action context.
116
+ * @param itemStates - The states from `runMultiObjectValidate`.
117
+ * @param events - The action's events array; mutated in place.
118
+ * @param primaryEventType - Event type a success `override` targets.
119
+ * @param blockedEventType - Event type a blocked `override` targets.
120
+ * @param reportSuccess - Pushes the item's standard success event(s).
121
+ * @param reportBlocked - Pushes the item's standard blocked event.
122
+ */
123
+ function runMultiObjectReport(context, itemStates, events, primaryEventType, blockedEventType, reportSuccess, reportBlocked) {
124
+ for (const itemState of itemStates) {
125
+ const searchFrom = events.length;
126
+ if (itemState.success) {
127
+ reportSuccess(context, itemState.entity, itemState.itemData, events);
128
+ (0, lifecycle_engine_1.runPostReport)(context, itemState.state, events, primaryEventType, searchFrom);
129
+ }
130
+ else {
131
+ reportBlocked(context, itemState.entity, itemState.error ?? '', itemState.errorParams, events);
132
+ (0, lifecycle_engine_1.runOnBlocked)(context, itemState.state, events, blockedEventType, itemState.error ?? '', searchFrom);
133
+ }
134
+ }
135
+ }
136
+ //# sourceMappingURL=multi-object-lifecycle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"multi-object-lifecycle.js","sourceRoot":"","sources":["../../../../../../../../repos/sharpee_v2/packages/stdlib/src/actions/lifecycle/multi-object-lifecycle.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;AAiEH,wDAiCC;AASD,0DAEC;AAWD,sDAUC;AAmBD,oDAmBC;AAlKD,yDAQ4B;AAE5B;;;;GAIG;AACH,MAAM,mBAAmB,GAAG,iBAAiB,CAAC;AAuB9C;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,SAAgB,sBAAsB,CACpC,OAAsB,EACtB,UAAqC,EACrC,iBAAyB,EACzB,KAAiB,EACjB,YAA6G;IAE7G,MAAM,OAAO,GAA2B,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QACzD,MAAM,KAAK,GAAG,IAAA,mCAAgB,EAAC,OAAO,EAAE,UAAU,EAAE;YAClD,YAAY,EAAE,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,EAAE,IAAI,EAAE;SAC1D,CA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0 +1,39 @@
1
+ /**
2
+ * Wired-action registry (ADR-228 D5).
3
+ *
4
+ * The descriptor table: every standard action's `ActionLifecycleDescriptor`,
5
+ * collected in one place, plus the set of interceptor-consulting action ids
6
+ * derived mechanically from it. The table IS the source of truth — an action
7
+ * is "wired" iff its descriptor appears here, and the id set is never
8
+ * hand-maintained. Consumers (the Chord story-loader's load-time fail-fast,
9
+ * tooling, tests) read the derived set to decide whether an interceptor
10
+ * registered under a given action id will ever be consulted.
11
+ *
12
+ * Public interface: `actionLifecycleDescriptors`,
13
+ * `interceptorConsultingActionIds`.
14
+ * Owner: stdlib standard-action infrastructure (ADR-228).
15
+ *
16
+ * NOTE: this module is deliberately NOT exported from `./index.ts` (the
17
+ * lifecycle barrel) — actions import that barrel, and this module imports
18
+ * the actions, so routing it through the barrel would create an import
19
+ * cycle. It is exported from the actions barrel (`../index.ts`) instead.
20
+ */
21
+ import { ActionLifecycleDescriptor } from './descriptor';
22
+ /**
23
+ * The descriptor table: all 37 entity-keyed standard actions (33 per
24
+ * ADR-228 Consequences + cutting per ADR-230 D3c + digging + asking/telling per
25
+ * ADR-230 Phase 6). Structural exemptions
26
+ * (no entity to key on: about, waiting, looking, … and the full-delegation
27
+ * capability actions lowering/raising) are absent by design — see ADR-228
28
+ * Context.
29
+ */
30
+ export declare const actionLifecycleDescriptors: readonly ActionLifecycleDescriptor[];
31
+ /**
32
+ * Every action id under which some wired action consults interceptors —
33
+ * the union of all descriptors' slot actionIds (mechanically derived; the
34
+ * both-ids delegation seams of ADR-228 D6 and implicit-entity ids like
35
+ * `if.action.entering_room` fall out of the slots, not a hand-kept list).
36
+ * An interceptor registered under an id NOT in this set will never fire.
37
+ */
38
+ export declare const interceptorConsultingActionIds: ReadonlySet<string>;
39
+ //# sourceMappingURL=registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../../../../../../../repos/sharpee_v2/packages/stdlib/src/actions/lifecycle/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAC;AAwCzD;;;;;;;GAOG;AACH,eAAO,MAAM,0BAA0B,EAAE,SAAS,yBAAyB,EAsCzE,CAAC;AAiBH;;;;;;GAMG;AACH,eAAO,MAAM,8BAA8B,EAAE,WAAW,CAAC,MAAM,CAI9D,CAAC"}