@tbox.cn/app-template-agent 0.10.37 → 1.0.0-alpha.10
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.
- package/._.gitignore +0 -0
- package/._.nvmrc +0 -0
- package/._AGENTS.md +0 -0
- package/._ENV.md +0 -0
- package/._LEGAL.md +0 -0
- package/._LICENSE +0 -0
- package/._README.md +0 -0
- package/._eslint.config.mjs +0 -0
- package/._package.json +0 -0
- package/._pnpm-lock.template.yaml +0 -0
- package/._pnpm-workspace.template.yaml +0 -0
- package/._tsconfig.base.json +0 -0
- package/.gitignore +14 -2
- package/.tbox/._app.json +0 -0
- package/.tbox/._default-modules.json +0 -0
- package/.tbox/._miniapp-containers.json +0 -0
- package/.tbox/app.json +3 -19
- package/.tbox/default-modules.json +4 -1
- package/.tbox/factory/._chat.json +0 -0
- package/.tbox/factory/chat.json +9 -0
- package/.tbox/miniapp-containers.json +1 -1
- package/AGENTS.md +96 -148
- package/ENV.md +4 -4
- package/README.md +31 -27
- package/apps/._AGENTS.md +0 -0
- package/apps/AGENTS.md +9 -0
- package/apps/client/._index.html +0 -0
- package/apps/client/._package.json +0 -0
- package/apps/client/._tsconfig.json +0 -0
- package/apps/client/._vite.config.ts +0 -0
- package/apps/client/index.html +1 -20
- package/apps/client/package.json +7 -5
- package/apps/client/scripts/._acceptance-changes.test.mjs +0 -0
- package/apps/client/scripts/._check-evidence.mjs +0 -0
- package/apps/client/scripts/._color-scan.mjs +0 -0
- package/apps/client/scripts/._color-scan.test.mjs +0 -0
- package/apps/client/scripts/._evidence-gate.mjs +0 -0
- package/apps/client/scripts/._evidence-gate.test.mjs +0 -0
- package/apps/client/scripts/._experience-checks.mjs +0 -0
- package/apps/client/scripts/._geometry-kernel.test.mjs +0 -0
- package/apps/client/scripts/._in-process-checks.mjs +0 -0
- package/apps/client/scripts/._probe-checks.mjs +0 -0
- package/apps/client/scripts/._render-card.mjs +0 -0
- package/apps/client/scripts/._sample-entries.test.mjs +0 -0
- package/apps/client/scripts/._storyboard.test.mjs +0 -0
- package/apps/client/scripts/._surface-css.mjs +0 -0
- package/apps/client/scripts/._theme-kernel.mjs +0 -0
- package/apps/client/scripts/._theme-kernel.test.mjs +0 -0
- package/apps/client/scripts/acceptance-changes.test.mjs +97 -0
- package/apps/client/scripts/check-evidence.mjs +1402 -0
- package/apps/client/scripts/color-scan.mjs +66 -0
- package/apps/client/scripts/color-scan.test.mjs +25 -0
- package/apps/client/scripts/evidence-gate.mjs +337 -0
- package/apps/client/scripts/evidence-gate.test.mjs +135 -0
- package/apps/client/scripts/experience-checks.mjs +163 -0
- package/apps/client/scripts/geometry-kernel.test.mjs +92 -0
- package/apps/client/scripts/in-process-checks.mjs +51 -0
- package/apps/client/scripts/lib/._card-registry.mjs +0 -0
- package/apps/client/scripts/lib/._card-registry.test.mjs +0 -0
- package/apps/client/scripts/lib/._evidence-inputs.mjs +0 -0
- package/apps/client/scripts/lib/._evidence-inputs.test.mjs +0 -0
- package/apps/client/scripts/lib/._static-render.mjs +0 -0
- package/apps/client/scripts/lib/._static-render.test.mjs +0 -0
- package/apps/client/scripts/lib/card-registry.mjs +81 -0
- package/apps/client/scripts/lib/card-registry.test.mjs +59 -0
- package/apps/client/scripts/lib/evidence-inputs.mjs +91 -0
- package/apps/client/scripts/lib/evidence-inputs.test.mjs +27 -0
- package/apps/client/scripts/lib/static-render.mjs +35 -0
- package/apps/client/scripts/lib/static-render.test.mjs +21 -0
- package/apps/client/scripts/probe-checks.mjs +85 -0
- package/apps/client/scripts/render-card.mjs +710 -0
- package/apps/client/scripts/sample-entries.test.mjs +31 -0
- package/apps/client/scripts/storyboard.test.mjs +149 -0
- package/apps/client/scripts/surface-css.mjs +55 -0
- package/apps/client/scripts/theme-kernel.mjs +236 -0
- package/apps/client/scripts/theme-kernel.test.mjs +136 -0
- package/apps/client/src/._app.config.ts +0 -0
- package/apps/client/src/._vite-env.d.ts +0 -0
- package/apps/client/src/app.config.ts +43 -0
- package/apps/client/src/cards/._AGENTS.md +0 -0
- package/apps/client/src/cards/._registry.ts +0 -0
- package/apps/client/src/cards/AGENTS.md +11 -0
- package/apps/client/src/cards/registry.ts +6 -19
- package/apps/client/src/pages/._page.tsx +0 -0
- package/apps/client/src/pages/index/._index.tsx +0 -0
- package/apps/client/src/pages/index/index.tsx +1 -1
- package/apps/client/src/pages/page.tsx +11 -0
- package/apps/client/src/store/._chat.ts +0 -0
- package/apps/client/src/store/chat.ts +7 -3
- package/apps/client/src/styles/._brand.css +0 -0
- package/apps/client/src/styles/._tailwind.css +0 -0
- package/apps/client/src/styles/brand.css +50 -0
- package/apps/client/src/styles/tailwind.css +326 -0
- package/apps/client/src/test/._setup.ts +0 -0
- package/apps/client/src/vite-env.d.ts +0 -2
- package/apps/client/vite.config.ts +7 -53
- package/apps/server/._package.json +0 -0
- package/apps/server/._tsconfig.json +0 -0
- package/apps/server/._tsup.config.ts +0 -0
- package/apps/server/._vitest.config.ts +0 -0
- package/apps/server/package.json +1 -1
- package/apps/server/scripts/._probe.mjs +0 -0
- package/apps/server/scripts/._scenario-lib.mjs +0 -0
- package/apps/server/scripts/._scenario.mjs +0 -0
- package/apps/server/scripts/probe.mjs +387 -0
- package/apps/server/scripts/scenario-lib.mjs +295 -0
- package/apps/server/scripts/scenario.mjs +67 -0
- package/apps/server/src/._app.ts +0 -0
- package/apps/server/src/._dev.ts +0 -0
- package/apps/server/src/._index.ts +0 -0
- package/apps/server/src/._intent-routes.ts +0 -0
- package/apps/server/src/._pre-tools.ts +0 -0
- package/apps/server/src/app.ts +17 -17
- package/apps/server/src/cards/._AGENTS.md +0 -0
- package/apps/server/src/cards/AGENTS.md +19 -0
- package/apps/server/src/cli/._collect-registry.ts +0 -0
- package/apps/server/src/cli/._plugin-doctor.ts +0 -0
- package/apps/server/src/cli/._plugin-inspect.ts +0 -0
- package/apps/server/src/cli/collect-registry.ts +7 -11
- package/apps/server/src/config/._integration.ts +0 -0
- package/apps/server/src/dev.ts +38 -64
- package/apps/server/src/index.ts +27 -45
- package/apps/server/src/pre-tools.ts +7 -16
- package/apps/server/src/tools/._AGENTS.md +0 -0
- package/apps/server/src/tools/AGENTS.md +23 -0
- package/apps/server/tests/._agent-prompt.test.ts +0 -0
- package/apps/server/tests/._cards-registry.test.ts +0 -0
- package/apps/server/tests/._deployment-loader.test.ts +0 -0
- package/apps/server/tests/._intent-dispatcher.test.ts +0 -0
- package/apps/server/tests/._tool-runtime.test.ts +0 -0
- package/apps/server/tests/cards-registry.test.ts +1 -1
- package/apps/server/tests/helpers/._register.ts +0 -0
- package/apps/server/tests/helpers/register.ts +10 -0
- package/apps/server/tests/tool-runtime.test.ts +1 -28
- package/apps/server/tsconfig.json +1 -1
- package/apps/server/tsup.config.ts +6 -3
- package/config/._AGENTS.md +0 -0
- package/config/._README.md +0 -0
- package/config/._chat.json +0 -0
- package/config/._integrations.json +0 -0
- package/config/._llm_provider.json +0 -0
- package/config/._plugins.json +0 -0
- package/config/AGENTS.md +14 -0
- package/config/README.md +4 -4
- package/config/chat.json +25 -7
- package/config/integrations.json +1 -1
- package/docs/agent/._agent-prompt.md +0 -0
- package/docs/agent/._card-action.md +0 -0
- package/docs/agent/._card.md +0 -0
- package/docs/agent/._conversation.md +0 -0
- package/docs/agent/._kit.md +0 -0
- package/docs/agent/._shell.md +0 -0
- package/docs/agent/._state.md +0 -0
- package/docs/agent/._style.md +0 -0
- package/docs/agent/._tool-emits-card.md +0 -0
- package/docs/agent/._tool.md +0 -0
- package/docs/agent/._verify.md +0 -0
- package/docs/agent/agent-prompt.md +38 -0
- package/docs/agent/card-action.md +101 -0
- package/docs/agent/card.md +159 -0
- package/docs/agent/conversation.md +52 -0
- package/docs/agent/kit.md +80 -0
- package/docs/agent/shell.md +77 -0
- package/docs/agent/state.md +85 -0
- package/docs/agent/style.md +107 -0
- package/docs/agent/tool-emits-card.md +62 -0
- package/docs/agent/tool.md +71 -0
- package/docs/agent/verify.md +188 -0
- package/eslint.config.mjs +18 -0
- package/modules/provider-custom/._AGENTS.md +0 -0
- package/modules/provider-custom/._INTEGRATION.md +0 -0
- package/modules/provider-custom/._LICENSE +0 -0
- package/modules/provider-custom/._README.md +0 -0
- package/modules/provider-custom/._package.json +0 -0
- package/modules/provider-custom/._tbox.module.json +0 -0
- package/modules/provider-custom/._tsconfig.json +0 -0
- package/modules/provider-custom/._tsup.config.ts +0 -0
- package/{packages → modules}/provider-custom/AGENTS.md +6 -6
- package/modules/provider-custom/INTEGRATION.md +10 -0
- package/{packages → modules}/provider-custom/package.json +1 -0
- package/modules/provider-custom/src/._index.ts +0 -0
- package/modules/provider-custom/src/server/._example-adapter.ts +0 -0
- package/modules/provider-custom/src/server/._index.ts +0 -0
- package/{packages → modules}/provider-custom/src/server/example-adapter.ts +2 -2
- package/{packages → modules}/provider-custom/src/server/index.ts +1 -1
- package/modules/provider-custom/tests/._provider-custom.test.ts +0 -0
- package/package.json +38 -7
- package/packages/agent-ui-kit/._AGENTS.md +0 -0
- package/packages/agent-ui-kit/._LICENSE +0 -0
- package/packages/agent-ui-kit/._README.md +0 -0
- package/packages/agent-ui-kit/._catalog.json +0 -0
- package/packages/agent-ui-kit/._package.json +0 -0
- package/packages/agent-ui-kit/._tsconfig.json +0 -0
- package/packages/agent-ui-kit/._vitest.config.ts +0 -0
- package/packages/agent-ui-kit/AGENTS.md +8 -0
- package/packages/agent-ui-kit/README.md +59 -6
- package/packages/agent-ui-kit/assets/._keyboard-circle.svg +0 -0
- package/packages/agent-ui-kit/assets/._more-circle.svg +0 -0
- package/packages/agent-ui-kit/assets/._new-chat.svg +0 -0
- package/packages/agent-ui-kit/assets/._quick-command-star.svg +0 -0
- package/packages/agent-ui-kit/assets/._send-gradient.svg +0 -0
- package/packages/agent-ui-kit/assets/._stop@2x.png +0 -0
- package/packages/agent-ui-kit/assets/._voice-circle.svg +0 -0
- package/packages/agent-ui-kit/catalog.json +855 -0
- package/packages/agent-ui-kit/package.json +24 -9
- package/packages/agent-ui-kit/src/._ChatPage.tsx +0 -0
- package/packages/agent-ui-kit/src/._chat-config.test.ts +0 -0
- package/packages/agent-ui-kit/src/._chat-config.ts +0 -0
- package/packages/agent-ui-kit/src/._icons.ts +0 -0
- package/packages/agent-ui-kit/src/._index.ts +0 -0
- package/packages/agent-ui-kit/src/._preview-provider.tsx +0 -0
- package/packages/agent-ui-kit/src/._shell.contract.json +0 -0
- package/packages/agent-ui-kit/src/._shell.test.ts +0 -0
- package/packages/agent-ui-kit/src/._shell.ts +0 -0
- package/packages/agent-ui-kit/src/._store-context.tsx +0 -0
- package/packages/agent-ui-kit/src/._surface.test.tsx +0 -0
- package/packages/agent-ui-kit/src/._surface.tsx +0 -0
- package/packages/agent-ui-kit/src/._types.ts +0 -0
- package/packages/agent-ui-kit/src/._vite-env.d.ts +0 -0
- package/packages/agent-ui-kit/src/ChatPage.tsx +115 -20
- package/packages/agent-ui-kit/src/card/._action-list-pending.test.tsx +0 -0
- package/packages/agent-ui-kit/src/card/._define-card.test.ts +0 -0
- package/packages/agent-ui-kit/src/card/._define-card.ts +0 -0
- package/packages/agent-ui-kit/src/card/._primitives.test.tsx +0 -0
- package/packages/agent-ui-kit/src/card/._primitives.tsx +0 -0
- package/packages/agent-ui-kit/src/card/._use-card-actions.ts +0 -0
- package/packages/agent-ui-kit/src/card/._view-card-inline.test.tsx +0 -0
- package/packages/agent-ui-kit/src/card/._view-card.test.tsx +0 -0
- package/packages/agent-ui-kit/src/card/._view-card.tsx +0 -0
- package/packages/agent-ui-kit/src/card/action-list-pending.test.tsx +91 -0
- package/packages/agent-ui-kit/src/card/define-card.test.ts +25 -0
- package/packages/agent-ui-kit/src/card/define-card.ts +47 -0
- package/packages/agent-ui-kit/src/card/primitives.test.tsx +157 -0
- package/packages/agent-ui-kit/src/card/primitives.tsx +717 -0
- package/packages/agent-ui-kit/src/card/use-card-actions.ts +86 -0
- package/packages/agent-ui-kit/src/card/view-card-inline.test.tsx +42 -0
- package/packages/agent-ui-kit/src/card/view-card.test.tsx +79 -0
- package/packages/agent-ui-kit/src/card/view-card.tsx +250 -0
- package/packages/agent-ui-kit/src/chat-config.test.ts +35 -71
- package/packages/agent-ui-kit/src/chat-config.ts +29 -7
- package/packages/agent-ui-kit/src/components/._CardRenderer.tsx +0 -0
- package/packages/agent-ui-kit/src/components/ActionBar/._DebugButton.test.tsx +0 -0
- package/packages/agent-ui-kit/src/components/ActionBar/._DebugButton.tsx +0 -0
- package/packages/agent-ui-kit/src/components/ActionBar/._index.test.tsx +0 -0
- package/packages/agent-ui-kit/src/components/ActionBar/._index.tsx +0 -0
- package/packages/agent-ui-kit/src/components/ActionBar/DebugButton.test.tsx +3 -0
- package/packages/agent-ui-kit/src/components/ActionBar/DebugButton.tsx +5 -10
- package/packages/agent-ui-kit/src/components/ActionBar/index.tsx +13 -14
- package/packages/agent-ui-kit/src/components/BottomSheet/._index.test.tsx +0 -0
- package/packages/agent-ui-kit/src/components/BottomSheet/._index.tsx +0 -0
- package/packages/agent-ui-kit/src/components/BottomSheet/index.test.tsx +97 -0
- package/packages/agent-ui-kit/src/components/BottomSheet/index.tsx +49 -0
- package/packages/agent-ui-kit/src/components/ChatHeader/._index.test.tsx +0 -0
- package/packages/agent-ui-kit/src/components/ChatHeader/._index.tsx +0 -0
- package/packages/agent-ui-kit/src/components/ChatHeader/index.tsx +19 -17
- package/packages/agent-ui-kit/src/components/ChatInput/._index.test.tsx +0 -0
- package/packages/agent-ui-kit/src/components/ChatInput/._index.tsx +0 -0
- package/packages/agent-ui-kit/src/components/ChatInput/index.test.tsx +2 -2
- package/packages/agent-ui-kit/src/components/ChatInput/index.tsx +44 -33
- package/packages/agent-ui-kit/src/components/ChatInput/voice/._VoicePressField.tsx +0 -0
- package/packages/agent-ui-kit/src/components/ChatInput/voice/._VoiceRecordingOverlay.tsx +0 -0
- package/packages/agent-ui-kit/src/components/ChatInput/voice/._machine.ts +0 -0
- package/packages/agent-ui-kit/src/components/ChatInput/voice/._useVoicePress.ts +0 -0
- package/packages/agent-ui-kit/src/components/ChatInput/voice/VoicePressField.tsx +12 -3
- package/packages/agent-ui-kit/src/components/ChatInput/voice/VoiceRecordingOverlay.tsx +9 -9
- package/packages/agent-ui-kit/src/components/ChatInput/voice/useVoicePress.ts +1 -1
- package/packages/agent-ui-kit/src/components/HistoryEntry/._index.tsx +0 -0
- package/packages/agent-ui-kit/src/components/HistoryEntry/index.tsx +4 -4
- package/packages/agent-ui-kit/src/components/MediaList/._index.tsx +0 -0
- package/packages/agent-ui-kit/src/components/MediaList/index.tsx +42 -28
- package/packages/agent-ui-kit/src/components/MessageBubble/._index.test.tsx +0 -0
- package/packages/agent-ui-kit/src/components/MessageBubble/._index.tsx +0 -0
- package/packages/agent-ui-kit/src/components/MessageBubble/index.tsx +59 -28
- package/packages/agent-ui-kit/src/components/PullDownIndicator/._index.tsx +0 -0
- package/packages/agent-ui-kit/src/components/PullDownIndicator/index.tsx +3 -4
- package/packages/agent-ui-kit/src/components/QuickCommands/._index.test.tsx +0 -0
- package/packages/agent-ui-kit/src/components/QuickCommands/._index.tsx +0 -0
- package/packages/agent-ui-kit/src/components/QuickCommands/index.test.tsx +3 -1
- package/packages/agent-ui-kit/src/components/QuickCommands/index.tsx +33 -10
- package/packages/agent-ui-kit/src/components/ReasoningBlock/._index.tsx +0 -0
- package/packages/agent-ui-kit/src/components/ReasoningBlock/index.tsx +14 -9
- package/packages/agent-ui-kit/src/components/ScrollToBottomButton/._index.tsx +0 -0
- package/packages/agent-ui-kit/src/components/ScrollToBottomButton/index.tsx +7 -5
- package/packages/agent-ui-kit/src/components/ToolCallBlock/._detail.test.ts +0 -0
- package/packages/agent-ui-kit/src/components/ToolCallBlock/._detail.ts +0 -0
- package/packages/agent-ui-kit/src/components/ToolCallBlock/._index.test.tsx +0 -0
- package/packages/agent-ui-kit/src/components/ToolCallBlock/._index.tsx +0 -0
- package/packages/agent-ui-kit/src/components/ToolCallBlock/._titles.ts +0 -0
- package/packages/agent-ui-kit/src/components/ToolCallBlock/index.tsx +58 -38
- package/packages/agent-ui-kit/src/hooks/._use-drag-gesture.test.ts +0 -0
- package/packages/agent-ui-kit/src/hooks/._use-drag-gesture.ts +0 -0
- package/packages/agent-ui-kit/src/hooks/._use-pull-down-history.ts +0 -0
- package/packages/agent-ui-kit/src/hooks/._use-pull-down-wheel-native.test.ts +0 -0
- package/packages/agent-ui-kit/src/hooks/._useMediaUpload.ts +0 -0
- package/packages/agent-ui-kit/src/hooks/._useTTSAutoPlay.ts +0 -0
- package/packages/agent-ui-kit/src/icons.ts +39 -0
- package/packages/agent-ui-kit/src/index.ts +76 -2
- package/packages/agent-ui-kit/src/overlay/._Overlay.tsx +0 -0
- package/packages/agent-ui-kit/src/overlay/._focus.ts +0 -0
- package/packages/agent-ui-kit/src/overlay/._index.ts +0 -0
- package/packages/agent-ui-kit/src/overlay/._inert.ts +0 -0
- package/packages/agent-ui-kit/src/overlay/._layers.ts +0 -0
- package/packages/agent-ui-kit/src/overlay/._overlay.ssr.test.tsx +0 -0
- package/packages/agent-ui-kit/src/overlay/._overlay.test.tsx +0 -0
- package/packages/agent-ui-kit/src/overlay/._presence.ts +0 -0
- package/packages/agent-ui-kit/src/overlay/._scroll-lock.ts +0 -0
- package/packages/agent-ui-kit/src/overlay/._stack.ts +0 -0
- package/packages/agent-ui-kit/src/overlay/._use-overlay.ts +0 -0
- package/packages/agent-ui-kit/src/overlay/Overlay.tsx +154 -0
- package/packages/agent-ui-kit/src/overlay/focus.ts +53 -0
- package/packages/agent-ui-kit/src/overlay/index.ts +16 -0
- package/packages/agent-ui-kit/src/overlay/inert.ts +27 -0
- package/packages/agent-ui-kit/src/overlay/layers.ts +21 -0
- package/packages/agent-ui-kit/src/overlay/overlay.ssr.test.tsx +27 -0
- package/packages/agent-ui-kit/src/overlay/overlay.test.tsx +209 -0
- package/packages/agent-ui-kit/src/overlay/presence.ts +86 -0
- package/packages/agent-ui-kit/src/overlay/scroll-lock.ts +62 -0
- package/packages/agent-ui-kit/src/overlay/stack.ts +111 -0
- package/packages/agent-ui-kit/src/overlay/use-overlay.ts +80 -0
- package/packages/agent-ui-kit/src/preview-provider.tsx +47 -0
- package/packages/agent-ui-kit/src/shell.contract.json +75 -0
- package/packages/agent-ui-kit/src/shell.test.ts +72 -0
- package/packages/agent-ui-kit/src/shell.ts +60 -0
- package/packages/agent-ui-kit/src/surface.test.tsx +35 -0
- package/packages/agent-ui-kit/src/surface.tsx +44 -0
- package/packages/agent-ui-kit/src/test/._setup.ts +0 -0
- package/packages/agent-ui-kit/src/theme/._base.css +0 -0
- package/packages/agent-ui-kit/src/theme/._contract.json +0 -0
- package/packages/agent-ui-kit/src/theme/._motion.css +0 -0
- package/packages/agent-ui-kit/src/theme/._theme-contract.test.ts +0 -0
- package/packages/agent-ui-kit/src/theme/._theme.ts +0 -0
- package/packages/agent-ui-kit/src/theme/._tokens.css +0 -0
- package/packages/agent-ui-kit/src/theme/base.css +167 -0
- package/packages/agent-ui-kit/src/theme/contract.json +123 -2
- package/packages/agent-ui-kit/src/theme/theme-contract.test.ts +19 -3
- package/packages/agent-ui-kit/src/theme/{tokens.less → tokens.css} +19 -20
- package/packages/agent-ui-kit/src/utils/._copyText.ts +0 -0
- package/packages/agent-ui-kit/src/utils/._haptics.test.ts +0 -0
- package/packages/agent-ui-kit/src/utils/._haptics.ts +0 -0
- package/packages/agent-ui-kit/src/utils/._image-preview-host.tsx +0 -0
- package/packages/agent-ui-kit/src/utils/._imagePreview.test.ts +0 -0
- package/packages/agent-ui-kit/src/utils/._imagePreview.ts +0 -0
- package/packages/agent-ui-kit/src/utils/._pull-down-machine.test.ts +0 -0
- package/packages/agent-ui-kit/src/utils/._pull-down-machine.ts +0 -0
- package/packages/agent-ui-kit/src/utils/._session-error.ts +0 -0
- package/packages/agent-ui-kit/src/utils/._toast.test.ts +0 -0
- package/packages/agent-ui-kit/src/utils/._toast.ts +0 -0
- package/packages/agent-ui-kit/src/utils/._tool-call-display.test.ts +0 -0
- package/packages/agent-ui-kit/src/utils/._tool-call-display.ts +0 -0
- package/packages/agent-ui-kit/src/utils/image-preview-host.tsx +95 -0
- package/packages/agent-ui-kit/src/utils/imagePreview.test.ts +32 -0
- package/packages/agent-ui-kit/src/utils/imagePreview.ts +14 -5
- package/packages/agent-ui-kit/src/utils/toast.test.ts +64 -0
- package/packages/agent-ui-kit/src/utils/toast.ts +100 -7
- package/packages/contracts-mall/._package.json +0 -0
- package/packages/contracts-mall/._tsconfig.json +0 -0
- package/packages/contracts-mall/src/._index.ts +0 -0
- package/packages/contracts-mall/src/._runtime.ts +0 -0
- package/packages/contracts-mall/src/server/._index.ts +0 -0
- package/packages/shared/._AGENTS.md +0 -0
- package/packages/shared/._package.json +0 -0
- package/packages/shared/._tsconfig.json +0 -0
- package/packages/shared/AGENTS.md +13 -0
- package/packages/shared/package.json +20 -0
- package/packages/shared/src/._index.ts +0 -0
- package/packages/shared/src/index.ts +8 -0
- package/packages/shared/tsconfig.json +7 -0
- package/pnpm-lock.template.yaml +781 -846
- package/pnpm-workspace.template.yaml +19 -11
- package/profiles/._mall.json +0 -0
- package/profiles/mall/._TEMPLATE.md +0 -0
- package/profiles/mall/._chat.overrides.json +0 -0
- package/profiles/mall/chat.overrides.json +12 -0
- package/profiles/mall/config/._agent.jsonc +0 -0
- package/profiles/mall/config/._chat.json +0 -0
- package/profiles/mall/config/._knowledge.json +0 -0
- package/profiles/mall/config/chat.json +14 -6
- package/profiles/mall.json +2 -2
- package/scenarios/._README.md +0 -0
- package/scenarios/README.md +7 -0
- package/scripts/._assert-pack.mjs +0 -0
- package/scripts/._build.sh +0 -0
- package/scripts/._check-css-target.mjs +0 -0
- package/scripts/._check-fast.mjs +0 -0
- package/scripts/._check-workspace.mjs +0 -0
- package/scripts/._checks.json +0 -0
- package/scripts/._deliver.mjs +0 -0
- package/scripts/._dev-alipay.mjs +0 -0
- package/scripts/._dev.sh +0 -0
- package/scripts/._generate.mjs +0 -0
- package/scripts/._prepare.sh +0 -0
- package/scripts/._shell-probe.mjs +0 -0
- package/scripts/._smoke.mjs +0 -0
- package/scripts/._start.sh +0 -0
- package/scripts/._stop.sh +0 -0
- package/scripts/._storyboard.mjs +0 -0
- package/scripts/._verify-generated.mjs +0 -0
- package/scripts/assert-pack.mjs +48 -0
- package/scripts/check-css-target.mjs +54 -0
- package/scripts/check-fast.mjs +119 -0
- package/scripts/check-workspace.mjs +68 -19
- package/scripts/checks.json +627 -0
- package/scripts/deliver.mjs +183 -0
- package/scripts/dev-alipay.mjs +1 -1
- package/scripts/generate.mjs +3 -0
- package/scripts/lib/._chrome-pipe.mjs +0 -0
- package/scripts/lib/._geometry-kernel.mjs +0 -0
- package/scripts/lib/chrome-pipe.mjs +95 -0
- package/scripts/lib/geometry-kernel.mjs +137 -0
- package/scripts/shell-probe.mjs +280 -0
- package/scripts/storyboard.mjs +350 -0
- package/scripts/verify-generated.mjs +22 -127
- package/tsconfig.base.json +1 -0
- package/apps/client/STYLE_GUIDE.md +0 -81
- package/apps/client/VISUAL_RESTORE.md +0 -90
- package/apps/client/src/app.tsx +0 -11
- package/apps/client/src/business/App.tsx +0 -11
- package/apps/client/src/business/README.md +0 -99
- package/apps/client/src/business/routes.json +0 -3
- package/apps/client/src/main.tsx +0 -17
- package/apps/client/src/modules.ts +0 -33
- package/apps/client/src/platform/AgentChatApp.tsx +0 -14
- package/apps/client/src/platform/AppShell.tsx +0 -42
- package/apps/client/src/platform/agent-runtime.ts +0 -16
- package/apps/client/src/platform/bootstrap.ts +0 -55
- package/apps/client/src/platform/card-preview-page.tsx +0 -12
- package/apps/client/src/platform/mount-page.tsx +0 -25
- package/apps/client/src/platform/state/createPersistedStore.ts +0 -19
- package/apps/server/src/app-tools.ts +0 -14
- package/apps/server/src/modules.ts +0 -38
- package/apps/server/src/tools/clock.ts +0 -24
- package/apps/server/src/tools/translate.ts +0 -47
- package/packages/agent-ui-kit/src/ChatPage.less +0 -66
- package/packages/agent-ui-kit/src/components/ActionBar/index.less +0 -123
- package/packages/agent-ui-kit/src/components/ChatHeader/index.less +0 -148
- package/packages/agent-ui-kit/src/components/ChatInput/index.less +0 -394
- package/packages/agent-ui-kit/src/components/HistoryEntry/index.less +0 -49
- package/packages/agent-ui-kit/src/components/MediaList/index.less +0 -241
- package/packages/agent-ui-kit/src/components/MessageBubble/index.less +0 -325
- package/packages/agent-ui-kit/src/components/PullDownIndicator/index.less +0 -32
- package/packages/agent-ui-kit/src/components/QuickCommands/index.less +0 -63
- package/packages/agent-ui-kit/src/components/ReasoningBlock/index.less +0 -90
- package/packages/agent-ui-kit/src/components/ScrollToBottomButton/index.less +0 -32
- package/packages/agent-ui-kit/src/components/ToolCallBlock/index.less +0 -312
- package/packages/agent-ui-kit/src/theme/global.less +0 -99
- package/profiles/mall/config/llm_provider.json +0 -5
- package/profiles/mall/config/plugins.json +0 -3
- /package/{packages → modules}/provider-custom/LICENSE +0 -0
- /package/{packages → modules}/provider-custom/README.md +0 -0
- /package/{packages → modules}/provider-custom/src/index.ts +0 -0
- /package/{packages → modules}/provider-custom/tbox.module.json +0 -0
- /package/{packages → modules}/provider-custom/tests/provider-custom.test.ts +0 -0
- /package/{packages → modules}/provider-custom/tsconfig.json +0 -0
- /package/{packages → modules}/provider-custom/tsup.config.ts +0 -0
- /package/packages/agent-ui-kit/src/theme/{motion.less → motion.css} +0 -0
|
@@ -0,0 +1,710 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* render-card — 用真实客户端组件渲染一张卡(F9)。
|
|
4
|
+
*
|
|
5
|
+
* 加载方式与 check:fast 的证据包完全一致:不读应用 vite.config.ts,直接
|
|
6
|
+
* `createServer({ configFile: false, root: apps/client, plugins: [tailwindcss(), react()] })`,
|
|
7
|
+
* 再用 `ssrLoadModule` 同时加载客户端卡片注册表与服务端卡片 meta(样例的静态真源)。
|
|
8
|
+
* 样式与 dev/build 同一条管线(surface-css.mjs):没有 Less、没有 rem 换算、没有固定根字号。
|
|
9
|
+
*
|
|
10
|
+
* 用法:
|
|
11
|
+
* node scripts/render-card.mjs --type <cardType> [--sample <label|序号>] [--all] [--outline] [--audit] [--screenshot] [--baseline] [--json]
|
|
12
|
+
* pnpm card:render --type <cardType> --outline
|
|
13
|
+
*
|
|
14
|
+
* 输出:
|
|
15
|
+
* - 缺省把渲染结果写成独立 HTML(.tbox/card-render/<type>[-<label>].html)并打印路径;
|
|
16
|
+
* - `--outline` 额外打印文本轮廓(层级缩进、文案、按钮及其 disabled 态);
|
|
17
|
+
* - `--json` 输出机器可读结果(含 html 与 outline)。
|
|
18
|
+
* 退出码:0 = 成功;1 = 找不到卡片/样例或渲染失败。
|
|
19
|
+
*/
|
|
20
|
+
import { createRequire } from 'node:module';
|
|
21
|
+
import { copyFileSync, existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from 'node:fs';
|
|
22
|
+
import { createServer as createHttpServer } from 'node:http';
|
|
23
|
+
import { buildSurfaceCss, SURFACE_CSS_SENTINELS } from './surface-css.mjs';
|
|
24
|
+
import { geometryFunctionSource } from '../../../scripts/lib/geometry-kernel.mjs';
|
|
25
|
+
import { execFileSync } from 'node:child_process';
|
|
26
|
+
import path from 'node:path';
|
|
27
|
+
import { fileURLToPath } from 'node:url';
|
|
28
|
+
import process from 'node:process';
|
|
29
|
+
|
|
30
|
+
const appDir = path.resolve(import.meta.dirname, '..', '..', '..');
|
|
31
|
+
const clientDir = path.join(appDir, 'apps/client');
|
|
32
|
+
|
|
33
|
+
const USAGE = `用法:node scripts/render-card.mjs --type <cardType> [--sample <label|序号>] [--all] [--outline] [--audit] [--json] [--out <dir>]
|
|
34
|
+
|
|
35
|
+
--type 卡片类型(服务端 cardType)
|
|
36
|
+
--sample 样例 label(也接受序号;缺省 0 = 第一个样例)
|
|
37
|
+
--all 渲染该卡片的全部样例
|
|
38
|
+
--outline 打印文本轮廓(层级、文案、按钮 disabled 态)
|
|
39
|
+
--audit 视觉体检:用无头浏览器量横向溢出/最小字号/点击区/截断(需 Chrome,可设 TBOX_CHROME)
|
|
40
|
+
--screenshot 用无头 Chrome 截 390×1200@2x PNG(需 Chrome)
|
|
41
|
+
--baseline 截图并与 .tbox/card-render/baseline 对比;首次自动存基线,差异 >0.5% 失败
|
|
42
|
+
--json 输出 JSON(含 html 与 outline)
|
|
43
|
+
--out 输出目录(缺省 .tbox/card-render)
|
|
44
|
+
--help 显示本帮助`;
|
|
45
|
+
|
|
46
|
+
function readArgs(argv) {
|
|
47
|
+
const out = { _: [] };
|
|
48
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
49
|
+
let arg = argv[i];
|
|
50
|
+
if (arg === '--help' || arg === '-h') {
|
|
51
|
+
out.help = true;
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
if (arg === '--all') {
|
|
55
|
+
out.all = true;
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
if (arg === '--outline') {
|
|
59
|
+
out.outline = true;
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
if (arg === '--json') {
|
|
63
|
+
out.json = true;
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
if (arg === '--audit') {
|
|
67
|
+
out.audit = true;
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
if (arg === '--screenshot') {
|
|
71
|
+
out.screenshot = true;
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
if (arg === '--baseline') {
|
|
75
|
+
out.screenshot = true;
|
|
76
|
+
out.baseline = true;
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
let value;
|
|
80
|
+
const eq = arg.indexOf('=');
|
|
81
|
+
if (arg.startsWith('--') && eq > 2) {
|
|
82
|
+
value = arg.slice(eq + 1);
|
|
83
|
+
arg = arg.slice(0, eq);
|
|
84
|
+
}
|
|
85
|
+
const take = () => {
|
|
86
|
+
if (value !== undefined) return value;
|
|
87
|
+
i += 1;
|
|
88
|
+
if (i >= argv.length) throw new Error(`${arg} 缺少取值`);
|
|
89
|
+
return argv[i];
|
|
90
|
+
};
|
|
91
|
+
if (arg === '--type') out.type = take();
|
|
92
|
+
else if (arg === '--sample') out.sample = take();
|
|
93
|
+
else if (arg === '--out') out.out = take();
|
|
94
|
+
else if (arg.startsWith('-')) throw new Error(`未知参数:${arg}`);
|
|
95
|
+
else out._.push(arg);
|
|
96
|
+
}
|
|
97
|
+
return out;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function usageError(message) {
|
|
101
|
+
return new Error(`${message}\n\n${USAGE}`);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// ── 1. 启动 Vite(与 check-evidence 同一条加载路径) ─────────────────
|
|
105
|
+
export async function loadVite() {
|
|
106
|
+
let createServer;
|
|
107
|
+
let react;
|
|
108
|
+
let tailwindcss;
|
|
109
|
+
try {
|
|
110
|
+
({ createServer } = await import('vite'));
|
|
111
|
+
react = (await import('@vitejs/plugin-react')).default;
|
|
112
|
+
tailwindcss = (await import('@tailwindcss/vite')).default;
|
|
113
|
+
} catch (error) {
|
|
114
|
+
throw new Error(`加载 vite/@vitejs/plugin-react 失败:${error?.message ?? error}\n 修复:在应用根跑 pnpm install`);
|
|
115
|
+
}
|
|
116
|
+
try {
|
|
117
|
+
return await createServer({
|
|
118
|
+
configFile: false,
|
|
119
|
+
root: clientDir,
|
|
120
|
+
appType: 'custom',
|
|
121
|
+
logLevel: 'error',
|
|
122
|
+
plugins: [tailwindcss(), react()],
|
|
123
|
+
resolve: {
|
|
124
|
+
alias: {
|
|
125
|
+
'@': path.join(clientDir, 'src'),
|
|
126
|
+
'@config': path.join(appDir, 'config'),
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
// 零 socket:给 Vite 一个永不 listen 的 http server 承载 HMR 升级,避免自建 24678 监听。
|
|
130
|
+
server: { middlewareMode: true, hmr: { server: createHttpServer() }, fs: { allow: [appDir] } },
|
|
131
|
+
optimizeDeps: { noDiscovery: true, include: [] },
|
|
132
|
+
});
|
|
133
|
+
} catch (error) {
|
|
134
|
+
throw new Error(`Vite 启动失败:${error?.message ?? error}\n 修复:检查依赖安装与 apps/client/.tbox-gen(pnpm generate)`);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export async function loadRegistry(vite) {
|
|
139
|
+
let client;
|
|
140
|
+
let server;
|
|
141
|
+
try {
|
|
142
|
+
client = await vite.ssrLoadModule('/.tbox-gen/registry.client.ts');
|
|
143
|
+
} catch (error) {
|
|
144
|
+
throw new Error(`客户端 registry 加载失败:${error?.message ?? error}\n 修复:先跑 pnpm generate 重新生成 .tbox-gen`);
|
|
145
|
+
}
|
|
146
|
+
try {
|
|
147
|
+
server = await vite.ssrLoadModule(`/@fs${path.join(clientDir, '.tbox-gen/registry.server.ts')}`);
|
|
148
|
+
} catch (error) {
|
|
149
|
+
throw new Error(`服务端 registry 加载失败:${error?.message ?? error}\n 修复:先跑 pnpm generate 重新生成 .tbox-gen`);
|
|
150
|
+
}
|
|
151
|
+
return { client, server };
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// ── 2. 样式:与 dev/build 同一条 Vite + Tailwind 管线 ────────────────
|
|
155
|
+
export async function buildStyleSheet(vite) {
|
|
156
|
+
const { cssText, bytes, missing } = await buildSurfaceCss(vite, { clientDir, appDir });
|
|
157
|
+
return { css: cssText, bytes, missing };
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function buildHtmlDocument(cardHtml, css) {
|
|
161
|
+
return `<!doctype html>
|
|
162
|
+
<html lang="zh-CN" data-theme="tbox">
|
|
163
|
+
<head>
|
|
164
|
+
<meta charset="utf-8">
|
|
165
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
166
|
+
<title>tbox card render</title>
|
|
167
|
+
<style>
|
|
168
|
+
body { margin: 0; background: #f5f6f7; color: #1f1f1f; font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif; }
|
|
169
|
+
/* 左对齐固定 8px:无头 Chrome 有最小窗口宽(约 500),居中会被 420 截图裁掉右缘。 */
|
|
170
|
+
.tbox-card-render { width: 375px; max-width: calc(100% - 16px); margin: 16px 8px; }
|
|
171
|
+
${css}
|
|
172
|
+
</style>
|
|
173
|
+
</head>
|
|
174
|
+
<body>
|
|
175
|
+
<div class="tbox-card-render">${cardHtml}</div>
|
|
176
|
+
</body>
|
|
177
|
+
</html>
|
|
178
|
+
`;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// ── 3. 文本轮廓(不依赖 DOM:标签栈 + 类名语义) ─────────────────────
|
|
182
|
+
const VOID_TAGS = new Set(['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', 'track', 'wbr']);
|
|
183
|
+
|
|
184
|
+
const CLASS_LABELS = {
|
|
185
|
+
'tbox-card-primitive': '卡片',
|
|
186
|
+
'tbox-card-primitive__body': '卡片主体',
|
|
187
|
+
'tbox-card-primitive__footer': '卡片脚注',
|
|
188
|
+
'tbox-card-head': '卡头',
|
|
189
|
+
'tbox-card-head__icon': '图标',
|
|
190
|
+
'tbox-card-head__text': '标题区',
|
|
191
|
+
'tbox-card-head__eyebrow': '小标题',
|
|
192
|
+
'tbox-card-head__title': '标题',
|
|
193
|
+
'tbox-card-head__status': '状态',
|
|
194
|
+
'tbox-kv': '属性列表',
|
|
195
|
+
'tbox-kv__row': '行',
|
|
196
|
+
'tbox-kv__label': '标签',
|
|
197
|
+
'tbox-kv__value': '值',
|
|
198
|
+
'tbox-bill': '明细',
|
|
199
|
+
'tbox-bill__row': '明细行',
|
|
200
|
+
'tbox-bill__label': '项目',
|
|
201
|
+
'tbox-bill__value': '金额',
|
|
202
|
+
'tbox-bill__total': '合计',
|
|
203
|
+
'tbox-tag': '标签',
|
|
204
|
+
'tbox-notice': '提示',
|
|
205
|
+
'tbox-notice__icon': '图标',
|
|
206
|
+
'tbox-notice__text': '提示文案',
|
|
207
|
+
'tbox-actions': '操作区',
|
|
208
|
+
'tbox-actions__primary': '主操作',
|
|
209
|
+
'tbox-actions__secondary': '次操作',
|
|
210
|
+
'tbox-btn': '按钮',
|
|
211
|
+
'tbox-steps': '步骤',
|
|
212
|
+
'tbox-steps__item': '步骤项',
|
|
213
|
+
'tbox-steps__index': '序号',
|
|
214
|
+
'tbox-steps__text': '步骤文案',
|
|
215
|
+
'tbox-steps__title': '步骤标题',
|
|
216
|
+
'tbox-steps__detail': '步骤说明',
|
|
217
|
+
'tbox-media': '图文',
|
|
218
|
+
'tbox-media__thumb': '缩略图',
|
|
219
|
+
'tbox-media__text': '图文文案',
|
|
220
|
+
'tbox-media__title': '标题',
|
|
221
|
+
'tbox-media__meta': '说明',
|
|
222
|
+
'tbox-media__tags': '标签',
|
|
223
|
+
'tbox-media__action': '操作',
|
|
224
|
+
'tbox-hero': '主视觉',
|
|
225
|
+
'tbox-hero__text': '主视觉文案',
|
|
226
|
+
'tbox-hero__eyebrow': '小标题',
|
|
227
|
+
'tbox-hero__title': '标题',
|
|
228
|
+
'tbox-hero__value': '数值',
|
|
229
|
+
'tbox-hero__footnote': '脚注',
|
|
230
|
+
'tbox-sheet': '浮层',
|
|
231
|
+
'tbox-sheet__title': '浮层标题',
|
|
232
|
+
'tbox-sheet__desc': '浮层说明',
|
|
233
|
+
'tbox-sheet__actions': '浮层操作区',
|
|
234
|
+
'tbox-ticket': '票券',
|
|
235
|
+
'tbox-ticket__amount': '金额',
|
|
236
|
+
'tbox-ticket__condition': '条件',
|
|
237
|
+
'tbox-ticket__meta': '说明',
|
|
238
|
+
'tbox-ticket__status': '状态',
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
/** 剥掉 dev 期 babel 注入的源码定位属性(本项目 configFile:false 本不会注入,防未来漂移)。 */
|
|
242
|
+
function stripCodeInspect(html) {
|
|
243
|
+
return html.replace(/\s+data-code-inspect-[\w-]+=(?:"[^"]*"|'[^']*')/g, '');
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function decodeEntities(text) {
|
|
247
|
+
return text
|
|
248
|
+
.replace(/&#(\d+);/g, (_m, code) => String.fromCodePoint(Number(code)))
|
|
249
|
+
.replace(/&#x([0-9a-f]+);/gi, (_m, code) => String.fromCodePoint(Number.parseInt(code, 16)))
|
|
250
|
+
.replace(/ /g, ' ')
|
|
251
|
+
.replace(/"/g, '"')
|
|
252
|
+
.replace(/'|'/g, "'")
|
|
253
|
+
.replace(/</g, '<')
|
|
254
|
+
.replace(/>/g, '>')
|
|
255
|
+
.replace(/&/g, '&');
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
function parseHtml(html) {
|
|
259
|
+
const roots = [];
|
|
260
|
+
const stack = [];
|
|
261
|
+
const tokens = stripCodeInspect(html).replace(/<!--[\s\S]*?-->/g, '').split(/(<[^>]*>)/g).filter(Boolean);
|
|
262
|
+
const current = () => stack[stack.length - 1];
|
|
263
|
+
for (const token of tokens) {
|
|
264
|
+
if (!token.startsWith('<')) {
|
|
265
|
+
const text = decodeEntities(token).replace(/\s+/g, ' ').trim();
|
|
266
|
+
if (text) {
|
|
267
|
+
const parent = current();
|
|
268
|
+
if (parent) parent.children.push(text);
|
|
269
|
+
else roots.push({ tag: '#text', classes: [], disabled: false, children: [text] });
|
|
270
|
+
}
|
|
271
|
+
continue;
|
|
272
|
+
}
|
|
273
|
+
const close = /^<\s*\//.test(token);
|
|
274
|
+
const match = /^<\s*\/?\s*([a-zA-Z][\w:-]*)/.exec(token);
|
|
275
|
+
if (!match) continue;
|
|
276
|
+
const tag = match[1].toLowerCase();
|
|
277
|
+
if (close) {
|
|
278
|
+
for (let i = stack.length - 1; i >= 0; i -= 1) {
|
|
279
|
+
if (stack[i].tag === tag) {
|
|
280
|
+
stack.length = i;
|
|
281
|
+
break;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
continue;
|
|
285
|
+
}
|
|
286
|
+
const classMatch = /class\s*=\s*(?:"([^"]*)"|'([^']*)')/.exec(token);
|
|
287
|
+
const classes = (classMatch?.[1] ?? classMatch?.[2] ?? '').split(/\s+/).filter(Boolean);
|
|
288
|
+
const placeholderMatch = /placeholder\s*=\s*(?:"([^"]*)"|'([^']*)')/.exec(token);
|
|
289
|
+
const node = {
|
|
290
|
+
tag,
|
|
291
|
+
classes,
|
|
292
|
+
disabled: /(?:^|\s)disabled(?=[\s=/>])/.test(token),
|
|
293
|
+
placeholder: decodeEntities(placeholderMatch?.[1] ?? placeholderMatch?.[2] ?? ''),
|
|
294
|
+
children: [],
|
|
295
|
+
};
|
|
296
|
+
if (current()) current().children.push(node);
|
|
297
|
+
else roots.push(node);
|
|
298
|
+
const selfClosing = /\/\s*>$/.test(token) || VOID_TAGS.has(tag);
|
|
299
|
+
if (!selfClosing) stack.push(node);
|
|
300
|
+
}
|
|
301
|
+
return roots;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
function labelOf(node) {
|
|
305
|
+
if (node.tag === 'button') return '按钮';
|
|
306
|
+
if (node.tag === 'input' || node.tag === 'textarea') return '输入框';
|
|
307
|
+
for (const cls of node.classes) if (CLASS_LABELS[cls]) return CLASS_LABELS[cls];
|
|
308
|
+
return node.classes[0] ? `${node.tag}.${node.classes[0]}` : node.tag;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
function textOf(node) {
|
|
312
|
+
let out = '';
|
|
313
|
+
for (const child of node.children) out += typeof child === 'string' ? child : textOf(child);
|
|
314
|
+
return out.replace(/\s+/g, ' ').trim();
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
function directText(node) {
|
|
318
|
+
return node.children.filter((child) => typeof child === 'string').join(' ').replace(/\s+/g, ' ').trim();
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
const GENERIC_TAGS = new Set([
|
|
322
|
+
'span', 'strong', 'b', 'em', 'i', 'p', 'div', 'section', 'article', 'header', 'footer', 'main',
|
|
323
|
+
'ul', 'ol', 'li', 'dl', 'dt', 'dd', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'small',
|
|
324
|
+
]);
|
|
325
|
+
|
|
326
|
+
function outlineNode(node, depth, lines) {
|
|
327
|
+
const pad = ' '.repeat(depth);
|
|
328
|
+
if (node.tag === '#text') {
|
|
329
|
+
const text = textOf(node);
|
|
330
|
+
if (text) lines.push(`${pad}${text}`);
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
const text = textOf(node);
|
|
334
|
+
if (node.tag === 'button') {
|
|
335
|
+
lines.push(`${pad}按钮${text ? `「${text}」` : ''}${node.disabled ? '(disabled)' : ''}`);
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
const children = node.children.filter((child) => typeof child !== 'string');
|
|
339
|
+
if (!text && children.length === 0) return;
|
|
340
|
+
const label = labelOf(node);
|
|
341
|
+
if (node.tag === 'input' || node.tag === 'textarea') {
|
|
342
|
+
lines.push(`${pad}${label}${node.placeholder ? `「${node.placeholder}」` : ''}${node.disabled ? '(disabled)' : ''}`);
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
// 无语义的包装标签(span/div/strong…):单文本直接给文案,纯包装直接摊平——轮廓读的是卡的结构与文案。
|
|
346
|
+
const semantic = node.classes.some((cls) => CLASS_LABELS[cls]);
|
|
347
|
+
if (!semantic && GENERIC_TAGS.has(node.tag)) {
|
|
348
|
+
if (children.length === 0) {
|
|
349
|
+
lines.push(`${pad}${text}`);
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
if (!text) {
|
|
353
|
+
for (const child of children) outlineNode(child, depth, lines);
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
lines.push(`${pad}${text}`);
|
|
357
|
+
for (const child of children) outlineNode(child, depth + 1, lines);
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
if (children.length === 0) {
|
|
361
|
+
lines.push(`${pad}${label}「${text}」`);
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
const own = directText(node);
|
|
365
|
+
lines.push(own ? `${pad}${label}「${own}」` : `${pad}${label}`);
|
|
366
|
+
for (const child of children) outlineNode(child, depth + 1, lines);
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
function buildOutline(cardType, label, cardHtml) {
|
|
370
|
+
const lines = [`${cardType}[${label}]`];
|
|
371
|
+
for (const root of parseHtml(cardHtml)) outlineNode(root, 1, lines);
|
|
372
|
+
return lines.join('\n');
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
// ── 4. 渲染 ──────────────────────────────────────────────────────────
|
|
376
|
+
export function sampleEntries(meta, { includeHidden = true } = {}) {
|
|
377
|
+
const samples = [];
|
|
378
|
+
if (meta.sampleData !== undefined) samples.push({ label: 'sampleData', note: undefined, data: meta.sampleData, isHistory: false, noTokens: false, hidden: false });
|
|
379
|
+
if (Array.isArray(meta.samples)) {
|
|
380
|
+
meta.samples.forEach((entry, index) => {
|
|
381
|
+
if (entry?.hidden === true && !includeHidden) return;
|
|
382
|
+
samples.push({
|
|
383
|
+
label: typeof entry?.label === 'string' ? entry.label : `samples[${index}]`,
|
|
384
|
+
note: typeof entry?.note === 'string' ? entry.note : undefined,
|
|
385
|
+
group: typeof entry?.group === 'string' ? entry.group : undefined,
|
|
386
|
+
data: entry?.data,
|
|
387
|
+
isHistory: entry?.isHistory === true,
|
|
388
|
+
noTokens: entry?.noTokens === true,
|
|
389
|
+
hidden: entry?.hidden === true,
|
|
390
|
+
});
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
return samples;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
/** 同卡样例 label 重复检测:label 是故事板帧键与渲染文件名的一部分,重复会静默覆盖证据。 */
|
|
397
|
+
export function duplicateSampleLabels(meta, { includeHidden = true } = {}) {
|
|
398
|
+
const seen = new Set();
|
|
399
|
+
const duplicates = new Set();
|
|
400
|
+
for (const sample of sampleEntries(meta, { includeHidden })) {
|
|
401
|
+
if (seen.has(sample.label)) duplicates.add(sample.label);
|
|
402
|
+
seen.add(sample.label);
|
|
403
|
+
}
|
|
404
|
+
return [...duplicates];
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
function selectSamples(samples, args) {
|
|
408
|
+
if (samples.length === 0) return [];
|
|
409
|
+
if (args.all) return samples;
|
|
410
|
+
if (args.sample === undefined) return samples.slice(0, 1);
|
|
411
|
+
const byLabel = samples.findIndex((entry) => entry.label === args.sample);
|
|
412
|
+
if (byLabel >= 0) return [samples[byLabel]];
|
|
413
|
+
const index = Number(args.sample);
|
|
414
|
+
if (Number.isInteger(index) && index >= 0 && index < samples.length) return [samples[index]];
|
|
415
|
+
throw new Error(
|
|
416
|
+
`样例 "${args.sample}" 不存在(共 ${samples.length} 份:${samples.map((entry, i) => `${i}=${entry.label}`).join('、')})\n` +
|
|
417
|
+
` 提示:--sample <label|序号> 选一份;--all 渲染全部`,
|
|
418
|
+
);
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
const slug = (label) => label.replace(/[^\p{L}\p{N}._-]+/gu, '-').replace(/^-+|-+$/g, '') || 'sample';
|
|
422
|
+
|
|
423
|
+
export async function renderSamples(vite, registries, cardType, samples) {
|
|
424
|
+
const meta = registries.server?.cards?.[cardType];
|
|
425
|
+
const components = registries.client?.cards ?? {};
|
|
426
|
+
const Component = components[cardType];
|
|
427
|
+
if (!Component) {
|
|
428
|
+
throw new Error(
|
|
429
|
+
`卡片 ${cardType} 有服务端声明但客户端组件未注册。\n` +
|
|
430
|
+
` 修复:补 apps/client/src/cards/${cardType}.card.tsx(export const card = defineCard({ type: '${cardType}' }, …)),再 pnpm generate`,
|
|
431
|
+
);
|
|
432
|
+
}
|
|
433
|
+
const React = (await import('react')).default;
|
|
434
|
+
const { renderToStaticMarkup } = await import('react-dom/server');
|
|
435
|
+
const { createStaticRenderer } = await import('./lib/static-render.mjs');
|
|
436
|
+
const staticRender = createStaticRenderer(renderToStaticMarkup);
|
|
437
|
+
const kit = await vite.ssrLoadModule('@tbox.cn/app-agent-ui-kit');
|
|
438
|
+
|
|
439
|
+
// 与 check:fast / 预览同一条装配(SurfaceHarness):动作不落库、isGenerating=false。
|
|
440
|
+
const harness = kit.createSurfaceHarness({ cards: components });
|
|
441
|
+
|
|
442
|
+
const rendered = [];
|
|
443
|
+
for (const sample of samples) {
|
|
444
|
+
const parsed = meta.dataSchema?.safeParse?.(sample.data);
|
|
445
|
+
const schemaValid = parsed ? parsed.success : true;
|
|
446
|
+
let html;
|
|
447
|
+
try {
|
|
448
|
+
html = staticRender.render(
|
|
449
|
+
harness.wrap(
|
|
450
|
+
React.createElement(Component, { data: parsed?.success ? parsed.data : sample.data, cardId: `render-${cardType}`, isHistory: sample.isHistory === true, actionTokens: {} }),
|
|
451
|
+
),
|
|
452
|
+
);
|
|
453
|
+
} catch (error) {
|
|
454
|
+
throw new Error(`卡片 ${cardType} / ${sample.label} 渲染抛错:${error?.message ?? error}\n 修复:按报错栈修 apps/client/src/cards/${cardType}.card.tsx`);
|
|
455
|
+
}
|
|
456
|
+
if (!html.trim()) throw new Error(`卡片 ${cardType} / ${sample.label} 渲染为空(组件返回了空树)`);
|
|
457
|
+
html = stripCodeInspect(html);
|
|
458
|
+
rendered.push({
|
|
459
|
+
...sample,
|
|
460
|
+
schemaValid,
|
|
461
|
+
...(schemaValid ? {} : { issues: parsed?.error?.issues?.map((issue) => issue.message) ?? [] }),
|
|
462
|
+
html,
|
|
463
|
+
outline: buildOutline(cardType, sample.label, html),
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
return rendered;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
// ── 视觉体检(F12,可选层:需要无头浏览器) ──────────────────────
|
|
470
|
+
const CHROME_CANDIDATES = [
|
|
471
|
+
process.env.TBOX_CHROME,
|
|
472
|
+
// 平台沙箱:Chrome for Testing 由镜像安装,路径只在 AGENT_BROWSER_EXECUTABLE_PATH 暴露。
|
|
473
|
+
process.env.AGENT_BROWSER_EXECUTABLE_PATH,
|
|
474
|
+
'/home/admin/.agent-browser/chrome/chrome-linux64/chrome',
|
|
475
|
+
'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
|
|
476
|
+
'/Applications/Chromium.app/Contents/MacOS/Chromium',
|
|
477
|
+
'/usr/bin/google-chrome',
|
|
478
|
+
'/usr/bin/google-chrome-stable',
|
|
479
|
+
'/usr/bin/chromium',
|
|
480
|
+
'/usr/bin/chromium-browser',
|
|
481
|
+
].filter(Boolean);
|
|
482
|
+
|
|
483
|
+
let chromeLookupError = '';
|
|
484
|
+
function findChrome() {
|
|
485
|
+
for (const candidate of CHROME_CANDIDATES) if (existsSync(candidate)) return candidate;
|
|
486
|
+
for (const name of ['chromium', 'google-chrome', 'chrome']) {
|
|
487
|
+
try {
|
|
488
|
+
const found = execFileSync('which', [name], { encoding: 'utf8' }).trim();
|
|
489
|
+
if (found) return found;
|
|
490
|
+
} catch {
|
|
491
|
+
// 继续找
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
chromeLookupError = '已尝试:' + CHROME_CANDIDATES.join('、') + ' 与 PATH 中的 chromium/google-chrome/chrome';
|
|
495
|
+
return undefined;
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
const auditScript = () => `
|
|
499
|
+
<script>
|
|
500
|
+
(function () {
|
|
501
|
+
// 量法统一在 scripts/lib/geometry-kernel.mjs(与壳探针、故事板同一份);
|
|
502
|
+
// 这里只把内核输出映射回体检原有的字段名,报告与命令行输出不变。
|
|
503
|
+
// 无头浏览器有最小窗口宽(macOS 上约 500),这里按实际视口量并把宽度写进结果。
|
|
504
|
+
${geometryFunctionSource()}
|
|
505
|
+
var g = tboxGeometry({ targets: 'button, a', thresholds: { minTarget: 44, minFontPx: 12 } });
|
|
506
|
+
var out = {
|
|
507
|
+
viewport: g.viewport.w,
|
|
508
|
+
overflow: g.overflowX,
|
|
509
|
+
overflowRight: g.overflowRight,
|
|
510
|
+
minFontPx: g.minFontPx,
|
|
511
|
+
truncated: g.clipped.length,
|
|
512
|
+
smallTargets: g.smallTargets,
|
|
513
|
+
typeScale: g.typeScale,
|
|
514
|
+
};
|
|
515
|
+
var pre = document.createElement('pre');
|
|
516
|
+
pre.id = '__tbox_audit';
|
|
517
|
+
pre.textContent = JSON.stringify(out);
|
|
518
|
+
document.body.appendChild(pre);
|
|
519
|
+
})();
|
|
520
|
+
</script>`;
|
|
521
|
+
|
|
522
|
+
/** 用无头浏览器量一张卡在 390 宽下的布局风险;找不到浏览器时返回 skipped。 */
|
|
523
|
+
function auditFile(file, width = 390) {
|
|
524
|
+
const chrome = findChrome();
|
|
525
|
+
if (!chrome) return { skipped: true, reason: '未找到无头浏览器(可设 TBOX_CHROME 指向 Chrome/Chromium)' + (chromeLookupError ? ';' + chromeLookupError : '') };
|
|
526
|
+
const html = readFileSync(file, 'utf8').replace('</body>', `${auditScript(width)}\n</body>`);
|
|
527
|
+
const probe = file.replace(/\.html$/, '.audit.html');
|
|
528
|
+
writeFileSync(probe, html, 'utf8');
|
|
529
|
+
try {
|
|
530
|
+
const dom = execFileSync(
|
|
531
|
+
chrome,
|
|
532
|
+
['--headless=new', '--disable-gpu', '--no-sandbox', '--hide-scrollbars', `--window-size=${Math.max(500, width)},900`, '--virtual-time-budget=1500', '--dump-dom', `file://${probe}`],
|
|
533
|
+
{ encoding: 'utf8', timeout: 30000, maxBuffer: 20 * 1024 * 1024 },
|
|
534
|
+
);
|
|
535
|
+
const match = /<pre id="__tbox_audit">([\s\S]*?)<\/pre>/.exec(dom);
|
|
536
|
+
if (!match) return { skipped: true, reason: '无头浏览器未回传测量结果' };
|
|
537
|
+
return JSON.parse(decodeEntities(match[1]));
|
|
538
|
+
} catch (error) {
|
|
539
|
+
return { skipped: true, reason: `无头浏览器运行失败:${error?.message ?? error}` };
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
function auditLines(audit) {
|
|
544
|
+
if (audit?.skipped) return [`体检跳过:${audit.reason}`];
|
|
545
|
+
const lines = [`体检(${audit.viewport}px 宽):横向溢出 ${audit.overflow}px(右侧越界 ${audit.overflowRight}px)|最小字号 ${audit.minFontPx ?? '—'}px|截断 ${audit.truncated} 处`];
|
|
546
|
+
if (audit.smallTargets?.length) lines.push(` 点击区不足 44px:${audit.smallTargets.map((item) => `${item.text || item.tag}(${item.w}×${item.h})`).join('、')}`);
|
|
547
|
+
const scale = audit.typeScale;
|
|
548
|
+
if (scale?.offScale?.length) {
|
|
549
|
+
lines.push(` 字号越档:${scale.offScale.map((item) => `${item.px}px×${item.count}`).join('、')}(五档 ${scale.allowed.join('/')})`);
|
|
550
|
+
}
|
|
551
|
+
return lines;
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
function captureScreenshot(file, outDir, base) {
|
|
555
|
+
const chrome = findChrome();
|
|
556
|
+
if (!chrome) return { skipped: true, reason: '未找到无头浏览器(可设 TBOX_CHROME 指向 Chrome/Chromium)' + (chromeLookupError ? ';' + chromeLookupError : '') };
|
|
557
|
+
const png = path.join(outDir, `${base}.png`);
|
|
558
|
+
try {
|
|
559
|
+
execFileSync(
|
|
560
|
+
chrome,
|
|
561
|
+
[
|
|
562
|
+
'--headless=new',
|
|
563
|
+
'--disable-gpu',
|
|
564
|
+
'--hide-scrollbars',
|
|
565
|
+
'--force-device-scale-factor=2',
|
|
566
|
+
'--window-size=390,1200',
|
|
567
|
+
`--screenshot=${png}`,
|
|
568
|
+
`file://${file}`,
|
|
569
|
+
],
|
|
570
|
+
{ stdio: 'pipe' },
|
|
571
|
+
);
|
|
572
|
+
return { file: png, bytes: statSync(png).size };
|
|
573
|
+
} catch (error) {
|
|
574
|
+
return { skipped: true, reason: `截图失败:${error?.message ?? error}` };
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
const PIXEL_DIFF_SCRIPT = `
|
|
579
|
+
import json, sys
|
|
580
|
+
from PIL import Image, ImageChops
|
|
581
|
+
a, b = sys.argv[1], sys.argv[2]
|
|
582
|
+
ia, ib = Image.open(a).convert('RGBA'), Image.open(b).convert('RGBA')
|
|
583
|
+
if ia.size != ib.size:
|
|
584
|
+
print(json.dumps({'sizeMismatch': True, 'before': ia.size, 'after': ib.size}))
|
|
585
|
+
sys.exit(0)
|
|
586
|
+
diff = ImageChops.difference(ia, ib)
|
|
587
|
+
pixels = [p for p in diff.getdata() if p[:3] != (0, 0, 0) or p[3] != 0]
|
|
588
|
+
total = ia.size[0] * ia.size[1]
|
|
589
|
+
print(json.dumps({'diffPixels': len(pixels), 'total': total, 'ratio': len(pixels) / total}))
|
|
590
|
+
`;
|
|
591
|
+
|
|
592
|
+
function compareScreenshot(current, baselineDir, base) {
|
|
593
|
+
mkdirSync(baselineDir, { recursive: true });
|
|
594
|
+
const baseline = path.join(baselineDir, `${base}.png`);
|
|
595
|
+
if (!existsSync(baseline)) {
|
|
596
|
+
copyFileSync(current, baseline);
|
|
597
|
+
return { baseline: 'created', file: baseline };
|
|
598
|
+
}
|
|
599
|
+
try {
|
|
600
|
+
const output = execFileSync('python3', ['-c', PIXEL_DIFF_SCRIPT, baseline, current], { encoding: 'utf8' });
|
|
601
|
+
const diff = JSON.parse(output.trim());
|
|
602
|
+
if (diff.sizeMismatch) return { ok: false, reason: `尺寸不同:${diff.before} → ${diff.after}` };
|
|
603
|
+
return { ok: diff.ratio <= 0.005, ...diff };
|
|
604
|
+
} catch (error) {
|
|
605
|
+
const same = readFileSync(baseline).equals(readFileSync(current));
|
|
606
|
+
return { ok: same, fallback: 'byte', reason: same ? undefined : '像素对比不可用(缺 Pillow),字节不同' };
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
// ── 5. 输出 ──────────────────────────────────────────────────────────
|
|
611
|
+
export function writeSample(outDir, cardType, sample, css) {
|
|
612
|
+
mkdirSync(outDir, { recursive: true });
|
|
613
|
+
const base = sample.label === 'sampleData' ? cardType : `${cardType}-${slug(sample.label)}`;
|
|
614
|
+
const file = path.join(outDir, `${base}.html`);
|
|
615
|
+
const document = buildHtmlDocument(sample.html, css);
|
|
616
|
+
writeFileSync(file, document, 'utf8');
|
|
617
|
+
return { file, bytes: Buffer.byteLength(document) };
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
async function main() {
|
|
621
|
+
const args = readArgs(process.argv.slice(2));
|
|
622
|
+
if (args.help) {
|
|
623
|
+
console.log(USAGE);
|
|
624
|
+
return;
|
|
625
|
+
}
|
|
626
|
+
if (!args.type) throw usageError('缺少 --type <cardType>');
|
|
627
|
+
const warnings = [];
|
|
628
|
+
|
|
629
|
+
const vite = await loadVite();
|
|
630
|
+
try {
|
|
631
|
+
const registries = await loadRegistry(vite);
|
|
632
|
+
const view = (await import('./lib/card-registry.mjs')).collectCards({ server: registries.server, client: registries.client });
|
|
633
|
+
const resolved = { ...registries, server: { ...registries.server, cards: view.metas }, client: { ...registries.client, cards: view.components } };
|
|
634
|
+
const knownCards = Object.keys(view.metas);
|
|
635
|
+
const meta = view.metas[args.type];
|
|
636
|
+
if (!meta) {
|
|
637
|
+
throw new Error(
|
|
638
|
+
`未找到卡片类型 "${args.type}"(已注册:${knownCards.join('、') || '无'})\n` +
|
|
639
|
+
` 修复:先 pnpm generate(.tbox-gen/registry.*.ts 可能过期);没有卡片时用 pnpm exec tbox-app new card ${args.type}`,
|
|
640
|
+
);
|
|
641
|
+
}
|
|
642
|
+
const samples = sampleEntries(meta);
|
|
643
|
+
if (samples.length === 0) {
|
|
644
|
+
throw new Error(
|
|
645
|
+
`卡片 ${args.type} 没有样例。\n` +
|
|
646
|
+
` 修复:在 ${view.provenance?.[args.type]?.kind === 'module' ? `modules/${view.provenance[args.type].moduleId}/src/server/cards/${args.type}/meta.ts` : `apps/server/src/cards/${args.type}.card.ts`} 的 sampleData 或 samples 里补一条静态字面量(card render 依赖它)`,
|
|
647
|
+
);
|
|
648
|
+
}
|
|
649
|
+
const selected = selectSamples(samples, args);
|
|
650
|
+
const rendered = await renderSamples(vite, resolved, args.type, selected);
|
|
651
|
+
const surface = await buildStyleSheet(vite);
|
|
652
|
+
const css = surface.css;
|
|
653
|
+
// 证据自校验:CSS 为空或哨兵缺失时,截图/HTML 只会说谎——直接失败,不产出「无样式证据」。
|
|
654
|
+
if (surface.missing.length > 0 || surface.bytes < 20000) {
|
|
655
|
+
throw new Error(
|
|
656
|
+
`表面 CSS 不可信:${surface.bytes} 字节,缺哨兵 ${surface.missing.join('、') || '无'}。\n` +
|
|
657
|
+
` 修复:确认 apps/client/vite.config.ts 的 tboxModuleSourcesPlugin 在 tailwindcss() 之前;本命令与 check:fast 同一管线(surface-css.mjs)。`,
|
|
658
|
+
);
|
|
659
|
+
}
|
|
660
|
+
const outDir = path.resolve(args.out ?? path.join(appDir, '.tbox/card-render'));
|
|
661
|
+
const baselineDir = path.join(outDir, 'baseline');
|
|
662
|
+
const results = rendered.map((sample) => {
|
|
663
|
+
const { file, bytes } = writeSample(outDir, args.type, sample, css);
|
|
664
|
+
const base = sample.label === 'sampleData' ? args.type : `${args.type}-${slug(sample.label)}`;
|
|
665
|
+
const shot = args.screenshot ? captureScreenshot(file, outDir, base) : undefined;
|
|
666
|
+
const visual = shot && !shot.skipped && args.baseline ? compareScreenshot(shot.file, baselineDir, base) : undefined;
|
|
667
|
+
if (visual && visual.ok === false) warnings.push(`${args.type} / ${sample.label} 视觉差异超阈值:${(visual.ratio * 100).toFixed(2)}%`);
|
|
668
|
+
return { ...sample, file, bytes, ...(args.audit ? { audit: auditFile(file) } : {}), ...(shot ? { screenshot: shot } : {}), ...(visual ? { visual } : {}) };
|
|
669
|
+
});
|
|
670
|
+
for (const sample of results) if (sample.schemaValid === false) warnings.push(`${args.type} / ${sample.label} 的样例未过 dataSchema:${(sample.issues ?? []).join(';')}`);
|
|
671
|
+
|
|
672
|
+
// --baseline 的契约是「差异 > 阈值失败」:不能只记 warning,否则视觉门禁形同虚设
|
|
673
|
+
const visualFailures = results.filter((sample) => sample.visual && sample.visual.ok === false);
|
|
674
|
+
const result = { ok: visualFailures.length === 0, cardType: args.type, cssBytes: surface.bytes, samples: results, warnings };
|
|
675
|
+
if (visualFailures.length > 0) process.exitCode = 1;
|
|
676
|
+
if (args.json) {
|
|
677
|
+
console.log(JSON.stringify(result));
|
|
678
|
+
return;
|
|
679
|
+
}
|
|
680
|
+
for (const warning of warnings) console.error(`⚠️ ${warning}`);
|
|
681
|
+
for (const sample of results) {
|
|
682
|
+
console.log(`✅ ${path.relative(appDir, sample.file)}(${args.type} / ${sample.label},${sample.bytes} 字节)`);
|
|
683
|
+
if (args.outline) console.log(sample.outline);
|
|
684
|
+
if (sample.audit) for (const line of auditLines(sample.audit)) console.log(` ${line}`);
|
|
685
|
+
if (sample.screenshot && !sample.screenshot.skipped) console.log(` 📷 ${path.relative(appDir, sample.screenshot.file)}`);
|
|
686
|
+
if (sample.visual) {
|
|
687
|
+
if (sample.visual.baseline === 'created') console.log(` 基线已保存:${path.relative(appDir, sample.visual.file)}`);
|
|
688
|
+
else if (sample.visual.ok === false) console.log(` ❌ 视觉差异:${sample.visual.reason ?? `${(sample.visual.ratio * 100).toFixed(2)}%(${sample.visual.diffPixels} px)`}`);
|
|
689
|
+
else if (sample.visual.fallback === 'byte') console.log(' ✅ 视觉一致(字节比对;装 Pillow 可看像素差异)');
|
|
690
|
+
else console.log(` ✅ 视觉差异 ${(sample.visual.ratio * 100).toFixed(3)}%`);
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
console.log(` 样式:${surface.bytes} 字节(与 dev/build 同一管线)`);
|
|
694
|
+
if (!args.outline) console.log(' 提示:--outline 看层级与按钮;--all 渲染全部样例;--json 机器可读');
|
|
695
|
+
} finally {
|
|
696
|
+
await vite.close();
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
// 直接运行才走 CLI;被 scripts/storyboard.mjs 导入时只提供渲染函数(同进程复用一次 vite)。
|
|
701
|
+
const invokedDirectly = process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url);
|
|
702
|
+
if (invokedDirectly) {
|
|
703
|
+
try {
|
|
704
|
+
await main();
|
|
705
|
+
} catch (error) {
|
|
706
|
+
if (process.argv.includes('--json')) console.log(JSON.stringify({ ok: false, error: error?.message ?? String(error) }));
|
|
707
|
+
else console.error(`❌ ${error?.message ?? error}`);
|
|
708
|
+
process.exitCode = 1;
|
|
709
|
+
}
|
|
710
|
+
}
|