soma-core 1.4.1 → 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 (221) 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 +443 -30
  9. package/core/build/component/component-graph.ts +28 -105
  10. package/core/build/component/package-loader.ts +50 -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/build/pack/pack-init.ts +19 -14
  58. package/core/client/base/SomaHttpClient.ts +34 -1
  59. package/core/client/component/ai-catalog.ts +42 -0
  60. package/core/client/component/example-blocks.ts +1 -7
  61. package/core/client/component/theme-component-tokens.ts +12 -15
  62. package/core/client/component/verify-pack.ts +120 -1
  63. package/core/client/container/SomaContainerAdapter.ts +6 -2
  64. package/core/client/data/data-object-resolver.ts +27 -8
  65. package/core/client/diagnostics/telemetry-context.ts +0 -4
  66. package/core/client/engine/asset-resolver.ts +0 -1
  67. package/core/client/engine/event-engine.ts +7 -3
  68. package/core/client/engine/soma-bootstrap.ts +292 -34
  69. package/core/client/engine/style-binder.ts +0 -1
  70. package/core/client/infra/http/IHttpClient.ts +0 -6
  71. package/core/client/infra/http/SomaHttpService.ts +5 -2
  72. package/core/client/infra/notify/DomNotifyService.ts +1 -1
  73. package/core/client/infra/router/router-path.ts +0 -6
  74. package/core/client/parser/annotation-extractor.ts +1 -1
  75. package/core/client/parser/blocks/namespace.ts +30 -5
  76. package/core/client/parser/blocks/page-parser.ts +44 -1
  77. package/core/client/parser/blocks/use-parser.ts +266 -46
  78. package/core/client/parser/data-config-parser.ts +71 -3
  79. package/core/client/parser/layout-parser.ts +4 -3
  80. package/core/client/parser/reaction-parser.ts +0 -1
  81. package/core/client/parser/ui-config-parser.ts +212 -74
  82. package/core/client/theme/scene-tokens.ts +9 -3
  83. package/core/client/theme/theme-axes.ts +74 -16
  84. package/core/client/theme/theme-engine.ts +280 -69
  85. package/core/client/theme/tone-solver.ts +9 -8
  86. package/core/index.ts +38 -3
  87. package/core/server/api/load-host-service.ts +8 -2
  88. package/core/server/declaration-safety.ts +11 -0
  89. package/core/server/host/page-response-request.ts +0 -2
  90. package/core/server/host/published-page-artifact-cache.ts +244 -0
  91. package/core/server/host/published-page-assets.ts +44 -5
  92. package/core/server/mock/node/cli.mjs +0 -1
  93. package/core/server/mock/node/schema-generator.mjs +0 -1
  94. package/core/server/ooui.ts +34 -0
  95. package/core/server/page-assets.ts +8 -0
  96. package/core/server/page-declaration.ts +18 -0
  97. package/core/server/registry/asset-store.ts +327 -0
  98. package/core/server/registry/declaration-precompiler.ts +49 -6
  99. package/core/server/registry/index.ts +47 -1
  100. package/core/server/registry/page-registry-repository.ts +6 -2
  101. package/core/server/registry/page-registry-store.ts +133 -19
  102. package/core/server/registry/publish-asset-pin.ts +557 -0
  103. package/core/server/registry/services/pages/List.ts +15 -3
  104. package/core/server/registry/validation/compile-gate.ts +180 -8
  105. package/core/server/registry/validation/declaration-safety-scan.ts +113 -23
  106. package/core/shared/component/derive-sample.ts +290 -0
  107. package/core/shared/component/field-lines.ts +563 -0
  108. package/core/shared/container-breakpoints.ts +46 -0
  109. package/core/shared/object-semantics.ts +240 -0
  110. package/core/shared/ooui-declaration.ts +235 -0
  111. package/core/shared/types/component-contract.types.ts +30 -13
  112. package/core/shared/types/data-config.types.ts +95 -0
  113. package/core/shared/types/domain.types.ts +0 -24
  114. package/core/shared/types/engine.types.ts +0 -5
  115. package/core/shared/types/layout-constraint.types.ts +16 -0
  116. package/core/shared/types/ui-config.types.ts +163 -13
  117. package/dist/cli/soma.js +24 -11
  118. package/dist/core/index.cjs +2424 -1098
  119. package/dist/types/build/blocks/block-compile.d.ts +16 -1
  120. package/dist/types/build/blocks/migrate-flat.d.ts +17 -0
  121. package/dist/types/build/compiler/page-declaration-compiler.d.ts +46 -0
  122. package/dist/types/build/compiler/route-builder.d.ts +0 -1
  123. package/dist/types/build/component/component-graph.d.ts +17 -53
  124. package/dist/types/build/component/package-loader.d.ts +8 -1
  125. package/dist/types/build/layout/constraint-solver.d.ts +46 -4
  126. package/dist/types/build/ooui/artifact/artifact.types.d.ts +180 -0
  127. package/dist/types/build/ooui/artifact/emit-artifact.d.ts +58 -0
  128. package/dist/types/build/ooui/artifact/emit-html.d.ts +53 -0
  129. package/dist/types/build/ooui/artifact/index.d.ts +5 -0
  130. package/dist/types/build/ooui/artifact/spatial-tree.d.ts +48 -0
  131. package/dist/types/build/ooui/artifact/utility-class.d.ts +46 -0
  132. package/dist/types/build/ooui/composition/candidate.types.d.ts +206 -0
  133. package/dist/types/build/ooui/composition/control-model.d.ts +37 -0
  134. package/dist/types/build/ooui/composition/registry.d.ts +66 -0
  135. package/dist/types/build/ooui/composition/select.d.ts +63 -0
  136. package/dist/types/build/ooui/diagnostics/codes.d.ts +28 -0
  137. package/dist/types/build/ooui/diagnostics/error.d.ts +135 -0
  138. package/dist/types/build/ooui/diagnostics/format.d.ts +51 -0
  139. package/dist/types/build/ooui/diagnostics/index.d.ts +25 -0
  140. package/dist/types/build/ooui/diagnostics/issue.types.d.ts +56 -0
  141. package/dist/types/build/ooui/engine-slot.d.ts +41 -0
  142. package/dist/types/build/ooui/index.d.ts +286 -0
  143. package/dist/types/build/ooui/intent/derive-intent.d.ts +32 -0
  144. package/dist/types/build/ooui/intent/field-rules.d.ts +99 -0
  145. package/dist/types/build/ooui/intent/intent.types.d.ts +318 -0
  146. package/dist/types/build/ooui/intent/verb-events.d.ts +70 -0
  147. package/dist/types/build/ooui/page/budget.d.ts +28 -0
  148. package/dist/types/build/ooui/page/compose-page.d.ts +41 -0
  149. package/dist/types/build/ooui/page/index.d.ts +4 -0
  150. package/dist/types/build/ooui/page/page.types.d.ts +264 -0
  151. package/dist/types/build/ooui/page/region-row.d.ts +16 -0
  152. package/dist/types/build/ooui/semantic/expand-page-surface.d.ts +33 -0
  153. package/dist/types/build/ooui/semantic/kernel.types.d.ts +125 -0
  154. package/dist/types/build/ooui/semantic/normalize.d.ts +45 -0
  155. package/dist/types/build/ooui/semantic/origin.types.d.ts +95 -0
  156. package/dist/types/build/ooui/semantic/role-alias.d.ts +35 -0
  157. package/dist/types/build/ooui/semantic/shorthand.d.ts +60 -0
  158. package/dist/types/build/ooui/semantic/surface.types.d.ts +16 -0
  159. package/dist/types/build/ooui/semantic/validate-request.d.ts +19 -0
  160. package/dist/types/build/ooui/spatial/emit-utility.d.ts +43 -0
  161. package/dist/types/build/ooui/spatial/ir.types.d.ts +280 -0
  162. package/dist/types/build/ooui/spatial/registry.d.ts +110 -0
  163. package/dist/types/build/ooui/spatial/solve.d.ts +42 -0
  164. package/dist/types/build/ooui/spatial/utility.types.d.ts +191 -0
  165. package/dist/types/build/ooui/trace/index.d.ts +3 -0
  166. package/dist/types/build/ooui/trace/render.d.ts +42 -0
  167. package/dist/types/build/ooui/trace/source.types.d.ts +25 -0
  168. package/dist/types/build/ooui/trace/trace.types.d.ts +143 -0
  169. package/dist/types/client/base/SomaHttpClient.d.ts +8 -0
  170. package/dist/types/client/component/ai-catalog.d.ts +9 -0
  171. package/dist/types/client/component/example-blocks.d.ts +0 -2
  172. package/dist/types/client/component/theme-component-tokens.d.ts +8 -5
  173. package/dist/types/client/component/verify-pack.d.ts +10 -0
  174. package/dist/types/client/data/data-object-resolver.d.ts +10 -2
  175. package/dist/types/client/diagnostics/telemetry-context.d.ts +0 -1
  176. package/dist/types/client/engine/soma-bootstrap.d.ts +123 -10
  177. package/dist/types/client/infra/http/IHttpClient.d.ts +0 -5
  178. package/dist/types/client/infra/http/SomaHttpService.d.ts +1 -1
  179. package/dist/types/client/infra/router/router-path.d.ts +0 -2
  180. package/dist/types/client/parser/blocks/namespace.d.ts +20 -0
  181. package/dist/types/client/parser/blocks/page-parser.d.ts +9 -0
  182. package/dist/types/client/parser/blocks/use-parser.d.ts +38 -4
  183. package/dist/types/client/parser/data-config-parser.d.ts +13 -0
  184. package/dist/types/client/parser/ui-config-parser.d.ts +1 -11
  185. package/dist/types/client/theme/scene-tokens.d.ts +9 -3
  186. package/dist/types/client/theme/theme-axes.d.ts +64 -1
  187. package/dist/types/client/theme/theme-engine.d.ts +13 -8
  188. package/dist/types/client/theme/tone-solver.d.ts +9 -5
  189. package/dist/types/index.d.ts +6 -4
  190. package/dist/types/server/declaration-safety.d.ts +7 -0
  191. package/dist/types/server/host/page-response-request.d.ts +0 -1
  192. package/dist/types/server/host/published-page-artifact-cache.d.ts +64 -0
  193. package/dist/types/server/ooui.d.ts +18 -0
  194. package/dist/types/server/page-assets.d.ts +7 -0
  195. package/dist/types/server/page-declaration.d.ts +14 -0
  196. package/dist/types/server/registry/asset-store.d.ts +112 -0
  197. package/dist/types/server/registry/declaration-precompiler.d.ts +23 -3
  198. package/dist/types/server/registry/index.d.ts +3 -1
  199. package/dist/types/server/registry/page-registry-store.d.ts +57 -4
  200. package/dist/types/server/registry/publish-asset-pin.d.ts +166 -0
  201. package/dist/types/server/registry/services/pages/List.d.ts +9 -3
  202. package/dist/types/server/registry/validation/compile-gate.d.ts +63 -0
  203. package/dist/types/shared/component/derive-sample.d.ts +37 -0
  204. package/dist/types/shared/component/field-lines.d.ts +19 -0
  205. package/dist/types/shared/container-breakpoints.d.ts +42 -0
  206. package/dist/types/shared/object-semantics.d.ts +42 -0
  207. package/dist/types/shared/ooui-declaration.d.ts +135 -0
  208. package/dist/types/shared/types/component-contract.types.d.ts +29 -12
  209. package/dist/types/shared/types/data-config.types.d.ts +86 -0
  210. package/dist/types/shared/types/domain.types.d.ts +0 -21
  211. package/dist/types/shared/types/engine.types.d.ts +0 -4
  212. package/dist/types/shared/types/layout-constraint.types.d.ts +1 -0
  213. package/dist/types/shared/types/ui-config.types.d.ts +157 -12
  214. package/next.config.js +106 -13
  215. package/package.json +28 -2
  216. package/core/client/host-bridge/index.ts +0 -27
  217. package/core/client/parser/yaml-loader.ts +0 -36
  218. package/core/shared/manifest/manifest-contract.ts +0 -12
  219. package/dist/types/client/host-bridge/index.d.ts +0 -9
  220. package/dist/types/client/parser/yaml-loader.d.ts +0 -21
  221. package/dist/types/shared/manifest/manifest-contract.d.ts +0 -4
@@ -84,27 +84,3 @@ export interface ValidationResult {
84
84
  /** 各字段的错误消息集合 */
85
85
  errors: Record<string, string[]>;
86
86
  }
87
-
88
- /**
89
- * 业务事件处理函数签名
90
- * 所有被 _event.yaml 引用的方法必须符合此签名
91
- */
92
- export interface SomaEventHandler {
93
- (...args: any[]): Promise<boolean> | boolean | void;
94
- }
95
-
96
- /**
97
- * 常量对象接口
98
- * 提供静态枚举值或配置项
99
- */
100
- export interface SomaConstant {
101
- readonly [key: string]: any;
102
- }
103
-
104
- /**
105
- * 可加载常量接口
106
- * 支持从后端加载动态字典数据
107
- */
108
- export interface SomaLoadableConstant extends SomaConstant {
109
- loadFromAPI(): Promise<void>;
110
- }
@@ -34,8 +34,3 @@ export interface BindingEntry {
34
34
  /** 预编译的渲染函数:消除 switch 分支 + 类型判断 */
35
35
  compiledRender?: (value: any) => void;
36
36
  }
37
-
38
- export interface PendingPatch {
39
- path: string;
40
- value: any;
41
- }
@@ -24,6 +24,22 @@ export type SomaSizing = 'fixed' | 'hug' | 'fill';
24
24
  export const SOMA_LAYOUT_PRIORITIES = [250, 500, 750, 1000] as const;
25
25
  export type SomaPriority = typeof SOMA_LAYOUT_PRIORITIES[number];
26
26
 
27
+ /**
28
+ * 尺寸意图三档的闭集:`SomaSizing` 这个**类型**在运行时的样子,全仓只此一份。
29
+ *
30
+ * 此前有两份:`layout:` 解析器自持一个 Set,`ooui:` 那一侧(`shared/ooui-declaration.ts`)另有一份。
31
+ * 两份逐字相同,可漂开的那天不会有任何断言红——解析器与演绎引擎会对同一个 `sizing` 给出不同的裁决。
32
+ * 以 `SomaSizing` 做**编译期对账**(`satisfies`):类型加一档、减一档而这里没跟上,typecheck 当场红。
33
+ * 顺序即文档书写序,也是报错文案里「fixed / hug / fill」的顺序。
34
+ */
35
+ const SIZING_SET = {
36
+ fixed: true,
37
+ hug: true,
38
+ fill: true,
39
+ } as const satisfies Record<SomaSizing, true>;
40
+
41
+ export const SOMA_LAYOUT_SIZINGS = Object.keys(SIZING_SET) as readonly SomaSizing[];
42
+
27
43
  /** 换行策略:不换 / 窄了就竖排 / 横向滚动成一条卷轴 */
28
44
  export type SomaWrap = 'none' | 'below' | 'reel';
29
45
 
@@ -84,6 +84,156 @@ export interface ExtendedShowValue {
84
84
  */
85
85
  export type ShowMapping = Record<string, ShowValue>;
86
86
 
87
+ // ─────────────────────────────────────────────────────────────────────
88
+ // OOUI 演绎(REQ-014):声明 `ooui` 与产物 `oouiArtifact` 的运行时形状
89
+ //
90
+ // ── 为什么这两个类型必须住在 shared,而不是住在引擎里 ────────────────
91
+ // 引擎在 `core/build/ooui/`,运行时永远够不着它(`verify-client-dep-graph`
92
+ // 禁止 client import build)。产物却必须**穿过**运行时资产才能到浏览器:
93
+ // 它随 `_ui.yaml` 一起被 Registry 发布、被 parseUiConfig 读回。
94
+ // 类型若留在引擎里,运行时只能拿 `unknown` 顶着,于是产物字段名改一次、
95
+ // 运行时读旧名字读到 `undefined`——表现是"这页的演绎样式忽然没了",
96
+ // 不报错、不留痕。放 shared 是唯一能让两端共用一份字段名的位置。
97
+ //
98
+ // 与 `layout` / `layoutCss` 是同一条范式:**声明进、产物出、声明不下发**。
99
+ // ─────────────────────────────────────────────────────────────────────
100
+
101
+ /**
102
+ * 一处演绎请求的声明(`ooui:` 段的一条)。键是 HTML 锚点 id。
103
+ *
104
+ * 这是**表层书写形态**,不是语义层的 `SomaSemanticRequest`:
105
+ * `object` 在这里是页面 `data:` 段里的对象**名**,构建期才解析成对象本体。
106
+ * 运行时拿不到 `data:` 的解析结果(它是另一份资产),所以这里只能是名字。
107
+ *
108
+ * `verb` / `form` 保持 `string`:八动词与十九形态的封闭集住在引擎里
109
+ * (`core/build/ooui/**`),运行时 import 不到。**闭集判定归构建期**
110
+ * (`OOUI-SEM-VERB-UNKNOWN` / `OOUI-INT-FORM-UNKNOWN`),
111
+ * 这里若照抄一份闭集,两份必然漂,而漂掉的表现是"某个动词在运行时被判非法、
112
+ * 在构建期却合法"——两处都看着对,只有页面是错的。
113
+ */
114
+ export interface SomaOouiRequestDeclaration {
115
+ /** 页面 `data:` 段里的对象名 */
116
+ object: string;
117
+ /** 八动词之一(闭集在构建期查) */
118
+ verb: string;
119
+ /** 只演绎这几个字段;省略 = 全部字段 */
120
+ focus?: string[];
121
+ /** 动词的作用路径:对象 `relations` 里的关系名 */
122
+ through?: string;
123
+ /** 逃生门:直接指定根形态,跳过动词分派 */
124
+ form?: string;
125
+ /**
126
+ * 联动来源(REQ-014 §29.1):本区域监听**另一个区域**的哪个语义事件。
127
+ *
128
+ * `{ region: <另一个锚点>, as: <语义事件> }`。它在**编译期**被裁决:
129
+ * 源区域的动词 / 控制模型 / 选中组件三者合起来若产不出那个事件,当场拒收
130
+ * (`OOUI-SEM-BINDING-UNSUPPORTED`)。这道闸门防的正是"点了左边列表右边没反应"——
131
+ * 那件事运行期不报错:两块都渲染正常、事件也确实发出去了,只是没有人接。
132
+ */
133
+ bound_to?: { region: string; as: string };
134
+ /**
135
+ * 本区域的空间约束(逃生门)。缺省 = 与其余区域等分(`sizing: 'fill'`)。
136
+ *
137
+ * **这是缺省,不是推断**:从 `bound_to` 反推"主区该宽一些"是一个关于视觉设计的
138
+ * 猜测,不是关于信息对象的事实(铁律三不许猜)。要主从不等分就写出来(铁律一)。
139
+ */
140
+ layout?: { sizing?: string; width?: string; min?: string; max?: string; priority?: number };
141
+ }
142
+
143
+ /** 演绎出的一个界面节点。`children` 是字段级节点 */
144
+ export interface SomaOouiNode {
145
+ /** 交互形态(§3.2 十九形态之一) */
146
+ form: string;
147
+ /** 选中的组件契约名;`#text` 表示纯文本节点 */
148
+ component: string;
149
+ /** 组件所在层:atom / composite / solution / template / text-node */
150
+ layer: string;
151
+ /** 控制模型:autonomous(自治型)/ controlled(受控型) */
152
+ control_model: string;
153
+ /** 命中的规则名——"为什么是这个组件"的答案 */
154
+ rule: string;
155
+ /** `display` 形态的呈现细分 */
156
+ variant?: string;
157
+ /** 字段级节点指向的字段键;根节点没有 */
158
+ field?: string;
159
+ /** 组件 emit → 语义事件的接线 */
160
+ events?: Array<{ emit: string; kinds: string[] }>;
161
+ children?: SomaOouiNode[];
162
+ }
163
+
164
+ /**
165
+ * 一个锚点的演绎结果。
166
+ *
167
+ * `html` 是**这一处区域真正要出现在浏览器里的那份 DOM**——没有它,整条演绎链
168
+ * 止于 `deduce()` 的返回值:六层全绿、产物齐全、页面上什么都没有。
169
+ * 那种"通了"最像成功:`ooui_artifact` 在资产里、样式表注入了、
170
+ * 锚点还是空的,而空锚点与"这块本来就没写内容"长得一模一样。
171
+ *
172
+ * ── 为什么 html 挂在 region 上而不是挂在整页产物上 ──────────────────
173
+ * 落点是**逐锚点**的:每份 html 要插进它自己那个 `data-soma-id` 容器里。
174
+ * 挂在页面级只能得到一份拼接串,运行时再去拆——拆的判据就是第二份发射器语法,
175
+ * 而两份语法漂开时页面照样渲染,只是某一块插错了容器。
176
+ *
177
+ * ── 为什么没有 `html_key`(对照 `css_key`)────────────────────────
178
+ * `css` 要进的是**全局**的 `<style>` 去重表(`injectStyleOnce` 同键不同内容
179
+ * 静默保留第一份),所以它必须内容寻址。`html` 的落点是页面里那个锚点元素本身,
180
+ * 天然逐页隔离,没有跨页共用一个键的面。运行时仍按内容变化决定要不要重插
181
+ * (见 `soma-bootstrap.ts` 的 `installOouiHtml`),但那个标记是**运行时的**,
182
+ * 不是产物字段——把它写进产物等于让产物记住某一次挂载的过程。
183
+ */
184
+ export interface SomaOouiRegion {
185
+ /** HTML 锚点 id(`data-soma-id`) */
186
+ anchor: string;
187
+ /** 演绎所依据的数据对象名 */
188
+ object: string;
189
+ /** 演绎所依据的动词 */
190
+ verb: string;
191
+ root: SomaOouiNode;
192
+ /**
193
+ * 这一处区域发射出的 DOM:`区域外壳 > 根构件` 两层,**到组件边界为止**
194
+ * (架构 D4;字段级落 `root.children` 与构件层的 `bindings.fields`,不摊成基础件拼装)。
195
+ *
196
+ * **不含任何内联事件处理器**(架构 §24.1):事件走 `eventConfig`,不进 DOM 属性。
197
+ * 由 `core/build/ooui/artifact/emit-html.ts` 产出并当场过闸门
198
+ * (`OOUI-ART-INLINE-HANDLER` / `OOUI-ART-CLASS-UNKNOWN`)。
199
+ *
200
+ * 运行时**仍然不信它**:它随 `_ui.yaml` 走,而那份资产可以被手写、被改。
201
+ * 发布期的注入面静态扫描今天**也扫这一面**(`declaration-safety-scan.ts` 把禁用标签 /
202
+ * 内联 on* / srcdoc / 伪协议四条判据一并施加到四个 YAML 面上,按文本扫),
203
+ * 但它守的是"写进声明仓库"这个入口——绕过 Registry 直接构建、或发布后再改资产的路
204
+ * 它一条都拦不到。所以注入前还要再过一道结构闸门:两道是纵深,不是重复,
205
+ * "引擎生成的"与"可信的"不是同一句话。
206
+ */
207
+ html: string;
208
+ }
209
+
210
+ /**
211
+ * 整页演绎产物。**构建期产物,不手写**。
212
+ *
213
+ * `css` 与 `css_key` 成对出现或成对缺席:
214
+ * 注入键必须是**内容哈希**(`ooui:<sha256 前 8 位>`),不能是语义名。
215
+ * 理由在 `pack-styles.ts` 的 `injectOnce` 里——它没有内容冲突检测:
216
+ *
217
+ * if (!css.trim() || injected.has(key)) return; // 同键不同内容 → 静默保留第一份
218
+ *
219
+ * 按 `(对象, 动词)` 之类的语义名命名,SPA 内路由切到同键不同产物的页面时
220
+ * **会继续用上一页的 CSS**,页面看着渲染正常、间距全错,控制台一行都没有。
221
+ * 内容哈希让"同键"与"同内容"变成同一件事,顺带把内容寻址提前一半。
222
+ */
223
+ export interface SomaPageOouiArtifact {
224
+ /** 产物格式版本。运行时读到不认识的版本整份忽略并告警,不猜字段 */
225
+ version: 1;
226
+ /** 按锚点名升序——同一份声明必须产出同一份字节(§19.3 幂等) */
227
+ regions: SomaOouiRegion[];
228
+ /**
229
+ * 空间层产物:布局解的容器查询 + 原子类规则,整页合并去重后的一份。
230
+ * 区域一个原子类都没产出时才缺席——那时也不该发一份空 `<style>`。
231
+ */
232
+ css?: string;
233
+ /** `css` 的注入键:`ooui:<sha256 前 8 位>` */
234
+ css_key?: string;
235
+ }
236
+
87
237
  /**
88
238
  * UI 配置顶层结构
89
239
  * 对应 _ui.yaml 文件的完整结构
@@ -120,17 +270,17 @@ export interface UiConfig {
120
270
  layout?: Record<string, SomaLayoutConstraint>;
121
271
  /** 构建期求解产物:只含容器查询 + flex 的 CSS(CL-2),运行时按页注入一次 */
122
272
  layoutCss?: string;
123
- }
124
-
125
- /**
126
- * 解析后的 show 条目
127
- * somaId@attr 语法拆分为 somaId + attrName
128
- */
129
- export interface ParsedShowEntry {
130
- /** 纯 data-soma-id(不含 @attr 后缀) */
131
- somaId: string;
132
- /** 属性绑定时的属性名(如 src、href、value) */
133
- attrName?: string;
134
- /** 原始绑定值 */
135
- value: ShowValue;
273
+ /**
274
+ * OOUI 演绎声明(REQ-014,保留键,可选):锚点 id → 一处演绎请求。
275
+ *
276
+ * 与 `layout` 同一条纪律:**未声明时编译产物与接线前字节级一致**——
277
+ * 页面不写 `ooui:`,整条演绎链一行都不跑,运行时也拿不到任何新字段。
278
+ *
279
+ * 它的产物是 `oouiArtifact`。演绎只在构建期(`compilePageDeclaration`)发生;
280
+ * 运行时若收到的是声明本身而没有产物,说明这页没走构建期编译——
281
+ * 引擎只告警、不代为演绎(求解器不进 client,与 CL-4 同)。
282
+ */
283
+ ooui?: Record<string, SomaOouiRequestDeclaration>;
284
+ /** 构建期演绎产物(REQ-014):区域 → 组件 + 事件接线,附空间层样式表 */
285
+ oouiArtifact?: SomaPageOouiArtifact;
136
286
  }
package/dist/cli/soma.js CHANGED
@@ -9,24 +9,36 @@ const node_fs_1 = __importDefault(require("node:fs"));
9
9
  const node_path_1 = __importDefault(require("node:path"));
10
10
  const args = process.argv.slice(2);
11
11
  const command = args[0] || 'dev';
12
- const delegated = ['doctor', 'sync', 'lsp', 'codegen', 'init', 'package-vscode', 'eject'];
12
+ // 委派给 bin/soma-inline.cjs 的命令。soma-inline.cjs 不随包发布,所以这一组在装出去的包里
13
+ // 跑不起来——《框架接入指南》一.2 如实标着「当前不可用」。手册里写着可用的命令
14
+ // (component / pack / db / migrate / eject)都在下面各走自己的 bin,不经过这里。
15
+ const delegated = ['doctor', 'sync', 'lsp', 'codegen', 'init', 'package-vscode'];
13
16
  const packageRoot = node_path_1.default.resolve(__dirname, '../..');
14
- // REQ-009 EC-1/2/3:组件 eject / diff 与组件包脚手架。
15
- // 与 `db` 同样走独立进程:它们只读写文件,不需要 Next 工作区那一整套装配。
17
+ // `soma component eject|diff|upgrade` 与 `soma pack init`(REQ-009 EC-1/2/3 + REQ-010 F-45)。
18
+ // 与 db 同一分派方式:自有 bin、独立进程——它们只读写文件,不需要 Next 工作区那一整套装配。
19
+ // (这一段曾经原样重复了一份,第二份永远走不到。)
16
20
  if (command === 'component' || command === 'pack') {
17
21
  const child = (0, node_child_process_1.spawnSync)(process.execPath, [node_path_1.default.join(packageRoot, 'bin', 'component.cjs'), ...args], { cwd: process.cwd(), stdio: 'inherit', env: process.env });
18
22
  process.exit(child.status === null ? 1 : child.status);
19
23
  }
20
- // `soma component eject|diff` 与 `soma pack init`(REQ-009 EC-1/2/3)。
21
- // 与 db 同一分派方式:它们有自己的 bin,不走 soma-inline 的页面固化那条线。
22
- if (command === 'component' || command === 'pack') {
23
- const child = (0, node_child_process_1.spawnSync)(process.execPath, [node_path_1.default.join(packageRoot, 'bin', 'component.cjs'), command, ...args.slice(1)], { cwd: process.cwd(), stdio: 'inherit', env: process.env });
24
- process.exit(child.status === null ? 1 : child.status);
25
- }
26
24
  if (command === 'db') {
27
25
  const child = (0, node_child_process_1.spawnSync)(process.execPath, [node_path_1.default.join(packageRoot, 'bin', 'soma-db.cjs'), ...args.slice(1)], { cwd: process.cwd(), stdio: 'inherit', env: process.env });
28
26
  process.exit(child.status === null ? 1 : child.status);
29
27
  }
28
+ // `soma migrate`(平铺 → 块声明)。与 db 同一分派方式:自有 bin、独立进程、只读写页面声明。
29
+ // 曾经只有 soma-inline.cjs 路由它——而发布入口走的是本文件编译出的 dist/cli/soma.js,
30
+ // 装出去的包里 `soma migrate` 直接落进 Usage,手册里写着的命令用户一条都跑不起来。
31
+ if (command === 'migrate') {
32
+ const child = (0, node_child_process_1.spawnSync)(process.execPath, [node_path_1.default.join(packageRoot, 'bin', 'migrate.cjs'), ...args], { cwd: process.cwd(), stdio: 'inherit', env: process.env });
33
+ process.exit(child.status === null ? 1 : child.status);
34
+ }
35
+ // `soma eject <页面名>`(运行态 → 开发态)。曾经委派给 soma-inline.cjs——那个文件不随包发布,
36
+ // 装出去的包里这条命令一跑就 "Cannot find module"。改成与 db / migrate 同一分派方式。
37
+ // eject 作用于"我现在所在的宿主目录":cwd 与 SOMA_INVOKE_CWD 都取调用方的(与委派时同一语义)。
38
+ if (command === 'eject') {
39
+ const child = (0, node_child_process_1.spawnSync)(process.execPath, [node_path_1.default.join(packageRoot, 'bin', 'eject.cjs'), ...args], { cwd: process.cwd(), stdio: 'inherit', env: { ...process.env, SOMA_INVOKE_CWD: process.cwd() } });
40
+ process.exit(child.status === null ? 1 : child.status);
41
+ }
30
42
  function lstatIfPresent(filePath) {
31
43
  try {
32
44
  return node_fs_1.default.lstatSync(filePath);
@@ -435,8 +447,9 @@ function ensureNextWorkspace(hostDir) {
435
447
  }
436
448
  if (delegated.includes(command)) {
437
449
  // 用 packageRoot 而不是 __dirname:编译产物在 dist/cli/ 下,那里没有 soma-inline.cjs,
438
- // 于是全部 delegated 命令(doctor/sync/lsp/codegen/init/eject)一走 dist 就报
450
+ // 于是全部 delegated 命令(doctor/sync/lsp/codegen/init)一走 dist 就报
439
451
  // "Cannot find module"。源码目录跑得通、装出去就坏,是最难发现的一类路径 bug。
452
+ // (bin/soma-inline.cjs 本身也不在 package.json 的 files 里——见 delegated 的注释。)
440
453
  const inline = node_path_1.default.join(packageRoot, 'bin', 'soma-inline.cjs');
441
454
  const child = (0, node_child_process_1.spawnSync)(process.execPath, [inline, command, ...args.slice(1)], {
442
455
  cwd: packageRoot,
@@ -448,7 +461,7 @@ if (delegated.includes(command)) {
448
461
  process.exit(child.status === null ? 1 : child.status);
449
462
  }
450
463
  if (!['dev', 'build', 'start'].includes(command)) {
451
- console.error(`Usage: soma <dev|build|start|db|component|pack|${delegated.join('|')}> [...args]`);
464
+ console.error(`Usage: soma <dev|build|start|db|component|pack|migrate|eject|${delegated.join('|')}> [...args]`);
452
465
  process.exit(1);
453
466
  }
454
467
  const nextBin = resolveNextBin();