@tbox.cn/app-template-agent 1.0.0-alpha.15 → 1.0.0-alpha.17
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 +2 -0
- package/.tbox/app.json +1 -1
- package/.tbox/cache/._apps-client-strict.tsbuildinfo +0 -0
- package/.tbox/cache/._apps-client.tsbuildinfo +0 -0
- package/.tbox/cache/._apps-server-strict.tsbuildinfo +0 -0
- package/.tbox/cache/._apps-server.tsbuildinfo +0 -0
- package/.tbox/cache/._packages-agent-ui-kit-strict.tsbuildinfo +0 -0
- package/.tbox/cache/._packages-agent-ui-kit.tsbuildinfo +0 -0
- package/.tbox/cache/._packages-shared-strict.tsbuildinfo +0 -0
- package/.tbox/cache/._packages-shared.tsbuildinfo +0 -0
- package/.tbox/cache/apps-client-strict.tsbuildinfo +1 -0
- package/.tbox/cache/apps-client.tsbuildinfo +1 -0
- package/.tbox/cache/apps-server-strict.tsbuildinfo +1 -0
- package/.tbox/cache/apps-server.tsbuildinfo +1 -0
- package/.tbox/cache/packages-agent-ui-kit-strict.tsbuildinfo +1 -0
- package/.tbox/cache/packages-agent-ui-kit.tsbuildinfo +1 -0
- package/.tbox/cache/packages-shared-strict.tsbuildinfo +1 -0
- package/.tbox/cache/packages-shared.tsbuildinfo +1 -0
- package/.tbox/default-modules.json +1 -1
- package/.tbox/miniapp-containers.json +1 -1
- package/AGENTS.md +4 -0
- package/apps/client/scripts/._home-preset-wiring.test.ts +0 -0
- package/apps/client/scripts/._home-preset-wiring.ts +0 -0
- package/apps/client/scripts/._static-checks.test.mjs +0 -0
- package/apps/client/scripts/acceptance-changes.test.mjs +16 -3
- package/apps/client/scripts/check-evidence.mjs +69 -7
- package/apps/client/scripts/evidence-gate.mjs +9 -6
- package/apps/client/scripts/experience-checks.mjs +139 -0
- package/apps/client/scripts/geometry-kernel.test.mjs +3 -1
- package/apps/client/scripts/home-preset-wiring.test.ts +61 -0
- package/apps/client/scripts/home-preset-wiring.ts +41 -0
- package/apps/client/scripts/in-process-checks.mjs +100 -1
- package/apps/client/scripts/probe-checks.mjs +1 -0
- package/apps/client/scripts/static-checks.test.mjs +219 -0
- package/apps/client/src/cards/._home-preset.test.ts +0 -0
- package/apps/client/src/cards/._home-preset.ts +0 -0
- package/apps/client/src/cards/home-preset.test.ts +40 -0
- package/apps/client/src/cards/home-preset.ts +19 -0
- package/apps/client/src/cards/registry.ts +10 -3
- package/apps/client/src/pages/index/index.tsx +1 -1
- package/apps/client/src/styles/tailwind.css +3 -1
- package/apps/client/tsconfig.json +1 -0
- package/apps/client/vite.config.ts +15 -5
- package/apps/server/scripts/scenario-lib.mjs +12 -1
- package/config/._agent.jsonc +0 -0
- package/config/agent.jsonc +10 -0
- package/docs/agent/card-action.md +5 -1
- package/docs/agent/card.md +7 -1
- package/docs/agent/errors.md +7 -1
- package/docs/agent/kit.md +7 -6
- package/docs/agent/shell.md +3 -1
- package/docs/agent/style.md +37 -0
- package/docs/agent/verify.md +5 -2
- package/package.json +5 -4
- package/packages/agent-ui-kit/catalog.json +134 -5
- package/packages/agent-ui-kit/package.json +1 -1
- package/packages/agent-ui-kit/src/._contract.test.tsx +0 -0
- package/packages/agent-ui-kit/src/ChatPage.tsx +204 -27
- package/packages/agent-ui-kit/src/card/._confirm-fields.test.tsx +0 -0
- package/packages/agent-ui-kit/src/card/confirm-fields.test.tsx +106 -0
- package/packages/agent-ui-kit/src/card/primitives.tsx +270 -59
- package/packages/agent-ui-kit/src/card/use-card-actions.ts +5 -1
- package/packages/agent-ui-kit/src/card/view-card.tsx +113 -22
- package/packages/agent-ui-kit/src/chat-config.ts +2 -0
- package/packages/agent-ui-kit/src/components/ActionBar/DebugButton.tsx +12 -4
- package/packages/agent-ui-kit/src/components/ActionBar/index.tsx +61 -27
- package/packages/agent-ui-kit/src/components/BottomSheet/index.tsx +26 -2
- package/packages/agent-ui-kit/src/components/QuickCommands/index.tsx +60 -14
- package/packages/agent-ui-kit/src/components/ToolCallBlock/detail.test.ts +2 -0
- package/packages/agent-ui-kit/src/components/ToolCallBlock/detail.ts +9 -2
- package/packages/agent-ui-kit/src/contract.test.tsx +176 -0
- package/packages/agent-ui-kit/src/hooks/use-stick-to-bottom.test.tsx +101 -0
- package/packages/agent-ui-kit/src/hooks/use-stick-to-bottom.ts +35 -7
- package/packages/agent-ui-kit/src/index.ts +2 -0
- package/packages/agent-ui-kit/src/overlay/Overlay.tsx +21 -2
- package/packages/agent-ui-kit/src/overlay/overlay.test.tsx +15 -0
- package/packages/agent-ui-kit/src/preview-provider.tsx +8 -0
- package/packages/agent-ui-kit/src/shell.contract.json +1 -1
- package/packages/agent-ui-kit/src/shell.test.ts +105 -2
- package/packages/agent-ui-kit/src/theme/base.css +42 -2
- package/pnpm-lock.template.yaml +94 -94
- package/pnpm-workspace.template.yaml +11 -11
- package/scripts/._interaction-probe.mjs +0 -0
- package/scripts/check-fast.mjs +11 -2
- package/scripts/checks.json +80 -2
- package/scripts/deliver.mjs +85 -7
- package/scripts/interaction-probe.mjs +222 -0
- package/scripts/lib/geometry-kernel.mjs +8 -1
- package/scripts/shell-probe.mjs +8 -3
- package/scripts/storyboard.mjs +5 -0
package/scripts/deliver.mjs
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* 选项:--json(stdout 只输出交付 JSON)/ --policy quick|standard|deep / --commit(只提交 DELIVERY.md)
|
|
9
9
|
* 退出码:0 可交付;1 不可交付(failing / incomplete / unspecified)。
|
|
10
10
|
*/
|
|
11
|
-
import { spawnSync } from 'node:child_process';
|
|
11
|
+
import { spawn, spawnSync } from 'node:child_process';
|
|
12
12
|
import { existsSync, mkdirSync, readdirSync, readFileSync, statSync, writeFileSync } from 'node:fs';
|
|
13
13
|
import path from 'node:path';
|
|
14
14
|
|
|
@@ -47,11 +47,26 @@ const newestMtime = (root) => {
|
|
|
47
47
|
walk(root);
|
|
48
48
|
return newest;
|
|
49
49
|
};
|
|
50
|
-
|
|
50
|
+
// 壳探针输入:只有壳配置/主题/kit 会影响它的结论。
|
|
51
|
+
const newestShellInput = Math.max(
|
|
51
52
|
...probeInputs.map((file) => statSync(file).mtimeMs),
|
|
52
53
|
newestMtime(path.join(appDir, 'packages/agent-ui-kit/src')),
|
|
53
54
|
0,
|
|
54
55
|
);
|
|
56
|
+
// 门禁输入:业务代码、场景、配置、模块全都算——**不能**沿用壳探针那份窄口径。
|
|
57
|
+
// 曾经用窄口径判断「门禁结果是否过期」,导致改了 apps/server 的工具/动作之后
|
|
58
|
+
// `deliver --policy quick` 仍复用旧结论,等于跳过一次完整验证就宣称交付。
|
|
59
|
+
const newestGateInput = Math.max(
|
|
60
|
+
newestShellInput,
|
|
61
|
+
newestMtime(path.join(appDir, 'apps/server/src')),
|
|
62
|
+
newestMtime(path.join(appDir, 'apps/client/src')),
|
|
63
|
+
newestMtime(path.join(appDir, 'packages/shared/src')),
|
|
64
|
+
newestMtime(path.join(appDir, 'packages/agent-ui-kit/src')),
|
|
65
|
+
newestMtime(path.join(appDir, 'modules')),
|
|
66
|
+
newestMtime(path.join(appDir, 'scenarios')),
|
|
67
|
+
newestMtime(path.join(appDir, 'config')),
|
|
68
|
+
0,
|
|
69
|
+
);
|
|
55
70
|
const readShellInfo = () => {
|
|
56
71
|
try {
|
|
57
72
|
return JSON.parse(readFileSync(shellFile, 'utf8'));
|
|
@@ -59,10 +74,14 @@ const readShellInfo = () => {
|
|
|
59
74
|
return undefined;
|
|
60
75
|
}
|
|
61
76
|
};
|
|
62
|
-
const probeFresh = existsSync(shellFile) && statSync(shellFile).mtimeMs + 1000 >=
|
|
77
|
+
const probeFresh = existsSync(shellFile) && statSync(shellFile).mtimeMs + 1000 >= newestShellInput;
|
|
63
78
|
let shellInfo = readShellInfo();
|
|
64
79
|
let probeOk = probeFresh;
|
|
65
|
-
if (
|
|
80
|
+
if (platformPolicy === 'static') {
|
|
81
|
+
// quick 档(= static)不要求布局车道:既不跑壳探针,也不跑故事板——
|
|
82
|
+
// 为一份用不到的布局证据启动无头 Chrome,正好抵消这个档位存在的意义。
|
|
83
|
+
probeOk = false;
|
|
84
|
+
} else if (!probeFresh) {
|
|
66
85
|
const probe = spawnSync('node', ['scripts/shell-probe.mjs'], { cwd: appDir, stdio: 'ignore', timeout: 120000 });
|
|
67
86
|
probeOk = probe.status === 0;
|
|
68
87
|
shellInfo = readShellInfo();
|
|
@@ -82,7 +101,61 @@ if (platformPolicy !== 'static') {
|
|
|
82
101
|
env: { ...process.env, ...(shellReady ? { TBOX_SHELL_FRESH: '1' } : {}) },
|
|
83
102
|
});
|
|
84
103
|
}
|
|
85
|
-
|
|
104
|
+
// quick 档快收口:门禁结果未过期时直接复用(交付摘要要的是裁决,不是再跑一遍全量)。
|
|
105
|
+
// 过期判定看 last-gate.json 的时间戳与源码树最新 mtime(与 shell/storyboard 同口径)。
|
|
106
|
+
const LAST_GATE = path.join(appDir, '.tbox/evidence/last-gate.json');
|
|
107
|
+
const gateFresh = (() => {
|
|
108
|
+
if (platformPolicy !== 'static') return false;
|
|
109
|
+
try {
|
|
110
|
+
if (!existsSync(LAST_GATE)) return false;
|
|
111
|
+
const gateAge = statSync(LAST_GATE).mtimeMs;
|
|
112
|
+
return gateAge + 1000 >= newestGateInput;
|
|
113
|
+
} catch {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
})();
|
|
117
|
+
const cachedSummary = (() => {
|
|
118
|
+
if (!gateFresh) return undefined;
|
|
119
|
+
try {
|
|
120
|
+
const parsed = JSON.parse(readFileSync(LAST_GATE, 'utf8'));
|
|
121
|
+
// 只复用「同档位 + 通过」的结论:visual 档的旧结果、失败的旧结果都不能冒充 static 的成功。
|
|
122
|
+
if (parsed?.policy !== 'static' || parsed?.ok !== true) return undefined;
|
|
123
|
+
return parsed;
|
|
124
|
+
} catch {
|
|
125
|
+
return undefined;
|
|
126
|
+
}
|
|
127
|
+
})();
|
|
128
|
+
// 交付前严格 tsc(开发期 check:fast 放宽了未使用变量,收口时要一次干净的类型面)。
|
|
129
|
+
// 四个包并行跑:串行 spawn 的固定开销(约 0.4s/次)在 quick 档里比 tsc 本身还显眼。
|
|
130
|
+
if (!jsonOutput) console.error('(交付前严格类型检查)');
|
|
131
|
+
const strictTypecheck = () =>
|
|
132
|
+
Promise.all(
|
|
133
|
+
['apps/server', 'apps/client', 'packages/shared', 'packages/agent-ui-kit'].map((pkg) => {
|
|
134
|
+
// 严格跑也带增量缓存(与 check:fast 的放宽跑分开缓存,互不污染选项面):
|
|
135
|
+
// 首次交付付一次全量,之后每次只重算改动文件。
|
|
136
|
+
const cacheName = pkg.replace(/[\\/]/g, '-');
|
|
137
|
+
return new Promise((resolve) => {
|
|
138
|
+
const child = spawn(
|
|
139
|
+
'pnpm',
|
|
140
|
+
['exec', 'tsc', '--noEmit', '-p', `${pkg}/tsconfig.json`, '--incremental', '--tsBuildInfoFile', `.tbox/cache/${cacheName}-strict.tsbuildinfo`],
|
|
141
|
+
{ cwd: appDir, stdio: 'ignore' },
|
|
142
|
+
);
|
|
143
|
+
const timer = setTimeout(() => { child.kill(); resolve({ pkg, ok: false, reason: '超时' }); }, 300000);
|
|
144
|
+
child.on('error', () => { clearTimeout(timer); resolve({ pkg, ok: false, reason: 'spawn 失败' }); });
|
|
145
|
+
child.on('close', (code) => { clearTimeout(timer); resolve({ pkg, ok: code === 0 }); });
|
|
146
|
+
});
|
|
147
|
+
}),
|
|
148
|
+
);
|
|
149
|
+
const strictResults = await strictTypecheck();
|
|
150
|
+
const strictFailed = strictResults.filter((result) => !result.ok);
|
|
151
|
+
if (strictFailed.length > 0) {
|
|
152
|
+
console.error(`严格类型检查未通过:${strictFailed.map((result) => result.pkg + (result.reason ? `(${result.reason})` : '')).join('、')}(先修类型,再交付)`);
|
|
153
|
+
process.exit(1);
|
|
154
|
+
}
|
|
155
|
+
if (cachedSummary && !jsonOutput) console.error('(复用未过期的门禁结果:quick 档快收口)');
|
|
156
|
+
const run = cachedSummary
|
|
157
|
+
? { status: 0, stdout: JSON.stringify(cachedSummary) }
|
|
158
|
+
: spawnSync('node', ['scripts/check-fast.mjs'], {
|
|
86
159
|
cwd: appDir, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], maxBuffer: 32 * 1024 * 1024,
|
|
87
160
|
env: { ...process.env, ...(platformPolicy ? { TBOX_POLICY: platformPolicy } : {}) },
|
|
88
161
|
});
|
|
@@ -120,6 +193,9 @@ const changedSinceDelivered = Number.isInteger(delivery.changedSinceDelivered)
|
|
|
120
193
|
: 0;
|
|
121
194
|
const advisoryCount = (Array.isArray(summary.warnings) ? summary.warnings : [])
|
|
122
195
|
.filter((warning) => warning?.id === 'check-warning' && String(warning?.message ?? '').includes('(advisory')).length;
|
|
196
|
+
// 门禁 stdout 会把超量的 warnings 截断(只留前 8 条 + warningCount):截断时按总数说明,
|
|
197
|
+
// 别把「还有更多 advisory」说成只有 8 条。
|
|
198
|
+
const warningsTruncated = Number(summary.warningCount ?? 0) > (Array.isArray(summary.warnings) ? summary.warnings.length : 0);
|
|
123
199
|
|
|
124
200
|
const lines = [];
|
|
125
201
|
lines.push(deliverable ? '已交付。不要再次运行 deliver 或 storyboard。' : '裁决:' + verdict);
|
|
@@ -143,7 +219,7 @@ if (existsSync(storyboardFile)) {
|
|
|
143
219
|
}
|
|
144
220
|
const driftItems = [
|
|
145
221
|
...capability.map((item) => item.key + '(' + item.change + ')'),
|
|
146
|
-
...moduleDrift.map((item) => item.key +
|
|
222
|
+
...moduleDrift.map((item) => item.key + '(已移除)'),
|
|
147
223
|
];
|
|
148
224
|
lines.push(driftItems.length ? '偏离出厂:' + driftItems.join('、') : '偏离出厂:无');
|
|
149
225
|
lines.push('交付后改动:' + (changedSinceDelivered === null ? '无法统计(应用目录不是独立 git 仓)' : changedSinceDelivered + ' 个文件'));
|
|
@@ -159,7 +235,9 @@ if (notApplicable.length > 0) {
|
|
|
159
235
|
// next 只来自门禁的 blocking 结论;advisory 告警在门禁侧只进 warnings,不会出现在这里。
|
|
160
236
|
lines.push('下一步:' + (summary.next ?? (deliverable ? '按摘要交付' : '先修失败项')));
|
|
161
237
|
if (deliverable && advisoryCount > 0) {
|
|
162
|
-
lines.push(
|
|
238
|
+
lines.push(
|
|
239
|
+
'告警:' + (warningsTruncated ? '至少 ' : '') + advisoryCount + ' 条 advisory 不阻断;如需处理,交付后由人决定。',
|
|
240
|
+
);
|
|
163
241
|
}
|
|
164
242
|
|
|
165
243
|
let text = lines.join('\n');
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* interaction-probe —— 弹层层叠与命中区的真浏览器契约探针(L2)。
|
|
4
|
+
*
|
|
5
|
+
* 为什么需要它:`<Overlay>` 的面板若没有自己的定位上下文,绝对定位的遮罩会画在面板之上,
|
|
6
|
+
* 面板里的按钮就永远点不到(`ConfirmSheet` / `BottomSheet` 全中)。这类缺陷在
|
|
7
|
+
* happy-dom 单测里看不出来(`dispatchEvent` 直接打节点,绕过命中测试),只有在真浏览器里
|
|
8
|
+
* 用 `document.elementFromPoint` 才暴露。
|
|
9
|
+
*
|
|
10
|
+
* 实现:SSR 渲染真实的 ConfirmSheet / BottomSheet(canUseDom=false → 就地渲染,不传送),
|
|
11
|
+
* 注入应用真实编译的 Tailwind 产物,再在无头 Chrome 里量命中与计算样式;
|
|
12
|
+
* 额外用 CDP 模拟 `prefers-reduced-motion: reduce`(动画被关掉时最容易丢掉堆叠上下文)。
|
|
13
|
+
*
|
|
14
|
+
* 输出:.tbox/evidence/interaction.json(逐项 status);`TBOX_PROBE_REQUIRED=1` 时无浏览器即失败。
|
|
15
|
+
* CI 无 Chrome 是常态 → 缺浏览器记 not-run 且不阻断(与 shell-probe 同契约)。
|
|
16
|
+
*/
|
|
17
|
+
import { existsSync, mkdirSync, rmSync, writeFileSync } from 'node:fs';
|
|
18
|
+
import { pathToFileURL } from 'node:url';
|
|
19
|
+
import { createRequire } from 'node:module';
|
|
20
|
+
import path from 'node:path';
|
|
21
|
+
import { findChrome, openChromeSession } from './lib/chrome-pipe.mjs';
|
|
22
|
+
|
|
23
|
+
const appDir = path.resolve(import.meta.dirname, '..');
|
|
24
|
+
const clientDir = path.join(appDir, 'apps/client');
|
|
25
|
+
const outDir = path.join(appDir, '.tbox/evidence');
|
|
26
|
+
mkdirSync(outDir, { recursive: true });
|
|
27
|
+
|
|
28
|
+
const PROBE_REQUIRED = process.env.TBOX_PROBE_REQUIRED === '1';
|
|
29
|
+
const chromePath = findChrome();
|
|
30
|
+
const items = [];
|
|
31
|
+
|
|
32
|
+
const push = (id, status, detail, extra = {}) => {
|
|
33
|
+
items.push({ id, lane: 'runtime', status, detail, ...extra });
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
function write(extra) {
|
|
37
|
+
writeFileSync(
|
|
38
|
+
path.join(outDir, 'interaction.json'),
|
|
39
|
+
JSON.stringify({ schemaVersion: 1, protocolVersion: 1, generatedAt: new Date().toISOString(), ...extra, items }, null, 2) + '\n',
|
|
40
|
+
'utf8',
|
|
41
|
+
);
|
|
42
|
+
console.log('interaction probe: ' + items.map((item) => `${item.id}=${item.status}`).join(' '));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (!chromePath) {
|
|
46
|
+
for (const id of ['overlay.hit-test', 'overlay.sheet-hit-test', 'overlay.reduced-motion', 'overlay.sheet-reduced-motion']) {
|
|
47
|
+
push(id, 'not-run', '未找到无头浏览器(可设 TBOX_CHROME)');
|
|
48
|
+
}
|
|
49
|
+
write({ chrome: null, reason: 'no-chrome' });
|
|
50
|
+
if (PROBE_REQUIRED) {
|
|
51
|
+
console.error('interaction probe 失败:TBOX_PROBE_REQUIRED=1 但找不到无头浏览器(可设 TBOX_CHROME)');
|
|
52
|
+
process.exit(1);
|
|
53
|
+
}
|
|
54
|
+
process.exit(0);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
let vite;
|
|
58
|
+
let chrome;
|
|
59
|
+
let htmlFile;
|
|
60
|
+
try {
|
|
61
|
+
const clientRequire = createRequire(path.join(clientDir, 'package.json'));
|
|
62
|
+
const load = (specifier) => import(pathToFileURL(clientRequire.resolve(specifier)).href);
|
|
63
|
+
const { createServer } = await load('vite');
|
|
64
|
+
const react = (await load('@vitejs/plugin-react')).default;
|
|
65
|
+
const tailwindcss = (await load('@tailwindcss/vite')).default;
|
|
66
|
+
const React = (await load('react')).default;
|
|
67
|
+
const { renderToStaticMarkup } = await load('react-dom/server');
|
|
68
|
+
|
|
69
|
+
vite = await createServer({
|
|
70
|
+
configFile: false,
|
|
71
|
+
root: clientDir,
|
|
72
|
+
appType: 'custom',
|
|
73
|
+
logLevel: 'error',
|
|
74
|
+
plugins: [tailwindcss(), react()],
|
|
75
|
+
resolve: { alias: { '@': path.join(clientDir, 'src'), '@config': path.join(appDir, 'config') } },
|
|
76
|
+
server: { middlewareMode: true, fs: { allow: [appDir] } },
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
// 真实 Tailwind 产物(与应用同一入口,@source 已含 kit 源码)
|
|
80
|
+
const { buildSurfaceCss } = await import(path.join(clientDir, 'scripts/surface-css.mjs'));
|
|
81
|
+
const surface = await buildSurfaceCss(vite, { clientDir, appDir });
|
|
82
|
+
const css = surface.cssText;
|
|
83
|
+
|
|
84
|
+
const kit = await vite.ssrLoadModule('@tbox.cn/app-agent-ui-kit');
|
|
85
|
+
const { ConfirmSheet, BottomSheet } = kit;
|
|
86
|
+
|
|
87
|
+
// 每个弹层单独一页:同时打开两个弹层时,后渲染者的遮罩会合法地盖住前者,
|
|
88
|
+
// 那样量出来的「点不到」是假阳性(真实交互里不会两个弹层同时开)。
|
|
89
|
+
const background = React.createElement(
|
|
90
|
+
'div',
|
|
91
|
+
{ className: 'chat-page relative flex h-full w-full flex-col' },
|
|
92
|
+
React.createElement('p', null, '背景内容'),
|
|
93
|
+
);
|
|
94
|
+
const fixtures = {
|
|
95
|
+
confirm: React.createElement(ConfirmSheet, {
|
|
96
|
+
open: true,
|
|
97
|
+
title: '确认碰一下入会?',
|
|
98
|
+
description: '确认后将开通会员',
|
|
99
|
+
confirmText: '碰一下,开通会员',
|
|
100
|
+
cancelText: '再想想',
|
|
101
|
+
highlights: ['+100 积分'],
|
|
102
|
+
onConfirm: () => {},
|
|
103
|
+
onCancel: () => {},
|
|
104
|
+
}),
|
|
105
|
+
sheet: React.createElement(
|
|
106
|
+
BottomSheet,
|
|
107
|
+
{ open: true, variant: 'card', title: '商户详情', onClose: () => {} },
|
|
108
|
+
// 正文必须有**普通流内按钮**:只测自带的 absolute 关闭键,等于没测抽屉里的业务按钮。
|
|
109
|
+
React.createElement(
|
|
110
|
+
'div',
|
|
111
|
+
{ className: 'flex flex-col gap-3' },
|
|
112
|
+
React.createElement('p', { className: 'm-0 text-sm' }, '抽屉内容'),
|
|
113
|
+
React.createElement(
|
|
114
|
+
'button',
|
|
115
|
+
{ type: 'button', className: 'tbox-btn tbox-btn--primary min-h-11 rounded-full bg-primary px-4 text-sm font-medium text-white' },
|
|
116
|
+
'立即领取',
|
|
117
|
+
),
|
|
118
|
+
),
|
|
119
|
+
),
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
// `TBOX_PROBE_BREAK=1`:注入「面板没有定位上下文」的样式,复现历史 bug,
|
|
123
|
+
// 用来验证「探针失败 → 非零退出」这条链路本身(自检不靠人肉记忆)。
|
|
124
|
+
// 破坏模式要同时打破两条层叠依据(遮罩 -z-[1] 与面板定位):
|
|
125
|
+
// 只破坏面板定位时遮罩仍在最底层,探针依然全绿——那会让自检变成摆设。
|
|
126
|
+
const breakCss = process.env.TBOX_PROBE_BREAK === '1'
|
|
127
|
+
? '[data-tbox-overlay-mask]{z-index:auto !important}[data-tbox-overlay-panel]{position:static !important;z-index:auto !important}'
|
|
128
|
+
: '';
|
|
129
|
+
const pageFor = (element) =>
|
|
130
|
+
`<!doctype html><html lang="zh-CN" data-theme="tbox"><head><meta charset="utf-8">` +
|
|
131
|
+
`<meta name="viewport" content="width=device-width,initial-scale=1"><style>${css}${breakCss}</style></head>` +
|
|
132
|
+
`<body>${renderToStaticMarkup(React.createElement('div', { className: 'tbox-app' }, background, element))}</body></html>`;
|
|
133
|
+
|
|
134
|
+
const hitScript = `(() => {
|
|
135
|
+
const panels = [...document.querySelectorAll('[data-tbox-overlay-panel]')];
|
|
136
|
+
return panels.map((panel) => {
|
|
137
|
+
const buttons = [...panel.querySelectorAll('button')];
|
|
138
|
+
const hits = buttons.map((button) => {
|
|
139
|
+
const rect = button.getBoundingClientRect();
|
|
140
|
+
const el = document.elementFromPoint(rect.left + rect.width / 2, rect.top + rect.height / 2);
|
|
141
|
+
return {
|
|
142
|
+
label: (button.textContent || '').trim().slice(0, 20),
|
|
143
|
+
inPanel: !!el && panel.contains(el),
|
|
144
|
+
hitMask: !!el && el.hasAttribute('data-tbox-overlay-mask'),
|
|
145
|
+
};
|
|
146
|
+
});
|
|
147
|
+
const cs = getComputedStyle(panel);
|
|
148
|
+
return { position: cs.position, zIndex: cs.zIndex, hits };
|
|
149
|
+
});
|
|
150
|
+
})()`;
|
|
151
|
+
|
|
152
|
+
const run = async (fixtureKey, label, reducedMotion) => {
|
|
153
|
+
htmlFile = path.join(outDir, `interaction-probe-${fixtureKey}.html`);
|
|
154
|
+
writeFileSync(htmlFile, pageFor(fixtures[fixtureKey]), 'utf8');
|
|
155
|
+
chrome = await openChromeSession({
|
|
156
|
+
chrome: chromePath,
|
|
157
|
+
url: pathToFileURL(htmlFile).href,
|
|
158
|
+
width: 390,
|
|
159
|
+
height: 844,
|
|
160
|
+
});
|
|
161
|
+
if (!chrome) return null;
|
|
162
|
+
if (reducedMotion) {
|
|
163
|
+
await chrome.call('Emulation.setEmulatedMedia', {
|
|
164
|
+
features: [{ name: 'prefers-reduced-motion', value: 'reduce' }],
|
|
165
|
+
});
|
|
166
|
+
await chrome.evaluate('location.reload()');
|
|
167
|
+
await new Promise((resolve) => setTimeout(resolve, 400));
|
|
168
|
+
}
|
|
169
|
+
const result = await chrome.evaluate(hitScript);
|
|
170
|
+
chrome.close();
|
|
171
|
+
chrome = null;
|
|
172
|
+
return { label, result };
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
const confirmNormal = await run('confirm', 'confirm', false);
|
|
176
|
+
const sheetNormal = await run('sheet', 'sheet', false);
|
|
177
|
+
const confirmReduced = await run('confirm', 'confirm-reduced', true);
|
|
178
|
+
const sheetReduced = await run('sheet', 'sheet-reduced', true);
|
|
179
|
+
|
|
180
|
+
const judge = (runResult, id) => {
|
|
181
|
+
if (!runResult || !Array.isArray(runResult.result)) {
|
|
182
|
+
push(id, 'not-run', '浏览器会话未取到命中结果');
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
const panels = runResult.result;
|
|
186
|
+
const buttons = panels.flatMap((panel) => panel.hits);
|
|
187
|
+
if (buttons.length < 2) {
|
|
188
|
+
// 单个按钮(只剩关闭键)说明 fixture 退化了:抽屉正文的业务按钮没被测到。
|
|
189
|
+
push(id, 'fail', `面板里只测到 ${buttons.length} 个按钮(正文按钮缺失,检查 fixture)`);
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
const missed = buttons.filter((hit) => !hit.inPanel);
|
|
193
|
+
const detail = panels.map((panel) => `${panel.position}/${panel.zIndex}`).join(' · ');
|
|
194
|
+
push(
|
|
195
|
+
id,
|
|
196
|
+
missed.length === 0 && buttons.length > 0 ? 'pass' : 'fail',
|
|
197
|
+
missed.length === 0
|
|
198
|
+
? `${buttons.length} 个面板按钮全部命中面板内(面板 ${detail})`
|
|
199
|
+
: `${missed.length} 个按钮点不到:${missed.map((hit) => hit.label).join('、')}(面板 ${detail})`,
|
|
200
|
+
);
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
judge(confirmNormal, 'overlay.hit-test');
|
|
204
|
+
judge(sheetNormal, 'overlay.sheet-hit-test');
|
|
205
|
+
judge(confirmReduced, 'overlay.reduced-motion');
|
|
206
|
+
judge(sheetReduced, 'overlay.sheet-reduced-motion');
|
|
207
|
+
write({ chrome: chromePath });
|
|
208
|
+
// 失败必须让进程非零退出:否则 stage/CI 读 exit code 会把「四项全红」当成通过
|
|
209
|
+
// (假绿比不跑更糟——它会把已修好的回归悄悄放回去)。
|
|
210
|
+
if (items.some((item) => item.status === 'fail')) process.exitCode = 1;
|
|
211
|
+
} catch (error) {
|
|
212
|
+
push('overlay.hit-test', 'fail', `探针执行失败:${(error).message ?? String(error)}`);
|
|
213
|
+
write({ chrome: chromePath, error: true });
|
|
214
|
+
process.exitCode = 1;
|
|
215
|
+
} finally {
|
|
216
|
+
chrome?.close?.();
|
|
217
|
+
await vite?.close?.();
|
|
218
|
+
for (const key of ['confirm', 'sheet']) {
|
|
219
|
+
const file = path.join(outDir, `interaction-probe-${key}.html`);
|
|
220
|
+
if (existsSync(file)) rmSync(file, { force: true });
|
|
221
|
+
}
|
|
222
|
+
}
|
|
@@ -40,7 +40,7 @@ export function geometryFunctionSource() {
|
|
|
40
40
|
' var rootSel = o.root || "body";',
|
|
41
41
|
' var root = (rootSel === "body" ? document.body : document.querySelector(rootSel)) || document.body;',
|
|
42
42
|
' var W = window.innerWidth;',
|
|
43
|
-
' var out = { viewport: { w: W, h: window.innerHeight }, overflowX: 0, overflowRight: 0, clipped: [], smallTargets: [], minFontPx: null, typeScale: { allowed: scale, counts: {}, offScale: [] }, blankGap: null, height: 0 };',
|
|
43
|
+
' var out = { viewport: { w: W, h: window.innerHeight }, overflowX: 0, overflowRight: 0, clipped: [], smallTargets: [], uaStyleButtons: [], minFontPx: null, typeScale: { allowed: scale, counts: {}, offScale: [] }, blankGap: null, height: 0 };',
|
|
44
44
|
' var minFont = 1e9;',
|
|
45
45
|
' var counts = {};',
|
|
46
46
|
' var samples = {};',
|
|
@@ -64,6 +64,12 @@ export function geometryFunctionSource() {
|
|
|
64
64
|
' out.clipped.push({ text: (el.textContent || "").trim().slice(0, 24), tag: el.tagName, ellipsis: ellipsis });',
|
|
65
65
|
' }',
|
|
66
66
|
' }',
|
|
67
|
+
// 浏览器默认外观残留:outset 边框 = 没被任何规则重置过;字体未继承 = 落回 13.33px 系统字。
|
|
68
|
+
' if (el.tagName === "BUTTON" && rect.width > 0 && rect.height > 0) {',
|
|
69
|
+
' var bcs = getComputedStyle(el);',
|
|
70
|
+
' var uaBorder = (bcs.borderTopStyle || "") === "outset" || (bcs.borderTopStyle || "") === "inset";',
|
|
71
|
+
' if (uaBorder) out.uaStyleButtons.push({ reason: "outset 边框", text: (el.textContent || "").trim().slice(0, 16) });',
|
|
72
|
+
' }',
|
|
67
73
|
' if (rect.width > 0 && el.matches(o.targets || ' + JSON.stringify(DEFAULT_TARGETS) + ')) {',
|
|
68
74
|
' if (Math.round(rect.width) < minTarget || Math.round(rect.height) < minTarget) {',
|
|
69
75
|
' out.smallTargets.push({ tag: el.tagName, w: Math.round(rect.width), h: Math.round(rect.height), text: (el.textContent || "").trim().slice(0, 16) });',
|
|
@@ -76,6 +82,7 @@ export function geometryFunctionSource() {
|
|
|
76
82
|
' out.typeScale.offScale = Object.keys(counts).map(Number).filter(function (px) { return scale.indexOf(px) < 0; }).map(function (px) { return { px: px, count: counts[px], sample: samples[px] }; });',
|
|
77
83
|
' out.smallTargets = out.smallTargets.slice(0, 5);',
|
|
78
84
|
' out.clipped = out.clipped.slice(0, 10);',
|
|
85
|
+
' out.uaStyleButtons = out.uaStyleButtons.slice(0, 5);',
|
|
79
86
|
' out.height = Math.round(document.documentElement.scrollHeight);',
|
|
80
87
|
' var blankSels = o.blankSelectors || [];',
|
|
81
88
|
' if (blankSels.length > 0) {',
|
package/scripts/shell-probe.mjs
CHANGED
|
@@ -228,7 +228,9 @@ function staticExpression() {
|
|
|
228
228
|
' const nodes = [...document.querySelectorAll("[data-tbox-control], button, [role=button], .tbox-btn")].filter(visible);',
|
|
229
229
|
' const controls = nodes.map((el) => { const r = rect(el); return { tag: el.tagName, id: el.getAttribute("data-tbox-control") || "", cls: String(el.className).slice(0, 40), label: el.getAttribute("aria-label") || "", text: (el.textContent || "").trim().slice(0, 16), w: r[0], h: r[1] }; });',
|
|
230
230
|
' const quickEl = document.querySelector(".quick-commands");',
|
|
231
|
-
' const
|
|
231
|
+
' const quickScrollEl = quickEl ? (quickEl.querySelector(".quick-commands__scroll") || quickEl) : null;',
|
|
232
|
+
' // 单行变体把按钮包在横向滚动层里:计数与宽度都必须量内层,外围只判形态(grid vs 单行)。',
|
|
233
|
+
' const quick = quickEl ? { count: quickEl.querySelectorAll(".quick-commands__item").length, isGrid: quickEl.classList.contains("quick-commands--grid"), scrollWidth: quickScrollEl.scrollWidth, clientWidth: quickScrollEl.clientWidth } : null;',
|
|
232
234
|
' // 图标三类载体都算可见:CSS 遮罩、文字/自绘、以及 <img> 已解码(默认星标就是资产图)',
|
|
233
235
|
' const icons = [...document.querySelectorAll(".quick-commands__icon")].map((el) => {',
|
|
234
236
|
' const cs = getComputedStyle(el);',
|
|
@@ -313,9 +315,12 @@ function applyChecks(result, chat) {
|
|
|
313
315
|
} else if (!quick) {
|
|
314
316
|
push('shell.quick-visible', 'layout', 'fail', '快捷问题容器未渲染(配置 ' + expected + ' 条)');
|
|
315
317
|
} else {
|
|
316
|
-
|
|
318
|
+
// 无 home 槽的 grid 要求全量不横向溢出;有 home 槽的单行条本来就是横向滚动容器,
|
|
319
|
+
// 只要求按钮全部渲染且容器有可视宽度(溢出由渐隐层提示,不算缺陷)。
|
|
320
|
+
const fits = quick.isGrid ? quick.scrollWidth <= quick.clientWidth + 1 : quick.clientWidth > 0;
|
|
321
|
+
const visible = quick.count >= expected && fits;
|
|
317
322
|
push('shell.quick-visible', 'layout', visible ? 'pass' : 'fail',
|
|
318
|
-
'渲染 ' + quick.count + '/' + expected + '
|
|
323
|
+
'渲染 ' + quick.count + '/' + expected + ' 条(' + (quick.isGrid ? 'grid' : '单行') + ');内容宽 ' + quick.scrollWidth + ' / 容器 ' + quick.clientWidth);
|
|
319
324
|
}
|
|
320
325
|
|
|
321
326
|
const capabilities = [];
|
package/scripts/storyboard.mjs
CHANGED
|
@@ -72,6 +72,11 @@ export function geometryProblems(frame, limits = thresholds) {
|
|
|
72
72
|
if (typeof geometry.minFontPx === 'number' && geometry.minFontPx < limits.minFontPx) {
|
|
73
73
|
problems.push({ id: 'card.min-font', detail: frame.id + ' 最小字号 ' + geometry.minFontPx + 'px' });
|
|
74
74
|
}
|
|
75
|
+
// 按钮仍在用浏览器默认外观(outset 边框):说明既没走 kit 基元、也没有作用域重置兜底。
|
|
76
|
+
const uaButtons = geometry.uaStyleButtons ?? [];
|
|
77
|
+
if (uaButtons.length > 0) {
|
|
78
|
+
problems.push({ id: 'card.button-ua-style', detail: frame.id + ' 按钮为浏览器默认外观 ' + uaButtons.length + ' 处:' + uaButtons.slice(0, 3).map((item) => item.text || item.reason).join('、') });
|
|
79
|
+
}
|
|
75
80
|
return problems;
|
|
76
81
|
}
|
|
77
82
|
|