@tbox.cn/app-template-agent 1.0.0-alpha.1 → 1.0.0-alpha.7
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 +1 -1
- 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 +1 -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 +59 -13
- package/ENV.md +4 -4
- package/README.md +22 -20
- package/apps/._AGENTS.md +0 -0
- package/apps/AGENTS.md +0 -4
- 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/._app-registry.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/app-registry.ts +3 -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 +38 -14
- package/apps/client/.tbox-gen/documents/index.html +38 -14
- 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 +3 -15
- package/apps/client/.tbox-gen/entries/index.tsx +8 -15
- package/apps/client/.tbox-gen/registry.server.ts +4 -4
- package/apps/client/STYLE_GUIDE.md +31 -64
- package/apps/client/index.html +38 -14
- package/apps/client/package.json +3 -3
- 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 +831 -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/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 +2 -2
- 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 -22
- 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/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 +247 -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 +10 -3
- 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/config/._integration.ts +0 -0
- package/apps/server/src/dev.ts +2 -2
- package/apps/server/src/index.ts +2 -2
- 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/helpers/._register.ts +0 -0
- package/apps/server/tests/tool-runtime.test.ts +0 -27
- 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 +145 -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/modules/provider-custom/AGENTS.md +5 -5
- package/modules/provider-custom/INTEGRATION.md +2 -2
- 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/modules/provider-custom/src/server/example-adapter.ts +2 -2
- package/modules/provider-custom/src/server/index.ts +1 -1
- package/modules/provider-custom/tests/._provider-custom.test.ts +0 -0
- package/package.json +13 -5
- 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 +4 -2
- package/packages/shared/package.json +7 -0
- package/packages/shared/src/._index.ts +0 -0
- package/pnpm-lock.template.yaml +679 -464
- package/pnpm-workspace.template.yaml +16 -11
- 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 +118 -0
- package/scripts/check-workspace.mjs +68 -19
- package/scripts/checks.json +253 -0
- package/scripts/compat-probe.mjs +108 -0
- package/scripts/dev-alipay.mjs +1 -1
- package/scripts/gen-tailwind-sources.mjs +55 -0
- package/tsconfig.base.json +1 -0
- package/apps/client/.tbox-gen/app-kind.ts +0 -1
- package/apps/client/src/platform/AgentChatApp.tsx +0 -6
- 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 -10
- package/apps/client/src/platform/mount-page.tsx +0 -20
- package/apps/client/src/platform/state/createPersistedStore.ts +0 -19
- package/apps/server/src/tools/clock.tool.ts +0 -24
- package/apps/server/src/tools/translate.tool.ts +0 -47
- package/packages/agent-ui-kit/src/ChatPage.less +0 -62
- 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/agent-ui-kit/src/theme/{motion.less → motion.css} +0 -0
|
@@ -0,0 +1,831 @@
|
|
|
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
|
+
/**
|
|
538
|
+
* 模块声明面(C3):`modules/<id>/tbox.module.json` 的 declare.tools/cards/actions。
|
|
539
|
+
* 生成 registry 的 tools/cards 只含应用目录;模块能力在运行时由模块 register 装配,
|
|
540
|
+
* 能力图必须把它们算进来,否则 profile/mall 应用的缺口会永远显示「缺工具」。
|
|
541
|
+
*/
|
|
542
|
+
function moduleDeclaredSurface(appDir) {
|
|
543
|
+
const surface = { tools: new Set(), cards: new Set(), actions: new Set() };
|
|
544
|
+
const root = path.join(appDir, 'modules');
|
|
545
|
+
if (!existsSync(root)) return surface;
|
|
546
|
+
for (const name of readdirSync(root)) {
|
|
547
|
+
const file = path.join(root, name, 'tbox.module.json');
|
|
548
|
+
if (!existsSync(file)) continue;
|
|
549
|
+
try {
|
|
550
|
+
// tbox.module.json 是严格 JSON:直接 parse,避免 readJsonc 的注释剥离误伤字符串
|
|
551
|
+
const declare = JSON.parse(readFileSync(file, 'utf8')).declare ?? {};
|
|
552
|
+
for (const tool of declare.tools ?? []) surface.tools.add(typeof tool === 'string' ? tool : tool?.id);
|
|
553
|
+
for (const card of declare.cards ?? []) surface.cards.add(typeof card === 'string' ? card : card?.cardType);
|
|
554
|
+
for (const action of declare.actions ?? []) surface.actions.add(typeof action === 'string' ? action : action?.id);
|
|
555
|
+
} catch {
|
|
556
|
+
// 模块清单坏掉由 build 扫描器报错;这里只做能力图,不重复报
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
for (const set of [surface.tools, surface.cards, surface.actions]) set.delete(undefined);
|
|
560
|
+
return surface;
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
function gateVerdict() {
|
|
564
|
+
const file = ['scenarios/acceptance.jsonc', 'scenarios/acceptance.json'].map((name) => path.join(appDir, name)).find((name) => existsSync(name));
|
|
565
|
+
const doc = file ? readJsonc(file) : {};
|
|
566
|
+
const items = doc.items ?? [];
|
|
567
|
+
const scenarioItems = items.filter((item) => (item.by ?? 'scenario') === 'scenario');
|
|
568
|
+
// E1:review 改名为 handoff(旧名保留为别名)。名字本身不再邀请复审。
|
|
569
|
+
// E2:证据策略声明本任务允许验证到哪一级;handoff 只接受策略判为不可验的维度。
|
|
570
|
+
const policy = ['static', 'visual', 'flow'].includes(doc.policy) ? doc.policy : 'static';
|
|
571
|
+
if (doc.policy && !['static', 'visual', 'flow'].includes(doc.policy)) {
|
|
572
|
+
warn('policy-unknown', `scenarios/acceptance.jsonc 的 policy=${JSON.stringify(doc.policy)} 不支持(static / visual / flow),按 static 处理`, {
|
|
573
|
+
fix: '改成三档之一,或删掉 policy 使用缺省 static',
|
|
574
|
+
recipe: 'verify',
|
|
575
|
+
});
|
|
576
|
+
}
|
|
577
|
+
const handoffItems = items.filter((item) => item.by === 'handoff' || item.by === 'review');
|
|
578
|
+
const covered = new Set();
|
|
579
|
+
for (const result of scenarioResults) {
|
|
580
|
+
if (!result.ok) continue;
|
|
581
|
+
for (const id of result.covers ?? []) covered.add(id);
|
|
582
|
+
}
|
|
583
|
+
// 策略允许场景验证的项不能借 handoff 绕过:没有 reason 的 handoff 计入 incomplete。
|
|
584
|
+
// 旧名 review 不要求 reason(历史应用平滑);新名 handoff 必须写清为什么当前策略验不了。
|
|
585
|
+
const handoffWithoutReason = handoffItems.filter((item) => item.by === 'handoff' && !item.reason);
|
|
586
|
+
const uncovered = [
|
|
587
|
+
...scenarioItems.filter((item) => !covered.has(item.id)).map((item) => item.id),
|
|
588
|
+
...handoffWithoutReason.map((item) => item.id),
|
|
589
|
+
];
|
|
590
|
+
if (handoffWithoutReason.length > 0) {
|
|
591
|
+
warn('handoff-misuse', `handoff 项缺 reason:${handoffWithoutReason.map((item) => item.id).join('、')}(能由场景判定的项不要标 handoff)`, {
|
|
592
|
+
fix: '补一条场景并写 covers,或给 handoff 项加 reason 说明为什么当前策略验不了',
|
|
593
|
+
recipe: 'verify',
|
|
594
|
+
});
|
|
595
|
+
}
|
|
596
|
+
const hasSurface = (registryServer?.tools?.length ?? 0) + (registryServer?.actions?.length ?? 0) > 0;
|
|
597
|
+
|
|
598
|
+
// C3 能力图:验收项上的 tool/action/card 名字键声明「这件事经由什么实现」。
|
|
599
|
+
// 声明了但还没注册 = 缺口;门禁把它列出来,完成的定义从第三分钟起就存在。
|
|
600
|
+
const declaredTools = new Set(items.map((item) => item.tool).filter(Boolean));
|
|
601
|
+
const declaredActions = new Set(items.map((item) => item.action).filter(Boolean));
|
|
602
|
+
const declaredCards = new Set(
|
|
603
|
+
items.flatMap((item) => (Array.isArray(item.on) ? item.on : item.card ? [item.card] : [])).filter(Boolean),
|
|
604
|
+
);
|
|
605
|
+
const registeredTools = new Set((registryServer?.tools ?? []).map((tool) => tool.id));
|
|
606
|
+
const registeredActions = new Set(Object.keys(registryServer?.actions ?? {}));
|
|
607
|
+
const registeredCards = new Set(Object.keys(registryServer?.cards ?? {}));
|
|
608
|
+
const moduleSurface = moduleDeclaredSurface(appDir);
|
|
609
|
+
for (const id of moduleSurface.tools) registeredTools.add(id);
|
|
610
|
+
for (const id of moduleSurface.actions) registeredActions.add(id);
|
|
611
|
+
for (const id of moduleSurface.cards) registeredCards.add(id);
|
|
612
|
+
const missingTools = [...declaredTools].filter((id) => !registeredTools.has(id));
|
|
613
|
+
const missingActions = [...declaredActions].filter((id) => !registeredActions.has(id));
|
|
614
|
+
const missingCards = [...declaredCards].filter((id) => !registeredCards.has(id));
|
|
615
|
+
const capabilities = {
|
|
616
|
+
declared: { tools: declaredTools.size, actions: declaredActions.size, cards: declaredCards.size },
|
|
617
|
+
missing: { tools: missingTools, actions: missingActions, cards: missingCards },
|
|
618
|
+
};
|
|
619
|
+
const missingCapabilityText = [
|
|
620
|
+
...missingTools.map((id) => `工具 ${id}`),
|
|
621
|
+
...missingActions.map((id) => `动作 ${id}`),
|
|
622
|
+
...missingCards.map((id) => `卡片 ${id}`),
|
|
623
|
+
];
|
|
624
|
+
|
|
625
|
+
// 每个验收维度一个状态:已验证 / 未运行(带原因)。验不了的进 handoff,不留作疑问。
|
|
626
|
+
const scenarioSteps = scenarioResults.reduce((sum, item) => sum + (item.steps ?? 0), 0);
|
|
627
|
+
const coverage = {
|
|
628
|
+
structure: '已验证:生成 / 类型 / 结构 / 原语',
|
|
629
|
+
logic:
|
|
630
|
+
scenarioResults.length > 0
|
|
631
|
+
? `已验证:${scenarioResults.length} 个场景 / ${scenarioSteps} 步 / ${covered.size} 项`
|
|
632
|
+
: '未运行:没有场景(先按 verify.md 写一条)',
|
|
633
|
+
render:
|
|
634
|
+
cardDigests.length > 0
|
|
635
|
+
? `已验证:${cardDigests.length} 张卡 / ${scenarioInstances.length + cardDigests.length} 份样例`
|
|
636
|
+
: '未运行:没有卡片',
|
|
637
|
+
visual: policy === 'static' ? '未运行:当前策略 static(任务要求快速交付,不起浏览器)' : '未运行:本轮未执行浏览器(需要 --visual / dev server)',
|
|
638
|
+
routing: policy === 'flow' ? '未运行:本轮未跑模型级验收' : '未运行:当前策略不要求模型级验收',
|
|
639
|
+
};
|
|
640
|
+
const handoff = handoffItems.map((item) => `${item.id} ${item.text ?? ''}`.trim());
|
|
641
|
+
|
|
642
|
+
let verdict;
|
|
643
|
+
let next;
|
|
644
|
+
if (errors.length > 0) {
|
|
645
|
+
verdict = 'failing';
|
|
646
|
+
next = `先修第一个失败项:${errors[0].message}${errors[0].fix ? `(${errors[0].fix})` : ''}`;
|
|
647
|
+
} else if (!file) {
|
|
648
|
+
verdict = hasSurface ? 'unspecified' : 'deliverable';
|
|
649
|
+
next = hasSurface
|
|
650
|
+
? '先把需求拆成 scenarios/acceptance.jsonc 的验收项(id + text),再让场景用 covers 声明覆盖'
|
|
651
|
+
: '交付条件已满足:总结并结束。不要继续复审或打磨。';
|
|
652
|
+
} else if (missingCapabilityText.length > 0) {
|
|
653
|
+
verdict = 'incomplete';
|
|
654
|
+
next = `能力图还缺:${missingCapabilityText.join('、')};先在 acceptance.jsonc 声明,再补对应文件(new tool / new card / new action)`;
|
|
655
|
+
} else if (uncovered.length > 0) {
|
|
656
|
+
verdict = 'incomplete';
|
|
657
|
+
next = `未覆盖验收项:${uncovered.join('、')};补场景并在 covers 里登记,或给确实无法自动判定的项标 by: "handoff" 并写 reason`;
|
|
658
|
+
} else {
|
|
659
|
+
verdict = 'deliverable';
|
|
660
|
+
next =
|
|
661
|
+
handoff.length > 0
|
|
662
|
+
? `把 handoff 的 ${handoff.length} 项原样写进交付说明,然后结束。这些项在当前策略(${policy})下无法验证,继续读代码不会改变它们的状态。`
|
|
663
|
+
: '交付条件已满足:总结并结束。不要继续复审或打磨。';
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
const gateFile = path.join(appDir, '.tbox/evidence/gate.json');
|
|
667
|
+
let previous;
|
|
668
|
+
try {
|
|
669
|
+
previous = JSON.parse(readFileSync(gateFile, 'utf8'));
|
|
670
|
+
} catch {
|
|
671
|
+
previous = undefined;
|
|
672
|
+
}
|
|
673
|
+
let changedFiles = 0;
|
|
674
|
+
try {
|
|
675
|
+
changedFiles = execFileSync('git', ['status', '--porcelain'], { cwd: appDir, encoding: 'utf8' })
|
|
676
|
+
.split('\n')
|
|
677
|
+
.filter((line) => line.trim() && !line.includes('.tbox/')).length;
|
|
678
|
+
} catch {
|
|
679
|
+
changedFiles = 0;
|
|
680
|
+
}
|
|
681
|
+
const runs = previous?.verdict === 'deliverable' ? (previous.runs ?? 0) + 1 : 0;
|
|
682
|
+
const sinceDeliverable = previous?.verdict === 'deliverable' ? { runs, changedFiles } : undefined;
|
|
683
|
+
try {
|
|
684
|
+
mkdirSync(path.dirname(gateFile), { recursive: true });
|
|
685
|
+
writeFileSync(gateFile, JSON.stringify({ verdict, at: Date.now(), changedFiles, runs }));
|
|
686
|
+
} catch {
|
|
687
|
+
// 只读环境不影响裁决
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
return {
|
|
691
|
+
verdict,
|
|
692
|
+
next,
|
|
693
|
+
policy,
|
|
694
|
+
coverage,
|
|
695
|
+
capabilities,
|
|
696
|
+
handoff,
|
|
697
|
+
acceptance: {
|
|
698
|
+
items: items.length,
|
|
699
|
+
covered: covered.size,
|
|
700
|
+
// 旧名保留一版(读取方可能仍看 review);新代码用 handoff。
|
|
701
|
+
review: handoffItems.length,
|
|
702
|
+
handoff: handoffItems.length,
|
|
703
|
+
uncovered,
|
|
704
|
+
...(file ? { file: path.relative(appDir, file) } : {}),
|
|
705
|
+
},
|
|
706
|
+
...(sinceDeliverable ? { sinceDeliverable } : {}),
|
|
707
|
+
};
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
// ── 3.5 渲染与路由的启发式告警(E3) ─────────────────────────────
|
|
711
|
+
// 交付后最常见的两类复审是「界面看不见」与「模型会不会调用工具」。这里把能机器判断的
|
|
712
|
+
// 形态问题变成告警(不阻断):空渲染、状态样例渲染完全相同、工具描述缺失/重复。
|
|
713
|
+
function checkRenderSignals() {
|
|
714
|
+
const empty = cardDigests.filter((item) => !item.text || item.text.trim().length < 6);
|
|
715
|
+
if (empty.length > 0) {
|
|
716
|
+
warn('render-empty', `${empty.length} 份卡片渲染结果为空:${empty.map((item) => `${item.cardType}/${item.label}`).join('、')}`, {
|
|
717
|
+
fix: '检查组件是否按 cardType 注册、样例数据是否为空',
|
|
718
|
+
recipe: 'card',
|
|
719
|
+
});
|
|
720
|
+
}
|
|
721
|
+
const byCard = new Map();
|
|
722
|
+
for (const item of cardDigests) byCard.set(item.cardType, [...(byCard.get(item.cardType) ?? []), item]);
|
|
723
|
+
for (const [cardType, list] of byCard) {
|
|
724
|
+
if (list.length >= 2 && new Set(list.map((item) => item.text)).size === 1) {
|
|
725
|
+
warn('render-identical', `${cardType} 的 ${list.length} 份样例渲染结果完全相同——状态没有真正区分`, {
|
|
726
|
+
fix: '给不同状态不同的可见内容(状态标签/按钮/提示),或删掉重复样例',
|
|
727
|
+
recipe: 'card',
|
|
728
|
+
});
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
const tools = registryServer?.tools ?? [];
|
|
732
|
+
const byDescription = new Map();
|
|
733
|
+
for (const tool of tools) {
|
|
734
|
+
const description = String(tool.description ?? '').trim();
|
|
735
|
+
if (!description) {
|
|
736
|
+
warn('tool-description-empty', `工具 ${tool.id} 的 description 为空——模型没有依据选择它`, { fix: '写「什么时候用」,不要写「做什么」', recipe: 'tool' });
|
|
737
|
+
continue;
|
|
738
|
+
}
|
|
739
|
+
const duplicate = byDescription.get(description);
|
|
740
|
+
if (duplicate) {
|
|
741
|
+
warn('tool-description-duplicate', `工具 ${duplicate} 与 ${tool.id} 的 description 完全相同——模型无法区分`, { fix: '让两个工具的描述各自说明触发场景', recipe: 'tool' });
|
|
742
|
+
} else {
|
|
743
|
+
byDescription.set(description, tool.id);
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
// ── 4.5 状态覆盖(声明样例 + 场景实例) ──────────────────────────
|
|
749
|
+
function checkCoverage() {
|
|
750
|
+
const started = performance.now();
|
|
751
|
+
const metas = registryServer?.cards ?? {};
|
|
752
|
+
for (const [cardType, meta] of Object.entries(metas)) {
|
|
753
|
+
const declared = [
|
|
754
|
+
meta.sampleData,
|
|
755
|
+
...(Array.isArray(meta.samples) ? meta.samples.map((sample) => sample?.data) : []),
|
|
756
|
+
];
|
|
757
|
+
const fromScenarios = scenarioInstances.filter((item) => item.cardType === cardType).map((item) => item.data);
|
|
758
|
+
const samples = [...declared, ...fromScenarios];
|
|
759
|
+
const shape = meta.dataSchema?.shape;
|
|
760
|
+
if (!shape || typeof shape !== 'object') continue;
|
|
761
|
+
for (const [field, schema] of Object.entries(shape)) {
|
|
762
|
+
const values = schema?._def?.values;
|
|
763
|
+
if (!Array.isArray(values) || values.length === 0) continue;
|
|
764
|
+
const seen = new Set(samples.map((data) => data?.[field]).filter((value) => value !== undefined));
|
|
765
|
+
const missing = values.filter((value) => !seen.has(value));
|
|
766
|
+
if (missing.length > 0) {
|
|
767
|
+
warn('card-sample-coverage', `${cardType}.${field} 的状态 ${JSON.stringify(missing)} 既没有样例也没有场景实例`, {
|
|
768
|
+
fix: '补一条 samples,或让场景真的走到这个状态(场景实例自动计入覆盖)',
|
|
769
|
+
recipe: 'card',
|
|
770
|
+
});
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
steps.push({ name: 'coverage', ok: true, ms: Math.round(performance.now() - started), instances: scenarioInstances.length });
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
// ── 执行 ────────────────────────────────────────────────────────────
|
|
778
|
+
await checkStyles();
|
|
779
|
+
if (registryServer) checkPrimitives();
|
|
780
|
+
checkTailwindClasses();
|
|
781
|
+
await checkScenarios();
|
|
782
|
+
if (registryServer) checkCoverage();
|
|
783
|
+
await checkRender();
|
|
784
|
+
checkRenderSignals();
|
|
785
|
+
const verdict = gateVerdict();
|
|
786
|
+
try {
|
|
787
|
+
const dir = path.join(appDir, '.tbox/evidence');
|
|
788
|
+
mkdirSync(dir, { recursive: true });
|
|
789
|
+
writeFileSync(path.join(dir, 'cards.txt'), cardDigests.map((item) => `- ${item.cardType} [${item.source}:${item.label}] ${item.text}`).join('\n') + '\n');
|
|
790
|
+
writeFileSync(path.join(dir, 'scenarios.json'), JSON.stringify(scenarioResults, null, 2) + '\n');
|
|
791
|
+
} catch {
|
|
792
|
+
// 只读环境不影响门禁
|
|
793
|
+
}
|
|
794
|
+
await vite.close();
|
|
795
|
+
|
|
796
|
+
const ok = errors.length === 0;
|
|
797
|
+
const summary = {
|
|
798
|
+
ok,
|
|
799
|
+
durationMs: Math.round(steps.reduce((sum, step) => sum + (step.ms ?? 0), 0)),
|
|
800
|
+
steps,
|
|
801
|
+
registry: {
|
|
802
|
+
tools: (registryServer?.tools ?? []).map((tool) => tool.id),
|
|
803
|
+
cards: Object.keys(registryServer?.cards ?? {}),
|
|
804
|
+
actions: Object.keys(registryServer?.actions ?? {}),
|
|
805
|
+
},
|
|
806
|
+
warnings,
|
|
807
|
+
notRun,
|
|
808
|
+
evidence: { cards: cardDigests.length, scenarios: scenarioResults.length, instances: scenarioInstances.length },
|
|
809
|
+
...verdict,
|
|
810
|
+
};
|
|
811
|
+
if (errors.length > 0) summary.errors = errors;
|
|
812
|
+
|
|
813
|
+
if (!ok) {
|
|
814
|
+
for (const item of errors) {
|
|
815
|
+
const where = item.file ? `${item.file}: ` : '';
|
|
816
|
+
console.error(` ❌ [${item.step}]${item.id ? ` [${item.id}]` : ''} ${where}${item.message}`);
|
|
817
|
+
if (item.fix) console.error(` 修复:${item.fix}${item.recipe ? `(docs/agent/${item.recipe}.md)` : ''}`);
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
for (const item of warnings) console.error(` ⚠️ ${item.message}`);
|
|
821
|
+
|
|
822
|
+
try {
|
|
823
|
+
const dir = path.join(appDir, '.tbox/evidence');
|
|
824
|
+
mkdirSync(dir, { recursive: true });
|
|
825
|
+
writeFileSync(path.join(dir, 'last-gate.json'), json(summary));
|
|
826
|
+
} catch {
|
|
827
|
+
// 只读环境不影响门禁
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
process.stdout.write(json(summary) + '\n');
|
|
831
|
+
if (!ok) process.exitCode = 1;
|