@tbox.cn/app-template-agent 1.0.0-alpha.20 → 1.0.0-alpha.21
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/._.ignore +0 -0
- package/.ignore +9 -0
- package/.tbox/app.json +1 -1
- package/.tbox/cache/._.eslintcache +0 -0
- package/.tbox/cache/.eslintcache +1 -0
- package/.tbox/cache/apps-client.tsbuildinfo +1 -1
- package/.tbox/cache/apps-server.tsbuildinfo +1 -1
- package/.tbox/cache/packages-agent-ui-kit.tsbuildinfo +1 -1
- package/.tbox/default-modules.json +1 -1
- package/.tbox/miniapp-containers.json +1 -1
- package/AGENTS.md +1 -1
- package/apps/client/scripts/check-evidence.mjs +61 -15
- package/apps/client/scripts/experience-checks.mjs +50 -5
- package/apps/client/scripts/in-process-checks.mjs +52 -2
- package/apps/client/scripts/lib/._tool-cards-static.mjs +0 -0
- package/apps/client/scripts/lib/tool-cards-static.mjs +91 -0
- package/apps/client/scripts/probe-checks.mjs +1 -0
- package/docs/agent/card.md +1 -1
- package/docs/agent/errors.md +4 -1
- package/docs/agent/kit.md +4 -3
- package/docs/agent/shell.md +34 -3
- package/docs/agent/style.md +3 -3
- package/package.json +5 -4
- package/packages/agent-ui-kit/catalog.json +16 -3
- package/packages/agent-ui-kit/package.json +1 -1
- package/packages/agent-ui-kit/src/ChatPage.tsx +48 -11
- package/packages/agent-ui-kit/src/card/primitives.tsx +38 -17
- package/packages/agent-ui-kit/src/card/view-card.tsx +4 -1
- package/packages/agent-ui-kit/src/chat-config.test.ts +19 -1
- package/packages/agent-ui-kit/src/chat-config.ts +23 -1
- package/packages/agent-ui-kit/src/components/QuickCommands/index.test.tsx +55 -0
- package/packages/agent-ui-kit/src/components/QuickCommands/index.tsx +72 -11
- package/packages/agent-ui-kit/src/components/StarterQuestions/._index.test.tsx +0 -0
- package/packages/agent-ui-kit/src/components/StarterQuestions/._index.tsx +0 -0
- package/packages/agent-ui-kit/src/components/StarterQuestions/index.test.tsx +115 -0
- package/packages/agent-ui-kit/src/components/StarterQuestions/index.tsx +61 -0
- package/packages/agent-ui-kit/src/contract.test.tsx +13 -1
- package/packages/agent-ui-kit/src/shell.contract.json +9 -2
- package/packages/agent-ui-kit/src/shell.test.ts +1 -0
- package/packages/agent-ui-kit/src/theme/base.css +10 -5
- package/pnpm-lock.template.yaml +94 -94
- package/pnpm-workspace.template.yaml +11 -11
- package/profiles/mall.json +5 -3
- package/scripts/check-fast.mjs +3 -1
- package/scripts/checks.json +42 -3
- package/scripts/shell-probe.mjs +82 -5
- package/scripts/storyboard.mjs +37 -0
package/AGENTS.md
CHANGED
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
| 把一条联动链路存成可执行断言 | [verify](docs/agent/verify.md) | `pnpm exec tbox-app scenario record <名称> --steps "…"`、`pnpm exec tbox-app scenario run` |
|
|
39
39
|
| 改提示词 / 对话配置 | [agent-prompt](docs/agent/agent-prompt.md) | `pnpm exec tbox-app schema config/agent.jsonc` |
|
|
40
40
|
| 改欢迎区、快捷问题 | [shell](docs/agent/shell.md) | `pnpm exec tbox-app schema config/chat.json` |
|
|
41
|
-
| 写样式 / 换品牌色 | [style](docs/agent/style.md) |
|
|
41
|
+
| 写样式 / 换品牌色 | [style](docs/agent/style.md) | `pnpm exec tbox-app theme check`、`pnpm exec tbox-app theme tune --write`、`pnpm exec tbox-app theme derive --seed <hex>` |
|
|
42
42
|
| 验证 | [verify](docs/agent/verify.md) | `pnpm check:fast` |
|
|
43
43
|
<!-- agent-surface:routes end -->
|
|
44
44
|
|
|
@@ -21,12 +21,14 @@ import process from 'node:process';
|
|
|
21
21
|
import { createHash } from 'node:crypto';
|
|
22
22
|
import { createServer as createHttpServer } from 'node:http';
|
|
23
23
|
import { createRequire } from 'node:module';
|
|
24
|
+
import { tune as themeTune } from './theme-kernel.mjs';
|
|
24
25
|
import { buildSurfaceCss } from './surface-css.mjs';
|
|
25
26
|
import { checkCss } from '@tbox.cn/app-build/compat';
|
|
26
27
|
import { duplicateSampleLabels, sampleEntries } from './render-card.mjs';
|
|
27
28
|
import { collectCards, cardSourceHint, cardMetaSourceHint } from './lib/card-registry.mjs';
|
|
28
29
|
import { createStaticRenderer } from './lib/static-render.mjs';
|
|
29
30
|
import { evidenceInputFiles } from './lib/evidence-inputs.mjs';
|
|
31
|
+
import { toolEmittedCardTypes } from './lib/tool-cards-static.mjs';
|
|
30
32
|
import { STATIC_CHECKS, runStaticChecks } from './experience-checks.mjs';
|
|
31
33
|
import { IN_PROCESS_CHECKS, runInProcessChecks } from './in-process-checks.mjs';
|
|
32
34
|
import { PROBE_CHECKS, STORYBOARD_CHECKS, mergeProbeChecks, mergeStoryboardChecks } from './probe-checks.mjs';
|
|
@@ -96,12 +98,12 @@ try {
|
|
|
96
98
|
}
|
|
97
99
|
|
|
98
100
|
const registryClient = await vite.ssrLoadModule('/.tbox-gen/registry.client.ts').catch((error) => {
|
|
99
|
-
fail('registry', [{ id: 'registry-load-failed', message: `客户端 registry 加载失败:${error?.message ?? error}`, fix: '
|
|
101
|
+
fail('registry', [{ id: 'registry-load-failed', message: `客户端 registry 加载失败:${error?.message ?? error}`, fix: '先生成:pnpm generate。已生成仍失败 = 某个卡片的客户端模块在加载期抛错——按报错栈里的具体文件改代码(.tbox-gen 是派生物,改它无效)' }]);
|
|
100
102
|
return undefined;
|
|
101
103
|
});
|
|
102
104
|
|
|
103
105
|
const registryServer = await vite.ssrLoadModule('/@fs' + path.join(clientDir, '.tbox-gen/registry.server.ts')).catch((error) => {
|
|
104
|
-
fail('registry', [{ id: 'registry-load-failed', message: `服务端 registry 加载失败:${error?.message ?? error}`, fix: '
|
|
106
|
+
fail('registry', [{ id: 'registry-load-failed', message: `服务端 registry 加载失败:${error?.message ?? error}`, fix: '先生成:pnpm generate。已生成仍失败 = 某张卡片在样本派生/注册期抛错(Zod 报 path 就是 view() 返回结构越界)——按报错栈里的具体卡片文件改代码(.tbox-gen 是派生物,改它无效)' }]);
|
|
105
107
|
return undefined;
|
|
106
108
|
});
|
|
107
109
|
|
|
@@ -403,12 +405,22 @@ const TAILWIND_BANNED = [
|
|
|
403
405
|
},
|
|
404
406
|
{
|
|
405
407
|
id: 'font-size-off-scale',
|
|
406
|
-
|
|
407
|
-
|
|
408
|
+
// Tailwind v4 消歧前缀 text-[length:Npx] 同样是越档固定字号(2026-11:官方首页资产曾借此逃逸);
|
|
409
|
+
// rem 是上游 2x 缩放体系的残留,宿主 16px 根下尺寸失真,一并拦截。
|
|
410
|
+
pattern: /\btext-\[(?:length:)?\d+(?:\.\d+)?(?:px|rem)\]/,
|
|
411
|
+
message: '字号越档(档位 12/14/16/18/20/24/30/36;4xl=36 仅特殊场景)',
|
|
408
412
|
fix: '用 text-xs/sm/base/lg/xl/2xl/3xl;确需精确值改 line-height 或行内样式',
|
|
409
413
|
// 例外:活动卡的 badge / meta 标注档(11px)。只放行这一类钩子,不得扩散。
|
|
410
414
|
skipLine: (line) => /text-\[11px\]/.test(line) && /ap-badge|__meta|__badge|__hint/.test(line),
|
|
411
415
|
},
|
|
416
|
+
{
|
|
417
|
+
// style.md 承诺过的规则在此实装(2026-11 前「文档有、代码无」):
|
|
418
|
+
// 语义色加透明度修饰符 → Tailwind v4 生成无回退 color-mix,Chrome 105 / 支付宝壳下退化为不透明。
|
|
419
|
+
id: 'color-opacity-modifier',
|
|
420
|
+
pattern: /\b(?:bg|text|border|ring|outline|from|to|via|fill|stroke|divide|placeholder|decoration)-[a-z][a-z0-9-]*\/\d{1,3}\b/,
|
|
421
|
+
message: '语义色加了透明度修饰符(生成无回退 color-mix,兼容基线 Chrome 105 / 小程序壳退化)',
|
|
422
|
+
fix: '用不透明语义色(bg-card / bg-muted / bg-primary-soft…);要半透明写带 alpha 的任意值:bg-[rgba(11,15,23,0.02)]',
|
|
423
|
+
},
|
|
412
424
|
{
|
|
413
425
|
id: 'class-before-interpolation',
|
|
414
426
|
// 类名紧贴 `${` 时扫描器拿不到完整候选(实测 `gap-1.5${…}` 整条不生成 CSS)
|
|
@@ -1151,40 +1163,73 @@ function checkContrast() {
|
|
|
1151
1163
|
const ratio = contrastRatio(fg, bg);
|
|
1152
1164
|
if (ratio < pair.min) failures.push(pair.fg + ' on ' + pair.bg + ' = ' + ratio.toFixed(2) + ' < ' + pair.min);
|
|
1153
1165
|
}
|
|
1154
|
-
if (failures.length > 0)
|
|
1166
|
+
if (failures.length > 0) {
|
|
1167
|
+
// 可行动诊断(2026-11):调校内核就在隔壁(theme-kernel.tune),失败时直接算最小改动色值。
|
|
1168
|
+
// 真实构建里这一步之前全靠模型现写 Python 算 WCAG 亮度(3/3 case 撞墙各花 2–3 步)。
|
|
1169
|
+
let suggestion = '';
|
|
1170
|
+
try {
|
|
1171
|
+
const tuned = themeTune(tokens, pairs);
|
|
1172
|
+
const changes = (tuned.changes ?? []).map((change) => change.token + ' → ' + change.to);
|
|
1173
|
+
if (changes.length > 0) suggestion = ';最小改动建议:' + changes.join('、') + '(一键写入:pnpm exec tbox-app theme tune --write)';
|
|
1174
|
+
} catch { /* 内核不可用退回纯报错 */ }
|
|
1175
|
+
return { status: 'fail', detail: failures.join(';') + suggestion };
|
|
1176
|
+
}
|
|
1155
1177
|
if (deferred.length > 0) return { status: 'deferred', detail: '无法静态解析:' + deferred.join(';') };
|
|
1156
1178
|
return { status: 'pass', detail: pairs.length + ' 对全部达到阈值' };
|
|
1157
1179
|
}
|
|
1158
1180
|
|
|
1159
1181
|
// 视图卡的静态密度:版式归平台后高度是视图树的函数,不用开浏览器。
|
|
1182
|
+
// 2026-11 诊断升级:offenders 按高度降序携带「卡名 + 样例名 + 逐积木 px 分解」——
|
|
1183
|
+
// 原 warn 只报总高不报卡名,真实构建里模型盲猜两张无关卡改了 14 步(126s)才定位元凶。
|
|
1160
1184
|
async function checkCardDensity() {
|
|
1161
|
-
if (!registryServer) return { available: false, worst: 0, violations: [], reason: '没有服务端 registry' };
|
|
1185
|
+
if (!registryServer) return { available: false, worst: 0, violations: [], offenders: [], reason: '没有服务端 registry' };
|
|
1162
1186
|
let contracts;
|
|
1163
|
-
try { contracts = await vite.ssrLoadModule('@tbox.cn/app-contracts'); } catch { return { available: false, worst: 0, violations: [], reason: '契约模块加载失败' }; }
|
|
1187
|
+
try { contracts = await vite.ssrLoadModule('@tbox.cn/app-contracts'); } catch { return { available: false, worst: 0, violations: [], offenders: [], reason: '契约模块加载失败' }; }
|
|
1164
1188
|
const estimate = contracts.estimateCardHeight;
|
|
1165
|
-
|
|
1189
|
+
const explain = typeof contracts.explainCardHeight === 'function' ? contracts.explainCardHeight : undefined;
|
|
1190
|
+
if (typeof estimate !== 'function') return { available: false, worst: 0, violations: [], offenders: [], reason: '契约未导出 estimateCardHeight' };
|
|
1166
1191
|
let worst = 0;
|
|
1167
1192
|
const violations = [];
|
|
1193
|
+
const offenders = [];
|
|
1168
1194
|
const sheetCards = [];
|
|
1195
|
+
// 2026-11 落点精准化:sheet 豁免只对「可进抽屉」的卡成立——工具直出(import ../cards/<x>.card
|
|
1196
|
+
// 于 *.tool.ts)的 sheet 卡恒渲染在消息流内(真实构建 4/4 滥用 sheet 洗掉高度门禁),
|
|
1197
|
+
// 它们回到流内计高:>633px 时 card.height 照常阻断执行;cross-ref 同步点名落点失配。
|
|
1198
|
+
const toolEmitted = new Set([...toolEmittedCardTypes(appDir).values()].flat());
|
|
1199
|
+
const sheetToolEmitted = [];
|
|
1169
1200
|
for (const [cardType, meta] of Object.entries(mergedMetas)) {
|
|
1170
1201
|
if (!meta || !meta.view) continue;
|
|
1171
1202
|
// 明细卡(meta.defaultPlacement === 'sheet')由半屏抽屉承接,自带滚动容器:
|
|
1172
|
-
//
|
|
1173
|
-
|
|
1203
|
+
// 不参与「流内一屏」判定。例外(2026-11):被工具直出的 sheet 卡渲染在消息流
|
|
1204
|
+
// 里、进不了抽屉——不豁免,回到流内计高并单列在 sheetToolEmitted。
|
|
1205
|
+
if (meta.defaultPlacement === 'sheet' && !toolEmitted.has(cardType)) {
|
|
1174
1206
|
sheetCards.push(cardType);
|
|
1175
1207
|
continue;
|
|
1176
1208
|
}
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1209
|
+
if (meta.defaultPlacement === 'sheet' && toolEmitted.has(cardType)) {
|
|
1210
|
+
sheetToolEmitted.push(cardType);
|
|
1211
|
+
}
|
|
1212
|
+
const samples = [
|
|
1213
|
+
{ label: '基准', data: meta.sampleData },
|
|
1214
|
+
...(Array.isArray(meta.samples) ? meta.samples.map((sample) => ({ label: typeof sample?.label === 'string' && sample.label ? sample.label : '(未命名样例)', data: sample?.data })) : []),
|
|
1215
|
+
];
|
|
1216
|
+
for (const sample of samples) {
|
|
1217
|
+
if (!sample.data) continue;
|
|
1180
1218
|
try {
|
|
1181
|
-
const height = estimate(data);
|
|
1219
|
+
const height = estimate(sample.data);
|
|
1182
1220
|
if (height > worst) worst = height;
|
|
1183
1221
|
if (height > 633) violations.push(cardType + ' ' + height + 'px');
|
|
1222
|
+
if (height > 506) {
|
|
1223
|
+
const partsText = explain
|
|
1224
|
+
? explain(sample.data).parts.map((part) => part.kind + ' ' + Math.round(part.px)).join(' + ')
|
|
1225
|
+
: '';
|
|
1226
|
+
offenders.push({ cardType, sample: sample.label, height, parts: partsText });
|
|
1227
|
+
}
|
|
1184
1228
|
} catch { /* 形状不对由 render 报 */ }
|
|
1185
1229
|
}
|
|
1186
1230
|
}
|
|
1187
|
-
|
|
1231
|
+
offenders.sort((a, b) => b.height - a.height);
|
|
1232
|
+
return { available: true, worst, violations, offenders, sheetCards, sheetToolEmitted };
|
|
1188
1233
|
}
|
|
1189
1234
|
|
|
1190
1235
|
// ── 4.8 体验不变量(登记在 checks.json 的 experience 族)──────────────
|
|
@@ -1269,6 +1314,7 @@ async function checkExperience(cssBytes) {
|
|
|
1269
1314
|
// 进程内车道走执行器:上下文中转,新增检查只需 checks.json + in-process-checks.mjs。
|
|
1270
1315
|
const inProcessIds = Object.keys(IN_PROCESS_CHECKS).filter((id) => checkMeta.get(id)?.phase === 'in-process');
|
|
1271
1316
|
const inProcessContext = {
|
|
1317
|
+
appDir,
|
|
1272
1318
|
cssBytes,
|
|
1273
1319
|
registryServer: { ...registryServer, cards: mergedMetas },
|
|
1274
1320
|
registryClient: { ...registryClient, cards: mergedComponents },
|
|
@@ -131,11 +131,23 @@ export const STATIC_CHECKS = {
|
|
|
131
131
|
'quick.label-query': ({ appDir }) => {
|
|
132
132
|
try {
|
|
133
133
|
const chat = JSON.parse(readFileSync(path.join(appDir, 'config/chat.json'), 'utf8'));
|
|
134
|
-
|
|
135
|
-
|
|
134
|
+
// 2026-11 v2:原「query 必须包含 label 子串」机械规则把正常的「短按钮 → 自然完整问句」
|
|
135
|
+
// 全部误伤(真实构建两例全数误报,模型只能读门禁源码反推规则)。改为只拦确定性缺陷:
|
|
136
|
+
// 空白文案、透传内部实现标识符、超长按钮文案(两列网格必然折行不可读)。
|
|
137
|
+
const problems = [];
|
|
138
|
+
(Array.isArray(chat.quickCommands) ? chat.quickCommands : []).forEach((command, index) => {
|
|
139
|
+
if (!command || typeof command !== 'object') return;
|
|
140
|
+
const label = String(command.label ?? '');
|
|
141
|
+
const query = String(command.query ?? '');
|
|
142
|
+
const where = '第' + (index + 1) + '条';
|
|
143
|
+
if (!label.trim() || !query.trim()) problems.push(where + ' label/query 为空白');
|
|
144
|
+
if (/^(?:tool|action|cmd|config):/i.test(query) || /\btool_[a-z0-9_]+/i.test(query)) problems.push(where + ' 透传内部实现标识符:' + query.slice(0, 20));
|
|
145
|
+
if (label.length > 16) problems.push(where + ' 按钮文案 ' + label.length + ' 字(>16 两列网格必折行)');
|
|
146
|
+
});
|
|
147
|
+
const count = Array.isArray(chat.quickCommands) ? chat.quickCommands.length : 0;
|
|
136
148
|
return {
|
|
137
|
-
status:
|
|
138
|
-
detail:
|
|
149
|
+
status: problems.length > 0 ? 'fail' : 'pass',
|
|
150
|
+
detail: problems.length > 0 ? problems.slice(0, 5).join(';') : count + ' 条快捷问题文案可用(短按钮映射自然问句合法)',
|
|
139
151
|
};
|
|
140
152
|
} catch {
|
|
141
153
|
return { status: 'deferred', detail: '读不到 config/chat.json' };
|
|
@@ -185,7 +197,7 @@ export const STATIC_CHECKS = {
|
|
|
185
197
|
const full = path.join(dir, entry.name);
|
|
186
198
|
if (entry.isDirectory()) walk(full);
|
|
187
199
|
else if (/\.(tsx?|css)$/.test(entry.name) && !entry.name.endsWith('.test.tsx')) {
|
|
188
|
-
if (/text-\[
|
|
200
|
+
if (/text-\[(?:length:)?\d+(?:\.\d+)?(?:px|rem)\]/.test(readFileSync(full, 'utf8'))) offScale.push(path.relative(appDir, full));
|
|
189
201
|
}
|
|
190
202
|
}
|
|
191
203
|
};
|
|
@@ -196,6 +208,39 @@ export const STATIC_CHECKS = {
|
|
|
196
208
|
};
|
|
197
209
|
},
|
|
198
210
|
|
|
211
|
+
/**
|
|
212
|
+
* 版式合同(2026-11):brand.css 只准写品牌色/素材令牌,不得覆写版式合同变量
|
|
213
|
+
* (--tbox-fs-* / --tbox-radius-* / --tbox-shadow-*,真实构建曾整组覆写致基元错位)
|
|
214
|
+
* 与壳欢迎区几何;index.html 外链 Google Fonts(国内/离线/小程序壳首屏阻塞)告警。
|
|
215
|
+
*/
|
|
216
|
+
'style.brand-contract': ({ appDir, clientDir }) => {
|
|
217
|
+
const base = clientDir ?? path.join(appDir, 'apps/client');
|
|
218
|
+
const problems = [];
|
|
219
|
+
try {
|
|
220
|
+
const brandPath = path.join(base, 'src/styles/brand.css');
|
|
221
|
+
if (existsSync(brandPath)) {
|
|
222
|
+
// 注释先抹白再扫(.css 模式保留行号):出厂 brand.css 的「注释示例」不是实际覆写,
|
|
223
|
+
// 首轮实现把注释示例当命中、模板自身 check:fast 全量误报。
|
|
224
|
+
const brand = blankComments(readFileSync(brandPath, 'utf8'), '.css');
|
|
225
|
+
for (const match of brand.matchAll(/(--tbox-(?:fs|radius|shadow)-[a-z0-9-]*)\s*:/g)) {
|
|
226
|
+
problems.push('brand.css 覆写版式合同变量 ' + match[1] + '(基元按它对齐,改了必错位)');
|
|
227
|
+
}
|
|
228
|
+
for (const block of brand.matchAll(/\.chat-page__welcome[^{}]*\{([^}]*)\}/g)) {
|
|
229
|
+
if (/padding[^;}]*:/i.test(block[1])) problems.push('brand.css 覆写欢迎区 padding(垂直内距归壳:py-5 已保底)');
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
const htmlPath = path.join(base, 'index.html');
|
|
233
|
+
if (existsSync(htmlPath) && /fonts\.(?:googleapis|gstatic)\.com/.test(readFileSync(htmlPath, 'utf8'))) {
|
|
234
|
+
problems.push('index.html 外链 Google Fonts(国内/离线/小程序壳会阻塞首屏;改系统字体栈或本地字体)');
|
|
235
|
+
}
|
|
236
|
+
return problems.length === 0
|
|
237
|
+
? { status: 'pass', detail: '品牌层未触碰版式合同' }
|
|
238
|
+
: { status: 'fail', detail: problems.slice(0, 5).join(';') };
|
|
239
|
+
} catch (error) {
|
|
240
|
+
return { status: 'deferred', detail: '版式合同不可检查:' + (error?.message ?? error) };
|
|
241
|
+
}
|
|
242
|
+
},
|
|
243
|
+
|
|
199
244
|
'shell.no-custom-chrome': ({ appDir, clientDir }) => {
|
|
200
245
|
const base = clientDir ?? path.join(appDir, 'apps/client');
|
|
201
246
|
const offenders = findCustomChrome(base);
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* 上下文由门禁提供(CSS 字节数、registry、渲染计数、对比度/密度函数),执行器只按 id 分发。
|
|
5
5
|
* 新增检查 = checks.json 一行 + IN_PROCESS_CHECKS 一段。
|
|
6
6
|
*/
|
|
7
|
+
import { scanContractCrossReferences } from './lib/tool-cards-static.mjs';
|
|
7
8
|
export const IN_PROCESS_CHECKS = {
|
|
8
9
|
'shell.contrast': (ctx) => ctx.checkContrast(),
|
|
9
10
|
|
|
@@ -54,6 +55,38 @@ export const IN_PROCESS_CHECKS = {
|
|
|
54
55
|
: { status: 'fail', detail: problems.slice(0, 4).join(';') };
|
|
55
56
|
},
|
|
56
57
|
|
|
58
|
+
/**
|
|
59
|
+
* 跨文件契约一致性(2026-11):三类「运行时静默失败」的静态可判定缺陷——
|
|
60
|
+
* 工具 import ../cards/<x>.card 却漏 defineTool({ cards: [...] })声明、
|
|
61
|
+
* invalidateCardTypes 引用未注册卡名(旧卡永不失效)、工具直出的卡声明
|
|
62
|
+
* defaultPlacement: 'sheet'(流内渲染进不了抽屉却洗掉高度门禁)。
|
|
63
|
+
*/
|
|
64
|
+
'contract.cross-ref': (ctx) => {
|
|
65
|
+
if (!ctx.appDir) return { status: 'deferred', detail: '没有应用根(跳过交叉扫描)' };
|
|
66
|
+
const registered = new Set(Object.keys(ctx.registryServer?.cards ?? {}));
|
|
67
|
+
// 无卡应用(纯对话模板)不跑交叉
|
|
68
|
+
if (registered.size === 0) return { status: 'deferred', detail: '没有卡片(无交叉面)' };
|
|
69
|
+
let scan;
|
|
70
|
+
try {
|
|
71
|
+
scan = scanContractCrossReferences({ appDir: ctx.appDir, registeredCardTypes: [...registered], metas: (ctx.registryServer?.cards ?? {}) });
|
|
72
|
+
} catch (error) {
|
|
73
|
+
return { status: 'deferred', detail: '交叉扫描不可用:' + (error?.message ?? error) };
|
|
74
|
+
}
|
|
75
|
+
const problems = [];
|
|
76
|
+
for (const item of scan.missingToolCardsDeclarations) {
|
|
77
|
+
problems.push(`${item.file} 发布了出卡工具却未在 defineTool options 声明 cards: [${item.types.join('、')}]——withCardEmissionHint 不生效,模型不知道这些卡候选存在`);
|
|
78
|
+
}
|
|
79
|
+
for (const ref of scan.danglingInvalidateRefs) {
|
|
80
|
+
problems.push(`${ref.file} 的 invalidateCardTypes 引用未注册卡名「${ref.cardType}」——检查拼写(已注册卡:${[...registered].slice(0, 5).join('、')}${registered.size > 5 ? '…' : ''})`);
|
|
81
|
+
}
|
|
82
|
+
for (const cardType of scan.toolEmittedSheetCards ?? []) {
|
|
83
|
+
problems.push(`卡片「${cardType}」声明 defaultPlacement: 'sheet' 但被工具直出(*.tool.ts import)——工具直出卡渲染在消息流内、进不了抽屉,请去掉 sheet 声明或改为 action 弹出`);
|
|
84
|
+
}
|
|
85
|
+
return problems.length === 0
|
|
86
|
+
? { status: 'pass', detail: '工具出卡声明 / invalidate 引用 / sheet 落点无静态缺陷' }
|
|
87
|
+
: { status: 'fail', detail: problems.slice(0, 4).join(';') };
|
|
88
|
+
},
|
|
89
|
+
|
|
57
90
|
'card.height': async (ctx) => {
|
|
58
91
|
const cardCount = Object.keys(ctx.registryServer?.cards ?? {}).length;
|
|
59
92
|
if (cardCount === 0) return { status: 'deferred', detail: '没有卡片' };
|
|
@@ -61,15 +94,32 @@ export const IN_PROCESS_CHECKS = {
|
|
|
61
94
|
if (!density.available) return { status: 'deferred', detail: '视图卡密度未检查:' + density.reason };
|
|
62
95
|
const viewCards = Object.values(ctx.registryServer?.cards ?? {}).filter((meta) => meta && meta.view).length;
|
|
63
96
|
if (viewCards === 0) return { status: 'pass', detail: '没有视图卡(三件套不估算)' };
|
|
97
|
+
// 可行动诊断(2026-11):offenders = 超线卡清单(卡名 + 样例名 + 逐积木 px 分解)。
|
|
98
|
+
// 原输出只有总高,真实构建里模型盲猜两张无关卡改 14 步才定位超线元凶。
|
|
99
|
+
const offenders = Array.isArray(density.offenders) ? density.offenders : [];
|
|
100
|
+
const offendersText = offenders
|
|
101
|
+
.slice(0, 5)
|
|
102
|
+
.map((entry) => entry.cardType + '[' + entry.sample + '] ' + entry.height + 'px' + (entry.parts ? '(' + entry.parts + ')' : ''))
|
|
103
|
+
.join('、');
|
|
64
104
|
if (density.worst > 506 && density.worst <= 633) {
|
|
65
|
-
ctx.warn('card-height-warn',
|
|
105
|
+
ctx.warn('card-height-warn',
|
|
106
|
+
'视图卡最高 ' + density.worst + 'px(超过一屏 60% 的 506px)' + (offendersText ? ';超线卡:' + offendersText : ''),
|
|
107
|
+
{ fix: '按分解减对应积木或拆卡;>633px 会阻断', recipe: 'card' });
|
|
66
108
|
}
|
|
109
|
+
const sheetToolEmitted = Array.isArray(density.sheetToolEmitted) ? density.sheetToolEmitted : [];
|
|
67
110
|
const sheetNote = (density.sheetCards ?? []).length > 0
|
|
68
111
|
? ';抽屉卡豁免:' + density.sheetCards.join('、')
|
|
69
112
|
: '';
|
|
113
|
+
const sheetMismatchNote = sheetToolEmitted.length > 0
|
|
114
|
+
? ';工具直出的 sheet 卡已回流内计高:' + sheetToolEmitted.join('、') + '(去 sheet 声明或改动作弹层)'
|
|
115
|
+
: '';
|
|
70
116
|
return {
|
|
71
117
|
status: density.violations.length > 0 ? 'fail' : 'pass',
|
|
72
|
-
detail: '最高 ' + density.worst + 'px'
|
|
118
|
+
detail: '最高 ' + density.worst + 'px'
|
|
119
|
+
+ (offendersText ? ';超线卡:' + offendersText : '')
|
|
120
|
+
+ (density.violations.length > 0 ? ';>633px 阻断:' + density.violations.join('、') : '')
|
|
121
|
+
+ sheetNote
|
|
122
|
+
+ sheetMismatchNote,
|
|
73
123
|
};
|
|
74
124
|
},
|
|
75
125
|
};
|
|
Binary file
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 服务端源码的静态交叉事实(2026-11,卡片落点与契约一致性门禁的单源):
|
|
3
|
+
*
|
|
4
|
+
* 真实构建调查发现三类「静态可判定、运行时静默失败」的缺陷反复出现:
|
|
5
|
+
* 1. 工具源文件 import 了 ../cards/<x>.card 却未在 defineTool({ cards: [...] }) 声明
|
|
6
|
+
* —— withCardEmissionHint 失效(模型不知道该工具能出卡,候选池描述不完整);
|
|
7
|
+
* 2. action 的 invalidateCardTypes 引用不存在的卡名(拼写漂移)——旧卡永不失效;
|
|
8
|
+
* 3. 卡声明 defaultPlacement: 'sheet' 但只被工具直出(进不了抽屉)却被高度门禁豁免。
|
|
9
|
+
*
|
|
10
|
+
* 全部走纯文本扫描(fs + 正则),无 AST 依赖;扫描的 breakdown 面向「给模型可行动的报错」。
|
|
11
|
+
*/
|
|
12
|
+
import { existsSync, readFileSync, readdirSync } from 'node:fs';
|
|
13
|
+
import path from 'node:path';
|
|
14
|
+
|
|
15
|
+
/** 递归收集目录下的 .ts 源文件。
|
|
16
|
+
* 注意:**不过滤** node_modules/dist——目录语义由调用方保证(扫的是 apps/server/src/tools|actions 的直接源码目录)。 */
|
|
17
|
+
export function listServerSources(appDir, kind) {
|
|
18
|
+
const dir = path.join(appDir, 'apps/server/src', kind);
|
|
19
|
+
if (!existsSync(dir)) return [];
|
|
20
|
+
const out = [];
|
|
21
|
+
const walk = (current) => {
|
|
22
|
+
for (const entry of readdirSync(current, { withFileTypes: true })) {
|
|
23
|
+
const full = path.join(current, entry.name);
|
|
24
|
+
if (entry.isDirectory()) walk(full);
|
|
25
|
+
else if (entry.name.endsWith('.ts')) out.push(full);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
walk(dir);
|
|
29
|
+
return out;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** 工具源文件里 import 的卡片名:from '../cards/<cardType>.card'(import 路径即 cardType 判定单源)。 */
|
|
33
|
+
export function toolEmittedCardTypes(appDir) {
|
|
34
|
+
const map = new Map(); // file → cardType[]
|
|
35
|
+
for (const file of listServerSources(appDir, 'tools')) {
|
|
36
|
+
const text = readFileSync(file, 'utf8');
|
|
37
|
+
const types = new Set();
|
|
38
|
+
for (const match of text.matchAll(/from\s+['"][^'"]*\/cards\/([a-z0-9-]+)\.card['"]/g)) types.add(match[1]);
|
|
39
|
+
// 判定面=import 路径(cardOf/cardOfView 调用不做文本扫描——注释不承诺没实现的近似)。
|
|
40
|
+
if (types.size > 0) map.set(path.relative(appDir, file), [...types]);
|
|
41
|
+
}
|
|
42
|
+
return map;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** action 源文件里的 invalidateCardTypes 字面量清单(不解析 AST:数组字符串元素)。 */
|
|
46
|
+
export function invalidateReferences(appDir) {
|
|
47
|
+
const out = [];
|
|
48
|
+
for (const file of listServerSources(appDir, 'actions')) {
|
|
49
|
+
const text = readFileSync(file, 'utf8');
|
|
50
|
+
for (const block of text.matchAll(/invalidateCardTypes\s*:\s*\[([^\]]*)\]/g)) {
|
|
51
|
+
for (const item of block[1].matchAll(/['"]([a-z0-9-]+)['"]/g)) {
|
|
52
|
+
out.push({ file: path.relative(appDir, file), cardType: item[1] });
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return out;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* 交叉一致性扫描(contract.cross-ref 单源):
|
|
62
|
+
* - 未声明的出卡工具(import ../cards 但 defineTool 无 cards:)→ missingToolCardsDeclarations
|
|
63
|
+
* - invalidateCardTypes 引用未注册卡名 → danglingInvalidateRefs
|
|
64
|
+
* - 工具直出却声明 sheet 的卡 → toolEmittedSheetCards
|
|
65
|
+
*/
|
|
66
|
+
export function scanContractCrossReferences({ appDir, registeredCardTypes, metas }) {
|
|
67
|
+
const registered = new Set(registeredCardTypes ?? []);
|
|
68
|
+
const result = {
|
|
69
|
+
missingToolCardsDeclarations: [],
|
|
70
|
+
danglingInvalidateRefs: [],
|
|
71
|
+
toolEmittedSheetCards: [],
|
|
72
|
+
emittedCardTypes: new Set(),
|
|
73
|
+
};
|
|
74
|
+
for (const [file, types] of toolEmittedCardTypes(appDir)) {
|
|
75
|
+
const text = readFileSync(path.join(appDir, file), 'utf8');
|
|
76
|
+
const hasCardsOption = /defineTool\s*\(\s*\{[\s\S]*?\bcards\s*:/.test(text);
|
|
77
|
+
if (!hasCardsOption) result.missingToolCardsDeclarations.push({ file, types });
|
|
78
|
+
for (const cardType of types) result.emittedCardTypes.add(cardType);
|
|
79
|
+
}
|
|
80
|
+
for (const ref of invalidateReferences(appDir)) {
|
|
81
|
+
if (registered.size > 0 && !registered.has(ref.cardType)) result.danglingInvalidateRefs.push(ref);
|
|
82
|
+
}
|
|
83
|
+
// 工具直出却声明 sheet 的卡:metas(cardType → meta)在场才判(density 门禁同步细化)。
|
|
84
|
+
if (metas) {
|
|
85
|
+
for (const cardType of result.emittedCardTypes) {
|
|
86
|
+
if (metas[cardType]?.defaultPlacement === 'sheet') result.toolEmittedSheetCards.push(cardType);
|
|
87
|
+
}
|
|
88
|
+
result.toolEmittedSheetCards.sort();
|
|
89
|
+
}
|
|
90
|
+
return result;
|
|
91
|
+
}
|
|
@@ -12,6 +12,7 @@ export const PROBE_CHECKS = {
|
|
|
12
12
|
'shell.control-present': { lane: 'layout', title: '能力开启时控件在场' },
|
|
13
13
|
'shell.a11y-name': { lane: 'layout', title: '控件有可访问名' },
|
|
14
14
|
'shell.blank': { lane: 'layout', title: '首页块间空白 ≤35%(聊天流不适用)' },
|
|
15
|
+
'shell.home-geometry': { lane: 'layout', title: '实体表面/welcome/home 块屏边距 ≥12px、首屏字号 ≤32px、图标 ≤44px' },
|
|
15
16
|
'shell.no-fixed-chrome': { lane: 'layout', title: '滚动区之上无常驻元素' },
|
|
16
17
|
'shell.input-rows': { lane: 'layout', title: '空输入框单行且命中区达标' },
|
|
17
18
|
'shell.follow-latest': { lane: 'runtime', title: '内容增长跟到底、上滑停止跟随' },
|
package/docs/agent/card.md
CHANGED
|
@@ -149,7 +149,7 @@ pnpm card:render --type <cardType> --screenshot --baseline
|
|
|
149
149
|
|
|
150
150
|
首次运行把截图写到 `.tbox/card-render/baseline/<type>.png`;之后逐像素比对(需 Pillow),差异 >0.5% 失败;没有 Pillow 时退回字节比对。改样式后用 `--baseline` 重跑,确认差异符合预期再删除对应基线、重新生成。
|
|
151
151
|
|
|
152
|
-
`--audit` 同时列出字号分布:每张卡的文字必须落在 12 / 14 / 16 / 18 / 20
|
|
152
|
+
`--audit` 同时列出字号分布:每张卡的文字必须落在 12 / 14 / 16 / 18 / 20 / 24 / 30 / 36 八档,越档会单独列一行。
|
|
153
153
|
|
|
154
154
|
## 要点
|
|
155
155
|
|
package/docs/agent/errors.md
CHANGED
|
@@ -44,14 +44,17 @@
|
|
|
44
44
|
| `shell.quick-visible`(错误) | 空态快捷问题没有全部可见(横向溢出或贴底) | 无 home 槽的纯对话欢迎态用两列 grid,有 home 槽的首页与对话态共用输入框上方单行([shell](shell.md)) |
|
|
45
45
|
| `flow.persist`(建议) | 状态没有跨进程重启验证 | 用 createUserState({ persist: "file" }) 并加重启探针([state](state.md)) |
|
|
46
46
|
| `shell.contrast`(错误) | 令牌对比度低于阈值(文字看不清) | 调 brand.css 的令牌值;color-mix 派生的由浏览器车道补验([style](style.md)) |
|
|
47
|
+
| `shell.home-geometry`(建议) | 欢迎卡 / home 自动块 0px 贴屏、或首屏字号/图标比例失控(2x 稿残留) | 实体 surface 用 mx-page(壳表面);首页槽注册传 { gutter: 'inset' };字号回八档 token、图标用 size-* 标度([shell](shell.md)) |
|
|
47
48
|
| `shell.blank`(建议) | 首页内容块之间空白过大(看起来没做完) | 空态成组居中、补服务入口;只算块间空白,不算首尾对称留白;聊天流首屏记 not-run([shell](shell.md)) |
|
|
49
|
+
| `contract.cross-ref`(建议) | 工具 import ../cards/<x>.card 却未在 defineTool 声明 cards;invalidateCardTypes 引用未注册卡名;工具直出卡声明 sheet 落点失配 | 在 defineTool options 补 cards: [<cardType>](否则 withCardEmissionHint 不生效);纠正 invalidateCardTypes 里的拼写;工具直出卡去掉 defaultPlacement: sheet 或改为动作弹层([tool-emits-card](tool-emits-card.md)) |
|
|
48
50
|
| `card.height`(建议) | 视图卡过高(一屏放不下) | 按预算减积木或拆卡;详情用单独的卡承接([card](card.md)) |
|
|
49
51
|
| `CARD_TYPE_INVALID`(错误) | 卡片类型含路径分隔符或非法字符 | 改成小写 kebab(字母/数字/点/下划线/中划线),不要用 ../ 或斜杠([card](card.md)) |
|
|
50
52
|
| `shell.icon-render`(错误) | 快捷问题图标不可见(遮罩失效或节点被隐藏) | 修正 maskImage 引号或改用可见元素;应用自绘图标时保证按钮内有可见内容([shell](shell.md)) |
|
|
51
53
|
| `shell.controls-semantic`(错误) | 核心控件不是 button/a(键盘与读屏不可用) | 用 button + aria-label + focus-visible;保留原类名([shell](shell.md)) |
|
|
52
54
|
| `shell.control-present`(错误) | 能力开启但对应控件不可见 | 按能力配置渲染控件;关闭能力时才隐藏([shell](shell.md)) |
|
|
53
55
|
| `shell.a11y-name`(错误) | 控件缺可访问名 | aria-label 或可见文本([shell](shell.md)) |
|
|
54
|
-
| `quick.label-query`(建议) |
|
|
56
|
+
| `quick.label-query`(建议) | 快捷问题文案为空白、透传内部实现标识符、或按钮文案超长折行 | 补全 label/query;query 用自然问句(短按钮 → 完整问题合法);按钮文案压到 16 字内([shell](shell.md)) |
|
|
57
|
+
| `style.brand-contract`(建议) | brand.css 覆写 --tbox-fs-*/--tbox-radius-*/--tbox-shadow-* 或欢迎区 padding;index.html 外链 Google Fonts | 品牌只改颜色/素材令牌(版式变量是基元合同);移除外链字体改系统字体栈或本地字体([style](style.md)) |
|
|
55
58
|
| `checks.registry`(错误) | checks.json 登记了门禁未实现的检查项 | 补实现或删登记;sync-check-docs 会同步报错表([verify](verify.md)) |
|
|
56
59
|
| `shell.console-clean`(错误) | 水合时控制台出现告警/错误(重复注册、未知属性、SSR 警告) | 按告警修源头;不要静音 console([shell](shell.md)) |
|
|
57
60
|
| `storyboard.render`(错误) | 故事板渲染失败(帧没跑完) | 看 storyboard.json 的 reason;多为样例数据不合 schema 或 Chrome 未就绪([verify](verify.md)) |
|
package/docs/agent/kit.md
CHANGED
|
@@ -29,7 +29,7 @@ import { Card, CardHeader, KeyValueList, StatusTag } from '@tbox.cn/app-agent-ui
|
|
|
29
29
|
| `Steps` | 步骤/路线:取车路线、办理进度。 | `steps: StepItem[]` |
|
|
30
30
|
| `MediaRow` | 图文条目:门店、商品、活动。 | `title: ReactNode` `meta?: ReactNode` `tags?: ReactNode` `action?: ReactNode` `thumb?: ReactNode` |
|
|
31
31
|
| `Hero` | 品牌色块:主数值 + 说明,用于会员、积分、钱包类卡片的头部。 | `eyebrow?: ReactNode` `title?: ReactNode` `value?: ReactNode` `unit?: ReactNode` `footnote?: ReactNode` `icon?: ReactNode` `tone?: 'primary' \| 'warm' \| 'jade' \| 'inverse' \| 'neutral'` |
|
|
32
|
-
| `StatGrid` |
|
|
32
|
+
| `StatGrid` | 并列数值格(两到四格):积分/余额、车位/时长、行程 KPI。 | `items: StatItem[]` |
|
|
33
33
|
| `EntityRow` | 实体行(MediaRow 的超集):商户、活动、券包条目,支持价格与展开说明。 | `title: ReactNode` `badge?: ReactNode` `status?: ReactNode` `meta?: ReactNode` `tags?: ReactNode` `price?: ReactNode` `action?: ReactNode` `actions?: ReactNode` `thumb?: ReactNode` `description?: ReactNode` |
|
|
34
34
|
| `CheckRow` | 勾选行:用券、同意条款、选择车位。 | `label: ReactNode` `description?: ReactNode` `checked: boolean` `onChange?: (checked: boolean) => void` `disabled?: boolean` `trailing?: ReactNode` |
|
|
35
35
|
| `Timeline` | 明细时间线:积分收支、停车计费。 * | `items: TimelineItem[]` |
|
|
@@ -79,11 +79,12 @@ ChatPage 渲染的区域如下;`可覆写` 为 true 的选择器可以在 `bra
|
|
|
79
79
|
|
|
80
80
|
| 区域 | 选择器 | 由什么驱动 | 可覆写 |
|
|
81
81
|
|---|---|---|---|
|
|
82
|
-
| `welcome` | `.chat-page__welcome` | chat.json welcome.title;chat.json welcome.subtitle | 是 |
|
|
82
|
+
| `welcome` | `.chat-page__welcome` | chat.json welcome.title;chat.json welcome.subtitle;chat.json welcome.badge | 是 |
|
|
83
83
|
| `messages` | `.chat-page__body` | chat store messages / historyMessages,历史分页保留当前阅读位置 | 否 |
|
|
84
84
|
| `history-entry` | `.history-entry` | chat store historyHasMore / isLoadingHistory | 否 |
|
|
85
|
-
| `home-slot` | `.chat-page__home-slot` | 客户端槽 home | 否 |
|
|
85
|
+
| `home-slot` | `.chat-page__home-slot` | 客户端槽 home;HomeSlotMeta(register 第三参数:lifecycle home-only\|persistent / gutter inset\|bleed / hideBottomQuickCommands) | 否 |
|
|
86
86
|
| `conversation-overlay` | `.chat-page__conversation-overlay` | 客户端槽 conversationOverlay | 否 |
|
|
87
|
+
| `starter-questions` | `.chat-page__starter-questions` | chat.json starterQuestions.title;chat.json starterQuestions.pageSize;chat.json starterQuestions.items[].label/query | 是 |
|
|
87
88
|
| `quick-commands` | `.quick-commands` | HELLO_ACK chatConfig.quickCommands(缺省回落 chat.json);chat.json quickCommands[].icon(图片或 icon:calendar) | 是 |
|
|
88
89
|
| `input` | `.tbox-chat-input` | chat.json(enableTTS / input.minRows / input.maxRows);chat store runtimeStatus / isGenerating | 否 |
|
|
89
90
|
|
package/docs/agent/shell.md
CHANGED
|
@@ -23,8 +23,9 @@ export default function Index() {
|
|
|
23
23
|
壳没有页头,也不渲染任何常驻标题区。智能体身份由两处配置承载:
|
|
24
24
|
|
|
25
25
|
- `welcome.title` / `welcome.subtitle`:空会话欢迎区的标题与副标题;
|
|
26
|
+
- `welcome.badge`:迎宾卡顶部的短身份角标(≤16 字,如「7×24 智能售后」);
|
|
26
27
|
- `welcome.surface`:欢迎区表面(`default` 缺省 / `brand` 品牌深色渐变 / `subtle` 弱化描边)。
|
|
27
|
-
`brand`
|
|
28
|
+
`brand` 只组合既有主题变量(primary-dark → primary 双停承载文字,accent 角部光晕),并自带 20% 深色罩保证小字对比度——换品牌色不用改它。实体表面按 16px 栅格对齐屏边(`shell.home-geometry` 探针会量);
|
|
28
29
|
- `page.title`:页面标题(浏览器标签页与分享卡片)。
|
|
29
30
|
|
|
30
31
|
欢迎区只在空会话且没有 `home` 槽时出现。
|
|
@@ -32,12 +33,40 @@ export default function Index() {
|
|
|
32
33
|
```jsonc
|
|
33
34
|
// config/chat.json 片段
|
|
34
35
|
{
|
|
35
|
-
"welcome": { "title": "今天想逛点什么?", "subtitle": "需要什么,直接问我就好" },
|
|
36
|
+
"welcome": { "title": "今天想逛点什么?", "subtitle": "需要什么,直接问我就好", "badge": "商场会员 8 折" },
|
|
36
37
|
"retryOnError": true,
|
|
37
38
|
"input": { "minRows": 1, "maxRows": 4 }
|
|
38
39
|
}
|
|
39
40
|
```
|
|
40
41
|
|
|
42
|
+
## L0 声明式首页:一个 JSON 出饱满首屏
|
|
43
|
+
|
|
44
|
+
多数到的智能体首屏只需要「迎宾卡 + 核心服务入口 + 猜你想问」三段——不要为这个写 `home` 槽与 TSX,
|
|
45
|
+
全部写进 `chat.json`,零代码、零布局 CSS(壳已按 16px 栅格对齐,`shell.home-geometry` 探针兜底):
|
|
46
|
+
|
|
47
|
+
```jsonc
|
|
48
|
+
// config/chat.json 片段:快捷项带 description = 空态升级成两列服务卡;
|
|
49
|
+
// 同一份配置在对话态自动收敛回输入框上方的单行胶囊——不重复维护两份清单。
|
|
50
|
+
"quickCommands": [
|
|
51
|
+
{ "label": "查订单", "query": "帮我查最近的订单物流", "icon": "icon:receipt", "description": "实时轨迹与签收状态" },
|
|
52
|
+
{ "label": "申请退换货", "query": "我想申请退换货", "icon": "icon:gift", "description": "签收后 7 天可退" },
|
|
53
|
+
{ "label": "商品咨询", "query": "咨询商品规格与库存", "icon": "icon:info", "description": "尺寸/材质/发货时效" }
|
|
54
|
+
],
|
|
55
|
+
// 超过 pageSize 自动出「换一换」;label ≤16 字、query 写自然完整问句(不必包含 label)。
|
|
56
|
+
"starterQuestions": {
|
|
57
|
+
"title": "猜你想问",
|
|
58
|
+
"pageSize": 3,
|
|
59
|
+
"items": [
|
|
60
|
+
{ "label": "订单到哪了?", "query": "我的订单到哪了?" },
|
|
61
|
+
{ "label": "怎么申请退款" },
|
|
62
|
+
{ "label": "推荐一款通勤耳机" }
|
|
63
|
+
]
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
- 图标可用图片路径或内置白名单 `icon:calendar / icon:clock / icon:coins / icon:credit-card / icon:gift / icon:info / icon:map / icon:map-pin / icon:qr-code / icon:receipt / icon:sparkle / icon:star / icon:storefront / icon:ticket / icon:user / icon:warning`(零外链零体积),真源在 kit `QuickCommands` 的 `VECTOR_ICONS`;
|
|
68
|
+
- 富视觉首页(轮播、图文卡、弹幕)仍走 `pnpm exec tbox-app home add` 复制源码——那是 L1;带实时状态的仪表盘用 `home` 槽——那是 L2。选型决策先改 `chat.json`,不够再上 L1/L2。
|
|
69
|
+
|
|
41
70
|
## 能改什么
|
|
42
71
|
|
|
43
72
|
| 位置 | 改法 |
|
|
@@ -63,7 +92,9 @@ import { KitChatProvider } from '@tbox.cn/app-agent-ui-kit';
|
|
|
63
92
|
<KitChatProvider store={store} cards={cards} slots={{ home: (props) => <YourHome {...props} /> }}>
|
|
64
93
|
```
|
|
65
94
|
|
|
66
|
-
- 拿到 `home` 槽时,首屏由你的组件渲染。`HomeSlotRenderProps` 提供 `onSend
|
|
95
|
+
- 拿到 `home` 槽时,首屏由你的组件渲染。`HomeSlotRenderProps` 提供 `onSend`(发一句话进对话)、`onOpenLink`(跳转外链——不再 import `@/store/chat`)、`visible`(空会话态)与 `mallName`。
|
|
96
|
+
- 注册表第三参 `meta`:`slots.register('home', render, { lifecycle, gutter, hideBottomQuickCommands })`。
|
|
97
|
+
推荐 `{ lifecycle: 'home-only', gutter: 'inset' }`:进对话后壳自动卸载收起、壳统一补 16px 屏边距(零行布局 CSS)。裸函数注册 = 存量兼容(`persistent + bleed`,MallHome 形态)。
|
|
67
98
|
- 想保留默认对话体验、只加一块内容时,优先用卡片而不是槽位——卡片能随对话流转,槽位是静态的。
|
|
68
99
|
- 不要 fork kit 去改壳:`packages/agent-ui-kit` 是模板出厂副本,同步会覆盖。需要新能力时改真源并走上游流程。
|
|
69
100
|
|
package/docs/agent/style.md
CHANGED
|
@@ -28,7 +28,7 @@ const TONE = { ok: 'bg-success-soft text-success', warn: 'bg-warning-soft text-w
|
|
|
28
28
|
|
|
29
29
|
- 间距 1 单位 = **4 物理像素**:`p-3`=12px、`gap-1.5`=6px、`mt-5.5`=22px。
|
|
30
30
|
- 不是 4 的倍数用精确值:`py-[3px]`、`h-[95px]`、`rounded-[14px]`、`w-[33.18px]`。
|
|
31
|
-
-
|
|
31
|
+
- 字号只有八档:`text-xs`12 / `text-sm`14 / `text-base`16 / `text-lg`18 / `text-xl`20 / `text-2xl`24 / `text-3xl`30 / `text-4xl`36(4xl 仅大数值特殊场景)。正文 14、辅助 12、卡标题 16–20。**不要写 `text-[13px]`,也不要写 `text-[length:48px]` / rem 字号**:档位外固定字号一律被 `check:fast` 拦下。
|
|
32
32
|
- 唯一例外:活动卡的小标注档 11px(配 `leading-[15px]`),只允许出现在 `ap-badge` / `__badge` / `__meta` / `__hint` 这类钩子所在行;`check:fast` 的 `font-size-off-scale` 只对这一组合放行。
|
|
33
33
|
- 行高用 `leading-5`(20px)这类 4 的倍数,精确值写 `leading-[22px]`。
|
|
34
34
|
- 圆角与阴影优先契约:`rounded-lg/md/sm` 映射 `--tbox-radius-*`,`shadow-sm/md/lg` 映射 `--tbox-shadow-*`。
|
|
@@ -83,9 +83,9 @@ html[data-theme='tbox'] {
|
|
|
83
83
|
}
|
|
84
84
|
```
|
|
85
85
|
|
|
86
|
-
- 换品牌只改这 13 个键,不要改 `--tbox-fs-*` / `--tbox-radius-*` /
|
|
86
|
+
- 换品牌只改这 13 个键,不要改 `--tbox-fs-*` / `--tbox-radius-*` / 阴影、也不要覆写壳欢迎区的 padding:那几组是版式合同,改了就与基元对不上——`style.brand-contract` 门禁会点名。
|
|
87
87
|
- 深色主视觉(`hero.tone: 'inverse'`、`welcome.surface: 'brand'`)用 `primary-dark` 打底 + `primary-light` 写字;
|
|
88
|
-
浅色字压在中间调品牌色上达不到 4.5:1,平台已在欢迎区叠
|
|
88
|
+
浅色字压在中间调品牌色上达不到 4.5:1,平台已在欢迎区叠 20% 深色罩兜底,自定义时不要把它去掉。
|
|
89
89
|
- 需要第四套以外的品牌色:`theme derive --seed <hex>` 从种子派生,再 `theme check` 复核。
|
|
90
90
|
|
|
91
91
|
## 品牌与主题变量
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tbox.cn/app-template-agent",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.21",
|
|
4
4
|
"description": "tbox AI Agent 全栈模板(多包 pnpm workspace):apps/client + apps/server。唯一模板(W4 单一模板统一化:缺省带 AI 支付体验的 chat 形态;mall 能力经 profiles/mall 加装),能力经 CLI module add 模块扩展(shopping-guide/member 等)。",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=24.0.0 <25.0.0",
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
"!.tbox/state",
|
|
34
34
|
"!.tbox/compat-probe.html",
|
|
35
35
|
".gitignore",
|
|
36
|
+
".ignore",
|
|
36
37
|
".nvmrc",
|
|
37
38
|
"AGENTS.md",
|
|
38
39
|
"ENV.md",
|
|
@@ -49,9 +50,9 @@
|
|
|
49
50
|
"typescript-eslint": "8.67.0",
|
|
50
51
|
"eslint-plugin-react-hooks": "5.2.0",
|
|
51
52
|
"vite": "6.4.3",
|
|
52
|
-
"@tbox.cn/app-sdk-server": "1.0.0-alpha.
|
|
53
|
-
"@tbox.cn/app-build": "1.0.0-alpha.
|
|
54
|
-
"@tbox.cn/app-cli": "1.0.0-alpha.
|
|
53
|
+
"@tbox.cn/app-sdk-server": "1.0.0-alpha.21",
|
|
54
|
+
"@tbox.cn/app-build": "1.0.0-alpha.21",
|
|
55
|
+
"@tbox.cn/app-cli": "1.0.0-alpha.21"
|
|
55
56
|
},
|
|
56
57
|
"license": "MIT",
|
|
57
58
|
"publishConfig": {
|