soma-core 1.4.2 → 1.5.1

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 (216) 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 +29 -10
  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/component-expander.ts +18 -3
  58. package/core/client/component/component-manager.ts +4 -0
  59. package/core/client/component/example-blocks.ts +1 -7
  60. package/core/client/component/theme-component-tokens.ts +12 -15
  61. package/core/client/component/verify-pack.ts +43 -0
  62. package/core/client/data/data-object-resolver.ts +27 -8
  63. package/core/client/diagnostics/telemetry-context.ts +0 -4
  64. package/core/client/engine/asset-resolver.ts +0 -1
  65. package/core/client/engine/event-engine.ts +7 -3
  66. package/core/client/engine/soma-bootstrap.ts +292 -34
  67. package/core/client/engine/style-binder.ts +0 -1
  68. package/core/client/infra/http/IHttpClient.ts +0 -6
  69. package/core/client/infra/http/SomaHttpService.ts +4 -1
  70. package/core/client/infra/notify/DomNotifyService.ts +1 -1
  71. package/core/client/infra/router/router-path.ts +0 -6
  72. package/core/client/parser/annotation-extractor.ts +1 -1
  73. package/core/client/parser/blocks/namespace.ts +30 -5
  74. package/core/client/parser/blocks/page-parser.ts +44 -1
  75. package/core/client/parser/blocks/use-parser.ts +266 -46
  76. package/core/client/parser/data-config-parser.ts +71 -3
  77. package/core/client/parser/layout-parser.ts +4 -3
  78. package/core/client/parser/reaction-parser.ts +0 -1
  79. package/core/client/parser/ui-config-parser.ts +212 -74
  80. package/core/client/theme/scene-tokens.ts +9 -3
  81. package/core/client/theme/theme-axes.ts +74 -16
  82. package/core/client/theme/theme-engine.ts +341 -70
  83. package/core/client/theme/tone-solver.ts +9 -8
  84. package/core/index.ts +24 -5
  85. package/core/server/api/load-host-service.ts +8 -2
  86. package/core/server/declaration-safety.ts +11 -0
  87. package/core/server/host/page-response-request.ts +0 -2
  88. package/core/server/host/published-page-artifact-cache.ts +244 -0
  89. package/core/server/host/published-page-assets.ts +44 -5
  90. package/core/server/mock/node/cli.mjs +0 -1
  91. package/core/server/mock/node/schema-generator.mjs +0 -1
  92. package/core/server/ooui.ts +34 -0
  93. package/core/server/page-assets.ts +8 -0
  94. package/core/server/page-declaration.ts +18 -0
  95. package/core/server/registry/asset-store.ts +327 -0
  96. package/core/server/registry/declaration-precompiler.ts +49 -6
  97. package/core/server/registry/index.ts +47 -1
  98. package/core/server/registry/page-registry-repository.ts +6 -2
  99. package/core/server/registry/page-registry-store.ts +133 -19
  100. package/core/server/registry/publish-asset-pin.ts +557 -0
  101. package/core/server/registry/services/pages/List.ts +15 -3
  102. package/core/server/registry/validation/compile-gate.ts +180 -8
  103. package/core/server/registry/validation/declaration-safety-scan.ts +113 -23
  104. package/core/shared/component/derive-sample.ts +201 -16
  105. package/core/shared/component/field-lines.ts +98 -8
  106. package/core/shared/container-breakpoints.ts +46 -0
  107. package/core/shared/object-semantics.ts +240 -0
  108. package/core/shared/ooui-declaration.ts +235 -0
  109. package/core/shared/types/component-contract.types.ts +7 -6
  110. package/core/shared/types/data-config.types.ts +95 -0
  111. package/core/shared/types/domain.types.ts +0 -24
  112. package/core/shared/types/engine.types.ts +0 -5
  113. package/core/shared/types/layout-constraint.types.ts +16 -0
  114. package/core/shared/types/ui-config.types.ts +163 -13
  115. package/dist/cli/soma.js +24 -11
  116. package/dist/core/index.cjs +1829 -1028
  117. package/dist/types/build/blocks/block-compile.d.ts +16 -1
  118. package/dist/types/build/blocks/migrate-flat.d.ts +17 -0
  119. package/dist/types/build/compiler/page-declaration-compiler.d.ts +46 -0
  120. package/dist/types/build/compiler/route-builder.d.ts +0 -1
  121. package/dist/types/build/component/component-graph.d.ts +17 -53
  122. package/dist/types/build/component/package-loader.d.ts +8 -1
  123. package/dist/types/build/layout/constraint-solver.d.ts +46 -4
  124. package/dist/types/build/ooui/artifact/artifact.types.d.ts +180 -0
  125. package/dist/types/build/ooui/artifact/emit-artifact.d.ts +58 -0
  126. package/dist/types/build/ooui/artifact/emit-html.d.ts +53 -0
  127. package/dist/types/build/ooui/artifact/index.d.ts +5 -0
  128. package/dist/types/build/ooui/artifact/spatial-tree.d.ts +48 -0
  129. package/dist/types/build/ooui/artifact/utility-class.d.ts +46 -0
  130. package/dist/types/build/ooui/composition/candidate.types.d.ts +206 -0
  131. package/dist/types/build/ooui/composition/control-model.d.ts +37 -0
  132. package/dist/types/build/ooui/composition/registry.d.ts +66 -0
  133. package/dist/types/build/ooui/composition/select.d.ts +63 -0
  134. package/dist/types/build/ooui/diagnostics/codes.d.ts +28 -0
  135. package/dist/types/build/ooui/diagnostics/error.d.ts +135 -0
  136. package/dist/types/build/ooui/diagnostics/format.d.ts +51 -0
  137. package/dist/types/build/ooui/diagnostics/index.d.ts +25 -0
  138. package/dist/types/build/ooui/diagnostics/issue.types.d.ts +56 -0
  139. package/dist/types/build/ooui/engine-slot.d.ts +41 -0
  140. package/dist/types/build/ooui/index.d.ts +286 -0
  141. package/dist/types/build/ooui/intent/derive-intent.d.ts +32 -0
  142. package/dist/types/build/ooui/intent/field-rules.d.ts +99 -0
  143. package/dist/types/build/ooui/intent/intent.types.d.ts +318 -0
  144. package/dist/types/build/ooui/intent/verb-events.d.ts +70 -0
  145. package/dist/types/build/ooui/page/budget.d.ts +28 -0
  146. package/dist/types/build/ooui/page/compose-page.d.ts +41 -0
  147. package/dist/types/build/ooui/page/index.d.ts +4 -0
  148. package/dist/types/build/ooui/page/page.types.d.ts +264 -0
  149. package/dist/types/build/ooui/page/region-row.d.ts +16 -0
  150. package/dist/types/build/ooui/semantic/expand-page-surface.d.ts +33 -0
  151. package/dist/types/build/ooui/semantic/kernel.types.d.ts +125 -0
  152. package/dist/types/build/ooui/semantic/normalize.d.ts +45 -0
  153. package/dist/types/build/ooui/semantic/origin.types.d.ts +95 -0
  154. package/dist/types/build/ooui/semantic/role-alias.d.ts +35 -0
  155. package/dist/types/build/ooui/semantic/shorthand.d.ts +60 -0
  156. package/dist/types/build/ooui/semantic/surface.types.d.ts +16 -0
  157. package/dist/types/build/ooui/semantic/validate-request.d.ts +19 -0
  158. package/dist/types/build/ooui/spatial/emit-utility.d.ts +43 -0
  159. package/dist/types/build/ooui/spatial/ir.types.d.ts +280 -0
  160. package/dist/types/build/ooui/spatial/registry.d.ts +110 -0
  161. package/dist/types/build/ooui/spatial/solve.d.ts +42 -0
  162. package/dist/types/build/ooui/spatial/utility.types.d.ts +191 -0
  163. package/dist/types/build/ooui/trace/index.d.ts +3 -0
  164. package/dist/types/build/ooui/trace/render.d.ts +42 -0
  165. package/dist/types/build/ooui/trace/source.types.d.ts +25 -0
  166. package/dist/types/build/ooui/trace/trace.types.d.ts +143 -0
  167. package/dist/types/client/component/component-expander.d.ts +1 -0
  168. package/dist/types/client/component/example-blocks.d.ts +0 -2
  169. package/dist/types/client/component/theme-component-tokens.d.ts +8 -5
  170. package/dist/types/client/data/data-object-resolver.d.ts +10 -2
  171. package/dist/types/client/diagnostics/telemetry-context.d.ts +0 -1
  172. package/dist/types/client/engine/soma-bootstrap.d.ts +123 -10
  173. package/dist/types/client/infra/http/IHttpClient.d.ts +0 -5
  174. package/dist/types/client/infra/http/SomaHttpService.d.ts +1 -1
  175. package/dist/types/client/infra/router/router-path.d.ts +0 -2
  176. package/dist/types/client/parser/blocks/namespace.d.ts +20 -0
  177. package/dist/types/client/parser/blocks/page-parser.d.ts +9 -0
  178. package/dist/types/client/parser/blocks/use-parser.d.ts +38 -4
  179. package/dist/types/client/parser/data-config-parser.d.ts +13 -0
  180. package/dist/types/client/parser/ui-config-parser.d.ts +1 -11
  181. package/dist/types/client/theme/scene-tokens.d.ts +9 -3
  182. package/dist/types/client/theme/theme-axes.d.ts +64 -1
  183. package/dist/types/client/theme/theme-engine.d.ts +13 -8
  184. package/dist/types/client/theme/tone-solver.d.ts +9 -5
  185. package/dist/types/index.d.ts +4 -6
  186. package/dist/types/server/declaration-safety.d.ts +7 -0
  187. package/dist/types/server/host/page-response-request.d.ts +0 -1
  188. package/dist/types/server/host/published-page-artifact-cache.d.ts +64 -0
  189. package/dist/types/server/ooui.d.ts +18 -0
  190. package/dist/types/server/page-assets.d.ts +7 -0
  191. package/dist/types/server/page-declaration.d.ts +14 -0
  192. package/dist/types/server/registry/asset-store.d.ts +112 -0
  193. package/dist/types/server/registry/declaration-precompiler.d.ts +23 -3
  194. package/dist/types/server/registry/index.d.ts +3 -1
  195. package/dist/types/server/registry/page-registry-store.d.ts +57 -4
  196. package/dist/types/server/registry/publish-asset-pin.d.ts +166 -0
  197. package/dist/types/server/registry/services/pages/List.d.ts +9 -3
  198. package/dist/types/server/registry/validation/compile-gate.d.ts +63 -0
  199. package/dist/types/shared/component/derive-sample.d.ts +14 -0
  200. package/dist/types/shared/container-breakpoints.d.ts +42 -0
  201. package/dist/types/shared/object-semantics.d.ts +42 -0
  202. package/dist/types/shared/ooui-declaration.d.ts +135 -0
  203. package/dist/types/shared/types/component-contract.types.d.ts +7 -6
  204. package/dist/types/shared/types/data-config.types.d.ts +86 -0
  205. package/dist/types/shared/types/domain.types.d.ts +0 -21
  206. package/dist/types/shared/types/engine.types.d.ts +0 -4
  207. package/dist/types/shared/types/layout-constraint.types.d.ts +1 -0
  208. package/dist/types/shared/types/ui-config.types.d.ts +157 -12
  209. package/next.config.js +106 -13
  210. package/package.json +29 -2
  211. package/core/client/host-bridge/index.ts +0 -27
  212. package/core/client/parser/yaml-loader.ts +0 -36
  213. package/core/shared/manifest/manifest-contract.ts +0 -12
  214. package/dist/types/client/host-bridge/index.d.ts +0 -9
  215. package/dist/types/client/parser/yaml-loader.d.ts +0 -21
  216. package/dist/types/shared/manifest/manifest-contract.d.ts +0 -4
@@ -0,0 +1,285 @@
1
+ // 意图层 ② · 动词 → 根形态 + 事件契约。§16.2 / §30.1 / §35.2 的可执行形态。
2
+ //
3
+ // ── 为什么这一层的失败模式是静默的 ─────────────────────────────────
4
+ // ① **事件表按动词一刀切**。这是 §35 挖出来的根因,也是本文件存在的理由:
5
+ // `edit: { required: ['change','submit'] }` 写下去的那天,
6
+ // 单测绿、矩阵绿、8 个动词全部有候选(§30.2)——**判据错了却全绿**,
7
+ // 因为验证用的候选表也是照同一套语汇手写的。
8
+ // 真相要到"唯一能零 Domain 闭环的 FormConsole 被自己的闸门刷掉"
9
+ // 这个反常现象出现,再往下挖一层才见到(§35.5)。
10
+ // 所以事件的"必需"必须写成**相对控制模型**的,不能写成绝对的。
11
+ //
12
+ // ② **必需事件与语义启用事件混成一张表**。§16.2 第一版把事件写成
13
+ // "动词**必然**产生",于是 `Card` / `LineChart` / `KpiBoard` 这类零 emit 的
14
+ // 纯展示件被判为不合格的 `inspect` / `monitor` 载体——**而它们是合法的**。
15
+ // §30.1 修正为"必需由动词本质决定,其余由对象语义启用"。
16
+ // 混在一起的表现不是报错,是"这个动词永远选不出候选",
17
+ // 而报出来的话指向的是构件层的候选表,不是这张事件表。
18
+ //
19
+ // ③ **动词 → 形态映射漂到封闭集之外**。原型 `full-matrix.mjs` 的
20
+ // `select: 'picker'` 就是这么来的(§34.3)。本文件的映射表用
21
+ // `SomaInteractionForm` 类型标注,漂移当场是编译错误。
22
+
23
+ import type { SomaObject, SomaVerb } from '../semantic/kernel.types';
24
+ import { SOMA_WRITE_VERBS } from '../semantic/kernel.types';
25
+ import type {
26
+ SomaCardinality,
27
+ SomaControlModel,
28
+ SomaInteraction,
29
+ SomaInteractionKind,
30
+ SomaInteractionPayloadType,
31
+ SomaIntentCapability,
32
+ SomaInteractionForm,
33
+ } from './intent.types';
34
+
35
+ /**
36
+ * 动词 → 根形态(§3.2 + §36.1 裁定 1)。
37
+ *
38
+ * 与原型 `full-matrix.mjs` 的唯一差别是 `select`:原型写 `picker`,
39
+ * 而 `picker` 不在封闭集里——**下拉还是分段是控件形态,属构件层**。
40
+ *
41
+ * `select` 恒取 `single-choice`:当前声明词汇里**没有任何一处能表达"选一个还是选多个"**
42
+ * (§17.2 说 `collection.selection.mode` 决定单选/多选,但仓库真实的
43
+ * `SomaWindowSelection` 只有 `base` / `toggled`,没有 `mode`——见本批 findings)。
44
+ * 铁律三是不猜测意图,所以这里不从 `select_all` 之类的默认值里编一个信号出来;
45
+ * 真要多选,走 `deriveIntent` 的逃生门显式指定 `form: 'multi-choice'`。
46
+ */
47
+ export const VERB_ROOT_FORM: Readonly<Record<SomaVerb, SomaInteractionForm>> = {
48
+ inspect: 'record-detail',
49
+ browse: 'record-list',
50
+ edit: 'form',
51
+ select: 'single-choice',
52
+ compare: 'comparison',
53
+ advance: 'progression',
54
+ navigate: 'hierarchy',
55
+ monitor: 'timeline',
56
+ };
57
+
58
+ /**
59
+ * 根形态的基数。`window` 段的有无是唯一的分叉:
60
+ * 声明了服务端窗口意味着"一屏一屏地取",总量前端不知道,故 `unbounded`。
61
+ */
62
+ export function rootCardinality(verb: SomaVerb, object: SomaObject): SomaCardinality {
63
+ const windowed = object.window !== undefined;
64
+ switch (verb) {
65
+ case 'inspect':
66
+ case 'edit':
67
+ case 'advance':
68
+ return 'one';
69
+ case 'compare':
70
+ return 'few';
71
+ case 'browse':
72
+ case 'select':
73
+ case 'navigate':
74
+ case 'monitor':
75
+ return windowed ? 'unbounded' : 'many';
76
+ default:
77
+ return 'one';
78
+ }
79
+ }
80
+
81
+ /** 事件载荷契约:一个事件必然携带什么。**唯一真源**,两处语汇都从这里取 */
82
+ const PAYLOADS: Readonly<Record<SomaInteractionKind, Readonly<Record<string, SomaInteractionPayloadType>>>> = {
83
+ // 受控语汇
84
+ change: { field: 'field-ref', value: 'value' },
85
+ submit: { object: 'object-ref' },
86
+ cancel: {},
87
+ validate: { field: 'field-ref', message: 'text' },
88
+ select: { ids: 'object-ref-list' },
89
+ open: { id: 'object-ref' },
90
+ sort: { patch: 'window-patch' },
91
+ filter: { patch: 'window-patch' },
92
+ page: { patch: 'window-patch' },
93
+ pick: { id: 'object-ref' },
94
+ search: { keyword: 'text' },
95
+ transition: { object: 'object-ref', to: 'text' },
96
+ action: { object: 'object-ref', action: 'text' },
97
+ traverse: { relation: 'text', id: 'object-ref' },
98
+ add: { id: 'object-ref' },
99
+ remove: { id: 'object-ref' },
100
+ range: { patch: 'window-patch' },
101
+ drill: { id: 'object-ref' },
102
+ // 自治语汇
103
+ loaded: { object: 'object-ref' },
104
+ submitted: { object: 'object-ref' },
105
+ error: { message: 'text' },
106
+ row_open: { id: 'object-ref' },
107
+ action_done: { object: 'object-ref', action: 'text' },
108
+ };
109
+
110
+ /**
111
+ * 需要宿主授权的事件(§16.4)。
112
+ *
113
+ * 判据是"这个事件一旦发生,服务端的数据就变了",不是"这个事件听起来像写"。
114
+ * `change` **不在**表里:受控件的 `change` 只改页面持有的 values,
115
+ * 落库要等 `submit`。把 `change` 算作写会让每一张受控表单都要求 `write` 端点,
116
+ * 连"填一半还没提交"都不许——那是把授权点定错了位置。
117
+ */
118
+ const GRANT_REQUIRED: ReadonlySet<SomaInteractionKind> = new Set<SomaInteractionKind>([
119
+ 'submit', 'submitted', 'transition', 'action', 'action_done',
120
+ ]);
121
+
122
+ /** 一个动词在某控制模型下的事件清单 */
123
+ interface VerbEventSpec {
124
+ required: readonly SomaInteractionKind[];
125
+ optional: readonly SomaInteractionKind[];
126
+ }
127
+
128
+ /**
129
+ * §35.2 的表:**必需事件按控制模型分**。
130
+ *
131
+ * 两列的语态不同不是风格差异,是控制模型的定义:
132
+ * 自治型只在事情做完后通知(过去式),它永远 emit 不出 `change`——
133
+ * 因为它根本不需要把中间状态抛给页面。
134
+ *
135
+ * 每一格的"必需"都要能回答同一个问题:**缺了它,这个动词还成立吗?**
136
+ * · browse/controlled 缺 `select`:不能选中就不是浏览 → 必需;
137
+ * · browse/autonomous 什么都不缺:自治型自己浏览、自己翻页,页面不需要知道 → 空;
138
+ * · edit/autonomous 缺 `submitted`:写完了却不通知宿主,页面上其他区域
139
+ * 永远停在旧数据上,而那是"看着正常"的一页 → 必需;
140
+ * · select 两列都要 `pick`:**这次交互的产物就是被选中的东西**,
141
+ * 自治型也必须把它交出去,否则选了等于没选;
142
+ * · navigate/autonomous 取 `row_open`:它是 `traverse` 的过去式,
143
+ * 且是 catalog 里 `QueryConsole` 真实 emit 的名字(不是编出来的词)。
144
+ */
145
+ export const VERB_EVENTS_BY_MODEL: Readonly<Record<SomaVerb, Readonly<Record<SomaControlModel, VerbEventSpec>>>> = {
146
+ inspect: {
147
+ controlled: { required: [], optional: ['action'] },
148
+ autonomous: { required: [], optional: ['loaded', 'action_done', 'error'] },
149
+ },
150
+ browse: {
151
+ controlled: { required: ['select'], optional: ['open', 'sort', 'filter', 'page'] },
152
+ autonomous: { required: [], optional: ['loaded', 'row_open', 'action_done', 'error'] },
153
+ },
154
+ edit: {
155
+ controlled: { required: ['change', 'submit'], optional: ['validate', 'cancel'] },
156
+ autonomous: { required: ['submitted'], optional: ['loaded', 'error'] },
157
+ },
158
+ select: {
159
+ controlled: { required: ['pick'], optional: ['search'] },
160
+ autonomous: { required: ['pick'], optional: ['loaded', 'search', 'error'] },
161
+ },
162
+ compare: {
163
+ controlled: { required: [], optional: ['add', 'remove'] },
164
+ autonomous: { required: [], optional: ['loaded', 'error'] },
165
+ },
166
+ advance: {
167
+ controlled: { required: ['transition'], optional: ['action'] },
168
+ autonomous: { required: ['action_done'], optional: ['loaded', 'error'] },
169
+ },
170
+ navigate: {
171
+ controlled: { required: ['traverse'], optional: [] },
172
+ autonomous: { required: ['row_open'], optional: ['loaded', 'error'] },
173
+ },
174
+ monitor: {
175
+ controlled: { required: [], optional: ['range', 'drill'] },
176
+ autonomous: { required: [], optional: ['loaded', 'error'] },
177
+ },
178
+ };
179
+
180
+ /** 语义启用的一条事件:谁启用的、对谁必需 */
181
+ interface EnabledEvent {
182
+ kind: SomaInteractionKind;
183
+ requiredFor: readonly SomaControlModel[];
184
+ enabledBy: string;
185
+ }
186
+
187
+ /**
188
+ * 对象语义启用的能力与事件(§17.2)。
189
+ *
190
+ * 能力与事件在这里分家:`window.sort` 声明了就意味着**这次交互要能排序**(能力),
191
+ * 但只有受控型需要把排序意图 emit 出去(事件)——自治型自己排。
192
+ * 合成一个概念,自治型候选会因为"emit 不出 sort"被判成排不了序,
193
+ * 那是 §35 修掉的那个判据缺陷换个位置重演。
194
+ */
195
+ export function semanticEnablement(
196
+ verb: SomaVerb,
197
+ object: SomaObject,
198
+ ): { capabilities: SomaIntentCapability[]; events: EnabledEvent[] } {
199
+ const capabilities: SomaIntentCapability[] = [];
200
+ const events: EnabledEvent[] = [];
201
+ const win = object.window;
202
+ const collectionVerb = verb === 'browse' || verb === 'select' || verb === 'navigate' || verb === 'monitor';
203
+
204
+ if (win && collectionVerb) {
205
+ capabilities.push('paginate');
206
+ events.push({ kind: 'page', requiredFor: ['controlled'], enabledBy: 'window.block' });
207
+ if (win.sort.length > 0) {
208
+ capabilities.push('sort');
209
+ events.push({ kind: 'sort', requiredFor: ['controlled'], enabledBy: 'window.sort' });
210
+ }
211
+ if (win.filter !== null) {
212
+ capabilities.push('filter');
213
+ events.push({ kind: 'filter', requiredFor: ['controlled'], enabledBy: 'window.filter' });
214
+ }
215
+ if (win.group !== null) capabilities.push('group');
216
+ if (win.aggregate.length > 0) capabilities.push('aggregate');
217
+ // selection 在解析产物里恒存在(`base: 'none'` 是缺省),所以它**不能**当作
218
+ // "作者声明了多选"的信号——只有 base 已经是 'all' 才是作者写下的事实。
219
+ if (win.selection.base === 'all' || win.selection.toggled.length > 0) {
220
+ capabilities.push('select');
221
+ events.push({ kind: 'select', requiredFor: ['controlled'], enabledBy: 'window.selection' });
222
+ }
223
+ }
224
+
225
+ if (object.write && (SOMA_WRITE_VERBS as readonly string[]).includes(verb)) {
226
+ capabilities.push('write');
227
+ }
228
+
229
+ return { capabilities, events };
230
+ }
231
+
232
+ /**
233
+ * 组装一个动词在本次语义下的完整事件清单。
234
+ *
235
+ * 同一个 `kind` 被动词与语义各启用一次时**合并**(`requiredFor` 取并集),
236
+ * 而不是产出两条:两条同名事件会让构件层的 eventMap 校验对着其中一条通过、
237
+ * 对着另一条失败,取决于遍历顺序。
238
+ */
239
+ export function deriveInteractions(verb: SomaVerb, object: SomaObject): SomaInteraction[] {
240
+ const spec = VERB_EVENTS_BY_MODEL[verb];
241
+ const byKind = new Map<SomaInteractionKind, SomaInteraction>();
242
+
243
+ const put = (kind: SomaInteractionKind, requiredFor: readonly SomaControlModel[], enabledBy: string) => {
244
+ const existing = byKind.get(kind);
245
+ if (existing) {
246
+ const merged = new Set<SomaControlModel>([...existing.requiredFor, ...requiredFor]);
247
+ byKind.set(kind, {
248
+ ...existing,
249
+ requiredFor: (['autonomous', 'controlled'] as const).filter((m) => merged.has(m)),
250
+ enabledBy: existing.enabledBy === enabledBy ? enabledBy : `${existing.enabledBy}+${enabledBy}`,
251
+ });
252
+ return;
253
+ }
254
+ byKind.set(kind, {
255
+ kind,
256
+ payload: PAYLOADS[kind],
257
+ requiresGrant: GRANT_REQUIRED.has(kind),
258
+ requiredFor,
259
+ enabledBy,
260
+ });
261
+ };
262
+
263
+ for (const model of ['autonomous', 'controlled'] as const) {
264
+ for (const kind of spec[model].required) put(kind, [model], 'verb');
265
+ for (const kind of spec[model].optional) put(kind, [], 'verb');
266
+ }
267
+ for (const event of semanticEnablement(verb, object).events) {
268
+ put(event.kind, event.requiredFor, event.enabledBy);
269
+ }
270
+
271
+ // 输出顺序固定为封闭集顺序:产物要能逐字比对(§19.3 幂等)
272
+ return [...byKind.values()].sort((a, b) => (
273
+ SOMA_INTERACTION_ORDER.indexOf(a.kind) - SOMA_INTERACTION_ORDER.indexOf(b.kind)
274
+ ));
275
+ }
276
+
277
+ const SOMA_INTERACTION_ORDER: readonly SomaInteractionKind[] = [
278
+ 'change', 'submit', 'cancel', 'validate',
279
+ 'select', 'open', 'sort', 'filter', 'page',
280
+ 'pick', 'search',
281
+ 'transition', 'action', 'traverse',
282
+ 'add', 'remove',
283
+ 'range', 'drill',
284
+ 'loaded', 'submitted', 'error', 'row_open', 'action_done',
285
+ ];