soma-kit 0.0.0-stage → 0.1.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 (353) hide show
  1. package/README.md +539 -2
  2. package/bin/soma-kit.mjs +27 -0
  3. package/package.json +66 -4
  4. package/packs/ai/agent-run-card.ts +64 -0
  5. package/packs/ai/evaluation-card.ts +51 -0
  6. package/packs/ai/guardrail-policy-card.ts +48 -0
  7. package/packs/ai/index.ts +31 -0
  8. package/packs/ai/model-card.ts +55 -0
  9. package/packs/ai/model-routing-card.ts +49 -0
  10. package/packs/ai/prompt-template-card.ts +49 -0
  11. package/packs/ai/texts.ts +19 -0
  12. package/packs/commerce/address-card.ts +58 -0
  13. package/packs/commerce/coupon-card.ts +64 -0
  14. package/packs/commerce/index.ts +25 -0
  15. package/packs/commerce/order-card.ts +60 -0
  16. package/packs/commerce/purchase-order-card.ts +74 -0
  17. package/packs/commerce/texts.ts +14 -0
  18. package/packs/finance/index.ts +30 -0
  19. package/packs/finance/invoice-summary-card.ts +48 -0
  20. package/packs/finance/reconcile-board.ts +450 -0
  21. package/packs/finance/reconcile-case-card.ts +70 -0
  22. package/packs/finance/reconcile-desk/compile.ts +208 -0
  23. package/packs/finance/reconcile-desk/index.ts +20 -0
  24. package/packs/finance/reconcile-desk/shell.ts +27 -0
  25. package/packs/finance/texts.ts +21 -0
  26. package/packs/ops/change-window-card.ts +54 -0
  27. package/packs/ops/dependency-status-card.ts +50 -0
  28. package/packs/ops/error-budget-card.ts +60 -0
  29. package/packs/ops/execution-task-runner.ts +61 -0
  30. package/packs/ops/index.ts +36 -0
  31. package/packs/ops/integration-status-card.ts +45 -0
  32. package/packs/ops/release-readiness-card.ts +63 -0
  33. package/packs/ops/runbook-execution-card.ts +81 -0
  34. package/packs/ops/texts.ts +21 -0
  35. package/packs/security/control-evidence-card.ts +54 -0
  36. package/packs/security/finding-card.ts +96 -0
  37. package/packs/security/index.ts +29 -0
  38. package/packs/security/texts.ts +31 -0
  39. package/packs/shared/card-util.ts +60 -0
  40. package/packs/shared/wrap.ts +13 -0
  41. package/spec/generated/kit-app.schema.json +84 -0
  42. package/spec/generated/kit-page.schema.json +2766 -0
  43. package/spec/kit-grammar.json +1358 -0
  44. package/spec/kit-grammar.schema.json +716 -0
  45. package/src/app/app-config.ts +108 -0
  46. package/src/app/compose-apps.ts +139 -0
  47. package/src/app/define-kit-actions.ts +89 -0
  48. package/src/app/define-kit-app.ts +362 -0
  49. package/src/app/define-kit-pack.ts +114 -0
  50. package/src/app/envelope.ts +117 -0
  51. package/src/app/index.ts +50 -0
  52. package/src/app/notify-renderer.ts +114 -0
  53. package/src/app/paged-list-adapter.ts +246 -0
  54. package/src/app/server-pages.ts +303 -0
  55. package/src/app/server.ts +244 -0
  56. package/src/app/submit.types.ts +87 -0
  57. package/src/base/action-busy.ts +159 -0
  58. package/src/base/action-gate.ts +267 -0
  59. package/src/base/action-status.ts +31 -0
  60. package/src/base/alert.ts +136 -0
  61. package/src/base/avatar.ts +271 -0
  62. package/src/base/button.ts +139 -0
  63. package/src/base/cascader.ts +523 -0
  64. package/src/base/check-core.ts +214 -0
  65. package/src/base/checkbox.ts +35 -0
  66. package/src/base/choice.ts +183 -0
  67. package/src/base/color-picker.ts +316 -0
  68. package/src/base/combobox.ts +61 -0
  69. package/src/base/command-palette.ts +371 -0
  70. package/src/base/context-menu.ts +103 -0
  71. package/src/base/countdown.ts +168 -0
  72. package/src/base/date-range.ts +444 -0
  73. package/src/base/date.ts +899 -0
  74. package/src/base/divider.ts +156 -0
  75. package/src/base/fab.ts +192 -0
  76. package/src/base/icons.ts +106 -0
  77. package/src/base/image.ts +177 -0
  78. package/src/base/index.ts +214 -0
  79. package/src/base/input.ts +316 -0
  80. package/src/base/kbd.ts +99 -0
  81. package/src/base/link.ts +167 -0
  82. package/src/base/listbox-core.ts +965 -0
  83. package/src/base/mentions.ts +323 -0
  84. package/src/base/menu-button.ts +240 -0
  85. package/src/base/menu-core.ts +341 -0
  86. package/src/base/month-grid.ts +171 -0
  87. package/src/base/motion/aura.ts +94 -0
  88. package/src/base/motion/hover-3d.ts +154 -0
  89. package/src/base/motion/hover-gallery.ts +185 -0
  90. package/src/base/motion/index.ts +27 -0
  91. package/src/base/motion/limits.ts +75 -0
  92. package/src/base/motion/marquee.ts +157 -0
  93. package/src/base/motion/text-rotate.ts +195 -0
  94. package/src/base/number.ts +121 -0
  95. package/src/base/otp.ts +259 -0
  96. package/src/base/permission-gate.ts +99 -0
  97. package/src/base/popover.ts +352 -0
  98. package/src/base/popup.ts +542 -0
  99. package/src/base/portal-core.ts +297 -0
  100. package/src/base/price-text.ts +126 -0
  101. package/src/base/progress.ts +216 -0
  102. package/src/base/qr-code.ts +446 -0
  103. package/src/base/qty-stepper.ts +241 -0
  104. package/src/base/radio.ts +33 -0
  105. package/src/base/range.ts +444 -0
  106. package/src/base/rating.ts +249 -0
  107. package/src/base/segmented.ts +286 -0
  108. package/src/base/select.ts +57 -0
  109. package/src/base/shared.ts +708 -0
  110. package/src/base/swap.ts +86 -0
  111. package/src/base/switch.ts +111 -0
  112. package/src/base/tag-input.ts +464 -0
  113. package/src/base/tag.ts +250 -0
  114. package/src/base/text.ts +126 -0
  115. package/src/base/textarea.ts +129 -0
  116. package/src/base/time-picker.ts +606 -0
  117. package/src/base/tree-select.ts +629 -0
  118. package/src/base/upload.ts +548 -0
  119. package/src/base/virtual-list.ts +286 -0
  120. package/src/biz/approval-desk/compile.ts +179 -0
  121. package/src/biz/approval-desk/index.ts +21 -0
  122. package/src/biz/approval-desk/shell.ts +50 -0
  123. package/src/biz/auth-panel/compile.ts +196 -0
  124. package/src/biz/auth-panel/index.ts +24 -0
  125. package/src/biz/auth-panel/shell.ts +46 -0
  126. package/src/biz/category-crud/compile.ts +173 -0
  127. package/src/biz/category-crud/index.ts +19 -0
  128. package/src/biz/category-crud/shell.ts +29 -0
  129. package/src/biz/checkout-page/compile.ts +111 -0
  130. package/src/biz/checkout-page/index.ts +20 -0
  131. package/src/biz/checkout-page/shell.ts +50 -0
  132. package/src/biz/compose.ts +313 -0
  133. package/src/biz/data-components.ts +26 -0
  134. package/src/biz/define.ts +23 -0
  135. package/src/biz/import-wizard/compile.ts +204 -0
  136. package/src/biz/import-wizard/hub.ts +540 -0
  137. package/src/biz/import-wizard/index.ts +24 -0
  138. package/src/biz/import-wizard/shell.ts +161 -0
  139. package/src/biz/index.ts +80 -0
  140. package/src/biz/landing-page/compile.ts +67 -0
  141. package/src/biz/landing-page/index.ts +20 -0
  142. package/src/biz/landing-page/shell.ts +48 -0
  143. package/src/biz/link/hub.ts +255 -0
  144. package/src/biz/link/shared.ts +493 -0
  145. package/src/biz/master-sub/compile.ts +232 -0
  146. package/src/biz/master-sub/index.ts +20 -0
  147. package/src/biz/master-sub/shell.ts +56 -0
  148. package/src/biz/multi-board/compile.ts +234 -0
  149. package/src/biz/multi-board/index.ts +19 -0
  150. package/src/biz/multi-board/shell.ts +70 -0
  151. package/src/biz/names.ts +30 -0
  152. package/src/biz/notification-center/compile.ts +138 -0
  153. package/src/biz/notification-center/index.ts +29 -0
  154. package/src/biz/notification-center/shell.ts +42 -0
  155. package/src/biz/page-templates/result-page/compile.ts +46 -0
  156. package/src/biz/page-templates/result-page/index.ts +19 -0
  157. package/src/biz/page-templates/result-page/shell.ts +31 -0
  158. package/src/biz/page-templates/shared.ts +121 -0
  159. package/src/biz/page-templates/sign-in-page/compile.ts +176 -0
  160. package/src/biz/page-templates/sign-in-page/index.ts +18 -0
  161. package/src/biz/page-templates/sign-in-page/shell.ts +116 -0
  162. package/src/biz/record-detail/compile.ts +290 -0
  163. package/src/biz/record-detail/index.ts +22 -0
  164. package/src/biz/record-detail/shell.ts +64 -0
  165. package/src/biz/settings-center/compile.ts +100 -0
  166. package/src/biz/settings-center/index.ts +18 -0
  167. package/src/biz/settings-center/shell.ts +51 -0
  168. package/src/biz/shared/action-host.ts +469 -0
  169. package/src/biz/shared/coordinator.ts +516 -0
  170. package/src/biz/shared/index.ts +9 -0
  171. package/src/biz/shared/pipes.ts +58 -0
  172. package/src/biz/shared/runtime-hub.ts +112 -0
  173. package/src/biz/shared/step-values.ts +25 -0
  174. package/src/biz/single-form/compile.ts +146 -0
  175. package/src/biz/single-form/index.ts +18 -0
  176. package/src/biz/single-form/shell.ts +38 -0
  177. package/src/biz/standard-crud/bridge.ts +11 -0
  178. package/src/biz/standard-crud/compile.ts +546 -0
  179. package/src/biz/standard-crud/index.ts +18 -0
  180. package/src/biz/standard-crud/shell.ts +157 -0
  181. package/src/biz/step-form/compile.ts +400 -0
  182. package/src/biz/step-form/hub.ts +412 -0
  183. package/src/biz/step-form/index.ts +23 -0
  184. package/src/biz/step-form/shell.ts +96 -0
  185. package/src/biz/step-form/steps-ref.ts +112 -0
  186. package/src/biz/types.ts +96 -0
  187. package/src/cli/kit-cli.ts +102 -0
  188. package/src/compile/action-host-attach.ts +76 -0
  189. package/src/compile/compile-page.ts +472 -0
  190. package/src/compile/component-candidates.ts +147 -0
  191. package/src/compile/fragment.ts +104 -0
  192. package/src/compile/hints.ts +255 -0
  193. package/src/compile/index.ts +16 -0
  194. package/src/compile/locate.ts +166 -0
  195. package/src/compile/page-params.ts +80 -0
  196. package/src/compile/parse.ts +355 -0
  197. package/src/compile/redirect.ts +90 -0
  198. package/src/compile/registry.ts +30 -0
  199. package/src/compile/remove-guard.ts +99 -0
  200. package/src/compile/styles.ts +244 -0
  201. package/src/compile/types.ts +106 -0
  202. package/src/data/amount-breakdown.ts +132 -0
  203. package/src/data/anchor-nav.ts +225 -0
  204. package/src/data/approval-flow.ts +269 -0
  205. package/src/data/assignment-picker.ts +652 -0
  206. package/src/data/async-result-panel.ts +308 -0
  207. package/src/data/breadcrumbs.ts +197 -0
  208. package/src/data/calendar.ts +363 -0
  209. package/src/data/carousel.ts +408 -0
  210. package/src/data/chart.ts +726 -0
  211. package/src/data/checklist.ts +215 -0
  212. package/src/data/code-view.ts +415 -0
  213. package/src/data/comment-thread.ts +342 -0
  214. package/src/data/confirm-dialog.ts +144 -0
  215. package/src/data/context-menu.ts +216 -0
  216. package/src/data/d9-limits.ts +42 -0
  217. package/src/data/d9-util.ts +81 -0
  218. package/src/data/diff.ts +239 -0
  219. package/src/data/display-util.ts +135 -0
  220. package/src/data/dock.ts +152 -0
  221. package/src/data/embed.ts +200 -0
  222. package/src/data/field-mapper.ts +544 -0
  223. package/src/data/flow-editor-contract.ts +41 -0
  224. package/src/data/flow-editor.ts +2622 -0
  225. package/src/data/flow-remote-options.ts +257 -0
  226. package/src/data/footer.ts +157 -0
  227. package/src/data/form-draft-registry.ts +76 -0
  228. package/src/data/gantt.ts +430 -0
  229. package/src/data/hero.ts +149 -0
  230. package/src/data/image-viewer.ts +333 -0
  231. package/src/data/index.ts +268 -0
  232. package/src/data/item-list.ts +335 -0
  233. package/src/data/kanban.ts +667 -0
  234. package/src/data/media-grid.ts +246 -0
  235. package/src/data/mega-menu.ts +257 -0
  236. package/src/data/menu-dom.ts +169 -0
  237. package/src/data/menu.ts +464 -0
  238. package/src/data/mockup.ts +176 -0
  239. package/src/data/modal-dialog.ts +182 -0
  240. package/src/data/navbar.ts +292 -0
  241. package/src/data/object-form.ts +1981 -0
  242. package/src/data/options-bus.ts +24 -0
  243. package/src/data/outcome-watch.ts +40 -0
  244. package/src/data/overlay-portal.ts +6 -0
  245. package/src/data/pager.ts +473 -0
  246. package/src/data/permission-matrix.ts +432 -0
  247. package/src/data/permission-tree.ts +916 -0
  248. package/src/data/pricing-table.ts +269 -0
  249. package/src/data/prompt-dialog.ts +235 -0
  250. package/src/data/reaction-bar.ts +236 -0
  251. package/src/data/record-card.ts +413 -0
  252. package/src/data/record-picker.ts +489 -0
  253. package/src/data/redirect.ts +109 -0
  254. package/src/data/remote-options.ts +54 -0
  255. package/src/data/request-console.ts +399 -0
  256. package/src/data/resident.ts +58 -0
  257. package/src/data/result-panel.ts +160 -0
  258. package/src/data/rich-text.ts +626 -0
  259. package/src/data/row-editor.ts +1066 -0
  260. package/src/data/rule-builder.ts +1137 -0
  261. package/src/data/shape-util.ts +221 -0
  262. package/src/data/staged-rows.ts +69 -0
  263. package/src/data/stat-group.ts +231 -0
  264. package/src/data/static-lazy.ts +63 -0
  265. package/src/data/static-registry.ts +227 -0
  266. package/src/data/steps.ts +195 -0
  267. package/src/data/survey.ts +455 -0
  268. package/src/data/system-switcher.ts +243 -0
  269. package/src/data/timeline.ts +204 -0
  270. package/src/data/tour-guide.ts +392 -0
  271. package/src/data/transfer.ts +597 -0
  272. package/src/data/tree-check.ts +30 -0
  273. package/src/data/tree-table.ts +674 -0
  274. package/src/data/tree.ts +656 -0
  275. package/src/data/trend-line.ts +147 -0
  276. package/src/data/virtual-rows.ts +556 -0
  277. package/src/data/watermark.ts +140 -0
  278. package/src/data/wrap.ts +267 -0
  279. package/src/data/wrapped-candidates.ts +96 -0
  280. package/src/frames/blank-frame.ts +19 -0
  281. package/src/frames/index.ts +44 -0
  282. package/src/frames/page-bar.ts +185 -0
  283. package/src/frames/page-header.ts +185 -0
  284. package/src/frames/page-status.ts +54 -0
  285. package/src/frames/resize-handle.ts +147 -0
  286. package/src/frames/shared.ts +242 -0
  287. package/src/frames/single-frame.ts +16 -0
  288. package/src/frames/split-frame/index.ts +4 -0
  289. package/src/frames/split-frame/shell.ts +219 -0
  290. package/src/frames/split-frame/span.ts +64 -0
  291. package/src/frames/split-frame/wiring.ts +164 -0
  292. package/src/frames/tabs-frame/index.ts +3 -0
  293. package/src/frames/tabs-frame/shell.ts +112 -0
  294. package/src/frames/tabs-frame/wiring.ts +69 -0
  295. package/src/frames/top-main-frame.ts +20 -0
  296. package/src/frames/types.ts +72 -0
  297. package/src/frames/workspace-frame/extras.ts +197 -0
  298. package/src/frames/workspace-frame/index.ts +13 -0
  299. package/src/frames/workspace-frame/shell.ts +282 -0
  300. package/src/frames/workspace-frame/state.ts +152 -0
  301. package/src/frames/workspace-frame/view.ts +1013 -0
  302. package/src/generated/kit-grammar-runtime.ts +2822 -0
  303. package/src/generated/page-origin.ts +57 -0
  304. package/src/i18n/index.ts +22 -0
  305. package/src/i18n/kit-text.ts +692 -0
  306. package/src/i18n/resolve-text-refs.ts +128 -0
  307. package/src/index.ts +6 -0
  308. package/src/object-renderer/action-gate.ts +216 -0
  309. package/src/object-renderer/adopt-gate.ts +333 -0
  310. package/src/object-renderer/arrange.ts +411 -0
  311. package/src/object-renderer/candidates.ts +68 -0
  312. package/src/object-renderer/collapse-wiring.ts +99 -0
  313. package/src/object-renderer/collection-expand.ts +185 -0
  314. package/src/object-renderer/collection-parts.ts +653 -0
  315. package/src/object-renderer/collection-table.ts +503 -0
  316. package/src/object-renderer/collection.ts +628 -0
  317. package/src/object-renderer/compile-data.ts +549 -0
  318. package/src/object-renderer/defaults.ts +252 -0
  319. package/src/object-renderer/display-checks.ts +153 -0
  320. package/src/object-renderer/emit-events.ts +498 -0
  321. package/src/object-renderer/emit-object.ts +98 -0
  322. package/src/object-renderer/emit-static.ts +1036 -0
  323. package/src/object-renderer/field-policy.ts +89 -0
  324. package/src/object-renderer/field-value.ts +581 -0
  325. package/src/object-renderer/form-detail.ts +116 -0
  326. package/src/object-renderer/index.ts +13 -0
  327. package/src/object-renderer/linkage.ts +371 -0
  328. package/src/object-renderer/merge-class.ts +126 -0
  329. package/src/object-renderer/mode.ts +25 -0
  330. package/src/object-renderer/outcome-draft.ts +61 -0
  331. package/src/object-renderer/parts.ts +136 -0
  332. package/src/object-renderer/pick-component.ts +36 -0
  333. package/src/object-renderer/render-object.ts +724 -0
  334. package/src/object-renderer/request-actions.ts +581 -0
  335. package/src/object-renderer/skeleton.ts +101 -0
  336. package/src/object-renderer/table-actions.ts +438 -0
  337. package/src/object-renderer/table-summary.ts +105 -0
  338. package/src/object-renderer/table-tools.ts +1072 -0
  339. package/src/object-renderer/types.ts +936 -0
  340. package/src/page-target/ai-surface.ts +154 -0
  341. package/src/page-target/compile.ts +354 -0
  342. package/src/page-target/drift.ts +186 -0
  343. package/src/page-target/index.ts +25 -0
  344. package/src/page-target/intent-map.ts +137 -0
  345. package/src/page-target/intent-schema.ts +711 -0
  346. package/src/page-target/origin.ts +17 -0
  347. package/src/page-target/target.ts +450 -0
  348. package/src/page-target/writer-policy.ts +315 -0
  349. package/src/theme/block-theme.ts +202 -0
  350. package/src/theme/kit-theme-text.ts +2 -0
  351. package/src/theme/kit-theme.css +275 -0
  352. package/src/theme/kit-theme.tpl +275 -0
  353. package/src/theme/theme-tokens.ts +135 -0
@@ -0,0 +1,96 @@
1
+ // 业务组件框架的类型(H 组独占;I 组的 MasterSub / CategoryCrud 只 import)。
2
+ //
3
+ // 业务组件 = 写死的 HTML 代码壳 + 写死的多对象协作规则(规格 5.1)。
4
+ // 它不是组件层:编译器按 `product.kind` 查 `KIT_BIZ_COMPONENTS`,把页面传入的各对象交给 `compile`,
5
+ // 得到一个 KitFragment(HTML + `_ui.yaml` 片段 + `_event.yaml` 片段 + 候选类 + 诊断),再交页面框装入。
6
+
7
+ import type { KitObject } from '../object-renderer/types';
8
+ import type { KitFragment } from '../compile/fragment';
9
+
10
+ /** 附加浮层声明(StandardCrud 的 `overlays.*`):一个附加关联对象 + 浮层壳的种类与标题。 */
11
+ export interface KitOverlayDecl {
12
+ /**
13
+ * dialog / drawer = 浮层壳;expand = 展开行子表的子对象(Q 波 G5,不画浮层,由 entity 的 `collection.expand: { list: <本浮层名>, link }` 引用,
14
+ * 其 behavior.from 的 link 参数由编译器编成 require)
15
+ */
16
+ kind: 'dialog' | 'drawer' | 'expand';
17
+ title?: string;
18
+ /**
19
+ * 浮层里写死形状数据组件的事件映射(K-1):{ 组件抛出的事件名: 'saved' | 'close' | 'reload' }。
20
+ * 约定名 saved / cancel / close / reload 不用写,编译器自动接线;这里只补自定义事件名。
21
+ */
22
+ events?: Record<string, string | KitOverlayEventAction>;
23
+ /** 浮层面板外框类(如 `w-96`),按同族规则覆写基准 */
24
+ class?: string;
25
+ /**
26
+ * 只读浮层(view 是 summary)的「编辑」去向:另一个浮层名(view 是 form,kind 可与本浮层不同,如只读抽屉切到编辑弹窗)。
27
+ * 浮层头出现「编辑」钮,点了关闭本浮层、打开目标浮层,当前行保留(E3:显示态与编辑态)。
28
+ */
29
+ editOverlay?: string;
30
+ /**
31
+ * 整行点击进入本浮层(StandardCrud,至多一个浮层写 true):点列表行(按钮 / 复选框 / 链接上的点击除外)或聚焦行按 Enter,
32
+ * 以当前行打开本浮层——通常是只读详情(view 是 summary)。行上的「查看」之类行动作照常可用。
33
+ */
34
+ rowClick?: boolean;
35
+ behavior?: KitObject['behavior'];
36
+ view?: KitObject['view'];
37
+ schema?: KitObject['schema'];
38
+ }
39
+
40
+ /** 浮层事件先执行具名动作、成功后再走 then(M1-5):`{ action: 具名动作, then: saved | close | reload }` */
41
+ export interface KitOverlayEventAction {
42
+ action: string;
43
+ then?: 'saved' | 'close' | 'reload';
44
+ }
45
+
46
+ export interface KitBizInput {
47
+ kind: string;
48
+ /** 对象角色槽;`many: true` 的角色(如 MasterSub 的 subs)值是「名字 -> 对象」的表 */
49
+ objects: Record<string, KitObject | Record<string, KitObject>>;
50
+ overlays?: Record<string, KitOverlayDecl>;
51
+ class?: string;
52
+ /** 内部区域名 -> 覆写类;键必须在业务组件定义的 `areas` 里 */
53
+ areaClass?: Record<string, string>;
54
+ /** 仅 acceptConfig: true 的包装/定制业务组件可接收的专属配置字典 */
55
+ config?: Record<string, unknown>;
56
+ }
57
+
58
+ export interface KitBizContext {
59
+ /**
60
+ * 页面框的槽名(main / top / left / right / <页签 id>),全部对象名、锚点、作用域 id 都以它为前缀。
61
+ * 只含字母数字下划线;保留名 frame / tabs / page / p / ctrl 由编译器前置拒收。
62
+ */
63
+ pageId: string;
64
+ /** 应用登记的具名动作名(核 `submit` 引用) */
65
+ registeredActions: ReadonlySet<string>;
66
+ /** 已登记的基础组件名(内置 13 个 + App*) */
67
+ registeredComponents: ReadonlySet<string>;
68
+ /** 已登记的写死形状数据组件 */
69
+ staticComponents: Record<string, { accept: 'single' | 'list'; emits?: readonly string[]; props?: readonly string[] }>;
70
+ /** 页面语言(`page.locale`,缺省应用 defaultLocale;未声明为空串):业务组件写进产物的内置文案按它取(`kitText(key, params, ctx.locale)`) */
71
+ locale?: string;
72
+ }
73
+
74
+ export interface KitBizRole {
75
+ required: boolean;
76
+ /** 该角色的对象允许出现的视图槽位 */
77
+ views: Array<'list' | 'summary' | 'filter' | 'form'>;
78
+ /** 对象表(如 `subs.*`):值是「名字 -> 对象」 */
79
+ many?: boolean;
80
+ }
81
+
82
+ export interface KitBizDefinition {
83
+ kind: string;
84
+ /** 对象角色槽:required、允许的 view 槽位、是否为对象表 */
85
+ roles: Record<string, KitBizRole>;
86
+ /** 可用 `areaClass` 覆写的内部区域名 */
87
+ areas: string[];
88
+ /** 是否允许页面传入 product.config(内置标准组件缺省 false 保持通用;应用包装或定制组件设为 true 承接专属语法翻译) */
89
+ acceptConfig?: boolean;
90
+ /**
91
+ * 内置业务组件的受限 config 通道(Q 波):只接收这里列出的键(如 StepForm 的 saveMode / stepKey),其它键报 KIT-PAGE-001。
92
+ * 与 acceptConfig 不同,它不让 AI 目标把该组件排除在映射外——这些键在 aiWriter 里仍是 human-only。
93
+ */
94
+ configKeys?: readonly string[];
95
+ compile(input: KitBizInput, ctx: KitBizContext): KitFragment;
96
+ }
@@ -0,0 +1,102 @@
1
+ // `soma kit explain <诊断码>` 与 `soma kit check <应用目录>` 的实现(bin/soma-kit.mjs 只拿参数、接标准输出、设退出码)。
2
+ // 说明正文读真源 kit-grammar.json#diagnostics,常见原因与正反示例读 #diagnosticExamples;建议由 compile/hints.ts 生成。
3
+ import grammarJson from '../../spec/kit-grammar.json';
4
+ import { closestOf, formatKitDiagnostic } from '../compile/hints';
5
+ import type { KitDiagnostic } from '../object-renderer/types';
6
+
7
+ type Examples = Record<string, { causes?: string[]; bad: string; good: string }>;
8
+
9
+ const DIAGNOSTICS = (grammarJson as unknown as { diagnostics: Record<string, string> }).diagnostics;
10
+ const EXAMPLES = (grammarJson as unknown as { diagnosticExamples: Examples }).diagnosticExamples;
11
+
12
+ export interface KitCliIo {
13
+ out(text: string): void;
14
+ err(text: string): void;
15
+ }
16
+
17
+ export const KIT_CLI_USAGE = [
18
+ 'Usage:',
19
+ ' soma kit explain <诊断码> 打印诊断的完整说明、常见原因与正反示例',
20
+ ' soma kit check <应用目录> 编译应用全部页面,打印带修改建议的诊断',
21
+ '',
22
+ ].join('\n');
23
+
24
+ const indent = (text: string): string => text.split('\n').map((l) => ` ${l}`).join('\n');
25
+
26
+ /** 诊断码说明文本;码未登记返回 undefined */
27
+ export function explainKitCode(raw: string): string | undefined {
28
+ const code = raw.trim().toUpperCase();
29
+ const text = DIAGNOSTICS[code];
30
+ if (text === undefined) return undefined;
31
+ const lines = [`${code}`, '', `说明:${text}`];
32
+ const ex = EXAMPLES[code];
33
+ if (ex !== undefined) {
34
+ if (ex.causes !== undefined && ex.causes.length > 0) lines.push('', '常见原因:', ...ex.causes.map((c) => ` - ${c}`));
35
+ lines.push('', '反例:', indent(ex.bad), '', '正例:', indent(ex.good));
36
+ } else {
37
+ lines.push('', '(该诊断码暂无示例;说明即真源 kit-grammar.json#diagnostics 的条目)');
38
+ }
39
+ return `${lines.join('\n')}\n`;
40
+ }
41
+
42
+ /** 装配一个 soma-kit 应用并编译全部页面;返回诊断(空 = 全部通过)与页面数 */
43
+ async function checkApp(appDir: string, load: (file: string) => unknown): Promise<{ pages: number; diagnostics: KitDiagnostic[] }> {
44
+ const path = await import(/* webpackIgnore: true */ 'node:path');
45
+ const fs = await import(/* webpackIgnore: true */ 'node:fs');
46
+ const root = path.resolve(appDir);
47
+ const file = path.join(root, 'soma.app.ts');
48
+ if (!fs.existsSync(file)) throw new Error(`${root} 下没有 soma.app.ts(应用装配入口)`);
49
+ process.env.SOMA_HOST_DIR = root;
50
+ const loaded = load(file) as { default?: unknown };
51
+ const assembly = (loaded.default ?? loaded) as { server?: () => Promise<{ artifacts?: ReadonlyMap<string, unknown> }> };
52
+ if (typeof assembly.server !== 'function') throw new Error('soma.app.ts 的默认导出不是 defineKitApp(...) 的装配(没有 server())');
53
+ try {
54
+ const face = await assembly.server();
55
+ return { pages: face.artifacts?.size ?? 0, diagnostics: [] };
56
+ } catch (error) {
57
+ const list = (error as { diagnostics?: KitDiagnostic[] }).diagnostics;
58
+ if (Array.isArray(list)) return { pages: 0, diagnostics: list };
59
+ throw error;
60
+ }
61
+ }
62
+
63
+ /** 入口:返回退出码 */
64
+ export async function runKitCli(args: readonly string[], io: KitCliIo, load: (file: string) => unknown): Promise<number> {
65
+ const [sub, ...rest] = args;
66
+ if (sub === 'explain') {
67
+ const given = rest[0];
68
+ if (given === undefined) {
69
+ io.err(`[soma kit explain] 缺诊断码\n${KIT_CLI_USAGE}`);
70
+ return 1;
71
+ }
72
+ const text = explainKitCode(given);
73
+ if (text === undefined) {
74
+ const near = closestOf(given.toUpperCase(), Object.keys(DIAGNOSTICS));
75
+ io.err(`[soma kit explain] 诊断码 ${given} 未登记${near === undefined ? '' : `,你可能想查的是 ${near}`}\n`);
76
+ return 1;
77
+ }
78
+ io.out(text);
79
+ return 0;
80
+ }
81
+ if (sub === 'check') {
82
+ const dir = rest[0];
83
+ if (dir === undefined) {
84
+ io.err(`[soma kit check] 缺应用目录\n${KIT_CLI_USAGE}`);
85
+ return 1;
86
+ }
87
+ try {
88
+ const { pages, diagnostics } = await checkApp(dir, load);
89
+ if (diagnostics.length === 0) {
90
+ io.out(`OK 页面 ${pages} 个,零诊断\n`);
91
+ return 0;
92
+ }
93
+ io.out(`FAIL ${diagnostics.length} 条诊断\n${diagnostics.map((d) => ` ${formatKitDiagnostic(d)}`).join('\n')}\n`);
94
+ return 1;
95
+ } catch (error) {
96
+ io.err(`[soma kit check] ${(error as Error).message}\n`);
97
+ return 1;
98
+ }
99
+ }
100
+ io.err(KIT_CLI_USAGE);
101
+ return sub === undefined || sub === 'help' || sub === '--help' ? 0 : 1;
102
+ }
@@ -0,0 +1,76 @@
1
+ // 页面里存在 request / download 动作时,把页面级 KitActionHost 与它依赖的声明补进已装框的片段。
2
+ // 补三样:宿主实例(html + show props)、语义作用域 kit_act(切片 results 的 owner 是宿主)、request 动作合成的 core 只写对象(data 段)。
3
+
4
+ import { KIT_ACT_HOST, KIT_ACT_SCOPE, requestWriteObjects, type KitRequestSpec } from '../object-renderer/request-actions';
5
+ import type { KitDiagnostic } from '../object-renderer/types';
6
+ import { getCompileEnvelope } from '../app/envelope';
7
+ import type { KitFragment } from './fragment';
8
+
9
+ const HOST_ANCHOR = 'kit-act-host';
10
+
11
+ const isRec = (v: unknown): v is Record<string, unknown> => typeof v === 'object' && v !== null && !Array.isArray(v);
12
+
13
+ /** 递归收集 show 里所有字符串叶子(核对 then 点名的 options.from 接口路径在本页真有字段在用) */
14
+ function collectStrings(root: unknown, into: Set<string> = new Set()): Set<string> {
15
+ if (typeof root === 'string') into.add(root);
16
+ else if (Array.isArray(root)) for (const v of root) collectStrings(v, into);
17
+ else if (isRec(root)) for (const v of Object.values(root)) collectStrings(v, into);
18
+ return into;
19
+ }
20
+
21
+ /** 就地补进 framed;返回诊断(into 与页面已有数据对象重名、作用域重复) */
22
+ export function attachActionHost(framed: KitFragment, specs: ReadonlyMap<string, KitRequestSpec>): KitDiagnostic[] {
23
+ const diagnostics: KitDiagnostic[] = [];
24
+ const data = (framed.ui.data ??= {});
25
+
26
+ // request 合成的只写对象;into 范围名不得与页面数据对象(含合成对象)重名——它们是两套命名空间里的同名,读起来会混
27
+ const writeObjects = requestWriteObjects(specs);
28
+ for (const spec of specs.values()) {
29
+ if (spec.kind !== 'request' || spec.outcome === undefined || spec.outcome === spec.writeObject) continue;
30
+ if (spec.outcome in data) {
31
+ diagnostics.push({ code: 'KIT-ACT-002', path: `behavior.actions.${spec.actionId}.request.into`, message: `into "${spec.outcome}" 与页面里的数据对象重名:into 是写入结果的范围名,换一个不重复的名字` });
32
+ }
33
+ }
34
+ // H1b / H1c:request.then 数组里点名的数据对象 / 选项接口路径必须在本页找得到(拼错了静默不刷新最难查)
35
+ let optionPaths: Set<string> | undefined;
36
+ for (const spec of specs.values()) {
37
+ for (const [i, it] of (spec.thenItems ?? []).entries()) {
38
+ if (it.reload === true) continue;
39
+ const at = `behavior.actions.${spec.actionId}.request.then[${i}].reload`;
40
+ if (it.reload.startsWith('/')) {
41
+ optionPaths ??= collectStrings(framed.ui.show);
42
+ if (!optionPaths.has(it.reload)) {
43
+ diagnostics.push({ code: 'KIT-ACT-009', path: at, message: `reload 点名的接口路径 ${it.reload} 在本页没有任何字段把它写作 options.from,重取不到任何候选(路径拼错了?)` });
44
+ }
45
+ } else if (!(it.reload in data) || it.reload in writeObjects) {
46
+ diagnostics.push({ code: 'KIT-ACT-009', path: at, message: `reload 点名的数据对象 ${it.reload} 不在本页(页面里的数据对象:${Object.keys(data).filter((n) => !(n in writeObjects)).join(' / ')})` });
47
+ }
48
+ }
49
+ }
50
+ if (diagnostics.length > 0) return diagnostics;
51
+ for (const [name, decl] of Object.entries(writeObjects)) data[name] = decl;
52
+
53
+ // 作用域:object 取第一个真实存在的数据对象(作用域必须绑一个对象)
54
+ const names = Object.keys(data);
55
+ const bound = [...specs.values()].map((s) => s.object).find((o) => o in data && !(o in writeObjects)) ?? names.find((n) => !(n in writeObjects)) ?? names[0];
56
+ if (bound === undefined) {
57
+ return [{ code: 'KIT-ACT-002', path: 'behavior.actions', message: 'request / download 动作所在页面没有任何数据对象,宿主没有可绑定的作用域对象' }];
58
+ }
59
+ const scopes: Array<Record<string, unknown>> = Array.isArray(framed.ui.scopes)
60
+ ? framed.ui.scopes
61
+ : (framed.ui.scopes = Object.entries(framed.ui.scopes ?? {}).map(([id, v]) => ({ id, ...(isRec(v) ? v : {}) })));
62
+ if (scopes.some((s) => s.id === KIT_ACT_SCOPE)) {
63
+ diagnostics.push({ code: 'KIT-PAGE-002', path: `ui.scopes.${KIT_ACT_SCOPE}`, message: `scopes 作用域重复:${KIT_ACT_SCOPE}(页面里的对象名不能叫 ${KIT_ACT_SCOPE})` });
64
+ return diagnostics;
65
+ }
66
+ scopes.push({ id: KIT_ACT_SCOPE, object: bound, slices: [{ name: 'results', owner: HOST_ANCHOR }] });
67
+
68
+ // 宿主实例
69
+ const requests: Record<string, KitRequestSpec> = Object.fromEntries(specs);
70
+ const show = (framed.ui.show ??= {});
71
+ const envelope = getCompileEnvelope();
72
+ show[HOST_ANCHOR] = { props: { scope: KIT_ACT_SCOPE, requests, ...(envelope !== undefined ? { envelope } : {}) } };
73
+ framed.html = `${framed.html}\n<div data-soma-component="${KIT_ACT_HOST}" data-soma-id="${HOST_ANCHOR}"></div>`;
74
+ if (!framed.components.includes(KIT_ACT_HOST)) framed.components.push(KIT_ACT_HOST);
75
+ return diagnostics;
76
+ }