soma-core 1.4.2 → 1.5.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 (212) hide show
  1. package/bin/component.cjs +240 -0
  2. package/bin/eject.cjs +174 -0
  3. package/bin/migrate.cjs +362 -0
  4. package/core/build/blocks/block-compile.ts +143 -17
  5. package/core/build/blocks/migrate-flat.ts +118 -25
  6. package/core/build/compiler/page-declaration-compiler.ts +149 -5
  7. package/core/build/compiler/route-builder.ts +0 -4
  8. package/core/build/compiler/soma-precompile.js +431 -26
  9. package/core/build/component/component-graph.ts +28 -105
  10. package/core/build/component/package-loader.ts +18 -4
  11. package/core/build/eject/component-eject.ts +8 -2
  12. package/core/build/layout/constraint-solver.ts +131 -16
  13. package/core/build/layout/css-emitter.ts +15 -9
  14. package/core/build/ooui/artifact/artifact.types.ts +275 -0
  15. package/core/build/ooui/artifact/emit-artifact.ts +269 -0
  16. package/core/build/ooui/artifact/emit-html.ts +204 -0
  17. package/core/build/ooui/artifact/index.ts +53 -0
  18. package/core/build/ooui/artifact/spatial-tree.ts +268 -0
  19. package/core/build/ooui/artifact/utility-class.ts +83 -0
  20. package/core/build/ooui/composition/candidate.types.ts +323 -0
  21. package/core/build/ooui/composition/control-model.ts +114 -0
  22. package/core/build/ooui/composition/registry.ts +520 -0
  23. package/core/build/ooui/composition/select.ts +232 -0
  24. package/core/build/ooui/diagnostics/codes.ts +230 -0
  25. package/core/build/ooui/diagnostics/error.ts +235 -0
  26. package/core/build/ooui/diagnostics/format.ts +106 -0
  27. package/core/build/ooui/diagnostics/index.ts +62 -0
  28. package/core/build/ooui/diagnostics/issue.types.ts +112 -0
  29. package/core/build/ooui/engine-slot.ts +184 -0
  30. package/core/build/ooui/index.ts +1427 -0
  31. package/core/build/ooui/intent/derive-intent.ts +450 -0
  32. package/core/build/ooui/intent/field-rules.ts +330 -0
  33. package/core/build/ooui/intent/intent.types.ts +476 -0
  34. package/core/build/ooui/intent/verb-events.ts +285 -0
  35. package/core/build/ooui/page/budget.ts +503 -0
  36. package/core/build/ooui/page/compose-page.ts +736 -0
  37. package/core/build/ooui/page/index.ts +66 -0
  38. package/core/build/ooui/page/page.types.ts +402 -0
  39. package/core/build/ooui/page/region-row.ts +241 -0
  40. package/core/build/ooui/semantic/expand-page-surface.ts +180 -0
  41. package/core/build/ooui/semantic/kernel.types.ts +187 -0
  42. package/core/build/ooui/semantic/normalize.ts +784 -0
  43. package/core/build/ooui/semantic/origin.types.ts +211 -0
  44. package/core/build/ooui/semantic/role-alias.ts +154 -0
  45. package/core/build/ooui/semantic/shorthand.ts +233 -0
  46. package/core/build/ooui/semantic/surface.types.ts +78 -0
  47. package/core/build/ooui/semantic/validate-request.ts +267 -0
  48. package/core/build/ooui/spatial/emit-utility.ts +480 -0
  49. package/core/build/ooui/spatial/ir.types.ts +443 -0
  50. package/core/build/ooui/spatial/registry.ts +565 -0
  51. package/core/build/ooui/spatial/solve.ts +769 -0
  52. package/core/build/ooui/spatial/utility.types.ts +242 -0
  53. package/core/build/ooui/trace/index.ts +40 -0
  54. package/core/build/ooui/trace/render.ts +190 -0
  55. package/core/build/ooui/trace/source.types.ts +69 -0
  56. package/core/build/ooui/trace/trace.types.ts +326 -0
  57. package/core/client/component/example-blocks.ts +1 -7
  58. package/core/client/component/theme-component-tokens.ts +12 -15
  59. package/core/client/data/data-object-resolver.ts +27 -8
  60. package/core/client/diagnostics/telemetry-context.ts +0 -4
  61. package/core/client/engine/asset-resolver.ts +0 -1
  62. package/core/client/engine/event-engine.ts +7 -3
  63. package/core/client/engine/soma-bootstrap.ts +292 -34
  64. package/core/client/engine/style-binder.ts +0 -1
  65. package/core/client/infra/http/IHttpClient.ts +0 -6
  66. package/core/client/infra/http/SomaHttpService.ts +4 -1
  67. package/core/client/infra/notify/DomNotifyService.ts +1 -1
  68. package/core/client/infra/router/router-path.ts +0 -6
  69. package/core/client/parser/annotation-extractor.ts +1 -1
  70. package/core/client/parser/blocks/namespace.ts +30 -5
  71. package/core/client/parser/blocks/page-parser.ts +44 -1
  72. package/core/client/parser/blocks/use-parser.ts +266 -46
  73. package/core/client/parser/data-config-parser.ts +71 -3
  74. package/core/client/parser/layout-parser.ts +4 -3
  75. package/core/client/parser/reaction-parser.ts +0 -1
  76. package/core/client/parser/ui-config-parser.ts +212 -74
  77. package/core/client/theme/scene-tokens.ts +9 -3
  78. package/core/client/theme/theme-axes.ts +74 -16
  79. package/core/client/theme/theme-engine.ts +280 -69
  80. package/core/client/theme/tone-solver.ts +9 -8
  81. package/core/index.ts +18 -4
  82. package/core/server/api/load-host-service.ts +8 -2
  83. package/core/server/declaration-safety.ts +11 -0
  84. package/core/server/host/page-response-request.ts +0 -2
  85. package/core/server/host/published-page-artifact-cache.ts +244 -0
  86. package/core/server/host/published-page-assets.ts +44 -5
  87. package/core/server/mock/node/cli.mjs +0 -1
  88. package/core/server/mock/node/schema-generator.mjs +0 -1
  89. package/core/server/ooui.ts +34 -0
  90. package/core/server/page-assets.ts +8 -0
  91. package/core/server/page-declaration.ts +18 -0
  92. package/core/server/registry/asset-store.ts +327 -0
  93. package/core/server/registry/declaration-precompiler.ts +49 -6
  94. package/core/server/registry/index.ts +47 -1
  95. package/core/server/registry/page-registry-repository.ts +6 -2
  96. package/core/server/registry/page-registry-store.ts +133 -19
  97. package/core/server/registry/publish-asset-pin.ts +557 -0
  98. package/core/server/registry/services/pages/List.ts +15 -3
  99. package/core/server/registry/validation/compile-gate.ts +180 -8
  100. package/core/server/registry/validation/declaration-safety-scan.ts +113 -23
  101. package/core/shared/component/derive-sample.ts +201 -16
  102. package/core/shared/component/field-lines.ts +98 -8
  103. package/core/shared/container-breakpoints.ts +46 -0
  104. package/core/shared/object-semantics.ts +240 -0
  105. package/core/shared/ooui-declaration.ts +235 -0
  106. package/core/shared/types/component-contract.types.ts +7 -6
  107. package/core/shared/types/data-config.types.ts +95 -0
  108. package/core/shared/types/domain.types.ts +0 -24
  109. package/core/shared/types/engine.types.ts +0 -5
  110. package/core/shared/types/layout-constraint.types.ts +16 -0
  111. package/core/shared/types/ui-config.types.ts +163 -13
  112. package/dist/cli/soma.js +24 -11
  113. package/dist/core/index.cjs +1563 -800
  114. package/dist/types/build/blocks/block-compile.d.ts +16 -1
  115. package/dist/types/build/blocks/migrate-flat.d.ts +17 -0
  116. package/dist/types/build/compiler/page-declaration-compiler.d.ts +46 -0
  117. package/dist/types/build/compiler/route-builder.d.ts +0 -1
  118. package/dist/types/build/component/component-graph.d.ts +17 -53
  119. package/dist/types/build/component/package-loader.d.ts +8 -1
  120. package/dist/types/build/layout/constraint-solver.d.ts +46 -4
  121. package/dist/types/build/ooui/artifact/artifact.types.d.ts +180 -0
  122. package/dist/types/build/ooui/artifact/emit-artifact.d.ts +58 -0
  123. package/dist/types/build/ooui/artifact/emit-html.d.ts +53 -0
  124. package/dist/types/build/ooui/artifact/index.d.ts +5 -0
  125. package/dist/types/build/ooui/artifact/spatial-tree.d.ts +48 -0
  126. package/dist/types/build/ooui/artifact/utility-class.d.ts +46 -0
  127. package/dist/types/build/ooui/composition/candidate.types.d.ts +206 -0
  128. package/dist/types/build/ooui/composition/control-model.d.ts +37 -0
  129. package/dist/types/build/ooui/composition/registry.d.ts +66 -0
  130. package/dist/types/build/ooui/composition/select.d.ts +63 -0
  131. package/dist/types/build/ooui/diagnostics/codes.d.ts +28 -0
  132. package/dist/types/build/ooui/diagnostics/error.d.ts +135 -0
  133. package/dist/types/build/ooui/diagnostics/format.d.ts +51 -0
  134. package/dist/types/build/ooui/diagnostics/index.d.ts +25 -0
  135. package/dist/types/build/ooui/diagnostics/issue.types.d.ts +56 -0
  136. package/dist/types/build/ooui/engine-slot.d.ts +41 -0
  137. package/dist/types/build/ooui/index.d.ts +286 -0
  138. package/dist/types/build/ooui/intent/derive-intent.d.ts +32 -0
  139. package/dist/types/build/ooui/intent/field-rules.d.ts +99 -0
  140. package/dist/types/build/ooui/intent/intent.types.d.ts +318 -0
  141. package/dist/types/build/ooui/intent/verb-events.d.ts +70 -0
  142. package/dist/types/build/ooui/page/budget.d.ts +28 -0
  143. package/dist/types/build/ooui/page/compose-page.d.ts +41 -0
  144. package/dist/types/build/ooui/page/index.d.ts +4 -0
  145. package/dist/types/build/ooui/page/page.types.d.ts +264 -0
  146. package/dist/types/build/ooui/page/region-row.d.ts +16 -0
  147. package/dist/types/build/ooui/semantic/expand-page-surface.d.ts +33 -0
  148. package/dist/types/build/ooui/semantic/kernel.types.d.ts +125 -0
  149. package/dist/types/build/ooui/semantic/normalize.d.ts +45 -0
  150. package/dist/types/build/ooui/semantic/origin.types.d.ts +95 -0
  151. package/dist/types/build/ooui/semantic/role-alias.d.ts +35 -0
  152. package/dist/types/build/ooui/semantic/shorthand.d.ts +60 -0
  153. package/dist/types/build/ooui/semantic/surface.types.d.ts +16 -0
  154. package/dist/types/build/ooui/semantic/validate-request.d.ts +19 -0
  155. package/dist/types/build/ooui/spatial/emit-utility.d.ts +43 -0
  156. package/dist/types/build/ooui/spatial/ir.types.d.ts +280 -0
  157. package/dist/types/build/ooui/spatial/registry.d.ts +110 -0
  158. package/dist/types/build/ooui/spatial/solve.d.ts +42 -0
  159. package/dist/types/build/ooui/spatial/utility.types.d.ts +191 -0
  160. package/dist/types/build/ooui/trace/index.d.ts +3 -0
  161. package/dist/types/build/ooui/trace/render.d.ts +42 -0
  162. package/dist/types/build/ooui/trace/source.types.d.ts +25 -0
  163. package/dist/types/build/ooui/trace/trace.types.d.ts +143 -0
  164. package/dist/types/client/component/example-blocks.d.ts +0 -2
  165. package/dist/types/client/component/theme-component-tokens.d.ts +8 -5
  166. package/dist/types/client/data/data-object-resolver.d.ts +10 -2
  167. package/dist/types/client/diagnostics/telemetry-context.d.ts +0 -1
  168. package/dist/types/client/engine/soma-bootstrap.d.ts +123 -10
  169. package/dist/types/client/infra/http/IHttpClient.d.ts +0 -5
  170. package/dist/types/client/infra/http/SomaHttpService.d.ts +1 -1
  171. package/dist/types/client/infra/router/router-path.d.ts +0 -2
  172. package/dist/types/client/parser/blocks/namespace.d.ts +20 -0
  173. package/dist/types/client/parser/blocks/page-parser.d.ts +9 -0
  174. package/dist/types/client/parser/blocks/use-parser.d.ts +38 -4
  175. package/dist/types/client/parser/data-config-parser.d.ts +13 -0
  176. package/dist/types/client/parser/ui-config-parser.d.ts +1 -11
  177. package/dist/types/client/theme/scene-tokens.d.ts +9 -3
  178. package/dist/types/client/theme/theme-axes.d.ts +64 -1
  179. package/dist/types/client/theme/theme-engine.d.ts +13 -8
  180. package/dist/types/client/theme/tone-solver.d.ts +9 -5
  181. package/dist/types/index.d.ts +4 -5
  182. package/dist/types/server/declaration-safety.d.ts +7 -0
  183. package/dist/types/server/host/page-response-request.d.ts +0 -1
  184. package/dist/types/server/host/published-page-artifact-cache.d.ts +64 -0
  185. package/dist/types/server/ooui.d.ts +18 -0
  186. package/dist/types/server/page-assets.d.ts +7 -0
  187. package/dist/types/server/page-declaration.d.ts +14 -0
  188. package/dist/types/server/registry/asset-store.d.ts +112 -0
  189. package/dist/types/server/registry/declaration-precompiler.d.ts +23 -3
  190. package/dist/types/server/registry/index.d.ts +3 -1
  191. package/dist/types/server/registry/page-registry-store.d.ts +57 -4
  192. package/dist/types/server/registry/publish-asset-pin.d.ts +166 -0
  193. package/dist/types/server/registry/services/pages/List.d.ts +9 -3
  194. package/dist/types/server/registry/validation/compile-gate.d.ts +63 -0
  195. package/dist/types/shared/component/derive-sample.d.ts +14 -0
  196. package/dist/types/shared/container-breakpoints.d.ts +42 -0
  197. package/dist/types/shared/object-semantics.d.ts +42 -0
  198. package/dist/types/shared/ooui-declaration.d.ts +135 -0
  199. package/dist/types/shared/types/component-contract.types.d.ts +7 -6
  200. package/dist/types/shared/types/data-config.types.d.ts +86 -0
  201. package/dist/types/shared/types/domain.types.d.ts +0 -21
  202. package/dist/types/shared/types/engine.types.d.ts +0 -4
  203. package/dist/types/shared/types/layout-constraint.types.d.ts +1 -0
  204. package/dist/types/shared/types/ui-config.types.d.ts +157 -12
  205. package/next.config.js +106 -13
  206. package/package.json +28 -2
  207. package/core/client/host-bridge/index.ts +0 -27
  208. package/core/client/parser/yaml-loader.ts +0 -36
  209. package/core/shared/manifest/manifest-contract.ts +0 -12
  210. package/dist/types/client/host-bridge/index.d.ts +0 -9
  211. package/dist/types/client/parser/yaml-loader.d.ts +0 -21
  212. package/dist/types/shared/manifest/manifest-contract.d.ts +0 -4
@@ -0,0 +1,184 @@
1
+ // OOUI 引擎槽位 · 进程级(REQ-014 §38.5 断线 ①)。
2
+ //
3
+ // ── 这个文件补的是哪一段断线 ───────────────────────────────────────
4
+ // `assembleOoui()` 在 `./index.ts` 里就位很久了,**而全仓没有一个生产调用者**。
5
+ // 于是 `ooui:` 段能写、能过解析、能过形状校验,走到编译那一步撞
6
+ // `OOUI-ASM-ENGINE-MISSING`——发布路径上一条 `ooui:` 页面都发不出去。
7
+ //
8
+ // 缺的不是引擎,是**引擎到编译点的那条路**。
9
+ //
10
+ // ── 为什么是进程级槽位,而不是把 `ooui` 参数一路传下去 ───────────────
11
+ // `compilePageDeclaration` 在生产上有八个调用点,分属五个进程:
12
+ //
13
+ // · `registry/validation/compile-gate.ts` Registry 发布干跑
14
+ // · `server/registry/declaration-precompiler.ts` Registry 预编译
15
+ // · `server/host/published-page-artifact-cache.ts` Next 服务端取页
16
+ // · `server/host/soma-page-compile.ts` Next 服务端
17
+ // · `build/compiler/full-manifest-builder.ts` 文件态页面全量预编译
18
+ // · `build/compiler/page-assets.ts` 预览器与测试替身
19
+ // · soma-ai 的 PageGenerator / PageDeclarationValidator / ReviseDriftGuard
20
+ // · soma-web 的发布服务
21
+ //
22
+ // 前六个**住在 soma-core 里面**,而引擎的词汇(候选表、空间令牌、契约视图)住在
23
+ // soma-ui,core 不许 import 它。所以这六个点没有任何办法自己拿到引擎:
24
+ // 参数式传递要求每一层调用方的 options 都开一个 `ooui` 口子,
25
+ // 一路穿过 Registry 的发布 API、Next 的取页路径、manifest 插件的子进程边界——
26
+ // 而**任何一层忘了透传都不报错**,表现是那条路上的 `ooui:` 页面发不出去,
27
+ // 另几条路好的,而"这条路没透传"与"这页没写 ooui" 在错误消息里长得一模一样。
28
+ //
29
+ // 槽位把这件事收成一个点:宿主注册一次,六个 core 内调用点从同一处读。
30
+ // 这与 `SomaPipeRegistry`(管道词汇)是同一形状,不是新发明。
31
+ //
32
+ // ── 为什么"注册"而不是"静态 import 一份默认词汇" ──────────────────
33
+ // 期 1.2 的形态决定说过:词汇必须**能在 Node 里静态 import**,不能只靠 bootstrap。
34
+ // 那条说的是 soma-ui 侧——`src/ooui/*.ts` 是纯数据模块,不碰 DOM,任何 Node 进程
35
+ // 都能 import。这条不冲突:静态可 import 是**前提**,注册是**接线**。
36
+ // core 侧不能有默认值,因为 core 不许 import soma-ui;宿主必须显式交一次。
37
+ //
38
+ // ── 冲突为什么默认拒收 ─────────────────────────────────────────────
39
+ // 照 `composeComponentPacks` / `createAdaptiveVocabulary` 的既有裁决:
40
+ // 同名注册两次抛错,**不做"后者覆盖前者"**。
41
+ // 静默覆盖在这里的具体坏法是:宿主 A 注册了含业务包契约的完整表,
42
+ // 某条测试辅助路径随后注册了 soma-ui 裸表,之后所有编译都对着裸表核 eventMap,
43
+ // 业务包覆盖过的组件的 emit 变成幽灵而闸门不响。
44
+ //
45
+ // 指纹相同则**幂等放行**(不抛)——同一份表被注册两次是模块加载序的正常结果,
46
+ // 不是配置错误,抛在这里只会逼每个宿主自己写 try/catch。
47
+
48
+ import { createHash } from 'node:crypto';
49
+
50
+ import { SomaOouiError } from './diagnostics';
51
+ import { assembleOoui, type SomaOouiEngine, type SomaOouiPack } from './index';
52
+
53
+ interface Slot {
54
+ readonly engine: SomaOouiEngine;
55
+ /** 装配时那批包的指纹,用于幂等放行与冲突判定 */
56
+ readonly fingerprint: string;
57
+ /** 包名清单,进冲突消息——报"谁和谁撞了"比报两串哈希有用 */
58
+ readonly packNames: readonly string[];
59
+ }
60
+
61
+ let slot: Slot | null = null;
62
+
63
+ /**
64
+ * 键序无关的规范化序列化。
65
+ *
66
+ * `JSON.stringify` 的键序跟对象插入序,而候选表与契约视图都是从
67
+ * `Object.keys` / `map` 出来的,插入序会随上游改动变化。
68
+ * 指纹若跟着变,同一份词表在两次注册之间就会"看起来不同"而误报冲突。
69
+ *
70
+ * **函数按源码文本入指纹。** 包里有真正决定产物的函数:原子类的 `emit`
71
+ * (类名 → CSS 声明)与容器变体的 `wrap`(规则 → `@container` 包裹)。
72
+ * 此前这里对函数走 `JSON.stringify(fn) ?? 'null'`,于是**只差一个 `emit` 的两个包
73
+ * 指纹相同**,第二次注册被幂等放行,整个进程按第一份的 emit 发 CSS——
74
+ * 正是文件头说的"不做后者覆盖前者"要防的那种静默,只是换成了"后者被静默丢弃"。
75
+ *
76
+ * 为什么是源码文本而不是函数身份(引用相等):同一份包由工厂在两个模块实例里各造一次
77
+ * 是正常的加载序,闭包是新的、源码是同一段——按身份判会把它误报成冲突,
78
+ * 逼每个宿主写 try/catch(见文件头"冲突为什么默认拒收"的最后一段)。
79
+ * 代价如实写在这里:两个函数**源码相同、只差闭包捕获的值**时仍判为同一份。
80
+ * 所以包里决定产物的取值要写在数据字段上(`root` / `namespace` / `minRem`…),
81
+ * 不要藏进闭包——soma-ui 的词表今天正是这么写的(emit 体里是字面量属性名)。
82
+ */
83
+ function canonical(value: unknown): string {
84
+ if (typeof value === 'function') return `fn:${JSON.stringify(value.toString())}`;
85
+ if (value === null || typeof value !== 'object') return JSON.stringify(value) ?? 'null';
86
+ if (Array.isArray(value)) return `[${value.map(canonical).join(',')}]`;
87
+ const entries = Object.entries(value as Record<string, unknown>)
88
+ .filter(([, item]) => item !== undefined)
89
+ .sort(([left], [right]) => (left < right ? -1 : left > right ? 1 : 0));
90
+ return `{${entries.map(([key, item]) => `${JSON.stringify(key)}:${canonical(item)}`).join(',')}}`;
91
+ }
92
+
93
+ /**
94
+ * 指纹取**全量内容**,不取"包名 + 各表条数"。
95
+ *
96
+ * 浅指纹的坏法很具体:两份候选表包名相同、条数相同、只有某个 `eventMap` 的
97
+ * 一个键不一样——浅指纹判为同一份,于是第二次注册被幂等放行,
98
+ * 之后整个进程用的是第一份。这正是本槽位要防的那种静默。
99
+ * 全量哈希每进程一次,代价可忽略。
100
+ */
101
+ function fingerprintOf(packs: readonly SomaOouiPack[]): string {
102
+ const ordered = [...packs].sort((left, right) => (left.name < right.name ? -1 : left.name > right.name ? 1 : 0));
103
+ return createHash('sha256').update(canonical(ordered)).digest('hex').slice(0, 16);
104
+ }
105
+
106
+ export interface RegisterOouiPacksOptions {
107
+ /**
108
+ * 显式换掉已注册的引擎。
109
+ *
110
+ * 只给"确实要换"的场景(宿主重配、测试里换一份裁剪词表)。
111
+ * 不加它而注册了不同的表 = 抛错,因为那更可能是两处接线都在跑,而不是有意替换。
112
+ */
113
+ readonly override?: boolean;
114
+ }
115
+
116
+ /**
117
+ * 宿主接线点:每进程一次,与组件注册同点、用同一张组件表。
118
+ *
119
+ * ```ts
120
+ * import { contractView, registerOouiPacks } from 'soma-core/server/ooui';
121
+ * const components = composeComponentPacks([createSomaUiPack(), ...business]).components;
122
+ * const contracts = Object.values(components).map((d) => contractView(d.contract));
123
+ * registerOouiPacks([createSomaUiOouiPack({ contracts })]);
124
+ * ```
125
+ *
126
+ * 装配不过**当场抛**(`assembleOoui` 的既有行为):一个装不起来的引擎继续跑下去,
127
+ * 产出的是"少了一半词汇"的界面,而不是错误。
128
+ */
129
+ export function registerOouiPacks(
130
+ packs: readonly SomaOouiPack[],
131
+ options: RegisterOouiPacksOptions = {},
132
+ ): SomaOouiEngine {
133
+ const fingerprint = fingerprintOf(packs);
134
+ const existing = slot;
135
+ if (existing && !options.override) {
136
+ // 同一份表注册两次:模块加载序的正常结果,幂等放行。
137
+ if (existing.fingerprint === fingerprint) return existing.engine;
138
+ throw new SomaOouiError({
139
+ layer: 'assembly',
140
+ code: 'OOUI-ASM-SLOT-CONFLICT',
141
+ situation: `本进程已注册过演绎引擎(词汇包 ${existing.packNames.join(' + ') || '(无名)'}),`
142
+ + `现在又收到一份不同的(${packs.map((pack) => pack.name).join(' + ') || '(无名)'})。`,
143
+ problem: '静默取用后者会让"演绎依据哪份词汇"这件事不可追查;静默保留前者更坏——'
144
+ + '业务包覆盖过的组件契约会被裸表的那份顶掉,于是 eventMap 对着错的一份 emits '
145
+ + '核过闸门,幽灵 emit 一声不出,表现是运行期点了没反应。'
146
+ + '所以两种"静默"都不选,当场拒收。',
147
+ remedy: '三条按实情选一条:\n'
148
+ + ' ① 宿主只应注册一次——把两处接线合成一处(与组件注册同点);\n'
149
+ + ' ② 确实要换(宿主重配 / 测试用裁剪词表):'
150
+ + 'registerOouiPacks(packs, { override: true });\n'
151
+ + ' ③ 测试里想回到未注册状态:resetOouiEngineSlot()。',
152
+ src: { file: '<host:bootstrap>', path: 'registerOouiPacks' },
153
+ });
154
+ }
155
+ const engine = assembleOoui(packs);
156
+ slot = { engine, fingerprint, packNames: packs.map((pack) => pack.name) };
157
+ return engine;
158
+ }
159
+
160
+ /**
161
+ * 取本进程的引擎。**没注册时返回 `undefined`,不抛、不兜底。**
162
+ *
163
+ * 兜底(空引擎 / 内置默认词汇)在这里的坏法是:编译照常成功、页面照常发布、
164
+ * 演绎出的那块永远是空的——而空区域与"这块本来就没写内容"分不开。
165
+ * 拒收归调用点(`requireOouiEngine`),它知道是哪个页面的哪一段,报得出位置。
166
+ */
167
+ export function resolveOouiEngine(): SomaOouiEngine | undefined {
168
+ return slot?.engine ?? undefined;
169
+ }
170
+
171
+ /** 已注册引擎的词汇包名(诊断与自检报告用)。未注册时为空数组 */
172
+ export function registeredOouiPackNames(): readonly string[] {
173
+ return slot?.packNames ?? [];
174
+ }
175
+
176
+ /**
177
+ * 清空槽位。**只给测试用**——生产路径上没有"卸载引擎"这件事。
178
+ *
179
+ * 与 `resetPackStyleInjection()` 同一性质:进程级状态在测试之间必须能归零,
180
+ * 否则用例顺序会决定断言结果。
181
+ */
182
+ export function resetOouiEngineSlot(): void {
183
+ slot = null;
184
+ }