@tbox.cn/app-template-agent 1.0.0-alpha.1 → 1.0.0-alpha.11

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 (436) hide show
  1. package/._.gitignore +0 -0
  2. package/._.nvmrc +0 -0
  3. package/._AGENTS.md +0 -0
  4. package/._ENV.md +0 -0
  5. package/._LEGAL.md +0 -0
  6. package/._LICENSE +0 -0
  7. package/._README.md +0 -0
  8. package/._eslint.config.mjs +0 -0
  9. package/._package.json +0 -0
  10. package/._pnpm-lock.template.yaml +0 -0
  11. package/._pnpm-workspace.template.yaml +0 -0
  12. package/._tsconfig.base.json +0 -0
  13. package/.gitignore +14 -2
  14. package/.tbox/._app.json +0 -0
  15. package/.tbox/._default-modules.json +0 -0
  16. package/.tbox/._miniapp-containers.json +0 -0
  17. package/.tbox/app.json +1 -1
  18. package/.tbox/default-modules.json +1 -1
  19. package/.tbox/factory/._chat.json +0 -0
  20. package/.tbox/factory/chat.json +9 -0
  21. package/.tbox/miniapp-containers.json +1 -1
  22. package/AGENTS.md +64 -13
  23. package/ENV.md +4 -4
  24. package/README.md +24 -20
  25. package/apps/._AGENTS.md +0 -0
  26. package/apps/AGENTS.md +0 -4
  27. package/apps/client/._index.html +0 -0
  28. package/apps/client/._package.json +0 -0
  29. package/apps/client/._tsconfig.json +0 -0
  30. package/apps/client/._vite.config.ts +0 -0
  31. package/apps/client/index.html +1 -20
  32. package/apps/client/package.json +4 -3
  33. package/apps/client/scripts/._acceptance-changes.test.mjs +0 -0
  34. package/apps/client/scripts/._check-evidence.mjs +0 -0
  35. package/apps/client/scripts/._color-scan.mjs +0 -0
  36. package/apps/client/scripts/._color-scan.test.mjs +0 -0
  37. package/apps/client/scripts/._evidence-gate.mjs +0 -0
  38. package/apps/client/scripts/._evidence-gate.test.mjs +0 -0
  39. package/apps/client/scripts/._experience-checks.mjs +0 -0
  40. package/apps/client/scripts/._geometry-kernel.test.mjs +0 -0
  41. package/apps/client/scripts/._in-process-checks.mjs +0 -0
  42. package/apps/client/scripts/._probe-checks.mjs +0 -0
  43. package/apps/client/scripts/._render-card.mjs +0 -0
  44. package/apps/client/scripts/._sample-entries.test.mjs +0 -0
  45. package/apps/client/scripts/._storyboard.test.mjs +0 -0
  46. package/apps/client/scripts/._surface-css.mjs +0 -0
  47. package/apps/client/scripts/._theme-kernel.mjs +0 -0
  48. package/apps/client/scripts/._theme-kernel.test.mjs +0 -0
  49. package/apps/client/scripts/acceptance-changes.test.mjs +97 -0
  50. package/apps/client/scripts/check-evidence.mjs +1402 -0
  51. package/apps/client/scripts/color-scan.mjs +66 -0
  52. package/apps/client/scripts/color-scan.test.mjs +25 -0
  53. package/apps/client/scripts/evidence-gate.mjs +337 -0
  54. package/apps/client/scripts/evidence-gate.test.mjs +135 -0
  55. package/apps/client/scripts/experience-checks.mjs +163 -0
  56. package/apps/client/scripts/geometry-kernel.test.mjs +92 -0
  57. package/apps/client/scripts/in-process-checks.mjs +51 -0
  58. package/apps/client/scripts/lib/._card-registry.mjs +0 -0
  59. package/apps/client/scripts/lib/._card-registry.test.mjs +0 -0
  60. package/apps/client/scripts/lib/._evidence-inputs.mjs +0 -0
  61. package/apps/client/scripts/lib/._evidence-inputs.test.mjs +0 -0
  62. package/apps/client/scripts/lib/._static-render.mjs +0 -0
  63. package/apps/client/scripts/lib/._static-render.test.mjs +0 -0
  64. package/apps/client/scripts/lib/card-registry.mjs +81 -0
  65. package/apps/client/scripts/lib/card-registry.test.mjs +59 -0
  66. package/apps/client/scripts/lib/evidence-inputs.mjs +91 -0
  67. package/apps/client/scripts/lib/evidence-inputs.test.mjs +27 -0
  68. package/apps/client/scripts/lib/static-render.mjs +35 -0
  69. package/apps/client/scripts/lib/static-render.test.mjs +21 -0
  70. package/apps/client/scripts/probe-checks.mjs +85 -0
  71. package/apps/client/scripts/render-card.mjs +710 -0
  72. package/apps/client/scripts/sample-entries.test.mjs +31 -0
  73. package/apps/client/scripts/storyboard.test.mjs +149 -0
  74. package/apps/client/scripts/surface-css.mjs +55 -0
  75. package/apps/client/scripts/theme-kernel.mjs +236 -0
  76. package/apps/client/scripts/theme-kernel.test.mjs +136 -0
  77. package/apps/client/src/._app.config.ts +0 -0
  78. package/apps/client/src/._vite-env.d.ts +0 -0
  79. package/apps/client/src/app.config.ts +43 -0
  80. package/apps/client/src/cards/._AGENTS.md +0 -0
  81. package/apps/client/src/cards/._registry.ts +0 -0
  82. package/apps/client/src/cards/AGENTS.md +11 -0
  83. package/apps/client/src/pages/._page.tsx +0 -0
  84. package/apps/client/src/pages/index/._index.tsx +0 -0
  85. package/apps/client/src/pages/index/index.tsx +1 -1
  86. package/apps/client/src/pages/page.tsx +2 -2
  87. package/apps/client/src/store/._chat.ts +0 -0
  88. package/apps/client/src/store/chat.ts +7 -3
  89. package/apps/client/src/styles/._brand.css +0 -0
  90. package/apps/client/src/styles/._tailwind.css +0 -0
  91. package/apps/client/src/styles/brand.css +50 -0
  92. package/apps/client/src/styles/tailwind.css +326 -0
  93. package/apps/client/src/test/._setup.ts +0 -0
  94. package/apps/client/src/vite-env.d.ts +0 -2
  95. package/apps/client/vite.config.ts +8 -23
  96. package/apps/server/._package.json +0 -0
  97. package/apps/server/._tsconfig.json +0 -0
  98. package/apps/server/._tsup.config.ts +0 -0
  99. package/apps/server/._vitest.config.ts +0 -0
  100. package/apps/server/scripts/._probe.mjs +0 -0
  101. package/apps/server/scripts/._scenario-lib.mjs +0 -0
  102. package/apps/server/scripts/._scenario.mjs +0 -0
  103. package/apps/server/scripts/probe.mjs +387 -0
  104. package/apps/server/scripts/scenario-lib.mjs +295 -0
  105. package/apps/server/scripts/scenario.mjs +67 -0
  106. package/apps/server/src/._app.ts +0 -0
  107. package/apps/server/src/._dev.ts +0 -0
  108. package/apps/server/src/._index.ts +0 -0
  109. package/apps/server/src/._intent-routes.ts +0 -0
  110. package/apps/server/src/._pre-tools.ts +0 -0
  111. package/apps/server/src/app.ts +10 -3
  112. package/apps/server/src/cards/._AGENTS.md +0 -0
  113. package/apps/server/src/cards/AGENTS.md +19 -0
  114. package/apps/server/src/cli/._collect-registry.ts +0 -0
  115. package/apps/server/src/cli/._plugin-doctor.ts +0 -0
  116. package/apps/server/src/cli/._plugin-inspect.ts +0 -0
  117. package/apps/server/src/config/._integration.ts +0 -0
  118. package/apps/server/src/dev.ts +2 -2
  119. package/apps/server/src/index.ts +2 -2
  120. package/apps/server/src/pre-tools.ts +7 -16
  121. package/apps/server/src/tools/._AGENTS.md +0 -0
  122. package/apps/server/src/tools/AGENTS.md +23 -0
  123. package/apps/server/tests/._agent-prompt.test.ts +0 -0
  124. package/apps/server/tests/._cards-registry.test.ts +0 -0
  125. package/apps/server/tests/._deployment-loader.test.ts +0 -0
  126. package/apps/server/tests/._intent-dispatcher.test.ts +0 -0
  127. package/apps/server/tests/._tool-runtime.test.ts +0 -0
  128. package/apps/server/tests/helpers/._register.ts +0 -0
  129. package/apps/server/tests/tool-runtime.test.ts +0 -27
  130. package/config/._AGENTS.md +0 -0
  131. package/config/._README.md +0 -0
  132. package/config/._chat.json +0 -0
  133. package/config/._integrations.json +0 -0
  134. package/config/._llm_provider.json +0 -0
  135. package/config/._plugins.json +0 -0
  136. package/config/AGENTS.md +14 -0
  137. package/config/README.md +4 -4
  138. package/config/chat.json +25 -7
  139. package/config/integrations.json +1 -1
  140. package/docs/agent/._agent-prompt.md +0 -0
  141. package/docs/agent/._card-action.md +0 -0
  142. package/docs/agent/._card.md +0 -0
  143. package/docs/agent/._conversation.md +0 -0
  144. package/docs/agent/._kit.md +0 -0
  145. package/docs/agent/._shell.md +0 -0
  146. package/docs/agent/._state.md +0 -0
  147. package/docs/agent/._style.md +0 -0
  148. package/docs/agent/._tool-emits-card.md +0 -0
  149. package/docs/agent/._tool.md +0 -0
  150. package/docs/agent/._verify.md +0 -0
  151. package/docs/agent/agent-prompt.md +38 -0
  152. package/docs/agent/card-action.md +101 -0
  153. package/docs/agent/card.md +159 -0
  154. package/docs/agent/conversation.md +52 -0
  155. package/docs/agent/kit.md +80 -0
  156. package/docs/agent/shell.md +77 -0
  157. package/docs/agent/state.md +85 -0
  158. package/docs/agent/style.md +107 -0
  159. package/docs/agent/tool-emits-card.md +62 -0
  160. package/docs/agent/tool.md +71 -0
  161. package/docs/agent/verify.md +188 -0
  162. package/eslint.config.mjs +18 -0
  163. package/modules/provider-custom/._AGENTS.md +0 -0
  164. package/modules/provider-custom/._INTEGRATION.md +0 -0
  165. package/modules/provider-custom/._LICENSE +0 -0
  166. package/modules/provider-custom/._README.md +0 -0
  167. package/modules/provider-custom/._package.json +0 -0
  168. package/modules/provider-custom/._tbox.module.json +0 -0
  169. package/modules/provider-custom/._tsconfig.json +0 -0
  170. package/modules/provider-custom/._tsup.config.ts +0 -0
  171. package/modules/provider-custom/AGENTS.md +5 -5
  172. package/modules/provider-custom/INTEGRATION.md +2 -2
  173. package/modules/provider-custom/src/._index.ts +0 -0
  174. package/modules/provider-custom/src/server/._example-adapter.ts +0 -0
  175. package/modules/provider-custom/src/server/._index.ts +0 -0
  176. package/modules/provider-custom/src/server/example-adapter.ts +2 -2
  177. package/modules/provider-custom/src/server/index.ts +1 -1
  178. package/modules/provider-custom/tests/._provider-custom.test.ts +0 -0
  179. package/package.json +33 -6
  180. package/packages/agent-ui-kit/._AGENTS.md +0 -0
  181. package/packages/agent-ui-kit/._LICENSE +0 -0
  182. package/packages/agent-ui-kit/._README.md +0 -0
  183. package/packages/agent-ui-kit/._catalog.json +0 -0
  184. package/packages/agent-ui-kit/._package.json +0 -0
  185. package/packages/agent-ui-kit/._tsconfig.json +0 -0
  186. package/packages/agent-ui-kit/._vitest.config.ts +0 -0
  187. package/packages/agent-ui-kit/AGENTS.md +8 -0
  188. package/packages/agent-ui-kit/README.md +59 -6
  189. package/packages/agent-ui-kit/assets/._keyboard-circle.svg +0 -0
  190. package/packages/agent-ui-kit/assets/._more-circle.svg +0 -0
  191. package/packages/agent-ui-kit/assets/._new-chat.svg +0 -0
  192. package/packages/agent-ui-kit/assets/._quick-command-star.svg +0 -0
  193. package/packages/agent-ui-kit/assets/._send-gradient.svg +0 -0
  194. package/packages/agent-ui-kit/assets/._stop@2x.png +0 -0
  195. package/packages/agent-ui-kit/assets/._voice-circle.svg +0 -0
  196. package/packages/agent-ui-kit/catalog.json +855 -0
  197. package/packages/agent-ui-kit/package.json +24 -9
  198. package/packages/agent-ui-kit/src/._ChatPage.tsx +0 -0
  199. package/packages/agent-ui-kit/src/._chat-config.test.ts +0 -0
  200. package/packages/agent-ui-kit/src/._chat-config.ts +0 -0
  201. package/packages/agent-ui-kit/src/._icons.ts +0 -0
  202. package/packages/agent-ui-kit/src/._index.ts +0 -0
  203. package/packages/agent-ui-kit/src/._preview-provider.tsx +0 -0
  204. package/packages/agent-ui-kit/src/._shell.contract.json +0 -0
  205. package/packages/agent-ui-kit/src/._shell.test.ts +0 -0
  206. package/packages/agent-ui-kit/src/._shell.ts +0 -0
  207. package/packages/agent-ui-kit/src/._store-context.tsx +0 -0
  208. package/packages/agent-ui-kit/src/._surface.test.tsx +0 -0
  209. package/packages/agent-ui-kit/src/._surface.tsx +0 -0
  210. package/packages/agent-ui-kit/src/._types.ts +0 -0
  211. package/packages/agent-ui-kit/src/._vite-env.d.ts +0 -0
  212. package/packages/agent-ui-kit/src/ChatPage.tsx +115 -20
  213. package/packages/agent-ui-kit/src/card/._action-list-pending.test.tsx +0 -0
  214. package/packages/agent-ui-kit/src/card/._define-card.test.ts +0 -0
  215. package/packages/agent-ui-kit/src/card/._define-card.ts +0 -0
  216. package/packages/agent-ui-kit/src/card/._primitives.test.tsx +0 -0
  217. package/packages/agent-ui-kit/src/card/._primitives.tsx +0 -0
  218. package/packages/agent-ui-kit/src/card/._use-card-actions.ts +0 -0
  219. package/packages/agent-ui-kit/src/card/._view-card-inline.test.tsx +0 -0
  220. package/packages/agent-ui-kit/src/card/._view-card.test.tsx +0 -0
  221. package/packages/agent-ui-kit/src/card/._view-card.tsx +0 -0
  222. package/packages/agent-ui-kit/src/card/action-list-pending.test.tsx +91 -0
  223. package/packages/agent-ui-kit/src/card/define-card.test.ts +25 -0
  224. package/packages/agent-ui-kit/src/card/define-card.ts +47 -0
  225. package/packages/agent-ui-kit/src/card/primitives.test.tsx +157 -0
  226. package/packages/agent-ui-kit/src/card/primitives.tsx +717 -0
  227. package/packages/agent-ui-kit/src/card/use-card-actions.ts +86 -0
  228. package/packages/agent-ui-kit/src/card/view-card-inline.test.tsx +42 -0
  229. package/packages/agent-ui-kit/src/card/view-card.test.tsx +79 -0
  230. package/packages/agent-ui-kit/src/card/view-card.tsx +250 -0
  231. package/packages/agent-ui-kit/src/chat-config.test.ts +35 -71
  232. package/packages/agent-ui-kit/src/chat-config.ts +29 -7
  233. package/packages/agent-ui-kit/src/components/._CardRenderer.tsx +0 -0
  234. package/packages/agent-ui-kit/src/components/ActionBar/._DebugButton.test.tsx +0 -0
  235. package/packages/agent-ui-kit/src/components/ActionBar/._DebugButton.tsx +0 -0
  236. package/packages/agent-ui-kit/src/components/ActionBar/._index.test.tsx +0 -0
  237. package/packages/agent-ui-kit/src/components/ActionBar/._index.tsx +0 -0
  238. package/packages/agent-ui-kit/src/components/ActionBar/DebugButton.test.tsx +3 -0
  239. package/packages/agent-ui-kit/src/components/ActionBar/DebugButton.tsx +5 -10
  240. package/packages/agent-ui-kit/src/components/ActionBar/index.tsx +13 -14
  241. package/packages/agent-ui-kit/src/components/BottomSheet/._index.test.tsx +0 -0
  242. package/packages/agent-ui-kit/src/components/BottomSheet/._index.tsx +0 -0
  243. package/packages/agent-ui-kit/src/components/BottomSheet/index.test.tsx +97 -0
  244. package/packages/agent-ui-kit/src/components/BottomSheet/index.tsx +49 -0
  245. package/packages/agent-ui-kit/src/components/ChatHeader/._index.test.tsx +0 -0
  246. package/packages/agent-ui-kit/src/components/ChatHeader/._index.tsx +0 -0
  247. package/packages/agent-ui-kit/src/components/ChatHeader/index.tsx +19 -17
  248. package/packages/agent-ui-kit/src/components/ChatInput/._index.test.tsx +0 -0
  249. package/packages/agent-ui-kit/src/components/ChatInput/._index.tsx +0 -0
  250. package/packages/agent-ui-kit/src/components/ChatInput/index.test.tsx +2 -2
  251. package/packages/agent-ui-kit/src/components/ChatInput/index.tsx +44 -33
  252. package/packages/agent-ui-kit/src/components/ChatInput/voice/._VoicePressField.tsx +0 -0
  253. package/packages/agent-ui-kit/src/components/ChatInput/voice/._VoiceRecordingOverlay.tsx +0 -0
  254. package/packages/agent-ui-kit/src/components/ChatInput/voice/._machine.ts +0 -0
  255. package/packages/agent-ui-kit/src/components/ChatInput/voice/._useVoicePress.ts +0 -0
  256. package/packages/agent-ui-kit/src/components/ChatInput/voice/VoicePressField.tsx +12 -3
  257. package/packages/agent-ui-kit/src/components/ChatInput/voice/VoiceRecordingOverlay.tsx +9 -9
  258. package/packages/agent-ui-kit/src/components/ChatInput/voice/useVoicePress.ts +1 -1
  259. package/packages/agent-ui-kit/src/components/HistoryEntry/._index.tsx +0 -0
  260. package/packages/agent-ui-kit/src/components/HistoryEntry/index.tsx +4 -4
  261. package/packages/agent-ui-kit/src/components/MediaList/._index.tsx +0 -0
  262. package/packages/agent-ui-kit/src/components/MediaList/index.tsx +42 -28
  263. package/packages/agent-ui-kit/src/components/MessageBubble/._index.test.tsx +0 -0
  264. package/packages/agent-ui-kit/src/components/MessageBubble/._index.tsx +0 -0
  265. package/packages/agent-ui-kit/src/components/MessageBubble/index.tsx +59 -28
  266. package/packages/agent-ui-kit/src/components/PullDownIndicator/._index.tsx +0 -0
  267. package/packages/agent-ui-kit/src/components/PullDownIndicator/index.tsx +3 -4
  268. package/packages/agent-ui-kit/src/components/QuickCommands/._index.test.tsx +0 -0
  269. package/packages/agent-ui-kit/src/components/QuickCommands/._index.tsx +0 -0
  270. package/packages/agent-ui-kit/src/components/QuickCommands/index.test.tsx +3 -1
  271. package/packages/agent-ui-kit/src/components/QuickCommands/index.tsx +33 -10
  272. package/packages/agent-ui-kit/src/components/ReasoningBlock/._index.tsx +0 -0
  273. package/packages/agent-ui-kit/src/components/ReasoningBlock/index.tsx +14 -9
  274. package/packages/agent-ui-kit/src/components/ScrollToBottomButton/._index.tsx +0 -0
  275. package/packages/agent-ui-kit/src/components/ScrollToBottomButton/index.tsx +7 -5
  276. package/packages/agent-ui-kit/src/components/ToolCallBlock/._detail.test.ts +0 -0
  277. package/packages/agent-ui-kit/src/components/ToolCallBlock/._detail.ts +0 -0
  278. package/packages/agent-ui-kit/src/components/ToolCallBlock/._index.test.tsx +0 -0
  279. package/packages/agent-ui-kit/src/components/ToolCallBlock/._index.tsx +0 -0
  280. package/packages/agent-ui-kit/src/components/ToolCallBlock/._titles.ts +0 -0
  281. package/packages/agent-ui-kit/src/components/ToolCallBlock/index.tsx +58 -38
  282. package/packages/agent-ui-kit/src/hooks/._use-drag-gesture.test.ts +0 -0
  283. package/packages/agent-ui-kit/src/hooks/._use-drag-gesture.ts +0 -0
  284. package/packages/agent-ui-kit/src/hooks/._use-pull-down-history.ts +0 -0
  285. package/packages/agent-ui-kit/src/hooks/._use-pull-down-wheel-native.test.ts +0 -0
  286. package/packages/agent-ui-kit/src/hooks/._useMediaUpload.ts +0 -0
  287. package/packages/agent-ui-kit/src/hooks/._useTTSAutoPlay.ts +0 -0
  288. package/packages/agent-ui-kit/src/icons.ts +39 -0
  289. package/packages/agent-ui-kit/src/index.ts +76 -2
  290. package/packages/agent-ui-kit/src/overlay/._Overlay.tsx +0 -0
  291. package/packages/agent-ui-kit/src/overlay/._focus.ts +0 -0
  292. package/packages/agent-ui-kit/src/overlay/._index.ts +0 -0
  293. package/packages/agent-ui-kit/src/overlay/._inert.ts +0 -0
  294. package/packages/agent-ui-kit/src/overlay/._layers.ts +0 -0
  295. package/packages/agent-ui-kit/src/overlay/._overlay.ssr.test.tsx +0 -0
  296. package/packages/agent-ui-kit/src/overlay/._overlay.test.tsx +0 -0
  297. package/packages/agent-ui-kit/src/overlay/._presence.ts +0 -0
  298. package/packages/agent-ui-kit/src/overlay/._scroll-lock.ts +0 -0
  299. package/packages/agent-ui-kit/src/overlay/._stack.ts +0 -0
  300. package/packages/agent-ui-kit/src/overlay/._use-overlay.ts +0 -0
  301. package/packages/agent-ui-kit/src/overlay/Overlay.tsx +154 -0
  302. package/packages/agent-ui-kit/src/overlay/focus.ts +53 -0
  303. package/packages/agent-ui-kit/src/overlay/index.ts +16 -0
  304. package/packages/agent-ui-kit/src/overlay/inert.ts +27 -0
  305. package/packages/agent-ui-kit/src/overlay/layers.ts +21 -0
  306. package/packages/agent-ui-kit/src/overlay/overlay.ssr.test.tsx +27 -0
  307. package/packages/agent-ui-kit/src/overlay/overlay.test.tsx +209 -0
  308. package/packages/agent-ui-kit/src/overlay/presence.ts +86 -0
  309. package/packages/agent-ui-kit/src/overlay/scroll-lock.ts +62 -0
  310. package/packages/agent-ui-kit/src/overlay/stack.ts +111 -0
  311. package/packages/agent-ui-kit/src/overlay/use-overlay.ts +80 -0
  312. package/packages/agent-ui-kit/src/preview-provider.tsx +47 -0
  313. package/packages/agent-ui-kit/src/shell.contract.json +75 -0
  314. package/packages/agent-ui-kit/src/shell.test.ts +72 -0
  315. package/packages/agent-ui-kit/src/shell.ts +60 -0
  316. package/packages/agent-ui-kit/src/surface.test.tsx +35 -0
  317. package/packages/agent-ui-kit/src/surface.tsx +44 -0
  318. package/packages/agent-ui-kit/src/test/._setup.ts +0 -0
  319. package/packages/agent-ui-kit/src/theme/._base.css +0 -0
  320. package/packages/agent-ui-kit/src/theme/._contract.json +0 -0
  321. package/packages/agent-ui-kit/src/theme/._motion.css +0 -0
  322. package/packages/agent-ui-kit/src/theme/._theme-contract.test.ts +0 -0
  323. package/packages/agent-ui-kit/src/theme/._theme.ts +0 -0
  324. package/packages/agent-ui-kit/src/theme/._tokens.css +0 -0
  325. package/packages/agent-ui-kit/src/theme/base.css +167 -0
  326. package/packages/agent-ui-kit/src/theme/contract.json +123 -2
  327. package/packages/agent-ui-kit/src/theme/theme-contract.test.ts +19 -3
  328. package/packages/agent-ui-kit/src/theme/{tokens.less → tokens.css} +19 -20
  329. package/packages/agent-ui-kit/src/utils/._copyText.ts +0 -0
  330. package/packages/agent-ui-kit/src/utils/._haptics.test.ts +0 -0
  331. package/packages/agent-ui-kit/src/utils/._haptics.ts +0 -0
  332. package/packages/agent-ui-kit/src/utils/._image-preview-host.tsx +0 -0
  333. package/packages/agent-ui-kit/src/utils/._imagePreview.test.ts +0 -0
  334. package/packages/agent-ui-kit/src/utils/._imagePreview.ts +0 -0
  335. package/packages/agent-ui-kit/src/utils/._pull-down-machine.test.ts +0 -0
  336. package/packages/agent-ui-kit/src/utils/._pull-down-machine.ts +0 -0
  337. package/packages/agent-ui-kit/src/utils/._session-error.ts +0 -0
  338. package/packages/agent-ui-kit/src/utils/._toast.test.ts +0 -0
  339. package/packages/agent-ui-kit/src/utils/._toast.ts +0 -0
  340. package/packages/agent-ui-kit/src/utils/._tool-call-display.test.ts +0 -0
  341. package/packages/agent-ui-kit/src/utils/._tool-call-display.ts +0 -0
  342. package/packages/agent-ui-kit/src/utils/image-preview-host.tsx +95 -0
  343. package/packages/agent-ui-kit/src/utils/imagePreview.test.ts +32 -0
  344. package/packages/agent-ui-kit/src/utils/imagePreview.ts +14 -5
  345. package/packages/agent-ui-kit/src/utils/toast.test.ts +64 -0
  346. package/packages/agent-ui-kit/src/utils/toast.ts +100 -7
  347. package/packages/contracts-mall/._package.json +0 -0
  348. package/packages/contracts-mall/._tsconfig.json +0 -0
  349. package/packages/contracts-mall/src/._index.ts +0 -0
  350. package/packages/contracts-mall/src/._runtime.ts +0 -0
  351. package/packages/contracts-mall/src/server/._index.ts +0 -0
  352. package/packages/shared/._AGENTS.md +0 -0
  353. package/packages/shared/._package.json +0 -0
  354. package/packages/shared/._tsconfig.json +0 -0
  355. package/packages/shared/AGENTS.md +4 -2
  356. package/packages/shared/package.json +7 -0
  357. package/packages/shared/src/._index.ts +0 -0
  358. package/pnpm-lock.template.yaml +712 -779
  359. package/pnpm-workspace.template.yaml +19 -13
  360. package/profiles/._mall.json +0 -0
  361. package/profiles/mall/._TEMPLATE.md +0 -0
  362. package/profiles/mall/._chat.overrides.json +0 -0
  363. package/profiles/mall/chat.overrides.json +12 -0
  364. package/profiles/mall/config/._agent.jsonc +0 -0
  365. package/profiles/mall/config/._chat.json +0 -0
  366. package/profiles/mall/config/._knowledge.json +0 -0
  367. package/profiles/mall/config/chat.json +14 -6
  368. package/profiles/mall.json +2 -2
  369. package/scenarios/._README.md +0 -0
  370. package/scenarios/README.md +7 -0
  371. package/scripts/._assert-pack.mjs +0 -0
  372. package/scripts/._build.sh +0 -0
  373. package/scripts/._check-css-target.mjs +0 -0
  374. package/scripts/._check-fast.mjs +0 -0
  375. package/scripts/._check-workspace.mjs +0 -0
  376. package/scripts/._checks.json +0 -0
  377. package/scripts/._deliver.mjs +0 -0
  378. package/scripts/._dev-alipay.mjs +0 -0
  379. package/scripts/._dev.sh +0 -0
  380. package/scripts/._generate.mjs +0 -0
  381. package/scripts/._prepare.sh +0 -0
  382. package/scripts/._shell-probe.mjs +0 -0
  383. package/scripts/._smoke.mjs +0 -0
  384. package/scripts/._start.sh +0 -0
  385. package/scripts/._stop.sh +0 -0
  386. package/scripts/._storyboard.mjs +0 -0
  387. package/scripts/._verify-generated.mjs +0 -0
  388. package/scripts/assert-pack.mjs +48 -0
  389. package/scripts/check-css-target.mjs +54 -0
  390. package/scripts/check-fast.mjs +119 -0
  391. package/scripts/check-workspace.mjs +68 -19
  392. package/scripts/checks.json +627 -0
  393. package/scripts/deliver.mjs +183 -0
  394. package/scripts/dev-alipay.mjs +1 -1
  395. package/scripts/lib/._chrome-pipe.mjs +0 -0
  396. package/scripts/lib/._geometry-kernel.mjs +0 -0
  397. package/scripts/lib/chrome-pipe.mjs +95 -0
  398. package/scripts/lib/geometry-kernel.mjs +137 -0
  399. package/scripts/shell-probe.mjs +280 -0
  400. package/scripts/storyboard.mjs +350 -0
  401. package/tsconfig.base.json +1 -0
  402. package/apps/client/.tbox-gen/app-kind.ts +0 -1
  403. package/apps/client/.tbox-gen/documents/_tbox/card-preview.html +0 -38
  404. package/apps/client/.tbox-gen/documents/index.html +0 -39
  405. package/apps/client/.tbox-gen/entries/card-preview.tsx +0 -18
  406. package/apps/client/.tbox-gen/entries/index.tsx +0 -18
  407. package/apps/client/.tbox-gen/manifest.json +0 -17
  408. package/apps/client/.tbox-gen/registry.client.ts +0 -6
  409. package/apps/client/.tbox-gen/registry.server.ts +0 -15
  410. package/apps/client/STYLE_GUIDE.md +0 -81
  411. package/apps/client/VISUAL_RESTORE.md +0 -90
  412. package/apps/client/src/platform/AgentChatApp.tsx +0 -6
  413. package/apps/client/src/platform/AppShell.tsx +0 -42
  414. package/apps/client/src/platform/agent-runtime.ts +0 -16
  415. package/apps/client/src/platform/bootstrap.ts +0 -55
  416. package/apps/client/src/platform/card-preview-page.tsx +0 -10
  417. package/apps/client/src/platform/mount-page.tsx +0 -20
  418. package/apps/client/src/platform/state/createPersistedStore.ts +0 -19
  419. package/apps/server/src/tools/clock.tool.ts +0 -24
  420. package/apps/server/src/tools/translate.tool.ts +0 -47
  421. package/packages/agent-ui-kit/src/ChatPage.less +0 -62
  422. package/packages/agent-ui-kit/src/components/ActionBar/index.less +0 -123
  423. package/packages/agent-ui-kit/src/components/ChatHeader/index.less +0 -148
  424. package/packages/agent-ui-kit/src/components/ChatInput/index.less +0 -394
  425. package/packages/agent-ui-kit/src/components/HistoryEntry/index.less +0 -49
  426. package/packages/agent-ui-kit/src/components/MediaList/index.less +0 -241
  427. package/packages/agent-ui-kit/src/components/MessageBubble/index.less +0 -325
  428. package/packages/agent-ui-kit/src/components/PullDownIndicator/index.less +0 -32
  429. package/packages/agent-ui-kit/src/components/QuickCommands/index.less +0 -63
  430. package/packages/agent-ui-kit/src/components/ReasoningBlock/index.less +0 -90
  431. package/packages/agent-ui-kit/src/components/ScrollToBottomButton/index.less +0 -32
  432. package/packages/agent-ui-kit/src/components/ToolCallBlock/index.less +0 -312
  433. package/packages/agent-ui-kit/src/theme/global.less +0 -99
  434. package/profiles/mall/config/llm_provider.json +0 -5
  435. package/profiles/mall/config/plugins.json +0 -3
  436. /package/packages/agent-ui-kit/src/theme/{motion.less → motion.css} +0 -0
@@ -0,0 +1,183 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * pnpm deliver —— 交付唯一入口。
4
+ *
5
+ * 跑 check:fast,把裁决、验收覆盖、能力偏离、漂移、未运行项收成一份摘要(stdout ≤1500 字符)
6
+ * 与 .tbox/evidence/delivery.json + 应用根 DELIVERY.md。
7
+ *
8
+ * 选项:--json(stdout 只输出交付 JSON)/ --policy quick|standard|deep / --commit(只提交 DELIVERY.md)
9
+ * 退出码:0 deliverable / 1 failing / 2 incomplete 或 reopened。
10
+ */
11
+ import { spawnSync } from 'node:child_process';
12
+ import { existsSync, mkdirSync, readdirSync, readFileSync, statSync, writeFileSync } from 'node:fs';
13
+ import path from 'node:path';
14
+
15
+ const appDir = path.resolve(import.meta.dirname, '..');
16
+ const argv = process.argv.slice(2);
17
+ const jsonOutput = argv.includes('--json');
18
+ const commitSummary = argv.includes('--commit');
19
+ const policyIndex = argv.indexOf('--policy');
20
+ const policyArg = policyIndex >= 0 ? argv[policyIndex + 1] : undefined;
21
+ const POLICY_MAP = { quick: 'static', standard: 'visual', deep: 'flow' };
22
+ const platformPolicy = policyArg ? POLICY_MAP[policyArg] ?? policyArg : process.env.TBOX_POLICY;
23
+ if (policyArg && !POLICY_MAP[policyArg]) {
24
+ console.error('未知档位:' + policyArg + '(可用:quick / standard / deep)');
25
+ process.exit(2);
26
+ }
27
+ // 先跑壳探针(有 Chrome 时产出布局证据;没有则如实 not-run,不阻断)。
28
+ // 结果未过期就复用:输入(壳配置/主题/kit)没变时不必重复起 Chrome。
29
+ const probeInputs = [
30
+ 'config/chat.json',
31
+ 'apps/client/src/styles/brand.css',
32
+ 'apps/client/src/styles/tokens.css',
33
+ ].map((rel) => path.join(appDir, rel)).filter((file) => existsSync(file));
34
+ const shellFile = path.join(appDir, '.tbox', 'evidence', 'shell.json');
35
+ const newestMtime = (root) => {
36
+ let newest = 0;
37
+ const walk = (dir) => {
38
+ let entries;
39
+ try { entries = readdirSync(dir, { withFileTypes: true }); } catch { return; }
40
+ for (const entry of entries) {
41
+ if (entry.name === 'node_modules' || entry.name === 'dist' || entry.name === '.git') continue;
42
+ const full = path.join(dir, entry.name);
43
+ if (entry.isDirectory()) walk(full);
44
+ else { try { newest = Math.max(newest, statSync(full).mtimeMs); } catch { /* ignore */ } }
45
+ }
46
+ };
47
+ walk(root);
48
+ return newest;
49
+ };
50
+ const newestInput = Math.max(
51
+ ...probeInputs.map((file) => statSync(file).mtimeMs),
52
+ newestMtime(path.join(appDir, 'packages/agent-ui-kit/src')),
53
+ 0,
54
+ );
55
+ const readShellInfo = () => {
56
+ try {
57
+ return JSON.parse(readFileSync(shellFile, 'utf8'));
58
+ } catch {
59
+ return undefined;
60
+ }
61
+ };
62
+ const probeFresh = existsSync(shellFile) && statSync(shellFile).mtimeMs + 1000 >= newestInput;
63
+ let shellInfo = readShellInfo();
64
+ let probeOk = probeFresh;
65
+ if (!probeFresh) {
66
+ const probe = spawnSync('node', ['scripts/shell-probe.mjs'], { cwd: appDir, stdio: 'ignore', timeout: 120000 });
67
+ probeOk = probe.status === 0;
68
+ shellInfo = readShellInfo();
69
+ } else if (!jsonOutput) {
70
+ console.log('(复用未过期的壳探针结果)');
71
+ }
72
+ // 故事板:卡片/品牌/壳任一变了就重跑(storyboard 自己带缓存,命中时 <2s)。
73
+ // 档位与裁决同源:quick 映射成 static,static 档不要求布局证据。
74
+ if (platformPolicy !== 'static') {
75
+ // 只有壳探针真正成功(shell.json 带 html 标记且 html 在场)才允许 storyboard 复用它:
76
+ // probe 失败但旧 shell.html 残留时,跳过会让故事板用旧壳冒充当前。
77
+ const shellReady = probeOk && Boolean(shellInfo?.html) && existsSync(path.join(appDir, String(shellInfo.html)));
78
+ spawnSync('node', ['scripts/storyboard.mjs'], {
79
+ cwd: appDir,
80
+ stdio: 'ignore',
81
+ timeout: 120000,
82
+ env: { ...process.env, ...(shellReady ? { TBOX_SHELL_FRESH: '1' } : {}) },
83
+ });
84
+ }
85
+ const run = spawnSync('node', ['scripts/check-fast.mjs'], {
86
+ cwd: appDir, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], maxBuffer: 32 * 1024 * 1024,
87
+ env: { ...process.env, ...(platformPolicy ? { TBOX_POLICY: platformPolicy } : {}) },
88
+ });
89
+ const stdout = String(run.stdout ?? '');
90
+ const parse = () => {
91
+ const lines = stdout.trim().split('\n');
92
+ for (let i = lines.length - 1; i >= 0; i -= 1) {
93
+ const line = lines[i].trim();
94
+ if (!line.startsWith('{')) continue;
95
+ try { return JSON.parse(line); } catch { /* 继续找 */ }
96
+ }
97
+ return undefined;
98
+ };
99
+ const summary = parse();
100
+ if (!summary) {
101
+ console.error((String(run.stderr ?? '') || stdout || 'check:fast 未产出摘要').slice(0, 1500));
102
+ process.exit(1);
103
+ }
104
+ const verdict = summary.verdict ?? (summary.ok ? 'unknown' : 'failing');
105
+ const acceptance = summary.acceptance ?? {};
106
+ const delivery = summary.delivery ?? {};
107
+ const policy = summary.policy ?? 'unknown';
108
+ const drift = Array.isArray(delivery.drift) ? delivery.drift : [];
109
+ const capability = Array.isArray(delivery.capabilityDrift) ? delivery.capabilityDrift : [];
110
+ // 偏离出厂 = 能力开关 + 默认模块集(两处登记,同一行账)。
111
+ const moduleDrift = Array.isArray(delivery.moduleDrift) ? delivery.moduleDrift : [];
112
+ const notRun = Array.isArray(summary.notRun) ? summary.notRun : [];
113
+ const deferred = Array.isArray(delivery.deferred) ? delivery.deferred : [];
114
+
115
+ const lines = [];
116
+ lines.push('裁决:' + verdict);
117
+ if (summary.acceptance) {
118
+ lines.push('验收:' + (acceptance.items ?? 0) + ' 项 / 覆盖 ' + (acceptance.covered ?? 0) + ' / handoff ' + (acceptance.handoff ?? acceptance.review ?? 0));
119
+ }
120
+ lines.push('档位:' + policy);
121
+ // 视觉证据在裁决之后固定给出——「界面看过了」有图可指,agent 不必自己再去看。
122
+ const storyboardFile = path.join(appDir, '.tbox', 'evidence', 'storyboard.json');
123
+ if (existsSync(storyboardFile)) {
124
+ try {
125
+ const board = JSON.parse(readFileSync(storyboardFile, 'utf8'));
126
+ if (board.status === 'not-run') {
127
+ lines.push('视觉证据:未生成(' + (board.reason ?? '无原因') + ')');
128
+ } else {
129
+ const problems = (board.frames ?? []).reduce((total, frame) => total + (frame.problems?.length ?? 0), 0);
130
+ const first = (board.images ?? [])[0];
131
+ lines.push('视觉证据:' + (first ? first.file : '(无图)') + '(' + (board.frames ?? []).length + ' 帧,几何问题 ' + problems + ' 个)');
132
+ }
133
+ } catch { /* 坏文件不影响交付 */ }
134
+ }
135
+ const driftItems = [
136
+ ...capability.map((item) => item.key + '(' + item.change + ')'),
137
+ ...moduleDrift.map((item) => item.key + (item.kind === 'module-removed' ? '(已移除)' : '(新增)')),
138
+ ];
139
+ lines.push(driftItems.length ? '偏离出厂:' + driftItems.join('、') : '偏离出厂:无');
140
+ const changeSummary = Array.isArray(delivery.acceptanceChangeSummary) ? delivery.acceptanceChangeSummary : [];
141
+ lines.push(changeSummary.length ? '验收变更:' + changeSummary.slice(0, 5).join('、') : '验收变更:无');
142
+ const notRunList = [...notRun.map((item) => String(item)), ...deferred.map((item) => item.id + '(' + item.lane + ')')];
143
+ lines.push(notRunList.length ? '未运行:' + notRunList.slice(0, 6).join('、') : '未运行:无');
144
+ lines.push('下一步:' + (summary.next ?? (verdict === 'deliverable' ? '按摘要交付' : '先修失败项')));
145
+
146
+ let text = lines.join('\n');
147
+ if (text.length > 1500) text = text.slice(0, 1450) + '\n…(已截断)';
148
+
149
+ const evidenceDir = path.join(appDir, '.tbox', 'evidence');
150
+ mkdirSync(evidenceDir, { recursive: true });
151
+ const record = {
152
+ schemaVersion: 1,
153
+ generatedAt: new Date().toISOString(),
154
+ verdict,
155
+ policy,
156
+ acceptance,
157
+ capabilityDrift: capability,
158
+ drift,
159
+ notRun: notRunList,
160
+ next: summary.next ?? null,
161
+ source: existsSync(path.join(evidenceDir, 'gate.json')) ? '.tbox/evidence/gate.json' : null,
162
+ };
163
+ writeFileSync(path.join(evidenceDir, 'delivery.json'), JSON.stringify(record, null, 2) + '\n', 'utf8');
164
+ writeFileSync(path.join(appDir, 'DELIVERY.md'), '# 交付摘要\n\n' + lines.map((line) => '- ' + line).join('\n') + '\n\n> 由 pnpm deliver 生成;完整证据在 .tbox/evidence/。\n', 'utf8');
165
+
166
+ if (commitSummary) {
167
+ const staged = spawnSync('git', ['add', 'DELIVERY.md'], { cwd: appDir, encoding: 'utf8' });
168
+ const committed = staged.status === 0
169
+ ? spawnSync('git', ['commit', '-m', 'chore: delivery summary', '--', 'DELIVERY.md'], { cwd: appDir, encoding: 'utf8' })
170
+ : staged;
171
+ if (committed.status !== 0) console.error('(--commit 未完成:' + String(committed.stderr ?? '').trim() + ')');
172
+ else console.error('已提交 DELIVERY.md');
173
+ }
174
+
175
+ if (jsonOutput) {
176
+ console.log(JSON.stringify(record, null, 2));
177
+ console.error(text);
178
+ } else {
179
+ console.log(text);
180
+ }
181
+ if (verdict === 'failing') process.exit(1);
182
+ if (verdict === 'incomplete' || verdict === 'reopened' || verdict === 'unspecified') process.exit(2);
183
+ process.exit(0);
@@ -50,7 +50,7 @@ export function startDevAlipay({
50
50
  const containerDir = path.join(projectDir, 'apps/miniapp-container-alipay');
51
51
  if (!existsSync(path.join(containerDir, 'package.json'))) {
52
52
  log.error('未找到支付宝小程序容器(apps/miniapp-container-alipay)。先生成容器再重试:');
53
- log.error(' npx --yes @tbox.cn/app-cli miniapp-container init alipay');
53
+ log.error(' pnpm exec tbox-app miniapp-container init alipay');
54
54
  finish(1);
55
55
  return null;
56
56
  }
Binary file
@@ -0,0 +1,95 @@
1
+ /**
2
+ * 无头浏览器的 CDP 会话(--remote-debugging-pipe,零 TCP socket)。
3
+ *
4
+ * 壳探针与故事板共用:一次会话里可以连续 eval / 截图;调用方负责 close。
5
+ * 找不到浏览器时返回 null,由调用方记 not-run(CI 无 Chrome 是常态)。
6
+ */
7
+ import { spawn } from 'node:child_process';
8
+ import { existsSync } from 'node:fs';
9
+
10
+ const CANDIDATES = [
11
+ process.env.TBOX_CHROME,
12
+ process.env.AGENT_BROWSER_EXECUTABLE_PATH,
13
+ '/home/admin/.agent-browser/chrome/chrome-linux64/chrome',
14
+ '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
15
+ '/Applications/Chromium.app/Contents/MacOS/Chromium',
16
+ '/usr/bin/google-chrome',
17
+ '/usr/bin/google-chrome-stable',
18
+ '/usr/bin/chromium',
19
+ '/usr/bin/chromium-browser',
20
+ ].filter(Boolean);
21
+
22
+ export function findChrome(candidates = CANDIDATES) {
23
+ return candidates.find((candidate) => existsSync(candidate));
24
+ }
25
+
26
+ /**
27
+ * 打开一个页面会话。
28
+ *
29
+ * @returns {Promise<null | { call(method: string, params?: object, sessionId?: string): Promise<any>,
30
+ * evaluate(expression: string, sessionId?: string): Promise<unknown>,
31
+ * screenshot(sessionId?: string): Promise<Buffer>,
32
+ * version(): Promise<string>, close(): void, sessionId: string, width: number, height: number }>}
33
+ */
34
+ export async function openChromeSession({ chrome, url, width = 390, height = 844, deviceScaleFactor = 2, settleMs = 800, timeoutMs = 15000 }) {
35
+ if (!chrome) return null;
36
+ const child = spawn(chrome, ['--headless=new', '--disable-gpu', '--no-sandbox', '--hide-scrollbars', '--remote-debugging-pipe', 'about:blank'], { stdio: ['ignore', 'ignore', 'pipe', 'pipe', 'pipe'] });
37
+ let buffer = '';
38
+ let nextId = 0;
39
+ const waiters = new Map();
40
+ const fail = (error) => { for (const waiter of waiters.values()) waiter.reject(error); waiters.clear(); };
41
+ child.stdio[4].on('data', (chunk) => {
42
+ buffer += chunk.toString('utf8');
43
+ const parts = buffer.split('\u0000');
44
+ buffer = parts.pop() ?? '';
45
+ for (const part of parts) {
46
+ if (!part.trim()) continue;
47
+ let message;
48
+ try { message = JSON.parse(part); } catch { continue; }
49
+ const waiter = waiters.get(message.id);
50
+ if (waiter) { waiters.delete(message.id); waiter.resolve(message); }
51
+ }
52
+ });
53
+ child.on('error', (error) => fail(error));
54
+
55
+ const call = (method, params, sessionId) => new Promise((resolve, reject) => {
56
+ const id = ++nextId;
57
+ waiters.set(id, { resolve, reject });
58
+ const payload = { id, method, params: params ?? {} };
59
+ if (sessionId) payload.sessionId = sessionId;
60
+ child.stdio[3].write(JSON.stringify(payload) + '\u0000');
61
+ setTimeout(() => { if (waiters.has(id)) { waiters.delete(id); reject(new Error('CDP timeout: ' + method)); } }, timeoutMs);
62
+ });
63
+
64
+ const targets = await call('Target.getTargets');
65
+ const page = (targets.result?.targetInfos ?? []).find((target) => target.type === 'page');
66
+ const attached = await call('Target.attachToTarget', { targetId: page.targetId, flatten: true });
67
+ const sessionId = attached.result.sessionId;
68
+ await call('Emulation.setDeviceMetricsOverride', { width, height, deviceScaleFactor, mobile: true }, sessionId);
69
+ await call('Page.navigate', { url }, sessionId);
70
+ await new Promise((resolve) => setTimeout(resolve, settleMs));
71
+
72
+ return {
73
+ sessionId,
74
+ width,
75
+ height,
76
+ call,
77
+ async evaluate(expression) {
78
+ const evaluated = await call('Runtime.evaluate', { expression, returnByValue: true }, sessionId);
79
+ const failure = evaluated.result.exceptionDetails;
80
+ if (failure) throw new Error('页面脚本异常:' + (failure.exception?.description ?? failure.text ?? '未知'));
81
+ return evaluated.result.result.value;
82
+ },
83
+ async screenshot() {
84
+ const shot = await call('Page.captureScreenshot', { format: 'png', fromSurface: true, captureBeyondViewport: true }, sessionId);
85
+ return Buffer.from(shot.result.data, 'base64');
86
+ },
87
+ async version() {
88
+ const version = await call('Browser.getVersion');
89
+ return version.result.product;
90
+ },
91
+ close() {
92
+ child.kill();
93
+ },
94
+ };
95
+ }
@@ -0,0 +1,137 @@
1
+ /**
2
+ * 几何内核:一次 DOM 遍历回答「有没有溢出、字号够不够、点击区够不够、截断与空白」。
3
+ *
4
+ * 三处消费者(壳探针、卡片渲染体检、故事板)共用这一份实现;新增一处消费 = 调用它,
5
+ * 不再各写一遍量法。阈值可被 checks.json 的 threshold 字段覆盖。
6
+ *
7
+ * 内核只认识 DOM,不认识「商圈」「卡片」「DSH」:它不读配置、不发请求、不写文件。
8
+ */
9
+ export const GEOMETRY_DEFAULTS = {
10
+ /** 可点元素的最小边长(CSS px) */
11
+ minTarget: 44,
12
+ /** 正文最小字号(CSS px) */
13
+ minFontPx: 12,
14
+ /** 横向溢出容差:1px 内的亚像素误差不算溢出 */
15
+ overflowTolerancePx: 1,
16
+ };
17
+
18
+ /** 默认的「可点元素」选择器:只认原生可交互元素,避免把装饰 div 算进去。 */
19
+ export const DEFAULT_TARGETS = 'button, a, [role="button"], input, select, textarea';
20
+
21
+ /**
22
+ * 浏览器内执行的测量函数源码。调用方把它拼进表达式或 <script>,再调用 tboxGeometry(opts)。
23
+ *
24
+ * opts:
25
+ * targets 可点元素选择器(缺省 DEFAULT_TARGETS)
26
+ * blankSelectors 参与「块间空白」的块选择器数组(缺省空 = 不量空白)
27
+ * thresholds { minTarget, minFontPx, overflowTolerancePx }
28
+ * root 遍历起点选择器(缺省 document.body)
29
+ * typeScale 字号标度白名单(缺省 [12,14,16,18,20])
30
+ */
31
+ export function geometryFunctionSource() {
32
+ return [
33
+ 'function tboxGeometry(opts) {',
34
+ ' var o = opts || {};',
35
+ ' var t = o.thresholds || {};',
36
+ ' var minTarget = typeof t.minTarget === "number" ? t.minTarget : 44;',
37
+ ' var minFontAllowed = typeof t.minFontPx === "number" ? t.minFontPx : 12;',
38
+ ' var tolerance = typeof t.overflowTolerancePx === "number" ? t.overflowTolerancePx : 1;',
39
+ ' var scale = o.typeScale || [12, 14, 16, 18, 20];',
40
+ ' var rootSel = o.root || "body";',
41
+ ' var root = (rootSel === "body" ? document.body : document.querySelector(rootSel)) || document.body;',
42
+ ' var W = window.innerWidth;',
43
+ ' var out = { viewport: { w: W, h: window.innerHeight }, overflowX: 0, overflowRight: 0, clipped: [], smallTargets: [], minFontPx: null, typeScale: { allowed: scale, counts: {}, offScale: [] }, blankGap: null, height: 0 };',
44
+ ' var minFont = 1e9;',
45
+ ' var counts = {};',
46
+ ' var samples = {};',
47
+ ' var nodes = root.querySelectorAll("*");',
48
+ ' for (var i = 0; i < nodes.length; i += 1) {',
49
+ ' var el = nodes[i];',
50
+ ' var rect = el.getBoundingClientRect();',
51
+ ' if (rect.width > 0 && rect.right > W + tolerance) out.overflowRight = Math.max(out.overflowRight, Math.round(rect.right - W));',
52
+ ' if (el.tagName === "SCRIPT" || el.tagName === "STYLE" || el.tagName === "NOSCRIPT") continue;',
53
+ ' if (el.children.length === 0 && (el.textContent || "").trim() !== "") {',
54
+ ' var size = parseFloat(getComputedStyle(el).fontSize);',
55
+ ' if (size > 0) {',
56
+ ' minFont = Math.min(minFont, size);',
57
+ ' var key = Math.round(size * 10) / 10;',
58
+ ' counts[key] = (counts[key] || 0) + 1;',
59
+ ' if (!samples[key]) samples[key] = (el.textContent || "").trim().slice(0, 20);',
60
+ ' }',
61
+ ' if (el.scrollWidth > el.clientWidth + tolerance) {',
62
+ ' var style = getComputedStyle(el);',
63
+ ' var ellipsis = (style.textOverflow || "") === "ellipsis";',
64
+ ' out.clipped.push({ text: (el.textContent || "").trim().slice(0, 24), tag: el.tagName, ellipsis: ellipsis });',
65
+ ' }',
66
+ ' }',
67
+ ' if (rect.width > 0 && el.matches(o.targets || ' + JSON.stringify(DEFAULT_TARGETS) + ')) {',
68
+ ' if (Math.round(rect.width) < minTarget || Math.round(rect.height) < minTarget) {',
69
+ ' out.smallTargets.push({ tag: el.tagName, w: Math.round(rect.width), h: Math.round(rect.height), text: (el.textContent || "").trim().slice(0, 16) });',
70
+ ' }',
71
+ ' }',
72
+ ' }',
73
+ ' out.overflowX = Math.max(0, document.documentElement.scrollWidth - W);',
74
+ ' out.minFontPx = minFont === 1e9 ? null : Math.round(minFont * 10) / 10;',
75
+ ' out.typeScale.counts = counts;',
76
+ ' out.typeScale.offScale = Object.keys(counts).map(Number).filter(function (px) { return scale.indexOf(px) < 0; }).map(function (px) { return { px: px, count: counts[px], sample: samples[px] }; });',
77
+ ' out.smallTargets = out.smallTargets.slice(0, 5);',
78
+ ' out.clipped = out.clipped.slice(0, 10);',
79
+ ' out.height = Math.round(document.documentElement.scrollHeight);',
80
+ ' var blankSels = o.blankSelectors || [];',
81
+ ' if (blankSels.length > 0) {',
82
+ ' var blocks = [];',
83
+ ' for (var s = 0; s < blankSels.length; s += 1) {',
84
+ ' var found = document.querySelectorAll(blankSels[s]);',
85
+ ' for (var f = 0; f < found.length; f += 1) {',
86
+ ' var cs = getComputedStyle(found[f]);',
87
+ ' var r = found[f].getBoundingClientRect();',
88
+ ' if (cs.display !== "none" && cs.visibility !== "hidden" && Number(cs.opacity) > 0 && r.width > 0 && r.height > 0) blocks.push(r);',
89
+ ' }',
90
+ ' }',
91
+ ' blocks.sort(function (a, b) { return a.top - b.top; });',
92
+ ' var maxGap = 0;',
93
+ ' for (var b = 1; b < blocks.length; b += 1) maxGap = Math.max(maxGap, Math.round(blocks[b].top - blocks[b - 1].bottom));',
94
+ ' out.blankGap = { maxGap: Math.max(0, maxGap), blocks: blocks.length };',
95
+ ' }',
96
+ ' return out;',
97
+ '}',
98
+ ].join('\n');
99
+ }
100
+
101
+ /** 阈值:checks.json 里对应检查的 threshold 覆盖缺省。 */
102
+ export function loadThresholds(checksJson, ids = []) {
103
+ const merged = { ...GEOMETRY_DEFAULTS };
104
+ const list = Array.isArray(checksJson?.checks) ? checksJson.checks : [];
105
+ for (const id of ids) {
106
+ const check = list.find((item) => item.id === id);
107
+ if (check && check.threshold && typeof check.threshold === 'object') Object.assign(merged, check.threshold);
108
+ }
109
+ return merged;
110
+ }
111
+
112
+ /** CDP Runtime.evaluate 可直接执行的表达式;返回 JSON 字符串。 */
113
+ export function geometryExpression(options = {}) {
114
+ const { thresholds = {}, ...rest } = options;
115
+ return [
116
+ '(() => {',
117
+ geometryFunctionSource(),
118
+ ' return JSON.stringify(tboxGeometry(' + JSON.stringify({ ...rest, thresholds }) + '));',
119
+ '})()',
120
+ ].join('\n');
121
+ }
122
+
123
+ /** 拼进 HTML 的 <script> 内容:量完写进 <pre id="__tbox_audit">,供 --dump-dom 读回。 */
124
+ export function geometryAuditScript(options = {}) {
125
+ return [
126
+ '<script>',
127
+ '(function () {',
128
+ geometryFunctionSource(),
129
+ ' var out = tboxGeometry(' + JSON.stringify(options) + ');',
130
+ ' var pre = document.createElement("pre");',
131
+ ' pre.id = "__tbox_audit";',
132
+ ' pre.textContent = JSON.stringify(out);',
133
+ ' document.body.appendChild(pre);',
134
+ '})();',
135
+ '</script>',
136
+ ].join('\n');
137
+ }