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
@@ -0,0 +1,46 @@
1
+ /**
2
+ * 产物层要用到的间距档(`--soma-space-<n>`)。
3
+ *
4
+ * 只列产物层的配方真正引用的那几档。**不是全阶梯**:抄一份 0–10 的完整阶梯
5
+ * 就成了第二份间距表,而第二份表的唯一命运是漂。
6
+ */
7
+ export declare const SOMA_ARTIFACT_SPACE_STEPS: readonly ["2", "3", "4", "5"];
8
+ export type SomaArtifactSpaceStep = typeof SOMA_ARTIFACT_SPACE_STEPS[number];
9
+ /**
10
+ * 一条具名原子类:root 与值段**都是闭集成员**,写不出闭集之外的组合。
11
+ *
12
+ * 为什么不写成 `{ root: string; value: string }`:那样一来
13
+ * `{ root: 'pad', value: '240px' }` 就是合法的 TypeScript,
14
+ * 而它要到发射那一步才被拦下——拦是拦住了,但"能写出来"意味着
15
+ * 代码里会长出拼字符串的路径,下一次重构就会有人绕过发射直接把它塞进 HTML。
16
+ */
17
+ export interface SomaArtifactUtility {
18
+ root: SomaArtifactSpaceRoot;
19
+ value: SomaArtifactSpaceStep;
20
+ }
21
+ /**
22
+ * 产物层今天只表达**间距**一族。
23
+ *
24
+ * 排列(`flow`)、对齐(`align`)、栅格(`cols`)这三族**有意不在这里**:
25
+ * 排列由二级求解的组 CSS 发(`display:flex` + `flex-direction` + `container-type`),
26
+ * 两边都发就是同一条声明有两个真源,而它们的特异度相同、胜负取决于两段 CSS 的
27
+ * 拼接顺序——改一句无关的代码就可能翻转视觉结果,且没有任何测试会红。
28
+ * 需要它们的那天,配方与词表一起扩,不是先把词汇摊在这里等着。
29
+ */
30
+ export declare const SOMA_ARTIFACT_SPACE_ROOTS: readonly ["pad", "pad-block", "pad-inline", "gap"];
31
+ export type SomaArtifactSpaceRoot = typeof SOMA_ARTIFACT_SPACE_ROOTS[number];
32
+ /**
33
+ * 具名值 → 候选串。**产物层唯一能造出类名的地方。**
34
+ *
35
+ * 文法与空间层的 `UTILITY_CANDIDATE_PATTERN` 同源:`soma-<root>-<值段>`。
36
+ * 这里不重复校验文法——闭集里的 root 与值段拼出来必然合法,
37
+ * 而真正的裁决在发射端(`emit-utility.ts`),两处各校一遍就是两份判据。
38
+ *
39
+ * **不带容器变体段**(`@cqLg`):产物层不产带变体的类——布局的档位差异由二级求解的
40
+ * 容器查询 CSS 表达,不由原子类表达。此前留着一个没有任何生产调用方传的 `variant`
41
+ * 参数"为了哪天需要",而没人走的参数也没人守:它拼出来的变体名不经任何闭集。
42
+ * 真要那天,变体名要以 `shared/container-breakpoints` 的档名为闭集入参,连同配方一起扩。
43
+ */
44
+ export declare function utilityClass(utility: SomaArtifactUtility): string;
45
+ /** 一组具名值 → 候选串数组,顺序即书写顺序(级联序由发射端按 utility.order 重排) */
46
+ export declare function utilityClasses(utilities: readonly SomaArtifactUtility[]): string[];
@@ -0,0 +1,206 @@
1
+ import type { SomaComponentContract, SomaComponentLayer } from '../../../shared/types/component-contract.types';
2
+ import { SomaOouiError } from '../diagnostics';
3
+ import type { SomaOouiIssue } from '../diagnostics';
4
+ import type { SomaCardinality, SomaControlModel, SomaDisplayVariant, SomaInteraction, SomaInteractionForm, SomaInteractionKind, SomaSource } from '../intent/intent.types';
5
+ import type { SomaTrace } from '../trace/trace.types';
6
+ export type { SomaCardinality, SomaControlModel, SomaDisplayVariant, SomaInteraction, SomaInteractionForm, SomaInteractionKind, SomaSource, };
7
+ /**
8
+ * 纯文本节点:**不是组件**。
9
+ *
10
+ * §36.1 裁定 2 定死了"不补通用 `Text` 原子件",`display` 形态按 variant 分派到
11
+ * 已有真实组件,而 `plain` 这一档的答案是"纯文本节点"。
12
+ * 那个答案必须在类型里有位置——否则候选表被迫写一个组件名,
13
+ * 而"随手编一个组件名"正是 `Text` 幽灵的成因(§36.3④)。
14
+ *
15
+ * 装配期对它**跳过契约存在性检查**,且它的 eventMap 必须为空(文本节点不 emit)。
16
+ *
17
+ * 真源在 `shared/ooui-declaration.ts`,这里只转口:产物层发射时也要按它分支,
18
+ * 而依赖闸门不许产物层回看本层(`SKIP-BACK`),此前那边只好写两处 `'#text'` 字面量。
19
+ */
20
+ export { SOMA_TEXT_NODE } from '../../../shared/ooui-declaration';
21
+ /**
22
+ * 组件契约的**最小视图**:构件层只需要名字、层、prop 名与 emit 名。
23
+ *
24
+ * 为什么收窄而不是直接吃 `SomaComponentContract`:构件层要能被喂一份"手搓的两行夹具"
25
+ * 来单测(§18.3 每层独立可测),而完整契约有二十多个必填/可选段。
26
+ * `SomaComponentContract` 结构上可赋值给它(见 `contractView()`),所以没有第二份真源。
27
+ */
28
+ export interface SomaComponentContractView {
29
+ readonly name: string;
30
+ readonly layer: SomaComponentLayer;
31
+ /** prop 名集合。顺序无意义 */
32
+ readonly props: readonly string[];
33
+ /** emit 名集合。**eventMap 的键必须逐个落在这里面** */
34
+ readonly emits: readonly string[];
35
+ }
36
+ /** 把仓库的真契约收窄成构件层视图。唯一的转换点,不要在调用处自己摊 */
37
+ export declare function contractView(contract: SomaComponentContract): SomaComponentContractView;
38
+ /**
39
+ * 一个 emit 可以同时承担多个语义事件。
40
+ *
41
+ * 架构 §16.3 写的是 `Record<string, SomaInteractionKind>`(一对一)。
42
+ * **实测放宽为一对多**,理由是同一次 emit 在不同上下文里确实是两件事:
43
+ * `SegmentedControl.change` 作为表单字段是一次 `change`,
44
+ * 作为 `select` 动词的载体是一次 `pick`。一对一会逼着候选表按上下文分叉成两条,
45
+ * **而那两条会各自漂**——正是本层要防的双写。
46
+ */
47
+ export type SomaEventMapValue = SomaInteractionKind | readonly SomaInteractionKind[];
48
+ /**
49
+ * 候选表条目:**词表作者手写的那一份**(由组件库注册进来,core 不内建)。
50
+ *
51
+ * 注意它**没有** `controlModel`、没有 `layer`、没有 `bind`:
52
+ * 前两者从契约推(人写得进来就会漂),`bind` 属产物层的数据绑定,
53
+ * 不在选择算法的输入里——架构 §3.3 把 `bind` 画在同一个接口上,
54
+ * 那会让候选表同时承担"选谁"与"怎么传参"两件事:前者要能被闸门**静态**核对,
55
+ * 后者要跑起来才知道对不对,混在一起时闸门只能核对一半,而"核对了一半"
56
+ * 与"全核对过了"在绿色的 CI 里长得一样。
57
+ */
58
+ export interface SomaComponentCandidateInput {
59
+ form: SomaInteractionForm;
60
+ /** 契约名(PascalCase),或 `SOMA_TEXT_NODE` */
61
+ component: string;
62
+ /** 适用条件;缺省即"不挑" */
63
+ when?: {
64
+ /** 命中这些基数才可用;缺省即全基数 */
65
+ cardinality?: readonly SomaCardinality[];
66
+ /** 该组件要求的最小可用宽(rem)。缺省 0 */
67
+ minInline?: number;
68
+ /** true=只用于可写场景,false=只用于只读;缺省即两可 */
69
+ mutable?: boolean;
70
+ /** `display` 形态按 variant 分派(§36.1 裁定 2);缺省即不挑 variant */
71
+ variant?: readonly SomaDisplayVariant[];
72
+ };
73
+ /** 组件 emit 名 → 语义事件名。**键必须真实存在于契约的 emits 里** */
74
+ eventMap?: Readonly<Record<string, SomaEventMapValue>>;
75
+ /** 同形态多候选时的偏好序,**小者优先**。同形态内不得重复 */
76
+ preference: number;
77
+ src?: SomaSource;
78
+ }
79
+ /** 一份候选词表:组件库(soma-ui / 第三方包)交给 core 的候选集 */
80
+ export interface SomaCompositionVocabulary {
81
+ /** 词表名,小写字母/数字/连字符。冲突消息里点的就是它 */
82
+ name: string;
83
+ version?: string;
84
+ candidates: readonly SomaComponentCandidateInput[];
85
+ }
86
+ /** 装配后的候选:`controlModel` / `layer` / `semanticEvents` 全部是**推出来的**,不可手写 */
87
+ export interface SomaComponentCandidate {
88
+ readonly form: SomaInteractionForm;
89
+ readonly component: string;
90
+ readonly vocabulary: string;
91
+ readonly layer: SomaComponentLayer | 'text-node';
92
+ readonly controlModel: SomaControlModel;
93
+ /** 判定依据的人话版本,进 trace 与错误消息 */
94
+ readonly controlModelReason: string;
95
+ readonly when: {
96
+ readonly cardinality?: readonly SomaCardinality[];
97
+ readonly minInline: number;
98
+ readonly mutable?: boolean;
99
+ readonly variant?: readonly SomaDisplayVariant[];
100
+ };
101
+ /** 归一成数组后的映射:emit 名 → 语义事件们 */
102
+ readonly eventMap: Readonly<Record<string, readonly SomaInteractionKind[]>>;
103
+ /** eventMap 值的并集(升序去重),选择算法按它判覆盖 */
104
+ readonly semanticEvents: readonly SomaInteractionKind[];
105
+ /** 契约有、eventMap 没接的 emit(升序)。§16.5③:告警不阻断 */
106
+ readonly unmappedEmits: readonly string[];
107
+ readonly preference: number;
108
+ readonly src?: SomaSource;
109
+ }
110
+ /**
111
+ * 注册表的**结构最小面**:选择算法只需要"某形态有哪些候选"与"有候选的形态有哪些"。
112
+ *
113
+ * 为什么收窄:选择算法要能被喂一份手搓的两条候选来单测(§18.3 每层独立可测)。
114
+ * 让 `select.ts` 直接吃 `registry.ts` 的完整接口,等于把"装配"与"选择"焊死——
115
+ * 而这两件事的失败模式完全不同(前者装配期、后者编译期),焊死之后
116
+ * 单测里造的那份注册表复现不出真实调用,测试却依然全绿。
117
+ */
118
+ export interface SomaCandidateRegistryLike {
119
+ /** 有候选的形态,按封闭集序。错误消息要报得出"当前有候选的形态" */
120
+ readonly forms: readonly SomaInteractionForm[];
121
+ candidatesFor(form: SomaInteractionForm): readonly SomaComponentCandidate[];
122
+ }
123
+ /** 逐候选的裁决结果:合格与否,以及**为什么不合格**(错误消息要能直接抄) */
124
+ export interface SomaCandidateVerdict {
125
+ readonly component: string;
126
+ readonly ok: boolean;
127
+ /** 不合格的原因,人话,可多条 */
128
+ readonly issues: readonly string[];
129
+ /** 在**这个候选自己的控制模型**下仍然缺的语义事件 */
130
+ readonly missing: readonly SomaInteractionKind[];
131
+ }
132
+ /** 选择结果 */
133
+ export interface SomaCompositionChoice {
134
+ readonly form: SomaInteractionForm;
135
+ readonly component: string;
136
+ readonly layer: SomaComponentLayer | 'text-node';
137
+ readonly controlModel: SomaControlModel;
138
+ readonly controlModelReason: string;
139
+ /** 事件路由:组件 emit → 语义事件(§16.3 的三跳上行由本层接线) */
140
+ readonly eventRoutes: readonly {
141
+ readonly emit: string;
142
+ readonly kinds: readonly SomaInteractionKind[];
143
+ }[];
144
+ /** 契约有、没接线的 emit:告警面,不阻断(§16.5③) */
145
+ readonly unmappedEmits: readonly string[];
146
+ /** 全部候选的逐条裁决,含被淘汰者的原因。trace 与诊断按它解释"为什么是这个组件" */
147
+ readonly considered: readonly SomaCandidateVerdict[];
148
+ readonly candidate: SomaComponentCandidate;
149
+ }
150
+ /**
151
+ * 构件层的一条问题记录。**已不再是独立定义**:它就是横切层的 `SomaOouiIssue`。
152
+ *
153
+ * 此前是一份与 `SomaSemanticIssue` 字段逐字相同、只多了 `readonly` 的抄本。
154
+ * 结构类型下两份互相可赋值,**漂开之前没有任何东西会红**——
155
+ * 收敛的理由与 `SomaSource` 那次(§36.3②)一模一样,见
156
+ * `../diagnostics/issue.types.ts` 的头注释。
157
+ */
158
+ export type SomaCompositionIssue = SomaOouiIssue;
159
+ export type SomaCompositionErrorLayer = 'assembly' | 'composition';
160
+ /**
161
+ * 构件层错误:装配期(候选词表)与编译期(选择)共用。
162
+ *
163
+ * **已收敛为横切层 `SomaOouiError` 的窄化子类**(架构 §20.1)。
164
+ * 此前它自己复写了一遍 message 拼装,与空间层的 `SomaSpatialError` 逐字相同——
165
+ * 两份拼装不会一起坏,只会一份一份地漂,而漂的表现是同一次编译里
166
+ * 两层错误的抬头不一样,按行首切段的下游(soma-ai 自修复提示词)切出来的
167
+ * 仍然是合法文本,没有断言会红。
168
+ *
169
+ * 子类只保留两件事:`name`(既有的 `instanceof` / 错误名断言按它读)
170
+ * 与窄化的 `layer`(本层只可能是这两个值,宽成六层等于让类型不再拦错值)。
171
+ *
172
+ * `code` 是公开契约(§20.2,全量登记在 `../diagnostics/codes.ts`),
173
+ * `remedy` 是硬要求——错误必须回答"我该改哪一行"。
174
+ */
175
+ export declare class SomaCompositionError extends SomaOouiError {
176
+ readonly layer: SomaCompositionErrorLayer;
177
+ constructor(input: {
178
+ layer: SomaCompositionErrorLayer;
179
+ code: string;
180
+ situation: string;
181
+ problem: string;
182
+ remedy: string;
183
+ issues?: readonly SomaCompositionIssue[];
184
+ src?: SomaSource;
185
+ });
186
+ }
187
+ /** `compositionTrace` 的环境:本次是按多宽裁定的、挂在哪条链下 */
188
+ export interface SomaCompositionTraceOptions {
189
+ readonly parent?: SomaTrace;
190
+ /** 本次裁定用的可用行内宽(rem)。**不给就不说** —— 见 `caveat` 的注释 */
191
+ readonly availRem?: number;
192
+ /** 结论落在哪个节点路径上(如 `detail.amount`) */
193
+ readonly path?: string;
194
+ }
195
+ /**
196
+ * 把一次构件选择翻成 trace(架构 §5 链条的第 ③ 跳)。
197
+ *
198
+ * `caveat` 是**铁律四**(编译期决策对运行时可变量取保守边界)的可读形态:
199
+ * 组件是按"这一档的可用宽"选的,而可用宽在运行时会变。
200
+ * 没有这一行的话,"这次成立"与"永远成立"在报告里长得一模一样——
201
+ * 而窄档下组件塞不进去**在浏览器里不报错**,只是挤成一团。
202
+ *
203
+ * `availRem` 缺席时 caveat 只说"窄于 X 时本候选不再合格",**不编一个宽度出来**:
204
+ * 报告里一个来路不明的数字比没有数字更坏,读者会拿它去调声明。
205
+ */
206
+ export declare function compositionTrace(choice: SomaCompositionChoice, options?: SomaCompositionTraceOptions): SomaTrace;
@@ -0,0 +1,37 @@
1
+ import type { SomaComponentContractView, SomaControlModel } from './candidate.types';
2
+ /**
3
+ * 端点 prop 的形状:`api` 或 `<前缀>_api`。
4
+ *
5
+ * 收得这么紧是有意的:放开成 `/api/i` 会把 `api_hint`、`legacy_api_note`
6
+ * 这类文案 prop 也算进来,而多算一个的后果是把某个受控组件判成自治型——
7
+ * 那正是上面第二种静默坏法。
8
+ */
9
+ export declare const ENDPOINT_PROP_PATTERN: RegExp;
10
+ /** 受控型的标志 prop:页面持有值 */
11
+ export declare const CONTROLLED_VALUE_PROP = "values";
12
+ export interface SomaControlModelVerdict {
13
+ readonly model: SomaControlModel;
14
+ /** 判定依据的人话版本,进 trace 与错误消息 */
15
+ readonly reason: string;
16
+ /** 触发判定的 prop 名;③ 号分支为 undefined */
17
+ readonly signal?: string;
18
+ }
19
+ /**
20
+ * 从契约推控制模型。**纯函数,唯一判定入口**——别在调用点自己看 prop。
21
+ */
22
+ export declare function deriveControlModel(view: SomaComponentContractView): SomaControlModelVerdict;
23
+ /**
24
+ * 判据自检探针:**已知答案的真实组件**。
25
+ *
26
+ * 判据本身是一段 if-else,改坏了不会有任何测试自然变红——它只会让某个形态
27
+ * 悄悄换一个首选组件。所以判据必须自带一组"答案写在架构文档里"的样本,
28
+ * 在 soma-ui 侧对着**真 catalog** 跑(core 拿不到 soma-ui,方向是单向的)。
29
+ *
30
+ * 名单**只增不减**:新增一个自治型 solution 就在这里补一条,
31
+ * 顺带被迫回答"它凭什么是自治型"。
32
+ */
33
+ export declare const SOMA_CONTROL_MODEL_PROBES: readonly {
34
+ readonly component: string;
35
+ readonly expect: SomaControlModel;
36
+ readonly why: string;
37
+ }[];
@@ -0,0 +1,66 @@
1
+ import { type SomaCandidateRegistryLike, type SomaCandidateVerdict, type SomaComponentCandidate, type SomaComponentContractView, type SomaCompositionIssue, type SomaCompositionVocabulary } from './candidate.types';
2
+ import { type SomaInteractionForm } from '../intent/intent.types';
3
+ /** 词表标识:小写字母/数字/连字符。冲突报错与来源登记都用它 */
4
+ export declare const COMPOSITION_VOCABULARY_NAME_PATTERN: RegExp;
5
+ /** 契约名形状:PascalCase。与 `SomaComponentContract.name` 同一条规则 */
6
+ export declare const CANDIDATE_COMPONENT_PATTERN: RegExp;
7
+ /** 一个形态的覆盖情况。`count === 0` 就是 §36.2③ 说的"形态空洞" */
8
+ export interface SomaFormCoverage {
9
+ readonly form: SomaInteractionForm;
10
+ readonly count: number;
11
+ /**
12
+ * 是不是页面级形态:**非标量形态**即页面级。
13
+ *
14
+ * 这条分组不是装饰:CLAUDE.md 明令"新页面只允许编排 solution/page 业务组件",
15
+ * 而这条纪律只对页面级形态成立——`text-entry` 选中的 `TextInput` 是 atom,
16
+ * 但它渲染在 `FormConsole` 内部,不是页面直接编排的东西(§34.4③ 把这两件事
17
+ * 混成了一条缺口)。分组之后闸门才判得清"这条违纪"与"这条本来就该是 atom"。
18
+ *
19
+ * 判据取自意图层的 `SOMA_SCALAR_FORMS`(取反),**不在本层重列一份形态名单**:
20
+ * 重列的那份会在形态扩表时漏掉新词,而漏掉的表现只是"某个新形态没被纪律管住"。
21
+ */
22
+ readonly pageLevel: boolean;
23
+ /** 候选组件名,按 preference 序 */
24
+ readonly components: readonly string[];
25
+ }
26
+ export interface SomaCandidateRegistry extends SomaCandidateRegistryLike {
27
+ /** 全部候选,按 (form 封闭集序, preference 升序) 稳定排列 */
28
+ readonly candidates: readonly SomaComponentCandidate[];
29
+ /** 有候选的形态,按封闭集序 */
30
+ readonly forms: readonly SomaInteractionForm[];
31
+ readonly vocabularies: readonly {
32
+ readonly name: string;
33
+ readonly version?: string;
34
+ readonly count: number;
35
+ }[];
36
+ /** 某形态的候选,已按 preference 升序。**空数组是合法返回值**——由选择算法决定怎么红 */
37
+ candidatesFor(form: SomaInteractionForm): readonly SomaComponentCandidate[];
38
+ /** 十九种形态的覆盖全景(含零候选的那些),闸门与诊断报告按它出数 */
39
+ coverage(): readonly SomaFormCoverage[];
40
+ }
41
+ interface ComposeOptions {
42
+ /** 组件契约视图。**必填**:控制模型与幽灵 emit 都从它推,缺了这道对账就是空转 */
43
+ readonly contracts: readonly SomaComponentContractView[];
44
+ }
45
+ /**
46
+ * 逐条对账候选词表,返回 `issues[]`(空数组即通过)。**不抛**——
47
+ * 照 `verifyTypeTable` 的先例,让调用方决定措辞与位置。
48
+ */
49
+ export declare function verifyComponentCandidates(vocabularies: readonly SomaCompositionVocabulary[], options: ComposeOptions): SomaCompositionIssue[];
50
+ /**
51
+ * 装配候选词表。对账不过**当场抛**——构件层的错误必须在编译期发作,
52
+ * 不能留到"页面点了没反应"那一刻(§3.3 失败模式)。
53
+ */
54
+ export declare function composeComponentCandidates(vocabularies: readonly SomaCompositionVocabulary[], options: ComposeOptions): SomaCandidateRegistry;
55
+ export type { SomaCandidateVerdict };
56
+ /**
57
+ * 上游契约自检:语义事件封闭集必须**恰好**被"受控/自治"两族划分。
58
+ *
59
+ * `OOUI-CMP-EVENT-FAMILY` 那道检查完全建立在这个划分上。意图层若给封闭集加了一个词
60
+ * 却忘了归族,本层的族判定会静默地"两族都查不到 ⇒ 两边都不报",
61
+ * 于是一条接错族的映射被放行——而接错族的后果是提交两次或一次都不提交,都不抛异常。
62
+ * 所以划分本身必须先被断言一次,再拿它去判别人。
63
+ *
64
+ * 返回问题列表(空数组即通过),由测试与闸门调用。
65
+ */
66
+ export declare function verifyInteractionKindPartition(): string[];
@@ -0,0 +1,63 @@
1
+ import { type SomaCandidateRegistryLike, type SomaCandidateVerdict, type SomaComponentCandidate, type SomaCompositionChoice } from './candidate.types';
2
+ import type { SomaCardinality, SomaControlModel, SomaDisplayVariant, SomaInteractionForm, SomaInteractionKind, SomaIntent, SomaSource } from '../intent/intent.types';
3
+ /**
4
+ * 一次选择请求。
5
+ *
6
+ * 字段是 `SomaIntent`(意图层产物)的**子集**,`SomaIntent` 结构上可直接赋值给它——
7
+ * 因此本层既能吃真产物,也能吃单测里手搓的三行夹具(§18.3 每层独立可测),
8
+ * 而两者走的是同一条代码路径。
9
+ */
10
+ export interface SomaCompositionRequest {
11
+ readonly form: SomaInteractionForm;
12
+ /** `display` 形态的呈现细分(§36.1 裁定 2);其余形态恒 undefined */
13
+ readonly variant?: SomaDisplayVariant;
14
+ readonly cardinality?: SomaCardinality;
15
+ readonly mutable?: boolean;
16
+ /**
17
+ * 这次交互会发生哪些事,以及每一件在**哪些控制模型下是必需的**。
18
+ *
19
+ * 只读 `kind` 与 `requiredFor` 两个字段:`payload` / `requiresGrant` / `enabledBy`
20
+ * 是产物层与授权闸门的事,选组件时用不上——多读一个字段就多一处会漂的耦合。
21
+ */
22
+ readonly interactions?: readonly {
23
+ readonly kind: SomaInteractionKind;
24
+ readonly requiredFor: readonly SomaControlModel[];
25
+ }[];
26
+ /**
27
+ * 本次可用的行内宽(rem)。省略 = 不限宽。
28
+ *
29
+ * **省略是有风险的**:`minInline` 是唯一挡得住"组件塞不进去"的东西,
30
+ * 而塞不进去在浏览器里不报错。字段级形态由容器负责分配,省略是安全的;
31
+ * 页面级形态请把档位宽度传进来。
32
+ */
33
+ readonly availableInline?: number;
34
+ readonly src?: SomaSource;
35
+ }
36
+ /**
37
+ * 意图产物 → 选择请求。**唯一的转换点**,不要在调用处自己摊字段:
38
+ * 摊字段的地方多了,某次意图层加字段时总有一处会漏,而漏掉不会红。
39
+ */
40
+ export declare function compositionRequestFromIntent(intent: SomaIntent, availableInline?: number): SomaCompositionRequest;
41
+ /**
42
+ * 这个候选在**它自己的控制模型**下,必须满足哪些语义事件。
43
+ *
44
+ * 这一行就是 §35 那条修正的全部内容:判据不再按动词一刀切,
45
+ * 而是问"对你这种控制模型,这件事必需吗"。
46
+ */
47
+ export declare function requiredKindsFor(request: SomaCompositionRequest, controlModel: SomaControlModel): SomaInteractionKind[];
48
+ /**
49
+ * 逐候选裁决,**不抛**。诊断报告与测试按它解释"为什么是这个组件"。
50
+ * 返回顺序即候选的偏好序(preference 升序)。
51
+ */
52
+ export declare function explainCandidates(request: SomaCompositionRequest, candidates: readonly SomaComponentCandidate[]): SomaCandidateVerdict[];
53
+ /**
54
+ * 形态 → 具体组件 + 事件接线。**选不出来就抛**,绝不降级到兜底候选。
55
+ *
56
+ * 排序:合格者按 `preference` 升序;同分在装配期已被拒(`OOUI-CMP-PREFERENCE-CLASH`),
57
+ * 故这里不需要第二关键字兜底——**顺序是设计决定,不是数组顺序**。
58
+ *
59
+ * §35.3「候选选择应当优先自治型」由词表把自治型的 preference 写小来兑现,
60
+ * **不由本文件按控制模型偷偷加权**:偷偷加权会让候选表里写的顺序与实际生效的顺序
61
+ * 不一致,而那种不一致查起来最贵——两处都"看着对",只有产物是错的。
62
+ */
63
+ export declare function selectComponent(request: SomaCompositionRequest, registry: SomaCandidateRegistryLike): SomaCompositionChoice;
@@ -0,0 +1,28 @@
1
+ import type { SomaOouiErrorLayer } from './issue.types';
2
+ /** 错误码前缀 → 层(架构 §20.2 的对照表,可执行化) */
3
+ export declare const SOMA_OOUI_CODE_PREFIXES: Readonly<Record<string, SomaOouiErrorLayer>>;
4
+ /** 错误码的字面文法。**登记与使用都按它校**,写错一个字母不会静默通过 */
5
+ export declare const SOMA_OOUI_CODE_PATTERN: RegExp;
6
+ /** 抛出这个码的阶段:`assembly` = 宿主启动装配一次;`compile` = 每次演绎 */
7
+ export type SomaOouiCodePhase = 'assembly' | 'compile';
8
+ export interface SomaOouiCodeSpec {
9
+ /** 稳定错误码。公开契约 */
10
+ readonly code: string;
11
+ /** 前缀对应的层(由 `SOMA_OOUI_CODE_PREFIXES` 决定,登记时冗余写出以便阅读) */
12
+ readonly layer: SomaOouiErrorLayer;
13
+ readonly phase: SomaOouiCodePhase;
14
+ /** 一句话:什么情况下会红 */
15
+ readonly meaning: string;
16
+ /** 抛出点(相对 soma-core 根)。两处 = 同一份声明被两层各拦一次 */
17
+ readonly raisedIn: readonly string[];
18
+ /** 前缀与抛出阶段不一致的存量。**只减不增**,见文件头注释 */
19
+ readonly prefixDrift?: true;
20
+ }
21
+ /**
22
+ * 全部错误码。**新增码必须先进这张表**,否则闸门当场红。
23
+ *
24
+ * 排序:按前缀分组,组内按码字典序——两个人同时加码时冲突落在相邻行,一眼可见。
25
+ */
26
+ export declare const SOMA_OOUI_ERROR_CODES: readonly SomaOouiCodeSpec[];
27
+ /** 码 → 前缀声明的层。前缀不合法时返回 undefined */
28
+ export declare function layerOfSomaOouiCode(code: string): SomaOouiErrorLayer | undefined;
@@ -0,0 +1,135 @@
1
+ import { formatOouiIssue, formatOouiIssues } from './format';
2
+ import type { SomaOouiErrorLayer, SomaOouiIssue } from './issue.types';
3
+ import type { SomaSource } from '../trace/source.types';
4
+ import type { SomaTrace } from '../trace/trace.types';
5
+ export interface SomaOouiErrorInput {
6
+ /** 出错的层/阶段。**是发现它的那一层**;错误码前缀说的是被违反的是谁的契约 */
7
+ readonly layer: SomaOouiErrorLayer;
8
+ /** 稳定错误码(`./codes.ts` 登记的公开契约) */
9
+ readonly code: string;
10
+ /** 现状:发生了什么、涉及谁 */
11
+ readonly situation: string;
12
+ /** 问题:为什么这不能放行 */
13
+ readonly problem: string;
14
+ /** 建议:能直接抄的修法 */
15
+ readonly remedy: string;
16
+ /** 指回声明位置 */
17
+ readonly src?: SomaSource;
18
+ /**
19
+ * 到失败点为止的推导链(架构 §20.1 的 `trace: SomaTrace[]`)。
20
+ *
21
+ * 此前取 `readonly unknown[]`,因为 trace 层当时只有 `source.types.ts`。
22
+ * `SomaTrace` 落地后按那条注释的交代**只改这一行**收窄成它——
23
+ * `unknown[]` 收得下任何东西,于是"诊断带着一条解释不了自己的链"
24
+ * 与"诊断带着一条真链"在编译期长得一模一样,而下游(soma-ai 自修复回路)
25
+ * 正是照着这条链决定改哪一行的。
26
+ *
27
+ * 下游消费者 `compile-gate.ts` 的 `SomaCompileDiagnostic.trace` 仍是
28
+ * `readonly unknown[]`(它是跨包的公开诊断形状,不该随引擎内部类型收紧),
29
+ * `readonly SomaTrace[]` 赋给它天然成立,两边不必同时改。
30
+ *
31
+ * 必须**原样可 JSON 序列化**:compile-gate 会 `JSON.parse(JSON.stringify(trace))`,
32
+ * 带函数或循环引用时它会静默丢掉整条链(它宁可丢 trace 也不让诊断本身变成新失败面)。
33
+ * `SomaTrace` 是纯数据,`parent` 构成链不构成环——成环由 `traceDefects` 点名。
34
+ */
35
+ readonly trace?: readonly SomaTrace[];
36
+ /** 批量场景下的逐条诊断(如装配对账一次列全) */
37
+ readonly issues?: readonly SomaOouiIssue[];
38
+ }
39
+ /**
40
+ * ooui 六层统一错误(架构 §20.1)。
41
+ *
42
+ * 五个字段全是硬要求:
43
+ * · `layer` —— 发现它的层/阶段;
44
+ * · `code` —— 稳定错误码,**公开契约**,进 external-docs,不随重构变化(§20.2);
45
+ * · `src` —— 指回声明位置,回答"我该改哪一行";
46
+ * · `trace` —— 到失败点为止的推导链,回答"它是怎么推到这一步的";
47
+ * · `remedy` —— **可操作的修法,不是现象描述**。
48
+ *
49
+ * `remedy` 的判据(照 `composeComponentPacks` 的重名拒收消息与
50
+ * `verify-log-prefix.mjs` 的可粘贴输出):读者不必再查任何文档或源码,
51
+ * 就能把这段话里的东西直接粘进声明。低代码报"渲染失败",这里报
52
+ * "`comparison` 形态无可用候选,已检查 soma-ui 的 3 个候选;请注册候选或改用 `browse`"。
53
+ */
54
+ export declare class SomaOouiError extends Error {
55
+ readonly layer: SomaOouiErrorLayer;
56
+ readonly code: string;
57
+ readonly situation: string;
58
+ readonly problem: string;
59
+ readonly remedy: string;
60
+ readonly src?: SomaSource;
61
+ readonly trace: readonly SomaTrace[];
62
+ readonly issues: readonly SomaOouiIssue[];
63
+ constructor(input: SomaOouiErrorInput);
64
+ /**
65
+ * 补上到失败点为止的推导链(REQ-014 §38.5 断线 ③)。
66
+ *
67
+ * ── 为什么不是构造参数 ───────────────────────────────────────────
68
+ * `trace` 从设计之日起就在构造参数里,而**全仓 17 个抛出点没有一个传它**——
69
+ * 于是所有 ooui 错误的 `trace` 都是 `[]`,而 soma-ai 的自修复回路读的正是这条链。
70
+ * 那不是十七处疏忽:**抛的那一层手里没有链条**。
71
+ * 空间层求解失败时,它只知道自己收到的 IR;"这份 IR 是哪个动词、经哪条规则、
72
+ * 选中哪个组件推出来的"住在编排层。要让每一层都能传,就得把整条链
73
+ * 一路穿过五层的函数签名——而任何一层忘了透传都不报错,表现是
74
+ * "某一类错误没有 trace",与"这类错误本来就推不出链"分不开。
75
+ *
76
+ * 所以链条由**编排层**在 catch 里补:它是唯一同时看得见五层产物的地方。
77
+ *
78
+ * ── 为什么只补一次,且不覆盖已有的链 ──────────────────────────────
79
+ * 内层若已经带了链,它知道的比外层多(外层只到调用那一步为止)。
80
+ * 覆盖会把更深的那段换成更浅的一段,而两段都"看起来像一条完整的链"。
81
+ * 所以已有非空链时本方法什么都不做。
82
+ *
83
+ * 返回 `this`(不是新对象):换个实例会丢掉子类身份,
84
+ * 而 `instanceof SomaSpatialError` 失手的表现是 catch 分支整段被跳过。
85
+ */
86
+ attachTrace(trace: readonly SomaTrace[]): this;
87
+ /** 转成一条诊断(闸门要的是数据,不是异常) */
88
+ toIssue(path?: string): SomaOouiIssue;
89
+ }
90
+ /**
91
+ * 唯一的 message 拼装点。
92
+ *
93
+ * 形状与既有的 `SomaSpatialError` / `SomaCompositionError` **逐字一致**——
94
+ * 收敛不是改版:既有测试按 `spatial.message` 里的子串断言,改一个字都会红,
95
+ * 而"红了就跟着调断言"正是让格式慢慢漂开的那条路。
96
+ */
97
+ export declare function formatOouiErrorMessage(input: SomaOouiErrorInput): string;
98
+ export interface FoldOouiIssuesInput {
99
+ /** 发现它的层 */
100
+ readonly layer: SomaOouiErrorLayer;
101
+ /** 这一批问题的抬头,如「语义声明不合法」。「共 N 条」与逐条正文由本函数统一拼 */
102
+ readonly headline: string;
103
+ readonly issues: readonly SomaOouiIssue[];
104
+ /** 整批的声明位置(逐条的位置在各条 issue 自己身上) */
105
+ readonly src: SomaSource;
106
+ /** 到失败点为止的推导链。为空时不挂——编一条链上去等于说"它是这么推到这一步的" */
107
+ readonly trace?: readonly SomaTrace[];
108
+ /**
109
+ * 清单为空时的码与"问题"。
110
+ *
111
+ * 正常路径上折叠只发生在"有问题"之后,这一项只防调用方哪天在空清单上调用——
112
+ * 那时交出去的仍然是一条带登记码的三段式错误,而不是 `code: undefined`。
113
+ * 不给的调用方等于声明"我这里不可能是空清单",真空了当场抛内部错误。
114
+ */
115
+ readonly fallback?: {
116
+ readonly code: string;
117
+ readonly problem: string;
118
+ };
119
+ }
120
+ /**
121
+ * 把某一层"返回 issues 而不抛"的一批问题折叠成一个错误。**唯一的折叠口径。**
122
+ *
123
+ * 此前编排层(`aggregate`)、页面组合层(`assertPageComposition`)、表层入口
124
+ * (`expandPageSurface`)各折叠一遍,措辞已经漂开(「共 N 条:」与「有 N 条问题:」、
125
+ * 「上面每一段」与「每一段」、全角与半角逗号)。三份单看都对,
126
+ * 只是同一次编译里三种错误的抬头长得不一样,而按行首切段的下游切出来的仍是合法文本。
127
+ *
128
+ * 口径三条,都是下游读法定的:
129
+ * · `code` 取**第一条**的码,不另造汇总码——发布闸门与 soma-ai 自修复读的是单数 `code`,
130
+ * 给汇总码等于让它查不到任何修法,而"查不到"与"这类错没有修法"在回路里长得一样;
131
+ * · `situation` 逐条列全,不挤牙膏;
132
+ * · 只有一条时 `remedy` 就是那一条的修法,多条时指回逐条的「建议」。
133
+ */
134
+ export declare function foldOouiIssues(input: FoldOouiIssuesInput): SomaOouiError;
135
+ export { formatOouiIssue, formatOouiIssues };
@@ -0,0 +1,51 @@
1
+ import type { SomaOouiIssue } from './issue.types';
2
+ /** 三段的固定抬头。**不要改字面量**:闸门与 soma-ai 提示词按它切段 */
3
+ export declare const SOMA_OOUI_SECTIONS: {
4
+ readonly situation: "现状:";
5
+ readonly problem: "问题:";
6
+ readonly remedy: "建议:";
7
+ readonly src: "声明处:";
8
+ };
9
+ export interface FormatOouiIssuesOptions {
10
+ /**
11
+ * 每条问题首行的缩进空格数,正文再缩进两格。
12
+ *
13
+ * 默认 2:与 `verify-ooui-dep-graph.mjs` / `verify-log-prefix.mjs` 等闸门的
14
+ * ` ✗ …` 输出对齐——终端里错误块与闸门抬头分得开。
15
+ * 外层已经缩过一次的调用点传 0,传值而不是各写各的。
16
+ */
17
+ readonly indent?: number;
18
+ /** 空清单时的占位文本。默认空串("没有问题"就该什么都不打印) */
19
+ readonly empty?: string;
20
+ }
21
+ /**
22
+ * 格一条诊断成三段式文本。
23
+ *
24
+ * 形状固定为:
25
+ * ```text
26
+ * ✗ [OOUI-SEM-VERB-UNKNOWN] request.verb
27
+ * 现状:…
28
+ * 问题:…
29
+ * 建议:…
30
+ * 声明处:page.yaml#ooui.detail
31
+ * ```
32
+ * `remedy` 里的多行缩进**原样保留**——那几行是给人抄的,重新缩进会把
33
+ * 可粘贴的 YAML 片段缩坏(粘进声明里就是错的缩进,而 YAML 错缩进不一定报错)。
34
+ */
35
+ export declare function formatOouiIssue(issue: SomaOouiIssue, options?: FormatOouiIssuesOptions): string;
36
+ /**
37
+ * 格一批诊断。条目之间空一行——挤在一起时人眼分不出第二条从哪里开始。
38
+ *
39
+ * **一次列全,不挤牙膏**:只报第一条会让作者改一条跑一次,
40
+ * 而每一次跑都要重编译整页;三条错误就是三轮,且第三轮才知道还有第四条。
41
+ */
42
+ export declare function formatOouiIssues(issues: readonly SomaOouiIssue[], options?: FormatOouiIssuesOptions): string;
43
+ /**
44
+ * 一个值的人话描述,进错误消息的「现状」段:要能看出"它到底是什么",不能只说"不合法"。
45
+ *
46
+ * 此前空间层、页面组合层、产物层各有一份私有的 `describe()`,输出已经三种样子
47
+ * (缺席 / undefined、`长度 3 的数组` / `数组(3 项)`、`“x”` / `"x"`)——
48
+ * 同一次编译里三层错误描述同一个坏值的措辞不一样,而下游自修复读的正是这一段。
49
+ * 标量把值一起带上(`number 5`):只说 `number` 的话,作者还得回去翻是哪个数。
50
+ */
51
+ export declare function describeOouiValue(value: unknown): string;