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
@@ -18,15 +18,28 @@
18
18
  // - 向后兼容:存量 JSON(无 app/tags/meta 的旧记录)读入时自动归一化补缺省值。
19
19
 
20
20
  import fs from 'node:fs';
21
- import { precompileDeclaration, type CompiledDeclaration } from './declaration-precompiler';
21
+ import type { CompiledPageDeclaration } from '../../build/compiler/page-declaration-compiler';
22
+ import {
23
+ DECLARATION_COMPILER_VERSION,
24
+ precompileDeclaration,
25
+ type CompiledDeclaration,
26
+ } from './declaration-precompiler';
27
+ import {
28
+ assetSupplyDriftNotice,
29
+ pinPublishedAssets,
30
+ type SomaAssetPin,
31
+ } from './publish-asset-pin';
32
+ import type { UiConfig } from '../../shared/types/ui-config.types';
22
33
  import { withRegistryLock, writeFileAtomic } from './registry-file-lock';
23
34
  import { RegistryError } from './registry-error';
24
35
  import path from 'node:path';
25
36
  import { scanDeclarationSafety } from './validation/declaration-safety-scan';
26
37
  import { crossCheckDeclaredApis } from './validation/cross-check';
27
- import { dryRunCompile } from './validation/compile-gate';
38
+ import {
39
+ dryRunCompileWithDiagnostics,
40
+ type SomaCompileDiagnostic,
41
+ } from './validation/compile-gate';
28
42
  import { scanUnknownComponents } from './validation/component-existence';
29
- import { compilePageDeclaration } from '../../build/compiler/page-declaration-compiler';
30
43
 
31
44
  /** 页面名约束:小写字母 / 数字 / 连字符,1~64 位(可直接用作文件名与 URL 片段) */
32
45
  export const PAGE_NAME_PATTERN = /^[a-z0-9-]{1,64}$/;
@@ -85,9 +98,23 @@ export type PageRegistryErrorCode =
85
98
  export class PageRegistryError extends RegistryError {
86
99
  declare readonly code: PageRegistryErrorCode;
87
100
 
88
- constructor(code: PageRegistryErrorCode, message: string) {
101
+ /**
102
+ * 结构化诊断(可选):编译闸门命中时带上 `code` / `src` / `trace` / `remedy`。
103
+ *
104
+ * 为什么挂在错误上而不是只发字符串:`message` 是给人读的终点,
105
+ * 而这条错误的真实消费者是 AI 修订链——它要按 `remedy` 改哪一行。
106
+ * 字段可选、纯数据,现有 `catch (e) { e.message }` 的调用方一律不受影响。
107
+ */
108
+ readonly diagnostics?: readonly SomaCompileDiagnostic[];
109
+
110
+ constructor(
111
+ code: PageRegistryErrorCode,
112
+ message: string,
113
+ diagnostics?: readonly SomaCompileDiagnostic[],
114
+ ) {
89
115
  super(code, message);
90
116
  this.name = 'PageRegistryError';
117
+ if (diagnostics && diagnostics.length > 0) this.diagnostics = diagnostics;
91
118
  }
92
119
  }
93
120
 
@@ -138,6 +165,18 @@ export interface PageVersionRecord {
138
165
  * 由服务端从统一源声明重新编译(见 DeclarationPrecompiler.isCompiledUsable)。
139
166
  */
140
167
  compiled?: CompiledDeclaration;
168
+ /**
169
+ * 资产钉子(可选):这一版**是对着哪一份组件 CSS 发布的**(内容摘要)。
170
+ *
171
+ * 与 `compiled` 平级而不是它的子键,因为两者性质相反:`compiled` 是缓存
172
+ * (编译失败即缺席,重编即可),钉子是真理(发布那一刻的事实,过后无从重建)。
173
+ * 塞进 `compiled` 会让一次编译失败连带丢掉钉子,而丢掉之后对账只会说"未钉住"——
174
+ * 通过,静默。详见 `publish-asset-pin.ts` 文件头。
175
+ *
176
+ * 缺席是正常状态:宿主没接样式供货来源(`setPublishedAssetSource`)、页面没引用构件、
177
+ * 或字节没能落库时都不钉。**钉子宁可缺席,不可说谎。**
178
+ */
179
+ assets?: SomaAssetPin;
141
180
  }
142
181
 
143
182
  /** publish 的可选项(第三参也兼容旧的裸 status 字符串写法) */
@@ -163,6 +202,12 @@ export interface PageVersionFields {
163
202
  tags: string[];
164
203
  meta?: PageRegistryMeta;
165
204
  operator?: string;
205
+ /**
206
+ * 编译闸门对**这同一份** `declaration` 的编译结果(发布路径专用,可选)。
207
+ * 给了就直接复用,`createPageVersionRecord` 不再编第二遍;不给(rollback / archive
208
+ * 复制旧声明时没有闸门那一次)照旧自己编。它只是编译输入,不进版本记录。
209
+ */
210
+ compiledPage?: CompiledPageDeclaration;
166
211
  }
167
212
 
168
213
  /** list() 返回的摘要条目(速记列直接可渲:状态 / 应用 / 标签 / 标题齐备) */
@@ -185,6 +230,19 @@ export interface PageRegistryListOptions {
185
230
  keyword?: string;
186
231
  /** 是否包含已归档页面(缺省 false:归档页从清单消失) */
187
232
  includeArchived?: boolean;
233
+ /**
234
+ * 精确只看这一种状态——比 includeArchived 更具体的筛选。
235
+ *
236
+ * 与 includeArchived 的关系:includeArchived 只是"要不要把 archived 混进缺省清单"
237
+ * 的粗粒度开关;显式传了 status 就按它精筛,覆盖 includeArchived 的缺省收窄行为
238
+ * (例如 status: 'archived' 时无需再传 includeArchived: true)。不传 status 时,
239
+ * 行为完全由 includeArchived 决定,不受影响。
240
+ *
241
+ * 与 publishedOnly 的关系:**publishedOnly 是不可越权的可见性铁律,永远先于 status
242
+ * 生效**——非特权主体(publishedOnly: true)传 status: 'archived' 依旧看不到任何
243
+ * 已下架页面。这个可选查询参数不能绕开按主体分层的访问控制(见 publishedOnly 注释)。
244
+ */
245
+ status?: Extract<PageRegistryStatus, 'published' | 'archived'>;
188
246
  /**
189
247
  * 只列已发布页面(匿名调用方的缺省视角)。
190
248
  *
@@ -255,7 +313,7 @@ export class PageRegistryStore {
255
313
  ): PageVersionRecord {
256
314
  const safeName = assertPageName(name);
257
315
  const normalizedOptions = normalizePublishOptions(options);
258
- const normalized = normalizeDeclaration(declaration);
316
+ const { declaration: normalized, compiledPage } = normalizeDeclaration(declaration);
259
317
  this.cache.delete(safeName);
260
318
  return this.appendLocked(safeName, {
261
319
  declaration: normalized,
@@ -264,6 +322,7 @@ export class PageRegistryStore {
264
322
  tags: normalizedOptions.tags ?? [],
265
323
  meta: normalizedOptions.meta,
266
324
  operator: normalizedOptions.operator,
325
+ compiledPage,
267
326
  });
268
327
  }
269
328
 
@@ -311,7 +370,8 @@ export class PageRegistryStore {
311
370
 
312
371
  /**
313
372
  * 页面摘要清单(按页面名排序,分页协议 { pages, total })。
314
- * 缺省排除已归档页面;支持 app / 关键词过滤与 limit/offset 分页。
373
+ * 缺省排除已归档页面;支持 app / 关键词 / status 精筛与 limit/offset 分页;
374
+ * status 语义见 PageRegistryListOptions.status 注释。
315
375
  */
316
376
  list(options: PageRegistryListOptions = {}): PageRegistryListResult {
317
377
  const names = new Set<string>(this.cache.keys());
@@ -338,7 +398,11 @@ export class PageRegistryStore {
338
398
  if (options.publishedOnly && item.status !== 'published') {
339
399
  continue;
340
400
  }
341
- if (!options.includeArchived && item.status === 'archived') {
401
+ if (options.status !== undefined) {
402
+ if (item.status !== options.status) {
403
+ continue;
404
+ }
405
+ } else if (!options.includeArchived && item.status === 'archived') {
342
406
  continue;
343
407
  }
344
408
  if (options.app !== undefined && item.app !== options.app) {
@@ -630,8 +694,32 @@ export function createPageVersionRecord(
630
694
  ...(fields.meta ? { meta: { ...fields.meta } } : {}),
631
695
  ...(fields.operator ? { operator: fields.operator } : {}),
632
696
  };
633
- const compiled = precompileDeclaration(fields.declaration);
634
- return compiled ? { ...record, compiled } : record;
697
+ // 发布路径上闸门已经编过这同一份声明(`fields.compiledPage`),直接复用;
698
+ // rollback / archive 复制的是旧声明,没有闸门那一次,照旧在这里编。
699
+ const compiled = precompileDeclaration(fields.declaration, fields.compiledPage);
700
+ // 钉资产必须与产生版本记录**在同一步**完成:分成两步就有了"版本已落库、资产还没落库"
701
+ // 的中间态,而那个中间态崩一次就留下一个指向不存在字节的钉子。
702
+ //
703
+ // 演绎产物要一起带上:演绎选出的组件不在 html 里(它在 `oouiArtifact.regions[].root`),
704
+ // 不带就会漏钉恰好是演绎选中的那批——表现是手写那部分有样式、演绎那一块光秃秃,
705
+ // 两边都"渲染成功"。编译失败(compiled 为 null)时带不上,钉子会把这件事记进 caveats。
706
+ const artifact = (compiled?.uiConfig as UiConfig | undefined)?.oouiArtifact;
707
+ const assets = pinPublishedAssets(fields.declaration, {
708
+ compilerVersion: compiled?.compilerVersion ?? DECLARATION_COMPILER_VERSION,
709
+ ...(artifact ? { artifact } : {}),
710
+ });
711
+ // 组件库在两次发布之间换了,就在**发布这一刻**说;等回滚时再说已经是故障现场了。
712
+ const drift = assetSupplyDriftNotice(
713
+ versions[versions.length - 1]?.assets,
714
+ assets ?? undefined,
715
+ `${name} v${record.version}`,
716
+ );
717
+ if (drift) console.warn(`[soma-core][注册中心] ${drift}`);
718
+ return {
719
+ ...record,
720
+ ...(compiled ? { compiled } : {}),
721
+ ...(assets ? { assets } : {}),
722
+ };
635
723
  }
636
724
 
637
725
  function cloneDeclaration(declaration: PageRegistryDeclaration): PageRegistryDeclaration {
@@ -758,8 +846,18 @@ function normalizeMeta(meta: unknown): PageRegistryMeta {
758
846
  return normalized;
759
847
  }
760
848
 
761
- /** 声明归一化:HTML + 统一 SOMA DSL 必填;页面侧车字段只允许缺省或空串。 */
762
- export function normalizeDeclaration(declaration: unknown): PageRegistryDeclaration {
849
+ /**
850
+ * 声明归一化:HTML + 统一 SOMA DSL 必填;页面侧车字段只允许缺省或空串。
851
+ *
852
+ * 除了归一化后的声明,还把编译闸门那一次的编译结果(`compiledPage`)一并交出来,
853
+ * 供 `createPageVersionRecord` 落预编译产物时复用。闸门编的与预编译要编的是
854
+ * **同一份归一化声明**、同一个纯函数,发布路径上相邻两步——第二遍只是重付一次编译代价
855
+ * (演绎链接进来之后这笔代价随声明规模长),而落库结果逐字相同,多编一遍不会让任何东西红。
856
+ */
857
+ export function normalizeDeclaration(declaration: unknown): {
858
+ declaration: PageRegistryDeclaration;
859
+ compiledPage: CompiledPageDeclaration;
860
+ } {
763
861
  if (!declaration || typeof declaration !== 'object' || Array.isArray(declaration)) {
764
862
  throw new PageRegistryError(
765
863
  PageRegistryErrorCodes.PAGE_DECLARATION_INVALID,
@@ -815,11 +913,16 @@ export function normalizeDeclaration(declaration: unknown): PageRegistryDeclarat
815
913
 
816
914
  // 干跑编译:编不过的声明不许落库。排在安全扫描之后、白名单之前——
817
915
  // 扫描是纯正则(最便宜),编译要真跑解析器(贵一些),白名单还要读 API 注册表(要读盘)。
818
- const uncompilable = dryRunCompile(normalized);
819
- if (uncompilable.length > 0) {
916
+ //
917
+ // 取 WithDiagnostics 形态有两个理由:
918
+ // ① 拒绝时把结构化诊断(code / src / trace / remedy)挂到错误上,AI 修订链才修得动;
919
+ // ② 通过时把编译产物留在手里,下面的取数白名单与落库的预编译产物都直接复用,不再编第二遍。
920
+ const gate = dryRunCompileWithDiagnostics(normalized);
921
+ if (gate.issues.length > 0) {
820
922
  throw new PageRegistryError(
821
923
  PageRegistryErrorCodes.PAGE_DECLARATION_INVALID,
822
- `声明未通过编译闸门:${uncompilable.join(';')}`,
924
+ `声明未通过编译闸门:${gate.issues.join(';')}`,
925
+ gate.diagnostics,
823
926
  );
824
927
  }
825
928
 
@@ -835,10 +938,21 @@ export function normalizeDeclaration(declaration: unknown): PageRegistryDeclarat
835
938
  // 两表交叉校验:页面绑定的数据接口必须已在 API 注册表登记。
836
939
  // 与安全扫描同一个咽喉、同一种失败方式——白名单才有牙齿:
837
940
  // 没登记过的接口,AI 生成的页面在物理上就绑不上。
838
- // 编译闸门已经证明可编译;这里再取同一编译器的 dataConfig 做 API 白名单交叉校验,
839
- // 不另开 dataYaml 解析入口。
840
- const compiled = compilePageDeclaration(normalized);
841
- const unregistered = crossCheckDeclaredApis(compiled.dataConfig);
941
+ // 判据取自**编译闸门那一次**的 dataConfig:同一份输入、同一个纯函数,
942
+ // 再编一遍只是重付一次编译代价,不另开 dataYaml 解析入口。
943
+ //
944
+ // fail-closed:产物在手才放行。`compiled` 为空意味着闸门自己出了内部问题
945
+ // (正常路径上 issues 空 ⇒ 产物必非空),此时**必须拒**——
946
+ // 一旦退化成"没编出来就跳过白名单",未注册接口就从这里进库了,
947
+ // 而且不留任何痕迹:发布成功、页面能开、越权取数直到线上才发作。
948
+ if (!gate.compiled) {
949
+ throw new PageRegistryError(
950
+ PageRegistryErrorCodes.PAGE_DECLARATION_INVALID,
951
+ '声明未通过取数白名单:编译闸门未产出可复用的编译产物,无法核对接口白名单。'
952
+ + '这不是声明的问题,请检查 soma-core 产物是否陈旧(npm run build:precompile / build:core-dist)后重试。',
953
+ );
954
+ }
955
+ const unregistered = crossCheckDeclaredApis(gate.compiled.dataConfig);
842
956
  if (unregistered.length > 0) {
843
957
  throw new PageRegistryError(
844
958
  PageRegistryErrorCodes.PAGE_DECLARATION_INVALID,
@@ -846,7 +960,7 @@ export function normalizeDeclaration(declaration: unknown): PageRegistryDeclarat
846
960
  );
847
961
  }
848
962
 
849
- return normalized;
963
+ return { declaration: normalized, compiledPage: gate.compiled };
850
964
  }
851
965
 
852
966
  /** 声明总字节数:UTF-8 计,涵盖 declaration 的全部字符串字段 */