@tbox.cn/app-template-agent 1.0.0-alpha.8 → 1.0.0-alpha.9

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.
Files changed (109) hide show
  1. package/.gitignore +7 -0
  2. package/.tbox/app.json +1 -1
  3. package/.tbox/default-modules.json +1 -1
  4. package/.tbox/factory/chat.json +9 -0
  5. package/.tbox/miniapp-containers.json +1 -1
  6. package/AGENTS.md +4 -2
  7. package/apps/client/package.json +1 -0
  8. package/apps/client/scripts/._color-scan.test.mjs +0 -0
  9. package/apps/client/scripts/._experience-checks.mjs +0 -0
  10. package/apps/client/scripts/._geometry-kernel.test.mjs +0 -0
  11. package/apps/client/scripts/._in-process-checks.mjs +0 -0
  12. package/apps/client/scripts/._probe-checks.mjs +0 -0
  13. package/apps/client/scripts/._sample-entries.test.mjs +0 -0
  14. package/apps/client/scripts/._storyboard.test.mjs +0 -0
  15. package/apps/client/scripts/._theme-kernel.mjs +0 -0
  16. package/apps/client/scripts/._theme-kernel.test.mjs +0 -0
  17. package/apps/client/scripts/acceptance-changes.test.mjs +97 -0
  18. package/apps/client/scripts/check-evidence.mjs +361 -94
  19. package/apps/client/scripts/color-scan.mjs +66 -0
  20. package/apps/client/scripts/color-scan.test.mjs +25 -0
  21. package/apps/client/scripts/evidence-gate.mjs +248 -46
  22. package/apps/client/scripts/evidence-gate.test.mjs +63 -5
  23. package/apps/client/scripts/experience-checks.mjs +163 -0
  24. package/apps/client/scripts/geometry-kernel.test.mjs +92 -0
  25. package/apps/client/scripts/in-process-checks.mjs +51 -0
  26. package/apps/client/scripts/lib/._card-registry.mjs +0 -0
  27. package/apps/client/scripts/lib/._card-registry.test.mjs +0 -0
  28. package/apps/client/scripts/lib/._evidence-inputs.mjs +0 -0
  29. package/apps/client/scripts/lib/._evidence-inputs.test.mjs +0 -0
  30. package/apps/client/scripts/lib/._static-render.mjs +0 -0
  31. package/apps/client/scripts/lib/._static-render.test.mjs +0 -0
  32. package/apps/client/scripts/lib/card-registry.mjs +81 -0
  33. package/apps/client/scripts/lib/card-registry.test.mjs +59 -0
  34. package/apps/client/scripts/lib/evidence-inputs.mjs +91 -0
  35. package/apps/client/scripts/lib/evidence-inputs.test.mjs +27 -0
  36. package/apps/client/scripts/lib/static-render.mjs +35 -0
  37. package/apps/client/scripts/lib/static-render.test.mjs +21 -0
  38. package/apps/client/scripts/probe-checks.mjs +85 -0
  39. package/apps/client/scripts/render-card.mjs +76 -60
  40. package/apps/client/scripts/sample-entries.test.mjs +31 -0
  41. package/apps/client/scripts/storyboard.test.mjs +149 -0
  42. package/apps/client/scripts/surface-css.mjs +5 -2
  43. package/apps/client/scripts/theme-kernel.mjs +236 -0
  44. package/apps/client/scripts/theme-kernel.test.mjs +136 -0
  45. package/apps/client/src/styles/brand.css +11 -11
  46. package/apps/client/src/styles/tailwind.css +3 -4
  47. package/apps/client/vite.config.ts +2 -1
  48. package/apps/server/scripts/probe.mjs +6 -1
  49. package/apps/server/scripts/scenario-lib.mjs +54 -7
  50. package/apps/server/scripts/scenario.mjs +41 -7
  51. package/config/AGENTS.md +1 -0
  52. package/config/chat.json +21 -9
  53. package/docs/agent/card.md +1 -0
  54. package/docs/agent/kit.md +1 -1
  55. package/docs/agent/shell.md +1 -0
  56. package/docs/agent/style.md +3 -1
  57. package/docs/agent/verify.md +37 -8
  58. package/package.json +9 -6
  59. package/packages/agent-ui-kit/README.md +21 -1
  60. package/packages/agent-ui-kit/catalog.json +1 -1
  61. package/packages/agent-ui-kit/package.json +9 -1
  62. package/packages/agent-ui-kit/src/ChatPage.tsx +30 -1
  63. package/packages/agent-ui-kit/src/card/primitives.test.tsx +10 -0
  64. package/packages/agent-ui-kit/src/card/primitives.tsx +14 -10
  65. package/packages/agent-ui-kit/src/card/view-card.tsx +6 -1
  66. package/packages/agent-ui-kit/src/chat-config.ts +11 -7
  67. package/packages/agent-ui-kit/src/components/ActionBar/DebugButton.test.tsx +3 -0
  68. package/packages/agent-ui-kit/src/components/ActionBar/DebugButton.tsx +2 -7
  69. package/packages/agent-ui-kit/src/components/BottomSheet/._index.test.tsx +0 -0
  70. package/packages/agent-ui-kit/src/components/BottomSheet/._index.tsx +0 -0
  71. package/packages/agent-ui-kit/src/components/BottomSheet/index.test.tsx +90 -0
  72. package/packages/agent-ui-kit/src/components/BottomSheet/index.tsx +129 -0
  73. package/packages/agent-ui-kit/src/components/ChatInput/index.test.tsx +2 -2
  74. package/packages/agent-ui-kit/src/components/ChatInput/index.tsx +21 -16
  75. package/packages/agent-ui-kit/src/components/HistoryEntry/index.tsx +1 -0
  76. package/packages/agent-ui-kit/src/components/QuickCommands/index.tsx +2 -2
  77. package/packages/agent-ui-kit/src/components/ScrollToBottomButton/index.tsx +7 -3
  78. package/packages/agent-ui-kit/src/components/ToolCallBlock/index.tsx +4 -2
  79. package/packages/agent-ui-kit/src/index.ts +4 -0
  80. package/packages/agent-ui-kit/src/shell.contract.json +9 -0
  81. package/packages/agent-ui-kit/src/shell.test.ts +10 -0
  82. package/packages/agent-ui-kit/src/shell.ts +15 -0
  83. package/packages/agent-ui-kit/src/theme/contract.json +78 -1
  84. package/packages/agent-ui-kit/src/theme/theme-contract.test.ts +16 -0
  85. package/packages/agent-ui-kit/src/theme/tokens.css +1 -1
  86. package/pnpm-lock.template.yaml +97 -91
  87. package/pnpm-workspace.template.yaml +10 -10
  88. package/profiles/mall/._chat.overrides.json +0 -0
  89. package/profiles/mall/chat.overrides.json +12 -0
  90. package/profiles/mall/config/chat.json +14 -6
  91. package/profiles/mall.json +1 -1
  92. package/scripts/._deliver.mjs +0 -0
  93. package/scripts/._shell-probe.mjs +0 -0
  94. package/scripts/._storyboard.mjs +0 -0
  95. package/scripts/check-fast.mjs +1 -0
  96. package/scripts/checks.json +294 -17
  97. package/scripts/deliver.mjs +183 -0
  98. package/scripts/lib/._chrome-pipe.mjs +0 -0
  99. package/scripts/lib/._geometry-kernel.mjs +0 -0
  100. package/scripts/lib/chrome-pipe.mjs +95 -0
  101. package/scripts/lib/geometry-kernel.mjs +137 -0
  102. package/scripts/shell-probe.mjs +283 -0
  103. package/scripts/storyboard.mjs +350 -0
  104. package/profiles/mall/config/llm_provider.json +0 -5
  105. package/profiles/mall/config/plugins.json +0 -3
  106. package/scripts/gen-tailwind-sources.mjs +0 -55
  107. /package/{profiles/mall/config/._llm_provider.json → .tbox/factory/._chat.json} +0 -0
  108. /package/{profiles/mall/config/._plugins.json → apps/client/scripts/._acceptance-changes.test.mjs} +0 -0
  109. /package/{scripts/._gen-tailwind-sources.mjs → apps/client/scripts/._color-scan.mjs} +0 -0
@@ -233,7 +233,9 @@
233
233
  "threshold": "0 段",
234
234
  "symptom": "入口 HTML 有内联脚本(解析期执行,body 可能还是 null)",
235
235
  "fix": "删掉内联脚本;启动逻辑放打包后的模块里",
236
- "recipe": "verify"
236
+ "recipe": "verify",
237
+ "since": "1.0.0-alpha.8",
238
+ "phase": "static"
237
239
  },
238
240
  {
239
241
  "id": "shell.identity",
@@ -243,7 +245,9 @@
243
245
  "threshold": "取 identity.name",
244
246
  "symptom": "发送者名写死「AI 助手」,已配置的身份没用上",
245
247
  "fix": "从 chat.json identity.name 取,缺省再回落",
246
- "recipe": "shell"
248
+ "recipe": "shell",
249
+ "since": "1.0.0-alpha.8",
250
+ "phase": "static"
247
251
  },
248
252
  {
249
253
  "id": "shell.type-scale",
@@ -253,17 +257,21 @@
253
257
  "threshold": "0 处",
254
258
  "symptom": "写了档外字号(text-[13px] 之类)",
255
259
  "fix": "用 12/14/16/18/20/24/30/36 档:正文 16、卡片正文 14、说明 12",
256
- "recipe": "style"
260
+ "recipe": "style",
261
+ "since": "1.0.0-alpha.8",
262
+ "phase": "static"
257
263
  },
258
264
  {
259
265
  "id": "css.sentinel",
260
266
  "level": "error",
261
267
  "source": "experience",
262
268
  "lane": "in-process",
263
- "threshold": ">20KB 且含哨兵",
264
- "symptom": "证据 CSS 为空或不完整(样式管线断了)",
265
- "fix": "确认 tailwind.css 与 @source;证据与 dev/build 共用 surface-css.mjs",
266
- "recipe": "style"
269
+ "threshold": ">20KB、模块 ID 对齐且含哨兵",
270
+ "symptom": "证据 CSS 为空、缺模块源码或模块类未生成",
271
+ "fix": "确认 `vite.config.ts` 的 `tboxModuleSourcesPlugin` 在 `tailwindcss()` 之前;证据与 dev/build 共用 app-build 的 `collectModuleSourceDirs`",
272
+ "recipe": "style",
273
+ "since": "1.0.0-alpha.8",
274
+ "phase": "in-process"
267
275
  },
268
276
  {
269
277
  "id": "card.states",
@@ -273,27 +281,33 @@
273
281
  "threshold": "全部卡片",
274
282
  "symptom": "卡片历史态渲染失败或为空",
275
283
  "fix": "用 isHistory 只禁用动作,不隐藏内容",
276
- "recipe": "card"
284
+ "recipe": "card",
285
+ "since": "1.0.0-alpha.8",
286
+ "phase": "in-process"
277
287
  },
278
288
  {
279
289
  "id": "shell.hit-target",
280
290
  "level": "error",
281
291
  "source": "experience",
282
- "lane": "browser",
292
+ "lane": "layout",
283
293
  "threshold": ">=44x44",
284
294
  "symptom": "可交互元素命中区小于 44px",
285
295
  "fix": "用 kit 按钮与 min-h-11;视觉尺寸可小,命中区要足",
286
- "recipe": "shell"
296
+ "recipe": "shell",
297
+ "since": "1.0.0-alpha.8",
298
+ "phase": "probe"
287
299
  },
288
300
  {
289
301
  "id": "shell.quick-visible",
290
302
  "level": "error",
291
303
  "source": "experience",
292
- "lane": "browser",
304
+ "lane": "layout",
293
305
  "threshold": "N/N",
294
306
  "symptom": "空态快捷问题没有全部可见(横向溢出或贴底)",
295
307
  "fix": "空态用两列 grid,对话态才用单行",
296
- "recipe": "shell"
308
+ "recipe": "shell",
309
+ "since": "1.0.0-alpha.8",
310
+ "phase": "probe"
297
311
  },
298
312
  {
299
313
  "id": "flow.persist",
@@ -303,7 +317,8 @@
303
317
  "threshold": "重启一致",
304
318
  "symptom": "状态没有跨进程重启验证",
305
319
  "fix": "用 createUserState({ persist: \"file\" }) 并加重启探针",
306
- "recipe": "state"
320
+ "recipe": "state",
321
+ "since": "1.0.0-alpha.8"
307
322
  },
308
323
  {
309
324
  "id": "shell.contrast",
@@ -314,18 +329,22 @@
314
329
  "metric": "对比度",
315
330
  "symptom": "令牌对比度低于阈值(文字看不清)",
316
331
  "fix": "调 brand.css 的令牌值;color-mix 派生的由浏览器车道补验",
317
- "recipe": "style"
332
+ "recipe": "style",
333
+ "since": "1.0.0-alpha.8",
334
+ "phase": "in-process"
318
335
  },
319
336
  {
320
337
  "id": "shell.blank",
321
338
  "level": "error",
322
339
  "source": "experience",
323
- "lane": "browser",
340
+ "lane": "layout",
324
341
  "threshold": "<=35% 视口高",
325
342
  "metric": "最大块间空白",
326
343
  "symptom": "内容块之间空白过大(看起来没做完)",
327
344
  "fix": "空态成组居中、补服务入口;只算块间空白,不算首尾对称留白",
328
- "recipe": "shell"
345
+ "recipe": "shell",
346
+ "since": "1.0.0-alpha.8",
347
+ "phase": "probe"
329
348
  },
330
349
  {
331
350
  "id": "card.height",
@@ -336,7 +355,9 @@
336
355
  "metric": "估算高度",
337
356
  "symptom": "视图卡过高(一屏放不下)",
338
357
  "fix": "按预算减积木或拆卡;详情用单独的卡承接",
339
- "recipe": "card"
358
+ "recipe": "card",
359
+ "since": "1.0.0-alpha.8",
360
+ "phase": "in-process"
340
361
  },
341
362
  {
342
363
  "id": "CARD_TYPE_INVALID",
@@ -345,6 +366,262 @@
345
366
  "symptom": "卡片类型含路径分隔符或非法字符",
346
367
  "fix": "改成小写 kebab(字母/数字/点/下划线/中划线),不要用 ../ 或斜杠",
347
368
  "recipe": "card"
369
+ },
370
+ {
371
+ "id": "shell.icon-render",
372
+ "level": "error",
373
+ "source": "experience",
374
+ "lane": "layout",
375
+ "threshold": "可见",
376
+ "symptom": "快捷问题图标不可见(遮罩失效或节点被隐藏)",
377
+ "fix": "修正 maskImage 引号或改用可见元素;应用自绘图标时保证按钮内有可见内容",
378
+ "recipe": "shell",
379
+ "since": "1.0.0-alpha.8",
380
+ "phase": "probe"
381
+ },
382
+ {
383
+ "id": "shell.controls-semantic",
384
+ "level": "error",
385
+ "source": "experience",
386
+ "lane": "layout",
387
+ "threshold": "0 处",
388
+ "symptom": "核心控件不是 button/a(键盘与读屏不可用)",
389
+ "fix": "用 button + aria-label + focus-visible;保留原类名",
390
+ "recipe": "shell",
391
+ "since": "1.0.0-alpha.8",
392
+ "phase": "probe"
393
+ },
394
+ {
395
+ "id": "shell.control-present",
396
+ "level": "error",
397
+ "source": "experience",
398
+ "lane": "layout",
399
+ "threshold": "能力与控件一致",
400
+ "symptom": "能力开启但对应控件不可见",
401
+ "fix": "按能力配置渲染控件;关闭能力时才隐藏",
402
+ "recipe": "shell",
403
+ "since": "1.0.0-alpha.8",
404
+ "phase": "probe"
405
+ },
406
+ {
407
+ "id": "shell.a11y-name",
408
+ "level": "error",
409
+ "source": "experience",
410
+ "lane": "layout",
411
+ "threshold": "全部有名称",
412
+ "symptom": "控件缺可访问名",
413
+ "fix": "aria-label 或可见文本",
414
+ "recipe": "shell",
415
+ "since": "1.0.0-alpha.8",
416
+ "phase": "probe"
417
+ },
418
+ {
419
+ "id": "meta.brand",
420
+ "level": "warning",
421
+ "source": "experience",
422
+ "lane": "static",
423
+ "threshold": "与 identity 一致",
424
+ "symptom": "页面标题/主题色未跟品牌",
425
+ "fix": "由 identity 注入 title 与 theme-color",
426
+ "recipe": "shell",
427
+ "since": "1.0.0-alpha.8",
428
+ "phase": "static"
429
+ },
430
+ {
431
+ "id": "quick.label-query",
432
+ "level": "warning",
433
+ "source": "experience",
434
+ "lane": "static",
435
+ "threshold": "一致或包含",
436
+ "symptom": "快捷问题按钮文案与发送文本不一致",
437
+ "fix": "query 缺省等于 label,或让 query 包含 label",
438
+ "recipe": "shell",
439
+ "since": "1.0.0-alpha.8",
440
+ "phase": "static"
441
+ },
442
+ {
443
+ "id": "card.action-primary",
444
+ "level": "warning",
445
+ "source": "experience",
446
+ "lane": "in-process",
447
+ "threshold": "≤1 个主按钮",
448
+ "symptom": "卡片动作无主次",
449
+ "fix": "第一个动作 primary,其余 secondary",
450
+ "recipe": "card",
451
+ "since": "1.0.0-alpha.8",
452
+ "phase": "static"
453
+ },
454
+ {
455
+ "id": "kit.color-literal",
456
+ "level": "warning",
457
+ "source": "experience",
458
+ "lane": "static",
459
+ "threshold": "0 处",
460
+ "symptom": "kit 样式里出现令牌之外的颜色字面量",
461
+ "fix": "改用主题令牌(标签色随主色派生)",
462
+ "recipe": "style",
463
+ "since": "1.0.0-alpha.8",
464
+ "phase": "static"
465
+ },
466
+ {
467
+ "id": "style.url-quoted",
468
+ "level": "warning",
469
+ "source": "experience",
470
+ "lane": "static",
471
+ "threshold": "0 处",
472
+ "symptom": "样式里的 url() 未加引号,data URI 会被 CSSOM 拒绝",
473
+ "fix": "写 url(\"…\")",
474
+ "recipe": "style",
475
+ "since": "1.0.0-alpha.8",
476
+ "phase": "static"
477
+ },
478
+ {
479
+ "id": "checks.registry",
480
+ "level": "error",
481
+ "source": "experience",
482
+ "lane": "static",
483
+ "threshold": "登记=实现",
484
+ "symptom": "checks.json 登记了门禁未实现的检查项",
485
+ "fix": "补实现或删登记;sync-check-docs 会同步报错表",
486
+ "recipe": "verify",
487
+ "since": "1.0.0-alpha.8"
488
+ },
489
+ {
490
+ "id": "shell.turn-visible",
491
+ "level": "error",
492
+ "source": "experience",
493
+ "lane": "runtime",
494
+ "threshold": "0 条告警",
495
+ "symptom": "新回合把问题顶出视口,用户看不到自己在问什么",
496
+ "fix": "修回合锚定与浮标;不要用定时器追底",
497
+ "recipe": "shell",
498
+ "since": "1.0.0-alpha.8",
499
+ "phase": "probe"
500
+ },
501
+ {
502
+ "id": "shell.console-clean",
503
+ "level": "error",
504
+ "source": "experience",
505
+ "lane": "runtime",
506
+ "threshold": "0 条告警",
507
+ "symptom": "水合时控制台出现告警/错误(重复注册、未知属性、SSR 警告)",
508
+ "fix": "按告警修源头;不要静音 console",
509
+ "recipe": "shell",
510
+ "since": "1.0.0-alpha.8",
511
+ "phase": "probe"
512
+ },
513
+ {
514
+ "id": "storyboard.render",
515
+ "level": "error",
516
+ "source": "experience",
517
+ "lane": "layout",
518
+ "phase": "probe",
519
+ "symptom": "故事板渲染失败(帧没跑完)",
520
+ "fix": "看 storyboard.json 的 reason;多为样例数据不合 schema 或 Chrome 未就绪",
521
+ "recipe": "verify",
522
+ "since": "1.0.0-alpha.8"
523
+ },
524
+ {
525
+ "id": "card.overflow-x",
526
+ "level": "error",
527
+ "source": "experience",
528
+ "lane": "layout",
529
+ "phase": "probe",
530
+ "threshold": {
531
+ "overflowTolerancePx": 1
532
+ },
533
+ "metric": "横向溢出像素",
534
+ "symptom": "卡片在窄屏横向溢出",
535
+ "fix": "去掉定宽;长文本允许换行(break-words),图片用 max-w-full",
536
+ "recipe": "card",
537
+ "since": "1.0.0-alpha.8"
538
+ },
539
+ {
540
+ "id": "card.text-clip",
541
+ "level": "warning",
542
+ "source": "experience",
543
+ "lane": "layout",
544
+ "phase": "probe",
545
+ "metric": "无省略号的截断处",
546
+ "symptom": "文本被容器截断且没有省略号",
547
+ "fix": "加 truncate(省略号)或允许换行;数字与金额不要截断",
548
+ "recipe": "card",
549
+ "since": "1.0.0-alpha.8"
550
+ },
551
+ {
552
+ "id": "card.tap-target",
553
+ "level": "warning",
554
+ "source": "experience",
555
+ "lane": "layout",
556
+ "phase": "probe",
557
+ "threshold": {
558
+ "minTarget": 44
559
+ },
560
+ "metric": "可点元素边长",
561
+ "symptom": "卡片上的按钮点击区小于 44px",
562
+ "fix": "用 kit Button;视觉尺寸小时给外层留 min-h-11",
563
+ "recipe": "card",
564
+ "since": "1.0.0-alpha.8"
565
+ },
566
+ {
567
+ "id": "card.min-font",
568
+ "level": "warning",
569
+ "source": "experience",
570
+ "lane": "layout",
571
+ "phase": "probe",
572
+ "threshold": {
573
+ "minFontPx": 12
574
+ },
575
+ "metric": "最小字号",
576
+ "symptom": "卡片里有小于 12px 的文字",
577
+ "fix": "用 text-xs 及以上;次要信息降级不如减少信息",
578
+ "recipe": "card",
579
+ "since": "1.0.0-alpha.8"
580
+ },
581
+ {
582
+ "id": "style.color-repeat",
583
+ "level": "warning",
584
+ "source": "experience",
585
+ "lane": "static",
586
+ "phase": "static",
587
+ "threshold": ">=3 处",
588
+ "metric": "重复色值组数",
589
+ "symptom": "同一色值在卡片/组件里出现 3 次以上(该进令牌)",
590
+ "fix": "换成语义类;确需新色就写进 brand.css 的令牌,再用 bg-[var(--tbox-*)] 或语义类",
591
+ "recipe": "style",
592
+ "since": "1.0.0-alpha.8"
593
+ }
594
+ ],
595
+ "storyboard": {
596
+ "$comment": "故事板容量(帧数=壳+卡样例;超上限时截断仍记 ok+truncated,已渲染帧全部通过)。module 卡较多时按实际帧数调 maxPages。",
597
+ "maxPages": 7,
598
+ "budgetMs": 45000,
599
+ "pageLimit": 12000
600
+ },
601
+ "frames": [
602
+ {
603
+ "id": "shell.empty",
604
+ "source": "shell",
605
+ "widths": [
606
+ 390,
607
+ 320
608
+ ]
609
+ },
610
+ {
611
+ "id": "shell.runtime",
612
+ "source": "shell",
613
+ "widths": [
614
+ 390
615
+ ]
616
+ },
617
+ {
618
+ "id": "card",
619
+ "source": "card-samples",
620
+ "widths": [
621
+ 390,
622
+ 320
623
+ ],
624
+ "maxSamplesPerCard": 3
348
625
  }
349
626
  ]
350
627
  }
@@ -0,0 +1,183 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * pnpm deliver —— 交付唯一入口。
4
+ *
5
+ * 跑 check:fast,把裁决、验收覆盖、能力偏离、漂移、未运行项收成一份摘要(stdout ≤1500 字符)
6
+ * 与 .tbox/evidence/delivery.json + 应用根 DELIVERY.md。
7
+ *
8
+ * 选项:--json(stdout 只输出交付 JSON)/ --policy quick|standard|deep / --commit(只提交 DELIVERY.md)
9
+ * 退出码:0 deliverable / 1 failing / 2 incomplete 或 reopened。
10
+ */
11
+ import { spawnSync } from 'node:child_process';
12
+ import { existsSync, mkdirSync, readdirSync, readFileSync, statSync, writeFileSync } from 'node:fs';
13
+ import path from 'node:path';
14
+
15
+ const appDir = path.resolve(import.meta.dirname, '..');
16
+ const argv = process.argv.slice(2);
17
+ const jsonOutput = argv.includes('--json');
18
+ const commitSummary = argv.includes('--commit');
19
+ const policyIndex = argv.indexOf('--policy');
20
+ const policyArg = policyIndex >= 0 ? argv[policyIndex + 1] : undefined;
21
+ const POLICY_MAP = { quick: 'static', standard: 'visual', deep: 'flow' };
22
+ const platformPolicy = policyArg ? POLICY_MAP[policyArg] ?? policyArg : process.env.TBOX_POLICY;
23
+ if (policyArg && !POLICY_MAP[policyArg]) {
24
+ console.error('未知档位:' + policyArg + '(可用:quick / standard / deep)');
25
+ process.exit(2);
26
+ }
27
+ // 先跑壳探针(有 Chrome 时产出布局证据;没有则如实 not-run,不阻断)。
28
+ // 结果未过期就复用:输入(壳配置/主题/kit)没变时不必重复起 Chrome。
29
+ const probeInputs = [
30
+ 'config/chat.json',
31
+ 'apps/client/src/styles/brand.css',
32
+ 'apps/client/src/styles/tokens.css',
33
+ ].map((rel) => path.join(appDir, rel)).filter((file) => existsSync(file));
34
+ const shellFile = path.join(appDir, '.tbox', 'evidence', 'shell.json');
35
+ const newestMtime = (root) => {
36
+ let newest = 0;
37
+ const walk = (dir) => {
38
+ let entries;
39
+ try { entries = readdirSync(dir, { withFileTypes: true }); } catch { return; }
40
+ for (const entry of entries) {
41
+ if (entry.name === 'node_modules' || entry.name === 'dist' || entry.name === '.git') continue;
42
+ const full = path.join(dir, entry.name);
43
+ if (entry.isDirectory()) walk(full);
44
+ else { try { newest = Math.max(newest, statSync(full).mtimeMs); } catch { /* ignore */ } }
45
+ }
46
+ };
47
+ walk(root);
48
+ return newest;
49
+ };
50
+ const newestInput = Math.max(
51
+ ...probeInputs.map((file) => statSync(file).mtimeMs),
52
+ newestMtime(path.join(appDir, 'packages/agent-ui-kit/src')),
53
+ 0,
54
+ );
55
+ const readShellInfo = () => {
56
+ try {
57
+ return JSON.parse(readFileSync(shellFile, 'utf8'));
58
+ } catch {
59
+ return undefined;
60
+ }
61
+ };
62
+ const probeFresh = existsSync(shellFile) && statSync(shellFile).mtimeMs + 1000 >= newestInput;
63
+ let shellInfo = readShellInfo();
64
+ let probeOk = probeFresh;
65
+ if (!probeFresh) {
66
+ const probe = spawnSync('node', ['scripts/shell-probe.mjs'], { cwd: appDir, stdio: 'ignore', timeout: 120000 });
67
+ probeOk = probe.status === 0;
68
+ shellInfo = readShellInfo();
69
+ } else if (!jsonOutput) {
70
+ console.log('(复用未过期的壳探针结果)');
71
+ }
72
+ // 故事板:卡片/品牌/壳任一变了就重跑(storyboard 自己带缓存,命中时 <2s)。
73
+ // 档位与裁决同源:quick 映射成 static,static 档不要求布局证据。
74
+ if (platformPolicy !== 'static') {
75
+ // 只有壳探针真正成功(shell.json 带 html 标记且 html 在场)才允许 storyboard 复用它:
76
+ // probe 失败但旧 shell.html 残留时,跳过会让故事板用旧壳冒充当前。
77
+ const shellReady = probeOk && Boolean(shellInfo?.html) && existsSync(path.join(appDir, String(shellInfo.html)));
78
+ spawnSync('node', ['scripts/storyboard.mjs'], {
79
+ cwd: appDir,
80
+ stdio: 'ignore',
81
+ timeout: 120000,
82
+ env: { ...process.env, ...(shellReady ? { TBOX_SHELL_FRESH: '1' } : {}) },
83
+ });
84
+ }
85
+ const run = spawnSync('node', ['scripts/check-fast.mjs'], {
86
+ cwd: appDir, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], maxBuffer: 32 * 1024 * 1024,
87
+ env: { ...process.env, ...(platformPolicy ? { TBOX_POLICY: platformPolicy } : {}) },
88
+ });
89
+ const stdout = String(run.stdout ?? '');
90
+ const parse = () => {
91
+ const lines = stdout.trim().split('\n');
92
+ for (let i = lines.length - 1; i >= 0; i -= 1) {
93
+ const line = lines[i].trim();
94
+ if (!line.startsWith('{')) continue;
95
+ try { return JSON.parse(line); } catch { /* 继续找 */ }
96
+ }
97
+ return undefined;
98
+ };
99
+ const summary = parse();
100
+ if (!summary) {
101
+ console.error((String(run.stderr ?? '') || stdout || 'check:fast 未产出摘要').slice(0, 1500));
102
+ process.exit(1);
103
+ }
104
+ const verdict = summary.verdict ?? (summary.ok ? 'unknown' : 'failing');
105
+ const acceptance = summary.acceptance ?? {};
106
+ const delivery = summary.delivery ?? {};
107
+ const policy = summary.policy ?? 'unknown';
108
+ const drift = Array.isArray(delivery.drift) ? delivery.drift : [];
109
+ const capability = Array.isArray(delivery.capabilityDrift) ? delivery.capabilityDrift : [];
110
+ // 偏离出厂 = 能力开关 + 默认模块集(两处登记,同一行账)。
111
+ const moduleDrift = Array.isArray(delivery.moduleDrift) ? delivery.moduleDrift : [];
112
+ const notRun = Array.isArray(summary.notRun) ? summary.notRun : [];
113
+ const deferred = Array.isArray(delivery.deferred) ? delivery.deferred : [];
114
+
115
+ const lines = [];
116
+ lines.push('裁决:' + verdict);
117
+ if (summary.acceptance) {
118
+ lines.push('验收:' + (acceptance.items ?? 0) + ' 项 / 覆盖 ' + (acceptance.covered ?? 0) + ' / handoff ' + (acceptance.handoff ?? acceptance.review ?? 0));
119
+ }
120
+ lines.push('档位:' + policy);
121
+ // 视觉证据在裁决之后固定给出——「界面看过了」有图可指,agent 不必自己再去看。
122
+ const storyboardFile = path.join(appDir, '.tbox', 'evidence', 'storyboard.json');
123
+ if (existsSync(storyboardFile)) {
124
+ try {
125
+ const board = JSON.parse(readFileSync(storyboardFile, 'utf8'));
126
+ if (board.status === 'not-run') {
127
+ lines.push('视觉证据:未生成(' + (board.reason ?? '无原因') + ')');
128
+ } else {
129
+ const problems = (board.frames ?? []).reduce((total, frame) => total + (frame.problems?.length ?? 0), 0);
130
+ const first = (board.images ?? [])[0];
131
+ lines.push('视觉证据:' + (first ? first.file : '(无图)') + '(' + (board.frames ?? []).length + ' 帧,几何问题 ' + problems + ' 个)');
132
+ }
133
+ } catch { /* 坏文件不影响交付 */ }
134
+ }
135
+ const driftItems = [
136
+ ...capability.map((item) => item.key + '(' + item.change + ')'),
137
+ ...moduleDrift.map((item) => item.key + (item.kind === 'module-removed' ? '(已移除)' : '(新增)')),
138
+ ];
139
+ lines.push(driftItems.length ? '偏离出厂:' + driftItems.join('、') : '偏离出厂:无');
140
+ const changeSummary = Array.isArray(delivery.acceptanceChangeSummary) ? delivery.acceptanceChangeSummary : [];
141
+ lines.push(changeSummary.length ? '验收变更:' + changeSummary.slice(0, 5).join('、') : '验收变更:无');
142
+ const notRunList = [...notRun.map((item) => String(item)), ...deferred.map((item) => item.id + '(' + item.lane + ')')];
143
+ lines.push(notRunList.length ? '未运行:' + notRunList.slice(0, 6).join('、') : '未运行:无');
144
+ lines.push('下一步:' + (summary.next ?? (verdict === 'deliverable' ? '按摘要交付' : '先修失败项')));
145
+
146
+ let text = lines.join('\n');
147
+ if (text.length > 1500) text = text.slice(0, 1450) + '\n…(已截断)';
148
+
149
+ const evidenceDir = path.join(appDir, '.tbox', 'evidence');
150
+ mkdirSync(evidenceDir, { recursive: true });
151
+ const record = {
152
+ schemaVersion: 1,
153
+ generatedAt: new Date().toISOString(),
154
+ verdict,
155
+ policy,
156
+ acceptance,
157
+ capabilityDrift: capability,
158
+ drift,
159
+ notRun: notRunList,
160
+ next: summary.next ?? null,
161
+ source: existsSync(path.join(evidenceDir, 'gate.json')) ? '.tbox/evidence/gate.json' : null,
162
+ };
163
+ writeFileSync(path.join(evidenceDir, 'delivery.json'), JSON.stringify(record, null, 2) + '\n', 'utf8');
164
+ writeFileSync(path.join(appDir, 'DELIVERY.md'), '# 交付摘要\n\n' + lines.map((line) => '- ' + line).join('\n') + '\n\n> 由 pnpm deliver 生成;完整证据在 .tbox/evidence/。\n', 'utf8');
165
+
166
+ if (commitSummary) {
167
+ const staged = spawnSync('git', ['add', 'DELIVERY.md'], { cwd: appDir, encoding: 'utf8' });
168
+ const committed = staged.status === 0
169
+ ? spawnSync('git', ['commit', '-m', 'chore: delivery summary', '--', 'DELIVERY.md'], { cwd: appDir, encoding: 'utf8' })
170
+ : staged;
171
+ if (committed.status !== 0) console.error('(--commit 未完成:' + String(committed.stderr ?? '').trim() + ')');
172
+ else console.error('已提交 DELIVERY.md');
173
+ }
174
+
175
+ if (jsonOutput) {
176
+ console.log(JSON.stringify(record, null, 2));
177
+ console.error(text);
178
+ } else {
179
+ console.log(text);
180
+ }
181
+ if (verdict === 'failing') process.exit(1);
182
+ if (verdict === 'incomplete' || verdict === 'reopened' || verdict === 'unspecified') process.exit(2);
183
+ process.exit(0);
Binary file
@@ -0,0 +1,95 @@
1
+ /**
2
+ * 无头浏览器的 CDP 会话(--remote-debugging-pipe,零 TCP socket)。
3
+ *
4
+ * 壳探针与故事板共用:一次会话里可以连续 eval / 截图;调用方负责 close。
5
+ * 找不到浏览器时返回 null,由调用方记 not-run(CI 无 Chrome 是常态)。
6
+ */
7
+ import { spawn } from 'node:child_process';
8
+ import { existsSync } from 'node:fs';
9
+
10
+ const CANDIDATES = [
11
+ process.env.TBOX_CHROME,
12
+ process.env.AGENT_BROWSER_EXECUTABLE_PATH,
13
+ '/home/admin/.agent-browser/chrome/chrome-linux64/chrome',
14
+ '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
15
+ '/Applications/Chromium.app/Contents/MacOS/Chromium',
16
+ '/usr/bin/google-chrome',
17
+ '/usr/bin/google-chrome-stable',
18
+ '/usr/bin/chromium',
19
+ '/usr/bin/chromium-browser',
20
+ ].filter(Boolean);
21
+
22
+ export function findChrome(candidates = CANDIDATES) {
23
+ return candidates.find((candidate) => existsSync(candidate));
24
+ }
25
+
26
+ /**
27
+ * 打开一个页面会话。
28
+ *
29
+ * @returns {Promise<null | { call(method: string, params?: object, sessionId?: string): Promise<any>,
30
+ * evaluate(expression: string, sessionId?: string): Promise<unknown>,
31
+ * screenshot(sessionId?: string): Promise<Buffer>,
32
+ * version(): Promise<string>, close(): void, sessionId: string, width: number, height: number }>}
33
+ */
34
+ export async function openChromeSession({ chrome, url, width = 390, height = 844, deviceScaleFactor = 2, settleMs = 800, timeoutMs = 15000 }) {
35
+ if (!chrome) return null;
36
+ const child = spawn(chrome, ['--headless=new', '--disable-gpu', '--no-sandbox', '--hide-scrollbars', '--remote-debugging-pipe', 'about:blank'], { stdio: ['ignore', 'ignore', 'pipe', 'pipe', 'pipe'] });
37
+ let buffer = '';
38
+ let nextId = 0;
39
+ const waiters = new Map();
40
+ const fail = (error) => { for (const waiter of waiters.values()) waiter.reject(error); waiters.clear(); };
41
+ child.stdio[4].on('data', (chunk) => {
42
+ buffer += chunk.toString('utf8');
43
+ const parts = buffer.split('\u0000');
44
+ buffer = parts.pop() ?? '';
45
+ for (const part of parts) {
46
+ if (!part.trim()) continue;
47
+ let message;
48
+ try { message = JSON.parse(part); } catch { continue; }
49
+ const waiter = waiters.get(message.id);
50
+ if (waiter) { waiters.delete(message.id); waiter.resolve(message); }
51
+ }
52
+ });
53
+ child.on('error', (error) => fail(error));
54
+
55
+ const call = (method, params, sessionId) => new Promise((resolve, reject) => {
56
+ const id = ++nextId;
57
+ waiters.set(id, { resolve, reject });
58
+ const payload = { id, method, params: params ?? {} };
59
+ if (sessionId) payload.sessionId = sessionId;
60
+ child.stdio[3].write(JSON.stringify(payload) + '\u0000');
61
+ setTimeout(() => { if (waiters.has(id)) { waiters.delete(id); reject(new Error('CDP timeout: ' + method)); } }, timeoutMs);
62
+ });
63
+
64
+ const targets = await call('Target.getTargets');
65
+ const page = (targets.result?.targetInfos ?? []).find((target) => target.type === 'page');
66
+ const attached = await call('Target.attachToTarget', { targetId: page.targetId, flatten: true });
67
+ const sessionId = attached.result.sessionId;
68
+ await call('Emulation.setDeviceMetricsOverride', { width, height, deviceScaleFactor, mobile: true }, sessionId);
69
+ await call('Page.navigate', { url }, sessionId);
70
+ await new Promise((resolve) => setTimeout(resolve, settleMs));
71
+
72
+ return {
73
+ sessionId,
74
+ width,
75
+ height,
76
+ call,
77
+ async evaluate(expression) {
78
+ const evaluated = await call('Runtime.evaluate', { expression, returnByValue: true }, sessionId);
79
+ const failure = evaluated.result.exceptionDetails;
80
+ if (failure) throw new Error('页面脚本异常:' + (failure.exception?.description ?? failure.text ?? '未知'));
81
+ return evaluated.result.result.value;
82
+ },
83
+ async screenshot() {
84
+ const shot = await call('Page.captureScreenshot', { format: 'png', fromSurface: true, captureBeyondViewport: true }, sessionId);
85
+ return Buffer.from(shot.result.data, 'base64');
86
+ },
87
+ async version() {
88
+ const version = await call('Browser.getVersion');
89
+ return version.result.product;
90
+ },
91
+ close() {
92
+ child.kill();
93
+ },
94
+ };
95
+ }