@tbox.cn/app-template-agent 0.10.36 → 1.0.0-alpha.6
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 +7 -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/card-render/._demo.html +0 -0
- package/.tbox/card-render/._demo.png +0 -0
- package/.tbox/card-render/._scale-demo.audit.html +0 -0
- package/.tbox/card-render/._scale-demo.html +0 -0
- package/.tbox/card-render/baseline/._demo.png +0 -0
- package/.tbox/card-render/baseline/demo.png +0 -0
- package/.tbox/card-render/demo.html +342 -0
- package/.tbox/card-render/demo.png +0 -0
- package/.tbox/card-render/scale-demo.audit.html +984 -0
- package/.tbox/card-render/scale-demo.html +939 -0
- package/.tbox/default-modules.json +4 -1
- package/.tbox/evidence/._cards.txt +0 -0
- package/.tbox/evidence/._gate.json +0 -0
- package/.tbox/evidence/._last-gate.json +0 -0
- package/.tbox/evidence/._scenarios.json +0 -0
- package/.tbox/evidence/cards.txt +1 -0
- package/.tbox/evidence/gate.json +1 -0
- package/.tbox/evidence/last-gate.json +1 -0
- package/.tbox/evidence/scenarios.json +1 -0
- package/.tbox/miniapp-containers.json +1 -1
- package/AGENTS.md +93 -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/._STYLE_GUIDE.md +0 -0
- package/apps/client/._VISUAL_RESTORE.md +0 -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/.tbox-gen/._manifest.json +0 -0
- package/apps/client/.tbox-gen/._registry.client.ts +0 -0
- package/apps/client/.tbox-gen/._registry.server.ts +0 -0
- package/apps/client/.tbox-gen/documents/._index.html +0 -0
- package/apps/client/.tbox-gen/documents/_tbox/._card-preview.html +0 -0
- package/apps/client/.tbox-gen/documents/_tbox/card-preview.html +62 -0
- package/apps/client/.tbox-gen/documents/index.html +63 -0
- package/apps/client/.tbox-gen/entries/._card-preview.tsx +0 -0
- package/apps/client/.tbox-gen/entries/._index.tsx +0 -0
- package/apps/client/.tbox-gen/entries/card-preview.tsx +6 -0
- package/apps/client/.tbox-gen/entries/index.tsx +11 -0
- package/apps/client/.tbox-gen/manifest.json +17 -0
- package/apps/client/.tbox-gen/registry.client.ts +6 -0
- package/apps/client/.tbox-gen/registry.server.ts +15 -0
- package/apps/client/STYLE_GUIDE.md +31 -64
- package/apps/client/index.html +39 -15
- package/apps/client/package.json +6 -5
- package/apps/client/scripts/._check-evidence.mjs +0 -0
- package/apps/client/scripts/._render-card.mjs +0 -0
- package/apps/client/scripts/check-evidence.mjs +688 -0
- package/apps/client/scripts/render-card.mjs +743 -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 +40 -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 +51 -0
- package/apps/client/src/styles/tailwind.css +307 -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 +5 -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 +382 -0
- package/apps/server/scripts/scenario-lib.mjs +223 -0
- package/apps/server/scripts/scenario.mjs +33 -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 +20 -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 +13 -0
- package/config/README.md +4 -4
- package/config/chat.json +8 -2
- 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 +96 -0
- package/docs/agent/card.md +116 -0
- package/docs/agent/conversation.md +52 -0
- package/docs/agent/kit.md +79 -0
- package/docs/agent/shell.md +76 -0
- package/docs/agent/state.md +85 -0
- package/docs/agent/style.md +95 -0
- package/docs/agent/tool-emits-card.md +57 -0
- package/docs/agent/tool.md +69 -0
- package/docs/agent/verify.md +129 -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 +19 -6
- 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 +4 -4
- 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 +842 -0
- package/packages/agent-ui-kit/package.json +8 -5
- 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/._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/._types.ts +0 -0
- package/packages/agent-ui-kit/src/._vite-env.d.ts +0 -0
- package/packages/agent-ui-kit/src/ChatPage.tsx +34 -7
- 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/define-card.ts +34 -0
- package/packages/agent-ui-kit/src/card/primitives.test.tsx +147 -0
- package/packages/agent-ui-kit/src/card/primitives.tsx +627 -0
- package/packages/agent-ui-kit/src/card/use-card-actions.ts +86 -0
- package/packages/agent-ui-kit/src/chat-config.test.ts +35 -71
- package/packages/agent-ui-kit/src/chat-config.ts +18 -0
- 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.tsx +3 -3
- package/packages/agent-ui-kit/src/components/ActionBar/index.tsx +13 -14
- 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.tsx +32 -26
- 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/HistoryEntry/._index.tsx +0 -0
- package/packages/agent-ui-kit/src/components/HistoryEntry/index.tsx +3 -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 +52 -27
- 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.tsx +6 -6
- 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 +2 -4
- 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 +54 -36
- 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 +55 -2
- package/packages/agent-ui-kit/src/shell.contract.json +59 -0
- package/packages/agent-ui-kit/src/shell.test.ts +61 -0
- package/packages/agent-ui-kit/src/shell.ts +45 -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 +132 -0
- package/packages/agent-ui-kit/src/theme/contract.json +1 -1
- package/packages/agent-ui-kit/src/theme/theme-contract.test.ts +3 -3
- package/packages/agent-ui-kit/src/theme/{tokens.less → tokens.css} +14 -12
- 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/._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.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/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 +745 -512
- package/pnpm-workspace.template.yaml +17 -10
- package/profiles/._mall.json +0 -0
- package/profiles/mall/._TEMPLATE.md +0 -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/._llm_provider.json +0 -0
- package/profiles/mall/config/._plugins.json +0 -0
- package/scenarios/._README.md +0 -0
- package/scenarios/README.md +7 -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/._compat-probe.mjs +0 -0
- package/scripts/._dev-alipay.mjs +0 -0
- package/scripts/._dev.sh +0 -0
- package/scripts/._gen-tailwind-sources.mjs +0 -0
- package/scripts/._generate.mjs +0 -0
- package/scripts/._prepare.sh +0 -0
- package/scripts/._smoke.mjs +0 -0
- package/scripts/._start.sh +0 -0
- package/scripts/._stop.sh +0 -0
- package/scripts/._verify-generated.mjs +0 -0
- package/scripts/check-css-target.mjs +69 -0
- package/scripts/check-fast.mjs +113 -0
- package/scripts/check-workspace.mjs +68 -19
- package/scripts/checks.json +205 -0
- package/scripts/compat-probe.mjs +108 -0
- package/scripts/dev-alipay.mjs +1 -1
- package/scripts/gen-tailwind-sources.mjs +55 -0
- package/scripts/generate.mjs +3 -0
- package/scripts/verify-generated.mjs +22 -127
- package/tsconfig.base.json +1 -0
- 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/{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,688 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* check-evidence — `check:fast` 的证据包(T0 增强)。
|
|
4
|
+
*
|
|
5
|
+
* 一个进程里跑四步,任何一步失败即给出可执行的修复信息:
|
|
6
|
+
* ① styles —— 用与构建相同的 less 编译应用品牌样式;
|
|
7
|
+
* ② primitives —— 卡片样例过 schema、出卡/动作类型已注册、出卡提示、字号下限、颜色语法;
|
|
8
|
+
* ③ render —— 每张卡 × 每个样例经真实 React 组件渲染(SSR),不抛错;
|
|
9
|
+
* ④ scenarios —— `scenarios/*.json` 全部通过(没有场景记 notRun,不算失败)。
|
|
10
|
+
*
|
|
11
|
+
* 三步共用一个 Vite 实例(`ssrLoadModule` 同时加载客户端卡片与服务端 registry),
|
|
12
|
+
* 合并进程是把四步压进 8 秒预算的前提;分开起进程会超时(实测 3.2–3.9 秒 → 合并 2.1–2.4 秒)。
|
|
13
|
+
*
|
|
14
|
+
* 用法:node scripts/check-evidence.mjs [--no-render] [--no-scenarios] [--json]
|
|
15
|
+
* 退出码:0 = 无错误(告警不影响);1 = 有错误。
|
|
16
|
+
*/
|
|
17
|
+
import { execFileSync } from 'node:child_process';
|
|
18
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
19
|
+
import path from 'node:path';
|
|
20
|
+
import process from 'node:process';
|
|
21
|
+
|
|
22
|
+
// 门禁里的场景与渲染不写真实状态文件。
|
|
23
|
+
process.env.TBOX_STATE_MEMORY ??= '1';
|
|
24
|
+
|
|
25
|
+
const appDir = path.resolve(import.meta.dirname, '..', '..', '..');
|
|
26
|
+
const clientDir = path.join(appDir, 'apps/client');
|
|
27
|
+
const args = new Set(process.argv.slice(2));
|
|
28
|
+
const withRender = !args.has('--no-render');
|
|
29
|
+
const withScenarios = !args.has('--no-scenarios');
|
|
30
|
+
|
|
31
|
+
const MIN_DESIGN_FONT_PX = 22; // ≈11 屏幕像素(750 设计稿,rootValue 100)
|
|
32
|
+
|
|
33
|
+
const steps = [];
|
|
34
|
+
const warnings = [];
|
|
35
|
+
const notRun = [];
|
|
36
|
+
const errors = [];
|
|
37
|
+
let scenarioResults = [];
|
|
38
|
+
let scenarioInstances = [];
|
|
39
|
+
const cardDigests = [];
|
|
40
|
+
|
|
41
|
+
const json = (value) => JSON.stringify(value);
|
|
42
|
+
|
|
43
|
+
function warn(id, message, extra = {}) {
|
|
44
|
+
warnings.push({ id, message, ...extra });
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function fail(step, items) {
|
|
48
|
+
steps.push({ name: step, ok: false, ms: 0 });
|
|
49
|
+
for (const item of items) errors.push({ step, ...(typeof item === 'string' ? { message: item } : item) });
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// ── 0. 一个 Vite 实例 ────────────────────────────────────────────────
|
|
53
|
+
// 不加载应用自己的 vite.config.ts:它把 @tbox.cn/app-build 等仓内源码包当外部依赖交给 Node ESM,
|
|
54
|
+
// 在仓库内(非发布态)会因无扩展名 import 解析失败。这里只需要 TSX 转换、别名与 less。
|
|
55
|
+
const { createServer } = await import('vite');
|
|
56
|
+
const react = (await import('@vitejs/plugin-react')).default;
|
|
57
|
+
let vite;
|
|
58
|
+
const bootstrapStart = performance.now();
|
|
59
|
+
try {
|
|
60
|
+
vite = await createServer({
|
|
61
|
+
configFile: false,
|
|
62
|
+
root: clientDir,
|
|
63
|
+
appType: 'custom',
|
|
64
|
+
logLevel: 'error',
|
|
65
|
+
plugins: [react()],
|
|
66
|
+
resolve: {
|
|
67
|
+
alias: {
|
|
68
|
+
'@': path.join(clientDir, 'src'),
|
|
69
|
+
'@config': path.join(appDir, 'config'),
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
server: { middlewareMode: true, fs: { allow: [appDir] } },
|
|
73
|
+
optimizeDeps: { noDiscovery: true, include: [] },
|
|
74
|
+
});
|
|
75
|
+
steps.push({ name: 'vite', ok: true, ms: Math.round(performance.now() - bootstrapStart) });
|
|
76
|
+
} catch (error) {
|
|
77
|
+
fail('vite', [{ message: `Vite 启动失败:${error?.message ?? error}`, fix: '检查依赖安装与 .tbox-gen 是否生成' }]);
|
|
78
|
+
process.stdout.write(json({ ok: false, durationMs: 0, steps, errors }) + '\n');
|
|
79
|
+
process.exit(1);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const registryClient = await vite.ssrLoadModule('/.tbox-gen/registry.client.ts').catch((error) => {
|
|
83
|
+
fail('registry', [{ id: 'registry-load-failed', message: `客户端 registry 加载失败:${error?.message ?? error}`, fix: '跑 pnpm generate 重新生成 .tbox-gen' }]);
|
|
84
|
+
return undefined;
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
const registryServer = await vite.ssrLoadModule('/@fs' + path.join(clientDir, '.tbox-gen/registry.server.ts')).catch((error) => {
|
|
88
|
+
fail('registry', [{ id: 'registry-load-failed', message: `服务端 registry 加载失败:${error?.message ?? error}`, fix: '跑 pnpm generate 重新生成 .tbox-gen' }]);
|
|
89
|
+
return undefined;
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
// ── 1. styles ───────────────────────────────────────────────────────
|
|
93
|
+
async function checkStyles() {
|
|
94
|
+
const started = performance.now();
|
|
95
|
+
const entry = path.join(clientDir, 'src/styles/brand.css');
|
|
96
|
+
if (!existsSync(entry)) {
|
|
97
|
+
notRun.push('styles');
|
|
98
|
+
warn('styles-entry-missing', '没有 apps/client/src/styles/brand.css:品牌变量无法校验', {
|
|
99
|
+
fix: '新建 brand.css(只放品牌变量覆写,模板出厂自带),app.config.ts 里 import 它',
|
|
100
|
+
recipe: 'style',
|
|
101
|
+
});
|
|
102
|
+
steps.push({ name: 'styles', ok: true, ms: Math.round(performance.now() - started), skipped: true });
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
// 用同一个 Vite 实例过一遍(CSS 由 Vite 的 postcss 管线解析):不再依赖 less。
|
|
106
|
+
try {
|
|
107
|
+
await vite.transformRequest('/src/styles/brand.css');
|
|
108
|
+
steps.push({ name: 'styles', ok: true, ms: Math.round(performance.now() - started) });
|
|
109
|
+
} catch (error) {
|
|
110
|
+
fail('styles', [{
|
|
111
|
+
id: 'styles-compile-failed',
|
|
112
|
+
message: `样式编译失败 ${path.relative(appDir, entry)}:${error?.message ?? error}`,
|
|
113
|
+
fix: '修掉 CSS 语法/变量错误;变量名以 docs/agent/kit.md 的 token 表为准',
|
|
114
|
+
recipe: 'style',
|
|
115
|
+
}]);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// ── 2. primitives ───────────────────────────────────────────────────
|
|
120
|
+
function walkLess(dir, out = []) {
|
|
121
|
+
if (!existsSync(dir)) return out;
|
|
122
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
123
|
+
const full = path.join(dir, entry.name);
|
|
124
|
+
if (entry.isDirectory()) walkLess(full, out);
|
|
125
|
+
else if (entry.name.endsWith('.less')) out.push(full);
|
|
126
|
+
}
|
|
127
|
+
return out;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function checkPrimitives() {
|
|
131
|
+
const started = performance.now();
|
|
132
|
+
const cards = registryServer?.cards ?? {};
|
|
133
|
+
const cardTypes = new Set(Object.keys(cards));
|
|
134
|
+
const tools = registryServer?.tools ?? [];
|
|
135
|
+
|
|
136
|
+
for (const [cardType, meta] of Object.entries(cards)) {
|
|
137
|
+
const samples = [
|
|
138
|
+
['sampleData', meta.sampleData],
|
|
139
|
+
...(Array.isArray(meta.samples) ? meta.samples.map((sample, index) => [`samples[${index}]`, sample?.data]) : []),
|
|
140
|
+
];
|
|
141
|
+
for (const [label, data] of samples) {
|
|
142
|
+
const parsed = meta.dataSchema.safeParse(data);
|
|
143
|
+
if (!parsed.success) {
|
|
144
|
+
errors.push({
|
|
145
|
+
step: 'primitives',
|
|
146
|
+
id: 'card-sample-invalid',
|
|
147
|
+
message: `卡片样例不合法 ${cardType} ${label}: ${parsed.error.issues[0]?.message ?? parsed.error.message}`,
|
|
148
|
+
fix: `补 apps/server/src/cards/${cardType}.card.ts 的 sampleData/samples`,
|
|
149
|
+
recipe: 'card',
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const toolsDir = path.join(appDir, 'apps/server/src/tools');
|
|
156
|
+
const knownToolIds = new Set(tools.map((tool) => tool.id));
|
|
157
|
+
if (existsSync(toolsDir)) {
|
|
158
|
+
for (const name of readdirSync(toolsDir).filter((file) => file.endsWith('.tool.ts'))) {
|
|
159
|
+
const source = readFileSync(path.join(toolsDir, name), 'utf8');
|
|
160
|
+
const id = /id:\s*'([^']+)'/.exec(source)?.[1];
|
|
161
|
+
if (id && !knownToolIds.has(id)) {
|
|
162
|
+
warn('tool-not-registered', `${name}: 工具 id "${id}" 未进入 registry`, {
|
|
163
|
+
fix: '检查是否漏了 export const tool(app-build 只扫描具名导出)',
|
|
164
|
+
recipe: 'tool',
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
const declared = [...source.matchAll(/cardType:\s*'([^']+)'/g)].map((match) => match[1]);
|
|
168
|
+
for (const cardType of new Set(declared)) {
|
|
169
|
+
if (!cardTypes.has(cardType)) {
|
|
170
|
+
errors.push({
|
|
171
|
+
step: 'primitives',
|
|
172
|
+
file: `apps/server/src/tools/${name}`,
|
|
173
|
+
id: 'card-type-unknown',
|
|
174
|
+
message: `出卡类型 "${cardType}" 未注册`,
|
|
175
|
+
fix: `补 apps/server/src/cards/${cardType}.card.ts 与 apps/client/src/cards/${cardType}.card.tsx`,
|
|
176
|
+
recipe: 'card',
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
if (declared.length > 0 && !/可展示卡片/.test(source)) {
|
|
181
|
+
warn('card-emission-hint', `${name}: 出卡工具的 description 未声明「命中数据时结果附可展示卡片(cards)。」`, {
|
|
182
|
+
fix: '用 withCardEmissionHint 或在 description 里补这句,否则模型不知道可以出卡',
|
|
183
|
+
recipe: 'tool-emits-card',
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const actionsDir = path.join(appDir, 'apps/server/src/actions');
|
|
190
|
+
if (existsSync(actionsDir)) {
|
|
191
|
+
for (const name of readdirSync(actionsDir).filter((file) => file.endsWith('.action.ts'))) {
|
|
192
|
+
const source = readFileSync(path.join(actionsDir, name), 'utf8');
|
|
193
|
+
const declaredTypes = [...source.matchAll(/cardType:\s*(\[[^\]]*\]|'[^']+')/g)].flatMap((match) =>
|
|
194
|
+
match[1].startsWith('[') ? [...match[1].matchAll(/'([^']+)'/g)].map((item) => item[1]) : [match[1].slice(1, -1)],
|
|
195
|
+
);
|
|
196
|
+
for (const cardType of new Set(declaredTypes)) {
|
|
197
|
+
if (!cardTypes.has(cardType)) {
|
|
198
|
+
errors.push({
|
|
199
|
+
step: 'primitives',
|
|
200
|
+
file: `apps/server/src/actions/${name}`,
|
|
201
|
+
id: 'action-card-unknown',
|
|
202
|
+
message: `动作挂在不存在的卡片 "${cardType}" 上(按钮不会出现)`,
|
|
203
|
+
fix: `补 apps/server/src/cards/${cardType}.card.ts`,
|
|
204
|
+
recipe: 'card-action',
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// 按钮动作引用与注册表对齐(E3):invoke 字面量 → 动作存在、且挂在这张卡上。
|
|
212
|
+
const actions = registryServer?.actions ?? {};
|
|
213
|
+
const actionsDirClient = path.join(clientDir, 'src/cards');
|
|
214
|
+
if (existsSync(actionsDirClient)) {
|
|
215
|
+
for (const name of readdirSync(actionsDirClient).filter((file) => file.endsWith('.card.tsx'))) {
|
|
216
|
+
const cardType = name.slice(0, -'.card.tsx'.length);
|
|
217
|
+
const source = readFileSync(path.join(actionsDirClient, name), 'utf8');
|
|
218
|
+
const ids = new Set([...source.matchAll(/\binvoke\s*:\s*\{\s*id\s*:\s*'([^']+)'/g)].map((match) => match[1]));
|
|
219
|
+
for (const id of ids) {
|
|
220
|
+
const action = actions[id];
|
|
221
|
+
if (!action) {
|
|
222
|
+
errors.push({
|
|
223
|
+
step: 'primitives',
|
|
224
|
+
file: `apps/client/src/cards/${name}`,
|
|
225
|
+
id: 'action-invoke-unknown',
|
|
226
|
+
message: `按钮 invoke 的动作 "${id}" 未注册`,
|
|
227
|
+
fix: `补 apps/server/src/actions/${id}.action.ts,或改 invoke 的 id`,
|
|
228
|
+
recipe: 'card-action',
|
|
229
|
+
});
|
|
230
|
+
continue;
|
|
231
|
+
}
|
|
232
|
+
const bound = Array.isArray(action.cardType) ? action.cardType : [action.cardType];
|
|
233
|
+
if (!bound.includes(cardType)) {
|
|
234
|
+
errors.push({
|
|
235
|
+
step: 'primitives',
|
|
236
|
+
file: `apps/client/src/cards/${name}`,
|
|
237
|
+
id: 'action-invoke-card-mismatch',
|
|
238
|
+
message: `动作 "${id}" 没有绑定到 ${cardType}(声明:${bound.join('、') || '无'})`,
|
|
239
|
+
fix: `把 ${cardType} 加进动作的 cardType,或从这张卡上撤掉该按钮`,
|
|
240
|
+
recipe: 'card-action',
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
for (const file of walkLess(path.join(clientDir, 'src'))) {
|
|
248
|
+
const rel = path.relative(appDir, file);
|
|
249
|
+
readFileSync(file, 'utf8').split('\n').forEach((line, index) => {
|
|
250
|
+
const at = `${rel}:${index + 1}`;
|
|
251
|
+
for (const match of line.matchAll(/font-size:\s*(\d+(?:\.\d+)?)px\b/g)) {
|
|
252
|
+
const size = Number(match[1]);
|
|
253
|
+
if (size > 0 && size < MIN_DESIGN_FONT_PX) {
|
|
254
|
+
warn('font-too-small', `${at}: font-size ${size}px 低于可读下限 ${MIN_DESIGN_FONT_PX}px(≈${Math.round(size / 2)} 屏幕像素)`, {
|
|
255
|
+
fix: '设计稿 750 宽:正文 ≥22px、辅助 ≥22px;屏幕像素 = 设计稿/2',
|
|
256
|
+
recipe: 'style',
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
if (/rgb\(\s*\d+\s+\d+\s+\d+\s*\/|\brgb\([^)]*\s\/\s/.test(line)) {
|
|
261
|
+
warn('color-syntax', `${at}: 使用 CSS Color 4 空格语法,旧 web-view 整条失效`, {
|
|
262
|
+
fix: '改用 rgba(r, g, b, a)',
|
|
263
|
+
recipe: 'style',
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
steps.push({ name: 'primitives', ok: !errors.some((item) => item.step === 'primitives'), ms: Math.round(performance.now() - started) });
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// ── 2b. tailwind 类名禁忌(禁用项)────────────────────────────────────
|
|
273
|
+
// Tailwind 对不认识的类不报错、只是不生成——所以这几类必须让它们出声。
|
|
274
|
+
// 规则与 docs/agent/style.md 一一对应:默认调色板、语义色的透明度修饰符(依赖 color-mix)、
|
|
275
|
+
// 档外字号、元素级 --tbox-asset-* 声明(会截断 html[data-theme] 覆写继承)。
|
|
276
|
+
/** 判断一个 token 像不像工具类(去掉变体前缀后看末段):用来把 BEM 钩子排除在外 */
|
|
277
|
+
function looksLikeUtility(token) {
|
|
278
|
+
if (token.includes('__')) return false;
|
|
279
|
+
let depth = 0;
|
|
280
|
+
let cut = 0;
|
|
281
|
+
for (let i = 0; i < token.length; i += 1) {
|
|
282
|
+
const ch = token[i];
|
|
283
|
+
if (ch === '[') depth += 1;
|
|
284
|
+
else if (ch === ']') depth -= 1;
|
|
285
|
+
else if (ch === ':' && depth === 0) cut = i + 1;
|
|
286
|
+
}
|
|
287
|
+
const base = token.slice(cut);
|
|
288
|
+
if (base.startsWith('[')) return base.length > 3 && base.includes(']');
|
|
289
|
+
return /^(?:-?(?:m|p)[trblxy]?|w|h|size|min|max|gap|space|inset|top|right|bottom|left|z|flex|grid|block|inline|hidden|items|justify|content|self|place|order|col|row|basis|grow|shrink|text|font|leading|tracking|whitespace|break|truncate|line-clamp|bg|border|rounded|shadow|ring|outline|opacity|transition|duration|ease|delay|animate|cursor|appearance|fill|stroke|object|aspect|overflow|divide|sr-only|tabular-nums|antialiased|from|via|to)(?:-|$)/.test(base);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
const TAILWIND_BANNED = [
|
|
293
|
+
{
|
|
294
|
+
id: 'palette-color',
|
|
295
|
+
pattern: /\b(?:bg|text|border|from|to|via|ring|outline|fill|stroke|divide|placeholder|decoration)-(?:slate|gray|zinc|neutral|stone|red|orange|amber|yellow|lime|green|emerald|teal|cyan|sky|blue|indigo|violet|purple|fuchsia|pink|rose)-\d{2,3}\b/,
|
|
296
|
+
message: '用了 Tailwind 默认调色板(不生成 CSS,且产物会带 oklch)',
|
|
297
|
+
fix: '换成语义色:text-foreground / bg-card / border-border 等(docs/agent/style.md)',
|
|
298
|
+
},
|
|
299
|
+
{
|
|
300
|
+
id: 'color-opacity-modifier',
|
|
301
|
+
pattern: /\b(?:bg|text|border|ring|outline|fill|stroke|from|to|via|divide|placeholder|decoration)-(?!xs\b|sm\b|base\b|lg\b|xl\b|2xl\b|3xl\b)[a-z][a-z0-9-]*\/\d{1,3}\b/,
|
|
302
|
+
message: '用了颜色透明度修饰符(依赖 color-mix,旧内核回落为不透明)',
|
|
303
|
+
fix: '改带 alpha 的任意值,如 bg-[rgba(255,255,255,0.18)]',
|
|
304
|
+
},
|
|
305
|
+
{
|
|
306
|
+
id: 'font-size-off-scale',
|
|
307
|
+
pattern: /\btext-\[\d+(?:\.\d+)?px\]/,
|
|
308
|
+
message: '字号越档(只有 12/14/16/18/20/24/30 六档)',
|
|
309
|
+
fix: '用 text-xs/sm/base/lg/xl/2xl/3xl;确需精确值改 line-height 或行内样式',
|
|
310
|
+
},
|
|
311
|
+
{
|
|
312
|
+
id: 'class-before-interpolation',
|
|
313
|
+
// 类名紧贴 `${` 时扫描器拿不到完整候选(实测 `gap-1.5${…}` 整条不生成 CSS)
|
|
314
|
+
pattern: /(?:^|[\s'"`{])([a-z[][\w:[\]/.(),#%-]*)\$\{/,
|
|
315
|
+
message: '类名紧贴模板插值(扫描器会漏掉这条类,样式静默不生效)',
|
|
316
|
+
fix: '在 `${` 前留一个空格:`text-xs ${cond ? … : …}`',
|
|
317
|
+
skip: (token) => !looksLikeUtility(token),
|
|
318
|
+
},
|
|
319
|
+
{
|
|
320
|
+
id: 'element-asset-declaration',
|
|
321
|
+
pattern: /\[--tbox-asset-/,
|
|
322
|
+
message: '在元素上声明 --tbox-asset-*(会截断 html[data-theme] 覆写继承)',
|
|
323
|
+
fix: '素材变量归主题包;元素只消费 var(--tbox-asset-*, 兜底)',
|
|
324
|
+
},
|
|
325
|
+
];
|
|
326
|
+
|
|
327
|
+
function checkTailwindClasses() {
|
|
328
|
+
const started = performance.now();
|
|
329
|
+
const roots = [
|
|
330
|
+
path.join(clientDir, 'src'),
|
|
331
|
+
path.join(appDir, 'packages/agent-ui-kit/src'),
|
|
332
|
+
];
|
|
333
|
+
const files = [];
|
|
334
|
+
const walkTsx = (dir) => {
|
|
335
|
+
if (!existsSync(dir)) return;
|
|
336
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
337
|
+
const full = path.join(dir, entry.name);
|
|
338
|
+
if (entry.isDirectory()) walkTsx(full);
|
|
339
|
+
else if (entry.name.endsWith('.tsx') || entry.name.endsWith('.ts')) files.push(full);
|
|
340
|
+
}
|
|
341
|
+
};
|
|
342
|
+
roots.forEach(walkTsx);
|
|
343
|
+
for (const file of files) {
|
|
344
|
+
const rel = path.relative(appDir, file);
|
|
345
|
+
readFileSync(file, 'utf8').split('\n').forEach((line, index) => {
|
|
346
|
+
for (const rule of TAILWIND_BANNED) {
|
|
347
|
+
const match = rule.pattern.exec(line);
|
|
348
|
+
if (!match) continue;
|
|
349
|
+
if (rule.skip?.(match[1] ?? '')) continue;
|
|
350
|
+
errors.push({
|
|
351
|
+
step: 'primitives',
|
|
352
|
+
file: `${rel}:${index + 1}`,
|
|
353
|
+
id: rule.id,
|
|
354
|
+
message: `${rule.message}:${match[0]}`,
|
|
355
|
+
fix: rule.fix,
|
|
356
|
+
recipe: 'style',
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
steps.push({ name: 'tailwind', ok: !errors.some((item) => item.step === 'primitives'), ms: Math.round(performance.now() - started), files: files.length });
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
function htmlDigest(html) {
|
|
365
|
+
return String(html)
|
|
366
|
+
.replace(/<script[\s\S]*?<\/script>/g, ' ')
|
|
367
|
+
.replace(/<style[\s\S]*?<\/style>/g, ' ')
|
|
368
|
+
.replace(/<[^>]+>/g, ' ')
|
|
369
|
+
.replace(/ /g, ' ')
|
|
370
|
+
.replace(/\s+/g, ' ')
|
|
371
|
+
.trim()
|
|
372
|
+
.slice(0, 240);
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
// ── 3. render ───────────────────────────────────────────────────────
|
|
376
|
+
async function checkRender() {
|
|
377
|
+
const started = performance.now();
|
|
378
|
+
if (!withRender) {
|
|
379
|
+
notRun.push('render');
|
|
380
|
+
steps.push({ name: 'render', ok: true, ms: 0, skipped: true });
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
const metas = registryServer?.cards ?? {};
|
|
384
|
+
if (Object.keys(metas).length === 0) {
|
|
385
|
+
steps.push({ name: 'render', ok: true, ms: Math.round(performance.now() - started), cards: 0, rendered: 0, skipped: true });
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
const React = (await import('react')).default;
|
|
389
|
+
const { renderToStaticMarkup } = await import('react-dom/server');
|
|
390
|
+
const { createStore } = await import('zustand/vanilla');
|
|
391
|
+
const { useStore } = await import('zustand');
|
|
392
|
+
const kit = await vite.ssrLoadModule('@tbox.cn/app-agent-ui-kit');
|
|
393
|
+
|
|
394
|
+
const store = createStore(() => ({ sendUiAction() {}, isGenerating: false }));
|
|
395
|
+
const hook = (selector) => useStore(store, selector);
|
|
396
|
+
hook.getState = store.getState;
|
|
397
|
+
hook.setState = store.setState;
|
|
398
|
+
hook.subscribe = store.subscribe;
|
|
399
|
+
|
|
400
|
+
const components = registryClient?.cards ?? {};
|
|
401
|
+
let rendered = 0;
|
|
402
|
+
let bytes = 0;
|
|
403
|
+
|
|
404
|
+
for (const [cardType, meta] of Object.entries(metas)) {
|
|
405
|
+
const Component = components[cardType];
|
|
406
|
+
if (!Component) {
|
|
407
|
+
errors.push({
|
|
408
|
+
step: 'render',
|
|
409
|
+
id: 'card-client-missing',
|
|
410
|
+
message: `客户端缺少卡片组件 ${cardType}`,
|
|
411
|
+
fix: `补 apps/client/src/cards/${cardType}.card.tsx(export const card = defineCard({ type: '${cardType}' }, …))`,
|
|
412
|
+
recipe: 'card',
|
|
413
|
+
});
|
|
414
|
+
continue;
|
|
415
|
+
}
|
|
416
|
+
const samples = [
|
|
417
|
+
['sampleData', meta.sampleData],
|
|
418
|
+
...(Array.isArray(meta.samples) ? meta.samples.map((sample, index) => [sample?.label ?? `samples[${index}]`, sample?.data]) : []),
|
|
419
|
+
];
|
|
420
|
+
for (const [label, data] of samples) {
|
|
421
|
+
try {
|
|
422
|
+
const html = renderToStaticMarkup(
|
|
423
|
+
React.createElement(
|
|
424
|
+
kit.KitChatProvider,
|
|
425
|
+
{ store: hook, cards: components, rawCards: components },
|
|
426
|
+
React.createElement(Component, { data, cardId: `evidence-${cardType}`, isHistory: false, actionTokens: {} }),
|
|
427
|
+
),
|
|
428
|
+
);
|
|
429
|
+
rendered += 1;
|
|
430
|
+
bytes += html.length;
|
|
431
|
+
cardDigests.push({ cardType, label, source: 'sample', text: htmlDigest(html) });
|
|
432
|
+
if (html.trim() === '') {
|
|
433
|
+
errors.push({
|
|
434
|
+
step: 'render',
|
|
435
|
+
id: 'card-render-empty',
|
|
436
|
+
message: `卡片 ${cardType} ${label} 渲染为空`,
|
|
437
|
+
fix: '组件返回了空树;检查数据字段与条件分支',
|
|
438
|
+
recipe: 'card',
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
} catch (error) {
|
|
442
|
+
errors.push({
|
|
443
|
+
step: 'render',
|
|
444
|
+
file: `apps/client/src/cards/${cardType}.card.tsx`,
|
|
445
|
+
id: 'card-render-failed',
|
|
446
|
+
message: `卡片 ${cardType} ${label} 渲染抛错:${error?.message ?? error}`,
|
|
447
|
+
fix: '按报错栈修组件;数据形状以服务端 dataSchema 为准',
|
|
448
|
+
recipe: 'card',
|
|
449
|
+
});
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
for (const instance of scenarioInstances) {
|
|
455
|
+
const Component = components[instance.cardType];
|
|
456
|
+
if (!Component) continue;
|
|
457
|
+
try {
|
|
458
|
+
const html = renderToStaticMarkup(
|
|
459
|
+
React.createElement(
|
|
460
|
+
kit.KitChatProvider,
|
|
461
|
+
{ store: hook, cards: components, rawCards: components },
|
|
462
|
+
React.createElement(Component, {
|
|
463
|
+
data: instance.data,
|
|
464
|
+
cardId: `evidence-scenario-${instance.cardType}-${instance.step}`,
|
|
465
|
+
isHistory: false,
|
|
466
|
+
actionTokens: {},
|
|
467
|
+
}),
|
|
468
|
+
),
|
|
469
|
+
);
|
|
470
|
+
rendered += 1;
|
|
471
|
+
bytes += html.length;
|
|
472
|
+
cardDigests.push({ cardType: instance.cardType, label: `${instance.file}#${instance.step}`, source: 'scenario', text: htmlDigest(html) });
|
|
473
|
+
} catch (error) {
|
|
474
|
+
errors.push({
|
|
475
|
+
step: 'render',
|
|
476
|
+
file: instance.file,
|
|
477
|
+
id: 'scenario-card-render-failed',
|
|
478
|
+
message: `${instance.file} #${instance.step} 的 ${instance.cardType} 实例渲染抛错:${error?.message ?? error}`,
|
|
479
|
+
fix: '按报错栈修组件;数据形状以服务端 dataSchema 为准',
|
|
480
|
+
recipe: 'card',
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
steps.push({ name: 'render', ok: !errors.some((item) => item.step === 'render'), ms: Math.round(performance.now() - started), cards: Object.keys(metas).length, rendered, bytes });
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
// ── 4. scenarios ────────────────────────────────────────────────────
|
|
489
|
+
async function checkScenarios() {
|
|
490
|
+
const started = performance.now();
|
|
491
|
+
if (!withScenarios) {
|
|
492
|
+
notRun.push('scenarios');
|
|
493
|
+
steps.push({ name: 'scenarios', ok: true, ms: 0, skipped: true });
|
|
494
|
+
return;
|
|
495
|
+
}
|
|
496
|
+
if (!existsSync(path.join(appDir, 'scenarios'))) {
|
|
497
|
+
notRun.push('scenarios');
|
|
498
|
+
steps.push({ name: 'scenarios', ok: true, ms: Math.round(performance.now() - started), scenarios: 0, skipped: true });
|
|
499
|
+
return;
|
|
500
|
+
}
|
|
501
|
+
if (!registryServer) {
|
|
502
|
+
steps.push({ name: 'scenarios', ok: false, ms: Math.round(performance.now() - started) });
|
|
503
|
+
return;
|
|
504
|
+
}
|
|
505
|
+
try {
|
|
506
|
+
const lib = await vite.ssrLoadModule('/@fs' + path.join(appDir, 'apps/server/scripts/scenario-lib.mjs'));
|
|
507
|
+
const files = lib.resolveScenarioFiles(appDir, []);
|
|
508
|
+
if (files.length === 0) {
|
|
509
|
+
notRun.push('scenarios');
|
|
510
|
+
steps.push({ name: 'scenarios', ok: true, ms: Math.round(performance.now() - started), scenarios: 0, skipped: true });
|
|
511
|
+
return;
|
|
512
|
+
}
|
|
513
|
+
const result = await lib.runScenarios({ appDir, registry: registryServer, files });
|
|
514
|
+
scenarioResults = result.results;
|
|
515
|
+
scenarioInstances = result.instances ?? [];
|
|
516
|
+
for (const item of result.results) {
|
|
517
|
+
for (const line of item.failures) {
|
|
518
|
+
errors.push({ step: 'scenarios', id: 'scenario-failed', file: item.file, message: line, fix: '按失败断言修工具/动作;期望值只写稳定字段', recipe: 'verify' });
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
const totalSteps = result.results.reduce((sum, item) => sum + item.steps, 0);
|
|
522
|
+
steps.push({ name: 'scenarios', ok: result.ok, ms: Math.round(performance.now() - started), files: result.scenarios, steps: totalSteps, passed: result.ok ? totalSteps : undefined });
|
|
523
|
+
} catch (error) {
|
|
524
|
+
fail('scenarios', [{ message: `场景执行失败:${error?.message ?? error}`, fix: '检查 scenarios/*.json 格式与工具 id', recipe: 'verify' }]);
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
// ── 5. 验收项与裁决(V1–V3) ─────────────────────────────────────
|
|
529
|
+
function readJsonc(file) {
|
|
530
|
+
const raw = readFileSync(file, 'utf8')
|
|
531
|
+
.replace(/\/\*[\s\S]*?\*\//g, '')
|
|
532
|
+
.replace(/(^|[^:])\/\/[^\n]*/g, '$1')
|
|
533
|
+
.replace(/,\s*([}\]])/g, '$1');
|
|
534
|
+
return JSON.parse(raw);
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
function gateVerdict() {
|
|
538
|
+
const file = ['scenarios/acceptance.jsonc', 'scenarios/acceptance.json'].map((name) => path.join(appDir, name)).find((name) => existsSync(name));
|
|
539
|
+
const items = file ? readJsonc(file).items ?? [] : [];
|
|
540
|
+
const scenarioItems = items.filter((item) => (item.by ?? 'scenario') === 'scenario');
|
|
541
|
+
const reviewItems = items.filter((item) => item.by === 'review');
|
|
542
|
+
const covered = new Set();
|
|
543
|
+
for (const result of scenarioResults) {
|
|
544
|
+
if (!result.ok) continue;
|
|
545
|
+
for (const id of result.covers ?? []) covered.add(id);
|
|
546
|
+
}
|
|
547
|
+
const uncovered = scenarioItems.filter((item) => !covered.has(item.id)).map((item) => item.id);
|
|
548
|
+
const hasSurface = (registryServer?.tools?.length ?? 0) + (registryServer?.actions?.length ?? 0) > 0;
|
|
549
|
+
|
|
550
|
+
let verdict;
|
|
551
|
+
let next;
|
|
552
|
+
if (errors.length > 0) {
|
|
553
|
+
verdict = 'failing';
|
|
554
|
+
next = `先修第一个失败项:${errors[0].message}${errors[0].fix ? `(${errors[0].fix})` : ''}`;
|
|
555
|
+
} else if (!file) {
|
|
556
|
+
verdict = hasSurface ? 'unspecified' : 'deliverable';
|
|
557
|
+
next = hasSurface
|
|
558
|
+
? '先把需求拆成 scenarios/acceptance.jsonc 的验收项(id + text),再让场景用 covers 声明覆盖'
|
|
559
|
+
: '交付条件已满足:总结并结束。不要继续复审或打磨。';
|
|
560
|
+
} else if (uncovered.length > 0) {
|
|
561
|
+
verdict = 'incomplete';
|
|
562
|
+
next = `未覆盖验收项:${uncovered.join('、')};补场景并在 covers 里登记,或把无法自动判定的项标 by: "review"`;
|
|
563
|
+
} else {
|
|
564
|
+
verdict = 'deliverable';
|
|
565
|
+
next = '交付条件已满足:总结并结束。不要继续复审或打磨。';
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
const gateFile = path.join(appDir, '.tbox/evidence/gate.json');
|
|
569
|
+
let previous;
|
|
570
|
+
try {
|
|
571
|
+
previous = JSON.parse(readFileSync(gateFile, 'utf8'));
|
|
572
|
+
} catch {
|
|
573
|
+
previous = undefined;
|
|
574
|
+
}
|
|
575
|
+
let changedFiles = 0;
|
|
576
|
+
try {
|
|
577
|
+
changedFiles = execFileSync('git', ['status', '--porcelain'], { cwd: appDir, encoding: 'utf8' })
|
|
578
|
+
.split('\n')
|
|
579
|
+
.filter((line) => line.trim() && !line.includes('.tbox/')).length;
|
|
580
|
+
} catch {
|
|
581
|
+
changedFiles = 0;
|
|
582
|
+
}
|
|
583
|
+
const runs = previous?.verdict === 'deliverable' ? (previous.runs ?? 0) + 1 : 0;
|
|
584
|
+
const sinceDeliverable = previous?.verdict === 'deliverable' ? { runs, changedFiles } : undefined;
|
|
585
|
+
try {
|
|
586
|
+
mkdirSync(path.dirname(gateFile), { recursive: true });
|
|
587
|
+
writeFileSync(gateFile, JSON.stringify({ verdict, at: Date.now(), changedFiles, runs }));
|
|
588
|
+
} catch {
|
|
589
|
+
// 只读环境不影响裁决
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
return {
|
|
593
|
+
verdict,
|
|
594
|
+
next,
|
|
595
|
+
acceptance: {
|
|
596
|
+
items: items.length,
|
|
597
|
+
covered: covered.size,
|
|
598
|
+
review: reviewItems.length,
|
|
599
|
+
uncovered,
|
|
600
|
+
...(file ? { file: path.relative(appDir, file) } : {}),
|
|
601
|
+
},
|
|
602
|
+
...(sinceDeliverable ? { sinceDeliverable } : {}),
|
|
603
|
+
};
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
// ── 4.5 状态覆盖(声明样例 + 场景实例) ──────────────────────────
|
|
607
|
+
function checkCoverage() {
|
|
608
|
+
const started = performance.now();
|
|
609
|
+
const metas = registryServer?.cards ?? {};
|
|
610
|
+
for (const [cardType, meta] of Object.entries(metas)) {
|
|
611
|
+
const declared = [
|
|
612
|
+
meta.sampleData,
|
|
613
|
+
...(Array.isArray(meta.samples) ? meta.samples.map((sample) => sample?.data) : []),
|
|
614
|
+
];
|
|
615
|
+
const fromScenarios = scenarioInstances.filter((item) => item.cardType === cardType).map((item) => item.data);
|
|
616
|
+
const samples = [...declared, ...fromScenarios];
|
|
617
|
+
const shape = meta.dataSchema?.shape;
|
|
618
|
+
if (!shape || typeof shape !== 'object') continue;
|
|
619
|
+
for (const [field, schema] of Object.entries(shape)) {
|
|
620
|
+
const values = schema?._def?.values;
|
|
621
|
+
if (!Array.isArray(values) || values.length === 0) continue;
|
|
622
|
+
const seen = new Set(samples.map((data) => data?.[field]).filter((value) => value !== undefined));
|
|
623
|
+
const missing = values.filter((value) => !seen.has(value));
|
|
624
|
+
if (missing.length > 0) {
|
|
625
|
+
warn('card-sample-coverage', `${cardType}.${field} 的状态 ${JSON.stringify(missing)} 既没有样例也没有场景实例`, {
|
|
626
|
+
fix: '补一条 samples,或让场景真的走到这个状态(场景实例自动计入覆盖)',
|
|
627
|
+
recipe: 'card',
|
|
628
|
+
});
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
steps.push({ name: 'coverage', ok: true, ms: Math.round(performance.now() - started), instances: scenarioInstances.length });
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
// ── 执行 ────────────────────────────────────────────────────────────
|
|
636
|
+
await checkStyles();
|
|
637
|
+
if (registryServer) checkPrimitives();
|
|
638
|
+
checkTailwindClasses();
|
|
639
|
+
await checkScenarios();
|
|
640
|
+
if (registryServer) checkCoverage();
|
|
641
|
+
await checkRender();
|
|
642
|
+
const verdict = gateVerdict();
|
|
643
|
+
try {
|
|
644
|
+
const dir = path.join(appDir, '.tbox/evidence');
|
|
645
|
+
mkdirSync(dir, { recursive: true });
|
|
646
|
+
writeFileSync(path.join(dir, 'cards.txt'), cardDigests.map((item) => `- ${item.cardType} [${item.source}:${item.label}] ${item.text}`).join('\n') + '\n');
|
|
647
|
+
writeFileSync(path.join(dir, 'scenarios.json'), JSON.stringify(scenarioResults, null, 2) + '\n');
|
|
648
|
+
} catch {
|
|
649
|
+
// 只读环境不影响门禁
|
|
650
|
+
}
|
|
651
|
+
await vite.close();
|
|
652
|
+
|
|
653
|
+
const ok = errors.length === 0;
|
|
654
|
+
const summary = {
|
|
655
|
+
ok,
|
|
656
|
+
durationMs: Math.round(steps.reduce((sum, step) => sum + (step.ms ?? 0), 0)),
|
|
657
|
+
steps,
|
|
658
|
+
registry: {
|
|
659
|
+
tools: (registryServer?.tools ?? []).map((tool) => tool.id),
|
|
660
|
+
cards: Object.keys(registryServer?.cards ?? {}),
|
|
661
|
+
actions: Object.keys(registryServer?.actions ?? {}),
|
|
662
|
+
},
|
|
663
|
+
warnings,
|
|
664
|
+
notRun,
|
|
665
|
+
evidence: { cards: cardDigests.length, scenarios: scenarioResults.length, instances: scenarioInstances.length },
|
|
666
|
+
...verdict,
|
|
667
|
+
};
|
|
668
|
+
if (errors.length > 0) summary.errors = errors;
|
|
669
|
+
|
|
670
|
+
if (!ok) {
|
|
671
|
+
for (const item of errors) {
|
|
672
|
+
const where = item.file ? `${item.file}: ` : '';
|
|
673
|
+
console.error(` ❌ [${item.step}]${item.id ? ` [${item.id}]` : ''} ${where}${item.message}`);
|
|
674
|
+
if (item.fix) console.error(` 修复:${item.fix}${item.recipe ? `(docs/agent/${item.recipe}.md)` : ''}`);
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
for (const item of warnings) console.error(` ⚠️ ${item.message}`);
|
|
678
|
+
|
|
679
|
+
try {
|
|
680
|
+
const dir = path.join(appDir, '.tbox/evidence');
|
|
681
|
+
mkdirSync(dir, { recursive: true });
|
|
682
|
+
writeFileSync(path.join(dir, 'last-gate.json'), json(summary));
|
|
683
|
+
} catch {
|
|
684
|
+
// 只读环境不影响门禁
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
process.stdout.write(json(summary) + '\n');
|
|
688
|
+
if (!ok) process.exitCode = 1;
|