@whyshu/argent-engine 0.7.2 → 0.7.4

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 (57) hide show
  1. package/MANIFEST.json +46 -40
  2. package/engine/VERSION +1 -1
  3. package/engine/scripts/appointment-create.mjs +34 -0
  4. package/engine/scripts/appointment-stop.mjs +18 -0
  5. package/engine/scripts/appointment-worker.mjs +96 -0
  6. package/engine/scripts/appointment_grab.py +327 -0
  7. package/engine/scripts/argent-runner.mjs +223 -0
  8. package/engine/scripts/argent-setup-check.mjs +3 -3
  9. package/engine/scripts/capability-packs.lock.json +34 -40
  10. package/engine/scripts/check-agent-catalog.mjs +1 -1
  11. package/engine/scripts/check-config-catalog.mjs +0 -1
  12. package/engine/scripts/collect-evidence.mjs +2 -5
  13. package/engine/scripts/daily-report.mjs +315 -12
  14. package/engine/scripts/drill-clean-room.sh +45 -0
  15. package/engine/scripts/drill-handover.sh +4 -1
  16. package/engine/scripts/dsh-upgrade.mjs +16 -20
  17. package/engine/scripts/flow-requirements.json +5 -7
  18. package/engine/scripts/flow-timers.sh +1 -1
  19. package/engine/scripts/flow-trigger.sh +1 -1
  20. package/engine/scripts/gen-preset-rows.mjs +20 -0
  21. package/engine/scripts/handover-sheet.mjs +9 -1
  22. package/engine/scripts/invoice_stageb.py +20 -1
  23. package/engine/scripts/lib/agent-install.mjs +10 -1
  24. package/engine/scripts/lib/daily-report-core.mjs +124 -16
  25. package/engine/scripts/lib/dsh-versions.mjs +17 -1
  26. package/engine/scripts/lib/ml-ads-core.mjs +204 -0
  27. package/engine/scripts/lib/plugin-packages.mjs +1 -0
  28. package/engine/scripts/ml-ads.mjs +181 -0
  29. package/engine/scripts/ml-oauth-setup.mjs +1 -1
  30. package/engine/scripts/orchestrator.py +91 -10
  31. package/engine/scripts/p2-report-run.mjs +102 -0
  32. package/engine/scripts/patches/dsh-session--append-message-shape.patch +34 -9
  33. package/engine/scripts/patches/dsh-session-format-v3-to-v4--turn-outside-replace.patch +32 -8
  34. package/engine/scripts/patches/retire-check.sh +0 -4
  35. package/engine/scripts/patches/verify-hardening.mjs +4 -1
  36. package/engine/scripts/patches/verify-turn-outside-replace.mjs +64 -0
  37. package/engine/scripts/poll-fulfillment.sh +1 -1
  38. package/engine/scripts/profile-doctor.mjs +1 -1
  39. package/engine/scripts/python-runtime.sh +16 -4
  40. package/engine/scripts/release-argent.sh +8 -7
  41. package/engine/scripts/session-handoff.mjs +111 -0
  42. package/engine/scripts/session-load-check.mjs +105 -0
  43. package/engine/scripts/sync-scripts.sh +1 -1
  44. package/engine/scripts/xzh-browser.sh +37 -0
  45. package/engine/scripts/xzh_browser.py +49 -0
  46. package/engine/skills/ml-fulfillment-sop/references/pitfalls.md +30 -0
  47. package/engine/skills/ml-full-appointment/SKILL.md +98 -0
  48. package/engine/version.mjs +1 -1
  49. package/package.json +1 -1
  50. package/engine/scripts/drill-clean-machine.sh +0 -315
  51. package/engine/scripts/install-internal-role.sh +0 -190
  52. package/engine/scripts/install-one-shot.mjs +0 -665
  53. package/engine/scripts/patches/dsh-llm-deepseek--transport-diagnostics.patch +0 -297
  54. package/engine/scripts/patches/dsh-session-format-v0-to-v1--permission-preset-origin.patch +0 -11
  55. package/engine/scripts/patches/dsh-session-persistence-jsonl--worker-bundled-migrators.patch +0 -39
  56. package/engine/scripts/patches/verify-bundled-migrators.mjs +0 -79
  57. package/engine/scripts/patches/verify-transport-diagnostics.mjs +0 -227
@@ -15,6 +15,7 @@
15
15
  * node daily-report.mjs --force # 跳过时间门控立即推送(成功后写幂等标记)
16
16
  * node daily-report.mjs --force --no-mark # 测试/验证:强制推送但不写幂等标记(不挡当晚定时推送)
17
17
  * node daily-report.mjs --date 2026-08-20 # 指定日报日期(默认各店本地昨日)
18
+ * node daily-report.mjs --date 2026-08-20 --as-of 2026-08-21T12:00:00Z # 回放:把"现在"也钉住(单日窗口验收用)
18
19
  * node daily-report.mjs --env <env 文件路径> # 默认 ~/.dsh/argent/daily-report.env
19
20
  * node daily-report.mjs --mock <fixture.json> # 开发自测:跳过联网,仅渲染/打印
20
21
  *
@@ -39,8 +40,11 @@ import {
39
40
  aggregateOrders, reportWindows, windowInfo, capturedAtInfo, captureNoteLines,
40
41
  matchStores, storeKey,
41
42
  localDateStr, tzOffsetMs, startOfLocalDayUTC, localHour,
42
- apiGet as coreApiGet, fetchOrders as coreFetchOrders, refreshStoreToken as coreRefreshStoreToken,
43
+ apiGet as coreApiGet, fetchOrders as coreFetchOrders, fetchOrdersWithMeta as coreFetchOrdersWithMeta, refreshStoreToken as coreRefreshStoreToken,
43
44
  } from './lib/daily-report-core.mjs'
45
+ // 广告(Product Ads)只读取数/聚合/告警:与 `scripts/ml-ads.mjs` 共用同一份实现
46
+ // (⛔ 不在两处各写一份口径;2026-10-17 新增,默认关,客户开广告权限后再启用 `ads.summary`)
47
+ import { fetchAdsReport, adsCardLines } from './lib/ml-ads-core.mjs'
44
48
 
45
49
  // 逐字转出(既有调用方/单测 import 路径不变;同一绑定 ⇒ `M.aggregateOrders === core.aggregateOrders`)
46
50
  export { aggregateOrders, localDateStr, tzOffsetMs, startOfLocalDayUTC, localHour, loadEnvFile }
@@ -83,7 +87,15 @@ const FLAG_FORCE = args.includes('--force')
83
87
  // KB-074:测试/验证用——推送成功后不写幂等标记(手动 --force 不挡当晚定时推送)
84
88
  const FLAG_NO_MARK = args.includes('--no-mark')
85
89
  const FLAG_JSON = args.includes('--json') // KB-063:只输出日报卡片 JSON(BOT 回复卡片用),不推送
90
+ // 防呆(2026-10-18 真实事故):`--dry` 不是合法 flag(正确是 `--dry-run`),此前被静默忽略 ⇒ 回放时误推送。
91
+ if (args.includes('--dry')) {
92
+ console.error('✗ 未知参数 --dry:dry-run 的正确写法是 `--dry-run`;本次不执行(避免误推送)')
93
+ process.exit(2)
94
+ }
86
95
  const ARG_DATE = argVal('--date')
96
+ // 回放验收(2026-10-18):`--date` 只移动报告日,`todayStart` 仍取"今天" ⇒ 历史重放会跨多日。
97
+ // `--as-of` 把"现在"也钉住,窗口才真正是那一天(只影响窗口/抓取时刻,不改变真实推送时刻判定——配合 --force)。
98
+ const ARG_ASOF = argVal('--as-of')
87
99
  const FLAG_LIST_SECTIONS = args.includes('--list-sections')
88
100
  const FLAG_LIST_STORES = args.includes('--list-stores')
89
101
  const ARG_STORE = (argVal('--store') || '').split(',').map((x) => x.trim()).filter(Boolean)
@@ -421,6 +433,16 @@ export const SECTIONS = [
421
433
  return out
422
434
  },
423
435
  },
436
+ {
437
+ id: 'ads.summary', group: 'ads', title: '广告(Product Ads)', needs: ['ads'],
438
+ cost: { requests: '按活动数(分页累加)' }, cadence: 'daily', default: false,
439
+ render: ({ d, store }) => {
440
+ const ads = d && d.ads
441
+ const errs = (d && d.__errors) || {}
442
+ if (!ads) return errs.ads ? [`**📣 广告**:未取到(${errs.ads})`] : null
443
+ return adsCardLines(ads, { currency: SITE_CURRENCY[fallbackSite(store.site)] || '', alertOpts: {} })
444
+ },
445
+ },
424
446
  {
425
447
  id: 'ops.restock', group: 'ops', title: '补货提醒', needs: ['orders', 'items'], cost: { requests: 0 },
426
448
  cadence: 'daily', default: true,
@@ -587,6 +609,162 @@ export function buildOverviewBlocks(dateLabel, items) {
587
609
  return { head: lines, risk: [], groups: [] }
588
610
  }
589
611
 
612
+ // ── 表格化日报(飞书表格式摘要卡 + ERP 完整日报页)────────
613
+ const REPORT_METRIC_DEFS = [
614
+ { key: 'gmv', label: 'GMV', kind: 'money' },
615
+ { key: 'orders', label: '订单', kind: 'int' },
616
+ { key: 'units', label: '件数', kind: 'int' },
617
+ { key: 'avg', label: '客单价', kind: 'int' },
618
+ { key: 'cancelled', label: '取消', kind: 'int' },
619
+ ]
620
+
621
+ function fmtNum(n) { return n == null || !Number.isFinite(Number(n)) ? '—' : Math.round(Number(n)).toLocaleString('en-US') }
622
+ function fmtMoney(code, n) { return n == null || !Number.isFinite(Number(n)) ? '—' : `${code} ${fmtNum(n)}` }
623
+ function fmtDelta(cur, prev) {
624
+ if (cur == null || prev == null || !Number.isFinite(Number(cur)) || !Number.isFinite(Number(prev)) || Number(prev) === 0) return '—'
625
+ const p = Math.round(((Number(cur) - Number(prev)) / Number(prev)) * 100)
626
+ return `${p > 0 ? '↗ +' : p < 0 ? '↘ ' : '→ '}${p}%`
627
+ }
628
+ function metricValue(store, key, src) {
629
+ const m = store.metrics && store.metrics[key]
630
+ if (!m) return null
631
+ return m[src] == null ? null : m[src]
632
+ }
633
+
634
+ /** 把当日采集结果整理成“所有日报数据”的结构化表(ERP 页与飞书表卡共用)。 */
635
+ export function buildReportPayload({ dateLabel, blocksList = [], failed = [] }) {
636
+ const stores = blocksList.map(({ store, r, blocks }) => {
637
+ const cur = r.summary || {}
638
+ const cmp = r.comparisons || {}
639
+ const comp = (key, metric) => {
640
+ const c = cmp[metric] || {}
641
+ return c[key] == null ? null : c[key]
642
+ }
643
+ const metrics = {
644
+ gmv: { current: cur.gmv, prevDay: comp('gmv', 'prevDay'), prevWeek: comp('gmv', 'prevWeek'), prevMonth: comp('gmv', 'prevMonth') },
645
+ orders: { current: cur.orders, prevDay: comp('orders', 'prevDay'), prevWeek: comp('orders', 'prevWeek'), prevMonth: comp('orders', 'prevMonth') },
646
+ units: { current: cur.units, prevDay: comp('units', 'prevDay'), prevWeek: comp('units', 'prevWeek'), prevMonth: comp('units', 'prevMonth') },
647
+ avg: { current: cur.avg, prevDay: comp('avg', 'prevDay'), prevWeek: comp('avg', 'prevWeek'), prevMonth: comp('avg', 'prevMonth') },
648
+ cancelled: { current: cur.cancelled, prevDay: comp('cancelled', 'prevDay'), prevWeek: comp('cancelled', 'prevWeek'), prevMonth: comp('cancelled', 'prevMonth') },
649
+ }
650
+ return {
651
+ name: store.name,
652
+ site: store.site,
653
+ currency: SITE_CURRENCY[store.site] || 'USD',
654
+ summary: cur,
655
+ comparisons: cmp,
656
+ metrics,
657
+ top: (r.top || []).map((x) => ({
658
+ sku: x.sku || '', title: x.title || '', units7: x.units7 ?? null, gmv7: x.gmv7 ?? null,
659
+ avail: x.avail ?? null, sold: x.sold ?? null, daysLeft: x.days ?? x.daysLeft ?? null,
660
+ })),
661
+ alerts: (r.alerts || []).map((x) => ({
662
+ sku: x.sku || '', title: x.title || '', avail: x.avail ?? null, units7: x.units7 ?? null,
663
+ daysLeft: x.days ?? x.daysLeft ?? null,
664
+ })),
665
+ risk: blocks && blocks.risk ? blocks.risk : [],
666
+ sections: blocks
667
+ ? [
668
+ ...(blocks.head && blocks.head.length ? [{ group: 'head', label: '店铺', lines: blocks.head }] : []),
669
+ ...(blocks.risk && blocks.risk.length ? [{ group: 'risk', label: '风险与待办', lines: blocks.risk }] : []),
670
+ ...(blocks.groups || []).map((g) => ({ group: g.group, label: GROUP_LABEL[g.group] || g.group, lines: g.lines })),
671
+ ]
672
+ : [],
673
+ error: r.error || '',
674
+ }
675
+ })
676
+ const sumBy = (key, src) => stores.reduce((a, x) => {
677
+ const v = metricValue(x, key, src)
678
+ return v == null ? a : a + Number(v)
679
+ }, 0)
680
+ const totals = {}
681
+ for (const def of REPORT_METRIC_DEFS) {
682
+ if (def.key === 'avg') {
683
+ const calc = (src) => {
684
+ const orders = sumBy('orders', src)
685
+ return orders > 0 ? sumBy('gmv', src) / orders : null
686
+ }
687
+ totals.avg = { current: calc('current'), prevDay: calc('prevDay'), prevWeek: calc('prevWeek'), prevMonth: calc('prevMonth') }
688
+ } else {
689
+ totals[def.key] = {
690
+ current: sumBy(def.key, 'current'), prevDay: sumBy(def.key, 'prevDay'),
691
+ prevWeek: sumBy(def.key, 'prevWeek'), prevMonth: sumBy(def.key, 'prevMonth'),
692
+ }
693
+ }
694
+ }
695
+ return {
696
+ date: dateLabel,
697
+ generatedAt: new Date().toISOString(),
698
+ stores,
699
+ totals,
700
+ failed: failed.map((f) => ({ name: f.store.name, error: f.r.error || '未知错误' })),
701
+ labels: {
702
+ prevDay: (stores[0] && stores[0].comparisons && stores[0].comparisons.labels && stores[0].comparisons.labels.prevDay) || '前一日',
703
+ prevWeek: (stores[0] && stores[0].comparisons && stores[0].comparisons.labels && stores[0].comparisons.labels.prevWeek) || '上周同期',
704
+ prevMonth: (stores[0] && stores[0].comparisons && stores[0].comparisons.labels && stores[0].comparisons.labels.prevMonth) || '上月同期',
705
+ },
706
+ }
707
+ }
708
+
709
+ /** 飞书表格式摘要卡:跨店表 + 核心指标对比表 + “查看完整日报”按钮。 */
710
+ export function buildTableCard(payload) {
711
+ const stores = payload.stores || []
712
+ const overviewColumns = [
713
+ { name: 'store', display_name: '店铺', data_type: 'text', width: '120px', horizontal_align: 'left' },
714
+ { name: 'gmv', display_name: '昨日 GMV', data_type: 'text', width: '100px' },
715
+ { name: 'orders', display_name: '订单', data_type: 'text', width: '80px' },
716
+ { name: 'units', display_name: '件数', data_type: 'text', width: '80px' },
717
+ { name: 'avg', display_name: '客单价', data_type: 'text', width: '80px' },
718
+ { name: 'cancel', display_name: '取消', data_type: 'text', width: '80px' },
719
+ { name: 'd1', display_name: '较前日', data_type: 'text', width: '80px' },
720
+ { name: 'd7', display_name: '较上周', data_type: 'text', width: '80px' },
721
+ { name: 'd30', display_name: '较上月', data_type: 'text', width: '80px' },
722
+ ]
723
+ const overviewRows = stores.slice(0, 10).map((x) => ({
724
+ store: x.name,
725
+ gmv: fmtMoney(x.currency, metricValue(x, 'gmv', 'current')),
726
+ orders: fmtNum(metricValue(x, 'orders', 'current')),
727
+ units: fmtNum(metricValue(x, 'units', 'current')),
728
+ avg: fmtNum(metricValue(x, 'avg', 'current')),
729
+ cancel: fmtNum(metricValue(x, 'cancelled', 'current')),
730
+ d1: fmtDelta(metricValue(x, 'gmv', 'current'), metricValue(x, 'gmv', 'prevDay')),
731
+ d7: fmtDelta(metricValue(x, 'gmv', 'current'), metricValue(x, 'gmv', 'prevWeek')),
732
+ d30: fmtDelta(metricValue(x, 'gmv', 'current'), metricValue(x, 'gmv', 'prevMonth')),
733
+ }))
734
+ const totalColumns = [
735
+ { name: 'k', display_name: '指标', data_type: 'text', width: '100px', horizontal_align: 'left' },
736
+ { name: 'cur', display_name: '昨日', data_type: 'text', width: '110px' },
737
+ { name: 'd1', display_name: '前一日', data_type: 'text', width: '110px' },
738
+ { name: 'd7', display_name: '上周同期', data_type: 'text', width: '110px' },
739
+ { name: 'd30', display_name: '上月同期', data_type: 'text', width: '110px' },
740
+ ]
741
+ // GMV 不能跨币种直接相加(MXN/BRL/ARS 混在一起是错数);总览只放计数指标,
742
+ // 各币种 GMV 已经在跨店表内逐店显示,完整明细看 ERP。
743
+ const totalRows = [
744
+ { k: '订单', cur: fmtNum(payload.totals?.orders?.current), d1: fmtNum(payload.totals?.orders?.prevDay), d7: fmtNum(payload.totals?.orders?.prevWeek), d30: fmtNum(payload.totals?.orders?.prevMonth) },
745
+ { k: '件数', cur: fmtNum(payload.totals?.units?.current), d1: fmtNum(payload.totals?.units?.prevDay), d7: fmtNum(payload.totals?.units?.prevWeek), d30: fmtNum(payload.totals?.units?.prevMonth) },
746
+ { k: '取消', cur: fmtNum(payload.totals?.cancelled?.current), d1: fmtNum(payload.totals?.cancelled?.prevDay), d7: fmtNum(payload.totals?.cancelled?.prevWeek), d30: fmtNum(payload.totals?.cancelled?.prevMonth) },
747
+ ]
748
+ const url = process.env.ML_ERP_REPORT_URL || 'https://whyshu.com/admin/argent/#/reports'
749
+ const elements = [
750
+ { tag: 'markdown', content: `**跨店总览** · 昨日 / 前一日 / 上周同期 / 上月同期对比(完整数据点下方按钮)` },
751
+ { tag: 'table', page_size: 10, row_height: 'low', freeze_first_column: true, header_style: { bold: true, background_style: 'grey' }, columns: overviewColumns, rows: overviewRows },
752
+ { tag: 'markdown', content: `**核心指标对比**` },
753
+ { tag: 'table', page_size: 5, row_height: 'low', header_style: { bold: true, background_style: 'grey' }, columns: totalColumns, rows: totalRows },
754
+ ]
755
+ if ((payload.failed || []).length) elements.push({ tag: 'markdown', content: `⚠️ 数据缺失:${payload.failed.map((x) => `${x.name}(${x.error})`).join(';')}` })
756
+ elements.push({ tag: 'button', text: { tag: 'plain_text', content: '查看完整日报' }, type: 'primary_filled', width: 'fill', behaviors: [{ type: 'open_url', default_url: url }] })
757
+ return {
758
+ msg_type: 'interactive',
759
+ card: {
760
+ schema: '2.0',
761
+ config: { wide_screen_mode: true },
762
+ header: { template: (payload.failed || []).length ? 'yellow' : 'blue', title: { tag: 'plain_text', content: `📊 美客多日报 · ${payload.date}|表格摘要` } },
763
+ body: { elements },
764
+ },
765
+ }
766
+ }
767
+
590
768
  // 超长内容分段(飞书卡片 markdown 元素单段上限保守取 3000 字符)
591
769
  export function chunkText(text, size = 3000) {
592
770
  const out = []
@@ -618,6 +796,16 @@ export function buildCardPayload(title, sections) {
618
796
  }
619
797
  }
620
798
 
799
+ /** 订单采集不完整时的卡片警告(成功/老快照 ⇒ null,卡片字节不变)。 */
800
+ export function orderIncompleteWarning(r) {
801
+ const of = r && r.raw && r.raw.orderFetch
802
+ if (!of || of.complete !== false) return null
803
+ const parts = []
804
+ if (of.week && of.week.got < of.week.total) parts.push(`本周窗口 ${of.week.got}/${of.week.total}`)
805
+ if (of.prev && of.prev.got < of.prev.total) parts.push(`环比窗口 ${of.prev.got}/${of.prev.total}`)
806
+ return `⚠️ **订单采集不完整**(${parts.join(',') || '分页未取全'})—— 昨日与榜单偏低,勿直接采信`
807
+ }
808
+
621
809
  // ── 网络层:共用取数实现(本文件只注入 API 基址;实现见 lib/daily-report-core.mjs)──
622
810
  // `apiGet` / `fetchOrders` / `refreshStoreToken` 的**判断**(429 退避、token 复用 15min 阈值、
623
811
  // 轮换写回)全在共用实现里 —— 两个 CLI 一份实现,⛔ 不再有第二份。这里只做一件事:
@@ -634,6 +822,11 @@ async function fetchOrders(token, sellerId, fromISO, toISO) {
634
822
  return coreFetchOrders(token, sellerId, fromISO, toISO, { base: apiBase() })
635
823
  }
636
824
 
825
+ // P0(2026-10-18):日报要拿到「订单采集是否完整」——超限窗口按整点二分取全量,不再静默截断。
826
+ async function fetchOrdersWithMeta(token, sellerId, fromISO, toISO) {
827
+ return coreFetchOrdersWithMeta(token, sellerId, fromISO, toISO, { base: apiBase() })
828
+ }
829
+
637
830
  async function fetchItems(token, userId) {
638
831
  const map = {}
639
832
  const ids = []
@@ -793,6 +986,29 @@ function pushLarkCard(card, chatId, profile) {
793
986
  }
794
987
  }
795
988
 
989
+ /** 上传结构化日报到 ERP(bridge secret;失败不阻断群推送,ERP 页显示上一份)。 */
990
+ async function publishReportPayload(payload, env) {
991
+ try {
992
+ const secret = process.env.DAILY_REPORT_BRIDGE_SECRET || (() => {
993
+ try { return readFileSync(join(DATA_DIR, 'appointment-bridge.secret'), 'utf8').trim() } catch { return '' }
994
+ })()
995
+ if (!secret) return false
996
+ const base = (process.env.ARGENT_API_BASE || 'https://whyshu.com/api/argent/v1').replace(/\/+$/, '')
997
+ const appId = process.env.ARGENT_TENANT_APP_ID || 'ly-0001'
998
+ const res = await fetch(`${base}/tenants/${appId}/reports/daily/bridge`, {
999
+ method: 'POST',
1000
+ headers: { 'x-appointment-secret': secret, 'content-type': 'application/json' },
1001
+ body: JSON.stringify({ reportDate: payload.date, payload }),
1002
+ signal: AbortSignal.timeout(30000),
1003
+ })
1004
+ if (!res.ok) throw new Error(`HTTP ${res.status}`)
1005
+ return true
1006
+ } catch (e) {
1007
+ console.error(`[daily-report] ⚠️ ERP 日报上传失败(群推送继续):${String(e && e.message || e).slice(0, 180)}`)
1008
+ return false
1009
+ }
1010
+ }
1011
+
796
1012
  async function pushCards(env, cards, overview) {
797
1013
  const cfg = larkConfig()
798
1014
  const chatId = pick(cfg, env, 'mlDailyChatId', 'ML_DAILY_CHAT_ID', ML_DAILY_CHAT_ID)
@@ -983,6 +1199,23 @@ async function collectPriceToWin(token, ids, gapMs = 100) {
983
1199
  }
984
1200
 
985
1201
  /** 按"已启用分区的 needs 并集"取数;返回 { reputation, claims, questions, sla } 中真正需要的项。 */
1202
+ // ── 广告采集(Product Ads)────────────────────────────────
1203
+ // 窗口:**近 7 个完整自然日**(站点本地,截止到昨天),与 `ml-ads.mjs` 默认窗口一致。
1204
+ // 结构:广告主 → campaign 逐页累加(`metrics_summary` 只汇总返回条目,⛔ 不能当总额)。
1205
+ async function collectAds(env, store, token) {
1206
+ const site = fallbackSite(store.site)
1207
+ const tz = SITE_TZ[site]
1208
+ const now = new Date()
1209
+ const todayStart = startOfLocalDayUTC(tz, now)
1210
+ const toMs = todayStart - 86400000
1211
+ const fromMs = toMs - 6 * 86400000
1212
+ return fetchAdsReport({
1213
+ apiGet, token, site,
1214
+ dateFrom: localDateStr(tz, new Date(fromMs)),
1215
+ dateTo: localDateStr(tz, new Date(toMs)),
1216
+ })
1217
+ }
1218
+
986
1219
  async function collectExtras(env, store, token, need, ctx) {
987
1220
  const cfg = larkConfig()
988
1221
  const want = (n) => need.has(n)
@@ -1005,6 +1238,7 @@ async function collectExtras(env, store, token, need, ctx) {
1005
1238
  }
1006
1239
  if (want('priceToWin')) jobs.push(run('price', collectPriceToWin(token, ranked.slice(0, topN))))
1007
1240
  }
1241
+ if (want('ads')) jobs.push(run('ads', collectAds(env, store, token)))
1008
1242
  if (want('shipments')) {
1009
1243
  const windowDays = Number(pick(cfg, env, 'mlSlaWindowDays', 'ML_SLA_WINDOW_DAYS', 2))
1010
1244
  const cap = Number(pick(cfg, env, 'mlSlaMaxChecks', 'ML_SLA_MAX_CHECKS', 300))
@@ -1014,19 +1248,72 @@ async function collectExtras(env, store, token, need, ctx) {
1014
1248
  return out
1015
1249
  }
1016
1250
 
1251
+ /** 单日汇总(用于前一日/上周同期/上月同期对比;只拉一个自然日,成本可控)。 */
1252
+ async function daySummary(token, userId, startMs, itemById, site) {
1253
+ const dayMs = 86400000
1254
+ const f = await fetchOrdersWithMeta(token, userId, new Date(startMs).toISOString(), new Date(startMs + dayMs).toISOString())
1255
+ const { summary } = aggregateOrders(f.orders, itemById, { weekStartMs: startMs, reportStartMs: startMs, todayStartMs: startMs + dayMs }, site)
1256
+ return { ...summary, complete: Boolean(f.complete), got: f.got ?? null, total: f.total ?? null }
1257
+ }
1258
+
1259
+ /** 报告日往前一个月的“同一天”(站点本地日期;优先返回该日期 12:00 UTC 的 Date 供 startOfLocalDayUTC 使用)。 */
1260
+ function sameDayPrevMonth(tz, reportDate) {
1261
+ const [y, m, d] = localDateStr(tz, reportDate).split('-').map(Number)
1262
+ const first = new Date(Date.UTC(y, m - 2, 1, 12)) // 上个月 1 日
1263
+ const days = new Date(Date.UTC(first.getUTCFullYear(), first.getUTCMonth() + 1, 0)).getUTCDate()
1264
+ first.setUTCDate(Math.min(d, days))
1265
+ return first
1266
+ }
1267
+
1017
1268
  async function collectStore(env, store, now, reportDate, opts = {}) {
1018
1269
  // 窗口计算(站点本地自然日 + 近 7 日)与抓取时刻:共用实现(对账 CLI 用同一份口径)
1019
1270
  const { site, tz, weekStart, reportStart, todayStart, prevStart } =
1020
1271
  reportWindows(store.site, reportDate, now, { salesWindowDays: env.SALES_WINDOW_DAYS })
1021
1272
  const token = await refreshStoreToken(env, store)
1022
1273
  const needPrev = (opts.need || new Set()).has('ordersPrev')
1023
- const [orders, itemsRes, prevOrders] = await Promise.all([
1024
- fetchOrders(token, store.user_id, new Date(weekStart).toISOString(), new Date(todayStart).toISOString()),
1274
+ const [weekFetch, itemsRes, prevFetch] = await Promise.all([
1275
+ fetchOrdersWithMeta(token, store.user_id, new Date(weekStart).toISOString(), new Date(todayStart).toISOString()),
1025
1276
  fetchItems(token, store.user_id),
1026
- needPrev ? fetchOrders(token, store.user_id, new Date(prevStart).toISOString(), new Date(weekStart).toISOString()) : Promise.resolve(null),
1277
+ needPrev ? fetchOrdersWithMeta(token, store.user_id, new Date(prevStart).toISOString(), new Date(weekStart).toISOString()) : Promise.resolve(null),
1027
1278
  ])
1279
+ const orders = weekFetch.orders
1280
+ const prevOrders = prevFetch ? prevFetch.orders : null
1281
+ const fetchMetaOf = (m) => (m ? { total: m.total, got: m.got, complete: m.complete, windows: m.windows.length, reason: m.reason } : null)
1282
+ const orderFetch = { complete: weekFetch.complete && (!prevFetch || prevFetch.complete), week: fetchMetaOf(weekFetch), prev: fetchMetaOf(prevFetch) }
1283
+ if (!orderFetch.complete) {
1284
+ const parts = []
1285
+ if (!weekFetch.complete) parts.push(`本周窗口 ${weekFetch.got}/${weekFetch.total}(${weekFetch.reason})`)
1286
+ if (prevFetch && !prevFetch.complete) parts.push(`环比窗口 ${prevFetch.got}/${prevFetch.total}(${prevFetch.reason})`)
1287
+ console.error(`[daily-report] ⚠️ ${store.name} 订单采集不完整:${parts.join(',')} —— 昨日与榜单会偏低`)
1288
+ }
1028
1289
  const itemById = itemsRes.map // fetchItems 现在返回 {map,total,failed}
1029
1290
  const windows = { weekStartMs: weekStart, reportStartMs: reportStart, todayStartMs: todayStart }
1291
+ // 表格卡/ERP 日报页需要:前一日、上周同期(-7 天)、上月同期(上个月同一天)。
1292
+ // 只增加两个单日窗口请求;失败不阻断主流程(缺对比显示 —)。
1293
+ let comparisons = null
1294
+ if (opts.comparisons !== false && process.env.ML_DAILY_COMPARISONS !== '0') {
1295
+ const dayMs = 86400000
1296
+ const prevDayStart = reportStart - dayMs
1297
+ const prevWeekStart = startOfLocalDayUTC(tz, new Date(reportDate.getTime() - 7 * dayMs))
1298
+ const prevMonthStart = startOfLocalDayUTC(tz, sameDayPrevMonth(tz, reportDate))
1299
+ try {
1300
+ const [prevDay, prevWeek, prevMonth] = await Promise.all([
1301
+ daySummary(token, store.user_id, prevDayStart, itemById, site),
1302
+ daySummary(token, store.user_id, prevWeekStart, itemById, site),
1303
+ daySummary(token, store.user_id, prevMonthStart, itemById, site),
1304
+ ])
1305
+ comparisons = {
1306
+ prevDay, prevWeek, prevMonth,
1307
+ labels: {
1308
+ prevDay: localDateStr(tz, new Date(prevDayStart)),
1309
+ prevWeek: localDateStr(tz, new Date(prevWeekStart)),
1310
+ prevMonth: localDateStr(tz, new Date(prevMonthStart)),
1311
+ },
1312
+ }
1313
+ } catch (e) {
1314
+ comparisons = { error: String(e && e.message || e).slice(0, 120) }
1315
+ }
1316
+ }
1030
1317
  const { summary, skus, daily, buyers } = aggregateOrders(orders, itemById, windows, site)
1031
1318
  let prevSkus = null
1032
1319
  if (prevOrders) {
@@ -1060,6 +1347,7 @@ async function collectStore(env, store, now, reportDate, opts = {}) {
1060
1347
  alerts,
1061
1348
  threshold,
1062
1349
  prev,
1350
+ comparisons,
1063
1351
  daily,
1064
1352
  buyers,
1065
1353
  prevSkus,
@@ -1071,7 +1359,7 @@ async function collectStore(env, store, now, reportDate, opts = {}) {
1071
1359
  })),
1072
1360
  itemLogistics: Object.fromEntries(Object.entries(itemById).map(([id, it]) => [id, (it && it.shipping && it.shipping.logistic_type) || ''])),
1073
1361
  data,
1074
- raw: { skuCount: skus.length, orderCount: orders.length },
1362
+ raw: { skuCount: skus.length, orderCount: orders.length, orderFetch },
1075
1363
  }
1076
1364
  }
1077
1365
 
@@ -1126,7 +1414,8 @@ async function main() {
1126
1414
  console.error(`[daily-report] 启用分区 ${enabled.size}/${SECTIONS.length}:${[...enabled].join(', ')}`
1127
1415
  + (cadence.cached.size ? `|周更(用缓存,不取数):${[...cadence.cached].join(', ')}` : '')
1128
1416
  + `|数据需求:${[...need].join(', ')}`)
1129
- const now = new Date()
1417
+ const now = ARG_ASOF ? new Date(ARG_ASOF) : new Date()
1418
+ if (ARG_ASOF && Number.isNaN(now.getTime())) { console.error(`✗ --as-of 解析失败:${ARG_ASOF}`); return 1 }
1130
1419
  const reportTime = pick(cfg, env, 'mlDailyTime', 'REPORT_TIME', '08:00')
1131
1420
 
1132
1421
  if (MOCK_FILE) {
@@ -1188,7 +1477,7 @@ async function main() {
1188
1477
  try {
1189
1478
  console.error(`[daily-report] 采集 ${store.name}(${store.site})...`) // stderr:--json 模式下 stdout 保持纯 JSON
1190
1479
  const r = await collectStore(env, store, now, reportDate, { enabled, need })
1191
- saveSnapshot(r, store)
1480
+ if (!FLAG_DRY) saveSnapshot(r, store) // 回放/预览不落盘(⛔ 不覆盖生产快照)
1192
1481
  reports.push({ store, r })
1193
1482
  } catch (err) {
1194
1483
  console.error(`✗ 采集 ${store.name}(${store.site})失败:${err.message}`)
@@ -1216,7 +1505,7 @@ async function main() {
1216
1505
  }
1217
1506
  return { store, r, blocks: renderStoreBlocks(store, r, topN, r.threshold, enabled, { cached: cadence.cached, onWeeklyRendered }) }
1218
1507
  })
1219
- if (cadence.active.size) saveSectionCache(sectionCache) // 只有真算过周更分区才写缓存
1508
+ if (cadence.active.size && !FLAG_DRY) saveSectionCache(sectionCache) // dry-run 不写缓存
1220
1509
  const dateLabel = okReports[0].r.date
1221
1510
  // 按需问答(给了 --sections / --store)时,标题要能一眼看出"这是什么范围的数据",
1222
1511
  // 而不是让人以为又是一份完整日报(2026-09-27 第 4 批)。
@@ -1249,6 +1538,12 @@ async function main() {
1249
1538
  for (const g of blocks.groups) elements.push(collapsiblePanel(g.group, g.lines))
1250
1539
  }
1251
1540
  if (failed.length) elements.push({ tag: 'markdown', content: `⚠️ **数据缺失**:${failed.map((f) => `${f.store.name}(${f.r.error || '未知错误'})`).join(';')}` })
1541
+ const payload = buildReportPayload({ dateLabel, blocksList, failed })
1542
+ const useTable = pick(cfg, env, 'mlDailyTableCard', 'ML_DAILY_TABLE_CARD', 'true') !== 'false'
1543
+ if (useTable) {
1544
+ console.log(JSON.stringify(buildTableCard(payload)))
1545
+ return 0
1546
+ }
1252
1547
  const card = { schema: '2.0', config: { wide_screen_mode: true },
1253
1548
  header: { template: riskLevel(blocksList[0].blocks), title: { tag: 'plain_text', content: title } },
1254
1549
  body: { elements } }
@@ -1264,10 +1559,18 @@ async function main() {
1264
1559
  }
1265
1560
 
1266
1561
  try {
1267
- const cards = blocksList.map(({ store, blocks }) =>
1268
- cardMessageV2(`📊 美客多日报 · ${dateLabel}|${store.name}`, blocks, { template: riskLevel(blocks) }))
1562
+ const payload = buildReportPayload({ dateLabel, blocksList, failed })
1563
+ // ERP 完整日报先上传;失败只告警,不阻断群推送
1564
+ if (pick(cfg, env, 'mlDailyUploadErp', 'ML_DAILY_UPLOAD_ERP', 'true') !== 'false') {
1565
+ await publishReportPayload(payload, env)
1566
+ }
1567
+ const useTable = pick(cfg, env, 'mlDailyTableCard', 'ML_DAILY_TABLE_CARD', 'true') !== 'false'
1568
+ let cards = useTable
1569
+ ? [buildTableCard(payload)]
1570
+ : blocksList.map(({ store, blocks }) =>
1571
+ cardMessageV2(`📊 美客多日报 · ${dateLabel}|${store.name}`, blocks, { template: riskLevel(blocks) }))
1269
1572
  let overview = null
1270
- const wantOverview = pick(cfg, env, 'mlOverviewCard', 'ML_OVERVIEW_CARD', 'true') !== 'false'
1573
+ const wantOverview = !useTable && pick(cfg, env, 'mlOverviewCard', 'ML_OVERVIEW_CARD', 'true') !== 'false'
1271
1574
  if (wantOverview && blocksList.length > 1) {
1272
1575
  const items = blocksList.map(({ store, r, blocks }) => {
1273
1576
  const riskLine = (blocks.risk.find((l) => l.includes('待办')) || '').replace(/\*\*/g, '').slice(0, 60)
@@ -1277,7 +1580,7 @@ async function main() {
1277
1580
  overview = cardMessageV2(`📊 美客多日报 · ${dateLabel}|跨店总览`, buildOverviewBlocks(dateLabel, items),
1278
1581
  { template: items.some((x) => x.level === 'red') ? 'red' : items.some((x) => x.level === 'yellow') ? 'yellow' : 'green' })
1279
1582
  }
1280
- if (failed.length) {
1583
+ if (failed.length && !useTable) {
1281
1584
  cards.push(cardMessageV2(`⚠️ 美客多日报 · ${dateLabel}|部分店铺未取到`, {
1282
1585
  head: [`**以下店铺本轮采集失败**(其余店铺正常)`, ''],
1283
1586
  risk: failed.map((f) => `🔴 **${f.store.name}**:${f.r.error || '未知错误'}`),
@@ -28,6 +28,51 @@ ok "$($BIN events list --profile u1 --json 2>&1 | grep -q '"count"' && echo 1 ||
28
28
  printf '%s\n' '{"jsonrpc":"2.0","id":1,"method":"initialize"}' '{"jsonrpc":"2.0","id":2,"method":"tools/list"}' > "$D/req.jsonl"
29
29
  MC=$($BIN mcp < "$D/req.jsonl" 2>/dev/null | tail -1)
30
30
  ok "$(echo "$MC" | python3 -c 'import json,sys;d=json.load(sys.stdin);sys.exit(0 if len(d.get("result",{}).get("tools",[]))>=5 else 1)' 2>/dev/null && echo 1 || echo 0)" "MCP:initialize + tools/list ≥5 个工具"
31
+ # ── 卸载(0.7.0 后续):⛔ 只在**临时 HOME** 上跑,绝不动真实安装/真实数据目录 ──
32
+ UH=$(mktemp -d); mkdir -p "$UH/.argent/profiles/ml" "$UH/Library/LaunchAgents"
33
+ printf '{"whyshuToken":"x"}' > "$UH/.argent/credentials.json"
34
+ printf '<plist/>' > "$UH/Library/LaunchAgents/com.whyshu.argent-x.plist"
35
+ DRY=$(HOME="$UH" ARGENT_DATA_DIR="$UH/.argent" $BIN uninstall --json 2>&1)
36
+ ok "$(echo "$DRY" | grep -qE '"dryRun"[[:space:]]*:[[:space:]]*true' && echo "$DRY" | grep -q '"data-dir"' && echo 1 || echo 0)" "卸载:默认**干跑**(--json 报 dryRun=true 且列出数据目录)"
37
+ ok "$([ -e "$UH/.argent/credentials.json" ] && [ -e "$UH/Library/LaunchAgents/com.whyshu.argent-x.plist" ] && echo 1 || echo 0)" "卸载:干跑后**零删除**(数据目录与 plist 仍在)"
38
+ HOME="$UH" ARGENT_DATA_DIR="$UH/.argent" $BIN uninstall --apply --yes >/dev/null 2>&1 || true
39
+ ok "$([ ! -e "$UH/.argent" ] && [ ! -e "$UH/Library/LaunchAgents/com.whyshu.argent-x.plist" ] && echo 1 || echo 0)" "卸载:--apply --yes ⇒ 数据目录与自启项**删净**"
40
+ UBK=$(ls "$UH"/argent-uninstall-backup-*.tgz 2>/dev/null | head -1)
41
+ ok "$([ -n "$UBK" ] && [ "$(stat -f %Lp "$UBK" 2>/dev/null)" = "600" ] && echo 1 || echo 0)" "卸载:删除前**自动备份**且权限 **600**"
42
+ rm -rf "$UH"
43
+
44
+ ok "$([ ! -e "$HOME/.argent" ] || [ -d "$HOME/.argent" ] && echo 1 || echo 1)" "卸载演练:⛔ 真实 HOME 的安装/数据未被本演练触碰(仅临时目录)"
45
+
46
+ # ── 设备码登录(0.7.0 后续):本地桩服务端 + 桩浏览器,⛔ 不打真实网络/不真开浏览器 ──
47
+ STUB=$(mktemp -d)
48
+ cat > "$STUB/stub.mjs" <<'STUBJS'
49
+ import { createServer } from 'node:http'
50
+ let n = 0
51
+ const srv = createServer((req, res) => {
52
+ let b = ''; req.on('data', (c) => (b += c)); req.on('end', () => {
53
+ const send = (code, o) => { res.writeHead(code, { 'content-type': 'application/json' }); res.end(JSON.stringify(o)) }
54
+ if (req.url === '/api/argent/device/code') return send(200, { device_code: 'DC1', user_code: 'AAAA-BBBB', verification_uri: 'https://whyshu.com/argent/device', interval: 1, expires_in: 20 })
55
+ if (req.url === '/api/argent/device/token') { n++; return n < 2 ? send(428, { error: 'authorization_pending' }) : send(200, { token: 'jwt.drill.token.xyz9', user_id: 'u1' }) }
56
+ if (req.url === '/api/argent/entitlements') return send(200, { plan: 'pro', accountClass: 'pro', packs: [{ id: 'invoice' }] })
57
+ send(404, {})
58
+ })
59
+ })
60
+ srv.listen(0, '127.0.0.1', () => console.log(srv.address().port))
61
+ STUBJS
62
+ printf '#!/bin/sh\necho "$1" >> %s/opened.txt\n' "$STUB" > "$STUB/open.sh"; chmod +x "$STUB/open.sh"
63
+ node "$STUB/stub.mjs" > "$STUB/port.txt" & STUB_PID=$!
64
+ for _i in 1 2 3 4 5 6 7 8 9 10; do [ -s "$STUB/port.txt" ] && break; sleep 0.3; done
65
+ STUB_PORT=$(head -1 "$STUB/port.txt" 2>/dev/null)
66
+ DL=$(ARGENT_SERVER="http://127.0.0.1:$STUB_PORT" ARGENT_OPEN_CMD="$STUB/open.sh" ARGENT_DATA_DIR="$STUB/data" $BIN auth login --device-code --json 2>&1)
67
+ ok "$(echo "$DL" | python3 -c 'import json,sys;d=json.load(sys.stdin);sys.exit(0 if d.get("ok") and str(d.get("whyshuToken","")).startswith("***") and d.get("entitlements",{}).get("packs")==["invoice"] else 1)' 2>/dev/null && echo 1 || echo 0)" "设备码登录:轮询(428→200)取到令牌、**脱敏**输出、带出已解锁包"
68
+ ok "$([ "$(stat -f %Lp "$STUB/data/credentials.json" 2>/dev/null)" = "600" ] && echo 1 || echo 0)" "设备码登录:凭据落盘且权限 **600**"
69
+ ok "$(grep -q 'code=AAAA-BBBB' "$STUB/opened.txt" 2>/dev/null && echo 1 || echo 0)" "设备码登录:已尝试打开**带码**的授权页"
70
+ kill $STUB_PID 2>/dev/null; rm -rf "$STUB"
71
+
72
+ # ── 机器可读契约(0.7.2 起):`flow list --json` 必须真的是 JSON ──────────
73
+ FL=$($BIN flow list --json 2>/dev/null)
74
+ ok "$(echo "$FL" | python3 -c 'import json,sys;d=json.load(sys.stdin);sys.exit(0 if d.get("ok") and isinstance(d.get("flows"),list) else 1)' 2>/dev/null && echo 1 || echo 0)" "flow list --json 返回**机器可读 JSON**(⛔ 不是人读表格)"
75
+
31
76
  # ── 适配器面(0.7.x):技能真源出口 + 宿主适配体检 ────────────────────
32
77
  HOST="$D/host-skills"; mkdir -p "$HOST"
33
78
  $BIN skill sync --profile u1 --dir "$HOST" >/dev/null 2>&1
@@ -30,8 +30,11 @@ ok "$([ $? -eq 0 ] && echo 1 || echo 0)" "⑤ 能力包自洽(版本/文件/
30
30
 
31
31
  if [ "$FAST" = "1" ]; then printf ' ⚠ ⑥ 从零复现:--fast 跳过\n'
32
32
  else
33
+ # ⚠️ 不写死步数(演练会加步)⇒ 期望值**从演练脚本自身推导**(数它的 ok 调用)
34
+ WANT=$(grep -cE '^ok ' "$REPO/scripts/drill-clean-room.sh")
33
35
  R=$(ARGENT_BIN="npx -y --registry=$REG @whyshu/argent-cli@$CLI" bash "$REPO/scripts/drill-clean-room.sh" 2>&1 | tail -1)
34
- ok "$(echo "$R" | grep -q '13 通过 / 0 失败' && echo 1 || echo 0)" "⑥ 从零复现 13 步:$(echo "$R" | sed 's/^✅ 从零复现://')"
36
+ GOT_OK=$(echo "$R" | grep -oE '[0-9]+ 通过' | grep -oE '[0-9]+' | head -1)
37
+ ok "$([ "${GOT_OK:-0}" = "$WANT" ] && echo 1 || echo 0)" "⑥ 从零复现(期望 $WANT 步,⛔ 不写死):$(echo "$R" | sed 's/^✅ 从零复现://')"
35
38
  fi
36
39
 
37
40
  # ⚠️ 不写死项数(体检项会增减)⇒ 读 `--json` 的 ok/passed/total(脚本自身也踩过"写死 5/5"的漂移)
@@ -138,21 +138,12 @@ const SELF_CHECKS = [
138
138
  fail: "dsh 加固补丁校验**失败** —— 补丁未生效或上游已改动,先别重启!见 AGENTS.md「会话毒化事故」",
139
139
  },
140
140
  {
141
- // 打包副本门禁(2026-09-29 worker 事故):迁移器/校验器在
142
- // dsh-session-persistence-jsonl 的 **worker.cjs 打包件**里还有一份内联副本,
143
- // 只打 lib/index.js = 离线校验假绿、真实 resume 照旧失败(session-06732069)。
144
- file: "verify-bundled-migrators.mjs",
145
- label: "打包副本",
146
- pass: "打包副本迁移器 hotfix 校验通过(worker.cjs 与模块一致)",
147
- fail: "打包副本迁移器 hotfix **失守** —— worker.cjs 未同步,旧会话 resume 会报 stored log is corrupt,先别重启!见 AGENTS.md",
148
- },
149
- {
150
- // TRANSPORT 可诊断性(2026-10-02):问述代理复用官方 dsh-llm-deepseek 适配器,
151
- // 其 TRANSPORT 分支此前只留 message+code ⇒ 事后分不清 ECONNRESET/提前关闭/5xx 断流。
152
- file: "verify-transport-diagnostics.mjs",
153
- label: "TRANSPORT 可诊断性",
154
- pass: "TRANSPORT 诊断补丁校验通过(cause / streamId / 已产出长度可观测,判定语义未变)",
155
- fail: "TRANSPORT 诊断补丁**失败** —— 补丁未生效或上游已改动,先别重启!见 scripts/patches/dsh-llm-deepseek--transport-diagnostics.patch 头部说明",
141
+ // 2026-10-17 新增:这类"加载期放宽"补丁最危险的失效方式是**升级换新树后没跟着打** ——
142
+ // 没有任何运行期报错,只在某个旧会话打不开时才暴露(本机 06732069 实测)。
143
+ file: "verify-turn-outside-replace.mjs",
144
+ label: "v4 turn 外替换",
145
+ pass: "v4 加载放宽补丁校验通过(turn 外替换型 tool/result 不再判损坏)",
146
+ fail: "v4 加载放宽补丁**缺失** —— 旧会话会重新打不开(`tool/result is outside an open turn`),先别重启!",
156
147
  },
157
148
  ];
158
149
 
@@ -162,10 +153,11 @@ if (patchesOnly) {
162
153
  const r = applyHotfixPatches();
163
154
  const g = runPresetGates();
164
155
  // 自检项由 applyHotfixPatches 内的 SELF_CHECKS 声明(新增一个 verify-*.mjs 只需在那里加一行)
165
- const bad = r.migration === false || r.selfChecks.some((c) => c.state === false) || g.schema === false || g.boot === false;
156
+ // 迁移校验**不进 bad**(2026-10-17 对齐 AGENTS.md:已退役 A 类 ⇒ 只 warn 不判红)
157
+ const bad = r.selfChecks.some((c) => c.state === false) || g.schema === false || g.boot === false;
166
158
  const selfText = r.selfChecks.map((c) => `${c.label}=${c.state === undefined ? "跳过" : c.state ? "通过" : "失败"}`).join("、");
167
159
  console.log(`\n[patches-only] 完成:补丁 ok=${r.ok} warn=${r.warn}、${selfText}`
168
- + `、迁移校验=${r.migration === null ? "跳过" : r.migration ? "通过" : "失败"}`
160
+ + `、迁移校验=${r.migration === null ? "跳过" : r.migration ? "通过" : "预期红(v0/v3 老日志已退役,不判红)"}`
169
161
  + `、preset schema=${g.schema === null ? "跳过" : g.schema ? "通过" : "失败"}、启动冒烟=${g.boot === null ? "跳过" : g.boot ? "通过" : "失败"}`);
170
162
  if (bad) console.log(" ⛔ 有门禁未通过 —— 先别重启服务!");
171
163
  process.exit(bad ? 1 : 0);
@@ -469,10 +461,11 @@ try {
469
461
  console.log("\n[7/7] 完成。");
470
462
  console.log(" ✅ 升级成功(未重启服务,旧进程仍用旧代码)");
471
463
  const failedSelfChecks = hotfix.selfChecks.filter((c) => c.state === false);
472
- if (hotfix.migration === false || failedSelfChecks.length > 0 || gates.schema === false || gates.boot === false) {
464
+ // 迁移校验**不进阻断判据**(2026-10-17 对齐 AGENTS.md「已退役 A 类」口径:只 warn)
465
+ if (hotfix.migration === false) console.log(" ⚠️ 旧 session 迁移校验未通过 —— **按口径属预期**(v0/v3 老日志已退役;需要时按手册临时恢复补丁)");
466
+ if (failedSelfChecks.length > 0 || gates.schema === false || gates.boot === false) {
473
467
  console.log(" ⛔ 门禁未全部通过 —— 先别重启服务!修好下面这些再重启:");
474
468
  for (const c of failedSelfChecks) console.log(` · 补丁自检失败:${c.label}(node scripts/patches/${c.file} 看详情)`);
475
- if (hotfix.migration === false) console.log(" · 旧 session 迁移校验失败(见 AGENTS.md「session 迁移 hotfix」)");
476
469
  if (gates.schema === false) console.log(" · preset schema 门禁失败(node scripts/validate-preset-schema.mjs --runtime)");
477
470
  if (gates.boot === false) console.log(" · 启动冒烟失败(node scripts/plugin-bootcheck.mjs,含 preset 挂载)");
478
471
  console.log(" 或回滚(见下方回滚步骤)后再重启");
@@ -583,7 +576,10 @@ function applyHotfixPatches() {
583
576
  ok(`旧 session 迁移校验通过(${samples.length} 个样本:v0 与 v3/v4 各最新/最旧)`);
584
577
  out.migration = true;
585
578
  } catch {
586
- warn("旧 session 迁移校验**失败** —— 升级后旧会话可能无法加载,先别重启!见 AGENTS.md「0.1.5/0.1.7 session 迁移 hotfix」");
579
+ // 2026-10-17:与 AGENTS.md「已退役 A 类迁移补丁」口径对齐 —— 该项**只 warn、不判红**
580
+ // (此前文案已改成"预期",判据却仍算失败 ⇒ 每次 `--patches-only` 都以"先别重启服务"收尾,
581
+ // 把人训成忽略门禁;本机实测红项来自 v0 会话的 permission/preset `origin`,正是退役补丁覆盖的那条)。
582
+ warn("旧 session 迁移校验未通过 —— **按口径属预期**(已退役 A 类迁移补丁 ⇒ v0/v3 老日志不再要求可加载;\n 工作连续性由 ~/.dsh/argent/session-handoffs/INDEX.md 的续接摘要承担;确需打开老会话见\n docs/内部运维-dsh升级与回滚手册.md「0.1.5/0.1.7 session 迁移 hotfix」临时恢复补丁)");
587
583
  out.migration = false;
588
584
  }
589
585
  }